aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2010-12-22 12:57:02 -0500
committerJiri Kosina <jkosina@suse.cz>2010-12-22 12:57:02 -0500
commit4b7bd364700d9ac8372eff48832062b936d0793b (patch)
tree0dbf78c95456a0b02d07fcd473281f04a87e266d
parentc0d8768af260e2cbb4bf659ae6094a262c86b085 (diff)
parent90a8a73c06cc32b609a880d48449d7083327e11a (diff)
Merge branch 'master' into for-next
Conflicts: MAINTAINERS arch/arm/mach-omap2/pm24xx.c drivers/scsi/bfa/bfa_fcpim.c Needed to update to apply fixes for which the old branch was too outdated.
-rw-r--r--Documentation/ABI/obsolete/proc-pid-oom_adj22
-rw-r--r--Documentation/ABI/testing/sysfs-bus-rbd83
-rw-r--r--Documentation/ABI/testing/sysfs-platform-asus-laptop16
-rw-r--r--Documentation/ABI/testing/sysfs-platform-eeepc-wmi10
-rw-r--r--Documentation/DocBook/sh.tmpl4
-rw-r--r--Documentation/DocBook/uio-howto.tmpl6
-rw-r--r--Documentation/arm/OMAP/DSS7
-rw-r--r--Documentation/block/switching-sched.txt8
-rw-r--r--Documentation/development-process/2.Process33
-rw-r--r--Documentation/driver-model/interface.txt129
-rw-r--r--Documentation/edac.txt8
-rw-r--r--Documentation/fb/00-INDEX32
-rw-r--r--Documentation/feature-removal-schedule.txt10
-rw-r--r--Documentation/filesystems/Locking9
-rw-r--r--Documentation/filesystems/configfs/configfs_example_explicit.c2
-rw-r--r--Documentation/filesystems/vfs.txt16
-rw-r--r--Documentation/filesystems/xfs-delayed-logging-design.txt11
-rw-r--r--Documentation/gpio.txt10
-rw-r--r--Documentation/hwmon/lm932
-rw-r--r--Documentation/hwmon/max66502
-rw-r--r--Documentation/i2c/busses/i2c-i8016
-rw-r--r--Documentation/kernel-parameters.txt12
-rw-r--r--Documentation/leds-class.txt21
-rw-r--r--Documentation/leds/leds-lp5521.txt88
-rw-r--r--Documentation/leds/leds-lp5523.txt83
-rw-r--r--Documentation/networking/ip-sysctl.txt10
-rw-r--r--Documentation/power/opp.txt3
-rw-r--r--Documentation/power/runtime_pm.txt4
-rw-r--r--Documentation/rbtree.txt4
-rw-r--r--Documentation/scsi/ChangeLog.megaraid_sas47
-rw-r--r--Documentation/sh/clk.txt32
-rw-r--r--Documentation/sysctl/kernel.txt14
-rw-r--r--MAINTAINERS60
-rw-r--r--Makefile4
-rw-r--r--arch/arm/Kconfig40
-rw-r--r--arch/arm/boot/Makefile5
-rw-r--r--arch/arm/boot/bootp/init.S2
-rw-r--r--arch/arm/boot/compressed/head.S15
-rw-r--r--arch/arm/boot/compressed/vmlinux.lds.in2
-rw-r--r--arch/arm/common/gic.c64
-rw-r--r--arch/arm/configs/at91rm9200_defconfig341
-rw-r--r--arch/arm/configs/at91rm9200dk_defconfig72
-rw-r--r--arch/arm/configs/at91rm9200ek_defconfig73
-rw-r--r--arch/arm/configs/ateb9200_defconfig131
-rw-r--r--arch/arm/configs/carmeva_defconfig47
-rw-r--r--arch/arm/configs/cpuat91_defconfig112
-rw-r--r--arch/arm/configs/csb337_defconfig104
-rw-r--r--arch/arm/configs/csb637_defconfig98
-rw-r--r--arch/arm/configs/ecbat91_defconfig99
-rw-r--r--arch/arm/configs/kafa_defconfig61
-rw-r--r--arch/arm/configs/kb9202_defconfig127
-rw-r--r--arch/arm/configs/onearm_defconfig80
-rw-r--r--arch/arm/configs/picotux200_defconfig242
-rw-r--r--arch/arm/configs/yl9200_defconfig137
-rw-r--r--arch/arm/include/asm/assembler.h2
-rw-r--r--arch/arm/include/asm/hardware/it8152.h2
-rw-r--r--arch/arm/include/asm/mmu.h4
-rw-r--r--arch/arm/include/asm/pgtable.h3
-rw-r--r--arch/arm/kernel/entry-armv.S2
-rw-r--r--arch/arm/kernel/head.S7
-rw-r--r--arch/arm/kernel/hw_breakpoint.c3
-rw-r--r--arch/arm/kernel/perf_event.c2
-rw-r--r--arch/arm/kernel/relocate_kernel.S2
-rw-r--r--arch/arm/kernel/stacktrace.c2
-rw-r--r--arch/arm/kernel/traps.c5
-rw-r--r--arch/arm/kernel/unwind.c2
-rw-r--r--arch/arm/lib/findbit.S6
-rw-r--r--arch/arm/mach-aaec2000/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-at91/Makefile6
-rw-r--r--arch/arm/mach-at91/at91rm9200_devices.c45
-rw-r--r--arch/arm/mach-at91/board-1arm.c26
-rw-r--r--arch/arm/mach-at91/board-kafa.c21
-rw-r--r--arch/arm/mach-at91/board-pcontrol-g20.c98
-rw-r--r--arch/arm/mach-at91/board-picotux200.c53
-rw-r--r--arch/arm/mach-at91/board-rm9200dk.c (renamed from arch/arm/mach-at91/board-dk.c)4
-rw-r--r--arch/arm/mach-at91/board-rm9200ek.c (renamed from arch/arm/mach-at91/board-ek.c)4
-rw-r--r--arch/arm/mach-at91/board-stamp9g20.c82
-rw-r--r--arch/arm/mach-at91/board-yl-9200.c2
-rw-r--r--arch/arm/mach-at91/clock.c2
-rw-r--r--arch/arm/mach-at91/include/mach/board.h6
-rw-r--r--arch/arm/mach-at91/include/mach/stamp9g20.h7
-rw-r--r--arch/arm/mach-bcmring/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-clps711x/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-cns3xxx/pcie.c2
-rw-r--r--arch/arm/mach-davinci/dm355.c6
-rw-r--r--arch/arm/mach-davinci/dm365.c6
-rw-r--r--arch/arm/mach-davinci/dm644x.c4
-rw-r--r--arch/arm/mach-ebsa110/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-ep93xx/include/mach/dma.h111
-rw-r--r--arch/arm/mach-footbridge/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-h720x/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-imx/eukrea_mbimx27-baseboard.c6
-rw-r--r--arch/arm/mach-integrator/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-kirkwood/common.c7
-rw-r--r--arch/arm/mach-kirkwood/d2net_v2-setup.c2
-rw-r--r--arch/arm/mach-kirkwood/lacie_v2-common.c14
-rw-r--r--arch/arm/mach-kirkwood/lacie_v2-common.h2
-rw-r--r--arch/arm/mach-kirkwood/mpp.c4
-rw-r--r--arch/arm/mach-kirkwood/netspace_v2-setup.c6
-rw-r--r--arch/arm/mach-kirkwood/netxbig_v2-setup.c4
-rw-r--r--arch/arm/mach-kirkwood/ts41x-setup.c14
-rw-r--r--arch/arm/mach-mmp/include/mach/cputype.h3
-rw-r--r--arch/arm/mach-mmp/mmp2.c1
-rw-r--r--arch/arm/mach-msm/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-mv78xx0/mpp.c4
-rw-r--r--arch/arm/mach-mx25/devices-imx25.h4
-rw-r--r--arch/arm/mach-mx3/mach-pcm037_eet.c5
-rw-r--r--arch/arm/mach-netx/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-omap1/devices.c5
-rw-r--r--arch/arm/mach-omap1/include/mach/camera.h2
-rw-r--r--arch/arm/mach-omap1/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-omap2/board-devkit8000.c3
-rw-r--r--arch/arm/mach-omap2/board-zoom-peripherals.c2
-rw-r--r--arch/arm/mach-omap2/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-omap2/io.c2
-rw-r--r--arch/arm/mach-omap2/pm-debug.c34
-rw-r--r--arch/arm/mach-omap2/pm24xx.c35
-rw-r--r--arch/arm/mach-omap2/pm34xx.c27
-rw-r--r--arch/arm/mach-omap2/prcm-common.h11
-rw-r--r--arch/arm/mach-omap2/serial.c7
-rw-r--r--arch/arm/mach-orion5x/mpp.c4
-rw-r--r--arch/arm/mach-orion5x/ts78xx-setup.c2
-rw-r--r--arch/arm/mach-pnx4008/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-pxa/cm-x2xx.c2
-rw-r--r--arch/arm/mach-pxa/palmtx.c3
-rw-r--r--arch/arm/mach-pxa/saar.c2
-rw-r--r--arch/arm/mach-realview/headsmp.S1
-rw-r--r--arch/arm/mach-rpc/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-s3c2410/h1940-bluetooth.c8
-rw-r--r--arch/arm/mach-s3c2412/Kconfig9
-rw-r--r--arch/arm/mach-s3c2412/Makefile3
-rw-r--r--arch/arm/mach-s3c2416/Kconfig4
-rw-r--r--arch/arm/mach-s3c2416/irq.c5
-rw-r--r--arch/arm/mach-s3c2440/Kconfig4
-rw-r--r--arch/arm/mach-s3c2440/s3c2440.c11
-rw-r--r--arch/arm/mach-s3c2440/s3c2442.c14
-rw-r--r--arch/arm/mach-s3c2443/Kconfig1
-rw-r--r--arch/arm/mach-s3c2443/irq.c5
-rw-r--r--arch/arm/mach-s3c64xx/Kconfig2
-rw-r--r--arch/arm/mach-s3c64xx/mach-mini6410.c2
-rw-r--r--arch/arm/mach-s3c64xx/mach-real6410.c2
-rw-r--r--arch/arm/mach-s5pv210/mach-aquila.c6
-rw-r--r--arch/arm/mach-s5pv210/mach-goni.c6
-rw-r--r--arch/arm/mach-s5pv210/mach-smdkc110.c1
-rw-r--r--arch/arm/mach-s5pv210/mach-smdkv210.c1
-rw-r--r--arch/arm/mach-shark/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-shmobile/Kconfig2
-rw-r--r--arch/arm/mach-shmobile/board-ap4evb.c167
-rw-r--r--arch/arm/mach-shmobile/clock-sh7372.c115
-rw-r--r--arch/arm/mach-shmobile/include/mach/entry-macro.S30
-rw-r--r--arch/arm/mach-shmobile/include/mach/gpio.h4
-rw-r--r--arch/arm/mach-shmobile/include/mach/sh7372.h2
-rw-r--r--arch/arm/mach-shmobile/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-shmobile/intc-sh7372.c2
-rw-r--r--arch/arm/mach-tegra/include/mach/debug-macro.S4
-rw-r--r--arch/arm/mach-u300/spi.c2
-rw-r--r--arch/arm/mach-ux500/cpu.c6
-rw-r--r--arch/arm/mach-versatile/include/mach/vmalloc.h2
-rw-r--r--arch/arm/mach-vexpress/ct-ca9x4.c2
-rw-r--r--arch/arm/mach-vexpress/headsmp.S1
-rw-r--r--arch/arm/mm/cache-v6.S28
-rw-r--r--arch/arm/mm/cache-v7.S27
-rw-r--r--arch/arm/mm/dma-mapping.c2
-rw-r--r--arch/arm/mm/ioremap.c4
-rw-r--r--arch/arm/mm/proc-macros.S22
-rw-r--r--arch/arm/mm/proc-v7.S4
-rw-r--r--arch/arm/plat-iop/time.c3
-rw-r--r--arch/arm/plat-mxc/devices/platform-imx-dma.c8
-rw-r--r--arch/arm/plat-mxc/devices/platform-spi_imx.c1
-rw-r--r--arch/arm/plat-nomadik/timer.c89
-rw-r--r--arch/arm/plat-omap/counter_32k.c3
-rw-r--r--arch/arm/plat-omap/devices.c4
-rw-r--r--arch/arm/plat-omap/dma.c2
-rw-r--r--arch/arm/plat-omap/sram.c2
-rw-r--r--arch/arm/plat-orion/include/plat/pcie.h3
-rw-r--r--arch/arm/plat-orion/pcie.c5
-rw-r--r--arch/arm/plat-pxa/include/plat/sdhci.h3
-rw-r--r--arch/arm/plat-s3c24xx/Kconfig2
-rw-r--r--arch/arm/plat-s3c24xx/cpu.c8
-rw-r--r--arch/arm/plat-s3c24xx/gpiolib.c2
-rw-r--r--arch/arm/plat-s3c24xx/include/plat/s3c244x.h7
-rw-r--r--arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c6
-rw-r--r--arch/arm/plat-s3c24xx/spi-bus1-gpd8_9_10.c6
-rw-r--r--arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c6
-rw-r--r--arch/arm/plat-samsung/gpio-config.c47
-rw-r--r--arch/arm/plat-samsung/include/plat/gpio-cfg-helpers.h11
-rw-r--r--arch/arm/tools/mach-types183
-rw-r--r--arch/arm/vfp/vfphw.S1
-rw-r--r--arch/blackfin/kernel/process.c1
-rw-r--r--arch/frv/kernel/process.c1
-rw-r--r--arch/h8300/kernel/process.c1
-rw-r--r--arch/ia64/hp/sim/simscsi.c4
-rw-r--r--arch/m68k/include/asm/irqflags.h2
-rw-r--r--arch/m68k/include/asm/machdep.h1
-rw-r--r--arch/m68k/kernel/process.c1
-rw-r--r--arch/m68knommu/kernel/process.c1
-rw-r--r--arch/mips/Kconfig38
-rw-r--r--arch/mips/alchemy/common/platform.c2
-rw-r--r--arch/mips/alchemy/devboards/prom.c5
-rw-r--r--arch/mips/ar7/clock.c9
-rw-r--r--arch/mips/ar7/time.c3
-rw-r--r--arch/mips/bcm47xx/setup.c153
-rw-r--r--arch/mips/include/asm/cpu.h4
-rw-r--r--arch/mips/include/asm/elf.h8
-rw-r--r--arch/mips/include/asm/io.h12
-rw-r--r--arch/mips/include/asm/mach-ar7/ar7.h3
-rw-r--r--arch/mips/include/asm/mach-bcm47xx/nvram.h7
-rw-r--r--arch/mips/jz4740/board-qi_lb60.c4
-rw-r--r--arch/mips/jz4740/platform.c2
-rw-r--r--arch/mips/jz4740/prom.c2
-rw-r--r--arch/mips/kernel/cevt-r4k.c2
-rw-r--r--arch/mips/kernel/cpu-probe.c7
-rw-r--r--arch/mips/kernel/linux32.c13
-rw-r--r--arch/mips/kernel/process.c1
-rw-r--r--arch/mips/kernel/prom.c2
-rw-r--r--arch/mips/kernel/smp-mt.c2
-rw-r--r--arch/mips/kernel/traps.c44
-rw-r--r--arch/mips/kernel/vpe.c14
-rw-r--r--arch/mips/lib/memset.S4
-rw-r--r--arch/mips/loongson/common/env.c4
-rw-r--r--arch/mips/math-emu/cp1emu.c116
-rw-r--r--arch/mips/mm/dma-default.c4
-rw-r--r--arch/mips/mm/sc-mips.c4
-rw-r--r--arch/mips/pmc-sierra/yosemite/py-console.c12
-rw-r--r--arch/mips/sibyte/swarm/setup.c8
-rw-r--r--arch/mn10300/include/asm/syscall.h117
-rw-r--r--arch/mn10300/kernel/gdb-io-serial.c3
-rw-r--r--arch/mn10300/kernel/gdb-io-ttysm.c3
-rw-r--r--arch/mn10300/kernel/gdb-stub.c3
-rw-r--r--arch/mn10300/kernel/process.c1
-rw-r--r--arch/mn10300/kernel/time.c10
-rw-r--r--arch/parisc/hpux/sys_hpux.c1
-rw-r--r--arch/parisc/kernel/irq.c7
-rw-r--r--arch/parisc/kernel/signal.c9
-rw-r--r--arch/parisc/kernel/sys_parisc32.c1
-rw-r--r--arch/powerpc/Kconfig4
-rw-r--r--arch/powerpc/boot/div64.S3
-rw-r--r--arch/powerpc/kernel/kgdb.c4
-rw-r--r--arch/powerpc/kernel/kvm.c2
-rw-r--r--arch/powerpc/kernel/setup_64.c5
-rw-r--r--arch/powerpc/kernel/sys_ppc32.c1
-rw-r--r--arch/powerpc/kvm/booke_interrupts.S2
-rw-r--r--arch/powerpc/kvm/e500.c2
-rw-r--r--arch/powerpc/kvm/powerpc.c1
-rw-r--r--arch/powerpc/kvm/timing.c2
-rw-r--r--arch/powerpc/mm/hash_utils_64.c2
-rw-r--r--arch/powerpc/mm/pgtable.c2
-rw-r--r--arch/powerpc/mm/tlb_low_64e.S5
-rw-r--r--arch/powerpc/mm/tlb_nohash.c2
-rw-r--r--arch/powerpc/platforms/pseries/Kconfig6
-rw-r--r--arch/powerpc/platforms/pseries/eeh.c2
-rw-r--r--arch/powerpc/platforms/pseries/pci_dlpar.c2
-rw-r--r--arch/s390/Kconfig.debug12
-rw-r--r--arch/s390/include/asm/page.h5
-rw-r--r--arch/s390/kernel/compat_linux.c1
-rw-r--r--arch/s390/kernel/kprobes.c70
-rw-r--r--arch/s390/kernel/nmi.c10
-rw-r--r--arch/s390/kernel/vtime.c19
-rw-r--r--arch/s390/lib/delay.c14
-rw-r--r--arch/s390/mm/gup.c7
-rw-r--r--arch/sh/Kconfig4
-rw-r--r--arch/sh/Makefile3
-rw-r--r--arch/sh/boards/Kconfig7
-rw-r--r--arch/sh/boards/Makefile2
-rw-r--r--arch/sh/boards/board-edosk7705.c78
-rw-r--r--arch/sh/boards/board-secureedge5410.c (renamed from arch/sh/boards/mach-snapgear/setup.c)38
-rw-r--r--arch/sh/boards/mach-ecovec24/setup.c34
-rw-r--r--arch/sh/boards/mach-edosk7705/Makefile5
-rw-r--r--arch/sh/boards/mach-edosk7705/io.c71
-rw-r--r--arch/sh/boards/mach-edosk7705/setup.c36
-rw-r--r--arch/sh/boards/mach-microdev/io.c246
-rw-r--r--arch/sh/boards/mach-microdev/setup.c23
-rw-r--r--arch/sh/boards/mach-se/7206/Makefile2
-rw-r--r--arch/sh/boards/mach-se/7206/io.c104
-rw-r--r--arch/sh/boards/mach-se/7206/irq.c4
-rw-r--r--arch/sh/boards/mach-se/7206/setup.c15
-rw-r--r--arch/sh/boards/mach-se/770x/Makefile2
-rw-r--r--arch/sh/boards/mach-se/770x/io.c156
-rw-r--r--arch/sh/boards/mach-se/770x/setup.c22
-rw-r--r--arch/sh/boards/mach-se/7724/setup.c47
-rw-r--r--arch/sh/boards/mach-se/7751/Makefile2
-rw-r--r--arch/sh/boards/mach-se/7751/io.c119
-rw-r--r--arch/sh/boards/mach-se/7751/setup.c18
-rw-r--r--arch/sh/boards/mach-snapgear/Makefile5
-rw-r--r--arch/sh/boards/mach-snapgear/io.c121
-rw-r--r--arch/sh/boards/mach-systemh/Makefile13
-rw-r--r--arch/sh/boards/mach-systemh/io.c158
-rw-r--r--arch/sh/boards/mach-systemh/irq.c61
-rw-r--r--arch/sh/boards/mach-systemh/setup.c57
-rw-r--r--arch/sh/configs/secureedge5410_defconfig (renamed from arch/sh/configs/snapgear_defconfig)0
-rw-r--r--arch/sh/configs/systemh_defconfig28
-rw-r--r--arch/sh/include/asm/addrspace.h8
-rw-r--r--arch/sh/include/asm/cacheflush.h2
-rw-r--r--arch/sh/include/asm/pgtable.h12
-rw-r--r--arch/sh/include/asm/processor_32.h7
-rw-r--r--arch/sh/include/asm/system.h4
-rw-r--r--arch/sh/include/asm/system_32.h36
-rw-r--r--arch/sh/include/asm/system_64.h3
-rw-r--r--arch/sh/include/asm/uncached.h40
-rw-r--r--arch/sh/include/asm/unistd_32.h3
-rw-r--r--arch/sh/include/cpu-sh4/cpu/sh7724.h3
-rw-r--r--arch/sh/include/mach-common/mach/edosk7705.h7
-rw-r--r--arch/sh/include/mach-common/mach/microdev.h9
-rw-r--r--arch/sh/include/mach-common/mach/secureedge5410.h (renamed from arch/sh/include/mach-common/mach/snapgear.h)22
-rw-r--r--arch/sh/include/mach-common/mach/systemh7751.h71
-rw-r--r--arch/sh/kernel/cpu/sh4/clock-sh4-202.c2
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7724.c50
-rw-r--r--arch/sh/kernel/sys_sh.c2
-rw-r--r--arch/sh/kernel/syscalls_32.S1
-rw-r--r--arch/sh/kernel/vsyscall/vsyscall-trapa.S2
-rw-r--r--arch/sh/mm/Kconfig2
-rw-r--r--arch/sh/mm/cache-sh4.c4
-rw-r--r--arch/sh/mm/cache-sh7705.c2
-rw-r--r--arch/sh/mm/cache.c14
-rw-r--r--arch/sh/mm/consistent.c15
-rw-r--r--arch/sh/mm/kmap.c2
-rw-r--r--arch/sh/mm/uncached.c2
-rw-r--r--arch/sh/tools/mach-types1
-rw-r--r--arch/sparc/include/asm/openprom.h2
-rw-r--r--arch/sparc/include/asm/oplib_32.h35
-rw-r--r--arch/sparc/include/asm/oplib_64.h46
-rw-r--r--arch/sparc/kernel/leon_kernel.c4
-rw-r--r--arch/sparc/kernel/leon_smp.c1
-rw-r--r--arch/sparc/kernel/sys_sparc32.c1
-rw-r--r--arch/sparc/kernel/sys_sparc_32.c1
-rw-r--r--arch/sparc/kernel/unaligned_32.c1
-rw-r--r--arch/sparc/kernel/windows.c1
-rw-r--r--arch/sparc/prom/Makefile1
-rw-r--r--arch/sparc/prom/console_32.c65
-rw-r--r--arch/sparc/prom/console_64.c81
-rw-r--r--arch/sparc/prom/devops_32.c87
-rw-r--r--arch/sparc/prom/devops_64.c67
-rw-r--r--arch/sparc/prom/misc_64.c16
-rw-r--r--arch/sparc/prom/printf.c35
-rw-r--r--arch/sparc/prom/tree_32.c16
-rw-r--r--arch/sparc/prom/tree_64.c18
-rw-r--r--arch/tile/Kconfig12
-rw-r--r--arch/tile/include/asm/cacheflush.h52
-rw-r--r--arch/tile/include/asm/highmem.h1
-rw-r--r--arch/tile/include/asm/io.h15
-rw-r--r--arch/tile/include/asm/kmap_types.h34
-rw-r--r--arch/tile/include/asm/pci-bridge.h117
-rw-r--r--arch/tile/include/asm/pci.h107
-rw-r--r--arch/tile/include/asm/pgtable.h6
-rw-r--r--arch/tile/include/asm/processor.h10
-rw-r--r--arch/tile/include/asm/signal.h2
-rw-r--r--arch/tile/include/asm/stat.h3
-rw-r--r--arch/tile/include/asm/unistd.h1
-rw-r--r--arch/tile/include/hv/drv_xgbe_impl.h300
-rw-r--r--arch/tile/include/hv/drv_xgbe_intf.h615
-rw-r--r--arch/tile/include/hv/netio_errors.h122
-rw-r--r--arch/tile/include/hv/netio_intf.h2975
-rw-r--r--arch/tile/kernel/Makefile1
-rw-r--r--arch/tile/kernel/compat.c11
-rw-r--r--arch/tile/kernel/compat_signal.c7
-rw-r--r--arch/tile/kernel/early_printk.c2
-rw-r--r--arch/tile/kernel/hardwall.c6
-rw-r--r--arch/tile/kernel/intvec_32.S24
-rw-r--r--arch/tile/kernel/irq.c4
-rw-r--r--arch/tile/kernel/machine_kexec.c6
-rw-r--r--arch/tile/kernel/messaging.c2
-rw-r--r--arch/tile/kernel/pci.c621
-rw-r--r--arch/tile/kernel/process.c8
-rw-r--r--arch/tile/kernel/ptrace.c39
-rw-r--r--arch/tile/kernel/reboot.c6
-rw-r--r--arch/tile/kernel/setup.c10
-rw-r--r--arch/tile/kernel/signal.c20
-rw-r--r--arch/tile/kernel/smp.c2
-rw-r--r--arch/tile/kernel/smpboot.c1
-rw-r--r--arch/tile/kernel/sys.c1
-rw-r--r--arch/tile/kernel/time.c8
-rw-r--r--arch/tile/lib/memchr_32.c35
-rw-r--r--arch/tile/lib/memcpy_tile64.c11
-rw-r--r--arch/tile/lib/spinlock_32.c29
-rw-r--r--arch/tile/mm/fault.c1
-rw-r--r--arch/tile/mm/highmem.c2
-rw-r--r--arch/tile/mm/hugetlbpage.c1
-rw-r--r--arch/tile/mm/init.c8
-rw-r--r--arch/tile/mm/pgtable.c4
-rw-r--r--arch/um/drivers/line.c5
-rw-r--r--arch/um/include/asm/ptrace-generic.h4
-rw-r--r--arch/um/kernel/exec.c1
-rw-r--r--arch/um/kernel/ptrace.c2
-rw-r--r--arch/x86/Kconfig2
-rw-r--r--arch/x86/boot/compressed/misc.c2
-rw-r--r--arch/x86/crypto/ghash-clmulni-intel_glue.c1
-rw-r--r--arch/x86/ia32/sys_ia32.c1
-rw-r--r--arch/x86/include/asm/apic.h10
-rw-r--r--arch/x86/include/asm/e820.h3
-rw-r--r--arch/x86/include/asm/fixmap.h4
-rw-r--r--arch/x86/include/asm/kvm_host.h2
-rw-r--r--arch/x86/include/asm/msr-index.h2
-rw-r--r--arch/x86/include/asm/paravirt.h10
-rw-r--r--arch/x86/include/asm/pvclock.h1
-rw-r--r--arch/x86/include/asm/uv/uv_hub.h4
-rw-r--r--arch/x86/include/asm/uv/uv_mmrs.h208
-rw-r--r--arch/x86/include/asm/xen/interface.h6
-rw-r--r--arch/x86/include/asm/xen/interface_32.h5
-rw-r--r--arch/x86/include/asm/xen/interface_64.h13
-rw-r--r--arch/x86/include/asm/xen/page.h7
-rw-r--r--arch/x86/kernel/Makefile1
-rw-r--r--arch/x86/kernel/apic/apic.c9
-rw-r--r--arch/x86/kernel/apic/hw_nmi.c7
-rw-r--r--arch/x86/kernel/apic/io_apic.c4
-rw-r--r--arch/x86/kernel/apic/probe_64.c7
-rw-r--r--arch/x86/kernel/apic/x2apic_uv_x.c37
-rw-r--r--arch/x86/kernel/cpu/perf_event.c20
-rw-r--r--arch/x86/kernel/cpu/perf_event_amd.c4
-rw-r--r--arch/x86/kernel/cpuid.c1
-rw-r--r--arch/x86/kernel/entry_32.S2
-rw-r--r--arch/x86/kernel/entry_64.S2
-rw-r--r--arch/x86/kernel/head_32.S16
-rw-r--r--arch/x86/kernel/hpet.c26
-rw-r--r--arch/x86/kernel/hw_breakpoint.c4
-rw-r--r--arch/x86/kernel/kgdb.c12
-rw-r--r--arch/x86/kernel/microcode_amd.c2
-rw-r--r--arch/x86/kernel/mmconf-fam10h_64.c71
-rw-r--r--arch/x86/kernel/msr.c1
-rw-r--r--arch/x86/kernel/pvclock.c43
-rw-r--r--arch/x86/kernel/resource.c48
-rw-r--r--arch/x86/kernel/setup.c1
-rw-r--r--arch/x86/kernel/xsave.c3
-rw-r--r--arch/x86/kvm/mmu.c9
-rw-r--r--arch/x86/kvm/svm.c6
-rw-r--r--arch/x86/kvm/vmx.c24
-rw-r--r--arch/x86/kvm/x86.c27
-rw-r--r--arch/x86/kvm/x86.h5
-rw-r--r--arch/x86/lguest/boot.c16
-rw-r--r--arch/x86/lguest/i386_head.S105
-rw-r--r--arch/x86/mm/tlb.c7
-rw-r--r--arch/x86/pci/acpi.c103
-rw-r--r--arch/x86/pci/i386.c18
-rw-r--r--arch/x86/pci/xen.c35
-rw-r--r--arch/x86/platform/uv/tlb_uv.c15
-rw-r--r--arch/x86/platform/uv/uv_time.c4
-rw-r--r--arch/x86/vdso/Makefile4
-rw-r--r--arch/x86/xen/enlighten.c25
-rw-r--r--arch/x86/xen/mmu.c88
-rw-r--r--arch/x86/xen/platform-pci-unplug.c2
-rw-r--r--arch/x86/xen/setup.c71
-rw-r--r--arch/x86/xen/suspend.c1
-rw-r--r--arch/x86/xen/time.c2
-rw-r--r--arch/x86/xen/xen-ops.h2
-rw-r--r--block/blk-core.c11
-rw-r--r--block/blk-ioc.c14
-rw-r--r--block/blk-map.c3
-rw-r--r--block/blk-merge.c6
-rw-r--r--block/blk-settings.c51
-rw-r--r--block/blk-sysfs.c2
-rw-r--r--block/blk-throttle.c41
-rw-r--r--block/bsg.c8
-rw-r--r--block/compat_ioctl.c5
-rw-r--r--block/elevator.c4
-rw-r--r--block/ioctl.c8
-rw-r--r--block/scsi_ioctl.c34
-rw-r--r--crypto/pcrypt.c1
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/acpi/ac.c46
-rw-r--r--drivers/acpi/apei/erst.c34
-rw-r--r--drivers/acpi/apei/hest.c10
-rw-r--r--drivers/acpi/battery.c5
-rw-r--r--drivers/acpi/debugfs.c2
-rw-r--r--drivers/acpi/ec.c3
-rw-r--r--drivers/acpi/osl.c113
-rw-r--r--drivers/acpi/power.c12
-rw-r--r--drivers/acpi/processor_thermal.c9
-rw-r--r--drivers/acpi/sleep.c12
-rw-r--r--drivers/ata/libata-scsi.c24
-rw-r--r--drivers/ata/pata_legacy.c2
-rw-r--r--drivers/ata/pata_octeon_cf.c2
-rw-r--r--drivers/ata/sata_via.c9
-rw-r--r--drivers/atm/adummy.c2
-rw-r--r--drivers/atm/ambassador.c3
-rw-r--r--drivers/atm/atmtcp.c2
-rw-r--r--drivers/atm/eni.c2
-rw-r--r--drivers/atm/firestream.c2
-rw-r--r--drivers/atm/fore200e.c14
-rw-r--r--drivers/atm/he.c2
-rw-r--r--drivers/atm/horizon.c3
-rw-r--r--drivers/atm/idt77252.c3
-rw-r--r--drivers/atm/iphase.c2
-rw-r--r--drivers/atm/lanai.c2
-rw-r--r--drivers/atm/nicstar.c3
-rw-r--r--drivers/atm/solos-attrlist.c1
-rw-r--r--drivers/atm/solos-pci.c16
-rw-r--r--drivers/atm/zatm.c2
-rw-r--r--drivers/base/power/main.c34
-rw-r--r--drivers/block/amiflop.c2
-rw-r--r--drivers/block/aoe/aoeblk.c3
-rw-r--r--drivers/block/ataflop.c2
-rw-r--r--drivers/block/cciss.c136
-rw-r--r--drivers/block/cciss.h4
-rw-r--r--drivers/block/cciss_scsi.c8
-rw-r--r--drivers/block/drbd/drbd_actlog.c42
-rw-r--r--drivers/block/drbd/drbd_int.h52
-rw-r--r--drivers/block/drbd/drbd_main.c148
-rw-r--r--drivers/block/drbd/drbd_nl.c25
-rw-r--r--drivers/block/drbd/drbd_proc.c1
-rw-r--r--drivers/block/drbd/drbd_receiver.c232
-rw-r--r--drivers/block/drbd/drbd_req.c38
-rw-r--r--drivers/block/drbd/drbd_req.h3
-rw-r--r--drivers/block/drbd/drbd_worker.c34
-rw-r--r--drivers/block/floppy.c4
-rw-r--r--drivers/block/loop.c6
-rw-r--r--drivers/block/rbd.c748
-rw-r--r--drivers/block/xen-blkfront.c57
-rw-r--r--drivers/bluetooth/ath3k.c4
-rw-r--r--drivers/bluetooth/btusb.c17
-rw-r--r--drivers/char/Makefile44
-rw-r--r--drivers/char/agp/frontend.c1
-rw-r--r--drivers/char/agp/intel-gtt.c12
-rw-r--r--drivers/char/amiserial.c2
-rw-r--r--drivers/char/briq_panel.c1
-rw-r--r--drivers/char/hpet.c1
-rw-r--r--drivers/char/hw_random/core.c1
-rw-r--r--drivers/char/i8k.c7
-rw-r--r--drivers/char/istallion.c1
-rw-r--r--drivers/char/nozomi.c1
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c3
-rw-r--r--drivers/char/pcmcia/synclink_cs.c1
-rw-r--r--drivers/char/serial167.c1
-rw-r--r--drivers/char/specialix.c1
-rw-r--r--drivers/char/stallion.c1
-rw-r--r--drivers/char/sx.c1
-rw-r--r--drivers/char/tpm/tpm_tis.c24
-rw-r--r--drivers/char/uv_mmtimer.c1
-rw-r--r--drivers/char/virtio_console.c37
-rw-r--r--drivers/clocksource/sh_cmt.c27
-rw-r--r--drivers/clocksource/sh_mtu2.c10
-rw-r--r--drivers/clocksource/sh_tmu.c10
-rw-r--r--drivers/connector/connector.c1
-rw-r--r--drivers/crypto/n2_core.c2
-rw-r--r--drivers/crypto/padlock-aes.c2
-rw-r--r--drivers/dma/Makefile4
-rw-r--r--drivers/dma/at_hdmac.c2
-rw-r--r--drivers/dma/fsldma.c6
-rw-r--r--drivers/dma/fsldma.h9
-rw-r--r--drivers/dma/imx-dma.c2
-rw-r--r--drivers/dma/imx-sdma.c4
-rw-r--r--drivers/dma/intel_mid_dma.c8
-rw-r--r--drivers/dma/ioat/Makefile2
-rw-r--r--drivers/dma/pch_dma.c15
-rw-r--r--drivers/dma/ppc4xx/adma.c5
-rw-r--r--drivers/dma/shdma.c1
-rw-r--r--drivers/edac/Makefile8
-rw-r--r--drivers/edac/amd64_edac.c2
-rw-r--r--drivers/edac/edac_core.h6
-rw-r--r--drivers/edac/edac_mc.c10
-rw-r--r--drivers/edac/mce_amd_inj.c2
-rw-r--r--drivers/firewire/net.c160
-rw-r--r--drivers/firewire/ohci.c135
-rw-r--r--drivers/firewire/sbp2.c4
-rw-r--r--drivers/gpio/cs5535-gpio.c16
-rw-r--r--drivers/gpu/drm/drm_crtc.c10
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c18
-rw-r--r--drivers/gpu/drm/drm_edid.c26
-rw-r--r--drivers/gpu/drm/drm_fops.c1
-rw-r--r--drivers/gpu/drm/drm_irq.c21
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c3
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c5
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h3
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c720
-rw-r--r--drivers/gpu/drm/i915/i915_gem_evict.c8
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h1
-rw-r--r--drivers/gpu/drm/i915/i915_suspend.c44
-rw-r--r--drivers/gpu/drm/i915/intel_acpi.c34
-rw-r--r--drivers/gpu/drm/i915/intel_crt.c159
-rw-r--r--drivers/gpu/drm/i915/intel_display.c165
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c173
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h3
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c11
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c133
-rw-r--r--drivers/gpu/drm/i915/intel_opregion.c2
-rw-r--r--drivers/gpu/drm/i915/intel_overlay.c4
-rw-r--r--drivers/gpu/drm/i915/intel_ringbuffer.c159
-rw-r--r--drivers/gpu/drm/i915/intel_ringbuffer.h3
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c84
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_backlight.c9
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bo.c43
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_connector.c77
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_connector.h3
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.h55
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fence.c7
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_gem.c36
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_hw.c8
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_hw.h19
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_irq.c42
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_mem.c49
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_object.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_pm.c7
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_ramht.c71
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_sgdma.c14
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_state.c17
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_temp.c2
-rw-r--r--drivers/gpu/drm/nouveau/nv04_crtc.c7
-rw-r--r--drivers/gpu/drm/nouveau/nv04_dfp.c13
-rw-r--r--drivers/gpu/drm/nouveau/nv04_pm.c9
-rw-r--r--drivers/gpu/drm/nouveau/nv50_calc.c16
-rw-r--r--drivers/gpu/drm/nouveau/nv50_crtc.c4
-rw-r--r--drivers/gpu/drm/nouveau/nv50_display.c35
-rw-r--r--drivers/gpu/drm/nouveau/nv50_fifo.c5
-rw-r--r--drivers/gpu/drm/nouveau/nv50_graph.c52
-rw-r--r--drivers/gpu/drm/nouveau/nv50_instmem.c1
-rw-r--r--drivers/gpu/drm/radeon/atom.c1
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c39
-rw-r--r--drivers/gpu/drm/radeon/evergreen_blit_kms.c2
-rw-r--r--drivers/gpu/drm/radeon/r100.c4
-rw-r--r--drivers/gpu/drm/radeon/r300.c2
-rw-r--r--drivers/gpu/drm/radeon/r600.c31
-rw-r--r--drivers/gpu/drm/radeon/r600_blit_kms.c2
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c309
-rw-r--r--drivers/gpu/drm/radeon/r600_reg.h1
-rw-r--r--drivers/gpu/drm/radeon/r600d.h6
-rw-r--r--drivers/gpu/drm/radeon/radeon.h4
-rw-r--r--drivers/gpu/drm/radeon/radeon_atombios.c43
-rw-r--r--drivers/gpu/drm/radeon/radeon_benchmark.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_bios.c13
-rw-r--r--drivers/gpu/drm/radeon/radeon_combios.c15
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c68
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c18
-rw-r--r--drivers/gpu/drm/radeon/radeon_encoders.c382
-rw-r--r--drivers/gpu/drm/radeon/radeon_fence.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_gart.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_gem.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_i2c.c49
-rw-r--r--drivers/gpu/drm/radeon/radeon_irq.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_legacy_encoders.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_mode.h22
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c22
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.h7
-rw-r--r--drivers/gpu/drm/radeon/radeon_ring.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon_test.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_ttm.c5
-rw-r--r--drivers/gpu/drm/radeon/rs400.c2
-rw-r--r--drivers/gpu/drm/radeon/rs600.c4
-rw-r--r--drivers/gpu/drm/radeon/rv770.c4
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c97
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_manager.c81
-rw-r--r--drivers/gpu/drm/ttm/ttm_tt.c4
-rw-r--r--drivers/gpu/drm/via/via_dmablit.c4
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c1
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.c5
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c14
-rw-r--r--drivers/gpu/stub/Kconfig3
-rw-r--r--drivers/hid/hid-core.c1
-rw-r--r--drivers/hid/hid-egalax.c2
-rw-r--r--drivers/hid/hid-input.c21
-rw-r--r--drivers/hid/hid-tmff.c2
-rw-r--r--drivers/hid/hidraw.c1
-rw-r--r--drivers/hid/usbhid/hiddev.c1
-rw-r--r--drivers/hwmon/ad7414.c6
-rw-r--r--drivers/hwmon/adm1026.c20
-rw-r--r--drivers/hwmon/adt7470.c4
-rw-r--r--drivers/hwmon/amc6821.c2
-rw-r--r--drivers/hwmon/gpio-fan.c8
-rw-r--r--drivers/hwmon/i5k_amb.c2
-rw-r--r--drivers/hwmon/it87.c61
-rw-r--r--drivers/hwmon/lis3lv02d_i2c.c10
-rw-r--r--drivers/hwmon/lm93.c4
-rw-r--r--drivers/hwmon/lm95241.c19
-rw-r--r--drivers/hwmon/ltc4215.c4
-rw-r--r--drivers/hwmon/ltc4261.c5
-rw-r--r--drivers/hwmon/max6650.c2
-rw-r--r--drivers/hwmon/w83795.c207
-rw-r--r--drivers/i2c/Kconfig3
-rw-r--r--drivers/i2c/algos/Kconfig14
-rw-r--r--drivers/i2c/busses/Kconfig1
-rw-r--r--drivers/i2c/busses/i2c-i801.c333
-rw-r--r--drivers/i2c/busses/i2c-intel-mid.c2
-rw-r--r--drivers/i2c/i2c-core.c12
-rw-r--r--drivers/i2c/i2c-mux.c1
-rw-r--r--drivers/idle/intel_idle.c12
-rw-r--r--drivers/infiniband/core/ud_header.c30
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c99
-rw-r--r--drivers/infiniband/core/uverbs_marshall.c4
-rw-r--r--drivers/infiniband/hw/ipath/ipath_file_ops.c1
-rw-r--r--drivers/infiniband/hw/mlx4/main.c4
-rw-r--r--drivers/infiniband/hw/mlx4/qp.c10
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c4
-rw-r--r--drivers/input/evdev.c113
-rw-r--r--drivers/input/input.c90
-rw-r--r--drivers/input/joystick/turbografx.c1
-rw-r--r--drivers/input/keyboard/Kconfig16
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/adp5588-keys.c74
-rw-r--r--drivers/input/keyboard/atkbd.c12
-rw-r--r--drivers/input/keyboard/gpio_keys_polled.c261
-rw-r--r--drivers/input/misc/pcf8574_keypad.c23
-rw-r--r--drivers/input/mouse/appletouch.c2
-rw-r--r--drivers/input/mouse/synaptics.h3
-rw-r--r--drivers/input/serio/gscps2.c2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h11
-rw-r--r--drivers/input/serio/serio_raw.c1
-rw-r--r--drivers/input/tablet/acecad.c3
-rw-r--r--drivers/input/tablet/aiptek.c28
-rw-r--r--drivers/input/tablet/wacom_wac.c12
-rw-r--r--drivers/input/touchscreen/ad7879.c32
-rw-r--r--drivers/input/touchscreen/bu21013_ts.c2
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c1
-rw-r--r--drivers/isdn/icn/icn.c7
-rw-r--r--drivers/isdn/mISDN/socket.c2
-rw-r--r--drivers/leds/Kconfig70
-rw-r--r--drivers/leds/Makefile2
-rw-r--r--drivers/leds/led-class.c105
-rw-r--r--drivers/leds/led-triggers.c2
-rw-r--r--drivers/leds/leds-gpio.c2
-rw-r--r--drivers/leds/leds-lp5521.c837
-rw-r--r--drivers/leds/leds-lp5523.c1069
-rw-r--r--drivers/leds/leds-net5501.c2
-rw-r--r--drivers/leds/leds-ss4200.c1
-rw-r--r--drivers/leds/ledtrig-timer.c124
-rw-r--r--drivers/macintosh/Kconfig1
-rw-r--r--drivers/macintosh/adb-iop.c4
-rw-r--r--drivers/md/dm-table.c10
-rw-r--r--drivers/md/md.c68
-rw-r--r--drivers/md/raid1.c1
-rw-r--r--drivers/md/raid10.c2
-rw-r--r--drivers/media/IR/ir-keytable.c8
-rw-r--r--drivers/media/Kconfig1
-rw-r--r--drivers/media/common/saa7146_hlp.c8
-rw-r--r--drivers/media/common/saa7146_i2c.c1
-rw-r--r--drivers/media/common/saa7146_video.c16
-rw-r--r--drivers/media/common/tuners/Kconfig8
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c1
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c1
-rw-r--r--drivers/media/dvb/frontends/Kconfig5
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.c1
-rw-r--r--drivers/media/dvb/ngene/ngene-core.c1
-rw-r--r--drivers/media/dvb/ngene/ngene-dvb.c1
-rw-r--r--drivers/media/dvb/ngene/ngene-i2c.c1
-rw-r--r--drivers/media/radio/radio-aimslab.c16
-rw-r--r--drivers/media/radio/radio-aztech.c6
-rw-r--r--drivers/media/radio/radio-cadet.c12
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c6
-rw-r--r--drivers/media/radio/radio-gemtek.c14
-rw-r--r--drivers/media/radio/radio-maestro.c14
-rw-r--r--drivers/media/radio/radio-maxiradio.c2
-rw-r--r--drivers/media/radio/radio-miropcm20.c6
-rw-r--r--drivers/media/radio/radio-mr800.c1
-rw-r--r--drivers/media/radio/radio-rtrack2.c10
-rw-r--r--drivers/media/radio/radio-sf16fmi.c7
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c11
-rw-r--r--drivers/media/radio/radio-si4713.c5
-rw-r--r--drivers/media/radio/radio-tea5764.c49
-rw-r--r--drivers/media/radio/radio-terratec.c8
-rw-r--r--drivers/media/radio/radio-timb.c5
-rw-r--r--drivers/media/radio/radio-trust.c18
-rw-r--r--drivers/media/radio/radio-typhoon.c16
-rw-r--r--drivers/media/radio/radio-zoltrix.c30
-rw-r--r--drivers/media/radio/si470x/radio-si470x.h1
-rw-r--r--drivers/media/video/Kconfig2
-rw-r--r--drivers/media/video/arv.c2
-rw-r--r--drivers/media/video/au0828/au0828-cards.c4
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c22
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c118
-rw-r--r--drivers/media/video/bw-qcam.c2
-rw-r--r--drivers/media/video/c-qcam.c2
-rw-r--r--drivers/media/video/cafe_ccic.c6
-rw-r--r--drivers/media/video/cx18/cx18-alsa-pcm.c8
-rw-r--r--drivers/media/video/cx18/cx18-i2c.c8
-rw-r--r--drivers/media/video/cx18/cx18-streams.c2
-rw-r--r--drivers/media/video/cx231xx/cx231xx-417.c6
-rw-r--r--drivers/media/video/cx231xx/cx231xx-cards.c4
-rw-r--r--drivers/media/video/cx23885/cx23885-417.c9
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c2
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c9
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c1
-rw-r--r--drivers/media/video/cx88/cx88-cards.c9
-rw-r--r--drivers/media/video/cx88/cx88-video.c8
-rw-r--r--drivers/media/video/davinci/vpfe_capture.c1
-rw-r--r--drivers/media/video/davinci/vpif_capture.c1
-rw-r--r--drivers/media/video/davinci/vpif_display.c2
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c18
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c2
-rw-r--r--drivers/media/video/fsl-viu.c2
-rw-r--r--drivers/media/video/gspca/sonixj.c416
-rw-r--r--drivers/media/video/imx074.c2
-rw-r--r--drivers/media/video/ir-kbd-i2c.c1
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c22
-rw-r--r--drivers/media/video/meye.c14
-rw-r--r--drivers/media/video/mx2_camera.c13
-rw-r--r--drivers/media/video/mx3_camera.c4
-rw-r--r--drivers/media/video/mxb.c12
-rw-r--r--drivers/media/video/omap1_camera.c16
-rw-r--r--drivers/media/video/ov6650.c6
-rw-r--r--drivers/media/video/pms.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c6
-rw-r--r--drivers/media/video/pwc/pwc-if.c1
-rw-r--r--drivers/media/video/s2255drv.c1
-rw-r--r--drivers/media/video/s5p-fimc/fimc-capture.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c32
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c4
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c1
-rw-r--r--drivers/media/video/saa7164/saa7164.h1
-rw-r--r--drivers/media/video/se401.c7
-rw-r--r--drivers/media/video/sh_vou.c15
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c2
-rw-r--r--drivers/media/video/soc_camera.c2
-rw-r--r--drivers/media/video/stk-webcam.c4
-rw-r--r--drivers/media/video/tlg2300/pd-main.c13
-rw-r--r--drivers/media/video/usbvideo/vicam.c29
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c6
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c1
-rw-r--r--drivers/media/video/uvc/uvc_ctrl.c48
-rw-r--r--drivers/media/video/uvc/uvc_queue.c133
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c185
-rw-r--r--drivers/media/video/uvc/uvc_video.c3
-rw-r--r--drivers/media/video/uvc/uvcvideo.h10
-rw-r--r--drivers/media/video/v4l2-common.c15
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c1
-rw-r--r--drivers/media/video/v4l2-dev.c72
-rw-r--r--drivers/media/video/v4l2-device.c1
-rw-r--r--drivers/media/video/via-camera.c2
-rw-r--r--drivers/media/video/vino.c4
-rw-r--r--drivers/media/video/w9966.c2
-rw-r--r--drivers/media/video/zoran/zoran.h1
-rw-r--r--drivers/media/video/zoran/zoran_card.c6
-rw-r--r--drivers/media/video/zoran/zoran_driver.c27
-rw-r--r--drivers/message/fusion/mptfc.c7
-rw-r--r--drivers/message/fusion/mptsas.c4
-rw-r--r--drivers/message/fusion/mptspi.c4
-rw-r--r--drivers/message/i2o/i2o_scsi.c6
-rw-r--r--drivers/misc/apds9802als.c3
-rw-r--r--drivers/misc/bh1770glc.c8
-rw-r--r--drivers/misc/isl29020.c8
-rw-r--r--drivers/misc/sgi-xp/xpc_partition.c25
-rw-r--r--drivers/mmc/core/core.c2
-rw-r--r--drivers/mmc/core/mmc.c8
-rw-r--r--drivers/mmc/core/sdio.c51
-rw-r--r--drivers/mmc/core/sdio_bus.c33
-rw-r--r--drivers/mmc/host/omap_hsmmc.c2
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c12
-rw-r--r--drivers/mmc/host/sdhci-pci.c31
-rw-r--r--drivers/mmc/host/sdhci-pxa.c4
-rw-r--r--drivers/mmc/host/sdhci.c54
-rw-r--r--drivers/mmc/host/sdhci.h9
-rw-r--r--drivers/mmc/host/ushc.c30
-rw-r--r--drivers/mtd/maps/pxa2xx-flash.c2
-rw-r--r--drivers/mtd/nand/omap2.c1
-rw-r--r--drivers/mtd/ubi/io.c37
-rw-r--r--drivers/mtd/ubi/scan.c20
-rw-r--r--drivers/net/3c59x.c6
-rw-r--r--drivers/net/8139cp.c10
-rw-r--r--drivers/net/Kconfig18
-rw-r--r--drivers/net/Makefile1
-rw-r--r--drivers/net/atl1c/atl1c_hw.c2
-rw-r--r--drivers/net/atlx/atl1.c1
-rw-r--r--drivers/net/au1000_eth.c10
-rw-r--r--drivers/net/b44.c11
-rw-r--r--drivers/net/benet/be_cmds.c2
-rw-r--r--drivers/net/benet/be_main.c6
-rw-r--r--drivers/net/bnx2x/bnx2x.h4
-rw-r--r--drivers/net/bnx2x/bnx2x_cmn.c44
-rw-r--r--drivers/net/bnx2x/bnx2x_hsi.h9
-rw-r--r--drivers/net/bnx2x/bnx2x_init_ops.h4
-rw-r--r--drivers/net/bnx2x/bnx2x_link.c57
-rw-r--r--drivers/net/bnx2x/bnx2x_main.c2
-rw-r--r--drivers/net/bonding/bond_main.c21
-rw-r--r--drivers/net/bonding/bonding.h12
-rw-r--r--drivers/net/caif/caif_shm_u5500.c2
-rw-r--r--drivers/net/caif/caif_shmcore.c2
-rw-r--r--drivers/net/caif/caif_spi.c61
-rw-r--r--drivers/net/caif/caif_spi_slave.c13
-rw-r--r--drivers/net/can/at91_can.c2
-rw-r--r--drivers/net/can/pch_can.c10
-rw-r--r--drivers/net/cxgb3/cxgb3_main.c1
-rw-r--r--drivers/net/cxgb4/cxgb4_main.c1
-rw-r--r--drivers/net/cxgb4/t4_hw.c2
-rw-r--r--drivers/net/cxgb4vf/cxgb4vf_main.c131
-rw-r--r--drivers/net/cxgb4vf/sge.c122
-rw-r--r--drivers/net/cxgb4vf/t4vf_common.h1
-rw-r--r--drivers/net/cxgb4vf/t4vf_hw.c113
-rw-r--r--drivers/net/e1000/e1000_main.c12
-rw-r--r--drivers/net/ehea/ehea_ethtool.c9
-rw-r--r--drivers/net/ehea/ehea_main.c25
-rw-r--r--drivers/net/enic/enic_main.c3
-rw-r--r--drivers/net/gianfar.c7
-rw-r--r--drivers/net/gianfar_ethtool.c5
-rw-r--r--drivers/net/ibm_newemac/core.c1
-rw-r--r--drivers/net/ifb.c2
-rw-r--r--drivers/net/ipg.c6
-rw-r--r--drivers/net/irda/sh_sir.c2
-rw-r--r--drivers/net/ixgbe/ixgbe_main.c63
-rw-r--r--drivers/net/jme.c4
-rw-r--r--drivers/net/mlx4/fw.c4
-rw-r--r--drivers/net/netxen/netxen_nic_main.c4
-rw-r--r--drivers/net/pch_gbe/pch_gbe_main.c6
-rw-r--r--drivers/net/pch_gbe/pch_gbe_param.c8
-rw-r--r--drivers/net/pcmcia/axnet_cs.c30
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c1
-rw-r--r--drivers/net/phy/Kconfig2
-rw-r--r--drivers/net/phy/icplus.c59
-rw-r--r--drivers/net/phy/marvell.c182
-rw-r--r--drivers/net/ppp_generic.c43
-rw-r--r--drivers/net/pppoe.c2
-rw-r--r--drivers/net/qlcnic/qlcnic_main.c1
-rw-r--r--drivers/net/qlge/qlge.h1
-rw-r--r--drivers/net/qlge/qlge_main.c7
-rw-r--r--drivers/net/qlge/qlge_mpi.c12
-rw-r--r--drivers/net/r8169.c38
-rw-r--r--drivers/net/sfc/efx.c43
-rw-r--r--drivers/net/sfc/net_driver.h2
-rw-r--r--drivers/net/sfc/nic.c6
-rw-r--r--drivers/net/skge.c1
-rw-r--r--drivers/net/smsc911x.h2
-rw-r--r--drivers/net/stmmac/stmmac_main.c4
-rw-r--r--drivers/net/tile/Makefile10
-rw-r--r--drivers/net/tile/tilepro.c2406
-rw-r--r--drivers/net/tulip/de2104x.c1
-rw-r--r--drivers/net/tulip/dmfe.c6
-rw-r--r--drivers/net/ucc_geth.c25
-rw-r--r--drivers/net/ucc_geth.h3
-rw-r--r--drivers/net/usb/hso.c14
-rw-r--r--drivers/net/usb/usbnet.c11
-rw-r--r--drivers/net/virtio_net.c12
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c2
-rw-r--r--drivers/net/vmxnet3/vmxnet3_int.h8
-rw-r--r--drivers/net/wan/hd64572.c5
-rw-r--r--drivers/net/wan/x25_asy.c13
-rw-r--r--drivers/net/wireless/ath/ath5k/base.c13
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_hw.c3
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.c73
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.h9
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h5
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom.h27
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_9287.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_def.c23
-rw-r--r--drivers/net/wireless/ath/ath9k/hif_usb.c47
-rw-r--r--drivers/net/wireless/ath/ath9k/htc.h3
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_init.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_main.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_txrx.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c18
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/mac.c3
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c51
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c15
-rw-r--r--drivers/net/wireless/ath/ath9k/reg.h15
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c22
-rw-r--r--drivers/net/wireless/ath/carl9170/fw.c3
-rw-r--r--drivers/net/wireless/ath/carl9170/main.c5
-rw-r--r--drivers/net/wireless/ath/carl9170/tx.c2
-rw-r--r--drivers/net/wireless/ath/carl9170/usb.c8
-rw-r--r--drivers/net/wireless/b43/sdio.c1
-rw-r--r--drivers/net/wireless/ipw2x00/libipw_module.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c3
-rw-r--r--drivers/net/wireless/libertas/cfg.c5
-rw-r--r--drivers/net/wireless/libertas/dev.h1
-rw-r--r--drivers/net/wireless/libertas/if_sdio.c1
-rw-r--r--drivers/net/wireless/libertas/if_spi.c1
-rw-r--r--drivers/net/wireless/libertas/main.c9
-rw-r--r--drivers/net/wireless/orinoco/main.c18
-rw-r--r--drivers/net/wireless/orinoco/orinoco_cs.c14
-rw-r--r--drivers/net/wireless/orinoco/orinoco_usb.c1
-rw-r--r--drivers/net/wireless/orinoco/scan.c8
-rw-r--r--drivers/net/wireless/orinoco/scan.h1
-rw-r--r--drivers/net/wireless/orinoco/spectrum_cs.c14
-rw-r--r--drivers/net/wireless/orinoco/wext.c4
-rw-r--r--drivers/net/wireless/rt2x00/Kconfig3
-rw-r--r--drivers/net/xen-netfront.c4
-rw-r--r--drivers/parisc/dino.c1
-rw-r--r--drivers/parisc/eisa.c3
-rw-r--r--drivers/parisc/eisa_eeprom.c1
-rw-r--r--drivers/parisc/gsc.c3
-rw-r--r--drivers/parisc/iosapic.c8
-rw-r--r--drivers/parisc/led.c17
-rw-r--r--drivers/parisc/superio.c3
-rw-r--r--drivers/pci/Makefile1
-rw-r--r--drivers/pci/bus.c53
-rw-r--r--drivers/pci/dmar.c5
-rw-r--r--drivers/pci/hotplug/ibmphp_ebda.c6
-rw-r--r--drivers/pci/pci-sysfs.c23
-rw-r--r--drivers/pci/pci.c12
-rw-r--r--drivers/pci/pci.h7
-rw-r--r--drivers/pci/proc.c3
-rw-r--r--drivers/pci/quirks.c44
-rw-r--r--drivers/pci/xen-pcifront.c6
-rw-r--r--drivers/pcmcia/pd6729.c8
-rw-r--r--drivers/pcmcia/pd6729.h2
-rw-r--r--drivers/pcmcia/pxa2xx_sharpsl.c2
-rw-r--r--drivers/pcmcia/sa1100_assabet.c2
-rw-r--r--drivers/pcmcia/sa1100_cerf.c2
-rw-r--r--drivers/pcmcia/sa1100_generic.c2
-rw-r--r--drivers/pcmcia/sa1100_h3600.c2
-rw-r--r--drivers/pcmcia/sa1100_shannon.c2
-rw-r--r--drivers/pcmcia/sa1100_simpad.c2
-rw-r--r--drivers/pcmcia/soc_common.c10
-rw-r--r--drivers/platform/x86/asus-laptop.c97
-rw-r--r--drivers/platform/x86/eeepc-wmi.c4
-rw-r--r--drivers/platform/x86/hp-wmi.c2
-rw-r--r--drivers/platform/x86/ibm_rtl.c34
-rw-r--r--drivers/platform/x86/msi-wmi.c16
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c1
-rw-r--r--drivers/platform/x86/toshiba_acpi.c1
-rw-r--r--drivers/platform/x86/wmi.c2
-rw-r--r--drivers/pnp/isapnp/proc.c1
-rw-r--r--drivers/pnp/pnpacpi/core.c2
-rw-r--r--drivers/rapidio/rio.c4
-rw-r--r--drivers/regulator/core.c30
-rw-r--r--drivers/regulator/mc13783-regulator.c4
-rw-r--r--drivers/regulator/tps6586x-regulator.c33
-rw-r--r--drivers/regulator/twl-regulator.c6
-rw-r--r--drivers/rtc/rtc-ds1302.c2
-rw-r--r--drivers/rtc/rtc-sh.c4
-rw-r--r--drivers/s390/block/dasd_eer.c1
-rw-r--r--drivers/s390/char/fs3270.c1
-rw-r--r--drivers/s390/char/tape_char.c1
-rw-r--r--drivers/s390/char/tape_core.c68
-rw-r--r--drivers/s390/char/vmlogrdr.c37
-rw-r--r--drivers/s390/char/vmur.c1
-rw-r--r--drivers/s390/cio/css.c2
-rw-r--r--drivers/s390/cio/device.c11
-rw-r--r--drivers/s390/cio/qdio_thinint.c2
-rw-r--r--drivers/s390/crypto/zcrypt_api.c1
-rw-r--r--drivers/s390/net/qeth_core.h9
-rw-r--r--drivers/s390/net/qeth_core_main.c55
-rw-r--r--drivers/s390/scsi/zfcp_erp.c11
-rw-r--r--drivers/s390/scsi/zfcp_fc.h2
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c14
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c5
-rw-r--r--drivers/s390/scsi/zfcp_unit.c4
-rw-r--r--drivers/scsi/3w-9xxx.c4
-rw-r--r--drivers/scsi/3w-sas.c4
-rw-r--r--drivers/scsi/3w-xxxx.c4
-rw-r--r--drivers/scsi/53c700.c8
-rw-r--r--drivers/scsi/BusLogic.c3
-rw-r--r--drivers/scsi/BusLogic.h2
-rw-r--r--drivers/scsi/NCR5380.c3
-rw-r--r--drivers/scsi/NCR5380.h2
-rw-r--r--drivers/scsi/NCR53c406a.c4
-rw-r--r--drivers/scsi/a100u2w.c4
-rw-r--r--drivers/scsi/aacraid/linit.c4
-rw-r--r--drivers/scsi/advansys.c4
-rw-r--r--drivers/scsi/aha152x.c4
-rw-r--r--drivers/scsi/aha1542.c4
-rw-r--r--drivers/scsi/aha1542.h2
-rw-r--r--drivers/scsi/aha1740.c4
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c4
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c4
-rw-r--r--drivers/scsi/aic7xxx_old.c4
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c7
-rw-r--r--drivers/scsi/arm/acornscsi.c4
-rw-r--r--drivers/scsi/arm/fas216.c10
-rw-r--r--drivers/scsi/arm/fas216.h18
-rw-r--r--drivers/scsi/atari_NCR5380.c4
-rw-r--r--drivers/scsi/atari_scsi.c17
-rw-r--r--drivers/scsi/atp870u.c4
-rw-r--r--drivers/scsi/bfa/bfa.h48
-rw-r--r--drivers/scsi/bfa/bfa_cb_ioim.h22
-rw-r--r--drivers/scsi/bfa/bfa_core.c178
-rw-r--r--drivers/scsi/bfa/bfa_cs.h24
-rw-r--r--drivers/scsi/bfa/bfa_defs.h54
-rw-r--r--drivers/scsi/bfa/bfa_defs_fcs.h48
-rw-r--r--drivers/scsi/bfa/bfa_defs_svc.h82
-rw-r--r--drivers/scsi/bfa/bfa_drv.c6
-rw-r--r--drivers/scsi/bfa/bfa_fc.h30
-rw-r--r--drivers/scsi/bfa/bfa_fcbuild.c196
-rw-r--r--drivers/scsi/bfa/bfa_fcpim.c351
-rw-r--r--drivers/scsi/bfa/bfa_fcpim.h18
-rw-r--r--drivers/scsi/bfa/bfa_fcs.c335
-rw-r--r--drivers/scsi/bfa/bfa_fcs.h43
-rw-r--r--drivers/scsi/bfa/bfa_fcs_fcpim.c34
-rw-r--r--drivers/scsi/bfa/bfa_fcs_lport.c468
-rw-r--r--drivers/scsi/bfa/bfa_fcs_rport.c198
-rw-r--r--drivers/scsi/bfa/bfa_hw_cb.c16
-rw-r--r--drivers/scsi/bfa/bfa_hw_ct.c22
-rw-r--r--drivers/scsi/bfa/bfa_ioc.c397
-rw-r--r--drivers/scsi/bfa/bfa_ioc.h108
-rw-r--r--drivers/scsi/bfa/bfa_ioc_cb.c90
-rw-r--r--drivers/scsi/bfa/bfa_ioc_ct.c167
-rw-r--r--drivers/scsi/bfa/bfa_modules.h6
-rw-r--r--drivers/scsi/bfa/bfa_os_inc.h82
-rw-r--r--drivers/scsi/bfa/bfa_port.c40
-rw-r--r--drivers/scsi/bfa/bfa_svc.c504
-rw-r--r--drivers/scsi/bfa/bfa_svc.h41
-rw-r--r--drivers/scsi/bfa/bfad.c73
-rw-r--r--drivers/scsi/bfa/bfad_attr.c38
-rw-r--r--drivers/scsi/bfa/bfad_debugfs.c4
-rw-r--r--drivers/scsi/bfa/bfad_drv.h5
-rw-r--r--drivers/scsi/bfa/bfad_im.c78
-rw-r--r--drivers/scsi/bfa/bfi.h58
-rw-r--r--drivers/scsi/bfa/bfi_ms.h50
-rw-r--r--drivers/scsi/cxgbi/cxgb4i/cxgb4i.c3
-rw-r--r--drivers/scsi/dc395x.c3
-rw-r--r--drivers/scsi/device_handler/scsi_dh_rdac.c2
-rw-r--r--drivers/scsi/dpt_i2o.c4
-rw-r--r--drivers/scsi/dpti.h2
-rw-r--r--drivers/scsi/dtc.h2
-rw-r--r--drivers/scsi/eata.c7
-rw-r--r--drivers/scsi/eata_pio.c4
-rw-r--r--drivers/scsi/esp_scsi.c4
-rw-r--r--drivers/scsi/fcoe/fcoe.c18
-rw-r--r--drivers/scsi/fcoe/libfcoe.c2
-rw-r--r--drivers/scsi/fd_mcs.c4
-rw-r--r--drivers/scsi/fdomain.c4
-rw-r--r--drivers/scsi/fnic/fnic.h2
-rw-r--r--drivers/scsi/fnic/fnic_scsi.c4
-rw-r--r--drivers/scsi/g_NCR5380.h2
-rw-r--r--drivers/scsi/gdth.c14
-rw-r--r--drivers/scsi/hpsa.c16
-rw-r--r--drivers/scsi/hptiop.c4
-rw-r--r--drivers/scsi/ibmmca.c6
-rw-r--r--drivers/scsi/ibmvscsi/ibmvfc.c4
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c4
-rw-r--r--drivers/scsi/imm.c4
-rw-r--r--drivers/scsi/in2000.c4
-rw-r--r--drivers/scsi/in2000.h2
-rw-r--r--drivers/scsi/initio.c4
-rw-r--r--drivers/scsi/ipr.c6
-rw-r--r--drivers/scsi/ipr.h1
-rw-r--r--drivers/scsi/ips.c6
-rw-r--r--drivers/scsi/libfc/fc_disc.c5
-rw-r--r--drivers/scsi/libfc/fc_fcp.c28
-rw-r--r--drivers/scsi/libfc/fc_lport.c12
-rw-r--r--drivers/scsi/libfc/fc_rport.c4
-rw-r--r--drivers/scsi/libiscsi.c4
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c4
-rw-r--r--drivers/scsi/lpfc/lpfc.h12
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c7
-rw-r--r--drivers/scsi/lpfc/lpfc_bsg.c4
-rw-r--r--drivers/scsi/lpfc/lpfc_crtn.h4
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c439
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c437
-rw-r--r--drivers/scsi/lpfc/lpfc_hw.h41
-rw-r--r--drivers/scsi/lpfc/lpfc_hw4.h167
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c102
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c28
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c13
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c458
-rw-r--r--drivers/scsi/lpfc/lpfc_sli4.h9
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h2
-rw-r--r--drivers/scsi/mac53c94.c4
-rw-r--r--drivers/scsi/megaraid.c6
-rw-r--r--drivers/scsi/megaraid.h2
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c7
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c130
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h7
-rw-r--r--drivers/scsi/mesh.c4
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_scsih.c4
-rw-r--r--drivers/scsi/ncr53c8xx.c4
-rw-r--r--drivers/scsi/nsp32.c7
-rw-r--r--drivers/scsi/osd/osd_initiator.c244
-rw-r--r--drivers/scsi/pas16.h2
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c4
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.h3
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c4
-rw-r--r--drivers/scsi/pm8001/pm8001_sas.h1
-rw-r--r--drivers/scsi/pmcraid.c137
-rw-r--r--drivers/scsi/pmcraid.h27
-rw-r--r--drivers/scsi/ppa.c4
-rw-r--r--drivers/scsi/ps3rom.c4
-rw-r--r--drivers/scsi/qla1280.c4
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c4
-rw-r--r--drivers/scsi/qla2xxx/qla_bsg.c125
-rw-r--r--drivers/scsi/qla2xxx/qla_bsg.h2
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h3
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h1
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c28
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c5
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c26
-rw-r--r--drivers/scsi/qla2xxx/qla_nx.c1
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c215
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h4
-rw-r--r--drivers/scsi/qla4xxx/ql4_dbg.c101
-rw-r--r--drivers/scsi/qla4xxx/ql4_def.h20
-rw-r--r--drivers/scsi/qla4xxx/ql4_fw.h3
-rw-r--r--drivers/scsi/qla4xxx/ql4_glbl.h1
-rw-r--r--drivers/scsi/qla4xxx/ql4_init.c10
-rw-r--r--drivers/scsi/qla4xxx/ql4_iocb.c10
-rw-r--r--drivers/scsi/qla4xxx/ql4_isr.c16
-rw-r--r--drivers/scsi/qla4xxx/ql4_mbx.c11
-rw-r--r--drivers/scsi/qla4xxx/ql4_nx.c89
-rw-r--r--drivers/scsi/qla4xxx/ql4_nx.h5
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c116
-rw-r--r--drivers/scsi/qla4xxx/ql4_version.h2
-rw-r--r--drivers/scsi/qlogicfas408.c4
-rw-r--r--drivers/scsi/qlogicfas408.h3
-rw-r--r--drivers/scsi/qlogicpti.c4
-rw-r--r--drivers/scsi/scsi.c18
-rw-r--r--drivers/scsi/scsi_debug.c4
-rw-r--r--drivers/scsi/scsi_error.c50
-rw-r--r--drivers/scsi/scsi_lib.c11
-rw-r--r--drivers/scsi/scsi_sysfs.c3
-rw-r--r--drivers/scsi/sd.c24
-rw-r--r--drivers/scsi/sr_ioctl.c9
-rw-r--r--drivers/scsi/stex.c4
-rw-r--r--drivers/scsi/sun3_NCR5380.c4
-rw-r--r--drivers/scsi/sun3_scsi.h3
-rw-r--r--drivers/scsi/sym53c416.c4
-rw-r--r--drivers/scsi/sym53c416.h2
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.c4
-rw-r--r--drivers/scsi/t128.h3
-rw-r--r--drivers/scsi/tmscsim.c4
-rw-r--r--drivers/scsi/u14-34f.c6
-rw-r--r--drivers/scsi/ultrastor.c4
-rw-r--r--drivers/scsi/ultrastor.h3
-rw-r--r--drivers/scsi/vmw_pvscsi.c4
-rw-r--r--drivers/scsi/wd33c93.c6
-rw-r--r--drivers/scsi/wd33c93.h3
-rw-r--r--drivers/scsi/wd7000.c4
-rw-r--r--drivers/serial/8250.c2
-rw-r--r--drivers/serial/8250_pci.c5
-rw-r--r--drivers/serial/bfin_5xx.c31
-rw-r--r--drivers/serial/crisv10.c24
-rw-r--r--drivers/serial/kgdboc.c60
-rw-r--r--drivers/serial/mfd.c24
-rw-r--r--drivers/serial/serial_core.c1
-rw-r--r--drivers/sh/clk/core.c112
-rw-r--r--drivers/sh/clk/cpg.c7
-rw-r--r--drivers/sh/intc/core.c2
-rw-r--r--drivers/sh/intc/dynamic.c2
-rw-r--r--drivers/sh/intc/virq.c2
-rw-r--r--drivers/spi/atmel_spi.c6
-rw-r--r--drivers/spi/dw_spi.c5
-rw-r--r--drivers/spi/spi.c98
-rw-r--r--drivers/spi/spi_bfin5xx.c22
-rw-r--r--drivers/ssb/b43_pci_bridge.c1
-rw-r--r--drivers/staging/asus_oled/asus_oled.c8
-rw-r--r--drivers/staging/ath6kl/Kconfig2
-rw-r--r--drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c4
-rw-r--r--drivers/staging/ath6kl/os/linux/ar6000_drv.c5
-rw-r--r--drivers/staging/ath6kl/os/linux/ar6000_raw_if.c4
-rw-r--r--drivers/staging/ath6kl/os/linux/cfg80211.c7
-rw-r--r--drivers/staging/ath6kl/os/linux/include/athendpack_linux.h0
-rw-r--r--drivers/staging/ath6kl/os/linux/include/athstartpack_linux.h0
-rw-r--r--drivers/staging/batman-adv/hard-interface.c34
-rw-r--r--drivers/staging/batman-adv/routing.c12
-rw-r--r--drivers/staging/batman-adv/routing.h4
-rw-r--r--drivers/staging/batman-adv/soft-interface.c14
-rw-r--r--drivers/staging/batman-adv/unicast.c2
-rw-r--r--drivers/staging/bcm/Bcmchar.c49
-rw-r--r--drivers/staging/brcm80211/README8
-rw-r--r--drivers/staging/brcm80211/TODO4
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_linux.c6
-rw-r--r--drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c12
-rw-r--r--drivers/staging/brcm80211/sys/wl_mac80211.c2
-rw-r--r--drivers/staging/comedi/drivers/dt9812.c2
-rw-r--r--drivers/staging/comedi/drivers/usbdux.c8
-rw-r--r--drivers/staging/comedi/drivers/usbduxfast.c4
-rw-r--r--drivers/staging/cpia/cpia.c6
-rw-r--r--drivers/staging/cx25821/cx25821-video.c8
-rw-r--r--drivers/staging/cx25821/cx25821-video.h2
-rw-r--r--drivers/staging/easycap/easycap.h2
-rw-r--r--drivers/staging/frontier/tranzport.c2
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c1
-rw-r--r--drivers/staging/go7007/go7007-driver.c2
-rw-r--r--drivers/staging/hv/hv_utils.c3
-rw-r--r--drivers/staging/hv/storvsc_drv.c7
-rw-r--r--drivers/staging/iio/accel/adis16220_core.c2
-rw-r--r--drivers/staging/intel_sst/intel_sst_app_interface.c285
-rw-r--r--drivers/staging/intel_sst/intel_sst_common.h4
-rw-r--r--drivers/staging/intel_sst/intel_sst_stream_encoded.c2
-rw-r--r--drivers/staging/keucr/init.c18
-rw-r--r--drivers/staging/keucr/ms.c14
-rw-r--r--drivers/staging/keucr/msscsi.c6
-rw-r--r--drivers/staging/keucr/scsiglue.c4
-rw-r--r--drivers/staging/keucr/sdscsi.c4
-rw-r--r--drivers/staging/keucr/smilsub.c18
-rw-r--r--drivers/staging/keucr/transport.c2
-rw-r--r--drivers/staging/line6/control.c204
-rw-r--r--drivers/staging/line6/midi.c4
-rw-r--r--drivers/staging/line6/pcm.c4
-rw-r--r--drivers/staging/line6/pod.c32
-rw-r--r--drivers/staging/line6/toneport.c4
-rw-r--r--drivers/staging/line6/variax.c12
-rw-r--r--drivers/staging/msm/msm_fb.c4
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.c4
-rw-r--r--drivers/staging/quickstart/quickstart.c10
-rw-r--r--drivers/staging/rt2860/common/cmm_aes.c2
-rw-r--r--drivers/staging/rt2860/usb_main_dev.c2
-rw-r--r--drivers/staging/rtl8187se/r8185b_init.c30
-rw-r--r--drivers/staging/rtl8192e/r8192E_core.c3
-rw-r--r--drivers/staging/rtl8712/osdep_service.h3
-rw-r--r--drivers/staging/rtl8712/usb_halinit.c2
-rw-r--r--drivers/staging/samsung-laptop/samsung-laptop.c2
-rw-r--r--drivers/staging/smbfs/inode.c2
-rw-r--r--drivers/staging/solo6x10/solo6010-v4l2-enc.c2
-rw-r--r--drivers/staging/solo6x10/solo6010-v4l2.c2
-rw-r--r--drivers/staging/speakup/buffers.c1
-rw-r--r--drivers/staging/speakup/fakekey.c1
-rw-r--r--drivers/staging/spectra/ffsport.c2
-rw-r--r--drivers/staging/stradis/Kconfig2
-rw-r--r--drivers/staging/stradis/stradis.c11
-rw-r--r--drivers/staging/tidspbridge/Kconfig1
-rw-r--r--drivers/staging/tidspbridge/Makefile7
-rw-r--r--drivers/staging/tidspbridge/core/_deh.h5
-rw-r--r--drivers/staging/tidspbridge/core/_tiomap.h19
-rw-r--r--drivers/staging/tidspbridge/core/dsp-mmu.c317
-rw-r--r--drivers/staging/tidspbridge/core/io_sm.c180
-rw-r--r--drivers/staging/tidspbridge/core/tiomap3430.c1083
-rw-r--r--drivers/staging/tidspbridge/core/tiomap3430_pwr.c4
-rw-r--r--drivers/staging/tidspbridge/core/tiomap_io.c17
-rw-r--r--drivers/staging/tidspbridge/core/ue_deh.c115
-rw-r--r--drivers/staging/tidspbridge/hw/EasiGlobal.h41
-rw-r--r--drivers/staging/tidspbridge/hw/MMUAccInt.h76
-rw-r--r--drivers/staging/tidspbridge/hw/MMURegAcM.h225
-rw-r--r--drivers/staging/tidspbridge/hw/hw_defs.h58
-rw-r--r--drivers/staging/tidspbridge/hw/hw_mmu.c562
-rw-r--r--drivers/staging/tidspbridge/hw/hw_mmu.h163
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/cfgdefs.h1
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/dev.h24
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/dmm.h75
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/drv.h10
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/dsp-mmu.h67
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/dspdefs.h44
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/dspioctl.h7
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/proc.h46
-rw-r--r--drivers/staging/tidspbridge/pmgr/dev.c63
-rw-r--r--drivers/staging/tidspbridge/pmgr/dmm.c533
-rw-r--r--drivers/staging/tidspbridge/pmgr/dspapi.c34
-rw-r--r--drivers/staging/tidspbridge/rmgr/drv.c15
-rw-r--r--drivers/staging/tidspbridge/rmgr/drv_interface.c2
-rw-r--r--drivers/staging/tidspbridge/rmgr/node.c48
-rw-r--r--drivers/staging/tidspbridge/rmgr/proc.c197
-rw-r--r--drivers/staging/tm6000/tm6000-cards.c4
-rw-r--r--drivers/staging/tm6000/tm6000-i2c.c1
-rw-r--r--drivers/staging/tm6000/tm6000-video.c1
-rw-r--r--drivers/staging/udlfb/udlfb.c4
-rw-r--r--drivers/staging/vt6656/main_usb.c3
-rw-r--r--drivers/staging/westbridge/astoria/api/src/cyasusb.c1
-rw-r--r--drivers/staging/westbridge/astoria/block/cyasblkdev_block.c2
-rw-r--r--drivers/staging/westbridge/astoria/block/cyasblkdev_queue.c2
-rw-r--r--drivers/staging/winbond/sysdef.h3
-rw-r--r--drivers/staging/wlan-ng/cfg80211.c6
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.c2
-rw-r--r--drivers/staging/zram/zram_sysfs.c4
-rw-r--r--drivers/tty/Makefile11
-rw-r--r--drivers/tty/n_gsm.c (renamed from drivers/char/n_gsm.c)7
-rw-r--r--drivers/tty/n_hdlc.c (renamed from drivers/char/n_hdlc.c)0
-rw-r--r--drivers/tty/n_r3964.c (renamed from drivers/char/n_r3964.c)0
-rw-r--r--drivers/tty/n_tty.c (renamed from drivers/char/n_tty.c)0
-rw-r--r--drivers/tty/pty.c (renamed from drivers/char/pty.c)0
-rw-r--r--drivers/tty/sysrq.c (renamed from drivers/char/sysrq.c)169
-rw-r--r--drivers/tty/tty_audit.c (renamed from drivers/char/tty_audit.c)0
-rw-r--r--drivers/tty/tty_buffer.c (renamed from drivers/char/tty_buffer.c)14
-rw-r--r--drivers/tty/tty_io.c (renamed from drivers/char/tty_io.c)13
-rw-r--r--drivers/tty/tty_ioctl.c (renamed from drivers/char/tty_ioctl.c)0
-rw-r--r--drivers/tty/tty_ldisc.c (renamed from drivers/char/tty_ldisc.c)51
-rw-r--r--drivers/tty/tty_mutex.c (renamed from drivers/char/tty_mutex.c)0
-rw-r--r--drivers/tty/tty_port.c (renamed from drivers/char/tty_port.c)0
-rw-r--r--drivers/tty/vt/.gitignore (renamed from drivers/char/.gitignore)0
-rw-r--r--drivers/tty/vt/Makefile34
-rw-r--r--drivers/tty/vt/consolemap.c (renamed from drivers/char/consolemap.c)0
-rw-r--r--drivers/tty/vt/cp437.uni (renamed from drivers/char/cp437.uni)0
-rw-r--r--drivers/tty/vt/defkeymap.c_shipped (renamed from drivers/char/defkeymap.c_shipped)0
-rw-r--r--drivers/tty/vt/defkeymap.map (renamed from drivers/char/defkeymap.map)0
-rw-r--r--drivers/tty/vt/keyboard.c (renamed from drivers/char/keyboard.c)0
-rw-r--r--drivers/tty/vt/selection.c (renamed from drivers/char/selection.c)0
-rw-r--r--drivers/tty/vt/vc_screen.c (renamed from drivers/char/vc_screen.c)6
-rw-r--r--drivers/tty/vt/vt.c (renamed from drivers/char/vt.c)0
-rw-r--r--drivers/tty/vt/vt_ioctl.c (renamed from drivers/char/vt_ioctl.c)0
-rw-r--r--drivers/uio/uio.c2
-rw-r--r--drivers/uio/uio_cif.c2
-rw-r--r--drivers/uio/uio_netx.c2
-rw-r--r--drivers/usb/atm/ueagle-atm.c7
-rw-r--r--drivers/usb/atm/usbatm.c15
-rw-r--r--drivers/usb/core/Kconfig12
-rw-r--r--drivers/usb/core/devices.c1
-rw-r--r--drivers/usb/core/devio.c8
-rw-r--r--drivers/usb/core/file.c1
-rw-r--r--drivers/usb/core/hcd.c2
-rw-r--r--drivers/usb/core/inode.c1
-rw-r--r--drivers/usb/gadget/Kconfig2
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c2
-rw-r--r--drivers/usb/gadget/composite.c18
-rw-r--r--drivers/usb/gadget/f_fs.c1
-rw-r--r--drivers/usb/gadget/f_hid.c1
-rw-r--r--drivers/usb/gadget/goku_udc.h3
-rw-r--r--drivers/usb/gadget/u_ether.c1
-rw-r--r--drivers/usb/gadget/u_serial.c54
-rw-r--r--drivers/usb/host/Kconfig2
-rw-r--r--drivers/usb/host/ehci-dbg.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c10
-rw-r--r--drivers/usb/host/ehci-mem.c26
-rw-r--r--drivers/usb/host/ehci-mxc.c14
-rw-r--r--drivers/usb/host/ehci-pci.c25
-rw-r--r--drivers/usb/host/ehci-sched.c21
-rw-r--r--drivers/usb/host/ehci.h2
-rw-r--r--drivers/usb/host/isp1362-hcd.c3
-rw-r--r--drivers/usb/host/ohci-jz4740.c2
-rw-r--r--drivers/usb/host/uhci-debug.c1
-rw-r--r--drivers/usb/host/xhci-hub.c7
-rw-r--r--drivers/usb/host/xhci-mem.c173
-rw-r--r--drivers/usb/host/xhci-ring.c1
-rw-r--r--drivers/usb/host/xhci.c91
-rw-r--r--drivers/usb/host/xhci.h31
-rw-r--r--drivers/usb/image/microtek.c6
-rw-r--r--drivers/usb/misc/cypress_cy7c63.c6
-rw-r--r--drivers/usb/misc/iowarrior.c1
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c1
-rw-r--r--drivers/usb/misc/trancevibrator.c2
-rw-r--r--drivers/usb/misc/usbled.c2
-rw-r--r--drivers/usb/misc/usbsevseg.c10
-rw-r--r--drivers/usb/misc/uss720.c4
-rw-r--r--drivers/usb/misc/yurex.c1
-rw-r--r--drivers/usb/mon/mon_bin.c1
-rw-r--r--drivers/usb/mon/mon_stat.c1
-rw-r--r--drivers/usb/musb/blackfin.c80
-rw-r--r--drivers/usb/musb/musb_core.c44
-rw-r--r--drivers/usb/musb/musb_core.h2
-rw-r--r--drivers/usb/musb/musb_gadget.c165
-rw-r--r--drivers/usb/musb/musb_regs.h3
-rw-r--r--drivers/usb/musb/musbhsdma.c14
-rw-r--r--drivers/usb/otg/langwell_otg.c9
-rw-r--r--drivers/usb/serial/ftdi_sio.c5
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h16
-rw-r--r--drivers/usb/serial/option.c2
-rw-r--r--drivers/usb/serial/usb-serial.c4
-rw-r--r--drivers/usb/storage/scsiglue.c4
-rw-r--r--drivers/usb/storage/sierra_ms.c2
-rw-r--r--drivers/usb/storage/uas.c9
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/uwb/allocator.c3
-rw-r--r--drivers/vhost/net.c5
-rw-r--r--drivers/vhost/vhost.c3
-rw-r--r--drivers/video/backlight/adp8860_bl.c8
-rw-r--r--drivers/video/backlight/backlight.c12
-rw-r--r--drivers/video/backlight/l4f00242t03.c2
-rw-r--r--drivers/video/backlight/lms283gf05.c2
-rw-r--r--drivers/video/backlight/mbp_nvidia_bl.c18
-rw-r--r--drivers/video/backlight/pwm_bl.c7
-rw-r--r--drivers/video/backlight/s6e63m0.c7
-rw-r--r--drivers/video/console/vgacon.c1
-rw-r--r--drivers/video/da8xx-fb.c14
-rw-r--r--drivers/video/fbcmap.c69
-rw-r--r--drivers/video/geode/lxfb.h4
-rw-r--r--drivers/video/geode/lxfb_ops.c24
-rw-r--r--drivers/video/modedb.c1
-rw-r--r--drivers/video/mx3fb.c4
-rw-r--r--drivers/video/omap/Kconfig4
-rw-r--r--drivers/video/omap2/vram.c19
-rw-r--r--drivers/video/riva/rivafb-i2c.c1
-rw-r--r--drivers/video/sh_mobile_hdmi.c5
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c25
-rw-r--r--drivers/video/sis/init.c685
-rw-r--r--drivers/video/sis/init.h63
-rw-r--r--drivers/video/sis/init301.c467
-rw-r--r--drivers/video/sis/init301.h43
-rw-r--r--drivers/video/sis/initextlfb.c7
-rw-r--r--drivers/video/sis/osdef.h133
-rw-r--r--drivers/video/sis/sis.h1
-rw-r--r--drivers/video/sis/sis_main.c38
-rw-r--r--drivers/video/sis/vgatypes.h11
-rw-r--r--drivers/video/sis/vstruct.h12
-rw-r--r--drivers/virtio/virtio.c6
-rw-r--r--drivers/virtio/virtio_ring.c3
-rw-r--r--drivers/watchdog/Kconfig3
-rw-r--r--drivers/watchdog/bcm63xx_wdt.c42
-rw-r--r--drivers/watchdog/gef_wdt.c1
-rw-r--r--drivers/watchdog/iTCO_wdt.c8
-rw-r--r--drivers/xen/Makefile5
-rw-r--r--drivers/xen/balloon.c42
-rw-r--r--drivers/xen/events.c147
-rw-r--r--drivers/xen/evtchn.c100
-rw-r--r--drivers/xen/manage.c1
-rw-r--r--drivers/xen/xenfs/privcmd.c14
-rw-r--r--drivers/xen/xenfs/super.c46
-rw-r--r--drivers/zorro/proc.c1
-rw-r--r--fs/autofs4/root.c12
-rw-r--r--fs/bio.c23
-rw-r--r--fs/block_dev.c1
-rw-r--r--fs/btrfs/compression.c15
-rw-r--r--fs/btrfs/ctree.h6
-rw-r--r--fs/btrfs/disk-io.c41
-rw-r--r--fs/btrfs/export.c78
-rw-r--r--fs/btrfs/extent-tree.c77
-rw-r--r--fs/btrfs/extent_io.c77
-rw-r--r--fs/btrfs/extent_io.h3
-rw-r--r--fs/btrfs/file.c99
-rw-r--r--fs/btrfs/free-space-cache.c12
-rw-r--r--fs/btrfs/inode.c299
-rw-r--r--fs/btrfs/ioctl.c87
-rw-r--r--fs/btrfs/ioctl.h14
-rw-r--r--fs/btrfs/ordered-data.c67
-rw-r--r--fs/btrfs/ordered-data.h3
-rw-r--r--fs/btrfs/orphan.c6
-rw-r--r--fs/btrfs/super.c43
-rw-r--r--fs/btrfs/transaction.c5
-rw-r--r--fs/btrfs/tree-log.c21
-rw-r--r--fs/btrfs/volumes.c20
-rw-r--r--fs/btrfs/volumes.h2
-rw-r--r--fs/ceph/addr.c6
-rw-r--r--fs/ceph/caps.c17
-rw-r--r--fs/ceph/dir.c23
-rw-r--r--fs/ceph/file.c65
-rw-r--r--fs/ceph/inode.c50
-rw-r--r--fs/ceph/ioctl.h2
-rw-r--r--fs/ceph/locks.c94
-rw-r--r--fs/ceph/mds_client.c49
-rw-r--r--fs/ceph/mds_client.h33
-rw-r--r--fs/ceph/super.h4
-rw-r--r--fs/cifs/Kconfig8
-rw-r--r--fs/cifs/Makefile4
-rw-r--r--fs/cifs/README9
-rw-r--r--fs/cifs/TODO2
-rw-r--r--fs/cifs/cifs_fs_sb.h7
-rw-r--r--fs/cifs/cifsacl.c51
-rw-r--r--fs/cifs/cifsacl.h4
-rw-r--r--fs/cifs/cifsfs.c10
-rw-r--r--fs/cifs/cifsglob.h15
-rw-r--r--fs/cifs/cifsproto.h12
-rw-r--r--fs/cifs/cifssmb.c183
-rw-r--r--fs/cifs/connect.c242
-rw-r--r--fs/cifs/dns_resolve.c2
-rw-r--r--fs/cifs/file.c78
-rw-r--r--fs/cifs/fscache.c12
-rw-r--r--fs/cifs/inode.c58
-rw-r--r--fs/cifs/ioctl.c16
-rw-r--r--fs/cifs/misc.c25
-rw-r--r--fs/cifs/readdir.c41
-rw-r--r--fs/cifs/xattr.c55
-rw-r--r--fs/compat.c28
-rw-r--r--fs/compat_ioctl.c1
-rw-r--r--fs/ecryptfs/super.c1
-rw-r--r--fs/exec.c41
-rw-r--r--fs/ext3/super.c1
-rw-r--r--fs/ext4/ext4.h5
-rw-r--r--fs/ext4/inode.c10
-rw-r--r--fs/ext4/ioctl.c24
-rw-r--r--fs/ext4/mballoc.c2
-rw-r--r--fs/ext4/namei.c2
-rw-r--r--fs/ext4/page-io.c99
-rw-r--r--fs/ext4/super.c125
-rw-r--r--fs/fuse/file.c82
-rw-r--r--fs/gfs2/export.c46
-rw-r--r--fs/gfs2/glock.c21
-rw-r--r--fs/gfs2/inode.c152
-rw-r--r--fs/gfs2/inode.h4
-rw-r--r--fs/gfs2/quota.c15
-rw-r--r--fs/gfs2/rgrp.c91
-rw-r--r--fs/hpfs/buffer.c4
-rw-r--r--fs/hpfs/hpfs_fn.h2
-rw-r--r--fs/hpfs/super.c2
-rw-r--r--fs/hugetlbfs/inode.c3
-rw-r--r--fs/ioctl.c40
-rw-r--r--fs/ioprio.c13
-rw-r--r--fs/jbd2/journal.c24
-rw-r--r--fs/lockd/clntlock.c1
-rw-r--r--fs/lockd/clntproc.c1
-rw-r--r--fs/lockd/host.c11
-rw-r--r--fs/lockd/svc4proc.c1
-rw-r--r--fs/lockd/svclock.c1
-rw-r--r--fs/lockd/svcproc.c1
-rw-r--r--fs/locks.c91
-rw-r--r--fs/logfs/logfs.h2
-rw-r--r--fs/namei.c3
-rw-r--r--fs/namespace.c1
-rw-r--r--fs/ncpfs/dir.c1
-rw-r--r--fs/ncpfs/file.c1
-rw-r--r--fs/ncpfs/inode.c1
-rw-r--r--fs/ncpfs/ioctl.c1
-rw-r--r--fs/nfs/callback.c1
-rw-r--r--fs/nfs/delegation.c1
-rw-r--r--fs/nfs/dir.c220
-rw-r--r--fs/nfs/direct.c2
-rw-r--r--fs/nfs/file.c3
-rw-r--r--fs/nfs/inode.c1
-rw-r--r--fs/nfs/internal.h9
-rw-r--r--fs/nfs/mount_clnt.c4
-rw-r--r--fs/nfs/nfs2xdr.c8
-rw-r--r--fs/nfs/nfs3xdr.c8
-rw-r--r--fs/nfs/nfs4proc.c13
-rw-r--r--fs/nfs/nfs4xdr.c8
-rw-r--r--fs/nfs/pagelist.c4
-rw-r--r--fs/nfs/read.c1
-rw-r--r--fs/nfs/super.c13
-rw-r--r--fs/nfs/write.c3
-rw-r--r--fs/nfsd/nfs3xdr.c6
-rw-r--r--fs/nfsd/nfs4state.c44
-rw-r--r--fs/nfsd/xdr4.h21
-rw-r--r--fs/nilfs2/dat.c2
-rw-r--r--fs/nilfs2/gcinode.c9
-rw-r--r--fs/nilfs2/ioctl.c16
-rw-r--r--fs/notify/fanotify/fanotify.c6
-rw-r--r--fs/notify/fanotify/fanotify_user.c81
-rw-r--r--fs/notify/inotify/inotify_user.c1
-rw-r--r--fs/ocfs2/cluster/heartbeat.c14
-rw-r--r--fs/ocfs2/dcache.c1
-rw-r--r--fs/ocfs2/dlm/dlmdomain.c2
-rw-r--r--fs/ocfs2/ocfs2.h6
-rw-r--r--fs/ocfs2/stack_user.c2
-rw-r--r--fs/ocfs2/super.c1
-rw-r--r--fs/openpromfs/inode.c2
-rw-r--r--fs/pipe.c14
-rw-r--r--fs/proc/base.c2
-rw-r--r--fs/proc/inode.c1
-rw-r--r--fs/proc/task_mmu.c3
-rw-r--r--fs/read_write.c1
-rw-r--r--fs/reiserfs/inode.c1
-rw-r--r--fs/reiserfs/ioctl.c8
-rw-r--r--fs/reiserfs/journal.c1
-rw-r--r--fs/reiserfs/super.c1
-rw-r--r--fs/reiserfs/xattr_acl.c6
-rw-r--r--fs/splice.c24
-rw-r--r--fs/xfs/linux-2.6/xfs_aops.c101
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c37
-rw-r--r--fs/xfs/linux-2.6/xfs_ioctl.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_iops.c3
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c3
-rw-r--r--fs/xfs/linux-2.6/xfs_sync.c1
-rw-r--r--fs/xfs/xfs_bmap.c85
-rw-r--r--fs/xfs/xfs_bmap.h5
-rw-r--r--fs/xfs/xfs_dfrag.c13
-rw-r--r--fs/xfs/xfs_error.c3
-rw-r--r--fs/xfs/xfs_error.h5
-rw-r--r--fs/xfs/xfs_filestream.c8
-rw-r--r--fs/xfs/xfs_inode_item.c31
-rw-r--r--fs/xfs/xfs_mount.c1
-rw-r--r--fs/xfs/xfs_quota.h20
-rw-r--r--fs/xfs/xfs_rename.c1
-rw-r--r--include/acpi/video.h5
-rw-r--r--include/asm-generic/stat.h14
-rw-r--r--include/drm/i915_drm.h2
-rw-r--r--include/drm/nouveau_drm.h7
-rw-r--r--include/drm/ttm/ttm_bo_api.h4
-rw-r--r--include/drm/ttm/ttm_bo_driver.h79
-rw-r--r--include/linux/acpi.h2
-rw-r--r--include/linux/atmdev.h6
-rw-r--r--include/linux/atomic.h37
-rw-r--r--include/linux/binfmts.h5
-rw-r--r--include/linux/bio.h4
-rw-r--r--include/linux/blk_types.h6
-rw-r--r--include/linux/blkdev.h13
-rw-r--r--include/linux/bootmem.h2
-rw-r--r--include/linux/ceph/libceph.h7
-rw-r--r--include/linux/ceph/messenger.h1
-rw-r--r--include/linux/ceph/osd_client.h7
-rw-r--r--include/linux/cnt32_to_63.h20
-rw-r--r--include/linux/cpu.h5
-rw-r--r--include/linux/dmar.h17
-rw-r--r--include/linux/drbd.h2
-rw-r--r--include/linux/fanotify.h10
-rw-r--r--include/linux/fb.h1
-rw-r--r--include/linux/fs.h10
-rw-r--r--include/linux/fsl-diu-fb.h1
-rw-r--r--include/linux/fsnotify.h3
-rw-r--r--include/linux/fsnotify_backend.h2
-rw-r--r--include/linux/gfp.h4
-rw-r--r--include/linux/gpio_keys.h2
-rw-r--r--include/linux/hardirq.h12
-rw-r--r--include/linux/highmem.h1
-rw-r--r--include/linux/hw_breakpoint.h4
-rw-r--r--include/linux/i2c-id.h22
-rw-r--r--include/linux/i2c.h4
-rw-r--r--include/linux/i2c/adp5588.h15
-rw-r--r--include/linux/if_vlan.h25
-rw-r--r--include/linux/input.h35
-rw-r--r--include/linux/iocontext.h1
-rw-r--r--include/linux/ioport.h2
-rw-r--r--include/linux/irq.h5
-rw-r--r--include/linux/irqnr.h2
-rw-r--r--include/linux/kernel.h246
-rw-r--r--include/linux/leds-lp5521.h47
-rw-r--r--include/linux/leds-lp5523.h47
-rw-r--r--include/linux/leds.h47
-rw-r--r--include/linux/libata.h2
-rw-r--r--include/linux/lockd/lockd.h1
-rw-r--r--include/linux/marvell_phy.h3
-rw-r--r--include/linux/memory_hotplug.h6
-rw-r--r--include/linux/mfd/wm8350/audio.h3
-rw-r--r--include/linux/mfd/wm8994/pdata.h2
-rw-r--r--include/linux/mmc/host.h1
-rw-r--r--include/linux/mmc/sh_mmcif.h18
-rw-r--r--include/linux/module.h2
-rw-r--r--include/linux/netdevice.h5
-rw-r--r--include/linux/netfilter.h2
-rw-r--r--include/linux/nfs_fs.h7
-rw-r--r--include/linux/nfs_page.h1
-rw-r--r--include/linux/nfs_xdr.h1
-rw-r--r--include/linux/node.h5
-rw-r--r--include/linux/page_cgroup.h7
-rw-r--r--include/linux/pci_ids.h3
-rw-r--r--include/linux/perf_event.h41
-rw-r--r--include/linux/pipe_fs_i.h1
-rw-r--r--include/linux/pm_runtime.h3
-rw-r--r--include/linux/printk.h248
-rw-r--r--include/linux/pwm_backlight.h1
-rw-r--r--include/linux/radix-tree.h39
-rw-r--r--include/linux/reiserfs_fs.h1
-rw-r--r--include/linux/resource.h1
-rw-r--r--include/linux/rtnetlink.h2
-rw-r--r--include/linux/sched.h3
-rw-r--r--include/linux/security.h9
-rw-r--r--include/linux/semaphore.h6
-rw-r--r--include/linux/sh_clk.h38
-rw-r--r--include/linux/sh_intc.h2
-rw-r--r--include/linux/sh_timer.h1
-rw-r--r--include/linux/smp_lock.h3
-rw-r--r--include/linux/snmp.h1
-rw-r--r--include/linux/spi/spi.h3
-rw-r--r--include/linux/ssb/ssb_driver_gige.h17
-rw-r--r--include/linux/sunrpc/svc_xprt.h18
-rw-r--r--include/linux/tty.h4
-rw-r--r--include/linux/uio_driver.h2
-rw-r--r--include/linux/usb.h6
-rw-r--r--include/linux/usb/musb.h2
-rw-r--r--include/linux/video_output.h15
-rw-r--r--include/linux/vmalloc.h2
-rw-r--r--include/media/saa7146.h2
-rw-r--r--include/media/v4l2-common.h16
-rw-r--r--include/media/v4l2-device.h2
-rw-r--r--include/net/af_unix.h2
-rw-r--r--include/net/caif/caif_dev.h4
-rw-r--r--include/net/caif/caif_spi.h2
-rw-r--r--include/net/caif/cfcnfg.h8
-rw-r--r--include/net/cfg80211.h2
-rw-r--r--include/net/dn.h2
-rw-r--r--include/net/dst_ops.h1
-rw-r--r--include/net/neighbour.h2
-rw-r--r--include/net/netlink.h2
-rw-r--r--include/net/sock.h8
-rw-r--r--include/net/tcp.h6
-rw-r--r--include/net/udp.h4
-rw-r--r--include/scsi/libfc.h5
-rw-r--r--include/scsi/libiscsi.h3
-rw-r--r--include/scsi/libsas.h3
-rw-r--r--include/scsi/osd_initiator.h16
-rw-r--r--include/scsi/osd_protocol.h42
-rw-r--r--include/scsi/osd_types.h5
-rw-r--r--include/scsi/scsi_host.h23
-rw-r--r--include/sound/sh_fsi.h6
-rw-r--r--include/trace/events/ext4.h97
-rw-r--r--include/video/da8xx-fb.h1
-rw-r--r--include/xen/events.h7
-rw-r--r--include/xen/interface/io/ring.h11
-rw-r--r--include/xen/interface/memory.h13
-rw-r--r--include/xen/interface/physdev.h10
-rw-r--r--include/xen/page.h7
-rw-r--r--include/xen/privcmd.h5
-rw-r--r--init/Kconfig13
-rw-r--r--init/main.c1
-rw-r--r--kernel/debug/kdb/kdb_main.c21
-rw-r--r--kernel/exit.c17
-rw-r--r--kernel/fork.c1
-rw-r--r--kernel/futex.c3
-rw-r--r--kernel/futex_compat.c3
-rw-r--r--kernel/hw_breakpoint.c3
-rw-r--r--kernel/irq/manage.c4
-rw-r--r--kernel/irq/proc.c2
-rw-r--r--kernel/irq_work.c4
-rw-r--r--kernel/latencytop.c17
-rw-r--r--kernel/module.c12
-rw-r--r--kernel/perf_event.c172
-rw-r--r--kernel/pm_qos_params.c4
-rw-r--r--kernel/posix-cpu-timers.c12
-rw-r--r--kernel/power/Kconfig4
-rw-r--r--kernel/power/hibernate.c22
-rw-r--r--kernel/power/suspend.c5
-rw-r--r--kernel/power/swap.c55
-rw-r--r--kernel/power/user.c4
-rw-r--r--kernel/printk.c25
-rw-r--r--kernel/range.c2
-rw-r--r--kernel/relay.c15
-rw-r--r--kernel/resource.c104
-rw-r--r--kernel/sched.c324
-rw-r--r--kernel/sched_fair.c48
-rw-r--r--kernel/sched_stoptask.c4
-rw-r--r--kernel/sysctl.c9
-rw-r--r--kernel/timer.c8
-rw-r--r--kernel/trace/Kconfig2
-rw-r--r--kernel/trace/blktrace.c4
-rw-r--r--kernel/trace/trace.c30
-rw-r--r--kernel/watchdog.c2
-rw-r--r--kernel/workqueue.c7
-rw-r--r--lib/debug_locks.c2
-rw-r--r--lib/radix-tree.c83
-rw-r--r--mm/filemap.c38
-rw-r--r--mm/hugetlb.c3
-rw-r--r--mm/ksm.c7
-rw-r--r--mm/memcontrol.c82
-rw-r--r--mm/memory-failure.c8
-rw-r--r--mm/memory_hotplug.c31
-rw-r--r--mm/mempolicy.c3
-rw-r--r--mm/mmap.c16
-rw-r--r--mm/mprotect.c2
-rw-r--r--mm/nommu.c1
-rw-r--r--mm/page_alloc.c33
-rw-r--r--mm/pagewalk.c5
-rw-r--r--mm/slub.c7
-rw-r--r--mm/truncate.c4
-rw-r--r--mm/vmalloc.c28
-rw-r--r--mm/vmscan.c9
-rw-r--r--mm/vmstat.c6
-rw-r--r--net/atm/atm_sysfs.c3
-rw-r--r--net/atm/resources.c7
-rw-r--r--net/atm/resources.h2
-rw-r--r--net/ax25/af_ax25.c2
-rw-r--r--net/bluetooth/hci_event.c6
-rw-r--r--net/bluetooth/hidp/Kconfig2
-rw-r--r--net/bluetooth/l2cap.c8
-rw-r--r--net/bluetooth/rfcomm/core.c13
-rw-r--r--net/bluetooth/sco.c6
-rw-r--r--net/caif/caif_config_util.c13
-rw-r--r--net/caif/caif_dev.c2
-rw-r--r--net/caif/caif_socket.c45
-rw-r--r--net/caif/cfcnfg.c17
-rw-r--r--net/caif/cfctrl.c3
-rw-r--r--net/caif/cfdbgl.c14
-rw-r--r--net/caif/cfrfml.c2
-rw-r--r--net/can/bcm.c2
-rw-r--r--net/ceph/Makefile22
-rw-r--r--net/ceph/buffer.c2
-rw-r--r--net/ceph/messenger.c21
-rw-r--r--net/ceph/osd_client.c25
-rw-r--r--net/ceph/pagevec.c16
-rw-r--r--net/core/dev.c2
-rw-r--r--net/core/dst.c1
-rw-r--r--net/core/filter.c83
-rw-r--r--net/core/net-sysfs.c10
-rw-r--r--net/core/pktgen.c6
-rw-r--r--net/core/request_sock.c4
-rw-r--r--net/core/rtnetlink.c9
-rw-r--r--net/core/sock.c14
-rw-r--r--net/core/timestamping.c6
-rw-r--r--net/dccp/input.c3
-rw-r--r--net/decnet/af_decnet.c4
-rw-r--r--net/decnet/sysctl_net_decnet.c4
-rw-r--r--net/econet/af_econet.c99
-rw-r--r--net/ipv4/fib_lookup.h5
-rw-r--r--net/ipv4/fib_trie.c2
-rw-r--r--net/ipv4/icmp.c3
-rw-r--r--net/ipv4/igmp.c4
-rw-r--r--net/ipv4/inet_diag.c27
-rw-r--r--net/ipv4/inet_hashtables.c3
-rw-r--r--net/ipv4/ip_gre.c6
-rw-r--r--net/ipv4/netfilter/arp_tables.c1
-rw-r--r--net/ipv4/netfilter/ip_tables.c1
-rw-r--r--net/ipv4/netfilter/nf_nat_core.c40
-rw-r--r--net/ipv4/proc.c9
-rw-r--r--net/ipv4/sysctl_net_ipv4.c11
-rw-r--r--net/ipv4/tcp.c6
-rw-r--r--net/ipv4/tcp_input.c11
-rw-r--r--net/ipv4/tcp_ipv4.c12
-rw-r--r--net/ipv4/tcp_minisocks.c2
-rw-r--r--net/ipv4/tcp_output.c42
-rw-r--r--net/ipv4/udp.c4
-rw-r--r--net/ipv6/addrconf.c56
-rw-r--r--net/ipv6/ip6_tunnel.c7
-rw-r--r--net/ipv6/netfilter/ip6_tables.c1
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c2
-rw-r--r--net/ipv6/proc.c4
-rw-r--r--net/ipv6/reassembly.c2
-rw-r--r--net/ipv6/route.c8
-rw-r--r--net/ipv6/sit.c3
-rw-r--r--net/irda/af_irda.c1
-rw-r--r--net/irda/irnet/irnet_ppp.c1
-rw-r--r--net/irda/irttp.c30
-rw-r--r--net/l2tp/l2tp_debugfs.c2
-rw-r--r--net/l2tp/l2tp_ip.c6
-rw-r--r--net/llc/af_llc.c5
-rw-r--r--net/mac80211/Kconfig2
-rw-r--r--net/mac80211/iface.c6
-rw-r--r--net/mac80211/rx.c6
-rw-r--r--net/mac80211/tx.c28
-rw-r--r--net/netfilter/ipvs/Kconfig1
-rw-r--r--net/netfilter/nf_conntrack_core.c3
-rw-r--r--net/netfilter/nf_conntrack_proto.c6
-rw-r--r--net/packet/af_packet.c7
-rw-r--r--net/rds/loop.c4
-rw-r--r--net/rds/message.c7
-rw-r--r--net/rds/rdma.c128
-rw-r--r--net/rds/send.c4
-rw-r--r--net/rds/tcp.c6
-rw-r--r--net/sched/cls_basic.c4
-rw-r--r--net/sched/cls_cgroup.c2
-rw-r--r--net/sched/em_text.c3
-rw-r--r--net/sctp/protocol.c2
-rw-r--r--net/sctp/socket.c12
-rw-r--r--net/sctp/sysctl.c4
-rw-r--r--net/socket.c19
-rw-r--r--net/sunrpc/clnt.c24
-rw-r--r--net/sunrpc/stats.c4
-rw-r--r--net/sunrpc/svc_xprt.c10
-rw-r--r--net/tipc/socket.c1
-rw-r--r--net/unix/af_unix.c37
-rw-r--r--net/unix/garbage.c9
-rw-r--r--net/wireless/chan.c54
-rw-r--r--net/wireless/nl80211.c4
-rw-r--r--net/x25/x25_facilities.c20
-rw-r--r--net/x25/x25_in.c2
-rw-r--r--net/x25/x25_link.c1
-rw-r--r--net/xfrm/xfrm_hash.c2
-rw-r--r--net/xfrm/xfrm_state.c2
-rwxr-xr-xscripts/checkpatch.pl8
-rw-r--r--scripts/gfp-translate7
-rw-r--r--scripts/kconfig/expr.h1
-rw-r--r--scripts/kconfig/lkc.h1
-rw-r--r--scripts/kconfig/menu.c11
-rw-r--r--scripts/kconfig/symbol.c2
-rw-r--r--scripts/kconfig/zconf.gperf1
-rw-r--r--scripts/kconfig/zconf.hash.c_shipped122
-rw-r--r--scripts/kconfig/zconf.tab.c_shipped570
-rw-r--r--scripts/kconfig/zconf.y21
-rwxr-xr-xscripts/kernel-doc12
-rw-r--r--scripts/recordmcount.h2
-rwxr-xr-xscripts/tags.sh4
-rw-r--r--security/Kconfig12
-rw-r--r--security/apparmor/lsm.c6
-rw-r--r--security/apparmor/policy.c2
-rw-r--r--security/capability.c5
-rw-r--r--security/commoncap.c19
-rw-r--r--security/security.c4
-rw-r--r--security/selinux/hooks.c6
-rw-r--r--security/smack/smack_lsm.c8
-rw-r--r--sound/atmel/abdac.c4
-rw-r--r--sound/core/info.c1
-rw-r--r--sound/core/oss/pcm_oss.c19
-rw-r--r--sound/core/pcm_lib.c2
-rw-r--r--sound/core/pcm_native.c1
-rw-r--r--sound/core/sound.c1
-rw-r--r--sound/oss/dev_table.c6
-rw-r--r--sound/oss/midibuf.c4
-rw-r--r--sound/oss/pss.c6
-rw-r--r--sound/oss/sequencer.c4
-rw-r--r--sound/pci/asihpi/hpi6000.c2
-rw-r--r--sound/pci/asihpi/hpi6205.c2
-rw-r--r--sound/pci/asihpi/hpicmn.c12
-rw-r--r--sound/pci/asihpi/hpioctl.c2
-rw-r--r--sound/pci/azt3328.c26
-rw-r--r--sound/pci/cs46xx/dsp_spos.c33
-rw-r--r--sound/pci/ctxfi/ctpcm.c16
-rw-r--r--sound/pci/hda/hda_eld.c24
-rw-r--r--sound/pci/hda/hda_intel.c1
-rw-r--r--sound/pci/hda/patch_cirrus.c1
-rw-r--r--sound/pci/hda/patch_conexant.c37
-rw-r--r--sound/pci/hda/patch_hdmi.c1
-rw-r--r--sound/pci/hda/patch_realtek.c110
-rw-r--r--sound/pci/hda/patch_sigmatel.c20
-rw-r--r--sound/pci/intel8x0.c6
-rw-r--r--sound/pci/lx6464es/lx6464es.c4
-rw-r--r--sound/pci/lx6464es/lx6464es.h2
-rw-r--r--sound/pci/lx6464es/lx_core.c2
-rw-r--r--sound/pci/mixart/mixart_hwdep.h10
-rw-r--r--sound/ppc/pmac.c12
-rw-r--r--sound/soc/atmel/Kconfig5
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c9
-rw-r--r--sound/soc/atmel/snd-soc-afeb9260.c1
-rw-r--r--sound/soc/codecs/Kconfig3
-rw-r--r--sound/soc/codecs/max98088.c14
-rw-r--r--sound/soc/codecs/stac9766.c1
-rw-r--r--sound/soc/codecs/tlv320aic3x.c6
-rw-r--r--sound/soc/codecs/tlv320dac33.c36
-rw-r--r--sound/soc/codecs/tpa6130a2.c10
-rw-r--r--sound/soc/codecs/uda134x.c1
-rw-r--r--sound/soc/codecs/wm8350.c9
-rw-r--r--sound/soc/codecs/wm8523.c1
-rw-r--r--sound/soc/codecs/wm8580.c10
-rw-r--r--sound/soc/codecs/wm8731.c2
-rw-r--r--sound/soc/codecs/wm8776.c1
-rw-r--r--sound/soc/codecs/wm8900.c6
-rw-r--r--sound/soc/codecs/wm8904.c5
-rw-r--r--sound/soc/codecs/wm8955.c3
-rw-r--r--sound/soc/codecs/wm8960.c3
-rw-r--r--sound/soc/codecs/wm8961.c4
-rw-r--r--sound/soc/codecs/wm8962.c7
-rw-r--r--sound/soc/codecs/wm8994.c6
-rw-r--r--sound/soc/codecs/wm_hubs.c4
-rw-r--r--sound/soc/davinci/davinci-evm.c40
-rw-r--r--sound/soc/davinci/davinci-i2s.c15
-rw-r--r--sound/soc/davinci/davinci-mcasp.c13
-rw-r--r--sound/soc/davinci/davinci-sffsdr.c2
-rw-r--r--sound/soc/davinci/davinci-vcif.c16
-rw-r--r--sound/soc/ep93xx/simone.c18
-rw-r--r--sound/soc/fsl/efika-audio-fabric.c1
-rw-r--r--sound/soc/fsl/mpc5200_dma.c1
-rw-r--r--sound/soc/fsl/mpc5200_psc_i2s.c2
-rw-r--r--sound/soc/fsl/mpc8610_hpcd.c1
-rw-r--r--sound/soc/fsl/p1022_ds.c1
-rw-r--r--sound/soc/fsl/pcm030-audio-fabric.c1
-rw-r--r--sound/soc/imx/eukrea-tlv320.c8
-rw-r--r--sound/soc/imx/imx-pcm-dma-mx2.c221
-rw-r--r--sound/soc/imx/imx-ssi.c57
-rw-r--r--sound/soc/imx/imx-ssi.h4
-rw-r--r--sound/soc/imx/phycore-ac97.c33
-rw-r--r--sound/soc/nuc900/nuc900-ac97.c17
-rw-r--r--sound/soc/nuc900/nuc900-audio.h2
-rw-r--r--sound/soc/nuc900/nuc900-pcm.c11
-rw-r--r--sound/soc/omap/Kconfig2
-rw-r--r--sound/soc/omap/omap-mcbsp.c8
-rw-r--r--sound/soc/omap/omap3pandora.c1
-rw-r--r--sound/soc/omap/osk5912.c11
-rw-r--r--sound/soc/pxa/Kconfig1
-rw-r--r--sound/soc/pxa/corgi.c5
-rw-r--r--sound/soc/pxa/magician.c4
-rw-r--r--sound/soc/pxa/poodle.c5
-rw-r--r--sound/soc/pxa/spitz.c5
-rw-r--r--sound/soc/pxa/tosa.c7
-rw-r--r--sound/soc/s3c24xx/Kconfig1
-rw-r--r--sound/soc/s3c24xx/rx1950_uda1380.c20
-rw-r--r--sound/soc/s3c24xx/smdk_spdif.c4
-rw-r--r--sound/soc/s6000/s6000-i2s.c2
-rw-r--r--sound/soc/s6000/s6000-pcm.c2
-rw-r--r--sound/soc/s6000/s6105-ipcam.c2
-rw-r--r--sound/soc/sh/fsi.c25
-rw-r--r--sound/soc/sh/ssi.c2
-rw-r--r--sound/soc/soc-core.c28
-rw-r--r--sound/soc/soc-dapm.c7
-rw-r--r--sound/sound_core.c1
-rw-r--r--sound/spi/at73c213.c2
-rw-r--r--sound/usb/mixer_quirks.c15
-rw-r--r--sound/usb/pcm.c4
-rw-r--r--tools/perf/Documentation/perf-trace.txt57
-rw-r--r--tools/perf/builtin-record.c33
-rw-r--r--tools/perf/builtin-top.c12
-rw-r--r--tools/perf/builtin-trace.c209
-rw-r--r--tools/perf/scripts/perl/bin/failed-syscalls-record2
-rw-r--r--tools/perf/scripts/perl/bin/rw-by-file-record2
-rw-r--r--tools/perf/scripts/perl/bin/rw-by-pid-record2
-rw-r--r--tools/perf/scripts/perl/bin/rwtop-record2
-rw-r--r--tools/perf/scripts/perl/bin/wakeup-latency-record2
-rw-r--r--tools/perf/scripts/perl/bin/workqueue-stats-record2
-rw-r--r--tools/perf/scripts/python/bin/failed-syscalls-by-pid-record2
-rw-r--r--tools/perf/scripts/python/bin/futex-contention-record2
-rw-r--r--tools/perf/scripts/python/bin/netdev-times-record2
-rw-r--r--tools/perf/scripts/python/bin/sched-migration-record2
-rw-r--r--tools/perf/scripts/python/bin/sctop-record2
-rw-r--r--tools/perf/scripts/python/bin/syscall-counts-by-pid-record2
-rw-r--r--tools/perf/scripts/python/bin/syscall-counts-record2
-rw-r--r--tools/perf/util/header.c11
-rw-r--r--tools/perf/util/symbol.c63
-rw-r--r--tools/perf/util/ui/util.c5
-rw-r--r--usr/initramfs_data.S11
2029 files changed, 37852 insertions, 20361 deletions
diff --git a/Documentation/ABI/obsolete/proc-pid-oom_adj b/Documentation/ABI/obsolete/proc-pid-oom_adj
new file mode 100644
index 000000000000..cf63f264ce0f
--- /dev/null
+++ b/Documentation/ABI/obsolete/proc-pid-oom_adj
@@ -0,0 +1,22 @@
1What: /proc/<pid>/oom_adj
2When: August 2012
3Why: /proc/<pid>/oom_adj allows userspace to influence the oom killer's
4 badness heuristic used to determine which task to kill when the kernel
5 is out of memory.
6
7 The badness heuristic has since been rewritten since the introduction of
8 this tunable such that its meaning is deprecated. The value was
9 implemented as a bitshift on a score generated by the badness()
10 function that did not have any precise units of measure. With the
11 rewrite, the score is given as a proportion of available memory to the
12 task allocating pages, so using a bitshift which grows the score
13 exponentially is, thus, impossible to tune with fine granularity.
14
15 A much more powerful interface, /proc/<pid>/oom_score_adj, was
16 introduced with the oom killer rewrite that allows users to increase or
17 decrease the badness() score linearly. This interface will replace
18 /proc/<pid>/oom_adj.
19
20 A warning will be emitted to the kernel log if an application uses this
21 deprecated interface. After it is printed once, future warnings will be
22 suppressed until the kernel is rebooted.
diff --git a/Documentation/ABI/testing/sysfs-bus-rbd b/Documentation/ABI/testing/sysfs-bus-rbd
new file mode 100644
index 000000000000..90a87e2a572b
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-rbd
@@ -0,0 +1,83 @@
1What: /sys/bus/rbd/
2Date: November 2010
3Contact: Yehuda Sadeh <yehuda@hq.newdream.net>,
4 Sage Weil <sage@newdream.net>
5Description:
6
7Being used for adding and removing rbd block devices.
8
9Usage: <mon ip addr> <options> <pool name> <rbd image name> [snap name]
10
11 $ echo "192.168.0.1 name=admin rbd foo" > /sys/bus/rbd/add
12
13The snapshot name can be "-" or omitted to map the image read/write. A <dev-id>
14will be assigned for any registered block device. If snapshot is used, it will
15be mapped read-only.
16
17Removal of a device:
18
19 $ echo <dev-id> > /sys/bus/rbd/remove
20
21Entries under /sys/bus/rbd/devices/<dev-id>/
22--------------------------------------------
23
24client_id
25
26 The ceph unique client id that was assigned for this specific session.
27
28major
29
30 The block device major number.
31
32name
33
34 The name of the rbd image.
35
36pool
37
38 The pool where this rbd image resides. The pool-name pair is unique
39 per rados system.
40
41size
42
43 The size (in bytes) of the mapped block device.
44
45refresh
46
47 Writing to this file will reread the image header data and set
48 all relevant datastructures accordingly.
49
50current_snap
51
52 The current snapshot for which the device is mapped.
53
54create_snap
55
56 Create a snapshot:
57
58 $ echo <snap-name> > /sys/bus/rbd/devices/<dev-id>/snap_create
59
60rollback_snap
61
62 Rolls back data to the specified snapshot. This goes over the entire
63 list of rados blocks and sends a rollback command to each.
64
65 $ echo <snap-name> > /sys/bus/rbd/devices/<dev-id>/snap_rollback
66
67snap_*
68
69 A directory per each snapshot
70
71
72Entries under /sys/bus/rbd/devices/<dev-id>/snap_<snap-name>
73-------------------------------------------------------------
74
75id
76
77 The rados internal snapshot id assigned for this snapshot
78
79size
80
81 The size of the image when this snapshot was taken.
82
83
diff --git a/Documentation/ABI/testing/sysfs-platform-asus-laptop b/Documentation/ABI/testing/sysfs-platform-asus-laptop
index 1d775390e856..41ff8ae4dee0 100644
--- a/Documentation/ABI/testing/sysfs-platform-asus-laptop
+++ b/Documentation/ABI/testing/sysfs-platform-asus-laptop
@@ -47,6 +47,20 @@ Date: January 2007
47KernelVersion: 2.6.20 47KernelVersion: 2.6.20
48Contact: "Corentin Chary" <corentincj@iksaif.net> 48Contact: "Corentin Chary" <corentincj@iksaif.net>
49Description: 49Description:
50 Control the bluetooth device. 1 means on, 0 means off. 50 Control the wlan device. 1 means on, 0 means off.
51 This may control the led, the device or both. 51 This may control the led, the device or both.
52Users: Lapsus 52Users: Lapsus
53
54What: /sys/devices/platform/asus_laptop/wimax
55Date: October 2010
56KernelVersion: 2.6.37
57Contact: "Corentin Chary" <corentincj@iksaif.net>
58Description:
59 Control the wimax device. 1 means on, 0 means off.
60
61What: /sys/devices/platform/asus_laptop/wwan
62Date: October 2010
63KernelVersion: 2.6.37
64Contact: "Corentin Chary" <corentincj@iksaif.net>
65Description:
66 Control the wwan (3G) device. 1 means on, 0 means off.
diff --git a/Documentation/ABI/testing/sysfs-platform-eeepc-wmi b/Documentation/ABI/testing/sysfs-platform-eeepc-wmi
new file mode 100644
index 000000000000..e4b5fef5fadd
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-eeepc-wmi
@@ -0,0 +1,10 @@
1What: /sys/devices/platform/eeepc-wmi/cpufv
2Date: Oct 2010
3KernelVersion: 2.6.37
4Contact: "Corentin Chary" <corentincj@iksaif.net>
5Description:
6 Change CPU clock configuration (write-only).
7 There are three available clock configuration:
8 * 0 -> Super Performance Mode
9 * 1 -> High Performance Mode
10 * 2 -> Power Saving Mode
diff --git a/Documentation/DocBook/sh.tmpl b/Documentation/DocBook/sh.tmpl
index d858d92cf6d9..4a38f604fa66 100644
--- a/Documentation/DocBook/sh.tmpl
+++ b/Documentation/DocBook/sh.tmpl
@@ -79,10 +79,6 @@
79 </sect2> 79 </sect2>
80 </sect1> 80 </sect1>
81 </chapter> 81 </chapter>
82 <chapter id="clk">
83 <title>Clock Framework Extensions</title>
84!Iinclude/linux/sh_clk.h
85 </chapter>
86 <chapter id="mach"> 82 <chapter id="mach">
87 <title>Machine Specific Interfaces</title> 83 <title>Machine Specific Interfaces</title>
88 <sect1 id="dreamcast"> 84 <sect1 id="dreamcast">
diff --git a/Documentation/DocBook/uio-howto.tmpl b/Documentation/DocBook/uio-howto.tmpl
index 4d4ce0e61e42..b4665b9c40b0 100644
--- a/Documentation/DocBook/uio-howto.tmpl
+++ b/Documentation/DocBook/uio-howto.tmpl
@@ -16,7 +16,7 @@
16 </orgname> 16 </orgname>
17 17
18 <address> 18 <address>
19 <email>hjk@linutronix.de</email> 19 <email>hjk@hansjkoch.de</email>
20 </address> 20 </address>
21 </affiliation> 21 </affiliation>
22</author> 22</author>
@@ -114,7 +114,7 @@ GPL version 2.
114 114
115<para>If you know of any translations for this document, or you are 115<para>If you know of any translations for this document, or you are
116interested in translating it, please email me 116interested in translating it, please email me
117<email>hjk@linutronix.de</email>. 117<email>hjk@hansjkoch.de</email>.
118</para> 118</para>
119</sect1> 119</sect1>
120 120
@@ -171,7 +171,7 @@ interested in translating it, please email me
171<title>Feedback</title> 171<title>Feedback</title>
172 <para>Find something wrong with this document? (Or perhaps something 172 <para>Find something wrong with this document? (Or perhaps something
173 right?) I would love to hear from you. Please email me at 173 right?) I would love to hear from you. Please email me at
174 <email>hjk@linutronix.de</email>.</para> 174 <email>hjk@hansjkoch.de</email>.</para>
175</sect1> 175</sect1>
176</chapter> 176</chapter>
177 177
diff --git a/Documentation/arm/OMAP/DSS b/Documentation/arm/OMAP/DSS
index 0af0e9eed5d6..888ae7b83ae4 100644
--- a/Documentation/arm/OMAP/DSS
+++ b/Documentation/arm/OMAP/DSS
@@ -255,9 +255,10 @@ framebuffer parameters.
255Kernel boot arguments 255Kernel boot arguments
256--------------------- 256---------------------
257 257
258vram=<size> 258vram=<size>[,<physaddr>]
259 - Amount of total VRAM to preallocate. For example, "10M". omapfb 259 - Amount of total VRAM to preallocate and optionally a physical start
260 allocates memory for framebuffers from VRAM. 260 memory address. For example, "10M". omapfb allocates memory for
261 framebuffers from VRAM.
261 262
262omapfb.mode=<display>:<mode>[,...] 263omapfb.mode=<display>:<mode>[,...]
263 - Default video mode for specified displays. For example, 264 - Default video mode for specified displays. For example,
diff --git a/Documentation/block/switching-sched.txt b/Documentation/block/switching-sched.txt
index d5af3f630814..71cfbdc0f74d 100644
--- a/Documentation/block/switching-sched.txt
+++ b/Documentation/block/switching-sched.txt
@@ -16,7 +16,7 @@ you can do so by typing:
16As of the Linux 2.6.10 kernel, it is now possible to change the 16As of the Linux 2.6.10 kernel, it is now possible to change the
17IO scheduler for a given block device on the fly (thus making it possible, 17IO scheduler for a given block device on the fly (thus making it possible,
18for instance, to set the CFQ scheduler for the system default, but 18for instance, to set the CFQ scheduler for the system default, but
19set a specific device to use the anticipatory or noop schedulers - which 19set a specific device to use the deadline or noop schedulers - which
20can improve that device's throughput). 20can improve that device's throughput).
21 21
22To set a specific scheduler, simply do this: 22To set a specific scheduler, simply do this:
@@ -31,7 +31,7 @@ a "cat /sys/block/DEV/queue/scheduler" - the list of valid names
31will be displayed, with the currently selected scheduler in brackets: 31will be displayed, with the currently selected scheduler in brackets:
32 32
33# cat /sys/block/hda/queue/scheduler 33# cat /sys/block/hda/queue/scheduler
34noop anticipatory deadline [cfq] 34noop deadline [cfq]
35# echo anticipatory > /sys/block/hda/queue/scheduler 35# echo deadline > /sys/block/hda/queue/scheduler
36# cat /sys/block/hda/queue/scheduler 36# cat /sys/block/hda/queue/scheduler
37noop [anticipatory] deadline cfq 37noop [deadline] cfq
diff --git a/Documentation/development-process/2.Process b/Documentation/development-process/2.Process
index 97726eba6102..911a45186340 100644
--- a/Documentation/development-process/2.Process
+++ b/Documentation/development-process/2.Process
@@ -154,7 +154,7 @@ The stages that a patch goes through are, generally:
154 inclusion, it should be accepted by a relevant subsystem maintainer - 154 inclusion, it should be accepted by a relevant subsystem maintainer -
155 though this acceptance is not a guarantee that the patch will make it 155 though this acceptance is not a guarantee that the patch will make it
156 all the way to the mainline. The patch will show up in the maintainer's 156 all the way to the mainline. The patch will show up in the maintainer's
157 subsystem tree and into the staging trees (described below). When the 157 subsystem tree and into the -next trees (described below). When the
158 process works, this step leads to more extensive review of the patch and 158 process works, this step leads to more extensive review of the patch and
159 the discovery of any problems resulting from the integration of this 159 the discovery of any problems resulting from the integration of this
160 patch with work being done by others. 160 patch with work being done by others.
@@ -236,7 +236,7 @@ finding the right maintainer. Sending patches directly to Linus is not
236normally the right way to go. 236normally the right way to go.
237 237
238 238
2392.4: STAGING TREES 2392.4: NEXT TREES
240 240
241The chain of subsystem trees guides the flow of patches into the kernel, 241The chain of subsystem trees guides the flow of patches into the kernel,
242but it also raises an interesting question: what if somebody wants to look 242but it also raises an interesting question: what if somebody wants to look
@@ -250,7 +250,7 @@ changes land in the mainline kernel. One could pull changes from all of
250the interesting subsystem trees, but that would be a big and error-prone 250the interesting subsystem trees, but that would be a big and error-prone
251job. 251job.
252 252
253The answer comes in the form of staging trees, where subsystem trees are 253The answer comes in the form of -next trees, where subsystem trees are
254collected for testing and review. The older of these trees, maintained by 254collected for testing and review. The older of these trees, maintained by
255Andrew Morton, is called "-mm" (for memory management, which is how it got 255Andrew Morton, is called "-mm" (for memory management, which is how it got
256started). The -mm tree integrates patches from a long list of subsystem 256started). The -mm tree integrates patches from a long list of subsystem
@@ -275,7 +275,7 @@ directory at:
275Use of the MMOTM tree is likely to be a frustrating experience, though; 275Use of the MMOTM tree is likely to be a frustrating experience, though;
276there is a definite chance that it will not even compile. 276there is a definite chance that it will not even compile.
277 277
278The other staging tree, started more recently, is linux-next, maintained by 278The other -next tree, started more recently, is linux-next, maintained by
279Stephen Rothwell. The linux-next tree is, by design, a snapshot of what 279Stephen Rothwell. The linux-next tree is, by design, a snapshot of what
280the mainline is expected to look like after the next merge window closes. 280the mainline is expected to look like after the next merge window closes.
281Linux-next trees are announced on the linux-kernel and linux-next mailing 281Linux-next trees are announced on the linux-kernel and linux-next mailing
@@ -303,12 +303,25 @@ volatility of linux-next tends to make it a difficult development target.
303See http://lwn.net/Articles/289013/ for more information on this topic, and 303See http://lwn.net/Articles/289013/ for more information on this topic, and
304stay tuned; much is still in flux where linux-next is involved. 304stay tuned; much is still in flux where linux-next is involved.
305 305
306Besides the mmotm and linux-next trees, the kernel source tree now contains 3062.4.1: STAGING TREES
307the drivers/staging/ directory and many sub-directories for drivers or 307
308filesystems that are on their way to being added to the kernel tree 308The kernel source tree now contains the drivers/staging/ directory, where
309proper, but they remain in drivers/staging/ while they still need more 309many sub-directories for drivers or filesystems that are on their way to
310work. 310being added to the kernel tree live. They remain in drivers/staging while
311 311they still need more work; once complete, they can be moved into the
312kernel proper. This is a way to keep track of drivers that aren't
313up to Linux kernel coding or quality standards, but people may want to use
314them and track development.
315
316Greg Kroah-Hartman currently (as of 2.6.36) maintains the staging tree.
317Drivers that still need work are sent to him, with each driver having
318its own subdirectory in drivers/staging/. Along with the driver source
319files, a TODO file should be present in the directory as well. The TODO
320file lists the pending work that the driver needs for acceptance into
321the kernel proper, as well as a list of people that should be Cc'd for any
322patches to the driver. Staging drivers that don't currently build should
323have their config entries depend upon CONFIG_BROKEN. Once they can
324be successfully built without outside patches, CONFIG_BROKEN can be removed.
312 325
3132.5: TOOLS 3262.5: TOOLS
314 327
diff --git a/Documentation/driver-model/interface.txt b/Documentation/driver-model/interface.txt
deleted file mode 100644
index c66912bfe866..000000000000
--- a/Documentation/driver-model/interface.txt
+++ /dev/null
@@ -1,129 +0,0 @@
1
2Device Interfaces
3
4Introduction
5~~~~~~~~~~~~
6
7Device interfaces are the logical interfaces of device classes that correlate
8directly to userspace interfaces, like device nodes.
9
10Each device class may have multiple interfaces through which you can
11access the same device. An input device may support the mouse interface,
12the 'evdev' interface, and the touchscreen interface. A SCSI disk would
13support the disk interface, the SCSI generic interface, and possibly a raw
14device interface.
15
16Device interfaces are registered with the class they belong to. As devices
17are added to the class, they are added to each interface registered with
18the class. The interface is responsible for determining whether the device
19supports the interface or not.
20
21
22Programming Interface
23~~~~~~~~~~~~~~~~~~~~~
24
25struct device_interface {
26 char * name;
27 rwlock_t lock;
28 u32 devnum;
29 struct device_class * devclass;
30
31 struct list_head node;
32 struct driver_dir_entry dir;
33
34 int (*add_device)(struct device *);
35 int (*add_device)(struct intf_data *);
36};
37
38int interface_register(struct device_interface *);
39void interface_unregister(struct device_interface *);
40
41
42An interface must specify the device class it belongs to. It is added
43to that class's list of interfaces on registration.
44
45
46Interfaces can be added to a device class at any time. Whenever it is
47added, each device in the class is passed to the interface's
48add_device callback. When an interface is removed, each device is
49removed from the interface.
50
51
52Devices
53~~~~~~~
54Once a device is added to a device class, it is added to each
55interface that is registered with the device class. The class
56is expected to place a class-specific data structure in
57struct device::class_data. The interface can use that (along with
58other fields of struct device) to determine whether or not the driver
59and/or device support that particular interface.
60
61
62Data
63~~~~
64
65struct intf_data {
66 struct list_head node;
67 struct device_interface * intf;
68 struct device * dev;
69 u32 intf_num;
70};
71
72int interface_add_data(struct interface_data *);
73
74The interface is responsible for allocating and initializing a struct
75intf_data and calling interface_add_data() to add it to the device's list
76of interfaces it belongs to. This list will be iterated over when the device
77is removed from the class (instead of all possible interfaces for a class).
78This structure should probably be embedded in whatever per-device data
79structure the interface is allocating anyway.
80
81Devices are enumerated within the interface. This happens in interface_add_data()
82and the enumerated value is stored in the struct intf_data for that device.
83
84sysfs
85~~~~~
86Each interface is given a directory in the directory of the device
87class it belongs to:
88
89Interfaces get a directory in the class's directory as well:
90
91 class/
92 `-- input
93 |-- devices
94 |-- drivers
95 |-- mouse
96 `-- evdev
97
98When a device is added to the interface, a symlink is created that points
99to the device's directory in the physical hierarchy:
100
101 class/
102 `-- input
103 |-- devices
104 | `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
105 |-- drivers
106 | `-- usb:usb_mouse -> ../../../bus/drivers/usb_mouse/
107 |-- mouse
108 | `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
109 `-- evdev
110 `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
111
112
113Future Plans
114~~~~~~~~~~~~
115A device interface is correlated directly with a userspace interface
116for a device, specifically a device node. For instance, a SCSI disk
117exposes at least two interfaces to userspace: the standard SCSI disk
118interface and the SCSI generic interface. It might also export a raw
119device interface.
120
121Many interfaces have a major number associated with them and each
122device gets a minor number. Or, multiple interfaces might share one
123major number, and each will receive a range of minor numbers (like in
124the case of input devices).
125
126These major and minor numbers could be stored in the interface
127structure. Major and minor allocations could happen when the interface
128is registered with the class, or via a helper function.
129
diff --git a/Documentation/edac.txt b/Documentation/edac.txt
index 0b875e8da969..9ee774de57cd 100644
--- a/Documentation/edac.txt
+++ b/Documentation/edac.txt
@@ -196,7 +196,7 @@ csrow3.
196The representation of the above is reflected in the directory tree 196The representation of the above is reflected in the directory tree
197in EDAC's sysfs interface. Starting in directory 197in EDAC's sysfs interface. Starting in directory
198/sys/devices/system/edac/mc each memory controller will be represented 198/sys/devices/system/edac/mc each memory controller will be represented
199by its own 'mcX' directory, where 'X" is the index of the MC. 199by its own 'mcX' directory, where 'X' is the index of the MC.
200 200
201 201
202 ..../edac/mc/ 202 ..../edac/mc/
@@ -207,7 +207,7 @@ by its own 'mcX' directory, where 'X" is the index of the MC.
207 .... 207 ....
208 208
209Under each 'mcX' directory each 'csrowX' is again represented by a 209Under each 'mcX' directory each 'csrowX' is again represented by a
210'csrowX', where 'X" is the csrow index: 210'csrowX', where 'X' is the csrow index:
211 211
212 212
213 .../mc/mc0/ 213 .../mc/mc0/
@@ -232,7 +232,7 @@ EDAC control and attribute files.
232 232
233 233
234In 'mcX' directories are EDAC control and attribute files for 234In 'mcX' directories are EDAC control and attribute files for
235this 'X" instance of the memory controllers: 235this 'X' instance of the memory controllers:
236 236
237 237
238Counter reset control file: 238Counter reset control file:
@@ -343,7 +343,7 @@ Sdram memory scrubbing rate:
343'csrowX' DIRECTORIES 343'csrowX' DIRECTORIES
344 344
345In the 'csrowX' directories are EDAC control and attribute files for 345In the 'csrowX' directories are EDAC control and attribute files for
346this 'X" instance of csrow: 346this 'X' instance of csrow:
347 347
348 348
349Total Uncorrectable Errors count attribute file: 349Total Uncorrectable Errors count attribute file:
diff --git a/Documentation/fb/00-INDEX b/Documentation/fb/00-INDEX
index a618fd99c9f0..30a70542e823 100644
--- a/Documentation/fb/00-INDEX
+++ b/Documentation/fb/00-INDEX
@@ -4,33 +4,41 @@ please mail me.
4 Geert Uytterhoeven <geert@linux-m68k.org> 4 Geert Uytterhoeven <geert@linux-m68k.org>
5 5
600-INDEX 600-INDEX
7 - this file 7 - this file.
8arkfb.txt 8arkfb.txt
9 - info on the fbdev driver for ARK Logic chips. 9 - info on the fbdev driver for ARK Logic chips.
10aty128fb.txt 10aty128fb.txt
11 - info on the ATI Rage128 frame buffer driver. 11 - info on the ATI Rage128 frame buffer driver.
12cirrusfb.txt 12cirrusfb.txt
13 - info on the driver for Cirrus Logic chipsets. 13 - info on the driver for Cirrus Logic chipsets.
14cmap_xfbdev.txt
15 - an introduction to fbdev's cmap structures.
14deferred_io.txt 16deferred_io.txt
15 - an introduction to deferred IO. 17 - an introduction to deferred IO.
18efifb.txt
19 - info on the EFI platform driver for Intel based Apple computers.
20ep93xx-fb.txt
21 - info on the driver for EP93xx LCD controller.
16fbcon.txt 22fbcon.txt
17 - intro to and usage guide for the framebuffer console (fbcon). 23 - intro to and usage guide for the framebuffer console (fbcon).
18framebuffer.txt 24framebuffer.txt
19 - introduction to frame buffer devices. 25 - introduction to frame buffer devices.
20imacfb.txt 26gxfb.txt
21 - info on the generic EFI platform driver for Intel based Macs. 27 - info on the framebuffer driver for AMD Geode GX2 based processors.
22intel810.txt 28intel810.txt
23 - documentation for the Intel 810/815 framebuffer driver. 29 - documentation for the Intel 810/815 framebuffer driver.
24intelfb.txt 30intelfb.txt
25 - docs for Intel 830M/845G/852GM/855GM/865G/915G/945G fb driver. 31 - docs for Intel 830M/845G/852GM/855GM/865G/915G/945G fb driver.
26internals.txt 32internals.txt
27 - quick overview of frame buffer device internals. 33 - quick overview of frame buffer device internals.
34lxfb.txt
35 - info on the framebuffer driver for AMD Geode LX based processors.
28matroxfb.txt 36matroxfb.txt
29 - info on the Matrox framebuffer driver for Alpha, Intel and PPC. 37 - info on the Matrox framebuffer driver for Alpha, Intel and PPC.
38metronomefb.txt
39 - info on the driver for the Metronome display controller.
30modedb.txt 40modedb.txt
31 - info on the video mode database. 41 - info on the video mode database.
32matroxfb.txt
33 - info on the Matrox frame buffer driver.
34pvr2fb.txt 42pvr2fb.txt
35 - info on the PowerVR 2 frame buffer driver. 43 - info on the PowerVR 2 frame buffer driver.
36pxafb.txt 44pxafb.txt
@@ -39,13 +47,23 @@ s3fb.txt
39 - info on the fbdev driver for S3 Trio/Virge chips. 47 - info on the fbdev driver for S3 Trio/Virge chips.
40sa1100fb.txt 48sa1100fb.txt
41 - information about the driver for the SA-1100 LCD controller. 49 - information about the driver for the SA-1100 LCD controller.
50sh7760fb.txt
51 - info on the SH7760/SH7763 integrated LCDC Framebuffer driver.
42sisfb.txt 52sisfb.txt
43 - info on the framebuffer device driver for various SiS chips. 53 - info on the framebuffer device driver for various SiS chips.
44sstfb.txt 54sstfb.txt
45 - info on the frame buffer driver for 3dfx' Voodoo Graphics boards. 55 - info on the frame buffer driver for 3dfx' Voodoo Graphics boards.
46tgafb.txt 56tgafb.txt
47 - info on the TGA (DECChip 21030) frame buffer driver 57 - info on the TGA (DECChip 21030) frame buffer driver.
58tridentfb.txt
59 info on the framebuffer driver for some Trident chip based cards.
60uvesafb.txt
61 - info on the userspace VESA (VBE2+ compliant) frame buffer device.
48vesafb.txt 62vesafb.txt
49 - info on the VESA frame buffer device 63 - info on the VESA frame buffer device.
64viafb.modes
65 - list of modes for VIA Integration Graphic Chip.
66viafb.txt
67 - info on the VIA Integration Graphic Chip console framebuffer driver.
50vt8623fb.txt 68vt8623fb.txt
51 - info on the fb driver for the graphics core in VIA VT8623 chipsets. 69 - info on the fb driver for the graphics core in VIA VT8623 chipsets.
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index d8f36f984faa..6c2f55e05f13 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -554,3 +554,13 @@ Why: This is a legacy interface which have been replaced by a more
554Who: NeilBrown <neilb@suse.de> 554Who: NeilBrown <neilb@suse.de>
555 555
556---------------------------- 556----------------------------
557
558What: i2c_adapter.id
559When: June 2011
560Why: This field is deprecated. I2C device drivers shouldn't change their
561 behavior based on the underlying I2C adapter. Instead, the I2C
562 adapter driver should instantiate the I2C devices and provide the
563 needed platform-specific information.
564Who: Jean Delvare <khali@linux-fr.org>
565
566----------------------------
diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking
index 8a817f656f0a..b6426f15b4ae 100644
--- a/Documentation/filesystems/Locking
+++ b/Documentation/filesystems/Locking
@@ -173,12 +173,13 @@ prototypes:
173 sector_t (*bmap)(struct address_space *, sector_t); 173 sector_t (*bmap)(struct address_space *, sector_t);
174 int (*invalidatepage) (struct page *, unsigned long); 174 int (*invalidatepage) (struct page *, unsigned long);
175 int (*releasepage) (struct page *, int); 175 int (*releasepage) (struct page *, int);
176 void (*freepage)(struct page *);
176 int (*direct_IO)(int, struct kiocb *, const struct iovec *iov, 177 int (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
177 loff_t offset, unsigned long nr_segs); 178 loff_t offset, unsigned long nr_segs);
178 int (*launder_page) (struct page *); 179 int (*launder_page) (struct page *);
179 180
180locking rules: 181locking rules:
181 All except set_page_dirty may block 182 All except set_page_dirty and freepage may block
182 183
183 BKL PageLocked(page) i_mutex 184 BKL PageLocked(page) i_mutex
184writepage: no yes, unlocks (see below) 185writepage: no yes, unlocks (see below)
@@ -193,6 +194,7 @@ perform_write: no n/a yes
193bmap: no 194bmap: no
194invalidatepage: no yes 195invalidatepage: no yes
195releasepage: no yes 196releasepage: no yes
197freepage: no yes
196direct_IO: no 198direct_IO: no
197launder_page: no yes 199launder_page: no yes
198 200
@@ -288,6 +290,9 @@ buffers from the page in preparation for freeing it. It returns zero to
288indicate that the buffers are (or may be) freeable. If ->releasepage is zero, 290indicate that the buffers are (or may be) freeable. If ->releasepage is zero,
289the kernel assumes that the fs has no private interest in the buffers. 291the kernel assumes that the fs has no private interest in the buffers.
290 292
293 ->freepage() is called when the kernel is done dropping the page
294from the page cache.
295
291 ->launder_page() may be called prior to releasing a page if 296 ->launder_page() may be called prior to releasing a page if
292it is still found to be dirty. It returns zero if the page was successfully 297it is still found to be dirty. It returns zero if the page was successfully
293cleaned, or an error value if not. Note that in order to prevent the page 298cleaned, or an error value if not. Note that in order to prevent the page
@@ -322,7 +327,6 @@ fl_release_private: yes yes
322prototypes: 327prototypes:
323 int (*fl_compare_owner)(struct file_lock *, struct file_lock *); 328 int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
324 void (*fl_notify)(struct file_lock *); /* unblock callback */ 329 void (*fl_notify)(struct file_lock *); /* unblock callback */
325 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
326 void (*fl_release_private)(struct file_lock *); 330 void (*fl_release_private)(struct file_lock *);
327 void (*fl_break)(struct file_lock *); /* break_lease callback */ 331 void (*fl_break)(struct file_lock *); /* break_lease callback */
328 332
@@ -330,7 +334,6 @@ locking rules:
330 BKL may block 334 BKL may block
331fl_compare_owner: yes no 335fl_compare_owner: yes no
332fl_notify: yes no 336fl_notify: yes no
333fl_copy_lock: yes no
334fl_release_private: yes yes 337fl_release_private: yes yes
335fl_break: yes no 338fl_break: yes no
336 339
diff --git a/Documentation/filesystems/configfs/configfs_example_explicit.c b/Documentation/filesystems/configfs/configfs_example_explicit.c
index d428cc9f07f3..fd53869f5633 100644
--- a/Documentation/filesystems/configfs/configfs_example_explicit.c
+++ b/Documentation/filesystems/configfs/configfs_example_explicit.c
@@ -89,7 +89,7 @@ static ssize_t childless_storeme_write(struct childless *childless,
89 char *p = (char *) page; 89 char *p = (char *) page;
90 90
91 tmp = simple_strtoul(p, &p, 10); 91 tmp = simple_strtoul(p, &p, 10);
92 if (!p || (*p && (*p != '\n'))) 92 if ((*p != '\0') && (*p != '\n'))
93 return -EINVAL; 93 return -EINVAL;
94 94
95 if (tmp > INT_MAX) 95 if (tmp > INT_MAX)
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt
index ed7e5efc06d8..20899e095e7e 100644
--- a/Documentation/filesystems/vfs.txt
+++ b/Documentation/filesystems/vfs.txt
@@ -534,6 +534,7 @@ struct address_space_operations {
534 sector_t (*bmap)(struct address_space *, sector_t); 534 sector_t (*bmap)(struct address_space *, sector_t);
535 int (*invalidatepage) (struct page *, unsigned long); 535 int (*invalidatepage) (struct page *, unsigned long);
536 int (*releasepage) (struct page *, int); 536 int (*releasepage) (struct page *, int);
537 void (*freepage)(struct page *);
537 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, 538 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
538 loff_t offset, unsigned long nr_segs); 539 loff_t offset, unsigned long nr_segs);
539 struct page* (*get_xip_page)(struct address_space *, sector_t, 540 struct page* (*get_xip_page)(struct address_space *, sector_t,
@@ -660,11 +661,10 @@ struct address_space_operations {
660 releasepage: releasepage is called on PagePrivate pages to indicate 661 releasepage: releasepage is called on PagePrivate pages to indicate
661 that the page should be freed if possible. ->releasepage 662 that the page should be freed if possible. ->releasepage
662 should remove any private data from the page and clear the 663 should remove any private data from the page and clear the
663 PagePrivate flag. It may also remove the page from the 664 PagePrivate flag. If releasepage() fails for some reason, it must
664 address_space. If this fails for some reason, it may indicate 665 indicate failure with a 0 return value.
665 failure with a 0 return value. 666 releasepage() is used in two distinct though related cases. The
666 This is used in two distinct though related cases. The first 667 first is when the VM finds a clean page with no active users and
667 is when the VM finds a clean page with no active users and
668 wants to make it a free page. If ->releasepage succeeds, the 668 wants to make it a free page. If ->releasepage succeeds, the
669 page will be removed from the address_space and become free. 669 page will be removed from the address_space and become free.
670 670
@@ -679,6 +679,12 @@ struct address_space_operations {
679 need to ensure this. Possibly it can clear the PageUptodate 679 need to ensure this. Possibly it can clear the PageUptodate
680 bit if it cannot free private data yet. 680 bit if it cannot free private data yet.
681 681
682 freepage: freepage is called once the page is no longer visible in
683 the page cache in order to allow the cleanup of any private
684 data. Since it may be called by the memory reclaimer, it
685 should not assume that the original address_space mapping still
686 exists, and it should not block.
687
682 direct_IO: called by the generic read/write routines to perform 688 direct_IO: called by the generic read/write routines to perform
683 direct_IO - that is IO requests which bypass the page cache 689 direct_IO - that is IO requests which bypass the page cache
684 and transfer data directly between the storage and the 690 and transfer data directly between the storage and the
diff --git a/Documentation/filesystems/xfs-delayed-logging-design.txt b/Documentation/filesystems/xfs-delayed-logging-design.txt
index 96d0df28bed3..7445bf335dae 100644
--- a/Documentation/filesystems/xfs-delayed-logging-design.txt
+++ b/Documentation/filesystems/xfs-delayed-logging-design.txt
@@ -794,17 +794,6 @@ designed.
794 794
795Roadmap: 795Roadmap:
796 796
7972.6.37 Remove experimental tag from mount option
798 => should be roughly 6 months after initial merge
799 => enough time to:
800 => gain confidence and fix problems reported by early
801 adopters (a.k.a. guinea pigs)
802 => address worst performance regressions and undesired
803 behaviours
804 => start tuning/optimising code for parallelism
805 => start tuning/optimising algorithms consuming
806 excessive CPU time
807
8082.6.39 Switch default mount option to use delayed logging 7972.6.39 Switch default mount option to use delayed logging
809 => should be roughly 12 months after initial merge 798 => should be roughly 12 months after initial merge
810 => enough time to shake out remaining problems before next round of 799 => enough time to shake out remaining problems before next round of
diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt
index 9633da01ff46..792faa3c06cf 100644
--- a/Documentation/gpio.txt
+++ b/Documentation/gpio.txt
@@ -617,6 +617,16 @@ and have the following read/write attributes:
617 is configured as an output, this value may be written; 617 is configured as an output, this value may be written;
618 any nonzero value is treated as high. 618 any nonzero value is treated as high.
619 619
620 If the pin can be configured as interrupt-generating interrupt
621 and if it has been configured to generate interrupts (see the
622 description of "edge"), you can poll(2) on that file and
623 poll(2) will return whenever the interrupt was triggered. If
624 you use poll(2), set the events POLLPRI and POLLERR. If you
625 use select(2), set the file descriptor in exceptfds. After
626 poll(2) returns, either lseek(2) to the beginning of the sysfs
627 file and read the new value or close the file and re-open it
628 to read the value.
629
620 "edge" ... reads as either "none", "rising", "falling", or 630 "edge" ... reads as either "none", "rising", "falling", or
621 "both". Write these strings to select the signal edge(s) 631 "both". Write these strings to select the signal edge(s)
622 that will make poll(2) on the "value" file return. 632 that will make poll(2) on the "value" file return.
diff --git a/Documentation/hwmon/lm93 b/Documentation/hwmon/lm93
index ac711f357faf..7a10616d0b44 100644
--- a/Documentation/hwmon/lm93
+++ b/Documentation/hwmon/lm93
@@ -11,7 +11,7 @@ Authors:
11 Mark M. Hoffman <mhoffman@lightlink.com> 11 Mark M. Hoffman <mhoffman@lightlink.com>
12 Ported to 2.6 by Eric J. Bowersox <ericb@aspsys.com> 12 Ported to 2.6 by Eric J. Bowersox <ericb@aspsys.com>
13 Adapted to 2.6.20 by Carsten Emde <ce@osadl.org> 13 Adapted to 2.6.20 by Carsten Emde <ce@osadl.org>
14 Modified for mainline integration by Hans J. Koch <hjk@linutronix.de> 14 Modified for mainline integration by Hans J. Koch <hjk@hansjkoch.de>
15 15
16Module Parameters 16Module Parameters
17----------------- 17-----------------
diff --git a/Documentation/hwmon/max6650 b/Documentation/hwmon/max6650
index 8be7beb9e3e8..c565650fcfc6 100644
--- a/Documentation/hwmon/max6650
+++ b/Documentation/hwmon/max6650
@@ -8,7 +8,7 @@ Supported chips:
8 Datasheet: http://pdfserv.maxim-ic.com/en/ds/MAX6650-MAX6651.pdf 8 Datasheet: http://pdfserv.maxim-ic.com/en/ds/MAX6650-MAX6651.pdf
9 9
10Authors: 10Authors:
11 Hans J. Koch <hjk@linutronix.de> 11 Hans J. Koch <hjk@hansjkoch.de>
12 John Morris <john.morris@spirentcom.com> 12 John Morris <john.morris@spirentcom.com>
13 Claus Gindhart <claus.gindhart@kontron.com> 13 Claus Gindhart <claus.gindhart@kontron.com>
14 14
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index e307914a3eda..93fe76e56522 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -15,10 +15,14 @@ Supported adapters:
15 * Intel 82801I (ICH9) 15 * Intel 82801I (ICH9)
16 * Intel EP80579 (Tolapai) 16 * Intel EP80579 (Tolapai)
17 * Intel 82801JI (ICH10) 17 * Intel 82801JI (ICH10)
18 * Intel 3400/5 Series (PCH) 18 * Intel 5/3400 Series (PCH)
19 * Intel Cougar Point (PCH) 19 * Intel Cougar Point (PCH)
20 * Intel Patsburg (PCH)
20 Datasheets: Publicly available at the Intel website 21 Datasheets: Publicly available at the Intel website
21 22
23On Intel Patsburg and later chipsets, both the normal host SMBus controller
24and the additional 'Integrated Device Function' controllers are supported.
25
22Authors: 26Authors:
23 Mark Studebaker <mdsxyz123@yahoo.com> 27 Mark Studebaker <mdsxyz123@yahoo.com>
24 Jean Delvare <khali@linux-fr.org> 28 Jean Delvare <khali@linux-fr.org>
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index ed45e9802aa8..8b61c9360999 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -706,7 +706,7 @@ and is between 256 and 4096 characters. It is defined in the file
706 arch/x86/kernel/cpu/cpufreq/elanfreq.c. 706 arch/x86/kernel/cpu/cpufreq/elanfreq.c.
707 707
708 elevator= [IOSCHED] 708 elevator= [IOSCHED]
709 Format: {"anticipatory" | "cfq" | "deadline" | "noop"} 709 Format: {"cfq" | "deadline" | "noop"}
710 See Documentation/block/as-iosched.txt and 710 See Documentation/block/as-iosched.txt and
711 Documentation/block/deadline-iosched.txt for details. 711 Documentation/block/deadline-iosched.txt for details.
712 712
@@ -2175,11 +2175,6 @@ and is between 256 and 4096 characters. It is defined in the file
2175 reset_devices [KNL] Force drivers to reset the underlying device 2175 reset_devices [KNL] Force drivers to reset the underlying device
2176 during initialization. 2176 during initialization.
2177 2177
2178 resource_alloc_from_bottom
2179 Allocate new resources from the beginning of available
2180 space, not the end. If you need to use this, please
2181 report a bug.
2182
2183 resume= [SWSUSP] 2178 resume= [SWSUSP]
2184 Specify the partition device for software suspend 2179 Specify the partition device for software suspend
2185 2180
@@ -2385,6 +2380,11 @@ and is between 256 and 4096 characters. It is defined in the file
2385 improve throughput, but will also increase the 2380 improve throughput, but will also increase the
2386 amount of memory reserved for use by the client. 2381 amount of memory reserved for use by the client.
2387 2382
2383 swapaccount[=0|1]
2384 [KNL] Enable accounting of swap in memory resource
2385 controller if no parameter or 1 is given or disable
2386 it if 0 is given (See Documentation/cgroups/memory.txt)
2387
2388 swiotlb= [IA-64] Number of I/O TLB slabs 2388 swiotlb= [IA-64] Number of I/O TLB slabs
2389 2389
2390 switches= [HW,M68k] 2390 switches= [HW,M68k]
diff --git a/Documentation/leds-class.txt b/Documentation/leds-class.txt
index 8fd5ca2ae32d..58b266bd1846 100644
--- a/Documentation/leds-class.txt
+++ b/Documentation/leds-class.txt
@@ -60,15 +60,18 @@ Hardware accelerated blink of LEDs
60 60
61Some LEDs can be programmed to blink without any CPU interaction. To 61Some LEDs can be programmed to blink without any CPU interaction. To
62support this feature, a LED driver can optionally implement the 62support this feature, a LED driver can optionally implement the
63blink_set() function (see <linux/leds.h>). If implemented, triggers can 63blink_set() function (see <linux/leds.h>). To set an LED to blinking,
64attempt to use it before falling back to software timers. The blink_set() 64however, it is better to use use the API function led_blink_set(),
65function should return 0 if the blink setting is supported, or -EINVAL 65as it will check and implement software fallback if necessary.
66otherwise, which means that LED blinking will be handled by software. 66
67 67To turn off blinking again, use the API function led_brightness_set()
68The blink_set() function should choose a user friendly blinking 68as that will not just set the LED brightness but also stop any software
69value if it is called with *delay_on==0 && *delay_off==0 parameters. In 69timers that may have been required for blinking.
70this case the driver should give back the chosen value through delay_on 70
71and delay_off parameters to the leds subsystem. 71The blink_set() function should choose a user friendly blinking value
72if it is called with *delay_on==0 && *delay_off==0 parameters. In this
73case the driver should give back the chosen value through delay_on and
74delay_off parameters to the leds subsystem.
72 75
73Setting the brightness to zero with brightness_set() callback function 76Setting the brightness to zero with brightness_set() callback function
74should completely turn off the LED and cancel the previously programmed 77should completely turn off the LED and cancel the previously programmed
diff --git a/Documentation/leds/leds-lp5521.txt b/Documentation/leds/leds-lp5521.txt
new file mode 100644
index 000000000000..c4d8d151e0fe
--- /dev/null
+++ b/Documentation/leds/leds-lp5521.txt
@@ -0,0 +1,88 @@
1Kernel driver for lp5521
2========================
3
4* National Semiconductor LP5521 led driver chip
5* Datasheet: http://www.national.com/pf/LP/LP5521.html
6
7Authors: Mathias Nyman, Yuri Zaporozhets, Samu Onkalo
8Contact: Samu Onkalo (samu.p.onkalo-at-nokia.com)
9
10Description
11-----------
12
13LP5521 can drive up to 3 channels. Leds can be controlled directly via
14the led class control interface. Channels have generic names:
15lp5521:channelx, where x is 0 .. 2
16
17All three channels can be also controlled using the engine micro programs.
18More details of the instructions can be found from the public data sheet.
19
20Control interface for the engines:
21x is 1 .. 3
22enginex_mode : disabled, load, run
23enginex_load : store program (visible only in engine load mode)
24
25Example (start to blink the channel 2 led):
26cd /sys/class/leds/lp5521:channel2/device
27echo "load" > engine3_mode
28echo "037f4d0003ff6000" > engine3_load
29echo "run" > engine3_mode
30
31stop the engine:
32echo "disabled" > engine3_mode
33
34sysfs contains a selftest entry.
35The test communicates with the chip and checks that
36the clock mode is automatically set to the requested one.
37
38Each channel has its own led current settings.
39/sys/class/leds/lp5521:channel0/led_current - RW
40/sys/class/leds/lp5521:channel0/max_current - RO
41Format: 10x mA i.e 10 means 1.0 mA
42
43example platform data:
44
45Note: chan_nr can have values between 0 and 2.
46
47static struct lp5521_led_config lp5521_led_config[] = {
48 {
49 .chan_nr = 0,
50 .led_current = 50,
51 .max_current = 130,
52 }, {
53 .chan_nr = 1,
54 .led_current = 0,
55 .max_current = 130,
56 }, {
57 .chan_nr = 2,
58 .led_current = 0,
59 .max_current = 130,
60 }
61};
62
63static int lp5521_setup(void)
64{
65 /* setup HW resources */
66}
67
68static void lp5521_release(void)
69{
70 /* Release HW resources */
71}
72
73static void lp5521_enable(bool state)
74{
75 /* Control of chip enable signal */
76}
77
78static struct lp5521_platform_data lp5521_platform_data = {
79 .led_config = lp5521_led_config,
80 .num_channels = ARRAY_SIZE(lp5521_led_config),
81 .clock_mode = LP5521_CLOCK_EXT,
82 .setup_resources = lp5521_setup,
83 .release_resources = lp5521_release,
84 .enable = lp5521_enable,
85};
86
87If the current is set to 0 in the platform data, that channel is
88disabled and it is not visible in the sysfs.
diff --git a/Documentation/leds/leds-lp5523.txt b/Documentation/leds/leds-lp5523.txt
new file mode 100644
index 000000000000..fad2feb8b7ce
--- /dev/null
+++ b/Documentation/leds/leds-lp5523.txt
@@ -0,0 +1,83 @@
1Kernel driver for lp5523
2========================
3
4* National Semiconductor LP5523 led driver chip
5* Datasheet: http://www.national.com/pf/LP/LP5523.html
6
7Authors: Mathias Nyman, Yuri Zaporozhets, Samu Onkalo
8Contact: Samu Onkalo (samu.p.onkalo-at-nokia.com)
9
10Description
11-----------
12LP5523 can drive up to 9 channels. Leds can be controlled directly via
13the led class control interface. Channels have generic names:
14lp5523:channelx where x is 0...8
15
16The chip provides 3 engines. Each engine can control channels without
17interaction from the main CPU. Details of the micro engine code can be found
18from the public data sheet. Leds can be muxed to different channels.
19
20Control interface for the engines:
21x is 1 .. 3
22enginex_mode : disabled, load, run
23enginex_load : microcode load (visible only in load mode)
24enginex_leds : led mux control (visible only in load mode)
25
26cd /sys/class/leds/lp5523:channel2/device
27echo "load" > engine3_mode
28echo "9d80400004ff05ff437f0000" > engine3_load
29echo "111111111" > engine3_leds
30echo "run" > engine3_mode
31
32sysfs contains a selftest entry. It measures each channel
33voltage level and checks if it looks reasonable. If the level is too high,
34the led is missing; if the level is too low, there is a short circuit.
35
36Selftest uses always the current from the platform data.
37
38Each channel contains led current settings.
39/sys/class/leds/lp5523:channel2/led_current - RW
40/sys/class/leds/lp5523:channel2/max_current - RO
41Format: 10x mA i.e 10 means 1.0 mA
42
43Example platform data:
44
45Note - chan_nr can have values between 0 and 8.
46
47static struct lp5523_led_config lp5523_led_config[] = {
48 {
49 .chan_nr = 0,
50 .led_current = 50,
51 .max_current = 130,
52 },
53...
54 }, {
55 .chan_nr = 8,
56 .led_current = 50,
57 .max_current = 130,
58 }
59};
60
61static int lp5523_setup(void)
62{
63 /* Setup HW resources */
64}
65
66static void lp5523_release(void)
67{
68 /* Release HW resources */
69}
70
71static void lp5523_enable(bool state)
72{
73 /* Control chip enable signal */
74}
75
76static struct lp5523_platform_data lp5523_platform_data = {
77 .led_config = lp5523_led_config,
78 .num_channels = ARRAY_SIZE(lp5523_led_config),
79 .clock_mode = LP5523_CLOCK_EXT,
80 .setup_resources = lp5523_setup,
81 .release_resources = lp5523_release,
82 .enable = lp5523_enable,
83};
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
index c7165f4cb792..3c5e465296e1 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -20,6 +20,15 @@ ip_no_pmtu_disc - BOOLEAN
20min_pmtu - INTEGER 20min_pmtu - INTEGER
21 default 562 - minimum discovered Path MTU 21 default 562 - minimum discovered Path MTU
22 22
23route/max_size - INTEGER
24 Maximum number of routes allowed in the kernel. Increase
25 this when using large numbers of interfaces and/or routes.
26
27neigh/default/gc_thresh3 - INTEGER
28 Maximum number of neighbor entries allowed. Increase this
29 when using large numbers of interfaces and when communicating
30 with large numbers of directly-connected peers.
31
23mtu_expires - INTEGER 32mtu_expires - INTEGER
24 Time, in seconds, that cached PMTU information is kept. 33 Time, in seconds, that cached PMTU information is kept.
25 34
@@ -135,6 +144,7 @@ tcp_adv_win_scale - INTEGER
135 Count buffering overhead as bytes/2^tcp_adv_win_scale 144 Count buffering overhead as bytes/2^tcp_adv_win_scale
136 (if tcp_adv_win_scale > 0) or bytes-bytes/2^(-tcp_adv_win_scale), 145 (if tcp_adv_win_scale > 0) or bytes-bytes/2^(-tcp_adv_win_scale),
137 if it is <= 0. 146 if it is <= 0.
147 Possible values are [-31, 31], inclusive.
138 Default: 2 148 Default: 2
139 149
140tcp_allowed_congestion_control - STRING 150tcp_allowed_congestion_control - STRING
diff --git a/Documentation/power/opp.txt b/Documentation/power/opp.txt
index 44d87ad3cea9..cd445582d1f8 100644
--- a/Documentation/power/opp.txt
+++ b/Documentation/power/opp.txt
@@ -37,6 +37,9 @@ Typical usage of the OPP library is as follows:
37SoC framework -> modifies on required cases certain OPPs -> OPP layer 37SoC framework -> modifies on required cases certain OPPs -> OPP layer
38 -> queries to search/retrieve information -> 38 -> queries to search/retrieve information ->
39 39
40Architectures that provide a SoC framework for OPP should select ARCH_HAS_OPP
41to make the OPP layer available.
42
40OPP layer expects each domain to be represented by a unique device pointer. SoC 43OPP layer expects each domain to be represented by a unique device pointer. SoC
41framework registers a set of initial OPPs per device with the OPP layer. This 44framework registers a set of initial OPPs per device with the OPP layer. This
42list is expected to be an optimally small number typically around 5 per device. 45list is expected to be an optimally small number typically around 5 per device.
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt
index 489e9bacd165..41cc7b30d7dd 100644
--- a/Documentation/power/runtime_pm.txt
+++ b/Documentation/power/runtime_pm.txt
@@ -379,8 +379,8 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
379 zero) 379 zero)
380 380
381 bool pm_runtime_suspended(struct device *dev); 381 bool pm_runtime_suspended(struct device *dev);
382 - return true if the device's runtime PM status is 'suspended', or false 382 - return true if the device's runtime PM status is 'suspended' and its
383 otherwise 383 'power.disable_depth' field is equal to zero, or false otherwise
384 384
385 void pm_runtime_allow(struct device *dev); 385 void pm_runtime_allow(struct device *dev);
386 - set the power.runtime_auto flag for the device and decrease its usage 386 - set the power.runtime_auto flag for the device and decrease its usage
diff --git a/Documentation/rbtree.txt b/Documentation/rbtree.txt
index 221f38be98f4..19f8278c3854 100644
--- a/Documentation/rbtree.txt
+++ b/Documentation/rbtree.txt
@@ -21,8 +21,8 @@ three rotations, respectively, to balance the tree), with slightly slower
21To quote Linux Weekly News: 21To quote Linux Weekly News:
22 22
23 There are a number of red-black trees in use in the kernel. 23 There are a number of red-black trees in use in the kernel.
24 The anticipatory, deadline, and CFQ I/O schedulers all employ 24 The deadline and CFQ I/O schedulers employ rbtrees to
25 rbtrees to track requests; the packet CD/DVD driver does the same. 25 track requests; the packet CD/DVD driver does the same.
26 The high-resolution timer code uses an rbtree to organize outstanding 26 The high-resolution timer code uses an rbtree to organize outstanding
27 timer requests. The ext3 filesystem tracks directory entries in a 27 timer requests. The ext3 filesystem tracks directory entries in a
28 red-black tree. Virtual memory areas (VMAs) are tracked with red-black 28 red-black tree. Virtual memory areas (VMAs) are tracked with red-black
diff --git a/Documentation/scsi/ChangeLog.megaraid_sas b/Documentation/scsi/ChangeLog.megaraid_sas
index 30023568805e..00301ed9c371 100644
--- a/Documentation/scsi/ChangeLog.megaraid_sas
+++ b/Documentation/scsi/ChangeLog.megaraid_sas
@@ -1,3 +1,50 @@
11 Release Date : Thur. May 03, 2010 09:12:45 PST 2009 -
2 (emaild-id:megaraidlinux@lsi.com)
3 Bo Yang
4
52 Current Version : 00.00.04.31-rc1
63 Older Version : 00.00.04.17.1-rc1
7
81. Add the Online Controller Reset (OCR) to the Driver.
9 OCR is the new feature for megaraid_sas driver which
10 will allow the fw to do the chip reset which will not
11 affact the OS behavious.
12
13 To add the OCR support, driver need to do:
14 a). reset the controller chips -- Xscale and Gen2 which
15 will change the function calls and add the reset function
16 related to this two chips.
17
18 b). during the reset, driver will store the pending cmds
19 which not returned by FW to driver's pending queue. Driver
20 will re-issue those pending cmds again to FW after the OCR
21 finished.
22
23 c). In driver's timeout routine, driver will report to
24 OS as reset. Also driver's queue routine will block the
25 cmds until the OCR finished.
26
27 d). in Driver's ISR routine, if driver get the FW state as
28 state change, FW in Failure status and FW support online controller
29 reset (OCR), driver will start to do the controller reset.
30
31 e). In driver's IOCTL routine, the application cmds will wait for the
32 OCR to finish, then issue the cmds to FW.
33
34 f). Before driver kill adapter, driver will do last chance of
35 OCR to see if driver can bring back the FW.
36
372. Add the support update flag to the driver to tell LSI megaraid_sas
38 application which driver will support the device update. So application
39 will not need to do the device update after application add/del the device
40 from the system.
413. In driver's timeout routine, driver will do three time reset if fw is in
42 failed state. Driver will kill adapter if can't bring back FW after the
43 this three times reset.
444. Add the input parameter max_sectors to 1MB support to our GEN2 controller.
45 customer can use the input paramenter max_sectors to add 1MB support to GEN2
46 controller.
47
11 Release Date : Thur. Oct 29, 2009 09:12:45 PST 2009 - 481 Release Date : Thur. Oct 29, 2009 09:12:45 PST 2009 -
2 (emaild-id:megaraidlinux@lsi.com) 49 (emaild-id:megaraidlinux@lsi.com)
3 Bo Yang 50 Bo Yang
diff --git a/Documentation/sh/clk.txt b/Documentation/sh/clk.txt
deleted file mode 100644
index 114b595cfa97..000000000000
--- a/Documentation/sh/clk.txt
+++ /dev/null
@@ -1,32 +0,0 @@
1Clock framework on SuperH architecture
2
3The framework on SH extends existing API by the function clk_set_rate_ex,
4which prototype is as follows:
5
6 clk_set_rate_ex (struct clk *clk, unsigned long rate, int algo_id)
7
8The algo_id parameter is used to specify algorithm used to recalculate clocks,
9adjanced to clock, specified as first argument. It is assumed that algo_id==0
10means no changes to adjanced clock
11
12Internally, the clk_set_rate_ex forwards request to clk->ops->set_rate method,
13if it is present in ops structure. The method should set the clock rate and adjust
14all needed clocks according to the passed algo_id.
15Exact values for algo_id are machine-dependent. For the sh7722, the following
16values are defined:
17
18 NO_CHANGE = 0,
19 IUS_N1_N1, /* I:U = N:1, U:Sh = N:1 */
20 IUS_322, /* I:U:Sh = 3:2:2 */
21 IUS_522, /* I:U:Sh = 5:2:2 */
22 IUS_N11, /* I:U:Sh = N:1:1 */
23 SB_N1, /* Sh:B = N:1 */
24 SB3_N1, /* Sh:B3 = N:1 */
25 SB3_32, /* Sh:B3 = 3:2 */
26 SB3_43, /* Sh:B3 = 4:3 */
27 SB3_54, /* Sh:B3 = 5:4 */
28 BP_N1, /* B:P = N:1 */
29 IP_N1 /* I:P = N:1 */
30
31Each of these constants means relation between clocks that can be set via the FRQCR
32register
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index 3894eaa23486..209e1584c3dc 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -28,6 +28,7 @@ show up in /proc/sys/kernel:
28- core_uses_pid 28- core_uses_pid
29- ctrl-alt-del 29- ctrl-alt-del
30- dentry-state 30- dentry-state
31- dmesg_restrict
31- domainname 32- domainname
32- hostname 33- hostname
33- hotplug 34- hotplug
@@ -213,6 +214,19 @@ to decide what to do with it.
213 214
214============================================================== 215==============================================================
215 216
217dmesg_restrict:
218
219This toggle indicates whether unprivileged users are prevented from using
220dmesg(8) to view messages from the kernel's log buffer. When
221dmesg_restrict is set to (0) there are no restrictions. When
222dmesg_restrict is set set to (1), users must have CAP_SYS_ADMIN to use
223dmesg(8).
224
225The kernel config option CONFIG_SECURITY_DMESG_RESTRICT sets the default
226value of dmesg_restrict.
227
228==============================================================
229
216domainname & hostname: 230domainname & hostname:
217 231
218These files can be used to set the NIS/YP domainname and the 232These files can be used to set the NIS/YP domainname and the
diff --git a/MAINTAINERS b/MAINTAINERS
index 4d204e2a9754..510997499b59 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -161,7 +161,7 @@ M: Greg Kroah-Hartman <gregkh@suse.de>
161L: linux-serial@vger.kernel.org 161L: linux-serial@vger.kernel.org
162W: http://serial.sourceforge.net 162W: http://serial.sourceforge.net
163S: Maintained 163S: Maintained
164T: quilt kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/ 164T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6.git
165F: drivers/serial/8250* 165F: drivers/serial/8250*
166F: include/linux/serial_8250.h 166F: include/linux/serial_8250.h
167 167
@@ -559,14 +559,14 @@ W: http://maxim.org.za/at91_26.html
559S: Maintained 559S: Maintained
560 560
561ARM/BCMRING ARM ARCHITECTURE 561ARM/BCMRING ARM ARCHITECTURE
562M: Leo Chen <leochen@broadcom.com> 562M: Jiandong Zheng <jdzheng@broadcom.com>
563M: Scott Branden <sbranden@broadcom.com> 563M: Scott Branden <sbranden@broadcom.com>
564L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 564L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
565S: Maintained 565S: Maintained
566F: arch/arm/mach-bcmring 566F: arch/arm/mach-bcmring
567 567
568ARM/BCMRING MTD NAND DRIVER 568ARM/BCMRING MTD NAND DRIVER
569M: Leo Chen <leochen@broadcom.com> 569M: Jiandong Zheng <jdzheng@broadcom.com>
570M: Scott Branden <sbranden@broadcom.com> 570M: Scott Branden <sbranden@broadcom.com>
571L: linux-mtd@lists.infradead.org 571L: linux-mtd@lists.infradead.org
572S: Maintained 572S: Maintained
@@ -815,7 +815,7 @@ F: drivers/mmc/host/msm_sdcc.c
815F: drivers/mmc/host/msm_sdcc.h 815F: drivers/mmc/host/msm_sdcc.h
816F: drivers/serial/msm_serial.h 816F: drivers/serial/msm_serial.h
817F: drivers/serial/msm_serial.c 817F: drivers/serial/msm_serial.c
818T: git git://codeaurora.org/quic/kernel/dwalker/linux-msm.git 818T: git git://codeaurora.org/quic/kernel/davidb/linux-msm.git
819S: Maintained 819S: Maintained
820 820
821ARM/TOSA MACHINE SUPPORT 821ARM/TOSA MACHINE SUPPORT
@@ -945,7 +945,7 @@ M: Magnus Damm <magnus.damm@gmail.com>
945L: linux-sh@vger.kernel.org 945L: linux-sh@vger.kernel.org
946W: http://oss.renesas.com 946W: http://oss.renesas.com
947Q: http://patchwork.kernel.org/project/linux-sh/list/ 947Q: http://patchwork.kernel.org/project/linux-sh/list/
948T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/genesis-2.6.git 948T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git rmobile-latest
949S: Supported 949S: Supported
950F: arch/arm/mach-shmobile/ 950F: arch/arm/mach-shmobile/
951F: drivers/sh/ 951F: drivers/sh/
@@ -1359,7 +1359,7 @@ F: include/net/bluetooth/
1359 1359
1360BONDING DRIVER 1360BONDING DRIVER
1361M: Jay Vosburgh <fubar@us.ibm.com> 1361M: Jay Vosburgh <fubar@us.ibm.com>
1362L: bonding-devel@lists.sourceforge.net 1362L: netdev@vger.kernel.org
1363W: http://sourceforge.net/projects/bonding/ 1363W: http://sourceforge.net/projects/bonding/
1364S: Supported 1364S: Supported
1365F: drivers/net/bonding/ 1365F: drivers/net/bonding/
@@ -1757,6 +1757,7 @@ L: linux-cris-kernel@axis.com
1757W: http://developer.axis.com 1757W: http://developer.axis.com
1758S: Maintained 1758S: Maintained
1759F: arch/cris/ 1759F: arch/cris/
1760F: drivers/serial/crisv10.*
1760 1761
1761CRYPTO API 1762CRYPTO API
1762M: Herbert Xu <herbert@gondor.apana.org.au> 1763M: Herbert Xu <herbert@gondor.apana.org.au>
@@ -1828,6 +1829,13 @@ W: http://www.chelsio.com
1828S: Supported 1829S: Supported
1829F: drivers/net/cxgb4vf/ 1830F: drivers/net/cxgb4vf/
1830 1831
1832STMMAC ETHERNET DRIVER
1833M: Giuseppe Cavallaro <peppe.cavallaro@st.com>
1834L: netdev@vger.kernel.org
1835W: http://www.stlinux.com
1836S: Supported
1837F: drivers/net/stmmac/
1838
1831CYBERPRO FB DRIVER 1839CYBERPRO FB DRIVER
1832M: Russell King <linux@arm.linux.org.uk> 1840M: Russell King <linux@arm.linux.org.uk>
1833L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1841L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
@@ -2007,6 +2015,7 @@ F: drivers/hwmon/dme1737.c
2007DOCBOOK FOR DOCUMENTATION 2015DOCBOOK FOR DOCUMENTATION
2008M: Randy Dunlap <rdunlap@xenotime.net> 2016M: Randy Dunlap <rdunlap@xenotime.net>
2009S: Maintained 2017S: Maintained
2018F: scripts/kernel-doc
2010 2019
2011DOCKING STATION DRIVER 2020DOCKING STATION DRIVER
2012M: Shaohua Li <shaohua.li@intel.com> 2021M: Shaohua Li <shaohua.li@intel.com>
@@ -2017,6 +2026,7 @@ F: drivers/acpi/dock.c
2017DOCUMENTATION 2026DOCUMENTATION
2018M: Randy Dunlap <rdunlap@xenotime.net> 2027M: Randy Dunlap <rdunlap@xenotime.net>
2019L: linux-doc@vger.kernel.org 2028L: linux-doc@vger.kernel.org
2029T: quilt oss.oracle.com/~rdunlap/kernel-doc-patches/current/
2020S: Maintained 2030S: Maintained
2021F: Documentation/ 2031F: Documentation/
2022 2032
@@ -2050,7 +2060,7 @@ F: Documentation/blockdev/drbd/
2050 2060
2051DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS 2061DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS
2052M: Greg Kroah-Hartman <gregkh@suse.de> 2062M: Greg Kroah-Hartman <gregkh@suse.de>
2053T: quilt kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/ 2063T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6.git
2054S: Supported 2064S: Supported
2055F: Documentation/kobject.txt 2065F: Documentation/kobject.txt
2056F: drivers/base/ 2066F: drivers/base/
@@ -2070,7 +2080,7 @@ F: include/drm/
2070 2080
2071INTEL DRM DRIVERS (excluding Poulsbo, Moorestown and derivative chipsets) 2081INTEL DRM DRIVERS (excluding Poulsbo, Moorestown and derivative chipsets)
2072M: Chris Wilson <chris@chris-wilson.co.uk> 2082M: Chris Wilson <chris@chris-wilson.co.uk>
2073L: intel-gfx@lists.freedesktop.org 2083L: intel-gfx@lists.freedesktop.org (subscribers-only)
2074L: dri-devel@lists.freedesktop.org 2084L: dri-devel@lists.freedesktop.org
2075T: git git://git.kernel.org/pub/scm/linux/kernel/git/ickle/drm-intel.git 2085T: git git://git.kernel.org/pub/scm/linux/kernel/git/ickle/drm-intel.git
2076S: Supported 2086S: Supported
@@ -2434,9 +2444,12 @@ F: drivers/net/wan/sdla.c
2434FRAMEBUFFER LAYER 2444FRAMEBUFFER LAYER
2435L: linux-fbdev@vger.kernel.org 2445L: linux-fbdev@vger.kernel.org
2436W: http://linux-fbdev.sourceforge.net/ 2446W: http://linux-fbdev.sourceforge.net/
2447Q: http://patchwork.kernel.org/project/linux-fbdev/list/
2448T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/fbdev-2.6.git
2437S: Orphan 2449S: Orphan
2438F: Documentation/fb/ 2450F: Documentation/fb/
2439F: drivers/video/fb* 2451F: drivers/video/
2452F: include/video/
2440F: include/linux/fb.h 2453F: include/linux/fb.h
2441 2454
2442FREESCALE DMA DRIVER 2455FREESCALE DMA DRIVER
@@ -4051,9 +4064,8 @@ F: drivers/scsi/NCR_D700.*
4051 4064
4052NETEFFECT IWARP RNIC DRIVER (IW_NES) 4065NETEFFECT IWARP RNIC DRIVER (IW_NES)
4053M: Faisal Latif <faisal.latif@intel.com> 4066M: Faisal Latif <faisal.latif@intel.com>
4054M: Chien Tung <chien.tin.tung@intel.com>
4055L: linux-rdma@vger.kernel.org 4067L: linux-rdma@vger.kernel.org
4056W: http://www.neteffect.com 4068W: http://www.intel.com/Products/Server/Adapters/Server-Cluster/Server-Cluster-overview.htm
4057S: Supported 4069S: Supported
4058F: drivers/infiniband/hw/nes/ 4070F: drivers/infiniband/hw/nes/
4059 4071
@@ -5675,7 +5687,7 @@ S: Maintained
5675 5687
5676STAGING SUBSYSTEM 5688STAGING SUBSYSTEM
5677M: Greg Kroah-Hartman <gregkh@suse.de> 5689M: Greg Kroah-Hartman <gregkh@suse.de>
5678T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-next-2.6.git 5690T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6.git
5679L: devel@driverdev.osuosl.org 5691L: devel@driverdev.osuosl.org
5680S: Maintained 5692S: Maintained
5681F: drivers/staging/ 5693F: drivers/staging/
@@ -5704,7 +5716,7 @@ M: Paul Mundt <lethal@linux-sh.org>
5704L: linux-sh@vger.kernel.org 5716L: linux-sh@vger.kernel.org
5705W: http://www.linux-sh.org 5717W: http://www.linux-sh.org
5706Q: http://patchwork.kernel.org/project/linux-sh/list/ 5718Q: http://patchwork.kernel.org/project/linux-sh/list/
5707T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git 5719T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git sh-latest
5708S: Supported 5720S: Supported
5709F: Documentation/sh/ 5721F: Documentation/sh/
5710F: arch/sh/ 5722F: arch/sh/
@@ -5826,6 +5838,8 @@ M: Chris Metcalf <cmetcalf@tilera.com>
5826W: http://www.tilera.com/scm/ 5838W: http://www.tilera.com/scm/
5827S: Supported 5839S: Supported
5828F: arch/tile/ 5840F: arch/tile/
5841F: drivers/char/hvc_tile.c
5842F: drivers/net/tile/
5829 5843
5830TLAN NETWORK DRIVER 5844TLAN NETWORK DRIVER
5831M: Samuel Chessman <chessman@tux.org> 5845M: Samuel Chessman <chessman@tux.org>
@@ -5909,7 +5923,7 @@ S: Maintained
5909TTY LAYER 5923TTY LAYER
5910M: Greg Kroah-Hartman <gregkh@suse.de> 5924M: Greg Kroah-Hartman <gregkh@suse.de>
5911S: Maintained 5925S: Maintained
5912T: quilt kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/ 5926T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6.git
5913F: drivers/char/tty_* 5927F: drivers/char/tty_*
5914F: drivers/serial/serial_core.c 5928F: drivers/serial/serial_core.c
5915F: include/linux/serial_core.h 5929F: include/linux/serial_core.h
@@ -5918,7 +5932,6 @@ F: include/linux/tty.h
5918 5932
5919TULIP NETWORK DRIVERS 5933TULIP NETWORK DRIVERS
5920M: Grant Grundler <grundler@parisc-linux.org> 5934M: Grant Grundler <grundler@parisc-linux.org>
5921M: Kyle McMartin <kyle@mcmartin.ca>
5922L: netdev@vger.kernel.org 5935L: netdev@vger.kernel.org
5923S: Maintained 5936S: Maintained
5924F: drivers/net/tulip/ 5937F: drivers/net/tulip/
@@ -6232,7 +6245,7 @@ USB SUBSYSTEM
6232M: Greg Kroah-Hartman <gregkh@suse.de> 6245M: Greg Kroah-Hartman <gregkh@suse.de>
6233L: linux-usb@vger.kernel.org 6246L: linux-usb@vger.kernel.org
6234W: http://www.linux-usb.org 6247W: http://www.linux-usb.org
6235T: quilt kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/ 6248T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6.git
6236S: Supported 6249S: Supported
6237F: Documentation/usb/ 6250F: Documentation/usb/
6238F: drivers/net/usb/ 6251F: drivers/net/usb/
@@ -6570,6 +6583,15 @@ F: include/linux/mfd/wm8400*
6570F: include/sound/wm????.h 6583F: include/sound/wm????.h
6571F: sound/soc/codecs/wm* 6584F: sound/soc/codecs/wm*
6572 6585
6586WORKQUEUE
6587M: Tejun Heo <tj@kernel.org>
6588L: linux-kernel@vger.kernel.org
6589T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git
6590S: Maintained
6591F: include/linux/workqueue.h
6592F: kernel/workqueue.c
6593F: Documentation/workqueue.txt
6594
6573X.25 NETWORK LAYER 6595X.25 NETWORK LAYER
6574M: Andrew Hendry <andrew.hendry@gmail.com> 6596M: Andrew Hendry <andrew.hendry@gmail.com>
6575L: linux-x25@vger.kernel.org 6597L: linux-x25@vger.kernel.org
@@ -6597,14 +6619,14 @@ F: drivers/platform/x86
6597 6619
6598XEN PCI SUBSYSTEM 6620XEN PCI SUBSYSTEM
6599M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 6621M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
6600L: xen-devel@lists.xensource.com 6622L: xen-devel@lists.xensource.com (moderated for non-subscribers)
6601S: Supported 6623S: Supported
6602F: arch/x86/pci/*xen* 6624F: arch/x86/pci/*xen*
6603F: drivers/pci/*xen* 6625F: drivers/pci/*xen*
6604 6626
6605XEN SWIOTLB SUBSYSTEM 6627XEN SWIOTLB SUBSYSTEM
6606M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 6628M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
6607L: xen-devel@lists.xensource.com 6629L: xen-devel@lists.xensource.com (moderated for non-subscribers)
6608S: Supported 6630S: Supported
6609F: arch/x86/xen/*swiotlb* 6631F: arch/x86/xen/*swiotlb*
6610F: drivers/xen/*swiotlb* 6632F: drivers/xen/*swiotlb*
@@ -6612,7 +6634,7 @@ F: drivers/xen/*swiotlb*
6612XEN HYPERVISOR INTERFACE 6634XEN HYPERVISOR INTERFACE
6613M: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com> 6635M: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
6614M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 6636M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
6615L: xen-devel@lists.xen.org 6637L: xen-devel@lists.xensource.com (moderated for non-subscribers)
6616L: virtualization@lists.linux-foundation.org 6638L: virtualization@lists.linux-foundation.org
6617S: Supported 6639S: Supported
6618F: arch/x86/xen/ 6640F: arch/x86/xen/
diff --git a/Makefile b/Makefile
index 519db43052a0..77044b7918a5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 2 1VERSION = 2
2PATCHLEVEL = 6 2PATCHLEVEL = 6
3SUBLEVEL = 36 3SUBLEVEL = 37
4EXTRAVERSION = 4EXTRAVERSION = -rc7
5NAME = Flesh-Eating Bats with Fangs 5NAME = Flesh-Eating Bats with Fangs
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index a19a5266d5fc..d56d21c0573b 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -6,10 +6,10 @@ config ARM
6 select HAVE_MEMBLOCK 6 select HAVE_MEMBLOCK
7 select RTC_LIB 7 select RTC_LIB
8 select SYS_SUPPORTS_APM_EMULATION 8 select SYS_SUPPORTS_APM_EMULATION
9 select GENERIC_ATOMIC64 if (!CPU_32v6K) 9 select GENERIC_ATOMIC64 if (!CPU_32v6K || !AEABI)
10 select HAVE_OPROFILE if (HAVE_PERF_EVENTS) 10 select HAVE_OPROFILE if (HAVE_PERF_EVENTS)
11 select HAVE_ARCH_KGDB 11 select HAVE_ARCH_KGDB
12 select HAVE_KPROBES if (!XIP_KERNEL) 12 select HAVE_KPROBES if (!XIP_KERNEL && !THUMB2_KERNEL)
13 select HAVE_KRETPROBES if (HAVE_KPROBES) 13 select HAVE_KRETPROBES if (HAVE_KPROBES)
14 select HAVE_FUNCTION_TRACER if (!XIP_KERNEL) 14 select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
15 select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) 15 select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
@@ -646,7 +646,7 @@ config ARCH_S3C2410
646 select ARCH_HAS_CPUFREQ 646 select ARCH_HAS_CPUFREQ
647 select HAVE_CLK 647 select HAVE_CLK
648 select ARCH_USES_GETTIMEOFFSET 648 select ARCH_USES_GETTIMEOFFSET
649 select HAVE_S3C2410_I2C 649 select HAVE_S3C2410_I2C if I2C
650 help 650 help
651 Samsung S3C2410X CPU based systems, such as the Simtec Electronics 651 Samsung S3C2410X CPU based systems, such as the Simtec Electronics
652 BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or 652 BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or
@@ -676,8 +676,8 @@ config ARCH_S3C64XX
676 select S3C_DEV_NAND 676 select S3C_DEV_NAND
677 select USB_ARCH_HAS_OHCI 677 select USB_ARCH_HAS_OHCI
678 select SAMSUNG_GPIOLIB_4BIT 678 select SAMSUNG_GPIOLIB_4BIT
679 select HAVE_S3C2410_I2C 679 select HAVE_S3C2410_I2C if I2C
680 select HAVE_S3C2410_WATCHDOG 680 select HAVE_S3C2410_WATCHDOG if WATCHDOG
681 help 681 help
682 Samsung S3C64XX series based systems 682 Samsung S3C64XX series based systems
683 683
@@ -686,10 +686,10 @@ config ARCH_S5P64X0
686 select CPU_V6 686 select CPU_V6
687 select GENERIC_GPIO 687 select GENERIC_GPIO
688 select HAVE_CLK 688 select HAVE_CLK
689 select HAVE_S3C2410_WATCHDOG 689 select HAVE_S3C2410_WATCHDOG if WATCHDOG
690 select ARCH_USES_GETTIMEOFFSET 690 select ARCH_USES_GETTIMEOFFSET
691 select HAVE_S3C2410_I2C 691 select HAVE_S3C2410_I2C if I2C
692 select HAVE_S3C_RTC 692 select HAVE_S3C_RTC if RTC_CLASS
693 help 693 help
694 Samsung S5P64X0 CPU based systems, such as the Samsung SMDK6440, 694 Samsung S5P64X0 CPU based systems, such as the Samsung SMDK6440,
695 SMDK6450. 695 SMDK6450.
@@ -700,7 +700,7 @@ config ARCH_S5P6442
700 select GENERIC_GPIO 700 select GENERIC_GPIO
701 select HAVE_CLK 701 select HAVE_CLK
702 select ARCH_USES_GETTIMEOFFSET 702 select ARCH_USES_GETTIMEOFFSET
703 select HAVE_S3C2410_WATCHDOG 703 select HAVE_S3C2410_WATCHDOG if WATCHDOG
704 help 704 help
705 Samsung S5P6442 CPU based systems 705 Samsung S5P6442 CPU based systems
706 706
@@ -711,9 +711,9 @@ config ARCH_S5PC100
711 select CPU_V7 711 select CPU_V7
712 select ARM_L1_CACHE_SHIFT_6 712 select ARM_L1_CACHE_SHIFT_6
713 select ARCH_USES_GETTIMEOFFSET 713 select ARCH_USES_GETTIMEOFFSET
714 select HAVE_S3C2410_I2C 714 select HAVE_S3C2410_I2C if I2C
715 select HAVE_S3C_RTC 715 select HAVE_S3C_RTC if RTC_CLASS
716 select HAVE_S3C2410_WATCHDOG 716 select HAVE_S3C2410_WATCHDOG if WATCHDOG
717 help 717 help
718 Samsung S5PC100 series based systems 718 Samsung S5PC100 series based systems
719 719
@@ -726,9 +726,9 @@ config ARCH_S5PV210
726 select ARM_L1_CACHE_SHIFT_6 726 select ARM_L1_CACHE_SHIFT_6
727 select ARCH_HAS_CPUFREQ 727 select ARCH_HAS_CPUFREQ
728 select ARCH_USES_GETTIMEOFFSET 728 select ARCH_USES_GETTIMEOFFSET
729 select HAVE_S3C2410_I2C 729 select HAVE_S3C2410_I2C if I2C
730 select HAVE_S3C_RTC 730 select HAVE_S3C_RTC if RTC_CLASS
731 select HAVE_S3C2410_WATCHDOG 731 select HAVE_S3C2410_WATCHDOG if WATCHDOG
732 help 732 help
733 Samsung S5PV210/S5PC110 series based systems 733 Samsung S5PV210/S5PC110 series based systems
734 734
@@ -739,9 +739,9 @@ config ARCH_S5PV310
739 select GENERIC_GPIO 739 select GENERIC_GPIO
740 select HAVE_CLK 740 select HAVE_CLK
741 select GENERIC_CLOCKEVENTS 741 select GENERIC_CLOCKEVENTS
742 select HAVE_S3C_RTC 742 select HAVE_S3C_RTC if RTC_CLASS
743 select HAVE_S3C2410_I2C 743 select HAVE_S3C2410_I2C if I2C
744 select HAVE_S3C2410_WATCHDOG 744 select HAVE_S3C2410_WATCHDOG if WATCHDOG
745 help 745 help
746 Samsung S5PV310 series based systems 746 Samsung S5PV310 series based systems
747 747
@@ -1311,7 +1311,7 @@ config HZ
1311 1311
1312config THUMB2_KERNEL 1312config THUMB2_KERNEL
1313 bool "Compile the kernel in Thumb-2 mode" 1313 bool "Compile the kernel in Thumb-2 mode"
1314 depends on CPU_V7 && EXPERIMENTAL 1314 depends on CPU_V7 && !CPU_V6 && EXPERIMENTAL
1315 select AEABI 1315 select AEABI
1316 select ARM_ASM_UNIFIED 1316 select ARM_ASM_UNIFIED
1317 help 1317 help
@@ -1759,7 +1759,7 @@ comment "At least one emulation must be selected"
1759 1759
1760config FPE_NWFPE 1760config FPE_NWFPE
1761 bool "NWFPE math emulation" 1761 bool "NWFPE math emulation"
1762 depends on !AEABI || OABI_COMPAT 1762 depends on (!AEABI || OABI_COMPAT) && !THUMB2_KERNEL
1763 ---help--- 1763 ---help---
1764 Say Y to include the NWFPE floating point emulator in the kernel. 1764 Say Y to include the NWFPE floating point emulator in the kernel.
1765 This is necessary to run most binaries. Linux does not currently 1765 This is necessary to run most binaries. Linux does not currently
diff --git a/arch/arm/boot/Makefile b/arch/arm/boot/Makefile
index 4a590f4113e2..4d26f2c52a75 100644
--- a/arch/arm/boot/Makefile
+++ b/arch/arm/boot/Makefile
@@ -70,12 +70,7 @@ else
70$(obj)/uImage: LOADADDR=$(ZRELADDR) 70$(obj)/uImage: LOADADDR=$(ZRELADDR)
71endif 71endif
72 72
73ifeq ($(CONFIG_THUMB2_KERNEL),y)
74# Set bit 0 to 1 so that "mov pc, rx" switches to Thumb-2 mode
75$(obj)/uImage: STARTADDR=$(shell echo $(LOADADDR) | sed -e "s/.$$/1/")
76else
77$(obj)/uImage: STARTADDR=$(LOADADDR) 73$(obj)/uImage: STARTADDR=$(LOADADDR)
78endif
79 74
80$(obj)/uImage: $(obj)/zImage FORCE 75$(obj)/uImage: $(obj)/zImage FORCE
81 $(call if_changed,uimage) 76 $(call if_changed,uimage)
diff --git a/arch/arm/boot/bootp/init.S b/arch/arm/boot/bootp/init.S
index 8b0de41c3dcb..78b508075161 100644
--- a/arch/arm/boot/bootp/init.S
+++ b/arch/arm/boot/bootp/init.S
@@ -73,6 +73,8 @@ move: ldmia r4!, {r7 - r10} @ move 32-bytes at a time
73 73
74 .size _start, . - _start 74 .size _start, . - _start
75 75
76 .align
77
76 .type data,#object 78 .type data,#object
77data: .word initrd_start @ source initrd address 79data: .word initrd_start @ source initrd address
78 .word initrd_phys @ destination initrd address 80 .word initrd_phys @ destination initrd address
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 6825c34646d4..7193884ed8b0 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -125,9 +125,13 @@ wait: mrc p14, 0, pc, c0, c1, 0
125 * sort out different calling conventions 125 * sort out different calling conventions
126 */ 126 */
127 .align 127 .align
128 .arm @ Always enter in ARM state
128start: 129start:
129 .type start,#function 130 .type start,#function
130 .rept 8 131 THUMB( adr r12, BSYM(1f) )
132 THUMB( bx r12 )
133 THUMB( .rept 6 )
134 ARM( .rept 8 )
131 mov r0, r0 135 mov r0, r0
132 .endr 136 .endr
133 137
@@ -135,6 +139,7 @@ start:
135 .word 0x016f2818 @ Magic numbers to help the loader 139 .word 0x016f2818 @ Magic numbers to help the loader
136 .word start @ absolute load/run zImage address 140 .word start @ absolute load/run zImage address
137 .word _edata @ zImage end address 141 .word _edata @ zImage end address
142 THUMB( .thumb )
1381: mov r7, r1 @ save architecture ID 1431: mov r7, r1 @ save architecture ID
139 mov r8, r2 @ save atags pointer 144 mov r8, r2 @ save atags pointer
140 145
@@ -174,7 +179,8 @@ not_angel:
174 ldr sp, [r0, #28] 179 ldr sp, [r0, #28]
175#ifdef CONFIG_AUTO_ZRELADDR 180#ifdef CONFIG_AUTO_ZRELADDR
176 @ determine final kernel image address 181 @ determine final kernel image address
177 and r4, pc, #0xf8000000 182 mov r4, pc
183 and r4, r4, #0xf8000000
178 add r4, r4, #TEXT_OFFSET 184 add r4, r4, #TEXT_OFFSET
179#else 185#else
180 ldr r4, =zreladdr 186 ldr r4, =zreladdr
@@ -445,7 +451,8 @@ __setup_mmu: sub r3, r4, #16384 @ Page directory size
445 */ 451 */
446 mov r1, #0x1e 452 mov r1, #0x1e
447 orr r1, r1, #3 << 10 453 orr r1, r1, #3 << 10
448 mov r2, pc, lsr #20 454 mov r2, pc
455 mov r2, r2, lsr #20
449 orr r1, r1, r2, lsl #20 456 orr r1, r1, r2, lsl #20
450 add r0, r3, r2, lsl #2 457 add r0, r3, r2, lsl #2
451 str r1, [r0], #4 458 str r1, [r0], #4
@@ -1084,6 +1091,6 @@ memdump: mov r12, r0
1084reloc_end: 1091reloc_end:
1085 1092
1086 .align 1093 .align
1087 .section ".stack", "w" 1094 .section ".stack", "aw", %nobits
1088user_stack: .space 4096 1095user_stack: .space 4096
1089user_stack_end: 1096user_stack_end:
diff --git a/arch/arm/boot/compressed/vmlinux.lds.in b/arch/arm/boot/compressed/vmlinux.lds.in
index d08168941bd6..366a924019ac 100644
--- a/arch/arm/boot/compressed/vmlinux.lds.in
+++ b/arch/arm/boot/compressed/vmlinux.lds.in
@@ -57,7 +57,7 @@ SECTIONS
57 .bss : { *(.bss) } 57 .bss : { *(.bss) }
58 _end = .; 58 _end = .;
59 59
60 .stack (NOLOAD) : { *(.stack) } 60 .stack : { *(.stack) }
61 61
62 .stab 0 : { *(.stab) } 62 .stab 0 : { *(.stab) }
63 .stabstr 0 : { *(.stabstr) } 63 .stabstr 0 : { *(.stabstr) }
diff --git a/arch/arm/common/gic.c b/arch/arm/common/gic.c
index ada6359160eb..e6388dcd8cfa 100644
--- a/arch/arm/common/gic.c
+++ b/arch/arm/common/gic.c
@@ -146,9 +146,15 @@ static int gic_set_cpu(unsigned int irq, const struct cpumask *mask_val)
146 unsigned int shift = (irq % 4) * 8; 146 unsigned int shift = (irq % 4) * 8;
147 unsigned int cpu = cpumask_first(mask_val); 147 unsigned int cpu = cpumask_first(mask_val);
148 u32 val; 148 u32 val;
149 struct irq_desc *desc;
149 150
150 spin_lock(&irq_controller_lock); 151 spin_lock(&irq_controller_lock);
151 irq_desc[irq].node = cpu; 152 desc = irq_to_desc(irq);
153 if (desc == NULL) {
154 spin_unlock(&irq_controller_lock);
155 return -EINVAL;
156 }
157 desc->node = cpu;
152 val = readl(reg) & ~(0xff << shift); 158 val = readl(reg) & ~(0xff << shift);
153 val |= 1 << (cpu + shift); 159 val |= 1 << (cpu + shift);
154 writel(val, reg); 160 writel(val, reg);
@@ -210,7 +216,7 @@ void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq)
210void __init gic_dist_init(unsigned int gic_nr, void __iomem *base, 216void __init gic_dist_init(unsigned int gic_nr, void __iomem *base,
211 unsigned int irq_start) 217 unsigned int irq_start)
212{ 218{
213 unsigned int max_irq, i; 219 unsigned int gic_irqs, irq_limit, i;
214 u32 cpumask = 1 << smp_processor_id(); 220 u32 cpumask = 1 << smp_processor_id();
215 221
216 if (gic_nr >= MAX_GIC_NR) 222 if (gic_nr >= MAX_GIC_NR)
@@ -226,46 +232,49 @@ void __init gic_dist_init(unsigned int gic_nr, void __iomem *base,
226 232
227 /* 233 /*
228 * Find out how many interrupts are supported. 234 * Find out how many interrupts are supported.
229 */
230 max_irq = readl(base + GIC_DIST_CTR) & 0x1f;
231 max_irq = (max_irq + 1) * 32;
232
233 /*
234 * The GIC only supports up to 1020 interrupt sources. 235 * The GIC only supports up to 1020 interrupt sources.
235 * Limit this to either the architected maximum, or the
236 * platform maximum.
237 */ 236 */
238 if (max_irq > max(1020, NR_IRQS)) 237 gic_irqs = readl(base + GIC_DIST_CTR) & 0x1f;
239 max_irq = max(1020, NR_IRQS); 238 gic_irqs = (gic_irqs + 1) * 32;
239 if (gic_irqs > 1020)
240 gic_irqs = 1020;
240 241
241 /* 242 /*
242 * Set all global interrupts to be level triggered, active low. 243 * Set all global interrupts to be level triggered, active low.
243 */ 244 */
244 for (i = 32; i < max_irq; i += 16) 245 for (i = 32; i < gic_irqs; i += 16)
245 writel(0, base + GIC_DIST_CONFIG + i * 4 / 16); 246 writel(0, base + GIC_DIST_CONFIG + i * 4 / 16);
246 247
247 /* 248 /*
248 * Set all global interrupts to this CPU only. 249 * Set all global interrupts to this CPU only.
249 */ 250 */
250 for (i = 32; i < max_irq; i += 4) 251 for (i = 32; i < gic_irqs; i += 4)
251 writel(cpumask, base + GIC_DIST_TARGET + i * 4 / 4); 252 writel(cpumask, base + GIC_DIST_TARGET + i * 4 / 4);
252 253
253 /* 254 /*
254 * Set priority on all interrupts. 255 * Set priority on all global interrupts.
255 */ 256 */
256 for (i = 0; i < max_irq; i += 4) 257 for (i = 32; i < gic_irqs; i += 4)
257 writel(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4); 258 writel(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4);
258 259
259 /* 260 /*
260 * Disable all interrupts. 261 * Disable all interrupts. Leave the PPI and SGIs alone
262 * as these enables are banked registers.
261 */ 263 */
262 for (i = 0; i < max_irq; i += 32) 264 for (i = 32; i < gic_irqs; i += 32)
263 writel(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32); 265 writel(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32);
264 266
265 /* 267 /*
268 * Limit number of interrupts registered to the platform maximum
269 */
270 irq_limit = gic_data[gic_nr].irq_offset + gic_irqs;
271 if (WARN_ON(irq_limit > NR_IRQS))
272 irq_limit = NR_IRQS;
273
274 /*
266 * Setup the Linux IRQ subsystem. 275 * Setup the Linux IRQ subsystem.
267 */ 276 */
268 for (i = irq_start; i < gic_data[gic_nr].irq_offset + max_irq; i++) { 277 for (i = irq_start; i < irq_limit; i++) {
269 set_irq_chip(i, &gic_chip); 278 set_irq_chip(i, &gic_chip);
270 set_irq_chip_data(i, &gic_data[gic_nr]); 279 set_irq_chip_data(i, &gic_data[gic_nr]);
271 set_irq_handler(i, handle_level_irq); 280 set_irq_handler(i, handle_level_irq);
@@ -277,11 +286,30 @@ void __init gic_dist_init(unsigned int gic_nr, void __iomem *base,
277 286
278void __cpuinit gic_cpu_init(unsigned int gic_nr, void __iomem *base) 287void __cpuinit gic_cpu_init(unsigned int gic_nr, void __iomem *base)
279{ 288{
289 void __iomem *dist_base;
290 int i;
291
280 if (gic_nr >= MAX_GIC_NR) 292 if (gic_nr >= MAX_GIC_NR)
281 BUG(); 293 BUG();
282 294
295 dist_base = gic_data[gic_nr].dist_base;
296 BUG_ON(!dist_base);
297
283 gic_data[gic_nr].cpu_base = base; 298 gic_data[gic_nr].cpu_base = base;
284 299
300 /*
301 * Deal with the banked PPI and SGI interrupts - disable all
302 * PPI interrupts, ensure all SGI interrupts are enabled.
303 */
304 writel(0xffff0000, dist_base + GIC_DIST_ENABLE_CLEAR);
305 writel(0x0000ffff, dist_base + GIC_DIST_ENABLE_SET);
306
307 /*
308 * Set priority on PPI and SGI interrupts
309 */
310 for (i = 0; i < 32; i += 4)
311 writel(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4 / 4);
312
285 writel(0xf0, base + GIC_CPU_PRIMASK); 313 writel(0xf0, base + GIC_CPU_PRIMASK);
286 writel(1, base + GIC_CPU_CTRL); 314 writel(1, base + GIC_CPU_CTRL);
287} 315}
diff --git a/arch/arm/configs/at91rm9200_defconfig b/arch/arm/configs/at91rm9200_defconfig
new file mode 100644
index 000000000000..38cb7c985426
--- /dev/null
+++ b/arch/arm/configs/at91rm9200_defconfig
@@ -0,0 +1,341 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_LOCALVERSION_AUTO is not set
3# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y
5CONFIG_IKCONFIG=y
6CONFIG_IKCONFIG_PROC=y
7CONFIG_LOG_BUF_SHIFT=14
8CONFIG_SYSFS_DEPRECATED_V2=y
9CONFIG_BLK_DEV_INITRD=y
10CONFIG_MODULES=y
11CONFIG_MODULE_FORCE_LOAD=y
12CONFIG_MODULE_UNLOAD=y
13CONFIG_MODVERSIONS=y
14CONFIG_MODULE_SRCVERSION_ALL=y
15# CONFIG_BLK_DEV_BSG is not set
16# CONFIG_IOSCHED_CFQ is not set
17CONFIG_ARCH_AT91=y
18CONFIG_MACH_ONEARM=y
19CONFIG_ARCH_AT91RM9200DK=y
20CONFIG_MACH_AT91RM9200EK=y
21CONFIG_MACH_CSB337=y
22CONFIG_MACH_CSB637=y
23CONFIG_MACH_CARMEVA=y
24CONFIG_MACH_ATEB9200=y
25CONFIG_MACH_KB9200=y
26CONFIG_MACH_PICOTUX2XX=y
27CONFIG_MACH_KAFA=y
28CONFIG_MACH_ECBAT91=y
29CONFIG_MACH_YL9200=y
30CONFIG_MACH_CPUAT91=y
31CONFIG_MACH_ECO920=y
32CONFIG_MTD_AT91_DATAFLASH_CARD=y
33CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
34CONFIG_AT91_TIMER_HZ=100
35# CONFIG_ARM_THUMB is not set
36CONFIG_PCCARD=y
37CONFIG_AT91_CF=y
38CONFIG_NO_HZ=y
39CONFIG_HIGH_RES_TIMERS=y
40CONFIG_PREEMPT=y
41CONFIG_AEABI=y
42CONFIG_LEDS=y
43CONFIG_LEDS_CPU=y
44CONFIG_ZBOOT_ROM_TEXT=0x10000000
45CONFIG_ZBOOT_ROM_BSS=0x20040000
46CONFIG_KEXEC=y
47CONFIG_FPE_NWFPE=y
48CONFIG_BINFMT_MISC=y
49CONFIG_NET=y
50CONFIG_PACKET=y
51CONFIG_UNIX=y
52CONFIG_XFRM_USER=m
53CONFIG_INET=y
54CONFIG_IP_MULTICAST=y
55CONFIG_IP_PNP=y
56CONFIG_IP_PNP_DHCP=y
57CONFIG_IP_PNP_BOOTP=y
58CONFIG_NET_IPIP=m
59CONFIG_NET_IPGRE=m
60CONFIG_INET_AH=m
61CONFIG_INET_ESP=m
62CONFIG_INET_IPCOMP=m
63CONFIG_INET_XFRM_MODE_TRANSPORT=m
64CONFIG_INET_XFRM_MODE_TUNNEL=m
65CONFIG_INET_XFRM_MODE_BEET=m
66CONFIG_IPV6_PRIVACY=y
67CONFIG_IPV6_ROUTER_PREF=y
68CONFIG_IPV6_ROUTE_INFO=y
69CONFIG_INET6_AH=m
70CONFIG_INET6_ESP=m
71CONFIG_INET6_IPCOMP=m
72CONFIG_IPV6_MIP6=m
73CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
74CONFIG_IPV6_TUNNEL=m
75CONFIG_BRIDGE=m
76CONFIG_VLAN_8021Q=m
77CONFIG_BT=m
78CONFIG_BT_L2CAP=m
79CONFIG_BT_SCO=m
80CONFIG_BT_RFCOMM=m
81CONFIG_BT_RFCOMM_TTY=y
82CONFIG_BT_BNEP=m
83CONFIG_BT_BNEP_MC_FILTER=y
84CONFIG_BT_BNEP_PROTO_FILTER=y
85CONFIG_BT_HIDP=m
86CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
87CONFIG_MTD=y
88CONFIG_MTD_CONCAT=y
89CONFIG_MTD_PARTITIONS=y
90CONFIG_MTD_CMDLINE_PARTS=y
91CONFIG_MTD_AFS_PARTS=y
92CONFIG_MTD_CHAR=y
93CONFIG_MTD_BLOCK=y
94CONFIG_MTD_CFI=y
95CONFIG_MTD_JEDECPROBE=y
96CONFIG_MTD_CFI_INTELEXT=y
97CONFIG_MTD_CFI_AMDSTD=y
98CONFIG_MTD_COMPLEX_MAPPINGS=y
99CONFIG_MTD_PHYSMAP=y
100CONFIG_MTD_PLATRAM=y
101CONFIG_MTD_DATAFLASH=y
102CONFIG_MTD_NAND=y
103CONFIG_MTD_NAND_ATMEL=y
104CONFIG_MTD_NAND_PLATFORM=y
105CONFIG_MTD_UBI=y
106CONFIG_MTD_UBI_GLUEBI=y
107CONFIG_BLK_DEV_LOOP=y
108CONFIG_BLK_DEV_NBD=y
109CONFIG_BLK_DEV_RAM=y
110CONFIG_BLK_DEV_RAM_SIZE=8192
111CONFIG_ATMEL_TCLIB=y
112CONFIG_EEPROM_LEGACY=m
113CONFIG_SCSI=y
114CONFIG_BLK_DEV_SD=y
115CONFIG_BLK_DEV_SR=m
116CONFIG_BLK_DEV_SR_VENDOR=y
117CONFIG_CHR_DEV_SG=m
118CONFIG_SCSI_MULTI_LUN=y
119# CONFIG_SCSI_LOWLEVEL is not set
120CONFIG_NETDEVICES=y
121CONFIG_TUN=m
122CONFIG_PHYLIB=y
123CONFIG_DAVICOM_PHY=y
124CONFIG_SMSC_PHY=y
125CONFIG_MICREL_PHY=y
126CONFIG_NET_ETHERNET=y
127CONFIG_ARM_AT91_ETHER=y
128# CONFIG_NETDEV_1000 is not set
129# CONFIG_NETDEV_10000 is not set
130CONFIG_USB_CATC=m
131CONFIG_USB_KAWETH=m
132CONFIG_USB_PEGASUS=m
133CONFIG_USB_RTL8150=m
134CONFIG_USB_USBNET=m
135CONFIG_USB_NET_DM9601=m
136CONFIG_USB_NET_GL620A=m
137CONFIG_USB_NET_PLUSB=m
138CONFIG_USB_NET_RNDIS_HOST=m
139CONFIG_USB_ALI_M5632=y
140CONFIG_USB_AN2720=y
141CONFIG_USB_EPSON2888=y
142CONFIG_PPP=y
143CONFIG_PPP_MULTILINK=y
144CONFIG_PPP_FILTER=y
145CONFIG_PPP_ASYNC=y
146CONFIG_PPP_DEFLATE=y
147CONFIG_PPP_BSDCOMP=y
148CONFIG_PPP_MPPE=m
149CONFIG_PPPOE=m
150CONFIG_SLIP=m
151CONFIG_SLIP_COMPRESSED=y
152CONFIG_SLIP_SMART=y
153CONFIG_SLIP_MODE_SLIP6=y
154# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
155CONFIG_INPUT_MOUSEDEV_SCREEN_X=640
156CONFIG_INPUT_MOUSEDEV_SCREEN_Y=480
157CONFIG_INPUT_EVDEV=y
158CONFIG_KEYBOARD_GPIO=y
159# CONFIG_INPUT_MOUSE is not set
160CONFIG_INPUT_TOUCHSCREEN=y
161CONFIG_SERIAL_ATMEL=y
162CONFIG_SERIAL_ATMEL_CONSOLE=y
163CONFIG_LEGACY_PTY_COUNT=32
164CONFIG_HW_RANDOM=y
165CONFIG_I2C=y
166CONFIG_I2C_CHARDEV=y
167CONFIG_I2C_GPIO=y
168CONFIG_SPI=y
169CONFIG_SPI_ATMEL=y
170CONFIG_SPI_BITBANG=y
171CONFIG_GPIO_SYSFS=y
172CONFIG_HWMON=m
173CONFIG_SENSORS_ADM1021=m
174CONFIG_SENSORS_ADM1025=m
175CONFIG_SENSORS_ADM1026=m
176CONFIG_SENSORS_ADM1029=m
177CONFIG_SENSORS_ADM1031=m
178CONFIG_SENSORS_ADM9240=m
179CONFIG_SENSORS_DS1621=m
180CONFIG_SENSORS_GL518SM=m
181CONFIG_SENSORS_GL520SM=m
182CONFIG_SENSORS_IT87=m
183CONFIG_SENSORS_LM63=m
184CONFIG_SENSORS_LM73=m
185CONFIG_SENSORS_LM75=m
186CONFIG_SENSORS_LM77=m
187CONFIG_SENSORS_LM78=m
188CONFIG_SENSORS_LM80=m
189CONFIG_SENSORS_LM83=m
190CONFIG_SENSORS_LM85=m
191CONFIG_SENSORS_LM87=m
192CONFIG_SENSORS_LM90=m
193CONFIG_SENSORS_LM92=m
194CONFIG_SENSORS_MAX1619=m
195CONFIG_SENSORS_PCF8591=m
196CONFIG_SENSORS_SMSC47B397=m
197CONFIG_SENSORS_W83781D=m
198CONFIG_SENSORS_W83791D=m
199CONFIG_SENSORS_W83792D=m
200CONFIG_SENSORS_W83793=m
201CONFIG_SENSORS_W83L785TS=m
202CONFIG_WATCHDOG=y
203CONFIG_WATCHDOG_NOWAYOUT=y
204CONFIG_AT91RM9200_WATCHDOG=y
205CONFIG_FB=y
206CONFIG_FB_MODE_HELPERS=y
207CONFIG_FB_TILEBLITTING=y
208CONFIG_FB_S1D13XXX=y
209CONFIG_BACKLIGHT_LCD_SUPPORT=y
210CONFIG_LCD_CLASS_DEVICE=y
211CONFIG_BACKLIGHT_CLASS_DEVICE=y
212# CONFIG_BACKLIGHT_GENERIC is not set
213CONFIG_DISPLAY_SUPPORT=y
214CONFIG_FRAMEBUFFER_CONSOLE=y
215CONFIG_FONTS=y
216CONFIG_FONT_MINI_4x6=y
217CONFIG_LOGO=y
218# CONFIG_LOGO_LINUX_MONO is not set
219# CONFIG_LOGO_LINUX_VGA16 is not set
220CONFIG_USB=y
221CONFIG_USB_DEVICEFS=y
222# CONFIG_USB_DEVICE_CLASS is not set
223CONFIG_USB_MON=y
224CONFIG_USB_OHCI_HCD=y
225CONFIG_USB_ACM=m
226CONFIG_USB_PRINTER=m
227CONFIG_USB_STORAGE=y
228CONFIG_USB_SERIAL=y
229CONFIG_USB_SERIAL_CONSOLE=y
230CONFIG_USB_SERIAL_GENERIC=y
231CONFIG_USB_SERIAL_FTDI_SIO=y
232CONFIG_USB_SERIAL_KEYSPAN=y
233CONFIG_USB_SERIAL_KEYSPAN_MPR=y
234CONFIG_USB_SERIAL_KEYSPAN_USA28=y
235CONFIG_USB_SERIAL_KEYSPAN_USA28X=y
236CONFIG_USB_SERIAL_KEYSPAN_USA28XA=y
237CONFIG_USB_SERIAL_KEYSPAN_USA28XB=y
238CONFIG_USB_SERIAL_KEYSPAN_USA19=y
239CONFIG_USB_SERIAL_KEYSPAN_USA18X=y
240CONFIG_USB_SERIAL_KEYSPAN_USA19W=y
241CONFIG_USB_SERIAL_KEYSPAN_USA19QW=y
242CONFIG_USB_SERIAL_KEYSPAN_USA19QI=y
243CONFIG_USB_SERIAL_KEYSPAN_USA49W=y
244CONFIG_USB_SERIAL_KEYSPAN_USA49WLC=y
245CONFIG_USB_SERIAL_MCT_U232=y
246CONFIG_USB_SERIAL_PL2303=y
247CONFIG_USB_GADGET=y
248CONFIG_USB_ETH=m
249CONFIG_USB_MASS_STORAGE=m
250CONFIG_MMC=y
251CONFIG_MMC_AT91=y
252CONFIG_NEW_LEDS=y
253CONFIG_LEDS_CLASS=y
254CONFIG_LEDS_GPIO=y
255CONFIG_LEDS_TRIGGERS=y
256CONFIG_LEDS_TRIGGER_TIMER=y
257CONFIG_LEDS_TRIGGER_HEARTBEAT=y
258CONFIG_LEDS_TRIGGER_GPIO=y
259CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
260CONFIG_RTC_CLASS=y
261# CONFIG_RTC_HCTOSYS is not set
262CONFIG_RTC_DRV_DS1307=y
263CONFIG_RTC_DRV_PCF8563=y
264CONFIG_RTC_DRV_AT91RM9200=y
265CONFIG_EXT2_FS=y
266CONFIG_EXT2_FS_XATTR=y
267CONFIG_EXT3_FS=y
268# CONFIG_EXT3_FS_XATTR is not set
269CONFIG_REISERFS_FS=y
270CONFIG_AUTOFS4_FS=y
271CONFIG_ISO9660_FS=y
272CONFIG_JOLIET=y
273CONFIG_ZISOFS=y
274CONFIG_UDF_FS=y
275CONFIG_MSDOS_FS=y
276CONFIG_VFAT_FS=y
277CONFIG_NTFS_FS=m
278CONFIG_TMPFS=y
279CONFIG_CONFIGFS_FS=y
280CONFIG_JFFS2_FS=y
281CONFIG_JFFS2_SUMMARY=y
282CONFIG_JFFS2_COMPRESSION_OPTIONS=y
283CONFIG_JFFS2_LZO=y
284CONFIG_JFFS2_RUBIN=y
285CONFIG_CRAMFS=y
286CONFIG_MINIX_FS=y
287CONFIG_NFS_FS=y
288CONFIG_NFS_V3=y
289CONFIG_NFS_V3_ACL=y
290CONFIG_NFS_V4=y
291CONFIG_ROOT_NFS=y
292CONFIG_NFSD=y
293CONFIG_SMB_FS=m
294CONFIG_CIFS=m
295CONFIG_PARTITION_ADVANCED=y
296CONFIG_MAC_PARTITION=y
297CONFIG_NLS_CODEPAGE_437=y
298CONFIG_NLS_CODEPAGE_737=m
299CONFIG_NLS_CODEPAGE_775=m
300CONFIG_NLS_CODEPAGE_850=m
301CONFIG_NLS_CODEPAGE_852=m
302CONFIG_NLS_CODEPAGE_855=m
303CONFIG_NLS_CODEPAGE_857=m
304CONFIG_NLS_CODEPAGE_860=m
305CONFIG_NLS_CODEPAGE_861=m
306CONFIG_NLS_CODEPAGE_862=m
307CONFIG_NLS_CODEPAGE_863=m
308CONFIG_NLS_CODEPAGE_864=m
309CONFIG_NLS_CODEPAGE_865=m
310CONFIG_NLS_CODEPAGE_866=m
311CONFIG_NLS_CODEPAGE_869=m
312CONFIG_NLS_CODEPAGE_936=m
313CONFIG_NLS_CODEPAGE_950=m
314CONFIG_NLS_CODEPAGE_932=m
315CONFIG_NLS_CODEPAGE_949=m
316CONFIG_NLS_CODEPAGE_874=m
317CONFIG_NLS_ISO8859_8=m
318CONFIG_NLS_CODEPAGE_1250=m
319CONFIG_NLS_CODEPAGE_1251=m
320CONFIG_NLS_ASCII=m
321CONFIG_NLS_ISO8859_1=y
322CONFIG_NLS_ISO8859_2=m
323CONFIG_NLS_ISO8859_3=m
324CONFIG_NLS_ISO8859_4=m
325CONFIG_NLS_ISO8859_5=m
326CONFIG_NLS_ISO8859_6=m
327CONFIG_NLS_ISO8859_7=m
328CONFIG_NLS_ISO8859_9=m
329CONFIG_NLS_ISO8859_13=m
330CONFIG_NLS_ISO8859_14=m
331CONFIG_NLS_ISO8859_15=m
332CONFIG_NLS_KOI8_R=m
333CONFIG_NLS_KOI8_U=m
334CONFIG_NLS_UTF8=y
335CONFIG_MAGIC_SYSRQ=y
336CONFIG_DEBUG_FS=y
337CONFIG_DEBUG_KERNEL=y
338# CONFIG_RCU_CPU_STALL_DETECTOR is not set
339# CONFIG_FTRACE is not set
340CONFIG_CRYPTO_PCBC=y
341CONFIG_CRYPTO_SHA1=y
diff --git a/arch/arm/configs/at91rm9200dk_defconfig b/arch/arm/configs/at91rm9200dk_defconfig
deleted file mode 100644
index 4438e64f3bfb..000000000000
--- a/arch/arm/configs/at91rm9200dk_defconfig
+++ /dev/null
@@ -1,72 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_LOG_BUF_SHIFT=14
5CONFIG_BLK_DEV_INITRD=y
6CONFIG_MODULES=y
7CONFIG_MODULE_UNLOAD=y
8# CONFIG_IOSCHED_DEADLINE is not set
9# CONFIG_IOSCHED_CFQ is not set
10CONFIG_ARCH_AT91=y
11CONFIG_ARCH_AT91RM9200DK=y
12CONFIG_MACH_ECO920=y
13CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
14# CONFIG_ARM_THUMB is not set
15CONFIG_PCCARD=y
16CONFIG_AT91_CF=y
17CONFIG_LEDS=y
18CONFIG_ZBOOT_ROM_TEXT=0x0
19CONFIG_ZBOOT_ROM_BSS=0x0
20CONFIG_CMDLINE="mem=32M console=ttyS0,115200 initrd=0x20410000,3145728 root=/dev/ram0 rw"
21CONFIG_FPE_NWFPE=y
22CONFIG_NET=y
23CONFIG_PACKET=y
24CONFIG_UNIX=y
25CONFIG_INET=y
26CONFIG_IP_PNP=y
27CONFIG_IP_PNP_BOOTP=y
28# CONFIG_IPV6 is not set
29CONFIG_MTD=y
30CONFIG_MTD_PARTITIONS=y
31CONFIG_MTD_CMDLINE_PARTS=y
32CONFIG_MTD_CHAR=y
33CONFIG_MTD_BLOCK=y
34CONFIG_MTD_CFI=y
35CONFIG_MTD_JEDECPROBE=y
36CONFIG_MTD_CFI_AMDSTD=y
37CONFIG_MTD_PHYSMAP=y
38CONFIG_BLK_DEV_RAM=y
39CONFIG_BLK_DEV_RAM_SIZE=8192
40CONFIG_NETDEVICES=y
41CONFIG_NET_ETHERNET=y
42CONFIG_ARM_AT91_ETHER=y
43# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
44# CONFIG_INPUT_KEYBOARD is not set
45# CONFIG_INPUT_MOUSE is not set
46# CONFIG_SERIO is not set
47CONFIG_SERIAL_ATMEL=y
48CONFIG_SERIAL_ATMEL_CONSOLE=y
49CONFIG_I2C=y
50CONFIG_I2C_CHARDEV=y
51CONFIG_I2C_GPIO=y
52CONFIG_WATCHDOG=y
53CONFIG_WATCHDOG_NOWAYOUT=y
54CONFIG_AT91RM9200_WATCHDOG=y
55# CONFIG_VGA_CONSOLE is not set
56# CONFIG_USB_HID is not set
57CONFIG_USB=y
58CONFIG_USB_DEBUG=y
59CONFIG_USB_DEVICEFS=y
60CONFIG_USB_MON=y
61CONFIG_USB_OHCI_HCD=y
62CONFIG_USB_GADGET=y
63CONFIG_MMC=y
64CONFIG_RTC_CLASS=y
65CONFIG_RTC_DRV_AT91RM9200=y
66CONFIG_EXT2_FS=y
67CONFIG_INOTIFY=y
68CONFIG_TMPFS=y
69CONFIG_CRAMFS=y
70CONFIG_DEBUG_KERNEL=y
71CONFIG_DEBUG_USER=y
72CONFIG_DEBUG_LL=y
diff --git a/arch/arm/configs/at91rm9200ek_defconfig b/arch/arm/configs/at91rm9200ek_defconfig
deleted file mode 100644
index ccd517c64bc7..000000000000
--- a/arch/arm/configs/at91rm9200ek_defconfig
+++ /dev/null
@@ -1,73 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_LOCALVERSION_AUTO is not set
3# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y
5CONFIG_LOG_BUF_SHIFT=14
6CONFIG_BLK_DEV_INITRD=y
7CONFIG_MODULES=y
8CONFIG_MODULE_UNLOAD=y
9# CONFIG_IOSCHED_DEADLINE is not set
10# CONFIG_IOSCHED_CFQ is not set
11CONFIG_ARCH_AT91=y
12CONFIG_MACH_AT91RM9200EK=y
13CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
14# CONFIG_ARM_THUMB is not set
15CONFIG_LEDS=y
16CONFIG_LEDS_CPU=y
17CONFIG_ZBOOT_ROM_TEXT=0x0
18CONFIG_ZBOOT_ROM_BSS=0x0
19CONFIG_CMDLINE="mem=32M console=ttyS0,115200 initrd=0x20410000,3145728 root=/dev/ram0 rw"
20CONFIG_FPE_NWFPE=y
21CONFIG_NET=y
22CONFIG_PACKET=y
23CONFIG_UNIX=y
24CONFIG_INET=y
25CONFIG_IP_PNP=y
26CONFIG_IP_PNP_BOOTP=y
27# CONFIG_IPV6 is not set
28CONFIG_MTD=y
29CONFIG_MTD_PARTITIONS=y
30CONFIG_MTD_CMDLINE_PARTS=y
31CONFIG_MTD_CHAR=y
32CONFIG_MTD_BLOCK=y
33CONFIG_MTD_CFI=y
34CONFIG_MTD_JEDECPROBE=y
35CONFIG_MTD_CFI_AMDSTD=y
36CONFIG_MTD_PHYSMAP=y
37CONFIG_BLK_DEV_RAM=y
38CONFIG_BLK_DEV_RAM_SIZE=8192
39CONFIG_NETDEVICES=y
40CONFIG_NET_ETHERNET=y
41CONFIG_ARM_AT91_ETHER=y
42# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
43# CONFIG_INPUT_KEYBOARD is not set
44# CONFIG_INPUT_MOUSE is not set
45# CONFIG_SERIO is not set
46CONFIG_SERIAL_ATMEL=y
47CONFIG_SERIAL_ATMEL_CONSOLE=y
48CONFIG_I2C=y
49CONFIG_I2C_CHARDEV=y
50CONFIG_I2C_GPIO=y
51CONFIG_WATCHDOG=y
52CONFIG_WATCHDOG_NOWAYOUT=y
53CONFIG_AT91RM9200_WATCHDOG=y
54CONFIG_FB=y
55CONFIG_FB_S1D13XXX=y
56# CONFIG_VGA_CONSOLE is not set
57# CONFIG_USB_HID is not set
58CONFIG_USB=y
59CONFIG_USB_DEBUG=y
60CONFIG_USB_DEVICEFS=y
61CONFIG_USB_MON=y
62CONFIG_USB_OHCI_HCD=y
63CONFIG_USB_GADGET=y
64CONFIG_MMC=y
65CONFIG_RTC_CLASS=y
66CONFIG_RTC_DRV_AT91RM9200=y
67CONFIG_EXT2_FS=y
68CONFIG_INOTIFY=y
69CONFIG_TMPFS=y
70CONFIG_CRAMFS=y
71CONFIG_DEBUG_KERNEL=y
72CONFIG_DEBUG_USER=y
73CONFIG_DEBUG_LL=y
diff --git a/arch/arm/configs/ateb9200_defconfig b/arch/arm/configs/ateb9200_defconfig
deleted file mode 100644
index 1b0e9a1689bb..000000000000
--- a/arch/arm/configs/ateb9200_defconfig
+++ /dev/null
@@ -1,131 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_SYSVIPC=y
3CONFIG_LOG_BUF_SHIFT=14
4CONFIG_EMBEDDED=y
5CONFIG_SLAB=y
6CONFIG_PROFILING=y
7CONFIG_OPROFILE=m
8CONFIG_MODULES=y
9CONFIG_MODULE_UNLOAD=y
10CONFIG_ARCH_AT91=y
11CONFIG_MACH_ATEB9200=y
12CONFIG_PCCARD=m
13CONFIG_AT91_CF=m
14CONFIG_PREEMPT=y
15CONFIG_ZBOOT_ROM_TEXT=0x0
16CONFIG_ZBOOT_ROM_BSS=0x0
17CONFIG_FPE_NWFPE=y
18CONFIG_PM=y
19CONFIG_NET=y
20CONFIG_PACKET=y
21CONFIG_UNIX=y
22CONFIG_NET_KEY=y
23CONFIG_INET=y
24# CONFIG_IPV6 is not set
25CONFIG_BRIDGE=m
26CONFIG_VLAN_8021Q=m
27CONFIG_MTD=y
28CONFIG_MTD_PARTITIONS=y
29CONFIG_MTD_CMDLINE_PARTS=y
30CONFIG_MTD_CHAR=y
31CONFIG_MTD_BLOCK_RO=y
32CONFIG_BLK_DEV_LOOP=m
33CONFIG_BLK_DEV_NBD=m
34CONFIG_SCSI=m
35CONFIG_BLK_DEV_SD=m
36CONFIG_BLK_DEV_SR=m
37CONFIG_BLK_DEV_SR_VENDOR=y
38CONFIG_CHR_DEV_SG=m
39CONFIG_SCSI_MULTI_LUN=y
40CONFIG_NETDEVICES=y
41CONFIG_DUMMY=m
42CONFIG_TUN=m
43CONFIG_PHYLIB=y
44CONFIG_DAVICOM_PHY=y
45CONFIG_NET_ETHERNET=y
46CONFIG_ARM_AT91_ETHER=y
47CONFIG_USB_USBNET=y
48CONFIG_USB_NET_GL620A=y
49CONFIG_USB_NET_PLUSB=y
50CONFIG_USB_NET_RNDIS_HOST=y
51CONFIG_USB_ALI_M5632=y
52CONFIG_USB_AN2720=y
53CONFIG_USB_EPSON2888=y
54CONFIG_PPP=m
55CONFIG_PPP_ASYNC=m
56CONFIG_PPP_SYNC_TTY=m
57CONFIG_PPP_DEFLATE=m
58CONFIG_PPP_BSDCOMP=m
59CONFIG_PPPOE=m
60CONFIG_SERIAL_ATMEL=y
61CONFIG_SERIAL_ATMEL_CONSOLE=y
62CONFIG_I2C=m
63CONFIG_I2C_CHARDEV=m
64CONFIG_I2C_GPIO=m
65# CONFIG_VGA_CONSOLE is not set
66CONFIG_SOUND=y
67CONFIG_USB_HID=m
68CONFIG_HID_PID=y
69CONFIG_USB_HIDDEV=y
70CONFIG_USB=y
71CONFIG_USB_DEVICEFS=y
72CONFIG_USB_MON=y
73CONFIG_USB_OHCI_HCD=y
74CONFIG_USB_ACM=m
75CONFIG_USB_PRINTER=m
76CONFIG_USB_STORAGE=m
77CONFIG_USB_STORAGE_DATAFAB=m
78CONFIG_USB_STORAGE_FREECOM=m
79CONFIG_USB_STORAGE_USBAT=m
80CONFIG_USB_STORAGE_SDDR09=m
81CONFIG_USB_STORAGE_SDDR55=m
82CONFIG_USB_STORAGE_JUMPSHOT=m
83CONFIG_USB_SERIAL=m
84CONFIG_USB_SERIAL_GENERIC=y
85CONFIG_USB_SERIAL_FTDI_SIO=m
86CONFIG_USB_SERIAL_PL2303=m
87CONFIG_USB_GADGET=m
88CONFIG_USB_ETH=m
89CONFIG_USB_GADGETFS=m
90CONFIG_USB_FILE_STORAGE=m
91CONFIG_USB_G_SERIAL=m
92CONFIG_MMC=m
93CONFIG_MMC_DEBUG=y
94CONFIG_RTC_CLASS=y
95# CONFIG_RTC_HCTOSYS is not set
96CONFIG_RTC_DRV_AT91RM9200=y
97CONFIG_EXT2_FS=m
98CONFIG_EXT3_FS=m
99CONFIG_REISERFS_FS=m
100CONFIG_INOTIFY=y
101CONFIG_ISO9660_FS=m
102CONFIG_JOLIET=y
103CONFIG_ZISOFS=y
104CONFIG_UDF_FS=m
105CONFIG_MSDOS_FS=m
106CONFIG_VFAT_FS=m
107CONFIG_NTFS_FS=m
108CONFIG_NTFS_RW=y
109CONFIG_TMPFS=y
110CONFIG_CRAMFS=y
111CONFIG_NFS_FS=m
112CONFIG_NFS_V3=y
113CONFIG_NFS_V3_ACL=y
114CONFIG_NFS_V4=y
115CONFIG_NFSD=m
116CONFIG_NFSD_V4=y
117CONFIG_PARTITION_ADVANCED=y
118CONFIG_MAC_PARTITION=y
119CONFIG_BSD_DISKLABEL=y
120CONFIG_MINIX_SUBPARTITION=y
121CONFIG_SOLARIS_X86_PARTITION=y
122CONFIG_UNIXWARE_DISKLABEL=y
123CONFIG_NLS_CODEPAGE_932=m
124CONFIG_NLS_ASCII=m
125CONFIG_NLS_ISO8859_15=m
126CONFIG_NLS_UTF8=m
127CONFIG_CRYPTO_MD5=y
128CONFIG_CRYPTO_MICHAEL_MIC=m
129CONFIG_CRYPTO_ARC4=m
130CONFIG_CRC16=m
131CONFIG_LIBCRC32C=m
diff --git a/arch/arm/configs/carmeva_defconfig b/arch/arm/configs/carmeva_defconfig
deleted file mode 100644
index ac64dbd8a49c..000000000000
--- a/arch/arm/configs/carmeva_defconfig
+++ /dev/null
@@ -1,47 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_LOG_BUF_SHIFT=14
3CONFIG_BLK_DEV_INITRD=y
4CONFIG_EMBEDDED=y
5# CONFIG_HOTPLUG is not set
6CONFIG_MODULES=y
7CONFIG_MODULE_UNLOAD=y
8CONFIG_MODULE_FORCE_UNLOAD=y
9CONFIG_ARCH_AT91=y
10CONFIG_MACH_CARMEVA=y
11CONFIG_ZBOOT_ROM_TEXT=0x0
12CONFIG_ZBOOT_ROM_BSS=0x0
13CONFIG_FPE_NWFPE=y
14CONFIG_NET=y
15CONFIG_UNIX=y
16CONFIG_INET=y
17CONFIG_IP_MULTICAST=y
18CONFIG_IP_PNP=y
19# CONFIG_IPV6 is not set
20CONFIG_MTD=y
21CONFIG_MTD_PARTITIONS=y
22CONFIG_MTD_CMDLINE_PARTS=y
23CONFIG_MTD_CHAR=y
24CONFIG_MTD_BLOCK=y
25CONFIG_BLK_DEV_RAM=y
26CONFIG_NETDEVICES=y
27CONFIG_NET_ETHERNET=y
28CONFIG_ARM_AT91_ETHER=y
29# CONFIG_INPUT_MOUSEDEV is not set
30# CONFIG_INPUT_KEYBOARD is not set
31# CONFIG_INPUT_MOUSE is not set
32CONFIG_SERIO=m
33CONFIG_SERIAL_ATMEL=y
34CONFIG_SERIAL_ATMEL_CONSOLE=y
35# CONFIG_VGA_CONSOLE is not set
36CONFIG_MMC=m
37CONFIG_MMC_DEBUG=y
38CONFIG_EXT2_FS=y
39CONFIG_EXT2_FS_XATTR=y
40# CONFIG_DNOTIFY is not set
41CONFIG_JFFS2_FS=y
42CONFIG_JFFS2_COMPRESSION_OPTIONS=y
43CONFIG_NFS_FS=y
44CONFIG_NFS_V3=y
45CONFIG_NFS_V4=y
46CONFIG_ROOT_NFS=y
47CONFIG_NFSD=y
diff --git a/arch/arm/configs/cpuat91_defconfig b/arch/arm/configs/cpuat91_defconfig
deleted file mode 100644
index 022aeb55b676..000000000000
--- a/arch/arm/configs/cpuat91_defconfig
+++ /dev/null
@@ -1,112 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_LOCALVERSION_AUTO is not set
3# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y
5CONFIG_LOG_BUF_SHIFT=14
6CONFIG_SYSFS_DEPRECATED_V2=y
7CONFIG_MODULES=y
8CONFIG_MODULE_UNLOAD=y
9# CONFIG_BLK_DEV_BSG is not set
10# CONFIG_IOSCHED_CFQ is not set
11CONFIG_ARCH_AT91=y
12CONFIG_MACH_CPUAT91=y
13CONFIG_AT91_TIMER_HZ=100
14# CONFIG_ARM_THUMB is not set
15CONFIG_PREEMPT=y
16CONFIG_ZBOOT_ROM_TEXT=0x0
17CONFIG_ZBOOT_ROM_BSS=0x0
18CONFIG_NET=y
19CONFIG_PACKET=y
20CONFIG_UNIX=y
21CONFIG_INET=y
22CONFIG_IP_PNP=y
23# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
24# CONFIG_INET_XFRM_MODE_TUNNEL is not set
25# CONFIG_INET_XFRM_MODE_BEET is not set
26# CONFIG_IPV6 is not set
27CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
28CONFIG_MTD=y
29CONFIG_MTD_PARTITIONS=y
30CONFIG_MTD_CMDLINE_PARTS=y
31CONFIG_MTD_CHAR=y
32CONFIG_MTD_BLOCK=y
33CONFIG_MTD_CFI=y
34CONFIG_MTD_CFI_INTELEXT=y
35CONFIG_MTD_PHYSMAP=y
36CONFIG_MTD_PLATRAM=y
37CONFIG_BLK_DEV_LOOP=y
38CONFIG_BLK_DEV_NBD=y
39CONFIG_BLK_DEV_RAM=y
40# CONFIG_MISC_DEVICES is not set
41CONFIG_SCSI=y
42CONFIG_BLK_DEV_SD=y
43CONFIG_SCSI_MULTI_LUN=y
44# CONFIG_SCSI_LOWLEVEL is not set
45CONFIG_NETDEVICES=y
46CONFIG_PHYLIB=y
47CONFIG_NET_ETHERNET=y
48CONFIG_ARM_AT91_ETHER=y
49# CONFIG_NETDEV_1000 is not set
50# CONFIG_NETDEV_10000 is not set
51CONFIG_PPP=y
52CONFIG_PPP_ASYNC=y
53CONFIG_PPP_DEFLATE=y
54CONFIG_PPP_BSDCOMP=y
55# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
56# CONFIG_INPUT_KEYBOARD is not set
57# CONFIG_INPUT_MOUSE is not set
58# CONFIG_SERIO is not set
59CONFIG_SERIAL_ATMEL=y
60CONFIG_SERIAL_ATMEL_CONSOLE=y
61CONFIG_LEGACY_PTY_COUNT=32
62# CONFIG_HW_RANDOM is not set
63CONFIG_I2C=y
64CONFIG_I2C_CHARDEV=y
65CONFIG_I2C_GPIO=y
66CONFIG_GPIO_SYSFS=y
67# CONFIG_HWMON is not set
68CONFIG_WATCHDOG=y
69CONFIG_WATCHDOG_NOWAYOUT=y
70CONFIG_AT91RM9200_WATCHDOG=y
71# CONFIG_VGA_CONSOLE is not set
72# CONFIG_HID_SUPPORT is not set
73CONFIG_USB=y
74# CONFIG_USB_DEVICE_CLASS is not set
75CONFIG_USB_OHCI_HCD=y
76CONFIG_USB_STORAGE=y
77CONFIG_USB_GADGET=y
78CONFIG_USB_ETH=m
79CONFIG_MMC=y
80CONFIG_MMC_AT91=m
81CONFIG_NEW_LEDS=y
82CONFIG_LEDS_CLASS=y
83CONFIG_LEDS_GPIO=y
84CONFIG_LEDS_TRIGGERS=y
85CONFIG_LEDS_TRIGGER_TIMER=y
86CONFIG_LEDS_TRIGGER_HEARTBEAT=y
87CONFIG_LEDS_TRIGGER_GPIO=y
88CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
89CONFIG_RTC_CLASS=y
90# CONFIG_RTC_HCTOSYS is not set
91CONFIG_RTC_DRV_DS1307=y
92CONFIG_RTC_DRV_PCF8563=y
93CONFIG_EXT2_FS=y
94CONFIG_EXT3_FS=y
95# CONFIG_EXT3_FS_XATTR is not set
96CONFIG_INOTIFY=y
97CONFIG_AUTOFS4_FS=y
98CONFIG_MSDOS_FS=y
99CONFIG_VFAT_FS=y
100CONFIG_TMPFS=y
101CONFIG_JFFS2_FS=y
102CONFIG_JFFS2_SUMMARY=y
103CONFIG_CRAMFS=y
104CONFIG_MINIX_FS=y
105CONFIG_NFS_FS=y
106CONFIG_NFS_V3=y
107CONFIG_ROOT_NFS=y
108CONFIG_PARTITION_ADVANCED=y
109CONFIG_NLS_CODEPAGE_437=y
110CONFIG_NLS_ISO8859_1=y
111CONFIG_NLS_UTF8=y
112# CONFIG_RCU_CPU_STALL_DETECTOR is not set
diff --git a/arch/arm/configs/csb337_defconfig b/arch/arm/configs/csb337_defconfig
deleted file mode 100644
index a24c448840c4..000000000000
--- a/arch/arm/configs/csb337_defconfig
+++ /dev/null
@@ -1,104 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_LOG_BUF_SHIFT=14
5CONFIG_BLK_DEV_INITRD=y
6CONFIG_MODULES=y
7CONFIG_MODULE_UNLOAD=y
8# CONFIG_BLK_DEV_BSG is not set
9CONFIG_ARCH_AT91=y
10CONFIG_MACH_CSB337=y
11CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
12# CONFIG_ARM_THUMB is not set
13CONFIG_PCCARD=y
14CONFIG_AT91_CF=y
15CONFIG_LEDS=y
16CONFIG_LEDS_CPU=y
17CONFIG_ZBOOT_ROM_TEXT=0x0
18CONFIG_ZBOOT_ROM_BSS=0x0
19CONFIG_CMDLINE="mem=32M console=ttyS0,38400 initrd=0x20410000,3145728 root=/dev/ram0 rw"
20CONFIG_FPE_NWFPE=y
21CONFIG_NET=y
22CONFIG_PACKET=y
23CONFIG_UNIX=y
24CONFIG_INET=y
25CONFIG_IP_PNP=y
26CONFIG_IP_PNP_DHCP=y
27CONFIG_IP_PNP_BOOTP=y
28# CONFIG_INET_LRO is not set
29# CONFIG_IPV6 is not set
30CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
31CONFIG_MTD=y
32CONFIG_MTD_PARTITIONS=y
33CONFIG_MTD_CMDLINE_PARTS=y
34CONFIG_MTD_CHAR=y
35CONFIG_MTD_BLOCK=y
36CONFIG_MTD_CFI=y
37CONFIG_MTD_CFI_INTELEXT=y
38CONFIG_MTD_PHYSMAP=y
39CONFIG_BLK_DEV_LOOP=y
40CONFIG_BLK_DEV_RAM=y
41CONFIG_BLK_DEV_RAM_SIZE=8192
42CONFIG_ATMEL_SSC=y
43CONFIG_SCSI=y
44CONFIG_NETDEVICES=y
45CONFIG_NET_ETHERNET=y
46CONFIG_ARM_AT91_ETHER=y
47# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
48# CONFIG_INPUT_KEYBOARD is not set
49# CONFIG_INPUT_MOUSE is not set
50# CONFIG_SERIO is not set
51CONFIG_SERIAL_ATMEL=y
52CONFIG_SERIAL_ATMEL_CONSOLE=y
53# CONFIG_HW_RANDOM is not set
54CONFIG_I2C=y
55CONFIG_I2C_CHARDEV=y
56CONFIG_I2C_GPIO=y
57# CONFIG_HWMON is not set
58CONFIG_WATCHDOG=y
59CONFIG_WATCHDOG_NOWAYOUT=y
60CONFIG_AT91RM9200_WATCHDOG=y
61# CONFIG_VGA_CONSOLE is not set
62# CONFIG_USB_HID is not set
63CONFIG_USB=y
64CONFIG_USB_DEBUG=y
65CONFIG_USB_DEVICEFS=y
66CONFIG_USB_MON=y
67CONFIG_USB_OHCI_HCD=y
68CONFIG_USB_STORAGE=y
69CONFIG_USB_SERIAL=y
70CONFIG_USB_SERIAL_CONSOLE=y
71CONFIG_USB_SERIAL_GENERIC=y
72CONFIG_USB_SERIAL_FTDI_SIO=y
73CONFIG_USB_SERIAL_KEYSPAN=y
74CONFIG_USB_SERIAL_KEYSPAN_MPR=y
75CONFIG_USB_SERIAL_KEYSPAN_USA28=y
76CONFIG_USB_SERIAL_KEYSPAN_USA28X=y
77CONFIG_USB_SERIAL_KEYSPAN_USA28XA=y
78CONFIG_USB_SERIAL_KEYSPAN_USA28XB=y
79CONFIG_USB_SERIAL_KEYSPAN_USA19=y
80CONFIG_USB_SERIAL_KEYSPAN_USA18X=y
81CONFIG_USB_SERIAL_KEYSPAN_USA19W=y
82CONFIG_USB_SERIAL_KEYSPAN_USA19QW=y
83CONFIG_USB_SERIAL_KEYSPAN_USA19QI=y
84CONFIG_USB_SERIAL_KEYSPAN_USA49W=y
85CONFIG_USB_SERIAL_KEYSPAN_USA49WLC=y
86CONFIG_USB_SERIAL_MCT_U232=y
87CONFIG_USB_GADGET=y
88CONFIG_MMC=y
89CONFIG_RTC_CLASS=y
90CONFIG_RTC_HCTOSYS_DEVICE="rtc1"
91# CONFIG_RTC_INTF_SYSFS is not set
92CONFIG_RTC_DRV_DS1307=y
93CONFIG_RTC_DRV_AT91RM9200=y
94CONFIG_EXT2_FS=y
95CONFIG_INOTIFY=y
96CONFIG_TMPFS=y
97CONFIG_CRAMFS=y
98CONFIG_NFS_FS=y
99CONFIG_NFS_V3=y
100CONFIG_NFS_V4=y
101CONFIG_ROOT_NFS=y
102CONFIG_DEBUG_KERNEL=y
103CONFIG_DEBUG_USER=y
104CONFIG_DEBUG_LL=y
diff --git a/arch/arm/configs/csb637_defconfig b/arch/arm/configs/csb637_defconfig
deleted file mode 100644
index 98552adac5fb..000000000000
--- a/arch/arm/configs/csb637_defconfig
+++ /dev/null
@@ -1,98 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_LOG_BUF_SHIFT=14
5CONFIG_SYSFS_DEPRECATED_V2=y
6CONFIG_BLK_DEV_INITRD=y
7CONFIG_MODULES=y
8CONFIG_MODULE_UNLOAD=y
9# CONFIG_BLK_DEV_BSG is not set
10CONFIG_ARCH_AT91=y
11CONFIG_MACH_CSB637=y
12CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
13# CONFIG_ARM_THUMB is not set
14CONFIG_PCCARD=y
15CONFIG_AT91_CF=y
16CONFIG_LEDS=y
17CONFIG_LEDS_CPU=y
18CONFIG_ZBOOT_ROM_TEXT=0x0
19CONFIG_ZBOOT_ROM_BSS=0x0
20CONFIG_CMDLINE="mem=32M console=ttyS0,38400 initrd=0x20410000,3145728 root=/dev/ram0 rw"
21CONFIG_FPE_NWFPE=y
22CONFIG_NET=y
23CONFIG_PACKET=y
24CONFIG_UNIX=y
25CONFIG_INET=y
26CONFIG_IP_PNP=y
27CONFIG_IP_PNP_DHCP=y
28CONFIG_IP_PNP_BOOTP=y
29# CONFIG_INET_LRO is not set
30# CONFIG_IPV6 is not set
31CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
32CONFIG_MTD=y
33CONFIG_MTD_PARTITIONS=y
34CONFIG_MTD_CMDLINE_PARTS=y
35CONFIG_MTD_CHAR=y
36CONFIG_MTD_BLOCK=y
37CONFIG_MTD_CFI=y
38CONFIG_MTD_CFI_INTELEXT=y
39CONFIG_MTD_PHYSMAP=y
40CONFIG_BLK_DEV_LOOP=y
41CONFIG_BLK_DEV_RAM=y
42CONFIG_BLK_DEV_RAM_SIZE=8192
43CONFIG_SCSI=y
44CONFIG_NETDEVICES=y
45CONFIG_NET_ETHERNET=y
46CONFIG_ARM_AT91_ETHER=y
47# CONFIG_INPUT_KEYBOARD is not set
48# CONFIG_INPUT_MOUSE is not set
49# CONFIG_SERIO is not set
50CONFIG_SERIAL_ATMEL=y
51CONFIG_SERIAL_ATMEL_CONSOLE=y
52CONFIG_I2C=y
53CONFIG_I2C_CHARDEV=y
54CONFIG_WATCHDOG=y
55CONFIG_WATCHDOG_NOWAYOUT=y
56CONFIG_AT91RM9200_WATCHDOG=y
57# CONFIG_VGA_CONSOLE is not set
58# CONFIG_USB_HID is not set
59CONFIG_USB=y
60CONFIG_USB_DEBUG=y
61CONFIG_USB_DEVICEFS=y
62CONFIG_USB_MON=y
63CONFIG_USB_OHCI_HCD=y
64CONFIG_USB_STORAGE=y
65CONFIG_USB_SERIAL=y
66CONFIG_USB_SERIAL_CONSOLE=y
67CONFIG_USB_SERIAL_GENERIC=y
68CONFIG_USB_SERIAL_FTDI_SIO=y
69CONFIG_USB_SERIAL_KEYSPAN=y
70CONFIG_USB_SERIAL_KEYSPAN_MPR=y
71CONFIG_USB_SERIAL_KEYSPAN_USA28=y
72CONFIG_USB_SERIAL_KEYSPAN_USA28X=y
73CONFIG_USB_SERIAL_KEYSPAN_USA28XA=y
74CONFIG_USB_SERIAL_KEYSPAN_USA28XB=y
75CONFIG_USB_SERIAL_KEYSPAN_USA19=y
76CONFIG_USB_SERIAL_KEYSPAN_USA18X=y
77CONFIG_USB_SERIAL_KEYSPAN_USA19W=y
78CONFIG_USB_SERIAL_KEYSPAN_USA19QW=y
79CONFIG_USB_SERIAL_KEYSPAN_USA19QI=y
80CONFIG_USB_SERIAL_KEYSPAN_USA49W=y
81CONFIG_USB_SERIAL_KEYSPAN_USA49WLC=y
82CONFIG_USB_SERIAL_MCT_U232=y
83CONFIG_NEW_LEDS=y
84CONFIG_LEDS_CLASS=y
85CONFIG_LEDS_GPIO=y
86CONFIG_LEDS_TRIGGERS=y
87CONFIG_LEDS_TRIGGER_HEARTBEAT=y
88CONFIG_EXT2_FS=y
89CONFIG_INOTIFY=y
90CONFIG_TMPFS=y
91CONFIG_CRAMFS=y
92CONFIG_NFS_FS=y
93CONFIG_NFS_V3=y
94CONFIG_NFS_V4=y
95CONFIG_ROOT_NFS=y
96CONFIG_DEBUG_KERNEL=y
97CONFIG_DEBUG_USER=y
98CONFIG_DEBUG_LL=y
diff --git a/arch/arm/configs/ecbat91_defconfig b/arch/arm/configs/ecbat91_defconfig
deleted file mode 100644
index 6bb6abdcea8c..000000000000
--- a/arch/arm/configs/ecbat91_defconfig
+++ /dev/null
@@ -1,99 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_SYSVIPC=y
3CONFIG_IKCONFIG=y
4CONFIG_IKCONFIG_PROC=y
5CONFIG_LOG_BUF_SHIFT=14
6CONFIG_SLAB=y
7CONFIG_MODULES=y
8CONFIG_MODULE_UNLOAD=y
9# CONFIG_IOSCHED_DEADLINE is not set
10# CONFIG_IOSCHED_CFQ is not set
11CONFIG_ARCH_AT91=y
12CONFIG_MACH_ECBAT91=y
13CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
14CONFIG_PCCARD=y
15CONFIG_AT91_CF=y
16CONFIG_PREEMPT=y
17CONFIG_LEDS=y
18CONFIG_LEDS_CPU=y
19CONFIG_ZBOOT_ROM_TEXT=0x0
20CONFIG_ZBOOT_ROM_BSS=0x0
21CONFIG_CMDLINE="rootfstype=reiserfs root=/dev/mmcblk0p1 console=ttyS0,115200n8 rootdelay=1"
22CONFIG_FPE_NWFPE=y
23CONFIG_NET=y
24CONFIG_PACKET=y
25CONFIG_UNIX=y
26CONFIG_INET=y
27CONFIG_IP_PNP=y
28CONFIG_IP_PNP_DHCP=y
29# CONFIG_IPV6 is not set
30CONFIG_CFG80211=y
31CONFIG_MAC80211=y
32# CONFIG_STANDALONE is not set
33# CONFIG_PREVENT_FIRMWARE_BUILD is not set
34CONFIG_MTD=y
35CONFIG_MTD_PARTITIONS=y
36CONFIG_MTD_CMDLINE_PARTS=y
37CONFIG_MTD_AFS_PARTS=y
38CONFIG_MTD_CHAR=y
39CONFIG_MTD_BLOCK=y
40CONFIG_MTD_DATAFLASH=y
41CONFIG_BLK_DEV_LOOP=y
42CONFIG_SCSI=y
43CONFIG_BLK_DEV_SD=y
44CONFIG_CHR_DEV_SG=y
45CONFIG_NETDEVICES=y
46CONFIG_NET_ETHERNET=y
47CONFIG_ARM_AT91_ETHER=y
48# CONFIG_NETDEV_1000 is not set
49# CONFIG_NETDEV_10000 is not set
50CONFIG_PPP=y
51CONFIG_PPP_MULTILINK=y
52CONFIG_PPP_FILTER=y
53CONFIG_PPP_ASYNC=y
54# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
55# CONFIG_INPUT_KEYBOARD is not set
56# CONFIG_INPUT_MOUSE is not set
57# CONFIG_SERIO is not set
58CONFIG_SERIAL_ATMEL=y
59CONFIG_SERIAL_ATMEL_CONSOLE=y
60CONFIG_HW_RANDOM=y
61CONFIG_I2C=y
62CONFIG_I2C_CHARDEV=y
63CONFIG_SPI=y
64CONFIG_SPI_BITBANG=y
65CONFIG_WATCHDOG=y
66CONFIG_WATCHDOG_NOWAYOUT=y
67# CONFIG_VGA_CONSOLE is not set
68# CONFIG_USB_HID is not set
69CONFIG_USB=y
70CONFIG_USB_DEVICEFS=y
71# CONFIG_USB_DEVICE_CLASS is not set
72CONFIG_USB_OHCI_HCD=y
73CONFIG_USB_PRINTER=y
74CONFIG_USB_STORAGE=y
75CONFIG_USB_GADGET=y
76CONFIG_MMC=y
77CONFIG_MMC_DEBUG=y
78CONFIG_MMC_AT91=m
79CONFIG_NEW_LEDS=y
80CONFIG_LEDS_CLASS=y
81CONFIG_RTC_CLASS=y
82# CONFIG_RTC_HCTOSYS is not set
83CONFIG_RTC_DRV_AT91RM9200=y
84CONFIG_EXT2_FS=y
85CONFIG_EXT3_FS=y
86CONFIG_REISERFS_FS=y
87CONFIG_INOTIFY=y
88CONFIG_TMPFS=y
89CONFIG_CONFIGFS_FS=y
90CONFIG_CRAMFS=y
91CONFIG_NFS_FS=y
92CONFIG_NFS_V3=y
93CONFIG_NFS_V3_ACL=y
94CONFIG_NFS_V4=y
95CONFIG_ROOT_NFS=y
96CONFIG_PARTITION_ADVANCED=y
97CONFIG_DEBUG_USER=y
98CONFIG_CRYPTO_PCBC=y
99CONFIG_CRYPTO_SHA1=y
diff --git a/arch/arm/configs/kafa_defconfig b/arch/arm/configs/kafa_defconfig
deleted file mode 100644
index 896dbe00dc6e..000000000000
--- a/arch/arm/configs/kafa_defconfig
+++ /dev/null
@@ -1,61 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_LOCALVERSION_AUTO is not set
3# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y
5CONFIG_LOG_BUF_SHIFT=14
6CONFIG_SLAB=y
7CONFIG_MODULES=y
8CONFIG_MODULE_UNLOAD=y
9# CONFIG_IOSCHED_CFQ is not set
10CONFIG_ARCH_AT91=y
11CONFIG_MACH_KAFA=y
12# CONFIG_ARM_THUMB is not set
13CONFIG_PREEMPT=y
14CONFIG_LEDS=y
15CONFIG_LEDS_CPU=y
16CONFIG_ZBOOT_ROM_TEXT=0x0
17CONFIG_ZBOOT_ROM_BSS=0x0
18CONFIG_CMDLINE="mem=32M console=ttyS0,115200 initrd=0x20800000,10M root=/dev/ram0 rw"
19CONFIG_FPE_NWFPE=y
20CONFIG_BINFMT_MISC=y
21CONFIG_NET=y
22CONFIG_PACKET=y
23CONFIG_UNIX=y
24CONFIG_INET=y
25# CONFIG_INET_DIAG is not set
26# CONFIG_IPV6 is not set
27CONFIG_MTD=y
28CONFIG_MTD_PARTITIONS=y
29CONFIG_MTD_CHAR=y
30CONFIG_MTD_BLOCK_RO=y
31CONFIG_NETDEVICES=y
32CONFIG_PHYLIB=y
33CONFIG_DAVICOM_PHY=y
34CONFIG_NET_ETHERNET=y
35CONFIG_ARM_AT91_ETHER=y
36# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
37# CONFIG_INPUT_KEYBOARD is not set
38# CONFIG_INPUT_MOUSE is not set
39# CONFIG_SERIO is not set
40CONFIG_SERIAL_ATMEL=y
41CONFIG_SERIAL_ATMEL_CONSOLE=y
42CONFIG_LEGACY_PTY_COUNT=32
43CONFIG_I2C=y
44CONFIG_I2C_CHARDEV=y
45CONFIG_I2C_GPIO=y
46# CONFIG_HWMON is not set
47CONFIG_WATCHDOG=y
48CONFIG_WATCHDOG_NOWAYOUT=y
49CONFIG_AT91RM9200_WATCHDOG=y
50# CONFIG_VGA_CONSOLE is not set
51CONFIG_RTC_CLASS=y
52# CONFIG_RTC_HCTOSYS is not set
53CONFIG_RTC_DRV_AT91RM9200=y
54CONFIG_EXT3_FS=y
55# CONFIG_EXT3_FS_XATTR is not set
56CONFIG_TMPFS=y
57CONFIG_CRAMFS=y
58CONFIG_NFS_FS=m
59CONFIG_NFS_V3=y
60CONFIG_CRYPTO_MD5=y
61CONFIG_CRYPTO_DES=y
diff --git a/arch/arm/configs/kb9202_defconfig b/arch/arm/configs/kb9202_defconfig
deleted file mode 100644
index 9f906a85f5c2..000000000000
--- a/arch/arm/configs/kb9202_defconfig
+++ /dev/null
@@ -1,127 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_POSIX_MQUEUE=y
5CONFIG_BSD_PROCESS_ACCT=y
6CONFIG_AUDIT=y
7CONFIG_IKCONFIG=y
8CONFIG_IKCONFIG_PROC=y
9CONFIG_BLK_DEV_INITRD=y
10CONFIG_KALLSYMS_EXTRA_PASS=y
11CONFIG_MODULES=y
12CONFIG_MODULE_UNLOAD=y
13CONFIG_MODVERSIONS=y
14CONFIG_MODULE_SRCVERSION_ALL=y
15# CONFIG_BLK_DEV_BSG is not set
16# CONFIG_IOSCHED_DEADLINE is not set
17CONFIG_ARCH_AT91=y
18CONFIG_MACH_KB9200=y
19CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
20CONFIG_NO_HZ=y
21CONFIG_HIGH_RES_TIMERS=y
22CONFIG_PREEMPT=y
23CONFIG_AEABI=y
24CONFIG_ZBOOT_ROM_TEXT=0x10000000
25CONFIG_ZBOOT_ROM_BSS=0x20040000
26CONFIG_CMDLINE="noinitrd root=/dev/mtdblock0 rootfstype=jffs2 mem=64M"
27CONFIG_KEXEC=y
28CONFIG_FPE_NWFPE=y
29CONFIG_BINFMT_MISC=y
30CONFIG_NET=y
31CONFIG_PACKET=y
32CONFIG_UNIX=y
33CONFIG_INET=y
34CONFIG_IP_PNP=y
35CONFIG_IP_PNP_DHCP=y
36CONFIG_IP_PNP_BOOTP=y
37# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
38# CONFIG_INET_XFRM_MODE_TUNNEL is not set
39# CONFIG_INET_XFRM_MODE_BEET is not set
40# CONFIG_INET_LRO is not set
41# CONFIG_INET_DIAG is not set
42# CONFIG_IPV6 is not set
43CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
44# CONFIG_FIRMWARE_IN_KERNEL is not set
45CONFIG_MTD=y
46CONFIG_MTD_CONCAT=y
47CONFIG_MTD_PARTITIONS=y
48CONFIG_MTD_CMDLINE_PARTS=y
49CONFIG_MTD_CHAR=y
50CONFIG_MTD_BLOCK=y
51CONFIG_MTD_CFI=y
52CONFIG_MTD_CFI_INTELEXT=y
53CONFIG_MTD_COMPLEX_MAPPINGS=y
54CONFIG_MTD_PHYSMAP=y
55CONFIG_MTD_NAND=y
56CONFIG_MTD_NAND_ATMEL=y
57CONFIG_MTD_UBI=y
58CONFIG_MTD_UBI_GLUEBI=y
59CONFIG_BLK_DEV_LOOP=y
60CONFIG_BLK_DEV_RAM=y
61CONFIG_BLK_DEV_RAM_SIZE=16384
62CONFIG_ATMEL_TCLIB=y
63CONFIG_ATMEL_SSC=y
64CONFIG_SCSI=y
65CONFIG_BLK_DEV_SD=y
66CONFIG_CHR_DEV_SG=y
67CONFIG_SCSI_MULTI_LUN=y
68CONFIG_SCSI_CONSTANTS=y
69CONFIG_SCSI_LOGGING=y
70CONFIG_SCSI_SPI_ATTRS=m
71# CONFIG_SCSI_LOWLEVEL is not set
72CONFIG_NETDEVICES=y
73CONFIG_NET_ETHERNET=y
74CONFIG_ARM_AT91_ETHER=y
75# CONFIG_NETDEV_1000 is not set
76# CONFIG_NETDEV_10000 is not set
77# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
78# CONFIG_INPUT_KEYBOARD is not set
79# CONFIG_INPUT_MOUSE is not set
80# CONFIG_SERIO is not set
81CONFIG_SERIAL_ATMEL=y
82CONFIG_SERIAL_ATMEL_CONSOLE=y
83# CONFIG_LEGACY_PTYS is not set
84# CONFIG_HW_RANDOM is not set
85# CONFIG_HWMON is not set
86CONFIG_WATCHDOG=y
87CONFIG_AT91RM9200_WATCHDOG=y
88CONFIG_FB=y
89CONFIG_FB_MODE_HELPERS=y
90CONFIG_FB_TILEBLITTING=y
91CONFIG_BACKLIGHT_LCD_SUPPORT=y
92# CONFIG_LCD_CLASS_DEVICE is not set
93CONFIG_BACKLIGHT_CLASS_DEVICE=y
94# CONFIG_BACKLIGHT_GENERIC is not set
95# CONFIG_VGA_CONSOLE is not set
96CONFIG_FRAMEBUFFER_CONSOLE=y
97CONFIG_FONTS=y
98CONFIG_FONT_MINI_4x6=y
99# CONFIG_HID_SUPPORT is not set
100CONFIG_USB=y
101CONFIG_USB_DEVICEFS=y
102CONFIG_USB_OHCI_HCD=y
103CONFIG_USB_STORAGE=y
104CONFIG_USB_LIBUSUAL=y
105CONFIG_MMC=y
106CONFIG_MMC_AT91=m
107CONFIG_RTC_CLASS=y
108CONFIG_RTC_DRV_AT91RM9200=y
109CONFIG_EXT2_FS=y
110CONFIG_EXT3_FS=y
111# CONFIG_DNOTIFY is not set
112CONFIG_INOTIFY=y
113CONFIG_VFAT_FS=y
114CONFIG_TMPFS=y
115CONFIG_CONFIGFS_FS=y
116CONFIG_JFFS2_FS=y
117CONFIG_NFS_FS=y
118CONFIG_NFS_V3=y
119CONFIG_ROOT_NFS=y
120CONFIG_NLS_CODEPAGE_437=y
121CONFIG_NLS_UTF8=y
122CONFIG_MAGIC_SYSRQ=y
123CONFIG_DEBUG_FS=y
124CONFIG_DEBUG_KERNEL=y
125# CONFIG_SCHED_DEBUG is not set
126# CONFIG_DEBUG_PREEMPT is not set
127# CONFIG_RCU_CPU_STALL_DETECTOR is not set
diff --git a/arch/arm/configs/onearm_defconfig b/arch/arm/configs/onearm_defconfig
deleted file mode 100644
index 1579857aeeaa..000000000000
--- a/arch/arm/configs/onearm_defconfig
+++ /dev/null
@@ -1,80 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_LOG_BUF_SHIFT=14
5CONFIG_BLK_DEV_INITRD=y
6CONFIG_EMBEDDED=y
7CONFIG_SLAB=y
8CONFIG_MODULES=y
9CONFIG_MODULE_UNLOAD=y
10# CONFIG_IOSCHED_DEADLINE is not set
11# CONFIG_IOSCHED_CFQ is not set
12CONFIG_ARCH_AT91=y
13CONFIG_MACH_ONEARM=y
14CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
15# CONFIG_ARM_THUMB is not set
16CONFIG_PCCARD=y
17CONFIG_AT91_CF=y
18CONFIG_LEDS=y
19CONFIG_ZBOOT_ROM_TEXT=0x0
20CONFIG_ZBOOT_ROM_BSS=0x0
21CONFIG_CMDLINE="console=ttyS0,115200 root=/dev/nfs ip=bootp mem=64M"
22CONFIG_FPE_NWFPE=y
23CONFIG_NET=y
24CONFIG_PACKET=y
25CONFIG_UNIX=y
26CONFIG_INET=y
27CONFIG_IP_PNP=y
28CONFIG_IP_PNP_BOOTP=y
29CONFIG_IPV6=y
30# CONFIG_INET6_XFRM_MODE_TRANSPORT is not set
31# CONFIG_INET6_XFRM_MODE_TUNNEL is not set
32# CONFIG_INET6_XFRM_MODE_BEET is not set
33# CONFIG_IPV6_SIT is not set
34CONFIG_MTD=y
35CONFIG_MTD_PARTITIONS=y
36CONFIG_MTD_CMDLINE_PARTS=y
37CONFIG_MTD_CHAR=y
38CONFIG_MTD_BLOCK=y
39CONFIG_MTD_CFI=y
40CONFIG_MTD_JEDECPROBE=y
41CONFIG_MTD_CFI_AMDSTD=y
42CONFIG_MTD_PHYSMAP=y
43CONFIG_BLK_DEV_NBD=y
44CONFIG_BLK_DEV_RAM=y
45CONFIG_BLK_DEV_RAM_SIZE=8192
46CONFIG_NETDEVICES=y
47CONFIG_NET_ETHERNET=y
48CONFIG_ARM_AT91_ETHER=y
49# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
50# CONFIG_INPUT_KEYBOARD is not set
51# CONFIG_INPUT_MOUSE is not set
52# CONFIG_SERIO is not set
53# CONFIG_VT is not set
54CONFIG_SERIAL_ATMEL=y
55CONFIG_SERIAL_ATMEL_CONSOLE=y
56# CONFIG_HW_RANDOM is not set
57CONFIG_I2C=y
58CONFIG_I2C_CHARDEV=y
59CONFIG_WATCHDOG=y
60CONFIG_WATCHDOG_NOWAYOUT=y
61CONFIG_AT91RM9200_WATCHDOG=y
62# CONFIG_USB_HID is not set
63CONFIG_USB=y
64CONFIG_USB_DEBUG=y
65CONFIG_USB_DEVICEFS=y
66CONFIG_USB_MON=y
67CONFIG_USB_OHCI_HCD=y
68CONFIG_USB_GADGET=y
69CONFIG_MMC=y
70CONFIG_EXT2_FS=y
71CONFIG_INOTIFY=y
72CONFIG_TMPFS=y
73CONFIG_CRAMFS=y
74CONFIG_NFS_FS=y
75CONFIG_NFS_V3=y
76CONFIG_NFS_V3_ACL=y
77CONFIG_ROOT_NFS=y
78CONFIG_DEBUG_KERNEL=y
79CONFIG_DEBUG_USER=y
80CONFIG_DEBUG_LL=y
diff --git a/arch/arm/configs/picotux200_defconfig b/arch/arm/configs/picotux200_defconfig
deleted file mode 100644
index 4c9afa478d57..000000000000
--- a/arch/arm/configs/picotux200_defconfig
+++ /dev/null
@@ -1,242 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_SYSVIPC=y
3CONFIG_IKCONFIG=m
4CONFIG_IKCONFIG_PROC=y
5CONFIG_LOG_BUF_SHIFT=14
6CONFIG_EMBEDDED=y
7# CONFIG_KALLSYMS is not set
8CONFIG_SLAB=y
9CONFIG_MODULES=y
10CONFIG_MODULE_UNLOAD=y
11# CONFIG_IOSCHED_DEADLINE is not set
12# CONFIG_IOSCHED_CFQ is not set
13CONFIG_ARCH_AT91=y
14CONFIG_MACH_PICOTUX2XX=y
15CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
16CONFIG_AEABI=y
17CONFIG_ZBOOT_ROM_TEXT=0x0
18CONFIG_ZBOOT_ROM_BSS=0x0
19CONFIG_KEXEC=y
20CONFIG_FPE_NWFPE=y
21CONFIG_BINFMT_MISC=m
22CONFIG_NET=y
23CONFIG_PACKET=m
24CONFIG_UNIX=y
25CONFIG_XFRM_USER=m
26CONFIG_INET=y
27CONFIG_IP_PNP=y
28CONFIG_IP_PNP_BOOTP=y
29CONFIG_NET_IPIP=m
30CONFIG_NET_IPGRE=m
31CONFIG_INET_AH=m
32CONFIG_INET_ESP=m
33CONFIG_INET_IPCOMP=m
34CONFIG_INET_XFRM_MODE_TRANSPORT=m
35CONFIG_INET_XFRM_MODE_TUNNEL=m
36CONFIG_INET_XFRM_MODE_BEET=m
37CONFIG_INET_DIAG=m
38CONFIG_IPV6_PRIVACY=y
39CONFIG_IPV6_ROUTER_PREF=y
40CONFIG_IPV6_ROUTE_INFO=y
41CONFIG_INET6_AH=m
42CONFIG_INET6_ESP=m
43CONFIG_INET6_IPCOMP=m
44CONFIG_IPV6_MIP6=m
45CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
46CONFIG_IPV6_TUNNEL=m
47CONFIG_BRIDGE=m
48CONFIG_VLAN_8021Q=m
49CONFIG_BT=m
50CONFIG_BT_L2CAP=m
51CONFIG_BT_SCO=m
52CONFIG_BT_RFCOMM=m
53CONFIG_BT_RFCOMM_TTY=y
54CONFIG_BT_BNEP=m
55CONFIG_BT_BNEP_MC_FILTER=y
56CONFIG_BT_BNEP_PROTO_FILTER=y
57CONFIG_BT_HIDP=m
58CONFIG_FW_LOADER=m
59CONFIG_MTD=y
60CONFIG_MTD_PARTITIONS=y
61CONFIG_MTD_CMDLINE_PARTS=y
62CONFIG_MTD_CHAR=y
63CONFIG_MTD_BLOCK=y
64CONFIG_MTD_CFI=y
65CONFIG_MTD_CFI_AMDSTD=y
66CONFIG_MTD_PHYSMAP=y
67CONFIG_BLK_DEV_LOOP=m
68CONFIG_EEPROM_LEGACY=m
69CONFIG_SCSI=m
70CONFIG_BLK_DEV_SD=m
71CONFIG_BLK_DEV_SR=m
72CONFIG_BLK_DEV_SR_VENDOR=y
73CONFIG_CHR_DEV_SG=m
74CONFIG_NETDEVICES=y
75CONFIG_TUN=m
76CONFIG_NET_ETHERNET=y
77CONFIG_ARM_AT91_ETHER=y
78CONFIG_USB_CATC=m
79CONFIG_USB_KAWETH=m
80CONFIG_USB_PEGASUS=m
81CONFIG_USB_RTL8150=m
82CONFIG_USB_USBNET=m
83CONFIG_USB_NET_DM9601=m
84CONFIG_USB_NET_GL620A=m
85CONFIG_USB_NET_PLUSB=m
86CONFIG_USB_NET_MCS7830=m
87CONFIG_USB_NET_RNDIS_HOST=m
88CONFIG_USB_ALI_M5632=y
89CONFIG_USB_AN2720=y
90CONFIG_USB_EPSON2888=y
91CONFIG_USB_KC2190=y
92CONFIG_PPP=m
93CONFIG_PPP_FILTER=y
94CONFIG_PPP_ASYNC=m
95CONFIG_PPP_DEFLATE=m
96CONFIG_PPP_BSDCOMP=m
97CONFIG_PPP_MPPE=m
98CONFIG_PPPOE=m
99CONFIG_SLIP=m
100CONFIG_SLIP_COMPRESSED=y
101CONFIG_SLIP_SMART=y
102CONFIG_SLIP_MODE_SLIP6=y
103# CONFIG_INPUT_MOUSEDEV is not set
104# CONFIG_INPUT_KEYBOARD is not set
105# CONFIG_INPUT_MOUSE is not set
106# CONFIG_SERIO is not set
107# CONFIG_VT is not set
108CONFIG_SERIAL_ATMEL=y
109CONFIG_SERIAL_ATMEL_CONSOLE=y
110# CONFIG_LEGACY_PTYS is not set
111CONFIG_I2C=m
112CONFIG_I2C_CHARDEV=m
113CONFIG_I2C_GPIO=m
114CONFIG_HWMON=m
115CONFIG_SENSORS_ADM1021=m
116CONFIG_SENSORS_ADM1025=m
117CONFIG_SENSORS_ADM1026=m
118CONFIG_SENSORS_ADM1029=m
119CONFIG_SENSORS_ADM1031=m
120CONFIG_SENSORS_ADM9240=m
121CONFIG_SENSORS_DS1621=m
122CONFIG_SENSORS_GL518SM=m
123CONFIG_SENSORS_GL520SM=m
124CONFIG_SENSORS_IT87=m
125CONFIG_SENSORS_LM63=m
126CONFIG_SENSORS_LM75=m
127CONFIG_SENSORS_LM77=m
128CONFIG_SENSORS_LM78=m
129CONFIG_SENSORS_LM80=m
130CONFIG_SENSORS_LM83=m
131CONFIG_SENSORS_LM85=m
132CONFIG_SENSORS_LM87=m
133CONFIG_SENSORS_LM90=m
134CONFIG_SENSORS_LM92=m
135CONFIG_SENSORS_MAX1619=m
136CONFIG_SENSORS_PCF8591=m
137CONFIG_SENSORS_SMSC47B397=m
138CONFIG_SENSORS_W83781D=m
139CONFIG_SENSORS_W83791D=m
140CONFIG_SENSORS_W83792D=m
141CONFIG_SENSORS_W83793=m
142CONFIG_SENSORS_W83L785TS=m
143CONFIG_WATCHDOG=y
144CONFIG_WATCHDOG_NOWAYOUT=y
145CONFIG_AT91RM9200_WATCHDOG=m
146CONFIG_HID=m
147CONFIG_USB=m
148CONFIG_USB_DEVICEFS=y
149CONFIG_USB_OHCI_HCD=m
150CONFIG_USB_ACM=m
151CONFIG_USB_PRINTER=m
152CONFIG_USB_STORAGE=m
153CONFIG_USB_SERIAL=m
154CONFIG_USB_SERIAL_GENERIC=y
155CONFIG_USB_SERIAL_PL2303=m
156CONFIG_MMC=m
157CONFIG_MMC_AT91=m
158CONFIG_RTC_CLASS=m
159CONFIG_RTC_DRV_AT91RM9200=m
160CONFIG_EXT2_FS=m
161CONFIG_EXT3_FS=m
162# CONFIG_EXT3_FS_XATTR is not set
163CONFIG_INOTIFY=y
164CONFIG_ISO9660_FS=m
165CONFIG_JOLIET=y
166CONFIG_UDF_FS=m
167CONFIG_MSDOS_FS=m
168CONFIG_VFAT_FS=m
169CONFIG_NTFS_FS=m
170CONFIG_TMPFS=y
171CONFIG_JFFS2_FS=y
172CONFIG_JFFS2_SUMMARY=y
173CONFIG_JFFS2_COMPRESSION_OPTIONS=y
174CONFIG_NFS_FS=m
175CONFIG_SMB_FS=m
176CONFIG_CIFS=m
177CONFIG_PARTITION_ADVANCED=y
178CONFIG_AMIGA_PARTITION=y
179CONFIG_NLS_DEFAULT="utf-8"
180CONFIG_NLS_CODEPAGE_437=m
181CONFIG_NLS_CODEPAGE_737=m
182CONFIG_NLS_CODEPAGE_775=m
183CONFIG_NLS_CODEPAGE_850=m
184CONFIG_NLS_CODEPAGE_852=m
185CONFIG_NLS_CODEPAGE_855=m
186CONFIG_NLS_CODEPAGE_857=m
187CONFIG_NLS_CODEPAGE_860=m
188CONFIG_NLS_CODEPAGE_861=m
189CONFIG_NLS_CODEPAGE_862=m
190CONFIG_NLS_CODEPAGE_863=m
191CONFIG_NLS_CODEPAGE_864=m
192CONFIG_NLS_CODEPAGE_865=m
193CONFIG_NLS_CODEPAGE_866=m
194CONFIG_NLS_CODEPAGE_869=m
195CONFIG_NLS_CODEPAGE_936=m
196CONFIG_NLS_CODEPAGE_950=m
197CONFIG_NLS_CODEPAGE_932=m
198CONFIG_NLS_CODEPAGE_949=m
199CONFIG_NLS_CODEPAGE_874=m
200CONFIG_NLS_ISO8859_8=m
201CONFIG_NLS_CODEPAGE_1250=m
202CONFIG_NLS_CODEPAGE_1251=m
203CONFIG_NLS_ASCII=m
204CONFIG_NLS_ISO8859_1=m
205CONFIG_NLS_ISO8859_2=m
206CONFIG_NLS_ISO8859_3=m
207CONFIG_NLS_ISO8859_4=m
208CONFIG_NLS_ISO8859_5=m
209CONFIG_NLS_ISO8859_6=m
210CONFIG_NLS_ISO8859_7=m
211CONFIG_NLS_ISO8859_9=m
212CONFIG_NLS_ISO8859_13=m
213CONFIG_NLS_ISO8859_14=m
214CONFIG_NLS_ISO8859_15=m
215CONFIG_NLS_KOI8_R=m
216CONFIG_NLS_KOI8_U=m
217CONFIG_NLS_UTF8=m
218CONFIG_DEBUG_KERNEL=y
219# CONFIG_DEBUG_BUGVERBOSE is not set
220CONFIG_DEBUG_LL=y
221CONFIG_CRYPTO_NULL=m
222CONFIG_CRYPTO_TEST=m
223CONFIG_CRYPTO_LRW=m
224CONFIG_CRYPTO_PCBC=m
225CONFIG_CRYPTO_XCBC=m
226CONFIG_CRYPTO_MD4=m
227CONFIG_CRYPTO_MICHAEL_MIC=m
228CONFIG_CRYPTO_SHA256=m
229CONFIG_CRYPTO_SHA512=m
230CONFIG_CRYPTO_TGR192=m
231CONFIG_CRYPTO_WP512=m
232CONFIG_CRYPTO_ANUBIS=m
233CONFIG_CRYPTO_BLOWFISH=m
234CONFIG_CRYPTO_CAMELLIA=m
235CONFIG_CRYPTO_CAST5=m
236CONFIG_CRYPTO_CAST6=m
237CONFIG_CRYPTO_FCRYPT=m
238CONFIG_CRYPTO_KHAZAD=m
239CONFIG_CRYPTO_SERPENT=m
240CONFIG_CRYPTO_TEA=m
241CONFIG_CRYPTO_TWOFISH=m
242CONFIG_LIBCRC32C=m
diff --git a/arch/arm/configs/yl9200_defconfig b/arch/arm/configs/yl9200_defconfig
deleted file mode 100644
index 30c537f61089..000000000000
--- a/arch/arm/configs/yl9200_defconfig
+++ /dev/null
@@ -1,137 +0,0 @@
1# CONFIG_SWAP is not set
2CONFIG_SYSVIPC=y
3CONFIG_LOG_BUF_SHIFT=14
4CONFIG_BLK_DEV_INITRD=y
5# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
6CONFIG_MODULES=y
7CONFIG_MODULE_UNLOAD=y
8# CONFIG_IOSCHED_DEADLINE is not set
9# CONFIG_IOSCHED_CFQ is not set
10CONFIG_ARCH_AT91=y
11CONFIG_ARCH_AT91RM9200DK=y
12CONFIG_MACH_YL9200=y
13# CONFIG_ARM_THUMB is not set
14CONFIG_ZBOOT_ROM_TEXT=0x0
15CONFIG_ZBOOT_ROM_BSS=0x0
16CONFIG_CMDLINE="mem=32M console=ttyS0,115200 initrd=0x20410000,3145728 root=/dev/ram0 rw"
17CONFIG_FPE_NWFPE=y
18CONFIG_NET=y
19CONFIG_PACKET=y
20CONFIG_UNIX=y
21CONFIG_INET=y
22CONFIG_IP_PNP=y
23CONFIG_IP_PNP_DHCP=y
24# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
25# CONFIG_INET_XFRM_MODE_TUNNEL is not set
26# CONFIG_INET_XFRM_MODE_BEET is not set
27# CONFIG_INET_LRO is not set
28# CONFIG_INET_DIAG is not set
29# CONFIG_IPV6 is not set
30CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
31CONFIG_MTD=y
32CONFIG_MTD_CONCAT=y
33CONFIG_MTD_PARTITIONS=y
34CONFIG_MTD_CMDLINE_PARTS=y
35CONFIG_MTD_CHAR=y
36CONFIG_MTD_BLOCK=y
37CONFIG_MTD_CFI=y
38CONFIG_MTD_JEDECPROBE=y
39CONFIG_MTD_CFI_INTELEXT=y
40CONFIG_MTD_COMPLEX_MAPPINGS=y
41CONFIG_MTD_PHYSMAP=y
42CONFIG_MTD_PLATRAM=y
43CONFIG_MTD_NAND=y
44CONFIG_MTD_NAND_ATMEL=y
45CONFIG_MTD_NAND_PLATFORM=y
46CONFIG_BLK_DEV_LOOP=y
47CONFIG_BLK_DEV_RAM=y
48CONFIG_BLK_DEV_RAM_COUNT=3
49CONFIG_BLK_DEV_RAM_SIZE=8192
50# CONFIG_MISC_DEVICES is not set
51CONFIG_BLK_DEV_SD=y
52CONFIG_ATA=y
53CONFIG_NETDEVICES=y
54CONFIG_PHYLIB=y
55CONFIG_DAVICOM_PHY=y
56CONFIG_NET_ETHERNET=y
57CONFIG_ARM_AT91_ETHER=y
58# CONFIG_NETDEV_1000 is not set
59# CONFIG_NETDEV_10000 is not set
60# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
61CONFIG_INPUT_MOUSEDEV_SCREEN_X=640
62CONFIG_INPUT_MOUSEDEV_SCREEN_Y=480
63CONFIG_INPUT_EVDEV=y
64# CONFIG_KEYBOARD_ATKBD is not set
65CONFIG_KEYBOARD_GPIO=y
66CONFIG_INPUT_TOUCHSCREEN=y
67CONFIG_TOUCHSCREEN_ADS7846=y
68# CONFIG_SERIO_SERPORT is not set
69CONFIG_SERIAL_ATMEL=y
70CONFIG_SERIAL_ATMEL_CONSOLE=y
71# CONFIG_HW_RANDOM is not set
72CONFIG_I2C=y
73CONFIG_SPI=y
74CONFIG_SPI_DEBUG=y
75CONFIG_SPI_ATMEL=y
76CONFIG_FB=y
77CONFIG_BACKLIGHT_LCD_SUPPORT=y
78CONFIG_LCD_CLASS_DEVICE=y
79CONFIG_BACKLIGHT_CLASS_DEVICE=y
80CONFIG_DISPLAY_SUPPORT=y
81# CONFIG_VGA_CONSOLE is not set
82CONFIG_LOGO=y
83# CONFIG_LOGO_LINUX_MONO is not set
84# CONFIG_LOGO_LINUX_VGA16 is not set
85CONFIG_USB=y
86CONFIG_USB_DEBUG=y
87CONFIG_USB_DEVICEFS=y
88# CONFIG_USB_DEVICE_CLASS is not set
89CONFIG_USB_MON=y
90CONFIG_USB_OHCI_HCD=y
91CONFIG_USB_STORAGE=y
92CONFIG_USB_GADGET=y
93CONFIG_USB_GADGET_M66592=y
94CONFIG_USB_FILE_STORAGE=m
95CONFIG_MMC=y
96CONFIG_MMC_DEBUG=y
97# CONFIG_MMC_BLOCK_BOUNCE is not set
98CONFIG_MMC_AT91=m
99CONFIG_NEW_LEDS=y
100CONFIG_LEDS_CLASS=y
101CONFIG_LEDS_GPIO=y
102CONFIG_LEDS_TRIGGERS=y
103CONFIG_LEDS_TRIGGER_TIMER=y
104CONFIG_LEDS_TRIGGER_HEARTBEAT=y
105CONFIG_RTC_CLASS=y
106CONFIG_RTC_DRV_AT91RM9200=y
107CONFIG_EXT2_FS=y
108CONFIG_EXT2_FS_XATTR=y
109CONFIG_EXT3_FS=y
110CONFIG_REISERFS_FS=y
111CONFIG_INOTIFY=y
112CONFIG_ISO9660_FS=y
113CONFIG_JOLIET=y
114CONFIG_ZISOFS=y
115CONFIG_UDF_FS=y
116CONFIG_MSDOS_FS=y
117CONFIG_VFAT_FS=y
118CONFIG_TMPFS=y
119CONFIG_JFFS2_FS=y
120CONFIG_JFFS2_FS_DEBUG=1
121CONFIG_JFFS2_COMPRESSION_OPTIONS=y
122CONFIG_JFFS2_RUBIN=y
123CONFIG_CRAMFS=y
124CONFIG_PARTITION_ADVANCED=y
125CONFIG_MAC_PARTITION=y
126CONFIG_NLS_CODEPAGE_437=y
127CONFIG_NLS_ISO8859_1=y
128# CONFIG_ENABLE_MUST_CHECK is not set
129CONFIG_DEBUG_FS=y
130CONFIG_DEBUG_KERNEL=y
131CONFIG_SLUB_DEBUG_ON=y
132CONFIG_DEBUG_KOBJECT=y
133CONFIG_DEBUG_INFO=y
134CONFIG_DEBUG_LIST=y
135CONFIG_DEBUG_USER=y
136CONFIG_DEBUG_ERRORS=y
137CONFIG_DEBUG_LL=y
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 062b58c029ab..749bb6622404 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -238,7 +238,7 @@
238 @ Slightly optimised to avoid incrementing the pointer twice 238 @ Slightly optimised to avoid incrementing the pointer twice
239 usraccoff \instr, \reg, \ptr, \inc, 0, \cond, \abort 239 usraccoff \instr, \reg, \ptr, \inc, 0, \cond, \abort
240 .if \rept == 2 240 .if \rept == 2
241 usraccoff \instr, \reg, \ptr, \inc, 4, \cond, \abort 241 usraccoff \instr, \reg, \ptr, \inc, \inc, \cond, \abort
242 .endif 242 .endif
243 243
244 add\cond \ptr, #\rept * \inc 244 add\cond \ptr, #\rept * \inc
diff --git a/arch/arm/include/asm/hardware/it8152.h b/arch/arm/include/asm/hardware/it8152.h
index 6700c7fc7ebd..21fa272301f8 100644
--- a/arch/arm/include/asm/hardware/it8152.h
+++ b/arch/arm/include/asm/hardware/it8152.h
@@ -75,7 +75,7 @@ extern unsigned long it8152_base_address;
75 IT8152_PD_IRQ(1) USB (USBR) 75 IT8152_PD_IRQ(1) USB (USBR)
76 IT8152_PD_IRQ(0) Audio controller (ACR) 76 IT8152_PD_IRQ(0) Audio controller (ACR)
77 */ 77 */
78#define IT8152_IRQ(x) (IRQ_BOARD_END + (x)) 78#define IT8152_IRQ(x) (IRQ_BOARD_START + (x))
79 79
80/* IRQ-sources in 3 groups - local devices, LPC (serial), and external PCI */ 80/* IRQ-sources in 3 groups - local devices, LPC (serial), and external PCI */
81#define IT8152_LD_IRQ_COUNT 9 81#define IT8152_LD_IRQ_COUNT 9
diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h
index 68870c776671..b4ffe9d5b526 100644
--- a/arch/arm/include/asm/mmu.h
+++ b/arch/arm/include/asm/mmu.h
@@ -13,6 +13,10 @@ typedef struct {
13 13
14#ifdef CONFIG_CPU_HAS_ASID 14#ifdef CONFIG_CPU_HAS_ASID
15#define ASID(mm) ((mm)->context.id & 255) 15#define ASID(mm) ((mm)->context.id & 255)
16
17/* init_mm.context.id_lock should be initialized. */
18#define INIT_MM_CONTEXT(name) \
19 .context.id_lock = __SPIN_LOCK_UNLOCKED(name.context.id_lock),
16#else 20#else
17#define ASID(mm) (0) 21#define ASID(mm) (0)
18#endif 22#endif
diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index b155414192da..53d1d5deb111 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -374,6 +374,9 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)
374 374
375#define pmd_page(pmd) pfn_to_page(__phys_to_pfn(pmd_val(pmd))) 375#define pmd_page(pmd) pfn_to_page(__phys_to_pfn(pmd_val(pmd)))
376 376
377/* we don't need complex calculations here as the pmd is folded into the pgd */
378#define pmd_addr_end(addr,end) (end)
379
377/* 380/*
378 * Conversion functions: convert a page and protection to a page entry, 381 * Conversion functions: convert a page and protection to a page entry,
379 * and a page entry and page directory to the page they refer to. 382 * and a page entry and page directory to the page they refer to.
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index c09e3573c5de..bb96a7d4bbf5 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -911,7 +911,7 @@ __kuser_cmpxchg: @ 0xffff0fc0
911 * A special ghost syscall is used for that (see traps.c). 911 * A special ghost syscall is used for that (see traps.c).
912 */ 912 */
913 stmfd sp!, {r7, lr} 913 stmfd sp!, {r7, lr}
914 ldr r7, =1f @ it's 20 bits 914 ldr r7, 1f @ it's 20 bits
915 swi __ARM_NR_cmpxchg 915 swi __ARM_NR_cmpxchg
916 ldmfd sp!, {r7, pc} 916 ldmfd sp!, {r7, pc}
9171: .word __ARM_NR_cmpxchg 9171: .word __ARM_NR_cmpxchg
diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index dd6b369ac69c..6bd82d25683c 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -85,9 +85,11 @@ ENTRY(stext)
85 mrc p15, 0, r9, c0, c0 @ get processor id 85 mrc p15, 0, r9, c0, c0 @ get processor id
86 bl __lookup_processor_type @ r5=procinfo r9=cpuid 86 bl __lookup_processor_type @ r5=procinfo r9=cpuid
87 movs r10, r5 @ invalid processor (r5=0)? 87 movs r10, r5 @ invalid processor (r5=0)?
88 THUMB( it eq ) @ force fixup-able long branch encoding
88 beq __error_p @ yes, error 'p' 89 beq __error_p @ yes, error 'p'
89 bl __lookup_machine_type @ r5=machinfo 90 bl __lookup_machine_type @ r5=machinfo
90 movs r8, r5 @ invalid machine (r5=0)? 91 movs r8, r5 @ invalid machine (r5=0)?
92 THUMB( it eq ) @ force fixup-able long branch encoding
91 beq __error_a @ yes, error 'a' 93 beq __error_a @ yes, error 'a'
92 bl __vet_atags 94 bl __vet_atags
93#ifdef CONFIG_SMP_ON_UP 95#ifdef CONFIG_SMP_ON_UP
@@ -262,6 +264,7 @@ __create_page_tables:
262 mov pc, lr 264 mov pc, lr
263ENDPROC(__create_page_tables) 265ENDPROC(__create_page_tables)
264 .ltorg 266 .ltorg
267 .align
265__enable_mmu_loc: 268__enable_mmu_loc:
266 .long . 269 .long .
267 .long __enable_mmu 270 .long __enable_mmu
@@ -282,6 +285,7 @@ ENTRY(secondary_startup)
282 bl __lookup_processor_type 285 bl __lookup_processor_type
283 movs r10, r5 @ invalid processor? 286 movs r10, r5 @ invalid processor?
284 moveq r0, #'p' @ yes, error 'p' 287 moveq r0, #'p' @ yes, error 'p'
288 THUMB( it eq ) @ force fixup-able long branch encoding
285 beq __error_p 289 beq __error_p
286 290
287 /* 291 /*
@@ -308,6 +312,8 @@ ENTRY(__secondary_switched)
308 b secondary_start_kernel 312 b secondary_start_kernel
309ENDPROC(__secondary_switched) 313ENDPROC(__secondary_switched)
310 314
315 .align
316
311 .type __secondary_data, %object 317 .type __secondary_data, %object
312__secondary_data: 318__secondary_data:
313 .long . 319 .long .
@@ -413,6 +419,7 @@ __fixup_smp_on_up:
413 mov pc, lr 419 mov pc, lr
414ENDPROC(__fixup_smp) 420ENDPROC(__fixup_smp)
415 421
422 .align
4161: .word . 4231: .word .
417 .word __smpalt_begin 424 .word __smpalt_begin
418 .word __smpalt_end 425 .word __smpalt_end
diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
index 54593b0c241b..21e3a4ab3b8c 100644
--- a/arch/arm/kernel/hw_breakpoint.c
+++ b/arch/arm/kernel/hw_breakpoint.c
@@ -748,8 +748,7 @@ static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,
748 breakpoint_handler(addr, regs); 748 breakpoint_handler(addr, regs);
749 break; 749 break;
750 case ARM_ENTRY_ASYNC_WATCHPOINT: 750 case ARM_ENTRY_ASYNC_WATCHPOINT:
751 WARN_ON("Asynchronous watchpoint exception taken. " 751 WARN(1, "Asynchronous watchpoint exception taken. Debugging results may be unreliable\n");
752 "Debugging results may be unreliable");
753 case ARM_ENTRY_SYNC_WATCHPOINT: 752 case ARM_ENTRY_SYNC_WATCHPOINT:
754 watchpoint_handler(addr, regs); 753 watchpoint_handler(addr, regs);
755 break; 754 break;
diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c
index 49643b1467e6..07a50357492a 100644
--- a/arch/arm/kernel/perf_event.c
+++ b/arch/arm/kernel/perf_event.c
@@ -1749,7 +1749,7 @@ static inline int armv7_pmnc_has_overflowed(unsigned long pmnc)
1749static inline int armv7_pmnc_counter_has_overflowed(unsigned long pmnc, 1749static inline int armv7_pmnc_counter_has_overflowed(unsigned long pmnc,
1750 enum armv7_counters counter) 1750 enum armv7_counters counter)
1751{ 1751{
1752 int ret; 1752 int ret = 0;
1753 1753
1754 if (counter == ARMV7_CYCLE_COUNTER) 1754 if (counter == ARMV7_CYCLE_COUNTER)
1755 ret = pmnc & ARMV7_FLAG_C; 1755 ret = pmnc & ARMV7_FLAG_C;
diff --git a/arch/arm/kernel/relocate_kernel.S b/arch/arm/kernel/relocate_kernel.S
index fd26f8d65151..9cf4cbf8f95b 100644
--- a/arch/arm/kernel/relocate_kernel.S
+++ b/arch/arm/kernel/relocate_kernel.S
@@ -59,6 +59,8 @@ relocate_new_kernel:
59 ldr r2,kexec_boot_atags 59 ldr r2,kexec_boot_atags
60 mov pc,lr 60 mov pc,lr
61 61
62 .align
63
62 .globl kexec_start_address 64 .globl kexec_start_address
63kexec_start_address: 65kexec_start_address:
64 .long 0x0 66 .long 0x0
diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c
index 20b7411e47fd..c2e112e1a05f 100644
--- a/arch/arm/kernel/stacktrace.c
+++ b/arch/arm/kernel/stacktrace.c
@@ -28,7 +28,7 @@ int notrace unwind_frame(struct stackframe *frame)
28 28
29 /* only go to a higher address on the stack */ 29 /* only go to a higher address on the stack */
30 low = frame->sp; 30 low = frame->sp;
31 high = ALIGN(low, THREAD_SIZE) + THREAD_SIZE; 31 high = ALIGN(low, THREAD_SIZE);
32 32
33 /* check current frame pointer is within bounds */ 33 /* check current frame pointer is within bounds */
34 if (fp < (low + 12) || fp + 4 >= high) 34 if (fp < (low + 12) || fp + 4 >= high)
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index cda78d59aa31..446aee97436f 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -53,10 +53,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
53void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame) 53void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
54{ 54{
55#ifdef CONFIG_KALLSYMS 55#ifdef CONFIG_KALLSYMS
56 char sym1[KSYM_SYMBOL_LEN], sym2[KSYM_SYMBOL_LEN]; 56 printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
57 sprint_symbol(sym1, where);
58 sprint_symbol(sym2, from);
59 printk("[<%08lx>] (%s) from [<%08lx>] (%s)\n", where, sym1, from, sym2);
60#else 57#else
61 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from); 58 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
62#endif 59#endif
diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c
index 2a161765f6d5..d2cb0b3c9872 100644
--- a/arch/arm/kernel/unwind.c
+++ b/arch/arm/kernel/unwind.c
@@ -279,7 +279,7 @@ int unwind_frame(struct stackframe *frame)
279 279
280 /* only go to a higher address on the stack */ 280 /* only go to a higher address on the stack */
281 low = frame->sp; 281 low = frame->sp;
282 high = ALIGN(low, THREAD_SIZE) + THREAD_SIZE; 282 high = ALIGN(low, THREAD_SIZE);
283 283
284 pr_debug("%s(pc = %08lx lr = %08lx sp = %08lx)\n", __func__, 284 pr_debug("%s(pc = %08lx lr = %08lx sp = %08lx)\n", __func__,
285 frame->pc, frame->lr, frame->sp); 285 frame->pc, frame->lr, frame->sp);
diff --git a/arch/arm/lib/findbit.S b/arch/arm/lib/findbit.S
index 1e4cbd4e7be9..64f6bc1a9132 100644
--- a/arch/arm/lib/findbit.S
+++ b/arch/arm/lib/findbit.S
@@ -174,8 +174,8 @@ ENDPROC(_find_next_bit_be)
174 */ 174 */
175.L_found: 175.L_found:
176#if __LINUX_ARM_ARCH__ >= 5 176#if __LINUX_ARM_ARCH__ >= 5
177 rsb r1, r3, #0 177 rsb r0, r3, #0
178 and r3, r3, r1 178 and r3, r3, r0
179 clz r3, r3 179 clz r3, r3
180 rsb r3, r3, #31 180 rsb r3, r3, #31
181 add r0, r2, r3 181 add r0, r2, r3
@@ -190,5 +190,7 @@ ENDPROC(_find_next_bit_be)
190 addeq r2, r2, #1 190 addeq r2, r2, #1
191 mov r0, r2 191 mov r0, r2
192#endif 192#endif
193 cmp r1, r0 @ Clamp to maxbit
194 movlo r0, r1
193 mov pc, lr 195 mov pc, lr
194 196
diff --git a/arch/arm/mach-aaec2000/include/mach/vmalloc.h b/arch/arm/mach-aaec2000/include/mach/vmalloc.h
index cff4e0a996ce..a6299e8321bd 100644
--- a/arch/arm/mach-aaec2000/include/mach/vmalloc.h
+++ b/arch/arm/mach-aaec2000/include/mach/vmalloc.h
@@ -11,6 +11,6 @@
11#ifndef __ASM_ARCH_VMALLOC_H 11#ifndef __ASM_ARCH_VMALLOC_H
12#define __ASM_ARCH_VMALLOC_H 12#define __ASM_ARCH_VMALLOC_H
13 13
14#define VMALLOC_END 0xd0000000 14#define VMALLOC_END 0xd0000000UL
15 15
16#endif /* __ASM_ARCH_VMALLOC_H */ 16#endif /* __ASM_ARCH_VMALLOC_H */
diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index 821eb842795f..d13add71f72a 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -24,8 +24,8 @@ obj-$(CONFIG_ARCH_AT91X40) += at91x40.o at91x40_time.o
24 24
25# AT91RM9200 board-specific support 25# AT91RM9200 board-specific support
26obj-$(CONFIG_MACH_ONEARM) += board-1arm.o 26obj-$(CONFIG_MACH_ONEARM) += board-1arm.o
27obj-$(CONFIG_ARCH_AT91RM9200DK) += board-dk.o 27obj-$(CONFIG_ARCH_AT91RM9200DK) += board-rm9200dk.o
28obj-$(CONFIG_MACH_AT91RM9200EK) += board-ek.o 28obj-$(CONFIG_MACH_AT91RM9200EK) += board-rm9200ek.o
29obj-$(CONFIG_MACH_CSB337) += board-csb337.o 29obj-$(CONFIG_MACH_CSB337) += board-csb337.o
30obj-$(CONFIG_MACH_CSB637) += board-csb637.o 30obj-$(CONFIG_MACH_CSB637) += board-csb637.o
31obj-$(CONFIG_MACH_CARMEVA) += board-carmeva.o 31obj-$(CONFIG_MACH_CARMEVA) += board-carmeva.o
@@ -65,7 +65,7 @@ obj-$(CONFIG_MACH_AT91SAM9G20EK) += board-sam9g20ek.o
65obj-$(CONFIG_MACH_CPU9G20) += board-cpu9krea.o 65obj-$(CONFIG_MACH_CPU9G20) += board-cpu9krea.o
66obj-$(CONFIG_MACH_STAMP9G20) += board-stamp9g20.o 66obj-$(CONFIG_MACH_STAMP9G20) += board-stamp9g20.o
67obj-$(CONFIG_MACH_PORTUXG20) += board-stamp9g20.o 67obj-$(CONFIG_MACH_PORTUXG20) += board-stamp9g20.o
68obj-$(CONFIG_MACH_PCONTROL_G20) += board-pcontrol-g20.o 68obj-$(CONFIG_MACH_PCONTROL_G20) += board-pcontrol-g20.o board-stamp9g20.o
69 69
70# AT91SAM9260/AT91SAM9G20 board-specific support 70# AT91SAM9260/AT91SAM9G20 board-specific support
71obj-$(CONFIG_MACH_SNAPPER_9260) += board-snapper9260.o 71obj-$(CONFIG_MACH_SNAPPER_9260) += board-snapper9260.o
diff --git a/arch/arm/mach-at91/at91rm9200_devices.c b/arch/arm/mach-at91/at91rm9200_devices.c
index 9338825cfcd7..7b539228e0ef 100644
--- a/arch/arm/mach-at91/at91rm9200_devices.c
+++ b/arch/arm/mach-at91/at91rm9200_devices.c
@@ -1106,51 +1106,6 @@ static inline void configure_usart3_pins(unsigned pins)
1106static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */ 1106static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
1107struct platform_device *atmel_default_console_device; /* the serial console device */ 1107struct platform_device *atmel_default_console_device; /* the serial console device */
1108 1108
1109void __init __deprecated at91_init_serial(struct at91_uart_config *config)
1110{
1111 int i;
1112
1113 /* Fill in list of supported UARTs */
1114 for (i = 0; i < config->nr_tty; i++) {
1115 switch (config->tty_map[i]) {
1116 case 0:
1117 configure_usart0_pins(ATMEL_UART_CTS | ATMEL_UART_RTS);
1118 at91_uarts[i] = &at91rm9200_uart0_device;
1119 at91_clock_associate("usart0_clk", &at91rm9200_uart0_device.dev, "usart");
1120 break;
1121 case 1:
1122 configure_usart1_pins(ATMEL_UART_CTS | ATMEL_UART_RTS | ATMEL_UART_DSR | ATMEL_UART_DTR | ATMEL_UART_DCD | ATMEL_UART_RI);
1123 at91_uarts[i] = &at91rm9200_uart1_device;
1124 at91_clock_associate("usart1_clk", &at91rm9200_uart1_device.dev, "usart");
1125 break;
1126 case 2:
1127 configure_usart2_pins(0);
1128 at91_uarts[i] = &at91rm9200_uart2_device;
1129 at91_clock_associate("usart2_clk", &at91rm9200_uart2_device.dev, "usart");
1130 break;
1131 case 3:
1132 configure_usart3_pins(0);
1133 at91_uarts[i] = &at91rm9200_uart3_device;
1134 at91_clock_associate("usart3_clk", &at91rm9200_uart3_device.dev, "usart");
1135 break;
1136 case 4:
1137 configure_dbgu_pins();
1138 at91_uarts[i] = &at91rm9200_dbgu_device;
1139 at91_clock_associate("mck", &at91rm9200_dbgu_device.dev, "usart");
1140 break;
1141 default:
1142 continue;
1143 }
1144 at91_uarts[i]->id = i; /* update ID number to mapped ID */
1145 }
1146
1147 /* Set serial console device */
1148 if (config->console_tty < ATMEL_MAX_UART)
1149 atmel_default_console_device = at91_uarts[config->console_tty];
1150 if (!atmel_default_console_device)
1151 printk(KERN_INFO "AT91: No default serial console defined.\n");
1152}
1153
1154void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) 1109void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1155{ 1110{
1156 struct platform_device *pdev; 1111 struct platform_device *pdev;
diff --git a/arch/arm/mach-at91/board-1arm.c b/arch/arm/mach-at91/board-1arm.c
index 46bdc82d3fbf..8a3fc84847c1 100644
--- a/arch/arm/mach-at91/board-1arm.c
+++ b/arch/arm/mach-at91/board-1arm.c
@@ -39,24 +39,24 @@
39#include "generic.h" 39#include "generic.h"
40 40
41 41
42/*
43 * Serial port configuration.
44 * 0 .. 3 = USART0 .. USART3
45 * 4 = DBGU
46 */
47static struct at91_uart_config __initdata onearm_uart_config = {
48 .console_tty = 0, /* ttyS0 */
49 .nr_tty = 3,
50 .tty_map = { 4, 0, 1, -1, -1 }, /* ttyS0, ..., ttyS4 */
51};
52
53static void __init onearm_map_io(void) 42static void __init onearm_map_io(void)
54{ 43{
55 /* Initialize processor: 18.432 MHz crystal */ 44 /* Initialize processor: 18.432 MHz crystal */
56 at91rm9200_initialize(18432000, AT91RM9200_PQFP); 45 at91rm9200_initialize(18432000, AT91RM9200_PQFP);
57 46
58 /* Setup the serial ports and console */ 47 /* DBGU on ttyS0. (Rx & Tx only) */
59 at91_init_serial(&onearm_uart_config); 48 at91_register_uart(0, 0, 0);
49
50 /* USART0 on ttyS1 (Rx, Tx, CTS, RTS) */
51 at91_register_uart(AT91RM9200_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS);
52
53 /* USART1 on ttyS2 (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
54 at91_register_uart(AT91RM9200_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS
55 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
56 | ATMEL_UART_RI);
57
58 /* set serial console to ttyS0 (ie, DBGU) */
59 at91_set_serial_console(0);
60} 60}
61 61
62static void __init onearm_init_irq(void) 62static void __init onearm_init_irq(void)
diff --git a/arch/arm/mach-at91/board-kafa.c b/arch/arm/mach-at91/board-kafa.c
index c0ce79d431a0..d2e1f4ec1fcc 100644
--- a/arch/arm/mach-at91/board-kafa.c
+++ b/arch/arm/mach-at91/board-kafa.c
@@ -39,17 +39,6 @@
39#include "generic.h" 39#include "generic.h"
40 40
41 41
42/*
43 * Serial port configuration.
44 * 0 .. 3 = USART0 .. USART3
45 * 4 = DBGU
46 */
47static struct at91_uart_config __initdata kafa_uart_config = {
48 .console_tty = 0, /* ttyS0 */
49 .nr_tty = 2,
50 .tty_map = { 4, 0, -1, -1, -1 } /* ttyS0, ..., ttyS4 */
51};
52
53static void __init kafa_map_io(void) 42static void __init kafa_map_io(void)
54{ 43{
55 /* Initialize processor: 18.432 MHz crystal */ 44 /* Initialize processor: 18.432 MHz crystal */
@@ -58,8 +47,14 @@ static void __init kafa_map_io(void)
58 /* Set up the LEDs */ 47 /* Set up the LEDs */
59 at91_init_leds(AT91_PIN_PB4, AT91_PIN_PB4); 48 at91_init_leds(AT91_PIN_PB4, AT91_PIN_PB4);
60 49
61 /* Setup the serial ports and console */ 50 /* DBGU on ttyS0. (Rx & Tx only) */
62 at91_init_serial(&kafa_uart_config); 51 at91_register_uart(0, 0, 0);
52
53 /* USART0 on ttyS1 (Rx, Tx, CTS, RTS) */
54 at91_register_uart(AT91RM9200_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS);
55
56 /* set serial console to ttyS0 (ie, DBGU) */
57 at91_set_serial_console(0);
63} 58}
64 59
65static void __init kafa_init_irq(void) 60static void __init kafa_init_irq(void)
diff --git a/arch/arm/mach-at91/board-pcontrol-g20.c b/arch/arm/mach-at91/board-pcontrol-g20.c
index bba5a560e02b..feb65787c30b 100644
--- a/arch/arm/mach-at91/board-pcontrol-g20.c
+++ b/arch/arm/mach-at91/board-pcontrol-g20.c
@@ -31,6 +31,7 @@
31 31
32#include <mach/board.h> 32#include <mach/board.h>
33#include <mach/at91sam9_smc.h> 33#include <mach/at91sam9_smc.h>
34#include <mach/stamp9g20.h>
34 35
35#include "sam9_smc.h" 36#include "sam9_smc.h"
36#include "generic.h" 37#include "generic.h"
@@ -38,11 +39,7 @@
38 39
39static void __init pcontrol_g20_map_io(void) 40static void __init pcontrol_g20_map_io(void)
40{ 41{
41 /* Initialize processor: 18.432 MHz crystal */ 42 stamp9g20_map_io();
42 at91sam9260_initialize(18432000);
43
44 /* DGBU on ttyS0. (Rx, Tx) only TTL -> JTAG connector X7 17,19 ) */
45 at91_register_uart(0, 0, 0);
46 43
47 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS) piggyback A2 */ 44 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS) piggyback A2 */
48 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS 45 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS
@@ -54,9 +51,6 @@ static void __init pcontrol_g20_map_io(void)
54 51
55 /* USART2 on ttyS3. (Rx, Tx) 9bit-Bus Multidrop-mode X4 */ 52 /* USART2 on ttyS3. (Rx, Tx) 9bit-Bus Multidrop-mode X4 */
56 at91_register_uart(AT91SAM9260_ID_US4, 3, 0); 53 at91_register_uart(AT91SAM9260_ID_US4, 3, 0);
57
58 /* set serial console to ttyS0 (ie, DBGU) */
59 at91_set_serial_console(0);
60} 54}
61 55
62 56
@@ -66,38 +60,6 @@ static void __init init_irq(void)
66} 60}
67 61
68 62
69/*
70 * NAND flash 512MiB 1,8V 8-bit, sector size 128 KiB
71 */
72static struct atmel_nand_data __initdata nand_data = {
73 .ale = 21,
74 .cle = 22,
75 .rdy_pin = AT91_PIN_PC13,
76 .enable_pin = AT91_PIN_PC14,
77};
78
79/*
80 * Bus timings; unit = 7.57ns
81 */
82static struct sam9_smc_config __initdata nand_smc_config = {
83 .ncs_read_setup = 0,
84 .nrd_setup = 2,
85 .ncs_write_setup = 0,
86 .nwe_setup = 2,
87
88 .ncs_read_pulse = 4,
89 .nrd_pulse = 4,
90 .ncs_write_pulse = 4,
91 .nwe_pulse = 4,
92
93 .read_cycle = 7,
94 .write_cycle = 7,
95
96 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
97 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
98 .tdf_cycles = 3,
99};
100
101static struct sam9_smc_config __initdata pcontrol_smc_config[2] = { { 63static struct sam9_smc_config __initdata pcontrol_smc_config[2] = { {
102 .ncs_read_setup = 16, 64 .ncs_read_setup = 16,
103 .nrd_setup = 18, 65 .nrd_setup = 18,
@@ -138,14 +100,6 @@ static struct sam9_smc_config __initdata pcontrol_smc_config[2] = { {
138 .tdf_cycles = 1, 100 .tdf_cycles = 1,
139} }; 101} };
140 102
141static void __init add_device_nand(void)
142{
143 /* configure chip-select 3 (NAND) */
144 sam9_smc_configure(3, &nand_smc_config);
145 at91_add_device_nand(&nand_data);
146}
147
148
149static void __init add_device_pcontrol(void) 103static void __init add_device_pcontrol(void)
150{ 104{
151 /* configure chip-select 4 (IO compatible to 8051 X4 ) */ 105 /* configure chip-select 4 (IO compatible to 8051 X4 ) */
@@ -156,23 +110,6 @@ static void __init add_device_pcontrol(void)
156 110
157 111
158/* 112/*
159 * MCI (SD/MMC)
160 * det_pin, wp_pin and vcc_pin are not connected
161 */
162#if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
163static struct mci_platform_data __initdata mmc_data = {
164 .slot[0] = {
165 .bus_width = 4,
166 },
167};
168#else
169static struct at91_mmc_data __initdata mmc_data = {
170 .wire4 = 1,
171};
172#endif
173
174
175/*
176 * USB Host port 113 * USB Host port
177 */ 114 */
178static struct at91_usbh_data __initdata usbh_data = { 115static struct at91_usbh_data __initdata usbh_data = {
@@ -265,42 +202,13 @@ static struct spi_board_info pcontrol_g20_spi_devices[] = {
265}; 202};
266 203
267 204
268/*
269 * Dallas 1-Wire DS2431
270 */
271static struct w1_gpio_platform_data w1_gpio_pdata = {
272 .pin = AT91_PIN_PA29,
273 .is_open_drain = 1,
274};
275
276static struct platform_device w1_device = {
277 .name = "w1-gpio",
278 .id = -1,
279 .dev.platform_data = &w1_gpio_pdata,
280};
281
282static void add_wire1(void)
283{
284 at91_set_GPIO_periph(w1_gpio_pdata.pin, 1);
285 at91_set_multi_drive(w1_gpio_pdata.pin, 1);
286 platform_device_register(&w1_device);
287}
288
289
290static void __init pcontrol_g20_board_init(void) 205static void __init pcontrol_g20_board_init(void)
291{ 206{
292 at91_add_device_serial(); 207 stamp9g20_board_init();
293 add_device_nand();
294#if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
295 at91_add_device_mci(0, &mmc_data);
296#else
297 at91_add_device_mmc(0, &mmc_data);
298#endif
299 at91_add_device_usbh(&usbh_data); 208 at91_add_device_usbh(&usbh_data);
300 at91_add_device_eth(&macb_data); 209 at91_add_device_eth(&macb_data);
301 at91_add_device_i2c(pcontrol_g20_i2c_devices, 210 at91_add_device_i2c(pcontrol_g20_i2c_devices,
302 ARRAY_SIZE(pcontrol_g20_i2c_devices)); 211 ARRAY_SIZE(pcontrol_g20_i2c_devices));
303 add_wire1();
304 add_device_pcontrol(); 212 add_device_pcontrol();
305 at91_add_device_spi(pcontrol_g20_spi_devices, 213 at91_add_device_spi(pcontrol_g20_spi_devices,
306 ARRAY_SIZE(pcontrol_g20_spi_devices)); 214 ARRAY_SIZE(pcontrol_g20_spi_devices));
diff --git a/arch/arm/mach-at91/board-picotux200.c b/arch/arm/mach-at91/board-picotux200.c
index 9d833bbc592d..55dad3a46547 100644
--- a/arch/arm/mach-at91/board-picotux200.c
+++ b/arch/arm/mach-at91/board-picotux200.c
@@ -43,24 +43,21 @@
43#include "generic.h" 43#include "generic.h"
44 44
45 45
46/*
47 * Serial port configuration.
48 * 0 .. 3 = USART0 .. USART3
49 * 4 = DBGU
50 */
51static struct at91_uart_config __initdata picotux200_uart_config = {
52 .console_tty = 0, /* ttyS0 */
53 .nr_tty = 2,
54 .tty_map = { 4, 1, -1, -1, -1 } /* ttyS0, ..., ttyS4 */
55};
56
57static void __init picotux200_map_io(void) 46static void __init picotux200_map_io(void)
58{ 47{
59 /* Initialize processor: 18.432 MHz crystal */ 48 /* Initialize processor: 18.432 MHz crystal */
60 at91rm9200_initialize(18432000, AT91RM9200_BGA); 49 at91rm9200_initialize(18432000, AT91RM9200_BGA);
61 50
62 /* Setup the serial ports and console */ 51 /* DBGU on ttyS0. (Rx & Tx only) */
63 at91_init_serial(&picotux200_uart_config); 52 at91_register_uart(0, 0, 0);
53
54 /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
55 at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
56 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
57 | ATMEL_UART_RI);
58
59 /* set serial console to ttyS0 (ie, DBGU) */
60 at91_set_serial_console(0);
64} 61}
65 62
66static void __init picotux200_init_irq(void) 63static void __init picotux200_init_irq(void)
@@ -77,11 +74,6 @@ static struct at91_usbh_data __initdata picotux200_usbh_data = {
77 .ports = 1, 74 .ports = 1,
78}; 75};
79 76
80// static struct at91_udc_data __initdata picotux200_udc_data = {
81// .vbus_pin = AT91_PIN_PD4,
82// .pullup_pin = AT91_PIN_PD5,
83// };
84
85static struct at91_mmc_data __initdata picotux200_mmc_data = { 77static struct at91_mmc_data __initdata picotux200_mmc_data = {
86 .det_pin = AT91_PIN_PB27, 78 .det_pin = AT91_PIN_PB27,
87 .slot_b = 0, 79 .slot_b = 0,
@@ -89,21 +81,6 @@ static struct at91_mmc_data __initdata picotux200_mmc_data = {
89 .wp_pin = AT91_PIN_PA17, 81 .wp_pin = AT91_PIN_PA17,
90}; 82};
91 83
92// static struct spi_board_info picotux200_spi_devices[] = {
93// { /* DataFlash chip */
94// .modalias = "mtd_dataflash",
95// .chip_select = 0,
96// .max_speed_hz = 15 * 1000 * 1000,
97// },
98// #ifdef CONFIG_MTD_AT91_DATAFLASH_CARD
99// { /* DataFlash card */
100// .modalias = "mtd_dataflash",
101// .chip_select = 3,
102// .max_speed_hz = 15 * 1000 * 1000,
103// },
104// #endif
105// };
106
107#define PICOTUX200_FLASH_BASE AT91_CHIPSELECT_0 84#define PICOTUX200_FLASH_BASE AT91_CHIPSELECT_0
108#define PICOTUX200_FLASH_SIZE SZ_4M 85#define PICOTUX200_FLASH_SIZE SZ_4M
109 86
@@ -135,21 +112,11 @@ static void __init picotux200_board_init(void)
135 at91_add_device_eth(&picotux200_eth_data); 112 at91_add_device_eth(&picotux200_eth_data);
136 /* USB Host */ 113 /* USB Host */
137 at91_add_device_usbh(&picotux200_usbh_data); 114 at91_add_device_usbh(&picotux200_usbh_data);
138 /* USB Device */
139 // at91_add_device_udc(&picotux200_udc_data);
140 // at91_set_multi_drive(picotux200_udc_data.pullup_pin, 1); /* pullup_pin is connected to reset */
141 /* I2C */ 115 /* I2C */
142 at91_add_device_i2c(NULL, 0); 116 at91_add_device_i2c(NULL, 0);
143 /* SPI */
144 // at91_add_device_spi(picotux200_spi_devices, ARRAY_SIZE(picotux200_spi_devices));
145#ifdef CONFIG_MTD_AT91_DATAFLASH_CARD
146 /* DataFlash card */
147 at91_set_gpio_output(AT91_PIN_PB22, 0);
148#else
149 /* MMC */ 117 /* MMC */
150 at91_set_gpio_output(AT91_PIN_PB22, 1); /* this MMC card slot can optionally use SPI signaling (CS3). */ 118 at91_set_gpio_output(AT91_PIN_PB22, 1); /* this MMC card slot can optionally use SPI signaling (CS3). */
151 at91_add_device_mmc(0, &picotux200_mmc_data); 119 at91_add_device_mmc(0, &picotux200_mmc_data);
152#endif
153 /* NOR Flash */ 120 /* NOR Flash */
154 platform_device_register(&picotux200_flash); 121 platform_device_register(&picotux200_flash);
155} 122}
diff --git a/arch/arm/mach-at91/board-dk.c b/arch/arm/mach-at91/board-rm9200dk.c
index e14f0e165680..4c1047c8200d 100644
--- a/arch/arm/mach-at91/board-dk.c
+++ b/arch/arm/mach-at91/board-rm9200dk.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/arch/arm/mach-at91/board-dk.c 2 * linux/arch/arm/mach-at91/board-rm9200dk.c
3 * 3 *
4 * Copyright (C) 2005 SAN People 4 * Copyright (C) 2005 SAN People
5 * 5 *
@@ -91,10 +91,12 @@ static struct at91_cf_data __initdata dk_cf_data = {
91 // .vcc_pin = ... always powered 91 // .vcc_pin = ... always powered
92}; 92};
93 93
94#ifndef CONFIG_MTD_AT91_DATAFLASH_CARD
94static struct at91_mmc_data __initdata dk_mmc_data = { 95static struct at91_mmc_data __initdata dk_mmc_data = {
95 .slot_b = 0, 96 .slot_b = 0,
96 .wire4 = 1, 97 .wire4 = 1,
97}; 98};
99#endif
98 100
99static struct spi_board_info dk_spi_devices[] = { 101static struct spi_board_info dk_spi_devices[] = {
100 { /* DataFlash chip */ 102 { /* DataFlash chip */
diff --git a/arch/arm/mach-at91/board-ek.c b/arch/arm/mach-at91/board-rm9200ek.c
index 56e92c4bbc2a..9df1be8818c0 100644
--- a/arch/arm/mach-at91/board-ek.c
+++ b/arch/arm/mach-at91/board-rm9200ek.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/arch/arm/mach-at91/board-ek.c 2 * linux/arch/arm/mach-at91/board-rm9200ek.c
3 * 3 *
4 * Copyright (C) 2005 SAN People 4 * Copyright (C) 2005 SAN People
5 * 5 *
@@ -84,12 +84,14 @@ static struct at91_udc_data __initdata ek_udc_data = {
84 .pullup_pin = AT91_PIN_PD5, 84 .pullup_pin = AT91_PIN_PD5,
85}; 85};
86 86
87#ifndef CONFIG_MTD_AT91_DATAFLASH_CARD
87static struct at91_mmc_data __initdata ek_mmc_data = { 88static struct at91_mmc_data __initdata ek_mmc_data = {
88 .det_pin = AT91_PIN_PB27, 89 .det_pin = AT91_PIN_PB27,
89 .slot_b = 0, 90 .slot_b = 0,
90 .wire4 = 1, 91 .wire4 = 1,
91 .wp_pin = AT91_PIN_PA17, 92 .wp_pin = AT91_PIN_PA17,
92}; 93};
94#endif
93 95
94static struct spi_board_info ek_spi_devices[] = { 96static struct spi_board_info ek_spi_devices[] = {
95 { /* DataFlash chip */ 97 { /* DataFlash chip */
diff --git a/arch/arm/mach-at91/board-stamp9g20.c b/arch/arm/mach-at91/board-stamp9g20.c
index 5206eef4a67e..f8902b118960 100644
--- a/arch/arm/mach-at91/board-stamp9g20.c
+++ b/arch/arm/mach-at91/board-stamp9g20.c
@@ -32,7 +32,7 @@
32#include "generic.h" 32#include "generic.h"
33 33
34 34
35static void __init portuxg20_map_io(void) 35void __init stamp9g20_map_io(void)
36{ 36{
37 /* Initialize processor: 18.432 MHz crystal */ 37 /* Initialize processor: 18.432 MHz crystal */
38 at91sam9260_initialize(18432000); 38 at91sam9260_initialize(18432000);
@@ -40,6 +40,24 @@ static void __init portuxg20_map_io(void)
40 /* DGBU on ttyS0. (Rx & Tx only) */ 40 /* DGBU on ttyS0. (Rx & Tx only) */
41 at91_register_uart(0, 0, 0); 41 at91_register_uart(0, 0, 0);
42 42
43 /* set serial console to ttyS0 (ie, DBGU) */
44 at91_set_serial_console(0);
45}
46
47static void __init stamp9g20evb_map_io(void)
48{
49 stamp9g20_map_io();
50
51 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
52 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
53 | ATMEL_UART_DTR | ATMEL_UART_DSR
54 | ATMEL_UART_DCD | ATMEL_UART_RI);
55}
56
57static void __init portuxg20_map_io(void)
58{
59 stamp9g20_map_io();
60
43 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */ 61 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
44 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS 62 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
45 | ATMEL_UART_DTR | ATMEL_UART_DSR 63 | ATMEL_UART_DTR | ATMEL_UART_DSR
@@ -56,26 +74,6 @@ static void __init portuxg20_map_io(void)
56 74
57 /* USART5 on ttyS6. (Rx, Tx only) */ 75 /* USART5 on ttyS6. (Rx, Tx only) */
58 at91_register_uart(AT91SAM9260_ID_US5, 6, 0); 76 at91_register_uart(AT91SAM9260_ID_US5, 6, 0);
59
60 /* set serial console to ttyS0 (ie, DBGU) */
61 at91_set_serial_console(0);
62}
63
64static void __init stamp9g20_map_io(void)
65{
66 /* Initialize processor: 18.432 MHz crystal */
67 at91sam9260_initialize(18432000);
68
69 /* DGBU on ttyS0. (Rx & Tx only) */
70 at91_register_uart(0, 0, 0);
71
72 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
73 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
74 | ATMEL_UART_DTR | ATMEL_UART_DSR
75 | ATMEL_UART_DCD | ATMEL_UART_RI);
76
77 /* set serial console to ttyS0 (ie, DBGU) */
78 at91_set_serial_console(0);
79} 77}
80 78
81static void __init init_irq(void) 79static void __init init_irq(void)
@@ -156,7 +154,7 @@ static struct at91_udc_data __initdata portuxg20_udc_data = {
156 .pullup_pin = 0, /* pull-up driven by UDC */ 154 .pullup_pin = 0, /* pull-up driven by UDC */
157}; 155};
158 156
159static struct at91_udc_data __initdata stamp9g20_udc_data = { 157static struct at91_udc_data __initdata stamp9g20evb_udc_data = {
160 .vbus_pin = AT91_PIN_PA22, 158 .vbus_pin = AT91_PIN_PA22,
161 .pullup_pin = 0, /* pull-up driven by UDC */ 159 .pullup_pin = 0, /* pull-up driven by UDC */
162}; 160};
@@ -190,7 +188,7 @@ static struct gpio_led portuxg20_leds[] = {
190 } 188 }
191}; 189};
192 190
193static struct gpio_led stamp9g20_leds[] = { 191static struct gpio_led stamp9g20evb_leds[] = {
194 { 192 {
195 .name = "D8", 193 .name = "D8",
196 .gpio = AT91_PIN_PB18, 194 .gpio = AT91_PIN_PB18,
@@ -250,7 +248,7 @@ void add_w1(void)
250} 248}
251 249
252 250
253static void __init generic_board_init(void) 251void __init stamp9g20_board_init(void)
254{ 252{
255 /* Serial */ 253 /* Serial */
256 at91_add_device_serial(); 254 at91_add_device_serial();
@@ -262,34 +260,40 @@ static void __init generic_board_init(void)
262#else 260#else
263 at91_add_device_mmc(0, &mmc_data); 261 at91_add_device_mmc(0, &mmc_data);
264#endif 262#endif
265 /* USB Host */
266 at91_add_device_usbh(&usbh_data);
267 /* Ethernet */
268 at91_add_device_eth(&macb_data);
269 /* I2C */
270 at91_add_device_i2c(NULL, 0);
271 /* W1 */ 263 /* W1 */
272 add_w1(); 264 add_w1();
273} 265}
274 266
275static void __init portuxg20_board_init(void) 267static void __init portuxg20_board_init(void)
276{ 268{
277 generic_board_init(); 269 stamp9g20_board_init();
278 /* SPI */ 270 /* USB Host */
279 at91_add_device_spi(portuxg20_spi_devices, ARRAY_SIZE(portuxg20_spi_devices)); 271 at91_add_device_usbh(&usbh_data);
280 /* USB Device */ 272 /* USB Device */
281 at91_add_device_udc(&portuxg20_udc_data); 273 at91_add_device_udc(&portuxg20_udc_data);
274 /* Ethernet */
275 at91_add_device_eth(&macb_data);
276 /* I2C */
277 at91_add_device_i2c(NULL, 0);
278 /* SPI */
279 at91_add_device_spi(portuxg20_spi_devices, ARRAY_SIZE(portuxg20_spi_devices));
282 /* LEDs */ 280 /* LEDs */
283 at91_gpio_leds(portuxg20_leds, ARRAY_SIZE(portuxg20_leds)); 281 at91_gpio_leds(portuxg20_leds, ARRAY_SIZE(portuxg20_leds));
284} 282}
285 283
286static void __init stamp9g20_board_init(void) 284static void __init stamp9g20evb_board_init(void)
287{ 285{
288 generic_board_init(); 286 stamp9g20_board_init();
287 /* USB Host */
288 at91_add_device_usbh(&usbh_data);
289 /* USB Device */ 289 /* USB Device */
290 at91_add_device_udc(&stamp9g20_udc_data); 290 at91_add_device_udc(&stamp9g20evb_udc_data);
291 /* Ethernet */
292 at91_add_device_eth(&macb_data);
293 /* I2C */
294 at91_add_device_i2c(NULL, 0);
291 /* LEDs */ 295 /* LEDs */
292 at91_gpio_leds(stamp9g20_leds, ARRAY_SIZE(stamp9g20_leds)); 296 at91_gpio_leds(stamp9g20evb_leds, ARRAY_SIZE(stamp9g20evb_leds));
293} 297}
294 298
295MACHINE_START(PORTUXG20, "taskit PortuxG20") 299MACHINE_START(PORTUXG20, "taskit PortuxG20")
@@ -305,7 +309,7 @@ MACHINE_START(STAMP9G20, "taskit Stamp9G20")
305 /* Maintainer: taskit GmbH */ 309 /* Maintainer: taskit GmbH */
306 .boot_params = AT91_SDRAM_BASE + 0x100, 310 .boot_params = AT91_SDRAM_BASE + 0x100,
307 .timer = &at91sam926x_timer, 311 .timer = &at91sam926x_timer,
308 .map_io = stamp9g20_map_io, 312 .map_io = stamp9g20evb_map_io,
309 .init_irq = init_irq, 313 .init_irq = init_irq,
310 .init_machine = stamp9g20_board_init, 314 .init_machine = stamp9g20evb_board_init,
311MACHINE_END 315MACHINE_END
diff --git a/arch/arm/mach-at91/board-yl-9200.c b/arch/arm/mach-at91/board-yl-9200.c
index 89df00a9d2f7..e0f0080eb639 100644
--- a/arch/arm/mach-at91/board-yl-9200.c
+++ b/arch/arm/mach-at91/board-yl-9200.c
@@ -387,7 +387,7 @@ static struct spi_board_info yl9200_spi_devices[] = {
387 * EPSON S1D13806 FB (discontinued chip) 387 * EPSON S1D13806 FB (discontinued chip)
388 * EPSON S1D13506 FB 388 * EPSON S1D13506 FB
389 */ 389 */
390#if defined(CONFIG_FB_S1D135XX) || defined(CONFIG_FB_S1D13XXX_MODULE) 390#if defined(CONFIG_FB_S1D13XXX) || defined(CONFIG_FB_S1D13XXX_MODULE)
391#include <video/s1d13xxxfb.h> 391#include <video/s1d13xxxfb.h>
392 392
393 393
diff --git a/arch/arm/mach-at91/clock.c b/arch/arm/mach-at91/clock.c
index 7525cee3983f..9113da6845f1 100644
--- a/arch/arm/mach-at91/clock.c
+++ b/arch/arm/mach-at91/clock.c
@@ -658,7 +658,7 @@ static void __init at91_upll_usbfs_clock_init(unsigned long main_clock)
658 /* Now set uhpck values */ 658 /* Now set uhpck values */
659 uhpck.parent = &utmi_clk; 659 uhpck.parent = &utmi_clk;
660 uhpck.pmc_mask = AT91SAM926x_PMC_UHP; 660 uhpck.pmc_mask = AT91SAM926x_PMC_UHP;
661 uhpck.rate_hz = utmi_clk.parent->rate_hz; 661 uhpck.rate_hz = utmi_clk.rate_hz;
662 uhpck.rate_hz /= 1 + ((at91_sys_read(AT91_PMC_USB) & AT91_PMC_OHCIUSBDIV) >> 8); 662 uhpck.rate_hz /= 1 + ((at91_sys_read(AT91_PMC_USB) & AT91_PMC_OHCIUSBDIV) >> 8);
663} 663}
664 664
diff --git a/arch/arm/mach-at91/include/mach/board.h b/arch/arm/mach-at91/include/mach/board.h
index 58528aa9c8a8..2b499eb343a1 100644
--- a/arch/arm/mach-at91/include/mach/board.h
+++ b/arch/arm/mach-at91/include/mach/board.h
@@ -137,13 +137,7 @@ extern void __init at91_add_device_spi(struct spi_board_info *devices, int nr_de
137extern void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins); 137extern void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins);
138extern void __init at91_set_serial_console(unsigned portnr); 138extern void __init at91_set_serial_console(unsigned portnr);
139 139
140struct at91_uart_config {
141 unsigned short console_tty; /* tty number of serial console */
142 unsigned short nr_tty; /* number of serial tty's */
143 short tty_map[]; /* map UART to tty number */
144};
145extern struct platform_device *atmel_default_console_device; 140extern struct platform_device *atmel_default_console_device;
146extern void __init __deprecated at91_init_serial(struct at91_uart_config *config);
147 141
148struct atmel_uart_data { 142struct atmel_uart_data {
149 short use_dma_tx; /* use transmit DMA? */ 143 short use_dma_tx; /* use transmit DMA? */
diff --git a/arch/arm/mach-at91/include/mach/stamp9g20.h b/arch/arm/mach-at91/include/mach/stamp9g20.h
new file mode 100644
index 000000000000..6120f9c46d59
--- /dev/null
+++ b/arch/arm/mach-at91/include/mach/stamp9g20.h
@@ -0,0 +1,7 @@
1#ifndef __MACH_STAMP9G20_H
2#define __MACH_STAMP9G20_H
3
4void stamp9g20_map_io(void);
5void stamp9g20_board_init(void);
6
7#endif
diff --git a/arch/arm/mach-bcmring/include/mach/vmalloc.h b/arch/arm/mach-bcmring/include/mach/vmalloc.h
index 3db3a09fd398..7397bd7817d9 100644
--- a/arch/arm/mach-bcmring/include/mach/vmalloc.h
+++ b/arch/arm/mach-bcmring/include/mach/vmalloc.h
@@ -22,4 +22,4 @@
22 * 0xe0000000 to 0xefffffff. This gives us 256 MB of vm space and handles 22 * 0xe0000000 to 0xefffffff. This gives us 256 MB of vm space and handles
23 * larger physical memory designs better. 23 * larger physical memory designs better.
24 */ 24 */
25#define VMALLOC_END 0xf0000000 25#define VMALLOC_END 0xf0000000UL
diff --git a/arch/arm/mach-clps711x/include/mach/vmalloc.h b/arch/arm/mach-clps711x/include/mach/vmalloc.h
index 30b3a287ed88..467b96137e47 100644
--- a/arch/arm/mach-clps711x/include/mach/vmalloc.h
+++ b/arch/arm/mach-clps711x/include/mach/vmalloc.h
@@ -17,4 +17,4 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20#define VMALLOC_END 0xd0000000 20#define VMALLOC_END 0xd0000000UL
diff --git a/arch/arm/mach-cns3xxx/pcie.c b/arch/arm/mach-cns3xxx/pcie.c
index 38088c36936c..78defd71a829 100644
--- a/arch/arm/mach-cns3xxx/pcie.c
+++ b/arch/arm/mach-cns3xxx/pcie.c
@@ -369,7 +369,7 @@ static int __init cns3xxx_pcie_init(void)
369{ 369{
370 int i; 370 int i;
371 371
372 hook_fault_code(16 + 6, cns3xxx_pcie_abort_handler, SIGBUS, 372 hook_fault_code(16 + 6, cns3xxx_pcie_abort_handler, SIGBUS, 0,
373 "imprecise external abort"); 373 "imprecise external abort");
374 374
375 for (i = 0; i < ARRAY_SIZE(cns3xxx_pcie); i++) { 375 for (i = 0; i < ARRAY_SIZE(cns3xxx_pcie); i++) {
diff --git a/arch/arm/mach-davinci/dm355.c b/arch/arm/mach-davinci/dm355.c
index 9be261beae7d..2652af124acd 100644
--- a/arch/arm/mach-davinci/dm355.c
+++ b/arch/arm/mach-davinci/dm355.c
@@ -359,8 +359,8 @@ static struct clk_lookup dm355_clks[] = {
359 CLK(NULL, "uart1", &uart1_clk), 359 CLK(NULL, "uart1", &uart1_clk),
360 CLK(NULL, "uart2", &uart2_clk), 360 CLK(NULL, "uart2", &uart2_clk),
361 CLK("i2c_davinci.1", NULL, &i2c_clk), 361 CLK("i2c_davinci.1", NULL, &i2c_clk),
362 CLK("davinci-asp.0", NULL, &asp0_clk), 362 CLK("davinci-mcbsp.0", NULL, &asp0_clk),
363 CLK("davinci-asp.1", NULL, &asp1_clk), 363 CLK("davinci-mcbsp.1", NULL, &asp1_clk),
364 CLK("davinci_mmc.0", NULL, &mmcsd0_clk), 364 CLK("davinci_mmc.0", NULL, &mmcsd0_clk),
365 CLK("davinci_mmc.1", NULL, &mmcsd1_clk), 365 CLK("davinci_mmc.1", NULL, &mmcsd1_clk),
366 CLK("spi_davinci.0", NULL, &spi0_clk), 366 CLK("spi_davinci.0", NULL, &spi0_clk),
@@ -664,7 +664,7 @@ static struct resource dm355_asp1_resources[] = {
664}; 664};
665 665
666static struct platform_device dm355_asp1_device = { 666static struct platform_device dm355_asp1_device = {
667 .name = "davinci-asp", 667 .name = "davinci-mcbsp",
668 .id = 1, 668 .id = 1,
669 .num_resources = ARRAY_SIZE(dm355_asp1_resources), 669 .num_resources = ARRAY_SIZE(dm355_asp1_resources),
670 .resource = dm355_asp1_resources, 670 .resource = dm355_asp1_resources,
diff --git a/arch/arm/mach-davinci/dm365.c b/arch/arm/mach-davinci/dm365.c
index a12065e87266..c466d710d3c1 100644
--- a/arch/arm/mach-davinci/dm365.c
+++ b/arch/arm/mach-davinci/dm365.c
@@ -459,7 +459,7 @@ static struct clk_lookup dm365_clks[] = {
459 CLK(NULL, "usb", &usb_clk), 459 CLK(NULL, "usb", &usb_clk),
460 CLK("davinci_emac.1", NULL, &emac_clk), 460 CLK("davinci_emac.1", NULL, &emac_clk),
461 CLK("davinci_voicecodec", NULL, &voicecodec_clk), 461 CLK("davinci_voicecodec", NULL, &voicecodec_clk),
462 CLK("davinci-asp.0", NULL, &asp0_clk), 462 CLK("davinci-mcbsp", NULL, &asp0_clk),
463 CLK(NULL, "rto", &rto_clk), 463 CLK(NULL, "rto", &rto_clk),
464 CLK(NULL, "mjcp", &mjcp_clk), 464 CLK(NULL, "mjcp", &mjcp_clk),
465 CLK(NULL, NULL, NULL), 465 CLK(NULL, NULL, NULL),
@@ -922,8 +922,8 @@ static struct resource dm365_asp_resources[] = {
922}; 922};
923 923
924static struct platform_device dm365_asp_device = { 924static struct platform_device dm365_asp_device = {
925 .name = "davinci-asp", 925 .name = "davinci-mcbsp",
926 .id = 0, 926 .id = -1,
927 .num_resources = ARRAY_SIZE(dm365_asp_resources), 927 .num_resources = ARRAY_SIZE(dm365_asp_resources),
928 .resource = dm365_asp_resources, 928 .resource = dm365_asp_resources,
929}; 929};
diff --git a/arch/arm/mach-davinci/dm644x.c b/arch/arm/mach-davinci/dm644x.c
index 0608dd776a16..9a2376b3137c 100644
--- a/arch/arm/mach-davinci/dm644x.c
+++ b/arch/arm/mach-davinci/dm644x.c
@@ -302,7 +302,7 @@ static struct clk_lookup dm644x_clks[] = {
302 CLK("davinci_emac.1", NULL, &emac_clk), 302 CLK("davinci_emac.1", NULL, &emac_clk),
303 CLK("i2c_davinci.1", NULL, &i2c_clk), 303 CLK("i2c_davinci.1", NULL, &i2c_clk),
304 CLK("palm_bk3710", NULL, &ide_clk), 304 CLK("palm_bk3710", NULL, &ide_clk),
305 CLK("davinci-asp", NULL, &asp_clk), 305 CLK("davinci-mcbsp", NULL, &asp_clk),
306 CLK("davinci_mmc.0", NULL, &mmcsd_clk), 306 CLK("davinci_mmc.0", NULL, &mmcsd_clk),
307 CLK(NULL, "spi", &spi_clk), 307 CLK(NULL, "spi", &spi_clk),
308 CLK(NULL, "gpio", &gpio_clk), 308 CLK(NULL, "gpio", &gpio_clk),
@@ -580,7 +580,7 @@ static struct resource dm644x_asp_resources[] = {
580}; 580};
581 581
582static struct platform_device dm644x_asp_device = { 582static struct platform_device dm644x_asp_device = {
583 .name = "davinci-asp", 583 .name = "davinci-mcbsp",
584 .id = -1, 584 .id = -1,
585 .num_resources = ARRAY_SIZE(dm644x_asp_resources), 585 .num_resources = ARRAY_SIZE(dm644x_asp_resources),
586 .resource = dm644x_asp_resources, 586 .resource = dm644x_asp_resources,
diff --git a/arch/arm/mach-ebsa110/include/mach/vmalloc.h b/arch/arm/mach-ebsa110/include/mach/vmalloc.h
index 60bde56fba4c..ea141b7a3e03 100644
--- a/arch/arm/mach-ebsa110/include/mach/vmalloc.h
+++ b/arch/arm/mach-ebsa110/include/mach/vmalloc.h
@@ -7,4 +7,4 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#define VMALLOC_END 0xdf000000 10#define VMALLOC_END 0xdf000000UL
diff --git a/arch/arm/mach-ep93xx/include/mach/dma.h b/arch/arm/mach-ep93xx/include/mach/dma.h
index 3a5961d3f3b1..5e31b2b25da9 100644
--- a/arch/arm/mach-ep93xx/include/mach/dma.h
+++ b/arch/arm/mach-ep93xx/include/mach/dma.h
@@ -1,5 +1,13 @@
1/* 1/**
2 * arch/arm/mach-ep93xx/include/mach/dma.h 2 * DOC: EP93xx DMA M2P memory to peripheral and peripheral to memory engine
3 *
4 * The EP93xx DMA M2P subsystem handles DMA transfers between memory and
5 * peripherals. DMA M2P channels are available for audio, UARTs and IrDA.
6 * See chapter 10 of the EP93xx users guide for full details on the DMA M2P
7 * engine.
8 *
9 * See sound/soc/ep93xx/ep93xx-pcm.c for an example use of the DMA M2P code.
10 *
3 */ 11 */
4 12
5#ifndef __ASM_ARCH_DMA_H 13#ifndef __ASM_ARCH_DMA_H
@@ -8,12 +16,34 @@
8#include <linux/list.h> 16#include <linux/list.h>
9#include <linux/types.h> 17#include <linux/types.h>
10 18
19/**
20 * struct ep93xx_dma_buffer - Information about a buffer to be transferred
21 * using the DMA M2P engine
22 *
23 * @list: Entry in DMA buffer list
24 * @bus_addr: Physical address of the buffer
25 * @size: Size of the buffer in bytes
26 */
11struct ep93xx_dma_buffer { 27struct ep93xx_dma_buffer {
12 struct list_head list; 28 struct list_head list;
13 u32 bus_addr; 29 u32 bus_addr;
14 u16 size; 30 u16 size;
15}; 31};
16 32
33/**
34 * struct ep93xx_dma_m2p_client - Information about a DMA M2P client
35 *
36 * @name: Unique name for this client
37 * @flags: Client flags
38 * @cookie: User data to pass to callback functions
39 * @buffer_started: Non NULL function to call when a transfer is started.
40 * The arguments are the user data cookie and the DMA
41 * buffer which is starting.
42 * @buffer_finished: Non NULL function to call when a transfer is completed.
43 * The arguments are the user data cookie, the DMA buffer
44 * which has completed, and a boolean flag indicating if
45 * the transfer had an error.
46 */
17struct ep93xx_dma_m2p_client { 47struct ep93xx_dma_m2p_client {
18 char *name; 48 char *name;
19 u8 flags; 49 u8 flags;
@@ -24,10 +54,11 @@ struct ep93xx_dma_m2p_client {
24 struct ep93xx_dma_buffer *buf, 54 struct ep93xx_dma_buffer *buf,
25 int bytes, int error); 55 int bytes, int error);
26 56
27 /* Internal to the DMA code. */ 57 /* private: Internal use only */
28 void *channel; 58 void *channel;
29}; 59};
30 60
61/* DMA M2P ports */
31#define EP93XX_DMA_M2P_PORT_I2S1 0x00 62#define EP93XX_DMA_M2P_PORT_I2S1 0x00
32#define EP93XX_DMA_M2P_PORT_I2S2 0x01 63#define EP93XX_DMA_M2P_PORT_I2S2 0x01
33#define EP93XX_DMA_M2P_PORT_AAC1 0x02 64#define EP93XX_DMA_M2P_PORT_AAC1 0x02
@@ -39,18 +70,80 @@ struct ep93xx_dma_m2p_client {
39#define EP93XX_DMA_M2P_PORT_UART3 0x08 70#define EP93XX_DMA_M2P_PORT_UART3 0x08
40#define EP93XX_DMA_M2P_PORT_IRDA 0x09 71#define EP93XX_DMA_M2P_PORT_IRDA 0x09
41#define EP93XX_DMA_M2P_PORT_MASK 0x0f 72#define EP93XX_DMA_M2P_PORT_MASK 0x0f
42#define EP93XX_DMA_M2P_TX 0x00
43#define EP93XX_DMA_M2P_RX 0x10
44#define EP93XX_DMA_M2P_ABORT_ON_ERROR 0x20
45#define EP93XX_DMA_M2P_IGNORE_ERROR 0x40
46#define EP93XX_DMA_M2P_ERROR_MASK 0x60
47 73
48int ep93xx_dma_m2p_client_register(struct ep93xx_dma_m2p_client *m2p); 74/* DMA M2P client flags */
75#define EP93XX_DMA_M2P_TX 0x00 /* Memory to peripheral */
76#define EP93XX_DMA_M2P_RX 0x10 /* Peripheral to memory */
77
78/*
79 * DMA M2P client error handling flags. See the EP93xx users guide
80 * documentation on the DMA M2P CONTROL register for more details
81 */
82#define EP93XX_DMA_M2P_ABORT_ON_ERROR 0x20 /* Abort on peripheral error */
83#define EP93XX_DMA_M2P_IGNORE_ERROR 0x40 /* Ignore peripheral errors */
84#define EP93XX_DMA_M2P_ERROR_MASK 0x60 /* Mask of error bits */
85
86/**
87 * ep93xx_dma_m2p_client_register - Register a client with the DMA M2P
88 * subsystem
89 *
90 * @m2p: Client information to register
91 * returns 0 on success
92 *
93 * The DMA M2P subsystem allocates a channel and an interrupt line for the DMA
94 * client
95 */
96int ep93xx_dma_m2p_client_register(struct ep93xx_dma_m2p_client *m2p);
97
98/**
99 * ep93xx_dma_m2p_client_unregister - Unregister a client from the DMA M2P
100 * subsystem
101 *
102 * @m2p: Client to unregister
103 *
104 * Any transfers currently in progress will be completed in hardware, but
105 * ignored in software.
106 */
49void ep93xx_dma_m2p_client_unregister(struct ep93xx_dma_m2p_client *m2p); 107void ep93xx_dma_m2p_client_unregister(struct ep93xx_dma_m2p_client *m2p);
108
109/**
110 * ep93xx_dma_m2p_submit - Submit a DMA M2P transfer
111 *
112 * @m2p: DMA Client to submit the transfer on
113 * @buf: DMA Buffer to submit
114 *
115 * If the current or next transfer positions are free on the M2P client then
116 * the transfer is started immediately. If not, the transfer is added to the
117 * list of pending transfers. This function must not be called from the
118 * buffer_finished callback for an M2P channel.
119 *
120 */
50void ep93xx_dma_m2p_submit(struct ep93xx_dma_m2p_client *m2p, 121void ep93xx_dma_m2p_submit(struct ep93xx_dma_m2p_client *m2p,
51 struct ep93xx_dma_buffer *buf); 122 struct ep93xx_dma_buffer *buf);
123
124/**
125 * ep93xx_dma_m2p_submit_recursive - Put a DMA transfer on the pending list
126 * for an M2P channel
127 *
128 * @m2p: DMA Client to submit the transfer on
129 * @buf: DMA Buffer to submit
130 *
131 * This function must only be called from the buffer_finished callback for an
132 * M2P channel. It is commonly used to add the next transfer in a chained list
133 * of DMA transfers.
134 */
52void ep93xx_dma_m2p_submit_recursive(struct ep93xx_dma_m2p_client *m2p, 135void ep93xx_dma_m2p_submit_recursive(struct ep93xx_dma_m2p_client *m2p,
53 struct ep93xx_dma_buffer *buf); 136 struct ep93xx_dma_buffer *buf);
137
138/**
139 * ep93xx_dma_m2p_flush - Flush all pending transfers on a DMA M2P client
140 *
141 * @m2p: DMA client to flush transfers on
142 *
143 * Any transfers currently in progress will be completed in hardware, but
144 * ignored in software.
145 *
146 */
54void ep93xx_dma_m2p_flush(struct ep93xx_dma_m2p_client *m2p); 147void ep93xx_dma_m2p_flush(struct ep93xx_dma_m2p_client *m2p);
55 148
56#endif /* __ASM_ARCH_DMA_H */ 149#endif /* __ASM_ARCH_DMA_H */
diff --git a/arch/arm/mach-footbridge/include/mach/vmalloc.h b/arch/arm/mach-footbridge/include/mach/vmalloc.h
index 0ffbb7c85e59..40ba78e5782b 100644
--- a/arch/arm/mach-footbridge/include/mach/vmalloc.h
+++ b/arch/arm/mach-footbridge/include/mach/vmalloc.h
@@ -7,4 +7,4 @@
7 */ 7 */
8 8
9 9
10#define VMALLOC_END 0xf0000000 10#define VMALLOC_END 0xf0000000UL
diff --git a/arch/arm/mach-h720x/include/mach/vmalloc.h b/arch/arm/mach-h720x/include/mach/vmalloc.h
index a45915b88756..8520b4a4d4e6 100644
--- a/arch/arm/mach-h720x/include/mach/vmalloc.h
+++ b/arch/arm/mach-h720x/include/mach/vmalloc.h
@@ -5,6 +5,6 @@
5#ifndef __ARCH_ARM_VMALLOC_H 5#ifndef __ARCH_ARM_VMALLOC_H
6#define __ARCH_ARM_VMALLOC_H 6#define __ARCH_ARM_VMALLOC_H
7 7
8#define VMALLOC_END 0xd0000000 8#define VMALLOC_END 0xd0000000UL
9 9
10#endif 10#endif
diff --git a/arch/arm/mach-imx/eukrea_mbimx27-baseboard.c b/arch/arm/mach-imx/eukrea_mbimx27-baseboard.c
index 026263c665ca..7e1e9dc2c8fc 100644
--- a/arch/arm/mach-imx/eukrea_mbimx27-baseboard.c
+++ b/arch/arm/mach-imx/eukrea_mbimx27-baseboard.c
@@ -250,9 +250,6 @@ static const struct imxuart_platform_data uart_pdata __initconst = {
250 .flags = IMXUART_HAVE_RTSCTS, 250 .flags = IMXUART_HAVE_RTSCTS,
251}; 251};
252 252
253#if defined(CONFIG_TOUCHSCREEN_ADS7846) \
254 || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
255
256#define ADS7846_PENDOWN (GPIO_PORTD | 25) 253#define ADS7846_PENDOWN (GPIO_PORTD | 25)
257 254
258static void ads7846_dev_init(void) 255static void ads7846_dev_init(void)
@@ -273,9 +270,7 @@ static struct ads7846_platform_data ads7846_config __initdata = {
273 .get_pendown_state = ads7846_get_pendown_state, 270 .get_pendown_state = ads7846_get_pendown_state,
274 .keep_vref_on = 1, 271 .keep_vref_on = 1,
275}; 272};
276#endif
277 273
278#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
279static struct spi_board_info eukrea_mbimx27_spi_board_info[] __initdata = { 274static struct spi_board_info eukrea_mbimx27_spi_board_info[] __initdata = {
280 [0] = { 275 [0] = {
281 .modalias = "ads7846", 276 .modalias = "ads7846",
@@ -294,7 +289,6 @@ static const struct spi_imx_master eukrea_mbimx27_spi0_data __initconst = {
294 .chipselect = eukrea_mbimx27_spi_cs, 289 .chipselect = eukrea_mbimx27_spi_cs,
295 .num_chipselect = ARRAY_SIZE(eukrea_mbimx27_spi_cs), 290 .num_chipselect = ARRAY_SIZE(eukrea_mbimx27_spi_cs),
296}; 291};
297#endif
298 292
299static struct i2c_board_info eukrea_mbimx27_i2c_devices[] = { 293static struct i2c_board_info eukrea_mbimx27_i2c_devices[] = {
300 { 294 {
diff --git a/arch/arm/mach-integrator/include/mach/vmalloc.h b/arch/arm/mach-integrator/include/mach/vmalloc.h
index e056e7cf5645..2f5a2bafb11f 100644
--- a/arch/arm/mach-integrator/include/mach/vmalloc.h
+++ b/arch/arm/mach-integrator/include/mach/vmalloc.h
@@ -17,4 +17,4 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20#define VMALLOC_END 0xd0000000 20#define VMALLOC_END 0xd0000000UL
diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
index 51ff23b72d3a..3688123b5ad8 100644
--- a/arch/arm/mach-kirkwood/common.c
+++ b/arch/arm/mach-kirkwood/common.c
@@ -854,10 +854,9 @@ int __init kirkwood_find_tclk(void)
854 854
855 kirkwood_pcie_id(&dev, &rev); 855 kirkwood_pcie_id(&dev, &rev);
856 856
857 if ((dev == MV88F6281_DEV_ID && (rev == MV88F6281_REV_A0 || 857 if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
858 rev == MV88F6281_REV_A1)) || 858 if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
859 (dev == MV88F6282_DEV_ID)) 859 return 200000000;
860 return 200000000;
861 860
862 return 166666667; 861 return 166666667;
863} 862}
diff --git a/arch/arm/mach-kirkwood/d2net_v2-setup.c b/arch/arm/mach-kirkwood/d2net_v2-setup.c
index 4aa86e4a152c..a31c9499ab36 100644
--- a/arch/arm/mach-kirkwood/d2net_v2-setup.c
+++ b/arch/arm/mach-kirkwood/d2net_v2-setup.c
@@ -225,5 +225,5 @@ MACHINE_START(D2NET_V2, "LaCie d2 Network v2")
225 .init_machine = d2net_v2_init, 225 .init_machine = d2net_v2_init,
226 .map_io = kirkwood_map_io, 226 .map_io = kirkwood_map_io,
227 .init_irq = kirkwood_init_irq, 227 .init_irq = kirkwood_init_irq,
228 .timer = &lacie_v2_timer, 228 .timer = &kirkwood_timer,
229MACHINE_END 229MACHINE_END
diff --git a/arch/arm/mach-kirkwood/lacie_v2-common.c b/arch/arm/mach-kirkwood/lacie_v2-common.c
index d3ea1b6c8a02..285edab776e9 100644
--- a/arch/arm/mach-kirkwood/lacie_v2-common.c
+++ b/arch/arm/mach-kirkwood/lacie_v2-common.c
@@ -111,17 +111,3 @@ void __init lacie_v2_hdd_power_init(int hdd_num)
111 pr_err("Failed to power up HDD%d\n", i + 1); 111 pr_err("Failed to power up HDD%d\n", i + 1);
112 } 112 }
113} 113}
114
115/*****************************************************************************
116 * Timer
117 ****************************************************************************/
118
119static void lacie_v2_timer_init(void)
120{
121 kirkwood_tclk = 166666667;
122 orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
123}
124
125struct sys_timer lacie_v2_timer = {
126 .init = lacie_v2_timer_init,
127};
diff --git a/arch/arm/mach-kirkwood/lacie_v2-common.h b/arch/arm/mach-kirkwood/lacie_v2-common.h
index af521315b87b..fc64f578536e 100644
--- a/arch/arm/mach-kirkwood/lacie_v2-common.h
+++ b/arch/arm/mach-kirkwood/lacie_v2-common.h
@@ -13,6 +13,4 @@ void lacie_v2_register_flash(void);
13void lacie_v2_register_i2c_devices(void); 13void lacie_v2_register_i2c_devices(void);
14void lacie_v2_hdd_power_init(int hdd_num); 14void lacie_v2_hdd_power_init(int hdd_num);
15 15
16extern struct sys_timer lacie_v2_timer;
17
18#endif 16#endif
diff --git a/arch/arm/mach-kirkwood/mpp.c b/arch/arm/mach-kirkwood/mpp.c
index 065187d177c6..27901f702feb 100644
--- a/arch/arm/mach-kirkwood/mpp.c
+++ b/arch/arm/mach-kirkwood/mpp.c
@@ -59,7 +59,7 @@ void __init kirkwood_mpp_conf(unsigned int *mpp_list)
59 } 59 }
60 printk("\n"); 60 printk("\n");
61 61
62 while (*mpp_list) { 62 for ( ; *mpp_list; mpp_list++) {
63 unsigned int num = MPP_NUM(*mpp_list); 63 unsigned int num = MPP_NUM(*mpp_list);
64 unsigned int sel = MPP_SEL(*mpp_list); 64 unsigned int sel = MPP_SEL(*mpp_list);
65 int shift, gpio_mode; 65 int shift, gpio_mode;
@@ -88,8 +88,6 @@ void __init kirkwood_mpp_conf(unsigned int *mpp_list)
88 if (sel != 0) 88 if (sel != 0)
89 gpio_mode = 0; 89 gpio_mode = 0;
90 orion_gpio_set_valid(num, gpio_mode); 90 orion_gpio_set_valid(num, gpio_mode);
91
92 mpp_list++;
93 } 91 }
94 92
95 printk(KERN_DEBUG " final MPP regs:"); 93 printk(KERN_DEBUG " final MPP regs:");
diff --git a/arch/arm/mach-kirkwood/netspace_v2-setup.c b/arch/arm/mach-kirkwood/netspace_v2-setup.c
index 5ea66f1f4178..65ee21fd2f3b 100644
--- a/arch/arm/mach-kirkwood/netspace_v2-setup.c
+++ b/arch/arm/mach-kirkwood/netspace_v2-setup.c
@@ -262,7 +262,7 @@ MACHINE_START(NETSPACE_V2, "LaCie Network Space v2")
262 .init_machine = netspace_v2_init, 262 .init_machine = netspace_v2_init,
263 .map_io = kirkwood_map_io, 263 .map_io = kirkwood_map_io,
264 .init_irq = kirkwood_init_irq, 264 .init_irq = kirkwood_init_irq,
265 .timer = &lacie_v2_timer, 265 .timer = &kirkwood_timer,
266MACHINE_END 266MACHINE_END
267#endif 267#endif
268 268
@@ -272,7 +272,7 @@ MACHINE_START(INETSPACE_V2, "LaCie Internet Space v2")
272 .init_machine = netspace_v2_init, 272 .init_machine = netspace_v2_init,
273 .map_io = kirkwood_map_io, 273 .map_io = kirkwood_map_io,
274 .init_irq = kirkwood_init_irq, 274 .init_irq = kirkwood_init_irq,
275 .timer = &lacie_v2_timer, 275 .timer = &kirkwood_timer,
276MACHINE_END 276MACHINE_END
277#endif 277#endif
278 278
@@ -282,6 +282,6 @@ MACHINE_START(NETSPACE_MAX_V2, "LaCie Network Space Max v2")
282 .init_machine = netspace_v2_init, 282 .init_machine = netspace_v2_init,
283 .map_io = kirkwood_map_io, 283 .map_io = kirkwood_map_io,
284 .init_irq = kirkwood_init_irq, 284 .init_irq = kirkwood_init_irq,
285 .timer = &lacie_v2_timer, 285 .timer = &kirkwood_timer,
286MACHINE_END 286MACHINE_END
287#endif 287#endif
diff --git a/arch/arm/mach-kirkwood/netxbig_v2-setup.c b/arch/arm/mach-kirkwood/netxbig_v2-setup.c
index a1b45d501aef..93afd3c8bfd8 100644
--- a/arch/arm/mach-kirkwood/netxbig_v2-setup.c
+++ b/arch/arm/mach-kirkwood/netxbig_v2-setup.c
@@ -403,7 +403,7 @@ MACHINE_START(NET2BIG_V2, "LaCie 2Big Network v2")
403 .init_machine = netxbig_v2_init, 403 .init_machine = netxbig_v2_init,
404 .map_io = kirkwood_map_io, 404 .map_io = kirkwood_map_io,
405 .init_irq = kirkwood_init_irq, 405 .init_irq = kirkwood_init_irq,
406 .timer = &lacie_v2_timer, 406 .timer = &kirkwood_timer,
407MACHINE_END 407MACHINE_END
408#endif 408#endif
409 409
@@ -413,6 +413,6 @@ MACHINE_START(NET5BIG_V2, "LaCie 5Big Network v2")
413 .init_machine = netxbig_v2_init, 413 .init_machine = netxbig_v2_init,
414 .map_io = kirkwood_map_io, 414 .map_io = kirkwood_map_io,
415 .init_irq = kirkwood_init_irq, 415 .init_irq = kirkwood_init_irq,
416 .timer = &lacie_v2_timer, 416 .timer = &kirkwood_timer,
417MACHINE_END 417MACHINE_END
418#endif 418#endif
diff --git a/arch/arm/mach-kirkwood/ts41x-setup.c b/arch/arm/mach-kirkwood/ts41x-setup.c
index 8be09a0ce4ac..3587a281d993 100644
--- a/arch/arm/mach-kirkwood/ts41x-setup.c
+++ b/arch/arm/mach-kirkwood/ts41x-setup.c
@@ -27,6 +27,10 @@
27#include "mpp.h" 27#include "mpp.h"
28#include "tsx1x-common.h" 28#include "tsx1x-common.h"
29 29
30/* for the PCIe reset workaround */
31#include <plat/pcie.h>
32
33
30#define QNAP_TS41X_JUMPER_JP1 45 34#define QNAP_TS41X_JUMPER_JP1 45
31 35
32static struct i2c_board_info __initdata qnap_ts41x_i2c_rtc = { 36static struct i2c_board_info __initdata qnap_ts41x_i2c_rtc = {
@@ -140,8 +144,16 @@ static void __init qnap_ts41x_init(void)
140 144
141static int __init ts41x_pci_init(void) 145static int __init ts41x_pci_init(void)
142{ 146{
143 if (machine_is_ts41x()) 147 if (machine_is_ts41x()) {
148 /*
149 * Without this explicit reset, the PCIe SATA controller
150 * (Marvell 88sx7042/sata_mv) is known to stop working
151 * after a few minutes.
152 */
153 orion_pcie_reset((void __iomem *)PCIE_VIRT_BASE);
154
144 kirkwood_pcie_init(KW_PCIE0); 155 kirkwood_pcie_init(KW_PCIE0);
156 }
145 157
146 return 0; 158 return 0;
147} 159}
diff --git a/arch/arm/mach-mmp/include/mach/cputype.h b/arch/arm/mach-mmp/include/mach/cputype.h
index f43a68b213f1..8a3b56dfd35d 100644
--- a/arch/arm/mach-mmp/include/mach/cputype.h
+++ b/arch/arm/mach-mmp/include/mach/cputype.h
@@ -46,7 +46,8 @@ static inline int cpu_is_pxa910(void)
46#ifdef CONFIG_CPU_MMP2 46#ifdef CONFIG_CPU_MMP2
47static inline int cpu_is_mmp2(void) 47static inline int cpu_is_mmp2(void)
48{ 48{
49 return (((cpu_readid_id() >> 8) & 0xff) == 0x58); 49 return (((read_cpuid_id() >> 8) & 0xff) == 0x58);
50}
50#else 51#else
51#define cpu_is_mmp2() (0) 52#define cpu_is_mmp2() (0)
52#endif 53#endif
diff --git a/arch/arm/mach-mmp/mmp2.c b/arch/arm/mach-mmp/mmp2.c
index daf3993349f8..2e3dd08ccc3f 100644
--- a/arch/arm/mach-mmp/mmp2.c
+++ b/arch/arm/mach-mmp/mmp2.c
@@ -126,7 +126,6 @@ static APBC_CLK(twsi3, MMP2_TWSI3, 0, 26000000);
126static APBC_CLK(twsi4, MMP2_TWSI4, 0, 26000000); 126static APBC_CLK(twsi4, MMP2_TWSI4, 0, 26000000);
127static APBC_CLK(twsi5, MMP2_TWSI5, 0, 26000000); 127static APBC_CLK(twsi5, MMP2_TWSI5, 0, 26000000);
128static APBC_CLK(twsi6, MMP2_TWSI6, 0, 26000000); 128static APBC_CLK(twsi6, MMP2_TWSI6, 0, 26000000);
129static APBC_CLK(rtc, MMP2_RTC, 0, 32768);
130 129
131static APMU_CLK(nand, NAND, 0xbf, 100000000); 130static APMU_CLK(nand, NAND, 0xbf, 100000000);
132 131
diff --git a/arch/arm/mach-msm/include/mach/vmalloc.h b/arch/arm/mach-msm/include/mach/vmalloc.h
index 31a32ad062dc..d138448eff16 100644
--- a/arch/arm/mach-msm/include/mach/vmalloc.h
+++ b/arch/arm/mach-msm/include/mach/vmalloc.h
@@ -16,7 +16,7 @@
16#ifndef __ASM_ARCH_MSM_VMALLOC_H 16#ifndef __ASM_ARCH_MSM_VMALLOC_H
17#define __ASM_ARCH_MSM_VMALLOC_H 17#define __ASM_ARCH_MSM_VMALLOC_H
18 18
19#define VMALLOC_END 0xd0000000 19#define VMALLOC_END 0xd0000000UL
20 20
21#endif 21#endif
22 22
diff --git a/arch/arm/mach-mv78xx0/mpp.c b/arch/arm/mach-mv78xx0/mpp.c
index 354ac514eb89..84db2dfc475c 100644
--- a/arch/arm/mach-mv78xx0/mpp.c
+++ b/arch/arm/mach-mv78xx0/mpp.c
@@ -54,7 +54,7 @@ void __init mv78xx0_mpp_conf(unsigned int *mpp_list)
54 } 54 }
55 printk("\n"); 55 printk("\n");
56 56
57 while (*mpp_list) { 57 for ( ; *mpp_list; mpp_list++) {
58 unsigned int num = MPP_NUM(*mpp_list); 58 unsigned int num = MPP_NUM(*mpp_list);
59 unsigned int sel = MPP_SEL(*mpp_list); 59 unsigned int sel = MPP_SEL(*mpp_list);
60 int shift, gpio_mode; 60 int shift, gpio_mode;
@@ -83,8 +83,6 @@ void __init mv78xx0_mpp_conf(unsigned int *mpp_list)
83 if (sel != 0) 83 if (sel != 0)
84 gpio_mode = 0; 84 gpio_mode = 0;
85 orion_gpio_set_valid(num, gpio_mode); 85 orion_gpio_set_valid(num, gpio_mode);
86
87 mpp_list++;
88 } 86 }
89 87
90 printk(KERN_DEBUG " final MPP regs:"); 88 printk(KERN_DEBUG " final MPP regs:");
diff --git a/arch/arm/mach-mx25/devices-imx25.h b/arch/arm/mach-mx25/devices-imx25.h
index 93afa10b13cf..d94d282fa676 100644
--- a/arch/arm/mach-mx25/devices-imx25.h
+++ b/arch/arm/mach-mx25/devices-imx25.h
@@ -42,9 +42,9 @@ extern const struct imx_mxc_nand_data imx25_mxc_nand_data __initconst;
42#define imx25_add_mxc_nand(pdata) \ 42#define imx25_add_mxc_nand(pdata) \
43 imx_add_mxc_nand(&imx25_mxc_nand_data, pdata) 43 imx_add_mxc_nand(&imx25_mxc_nand_data, pdata)
44 44
45extern const struct imx_spi_imx_data imx25_spi_imx_data[] __initconst; 45extern const struct imx_spi_imx_data imx25_cspi_data[] __initconst;
46#define imx25_add_spi_imx(id, pdata) \ 46#define imx25_add_spi_imx(id, pdata) \
47 imx_add_spi_imx(&imx25_spi_imx_data[id], pdata) 47 imx_add_spi_imx(&imx25_cspi_data[id], pdata)
48#define imx25_add_spi_imx0(pdata) imx25_add_spi_imx(0, pdata) 48#define imx25_add_spi_imx0(pdata) imx25_add_spi_imx(0, pdata)
49#define imx25_add_spi_imx1(pdata) imx25_add_spi_imx(1, pdata) 49#define imx25_add_spi_imx1(pdata) imx25_add_spi_imx(1, pdata)
50#define imx25_add_spi_imx2(pdata) imx25_add_spi_imx(2, pdata) 50#define imx25_add_spi_imx2(pdata) imx25_add_spi_imx(2, pdata)
diff --git a/arch/arm/mach-mx3/mach-pcm037_eet.c b/arch/arm/mach-mx3/mach-pcm037_eet.c
index 99e0894e07db..fda56545d2fd 100644
--- a/arch/arm/mach-mx3/mach-pcm037_eet.c
+++ b/arch/arm/mach-mx3/mach-pcm037_eet.c
@@ -14,6 +14,7 @@
14 14
15#include <mach/common.h> 15#include <mach/common.h>
16#include <mach/iomux-mx3.h> 16#include <mach/iomux-mx3.h>
17#include <mach/spi.h>
17 18
18#include <asm/mach-types.h> 19#include <asm/mach-types.h>
19 20
@@ -59,14 +60,12 @@ static struct spi_board_info pcm037_spi_dev[] = {
59}; 60};
60 61
61/* Platform Data for MXC CSPI */ 62/* Platform Data for MXC CSPI */
62#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
63static int pcm037_spi1_cs[] = {MXC_SPI_CS(1), IOMUX_TO_GPIO(MX31_PIN_KEY_COL7)}; 63static int pcm037_spi1_cs[] = {MXC_SPI_CS(1), IOMUX_TO_GPIO(MX31_PIN_KEY_COL7)};
64 64
65static const struct spi_imx_master pcm037_spi1_pdata __initconst = { 65static const struct spi_imx_master pcm037_spi1_pdata __initconst = {
66 .chipselect = pcm037_spi1_cs, 66 .chipselect = pcm037_spi1_cs,
67 .num_chipselect = ARRAY_SIZE(pcm037_spi1_cs), 67 .num_chipselect = ARRAY_SIZE(pcm037_spi1_cs),
68}; 68};
69#endif
70 69
71/* GPIO-keys input device */ 70/* GPIO-keys input device */
72static struct gpio_keys_button pcm037_gpio_keys[] = { 71static struct gpio_keys_button pcm037_gpio_keys[] = {
@@ -171,7 +170,7 @@ static struct platform_device pcm037_gpio_keys_device = {
171 }, 170 },
172}; 171};
173 172
174static int eet_init_devices(void) 173static int __init eet_init_devices(void)
175{ 174{
176 if (!machine_is_pcm037() || pcm037_variant() != PCM037_EET) 175 if (!machine_is_pcm037() || pcm037_variant() != PCM037_EET)
177 return 0; 176 return 0;
diff --git a/arch/arm/mach-netx/include/mach/vmalloc.h b/arch/arm/mach-netx/include/mach/vmalloc.h
index 7cca3574308f..871f1ef7bff5 100644
--- a/arch/arm/mach-netx/include/mach/vmalloc.h
+++ b/arch/arm/mach-netx/include/mach/vmalloc.h
@@ -16,4 +16,4 @@
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19#define VMALLOC_END 0xd0000000 19#define VMALLOC_END 0xd0000000UL
diff --git a/arch/arm/mach-omap1/devices.c b/arch/arm/mach-omap1/devices.c
index ea0d80a89da7..e7f9ee63dce5 100644
--- a/arch/arm/mach-omap1/devices.c
+++ b/arch/arm/mach-omap1/devices.c
@@ -321,10 +321,9 @@ static struct platform_device omap_wdt_device = {
321static int __init omap_init_wdt(void) 321static int __init omap_init_wdt(void)
322{ 322{
323 if (!cpu_is_omap16xx()) 323 if (!cpu_is_omap16xx())
324 return; 324 return -ENODEV;
325 325
326 platform_device_register(&omap_wdt_device); 326 return platform_device_register(&omap_wdt_device);
327 return 0;
328} 327}
329subsys_initcall(omap_init_wdt); 328subsys_initcall(omap_init_wdt);
330#endif 329#endif
diff --git a/arch/arm/mach-omap1/include/mach/camera.h b/arch/arm/mach-omap1/include/mach/camera.h
index fd54b452eb22..847d00f0bb0a 100644
--- a/arch/arm/mach-omap1/include/mach/camera.h
+++ b/arch/arm/mach-omap1/include/mach/camera.h
@@ -1,6 +1,8 @@
1#ifndef __ASM_ARCH_CAMERA_H_ 1#ifndef __ASM_ARCH_CAMERA_H_
2#define __ASM_ARCH_CAMERA_H_ 2#define __ASM_ARCH_CAMERA_H_
3 3
4#include <media/omap1_camera.h>
5
4void omap1_camera_init(void *); 6void omap1_camera_init(void *);
5 7
6static inline void omap1_set_camera_info(struct omap1_cam_platform_data *info) 8static inline void omap1_set_camera_info(struct omap1_cam_platform_data *info)
diff --git a/arch/arm/mach-omap1/include/mach/vmalloc.h b/arch/arm/mach-omap1/include/mach/vmalloc.h
index b001f67d695b..22ec4a479577 100644
--- a/arch/arm/mach-omap1/include/mach/vmalloc.h
+++ b/arch/arm/mach-omap1/include/mach/vmalloc.h
@@ -17,4 +17,4 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20#define VMALLOC_END 0xd8000000 20#define VMALLOC_END 0xd8000000UL
diff --git a/arch/arm/mach-omap2/board-devkit8000.c b/arch/arm/mach-omap2/board-devkit8000.c
index 067f4379c87f..53ac762518bd 100644
--- a/arch/arm/mach-omap2/board-devkit8000.c
+++ b/arch/arm/mach-omap2/board-devkit8000.c
@@ -242,9 +242,6 @@ static int devkit8000_twl_gpio_setup(struct device *dev,
242 mmc[0].gpio_cd = gpio + 0; 242 mmc[0].gpio_cd = gpio + 0;
243 omap2_hsmmc_init(mmc); 243 omap2_hsmmc_init(mmc);
244 244
245 /* link regulators to MMC adapters */
246 devkit8000_vmmc1_supply.dev = mmc[0].dev;
247
248 /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */ 245 /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
249 gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1; 246 gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
250 247
diff --git a/arch/arm/mach-omap2/board-zoom-peripherals.c b/arch/arm/mach-omap2/board-zoom-peripherals.c
index 86c9b2102952..9db9203667df 100644
--- a/arch/arm/mach-omap2/board-zoom-peripherals.c
+++ b/arch/arm/mach-omap2/board-zoom-peripherals.c
@@ -216,7 +216,7 @@ static struct omap2_hsmmc_info mmc[] __initdata = {
216 { 216 {
217 .name = "wl1271", 217 .name = "wl1271",
218 .mmc = 3, 218 .mmc = 3,
219 .caps = MMC_CAP_4_BIT_DATA, 219 .caps = MMC_CAP_4_BIT_DATA | MMC_CAP_POWER_OFF_CARD,
220 .gpio_wp = -EINVAL, 220 .gpio_wp = -EINVAL,
221 .gpio_cd = -EINVAL, 221 .gpio_cd = -EINVAL,
222 .nonremovable = true, 222 .nonremovable = true,
diff --git a/arch/arm/mach-omap2/include/mach/vmalloc.h b/arch/arm/mach-omap2/include/mach/vmalloc.h
index 4da31e997efe..866319947760 100644
--- a/arch/arm/mach-omap2/include/mach/vmalloc.h
+++ b/arch/arm/mach-omap2/include/mach/vmalloc.h
@@ -17,4 +17,4 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20#define VMALLOC_END 0xf8000000 20#define VMALLOC_END 0xf8000000UL
diff --git a/arch/arm/mach-omap2/io.c b/arch/arm/mach-omap2/io.c
index 40562ddd3ee4..a1939b1e6f82 100644
--- a/arch/arm/mach-omap2/io.c
+++ b/arch/arm/mach-omap2/io.c
@@ -297,7 +297,7 @@ static int __init _omap2_init_reprogram_sdrc(void)
297 return 0; 297 return 0;
298 298
299 dpll3_m2_ck = clk_get(NULL, "dpll3_m2_ck"); 299 dpll3_m2_ck = clk_get(NULL, "dpll3_m2_ck");
300 if (!dpll3_m2_ck) 300 if (IS_ERR(dpll3_m2_ck))
301 return -EINVAL; 301 return -EINVAL;
302 302
303 rate = clk_get_rate(dpll3_m2_ck); 303 rate = clk_get_rate(dpll3_m2_ck);
diff --git a/arch/arm/mach-omap2/pm-debug.c b/arch/arm/mach-omap2/pm-debug.c
index 5e81517a7af2..a8afb610c7d8 100644
--- a/arch/arm/mach-omap2/pm-debug.c
+++ b/arch/arm/mach-omap2/pm-debug.c
@@ -161,6 +161,23 @@ void omap2_pm_dump(int mode, int resume, unsigned int us)
161 printk(KERN_INFO "%-20s: 0x%08x\n", regs[i].name, regs[i].val); 161 printk(KERN_INFO "%-20s: 0x%08x\n", regs[i].name, regs[i].val);
162} 162}
163 163
164void omap2_pm_wakeup_on_timer(u32 seconds, u32 milliseconds)
165{
166 u32 tick_rate, cycles;
167
168 if (!seconds && !milliseconds)
169 return;
170
171 tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gptimer_wakeup));
172 cycles = tick_rate * seconds + tick_rate * milliseconds / 1000;
173 omap_dm_timer_stop(gptimer_wakeup);
174 omap_dm_timer_set_load_start(gptimer_wakeup, 0, 0xffffffff - cycles);
175
176 pr_info("PM: Resume timer in %u.%03u secs"
177 " (%d ticks at %d ticks/sec.)\n",
178 seconds, milliseconds, cycles, tick_rate);
179}
180
164#ifdef CONFIG_DEBUG_FS 181#ifdef CONFIG_DEBUG_FS
165#include <linux/debugfs.h> 182#include <linux/debugfs.h>
166#include <linux/seq_file.h> 183#include <linux/seq_file.h>
@@ -354,23 +371,6 @@ void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
354 pwrdm->timer = t; 371 pwrdm->timer = t;
355} 372}
356 373
357void omap2_pm_wakeup_on_timer(u32 seconds, u32 milliseconds)
358{
359 u32 tick_rate, cycles;
360
361 if (!seconds && !milliseconds)
362 return;
363
364 tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gptimer_wakeup));
365 cycles = tick_rate * seconds + tick_rate * milliseconds / 1000;
366 omap_dm_timer_stop(gptimer_wakeup);
367 omap_dm_timer_set_load_start(gptimer_wakeup, 0, 0xffffffff - cycles);
368
369 pr_info("PM: Resume timer in %u.%03u secs"
370 " (%d ticks at %d ticks/sec.)\n",
371 seconds, milliseconds, cycles, tick_rate);
372}
373
374static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user) 374static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
375{ 375{
376 struct seq_file *s = (struct seq_file *)user; 376 struct seq_file *s = (struct seq_file *)user;
diff --git a/arch/arm/mach-omap2/pm24xx.c b/arch/arm/mach-omap2/pm24xx.c
index aa9764eeb941..f3f3bfa230d7 100644
--- a/arch/arm/mach-omap2/pm24xx.c
+++ b/arch/arm/mach-omap2/pm24xx.c
@@ -30,6 +30,7 @@
30#include <linux/irq.h> 30#include <linux/irq.h>
31#include <linux/time.h> 31#include <linux/time.h>
32#include <linux/gpio.h> 32#include <linux/gpio.h>
33#include <linux/console.h>
33 34
34#include <asm/mach/time.h> 35#include <asm/mach/time.h>
35#include <asm/mach/irq.h> 36#include <asm/mach/irq.h>
@@ -52,6 +53,19 @@
52#include <plat/powerdomain.h> 53#include <plat/powerdomain.h>
53#include <plat/clockdomain.h> 54#include <plat/clockdomain.h>
54 55
56#ifdef CONFIG_SUSPEND
57static suspend_state_t suspend_state = PM_SUSPEND_ON;
58static inline bool is_suspending(void)
59{
60 return (suspend_state != PM_SUSPEND_ON);
61}
62#else
63static inline bool is_suspending(void)
64{
65 return false;
66}
67#endif
68
55static void (*omap2_sram_idle)(void); 69static void (*omap2_sram_idle)(void);
56static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl, 70static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl,
57 void __iomem *sdrc_power); 71 void __iomem *sdrc_power);
@@ -118,6 +132,11 @@ static void omap2_enter_full_retention(void)
118 if (omap_irq_pending()) 132 if (omap_irq_pending())
119 goto no_sleep; 133 goto no_sleep;
120 134
135 /* Block console output in case it is on one of the OMAP UARTs */
136 if (!is_suspending())
137 if (try_acquire_console_sem())
138 goto no_sleep;
139
121 omap_uart_prepare_idle(0); 140 omap_uart_prepare_idle(0);
122 omap_uart_prepare_idle(1); 141 omap_uart_prepare_idle(1);
123 omap_uart_prepare_idle(2); 142 omap_uart_prepare_idle(2);
@@ -131,6 +150,9 @@ static void omap2_enter_full_retention(void)
131 omap_uart_resume_idle(1); 150 omap_uart_resume_idle(1);
132 omap_uart_resume_idle(0); 151 omap_uart_resume_idle(0);
133 152
153 if (!is_suspending())
154 release_console_sem();
155
134no_sleep: 156no_sleep:
135 if (omap2_pm_debug) { 157 if (omap2_pm_debug) {
136 unsigned long long tmp; 158 unsigned long long tmp;
@@ -277,6 +299,12 @@ out:
277 local_irq_enable(); 299 local_irq_enable();
278} 300}
279 301
302static int omap2_pm_begin(suspend_state_t state)
303{
304 suspend_state = state;
305 return 0;
306}
307
280static int omap2_pm_prepare(void) 308static int omap2_pm_prepare(void)
281{ 309{
282 /* We cannot sleep in idle until we have resumed */ 310 /* We cannot sleep in idle until we have resumed */
@@ -326,10 +354,17 @@ static void omap2_pm_finish(void)
326 enable_hlt(); 354 enable_hlt();
327} 355}
328 356
357static void omap2_pm_end(void)
358{
359 suspend_state = PM_SUSPEND_ON;
360}
361
329static const struct platform_suspend_ops omap_pm_ops = { 362static const struct platform_suspend_ops omap_pm_ops = {
363 .begin = omap2_pm_begin,
330 .prepare = omap2_pm_prepare, 364 .prepare = omap2_pm_prepare,
331 .enter = omap2_pm_enter, 365 .enter = omap2_pm_enter,
332 .finish = omap2_pm_finish, 366 .finish = omap2_pm_finish,
367 .end = omap2_pm_end,
333 .valid = suspend_valid_only_mem, 368 .valid = suspend_valid_only_mem,
334}; 369};
335 370
diff --git a/arch/arm/mach-omap2/pm34xx.c b/arch/arm/mach-omap2/pm34xx.c
index 4000c3c8bbd5..0cb20d29f70c 100644
--- a/arch/arm/mach-omap2/pm34xx.c
+++ b/arch/arm/mach-omap2/pm34xx.c
@@ -28,6 +28,7 @@
28#include <linux/clk.h> 28#include <linux/clk.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/console.h>
31 32
32#include <plat/sram.h> 33#include <plat/sram.h>
33#include <plat/clockdomain.h> 34#include <plat/clockdomain.h>
@@ -49,6 +50,19 @@
49#include "sdrc.h" 50#include "sdrc.h"
50#include "control.h" 51#include "control.h"
51 52
53#ifdef CONFIG_SUSPEND
54static suspend_state_t suspend_state = PM_SUSPEND_ON;
55static inline bool is_suspending(void)
56{
57 return (suspend_state != PM_SUSPEND_ON);
58}
59#else
60static inline bool is_suspending(void)
61{
62 return false;
63}
64#endif
65
52/* Scratchpad offsets */ 66/* Scratchpad offsets */
53#define OMAP343X_TABLE_ADDRESS_OFFSET 0xc4 67#define OMAP343X_TABLE_ADDRESS_OFFSET 0xc4
54#define OMAP343X_TABLE_VALUE_OFFSET 0xc0 68#define OMAP343X_TABLE_VALUE_OFFSET 0xc0
@@ -385,6 +399,13 @@ void omap_sram_idle(void)
385 omap3_enable_io_chain(); 399 omap3_enable_io_chain();
386 } 400 }
387 401
402 /* Block console output in case it is on one of the OMAP UARTs */
403 if (!is_suspending())
404 if (per_next_state < PWRDM_POWER_ON ||
405 core_next_state < PWRDM_POWER_ON)
406 if (try_acquire_console_sem())
407 goto console_still_active;
408
388 /* PER */ 409 /* PER */
389 if (per_next_state < PWRDM_POWER_ON) { 410 if (per_next_state < PWRDM_POWER_ON) {
390 omap_uart_prepare_idle(2); 411 omap_uart_prepare_idle(2);
@@ -463,6 +484,10 @@ void omap_sram_idle(void)
463 omap_uart_resume_idle(3); 484 omap_uart_resume_idle(3);
464 } 485 }
465 486
487 if (!is_suspending())
488 release_console_sem();
489
490console_still_active:
466 /* Disable IO-PAD and IO-CHAIN wakeup */ 491 /* Disable IO-PAD and IO-CHAIN wakeup */
467 if (omap3_has_io_wakeup() && 492 if (omap3_has_io_wakeup() &&
468 (per_next_state < PWRDM_POWER_ON || 493 (per_next_state < PWRDM_POWER_ON ||
@@ -504,8 +529,6 @@ out:
504} 529}
505 530
506#ifdef CONFIG_SUSPEND 531#ifdef CONFIG_SUSPEND
507static suspend_state_t suspend_state;
508
509static int omap3_pm_prepare(void) 532static int omap3_pm_prepare(void)
510{ 533{
511 disable_hlt(); 534 disable_hlt();
diff --git a/arch/arm/mach-omap2/prcm-common.h b/arch/arm/mach-omap2/prcm-common.h
index 298a22a754e2..f81acee4738d 100644
--- a/arch/arm/mach-omap2/prcm-common.h
+++ b/arch/arm/mach-omap2/prcm-common.h
@@ -243,13 +243,14 @@
243#define OMAP24XX_EN_GPT1_MASK (1 << 0) 243#define OMAP24XX_EN_GPT1_MASK (1 << 0)
244 244
245/* PM_WKST_WKUP, CM_IDLEST_WKUP shared bits */ 245/* PM_WKST_WKUP, CM_IDLEST_WKUP shared bits */
246#define OMAP24XX_ST_GPIOS_SHIFT (1 << 2) 246#define OMAP24XX_ST_GPIOS_SHIFT 2
247#define OMAP24XX_ST_GPIOS_MASK 2 247#define OMAP24XX_ST_GPIOS_MASK (1 << 2)
248#define OMAP24XX_ST_GPT1_SHIFT (1 << 0) 248#define OMAP24XX_ST_GPT1_SHIFT 0
249#define OMAP24XX_ST_GPT1_MASK 0 249#define OMAP24XX_ST_GPT1_MASK (1 << 0)
250 250
251/* CM_IDLEST_MDM and PM_WKST_MDM shared bits */ 251/* CM_IDLEST_MDM and PM_WKST_MDM shared bits */
252#define OMAP2430_ST_MDM_SHIFT (1 << 0) 252#define OMAP2430_ST_MDM_SHIFT 0
253#define OMAP2430_ST_MDM_MASK (1 << 0)
253 254
254 255
255/* 3430 register bits shared between CM & PRM registers */ 256/* 3430 register bits shared between CM & PRM registers */
diff --git a/arch/arm/mach-omap2/serial.c b/arch/arm/mach-omap2/serial.c
index db79ac68ed97..b1edf78473b6 100644
--- a/arch/arm/mach-omap2/serial.c
+++ b/arch/arm/mach-omap2/serial.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/serial_8250.h> 28#include <linux/serial_8250.h>
29#include <linux/pm_runtime.h> 29#include <linux/pm_runtime.h>
30#include <linux/console.h>
30 31
31#ifdef CONFIG_SERIAL_OMAP 32#ifdef CONFIG_SERIAL_OMAP
32#include <plat/omap-serial.h> 33#include <plat/omap-serial.h>
@@ -406,7 +407,7 @@ void omap_uart_resume_idle(int num)
406 struct omap_uart_state *uart; 407 struct omap_uart_state *uart;
407 408
408 list_for_each_entry(uart, &uart_list, node) { 409 list_for_each_entry(uart, &uart_list, node) {
409 if (num == uart->num) { 410 if (num == uart->num && uart->can_sleep) {
410 omap_uart_enable_clocks(uart); 411 omap_uart_enable_clocks(uart);
411 412
412 /* Check for IO pad wakeup */ 413 /* Check for IO pad wakeup */
@@ -807,6 +808,8 @@ void __init omap_serial_init_port(int port)
807 808
808 oh->dev_attr = uart; 809 oh->dev_attr = uart;
809 810
811 acquire_console_sem(); /* in case the earlycon is on the UART */
812
810 /* 813 /*
811 * Because of early UART probing, UART did not get idled 814 * Because of early UART probing, UART did not get idled
812 * on init. Now that omap_device is ready, ensure full idle 815 * on init. Now that omap_device is ready, ensure full idle
@@ -831,6 +834,8 @@ void __init omap_serial_init_port(int port)
831 omap_uart_block_sleep(uart); 834 omap_uart_block_sleep(uart);
832 uart->timeout = DEFAULT_TIMEOUT; 835 uart->timeout = DEFAULT_TIMEOUT;
833 836
837 release_console_sem();
838
834 if ((cpu_is_omap34xx() && uart->padconf) || 839 if ((cpu_is_omap34xx() && uart->padconf) ||
835 (uart->wk_en && uart->wk_mask)) { 840 (uart->wk_en && uart->wk_mask)) {
836 device_init_wakeup(&od->pdev.dev, true); 841 device_init_wakeup(&od->pdev.dev, true);
diff --git a/arch/arm/mach-orion5x/mpp.c b/arch/arm/mach-orion5x/mpp.c
index bc4c3b9aaf83..db485d3b8144 100644
--- a/arch/arm/mach-orion5x/mpp.c
+++ b/arch/arm/mach-orion5x/mpp.c
@@ -127,7 +127,7 @@ void __init orion5x_mpp_conf(struct orion5x_mpp_mode *mode)
127 /* Initialize gpiolib. */ 127 /* Initialize gpiolib. */
128 orion_gpio_init(); 128 orion_gpio_init();
129 129
130 while (mode->mpp >= 0) { 130 for ( ; mode->mpp >= 0; mode++) {
131 u32 *reg; 131 u32 *reg;
132 int num_type; 132 int num_type;
133 int shift; 133 int shift;
@@ -160,8 +160,6 @@ void __init orion5x_mpp_conf(struct orion5x_mpp_mode *mode)
160 orion_gpio_set_unused(mode->mpp); 160 orion_gpio_set_unused(mode->mpp);
161 161
162 orion_gpio_set_valid(mode->mpp, !!(mode->type == MPP_GPIO)); 162 orion_gpio_set_valid(mode->mpp, !!(mode->type == MPP_GPIO));
163
164 mode++;
165 } 163 }
166 164
167 writel(mpp_0_7_ctrl, MPP_0_7_CTRL); 165 writel(mpp_0_7_ctrl, MPP_0_7_CTRL);
diff --git a/arch/arm/mach-orion5x/ts78xx-setup.c b/arch/arm/mach-orion5x/ts78xx-setup.c
index 16f1bd5324be..c1c1cd04bdde 100644
--- a/arch/arm/mach-orion5x/ts78xx-setup.c
+++ b/arch/arm/mach-orion5x/ts78xx-setup.c
@@ -239,7 +239,7 @@ static struct platform_nand_data ts78xx_ts_nand_data = {
239static struct resource ts78xx_ts_nand_resources = { 239static struct resource ts78xx_ts_nand_resources = {
240 .start = TS_NAND_DATA, 240 .start = TS_NAND_DATA,
241 .end = TS_NAND_DATA + 4, 241 .end = TS_NAND_DATA + 4,
242 .flags = IORESOURCE_IO, 242 .flags = IORESOURCE_MEM,
243}; 243};
244 244
245static struct platform_device ts78xx_ts_nand_device = { 245static struct platform_device ts78xx_ts_nand_device = {
diff --git a/arch/arm/mach-pnx4008/include/mach/vmalloc.h b/arch/arm/mach-pnx4008/include/mach/vmalloc.h
index 31b65ee07b0b..184913c71141 100644
--- a/arch/arm/mach-pnx4008/include/mach/vmalloc.h
+++ b/arch/arm/mach-pnx4008/include/mach/vmalloc.h
@@ -17,4 +17,4 @@
17 * The vmalloc() routines leaves a hole of 4kB between each vmalloced 17 * The vmalloc() routines leaves a hole of 4kB between each vmalloced
18 * area for the same reason. ;) 18 * area for the same reason. ;)
19 */ 19 */
20#define VMALLOC_END 0xd0000000 20#define VMALLOC_END 0xd0000000UL
diff --git a/arch/arm/mach-pxa/cm-x2xx.c b/arch/arm/mach-pxa/cm-x2xx.c
index ac5598ce9724..d34b99febeb9 100644
--- a/arch/arm/mach-pxa/cm-x2xx.c
+++ b/arch/arm/mach-pxa/cm-x2xx.c
@@ -476,8 +476,6 @@ static void __init cmx2xx_init(void)
476 476
477static void __init cmx2xx_init_irq(void) 477static void __init cmx2xx_init_irq(void)
478{ 478{
479 pxa27x_init_irq();
480
481 if (cpu_is_pxa25x()) { 479 if (cpu_is_pxa25x()) {
482 pxa25x_init_irq(); 480 pxa25x_init_irq();
483 cmx2xx_pci_init_irq(CMX255_GPIO_IT8152_IRQ); 481 cmx2xx_pci_init_irq(CMX255_GPIO_IT8152_IRQ);
diff --git a/arch/arm/mach-pxa/palmtx.c b/arch/arm/mach-pxa/palmtx.c
index d2060a1d1d68..e5c9932b7588 100644
--- a/arch/arm/mach-pxa/palmtx.c
+++ b/arch/arm/mach-pxa/palmtx.c
@@ -241,7 +241,8 @@ static inline void palmtx_keys_init(void) {}
241/****************************************************************************** 241/******************************************************************************
242 * NAND Flash 242 * NAND Flash
243 ******************************************************************************/ 243 ******************************************************************************/
244#if defined(CONFIG_MTD_NAND_GPIO) || defined(CONFIG_MTD_NAND_GPIO_MODULE) 244#if defined(CONFIG_MTD_NAND_PLATFORM) || \
245 defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
245static void palmtx_nand_cmd_ctl(struct mtd_info *mtd, int cmd, 246static void palmtx_nand_cmd_ctl(struct mtd_info *mtd, int cmd,
246 unsigned int ctrl) 247 unsigned int ctrl)
247{ 248{
diff --git a/arch/arm/mach-pxa/saar.c b/arch/arm/mach-pxa/saar.c
index 4b521e045d75..ffa50e633ee6 100644
--- a/arch/arm/mach-pxa/saar.c
+++ b/arch/arm/mach-pxa/saar.c
@@ -116,7 +116,7 @@ static struct platform_device smc91x_device = {
116 }, 116 },
117}; 117};
118 118
119#if defined(CONFIG_FB_PXA) || (CONFIG_FB_PXA_MODULE) 119#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
120static uint16_t lcd_power_on[] = { 120static uint16_t lcd_power_on[] = {
121 /* single frame */ 121 /* single frame */
122 SMART_CMD_NOOP, 122 SMART_CMD_NOOP,
diff --git a/arch/arm/mach-realview/headsmp.S b/arch/arm/mach-realview/headsmp.S
index 4075473cf68a..b34be4554d40 100644
--- a/arch/arm/mach-realview/headsmp.S
+++ b/arch/arm/mach-realview/headsmp.S
@@ -35,5 +35,6 @@ pen: ldr r7, [r6]
35 */ 35 */
36 b secondary_startup 36 b secondary_startup
37 37
38 .align
381: .long . 391: .long .
39 .long pen_release 40 .long pen_release
diff --git a/arch/arm/mach-rpc/include/mach/vmalloc.h b/arch/arm/mach-rpc/include/mach/vmalloc.h
index 3bcd86fadb81..fb700228637a 100644
--- a/arch/arm/mach-rpc/include/mach/vmalloc.h
+++ b/arch/arm/mach-rpc/include/mach/vmalloc.h
@@ -7,4 +7,4 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#define VMALLOC_END 0xdc000000 10#define VMALLOC_END 0xdc000000UL
diff --git a/arch/arm/mach-s3c2410/h1940-bluetooth.c b/arch/arm/mach-s3c2410/h1940-bluetooth.c
index 8aa2f1902a94..6b86a722a7db 100644
--- a/arch/arm/mach-s3c2410/h1940-bluetooth.c
+++ b/arch/arm/mach-s3c2410/h1940-bluetooth.c
@@ -77,13 +77,13 @@ static int __devinit h1940bt_probe(struct platform_device *pdev)
77 77
78 /* Configures BT serial port GPIOs */ 78 /* Configures BT serial port GPIOs */
79 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0); 79 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
80 s3c_gpio_cfgpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE); 80 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
81 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT); 81 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
82 s3c_gpio_cfgpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE); 82 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
83 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0); 83 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
84 s3c_gpio_cfgpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE); 84 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
85 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0); 85 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
86 s3c_gpio_cfgpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE); 86 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
87 87
88 88
89 rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH, 89 rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
diff --git a/arch/arm/mach-s3c2412/Kconfig b/arch/arm/mach-s3c2412/Kconfig
index cef6a65637bd..6983cb4d4cae 100644
--- a/arch/arm/mach-s3c2412/Kconfig
+++ b/arch/arm/mach-s3c2412/Kconfig
@@ -16,7 +16,7 @@ config CPU_S3C2412
16config CPU_S3C2412_ONLY 16config CPU_S3C2412_ONLY
17 bool 17 bool
18 depends on ARCH_S3C2410 && !CPU_S3C2400 && !CPU_S3C2410 && \ 18 depends on ARCH_S3C2410 && !CPU_S3C2400 && !CPU_S3C2410 && \
19 !CPU_2416 && !CPU_S3C2440 && !CPU_S3C2442 && \ 19 !CPU_S3C2416 && !CPU_S3C2440 && !CPU_S3C2442 && \
20 !CPU_S3C2443 && CPU_S3C2412 20 !CPU_S3C2443 && CPU_S3C2412
21 default y if CPU_S3C2412 21 default y if CPU_S3C2412
22 22
@@ -28,9 +28,16 @@ config S3C2412_DMA
28 28
29config S3C2412_PM 29config S3C2412_PM
30 bool 30 bool
31 select S3C2412_PM_SLEEP
31 help 32 help
32 Internal config node to apply S3C2412 power management 33 Internal config node to apply S3C2412 power management
33 34
35config S3C2412_PM_SLEEP
36 bool
37 help
38 Internal config node to apply sleep for S3C2412 power management.
39 Can be selected by another SoCs with similar sleep procedure.
40
34# Note, the S3C2412 IOtiming support is in plat-s3c24xx 41# Note, the S3C2412 IOtiming support is in plat-s3c24xx
35 42
36config S3C2412_CPUFREQ 43config S3C2412_CPUFREQ
diff --git a/arch/arm/mach-s3c2412/Makefile b/arch/arm/mach-s3c2412/Makefile
index 530ec46cbaea..6c48a91ea39e 100644
--- a/arch/arm/mach-s3c2412/Makefile
+++ b/arch/arm/mach-s3c2412/Makefile
@@ -14,7 +14,8 @@ obj-$(CONFIG_CPU_S3C2412) += irq.o
14obj-$(CONFIG_CPU_S3C2412) += clock.o 14obj-$(CONFIG_CPU_S3C2412) += clock.o
15obj-$(CONFIG_CPU_S3C2412) += gpio.o 15obj-$(CONFIG_CPU_S3C2412) += gpio.o
16obj-$(CONFIG_S3C2412_DMA) += dma.o 16obj-$(CONFIG_S3C2412_DMA) += dma.o
17obj-$(CONFIG_S3C2412_PM) += pm.o sleep.o 17obj-$(CONFIG_S3C2412_PM) += pm.o
18obj-$(CONFIG_S3C2412_PM_SLEEP) += sleep.o
18obj-$(CONFIG_S3C2412_CPUFREQ) += cpu-freq.o 19obj-$(CONFIG_S3C2412_CPUFREQ) += cpu-freq.o
19 20
20# Machine support 21# Machine support
diff --git a/arch/arm/mach-s3c2416/Kconfig b/arch/arm/mach-s3c2416/Kconfig
index 87b9c9f003bd..df8d14974c90 100644
--- a/arch/arm/mach-s3c2416/Kconfig
+++ b/arch/arm/mach-s3c2416/Kconfig
@@ -27,6 +27,7 @@ config S3C2416_DMA
27 27
28config S3C2416_PM 28config S3C2416_PM
29 bool 29 bool
30 select S3C2412_PM_SLEEP
30 help 31 help
31 Internal config node to apply S3C2416 power management 32 Internal config node to apply S3C2416 power management
32 33
@@ -35,9 +36,12 @@ menu "S3C2416 Machines"
35config MACH_SMDK2416 36config MACH_SMDK2416
36 bool "SMDK2416" 37 bool "SMDK2416"
37 select CPU_S3C2416 38 select CPU_S3C2416
39 select MACH_SMDK
38 select S3C_DEV_FB 40 select S3C_DEV_FB
39 select S3C_DEV_HSMMC 41 select S3C_DEV_HSMMC
40 select S3C_DEV_HSMMC1 42 select S3C_DEV_HSMMC1
43 select S3C_DEV_NAND
44 select S3C_DEV_USB_HOST
41 select S3C2416_PM if PM 45 select S3C2416_PM if PM
42 help 46 help
43 Say Y here if you are using an SMDK2416 47 Say Y here if you are using an SMDK2416
diff --git a/arch/arm/mach-s3c2416/irq.c b/arch/arm/mach-s3c2416/irq.c
index 084d121f368c..00174daf1526 100644
--- a/arch/arm/mach-s3c2416/irq.c
+++ b/arch/arm/mach-s3c2416/irq.c
@@ -168,12 +168,11 @@ static struct irq_chip s3c2416_irq_dma = {
168 168
169static void s3c2416_irq_demux_uart3(unsigned int irq, struct irq_desc *desc) 169static void s3c2416_irq_demux_uart3(unsigned int irq, struct irq_desc *desc)
170{ 170{
171 s3c2416_irq_demux(IRQ_S3C2443_UART3, 3); 171 s3c2416_irq_demux(IRQ_S3C2443_RX3, 3);
172} 172}
173 173
174#define INTMSK_UART3 (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0)) 174#define INTMSK_UART3 (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0))
175#define SUBMSK_UART3 (0xf << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0))) 175#define SUBMSK_UART3 (0x7 << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0)))
176
177 176
178static void s3c2416_irq_uart3_mask(unsigned int irqno) 177static void s3c2416_irq_uart3_mask(unsigned int irqno)
179{ 178{
diff --git a/arch/arm/mach-s3c2440/Kconfig b/arch/arm/mach-s3c2440/Kconfig
index ff024a6c0f85..a0cb2581894f 100644
--- a/arch/arm/mach-s3c2440/Kconfig
+++ b/arch/arm/mach-s3c2440/Kconfig
@@ -18,6 +18,7 @@ config CPU_S3C2440
18config CPU_S3C2442 18config CPU_S3C2442
19 bool 19 bool
20 select CPU_ARM920T 20 select CPU_ARM920T
21 select S3C_GPIO_PULL_DOWN
21 select S3C2410_CLOCK 22 select S3C2410_CLOCK
22 select S3C2410_GPIO 23 select S3C2410_GPIO
23 select S3C2410_PM if PM 24 select S3C2410_PM if PM
@@ -178,6 +179,9 @@ config MACH_MINI2440
178 bool "MINI2440 development board" 179 bool "MINI2440 development board"
179 select CPU_S3C2440 180 select CPU_S3C2440
180 select EEPROM_AT24 181 select EEPROM_AT24
182 select NEW_LEDS
183 select LEDS_CLASS
184 select LEDS_TRIGGER
181 select LEDS_TRIGGER_BACKLIGHT 185 select LEDS_TRIGGER_BACKLIGHT
182 select S3C_DEV_NAND 186 select S3C_DEV_NAND
183 select S3C_DEV_USB_HOST 187 select S3C_DEV_USB_HOST
diff --git a/arch/arm/mach-s3c2440/s3c2440.c b/arch/arm/mach-s3c2440/s3c2440.c
index d50f3ae6173d..f7663f731ea0 100644
--- a/arch/arm/mach-s3c2440/s3c2440.c
+++ b/arch/arm/mach-s3c2440/s3c2440.c
@@ -46,9 +46,6 @@ int __init s3c2440_init(void)
46{ 46{
47 printk("S3C2440: Initialising architecture\n"); 47 printk("S3C2440: Initialising architecture\n");
48 48
49 s3c24xx_gpiocfg_default.set_pull = s3c_gpio_setpull_1up;
50 s3c24xx_gpiocfg_default.get_pull = s3c_gpio_getpull_1up;
51
52 /* change irq for watchdog */ 49 /* change irq for watchdog */
53 50
54 s3c_device_wdt.resource[1].start = IRQ_S3C2440_WDT; 51 s3c_device_wdt.resource[1].start = IRQ_S3C2440_WDT;
@@ -58,3 +55,11 @@ int __init s3c2440_init(void)
58 55
59 return sysdev_register(&s3c2440_sysdev); 56 return sysdev_register(&s3c2440_sysdev);
60} 57}
58
59void __init s3c2440_map_io(void)
60{
61 s3c244x_map_io();
62
63 s3c24xx_gpiocfg_default.set_pull = s3c_gpio_setpull_1up;
64 s3c24xx_gpiocfg_default.get_pull = s3c_gpio_getpull_1up;
65}
diff --git a/arch/arm/mach-s3c2440/s3c2442.c b/arch/arm/mach-s3c2440/s3c2442.c
index 188ad1e57dc0..ecf813546554 100644
--- a/arch/arm/mach-s3c2440/s3c2442.c
+++ b/arch/arm/mach-s3c2440/s3c2442.c
@@ -32,6 +32,7 @@
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/ioport.h> 33#include <linux/ioport.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/gpio.h>
35#include <linux/clk.h> 36#include <linux/clk.h>
36#include <linux/io.h> 37#include <linux/io.h>
37 38
@@ -43,6 +44,11 @@
43 44
44#include <plat/clock.h> 45#include <plat/clock.h>
45#include <plat/cpu.h> 46#include <plat/cpu.h>
47#include <plat/s3c244x.h>
48
49#include <plat/gpio-core.h>
50#include <plat/gpio-cfg.h>
51#include <plat/gpio-cfg-helpers.h>
46 52
47/* S3C2442 extended clock support */ 53/* S3C2442 extended clock support */
48 54
@@ -163,3 +169,11 @@ int __init s3c2442_init(void)
163 169
164 return sysdev_register(&s3c2442_sysdev); 170 return sysdev_register(&s3c2442_sysdev);
165} 171}
172
173void __init s3c2442_map_io(void)
174{
175 s3c244x_map_io();
176
177 s3c24xx_gpiocfg_default.set_pull = s3c_gpio_setpull_1down;
178 s3c24xx_gpiocfg_default.get_pull = s3c_gpio_getpull_1down;
179}
diff --git a/arch/arm/mach-s3c2443/Kconfig b/arch/arm/mach-s3c2443/Kconfig
index 4fef723126fa..31babec90cec 100644
--- a/arch/arm/mach-s3c2443/Kconfig
+++ b/arch/arm/mach-s3c2443/Kconfig
@@ -5,6 +5,7 @@
5config CPU_S3C2443 5config CPU_S3C2443
6 bool 6 bool
7 depends on ARCH_S3C2410 7 depends on ARCH_S3C2410
8 select CPU_ARM920T
8 select S3C2443_DMA if S3C2410_DMA 9 select S3C2443_DMA if S3C2410_DMA
9 select CPU_LLSERIAL_S3C2440 10 select CPU_LLSERIAL_S3C2440
10 select SAMSUNG_CLKSRC 11 select SAMSUNG_CLKSRC
diff --git a/arch/arm/mach-s3c2443/irq.c b/arch/arm/mach-s3c2443/irq.c
index 0e0d693f3974..893424767ce1 100644
--- a/arch/arm/mach-s3c2443/irq.c
+++ b/arch/arm/mach-s3c2443/irq.c
@@ -166,12 +166,11 @@ static struct irq_chip s3c2443_irq_dma = {
166 166
167static void s3c2443_irq_demux_uart3(unsigned int irq, struct irq_desc *desc) 167static void s3c2443_irq_demux_uart3(unsigned int irq, struct irq_desc *desc)
168{ 168{
169 s3c2443_irq_demux(IRQ_S3C2443_UART3, 3); 169 s3c2443_irq_demux(IRQ_S3C2443_RX3, 3);
170} 170}
171 171
172#define INTMSK_UART3 (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0)) 172#define INTMSK_UART3 (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0))
173#define SUBMSK_UART3 (0xf << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0))) 173#define SUBMSK_UART3 (0x7 << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0)))
174
175 174
176static void s3c2443_irq_uart3_mask(unsigned int irqno) 175static void s3c2443_irq_uart3_mask(unsigned int irqno)
177{ 176{
diff --git a/arch/arm/mach-s3c64xx/Kconfig b/arch/arm/mach-s3c64xx/Kconfig
index 1ca7bdc6485c..579d2f0f4dd0 100644
--- a/arch/arm/mach-s3c64xx/Kconfig
+++ b/arch/arm/mach-s3c64xx/Kconfig
@@ -143,7 +143,7 @@ config MACH_SMDK6410
143 select S3C_DEV_USB_HSOTG 143 select S3C_DEV_USB_HSOTG
144 select S3C_DEV_WDT 144 select S3C_DEV_WDT
145 select SAMSUNG_DEV_KEYPAD 145 select SAMSUNG_DEV_KEYPAD
146 select HAVE_S3C2410_WATCHDOG 146 select HAVE_S3C2410_WATCHDOG if WATCHDOG
147 select S3C64XX_SETUP_SDHCI 147 select S3C64XX_SETUP_SDHCI
148 select S3C64XX_SETUP_I2C1 148 select S3C64XX_SETUP_I2C1
149 select S3C64XX_SETUP_IDE 149 select S3C64XX_SETUP_IDE
diff --git a/arch/arm/mach-s3c64xx/mach-mini6410.c b/arch/arm/mach-s3c64xx/mach-mini6410.c
index 249c62956471..89f35e02e883 100644
--- a/arch/arm/mach-s3c64xx/mach-mini6410.c
+++ b/arch/arm/mach-s3c64xx/mach-mini6410.c
@@ -45,7 +45,7 @@
45 45
46#include <video/platform_lcd.h> 46#include <video/platform_lcd.h>
47 47
48#define UCON (S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK) 48#define UCON S3C2410_UCON_DEFAULT
49#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB) 49#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
50#define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE) 50#define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
51 51
diff --git a/arch/arm/mach-s3c64xx/mach-real6410.c b/arch/arm/mach-s3c64xx/mach-real6410.c
index f9ef9b5c5f5a..4957ab0a0d4a 100644
--- a/arch/arm/mach-s3c64xx/mach-real6410.c
+++ b/arch/arm/mach-s3c64xx/mach-real6410.c
@@ -46,7 +46,7 @@
46 46
47#include <video/platform_lcd.h> 47#include <video/platform_lcd.h>
48 48
49#define UCON (S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK) 49#define UCON S3C2410_UCON_DEFAULT
50#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB) 50#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
51#define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE) 51#define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
52 52
diff --git a/arch/arm/mach-s5pv210/mach-aquila.c b/arch/arm/mach-s5pv210/mach-aquila.c
index 28677caf3613..461aa035afc0 100644
--- a/arch/arm/mach-s5pv210/mach-aquila.c
+++ b/arch/arm/mach-s5pv210/mach-aquila.c
@@ -378,6 +378,12 @@ static struct max8998_regulator_data aquila_regulators[] = {
378static struct max8998_platform_data aquila_max8998_pdata = { 378static struct max8998_platform_data aquila_max8998_pdata = {
379 .num_regulators = ARRAY_SIZE(aquila_regulators), 379 .num_regulators = ARRAY_SIZE(aquila_regulators),
380 .regulators = aquila_regulators, 380 .regulators = aquila_regulators,
381 .buck1_set1 = S5PV210_GPH0(3),
382 .buck1_set2 = S5PV210_GPH0(4),
383 .buck2_set3 = S5PV210_GPH0(5),
384 .buck1_max_voltage1 = 1200000,
385 .buck1_max_voltage2 = 1200000,
386 .buck2_max_voltage = 1200000,
381}; 387};
382#endif 388#endif
383 389
diff --git a/arch/arm/mach-s5pv210/mach-goni.c b/arch/arm/mach-s5pv210/mach-goni.c
index b1dcf964a768..e22d5112fd44 100644
--- a/arch/arm/mach-s5pv210/mach-goni.c
+++ b/arch/arm/mach-s5pv210/mach-goni.c
@@ -518,6 +518,12 @@ static struct max8998_regulator_data goni_regulators[] = {
518static struct max8998_platform_data goni_max8998_pdata = { 518static struct max8998_platform_data goni_max8998_pdata = {
519 .num_regulators = ARRAY_SIZE(goni_regulators), 519 .num_regulators = ARRAY_SIZE(goni_regulators),
520 .regulators = goni_regulators, 520 .regulators = goni_regulators,
521 .buck1_set1 = S5PV210_GPH0(3),
522 .buck1_set2 = S5PV210_GPH0(4),
523 .buck2_set3 = S5PV210_GPH0(5),
524 .buck1_max_voltage1 = 1200000,
525 .buck1_max_voltage2 = 1200000,
526 .buck2_max_voltage = 1200000,
521}; 527};
522#endif 528#endif
523 529
diff --git a/arch/arm/mach-s5pv210/mach-smdkc110.c b/arch/arm/mach-s5pv210/mach-smdkc110.c
index 0ad7924fe62e..5dd1681c069e 100644
--- a/arch/arm/mach-s5pv210/mach-smdkc110.c
+++ b/arch/arm/mach-s5pv210/mach-smdkc110.c
@@ -13,6 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/serial_core.h> 14#include <linux/serial_core.h>
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/sysdev.h>
16 17
17#include <asm/mach/arch.h> 18#include <asm/mach/arch.h>
18#include <asm/mach/map.h> 19#include <asm/mach/map.h>
diff --git a/arch/arm/mach-s5pv210/mach-smdkv210.c b/arch/arm/mach-s5pv210/mach-smdkv210.c
index bcd7a5d53401..1fbc45b2a432 100644
--- a/arch/arm/mach-s5pv210/mach-smdkv210.c
+++ b/arch/arm/mach-s5pv210/mach-smdkv210.c
@@ -13,6 +13,7 @@
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/serial_core.h> 15#include <linux/serial_core.h>
16#include <linux/sysdev.h>
16 17
17#include <asm/mach/arch.h> 18#include <asm/mach/arch.h>
18#include <asm/mach/map.h> 19#include <asm/mach/map.h>
diff --git a/arch/arm/mach-shark/include/mach/vmalloc.h b/arch/arm/mach-shark/include/mach/vmalloc.h
index 8e845b6a7cb5..b10df988526d 100644
--- a/arch/arm/mach-shark/include/mach/vmalloc.h
+++ b/arch/arm/mach-shark/include/mach/vmalloc.h
@@ -1,4 +1,4 @@
1/* 1/*
2 * arch/arm/mach-shark/include/mach/vmalloc.h 2 * arch/arm/mach-shark/include/mach/vmalloc.h
3 */ 3 */
4#define VMALLOC_END 0xd0000000 4#define VMALLOC_END 0xd0000000UL
diff --git a/arch/arm/mach-shmobile/Kconfig b/arch/arm/mach-shmobile/Kconfig
index 54b479c35ee0..51dcd59eda6a 100644
--- a/arch/arm/mach-shmobile/Kconfig
+++ b/arch/arm/mach-shmobile/Kconfig
@@ -116,4 +116,6 @@ endmenu
116config SH_CLK_CPG 116config SH_CLK_CPG
117 bool 117 bool
118 118
119source "drivers/sh/Kconfig"
120
119endif 121endif
diff --git a/arch/arm/mach-shmobile/board-ap4evb.c b/arch/arm/mach-shmobile/board-ap4evb.c
index 46ca4d4abf91..d440e5f456ad 100644
--- a/arch/arm/mach-shmobile/board-ap4evb.c
+++ b/arch/arm/mach-shmobile/board-ap4evb.c
@@ -163,11 +163,13 @@ static struct mtd_partition nor_flash_partitions[] = {
163 .name = "loader", 163 .name = "loader",
164 .offset = 0x00000000, 164 .offset = 0x00000000,
165 .size = 512 * 1024, 165 .size = 512 * 1024,
166 .mask_flags = MTD_WRITEABLE,
166 }, 167 },
167 { 168 {
168 .name = "bootenv", 169 .name = "bootenv",
169 .offset = MTDPART_OFS_APPEND, 170 .offset = MTDPART_OFS_APPEND,
170 .size = 512 * 1024, 171 .size = 512 * 1024,
172 .mask_flags = MTD_WRITEABLE,
171 }, 173 },
172 { 174 {
173 .name = "kernel_ro", 175 .name = "kernel_ro",
@@ -565,12 +567,143 @@ static struct platform_device *qhd_devices[] __initdata = {
565 567
566/* FSI */ 568/* FSI */
567#define IRQ_FSI evt2irq(0x1840) 569#define IRQ_FSI evt2irq(0x1840)
570static int __fsi_set_rate(struct clk *clk, long rate, int enable)
571{
572 int ret = 0;
573
574 if (rate <= 0)
575 return ret;
576
577 if (enable) {
578 ret = clk_set_rate(clk, rate);
579 if (0 == ret)
580 ret = clk_enable(clk);
581 } else {
582 clk_disable(clk);
583 }
584
585 return ret;
586}
587
588static int __fsi_set_round_rate(struct clk *clk, long rate, int enable)
589{
590 return __fsi_set_rate(clk, clk_round_rate(clk, rate), enable);
591}
592
593static int fsi_ak4642_set_rate(struct device *dev, int rate, int enable)
594{
595 struct clk *fsia_ick;
596 struct clk *fsiack;
597 int ret = -EIO;
598
599 fsia_ick = clk_get(dev, "icka");
600 if (IS_ERR(fsia_ick))
601 return PTR_ERR(fsia_ick);
602
603 /*
604 * FSIACK is connected to AK4642,
605 * and use external clock pin from it.
606 * it is parent of fsia_ick now.
607 */
608 fsiack = clk_get_parent(fsia_ick);
609 if (!fsiack)
610 goto fsia_ick_out;
611
612 /*
613 * we get 1/1 divided clock by setting same rate to fsiack and fsia_ick
614 *
615 ** FIXME **
616 * Because the freq_table of external clk (fsiack) are all 0,
617 * the return value of clk_round_rate became 0.
618 * So, it use __fsi_set_rate here.
619 */
620 ret = __fsi_set_rate(fsiack, rate, enable);
621 if (ret < 0)
622 goto fsiack_out;
623
624 ret = __fsi_set_round_rate(fsia_ick, rate, enable);
625 if ((ret < 0) && enable)
626 __fsi_set_round_rate(fsiack, rate, 0); /* disable FSI ACK */
627
628fsiack_out:
629 clk_put(fsiack);
630
631fsia_ick_out:
632 clk_put(fsia_ick);
633
634 return 0;
635}
636
637static int fsi_hdmi_set_rate(struct device *dev, int rate, int enable)
638{
639 struct clk *fsib_clk;
640 struct clk *fdiv_clk = &sh7372_fsidivb_clk;
641 long fsib_rate = 0;
642 long fdiv_rate = 0;
643 int ackmd_bpfmd;
644 int ret;
645
646 switch (rate) {
647 case 44100:
648 fsib_rate = rate * 256;
649 ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
650 break;
651 case 48000:
652 fsib_rate = 85428000; /* around 48kHz x 256 x 7 */
653 fdiv_rate = rate * 256;
654 ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
655 break;
656 default:
657 pr_err("unsupported rate in FSI2 port B\n");
658 return -EINVAL;
659 }
660
661 /* FSI B setting */
662 fsib_clk = clk_get(dev, "ickb");
663 if (IS_ERR(fsib_clk))
664 return -EIO;
665
666 ret = __fsi_set_round_rate(fsib_clk, fsib_rate, enable);
667 clk_put(fsib_clk);
668 if (ret < 0)
669 return ret;
670
671 /* FSI DIV setting */
672 ret = __fsi_set_round_rate(fdiv_clk, fdiv_rate, enable);
673 if (ret < 0) {
674 /* disable FSI B */
675 if (enable)
676 __fsi_set_round_rate(fsib_clk, fsib_rate, 0);
677 return ret;
678 }
679
680 return ackmd_bpfmd;
681}
682
683static int fsi_set_rate(struct device *dev, int is_porta, int rate, int enable)
684{
685 int ret;
686
687 if (is_porta)
688 ret = fsi_ak4642_set_rate(dev, rate, enable);
689 else
690 ret = fsi_hdmi_set_rate(dev, rate, enable);
691
692 return ret;
693}
694
568static struct sh_fsi_platform_info fsi_info = { 695static struct sh_fsi_platform_info fsi_info = {
569 .porta_flags = SH_FSI_BRS_INV | 696 .porta_flags = SH_FSI_BRS_INV |
570 SH_FSI_OUT_SLAVE_MODE | 697 SH_FSI_OUT_SLAVE_MODE |
571 SH_FSI_IN_SLAVE_MODE | 698 SH_FSI_IN_SLAVE_MODE |
572 SH_FSI_OFMT(PCM) | 699 SH_FSI_OFMT(PCM) |
573 SH_FSI_IFMT(PCM), 700 SH_FSI_IFMT(PCM),
701
702 .portb_flags = SH_FSI_BRS_INV |
703 SH_FSI_BRM_INV |
704 SH_FSI_LRS_INV |
705 SH_FSI_OFMT(SPDIF),
706 .set_rate = fsi_set_rate,
574}; 707};
575 708
576static struct resource fsi_resources[] = { 709static struct resource fsi_resources[] = {
@@ -634,6 +767,7 @@ static struct platform_device lcdc1_device = {
634static struct sh_mobile_hdmi_info hdmi_info = { 767static struct sh_mobile_hdmi_info hdmi_info = {
635 .lcd_chan = &sh_mobile_lcdc1_info.ch[0], 768 .lcd_chan = &sh_mobile_lcdc1_info.ch[0],
636 .lcd_dev = &lcdc1_device.dev, 769 .lcd_dev = &lcdc1_device.dev,
770 .flags = HDMI_SND_SRC_SPDIF,
637}; 771};
638 772
639static struct resource hdmi_resources[] = { 773static struct resource hdmi_resources[] = {
@@ -835,6 +969,11 @@ static int __init hdmi_init_pm_clock(void)
835 goto out; 969 goto out;
836 } 970 }
837 971
972 ret = clk_enable(&sh7372_pllc2_clk);
973 if (ret < 0) {
974 pr_err("Cannot enable pllc2 clock\n");
975 goto out;
976 }
838 pr_debug("PLLC2 set frequency %lu\n", rate); 977 pr_debug("PLLC2 set frequency %lu\n", rate);
839 978
840 ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk); 979 ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
@@ -851,23 +990,11 @@ out:
851 990
852device_initcall(hdmi_init_pm_clock); 991device_initcall(hdmi_init_pm_clock);
853 992
854#define FSIACK_DUMMY_RATE 48000
855static int __init fsi_init_pm_clock(void) 993static int __init fsi_init_pm_clock(void)
856{ 994{
857 struct clk *fsia_ick; 995 struct clk *fsia_ick;
858 int ret; 996 int ret;
859 997
860 /*
861 * FSIACK is connected to AK4642,
862 * and the rate is depend on playing sound rate.
863 * So, set dummy rate (= 48k) here
864 */
865 ret = clk_set_rate(&sh7372_fsiack_clk, FSIACK_DUMMY_RATE);
866 if (ret < 0) {
867 pr_err("Cannot set FSIACK dummy rate: %d\n", ret);
868 return ret;
869 }
870
871 fsia_ick = clk_get(&fsi_device.dev, "icka"); 998 fsia_ick = clk_get(&fsi_device.dev, "icka");
872 if (IS_ERR(fsia_ick)) { 999 if (IS_ERR(fsia_ick)) {
873 ret = PTR_ERR(fsia_ick); 1000 ret = PTR_ERR(fsia_ick);
@@ -876,16 +1003,9 @@ static int __init fsi_init_pm_clock(void)
876 } 1003 }
877 1004
878 ret = clk_set_parent(fsia_ick, &sh7372_fsiack_clk); 1005 ret = clk_set_parent(fsia_ick, &sh7372_fsiack_clk);
879 if (ret < 0) {
880 pr_err("Cannot set FSI-A parent: %d\n", ret);
881 goto out;
882 }
883
884 ret = clk_set_rate(fsia_ick, FSIACK_DUMMY_RATE);
885 if (ret < 0) 1006 if (ret < 0)
886 pr_err("Cannot set FSI-A rate: %d\n", ret); 1007 pr_err("Cannot set FSI-A parent: %d\n", ret);
887 1008
888out:
889 clk_put(fsia_ick); 1009 clk_put(fsia_ick);
890 1010
891 return ret; 1011 return ret;
@@ -992,6 +1112,7 @@ static void __init ap4evb_map_io(void)
992 1112
993#define GPIO_PORT9CR 0xE6051009 1113#define GPIO_PORT9CR 0xE6051009
994#define GPIO_PORT10CR 0xE605100A 1114#define GPIO_PORT10CR 0xE605100A
1115#define USCCR1 0xE6058144
995static void __init ap4evb_init(void) 1116static void __init ap4evb_init(void)
996{ 1117{
997 u32 srcr4; 1118 u32 srcr4;
@@ -1062,7 +1183,7 @@ static void __init ap4evb_init(void)
1062 /* setup USB phy */ 1183 /* setup USB phy */
1063 __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */ 1184 __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
1064 1185
1065 /* enable FSI2 */ 1186 /* enable FSI2 port A (ak4643) */
1066 gpio_request(GPIO_FN_FSIAIBT, NULL); 1187 gpio_request(GPIO_FN_FSIAIBT, NULL);
1067 gpio_request(GPIO_FN_FSIAILR, NULL); 1188 gpio_request(GPIO_FN_FSIAILR, NULL);
1068 gpio_request(GPIO_FN_FSIAISLD, NULL); 1189 gpio_request(GPIO_FN_FSIAISLD, NULL);
@@ -1079,6 +1200,10 @@ static void __init ap4evb_init(void)
1079 gpio_request(GPIO_PORT41, NULL); 1200 gpio_request(GPIO_PORT41, NULL);
1080 gpio_direction_input(GPIO_PORT41); 1201 gpio_direction_input(GPIO_PORT41);
1081 1202
1203 /* setup FSI2 port B (HDMI) */
1204 gpio_request(GPIO_FN_FSIBCK, NULL);
1205 __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
1206
1082 /* set SPU2 clock to 119.6 MHz */ 1207 /* set SPU2 clock to 119.6 MHz */
1083 clk = clk_get(NULL, "spu_clk"); 1208 clk = clk_get(NULL, "spu_clk");
1084 if (!IS_ERR(clk)) { 1209 if (!IS_ERR(clk)) {
diff --git a/arch/arm/mach-shmobile/clock-sh7372.c b/arch/arm/mach-shmobile/clock-sh7372.c
index 8565aefa21fd..3aa026069435 100644
--- a/arch/arm/mach-shmobile/clock-sh7372.c
+++ b/arch/arm/mach-shmobile/clock-sh7372.c
@@ -50,6 +50,9 @@
50#define SMSTPCR3 0xe615013c 50#define SMSTPCR3 0xe615013c
51#define SMSTPCR4 0xe6150140 51#define SMSTPCR4 0xe6150140
52 52
53#define FSIDIVA 0xFE1F8000
54#define FSIDIVB 0xFE1F8008
55
53/* Platforms must set frequency on their DV_CLKI pin */ 56/* Platforms must set frequency on their DV_CLKI pin */
54struct clk sh7372_dv_clki_clk = { 57struct clk sh7372_dv_clki_clk = {
55}; 58};
@@ -217,8 +220,7 @@ static void pllc2_disable(struct clk *clk)
217 __raw_writel(__raw_readl(PLLC2CR) & ~0x80000000, PLLC2CR); 220 __raw_writel(__raw_readl(PLLC2CR) & ~0x80000000, PLLC2CR);
218} 221}
219 222
220static int pllc2_set_rate(struct clk *clk, 223static int pllc2_set_rate(struct clk *clk, unsigned long rate)
221 unsigned long rate, int algo_id)
222{ 224{
223 unsigned long value; 225 unsigned long value;
224 int idx; 226 int idx;
@@ -227,21 +229,13 @@ static int pllc2_set_rate(struct clk *clk,
227 if (idx < 0) 229 if (idx < 0)
228 return idx; 230 return idx;
229 231
230 if (rate == clk->parent->rate) { 232 if (rate == clk->parent->rate)
231 pllc2_disable(clk); 233 return -EINVAL;
232 return 0;
233 }
234 234
235 value = __raw_readl(PLLC2CR) & ~(0x3f << 24); 235 value = __raw_readl(PLLC2CR) & ~(0x3f << 24);
236 236
237 if (value & 0x80000000)
238 pllc2_disable(clk);
239
240 __raw_writel((value & ~0x80000000) | ((idx + 19) << 24), PLLC2CR); 237 __raw_writel((value & ~0x80000000) | ((idx + 19) << 24), PLLC2CR);
241 238
242 if (value & 0x80000000)
243 return pllc2_enable(clk);
244
245 return 0; 239 return 0;
246} 240}
247 241
@@ -288,6 +282,7 @@ struct clk sh7372_pllc2_clk = {
288 .ops = &pllc2_clk_ops, 282 .ops = &pllc2_clk_ops,
289 .parent = &extal1_div2_clk, 283 .parent = &extal1_div2_clk,
290 .freq_table = pllc2_freq_table, 284 .freq_table = pllc2_freq_table,
285 .nr_freqs = ARRAY_SIZE(pllc2_freq_table) - 1,
291 .parent_table = pllc2_parent, 286 .parent_table = pllc2_parent,
292 .parent_num = ARRAY_SIZE(pllc2_parent), 287 .parent_num = ARRAY_SIZE(pllc2_parent),
293}; 288};
@@ -417,6 +412,93 @@ static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = {
417 fsibckcr_parent, ARRAY_SIZE(fsibckcr_parent), 6, 2), 412 fsibckcr_parent, ARRAY_SIZE(fsibckcr_parent), 6, 2),
418}; 413};
419 414
415/* FSI DIV */
416static unsigned long fsidiv_recalc(struct clk *clk)
417{
418 unsigned long value;
419
420 value = __raw_readl(clk->mapping->base);
421
422 if ((value & 0x3) != 0x3)
423 return 0;
424
425 value >>= 16;
426 if (value < 2)
427 return 0;
428
429 return clk->parent->rate / value;
430}
431
432static long fsidiv_round_rate(struct clk *clk, unsigned long rate)
433{
434 return clk_rate_div_range_round(clk, 2, 0xffff, rate);
435}
436
437static void fsidiv_disable(struct clk *clk)
438{
439 __raw_writel(0, clk->mapping->base);
440}
441
442static int fsidiv_enable(struct clk *clk)
443{
444 unsigned long value;
445
446 value = __raw_readl(clk->mapping->base) >> 16;
447 if (value < 2)
448 return -EIO;
449
450 __raw_writel((value << 16) | 0x3, clk->mapping->base);
451
452 return 0;
453}
454
455static int fsidiv_set_rate(struct clk *clk, unsigned long rate)
456{
457 int idx;
458
459 idx = (clk->parent->rate / rate) & 0xffff;
460 if (idx < 2)
461 return -EINVAL;
462
463 __raw_writel(idx << 16, clk->mapping->base);
464 return 0;
465}
466
467static struct clk_ops fsidiv_clk_ops = {
468 .recalc = fsidiv_recalc,
469 .round_rate = fsidiv_round_rate,
470 .set_rate = fsidiv_set_rate,
471 .enable = fsidiv_enable,
472 .disable = fsidiv_disable,
473};
474
475static struct clk_mapping sh7372_fsidiva_clk_mapping = {
476 .phys = FSIDIVA,
477 .len = 8,
478};
479
480struct clk sh7372_fsidiva_clk = {
481 .ops = &fsidiv_clk_ops,
482 .parent = &div6_reparent_clks[DIV6_FSIA], /* late install */
483 .mapping = &sh7372_fsidiva_clk_mapping,
484};
485
486static struct clk_mapping sh7372_fsidivb_clk_mapping = {
487 .phys = FSIDIVB,
488 .len = 8,
489};
490
491struct clk sh7372_fsidivb_clk = {
492 .ops = &fsidiv_clk_ops,
493 .parent = &div6_reparent_clks[DIV6_FSIB], /* late install */
494 .mapping = &sh7372_fsidivb_clk_mapping,
495};
496
497static struct clk *late_main_clks[] = {
498 &sh7372_fsidiva_clk,
499 &sh7372_fsidivb_clk,
500};
501
420enum { MSTP001, 502enum { MSTP001,
421 MSTP131, MSTP130, 503 MSTP131, MSTP130,
422 MSTP129, MSTP128, MSTP127, MSTP126, MSTP125, 504 MSTP129, MSTP128, MSTP127, MSTP126, MSTP125,
@@ -510,8 +592,6 @@ static struct clk_lookup lookups[] = {
510 CLKDEV_CON_ID("vck3_clk", &div6_clks[DIV6_VCK3]), 592 CLKDEV_CON_ID("vck3_clk", &div6_clks[DIV6_VCK3]),
511 CLKDEV_CON_ID("fmsi_clk", &div6_clks[DIV6_FMSI]), 593 CLKDEV_CON_ID("fmsi_clk", &div6_clks[DIV6_FMSI]),
512 CLKDEV_CON_ID("fmso_clk", &div6_clks[DIV6_FMSO]), 594 CLKDEV_CON_ID("fmso_clk", &div6_clks[DIV6_FMSO]),
513 CLKDEV_CON_ID("fsia_clk", &div6_reparent_clks[DIV6_FSIA]),
514 CLKDEV_CON_ID("fsib_clk", &div6_reparent_clks[DIV6_FSIB]),
515 CLKDEV_CON_ID("sub_clk", &div6_clks[DIV6_SUB]), 595 CLKDEV_CON_ID("sub_clk", &div6_clks[DIV6_SUB]),
516 CLKDEV_CON_ID("spu_clk", &div6_clks[DIV6_SPU]), 596 CLKDEV_CON_ID("spu_clk", &div6_clks[DIV6_SPU]),
517 CLKDEV_CON_ID("vou_clk", &div6_clks[DIV6_VOU]), 597 CLKDEV_CON_ID("vou_clk", &div6_clks[DIV6_VOU]),
@@ -548,8 +628,8 @@ static struct clk_lookup lookups[] = {
548 CLKDEV_DEV_ID("sh_cmt.10", &mstp_clks[MSTP329]), /* CMT10 */ 628 CLKDEV_DEV_ID("sh_cmt.10", &mstp_clks[MSTP329]), /* CMT10 */
549 CLKDEV_DEV_ID("sh_fsi2", &mstp_clks[MSTP328]), /* FSI2 */ 629 CLKDEV_DEV_ID("sh_fsi2", &mstp_clks[MSTP328]), /* FSI2 */
550 CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]), /* IIC1 */ 630 CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]), /* IIC1 */
551 CLKDEV_DEV_ID("r8a66597_hcd.0", &mstp_clks[MSTP323]), /* USB0 */ 631 CLKDEV_DEV_ID("r8a66597_hcd.0", &mstp_clks[MSTP322]), /* USB0 */
552 CLKDEV_DEV_ID("r8a66597_udc.0", &mstp_clks[MSTP323]), /* USB0 */ 632 CLKDEV_DEV_ID("r8a66597_udc.0", &mstp_clks[MSTP322]), /* USB0 */
553 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]), /* SDHI0 */ 633 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]), /* SDHI0 */
554 CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]), /* SDHI1 */ 634 CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]), /* SDHI1 */
555 CLKDEV_DEV_ID("sh_mmcif.0", &mstp_clks[MSTP312]), /* MMC */ 635 CLKDEV_DEV_ID("sh_mmcif.0", &mstp_clks[MSTP312]), /* MMC */
@@ -585,6 +665,9 @@ void __init sh7372_clock_init(void)
585 if (!ret) 665 if (!ret)
586 ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR); 666 ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
587 667
668 for (k = 0; !ret && (k < ARRAY_SIZE(late_main_clks)); k++)
669 ret = clk_register(late_main_clks[k]);
670
588 clkdev_add_table(lookups, ARRAY_SIZE(lookups)); 671 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
589 672
590 if (!ret) 673 if (!ret)
diff --git a/arch/arm/mach-shmobile/include/mach/entry-macro.S b/arch/arm/mach-shmobile/include/mach/entry-macro.S
index a285d13c7416..f428c4db2b60 100644
--- a/arch/arm/mach-shmobile/include/mach/entry-macro.S
+++ b/arch/arm/mach-shmobile/include/mach/entry-macro.S
@@ -1,4 +1,5 @@
1/* 1/*
2 * Copyright (C) 2010 Magnus Damm
2 * Copyright (C) 2008 Renesas Solutions Corp. 3 * Copyright (C) 2008 Renesas Solutions Corp.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
@@ -14,24 +15,45 @@
14 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */ 17 */
17#include <mach/hardware.h>
18#include <mach/irqs.h> 18#include <mach/irqs.h>
19 19
20#define INTCA_BASE 0xe6980000
21#define INTFLGA_OFFS 0x00000018 /* accept pending interrupt */
22#define INTEVTA_OFFS 0x00000020 /* vector number of accepted interrupt */
23#define INTLVLA_OFFS 0x00000030 /* priority level of accepted interrupt */
24#define INTLVLB_OFFS 0x00000034 /* previous priority level */
25
20 .macro disable_fiq 26 .macro disable_fiq
21 .endm 27 .endm
22 28
23 .macro get_irqnr_preamble, base, tmp 29 .macro get_irqnr_preamble, base, tmp
24 ldr \base, =INTFLGA 30 ldr \base, =INTCA_BASE
25 .endm 31 .endm
26 32
27 .macro arch_ret_to_user, tmp1, tmp2 33 .macro arch_ret_to_user, tmp1, tmp2
28 .endm 34 .endm
29 35
30 .macro get_irqnr_and_base, irqnr, irqstat, base, tmp 36 .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
31 ldr \irqnr, [\base] 37 /* The single INTFLGA read access below results in the following:
38 *
39 * 1. INTLVLB is updated with old priority value from INTLVLA
40 * 2. Highest priority interrupt is accepted
41 * 3. INTLVLA is updated to contain priority of accepted interrupt
42 * 4. Accepted interrupt vector is stored in INTFLGA and INTEVTA
43 */
44 ldr \irqnr, [\base, #INTFLGA_OFFS]
45
46 /* Restore INTLVLA with the value saved in INTLVLB.
47 * This is required to support interrupt priorities properly.
48 */
49 ldrb \tmp, [\base, #INTLVLB_OFFS]
50 strb \tmp, [\base, #INTLVLA_OFFS]
51
52 /* Handle invalid vector number case */
32 cmp \irqnr, #0 53 cmp \irqnr, #0
33 beq 1000f 54 beq 1000f
34 /* intevt to irq number */ 55
56 /* Convert vector to irq number, same as the evt2irq() macro */
35 lsr \irqnr, \irqnr, #0x5 57 lsr \irqnr, \irqnr, #0x5
36 subs \irqnr, \irqnr, #16 58 subs \irqnr, \irqnr, #16
37 59
diff --git a/arch/arm/mach-shmobile/include/mach/gpio.h b/arch/arm/mach-shmobile/include/mach/gpio.h
index 5bc6bd444d72..2b1bb9e43dda 100644
--- a/arch/arm/mach-shmobile/include/mach/gpio.h
+++ b/arch/arm/mach-shmobile/include/mach/gpio.h
@@ -35,12 +35,12 @@ static inline int gpio_cansleep(unsigned gpio)
35 35
36static inline int gpio_to_irq(unsigned gpio) 36static inline int gpio_to_irq(unsigned gpio)
37{ 37{
38 return -ENOSYS; 38 return __gpio_to_irq(gpio);
39} 39}
40 40
41static inline int irq_to_gpio(unsigned int irq) 41static inline int irq_to_gpio(unsigned int irq)
42{ 42{
43 return -EINVAL; 43 return -ENOSYS;
44} 44}
45 45
46#endif /* CONFIG_GPIOLIB */ 46#endif /* CONFIG_GPIOLIB */
diff --git a/arch/arm/mach-shmobile/include/mach/sh7372.h b/arch/arm/mach-shmobile/include/mach/sh7372.h
index 147775a94bce..e4f9004e7103 100644
--- a/arch/arm/mach-shmobile/include/mach/sh7372.h
+++ b/arch/arm/mach-shmobile/include/mach/sh7372.h
@@ -464,5 +464,7 @@ extern struct clk sh7372_dv_clki_div2_clk;
464extern struct clk sh7372_pllc2_clk; 464extern struct clk sh7372_pllc2_clk;
465extern struct clk sh7372_fsiack_clk; 465extern struct clk sh7372_fsiack_clk;
466extern struct clk sh7372_fsibck_clk; 466extern struct clk sh7372_fsibck_clk;
467extern struct clk sh7372_fsidiva_clk;
468extern struct clk sh7372_fsidivb_clk;
467 469
468#endif /* __ASM_SH7372_H__ */ 470#endif /* __ASM_SH7372_H__ */
diff --git a/arch/arm/mach-shmobile/include/mach/vmalloc.h b/arch/arm/mach-shmobile/include/mach/vmalloc.h
index 4aecf6e3a859..2b8fd8b942fe 100644
--- a/arch/arm/mach-shmobile/include/mach/vmalloc.h
+++ b/arch/arm/mach-shmobile/include/mach/vmalloc.h
@@ -2,6 +2,6 @@
2#define __ASM_MACH_VMALLOC_H 2#define __ASM_MACH_VMALLOC_H
3 3
4/* Vmalloc at ... - 0xe5ffffff */ 4/* Vmalloc at ... - 0xe5ffffff */
5#define VMALLOC_END 0xe6000000 5#define VMALLOC_END 0xe6000000UL
6 6
7#endif /* __ASM_MACH_VMALLOC_H */ 7#endif /* __ASM_MACH_VMALLOC_H */
diff --git a/arch/arm/mach-shmobile/intc-sh7372.c b/arch/arm/mach-shmobile/intc-sh7372.c
index 4cd3cae38e72..30b2f400666a 100644
--- a/arch/arm/mach-shmobile/intc-sh7372.c
+++ b/arch/arm/mach-shmobile/intc-sh7372.c
@@ -98,7 +98,7 @@ static struct intc_vect intca_vectors[] __initdata = {
98 INTC_VECT(IRQ14A, 0x03c0), INTC_VECT(IRQ15A, 0x03e0), 98 INTC_VECT(IRQ14A, 0x03c0), INTC_VECT(IRQ15A, 0x03e0),
99 INTC_VECT(IRQ16A, 0x3200), INTC_VECT(IRQ17A, 0x3220), 99 INTC_VECT(IRQ16A, 0x3200), INTC_VECT(IRQ17A, 0x3220),
100 INTC_VECT(IRQ18A, 0x3240), INTC_VECT(IRQ19A, 0x3260), 100 INTC_VECT(IRQ18A, 0x3240), INTC_VECT(IRQ19A, 0x3260),
101 INTC_VECT(IRQ20A, 0x3280), INTC_VECT(IRQ31A, 0x32a0), 101 INTC_VECT(IRQ20A, 0x3280), INTC_VECT(IRQ21A, 0x32a0),
102 INTC_VECT(IRQ22A, 0x32c0), INTC_VECT(IRQ23A, 0x32e0), 102 INTC_VECT(IRQ22A, 0x32c0), INTC_VECT(IRQ23A, 0x32e0),
103 INTC_VECT(IRQ24A, 0x3300), INTC_VECT(IRQ25A, 0x3320), 103 INTC_VECT(IRQ24A, 0x3300), INTC_VECT(IRQ25A, 0x3320),
104 INTC_VECT(IRQ26A, 0x3340), INTC_VECT(IRQ27A, 0x3360), 104 INTC_VECT(IRQ26A, 0x3340), INTC_VECT(IRQ27A, 0x3360),
diff --git a/arch/arm/mach-tegra/include/mach/debug-macro.S b/arch/arm/mach-tegra/include/mach/debug-macro.S
index 8ea3bffb4e00..a0e7c12868bd 100644
--- a/arch/arm/mach-tegra/include/mach/debug-macro.S
+++ b/arch/arm/mach-tegra/include/mach/debug-macro.S
@@ -21,8 +21,8 @@
21#include <mach/io.h> 21#include <mach/io.h>
22 22
23 .macro addruart, rp, rv 23 .macro addruart, rp, rv
24 ldreq \rp, =IO_APB_PHYS @ physical 24 ldr \rp, =IO_APB_PHYS @ physical
25 ldrne \rv, =IO_APB_VIRT @ virtual 25 ldr \rv, =IO_APB_VIRT @ virtual
26#if defined(CONFIG_TEGRA_DEBUG_UART_NONE) 26#if defined(CONFIG_TEGRA_DEBUG_UART_NONE)
27#error "A debug UART must be selected in the kernel config to use DEBUG_LL" 27#error "A debug UART must be selected in the kernel config to use DEBUG_LL"
28#elif defined(CONFIG_TEGRA_DEBUG_UARTA) 28#elif defined(CONFIG_TEGRA_DEBUG_UARTA)
diff --git a/arch/arm/mach-u300/spi.c b/arch/arm/mach-u300/spi.c
index edb2c0d255c2..00869def5420 100644
--- a/arch/arm/mach-u300/spi.c
+++ b/arch/arm/mach-u300/spi.c
@@ -67,7 +67,7 @@ static struct spi_board_info u300_spi_devices[] = {
67 .bus_num = 0, /* Only one bus on this chip */ 67 .bus_num = 0, /* Only one bus on this chip */
68 .chip_select = 0, 68 .chip_select = 0,
69 /* Means SPI_CS_HIGH, change if e.g low CS */ 69 /* Means SPI_CS_HIGH, change if e.g low CS */
70 .mode = SPI_MODE_1 | SPI_LSB_FIRST | SPI_LOOP, 70 .mode = SPI_MODE_1 | SPI_LOOP,
71 }, 71 },
72#endif 72#endif
73}; 73};
diff --git a/arch/arm/mach-ux500/cpu.c b/arch/arm/mach-ux500/cpu.c
index 73fb1a551ec6..608a1372b172 100644
--- a/arch/arm/mach-ux500/cpu.c
+++ b/arch/arm/mach-ux500/cpu.c
@@ -75,14 +75,14 @@ void __init ux500_init_irq(void)
75static inline void ux500_cache_wait(void __iomem *reg, unsigned long mask) 75static inline void ux500_cache_wait(void __iomem *reg, unsigned long mask)
76{ 76{
77 /* wait for the operation to complete */ 77 /* wait for the operation to complete */
78 while (readl(reg) & mask) 78 while (readl_relaxed(reg) & mask)
79 ; 79 ;
80} 80}
81 81
82static inline void ux500_cache_sync(void) 82static inline void ux500_cache_sync(void)
83{ 83{
84 void __iomem *base = __io_address(UX500_L2CC_BASE); 84 void __iomem *base = __io_address(UX500_L2CC_BASE);
85 writel(0, base + L2X0_CACHE_SYNC); 85 writel_relaxed(0, base + L2X0_CACHE_SYNC);
86 ux500_cache_wait(base + L2X0_CACHE_SYNC, 1); 86 ux500_cache_wait(base + L2X0_CACHE_SYNC, 1);
87} 87}
88 88
@@ -107,7 +107,7 @@ static void ux500_l2x0_inv_all(void)
107 uint32_t l2x0_way_mask = (1<<16) - 1; /* Bitmask of active ways */ 107 uint32_t l2x0_way_mask = (1<<16) - 1; /* Bitmask of active ways */
108 108
109 /* invalidate all ways */ 109 /* invalidate all ways */
110 writel(l2x0_way_mask, l2x0_base + L2X0_INV_WAY); 110 writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_INV_WAY);
111 ux500_cache_wait(l2x0_base + L2X0_INV_WAY, l2x0_way_mask); 111 ux500_cache_wait(l2x0_base + L2X0_INV_WAY, l2x0_way_mask);
112 ux500_cache_sync(); 112 ux500_cache_sync();
113} 113}
diff --git a/arch/arm/mach-versatile/include/mach/vmalloc.h b/arch/arm/mach-versatile/include/mach/vmalloc.h
index ebd8a2543d3b..7d8e069ad51b 100644
--- a/arch/arm/mach-versatile/include/mach/vmalloc.h
+++ b/arch/arm/mach-versatile/include/mach/vmalloc.h
@@ -18,4 +18,4 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21#define VMALLOC_END 0xd8000000 21#define VMALLOC_END 0xd8000000UL
diff --git a/arch/arm/mach-vexpress/ct-ca9x4.c b/arch/arm/mach-vexpress/ct-ca9x4.c
index c2e405a9e025..fd25ccd7272f 100644
--- a/arch/arm/mach-vexpress/ct-ca9x4.c
+++ b/arch/arm/mach-vexpress/ct-ca9x4.c
@@ -54,7 +54,9 @@ static struct map_desc ct_ca9x4_io_desc[] __initdata = {
54 54
55static void __init ct_ca9x4_map_io(void) 55static void __init ct_ca9x4_map_io(void)
56{ 56{
57#ifdef CONFIG_LOCAL_TIMERS
57 twd_base = MMIO_P2V(A9_MPCORE_TWD); 58 twd_base = MMIO_P2V(A9_MPCORE_TWD);
59#endif
58 v2m_map_io(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc)); 60 v2m_map_io(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
59} 61}
60 62
diff --git a/arch/arm/mach-vexpress/headsmp.S b/arch/arm/mach-vexpress/headsmp.S
index 8a78ff68e1ee..7a3f0632947c 100644
--- a/arch/arm/mach-vexpress/headsmp.S
+++ b/arch/arm/mach-vexpress/headsmp.S
@@ -35,5 +35,6 @@ pen: ldr r7, [r6]
35 */ 35 */
36 b secondary_startup 36 b secondary_startup
37 37
38 .align
381: .long . 391: .long .
39 .long pen_release 40 .long pen_release
diff --git a/arch/arm/mm/cache-v6.S b/arch/arm/mm/cache-v6.S
index 99fa688dfadd..c96fa1b3f49f 100644
--- a/arch/arm/mm/cache-v6.S
+++ b/arch/arm/mm/cache-v6.S
@@ -203,6 +203,10 @@ ENTRY(v6_flush_kern_dcache_area)
203 * - end - virtual end address of region 203 * - end - virtual end address of region
204 */ 204 */
205v6_dma_inv_range: 205v6_dma_inv_range:
206#ifdef CONFIG_DMA_CACHE_RWFO
207 ldrb r2, [r0] @ read for ownership
208 strb r2, [r0] @ write for ownership
209#endif
206 tst r0, #D_CACHE_LINE_SIZE - 1 210 tst r0, #D_CACHE_LINE_SIZE - 1
207 bic r0, r0, #D_CACHE_LINE_SIZE - 1 211 bic r0, r0, #D_CACHE_LINE_SIZE - 1
208#ifdef HARVARD_CACHE 212#ifdef HARVARD_CACHE
@@ -211,6 +215,10 @@ v6_dma_inv_range:
211 mcrne p15, 0, r0, c7, c11, 1 @ clean unified line 215 mcrne p15, 0, r0, c7, c11, 1 @ clean unified line
212#endif 216#endif
213 tst r1, #D_CACHE_LINE_SIZE - 1 217 tst r1, #D_CACHE_LINE_SIZE - 1
218#ifdef CONFIG_DMA_CACHE_RWFO
219 ldrneb r2, [r1, #-1] @ read for ownership
220 strneb r2, [r1, #-1] @ write for ownership
221#endif
214 bic r1, r1, #D_CACHE_LINE_SIZE - 1 222 bic r1, r1, #D_CACHE_LINE_SIZE - 1
215#ifdef HARVARD_CACHE 223#ifdef HARVARD_CACHE
216 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line 224 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line
@@ -218,10 +226,6 @@ v6_dma_inv_range:
218 mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line 226 mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line
219#endif 227#endif
2201: 2281:
221#ifdef CONFIG_DMA_CACHE_RWFO
222 ldr r2, [r0] @ read for ownership
223 str r2, [r0] @ write for ownership
224#endif
225#ifdef HARVARD_CACHE 229#ifdef HARVARD_CACHE
226 mcr p15, 0, r0, c7, c6, 1 @ invalidate D line 230 mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
227#else 231#else
@@ -229,6 +233,10 @@ v6_dma_inv_range:
229#endif 233#endif
230 add r0, r0, #D_CACHE_LINE_SIZE 234 add r0, r0, #D_CACHE_LINE_SIZE
231 cmp r0, r1 235 cmp r0, r1
236#ifdef CONFIG_DMA_CACHE_RWFO
237 ldrlo r2, [r0] @ read for ownership
238 strlo r2, [r0] @ write for ownership
239#endif
232 blo 1b 240 blo 1b
233 mov r0, #0 241 mov r0, #0
234 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer 242 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
@@ -263,12 +271,12 @@ v6_dma_clean_range:
263 * - end - virtual end address of region 271 * - end - virtual end address of region
264 */ 272 */
265ENTRY(v6_dma_flush_range) 273ENTRY(v6_dma_flush_range)
266 bic r0, r0, #D_CACHE_LINE_SIZE - 1
2671:
268#ifdef CONFIG_DMA_CACHE_RWFO 274#ifdef CONFIG_DMA_CACHE_RWFO
269 ldr r2, [r0] @ read for ownership 275 ldrb r2, [r0] @ read for ownership
270 str r2, [r0] @ write for ownership 276 strb r2, [r0] @ write for ownership
271#endif 277#endif
278 bic r0, r0, #D_CACHE_LINE_SIZE - 1
2791:
272#ifdef HARVARD_CACHE 280#ifdef HARVARD_CACHE
273 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line 281 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
274#else 282#else
@@ -276,6 +284,10 @@ ENTRY(v6_dma_flush_range)
276#endif 284#endif
277 add r0, r0, #D_CACHE_LINE_SIZE 285 add r0, r0, #D_CACHE_LINE_SIZE
278 cmp r0, r1 286 cmp r0, r1
287#ifdef CONFIG_DMA_CACHE_RWFO
288 ldrlob r2, [r0] @ read for ownership
289 strlob r2, [r0] @ write for ownership
290#endif
279 blo 1b 291 blo 1b
280 mov r0, #0 292 mov r0, #0
281 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer 293 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
diff --git a/arch/arm/mm/cache-v7.S b/arch/arm/mm/cache-v7.S
index a3ebf7a4f49b..6136e68ce953 100644
--- a/arch/arm/mm/cache-v7.S
+++ b/arch/arm/mm/cache-v7.S
@@ -173,15 +173,22 @@ ENTRY(v7_coherent_user_range)
173 UNWIND(.fnstart ) 173 UNWIND(.fnstart )
174 dcache_line_size r2, r3 174 dcache_line_size r2, r3
175 sub r3, r2, #1 175 sub r3, r2, #1
176 bic r0, r0, r3 176 bic r12, r0, r3
1771: 1771:
178 USER( mcr p15, 0, r0, c7, c11, 1 ) @ clean D line to the point of unification 178 USER( mcr p15, 0, r12, c7, c11, 1 ) @ clean D line to the point of unification
179 add r12, r12, r2
180 cmp r12, r1
181 blo 1b
179 dsb 182 dsb
180 USER( mcr p15, 0, r0, c7, c5, 1 ) @ invalidate I line 183 icache_line_size r2, r3
181 add r0, r0, r2 184 sub r3, r2, #1
185 bic r12, r0, r3
1822: 1862:
183 cmp r0, r1 187 USER( mcr p15, 0, r12, c7, c5, 1 ) @ invalidate I line
184 blo 1b 188 add r12, r12, r2
189 cmp r12, r1
190 blo 2b
1913:
185 mov r0, #0 192 mov r0, #0
186 ALT_SMP(mcr p15, 0, r0, c7, c1, 6) @ invalidate BTB Inner Shareable 193 ALT_SMP(mcr p15, 0, r0, c7, c1, 6) @ invalidate BTB Inner Shareable
187 ALT_UP(mcr p15, 0, r0, c7, c5, 6) @ invalidate BTB 194 ALT_UP(mcr p15, 0, r0, c7, c5, 6) @ invalidate BTB
@@ -194,10 +201,10 @@ ENTRY(v7_coherent_user_range)
194 * isn't mapped, just try the next page. 201 * isn't mapped, just try the next page.
195 */ 202 */
1969001: 2039001:
197 mov r0, r0, lsr #12 204 mov r12, r12, lsr #12
198 mov r0, r0, lsl #12 205 mov r12, r12, lsl #12
199 add r0, r0, #4096 206 add r12, r12, #4096
200 b 2b 207 b 3b
201 UNWIND(.fnend ) 208 UNWIND(.fnend )
202ENDPROC(v7_coherent_kern_range) 209ENDPROC(v7_coherent_kern_range)
203ENDPROC(v7_coherent_user_range) 210ENDPROC(v7_coherent_user_range)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index e4dd0646e859..ac6a36142fcd 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -198,7 +198,7 @@ __dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot)
198 * fragmentation of the DMA space, and also prevents allocations 198 * fragmentation of the DMA space, and also prevents allocations
199 * smaller than a section from crossing a section boundary. 199 * smaller than a section from crossing a section boundary.
200 */ 200 */
201 bit = fls(size - 1) + 1; 201 bit = fls(size - 1);
202 if (bit > SECTION_SHIFT) 202 if (bit > SECTION_SHIFT)
203 bit = SECTION_SHIFT; 203 bit = SECTION_SHIFT;
204 align = 1 << bit; 204 align = 1 << bit;
diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
index 17e7b0b57e49..55c17a6fb22f 100644
--- a/arch/arm/mm/ioremap.c
+++ b/arch/arm/mm/ioremap.c
@@ -206,8 +206,8 @@ void __iomem * __arm_ioremap_pfn_caller(unsigned long pfn,
206 */ 206 */
207 if (pfn_valid(pfn)) { 207 if (pfn_valid(pfn)) {
208 printk(KERN_WARNING "BUG: Your driver calls ioremap() on system memory. This leads\n" 208 printk(KERN_WARNING "BUG: Your driver calls ioremap() on system memory. This leads\n"
209 KERN_WARNING "to architecturally unpredictable behaviour on ARMv6+, and ioremap()\n" 209 "to architecturally unpredictable behaviour on ARMv6+, and ioremap()\n"
210 KERN_WARNING "will fail in the next kernel release. Please fix your driver.\n"); 210 "will fail in the next kernel release. Please fix your driver.\n");
211 WARN_ON(1); 211 WARN_ON(1);
212 } 212 }
213 213
diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
index 7d63beaf9745..b795afd0a2c6 100644
--- a/arch/arm/mm/proc-macros.S
+++ b/arch/arm/mm/proc-macros.S
@@ -61,17 +61,27 @@
61 .endm 61 .endm
62 62
63/* 63/*
64 * cache_line_size - get the cache line size from the CSIDR register 64 * dcache_line_size - get the minimum D-cache line size from the CTR register
65 * (available on ARMv7+). It assumes that the CSSR register was configured 65 * on ARMv7.
66 * to access the L1 data cache CSIDR.
67 */ 66 */
68 .macro dcache_line_size, reg, tmp 67 .macro dcache_line_size, reg, tmp
69 mrc p15, 1, \tmp, c0, c0, 0 @ read CSIDR 68 mrc p15, 0, \tmp, c0, c0, 1 @ read ctr
70 and \tmp, \tmp, #7 @ cache line size encoding 69 lsr \tmp, \tmp, #16
71 mov \reg, #16 @ size offset 70 and \tmp, \tmp, #0xf @ cache line size encoding
71 mov \reg, #4 @ bytes per word
72 mov \reg, \reg, lsl \tmp @ actual cache line size 72 mov \reg, \reg, lsl \tmp @ actual cache line size
73 .endm 73 .endm
74 74
75/*
76 * icache_line_size - get the minimum I-cache line size from the CTR register
77 * on ARMv7.
78 */
79 .macro icache_line_size, reg, tmp
80 mrc p15, 0, \tmp, c0, c0, 1 @ read ctr
81 and \tmp, \tmp, #0xf @ cache line size encoding
82 mov \reg, #4 @ bytes per word
83 mov \reg, \reg, lsl \tmp @ actual cache line size
84 .endm
75 85
76/* 86/*
77 * Sanity check the PTE configuration for the code below - which makes 87 * Sanity check the PTE configuration for the code below - which makes
diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S
index 53cbe2225153..9b9ff5d949fd 100644
--- a/arch/arm/mm/proc-v7.S
+++ b/arch/arm/mm/proc-v7.S
@@ -381,7 +381,7 @@ __v7_ca9mp_proc_info:
381 PMD_SECT_XN | \ 381 PMD_SECT_XN | \
382 PMD_SECT_AP_WRITE | \ 382 PMD_SECT_AP_WRITE | \
383 PMD_SECT_AP_READ 383 PMD_SECT_AP_READ
384 b __v7_ca9mp_setup 384 W(b) __v7_ca9mp_setup
385 .long cpu_arch_name 385 .long cpu_arch_name
386 .long cpu_elf_name 386 .long cpu_elf_name
387 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_TLS 387 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_TLS
@@ -413,7 +413,7 @@ __v7_proc_info:
413 PMD_SECT_XN | \ 413 PMD_SECT_XN | \
414 PMD_SECT_AP_WRITE | \ 414 PMD_SECT_AP_WRITE | \
415 PMD_SECT_AP_READ 415 PMD_SECT_AP_READ
416 b __v7_setup 416 W(b) __v7_setup
417 .long cpu_arch_name 417 .long cpu_arch_name
418 .long cpu_elf_name 418 .long cpu_elf_name
419 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_TLS 419 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_TLS
diff --git a/arch/arm/plat-iop/time.c b/arch/arm/plat-iop/time.c
index 85d3e55ca4a9..558cdfaf76b6 100644
--- a/arch/arm/plat-iop/time.c
+++ b/arch/arm/plat-iop/time.c
@@ -18,6 +18,7 @@
18#include <linux/time.h> 18#include <linux/time.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/timex.h> 20#include <linux/timex.h>
21#include <linux/sched.h>
21#include <linux/io.h> 22#include <linux/io.h>
22#include <linux/clocksource.h> 23#include <linux/clocksource.h>
23#include <linux/clockchips.h> 24#include <linux/clockchips.h>
@@ -36,7 +37,7 @@
36/* 37/*
37 * IOP clocksource (free-running timer 1). 38 * IOP clocksource (free-running timer 1).
38 */ 39 */
39static cycle_t iop_clocksource_read(struct clocksource *unused) 40static cycle_t notrace iop_clocksource_read(struct clocksource *unused)
40{ 41{
41 return 0xffffffffu - read_tcr1(); 42 return 0xffffffffu - read_tcr1();
42} 43}
diff --git a/arch/arm/plat-mxc/devices/platform-imx-dma.c b/arch/arm/plat-mxc/devices/platform-imx-dma.c
index 02d989018059..3a705c7877dd 100644
--- a/arch/arm/plat-mxc/devices/platform-imx-dma.c
+++ b/arch/arm/plat-mxc/devices/platform-imx-dma.c
@@ -12,15 +12,7 @@
12 12
13#include <mach/hardware.h> 13#include <mach/hardware.h>
14#include <mach/devices-common.h> 14#include <mach/devices-common.h>
15#ifdef SDMA_IS_MERGED
16#include <mach/sdma.h> 15#include <mach/sdma.h>
17#else
18struct sdma_platform_data {
19 int sdma_version;
20 char *cpu_name;
21 int to_version;
22};
23#endif
24 16
25struct imx_imx_sdma_data { 17struct imx_imx_sdma_data {
26 resource_size_t iobase; 18 resource_size_t iobase;
diff --git a/arch/arm/plat-mxc/devices/platform-spi_imx.c b/arch/arm/plat-mxc/devices/platform-spi_imx.c
index e48340ec331e..17f724c9452d 100644
--- a/arch/arm/plat-mxc/devices/platform-spi_imx.c
+++ b/arch/arm/plat-mxc/devices/platform-spi_imx.c
@@ -27,6 +27,7 @@ const struct imx_spi_imx_data imx21_cspi_data[] __initconst = {
27 imx_spi_imx_data_entry(MX21, CSPI, "imx21-cspi", _id, _hwid, SZ_4K) 27 imx_spi_imx_data_entry(MX21, CSPI, "imx21-cspi", _id, _hwid, SZ_4K)
28 imx21_cspi_data_entry(0, 1), 28 imx21_cspi_data_entry(0, 1),
29 imx21_cspi_data_entry(1, 2), 29 imx21_cspi_data_entry(1, 2),
30};
30#endif 31#endif
31 32
32#ifdef CONFIG_ARCH_MX25 33#ifdef CONFIG_ARCH_MX25
diff --git a/arch/arm/plat-nomadik/timer.c b/arch/arm/plat-nomadik/timer.c
index aedf9c1d645e..63cdc6025bd7 100644
--- a/arch/arm/plat-nomadik/timer.c
+++ b/arch/arm/plat-nomadik/timer.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright (C) 2008 STMicroelectronics 4 * Copyright (C) 2008 STMicroelectronics
5 * Copyright (C) 2010 Alessandro Rubini 5 * Copyright (C) 2010 Alessandro Rubini
6 * Copyright (C) 2010 Linus Walleij for ST-Ericsson
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2, as 9 * it under the terms of the GNU General Public License version 2, as
@@ -16,11 +17,13 @@
16#include <linux/clk.h> 17#include <linux/clk.h>
17#include <linux/jiffies.h> 18#include <linux/jiffies.h>
18#include <linux/err.h> 19#include <linux/err.h>
20#include <linux/cnt32_to_63.h>
21#include <linux/timer.h>
19#include <asm/mach/time.h> 22#include <asm/mach/time.h>
20 23
21#include <plat/mtu.h> 24#include <plat/mtu.h>
22 25
23void __iomem *mtu_base; /* ssigned by machine code */ 26void __iomem *mtu_base; /* Assigned by machine code */
24 27
25/* 28/*
26 * Kernel assumes that sched_clock can be called early 29 * Kernel assumes that sched_clock can be called early
@@ -48,16 +51,82 @@ static struct clocksource nmdk_clksrc = {
48/* 51/*
49 * Override the global weak sched_clock symbol with this 52 * Override the global weak sched_clock symbol with this
50 * local implementation which uses the clocksource to get some 53 * local implementation which uses the clocksource to get some
51 * better resolution when scheduling the kernel. We accept that 54 * better resolution when scheduling the kernel.
52 * this wraps around for now, since it is just a relative time 55 *
53 * stamp. (Inspired by OMAP implementation.) 56 * Because the hardware timer period may be quite short
57 * (32.3 secs on the 133 MHz MTU timer selection on ux500)
58 * and because cnt32_to_63() needs to be called at least once per
59 * half period to work properly, a kernel keepwarm() timer is set up
60 * to ensure this requirement is always met.
61 *
62 * Also the sched_clock timer will wrap around at some point,
63 * here we set it to run continously for a year.
54 */ 64 */
65#define SCHED_CLOCK_MIN_WRAP 3600*24*365
66static struct timer_list cnt32_to_63_keepwarm_timer;
67static u32 sched_mult;
68static u32 sched_shift;
69
55unsigned long long notrace sched_clock(void) 70unsigned long long notrace sched_clock(void)
56{ 71{
57 return clocksource_cyc2ns(nmdk_clksrc.read( 72 u64 cycles;
58 &nmdk_clksrc), 73
59 nmdk_clksrc.mult, 74 if (unlikely(!mtu_base))
60 nmdk_clksrc.shift); 75 return 0;
76
77 cycles = cnt32_to_63(-readl(mtu_base + MTU_VAL(0)));
78 /*
79 * sched_mult is guaranteed to be even so will
80 * shift out bit 63
81 */
82 return (cycles * sched_mult) >> sched_shift;
83}
84
85/* Just kick sched_clock every so often */
86static void cnt32_to_63_keepwarm(unsigned long data)
87{
88 mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
89 (void) sched_clock();
90}
91
92/*
93 * Set up a timer to keep sched_clock():s 32_to_63 algorithm warm
94 * once in half a 32bit timer wrap interval.
95 */
96static void __init nmdk_sched_clock_init(unsigned long rate)
97{
98 u32 v;
99 unsigned long delta;
100 u64 days;
101
102 /* Find the apropriate mult and shift factors */
103 clocks_calc_mult_shift(&sched_mult, &sched_shift,
104 rate, NSEC_PER_SEC, SCHED_CLOCK_MIN_WRAP);
105 /* We need to multiply by an even number to get rid of bit 63 */
106 if (sched_mult & 1)
107 sched_mult++;
108
109 /* Let's see what we get, take max counter and scale it */
110 days = (0xFFFFFFFFFFFFFFFFLLU * sched_mult) >> sched_shift;
111 do_div(days, NSEC_PER_SEC);
112 do_div(days, (3600*24));
113
114 pr_info("sched_clock: using %d bits @ %lu Hz wrap in %lu days\n",
115 (64 - sched_shift), rate, (unsigned long) days);
116
117 /*
118 * Program a timer to kick us at half 32bit wraparound
119 * Formula: seconds per wrap = (2^32) / f
120 */
121 v = 0xFFFFFFFFUL / rate;
122 /* We want half of the wrap time to keep cnt32_to_63 warm */
123 v /= 2;
124 pr_debug("sched_clock: prescaled timer rate: %lu Hz, "
125 "initialize keepwarm timer every %d seconds\n", rate, v);
126 /* Convert seconds to jiffies */
127 delta = msecs_to_jiffies(v*1000);
128 setup_timer(&cnt32_to_63_keepwarm_timer, cnt32_to_63_keepwarm, delta);
129 mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + delta));
61} 130}
62 131
63/* Clockevent device: use one-shot mode */ 132/* Clockevent device: use one-shot mode */
@@ -161,13 +230,15 @@ void __init nmdk_timer_init(void)
161 writel(0, mtu_base + MTU_BGLR(0)); 230 writel(0, mtu_base + MTU_BGLR(0));
162 writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0)); 231 writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0));
163 232
164 /* Now the scheduling clock is ready */ 233 /* Now the clock source is ready */
165 nmdk_clksrc.read = nmdk_read_timer; 234 nmdk_clksrc.read = nmdk_read_timer;
166 235
167 if (clocksource_register(&nmdk_clksrc)) 236 if (clocksource_register(&nmdk_clksrc))
168 pr_err("timer: failed to initialize clock source %s\n", 237 pr_err("timer: failed to initialize clock source %s\n",
169 nmdk_clksrc.name); 238 nmdk_clksrc.name);
170 239
240 nmdk_sched_clock_init(rate);
241
171 /* Timer 1 is used for events */ 242 /* Timer 1 is used for events */
172 243
173 clockevents_calc_mult_shift(&nmdk_clkevt, rate, MTU_MIN_RANGE); 244 clockevents_calc_mult_shift(&nmdk_clkevt, rate, MTU_MIN_RANGE);
diff --git a/arch/arm/plat-omap/counter_32k.c b/arch/arm/plat-omap/counter_32k.c
index 155fe43a672b..8722a136f3a5 100644
--- a/arch/arm/plat-omap/counter_32k.c
+++ b/arch/arm/plat-omap/counter_32k.c
@@ -16,6 +16,7 @@
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/err.h>
19 20
20#include <plat/common.h> 21#include <plat/common.h>
21#include <plat/board.h> 22#include <plat/board.h>
@@ -164,7 +165,7 @@ static int __init omap_init_clocksource_32k(void)
164 return -ENODEV; 165 return -ENODEV;
165 166
166 sync_32k_ick = clk_get(NULL, "omap_32ksync_ick"); 167 sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
167 if (sync_32k_ick) 168 if (!IS_ERR(sync_32k_ick))
168 clk_enable(sync_32k_ick); 169 clk_enable(sync_32k_ick);
169 170
170 clocksource_32k.mult = clocksource_hz2mult(32768, 171 clocksource_32k.mult = clocksource_hz2mult(32768,
diff --git a/arch/arm/plat-omap/devices.c b/arch/arm/plat-omap/devices.c
index 6f42a18b8aa4..fc819120978d 100644
--- a/arch/arm/plat-omap/devices.c
+++ b/arch/arm/plat-omap/devices.c
@@ -284,12 +284,14 @@ void __init omap_dsp_reserve_sdram_memblock(void)
284 if (!size) 284 if (!size)
285 return; 285 return;
286 286
287 paddr = __memblock_alloc_base(size, SZ_1M, MEMBLOCK_REAL_LIMIT); 287 paddr = memblock_alloc(size, SZ_1M);
288 if (!paddr) { 288 if (!paddr) {
289 pr_err("%s: failed to reserve %x bytes\n", 289 pr_err("%s: failed to reserve %x bytes\n",
290 __func__, size); 290 __func__, size);
291 return; 291 return;
292 } 292 }
293 memblock_free(paddr, size);
294 memblock_remove(paddr, size);
293 295
294 omap_dsp_phys_mempool_base = paddr; 296 omap_dsp_phys_mempool_base = paddr;
295} 297}
diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c
index f5c5b8da9a87..2c2826571d45 100644
--- a/arch/arm/plat-omap/dma.c
+++ b/arch/arm/plat-omap/dma.c
@@ -1983,6 +1983,8 @@ static int omap2_dma_handle_ch(int ch)
1983 1983
1984 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(ch)); 1984 dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(ch));
1985 dma_write(1 << ch, IRQSTATUS_L0); 1985 dma_write(1 << ch, IRQSTATUS_L0);
1986 /* read back the register to flush the write */
1987 dma_read(IRQSTATUS_L0);
1986 1988
1987 /* If the ch is not chained then chain_id will be -1 */ 1989 /* If the ch is not chained then chain_id will be -1 */
1988 if (dma_chan[ch].chain_id != -1) { 1990 if (dma_chan[ch].chain_id != -1) {
diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
index e2c8eebe6b3a..74dac419d328 100644
--- a/arch/arm/plat-omap/sram.c
+++ b/arch/arm/plat-omap/sram.c
@@ -166,7 +166,7 @@ static void __init omap_detect_sram(void)
166 cpu_is_omap1710()) 166 cpu_is_omap1710())
167 omap_sram_size = 0x4000; /* 16K */ 167 omap_sram_size = 0x4000; /* 16K */
168 else if (cpu_is_omap1611()) 168 else if (cpu_is_omap1611())
169 omap_sram_size = 0x3e800; /* 250K */ 169 omap_sram_size = SZ_256K;
170 else { 170 else {
171 printk(KERN_ERR "Could not detect SRAM size\n"); 171 printk(KERN_ERR "Could not detect SRAM size\n");
172 omap_sram_size = 0x4000; 172 omap_sram_size = 0x4000;
diff --git a/arch/arm/plat-orion/include/plat/pcie.h b/arch/arm/plat-orion/include/plat/pcie.h
index 3ebfef72b4e7..cc99163e73fd 100644
--- a/arch/arm/plat-orion/include/plat/pcie.h
+++ b/arch/arm/plat-orion/include/plat/pcie.h
@@ -11,12 +11,15 @@
11#ifndef __PLAT_PCIE_H 11#ifndef __PLAT_PCIE_H
12#define __PLAT_PCIE_H 12#define __PLAT_PCIE_H
13 13
14struct pci_bus;
15
14u32 orion_pcie_dev_id(void __iomem *base); 16u32 orion_pcie_dev_id(void __iomem *base);
15u32 orion_pcie_rev(void __iomem *base); 17u32 orion_pcie_rev(void __iomem *base);
16int orion_pcie_link_up(void __iomem *base); 18int orion_pcie_link_up(void __iomem *base);
17int orion_pcie_x4_mode(void __iomem *base); 19int orion_pcie_x4_mode(void __iomem *base);
18int orion_pcie_get_local_bus_nr(void __iomem *base); 20int orion_pcie_get_local_bus_nr(void __iomem *base);
19void orion_pcie_set_local_bus_nr(void __iomem *base, int nr); 21void orion_pcie_set_local_bus_nr(void __iomem *base, int nr);
22void orion_pcie_reset(void __iomem *base);
20void orion_pcie_setup(void __iomem *base, 23void orion_pcie_setup(void __iomem *base,
21 struct mbus_dram_target_info *dram); 24 struct mbus_dram_target_info *dram);
22int orion_pcie_rd_conf(void __iomem *base, struct pci_bus *bus, 25int orion_pcie_rd_conf(void __iomem *base, struct pci_bus *bus,
diff --git a/arch/arm/plat-orion/pcie.c b/arch/arm/plat-orion/pcie.c
index 779553a1595e..af2d733c50b5 100644
--- a/arch/arm/plat-orion/pcie.c
+++ b/arch/arm/plat-orion/pcie.c
@@ -182,11 +182,6 @@ void __init orion_pcie_setup(void __iomem *base,
182 u32 mask; 182 u32 mask;
183 183
184 /* 184 /*
185 * soft reset PCIe unit
186 */
187 orion_pcie_reset(base);
188
189 /*
190 * Point PCIe unit MBUS decode windows to DRAM space. 185 * Point PCIe unit MBUS decode windows to DRAM space.
191 */ 186 */
192 orion_pcie_setup_wins(base, dram); 187 orion_pcie_setup_wins(base, dram);
diff --git a/arch/arm/plat-pxa/include/plat/sdhci.h b/arch/arm/plat-pxa/include/plat/sdhci.h
index e49c5b6fc4e2..1ab332e37d7d 100644
--- a/arch/arm/plat-pxa/include/plat/sdhci.h
+++ b/arch/arm/plat-pxa/include/plat/sdhci.h
@@ -17,6 +17,9 @@
17/* Require clock free running */ 17/* Require clock free running */
18#define PXA_FLAG_DISABLE_CLOCK_GATING (1<<0) 18#define PXA_FLAG_DISABLE_CLOCK_GATING (1<<0)
19 19
20/* Board design supports 8-bit data on SD/SDIO BUS */
21#define PXA_FLAG_SD_8_BIT_CAPABLE_SLOT (1<<2)
22
20/* 23/*
21 * struct pxa_sdhci_platdata() - Platform device data for PXA SDHCI 24 * struct pxa_sdhci_platdata() - Platform device data for PXA SDHCI
22 * @max_speed: the maximum speed supported 25 * @max_speed: the maximum speed supported
diff --git a/arch/arm/plat-s3c24xx/Kconfig b/arch/arm/plat-s3c24xx/Kconfig
index 5a27b1b538f2..eb105e61c746 100644
--- a/arch/arm/plat-s3c24xx/Kconfig
+++ b/arch/arm/plat-s3c24xx/Kconfig
@@ -8,7 +8,7 @@ config PLAT_S3C24XX
8 default y 8 default y
9 select NO_IOPORT 9 select NO_IOPORT
10 select ARCH_REQUIRE_GPIOLIB 10 select ARCH_REQUIRE_GPIOLIB
11 select S3C_DEVICE_NAND 11 select S3C_DEV_NAND
12 select S3C_GPIO_CFG_S3C24XX 12 select S3C_GPIO_CFG_S3C24XX
13 help 13 help
14 Base platform code for any Samsung S3C24XX device 14 Base platform code for any Samsung S3C24XX device
diff --git a/arch/arm/plat-s3c24xx/cpu.c b/arch/arm/plat-s3c24xx/cpu.c
index 76d0858c3cbb..4a10c0f684b2 100644
--- a/arch/arm/plat-s3c24xx/cpu.c
+++ b/arch/arm/plat-s3c24xx/cpu.c
@@ -88,7 +88,7 @@ static struct cpu_table cpu_ids[] __initdata = {
88 { 88 {
89 .idcode = 0x32440000, 89 .idcode = 0x32440000,
90 .idmask = 0xffffffff, 90 .idmask = 0xffffffff,
91 .map_io = s3c244x_map_io, 91 .map_io = s3c2440_map_io,
92 .init_clocks = s3c244x_init_clocks, 92 .init_clocks = s3c244x_init_clocks,
93 .init_uarts = s3c244x_init_uarts, 93 .init_uarts = s3c244x_init_uarts,
94 .init = s3c2440_init, 94 .init = s3c2440_init,
@@ -97,7 +97,7 @@ static struct cpu_table cpu_ids[] __initdata = {
97 { 97 {
98 .idcode = 0x32440001, 98 .idcode = 0x32440001,
99 .idmask = 0xffffffff, 99 .idmask = 0xffffffff,
100 .map_io = s3c244x_map_io, 100 .map_io = s3c2440_map_io,
101 .init_clocks = s3c244x_init_clocks, 101 .init_clocks = s3c244x_init_clocks,
102 .init_uarts = s3c244x_init_uarts, 102 .init_uarts = s3c244x_init_uarts,
103 .init = s3c2440_init, 103 .init = s3c2440_init,
@@ -106,7 +106,7 @@ static struct cpu_table cpu_ids[] __initdata = {
106 { 106 {
107 .idcode = 0x32440aaa, 107 .idcode = 0x32440aaa,
108 .idmask = 0xffffffff, 108 .idmask = 0xffffffff,
109 .map_io = s3c244x_map_io, 109 .map_io = s3c2442_map_io,
110 .init_clocks = s3c244x_init_clocks, 110 .init_clocks = s3c244x_init_clocks,
111 .init_uarts = s3c244x_init_uarts, 111 .init_uarts = s3c244x_init_uarts,
112 .init = s3c2442_init, 112 .init = s3c2442_init,
@@ -115,7 +115,7 @@ static struct cpu_table cpu_ids[] __initdata = {
115 { 115 {
116 .idcode = 0x32440aab, 116 .idcode = 0x32440aab,
117 .idmask = 0xffffffff, 117 .idmask = 0xffffffff,
118 .map_io = s3c244x_map_io, 118 .map_io = s3c2442_map_io,
119 .init_clocks = s3c244x_init_clocks, 119 .init_clocks = s3c244x_init_clocks,
120 .init_uarts = s3c244x_init_uarts, 120 .init_uarts = s3c244x_init_uarts,
121 .init = s3c2442_init, 121 .init = s3c2442_init,
diff --git a/arch/arm/plat-s3c24xx/gpiolib.c b/arch/arm/plat-s3c24xx/gpiolib.c
index 24c6f5a30596..243b6411050d 100644
--- a/arch/arm/plat-s3c24xx/gpiolib.c
+++ b/arch/arm/plat-s3c24xx/gpiolib.c
@@ -82,8 +82,6 @@ static struct s3c_gpio_cfg s3c24xx_gpiocfg_banka = {
82struct s3c_gpio_cfg s3c24xx_gpiocfg_default = { 82struct s3c_gpio_cfg s3c24xx_gpiocfg_default = {
83 .set_config = s3c_gpio_setcfg_s3c24xx, 83 .set_config = s3c_gpio_setcfg_s3c24xx,
84 .get_config = s3c_gpio_getcfg_s3c24xx, 84 .get_config = s3c_gpio_getcfg_s3c24xx,
85 .set_pull = s3c_gpio_setpull_1up,
86 .get_pull = s3c_gpio_getpull_1up,
87}; 85};
88 86
89struct s3c_gpio_chip s3c24xx_gpios[] = { 87struct s3c_gpio_chip s3c24xx_gpios[] = {
diff --git a/arch/arm/plat-s3c24xx/include/plat/s3c244x.h b/arch/arm/plat-s3c24xx/include/plat/s3c244x.h
index 307248d1ccbb..89e8d0a25f87 100644
--- a/arch/arm/plat-s3c24xx/include/plat/s3c244x.h
+++ b/arch/arm/plat-s3c24xx/include/plat/s3c244x.h
@@ -21,17 +21,22 @@ extern void s3c244x_init_clocks(int xtal);
21#else 21#else
22#define s3c244x_init_clocks NULL 22#define s3c244x_init_clocks NULL
23#define s3c244x_init_uarts NULL 23#define s3c244x_init_uarts NULL
24#define s3c244x_map_io NULL
25#endif 24#endif
26 25
27#ifdef CONFIG_CPU_S3C2440 26#ifdef CONFIG_CPU_S3C2440
28extern int s3c2440_init(void); 27extern int s3c2440_init(void);
28
29extern void s3c2440_map_io(void);
29#else 30#else
30#define s3c2440_init NULL 31#define s3c2440_init NULL
32#define s3c2440_map_io NULL
31#endif 33#endif
32 34
33#ifdef CONFIG_CPU_S3C2442 35#ifdef CONFIG_CPU_S3C2442
34extern int s3c2442_init(void); 36extern int s3c2442_init(void);
37
38extern void s3c2442_map_io(void);
35#else 39#else
36#define s3c2442_init NULL 40#define s3c2442_init NULL
41#define s3c2442_map_io NULL
37#endif 42#endif
diff --git a/arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c b/arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c
index 9793544a6ace..704175b0573f 100644
--- a/arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c
+++ b/arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c
@@ -29,8 +29,8 @@ void s3c24xx_spi_gpiocfg_bus0_gpe11_12_13(struct s3c2410_spi_info *spi,
29 } else { 29 } else {
30 s3c_gpio_cfgpin(S3C2410_GPE(13), S3C2410_GPIO_INPUT); 30 s3c_gpio_cfgpin(S3C2410_GPE(13), S3C2410_GPIO_INPUT);
31 s3c_gpio_cfgpin(S3C2410_GPE(11), S3C2410_GPIO_INPUT); 31 s3c_gpio_cfgpin(S3C2410_GPE(11), S3C2410_GPIO_INPUT);
32 s3c_gpio_cfgpull(S3C2410_GPE(11), S3C_GPIO_PULL_NONE); 32 s3c_gpio_setpull(S3C2410_GPE(11), S3C_GPIO_PULL_NONE);
33 s3c_gpio_cfgpull(S3C2410_GPE(12), S3C_GPIO_PULL_NONE); 33 s3c_gpio_setpull(S3C2410_GPE(12), S3C_GPIO_PULL_NONE);
34 s3c_gpio_cfgpull(S3C2410_GPE(13), S3C_GPIO_PULL_NONE); 34 s3c_gpio_setpull(S3C2410_GPE(13), S3C_GPIO_PULL_NONE);
35 } 35 }
36} 36}
diff --git a/arch/arm/plat-s3c24xx/spi-bus1-gpd8_9_10.c b/arch/arm/plat-s3c24xx/spi-bus1-gpd8_9_10.c
index db9e9e477ec1..72457afd6255 100644
--- a/arch/arm/plat-s3c24xx/spi-bus1-gpd8_9_10.c
+++ b/arch/arm/plat-s3c24xx/spi-bus1-gpd8_9_10.c
@@ -31,8 +31,8 @@ void s3c24xx_spi_gpiocfg_bus1_gpd8_9_10(struct s3c2410_spi_info *spi,
31 } else { 31 } else {
32 s3c_gpio_cfgpin(S3C2410_GPD(8), S3C2410_GPIO_INPUT); 32 s3c_gpio_cfgpin(S3C2410_GPD(8), S3C2410_GPIO_INPUT);
33 s3c_gpio_cfgpin(S3C2410_GPD(9), S3C2410_GPIO_INPUT); 33 s3c_gpio_cfgpin(S3C2410_GPD(9), S3C2410_GPIO_INPUT);
34 s3c_gpio_cfgpull(S3C2410_GPD(10), S3C_GPIO_PULL_NONE); 34 s3c_gpio_setpull(S3C2410_GPD(10), S3C_GPIO_PULL_NONE);
35 s3c_gpio_cfgpull(S3C2410_GPD(9), S3C_GPIO_PULL_NONE); 35 s3c_gpio_setpull(S3C2410_GPD(9), S3C_GPIO_PULL_NONE);
36 s3c_gpio_cfgpull(S3C2410_GPD(8), S3C_GPIO_PULL_NONE); 36 s3c_gpio_setpull(S3C2410_GPD(8), S3C_GPIO_PULL_NONE);
37 } 37 }
38} 38}
diff --git a/arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c b/arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c
index 8ea663a438bb..c3972b645d13 100644
--- a/arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c
+++ b/arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c
@@ -29,8 +29,8 @@ void s3c24xx_spi_gpiocfg_bus1_gpg5_6_7(struct s3c2410_spi_info *spi,
29 } else { 29 } else {
30 s3c_gpio_cfgpin(S3C2410_GPG(7), S3C2410_GPIO_INPUT); 30 s3c_gpio_cfgpin(S3C2410_GPG(7), S3C2410_GPIO_INPUT);
31 s3c_gpio_cfgpin(S3C2410_GPG(5), S3C2410_GPIO_INPUT); 31 s3c_gpio_cfgpin(S3C2410_GPG(5), S3C2410_GPIO_INPUT);
32 s3c_gpio_cfgpull(S3C2410_GPG(5), S3C_GPIO_PULL_NONE); 32 s3c_gpio_setpull(S3C2410_GPG(5), S3C_GPIO_PULL_NONE);
33 s3c_gpio_cfgpull(S3C2410_GPG(6), S3C_GPIO_PULL_NONE); 33 s3c_gpio_setpull(S3C2410_GPG(6), S3C_GPIO_PULL_NONE);
34 s3c_gpio_cfgpull(S3C2410_GPG(7), S3C_GPIO_PULL_NONE); 34 s3c_gpio_setpull(S3C2410_GPG(7), S3C_GPIO_PULL_NONE);
35 } 35 }
36} 36}
diff --git a/arch/arm/plat-samsung/gpio-config.c b/arch/arm/plat-samsung/gpio-config.c
index b732b773b9af..0aa32f242ee4 100644
--- a/arch/arm/plat-samsung/gpio-config.c
+++ b/arch/arm/plat-samsung/gpio-config.c
@@ -280,18 +280,17 @@ s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
280} 280}
281#endif 281#endif
282 282
283#ifdef CONFIG_S3C_GPIO_PULL_UP 283#if defined(CONFIG_S3C_GPIO_PULL_UP) || defined(CONFIG_S3C_GPIO_PULL_DOWN)
284int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip, 284static int s3c_gpio_setpull_1(struct s3c_gpio_chip *chip,
285 unsigned int off, s3c_gpio_pull_t pull) 285 unsigned int off, s3c_gpio_pull_t pull,
286 s3c_gpio_pull_t updown)
286{ 287{
287 void __iomem *reg = chip->base + 0x08; 288 void __iomem *reg = chip->base + 0x08;
288 u32 pup = __raw_readl(reg); 289 u32 pup = __raw_readl(reg);
289 290
290 pup = __raw_readl(reg); 291 if (pull == updown)
291
292 if (pup == S3C_GPIO_PULL_UP)
293 pup &= ~(1 << off); 292 pup &= ~(1 << off);
294 else if (pup == S3C_GPIO_PULL_NONE) 293 else if (pull == S3C_GPIO_PULL_NONE)
295 pup |= (1 << off); 294 pup |= (1 << off);
296 else 295 else
297 return -EINVAL; 296 return -EINVAL;
@@ -300,17 +299,45 @@ int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip,
300 return 0; 299 return 0;
301} 300}
302 301
303s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip, 302static s3c_gpio_pull_t s3c_gpio_getpull_1(struct s3c_gpio_chip *chip,
304 unsigned int off) 303 unsigned int off, s3c_gpio_pull_t updown)
305{ 304{
306 void __iomem *reg = chip->base + 0x08; 305 void __iomem *reg = chip->base + 0x08;
307 u32 pup = __raw_readl(reg); 306 u32 pup = __raw_readl(reg);
308 307
309 pup &= (1 << off); 308 pup &= (1 << off);
310 return pup ? S3C_GPIO_PULL_NONE : S3C_GPIO_PULL_UP; 309 return pup ? S3C_GPIO_PULL_NONE : updown;
310}
311#endif /* CONFIG_S3C_GPIO_PULL_UP || CONFIG_S3C_GPIO_PULL_DOWN */
312
313#ifdef CONFIG_S3C_GPIO_PULL_UP
314s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip,
315 unsigned int off)
316{
317 return s3c_gpio_getpull_1(chip, off, S3C_GPIO_PULL_UP);
318}
319
320int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip,
321 unsigned int off, s3c_gpio_pull_t pull)
322{
323 return s3c_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_UP);
311} 324}
312#endif /* CONFIG_S3C_GPIO_PULL_UP */ 325#endif /* CONFIG_S3C_GPIO_PULL_UP */
313 326
327#ifdef CONFIG_S3C_GPIO_PULL_DOWN
328s3c_gpio_pull_t s3c_gpio_getpull_1down(struct s3c_gpio_chip *chip,
329 unsigned int off)
330{
331 return s3c_gpio_getpull_1(chip, off, S3C_GPIO_PULL_DOWN);
332}
333
334int s3c_gpio_setpull_1down(struct s3c_gpio_chip *chip,
335 unsigned int off, s3c_gpio_pull_t pull)
336{
337 return s3c_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_DOWN);
338}
339#endif /* CONFIG_S3C_GPIO_PULL_DOWN */
340
314#ifdef CONFIG_S5P_GPIO_DRVSTR 341#ifdef CONFIG_S5P_GPIO_DRVSTR
315s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin) 342s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
316{ 343{
diff --git a/arch/arm/plat-samsung/include/plat/gpio-cfg-helpers.h b/arch/arm/plat-samsung/include/plat/gpio-cfg-helpers.h
index 8fd65d8b5863..0d2c5703f1ee 100644
--- a/arch/arm/plat-samsung/include/plat/gpio-cfg-helpers.h
+++ b/arch/arm/plat-samsung/include/plat/gpio-cfg-helpers.h
@@ -210,6 +210,17 @@ extern s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip,
210 unsigned int off); 210 unsigned int off);
211 211
212/** 212/**
213 * s3c_gpio_getpull_1down() - Get configuration for choice of down or none
214 * @chip: The gpio chip that the GPIO pin belongs to
215 * @off: The offset to the pin to get the configuration of.
216 *
217 * This helper function reads the state of the pull-down resistor for the
218 * given GPIO in the same case as s3c_gpio_setpull_1down.
219*/
220extern s3c_gpio_pull_t s3c_gpio_getpull_1down(struct s3c_gpio_chip *chip,
221 unsigned int off);
222
223/**
213 * s3c_gpio_setpull_s3c2443() - Pull configuration for s3c2443. 224 * s3c_gpio_setpull_s3c2443() - Pull configuration for s3c2443.
214 * @chip: The gpio chip that is being configured. 225 * @chip: The gpio chip that is being configured.
215 * @off: The offset for the GPIO being configured. 226 * @off: The offset for the GPIO being configured.
diff --git a/arch/arm/tools/mach-types b/arch/arm/tools/mach-types
index 55590a4d87c9..2fea897ebeb1 100644
--- a/arch/arm/tools/mach-types
+++ b/arch/arm/tools/mach-types
@@ -12,7 +12,7 @@
12# 12#
13# http://www.arm.linux.org.uk/developer/machines/?action=new 13# http://www.arm.linux.org.uk/developer/machines/?action=new
14# 14#
15# Last update: Thu Sep 9 22:43:01 2010 15# Last update: Sun Dec 12 23:24:27 2010
16# 16#
17# machine_is_xxx CONFIG_xxxx MACH_TYPE_xxx number 17# machine_is_xxx CONFIG_xxxx MACH_TYPE_xxx number
18# 18#
@@ -2321,7 +2321,7 @@ mx31txtr MACH_MX31TXTR MX31TXTR 2332
2321u380 MACH_U380 U380 2333 2321u380 MACH_U380 U380 2333
2322oamp3_hualu MACH_HUALU_BOARD HUALU_BOARD 2334 2322oamp3_hualu MACH_HUALU_BOARD HUALU_BOARD 2334
2323npcmx50 MACH_NPCMX50 NPCMX50 2335 2323npcmx50 MACH_NPCMX50 NPCMX50 2335
2324mx51_lange51 MACH_MX51_LANGE51 MX51_LANGE51 2336 2324mx51_efikamx MACH_MX51_EFIKAMX MX51_EFIKAMX 2336
2325mx51_lange52 MACH_MX51_LANGE52 MX51_LANGE52 2337 2325mx51_lange52 MACH_MX51_LANGE52 MX51_LANGE52 2337
2326riom MACH_RIOM RIOM 2338 2326riom MACH_RIOM RIOM 2338
2327comcas MACH_COMCAS COMCAS 2339 2327comcas MACH_COMCAS COMCAS 2339
@@ -2355,7 +2355,7 @@ at91sam9263cs MACH_AT91SAM9263CS AT91SAM9263CS 2366
2355csb732 MACH_CSB732 CSB732 2367 2355csb732 MACH_CSB732 CSB732 2367
2356u8500 MACH_U8500 U8500 2368 2356u8500 MACH_U8500 U8500 2368
2357huqiu MACH_HUQIU HUQIU 2369 2357huqiu MACH_HUQIU HUQIU 2369
2358mx51_kunlun MACH_MX51_KUNLUN MX51_KUNLUN 2370 2358mx51_efikasb MACH_MX51_EFIKASB MX51_EFIKASB 2370
2359pmt1g MACH_PMT1G PMT1G 2371 2359pmt1g MACH_PMT1G PMT1G 2371
2360htcelf MACH_HTCELF HTCELF 2372 2360htcelf MACH_HTCELF HTCELF 2372
2361armadillo420 MACH_ARMADILLO420 ARMADILLO420 2373 2361armadillo420 MACH_ARMADILLO420 ARMADILLO420 2373
@@ -2971,7 +2971,7 @@ premierwave_en MACH_PREMIERWAVE_EN PREMIERWAVE_EN 2985
2971wasabi MACH_WASABI WASABI 2986 2971wasabi MACH_WASABI WASABI 2986
2972vivow MACH_VIVOW VIVOW 2987 2972vivow MACH_VIVOW VIVOW 2987
2973mx50_rdp MACH_MX50_RDP MX50_RDP 2988 2973mx50_rdp MACH_MX50_RDP MX50_RDP 2988
2974universal MACH_UNIVERSAL UNIVERSAL 2989 2974universal_c210 MACH_UNIVERSAL_C210 UNIVERSAL_C210 2989
2975real6410 MACH_REAL6410 REAL6410 2990 2975real6410 MACH_REAL6410 REAL6410 2990
2976spx_sakura MACH_SPX_SAKURA SPX_SAKURA 2991 2976spx_sakura MACH_SPX_SAKURA SPX_SAKURA 2991
2977ij3k_2440 MACH_IJ3K_2440 IJ3K_2440 2992 2977ij3k_2440 MACH_IJ3K_2440 IJ3K_2440 2992
@@ -3044,3 +3044,178 @@ harvest_desoto MACH_HARVEST_DESOTO HARVEST_DESOTO 3059
3044msm8x60_qrdc MACH_MSM8X60_QRDC MSM8X60_QRDC 3060 3044msm8x60_qrdc MACH_MSM8X60_QRDC MSM8X60_QRDC 3060
3045spear900 MACH_SPEAR900 SPEAR900 3061 3045spear900 MACH_SPEAR900 SPEAR900 3061
3046pcontrol_g20 MACH_PCONTROL_G20 PCONTROL_G20 3062 3046pcontrol_g20 MACH_PCONTROL_G20 PCONTROL_G20 3062
3047rdstor MACH_RDSTOR RDSTOR 3063
3048usdloader MACH_USDLOADER USDLOADER 3064
3049tsoploader MACH_TSOPLOADER TSOPLOADER 3065
3050kronos MACH_KRONOS KRONOS 3066
3051ffcore MACH_FFCORE FFCORE 3067
3052mone MACH_MONE MONE 3068
3053unit2s MACH_UNIT2S UNIT2S 3069
3054acer_a5 MACH_ACER_A5 ACER_A5 3070
3055etherpro_isp MACH_ETHERPRO_ISP ETHERPRO_ISP 3071
3056stretchs7000 MACH_STRETCHS7000 STRETCHS7000 3072
3057p87_smartsim MACH_P87_SMARTSIM P87_SMARTSIM 3073
3058tulip MACH_TULIP TULIP 3074
3059sunflower MACH_SUNFLOWER SUNFLOWER 3075
3060rib MACH_RIB RIB 3076
3061clod MACH_CLOD CLOD 3077
3062rump MACH_RUMP RUMP 3078
3063tenderloin MACH_TENDERLOIN TENDERLOIN 3079
3064shortloin MACH_SHORTLOIN SHORTLOIN 3080
3065crespo MACH_CRESPO CRESPO 3081
3066antares MACH_ANTARES ANTARES 3082
3067wb40n MACH_WB40N WB40N 3083
3068herring MACH_HERRING HERRING 3084
3069naxy400 MACH_NAXY400 NAXY400 3085
3070naxy1200 MACH_NAXY1200 NAXY1200 3086
3071vpr200 MACH_VPR200 VPR200 3087
3072bug20 MACH_BUG20 BUG20 3088
3073goflexnet MACH_GOFLEXNET GOFLEXNET 3089
3074torbreck MACH_TORBRECK TORBRECK 3090
3075saarb_mg1 MACH_SAARB_MG1 SAARB_MG1 3091
3076callisto MACH_CALLISTO CALLISTO 3092
3077multhsu MACH_MULTHSU MULTHSU 3093
3078saluda MACH_SALUDA SALUDA 3094
3079pemp_omap3_apollo MACH_PEMP_OMAP3_APOLLO PEMP_OMAP3_APOLLO 3095
3080vc0718 MACH_VC0718 VC0718 3096
3081mvblx MACH_MVBLX MVBLX 3097
3082inhand_apeiron MACH_INHAND_APEIRON INHAND_APEIRON 3098
3083inhand_fury MACH_INHAND_FURY INHAND_FURY 3099
3084inhand_siren MACH_INHAND_SIREN INHAND_SIREN 3100
3085hdnvp MACH_HDNVP HDNVP 3101
3086softwinner MACH_SOFTWINNER SOFTWINNER 3102
3087prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
3088nas6210 MACH_NAS6210 NAS6210 3104
3089unisdev MACH_UNISDEV UNISDEV 3105
3090sbca11 MACH_SBCA11 SBCA11 3106
3091saga MACH_SAGA SAGA 3107
3092ns_k330 MACH_NS_K330 NS_K330 3108
3093tanna MACH_TANNA TANNA 3109
3094imate8502 MACH_IMATE8502 IMATE8502 3110
3095aspen MACH_ASPEN ASPEN 3111
3096daintree_cwac MACH_DAINTREE_CWAC DAINTREE_CWAC 3112
3097zmx25 MACH_ZMX25 ZMX25 3113
3098maple1 MACH_MAPLE1 MAPLE1 3114
3099qsd8x72_surf MACH_QSD8X72_SURF QSD8X72_SURF 3115
3100qsd8x72_ffa MACH_QSD8X72_FFA QSD8X72_FFA 3116
3101abilene MACH_ABILENE ABILENE 3117
3102eigen_ttr MACH_EIGEN_TTR EIGEN_TTR 3118
3103iomega_ix2_200 MACH_IOMEGA_IX2_200 IOMEGA_IX2_200 3119
3104coretec_vcx7400 MACH_CORETEC_VCX7400 CORETEC_VCX7400 3120
3105santiago MACH_SANTIAGO SANTIAGO 3121
3106mx257sol MACH_MX257SOL MX257SOL 3122
3107strasbourg MACH_STRASBOURG STRASBOURG 3123
3108msm8x60_fluid MACH_MSM8X60_FLUID MSM8X60_FLUID 3124
3109smartqv5 MACH_SMARTQV5 SMARTQV5 3125
3110smartqv3 MACH_SMARTQV3 SMARTQV3 3126
3111smartqv7 MACH_SMARTQV7 SMARTQV7 3127
3112paz00 MACH_PAZ00 PAZ00 3128
3113acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
3114htcwillow MACH_HTCWILLOW HTCWILLOW 3130
3115fwbd_0404 MACH_FWBD_0404 FWBD_0404 3131
3116hdgu MACH_HDGU HDGU 3132
3117pyramid MACH_PYRAMID PYRAMID 3133
3118epiphan MACH_EPIPHAN EPIPHAN 3134
3119omap_bender MACH_OMAP_BENDER OMAP_BENDER 3135
3120gurnard MACH_GURNARD GURNARD 3136
3121gtl_it5100 MACH_GTL_IT5100 GTL_IT5100 3137
3122bcm2708 MACH_BCM2708 BCM2708 3138
3123mx51_ggc MACH_MX51_GGC MX51_GGC 3139
3124sharespace MACH_SHARESPACE SHARESPACE 3140
3125haba_knx_explorer MACH_HABA_KNX_EXPLORER HABA_KNX_EXPLORER 3141
3126simtec_kirkmod MACH_SIMTEC_KIRKMOD SIMTEC_KIRKMOD 3142
3127crux MACH_CRUX CRUX 3143
3128mx51_bravo MACH_MX51_BRAVO MX51_BRAVO 3144
3129charon MACH_CHARON CHARON 3145
3130picocom3 MACH_PICOCOM3 PICOCOM3 3146
3131picocom4 MACH_PICOCOM4 PICOCOM4 3147
3132serrano MACH_SERRANO SERRANO 3148
3133doubleshot MACH_DOUBLESHOT DOUBLESHOT 3149
3134evsy MACH_EVSY EVSY 3150
3135huashan MACH_HUASHAN HUASHAN 3151
3136lausanne MACH_LAUSANNE LAUSANNE 3152
3137emerald MACH_EMERALD EMERALD 3153
3138tqma35 MACH_TQMA35 TQMA35 3154
3139marvel MACH_MARVEL MARVEL 3155
3140manuae MACH_MANUAE MANUAE 3156
3141chacha MACH_CHACHA CHACHA 3157
3142lemon MACH_LEMON LEMON 3158
3143csc MACH_CSC CSC 3159
3144gira_knxip_router MACH_GIRA_KNXIP_ROUTER GIRA_KNXIP_ROUTER 3160
3145t20 MACH_T20 T20 3161
3146hdmini MACH_HDMINI HDMINI 3162
3147sciphone_g2 MACH_SCIPHONE_G2 SCIPHONE_G2 3163
3148express MACH_EXPRESS EXPRESS 3164
3149express_kt MACH_EXPRESS_KT EXPRESS_KT 3165
3150maximasp MACH_MAXIMASP MAXIMASP 3166
3151nitrogen_imx51 MACH_NITROGEN_IMX51 NITROGEN_IMX51 3167
3152nitrogen_imx53 MACH_NITROGEN_IMX53 NITROGEN_IMX53 3168
3153sunfire MACH_SUNFIRE SUNFIRE 3169
3154arowana MACH_AROWANA AROWANA 3170
3155tegra_daytona MACH_TEGRA_DAYTONA TEGRA_DAYTONA 3171
3156tegra_swordfish MACH_TEGRA_SWORDFISH TEGRA_SWORDFISH 3172
3157edison MACH_EDISON EDISON 3173
3158svp8500v1 MACH_SVP8500V1 SVP8500V1 3174
3159svp8500v2 MACH_SVP8500V2 SVP8500V2 3175
3160svp5500 MACH_SVP5500 SVP5500 3176
3161b5500 MACH_B5500 B5500 3177
3162s5500 MACH_S5500 S5500 3178
3163icon MACH_ICON ICON 3179
3164elephant MACH_ELEPHANT ELEPHANT 3180
3165msm8x60_fusion MACH_MSM8X60_FUSION MSM8X60_FUSION 3181
3166shooter MACH_SHOOTER SHOOTER 3182
3167spade_lte MACH_SPADE_LTE SPADE_LTE 3183
3168philhwani MACH_PHILHWANI PHILHWANI 3184
3169gsncomm MACH_GSNCOMM GSNCOMM 3185
3170strasbourg_a2 MACH_STRASBOURG_A2 STRASBOURG_A2 3186
3171mmm MACH_MMM MMM 3187
3172davinci_dm365_bv MACH_DAVINCI_DM365_BV DAVINCI_DM365_BV 3188
3173ag5evm MACH_AG5EVM AG5EVM 3189
3174sc575plc MACH_SC575PLC SC575PLC 3190
3175sc575hmi MACH_SC575IPC SC575IPC 3191
3176omap3_tdm3730 MACH_OMAP3_TDM3730 OMAP3_TDM3730 3192
3177g7 MACH_G7 G7 3193
3178top9000_eval MACH_TOP9000_EVAL TOP9000_EVAL 3194
3179top9000_su MACH_TOP9000_SU TOP9000_SU 3195
3180utm300 MACH_UTM300 UTM300 3196
3181tsunagi MACH_TSUNAGI TSUNAGI 3197
3182ts75xx MACH_TS75XX TS75XX 3198
3183msm8x60_fusn_ffa MACH_MSM8X60_FUSN_FFA MSM8X60_FUSN_FFA 3199
3184ts47xx MACH_TS47XX TS47XX 3200
3185da850_k5 MACH_DA850_K5 DA850_K5 3201
3186ax502 MACH_AX502 AX502 3202
3187igep0032 MACH_IGEP0032 IGEP0032 3203
3188antero MACH_ANTERO ANTERO 3204
3189synergy MACH_SYNERGY SYNERGY 3205
3190ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
3191wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
3192punica MACH_PUNICA PUNICA 3208
3193sbc_nt250 MACH_SBC_NT250 SBC_NT250 3209
3194mx27_wmultra MACH_MX27_WMULTRA MX27_WMULTRA 3210
3195mackerel MACH_MACKEREL MACKEREL 3211
3196fa9x27 MACH_FA9X27 FA9X27 3213
3197ns2816tb MACH_NS2816TB NS2816TB 3214
3198ns2816_ntpad MACH_NS2816_NTPAD NS2816_NTPAD 3215
3199ns2816_ntnb MACH_NS2816_NTNB NS2816_NTNB 3216
3200kaen MACH_KAEN KAEN 3217
3201nv1000 MACH_NV1000 NV1000 3218
3202nuc950ts MACH_NUC950TS NUC950TS 3219
3203nokia_rm680 MACH_NOKIA_RM680 NOKIA_RM680 3220
3204ast2200 MACH_AST2200 AST2200 3221
3205lead MACH_LEAD LEAD 3222
3206unino1 MACH_UNINO1 UNINO1 3223
3207greeco MACH_GREECO GREECO 3224
3208verdi MACH_VERDI VERDI 3225
3209dm6446_adbox MACH_DM6446_ADBOX DM6446_ADBOX 3226
3210quad_salsa MACH_QUAD_SALSA QUAD_SALSA 3227
3211abb_gma_1_1 MACH_ABB_GMA_1_1 ABB_GMA_1_1 3228
3212svcid MACH_SVCID SVCID 3229
3213msm8960_sim MACH_MSM8960_SIM MSM8960_SIM 3230
3214msm8960_rumi3 MACH_MSM8960_RUMI3 MSM8960_RUMI3 3231
3215icon_g MACH_ICON_G ICON_G 3232
3216mb3 MACH_MB3 MB3 3233
3217gsia18s MACH_GSIA18S GSIA18S 3234
3218pivicc MACH_PIVICC PIVICC 3235
3219pcm048 MACH_PCM048 PCM048 3236
3220dds MACH_DDS DDS 3237
3221chalten_xa1 MACH_CHALTEN_XA1 CHALTEN_XA1 3238
diff --git a/arch/arm/vfp/vfphw.S b/arch/arm/vfp/vfphw.S
index d66cead97d28..9897dcfc16d6 100644
--- a/arch/arm/vfp/vfphw.S
+++ b/arch/arm/vfp/vfphw.S
@@ -206,6 +206,7 @@ ENTRY(vfp_save_state)
206 mov pc, lr 206 mov pc, lr
207ENDPROC(vfp_save_state) 207ENDPROC(vfp_save_state)
208 208
209 .align
209last_VFP_context_address: 210last_VFP_context_address:
210 .word last_VFP_context 211 .word last_VFP_context
211 212
diff --git a/arch/blackfin/kernel/process.c b/arch/blackfin/kernel/process.c
index cd0c090ebc54..b407bc8ad918 100644
--- a/arch/blackfin/kernel/process.c
+++ b/arch/blackfin/kernel/process.c
@@ -7,7 +7,6 @@
7 */ 7 */
8 8
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/smp_lock.h>
11#include <linux/unistd.h> 10#include <linux/unistd.h>
12#include <linux/user.h> 11#include <linux/user.h>
13#include <linux/uaccess.h> 12#include <linux/uaccess.h>
diff --git a/arch/frv/kernel/process.c b/arch/frv/kernel/process.c
index 2b63b0191f52..efad12071c2e 100644
--- a/arch/frv/kernel/process.c
+++ b/arch/frv/kernel/process.c
@@ -16,7 +16,6 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/smp.h> 18#include <linux/smp.h>
19#include <linux/smp_lock.h>
20#include <linux/stddef.h> 19#include <linux/stddef.h>
21#include <linux/unistd.h> 20#include <linux/unistd.h>
22#include <linux/ptrace.h> 21#include <linux/ptrace.h>
diff --git a/arch/h8300/kernel/process.c b/arch/h8300/kernel/process.c
index 97478138e361..933bd388efb2 100644
--- a/arch/h8300/kernel/process.c
+++ b/arch/h8300/kernel/process.c
@@ -28,7 +28,6 @@
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/smp.h> 30#include <linux/smp.h>
31#include <linux/smp_lock.h>
32#include <linux/stddef.h> 31#include <linux/stddef.h>
33#include <linux/unistd.h> 32#include <linux/unistd.h>
34#include <linux/ptrace.h> 33#include <linux/ptrace.h>
diff --git a/arch/ia64/hp/sim/simscsi.c b/arch/ia64/hp/sim/simscsi.c
index 3a078ad3aa44..331de723c676 100644
--- a/arch/ia64/hp/sim/simscsi.c
+++ b/arch/ia64/hp/sim/simscsi.c
@@ -202,7 +202,7 @@ simscsi_readwrite10 (struct scsi_cmnd *sc, int mode)
202} 202}
203 203
204static int 204static int
205simscsi_queuecommand (struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) 205simscsi_queuecommand_lck (struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
206{ 206{
207 unsigned int target_id = sc->device->id; 207 unsigned int target_id = sc->device->id;
208 char fname[MAX_ROOT_LEN+16]; 208 char fname[MAX_ROOT_LEN+16];
@@ -326,6 +326,8 @@ simscsi_queuecommand (struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
326 return 0; 326 return 0;
327} 327}
328 328
329static DEF_SCSI_QCMD(simscsi_queuecommand)
330
329static int 331static int
330simscsi_host_reset (struct scsi_cmnd *sc) 332simscsi_host_reset (struct scsi_cmnd *sc)
331{ 333{
diff --git a/arch/m68k/include/asm/irqflags.h b/arch/m68k/include/asm/irqflags.h
index 4a5b284a1550..7ef4115b8c4a 100644
--- a/arch/m68k/include/asm/irqflags.h
+++ b/arch/m68k/include/asm/irqflags.h
@@ -2,7 +2,9 @@
2#define _M68K_IRQFLAGS_H 2#define _M68K_IRQFLAGS_H
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#ifdef CONFIG_MMU
5#include <linux/hardirq.h> 6#include <linux/hardirq.h>
7#endif
6#include <linux/preempt.h> 8#include <linux/preempt.h>
7#include <asm/thread_info.h> 9#include <asm/thread_info.h>
8#include <asm/entry.h> 10#include <asm/entry.h>
diff --git a/arch/m68k/include/asm/machdep.h b/arch/m68k/include/asm/machdep.h
index 789f3b2de0e9..415d5484916c 100644
--- a/arch/m68k/include/asm/machdep.h
+++ b/arch/m68k/include/asm/machdep.h
@@ -40,5 +40,6 @@ extern unsigned long hw_timer_offset(void);
40extern irqreturn_t arch_timer_interrupt(int irq, void *dummy); 40extern irqreturn_t arch_timer_interrupt(int irq, void *dummy);
41 41
42extern void config_BSP(char *command, int len); 42extern void config_BSP(char *command, int len);
43extern void do_IRQ(int irq, struct pt_regs *fp);
43 44
44#endif /* _M68K_MACHDEP_H */ 45#endif /* _M68K_MACHDEP_H */
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 18732ab23292..c2a1fc23dd75 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -18,7 +18,6 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/fs.h> 19#include <linux/fs.h>
20#include <linux/smp.h> 20#include <linux/smp.h>
21#include <linux/smp_lock.h>
22#include <linux/stddef.h> 21#include <linux/stddef.h>
23#include <linux/unistd.h> 22#include <linux/unistd.h>
24#include <linux/ptrace.h> 23#include <linux/ptrace.h>
diff --git a/arch/m68knommu/kernel/process.c b/arch/m68knommu/kernel/process.c
index 6d3390590e5b..e2a63af5d517 100644
--- a/arch/m68knommu/kernel/process.c
+++ b/arch/m68knommu/kernel/process.c
@@ -19,7 +19,6 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/mm.h> 20#include <linux/mm.h>
21#include <linux/smp.h> 21#include <linux/smp.h>
22#include <linux/smp_lock.h>
23#include <linux/stddef.h> 22#include <linux/stddef.h>
24#include <linux/unistd.h> 23#include <linux/unistd.h>
25#include <linux/ptrace.h> 24#include <linux/ptrace.h>
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 67a2fa2caa49..0a9b5b8b2a19 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -19,6 +19,8 @@ config MIPS
19 select GENERIC_ATOMIC64 if !64BIT 19 select GENERIC_ATOMIC64 if !64BIT
20 select HAVE_DMA_ATTRS 20 select HAVE_DMA_ATTRS
21 select HAVE_DMA_API_DEBUG 21 select HAVE_DMA_API_DEBUG
22 select HAVE_GENERIC_HARDIRQS
23 select GENERIC_IRQ_PROBE
22 24
23menu "Machine selection" 25menu "Machine selection"
24 26
@@ -1664,6 +1666,28 @@ config PAGE_SIZE_64KB
1664 1666
1665endchoice 1667endchoice
1666 1668
1669config FORCE_MAX_ZONEORDER
1670 int "Maximum zone order"
1671 range 13 64 if SYS_SUPPORTS_HUGETLBFS && PAGE_SIZE_32KB
1672 default "13" if SYS_SUPPORTS_HUGETLBFS && PAGE_SIZE_32KB
1673 range 12 64 if SYS_SUPPORTS_HUGETLBFS && PAGE_SIZE_16KB
1674 default "12" if SYS_SUPPORTS_HUGETLBFS && PAGE_SIZE_16KB
1675 range 11 64
1676 default "11"
1677 help
1678 The kernel memory allocator divides physically contiguous memory
1679 blocks into "zones", where each zone is a power of two number of
1680 pages. This option selects the largest power of two that the kernel
1681 keeps in the memory allocator. If you need to allocate very large
1682 blocks of physically contiguous memory, then you may need to
1683 increase this value.
1684
1685 This config option is actually maximum order plus one. For example,
1686 a value of 11 means that the largest free memory block is 2^10 pages.
1687
1688 The page size is not necessarily 4KB. Keep this in mind
1689 when choosing a value for this option.
1690
1667config BOARD_SCACHE 1691config BOARD_SCACHE
1668 bool 1692 bool
1669 1693
@@ -1922,20 +1946,6 @@ config CPU_R4400_WORKAROUNDS
1922 bool 1946 bool
1923 1947
1924# 1948#
1925# Use the generic interrupt handling code in kernel/irq/:
1926#
1927config GENERIC_HARDIRQS
1928 bool
1929 default y
1930
1931config GENERIC_IRQ_PROBE
1932 bool
1933 default y
1934
1935config IRQ_PER_CPU
1936 bool
1937
1938#
1939# - Highmem only makes sense for the 32-bit kernel. 1949# - Highmem only makes sense for the 32-bit kernel.
1940# - The current highmem code will only work properly on physically indexed 1950# - The current highmem code will only work properly on physically indexed
1941# caches such as R3000, SB1, R7000 or those that look like they're virtually 1951# caches such as R3000, SB1, R7000 or those that look like they're virtually
diff --git a/arch/mips/alchemy/common/platform.c b/arch/mips/alchemy/common/platform.c
index 3691630931d6..9e7814db3d03 100644
--- a/arch/mips/alchemy/common/platform.c
+++ b/arch/mips/alchemy/common/platform.c
@@ -27,6 +27,7 @@
27static void alchemy_8250_pm(struct uart_port *port, unsigned int state, 27static void alchemy_8250_pm(struct uart_port *port, unsigned int state,
28 unsigned int old_state) 28 unsigned int old_state)
29{ 29{
30#ifdef CONFIG_SERIAL_8250
30 switch (state) { 31 switch (state) {
31 case 0: 32 case 0:
32 if ((__raw_readl(port->membase + UART_MOD_CNTRL) & 3) != 3) { 33 if ((__raw_readl(port->membase + UART_MOD_CNTRL) & 3) != 3) {
@@ -49,6 +50,7 @@ static void alchemy_8250_pm(struct uart_port *port, unsigned int state,
49 serial8250_do_pm(port, state, old_state); 50 serial8250_do_pm(port, state, old_state);
50 break; 51 break;
51 } 52 }
53#endif
52} 54}
53 55
54#define PORT(_base, _irq) \ 56#define PORT(_base, _irq) \
diff --git a/arch/mips/alchemy/devboards/prom.c b/arch/mips/alchemy/devboards/prom.c
index b30df5c97ad3..baeb21385058 100644
--- a/arch/mips/alchemy/devboards/prom.c
+++ b/arch/mips/alchemy/devboards/prom.c
@@ -54,10 +54,9 @@ void __init prom_init(void)
54 54
55 prom_init_cmdline(); 55 prom_init_cmdline();
56 memsize_str = prom_getenv("memsize"); 56 memsize_str = prom_getenv("memsize");
57 if (!memsize_str) 57 if (!memsize_str || strict_strtoul(memsize_str, 0, &memsize))
58 memsize = ALCHEMY_BOARD_DEFAULT_MEMSIZE; 58 memsize = ALCHEMY_BOARD_DEFAULT_MEMSIZE;
59 else 59
60 strict_strtoul(memsize_str, 0, &memsize);
61 add_memory_region(0, memsize, BOOT_MEM_RAM); 60 add_memory_region(0, memsize, BOOT_MEM_RAM);
62} 61}
63 62
diff --git a/arch/mips/ar7/clock.c b/arch/mips/ar7/clock.c
index fc0e7154e8d6..2ca4ada1c291 100644
--- a/arch/mips/ar7/clock.c
+++ b/arch/mips/ar7/clock.c
@@ -239,12 +239,12 @@ static void tnetd7300_set_clock(u32 shift, struct tnetd7300_clock *clock,
239 calculate(base_clock, frequency, &prediv, &postdiv, &mul); 239 calculate(base_clock, frequency, &prediv, &postdiv, &mul);
240 240
241 writel(((prediv - 1) << PREDIV_SHIFT) | (postdiv - 1), &clock->ctrl); 241 writel(((prediv - 1) << PREDIV_SHIFT) | (postdiv - 1), &clock->ctrl);
242 msleep(1); 242 mdelay(1);
243 writel(4, &clock->pll); 243 writel(4, &clock->pll);
244 while (readl(&clock->pll) & PLL_STATUS) 244 while (readl(&clock->pll) & PLL_STATUS)
245 ; 245 ;
246 writel(((mul - 1) << MUL_SHIFT) | (0xff << 3) | 0x0e, &clock->pll); 246 writel(((mul - 1) << MUL_SHIFT) | (0xff << 3) | 0x0e, &clock->pll);
247 msleep(75); 247 mdelay(75);
248} 248}
249 249
250static void __init tnetd7300_init_clocks(void) 250static void __init tnetd7300_init_clocks(void)
@@ -456,7 +456,7 @@ void clk_put(struct clk *clk)
456} 456}
457EXPORT_SYMBOL(clk_put); 457EXPORT_SYMBOL(clk_put);
458 458
459int __init ar7_init_clocks(void) 459void __init ar7_init_clocks(void)
460{ 460{
461 switch (ar7_chip_id()) { 461 switch (ar7_chip_id()) {
462 case AR7_CHIP_7100: 462 case AR7_CHIP_7100:
@@ -472,7 +472,4 @@ int __init ar7_init_clocks(void)
472 } 472 }
473 /* adjust vbus clock rate */ 473 /* adjust vbus clock rate */
474 vbus_clk.rate = bus_clk.rate / 2; 474 vbus_clk.rate = bus_clk.rate / 2;
475
476 return 0;
477} 475}
478arch_initcall(ar7_init_clocks);
diff --git a/arch/mips/ar7/time.c b/arch/mips/ar7/time.c
index 5fb8a0134085..22c93213b233 100644
--- a/arch/mips/ar7/time.c
+++ b/arch/mips/ar7/time.c
@@ -30,6 +30,9 @@ void __init plat_time_init(void)
30{ 30{
31 struct clk *cpu_clk; 31 struct clk *cpu_clk;
32 32
33 /* Initialize ar7 clocks so the CPU clock frequency is correct */
34 ar7_init_clocks();
35
33 cpu_clk = clk_get(NULL, "cpu"); 36 cpu_clk = clk_get(NULL, "cpu");
34 if (IS_ERR(cpu_clk)) { 37 if (IS_ERR(cpu_clk)) {
35 printk(KERN_ERR "unable to get cpu clock\n"); 38 printk(KERN_ERR "unable to get cpu clock\n");
diff --git a/arch/mips/bcm47xx/setup.c b/arch/mips/bcm47xx/setup.c
index b1aee33efd11..c95f90bf734c 100644
--- a/arch/mips/bcm47xx/setup.c
+++ b/arch/mips/bcm47xx/setup.c
@@ -32,7 +32,6 @@
32#include <asm/reboot.h> 32#include <asm/reboot.h>
33#include <asm/time.h> 33#include <asm/time.h>
34#include <bcm47xx.h> 34#include <bcm47xx.h>
35#include <asm/fw/cfe/cfe_api.h>
36#include <asm/mach-bcm47xx/nvram.h> 35#include <asm/mach-bcm47xx/nvram.h>
37 36
38struct ssb_bus ssb_bcm47xx; 37struct ssb_bus ssb_bcm47xx;
@@ -57,68 +56,112 @@ static void bcm47xx_machine_halt(void)
57 cpu_relax(); 56 cpu_relax();
58} 57}
59 58
60static void str2eaddr(char *str, char *dest) 59#define READ_FROM_NVRAM(_outvar, name, buf) \
61{ 60 if (nvram_getenv(name, buf, sizeof(buf)) >= 0)\
62 int i = 0; 61 sprom->_outvar = simple_strtoul(buf, NULL, 0);
63 62
64 if (str == NULL) { 63static void bcm47xx_fill_sprom(struct ssb_sprom *sprom)
65 memset(dest, 0, 6); 64{
66 return; 65 char buf[100];
66 u32 boardflags;
67
68 memset(sprom, 0, sizeof(struct ssb_sprom));
69
70 sprom->revision = 1; /* Fallback: Old hardware does not define this. */
71 READ_FROM_NVRAM(revision, "sromrev", buf);
72 if (nvram_getenv("il0macaddr", buf, sizeof(buf)) >= 0)
73 nvram_parse_macaddr(buf, sprom->il0mac);
74 if (nvram_getenv("et0macaddr", buf, sizeof(buf)) >= 0)
75 nvram_parse_macaddr(buf, sprom->et0mac);
76 if (nvram_getenv("et1macaddr", buf, sizeof(buf)) >= 0)
77 nvram_parse_macaddr(buf, sprom->et1mac);
78 READ_FROM_NVRAM(et0phyaddr, "et0phyaddr", buf);
79 READ_FROM_NVRAM(et1phyaddr, "et1phyaddr", buf);
80 READ_FROM_NVRAM(et0mdcport, "et0mdcport", buf);
81 READ_FROM_NVRAM(et1mdcport, "et1mdcport", buf);
82 READ_FROM_NVRAM(board_rev, "boardrev", buf);
83 READ_FROM_NVRAM(country_code, "ccode", buf);
84 READ_FROM_NVRAM(ant_available_a, "aa5g", buf);
85 READ_FROM_NVRAM(ant_available_bg, "aa2g", buf);
86 READ_FROM_NVRAM(pa0b0, "pa0b0", buf);
87 READ_FROM_NVRAM(pa0b1, "pa0b1", buf);
88 READ_FROM_NVRAM(pa0b2, "pa0b2", buf);
89 READ_FROM_NVRAM(pa1b0, "pa1b0", buf);
90 READ_FROM_NVRAM(pa1b1, "pa1b1", buf);
91 READ_FROM_NVRAM(pa1b2, "pa1b2", buf);
92 READ_FROM_NVRAM(pa1lob0, "pa1lob0", buf);
93 READ_FROM_NVRAM(pa1lob2, "pa1lob1", buf);
94 READ_FROM_NVRAM(pa1lob1, "pa1lob2", buf);
95 READ_FROM_NVRAM(pa1hib0, "pa1hib0", buf);
96 READ_FROM_NVRAM(pa1hib2, "pa1hib1", buf);
97 READ_FROM_NVRAM(pa1hib1, "pa1hib2", buf);
98 READ_FROM_NVRAM(gpio0, "wl0gpio0", buf);
99 READ_FROM_NVRAM(gpio1, "wl0gpio1", buf);
100 READ_FROM_NVRAM(gpio2, "wl0gpio2", buf);
101 READ_FROM_NVRAM(gpio3, "wl0gpio3", buf);
102 READ_FROM_NVRAM(maxpwr_bg, "pa0maxpwr", buf);
103 READ_FROM_NVRAM(maxpwr_al, "pa1lomaxpwr", buf);
104 READ_FROM_NVRAM(maxpwr_a, "pa1maxpwr", buf);
105 READ_FROM_NVRAM(maxpwr_ah, "pa1himaxpwr", buf);
106 READ_FROM_NVRAM(itssi_a, "pa1itssit", buf);
107 READ_FROM_NVRAM(itssi_bg, "pa0itssit", buf);
108 READ_FROM_NVRAM(tri2g, "tri2g", buf);
109 READ_FROM_NVRAM(tri5gl, "tri5gl", buf);
110 READ_FROM_NVRAM(tri5g, "tri5g", buf);
111 READ_FROM_NVRAM(tri5gh, "tri5gh", buf);
112 READ_FROM_NVRAM(rxpo2g, "rxpo2g", buf);
113 READ_FROM_NVRAM(rxpo5g, "rxpo5g", buf);
114 READ_FROM_NVRAM(rssisav2g, "rssisav2g", buf);
115 READ_FROM_NVRAM(rssismc2g, "rssismc2g", buf);
116 READ_FROM_NVRAM(rssismf2g, "rssismf2g", buf);
117 READ_FROM_NVRAM(bxa2g, "bxa2g", buf);
118 READ_FROM_NVRAM(rssisav5g, "rssisav5g", buf);
119 READ_FROM_NVRAM(rssismc5g, "rssismc5g", buf);
120 READ_FROM_NVRAM(rssismf5g, "rssismf5g", buf);
121 READ_FROM_NVRAM(bxa5g, "bxa5g", buf);
122 READ_FROM_NVRAM(cck2gpo, "cck2gpo", buf);
123 READ_FROM_NVRAM(ofdm2gpo, "ofdm2gpo", buf);
124 READ_FROM_NVRAM(ofdm5glpo, "ofdm5glpo", buf);
125 READ_FROM_NVRAM(ofdm5gpo, "ofdm5gpo", buf);
126 READ_FROM_NVRAM(ofdm5ghpo, "ofdm5ghpo", buf);
127
128 if (nvram_getenv("boardflags", buf, sizeof(buf)) >= 0) {
129 boardflags = simple_strtoul(buf, NULL, 0);
130 if (boardflags) {
131 sprom->boardflags_lo = (boardflags & 0x0000FFFFU);
132 sprom->boardflags_hi = (boardflags & 0xFFFF0000U) >> 16;
133 }
67 } 134 }
68 135 if (nvram_getenv("boardflags2", buf, sizeof(buf)) >= 0) {
69 for (;;) { 136 boardflags = simple_strtoul(buf, NULL, 0);
70 dest[i++] = (char) simple_strtoul(str, NULL, 16); 137 if (boardflags) {
71 str += 2; 138 sprom->boardflags2_lo = (boardflags & 0x0000FFFFU);
72 if (!*str++ || i == 6) 139 sprom->boardflags2_hi = (boardflags & 0xFFFF0000U) >> 16;
73 break; 140 }
74 } 141 }
75} 142}
76 143
77static int bcm47xx_get_invariants(struct ssb_bus *bus, 144static int bcm47xx_get_invariants(struct ssb_bus *bus,
78 struct ssb_init_invariants *iv) 145 struct ssb_init_invariants *iv)
79{ 146{
80 char buf[100]; 147 char buf[20];
81 148
82 /* Fill boardinfo structure */ 149 /* Fill boardinfo structure */
83 memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo)); 150 memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
84 151
85 if (cfe_getenv("boardvendor", buf, sizeof(buf)) >= 0 || 152 if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0)
86 nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0) 153 iv->boardinfo.vendor = (u16)simple_strtoul(buf, NULL, 0);
87 iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0); 154 else
88 if (cfe_getenv("boardtype", buf, sizeof(buf)) >= 0 || 155 iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
89 nvram_getenv("boardtype", buf, sizeof(buf)) >= 0) 156 if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
90 iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0); 157 iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
91 if (cfe_getenv("boardrev", buf, sizeof(buf)) >= 0 || 158 if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
92 nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
93 iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0); 159 iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);
94 160
95 /* Fill sprom structure */ 161 bcm47xx_fill_sprom(&iv->sprom);
96 memset(&(iv->sprom), 0, sizeof(struct ssb_sprom));
97 iv->sprom.revision = 3;
98
99 if (cfe_getenv("et0macaddr", buf, sizeof(buf)) >= 0 ||
100 nvram_getenv("et0macaddr", buf, sizeof(buf)) >= 0)
101 str2eaddr(buf, iv->sprom.et0mac);
102 162
103 if (cfe_getenv("et1macaddr", buf, sizeof(buf)) >= 0 || 163 if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
104 nvram_getenv("et1macaddr", buf, sizeof(buf)) >= 0) 164 iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
105 str2eaddr(buf, iv->sprom.et1mac);
106
107 if (cfe_getenv("et0phyaddr", buf, sizeof(buf)) >= 0 ||
108 nvram_getenv("et0phyaddr", buf, sizeof(buf)) >= 0)
109 iv->sprom.et0phyaddr = simple_strtoul(buf, NULL, 0);
110
111 if (cfe_getenv("et1phyaddr", buf, sizeof(buf)) >= 0 ||
112 nvram_getenv("et1phyaddr", buf, sizeof(buf)) >= 0)
113 iv->sprom.et1phyaddr = simple_strtoul(buf, NULL, 0);
114
115 if (cfe_getenv("et0mdcport", buf, sizeof(buf)) >= 0 ||
116 nvram_getenv("et0mdcport", buf, sizeof(buf)) >= 0)
117 iv->sprom.et0mdcport = simple_strtoul(buf, NULL, 10);
118
119 if (cfe_getenv("et1mdcport", buf, sizeof(buf)) >= 0 ||
120 nvram_getenv("et1mdcport", buf, sizeof(buf)) >= 0)
121 iv->sprom.et1mdcport = simple_strtoul(buf, NULL, 10);
122 165
123 return 0; 166 return 0;
124} 167}
@@ -126,12 +169,28 @@ static int bcm47xx_get_invariants(struct ssb_bus *bus,
126void __init plat_mem_setup(void) 169void __init plat_mem_setup(void)
127{ 170{
128 int err; 171 int err;
172 char buf[100];
173 struct ssb_mipscore *mcore;
129 174
130 err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE, 175 err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE,
131 bcm47xx_get_invariants); 176 bcm47xx_get_invariants);
132 if (err) 177 if (err)
133 panic("Failed to initialize SSB bus (err %d)\n", err); 178 panic("Failed to initialize SSB bus (err %d)\n", err);
134 179
180 mcore = &ssb_bcm47xx.mipscore;
181 if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
182 if (strstr(buf, "console=ttyS1")) {
183 struct ssb_serial_port port;
184
185 printk(KERN_DEBUG "Swapping serial ports!\n");
186 /* swap serial ports */
187 memcpy(&port, &mcore->serial_ports[0], sizeof(port));
188 memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
189 sizeof(port));
190 memcpy(&mcore->serial_ports[1], &port, sizeof(port));
191 }
192 }
193
135 _machine_restart = bcm47xx_machine_restart; 194 _machine_restart = bcm47xx_machine_restart;
136 _machine_halt = bcm47xx_machine_halt; 195 _machine_halt = bcm47xx_machine_halt;
137 pm_power_off = bcm47xx_machine_halt; 196 pm_power_off = bcm47xx_machine_halt;
diff --git a/arch/mips/include/asm/cpu.h b/arch/mips/include/asm/cpu.h
index 06d59dcbe243..86877539c6e8 100644
--- a/arch/mips/include/asm/cpu.h
+++ b/arch/mips/include/asm/cpu.h
@@ -111,8 +111,8 @@
111 * These are the PRID's for when 23:16 == PRID_COMP_BROADCOM 111 * These are the PRID's for when 23:16 == PRID_COMP_BROADCOM
112 */ 112 */
113 113
114#define PRID_IMP_BMIPS4KC 0x4000 114#define PRID_IMP_BMIPS32_REV4 0x4000
115#define PRID_IMP_BMIPS32 0x8000 115#define PRID_IMP_BMIPS32_REV8 0x8000
116#define PRID_IMP_BMIPS3300 0x9000 116#define PRID_IMP_BMIPS3300 0x9000
117#define PRID_IMP_BMIPS3300_ALT 0x9100 117#define PRID_IMP_BMIPS3300_ALT 0x9100
118#define PRID_IMP_BMIPS3300_BUG 0x0000 118#define PRID_IMP_BMIPS3300_BUG 0x0000
diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
index fd1d39eb7431..455c0ac7d4ea 100644
--- a/arch/mips/include/asm/elf.h
+++ b/arch/mips/include/asm/elf.h
@@ -249,7 +249,8 @@ extern struct mips_abi mips_abi_n32;
249 249
250#define SET_PERSONALITY(ex) \ 250#define SET_PERSONALITY(ex) \
251do { \ 251do { \
252 set_personality(PER_LINUX); \ 252 if (personality(current->personality) != PER_LINUX) \
253 set_personality(PER_LINUX); \
253 \ 254 \
254 current->thread.abi = &mips_abi; \ 255 current->thread.abi = &mips_abi; \
255} while (0) 256} while (0)
@@ -296,6 +297,8 @@ do { \
296 297
297#define SET_PERSONALITY(ex) \ 298#define SET_PERSONALITY(ex) \
298do { \ 299do { \
300 unsigned int p; \
301 \
299 clear_thread_flag(TIF_32BIT_REGS); \ 302 clear_thread_flag(TIF_32BIT_REGS); \
300 clear_thread_flag(TIF_32BIT_ADDR); \ 303 clear_thread_flag(TIF_32BIT_ADDR); \
301 \ 304 \
@@ -304,7 +307,8 @@ do { \
304 else \ 307 else \
305 current->thread.abi = &mips_abi; \ 308 current->thread.abi = &mips_abi; \
306 \ 309 \
307 if (current->personality != PER_LINUX32) \ 310 p = personality(current->personality); \
311 if (p != PER_LINUX32 && p != PER_LINUX) \
308 set_personality(PER_LINUX); \ 312 set_personality(PER_LINUX); \
309} while (0) 313} while (0)
310 314
diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h
index c98bf514ec7d..5b017f23e243 100644
--- a/arch/mips/include/asm/io.h
+++ b/arch/mips/include/asm/io.h
@@ -329,10 +329,14 @@ static inline void pfx##write##bwlq(type val, \
329 "dsrl32 %L0, %L0, 0" "\n\t" \ 329 "dsrl32 %L0, %L0, 0" "\n\t" \
330 "dsll32 %M0, %M0, 0" "\n\t" \ 330 "dsll32 %M0, %M0, 0" "\n\t" \
331 "or %L0, %L0, %M0" "\n\t" \ 331 "or %L0, %L0, %M0" "\n\t" \
332 ".set push" "\n\t" \
333 ".set noreorder" "\n\t" \
334 ".set nomacro" "\n\t" \
332 "sd %L0, %2" "\n\t" \ 335 "sd %L0, %2" "\n\t" \
336 ".set pop" "\n\t" \
333 ".set mips0" "\n" \ 337 ".set mips0" "\n" \
334 : "=r" (__tmp) \ 338 : "=r" (__tmp) \
335 : "0" (__val), "m" (*__mem)); \ 339 : "0" (__val), "R" (*__mem)); \
336 if (irq) \ 340 if (irq) \
337 local_irq_restore(__flags); \ 341 local_irq_restore(__flags); \
338 } else \ 342 } else \
@@ -355,12 +359,16 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \
355 local_irq_save(__flags); \ 359 local_irq_save(__flags); \
356 __asm__ __volatile__( \ 360 __asm__ __volatile__( \
357 ".set mips3" "\t\t# __readq" "\n\t" \ 361 ".set mips3" "\t\t# __readq" "\n\t" \
362 ".set push" "\n\t" \
363 ".set noreorder" "\n\t" \
364 ".set nomacro" "\n\t" \
358 "ld %L0, %1" "\n\t" \ 365 "ld %L0, %1" "\n\t" \
366 ".set pop" "\n\t" \
359 "dsra32 %M0, %L0, 0" "\n\t" \ 367 "dsra32 %M0, %L0, 0" "\n\t" \
360 "sll %L0, %L0, 0" "\n\t" \ 368 "sll %L0, %L0, 0" "\n\t" \
361 ".set mips0" "\n" \ 369 ".set mips0" "\n" \
362 : "=r" (__val) \ 370 : "=r" (__val) \
363 : "m" (*__mem)); \ 371 : "R" (*__mem)); \
364 if (irq) \ 372 if (irq) \
365 local_irq_restore(__flags); \ 373 local_irq_restore(__flags); \
366 } else { \ 374 } else { \
diff --git a/arch/mips/include/asm/mach-ar7/ar7.h b/arch/mips/include/asm/mach-ar7/ar7.h
index 7919d76186bf..07d3fadb2443 100644
--- a/arch/mips/include/asm/mach-ar7/ar7.h
+++ b/arch/mips/include/asm/mach-ar7/ar7.h
@@ -201,7 +201,6 @@ static inline void ar7_device_off(u32 bit)
201} 201}
202 202
203int __init ar7_gpio_init(void); 203int __init ar7_gpio_init(void);
204 204void __init ar7_init_clocks(void);
205int __init ar7_gpio_init(void);
206 205
207#endif /* __AR7_H__ */ 206#endif /* __AR7_H__ */
diff --git a/arch/mips/include/asm/mach-bcm47xx/nvram.h b/arch/mips/include/asm/mach-bcm47xx/nvram.h
index c58ebd8bc155..9759588ba3cf 100644
--- a/arch/mips/include/asm/mach-bcm47xx/nvram.h
+++ b/arch/mips/include/asm/mach-bcm47xx/nvram.h
@@ -12,6 +12,7 @@
12#define __NVRAM_H 12#define __NVRAM_H
13 13
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/kernel.h>
15 16
16struct nvram_header { 17struct nvram_header {
17 u32 magic; 18 u32 magic;
@@ -36,4 +37,10 @@ struct nvram_header {
36 37
37extern int nvram_getenv(char *name, char *val, size_t val_len); 38extern int nvram_getenv(char *name, char *val, size_t val_len);
38 39
40static inline void nvram_parse_macaddr(char *buf, u8 *macaddr)
41{
42 sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0], &macaddr[1],
43 &macaddr[2], &macaddr[3], &macaddr[4], &macaddr[5]);
44}
45
39#endif 46#endif
diff --git a/arch/mips/jz4740/board-qi_lb60.c b/arch/mips/jz4740/board-qi_lb60.c
index de4433c5a771..2c0e107966ad 100644
--- a/arch/mips/jz4740/board-qi_lb60.c
+++ b/arch/mips/jz4740/board-qi_lb60.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Copyright (c) 2009 Qi Hardware inc., 6 * Copyright (c) 2009 Qi Hardware inc.,
7 * Author: Xiangfu Liu <xiangfu@qi-hardware.com> 7 * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
8 * Copyright 2010, Lars-Petrer Clausen <lars@metafoo.de> 8 * Copyright 2010, Lars-Peter Clausen <lars@metafoo.de>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 or later 11 * it under the terms of the GNU General Public License version 2 or later
@@ -235,7 +235,7 @@ static const unsigned int qi_lb60_keypad_rows[] = {
235 QI_LB60_GPIO_KEYIN(3), 235 QI_LB60_GPIO_KEYIN(3),
236 QI_LB60_GPIO_KEYIN(4), 236 QI_LB60_GPIO_KEYIN(4),
237 QI_LB60_GPIO_KEYIN(5), 237 QI_LB60_GPIO_KEYIN(5),
238 QI_LB60_GPIO_KEYIN(7), 238 QI_LB60_GPIO_KEYIN(6),
239 QI_LB60_GPIO_KEYIN8, 239 QI_LB60_GPIO_KEYIN8,
240}; 240};
241 241
diff --git a/arch/mips/jz4740/platform.c b/arch/mips/jz4740/platform.c
index 95bc2b5b14f1..1cc9e544d16b 100644
--- a/arch/mips/jz4740/platform.c
+++ b/arch/mips/jz4740/platform.c
@@ -208,7 +208,7 @@ struct platform_device jz4740_i2s_device = {
208 208
209/* PCM */ 209/* PCM */
210struct platform_device jz4740_pcm_device = { 210struct platform_device jz4740_pcm_device = {
211 .name = "jz4740-pcm", 211 .name = "jz4740-pcm-audio",
212 .id = -1, 212 .id = -1,
213}; 213};
214 214
diff --git a/arch/mips/jz4740/prom.c b/arch/mips/jz4740/prom.c
index cfeac15eb2e4..4a70407f55bb 100644
--- a/arch/mips/jz4740/prom.c
+++ b/arch/mips/jz4740/prom.c
@@ -23,7 +23,7 @@
23#include <asm/bootinfo.h> 23#include <asm/bootinfo.h>
24#include <asm/mach-jz4740/base.h> 24#include <asm/mach-jz4740/base.h>
25 25
26void jz4740_init_cmdline(int argc, char *argv[]) 26static __init void jz4740_init_cmdline(int argc, char *argv[])
27{ 27{
28 unsigned int count = COMMAND_LINE_SIZE - 1; 28 unsigned int count = COMMAND_LINE_SIZE - 1;
29 int i; 29 int i;
diff --git a/arch/mips/kernel/cevt-r4k.c b/arch/mips/kernel/cevt-r4k.c
index 2f4d7a99bcc2..98c5a9737c14 100644
--- a/arch/mips/kernel/cevt-r4k.c
+++ b/arch/mips/kernel/cevt-r4k.c
@@ -32,7 +32,7 @@ static int mips_next_event(unsigned long delta,
32 cnt = read_c0_count(); 32 cnt = read_c0_count();
33 cnt += delta; 33 cnt += delta;
34 write_c0_compare(cnt); 34 write_c0_compare(cnt);
35 res = ((int)(read_c0_count() - cnt) > 0) ? -ETIME : 0; 35 res = ((int)(read_c0_count() - cnt) >= 0) ? -ETIME : 0;
36 return res; 36 return res;
37} 37}
38 38
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 71620e19827a..68dae7b6b5db 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -905,7 +905,8 @@ static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
905{ 905{
906 decode_configs(c); 906 decode_configs(c);
907 switch (c->processor_id & 0xff00) { 907 switch (c->processor_id & 0xff00) {
908 case PRID_IMP_BMIPS32: 908 case PRID_IMP_BMIPS32_REV4:
909 case PRID_IMP_BMIPS32_REV8:
909 c->cputype = CPU_BMIPS32; 910 c->cputype = CPU_BMIPS32;
910 __cpu_name[cpu] = "Broadcom BMIPS32"; 911 __cpu_name[cpu] = "Broadcom BMIPS32";
911 break; 912 break;
@@ -933,10 +934,6 @@ static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
933 __cpu_name[cpu] = "Broadcom BMIPS5000"; 934 __cpu_name[cpu] = "Broadcom BMIPS5000";
934 c->options |= MIPS_CPU_ULRI; 935 c->options |= MIPS_CPU_ULRI;
935 break; 936 break;
936 case PRID_IMP_BMIPS4KC:
937 c->cputype = CPU_4KC;
938 __cpu_name[cpu] = "MIPS 4Kc";
939 break;
940 } 937 }
941} 938}
942 939
diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c
index 6343b4a5b835..876a75cc376f 100644
--- a/arch/mips/kernel/linux32.c
+++ b/arch/mips/kernel/linux32.c
@@ -251,14 +251,15 @@ SYSCALL_DEFINE5(n32_msgrcv, int, msqid, u32, msgp, size_t, msgsz,
251 251
252SYSCALL_DEFINE1(32_personality, unsigned long, personality) 252SYSCALL_DEFINE1(32_personality, unsigned long, personality)
253{ 253{
254 unsigned int p = personality & 0xffffffff;
254 int ret; 255 int ret;
255 personality &= 0xffffffff; 256
256 if (personality(current->personality) == PER_LINUX32 && 257 if (personality(current->personality) == PER_LINUX32 &&
257 personality == PER_LINUX) 258 personality(p) == PER_LINUX)
258 personality = PER_LINUX32; 259 p = (p & ~PER_MASK) | PER_LINUX32;
259 ret = sys_personality(personality); 260 ret = sys_personality(p);
260 if (ret == PER_LINUX32) 261 if (ret != -1 && personality(ret) == PER_LINUX32)
261 ret = PER_LINUX; 262 ret = (ret & ~PER_MASK) | PER_LINUX;
262 return ret; 263 return ret;
263} 264}
264 265
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 99960940d4a4..ae167df73ddd 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -142,7 +142,6 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
142 childregs->regs[7] = 0; /* Clear error flag */ 142 childregs->regs[7] = 0; /* Clear error flag */
143 143
144 childregs->regs[2] = 0; /* Child gets zero as return value */ 144 childregs->regs[2] = 0; /* Child gets zero as return value */
145 regs->regs[2] = p->pid;
146 145
147 if (childregs->cp0_status & ST0_CU0) { 146 if (childregs->cp0_status & ST0_CU0) {
148 childregs->regs[28] = (unsigned long) ti; 147 childregs->regs[28] = (unsigned long) ti;
diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
index e000b278f024..9dbe58368953 100644
--- a/arch/mips/kernel/prom.c
+++ b/arch/mips/kernel/prom.c
@@ -100,7 +100,7 @@ void __init device_tree_init(void)
100 return; 100 return;
101 101
102 base = virt_to_phys((void *)initial_boot_params); 102 base = virt_to_phys((void *)initial_boot_params);
103 size = initial_boot_params->totalsize; 103 size = be32_to_cpu(initial_boot_params->totalsize);
104 104
105 /* Before we do anything, lets reserve the dt blob */ 105 /* Before we do anything, lets reserve the dt blob */
106 reserve_mem_mach(base, size); 106 reserve_mem_mach(base, size);
diff --git a/arch/mips/kernel/smp-mt.c b/arch/mips/kernel/smp-mt.c
index 43e7cdc5ded2..c0e81418ba21 100644
--- a/arch/mips/kernel/smp-mt.c
+++ b/arch/mips/kernel/smp-mt.c
@@ -153,7 +153,7 @@ static void __cpuinit vsmp_init_secondary(void)
153{ 153{
154 extern int gic_present; 154 extern int gic_present;
155 155
156 /* This is Malta specific: IPI,performance and timer inetrrupts */ 156 /* This is Malta specific: IPI,performance and timer interrupts */
157 if (gic_present) 157 if (gic_present)
158 change_c0_status(ST0_IM, STATUSF_IP3 | STATUSF_IP4 | 158 change_c0_status(ST0_IM, STATUSF_IP3 | STATUSF_IP4 |
159 STATUSF_IP6 | STATUSF_IP7); 159 STATUSF_IP6 | STATUSF_IP7);
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 8e9fbe75894e..e97104302541 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -83,7 +83,8 @@ extern asmlinkage void handle_mcheck(void);
83extern asmlinkage void handle_reserved(void); 83extern asmlinkage void handle_reserved(void);
84 84
85extern int fpu_emulator_cop1Handler(struct pt_regs *xcp, 85extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
86 struct mips_fpu_struct *ctx, int has_fpu); 86 struct mips_fpu_struct *ctx, int has_fpu,
87 void *__user *fault_addr);
87 88
88void (*board_be_init)(void); 89void (*board_be_init)(void);
89int (*board_be_handler)(struct pt_regs *regs, int is_fixup); 90int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
@@ -661,12 +662,36 @@ asmlinkage void do_ov(struct pt_regs *regs)
661 force_sig_info(SIGFPE, &info, current); 662 force_sig_info(SIGFPE, &info, current);
662} 663}
663 664
665static int process_fpemu_return(int sig, void __user *fault_addr)
666{
667 if (sig == SIGSEGV || sig == SIGBUS) {
668 struct siginfo si = {0};
669 si.si_addr = fault_addr;
670 si.si_signo = sig;
671 if (sig == SIGSEGV) {
672 if (find_vma(current->mm, (unsigned long)fault_addr))
673 si.si_code = SEGV_ACCERR;
674 else
675 si.si_code = SEGV_MAPERR;
676 } else {
677 si.si_code = BUS_ADRERR;
678 }
679 force_sig_info(sig, &si, current);
680 return 1;
681 } else if (sig) {
682 force_sig(sig, current);
683 return 1;
684 } else {
685 return 0;
686 }
687}
688
664/* 689/*
665 * XXX Delayed fp exceptions when doing a lazy ctx switch XXX 690 * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
666 */ 691 */
667asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31) 692asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
668{ 693{
669 siginfo_t info; 694 siginfo_t info = {0};
670 695
671 if (notify_die(DIE_FP, "FP exception", regs, 0, regs_to_trapnr(regs), SIGFPE) 696 if (notify_die(DIE_FP, "FP exception", regs, 0, regs_to_trapnr(regs), SIGFPE)
672 == NOTIFY_STOP) 697 == NOTIFY_STOP)
@@ -675,6 +700,7 @@ asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
675 700
676 if (fcr31 & FPU_CSR_UNI_X) { 701 if (fcr31 & FPU_CSR_UNI_X) {
677 int sig; 702 int sig;
703 void __user *fault_addr = NULL;
678 704
679 /* 705 /*
680 * Unimplemented operation exception. If we've got the full 706 * Unimplemented operation exception. If we've got the full
@@ -690,7 +716,8 @@ asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
690 lose_fpu(1); 716 lose_fpu(1);
691 717
692 /* Run the emulator */ 718 /* Run the emulator */
693 sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1); 719 sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
720 &fault_addr);
694 721
695 /* 722 /*
696 * We can't allow the emulated instruction to leave any of 723 * We can't allow the emulated instruction to leave any of
@@ -702,8 +729,7 @@ asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
702 own_fpu(1); /* Using the FPU again. */ 729 own_fpu(1); /* Using the FPU again. */
703 730
704 /* If something went wrong, signal */ 731 /* If something went wrong, signal */
705 if (sig) 732 process_fpemu_return(sig, fault_addr);
706 force_sig(sig, current);
707 733
708 return; 734 return;
709 } else if (fcr31 & FPU_CSR_INV_X) 735 } else if (fcr31 & FPU_CSR_INV_X)
@@ -996,11 +1022,11 @@ asmlinkage void do_cpu(struct pt_regs *regs)
996 1022
997 if (!raw_cpu_has_fpu) { 1023 if (!raw_cpu_has_fpu) {
998 int sig; 1024 int sig;
1025 void __user *fault_addr = NULL;
999 sig = fpu_emulator_cop1Handler(regs, 1026 sig = fpu_emulator_cop1Handler(regs,
1000 &current->thread.fpu, 0); 1027 &current->thread.fpu,
1001 if (sig) 1028 0, &fault_addr);
1002 force_sig(sig, current); 1029 if (!process_fpemu_return(sig, fault_addr))
1003 else
1004 mt_ase_fp_affinity(); 1030 mt_ase_fp_affinity();
1005 } 1031 }
1006 1032
diff --git a/arch/mips/kernel/vpe.c b/arch/mips/kernel/vpe.c
index 3eb3cde2f661..6a1fdfef8fde 100644
--- a/arch/mips/kernel/vpe.c
+++ b/arch/mips/kernel/vpe.c
@@ -1092,6 +1092,10 @@ static int vpe_open(struct inode *inode, struct file *filp)
1092 1092
1093 /* this of-course trashes what was there before... */ 1093 /* this of-course trashes what was there before... */
1094 v->pbuffer = vmalloc(P_SIZE); 1094 v->pbuffer = vmalloc(P_SIZE);
1095 if (!v->pbuffer) {
1096 pr_warning("VPE loader: unable to allocate memory\n");
1097 return -ENOMEM;
1098 }
1095 v->plen = P_SIZE; 1099 v->plen = P_SIZE;
1096 v->load_addr = NULL; 1100 v->load_addr = NULL;
1097 v->len = 0; 1101 v->len = 0;
@@ -1149,10 +1153,9 @@ static int vpe_release(struct inode *inode, struct file *filp)
1149 if (ret < 0) 1153 if (ret < 0)
1150 v->shared_ptr = NULL; 1154 v->shared_ptr = NULL;
1151 1155
1152 // cleanup any temp buffers 1156 vfree(v->pbuffer);
1153 if (v->pbuffer)
1154 vfree(v->pbuffer);
1155 v->plen = 0; 1157 v->plen = 0;
1158
1156 return ret; 1159 return ret;
1157} 1160}
1158 1161
@@ -1169,11 +1172,6 @@ static ssize_t vpe_write(struct file *file, const char __user * buffer,
1169 if (v == NULL) 1172 if (v == NULL)
1170 return -ENODEV; 1173 return -ENODEV;
1171 1174
1172 if (v->pbuffer == NULL) {
1173 printk(KERN_ERR "VPE loader: no buffer for program\n");
1174 return -ENOMEM;
1175 }
1176
1177 if ((count + v->len) > v->plen) { 1175 if ((count + v->len) > v->plen) {
1178 printk(KERN_WARNING 1176 printk(KERN_WARNING
1179 "VPE loader: elf size too big. Perhaps strip uneeded symbols\n"); 1177 "VPE loader: elf size too big. Perhaps strip uneeded symbols\n");
diff --git a/arch/mips/lib/memset.S b/arch/mips/lib/memset.S
index 77dc3b20110a..606c8a9efe3b 100644
--- a/arch/mips/lib/memset.S
+++ b/arch/mips/lib/memset.S
@@ -161,16 +161,16 @@ FEXPORT(__bzero)
161 161
162.Lfwd_fixup: 162.Lfwd_fixup:
163 PTR_L t0, TI_TASK($28) 163 PTR_L t0, TI_TASK($28)
164 LONG_L t0, THREAD_BUADDR(t0)
165 andi a2, 0x3f 164 andi a2, 0x3f
165 LONG_L t0, THREAD_BUADDR(t0)
166 LONG_ADDU a2, t1 166 LONG_ADDU a2, t1
167 jr ra 167 jr ra
168 LONG_SUBU a2, t0 168 LONG_SUBU a2, t0
169 169
170.Lpartial_fixup: 170.Lpartial_fixup:
171 PTR_L t0, TI_TASK($28) 171 PTR_L t0, TI_TASK($28)
172 LONG_L t0, THREAD_BUADDR(t0)
173 andi a2, LONGMASK 172 andi a2, LONGMASK
173 LONG_L t0, THREAD_BUADDR(t0)
174 LONG_ADDU a2, t1 174 LONG_ADDU a2, t1
175 jr ra 175 jr ra
176 LONG_SUBU a2, t0 176 LONG_SUBU a2, t0
diff --git a/arch/mips/loongson/common/env.c b/arch/mips/loongson/common/env.c
index ae4cff97a56c..11b193f848f8 100644
--- a/arch/mips/loongson/common/env.c
+++ b/arch/mips/loongson/common/env.c
@@ -29,9 +29,9 @@ unsigned long memsize, highmemsize;
29 29
30#define parse_even_earlier(res, option, p) \ 30#define parse_even_earlier(res, option, p) \
31do { \ 31do { \
32 int ret; \
32 if (strncmp(option, (char *)p, strlen(option)) == 0) \ 33 if (strncmp(option, (char *)p, strlen(option)) == 0) \
33 strict_strtol((char *)p + strlen(option"="), \ 34 ret = strict_strtol((char *)p + strlen(option"="), 10, &res); \
34 10, &res); \
35} while (0) 35} while (0)
36 36
37void __init prom_init_env(void) 37void __init prom_init_env(void)
diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
index b2ad1b0910ff..d32cb0503110 100644
--- a/arch/mips/math-emu/cp1emu.c
+++ b/arch/mips/math-emu/cp1emu.c
@@ -64,7 +64,7 @@ static int fpu_emu(struct pt_regs *, struct mips_fpu_struct *,
64 64
65#if __mips >= 4 && __mips != 32 65#if __mips >= 4 && __mips != 32
66static int fpux_emu(struct pt_regs *, 66static int fpux_emu(struct pt_regs *,
67 struct mips_fpu_struct *, mips_instruction); 67 struct mips_fpu_struct *, mips_instruction, void *__user *);
68#endif 68#endif
69 69
70/* Further private data for which no space exists in mips_fpu_struct */ 70/* Further private data for which no space exists in mips_fpu_struct */
@@ -208,16 +208,23 @@ static inline int cop1_64bit(struct pt_regs *xcp)
208 * Two instructions if the instruction is in a branch delay slot. 208 * Two instructions if the instruction is in a branch delay slot.
209 */ 209 */
210 210
211static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx) 211static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
212 void *__user *fault_addr)
212{ 213{
213 mips_instruction ir; 214 mips_instruction ir;
214 unsigned long emulpc, contpc; 215 unsigned long emulpc, contpc;
215 unsigned int cond; 216 unsigned int cond;
216 217
217 if (get_user(ir, (mips_instruction __user *) xcp->cp0_epc)) { 218 if (!access_ok(VERIFY_READ, xcp->cp0_epc, sizeof(mips_instruction))) {
218 MIPS_FPU_EMU_INC_STATS(errors); 219 MIPS_FPU_EMU_INC_STATS(errors);
220 *fault_addr = (mips_instruction __user *)xcp->cp0_epc;
219 return SIGBUS; 221 return SIGBUS;
220 } 222 }
223 if (__get_user(ir, (mips_instruction __user *) xcp->cp0_epc)) {
224 MIPS_FPU_EMU_INC_STATS(errors);
225 *fault_addr = (mips_instruction __user *)xcp->cp0_epc;
226 return SIGSEGV;
227 }
221 228
222 /* XXX NEC Vr54xx bug workaround */ 229 /* XXX NEC Vr54xx bug workaround */
223 if ((xcp->cp0_cause & CAUSEF_BD) && !isBranchInstr(&ir)) 230 if ((xcp->cp0_cause & CAUSEF_BD) && !isBranchInstr(&ir))
@@ -245,10 +252,16 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx)
245#endif 252#endif
246 return SIGILL; 253 return SIGILL;
247 } 254 }
248 if (get_user(ir, (mips_instruction __user *) emulpc)) { 255 if (!access_ok(VERIFY_READ, emulpc, sizeof(mips_instruction))) {
249 MIPS_FPU_EMU_INC_STATS(errors); 256 MIPS_FPU_EMU_INC_STATS(errors);
257 *fault_addr = (mips_instruction __user *)emulpc;
250 return SIGBUS; 258 return SIGBUS;
251 } 259 }
260 if (__get_user(ir, (mips_instruction __user *) emulpc)) {
261 MIPS_FPU_EMU_INC_STATS(errors);
262 *fault_addr = (mips_instruction __user *)emulpc;
263 return SIGSEGV;
264 }
252 /* __compute_return_epc() will have updated cp0_epc */ 265 /* __compute_return_epc() will have updated cp0_epc */
253 contpc = xcp->cp0_epc; 266 contpc = xcp->cp0_epc;
254 /* In order not to confuse ptrace() et al, tweak context */ 267 /* In order not to confuse ptrace() et al, tweak context */
@@ -269,10 +282,17 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx)
269 u64 val; 282 u64 val;
270 283
271 MIPS_FPU_EMU_INC_STATS(loads); 284 MIPS_FPU_EMU_INC_STATS(loads);
272 if (get_user(val, va)) { 285
286 if (!access_ok(VERIFY_READ, va, sizeof(u64))) {
273 MIPS_FPU_EMU_INC_STATS(errors); 287 MIPS_FPU_EMU_INC_STATS(errors);
288 *fault_addr = va;
274 return SIGBUS; 289 return SIGBUS;
275 } 290 }
291 if (__get_user(val, va)) {
292 MIPS_FPU_EMU_INC_STATS(errors);
293 *fault_addr = va;
294 return SIGSEGV;
295 }
276 DITOREG(val, MIPSInst_RT(ir)); 296 DITOREG(val, MIPSInst_RT(ir));
277 break; 297 break;
278 } 298 }
@@ -284,10 +304,16 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx)
284 304
285 MIPS_FPU_EMU_INC_STATS(stores); 305 MIPS_FPU_EMU_INC_STATS(stores);
286 DIFROMREG(val, MIPSInst_RT(ir)); 306 DIFROMREG(val, MIPSInst_RT(ir));
287 if (put_user(val, va)) { 307 if (!access_ok(VERIFY_WRITE, va, sizeof(u64))) {
288 MIPS_FPU_EMU_INC_STATS(errors); 308 MIPS_FPU_EMU_INC_STATS(errors);
309 *fault_addr = va;
289 return SIGBUS; 310 return SIGBUS;
290 } 311 }
312 if (__put_user(val, va)) {
313 MIPS_FPU_EMU_INC_STATS(errors);
314 *fault_addr = va;
315 return SIGSEGV;
316 }
291 break; 317 break;
292 } 318 }
293 319
@@ -297,10 +323,16 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx)
297 u32 val; 323 u32 val;
298 324
299 MIPS_FPU_EMU_INC_STATS(loads); 325 MIPS_FPU_EMU_INC_STATS(loads);
300 if (get_user(val, va)) { 326 if (!access_ok(VERIFY_READ, va, sizeof(u32))) {
301 MIPS_FPU_EMU_INC_STATS(errors); 327 MIPS_FPU_EMU_INC_STATS(errors);
328 *fault_addr = va;
302 return SIGBUS; 329 return SIGBUS;
303 } 330 }
331 if (__get_user(val, va)) {
332 MIPS_FPU_EMU_INC_STATS(errors);
333 *fault_addr = va;
334 return SIGSEGV;
335 }
304 SITOREG(val, MIPSInst_RT(ir)); 336 SITOREG(val, MIPSInst_RT(ir));
305 break; 337 break;
306 } 338 }
@@ -312,10 +344,16 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx)
312 344
313 MIPS_FPU_EMU_INC_STATS(stores); 345 MIPS_FPU_EMU_INC_STATS(stores);
314 SIFROMREG(val, MIPSInst_RT(ir)); 346 SIFROMREG(val, MIPSInst_RT(ir));
315 if (put_user(val, va)) { 347 if (!access_ok(VERIFY_WRITE, va, sizeof(u32))) {
316 MIPS_FPU_EMU_INC_STATS(errors); 348 MIPS_FPU_EMU_INC_STATS(errors);
349 *fault_addr = va;
317 return SIGBUS; 350 return SIGBUS;
318 } 351 }
352 if (__put_user(val, va)) {
353 MIPS_FPU_EMU_INC_STATS(errors);
354 *fault_addr = va;
355 return SIGSEGV;
356 }
319 break; 357 break;
320 } 358 }
321 359
@@ -440,11 +478,18 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx)
440 contpc = (xcp->cp0_epc + 478 contpc = (xcp->cp0_epc +
441 (MIPSInst_SIMM(ir) << 2)); 479 (MIPSInst_SIMM(ir) << 2));
442 480
443 if (get_user(ir, 481 if (!access_ok(VERIFY_READ, xcp->cp0_epc,
444 (mips_instruction __user *) xcp->cp0_epc)) { 482 sizeof(mips_instruction))) {
445 MIPS_FPU_EMU_INC_STATS(errors); 483 MIPS_FPU_EMU_INC_STATS(errors);
484 *fault_addr = (mips_instruction __user *)xcp->cp0_epc;
446 return SIGBUS; 485 return SIGBUS;
447 } 486 }
487 if (__get_user(ir,
488 (mips_instruction __user *) xcp->cp0_epc)) {
489 MIPS_FPU_EMU_INC_STATS(errors);
490 *fault_addr = (mips_instruction __user *)xcp->cp0_epc;
491 return SIGSEGV;
492 }
448 493
449 switch (MIPSInst_OPCODE(ir)) { 494 switch (MIPSInst_OPCODE(ir)) {
450 case lwc1_op: 495 case lwc1_op:
@@ -506,9 +551,8 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx)
506 551
507#if __mips >= 4 && __mips != 32 552#if __mips >= 4 && __mips != 32
508 case cop1x_op:{ 553 case cop1x_op:{
509 int sig; 554 int sig = fpux_emu(xcp, ctx, ir, fault_addr);
510 555 if (sig)
511 if ((sig = fpux_emu(xcp, ctx, ir)))
512 return sig; 556 return sig;
513 break; 557 break;
514 } 558 }
@@ -604,7 +648,7 @@ DEF3OP(nmadd, dp, ieee754dp_mul, ieee754dp_add, ieee754dp_neg);
604DEF3OP(nmsub, dp, ieee754dp_mul, ieee754dp_sub, ieee754dp_neg); 648DEF3OP(nmsub, dp, ieee754dp_mul, ieee754dp_sub, ieee754dp_neg);
605 649
606static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx, 650static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
607 mips_instruction ir) 651 mips_instruction ir, void *__user *fault_addr)
608{ 652{
609 unsigned rcsr = 0; /* resulting csr */ 653 unsigned rcsr = 0; /* resulting csr */
610 654
@@ -624,10 +668,16 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
624 xcp->regs[MIPSInst_FT(ir)]); 668 xcp->regs[MIPSInst_FT(ir)]);
625 669
626 MIPS_FPU_EMU_INC_STATS(loads); 670 MIPS_FPU_EMU_INC_STATS(loads);
627 if (get_user(val, va)) { 671 if (!access_ok(VERIFY_READ, va, sizeof(u32))) {
628 MIPS_FPU_EMU_INC_STATS(errors); 672 MIPS_FPU_EMU_INC_STATS(errors);
673 *fault_addr = va;
629 return SIGBUS; 674 return SIGBUS;
630 } 675 }
676 if (__get_user(val, va)) {
677 MIPS_FPU_EMU_INC_STATS(errors);
678 *fault_addr = va;
679 return SIGSEGV;
680 }
631 SITOREG(val, MIPSInst_FD(ir)); 681 SITOREG(val, MIPSInst_FD(ir));
632 break; 682 break;
633 683
@@ -638,10 +688,16 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
638 MIPS_FPU_EMU_INC_STATS(stores); 688 MIPS_FPU_EMU_INC_STATS(stores);
639 689
640 SIFROMREG(val, MIPSInst_FS(ir)); 690 SIFROMREG(val, MIPSInst_FS(ir));
641 if (put_user(val, va)) { 691 if (!access_ok(VERIFY_WRITE, va, sizeof(u32))) {
642 MIPS_FPU_EMU_INC_STATS(errors); 692 MIPS_FPU_EMU_INC_STATS(errors);
693 *fault_addr = va;
643 return SIGBUS; 694 return SIGBUS;
644 } 695 }
696 if (put_user(val, va)) {
697 MIPS_FPU_EMU_INC_STATS(errors);
698 *fault_addr = va;
699 return SIGSEGV;
700 }
645 break; 701 break;
646 702
647 case madd_s_op: 703 case madd_s_op:
@@ -701,10 +757,16 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
701 xcp->regs[MIPSInst_FT(ir)]); 757 xcp->regs[MIPSInst_FT(ir)]);
702 758
703 MIPS_FPU_EMU_INC_STATS(loads); 759 MIPS_FPU_EMU_INC_STATS(loads);
704 if (get_user(val, va)) { 760 if (!access_ok(VERIFY_READ, va, sizeof(u64))) {
705 MIPS_FPU_EMU_INC_STATS(errors); 761 MIPS_FPU_EMU_INC_STATS(errors);
762 *fault_addr = va;
706 return SIGBUS; 763 return SIGBUS;
707 } 764 }
765 if (__get_user(val, va)) {
766 MIPS_FPU_EMU_INC_STATS(errors);
767 *fault_addr = va;
768 return SIGSEGV;
769 }
708 DITOREG(val, MIPSInst_FD(ir)); 770 DITOREG(val, MIPSInst_FD(ir));
709 break; 771 break;
710 772
@@ -714,10 +776,16 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
714 776
715 MIPS_FPU_EMU_INC_STATS(stores); 777 MIPS_FPU_EMU_INC_STATS(stores);
716 DIFROMREG(val, MIPSInst_FS(ir)); 778 DIFROMREG(val, MIPSInst_FS(ir));
717 if (put_user(val, va)) { 779 if (!access_ok(VERIFY_WRITE, va, sizeof(u64))) {
718 MIPS_FPU_EMU_INC_STATS(errors); 780 MIPS_FPU_EMU_INC_STATS(errors);
781 *fault_addr = va;
719 return SIGBUS; 782 return SIGBUS;
720 } 783 }
784 if (__put_user(val, va)) {
785 MIPS_FPU_EMU_INC_STATS(errors);
786 *fault_addr = va;
787 return SIGSEGV;
788 }
721 break; 789 break;
722 790
723 case madd_d_op: 791 case madd_d_op:
@@ -1242,7 +1310,7 @@ static int fpu_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
1242} 1310}
1243 1311
1244int fpu_emulator_cop1Handler(struct pt_regs *xcp, struct mips_fpu_struct *ctx, 1312int fpu_emulator_cop1Handler(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
1245 int has_fpu) 1313 int has_fpu, void *__user *fault_addr)
1246{ 1314{
1247 unsigned long oldepc, prevepc; 1315 unsigned long oldepc, prevepc;
1248 mips_instruction insn; 1316 mips_instruction insn;
@@ -1252,10 +1320,16 @@ int fpu_emulator_cop1Handler(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
1252 do { 1320 do {
1253 prevepc = xcp->cp0_epc; 1321 prevepc = xcp->cp0_epc;
1254 1322
1255 if (get_user(insn, (mips_instruction __user *) xcp->cp0_epc)) { 1323 if (!access_ok(VERIFY_READ, xcp->cp0_epc, sizeof(mips_instruction))) {
1256 MIPS_FPU_EMU_INC_STATS(errors); 1324 MIPS_FPU_EMU_INC_STATS(errors);
1325 *fault_addr = (mips_instruction __user *)xcp->cp0_epc;
1257 return SIGBUS; 1326 return SIGBUS;
1258 } 1327 }
1328 if (__get_user(insn, (mips_instruction __user *) xcp->cp0_epc)) {
1329 MIPS_FPU_EMU_INC_STATS(errors);
1330 *fault_addr = (mips_instruction __user *)xcp->cp0_epc;
1331 return SIGSEGV;
1332 }
1259 if (insn == 0) 1333 if (insn == 0)
1260 xcp->cp0_epc += 4; /* skip nops */ 1334 xcp->cp0_epc += 4; /* skip nops */
1261 else { 1335 else {
@@ -1267,7 +1341,7 @@ int fpu_emulator_cop1Handler(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
1267 */ 1341 */
1268 /* convert to ieee library modes */ 1342 /* convert to ieee library modes */
1269 ieee754_csr.rm = ieee_rm[ieee754_csr.rm]; 1343 ieee754_csr.rm = ieee_rm[ieee754_csr.rm];
1270 sig = cop1Emulate(xcp, ctx); 1344 sig = cop1Emulate(xcp, ctx, fault_addr);
1271 /* revert to mips rounding mode */ 1345 /* revert to mips rounding mode */
1272 ieee754_csr.rm = mips_rm[ieee754_csr.rm]; 1346 ieee754_csr.rm = mips_rm[ieee754_csr.rm];
1273 } 1347 }
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index 4fc1a0fbe007..21ea14efb837 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -288,7 +288,7 @@ int mips_dma_supported(struct device *dev, u64 mask)
288 return plat_dma_supported(dev, mask); 288 return plat_dma_supported(dev, mask);
289} 289}
290 290
291void mips_dma_cache_sync(struct device *dev, void *vaddr, size_t size, 291void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
292 enum dma_data_direction direction) 292 enum dma_data_direction direction)
293{ 293{
294 BUG_ON(direction == DMA_NONE); 294 BUG_ON(direction == DMA_NONE);
@@ -298,6 +298,8 @@ void mips_dma_cache_sync(struct device *dev, void *vaddr, size_t size,
298 __dma_sync((unsigned long)vaddr, size, direction); 298 __dma_sync((unsigned long)vaddr, size, direction);
299} 299}
300 300
301EXPORT_SYMBOL(dma_cache_sync);
302
301static struct dma_map_ops mips_default_dma_map_ops = { 303static struct dma_map_ops mips_default_dma_map_ops = {
302 .alloc_coherent = mips_dma_alloc_coherent, 304 .alloc_coherent = mips_dma_alloc_coherent,
303 .free_coherent = mips_dma_free_coherent, 305 .free_coherent = mips_dma_free_coherent,
diff --git a/arch/mips/mm/sc-mips.c b/arch/mips/mm/sc-mips.c
index 505fecad4684..9cca8de00545 100644
--- a/arch/mips/mm/sc-mips.c
+++ b/arch/mips/mm/sc-mips.c
@@ -68,6 +68,9 @@ static struct bcache_ops mips_sc_ops = {
68 */ 68 */
69static inline int mips_sc_is_activated(struct cpuinfo_mips *c) 69static inline int mips_sc_is_activated(struct cpuinfo_mips *c)
70{ 70{
71 unsigned int config2 = read_c0_config2();
72 unsigned int tmp;
73
71 /* Check the bypass bit (L2B) */ 74 /* Check the bypass bit (L2B) */
72 switch (c->cputype) { 75 switch (c->cputype) {
73 case CPU_34K: 76 case CPU_34K:
@@ -83,6 +86,7 @@ static inline int mips_sc_is_activated(struct cpuinfo_mips *c)
83 c->scache.linesz = 2 << tmp; 86 c->scache.linesz = 2 << tmp;
84 else 87 else
85 return 0; 88 return 0;
89 return 1;
86} 90}
87 91
88static inline int __init mips_sc_probe(void) 92static inline int __init mips_sc_probe(void)
diff --git a/arch/mips/pmc-sierra/yosemite/py-console.c b/arch/mips/pmc-sierra/yosemite/py-console.c
index b7f1d9c4a8a3..434d7b1a8c6a 100644
--- a/arch/mips/pmc-sierra/yosemite/py-console.c
+++ b/arch/mips/pmc-sierra/yosemite/py-console.c
@@ -65,11 +65,15 @@ static unsigned char readb_outer_space(unsigned long long phys)
65 65
66 __asm__ __volatile__ ( 66 __asm__ __volatile__ (
67 " .set mips3 \n" 67 " .set mips3 \n"
68 " .set push \n"
69 " .set noreorder \n"
70 " .set nomacro \n"
68 " ld %0, %1 \n" 71 " ld %0, %1 \n"
72 " .set pop \n"
69 " lbu %0, (%0) \n" 73 " lbu %0, (%0) \n"
70 " .set mips0 \n" 74 " .set mips0 \n"
71 : "=r" (res) 75 : "=r" (res)
72 : "m" (vaddr)); 76 : "R" (vaddr));
73 77
74 write_c0_status(sr); 78 write_c0_status(sr);
75 ssnop_4(); 79 ssnop_4();
@@ -89,11 +93,15 @@ static void writeb_outer_space(unsigned long long phys, unsigned char c)
89 93
90 __asm__ __volatile__ ( 94 __asm__ __volatile__ (
91 " .set mips3 \n" 95 " .set mips3 \n"
96 " .set push \n"
97 " .set noreorder \n"
98 " .set nomacro \n"
92 " ld %0, %1 \n" 99 " ld %0, %1 \n"
100 " .set pop \n"
93 " sb %2, (%0) \n" 101 " sb %2, (%0) \n"
94 " .set mips0 \n" 102 " .set mips0 \n"
95 : "=&r" (tmp) 103 : "=&r" (tmp)
96 : "m" (vaddr), "r" (c)); 104 : "R" (vaddr), "r" (c));
97 105
98 write_c0_status(sr); 106 write_c0_status(sr);
99 ssnop_4(); 107 ssnop_4();
diff --git a/arch/mips/sibyte/swarm/setup.c b/arch/mips/sibyte/swarm/setup.c
index c308989fc464..41707a245dea 100644
--- a/arch/mips/sibyte/swarm/setup.c
+++ b/arch/mips/sibyte/swarm/setup.c
@@ -82,7 +82,7 @@ int swarm_be_handler(struct pt_regs *regs, int is_fixup)
82enum swarm_rtc_type { 82enum swarm_rtc_type {
83 RTC_NONE, 83 RTC_NONE,
84 RTC_XICOR, 84 RTC_XICOR,
85 RTC_M4LT81 85 RTC_M41T81,
86}; 86};
87 87
88enum swarm_rtc_type swarm_rtc_type; 88enum swarm_rtc_type swarm_rtc_type;
@@ -96,7 +96,7 @@ void read_persistent_clock(struct timespec *ts)
96 sec = xicor_get_time(); 96 sec = xicor_get_time();
97 break; 97 break;
98 98
99 case RTC_M4LT81: 99 case RTC_M41T81:
100 sec = m41t81_get_time(); 100 sec = m41t81_get_time();
101 break; 101 break;
102 102
@@ -115,7 +115,7 @@ int rtc_mips_set_time(unsigned long sec)
115 case RTC_XICOR: 115 case RTC_XICOR:
116 return xicor_set_time(sec); 116 return xicor_set_time(sec);
117 117
118 case RTC_M4LT81: 118 case RTC_M41T81:
119 return m41t81_set_time(sec); 119 return m41t81_set_time(sec);
120 120
121 case RTC_NONE: 121 case RTC_NONE:
@@ -141,7 +141,7 @@ void __init plat_mem_setup(void)
141 if (xicor_probe()) 141 if (xicor_probe())
142 swarm_rtc_type = RTC_XICOR; 142 swarm_rtc_type = RTC_XICOR;
143 if (m41t81_probe()) 143 if (m41t81_probe())
144 swarm_rtc_type = RTC_M4LT81; 144 swarm_rtc_type = RTC_M41T81;
145 145
146#ifdef CONFIG_VT 146#ifdef CONFIG_VT
147 screen_info = (struct screen_info) { 147 screen_info = (struct screen_info) {
diff --git a/arch/mn10300/include/asm/syscall.h b/arch/mn10300/include/asm/syscall.h
new file mode 100644
index 000000000000..b44b0bb75a01
--- /dev/null
+++ b/arch/mn10300/include/asm/syscall.h
@@ -0,0 +1,117 @@
1/* Access to user system call parameters and results
2 *
3 * See asm-generic/syscall.h for function descriptions.
4 *
5 * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
6 * Written by David Howells (dhowells@redhat.com)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public Licence
10 * as published by the Free Software Foundation; either version
11 * 2 of the Licence, or (at your option) any later version.
12 */
13
14#ifndef _ASM_SYSCALL_H
15#define _ASM_SYSCALL_H
16
17#include <linux/sched.h>
18#include <linux/err.h>
19
20extern const unsigned long sys_call_table[];
21
22static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
23{
24 return regs->orig_d0;
25}
26
27static inline void syscall_rollback(struct task_struct *task,
28 struct pt_regs *regs)
29{
30 regs->d0 = regs->orig_d0;
31}
32
33static inline long syscall_get_error(struct task_struct *task,
34 struct pt_regs *regs)
35{
36 unsigned long error = regs->d0;
37 return IS_ERR_VALUE(error) ? error : 0;
38}
39
40static inline long syscall_get_return_value(struct task_struct *task,
41 struct pt_regs *regs)
42{
43 return regs->d0;
44}
45
46static inline void syscall_set_return_value(struct task_struct *task,
47 struct pt_regs *regs,
48 int error, long val)
49{
50 regs->d0 = (long) error ?: val;
51}
52
53static inline void syscall_get_arguments(struct task_struct *task,
54 struct pt_regs *regs,
55 unsigned int i, unsigned int n,
56 unsigned long *args)
57{
58 switch (i) {
59 case 0:
60 if (!n--) break;
61 *args++ = regs->a0;
62 case 1:
63 if (!n--) break;
64 *args++ = regs->d1;
65 case 2:
66 if (!n--) break;
67 *args++ = regs->a3;
68 case 3:
69 if (!n--) break;
70 *args++ = regs->a2;
71 case 4:
72 if (!n--) break;
73 *args++ = regs->d3;
74 case 5:
75 if (!n--) break;
76 *args++ = regs->d2;
77 case 6:
78 if (!n--) break;
79 default:
80 BUG();
81 break;
82 }
83}
84
85static inline void syscall_set_arguments(struct task_struct *task,
86 struct pt_regs *regs,
87 unsigned int i, unsigned int n,
88 const unsigned long *args)
89{
90 switch (i) {
91 case 0:
92 if (!n--) break;
93 regs->a0 = *args++;
94 case 1:
95 if (!n--) break;
96 regs->d1 = *args++;
97 case 2:
98 if (!n--) break;
99 regs->a3 = *args++;
100 case 3:
101 if (!n--) break;
102 regs->a2 = *args++;
103 case 4:
104 if (!n--) break;
105 regs->d3 = *args++;
106 case 5:
107 if (!n--) break;
108 regs->d2 = *args++;
109 case 6:
110 if (!n--) break;
111 default:
112 BUG();
113 break;
114 }
115}
116
117#endif /* _ASM_SYSCALL_H */
diff --git a/arch/mn10300/kernel/gdb-io-serial.c b/arch/mn10300/kernel/gdb-io-serial.c
index 0d5d63c91dc3..f28dc99c6f72 100644
--- a/arch/mn10300/kernel/gdb-io-serial.c
+++ b/arch/mn10300/kernel/gdb-io-serial.c
@@ -73,7 +73,8 @@ void gdbstub_io_init(void)
73 GDBPORT_SERIAL_IER = UART_IER_RDI | UART_IER_RLSI; 73 GDBPORT_SERIAL_IER = UART_IER_RDI | UART_IER_RLSI;
74 74
75 /* permit level 0 IRQs to take place */ 75 /* permit level 0 IRQs to take place */
76 local_change_intr_mask_level(NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL + 1)); 76 arch_local_change_intr_mask_level(
77 NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL + 1));
77} 78}
78 79
79/* 80/*
diff --git a/arch/mn10300/kernel/gdb-io-ttysm.c b/arch/mn10300/kernel/gdb-io-ttysm.c
index 97dfda23342c..abdeea153c89 100644
--- a/arch/mn10300/kernel/gdb-io-ttysm.c
+++ b/arch/mn10300/kernel/gdb-io-ttysm.c
@@ -87,7 +87,8 @@ void __init gdbstub_io_init(void)
87 tmp = *gdbstub_port->_control; 87 tmp = *gdbstub_port->_control;
88 88
89 /* permit level 0 IRQs only */ 89 /* permit level 0 IRQs only */
90 local_change_intr_mask_level(NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL + 1)); 90 arch_local_change_intr_mask_level(
91 NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL + 1));
91} 92}
92 93
93/* 94/*
diff --git a/arch/mn10300/kernel/gdb-stub.c b/arch/mn10300/kernel/gdb-stub.c
index a5fc3f05309b..b169d99d9f20 100644
--- a/arch/mn10300/kernel/gdb-stub.c
+++ b/arch/mn10300/kernel/gdb-stub.c
@@ -1194,7 +1194,8 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
1194 1194
1195 asm volatile("mov mdr,%0" : "=d"(mdr)); 1195 asm volatile("mov mdr,%0" : "=d"(mdr));
1196 local_save_flags(epsw); 1196 local_save_flags(epsw);
1197 local_change_intr_mask_level(NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL + 1)); 1197 arch_local_change_intr_mask_level(
1198 NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL + 1));
1198 1199
1199 gdbstub_store_fpu(); 1200 gdbstub_store_fpu();
1200 1201
diff --git a/arch/mn10300/kernel/process.c b/arch/mn10300/kernel/process.c
index 0d0f8049a17b..e1b14a6ed544 100644
--- a/arch/mn10300/kernel/process.c
+++ b/arch/mn10300/kernel/process.c
@@ -14,7 +14,6 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/mm.h> 15#include <linux/mm.h>
16#include <linux/smp.h> 16#include <linux/smp.h>
17#include <linux/smp_lock.h>
18#include <linux/stddef.h> 17#include <linux/stddef.h>
19#include <linux/unistd.h> 18#include <linux/unistd.h>
20#include <linux/ptrace.h> 19#include <linux/ptrace.h>
diff --git a/arch/mn10300/kernel/time.c b/arch/mn10300/kernel/time.c
index f860a340acc9..75da468090b9 100644
--- a/arch/mn10300/kernel/time.c
+++ b/arch/mn10300/kernel/time.c
@@ -40,21 +40,17 @@ unsigned long long sched_clock(void)
40 unsigned long long ll; 40 unsigned long long ll;
41 unsigned l[2]; 41 unsigned l[2];
42 } tsc64, result; 42 } tsc64, result;
43 unsigned long tsc, tmp; 43 unsigned long tmp;
44 unsigned product[3]; /* 96-bit intermediate value */ 44 unsigned product[3]; /* 96-bit intermediate value */
45 45
46 /* cnt32_to_63() is not safe with preemption */ 46 /* cnt32_to_63() is not safe with preemption */
47 preempt_disable(); 47 preempt_disable();
48 48
49 /* read the TSC value 49 /* expand the tsc to 64-bits.
50 */
51 tsc = get_cycles();
52
53 /* expand to 64-bits.
54 * - sched_clock() must be called once a minute or better or the 50 * - sched_clock() must be called once a minute or better or the
55 * following will go horribly wrong - see cnt32_to_63() 51 * following will go horribly wrong - see cnt32_to_63()
56 */ 52 */
57 tsc64.ll = cnt32_to_63(tsc) & 0x7fffffffffffffffULL; 53 tsc64.ll = cnt32_to_63(get_cycles()) & 0x7fffffffffffffffULL;
58 54
59 preempt_enable(); 55 preempt_enable();
60 56
diff --git a/arch/parisc/hpux/sys_hpux.c b/arch/parisc/hpux/sys_hpux.c
index ba430a03bc7a..30394081d9b6 100644
--- a/arch/parisc/hpux/sys_hpux.c
+++ b/arch/parisc/hpux/sys_hpux.c
@@ -28,7 +28,6 @@
28#include <linux/namei.h> 28#include <linux/namei.h>
29#include <linux/sched.h> 29#include <linux/sched.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/smp_lock.h>
32#include <linux/syscalls.h> 31#include <linux/syscalls.h>
33#include <linux/utsname.h> 32#include <linux/utsname.h>
34#include <linux/vfs.h> 33#include <linux/vfs.h>
diff --git a/arch/parisc/kernel/irq.c b/arch/parisc/kernel/irq.c
index 5024f643b3b1..d7d94b845dc2 100644
--- a/arch/parisc/kernel/irq.c
+++ b/arch/parisc/kernel/irq.c
@@ -75,9 +75,6 @@ static void cpu_unmask_irq(unsigned int irq)
75 smp_send_all_nop(); 75 smp_send_all_nop();
76} 76}
77 77
78void no_ack_irq(unsigned int irq) { }
79void no_end_irq(unsigned int irq) { }
80
81void cpu_ack_irq(unsigned int irq) 78void cpu_ack_irq(unsigned int irq)
82{ 79{
83 unsigned long mask = EIEM_MASK(irq); 80 unsigned long mask = EIEM_MASK(irq);
@@ -241,7 +238,7 @@ int cpu_claim_irq(unsigned int irq, struct irq_chip *type, void *data)
241 238
242 /* for iosapic interrupts */ 239 /* for iosapic interrupts */
243 if (type) { 240 if (type) {
244 set_irq_chip_and_handler(irq, type, handle_level_irq); 241 set_irq_chip_and_handler(irq, type, handle_percpu_irq);
245 set_irq_chip_data(irq, data); 242 set_irq_chip_data(irq, data);
246 cpu_unmask_irq(irq); 243 cpu_unmask_irq(irq);
247 } 244 }
@@ -392,7 +389,7 @@ static void claim_cpu_irqs(void)
392 int i; 389 int i;
393 for (i = CPU_IRQ_BASE; i <= CPU_IRQ_MAX; i++) { 390 for (i = CPU_IRQ_BASE; i <= CPU_IRQ_MAX; i++) {
394 set_irq_chip_and_handler(i, &cpu_interrupt_type, 391 set_irq_chip_and_handler(i, &cpu_interrupt_type,
395 handle_level_irq); 392 handle_percpu_irq);
396 } 393 }
397 394
398 set_irq_handler(TIMER_IRQ, handle_percpu_irq); 395 set_irq_handler(TIMER_IRQ, handle_percpu_irq);
diff --git a/arch/parisc/kernel/signal.c b/arch/parisc/kernel/signal.c
index 35c827e94e31..609a331878e7 100644
--- a/arch/parisc/kernel/signal.c
+++ b/arch/parisc/kernel/signal.c
@@ -98,7 +98,6 @@ void
98sys_rt_sigreturn(struct pt_regs *regs, int in_syscall) 98sys_rt_sigreturn(struct pt_regs *regs, int in_syscall)
99{ 99{
100 struct rt_sigframe __user *frame; 100 struct rt_sigframe __user *frame;
101 struct siginfo si;
102 sigset_t set; 101 sigset_t set;
103 unsigned long usp = (regs->gr[30] & ~(0x01UL)); 102 unsigned long usp = (regs->gr[30] & ~(0x01UL));
104 unsigned long sigframe_size = PARISC_RT_SIGFRAME_SIZE; 103 unsigned long sigframe_size = PARISC_RT_SIGFRAME_SIZE;
@@ -178,13 +177,7 @@ sys_rt_sigreturn(struct pt_regs *regs, int in_syscall)
178 177
179give_sigsegv: 178give_sigsegv:
180 DBG(1,"sys_rt_sigreturn: Sending SIGSEGV\n"); 179 DBG(1,"sys_rt_sigreturn: Sending SIGSEGV\n");
181 si.si_signo = SIGSEGV; 180 force_sig(SIGSEGV, current);
182 si.si_errno = 0;
183 si.si_code = SI_KERNEL;
184 si.si_pid = task_pid_vnr(current);
185 si.si_uid = current_uid();
186 si.si_addr = &frame->uc;
187 force_sig_info(SIGSEGV, &si, current);
188 return; 181 return;
189} 182}
190 183
diff --git a/arch/parisc/kernel/sys_parisc32.c b/arch/parisc/kernel/sys_parisc32.c
index 9779ece2b070..88a0ad14a9c9 100644
--- a/arch/parisc/kernel/sys_parisc32.c
+++ b/arch/parisc/kernel/sys_parisc32.c
@@ -20,7 +20,6 @@
20#include <linux/times.h> 20#include <linux/times.h>
21#include <linux/time.h> 21#include <linux/time.h>
22#include <linux/smp.h> 22#include <linux/smp.h>
23#include <linux/smp_lock.h>
24#include <linux/sem.h> 23#include <linux/sem.h>
25#include <linux/msg.h> 24#include <linux/msg.h>
26#include <linux/shm.h> 25#include <linux/shm.h>
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index b6447190e1a2..e625e9e034ae 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -4,6 +4,10 @@ config PPC32
4 bool 4 bool
5 default y if !PPC64 5 default y if !PPC64
6 6
7config 32BIT
8 bool
9 default y if PPC32
10
7config 64BIT 11config 64BIT
8 bool 12 bool
9 default y if PPC64 13 default y if PPC64
diff --git a/arch/powerpc/boot/div64.S b/arch/powerpc/boot/div64.S
index 722f360a32a9..d271ab542673 100644
--- a/arch/powerpc/boot/div64.S
+++ b/arch/powerpc/boot/div64.S
@@ -33,9 +33,10 @@ __div64_32:
33 cntlzw r0,r5 # we are shifting the dividend right 33 cntlzw r0,r5 # we are shifting the dividend right
34 li r10,-1 # to make it < 2^32, and shifting 34 li r10,-1 # to make it < 2^32, and shifting
35 srw r10,r10,r0 # the divisor right the same amount, 35 srw r10,r10,r0 # the divisor right the same amount,
36 add r9,r4,r10 # rounding up (so the estimate cannot 36 addc r9,r4,r10 # rounding up (so the estimate cannot
37 andc r11,r6,r10 # ever be too large, only too small) 37 andc r11,r6,r10 # ever be too large, only too small)
38 andc r9,r9,r10 38 andc r9,r9,r10
39 addze r9,r9
39 or r11,r5,r11 40 or r11,r5,r11
40 rotlw r9,r9,r0 41 rotlw r9,r9,r0
41 rotlw r11,r11,r0 42 rotlw r11,r11,r0
diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
index 7a9db64f3f04..42850ee00ada 100644
--- a/arch/powerpc/kernel/kgdb.c
+++ b/arch/powerpc/kernel/kgdb.c
@@ -337,7 +337,7 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
337 /* FP registers 32 -> 63 */ 337 /* FP registers 32 -> 63 */
338#if defined(CONFIG_FSL_BOOKE) && defined(CONFIG_SPE) 338#if defined(CONFIG_FSL_BOOKE) && defined(CONFIG_SPE)
339 if (current) 339 if (current)
340 memcpy(mem, current->thread.evr[regno-32], 340 memcpy(mem, &current->thread.evr[regno-32],
341 dbg_reg_def[regno].size); 341 dbg_reg_def[regno].size);
342#else 342#else
343 /* fp registers not used by kernel, leave zero */ 343 /* fp registers not used by kernel, leave zero */
@@ -362,7 +362,7 @@ int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
362 if (regno >= 32 && regno < 64) { 362 if (regno >= 32 && regno < 64) {
363 /* FP registers 32 -> 63 */ 363 /* FP registers 32 -> 63 */
364#if defined(CONFIG_FSL_BOOKE) && defined(CONFIG_SPE) 364#if defined(CONFIG_FSL_BOOKE) && defined(CONFIG_SPE)
365 memcpy(current->thread.evr[regno-32], mem, 365 memcpy(&current->thread.evr[regno-32], mem,
366 dbg_reg_def[regno].size); 366 dbg_reg_def[regno].size);
367#else 367#else
368 /* fp registers not used by kernel, leave zero */ 368 /* fp registers not used by kernel, leave zero */
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 428d0e538aec..b06bdae04064 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -127,7 +127,7 @@ static void kvm_patch_ins_nop(u32 *inst)
127 127
128static void kvm_patch_ins_b(u32 *inst, int addr) 128static void kvm_patch_ins_b(u32 *inst, int addr)
129{ 129{
130#ifdef CONFIG_RELOCATABLE 130#if defined(CONFIG_RELOCATABLE) && defined(CONFIG_PPC_BOOK3S)
131 /* On relocatable kernels interrupts handlers and our code 131 /* On relocatable kernels interrupts handlers and our code
132 can be in different regions, so we don't patch them */ 132 can be in different regions, so we don't patch them */
133 133
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 2a178b0ebcdf..ce6f61c6f871 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -497,9 +497,8 @@ static void __init emergency_stack_init(void)
497} 497}
498 498
499/* 499/*
500 * Called into from start_kernel, after lock_kernel has been called. 500 * Called into from start_kernel this initializes bootmem, which is used
501 * Initializes bootmem, which is unsed to manage page allocation until 501 * to manage page allocation until mem_init is called.
502 * mem_init is called.
503 */ 502 */
504void __init setup_arch(char **cmdline_p) 503void __init setup_arch(char **cmdline_p)
505{ 504{
diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c
index b1b6043a56c4..4e5bf1edc0f2 100644
--- a/arch/powerpc/kernel/sys_ppc32.c
+++ b/arch/powerpc/kernel/sys_ppc32.c
@@ -23,7 +23,6 @@
23#include <linux/resource.h> 23#include <linux/resource.h>
24#include <linux/times.h> 24#include <linux/times.h>
25#include <linux/smp.h> 25#include <linux/smp.h>
26#include <linux/smp_lock.h>
27#include <linux/sem.h> 26#include <linux/sem.h>
28#include <linux/msg.h> 27#include <linux/msg.h>
29#include <linux/shm.h> 28#include <linux/shm.h>
diff --git a/arch/powerpc/kvm/booke_interrupts.S b/arch/powerpc/kvm/booke_interrupts.S
index 049846911ce4..1cc471faac2d 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -416,7 +416,7 @@ lightweight_exit:
416 lwz r3, VCPU_PC(r4) 416 lwz r3, VCPU_PC(r4)
417 mtsrr0 r3 417 mtsrr0 r3
418 lwz r3, VCPU_SHARED(r4) 418 lwz r3, VCPU_SHARED(r4)
419 lwz r3, VCPU_SHARED_MSR(r3) 419 lwz r3, (VCPU_SHARED_MSR + 4)(r3)
420 oris r3, r3, KVMPPC_MSR_MASK@h 420 oris r3, r3, KVMPPC_MSR_MASK@h
421 ori r3, r3, KVMPPC_MSR_MASK@l 421 ori r3, r3, KVMPPC_MSR_MASK@l
422 mtsrr1 r3 422 mtsrr1 r3
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index 71750f2dd5d3..e3768ee9b595 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -138,8 +138,8 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
138 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 138 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
139 139
140 free_page((unsigned long)vcpu->arch.shared); 140 free_page((unsigned long)vcpu->arch.shared);
141 kvmppc_e500_tlb_uninit(vcpu_e500);
142 kvm_vcpu_uninit(vcpu); 141 kvm_vcpu_uninit(vcpu);
142 kvmppc_e500_tlb_uninit(vcpu_e500);
143 kmem_cache_free(kvm_vcpu_cache, vcpu_e500); 143 kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
144} 144}
145 145
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 2f87a1627f6c..38f756f25053 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -617,6 +617,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
617 switch (ioctl) { 617 switch (ioctl) {
618 case KVM_PPC_GET_PVINFO: { 618 case KVM_PPC_GET_PVINFO: {
619 struct kvm_ppc_pvinfo pvinfo; 619 struct kvm_ppc_pvinfo pvinfo;
620 memset(&pvinfo, 0, sizeof(pvinfo));
620 r = kvm_vm_ioctl_get_pvinfo(&pvinfo); 621 r = kvm_vm_ioctl_get_pvinfo(&pvinfo);
621 if (copy_to_user(argp, &pvinfo, sizeof(pvinfo))) { 622 if (copy_to_user(argp, &pvinfo, sizeof(pvinfo))) {
622 r = -EFAULT; 623 r = -EFAULT;
diff --git a/arch/powerpc/kvm/timing.c b/arch/powerpc/kvm/timing.c
index 46fa04f12a9b..a021f5827a33 100644
--- a/arch/powerpc/kvm/timing.c
+++ b/arch/powerpc/kvm/timing.c
@@ -35,7 +35,6 @@ void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu)
35 int i; 35 int i;
36 36
37 /* pause guest execution to avoid concurrent updates */ 37 /* pause guest execution to avoid concurrent updates */
38 local_irq_disable();
39 mutex_lock(&vcpu->mutex); 38 mutex_lock(&vcpu->mutex);
40 39
41 vcpu->arch.last_exit_type = 0xDEAD; 40 vcpu->arch.last_exit_type = 0xDEAD;
@@ -51,7 +50,6 @@ void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu)
51 vcpu->arch.timing_last_enter.tv64 = 0; 50 vcpu->arch.timing_last_enter.tv64 = 0;
52 51
53 mutex_unlock(&vcpu->mutex); 52 mutex_unlock(&vcpu->mutex);
54 local_irq_enable();
55} 53}
56 54
57static void add_exit_timing(struct kvm_vcpu *vcpu, u64 duration, int type) 55static void add_exit_timing(struct kvm_vcpu *vcpu, u64 duration, int type)
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 83f534d862db..5e9584405c45 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1123,7 +1123,7 @@ void hash_preload(struct mm_struct *mm, unsigned long ea,
1123 else 1123 else
1124#endif /* CONFIG_PPC_HAS_HASH_64K */ 1124#endif /* CONFIG_PPC_HAS_HASH_64K */
1125 rc = __hash_page_4K(ea, access, vsid, ptep, trap, local, ssize, 1125 rc = __hash_page_4K(ea, access, vsid, ptep, trap, local, ssize,
1126 subpage_protection(pgdir, ea)); 1126 subpage_protection(mm, ea));
1127 1127
1128 /* Dump some info in case of hash insertion failure, they should 1128 /* Dump some info in case of hash insertion failure, they should
1129 * never happen so it is really useful to know if/when they do 1129 * never happen so it is really useful to know if/when they do
diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c
index 2c7e801ab20b..6a3997f98dfb 100644
--- a/arch/powerpc/mm/pgtable.c
+++ b/arch/powerpc/mm/pgtable.c
@@ -92,7 +92,7 @@ static void pte_free_rcu_callback(struct rcu_head *head)
92 92
93static void pte_free_submit(struct pte_freelist_batch *batch) 93static void pte_free_submit(struct pte_freelist_batch *batch)
94{ 94{
95 call_rcu(&batch->rcu, pte_free_rcu_callback); 95 call_rcu_sched(&batch->rcu, pte_free_rcu_callback);
96} 96}
97 97
98void pgtable_free_tlb(struct mmu_gather *tlb, void *table, unsigned shift) 98void pgtable_free_tlb(struct mmu_gather *tlb, void *table, unsigned shift)
diff --git a/arch/powerpc/mm/tlb_low_64e.S b/arch/powerpc/mm/tlb_low_64e.S
index 8b04c54e596f..8526bd9d2aa3 100644
--- a/arch/powerpc/mm/tlb_low_64e.S
+++ b/arch/powerpc/mm/tlb_low_64e.S
@@ -138,8 +138,11 @@
138 cmpldi cr0,r15,0 /* Check for user region */ 138 cmpldi cr0,r15,0 /* Check for user region */
139 std r14,EX_TLB_ESR(r12) /* write crazy -1 to frame */ 139 std r14,EX_TLB_ESR(r12) /* write crazy -1 to frame */
140 beq normal_tlb_miss 140 beq normal_tlb_miss
141
142 li r11,_PAGE_PRESENT|_PAGE_BAP_SX /* Base perm */
143 oris r11,r11,_PAGE_ACCESSED@h
141 /* XXX replace the RMW cycles with immediate loads + writes */ 144 /* XXX replace the RMW cycles with immediate loads + writes */
1421: mfspr r10,SPRN_MAS1 145 mfspr r10,SPRN_MAS1
143 cmpldi cr0,r15,8 /* Check for vmalloc region */ 146 cmpldi cr0,r15,8 /* Check for vmalloc region */
144 rlwinm r10,r10,0,16,1 /* Clear TID */ 147 rlwinm r10,r10,0,16,1 /* Clear TID */
145 mtspr SPRN_MAS1,r10 148 mtspr SPRN_MAS1,r10
diff --git a/arch/powerpc/mm/tlb_nohash.c b/arch/powerpc/mm/tlb_nohash.c
index 36c0c449a899..2a030d89bbc6 100644
--- a/arch/powerpc/mm/tlb_nohash.c
+++ b/arch/powerpc/mm/tlb_nohash.c
@@ -585,6 +585,6 @@ void setup_initial_memory_limit(phys_addr_t first_memblock_base,
585 ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000); 585 ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
586 586
587 /* Finally limit subsequent allocations */ 587 /* Finally limit subsequent allocations */
588 memblock_set_current_limit(ppc64_memblock_base + ppc64_rma_size); 588 memblock_set_current_limit(first_memblock_base + ppc64_rma_size);
589} 589}
590#endif /* CONFIG_PPC64 */ 590#endif /* CONFIG_PPC64 */
diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
index c667f0f02c34..3139814f6439 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -47,6 +47,12 @@ config LPARCFG
47config PPC_PSERIES_DEBUG 47config PPC_PSERIES_DEBUG
48 depends on PPC_PSERIES && PPC_EARLY_DEBUG 48 depends on PPC_PSERIES && PPC_EARLY_DEBUG
49 bool "Enable extra debug logging in platforms/pseries" 49 bool "Enable extra debug logging in platforms/pseries"
50 help
51 Say Y here if you want the pseries core to produce a bunch of
52 debug messages to the system log. Select this if you are having a
53 problem with the pseries core and want to see more of what is
54 going on. This does not enable debugging in lpar.c, which must
55 be manually done due to its verbosity.
50 default y 56 default y
51 57
52config PPC_SMLPAR 58config PPC_SMLPAR
diff --git a/arch/powerpc/platforms/pseries/eeh.c b/arch/powerpc/platforms/pseries/eeh.c
index 34b7dc12e731..17a11c82e6f8 100644
--- a/arch/powerpc/platforms/pseries/eeh.c
+++ b/arch/powerpc/platforms/pseries/eeh.c
@@ -21,8 +21,6 @@
21 * Please address comments and feedback to Linas Vepstas <linas@austin.ibm.com> 21 * Please address comments and feedback to Linas Vepstas <linas@austin.ibm.com>
22 */ 22 */
23 23
24#undef DEBUG
25
26#include <linux/delay.h> 24#include <linux/delay.h>
27#include <linux/init.h> 25#include <linux/init.h>
28#include <linux/list.h> 26#include <linux/list.h>
diff --git a/arch/powerpc/platforms/pseries/pci_dlpar.c b/arch/powerpc/platforms/pseries/pci_dlpar.c
index 4b7a062dee15..5fcc92a12d3e 100644
--- a/arch/powerpc/platforms/pseries/pci_dlpar.c
+++ b/arch/powerpc/platforms/pseries/pci_dlpar.c
@@ -25,8 +25,6 @@
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */ 26 */
27 27
28#undef DEBUG
29
30#include <linux/pci.h> 28#include <linux/pci.h>
31#include <asm/pci-bridge.h> 29#include <asm/pci-bridge.h>
32#include <asm/ppc-pci.h> 30#include <asm/ppc-pci.h>
diff --git a/arch/s390/Kconfig.debug b/arch/s390/Kconfig.debug
index 45e0c6199f36..05221b13ffb1 100644
--- a/arch/s390/Kconfig.debug
+++ b/arch/s390/Kconfig.debug
@@ -6,6 +6,18 @@ config TRACE_IRQFLAGS_SUPPORT
6 6
7source "lib/Kconfig.debug" 7source "lib/Kconfig.debug"
8 8
9config STRICT_DEVMEM
10 def_bool y
11 prompt "Filter access to /dev/mem"
12 ---help---
13 This option restricts access to /dev/mem. If this option is
14 disabled, you allow userspace access to all memory, including
15 kernel and userspace memory. Accidental memory access is likely
16 to be disastrous.
17 Memory access is required for experts who want to debug the kernel.
18
19 If you are unsure, say Y.
20
9config DEBUG_STRICT_USER_COPY_CHECKS 21config DEBUG_STRICT_USER_COPY_CHECKS
10 bool "Strict user copy size checks" 22 bool "Strict user copy size checks"
11 ---help--- 23 ---help---
diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h
index a8729ea7e9ac..3c987e9ec8d6 100644
--- a/arch/s390/include/asm/page.h
+++ b/arch/s390/include/asm/page.h
@@ -130,6 +130,11 @@ struct page;
130void arch_free_page(struct page *page, int order); 130void arch_free_page(struct page *page, int order);
131void arch_alloc_page(struct page *page, int order); 131void arch_alloc_page(struct page *page, int order);
132 132
133static inline int devmem_is_allowed(unsigned long pfn)
134{
135 return 0;
136}
137
133#define HAVE_ARCH_FREE_PAGE 138#define HAVE_ARCH_FREE_PAGE
134#define HAVE_ARCH_ALLOC_PAGE 139#define HAVE_ARCH_ALLOC_PAGE
135 140
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c
index 1e6449c79ab6..53acaa86dd94 100644
--- a/arch/s390/kernel/compat_linux.c
+++ b/arch/s390/kernel/compat_linux.c
@@ -25,7 +25,6 @@
25#include <linux/resource.h> 25#include <linux/resource.h>
26#include <linux/times.h> 26#include <linux/times.h>
27#include <linux/smp.h> 27#include <linux/smp.h>
28#include <linux/smp_lock.h>
29#include <linux/sem.h> 28#include <linux/sem.h>
30#include <linux/msg.h> 29#include <linux/msg.h>
31#include <linux/shm.h> 30#include <linux/shm.h>
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index d60fc4398516..2564793ec2b6 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -30,6 +30,7 @@
30#include <asm/sections.h> 30#include <asm/sections.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/hardirq.h>
33 34
34DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL; 35DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
35DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); 36DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
@@ -212,7 +213,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
212 /* Set the PER control regs, turns on single step for this address */ 213 /* Set the PER control regs, turns on single step for this address */
213 __ctl_load(kprobe_per_regs, 9, 11); 214 __ctl_load(kprobe_per_regs, 9, 11);
214 regs->psw.mask |= PSW_MASK_PER; 215 regs->psw.mask |= PSW_MASK_PER;
215 regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK); 216 regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT);
216} 217}
217 218
218static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) 219static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
@@ -239,7 +240,7 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
239 __get_cpu_var(current_kprobe) = p; 240 __get_cpu_var(current_kprobe) = p;
240 /* Save the interrupt and per flags */ 241 /* Save the interrupt and per flags */
241 kcb->kprobe_saved_imask = regs->psw.mask & 242 kcb->kprobe_saved_imask = regs->psw.mask &
242 (PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK); 243 (PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT);
243 /* Save the control regs that govern PER */ 244 /* Save the control regs that govern PER */
244 __ctl_store(kcb->kprobe_saved_ctl, 9, 11); 245 __ctl_store(kcb->kprobe_saved_ctl, 9, 11);
245} 246}
@@ -316,8 +317,6 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
316 return 1; 317 return 1;
317 318
318ss_probe: 319ss_probe:
319 if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
320 local_irq_disable();
321 prepare_singlestep(p, regs); 320 prepare_singlestep(p, regs);
322 kcb->kprobe_status = KPROBE_HIT_SS; 321 kcb->kprobe_status = KPROBE_HIT_SS;
323 return 1; 322 return 1;
@@ -350,6 +349,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
350 struct hlist_node *node, *tmp; 349 struct hlist_node *node, *tmp;
351 unsigned long flags, orig_ret_address = 0; 350 unsigned long flags, orig_ret_address = 0;
352 unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline; 351 unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
352 kprobe_opcode_t *correct_ret_addr = NULL;
353 353
354 INIT_HLIST_HEAD(&empty_rp); 354 INIT_HLIST_HEAD(&empty_rp);
355 kretprobe_hash_lock(current, &head, &flags); 355 kretprobe_hash_lock(current, &head, &flags);
@@ -372,10 +372,32 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
372 /* another task is sharing our hash bucket */ 372 /* another task is sharing our hash bucket */
373 continue; 373 continue;
374 374
375 if (ri->rp && ri->rp->handler) 375 orig_ret_address = (unsigned long)ri->ret_addr;
376 ri->rp->handler(ri, regs); 376
377 if (orig_ret_address != trampoline_address)
378 /*
379 * This is the real return address. Any other
380 * instances associated with this task are for
381 * other calls deeper on the call stack
382 */
383 break;
384 }
385
386 kretprobe_assert(ri, orig_ret_address, trampoline_address);
387
388 correct_ret_addr = ri->ret_addr;
389 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
390 if (ri->task != current)
391 /* another task is sharing our hash bucket */
392 continue;
377 393
378 orig_ret_address = (unsigned long)ri->ret_addr; 394 orig_ret_address = (unsigned long)ri->ret_addr;
395
396 if (ri->rp && ri->rp->handler) {
397 ri->ret_addr = correct_ret_addr;
398 ri->rp->handler(ri, regs);
399 }
400
379 recycle_rp_inst(ri, &empty_rp); 401 recycle_rp_inst(ri, &empty_rp);
380 402
381 if (orig_ret_address != trampoline_address) { 403 if (orig_ret_address != trampoline_address) {
@@ -387,7 +409,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
387 break; 409 break;
388 } 410 }
389 } 411 }
390 kretprobe_assert(ri, orig_ret_address, trampoline_address); 412
391 regs->psw.addr = orig_ret_address | PSW_ADDR_AMODE; 413 regs->psw.addr = orig_ret_address | PSW_ADDR_AMODE;
392 414
393 reset_current_kprobe(); 415 reset_current_kprobe();
@@ -465,8 +487,6 @@ static int __kprobes post_kprobe_handler(struct pt_regs *regs)
465 goto out; 487 goto out;
466 } 488 }
467 reset_current_kprobe(); 489 reset_current_kprobe();
468 if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
469 local_irq_enable();
470out: 490out:
471 preempt_enable_no_resched(); 491 preempt_enable_no_resched();
472 492
@@ -482,7 +502,7 @@ out:
482 return 1; 502 return 1;
483} 503}
484 504
485int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr) 505static int __kprobes kprobe_trap_handler(struct pt_regs *regs, int trapnr)
486{ 506{
487 struct kprobe *cur = kprobe_running(); 507 struct kprobe *cur = kprobe_running();
488 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 508 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -508,8 +528,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
508 restore_previous_kprobe(kcb); 528 restore_previous_kprobe(kcb);
509 else { 529 else {
510 reset_current_kprobe(); 530 reset_current_kprobe();
511 if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
512 local_irq_enable();
513 } 531 }
514 preempt_enable_no_resched(); 532 preempt_enable_no_resched();
515 break; 533 break;
@@ -553,6 +571,18 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
553 return 0; 571 return 0;
554} 572}
555 573
574int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
575{
576 int ret;
577
578 if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
579 local_irq_disable();
580 ret = kprobe_trap_handler(regs, trapnr);
581 if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
582 local_irq_restore(regs->psw.mask & ~PSW_MASK_PER);
583 return ret;
584}
585
556/* 586/*
557 * Wrapper routine to for handling exceptions. 587 * Wrapper routine to for handling exceptions.
558 */ 588 */
@@ -560,8 +590,12 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
560 unsigned long val, void *data) 590 unsigned long val, void *data)
561{ 591{
562 struct die_args *args = (struct die_args *)data; 592 struct die_args *args = (struct die_args *)data;
593 struct pt_regs *regs = args->regs;
563 int ret = NOTIFY_DONE; 594 int ret = NOTIFY_DONE;
564 595
596 if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
597 local_irq_disable();
598
565 switch (val) { 599 switch (val) {
566 case DIE_BPT: 600 case DIE_BPT:
567 if (kprobe_handler(args->regs)) 601 if (kprobe_handler(args->regs))
@@ -572,16 +606,17 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
572 ret = NOTIFY_STOP; 606 ret = NOTIFY_STOP;
573 break; 607 break;
574 case DIE_TRAP: 608 case DIE_TRAP:
575 /* kprobe_running() needs smp_processor_id() */ 609 if (!preemptible() && kprobe_running() &&
576 preempt_disable(); 610 kprobe_trap_handler(args->regs, args->trapnr))
577 if (kprobe_running() &&
578 kprobe_fault_handler(args->regs, args->trapnr))
579 ret = NOTIFY_STOP; 611 ret = NOTIFY_STOP;
580 preempt_enable();
581 break; 612 break;
582 default: 613 default:
583 break; 614 break;
584 } 615 }
616
617 if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
618 local_irq_restore(regs->psw.mask & ~PSW_MASK_PER);
619
585 return ret; 620 return ret;
586} 621}
587 622
@@ -595,6 +630,7 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
595 630
596 /* setup return addr to the jprobe handler routine */ 631 /* setup return addr to the jprobe handler routine */
597 regs->psw.addr = (unsigned long)(jp->entry) | PSW_ADDR_AMODE; 632 regs->psw.addr = (unsigned long)(jp->entry) | PSW_ADDR_AMODE;
633 regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT);
598 634
599 /* r14 is the function return address */ 635 /* r14 is the function return address */
600 kcb->jprobe_saved_r14 = (unsigned long)regs->gprs[14]; 636 kcb->jprobe_saved_r14 = (unsigned long)regs->gprs[14];
diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
index ac151399ef34..1995c1712fc8 100644
--- a/arch/s390/kernel/nmi.c
+++ b/arch/s390/kernel/nmi.c
@@ -95,7 +95,6 @@ EXPORT_SYMBOL_GPL(s390_handle_mcck);
95static int notrace s390_revalidate_registers(struct mci *mci) 95static int notrace s390_revalidate_registers(struct mci *mci)
96{ 96{
97 int kill_task; 97 int kill_task;
98 u64 tmpclock;
99 u64 zero; 98 u64 zero;
100 void *fpt_save_area, *fpt_creg_save_area; 99 void *fpt_save_area, *fpt_creg_save_area;
101 100
@@ -214,11 +213,10 @@ static int notrace s390_revalidate_registers(struct mci *mci)
214 : "0", "cc"); 213 : "0", "cc");
215#endif 214#endif
216 /* Revalidate clock comparator register */ 215 /* Revalidate clock comparator register */
217 asm volatile( 216 if (S390_lowcore.clock_comparator == -1)
218 " stck 0(%1)\n" 217 set_clock_comparator(S390_lowcore.mcck_clock);
219 " sckc 0(%1)" 218 else
220 : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory"); 219 set_clock_comparator(S390_lowcore.clock_comparator);
221
222 /* Check if old PSW is valid */ 220 /* Check if old PSW is valid */
223 if (!mci->wp) 221 if (!mci->wp)
224 /* 222 /*
diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 56c8687b29b3..7eff9b7347c0 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -19,6 +19,7 @@
19#include <linux/kernel_stat.h> 19#include <linux/kernel_stat.h>
20#include <linux/rcupdate.h> 20#include <linux/rcupdate.h>
21#include <linux/posix-timers.h> 21#include <linux/posix-timers.h>
22#include <linux/cpu.h>
22 23
23#include <asm/s390_ext.h> 24#include <asm/s390_ext.h>
24#include <asm/timer.h> 25#include <asm/timer.h>
@@ -566,6 +567,23 @@ void init_cpu_vtimer(void)
566 __ctl_set_bit(0,10); 567 __ctl_set_bit(0,10);
567} 568}
568 569
570static int __cpuinit s390_nohz_notify(struct notifier_block *self,
571 unsigned long action, void *hcpu)
572{
573 struct s390_idle_data *idle;
574 long cpu = (long) hcpu;
575
576 idle = &per_cpu(s390_idle, cpu);
577 switch (action) {
578 case CPU_DYING:
579 case CPU_DYING_FROZEN:
580 idle->nohz_delay = 0;
581 default:
582 break;
583 }
584 return NOTIFY_OK;
585}
586
569void __init vtime_init(void) 587void __init vtime_init(void)
570{ 588{
571 /* request the cpu timer external interrupt */ 589 /* request the cpu timer external interrupt */
@@ -574,5 +592,6 @@ void __init vtime_init(void)
574 592
575 /* Enable cpu timer interrupts on the boot cpu. */ 593 /* Enable cpu timer interrupts on the boot cpu. */
576 init_cpu_vtimer(); 594 init_cpu_vtimer();
595 cpu_notifier(s390_nohz_notify, 0);
577} 596}
578 597
diff --git a/arch/s390/lib/delay.c b/arch/s390/lib/delay.c
index 752b362bf651..7c37ec359ec2 100644
--- a/arch/s390/lib/delay.c
+++ b/arch/s390/lib/delay.c
@@ -29,17 +29,21 @@ static void __udelay_disabled(unsigned long long usecs)
29{ 29{
30 unsigned long mask, cr0, cr0_saved; 30 unsigned long mask, cr0, cr0_saved;
31 u64 clock_saved; 31 u64 clock_saved;
32 u64 end;
32 33
34 mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
35 end = get_clock() + (usecs << 12);
33 clock_saved = local_tick_disable(); 36 clock_saved = local_tick_disable();
34 set_clock_comparator(get_clock() + (usecs << 12));
35 __ctl_store(cr0_saved, 0, 0); 37 __ctl_store(cr0_saved, 0, 0);
36 cr0 = (cr0_saved & 0xffff00e0) | 0x00000800; 38 cr0 = (cr0_saved & 0xffff00e0) | 0x00000800;
37 __ctl_load(cr0 , 0, 0); 39 __ctl_load(cr0 , 0, 0);
38 mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
39 lockdep_off(); 40 lockdep_off();
40 trace_hardirqs_on(); 41 do {
41 __load_psw_mask(mask); 42 set_clock_comparator(end);
42 local_irq_disable(); 43 trace_hardirqs_on();
44 __load_psw_mask(mask);
45 local_irq_disable();
46 } while (get_clock() < end);
43 lockdep_on(); 47 lockdep_on();
44 __ctl_load(cr0_saved, 0, 0); 48 __ctl_load(cr0_saved, 0, 0);
45 local_tick_enable(clock_saved); 49 local_tick_enable(clock_saved);
diff --git a/arch/s390/mm/gup.c b/arch/s390/mm/gup.c
index 38e641cdd977..45b405ca2567 100644
--- a/arch/s390/mm/gup.c
+++ b/arch/s390/mm/gup.c
@@ -20,18 +20,17 @@
20static inline int gup_pte_range(pmd_t *pmdp, pmd_t pmd, unsigned long addr, 20static inline int gup_pte_range(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
21 unsigned long end, int write, struct page **pages, int *nr) 21 unsigned long end, int write, struct page **pages, int *nr)
22{ 22{
23 unsigned long mask, result; 23 unsigned long mask;
24 pte_t *ptep, pte; 24 pte_t *ptep, pte;
25 struct page *page; 25 struct page *page;
26 26
27 result = write ? 0 : _PAGE_RO; 27 mask = (write ? _PAGE_RO : 0) | _PAGE_INVALID | _PAGE_SPECIAL;
28 mask = result | _PAGE_INVALID | _PAGE_SPECIAL;
29 28
30 ptep = ((pte_t *) pmd_deref(pmd)) + pte_index(addr); 29 ptep = ((pte_t *) pmd_deref(pmd)) + pte_index(addr);
31 do { 30 do {
32 pte = *ptep; 31 pte = *ptep;
33 barrier(); 32 barrier();
34 if ((pte_val(pte) & mask) != result) 33 if ((pte_val(pte) & mask) != 0)
35 return 0; 34 return 0;
36 VM_BUG_ON(!pfn_valid(pte_pfn(pte))); 35 VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
37 page = pte_page(pte); 36 page = pte_page(pte);
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index 5c075f562eba..2e9d78d21fd3 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -22,7 +22,8 @@ config SUPERH
22 select HAVE_SPARSE_IRQ 22 select HAVE_SPARSE_IRQ
23 select RTC_LIB 23 select RTC_LIB
24 select GENERIC_ATOMIC64 24 select GENERIC_ATOMIC64
25 select GENERIC_HARDIRQS_NO_DEPRECATED 25 # Support the deprecated APIs until MFD and GPIOLIB catch up.
26 select GENERIC_HARDIRQS_NO_DEPRECATED if !MFD_SUPPORT && !GPIOLIB
26 help 27 help
27 The SuperH is a RISC processor targeted for use in embedded systems 28 The SuperH is a RISC processor targeted for use in embedded systems
28 and consumer electronics; it was also used in the Sega Dreamcast 29 and consumer electronics; it was also used in the Sega Dreamcast
@@ -193,6 +194,7 @@ config CPU_SH2
193config CPU_SH2A 194config CPU_SH2A
194 bool 195 bool
195 select CPU_SH2 196 select CPU_SH2
197 select UNCACHED_MAPPING
196 198
197config CPU_SH3 199config CPU_SH3
198 bool 200 bool
diff --git a/arch/sh/Makefile b/arch/sh/Makefile
index 307b3a4a790b..9c8c6e1a2a15 100644
--- a/arch/sh/Makefile
+++ b/arch/sh/Makefile
@@ -133,10 +133,7 @@ machdir-$(CONFIG_SOLUTION_ENGINE) += mach-se
133machdir-$(CONFIG_SH_HP6XX) += mach-hp6xx 133machdir-$(CONFIG_SH_HP6XX) += mach-hp6xx
134machdir-$(CONFIG_SH_DREAMCAST) += mach-dreamcast 134machdir-$(CONFIG_SH_DREAMCAST) += mach-dreamcast
135machdir-$(CONFIG_SH_SH03) += mach-sh03 135machdir-$(CONFIG_SH_SH03) += mach-sh03
136machdir-$(CONFIG_SH_SECUREEDGE5410) += mach-snapgear
137machdir-$(CONFIG_SH_RTS7751R2D) += mach-r2d 136machdir-$(CONFIG_SH_RTS7751R2D) += mach-r2d
138machdir-$(CONFIG_SH_7751_SYSTEMH) += mach-systemh
139machdir-$(CONFIG_SH_EDOSK7705) += mach-edosk7705
140machdir-$(CONFIG_SH_HIGHLANDER) += mach-highlander 137machdir-$(CONFIG_SH_HIGHLANDER) += mach-highlander
141machdir-$(CONFIG_SH_MIGOR) += mach-migor 138machdir-$(CONFIG_SH_MIGOR) += mach-migor
142machdir-$(CONFIG_SH_AP325RXA) += mach-ap325rxa 139machdir-$(CONFIG_SH_AP325RXA) += mach-ap325rxa
diff --git a/arch/sh/boards/Kconfig b/arch/sh/boards/Kconfig
index 9c94711aa6ca..2018c7ea4c93 100644
--- a/arch/sh/boards/Kconfig
+++ b/arch/sh/boards/Kconfig
@@ -81,13 +81,6 @@ config SH_7343_SOLUTION_ENGINE
81 Select 7343 SolutionEngine if configuring for a Hitachi 81 Select 7343 SolutionEngine if configuring for a Hitachi
82 SH7343 (SH-Mobile 3AS) evaluation board. 82 SH7343 (SH-Mobile 3AS) evaluation board.
83 83
84config SH_7751_SYSTEMH
85 bool "SystemH7751R"
86 depends on CPU_SUBTYPE_SH7751R
87 help
88 Select SystemH if you are configuring for a Renesas SystemH
89 7751R evaluation board.
90
91config SH_HP6XX 84config SH_HP6XX
92 bool "HP6XX" 85 bool "HP6XX"
93 select SYS_SUPPORTS_APM_EMULATION 86 select SYS_SUPPORTS_APM_EMULATION
diff --git a/arch/sh/boards/Makefile b/arch/sh/boards/Makefile
index 38ef655cc0f0..be7d11d04b26 100644
--- a/arch/sh/boards/Makefile
+++ b/arch/sh/boards/Makefile
@@ -2,10 +2,12 @@
2# Specific board support, not covered by a mach group. 2# Specific board support, not covered by a mach group.
3# 3#
4obj-$(CONFIG_SH_MAGIC_PANEL_R2) += board-magicpanelr2.o 4obj-$(CONFIG_SH_MAGIC_PANEL_R2) += board-magicpanelr2.o
5obj-$(CONFIG_SH_SECUREEDGE5410) += board-secureedge5410.o
5obj-$(CONFIG_SH_SH2007) += board-sh2007.o 6obj-$(CONFIG_SH_SH2007) += board-sh2007.o
6obj-$(CONFIG_SH_SH7785LCR) += board-sh7785lcr.o 7obj-$(CONFIG_SH_SH7785LCR) += board-sh7785lcr.o
7obj-$(CONFIG_SH_URQUELL) += board-urquell.o 8obj-$(CONFIG_SH_URQUELL) += board-urquell.o
8obj-$(CONFIG_SH_SHMIN) += board-shmin.o 9obj-$(CONFIG_SH_SHMIN) += board-shmin.o
10obj-$(CONFIG_SH_EDOSK7705) += board-edosk7705.o
9obj-$(CONFIG_SH_EDOSK7760) += board-edosk7760.o 11obj-$(CONFIG_SH_EDOSK7760) += board-edosk7760.o
10obj-$(CONFIG_SH_ESPT) += board-espt.o 12obj-$(CONFIG_SH_ESPT) += board-espt.o
11obj-$(CONFIG_SH_POLARIS) += board-polaris.o 13obj-$(CONFIG_SH_POLARIS) += board-polaris.o
diff --git a/arch/sh/boards/board-edosk7705.c b/arch/sh/boards/board-edosk7705.c
new file mode 100644
index 000000000000..4cb3bb74c36f
--- /dev/null
+++ b/arch/sh/boards/board-edosk7705.c
@@ -0,0 +1,78 @@
1/*
2 * arch/sh/boards/renesas/edosk7705/setup.c
3 *
4 * Copyright (C) 2000 Kazumoto Kojima
5 *
6 * Hitachi SolutionEngine Support.
7 *
8 * Modified for edosk7705 development
9 * board by S. Dunn, 2003.
10 */
11#include <linux/init.h>
12#include <linux/irq.h>
13#include <linux/platform_device.h>
14#include <linux/interrupt.h>
15#include <linux/smc91x.h>
16#include <asm/machvec.h>
17#include <asm/sizes.h>
18
19#define SMC_IOBASE 0xA2000000
20#define SMC_IO_OFFSET 0x300
21#define SMC_IOADDR (SMC_IOBASE + SMC_IO_OFFSET)
22
23#define ETHERNET_IRQ 0x09
24
25static void __init sh_edosk7705_init_irq(void)
26{
27 make_imask_irq(ETHERNET_IRQ);
28}
29
30/* eth initialization functions */
31static struct smc91x_platdata smc91x_info = {
32 .flags = SMC91X_USE_16BIT | SMC91X_IO_SHIFT_1 | IORESOURCE_IRQ_LOWLEVEL,
33};
34
35static struct resource smc91x_res[] = {
36 [0] = {
37 .start = SMC_IOADDR,
38 .end = SMC_IOADDR + SZ_32 - 1,
39 .flags = IORESOURCE_MEM,
40 },
41 [1] = {
42 .start = ETHERNET_IRQ,
43 .end = ETHERNET_IRQ,
44 .flags = IORESOURCE_IRQ ,
45 }
46};
47
48static struct platform_device smc91x_dev = {
49 .name = "smc91x",
50 .id = -1,
51 .num_resources = ARRAY_SIZE(smc91x_res),
52 .resource = smc91x_res,
53
54 .dev = {
55 .platform_data = &smc91x_info,
56 },
57};
58
59/* platform init code */
60static struct platform_device *edosk7705_devices[] __initdata = {
61 &smc91x_dev,
62};
63
64static int __init init_edosk7705_devices(void)
65{
66 return platform_add_devices(edosk7705_devices,
67 ARRAY_SIZE(edosk7705_devices));
68}
69__initcall(init_edosk7705_devices);
70
71/*
72 * The Machine Vector
73 */
74static struct sh_machine_vector mv_edosk7705 __initmv = {
75 .mv_name = "EDOSK7705",
76 .mv_nr_irqs = 80,
77 .mv_init_irq = sh_edosk7705_init_irq,
78};
diff --git a/arch/sh/boards/mach-snapgear/setup.c b/arch/sh/boards/board-secureedge5410.c
index 331745dee379..32f875e8493d 100644
--- a/arch/sh/boards/mach-snapgear/setup.c
+++ b/arch/sh/boards/board-secureedge5410.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * linux/arch/sh/boards/snapgear/setup.c
3 *
4 * Copyright (C) 2002 David McCullough <davidm@snapgear.com> 2 * Copyright (C) 2002 David McCullough <davidm@snapgear.com>
5 * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org> 3 * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org>
6 * 4 *
@@ -19,18 +17,19 @@
19#include <linux/module.h> 17#include <linux/module.h>
20#include <linux/sched.h> 18#include <linux/sched.h>
21#include <asm/machvec.h> 19#include <asm/machvec.h>
22#include <mach/snapgear.h> 20#include <mach/secureedge5410.h>
23#include <asm/irq.h> 21#include <asm/irq.h>
24#include <asm/io.h> 22#include <asm/io.h>
25#include <cpu/timer.h> 23#include <cpu/timer.h>
26 24
25unsigned short secureedge5410_ioport;
26
27/* 27/*
28 * EraseConfig handling functions 28 * EraseConfig handling functions
29 */ 29 */
30
31static irqreturn_t eraseconfig_interrupt(int irq, void *dev_id) 30static irqreturn_t eraseconfig_interrupt(int irq, void *dev_id)
32{ 31{
33 (void)__raw_readb(0xb8000000); /* dummy read */ 32 ctrl_delay(); /* dummy read */
34 33
35 printk("SnapGear: erase switch interrupt!\n"); 34 printk("SnapGear: erase switch interrupt!\n");
36 35
@@ -39,21 +38,22 @@ static irqreturn_t eraseconfig_interrupt(int irq, void *dev_id)
39 38
40static int __init eraseconfig_init(void) 39static int __init eraseconfig_init(void)
41{ 40{
41 unsigned int irq = evt2irq(0x240);
42
42 printk("SnapGear: EraseConfig init\n"); 43 printk("SnapGear: EraseConfig init\n");
44
43 /* Setup "EraseConfig" switch on external IRQ 0 */ 45 /* Setup "EraseConfig" switch on external IRQ 0 */
44 if (request_irq(IRL0_IRQ, eraseconfig_interrupt, IRQF_DISABLED, 46 if (request_irq(irq, eraseconfig_interrupt, IRQF_DISABLED,
45 "Erase Config", NULL)) 47 "Erase Config", NULL))
46 printk("SnapGear: failed to register IRQ%d for Reset witch\n", 48 printk("SnapGear: failed to register IRQ%d for Reset witch\n",
47 IRL0_IRQ); 49 irq);
48 else 50 else
49 printk("SnapGear: registered EraseConfig switch on IRQ%d\n", 51 printk("SnapGear: registered EraseConfig switch on IRQ%d\n",
50 IRL0_IRQ); 52 irq);
51 return(0); 53 return 0;
52} 54}
53
54module_init(eraseconfig_init); 55module_init(eraseconfig_init);
55 56
56/****************************************************************************/
57/* 57/*
58 * Initialize IRQ setting 58 * Initialize IRQ setting
59 * 59 *
@@ -62,7 +62,6 @@ module_init(eraseconfig_init);
62 * IRL2 = eth1 62 * IRL2 = eth1
63 * IRL3 = crypto 63 * IRL3 = crypto
64 */ 64 */
65
66static void __init init_snapgear_IRQ(void) 65static void __init init_snapgear_IRQ(void)
67{ 66{
68 printk("Setup SnapGear IRQ/IPR ...\n"); 67 printk("Setup SnapGear IRQ/IPR ...\n");
@@ -76,20 +75,5 @@ static void __init init_snapgear_IRQ(void)
76static struct sh_machine_vector mv_snapgear __initmv = { 75static struct sh_machine_vector mv_snapgear __initmv = {
77 .mv_name = "SnapGear SecureEdge5410", 76 .mv_name = "SnapGear SecureEdge5410",
78 .mv_nr_irqs = 72, 77 .mv_nr_irqs = 72,
79
80 .mv_inb = snapgear_inb,
81 .mv_inw = snapgear_inw,
82 .mv_inl = snapgear_inl,
83 .mv_outb = snapgear_outb,
84 .mv_outw = snapgear_outw,
85 .mv_outl = snapgear_outl,
86
87 .mv_inb_p = snapgear_inb_p,
88 .mv_inw_p = snapgear_inw,
89 .mv_inl_p = snapgear_inl,
90 .mv_outb_p = snapgear_outb_p,
91 .mv_outw_p = snapgear_outw,
92 .mv_outl_p = snapgear_outl,
93
94 .mv_init_irq = init_snapgear_IRQ, 78 .mv_init_irq = init_snapgear_IRQ,
95}; 79};
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index 2eaeb9e59585..f48c492a68d3 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -720,32 +720,6 @@ static struct platform_device camera_devices[] = {
720}; 720};
721 721
722/* FSI */ 722/* FSI */
723/*
724 * FSI-B use external clock which came from da7210.
725 * So, we should change parent of fsi
726 */
727#define FCLKBCR 0xa415000c
728static void fsimck_init(struct clk *clk)
729{
730 u32 status = __raw_readl(clk->enable_reg);
731
732 /* use external clock */
733 status &= ~0x000000ff;
734 status |= 0x00000080;
735
736 __raw_writel(status, clk->enable_reg);
737}
738
739static struct clk_ops fsimck_clk_ops = {
740 .init = fsimck_init,
741};
742
743static struct clk fsimckb_clk = {
744 .ops = &fsimck_clk_ops,
745 .enable_reg = (void __iomem *)FCLKBCR,
746 .rate = 0, /* unknown */
747};
748
749static struct sh_fsi_platform_info fsi_info = { 723static struct sh_fsi_platform_info fsi_info = {
750 .portb_flags = SH_FSI_BRS_INV | 724 .portb_flags = SH_FSI_BRS_INV |
751 SH_FSI_OUT_SLAVE_MODE | 725 SH_FSI_OUT_SLAVE_MODE |
@@ -1264,10 +1238,10 @@ static int __init arch_setup(void)
1264 /* change parent of FSI B */ 1238 /* change parent of FSI B */
1265 clk = clk_get(NULL, "fsib_clk"); 1239 clk = clk_get(NULL, "fsib_clk");
1266 if (!IS_ERR(clk)) { 1240 if (!IS_ERR(clk)) {
1267 clk_register(&fsimckb_clk); 1241 /* 48kHz dummy clock was used to make sure 1/1 divide */
1268 clk_set_parent(clk, &fsimckb_clk); 1242 clk_set_rate(&sh7724_fsimckb_clk, 48000);
1269 clk_set_rate(clk, 11000); 1243 clk_set_parent(clk, &sh7724_fsimckb_clk);
1270 clk_set_rate(&fsimckb_clk, 11000); 1244 clk_set_rate(clk, 48000);
1271 clk_put(clk); 1245 clk_put(clk);
1272 } 1246 }
1273 1247
diff --git a/arch/sh/boards/mach-edosk7705/Makefile b/arch/sh/boards/mach-edosk7705/Makefile
deleted file mode 100644
index cd54acb51499..000000000000
--- a/arch/sh/boards/mach-edosk7705/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1#
2# Makefile for the EDOSK7705 specific parts of the kernel
3#
4
5obj-y := setup.o io.o
diff --git a/arch/sh/boards/mach-edosk7705/io.c b/arch/sh/boards/mach-edosk7705/io.c
deleted file mode 100644
index 5b9c57c43241..000000000000
--- a/arch/sh/boards/mach-edosk7705/io.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * arch/sh/boards/renesas/edosk7705/io.c
3 *
4 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
5 * Based largely on io_se.c.
6 *
7 * I/O routines for Hitachi EDOSK7705 board.
8 *
9 */
10
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/io.h>
14#include <mach/edosk7705.h>
15#include <asm/addrspace.h>
16
17#define SMC_IOADDR 0xA2000000
18
19/* Map the Ethernet addresses as if it is at 0x300 - 0x320 */
20static unsigned long sh_edosk7705_isa_port2addr(unsigned long port)
21{
22 /*
23 * SMC91C96 registers are 4 byte aligned rather than the
24 * usual 2 byte!
25 */
26 if (port >= 0x300 && port < 0x320)
27 return SMC_IOADDR + ((port - 0x300) * 2);
28
29 maybebadio(port);
30 return port;
31}
32
33/* Trying to read / write bytes on odd-byte boundaries to the Ethernet
34 * registers causes problems. So we bit-shift the value and read / write
35 * in 2 byte chunks. Setting the low byte to 0 does not cause problems
36 * now as odd byte writes are only made on the bit mask / interrupt
37 * register. This may not be the case in future Mar-2003 SJD
38 */
39unsigned char sh_edosk7705_inb(unsigned long port)
40{
41 if (port >= 0x300 && port < 0x320 && port & 0x01)
42 return __raw_readw(port - 1) >> 8;
43
44 return __raw_readb(sh_edosk7705_isa_port2addr(port));
45}
46
47void sh_edosk7705_outb(unsigned char value, unsigned long port)
48{
49 if (port >= 0x300 && port < 0x320 && port & 0x01) {
50 __raw_writew(((unsigned short)value << 8), port - 1);
51 return;
52 }
53
54 __raw_writeb(value, sh_edosk7705_isa_port2addr(port));
55}
56
57void sh_edosk7705_insb(unsigned long port, void *addr, unsigned long count)
58{
59 unsigned char *p = addr;
60
61 while (count--)
62 *p++ = sh_edosk7705_inb(port);
63}
64
65void sh_edosk7705_outsb(unsigned long port, const void *addr, unsigned long count)
66{
67 unsigned char *p = (unsigned char *)addr;
68
69 while (count--)
70 sh_edosk7705_outb(*p++, port);
71}
diff --git a/arch/sh/boards/mach-edosk7705/setup.c b/arch/sh/boards/mach-edosk7705/setup.c
deleted file mode 100644
index d59225e26fb9..000000000000
--- a/arch/sh/boards/mach-edosk7705/setup.c
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * arch/sh/boards/renesas/edosk7705/setup.c
3 *
4 * Copyright (C) 2000 Kazumoto Kojima
5 *
6 * Hitachi SolutionEngine Support.
7 *
8 * Modified for edosk7705 development
9 * board by S. Dunn, 2003.
10 */
11#include <linux/init.h>
12#include <linux/irq.h>
13#include <asm/machvec.h>
14#include <mach/edosk7705.h>
15
16static void __init sh_edosk7705_init_irq(void)
17{
18 /* This is the Ethernet interrupt */
19 make_imask_irq(0x09);
20}
21
22/*
23 * The Machine Vector
24 */
25static struct sh_machine_vector mv_edosk7705 __initmv = {
26 .mv_name = "EDOSK7705",
27 .mv_nr_irqs = 80,
28
29 .mv_inb = sh_edosk7705_inb,
30 .mv_outb = sh_edosk7705_outb,
31
32 .mv_insb = sh_edosk7705_insb,
33 .mv_outsb = sh_edosk7705_outsb,
34
35 .mv_init_irq = sh_edosk7705_init_irq,
36};
diff --git a/arch/sh/boards/mach-microdev/io.c b/arch/sh/boards/mach-microdev/io.c
index 2960c659020e..acdafb0c6404 100644
--- a/arch/sh/boards/mach-microdev/io.c
+++ b/arch/sh/boards/mach-microdev/io.c
@@ -54,7 +54,7 @@
54/* 54/*
55 * map I/O ports to memory-mapped addresses 55 * map I/O ports to memory-mapped addresses
56 */ 56 */
57static unsigned long microdev_isa_port2addr(unsigned long offset) 57void __iomem *microdev_ioport_map(unsigned long offset, unsigned int len)
58{ 58{
59 unsigned long result; 59 unsigned long result;
60 60
@@ -72,16 +72,6 @@ static unsigned long microdev_isa_port2addr(unsigned long offset)
72 * Configuration Registers 72 * Configuration Registers
73 */ 73 */
74 result = IO_SUPERIO_PHYS + (offset << 1); 74 result = IO_SUPERIO_PHYS + (offset << 1);
75#if 0
76 } else if (offset == KBD_DATA_REG || offset == KBD_CNTL_REG ||
77 offset == KBD_STATUS_REG) {
78 /*
79 * SMSC FDC37C93xAPM SuperIO chip
80 *
81 * PS/2 Keyboard + Mouse (ports 0x60 and 0x64).
82 */
83 result = IO_SUPERIO_PHYS + (offset << 1);
84#endif
85 } else if (((offset >= IO_IDE1_BASE) && 75 } else if (((offset >= IO_IDE1_BASE) &&
86 (offset < IO_IDE1_BASE + IO_IDE_EXTENT)) || 76 (offset < IO_IDE1_BASE + IO_IDE_EXTENT)) ||
87 (offset == IO_IDE1_MISC)) { 77 (offset == IO_IDE1_MISC)) {
@@ -131,237 +121,5 @@ static unsigned long microdev_isa_port2addr(unsigned long offset)
131 result = PVR; 121 result = PVR;
132 } 122 }
133 123
134 return result; 124 return (void __iomem *)result;
135}
136
137#define PORT2ADDR(x) (microdev_isa_port2addr(x))
138
139static inline void delay(void)
140{
141#if defined(CONFIG_PCI)
142 /* System board present, just make a dummy SRAM access. (CS0 will be
143 mapped to PCI memory, probably good to avoid it.) */
144 __raw_readw(0xa6800000);
145#else
146 /* CS0 will be mapped to flash, ROM etc so safe to access it. */
147 __raw_readw(0xa0000000);
148#endif
149}
150
151unsigned char microdev_inb(unsigned long port)
152{
153#ifdef CONFIG_PCI
154 if (port >= PCIBIOS_MIN_IO)
155 return microdev_pci_inb(port);
156#endif
157 return *(volatile unsigned char*)PORT2ADDR(port);
158}
159
160unsigned short microdev_inw(unsigned long port)
161{
162#ifdef CONFIG_PCI
163 if (port >= PCIBIOS_MIN_IO)
164 return microdev_pci_inw(port);
165#endif
166 return *(volatile unsigned short*)PORT2ADDR(port);
167}
168
169unsigned int microdev_inl(unsigned long port)
170{
171#ifdef CONFIG_PCI
172 if (port >= PCIBIOS_MIN_IO)
173 return microdev_pci_inl(port);
174#endif
175 return *(volatile unsigned int*)PORT2ADDR(port);
176}
177
178void microdev_outw(unsigned short b, unsigned long port)
179{
180#ifdef CONFIG_PCI
181 if (port >= PCIBIOS_MIN_IO) {
182 microdev_pci_outw(b, port);
183 return;
184 }
185#endif
186 *(volatile unsigned short*)PORT2ADDR(port) = b;
187}
188
189void microdev_outb(unsigned char b, unsigned long port)
190{
191#ifdef CONFIG_PCI
192 if (port >= PCIBIOS_MIN_IO) {
193 microdev_pci_outb(b, port);
194 return;
195 }
196#endif
197
198 /*
199 * There is a board feature with the current SH4-202 MicroDev in
200 * that the 2 byte enables (nBE0 and nBE1) are tied together (and
201 * to the Chip Select Line (Ethernet_CS)). Due to this connectivity,
202 * it is not possible to safely perform 8-bit writes to the
203 * Ethernet registers, as 16-bits will be consumed from the Data
204 * lines (corrupting the other byte). Hence, this function is
205 * written to implement 16-bit read/modify/write for all byte-wide
206 * accesses.
207 *
208 * Note: there is no problem with byte READS (even or odd).
209 *
210 * Sean McGoogan - 16th June 2003.
211 */
212 if ((port >= IO_LAN91C111_BASE) &&
213 (port < IO_LAN91C111_BASE + IO_LAN91C111_EXTENT)) {
214 /*
215 * Then are trying to perform a byte-write to the
216 * LAN91C111. This needs special care.
217 */
218 if (port % 2 == 1) { /* is the port odd ? */
219 /* unset bit-0, i.e. make even */
220 const unsigned long evenPort = port-1;
221 unsigned short word;
222
223 /*
224 * do a 16-bit read/write to write to 'port',
225 * preserving even byte.
226 *
227 * Even addresses are bits 0-7
228 * Odd addresses are bits 8-15
229 */
230 word = microdev_inw(evenPort);
231 word = (word & 0xffu) | (b << 8);
232 microdev_outw(word, evenPort);
233 } else {
234 /* else, we are trying to do an even byte write */
235 unsigned short word;
236
237 /*
238 * do a 16-bit read/write to write to 'port',
239 * preserving odd byte.
240 *
241 * Even addresses are bits 0-7
242 * Odd addresses are bits 8-15
243 */
244 word = microdev_inw(port);
245 word = (word & 0xff00u) | (b);
246 microdev_outw(word, port);
247 }
248 } else {
249 *(volatile unsigned char*)PORT2ADDR(port) = b;
250 }
251}
252
253void microdev_outl(unsigned int b, unsigned long port)
254{
255#ifdef CONFIG_PCI
256 if (port >= PCIBIOS_MIN_IO) {
257 microdev_pci_outl(b, port);
258 return;
259 }
260#endif
261 *(volatile unsigned int*)PORT2ADDR(port) = b;
262}
263
264unsigned char microdev_inb_p(unsigned long port)
265{
266 unsigned char v = microdev_inb(port);
267 delay();
268 return v;
269}
270
271unsigned short microdev_inw_p(unsigned long port)
272{
273 unsigned short v = microdev_inw(port);
274 delay();
275 return v;
276}
277
278unsigned int microdev_inl_p(unsigned long port)
279{
280 unsigned int v = microdev_inl(port);
281 delay();
282 return v;
283}
284
285void microdev_outb_p(unsigned char b, unsigned long port)
286{
287 microdev_outb(b, port);
288 delay();
289}
290
291void microdev_outw_p(unsigned short b, unsigned long port)
292{
293 microdev_outw(b, port);
294 delay();
295}
296
297void microdev_outl_p(unsigned int b, unsigned long port)
298{
299 microdev_outl(b, port);
300 delay();
301}
302
303void microdev_insb(unsigned long port, void *buffer, unsigned long count)
304{
305 volatile unsigned char *port_addr;
306 unsigned char *buf = buffer;
307
308 port_addr = (volatile unsigned char *)PORT2ADDR(port);
309
310 while (count--)
311 *buf++ = *port_addr;
312}
313
314void microdev_insw(unsigned long port, void *buffer, unsigned long count)
315{
316 volatile unsigned short *port_addr;
317 unsigned short *buf = buffer;
318
319 port_addr = (volatile unsigned short *)PORT2ADDR(port);
320
321 while (count--)
322 *buf++ = *port_addr;
323}
324
325void microdev_insl(unsigned long port, void *buffer, unsigned long count)
326{
327 volatile unsigned long *port_addr;
328 unsigned int *buf = buffer;
329
330 port_addr = (volatile unsigned long *)PORT2ADDR(port);
331
332 while (count--)
333 *buf++ = *port_addr;
334}
335
336void microdev_outsb(unsigned long port, const void *buffer, unsigned long count)
337{
338 volatile unsigned char *port_addr;
339 const unsigned char *buf = buffer;
340
341 port_addr = (volatile unsigned char *)PORT2ADDR(port);
342
343 while (count--)
344 *port_addr = *buf++;
345}
346
347void microdev_outsw(unsigned long port, const void *buffer, unsigned long count)
348{
349 volatile unsigned short *port_addr;
350 const unsigned short *buf = buffer;
351
352 port_addr = (volatile unsigned short *)PORT2ADDR(port);
353
354 while (count--)
355 *port_addr = *buf++;
356}
357
358void microdev_outsl(unsigned long port, const void *buffer, unsigned long count)
359{
360 volatile unsigned long *port_addr;
361 const unsigned int *buf = buffer;
362
363 port_addr = (volatile unsigned long *)PORT2ADDR(port);
364
365 while (count--)
366 *port_addr = *buf++;
367} 125}
diff --git a/arch/sh/boards/mach-microdev/setup.c b/arch/sh/boards/mach-microdev/setup.c
index d1df2a4fb9b8..d8a747291e03 100644
--- a/arch/sh/boards/mach-microdev/setup.c
+++ b/arch/sh/boards/mach-microdev/setup.c
@@ -195,27 +195,6 @@ device_initcall(microdev_devices_setup);
195static struct sh_machine_vector mv_sh4202_microdev __initmv = { 195static struct sh_machine_vector mv_sh4202_microdev __initmv = {
196 .mv_name = "SH4-202 MicroDev", 196 .mv_name = "SH4-202 MicroDev",
197 .mv_nr_irqs = 72, 197 .mv_nr_irqs = 72,
198 198 .mv_ioport_map = microdev_ioport_map,
199 .mv_inb = microdev_inb,
200 .mv_inw = microdev_inw,
201 .mv_inl = microdev_inl,
202 .mv_outb = microdev_outb,
203 .mv_outw = microdev_outw,
204 .mv_outl = microdev_outl,
205
206 .mv_inb_p = microdev_inb_p,
207 .mv_inw_p = microdev_inw_p,
208 .mv_inl_p = microdev_inl_p,
209 .mv_outb_p = microdev_outb_p,
210 .mv_outw_p = microdev_outw_p,
211 .mv_outl_p = microdev_outl_p,
212
213 .mv_insb = microdev_insb,
214 .mv_insw = microdev_insw,
215 .mv_insl = microdev_insl,
216 .mv_outsb = microdev_outsb,
217 .mv_outsw = microdev_outsw,
218 .mv_outsl = microdev_outsl,
219
220 .mv_init_irq = init_microdev_irq, 199 .mv_init_irq = init_microdev_irq,
221}; 200};
diff --git a/arch/sh/boards/mach-se/7206/Makefile b/arch/sh/boards/mach-se/7206/Makefile
index 63e7ed699f39..5c9eaa0535b9 100644
--- a/arch/sh/boards/mach-se/7206/Makefile
+++ b/arch/sh/boards/mach-se/7206/Makefile
@@ -2,4 +2,4 @@
2# Makefile for the 7206 SolutionEngine specific parts of the kernel 2# Makefile for the 7206 SolutionEngine specific parts of the kernel
3# 3#
4 4
5obj-y := setup.o io.o irq.o 5obj-y := setup.o irq.o
diff --git a/arch/sh/boards/mach-se/7206/io.c b/arch/sh/boards/mach-se/7206/io.c
deleted file mode 100644
index adadc77532ee..000000000000
--- a/arch/sh/boards/mach-se/7206/io.c
+++ /dev/null
@@ -1,104 +0,0 @@
1/* $Id: io.c,v 1.5 2004/02/22 23:08:43 kkojima Exp $
2 *
3 * linux/arch/sh/boards/se/7206/io.c
4 *
5 * Copyright (C) 2006 Yoshinori Sato
6 *
7 * I/O routine for Hitachi 7206 SolutionEngine.
8 *
9 */
10
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <asm/io.h>
14#include <mach-se/mach/se7206.h>
15
16
17static inline void delay(void)
18{
19 __raw_readw(0x20000000); /* P2 ROM Area */
20}
21
22/* MS7750 requires special versions of in*, out* routines, since
23 PC-like io ports are located at upper half byte of 16-bit word which
24 can be accessed only with 16-bit wide. */
25
26static inline volatile __u16 *
27port2adr(unsigned int port)
28{
29 if (port >= 0x2000 && port < 0x2020)
30 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
31 else if (port >= 0x300 && port < 0x310)
32 return (volatile __u16 *) (PA_SMSC + (port - 0x300));
33
34 return (volatile __u16 *)port;
35}
36
37unsigned char se7206_inb(unsigned long port)
38{
39 return (*port2adr(port)) & 0xff;
40}
41
42unsigned char se7206_inb_p(unsigned long port)
43{
44 unsigned long v;
45
46 v = (*port2adr(port)) & 0xff;
47 delay();
48 return v;
49}
50
51unsigned short se7206_inw(unsigned long port)
52{
53 return *port2adr(port);
54}
55
56void se7206_outb(unsigned char value, unsigned long port)
57{
58 *(port2adr(port)) = value;
59}
60
61void se7206_outb_p(unsigned char value, unsigned long port)
62{
63 *(port2adr(port)) = value;
64 delay();
65}
66
67void se7206_outw(unsigned short value, unsigned long port)
68{
69 *port2adr(port) = value;
70}
71
72void se7206_insb(unsigned long port, void *addr, unsigned long count)
73{
74 volatile __u16 *p = port2adr(port);
75 __u8 *ap = addr;
76
77 while (count--)
78 *ap++ = *p;
79}
80
81void se7206_insw(unsigned long port, void *addr, unsigned long count)
82{
83 volatile __u16 *p = port2adr(port);
84 __u16 *ap = addr;
85 while (count--)
86 *ap++ = *p;
87}
88
89void se7206_outsb(unsigned long port, const void *addr, unsigned long count)
90{
91 volatile __u16 *p = port2adr(port);
92 const __u8 *ap = addr;
93
94 while (count--)
95 *p = *ap++;
96}
97
98void se7206_outsw(unsigned long port, const void *addr, unsigned long count)
99{
100 volatile __u16 *p = port2adr(port);
101 const __u16 *ap = addr;
102 while (count--)
103 *p = *ap++;
104}
diff --git a/arch/sh/boards/mach-se/7206/irq.c b/arch/sh/boards/mach-se/7206/irq.c
index 883b21eacaa6..d961949600fd 100644
--- a/arch/sh/boards/mach-se/7206/irq.c
+++ b/arch/sh/boards/mach-se/7206/irq.c
@@ -139,11 +139,13 @@ void __init init_se7206_IRQ(void)
139 make_se7206_irq(IRQ0_IRQ); /* SMC91C111 */ 139 make_se7206_irq(IRQ0_IRQ); /* SMC91C111 */
140 make_se7206_irq(IRQ1_IRQ); /* ATA */ 140 make_se7206_irq(IRQ1_IRQ); /* ATA */
141 make_se7206_irq(IRQ3_IRQ); /* SLOT / PCM */ 141 make_se7206_irq(IRQ3_IRQ); /* SLOT / PCM */
142 __raw_writew(inw(INTC_ICR1) | 0x000b ,INTC_ICR1 ) ; /* ICR1 */ 142
143 __raw_writew(__raw_readw(INTC_ICR1) | 0x000b, INTC_ICR); /* ICR1 */
143 144
144 /* FPGA System register setup*/ 145 /* FPGA System register setup*/
145 __raw_writew(0x0000,INTSTS0); /* Clear INTSTS0 */ 146 __raw_writew(0x0000,INTSTS0); /* Clear INTSTS0 */
146 __raw_writew(0x0000,INTSTS1); /* Clear INTSTS1 */ 147 __raw_writew(0x0000,INTSTS1); /* Clear INTSTS1 */
148
147 /* IRQ0=LAN, IRQ1=ATA, IRQ3=SLT,PCM */ 149 /* IRQ0=LAN, IRQ1=ATA, IRQ3=SLT,PCM */
148 __raw_writew(0x0001,INTSEL); 150 __raw_writew(0x0001,INTSEL);
149} 151}
diff --git a/arch/sh/boards/mach-se/7206/setup.c b/arch/sh/boards/mach-se/7206/setup.c
index 8f5c65d43d1d..7f4871c71a01 100644
--- a/arch/sh/boards/mach-se/7206/setup.c
+++ b/arch/sh/boards/mach-se/7206/setup.c
@@ -86,20 +86,5 @@ __initcall(se7206_devices_setup);
86static struct sh_machine_vector mv_se __initmv = { 86static struct sh_machine_vector mv_se __initmv = {
87 .mv_name = "SolutionEngine", 87 .mv_name = "SolutionEngine",
88 .mv_nr_irqs = 256, 88 .mv_nr_irqs = 256,
89 .mv_inb = se7206_inb,
90 .mv_inw = se7206_inw,
91 .mv_outb = se7206_outb,
92 .mv_outw = se7206_outw,
93
94 .mv_inb_p = se7206_inb_p,
95 .mv_inw_p = se7206_inw,
96 .mv_outb_p = se7206_outb_p,
97 .mv_outw_p = se7206_outw,
98
99 .mv_insb = se7206_insb,
100 .mv_insw = se7206_insw,
101 .mv_outsb = se7206_outsb,
102 .mv_outsw = se7206_outsw,
103
104 .mv_init_irq = init_se7206_IRQ, 89 .mv_init_irq = init_se7206_IRQ,
105}; 90};
diff --git a/arch/sh/boards/mach-se/770x/Makefile b/arch/sh/boards/mach-se/770x/Makefile
index 8e624b06d5ea..43ea14feef51 100644
--- a/arch/sh/boards/mach-se/770x/Makefile
+++ b/arch/sh/boards/mach-se/770x/Makefile
@@ -2,4 +2,4 @@
2# Makefile for the 770x SolutionEngine specific parts of the kernel 2# Makefile for the 770x SolutionEngine specific parts of the kernel
3# 3#
4 4
5obj-y := setup.o io.o irq.o 5obj-y := setup.o irq.o
diff --git a/arch/sh/boards/mach-se/770x/io.c b/arch/sh/boards/mach-se/770x/io.c
deleted file mode 100644
index 28833c8786ea..000000000000
--- a/arch/sh/boards/mach-se/770x/io.c
+++ /dev/null
@@ -1,156 +0,0 @@
1/*
2 * Copyright (C) 2000 Kazumoto Kojima
3 *
4 * I/O routine for Hitachi SolutionEngine.
5 */
6#include <linux/kernel.h>
7#include <linux/types.h>
8#include <asm/io.h>
9#include <mach-se/mach/se.h>
10
11/* MS7750 requires special versions of in*, out* routines, since
12 PC-like io ports are located at upper half byte of 16-bit word which
13 can be accessed only with 16-bit wide. */
14
15static inline volatile __u16 *
16port2adr(unsigned int port)
17{
18 if (port & 0xff000000)
19 return ( volatile __u16 *) port;
20 if (port >= 0x2000)
21 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
22 else if (port >= 0x1000)
23 return (volatile __u16 *) (PA_83902 + (port << 1));
24 else
25 return (volatile __u16 *) (PA_SUPERIO + (port << 1));
26}
27
28static inline int
29shifted_port(unsigned long port)
30{
31 /* For IDE registers, value is not shifted */
32 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
33 return 0;
34 else
35 return 1;
36}
37
38unsigned char se_inb(unsigned long port)
39{
40 if (shifted_port(port))
41 return (*port2adr(port) >> 8);
42 else
43 return (*port2adr(port))&0xff;
44}
45
46unsigned char se_inb_p(unsigned long port)
47{
48 unsigned long v;
49
50 if (shifted_port(port))
51 v = (*port2adr(port) >> 8);
52 else
53 v = (*port2adr(port))&0xff;
54 ctrl_delay();
55 return v;
56}
57
58unsigned short se_inw(unsigned long port)
59{
60 if (port >= 0x2000)
61 return *port2adr(port);
62 else
63 maybebadio(port);
64 return 0;
65}
66
67unsigned int se_inl(unsigned long port)
68{
69 maybebadio(port);
70 return 0;
71}
72
73void se_outb(unsigned char value, unsigned long port)
74{
75 if (shifted_port(port))
76 *(port2adr(port)) = value << 8;
77 else
78 *(port2adr(port)) = value;
79}
80
81void se_outb_p(unsigned char value, unsigned long port)
82{
83 if (shifted_port(port))
84 *(port2adr(port)) = value << 8;
85 else
86 *(port2adr(port)) = value;
87 ctrl_delay();
88}
89
90void se_outw(unsigned short value, unsigned long port)
91{
92 if (port >= 0x2000)
93 *port2adr(port) = value;
94 else
95 maybebadio(port);
96}
97
98void se_outl(unsigned int value, unsigned long port)
99{
100 maybebadio(port);
101}
102
103void se_insb(unsigned long port, void *addr, unsigned long count)
104{
105 volatile __u16 *p = port2adr(port);
106 __u8 *ap = addr;
107
108 if (shifted_port(port)) {
109 while (count--)
110 *ap++ = *p >> 8;
111 } else {
112 while (count--)
113 *ap++ = *p;
114 }
115}
116
117void se_insw(unsigned long port, void *addr, unsigned long count)
118{
119 volatile __u16 *p = port2adr(port);
120 __u16 *ap = addr;
121 while (count--)
122 *ap++ = *p;
123}
124
125void se_insl(unsigned long port, void *addr, unsigned long count)
126{
127 maybebadio(port);
128}
129
130void se_outsb(unsigned long port, const void *addr, unsigned long count)
131{
132 volatile __u16 *p = port2adr(port);
133 const __u8 *ap = addr;
134
135 if (shifted_port(port)) {
136 while (count--)
137 *p = *ap++ << 8;
138 } else {
139 while (count--)
140 *p = *ap++;
141 }
142}
143
144void se_outsw(unsigned long port, const void *addr, unsigned long count)
145{
146 volatile __u16 *p = port2adr(port);
147 const __u16 *ap = addr;
148
149 while (count--)
150 *p = *ap++;
151}
152
153void se_outsl(unsigned long port, const void *addr, unsigned long count)
154{
155 maybebadio(port);
156}
diff --git a/arch/sh/boards/mach-se/770x/setup.c b/arch/sh/boards/mach-se/770x/setup.c
index 66d39d1b0901..31330c65c0ce 100644
--- a/arch/sh/boards/mach-se/770x/setup.c
+++ b/arch/sh/boards/mach-se/770x/setup.c
@@ -195,27 +195,5 @@ static struct sh_machine_vector mv_se __initmv = {
195#elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712) 195#elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
196 .mv_nr_irqs = 104, 196 .mv_nr_irqs = 104,
197#endif 197#endif
198
199 .mv_inb = se_inb,
200 .mv_inw = se_inw,
201 .mv_inl = se_inl,
202 .mv_outb = se_outb,
203 .mv_outw = se_outw,
204 .mv_outl = se_outl,
205
206 .mv_inb_p = se_inb_p,
207 .mv_inw_p = se_inw,
208 .mv_inl_p = se_inl,
209 .mv_outb_p = se_outb_p,
210 .mv_outw_p = se_outw,
211 .mv_outl_p = se_outl,
212
213 .mv_insb = se_insb,
214 .mv_insw = se_insw,
215 .mv_insl = se_insl,
216 .mv_outsb = se_outsb,
217 .mv_outsw = se_outsw,
218 .mv_outsl = se_outsl,
219
220 .mv_init_irq = init_se_IRQ, 198 .mv_init_irq = init_se_IRQ,
221}; 199};
diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c
index c31d228fdfc6..527a0cd956b5 100644
--- a/arch/sh/boards/mach-se/7724/setup.c
+++ b/arch/sh/boards/mach-se/7724/setup.c
@@ -283,31 +283,6 @@ static struct platform_device ceu1_device = {
283}; 283};
284 284
285/* FSI */ 285/* FSI */
286/*
287 * FSI-A use external clock which came from ak464x.
288 * So, we should change parent of fsi
289 */
290#define FCLKACR 0xa4150008
291static void fsimck_init(struct clk *clk)
292{
293 u32 status = __raw_readl(clk->enable_reg);
294
295 /* use external clock */
296 status &= ~0x000000ff;
297 status |= 0x00000080;
298 __raw_writel(status, clk->enable_reg);
299}
300
301static struct clk_ops fsimck_clk_ops = {
302 .init = fsimck_init,
303};
304
305static struct clk fsimcka_clk = {
306 .ops = &fsimck_clk_ops,
307 .enable_reg = (void __iomem *)FCLKACR,
308 .rate = 0, /* unknown */
309};
310
311/* change J20, J21, J22 pin to 1-2 connection to use slave mode */ 286/* change J20, J21, J22 pin to 1-2 connection to use slave mode */
312static struct sh_fsi_platform_info fsi_info = { 287static struct sh_fsi_platform_info fsi_info = {
313 .porta_flags = SH_FSI_BRS_INV | 288 .porta_flags = SH_FSI_BRS_INV |
@@ -852,37 +827,29 @@ static int __init devices_setup(void)
852 gpio_request(GPIO_FN_KEYOUT0, NULL); 827 gpio_request(GPIO_FN_KEYOUT0, NULL);
853 828
854 /* enable FSI */ 829 /* enable FSI */
855 gpio_request(GPIO_FN_FSIMCKB, NULL);
856 gpio_request(GPIO_FN_FSIMCKA, NULL); 830 gpio_request(GPIO_FN_FSIMCKA, NULL);
831 gpio_request(GPIO_FN_FSIIASD, NULL);
857 gpio_request(GPIO_FN_FSIOASD, NULL); 832 gpio_request(GPIO_FN_FSIOASD, NULL);
858 gpio_request(GPIO_FN_FSIIABCK, NULL); 833 gpio_request(GPIO_FN_FSIIABCK, NULL);
859 gpio_request(GPIO_FN_FSIIALRCK, NULL); 834 gpio_request(GPIO_FN_FSIIALRCK, NULL);
860 gpio_request(GPIO_FN_FSIOABCK, NULL); 835 gpio_request(GPIO_FN_FSIOABCK, NULL);
861 gpio_request(GPIO_FN_FSIOALRCK, NULL); 836 gpio_request(GPIO_FN_FSIOALRCK, NULL);
862 gpio_request(GPIO_FN_CLKAUDIOAO, NULL); 837 gpio_request(GPIO_FN_CLKAUDIOAO, NULL);
863 gpio_request(GPIO_FN_FSIIBSD, NULL);
864 gpio_request(GPIO_FN_FSIOBSD, NULL);
865 gpio_request(GPIO_FN_FSIIBBCK, NULL);
866 gpio_request(GPIO_FN_FSIIBLRCK, NULL);
867 gpio_request(GPIO_FN_FSIOBBCK, NULL);
868 gpio_request(GPIO_FN_FSIOBLRCK, NULL);
869 gpio_request(GPIO_FN_CLKAUDIOBO, NULL);
870 gpio_request(GPIO_FN_FSIIASD, NULL);
871 838
872 /* set SPU2 clock to 83.4 MHz */ 839 /* set SPU2 clock to 83.4 MHz */
873 clk = clk_get(NULL, "spu_clk"); 840 clk = clk_get(NULL, "spu_clk");
874 if (clk) { 841 if (!IS_ERR(clk)) {
875 clk_set_rate(clk, clk_round_rate(clk, 83333333)); 842 clk_set_rate(clk, clk_round_rate(clk, 83333333));
876 clk_put(clk); 843 clk_put(clk);
877 } 844 }
878 845
879 /* change parent of FSI A */ 846 /* change parent of FSI A */
880 clk = clk_get(NULL, "fsia_clk"); 847 clk = clk_get(NULL, "fsia_clk");
881 if (clk) { 848 if (!IS_ERR(clk)) {
882 clk_register(&fsimcka_clk); 849 /* 48kHz dummy clock was used to make sure 1/1 divide */
883 clk_set_parent(clk, &fsimcka_clk); 850 clk_set_rate(&sh7724_fsimcka_clk, 48000);
884 clk_set_rate(clk, 11000); 851 clk_set_parent(clk, &sh7724_fsimcka_clk);
885 clk_set_rate(&fsimcka_clk, 11000); 852 clk_set_rate(clk, 48000);
886 clk_put(clk); 853 clk_put(clk);
887 } 854 }
888 855
diff --git a/arch/sh/boards/mach-se/7751/Makefile b/arch/sh/boards/mach-se/7751/Makefile
index e6f4341bfe6e..a338fd9d5039 100644
--- a/arch/sh/boards/mach-se/7751/Makefile
+++ b/arch/sh/boards/mach-se/7751/Makefile
@@ -2,4 +2,4 @@
2# Makefile for the 7751 SolutionEngine specific parts of the kernel 2# Makefile for the 7751 SolutionEngine specific parts of the kernel
3# 3#
4 4
5obj-y := setup.o io.o irq.o 5obj-y := setup.o irq.o
diff --git a/arch/sh/boards/mach-se/7751/io.c b/arch/sh/boards/mach-se/7751/io.c
deleted file mode 100644
index 6e75bd4459e5..000000000000
--- a/arch/sh/boards/mach-se/7751/io.c
+++ /dev/null
@@ -1,119 +0,0 @@
1/*
2 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
3 * Based largely on io_se.c.
4 *
5 * I/O routine for Hitachi 7751 SolutionEngine.
6 *
7 * Initial version only to support LAN access; some
8 * placeholder code from io_se.c left in with the
9 * expectation of later SuperIO and PCMCIA access.
10 */
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/pci.h>
14#include <asm/io.h>
15#include <mach-se/mach/se7751.h>
16#include <asm/addrspace.h>
17
18static inline volatile u16 *port2adr(unsigned int port)
19{
20 if (port >= 0x2000)
21 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
22 maybebadio((unsigned long)port);
23 return (volatile __u16*)port;
24}
25
26/*
27 * General outline: remap really low stuff [eventually] to SuperIO,
28 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
29 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
30 * should be way beyond the window, and is used w/o translation for
31 * compatibility.
32 */
33unsigned char sh7751se_inb(unsigned long port)
34{
35 if (PXSEG(port))
36 return *(volatile unsigned char *)port;
37 else
38 return (*port2adr(port)) & 0xff;
39}
40
41unsigned char sh7751se_inb_p(unsigned long port)
42{
43 unsigned char v;
44
45 if (PXSEG(port))
46 v = *(volatile unsigned char *)port;
47 else
48 v = (*port2adr(port)) & 0xff;
49 ctrl_delay();
50 return v;
51}
52
53unsigned short sh7751se_inw(unsigned long port)
54{
55 if (PXSEG(port))
56 return *(volatile unsigned short *)port;
57 else if (port >= 0x2000)
58 return *port2adr(port);
59 else
60 maybebadio(port);
61 return 0;
62}
63
64unsigned int sh7751se_inl(unsigned long port)
65{
66 if (PXSEG(port))
67 return *(volatile unsigned long *)port;
68 else if (port >= 0x2000)
69 return *port2adr(port);
70 else
71 maybebadio(port);
72 return 0;
73}
74
75void sh7751se_outb(unsigned char value, unsigned long port)
76{
77
78 if (PXSEG(port))
79 *(volatile unsigned char *)port = value;
80 else
81 *(port2adr(port)) = value;
82}
83
84void sh7751se_outb_p(unsigned char value, unsigned long port)
85{
86 if (PXSEG(port))
87 *(volatile unsigned char *)port = value;
88 else
89 *(port2adr(port)) = value;
90 ctrl_delay();
91}
92
93void sh7751se_outw(unsigned short value, unsigned long port)
94{
95 if (PXSEG(port))
96 *(volatile unsigned short *)port = value;
97 else if (port >= 0x2000)
98 *port2adr(port) = value;
99 else
100 maybebadio(port);
101}
102
103void sh7751se_outl(unsigned int value, unsigned long port)
104{
105 if (PXSEG(port))
106 *(volatile unsigned long *)port = value;
107 else
108 maybebadio(port);
109}
110
111void sh7751se_insl(unsigned long port, void *addr, unsigned long count)
112{
113 maybebadio(port);
114}
115
116void sh7751se_outsl(unsigned long port, const void *addr, unsigned long count)
117{
118 maybebadio(port);
119}
diff --git a/arch/sh/boards/mach-se/7751/setup.c b/arch/sh/boards/mach-se/7751/setup.c
index 50572512e3e8..9fbc51beb181 100644
--- a/arch/sh/boards/mach-se/7751/setup.c
+++ b/arch/sh/boards/mach-se/7751/setup.c
@@ -56,23 +56,5 @@ __initcall(se7751_devices_setup);
56static struct sh_machine_vector mv_7751se __initmv = { 56static struct sh_machine_vector mv_7751se __initmv = {
57 .mv_name = "7751 SolutionEngine", 57 .mv_name = "7751 SolutionEngine",
58 .mv_nr_irqs = 72, 58 .mv_nr_irqs = 72,
59
60 .mv_inb = sh7751se_inb,
61 .mv_inw = sh7751se_inw,
62 .mv_inl = sh7751se_inl,
63 .mv_outb = sh7751se_outb,
64 .mv_outw = sh7751se_outw,
65 .mv_outl = sh7751se_outl,
66
67 .mv_inb_p = sh7751se_inb_p,
68 .mv_inw_p = sh7751se_inw,
69 .mv_inl_p = sh7751se_inl,
70 .mv_outb_p = sh7751se_outb_p,
71 .mv_outw_p = sh7751se_outw,
72 .mv_outl_p = sh7751se_outl,
73
74 .mv_insl = sh7751se_insl,
75 .mv_outsl = sh7751se_outsl,
76
77 .mv_init_irq = init_7751se_IRQ, 59 .mv_init_irq = init_7751se_IRQ,
78}; 60};
diff --git a/arch/sh/boards/mach-snapgear/Makefile b/arch/sh/boards/mach-snapgear/Makefile
deleted file mode 100644
index d2d2f4b6a502..000000000000
--- a/arch/sh/boards/mach-snapgear/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1#
2# Makefile for the SnapGear specific parts of the kernel
3#
4
5obj-y := setup.o io.o
diff --git a/arch/sh/boards/mach-snapgear/io.c b/arch/sh/boards/mach-snapgear/io.c
deleted file mode 100644
index 476650e42dbc..000000000000
--- a/arch/sh/boards/mach-snapgear/io.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/*
2 * Copyright (C) 2002 David McCullough <davidm@snapgear.com>
3 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
4 * Based largely on io_se.c.
5 *
6 * I/O routine for Hitachi 7751 SolutionEngine.
7 *
8 * Initial version only to support LAN access; some
9 * placeholder code from io_se.c left in with the
10 * expectation of later SuperIO and PCMCIA access.
11 */
12#include <linux/kernel.h>
13#include <linux/types.h>
14#include <linux/pci.h>
15#include <asm/io.h>
16#include <asm/addrspace.h>
17
18#ifdef CONFIG_SH_SECUREEDGE5410
19unsigned short secureedge5410_ioport;
20#endif
21
22static inline volatile __u16 *port2adr(unsigned int port)
23{
24 maybebadio((unsigned long)port);
25 return (volatile __u16*)port;
26}
27
28/*
29 * General outline: remap really low stuff [eventually] to SuperIO,
30 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
31 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
32 * should be way beyond the window, and is used w/o translation for
33 * compatibility.
34 */
35unsigned char snapgear_inb(unsigned long port)
36{
37 if (PXSEG(port))
38 return *(volatile unsigned char *)port;
39 else
40 return (*port2adr(port)) & 0xff;
41}
42
43unsigned char snapgear_inb_p(unsigned long port)
44{
45 unsigned char v;
46
47 if (PXSEG(port))
48 v = *(volatile unsigned char *)port;
49 else
50 v = (*port2adr(port))&0xff;
51 ctrl_delay();
52 return v;
53}
54
55unsigned short snapgear_inw(unsigned long port)
56{
57 if (PXSEG(port))
58 return *(volatile unsigned short *)port;
59 else if (port >= 0x2000)
60 return *port2adr(port);
61 else
62 maybebadio(port);
63 return 0;
64}
65
66unsigned int snapgear_inl(unsigned long port)
67{
68 if (PXSEG(port))
69 return *(volatile unsigned long *)port;
70 else if (port >= 0x2000)
71 return *port2adr(port);
72 else
73 maybebadio(port);
74 return 0;
75}
76
77void snapgear_outb(unsigned char value, unsigned long port)
78{
79
80 if (PXSEG(port))
81 *(volatile unsigned char *)port = value;
82 else
83 *(port2adr(port)) = value;
84}
85
86void snapgear_outb_p(unsigned char value, unsigned long port)
87{
88 if (PXSEG(port))
89 *(volatile unsigned char *)port = value;
90 else
91 *(port2adr(port)) = value;
92 ctrl_delay();
93}
94
95void snapgear_outw(unsigned short value, unsigned long port)
96{
97 if (PXSEG(port))
98 *(volatile unsigned short *)port = value;
99 else if (port >= 0x2000)
100 *port2adr(port) = value;
101 else
102 maybebadio(port);
103}
104
105void snapgear_outl(unsigned int value, unsigned long port)
106{
107 if (PXSEG(port))
108 *(volatile unsigned long *)port = value;
109 else
110 maybebadio(port);
111}
112
113void snapgear_insl(unsigned long port, void *addr, unsigned long count)
114{
115 maybebadio(port);
116}
117
118void snapgear_outsl(unsigned long port, const void *addr, unsigned long count)
119{
120 maybebadio(port);
121}
diff --git a/arch/sh/boards/mach-systemh/Makefile b/arch/sh/boards/mach-systemh/Makefile
deleted file mode 100644
index 2cc6a23d9d39..000000000000
--- a/arch/sh/boards/mach-systemh/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
1#
2# Makefile for the SystemH specific parts of the kernel
3#
4
5obj-y := setup.o irq.o io.o
6
7# XXX: This wants to be consolidated in arch/sh/drivers/pci, and more
8# importantly, with the generic sh7751_pcic_init() code. For now, we'll
9# just abuse the hell out of kbuild, because we can..
10
11obj-$(CONFIG_PCI) += pci.o
12pci-y := ../../se/7751/pci.o
13
diff --git a/arch/sh/boards/mach-systemh/io.c b/arch/sh/boards/mach-systemh/io.c
deleted file mode 100644
index 15577ff1f715..000000000000
--- a/arch/sh/boards/mach-systemh/io.c
+++ /dev/null
@@ -1,158 +0,0 @@
1/*
2 * linux/arch/sh/boards/renesas/systemh/io.c
3 *
4 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
5 * Based largely on io_se.c.
6 *
7 * I/O routine for Hitachi 7751 Systemh.
8 */
9#include <linux/kernel.h>
10#include <linux/types.h>
11#include <linux/pci.h>
12#include <mach/systemh7751.h>
13#include <asm/addrspace.h>
14#include <asm/io.h>
15
16#define ETHER_IOMAP(adr) (0xB3000000 + (adr)) /*map to 16bits access area
17 of smc lan chip*/
18static inline volatile __u16 *
19port2adr(unsigned int port)
20{
21 if (port >= 0x2000)
22 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
23 maybebadio((unsigned long)port);
24 return (volatile __u16*)port;
25}
26
27/*
28 * General outline: remap really low stuff [eventually] to SuperIO,
29 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
30 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
31 * should be way beyond the window, and is used w/o translation for
32 * compatibility.
33 */
34unsigned char sh7751systemh_inb(unsigned long port)
35{
36 if (PXSEG(port))
37 return *(volatile unsigned char *)port;
38 else if (port <= 0x3F1)
39 return *(volatile unsigned char *)ETHER_IOMAP(port);
40 else
41 return (*port2adr(port))&0xff;
42}
43
44unsigned char sh7751systemh_inb_p(unsigned long port)
45{
46 unsigned char v;
47
48 if (PXSEG(port))
49 v = *(volatile unsigned char *)port;
50 else if (port <= 0x3F1)
51 v = *(volatile unsigned char *)ETHER_IOMAP(port);
52 else
53 v = (*port2adr(port))&0xff;
54 ctrl_delay();
55 return v;
56}
57
58unsigned short sh7751systemh_inw(unsigned long port)
59{
60 if (PXSEG(port))
61 return *(volatile unsigned short *)port;
62 else if (port >= 0x2000)
63 return *port2adr(port);
64 else if (port <= 0x3F1)
65 return *(volatile unsigned int *)ETHER_IOMAP(port);
66 else
67 maybebadio(port);
68 return 0;
69}
70
71unsigned int sh7751systemh_inl(unsigned long port)
72{
73 if (PXSEG(port))
74 return *(volatile unsigned long *)port;
75 else if (port >= 0x2000)
76 return *port2adr(port);
77 else if (port <= 0x3F1)
78 return *(volatile unsigned int *)ETHER_IOMAP(port);
79 else
80 maybebadio(port);
81 return 0;
82}
83
84void sh7751systemh_outb(unsigned char value, unsigned long port)
85{
86
87 if (PXSEG(port))
88 *(volatile unsigned char *)port = value;
89 else if (port <= 0x3F1)
90 *(volatile unsigned char *)ETHER_IOMAP(port) = value;
91 else
92 *(port2adr(port)) = value;
93}
94
95void sh7751systemh_outb_p(unsigned char value, unsigned long port)
96{
97 if (PXSEG(port))
98 *(volatile unsigned char *)port = value;
99 else if (port <= 0x3F1)
100 *(volatile unsigned char *)ETHER_IOMAP(port) = value;
101 else
102 *(port2adr(port)) = value;
103 ctrl_delay();
104}
105
106void sh7751systemh_outw(unsigned short value, unsigned long port)
107{
108 if (PXSEG(port))
109 *(volatile unsigned short *)port = value;
110 else if (port >= 0x2000)
111 *port2adr(port) = value;
112 else if (port <= 0x3F1)
113 *(volatile unsigned short *)ETHER_IOMAP(port) = value;
114 else
115 maybebadio(port);
116}
117
118void sh7751systemh_outl(unsigned int value, unsigned long port)
119{
120 if (PXSEG(port))
121 *(volatile unsigned long *)port = value;
122 else
123 maybebadio(port);
124}
125
126void sh7751systemh_insb(unsigned long port, void *addr, unsigned long count)
127{
128 unsigned char *p = addr;
129 while (count--) *p++ = sh7751systemh_inb(port);
130}
131
132void sh7751systemh_insw(unsigned long port, void *addr, unsigned long count)
133{
134 unsigned short *p = addr;
135 while (count--) *p++ = sh7751systemh_inw(port);
136}
137
138void sh7751systemh_insl(unsigned long port, void *addr, unsigned long count)
139{
140 maybebadio(port);
141}
142
143void sh7751systemh_outsb(unsigned long port, const void *addr, unsigned long count)
144{
145 unsigned char *p = (unsigned char*)addr;
146 while (count--) sh7751systemh_outb(*p++, port);
147}
148
149void sh7751systemh_outsw(unsigned long port, const void *addr, unsigned long count)
150{
151 unsigned short *p = (unsigned short*)addr;
152 while (count--) sh7751systemh_outw(*p++, port);
153}
154
155void sh7751systemh_outsl(unsigned long port, const void *addr, unsigned long count)
156{
157 maybebadio(port);
158}
diff --git a/arch/sh/boards/mach-systemh/irq.c b/arch/sh/boards/mach-systemh/irq.c
deleted file mode 100644
index e5ee13adeff4..000000000000
--- a/arch/sh/boards/mach-systemh/irq.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/*
2 * linux/arch/sh/boards/renesas/systemh/irq.c
3 *
4 * Copyright (C) 2000 Kazumoto Kojima
5 *
6 * Hitachi SystemH Support.
7 *
8 * Modified for 7751 SystemH by
9 * Jonathan Short.
10 */
11
12#include <linux/init.h>
13#include <linux/irq.h>
14#include <linux/interrupt.h>
15#include <linux/io.h>
16
17#include <mach/systemh7751.h>
18#include <asm/smc37c93x.h>
19
20/* address of external interrupt mask register
21 * address must be set prior to use these (maybe in init_XXX_irq())
22 * XXX : is it better to use .config than specifying it in code? */
23static unsigned long *systemh_irq_mask_register = (unsigned long *)0xB3F10004;
24static unsigned long *systemh_irq_request_register = (unsigned long *)0xB3F10000;
25
26static void disable_systemh_irq(struct irq_data *data)
27{
28 unsigned long val, mask = 0x01 << 1;
29
30 /* Clear the "irq"th bit in the mask and set it in the request */
31 val = __raw_readl((unsigned long)systemh_irq_mask_register);
32 val &= ~mask;
33 __raw_writel(val, (unsigned long)systemh_irq_mask_register);
34
35 val = __raw_readl((unsigned long)systemh_irq_request_register);
36 val |= mask;
37 __raw_writel(val, (unsigned long)systemh_irq_request_register);
38}
39
40static void enable_systemh_irq(struct irq_data *data)
41{
42 unsigned long val, mask = 0x01 << 1;
43
44 /* Set "irq"th bit in the mask register */
45 val = __raw_readl((unsigned long)systemh_irq_mask_register);
46 val |= mask;
47 __raw_writel(val, (unsigned long)systemh_irq_mask_register);
48}
49
50static struct irq_chip systemh_irq_type = {
51 .name = "SystemH Register",
52 .irq_unmask = enable_systemh_irq,
53 .irq_mask = disable_systemh_irq,
54};
55
56void make_systemh_irq(unsigned int irq)
57{
58 disable_irq_nosync(irq);
59 set_irq_chip_and_handler(irq, &systemh_irq_type, handle_level_irq);
60 disable_systemh_irq(irq_get_irq_data(irq));
61}
diff --git a/arch/sh/boards/mach-systemh/setup.c b/arch/sh/boards/mach-systemh/setup.c
deleted file mode 100644
index 219fd800a43f..000000000000
--- a/arch/sh/boards/mach-systemh/setup.c
+++ /dev/null
@@ -1,57 +0,0 @@
1/*
2 * linux/arch/sh/boards/renesas/systemh/setup.c
3 *
4 * Copyright (C) 2000 Kazumoto Kojima
5 * Copyright (C) 2003 Paul Mundt
6 *
7 * Hitachi SystemH Support.
8 *
9 * Modified for 7751 SystemH by Jonathan Short.
10 *
11 * Rewritten for 2.6 by Paul Mundt.
12 *
13 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file "COPYING" in the main directory of this archive
15 * for more details.
16 */
17#include <linux/init.h>
18#include <asm/machvec.h>
19#include <mach/systemh7751.h>
20
21extern void make_systemh_irq(unsigned int irq);
22
23/*
24 * Initialize IRQ setting
25 */
26static void __init sh7751systemh_init_irq(void)
27{
28 make_systemh_irq(0xb); /* Ethernet interrupt */
29}
30
31static struct sh_machine_vector mv_7751systemh __initmv = {
32 .mv_name = "7751 SystemH",
33 .mv_nr_irqs = 72,
34
35 .mv_inb = sh7751systemh_inb,
36 .mv_inw = sh7751systemh_inw,
37 .mv_inl = sh7751systemh_inl,
38 .mv_outb = sh7751systemh_outb,
39 .mv_outw = sh7751systemh_outw,
40 .mv_outl = sh7751systemh_outl,
41
42 .mv_inb_p = sh7751systemh_inb_p,
43 .mv_inw_p = sh7751systemh_inw,
44 .mv_inl_p = sh7751systemh_inl,
45 .mv_outb_p = sh7751systemh_outb_p,
46 .mv_outw_p = sh7751systemh_outw,
47 .mv_outl_p = sh7751systemh_outl,
48
49 .mv_insb = sh7751systemh_insb,
50 .mv_insw = sh7751systemh_insw,
51 .mv_insl = sh7751systemh_insl,
52 .mv_outsb = sh7751systemh_outsb,
53 .mv_outsw = sh7751systemh_outsw,
54 .mv_outsl = sh7751systemh_outsl,
55
56 .mv_init_irq = sh7751systemh_init_irq,
57};
diff --git a/arch/sh/configs/snapgear_defconfig b/arch/sh/configs/secureedge5410_defconfig
index 7eae4e59d7f0..7eae4e59d7f0 100644
--- a/arch/sh/configs/snapgear_defconfig
+++ b/arch/sh/configs/secureedge5410_defconfig
diff --git a/arch/sh/configs/systemh_defconfig b/arch/sh/configs/systemh_defconfig
deleted file mode 100644
index b58dfc505efe..000000000000
--- a/arch/sh/configs/systemh_defconfig
+++ /dev/null
@@ -1,28 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_LOG_BUF_SHIFT=14
3CONFIG_BLK_DEV_INITRD=y
4# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
5# CONFIG_SYSCTL_SYSCALL is not set
6# CONFIG_HOTPLUG is not set
7CONFIG_SLAB=y
8CONFIG_MODULES=y
9CONFIG_MODULE_UNLOAD=y
10# CONFIG_BLK_DEV_BSG is not set
11CONFIG_CPU_SUBTYPE_SH7751R=y
12CONFIG_MEMORY_START=0x0c000000
13CONFIG_MEMORY_SIZE=0x00400000
14CONFIG_FLATMEM_MANUAL=y
15CONFIG_SH_7751_SYSTEMH=y
16CONFIG_PREEMPT=y
17# CONFIG_STANDALONE is not set
18CONFIG_BLK_DEV_RAM=y
19CONFIG_BLK_DEV_RAM_SIZE=1024
20# CONFIG_INPUT is not set
21# CONFIG_SERIO_SERPORT is not set
22# CONFIG_VT is not set
23CONFIG_HW_RANDOM=y
24CONFIG_PROC_KCORE=y
25CONFIG_TMPFS=y
26CONFIG_CRAMFS=y
27CONFIG_ROMFS_FS=y
28# CONFIG_RCU_CPU_STALL_DETECTOR is not set
diff --git a/arch/sh/include/asm/addrspace.h b/arch/sh/include/asm/addrspace.h
index 446b3831c214..3d1ae2bfaa6f 100644
--- a/arch/sh/include/asm/addrspace.h
+++ b/arch/sh/include/asm/addrspace.h
@@ -44,10 +44,10 @@
44/* 44/*
45 * These will never work in 32-bit, don't even bother. 45 * These will never work in 32-bit, don't even bother.
46 */ 46 */
47#define P1SEGADDR(a) __futile_remapping_attempt 47#define P1SEGADDR(a) ({ (void)(a); BUG(); NULL; })
48#define P2SEGADDR(a) __futile_remapping_attempt 48#define P2SEGADDR(a) ({ (void)(a); BUG(); NULL; })
49#define P3SEGADDR(a) __futile_remapping_attempt 49#define P3SEGADDR(a) ({ (void)(a); BUG(); NULL; })
50#define P4SEGADDR(a) __futile_remapping_attempt 50#define P4SEGADDR(a) ({ (void)(a); BUG(); NULL; })
51#endif 51#endif
52#endif /* P1SEG */ 52#endif /* P1SEG */
53 53
diff --git a/arch/sh/include/asm/cacheflush.h b/arch/sh/include/asm/cacheflush.h
index 1f4e562c5e8c..82e1eabeac98 100644
--- a/arch/sh/include/asm/cacheflush.h
+++ b/arch/sh/include/asm/cacheflush.h
@@ -96,7 +96,7 @@ void kmap_coherent_init(void);
96void *kmap_coherent(struct page *page, unsigned long addr); 96void *kmap_coherent(struct page *page, unsigned long addr);
97void kunmap_coherent(void *kvaddr); 97void kunmap_coherent(void *kvaddr);
98 98
99#define PG_dcache_dirty PG_arch_1 99#define PG_dcache_clean PG_arch_1
100 100
101void cpu_cache_init(void); 101void cpu_cache_init(void);
102 102
diff --git a/arch/sh/include/asm/pgtable.h b/arch/sh/include/asm/pgtable.h
index a15f1058bbf4..083ea068e819 100644
--- a/arch/sh/include/asm/pgtable.h
+++ b/arch/sh/include/asm/pgtable.h
@@ -66,7 +66,6 @@ static inline unsigned long long neff_sign_extend(unsigned long val)
66#define PHYS_ADDR_MASK29 0x1fffffff 66#define PHYS_ADDR_MASK29 0x1fffffff
67#define PHYS_ADDR_MASK32 0xffffffff 67#define PHYS_ADDR_MASK32 0xffffffff
68 68
69#ifdef CONFIG_PMB
70static inline unsigned long phys_addr_mask(void) 69static inline unsigned long phys_addr_mask(void)
71{ 70{
72 /* Is the MMU in 29bit mode? */ 71 /* Is the MMU in 29bit mode? */
@@ -75,17 +74,6 @@ static inline unsigned long phys_addr_mask(void)
75 74
76 return PHYS_ADDR_MASK32; 75 return PHYS_ADDR_MASK32;
77} 76}
78#elif defined(CONFIG_32BIT)
79static inline unsigned long phys_addr_mask(void)
80{
81 return PHYS_ADDR_MASK32;
82}
83#else
84static inline unsigned long phys_addr_mask(void)
85{
86 return PHYS_ADDR_MASK29;
87}
88#endif
89 77
90#define PTE_PHYS_MASK (phys_addr_mask() & PAGE_MASK) 78#define PTE_PHYS_MASK (phys_addr_mask() & PAGE_MASK)
91#define PTE_FLAGS_MASK (~(PTE_PHYS_MASK) << PAGE_SHIFT) 79#define PTE_FLAGS_MASK (~(PTE_PHYS_MASK) << PAGE_SHIFT)
diff --git a/arch/sh/include/asm/processor_32.h b/arch/sh/include/asm/processor_32.h
index 46d5179c9f49..e3c73cdd8c90 100644
--- a/arch/sh/include/asm/processor_32.h
+++ b/arch/sh/include/asm/processor_32.h
@@ -199,10 +199,13 @@ extern unsigned long get_wchan(struct task_struct *p);
199#define ARCH_HAS_PREFETCHW 199#define ARCH_HAS_PREFETCHW
200static inline void prefetch(void *x) 200static inline void prefetch(void *x)
201{ 201{
202 __asm__ __volatile__ ("pref @%0\n\t" : : "r" (x) : "memory"); 202 __builtin_prefetch(x, 0, 3);
203} 203}
204 204
205#define prefetchw(x) prefetch(x) 205static inline void prefetchw(void *x)
206{
207 __builtin_prefetch(x, 1, 3);
208}
206#endif 209#endif
207 210
208#endif /* __KERNEL__ */ 211#endif /* __KERNEL__ */
diff --git a/arch/sh/include/asm/system.h b/arch/sh/include/asm/system.h
index 1f1af5afff03..10c8b1823a18 100644
--- a/arch/sh/include/asm/system.h
+++ b/arch/sh/include/asm/system.h
@@ -10,6 +10,7 @@
10#include <linux/compiler.h> 10#include <linux/compiler.h>
11#include <linux/linkage.h> 11#include <linux/linkage.h>
12#include <asm/types.h> 12#include <asm/types.h>
13#include <asm/uncached.h>
13 14
14#define AT_VECTOR_SIZE_ARCH 5 /* entries in ARCH_DLINFO */ 15#define AT_VECTOR_SIZE_ARCH 5 /* entries in ARCH_DLINFO */
15 16
@@ -137,9 +138,6 @@ extern unsigned int instruction_size(unsigned int insn);
137#define instruction_size(insn) (4) 138#define instruction_size(insn) (4)
138#endif 139#endif
139 140
140extern unsigned long cached_to_uncached;
141extern unsigned long uncached_size;
142
143void per_cpu_trap_init(void); 141void per_cpu_trap_init(void);
144void default_idle(void); 142void default_idle(void);
145void cpu_idle_wait(void); 143void cpu_idle_wait(void);
diff --git a/arch/sh/include/asm/system_32.h b/arch/sh/include/asm/system_32.h
index c941b2739405..a4ad1cd9bc4d 100644
--- a/arch/sh/include/asm/system_32.h
+++ b/arch/sh/include/asm/system_32.h
@@ -145,42 +145,6 @@ do { \
145 __restore_dsp(prev); \ 145 __restore_dsp(prev); \
146} while (0) 146} while (0)
147 147
148/*
149 * Jump to uncached area.
150 * When handling TLB or caches, we need to do it from an uncached area.
151 */
152#define jump_to_uncached() \
153do { \
154 unsigned long __dummy; \
155 \
156 __asm__ __volatile__( \
157 "mova 1f, %0\n\t" \
158 "add %1, %0\n\t" \
159 "jmp @%0\n\t" \
160 " nop\n\t" \
161 ".balign 4\n" \
162 "1:" \
163 : "=&z" (__dummy) \
164 : "r" (cached_to_uncached)); \
165} while (0)
166
167/*
168 * Back to cached area.
169 */
170#define back_to_cached() \
171do { \
172 unsigned long __dummy; \
173 ctrl_barrier(); \
174 __asm__ __volatile__( \
175 "mov.l 1f, %0\n\t" \
176 "jmp @%0\n\t" \
177 " nop\n\t" \
178 ".balign 4\n" \
179 "1: .long 2f\n" \
180 "2:" \
181 : "=&r" (__dummy)); \
182} while (0)
183
184#ifdef CONFIG_CPU_HAS_SR_RB 148#ifdef CONFIG_CPU_HAS_SR_RB
185#define lookup_exception_vector() \ 149#define lookup_exception_vector() \
186({ \ 150({ \
diff --git a/arch/sh/include/asm/system_64.h b/arch/sh/include/asm/system_64.h
index 36338646dfc8..8593bc8d1a4e 100644
--- a/arch/sh/include/asm/system_64.h
+++ b/arch/sh/include/asm/system_64.h
@@ -34,9 +34,6 @@ do { \
34 &next->thread); \ 34 &next->thread); \
35} while (0) 35} while (0)
36 36
37#define jump_to_uncached() do { } while (0)
38#define back_to_cached() do { } while (0)
39
40#define __icbi(addr) __asm__ __volatile__ ( "icbi %0, 0\n\t" : : "r" (addr)) 37#define __icbi(addr) __asm__ __volatile__ ( "icbi %0, 0\n\t" : : "r" (addr))
41#define __ocbp(addr) __asm__ __volatile__ ( "ocbp %0, 0\n\t" : : "r" (addr)) 38#define __ocbp(addr) __asm__ __volatile__ ( "ocbp %0, 0\n\t" : : "r" (addr))
42#define __ocbi(addr) __asm__ __volatile__ ( "ocbi %0, 0\n\t" : : "r" (addr)) 39#define __ocbi(addr) __asm__ __volatile__ ( "ocbi %0, 0\n\t" : : "r" (addr))
diff --git a/arch/sh/include/asm/uncached.h b/arch/sh/include/asm/uncached.h
index e3419f96626a..6f8816b79cf1 100644
--- a/arch/sh/include/asm/uncached.h
+++ b/arch/sh/include/asm/uncached.h
@@ -4,15 +4,55 @@
4#include <linux/bug.h> 4#include <linux/bug.h>
5 5
6#ifdef CONFIG_UNCACHED_MAPPING 6#ifdef CONFIG_UNCACHED_MAPPING
7extern unsigned long cached_to_uncached;
8extern unsigned long uncached_size;
7extern unsigned long uncached_start, uncached_end; 9extern unsigned long uncached_start, uncached_end;
8 10
9extern int virt_addr_uncached(unsigned long kaddr); 11extern int virt_addr_uncached(unsigned long kaddr);
10extern void uncached_init(void); 12extern void uncached_init(void);
11extern void uncached_resize(unsigned long size); 13extern void uncached_resize(unsigned long size);
14
15/*
16 * Jump to uncached area.
17 * When handling TLB or caches, we need to do it from an uncached area.
18 */
19#define jump_to_uncached() \
20do { \
21 unsigned long __dummy; \
22 \
23 __asm__ __volatile__( \
24 "mova 1f, %0\n\t" \
25 "add %1, %0\n\t" \
26 "jmp @%0\n\t" \
27 " nop\n\t" \
28 ".balign 4\n" \
29 "1:" \
30 : "=&z" (__dummy) \
31 : "r" (cached_to_uncached)); \
32} while (0)
33
34/*
35 * Back to cached area.
36 */
37#define back_to_cached() \
38do { \
39 unsigned long __dummy; \
40 ctrl_barrier(); \
41 __asm__ __volatile__( \
42 "mov.l 1f, %0\n\t" \
43 "jmp @%0\n\t" \
44 " nop\n\t" \
45 ".balign 4\n" \
46 "1: .long 2f\n" \
47 "2:" \
48 : "=&r" (__dummy)); \
49} while (0)
12#else 50#else
13#define virt_addr_uncached(kaddr) (0) 51#define virt_addr_uncached(kaddr) (0)
14#define uncached_init() do { } while (0) 52#define uncached_init() do { } while (0)
15#define uncached_resize(size) BUG() 53#define uncached_resize(size) BUG()
54#define jump_to_uncached() do { } while (0)
55#define back_to_cached() do { } while (0)
16#endif 56#endif
17 57
18#endif /* __ASM_SH_UNCACHED_H */ 58#endif /* __ASM_SH_UNCACHED_H */
diff --git a/arch/sh/include/asm/unistd_32.h b/arch/sh/include/asm/unistd_32.h
index 903cd618eb74..d6741fca89a4 100644
--- a/arch/sh/include/asm/unistd_32.h
+++ b/arch/sh/include/asm/unistd_32.h
@@ -368,8 +368,9 @@
368#define __NR_sendmsg 355 368#define __NR_sendmsg 355
369#define __NR_recvmsg 356 369#define __NR_recvmsg 356
370#define __NR_recvmmsg 357 370#define __NR_recvmmsg 357
371#define __NR_accept4 358
371 372
372#define NR_syscalls 358 373#define NR_syscalls 359
373 374
374#ifdef __KERNEL__ 375#ifdef __KERNEL__
375 376
diff --git a/arch/sh/include/cpu-sh4/cpu/sh7724.h b/arch/sh/include/cpu-sh4/cpu/sh7724.h
index 4c27b68789b3..7eb435999426 100644
--- a/arch/sh/include/cpu-sh4/cpu/sh7724.h
+++ b/arch/sh/include/cpu-sh4/cpu/sh7724.h
@@ -303,4 +303,7 @@ enum {
303 SHDMA_SLAVE_SDHI1_RX, 303 SHDMA_SLAVE_SDHI1_RX,
304}; 304};
305 305
306extern struct clk sh7724_fsimcka_clk;
307extern struct clk sh7724_fsimckb_clk;
308
306#endif /* __ASM_SH7724_H__ */ 309#endif /* __ASM_SH7724_H__ */
diff --git a/arch/sh/include/mach-common/mach/edosk7705.h b/arch/sh/include/mach-common/mach/edosk7705.h
deleted file mode 100644
index efc43b323466..000000000000
--- a/arch/sh/include/mach-common/mach/edosk7705.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef __ASM_SH_EDOSK7705_H
2#define __ASM_SH_EDOSK7705_H
3
4#define __IO_PREFIX sh_edosk7705
5#include <asm/io_generic.h>
6
7#endif /* __ASM_SH_EDOSK7705_H */
diff --git a/arch/sh/include/mach-common/mach/microdev.h b/arch/sh/include/mach-common/mach/microdev.h
index 1aed15856e11..dcb05fa8c164 100644
--- a/arch/sh/include/mach-common/mach/microdev.h
+++ b/arch/sh/include/mach-common/mach/microdev.h
@@ -68,13 +68,4 @@ extern void microdev_print_fpga_intc_status(void);
68#define __IO_PREFIX microdev 68#define __IO_PREFIX microdev
69#include <asm/io_generic.h> 69#include <asm/io_generic.h>
70 70
71#if defined(CONFIG_PCI)
72unsigned char microdev_pci_inb(unsigned long port);
73unsigned short microdev_pci_inw(unsigned long port);
74unsigned long microdev_pci_inl(unsigned long port);
75void microdev_pci_outb(unsigned char data, unsigned long port);
76void microdev_pci_outw(unsigned short data, unsigned long port);
77void microdev_pci_outl(unsigned long data, unsigned long port);
78#endif
79
80#endif /* __ASM_SH_MICRODEV_H */ 71#endif /* __ASM_SH_MICRODEV_H */
diff --git a/arch/sh/include/mach-common/mach/snapgear.h b/arch/sh/include/mach-common/mach/secureedge5410.h
index 042d95f51c4d..3653b9a4bacc 100644
--- a/arch/sh/include/mach-common/mach/snapgear.h
+++ b/arch/sh/include/mach-common/mach/secureedge5410.h
@@ -12,30 +12,9 @@
12#ifndef _ASM_SH_IO_SNAPGEAR_H 12#ifndef _ASM_SH_IO_SNAPGEAR_H
13#define _ASM_SH_IO_SNAPGEAR_H 13#define _ASM_SH_IO_SNAPGEAR_H
14 14
15#if defined(CONFIG_CPU_SH4)
16/*
17 * The external interrupt lines, these take up ints 0 - 15 inclusive
18 * depending on the priority for the interrupt. In fact the priority
19 * is the interrupt :-)
20 */
21
22#define IRL0_IRQ 2
23#define IRL0_PRIORITY 13
24
25#define IRL1_IRQ 5
26#define IRL1_PRIORITY 10
27
28#define IRL2_IRQ 8
29#define IRL2_PRIORITY 7
30
31#define IRL3_IRQ 11
32#define IRL3_PRIORITY 4
33#endif
34
35#define __IO_PREFIX snapgear 15#define __IO_PREFIX snapgear
36#include <asm/io_generic.h> 16#include <asm/io_generic.h>
37 17
38#ifdef CONFIG_SH_SECUREEDGE5410
39/* 18/*
40 * We need to remember what was written to the ioport as some bits 19 * We need to remember what was written to the ioport as some bits
41 * are shared with other functions and you cannot read back what was 20 * are shared with other functions and you cannot read back what was
@@ -66,6 +45,5 @@ extern unsigned short secureedge5410_ioport;
66 ((secureedge5410_ioport & ~(mask)) | ((val) & (mask))))) 45 ((secureedge5410_ioport & ~(mask)) | ((val) & (mask)))))
67#define SECUREEDGE_READ_IOPORT() \ 46#define SECUREEDGE_READ_IOPORT() \
68 ((*SECUREEDGE_IOPORT_ADDR&0x0817) | (secureedge5410_ioport&~0x0817)) 47 ((*SECUREEDGE_IOPORT_ADDR&0x0817) | (secureedge5410_ioport&~0x0817))
69#endif
70 48
71#endif /* _ASM_SH_IO_SNAPGEAR_H */ 49#endif /* _ASM_SH_IO_SNAPGEAR_H */
diff --git a/arch/sh/include/mach-common/mach/systemh7751.h b/arch/sh/include/mach-common/mach/systemh7751.h
deleted file mode 100644
index 4161122c84ef..000000000000
--- a/arch/sh/include/mach-common/mach/systemh7751.h
+++ /dev/null
@@ -1,71 +0,0 @@
1#ifndef __ASM_SH_SYSTEMH_7751SYSTEMH_H
2#define __ASM_SH_SYSTEMH_7751SYSTEMH_H
3
4/*
5 * linux/include/asm-sh/systemh/7751systemh.h
6 *
7 * Copyright (C) 2000 Kazumoto Kojima
8 *
9 * Hitachi SystemH support
10
11 * Modified for 7751 SystemH by
12 * Jonathan Short, 2002.
13 */
14
15/* Box specific addresses. */
16
17#define PA_ROM 0x00000000 /* EPROM */
18#define PA_ROM_SIZE 0x00400000 /* EPROM size 4M byte */
19#define PA_FROM 0x01000000 /* EPROM */
20#define PA_FROM_SIZE 0x00400000 /* EPROM size 4M byte */
21#define PA_EXT1 0x04000000
22#define PA_EXT1_SIZE 0x04000000
23#define PA_EXT2 0x08000000
24#define PA_EXT2_SIZE 0x04000000
25#define PA_SDRAM 0x0c000000
26#define PA_SDRAM_SIZE 0x04000000
27
28#define PA_EXT4 0x12000000
29#define PA_EXT4_SIZE 0x02000000
30#define PA_EXT5 0x14000000
31#define PA_EXT5_SIZE 0x04000000
32#define PA_PCIC 0x18000000 /* MR-SHPC-01 PCMCIA */
33
34#define PA_DIPSW0 0xb9000000 /* Dip switch 5,6 */
35#define PA_DIPSW1 0xb9000002 /* Dip switch 7,8 */
36#define PA_LED 0xba000000 /* LED */
37#define PA_BCR 0xbb000000 /* FPGA on the MS7751SE01 */
38
39#define PA_MRSHPC 0xb83fffe0 /* MR-SHPC-01 PCMCIA controller */
40#define PA_MRSHPC_MW1 0xb8400000 /* MR-SHPC-01 memory window base */
41#define PA_MRSHPC_MW2 0xb8500000 /* MR-SHPC-01 attribute window base */
42#define PA_MRSHPC_IO 0xb8600000 /* MR-SHPC-01 I/O window base */
43#define MRSHPC_MODE (PA_MRSHPC + 4)
44#define MRSHPC_OPTION (PA_MRSHPC + 6)
45#define MRSHPC_CSR (PA_MRSHPC + 8)
46#define MRSHPC_ISR (PA_MRSHPC + 10)
47#define MRSHPC_ICR (PA_MRSHPC + 12)
48#define MRSHPC_CPWCR (PA_MRSHPC + 14)
49#define MRSHPC_MW0CR1 (PA_MRSHPC + 16)
50#define MRSHPC_MW1CR1 (PA_MRSHPC + 18)
51#define MRSHPC_IOWCR1 (PA_MRSHPC + 20)
52#define MRSHPC_MW0CR2 (PA_MRSHPC + 22)
53#define MRSHPC_MW1CR2 (PA_MRSHPC + 24)
54#define MRSHPC_IOWCR2 (PA_MRSHPC + 26)
55#define MRSHPC_CDCR (PA_MRSHPC + 28)
56#define MRSHPC_PCIC_INFO (PA_MRSHPC + 30)
57
58#define BCR_ILCRA (PA_BCR + 0)
59#define BCR_ILCRB (PA_BCR + 2)
60#define BCR_ILCRC (PA_BCR + 4)
61#define BCR_ILCRD (PA_BCR + 6)
62#define BCR_ILCRE (PA_BCR + 8)
63#define BCR_ILCRF (PA_BCR + 10)
64#define BCR_ILCRG (PA_BCR + 12)
65
66#define IRQ_79C973 13
67
68#define __IO_PREFIX sh7751systemh
69#include <asm/io_generic.h>
70
71#endif /* __ASM_SH_SYSTEMH_7751SYSTEMH_H */
diff --git a/arch/sh/kernel/cpu/sh4/clock-sh4-202.c b/arch/sh/kernel/cpu/sh4/clock-sh4-202.c
index 4eabc68cd753..b601fa3978d1 100644
--- a/arch/sh/kernel/cpu/sh4/clock-sh4-202.c
+++ b/arch/sh/kernel/cpu/sh4/clock-sh4-202.c
@@ -110,7 +110,7 @@ static int shoc_clk_verify_rate(struct clk *clk, unsigned long rate)
110 return 0; 110 return 0;
111} 111}
112 112
113static int shoc_clk_set_rate(struct clk *clk, unsigned long rate, int algo_id) 113static int shoc_clk_set_rate(struct clk *clk, unsigned long rate)
114{ 114{
115 unsigned long frqcr3; 115 unsigned long frqcr3;
116 unsigned int tmp; 116 unsigned int tmp;
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7724.c b/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
index 2d9700c6b53a..271c0b325a9a 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
@@ -48,7 +48,7 @@ static struct clk r_clk = {
48 * Default rate for the root input clock, reset this with clk_set_rate() 48 * Default rate for the root input clock, reset this with clk_set_rate()
49 * from the platform code. 49 * from the platform code.
50 */ 50 */
51struct clk extal_clk = { 51static struct clk extal_clk = {
52 .rate = 33333333, 52 .rate = 33333333,
53}; 53};
54 54
@@ -111,12 +111,21 @@ static struct clk div3_clk = {
111 .parent = &pll_clk, 111 .parent = &pll_clk,
112}; 112};
113 113
114struct clk *main_clks[] = { 114/* External input clock (pin name: FSIMCKA/FSIMCKB ) */
115struct clk sh7724_fsimcka_clk = {
116};
117
118struct clk sh7724_fsimckb_clk = {
119};
120
121static struct clk *main_clks[] = {
115 &r_clk, 122 &r_clk,
116 &extal_clk, 123 &extal_clk,
117 &fll_clk, 124 &fll_clk,
118 &pll_clk, 125 &pll_clk,
119 &div3_clk, 126 &div3_clk,
127 &sh7724_fsimcka_clk,
128 &sh7724_fsimckb_clk,
120}; 129};
121 130
122static void div4_kick(struct clk *clk) 131static void div4_kick(struct clk *clk)
@@ -154,16 +163,38 @@ struct clk div4_clks[DIV4_NR] = {
154 [DIV4_M1] = DIV4(FRQCRB, 4, 0x2f7c, CLK_ENABLE_ON_INIT), 163 [DIV4_M1] = DIV4(FRQCRB, 4, 0x2f7c, CLK_ENABLE_ON_INIT),
155}; 164};
156 165
157enum { DIV6_V, DIV6_FA, DIV6_FB, DIV6_I, DIV6_S, DIV6_NR }; 166enum { DIV6_V, DIV6_I, DIV6_S, DIV6_NR };
158 167
159struct clk div6_clks[DIV6_NR] = { 168static struct clk div6_clks[DIV6_NR] = {
160 [DIV6_V] = SH_CLK_DIV6(&div3_clk, VCLKCR, 0), 169 [DIV6_V] = SH_CLK_DIV6(&div3_clk, VCLKCR, 0),
161 [DIV6_FA] = SH_CLK_DIV6(&div3_clk, FCLKACR, 0),
162 [DIV6_FB] = SH_CLK_DIV6(&div3_clk, FCLKBCR, 0),
163 [DIV6_I] = SH_CLK_DIV6(&div3_clk, IRDACLKCR, 0), 170 [DIV6_I] = SH_CLK_DIV6(&div3_clk, IRDACLKCR, 0),
164 [DIV6_S] = SH_CLK_DIV6(&div3_clk, SPUCLKCR, CLK_ENABLE_ON_INIT), 171 [DIV6_S] = SH_CLK_DIV6(&div3_clk, SPUCLKCR, CLK_ENABLE_ON_INIT),
165}; 172};
166 173
174enum { DIV6_FA, DIV6_FB, DIV6_REPARENT_NR };
175
176/* Indices are important - they are the actual src selecting values */
177static struct clk *fclkacr_parent[] = {
178 [0] = &div3_clk,
179 [1] = NULL,
180 [2] = &sh7724_fsimcka_clk,
181 [3] = NULL,
182};
183
184static struct clk *fclkbcr_parent[] = {
185 [0] = &div3_clk,
186 [1] = NULL,
187 [2] = &sh7724_fsimckb_clk,
188 [3] = NULL,
189};
190
191static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = {
192 [DIV6_FA] = SH_CLK_DIV6_EXT(&div3_clk, FCLKACR, 0,
193 fclkacr_parent, ARRAY_SIZE(fclkacr_parent), 6, 2),
194 [DIV6_FB] = SH_CLK_DIV6_EXT(&div3_clk, FCLKBCR, 0,
195 fclkbcr_parent, ARRAY_SIZE(fclkbcr_parent), 6, 2),
196};
197
167static struct clk mstp_clks[HWBLK_NR] = { 198static struct clk mstp_clks[HWBLK_NR] = {
168 SH_HWBLK_CLK(HWBLK_TLB, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT), 199 SH_HWBLK_CLK(HWBLK_TLB, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
169 SH_HWBLK_CLK(HWBLK_IC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT), 200 SH_HWBLK_CLK(HWBLK_IC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
@@ -240,8 +271,8 @@ static struct clk_lookup lookups[] = {
240 271
241 /* DIV6 clocks */ 272 /* DIV6 clocks */
242 CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]), 273 CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
243 CLKDEV_CON_ID("fsia_clk", &div6_clks[DIV6_FA]), 274 CLKDEV_CON_ID("fsia_clk", &div6_reparent_clks[DIV6_FA]),
244 CLKDEV_CON_ID("fsib_clk", &div6_clks[DIV6_FB]), 275 CLKDEV_CON_ID("fsib_clk", &div6_reparent_clks[DIV6_FB]),
245 CLKDEV_CON_ID("irda_clk", &div6_clks[DIV6_I]), 276 CLKDEV_CON_ID("irda_clk", &div6_clks[DIV6_I]),
246 CLKDEV_CON_ID("spu_clk", &div6_clks[DIV6_S]), 277 CLKDEV_CON_ID("spu_clk", &div6_clks[DIV6_S]),
247 278
@@ -376,6 +407,9 @@ int __init arch_clk_init(void)
376 ret = sh_clk_div6_register(div6_clks, DIV6_NR); 407 ret = sh_clk_div6_register(div6_clks, DIV6_NR);
377 408
378 if (!ret) 409 if (!ret)
410 ret = sh_clk_div6_reparent_register(div6_reparent_clks, DIV6_REPARENT_NR);
411
412 if (!ret)
379 ret = sh_hwblk_clk_register(mstp_clks, HWBLK_NR); 413 ret = sh_hwblk_clk_register(mstp_clks, HWBLK_NR);
380 414
381 return ret; 415 return ret;
diff --git a/arch/sh/kernel/sys_sh.c b/arch/sh/kernel/sys_sh.c
index 81f58371613d..8c6a350df751 100644
--- a/arch/sh/kernel/sys_sh.c
+++ b/arch/sh/kernel/sys_sh.c
@@ -88,7 +88,7 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, int op)
88 } 88 }
89 89
90 if (op & CACHEFLUSH_I) 90 if (op & CACHEFLUSH_I)
91 flush_cache_all(); 91 flush_icache_range(addr, addr+len);
92 92
93 up_read(&current->mm->mmap_sem); 93 up_read(&current->mm->mmap_sem);
94 return 0; 94 return 0;
diff --git a/arch/sh/kernel/syscalls_32.S b/arch/sh/kernel/syscalls_32.S
index e872e81add8a..6fc347ebe59d 100644
--- a/arch/sh/kernel/syscalls_32.S
+++ b/arch/sh/kernel/syscalls_32.S
@@ -375,3 +375,4 @@ ENTRY(sys_call_table)
375 .long sys_sendmsg /* 355 */ 375 .long sys_sendmsg /* 355 */
376 .long sys_recvmsg 376 .long sys_recvmsg
377 .long sys_recvmmsg 377 .long sys_recvmmsg
378 .long sys_accept4
diff --git a/arch/sh/kernel/vsyscall/vsyscall-trapa.S b/arch/sh/kernel/vsyscall/vsyscall-trapa.S
index 3b6eb34c43fa..3e70f851cdc6 100644
--- a/arch/sh/kernel/vsyscall/vsyscall-trapa.S
+++ b/arch/sh/kernel/vsyscall/vsyscall-trapa.S
@@ -8,9 +8,9 @@ __kernel_vsyscall:
8 * fill out .eh_frame -- PFM. */ 8 * fill out .eh_frame -- PFM. */
9.LEND_vsyscall: 9.LEND_vsyscall:
10 .size __kernel_vsyscall,.-.LSTART_vsyscall 10 .size __kernel_vsyscall,.-.LSTART_vsyscall
11 .previous
12 11
13 .section .eh_frame,"a",@progbits 12 .section .eh_frame,"a",@progbits
13 .previous
14.LCIE: 14.LCIE:
15 .ualong .LCIE_end - .LCIE_start 15 .ualong .LCIE_end - .LCIE_start
16.LCIE_start: 16.LCIE_start:
diff --git a/arch/sh/mm/Kconfig b/arch/sh/mm/Kconfig
index 09370392aff1..c3e61b366493 100644
--- a/arch/sh/mm/Kconfig
+++ b/arch/sh/mm/Kconfig
@@ -79,7 +79,7 @@ config 29BIT
79 79
80config 32BIT 80config 32BIT
81 bool 81 bool
82 default y if CPU_SH5 82 default y if CPU_SH5 || !MMU
83 83
84config PMB 84config PMB
85 bool "Support 32-bit physical addressing through PMB" 85 bool "Support 32-bit physical addressing through PMB"
diff --git a/arch/sh/mm/cache-sh4.c b/arch/sh/mm/cache-sh4.c
index 2cfae81914aa..92eb98633ab0 100644
--- a/arch/sh/mm/cache-sh4.c
+++ b/arch/sh/mm/cache-sh4.c
@@ -114,7 +114,7 @@ static void sh4_flush_dcache_page(void *arg)
114 struct address_space *mapping = page_mapping(page); 114 struct address_space *mapping = page_mapping(page);
115 115
116 if (mapping && !mapping_mapped(mapping)) 116 if (mapping && !mapping_mapped(mapping))
117 set_bit(PG_dcache_dirty, &page->flags); 117 clear_bit(PG_dcache_clean, &page->flags);
118 else 118 else
119#endif 119#endif
120 flush_cache_one(CACHE_OC_ADDRESS_ARRAY | 120 flush_cache_one(CACHE_OC_ADDRESS_ARRAY |
@@ -239,7 +239,7 @@ static void sh4_flush_cache_page(void *args)
239 * another ASID than the current one. 239 * another ASID than the current one.
240 */ 240 */
241 map_coherent = (current_cpu_data.dcache.n_aliases && 241 map_coherent = (current_cpu_data.dcache.n_aliases &&
242 !test_bit(PG_dcache_dirty, &page->flags) && 242 test_bit(PG_dcache_clean, &page->flags) &&
243 page_mapped(page)); 243 page_mapped(page));
244 if (map_coherent) 244 if (map_coherent)
245 vaddr = kmap_coherent(page, address); 245 vaddr = kmap_coherent(page, address);
diff --git a/arch/sh/mm/cache-sh7705.c b/arch/sh/mm/cache-sh7705.c
index f498da1cce7a..7729cca727eb 100644
--- a/arch/sh/mm/cache-sh7705.c
+++ b/arch/sh/mm/cache-sh7705.c
@@ -139,7 +139,7 @@ static void sh7705_flush_dcache_page(void *arg)
139 struct address_space *mapping = page_mapping(page); 139 struct address_space *mapping = page_mapping(page);
140 140
141 if (mapping && !mapping_mapped(mapping)) 141 if (mapping && !mapping_mapped(mapping))
142 set_bit(PG_dcache_dirty, &page->flags); 142 clear_bit(PG_dcache_clean, &page->flags);
143 else 143 else
144 __flush_dcache_page(__pa(page_address(page))); 144 __flush_dcache_page(__pa(page_address(page)));
145} 145}
diff --git a/arch/sh/mm/cache.c b/arch/sh/mm/cache.c
index ba401d137bb9..88d3dc3d30d5 100644
--- a/arch/sh/mm/cache.c
+++ b/arch/sh/mm/cache.c
@@ -60,14 +60,14 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
60 unsigned long len) 60 unsigned long len)
61{ 61{
62 if (boot_cpu_data.dcache.n_aliases && page_mapped(page) && 62 if (boot_cpu_data.dcache.n_aliases && page_mapped(page) &&
63 !test_bit(PG_dcache_dirty, &page->flags)) { 63 test_bit(PG_dcache_clean, &page->flags)) {
64 void *vto = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK); 64 void *vto = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK);
65 memcpy(vto, src, len); 65 memcpy(vto, src, len);
66 kunmap_coherent(vto); 66 kunmap_coherent(vto);
67 } else { 67 } else {
68 memcpy(dst, src, len); 68 memcpy(dst, src, len);
69 if (boot_cpu_data.dcache.n_aliases) 69 if (boot_cpu_data.dcache.n_aliases)
70 set_bit(PG_dcache_dirty, &page->flags); 70 clear_bit(PG_dcache_clean, &page->flags);
71 } 71 }
72 72
73 if (vma->vm_flags & VM_EXEC) 73 if (vma->vm_flags & VM_EXEC)
@@ -79,14 +79,14 @@ void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
79 unsigned long len) 79 unsigned long len)
80{ 80{
81 if (boot_cpu_data.dcache.n_aliases && page_mapped(page) && 81 if (boot_cpu_data.dcache.n_aliases && page_mapped(page) &&
82 !test_bit(PG_dcache_dirty, &page->flags)) { 82 test_bit(PG_dcache_clean, &page->flags)) {
83 void *vfrom = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK); 83 void *vfrom = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK);
84 memcpy(dst, vfrom, len); 84 memcpy(dst, vfrom, len);
85 kunmap_coherent(vfrom); 85 kunmap_coherent(vfrom);
86 } else { 86 } else {
87 memcpy(dst, src, len); 87 memcpy(dst, src, len);
88 if (boot_cpu_data.dcache.n_aliases) 88 if (boot_cpu_data.dcache.n_aliases)
89 set_bit(PG_dcache_dirty, &page->flags); 89 clear_bit(PG_dcache_clean, &page->flags);
90 } 90 }
91} 91}
92 92
@@ -98,7 +98,7 @@ void copy_user_highpage(struct page *to, struct page *from,
98 vto = kmap_atomic(to, KM_USER1); 98 vto = kmap_atomic(to, KM_USER1);
99 99
100 if (boot_cpu_data.dcache.n_aliases && page_mapped(from) && 100 if (boot_cpu_data.dcache.n_aliases && page_mapped(from) &&
101 !test_bit(PG_dcache_dirty, &from->flags)) { 101 test_bit(PG_dcache_clean, &from->flags)) {
102 vfrom = kmap_coherent(from, vaddr); 102 vfrom = kmap_coherent(from, vaddr);
103 copy_page(vto, vfrom); 103 copy_page(vto, vfrom);
104 kunmap_coherent(vfrom); 104 kunmap_coherent(vfrom);
@@ -141,7 +141,7 @@ void __update_cache(struct vm_area_struct *vma,
141 141
142 page = pfn_to_page(pfn); 142 page = pfn_to_page(pfn);
143 if (pfn_valid(pfn)) { 143 if (pfn_valid(pfn)) {
144 int dirty = test_and_clear_bit(PG_dcache_dirty, &page->flags); 144 int dirty = !test_and_set_bit(PG_dcache_clean, &page->flags);
145 if (dirty) 145 if (dirty)
146 __flush_purge_region(page_address(page), PAGE_SIZE); 146 __flush_purge_region(page_address(page), PAGE_SIZE);
147 } 147 }
@@ -153,7 +153,7 @@ void __flush_anon_page(struct page *page, unsigned long vmaddr)
153 153
154 if (pages_do_alias(addr, vmaddr)) { 154 if (pages_do_alias(addr, vmaddr)) {
155 if (boot_cpu_data.dcache.n_aliases && page_mapped(page) && 155 if (boot_cpu_data.dcache.n_aliases && page_mapped(page) &&
156 !test_bit(PG_dcache_dirty, &page->flags)) { 156 test_bit(PG_dcache_clean, &page->flags)) {
157 void *kaddr; 157 void *kaddr;
158 158
159 kaddr = kmap_coherent(page, vmaddr); 159 kaddr = kmap_coherent(page, vmaddr);
diff --git a/arch/sh/mm/consistent.c b/arch/sh/mm/consistent.c
index 038793286990..40733a952402 100644
--- a/arch/sh/mm/consistent.c
+++ b/arch/sh/mm/consistent.c
@@ -79,21 +79,20 @@ void dma_generic_free_coherent(struct device *dev, size_t size,
79void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 79void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
80 enum dma_data_direction direction) 80 enum dma_data_direction direction)
81{ 81{
82#if defined(CONFIG_CPU_SH5) || defined(CONFIG_PMB) 82 void *addr;
83 void *p1addr = vaddr; 83
84#else 84 addr = __in_29bit_mode() ?
85 void *p1addr = (void*) P1SEGADDR((unsigned long)vaddr); 85 (void *)P1SEGADDR((unsigned long)vaddr) : vaddr;
86#endif
87 86
88 switch (direction) { 87 switch (direction) {
89 case DMA_FROM_DEVICE: /* invalidate only */ 88 case DMA_FROM_DEVICE: /* invalidate only */
90 __flush_invalidate_region(p1addr, size); 89 __flush_invalidate_region(addr, size);
91 break; 90 break;
92 case DMA_TO_DEVICE: /* writeback only */ 91 case DMA_TO_DEVICE: /* writeback only */
93 __flush_wback_region(p1addr, size); 92 __flush_wback_region(addr, size);
94 break; 93 break;
95 case DMA_BIDIRECTIONAL: /* writeback and invalidate */ 94 case DMA_BIDIRECTIONAL: /* writeback and invalidate */
96 __flush_purge_region(p1addr, size); 95 __flush_purge_region(addr, size);
97 break; 96 break;
98 default: 97 default:
99 BUG(); 98 BUG();
diff --git a/arch/sh/mm/kmap.c b/arch/sh/mm/kmap.c
index 15d74ea42094..ec29e14ec5a8 100644
--- a/arch/sh/mm/kmap.c
+++ b/arch/sh/mm/kmap.c
@@ -34,7 +34,7 @@ void *kmap_coherent(struct page *page, unsigned long addr)
34 enum fixed_addresses idx; 34 enum fixed_addresses idx;
35 unsigned long vaddr; 35 unsigned long vaddr;
36 36
37 BUG_ON(test_bit(PG_dcache_dirty, &page->flags)); 37 BUG_ON(!test_bit(PG_dcache_clean, &page->flags));
38 38
39 pagefault_disable(); 39 pagefault_disable();
40 40
diff --git a/arch/sh/mm/uncached.c b/arch/sh/mm/uncached.c
index 8a4eca551fc0..a7767da815e9 100644
--- a/arch/sh/mm/uncached.c
+++ b/arch/sh/mm/uncached.c
@@ -28,7 +28,7 @@ EXPORT_SYMBOL(virt_addr_uncached);
28 28
29void __init uncached_init(void) 29void __init uncached_init(void)
30{ 30{
31#ifdef CONFIG_29BIT 31#if defined(CONFIG_29BIT) || !defined(CONFIG_MMU)
32 uncached_start = P2SEG; 32 uncached_start = P2SEG;
33#else 33#else
34 uncached_start = memory_end; 34 uncached_start = memory_end;
diff --git a/arch/sh/tools/mach-types b/arch/sh/tools/mach-types
index 9f56eb978024..0e68465e7b50 100644
--- a/arch/sh/tools/mach-types
+++ b/arch/sh/tools/mach-types
@@ -26,7 +26,6 @@ HD64461 HD64461
267724SE SH_7724_SOLUTION_ENGINE 267724SE SH_7724_SOLUTION_ENGINE
277751SE SH_7751_SOLUTION_ENGINE 277751SE SH_7751_SOLUTION_ENGINE
287780SE SH_7780_SOLUTION_ENGINE 287780SE SH_7780_SOLUTION_ENGINE
297751SYSTEMH SH_7751_SYSTEMH
30HP6XX SH_HP6XX 29HP6XX SH_HP6XX
31DREAMCAST SH_DREAMCAST 30DREAMCAST SH_DREAMCAST
32SNAPGEAR SH_SECUREEDGE5410 31SNAPGEAR SH_SECUREEDGE5410
diff --git a/arch/sparc/include/asm/openprom.h b/arch/sparc/include/asm/openprom.h
index 81cd43432dc0..47eaafad15ce 100644
--- a/arch/sparc/include/asm/openprom.h
+++ b/arch/sparc/include/asm/openprom.h
@@ -39,7 +39,7 @@ struct linux_dev_v2_funcs {
39 int (*v2_dev_open)(char *devpath); 39 int (*v2_dev_open)(char *devpath);
40 void (*v2_dev_close)(int d); 40 void (*v2_dev_close)(int d);
41 int (*v2_dev_read)(int d, char *buf, int nbytes); 41 int (*v2_dev_read)(int d, char *buf, int nbytes);
42 int (*v2_dev_write)(int d, char *buf, int nbytes); 42 int (*v2_dev_write)(int d, const char *buf, int nbytes);
43 int (*v2_dev_seek)(int d, int hi, int lo); 43 int (*v2_dev_seek)(int d, int hi, int lo);
44 44
45 /* Never issued (multistage load support) */ 45 /* Never issued (multistage load support) */
diff --git a/arch/sparc/include/asm/oplib_32.h b/arch/sparc/include/asm/oplib_32.h
index 51296a6f5005..9e5c64084b86 100644
--- a/arch/sparc/include/asm/oplib_32.h
+++ b/arch/sparc/include/asm/oplib_32.h
@@ -60,25 +60,6 @@ extern char *prom_getbootargs(void);
60extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes); 60extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
61extern void prom_unmapio(char *virt_addr, unsigned int num_bytes); 61extern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
62 62
63/* Device operations. */
64
65/* Open the device described by the passed string. Note, that the format
66 * of the string is different on V0 vs. V2->higher proms. The caller must
67 * know what he/she is doing! Returns the device descriptor, an int.
68 */
69extern int prom_devopen(char *device_string);
70
71/* Close a previously opened device described by the passed integer
72 * descriptor.
73 */
74extern int prom_devclose(int device_handle);
75
76/* Do a seek operation on the device described by the passed integer
77 * descriptor.
78 */
79extern void prom_seek(int device_handle, unsigned int seek_hival,
80 unsigned int seek_lowval);
81
82/* Miscellaneous routines, don't really fit in any category per se. */ 63/* Miscellaneous routines, don't really fit in any category per se. */
83 64
84/* Reboot the machine with the command line passed. */ 65/* Reboot the machine with the command line passed. */
@@ -121,19 +102,8 @@ extern int prom_getrev(void);
121/* Get the prom firmware revision. */ 102/* Get the prom firmware revision. */
122extern int prom_getprev(void); 103extern int prom_getprev(void);
123 104
124/* Character operations to/from the console.... */ 105/* Write a buffer of characters to the console. */
125 106extern void prom_console_write_buf(const char *buf, int len);
126/* Non-blocking get character from console. */
127extern int prom_nbgetchar(void);
128
129/* Non-blocking put character to console. */
130extern int prom_nbputchar(char character);
131
132/* Blocking get character from console. */
133extern char prom_getchar(void);
134
135/* Blocking put character to console. */
136extern void prom_putchar(char character);
137 107
138/* Prom's internal routines, don't use in kernel/boot code. */ 108/* Prom's internal routines, don't use in kernel/boot code. */
139extern void prom_printf(const char *fmt, ...); 109extern void prom_printf(const char *fmt, ...);
@@ -238,7 +208,6 @@ extern int prom_node_has_property(phandle node, char *property);
238extern int prom_setprop(phandle node, const char *prop_name, char *prop_value, 208extern int prom_setprop(phandle node, const char *prop_name, char *prop_value,
239 int value_size); 209 int value_size);
240 210
241extern phandle prom_pathtoinode(char *path);
242extern phandle prom_inst2pkg(int); 211extern phandle prom_inst2pkg(int);
243 212
244/* Dorking with Bus ranges... */ 213/* Dorking with Bus ranges... */
diff --git a/arch/sparc/include/asm/oplib_64.h b/arch/sparc/include/asm/oplib_64.h
index c9cc078e3e31..8cd0df34e82b 100644
--- a/arch/sparc/include/asm/oplib_64.h
+++ b/arch/sparc/include/asm/oplib_64.h
@@ -67,27 +67,6 @@ extern void prom_init(void *cif_handler, void *cif_stack);
67/* Boot argument acquisition, returns the boot command line string. */ 67/* Boot argument acquisition, returns the boot command line string. */
68extern char *prom_getbootargs(void); 68extern char *prom_getbootargs(void);
69 69
70/* Device utilities. */
71
72/* Device operations. */
73
74/* Open the device described by the passed string. Note, that the format
75 * of the string is different on V0 vs. V2->higher proms. The caller must
76 * know what he/she is doing! Returns the device descriptor, an int.
77 */
78extern int prom_devopen(const char *device_string);
79
80/* Close a previously opened device described by the passed integer
81 * descriptor.
82 */
83extern int prom_devclose(int device_handle);
84
85/* Do a seek operation on the device described by the passed integer
86 * descriptor.
87 */
88extern void prom_seek(int device_handle, unsigned int seek_hival,
89 unsigned int seek_lowval);
90
91/* Miscellaneous routines, don't really fit in any category per se. */ 70/* Miscellaneous routines, don't really fit in any category per se. */
92 71
93/* Reboot the machine with the command line passed. */ 72/* Reboot the machine with the command line passed. */
@@ -109,33 +88,14 @@ extern void prom_halt(void) __attribute__ ((noreturn));
109/* Halt and power-off the machine. */ 88/* Halt and power-off the machine. */
110extern void prom_halt_power_off(void) __attribute__ ((noreturn)); 89extern void prom_halt_power_off(void) __attribute__ ((noreturn));
111 90
112/* Set the PROM 'sync' callback function to the passed function pointer.
113 * When the user gives the 'sync' command at the prom prompt while the
114 * kernel is still active, the prom will call this routine.
115 *
116 */
117typedef int (*callback_func_t)(long *cmd);
118extern void prom_setcallback(callback_func_t func_ptr);
119
120/* Acquire the IDPROM of the root node in the prom device tree. This 91/* Acquire the IDPROM of the root node in the prom device tree. This
121 * gets passed a buffer where you would like it stuffed. The return value 92 * gets passed a buffer where you would like it stuffed. The return value
122 * is the format type of this idprom or 0xff on error. 93 * is the format type of this idprom or 0xff on error.
123 */ 94 */
124extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size); 95extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
125 96
126/* Character operations to/from the console.... */ 97/* Write a buffer of characters to the console. */
127 98extern void prom_console_write_buf(const char *buf, int len);
128/* Non-blocking get character from console. */
129extern int prom_nbgetchar(void);
130
131/* Non-blocking put character to console. */
132extern int prom_nbputchar(char character);
133
134/* Blocking get character from console. */
135extern char prom_getchar(void);
136
137/* Blocking put character to console. */
138extern void prom_putchar(char character);
139 99
140/* Prom's internal routines, don't use in kernel/boot code. */ 100/* Prom's internal routines, don't use in kernel/boot code. */
141extern void prom_printf(const char *fmt, ...); 101extern void prom_printf(const char *fmt, ...);
@@ -279,9 +239,7 @@ extern phandle prom_finddevice(const char *name);
279extern int prom_setprop(phandle node, const char *prop_name, char *prop_value, 239extern int prom_setprop(phandle node, const char *prop_name, char *prop_value,
280 int value_size); 240 int value_size);
281 241
282extern phandle prom_pathtoinode(const char *path);
283extern phandle prom_inst2pkg(int); 242extern phandle prom_inst2pkg(int);
284extern int prom_service_exists(const char *service_name);
285extern void prom_sun4v_guest_soft_state(void); 243extern void prom_sun4v_guest_soft_state(void);
286 244
287extern int prom_ihandle2path(int handle, char *buffer, int bufsize); 245extern int prom_ihandle2path(int handle, char *buffer, int bufsize);
diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
index 2d51527d810f..f01c42661ee5 100644
--- a/arch/sparc/kernel/leon_kernel.c
+++ b/arch/sparc/kernel/leon_kernel.c
@@ -114,7 +114,7 @@ void __init leon_init_timers(irq_handler_t counter_fn)
114 if (leon3_gptimer_regs && leon3_irqctrl_regs) { 114 if (leon3_gptimer_regs && leon3_irqctrl_regs) {
115 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].val, 0); 115 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].val, 0);
116 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].rld, 116 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].rld,
117 (((1000000 / 100) - 1))); 117 (((1000000 / HZ) - 1)));
118 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, 0); 118 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, 0);
119 119
120#ifdef CONFIG_SMP 120#ifdef CONFIG_SMP
@@ -128,7 +128,7 @@ void __init leon_init_timers(irq_handler_t counter_fn)
128 } 128 }
129 129
130 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].val, 0); 130 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].val, 0);
131 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].rld, (((1000000/100) - 1))); 131 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].rld, (((1000000/HZ) - 1)));
132 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, 0); 132 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, 0);
133# endif 133# endif
134 134
diff --git a/arch/sparc/kernel/leon_smp.c b/arch/sparc/kernel/leon_smp.c
index 7524689b03d2..16582d85368a 100644
--- a/arch/sparc/kernel/leon_smp.c
+++ b/arch/sparc/kernel/leon_smp.c
@@ -12,7 +12,6 @@
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/threads.h> 13#include <linux/threads.h>
14#include <linux/smp.h> 14#include <linux/smp.h>
15#include <linux/smp_lock.h>
16#include <linux/interrupt.h> 15#include <linux/interrupt.h>
17#include <linux/kernel_stat.h> 16#include <linux/kernel_stat.h>
18#include <linux/init.h> 17#include <linux/init.h>
diff --git a/arch/sparc/kernel/sys_sparc32.c b/arch/sparc/kernel/sys_sparc32.c
index e6375a750d9a..6db18c6927fb 100644
--- a/arch/sparc/kernel/sys_sparc32.c
+++ b/arch/sparc/kernel/sys_sparc32.c
@@ -17,7 +17,6 @@
17#include <linux/resource.h> 17#include <linux/resource.h>
18#include <linux/times.h> 18#include <linux/times.h>
19#include <linux/smp.h> 19#include <linux/smp.h>
20#include <linux/smp_lock.h>
21#include <linux/sem.h> 20#include <linux/sem.h>
22#include <linux/msg.h> 21#include <linux/msg.h>
23#include <linux/shm.h> 22#include <linux/shm.h>
diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
index 675c9e11ada5..42b282fa6112 100644
--- a/arch/sparc/kernel/sys_sparc_32.c
+++ b/arch/sparc/kernel/sys_sparc_32.c
@@ -19,7 +19,6 @@
19#include <linux/mman.h> 19#include <linux/mman.h>
20#include <linux/utsname.h> 20#include <linux/utsname.h>
21#include <linux/smp.h> 21#include <linux/smp.h>
22#include <linux/smp_lock.h>
23#include <linux/ipc.h> 22#include <linux/ipc.h>
24 23
25#include <asm/uaccess.h> 24#include <asm/uaccess.h>
diff --git a/arch/sparc/kernel/unaligned_32.c b/arch/sparc/kernel/unaligned_32.c
index 12b9f352595f..4491f4cb2695 100644
--- a/arch/sparc/kernel/unaligned_32.c
+++ b/arch/sparc/kernel/unaligned_32.c
@@ -16,7 +16,6 @@
16#include <asm/system.h> 16#include <asm/system.h>
17#include <asm/uaccess.h> 17#include <asm/uaccess.h>
18#include <linux/smp.h> 18#include <linux/smp.h>
19#include <linux/smp_lock.h>
20#include <linux/perf_event.h> 19#include <linux/perf_event.h>
21 20
22enum direction { 21enum direction {
diff --git a/arch/sparc/kernel/windows.c b/arch/sparc/kernel/windows.c
index b351770cbdd6..3107381e576d 100644
--- a/arch/sparc/kernel/windows.c
+++ b/arch/sparc/kernel/windows.c
@@ -9,7 +9,6 @@
9#include <linux/string.h> 9#include <linux/string.h>
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/smp.h> 11#include <linux/smp.h>
12#include <linux/smp_lock.h>
13 12
14#include <asm/uaccess.h> 13#include <asm/uaccess.h>
15 14
diff --git a/arch/sparc/prom/Makefile b/arch/sparc/prom/Makefile
index 1b8c073adb44..816c0fa12dc0 100644
--- a/arch/sparc/prom/Makefile
+++ b/arch/sparc/prom/Makefile
@@ -6,7 +6,6 @@ ccflags := -Werror
6 6
7lib-y := bootstr_$(BITS).o 7lib-y := bootstr_$(BITS).o
8lib-$(CONFIG_SPARC32) += devmap.o 8lib-$(CONFIG_SPARC32) += devmap.o
9lib-y += devops_$(BITS).o
10lib-y += init_$(BITS).o 9lib-y += init_$(BITS).o
11lib-$(CONFIG_SPARC32) += memory.o 10lib-$(CONFIG_SPARC32) += memory.o
12lib-y += misc_$(BITS).o 11lib-y += misc_$(BITS).o
diff --git a/arch/sparc/prom/console_32.c b/arch/sparc/prom/console_32.c
index 5340264b78f5..48863108a44c 100644
--- a/arch/sparc/prom/console_32.c
+++ b/arch/sparc/prom/console_32.c
@@ -16,63 +16,26 @@
16 16
17extern void restore_current(void); 17extern void restore_current(void);
18 18
19/* Non blocking get character from console input device, returns -1
20 * if no input was taken. This can be used for polling.
21 */
22int
23prom_nbgetchar(void)
24{
25 static char inc;
26 int i = -1;
27 unsigned long flags;
28
29 spin_lock_irqsave(&prom_lock, flags);
30 switch(prom_vers) {
31 case PROM_V0:
32 i = (*(romvec->pv_nbgetchar))();
33 break;
34 case PROM_V2:
35 case PROM_V3:
36 if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1) {
37 i = inc;
38 } else {
39 i = -1;
40 }
41 break;
42 default:
43 i = -1;
44 break;
45 };
46 restore_current();
47 spin_unlock_irqrestore(&prom_lock, flags);
48 return i; /* Ugh, we could spin forever on unsupported proms ;( */
49}
50
51/* Non blocking put character to console device, returns -1 if 19/* Non blocking put character to console device, returns -1 if
52 * unsuccessful. 20 * unsuccessful.
53 */ 21 */
54int 22static int prom_nbputchar(const char *buf)
55prom_nbputchar(char c)
56{ 23{
57 static char outc;
58 unsigned long flags; 24 unsigned long flags;
59 int i = -1; 25 int i = -1;
60 26
61 spin_lock_irqsave(&prom_lock, flags); 27 spin_lock_irqsave(&prom_lock, flags);
62 switch(prom_vers) { 28 switch(prom_vers) {
63 case PROM_V0: 29 case PROM_V0:
64 i = (*(romvec->pv_nbputchar))(c); 30 i = (*(romvec->pv_nbputchar))(*buf);
65 break; 31 break;
66 case PROM_V2: 32 case PROM_V2:
67 case PROM_V3: 33 case PROM_V3:
68 outc = c; 34 if ((*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout,
69 if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1) 35 buf, 0x1) == 1)
70 i = 0; 36 i = 0;
71 else
72 i = -1;
73 break; 37 break;
74 default: 38 default:
75 i = -1;
76 break; 39 break;
77 }; 40 };
78 restore_current(); 41 restore_current();
@@ -80,18 +43,14 @@ prom_nbputchar(char c)
80 return i; /* Ugh, we could spin forever on unsupported proms ;( */ 43 return i; /* Ugh, we could spin forever on unsupported proms ;( */
81} 44}
82 45
83/* Blocking version of get character routine above. */ 46void prom_console_write_buf(const char *buf, int len)
84char
85prom_getchar(void)
86{ 47{
87 int character; 48 while (len) {
88 while((character = prom_nbgetchar()) == -1) ; 49 int n = prom_nbputchar(buf);
89 return (char) character; 50 if (n)
51 continue;
52 len--;
53 buf++;
54 }
90} 55}
91 56
92/* Blocking version of put character routine above. */
93void
94prom_putchar(char c)
95{
96 while(prom_nbputchar(c) == -1) ;
97}
diff --git a/arch/sparc/prom/console_64.c b/arch/sparc/prom/console_64.c
index 10322dc2f557..ed39e75828bd 100644
--- a/arch/sparc/prom/console_64.c
+++ b/arch/sparc/prom/console_64.c
@@ -15,85 +15,34 @@
15 15
16extern int prom_stdin, prom_stdout; 16extern int prom_stdin, prom_stdout;
17 17
18/* Non blocking get character from console input device, returns -1 18static int __prom_console_write_buf(const char *buf, int len)
19 * if no input was taken. This can be used for polling.
20 */
21inline int
22prom_nbgetchar(void)
23{
24 unsigned long args[7];
25 char inc;
26
27 args[0] = (unsigned long) "read";
28 args[1] = 3;
29 args[2] = 1;
30 args[3] = (unsigned int) prom_stdin;
31 args[4] = (unsigned long) &inc;
32 args[5] = 1;
33 args[6] = (unsigned long) -1;
34
35 p1275_cmd_direct(args);
36
37 if (args[6] == 1)
38 return inc;
39 return -1;
40}
41
42/* Non blocking put character to console device, returns -1 if
43 * unsuccessful.
44 */
45inline int
46prom_nbputchar(char c)
47{ 19{
48 unsigned long args[7]; 20 unsigned long args[7];
49 char outc; 21 int ret;
50
51 outc = c;
52 22
53 args[0] = (unsigned long) "write"; 23 args[0] = (unsigned long) "write";
54 args[1] = 3; 24 args[1] = 3;
55 args[2] = 1; 25 args[2] = 1;
56 args[3] = (unsigned int) prom_stdout; 26 args[3] = (unsigned int) prom_stdout;
57 args[4] = (unsigned long) &outc; 27 args[4] = (unsigned long) buf;
58 args[5] = 1; 28 args[5] = (unsigned int) len;
59 args[6] = (unsigned long) -1; 29 args[6] = (unsigned long) -1;
60 30
61 p1275_cmd_direct(args); 31 p1275_cmd_direct(args);
62 32
63 if (args[6] == 1) 33 ret = (int) args[6];
64 return 0; 34 if (ret < 0)
65 else
66 return -1; 35 return -1;
36 return ret;
67} 37}
68 38
69/* Blocking version of get character routine above. */ 39void prom_console_write_buf(const char *buf, int len)
70char
71prom_getchar(void)
72{
73 int character;
74 while((character = prom_nbgetchar()) == -1) ;
75 return (char) character;
76}
77
78/* Blocking version of put character routine above. */
79void
80prom_putchar(char c)
81{ 40{
82 prom_nbputchar(c); 41 while (len) {
83} 42 int n = __prom_console_write_buf(buf, len);
84 43 if (n < 0)
85void 44 continue;
86prom_puts(const char *s, int len) 45 len -= n;
87{ 46 buf += len;
88 unsigned long args[7]; 47 }
89
90 args[0] = (unsigned long) "write";
91 args[1] = 3;
92 args[2] = 1;
93 args[3] = (unsigned int) prom_stdout;
94 args[4] = (unsigned long) s;
95 args[5] = len;
96 args[6] = (unsigned long) -1;
97
98 p1275_cmd_direct(args);
99} 48}
diff --git a/arch/sparc/prom/devops_32.c b/arch/sparc/prom/devops_32.c
deleted file mode 100644
index 9c5d4687242a..000000000000
--- a/arch/sparc/prom/devops_32.c
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * devops.c: Device operations using the PROM.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 */
6#include <linux/types.h>
7#include <linux/kernel.h>
8#include <linux/sched.h>
9
10#include <asm/openprom.h>
11#include <asm/oplib.h>
12
13extern void restore_current(void);
14
15/* Open the device described by the string 'dstr'. Returns the handle
16 * to that device used for subsequent operations on that device.
17 * Returns -1 on failure.
18 */
19int
20prom_devopen(char *dstr)
21{
22 int handle;
23 unsigned long flags;
24 spin_lock_irqsave(&prom_lock, flags);
25 switch(prom_vers) {
26 case PROM_V0:
27 handle = (*(romvec->pv_v0devops.v0_devopen))(dstr);
28 if(handle == 0) handle = -1;
29 break;
30 case PROM_V2:
31 case PROM_V3:
32 handle = (*(romvec->pv_v2devops.v2_dev_open))(dstr);
33 break;
34 default:
35 handle = -1;
36 break;
37 };
38 restore_current();
39 spin_unlock_irqrestore(&prom_lock, flags);
40
41 return handle;
42}
43
44/* Close the device described by device handle 'dhandle'. */
45int
46prom_devclose(int dhandle)
47{
48 unsigned long flags;
49 spin_lock_irqsave(&prom_lock, flags);
50 switch(prom_vers) {
51 case PROM_V0:
52 (*(romvec->pv_v0devops.v0_devclose))(dhandle);
53 break;
54 case PROM_V2:
55 case PROM_V3:
56 (*(romvec->pv_v2devops.v2_dev_close))(dhandle);
57 break;
58 default:
59 break;
60 };
61 restore_current();
62 spin_unlock_irqrestore(&prom_lock, flags);
63 return 0;
64}
65
66/* Seek to specified location described by 'seekhi' and 'seeklo'
67 * for device 'dhandle'.
68 */
69void
70prom_seek(int dhandle, unsigned int seekhi, unsigned int seeklo)
71{
72 unsigned long flags;
73 spin_lock_irqsave(&prom_lock, flags);
74 switch(prom_vers) {
75 case PROM_V0:
76 (*(romvec->pv_v0devops.v0_seekdev))(dhandle, seekhi, seeklo);
77 break;
78 case PROM_V2:
79 case PROM_V3:
80 (*(romvec->pv_v2devops.v2_dev_seek))(dhandle, seekhi, seeklo);
81 break;
82 default:
83 break;
84 };
85 restore_current();
86 spin_unlock_irqrestore(&prom_lock, flags);
87}
diff --git a/arch/sparc/prom/devops_64.c b/arch/sparc/prom/devops_64.c
deleted file mode 100644
index a017119e7ef1..000000000000
--- a/arch/sparc/prom/devops_64.c
+++ /dev/null
@@ -1,67 +0,0 @@
1/*
2 * devops.c: Device operations using the PROM.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7#include <linux/types.h>
8#include <linux/kernel.h>
9#include <linux/sched.h>
10
11#include <asm/openprom.h>
12#include <asm/oplib.h>
13
14/* Open the device described by the string 'dstr'. Returns the handle
15 * to that device used for subsequent operations on that device.
16 * Returns 0 on failure.
17 */
18int
19prom_devopen(const char *dstr)
20{
21 unsigned long args[5];
22
23 args[0] = (unsigned long) "open";
24 args[1] = 1;
25 args[2] = 1;
26 args[3] = (unsigned long) dstr;
27 args[4] = (unsigned long) -1;
28
29 p1275_cmd_direct(args);
30
31 return (int) args[4];
32}
33
34/* Close the device described by device handle 'dhandle'. */
35int
36prom_devclose(int dhandle)
37{
38 unsigned long args[4];
39
40 args[0] = (unsigned long) "close";
41 args[1] = 1;
42 args[2] = 0;
43 args[3] = (unsigned int) dhandle;
44
45 p1275_cmd_direct(args);
46
47 return 0;
48}
49
50/* Seek to specified location described by 'seekhi' and 'seeklo'
51 * for device 'dhandle'.
52 */
53void
54prom_seek(int dhandle, unsigned int seekhi, unsigned int seeklo)
55{
56 unsigned long args[7];
57
58 args[0] = (unsigned long) "seek";
59 args[1] = 3;
60 args[2] = 1;
61 args[3] = (unsigned int) dhandle;
62 args[4] = seekhi;
63 args[5] = seeklo;
64 args[6] = (unsigned long) -1;
65
66 p1275_cmd_direct(args);
67}
diff --git a/arch/sparc/prom/misc_64.c b/arch/sparc/prom/misc_64.c
index d24bc44e361e..e4f31d4d3715 100644
--- a/arch/sparc/prom/misc_64.c
+++ b/arch/sparc/prom/misc_64.c
@@ -18,7 +18,7 @@
18#include <asm/system.h> 18#include <asm/system.h>
19#include <asm/ldc.h> 19#include <asm/ldc.h>
20 20
21int prom_service_exists(const char *service_name) 21static int prom_service_exists(const char *service_name)
22{ 22{
23 unsigned long args[5]; 23 unsigned long args[5];
24 24
@@ -150,20 +150,6 @@ void prom_halt_power_off(void)
150 prom_halt(); 150 prom_halt();
151} 151}
152 152
153/* Set prom sync handler to call function 'funcp'. */
154void prom_setcallback(callback_func_t funcp)
155{
156 unsigned long args[5];
157 if (!funcp)
158 return;
159 args[0] = (unsigned long) "set-callback";
160 args[1] = 1;
161 args[2] = 1;
162 args[3] = (unsigned long) funcp;
163 args[4] = (unsigned long) -1;
164 p1275_cmd_direct(args);
165}
166
167/* Get the idprom and stuff it into buffer 'idbuf'. Returns the 153/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
168 * format type. 'num_bytes' is the number of bytes that your idbuf 154 * format type. 'num_bytes' is the number of bytes that your idbuf
169 * has space for. Returns 0xff on error. 155 * has space for. Returns 0xff on error.
diff --git a/arch/sparc/prom/printf.c b/arch/sparc/prom/printf.c
index ca869266b9f3..d9682f06b3b0 100644
--- a/arch/sparc/prom/printf.c
+++ b/arch/sparc/prom/printf.c
@@ -15,22 +15,45 @@
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/compiler.h> 17#include <linux/compiler.h>
18#include <linux/spinlock.h>
18 19
19#include <asm/openprom.h> 20#include <asm/openprom.h>
20#include <asm/oplib.h> 21#include <asm/oplib.h>
21 22
23#define CONSOLE_WRITE_BUF_SIZE 1024
24
22static char ppbuf[1024]; 25static char ppbuf[1024];
26static char console_write_buf[CONSOLE_WRITE_BUF_SIZE];
27static DEFINE_RAW_SPINLOCK(console_write_lock);
23 28
24void notrace prom_write(const char *buf, unsigned int n) 29void notrace prom_write(const char *buf, unsigned int n)
25{ 30{
26 char ch; 31 unsigned int dest_len;
32 unsigned long flags;
33 char *dest;
34
35 dest = console_write_buf;
36 raw_spin_lock_irqsave(&console_write_lock, flags);
27 37
28 while (n != 0) { 38 dest_len = 0;
29 --n; 39 while (n-- != 0) {
30 if ((ch = *buf++) == '\n') 40 char ch = *buf++;
31 prom_putchar('\r'); 41 if (ch == '\n') {
32 prom_putchar(ch); 42 *dest++ = '\r';
43 dest_len++;
44 }
45 *dest++ = ch;
46 dest_len++;
47 if (dest_len >= CONSOLE_WRITE_BUF_SIZE - 1) {
48 prom_console_write_buf(console_write_buf, dest_len);
49 dest = console_write_buf;
50 dest_len = 0;
51 }
33 } 52 }
53 if (dest_len)
54 prom_console_write_buf(console_write_buf, dest_len);
55
56 raw_spin_unlock_irqrestore(&console_write_lock, flags);
34} 57}
35 58
36void notrace prom_printf(const char *fmt, ...) 59void notrace prom_printf(const char *fmt, ...)
diff --git a/arch/sparc/prom/tree_32.c b/arch/sparc/prom/tree_32.c
index 63e08e149774..535e2e69ac1d 100644
--- a/arch/sparc/prom/tree_32.c
+++ b/arch/sparc/prom/tree_32.c
@@ -342,19 +342,3 @@ phandle prom_inst2pkg(int inst)
342 if (node == -1) return 0; 342 if (node == -1) return 0;
343 return node; 343 return node;
344} 344}
345
346/* Return 'node' assigned to a particular prom 'path'
347 * FIXME: Should work for v0 as well
348 */
349phandle prom_pathtoinode(char *path)
350{
351 phandle node;
352 int inst;
353
354 inst = prom_devopen (path);
355 if (inst == -1) return 0;
356 node = prom_inst2pkg (inst);
357 prom_devclose (inst);
358 if (node == -1) return 0;
359 return node;
360}
diff --git a/arch/sparc/prom/tree_64.c b/arch/sparc/prom/tree_64.c
index 691be68932f8..d93660048376 100644
--- a/arch/sparc/prom/tree_64.c
+++ b/arch/sparc/prom/tree_64.c
@@ -374,24 +374,6 @@ inline phandle prom_inst2pkg(int inst)
374 return node; 374 return node;
375} 375}
376 376
377/* Return 'node' assigned to a particular prom 'path'
378 * FIXME: Should work for v0 as well
379 */
380phandle prom_pathtoinode(const char *path)
381{
382 phandle node;
383 int inst;
384
385 inst = prom_devopen (path);
386 if (inst == 0)
387 return 0;
388 node = prom_inst2pkg(inst);
389 prom_devclose(inst);
390 if (node == -1)
391 return 0;
392 return node;
393}
394
395int prom_ihandle2path(int handle, char *buffer, int bufsize) 377int prom_ihandle2path(int handle, char *buffer, int bufsize)
396{ 378{
397 unsigned long args[7]; 379 unsigned long args[7];
diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
index 07ec8a865c1d..e11b5fcb70eb 100644
--- a/arch/tile/Kconfig
+++ b/arch/tile/Kconfig
@@ -329,6 +329,18 @@ endmenu # Tilera-specific configuration
329 329
330menu "Bus options" 330menu "Bus options"
331 331
332config PCI
333 bool "PCI support"
334 default y
335 select PCI_DOMAINS
336 ---help---
337 Enable PCI root complex support, so PCIe endpoint devices can
338 be attached to the Tile chip. Many, but not all, PCI devices
339 are supported under Tilera's root complex driver.
340
341config PCI_DOMAINS
342 bool
343
332config NO_IOMEM 344config NO_IOMEM
333 def_bool !PCI 345 def_bool !PCI
334 346
diff --git a/arch/tile/include/asm/cacheflush.h b/arch/tile/include/asm/cacheflush.h
index c5741da4eeac..14a3f8556ace 100644
--- a/arch/tile/include/asm/cacheflush.h
+++ b/arch/tile/include/asm/cacheflush.h
@@ -137,4 +137,56 @@ static inline void finv_buffer(void *buffer, size_t size)
137 mb_incoherent(); 137 mb_incoherent();
138} 138}
139 139
140/*
141 * Flush & invalidate a VA range that is homed remotely on a single core,
142 * waiting until the memory controller holds the flushed values.
143 */
144static inline void finv_buffer_remote(void *buffer, size_t size)
145{
146 char *p;
147 int i;
148
149 /*
150 * Flush and invalidate the buffer out of the local L1/L2
151 * and request the home cache to flush and invalidate as well.
152 */
153 __finv_buffer(buffer, size);
154
155 /*
156 * Wait for the home cache to acknowledge that it has processed
157 * all the flush-and-invalidate requests. This does not mean
158 * that the flushed data has reached the memory controller yet,
159 * but it does mean the home cache is processing the flushes.
160 */
161 __insn_mf();
162
163 /*
164 * Issue a load to the last cache line, which can't complete
165 * until all the previously-issued flushes to the same memory
166 * controller have also completed. If we weren't striping
167 * memory, that one load would be sufficient, but since we may
168 * be, we also need to back up to the last load issued to
169 * another memory controller, which would be the point where
170 * we crossed an 8KB boundary (the granularity of striping
171 * across memory controllers). Keep backing up and doing this
172 * until we are before the beginning of the buffer, or have
173 * hit all the controllers.
174 */
175 for (i = 0, p = (char *)buffer + size - 1;
176 i < (1 << CHIP_LOG_NUM_MSHIMS()) && p >= (char *)buffer;
177 ++i) {
178 const unsigned long STRIPE_WIDTH = 8192;
179
180 /* Force a load instruction to issue. */
181 *(volatile char *)p;
182
183 /* Jump to end of previous stripe. */
184 p -= STRIPE_WIDTH;
185 p = (char *)((unsigned long)p | (STRIPE_WIDTH - 1));
186 }
187
188 /* Wait for the loads (and thus flushes) to have completed. */
189 __insn_mf();
190}
191
140#endif /* _ASM_TILE_CACHEFLUSH_H */ 192#endif /* _ASM_TILE_CACHEFLUSH_H */
diff --git a/arch/tile/include/asm/highmem.h b/arch/tile/include/asm/highmem.h
index e0f7ee186721..b2a6c5de79ab 100644
--- a/arch/tile/include/asm/highmem.h
+++ b/arch/tile/include/asm/highmem.h
@@ -23,7 +23,6 @@
23 23
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/threads.h> 25#include <linux/threads.h>
26#include <asm/kmap_types.h>
27#include <asm/tlbflush.h> 26#include <asm/tlbflush.h>
28#include <asm/homecache.h> 27#include <asm/homecache.h>
29 28
diff --git a/arch/tile/include/asm/io.h b/arch/tile/include/asm/io.h
index ee43328713ab..d3cbb9b14cbe 100644
--- a/arch/tile/include/asm/io.h
+++ b/arch/tile/include/asm/io.h
@@ -55,9 +55,6 @@ extern void iounmap(volatile void __iomem *addr);
55#define ioremap_writethrough(physaddr, size) ioremap(physaddr, size) 55#define ioremap_writethrough(physaddr, size) ioremap(physaddr, size)
56#define ioremap_fullcache(physaddr, size) ioremap(physaddr, size) 56#define ioremap_fullcache(physaddr, size) ioremap(physaddr, size)
57 57
58void __iomem *ioport_map(unsigned long port, unsigned int len);
59extern inline void ioport_unmap(void __iomem *addr) {}
60
61#define mmiowb() 58#define mmiowb()
62 59
63/* Conversion between virtual and physical mappings. */ 60/* Conversion between virtual and physical mappings. */
@@ -189,12 +186,22 @@ static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
189 * we never run, uses them unconditionally. 186 * we never run, uses them unconditionally.
190 */ 187 */
191 188
192static inline int ioport_panic(void) 189static inline long ioport_panic(void)
193{ 190{
194 panic("inb/outb and friends do not exist on tile"); 191 panic("inb/outb and friends do not exist on tile");
195 return 0; 192 return 0;
196} 193}
197 194
195static inline void __iomem *ioport_map(unsigned long port, unsigned int len)
196{
197 return (void __iomem *) ioport_panic();
198}
199
200static inline void ioport_unmap(void __iomem *addr)
201{
202 ioport_panic();
203}
204
198static inline u8 inb(unsigned long addr) 205static inline u8 inb(unsigned long addr)
199{ 206{
200 return ioport_panic(); 207 return ioport_panic();
diff --git a/arch/tile/include/asm/kmap_types.h b/arch/tile/include/asm/kmap_types.h
index 1480106d1c05..3d0f20246260 100644
--- a/arch/tile/include/asm/kmap_types.h
+++ b/arch/tile/include/asm/kmap_types.h
@@ -16,28 +16,42 @@
16#define _ASM_TILE_KMAP_TYPES_H 16#define _ASM_TILE_KMAP_TYPES_H
17 17
18/* 18/*
19 * In TILE Linux each set of four of these uses another 16MB chunk of 19 * In 32-bit TILE Linux we have to balance the desire to have a lot of
20 * address space, given 64 tiles and 64KB pages, so we only enable 20 * nested atomic mappings with the fact that large page sizes and many
21 * ones that are required by the kernel configuration. 21 * processors chew up address space quickly. In a typical
22 * 64-processor, 64KB-page layout build, making KM_TYPE_NR one larger
23 * adds 4MB of required address-space. For now we leave KM_TYPE_NR
24 * set to depth 8.
22 */ 25 */
23enum km_type { 26enum km_type {
27 KM_TYPE_NR = 8
28};
29
30/*
31 * We provide dummy definitions of all the stray values that used to be
32 * required for kmap_atomic() and no longer are.
33 */
34enum {
24 KM_BOUNCE_READ, 35 KM_BOUNCE_READ,
25 KM_SKB_SUNRPC_DATA, 36 KM_SKB_SUNRPC_DATA,
26 KM_SKB_DATA_SOFTIRQ, 37 KM_SKB_DATA_SOFTIRQ,
27 KM_USER0, 38 KM_USER0,
28 KM_USER1, 39 KM_USER1,
29 KM_BIO_SRC_IRQ, 40 KM_BIO_SRC_IRQ,
41 KM_BIO_DST_IRQ,
42 KM_PTE0,
43 KM_PTE1,
30 KM_IRQ0, 44 KM_IRQ0,
31 KM_IRQ1, 45 KM_IRQ1,
32 KM_SOFTIRQ0, 46 KM_SOFTIRQ0,
33 KM_SOFTIRQ1, 47 KM_SOFTIRQ1,
34 KM_MEMCPY0, 48 KM_SYNC_ICACHE,
35 KM_MEMCPY1, 49 KM_SYNC_DCACHE,
36#if defined(CONFIG_HIGHPTE) 50 KM_UML_USERCOPY,
37 KM_PTE0, 51 KM_IRQ_PTE,
38 KM_PTE1, 52 KM_NMI,
39#endif 53 KM_NMI_PTE,
40 KM_TYPE_NR 54 KM_KDB
41}; 55};
42 56
43#endif /* _ASM_TILE_KMAP_TYPES_H */ 57#endif /* _ASM_TILE_KMAP_TYPES_H */
diff --git a/arch/tile/include/asm/pci-bridge.h b/arch/tile/include/asm/pci-bridge.h
deleted file mode 100644
index e853b0e2793b..000000000000
--- a/arch/tile/include/asm/pci-bridge.h
+++ /dev/null
@@ -1,117 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PCI_BRIDGE_H
16#define _ASM_TILE_PCI_BRIDGE_H
17
18#include <linux/ioport.h>
19#include <linux/pci.h>
20
21struct device_node;
22struct pci_controller;
23
24/*
25 * pci_io_base returns the memory address at which you can access
26 * the I/O space for PCI bus number `bus' (or NULL on error).
27 */
28extern void __iomem *pci_bus_io_base(unsigned int bus);
29extern unsigned long pci_bus_io_base_phys(unsigned int bus);
30extern unsigned long pci_bus_mem_base_phys(unsigned int bus);
31
32/* Allocate a new PCI host bridge structure */
33extern struct pci_controller *pcibios_alloc_controller(void);
34
35/* Helper function for setting up resources */
36extern void pci_init_resource(struct resource *res, unsigned long start,
37 unsigned long end, int flags, char *name);
38
39/* Get the PCI host controller for a bus */
40extern struct pci_controller *pci_bus_to_hose(int bus);
41
42/*
43 * Structure of a PCI controller (host bridge)
44 */
45struct pci_controller {
46 int index; /* PCI domain number */
47 struct pci_bus *root_bus;
48
49 int first_busno;
50 int last_busno;
51
52 int hv_cfg_fd[2]; /* config{0,1} fds for this PCIe controller */
53 int hv_mem_fd; /* fd to Hypervisor for MMIO operations */
54
55 struct pci_ops *ops;
56
57 int irq_base; /* Base IRQ from the Hypervisor */
58 int plx_gen1; /* flag for PLX Gen 1 configuration */
59
60 /* Address ranges that are routed to this controller/bridge. */
61 struct resource mem_resources[3];
62};
63
64static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
65{
66 return bus->sysdata;
67}
68
69extern void setup_indirect_pci_nomap(struct pci_controller *hose,
70 void __iomem *cfg_addr, void __iomem *cfg_data);
71extern void setup_indirect_pci(struct pci_controller *hose,
72 u32 cfg_addr, u32 cfg_data);
73extern void setup_grackle(struct pci_controller *hose);
74
75extern unsigned char common_swizzle(struct pci_dev *, unsigned char *);
76
77/*
78 * The following code swizzles for exactly one bridge. The routine
79 * common_swizzle below handles multiple bridges. But there are a
80 * some boards that don't follow the PCI spec's suggestion so we
81 * break this piece out separately.
82 */
83static inline unsigned char bridge_swizzle(unsigned char pin,
84 unsigned char idsel)
85{
86 return (((pin-1) + idsel) % 4) + 1;
87}
88
89/*
90 * The following macro is used to lookup irqs in a standard table
91 * format for those PPC systems that do not already have PCI
92 * interrupts properly routed.
93 */
94/* FIXME - double check this */
95#define PCI_IRQ_TABLE_LOOKUP ({ \
96 long _ctl_ = -1; \
97 if (idsel >= min_idsel && idsel <= max_idsel && pin <= irqs_per_slot) \
98 _ctl_ = pci_irq_table[idsel - min_idsel][pin-1]; \
99 _ctl_; \
100})
101
102/*
103 * Scan the buses below a given PCI host bridge and assign suitable
104 * resources to all devices found.
105 */
106extern int pciauto_bus_scan(struct pci_controller *, int);
107
108#ifdef CONFIG_PCI
109extern unsigned long pci_address_to_pio(phys_addr_t address);
110#else
111static inline unsigned long pci_address_to_pio(phys_addr_t address)
112{
113 return (unsigned long)-1;
114}
115#endif
116
117#endif /* _ASM_TILE_PCI_BRIDGE_H */
diff --git a/arch/tile/include/asm/pci.h b/arch/tile/include/asm/pci.h
index b0c15da2d5d5..c3fc458a0d32 100644
--- a/arch/tile/include/asm/pci.h
+++ b/arch/tile/include/asm/pci.h
@@ -15,7 +15,29 @@
15#ifndef _ASM_TILE_PCI_H 15#ifndef _ASM_TILE_PCI_H
16#define _ASM_TILE_PCI_H 16#define _ASM_TILE_PCI_H
17 17
18#include <asm/pci-bridge.h> 18#include <linux/pci.h>
19
20/*
21 * Structure of a PCI controller (host bridge)
22 */
23struct pci_controller {
24 int index; /* PCI domain number */
25 struct pci_bus *root_bus;
26
27 int first_busno;
28 int last_busno;
29
30 int hv_cfg_fd[2]; /* config{0,1} fds for this PCIe controller */
31 int hv_mem_fd; /* fd to Hypervisor for MMIO operations */
32
33 struct pci_ops *ops;
34
35 int irq_base; /* Base IRQ from the Hypervisor */
36 int plx_gen1; /* flag for PLX Gen 1 configuration */
37
38 /* Address ranges that are routed to this controller/bridge. */
39 struct resource mem_resources[3];
40};
19 41
20/* 42/*
21 * The hypervisor maps the entirety of CPA-space as bus addresses, so 43 * The hypervisor maps the entirety of CPA-space as bus addresses, so
@@ -24,56 +46,12 @@
24 */ 46 */
25#define PCI_DMA_BUS_IS_PHYS 1 47#define PCI_DMA_BUS_IS_PHYS 1
26 48
27struct pci_controller *pci_bus_to_hose(int bus);
28unsigned char __init common_swizzle(struct pci_dev *dev, unsigned char *pinp);
29int __init tile_pci_init(void); 49int __init tile_pci_init(void);
30void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
31void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
32void __devinit pcibios_fixup_bus(struct pci_bus *bus);
33 50
34int __devinit _tile_cfg_read(struct pci_controller *hose, 51void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
35 int bus, 52static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) {}
36 int slot,
37 int function,
38 int offset,
39 int size,
40 u32 *val);
41int __devinit _tile_cfg_write(struct pci_controller *hose,
42 int bus,
43 int slot,
44 int function,
45 int offset,
46 int size,
47 u32 val);
48 53
49/* 54void __devinit pcibios_fixup_bus(struct pci_bus *bus);
50 * These are used to to config reads and writes in the early stages of
51 * setup before the driver infrastructure has been set up enough to be
52 * able to do config reads and writes.
53 */
54#define early_cfg_read(where, size, value) \
55 _tile_cfg_read(controller, \
56 current_bus, \
57 pci_slot, \
58 pci_fn, \
59 where, \
60 size, \
61 value)
62
63#define early_cfg_write(where, size, value) \
64 _tile_cfg_write(controller, \
65 current_bus, \
66 pci_slot, \
67 pci_fn, \
68 where, \
69 size, \
70 value)
71
72
73
74#define PCICFG_BYTE 1
75#define PCICFG_WORD 2
76#define PCICFG_DWORD 4
77 55
78#define TILE_NUM_PCIE 2 56#define TILE_NUM_PCIE 2
79 57
@@ -88,33 +66,33 @@ static inline int pci_proc_domain(struct pci_bus *bus)
88} 66}
89 67
90/* 68/*
91 * I/O space is currently not supported. 69 * pcibios_assign_all_busses() tells whether or not the bus numbers
70 * should be reassigned, in case the BIOS didn't do it correctly, or
71 * in case we don't have a BIOS and we want to let Linux do it.
92 */ 72 */
73static inline int pcibios_assign_all_busses(void)
74{
75 return 1;
76}
93 77
94#define TILE_PCIE_LOWER_IO 0x0 78/*
95#define TILE_PCIE_UPPER_IO 0x10000 79 * No special bus mastering setup handling.
96#define TILE_PCIE_PCIE_IO_SIZE 0x0000FFFF 80 */
97
98#define _PAGE_NO_CACHE 0
99#define _PAGE_GUARDED 0
100
101
102#define pcibios_assign_all_busses() pci_assign_all_buses
103extern int pci_assign_all_buses;
104
105static inline void pcibios_set_master(struct pci_dev *dev) 81static inline void pcibios_set_master(struct pci_dev *dev)
106{ 82{
107 /* No special bus mastering setup handling */
108} 83}
109 84
110#define PCIBIOS_MIN_MEM 0 85#define PCIBIOS_MIN_MEM 0
111#define PCIBIOS_MIN_IO TILE_PCIE_LOWER_IO 86#define PCIBIOS_MIN_IO 0
112 87
113/* 88/*
114 * This flag tells if the platform is TILEmpower that needs 89 * This flag tells if the platform is TILEmpower that needs
115 * special configuration for the PLX switch chip. 90 * special configuration for the PLX switch chip.
116 */ 91 */
117extern int blade_pci; 92extern int tile_plx_gen1;
93
94/* Use any cpu for PCI. */
95#define cpumask_of_pcibus(bus) cpu_online_mask
118 96
119/* implement the pci_ DMA API in terms of the generic device dma_ one */ 97/* implement the pci_ DMA API in terms of the generic device dma_ one */
120#include <asm-generic/pci-dma-compat.h> 98#include <asm-generic/pci-dma-compat.h>
@@ -122,7 +100,4 @@ extern int blade_pci;
122/* generic pci stuff */ 100/* generic pci stuff */
123#include <asm-generic/pci.h> 101#include <asm-generic/pci.h>
124 102
125/* Use any cpu for PCI. */
126#define cpumask_of_pcibus(bus) cpu_online_mask
127
128#endif /* _ASM_TILE_PCI_H */ 103#endif /* _ASM_TILE_PCI_H */
diff --git a/arch/tile/include/asm/pgtable.h b/arch/tile/include/asm/pgtable.h
index dc4ccdd855bc..a6604e9485da 100644
--- a/arch/tile/include/asm/pgtable.h
+++ b/arch/tile/include/asm/pgtable.h
@@ -344,10 +344,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
344#define pgd_offset_k(address) pgd_offset(&init_mm, address) 344#define pgd_offset_k(address) pgd_offset(&init_mm, address)
345 345
346#if defined(CONFIG_HIGHPTE) 346#if defined(CONFIG_HIGHPTE)
347extern pte_t *_pte_offset_map(pmd_t *, unsigned long address, enum km_type); 347extern pte_t *pte_offset_map(pmd_t *, unsigned long address);
348#define pte_offset_map(dir, address) \ 348#define pte_unmap(pte) kunmap_atomic(pte)
349 _pte_offset_map(dir, address, KM_PTE0)
350#define pte_unmap(pte) kunmap_atomic(pte, KM_PTE0)
351#else 349#else
352#define pte_offset_map(dir, address) pte_offset_kernel(dir, address) 350#define pte_offset_map(dir, address) pte_offset_kernel(dir, address)
353#define pte_unmap(pte) do { } while (0) 351#define pte_unmap(pte) do { } while (0)
diff --git a/arch/tile/include/asm/processor.h b/arch/tile/include/asm/processor.h
index 1747ff3946b2..a9e7c8760334 100644
--- a/arch/tile/include/asm/processor.h
+++ b/arch/tile/include/asm/processor.h
@@ -292,8 +292,18 @@ extern int kstack_hash;
292/* Are we using huge pages in the TLB for kernel data? */ 292/* Are we using huge pages in the TLB for kernel data? */
293extern int kdata_huge; 293extern int kdata_huge;
294 294
295/* Support standard Linux prefetching. */
296#define ARCH_HAS_PREFETCH
297#define prefetch(x) __builtin_prefetch(x)
295#define PREFETCH_STRIDE CHIP_L2_LINE_SIZE() 298#define PREFETCH_STRIDE CHIP_L2_LINE_SIZE()
296 299
300/* Bring a value into the L1D, faulting the TLB if necessary. */
301#ifdef __tilegx__
302#define prefetch_L1(x) __insn_prefetch_l1_fault((void *)(x))
303#else
304#define prefetch_L1(x) __insn_prefetch_L1((void *)(x))
305#endif
306
297#else /* __ASSEMBLY__ */ 307#else /* __ASSEMBLY__ */
298 308
299/* Do some slow action (e.g. read a slow SPR). */ 309/* Do some slow action (e.g. read a slow SPR). */
diff --git a/arch/tile/include/asm/signal.h b/arch/tile/include/asm/signal.h
index c1ee1d61d44c..81d92a45cd4b 100644
--- a/arch/tile/include/asm/signal.h
+++ b/arch/tile/include/asm/signal.h
@@ -25,7 +25,7 @@
25 25
26#if defined(__KERNEL__) && !defined(__ASSEMBLY__) 26#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
27struct pt_regs; 27struct pt_regs;
28int restore_sigcontext(struct pt_regs *, struct sigcontext __user *, long *); 28int restore_sigcontext(struct pt_regs *, struct sigcontext __user *);
29int setup_sigcontext(struct sigcontext __user *, struct pt_regs *); 29int setup_sigcontext(struct sigcontext __user *, struct pt_regs *);
30void do_signal(struct pt_regs *regs); 30void do_signal(struct pt_regs *regs);
31#endif 31#endif
diff --git a/arch/tile/include/asm/stat.h b/arch/tile/include/asm/stat.h
index 3dc90fa92c70..b16e5db8f0e7 100644
--- a/arch/tile/include/asm/stat.h
+++ b/arch/tile/include/asm/stat.h
@@ -1 +1,4 @@
1#ifdef CONFIG_COMPAT
2#define __ARCH_WANT_STAT64 /* Used for compat_sys_stat64() etc. */
3#endif
1#include <asm-generic/stat.h> 4#include <asm-generic/stat.h>
diff --git a/arch/tile/include/asm/unistd.h b/arch/tile/include/asm/unistd.h
index f2e3ff485333..b35c2db71199 100644
--- a/arch/tile/include/asm/unistd.h
+++ b/arch/tile/include/asm/unistd.h
@@ -41,6 +41,7 @@ __SYSCALL(__NR_cmpxchg_badaddr, sys_cmpxchg_badaddr)
41#ifdef CONFIG_COMPAT 41#ifdef CONFIG_COMPAT
42#define __ARCH_WANT_SYS_LLSEEK 42#define __ARCH_WANT_SYS_LLSEEK
43#endif 43#endif
44#define __ARCH_WANT_SYS_NEWFSTATAT
44#endif 45#endif
45 46
46#endif /* _ASM_TILE_UNISTD_H */ 47#endif /* _ASM_TILE_UNISTD_H */
diff --git a/arch/tile/include/hv/drv_xgbe_impl.h b/arch/tile/include/hv/drv_xgbe_impl.h
new file mode 100644
index 000000000000..3a73b2b44913
--- /dev/null
+++ b/arch/tile/include/hv/drv_xgbe_impl.h
@@ -0,0 +1,300 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file drivers/xgbe/impl.h
17 * Implementation details for the NetIO library.
18 */
19
20#ifndef __DRV_XGBE_IMPL_H__
21#define __DRV_XGBE_IMPL_H__
22
23#include <hv/netio_errors.h>
24#include <hv/netio_intf.h>
25#include <hv/drv_xgbe_intf.h>
26
27
28/** How many groups we have (log2). */
29#define LOG2_NUM_GROUPS (12)
30/** How many groups we have. */
31#define NUM_GROUPS (1 << LOG2_NUM_GROUPS)
32
33/** Number of output requests we'll buffer per tile. */
34#define EPP_REQS_PER_TILE (32)
35
36/** Words used in an eDMA command without checksum acceleration. */
37#define EDMA_WDS_NO_CSUM 8
38/** Words used in an eDMA command with checksum acceleration. */
39#define EDMA_WDS_CSUM 10
40/** Total available words in the eDMA command FIFO. */
41#define EDMA_WDS_TOTAL 128
42
43
44/*
45 * FIXME: These definitions are internal and should have underscores!
46 * NOTE: The actual numeric values here are intentional and allow us to
47 * optimize the concept "if small ... else if large ... else ...", by
48 * checking for the low bit being set, and then for non-zero.
49 * These are used as array indices, so they must have the values (0, 1, 2)
50 * in some order.
51 */
52#define SIZE_SMALL (1) /**< Small packet queue. */
53#define SIZE_LARGE (2) /**< Large packet queue. */
54#define SIZE_JUMBO (0) /**< Jumbo packet queue. */
55
56/** The number of "SIZE_xxx" values. */
57#define NETIO_NUM_SIZES 3
58
59
60/*
61 * Default numbers of packets for IPP drivers. These values are chosen
62 * such that CIPP1 will not overflow its L2 cache.
63 */
64
65/** The default number of small packets. */
66#define NETIO_DEFAULT_SMALL_PACKETS 2750
67/** The default number of large packets. */
68#define NETIO_DEFAULT_LARGE_PACKETS 2500
69/** The default number of jumbo packets. */
70#define NETIO_DEFAULT_JUMBO_PACKETS 250
71
72
73/** Log2 of the size of a memory arena. */
74#define NETIO_ARENA_SHIFT 24 /* 16 MB */
75/** Size of a memory arena. */
76#define NETIO_ARENA_SIZE (1 << NETIO_ARENA_SHIFT)
77
78
79/** A queue of packets.
80 *
81 * This structure partially defines a queue of packets waiting to be
82 * processed. The queue as a whole is written to by an interrupt handler and
83 * read by non-interrupt code; this data structure is what's touched by the
84 * interrupt handler. The other part of the queue state, the read offset, is
85 * kept in user space, not in hypervisor space, so it is in a separate data
86 * structure.
87 *
88 * The read offset (__packet_receive_read in the user part of the queue
89 * structure) points to the next packet to be read. When the read offset is
90 * equal to the write offset, the queue is empty; therefore the queue must
91 * contain one more slot than the required maximum queue size.
92 *
93 * Here's an example of all 3 state variables and what they mean. All
94 * pointers move left to right.
95 *
96 * @code
97 * I I V V V V I I I I
98 * 0 1 2 3 4 5 6 7 8 9 10
99 * ^ ^ ^ ^
100 * | | |
101 * | | __last_packet_plus_one
102 * | __buffer_write
103 * __packet_receive_read
104 * @endcode
105 *
106 * This queue has 10 slots, and thus can hold 9 packets (_last_packet_plus_one
107 * = 10). The read pointer is at 2, and the write pointer is at 6; thus,
108 * there are valid, unread packets in slots 2, 3, 4, and 5. The remaining
109 * slots are invalid (do not contain a packet).
110 */
111typedef struct {
112 /** Byte offset of the next notify packet to be written: zero for the first
113 * packet on the queue, sizeof (netio_pkt_t) for the second packet on the
114 * queue, etc. */
115 volatile uint32_t __packet_write;
116
117 /** Offset of the packet after the last valid packet (i.e., when any
118 * pointer is incremented to this value, it wraps back to zero). */
119 uint32_t __last_packet_plus_one;
120}
121__netio_packet_queue_t;
122
123
124/** A queue of buffers.
125 *
126 * This structure partially defines a queue of empty buffers which have been
127 * obtained via requests to the IPP. (The elements of the queue are packet
128 * handles, which are transformed into a full netio_pkt_t when the buffer is
129 * retrieved.) The queue as a whole is written to by an interrupt handler and
130 * read by non-interrupt code; this data structure is what's touched by the
131 * interrupt handler. The other parts of the queue state, the read offset and
132 * requested write offset, are kept in user space, not in hypervisor space, so
133 * they are in a separate data structure.
134 *
135 * The read offset (__buffer_read in the user part of the queue structure)
136 * points to the next buffer to be read. When the read offset is equal to the
137 * write offset, the queue is empty; therefore the queue must contain one more
138 * slot than the required maximum queue size.
139 *
140 * The requested write offset (__buffer_requested_write in the user part of
141 * the queue structure) points to the slot which will hold the next buffer we
142 * request from the IPP, once we get around to sending such a request. When
143 * the requested write offset is equal to the write offset, no requests for
144 * new buffers are outstanding; when the requested write offset is one greater
145 * than the read offset, no more requests may be sent.
146 *
147 * Note that, unlike the packet_queue, the buffer_queue places incoming
148 * buffers at decreasing addresses. This makes the check for "is it time to
149 * wrap the buffer pointer" cheaper in the assembly code which receives new
150 * buffers, and means that the value which defines the queue size,
151 * __last_buffer, is different than in the packet queue. Also, the offset
152 * used in the packet_queue is already scaled by the size of a packet; here we
153 * use unscaled slot indices for the offsets. (These differences are
154 * historical, and in the future it's possible that the packet_queue will look
155 * more like this queue.)
156 *
157 * @code
158 * Here's an example of all 4 state variables and what they mean. Remember:
159 * all pointers move right to left.
160 *
161 * V V V I I R R V V V
162 * 0 1 2 3 4 5 6 7 8 9
163 * ^ ^ ^ ^
164 * | | | |
165 * | | | __last_buffer
166 * | | __buffer_write
167 * | __buffer_requested_write
168 * __buffer_read
169 * @endcode
170 *
171 * This queue has 10 slots, and thus can hold 9 buffers (_last_buffer = 9).
172 * The read pointer is at 2, and the write pointer is at 6; thus, there are
173 * valid, unread buffers in slots 2, 1, 0, 9, 8, and 7. The requested write
174 * pointer is at 4; thus, requests have been made to the IPP for buffers which
175 * will be placed in slots 6 and 5 when they arrive. Finally, the remaining
176 * slots are invalid (do not contain a buffer).
177 */
178typedef struct
179{
180 /** Ordinal number of the next buffer to be written: 0 for the first slot in
181 * the queue, 1 for the second slot in the queue, etc. */
182 volatile uint32_t __buffer_write;
183
184 /** Ordinal number of the last buffer (i.e., when any pointer is decremented
185 * below zero, it is reloaded with this value). */
186 uint32_t __last_buffer;
187}
188__netio_buffer_queue_t;
189
190
191/**
192 * An object for providing Ethernet packets to a process.
193 */
194typedef struct __netio_queue_impl_t
195{
196 /** The queue of packets waiting to be received. */
197 __netio_packet_queue_t __packet_receive_queue;
198 /** The intr bit mask that IDs this device. */
199 unsigned int __intr_id;
200 /** Offset to queues of empty buffers, one per size. */
201 uint32_t __buffer_queue[NETIO_NUM_SIZES];
202 /** The address of the first EPP tile, or -1 if no EPP. */
203 /* ISSUE: Actually this is always "0" or "~0". */
204 uint32_t __epp_location;
205 /** The queue ID that this queue represents. */
206 unsigned int __queue_id;
207 /** Number of acknowledgements received. */
208 volatile uint32_t __acks_received;
209 /** Last completion number received for packet_sendv. */
210 volatile uint32_t __last_completion_rcv;
211 /** Number of packets allowed to be outstanding. */
212 uint32_t __max_outstanding;
213 /** First VA available for packets. */
214 void* __va_0;
215 /** First VA in second range available for packets. */
216 void* __va_1;
217 /** Padding to align the "__packets" field to the size of a netio_pkt_t. */
218 uint32_t __padding[3];
219 /** The packets themselves. */
220 netio_pkt_t __packets[0];
221}
222netio_queue_impl_t;
223
224
225/**
226 * An object for managing the user end of a NetIO queue.
227 */
228typedef struct __netio_queue_user_impl_t
229{
230 /** The next incoming packet to be read. */
231 uint32_t __packet_receive_read;
232 /** The next empty buffers to be read, one index per size. */
233 uint8_t __buffer_read[NETIO_NUM_SIZES];
234 /** Where the empty buffer we next request from the IPP will go, one index
235 * per size. */
236 uint8_t __buffer_requested_write[NETIO_NUM_SIZES];
237 /** PCIe interface flag. */
238 uint8_t __pcie;
239 /** Number of packets left to be received before we send a credit update. */
240 uint32_t __receive_credit_remaining;
241 /** Value placed in __receive_credit_remaining when it reaches zero. */
242 uint32_t __receive_credit_interval;
243 /** First fast I/O routine index. */
244 uint32_t __fastio_index;
245 /** Number of acknowledgements expected. */
246 uint32_t __acks_outstanding;
247 /** Last completion number requested. */
248 uint32_t __last_completion_req;
249 /** File descriptor for driver. */
250 int __fd;
251}
252netio_queue_user_impl_t;
253
254
255#define NETIO_GROUP_CHUNK_SIZE 64 /**< Max # groups in one IPP request */
256#define NETIO_BUCKET_CHUNK_SIZE 64 /**< Max # buckets in one IPP request */
257
258
259/** Internal structure used to convey packet send information to the
260 * hypervisor. FIXME: Actually, it's not used for that anymore, but
261 * netio_packet_send() still uses it internally.
262 */
263typedef struct
264{
265 uint16_t flags; /**< Packet flags (__NETIO_SEND_FLG_xxx) */
266 uint16_t transfer_size; /**< Size of packet */
267 uint32_t va; /**< VA of start of packet */
268 __netio_pkt_handle_t handle; /**< Packet handle */
269 uint32_t csum0; /**< First checksum word */
270 uint32_t csum1; /**< Second checksum word */
271}
272__netio_send_cmd_t;
273
274
275/** Flags used in two contexts:
276 * - As the "flags" member in the __netio_send_cmd_t, above; used only
277 * for netio_pkt_send_{prepare,commit}.
278 * - As part of the flags passed to the various send packet fast I/O calls.
279 */
280
281/** Need acknowledgement on this packet. Note that some code in the
282 * normal send_pkt fast I/O handler assumes that this is equal to 1. */
283#define __NETIO_SEND_FLG_ACK 0x1
284
285/** Do checksum on this packet. (Only used with the __netio_send_cmd_t;
286 * normal packet sends use a special fast I/O index to denote checksumming,
287 * and multi-segment sends test the checksum descriptor.) */
288#define __NETIO_SEND_FLG_CSUM 0x2
289
290/** Get a completion on this packet. Only used with multi-segment sends. */
291#define __NETIO_SEND_FLG_COMPLETION 0x4
292
293/** Position of the number-of-extra-segments value in the flags word.
294 Only used with multi-segment sends. */
295#define __NETIO_SEND_FLG_XSEG_SHIFT 3
296
297/** Width of the number-of-extra-segments value in the flags word. */
298#define __NETIO_SEND_FLG_XSEG_WIDTH 2
299
300#endif /* __DRV_XGBE_IMPL_H__ */
diff --git a/arch/tile/include/hv/drv_xgbe_intf.h b/arch/tile/include/hv/drv_xgbe_intf.h
new file mode 100644
index 000000000000..146e47d5334b
--- /dev/null
+++ b/arch/tile/include/hv/drv_xgbe_intf.h
@@ -0,0 +1,615 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file drv_xgbe_intf.h
17 * Interface to the hypervisor XGBE driver.
18 */
19
20#ifndef __DRV_XGBE_INTF_H__
21#define __DRV_XGBE_INTF_H__
22
23/**
24 * An object for forwarding VAs and PAs to the hypervisor.
25 * @ingroup types
26 *
27 * This allows the supervisor to specify a number of areas of memory to
28 * store packet buffers.
29 */
30typedef struct
31{
32 /** The physical address of the memory. */
33 HV_PhysAddr pa;
34 /** Page table entry for the memory. This is only used to derive the
35 * memory's caching mode; the PA bits are ignored. */
36 HV_PTE pte;
37 /** The virtual address of the memory. */
38 HV_VirtAddr va;
39 /** Size (in bytes) of the memory area. */
40 int size;
41
42}
43netio_ipp_address_t;
44
45/** The various pread/pwrite offsets into the hypervisor-level driver.
46 * @ingroup types
47 */
48typedef enum
49{
50 /** Inform the Linux driver of the address of the NetIO arena memory.
51 * This offset is actually only used to convey information from netio
52 * to the Linux driver; it never makes it from there to the hypervisor.
53 * Write-only; takes a uint32_t specifying the VA address. */
54 NETIO_FIXED_ADDR = 0x5000000000000000ULL,
55
56 /** Inform the Linux driver of the size of the NetIO arena memory.
57 * This offset is actually only used to convey information from netio
58 * to the Linux driver; it never makes it from there to the hypervisor.
59 * Write-only; takes a uint32_t specifying the VA size. */
60 NETIO_FIXED_SIZE = 0x5100000000000000ULL,
61
62 /** Register current tile with IPP. Write then read: write, takes a
63 * netio_input_config_t, read returns a pointer to a netio_queue_impl_t. */
64 NETIO_IPP_INPUT_REGISTER_OFF = 0x6000000000000000ULL,
65
66 /** Unregister current tile from IPP. Write-only, takes a dummy argument. */
67 NETIO_IPP_INPUT_UNREGISTER_OFF = 0x6100000000000000ULL,
68
69 /** Start packets flowing. Write-only, takes a dummy argument. */
70 NETIO_IPP_INPUT_INIT_OFF = 0x6200000000000000ULL,
71
72 /** Stop packets flowing. Write-only, takes a dummy argument. */
73 NETIO_IPP_INPUT_UNINIT_OFF = 0x6300000000000000ULL,
74
75 /** Configure group (typically we group on VLAN). Write-only: takes an
76 * array of netio_group_t's, low 24 bits of the offset is the base group
77 * number times the size of a netio_group_t. */
78 NETIO_IPP_INPUT_GROUP_CFG_OFF = 0x6400000000000000ULL,
79
80 /** Configure bucket. Write-only: takes an array of netio_bucket_t's, low
81 * 24 bits of the offset is the base bucket number times the size of a
82 * netio_bucket_t. */
83 NETIO_IPP_INPUT_BUCKET_CFG_OFF = 0x6500000000000000ULL,
84
85 /** Get/set a parameter. Read or write: read or write data is the parameter
86 * value, low 32 bits of the offset is a __netio_getset_offset_t. */
87 NETIO_IPP_PARAM_OFF = 0x6600000000000000ULL,
88
89 /** Get fast I/O index. Read-only; returns a 4-byte base index value. */
90 NETIO_IPP_GET_FASTIO_OFF = 0x6700000000000000ULL,
91
92 /** Configure hijack IP address. Packets with this IPv4 dest address
93 * go to bucket NETIO_NUM_BUCKETS - 1. Write-only: takes an IP address
94 * in some standard form. FIXME: Define the form! */
95 NETIO_IPP_INPUT_HIJACK_CFG_OFF = 0x6800000000000000ULL,
96
97 /**
98 * Offsets beyond this point are reserved for the supervisor (although that
99 * enforcement must be done by the supervisor driver itself).
100 */
101 NETIO_IPP_USER_MAX_OFF = 0x6FFFFFFFFFFFFFFFULL,
102
103 /** Register I/O memory. Write-only, takes a netio_ipp_address_t. */
104 NETIO_IPP_IOMEM_REGISTER_OFF = 0x7000000000000000ULL,
105
106 /** Unregister I/O memory. Write-only, takes a netio_ipp_address_t. */
107 NETIO_IPP_IOMEM_UNREGISTER_OFF = 0x7100000000000000ULL,
108
109 /* Offsets greater than 0x7FFFFFFF can't be used directly from Linux
110 * userspace code due to limitations in the pread/pwrite syscalls. */
111
112 /** Drain LIPP buffers. */
113 NETIO_IPP_DRAIN_OFF = 0xFA00000000000000ULL,
114
115 /** Supply a netio_ipp_address_t to be used as shared memory for the
116 * LEPP command queue. */
117 NETIO_EPP_SHM_OFF = 0xFB00000000000000ULL,
118
119 /* 0xFC... is currently unused. */
120
121 /** Stop IPP/EPP tiles. Write-only, takes a dummy argument. */
122 NETIO_IPP_STOP_SHIM_OFF = 0xFD00000000000000ULL,
123
124 /** Start IPP/EPP tiles. Write-only, takes a dummy argument. */
125 NETIO_IPP_START_SHIM_OFF = 0xFE00000000000000ULL,
126
127 /** Supply packet arena. Write-only, takes an array of
128 * netio_ipp_address_t values. */
129 NETIO_IPP_ADDRESS_OFF = 0xFF00000000000000ULL,
130} netio_hv_offset_t;
131
132/** Extract the base offset from an offset */
133#define NETIO_BASE_OFFSET(off) ((off) & 0xFF00000000000000ULL)
134/** Extract the local offset from an offset */
135#define NETIO_LOCAL_OFFSET(off) ((off) & 0x00FFFFFFFFFFFFFFULL)
136
137
138/**
139 * Get/set offset.
140 */
141typedef union
142{
143 struct
144 {
145 uint64_t addr:48; /**< Class-specific address */
146 unsigned int class:8; /**< Class (e.g., NETIO_PARAM) */
147 unsigned int opcode:8; /**< High 8 bits of NETIO_IPP_PARAM_OFF */
148 }
149 bits; /**< Bitfields */
150 uint64_t word; /**< Aggregated value to use as the offset */
151}
152__netio_getset_offset_t;
153
154/**
155 * Fast I/O index offsets (must be contiguous).
156 */
157typedef enum
158{
159 NETIO_FASTIO_ALLOCATE = 0, /**< Get empty packet buffer */
160 NETIO_FASTIO_FREE_BUFFER = 1, /**< Give buffer back to IPP */
161 NETIO_FASTIO_RETURN_CREDITS = 2, /**< Give credits to IPP */
162 NETIO_FASTIO_SEND_PKT_NOCK = 3, /**< Send a packet, no checksum */
163 NETIO_FASTIO_SEND_PKT_CK = 4, /**< Send a packet, with checksum */
164 NETIO_FASTIO_SEND_PKT_VEC = 5, /**< Send a vector of packets */
165 NETIO_FASTIO_SENDV_PKT = 6, /**< Sendv one packet */
166 NETIO_FASTIO_NUM_INDEX = 7, /**< Total number of fast I/O indices */
167} netio_fastio_index_t;
168
169/** 3-word return type for Fast I/O call. */
170typedef struct
171{
172 int err; /**< Error code. */
173 uint32_t val0; /**< Value. Meaning depends upon the specific call. */
174 uint32_t val1; /**< Value. Meaning depends upon the specific call. */
175} netio_fastio_rv3_t;
176
177/** 0-argument fast I/O call */
178int __netio_fastio0(uint32_t fastio_index);
179/** 1-argument fast I/O call */
180int __netio_fastio1(uint32_t fastio_index, uint32_t arg0);
181/** 3-argument fast I/O call, 2-word return value */
182netio_fastio_rv3_t __netio_fastio3_rv3(uint32_t fastio_index, uint32_t arg0,
183 uint32_t arg1, uint32_t arg2);
184/** 4-argument fast I/O call */
185int __netio_fastio4(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
186 uint32_t arg2, uint32_t arg3);
187/** 6-argument fast I/O call */
188int __netio_fastio6(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
189 uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5);
190/** 9-argument fast I/O call */
191int __netio_fastio9(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
192 uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5,
193 uint32_t arg6, uint32_t arg7, uint32_t arg8);
194
195/** Allocate an empty packet.
196 * @param fastio_index Fast I/O index.
197 * @param size Size of the packet to allocate.
198 */
199#define __netio_fastio_allocate(fastio_index, size) \
200 __netio_fastio1((fastio_index) + NETIO_FASTIO_ALLOCATE, size)
201
202/** Free a buffer.
203 * @param fastio_index Fast I/O index.
204 * @param handle Handle for the packet to free.
205 */
206#define __netio_fastio_free_buffer(fastio_index, handle) \
207 __netio_fastio1((fastio_index) + NETIO_FASTIO_FREE_BUFFER, handle)
208
209/** Increment our receive credits.
210 * @param fastio_index Fast I/O index.
211 * @param credits Number of credits to add.
212 */
213#define __netio_fastio_return_credits(fastio_index, credits) \
214 __netio_fastio1((fastio_index) + NETIO_FASTIO_RETURN_CREDITS, credits)
215
216/** Send packet, no checksum.
217 * @param fastio_index Fast I/O index.
218 * @param ackflag Nonzero if we want an ack.
219 * @param size Size of the packet.
220 * @param va Virtual address of start of packet.
221 * @param handle Packet handle.
222 */
223#define __netio_fastio_send_pkt_nock(fastio_index, ackflag, size, va, handle) \
224 __netio_fastio4((fastio_index) + NETIO_FASTIO_SEND_PKT_NOCK, ackflag, \
225 size, va, handle)
226
227/** Send packet, calculate checksum.
228 * @param fastio_index Fast I/O index.
229 * @param ackflag Nonzero if we want an ack.
230 * @param size Size of the packet.
231 * @param va Virtual address of start of packet.
232 * @param handle Packet handle.
233 * @param csum0 Shim checksum header.
234 * @param csum1 Checksum seed.
235 */
236#define __netio_fastio_send_pkt_ck(fastio_index, ackflag, size, va, handle, \
237 csum0, csum1) \
238 __netio_fastio6((fastio_index) + NETIO_FASTIO_SEND_PKT_CK, ackflag, \
239 size, va, handle, csum0, csum1)
240
241
242/** Format for the "csum0" argument to the __netio_fastio_send routines
243 * and LEPP. Note that this is currently exactly identical to the
244 * ShimProtocolOffloadHeader.
245 */
246typedef union
247{
248 struct
249 {
250 unsigned int start_byte:7; /**< The first byte to be checksummed */
251 unsigned int count:14; /**< Number of bytes to be checksummed. */
252 unsigned int destination_byte:7; /**< The byte to write the checksum to. */
253 unsigned int reserved:4; /**< Reserved. */
254 } bits; /**< Decomposed method of access. */
255 unsigned int word; /**< To send out the IDN. */
256} __netio_checksum_header_t;
257
258
259/** Sendv packet with 1 or 2 segments.
260 * @param fastio_index Fast I/O index.
261 * @param flags Ack/csum/notify flags in low 3 bits; number of segments minus
262 * 1 in next 2 bits; expected checksum in high 16 bits.
263 * @param confno Confirmation number to request, if notify flag set.
264 * @param csum0 Checksum descriptor; if zero, no checksum.
265 * @param va_F Virtual address of first segment.
266 * @param va_L Virtual address of last segment, if 2 segments.
267 * @param len_F_L Length of first segment in low 16 bits; length of last
268 * segment, if 2 segments, in high 16 bits.
269 */
270#define __netio_fastio_sendv_pkt_1_2(fastio_index, flags, confno, csum0, \
271 va_F, va_L, len_F_L) \
272 __netio_fastio6((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \
273 csum0, va_F, va_L, len_F_L)
274
275/** Send packet on PCIe interface.
276 * @param fastio_index Fast I/O index.
277 * @param flags Ack/csum/notify flags in low 3 bits.
278 * @param confno Confirmation number to request, if notify flag set.
279 * @param csum0 Checksum descriptor; Hard wired 0, not needed for PCIe.
280 * @param va_F Virtual address of the packet buffer.
281 * @param va_L Virtual address of last segment, if 2 segments. Hard wired 0.
282 * @param len_F_L Length of the packet buffer in low 16 bits.
283 */
284#define __netio_fastio_send_pcie_pkt(fastio_index, flags, confno, csum0, \
285 va_F, va_L, len_F_L) \
286 __netio_fastio6((fastio_index) + PCIE_FASTIO_SENDV_PKT, flags, confno, \
287 csum0, va_F, va_L, len_F_L)
288
289/** Sendv packet with 3 or 4 segments.
290 * @param fastio_index Fast I/O index.
291 * @param flags Ack/csum/notify flags in low 3 bits; number of segments minus
292 * 1 in next 2 bits; expected checksum in high 16 bits.
293 * @param confno Confirmation number to request, if notify flag set.
294 * @param csum0 Checksum descriptor; if zero, no checksum.
295 * @param va_F Virtual address of first segment.
296 * @param va_L Virtual address of last segment (third segment if 3 segments,
297 * fourth segment if 4 segments).
298 * @param len_F_L Length of first segment in low 16 bits; length of last
299 * segment in high 16 bits.
300 * @param va_M0 Virtual address of "middle 0" segment; this segment is sent
301 * second when there are three segments, and third if there are four.
302 * @param va_M1 Virtual address of "middle 1" segment; this segment is sent
303 * second when there are four segments.
304 * @param len_M0_M1 Length of middle 0 segment in low 16 bits; length of middle
305 * 1 segment, if 4 segments, in high 16 bits.
306 */
307#define __netio_fastio_sendv_pkt_3_4(fastio_index, flags, confno, csum0, va_F, \
308 va_L, len_F_L, va_M0, va_M1, len_M0_M1) \
309 __netio_fastio9((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \
310 csum0, va_F, va_L, len_F_L, va_M0, va_M1, len_M0_M1)
311
312/** Send vector of packets.
313 * @param fastio_index Fast I/O index.
314 * @param seqno Number of packets transmitted so far on this interface;
315 * used to decide which packets should be acknowledged.
316 * @param nentries Number of entries in vector.
317 * @param va Virtual address of start of vector entry array.
318 * @return 3-word netio_fastio_rv3_t structure. The structure's err member
319 * is an error code, or zero if no error. The val0 member is the
320 * updated value of seqno; it has been incremented by 1 for each
321 * packet sent. That increment may be less than nentries if an
322 * error occured, or if some of the entries in the vector contain
323 * handles equal to NETIO_PKT_HANDLE_NONE. The val1 member is the
324 * updated value of nentries; it has been decremented by 1 for each
325 * vector entry processed. Again, that decrement may be less than
326 * nentries (leaving the returned value positive) if an error
327 * occurred.
328 */
329#define __netio_fastio_send_pkt_vec(fastio_index, seqno, nentries, va) \
330 __netio_fastio3_rv3((fastio_index) + NETIO_FASTIO_SEND_PKT_VEC, seqno, \
331 nentries, va)
332
333
334/** An egress DMA command for LEPP. */
335typedef struct
336{
337 /** Is this a TSO transfer?
338 *
339 * NOTE: This field is always 0, to distinguish it from
340 * lepp_tso_cmd_t. It must come first!
341 */
342 uint8_t tso : 1;
343
344 /** Unused padding bits. */
345 uint8_t _unused : 3;
346
347 /** Should this packet be sent directly from caches instead of DRAM,
348 * using hash-for-home to locate the packet data?
349 */
350 uint8_t hash_for_home : 1;
351
352 /** Should we compute a checksum? */
353 uint8_t compute_checksum : 1;
354
355 /** Is this the final buffer for this packet?
356 *
357 * A single packet can be split over several input buffers (a "gather"
358 * operation). This flag indicates that this is the last buffer
359 * in a packet.
360 */
361 uint8_t end_of_packet : 1;
362
363 /** Should LEPP advance 'comp_busy' when this DMA is fully finished? */
364 uint8_t send_completion : 1;
365
366 /** High bits of Client Physical Address of the start of the buffer
367 * to be egressed.
368 *
369 * NOTE: Only 6 bits are actually needed here, as CPAs are
370 * currently 38 bits. So two bits could be scavenged from this.
371 */
372 uint8_t cpa_hi;
373
374 /** The number of bytes to be egressed. */
375 uint16_t length;
376
377 /** Low 32 bits of Client Physical Address of the start of the buffer
378 * to be egressed.
379 */
380 uint32_t cpa_lo;
381
382 /** Checksum information (only used if 'compute_checksum'). */
383 __netio_checksum_header_t checksum_data;
384
385} lepp_cmd_t;
386
387
388/** A chunk of physical memory for a TSO egress. */
389typedef struct
390{
391 /** The low bits of the CPA. */
392 uint32_t cpa_lo;
393 /** The high bits of the CPA. */
394 uint16_t cpa_hi : 15;
395 /** Should this packet be sent directly from caches instead of DRAM,
396 * using hash-for-home to locate the packet data?
397 */
398 uint16_t hash_for_home : 1;
399 /** The length in bytes. */
400 uint16_t length;
401} lepp_frag_t;
402
403
404/** An LEPP command that handles TSO. */
405typedef struct
406{
407 /** Is this a TSO transfer?
408 *
409 * NOTE: This field is always 1, to distinguish it from
410 * lepp_cmd_t. It must come first!
411 */
412 uint8_t tso : 1;
413
414 /** Unused padding bits. */
415 uint8_t _unused : 7;
416
417 /** Size of the header[] array in bytes. It must be in the range
418 * [40, 127], which are the smallest header for a TCP packet over
419 * Ethernet and the maximum possible prepend size supported by
420 * hardware, respectively. Note that the array storage must be
421 * padded out to a multiple of four bytes so that the following
422 * LEPP command is aligned properly.
423 */
424 uint8_t header_size;
425
426 /** Byte offset of the IP header in header[]. */
427 uint8_t ip_offset;
428
429 /** Byte offset of the TCP header in header[]. */
430 uint8_t tcp_offset;
431
432 /** The number of bytes to use for the payload of each packet,
433 * except of course the last one, which may not have enough bytes.
434 * This means that each Ethernet packet except the last will have a
435 * size of header_size + payload_size.
436 */
437 uint16_t payload_size;
438
439 /** The length of the 'frags' array that follows this struct. */
440 uint16_t num_frags;
441
442 /** The actual frags. */
443 lepp_frag_t frags[0 /* Variable-sized; num_frags entries. */];
444
445 /*
446 * The packet header template logically follows frags[],
447 * but you can't declare that in C.
448 *
449 * uint32_t header[header_size_in_words_rounded_up];
450 */
451
452} lepp_tso_cmd_t;
453
454
455/** An LEPP completion ring entry. */
456typedef void* lepp_comp_t;
457
458
459/** Maximum number of frags for one TSO command. This is adapted from
460 * linux's "MAX_SKB_FRAGS", and presumably over-estimates by one, for
461 * our page size of exactly 65536. We add one for a "body" fragment.
462 */
463#define LEPP_MAX_FRAGS (65536 / HV_PAGE_SIZE_SMALL + 2 + 1)
464
465/** Total number of bytes needed for an lepp_tso_cmd_t. */
466#define LEPP_TSO_CMD_SIZE(num_frags, header_size) \
467 (sizeof(lepp_tso_cmd_t) + \
468 (num_frags) * sizeof(lepp_frag_t) + \
469 (((header_size) + 3) & -4))
470
471/** The size of the lepp "cmd" queue. */
472#define LEPP_CMD_QUEUE_BYTES \
473 (((CHIP_L2_CACHE_SIZE() - 2 * CHIP_L2_LINE_SIZE()) / \
474 (sizeof(lepp_cmd_t) + sizeof(lepp_comp_t))) * sizeof(lepp_cmd_t))
475
476/** The largest possible command that can go in lepp_queue_t::cmds[]. */
477#define LEPP_MAX_CMD_SIZE LEPP_TSO_CMD_SIZE(LEPP_MAX_FRAGS, 128)
478
479/** The largest possible value of lepp_queue_t::cmd_{head, tail} (inclusive).
480 */
481#define LEPP_CMD_LIMIT \
482 (LEPP_CMD_QUEUE_BYTES - LEPP_MAX_CMD_SIZE)
483
484/** The maximum number of completions in an LEPP queue. */
485#define LEPP_COMP_QUEUE_SIZE \
486 ((LEPP_CMD_LIMIT + sizeof(lepp_cmd_t) - 1) / sizeof(lepp_cmd_t))
487
488/** Increment an index modulo the queue size. */
489#define LEPP_QINC(var) \
490 (var = __insn_mnz(var - (LEPP_COMP_QUEUE_SIZE - 1), var + 1))
491
492/** A queue used to convey egress commands from the client to LEPP. */
493typedef struct
494{
495 /** Index of first completion not yet processed by user code.
496 * If this is equal to comp_busy, there are no such completions.
497 *
498 * NOTE: This is only read/written by the user.
499 */
500 unsigned int comp_head;
501
502 /** Index of first completion record not yet completed.
503 * If this is equal to comp_tail, there are no such completions.
504 * This index gets advanced (modulo LEPP_QUEUE_SIZE) whenever
505 * a command with the 'completion' bit set is finished.
506 *
507 * NOTE: This is only written by LEPP, only read by the user.
508 */
509 volatile unsigned int comp_busy;
510
511 /** Index of the first empty slot in the completion ring.
512 * Entries from this up to but not including comp_head (in ring order)
513 * can be filled in with completion data.
514 *
515 * NOTE: This is only read/written by the user.
516 */
517 unsigned int comp_tail;
518
519 /** Byte index of first command enqueued for LEPP but not yet processed.
520 *
521 * This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.
522 *
523 * NOTE: LEPP advances this counter as soon as it no longer needs
524 * the cmds[] storage for this entry, but the transfer is not actually
525 * complete (i.e. the buffer pointed to by the command is no longer
526 * needed) until comp_busy advances.
527 *
528 * If this is equal to cmd_tail, the ring is empty.
529 *
530 * NOTE: This is only written by LEPP, only read by the user.
531 */
532 volatile unsigned int cmd_head;
533
534 /** Byte index of first empty slot in the command ring. This field can
535 * be incremented up to but not equal to cmd_head (because that would
536 * mean the ring is empty).
537 *
538 * This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.
539 *
540 * NOTE: This is read/written by the user, only read by LEPP.
541 */
542 volatile unsigned int cmd_tail;
543
544 /** A ring of variable-sized egress DMA commands.
545 *
546 * NOTE: Only written by the user, only read by LEPP.
547 */
548 char cmds[LEPP_CMD_QUEUE_BYTES]
549 __attribute__((aligned(CHIP_L2_LINE_SIZE())));
550
551 /** A ring of user completion data.
552 * NOTE: Only read/written by the user.
553 */
554 lepp_comp_t comps[LEPP_COMP_QUEUE_SIZE]
555 __attribute__((aligned(CHIP_L2_LINE_SIZE())));
556} lepp_queue_t;
557
558
559/** An internal helper function for determining the number of entries
560 * available in a ring buffer, given that there is one sentinel.
561 */
562static inline unsigned int
563_lepp_num_free_slots(unsigned int head, unsigned int tail)
564{
565 /*
566 * One entry is reserved for use as a sentinel, to distinguish
567 * "empty" from "full". So we compute
568 * (head - tail - 1) % LEPP_QUEUE_SIZE, but without using a slow % operation.
569 */
570 return (head - tail - 1) + ((head <= tail) ? LEPP_COMP_QUEUE_SIZE : 0);
571}
572
573
574/** Returns how many new comp entries can be enqueued. */
575static inline unsigned int
576lepp_num_free_comp_slots(const lepp_queue_t* q)
577{
578 return _lepp_num_free_slots(q->comp_head, q->comp_tail);
579}
580
581static inline int
582lepp_qsub(int v1, int v2)
583{
584 int delta = v1 - v2;
585 return delta + ((delta >> 31) & LEPP_COMP_QUEUE_SIZE);
586}
587
588
589/** FIXME: Check this from linux, via a new "pwrite()" call. */
590#define LIPP_VERSION 1
591
592
593/** We use exactly two bytes of alignment padding. */
594#define LIPP_PACKET_PADDING 2
595
596/** The minimum size of a "small" buffer (including the padding). */
597#define LIPP_SMALL_PACKET_SIZE 128
598
599/*
600 * NOTE: The following two values should total to less than around
601 * 13582, to keep the total size used for "lipp_state_t" below 64K.
602 */
603
604/** The maximum number of "small" buffers.
605 * This is enough for 53 network cpus with 128 credits. Note that
606 * if these are exhausted, we will fall back to using large buffers.
607 */
608#define LIPP_SMALL_BUFFERS 6785
609
610/** The maximum number of "large" buffers.
611 * This is enough for 53 network cpus with 128 credits.
612 */
613#define LIPP_LARGE_BUFFERS 6785
614
615#endif /* __DRV_XGBE_INTF_H__ */
diff --git a/arch/tile/include/hv/netio_errors.h b/arch/tile/include/hv/netio_errors.h
new file mode 100644
index 000000000000..e1591bff61b5
--- /dev/null
+++ b/arch/tile/include/hv/netio_errors.h
@@ -0,0 +1,122 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * Error codes returned from NetIO routines.
17 */
18
19#ifndef __NETIO_ERRORS_H__
20#define __NETIO_ERRORS_H__
21
22/**
23 * @addtogroup error
24 *
25 * @brief The error codes returned by NetIO functions.
26 *
27 * NetIO functions return 0 (defined as ::NETIO_NO_ERROR) on success, and
28 * a negative value if an error occurs.
29 *
30 * In cases where a NetIO function failed due to a error reported by
31 * system libraries, the error code will be the negation of the
32 * system errno at the time of failure. The @ref netio_strerror()
33 * function will deliver error strings for both NetIO and system error
34 * codes.
35 *
36 * @{
37 */
38
39/** The set of all NetIO errors. */
40typedef enum
41{
42 /** Operation successfully completed. */
43 NETIO_NO_ERROR = 0,
44
45 /** A packet was successfully retrieved from an input queue. */
46 NETIO_PKT = 0,
47
48 /** Largest NetIO error number. */
49 NETIO_ERR_MAX = -701,
50
51 /** The tile is not registered with the IPP. */
52 NETIO_NOT_REGISTERED = -701,
53
54 /** No packet was available to retrieve from the input queue. */
55 NETIO_NOPKT = -702,
56
57 /** The requested function is not implemented. */
58 NETIO_NOT_IMPLEMENTED = -703,
59
60 /** On a registration operation, the target queue already has the maximum
61 * number of tiles registered for it, and no more may be added. On a
62 * packet send operation, the output queue is full and nothing more can
63 * be queued until some of the queued packets are actually transmitted. */
64 NETIO_QUEUE_FULL = -704,
65
66 /** The calling process or thread is not bound to exactly one CPU. */
67 NETIO_BAD_AFFINITY = -705,
68
69 /** Cannot allocate memory on requested controllers. */
70 NETIO_CANNOT_HOME = -706,
71
72 /** On a registration operation, the IPP specified is not configured
73 * to support the options requested; for instance, the application
74 * wants a specific type of tagged headers which the configured IPP
75 * doesn't support. Or, the supplied configuration information is
76 * not self-consistent, or is out of range; for instance, specifying
77 * both NETIO_RECV and NETIO_NO_RECV, or asking for more than
78 * NETIO_MAX_SEND_BUFFERS to be preallocated. On a VLAN or bucket
79 * configure operation, the number of items, or the base item, was
80 * out of range.
81 */
82 NETIO_BAD_CONFIG = -707,
83
84 /** Too many tiles have registered to transmit packets. */
85 NETIO_TOOMANY_XMIT = -708,
86
87 /** Packet transmission was attempted on a queue which was registered
88 with transmit disabled. */
89 NETIO_UNREG_XMIT = -709,
90
91 /** This tile is already registered with the IPP. */
92 NETIO_ALREADY_REGISTERED = -710,
93
94 /** The Ethernet link is down. The application should try again later. */
95 NETIO_LINK_DOWN = -711,
96
97 /** An invalid memory buffer has been specified. This may be an unmapped
98 * virtual address, or one which does not meet alignment requirements.
99 * For netio_input_register(), this error may be returned when multiple
100 * processes specify different memory regions to be used for NetIO
101 * buffers. That can happen if these processes specify explicit memory
102 * regions with the ::NETIO_FIXED_BUFFER_VA flag, or if tmc_cmem_init()
103 * has not been called by a common ancestor of the processes.
104 */
105 NETIO_FAULT = -712,
106
107 /** Cannot combine user-managed shared memory and cache coherence. */
108 NETIO_BAD_CACHE_CONFIG = -713,
109
110 /** Smallest NetIO error number. */
111 NETIO_ERR_MIN = -713,
112
113#ifndef __DOXYGEN__
114 /** Used internally to mean that no response is needed; never returned to
115 * an application. */
116 NETIO_NO_RESPONSE = 1
117#endif
118} netio_error_t;
119
120/** @} */
121
122#endif /* __NETIO_ERRORS_H__ */
diff --git a/arch/tile/include/hv/netio_intf.h b/arch/tile/include/hv/netio_intf.h
new file mode 100644
index 000000000000..8d20972aba2c
--- /dev/null
+++ b/arch/tile/include/hv/netio_intf.h
@@ -0,0 +1,2975 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * NetIO interface structures and macros.
17 */
18
19#ifndef __NETIO_INTF_H__
20#define __NETIO_INTF_H__
21
22#include <hv/netio_errors.h>
23
24#ifdef __KERNEL__
25#include <linux/types.h>
26#else
27#include <stdint.h>
28#endif
29
30#if !defined(__HV__) && !defined(__BOGUX__) && !defined(__KERNEL__)
31#include <assert.h>
32#define netio_assert assert /**< Enable assertions from macros */
33#else
34#define netio_assert(...) ((void)(0)) /**< Disable assertions from macros */
35#endif
36
37/*
38 * If none of these symbols are defined, we're building libnetio in an
39 * environment where we have pthreads, so we'll enable locking.
40 */
41#if !defined(__HV__) && !defined(__BOGUX__) && !defined(__KERNEL__) && \
42 !defined(__NEWLIB__)
43#define _NETIO_PTHREAD /**< Include a mutex in netio_queue_t below */
44
45/*
46 * If NETIO_UNLOCKED is defined, we don't do use per-cpu locks on
47 * per-packet NetIO operations. We still do pthread locking on things
48 * like netio_input_register, though. This is used for building
49 * libnetio_unlocked.
50 */
51#ifndef NETIO_UNLOCKED
52
53/* Avoid PLT overhead by using our own inlined per-cpu lock. */
54#include <sched.h>
55typedef int _netio_percpu_mutex_t;
56
57static __inline int
58_netio_percpu_mutex_init(_netio_percpu_mutex_t* lock)
59{
60 *lock = 0;
61 return 0;
62}
63
64static __inline int
65_netio_percpu_mutex_lock(_netio_percpu_mutex_t* lock)
66{
67 while (__builtin_expect(__insn_tns(lock), 0))
68 sched_yield();
69 return 0;
70}
71
72static __inline int
73_netio_percpu_mutex_unlock(_netio_percpu_mutex_t* lock)
74{
75 *lock = 0;
76 return 0;
77}
78
79#else /* NETIO_UNLOCKED */
80
81/* Don't do any locking for per-packet NetIO operations. */
82typedef int _netio_percpu_mutex_t;
83#define _netio_percpu_mutex_init(L)
84#define _netio_percpu_mutex_lock(L)
85#define _netio_percpu_mutex_unlock(L)
86
87#endif /* NETIO_UNLOCKED */
88#endif /* !__HV__, !__BOGUX, !__KERNEL__, !__NEWLIB__ */
89
90/** How many tiles can register for a given queue.
91 * @ingroup setup */
92#define NETIO_MAX_TILES_PER_QUEUE 64
93
94
95/** Largest permissible queue identifier.
96 * @ingroup setup */
97#define NETIO_MAX_QUEUE_ID 255
98
99
100#ifndef __DOXYGEN__
101
102/* Metadata packet checksum/ethertype flags. */
103
104/** The L4 checksum has not been calculated. */
105#define _NETIO_PKT_NO_L4_CSUM_SHIFT 0
106#define _NETIO_PKT_NO_L4_CSUM_RMASK 1
107#define _NETIO_PKT_NO_L4_CSUM_MASK \
108 (_NETIO_PKT_NO_L4_CSUM_RMASK << _NETIO_PKT_NO_L4_CSUM_SHIFT)
109
110/** The L3 checksum has not been calculated. */
111#define _NETIO_PKT_NO_L3_CSUM_SHIFT 1
112#define _NETIO_PKT_NO_L3_CSUM_RMASK 1
113#define _NETIO_PKT_NO_L3_CSUM_MASK \
114 (_NETIO_PKT_NO_L3_CSUM_RMASK << _NETIO_PKT_NO_L3_CSUM_SHIFT)
115
116/** The L3 checksum is incorrect (or perhaps has not been calculated). */
117#define _NETIO_PKT_BAD_L3_CSUM_SHIFT 2
118#define _NETIO_PKT_BAD_L3_CSUM_RMASK 1
119#define _NETIO_PKT_BAD_L3_CSUM_MASK \
120 (_NETIO_PKT_BAD_L3_CSUM_RMASK << _NETIO_PKT_BAD_L3_CSUM_SHIFT)
121
122/** The Ethernet packet type is unrecognized. */
123#define _NETIO_PKT_TYPE_UNRECOGNIZED_SHIFT 3
124#define _NETIO_PKT_TYPE_UNRECOGNIZED_RMASK 1
125#define _NETIO_PKT_TYPE_UNRECOGNIZED_MASK \
126 (_NETIO_PKT_TYPE_UNRECOGNIZED_RMASK << \
127 _NETIO_PKT_TYPE_UNRECOGNIZED_SHIFT)
128
129/* Metadata packet type flags. */
130
131/** Where the packet type bits are; this field is the index into
132 * _netio_pkt_info. */
133#define _NETIO_PKT_TYPE_SHIFT 4
134#define _NETIO_PKT_TYPE_RMASK 0x3F
135
136/** How many VLAN tags the packet has, and, if we have two, which one we
137 * actually grouped on. A VLAN within a proprietary (Marvell or Broadcom)
138 * tag is counted here. */
139#define _NETIO_PKT_VLAN_SHIFT 4
140#define _NETIO_PKT_VLAN_RMASK 0x3
141#define _NETIO_PKT_VLAN_MASK \
142 (_NETIO_PKT_VLAN_RMASK << _NETIO_PKT_VLAN_SHIFT)
143#define _NETIO_PKT_VLAN_NONE 0 /* No VLAN tag. */
144#define _NETIO_PKT_VLAN_ONE 1 /* One VLAN tag. */
145#define _NETIO_PKT_VLAN_TWO_OUTER 2 /* Two VLAN tags, outer one used. */
146#define _NETIO_PKT_VLAN_TWO_INNER 3 /* Two VLAN tags, inner one used. */
147
148/** Which proprietary tags the packet has. */
149#define _NETIO_PKT_TAG_SHIFT 6
150#define _NETIO_PKT_TAG_RMASK 0x3
151#define _NETIO_PKT_TAG_MASK \
152 (_NETIO_PKT_TAG_RMASK << _NETIO_PKT_TAG_SHIFT)
153#define _NETIO_PKT_TAG_NONE 0 /* No proprietary tags. */
154#define _NETIO_PKT_TAG_MRVL 1 /* Marvell HyperG.Stack tags. */
155#define _NETIO_PKT_TAG_MRVL_EXT 2 /* HyperG.Stack extended tags. */
156#define _NETIO_PKT_TAG_BRCM 3 /* Broadcom HiGig tags. */
157
158/** Whether a packet has an LLC + SNAP header. */
159#define _NETIO_PKT_SNAP_SHIFT 8
160#define _NETIO_PKT_SNAP_RMASK 0x1
161#define _NETIO_PKT_SNAP_MASK \
162 (_NETIO_PKT_SNAP_RMASK << _NETIO_PKT_SNAP_SHIFT)
163
164/* NOTE: Bits 9 and 10 are unused. */
165
166/** Length of any custom data before the L2 header, in words. */
167#define _NETIO_PKT_CUSTOM_LEN_SHIFT 11
168#define _NETIO_PKT_CUSTOM_LEN_RMASK 0x1F
169#define _NETIO_PKT_CUSTOM_LEN_MASK \
170 (_NETIO_PKT_CUSTOM_LEN_RMASK << _NETIO_PKT_CUSTOM_LEN_SHIFT)
171
172/** The L4 checksum is incorrect (or perhaps has not been calculated). */
173#define _NETIO_PKT_BAD_L4_CSUM_SHIFT 16
174#define _NETIO_PKT_BAD_L4_CSUM_RMASK 0x1
175#define _NETIO_PKT_BAD_L4_CSUM_MASK \
176 (_NETIO_PKT_BAD_L4_CSUM_RMASK << _NETIO_PKT_BAD_L4_CSUM_SHIFT)
177
178/** Length of the L2 header, in words. */
179#define _NETIO_PKT_L2_LEN_SHIFT 17
180#define _NETIO_PKT_L2_LEN_RMASK 0x1F
181#define _NETIO_PKT_L2_LEN_MASK \
182 (_NETIO_PKT_L2_LEN_RMASK << _NETIO_PKT_L2_LEN_SHIFT)
183
184
185/* Flags in minimal packet metadata. */
186
187/** We need an eDMA checksum on this packet. */
188#define _NETIO_PKT_NEED_EDMA_CSUM_SHIFT 0
189#define _NETIO_PKT_NEED_EDMA_CSUM_RMASK 1
190#define _NETIO_PKT_NEED_EDMA_CSUM_MASK \
191 (_NETIO_PKT_NEED_EDMA_CSUM_RMASK << _NETIO_PKT_NEED_EDMA_CSUM_SHIFT)
192
193/* Data within the packet information table. */
194
195/* Note that, for efficiency, code which uses these fields assumes that none
196 * of the shift values below are zero. See uses below for an explanation. */
197
198/** Offset within the L2 header of the innermost ethertype (in halfwords). */
199#define _NETIO_PKT_INFO_ETYPE_SHIFT 6
200#define _NETIO_PKT_INFO_ETYPE_RMASK 0x1F
201
202/** Offset within the L2 header of the VLAN tag (in halfwords). */
203#define _NETIO_PKT_INFO_VLAN_SHIFT 11
204#define _NETIO_PKT_INFO_VLAN_RMASK 0x1F
205
206#endif
207
208
209/** The size of a memory buffer representing a small packet.
210 * @ingroup egress */
211#define SMALL_PACKET_SIZE 256
212
213/** The size of a memory buffer representing a large packet.
214 * @ingroup egress */
215#define LARGE_PACKET_SIZE 2048
216
217/** The size of a memory buffer representing a jumbo packet.
218 * @ingroup egress */
219#define JUMBO_PACKET_SIZE (12 * 1024)
220
221
222/* Common ethertypes.
223 * @ingroup ingress */
224/** @{ */
225/** The ethertype of IPv4. */
226#define ETHERTYPE_IPv4 (0x0800)
227/** The ethertype of ARP. */
228#define ETHERTYPE_ARP (0x0806)
229/** The ethertype of VLANs. */
230#define ETHERTYPE_VLAN (0x8100)
231/** The ethertype of a Q-in-Q header. */
232#define ETHERTYPE_Q_IN_Q (0x9100)
233/** The ethertype of IPv6. */
234#define ETHERTYPE_IPv6 (0x86DD)
235/** The ethertype of MPLS. */
236#define ETHERTYPE_MPLS (0x8847)
237/** @} */
238
239
240/** The possible return values of NETIO_PKT_STATUS.
241 * @ingroup ingress
242 */
243typedef enum
244{
245 /** No problems were detected with this packet. */
246 NETIO_PKT_STATUS_OK,
247 /** The packet is undersized; this is expected behavior if the packet's
248 * ethertype is unrecognized, but otherwise the packet is likely corrupt. */
249 NETIO_PKT_STATUS_UNDERSIZE,
250 /** The packet is oversized and some trailing bytes have been discarded.
251 This is expected behavior for short packets, since it's impossible to
252 precisely determine the amount of padding which may have been added to
253 them to make them meet the minimum Ethernet packet size. */
254 NETIO_PKT_STATUS_OVERSIZE,
255 /** The packet was judged to be corrupt by hardware (for instance, it had
256 a bad CRC, or part of it was discarded due to lack of buffer space in
257 the I/O shim) and should be discarded. */
258 NETIO_PKT_STATUS_BAD
259} netio_pkt_status_t;
260
261
262/** Log2 of how many buckets we have. */
263#define NETIO_LOG2_NUM_BUCKETS (10)
264
265/** How many buckets we have.
266 * @ingroup ingress */
267#define NETIO_NUM_BUCKETS (1 << NETIO_LOG2_NUM_BUCKETS)
268
269
270/**
271 * @brief A group-to-bucket identifier.
272 *
273 * @ingroup setup
274 *
275 * This tells us what to do with a given group.
276 */
277typedef union {
278 /** The header broken down into bits. */
279 struct {
280 /** Whether we should balance on L4, if available */
281 unsigned int __balance_on_l4:1;
282 /** Whether we should balance on L3, if available */
283 unsigned int __balance_on_l3:1;
284 /** Whether we should balance on L2, if available */
285 unsigned int __balance_on_l2:1;
286 /** Reserved for future use */
287 unsigned int __reserved:1;
288 /** The base bucket to use to send traffic */
289 unsigned int __bucket_base:NETIO_LOG2_NUM_BUCKETS;
290 /** The mask to apply to the balancing value. This must be one less
291 * than a power of two, e.g. 0x3 or 0xFF.
292 */
293 unsigned int __bucket_mask:NETIO_LOG2_NUM_BUCKETS;
294 /** Pad to 32 bits */
295 unsigned int __padding:(32 - 4 - 2 * NETIO_LOG2_NUM_BUCKETS);
296 } bits;
297 /** To send out the IDN. */
298 unsigned int word;
299}
300netio_group_t;
301
302
303/**
304 * @brief A VLAN-to-bucket identifier.
305 *
306 * @ingroup setup
307 *
308 * This tells us what to do with a given VLAN.
309 */
310typedef netio_group_t netio_vlan_t;
311
312
313/**
314 * A bucket-to-queue mapping.
315 * @ingroup setup
316 */
317typedef unsigned char netio_bucket_t;
318
319
320/**
321 * A packet size can always fit in a netio_size_t.
322 * @ingroup setup
323 */
324typedef unsigned int netio_size_t;
325
326
327/**
328 * @brief Ethernet standard (ingress) packet metadata.
329 *
330 * @ingroup ingress
331 *
332 * This is additional data associated with each packet.
333 * This structure is opaque and accessed through the @ref ingress.
334 *
335 * Also, the buffer population operation currently assumes that standard
336 * metadata is at least as large as minimal metadata, and will need to be
337 * modified if that is no longer the case.
338 */
339typedef struct
340{
341#ifdef __DOXYGEN__
342 /** This structure is opaque. */
343 unsigned char opaque[24];
344#else
345 /** The overall ordinal of the packet */
346 unsigned int __packet_ordinal;
347 /** The ordinal of the packet within the group */
348 unsigned int __group_ordinal;
349 /** The best flow hash IPP could compute. */
350 unsigned int __flow_hash;
351 /** Flags pertaining to checksum calculation, packet type, etc. */
352 unsigned int __flags;
353 /** The first word of "user data". */
354 unsigned int __user_data_0;
355 /** The second word of "user data". */
356 unsigned int __user_data_1;
357#endif
358}
359netio_pkt_metadata_t;
360
361
362/** To ensure that the L3 header is aligned mod 4, the L2 header should be
363 * aligned mod 4 plus 2, since every supported L2 header is 4n + 2 bytes
364 * long. The standard way to do this is to simply add 2 bytes of padding
365 * before the L2 header.
366 */
367#define NETIO_PACKET_PADDING 2
368
369
370
371/**
372 * @brief Ethernet minimal (egress) packet metadata.
373 *
374 * @ingroup egress
375 *
376 * This structure represents information about packets which have
377 * been processed by @ref netio_populate_buffer() or
378 * @ref netio_populate_prepend_buffer(). This structure is opaque
379 * and accessed through the @ref egress.
380 *
381 * @internal This structure is actually copied into the memory used by
382 * standard metadata, which is assumed to be large enough.
383 */
384typedef struct
385{
386#ifdef __DOXYGEN__
387 /** This structure is opaque. */
388 unsigned char opaque[14];
389#else
390 /** The offset of the L2 header from the start of the packet data. */
391 unsigned short l2_offset;
392 /** The offset of the L3 header from the start of the packet data. */
393 unsigned short l3_offset;
394 /** Where to write the checksum. */
395 unsigned char csum_location;
396 /** Where to start checksumming from. */
397 unsigned char csum_start;
398 /** Flags pertaining to checksum calculation etc. */
399 unsigned short flags;
400 /** The L2 length of the packet. */
401 unsigned short l2_length;
402 /** The checksum with which to seed the checksum generator. */
403 unsigned short csum_seed;
404 /** How much to checksum. */
405 unsigned short csum_length;
406#endif
407}
408netio_pkt_minimal_metadata_t;
409
410
411#ifndef __DOXYGEN__
412
413/**
414 * @brief An I/O notification header.
415 *
416 * This is the first word of data received from an I/O shim in a notification
417 * packet. It contains framing and status information.
418 */
419typedef union
420{
421 unsigned int word; /**< The whole word. */
422 /** The various fields. */
423 struct
424 {
425 unsigned int __channel:7; /**< Resource channel. */
426 unsigned int __type:4; /**< Type. */
427 unsigned int __ack:1; /**< Whether an acknowledgement is needed. */
428 unsigned int __reserved:1; /**< Reserved. */
429 unsigned int __protocol:1; /**< A protocol-specific word is added. */
430 unsigned int __status:2; /**< Status of the transfer. */
431 unsigned int __framing:2; /**< Framing of the transfer. */
432 unsigned int __transfer_size:14; /**< Transfer size in bytes (total). */
433 } bits;
434}
435__netio_pkt_notif_t;
436
437
438/**
439 * Returns the base address of the packet.
440 */
441#define _NETIO_PKT_HANDLE_BASE(p) \
442 ((unsigned char*)((p).word & 0xFFFFFFC0))
443
444/**
445 * Returns the base address of the packet.
446 */
447#define _NETIO_PKT_BASE(p) \
448 _NETIO_PKT_HANDLE_BASE(p->__packet)
449
450/**
451 * @brief An I/O notification packet (second word)
452 *
453 * This is the second word of data received from an I/O shim in a notification
454 * packet. This is the virtual address of the packet buffer, plus some flag
455 * bits. (The virtual address of the packet is always 256-byte aligned so we
456 * have room for 8 bits' worth of flags in the low 8 bits.)
457 *
458 * @internal
459 * NOTE: The low two bits must contain "__queue", so the "packet size"
460 * (SIZE_SMALL, SIZE_LARGE, or SIZE_JUMBO) can be determined quickly.
461 *
462 * If __addr or __offset are moved, _NETIO_PKT_BASE
463 * (defined right below this) must be changed.
464 */
465typedef union
466{
467 unsigned int word; /**< The whole word. */
468 /** The various fields. */
469 struct
470 {
471 /** Which queue the packet will be returned to once it is sent back to
472 the IPP. This is one of the SIZE_xxx values. */
473 unsigned int __queue:2;
474
475 /** The IPP handle of the sending IPP. */
476 unsigned int __ipp_handle:2;
477
478 /** Reserved for future use. */
479 unsigned int __reserved:1;
480
481 /** If 1, this packet has minimal (egress) metadata; otherwise, it
482 has standard (ingress) metadata. */
483 unsigned int __minimal:1;
484
485 /** Offset of the metadata within the packet. This value is multiplied
486 * by 64 and added to the base packet address to get the metadata
487 * address. Note that this field is aligned within the word such that
488 * you can easily extract the metadata address with a 26-bit mask. */
489 unsigned int __offset:2;
490
491 /** The top 24 bits of the packet's virtual address. */
492 unsigned int __addr:24;
493 } bits;
494}
495__netio_pkt_handle_t;
496
497#endif /* !__DOXYGEN__ */
498
499
500/**
501 * @brief A handle for an I/O packet's storage.
502 * @ingroup ingress
503 *
504 * netio_pkt_handle_t encodes the concept of a ::netio_pkt_t with its
505 * packet metadata removed. It is a much smaller type that exists to
506 * facilitate applications where the full ::netio_pkt_t type is too
507 * large, such as those that cache enormous numbers of packets or wish
508 * to transmit packet descriptors over the UDN.
509 *
510 * Because there is no metadata, most ::netio_pkt_t operations cannot be
511 * performed on a netio_pkt_handle_t. It supports only
512 * netio_free_handle() (to free the buffer) and
513 * NETIO_PKT_CUSTOM_DATA_H() (to access a pointer to its contents).
514 * The application must acquire any additional metadata it wants from the
515 * original ::netio_pkt_t and record it separately.
516 *
517 * A netio_pkt_handle_t can be extracted from a ::netio_pkt_t by calling
518 * NETIO_PKT_HANDLE(). An invalid handle (analogous to NULL) can be
519 * created by assigning the value ::NETIO_PKT_HANDLE_NONE. A handle can
520 * be tested for validity with NETIO_PKT_HANDLE_IS_VALID().
521 */
522typedef struct
523{
524 unsigned int word; /**< Opaque bits. */
525} netio_pkt_handle_t;
526
527/**
528 * @brief A packet descriptor.
529 *
530 * @ingroup ingress
531 * @ingroup egress
532 *
533 * This data structure represents a packet. The structure is manipulated
534 * through the @ref ingress and the @ref egress.
535 *
536 * While the contents of a netio_pkt_t are opaque, the structure itself is
537 * portable. This means that it may be shared between all tiles which have
538 * done a netio_input_register() call for the interface on which the pkt_t
539 * was initially received (via netio_get_packet()) or retrieved (via
540 * netio_get_buffer()). The contents of a netio_pkt_t can be transmitted to
541 * another tile via shared memory, or via a UDN message, or by other means.
542 * The destination tile may then use the pkt_t as if it had originally been
543 * received locally; it may read or write the packet's data, read its
544 * metadata, free the packet, send the packet, transfer the netio_pkt_t to
545 * yet another tile, and so forth.
546 *
547 * Once a netio_pkt_t has been transferred to a second tile, the first tile
548 * should not reference the original copy; in particular, if more than one
549 * tile frees or sends the same netio_pkt_t, the IPP's packet free lists will
550 * become corrupted. Note also that each tile which reads or modifies
551 * packet data must obey the memory coherency rules outlined in @ref input.
552 */
553typedef struct
554{
555#ifdef __DOXYGEN__
556 /** This structure is opaque. */
557 unsigned char opaque[32];
558#else
559 /** For an ingress packet (one with standard metadata), this is the
560 * notification header we got from the I/O shim. For an egress packet
561 * (one with minimal metadata), this word is zero if the packet has not
562 * been populated, and nonzero if it has. */
563 __netio_pkt_notif_t __notif_header;
564
565 /** Virtual address of the packet buffer, plus state flags. */
566 __netio_pkt_handle_t __packet;
567
568 /** Metadata associated with the packet. */
569 netio_pkt_metadata_t __metadata;
570#endif
571}
572netio_pkt_t;
573
574
575#ifndef __DOXYGEN__
576
577#define __NETIO_PKT_NOTIF_HEADER(pkt) ((pkt)->__notif_header)
578#define __NETIO_PKT_IPP_HANDLE(pkt) ((pkt)->__packet.bits.__ipp_handle)
579#define __NETIO_PKT_QUEUE(pkt) ((pkt)->__packet.bits.__queue)
580#define __NETIO_PKT_NOTIF_HEADER_M(mda, pkt) ((pkt)->__notif_header)
581#define __NETIO_PKT_IPP_HANDLE_M(mda, pkt) ((pkt)->__packet.bits.__ipp_handle)
582#define __NETIO_PKT_MINIMAL(pkt) ((pkt)->__packet.bits.__minimal)
583#define __NETIO_PKT_QUEUE_M(mda, pkt) ((pkt)->__packet.bits.__queue)
584#define __NETIO_PKT_FLAGS_M(mda, pkt) ((mda)->__flags)
585
586/* Packet information table, used by the attribute access functions below. */
587extern const uint16_t _netio_pkt_info[];
588
589#endif /* __DOXYGEN__ */
590
591
592#ifndef __DOXYGEN__
593/* These macros are deprecated and will disappear in a future MDE release. */
594#define NETIO_PKT_GOOD_CHECKSUM(pkt) \
595 NETIO_PKT_L4_CSUM_CORRECT(pkt)
596#define NETIO_PKT_GOOD_CHECKSUM_M(mda, pkt) \
597 NETIO_PKT_L4_CSUM_CORRECT_M(mda, pkt)
598#endif /* __DOXYGEN__ */
599
600
601/* Packet attribute access functions. */
602
603/** Return a pointer to the metadata for a packet.
604 * @ingroup ingress
605 *
606 * Calling this function once and passing the result to other retrieval
607 * functions with a "_M" suffix usually improves performance. This
608 * function must be called on an 'ingress' packet (i.e. one retrieved
609 * by @ref netio_get_packet(), on which @ref netio_populate_buffer() or
610 * @ref netio_populate_prepend_buffer have not been called). Use of this
611 * function on an 'egress' packet will cause an assertion failure.
612 *
613 * @param[in] pkt Packet on which to operate.
614 * @return A pointer to the packet's standard metadata.
615 */
616static __inline netio_pkt_metadata_t*
617NETIO_PKT_METADATA(netio_pkt_t* pkt)
618{
619 netio_assert(!pkt->__packet.bits.__minimal);
620 return &pkt->__metadata;
621}
622
623
624/** Return a pointer to the minimal metadata for a packet.
625 * @ingroup egress
626 *
627 * Calling this function once and passing the result to other retrieval
628 * functions with a "_MM" suffix usually improves performance. This
629 * function must be called on an 'egress' packet (i.e. one on which
630 * @ref netio_populate_buffer() or @ref netio_populate_prepend_buffer()
631 * have been called, or one retrieved by @ref netio_get_buffer()). Use of
632 * this function on an 'ingress' packet will cause an assertion failure.
633 *
634 * @param[in] pkt Packet on which to operate.
635 * @return A pointer to the packet's standard metadata.
636 */
637static __inline netio_pkt_minimal_metadata_t*
638NETIO_PKT_MINIMAL_METADATA(netio_pkt_t* pkt)
639{
640 netio_assert(pkt->__packet.bits.__minimal);
641 return (netio_pkt_minimal_metadata_t*) &pkt->__metadata;
642}
643
644
645/** Determine whether a packet has 'minimal' metadata.
646 * @ingroup pktfuncs
647 *
648 * This function will return nonzero if the packet is an 'egress'
649 * packet (i.e. one on which @ref netio_populate_buffer() or
650 * @ref netio_populate_prepend_buffer() have been called, or one
651 * retrieved by @ref netio_get_buffer()), and zero if the packet
652 * is an 'ingress' packet (i.e. one retrieved by @ref netio_get_packet(),
653 * which has not been converted into an 'egress' packet).
654 *
655 * @param[in] pkt Packet on which to operate.
656 * @return Nonzero if the packet has minimal metadata.
657 */
658static __inline unsigned int
659NETIO_PKT_IS_MINIMAL(netio_pkt_t* pkt)
660{
661 return pkt->__packet.bits.__minimal;
662}
663
664
665/** Return a handle for a packet's storage.
666 * @ingroup pktfuncs
667 *
668 * @param[in] pkt Packet on which to operate.
669 * @return A handle for the packet's storage.
670 */
671static __inline netio_pkt_handle_t
672NETIO_PKT_HANDLE(netio_pkt_t* pkt)
673{
674 netio_pkt_handle_t h;
675 h.word = pkt->__packet.word;
676 return h;
677}
678
679
680/** A special reserved value indicating the absence of a packet handle.
681 *
682 * @ingroup pktfuncs
683 */
684#define NETIO_PKT_HANDLE_NONE ((netio_pkt_handle_t) { 0 })
685
686
687/** Test whether a packet handle is valid.
688 *
689 * Applications may wish to use the reserved value NETIO_PKT_HANDLE_NONE
690 * to indicate no packet at all. This function tests to see if a packet
691 * handle is a real handle, not this special reserved value.
692 *
693 * @ingroup pktfuncs
694 *
695 * @param[in] handle Handle on which to operate.
696 * @return One if the packet handle is valid, else zero.
697 */
698static __inline unsigned int
699NETIO_PKT_HANDLE_IS_VALID(netio_pkt_handle_t handle)
700{
701 return handle.word != 0;
702}
703
704
705
706/** Return a pointer to the start of the packet's custom header.
707 * A custom header may or may not be present, depending upon the IPP; its
708 * contents and alignment are also IPP-dependent. Currently, none of the
709 * standard IPPs supplied by Tilera produce a custom header. If present,
710 * the custom header precedes the L2 header in the packet buffer.
711 * @ingroup ingress
712 *
713 * @param[in] handle Handle on which to operate.
714 * @return A pointer to start of the packet.
715 */
716static __inline unsigned char*
717NETIO_PKT_CUSTOM_DATA_H(netio_pkt_handle_t handle)
718{
719 return _NETIO_PKT_HANDLE_BASE(handle) + NETIO_PACKET_PADDING;
720}
721
722
723/** Return the length of the packet's custom header.
724 * A custom header may or may not be present, depending upon the IPP; its
725 * contents and alignment are also IPP-dependent. Currently, none of the
726 * standard IPPs supplied by Tilera produce a custom header. If present,
727 * the custom header precedes the L2 header in the packet buffer.
728 *
729 * @ingroup ingress
730 *
731 * @param[in] mda Pointer to packet's standard metadata.
732 * @param[in] pkt Packet on which to operate.
733 * @return The length of the packet's custom header, in bytes.
734 */
735static __inline netio_size_t
736NETIO_PKT_CUSTOM_HEADER_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
737{
738 /*
739 * Note that we effectively need to extract a quantity from the flags word
740 * which is measured in words, and then turn it into bytes by shifting
741 * it left by 2. We do this all at once by just shifting right two less
742 * bits, and shifting the mask up two bits.
743 */
744 return ((mda->__flags >> (_NETIO_PKT_CUSTOM_LEN_SHIFT - 2)) &
745 (_NETIO_PKT_CUSTOM_LEN_RMASK << 2));
746}
747
748
749/** Return the length of the packet, starting with the custom header.
750 * A custom header may or may not be present, depending upon the IPP; its
751 * contents and alignment are also IPP-dependent. Currently, none of the
752 * standard IPPs supplied by Tilera produce a custom header. If present,
753 * the custom header precedes the L2 header in the packet buffer.
754 * @ingroup ingress
755 *
756 * @param[in] mda Pointer to packet's standard metadata.
757 * @param[in] pkt Packet on which to operate.
758 * @return The length of the packet, in bytes.
759 */
760static __inline netio_size_t
761NETIO_PKT_CUSTOM_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
762{
763 return (__NETIO_PKT_NOTIF_HEADER(pkt).bits.__transfer_size -
764 NETIO_PACKET_PADDING);
765}
766
767
768/** Return a pointer to the start of the packet's custom header.
769 * A custom header may or may not be present, depending upon the IPP; its
770 * contents and alignment are also IPP-dependent. Currently, none of the
771 * standard IPPs supplied by Tilera produce a custom header. If present,
772 * the custom header precedes the L2 header in the packet buffer.
773 * @ingroup ingress
774 *
775 * @param[in] mda Pointer to packet's standard metadata.
776 * @param[in] pkt Packet on which to operate.
777 * @return A pointer to start of the packet.
778 */
779static __inline unsigned char*
780NETIO_PKT_CUSTOM_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
781{
782 return NETIO_PKT_CUSTOM_DATA_H(NETIO_PKT_HANDLE(pkt));
783}
784
785
786/** Return the length of the packet's L2 (Ethernet plus VLAN or SNAP) header.
787 * @ingroup ingress
788 *
789 * @param[in] mda Pointer to packet's standard metadata.
790 * @param[in] pkt Packet on which to operate.
791 * @return The length of the packet's L2 header, in bytes.
792 */
793static __inline netio_size_t
794NETIO_PKT_L2_HEADER_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
795{
796 /*
797 * Note that we effectively need to extract a quantity from the flags word
798 * which is measured in words, and then turn it into bytes by shifting
799 * it left by 2. We do this all at once by just shifting right two less
800 * bits, and shifting the mask up two bits. We then add two bytes.
801 */
802 return ((mda->__flags >> (_NETIO_PKT_L2_LEN_SHIFT - 2)) &
803 (_NETIO_PKT_L2_LEN_RMASK << 2)) + 2;
804}
805
806
807/** Return the length of the packet, starting with the L2 (Ethernet) header.
808 * @ingroup ingress
809 *
810 * @param[in] mda Pointer to packet's standard metadata.
811 * @param[in] pkt Packet on which to operate.
812 * @return The length of the packet, in bytes.
813 */
814static __inline netio_size_t
815NETIO_PKT_L2_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
816{
817 return (NETIO_PKT_CUSTOM_LENGTH_M(mda, pkt) -
818 NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda,pkt));
819}
820
821
822/** Return a pointer to the start of the packet's L2 (Ethernet) header.
823 * @ingroup ingress
824 *
825 * @param[in] mda Pointer to packet's standard metadata.
826 * @param[in] pkt Packet on which to operate.
827 * @return A pointer to start of the packet.
828 */
829static __inline unsigned char*
830NETIO_PKT_L2_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
831{
832 return (NETIO_PKT_CUSTOM_DATA_M(mda, pkt) +
833 NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt));
834}
835
836
837/** Retrieve the length of the packet, starting with the L3 (generally,
838 * the IP) header.
839 * @ingroup ingress
840 *
841 * @param[in] mda Pointer to packet's standard metadata.
842 * @param[in] pkt Packet on which to operate.
843 * @return Length of the packet's L3 header and data, in bytes.
844 */
845static __inline netio_size_t
846NETIO_PKT_L3_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
847{
848 return (NETIO_PKT_L2_LENGTH_M(mda, pkt) -
849 NETIO_PKT_L2_HEADER_LENGTH_M(mda,pkt));
850}
851
852
853/** Return a pointer to the packet's L3 (generally, the IP) header.
854 * @ingroup ingress
855 *
856 * Note that we guarantee word alignment of the L3 header.
857 *
858 * @param[in] mda Pointer to packet's standard metadata.
859 * @param[in] pkt Packet on which to operate.
860 * @return A pointer to the packet's L3 header.
861 */
862static __inline unsigned char*
863NETIO_PKT_L3_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
864{
865 return (NETIO_PKT_L2_DATA_M(mda, pkt) +
866 NETIO_PKT_L2_HEADER_LENGTH_M(mda, pkt));
867}
868
869
870/** Return the ordinal of the packet.
871 * @ingroup ingress
872 *
873 * Each packet is given an ordinal number when it is delivered by the IPP.
874 * In the medium term, the ordinal is unique and monotonically increasing,
875 * being incremented by 1 for each packet; the ordinal of the first packet
876 * delivered after the IPP starts is zero. (Since the ordinal is of finite
877 * size, given enough input packets, it will eventually wrap around to zero;
878 * in the long term, therefore, ordinals are not unique.) The ordinals
879 * handed out by different IPPs are not disjoint, so two packets from
880 * different IPPs may have identical ordinals. Packets dropped by the
881 * IPP or by the I/O shim are not assigned ordinals.
882 *
883 * @param[in] mda Pointer to packet's standard metadata.
884 * @param[in] pkt Packet on which to operate.
885 * @return The packet's per-IPP packet ordinal.
886 */
887static __inline unsigned int
888NETIO_PKT_ORDINAL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
889{
890 return mda->__packet_ordinal;
891}
892
893
894/** Return the per-group ordinal of the packet.
895 * @ingroup ingress
896 *
897 * Each packet is given a per-group ordinal number when it is
898 * delivered by the IPP. By default, the group is the packet's VLAN,
899 * although IPP can be recompiled to use different values. In
900 * the medium term, the ordinal is unique and monotonically
901 * increasing, being incremented by 1 for each packet; the ordinal of
902 * the first packet distributed to a particular group is zero.
903 * (Since the ordinal is of finite size, given enough input packets,
904 * it will eventually wrap around to zero; in the long term,
905 * therefore, ordinals are not unique.) The ordinals handed out by
906 * different IPPs are not disjoint, so two packets from different IPPs
907 * may have identical ordinals; similarly, packets distributed to
908 * different groups may have identical ordinals. Packets dropped by
909 * the IPP or by the I/O shim are not assigned ordinals.
910 *
911 * @param[in] mda Pointer to packet's standard metadata.
912 * @param[in] pkt Packet on which to operate.
913 * @return The packet's per-IPP, per-group ordinal.
914 */
915static __inline unsigned int
916NETIO_PKT_GROUP_ORDINAL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
917{
918 return mda->__group_ordinal;
919}
920
921
922/** Return the VLAN ID assigned to the packet.
923 * @ingroup ingress
924 *
925 * This value is usually contained within the packet header.
926 *
927 * This value will be zero if the packet does not have a VLAN tag, or if
928 * this value was not extracted from the packet.
929 *
930 * @param[in] mda Pointer to packet's standard metadata.
931 * @param[in] pkt Packet on which to operate.
932 * @return The packet's VLAN ID.
933 */
934static __inline unsigned short
935NETIO_PKT_VLAN_ID_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
936{
937 int vl = (mda->__flags >> _NETIO_PKT_VLAN_SHIFT) & _NETIO_PKT_VLAN_RMASK;
938 unsigned short* pkt_p;
939 int index;
940 unsigned short val;
941
942 if (vl == _NETIO_PKT_VLAN_NONE)
943 return 0;
944
945 pkt_p = (unsigned short*) NETIO_PKT_L2_DATA_M(mda, pkt);
946 index = (mda->__flags >> _NETIO_PKT_TYPE_SHIFT) & _NETIO_PKT_TYPE_RMASK;
947
948 val = pkt_p[(_netio_pkt_info[index] >> _NETIO_PKT_INFO_VLAN_SHIFT) &
949 _NETIO_PKT_INFO_VLAN_RMASK];
950
951#ifdef __TILECC__
952 return (__insn_bytex(val) >> 16) & 0xFFF;
953#else
954 return (__builtin_bswap32(val) >> 16) & 0xFFF;
955#endif
956}
957
958
959/** Return the ethertype of the packet.
960 * @ingroup ingress
961 *
962 * This value is usually contained within the packet header.
963 *
964 * This value is reliable if @ref NETIO_PKT_ETHERTYPE_RECOGNIZED_M()
965 * returns true, and otherwise, may not be well defined.
966 *
967 * @param[in] mda Pointer to packet's standard metadata.
968 * @param[in] pkt Packet on which to operate.
969 * @return The packet's ethertype.
970 */
971static __inline unsigned short
972NETIO_PKT_ETHERTYPE_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
973{
974 unsigned short* pkt_p = (unsigned short*) NETIO_PKT_L2_DATA_M(mda, pkt);
975 int index = (mda->__flags >> _NETIO_PKT_TYPE_SHIFT) & _NETIO_PKT_TYPE_RMASK;
976
977 unsigned short val =
978 pkt_p[(_netio_pkt_info[index] >> _NETIO_PKT_INFO_ETYPE_SHIFT) &
979 _NETIO_PKT_INFO_ETYPE_RMASK];
980
981 return __builtin_bswap32(val) >> 16;
982}
983
984
985/** Return the flow hash computed on the packet.
986 * @ingroup ingress
987 *
988 * For TCP and UDP packets, this hash is calculated by hashing together
989 * the "5-tuple" values, specifically the source IP address, destination
990 * IP address, protocol type, source port and destination port.
991 * The hash value is intended to be helpful for millions of distinct
992 * flows.
993 *
994 * For IPv4 or IPv6 packets which are neither TCP nor UDP, the flow hash is
995 * derived by hashing together the source and destination IP addresses.
996 *
997 * For MPLS-encapsulated packets, the flow hash is derived by hashing
998 * the first MPLS label.
999 *
1000 * For all other packets the flow hash is computed from the source
1001 * and destination Ethernet addresses.
1002 *
1003 * The hash is symmetric, meaning it produces the same value if the
1004 * source and destination are swapped. The only exceptions are
1005 * tunneling protocols 0x04 (IP in IP Encapsulation), 0x29 (Simple
1006 * Internet Protocol), 0x2F (General Routing Encapsulation) and 0x32
1007 * (Encap Security Payload), which use only the destination address
1008 * since the source address is not meaningful.
1009 *
1010 * @param[in] mda Pointer to packet's standard metadata.
1011 * @param[in] pkt Packet on which to operate.
1012 * @return The packet's 32-bit flow hash.
1013 */
1014static __inline unsigned int
1015NETIO_PKT_FLOW_HASH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1016{
1017 return mda->__flow_hash;
1018}
1019
1020
1021/** Return the first word of "user data" for the packet.
1022 *
1023 * The contents of the user data words depend on the IPP.
1024 *
1025 * When using the standard ipp1, ipp2, or ipp4 sub-drivers, the first
1026 * word of user data contains the least significant bits of the 64-bit
1027 * arrival cycle count (see @c get_cycle_count_low()).
1028 *
1029 * See the <em>System Programmer's Guide</em> for details.
1030 *
1031 * @ingroup ingress
1032 *
1033 * @param[in] mda Pointer to packet's standard metadata.
1034 * @param[in] pkt Packet on which to operate.
1035 * @return The packet's first word of "user data".
1036 */
1037static __inline unsigned int
1038NETIO_PKT_USER_DATA_0_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1039{
1040 return mda->__user_data_0;
1041}
1042
1043
1044/** Return the second word of "user data" for the packet.
1045 *
1046 * The contents of the user data words depend on the IPP.
1047 *
1048 * When using the standard ipp1, ipp2, or ipp4 sub-drivers, the second
1049 * word of user data contains the most significant bits of the 64-bit
1050 * arrival cycle count (see @c get_cycle_count_high()).
1051 *
1052 * See the <em>System Programmer's Guide</em> for details.
1053 *
1054 * @ingroup ingress
1055 *
1056 * @param[in] mda Pointer to packet's standard metadata.
1057 * @param[in] pkt Packet on which to operate.
1058 * @return The packet's second word of "user data".
1059 */
1060static __inline unsigned int
1061NETIO_PKT_USER_DATA_1_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1062{
1063 return mda->__user_data_1;
1064}
1065
1066
1067/** Determine whether the L4 (TCP/UDP) checksum was calculated.
1068 * @ingroup ingress
1069 *
1070 * @param[in] mda Pointer to packet's standard metadata.
1071 * @param[in] pkt Packet on which to operate.
1072 * @return Nonzero if the L4 checksum was calculated.
1073 */
1074static __inline unsigned int
1075NETIO_PKT_L4_CSUM_CALCULATED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1076{
1077 return !(mda->__flags & _NETIO_PKT_NO_L4_CSUM_MASK);
1078}
1079
1080
1081/** Determine whether the L4 (TCP/UDP) checksum was calculated and found to
1082 * be correct.
1083 * @ingroup ingress
1084 *
1085 * @param[in] mda Pointer to packet's standard metadata.
1086 * @param[in] pkt Packet on which to operate.
1087 * @return Nonzero if the checksum was calculated and is correct.
1088 */
1089static __inline unsigned int
1090NETIO_PKT_L4_CSUM_CORRECT_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1091{
1092 return !(mda->__flags &
1093 (_NETIO_PKT_BAD_L4_CSUM_MASK | _NETIO_PKT_NO_L4_CSUM_MASK));
1094}
1095
1096
1097/** Determine whether the L3 (IP) checksum was calculated.
1098 * @ingroup ingress
1099 *
1100 * @param[in] mda Pointer to packet's standard metadata.
1101 * @param[in] pkt Packet on which to operate.
1102 * @return Nonzero if the L3 (IP) checksum was calculated.
1103*/
1104static __inline unsigned int
1105NETIO_PKT_L3_CSUM_CALCULATED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1106{
1107 return !(mda->__flags & _NETIO_PKT_NO_L3_CSUM_MASK);
1108}
1109
1110
1111/** Determine whether the L3 (IP) checksum was calculated and found to be
1112 * correct.
1113 * @ingroup ingress
1114 *
1115 * @param[in] mda Pointer to packet's standard metadata.
1116 * @param[in] pkt Packet on which to operate.
1117 * @return Nonzero if the checksum was calculated and is correct.
1118 */
1119static __inline unsigned int
1120NETIO_PKT_L3_CSUM_CORRECT_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1121{
1122 return !(mda->__flags &
1123 (_NETIO_PKT_BAD_L3_CSUM_MASK | _NETIO_PKT_NO_L3_CSUM_MASK));
1124}
1125
1126
1127/** Determine whether the ethertype was recognized and L3 packet data was
1128 * processed.
1129 * @ingroup ingress
1130 *
1131 * @param[in] mda Pointer to packet's standard metadata.
1132 * @param[in] pkt Packet on which to operate.
1133 * @return Nonzero if the ethertype was recognized and L3 packet data was
1134 * processed.
1135 */
1136static __inline unsigned int
1137NETIO_PKT_ETHERTYPE_RECOGNIZED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1138{
1139 return !(mda->__flags & _NETIO_PKT_TYPE_UNRECOGNIZED_MASK);
1140}
1141
1142
1143/** Retrieve the status of a packet and any errors that may have occurred
1144 * during ingress processing (length mismatches, CRC errors, etc.).
1145 * @ingroup ingress
1146 *
1147 * Note that packets for which @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()
1148 * returns zero are always reported as underlength, as there is no a priori
1149 * means to determine their length. Normally, applications should use
1150 * @ref NETIO_PKT_BAD_M() instead of explicitly checking status with this
1151 * function.
1152 *
1153 * @param[in] mda Pointer to packet's standard metadata.
1154 * @param[in] pkt Packet on which to operate.
1155 * @return The packet's status.
1156 */
1157static __inline netio_pkt_status_t
1158NETIO_PKT_STATUS_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1159{
1160 return (netio_pkt_status_t) __NETIO_PKT_NOTIF_HEADER(pkt).bits.__status;
1161}
1162
1163
1164/** Report whether a packet is bad (i.e., was shorter than expected based on
1165 * its headers, or had a bad CRC).
1166 * @ingroup ingress
1167 *
1168 * Note that this function does not verify L3 or L4 checksums.
1169 *
1170 * @param[in] mda Pointer to packet's standard metadata.
1171 * @param[in] pkt Packet on which to operate.
1172 * @return Nonzero if the packet is bad and should be discarded.
1173 */
1174static __inline unsigned int
1175NETIO_PKT_BAD_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1176{
1177 return ((NETIO_PKT_STATUS_M(mda, pkt) & 1) &&
1178 (NETIO_PKT_ETHERTYPE_RECOGNIZED_M(mda, pkt) ||
1179 NETIO_PKT_STATUS_M(mda, pkt) == NETIO_PKT_STATUS_BAD));
1180}
1181
1182
1183/** Return the length of the packet, starting with the L2 (Ethernet) header.
1184 * @ingroup egress
1185 *
1186 * @param[in] mmd Pointer to packet's minimal metadata.
1187 * @param[in] pkt Packet on which to operate.
1188 * @return The length of the packet, in bytes.
1189 */
1190static __inline netio_size_t
1191NETIO_PKT_L2_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1192{
1193 return mmd->l2_length;
1194}
1195
1196
1197/** Return the length of the L2 (Ethernet) header.
1198 * @ingroup egress
1199 *
1200 * @param[in] mmd Pointer to packet's minimal metadata.
1201 * @param[in] pkt Packet on which to operate.
1202 * @return The length of the packet's L2 header, in bytes.
1203 */
1204static __inline netio_size_t
1205NETIO_PKT_L2_HEADER_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd,
1206 netio_pkt_t* pkt)
1207{
1208 return mmd->l3_offset - mmd->l2_offset;
1209}
1210
1211
1212/** Return the length of the packet, starting with the L3 (IP) header.
1213 * @ingroup egress
1214 *
1215 * @param[in] mmd Pointer to packet's minimal metadata.
1216 * @param[in] pkt Packet on which to operate.
1217 * @return Length of the packet's L3 header and data, in bytes.
1218 */
1219static __inline netio_size_t
1220NETIO_PKT_L3_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1221{
1222 return (NETIO_PKT_L2_LENGTH_MM(mmd, pkt) -
1223 NETIO_PKT_L2_HEADER_LENGTH_MM(mmd, pkt));
1224}
1225
1226
1227/** Return a pointer to the packet's L3 (generally, the IP) header.
1228 * @ingroup egress
1229 *
1230 * Note that we guarantee word alignment of the L3 header.
1231 *
1232 * @param[in] mmd Pointer to packet's minimal metadata.
1233 * @param[in] pkt Packet on which to operate.
1234 * @return A pointer to the packet's L3 header.
1235 */
1236static __inline unsigned char*
1237NETIO_PKT_L3_DATA_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1238{
1239 return _NETIO_PKT_BASE(pkt) + mmd->l3_offset;
1240}
1241
1242
1243/** Return a pointer to the packet's L2 (Ethernet) header.
1244 * @ingroup egress
1245 *
1246 * @param[in] mmd Pointer to packet's minimal metadata.
1247 * @param[in] pkt Packet on which to operate.
1248 * @return A pointer to start of the packet.
1249 */
1250static __inline unsigned char*
1251NETIO_PKT_L2_DATA_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1252{
1253 return _NETIO_PKT_BASE(pkt) + mmd->l2_offset;
1254}
1255
1256
1257/** Retrieve the status of a packet and any errors that may have occurred
1258 * during ingress processing (length mismatches, CRC errors, etc.).
1259 * @ingroup ingress
1260 *
1261 * Note that packets for which @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()
1262 * returns zero are always reported as underlength, as there is no a priori
1263 * means to determine their length. Normally, applications should use
1264 * @ref NETIO_PKT_BAD() instead of explicitly checking status with this
1265 * function.
1266 *
1267 * @param[in] pkt Packet on which to operate.
1268 * @return The packet's status.
1269 */
1270static __inline netio_pkt_status_t
1271NETIO_PKT_STATUS(netio_pkt_t* pkt)
1272{
1273 netio_assert(!pkt->__packet.bits.__minimal);
1274
1275 return (netio_pkt_status_t) __NETIO_PKT_NOTIF_HEADER(pkt).bits.__status;
1276}
1277
1278
1279/** Report whether a packet is bad (i.e., was shorter than expected based on
1280 * its headers, or had a bad CRC).
1281 * @ingroup ingress
1282 *
1283 * Note that this function does not verify L3 or L4 checksums.
1284 *
1285 * @param[in] pkt Packet on which to operate.
1286 * @return Nonzero if the packet is bad and should be discarded.
1287 */
1288static __inline unsigned int
1289NETIO_PKT_BAD(netio_pkt_t* pkt)
1290{
1291 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1292
1293 return NETIO_PKT_BAD_M(mda, pkt);
1294}
1295
1296
1297/** Return the length of the packet's custom header.
1298 * A custom header may or may not be present, depending upon the IPP; its
1299 * contents and alignment are also IPP-dependent. Currently, none of the
1300 * standard IPPs supplied by Tilera produce a custom header. If present,
1301 * the custom header precedes the L2 header in the packet buffer.
1302 * @ingroup pktfuncs
1303 *
1304 * @param[in] pkt Packet on which to operate.
1305 * @return The length of the packet's custom header, in bytes.
1306 */
1307static __inline netio_size_t
1308NETIO_PKT_CUSTOM_HEADER_LENGTH(netio_pkt_t* pkt)
1309{
1310 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1311
1312 return NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt);
1313}
1314
1315
1316/** Return the length of the packet, starting with the custom header.
1317 * A custom header may or may not be present, depending upon the IPP; its
1318 * contents and alignment are also IPP-dependent. Currently, none of the
1319 * standard IPPs supplied by Tilera produce a custom header. If present,
1320 * the custom header precedes the L2 header in the packet buffer.
1321 * @ingroup pktfuncs
1322 *
1323 * @param[in] pkt Packet on which to operate.
1324 * @return The length of the packet, in bytes.
1325 */
1326static __inline netio_size_t
1327NETIO_PKT_CUSTOM_LENGTH(netio_pkt_t* pkt)
1328{
1329 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1330
1331 return NETIO_PKT_CUSTOM_LENGTH_M(mda, pkt);
1332}
1333
1334
1335/** Return a pointer to the packet's custom header.
1336 * A custom header may or may not be present, depending upon the IPP; its
1337 * contents and alignment are also IPP-dependent. Currently, none of the
1338 * standard IPPs supplied by Tilera produce a custom header. If present,
1339 * the custom header precedes the L2 header in the packet buffer.
1340 * @ingroup pktfuncs
1341 *
1342 * @param[in] pkt Packet on which to operate.
1343 * @return A pointer to start of the packet.
1344 */
1345static __inline unsigned char*
1346NETIO_PKT_CUSTOM_DATA(netio_pkt_t* pkt)
1347{
1348 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1349
1350 return NETIO_PKT_CUSTOM_DATA_M(mda, pkt);
1351}
1352
1353
1354/** Return the length of the packet's L2 (Ethernet plus VLAN or SNAP) header.
1355 * @ingroup pktfuncs
1356 *
1357 * @param[in] pkt Packet on which to operate.
1358 * @return The length of the packet's L2 header, in bytes.
1359 */
1360static __inline netio_size_t
1361NETIO_PKT_L2_HEADER_LENGTH(netio_pkt_t* pkt)
1362{
1363 if (NETIO_PKT_IS_MINIMAL(pkt))
1364 {
1365 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1366
1367 return NETIO_PKT_L2_HEADER_LENGTH_MM(mmd, pkt);
1368 }
1369 else
1370 {
1371 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1372
1373 return NETIO_PKT_L2_HEADER_LENGTH_M(mda, pkt);
1374 }
1375}
1376
1377
1378/** Return the length of the packet, starting with the L2 (Ethernet) header.
1379 * @ingroup pktfuncs
1380 *
1381 * @param[in] pkt Packet on which to operate.
1382 * @return The length of the packet, in bytes.
1383 */
1384static __inline netio_size_t
1385NETIO_PKT_L2_LENGTH(netio_pkt_t* pkt)
1386{
1387 if (NETIO_PKT_IS_MINIMAL(pkt))
1388 {
1389 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1390
1391 return NETIO_PKT_L2_LENGTH_MM(mmd, pkt);
1392 }
1393 else
1394 {
1395 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1396
1397 return NETIO_PKT_L2_LENGTH_M(mda, pkt);
1398 }
1399}
1400
1401
1402/** Return a pointer to the packet's L2 (Ethernet) header.
1403 * @ingroup pktfuncs
1404 *
1405 * @param[in] pkt Packet on which to operate.
1406 * @return A pointer to start of the packet.
1407 */
1408static __inline unsigned char*
1409NETIO_PKT_L2_DATA(netio_pkt_t* pkt)
1410{
1411 if (NETIO_PKT_IS_MINIMAL(pkt))
1412 {
1413 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1414
1415 return NETIO_PKT_L2_DATA_MM(mmd, pkt);
1416 }
1417 else
1418 {
1419 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1420
1421 return NETIO_PKT_L2_DATA_M(mda, pkt);
1422 }
1423}
1424
1425
1426/** Retrieve the length of the packet, starting with the L3 (generally, the IP)
1427 * header.
1428 * @ingroup pktfuncs
1429 *
1430 * @param[in] pkt Packet on which to operate.
1431 * @return Length of the packet's L3 header and data, in bytes.
1432 */
1433static __inline netio_size_t
1434NETIO_PKT_L3_LENGTH(netio_pkt_t* pkt)
1435{
1436 if (NETIO_PKT_IS_MINIMAL(pkt))
1437 {
1438 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1439
1440 return NETIO_PKT_L3_LENGTH_MM(mmd, pkt);
1441 }
1442 else
1443 {
1444 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1445
1446 return NETIO_PKT_L3_LENGTH_M(mda, pkt);
1447 }
1448}
1449
1450
1451/** Return a pointer to the packet's L3 (generally, the IP) header.
1452 * @ingroup pktfuncs
1453 *
1454 * Note that we guarantee word alignment of the L3 header.
1455 *
1456 * @param[in] pkt Packet on which to operate.
1457 * @return A pointer to the packet's L3 header.
1458 */
1459static __inline unsigned char*
1460NETIO_PKT_L3_DATA(netio_pkt_t* pkt)
1461{
1462 if (NETIO_PKT_IS_MINIMAL(pkt))
1463 {
1464 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1465
1466 return NETIO_PKT_L3_DATA_MM(mmd, pkt);
1467 }
1468 else
1469 {
1470 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1471
1472 return NETIO_PKT_L3_DATA_M(mda, pkt);
1473 }
1474}
1475
1476
1477/** Return the ordinal of the packet.
1478 * @ingroup ingress
1479 *
1480 * Each packet is given an ordinal number when it is delivered by the IPP.
1481 * In the medium term, the ordinal is unique and monotonically increasing,
1482 * being incremented by 1 for each packet; the ordinal of the first packet
1483 * delivered after the IPP starts is zero. (Since the ordinal is of finite
1484 * size, given enough input packets, it will eventually wrap around to zero;
1485 * in the long term, therefore, ordinals are not unique.) The ordinals
1486 * handed out by different IPPs are not disjoint, so two packets from
1487 * different IPPs may have identical ordinals. Packets dropped by the
1488 * IPP or by the I/O shim are not assigned ordinals.
1489 *
1490 *
1491 * @param[in] pkt Packet on which to operate.
1492 * @return The packet's per-IPP packet ordinal.
1493 */
1494static __inline unsigned int
1495NETIO_PKT_ORDINAL(netio_pkt_t* pkt)
1496{
1497 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1498
1499 return NETIO_PKT_ORDINAL_M(mda, pkt);
1500}
1501
1502
1503/** Return the per-group ordinal of the packet.
1504 * @ingroup ingress
1505 *
1506 * Each packet is given a per-group ordinal number when it is
1507 * delivered by the IPP. By default, the group is the packet's VLAN,
1508 * although IPP can be recompiled to use different values. In
1509 * the medium term, the ordinal is unique and monotonically
1510 * increasing, being incremented by 1 for each packet; the ordinal of
1511 * the first packet distributed to a particular group is zero.
1512 * (Since the ordinal is of finite size, given enough input packets,
1513 * it will eventually wrap around to zero; in the long term,
1514 * therefore, ordinals are not unique.) The ordinals handed out by
1515 * different IPPs are not disjoint, so two packets from different IPPs
1516 * may have identical ordinals; similarly, packets distributed to
1517 * different groups may have identical ordinals. Packets dropped by
1518 * the IPP or by the I/O shim are not assigned ordinals.
1519 *
1520 * @param[in] pkt Packet on which to operate.
1521 * @return The packet's per-IPP, per-group ordinal.
1522 */
1523static __inline unsigned int
1524NETIO_PKT_GROUP_ORDINAL(netio_pkt_t* pkt)
1525{
1526 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1527
1528 return NETIO_PKT_GROUP_ORDINAL_M(mda, pkt);
1529}
1530
1531
1532/** Return the VLAN ID assigned to the packet.
1533 * @ingroup ingress
1534 *
1535 * This is usually also contained within the packet header. If the packet
1536 * does not have a VLAN tag, the VLAN ID returned by this function is zero.
1537 *
1538 * @param[in] pkt Packet on which to operate.
1539 * @return The packet's VLAN ID.
1540 */
1541static __inline unsigned short
1542NETIO_PKT_VLAN_ID(netio_pkt_t* pkt)
1543{
1544 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1545
1546 return NETIO_PKT_VLAN_ID_M(mda, pkt);
1547}
1548
1549
1550/** Return the ethertype of the packet.
1551 * @ingroup ingress
1552 *
1553 * This value is reliable if @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()
1554 * returns true, and otherwise, may not be well defined.
1555 *
1556 * @param[in] pkt Packet on which to operate.
1557 * @return The packet's ethertype.
1558 */
1559static __inline unsigned short
1560NETIO_PKT_ETHERTYPE(netio_pkt_t* pkt)
1561{
1562 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1563
1564 return NETIO_PKT_ETHERTYPE_M(mda, pkt);
1565}
1566
1567
1568/** Return the flow hash computed on the packet.
1569 * @ingroup ingress
1570 *
1571 * For TCP and UDP packets, this hash is calculated by hashing together
1572 * the "5-tuple" values, specifically the source IP address, destination
1573 * IP address, protocol type, source port and destination port.
1574 * The hash value is intended to be helpful for millions of distinct
1575 * flows.
1576 *
1577 * For IPv4 or IPv6 packets which are neither TCP nor UDP, the flow hash is
1578 * derived by hashing together the source and destination IP addresses.
1579 *
1580 * For MPLS-encapsulated packets, the flow hash is derived by hashing
1581 * the first MPLS label.
1582 *
1583 * For all other packets the flow hash is computed from the source
1584 * and destination Ethernet addresses.
1585 *
1586 * The hash is symmetric, meaning it produces the same value if the
1587 * source and destination are swapped. The only exceptions are
1588 * tunneling protocols 0x04 (IP in IP Encapsulation), 0x29 (Simple
1589 * Internet Protocol), 0x2F (General Routing Encapsulation) and 0x32
1590 * (Encap Security Payload), which use only the destination address
1591 * since the source address is not meaningful.
1592 *
1593 * @param[in] pkt Packet on which to operate.
1594 * @return The packet's 32-bit flow hash.
1595 */
1596static __inline unsigned int
1597NETIO_PKT_FLOW_HASH(netio_pkt_t* pkt)
1598{
1599 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1600
1601 return NETIO_PKT_FLOW_HASH_M(mda, pkt);
1602}
1603
1604
1605/** Return the first word of "user data" for the packet.
1606 *
1607 * The contents of the user data words depend on the IPP.
1608 *
1609 * When using the standard ipp1, ipp2, or ipp4 sub-drivers, the first
1610 * word of user data contains the least significant bits of the 64-bit
1611 * arrival cycle count (see @c get_cycle_count_low()).
1612 *
1613 * See the <em>System Programmer's Guide</em> for details.
1614 *
1615 * @ingroup ingress
1616 *
1617 * @param[in] pkt Packet on which to operate.
1618 * @return The packet's first word of "user data".
1619 */
1620static __inline unsigned int
1621NETIO_PKT_USER_DATA_0(netio_pkt_t* pkt)
1622{
1623 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1624
1625 return NETIO_PKT_USER_DATA_0_M(mda, pkt);
1626}
1627
1628
1629/** Return the second word of "user data" for the packet.
1630 *
1631 * The contents of the user data words depend on the IPP.
1632 *
1633 * When using the standard ipp1, ipp2, or ipp4 sub-drivers, the second
1634 * word of user data contains the most significant bits of the 64-bit
1635 * arrival cycle count (see @c get_cycle_count_high()).
1636 *
1637 * See the <em>System Programmer's Guide</em> for details.
1638 *
1639 * @ingroup ingress
1640 *
1641 * @param[in] pkt Packet on which to operate.
1642 * @return The packet's second word of "user data".
1643 */
1644static __inline unsigned int
1645NETIO_PKT_USER_DATA_1(netio_pkt_t* pkt)
1646{
1647 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1648
1649 return NETIO_PKT_USER_DATA_1_M(mda, pkt);
1650}
1651
1652
1653/** Determine whether the L4 (TCP/UDP) checksum was calculated.
1654 * @ingroup ingress
1655 *
1656 * @param[in] pkt Packet on which to operate.
1657 * @return Nonzero if the L4 checksum was calculated.
1658 */
1659static __inline unsigned int
1660NETIO_PKT_L4_CSUM_CALCULATED(netio_pkt_t* pkt)
1661{
1662 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1663
1664 return NETIO_PKT_L4_CSUM_CALCULATED_M(mda, pkt);
1665}
1666
1667
1668/** Determine whether the L4 (TCP/UDP) checksum was calculated and found to
1669 * be correct.
1670 * @ingroup ingress
1671 *
1672 * @param[in] pkt Packet on which to operate.
1673 * @return Nonzero if the checksum was calculated and is correct.
1674 */
1675static __inline unsigned int
1676NETIO_PKT_L4_CSUM_CORRECT(netio_pkt_t* pkt)
1677{
1678 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1679
1680 return NETIO_PKT_L4_CSUM_CORRECT_M(mda, pkt);
1681}
1682
1683
1684/** Determine whether the L3 (IP) checksum was calculated.
1685 * @ingroup ingress
1686 *
1687 * @param[in] pkt Packet on which to operate.
1688 * @return Nonzero if the L3 (IP) checksum was calculated.
1689*/
1690static __inline unsigned int
1691NETIO_PKT_L3_CSUM_CALCULATED(netio_pkt_t* pkt)
1692{
1693 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1694
1695 return NETIO_PKT_L3_CSUM_CALCULATED_M(mda, pkt);
1696}
1697
1698
1699/** Determine whether the L3 (IP) checksum was calculated and found to be
1700 * correct.
1701 * @ingroup ingress
1702 *
1703 * @param[in] pkt Packet on which to operate.
1704 * @return Nonzero if the checksum was calculated and is correct.
1705 */
1706static __inline unsigned int
1707NETIO_PKT_L3_CSUM_CORRECT(netio_pkt_t* pkt)
1708{
1709 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1710
1711 return NETIO_PKT_L3_CSUM_CORRECT_M(mda, pkt);
1712}
1713
1714
1715/** Determine whether the Ethertype was recognized and L3 packet data was
1716 * processed.
1717 * @ingroup ingress
1718 *
1719 * @param[in] pkt Packet on which to operate.
1720 * @return Nonzero if the Ethertype was recognized and L3 packet data was
1721 * processed.
1722 */
1723static __inline unsigned int
1724NETIO_PKT_ETHERTYPE_RECOGNIZED(netio_pkt_t* pkt)
1725{
1726 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1727
1728 return NETIO_PKT_ETHERTYPE_RECOGNIZED_M(mda, pkt);
1729}
1730
1731
1732/** Set an egress packet's L2 length, using a metadata pointer to speed the
1733 * computation.
1734 * @ingroup egress
1735 *
1736 * @param[in,out] mmd Pointer to packet's minimal metadata.
1737 * @param[in] pkt Packet on which to operate.
1738 * @param[in] len Packet L2 length, in bytes.
1739 */
1740static __inline void
1741NETIO_PKT_SET_L2_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt,
1742 int len)
1743{
1744 mmd->l2_length = len;
1745}
1746
1747
1748/** Set an egress packet's L2 length.
1749 * @ingroup egress
1750 *
1751 * @param[in,out] pkt Packet on which to operate.
1752 * @param[in] len Packet L2 length, in bytes.
1753 */
1754static __inline void
1755NETIO_PKT_SET_L2_LENGTH(netio_pkt_t* pkt, int len)
1756{
1757 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1758
1759 NETIO_PKT_SET_L2_LENGTH_MM(mmd, pkt, len);
1760}
1761
1762
1763/** Set an egress packet's L2 header length, using a metadata pointer to
1764 * speed the computation.
1765 * @ingroup egress
1766 *
1767 * It is not normally necessary to call this routine; only the L2 length,
1768 * not the header length, is needed to transmit a packet. It may be useful if
1769 * the egress packet will later be processed by code which expects to use
1770 * functions like @ref NETIO_PKT_L3_DATA() to get a pointer to the L3 payload.
1771 *
1772 * @param[in,out] mmd Pointer to packet's minimal metadata.
1773 * @param[in] pkt Packet on which to operate.
1774 * @param[in] len Packet L2 header length, in bytes.
1775 */
1776static __inline void
1777NETIO_PKT_SET_L2_HEADER_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd,
1778 netio_pkt_t* pkt, int len)
1779{
1780 mmd->l3_offset = mmd->l2_offset + len;
1781}
1782
1783
1784/** Set an egress packet's L2 header length.
1785 * @ingroup egress
1786 *
1787 * It is not normally necessary to call this routine; only the L2 length,
1788 * not the header length, is needed to transmit a packet. It may be useful if
1789 * the egress packet will later be processed by code which expects to use
1790 * functions like @ref NETIO_PKT_L3_DATA() to get a pointer to the L3 payload.
1791 *
1792 * @param[in,out] pkt Packet on which to operate.
1793 * @param[in] len Packet L2 header length, in bytes.
1794 */
1795static __inline void
1796NETIO_PKT_SET_L2_HEADER_LENGTH(netio_pkt_t* pkt, int len)
1797{
1798 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1799
1800 NETIO_PKT_SET_L2_HEADER_LENGTH_MM(mmd, pkt, len);
1801}
1802
1803
1804/** Set up an egress packet for hardware checksum computation, using a
1805 * metadata pointer to speed the operation.
1806 * @ingroup egress
1807 *
1808 * NetIO provides the ability to automatically calculate a standard
1809 * 16-bit Internet checksum on transmitted packets. The application
1810 * may specify the point in the packet where the checksum starts, the
1811 * number of bytes to be checksummed, and the two bytes in the packet
1812 * which will be replaced with the completed checksum. (If the range
1813 * of bytes to be checksummed includes the bytes to be replaced, the
1814 * initial values of those bytes will be included in the checksum.)
1815 *
1816 * For some protocols, the packet checksum covers data which is not present
1817 * in the packet, or is at least not contiguous to the main data payload.
1818 * For instance, the TCP checksum includes a "pseudo-header" which includes
1819 * the source and destination IP addresses of the packet. To accommodate
1820 * this, the checksum engine may be "seeded" with an initial value, which
1821 * the application would need to compute based on the specific protocol's
1822 * requirements. Note that the seed is given in host byte order (little-
1823 * endian), not network byte order (big-endian); code written to compute a
1824 * pseudo-header checksum in network byte order will need to byte-swap it
1825 * before use as the seed.
1826 *
1827 * Note that the checksum is computed as part of the transmission process,
1828 * so it will not be present in the packet upon completion of this routine.
1829 *
1830 * @param[in,out] mmd Pointer to packet's minimal metadata.
1831 * @param[in] pkt Packet on which to operate.
1832 * @param[in] start Offset within L2 packet of the first byte to include in
1833 * the checksum.
1834 * @param[in] length Number of bytes to include in the checksum.
1835 * the checksum.
1836 * @param[in] location Offset within L2 packet of the first of the two bytes
1837 * to be replaced with the calculated checksum.
1838 * @param[in] seed Initial value of the running checksum before any of the
1839 * packet data is added.
1840 */
1841static __inline void
1842NETIO_PKT_DO_EGRESS_CSUM_MM(netio_pkt_minimal_metadata_t* mmd,
1843 netio_pkt_t* pkt, int start, int length,
1844 int location, uint16_t seed)
1845{
1846 mmd->csum_start = start;
1847 mmd->csum_length = length;
1848 mmd->csum_location = location;
1849 mmd->csum_seed = seed;
1850 mmd->flags |= _NETIO_PKT_NEED_EDMA_CSUM_MASK;
1851}
1852
1853
1854/** Set up an egress packet for hardware checksum computation.
1855 * @ingroup egress
1856 *
1857 * NetIO provides the ability to automatically calculate a standard
1858 * 16-bit Internet checksum on transmitted packets. The application
1859 * may specify the point in the packet where the checksum starts, the
1860 * number of bytes to be checksummed, and the two bytes in the packet
1861 * which will be replaced with the completed checksum. (If the range
1862 * of bytes to be checksummed includes the bytes to be replaced, the
1863 * initial values of those bytes will be included in the checksum.)
1864 *
1865 * For some protocols, the packet checksum covers data which is not present
1866 * in the packet, or is at least not contiguous to the main data payload.
1867 * For instance, the TCP checksum includes a "pseudo-header" which includes
1868 * the source and destination IP addresses of the packet. To accommodate
1869 * this, the checksum engine may be "seeded" with an initial value, which
1870 * the application would need to compute based on the specific protocol's
1871 * requirements. Note that the seed is given in host byte order (little-
1872 * endian), not network byte order (big-endian); code written to compute a
1873 * pseudo-header checksum in network byte order will need to byte-swap it
1874 * before use as the seed.
1875 *
1876 * Note that the checksum is computed as part of the transmission process,
1877 * so it will not be present in the packet upon completion of this routine.
1878 *
1879 * @param[in,out] pkt Packet on which to operate.
1880 * @param[in] start Offset within L2 packet of the first byte to include in
1881 * the checksum.
1882 * @param[in] length Number of bytes to include in the checksum.
1883 * the checksum.
1884 * @param[in] location Offset within L2 packet of the first of the two bytes
1885 * to be replaced with the calculated checksum.
1886 * @param[in] seed Initial value of the running checksum before any of the
1887 * packet data is added.
1888 */
1889static __inline void
1890NETIO_PKT_DO_EGRESS_CSUM(netio_pkt_t* pkt, int start, int length,
1891 int location, uint16_t seed)
1892{
1893 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1894
1895 NETIO_PKT_DO_EGRESS_CSUM_MM(mmd, pkt, start, length, location, seed);
1896}
1897
1898
1899/** Return the number of bytes which could be prepended to a packet, using a
1900 * metadata pointer to speed the operation.
1901 * See @ref netio_populate_prepend_buffer() to get a full description of
1902 * prepending.
1903 *
1904 * @param[in,out] mda Pointer to packet's standard metadata.
1905 * @param[in] pkt Packet on which to operate.
1906 */
1907static __inline int
1908NETIO_PKT_PREPEND_AVAIL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1909{
1910 return (pkt->__packet.bits.__offset << 6) +
1911 NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt);
1912}
1913
1914
1915/** Return the number of bytes which could be prepended to a packet, using a
1916 * metadata pointer to speed the operation.
1917 * See @ref netio_populate_prepend_buffer() to get a full description of
1918 * prepending.
1919 * @ingroup egress
1920 *
1921 * @param[in,out] mmd Pointer to packet's minimal metadata.
1922 * @param[in] pkt Packet on which to operate.
1923 */
1924static __inline int
1925NETIO_PKT_PREPEND_AVAIL_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1926{
1927 return (pkt->__packet.bits.__offset << 6) + mmd->l2_offset;
1928}
1929
1930
1931/** Return the number of bytes which could be prepended to a packet.
1932 * See @ref netio_populate_prepend_buffer() to get a full description of
1933 * prepending.
1934 * @ingroup egress
1935 *
1936 * @param[in] pkt Packet on which to operate.
1937 */
1938static __inline int
1939NETIO_PKT_PREPEND_AVAIL(netio_pkt_t* pkt)
1940{
1941 if (NETIO_PKT_IS_MINIMAL(pkt))
1942 {
1943 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1944
1945 return NETIO_PKT_PREPEND_AVAIL_MM(mmd, pkt);
1946 }
1947 else
1948 {
1949 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1950
1951 return NETIO_PKT_PREPEND_AVAIL_M(mda, pkt);
1952 }
1953}
1954
1955
1956/** Flush a packet's minimal metadata from the cache, using a metadata pointer
1957 * to speed the operation.
1958 * @ingroup egress
1959 *
1960 * @param[in] mmd Pointer to packet's minimal metadata.
1961 * @param[in] pkt Packet on which to operate.
1962 */
1963static __inline void
1964NETIO_PKT_FLUSH_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,
1965 netio_pkt_t* pkt)
1966{
1967}
1968
1969
1970/** Invalidate a packet's minimal metadata from the cache, using a metadata
1971 * pointer to speed the operation.
1972 * @ingroup egress
1973 *
1974 * @param[in] mmd Pointer to packet's minimal metadata.
1975 * @param[in] pkt Packet on which to operate.
1976 */
1977static __inline void
1978NETIO_PKT_INV_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,
1979 netio_pkt_t* pkt)
1980{
1981}
1982
1983
1984/** Flush and then invalidate a packet's minimal metadata from the cache,
1985 * using a metadata pointer to speed the operation.
1986 * @ingroup egress
1987 *
1988 * @param[in] mmd Pointer to packet's minimal metadata.
1989 * @param[in] pkt Packet on which to operate.
1990 */
1991static __inline void
1992NETIO_PKT_FLUSH_INV_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,
1993 netio_pkt_t* pkt)
1994{
1995}
1996
1997
1998/** Flush a packet's metadata from the cache, using a metadata pointer
1999 * to speed the operation.
2000 * @ingroup ingress
2001 *
2002 * @param[in] mda Pointer to packet's minimal metadata.
2003 * @param[in] pkt Packet on which to operate.
2004 */
2005static __inline void
2006NETIO_PKT_FLUSH_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
2007{
2008}
2009
2010
2011/** Invalidate a packet's metadata from the cache, using a metadata
2012 * pointer to speed the operation.
2013 * @ingroup ingress
2014 *
2015 * @param[in] mda Pointer to packet's metadata.
2016 * @param[in] pkt Packet on which to operate.
2017 */
2018static __inline void
2019NETIO_PKT_INV_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
2020{
2021}
2022
2023
2024/** Flush and then invalidate a packet's metadata from the cache,
2025 * using a metadata pointer to speed the operation.
2026 * @ingroup ingress
2027 *
2028 * @param[in] mda Pointer to packet's metadata.
2029 * @param[in] pkt Packet on which to operate.
2030 */
2031static __inline void
2032NETIO_PKT_FLUSH_INV_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
2033{
2034}
2035
2036
2037/** Flush a packet's minimal metadata from the cache.
2038 * @ingroup egress
2039 *
2040 * @param[in] pkt Packet on which to operate.
2041 */
2042static __inline void
2043NETIO_PKT_FLUSH_MINIMAL_METADATA(netio_pkt_t* pkt)
2044{
2045}
2046
2047
2048/** Invalidate a packet's minimal metadata from the cache.
2049 * @ingroup egress
2050 *
2051 * @param[in] pkt Packet on which to operate.
2052 */
2053static __inline void
2054NETIO_PKT_INV_MINIMAL_METADATA(netio_pkt_t* pkt)
2055{
2056}
2057
2058
2059/** Flush and then invalidate a packet's minimal metadata from the cache.
2060 * @ingroup egress
2061 *
2062 * @param[in] pkt Packet on which to operate.
2063 */
2064static __inline void
2065NETIO_PKT_FLUSH_INV_MINIMAL_METADATA(netio_pkt_t* pkt)
2066{
2067}
2068
2069
2070/** Flush a packet's metadata from the cache.
2071 * @ingroup ingress
2072 *
2073 * @param[in] pkt Packet on which to operate.
2074 */
2075static __inline void
2076NETIO_PKT_FLUSH_METADATA(netio_pkt_t* pkt)
2077{
2078}
2079
2080
2081/** Invalidate a packet's metadata from the cache.
2082 * @ingroup ingress
2083 *
2084 * @param[in] pkt Packet on which to operate.
2085 */
2086static __inline void
2087NETIO_PKT_INV_METADATA(netio_pkt_t* pkt)
2088{
2089}
2090
2091
2092/** Flush and then invalidate a packet's metadata from the cache.
2093 * @ingroup ingress
2094 *
2095 * @param[in] pkt Packet on which to operate.
2096 */
2097static __inline void
2098NETIO_PKT_FLUSH_INV_METADATA(netio_pkt_t* pkt)
2099{
2100}
2101
2102/** Number of NUMA nodes we can distribute buffers to.
2103 * @ingroup setup */
2104#define NETIO_NUM_NODE_WEIGHTS 16
2105
2106/**
2107 * @brief An object for specifying the characteristics of NetIO communication
2108 * endpoint.
2109 *
2110 * @ingroup setup
2111 *
2112 * The @ref netio_input_register() function uses this structure to define
2113 * how an application tile will communicate with an IPP.
2114 *
2115 *
2116 * Future updates to NetIO may add new members to this structure,
2117 * which can affect the success of the registration operation. Thus,
2118 * if dynamically initializing the structure, applications are urged to
2119 * zero it out first, for example:
2120 *
2121 * @code
2122 * netio_input_config_t config;
2123 * memset(&config, 0, sizeof (config));
2124 * config.flags = NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE;
2125 * config.num_receive_packets = NETIO_MAX_RECEIVE_PKTS;
2126 * config.queue_id = 0;
2127 * .
2128 * .
2129 * .
2130 * @endcode
2131 *
2132 * since that guarantees that any unused structure members, including
2133 * members which did not exist when the application was first developed,
2134 * will not have unexpected values.
2135 *
2136 * If statically initializing the structure, we strongly recommend use of
2137 * C99-style named initializers, for example:
2138 *
2139 * @code
2140 * netio_input_config_t config = {
2141 * .flags = NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE,
2142 * .num_receive_packets = NETIO_MAX_RECEIVE_PKTS,
2143 * .queue_id = 0,
2144 * },
2145 * @endcode
2146 *
2147 * instead of the old-style structure initialization:
2148 *
2149 * @code
2150 * // Bad example! Currently equivalent to the above, but don't do this.
2151 * netio_input_config_t config = {
2152 * NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE, NETIO_MAX_RECEIVE_PKTS, 0
2153 * },
2154 * @endcode
2155 *
2156 * since the C99 style requires no changes to the code if elements of the
2157 * config structure are rearranged. (It also makes the initialization much
2158 * easier to understand.)
2159 *
2160 * Except for items which address a particular tile's transmit or receive
2161 * characteristics, such as the ::NETIO_RECV flag, applications are advised
2162 * to specify the same set of configuration data on all registrations.
2163 * This prevents differing results if multiple tiles happen to do their
2164 * registration operations in a different order on different invocations of
2165 * the application. This is particularly important for things like link
2166 * management flags, and buffer size and homing specifications.
2167 *
2168 * Unless the ::NETIO_FIXED_BUFFER_VA flag is specified in flags, the NetIO
2169 * buffer pool is automatically created and mapped into the application's
2170 * virtual address space at an address chosen by the operating system,
2171 * using the common memory (cmem) facility in the Tilera Multicore
2172 * Components library. The cmem facility allows multiple processes to gain
2173 * access to shared memory which is mapped into each process at an
2174 * identical virtual address. In order for this to work, the processes
2175 * must have a common ancestor, which must create the common memory using
2176 * tmc_cmem_init().
2177 *
2178 * In programs using the iLib process creation API, or in programs which use
2179 * only one process (which include programs using the pthreads library),
2180 * tmc_cmem_init() is called automatically. All other applications
2181 * must call it explicitly, before any child processes which might call
2182 * netio_input_register() are created.
2183 */
2184typedef struct
2185{
2186 /** Registration characteristics.
2187
2188 This value determines several characteristics of the registration;
2189 flags for different types of behavior are ORed together to make the
2190 final flag value. Generally applications should specify exactly
2191 one flag from each of the following categories:
2192
2193 - Whether the application will be receiving packets on this queue
2194 (::NETIO_RECV or ::NETIO_NO_RECV).
2195
2196 - Whether the application will be transmitting packets on this queue,
2197 and if so, whether it will request egress checksum calculation
2198 (::NETIO_XMIT, ::NETIO_XMIT_CSUM, or ::NETIO_NO_XMIT). It is
2199 legal to call netio_get_buffer() without one of the XMIT flags,
2200 as long as ::NETIO_RECV is specified; in this case, the retrieved
2201 buffers must be passed to another tile for transmission.
2202
2203 - Whether the application expects any vendor-specific tags in
2204 its packets' L2 headers (::NETIO_TAG_NONE, ::NETIO_TAG_BRCM,
2205 or ::NETIO_TAG_MRVL). This must match the configuration of the
2206 target IPP.
2207
2208 To accommodate applications written to previous versions of the NetIO
2209 interface, none of the flags above are currently required; if omitted,
2210 NetIO behaves more or less as if ::NETIO_RECV | ::NETIO_XMIT_CSUM |
2211 ::NETIO_TAG_NONE were used. However, explicit specification of
2212 the relevant flags allows NetIO to do a better job of resource
2213 allocation, allows earlier detection of certain configuration errors,
2214 and may enable advanced features or higher performance in the future,
2215 so their use is strongly recommended.
2216
2217 Note that specifying ::NETIO_NO_RECV along with ::NETIO_NO_XMIT
2218 is a special case, intended primarily for use by programs which
2219 retrieve network statistics or do link management operations.
2220 When these flags are both specified, the resulting queue may not
2221 be used with NetIO routines other than netio_get(), netio_set(),
2222 and netio_input_unregister(). See @ref link for more information
2223 on link management.
2224
2225 Other flags are optional; their use is described below.
2226 */
2227 int flags;
2228
2229 /** Interface name. This is a string which identifies the specific
2230 Ethernet controller hardware to be used. The format of the string
2231 is a device type and a device index, separated by a slash; so,
2232 the first 10 Gigabit Ethernet controller is named "xgbe/0", while
2233 the second 10/100/1000 Megabit Ethernet controller is named "gbe/1".
2234 */
2235 const char* interface;
2236
2237 /** Receive packet queue size. This specifies the maximum number
2238 of ingress packets that can be received on this queue without
2239 being retrieved by @ref netio_get_packet(). If the IPP's distribution
2240 algorithm calls for a packet to be sent to this queue, and this
2241 number of packets are already pending there, the new packet
2242 will either be discarded, or sent to another tile registered
2243 for the same queue_id (see @ref drops). This value must
2244 be at least ::NETIO_MIN_RECEIVE_PKTS, can always be at least
2245 ::NETIO_MAX_RECEIVE_PKTS, and may be larger than that on certain
2246 interfaces.
2247 */
2248 int num_receive_packets;
2249
2250 /** The queue ID being requested. Legal values for this range from 0
2251 to ::NETIO_MAX_QUEUE_ID, inclusive. ::NETIO_MAX_QUEUE_ID is always
2252 greater than or equal to the number of tiles; this allows one queue
2253 for each tile, plus at least one additional queue. Some applications
2254 may wish to use the additional queue as a destination for unwanted
2255 packets, since packets delivered to queues for which no tiles have
2256 registered are discarded.
2257 */
2258 unsigned int queue_id;
2259
2260 /** Maximum number of small send buffers to be held in the local empty
2261 buffer cache. This specifies the size of the area which holds
2262 empty small egress buffers requested from the IPP but not yet
2263 retrieved via @ref netio_get_buffer(). This value must be greater
2264 than zero if the application will ever use @ref netio_get_buffer()
2265 to allocate empty small egress buffers; it may be no larger than
2266 ::NETIO_MAX_SEND_BUFFERS. See @ref epp for more details on empty
2267 buffer caching.
2268 */
2269 int num_send_buffers_small_total;
2270
2271 /** Number of small send buffers to be preallocated at registration.
2272 If this value is nonzero, the specified number of empty small egress
2273 buffers will be requested from the IPP during the netio_input_register
2274 operation; this may speed the execution of @ref netio_get_buffer().
2275 This may be no larger than @ref num_send_buffers_small_total. See @ref
2276 epp for more details on empty buffer caching.
2277 */
2278 int num_send_buffers_small_prealloc;
2279
2280 /** Maximum number of large send buffers to be held in the local empty
2281 buffer cache. This specifies the size of the area which holds empty
2282 large egress buffers requested from the IPP but not yet retrieved via
2283 @ref netio_get_buffer(). This value must be greater than zero if the
2284 application will ever use @ref netio_get_buffer() to allocate empty
2285 large egress buffers; it may be no larger than ::NETIO_MAX_SEND_BUFFERS.
2286 See @ref epp for more details on empty buffer caching.
2287 */
2288 int num_send_buffers_large_total;
2289
2290 /** Number of large send buffers to be preallocated at registration.
2291 If this value is nonzero, the specified number of empty large egress
2292 buffers will be requested from the IPP during the netio_input_register
2293 operation; this may speed the execution of @ref netio_get_buffer().
2294 This may be no larger than @ref num_send_buffers_large_total. See @ref
2295 epp for more details on empty buffer caching.
2296 */
2297 int num_send_buffers_large_prealloc;
2298
2299 /** Maximum number of jumbo send buffers to be held in the local empty
2300 buffer cache. This specifies the size of the area which holds empty
2301 jumbo egress buffers requested from the IPP but not yet retrieved via
2302 @ref netio_get_buffer(). This value must be greater than zero if the
2303 application will ever use @ref netio_get_buffer() to allocate empty
2304 jumbo egress buffers; it may be no larger than ::NETIO_MAX_SEND_BUFFERS.
2305 See @ref epp for more details on empty buffer caching.
2306 */
2307 int num_send_buffers_jumbo_total;
2308
2309 /** Number of jumbo send buffers to be preallocated at registration.
2310 If this value is nonzero, the specified number of empty jumbo egress
2311 buffers will be requested from the IPP during the netio_input_register
2312 operation; this may speed the execution of @ref netio_get_buffer().
2313 This may be no larger than @ref num_send_buffers_jumbo_total. See @ref
2314 epp for more details on empty buffer caching.
2315 */
2316 int num_send_buffers_jumbo_prealloc;
2317
2318 /** Total packet buffer size. This determines the total size, in bytes,
2319 of the NetIO buffer pool. Note that the maximum number of available
2320 buffers of each size is determined during hypervisor configuration
2321 (see the <em>System Programmer's Guide</em> for details); this just
2322 influences how much host memory is allocated for those buffers.
2323
2324 The buffer pool is allocated from common memory, which will be
2325 automatically initialized if needed. If your buffer pool is larger
2326 than 240 MB, you might need to explicitly call @c tmc_cmem_init(),
2327 as described in the Application Libraries Reference Manual (UG227).
2328
2329 Packet buffers are currently allocated in chunks of 16 MB; this
2330 value will be rounded up to the next larger multiple of 16 MB.
2331 If this value is zero, a default of 32 MB will be used; this was
2332 the value used by previous versions of NetIO. Note that taking this
2333 default also affects the placement of buffers on Linux NUMA nodes.
2334 See @ref buffer_node_weights for an explanation of buffer placement.
2335
2336 In order to successfully allocate packet buffers, Linux must have
2337 available huge pages on the relevant Linux NUMA nodes. See the
2338 <em>System Programmer's Guide</em> for information on configuring
2339 huge page support in Linux.
2340 */
2341 uint64_t total_buffer_size;
2342
2343 /** Buffer placement weighting factors.
2344
2345 This array specifies the relative amount of buffering to place
2346 on each of the available Linux NUMA nodes. This array is
2347 indexed by the NUMA node, and the values in the array are
2348 proportional to the amount of buffer space to allocate on that
2349 node.
2350
2351 If memory striping is enabled in the Hypervisor, then there is
2352 only one logical NUMA node (node 0). In that case, NetIO will by
2353 default ignore the suggested buffer node weights, and buffers
2354 will be striped across the physical memory controllers. See
2355 UG209 System Programmer's Guide for a description of the
2356 hypervisor option that controls memory striping.
2357
2358 If memory striping is disabled, then there are up to four NUMA
2359 nodes, corresponding to the four DDRAM controllers in the TILE
2360 processor architecture. See UG100 Tile Processor Architecture
2361 Overview for a diagram showing the location of each of the DDRAM
2362 controllers relative to the tile array.
2363
2364 For instance, if memory striping is disabled, the following
2365 configuration strucure:
2366
2367 @code
2368 netio_input_config_t config = {
2369 .
2370 .
2371 .
2372 .total_buffer_size = 4 * 16 * 1024 * 1024;
2373 .buffer_node_weights = { 1, 0, 1, 0 },
2374 },
2375 @endcode
2376
2377 would result in 32 MB of buffers being placed on controller 0, and
2378 32 MB on controller 2. (Since buffers are allocated in units of
2379 16 MB, some sets of weights will not be able to be matched exactly.)
2380
2381 For the weights to be effective, @ref total_buffer_size must be
2382 nonzero. If @ref total_buffer_size is zero, causing the default
2383 32 MB of buffer space to be used, then any specified weights will
2384 be ignored, and buffers will positioned as they were in previous
2385 versions of NetIO:
2386
2387 - For xgbe/0 and gbe/0, 16 MB of buffers will be placed on controller 1,
2388 and the other 16 MB will be placed on controller 2.
2389
2390 - For xgbe/1 and gbe/1, 16 MB of buffers will be placed on controller 2,
2391 and the other 16 MB will be placed on controller 3.
2392
2393 If @ref total_buffer_size is nonzero, but all weights are zero,
2394 then all buffer space will be allocated on Linux NUMA node zero.
2395
2396 By default, the specified buffer placement is treated as a hint;
2397 if sufficient free memory is not available on the specified
2398 controllers, the buffers will be allocated elsewhere. However,
2399 if the ::NETIO_STRICT_HOMING flag is specified in @ref flags, then a
2400 failure to allocate buffer space exactly as requested will cause the
2401 registration operation to fail with an error of ::NETIO_CANNOT_HOME.
2402
2403 Note that maximal network performance cannot be achieved with
2404 only one memory controller.
2405 */
2406 uint8_t buffer_node_weights[NETIO_NUM_NODE_WEIGHTS];
2407
2408 /** Fixed virtual address for packet buffers. Only valid when
2409 ::NETIO_FIXED_BUFFER_VA is specified in @ref flags; see the
2410 description of that flag for details.
2411 */
2412 void* fixed_buffer_va;
2413
2414 /**
2415 Maximum number of outstanding send packet requests. This value is
2416 only relevant when an EPP is in use; it determines the number of
2417 slots in the EPP's outgoing packet queue which this tile is allowed
2418 to consume, and thus the number of packets which may be sent before
2419 the sending tile must wait for an acknowledgment from the EPP.
2420 Modifying this value is generally only helpful when using @ref
2421 netio_send_packet_vector(), where it can help improve performance by
2422 allowing a single vector send operation to process more packets.
2423 Typically it is not specified, and the default, which divides the
2424 outgoing packet slots evenly between all tiles on the chip, is used.
2425
2426 If a registration asks for more outgoing packet queue slots than are
2427 available, ::NETIO_TOOMANY_XMIT will be returned. The total number
2428 of packet queue slots which are available for all tiles for each EPP
2429 is subject to change, but is currently ::NETIO_TOTAL_SENDS_OUTSTANDING.
2430
2431
2432 This value is ignored if ::NETIO_XMIT is not specified in flags.
2433 If you want to specify a large value here for a specific tile, you are
2434 advised to specify NETIO_NO_XMIT on other, non-transmitting tiles so
2435 that they do not consume a default number of packet slots. Any tile
2436 transmitting is required to have at least ::NETIO_MIN_SENDS_OUTSTANDING
2437 slots allocated to it; values less than that will be silently
2438 increased by the NetIO library.
2439 */
2440 int num_sends_outstanding;
2441}
2442netio_input_config_t;
2443
2444
2445/** Registration flags; used in the @ref netio_input_config_t structure.
2446 * @addtogroup setup
2447 */
2448/** @{ */
2449
2450/** Fail a registration request if we can't put packet buffers
2451 on the specified memory controllers. */
2452#define NETIO_STRICT_HOMING 0x00000002
2453
2454/** This application expects no tags on its L2 headers. */
2455#define NETIO_TAG_NONE 0x00000004
2456
2457/** This application expects Marvell extended tags on its L2 headers. */
2458#define NETIO_TAG_MRVL 0x00000008
2459
2460/** This application expects Broadcom tags on its L2 headers. */
2461#define NETIO_TAG_BRCM 0x00000010
2462
2463/** This registration may call routines which receive packets. */
2464#define NETIO_RECV 0x00000020
2465
2466/** This registration may not call routines which receive packets. */
2467#define NETIO_NO_RECV 0x00000040
2468
2469/** This registration may call routines which transmit packets. */
2470#define NETIO_XMIT 0x00000080
2471
2472/** This registration may call routines which transmit packets with
2473 checksum acceleration. */
2474#define NETIO_XMIT_CSUM 0x00000100
2475
2476/** This registration may not call routines which transmit packets. */
2477#define NETIO_NO_XMIT 0x00000200
2478
2479/** This registration wants NetIO buffers mapped at an application-specified
2480 virtual address.
2481
2482 NetIO buffers are by default created by the TMC common memory facility,
2483 which must be configured by a common ancestor of all processes sharing
2484 a network interface. When this flag is specified, NetIO buffers are
2485 instead mapped at an address chosen by the application (and specified
2486 in @ref netio_input_config_t::fixed_buffer_va). This allows multiple
2487 unrelated but cooperating processes to share a NetIO interface.
2488 All processes sharing the same interface must specify this flag,
2489 and all must specify the same fixed virtual address.
2490
2491 @ref netio_input_config_t::fixed_buffer_va must be a
2492 multiple of 16 MB, and the packet buffers will occupy @ref
2493 netio_input_config_t::total_buffer_size bytes of virtual address
2494 space, beginning at that address. If any of those virtual addresses
2495 are currently occupied by other memory objects, like application or
2496 shared library code or data, @ref netio_input_register() will return
2497 ::NETIO_FAULT. While it is impossible to provide a fixed_buffer_va
2498 which will work for all applications, a good first guess might be to
2499 use 0xb0000000 minus @ref netio_input_config_t::total_buffer_size.
2500 If that fails, it might be helpful to consult the running application's
2501 virtual address description file (/proc/<em>pid</em>/maps) to see
2502 which regions of virtual address space are available.
2503 */
2504#define NETIO_FIXED_BUFFER_VA 0x00000400
2505
2506/** This registration call will not complete unless the network link
2507 is up. The process will wait several seconds for this to happen (the
2508 precise interval is link-dependent), but if the link does not come up,
2509 ::NETIO_LINK_DOWN will be returned. This flag is the default if
2510 ::NETIO_NOREQUIRE_LINK_UP is not specified. Note that this flag by
2511 itself does not request that the link be brought up; that can be done
2512 with the ::NETIO_AUTO_LINK_UPDN or ::NETIO_AUTO_LINK_UP flags (the
2513 latter is the default if no NETIO_AUTO_LINK_xxx flags are specified),
2514 or by explicitly setting the link's desired state via netio_set().
2515 If the link is not brought up by one of those methods, and this flag
2516 is specified, the registration operation will return ::NETIO_LINK_DOWN.
2517 This flag is ignored if it is specified along with ::NETIO_NO_XMIT and
2518 ::NETIO_NO_RECV. See @ref link for more information on link
2519 management.
2520 */
2521#define NETIO_REQUIRE_LINK_UP 0x00000800
2522
2523/** This registration call will complete even if the network link is not up.
2524 Whenever the link is not up, packets will not be sent or received:
2525 netio_get_packet() will return ::NETIO_NOPKT once all queued packets
2526 have been drained, and netio_send_packet() and similar routines will
2527 return NETIO_QUEUE_FULL once the outgoing packet queue in the EPP
2528 or the I/O shim is full. See @ref link for more information on link
2529 management.
2530 */
2531#define NETIO_NOREQUIRE_LINK_UP 0x00001000
2532
2533#ifndef __DOXYGEN__
2534/*
2535 * These are part of the implementation of the NETIO_AUTO_LINK_xxx flags,
2536 * but should not be used directly by applications, and are thus not
2537 * documented.
2538 */
2539#define _NETIO_AUTO_UP 0x00002000
2540#define _NETIO_AUTO_DN 0x00004000
2541#define _NETIO_AUTO_PRESENT 0x00008000
2542#endif
2543
2544/** Set the desired state of the link to up, allowing any speeds which are
2545 supported by the link hardware, as part of this registration operation.
2546 Do not take down the link automatically. This is the default if
2547 no other NETIO_AUTO_LINK_xxx flags are specified. This flag is ignored
2548 if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.
2549 See @ref link for more information on link management.
2550 */
2551#define NETIO_AUTO_LINK_UP (_NETIO_AUTO_PRESENT | _NETIO_AUTO_UP)
2552
2553/** Set the desired state of the link to up, allowing any speeds which are
2554 supported by the link hardware, as part of this registration operation.
2555 Set the desired state of the link to down the next time no tiles are
2556 registered for packet reception or transmission. This flag is ignored
2557 if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.
2558 See @ref link for more information on link management.
2559 */
2560#define NETIO_AUTO_LINK_UPDN (_NETIO_AUTO_PRESENT | _NETIO_AUTO_UP | \
2561 _NETIO_AUTO_DN)
2562
2563/** Set the desired state of the link to down the next time no tiles are
2564 registered for packet reception or transmission. This flag is ignored
2565 if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.
2566 See @ref link for more information on link management.
2567 */
2568#define NETIO_AUTO_LINK_DN (_NETIO_AUTO_PRESENT | _NETIO_AUTO_DN)
2569
2570/** Do not bring up the link automatically as part of this registration
2571 operation. Do not take down the link automatically. This flag
2572 is ignored if it is specified along with ::NETIO_NO_XMIT and
2573 ::NETIO_NO_RECV. See @ref link for more information on link management.
2574 */
2575#define NETIO_AUTO_LINK_NONE _NETIO_AUTO_PRESENT
2576
2577
2578/** Minimum number of receive packets. */
2579#define NETIO_MIN_RECEIVE_PKTS 16
2580
2581/** Lower bound on the maximum number of receive packets; may be higher
2582 than this on some interfaces. */
2583#define NETIO_MAX_RECEIVE_PKTS 128
2584
2585/** Maximum number of send buffers, per packet size. */
2586#define NETIO_MAX_SEND_BUFFERS 16
2587
2588/** Number of EPP queue slots, and thus outstanding sends, per EPP. */
2589#define NETIO_TOTAL_SENDS_OUTSTANDING 2015
2590
2591/** Minimum number of EPP queue slots, and thus outstanding sends, per
2592 * transmitting tile. */
2593#define NETIO_MIN_SENDS_OUTSTANDING 16
2594
2595
2596/**@}*/
2597
2598#ifndef __DOXYGEN__
2599
2600/**
2601 * An object for providing Ethernet packets to a process.
2602 */
2603struct __netio_queue_impl_t;
2604
2605/**
2606 * An object for managing the user end of a NetIO queue.
2607 */
2608struct __netio_queue_user_impl_t;
2609
2610#endif /* !__DOXYGEN__ */
2611
2612
2613/** A netio_queue_t describes a NetIO communications endpoint.
2614 * @ingroup setup
2615 */
2616typedef struct
2617{
2618#ifdef __DOXYGEN__
2619 uint8_t opaque[8]; /**< This is an opaque structure. */
2620#else
2621 struct __netio_queue_impl_t* __system_part; /**< The system part. */
2622 struct __netio_queue_user_impl_t* __user_part; /**< The user part. */
2623#ifdef _NETIO_PTHREAD
2624 _netio_percpu_mutex_t lock; /**< Queue lock. */
2625#endif
2626#endif
2627}
2628netio_queue_t;
2629
2630
2631/**
2632 * @brief Packet send context.
2633 *
2634 * @ingroup egress
2635 *
2636 * Packet send context for use with netio_send_packet_prepare and _commit.
2637 */
2638typedef struct
2639{
2640#ifdef __DOXYGEN__
2641 uint8_t opaque[44]; /**< This is an opaque structure. */
2642#else
2643 uint8_t flags; /**< Defined below */
2644 uint8_t datalen; /**< Number of valid words pointed to by data. */
2645 uint32_t request[9]; /**< Request to be sent to the EPP or shim. Note
2646 that this is smaller than the 11-word maximum
2647 request size, since some constant values are
2648 not saved in the context. */
2649 uint32_t *data; /**< Data to be sent to the EPP or shim via IDN. */
2650#endif
2651}
2652netio_send_pkt_context_t;
2653
2654
2655#ifndef __DOXYGEN__
2656#define SEND_PKT_CTX_USE_EPP 1 /**< We're sending to an EPP. */
2657#define SEND_PKT_CTX_SEND_CSUM 2 /**< Request includes a checksum. */
2658#endif
2659
2660/**
2661 * @brief Packet vector entry.
2662 *
2663 * @ingroup egress
2664 *
2665 * This data structure is used with netio_send_packet_vector() to send multiple
2666 * packets with one NetIO call. The structure should be initialized by
2667 * calling netio_pkt_vector_set(), rather than by setting the fields
2668 * directly.
2669 *
2670 * This structure is guaranteed to be a power of two in size, no
2671 * bigger than one L2 cache line, and to be aligned modulo its size.
2672 */
2673typedef struct
2674#ifndef __DOXYGEN__
2675__attribute__((aligned(8)))
2676#endif
2677{
2678 /** Reserved for use by the user application. When initialized with
2679 * the netio_set_pkt_vector_entry() function, this field is guaranteed
2680 * to be visible to readers only after all other fields are already
2681 * visible. This way it can be used as a valid flag or generation
2682 * counter. */
2683 uint8_t user_data;
2684
2685 /* Structure members below this point should not be accessed directly by
2686 * applications, as they may change in the future. */
2687
2688 /** Low 8 bits of the packet address to send. The high bits are
2689 * acquired from the 'handle' field. */
2690 uint8_t buffer_address_low;
2691
2692 /** Number of bytes to transmit. */
2693 uint16_t size;
2694
2695 /** The raw handle from a netio_pkt_t. If this is NETIO_PKT_HANDLE_NONE,
2696 * this vector entry will be skipped and no packet will be transmitted. */
2697 netio_pkt_handle_t handle;
2698}
2699netio_pkt_vector_entry_t;
2700
2701
2702/**
2703 * @brief Initialize fields in a packet vector entry.
2704 *
2705 * @ingroup egress
2706 *
2707 * @param[out] v Pointer to the vector entry to be initialized.
2708 * @param[in] pkt Packet to be transmitted when the vector entry is passed to
2709 * netio_send_packet_vector(). Note that the packet's attributes
2710 * (e.g., its L2 offset and length) are captured at the time this
2711 * routine is called; subsequent changes in those attributes will not
2712 * be reflected in the packet which is actually transmitted.
2713 * Changes in the packet's contents, however, will be so reflected.
2714 * If this is NULL, no packet will be transmitted.
2715 * @param[in] user_data User data to be set in the vector entry.
2716 * This function guarantees that the "user_data" field will become
2717 * visible to a reader only after all other fields have become visible.
2718 * This allows a structure in a ring buffer to be written and read
2719 * by a polling reader without any locks or other synchronization.
2720 */
2721static __inline void
2722netio_pkt_vector_set(volatile netio_pkt_vector_entry_t* v, netio_pkt_t* pkt,
2723 uint8_t user_data)
2724{
2725 if (pkt)
2726 {
2727 if (NETIO_PKT_IS_MINIMAL(pkt))
2728 {
2729 netio_pkt_minimal_metadata_t* mmd =
2730 (netio_pkt_minimal_metadata_t*) &pkt->__metadata;
2731 v->buffer_address_low = (uintptr_t) NETIO_PKT_L2_DATA_MM(mmd, pkt) & 0xFF;
2732 v->size = NETIO_PKT_L2_LENGTH_MM(mmd, pkt);
2733 }
2734 else
2735 {
2736 netio_pkt_metadata_t* mda = &pkt->__metadata;
2737 v->buffer_address_low = (uintptr_t) NETIO_PKT_L2_DATA_M(mda, pkt) & 0xFF;
2738 v->size = NETIO_PKT_L2_LENGTH_M(mda, pkt);
2739 }
2740 v->handle.word = pkt->__packet.word;
2741 }
2742 else
2743 {
2744 v->handle.word = 0; /* Set handle to NETIO_PKT_HANDLE_NONE. */
2745 }
2746
2747 __asm__("" : : : "memory");
2748
2749 v->user_data = user_data;
2750}
2751
2752
2753/**
2754 * Flags and structures for @ref netio_get() and @ref netio_set().
2755 * @ingroup config
2756 */
2757
2758/** @{ */
2759/** Parameter class; addr is a NETIO_PARAM_xxx value. */
2760#define NETIO_PARAM 0
2761/** Interface MAC address. This address is only valid with @ref netio_get().
2762 * The value is a 6-byte MAC address. Depending upon the overall system
2763 * design, a MAC address may or may not be available for each interface. */
2764#define NETIO_PARAM_MAC 0
2765
2766/** Determine whether to suspend output on the receipt of pause frames.
2767 * If the value is nonzero, the I/O shim will suspend output when a pause
2768 * frame is received. If the value is zero, pause frames will be ignored. */
2769#define NETIO_PARAM_PAUSE_IN 1
2770
2771/** Determine whether to send pause frames if the I/O shim packet FIFOs are
2772 * nearly full. If the value is zero, pause frames are not sent. If
2773 * the value is nonzero, it is the delay value which will be sent in any
2774 * pause frames which are output, in units of 512 bit times. */
2775#define NETIO_PARAM_PAUSE_OUT 2
2776
2777/** Jumbo frame support. The value is a 4-byte integer. If the value is
2778 * nonzero, the MAC will accept frames of up to 10240 bytes. If the value
2779 * is zero, the MAC will only accept frames of up to 1544 bytes. */
2780#define NETIO_PARAM_JUMBO 3
2781
2782/** I/O shim's overflow statistics register. The value is two 16-bit integers.
2783 * The first 16-bit value (or the low 16 bits, if the value is treated as a
2784 * 32-bit number) is the count of packets which were completely dropped and
2785 * not delivered by the shim. The second 16-bit value (or the high 16 bits,
2786 * if the value is treated as a 32-bit number) is the count of packets
2787 * which were truncated and thus only partially delivered by the shim. This
2788 * register is automatically reset to zero after it has been read.
2789 */
2790#define NETIO_PARAM_OVERFLOW 4
2791
2792/** IPP statistics. This address is only valid with @ref netio_get(). The
2793 * value is a netio_stat_t structure. Unlike the I/O shim statistics, the
2794 * IPP statistics are not all reset to zero on read; see the description
2795 * of the netio_stat_t for details. */
2796#define NETIO_PARAM_STAT 5
2797
2798/** Possible link state. The value is a combination of "NETIO_LINK_xxx"
2799 * flags. With @ref netio_get(), this will indicate which flags are
2800 * actually supported by the hardware.
2801 *
2802 * For historical reasons, specifying this value to netio_set() will have
2803 * the same behavior as using ::NETIO_PARAM_LINK_CONFIG, but this usage is
2804 * discouraged.
2805 */
2806#define NETIO_PARAM_LINK_POSSIBLE_STATE 6
2807
2808/** Link configuration. The value is a combination of "NETIO_LINK_xxx" flags.
2809 * With @ref netio_set(), this will attempt to immediately bring up the
2810 * link using whichever of the requested flags are supported by the
2811 * hardware, or take down the link if the flags are zero; if this is
2812 * not possible, an error will be returned. Many programs will want
2813 * to use ::NETIO_PARAM_LINK_DESIRED_STATE instead.
2814 *
2815 * For historical reasons, specifying this value to netio_get() will
2816 * have the same behavior as using ::NETIO_PARAM_LINK_POSSIBLE_STATE,
2817 * but this usage is discouraged.
2818 */
2819#define NETIO_PARAM_LINK_CONFIG NETIO_PARAM_LINK_POSSIBLE_STATE
2820
2821/** Current link state. This address is only valid with @ref netio_get().
2822 * The value is zero or more of the "NETIO_LINK_xxx" flags, ORed together.
2823 * If the link is down, the value ANDed with NETIO_LINK_SPEED will be
2824 * zero; if the link is up, the value ANDed with NETIO_LINK_SPEED will
2825 * result in exactly one of the NETIO_LINK_xxx values, indicating the
2826 * current speed. */
2827#define NETIO_PARAM_LINK_CURRENT_STATE 7
2828
2829/** Variant symbol for current state, retained for compatibility with
2830 * pre-MDE-2.1 programs. */
2831#define NETIO_PARAM_LINK_STATUS NETIO_PARAM_LINK_CURRENT_STATE
2832
2833/** Packet Coherence protocol. This address is only valid with @ref netio_get().
2834 * The value is nonzero if the interface is configured for cache-coherent DMA.
2835 */
2836#define NETIO_PARAM_COHERENT 8
2837
2838/** Desired link state. The value is a conbination of "NETIO_LINK_xxx"
2839 * flags, which specify the desired state for the link. With @ref
2840 * netio_set(), this will, in the background, attempt to bring up the link
2841 * using whichever of the requested flags are reasonable, or take down the
2842 * link if the flags are zero. The actual link up or down operation may
2843 * happen after this call completes. If the link state changes in the
2844 * future, the system will continue to try to get back to the desired link
2845 * state; for instance, if the link is brought up successfully, and then
2846 * the network cable is disconnected, the link will go down. However, the
2847 * desired state of the link is still up, so if the cable is reconnected,
2848 * the link will be brought up again.
2849 *
2850 * With @ref netio_get(), this will indicate the desired state for the
2851 * link, as set with a previous netio_set() call, or implicitly by a
2852 * netio_input_register() or netio_input_unregister() operation. This may
2853 * not reflect the current state of the link; to get that, use
2854 * ::NETIO_PARAM_LINK_CURRENT_STATE. */
2855#define NETIO_PARAM_LINK_DESIRED_STATE 9
2856
2857/** NetIO statistics structure. Retrieved using the ::NETIO_PARAM_STAT
2858 * address passed to @ref netio_get(). */
2859typedef struct
2860{
2861 /** Number of packets which have been received by the IPP and forwarded
2862 * to a tile's receive queue for processing. This value wraps at its
2863 * maximum, and is not cleared upon read. */
2864 uint32_t packets_received;
2865
2866 /** Number of packets which have been dropped by the IPP, because they could
2867 * not be received, or could not be forwarded to a tile. The former happens
2868 * when the IPP does not have a free packet buffer of suitable size for an
2869 * incoming frame. The latter happens when all potential destination tiles
2870 * for a packet, as defined by the group, bucket, and queue configuration,
2871 * have full receive queues. This value wraps at its maximum, and is not
2872 * cleared upon read. */
2873 uint32_t packets_dropped;
2874
2875 /*
2876 * Note: the #defines after each of the following four one-byte values
2877 * denote their location within the third word of the netio_stat_t. They
2878 * are intended for use only by the IPP implementation and are thus omitted
2879 * from the Doxygen output.
2880 */
2881
2882 /** Number of packets dropped because no worker was able to accept a new
2883 * packet. This value saturates at its maximum, and is cleared upon
2884 * read. */
2885 uint8_t drops_no_worker;
2886#ifndef __DOXYGEN__
2887#define NETIO_STAT_DROPS_NO_WORKER 0
2888#endif
2889
2890 /** Number of packets dropped because no small buffers were available.
2891 * This value saturates at its maximum, and is cleared upon read. */
2892 uint8_t drops_no_smallbuf;
2893#ifndef __DOXYGEN__
2894#define NETIO_STAT_DROPS_NO_SMALLBUF 1
2895#endif
2896
2897 /** Number of packets dropped because no large buffers were available.
2898 * This value saturates at its maximum, and is cleared upon read. */
2899 uint8_t drops_no_largebuf;
2900#ifndef __DOXYGEN__
2901#define NETIO_STAT_DROPS_NO_LARGEBUF 2
2902#endif
2903
2904 /** Number of packets dropped because no jumbo buffers were available.
2905 * This value saturates at its maximum, and is cleared upon read. */
2906 uint8_t drops_no_jumbobuf;
2907#ifndef __DOXYGEN__
2908#define NETIO_STAT_DROPS_NO_JUMBOBUF 3
2909#endif
2910}
2911netio_stat_t;
2912
2913
2914/** Link can run, should run, or is running at 10 Mbps. */
2915#define NETIO_LINK_10M 0x01
2916
2917/** Link can run, should run, or is running at 100 Mbps. */
2918#define NETIO_LINK_100M 0x02
2919
2920/** Link can run, should run, or is running at 1 Gbps. */
2921#define NETIO_LINK_1G 0x04
2922
2923/** Link can run, should run, or is running at 10 Gbps. */
2924#define NETIO_LINK_10G 0x08
2925
2926/** Link should run at the highest speed supported by the link and by
2927 * the device connected to the link. Only usable as a value for
2928 * the link's desired state; never returned as a value for the current
2929 * or possible states. */
2930#define NETIO_LINK_ANYSPEED 0x10
2931
2932/** All legal link speeds. */
2933#define NETIO_LINK_SPEED (NETIO_LINK_10M | \
2934 NETIO_LINK_100M | \
2935 NETIO_LINK_1G | \
2936 NETIO_LINK_10G | \
2937 NETIO_LINK_ANYSPEED)
2938
2939
2940/** MAC register class. Addr is a register offset within the MAC.
2941 * Registers within the XGbE and GbE MACs are documented in the Tile
2942 * Processor I/O Device Guide (UG104). MAC registers start at address
2943 * 0x4000, and do not include the MAC_INTERFACE registers. */
2944#define NETIO_MAC 1
2945
2946/** MDIO register class (IEEE 802.3 clause 22 format). Addr is the "addr"
2947 * member of a netio_mdio_addr_t structure. */
2948#define NETIO_MDIO 2
2949
2950/** MDIO register class (IEEE 802.3 clause 45 format). Addr is the "addr"
2951 * member of a netio_mdio_addr_t structure. */
2952#define NETIO_MDIO_CLAUSE45 3
2953
2954/** NetIO MDIO address type. Retrieved or provided using the ::NETIO_MDIO
2955 * address passed to @ref netio_get() or @ref netio_set(). */
2956typedef union
2957{
2958 struct
2959 {
2960 unsigned int reg:16; /**< MDIO register offset. For clause 22 access,
2961 must be less than 32. */
2962 unsigned int phy:5; /**< Which MDIO PHY to access. */
2963 unsigned int dev:5; /**< Which MDIO device to access within that PHY.
2964 Applicable for clause 45 access only; ignored
2965 for clause 22 access. */
2966 }
2967 bits; /**< Container for bitfields. */
2968 uint64_t addr; /**< Value to pass to @ref netio_get() or
2969 * @ref netio_set(). */
2970}
2971netio_mdio_addr_t;
2972
2973/** @} */
2974
2975#endif /* __NETIO_INTF_H__ */
diff --git a/arch/tile/kernel/Makefile b/arch/tile/kernel/Makefile
index 112b1e248f05..b4c8e8ec45dc 100644
--- a/arch/tile/kernel/Makefile
+++ b/arch/tile/kernel/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_SMP) += smpboot.o smp.o tlb.o
15obj-$(CONFIG_MODULES) += module.o 15obj-$(CONFIG_MODULES) += module.o
16obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 16obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
17obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o 17obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
18obj-$(CONFIG_PCI) += pci.o
diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c
index 77739cdd9462..dbc213adf5e1 100644
--- a/arch/tile/kernel/compat.c
+++ b/arch/tile/kernel/compat.c
@@ -21,7 +21,6 @@
21#include <linux/kdev_t.h> 21#include <linux/kdev_t.h>
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/fcntl.h> 23#include <linux/fcntl.h>
24#include <linux/smp_lock.h>
25#include <linux/uaccess.h> 24#include <linux/uaccess.h>
26#include <linux/signal.h> 25#include <linux/signal.h>
27#include <asm/syscalls.h> 26#include <asm/syscalls.h>
@@ -148,11 +147,11 @@ long tile_compat_sys_msgrcv(int msqid,
148#define compat_sys_readahead sys32_readahead 147#define compat_sys_readahead sys32_readahead
149#define compat_sys_sync_file_range compat_sys_sync_file_range2 148#define compat_sys_sync_file_range compat_sys_sync_file_range2
150 149
151/* The native 64-bit "struct stat" matches the 32-bit "struct stat64". */ 150/* We leverage the "struct stat64" type for 32-bit time_t/nsec. */
152#define compat_sys_stat64 sys_newstat 151#define compat_sys_stat64 sys_stat64
153#define compat_sys_lstat64 sys_newlstat 152#define compat_sys_lstat64 sys_lstat64
154#define compat_sys_fstat64 sys_newfstat 153#define compat_sys_fstat64 sys_fstat64
155#define compat_sys_fstatat64 sys_newfstatat 154#define compat_sys_fstatat64 sys_fstatat64
156 155
157/* The native sys_ptrace dynamically handles compat binaries. */ 156/* The native sys_ptrace dynamically handles compat binaries. */
158#define compat_sys_ptrace sys_ptrace 157#define compat_sys_ptrace sys_ptrace
diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c
index fb64b99959d4..dbb0dfc7bece 100644
--- a/arch/tile/kernel/compat_signal.c
+++ b/arch/tile/kernel/compat_signal.c
@@ -15,7 +15,6 @@
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/smp.h> 17#include <linux/smp.h>
18#include <linux/smp_lock.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/signal.h> 19#include <linux/signal.h>
21#include <linux/errno.h> 20#include <linux/errno.h>
@@ -291,12 +290,12 @@ long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr,
291 return ret; 290 return ret;
292} 291}
293 292
293/* The assembly shim for this function arranges to ignore the return value. */
294long compat_sys_rt_sigreturn(struct pt_regs *regs) 294long compat_sys_rt_sigreturn(struct pt_regs *regs)
295{ 295{
296 struct compat_rt_sigframe __user *frame = 296 struct compat_rt_sigframe __user *frame =
297 (struct compat_rt_sigframe __user *) compat_ptr(regs->sp); 297 (struct compat_rt_sigframe __user *) compat_ptr(regs->sp);
298 sigset_t set; 298 sigset_t set;
299 long r0;
300 299
301 if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) 300 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
302 goto badframe; 301 goto badframe;
@@ -309,13 +308,13 @@ long compat_sys_rt_sigreturn(struct pt_regs *regs)
309 recalc_sigpending(); 308 recalc_sigpending();
310 spin_unlock_irq(&current->sighand->siglock); 309 spin_unlock_irq(&current->sighand->siglock);
311 310
312 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0)) 311 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
313 goto badframe; 312 goto badframe;
314 313
315 if (compat_sys_sigaltstack(&frame->uc.uc_stack, NULL, regs) != 0) 314 if (compat_sys_sigaltstack(&frame->uc.uc_stack, NULL, regs) != 0)
316 goto badframe; 315 goto badframe;
317 316
318 return r0; 317 return 0;
319 318
320badframe: 319badframe:
321 force_sig(SIGSEGV, current); 320 force_sig(SIGSEGV, current);
diff --git a/arch/tile/kernel/early_printk.c b/arch/tile/kernel/early_printk.c
index 2c54fd43a8a0..493a0e66d916 100644
--- a/arch/tile/kernel/early_printk.c
+++ b/arch/tile/kernel/early_printk.c
@@ -54,7 +54,7 @@ void early_printk(const char *fmt, ...)
54void early_panic(const char *fmt, ...) 54void early_panic(const char *fmt, ...)
55{ 55{
56 va_list ap; 56 va_list ap;
57 raw_local_irq_disable_all(); 57 arch_local_irq_disable_all();
58 va_start(ap, fmt); 58 va_start(ap, fmt);
59 early_printk("Kernel panic - not syncing: "); 59 early_printk("Kernel panic - not syncing: ");
60 early_vprintk(fmt, ap); 60 early_vprintk(fmt, ap);
diff --git a/arch/tile/kernel/hardwall.c b/arch/tile/kernel/hardwall.c
index 1e54a7843410..e910530436e6 100644
--- a/arch/tile/kernel/hardwall.c
+++ b/arch/tile/kernel/hardwall.c
@@ -151,12 +151,12 @@ enum direction_protect {
151 151
152static void enable_firewall_interrupts(void) 152static void enable_firewall_interrupts(void)
153{ 153{
154 raw_local_irq_unmask_now(INT_UDN_FIREWALL); 154 arch_local_irq_unmask_now(INT_UDN_FIREWALL);
155} 155}
156 156
157static void disable_firewall_interrupts(void) 157static void disable_firewall_interrupts(void)
158{ 158{
159 raw_local_irq_mask_now(INT_UDN_FIREWALL); 159 arch_local_irq_mask_now(INT_UDN_FIREWALL);
160} 160}
161 161
162/* Set up hardwall on this cpu based on the passed hardwall_info. */ 162/* Set up hardwall on this cpu based on the passed hardwall_info. */
@@ -768,13 +768,13 @@ static int hardwall_release(struct inode *inode, struct file *file)
768} 768}
769 769
770static const struct file_operations dev_hardwall_fops = { 770static const struct file_operations dev_hardwall_fops = {
771 .open = nonseekable_open,
771 .unlocked_ioctl = hardwall_ioctl, 772 .unlocked_ioctl = hardwall_ioctl,
772#ifdef CONFIG_COMPAT 773#ifdef CONFIG_COMPAT
773 .compat_ioctl = hardwall_compat_ioctl, 774 .compat_ioctl = hardwall_compat_ioctl,
774#endif 775#endif
775 .flush = hardwall_flush, 776 .flush = hardwall_flush,
776 .release = hardwall_release, 777 .release = hardwall_release,
777 .llseek = noop_llseek,
778}; 778};
779 779
780static struct cdev hardwall_dev; 780static struct cdev hardwall_dev;
diff --git a/arch/tile/kernel/intvec_32.S b/arch/tile/kernel/intvec_32.S
index f5821626247f..5eed4a02bf62 100644
--- a/arch/tile/kernel/intvec_32.S
+++ b/arch/tile/kernel/intvec_32.S
@@ -1342,8 +1342,8 @@ handle_syscall:
1342 lw r20, r20 1342 lw r20, r20
1343 1343
1344 /* Jump to syscall handler. */ 1344 /* Jump to syscall handler. */
1345 jalr r20; .Lhandle_syscall_link: 1345 jalr r20
1346 FEEDBACK_REENTER(handle_syscall) 1346.Lhandle_syscall_link: /* value of "lr" after "jalr r20" above */
1347 1347
1348 /* 1348 /*
1349 * Write our r0 onto the stack so it gets restored instead 1349 * Write our r0 onto the stack so it gets restored instead
@@ -1352,6 +1352,9 @@ handle_syscall:
1352 PTREGS_PTR(r29, PTREGS_OFFSET_REG(0)) 1352 PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
1353 sw r29, r0 1353 sw r29, r0
1354 1354
1355.Lsyscall_sigreturn_skip:
1356 FEEDBACK_REENTER(handle_syscall)
1357
1355 /* Do syscall trace again, if requested. */ 1358 /* Do syscall trace again, if requested. */
1356 lw r30, r31 1359 lw r30, r31
1357 andi r30, r30, _TIF_SYSCALL_TRACE 1360 andi r30, r30, _TIF_SYSCALL_TRACE
@@ -1536,9 +1539,24 @@ STD_ENTRY_LOCAL(bad_intr)
1536 }; \ 1539 }; \
1537 STD_ENDPROC(_##x) 1540 STD_ENDPROC(_##x)
1538 1541
1542/*
1543 * Special-case sigreturn to not write r0 to the stack on return.
1544 * This is technically more efficient, but it also avoids difficulties
1545 * in the 64-bit OS when handling 32-bit compat code, since we must not
1546 * sign-extend r0 for the sigreturn return-value case.
1547 */
1548#define PTREGS_SYSCALL_SIGRETURN(x, reg) \
1549 STD_ENTRY(_##x); \
1550 addli lr, lr, .Lsyscall_sigreturn_skip - .Lhandle_syscall_link; \
1551 { \
1552 PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \
1553 j x \
1554 }; \
1555 STD_ENDPROC(_##x)
1556
1539PTREGS_SYSCALL(sys_execve, r3) 1557PTREGS_SYSCALL(sys_execve, r3)
1540PTREGS_SYSCALL(sys_sigaltstack, r2) 1558PTREGS_SYSCALL(sys_sigaltstack, r2)
1541PTREGS_SYSCALL(sys_rt_sigreturn, r0) 1559PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0)
1542PTREGS_SYSCALL(sys_cmpxchg_badaddr, r1) 1560PTREGS_SYSCALL(sys_cmpxchg_badaddr, r1)
1543 1561
1544/* Save additional callee-saves to pt_regs, put address in r4 and jump. */ 1562/* Save additional callee-saves to pt_regs, put address in r4 and jump. */
diff --git a/arch/tile/kernel/irq.c b/arch/tile/kernel/irq.c
index e63917687e99..128805ef8f2c 100644
--- a/arch/tile/kernel/irq.c
+++ b/arch/tile/kernel/irq.c
@@ -26,7 +26,7 @@
26#define IS_HW_CLEARED 1 26#define IS_HW_CLEARED 1
27 27
28/* 28/*
29 * The set of interrupts we enable for raw_local_irq_enable(). 29 * The set of interrupts we enable for arch_local_irq_enable().
30 * This is initialized to have just a single interrupt that the kernel 30 * This is initialized to have just a single interrupt that the kernel
31 * doesn't actually use as a sentinel. During kernel init, 31 * doesn't actually use as a sentinel. During kernel init,
32 * interrupts are added as the kernel gets prepared to support them. 32 * interrupts are added as the kernel gets prepared to support them.
@@ -225,7 +225,7 @@ void __cpuinit setup_irq_regs(void)
225 /* Enable interrupt delivery. */ 225 /* Enable interrupt delivery. */
226 unmask_irqs(~0UL); 226 unmask_irqs(~0UL);
227#if CHIP_HAS_IPI() 227#if CHIP_HAS_IPI()
228 raw_local_irq_unmask(INT_IPI_K); 228 arch_local_irq_unmask(INT_IPI_K);
229#endif 229#endif
230} 230}
231 231
diff --git a/arch/tile/kernel/machine_kexec.c b/arch/tile/kernel/machine_kexec.c
index ba7a265d6179..0d8b9e933487 100644
--- a/arch/tile/kernel/machine_kexec.c
+++ b/arch/tile/kernel/machine_kexec.c
@@ -182,13 +182,13 @@ static void kexec_find_and_set_command_line(struct kimage *image)
182 182
183 if ((entry & IND_SOURCE)) { 183 if ((entry & IND_SOURCE)) {
184 void *va = 184 void *va =
185 kmap_atomic_pfn(entry >> PAGE_SHIFT, KM_USER0); 185 kmap_atomic_pfn(entry >> PAGE_SHIFT);
186 r = kexec_bn2cl(va); 186 r = kexec_bn2cl(va);
187 if (r) { 187 if (r) {
188 command_line = r; 188 command_line = r;
189 break; 189 break;
190 } 190 }
191 kunmap_atomic(va, KM_USER0); 191 kunmap_atomic(va);
192 } 192 }
193 } 193 }
194 194
@@ -198,7 +198,7 @@ static void kexec_find_and_set_command_line(struct kimage *image)
198 198
199 hverr = hv_set_command_line( 199 hverr = hv_set_command_line(
200 (HV_VirtAddr) command_line, strlen(command_line)); 200 (HV_VirtAddr) command_line, strlen(command_line));
201 kunmap_atomic(command_line, KM_USER0); 201 kunmap_atomic(command_line);
202 } else { 202 } else {
203 pr_info("%s: no command line found; making empty\n", 203 pr_info("%s: no command line found; making empty\n",
204 __func__); 204 __func__);
diff --git a/arch/tile/kernel/messaging.c b/arch/tile/kernel/messaging.c
index 997e3933f726..0858ee6b520f 100644
--- a/arch/tile/kernel/messaging.c
+++ b/arch/tile/kernel/messaging.c
@@ -34,7 +34,7 @@ void __cpuinit init_messaging(void)
34 panic("hv_register_message_state: error %d", rc); 34 panic("hv_register_message_state: error %d", rc);
35 35
36 /* Make sure downcall interrupts will be enabled. */ 36 /* Make sure downcall interrupts will be enabled. */
37 raw_local_irq_unmask(INT_INTCTRL_K); 37 arch_local_irq_unmask(INT_INTCTRL_K);
38} 38}
39 39
40void hv_message_intr(struct pt_regs *regs, int intnum) 40void hv_message_intr(struct pt_regs *regs, int intnum)
diff --git a/arch/tile/kernel/pci.c b/arch/tile/kernel/pci.c
new file mode 100644
index 000000000000..a1ee25be9ad9
--- /dev/null
+++ b/arch/tile/kernel/pci.c
@@ -0,0 +1,621 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/pci.h>
17#include <linux/delay.h>
18#include <linux/string.h>
19#include <linux/init.h>
20#include <linux/capability.h>
21#include <linux/sched.h>
22#include <linux/errno.h>
23#include <linux/bootmem.h>
24#include <linux/irq.h>
25#include <linux/io.h>
26#include <linux/uaccess.h>
27
28#include <asm/processor.h>
29#include <asm/sections.h>
30#include <asm/byteorder.h>
31#include <asm/hv_driver.h>
32#include <hv/drv_pcie_rc_intf.h>
33
34
35/*
36 * Initialization flow and process
37 * -------------------------------
38 *
39 * This files containes the routines to search for PCI buses,
40 * enumerate the buses, and configure any attached devices.
41 *
42 * There are two entry points here:
43 * 1) tile_pci_init
44 * This sets up the pci_controller structs, and opens the
45 * FDs to the hypervisor. This is called from setup_arch() early
46 * in the boot process.
47 * 2) pcibios_init
48 * This probes the PCI bus(es) for any attached hardware. It's
49 * called by subsys_initcall. All of the real work is done by the
50 * generic Linux PCI layer.
51 *
52 */
53
54/*
55 * This flag tells if the platform is TILEmpower that needs
56 * special configuration for the PLX switch chip.
57 */
58int __write_once tile_plx_gen1;
59
60static struct pci_controller controllers[TILE_NUM_PCIE];
61static int num_controllers;
62
63static struct pci_ops tile_cfg_ops;
64
65
66/*
67 * We don't need to worry about the alignment of resources.
68 */
69resource_size_t pcibios_align_resource(void *data, const struct resource *res,
70 resource_size_t size, resource_size_t align)
71{
72 return res->start;
73}
74EXPORT_SYMBOL(pcibios_align_resource);
75
76/*
77 * Open a FD to the hypervisor PCI device.
78 *
79 * controller_id is the controller number, config type is 0 or 1 for
80 * config0 or config1 operations.
81 */
82static int __init tile_pcie_open(int controller_id, int config_type)
83{
84 char filename[32];
85 int fd;
86
87 sprintf(filename, "pcie/%d/config%d", controller_id, config_type);
88
89 fd = hv_dev_open((HV_VirtAddr)filename, 0);
90
91 return fd;
92}
93
94
95/*
96 * Get the IRQ numbers from the HV and set up the handlers for them.
97 */
98static int __init tile_init_irqs(int controller_id,
99 struct pci_controller *controller)
100{
101 char filename[32];
102 int fd;
103 int ret;
104 int x;
105 struct pcie_rc_config rc_config;
106
107 sprintf(filename, "pcie/%d/ctl", controller_id);
108 fd = hv_dev_open((HV_VirtAddr)filename, 0);
109 if (fd < 0) {
110 pr_err("PCI: hv_dev_open(%s) failed\n", filename);
111 return -1;
112 }
113 ret = hv_dev_pread(fd, 0, (HV_VirtAddr)(&rc_config),
114 sizeof(rc_config), PCIE_RC_CONFIG_MASK_OFF);
115 hv_dev_close(fd);
116 if (ret != sizeof(rc_config)) {
117 pr_err("PCI: wanted %zd bytes, got %d\n",
118 sizeof(rc_config), ret);
119 return -1;
120 }
121 /* Record irq_base so that we can map INTx to IRQ # later. */
122 controller->irq_base = rc_config.intr;
123
124 for (x = 0; x < 4; x++)
125 tile_irq_activate(rc_config.intr + x,
126 TILE_IRQ_HW_CLEAR);
127
128 if (rc_config.plx_gen1)
129 controller->plx_gen1 = 1;
130
131 return 0;
132}
133
134/*
135 * First initialization entry point, called from setup_arch().
136 *
137 * Find valid controllers and fill in pci_controller structs for each
138 * of them.
139 *
140 * Returns the number of controllers discovered.
141 */
142int __init tile_pci_init(void)
143{
144 int i;
145
146 pr_info("PCI: Searching for controllers...\n");
147
148 /* Do any configuration we need before using the PCIe */
149
150 for (i = 0; i < TILE_NUM_PCIE; i++) {
151 int hv_cfg_fd0 = -1;
152 int hv_cfg_fd1 = -1;
153 int hv_mem_fd = -1;
154 char name[32];
155 struct pci_controller *controller;
156
157 /*
158 * Open the fd to the HV. If it fails then this
159 * device doesn't exist.
160 */
161 hv_cfg_fd0 = tile_pcie_open(i, 0);
162 if (hv_cfg_fd0 < 0)
163 continue;
164 hv_cfg_fd1 = tile_pcie_open(i, 1);
165 if (hv_cfg_fd1 < 0) {
166 pr_err("PCI: Couldn't open config fd to HV "
167 "for controller %d\n", i);
168 goto err_cont;
169 }
170
171 sprintf(name, "pcie/%d/mem", i);
172 hv_mem_fd = hv_dev_open((HV_VirtAddr)name, 0);
173 if (hv_mem_fd < 0) {
174 pr_err("PCI: Could not open mem fd to HV!\n");
175 goto err_cont;
176 }
177
178 pr_info("PCI: Found PCI controller #%d\n", i);
179
180 controller = &controllers[num_controllers];
181
182 if (tile_init_irqs(i, controller)) {
183 pr_err("PCI: Could not initialize "
184 "IRQs, aborting.\n");
185 goto err_cont;
186 }
187
188 controller->index = num_controllers;
189 controller->hv_cfg_fd[0] = hv_cfg_fd0;
190 controller->hv_cfg_fd[1] = hv_cfg_fd1;
191 controller->hv_mem_fd = hv_mem_fd;
192 controller->first_busno = 0;
193 controller->last_busno = 0xff;
194 controller->ops = &tile_cfg_ops;
195
196 num_controllers++;
197 continue;
198
199err_cont:
200 if (hv_cfg_fd0 >= 0)
201 hv_dev_close(hv_cfg_fd0);
202 if (hv_cfg_fd1 >= 0)
203 hv_dev_close(hv_cfg_fd1);
204 if (hv_mem_fd >= 0)
205 hv_dev_close(hv_mem_fd);
206 continue;
207 }
208
209 /*
210 * Before using the PCIe, see if we need to do any platform-specific
211 * configuration, such as the PLX switch Gen 1 issue on TILEmpower.
212 */
213 for (i = 0; i < num_controllers; i++) {
214 struct pci_controller *controller = &controllers[i];
215
216 if (controller->plx_gen1)
217 tile_plx_gen1 = 1;
218 }
219
220 return num_controllers;
221}
222
223/*
224 * (pin - 1) converts from the PCI standard's [1:4] convention to
225 * a normal [0:3] range.
226 */
227static int tile_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
228{
229 struct pci_controller *controller =
230 (struct pci_controller *)dev->sysdata;
231 return (pin - 1) + controller->irq_base;
232}
233
234
235static void __init fixup_read_and_payload_sizes(void)
236{
237 struct pci_dev *dev = NULL;
238 int smallest_max_payload = 0x1; /* Tile maxes out at 256 bytes. */
239 int max_read_size = 0x2; /* Limit to 512 byte reads. */
240 u16 new_values;
241
242 /* Scan for the smallest maximum payload size. */
243 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
244 int pcie_caps_offset;
245 u32 devcap;
246 int max_payload;
247
248 pcie_caps_offset = pci_find_capability(dev, PCI_CAP_ID_EXP);
249 if (pcie_caps_offset == 0)
250 continue;
251
252 pci_read_config_dword(dev, pcie_caps_offset + PCI_EXP_DEVCAP,
253 &devcap);
254 max_payload = devcap & PCI_EXP_DEVCAP_PAYLOAD;
255 if (max_payload < smallest_max_payload)
256 smallest_max_payload = max_payload;
257 }
258
259 /* Now, set the max_payload_size for all devices to that value. */
260 new_values = (max_read_size << 12) | (smallest_max_payload << 5);
261 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
262 int pcie_caps_offset;
263 u16 devctl;
264
265 pcie_caps_offset = pci_find_capability(dev, PCI_CAP_ID_EXP);
266 if (pcie_caps_offset == 0)
267 continue;
268
269 pci_read_config_word(dev, pcie_caps_offset + PCI_EXP_DEVCTL,
270 &devctl);
271 devctl &= ~(PCI_EXP_DEVCTL_PAYLOAD | PCI_EXP_DEVCTL_READRQ);
272 devctl |= new_values;
273 pci_write_config_word(dev, pcie_caps_offset + PCI_EXP_DEVCTL,
274 devctl);
275 }
276}
277
278
279/*
280 * Second PCI initialization entry point, called by subsys_initcall.
281 *
282 * The controllers have been set up by the time we get here, by a call to
283 * tile_pci_init.
284 */
285static int __init pcibios_init(void)
286{
287 int i;
288
289 pr_info("PCI: Probing PCI hardware\n");
290
291 /*
292 * Delay a bit in case devices aren't ready. Some devices are
293 * known to require at least 20ms here, but we use a more
294 * conservative value.
295 */
296 mdelay(250);
297
298 /* Scan all of the recorded PCI controllers. */
299 for (i = 0; i < num_controllers; i++) {
300 struct pci_controller *controller = &controllers[i];
301 struct pci_bus *bus;
302
303 pr_info("PCI: initializing controller #%d\n", i);
304
305 /*
306 * This comes from the generic Linux PCI driver.
307 *
308 * It reads the PCI tree for this bus into the Linux
309 * data structures.
310 *
311 * This is inlined in linux/pci.h and calls into
312 * pci_scan_bus_parented() in probe.c.
313 */
314 bus = pci_scan_bus(0, controller->ops, controller);
315 controller->root_bus = bus;
316 controller->last_busno = bus->subordinate;
317
318 }
319
320 /* Do machine dependent PCI interrupt routing */
321 pci_fixup_irqs(pci_common_swizzle, tile_map_irq);
322
323 /*
324 * This comes from the generic Linux PCI driver.
325 *
326 * It allocates all of the resources (I/O memory, etc)
327 * associated with the devices read in above.
328 */
329
330 pci_assign_unassigned_resources();
331
332 /* Configure the max_read_size and max_payload_size values. */
333 fixup_read_and_payload_sizes();
334
335 /* Record the I/O resources in the PCI controller structure. */
336 for (i = 0; i < num_controllers; i++) {
337 struct pci_bus *root_bus = controllers[i].root_bus;
338 struct pci_bus *next_bus;
339 struct pci_dev *dev;
340
341 list_for_each_entry(dev, &root_bus->devices, bus_list) {
342 /* Find the PCI host controller, ie. the 1st bridge. */
343 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI &&
344 (PCI_SLOT(dev->devfn) == 0)) {
345 next_bus = dev->subordinate;
346 controllers[i].mem_resources[0] =
347 *next_bus->resource[0];
348 controllers[i].mem_resources[1] =
349 *next_bus->resource[1];
350 controllers[i].mem_resources[2] =
351 *next_bus->resource[2];
352
353 break;
354 }
355 }
356
357 }
358
359 return 0;
360}
361subsys_initcall(pcibios_init);
362
363/*
364 * No bus fixups needed.
365 */
366void __devinit pcibios_fixup_bus(struct pci_bus *bus)
367{
368 /* Nothing needs to be done. */
369}
370
371/*
372 * This can be called from the generic PCI layer, but doesn't need to
373 * do anything.
374 */
375char __devinit *pcibios_setup(char *str)
376{
377 /* Nothing needs to be done. */
378 return str;
379}
380
381/*
382 * This is called from the generic Linux layer.
383 */
384void __init pcibios_update_irq(struct pci_dev *dev, int irq)
385{
386 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
387}
388
389/*
390 * Enable memory and/or address decoding, as appropriate, for the
391 * device described by the 'dev' struct.
392 *
393 * This is called from the generic PCI layer, and can be called
394 * for bridges or endpoints.
395 */
396int pcibios_enable_device(struct pci_dev *dev, int mask)
397{
398 u16 cmd, old_cmd;
399 u8 header_type;
400 int i;
401 struct resource *r;
402
403 pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
404
405 pci_read_config_word(dev, PCI_COMMAND, &cmd);
406 old_cmd = cmd;
407 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
408 /*
409 * For bridges, we enable both memory and I/O decoding
410 * in call cases.
411 */
412 cmd |= PCI_COMMAND_IO;
413 cmd |= PCI_COMMAND_MEMORY;
414 } else {
415 /*
416 * For endpoints, we enable memory and/or I/O decoding
417 * only if they have a memory resource of that type.
418 */
419 for (i = 0; i < 6; i++) {
420 r = &dev->resource[i];
421 if (r->flags & IORESOURCE_UNSET) {
422 pr_err("PCI: Device %s not available "
423 "because of resource collisions\n",
424 pci_name(dev));
425 return -EINVAL;
426 }
427 if (r->flags & IORESOURCE_IO)
428 cmd |= PCI_COMMAND_IO;
429 if (r->flags & IORESOURCE_MEM)
430 cmd |= PCI_COMMAND_MEMORY;
431 }
432 }
433
434 /*
435 * We only write the command if it changed.
436 */
437 if (cmd != old_cmd)
438 pci_write_config_word(dev, PCI_COMMAND, cmd);
439 return 0;
440}
441
442void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
443{
444 unsigned long start = pci_resource_start(dev, bar);
445 unsigned long len = pci_resource_len(dev, bar);
446 unsigned long flags = pci_resource_flags(dev, bar);
447
448 if (!len)
449 return NULL;
450 if (max && len > max)
451 len = max;
452
453 if (!(flags & IORESOURCE_MEM)) {
454 pr_info("PCI: Trying to map invalid resource %#lx\n", flags);
455 start = 0;
456 }
457
458 return (void __iomem *)start;
459}
460EXPORT_SYMBOL(pci_iomap);
461
462
463/****************************************************************
464 *
465 * Tile PCI config space read/write routines
466 *
467 ****************************************************************/
468
469/*
470 * These are the normal read and write ops
471 * These are expanded with macros from pci_bus_read_config_byte() etc.
472 *
473 * devfn is the combined PCI slot & function.
474 *
475 * offset is in bytes, from the start of config space for the
476 * specified bus & slot.
477 */
478
479static int __devinit tile_cfg_read(struct pci_bus *bus,
480 unsigned int devfn,
481 int offset,
482 int size,
483 u32 *val)
484{
485 struct pci_controller *controller = bus->sysdata;
486 int busnum = bus->number & 0xff;
487 int slot = (devfn >> 3) & 0x1f;
488 int function = devfn & 0x7;
489 u32 addr;
490 int config_mode = 1;
491
492 /*
493 * There is no bridge between the Tile and bus 0, so we
494 * use config0 to talk to bus 0.
495 *
496 * If we're talking to a bus other than zero then we
497 * must have found a bridge.
498 */
499 if (busnum == 0) {
500 /*
501 * We fake an empty slot for (busnum == 0) && (slot > 0),
502 * since there is only one slot on bus 0.
503 */
504 if (slot) {
505 *val = 0xFFFFFFFF;
506 return 0;
507 }
508 config_mode = 0;
509 }
510
511 addr = busnum << 20; /* Bus in 27:20 */
512 addr |= slot << 15; /* Slot (device) in 19:15 */
513 addr |= function << 12; /* Function is in 14:12 */
514 addr |= (offset & 0xFFF); /* byte address in 0:11 */
515
516 return hv_dev_pread(controller->hv_cfg_fd[config_mode], 0,
517 (HV_VirtAddr)(val), size, addr);
518}
519
520
521/*
522 * See tile_cfg_read() for relevent comments.
523 * Note that "val" is the value to write, not a pointer to that value.
524 */
525static int __devinit tile_cfg_write(struct pci_bus *bus,
526 unsigned int devfn,
527 int offset,
528 int size,
529 u32 val)
530{
531 struct pci_controller *controller = bus->sysdata;
532 int busnum = bus->number & 0xff;
533 int slot = (devfn >> 3) & 0x1f;
534 int function = devfn & 0x7;
535 u32 addr;
536 int config_mode = 1;
537 HV_VirtAddr valp = (HV_VirtAddr)&val;
538
539 /*
540 * For bus 0 slot 0 we use config 0 accesses.
541 */
542 if (busnum == 0) {
543 /*
544 * We fake an empty slot for (busnum == 0) && (slot > 0),
545 * since there is only one slot on bus 0.
546 */
547 if (slot)
548 return 0;
549 config_mode = 0;
550 }
551
552 addr = busnum << 20; /* Bus in 27:20 */
553 addr |= slot << 15; /* Slot (device) in 19:15 */
554 addr |= function << 12; /* Function is in 14:12 */
555 addr |= (offset & 0xFFF); /* byte address in 0:11 */
556
557#ifdef __BIG_ENDIAN
558 /* Point to the correct part of the 32-bit "val". */
559 valp += 4 - size;
560#endif
561
562 return hv_dev_pwrite(controller->hv_cfg_fd[config_mode], 0,
563 valp, size, addr);
564}
565
566
567static struct pci_ops tile_cfg_ops = {
568 .read = tile_cfg_read,
569 .write = tile_cfg_write,
570};
571
572
573/*
574 * In the following, each PCI controller's mem_resources[1]
575 * represents its (non-prefetchable) PCI memory resource.
576 * mem_resources[0] and mem_resources[2] refer to its PCI I/O and
577 * prefetchable PCI memory resources, respectively.
578 * For more details, see pci_setup_bridge() in setup-bus.c.
579 * By comparing the target PCI memory address against the
580 * end address of controller 0, we can determine the controller
581 * that should accept the PCI memory access.
582 */
583#define TILE_READ(size, type) \
584type _tile_read##size(unsigned long addr) \
585{ \
586 type val; \
587 int idx = 0; \
588 if (addr > controllers[0].mem_resources[1].end && \
589 addr > controllers[0].mem_resources[2].end) \
590 idx = 1; \
591 if (hv_dev_pread(controllers[idx].hv_mem_fd, 0, \
592 (HV_VirtAddr)(&val), sizeof(type), addr)) \
593 pr_err("PCI: read %zd bytes at 0x%lX failed\n", \
594 sizeof(type), addr); \
595 return val; \
596} \
597EXPORT_SYMBOL(_tile_read##size)
598
599TILE_READ(b, u8);
600TILE_READ(w, u16);
601TILE_READ(l, u32);
602TILE_READ(q, u64);
603
604#define TILE_WRITE(size, type) \
605void _tile_write##size(type val, unsigned long addr) \
606{ \
607 int idx = 0; \
608 if (addr > controllers[0].mem_resources[1].end && \
609 addr > controllers[0].mem_resources[2].end) \
610 idx = 1; \
611 if (hv_dev_pwrite(controllers[idx].hv_mem_fd, 0, \
612 (HV_VirtAddr)(&val), sizeof(type), addr)) \
613 pr_err("PCI: write %zd bytes at 0x%lX failed\n", \
614 sizeof(type), addr); \
615} \
616EXPORT_SYMBOL(_tile_write##size)
617
618TILE_WRITE(b, u8);
619TILE_WRITE(w, u16);
620TILE_WRITE(l, u32);
621TILE_WRITE(q, u64);
diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c
index 8430f45daea6..e90eb53173b0 100644
--- a/arch/tile/kernel/process.c
+++ b/arch/tile/kernel/process.c
@@ -212,6 +212,13 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
212 childregs->sp = sp; /* override with new user stack pointer */ 212 childregs->sp = sp; /* override with new user stack pointer */
213 213
214 /* 214 /*
215 * If CLONE_SETTLS is set, set "tp" in the new task to "r4",
216 * which is passed in as arg #5 to sys_clone().
217 */
218 if (clone_flags & CLONE_SETTLS)
219 childregs->tp = regs->regs[4];
220
221 /*
215 * Copy the callee-saved registers from the passed pt_regs struct 222 * Copy the callee-saved registers from the passed pt_regs struct
216 * into the context-switch callee-saved registers area. 223 * into the context-switch callee-saved registers area.
217 * This way when we start the interrupt-return sequence, the 224 * This way when we start the interrupt-return sequence, the
@@ -539,6 +546,7 @@ struct task_struct *__sched _switch_to(struct task_struct *prev,
539 return __switch_to(prev, next, next_current_ksp0(next)); 546 return __switch_to(prev, next, next_current_ksp0(next));
540} 547}
541 548
549/* Note there is an implicit fifth argument if (clone_flags & CLONE_SETTLS). */
542SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp, 550SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
543 void __user *, parent_tidptr, void __user *, child_tidptr, 551 void __user *, parent_tidptr, void __user *, child_tidptr,
544 struct pt_regs *, regs) 552 struct pt_regs *, regs)
diff --git a/arch/tile/kernel/ptrace.c b/arch/tile/kernel/ptrace.c
index 9cd29884c09f..e92e40527d6d 100644
--- a/arch/tile/kernel/ptrace.c
+++ b/arch/tile/kernel/ptrace.c
@@ -50,10 +50,10 @@ long arch_ptrace(struct task_struct *child, long request,
50{ 50{
51 unsigned long __user *datap = (long __user __force *)data; 51 unsigned long __user *datap = (long __user __force *)data;
52 unsigned long tmp; 52 unsigned long tmp;
53 int i;
54 long ret = -EIO; 53 long ret = -EIO;
55 unsigned long *childregs;
56 char *childreg; 54 char *childreg;
55 struct pt_regs copyregs;
56 int ex1_offset;
57 57
58 switch (request) { 58 switch (request) {
59 59
@@ -80,6 +80,16 @@ long arch_ptrace(struct task_struct *child, long request,
80 if (addr >= PTREGS_SIZE) 80 if (addr >= PTREGS_SIZE)
81 break; 81 break;
82 childreg = (char *)task_pt_regs(child) + addr; 82 childreg = (char *)task_pt_regs(child) + addr;
83
84 /* Guard against overwrites of the privilege level. */
85 ex1_offset = PTREGS_OFFSET_EX1;
86#if defined(CONFIG_COMPAT) && defined(__BIG_ENDIAN)
87 if (is_compat_task()) /* point at low word */
88 ex1_offset += sizeof(compat_long_t);
89#endif
90 if (addr == ex1_offset)
91 data = PL_ICS_EX1(USER_PL, EX1_ICS(data));
92
83#ifdef CONFIG_COMPAT 93#ifdef CONFIG_COMPAT
84 if (is_compat_task()) { 94 if (is_compat_task()) {
85 if (addr & (sizeof(compat_long_t)-1)) 95 if (addr & (sizeof(compat_long_t)-1))
@@ -96,26 +106,19 @@ long arch_ptrace(struct task_struct *child, long request,
96 break; 106 break;
97 107
98 case PTRACE_GETREGS: /* Get all registers from the child. */ 108 case PTRACE_GETREGS: /* Get all registers from the child. */
99 if (!access_ok(VERIFY_WRITE, datap, PTREGS_SIZE)) 109 if (copy_to_user(datap, task_pt_regs(child),
100 break; 110 sizeof(struct pt_regs)) == 0) {
101 childregs = (long *)task_pt_regs(child); 111 ret = 0;
102 for (i = 0; i < sizeof(struct pt_regs)/sizeof(unsigned long);
103 ++i) {
104 ret = __put_user(childregs[i], &datap[i]);
105 if (ret != 0)
106 break;
107 } 112 }
108 break; 113 break;
109 114
110 case PTRACE_SETREGS: /* Set all registers in the child. */ 115 case PTRACE_SETREGS: /* Set all registers in the child. */
111 if (!access_ok(VERIFY_READ, datap, PTREGS_SIZE)) 116 if (copy_from_user(&copyregs, datap,
112 break; 117 sizeof(struct pt_regs)) == 0) {
113 childregs = (long *)task_pt_regs(child); 118 copyregs.ex1 =
114 for (i = 0; i < sizeof(struct pt_regs)/sizeof(unsigned long); 119 PL_ICS_EX1(USER_PL, EX1_ICS(copyregs.ex1));
115 ++i) { 120 *task_pt_regs(child) = copyregs;
116 ret = __get_user(childregs[i], &datap[i]); 121 ret = 0;
117 if (ret != 0)
118 break;
119 } 122 }
120 break; 123 break;
121 124
diff --git a/arch/tile/kernel/reboot.c b/arch/tile/kernel/reboot.c
index acd86d20beba..baa3d905fee2 100644
--- a/arch/tile/kernel/reboot.c
+++ b/arch/tile/kernel/reboot.c
@@ -27,7 +27,7 @@
27void machine_halt(void) 27void machine_halt(void)
28{ 28{
29 warn_early_printk(); 29 warn_early_printk();
30 raw_local_irq_disable_all(); 30 arch_local_irq_disable_all();
31 smp_send_stop(); 31 smp_send_stop();
32 hv_halt(); 32 hv_halt();
33} 33}
@@ -35,14 +35,14 @@ void machine_halt(void)
35void machine_power_off(void) 35void machine_power_off(void)
36{ 36{
37 warn_early_printk(); 37 warn_early_printk();
38 raw_local_irq_disable_all(); 38 arch_local_irq_disable_all();
39 smp_send_stop(); 39 smp_send_stop();
40 hv_power_off(); 40 hv_power_off();
41} 41}
42 42
43void machine_restart(char *cmd) 43void machine_restart(char *cmd)
44{ 44{
45 raw_local_irq_disable_all(); 45 arch_local_irq_disable_all();
46 smp_send_stop(); 46 smp_send_stop();
47 hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd); 47 hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
48} 48}
diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
index ae51cad12da0..f18573643ed1 100644
--- a/arch/tile/kernel/setup.c
+++ b/arch/tile/kernel/setup.c
@@ -840,7 +840,7 @@ static int __init topology_init(void)
840 for_each_online_node(i) 840 for_each_online_node(i)
841 register_one_node(i); 841 register_one_node(i);
842 842
843 for_each_present_cpu(i) 843 for (i = 0; i < smp_height * smp_width; ++i)
844 register_cpu(&cpu_devices[i], i); 844 register_cpu(&cpu_devices[i], i);
845 845
846 return 0; 846 return 0;
@@ -868,14 +868,14 @@ void __cpuinit setup_cpu(int boot)
868 868
869 /* Allow asynchronous TLB interrupts. */ 869 /* Allow asynchronous TLB interrupts. */
870#if CHIP_HAS_TILE_DMA() 870#if CHIP_HAS_TILE_DMA()
871 raw_local_irq_unmask(INT_DMATLB_MISS); 871 arch_local_irq_unmask(INT_DMATLB_MISS);
872 raw_local_irq_unmask(INT_DMATLB_ACCESS); 872 arch_local_irq_unmask(INT_DMATLB_ACCESS);
873#endif 873#endif
874#if CHIP_HAS_SN_PROC() 874#if CHIP_HAS_SN_PROC()
875 raw_local_irq_unmask(INT_SNITLB_MISS); 875 arch_local_irq_unmask(INT_SNITLB_MISS);
876#endif 876#endif
877#ifdef __tilegx__ 877#ifdef __tilegx__
878 raw_local_irq_unmask(INT_SINGLE_STEP_K); 878 arch_local_irq_unmask(INT_SINGLE_STEP_K);
879#endif 879#endif
880 880
881 /* 881 /*
diff --git a/arch/tile/kernel/signal.c b/arch/tile/kernel/signal.c
index fb28e85ae3ae..1260321155f1 100644
--- a/arch/tile/kernel/signal.c
+++ b/arch/tile/kernel/signal.c
@@ -16,7 +16,6 @@
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/smp.h> 18#include <linux/smp.h>
19#include <linux/smp_lock.h>
20#include <linux/kernel.h> 19#include <linux/kernel.h>
21#include <linux/signal.h> 20#include <linux/signal.h>
22#include <linux/errno.h> 21#include <linux/errno.h>
@@ -53,7 +52,7 @@ SYSCALL_DEFINE3(sigaltstack, const stack_t __user *, uss,
53 */ 52 */
54 53
55int restore_sigcontext(struct pt_regs *regs, 54int restore_sigcontext(struct pt_regs *regs,
56 struct sigcontext __user *sc, long *pr0) 55 struct sigcontext __user *sc)
57{ 56{
58 int err = 0; 57 int err = 0;
59 int i; 58 int i;
@@ -71,19 +70,20 @@ int restore_sigcontext(struct pt_regs *regs,
71 for (i = 0; i < sizeof(struct pt_regs)/sizeof(long); ++i) 70 for (i = 0; i < sizeof(struct pt_regs)/sizeof(long); ++i)
72 err |= __get_user(regs->regs[i], &sc->gregs[i]); 71 err |= __get_user(regs->regs[i], &sc->gregs[i]);
73 72
73 /* Ensure that the PL is always set to USER_PL. */
74 regs->ex1 = PL_ICS_EX1(USER_PL, EX1_ICS(regs->ex1));
75
74 regs->faultnum = INT_SWINT_1_SIGRETURN; 76 regs->faultnum = INT_SWINT_1_SIGRETURN;
75 77
76 err |= __get_user(*pr0, &sc->gregs[0]);
77 return err; 78 return err;
78} 79}
79 80
80/* sigreturn() returns long since it restores r0 in the interrupted code. */ 81/* The assembly shim for this function arranges to ignore the return value. */
81SYSCALL_DEFINE1(rt_sigreturn, struct pt_regs *, regs) 82SYSCALL_DEFINE1(rt_sigreturn, struct pt_regs *, regs)
82{ 83{
83 struct rt_sigframe __user *frame = 84 struct rt_sigframe __user *frame =
84 (struct rt_sigframe __user *)(regs->sp); 85 (struct rt_sigframe __user *)(regs->sp);
85 sigset_t set; 86 sigset_t set;
86 long r0;
87 87
88 if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) 88 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
89 goto badframe; 89 goto badframe;
@@ -96,13 +96,13 @@ SYSCALL_DEFINE1(rt_sigreturn, struct pt_regs *, regs)
96 recalc_sigpending(); 96 recalc_sigpending();
97 spin_unlock_irq(&current->sighand->siglock); 97 spin_unlock_irq(&current->sighand->siglock);
98 98
99 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0)) 99 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
100 goto badframe; 100 goto badframe;
101 101
102 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) 102 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
103 goto badframe; 103 goto badframe;
104 104
105 return r0; 105 return 0;
106 106
107badframe: 107badframe:
108 force_sig(SIGSEGV, current); 108 force_sig(SIGSEGV, current);
@@ -330,7 +330,7 @@ void do_signal(struct pt_regs *regs)
330 current_thread_info()->status &= ~TS_RESTORE_SIGMASK; 330 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
331 } 331 }
332 332
333 return; 333 goto done;
334 } 334 }
335 335
336 /* Did we come from a system call? */ 336 /* Did we come from a system call? */
@@ -358,4 +358,8 @@ void do_signal(struct pt_regs *regs)
358 current_thread_info()->status &= ~TS_RESTORE_SIGMASK; 358 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
359 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL); 359 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
360 } 360 }
361
362done:
363 /* Avoid double syscall restart if there are nested signals. */
364 regs->faultnum = INT_SWINT_1_SIGRETURN;
361} 365}
diff --git a/arch/tile/kernel/smp.c b/arch/tile/kernel/smp.c
index 75255d90aff3..9575b37a8b75 100644
--- a/arch/tile/kernel/smp.c
+++ b/arch/tile/kernel/smp.c
@@ -115,7 +115,7 @@ static void smp_start_cpu_interrupt(void)
115static void smp_stop_cpu_interrupt(void) 115static void smp_stop_cpu_interrupt(void)
116{ 116{
117 set_cpu_online(smp_processor_id(), 0); 117 set_cpu_online(smp_processor_id(), 0);
118 raw_local_irq_disable_all(); 118 arch_local_irq_disable_all();
119 for (;;) 119 for (;;)
120 asm("nap"); 120 asm("nap");
121} 121}
diff --git a/arch/tile/kernel/smpboot.c b/arch/tile/kernel/smpboot.c
index 74d62d098edf..b949edcec200 100644
--- a/arch/tile/kernel/smpboot.c
+++ b/arch/tile/kernel/smpboot.c
@@ -18,7 +18,6 @@
18#include <linux/mm.h> 18#include <linux/mm.h>
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/kernel_stat.h> 20#include <linux/kernel_stat.h>
21#include <linux/smp_lock.h>
22#include <linux/bootmem.h> 21#include <linux/bootmem.h>
23#include <linux/notifier.h> 22#include <linux/notifier.h>
24#include <linux/cpu.h> 23#include <linux/cpu.h>
diff --git a/arch/tile/kernel/sys.c b/arch/tile/kernel/sys.c
index 7e764669a022..e2187d24a9b4 100644
--- a/arch/tile/kernel/sys.c
+++ b/arch/tile/kernel/sys.c
@@ -20,7 +20,6 @@
20#include <linux/sched.h> 20#include <linux/sched.h>
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/smp.h> 22#include <linux/smp.h>
23#include <linux/smp_lock.h>
24#include <linux/syscalls.h> 23#include <linux/syscalls.h>
25#include <linux/mman.h> 24#include <linux/mman.h>
26#include <linux/file.h> 25#include <linux/file.h>
diff --git a/arch/tile/kernel/time.c b/arch/tile/kernel/time.c
index 6bed820e1421..f2e156e44692 100644
--- a/arch/tile/kernel/time.c
+++ b/arch/tile/kernel/time.c
@@ -132,7 +132,7 @@ static int tile_timer_set_next_event(unsigned long ticks,
132{ 132{
133 BUG_ON(ticks > MAX_TICK); 133 BUG_ON(ticks > MAX_TICK);
134 __insn_mtspr(SPR_TILE_TIMER_CONTROL, ticks); 134 __insn_mtspr(SPR_TILE_TIMER_CONTROL, ticks);
135 raw_local_irq_unmask_now(INT_TILE_TIMER); 135 arch_local_irq_unmask_now(INT_TILE_TIMER);
136 return 0; 136 return 0;
137} 137}
138 138
@@ -143,7 +143,7 @@ static int tile_timer_set_next_event(unsigned long ticks,
143static void tile_timer_set_mode(enum clock_event_mode mode, 143static void tile_timer_set_mode(enum clock_event_mode mode,
144 struct clock_event_device *evt) 144 struct clock_event_device *evt)
145{ 145{
146 raw_local_irq_mask_now(INT_TILE_TIMER); 146 arch_local_irq_mask_now(INT_TILE_TIMER);
147} 147}
148 148
149/* 149/*
@@ -172,7 +172,7 @@ void __cpuinit setup_tile_timer(void)
172 evt->cpumask = cpumask_of(smp_processor_id()); 172 evt->cpumask = cpumask_of(smp_processor_id());
173 173
174 /* Start out with timer not firing. */ 174 /* Start out with timer not firing. */
175 raw_local_irq_mask_now(INT_TILE_TIMER); 175 arch_local_irq_mask_now(INT_TILE_TIMER);
176 176
177 /* Register tile timer. */ 177 /* Register tile timer. */
178 clockevents_register_device(evt); 178 clockevents_register_device(evt);
@@ -188,7 +188,7 @@ void do_timer_interrupt(struct pt_regs *regs, int fault_num)
188 * Mask the timer interrupt here, since we are a oneshot timer 188 * Mask the timer interrupt here, since we are a oneshot timer
189 * and there are now by definition no events pending. 189 * and there are now by definition no events pending.
190 */ 190 */
191 raw_local_irq_mask(INT_TILE_TIMER); 191 arch_local_irq_mask(INT_TILE_TIMER);
192 192
193 /* Track time spent here in an interrupt context */ 193 /* Track time spent here in an interrupt context */
194 irq_enter(); 194 irq_enter();
diff --git a/arch/tile/lib/memchr_32.c b/arch/tile/lib/memchr_32.c
index 6235283b4859..cc3d9badf030 100644
--- a/arch/tile/lib/memchr_32.c
+++ b/arch/tile/lib/memchr_32.c
@@ -18,12 +18,24 @@
18 18
19void *memchr(const void *s, int c, size_t n) 19void *memchr(const void *s, int c, size_t n)
20{ 20{
21 const uint32_t *last_word_ptr;
22 const uint32_t *p;
23 const char *last_byte_ptr;
24 uintptr_t s_int;
25 uint32_t goal, before_mask, v, bits;
26 char *ret;
27
28 if (__builtin_expect(n == 0, 0)) {
29 /* Don't dereference any memory if the array is empty. */
30 return NULL;
31 }
32
21 /* Get an aligned pointer. */ 33 /* Get an aligned pointer. */
22 const uintptr_t s_int = (uintptr_t) s; 34 s_int = (uintptr_t) s;
23 const uint32_t *p = (const uint32_t *)(s_int & -4); 35 p = (const uint32_t *)(s_int & -4);
24 36
25 /* Create four copies of the byte for which we are looking. */ 37 /* Create four copies of the byte for which we are looking. */
26 const uint32_t goal = 0x01010101 * (uint8_t) c; 38 goal = 0x01010101 * (uint8_t) c;
27 39
28 /* Read the first word, but munge it so that bytes before the array 40 /* Read the first word, but munge it so that bytes before the array
29 * will not match goal. 41 * will not match goal.
@@ -31,23 +43,14 @@ void *memchr(const void *s, int c, size_t n)
31 * Note that this shift count expression works because we know 43 * Note that this shift count expression works because we know
32 * shift counts are taken mod 32. 44 * shift counts are taken mod 32.
33 */ 45 */
34 const uint32_t before_mask = (1 << (s_int << 3)) - 1; 46 before_mask = (1 << (s_int << 3)) - 1;
35 uint32_t v = (*p | before_mask) ^ (goal & before_mask); 47 v = (*p | before_mask) ^ (goal & before_mask);
36 48
37 /* Compute the address of the last byte. */ 49 /* Compute the address of the last byte. */
38 const char *const last_byte_ptr = (const char *)s + n - 1; 50 last_byte_ptr = (const char *)s + n - 1;
39 51
40 /* Compute the address of the word containing the last byte. */ 52 /* Compute the address of the word containing the last byte. */
41 const uint32_t *const last_word_ptr = 53 last_word_ptr = (const uint32_t *)((uintptr_t) last_byte_ptr & -4);
42 (const uint32_t *)((uintptr_t) last_byte_ptr & -4);
43
44 uint32_t bits;
45 char *ret;
46
47 if (__builtin_expect(n == 0, 0)) {
48 /* Don't dereference any memory if the array is empty. */
49 return NULL;
50 }
51 54
52 while ((bits = __insn_seqb(v, goal)) == 0) { 55 while ((bits = __insn_seqb(v, goal)) == 0) {
53 if (__builtin_expect(p == last_word_ptr, 0)) { 56 if (__builtin_expect(p == last_word_ptr, 0)) {
diff --git a/arch/tile/lib/memcpy_tile64.c b/arch/tile/lib/memcpy_tile64.c
index dfedea7b266b..f7d4a6ad61e8 100644
--- a/arch/tile/lib/memcpy_tile64.c
+++ b/arch/tile/lib/memcpy_tile64.c
@@ -54,7 +54,7 @@ typedef unsigned long (*memcpy_t)(void *, const void *, unsigned long);
54 * we must run with interrupts disabled to avoid the risk of some 54 * we must run with interrupts disabled to avoid the risk of some
55 * other code seeing the incoherent data in our cache. (Recall that 55 * other code seeing the incoherent data in our cache. (Recall that
56 * our cache is indexed by PA, so even if the other code doesn't use 56 * our cache is indexed by PA, so even if the other code doesn't use
57 * our KM_MEMCPY virtual addresses, they'll still hit in cache using 57 * our kmap_atomic virtual addresses, they'll still hit in cache using
58 * the normal VAs that aren't supposed to hit in cache.) 58 * the normal VAs that aren't supposed to hit in cache.)
59 */ 59 */
60static void memcpy_multicache(void *dest, const void *source, 60static void memcpy_multicache(void *dest, const void *source,
@@ -64,6 +64,7 @@ static void memcpy_multicache(void *dest, const void *source,
64 unsigned long flags, newsrc, newdst; 64 unsigned long flags, newsrc, newdst;
65 pmd_t *pmdp; 65 pmd_t *pmdp;
66 pte_t *ptep; 66 pte_t *ptep;
67 int type0, type1;
67 int cpu = get_cpu(); 68 int cpu = get_cpu();
68 69
69 /* 70 /*
@@ -77,7 +78,8 @@ static void memcpy_multicache(void *dest, const void *source,
77 sim_allow_multiple_caching(1); 78 sim_allow_multiple_caching(1);
78 79
79 /* Set up the new dest mapping */ 80 /* Set up the new dest mapping */
80 idx = FIX_KMAP_BEGIN + (KM_TYPE_NR * cpu) + KM_MEMCPY0; 81 type0 = kmap_atomic_idx_push();
82 idx = FIX_KMAP_BEGIN + (KM_TYPE_NR * cpu) + type0;
81 newdst = __fix_to_virt(idx) + ((unsigned long)dest & (PAGE_SIZE-1)); 83 newdst = __fix_to_virt(idx) + ((unsigned long)dest & (PAGE_SIZE-1));
82 pmdp = pmd_offset(pud_offset(pgd_offset_k(newdst), newdst), newdst); 84 pmdp = pmd_offset(pud_offset(pgd_offset_k(newdst), newdst), newdst);
83 ptep = pte_offset_kernel(pmdp, newdst); 85 ptep = pte_offset_kernel(pmdp, newdst);
@@ -87,7 +89,8 @@ static void memcpy_multicache(void *dest, const void *source,
87 } 89 }
88 90
89 /* Set up the new source mapping */ 91 /* Set up the new source mapping */
90 idx += (KM_MEMCPY0 - KM_MEMCPY1); 92 type1 = kmap_atomic_idx_push();
93 idx += (type0 - type1);
91 src_pte = hv_pte_set_nc(src_pte); 94 src_pte = hv_pte_set_nc(src_pte);
92 src_pte = hv_pte_clear_writable(src_pte); /* be paranoid */ 95 src_pte = hv_pte_clear_writable(src_pte); /* be paranoid */
93 newsrc = __fix_to_virt(idx) + ((unsigned long)source & (PAGE_SIZE-1)); 96 newsrc = __fix_to_virt(idx) + ((unsigned long)source & (PAGE_SIZE-1));
@@ -119,6 +122,8 @@ static void memcpy_multicache(void *dest, const void *source,
119 * We're done: notify the simulator that all is back to normal, 122 * We're done: notify the simulator that all is back to normal,
120 * and re-enable interrupts and pre-emption. 123 * and re-enable interrupts and pre-emption.
121 */ 124 */
125 kmap_atomic_idx_pop();
126 kmap_atomic_idx_pop();
122 sim_allow_multiple_caching(0); 127 sim_allow_multiple_caching(0);
123 local_irq_restore(flags); 128 local_irq_restore(flags);
124 put_cpu(); 129 put_cpu();
diff --git a/arch/tile/lib/spinlock_32.c b/arch/tile/lib/spinlock_32.c
index 485e24d62c6b..5cd1c4004eca 100644
--- a/arch/tile/lib/spinlock_32.c
+++ b/arch/tile/lib/spinlock_32.c
@@ -167,23 +167,30 @@ void arch_write_lock_slow(arch_rwlock_t *rwlock, u32 val)
167 * when we compare them. 167 * when we compare them.
168 */ 168 */
169 u32 my_ticket_; 169 u32 my_ticket_;
170 u32 iterations = 0;
170 171
171 /* Take out the next ticket; this will also stop would-be readers. */ 172 /*
172 if (val & 1) 173 * Wait until there are no readers, then bump up the next
173 val = get_rwlock(rwlock); 174 * field and capture the ticket value.
174 rwlock->lock = __insn_addb(val, 1 << WR_NEXT_SHIFT); 175 */
176 for (;;) {
177 if (!(val & 1)) {
178 if ((val >> RD_COUNT_SHIFT) == 0)
179 break;
180 rwlock->lock = val;
181 }
182 delay_backoff(iterations++);
183 val = __insn_tns((int *)&rwlock->lock);
184 }
175 185
176 /* Extract my ticket value from the original word. */ 186 /* Take out the next ticket and extract my ticket value. */
187 rwlock->lock = __insn_addb(val, 1 << WR_NEXT_SHIFT);
177 my_ticket_ = val >> WR_NEXT_SHIFT; 188 my_ticket_ = val >> WR_NEXT_SHIFT;
178 189
179 /* 190 /* Wait until the "current" field matches our ticket. */
180 * Wait until the "current" field matches our ticket, and
181 * there are no remaining readers.
182 */
183 for (;;) { 191 for (;;) {
184 u32 curr_ = val >> WR_CURR_SHIFT; 192 u32 curr_ = val >> WR_CURR_SHIFT;
185 u32 readers = val >> RD_COUNT_SHIFT; 193 u32 delta = ((my_ticket_ - curr_) & WR_MASK);
186 u32 delta = ((my_ticket_ - curr_) & WR_MASK) + !!readers;
187 if (likely(delta == 0)) 194 if (likely(delta == 0))
188 break; 195 break;
189 196
diff --git a/arch/tile/mm/fault.c b/arch/tile/mm/fault.c
index f295b4ac941d..dcebfc831cd6 100644
--- a/arch/tile/mm/fault.c
+++ b/arch/tile/mm/fault.c
@@ -24,7 +24,6 @@
24#include <linux/mman.h> 24#include <linux/mman.h>
25#include <linux/mm.h> 25#include <linux/mm.h>
26#include <linux/smp.h> 26#include <linux/smp.h>
27#include <linux/smp_lock.h>
28#include <linux/interrupt.h> 27#include <linux/interrupt.h>
29#include <linux/init.h> 28#include <linux/init.h>
30#include <linux/tty.h> 29#include <linux/tty.h>
diff --git a/arch/tile/mm/highmem.c b/arch/tile/mm/highmem.c
index abb57331cf6e..31dbbd9afe47 100644
--- a/arch/tile/mm/highmem.c
+++ b/arch/tile/mm/highmem.c
@@ -227,7 +227,7 @@ EXPORT_SYMBOL(kmap_atomic_prot);
227void *__kmap_atomic(struct page *page) 227void *__kmap_atomic(struct page *page)
228{ 228{
229 /* PAGE_NONE is a magic value that tells us to check immutability. */ 229 /* PAGE_NONE is a magic value that tells us to check immutability. */
230 return kmap_atomic_prot(page, type, PAGE_NONE); 230 return kmap_atomic_prot(page, PAGE_NONE);
231} 231}
232EXPORT_SYMBOL(__kmap_atomic); 232EXPORT_SYMBOL(__kmap_atomic);
233 233
diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
index 24688b697a8d..201a582c4137 100644
--- a/arch/tile/mm/hugetlbpage.c
+++ b/arch/tile/mm/hugetlbpage.c
@@ -21,7 +21,6 @@
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/hugetlb.h> 22#include <linux/hugetlb.h>
23#include <linux/pagemap.h> 23#include <linux/pagemap.h>
24#include <linux/smp_lock.h>
25#include <linux/slab.h> 24#include <linux/slab.h>
26#include <linux/err.h> 25#include <linux/err.h>
27#include <linux/sysctl.h> 26#include <linux/sysctl.h>
diff --git a/arch/tile/mm/init.c b/arch/tile/mm/init.c
index 78e1982cb6c9..0b9ce69b0ee5 100644
--- a/arch/tile/mm/init.c
+++ b/arch/tile/mm/init.c
@@ -988,8 +988,12 @@ static long __write_once initfree = 1;
988/* Select whether to free (1) or mark unusable (0) the __init pages. */ 988/* Select whether to free (1) or mark unusable (0) the __init pages. */
989static int __init set_initfree(char *str) 989static int __init set_initfree(char *str)
990{ 990{
991 strict_strtol(str, 0, &initfree); 991 long val;
992 pr_info("initfree: %s free init pages\n", initfree ? "will" : "won't"); 992 if (strict_strtol(str, 0, &val)) {
993 initfree = val;
994 pr_info("initfree: %s free init pages\n",
995 initfree ? "will" : "won't");
996 }
993 return 1; 997 return 1;
994} 998}
995__setup("initfree=", set_initfree); 999__setup("initfree=", set_initfree);
diff --git a/arch/tile/mm/pgtable.c b/arch/tile/mm/pgtable.c
index 335c24621c41..1f5430c53d0d 100644
--- a/arch/tile/mm/pgtable.c
+++ b/arch/tile/mm/pgtable.c
@@ -134,9 +134,9 @@ void __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t flags)
134} 134}
135 135
136#if defined(CONFIG_HIGHPTE) 136#if defined(CONFIG_HIGHPTE)
137pte_t *_pte_offset_map(pmd_t *dir, unsigned long address, enum km_type type) 137pte_t *_pte_offset_map(pmd_t *dir, unsigned long address)
138{ 138{
139 pte_t *pte = kmap_atomic(pmd_page(*dir), type) + 139 pte_t *pte = kmap_atomic(pmd_page(*dir)) +
140 (pmd_ptfn(*dir) << HV_LOG2_PAGE_TABLE_ALIGN) & ~PAGE_MASK; 140 (pmd_ptfn(*dir) << HV_LOG2_PAGE_TABLE_ALIGN) & ~PAGE_MASK;
141 return &pte[pte_index(address)]; 141 return &pte[pte_index(address)];
142} 142}
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 7f7338c90784..1664cce7b0ac 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -727,6 +727,9 @@ struct winch {
727 727
728static void free_winch(struct winch *winch, int free_irq_ok) 728static void free_winch(struct winch *winch, int free_irq_ok)
729{ 729{
730 if (free_irq_ok)
731 free_irq(WINCH_IRQ, winch);
732
730 list_del(&winch->list); 733 list_del(&winch->list);
731 734
732 if (winch->pid != -1) 735 if (winch->pid != -1)
@@ -735,8 +738,6 @@ static void free_winch(struct winch *winch, int free_irq_ok)
735 os_close_file(winch->fd); 738 os_close_file(winch->fd);
736 if (winch->stack != 0) 739 if (winch->stack != 0)
737 free_stack(winch->stack, 0); 740 free_stack(winch->stack, 0);
738 if (free_irq_ok)
739 free_irq(WINCH_IRQ, winch);
740 kfree(winch); 741 kfree(winch);
741} 742}
742 743
diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptrace-generic.h
index 2cd899f75a3c..b7c5bab9bd77 100644
--- a/arch/um/include/asm/ptrace-generic.h
+++ b/arch/um/include/asm/ptrace-generic.h
@@ -38,8 +38,8 @@ struct pt_regs {
38 38
39struct task_struct; 39struct task_struct;
40 40
41extern long subarch_ptrace(struct task_struct *child, long request, long addr, 41extern long subarch_ptrace(struct task_struct *child, long request,
42 long data); 42 unsigned long addr, unsigned long data);
43extern unsigned long getreg(struct task_struct *child, int regno); 43extern unsigned long getreg(struct task_struct *child, int regno);
44extern int putreg(struct task_struct *child, int regno, unsigned long value); 44extern int putreg(struct task_struct *child, int regno, unsigned long value);
45extern int get_fpregs(struct user_i387_struct __user *buf, 45extern int get_fpregs(struct user_i387_struct __user *buf,
diff --git a/arch/um/kernel/exec.c b/arch/um/kernel/exec.c
index 340268be00b5..09bd7b585726 100644
--- a/arch/um/kernel/exec.c
+++ b/arch/um/kernel/exec.c
@@ -5,7 +5,6 @@
5 5
6#include "linux/stddef.h" 6#include "linux/stddef.h"
7#include "linux/fs.h" 7#include "linux/fs.h"
8#include "linux/smp_lock.h"
9#include "linux/ptrace.h" 8#include "linux/ptrace.h"
10#include "linux/sched.h" 9#include "linux/sched.h"
11#include "linux/slab.h" 10#include "linux/slab.h"
diff --git a/arch/um/kernel/ptrace.c b/arch/um/kernel/ptrace.c
index a5e33f29bbeb..701b672c1122 100644
--- a/arch/um/kernel/ptrace.c
+++ b/arch/um/kernel/ptrace.c
@@ -122,7 +122,7 @@ long arch_ptrace(struct task_struct *child, long request,
122 break; 122 break;
123 123
124 case PTRACE_SET_THREAD_AREA: 124 case PTRACE_SET_THREAD_AREA:
125 ret = ptrace_set_thread_area(child, addr, datavp); 125 ret = ptrace_set_thread_area(child, addr, vp);
126 break; 126 break;
127 127
128 case PTRACE_FAULTINFO: { 128 case PTRACE_FAULTINFO: {
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index e8327686d3c5..e330da21b84f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -21,7 +21,7 @@ config X86
21 select HAVE_UNSTABLE_SCHED_CLOCK 21 select HAVE_UNSTABLE_SCHED_CLOCK
22 select HAVE_IDE 22 select HAVE_IDE
23 select HAVE_OPROFILE 23 select HAVE_OPROFILE
24 select HAVE_PERF_EVENTS if (!M386 && !M486) 24 select HAVE_PERF_EVENTS
25 select HAVE_IRQ_WORK 25 select HAVE_IRQ_WORK
26 select HAVE_IOREMAP_PROT 26 select HAVE_IOREMAP_PROT
27 select HAVE_KPROBES 27 select HAVE_KPROBES
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 23f315c9f215..325c05294fc4 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -355,7 +355,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
355 if (heap > 0x3fffffffffffUL) 355 if (heap > 0x3fffffffffffUL)
356 error("Destination address too large"); 356 error("Destination address too large");
357#else 357#else
358 if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff)) 358 if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff))
359 error("Destination address too large"); 359 error("Destination address too large");
360#endif 360#endif
361#ifndef CONFIG_RELOCATABLE 361#ifndef CONFIG_RELOCATABLE
diff --git a/arch/x86/crypto/ghash-clmulni-intel_glue.c b/arch/x86/crypto/ghash-clmulni-intel_glue.c
index cbcc8d8ea93a..7a6e68e4f748 100644
--- a/arch/x86/crypto/ghash-clmulni-intel_glue.c
+++ b/arch/x86/crypto/ghash-clmulni-intel_glue.c
@@ -10,6 +10,7 @@
10 * by the Free Software Foundation. 10 * by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/err.h>
13#include <linux/module.h> 14#include <linux/module.h>
14#include <linux/init.h> 15#include <linux/init.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
index 849813f398e7..5852519b2d0f 100644
--- a/arch/x86/ia32/sys_ia32.c
+++ b/arch/x86/ia32/sys_ia32.c
@@ -28,7 +28,6 @@
28#include <linux/syscalls.h> 28#include <linux/syscalls.h>
29#include <linux/times.h> 29#include <linux/times.h>
30#include <linux/utsname.h> 30#include <linux/utsname.h>
31#include <linux/smp_lock.h>
32#include <linux/mm.h> 31#include <linux/mm.h>
33#include <linux/uio.h> 32#include <linux/uio.h>
34#include <linux/poll.h> 33#include <linux/poll.h>
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index 286de34b0ed6..f6ce0bda3b98 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -141,13 +141,13 @@ static inline void native_apic_msr_write(u32 reg, u32 v)
141 141
142static inline u32 native_apic_msr_read(u32 reg) 142static inline u32 native_apic_msr_read(u32 reg)
143{ 143{
144 u32 low, high; 144 u64 msr;
145 145
146 if (reg == APIC_DFR) 146 if (reg == APIC_DFR)
147 return -1; 147 return -1;
148 148
149 rdmsr(APIC_BASE_MSR + (reg >> 4), low, high); 149 rdmsrl(APIC_BASE_MSR + (reg >> 4), msr);
150 return low; 150 return (u32)msr;
151} 151}
152 152
153static inline void native_x2apic_wait_icr_idle(void) 153static inline void native_x2apic_wait_icr_idle(void)
@@ -181,12 +181,12 @@ extern void enable_x2apic(void);
181extern void x2apic_icr_write(u32 low, u32 id); 181extern void x2apic_icr_write(u32 low, u32 id);
182static inline int x2apic_enabled(void) 182static inline int x2apic_enabled(void)
183{ 183{
184 int msr, msr2; 184 u64 msr;
185 185
186 if (!cpu_has_x2apic) 186 if (!cpu_has_x2apic)
187 return 0; 187 return 0;
188 188
189 rdmsr(MSR_IA32_APICBASE, msr, msr2); 189 rdmsrl(MSR_IA32_APICBASE, msr);
190 if (msr & X2APIC_ENABLE) 190 if (msr & X2APIC_ENABLE)
191 return 1; 191 return 1;
192 return 0; 192 return 0;
diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
index 5be1542fbfaf..e99d55d74df5 100644
--- a/arch/x86/include/asm/e820.h
+++ b/arch/x86/include/asm/e820.h
@@ -72,6 +72,9 @@ struct e820map {
72#define BIOS_BEGIN 0x000a0000 72#define BIOS_BEGIN 0x000a0000
73#define BIOS_END 0x00100000 73#define BIOS_END 0x00100000
74 74
75#define BIOS_ROM_BASE 0xffe00000
76#define BIOS_ROM_END 0xffffffff
77
75#ifdef __KERNEL__ 78#ifdef __KERNEL__
76/* see comment in arch/x86/kernel/e820.c */ 79/* see comment in arch/x86/kernel/e820.c */
77extern struct e820map e820; 80extern struct e820map e820;
diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index 4d293dced62f..9479a037419f 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -216,8 +216,8 @@ static inline unsigned long virt_to_fix(const unsigned long vaddr)
216} 216}
217 217
218/* Return an pointer with offset calculated */ 218/* Return an pointer with offset calculated */
219static inline unsigned long __set_fixmap_offset(enum fixed_addresses idx, 219static __always_inline unsigned long
220 phys_addr_t phys, pgprot_t flags) 220__set_fixmap_offset(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags)
221{ 221{
222 __set_fixmap(idx, phys, flags); 222 __set_fixmap(idx, phys, flags);
223 return fix_to_virt(idx) + (phys & (PAGE_SIZE - 1)); 223 return fix_to_virt(idx) + (phys & (PAGE_SIZE - 1));
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 9e6fe391094e..f702f82aa1eb 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -79,7 +79,7 @@
79#define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT) 79#define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT)
80#define KVM_MIN_FREE_MMU_PAGES 5 80#define KVM_MIN_FREE_MMU_PAGES 5
81#define KVM_REFILL_PAGES 25 81#define KVM_REFILL_PAGES 25
82#define KVM_MAX_CPUID_ENTRIES 40 82#define KVM_MAX_CPUID_ENTRIES 80
83#define KVM_NR_FIXED_MTRR_REGION 88 83#define KVM_NR_FIXED_MTRR_REGION 88
84#define KVM_NR_VAR_MTRR 8 84#define KVM_NR_VAR_MTRR 8
85 85
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 3ea3dc487047..6b89f5e86021 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -128,7 +128,7 @@
128#define FAM10H_MMIO_CONF_ENABLE (1<<0) 128#define FAM10H_MMIO_CONF_ENABLE (1<<0)
129#define FAM10H_MMIO_CONF_BUSRANGE_MASK 0xf 129#define FAM10H_MMIO_CONF_BUSRANGE_MASK 0xf
130#define FAM10H_MMIO_CONF_BUSRANGE_SHIFT 2 130#define FAM10H_MMIO_CONF_BUSRANGE_SHIFT 2
131#define FAM10H_MMIO_CONF_BASE_MASK 0xfffffff 131#define FAM10H_MMIO_CONF_BASE_MASK 0xfffffffULL
132#define FAM10H_MMIO_CONF_BASE_SHIFT 20 132#define FAM10H_MMIO_CONF_BASE_SHIFT 20
133#define MSR_FAM10H_NODE_ID 0xc001100c 133#define MSR_FAM10H_NODE_ID 0xc001100c
134 134
diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
index 18e3b8a8709f..ef9975812c77 100644
--- a/arch/x86/include/asm/paravirt.h
+++ b/arch/x86/include/asm/paravirt.h
@@ -824,27 +824,27 @@ static __always_inline void arch_spin_unlock(struct arch_spinlock *lock)
824#define __PV_IS_CALLEE_SAVE(func) \ 824#define __PV_IS_CALLEE_SAVE(func) \
825 ((struct paravirt_callee_save) { func }) 825 ((struct paravirt_callee_save) { func })
826 826
827static inline unsigned long arch_local_save_flags(void) 827static inline notrace unsigned long arch_local_save_flags(void)
828{ 828{
829 return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl); 829 return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl);
830} 830}
831 831
832static inline void arch_local_irq_restore(unsigned long f) 832static inline notrace void arch_local_irq_restore(unsigned long f)
833{ 833{
834 PVOP_VCALLEE1(pv_irq_ops.restore_fl, f); 834 PVOP_VCALLEE1(pv_irq_ops.restore_fl, f);
835} 835}
836 836
837static inline void arch_local_irq_disable(void) 837static inline notrace void arch_local_irq_disable(void)
838{ 838{
839 PVOP_VCALLEE0(pv_irq_ops.irq_disable); 839 PVOP_VCALLEE0(pv_irq_ops.irq_disable);
840} 840}
841 841
842static inline void arch_local_irq_enable(void) 842static inline notrace void arch_local_irq_enable(void)
843{ 843{
844 PVOP_VCALLEE0(pv_irq_ops.irq_enable); 844 PVOP_VCALLEE0(pv_irq_ops.irq_enable);
845} 845}
846 846
847static inline unsigned long arch_local_irq_save(void) 847static inline notrace unsigned long arch_local_irq_save(void)
848{ 848{
849 unsigned long f; 849 unsigned long f;
850 850
diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
index 7f7e577a0e39..31d84acc1512 100644
--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -11,6 +11,7 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src);
11void pvclock_read_wallclock(struct pvclock_wall_clock *wall, 11void pvclock_read_wallclock(struct pvclock_wall_clock *wall,
12 struct pvclock_vcpu_time_info *vcpu, 12 struct pvclock_vcpu_time_info *vcpu,
13 struct timespec *ts); 13 struct timespec *ts);
14void pvclock_resume(void);
14 15
15/* 16/*
16 * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, 17 * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
diff --git a/arch/x86/include/asm/uv/uv_hub.h b/arch/x86/include/asm/uv/uv_hub.h
index e969f691cbfd..a501741c2335 100644
--- a/arch/x86/include/asm/uv/uv_hub.h
+++ b/arch/x86/include/asm/uv/uv_hub.h
@@ -199,6 +199,8 @@ union uvh_apicid {
199#define UVH_APICID 0x002D0E00L 199#define UVH_APICID 0x002D0E00L
200#define UV_APIC_PNODE_SHIFT 6 200#define UV_APIC_PNODE_SHIFT 6
201 201
202#define UV_APICID_HIBIT_MASK 0xffff0000
203
202/* Local Bus from cpu's perspective */ 204/* Local Bus from cpu's perspective */
203#define LOCAL_BUS_BASE 0x1c00000 205#define LOCAL_BUS_BASE 0x1c00000
204#define LOCAL_BUS_SIZE (4 * 1024 * 1024) 206#define LOCAL_BUS_SIZE (4 * 1024 * 1024)
@@ -491,8 +493,10 @@ static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value)
491 } 493 }
492} 494}
493 495
496extern unsigned int uv_apicid_hibits;
494static unsigned long uv_hub_ipi_value(int apicid, int vector, int mode) 497static unsigned long uv_hub_ipi_value(int apicid, int vector, int mode)
495{ 498{
499 apicid |= uv_apicid_hibits;
496 return (1UL << UVH_IPI_INT_SEND_SHFT) | 500 return (1UL << UVH_IPI_INT_SEND_SHFT) |
497 ((apicid) << UVH_IPI_INT_APIC_ID_SHFT) | 501 ((apicid) << UVH_IPI_INT_APIC_ID_SHFT) |
498 (mode << UVH_IPI_INT_DELIVERY_MODE_SHFT) | 502 (mode << UVH_IPI_INT_DELIVERY_MODE_SHFT) |
diff --git a/arch/x86/include/asm/uv/uv_mmrs.h b/arch/x86/include/asm/uv/uv_mmrs.h
index b2f2d2e05cec..20cafeac7455 100644
--- a/arch/x86/include/asm/uv/uv_mmrs.h
+++ b/arch/x86/include/asm/uv/uv_mmrs.h
@@ -5,7 +5,7 @@
5 * 5 *
6 * SGI UV MMR definitions 6 * SGI UV MMR definitions
7 * 7 *
8 * Copyright (C) 2007-2008 Silicon Graphics, Inc. All rights reserved. 8 * Copyright (C) 2007-2010 Silicon Graphics, Inc. All rights reserved.
9 */ 9 */
10 10
11#ifndef _ASM_X86_UV_UV_MMRS_H 11#ifndef _ASM_X86_UV_UV_MMRS_H
@@ -754,6 +754,23 @@ union uvh_lb_bau_sb_descriptor_base_u {
754}; 754};
755 755
756/* ========================================================================= */ 756/* ========================================================================= */
757/* UVH_LB_TARGET_PHYSICAL_APIC_ID_MASK */
758/* ========================================================================= */
759#define UVH_LB_TARGET_PHYSICAL_APIC_ID_MASK 0x320130UL
760#define UVH_LB_TARGET_PHYSICAL_APIC_ID_MASK_32 0x009f0
761
762#define UVH_LB_TARGET_PHYSICAL_APIC_ID_MASK_BIT_ENABLES_SHFT 0
763#define UVH_LB_TARGET_PHYSICAL_APIC_ID_MASK_BIT_ENABLES_MASK 0x00000000ffffffffUL
764
765union uvh_lb_target_physical_apic_id_mask_u {
766 unsigned long v;
767 struct uvh_lb_target_physical_apic_id_mask_s {
768 unsigned long bit_enables : 32; /* RW */
769 unsigned long rsvd_32_63 : 32; /* */
770 } s;
771};
772
773/* ========================================================================= */
757/* UVH_NODE_ID */ 774/* UVH_NODE_ID */
758/* ========================================================================= */ 775/* ========================================================================= */
759#define UVH_NODE_ID 0x0UL 776#define UVH_NODE_ID 0x0UL
@@ -806,6 +823,78 @@ union uvh_node_present_table_u {
806}; 823};
807 824
808/* ========================================================================= */ 825/* ========================================================================= */
826/* UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR */
827/* ========================================================================= */
828#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR 0x16000c8UL
829
830#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR_BASE_SHFT 24
831#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR_BASE_MASK 0x00000000ff000000UL
832#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR_M_ALIAS_SHFT 48
833#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR_M_ALIAS_MASK 0x001f000000000000UL
834#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR_ENABLE_SHFT 63
835#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR_ENABLE_MASK 0x8000000000000000UL
836
837union uvh_rh_gam_alias210_overlay_config_0_mmr_u {
838 unsigned long v;
839 struct uvh_rh_gam_alias210_overlay_config_0_mmr_s {
840 unsigned long rsvd_0_23: 24; /* */
841 unsigned long base : 8; /* RW */
842 unsigned long rsvd_32_47: 16; /* */
843 unsigned long m_alias : 5; /* RW */
844 unsigned long rsvd_53_62: 10; /* */
845 unsigned long enable : 1; /* RW */
846 } s;
847};
848
849/* ========================================================================= */
850/* UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR */
851/* ========================================================================= */
852#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR 0x16000d8UL
853
854#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR_BASE_SHFT 24
855#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR_BASE_MASK 0x00000000ff000000UL
856#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR_M_ALIAS_SHFT 48
857#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR_M_ALIAS_MASK 0x001f000000000000UL
858#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR_ENABLE_SHFT 63
859#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR_ENABLE_MASK 0x8000000000000000UL
860
861union uvh_rh_gam_alias210_overlay_config_1_mmr_u {
862 unsigned long v;
863 struct uvh_rh_gam_alias210_overlay_config_1_mmr_s {
864 unsigned long rsvd_0_23: 24; /* */
865 unsigned long base : 8; /* RW */
866 unsigned long rsvd_32_47: 16; /* */
867 unsigned long m_alias : 5; /* RW */
868 unsigned long rsvd_53_62: 10; /* */
869 unsigned long enable : 1; /* RW */
870 } s;
871};
872
873/* ========================================================================= */
874/* UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR */
875/* ========================================================================= */
876#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR 0x16000e8UL
877
878#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR_BASE_SHFT 24
879#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR_BASE_MASK 0x00000000ff000000UL
880#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR_M_ALIAS_SHFT 48
881#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR_M_ALIAS_MASK 0x001f000000000000UL
882#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR_ENABLE_SHFT 63
883#define UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR_ENABLE_MASK 0x8000000000000000UL
884
885union uvh_rh_gam_alias210_overlay_config_2_mmr_u {
886 unsigned long v;
887 struct uvh_rh_gam_alias210_overlay_config_2_mmr_s {
888 unsigned long rsvd_0_23: 24; /* */
889 unsigned long base : 8; /* RW */
890 unsigned long rsvd_32_47: 16; /* */
891 unsigned long m_alias : 5; /* RW */
892 unsigned long rsvd_53_62: 10; /* */
893 unsigned long enable : 1; /* RW */
894 } s;
895};
896
897/* ========================================================================= */
809/* UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR */ 898/* UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR */
810/* ========================================================================= */ 899/* ========================================================================= */
811#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR 0x16000d0UL 900#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR 0x16000d0UL
@@ -857,6 +946,29 @@ union uvh_rh_gam_alias210_redirect_config_2_mmr_u {
857}; 946};
858 947
859/* ========================================================================= */ 948/* ========================================================================= */
949/* UVH_RH_GAM_CONFIG_MMR */
950/* ========================================================================= */
951#define UVH_RH_GAM_CONFIG_MMR 0x1600000UL
952
953#define UVH_RH_GAM_CONFIG_MMR_M_SKT_SHFT 0
954#define UVH_RH_GAM_CONFIG_MMR_M_SKT_MASK 0x000000000000003fUL
955#define UVH_RH_GAM_CONFIG_MMR_N_SKT_SHFT 6
956#define UVH_RH_GAM_CONFIG_MMR_N_SKT_MASK 0x00000000000003c0UL
957#define UVH_RH_GAM_CONFIG_MMR_MMIOL_CFG_SHFT 12
958#define UVH_RH_GAM_CONFIG_MMR_MMIOL_CFG_MASK 0x0000000000001000UL
959
960union uvh_rh_gam_config_mmr_u {
961 unsigned long v;
962 struct uvh_rh_gam_config_mmr_s {
963 unsigned long m_skt : 6; /* RW */
964 unsigned long n_skt : 4; /* RW */
965 unsigned long rsvd_10_11: 2; /* */
966 unsigned long mmiol_cfg : 1; /* RW */
967 unsigned long rsvd_13_63: 51; /* */
968 } s;
969};
970
971/* ========================================================================= */
860/* UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR */ 972/* UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR */
861/* ========================================================================= */ 973/* ========================================================================= */
862#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR 0x1600010UL 974#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR 0x1600010UL
@@ -987,97 +1099,5 @@ union uvh_rtc1_int_config_u {
987 } s; 1099 } s;
988}; 1100};
989 1101
990/* ========================================================================= */
991/* UVH_SI_ADDR_MAP_CONFIG */
992/* ========================================================================= */
993#define UVH_SI_ADDR_MAP_CONFIG 0xc80000UL
994
995#define UVH_SI_ADDR_MAP_CONFIG_M_SKT_SHFT 0
996#define UVH_SI_ADDR_MAP_CONFIG_M_SKT_MASK 0x000000000000003fUL
997#define UVH_SI_ADDR_MAP_CONFIG_N_SKT_SHFT 8
998#define UVH_SI_ADDR_MAP_CONFIG_N_SKT_MASK 0x0000000000000f00UL
999
1000union uvh_si_addr_map_config_u {
1001 unsigned long v;
1002 struct uvh_si_addr_map_config_s {
1003 unsigned long m_skt : 6; /* RW */
1004 unsigned long rsvd_6_7: 2; /* */
1005 unsigned long n_skt : 4; /* RW */
1006 unsigned long rsvd_12_63: 52; /* */
1007 } s;
1008};
1009
1010/* ========================================================================= */
1011/* UVH_SI_ALIAS0_OVERLAY_CONFIG */
1012/* ========================================================================= */
1013#define UVH_SI_ALIAS0_OVERLAY_CONFIG 0xc80008UL
1014
1015#define UVH_SI_ALIAS0_OVERLAY_CONFIG_BASE_SHFT 24
1016#define UVH_SI_ALIAS0_OVERLAY_CONFIG_BASE_MASK 0x00000000ff000000UL
1017#define UVH_SI_ALIAS0_OVERLAY_CONFIG_M_ALIAS_SHFT 48
1018#define UVH_SI_ALIAS0_OVERLAY_CONFIG_M_ALIAS_MASK 0x001f000000000000UL
1019#define UVH_SI_ALIAS0_OVERLAY_CONFIG_ENABLE_SHFT 63
1020#define UVH_SI_ALIAS0_OVERLAY_CONFIG_ENABLE_MASK 0x8000000000000000UL
1021
1022union uvh_si_alias0_overlay_config_u {
1023 unsigned long v;
1024 struct uvh_si_alias0_overlay_config_s {
1025 unsigned long rsvd_0_23: 24; /* */
1026 unsigned long base : 8; /* RW */
1027 unsigned long rsvd_32_47: 16; /* */
1028 unsigned long m_alias : 5; /* RW */
1029 unsigned long rsvd_53_62: 10; /* */
1030 unsigned long enable : 1; /* RW */
1031 } s;
1032};
1033
1034/* ========================================================================= */
1035/* UVH_SI_ALIAS1_OVERLAY_CONFIG */
1036/* ========================================================================= */
1037#define UVH_SI_ALIAS1_OVERLAY_CONFIG 0xc80010UL
1038
1039#define UVH_SI_ALIAS1_OVERLAY_CONFIG_BASE_SHFT 24
1040#define UVH_SI_ALIAS1_OVERLAY_CONFIG_BASE_MASK 0x00000000ff000000UL
1041#define UVH_SI_ALIAS1_OVERLAY_CONFIG_M_ALIAS_SHFT 48
1042#define UVH_SI_ALIAS1_OVERLAY_CONFIG_M_ALIAS_MASK 0x001f000000000000UL
1043#define UVH_SI_ALIAS1_OVERLAY_CONFIG_ENABLE_SHFT 63
1044#define UVH_SI_ALIAS1_OVERLAY_CONFIG_ENABLE_MASK 0x8000000000000000UL
1045
1046union uvh_si_alias1_overlay_config_u {
1047 unsigned long v;
1048 struct uvh_si_alias1_overlay_config_s {
1049 unsigned long rsvd_0_23: 24; /* */
1050 unsigned long base : 8; /* RW */
1051 unsigned long rsvd_32_47: 16; /* */
1052 unsigned long m_alias : 5; /* RW */
1053 unsigned long rsvd_53_62: 10; /* */
1054 unsigned long enable : 1; /* RW */
1055 } s;
1056};
1057
1058/* ========================================================================= */
1059/* UVH_SI_ALIAS2_OVERLAY_CONFIG */
1060/* ========================================================================= */
1061#define UVH_SI_ALIAS2_OVERLAY_CONFIG 0xc80018UL
1062
1063#define UVH_SI_ALIAS2_OVERLAY_CONFIG_BASE_SHFT 24
1064#define UVH_SI_ALIAS2_OVERLAY_CONFIG_BASE_MASK 0x00000000ff000000UL
1065#define UVH_SI_ALIAS2_OVERLAY_CONFIG_M_ALIAS_SHFT 48
1066#define UVH_SI_ALIAS2_OVERLAY_CONFIG_M_ALIAS_MASK 0x001f000000000000UL
1067#define UVH_SI_ALIAS2_OVERLAY_CONFIG_ENABLE_SHFT 63
1068#define UVH_SI_ALIAS2_OVERLAY_CONFIG_ENABLE_MASK 0x8000000000000000UL
1069
1070union uvh_si_alias2_overlay_config_u {
1071 unsigned long v;
1072 struct uvh_si_alias2_overlay_config_s {
1073 unsigned long rsvd_0_23: 24; /* */
1074 unsigned long base : 8; /* RW */
1075 unsigned long rsvd_32_47: 16; /* */
1076 unsigned long m_alias : 5; /* RW */
1077 unsigned long rsvd_53_62: 10; /* */
1078 unsigned long enable : 1; /* RW */
1079 } s;
1080};
1081
1082 1102
1083#endif /* _ASM_X86_UV_UV_MMRS_H */ 1103#endif /* __ASM_UV_MMRS_X86_H__ */
diff --git a/arch/x86/include/asm/xen/interface.h b/arch/x86/include/asm/xen/interface.h
index e8506c1f0c55..1c10c88ee4e1 100644
--- a/arch/x86/include/asm/xen/interface.h
+++ b/arch/x86/include/asm/xen/interface.h
@@ -61,9 +61,9 @@ DEFINE_GUEST_HANDLE(void);
61#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START) 61#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
62#endif 62#endif
63 63
64#ifndef machine_to_phys_mapping 64#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START)
65#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START) 65#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END)
66#endif 66#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>__MACH2PHYS_SHIFT)
67 67
68/* Maximum number of virtual CPUs in multi-processor guests. */ 68/* Maximum number of virtual CPUs in multi-processor guests. */
69#define MAX_VIRT_CPUS 32 69#define MAX_VIRT_CPUS 32
diff --git a/arch/x86/include/asm/xen/interface_32.h b/arch/x86/include/asm/xen/interface_32.h
index 42a7e004ae5c..8413688b2571 100644
--- a/arch/x86/include/asm/xen/interface_32.h
+++ b/arch/x86/include/asm/xen/interface_32.h
@@ -32,6 +32,11 @@
32/* And the trap vector is... */ 32/* And the trap vector is... */
33#define TRAP_INSTR "int $0x82" 33#define TRAP_INSTR "int $0x82"
34 34
35#define __MACH2PHYS_VIRT_START 0xF5800000
36#define __MACH2PHYS_VIRT_END 0xF6800000
37
38#define __MACH2PHYS_SHIFT 2
39
35/* 40/*
36 * Virtual addresses beyond this are not modifiable by guest OSes. The 41 * Virtual addresses beyond this are not modifiable by guest OSes. The
37 * machine->physical mapping table starts at this address, read-only. 42 * machine->physical mapping table starts at this address, read-only.
diff --git a/arch/x86/include/asm/xen/interface_64.h b/arch/x86/include/asm/xen/interface_64.h
index 100d2662b97c..839a4811cf98 100644
--- a/arch/x86/include/asm/xen/interface_64.h
+++ b/arch/x86/include/asm/xen/interface_64.h
@@ -39,18 +39,7 @@
39#define __HYPERVISOR_VIRT_END 0xFFFF880000000000 39#define __HYPERVISOR_VIRT_END 0xFFFF880000000000
40#define __MACH2PHYS_VIRT_START 0xFFFF800000000000 40#define __MACH2PHYS_VIRT_START 0xFFFF800000000000
41#define __MACH2PHYS_VIRT_END 0xFFFF804000000000 41#define __MACH2PHYS_VIRT_END 0xFFFF804000000000
42 42#define __MACH2PHYS_SHIFT 3
43#ifndef HYPERVISOR_VIRT_START
44#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
45#define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END)
46#endif
47
48#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START)
49#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END)
50#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
51#ifndef machine_to_phys_mapping
52#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
53#endif
54 43
55/* 44/*
56 * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base) 45 * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index dd8c1414b3d5..8760cc60a21c 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -5,6 +5,7 @@
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/spinlock.h> 6#include <linux/spinlock.h>
7#include <linux/pfn.h> 7#include <linux/pfn.h>
8#include <linux/mm.h>
8 9
9#include <asm/uaccess.h> 10#include <asm/uaccess.h>
10#include <asm/page.h> 11#include <asm/page.h>
@@ -35,6 +36,8 @@ typedef struct xpaddr {
35#define MAX_DOMAIN_PAGES \ 36#define MAX_DOMAIN_PAGES \
36 ((unsigned long)((u64)CONFIG_XEN_MAX_DOMAIN_MEMORY * 1024 * 1024 * 1024 / PAGE_SIZE)) 37 ((unsigned long)((u64)CONFIG_XEN_MAX_DOMAIN_MEMORY * 1024 * 1024 * 1024 / PAGE_SIZE))
37 38
39extern unsigned long *machine_to_phys_mapping;
40extern unsigned int machine_to_phys_order;
38 41
39extern unsigned long get_phys_to_machine(unsigned long pfn); 42extern unsigned long get_phys_to_machine(unsigned long pfn);
40extern bool set_phys_to_machine(unsigned long pfn, unsigned long mfn); 43extern bool set_phys_to_machine(unsigned long pfn, unsigned long mfn);
@@ -69,10 +72,8 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
69 if (xen_feature(XENFEAT_auto_translated_physmap)) 72 if (xen_feature(XENFEAT_auto_translated_physmap))
70 return mfn; 73 return mfn;
71 74
72#if 0
73 if (unlikely((mfn >> machine_to_phys_order) != 0)) 75 if (unlikely((mfn >> machine_to_phys_order) != 0))
74 return max_mapnr; 76 return ~0;
75#endif
76 77
77 pfn = 0; 78 pfn = 0;
78 /* 79 /*
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 9e13763b6092..1e994754d323 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -45,6 +45,7 @@ obj-y += pci-dma.o quirks.o i8237.o topology.o kdebugfs.o
45obj-y += alternative.o i8253.o pci-nommu.o hw_breakpoint.o 45obj-y += alternative.o i8253.o pci-nommu.o hw_breakpoint.o
46obj-y += tsc.o io_delay.o rtc.o 46obj-y += tsc.o io_delay.o rtc.o
47obj-y += pci-iommu_table.o 47obj-y += pci-iommu_table.o
48obj-y += resource.o
48 49
49obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o 50obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o
50obj-y += process.o 51obj-y += process.o
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 850657d1b0ed..78218135b48e 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -52,7 +52,6 @@
52#include <asm/mce.h> 52#include <asm/mce.h>
53#include <asm/kvm_para.h> 53#include <asm/kvm_para.h>
54#include <asm/tsc.h> 54#include <asm/tsc.h>
55#include <asm/atomic.h>
56 55
57unsigned int num_processors; 56unsigned int num_processors;
58 57
@@ -1390,6 +1389,14 @@ void __cpuinit end_local_APIC_setup(void)
1390 1389
1391 setup_apic_nmi_watchdog(NULL); 1390 setup_apic_nmi_watchdog(NULL);
1392 apic_pm_activate(); 1391 apic_pm_activate();
1392
1393 /*
1394 * Now that local APIC setup is completed for BP, configure the fault
1395 * handling for interrupt remapping.
1396 */
1397 if (!smp_processor_id() && intr_remapping_enabled)
1398 enable_drhd_fault_handling();
1399
1393} 1400}
1394 1401
1395#ifdef CONFIG_X86_X2APIC 1402#ifdef CONFIG_X86_X2APIC
diff --git a/arch/x86/kernel/apic/hw_nmi.c b/arch/x86/kernel/apic/hw_nmi.c
index cefd6942f0e9..62f6e1e55b90 100644
--- a/arch/x86/kernel/apic/hw_nmi.c
+++ b/arch/x86/kernel/apic/hw_nmi.c
@@ -17,15 +17,16 @@
17#include <linux/nmi.h> 17#include <linux/nmi.h>
18#include <linux/module.h> 18#include <linux/module.h>
19 19
20/* For reliability, we're prepared to waste bits here. */
21static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
22
23u64 hw_nmi_get_sample_period(void) 20u64 hw_nmi_get_sample_period(void)
24{ 21{
25 return (u64)(cpu_khz) * 1000 * 60; 22 return (u64)(cpu_khz) * 1000 * 60;
26} 23}
27 24
28#ifdef ARCH_HAS_NMI_WATCHDOG 25#ifdef ARCH_HAS_NMI_WATCHDOG
26
27/* For reliability, we're prepared to waste bits here. */
28static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
29
29void arch_trigger_all_cpu_backtrace(void) 30void arch_trigger_all_cpu_backtrace(void)
30{ 31{
31 int i; 32 int i;
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 7cc0a721f628..fadcd743a74f 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -2430,13 +2430,12 @@ static void ack_apic_level(struct irq_data *data)
2430{ 2430{
2431 struct irq_cfg *cfg = data->chip_data; 2431 struct irq_cfg *cfg = data->chip_data;
2432 int i, do_unmask_irq = 0, irq = data->irq; 2432 int i, do_unmask_irq = 0, irq = data->irq;
2433 struct irq_desc *desc = irq_to_desc(irq);
2434 unsigned long v; 2433 unsigned long v;
2435 2434
2436 irq_complete_move(cfg); 2435 irq_complete_move(cfg);
2437#ifdef CONFIG_GENERIC_PENDING_IRQ 2436#ifdef CONFIG_GENERIC_PENDING_IRQ
2438 /* If we are moving the irq we need to mask it */ 2437 /* If we are moving the irq we need to mask it */
2439 if (unlikely(desc->status & IRQ_MOVE_PENDING)) { 2438 if (unlikely(irq_to_desc(irq)->status & IRQ_MOVE_PENDING)) {
2440 do_unmask_irq = 1; 2439 do_unmask_irq = 1;
2441 mask_ioapic(cfg); 2440 mask_ioapic(cfg);
2442 } 2441 }
@@ -3413,6 +3412,7 @@ dmar_msi_set_affinity(struct irq_data *data, const struct cpumask *mask,
3413 msg.data |= MSI_DATA_VECTOR(cfg->vector); 3412 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3414 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK; 3413 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3415 msg.address_lo |= MSI_ADDR_DEST_ID(dest); 3414 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3415 msg.address_hi = MSI_ADDR_BASE_HI | MSI_ADDR_EXT_DEST_ID(dest);
3416 3416
3417 dmar_msi_write(irq, &msg); 3417 dmar_msi_write(irq, &msg);
3418 3418
diff --git a/arch/x86/kernel/apic/probe_64.c b/arch/x86/kernel/apic/probe_64.c
index f9e4e6a54073..d8c4a6feb286 100644
--- a/arch/x86/kernel/apic/probe_64.c
+++ b/arch/x86/kernel/apic/probe_64.c
@@ -79,13 +79,6 @@ void __init default_setup_apic_routing(void)
79 /* need to update phys_pkg_id */ 79 /* need to update phys_pkg_id */
80 apic->phys_pkg_id = apicid_phys_pkg_id; 80 apic->phys_pkg_id = apicid_phys_pkg_id;
81 } 81 }
82
83 /*
84 * Now that apic routing model is selected, configure the
85 * fault handling for intr remapping.
86 */
87 if (intr_remapping_enabled)
88 enable_drhd_fault_handling();
89} 82}
90 83
91/* Same for both flat and physical. */ 84/* Same for both flat and physical. */
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index ed4118de249e..c1c52c341f40 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -44,6 +44,8 @@ static u64 gru_start_paddr, gru_end_paddr;
44static union uvh_apicid uvh_apicid; 44static union uvh_apicid uvh_apicid;
45int uv_min_hub_revision_id; 45int uv_min_hub_revision_id;
46EXPORT_SYMBOL_GPL(uv_min_hub_revision_id); 46EXPORT_SYMBOL_GPL(uv_min_hub_revision_id);
47unsigned int uv_apicid_hibits;
48EXPORT_SYMBOL_GPL(uv_apicid_hibits);
47static DEFINE_SPINLOCK(uv_nmi_lock); 49static DEFINE_SPINLOCK(uv_nmi_lock);
48 50
49static inline bool is_GRU_range(u64 start, u64 end) 51static inline bool is_GRU_range(u64 start, u64 end)
@@ -85,6 +87,23 @@ static void __init early_get_apic_pnode_shift(void)
85 uvh_apicid.s.pnode_shift = UV_APIC_PNODE_SHIFT; 87 uvh_apicid.s.pnode_shift = UV_APIC_PNODE_SHIFT;
86} 88}
87 89
90/*
91 * Add an extra bit as dictated by bios to the destination apicid of
92 * interrupts potentially passing through the UV HUB. This prevents
93 * a deadlock between interrupts and IO port operations.
94 */
95static void __init uv_set_apicid_hibit(void)
96{
97 union uvh_lb_target_physical_apic_id_mask_u apicid_mask;
98 unsigned long *mmr;
99
100 mmr = early_ioremap(UV_LOCAL_MMR_BASE |
101 UVH_LB_TARGET_PHYSICAL_APIC_ID_MASK, sizeof(*mmr));
102 apicid_mask.v = *mmr;
103 early_iounmap(mmr, sizeof(*mmr));
104 uv_apicid_hibits = apicid_mask.s.bit_enables & UV_APICID_HIBIT_MASK;
105}
106
88static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id) 107static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
89{ 108{
90 int nodeid; 109 int nodeid;
@@ -102,6 +121,7 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
102 __get_cpu_var(x2apic_extra_bits) = 121 __get_cpu_var(x2apic_extra_bits) =
103 nodeid << (uvh_apicid.s.pnode_shift - 1); 122 nodeid << (uvh_apicid.s.pnode_shift - 1);
104 uv_system_type = UV_NON_UNIQUE_APIC; 123 uv_system_type = UV_NON_UNIQUE_APIC;
124 uv_set_apicid_hibit();
105 return 1; 125 return 1;
106 } 126 }
107 } 127 }
@@ -155,6 +175,7 @@ static int __cpuinit uv_wakeup_secondary(int phys_apicid, unsigned long start_ri
155 int pnode; 175 int pnode;
156 176
157 pnode = uv_apicid_to_pnode(phys_apicid); 177 pnode = uv_apicid_to_pnode(phys_apicid);
178 phys_apicid |= uv_apicid_hibits;
158 val = (1UL << UVH_IPI_INT_SEND_SHFT) | 179 val = (1UL << UVH_IPI_INT_SEND_SHFT) |
159 (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) | 180 (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
160 ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) | 181 ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
@@ -236,7 +257,7 @@ static unsigned int uv_cpu_mask_to_apicid(const struct cpumask *cpumask)
236 int cpu = cpumask_first(cpumask); 257 int cpu = cpumask_first(cpumask);
237 258
238 if ((unsigned)cpu < nr_cpu_ids) 259 if ((unsigned)cpu < nr_cpu_ids)
239 return per_cpu(x86_cpu_to_apicid, cpu); 260 return per_cpu(x86_cpu_to_apicid, cpu) | uv_apicid_hibits;
240 else 261 else
241 return BAD_APICID; 262 return BAD_APICID;
242} 263}
@@ -255,7 +276,7 @@ uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
255 if (cpumask_test_cpu(cpu, cpu_online_mask)) 276 if (cpumask_test_cpu(cpu, cpu_online_mask))
256 break; 277 break;
257 } 278 }
258 return per_cpu(x86_cpu_to_apicid, cpu); 279 return per_cpu(x86_cpu_to_apicid, cpu) | uv_apicid_hibits;
259} 280}
260 281
261static unsigned int x2apic_get_apic_id(unsigned long x) 282static unsigned int x2apic_get_apic_id(unsigned long x)
@@ -379,14 +400,14 @@ struct redir_addr {
379#define DEST_SHIFT UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT 400#define DEST_SHIFT UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT
380 401
381static __initdata struct redir_addr redir_addrs[] = { 402static __initdata struct redir_addr redir_addrs[] = {
382 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR, UVH_SI_ALIAS0_OVERLAY_CONFIG}, 403 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR, UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR},
383 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR, UVH_SI_ALIAS1_OVERLAY_CONFIG}, 404 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR, UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR},
384 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR, UVH_SI_ALIAS2_OVERLAY_CONFIG}, 405 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR, UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR},
385}; 406};
386 407
387static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size) 408static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size)
388{ 409{
389 union uvh_si_alias0_overlay_config_u alias; 410 union uvh_rh_gam_alias210_overlay_config_2_mmr_u alias;
390 union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect; 411 union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect;
391 int i; 412 int i;
392 413
@@ -660,7 +681,7 @@ void uv_nmi_init(void)
660 681
661void __init uv_system_init(void) 682void __init uv_system_init(void)
662{ 683{
663 union uvh_si_addr_map_config_u m_n_config; 684 union uvh_rh_gam_config_mmr_u m_n_config;
664 union uvh_node_id_u node_id; 685 union uvh_node_id_u node_id;
665 unsigned long gnode_upper, lowmem_redir_base, lowmem_redir_size; 686 unsigned long gnode_upper, lowmem_redir_base, lowmem_redir_size;
666 int bytes, nid, cpu, lcpu, pnode, blade, i, j, m_val, n_val; 687 int bytes, nid, cpu, lcpu, pnode, blade, i, j, m_val, n_val;
@@ -670,7 +691,7 @@ void __init uv_system_init(void)
670 691
671 map_low_mmrs(); 692 map_low_mmrs();
672 693
673 m_n_config.v = uv_read_local_mmr(UVH_SI_ADDR_MAP_CONFIG); 694 m_n_config.v = uv_read_local_mmr(UVH_RH_GAM_CONFIG_MMR );
674 m_val = m_n_config.s.m_skt; 695 m_val = m_n_config.s.m_skt;
675 n_val = m_n_config.s.n_skt; 696 n_val = m_n_config.s.n_skt;
676 mmr_base = 697 mmr_base =
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index ed6310183efb..6d75b9145b13 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -381,6 +381,20 @@ static void release_pmc_hardware(void) {}
381 381
382#endif 382#endif
383 383
384static bool check_hw_exists(void)
385{
386 u64 val, val_new = 0;
387 int ret = 0;
388
389 val = 0xabcdUL;
390 ret |= checking_wrmsrl(x86_pmu.perfctr, val);
391 ret |= rdmsrl_safe(x86_pmu.perfctr, &val_new);
392 if (ret || val != val_new)
393 return false;
394
395 return true;
396}
397
384static void reserve_ds_buffers(void); 398static void reserve_ds_buffers(void);
385static void release_ds_buffers(void); 399static void release_ds_buffers(void);
386 400
@@ -1372,6 +1386,12 @@ void __init init_hw_perf_events(void)
1372 1386
1373 pmu_check_apic(); 1387 pmu_check_apic();
1374 1388
1389 /* sanity check that the hardware exists or is emulated */
1390 if (!check_hw_exists()) {
1391 pr_cont("Broken PMU hardware detected, software events only.\n");
1392 return;
1393 }
1394
1375 pr_cont("%s PMU driver.\n", x86_pmu.name); 1395 pr_cont("%s PMU driver.\n", x86_pmu.name);
1376 1396
1377 if (x86_pmu.quirks) 1397 if (x86_pmu.quirks)
diff --git a/arch/x86/kernel/cpu/perf_event_amd.c b/arch/x86/kernel/cpu/perf_event_amd.c
index 46d58448c3af..e421b8cd6944 100644
--- a/arch/x86/kernel/cpu/perf_event_amd.c
+++ b/arch/x86/kernel/cpu/perf_event_amd.c
@@ -280,11 +280,11 @@ static struct amd_nb *amd_alloc_nb(int cpu, int nb_id)
280 struct amd_nb *nb; 280 struct amd_nb *nb;
281 int i; 281 int i;
282 282
283 nb = kmalloc(sizeof(struct amd_nb), GFP_KERNEL); 283 nb = kmalloc_node(sizeof(struct amd_nb), GFP_KERNEL | __GFP_ZERO,
284 cpu_to_node(cpu));
284 if (!nb) 285 if (!nb)
285 return NULL; 286 return NULL;
286 287
287 memset(nb, 0, sizeof(*nb));
288 nb->nb_id = nb_id; 288 nb->nb_id = nb_id;
289 289
290 /* 290 /*
diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index 1b7b31ab7d86..212a6a42527c 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -33,7 +33,6 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/poll.h> 34#include <linux/poll.h>
35#include <linux/smp.h> 35#include <linux/smp.h>
36#include <linux/smp_lock.h>
37#include <linux/major.h> 36#include <linux/major.h>
38#include <linux/fs.h> 37#include <linux/fs.h>
39#include <linux/device.h> 38#include <linux/device.h>
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index 59e175e89599..591e60104278 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -395,7 +395,7 @@ sysenter_past_esp:
395 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words 395 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
396 * pushed above; +8 corresponds to copy_thread's esp0 setting. 396 * pushed above; +8 corresponds to copy_thread's esp0 setting.
397 */ 397 */
398 pushl_cfi (TI_sysenter_return-THREAD_SIZE_asm+8+4*4)(%esp) 398 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE_asm+8+4*4)(%esp)
399 CFI_REL_OFFSET eip, 0 399 CFI_REL_OFFSET eip, 0
400 400
401 pushl_cfi %eax 401 pushl_cfi %eax
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index fe2690d71c0c..e3ba417e8697 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -295,6 +295,7 @@ ENDPROC(native_usergs_sysret64)
295 .endm 295 .endm
296 296
297/* save partial stack frame */ 297/* save partial stack frame */
298 .pushsection .kprobes.text, "ax"
298ENTRY(save_args) 299ENTRY(save_args)
299 XCPT_FRAME 300 XCPT_FRAME
300 cld 301 cld
@@ -334,6 +335,7 @@ ENTRY(save_args)
334 ret 335 ret
335 CFI_ENDPROC 336 CFI_ENDPROC
336END(save_args) 337END(save_args)
338 .popsection
337 339
338ENTRY(save_rest) 340ENTRY(save_rest)
339 PARTIAL_FRAME 1 REST_SKIP+8 341 PARTIAL_FRAME 1 REST_SKIP+8
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 8e09aa3aa6d6..01c3d455e576 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -60,16 +60,18 @@
60#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD) 60#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
61#endif 61#endif
62 62
63/* Number of possible pages in the lowmem region */
64LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
65
63/* Enough space to fit pagetables for the low memory linear map */ 66/* Enough space to fit pagetables for the low memory linear map */
64MAPPING_BEYOND_END = \ 67MAPPING_BEYOND_END = PAGE_TABLE_SIZE(LOWMEM_PAGES) << PAGE_SHIFT
65 PAGE_TABLE_SIZE(((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT) << PAGE_SHIFT
66 68
67/* 69/*
68 * Worst-case size of the kernel mapping we need to make: 70 * Worst-case size of the kernel mapping we need to make:
69 * the worst-case size of the kernel itself, plus the extra we need 71 * a relocatable kernel can live anywhere in lowmem, so we need to be able
70 * to map for the linear map. 72 * to map all of lowmem.
71 */ 73 */
72KERNEL_PAGES = (KERNEL_IMAGE_SIZE + MAPPING_BEYOND_END)>>PAGE_SHIFT 74KERNEL_PAGES = LOWMEM_PAGES
73 75
74INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE_asm 76INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE_asm
75RESERVE_BRK(pagetables, INIT_MAP_SIZE) 77RESERVE_BRK(pagetables, INIT_MAP_SIZE)
@@ -620,13 +622,13 @@ ENTRY(initial_code)
620__PAGE_ALIGNED_BSS 622__PAGE_ALIGNED_BSS
621 .align PAGE_SIZE_asm 623 .align PAGE_SIZE_asm
622#ifdef CONFIG_X86_PAE 624#ifdef CONFIG_X86_PAE
623initial_pg_pmd: 625ENTRY(initial_pg_pmd)
624 .fill 1024*KPMDS,4,0 626 .fill 1024*KPMDS,4,0
625#else 627#else
626ENTRY(initial_page_table) 628ENTRY(initial_page_table)
627 .fill 1024,4,0 629 .fill 1024,4,0
628#endif 630#endif
629initial_pg_fixmap: 631ENTRY(initial_pg_fixmap)
630 .fill 1024,4,0 632 .fill 1024,4,0
631ENTRY(empty_zero_page) 633ENTRY(empty_zero_page)
632 .fill 4096,1,0 634 .fill 4096,1,0
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index ae03cab4352e..4ff5968f12d2 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -27,6 +27,9 @@
27#define HPET_DEV_FSB_CAP 0x1000 27#define HPET_DEV_FSB_CAP 0x1000
28#define HPET_DEV_PERI_CAP 0x2000 28#define HPET_DEV_PERI_CAP 0x2000
29 29
30#define HPET_MIN_CYCLES 128
31#define HPET_MIN_PROG_DELTA (HPET_MIN_CYCLES + (HPET_MIN_CYCLES >> 1))
32
30#define EVT_TO_HPET_DEV(evt) container_of(evt, struct hpet_dev, evt) 33#define EVT_TO_HPET_DEV(evt) container_of(evt, struct hpet_dev, evt)
31 34
32/* 35/*
@@ -299,8 +302,9 @@ static void hpet_legacy_clockevent_register(void)
299 /* Calculate the min / max delta */ 302 /* Calculate the min / max delta */
300 hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFFFFFF, 303 hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFFFFFF,
301 &hpet_clockevent); 304 &hpet_clockevent);
302 /* 5 usec minimum reprogramming delta. */ 305 /* Setup minimum reprogramming delta. */
303 hpet_clockevent.min_delta_ns = 5000; 306 hpet_clockevent.min_delta_ns = clockevent_delta2ns(HPET_MIN_PROG_DELTA,
307 &hpet_clockevent);
304 308
305 /* 309 /*
306 * Start hpet with the boot cpu mask and make it 310 * Start hpet with the boot cpu mask and make it
@@ -393,22 +397,24 @@ static int hpet_next_event(unsigned long delta,
393 * the wraparound into account) nor a simple count down event 397 * the wraparound into account) nor a simple count down event
394 * mode. Further the write to the comparator register is 398 * mode. Further the write to the comparator register is
395 * delayed internally up to two HPET clock cycles in certain 399 * delayed internally up to two HPET clock cycles in certain
396 * chipsets (ATI, ICH9,10). We worked around that by reading 400 * chipsets (ATI, ICH9,10). Some newer AMD chipsets have even
397 * back the compare register, but that required another 401 * longer delays. We worked around that by reading back the
398 * workaround for ICH9,10 chips where the first readout after 402 * compare register, but that required another workaround for
399 * write can return the old stale value. We already have a 403 * ICH9,10 chips where the first readout after write can
400 * minimum delta of 5us enforced, but a NMI or SMI hitting 404 * return the old stale value. We already had a minimum
405 * programming delta of 5us enforced, but a NMI or SMI hitting
401 * between the counter readout and the comparator write can 406 * between the counter readout and the comparator write can
402 * move us behind that point easily. Now instead of reading 407 * move us behind that point easily. Now instead of reading
403 * the compare register back several times, we make the ETIME 408 * the compare register back several times, we make the ETIME
404 * decision based on the following: Return ETIME if the 409 * decision based on the following: Return ETIME if the
405 * counter value after the write is less than 8 HPET cycles 410 * counter value after the write is less than HPET_MIN_CYCLES
406 * away from the event or if the counter is already ahead of 411 * away from the event or if the counter is already ahead of
407 * the event. 412 * the event. The minimum programming delta for the generic
413 * clockevents code is set to 1.5 * HPET_MIN_CYCLES.
408 */ 414 */
409 res = (s32)(cnt - hpet_readl(HPET_COUNTER)); 415 res = (s32)(cnt - hpet_readl(HPET_COUNTER));
410 416
411 return res < 8 ? -ETIME : 0; 417 return res < HPET_MIN_CYCLES ? -ETIME : 0;
412} 418}
413 419
414static void hpet_legacy_set_mode(enum clock_event_mode mode, 420static void hpet_legacy_set_mode(enum clock_event_mode mode,
diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
index ff15c9dcc25d..42c594254507 100644
--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -433,6 +433,10 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args)
433 dr6_p = (unsigned long *)ERR_PTR(args->err); 433 dr6_p = (unsigned long *)ERR_PTR(args->err);
434 dr6 = *dr6_p; 434 dr6 = *dr6_p;
435 435
436 /* If it's a single step, TRAP bits are random */
437 if (dr6 & DR_STEP)
438 return NOTIFY_DONE;
439
436 /* Do an early return if no trap bits are set in DR6 */ 440 /* Do an early return if no trap bits are set in DR6 */
437 if ((dr6 & DR_TRAP_BITS) == 0) 441 if ((dr6 & DR_TRAP_BITS) == 0)
438 return NOTIFY_DONE; 442 return NOTIFY_DONE;
diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
index ec592caac4b4..cd21b654dec6 100644
--- a/arch/x86/kernel/kgdb.c
+++ b/arch/x86/kernel/kgdb.c
@@ -315,14 +315,18 @@ static void kgdb_remove_all_hw_break(void)
315 if (!breakinfo[i].enabled) 315 if (!breakinfo[i].enabled)
316 continue; 316 continue;
317 bp = *per_cpu_ptr(breakinfo[i].pev, cpu); 317 bp = *per_cpu_ptr(breakinfo[i].pev, cpu);
318 if (bp->attr.disabled == 1) 318 if (!bp->attr.disabled) {
319 arch_uninstall_hw_breakpoint(bp);
320 bp->attr.disabled = 1;
319 continue; 321 continue;
322 }
320 if (dbg_is_early) 323 if (dbg_is_early)
321 early_dr7 &= ~encode_dr7(i, breakinfo[i].len, 324 early_dr7 &= ~encode_dr7(i, breakinfo[i].len,
322 breakinfo[i].type); 325 breakinfo[i].type);
323 else 326 else if (hw_break_release_slot(i))
324 arch_uninstall_hw_breakpoint(bp); 327 printk(KERN_ERR "KGDB: hw bpt remove failed %lx\n",
325 bp->attr.disabled = 1; 328 breakinfo[i].addr);
329 breakinfo[i].enabled = 0;
326 } 330 }
327} 331}
328 332
diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index e1af7c055c7d..ce0cb4721c9a 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -212,7 +212,7 @@ static int install_equiv_cpu_table(const u8 *buf)
212 return 0; 212 return 0;
213 } 213 }
214 214
215 equiv_cpu_table = (struct equiv_cpu_entry *) vmalloc(size); 215 equiv_cpu_table = vmalloc(size);
216 if (!equiv_cpu_table) { 216 if (!equiv_cpu_table) {
217 pr_err("failed to allocate equivalent CPU table\n"); 217 pr_err("failed to allocate equivalent CPU table\n");
218 return 0; 218 return 0;
diff --git a/arch/x86/kernel/mmconf-fam10h_64.c b/arch/x86/kernel/mmconf-fam10h_64.c
index 71825806cd44..ac861b8348e2 100644
--- a/arch/x86/kernel/mmconf-fam10h_64.c
+++ b/arch/x86/kernel/mmconf-fam10h_64.c
@@ -25,7 +25,6 @@ struct pci_hostbridge_probe {
25}; 25};
26 26
27static u64 __cpuinitdata fam10h_pci_mmconf_base; 27static u64 __cpuinitdata fam10h_pci_mmconf_base;
28static int __cpuinitdata fam10h_pci_mmconf_base_status;
29 28
30static struct pci_hostbridge_probe pci_probes[] __cpuinitdata = { 29static struct pci_hostbridge_probe pci_probes[] __cpuinitdata = {
31 { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1200 }, 30 { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1200 },
@@ -44,10 +43,12 @@ static int __cpuinit cmp_range(const void *x1, const void *x2)
44 return start1 - start2; 43 return start1 - start2;
45} 44}
46 45
47/*[47:0] */ 46#define MMCONF_UNIT (1ULL << FAM10H_MMIO_CONF_BASE_SHIFT)
48/* need to avoid (0xfd<<32) and (0xfe<<32), ht used space */ 47#define MMCONF_MASK (~(MMCONF_UNIT - 1))
48#define MMCONF_SIZE (MMCONF_UNIT << 8)
49/* need to avoid (0xfd<<32), (0xfe<<32), and (0xff<<32), ht used space */
49#define FAM10H_PCI_MMCONF_BASE (0xfcULL<<32) 50#define FAM10H_PCI_MMCONF_BASE (0xfcULL<<32)
50#define BASE_VALID(b) ((b != (0xfdULL << 32)) && (b != (0xfeULL << 32))) 51#define BASE_VALID(b) ((b) + MMCONF_SIZE <= (0xfdULL<<32) || (b) >= (1ULL<<40))
51static void __cpuinit get_fam10h_pci_mmconf_base(void) 52static void __cpuinit get_fam10h_pci_mmconf_base(void)
52{ 53{
53 int i; 54 int i;
@@ -64,12 +65,11 @@ static void __cpuinit get_fam10h_pci_mmconf_base(void)
64 struct range range[8]; 65 struct range range[8];
65 66
66 /* only try to get setting from BSP */ 67 /* only try to get setting from BSP */
67 /* -1 or 1 */ 68 if (fam10h_pci_mmconf_base)
68 if (fam10h_pci_mmconf_base_status)
69 return; 69 return;
70 70
71 if (!early_pci_allowed()) 71 if (!early_pci_allowed())
72 goto fail; 72 return;
73 73
74 found = 0; 74 found = 0;
75 for (i = 0; i < ARRAY_SIZE(pci_probes); i++) { 75 for (i = 0; i < ARRAY_SIZE(pci_probes); i++) {
@@ -91,7 +91,7 @@ static void __cpuinit get_fam10h_pci_mmconf_base(void)
91 } 91 }
92 92
93 if (!found) 93 if (!found)
94 goto fail; 94 return;
95 95
96 /* SYS_CFG */ 96 /* SYS_CFG */
97 address = MSR_K8_SYSCFG; 97 address = MSR_K8_SYSCFG;
@@ -99,16 +99,16 @@ static void __cpuinit get_fam10h_pci_mmconf_base(void)
99 99
100 /* TOP_MEM2 is not enabled? */ 100 /* TOP_MEM2 is not enabled? */
101 if (!(val & (1<<21))) { 101 if (!(val & (1<<21))) {
102 tom2 = 0; 102 tom2 = 1ULL << 32;
103 } else { 103 } else {
104 /* TOP_MEM2 */ 104 /* TOP_MEM2 */
105 address = MSR_K8_TOP_MEM2; 105 address = MSR_K8_TOP_MEM2;
106 rdmsrl(address, val); 106 rdmsrl(address, val);
107 tom2 = val & (0xffffULL<<32); 107 tom2 = max(val & 0xffffff800000ULL, 1ULL << 32);
108 } 108 }
109 109
110 if (base <= tom2) 110 if (base <= tom2)
111 base = tom2 + (1ULL<<32); 111 base = (tom2 + 2 * MMCONF_UNIT - 1) & MMCONF_MASK;
112 112
113 /* 113 /*
114 * need to check if the range is in the high mmio range that is 114 * need to check if the range is in the high mmio range that is
@@ -123,11 +123,11 @@ static void __cpuinit get_fam10h_pci_mmconf_base(void)
123 if (!(reg & 3)) 123 if (!(reg & 3))
124 continue; 124 continue;
125 125
126 start = (((u64)reg) << 8) & (0xffULL << 32); /* 39:16 on 31:8*/ 126 start = (u64)(reg & 0xffffff00) << 8; /* 39:16 on 31:8*/
127 reg = read_pci_config(bus, slot, 1, 0x84 + (i << 3)); 127 reg = read_pci_config(bus, slot, 1, 0x84 + (i << 3));
128 end = (((u64)reg) << 8) & (0xffULL << 32); /* 39:16 on 31:8*/ 128 end = ((u64)(reg & 0xffffff00) << 8) | 0xffff; /* 39:16 on 31:8*/
129 129
130 if (!end) 130 if (end < tom2)
131 continue; 131 continue;
132 132
133 range[hi_mmio_num].start = start; 133 range[hi_mmio_num].start = start;
@@ -143,32 +143,27 @@ static void __cpuinit get_fam10h_pci_mmconf_base(void)
143 143
144 if (range[hi_mmio_num - 1].end < base) 144 if (range[hi_mmio_num - 1].end < base)
145 goto out; 145 goto out;
146 if (range[0].start > base) 146 if (range[0].start > base + MMCONF_SIZE)
147 goto out; 147 goto out;
148 148
149 /* need to find one window */ 149 /* need to find one window */
150 base = range[0].start - (1ULL << 32); 150 base = (range[0].start & MMCONF_MASK) - MMCONF_UNIT;
151 if ((base > tom2) && BASE_VALID(base)) 151 if ((base > tom2) && BASE_VALID(base))
152 goto out; 152 goto out;
153 base = range[hi_mmio_num - 1].end + (1ULL << 32); 153 base = (range[hi_mmio_num - 1].end + MMCONF_UNIT) & MMCONF_MASK;
154 if ((base > tom2) && BASE_VALID(base)) 154 if (BASE_VALID(base))
155 goto out; 155 goto out;
156 /* need to find window between ranges */ 156 /* need to find window between ranges */
157 if (hi_mmio_num > 1) 157 for (i = 1; i < hi_mmio_num; i++) {
158 for (i = 0; i < hi_mmio_num - 1; i++) { 158 base = (range[i - 1].end + MMCONF_UNIT) & MMCONF_MASK;
159 if (range[i + 1].start > (range[i].end + (1ULL << 32))) { 159 val = range[i].start & MMCONF_MASK;
160 base = range[i].end + (1ULL << 32); 160 if (val >= base + MMCONF_SIZE && BASE_VALID(base))
161 if ((base > tom2) && BASE_VALID(base)) 161 goto out;
162 goto out;
163 }
164 } 162 }
165
166fail:
167 fam10h_pci_mmconf_base_status = -1;
168 return; 163 return;
164
169out: 165out:
170 fam10h_pci_mmconf_base = base; 166 fam10h_pci_mmconf_base = base;
171 fam10h_pci_mmconf_base_status = 1;
172} 167}
173 168
174void __cpuinit fam10h_check_enable_mmcfg(void) 169void __cpuinit fam10h_check_enable_mmcfg(void)
@@ -190,11 +185,10 @@ void __cpuinit fam10h_check_enable_mmcfg(void)
190 185
191 /* only trust the one handle 256 buses, if acpi=off */ 186 /* only trust the one handle 256 buses, if acpi=off */
192 if (!acpi_pci_disabled || busnbits >= 8) { 187 if (!acpi_pci_disabled || busnbits >= 8) {
193 u64 base; 188 u64 base = val & MMCONF_MASK;
194 base = val & (0xffffULL << 32); 189
195 if (fam10h_pci_mmconf_base_status <= 0) { 190 if (!fam10h_pci_mmconf_base) {
196 fam10h_pci_mmconf_base = base; 191 fam10h_pci_mmconf_base = base;
197 fam10h_pci_mmconf_base_status = 1;
198 return; 192 return;
199 } else if (fam10h_pci_mmconf_base == base) 193 } else if (fam10h_pci_mmconf_base == base)
200 return; 194 return;
@@ -206,8 +200,10 @@ void __cpuinit fam10h_check_enable_mmcfg(void)
206 * with 256 buses 200 * with 256 buses
207 */ 201 */
208 get_fam10h_pci_mmconf_base(); 202 get_fam10h_pci_mmconf_base();
209 if (fam10h_pci_mmconf_base_status <= 0) 203 if (!fam10h_pci_mmconf_base) {
204 pci_probe &= ~PCI_CHECK_ENABLE_AMD_MMCONF;
210 return; 205 return;
206 }
211 207
212 printk(KERN_INFO "Enable MMCONFIG on AMD Family 10h\n"); 208 printk(KERN_INFO "Enable MMCONFIG on AMD Family 10h\n");
213 val &= ~((FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT) | 209 val &= ~((FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT) |
@@ -217,13 +213,13 @@ void __cpuinit fam10h_check_enable_mmcfg(void)
217 wrmsrl(address, val); 213 wrmsrl(address, val);
218} 214}
219 215
220static int __devinit set_check_enable_amd_mmconf(const struct dmi_system_id *d) 216static int __init set_check_enable_amd_mmconf(const struct dmi_system_id *d)
221{ 217{
222 pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF; 218 pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
223 return 0; 219 return 0;
224} 220}
225 221
226static const struct dmi_system_id __cpuinitconst mmconf_dmi_table[] = { 222static const struct dmi_system_id __initconst mmconf_dmi_table[] = {
227 { 223 {
228 .callback = set_check_enable_amd_mmconf, 224 .callback = set_check_enable_amd_mmconf,
229 .ident = "Sun Microsystems Machine", 225 .ident = "Sun Microsystems Machine",
@@ -234,7 +230,8 @@ static const struct dmi_system_id __cpuinitconst mmconf_dmi_table[] = {
234 {} 230 {}
235}; 231};
236 232
237void __cpuinit check_enable_amd_mmconf_dmi(void) 233/* Called from a __cpuinit function, but only on the BSP. */
234void __ref check_enable_amd_mmconf_dmi(void)
238{ 235{
239 dmi_check_system(mmconf_dmi_table); 236 dmi_check_system(mmconf_dmi_table);
240} 237}
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index 7bf2dc4c8f70..12fcbe2c143e 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -30,7 +30,6 @@
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/poll.h> 31#include <linux/poll.h>
32#include <linux/smp.h> 32#include <linux/smp.h>
33#include <linux/smp_lock.h>
34#include <linux/major.h> 33#include <linux/major.h>
35#include <linux/fs.h> 34#include <linux/fs.h>
36#include <linux/device.h> 35#include <linux/device.h>
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index bab3b9e6f66d..42eb3300dfc6 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -41,44 +41,6 @@ void pvclock_set_flags(u8 flags)
41 valid_flags = flags; 41 valid_flags = flags;
42} 42}
43 43
44/*
45 * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
46 * yielding a 64-bit result.
47 */
48static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift)
49{
50 u64 product;
51#ifdef __i386__
52 u32 tmp1, tmp2;
53#endif
54
55 if (shift < 0)
56 delta >>= -shift;
57 else
58 delta <<= shift;
59
60#ifdef __i386__
61 __asm__ (
62 "mul %5 ; "
63 "mov %4,%%eax ; "
64 "mov %%edx,%4 ; "
65 "mul %5 ; "
66 "xor %5,%5 ; "
67 "add %4,%%eax ; "
68 "adc %5,%%edx ; "
69 : "=A" (product), "=r" (tmp1), "=r" (tmp2)
70 : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
71#elif defined(__x86_64__)
72 __asm__ (
73 "mul %%rdx ; shrd $32,%%rdx,%%rax"
74 : "=a" (product) : "0" (delta), "d" ((u64)mul_frac) );
75#else
76#error implement me!
77#endif
78
79 return product;
80}
81
82static u64 pvclock_get_nsec_offset(struct pvclock_shadow_time *shadow) 44static u64 pvclock_get_nsec_offset(struct pvclock_shadow_time *shadow)
83{ 45{
84 u64 delta = native_read_tsc() - shadow->tsc_timestamp; 46 u64 delta = native_read_tsc() - shadow->tsc_timestamp;
@@ -121,6 +83,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
121 83
122static atomic64_t last_value = ATOMIC64_INIT(0); 84static atomic64_t last_value = ATOMIC64_INIT(0);
123 85
86void pvclock_resume(void)
87{
88 atomic64_set(&last_value, 0);
89}
90
124cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src) 91cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
125{ 92{
126 struct pvclock_shadow_time shadow; 93 struct pvclock_shadow_time shadow;
diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c
new file mode 100644
index 000000000000..2a26819bb6a8
--- /dev/null
+++ b/arch/x86/kernel/resource.c
@@ -0,0 +1,48 @@
1#include <linux/ioport.h>
2#include <asm/e820.h>
3
4static void resource_clip(struct resource *res, resource_size_t start,
5 resource_size_t end)
6{
7 resource_size_t low = 0, high = 0;
8
9 if (res->end < start || res->start > end)
10 return; /* no conflict */
11
12 if (res->start < start)
13 low = start - res->start;
14
15 if (res->end > end)
16 high = res->end - end;
17
18 /* Keep the area above or below the conflict, whichever is larger */
19 if (low > high)
20 res->end = start - 1;
21 else
22 res->start = end + 1;
23}
24
25static void remove_e820_regions(struct resource *avail)
26{
27 int i;
28 struct e820entry *entry;
29
30 for (i = 0; i < e820.nr_map; i++) {
31 entry = &e820.map[i];
32
33 resource_clip(avail, entry->addr,
34 entry->addr + entry->size - 1);
35 }
36}
37
38void arch_remove_reservations(struct resource *avail)
39{
40 /* Trim out BIOS areas (low 1MB and high 2MB) and E820 regions */
41 if (avail->flags & IORESOURCE_MEM) {
42 if (avail->start < BIOS_END)
43 avail->start = BIOS_END;
44 resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END);
45
46 remove_e820_regions(avail);
47 }
48}
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 21c6746338af..85268f8eadf6 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -769,7 +769,6 @@ void __init setup_arch(char **cmdline_p)
769 769
770 x86_init.oem.arch_setup(); 770 x86_init.oem.arch_setup();
771 771
772 resource_alloc_from_bottom = 0;
773 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 772 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
774 setup_memory_map(); 773 setup_memory_map();
775 parse_setup_data(); 774 parse_setup_data();
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
index 9c253bd65e24..547128546cc3 100644
--- a/arch/x86/kernel/xsave.c
+++ b/arch/x86/kernel/xsave.c
@@ -394,7 +394,8 @@ static void __init setup_xstate_init(void)
394 * Setup init_xstate_buf to represent the init state of 394 * Setup init_xstate_buf to represent the init state of
395 * all the features managed by the xsave 395 * all the features managed by the xsave
396 */ 396 */
397 init_xstate_buf = alloc_bootmem(xstate_size); 397 init_xstate_buf = alloc_bootmem_align(xstate_size,
398 __alignof__(struct xsave_struct));
398 init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT; 399 init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;
399 400
400 clts(); 401 clts();
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 908ea5464a51..fb8b376bf28c 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -720,7 +720,7 @@ static void rmap_remove(struct kvm *kvm, u64 *spte)
720 } 720 }
721} 721}
722 722
723static void set_spte_track_bits(u64 *sptep, u64 new_spte) 723static int set_spte_track_bits(u64 *sptep, u64 new_spte)
724{ 724{
725 pfn_t pfn; 725 pfn_t pfn;
726 u64 old_spte = *sptep; 726 u64 old_spte = *sptep;
@@ -731,19 +731,20 @@ static void set_spte_track_bits(u64 *sptep, u64 new_spte)
731 old_spte = __xchg_spte(sptep, new_spte); 731 old_spte = __xchg_spte(sptep, new_spte);
732 732
733 if (!is_rmap_spte(old_spte)) 733 if (!is_rmap_spte(old_spte))
734 return; 734 return 0;
735 735
736 pfn = spte_to_pfn(old_spte); 736 pfn = spte_to_pfn(old_spte);
737 if (!shadow_accessed_mask || old_spte & shadow_accessed_mask) 737 if (!shadow_accessed_mask || old_spte & shadow_accessed_mask)
738 kvm_set_pfn_accessed(pfn); 738 kvm_set_pfn_accessed(pfn);
739 if (!shadow_dirty_mask || (old_spte & shadow_dirty_mask)) 739 if (!shadow_dirty_mask || (old_spte & shadow_dirty_mask))
740 kvm_set_pfn_dirty(pfn); 740 kvm_set_pfn_dirty(pfn);
741 return 1;
741} 742}
742 743
743static void drop_spte(struct kvm *kvm, u64 *sptep, u64 new_spte) 744static void drop_spte(struct kvm *kvm, u64 *sptep, u64 new_spte)
744{ 745{
745 set_spte_track_bits(sptep, new_spte); 746 if (set_spte_track_bits(sptep, new_spte))
746 rmap_remove(kvm, sptep); 747 rmap_remove(kvm, sptep);
747} 748}
748 749
749static u64 *rmap_next(struct kvm *kvm, unsigned long *rmapp, u64 *spte) 750static u64 *rmap_next(struct kvm *kvm, unsigned long *rmapp, u64 *spte)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 82e144a4e514..b81a9b7c2ca4 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -3395,6 +3395,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
3395 vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip; 3395 vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip;
3396 3396
3397 load_host_msrs(vcpu); 3397 load_host_msrs(vcpu);
3398 kvm_load_ldt(ldt_selector);
3398 loadsegment(fs, fs_selector); 3399 loadsegment(fs, fs_selector);
3399#ifdef CONFIG_X86_64 3400#ifdef CONFIG_X86_64
3400 load_gs_index(gs_selector); 3401 load_gs_index(gs_selector);
@@ -3402,7 +3403,6 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
3402#else 3403#else
3403 loadsegment(gs, gs_selector); 3404 loadsegment(gs, gs_selector);
3404#endif 3405#endif
3405 kvm_load_ldt(ldt_selector);
3406 3406
3407 reload_tss(vcpu); 3407 reload_tss(vcpu);
3408 3408
@@ -3494,6 +3494,10 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu)
3494static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry) 3494static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
3495{ 3495{
3496 switch (func) { 3496 switch (func) {
3497 case 0x00000001:
3498 /* Mask out xsave bit as long as it is not supported by SVM */
3499 entry->ecx &= ~(bit(X86_FEATURE_XSAVE));
3500 break;
3497 case 0x80000001: 3501 case 0x80000001:
3498 if (nested) 3502 if (nested)
3499 entry->ecx |= (1 << 2); /* Set SVM bit */ 3503 entry->ecx |= (1 << 2); /* Set SVM bit */
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 8da0e45ff7c9..81fcbe9515c5 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -821,10 +821,9 @@ static void vmx_save_host_state(struct kvm_vcpu *vcpu)
821#endif 821#endif
822 822
823#ifdef CONFIG_X86_64 823#ifdef CONFIG_X86_64
824 if (is_long_mode(&vmx->vcpu)) { 824 rdmsrl(MSR_KERNEL_GS_BASE, vmx->msr_host_kernel_gs_base);
825 rdmsrl(MSR_KERNEL_GS_BASE, vmx->msr_host_kernel_gs_base); 825 if (is_long_mode(&vmx->vcpu))
826 wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base); 826 wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base);
827 }
828#endif 827#endif
829 for (i = 0; i < vmx->save_nmsrs; ++i) 828 for (i = 0; i < vmx->save_nmsrs; ++i)
830 kvm_set_shared_msr(vmx->guest_msrs[i].index, 829 kvm_set_shared_msr(vmx->guest_msrs[i].index,
@@ -839,23 +838,23 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)
839 838
840 ++vmx->vcpu.stat.host_state_reload; 839 ++vmx->vcpu.stat.host_state_reload;
841 vmx->host_state.loaded = 0; 840 vmx->host_state.loaded = 0;
842 if (vmx->host_state.fs_reload_needed) 841#ifdef CONFIG_X86_64
843 loadsegment(fs, vmx->host_state.fs_sel); 842 if (is_long_mode(&vmx->vcpu))
843 rdmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base);
844#endif
844 if (vmx->host_state.gs_ldt_reload_needed) { 845 if (vmx->host_state.gs_ldt_reload_needed) {
845 kvm_load_ldt(vmx->host_state.ldt_sel); 846 kvm_load_ldt(vmx->host_state.ldt_sel);
846#ifdef CONFIG_X86_64 847#ifdef CONFIG_X86_64
847 load_gs_index(vmx->host_state.gs_sel); 848 load_gs_index(vmx->host_state.gs_sel);
848 wrmsrl(MSR_KERNEL_GS_BASE, current->thread.gs);
849#else 849#else
850 loadsegment(gs, vmx->host_state.gs_sel); 850 loadsegment(gs, vmx->host_state.gs_sel);
851#endif 851#endif
852 } 852 }
853 if (vmx->host_state.fs_reload_needed)
854 loadsegment(fs, vmx->host_state.fs_sel);
853 reload_tss(); 855 reload_tss();
854#ifdef CONFIG_X86_64 856#ifdef CONFIG_X86_64
855 if (is_long_mode(&vmx->vcpu)) { 857 wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_host_kernel_gs_base);
856 rdmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base);
857 wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_host_kernel_gs_base);
858 }
859#endif 858#endif
860 if (current_thread_info()->status & TS_USEDFPU) 859 if (current_thread_info()->status & TS_USEDFPU)
861 clts(); 860 clts();
@@ -4228,11 +4227,6 @@ static int vmx_get_lpage_level(void)
4228 return PT_PDPE_LEVEL; 4227 return PT_PDPE_LEVEL;
4229} 4228}
4230 4229
4231static inline u32 bit(int bitno)
4232{
4233 return 1 << (bitno & 31);
4234}
4235
4236static void vmx_cpuid_update(struct kvm_vcpu *vcpu) 4230static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
4237{ 4231{
4238 struct kvm_cpuid_entry2 *best; 4232 struct kvm_cpuid_entry2 *best;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2288ad829b32..b989e1f1e5d3 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -155,11 +155,6 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
155 155
156u64 __read_mostly host_xcr0; 156u64 __read_mostly host_xcr0;
157 157
158static inline u32 bit(int bitno)
159{
160 return 1 << (bitno & 31);
161}
162
163static void kvm_on_user_return(struct user_return_notifier *urn) 158static void kvm_on_user_return(struct user_return_notifier *urn)
164{ 159{
165 unsigned slot; 160 unsigned slot;
@@ -2560,6 +2555,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
2560 !kvm_exception_is_soft(vcpu->arch.exception.nr); 2555 !kvm_exception_is_soft(vcpu->arch.exception.nr);
2561 events->exception.nr = vcpu->arch.exception.nr; 2556 events->exception.nr = vcpu->arch.exception.nr;
2562 events->exception.has_error_code = vcpu->arch.exception.has_error_code; 2557 events->exception.has_error_code = vcpu->arch.exception.has_error_code;
2558 events->exception.pad = 0;
2563 events->exception.error_code = vcpu->arch.exception.error_code; 2559 events->exception.error_code = vcpu->arch.exception.error_code;
2564 2560
2565 events->interrupt.injected = 2561 events->interrupt.injected =
@@ -2573,12 +2569,14 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
2573 events->nmi.injected = vcpu->arch.nmi_injected; 2569 events->nmi.injected = vcpu->arch.nmi_injected;
2574 events->nmi.pending = vcpu->arch.nmi_pending; 2570 events->nmi.pending = vcpu->arch.nmi_pending;
2575 events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu); 2571 events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu);
2572 events->nmi.pad = 0;
2576 2573
2577 events->sipi_vector = vcpu->arch.sipi_vector; 2574 events->sipi_vector = vcpu->arch.sipi_vector;
2578 2575
2579 events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING 2576 events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING
2580 | KVM_VCPUEVENT_VALID_SIPI_VECTOR 2577 | KVM_VCPUEVENT_VALID_SIPI_VECTOR
2581 | KVM_VCPUEVENT_VALID_SHADOW); 2578 | KVM_VCPUEVENT_VALID_SHADOW);
2579 memset(&events->reserved, 0, sizeof(events->reserved));
2582} 2580}
2583 2581
2584static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, 2582static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
@@ -2623,6 +2621,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
2623 dbgregs->dr6 = vcpu->arch.dr6; 2621 dbgregs->dr6 = vcpu->arch.dr6;
2624 dbgregs->dr7 = vcpu->arch.dr7; 2622 dbgregs->dr7 = vcpu->arch.dr7;
2625 dbgregs->flags = 0; 2623 dbgregs->flags = 0;
2624 memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
2626} 2625}
2627 2626
2628static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu, 2627static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu,
@@ -3106,6 +3105,7 @@ static int kvm_vm_ioctl_get_pit2(struct kvm *kvm, struct kvm_pit_state2 *ps)
3106 sizeof(ps->channels)); 3105 sizeof(ps->channels));
3107 ps->flags = kvm->arch.vpit->pit_state.flags; 3106 ps->flags = kvm->arch.vpit->pit_state.flags;
3108 mutex_unlock(&kvm->arch.vpit->pit_state.lock); 3107 mutex_unlock(&kvm->arch.vpit->pit_state.lock);
3108 memset(&ps->reserved, 0, sizeof(ps->reserved));
3109 return r; 3109 return r;
3110} 3110}
3111 3111
@@ -3169,10 +3169,6 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3169 struct kvm_memslots *slots, *old_slots; 3169 struct kvm_memslots *slots, *old_slots;
3170 unsigned long *dirty_bitmap; 3170 unsigned long *dirty_bitmap;
3171 3171
3172 spin_lock(&kvm->mmu_lock);
3173 kvm_mmu_slot_remove_write_access(kvm, log->slot);
3174 spin_unlock(&kvm->mmu_lock);
3175
3176 r = -ENOMEM; 3172 r = -ENOMEM;
3177 dirty_bitmap = vmalloc(n); 3173 dirty_bitmap = vmalloc(n);
3178 if (!dirty_bitmap) 3174 if (!dirty_bitmap)
@@ -3194,6 +3190,10 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3194 dirty_bitmap = old_slots->memslots[log->slot].dirty_bitmap; 3190 dirty_bitmap = old_slots->memslots[log->slot].dirty_bitmap;
3195 kfree(old_slots); 3191 kfree(old_slots);
3196 3192
3193 spin_lock(&kvm->mmu_lock);
3194 kvm_mmu_slot_remove_write_access(kvm, log->slot);
3195 spin_unlock(&kvm->mmu_lock);
3196
3197 r = -EFAULT; 3197 r = -EFAULT;
3198 if (copy_to_user(log->dirty_bitmap, dirty_bitmap, n)) { 3198 if (copy_to_user(log->dirty_bitmap, dirty_bitmap, n)) {
3199 vfree(dirty_bitmap); 3199 vfree(dirty_bitmap);
@@ -3486,6 +3486,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
3486 user_ns.clock = kvm->arch.kvmclock_offset + now_ns; 3486 user_ns.clock = kvm->arch.kvmclock_offset + now_ns;
3487 local_irq_enable(); 3487 local_irq_enable();
3488 user_ns.flags = 0; 3488 user_ns.flags = 0;
3489 memset(&user_ns.pad, 0, sizeof(user_ns.pad));
3489 3490
3490 r = -EFAULT; 3491 r = -EFAULT;
3491 if (copy_to_user(argp, &user_ns, sizeof(user_ns))) 3492 if (copy_to_user(argp, &user_ns, sizeof(user_ns)))
@@ -3972,8 +3973,10 @@ int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu)
3972 return X86EMUL_CONTINUE; 3973 return X86EMUL_CONTINUE;
3973 3974
3974 if (kvm_x86_ops->has_wbinvd_exit()) { 3975 if (kvm_x86_ops->has_wbinvd_exit()) {
3976 preempt_disable();
3975 smp_call_function_many(vcpu->arch.wbinvd_dirty_mask, 3977 smp_call_function_many(vcpu->arch.wbinvd_dirty_mask,
3976 wbinvd_ipi, NULL, 1); 3978 wbinvd_ipi, NULL, 1);
3979 preempt_enable();
3977 cpumask_clear(vcpu->arch.wbinvd_dirty_mask); 3980 cpumask_clear(vcpu->arch.wbinvd_dirty_mask);
3978 } 3981 }
3979 wbinvd(); 3982 wbinvd();
@@ -4561,9 +4564,11 @@ static void kvm_timer_init(void)
4561#ifdef CONFIG_CPU_FREQ 4564#ifdef CONFIG_CPU_FREQ
4562 struct cpufreq_policy policy; 4565 struct cpufreq_policy policy;
4563 memset(&policy, 0, sizeof(policy)); 4566 memset(&policy, 0, sizeof(policy));
4564 cpufreq_get_policy(&policy, get_cpu()); 4567 cpu = get_cpu();
4568 cpufreq_get_policy(&policy, cpu);
4565 if (policy.cpuinfo.max_freq) 4569 if (policy.cpuinfo.max_freq)
4566 max_tsc_khz = policy.cpuinfo.max_freq; 4570 max_tsc_khz = policy.cpuinfo.max_freq;
4571 put_cpu();
4567#endif 4572#endif
4568 cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block, 4573 cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block,
4569 CPUFREQ_TRANSITION_NOTIFIER); 4574 CPUFREQ_TRANSITION_NOTIFIER);
@@ -5514,6 +5519,8 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
5514 5519
5515 mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4; 5520 mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4;
5516 kvm_x86_ops->set_cr4(vcpu, sregs->cr4); 5521 kvm_x86_ops->set_cr4(vcpu, sregs->cr4);
5522 if (sregs->cr4 & X86_CR4_OSXSAVE)
5523 update_cpuid(vcpu);
5517 if (!is_long_mode(vcpu) && is_pae(vcpu)) { 5524 if (!is_long_mode(vcpu) && is_pae(vcpu)) {
5518 load_pdptrs(vcpu, vcpu->arch.walk_mmu, vcpu->arch.cr3); 5525 load_pdptrs(vcpu, vcpu->arch.walk_mmu, vcpu->arch.cr3);
5519 mmu_reset_needed = 1; 5526 mmu_reset_needed = 1;
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 2cea414489f3..c600da830ce0 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -70,6 +70,11 @@ static inline int is_paging(struct kvm_vcpu *vcpu)
70 return kvm_read_cr0_bits(vcpu, X86_CR0_PG); 70 return kvm_read_cr0_bits(vcpu, X86_CR0_PG);
71} 71}
72 72
73static inline u32 bit(int bitno)
74{
75 return 1 << (bitno & 31);
76}
77
73void kvm_before_handle_nmi(struct kvm_vcpu *vcpu); 78void kvm_before_handle_nmi(struct kvm_vcpu *vcpu);
74void kvm_after_handle_nmi(struct kvm_vcpu *vcpu); 79void kvm_after_handle_nmi(struct kvm_vcpu *vcpu);
75int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq); 80int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq);
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 73b1e1a1f489..4996cf5f73a0 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -531,7 +531,10 @@ static void lguest_write_cr3(unsigned long cr3)
531{ 531{
532 lguest_data.pgdir = cr3; 532 lguest_data.pgdir = cr3;
533 lazy_hcall1(LHCALL_NEW_PGTABLE, cr3); 533 lazy_hcall1(LHCALL_NEW_PGTABLE, cr3);
534 cr3_changed = true; 534
535 /* These two page tables are simple, linear, and used during boot */
536 if (cr3 != __pa(swapper_pg_dir) && cr3 != __pa(initial_page_table))
537 cr3_changed = true;
535} 538}
536 539
537static unsigned long lguest_read_cr3(void) 540static unsigned long lguest_read_cr3(void)
@@ -703,9 +706,9 @@ static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval)
703 * to forget all of them. Fortunately, this is very rare. 706 * to forget all of them. Fortunately, this is very rare.
704 * 707 *
705 * ... except in early boot when the kernel sets up the initial pagetables, 708 * ... except in early boot when the kernel sets up the initial pagetables,
706 * which makes booting astonishingly slow: 1.83 seconds! So we don't even tell 709 * which makes booting astonishingly slow: 48 seconds! So we don't even tell
707 * the Host anything changed until we've done the first page table switch, 710 * the Host anything changed until we've done the first real page table switch,
708 * which brings boot back to 0.25 seconds. 711 * which brings boot back to 4.3 seconds.
709 */ 712 */
710static void lguest_set_pte(pte_t *ptep, pte_t pteval) 713static void lguest_set_pte(pte_t *ptep, pte_t pteval)
711{ 714{
@@ -1002,7 +1005,7 @@ static void lguest_time_init(void)
1002 clockevents_register_device(&lguest_clockevent); 1005 clockevents_register_device(&lguest_clockevent);
1003 1006
1004 /* Finally, we unblock the timer interrupt. */ 1007 /* Finally, we unblock the timer interrupt. */
1005 enable_lguest_irq(0); 1008 clear_bit(0, lguest_data.blocked_interrupts);
1006} 1009}
1007 1010
1008/* 1011/*
@@ -1349,9 +1352,6 @@ __init void lguest_init(void)
1349 */ 1352 */
1350 switch_to_new_gdt(0); 1353 switch_to_new_gdt(0);
1351 1354
1352 /* We actually boot with all memory mapped, but let's say 128MB. */
1353 max_pfn_mapped = (128*1024*1024) >> PAGE_SHIFT;
1354
1355 /* 1355 /*
1356 * The Host<->Guest Switcher lives at the top of our address space, and 1356 * The Host<->Guest Switcher lives at the top of our address space, and
1357 * the Host told us how big it is when we made LGUEST_INIT hypercall: 1357 * the Host told us how big it is when we made LGUEST_INIT hypercall:
diff --git a/arch/x86/lguest/i386_head.S b/arch/x86/lguest/i386_head.S
index 4f420c2f2d55..e7d5382ef263 100644
--- a/arch/x86/lguest/i386_head.S
+++ b/arch/x86/lguest/i386_head.S
@@ -4,6 +4,7 @@
4#include <asm/asm-offsets.h> 4#include <asm/asm-offsets.h>
5#include <asm/thread_info.h> 5#include <asm/thread_info.h>
6#include <asm/processor-flags.h> 6#include <asm/processor-flags.h>
7#include <asm/pgtable.h>
7 8
8/*G:020 9/*G:020
9 * Our story starts with the kernel booting into startup_32 in 10 * Our story starts with the kernel booting into startup_32 in
@@ -37,9 +38,113 @@ ENTRY(lguest_entry)
37 /* Set up the initial stack so we can run C code. */ 38 /* Set up the initial stack so we can run C code. */
38 movl $(init_thread_union+THREAD_SIZE),%esp 39 movl $(init_thread_union+THREAD_SIZE),%esp
39 40
41 call init_pagetables
42
40 /* Jumps are relative: we're running __PAGE_OFFSET too low. */ 43 /* Jumps are relative: we're running __PAGE_OFFSET too low. */
41 jmp lguest_init+__PAGE_OFFSET 44 jmp lguest_init+__PAGE_OFFSET
42 45
46/*
47 * Initialize page tables. This creates a PDE and a set of page
48 * tables, which are located immediately beyond __brk_base. The variable
49 * _brk_end is set up to point to the first "safe" location.
50 * Mappings are created both at virtual address 0 (identity mapping)
51 * and PAGE_OFFSET for up to _end.
52 *
53 * FIXME: This code is taken verbatim from arch/x86/kernel/head_32.S: they
54 * don't have a stack at this point, so we can't just use call and ret.
55 */
56init_pagetables:
57#if PTRS_PER_PMD > 1
58#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
59#else
60#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
61#endif
62#define pa(X) ((X) - __PAGE_OFFSET)
63
64/* Enough space to fit pagetables for the low memory linear map */
65MAPPING_BEYOND_END = \
66 PAGE_TABLE_SIZE(((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT) << PAGE_SHIFT
67#ifdef CONFIG_X86_PAE
68
69 /*
70 * In PAE mode initial_page_table is statically defined to contain
71 * enough entries to cover the VMSPLIT option (that is the top 1, 2 or 3
72 * entries). The identity mapping is handled by pointing two PGD entries
73 * to the first kernel PMD.
74 *
75 * Note the upper half of each PMD or PTE are always zero at this stage.
76 */
77
78#define KPMDS (((-__PAGE_OFFSET) >> 30) & 3) /* Number of kernel PMDs */
79
80 xorl %ebx,%ebx /* %ebx is kept at zero */
81
82 movl $pa(__brk_base), %edi
83 movl $pa(initial_pg_pmd), %edx
84 movl $PTE_IDENT_ATTR, %eax
8510:
86 leal PDE_IDENT_ATTR(%edi),%ecx /* Create PMD entry */
87 movl %ecx,(%edx) /* Store PMD entry */
88 /* Upper half already zero */
89 addl $8,%edx
90 movl $512,%ecx
9111:
92 stosl
93 xchgl %eax,%ebx
94 stosl
95 xchgl %eax,%ebx
96 addl $0x1000,%eax
97 loop 11b
98
99 /*
100 * End condition: we must map up to the end + MAPPING_BEYOND_END.
101 */
102 movl $pa(_end) + MAPPING_BEYOND_END + PTE_IDENT_ATTR, %ebp
103 cmpl %ebp,%eax
104 jb 10b
1051:
106 addl $__PAGE_OFFSET, %edi
107 movl %edi, pa(_brk_end)
108 shrl $12, %eax
109 movl %eax, pa(max_pfn_mapped)
110
111 /* Do early initialization of the fixmap area */
112 movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
113 movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
114#else /* Not PAE */
115
116page_pde_offset = (__PAGE_OFFSET >> 20);
117
118 movl $pa(__brk_base), %edi
119 movl $pa(initial_page_table), %edx
120 movl $PTE_IDENT_ATTR, %eax
12110:
122 leal PDE_IDENT_ATTR(%edi),%ecx /* Create PDE entry */
123 movl %ecx,(%edx) /* Store identity PDE entry */
124 movl %ecx,page_pde_offset(%edx) /* Store kernel PDE entry */
125 addl $4,%edx
126 movl $1024, %ecx
12711:
128 stosl
129 addl $0x1000,%eax
130 loop 11b
131 /*
132 * End condition: we must map up to the end + MAPPING_BEYOND_END.
133 */
134 movl $pa(_end) + MAPPING_BEYOND_END + PTE_IDENT_ATTR, %ebp
135 cmpl %ebp,%eax
136 jb 10b
137 addl $__PAGE_OFFSET, %edi
138 movl %edi, pa(_brk_end)
139 shrl $12, %eax
140 movl %eax, pa(max_pfn_mapped)
141
142 /* Do early initialization of the fixmap area */
143 movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
144 movl %eax,pa(initial_page_table+0xffc)
145#endif
146 ret
147
43/*G:055 148/*G:055
44 * We create a macro which puts the assembler code between lgstart_ and lgend_ 149 * We create a macro which puts the assembler code between lgstart_ and lgend_
45 * markers. These templates are put in the .text section: they can't be 150 * markers. These templates are put in the .text section: they can't be
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 49358481c733..6acc724d5d8f 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -223,7 +223,7 @@ void native_flush_tlb_others(const struct cpumask *cpumask,
223 223
224static void __cpuinit calculate_tlb_offset(void) 224static void __cpuinit calculate_tlb_offset(void)
225{ 225{
226 int cpu, node, nr_node_vecs; 226 int cpu, node, nr_node_vecs, idx = 0;
227 /* 227 /*
228 * we are changing tlb_vector_offset for each CPU in runtime, but this 228 * we are changing tlb_vector_offset for each CPU in runtime, but this
229 * will not cause inconsistency, as the write is atomic under X86. we 229 * will not cause inconsistency, as the write is atomic under X86. we
@@ -239,7 +239,7 @@ static void __cpuinit calculate_tlb_offset(void)
239 nr_node_vecs = NUM_INVALIDATE_TLB_VECTORS/nr_online_nodes; 239 nr_node_vecs = NUM_INVALIDATE_TLB_VECTORS/nr_online_nodes;
240 240
241 for_each_online_node(node) { 241 for_each_online_node(node) {
242 int node_offset = (node % NUM_INVALIDATE_TLB_VECTORS) * 242 int node_offset = (idx % NUM_INVALIDATE_TLB_VECTORS) *
243 nr_node_vecs; 243 nr_node_vecs;
244 int cpu_offset = 0; 244 int cpu_offset = 0;
245 for_each_cpu(cpu, cpumask_of_node(node)) { 245 for_each_cpu(cpu, cpumask_of_node(node)) {
@@ -248,10 +248,11 @@ static void __cpuinit calculate_tlb_offset(void)
248 cpu_offset++; 248 cpu_offset++;
249 cpu_offset = cpu_offset % nr_node_vecs; 249 cpu_offset = cpu_offset % nr_node_vecs;
250 } 250 }
251 idx++;
251 } 252 }
252} 253}
253 254
254static int tlb_cpuhp_notify(struct notifier_block *n, 255static int __cpuinit tlb_cpuhp_notify(struct notifier_block *n,
255 unsigned long action, void *hcpu) 256 unsigned long action, void *hcpu)
256{ 257{
257 switch (action & 0xf) { 258 switch (action & 0xf) {
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index 15466c096ba5..0972315c3860 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -138,7 +138,6 @@ setup_resource(struct acpi_resource *acpi_res, void *data)
138 struct acpi_resource_address64 addr; 138 struct acpi_resource_address64 addr;
139 acpi_status status; 139 acpi_status status;
140 unsigned long flags; 140 unsigned long flags;
141 struct resource *root, *conflict;
142 u64 start, end; 141 u64 start, end;
143 142
144 status = resource_to_addr(acpi_res, &addr); 143 status = resource_to_addr(acpi_res, &addr);
@@ -146,12 +145,10 @@ setup_resource(struct acpi_resource *acpi_res, void *data)
146 return AE_OK; 145 return AE_OK;
147 146
148 if (addr.resource_type == ACPI_MEMORY_RANGE) { 147 if (addr.resource_type == ACPI_MEMORY_RANGE) {
149 root = &iomem_resource;
150 flags = IORESOURCE_MEM; 148 flags = IORESOURCE_MEM;
151 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY) 149 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
152 flags |= IORESOURCE_PREFETCH; 150 flags |= IORESOURCE_PREFETCH;
153 } else if (addr.resource_type == ACPI_IO_RANGE) { 151 } else if (addr.resource_type == ACPI_IO_RANGE) {
154 root = &ioport_resource;
155 flags = IORESOURCE_IO; 152 flags = IORESOURCE_IO;
156 } else 153 } else
157 return AE_OK; 154 return AE_OK;
@@ -172,25 +169,90 @@ setup_resource(struct acpi_resource *acpi_res, void *data)
172 return AE_OK; 169 return AE_OK;
173 } 170 }
174 171
175 conflict = insert_resource_conflict(root, res); 172 info->res_num++;
176 if (conflict) { 173 if (addr.translation_offset)
177 dev_err(&info->bridge->dev, 174 dev_info(&info->bridge->dev, "host bridge window %pR "
178 "address space collision: host bridge window %pR " 175 "(PCI address [%#llx-%#llx])\n",
179 "conflicts with %s %pR\n", 176 res, res->start - addr.translation_offset,
180 res, conflict->name, conflict); 177 res->end - addr.translation_offset);
181 } else { 178 else
182 pci_bus_add_resource(info->bus, res, 0); 179 dev_info(&info->bridge->dev, "host bridge window %pR\n", res);
183 info->res_num++; 180
184 if (addr.translation_offset) 181 return AE_OK;
185 dev_info(&info->bridge->dev, "host bridge window %pR " 182}
186 "(PCI address [%#llx-%#llx])\n", 183
187 res, res->start - addr.translation_offset, 184static bool resource_contains(struct resource *res, resource_size_t point)
188 res->end - addr.translation_offset); 185{
186 if (res->start <= point && point <= res->end)
187 return true;
188 return false;
189}
190
191static void coalesce_windows(struct pci_root_info *info, int type)
192{
193 int i, j;
194 struct resource *res1, *res2;
195
196 for (i = 0; i < info->res_num; i++) {
197 res1 = &info->res[i];
198 if (!(res1->flags & type))
199 continue;
200
201 for (j = i + 1; j < info->res_num; j++) {
202 res2 = &info->res[j];
203 if (!(res2->flags & type))
204 continue;
205
206 /*
207 * I don't like throwing away windows because then
208 * our resources no longer match the ACPI _CRS, but
209 * the kernel resource tree doesn't allow overlaps.
210 */
211 if (resource_contains(res1, res2->start) ||
212 resource_contains(res1, res2->end) ||
213 resource_contains(res2, res1->start) ||
214 resource_contains(res2, res1->end)) {
215 res1->start = min(res1->start, res2->start);
216 res1->end = max(res1->end, res2->end);
217 dev_info(&info->bridge->dev,
218 "host bridge window expanded to %pR; %pR ignored\n",
219 res1, res2);
220 res2->flags = 0;
221 }
222 }
223 }
224}
225
226static void add_resources(struct pci_root_info *info)
227{
228 int i;
229 struct resource *res, *root, *conflict;
230
231 if (!pci_use_crs)
232 return;
233
234 coalesce_windows(info, IORESOURCE_MEM);
235 coalesce_windows(info, IORESOURCE_IO);
236
237 for (i = 0; i < info->res_num; i++) {
238 res = &info->res[i];
239
240 if (res->flags & IORESOURCE_MEM)
241 root = &iomem_resource;
242 else if (res->flags & IORESOURCE_IO)
243 root = &ioport_resource;
189 else 244 else
190 dev_info(&info->bridge->dev, 245 continue;
191 "host bridge window %pR\n", res); 246
247 conflict = insert_resource_conflict(root, res);
248 if (conflict)
249 dev_err(&info->bridge->dev,
250 "address space collision: host bridge window %pR "
251 "conflicts with %s %pR\n",
252 res, conflict->name, conflict);
253 else
254 pci_bus_add_resource(info->bus, res, 0);
192 } 255 }
193 return AE_OK;
194} 256}
195 257
196static void 258static void
@@ -224,6 +286,7 @@ get_current_resources(struct acpi_device *device, int busnum,
224 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource, 286 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
225 &info); 287 &info);
226 288
289 add_resources(&info);
227 return; 290 return;
228 291
229name_alloc_fail: 292name_alloc_fail:
diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index c4bb261c106e..b1805b78842f 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -65,21 +65,13 @@ pcibios_align_resource(void *data, const struct resource *res,
65 resource_size_t size, resource_size_t align) 65 resource_size_t size, resource_size_t align)
66{ 66{
67 struct pci_dev *dev = data; 67 struct pci_dev *dev = data;
68 resource_size_t start = round_down(res->end - size + 1, align); 68 resource_size_t start = res->start;
69 69
70 if (res->flags & IORESOURCE_IO) { 70 if (res->flags & IORESOURCE_IO) {
71 71 if (skip_isa_ioresource_align(dev))
72 /* 72 return start;
73 * If we're avoiding ISA aliases, the largest contiguous I/O 73 if (start & 0x300)
74 * port space is 256 bytes. Clearing bits 9 and 10 preserves 74 start = (start + 0x3ff) & ~0x3ff;
75 * all 256-byte and smaller alignments, so the result will
76 * still be correctly aligned.
77 */
78 if (!skip_isa_ioresource_align(dev))
79 start &= ~0x300;
80 } else if (res->flags & IORESOURCE_MEM) {
81 if (start < BIOS_END)
82 start = res->end; /* fail; no space */
83 } 75 }
84 return start; 76 return start;
85} 77}
diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
index 117f5b8daf75..25cd4a07d09f 100644
--- a/arch/x86/pci/xen.c
+++ b/arch/x86/pci/xen.c
@@ -70,6 +70,9 @@ static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi,
70struct xen_pci_frontend_ops *xen_pci_frontend; 70struct xen_pci_frontend_ops *xen_pci_frontend;
71EXPORT_SYMBOL_GPL(xen_pci_frontend); 71EXPORT_SYMBOL_GPL(xen_pci_frontend);
72 72
73#define XEN_PIRQ_MSI_DATA (MSI_DATA_TRIGGER_EDGE | \
74 MSI_DATA_LEVEL_ASSERT | (3 << 8) | MSI_DATA_VECTOR(0))
75
73static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq, 76static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq,
74 struct msi_msg *msg) 77 struct msi_msg *msg)
75{ 78{
@@ -83,12 +86,7 @@ static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq,
83 MSI_ADDR_REDIRECTION_CPU | 86 MSI_ADDR_REDIRECTION_CPU |
84 MSI_ADDR_DEST_ID(pirq); 87 MSI_ADDR_DEST_ID(pirq);
85 88
86 msg->data = 89 msg->data = XEN_PIRQ_MSI_DATA;
87 MSI_DATA_TRIGGER_EDGE |
88 MSI_DATA_LEVEL_ASSERT |
89 /* delivery mode reserved */
90 (3 << 8) |
91 MSI_DATA_VECTOR(0);
92} 90}
93 91
94static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) 92static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
@@ -98,8 +96,23 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
98 struct msi_msg msg; 96 struct msi_msg msg;
99 97
100 list_for_each_entry(msidesc, &dev->msi_list, list) { 98 list_for_each_entry(msidesc, &dev->msi_list, list) {
99 __read_msi_msg(msidesc, &msg);
100 pirq = MSI_ADDR_EXT_DEST_ID(msg.address_hi) |
101 ((msg.address_lo >> MSI_ADDR_DEST_ID_SHIFT) & 0xff);
102 if (xen_irq_from_pirq(pirq) >= 0 && msg.data == XEN_PIRQ_MSI_DATA) {
103 xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ?
104 "msi-x" : "msi", &irq, &pirq, XEN_ALLOC_IRQ);
105 if (irq < 0)
106 goto error;
107 ret = set_irq_msi(irq, msidesc);
108 if (ret < 0)
109 goto error_while;
110 printk(KERN_DEBUG "xen: msi already setup: msi --> irq=%d"
111 " pirq=%d\n", irq, pirq);
112 return 0;
113 }
101 xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ? 114 xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ?
102 "msi-x" : "msi", &irq, &pirq); 115 "msi-x" : "msi", &irq, &pirq, (XEN_ALLOC_IRQ | XEN_ALLOC_PIRQ));
103 if (irq < 0 || pirq < 0) 116 if (irq < 0 || pirq < 0)
104 goto error; 117 goto error;
105 printk(KERN_DEBUG "xen: msi --> irq=%d, pirq=%d\n", irq, pirq); 118 printk(KERN_DEBUG "xen: msi --> irq=%d, pirq=%d\n", irq, pirq);
@@ -147,8 +160,10 @@ static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
147 irq = xen_allocate_pirq(v[i], 0, /* not sharable */ 160 irq = xen_allocate_pirq(v[i], 0, /* not sharable */
148 (type == PCI_CAP_ID_MSIX) ? 161 (type == PCI_CAP_ID_MSIX) ?
149 "pcifront-msi-x" : "pcifront-msi"); 162 "pcifront-msi-x" : "pcifront-msi");
150 if (irq < 0) 163 if (irq < 0) {
151 return -1; 164 ret = -1;
165 goto free;
166 }
152 167
153 ret = set_irq_msi(irq, msidesc); 168 ret = set_irq_msi(irq, msidesc);
154 if (ret) 169 if (ret)
@@ -164,7 +179,7 @@ error:
164 if (ret == -ENODEV) 179 if (ret == -ENODEV)
165 dev_err(&dev->dev, "Xen PCI frontend has not registered" \ 180 dev_err(&dev->dev, "Xen PCI frontend has not registered" \
166 " MSI/MSI-X support!\n"); 181 " MSI/MSI-X support!\n");
167 182free:
168 kfree(v); 183 kfree(v);
169 return ret; 184 return ret;
170} 185}
diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index 20ea20a39e2a..ba9caa808a9c 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -1343,8 +1343,8 @@ uv_activation_descriptor_init(int node, int pnode)
1343 * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR) 1343 * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
1344 * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub 1344 * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub
1345 */ 1345 */
1346 bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)* 1346 bau_desc = kmalloc_node(sizeof(struct bau_desc) * UV_ADP_SIZE
1347 UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node); 1347 * UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
1348 BUG_ON(!bau_desc); 1348 BUG_ON(!bau_desc);
1349 1349
1350 pa = uv_gpa(bau_desc); /* need the real nasid*/ 1350 pa = uv_gpa(bau_desc); /* need the real nasid*/
@@ -1402,9 +1402,9 @@ uv_payload_queue_init(int node, int pnode)
1402 struct bau_payload_queue_entry *pqp_malloc; 1402 struct bau_payload_queue_entry *pqp_malloc;
1403 struct bau_control *bcp; 1403 struct bau_control *bcp;
1404 1404
1405 pqp = (struct bau_payload_queue_entry *) kmalloc_node( 1405 pqp = kmalloc_node((DEST_Q_SIZE + 1)
1406 (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry), 1406 * sizeof(struct bau_payload_queue_entry),
1407 GFP_KERNEL, node); 1407 GFP_KERNEL, node);
1408 BUG_ON(!pqp); 1408 BUG_ON(!pqp);
1409 pqp_malloc = pqp; 1409 pqp_malloc = pqp;
1410 1410
@@ -1455,7 +1455,7 @@ static void __init uv_init_uvhub(int uvhub, int vector)
1455 * the below initialization can't be in firmware because the 1455 * the below initialization can't be in firmware because the
1456 * messaging IRQ will be determined by the OS 1456 * messaging IRQ will be determined by the OS
1457 */ 1457 */
1458 apicid = uvhub_to_first_apicid(uvhub); 1458 apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
1459 uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG, 1459 uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
1460 ((apicid << 32) | vector)); 1460 ((apicid << 32) | vector));
1461} 1461}
@@ -1520,8 +1520,7 @@ static void __init uv_init_per_cpu(int nuvhubs)
1520 1520
1521 timeout_us = calculate_destination_timeout(); 1521 timeout_us = calculate_destination_timeout();
1522 1522
1523 uvhub_descs = (struct uvhub_desc *) 1523 uvhub_descs = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1524 kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1525 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc)); 1524 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1526 uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL); 1525 uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
1527 for_each_present_cpu(cpu) { 1526 for_each_present_cpu(cpu) {
diff --git a/arch/x86/platform/uv/uv_time.c b/arch/x86/platform/uv/uv_time.c
index 56e421bc379b..9daf5d1af9f1 100644
--- a/arch/x86/platform/uv/uv_time.c
+++ b/arch/x86/platform/uv/uv_time.c
@@ -89,6 +89,7 @@ static void uv_rtc_send_IPI(int cpu)
89 89
90 apicid = cpu_physical_id(cpu); 90 apicid = cpu_physical_id(cpu);
91 pnode = uv_apicid_to_pnode(apicid); 91 pnode = uv_apicid_to_pnode(apicid);
92 apicid |= uv_apicid_hibits;
92 val = (1UL << UVH_IPI_INT_SEND_SHFT) | 93 val = (1UL << UVH_IPI_INT_SEND_SHFT) |
93 (apicid << UVH_IPI_INT_APIC_ID_SHFT) | 94 (apicid << UVH_IPI_INT_APIC_ID_SHFT) |
94 (X86_PLATFORM_IPI_VECTOR << UVH_IPI_INT_VECTOR_SHFT); 95 (X86_PLATFORM_IPI_VECTOR << UVH_IPI_INT_VECTOR_SHFT);
@@ -107,6 +108,7 @@ static int uv_intr_pending(int pnode)
107static int uv_setup_intr(int cpu, u64 expires) 108static int uv_setup_intr(int cpu, u64 expires)
108{ 109{
109 u64 val; 110 u64 val;
111 unsigned long apicid = cpu_physical_id(cpu) | uv_apicid_hibits;
110 int pnode = uv_cpu_to_pnode(cpu); 112 int pnode = uv_cpu_to_pnode(cpu);
111 113
112 uv_write_global_mmr64(pnode, UVH_RTC1_INT_CONFIG, 114 uv_write_global_mmr64(pnode, UVH_RTC1_INT_CONFIG,
@@ -117,7 +119,7 @@ static int uv_setup_intr(int cpu, u64 expires)
117 UVH_EVENT_OCCURRED0_RTC1_MASK); 119 UVH_EVENT_OCCURRED0_RTC1_MASK);
118 120
119 val = (X86_PLATFORM_IPI_VECTOR << UVH_RTC1_INT_CONFIG_VECTOR_SHFT) | 121 val = (X86_PLATFORM_IPI_VECTOR << UVH_RTC1_INT_CONFIG_VECTOR_SHFT) |
120 ((u64)cpu_physical_id(cpu) << UVH_RTC1_INT_CONFIG_APIC_ID_SHFT); 122 ((u64)apicid << UVH_RTC1_INT_CONFIG_APIC_ID_SHFT);
121 123
122 /* Set configuration */ 124 /* Set configuration */
123 uv_write_global_mmr64(pnode, UVH_RTC1_INT_CONFIG, val); 125 uv_write_global_mmr64(pnode, UVH_RTC1_INT_CONFIG, val);
diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
index 4a2afa1bac51..b6552b189bcd 100644
--- a/arch/x86/vdso/Makefile
+++ b/arch/x86/vdso/Makefile
@@ -25,7 +25,7 @@ targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
25 25
26export CPPFLAGS_vdso.lds += -P -C 26export CPPFLAGS_vdso.lds += -P -C
27 27
28VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -Wl,-soname=linux-vdso.so.1 \ 28VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
29 -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 29 -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
30 30
31$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so 31$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
@@ -69,7 +69,7 @@ vdso32.so-$(VDSO32-y) += sysenter
69vdso32-images = $(vdso32.so-y:%=vdso32-%.so) 69vdso32-images = $(vdso32.so-y:%=vdso32-%.so)
70 70
71CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds) 71CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
72VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -Wl,-soname=linux-gate.so.1 72VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-soname=linux-gate.so.1
73 73
74# This makes sure the $(obj) subdirectory exists even though vdso32/ 74# This makes sure the $(obj) subdirectory exists even though vdso32/
75# is not a kbuild sub-make subdirectory. 75# is not a kbuild sub-make subdirectory.
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 235c0f4d3861..44dcad43989d 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -75,6 +75,11 @@ DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
75enum xen_domain_type xen_domain_type = XEN_NATIVE; 75enum xen_domain_type xen_domain_type = XEN_NATIVE;
76EXPORT_SYMBOL_GPL(xen_domain_type); 76EXPORT_SYMBOL_GPL(xen_domain_type);
77 77
78unsigned long *machine_to_phys_mapping = (void *)MACH2PHYS_VIRT_START;
79EXPORT_SYMBOL(machine_to_phys_mapping);
80unsigned int machine_to_phys_order;
81EXPORT_SYMBOL(machine_to_phys_order);
82
78struct start_info *xen_start_info; 83struct start_info *xen_start_info;
79EXPORT_SYMBOL_GPL(xen_start_info); 84EXPORT_SYMBOL_GPL(xen_start_info);
80 85
@@ -1016,10 +1021,6 @@ static void xen_reboot(int reason)
1016{ 1021{
1017 struct sched_shutdown r = { .reason = reason }; 1022 struct sched_shutdown r = { .reason = reason };
1018 1023
1019#ifdef CONFIG_SMP
1020 stop_other_cpus();
1021#endif
1022
1023 if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r)) 1024 if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
1024 BUG(); 1025 BUG();
1025} 1026}
@@ -1090,6 +1091,8 @@ static void __init xen_setup_stackprotector(void)
1090/* First C function to be called on Xen boot */ 1091/* First C function to be called on Xen boot */
1091asmlinkage void __init xen_start_kernel(void) 1092asmlinkage void __init xen_start_kernel(void)
1092{ 1093{
1094 struct physdev_set_iopl set_iopl;
1095 int rc;
1093 pgd_t *pgd; 1096 pgd_t *pgd;
1094 1097
1095 if (!xen_start_info) 1098 if (!xen_start_info)
@@ -1097,6 +1100,8 @@ asmlinkage void __init xen_start_kernel(void)
1097 1100
1098 xen_domain_type = XEN_PV_DOMAIN; 1101 xen_domain_type = XEN_PV_DOMAIN;
1099 1102
1103 xen_setup_machphys_mapping();
1104
1100 /* Install Xen paravirt ops */ 1105 /* Install Xen paravirt ops */
1101 pv_info = xen_info; 1106 pv_info = xen_info;
1102 pv_init_ops = xen_init_ops; 1107 pv_init_ops = xen_init_ops;
@@ -1191,8 +1196,6 @@ asmlinkage void __init xen_start_kernel(void)
1191 /* Allocate and initialize top and mid mfn levels for p2m structure */ 1196 /* Allocate and initialize top and mid mfn levels for p2m structure */
1192 xen_build_mfn_list_list(); 1197 xen_build_mfn_list_list();
1193 1198
1194 init_mm.pgd = pgd;
1195
1196 /* keep using Xen gdt for now; no urgent need to change it */ 1199 /* keep using Xen gdt for now; no urgent need to change it */
1197 1200
1198#ifdef CONFIG_X86_32 1201#ifdef CONFIG_X86_32
@@ -1202,10 +1205,18 @@ asmlinkage void __init xen_start_kernel(void)
1202#else 1205#else
1203 pv_info.kernel_rpl = 0; 1206 pv_info.kernel_rpl = 0;
1204#endif 1207#endif
1205
1206 /* set the limit of our address space */ 1208 /* set the limit of our address space */
1207 xen_reserve_top(); 1209 xen_reserve_top();
1208 1210
1211 /* We used to do this in xen_arch_setup, but that is too late on AMD
1212 * were early_cpu_init (run before ->arch_setup()) calls early_amd_init
1213 * which pokes 0xcf8 port.
1214 */
1215 set_iopl.iopl = 1;
1216 rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
1217 if (rc != 0)
1218 xen_raw_printk("physdev_op failed %d\n", rc);
1219
1209#ifdef CONFIG_X86_32 1220#ifdef CONFIG_X86_32
1210 /* set up basic CPUID stuff */ 1221 /* set up basic CPUID stuff */
1211 cpu_detect(&new_cpu_data); 1222 cpu_detect(&new_cpu_data);
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index c237b810b03f..44924e551fde 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -2034,6 +2034,20 @@ static __init void xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)
2034 set_page_prot(pmd, PAGE_KERNEL_RO); 2034 set_page_prot(pmd, PAGE_KERNEL_RO);
2035} 2035}
2036 2036
2037void __init xen_setup_machphys_mapping(void)
2038{
2039 struct xen_machphys_mapping mapping;
2040 unsigned long machine_to_phys_nr_ents;
2041
2042 if (HYPERVISOR_memory_op(XENMEM_machphys_mapping, &mapping) == 0) {
2043 machine_to_phys_mapping = (unsigned long *)mapping.v_start;
2044 machine_to_phys_nr_ents = mapping.max_mfn + 1;
2045 } else {
2046 machine_to_phys_nr_ents = MACH2PHYS_NR_ENTRIES;
2047 }
2048 machine_to_phys_order = fls(machine_to_phys_nr_ents - 1);
2049}
2050
2037#ifdef CONFIG_X86_64 2051#ifdef CONFIG_X86_64
2038static void convert_pfn_mfn(void *v) 2052static void convert_pfn_mfn(void *v)
2039{ 2053{
@@ -2119,44 +2133,83 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
2119 return pgd; 2133 return pgd;
2120} 2134}
2121#else /* !CONFIG_X86_64 */ 2135#else /* !CONFIG_X86_64 */
2122static RESERVE_BRK_ARRAY(pmd_t, level2_kernel_pgt, PTRS_PER_PMD); 2136static RESERVE_BRK_ARRAY(pmd_t, initial_kernel_pmd, PTRS_PER_PMD);
2137static RESERVE_BRK_ARRAY(pmd_t, swapper_kernel_pmd, PTRS_PER_PMD);
2138
2139static __init void xen_write_cr3_init(unsigned long cr3)
2140{
2141 unsigned long pfn = PFN_DOWN(__pa(swapper_pg_dir));
2142
2143 BUG_ON(read_cr3() != __pa(initial_page_table));
2144 BUG_ON(cr3 != __pa(swapper_pg_dir));
2145
2146 /*
2147 * We are switching to swapper_pg_dir for the first time (from
2148 * initial_page_table) and therefore need to mark that page
2149 * read-only and then pin it.
2150 *
2151 * Xen disallows sharing of kernel PMDs for PAE
2152 * guests. Therefore we must copy the kernel PMD from
2153 * initial_page_table into a new kernel PMD to be used in
2154 * swapper_pg_dir.
2155 */
2156 swapper_kernel_pmd =
2157 extend_brk(sizeof(pmd_t) * PTRS_PER_PMD, PAGE_SIZE);
2158 memcpy(swapper_kernel_pmd, initial_kernel_pmd,
2159 sizeof(pmd_t) * PTRS_PER_PMD);
2160 swapper_pg_dir[KERNEL_PGD_BOUNDARY] =
2161 __pgd(__pa(swapper_kernel_pmd) | _PAGE_PRESENT);
2162 set_page_prot(swapper_kernel_pmd, PAGE_KERNEL_RO);
2163
2164 set_page_prot(swapper_pg_dir, PAGE_KERNEL_RO);
2165 xen_write_cr3(cr3);
2166 pin_pagetable_pfn(MMUEXT_PIN_L3_TABLE, pfn);
2167
2168 pin_pagetable_pfn(MMUEXT_UNPIN_TABLE,
2169 PFN_DOWN(__pa(initial_page_table)));
2170 set_page_prot(initial_page_table, PAGE_KERNEL);
2171 set_page_prot(initial_kernel_pmd, PAGE_KERNEL);
2172
2173 pv_mmu_ops.write_cr3 = &xen_write_cr3;
2174}
2123 2175
2124__init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd, 2176__init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
2125 unsigned long max_pfn) 2177 unsigned long max_pfn)
2126{ 2178{
2127 pmd_t *kernel_pmd; 2179 pmd_t *kernel_pmd;
2128 2180
2129 level2_kernel_pgt = extend_brk(sizeof(pmd_t *) * PTRS_PER_PMD, PAGE_SIZE); 2181 initial_kernel_pmd =
2182 extend_brk(sizeof(pmd_t) * PTRS_PER_PMD, PAGE_SIZE);
2130 2183
2131 max_pfn_mapped = PFN_DOWN(__pa(xen_start_info->pt_base) + 2184 max_pfn_mapped = PFN_DOWN(__pa(xen_start_info->pt_base) +
2132 xen_start_info->nr_pt_frames * PAGE_SIZE + 2185 xen_start_info->nr_pt_frames * PAGE_SIZE +
2133 512*1024); 2186 512*1024);
2134 2187
2135 kernel_pmd = m2v(pgd[KERNEL_PGD_BOUNDARY].pgd); 2188 kernel_pmd = m2v(pgd[KERNEL_PGD_BOUNDARY].pgd);
2136 memcpy(level2_kernel_pgt, kernel_pmd, sizeof(pmd_t) * PTRS_PER_PMD); 2189 memcpy(initial_kernel_pmd, kernel_pmd, sizeof(pmd_t) * PTRS_PER_PMD);
2137 2190
2138 xen_map_identity_early(level2_kernel_pgt, max_pfn); 2191 xen_map_identity_early(initial_kernel_pmd, max_pfn);
2139 2192
2140 memcpy(swapper_pg_dir, pgd, sizeof(pgd_t) * PTRS_PER_PGD); 2193 memcpy(initial_page_table, pgd, sizeof(pgd_t) * PTRS_PER_PGD);
2141 set_pgd(&swapper_pg_dir[KERNEL_PGD_BOUNDARY], 2194 initial_page_table[KERNEL_PGD_BOUNDARY] =
2142 __pgd(__pa(level2_kernel_pgt) | _PAGE_PRESENT)); 2195 __pgd(__pa(initial_kernel_pmd) | _PAGE_PRESENT);
2143 2196
2144 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO); 2197 set_page_prot(initial_kernel_pmd, PAGE_KERNEL_RO);
2145 set_page_prot(swapper_pg_dir, PAGE_KERNEL_RO); 2198 set_page_prot(initial_page_table, PAGE_KERNEL_RO);
2146 set_page_prot(empty_zero_page, PAGE_KERNEL_RO); 2199 set_page_prot(empty_zero_page, PAGE_KERNEL_RO);
2147 2200
2148 pin_pagetable_pfn(MMUEXT_UNPIN_TABLE, PFN_DOWN(__pa(pgd))); 2201 pin_pagetable_pfn(MMUEXT_UNPIN_TABLE, PFN_DOWN(__pa(pgd)));
2149 2202
2150 xen_write_cr3(__pa(swapper_pg_dir)); 2203 pin_pagetable_pfn(MMUEXT_PIN_L3_TABLE,
2151 2204 PFN_DOWN(__pa(initial_page_table)));
2152 pin_pagetable_pfn(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(swapper_pg_dir))); 2205 xen_write_cr3(__pa(initial_page_table));
2153 2206
2154 memblock_x86_reserve_range(__pa(xen_start_info->pt_base), 2207 memblock_x86_reserve_range(__pa(xen_start_info->pt_base),
2155 __pa(xen_start_info->pt_base + 2208 __pa(xen_start_info->pt_base +
2156 xen_start_info->nr_pt_frames * PAGE_SIZE), 2209 xen_start_info->nr_pt_frames * PAGE_SIZE),
2157 "XEN PAGETABLES"); 2210 "XEN PAGETABLES");
2158 2211
2159 return swapper_pg_dir; 2212 return initial_page_table;
2160} 2213}
2161#endif /* CONFIG_X86_64 */ 2214#endif /* CONFIG_X86_64 */
2162 2215
@@ -2290,7 +2343,11 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
2290 .write_cr2 = xen_write_cr2, 2343 .write_cr2 = xen_write_cr2,
2291 2344
2292 .read_cr3 = xen_read_cr3, 2345 .read_cr3 = xen_read_cr3,
2346#ifdef CONFIG_X86_32
2347 .write_cr3 = xen_write_cr3_init,
2348#else
2293 .write_cr3 = xen_write_cr3, 2349 .write_cr3 = xen_write_cr3,
2350#endif
2294 2351
2295 .flush_tlb_user = xen_flush_tlb, 2352 .flush_tlb_user = xen_flush_tlb,
2296 .flush_tlb_kernel = xen_flush_tlb, 2353 .flush_tlb_kernel = xen_flush_tlb,
@@ -2358,8 +2415,6 @@ void __init xen_init_mmu_ops(void)
2358 x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; 2415 x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done;
2359 pv_mmu_ops = xen_mmu_ops; 2416 pv_mmu_ops = xen_mmu_ops;
2360 2417
2361 vmap_lazy_unmap = false;
2362
2363 memset(dummy_mapping, 0xff, PAGE_SIZE); 2418 memset(dummy_mapping, 0xff, PAGE_SIZE);
2364} 2419}
2365 2420
@@ -2627,7 +2682,8 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
2627 2682
2628 prot = __pgprot(pgprot_val(prot) | _PAGE_IOMAP); 2683 prot = __pgprot(pgprot_val(prot) | _PAGE_IOMAP);
2629 2684
2630 vma->vm_flags |= VM_IO | VM_RESERVED | VM_PFNMAP; 2685 BUG_ON(!((vma->vm_flags & (VM_PFNMAP | VM_RESERVED | VM_IO)) ==
2686 (VM_PFNMAP | VM_RESERVED | VM_IO)));
2631 2687
2632 rmd.mfn = mfn; 2688 rmd.mfn = mfn;
2633 rmd.prot = prot; 2689 rmd.prot = prot;
diff --git a/arch/x86/xen/platform-pci-unplug.c b/arch/x86/xen/platform-pci-unplug.c
index 0f456386cce5..25c52f94a27c 100644
--- a/arch/x86/xen/platform-pci-unplug.c
+++ b/arch/x86/xen/platform-pci-unplug.c
@@ -68,7 +68,7 @@ static int __init check_platform_magic(void)
68 return 0; 68 return 0;
69} 69}
70 70
71void __init xen_unplug_emulated_devices(void) 71void xen_unplug_emulated_devices(void)
72{ 72{
73 int r; 73 int r;
74 74
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index b1dbdaa23ecc..b5a7f928234b 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -23,7 +23,6 @@
23#include <xen/interface/callback.h> 23#include <xen/interface/callback.h>
24#include <xen/interface/memory.h> 24#include <xen/interface/memory.h>
25#include <xen/interface/physdev.h> 25#include <xen/interface/physdev.h>
26#include <xen/interface/memory.h>
27#include <xen/features.h> 26#include <xen/features.h>
28 27
29#include "xen-ops.h" 28#include "xen-ops.h"
@@ -118,16 +117,18 @@ static unsigned long __init xen_return_unused_memory(unsigned long max_pfn,
118 const struct e820map *e820) 117 const struct e820map *e820)
119{ 118{
120 phys_addr_t max_addr = PFN_PHYS(max_pfn); 119 phys_addr_t max_addr = PFN_PHYS(max_pfn);
121 phys_addr_t last_end = 0; 120 phys_addr_t last_end = ISA_END_ADDRESS;
122 unsigned long released = 0; 121 unsigned long released = 0;
123 int i; 122 int i;
124 123
124 /* Free any unused memory above the low 1Mbyte. */
125 for (i = 0; i < e820->nr_map && last_end < max_addr; i++) { 125 for (i = 0; i < e820->nr_map && last_end < max_addr; i++) {
126 phys_addr_t end = e820->map[i].addr; 126 phys_addr_t end = e820->map[i].addr;
127 end = min(max_addr, end); 127 end = min(max_addr, end);
128 128
129 released += xen_release_chunk(last_end, end); 129 if (last_end < end)
130 last_end = e820->map[i].addr + e820->map[i].size; 130 released += xen_release_chunk(last_end, end);
131 last_end = max(last_end, e820->map[i].addr + e820->map[i].size);
131 } 132 }
132 133
133 if (last_end < max_addr) 134 if (last_end < max_addr)
@@ -164,6 +165,7 @@ char * __init xen_memory_setup(void)
164 XENMEM_memory_map; 165 XENMEM_memory_map;
165 rc = HYPERVISOR_memory_op(op, &memmap); 166 rc = HYPERVISOR_memory_op(op, &memmap);
166 if (rc == -ENOSYS) { 167 if (rc == -ENOSYS) {
168 BUG_ON(xen_initial_domain());
167 memmap.nr_entries = 1; 169 memmap.nr_entries = 1;
168 map[0].addr = 0ULL; 170 map[0].addr = 0ULL;
169 map[0].size = mem_end; 171 map[0].size = mem_end;
@@ -179,34 +181,32 @@ char * __init xen_memory_setup(void)
179 for (i = 0; i < memmap.nr_entries; i++) { 181 for (i = 0; i < memmap.nr_entries; i++) {
180 unsigned long long end = map[i].addr + map[i].size; 182 unsigned long long end = map[i].addr + map[i].size;
181 183
182 if (map[i].type == E820_RAM) { 184 if (map[i].type == E820_RAM && end > mem_end) {
183 if (map[i].addr < mem_end && end > mem_end) { 185 /* RAM off the end - may be partially included */
184 /* Truncate region to max_mem. */ 186 u64 delta = min(map[i].size, end - mem_end);
185 u64 delta = end - mem_end;
186 187
187 map[i].size -= delta; 188 map[i].size -= delta;
188 extra_pages += PFN_DOWN(delta); 189 end -= delta;
189 190
190 end = mem_end; 191 extra_pages += PFN_DOWN(delta);
191 }
192 } 192 }
193 193
194 if (end > xen_extra_mem_start) 194 if (map[i].size > 0 && end > xen_extra_mem_start)
195 xen_extra_mem_start = end; 195 xen_extra_mem_start = end;
196 196
197 /* If region is non-RAM or below mem_end, add what remains */ 197 /* Add region if any remains */
198 if ((map[i].type != E820_RAM || map[i].addr < mem_end) && 198 if (map[i].size > 0)
199 map[i].size > 0)
200 e820_add_region(map[i].addr, map[i].size, map[i].type); 199 e820_add_region(map[i].addr, map[i].size, map[i].type);
201 } 200 }
202 201
203 /* 202 /*
204 * Even though this is normal, usable memory under Xen, reserve 203 * In domU, the ISA region is normal, usable memory, but we
205 * ISA memory anyway because too many things think they can poke 204 * reserve ISA memory anyway because too many things poke
206 * about in there. 205 * about in there.
207 * 206 *
208 * In a dom0 kernel, this region is identity mapped with the 207 * In Dom0, the host E820 information can leave gaps in the
209 * hardware ISA area, so it really is out of bounds. 208 * ISA range, which would cause us to release those pages. To
209 * avoid this, we unconditionally reserve them here.
210 */ 210 */
211 e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, 211 e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
212 E820_RESERVED); 212 E820_RESERVED);
@@ -244,26 +244,11 @@ char * __init xen_memory_setup(void)
244 else 244 else
245 extra_pages = 0; 245 extra_pages = 0;
246 246
247 if (!xen_initial_domain()) 247 xen_add_extra_mem(extra_pages);
248 xen_add_extra_mem(extra_pages);
249 248
250 return "Xen"; 249 return "Xen";
251} 250}
252 251
253static void xen_idle(void)
254{
255 local_irq_disable();
256
257 if (need_resched())
258 local_irq_enable();
259 else {
260 current_thread_info()->status &= ~TS_POLLING;
261 smp_mb__after_clear_bit();
262 safe_halt();
263 current_thread_info()->status |= TS_POLLING;
264 }
265}
266
267/* 252/*
268 * Set the bit indicating "nosegneg" library variants should be used. 253 * Set the bit indicating "nosegneg" library variants should be used.
269 * We only need to bother in pure 32-bit mode; compat 32-bit processes 254 * We only need to bother in pure 32-bit mode; compat 32-bit processes
@@ -333,9 +318,6 @@ void __cpuinit xen_enable_syscall(void)
333 318
334void __init xen_arch_setup(void) 319void __init xen_arch_setup(void)
335{ 320{
336 struct physdev_set_iopl set_iopl;
337 int rc;
338
339 xen_panic_handler_init(); 321 xen_panic_handler_init();
340 322
341 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); 323 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments);
@@ -352,11 +334,6 @@ void __init xen_arch_setup(void)
352 xen_enable_sysenter(); 334 xen_enable_sysenter();
353 xen_enable_syscall(); 335 xen_enable_syscall();
354 336
355 set_iopl.iopl = 1;
356 rc = HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
357 if (rc != 0)
358 printk(KERN_INFO "physdev_op failed %d\n", rc);
359
360#ifdef CONFIG_ACPI 337#ifdef CONFIG_ACPI
361 if (!(xen_start_info->flags & SIF_INITDOMAIN)) { 338 if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
362 printk(KERN_INFO "ACPI in unprivileged domain disabled\n"); 339 printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
@@ -368,7 +345,11 @@ void __init xen_arch_setup(void)
368 MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ? 345 MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ?
369 COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE); 346 COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE);
370 347
371 pm_idle = xen_idle; 348 /* Set up idle, making sure it calls safe_halt() pvop */
349#ifdef CONFIG_X86_32
350 boot_cpu_data.hlt_works_ok = 1;
351#endif
352 pm_idle = default_idle;
372 353
373 fiddle_vdso(); 354 fiddle_vdso();
374} 355}
diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c
index 1d789d56877c..9bbd63a129b5 100644
--- a/arch/x86/xen/suspend.c
+++ b/arch/x86/xen/suspend.c
@@ -31,6 +31,7 @@ void xen_hvm_post_suspend(int suspend_cancelled)
31 int cpu; 31 int cpu;
32 xen_hvm_init_shared_info(); 32 xen_hvm_init_shared_info();
33 xen_callback_vector(); 33 xen_callback_vector();
34 xen_unplug_emulated_devices();
34 if (xen_feature(XENFEAT_hvm_safe_pvclock)) { 35 if (xen_feature(XENFEAT_hvm_safe_pvclock)) {
35 for_each_online_cpu(cpu) { 36 for_each_online_cpu(cpu) {
36 xen_setup_runstate_info(cpu); 37 xen_setup_runstate_info(cpu);
diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
index b2bb5aa3b054..5da5e53fb94c 100644
--- a/arch/x86/xen/time.c
+++ b/arch/x86/xen/time.c
@@ -426,6 +426,8 @@ void xen_timer_resume(void)
426{ 426{
427 int cpu; 427 int cpu;
428 428
429 pvclock_resume();
430
429 if (xen_clockevent != &xen_vcpuop_clockevent) 431 if (xen_clockevent != &xen_vcpuop_clockevent)
430 return; 432 return;
431 433
diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
index 64044747348e..9d41bf985757 100644
--- a/arch/x86/xen/xen-ops.h
+++ b/arch/x86/xen/xen-ops.h
@@ -43,7 +43,7 @@ void xen_vcpu_restore(void);
43 43
44void xen_callback_vector(void); 44void xen_callback_vector(void);
45void xen_hvm_init_shared_info(void); 45void xen_hvm_init_shared_info(void);
46void __init xen_unplug_emulated_devices(void); 46void xen_unplug_emulated_devices(void);
47 47
48void __init xen_build_dynamic_phys_to_machine(void); 48void __init xen_build_dynamic_phys_to_machine(void);
49 49
diff --git a/block/blk-core.c b/block/blk-core.c
index f0834e2f5727..4ce953f1b390 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1194,13 +1194,6 @@ static int __make_request(struct request_queue *q, struct bio *bio)
1194 int where = ELEVATOR_INSERT_SORT; 1194 int where = ELEVATOR_INSERT_SORT;
1195 int rw_flags; 1195 int rw_flags;
1196 1196
1197 /* REQ_HARDBARRIER is no more */
1198 if (WARN_ONCE(bio->bi_rw & REQ_HARDBARRIER,
1199 "block: HARDBARRIER is deprecated, use FLUSH/FUA instead\n")) {
1200 bio_endio(bio, -EOPNOTSUPP);
1201 return 0;
1202 }
1203
1204 /* 1197 /*
1205 * low level driver can indicate that it wants pages above a 1198 * low level driver can indicate that it wants pages above a
1206 * certain limit bounced to low memory (ie for highmem, or even 1199 * certain limit bounced to low memory (ie for highmem, or even
@@ -1351,7 +1344,7 @@ static void handle_bad_sector(struct bio *bio)
1351 bdevname(bio->bi_bdev, b), 1344 bdevname(bio->bi_bdev, b),
1352 bio->bi_rw, 1345 bio->bi_rw,
1353 (unsigned long long)bio->bi_sector + bio_sectors(bio), 1346 (unsigned long long)bio->bi_sector + bio_sectors(bio),
1354 (long long)(bio->bi_bdev->bd_inode->i_size >> 9)); 1347 (long long)(i_size_read(bio->bi_bdev->bd_inode) >> 9));
1355 1348
1356 set_bit(BIO_EOF, &bio->bi_flags); 1349 set_bit(BIO_EOF, &bio->bi_flags);
1357} 1350}
@@ -1404,7 +1397,7 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
1404 return 0; 1397 return 0;
1405 1398
1406 /* Test device or partition size, when known. */ 1399 /* Test device or partition size, when known. */
1407 maxsector = bio->bi_bdev->bd_inode->i_size >> 9; 1400 maxsector = i_size_read(bio->bi_bdev->bd_inode) >> 9;
1408 if (maxsector) { 1401 if (maxsector) {
1409 sector_t sector = bio->bi_sector; 1402 sector_t sector = bio->bi_sector;
1410 1403
diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index d22c4c55c406..3c7a339fe381 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -153,20 +153,6 @@ struct io_context *get_io_context(gfp_t gfp_flags, int node)
153} 153}
154EXPORT_SYMBOL(get_io_context); 154EXPORT_SYMBOL(get_io_context);
155 155
156void copy_io_context(struct io_context **pdst, struct io_context **psrc)
157{
158 struct io_context *src = *psrc;
159 struct io_context *dst = *pdst;
160
161 if (src) {
162 BUG_ON(atomic_long_read(&src->refcount) == 0);
163 atomic_long_inc(&src->refcount);
164 put_io_context(dst);
165 *pdst = src;
166 }
167}
168EXPORT_SYMBOL(copy_io_context);
169
170static int __init blk_ioc_init(void) 156static int __init blk_ioc_init(void)
171{ 157{
172 iocontext_cachep = kmem_cache_create("blkdev_ioc", 158 iocontext_cachep = kmem_cache_create("blkdev_ioc",
diff --git a/block/blk-map.c b/block/blk-map.c
index d4a586d8691e..e663ac2d8e68 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -201,6 +201,9 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
201 for (i = 0; i < iov_count; i++) { 201 for (i = 0; i < iov_count; i++) {
202 unsigned long uaddr = (unsigned long)iov[i].iov_base; 202 unsigned long uaddr = (unsigned long)iov[i].iov_base;
203 203
204 if (!iov[i].iov_len)
205 return -EINVAL;
206
204 if (uaddr & queue_dma_alignment(q)) { 207 if (uaddr & queue_dma_alignment(q)) {
205 unaligned = 1; 208 unaligned = 1;
206 break; 209 break;
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 77b7c26df6b5..74bc4a768f32 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -21,7 +21,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
21 return 0; 21 return 0;
22 22
23 fbio = bio; 23 fbio = bio;
24 cluster = test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags); 24 cluster = blk_queue_cluster(q);
25 seg_size = 0; 25 seg_size = 0;
26 nr_phys_segs = 0; 26 nr_phys_segs = 0;
27 for_each_bio(bio) { 27 for_each_bio(bio) {
@@ -87,7 +87,7 @@ EXPORT_SYMBOL(blk_recount_segments);
87static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio, 87static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
88 struct bio *nxt) 88 struct bio *nxt)
89{ 89{
90 if (!test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags)) 90 if (!blk_queue_cluster(q))
91 return 0; 91 return 0;
92 92
93 if (bio->bi_seg_back_size + nxt->bi_seg_front_size > 93 if (bio->bi_seg_back_size + nxt->bi_seg_front_size >
@@ -123,7 +123,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
123 int nsegs, cluster; 123 int nsegs, cluster;
124 124
125 nsegs = 0; 125 nsegs = 0;
126 cluster = test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags); 126 cluster = blk_queue_cluster(q);
127 127
128 /* 128 /*
129 * for each bio in rq 129 * for each bio in rq
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 701859fb9647..36c8c1f2af18 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -126,7 +126,7 @@ void blk_set_default_limits(struct queue_limits *lim)
126 lim->alignment_offset = 0; 126 lim->alignment_offset = 0;
127 lim->io_opt = 0; 127 lim->io_opt = 0;
128 lim->misaligned = 0; 128 lim->misaligned = 0;
129 lim->no_cluster = 0; 129 lim->cluster = 1;
130} 130}
131EXPORT_SYMBOL(blk_set_default_limits); 131EXPORT_SYMBOL(blk_set_default_limits);
132 132
@@ -229,8 +229,8 @@ void blk_queue_bounce_limit(struct request_queue *q, u64 dma_mask)
229EXPORT_SYMBOL(blk_queue_bounce_limit); 229EXPORT_SYMBOL(blk_queue_bounce_limit);
230 230
231/** 231/**
232 * blk_queue_max_hw_sectors - set max sectors for a request for this queue 232 * blk_limits_max_hw_sectors - set hard and soft limit of max sectors for request
233 * @q: the request queue for the device 233 * @limits: the queue limits
234 * @max_hw_sectors: max hardware sectors in the usual 512b unit 234 * @max_hw_sectors: max hardware sectors in the usual 512b unit
235 * 235 *
236 * Description: 236 * Description:
@@ -244,7 +244,7 @@ EXPORT_SYMBOL(blk_queue_bounce_limit);
244 * per-device basis in /sys/block/<device>/queue/max_sectors_kb. 244 * per-device basis in /sys/block/<device>/queue/max_sectors_kb.
245 * The soft limit can not exceed max_hw_sectors. 245 * The soft limit can not exceed max_hw_sectors.
246 **/ 246 **/
247void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors) 247void blk_limits_max_hw_sectors(struct queue_limits *limits, unsigned int max_hw_sectors)
248{ 248{
249 if ((max_hw_sectors << 9) < PAGE_CACHE_SIZE) { 249 if ((max_hw_sectors << 9) < PAGE_CACHE_SIZE) {
250 max_hw_sectors = 1 << (PAGE_CACHE_SHIFT - 9); 250 max_hw_sectors = 1 << (PAGE_CACHE_SHIFT - 9);
@@ -252,9 +252,23 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto
252 __func__, max_hw_sectors); 252 __func__, max_hw_sectors);
253 } 253 }
254 254
255 q->limits.max_hw_sectors = max_hw_sectors; 255 limits->max_hw_sectors = max_hw_sectors;
256 q->limits.max_sectors = min_t(unsigned int, max_hw_sectors, 256 limits->max_sectors = min_t(unsigned int, max_hw_sectors,
257 BLK_DEF_MAX_SECTORS); 257 BLK_DEF_MAX_SECTORS);
258}
259EXPORT_SYMBOL(blk_limits_max_hw_sectors);
260
261/**
262 * blk_queue_max_hw_sectors - set max sectors for a request for this queue
263 * @q: the request queue for the device
264 * @max_hw_sectors: max hardware sectors in the usual 512b unit
265 *
266 * Description:
267 * See description for blk_limits_max_hw_sectors().
268 **/
269void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
270{
271 blk_limits_max_hw_sectors(&q->limits, max_hw_sectors);
258} 272}
259EXPORT_SYMBOL(blk_queue_max_hw_sectors); 273EXPORT_SYMBOL(blk_queue_max_hw_sectors);
260 274
@@ -464,15 +478,6 @@ EXPORT_SYMBOL(blk_queue_io_opt);
464void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b) 478void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
465{ 479{
466 blk_stack_limits(&t->limits, &b->limits, 0); 480 blk_stack_limits(&t->limits, &b->limits, 0);
467
468 if (!t->queue_lock)
469 WARN_ON_ONCE(1);
470 else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
471 unsigned long flags;
472 spin_lock_irqsave(t->queue_lock, flags);
473 queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
474 spin_unlock_irqrestore(t->queue_lock, flags);
475 }
476} 481}
477EXPORT_SYMBOL(blk_queue_stack_limits); 482EXPORT_SYMBOL(blk_queue_stack_limits);
478 483
@@ -545,7 +550,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
545 t->io_min = max(t->io_min, b->io_min); 550 t->io_min = max(t->io_min, b->io_min);
546 t->io_opt = lcm(t->io_opt, b->io_opt); 551 t->io_opt = lcm(t->io_opt, b->io_opt);
547 552
548 t->no_cluster |= b->no_cluster; 553 t->cluster &= b->cluster;
549 t->discard_zeroes_data &= b->discard_zeroes_data; 554 t->discard_zeroes_data &= b->discard_zeroes_data;
550 555
551 /* Physical block size a multiple of the logical block size? */ 556 /* Physical block size a multiple of the logical block size? */
@@ -641,7 +646,6 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
641 sector_t offset) 646 sector_t offset)
642{ 647{
643 struct request_queue *t = disk->queue; 648 struct request_queue *t = disk->queue;
644 struct request_queue *b = bdev_get_queue(bdev);
645 649
646 if (bdev_stack_limits(&t->limits, bdev, offset >> 9) < 0) { 650 if (bdev_stack_limits(&t->limits, bdev, offset >> 9) < 0) {
647 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE]; 651 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
@@ -652,17 +656,6 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
652 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n", 656 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
653 top, bottom); 657 top, bottom);
654 } 658 }
655
656 if (!t->queue_lock)
657 WARN_ON_ONCE(1);
658 else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
659 unsigned long flags;
660
661 spin_lock_irqsave(t->queue_lock, flags);
662 if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags))
663 queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
664 spin_unlock_irqrestore(t->queue_lock, flags);
665 }
666} 659}
667EXPORT_SYMBOL(disk_stack_limits); 660EXPORT_SYMBOL(disk_stack_limits);
668 661
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 013457f47fdc..41fb69150b4d 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -119,7 +119,7 @@ static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *
119 119
120static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page) 120static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page)
121{ 121{
122 if (test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags)) 122 if (blk_queue_cluster(q))
123 return queue_var_show(queue_max_segment_size(q), (page)); 123 return queue_var_show(queue_max_segment_size(q), (page));
124 124
125 return queue_var_show(PAGE_CACHE_SIZE, (page)); 125 return queue_var_show(PAGE_CACHE_SIZE, (page));
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 56ad4531b412..381b09bb562b 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -355,6 +355,12 @@ throtl_start_new_slice(struct throtl_data *td, struct throtl_grp *tg, bool rw)
355 tg->slice_end[rw], jiffies); 355 tg->slice_end[rw], jiffies);
356} 356}
357 357
358static inline void throtl_set_slice_end(struct throtl_data *td,
359 struct throtl_grp *tg, bool rw, unsigned long jiffy_end)
360{
361 tg->slice_end[rw] = roundup(jiffy_end, throtl_slice);
362}
363
358static inline void throtl_extend_slice(struct throtl_data *td, 364static inline void throtl_extend_slice(struct throtl_data *td,
359 struct throtl_grp *tg, bool rw, unsigned long jiffy_end) 365 struct throtl_grp *tg, bool rw, unsigned long jiffy_end)
360{ 366{
@@ -391,6 +397,16 @@ throtl_trim_slice(struct throtl_data *td, struct throtl_grp *tg, bool rw)
391 if (throtl_slice_used(td, tg, rw)) 397 if (throtl_slice_used(td, tg, rw))
392 return; 398 return;
393 399
400 /*
401 * A bio has been dispatched. Also adjust slice_end. It might happen
402 * that initially cgroup limit was very low resulting in high
403 * slice_end, but later limit was bumped up and bio was dispached
404 * sooner, then we need to reduce slice_end. A high bogus slice_end
405 * is bad because it does not allow new slice to start.
406 */
407
408 throtl_set_slice_end(td, tg, rw, jiffies + throtl_slice);
409
394 time_elapsed = jiffies - tg->slice_start[rw]; 410 time_elapsed = jiffies - tg->slice_start[rw];
395 411
396 nr_slices = time_elapsed / throtl_slice; 412 nr_slices = time_elapsed / throtl_slice;
@@ -645,7 +661,7 @@ static int throtl_dispatch_tg(struct throtl_data *td, struct throtl_grp *tg,
645{ 661{
646 unsigned int nr_reads = 0, nr_writes = 0; 662 unsigned int nr_reads = 0, nr_writes = 0;
647 unsigned int max_nr_reads = throtl_grp_quantum*3/4; 663 unsigned int max_nr_reads = throtl_grp_quantum*3/4;
648 unsigned int max_nr_writes = throtl_grp_quantum - nr_reads; 664 unsigned int max_nr_writes = throtl_grp_quantum - max_nr_reads;
649 struct bio *bio; 665 struct bio *bio;
650 666
651 /* Try to dispatch 75% READS and 25% WRITES */ 667 /* Try to dispatch 75% READS and 25% WRITES */
@@ -709,26 +725,21 @@ static void throtl_process_limit_change(struct throtl_data *td)
709 struct throtl_grp *tg; 725 struct throtl_grp *tg;
710 struct hlist_node *pos, *n; 726 struct hlist_node *pos, *n;
711 727
712 /*
713 * Make sure atomic_inc() effects from
714 * throtl_update_blkio_group_read_bps(), group of functions are
715 * visible.
716 * Is this required or smp_mb__after_atomic_inc() was suffcient
717 * after the atomic_inc().
718 */
719 smp_rmb();
720 if (!atomic_read(&td->limits_changed)) 728 if (!atomic_read(&td->limits_changed))
721 return; 729 return;
722 730
723 throtl_log(td, "limit changed =%d", atomic_read(&td->limits_changed)); 731 throtl_log(td, "limit changed =%d", atomic_read(&td->limits_changed));
724 732
725 hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) { 733 /*
726 /* 734 * Make sure updates from throtl_update_blkio_group_read_bps() group
727 * Do I need an smp_rmb() here to make sure tg->limits_changed 735 * of functions to tg->limits_changed are visible. We do not
728 * update is visible. I am relying on smp_rmb() at the 736 * want update td->limits_changed to be visible but update to
729 * beginning of function and not putting a new one here. 737 * tg->limits_changed not being visible yet on this cpu. Hence
730 */ 738 * the read barrier.
739 */
740 smp_rmb();
731 741
742 hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
732 if (throtl_tg_on_rr(tg) && tg->limits_changed) { 743 if (throtl_tg_on_rr(tg) && tg->limits_changed) {
733 throtl_log_tg(td, tg, "limit change rbps=%llu wbps=%llu" 744 throtl_log_tg(td, tg, "limit change rbps=%llu wbps=%llu"
734 " riops=%u wiops=%u", tg->bps[READ], 745 " riops=%u wiops=%u", tg->bps[READ],
diff --git a/block/bsg.c b/block/bsg.c
index f20d6a789d48..0c8b64a16484 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -250,6 +250,14 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
250 int ret, rw; 250 int ret, rw;
251 unsigned int dxfer_len; 251 unsigned int dxfer_len;
252 void *dxferp = NULL; 252 void *dxferp = NULL;
253 struct bsg_class_device *bcd = &q->bsg_dev;
254
255 /* if the LLD has been removed then the bsg_unregister_queue will
256 * eventually be called and the class_dev was freed, so we can no
257 * longer use this request_queue. Return no such address.
258 */
259 if (!bcd->class_dev)
260 return ERR_PTR(-ENXIO);
253 261
254 dprintk("map hdr %llx/%u %llx/%u\n", (unsigned long long) hdr->dout_xferp, 262 dprintk("map hdr %llx/%u %llx/%u\n", (unsigned long long) hdr->dout_xferp,
255 hdr->dout_xfer_len, (unsigned long long) hdr->din_xferp, 263 hdr->dout_xfer_len, (unsigned long long) hdr->din_xferp,
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index 119f07b74dc0..cc3eb78e333a 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -8,7 +8,6 @@
8#include <linux/hdreg.h> 8#include <linux/hdreg.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/syscalls.h> 10#include <linux/syscalls.h>
11#include <linux/smp_lock.h>
12#include <linux/types.h> 11#include <linux/types.h>
13#include <linux/uaccess.h> 12#include <linux/uaccess.h>
14 13
@@ -744,13 +743,13 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
744 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE; 743 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
745 return 0; 744 return 0;
746 case BLKGETSIZE: 745 case BLKGETSIZE:
747 size = bdev->bd_inode->i_size; 746 size = i_size_read(bdev->bd_inode);
748 if ((size >> 9) > ~0UL) 747 if ((size >> 9) > ~0UL)
749 return -EFBIG; 748 return -EFBIG;
750 return compat_put_ulong(arg, size >> 9); 749 return compat_put_ulong(arg, size >> 9);
751 750
752 case BLKGETSIZE64_32: 751 case BLKGETSIZE64_32:
753 return compat_put_u64(arg, bdev->bd_inode->i_size); 752 return compat_put_u64(arg, i_size_read(bdev->bd_inode));
754 753
755 case BLKTRACESETUP32: 754 case BLKTRACESETUP32:
756 case BLKTRACESTART: /* compatible */ 755 case BLKTRACESTART: /* compatible */
diff --git a/block/elevator.c b/block/elevator.c
index 282e8308f7e2..2569512830d3 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -429,7 +429,7 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq)
429 q->nr_sorted--; 429 q->nr_sorted--;
430 430
431 boundary = q->end_sector; 431 boundary = q->end_sector;
432 stop_flags = REQ_SOFTBARRIER | REQ_HARDBARRIER | REQ_STARTED; 432 stop_flags = REQ_SOFTBARRIER | REQ_STARTED;
433 list_for_each_prev(entry, &q->queue_head) { 433 list_for_each_prev(entry, &q->queue_head) {
434 struct request *pos = list_entry_rq(entry); 434 struct request *pos = list_entry_rq(entry);
435 435
@@ -691,7 +691,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
691void __elv_add_request(struct request_queue *q, struct request *rq, int where, 691void __elv_add_request(struct request_queue *q, struct request *rq, int where,
692 int plug) 692 int plug)
693{ 693{
694 if (rq->cmd_flags & (REQ_SOFTBARRIER | REQ_HARDBARRIER)) { 694 if (rq->cmd_flags & REQ_SOFTBARRIER) {
695 /* barriers are scheduling boundary, update end_sector */ 695 /* barriers are scheduling boundary, update end_sector */
696 if (rq->cmd_type == REQ_TYPE_FS || 696 if (rq->cmd_type == REQ_TYPE_FS ||
697 (rq->cmd_flags & REQ_DISCARD)) { 697 (rq->cmd_flags & REQ_DISCARD)) {
diff --git a/block/ioctl.c b/block/ioctl.c
index d724ceb1d465..a9a302eba01e 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -5,7 +5,6 @@
5#include <linux/hdreg.h> 5#include <linux/hdreg.h>
6#include <linux/backing-dev.h> 6#include <linux/backing-dev.h>
7#include <linux/buffer_head.h> 7#include <linux/buffer_head.h>
8#include <linux/smp_lock.h>
9#include <linux/blktrace_api.h> 8#include <linux/blktrace_api.h>
10#include <asm/uaccess.h> 9#include <asm/uaccess.h>
11 10
@@ -125,7 +124,7 @@ static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
125 start >>= 9; 124 start >>= 9;
126 len >>= 9; 125 len >>= 9;
127 126
128 if (start + len > (bdev->bd_inode->i_size >> 9)) 127 if (start + len > (i_size_read(bdev->bd_inode) >> 9))
129 return -EINVAL; 128 return -EINVAL;
130 if (secure) 129 if (secure)
131 flags |= BLKDEV_DISCARD_SECURE; 130 flags |= BLKDEV_DISCARD_SECURE;
@@ -242,6 +241,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
242 * We need to set the startsect first, the driver may 241 * We need to set the startsect first, the driver may
243 * want to override it. 242 * want to override it.
244 */ 243 */
244 memset(&geo, 0, sizeof(geo));
245 geo.start = get_start_sect(bdev); 245 geo.start = get_start_sect(bdev);
246 ret = disk->fops->getgeo(bdev, &geo); 246 ret = disk->fops->getgeo(bdev, &geo);
247 if (ret) 247 if (ret)
@@ -307,12 +307,12 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
307 ret = blkdev_reread_part(bdev); 307 ret = blkdev_reread_part(bdev);
308 break; 308 break;
309 case BLKGETSIZE: 309 case BLKGETSIZE:
310 size = bdev->bd_inode->i_size; 310 size = i_size_read(bdev->bd_inode);
311 if ((size >> 9) > ~0UL) 311 if ((size >> 9) > ~0UL)
312 return -EFBIG; 312 return -EFBIG;
313 return put_ulong(arg, size >> 9); 313 return put_ulong(arg, size >> 9);
314 case BLKGETSIZE64: 314 case BLKGETSIZE64:
315 return put_u64(arg, bdev->bd_inode->i_size); 315 return put_u64(arg, i_size_read(bdev->bd_inode));
316 case BLKTRACESTART: 316 case BLKTRACESTART:
317 case BLKTRACESTOP: 317 case BLKTRACESTOP:
318 case BLKTRACESETUP: 318 case BLKTRACESETUP:
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index a8b5a10eb5b0..4f4230b79bb6 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -321,33 +321,47 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
321 if (hdr->iovec_count) { 321 if (hdr->iovec_count) {
322 const int size = sizeof(struct sg_iovec) * hdr->iovec_count; 322 const int size = sizeof(struct sg_iovec) * hdr->iovec_count;
323 size_t iov_data_len; 323 size_t iov_data_len;
324 struct sg_iovec *iov; 324 struct sg_iovec *sg_iov;
325 struct iovec *iov;
326 int i;
325 327
326 iov = kmalloc(size, GFP_KERNEL); 328 sg_iov = kmalloc(size, GFP_KERNEL);
327 if (!iov) { 329 if (!sg_iov) {
328 ret = -ENOMEM; 330 ret = -ENOMEM;
329 goto out; 331 goto out;
330 } 332 }
331 333
332 if (copy_from_user(iov, hdr->dxferp, size)) { 334 if (copy_from_user(sg_iov, hdr->dxferp, size)) {
333 kfree(iov); 335 kfree(sg_iov);
334 ret = -EFAULT; 336 ret = -EFAULT;
335 goto out; 337 goto out;
336 } 338 }
337 339
340 /*
341 * Sum up the vecs, making sure they don't overflow
342 */
343 iov = (struct iovec *) sg_iov;
344 iov_data_len = 0;
345 for (i = 0; i < hdr->iovec_count; i++) {
346 if (iov_data_len + iov[i].iov_len < iov_data_len) {
347 kfree(sg_iov);
348 ret = -EINVAL;
349 goto out;
350 }
351 iov_data_len += iov[i].iov_len;
352 }
353
338 /* SG_IO howto says that the shorter of the two wins */ 354 /* SG_IO howto says that the shorter of the two wins */
339 iov_data_len = iov_length((struct iovec *)iov,
340 hdr->iovec_count);
341 if (hdr->dxfer_len < iov_data_len) { 355 if (hdr->dxfer_len < iov_data_len) {
342 hdr->iovec_count = iov_shorten((struct iovec *)iov, 356 hdr->iovec_count = iov_shorten(iov,
343 hdr->iovec_count, 357 hdr->iovec_count,
344 hdr->dxfer_len); 358 hdr->dxfer_len);
345 iov_data_len = hdr->dxfer_len; 359 iov_data_len = hdr->dxfer_len;
346 } 360 }
347 361
348 ret = blk_rq_map_user_iov(q, rq, NULL, iov, hdr->iovec_count, 362 ret = blk_rq_map_user_iov(q, rq, NULL, sg_iov, hdr->iovec_count,
349 iov_data_len, GFP_KERNEL); 363 iov_data_len, GFP_KERNEL);
350 kfree(iov); 364 kfree(sg_iov);
351 } else if (hdr->dxfer_len) 365 } else if (hdr->dxfer_len)
352 ret = blk_rq_map_user(q, rq, NULL, hdr->dxferp, hdr->dxfer_len, 366 ret = blk_rq_map_user(q, rq, NULL, hdr->dxferp, hdr->dxfer_len,
353 GFP_KERNEL); 367 GFP_KERNEL);
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index de3078215fe6..75586f1f86e7 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -504,7 +504,6 @@ err:
504 504
505static void pcrypt_fini_padata(struct padata_pcrypt *pcrypt) 505static void pcrypt_fini_padata(struct padata_pcrypt *pcrypt)
506{ 506{
507 kobject_put(&pcrypt->pinst->kobj);
508 free_cpumask_var(pcrypt->cb_cpumask->mask); 507 free_cpumask_var(pcrypt->cb_cpumask->mask);
509 kfree(pcrypt->cb_cpumask); 508 kfree(pcrypt->cb_cpumask);
510 509
diff --git a/drivers/Makefile b/drivers/Makefile
index 14cf9077bb2b..f3ebb30f1b7f 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_REGULATOR) += regulator/
26 26
27# char/ comes before serial/ etc so that the VT console is the boot-time 27# char/ comes before serial/ etc so that the VT console is the boot-time
28# default. 28# default.
29obj-y += tty/
29obj-y += char/ 30obj-y += char/
30 31
31# gpu/ comes after char for AGP vs DRM startup 32# gpu/ comes after char for AGP vs DRM startup
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index ba9afeaa23ac..25d3aaebc10d 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -100,24 +100,7 @@ static const struct file_operations acpi_ac_fops = {
100 .release = single_release, 100 .release = single_release,
101}; 101};
102#endif 102#endif
103static int get_ac_property(struct power_supply *psy,
104 enum power_supply_property psp,
105 union power_supply_propval *val)
106{
107 struct acpi_ac *ac = to_acpi_ac(psy);
108 switch (psp) {
109 case POWER_SUPPLY_PROP_ONLINE:
110 val->intval = ac->state;
111 break;
112 default:
113 return -EINVAL;
114 }
115 return 0;
116}
117 103
118static enum power_supply_property ac_props[] = {
119 POWER_SUPPLY_PROP_ONLINE,
120};
121/* -------------------------------------------------------------------------- 104/* --------------------------------------------------------------------------
122 AC Adapter Management 105 AC Adapter Management
123 -------------------------------------------------------------------------- */ 106 -------------------------------------------------------------------------- */
@@ -140,6 +123,35 @@ static int acpi_ac_get_state(struct acpi_ac *ac)
140 return 0; 123 return 0;
141} 124}
142 125
126/* --------------------------------------------------------------------------
127 sysfs I/F
128 -------------------------------------------------------------------------- */
129static int get_ac_property(struct power_supply *psy,
130 enum power_supply_property psp,
131 union power_supply_propval *val)
132{
133 struct acpi_ac *ac = to_acpi_ac(psy);
134
135 if (!ac)
136 return -ENODEV;
137
138 if (acpi_ac_get_state(ac))
139 return -ENODEV;
140
141 switch (psp) {
142 case POWER_SUPPLY_PROP_ONLINE:
143 val->intval = ac->state;
144 break;
145 default:
146 return -EINVAL;
147 }
148 return 0;
149}
150
151static enum power_supply_property ac_props[] = {
152 POWER_SUPPLY_PROP_ONLINE,
153};
154
143#ifdef CONFIG_ACPI_PROCFS_POWER 155#ifdef CONFIG_ACPI_PROCFS_POWER
144/* -------------------------------------------------------------------------- 156/* --------------------------------------------------------------------------
145 FS Interface (/proc) 157 FS Interface (/proc)
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 1211c03149e8..5850d320404c 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -86,7 +86,7 @@ static struct erst_erange {
86 * It is used to provide exclusive accessing for ERST Error Log 86 * It is used to provide exclusive accessing for ERST Error Log
87 * Address Range too. 87 * Address Range too.
88 */ 88 */
89static DEFINE_SPINLOCK(erst_lock); 89static DEFINE_RAW_SPINLOCK(erst_lock);
90 90
91static inline int erst_errno(int command_status) 91static inline int erst_errno(int command_status)
92{ 92{
@@ -421,9 +421,9 @@ ssize_t erst_get_record_count(void)
421 if (erst_disable) 421 if (erst_disable)
422 return -ENODEV; 422 return -ENODEV;
423 423
424 spin_lock_irqsave(&erst_lock, flags); 424 raw_spin_lock_irqsave(&erst_lock, flags);
425 count = __erst_get_record_count(); 425 count = __erst_get_record_count();
426 spin_unlock_irqrestore(&erst_lock, flags); 426 raw_spin_unlock_irqrestore(&erst_lock, flags);
427 427
428 return count; 428 return count;
429} 429}
@@ -456,9 +456,9 @@ int erst_get_next_record_id(u64 *record_id)
456 if (erst_disable) 456 if (erst_disable)
457 return -ENODEV; 457 return -ENODEV;
458 458
459 spin_lock_irqsave(&erst_lock, flags); 459 raw_spin_lock_irqsave(&erst_lock, flags);
460 rc = __erst_get_next_record_id(record_id); 460 rc = __erst_get_next_record_id(record_id);
461 spin_unlock_irqrestore(&erst_lock, flags); 461 raw_spin_unlock_irqrestore(&erst_lock, flags);
462 462
463 return rc; 463 return rc;
464} 464}
@@ -624,17 +624,17 @@ int erst_write(const struct cper_record_header *record)
624 return -EINVAL; 624 return -EINVAL;
625 625
626 if (erst_erange.attr & ERST_RANGE_NVRAM) { 626 if (erst_erange.attr & ERST_RANGE_NVRAM) {
627 if (!spin_trylock_irqsave(&erst_lock, flags)) 627 if (!raw_spin_trylock_irqsave(&erst_lock, flags))
628 return -EBUSY; 628 return -EBUSY;
629 rc = __erst_write_to_nvram(record); 629 rc = __erst_write_to_nvram(record);
630 spin_unlock_irqrestore(&erst_lock, flags); 630 raw_spin_unlock_irqrestore(&erst_lock, flags);
631 return rc; 631 return rc;
632 } 632 }
633 633
634 if (record->record_length > erst_erange.size) 634 if (record->record_length > erst_erange.size)
635 return -EINVAL; 635 return -EINVAL;
636 636
637 if (!spin_trylock_irqsave(&erst_lock, flags)) 637 if (!raw_spin_trylock_irqsave(&erst_lock, flags))
638 return -EBUSY; 638 return -EBUSY;
639 memcpy(erst_erange.vaddr, record, record->record_length); 639 memcpy(erst_erange.vaddr, record, record->record_length);
640 rcd_erange = erst_erange.vaddr; 640 rcd_erange = erst_erange.vaddr;
@@ -642,7 +642,7 @@ int erst_write(const struct cper_record_header *record)
642 memcpy(&rcd_erange->persistence_information, "ER", 2); 642 memcpy(&rcd_erange->persistence_information, "ER", 2);
643 643
644 rc = __erst_write_to_storage(0); 644 rc = __erst_write_to_storage(0);
645 spin_unlock_irqrestore(&erst_lock, flags); 645 raw_spin_unlock_irqrestore(&erst_lock, flags);
646 646
647 return rc; 647 return rc;
648} 648}
@@ -696,9 +696,9 @@ ssize_t erst_read(u64 record_id, struct cper_record_header *record,
696 if (erst_disable) 696 if (erst_disable)
697 return -ENODEV; 697 return -ENODEV;
698 698
699 spin_lock_irqsave(&erst_lock, flags); 699 raw_spin_lock_irqsave(&erst_lock, flags);
700 len = __erst_read(record_id, record, buflen); 700 len = __erst_read(record_id, record, buflen);
701 spin_unlock_irqrestore(&erst_lock, flags); 701 raw_spin_unlock_irqrestore(&erst_lock, flags);
702 return len; 702 return len;
703} 703}
704EXPORT_SYMBOL_GPL(erst_read); 704EXPORT_SYMBOL_GPL(erst_read);
@@ -719,20 +719,20 @@ ssize_t erst_read_next(struct cper_record_header *record, size_t buflen)
719 if (erst_disable) 719 if (erst_disable)
720 return -ENODEV; 720 return -ENODEV;
721 721
722 spin_lock_irqsave(&erst_lock, flags); 722 raw_spin_lock_irqsave(&erst_lock, flags);
723 rc = __erst_get_next_record_id(&record_id); 723 rc = __erst_get_next_record_id(&record_id);
724 if (rc) { 724 if (rc) {
725 spin_unlock_irqrestore(&erst_lock, flags); 725 raw_spin_unlock_irqrestore(&erst_lock, flags);
726 return rc; 726 return rc;
727 } 727 }
728 /* no more record */ 728 /* no more record */
729 if (record_id == APEI_ERST_INVALID_RECORD_ID) { 729 if (record_id == APEI_ERST_INVALID_RECORD_ID) {
730 spin_unlock_irqrestore(&erst_lock, flags); 730 raw_spin_unlock_irqrestore(&erst_lock, flags);
731 return 0; 731 return 0;
732 } 732 }
733 733
734 len = __erst_read(record_id, record, buflen); 734 len = __erst_read(record_id, record, buflen);
735 spin_unlock_irqrestore(&erst_lock, flags); 735 raw_spin_unlock_irqrestore(&erst_lock, flags);
736 736
737 return len; 737 return len;
738} 738}
@@ -746,12 +746,12 @@ int erst_clear(u64 record_id)
746 if (erst_disable) 746 if (erst_disable)
747 return -ENODEV; 747 return -ENODEV;
748 748
749 spin_lock_irqsave(&erst_lock, flags); 749 raw_spin_lock_irqsave(&erst_lock, flags);
750 if (erst_erange.attr & ERST_RANGE_NVRAM) 750 if (erst_erange.attr & ERST_RANGE_NVRAM)
751 rc = __erst_clear_from_nvram(record_id); 751 rc = __erst_clear_from_nvram(record_id);
752 else 752 else
753 rc = __erst_clear_from_storage(record_id); 753 rc = __erst_clear_from_storage(record_id);
754 spin_unlock_irqrestore(&erst_lock, flags); 754 raw_spin_unlock_irqrestore(&erst_lock, flags);
755 755
756 return rc; 756 return rc;
757} 757}
diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c
index 1a3508a7fe03..daa7bc63f1d4 100644
--- a/drivers/acpi/apei/hest.c
+++ b/drivers/acpi/apei/hest.c
@@ -46,9 +46,9 @@ EXPORT_SYMBOL_GPL(hest_disable);
46 46
47/* HEST table parsing */ 47/* HEST table parsing */
48 48
49static struct acpi_table_hest *hest_tab; 49static struct acpi_table_hest *__read_mostly hest_tab;
50 50
51static int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = { 51static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
52 [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */ 52 [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */
53 [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1, 53 [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
54 [ACPI_HEST_TYPE_IA32_NMI] = sizeof(struct acpi_hest_ia_nmi), 54 [ACPI_HEST_TYPE_IA32_NMI] = sizeof(struct acpi_hest_ia_nmi),
@@ -126,7 +126,7 @@ struct ghes_arr {
126 unsigned int count; 126 unsigned int count;
127}; 127};
128 128
129static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) 129static int __init hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
130{ 130{
131 int *count = data; 131 int *count = data;
132 132
@@ -135,7 +135,7 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
135 return 0; 135 return 0;
136} 136}
137 137
138static int hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data) 138static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
139{ 139{
140 struct platform_device *ghes_dev; 140 struct platform_device *ghes_dev;
141 struct ghes_arr *ghes_arr = data; 141 struct ghes_arr *ghes_arr = data;
@@ -165,7 +165,7 @@ err:
165 return rc; 165 return rc;
166} 166}
167 167
168static int hest_ghes_dev_register(unsigned int ghes_count) 168static int __init hest_ghes_dev_register(unsigned int ghes_count)
169{ 169{
170 int rc, i; 170 int rc, i;
171 struct ghes_arr ghes_arr; 171 struct ghes_arr ghes_arr;
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 95649d373071..9fb9d5ac939d 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -130,6 +130,8 @@ struct acpi_battery {
130 unsigned long flags; 130 unsigned long flags;
131}; 131};
132 132
133static int acpi_battery_update(struct acpi_battery *battery);
134
133#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat); 135#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
134 136
135inline int acpi_battery_present(struct acpi_battery *battery) 137inline int acpi_battery_present(struct acpi_battery *battery)
@@ -184,6 +186,9 @@ static int acpi_battery_get_property(struct power_supply *psy,
184 int ret = 0; 186 int ret = 0;
185 struct acpi_battery *battery = to_acpi_battery(psy); 187 struct acpi_battery *battery = to_acpi_battery(psy);
186 188
189 if (acpi_battery_update(battery))
190 return -ENODEV;
191
187 if (acpi_battery_present(battery)) { 192 if (acpi_battery_present(battery)) {
188 /* run battery update only if it is present */ 193 /* run battery update only if it is present */
189 acpi_battery_get_state(battery); 194 acpi_battery_get_state(battery);
diff --git a/drivers/acpi/debugfs.c b/drivers/acpi/debugfs.c
index 6355b575ee5a..5df67f1d6c61 100644
--- a/drivers/acpi/debugfs.c
+++ b/drivers/acpi/debugfs.c
@@ -80,7 +80,7 @@ int __init acpi_debugfs_init(void)
80 if (!acpi_dir) 80 if (!acpi_dir)
81 goto err; 81 goto err;
82 82
83 cm_dentry = debugfs_create_file("custom_method", S_IWUGO, 83 cm_dentry = debugfs_create_file("custom_method", S_IWUSR,
84 acpi_dir, NULL, &cm_fops); 84 acpi_dir, NULL, &cm_fops);
85 if (!cm_dentry) 85 if (!cm_dentry)
86 goto err; 86 goto err;
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 372ff80b7b0c..302b31ed31f1 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -934,6 +934,9 @@ static struct dmi_system_id __initdata ec_dmi_table[] = {
934 ec_flag_msi, "MSI hardware", { 934 ec_flag_msi, "MSI hardware", {
935 DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-Star")}, NULL}, 935 DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-Star")}, NULL},
936 { 936 {
937 ec_flag_msi, "MSI hardware", {
938 DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR")}, NULL},
939 {
937 ec_validate_ecdt, "ASUS hardware", { 940 ec_validate_ecdt, "ASUS hardware", {
938 DMI_MATCH(DMI_BIOS_VENDOR, "ASUS") }, NULL}, 941 DMI_MATCH(DMI_BIOS_VENDOR, "ASUS") }, NULL},
939 {}, 942 {},
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 966feddf6b1b..055d7b701fff 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -110,9 +110,6 @@ struct acpi_ioremap {
110static LIST_HEAD(acpi_ioremaps); 110static LIST_HEAD(acpi_ioremaps);
111static DEFINE_SPINLOCK(acpi_ioremap_lock); 111static DEFINE_SPINLOCK(acpi_ioremap_lock);
112 112
113#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
114static char osi_setup_string[OSI_STRING_LENGTH_MAX];
115
116static void __init acpi_osi_setup_late(void); 113static void __init acpi_osi_setup_late(void);
117 114
118/* 115/*
@@ -152,8 +149,7 @@ static struct osi_linux {
152 unsigned int enable:1; 149 unsigned int enable:1;
153 unsigned int dmi:1; 150 unsigned int dmi:1;
154 unsigned int cmdline:1; 151 unsigned int cmdline:1;
155 unsigned int known:1; 152} osi_linux = {0, 0, 0};
156} osi_linux = { 0, 0, 0, 0};
157 153
158static u32 acpi_osi_handler(acpi_string interface, u32 supported) 154static u32 acpi_osi_handler(acpi_string interface, u32 supported)
159{ 155{
@@ -1055,13 +1051,53 @@ static int __init acpi_os_name_setup(char *str)
1055 1051
1056__setup("acpi_os_name=", acpi_os_name_setup); 1052__setup("acpi_os_name=", acpi_os_name_setup);
1057 1053
1054#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
1055#define OSI_STRING_ENTRIES_MAX 16 /* arbitrary */
1056
1057struct osi_setup_entry {
1058 char string[OSI_STRING_LENGTH_MAX];
1059 bool enable;
1060};
1061
1062static struct osi_setup_entry __initdata osi_setup_entries[OSI_STRING_ENTRIES_MAX];
1063
1064void __init acpi_osi_setup(char *str)
1065{
1066 struct osi_setup_entry *osi;
1067 bool enable = true;
1068 int i;
1069
1070 if (!acpi_gbl_create_osi_method)
1071 return;
1072
1073 if (str == NULL || *str == '\0') {
1074 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1075 acpi_gbl_create_osi_method = FALSE;
1076 return;
1077 }
1078
1079 if (*str == '!') {
1080 str++;
1081 enable = false;
1082 }
1083
1084 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1085 osi = &osi_setup_entries[i];
1086 if (!strcmp(osi->string, str)) {
1087 osi->enable = enable;
1088 break;
1089 } else if (osi->string[0] == '\0') {
1090 osi->enable = enable;
1091 strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
1092 break;
1093 }
1094 }
1095}
1096
1058static void __init set_osi_linux(unsigned int enable) 1097static void __init set_osi_linux(unsigned int enable)
1059{ 1098{
1060 if (osi_linux.enable != enable) { 1099 if (osi_linux.enable != enable)
1061 osi_linux.enable = enable; 1100 osi_linux.enable = enable;
1062 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1063 enable ? "Add": "Delet");
1064 }
1065 1101
1066 if (osi_linux.enable) 1102 if (osi_linux.enable)
1067 acpi_osi_setup("Linux"); 1103 acpi_osi_setup("Linux");
@@ -1073,7 +1109,8 @@ static void __init set_osi_linux(unsigned int enable)
1073 1109
1074static void __init acpi_cmdline_osi_linux(unsigned int enable) 1110static void __init acpi_cmdline_osi_linux(unsigned int enable)
1075{ 1111{
1076 osi_linux.cmdline = 1; /* cmdline set the default */ 1112 osi_linux.cmdline = 1; /* cmdline set the default and override DMI */
1113 osi_linux.dmi = 0;
1077 set_osi_linux(enable); 1114 set_osi_linux(enable);
1078 1115
1079 return; 1116 return;
@@ -1081,15 +1118,12 @@ static void __init acpi_cmdline_osi_linux(unsigned int enable)
1081 1118
1082void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d) 1119void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1083{ 1120{
1084 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1085
1086 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident); 1121 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1087 1122
1088 if (enable == -1) 1123 if (enable == -1)
1089 return; 1124 return;
1090 1125
1091 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */ 1126 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1092
1093 set_osi_linux(enable); 1127 set_osi_linux(enable);
1094 1128
1095 return; 1129 return;
@@ -1104,37 +1138,44 @@ void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1104 */ 1138 */
1105static void __init acpi_osi_setup_late(void) 1139static void __init acpi_osi_setup_late(void)
1106{ 1140{
1107 char *str = osi_setup_string; 1141 struct osi_setup_entry *osi;
1142 char *str;
1143 int i;
1144 acpi_status status;
1108 1145
1109 if (*str == '\0') 1146 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
1110 return; 1147 osi = &osi_setup_entries[i];
1148 str = osi->string;
1111 1149
1112 if (!strcmp("!Linux", str)) { 1150 if (*str == '\0')
1113 acpi_cmdline_osi_linux(0); /* !enable */ 1151 break;
1114 } else if (*str == '!') { 1152 if (osi->enable) {
1115 if (acpi_remove_interface(++str) == AE_OK) 1153 status = acpi_install_interface(str);
1116 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str); 1154
1117 } else if (!strcmp("Linux", str)) { 1155 if (ACPI_SUCCESS(status))
1118 acpi_cmdline_osi_linux(1); /* enable */ 1156 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1119 } else { 1157 } else {
1120 if (acpi_install_interface(str) == AE_OK) 1158 status = acpi_remove_interface(str);
1121 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str); 1159
1160 if (ACPI_SUCCESS(status))
1161 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
1162 }
1122 } 1163 }
1123} 1164}
1124 1165
1125int __init acpi_osi_setup(char *str) 1166static int __init osi_setup(char *str)
1126{ 1167{
1127 if (str == NULL || *str == '\0') { 1168 if (str && !strcmp("Linux", str))
1128 printk(KERN_INFO PREFIX "_OSI method disabled\n"); 1169 acpi_cmdline_osi_linux(1);
1129 acpi_gbl_create_osi_method = FALSE; 1170 else if (str && !strcmp("!Linux", str))
1130 } else { 1171 acpi_cmdline_osi_linux(0);
1131 strncpy(osi_setup_string, str, OSI_STRING_LENGTH_MAX); 1172 else
1132 } 1173 acpi_osi_setup(str);
1133 1174
1134 return 1; 1175 return 1;
1135} 1176}
1136 1177
1137__setup("acpi_osi=", acpi_osi_setup); 1178__setup("acpi_osi=", osi_setup);
1138 1179
1139/* enable serialization to combat AE_ALREADY_EXISTS errors */ 1180/* enable serialization to combat AE_ALREADY_EXISTS errors */
1140static int __init acpi_serialize_setup(char *str) 1181static int __init acpi_serialize_setup(char *str)
@@ -1530,7 +1571,7 @@ acpi_status __init acpi_os_initialize(void)
1530 return AE_OK; 1571 return AE_OK;
1531} 1572}
1532 1573
1533acpi_status acpi_os_initialize1(void) 1574acpi_status __init acpi_os_initialize1(void)
1534{ 1575{
1535 kacpid_wq = create_workqueue("kacpid"); 1576 kacpid_wq = create_workqueue("kacpid");
1536 kacpi_notify_wq = create_workqueue("kacpi_notify"); 1577 kacpi_notify_wq = create_workqueue("kacpi_notify");
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 67dedeed144c..4c9c2fb5d98f 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -213,11 +213,13 @@ static int acpi_power_on(acpi_handle handle)
213 resource->name)); 213 resource->name));
214 } else { 214 } else {
215 result = __acpi_power_on(resource); 215 result = __acpi_power_on(resource);
216 if (result)
217 resource->ref_count--;
216 } 218 }
217 219
218 mutex_unlock(&resource->resource_lock); 220 mutex_unlock(&resource->resource_lock);
219 221
220 return 0; 222 return result;
221} 223}
222 224
223static int acpi_power_off_device(acpi_handle handle) 225static int acpi_power_off_device(acpi_handle handle)
@@ -465,10 +467,12 @@ int acpi_power_transition(struct acpi_device *device, int state)
465 struct acpi_handle_list *tl = NULL; /* Target Resources */ 467 struct acpi_handle_list *tl = NULL; /* Target Resources */
466 int i = 0; 468 int i = 0;
467 469
468
469 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) 470 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
470 return -EINVAL; 471 return -EINVAL;
471 472
473 if (device->power.state == state)
474 return 0;
475
472 if ((device->power.state < ACPI_STATE_D0) 476 if ((device->power.state < ACPI_STATE_D0)
473 || (device->power.state > ACPI_STATE_D3)) 477 || (device->power.state > ACPI_STATE_D3))
474 return -ENODEV; 478 return -ENODEV;
@@ -488,10 +492,6 @@ int acpi_power_transition(struct acpi_device *device, int state)
488 goto end; 492 goto end;
489 } 493 }
490 494
491 if (device->power.state == state) {
492 goto end;
493 }
494
495 /* 495 /*
496 * Then we dereference all power resources used in the current list. 496 * Then we dereference all power resources used in the current list.
497 */ 497 */
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index fde49b9b1d99..79cb65332894 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -156,15 +156,6 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
156 return 0; 156 return 0;
157} 157}
158 158
159static int acpi_thermal_cpufreq_increase(unsigned int cpu)
160{
161 return -ENODEV;
162}
163static int acpi_thermal_cpufreq_decrease(unsigned int cpu)
164{
165 return -ENODEV;
166}
167
168#endif 159#endif
169 160
170int acpi_processor_get_limit_info(struct acpi_processor *pr) 161int acpi_processor_get_limit_info(struct acpi_processor *pr)
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index ba1caf724a16..c423231b952b 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -27,8 +27,6 @@
27 27
28static u8 sleep_states[ACPI_S_STATE_COUNT]; 28static u8 sleep_states[ACPI_S_STATE_COUNT];
29 29
30static u32 acpi_target_sleep_state = ACPI_STATE_S0;
31
32static void acpi_sleep_tts_switch(u32 acpi_state) 30static void acpi_sleep_tts_switch(u32 acpi_state)
33{ 31{
34 union acpi_object in_arg = { ACPI_TYPE_INTEGER }; 32 union acpi_object in_arg = { ACPI_TYPE_INTEGER };
@@ -81,6 +79,8 @@ static int acpi_sleep_prepare(u32 acpi_state)
81} 79}
82 80
83#ifdef CONFIG_ACPI_SLEEP 81#ifdef CONFIG_ACPI_SLEEP
82static u32 acpi_target_sleep_state = ACPI_STATE_S0;
83
84/* 84/*
85 * The ACPI specification wants us to save NVS memory regions during hibernation 85 * The ACPI specification wants us to save NVS memory regions during hibernation
86 * and to restore them during the subsequent resume. Windows does that also for 86 * and to restore them during the subsequent resume. Windows does that also for
@@ -427,6 +427,14 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
427 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"), 427 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
428 }, 428 },
429 }, 429 },
430 {
431 .callback = init_nvs_nosave,
432 .ident = "Sony Vaio VGN-NW130D",
433 .matches = {
434 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
435 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
436 },
437 },
430 {}, 438 {},
431}; 439};
432#endif /* CONFIG_SUSPEND */ 440#endif /* CONFIG_SUSPEND */
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index d050e073e570..66aa4bee80a6 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2552,8 +2552,11 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
2552 * 2552 *
2553 * If door lock fails, always clear sdev->locked to 2553 * If door lock fails, always clear sdev->locked to
2554 * avoid this infinite loop. 2554 * avoid this infinite loop.
2555 *
2556 * This may happen before SCSI scan is complete. Make
2557 * sure qc->dev->sdev isn't NULL before dereferencing.
2555 */ 2558 */
2556 if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL) 2559 if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev)
2557 qc->dev->sdev->locked = 0; 2560 qc->dev->sdev->locked = 0;
2558 2561
2559 qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; 2562 qc->scsicmd->result = SAM_STAT_CHECK_CONDITION;
@@ -3163,8 +3166,8 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
3163 3166
3164/** 3167/**
3165 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device 3168 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device
3169 * @shost: SCSI host of command to be sent
3166 * @cmd: SCSI command to be sent 3170 * @cmd: SCSI command to be sent
3167 * @done: Completion function, called when command is complete
3168 * 3171 *
3169 * In some cases, this function translates SCSI commands into 3172 * In some cases, this function translates SCSI commands into
3170 * ATA taskfiles, and queues the taskfiles to be sent to 3173 * ATA taskfiles, and queues the taskfiles to be sent to
@@ -3174,37 +3177,36 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
3174 * ATA and ATAPI devices appearing as SCSI devices. 3177 * ATA and ATAPI devices appearing as SCSI devices.
3175 * 3178 *
3176 * LOCKING: 3179 * LOCKING:
3177 * Releases scsi-layer-held lock, and obtains host lock. 3180 * ATA host lock
3178 * 3181 *
3179 * RETURNS: 3182 * RETURNS:
3180 * Return value from __ata_scsi_queuecmd() if @cmd can be queued, 3183 * Return value from __ata_scsi_queuecmd() if @cmd can be queued,
3181 * 0 otherwise. 3184 * 0 otherwise.
3182 */ 3185 */
3183int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 3186int ata_scsi_queuecmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
3184{ 3187{
3185 struct ata_port *ap; 3188 struct ata_port *ap;
3186 struct ata_device *dev; 3189 struct ata_device *dev;
3187 struct scsi_device *scsidev = cmd->device; 3190 struct scsi_device *scsidev = cmd->device;
3188 struct Scsi_Host *shost = scsidev->host;
3189 int rc = 0; 3191 int rc = 0;
3192 unsigned long irq_flags;
3190 3193
3191 ap = ata_shost_to_port(shost); 3194 ap = ata_shost_to_port(shost);
3192 3195
3193 spin_unlock(shost->host_lock); 3196 spin_lock_irqsave(ap->lock, irq_flags);
3194 spin_lock(ap->lock);
3195 3197
3196 ata_scsi_dump_cdb(ap, cmd); 3198 ata_scsi_dump_cdb(ap, cmd);
3197 3199
3198 dev = ata_scsi_find_dev(ap, scsidev); 3200 dev = ata_scsi_find_dev(ap, scsidev);
3199 if (likely(dev)) 3201 if (likely(dev))
3200 rc = __ata_scsi_queuecmd(cmd, done, dev); 3202 rc = __ata_scsi_queuecmd(cmd, cmd->scsi_done, dev);
3201 else { 3203 else {
3202 cmd->result = (DID_BAD_TARGET << 16); 3204 cmd->result = (DID_BAD_TARGET << 16);
3203 done(cmd); 3205 cmd->scsi_done(cmd);
3204 } 3206 }
3205 3207
3206 spin_unlock(ap->lock); 3208 spin_unlock_irqrestore(ap->lock, irq_flags);
3207 spin_lock(shost->host_lock); 3209
3208 return rc; 3210 return rc;
3209} 3211}
3210 3212
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index eaf194138f21..6bd9425ba5ab 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -142,7 +142,7 @@ static int autospeed; /* Chip present which snoops speed changes */
142static int pio_mask = ATA_PIO4; /* PIO range for autospeed devices */ 142static int pio_mask = ATA_PIO4; /* PIO range for autospeed devices */
143static int iordy_mask = 0xFFFFFFFF; /* Use iordy if available */ 143static int iordy_mask = 0xFFFFFFFF; /* Use iordy if available */
144 144
145#ifdef PATA_WINBOND_VLB_MODULE 145#ifdef CONFIG_PATA_WINBOND_VLB_MODULE
146static int winbond = 1; /* Set to probe Winbond controllers, 146static int winbond = 1; /* Set to probe Winbond controllers,
147 give I/O port if non standard */ 147 give I/O port if non standard */
148#else 148#else
diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
index 74b829817891..fa1b95a9a7ff 100644
--- a/drivers/ata/pata_octeon_cf.c
+++ b/drivers/ata/pata_octeon_cf.c
@@ -653,8 +653,6 @@ static irqreturn_t octeon_cf_interrupt(int irq, void *dev_instance)
653 653
654 ap = host->ports[i]; 654 ap = host->ports[i];
655 ocd = ap->dev->platform_data; 655 ocd = ap->dev->platform_data;
656
657 ocd = ap->dev->platform_data;
658 cf_port = ap->private_data; 656 cf_port = ap->private_data;
659 dma_int.u64 = 657 dma_int.u64 =
660 cvmx_read_csr(CVMX_MIO_BOOT_DMA_INTX(ocd->dma_engine)); 658 cvmx_read_csr(CVMX_MIO_BOOT_DMA_INTX(ocd->dma_engine));
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index c21589986c69..8b677bbf2d37 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -538,7 +538,7 @@ static int vt8251_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
538 return 0; 538 return 0;
539} 539}
540 540
541static void svia_configure(struct pci_dev *pdev) 541static void svia_configure(struct pci_dev *pdev, int board_id)
542{ 542{
543 u8 tmp8; 543 u8 tmp8;
544 544
@@ -577,7 +577,7 @@ static void svia_configure(struct pci_dev *pdev)
577 } 577 }
578 578
579 /* 579 /*
580 * vt6421 has problems talking to some drives. The following 580 * vt6420/1 has problems talking to some drives. The following
581 * is the fix from Joseph Chan <JosephChan@via.com.tw>. 581 * is the fix from Joseph Chan <JosephChan@via.com.tw>.
582 * 582 *
583 * When host issues HOLD, device may send up to 20DW of data 583 * When host issues HOLD, device may send up to 20DW of data
@@ -596,8 +596,9 @@ static void svia_configure(struct pci_dev *pdev)
596 * 596 *
597 * https://bugzilla.kernel.org/show_bug.cgi?id=15173 597 * https://bugzilla.kernel.org/show_bug.cgi?id=15173
598 * http://article.gmane.org/gmane.linux.ide/46352 598 * http://article.gmane.org/gmane.linux.ide/46352
599 * http://thread.gmane.org/gmane.linux.kernel/1062139
599 */ 600 */
600 if (pdev->device == 0x3249) { 601 if (board_id == vt6420 || board_id == vt6421) {
601 pci_read_config_byte(pdev, 0x52, &tmp8); 602 pci_read_config_byte(pdev, 0x52, &tmp8);
602 tmp8 |= 1 << 2; 603 tmp8 |= 1 << 2;
603 pci_write_config_byte(pdev, 0x52, tmp8); 604 pci_write_config_byte(pdev, 0x52, tmp8);
@@ -652,7 +653,7 @@ static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
652 if (rc) 653 if (rc)
653 return rc; 654 return rc;
654 655
655 svia_configure(pdev); 656 svia_configure(pdev, board_id);
656 657
657 pci_set_master(pdev); 658 pci_set_master(pdev);
658 return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt, 659 return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt,
diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
index 46b94762125b..f9b983ae6877 100644
--- a/drivers/atm/adummy.c
+++ b/drivers/atm/adummy.c
@@ -154,7 +154,7 @@ static int __init adummy_init(void)
154 err = -ENOMEM; 154 err = -ENOMEM;
155 goto out; 155 goto out;
156 } 156 }
157 atm_dev = atm_dev_register(DEV_LABEL, &adummy_ops, -1, NULL); 157 atm_dev = atm_dev_register(DEV_LABEL, NULL, &adummy_ops, -1, NULL);
158 if (!atm_dev) { 158 if (!atm_dev) {
159 printk(KERN_ERR DEV_LABEL ": atm_dev_register() failed\n"); 159 printk(KERN_ERR DEV_LABEL ": atm_dev_register() failed\n");
160 err = -ENODEV; 160 err = -ENODEV;
diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
index a33896a482e6..ffe9b655292e 100644
--- a/drivers/atm/ambassador.c
+++ b/drivers/atm/ambassador.c
@@ -2244,7 +2244,8 @@ static int __devinit amb_probe(struct pci_dev *pci_dev, const struct pci_device_
2244 goto out_reset; 2244 goto out_reset;
2245 } 2245 }
2246 2246
2247 dev->atm_dev = atm_dev_register (DEV_LABEL, &amb_ops, -1, NULL); 2247 dev->atm_dev = atm_dev_register (DEV_LABEL, &pci_dev->dev, &amb_ops, -1,
2248 NULL);
2248 if (!dev->atm_dev) { 2249 if (!dev->atm_dev) {
2249 PRINTD (DBG_ERR, "failed to register Madge ATM adapter"); 2250 PRINTD (DBG_ERR, "failed to register Madge ATM adapter");
2250 err = -EINVAL; 2251 err = -EINVAL;
diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
index b9101818b47b..2b464b631f22 100644
--- a/drivers/atm/atmtcp.c
+++ b/drivers/atm/atmtcp.c
@@ -366,7 +366,7 @@ static int atmtcp_create(int itf,int persist,struct atm_dev **result)
366 if (!dev_data) 366 if (!dev_data)
367 return -ENOMEM; 367 return -ENOMEM;
368 368
369 dev = atm_dev_register(DEV_LABEL,&atmtcp_v_dev_ops,itf,NULL); 369 dev = atm_dev_register(DEV_LABEL,NULL,&atmtcp_v_dev_ops,itf,NULL);
370 if (!dev) { 370 if (!dev) {
371 kfree(dev_data); 371 kfree(dev_data);
372 return itf == -1 ? -ENOMEM : -EBUSY; 372 return itf == -1 ? -ENOMEM : -EBUSY;
diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
index 97c5898cd76e..c495fae74200 100644
--- a/drivers/atm/eni.c
+++ b/drivers/atm/eni.c
@@ -2244,7 +2244,7 @@ static int __devinit eni_init_one(struct pci_dev *pci_dev,
2244 &zeroes); 2244 &zeroes);
2245 if (!cpu_zeroes) goto out1; 2245 if (!cpu_zeroes) goto out1;
2246 } 2246 }
2247 dev = atm_dev_register(DEV_LABEL,&ops,-1,NULL); 2247 dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &ops, -1, NULL);
2248 if (!dev) goto out2; 2248 if (!dev) goto out2;
2249 pci_set_drvdata(pci_dev, dev); 2249 pci_set_drvdata(pci_dev, dev);
2250 eni_dev->pci_dev = pci_dev; 2250 eni_dev->pci_dev = pci_dev;
diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
index 5d86bb803e94..7d912baf01d4 100644
--- a/drivers/atm/firestream.c
+++ b/drivers/atm/firestream.c
@@ -1911,7 +1911,7 @@ static int __devinit firestream_init_one (struct pci_dev *pci_dev,
1911 fs_dev, sizeof (struct fs_dev)); 1911 fs_dev, sizeof (struct fs_dev));
1912 if (!fs_dev) 1912 if (!fs_dev)
1913 goto err_out; 1913 goto err_out;
1914 atm_dev = atm_dev_register("fs", &ops, -1, NULL); 1914 atm_dev = atm_dev_register("fs", &pci_dev->dev, &ops, -1, NULL);
1915 if (!atm_dev) 1915 if (!atm_dev)
1916 goto err_out_free_fs_dev; 1916 goto err_out_free_fs_dev;
1917 1917
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index c8fc69c85a06..962c309b40c0 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -2567,14 +2567,14 @@ release:
2567 2567
2568 2568
2569static int __devinit 2569static int __devinit
2570fore200e_register(struct fore200e* fore200e) 2570fore200e_register(struct fore200e* fore200e, struct device *parent)
2571{ 2571{
2572 struct atm_dev* atm_dev; 2572 struct atm_dev* atm_dev;
2573 2573
2574 DPRINTK(2, "device %s being registered\n", fore200e->name); 2574 DPRINTK(2, "device %s being registered\n", fore200e->name);
2575 2575
2576 atm_dev = atm_dev_register(fore200e->bus->proc_name, &fore200e_ops, -1, 2576 atm_dev = atm_dev_register(fore200e->bus->proc_name, parent, &fore200e_ops,
2577 NULL); 2577 -1, NULL);
2578 if (atm_dev == NULL) { 2578 if (atm_dev == NULL) {
2579 printk(FORE200E "unable to register device %s\n", fore200e->name); 2579 printk(FORE200E "unable to register device %s\n", fore200e->name);
2580 return -ENODEV; 2580 return -ENODEV;
@@ -2594,9 +2594,9 @@ fore200e_register(struct fore200e* fore200e)
2594 2594
2595 2595
2596static int __devinit 2596static int __devinit
2597fore200e_init(struct fore200e* fore200e) 2597fore200e_init(struct fore200e* fore200e, struct device *parent)
2598{ 2598{
2599 if (fore200e_register(fore200e) < 0) 2599 if (fore200e_register(fore200e, parent) < 0)
2600 return -ENODEV; 2600 return -ENODEV;
2601 2601
2602 if (fore200e->bus->configure(fore200e) < 0) 2602 if (fore200e->bus->configure(fore200e) < 0)
@@ -2662,7 +2662,7 @@ static int __devinit fore200e_sba_probe(struct platform_device *op,
2662 2662
2663 sprintf(fore200e->name, "%s-%d", bus->model_name, index); 2663 sprintf(fore200e->name, "%s-%d", bus->model_name, index);
2664 2664
2665 err = fore200e_init(fore200e); 2665 err = fore200e_init(fore200e, &op->dev);
2666 if (err < 0) { 2666 if (err < 0) {
2667 fore200e_shutdown(fore200e); 2667 fore200e_shutdown(fore200e);
2668 kfree(fore200e); 2668 kfree(fore200e);
@@ -2740,7 +2740,7 @@ fore200e_pca_detect(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent
2740 2740
2741 sprintf(fore200e->name, "%s-%d", bus->model_name, index); 2741 sprintf(fore200e->name, "%s-%d", bus->model_name, index);
2742 2742
2743 err = fore200e_init(fore200e); 2743 err = fore200e_init(fore200e, &pci_dev->dev);
2744 if (err < 0) { 2744 if (err < 0) {
2745 fore200e_shutdown(fore200e); 2745 fore200e_shutdown(fore200e);
2746 goto out_free; 2746 goto out_free;
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index 801e8b6e9d1f..6cf59bf281dc 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -366,7 +366,7 @@ he_init_one(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
366 goto init_one_failure; 366 goto init_one_failure;
367 } 367 }
368 368
369 atm_dev = atm_dev_register(DEV_LABEL, &he_ops, -1, NULL); 369 atm_dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &he_ops, -1, NULL);
370 if (!atm_dev) { 370 if (!atm_dev) {
371 err = -ENODEV; 371 err = -ENODEV;
372 goto init_one_failure; 372 goto init_one_failure;
diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
index a95790452a68..24761e1d6642 100644
--- a/drivers/atm/horizon.c
+++ b/drivers/atm/horizon.c
@@ -2733,7 +2733,8 @@ static int __devinit hrz_probe(struct pci_dev *pci_dev, const struct pci_device_
2733 PRINTD(DBG_INFO, "found Madge ATM adapter (hrz) at: IO %x, IRQ %u, MEM %p", 2733 PRINTD(DBG_INFO, "found Madge ATM adapter (hrz) at: IO %x, IRQ %u, MEM %p",
2734 iobase, irq, membase); 2734 iobase, irq, membase);
2735 2735
2736 dev->atm_dev = atm_dev_register(DEV_LABEL, &hrz_ops, -1, NULL); 2736 dev->atm_dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &hrz_ops, -1,
2737 NULL);
2737 if (!(dev->atm_dev)) { 2738 if (!(dev->atm_dev)) {
2738 PRINTD(DBG_ERR, "failed to register Madge ATM adapter"); 2739 PRINTD(DBG_ERR, "failed to register Madge ATM adapter");
2739 err = -EINVAL; 2740 err = -EINVAL;
diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index bce57328ddde..bfb7feee0400 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -3698,7 +3698,8 @@ idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id)
3698 goto err_out_iounmap; 3698 goto err_out_iounmap;
3699 } 3699 }
3700 3700
3701 dev = atm_dev_register("idt77252", &idt77252_ops, -1, NULL); 3701 dev = atm_dev_register("idt77252", &pcidev->dev, &idt77252_ops, -1,
3702 NULL);
3702 if (!dev) { 3703 if (!dev) {
3703 printk("%s: can't register atm device\n", card->name); 3704 printk("%s: can't register atm device\n", card->name);
3704 err = -EIO; 3705 err = -EIO;
diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
index ad8e207784d4..d80d51b62a1a 100644
--- a/drivers/atm/iphase.c
+++ b/drivers/atm/iphase.c
@@ -3172,7 +3172,7 @@ static int __devinit ia_init_one(struct pci_dev *pdev,
3172 ret = -ENODEV; 3172 ret = -ENODEV;
3173 goto err_out_free_iadev; 3173 goto err_out_free_iadev;
3174 } 3174 }
3175 dev = atm_dev_register(DEV_LABEL, &ops, -1, NULL); 3175 dev = atm_dev_register(DEV_LABEL, &pdev->dev, &ops, -1, NULL);
3176 if (!dev) { 3176 if (!dev) {
3177 ret = -ENOMEM; 3177 ret = -ENOMEM;
3178 goto err_out_disable_dev; 3178 goto err_out_disable_dev;
diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
index cbe15a86c669..a395c9aab146 100644
--- a/drivers/atm/lanai.c
+++ b/drivers/atm/lanai.c
@@ -2591,7 +2591,7 @@ static int __devinit lanai_init_one(struct pci_dev *pci,
2591 return -ENOMEM; 2591 return -ENOMEM;
2592 } 2592 }
2593 2593
2594 atmdev = atm_dev_register(DEV_LABEL, &ops, -1, NULL); 2594 atmdev = atm_dev_register(DEV_LABEL, &pci->dev, &ops, -1, NULL);
2595 if (atmdev == NULL) { 2595 if (atmdev == NULL) {
2596 printk(KERN_ERR DEV_LABEL 2596 printk(KERN_ERR DEV_LABEL
2597 ": couldn't register atm device!\n"); 2597 ": couldn't register atm device!\n");
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index 2f3516b7f118..6b313ee9231b 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -771,7 +771,8 @@ static int __devinit ns_init_card(int i, struct pci_dev *pcidev)
771 } 771 }
772 772
773 /* Register device */ 773 /* Register device */
774 card->atmdev = atm_dev_register("nicstar", &atm_ops, -1, NULL); 774 card->atmdev = atm_dev_register("nicstar", &card->pcidev->dev, &atm_ops,
775 -1, NULL);
775 if (card->atmdev == NULL) { 776 if (card->atmdev == NULL) {
776 printk("nicstar%d: can't register device.\n", i); 777 printk("nicstar%d: can't register device.\n", i);
777 error = 17; 778 error = 17;
diff --git a/drivers/atm/solos-attrlist.c b/drivers/atm/solos-attrlist.c
index 1a9332e4efe0..9a676ee30824 100644
--- a/drivers/atm/solos-attrlist.c
+++ b/drivers/atm/solos-attrlist.c
@@ -1,6 +1,7 @@
1SOLOS_ATTR_RO(DriverVersion) 1SOLOS_ATTR_RO(DriverVersion)
2SOLOS_ATTR_RO(APIVersion) 2SOLOS_ATTR_RO(APIVersion)
3SOLOS_ATTR_RO(FirmwareVersion) 3SOLOS_ATTR_RO(FirmwareVersion)
4SOLOS_ATTR_RO(Version)
4// SOLOS_ATTR_RO(DspVersion) 5// SOLOS_ATTR_RO(DspVersion)
5// SOLOS_ATTR_RO(CommonHandshake) 6// SOLOS_ATTR_RO(CommonHandshake)
6SOLOS_ATTR_RO(Connected) 7SOLOS_ATTR_RO(Connected)
diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
index f46138ab38b6..73fb1c4f4cd4 100644
--- a/drivers/atm/solos-pci.c
+++ b/drivers/atm/solos-pci.c
@@ -166,7 +166,7 @@ static irqreturn_t solos_irq(int irq, void *dev_id);
166static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci); 166static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
167static int list_vccs(int vci); 167static int list_vccs(int vci);
168static void release_vccs(struct atm_dev *dev); 168static void release_vccs(struct atm_dev *dev);
169static int atm_init(struct solos_card *); 169static int atm_init(struct solos_card *, struct device *);
170static void atm_remove(struct solos_card *); 170static void atm_remove(struct solos_card *);
171static int send_command(struct solos_card *card, int dev, const char *buf, size_t size); 171static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
172static void solos_bh(unsigned long); 172static void solos_bh(unsigned long);
@@ -1161,6 +1161,14 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1161 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n", 1161 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
1162 major_ver, minor_ver, fpga_ver); 1162 major_ver, minor_ver, fpga_ver);
1163 1163
1164 if (fpga_ver < 37 && (fpga_upgrade || firmware_upgrade ||
1165 db_fpga_upgrade || db_firmware_upgrade)) {
1166 dev_warn(&dev->dev,
1167 "FPGA too old; cannot upgrade flash. Use JTAG.\n");
1168 fpga_upgrade = firmware_upgrade = 0;
1169 db_fpga_upgrade = db_firmware_upgrade = 0;
1170 }
1171
1164 if (card->fpga_version >= DMA_SUPPORTED){ 1172 if (card->fpga_version >= DMA_SUPPORTED){
1165 card->using_dma = 1; 1173 card->using_dma = 1;
1166 } else { 1174 } else {
@@ -1202,7 +1210,7 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1202 if (db_firmware_upgrade) 1210 if (db_firmware_upgrade)
1203 flash_upgrade(card, 3); 1211 flash_upgrade(card, 3);
1204 1212
1205 err = atm_init(card); 1213 err = atm_init(card, &dev->dev);
1206 if (err) 1214 if (err)
1207 goto out_free_irq; 1215 goto out_free_irq;
1208 1216
@@ -1225,7 +1233,7 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1225 return err; 1233 return err;
1226} 1234}
1227 1235
1228static int atm_init(struct solos_card *card) 1236static int atm_init(struct solos_card *card, struct device *parent)
1229{ 1237{
1230 int i; 1238 int i;
1231 1239
@@ -1236,7 +1244,7 @@ static int atm_init(struct solos_card *card)
1236 skb_queue_head_init(&card->tx_queue[i]); 1244 skb_queue_head_init(&card->tx_queue[i]);
1237 skb_queue_head_init(&card->cli_queue[i]); 1245 skb_queue_head_init(&card->cli_queue[i]);
1238 1246
1239 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL); 1247 card->atmdev[i] = atm_dev_register("solos-pci", parent, &fpga_ops, -1, NULL);
1240 if (!card->atmdev[i]) { 1248 if (!card->atmdev[i]) {
1241 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i); 1249 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
1242 atm_remove(card); 1250 atm_remove(card);
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index 4e885d2da49c..624917902b65 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -1597,7 +1597,7 @@ static int __devinit zatm_init_one(struct pci_dev *pci_dev,
1597 goto out; 1597 goto out;
1598 } 1598 }
1599 1599
1600 dev = atm_dev_register(DEV_LABEL, &ops, -1, NULL); 1600 dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &ops, -1, NULL);
1601 if (!dev) 1601 if (!dev)
1602 goto out_free; 1602 goto out_free;
1603 1603
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index c5356ef7e54e..fa5d98ee5902 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -475,20 +475,33 @@ End:
475 */ 475 */
476void dpm_resume_noirq(pm_message_t state) 476void dpm_resume_noirq(pm_message_t state)
477{ 477{
478 struct device *dev; 478 struct list_head list;
479 ktime_t starttime = ktime_get(); 479 ktime_t starttime = ktime_get();
480 480
481 INIT_LIST_HEAD(&list);
481 mutex_lock(&dpm_list_mtx); 482 mutex_lock(&dpm_list_mtx);
482 transition_started = false; 483 transition_started = false;
483 list_for_each_entry(dev, &dpm_list, power.entry) 484 while (!list_empty(&dpm_list)) {
485 struct device *dev = to_device(dpm_list.next);
486
487 get_device(dev);
484 if (dev->power.status > DPM_OFF) { 488 if (dev->power.status > DPM_OFF) {
485 int error; 489 int error;
486 490
487 dev->power.status = DPM_OFF; 491 dev->power.status = DPM_OFF;
492 mutex_unlock(&dpm_list_mtx);
493
488 error = device_resume_noirq(dev, state); 494 error = device_resume_noirq(dev, state);
495
496 mutex_lock(&dpm_list_mtx);
489 if (error) 497 if (error)
490 pm_dev_err(dev, state, " early", error); 498 pm_dev_err(dev, state, " early", error);
491 } 499 }
500 if (!list_empty(&dev->power.entry))
501 list_move_tail(&dev->power.entry, &list);
502 put_device(dev);
503 }
504 list_splice(&list, &dpm_list);
492 mutex_unlock(&dpm_list_mtx); 505 mutex_unlock(&dpm_list_mtx);
493 dpm_show_time(starttime, state, "early"); 506 dpm_show_time(starttime, state, "early");
494 resume_device_irqs(); 507 resume_device_irqs();
@@ -789,20 +802,33 @@ End:
789 */ 802 */
790int dpm_suspend_noirq(pm_message_t state) 803int dpm_suspend_noirq(pm_message_t state)
791{ 804{
792 struct device *dev; 805 struct list_head list;
793 ktime_t starttime = ktime_get(); 806 ktime_t starttime = ktime_get();
794 int error = 0; 807 int error = 0;
795 808
809 INIT_LIST_HEAD(&list);
796 suspend_device_irqs(); 810 suspend_device_irqs();
797 mutex_lock(&dpm_list_mtx); 811 mutex_lock(&dpm_list_mtx);
798 list_for_each_entry_reverse(dev, &dpm_list, power.entry) { 812 while (!list_empty(&dpm_list)) {
813 struct device *dev = to_device(dpm_list.prev);
814
815 get_device(dev);
816 mutex_unlock(&dpm_list_mtx);
817
799 error = device_suspend_noirq(dev, state); 818 error = device_suspend_noirq(dev, state);
819
820 mutex_lock(&dpm_list_mtx);
800 if (error) { 821 if (error) {
801 pm_dev_err(dev, state, " late", error); 822 pm_dev_err(dev, state, " late", error);
823 put_device(dev);
802 break; 824 break;
803 } 825 }
804 dev->power.status = DPM_OFF_IRQ; 826 dev->power.status = DPM_OFF_IRQ;
827 if (!list_empty(&dev->power.entry))
828 list_move(&dev->power.entry, &list);
829 put_device(dev);
805 } 830 }
831 list_splice_tail(&list, &dpm_list);
806 mutex_unlock(&dpm_list_mtx); 832 mutex_unlock(&dpm_list_mtx);
807 if (error) 833 if (error)
808 dpm_resume_noirq(resume_event(state)); 834 dpm_resume_noirq(resume_event(state));
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index a1725e6488d3..7888501ad9ee 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -1341,7 +1341,7 @@ static struct request *set_next_request(void)
1341{ 1341{
1342 struct request_queue *q; 1342 struct request_queue *q;
1343 int cnt = FD_MAX_UNITS; 1343 int cnt = FD_MAX_UNITS;
1344 struct request *rq; 1344 struct request *rq = NULL;
1345 1345
1346 /* Find next queue we can dispatch from */ 1346 /* Find next queue we can dispatch from */
1347 fdc_queue = fdc_queue + 1; 1347 fdc_queue = fdc_queue + 1;
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index 541e18879965..528f6318ded1 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -180,9 +180,6 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
180 BUG(); 180 BUG();
181 bio_endio(bio, -ENXIO); 181 bio_endio(bio, -ENXIO);
182 return 0; 182 return 0;
183 } else if (bio->bi_rw & REQ_HARDBARRIER) {
184 bio_endio(bio, -EOPNOTSUPP);
185 return 0;
186 } else if (bio->bi_io_vec == NULL) { 183 } else if (bio->bi_io_vec == NULL) {
187 printk(KERN_ERR "aoe: bi_io_vec is NULL\n"); 184 printk(KERN_ERR "aoe: bi_io_vec is NULL\n");
188 BUG(); 185 BUG();
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 4e4cc6c828cb..605a67e40bbf 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1399,7 +1399,7 @@ static struct request *set_next_request(void)
1399{ 1399{
1400 struct request_queue *q; 1400 struct request_queue *q;
1401 int old_pos = fdc_queue; 1401 int old_pos = fdc_queue;
1402 struct request *rq; 1402 struct request *rq = NULL;
1403 1403
1404 do { 1404 do {
1405 q = unit[fdc_queue].disk->queue; 1405 q = unit[fdc_queue].disk->queue;
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 2cc4dda46279..8e0f9256eb58 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -66,6 +66,7 @@ MODULE_VERSION("3.6.26");
66MODULE_LICENSE("GPL"); 66MODULE_LICENSE("GPL");
67 67
68static DEFINE_MUTEX(cciss_mutex); 68static DEFINE_MUTEX(cciss_mutex);
69static struct proc_dir_entry *proc_cciss;
69 70
70#include "cciss_cmd.h" 71#include "cciss_cmd.h"
71#include "cciss.h" 72#include "cciss.h"
@@ -113,6 +114,8 @@ static struct board_type products[] = {
113 {0x409D0E11, "Smart Array 6400 EM", &SA5_access}, 114 {0x409D0E11, "Smart Array 6400 EM", &SA5_access},
114 {0x40910E11, "Smart Array 6i", &SA5_access}, 115 {0x40910E11, "Smart Array 6i", &SA5_access},
115 {0x3225103C, "Smart Array P600", &SA5_access}, 116 {0x3225103C, "Smart Array P600", &SA5_access},
117 {0x3223103C, "Smart Array P800", &SA5_access},
118 {0x3234103C, "Smart Array P400", &SA5_access},
116 {0x3235103C, "Smart Array P400i", &SA5_access}, 119 {0x3235103C, "Smart Array P400i", &SA5_access},
117 {0x3211103C, "Smart Array E200i", &SA5_access}, 120 {0x3211103C, "Smart Array E200i", &SA5_access},
118 {0x3212103C, "Smart Array E200", &SA5_access}, 121 {0x3212103C, "Smart Array E200", &SA5_access},
@@ -361,8 +364,6 @@ static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG",
361#define ENG_GIG_FACTOR (ENG_GIG/512) 364#define ENG_GIG_FACTOR (ENG_GIG/512)
362#define ENGAGE_SCSI "engage scsi" 365#define ENGAGE_SCSI "engage scsi"
363 366
364static struct proc_dir_entry *proc_cciss;
365
366static void cciss_seq_show_header(struct seq_file *seq) 367static void cciss_seq_show_header(struct seq_file *seq)
367{ 368{
368 ctlr_info_t *h = seq->private; 369 ctlr_info_t *h = seq->private;
@@ -2833,6 +2834,8 @@ static int cciss_revalidate(struct gendisk *disk)
2833 InquiryData_struct *inq_buff = NULL; 2834 InquiryData_struct *inq_buff = NULL;
2834 2835
2835 for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) { 2836 for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) {
2837 if (!h->drv[logvol])
2838 continue;
2836 if (memcmp(h->drv[logvol]->LunID, drv->LunID, 2839 if (memcmp(h->drv[logvol]->LunID, drv->LunID,
2837 sizeof(drv->LunID)) == 0) { 2840 sizeof(drv->LunID)) == 0) {
2838 FOUND = 1; 2841 FOUND = 1;
@@ -3753,7 +3756,7 @@ static void __devinit cciss_wait_for_mode_change_ack(ctlr_info_t *h)
3753 for (i = 0; i < MAX_CONFIG_WAIT; i++) { 3756 for (i = 0; i < MAX_CONFIG_WAIT; i++) {
3754 if (!(readl(h->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq)) 3757 if (!(readl(h->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
3755 break; 3758 break;
3756 msleep(10); 3759 usleep_range(10000, 20000);
3757 } 3760 }
3758} 3761}
3759 3762
@@ -3937,10 +3940,9 @@ static int __devinit cciss_lookup_board_id(struct pci_dev *pdev, u32 *board_id)
3937 *board_id = ((subsystem_device_id << 16) & 0xffff0000) | 3940 *board_id = ((subsystem_device_id << 16) & 0xffff0000) |
3938 subsystem_vendor_id; 3941 subsystem_vendor_id;
3939 3942
3940 for (i = 0; i < ARRAY_SIZE(products); i++) { 3943 for (i = 0; i < ARRAY_SIZE(products); i++)
3941 if (*board_id == products[i].board_id) 3944 if (*board_id == products[i].board_id)
3942 return i; 3945 return i;
3943 }
3944 dev_warn(&pdev->dev, "unrecognized board ID: 0x%08x, ignoring.\n", 3946 dev_warn(&pdev->dev, "unrecognized board ID: 0x%08x, ignoring.\n",
3945 *board_id); 3947 *board_id);
3946 return -ENODEV; 3948 return -ENODEV;
@@ -3971,18 +3973,31 @@ static int __devinit cciss_pci_find_memory_BAR(struct pci_dev *pdev,
3971 return -ENODEV; 3973 return -ENODEV;
3972} 3974}
3973 3975
3974static int __devinit cciss_wait_for_board_ready(ctlr_info_t *h) 3976static int __devinit cciss_wait_for_board_state(struct pci_dev *pdev,
3977 void __iomem *vaddr, int wait_for_ready)
3978#define BOARD_READY 1
3979#define BOARD_NOT_READY 0
3975{ 3980{
3976 int i; 3981 int i, iterations;
3977 u32 scratchpad; 3982 u32 scratchpad;
3978 3983
3979 for (i = 0; i < CCISS_BOARD_READY_ITERATIONS; i++) { 3984 if (wait_for_ready)
3980 scratchpad = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET); 3985 iterations = CCISS_BOARD_READY_ITERATIONS;
3981 if (scratchpad == CCISS_FIRMWARE_READY) 3986 else
3982 return 0; 3987 iterations = CCISS_BOARD_NOT_READY_ITERATIONS;
3988
3989 for (i = 0; i < iterations; i++) {
3990 scratchpad = readl(vaddr + SA5_SCRATCHPAD_OFFSET);
3991 if (wait_for_ready) {
3992 if (scratchpad == CCISS_FIRMWARE_READY)
3993 return 0;
3994 } else {
3995 if (scratchpad != CCISS_FIRMWARE_READY)
3996 return 0;
3997 }
3983 msleep(CCISS_BOARD_READY_POLL_INTERVAL_MSECS); 3998 msleep(CCISS_BOARD_READY_POLL_INTERVAL_MSECS);
3984 } 3999 }
3985 dev_warn(&h->pdev->dev, "board not ready, timed out.\n"); 4000 dev_warn(&pdev->dev, "board not ready, timed out.\n");
3986 return -ENODEV; 4001 return -ENODEV;
3987} 4002}
3988 4003
@@ -4031,6 +4046,11 @@ static int __devinit cciss_find_cfgtables(ctlr_info_t *h)
4031static void __devinit cciss_get_max_perf_mode_cmds(struct ctlr_info *h) 4046static void __devinit cciss_get_max_perf_mode_cmds(struct ctlr_info *h)
4032{ 4047{
4033 h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands)); 4048 h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands));
4049
4050 /* Limit commands in memory limited kdump scenario. */
4051 if (reset_devices && h->max_commands > 32)
4052 h->max_commands = 32;
4053
4034 if (h->max_commands < 16) { 4054 if (h->max_commands < 16) {
4035 dev_warn(&h->pdev->dev, "Controller reports " 4055 dev_warn(&h->pdev->dev, "Controller reports "
4036 "max supported commands of %d, an obvious lie. " 4056 "max supported commands of %d, an obvious lie. "
@@ -4148,7 +4168,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
4148 err = -ENOMEM; 4168 err = -ENOMEM;
4149 goto err_out_free_res; 4169 goto err_out_free_res;
4150 } 4170 }
4151 err = cciss_wait_for_board_ready(h); 4171 err = cciss_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY);
4152 if (err) 4172 if (err)
4153 goto err_out_free_res; 4173 goto err_out_free_res;
4154 err = cciss_find_cfgtables(h); 4174 err = cciss_find_cfgtables(h);
@@ -4313,36 +4333,6 @@ static __devinit int cciss_message(struct pci_dev *pdev, unsigned char opcode, u
4313#define cciss_soft_reset_controller(p) cciss_message(p, 1, 0) 4333#define cciss_soft_reset_controller(p) cciss_message(p, 1, 0)
4314#define cciss_noop(p) cciss_message(p, 3, 0) 4334#define cciss_noop(p) cciss_message(p, 3, 0)
4315 4335
4316static __devinit int cciss_reset_msi(struct pci_dev *pdev)
4317{
4318/* the #defines are stolen from drivers/pci/msi.h. */
4319#define msi_control_reg(base) (base + PCI_MSI_FLAGS)
4320#define PCI_MSIX_FLAGS_ENABLE (1 << 15)
4321
4322 int pos;
4323 u16 control = 0;
4324
4325 pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
4326 if (pos) {
4327 pci_read_config_word(pdev, msi_control_reg(pos), &control);
4328 if (control & PCI_MSI_FLAGS_ENABLE) {
4329 dev_info(&pdev->dev, "resetting MSI\n");
4330 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSI_FLAGS_ENABLE);
4331 }
4332 }
4333
4334 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
4335 if (pos) {
4336 pci_read_config_word(pdev, msi_control_reg(pos), &control);
4337 if (control & PCI_MSIX_FLAGS_ENABLE) {
4338 dev_info(&pdev->dev, "resetting MSI-X\n");
4339 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSIX_FLAGS_ENABLE);
4340 }
4341 }
4342
4343 return 0;
4344}
4345
4346static int cciss_controller_hard_reset(struct pci_dev *pdev, 4336static int cciss_controller_hard_reset(struct pci_dev *pdev,
4347 void * __iomem vaddr, bool use_doorbell) 4337 void * __iomem vaddr, bool use_doorbell)
4348{ 4338{
@@ -4397,17 +4387,17 @@ static int cciss_controller_hard_reset(struct pci_dev *pdev,
4397 * states or using the doorbell register. */ 4387 * states or using the doorbell register. */
4398static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev) 4388static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev)
4399{ 4389{
4400 u16 saved_config_space[32];
4401 u64 cfg_offset; 4390 u64 cfg_offset;
4402 u32 cfg_base_addr; 4391 u32 cfg_base_addr;
4403 u64 cfg_base_addr_index; 4392 u64 cfg_base_addr_index;
4404 void __iomem *vaddr; 4393 void __iomem *vaddr;
4405 unsigned long paddr; 4394 unsigned long paddr;
4406 u32 misc_fw_support, active_transport; 4395 u32 misc_fw_support, active_transport;
4407 int rc, i; 4396 int rc;
4408 CfgTable_struct __iomem *cfgtable; 4397 CfgTable_struct __iomem *cfgtable;
4409 bool use_doorbell; 4398 bool use_doorbell;
4410 u32 board_id; 4399 u32 board_id;
4400 u16 command_register;
4411 4401
4412 /* For controllers as old a the p600, this is very nearly 4402 /* For controllers as old a the p600, this is very nearly
4413 * the same thing as 4403 * the same thing as
@@ -4417,14 +4407,6 @@ static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev)
4417 * pci_set_power_state(pci_dev, PCI_D0); 4407 * pci_set_power_state(pci_dev, PCI_D0);
4418 * pci_restore_state(pci_dev); 4408 * pci_restore_state(pci_dev);
4419 * 4409 *
4420 * but we can't use these nice canned kernel routines on
4421 * kexec, because they also check the MSI/MSI-X state in PCI
4422 * configuration space and do the wrong thing when it is
4423 * set/cleared. Also, the pci_save/restore_state functions
4424 * violate the ordering requirements for restoring the
4425 * configuration space from the CCISS document (see the
4426 * comment below). So we roll our own ....
4427 *
4428 * For controllers newer than the P600, the pci power state 4410 * For controllers newer than the P600, the pci power state
4429 * method of resetting doesn't work so we have another way 4411 * method of resetting doesn't work so we have another way
4430 * using the doorbell register. 4412 * using the doorbell register.
@@ -4443,8 +4425,13 @@ static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev)
4443 return -ENODEV; 4425 return -ENODEV;
4444 } 4426 }
4445 4427
4446 for (i = 0; i < 32; i++) 4428 /* Save the PCI command register */
4447 pci_read_config_word(pdev, 2*i, &saved_config_space[i]); 4429 pci_read_config_word(pdev, 4, &command_register);
4430 /* Turn the board off. This is so that later pci_restore_state()
4431 * won't turn the board on before the rest of config space is ready.
4432 */
4433 pci_disable_device(pdev);
4434 pci_save_state(pdev);
4448 4435
4449 /* find the first memory BAR, so we can find the cfg table */ 4436 /* find the first memory BAR, so we can find the cfg table */
4450 rc = cciss_pci_find_memory_BAR(pdev, &paddr); 4437 rc = cciss_pci_find_memory_BAR(pdev, &paddr);
@@ -4479,26 +4466,32 @@ static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev)
4479 rc = cciss_controller_hard_reset(pdev, vaddr, use_doorbell); 4466 rc = cciss_controller_hard_reset(pdev, vaddr, use_doorbell);
4480 if (rc) 4467 if (rc)
4481 goto unmap_cfgtable; 4468 goto unmap_cfgtable;
4482 4469 pci_restore_state(pdev);
4483 /* Restore the PCI configuration space. The Open CISS 4470 rc = pci_enable_device(pdev);
4484 * Specification says, "Restore the PCI Configuration 4471 if (rc) {
4485 * Registers, offsets 00h through 60h. It is important to 4472 dev_warn(&pdev->dev, "failed to enable device.\n");
4486 * restore the command register, 16-bits at offset 04h, 4473 goto unmap_cfgtable;
4487 * last. Do not restore the configuration status register,
4488 * 16-bits at offset 06h." Note that the offset is 2*i.
4489 */
4490 for (i = 0; i < 32; i++) {
4491 if (i == 2 || i == 3)
4492 continue;
4493 pci_write_config_word(pdev, 2*i, saved_config_space[i]);
4494 } 4474 }
4495 wmb(); 4475 pci_write_config_word(pdev, 4, command_register);
4496 pci_write_config_word(pdev, 4, saved_config_space[2]);
4497 4476
4498 /* Some devices (notably the HP Smart Array 5i Controller) 4477 /* Some devices (notably the HP Smart Array 5i Controller)
4499 need a little pause here */ 4478 need a little pause here */
4500 msleep(CCISS_POST_RESET_PAUSE_MSECS); 4479 msleep(CCISS_POST_RESET_PAUSE_MSECS);
4501 4480
4481 /* Wait for board to become not ready, then ready. */
4482 dev_info(&pdev->dev, "Waiting for board to become ready.\n");
4483 rc = cciss_wait_for_board_state(pdev, vaddr, BOARD_NOT_READY);
4484 if (rc) /* Don't bail, might be E500, etc. which can't be reset */
4485 dev_warn(&pdev->dev,
4486 "failed waiting for board to become not ready\n");
4487 rc = cciss_wait_for_board_state(pdev, vaddr, BOARD_READY);
4488 if (rc) {
4489 dev_warn(&pdev->dev,
4490 "failed waiting for board to become ready\n");
4491 goto unmap_cfgtable;
4492 }
4493 dev_info(&pdev->dev, "board ready.\n");
4494
4502 /* Controller should be in simple mode at this point. If it's not, 4495 /* Controller should be in simple mode at this point. If it's not,
4503 * It means we're on one of those controllers which doesn't support 4496 * It means we're on one of those controllers which doesn't support
4504 * the doorbell reset method and on which the PCI power management reset 4497 * the doorbell reset method and on which the PCI power management reset
@@ -4539,8 +4532,6 @@ static __devinit int cciss_init_reset_devices(struct pci_dev *pdev)
4539 return 0; /* just try to do the kdump anyhow. */ 4532 return 0; /* just try to do the kdump anyhow. */
4540 if (rc) 4533 if (rc)
4541 return -ENODEV; 4534 return -ENODEV;
4542 if (cciss_reset_msi(pdev))
4543 return -ENODEV;
4544 4535
4545 /* Now try to get the controller to respond to a no-op */ 4536 /* Now try to get the controller to respond to a no-op */
4546 for (i = 0; i < CCISS_POST_RESET_NOOP_RETRIES; i++) { 4537 for (i = 0; i < CCISS_POST_RESET_NOOP_RETRIES; i++) {
@@ -4936,7 +4927,8 @@ static void __exit cciss_cleanup(void)
4936 } 4927 }
4937 } 4928 }
4938 kthread_stop(cciss_scan_thread); 4929 kthread_stop(cciss_scan_thread);
4939 remove_proc_entry("driver/cciss", NULL); 4930 if (proc_cciss)
4931 remove_proc_entry("driver/cciss", NULL);
4940 bus_unregister(&cciss_bus_type); 4932 bus_unregister(&cciss_bus_type);
4941} 4933}
4942 4934
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index ae340ffc8f81..4b8933d778f1 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -200,10 +200,14 @@ struct ctlr_info
200 * the above. 200 * the above.
201 */ 201 */
202#define CCISS_BOARD_READY_WAIT_SECS (120) 202#define CCISS_BOARD_READY_WAIT_SECS (120)
203#define CCISS_BOARD_NOT_READY_WAIT_SECS (10)
203#define CCISS_BOARD_READY_POLL_INTERVAL_MSECS (100) 204#define CCISS_BOARD_READY_POLL_INTERVAL_MSECS (100)
204#define CCISS_BOARD_READY_ITERATIONS \ 205#define CCISS_BOARD_READY_ITERATIONS \
205 ((CCISS_BOARD_READY_WAIT_SECS * 1000) / \ 206 ((CCISS_BOARD_READY_WAIT_SECS * 1000) / \
206 CCISS_BOARD_READY_POLL_INTERVAL_MSECS) 207 CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
208#define CCISS_BOARD_NOT_READY_ITERATIONS \
209 ((CCISS_BOARD_NOT_READY_WAIT_SECS * 1000) / \
210 CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
207#define CCISS_POST_RESET_PAUSE_MSECS (3000) 211#define CCISS_POST_RESET_PAUSE_MSECS (3000)
208#define CCISS_POST_RESET_NOOP_INTERVAL_MSECS (1000) 212#define CCISS_POST_RESET_NOOP_INTERVAL_MSECS (1000)
209#define CCISS_POST_RESET_NOOP_RETRIES (12) 213#define CCISS_POST_RESET_NOOP_RETRIES (12)
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 575495f3c4b8..727d0225b7d0 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -62,8 +62,8 @@ static int cciss_scsi_proc_info(
62 int length, /* length of data in buffer */ 62 int length, /* length of data in buffer */
63 int func); /* 0 == read, 1 == write */ 63 int func); /* 0 == read, 1 == write */
64 64
65static int cciss_scsi_queue_command (struct scsi_cmnd *cmd, 65static int cciss_scsi_queue_command (struct Scsi_Host *h,
66 void (* done)(struct scsi_cmnd *)); 66 struct scsi_cmnd *cmd);
67static int cciss_eh_device_reset_handler(struct scsi_cmnd *); 67static int cciss_eh_device_reset_handler(struct scsi_cmnd *);
68static int cciss_eh_abort_handler(struct scsi_cmnd *); 68static int cciss_eh_abort_handler(struct scsi_cmnd *);
69 69
@@ -1406,7 +1406,7 @@ static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *c,
1406 1406
1407 1407
1408static int 1408static int
1409cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *)) 1409cciss_scsi_queue_command_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
1410{ 1410{
1411 ctlr_info_t *h; 1411 ctlr_info_t *h;
1412 int rc; 1412 int rc;
@@ -1504,6 +1504,8 @@ cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd
1504 return 0; 1504 return 0;
1505} 1505}
1506 1506
1507static DEF_SCSI_QCMD(cciss_scsi_queue_command)
1508
1507static void cciss_unregister_scsi(ctlr_info_t *h) 1509static void cciss_unregister_scsi(ctlr_info_t *h)
1508{ 1510{
1509 struct cciss_scsi_adapter_data_t *sa; 1511 struct cciss_scsi_adapter_data_t *sa;
diff --git a/drivers/block/drbd/drbd_actlog.c b/drivers/block/drbd/drbd_actlog.c
index ac04ef97eac2..ba95cba192be 100644
--- a/drivers/block/drbd/drbd_actlog.c
+++ b/drivers/block/drbd/drbd_actlog.c
@@ -78,11 +78,10 @@ static int _drbd_md_sync_page_io(struct drbd_conf *mdev,
78 init_completion(&md_io.event); 78 init_completion(&md_io.event);
79 md_io.error = 0; 79 md_io.error = 0;
80 80
81 if ((rw & WRITE) && !test_bit(MD_NO_BARRIER, &mdev->flags)) 81 if ((rw & WRITE) && !test_bit(MD_NO_FUA, &mdev->flags))
82 rw |= REQ_HARDBARRIER; 82 rw |= REQ_FUA;
83 rw |= REQ_UNPLUG | REQ_SYNC; 83 rw |= REQ_UNPLUG | REQ_SYNC;
84 84
85 retry:
86 bio = bio_alloc(GFP_NOIO, 1); 85 bio = bio_alloc(GFP_NOIO, 1);
87 bio->bi_bdev = bdev->md_bdev; 86 bio->bi_bdev = bdev->md_bdev;
88 bio->bi_sector = sector; 87 bio->bi_sector = sector;
@@ -100,17 +99,6 @@ static int _drbd_md_sync_page_io(struct drbd_conf *mdev,
100 wait_for_completion(&md_io.event); 99 wait_for_completion(&md_io.event);
101 ok = bio_flagged(bio, BIO_UPTODATE) && md_io.error == 0; 100 ok = bio_flagged(bio, BIO_UPTODATE) && md_io.error == 0;
102 101
103 /* check for unsupported barrier op.
104 * would rather check on EOPNOTSUPP, but that is not reliable.
105 * don't try again for ANY return value != 0 */
106 if (unlikely((bio->bi_rw & REQ_HARDBARRIER) && !ok)) {
107 /* Try again with no barrier */
108 dev_warn(DEV, "Barriers not supported on meta data device - disabling\n");
109 set_bit(MD_NO_BARRIER, &mdev->flags);
110 rw &= ~REQ_HARDBARRIER;
111 bio_put(bio);
112 goto retry;
113 }
114 out: 102 out:
115 bio_put(bio); 103 bio_put(bio);
116 return ok; 104 return ok;
@@ -284,18 +272,32 @@ w_al_write_transaction(struct drbd_conf *mdev, struct drbd_work *w, int unused)
284 u32 xor_sum = 0; 272 u32 xor_sum = 0;
285 273
286 if (!get_ldev(mdev)) { 274 if (!get_ldev(mdev)) {
287 dev_err(DEV, "get_ldev() failed in w_al_write_transaction\n"); 275 dev_err(DEV,
276 "disk is %s, cannot start al transaction (-%d +%d)\n",
277 drbd_disk_str(mdev->state.disk), evicted, new_enr);
288 complete(&((struct update_al_work *)w)->event); 278 complete(&((struct update_al_work *)w)->event);
289 return 1; 279 return 1;
290 } 280 }
291 /* do we have to do a bitmap write, first? 281 /* do we have to do a bitmap write, first?
292 * TODO reduce maximum latency: 282 * TODO reduce maximum latency:
293 * submit both bios, then wait for both, 283 * submit both bios, then wait for both,
294 * instead of doing two synchronous sector writes. */ 284 * instead of doing two synchronous sector writes.
285 * For now, we must not write the transaction,
286 * if we cannot write out the bitmap of the evicted extent. */
295 if (mdev->state.conn < C_CONNECTED && evicted != LC_FREE) 287 if (mdev->state.conn < C_CONNECTED && evicted != LC_FREE)
296 drbd_bm_write_sect(mdev, evicted/AL_EXT_PER_BM_SECT); 288 drbd_bm_write_sect(mdev, evicted/AL_EXT_PER_BM_SECT);
297 289
298 mutex_lock(&mdev->md_io_mutex); /* protects md_io_page, al_tr_cycle, ... */ 290 /* The bitmap write may have failed, causing a state change. */
291 if (mdev->state.disk < D_INCONSISTENT) {
292 dev_err(DEV,
293 "disk is %s, cannot write al transaction (-%d +%d)\n",
294 drbd_disk_str(mdev->state.disk), evicted, new_enr);
295 complete(&((struct update_al_work *)w)->event);
296 put_ldev(mdev);
297 return 1;
298 }
299
300 mutex_lock(&mdev->md_io_mutex); /* protects md_io_buffer, al_tr_cycle, ... */
299 buffer = (struct al_transaction *)page_address(mdev->md_io_page); 301 buffer = (struct al_transaction *)page_address(mdev->md_io_page);
300 302
301 buffer->magic = __constant_cpu_to_be32(DRBD_MAGIC); 303 buffer->magic = __constant_cpu_to_be32(DRBD_MAGIC);
@@ -739,7 +741,7 @@ void drbd_al_apply_to_bm(struct drbd_conf *mdev)
739 unsigned int enr; 741 unsigned int enr;
740 unsigned long add = 0; 742 unsigned long add = 0;
741 char ppb[10]; 743 char ppb[10];
742 int i; 744 int i, tmp;
743 745
744 wait_event(mdev->al_wait, lc_try_lock(mdev->act_log)); 746 wait_event(mdev->al_wait, lc_try_lock(mdev->act_log));
745 747
@@ -747,7 +749,9 @@ void drbd_al_apply_to_bm(struct drbd_conf *mdev)
747 enr = lc_element_by_index(mdev->act_log, i)->lc_number; 749 enr = lc_element_by_index(mdev->act_log, i)->lc_number;
748 if (enr == LC_FREE) 750 if (enr == LC_FREE)
749 continue; 751 continue;
750 add += drbd_bm_ALe_set_all(mdev, enr); 752 tmp = drbd_bm_ALe_set_all(mdev, enr);
753 dynamic_dev_dbg(DEV, "AL: set %d bits in extent %u\n", tmp, enr);
754 add += tmp;
751 } 755 }
752 756
753 lc_unlock(mdev->act_log); 757 lc_unlock(mdev->act_log);
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 9bdcf4393c0a..1ea1a34e78b2 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -114,11 +114,11 @@ struct drbd_conf;
114#define D_ASSERT(exp) if (!(exp)) \ 114#define D_ASSERT(exp) if (!(exp)) \
115 dev_err(DEV, "ASSERT( " #exp " ) in %s:%d\n", __FILE__, __LINE__) 115 dev_err(DEV, "ASSERT( " #exp " ) in %s:%d\n", __FILE__, __LINE__)
116 116
117#define ERR_IF(exp) if (({ \ 117#define ERR_IF(exp) if (({ \
118 int _b = (exp) != 0; \ 118 int _b = (exp) != 0; \
119 if (_b) dev_err(DEV, "%s: (%s) in %s:%d\n", \ 119 if (_b) dev_err(DEV, "ASSERT FAILED: %s: (%s) in %s:%d\n", \
120 __func__, #exp, __FILE__, __LINE__); \ 120 __func__, #exp, __FILE__, __LINE__); \
121 _b; \ 121 _b; \
122 })) 122 }))
123 123
124/* Defines to control fault insertion */ 124/* Defines to control fault insertion */
@@ -749,17 +749,12 @@ struct drbd_epoch {
749 749
750/* drbd_epoch flag bits */ 750/* drbd_epoch flag bits */
751enum { 751enum {
752 DE_BARRIER_IN_NEXT_EPOCH_ISSUED,
753 DE_BARRIER_IN_NEXT_EPOCH_DONE,
754 DE_CONTAINS_A_BARRIER,
755 DE_HAVE_BARRIER_NUMBER, 752 DE_HAVE_BARRIER_NUMBER,
756 DE_IS_FINISHING,
757}; 753};
758 754
759enum epoch_event { 755enum epoch_event {
760 EV_PUT, 756 EV_PUT,
761 EV_GOT_BARRIER_NR, 757 EV_GOT_BARRIER_NR,
762 EV_BARRIER_DONE,
763 EV_BECAME_LAST, 758 EV_BECAME_LAST,
764 EV_CLEANUP = 32, /* used as flag */ 759 EV_CLEANUP = 32, /* used as flag */
765}; 760};
@@ -801,11 +796,6 @@ enum {
801 __EE_CALL_AL_COMPLETE_IO, 796 __EE_CALL_AL_COMPLETE_IO,
802 __EE_MAY_SET_IN_SYNC, 797 __EE_MAY_SET_IN_SYNC,
803 798
804 /* This epoch entry closes an epoch using a barrier.
805 * On sucessful completion, the epoch is released,
806 * and the P_BARRIER_ACK send. */
807 __EE_IS_BARRIER,
808
809 /* In case a barrier failed, 799 /* In case a barrier failed,
810 * we need to resubmit without the barrier flag. */ 800 * we need to resubmit without the barrier flag. */
811 __EE_RESUBMITTED, 801 __EE_RESUBMITTED,
@@ -820,7 +810,6 @@ enum {
820}; 810};
821#define EE_CALL_AL_COMPLETE_IO (1<<__EE_CALL_AL_COMPLETE_IO) 811#define EE_CALL_AL_COMPLETE_IO (1<<__EE_CALL_AL_COMPLETE_IO)
822#define EE_MAY_SET_IN_SYNC (1<<__EE_MAY_SET_IN_SYNC) 812#define EE_MAY_SET_IN_SYNC (1<<__EE_MAY_SET_IN_SYNC)
823#define EE_IS_BARRIER (1<<__EE_IS_BARRIER)
824#define EE_RESUBMITTED (1<<__EE_RESUBMITTED) 813#define EE_RESUBMITTED (1<<__EE_RESUBMITTED)
825#define EE_WAS_ERROR (1<<__EE_WAS_ERROR) 814#define EE_WAS_ERROR (1<<__EE_WAS_ERROR)
826#define EE_HAS_DIGEST (1<<__EE_HAS_DIGEST) 815#define EE_HAS_DIGEST (1<<__EE_HAS_DIGEST)
@@ -843,16 +832,15 @@ enum {
843 * Gets cleared when the state.conn 832 * Gets cleared when the state.conn
844 * goes into C_CONNECTED state. */ 833 * goes into C_CONNECTED state. */
845 WRITE_BM_AFTER_RESYNC, /* A kmalloc() during resync failed */ 834 WRITE_BM_AFTER_RESYNC, /* A kmalloc() during resync failed */
846 NO_BARRIER_SUPP, /* underlying block device doesn't implement barriers */
847 CONSIDER_RESYNC, 835 CONSIDER_RESYNC,
848 836
849 MD_NO_BARRIER, /* meta data device does not support barriers, 837 MD_NO_FUA, /* Users wants us to not use FUA/FLUSH on meta data dev */
850 so don't even try */
851 SUSPEND_IO, /* suspend application io */ 838 SUSPEND_IO, /* suspend application io */
852 BITMAP_IO, /* suspend application io; 839 BITMAP_IO, /* suspend application io;
853 once no more io in flight, start bitmap io */ 840 once no more io in flight, start bitmap io */
854 BITMAP_IO_QUEUED, /* Started bitmap IO */ 841 BITMAP_IO_QUEUED, /* Started bitmap IO */
855 GO_DISKLESS, /* Disk failed, local_cnt reached zero, we are going diskless */ 842 GO_DISKLESS, /* Disk is being detached, on io-error or admin request. */
843 WAS_IO_ERROR, /* Local disk failed returned IO error */
856 RESYNC_AFTER_NEG, /* Resync after online grow after the attach&negotiate finished. */ 844 RESYNC_AFTER_NEG, /* Resync after online grow after the attach&negotiate finished. */
857 NET_CONGESTED, /* The data socket is congested */ 845 NET_CONGESTED, /* The data socket is congested */
858 846
@@ -947,7 +935,6 @@ enum write_ordering_e {
947 WO_none, 935 WO_none,
948 WO_drain_io, 936 WO_drain_io,
949 WO_bdev_flush, 937 WO_bdev_flush,
950 WO_bio_barrier
951}; 938};
952 939
953struct fifo_buffer { 940struct fifo_buffer {
@@ -1281,6 +1268,7 @@ extern int drbd_bmio_set_n_write(struct drbd_conf *mdev);
1281extern int drbd_bmio_clear_n_write(struct drbd_conf *mdev); 1268extern int drbd_bmio_clear_n_write(struct drbd_conf *mdev);
1282extern int drbd_bitmap_io(struct drbd_conf *mdev, int (*io_fn)(struct drbd_conf *), char *why); 1269extern int drbd_bitmap_io(struct drbd_conf *mdev, int (*io_fn)(struct drbd_conf *), char *why);
1283extern void drbd_go_diskless(struct drbd_conf *mdev); 1270extern void drbd_go_diskless(struct drbd_conf *mdev);
1271extern void drbd_ldev_destroy(struct drbd_conf *mdev);
1284 1272
1285 1273
1286/* Meta data layout 1274/* Meta data layout
@@ -1798,17 +1786,17 @@ static inline void __drbd_chk_io_error_(struct drbd_conf *mdev, int forcedetach,
1798 case EP_PASS_ON: 1786 case EP_PASS_ON:
1799 if (!forcedetach) { 1787 if (!forcedetach) {
1800 if (__ratelimit(&drbd_ratelimit_state)) 1788 if (__ratelimit(&drbd_ratelimit_state))
1801 dev_err(DEV, "Local IO failed in %s." 1789 dev_err(DEV, "Local IO failed in %s.\n", where);
1802 "Passing error on...\n", where);
1803 break; 1790 break;
1804 } 1791 }
1805 /* NOTE fall through to detach case if forcedetach set */ 1792 /* NOTE fall through to detach case if forcedetach set */
1806 case EP_DETACH: 1793 case EP_DETACH:
1807 case EP_CALL_HELPER: 1794 case EP_CALL_HELPER:
1795 set_bit(WAS_IO_ERROR, &mdev->flags);
1808 if (mdev->state.disk > D_FAILED) { 1796 if (mdev->state.disk > D_FAILED) {
1809 _drbd_set_state(_NS(mdev, disk, D_FAILED), CS_HARD, NULL); 1797 _drbd_set_state(_NS(mdev, disk, D_FAILED), CS_HARD, NULL);
1810 dev_err(DEV, "Local IO failed in %s." 1798 dev_err(DEV,
1811 "Detaching...\n", where); 1799 "Local IO failed in %s. Detaching...\n", where);
1812 } 1800 }
1813 break; 1801 break;
1814 } 1802 }
@@ -1874,7 +1862,7 @@ static inline sector_t drbd_md_last_sector(struct drbd_backing_dev *bdev)
1874static inline sector_t drbd_get_capacity(struct block_device *bdev) 1862static inline sector_t drbd_get_capacity(struct block_device *bdev)
1875{ 1863{
1876 /* return bdev ? get_capacity(bdev->bd_disk) : 0; */ 1864 /* return bdev ? get_capacity(bdev->bd_disk) : 0; */
1877 return bdev ? bdev->bd_inode->i_size >> 9 : 0; 1865 return bdev ? i_size_read(bdev->bd_inode) >> 9 : 0;
1878} 1866}
1879 1867
1880/** 1868/**
@@ -2127,7 +2115,11 @@ static inline void put_ldev(struct drbd_conf *mdev)
2127 __release(local); 2115 __release(local);
2128 D_ASSERT(i >= 0); 2116 D_ASSERT(i >= 0);
2129 if (i == 0) { 2117 if (i == 0) {
2118 if (mdev->state.disk == D_DISKLESS)
2119 /* even internal references gone, safe to destroy */
2120 drbd_ldev_destroy(mdev);
2130 if (mdev->state.disk == D_FAILED) 2121 if (mdev->state.disk == D_FAILED)
2122 /* all application IO references gone. */
2131 drbd_go_diskless(mdev); 2123 drbd_go_diskless(mdev);
2132 wake_up(&mdev->misc_wait); 2124 wake_up(&mdev->misc_wait);
2133 } 2125 }
@@ -2138,6 +2130,10 @@ static inline int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_stat
2138{ 2130{
2139 int io_allowed; 2131 int io_allowed;
2140 2132
2133 /* never get a reference while D_DISKLESS */
2134 if (mdev->state.disk == D_DISKLESS)
2135 return 0;
2136
2141 atomic_inc(&mdev->local_cnt); 2137 atomic_inc(&mdev->local_cnt);
2142 io_allowed = (mdev->state.disk >= mins); 2138 io_allowed = (mdev->state.disk >= mins);
2143 if (!io_allowed) 2139 if (!io_allowed)
@@ -2406,12 +2402,12 @@ static inline void drbd_md_flush(struct drbd_conf *mdev)
2406{ 2402{
2407 int r; 2403 int r;
2408 2404
2409 if (test_bit(MD_NO_BARRIER, &mdev->flags)) 2405 if (test_bit(MD_NO_FUA, &mdev->flags))
2410 return; 2406 return;
2411 2407
2412 r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_KERNEL, NULL); 2408 r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_KERNEL, NULL);
2413 if (r) { 2409 if (r) {
2414 set_bit(MD_NO_BARRIER, &mdev->flags); 2410 set_bit(MD_NO_FUA, &mdev->flags);
2415 dev_err(DEV, "meta data flush failed with status %d, disabling md-flushes\n", r); 2411 dev_err(DEV, "meta data flush failed with status %d, disabling md-flushes\n", r);
2416 } 2412 }
2417} 2413}
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 25c7a73c5062..6be5401d0e88 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -835,6 +835,15 @@ static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state
835 ns.conn != C_UNCONNECTED && ns.conn != C_DISCONNECTING && ns.conn <= C_TEAR_DOWN) 835 ns.conn != C_UNCONNECTED && ns.conn != C_DISCONNECTING && ns.conn <= C_TEAR_DOWN)
836 ns.conn = os.conn; 836 ns.conn = os.conn;
837 837
838 /* we cannot fail (again) if we already detached */
839 if (ns.disk == D_FAILED && os.disk == D_DISKLESS)
840 ns.disk = D_DISKLESS;
841
842 /* if we are only D_ATTACHING yet,
843 * we can (and should) go directly to D_DISKLESS. */
844 if (ns.disk == D_FAILED && os.disk == D_ATTACHING)
845 ns.disk = D_DISKLESS;
846
838 /* After C_DISCONNECTING only C_STANDALONE may follow */ 847 /* After C_DISCONNECTING only C_STANDALONE may follow */
839 if (os.conn == C_DISCONNECTING && ns.conn != C_STANDALONE) 848 if (os.conn == C_DISCONNECTING && ns.conn != C_STANDALONE)
840 ns.conn = os.conn; 849 ns.conn = os.conn;
@@ -1056,7 +1065,15 @@ int __drbd_set_state(struct drbd_conf *mdev,
1056 !test_and_set_bit(CONFIG_PENDING, &mdev->flags)) 1065 !test_and_set_bit(CONFIG_PENDING, &mdev->flags))
1057 set_bit(DEVICE_DYING, &mdev->flags); 1066 set_bit(DEVICE_DYING, &mdev->flags);
1058 1067
1059 mdev->state.i = ns.i; 1068 /* if we are going -> D_FAILED or D_DISKLESS, grab one extra reference
1069 * on the ldev here, to be sure the transition -> D_DISKLESS resp.
1070 * drbd_ldev_destroy() won't happen before our corresponding
1071 * after_state_ch works run, where we put_ldev again. */
1072 if ((os.disk != D_FAILED && ns.disk == D_FAILED) ||
1073 (os.disk != D_DISKLESS && ns.disk == D_DISKLESS))
1074 atomic_inc(&mdev->local_cnt);
1075
1076 mdev->state = ns;
1060 wake_up(&mdev->misc_wait); 1077 wake_up(&mdev->misc_wait);
1061 wake_up(&mdev->state_wait); 1078 wake_up(&mdev->state_wait);
1062 1079
@@ -1268,7 +1285,6 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os,
1268 if (test_bit(NEW_CUR_UUID, &mdev->flags)) { 1285 if (test_bit(NEW_CUR_UUID, &mdev->flags)) {
1269 drbd_uuid_new_current(mdev); 1286 drbd_uuid_new_current(mdev);
1270 clear_bit(NEW_CUR_UUID, &mdev->flags); 1287 clear_bit(NEW_CUR_UUID, &mdev->flags);
1271 drbd_md_sync(mdev);
1272 } 1288 }
1273 spin_lock_irq(&mdev->req_lock); 1289 spin_lock_irq(&mdev->req_lock);
1274 _drbd_set_state(_NS(mdev, susp_fen, 0), CS_VERBOSE, NULL); 1290 _drbd_set_state(_NS(mdev, susp_fen, 0), CS_VERBOSE, NULL);
@@ -1365,63 +1381,64 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os,
1365 os.disk > D_INCONSISTENT && ns.disk == D_INCONSISTENT) 1381 os.disk > D_INCONSISTENT && ns.disk == D_INCONSISTENT)
1366 drbd_queue_bitmap_io(mdev, &drbd_bmio_set_n_write, NULL, "set_n_write from invalidate"); 1382 drbd_queue_bitmap_io(mdev, &drbd_bmio_set_n_write, NULL, "set_n_write from invalidate");
1367 1383
1368 /* first half of local IO error */ 1384 /* first half of local IO error, failure to attach,
1369 if (os.disk > D_FAILED && ns.disk == D_FAILED) { 1385 * or administrative detach */
1370 enum drbd_io_error_p eh = EP_PASS_ON; 1386 if (os.disk != D_FAILED && ns.disk == D_FAILED) {
1387 enum drbd_io_error_p eh;
1388 int was_io_error;
1389 /* corresponding get_ldev was in __drbd_set_state, to serialize
1390 * our cleanup here with the transition to D_DISKLESS,
1391 * so it is safe to dreference ldev here. */
1392 eh = mdev->ldev->dc.on_io_error;
1393 was_io_error = test_and_clear_bit(WAS_IO_ERROR, &mdev->flags);
1394
1395 /* current state still has to be D_FAILED,
1396 * there is only one way out: to D_DISKLESS,
1397 * and that may only happen after our put_ldev below. */
1398 if (mdev->state.disk != D_FAILED)
1399 dev_err(DEV,
1400 "ASSERT FAILED: disk is %s during detach\n",
1401 drbd_disk_str(mdev->state.disk));
1371 1402
1372 if (drbd_send_state(mdev)) 1403 if (drbd_send_state(mdev))
1373 dev_warn(DEV, "Notified peer that my disk is broken.\n"); 1404 dev_warn(DEV, "Notified peer that I am detaching my disk\n");
1374 else 1405 else
1375 dev_err(DEV, "Sending state for drbd_io_error() failed\n"); 1406 dev_err(DEV, "Sending state for detaching disk failed\n");
1376 1407
1377 drbd_rs_cancel_all(mdev); 1408 drbd_rs_cancel_all(mdev);
1378 1409
1379 if (get_ldev_if_state(mdev, D_FAILED)) { 1410 /* In case we want to get something to stable storage still,
1380 eh = mdev->ldev->dc.on_io_error; 1411 * this may be the last chance.
1381 put_ldev(mdev); 1412 * Following put_ldev may transition to D_DISKLESS. */
1382 } 1413 drbd_md_sync(mdev);
1383 if (eh == EP_CALL_HELPER) 1414 put_ldev(mdev);
1415
1416 if (was_io_error && eh == EP_CALL_HELPER)
1384 drbd_khelper(mdev, "local-io-error"); 1417 drbd_khelper(mdev, "local-io-error");
1385 } 1418 }
1386 1419
1420 /* second half of local IO error, failure to attach,
1421 * or administrative detach,
1422 * after local_cnt references have reached zero again */
1423 if (os.disk != D_DISKLESS && ns.disk == D_DISKLESS) {
1424 /* We must still be diskless,
1425 * re-attach has to be serialized with this! */
1426 if (mdev->state.disk != D_DISKLESS)
1427 dev_err(DEV,
1428 "ASSERT FAILED: disk is %s while going diskless\n",
1429 drbd_disk_str(mdev->state.disk));
1387 1430
1388 /* second half of local IO error handling, 1431 mdev->rs_total = 0;
1389 * after local_cnt references have reached zero: */ 1432 mdev->rs_failed = 0;
1390 if (os.disk == D_FAILED && ns.disk == D_DISKLESS) { 1433 atomic_set(&mdev->rs_pending_cnt, 0);
1391 mdev->rs_total = 0;
1392 mdev->rs_failed = 0;
1393 atomic_set(&mdev->rs_pending_cnt, 0);
1394 }
1395
1396 if (os.disk > D_DISKLESS && ns.disk == D_DISKLESS) {
1397 /* We must still be diskless,
1398 * re-attach has to be serialized with this! */
1399 if (mdev->state.disk != D_DISKLESS)
1400 dev_err(DEV,
1401 "ASSERT FAILED: disk is %s while going diskless\n",
1402 drbd_disk_str(mdev->state.disk));
1403 1434
1404 /* we cannot assert local_cnt == 0 here, as get_ldev_if_state
1405 * will inc/dec it frequently. Since we became D_DISKLESS, no
1406 * one has touched the protected members anymore, though, so we
1407 * are safe to free them here. */
1408 if (drbd_send_state(mdev)) 1435 if (drbd_send_state(mdev))
1409 dev_warn(DEV, "Notified peer that I detached my disk.\n"); 1436 dev_warn(DEV, "Notified peer that I'm now diskless.\n");
1410 else 1437 else
1411 dev_err(DEV, "Sending state for detach failed\n"); 1438 dev_err(DEV, "Sending state for being diskless failed\n");
1412 1439 /* corresponding get_ldev in __drbd_set_state
1413 lc_destroy(mdev->resync); 1440 * this may finaly trigger drbd_ldev_destroy. */
1414 mdev->resync = NULL; 1441 put_ldev(mdev);
1415 lc_destroy(mdev->act_log);
1416 mdev->act_log = NULL;
1417 __no_warn(local,
1418 drbd_free_bc(mdev->ldev);
1419 mdev->ldev = NULL;);
1420
1421 if (mdev->md_io_tmpp) {
1422 __free_page(mdev->md_io_tmpp);
1423 mdev->md_io_tmpp = NULL;
1424 }
1425 } 1442 }
1426 1443
1427 /* Disks got bigger while they were detached */ 1444 /* Disks got bigger while they were detached */
@@ -2772,11 +2789,6 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
2772 2789
2773 drbd_set_defaults(mdev); 2790 drbd_set_defaults(mdev);
2774 2791
2775 /* for now, we do NOT yet support it,
2776 * even though we start some framework
2777 * to eventually support barriers */
2778 set_bit(NO_BARRIER_SUPP, &mdev->flags);
2779
2780 atomic_set(&mdev->ap_bio_cnt, 0); 2792 atomic_set(&mdev->ap_bio_cnt, 0);
2781 atomic_set(&mdev->ap_pending_cnt, 0); 2793 atomic_set(&mdev->ap_pending_cnt, 0);
2782 atomic_set(&mdev->rs_pending_cnt, 0); 2794 atomic_set(&mdev->rs_pending_cnt, 0);
@@ -2842,7 +2854,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
2842 drbd_thread_init(mdev, &mdev->asender, drbd_asender); 2854 drbd_thread_init(mdev, &mdev->asender, drbd_asender);
2843 2855
2844 mdev->agreed_pro_version = PRO_VERSION_MAX; 2856 mdev->agreed_pro_version = PRO_VERSION_MAX;
2845 mdev->write_ordering = WO_bio_barrier; 2857 mdev->write_ordering = WO_bdev_flush;
2846 mdev->resync_wenr = LC_FREE; 2858 mdev->resync_wenr = LC_FREE;
2847} 2859}
2848 2860
@@ -2899,7 +2911,6 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
2899 D_ASSERT(list_empty(&mdev->resync_work.list)); 2911 D_ASSERT(list_empty(&mdev->resync_work.list));
2900 D_ASSERT(list_empty(&mdev->unplug_work.list)); 2912 D_ASSERT(list_empty(&mdev->unplug_work.list));
2901 D_ASSERT(list_empty(&mdev->go_diskless.list)); 2913 D_ASSERT(list_empty(&mdev->go_diskless.list));
2902
2903} 2914}
2904 2915
2905 2916
@@ -3660,6 +3671,8 @@ void drbd_uuid_new_current(struct drbd_conf *mdev) __must_hold(local)
3660 3671
3661 get_random_bytes(&val, sizeof(u64)); 3672 get_random_bytes(&val, sizeof(u64));
3662 _drbd_uuid_set(mdev, UI_CURRENT, val); 3673 _drbd_uuid_set(mdev, UI_CURRENT, val);
3674 /* get it to stable storage _now_ */
3675 drbd_md_sync(mdev);
3663} 3676}
3664 3677
3665void drbd_uuid_set_bm(struct drbd_conf *mdev, u64 val) __must_hold(local) 3678void drbd_uuid_set_bm(struct drbd_conf *mdev, u64 val) __must_hold(local)
@@ -3756,19 +3769,31 @@ static int w_bitmap_io(struct drbd_conf *mdev, struct drbd_work *w, int unused)
3756 return 1; 3769 return 1;
3757} 3770}
3758 3771
3772void drbd_ldev_destroy(struct drbd_conf *mdev)
3773{
3774 lc_destroy(mdev->resync);
3775 mdev->resync = NULL;
3776 lc_destroy(mdev->act_log);
3777 mdev->act_log = NULL;
3778 __no_warn(local,
3779 drbd_free_bc(mdev->ldev);
3780 mdev->ldev = NULL;);
3781
3782 if (mdev->md_io_tmpp) {
3783 __free_page(mdev->md_io_tmpp);
3784 mdev->md_io_tmpp = NULL;
3785 }
3786 clear_bit(GO_DISKLESS, &mdev->flags);
3787}
3788
3759static int w_go_diskless(struct drbd_conf *mdev, struct drbd_work *w, int unused) 3789static int w_go_diskless(struct drbd_conf *mdev, struct drbd_work *w, int unused)
3760{ 3790{
3761 D_ASSERT(mdev->state.disk == D_FAILED); 3791 D_ASSERT(mdev->state.disk == D_FAILED);
3762 /* we cannot assert local_cnt == 0 here, as get_ldev_if_state will 3792 /* we cannot assert local_cnt == 0 here, as get_ldev_if_state will
3763 * inc/dec it frequently. Once we are D_DISKLESS, no one will touch 3793 * inc/dec it frequently. Once we are D_DISKLESS, no one will touch
3764 * the protected members anymore, though, so in the after_state_ch work 3794 * the protected members anymore, though, so once put_ldev reaches zero
3765 * it will be safe to free them. */ 3795 * again, it will be safe to free them. */
3766 drbd_force_state(mdev, NS(disk, D_DISKLESS)); 3796 drbd_force_state(mdev, NS(disk, D_DISKLESS));
3767 /* We need to wait for return of references checked out while we still
3768 * have been D_FAILED, though (drbd_md_sync, bitmap io). */
3769 wait_event(mdev->misc_wait, !atomic_read(&mdev->local_cnt));
3770
3771 clear_bit(GO_DISKLESS, &mdev->flags);
3772 return 1; 3797 return 1;
3773} 3798}
3774 3799
@@ -3777,9 +3802,6 @@ void drbd_go_diskless(struct drbd_conf *mdev)
3777 D_ASSERT(mdev->state.disk == D_FAILED); 3802 D_ASSERT(mdev->state.disk == D_FAILED);
3778 if (!test_and_set_bit(GO_DISKLESS, &mdev->flags)) 3803 if (!test_and_set_bit(GO_DISKLESS, &mdev->flags))
3779 drbd_queue_work(&mdev->data.work, &mdev->go_diskless); 3804 drbd_queue_work(&mdev->data.work, &mdev->go_diskless);
3780 /* don't drbd_queue_work_front,
3781 * we need to serialize with the after_state_ch work
3782 * of the -> D_FAILED transition. */
3783} 3805}
3784 3806
3785/** 3807/**
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index 87925e97e613..29e5c70e4e26 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -870,6 +870,11 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
870 retcode = ERR_DISK_CONFIGURED; 870 retcode = ERR_DISK_CONFIGURED;
871 goto fail; 871 goto fail;
872 } 872 }
873 /* It may just now have detached because of IO error. Make sure
874 * drbd_ldev_destroy is done already, we may end up here very fast,
875 * e.g. if someone calls attach from the on-io-error handler,
876 * to realize a "hot spare" feature (not that I'd recommend that) */
877 wait_event(mdev->misc_wait, !atomic_read(&mdev->local_cnt));
873 878
874 /* allocation not in the IO path, cqueue thread context */ 879 /* allocation not in the IO path, cqueue thread context */
875 nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL); 880 nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL);
@@ -1098,9 +1103,9 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1098 /* Reset the "barriers don't work" bits here, then force meta data to 1103 /* Reset the "barriers don't work" bits here, then force meta data to
1099 * be written, to ensure we determine if barriers are supported. */ 1104 * be written, to ensure we determine if barriers are supported. */
1100 if (nbc->dc.no_md_flush) 1105 if (nbc->dc.no_md_flush)
1101 set_bit(MD_NO_BARRIER, &mdev->flags); 1106 set_bit(MD_NO_FUA, &mdev->flags);
1102 else 1107 else
1103 clear_bit(MD_NO_BARRIER, &mdev->flags); 1108 clear_bit(MD_NO_FUA, &mdev->flags);
1104 1109
1105 /* Point of no return reached. 1110 /* Point of no return reached.
1106 * Devices and memory are no longer released by error cleanup below. 1111 * Devices and memory are no longer released by error cleanup below.
@@ -1112,8 +1117,8 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1112 nbc = NULL; 1117 nbc = NULL;
1113 resync_lru = NULL; 1118 resync_lru = NULL;
1114 1119
1115 mdev->write_ordering = WO_bio_barrier; 1120 mdev->write_ordering = WO_bdev_flush;
1116 drbd_bump_write_ordering(mdev, WO_bio_barrier); 1121 drbd_bump_write_ordering(mdev, WO_bdev_flush);
1117 1122
1118 if (drbd_md_test_flag(mdev->ldev, MDF_CRASHED_PRIMARY)) 1123 if (drbd_md_test_flag(mdev->ldev, MDF_CRASHED_PRIMARY))
1119 set_bit(CRASHED_PRIMARY, &mdev->flags); 1124 set_bit(CRASHED_PRIMARY, &mdev->flags);
@@ -1262,7 +1267,7 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1262 force_diskless_dec: 1267 force_diskless_dec:
1263 put_ldev(mdev); 1268 put_ldev(mdev);
1264 force_diskless: 1269 force_diskless:
1265 drbd_force_state(mdev, NS(disk, D_DISKLESS)); 1270 drbd_force_state(mdev, NS(disk, D_FAILED));
1266 drbd_md_sync(mdev); 1271 drbd_md_sync(mdev);
1267 release_bdev2_fail: 1272 release_bdev2_fail:
1268 if (nbc) 1273 if (nbc)
@@ -1285,10 +1290,19 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1285 return 0; 1290 return 0;
1286} 1291}
1287 1292
1293/* Detaching the disk is a process in multiple stages. First we need to lock
1294 * out application IO, in-flight IO, IO stuck in drbd_al_begin_io.
1295 * Then we transition to D_DISKLESS, and wait for put_ldev() to return all
1296 * internal references as well.
1297 * Only then we have finally detached. */
1288static int drbd_nl_detach(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp, 1298static int drbd_nl_detach(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1289 struct drbd_nl_cfg_reply *reply) 1299 struct drbd_nl_cfg_reply *reply)
1290{ 1300{
1301 drbd_suspend_io(mdev); /* so no-one is stuck in drbd_al_begin_io */
1291 reply->ret_code = drbd_request_state(mdev, NS(disk, D_DISKLESS)); 1302 reply->ret_code = drbd_request_state(mdev, NS(disk, D_DISKLESS));
1303 if (mdev->state.disk == D_DISKLESS)
1304 wait_event(mdev->misc_wait, !atomic_read(&mdev->local_cnt));
1305 drbd_resume_io(mdev);
1292 return 0; 1306 return 0;
1293} 1307}
1294 1308
@@ -1953,7 +1967,6 @@ static int drbd_nl_resume_io(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
1953 if (test_bit(NEW_CUR_UUID, &mdev->flags)) { 1967 if (test_bit(NEW_CUR_UUID, &mdev->flags)) {
1954 drbd_uuid_new_current(mdev); 1968 drbd_uuid_new_current(mdev);
1955 clear_bit(NEW_CUR_UUID, &mdev->flags); 1969 clear_bit(NEW_CUR_UUID, &mdev->flags);
1956 drbd_md_sync(mdev);
1957 } 1970 }
1958 drbd_suspend_io(mdev); 1971 drbd_suspend_io(mdev);
1959 reply->ret_code = drbd_request_state(mdev, NS3(susp, 0, susp_nod, 0, susp_fen, 0)); 1972 reply->ret_code = drbd_request_state(mdev, NS3(susp, 0, susp_nod, 0, susp_fen, 0));
diff --git a/drivers/block/drbd/drbd_proc.c b/drivers/block/drbd/drbd_proc.c
index ad325c5d0ce1..7e6ac307e2de 100644
--- a/drivers/block/drbd/drbd_proc.c
+++ b/drivers/block/drbd/drbd_proc.c
@@ -158,7 +158,6 @@ static int drbd_seq_show(struct seq_file *seq, void *v)
158 [WO_none] = 'n', 158 [WO_none] = 'n',
159 [WO_drain_io] = 'd', 159 [WO_drain_io] = 'd',
160 [WO_bdev_flush] = 'f', 160 [WO_bdev_flush] = 'f',
161 [WO_bio_barrier] = 'b',
162 }; 161 };
163 162
164 seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n", 163 seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index efd6169acf2f..24487d4fb202 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -36,7 +36,6 @@
36#include <linux/memcontrol.h> 36#include <linux/memcontrol.h>
37#include <linux/mm_inline.h> 37#include <linux/mm_inline.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/smp_lock.h>
40#include <linux/pkt_sched.h> 39#include <linux/pkt_sched.h>
41#define __KERNEL_SYSCALLS__ 40#define __KERNEL_SYSCALLS__
42#include <linux/unistd.h> 41#include <linux/unistd.h>
@@ -49,11 +48,6 @@
49 48
50#include "drbd_vli.h" 49#include "drbd_vli.h"
51 50
52struct flush_work {
53 struct drbd_work w;
54 struct drbd_epoch *epoch;
55};
56
57enum finish_epoch { 51enum finish_epoch {
58 FE_STILL_LIVE, 52 FE_STILL_LIVE,
59 FE_DESTROYED, 53 FE_DESTROYED,
@@ -66,16 +60,6 @@ static int drbd_do_auth(struct drbd_conf *mdev);
66static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *, struct drbd_epoch *, enum epoch_event); 60static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *, struct drbd_epoch *, enum epoch_event);
67static int e_end_block(struct drbd_conf *, struct drbd_work *, int); 61static int e_end_block(struct drbd_conf *, struct drbd_work *, int);
68 62
69static struct drbd_epoch *previous_epoch(struct drbd_conf *mdev, struct drbd_epoch *epoch)
70{
71 struct drbd_epoch *prev;
72 spin_lock(&mdev->epoch_lock);
73 prev = list_entry(epoch->list.prev, struct drbd_epoch, list);
74 if (prev == epoch || prev == mdev->current_epoch)
75 prev = NULL;
76 spin_unlock(&mdev->epoch_lock);
77 return prev;
78}
79 63
80#define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN) 64#define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN)
81 65
@@ -981,7 +965,7 @@ static int drbd_recv_header(struct drbd_conf *mdev, enum drbd_packets *cmd, unsi
981 return TRUE; 965 return TRUE;
982} 966}
983 967
984static enum finish_epoch drbd_flush_after_epoch(struct drbd_conf *mdev, struct drbd_epoch *epoch) 968static void drbd_flush(struct drbd_conf *mdev)
985{ 969{
986 int rv; 970 int rv;
987 971
@@ -997,24 +981,6 @@ static enum finish_epoch drbd_flush_after_epoch(struct drbd_conf *mdev, struct d
997 } 981 }
998 put_ldev(mdev); 982 put_ldev(mdev);
999 } 983 }
1000
1001 return drbd_may_finish_epoch(mdev, epoch, EV_BARRIER_DONE);
1002}
1003
1004static int w_flush(struct drbd_conf *mdev, struct drbd_work *w, int cancel)
1005{
1006 struct flush_work *fw = (struct flush_work *)w;
1007 struct drbd_epoch *epoch = fw->epoch;
1008
1009 kfree(w);
1010
1011 if (!test_and_set_bit(DE_BARRIER_IN_NEXT_EPOCH_ISSUED, &epoch->flags))
1012 drbd_flush_after_epoch(mdev, epoch);
1013
1014 drbd_may_finish_epoch(mdev, epoch, EV_PUT |
1015 (mdev->state.conn < C_CONNECTED ? EV_CLEANUP : 0));
1016
1017 return 1;
1018} 984}
1019 985
1020/** 986/**
@@ -1027,15 +993,13 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
1027 struct drbd_epoch *epoch, 993 struct drbd_epoch *epoch,
1028 enum epoch_event ev) 994 enum epoch_event ev)
1029{ 995{
1030 int finish, epoch_size; 996 int epoch_size;
1031 struct drbd_epoch *next_epoch; 997 struct drbd_epoch *next_epoch;
1032 int schedule_flush = 0;
1033 enum finish_epoch rv = FE_STILL_LIVE; 998 enum finish_epoch rv = FE_STILL_LIVE;
1034 999
1035 spin_lock(&mdev->epoch_lock); 1000 spin_lock(&mdev->epoch_lock);
1036 do { 1001 do {
1037 next_epoch = NULL; 1002 next_epoch = NULL;
1038 finish = 0;
1039 1003
1040 epoch_size = atomic_read(&epoch->epoch_size); 1004 epoch_size = atomic_read(&epoch->epoch_size);
1041 1005
@@ -1045,16 +1009,6 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
1045 break; 1009 break;
1046 case EV_GOT_BARRIER_NR: 1010 case EV_GOT_BARRIER_NR:
1047 set_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags); 1011 set_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags);
1048
1049 /* Special case: If we just switched from WO_bio_barrier to
1050 WO_bdev_flush we should not finish the current epoch */
1051 if (test_bit(DE_CONTAINS_A_BARRIER, &epoch->flags) && epoch_size == 1 &&
1052 mdev->write_ordering != WO_bio_barrier &&
1053 epoch == mdev->current_epoch)
1054 clear_bit(DE_CONTAINS_A_BARRIER, &epoch->flags);
1055 break;
1056 case EV_BARRIER_DONE:
1057 set_bit(DE_BARRIER_IN_NEXT_EPOCH_DONE, &epoch->flags);
1058 break; 1012 break;
1059 case EV_BECAME_LAST: 1013 case EV_BECAME_LAST:
1060 /* nothing to do*/ 1014 /* nothing to do*/
@@ -1063,23 +1017,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
1063 1017
1064 if (epoch_size != 0 && 1018 if (epoch_size != 0 &&
1065 atomic_read(&epoch->active) == 0 && 1019 atomic_read(&epoch->active) == 0 &&
1066 test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags) && 1020 test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags)) {
1067 epoch->list.prev == &mdev->current_epoch->list &&
1068 !test_bit(DE_IS_FINISHING, &epoch->flags)) {
1069 /* Nearly all conditions are met to finish that epoch... */
1070 if (test_bit(DE_BARRIER_IN_NEXT_EPOCH_DONE, &epoch->flags) ||
1071 mdev->write_ordering == WO_none ||
1072 (epoch_size == 1 && test_bit(DE_CONTAINS_A_BARRIER, &epoch->flags)) ||
1073 ev & EV_CLEANUP) {
1074 finish = 1;
1075 set_bit(DE_IS_FINISHING, &epoch->flags);
1076 } else if (!test_bit(DE_BARRIER_IN_NEXT_EPOCH_ISSUED, &epoch->flags) &&
1077 mdev->write_ordering == WO_bio_barrier) {
1078 atomic_inc(&epoch->active);
1079 schedule_flush = 1;
1080 }
1081 }
1082 if (finish) {
1083 if (!(ev & EV_CLEANUP)) { 1021 if (!(ev & EV_CLEANUP)) {
1084 spin_unlock(&mdev->epoch_lock); 1022 spin_unlock(&mdev->epoch_lock);
1085 drbd_send_b_ack(mdev, epoch->barrier_nr, epoch_size); 1023 drbd_send_b_ack(mdev, epoch->barrier_nr, epoch_size);
@@ -1102,6 +1040,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
1102 /* atomic_set(&epoch->active, 0); is already zero */ 1040 /* atomic_set(&epoch->active, 0); is already zero */
1103 if (rv == FE_STILL_LIVE) 1041 if (rv == FE_STILL_LIVE)
1104 rv = FE_RECYCLED; 1042 rv = FE_RECYCLED;
1043 wake_up(&mdev->ee_wait);
1105 } 1044 }
1106 } 1045 }
1107 1046
@@ -1113,22 +1052,6 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
1113 1052
1114 spin_unlock(&mdev->epoch_lock); 1053 spin_unlock(&mdev->epoch_lock);
1115 1054
1116 if (schedule_flush) {
1117 struct flush_work *fw;
1118 fw = kmalloc(sizeof(*fw), GFP_ATOMIC);
1119 if (fw) {
1120 fw->w.cb = w_flush;
1121 fw->epoch = epoch;
1122 drbd_queue_work(&mdev->data.work, &fw->w);
1123 } else {
1124 dev_warn(DEV, "Could not kmalloc a flush_work obj\n");
1125 set_bit(DE_BARRIER_IN_NEXT_EPOCH_ISSUED, &epoch->flags);
1126 /* That is not a recursion, only one level */
1127 drbd_may_finish_epoch(mdev, epoch, EV_BARRIER_DONE);
1128 drbd_may_finish_epoch(mdev, epoch, EV_PUT);
1129 }
1130 }
1131
1132 return rv; 1055 return rv;
1133} 1056}
1134 1057
@@ -1144,19 +1067,16 @@ void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo)
1144 [WO_none] = "none", 1067 [WO_none] = "none",
1145 [WO_drain_io] = "drain", 1068 [WO_drain_io] = "drain",
1146 [WO_bdev_flush] = "flush", 1069 [WO_bdev_flush] = "flush",
1147 [WO_bio_barrier] = "barrier",
1148 }; 1070 };
1149 1071
1150 pwo = mdev->write_ordering; 1072 pwo = mdev->write_ordering;
1151 wo = min(pwo, wo); 1073 wo = min(pwo, wo);
1152 if (wo == WO_bio_barrier && mdev->ldev->dc.no_disk_barrier)
1153 wo = WO_bdev_flush;
1154 if (wo == WO_bdev_flush && mdev->ldev->dc.no_disk_flush) 1074 if (wo == WO_bdev_flush && mdev->ldev->dc.no_disk_flush)
1155 wo = WO_drain_io; 1075 wo = WO_drain_io;
1156 if (wo == WO_drain_io && mdev->ldev->dc.no_disk_drain) 1076 if (wo == WO_drain_io && mdev->ldev->dc.no_disk_drain)
1157 wo = WO_none; 1077 wo = WO_none;
1158 mdev->write_ordering = wo; 1078 mdev->write_ordering = wo;
1159 if (pwo != mdev->write_ordering || wo == WO_bio_barrier) 1079 if (pwo != mdev->write_ordering || wo == WO_bdev_flush)
1160 dev_info(DEV, "Method to ensure write ordering: %s\n", write_ordering_str[mdev->write_ordering]); 1080 dev_info(DEV, "Method to ensure write ordering: %s\n", write_ordering_str[mdev->write_ordering]);
1161} 1081}
1162 1082
@@ -1192,7 +1112,7 @@ next_bio:
1192 bio->bi_sector = sector; 1112 bio->bi_sector = sector;
1193 bio->bi_bdev = mdev->ldev->backing_bdev; 1113 bio->bi_bdev = mdev->ldev->backing_bdev;
1194 /* we special case some flags in the multi-bio case, see below 1114 /* we special case some flags in the multi-bio case, see below
1195 * (REQ_UNPLUG, REQ_HARDBARRIER) */ 1115 * (REQ_UNPLUG) */
1196 bio->bi_rw = rw; 1116 bio->bi_rw = rw;
1197 bio->bi_private = e; 1117 bio->bi_private = e;
1198 bio->bi_end_io = drbd_endio_sec; 1118 bio->bi_end_io = drbd_endio_sec;
@@ -1226,11 +1146,6 @@ next_bio:
1226 bio->bi_rw &= ~REQ_UNPLUG; 1146 bio->bi_rw &= ~REQ_UNPLUG;
1227 1147
1228 drbd_generic_make_request(mdev, fault_type, bio); 1148 drbd_generic_make_request(mdev, fault_type, bio);
1229
1230 /* strip off REQ_HARDBARRIER,
1231 * unless it is the first or last bio */
1232 if (bios && bios->bi_next)
1233 bios->bi_rw &= ~REQ_HARDBARRIER;
1234 } while (bios); 1149 } while (bios);
1235 maybe_kick_lo(mdev); 1150 maybe_kick_lo(mdev);
1236 return 0; 1151 return 0;
@@ -1244,45 +1159,9 @@ fail:
1244 return -ENOMEM; 1159 return -ENOMEM;
1245} 1160}
1246 1161
1247/**
1248 * w_e_reissue() - Worker callback; Resubmit a bio, without REQ_HARDBARRIER set
1249 * @mdev: DRBD device.
1250 * @w: work object.
1251 * @cancel: The connection will be closed anyways (unused in this callback)
1252 */
1253int w_e_reissue(struct drbd_conf *mdev, struct drbd_work *w, int cancel) __releases(local)
1254{
1255 struct drbd_epoch_entry *e = (struct drbd_epoch_entry *)w;
1256 /* We leave DE_CONTAINS_A_BARRIER and EE_IS_BARRIER in place,
1257 (and DE_BARRIER_IN_NEXT_EPOCH_ISSUED in the previous Epoch)
1258 so that we can finish that epoch in drbd_may_finish_epoch().
1259 That is necessary if we already have a long chain of Epochs, before
1260 we realize that REQ_HARDBARRIER is actually not supported */
1261
1262 /* As long as the -ENOTSUPP on the barrier is reported immediately
1263 that will never trigger. If it is reported late, we will just
1264 print that warning and continue correctly for all future requests
1265 with WO_bdev_flush */
1266 if (previous_epoch(mdev, e->epoch))
1267 dev_warn(DEV, "Write ordering was not enforced (one time event)\n");
1268
1269 /* we still have a local reference,
1270 * get_ldev was done in receive_Data. */
1271
1272 e->w.cb = e_end_block;
1273 if (drbd_submit_ee(mdev, e, WRITE, DRBD_FAULT_DT_WR) != 0) {
1274 /* drbd_submit_ee fails for one reason only:
1275 * if was not able to allocate sufficient bios.
1276 * requeue, try again later. */
1277 e->w.cb = w_e_reissue;
1278 drbd_queue_work(&mdev->data.work, &e->w);
1279 }
1280 return 1;
1281}
1282
1283static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned int data_size) 1162static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned int data_size)
1284{ 1163{
1285 int rv, issue_flush; 1164 int rv;
1286 struct p_barrier *p = &mdev->data.rbuf.barrier; 1165 struct p_barrier *p = &mdev->data.rbuf.barrier;
1287 struct drbd_epoch *epoch; 1166 struct drbd_epoch *epoch;
1288 1167
@@ -1300,44 +1179,40 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
1300 * Therefore we must send the barrier_ack after the barrier request was 1179 * Therefore we must send the barrier_ack after the barrier request was
1301 * completed. */ 1180 * completed. */
1302 switch (mdev->write_ordering) { 1181 switch (mdev->write_ordering) {
1303 case WO_bio_barrier:
1304 case WO_none: 1182 case WO_none:
1305 if (rv == FE_RECYCLED) 1183 if (rv == FE_RECYCLED)
1306 return TRUE; 1184 return TRUE;
1307 break; 1185
1186 /* receiver context, in the writeout path of the other node.
1187 * avoid potential distributed deadlock */
1188 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
1189 if (epoch)
1190 break;
1191 else
1192 dev_warn(DEV, "Allocation of an epoch failed, slowing down\n");
1193 /* Fall through */
1308 1194
1309 case WO_bdev_flush: 1195 case WO_bdev_flush:
1310 case WO_drain_io: 1196 case WO_drain_io:
1311 if (rv == FE_STILL_LIVE) {
1312 set_bit(DE_BARRIER_IN_NEXT_EPOCH_ISSUED, &mdev->current_epoch->flags);
1313 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
1314 rv = drbd_flush_after_epoch(mdev, mdev->current_epoch);
1315 }
1316 if (rv == FE_RECYCLED)
1317 return TRUE;
1318
1319 /* The asender will send all the ACKs and barrier ACKs out, since
1320 all EEs moved from the active_ee to the done_ee. We need to
1321 provide a new epoch object for the EEs that come in soon */
1322 break;
1323 }
1324
1325 /* receiver context, in the writeout path of the other node.
1326 * avoid potential distributed deadlock */
1327 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
1328 if (!epoch) {
1329 dev_warn(DEV, "Allocation of an epoch failed, slowing down\n");
1330 issue_flush = !test_and_set_bit(DE_BARRIER_IN_NEXT_EPOCH_ISSUED, &mdev->current_epoch->flags);
1331 drbd_wait_ee_list_empty(mdev, &mdev->active_ee); 1197 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
1332 if (issue_flush) { 1198 drbd_flush(mdev);
1333 rv = drbd_flush_after_epoch(mdev, mdev->current_epoch); 1199
1334 if (rv == FE_RECYCLED) 1200 if (atomic_read(&mdev->current_epoch->epoch_size)) {
1335 return TRUE; 1201 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
1202 if (epoch)
1203 break;
1336 } 1204 }
1337 1205
1338 drbd_wait_ee_list_empty(mdev, &mdev->done_ee); 1206 epoch = mdev->current_epoch;
1207 wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
1208
1209 D_ASSERT(atomic_read(&epoch->active) == 0);
1210 D_ASSERT(epoch->flags == 0);
1339 1211
1340 return TRUE; 1212 return TRUE;
1213 default:
1214 dev_err(DEV, "Strangeness in mdev->write_ordering %d\n", mdev->write_ordering);
1215 return FALSE;
1341 } 1216 }
1342 1217
1343 epoch->flags = 0; 1218 epoch->flags = 0;
@@ -1652,15 +1527,8 @@ static int e_end_block(struct drbd_conf *mdev, struct drbd_work *w, int cancel)
1652{ 1527{
1653 struct drbd_epoch_entry *e = (struct drbd_epoch_entry *)w; 1528 struct drbd_epoch_entry *e = (struct drbd_epoch_entry *)w;
1654 sector_t sector = e->sector; 1529 sector_t sector = e->sector;
1655 struct drbd_epoch *epoch;
1656 int ok = 1, pcmd; 1530 int ok = 1, pcmd;
1657 1531
1658 if (e->flags & EE_IS_BARRIER) {
1659 epoch = previous_epoch(mdev, e->epoch);
1660 if (epoch)
1661 drbd_may_finish_epoch(mdev, epoch, EV_BARRIER_DONE + (cancel ? EV_CLEANUP : 0));
1662 }
1663
1664 if (mdev->net_conf->wire_protocol == DRBD_PROT_C) { 1532 if (mdev->net_conf->wire_protocol == DRBD_PROT_C) {
1665 if (likely((e->flags & EE_WAS_ERROR) == 0)) { 1533 if (likely((e->flags & EE_WAS_ERROR) == 0)) {
1666 pcmd = (mdev->state.conn >= C_SYNC_SOURCE && 1534 pcmd = (mdev->state.conn >= C_SYNC_SOURCE &&
@@ -1817,27 +1685,6 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
1817 e->epoch = mdev->current_epoch; 1685 e->epoch = mdev->current_epoch;
1818 atomic_inc(&e->epoch->epoch_size); 1686 atomic_inc(&e->epoch->epoch_size);
1819 atomic_inc(&e->epoch->active); 1687 atomic_inc(&e->epoch->active);
1820
1821 if (mdev->write_ordering == WO_bio_barrier && atomic_read(&e->epoch->epoch_size) == 1) {
1822 struct drbd_epoch *epoch;
1823 /* Issue a barrier if we start a new epoch, and the previous epoch
1824 was not a epoch containing a single request which already was
1825 a Barrier. */
1826 epoch = list_entry(e->epoch->list.prev, struct drbd_epoch, list);
1827 if (epoch == e->epoch) {
1828 set_bit(DE_CONTAINS_A_BARRIER, &e->epoch->flags);
1829 rw |= REQ_HARDBARRIER;
1830 e->flags |= EE_IS_BARRIER;
1831 } else {
1832 if (atomic_read(&epoch->epoch_size) > 1 ||
1833 !test_bit(DE_CONTAINS_A_BARRIER, &epoch->flags)) {
1834 set_bit(DE_BARRIER_IN_NEXT_EPOCH_ISSUED, &epoch->flags);
1835 set_bit(DE_CONTAINS_A_BARRIER, &e->epoch->flags);
1836 rw |= REQ_HARDBARRIER;
1837 e->flags |= EE_IS_BARRIER;
1838 }
1839 }
1840 }
1841 spin_unlock(&mdev->epoch_lock); 1688 spin_unlock(&mdev->epoch_lock);
1842 1689
1843 dp_flags = be32_to_cpu(p->dp_flags); 1690 dp_flags = be32_to_cpu(p->dp_flags);
@@ -1995,10 +1842,11 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
1995 break; 1842 break;
1996 } 1843 }
1997 1844
1998 if (mdev->state.pdsk == D_DISKLESS) { 1845 if (mdev->state.pdsk < D_INCONSISTENT) {
1999 /* In case we have the only disk of the cluster, */ 1846 /* In case we have the only disk of the cluster, */
2000 drbd_set_out_of_sync(mdev, e->sector, e->size); 1847 drbd_set_out_of_sync(mdev, e->sector, e->size);
2001 e->flags |= EE_CALL_AL_COMPLETE_IO; 1848 e->flags |= EE_CALL_AL_COMPLETE_IO;
1849 e->flags &= ~EE_MAY_SET_IN_SYNC;
2002 drbd_al_begin_io(mdev, e->sector); 1850 drbd_al_begin_io(mdev, e->sector);
2003 } 1851 }
2004 1852
@@ -3362,7 +3210,7 @@ static int receive_state(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
3362 if (ns.conn == C_MASK) { 3210 if (ns.conn == C_MASK) {
3363 ns.conn = C_CONNECTED; 3211 ns.conn = C_CONNECTED;
3364 if (mdev->state.disk == D_NEGOTIATING) { 3212 if (mdev->state.disk == D_NEGOTIATING) {
3365 drbd_force_state(mdev, NS(disk, D_DISKLESS)); 3213 drbd_force_state(mdev, NS(disk, D_FAILED));
3366 } else if (peer_state.disk == D_NEGOTIATING) { 3214 } else if (peer_state.disk == D_NEGOTIATING) {
3367 dev_err(DEV, "Disk attach process on the peer node was aborted.\n"); 3215 dev_err(DEV, "Disk attach process on the peer node was aborted.\n");
3368 peer_state.disk = D_DISKLESS; 3216 peer_state.disk = D_DISKLESS;
@@ -3779,17 +3627,19 @@ static void drbdd(struct drbd_conf *mdev)
3779 } 3627 }
3780 3628
3781 shs = drbd_cmd_handler[cmd].pkt_size - sizeof(union p_header); 3629 shs = drbd_cmd_handler[cmd].pkt_size - sizeof(union p_header);
3782 rv = drbd_recv(mdev, &header->h80.payload, shs);
3783 if (unlikely(rv != shs)) {
3784 dev_err(DEV, "short read while reading sub header: rv=%d\n", rv);
3785 goto err_out;
3786 }
3787
3788 if (packet_size - shs > 0 && !drbd_cmd_handler[cmd].expect_payload) { 3630 if (packet_size - shs > 0 && !drbd_cmd_handler[cmd].expect_payload) {
3789 dev_err(DEV, "No payload expected %s l:%d\n", cmdname(cmd), packet_size); 3631 dev_err(DEV, "No payload expected %s l:%d\n", cmdname(cmd), packet_size);
3790 goto err_out; 3632 goto err_out;
3791 } 3633 }
3792 3634
3635 if (shs) {
3636 rv = drbd_recv(mdev, &header->h80.payload, shs);
3637 if (unlikely(rv != shs)) {
3638 dev_err(DEV, "short read while reading sub header: rv=%d\n", rv);
3639 goto err_out;
3640 }
3641 }
3642
3793 rv = drbd_cmd_handler[cmd].function(mdev, cmd, packet_size - shs); 3643 rv = drbd_cmd_handler[cmd].function(mdev, cmd, packet_size - shs);
3794 3644
3795 if (unlikely(!rv)) { 3645 if (unlikely(!rv)) {
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 9e91a2545fc8..11a75d32a2e2 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -258,7 +258,7 @@ void _req_may_be_done(struct drbd_request *req, struct bio_and_error *m)
258 if (!hlist_unhashed(&req->colision)) 258 if (!hlist_unhashed(&req->colision))
259 hlist_del(&req->colision); 259 hlist_del(&req->colision);
260 else 260 else
261 D_ASSERT((s & RQ_NET_MASK) == 0); 261 D_ASSERT((s & (RQ_NET_MASK & ~RQ_NET_DONE)) == 0);
262 262
263 /* for writes we need to do some extra housekeeping */ 263 /* for writes we need to do some extra housekeeping */
264 if (rw == WRITE) 264 if (rw == WRITE)
@@ -813,7 +813,8 @@ static int drbd_make_request_common(struct drbd_conf *mdev, struct bio *bio)
813 mdev->state.conn >= C_CONNECTED)); 813 mdev->state.conn >= C_CONNECTED));
814 814
815 if (!(local || remote) && !is_susp(mdev->state)) { 815 if (!(local || remote) && !is_susp(mdev->state)) {
816 dev_err(DEV, "IO ERROR: neither local nor remote disk\n"); 816 if (__ratelimit(&drbd_ratelimit_state))
817 dev_err(DEV, "IO ERROR: neither local nor remote disk\n");
817 goto fail_free_complete; 818 goto fail_free_complete;
818 } 819 }
819 820
@@ -942,12 +943,21 @@ allocate_barrier:
942 if (local) { 943 if (local) {
943 req->private_bio->bi_bdev = mdev->ldev->backing_bdev; 944 req->private_bio->bi_bdev = mdev->ldev->backing_bdev;
944 945
945 if (FAULT_ACTIVE(mdev, rw == WRITE ? DRBD_FAULT_DT_WR 946 /* State may have changed since we grabbed our reference on the
946 : rw == READ ? DRBD_FAULT_DT_RD 947 * mdev->ldev member. Double check, and short-circuit to endio.
947 : DRBD_FAULT_DT_RA)) 948 * In case the last activity log transaction failed to get on
949 * stable storage, and this is a WRITE, we may not even submit
950 * this bio. */
951 if (get_ldev(mdev)) {
952 if (FAULT_ACTIVE(mdev, rw == WRITE ? DRBD_FAULT_DT_WR
953 : rw == READ ? DRBD_FAULT_DT_RD
954 : DRBD_FAULT_DT_RA))
955 bio_endio(req->private_bio, -EIO);
956 else
957 generic_make_request(req->private_bio);
958 put_ldev(mdev);
959 } else
948 bio_endio(req->private_bio, -EIO); 960 bio_endio(req->private_bio, -EIO);
949 else
950 generic_make_request(req->private_bio);
951 } 961 }
952 962
953 /* we need to plug ALWAYS since we possibly need to kick lo_dev. 963 /* we need to plug ALWAYS since we possibly need to kick lo_dev.
@@ -1022,20 +1032,6 @@ int drbd_make_request_26(struct request_queue *q, struct bio *bio)
1022 return 0; 1032 return 0;
1023 } 1033 }
1024 1034
1025 /* Reject barrier requests if we know the underlying device does
1026 * not support them.
1027 * XXX: Need to get this info from peer as well some how so we
1028 * XXX: reject if EITHER side/data/metadata area does not support them.
1029 *
1030 * because of those XXX, this is not yet enabled,
1031 * i.e. in drbd_init_set_defaults we set the NO_BARRIER_SUPP bit.
1032 */
1033 if (unlikely(bio->bi_rw & REQ_HARDBARRIER) && test_bit(NO_BARRIER_SUPP, &mdev->flags)) {
1034 /* dev_warn(DEV, "Rejecting barrier request as underlying device does not support\n"); */
1035 bio_endio(bio, -EOPNOTSUPP);
1036 return 0;
1037 }
1038
1039 /* 1035 /*
1040 * what we "blindly" assume: 1036 * what we "blindly" assume:
1041 */ 1037 */
diff --git a/drivers/block/drbd/drbd_req.h b/drivers/block/drbd/drbd_req.h
index 181ea0364822..ab2bd09d54b4 100644
--- a/drivers/block/drbd/drbd_req.h
+++ b/drivers/block/drbd/drbd_req.h
@@ -339,7 +339,8 @@ static inline int _req_mod(struct drbd_request *req, enum drbd_req_event what)
339} 339}
340 340
341/* completion of master bio is outside of spinlock. 341/* completion of master bio is outside of spinlock.
342 * If you need it irqsave, do it your self! */ 342 * If you need it irqsave, do it your self!
343 * Which means: don't use from bio endio callback. */
343static inline int req_mod(struct drbd_request *req, 344static inline int req_mod(struct drbd_request *req,
344 enum drbd_req_event what) 345 enum drbd_req_event what)
345{ 346{
diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
index 108d58015cd1..34f224b018b3 100644
--- a/drivers/block/drbd/drbd_worker.c
+++ b/drivers/block/drbd/drbd_worker.c
@@ -26,7 +26,6 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/drbd.h> 27#include <linux/drbd.h>
28#include <linux/sched.h> 28#include <linux/sched.h>
29#include <linux/smp_lock.h>
30#include <linux/wait.h> 29#include <linux/wait.h>
31#include <linux/mm.h> 30#include <linux/mm.h>
32#include <linux/memcontrol.h> 31#include <linux/memcontrol.h>
@@ -102,12 +101,6 @@ void drbd_endio_read_sec_final(struct drbd_epoch_entry *e) __releases(local)
102 put_ldev(mdev); 101 put_ldev(mdev);
103} 102}
104 103
105static int is_failed_barrier(int ee_flags)
106{
107 return (ee_flags & (EE_IS_BARRIER|EE_WAS_ERROR|EE_RESUBMITTED))
108 == (EE_IS_BARRIER|EE_WAS_ERROR);
109}
110
111/* writes on behalf of the partner, or resync writes, 104/* writes on behalf of the partner, or resync writes,
112 * "submitted" by the receiver, final stage. */ 105 * "submitted" by the receiver, final stage. */
113static void drbd_endio_write_sec_final(struct drbd_epoch_entry *e) __releases(local) 106static void drbd_endio_write_sec_final(struct drbd_epoch_entry *e) __releases(local)
@@ -119,21 +112,6 @@ static void drbd_endio_write_sec_final(struct drbd_epoch_entry *e) __releases(lo
119 int is_syncer_req; 112 int is_syncer_req;
120 int do_al_complete_io; 113 int do_al_complete_io;
121 114
122 /* if this is a failed barrier request, disable use of barriers,
123 * and schedule for resubmission */
124 if (is_failed_barrier(e->flags)) {
125 drbd_bump_write_ordering(mdev, WO_bdev_flush);
126 spin_lock_irqsave(&mdev->req_lock, flags);
127 list_del(&e->w.list);
128 e->flags = (e->flags & ~EE_WAS_ERROR) | EE_RESUBMITTED;
129 e->w.cb = w_e_reissue;
130 /* put_ldev actually happens below, once we come here again. */
131 __release(local);
132 spin_unlock_irqrestore(&mdev->req_lock, flags);
133 drbd_queue_work(&mdev->data.work, &e->w);
134 return;
135 }
136
137 D_ASSERT(e->block_id != ID_VACANT); 115 D_ASSERT(e->block_id != ID_VACANT);
138 116
139 /* after we moved e to done_ee, 117 /* after we moved e to done_ee,
@@ -215,8 +193,10 @@ void drbd_endio_sec(struct bio *bio, int error)
215 */ 193 */
216void drbd_endio_pri(struct bio *bio, int error) 194void drbd_endio_pri(struct bio *bio, int error)
217{ 195{
196 unsigned long flags;
218 struct drbd_request *req = bio->bi_private; 197 struct drbd_request *req = bio->bi_private;
219 struct drbd_conf *mdev = req->mdev; 198 struct drbd_conf *mdev = req->mdev;
199 struct bio_and_error m;
220 enum drbd_req_event what; 200 enum drbd_req_event what;
221 int uptodate = bio_flagged(bio, BIO_UPTODATE); 201 int uptodate = bio_flagged(bio, BIO_UPTODATE);
222 202
@@ -242,7 +222,13 @@ void drbd_endio_pri(struct bio *bio, int error)
242 bio_put(req->private_bio); 222 bio_put(req->private_bio);
243 req->private_bio = ERR_PTR(error); 223 req->private_bio = ERR_PTR(error);
244 224
245 req_mod(req, what); 225 /* not req_mod(), we need irqsave here! */
226 spin_lock_irqsave(&mdev->req_lock, flags);
227 __req_mod(req, what, &m);
228 spin_unlock_irqrestore(&mdev->req_lock, flags);
229
230 if (m.bio)
231 complete_master_bio(mdev, &m);
246} 232}
247 233
248int w_read_retry_remote(struct drbd_conf *mdev, struct drbd_work *w, int cancel) 234int w_read_retry_remote(struct drbd_conf *mdev, struct drbd_work *w, int cancel)
@@ -925,7 +911,7 @@ out:
925 drbd_md_sync(mdev); 911 drbd_md_sync(mdev);
926 912
927 if (test_and_clear_bit(WRITE_BM_AFTER_RESYNC, &mdev->flags)) { 913 if (test_and_clear_bit(WRITE_BM_AFTER_RESYNC, &mdev->flags)) {
928 dev_warn(DEV, "Writing the whole bitmap, due to failed kmalloc\n"); 914 dev_info(DEV, "Writing the whole bitmap\n");
929 drbd_queue_bitmap_io(mdev, &drbd_bm_write, NULL, "write from resync_finished"); 915 drbd_queue_bitmap_io(mdev, &drbd_bm_write, NULL, "write from resync_finished");
930 } 916 }
931 917
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 767107cce982..3951020e494a 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4363,9 +4363,9 @@ out_unreg_blkdev:
4363out_put_disk: 4363out_put_disk:
4364 while (dr--) { 4364 while (dr--) {
4365 del_timer(&motor_off_timer[dr]); 4365 del_timer(&motor_off_timer[dr]);
4366 put_disk(disks[dr]);
4367 if (disks[dr]->queue) 4366 if (disks[dr]->queue)
4368 blk_cleanup_queue(disks[dr]->queue); 4367 blk_cleanup_queue(disks[dr]->queue);
4368 put_disk(disks[dr]);
4369 } 4369 }
4370 return err; 4370 return err;
4371} 4371}
@@ -4573,8 +4573,8 @@ static void __exit floppy_module_exit(void)
4573 device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); 4573 device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos);
4574 platform_device_unregister(&floppy_device[drive]); 4574 platform_device_unregister(&floppy_device[drive]);
4575 } 4575 }
4576 put_disk(disks[drive]);
4577 blk_cleanup_queue(disks[drive]->queue); 4576 blk_cleanup_queue(disks[drive]->queue);
4577 put_disk(disks[drive]);
4578 } 4578 }
4579 4579
4580 del_timer_sync(&fd_timeout); 4580 del_timer_sync(&fd_timeout);
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 1e5284ef65fa..7ea0bea2f7e3 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -481,12 +481,6 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
481 if (bio_rw(bio) == WRITE) { 481 if (bio_rw(bio) == WRITE) {
482 struct file *file = lo->lo_backing_file; 482 struct file *file = lo->lo_backing_file;
483 483
484 /* REQ_HARDBARRIER is deprecated */
485 if (bio->bi_rw & REQ_HARDBARRIER) {
486 ret = -EOPNOTSUPP;
487 goto out;
488 }
489
490 if (bio->bi_rw & REQ_FLUSH) { 484 if (bio->bi_rw & REQ_FLUSH) {
491 ret = vfs_fsync(file, 0); 485 ret = vfs_fsync(file, 0);
492 if (unlikely(ret && ret != -EINVAL)) { 486 if (unlikely(ret && ret != -EINVAL)) {
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 6ec9d53806c5..008d4a00b50d 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -21,80 +21,9 @@
21 21
22 22
23 23
24 Instructions for use 24 For usage instructions, please refer to:
25 --------------------
26 25
27 1) Map a Linux block device to an existing rbd image. 26 Documentation/ABI/testing/sysfs-bus-rbd
28
29 Usage: <mon ip addr> <options> <pool name> <rbd image name> [snap name]
30
31 $ echo "192.168.0.1 name=admin rbd foo" > /sys/class/rbd/add
32
33 The snapshot name can be "-" or omitted to map the image read/write.
34
35 2) List all active blkdev<->object mappings.
36
37 In this example, we have performed step #1 twice, creating two blkdevs,
38 mapped to two separate rados objects in the rados rbd pool
39
40 $ cat /sys/class/rbd/list
41 #id major client_name pool name snap KB
42 0 254 client4143 rbd foo - 1024000
43
44 The columns, in order, are:
45 - blkdev unique id
46 - blkdev assigned major
47 - rados client id
48 - rados pool name
49 - rados block device name
50 - mapped snapshot ("-" if none)
51 - device size in KB
52
53
54 3) Create a snapshot.
55
56 Usage: <blkdev id> <snapname>
57
58 $ echo "0 mysnap" > /sys/class/rbd/snap_create
59
60
61 4) Listing a snapshot.
62
63 $ cat /sys/class/rbd/snaps_list
64 #id snap KB
65 0 - 1024000 (*)
66 0 foo 1024000
67
68 The columns, in order, are:
69 - blkdev unique id
70 - snapshot name, '-' means none (active read/write version)
71 - size of device at time of snapshot
72 - the (*) indicates this is the active version
73
74 5) Rollback to snapshot.
75
76 Usage: <blkdev id> <snapname>
77
78 $ echo "0 mysnap" > /sys/class/rbd/snap_rollback
79
80
81 6) Mapping an image using snapshot.
82
83 A snapshot mapping is read-only. This is being done by passing
84 snap=<snapname> to the options when adding a device.
85
86 $ echo "192.168.0.1 name=admin,snap=mysnap rbd foo" > /sys/class/rbd/add
87
88
89 7) Remove an active blkdev<->rbd image mapping.
90
91 In this example, we remove the mapping with blkdev unique id 1.
92
93 $ echo 1 > /sys/class/rbd/remove
94
95
96 NOTE: The actual creation and deletion of rados objects is outside the scope
97 of this driver.
98 27
99 */ 28 */
100 29
@@ -163,6 +92,14 @@ struct rbd_request {
163 u64 len; 92 u64 len;
164}; 93};
165 94
95struct rbd_snap {
96 struct device dev;
97 const char *name;
98 size_t size;
99 struct list_head node;
100 u64 id;
101};
102
166/* 103/*
167 * a single device 104 * a single device
168 */ 105 */
@@ -193,21 +130,60 @@ struct rbd_device {
193 int read_only; 130 int read_only;
194 131
195 struct list_head node; 132 struct list_head node;
133
134 /* list of snapshots */
135 struct list_head snaps;
136
137 /* sysfs related */
138 struct device dev;
139};
140
141static struct bus_type rbd_bus_type = {
142 .name = "rbd",
196}; 143};
197 144
198static spinlock_t node_lock; /* protects client get/put */ 145static spinlock_t node_lock; /* protects client get/put */
199 146
200static struct class *class_rbd; /* /sys/class/rbd */
201static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */ 147static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */
202static LIST_HEAD(rbd_dev_list); /* devices */ 148static LIST_HEAD(rbd_dev_list); /* devices */
203static LIST_HEAD(rbd_client_list); /* clients */ 149static LIST_HEAD(rbd_client_list); /* clients */
204 150
151static int __rbd_init_snaps_header(struct rbd_device *rbd_dev);
152static void rbd_dev_release(struct device *dev);
153static ssize_t rbd_snap_rollback(struct device *dev,
154 struct device_attribute *attr,
155 const char *buf,
156 size_t size);
157static ssize_t rbd_snap_add(struct device *dev,
158 struct device_attribute *attr,
159 const char *buf,
160 size_t count);
161static void __rbd_remove_snap_dev(struct rbd_device *rbd_dev,
162 struct rbd_snap *snap);;
163
164
165static struct rbd_device *dev_to_rbd(struct device *dev)
166{
167 return container_of(dev, struct rbd_device, dev);
168}
169
170static struct device *rbd_get_dev(struct rbd_device *rbd_dev)
171{
172 return get_device(&rbd_dev->dev);
173}
174
175static void rbd_put_dev(struct rbd_device *rbd_dev)
176{
177 put_device(&rbd_dev->dev);
178}
205 179
206static int rbd_open(struct block_device *bdev, fmode_t mode) 180static int rbd_open(struct block_device *bdev, fmode_t mode)
207{ 181{
208 struct gendisk *disk = bdev->bd_disk; 182 struct gendisk *disk = bdev->bd_disk;
209 struct rbd_device *rbd_dev = disk->private_data; 183 struct rbd_device *rbd_dev = disk->private_data;
210 184
185 rbd_get_dev(rbd_dev);
186
211 set_device_ro(bdev, rbd_dev->read_only); 187 set_device_ro(bdev, rbd_dev->read_only);
212 188
213 if ((mode & FMODE_WRITE) && rbd_dev->read_only) 189 if ((mode & FMODE_WRITE) && rbd_dev->read_only)
@@ -216,9 +192,19 @@ static int rbd_open(struct block_device *bdev, fmode_t mode)
216 return 0; 192 return 0;
217} 193}
218 194
195static int rbd_release(struct gendisk *disk, fmode_t mode)
196{
197 struct rbd_device *rbd_dev = disk->private_data;
198
199 rbd_put_dev(rbd_dev);
200
201 return 0;
202}
203
219static const struct block_device_operations rbd_bd_ops = { 204static const struct block_device_operations rbd_bd_ops = {
220 .owner = THIS_MODULE, 205 .owner = THIS_MODULE,
221 .open = rbd_open, 206 .open = rbd_open,
207 .release = rbd_release,
222}; 208};
223 209
224/* 210/*
@@ -361,7 +347,6 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
361 int ret = -ENOMEM; 347 int ret = -ENOMEM;
362 348
363 init_rwsem(&header->snap_rwsem); 349 init_rwsem(&header->snap_rwsem);
364
365 header->snap_names_len = le64_to_cpu(ondisk->snap_names_len); 350 header->snap_names_len = le64_to_cpu(ondisk->snap_names_len);
366 header->snapc = kmalloc(sizeof(struct ceph_snap_context) + 351 header->snapc = kmalloc(sizeof(struct ceph_snap_context) +
367 snap_count * 352 snap_count *
@@ -1256,10 +1241,20 @@ bad:
1256 return -ERANGE; 1241 return -ERANGE;
1257} 1242}
1258 1243
1244static void __rbd_remove_all_snaps(struct rbd_device *rbd_dev)
1245{
1246 struct rbd_snap *snap;
1247
1248 while (!list_empty(&rbd_dev->snaps)) {
1249 snap = list_first_entry(&rbd_dev->snaps, struct rbd_snap, node);
1250 __rbd_remove_snap_dev(rbd_dev, snap);
1251 }
1252}
1253
1259/* 1254/*
1260 * only read the first part of the ondisk header, without the snaps info 1255 * only read the first part of the ondisk header, without the snaps info
1261 */ 1256 */
1262static int rbd_update_snaps(struct rbd_device *rbd_dev) 1257static int __rbd_update_snaps(struct rbd_device *rbd_dev)
1263{ 1258{
1264 int ret; 1259 int ret;
1265 struct rbd_image_header h; 1260 struct rbd_image_header h;
@@ -1280,12 +1275,15 @@ static int rbd_update_snaps(struct rbd_device *rbd_dev)
1280 rbd_dev->header.total_snaps = h.total_snaps; 1275 rbd_dev->header.total_snaps = h.total_snaps;
1281 rbd_dev->header.snapc = h.snapc; 1276 rbd_dev->header.snapc = h.snapc;
1282 rbd_dev->header.snap_names = h.snap_names; 1277 rbd_dev->header.snap_names = h.snap_names;
1278 rbd_dev->header.snap_names_len = h.snap_names_len;
1283 rbd_dev->header.snap_sizes = h.snap_sizes; 1279 rbd_dev->header.snap_sizes = h.snap_sizes;
1284 rbd_dev->header.snapc->seq = snap_seq; 1280 rbd_dev->header.snapc->seq = snap_seq;
1285 1281
1282 ret = __rbd_init_snaps_header(rbd_dev);
1283
1286 up_write(&rbd_dev->header.snap_rwsem); 1284 up_write(&rbd_dev->header.snap_rwsem);
1287 1285
1288 return 0; 1286 return ret;
1289} 1287}
1290 1288
1291static int rbd_init_disk(struct rbd_device *rbd_dev) 1289static int rbd_init_disk(struct rbd_device *rbd_dev)
@@ -1300,6 +1298,11 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1300 if (rc) 1298 if (rc)
1301 return rc; 1299 return rc;
1302 1300
1301 /* no need to lock here, as rbd_dev is not registered yet */
1302 rc = __rbd_init_snaps_header(rbd_dev);
1303 if (rc)
1304 return rc;
1305
1303 rc = rbd_header_set_snap(rbd_dev, rbd_dev->snap_name, &total_size); 1306 rc = rbd_header_set_snap(rbd_dev, rbd_dev->snap_name, &total_size);
1304 if (rc) 1307 if (rc)
1305 return rc; 1308 return rc;
@@ -1343,54 +1346,360 @@ out:
1343 return rc; 1346 return rc;
1344} 1347}
1345 1348
1346/******************************************************************** 1349/*
1347 * /sys/class/rbd/ 1350 sysfs
1348 * add map rados objects to blkdev 1351*/
1349 * remove unmap rados objects 1352
1350 * list show mappings 1353static ssize_t rbd_size_show(struct device *dev,
1351 *******************************************************************/ 1354 struct device_attribute *attr, char *buf)
1355{
1356 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1357
1358 return sprintf(buf, "%llu\n", (unsigned long long)rbd_dev->header.image_size);
1359}
1360
1361static ssize_t rbd_major_show(struct device *dev,
1362 struct device_attribute *attr, char *buf)
1363{
1364 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1352 1365
1353static void class_rbd_release(struct class *cls) 1366 return sprintf(buf, "%d\n", rbd_dev->major);
1367}
1368
1369static ssize_t rbd_client_id_show(struct device *dev,
1370 struct device_attribute *attr, char *buf)
1354{ 1371{
1355 kfree(cls); 1372 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1373
1374 return sprintf(buf, "client%lld\n", ceph_client_id(rbd_dev->client));
1356} 1375}
1357 1376
1358static ssize_t class_rbd_list(struct class *c, 1377static ssize_t rbd_pool_show(struct device *dev,
1359 struct class_attribute *attr, 1378 struct device_attribute *attr, char *buf)
1360 char *data)
1361{ 1379{
1362 int n = 0; 1380 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1363 struct list_head *tmp; 1381
1364 int max = PAGE_SIZE; 1382 return sprintf(buf, "%s\n", rbd_dev->pool_name);
1383}
1384
1385static ssize_t rbd_name_show(struct device *dev,
1386 struct device_attribute *attr, char *buf)
1387{
1388 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1389
1390 return sprintf(buf, "%s\n", rbd_dev->obj);
1391}
1392
1393static ssize_t rbd_snap_show(struct device *dev,
1394 struct device_attribute *attr,
1395 char *buf)
1396{
1397 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1398
1399 return sprintf(buf, "%s\n", rbd_dev->snap_name);
1400}
1401
1402static ssize_t rbd_image_refresh(struct device *dev,
1403 struct device_attribute *attr,
1404 const char *buf,
1405 size_t size)
1406{
1407 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1408 int rc;
1409 int ret = size;
1365 1410
1366 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 1411 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1367 1412
1368 n += snprintf(data, max, 1413 rc = __rbd_update_snaps(rbd_dev);
1369 "#id\tmajor\tclient_name\tpool\tname\tsnap\tKB\n"); 1414 if (rc < 0)
1415 ret = rc;
1370 1416
1371 list_for_each(tmp, &rbd_dev_list) { 1417 mutex_unlock(&ctl_mutex);
1372 struct rbd_device *rbd_dev; 1418 return ret;
1419}
1373 1420
1374 rbd_dev = list_entry(tmp, struct rbd_device, node); 1421static DEVICE_ATTR(size, S_IRUGO, rbd_size_show, NULL);
1375 n += snprintf(data+n, max-n, 1422static DEVICE_ATTR(major, S_IRUGO, rbd_major_show, NULL);
1376 "%d\t%d\tclient%lld\t%s\t%s\t%s\t%lld\n", 1423static DEVICE_ATTR(client_id, S_IRUGO, rbd_client_id_show, NULL);
1377 rbd_dev->id, 1424static DEVICE_ATTR(pool, S_IRUGO, rbd_pool_show, NULL);
1378 rbd_dev->major, 1425static DEVICE_ATTR(name, S_IRUGO, rbd_name_show, NULL);
1379 ceph_client_id(rbd_dev->client), 1426static DEVICE_ATTR(refresh, S_IWUSR, NULL, rbd_image_refresh);
1380 rbd_dev->pool_name, 1427static DEVICE_ATTR(current_snap, S_IRUGO, rbd_snap_show, NULL);
1381 rbd_dev->obj, rbd_dev->snap_name, 1428static DEVICE_ATTR(create_snap, S_IWUSR, NULL, rbd_snap_add);
1382 rbd_dev->header.image_size >> 10); 1429static DEVICE_ATTR(rollback_snap, S_IWUSR, NULL, rbd_snap_rollback);
1383 if (n == max) 1430
1431static struct attribute *rbd_attrs[] = {
1432 &dev_attr_size.attr,
1433 &dev_attr_major.attr,
1434 &dev_attr_client_id.attr,
1435 &dev_attr_pool.attr,
1436 &dev_attr_name.attr,
1437 &dev_attr_current_snap.attr,
1438 &dev_attr_refresh.attr,
1439 &dev_attr_create_snap.attr,
1440 &dev_attr_rollback_snap.attr,
1441 NULL
1442};
1443
1444static struct attribute_group rbd_attr_group = {
1445 .attrs = rbd_attrs,
1446};
1447
1448static const struct attribute_group *rbd_attr_groups[] = {
1449 &rbd_attr_group,
1450 NULL
1451};
1452
1453static void rbd_sysfs_dev_release(struct device *dev)
1454{
1455}
1456
1457static struct device_type rbd_device_type = {
1458 .name = "rbd",
1459 .groups = rbd_attr_groups,
1460 .release = rbd_sysfs_dev_release,
1461};
1462
1463
1464/*
1465 sysfs - snapshots
1466*/
1467
1468static ssize_t rbd_snap_size_show(struct device *dev,
1469 struct device_attribute *attr,
1470 char *buf)
1471{
1472 struct rbd_snap *snap = container_of(dev, struct rbd_snap, dev);
1473
1474 return sprintf(buf, "%lld\n", (long long)snap->size);
1475}
1476
1477static ssize_t rbd_snap_id_show(struct device *dev,
1478 struct device_attribute *attr,
1479 char *buf)
1480{
1481 struct rbd_snap *snap = container_of(dev, struct rbd_snap, dev);
1482
1483 return sprintf(buf, "%lld\n", (long long)snap->id);
1484}
1485
1486static DEVICE_ATTR(snap_size, S_IRUGO, rbd_snap_size_show, NULL);
1487static DEVICE_ATTR(snap_id, S_IRUGO, rbd_snap_id_show, NULL);
1488
1489static struct attribute *rbd_snap_attrs[] = {
1490 &dev_attr_snap_size.attr,
1491 &dev_attr_snap_id.attr,
1492 NULL,
1493};
1494
1495static struct attribute_group rbd_snap_attr_group = {
1496 .attrs = rbd_snap_attrs,
1497};
1498
1499static void rbd_snap_dev_release(struct device *dev)
1500{
1501 struct rbd_snap *snap = container_of(dev, struct rbd_snap, dev);
1502 kfree(snap->name);
1503 kfree(snap);
1504}
1505
1506static const struct attribute_group *rbd_snap_attr_groups[] = {
1507 &rbd_snap_attr_group,
1508 NULL
1509};
1510
1511static struct device_type rbd_snap_device_type = {
1512 .groups = rbd_snap_attr_groups,
1513 .release = rbd_snap_dev_release,
1514};
1515
1516static void __rbd_remove_snap_dev(struct rbd_device *rbd_dev,
1517 struct rbd_snap *snap)
1518{
1519 list_del(&snap->node);
1520 device_unregister(&snap->dev);
1521}
1522
1523static int rbd_register_snap_dev(struct rbd_device *rbd_dev,
1524 struct rbd_snap *snap,
1525 struct device *parent)
1526{
1527 struct device *dev = &snap->dev;
1528 int ret;
1529
1530 dev->type = &rbd_snap_device_type;
1531 dev->parent = parent;
1532 dev->release = rbd_snap_dev_release;
1533 dev_set_name(dev, "snap_%s", snap->name);
1534 ret = device_register(dev);
1535
1536 return ret;
1537}
1538
1539static int __rbd_add_snap_dev(struct rbd_device *rbd_dev,
1540 int i, const char *name,
1541 struct rbd_snap **snapp)
1542{
1543 int ret;
1544 struct rbd_snap *snap = kzalloc(sizeof(*snap), GFP_KERNEL);
1545 if (!snap)
1546 return -ENOMEM;
1547 snap->name = kstrdup(name, GFP_KERNEL);
1548 snap->size = rbd_dev->header.snap_sizes[i];
1549 snap->id = rbd_dev->header.snapc->snaps[i];
1550 if (device_is_registered(&rbd_dev->dev)) {
1551 ret = rbd_register_snap_dev(rbd_dev, snap,
1552 &rbd_dev->dev);
1553 if (ret < 0)
1554 goto err;
1555 }
1556 *snapp = snap;
1557 return 0;
1558err:
1559 kfree(snap->name);
1560 kfree(snap);
1561 return ret;
1562}
1563
1564/*
1565 * search for the previous snap in a null delimited string list
1566 */
1567const char *rbd_prev_snap_name(const char *name, const char *start)
1568{
1569 if (name < start + 2)
1570 return NULL;
1571
1572 name -= 2;
1573 while (*name) {
1574 if (name == start)
1575 return start;
1576 name--;
1577 }
1578 return name + 1;
1579}
1580
1581/*
1582 * compare the old list of snapshots that we have to what's in the header
1583 * and update it accordingly. Note that the header holds the snapshots
1584 * in a reverse order (from newest to oldest) and we need to go from
1585 * older to new so that we don't get a duplicate snap name when
1586 * doing the process (e.g., removed snapshot and recreated a new
1587 * one with the same name.
1588 */
1589static int __rbd_init_snaps_header(struct rbd_device *rbd_dev)
1590{
1591 const char *name, *first_name;
1592 int i = rbd_dev->header.total_snaps;
1593 struct rbd_snap *snap, *old_snap = NULL;
1594 int ret;
1595 struct list_head *p, *n;
1596
1597 first_name = rbd_dev->header.snap_names;
1598 name = first_name + rbd_dev->header.snap_names_len;
1599
1600 list_for_each_prev_safe(p, n, &rbd_dev->snaps) {
1601 u64 cur_id;
1602
1603 old_snap = list_entry(p, struct rbd_snap, node);
1604
1605 if (i)
1606 cur_id = rbd_dev->header.snapc->snaps[i - 1];
1607
1608 if (!i || old_snap->id < cur_id) {
1609 /* old_snap->id was skipped, thus was removed */
1610 __rbd_remove_snap_dev(rbd_dev, old_snap);
1611 continue;
1612 }
1613 if (old_snap->id == cur_id) {
1614 /* we have this snapshot already */
1615 i--;
1616 name = rbd_prev_snap_name(name, first_name);
1617 continue;
1618 }
1619 for (; i > 0;
1620 i--, name = rbd_prev_snap_name(name, first_name)) {
1621 if (!name) {
1622 WARN_ON(1);
1623 return -EINVAL;
1624 }
1625 cur_id = rbd_dev->header.snapc->snaps[i];
1626 /* snapshot removal? handle it above */
1627 if (cur_id >= old_snap->id)
1628 break;
1629 /* a new snapshot */
1630 ret = __rbd_add_snap_dev(rbd_dev, i - 1, name, &snap);
1631 if (ret < 0)
1632 return ret;
1633
1634 /* note that we add it backward so using n and not p */
1635 list_add(&snap->node, n);
1636 p = &snap->node;
1637 }
1638 }
1639 /* we're done going over the old snap list, just add what's left */
1640 for (; i > 0; i--) {
1641 name = rbd_prev_snap_name(name, first_name);
1642 if (!name) {
1643 WARN_ON(1);
1644 return -EINVAL;
1645 }
1646 ret = __rbd_add_snap_dev(rbd_dev, i - 1, name, &snap);
1647 if (ret < 0)
1648 return ret;
1649 list_add(&snap->node, &rbd_dev->snaps);
1650 }
1651
1652 return 0;
1653}
1654
1655
1656static void rbd_root_dev_release(struct device *dev)
1657{
1658}
1659
1660static struct device rbd_root_dev = {
1661 .init_name = "rbd",
1662 .release = rbd_root_dev_release,
1663};
1664
1665static int rbd_bus_add_dev(struct rbd_device *rbd_dev)
1666{
1667 int ret = -ENOMEM;
1668 struct device *dev;
1669 struct rbd_snap *snap;
1670
1671 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1672 dev = &rbd_dev->dev;
1673
1674 dev->bus = &rbd_bus_type;
1675 dev->type = &rbd_device_type;
1676 dev->parent = &rbd_root_dev;
1677 dev->release = rbd_dev_release;
1678 dev_set_name(dev, "%d", rbd_dev->id);
1679 ret = device_register(dev);
1680 if (ret < 0)
1681 goto done_free;
1682
1683 list_for_each_entry(snap, &rbd_dev->snaps, node) {
1684 ret = rbd_register_snap_dev(rbd_dev, snap,
1685 &rbd_dev->dev);
1686 if (ret < 0)
1384 break; 1687 break;
1385 } 1688 }
1386 1689
1387 mutex_unlock(&ctl_mutex); 1690 mutex_unlock(&ctl_mutex);
1388 return n; 1691 return 0;
1692done_free:
1693 mutex_unlock(&ctl_mutex);
1694 return ret;
1389} 1695}
1390 1696
1391static ssize_t class_rbd_add(struct class *c, 1697static void rbd_bus_del_dev(struct rbd_device *rbd_dev)
1392 struct class_attribute *attr, 1698{
1393 const char *buf, size_t count) 1699 device_unregister(&rbd_dev->dev);
1700}
1701
1702static ssize_t rbd_add(struct bus_type *bus, const char *buf, size_t count)
1394{ 1703{
1395 struct ceph_osd_client *osdc; 1704 struct ceph_osd_client *osdc;
1396 struct rbd_device *rbd_dev; 1705 struct rbd_device *rbd_dev;
@@ -1419,6 +1728,7 @@ static ssize_t class_rbd_add(struct class *c,
1419 /* static rbd_device initialization */ 1728 /* static rbd_device initialization */
1420 spin_lock_init(&rbd_dev->lock); 1729 spin_lock_init(&rbd_dev->lock);
1421 INIT_LIST_HEAD(&rbd_dev->node); 1730 INIT_LIST_HEAD(&rbd_dev->node);
1731 INIT_LIST_HEAD(&rbd_dev->snaps);
1422 1732
1423 /* generate unique id: find highest unique id, add one */ 1733 /* generate unique id: find highest unique id, add one */
1424 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 1734 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
@@ -1478,6 +1788,9 @@ static ssize_t class_rbd_add(struct class *c,
1478 } 1788 }
1479 rbd_dev->major = irc; 1789 rbd_dev->major = irc;
1480 1790
1791 rc = rbd_bus_add_dev(rbd_dev);
1792 if (rc)
1793 goto err_out_disk;
1481 /* set up and announce blkdev mapping */ 1794 /* set up and announce blkdev mapping */
1482 rc = rbd_init_disk(rbd_dev); 1795 rc = rbd_init_disk(rbd_dev);
1483 if (rc) 1796 if (rc)
@@ -1487,6 +1800,8 @@ static ssize_t class_rbd_add(struct class *c,
1487 1800
1488err_out_blkdev: 1801err_out_blkdev:
1489 unregister_blkdev(rbd_dev->major, rbd_dev->name); 1802 unregister_blkdev(rbd_dev->major, rbd_dev->name);
1803err_out_disk:
1804 rbd_free_disk(rbd_dev);
1490err_out_client: 1805err_out_client:
1491 rbd_put_client(rbd_dev); 1806 rbd_put_client(rbd_dev);
1492 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 1807 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
@@ -1518,35 +1833,10 @@ static struct rbd_device *__rbd_get_dev(unsigned long id)
1518 return NULL; 1833 return NULL;
1519} 1834}
1520 1835
1521static ssize_t class_rbd_remove(struct class *c, 1836static void rbd_dev_release(struct device *dev)
1522 struct class_attribute *attr,
1523 const char *buf,
1524 size_t count)
1525{ 1837{
1526 struct rbd_device *rbd_dev = NULL; 1838 struct rbd_device *rbd_dev =
1527 int target_id, rc; 1839 container_of(dev, struct rbd_device, dev);
1528 unsigned long ul;
1529
1530 rc = strict_strtoul(buf, 10, &ul);
1531 if (rc)
1532 return rc;
1533
1534 /* convert to int; abort if we lost anything in the conversion */
1535 target_id = (int) ul;
1536 if (target_id != ul)
1537 return -EINVAL;
1538
1539 /* remove object from list immediately */
1540 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1541
1542 rbd_dev = __rbd_get_dev(target_id);
1543 if (rbd_dev)
1544 list_del_init(&rbd_dev->node);
1545
1546 mutex_unlock(&ctl_mutex);
1547
1548 if (!rbd_dev)
1549 return -ENOENT;
1550 1840
1551 rbd_put_client(rbd_dev); 1841 rbd_put_client(rbd_dev);
1552 1842
@@ -1557,67 +1847,11 @@ static ssize_t class_rbd_remove(struct class *c,
1557 1847
1558 /* release module ref */ 1848 /* release module ref */
1559 module_put(THIS_MODULE); 1849 module_put(THIS_MODULE);
1560
1561 return count;
1562} 1850}
1563 1851
1564static ssize_t class_rbd_snaps_list(struct class *c, 1852static ssize_t rbd_remove(struct bus_type *bus,
1565 struct class_attribute *attr, 1853 const char *buf,
1566 char *data) 1854 size_t count)
1567{
1568 struct rbd_device *rbd_dev = NULL;
1569 struct list_head *tmp;
1570 struct rbd_image_header *header;
1571 int i, n = 0, max = PAGE_SIZE;
1572 int ret;
1573
1574 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1575
1576 n += snprintf(data, max, "#id\tsnap\tKB\n");
1577
1578 list_for_each(tmp, &rbd_dev_list) {
1579 char *names, *p;
1580 struct ceph_snap_context *snapc;
1581
1582 rbd_dev = list_entry(tmp, struct rbd_device, node);
1583 header = &rbd_dev->header;
1584
1585 down_read(&header->snap_rwsem);
1586
1587 names = header->snap_names;
1588 snapc = header->snapc;
1589
1590 n += snprintf(data + n, max - n, "%d\t%s\t%lld%s\n",
1591 rbd_dev->id, RBD_SNAP_HEAD_NAME,
1592 header->image_size >> 10,
1593 (!rbd_dev->cur_snap ? " (*)" : ""));
1594 if (n == max)
1595 break;
1596
1597 p = names;
1598 for (i = 0; i < header->total_snaps; i++, p += strlen(p) + 1) {
1599 n += snprintf(data + n, max - n, "%d\t%s\t%lld%s\n",
1600 rbd_dev->id, p, header->snap_sizes[i] >> 10,
1601 (rbd_dev->cur_snap &&
1602 (snap_index(header, i) == rbd_dev->cur_snap) ?
1603 " (*)" : ""));
1604 if (n == max)
1605 break;
1606 }
1607
1608 up_read(&header->snap_rwsem);
1609 }
1610
1611
1612 ret = n;
1613 mutex_unlock(&ctl_mutex);
1614 return ret;
1615}
1616
1617static ssize_t class_rbd_snaps_refresh(struct class *c,
1618 struct class_attribute *attr,
1619 const char *buf,
1620 size_t count)
1621{ 1855{
1622 struct rbd_device *rbd_dev = NULL; 1856 struct rbd_device *rbd_dev = NULL;
1623 int target_id, rc; 1857 int target_id, rc;
@@ -1641,95 +1875,70 @@ static ssize_t class_rbd_snaps_refresh(struct class *c,
1641 goto done; 1875 goto done;
1642 } 1876 }
1643 1877
1644 rc = rbd_update_snaps(rbd_dev); 1878 list_del_init(&rbd_dev->node);
1645 if (rc < 0) 1879
1646 ret = rc; 1880 __rbd_remove_all_snaps(rbd_dev);
1881 rbd_bus_del_dev(rbd_dev);
1647 1882
1648done: 1883done:
1649 mutex_unlock(&ctl_mutex); 1884 mutex_unlock(&ctl_mutex);
1650 return ret; 1885 return ret;
1651} 1886}
1652 1887
1653static ssize_t class_rbd_snap_create(struct class *c, 1888static ssize_t rbd_snap_add(struct device *dev,
1654 struct class_attribute *attr, 1889 struct device_attribute *attr,
1655 const char *buf, 1890 const char *buf,
1656 size_t count) 1891 size_t count)
1657{ 1892{
1658 struct rbd_device *rbd_dev = NULL; 1893 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1659 int target_id, ret; 1894 int ret;
1660 char *name; 1895 char *name = kmalloc(count + 1, GFP_KERNEL);
1661
1662 name = kmalloc(RBD_MAX_SNAP_NAME_LEN + 1, GFP_KERNEL);
1663 if (!name) 1896 if (!name)
1664 return -ENOMEM; 1897 return -ENOMEM;
1665 1898
1666 /* parse snaps add command */ 1899 snprintf(name, count, "%s", buf);
1667 if (sscanf(buf, "%d "
1668 "%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
1669 &target_id,
1670 name) != 2) {
1671 ret = -EINVAL;
1672 goto done;
1673 }
1674 1900
1675 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 1901 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1676 1902
1677 rbd_dev = __rbd_get_dev(target_id);
1678 if (!rbd_dev) {
1679 ret = -ENOENT;
1680 goto done_unlock;
1681 }
1682
1683 ret = rbd_header_add_snap(rbd_dev, 1903 ret = rbd_header_add_snap(rbd_dev,
1684 name, GFP_KERNEL); 1904 name, GFP_KERNEL);
1685 if (ret < 0) 1905 if (ret < 0)
1686 goto done_unlock; 1906 goto done_unlock;
1687 1907
1688 ret = rbd_update_snaps(rbd_dev); 1908 ret = __rbd_update_snaps(rbd_dev);
1689 if (ret < 0) 1909 if (ret < 0)
1690 goto done_unlock; 1910 goto done_unlock;
1691 1911
1692 ret = count; 1912 ret = count;
1693done_unlock: 1913done_unlock:
1694 mutex_unlock(&ctl_mutex); 1914 mutex_unlock(&ctl_mutex);
1695done:
1696 kfree(name); 1915 kfree(name);
1697 return ret; 1916 return ret;
1698} 1917}
1699 1918
1700static ssize_t class_rbd_rollback(struct class *c, 1919static ssize_t rbd_snap_rollback(struct device *dev,
1701 struct class_attribute *attr, 1920 struct device_attribute *attr,
1702 const char *buf, 1921 const char *buf,
1703 size_t count) 1922 size_t count)
1704{ 1923{
1705 struct rbd_device *rbd_dev = NULL; 1924 struct rbd_device *rbd_dev = dev_to_rbd(dev);
1706 int target_id, ret; 1925 int ret;
1707 u64 snapid; 1926 u64 snapid;
1708 char snap_name[RBD_MAX_SNAP_NAME_LEN];
1709 u64 cur_ofs; 1927 u64 cur_ofs;
1710 char *seg_name; 1928 char *seg_name = NULL;
1929 char *snap_name = kmalloc(count + 1, GFP_KERNEL);
1930 ret = -ENOMEM;
1931 if (!snap_name)
1932 return ret;
1711 1933
1712 /* parse snaps add command */ 1934 /* parse snaps add command */
1713 if (sscanf(buf, "%d " 1935 snprintf(snap_name, count, "%s", buf);
1714 "%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
1715 &target_id,
1716 snap_name) != 2) {
1717 return -EINVAL;
1718 }
1719
1720 ret = -ENOMEM;
1721 seg_name = kmalloc(RBD_MAX_SEG_NAME_LEN + 1, GFP_NOIO); 1936 seg_name = kmalloc(RBD_MAX_SEG_NAME_LEN + 1, GFP_NOIO);
1722 if (!seg_name) 1937 if (!seg_name)
1723 return ret; 1938 goto done;
1724 1939
1725 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 1940 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1726 1941
1727 rbd_dev = __rbd_get_dev(target_id);
1728 if (!rbd_dev) {
1729 ret = -ENOENT;
1730 goto done_unlock;
1731 }
1732
1733 ret = snap_by_name(&rbd_dev->header, snap_name, &snapid, NULL); 1942 ret = snap_by_name(&rbd_dev->header, snap_name, &snapid, NULL);
1734 if (ret < 0) 1943 if (ret < 0)
1735 goto done_unlock; 1944 goto done_unlock;
@@ -1750,7 +1959,7 @@ static ssize_t class_rbd_rollback(struct class *c,
1750 seg_name, ret); 1959 seg_name, ret);
1751 } 1960 }
1752 1961
1753 ret = rbd_update_snaps(rbd_dev); 1962 ret = __rbd_update_snaps(rbd_dev);
1754 if (ret < 0) 1963 if (ret < 0)
1755 goto done_unlock; 1964 goto done_unlock;
1756 1965
@@ -1758,57 +1967,42 @@ static ssize_t class_rbd_rollback(struct class *c,
1758 1967
1759done_unlock: 1968done_unlock:
1760 mutex_unlock(&ctl_mutex); 1969 mutex_unlock(&ctl_mutex);
1970done:
1761 kfree(seg_name); 1971 kfree(seg_name);
1972 kfree(snap_name);
1762 1973
1763 return ret; 1974 return ret;
1764} 1975}
1765 1976
1766static struct class_attribute class_rbd_attrs[] = { 1977static struct bus_attribute rbd_bus_attrs[] = {
1767 __ATTR(add, 0200, NULL, class_rbd_add), 1978 __ATTR(add, S_IWUSR, NULL, rbd_add),
1768 __ATTR(remove, 0200, NULL, class_rbd_remove), 1979 __ATTR(remove, S_IWUSR, NULL, rbd_remove),
1769 __ATTR(list, 0444, class_rbd_list, NULL),
1770 __ATTR(snaps_refresh, 0200, NULL, class_rbd_snaps_refresh),
1771 __ATTR(snap_create, 0200, NULL, class_rbd_snap_create),
1772 __ATTR(snaps_list, 0444, class_rbd_snaps_list, NULL),
1773 __ATTR(snap_rollback, 0200, NULL, class_rbd_rollback),
1774 __ATTR_NULL 1980 __ATTR_NULL
1775}; 1981};
1776 1982
1777/* 1983/*
1778 * create control files in sysfs 1984 * create control files in sysfs
1779 * /sys/class/rbd/... 1985 * /sys/bus/rbd/...
1780 */ 1986 */
1781static int rbd_sysfs_init(void) 1987static int rbd_sysfs_init(void)
1782{ 1988{
1783 int ret = -ENOMEM; 1989 int ret;
1784 1990
1785 class_rbd = kzalloc(sizeof(*class_rbd), GFP_KERNEL); 1991 rbd_bus_type.bus_attrs = rbd_bus_attrs;
1786 if (!class_rbd)
1787 goto out;
1788 1992
1789 class_rbd->name = DRV_NAME; 1993 ret = bus_register(&rbd_bus_type);
1790 class_rbd->owner = THIS_MODULE; 1994 if (ret < 0)
1791 class_rbd->class_release = class_rbd_release; 1995 return ret;
1792 class_rbd->class_attrs = class_rbd_attrs;
1793 1996
1794 ret = class_register(class_rbd); 1997 ret = device_register(&rbd_root_dev);
1795 if (ret)
1796 goto out_class;
1797 return 0;
1798 1998
1799out_class:
1800 kfree(class_rbd);
1801 class_rbd = NULL;
1802 pr_err(DRV_NAME ": failed to create class rbd\n");
1803out:
1804 return ret; 1999 return ret;
1805} 2000}
1806 2001
1807static void rbd_sysfs_cleanup(void) 2002static void rbd_sysfs_cleanup(void)
1808{ 2003{
1809 if (class_rbd) 2004 device_unregister(&rbd_root_dev);
1810 class_destroy(class_rbd); 2005 bus_unregister(&rbd_bus_type);
1811 class_rbd = NULL;
1812} 2006}
1813 2007
1814int __init rbd_init(void) 2008int __init rbd_init(void)
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 06e2812ba124..657873e4328d 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -65,14 +65,14 @@ enum blkif_state {
65 65
66struct blk_shadow { 66struct blk_shadow {
67 struct blkif_request req; 67 struct blkif_request req;
68 unsigned long request; 68 struct request *request;
69 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 69 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST];
70}; 70};
71 71
72static DEFINE_MUTEX(blkfront_mutex); 72static DEFINE_MUTEX(blkfront_mutex);
73static const struct block_device_operations xlvbd_block_fops; 73static const struct block_device_operations xlvbd_block_fops;
74 74
75#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE) 75#define BLK_RING_SIZE __CONST_RING_SIZE(blkif, PAGE_SIZE)
76 76
77/* 77/*
78 * We have one of these per vbd, whether ide, scsi or 'other'. They 78 * We have one of these per vbd, whether ide, scsi or 'other'. They
@@ -136,7 +136,7 @@ static void add_id_to_freelist(struct blkfront_info *info,
136 unsigned long id) 136 unsigned long id)
137{ 137{
138 info->shadow[id].req.id = info->shadow_free; 138 info->shadow[id].req.id = info->shadow_free;
139 info->shadow[id].request = 0; 139 info->shadow[id].request = NULL;
140 info->shadow_free = id; 140 info->shadow_free = id;
141} 141}
142 142
@@ -245,14 +245,11 @@ static int blkif_ioctl(struct block_device *bdev, fmode_t mode,
245} 245}
246 246
247/* 247/*
248 * blkif_queue_request 248 * Generate a Xen blkfront IO request from a blk layer request. Reads
249 * and writes are handled as expected. Since we lack a loose flush
250 * request, we map flushes into a full ordered barrier.
249 * 251 *
250 * request block io 252 * @req: a request struct
251 *
252 * id: for guest use only.
253 * operation: BLKIF_OP_{READ,WRITE,PROBE}
254 * buffer: buffer to read/write into. this should be a
255 * virtual address in the guest os.
256 */ 253 */
257static int blkif_queue_request(struct request *req) 254static int blkif_queue_request(struct request *req)
258{ 255{
@@ -281,7 +278,7 @@ static int blkif_queue_request(struct request *req)
281 /* Fill out a communications ring structure. */ 278 /* Fill out a communications ring structure. */
282 ring_req = RING_GET_REQUEST(&info->ring, info->ring.req_prod_pvt); 279 ring_req = RING_GET_REQUEST(&info->ring, info->ring.req_prod_pvt);
283 id = get_id_from_freelist(info); 280 id = get_id_from_freelist(info);
284 info->shadow[id].request = (unsigned long)req; 281 info->shadow[id].request = req;
285 282
286 ring_req->id = id; 283 ring_req->id = id;
287 ring_req->sector_number = (blkif_sector_t)blk_rq_pos(req); 284 ring_req->sector_number = (blkif_sector_t)blk_rq_pos(req);
@@ -289,8 +286,18 @@ static int blkif_queue_request(struct request *req)
289 286
290 ring_req->operation = rq_data_dir(req) ? 287 ring_req->operation = rq_data_dir(req) ?
291 BLKIF_OP_WRITE : BLKIF_OP_READ; 288 BLKIF_OP_WRITE : BLKIF_OP_READ;
292 if (req->cmd_flags & REQ_HARDBARRIER) 289
290 if (req->cmd_flags & (REQ_FLUSH | REQ_FUA)) {
291 /*
292 * Ideally we could just do an unordered
293 * flush-to-disk, but all we have is a full write
294 * barrier at the moment. However, a barrier write is
295 * a superset of FUA, so we can implement it the same
296 * way. (It's also a FLUSH+FUA, since it is
297 * guaranteed ordered WRT previous writes.)
298 */
293 ring_req->operation = BLKIF_OP_WRITE_BARRIER; 299 ring_req->operation = BLKIF_OP_WRITE_BARRIER;
300 }
294 301
295 ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg); 302 ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg);
296 BUG_ON(ring_req->nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST); 303 BUG_ON(ring_req->nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST);
@@ -636,7 +643,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
636 643
637 bret = RING_GET_RESPONSE(&info->ring, i); 644 bret = RING_GET_RESPONSE(&info->ring, i);
638 id = bret->id; 645 id = bret->id;
639 req = (struct request *)info->shadow[id].request; 646 req = info->shadow[id].request;
640 647
641 blkif_completion(&info->shadow[id]); 648 blkif_completion(&info->shadow[id]);
642 649
@@ -649,6 +656,16 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
649 printk(KERN_WARNING "blkfront: %s: write barrier op failed\n", 656 printk(KERN_WARNING "blkfront: %s: write barrier op failed\n",
650 info->gd->disk_name); 657 info->gd->disk_name);
651 error = -EOPNOTSUPP; 658 error = -EOPNOTSUPP;
659 }
660 if (unlikely(bret->status == BLKIF_RSP_ERROR &&
661 info->shadow[id].req.nr_segments == 0)) {
662 printk(KERN_WARNING "blkfront: %s: empty write barrier op failed\n",
663 info->gd->disk_name);
664 error = -EOPNOTSUPP;
665 }
666 if (unlikely(error)) {
667 if (error == -EOPNOTSUPP)
668 error = 0;
652 info->feature_flush = 0; 669 info->feature_flush = 0;
653 xlvbd_flush(info); 670 xlvbd_flush(info);
654 } 671 }
@@ -901,7 +918,7 @@ static int blkif_recover(struct blkfront_info *info)
901 /* Stage 3: Find pending requests and requeue them. */ 918 /* Stage 3: Find pending requests and requeue them. */
902 for (i = 0; i < BLK_RING_SIZE; i++) { 919 for (i = 0; i < BLK_RING_SIZE; i++) {
903 /* Not in use? */ 920 /* Not in use? */
904 if (copy[i].request == 0) 921 if (!copy[i].request)
905 continue; 922 continue;
906 923
907 /* Grab a request slot and copy shadow state into it. */ 924 /* Grab a request slot and copy shadow state into it. */
@@ -918,9 +935,7 @@ static int blkif_recover(struct blkfront_info *info)
918 req->seg[j].gref, 935 req->seg[j].gref,
919 info->xbdev->otherend_id, 936 info->xbdev->otherend_id,
920 pfn_to_mfn(info->shadow[req->id].frame[j]), 937 pfn_to_mfn(info->shadow[req->id].frame[j]),
921 rq_data_dir( 938 rq_data_dir(info->shadow[req->id].request));
922 (struct request *)
923 info->shadow[req->id].request));
924 info->shadow[req->id].req = *req; 939 info->shadow[req->id].req = *req;
925 940
926 info->ring.req_prod_pvt++; 941 info->ring.req_prod_pvt++;
@@ -1069,14 +1084,8 @@ static void blkfront_connect(struct blkfront_info *info)
1069 */ 1084 */
1070 info->feature_flush = 0; 1085 info->feature_flush = 0;
1071 1086
1072 /*
1073 * The driver doesn't properly handled empty flushes, so
1074 * lets disable barrier support for now.
1075 */
1076#if 0
1077 if (!err && barrier) 1087 if (!err && barrier)
1078 info->feature_flush = REQ_FLUSH; 1088 info->feature_flush = REQ_FLUSH | REQ_FUA;
1079#endif
1080 1089
1081 err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size); 1090 err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size);
1082 if (err) { 1091 if (err) {
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 128cae4e8629..949ed09c6361 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -35,6 +35,10 @@
35static struct usb_device_id ath3k_table[] = { 35static struct usb_device_id ath3k_table[] = {
36 /* Atheros AR3011 */ 36 /* Atheros AR3011 */
37 { USB_DEVICE(0x0CF3, 0x3000) }, 37 { USB_DEVICE(0x0CF3, 0x3000) },
38
39 /* Atheros AR3011 with sflash firmware*/
40 { USB_DEVICE(0x0CF3, 0x3002) },
41
38 { } /* Terminating entry */ 42 { } /* Terminating entry */
39}; 43};
40 44
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index d120a5c1c093..1da773f899a2 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -68,6 +68,9 @@ static struct usb_device_id btusb_table[] = {
68 /* Apple MacBookPro6,2 */ 68 /* Apple MacBookPro6,2 */
69 { USB_DEVICE(0x05ac, 0x8218) }, 69 { USB_DEVICE(0x05ac, 0x8218) },
70 70
71 /* Apple MacBookAir3,1, MacBookAir3,2 */
72 { USB_DEVICE(0x05ac, 0x821b) },
73
71 /* AVM BlueFRITZ! USB v2.0 */ 74 /* AVM BlueFRITZ! USB v2.0 */
72 { USB_DEVICE(0x057c, 0x3800) }, 75 { USB_DEVICE(0x057c, 0x3800) },
73 76
@@ -96,6 +99,9 @@ static struct usb_device_id blacklist_table[] = {
96 /* Broadcom BCM2033 without firmware */ 99 /* Broadcom BCM2033 without firmware */
97 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE }, 100 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
98 101
102 /* Atheros 3011 with sflash firmware */
103 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
104
99 /* Broadcom BCM2035 */ 105 /* Broadcom BCM2035 */
100 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, 106 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
101 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU }, 107 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
@@ -236,7 +242,8 @@ static void btusb_intr_complete(struct urb *urb)
236 242
237 err = usb_submit_urb(urb, GFP_ATOMIC); 243 err = usb_submit_urb(urb, GFP_ATOMIC);
238 if (err < 0) { 244 if (err < 0) {
239 BT_ERR("%s urb %p failed to resubmit (%d)", 245 if (err != -EPERM)
246 BT_ERR("%s urb %p failed to resubmit (%d)",
240 hdev->name, urb, -err); 247 hdev->name, urb, -err);
241 usb_unanchor_urb(urb); 248 usb_unanchor_urb(urb);
242 } 249 }
@@ -320,7 +327,8 @@ static void btusb_bulk_complete(struct urb *urb)
320 327
321 err = usb_submit_urb(urb, GFP_ATOMIC); 328 err = usb_submit_urb(urb, GFP_ATOMIC);
322 if (err < 0) { 329 if (err < 0) {
323 BT_ERR("%s urb %p failed to resubmit (%d)", 330 if (err != -EPERM)
331 BT_ERR("%s urb %p failed to resubmit (%d)",
324 hdev->name, urb, -err); 332 hdev->name, urb, -err);
325 usb_unanchor_urb(urb); 333 usb_unanchor_urb(urb);
326 } 334 }
@@ -409,7 +417,8 @@ static void btusb_isoc_complete(struct urb *urb)
409 417
410 err = usb_submit_urb(urb, GFP_ATOMIC); 418 err = usb_submit_urb(urb, GFP_ATOMIC);
411 if (err < 0) { 419 if (err < 0) {
412 BT_ERR("%s urb %p failed to resubmit (%d)", 420 if (err != -EPERM)
421 BT_ERR("%s urb %p failed to resubmit (%d)",
413 hdev->name, urb, -err); 422 hdev->name, urb, -err);
414 usb_unanchor_urb(urb); 423 usb_unanchor_urb(urb);
415 } 424 }
@@ -1029,6 +1038,8 @@ static int btusb_probe(struct usb_interface *intf,
1029 1038
1030 usb_set_intfdata(intf, data); 1039 usb_set_intfdata(intf, data);
1031 1040
1041 usb_enable_autosuspend(interface_to_usbdev(intf));
1042
1032 return 0; 1043 return 0;
1033} 1044}
1034 1045
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 3a9c01416839..ba53ec956c95 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -2,24 +2,10 @@
2# Makefile for the kernel character device drivers. 2# Makefile for the kernel character device drivers.
3# 3#
4 4
5# 5obj-y += mem.o random.o
6# This file contains the font map for the default (hardware) font
7#
8FONTMAPFILE = cp437.uni
9
10obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o tty_buffer.o tty_port.o
11
12obj-y += tty_mutex.o
13obj-$(CONFIG_LEGACY_PTYS) += pty.o
14obj-$(CONFIG_UNIX98_PTYS) += pty.o
15obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o 6obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o
16obj-y += misc.o 7obj-y += misc.o
17obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o
18obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o 8obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o
19obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o
20obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
21obj-$(CONFIG_AUDIT) += tty_audit.o
22obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
23obj-$(CONFIG_MVME147_SCC) += generic_serial.o vme_scc.o 9obj-$(CONFIG_MVME147_SCC) += generic_serial.o vme_scc.o
24obj-$(CONFIG_MVME162_SCC) += generic_serial.o vme_scc.o 10obj-$(CONFIG_MVME162_SCC) += generic_serial.o vme_scc.o
25obj-$(CONFIG_BVME6000_SCC) += generic_serial.o vme_scc.o 11obj-$(CONFIG_BVME6000_SCC) += generic_serial.o vme_scc.o
@@ -41,8 +27,6 @@ obj-$(CONFIG_ISI) += isicom.o
41obj-$(CONFIG_SYNCLINK) += synclink.o 27obj-$(CONFIG_SYNCLINK) += synclink.o
42obj-$(CONFIG_SYNCLINKMP) += synclinkmp.o 28obj-$(CONFIG_SYNCLINKMP) += synclinkmp.o
43obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o 29obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o
44obj-$(CONFIG_N_HDLC) += n_hdlc.o
45obj-$(CONFIG_N_GSM) += n_gsm.o
46obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o 30obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
47obj-$(CONFIG_SX) += sx.o generic_serial.o 31obj-$(CONFIG_SX) += sx.o generic_serial.o
48obj-$(CONFIG_RIO) += rio/ generic_serial.o 32obj-$(CONFIG_RIO) += rio/ generic_serial.o
@@ -74,7 +58,6 @@ obj-$(CONFIG_PRINTER) += lp.o
74obj-$(CONFIG_APM_EMULATION) += apm-emulation.o 58obj-$(CONFIG_APM_EMULATION) += apm-emulation.o
75 59
76obj-$(CONFIG_DTLK) += dtlk.o 60obj-$(CONFIG_DTLK) += dtlk.o
77obj-$(CONFIG_R3964) += n_r3964.o
78obj-$(CONFIG_APPLICOM) += applicom.o 61obj-$(CONFIG_APPLICOM) += applicom.o
79obj-$(CONFIG_SONYPI) += sonypi.o 62obj-$(CONFIG_SONYPI) += sonypi.o
80obj-$(CONFIG_RTC) += rtc.o 63obj-$(CONFIG_RTC) += rtc.o
@@ -115,28 +98,3 @@ obj-$(CONFIG_RAMOOPS) += ramoops.o
115 98
116obj-$(CONFIG_JS_RTC) += js-rtc.o 99obj-$(CONFIG_JS_RTC) += js-rtc.o
117js-rtc-y = rtc.o 100js-rtc-y = rtc.o
118
119# Files generated that shall be removed upon make clean
120clean-files := consolemap_deftbl.c defkeymap.c
121
122quiet_cmd_conmk = CONMK $@
123 cmd_conmk = scripts/conmakehash $< > $@
124
125$(obj)/consolemap_deftbl.c: $(src)/$(FONTMAPFILE)
126 $(call cmd,conmk)
127
128$(obj)/defkeymap.o: $(obj)/defkeymap.c
129
130# Uncomment if you're changing the keymap and have an appropriate
131# loadkeys version for the map. By default, we'll use the shipped
132# versions.
133# GENERATE_KEYMAP := 1
134
135ifdef GENERATE_KEYMAP
136
137$(obj)/defkeymap.c: $(obj)/%.c: $(src)/%.map
138 loadkeys --mktable $< > $@.tmp
139 sed -e 's/^static *//' $@.tmp > $@
140 rm $@.tmp
141
142endif
diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
index 43412c03969e..3cb4539a98b2 100644
--- a/drivers/char/agp/frontend.c
+++ b/drivers/char/agp/frontend.c
@@ -39,7 +39,6 @@
39#include <linux/mm.h> 39#include <linux/mm.h>
40#include <linux/fs.h> 40#include <linux/fs.h>
41#include <linux/sched.h> 41#include <linux/sched.h>
42#include <linux/smp_lock.h>
43#include <asm/uaccess.h> 42#include <asm/uaccess.h>
44#include <asm/pgtable.h> 43#include <asm/pgtable.h>
45#include "agp.h" 44#include "agp.h"
diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
index 6b6760ea2435..16a2847b7cdb 100644
--- a/drivers/char/agp/intel-gtt.c
+++ b/drivers/char/agp/intel-gtt.c
@@ -812,8 +812,10 @@ static int intel_fake_agp_fetch_size(void)
812 812
813static void i830_cleanup(void) 813static void i830_cleanup(void)
814{ 814{
815 kunmap(intel_private.i8xx_page); 815 if (intel_private.i8xx_flush_page) {
816 intel_private.i8xx_flush_page = NULL; 816 kunmap(intel_private.i8xx_flush_page);
817 intel_private.i8xx_flush_page = NULL;
818 }
817 819
818 __free_page(intel_private.i8xx_page); 820 __free_page(intel_private.i8xx_page);
819 intel_private.i8xx_page = NULL; 821 intel_private.i8xx_page = NULL;
@@ -1210,14 +1212,14 @@ static void gen6_write_entry(dma_addr_t addr, unsigned int entry,
1210 unsigned int gfdt = flags & AGP_USER_CACHED_MEMORY_GFDT; 1212 unsigned int gfdt = flags & AGP_USER_CACHED_MEMORY_GFDT;
1211 u32 pte_flags; 1213 u32 pte_flags;
1212 1214
1213 if (type_mask == AGP_USER_UNCACHED_MEMORY) 1215 if (type_mask == AGP_USER_MEMORY)
1214 pte_flags = GEN6_PTE_UNCACHED | I810_PTE_VALID; 1216 pte_flags = GEN6_PTE_UNCACHED | I810_PTE_VALID;
1215 else if (type_mask == AGP_USER_CACHED_MEMORY_LLC_MLC) { 1217 else if (type_mask == AGP_USER_CACHED_MEMORY_LLC_MLC) {
1216 pte_flags = GEN6_PTE_LLC | I810_PTE_VALID; 1218 pte_flags = GEN6_PTE_LLC_MLC | I810_PTE_VALID;
1217 if (gfdt) 1219 if (gfdt)
1218 pte_flags |= GEN6_PTE_GFDT; 1220 pte_flags |= GEN6_PTE_GFDT;
1219 } else { /* set 'normal'/'cached' to LLC by default */ 1221 } else { /* set 'normal'/'cached' to LLC by default */
1220 pte_flags = GEN6_PTE_LLC_MLC | I810_PTE_VALID; 1222 pte_flags = GEN6_PTE_LLC | I810_PTE_VALID;
1221 if (gfdt) 1223 if (gfdt)
1222 pte_flags |= GEN6_PTE_GFDT; 1224 pte_flags |= GEN6_PTE_GFDT;
1223 } 1225 }
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index b0a70461a12c..6ee3348bc3e4 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -81,7 +81,6 @@ static char *serial_version = "4.30";
81#include <linux/mm.h> 81#include <linux/mm.h>
82#include <linux/seq_file.h> 82#include <linux/seq_file.h>
83#include <linux/slab.h> 83#include <linux/slab.h>
84#include <linux/smp_lock.h>
85#include <linux/init.h> 84#include <linux/init.h>
86#include <linux/bitops.h> 85#include <linux/bitops.h>
87#include <linux/platform_device.h> 86#include <linux/platform_device.h>
@@ -1299,7 +1298,6 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1299{ 1298{
1300 struct async_struct * info = tty->driver_data; 1299 struct async_struct * info = tty->driver_data;
1301 struct async_icount cprev, cnow; /* kernel counter temps */ 1300 struct async_icount cprev, cnow; /* kernel counter temps */
1302 struct serial_icounter_struct icount;
1303 void __user *argp = (void __user *)arg; 1301 void __user *argp = (void __user *)arg;
1304 unsigned long flags; 1302 unsigned long flags;
1305 1303
diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
index f6718f05dad4..095ab90535ce 100644
--- a/drivers/char/briq_panel.c
+++ b/drivers/char/briq_panel.c
@@ -6,7 +6,6 @@
6 6
7#include <linux/module.h> 7#include <linux/module.h>
8 8
9#include <linux/smp_lock.h>
10#include <linux/types.h> 9#include <linux/types.h>
11#include <linux/errno.h> 10#include <linux/errno.h>
12#include <linux/tty.h> 11#include <linux/tty.h>
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 55b8667f739f..7066e801b9d3 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -14,7 +14,6 @@
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/smp_lock.h>
18#include <linux/types.h> 17#include <linux/types.h>
19#include <linux/miscdevice.h> 18#include <linux/miscdevice.h>
20#include <linux/major.h> 19#include <linux/major.h>
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 788da05190cc..2016aad85203 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -37,7 +37,6 @@
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/fs.h> 38#include <linux/fs.h>
39#include <linux/sched.h> 39#include <linux/sched.h>
40#include <linux/smp_lock.h>
41#include <linux/init.h> 40#include <linux/init.h>
42#include <linux/miscdevice.h> 41#include <linux/miscdevice.h>
43#include <linux/delay.h> 42#include <linux/delay.h>
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index 3bc0eef88717..d72433f2d310 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -120,7 +120,7 @@ static int i8k_smm(struct smm_regs *regs)
120 int eax = regs->eax; 120 int eax = regs->eax;
121 121
122#if defined(CONFIG_X86_64) 122#if defined(CONFIG_X86_64)
123 asm("pushq %%rax\n\t" 123 asm volatile("pushq %%rax\n\t"
124 "movl 0(%%rax),%%edx\n\t" 124 "movl 0(%%rax),%%edx\n\t"
125 "pushq %%rdx\n\t" 125 "pushq %%rdx\n\t"
126 "movl 4(%%rax),%%ebx\n\t" 126 "movl 4(%%rax),%%ebx\n\t"
@@ -146,7 +146,7 @@ static int i8k_smm(struct smm_regs *regs)
146 : "a"(regs) 146 : "a"(regs)
147 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); 147 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
148#else 148#else
149 asm("pushl %%eax\n\t" 149 asm volatile("pushl %%eax\n\t"
150 "movl 0(%%eax),%%edx\n\t" 150 "movl 0(%%eax),%%edx\n\t"
151 "push %%edx\n\t" 151 "push %%edx\n\t"
152 "movl 4(%%eax),%%ebx\n\t" 152 "movl 4(%%eax),%%ebx\n\t"
@@ -167,7 +167,8 @@ static int i8k_smm(struct smm_regs *regs)
167 "movl %%edx,0(%%eax)\n\t" 167 "movl %%edx,0(%%eax)\n\t"
168 "lahf\n\t" 168 "lahf\n\t"
169 "shrl $8,%%eax\n\t" 169 "shrl $8,%%eax\n\t"
170 "andl $1,%%eax\n":"=a"(rc) 170 "andl $1,%%eax\n"
171 :"=a"(rc)
171 : "a"(regs) 172 : "a"(regs)
172 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); 173 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
173#endif 174#endif
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 667abd23ad6a..7c6de4c92458 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -21,7 +21,6 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/sched.h> 22#include <linux/sched.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/smp_lock.h>
25#include <linux/interrupt.h> 24#include <linux/interrupt.h>
26#include <linux/tty.h> 25#include <linux/tty.h>
27#include <linux/tty_flip.h> 26#include <linux/tty_flip.h>
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index dd3f9b1f11b4..294d03e8c61a 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -1828,7 +1828,6 @@ static int ntty_ioctl(struct tty_struct *tty, struct file *file,
1828 unsigned int cmd, unsigned long arg) 1828 unsigned int cmd, unsigned long arg)
1829{ 1829{
1830 struct port *port = tty->driver_data; 1830 struct port *port = tty->driver_data;
1831 void __user *argp = (void __user *)arg;
1832 int rval = -ENOIOCTLCMD; 1831 int rval = -ENOIOCTLCMD;
1833 1832
1834 DBG1("******** IOCTL, cmd: %d", cmd); 1833 DBG1("******** IOCTL, cmd: %d", cmd);
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index d962f25dcc2a..777181a2e603 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -979,8 +979,9 @@ static ssize_t cmm_read(struct file *filp, __user char *buf, size_t count,
979 if (dev->flags0 & 1) { 979 if (dev->flags0 & 1) {
980 set_bit(IS_CMM_ABSENT, &dev->flags); 980 set_bit(IS_CMM_ABSENT, &dev->flags);
981 rc = -ENODEV; 981 rc = -ENODEV;
982 } else {
983 rc = -EIO;
982 } 984 }
983 rc = -EIO;
984 goto release_io; 985 goto release_io;
985 } 986 }
986 987
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index bfc10f89d951..eaa41992fbe2 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2796,6 +2796,7 @@ static const struct tty_operations mgslpc_ops = {
2796 .hangup = mgslpc_hangup, 2796 .hangup = mgslpc_hangup,
2797 .tiocmget = tiocmget, 2797 .tiocmget = tiocmget,
2798 .tiocmset = tiocmset, 2798 .tiocmset = tiocmset,
2799 .get_icount = mgslpc_get_icount,
2799 .proc_fops = &mgslpc_proc_fops, 2800 .proc_fops = &mgslpc_proc_fops,
2800}; 2801};
2801 2802
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index f646725bd567..748c3b0ecd89 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -52,7 +52,6 @@
52#include <linux/interrupt.h> 52#include <linux/interrupt.h>
53#include <linux/serial.h> 53#include <linux/serial.h>
54#include <linux/serialP.h> 54#include <linux/serialP.h>
55#include <linux/smp_lock.h>
56#include <linux/string.h> 55#include <linux/string.h>
57#include <linux/fcntl.h> 56#include <linux/fcntl.h>
58#include <linux/ptrace.h> 57#include <linux/ptrace.h>
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 9f8495b4fc8f..a7616d226a49 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -87,7 +87,6 @@
87#include <linux/tty_flip.h> 87#include <linux/tty_flip.h>
88#include <linux/mm.h> 88#include <linux/mm.h>
89#include <linux/serial.h> 89#include <linux/serial.h>
90#include <linux/smp_lock.h>
91#include <linux/fcntl.h> 90#include <linux/fcntl.h>
92#include <linux/major.h> 91#include <linux/major.h>
93#include <linux/delay.h> 92#include <linux/delay.h>
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 4bef6ab83622..461a5a045517 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -40,7 +40,6 @@
40#include <linux/stallion.h> 40#include <linux/stallion.h>
41#include <linux/ioport.h> 41#include <linux/ioport.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/smp_lock.h>
44#include <linux/device.h> 43#include <linux/device.h>
45#include <linux/delay.h> 44#include <linux/delay.h>
46#include <linux/ctype.h> 45#include <linux/ctype.h>
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index e53f16865397..a786326cea2f 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -216,7 +216,6 @@
216#include <linux/eisa.h> 216#include <linux/eisa.h>
217#include <linux/pci.h> 217#include <linux/pci.h>
218#include <linux/slab.h> 218#include <linux/slab.h>
219#include <linux/smp_lock.h>
220#include <linux/init.h> 219#include <linux/init.h>
221#include <linux/miscdevice.h> 220#include <linux/miscdevice.h>
222#include <linux/bitops.h> 221#include <linux/bitops.h>
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 1030f8420137..c17a305ecb28 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/wait.h> 27#include <linux/wait.h>
28#include <linux/acpi.h>
28#include "tpm.h" 29#include "tpm.h"
29 30
30#define TPM_HEADER_SIZE 10 31#define TPM_HEADER_SIZE 10
@@ -78,6 +79,26 @@ enum tis_defaults {
78static LIST_HEAD(tis_chips); 79static LIST_HEAD(tis_chips);
79static DEFINE_SPINLOCK(tis_lock); 80static DEFINE_SPINLOCK(tis_lock);
80 81
82#ifdef CONFIG_ACPI
83static int is_itpm(struct pnp_dev *dev)
84{
85 struct acpi_device *acpi = pnp_acpi_device(dev);
86 struct acpi_hardware_id *id;
87
88 list_for_each_entry(id, &acpi->pnp.ids, list) {
89 if (!strcmp("INTC0102", id->id))
90 return 1;
91 }
92
93 return 0;
94}
95#else
96static int is_itpm(struct pnp_dev *dev)
97{
98 return 0;
99}
100#endif
101
81static int check_locality(struct tpm_chip *chip, int l) 102static int check_locality(struct tpm_chip *chip, int l)
82{ 103{
83 if ((ioread8(chip->vendor.iobase + TPM_ACCESS(l)) & 104 if ((ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
@@ -472,6 +493,9 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
472 "1.2 TPM (device-id 0x%X, rev-id %d)\n", 493 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
473 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0))); 494 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
474 495
496 if (is_itpm(to_pnp_dev(dev)))
497 itpm = 1;
498
475 if (itpm) 499 if (itpm)
476 dev_info(dev, "Intel iTPM workaround enabled\n"); 500 dev_info(dev, "Intel iTPM workaround enabled\n");
477 501
diff --git a/drivers/char/uv_mmtimer.c b/drivers/char/uv_mmtimer.c
index 493b47a0d511..956ebe2080a5 100644
--- a/drivers/char/uv_mmtimer.c
+++ b/drivers/char/uv_mmtimer.c
@@ -23,7 +23,6 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/time.h> 24#include <linux/time.h>
25#include <linux/math64.h> 25#include <linux/math64.h>
26#include <linux/smp_lock.h>
27 26
28#include <asm/genapic.h> 27#include <asm/genapic.h>
29#include <asm/uv/uv_hub.h> 28#include <asm/uv/uv_hub.h>
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 6c1b676643a9..896a2ced1d27 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1547,31 +1547,16 @@ static int init_vqs(struct ports_device *portdev)
1547 nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2; 1547 nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
1548 1548
1549 vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL); 1549 vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
1550 if (!vqs) {
1551 err = -ENOMEM;
1552 goto fail;
1553 }
1554 io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL); 1550 io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL);
1555 if (!io_callbacks) {
1556 err = -ENOMEM;
1557 goto free_vqs;
1558 }
1559 io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL); 1551 io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL);
1560 if (!io_names) {
1561 err = -ENOMEM;
1562 goto free_callbacks;
1563 }
1564 portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *), 1552 portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
1565 GFP_KERNEL); 1553 GFP_KERNEL);
1566 if (!portdev->in_vqs) {
1567 err = -ENOMEM;
1568 goto free_names;
1569 }
1570 portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *), 1554 portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
1571 GFP_KERNEL); 1555 GFP_KERNEL);
1572 if (!portdev->out_vqs) { 1556 if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs ||
1557 !portdev->out_vqs) {
1573 err = -ENOMEM; 1558 err = -ENOMEM;
1574 goto free_invqs; 1559 goto free;
1575 } 1560 }
1576 1561
1577 /* 1562 /*
@@ -1605,7 +1590,7 @@ static int init_vqs(struct ports_device *portdev)
1605 io_callbacks, 1590 io_callbacks,
1606 (const char **)io_names); 1591 (const char **)io_names);
1607 if (err) 1592 if (err)
1608 goto free_outvqs; 1593 goto free;
1609 1594
1610 j = 0; 1595 j = 0;
1611 portdev->in_vqs[0] = vqs[0]; 1596 portdev->in_vqs[0] = vqs[0];
@@ -1621,23 +1606,19 @@ static int init_vqs(struct ports_device *portdev)
1621 portdev->out_vqs[i] = vqs[j + 1]; 1606 portdev->out_vqs[i] = vqs[j + 1];
1622 } 1607 }
1623 } 1608 }
1624 kfree(io_callbacks);
1625 kfree(io_names); 1609 kfree(io_names);
1610 kfree(io_callbacks);
1626 kfree(vqs); 1611 kfree(vqs);
1627 1612
1628 return 0; 1613 return 0;
1629 1614
1630free_names: 1615free:
1631 kfree(io_names);
1632free_callbacks:
1633 kfree(io_callbacks);
1634free_outvqs:
1635 kfree(portdev->out_vqs); 1616 kfree(portdev->out_vqs);
1636free_invqs:
1637 kfree(portdev->in_vqs); 1617 kfree(portdev->in_vqs);
1638free_vqs: 1618 kfree(io_names);
1619 kfree(io_callbacks);
1639 kfree(vqs); 1620 kfree(vqs);
1640fail: 1621
1641 return err; 1622 return err;
1642} 1623}
1643 1624
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
index a44611652282..f975d24890fa 100644
--- a/drivers/clocksource/sh_cmt.c
+++ b/drivers/clocksource/sh_cmt.c
@@ -283,16 +283,21 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p,
283 } while (delay); 283 } while (delay);
284} 284}
285 285
286static void sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta) 286static void __sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta)
287{ 287{
288 unsigned long flags;
289
290 if (delta > p->max_match_value) 288 if (delta > p->max_match_value)
291 dev_warn(&p->pdev->dev, "delta out of range\n"); 289 dev_warn(&p->pdev->dev, "delta out of range\n");
292 290
293 spin_lock_irqsave(&p->lock, flags);
294 p->next_match_value = delta; 291 p->next_match_value = delta;
295 sh_cmt_clock_event_program_verify(p, 0); 292 sh_cmt_clock_event_program_verify(p, 0);
293}
294
295static void sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta)
296{
297 unsigned long flags;
298
299 spin_lock_irqsave(&p->lock, flags);
300 __sh_cmt_set_next(p, delta);
296 spin_unlock_irqrestore(&p->lock, flags); 301 spin_unlock_irqrestore(&p->lock, flags);
297} 302}
298 303
@@ -359,7 +364,7 @@ static int sh_cmt_start(struct sh_cmt_priv *p, unsigned long flag)
359 364
360 /* setup timeout if no clockevent */ 365 /* setup timeout if no clockevent */
361 if ((flag == FLAG_CLOCKSOURCE) && (!(p->flags & FLAG_CLOCKEVENT))) 366 if ((flag == FLAG_CLOCKSOURCE) && (!(p->flags & FLAG_CLOCKEVENT)))
362 sh_cmt_set_next(p, p->max_match_value); 367 __sh_cmt_set_next(p, p->max_match_value);
363 out: 368 out:
364 spin_unlock_irqrestore(&p->lock, flags); 369 spin_unlock_irqrestore(&p->lock, flags);
365 370
@@ -381,7 +386,7 @@ static void sh_cmt_stop(struct sh_cmt_priv *p, unsigned long flag)
381 386
382 /* adjust the timeout to maximum if only clocksource left */ 387 /* adjust the timeout to maximum if only clocksource left */
383 if ((flag == FLAG_CLOCKEVENT) && (p->flags & FLAG_CLOCKSOURCE)) 388 if ((flag == FLAG_CLOCKEVENT) && (p->flags & FLAG_CLOCKSOURCE))
384 sh_cmt_set_next(p, p->max_match_value); 389 __sh_cmt_set_next(p, p->max_match_value);
385 390
386 spin_unlock_irqrestore(&p->lock, flags); 391 spin_unlock_irqrestore(&p->lock, flags);
387} 392}
@@ -616,13 +621,9 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
616 /* get hold of clock */ 621 /* get hold of clock */
617 p->clk = clk_get(&p->pdev->dev, "cmt_fck"); 622 p->clk = clk_get(&p->pdev->dev, "cmt_fck");
618 if (IS_ERR(p->clk)) { 623 if (IS_ERR(p->clk)) {
619 dev_warn(&p->pdev->dev, "using deprecated clock lookup\n"); 624 dev_err(&p->pdev->dev, "cannot get clock\n");
620 p->clk = clk_get(&p->pdev->dev, cfg->clk); 625 ret = PTR_ERR(p->clk);
621 if (IS_ERR(p->clk)) { 626 goto err1;
622 dev_err(&p->pdev->dev, "cannot get clock\n");
623 ret = PTR_ERR(p->clk);
624 goto err1;
625 }
626 } 627 }
627 628
628 if (resource_size(res) == 6) { 629 if (resource_size(res) == 6) {
diff --git a/drivers/clocksource/sh_mtu2.c b/drivers/clocksource/sh_mtu2.c
index ef7a5be8a09f..40630cb98237 100644
--- a/drivers/clocksource/sh_mtu2.c
+++ b/drivers/clocksource/sh_mtu2.c
@@ -287,13 +287,9 @@ static int sh_mtu2_setup(struct sh_mtu2_priv *p, struct platform_device *pdev)
287 /* get hold of clock */ 287 /* get hold of clock */
288 p->clk = clk_get(&p->pdev->dev, "mtu2_fck"); 288 p->clk = clk_get(&p->pdev->dev, "mtu2_fck");
289 if (IS_ERR(p->clk)) { 289 if (IS_ERR(p->clk)) {
290 dev_warn(&p->pdev->dev, "using deprecated clock lookup\n"); 290 dev_err(&p->pdev->dev, "cannot get clock\n");
291 p->clk = clk_get(&p->pdev->dev, cfg->clk); 291 ret = PTR_ERR(p->clk);
292 if (IS_ERR(p->clk)) { 292 goto err1;
293 dev_err(&p->pdev->dev, "cannot get clock\n");
294 ret = PTR_ERR(p->clk);
295 goto err1;
296 }
297 } 293 }
298 294
299 return sh_mtu2_register(p, (char *)dev_name(&p->pdev->dev), 295 return sh_mtu2_register(p, (char *)dev_name(&p->pdev->dev),
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
index de715901b82a..36aba9923060 100644
--- a/drivers/clocksource/sh_tmu.c
+++ b/drivers/clocksource/sh_tmu.c
@@ -393,13 +393,9 @@ static int sh_tmu_setup(struct sh_tmu_priv *p, struct platform_device *pdev)
393 /* get hold of clock */ 393 /* get hold of clock */
394 p->clk = clk_get(&p->pdev->dev, "tmu_fck"); 394 p->clk = clk_get(&p->pdev->dev, "tmu_fck");
395 if (IS_ERR(p->clk)) { 395 if (IS_ERR(p->clk)) {
396 dev_warn(&p->pdev->dev, "using deprecated clock lookup\n"); 396 dev_err(&p->pdev->dev, "cannot get clock\n");
397 p->clk = clk_get(&p->pdev->dev, cfg->clk); 397 ret = PTR_ERR(p->clk);
398 if (IS_ERR(p->clk)) { 398 goto err1;
399 dev_err(&p->pdev->dev, "cannot get clock\n");
400 ret = PTR_ERR(p->clk);
401 goto err1;
402 }
403 } 399 }
404 400
405 return sh_tmu_register(p, (char *)dev_name(&p->pdev->dev), 401 return sh_tmu_register(p, (char *)dev_name(&p->pdev->dev),
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index e16c3fa8d2e3..05117f1ad867 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -36,6 +36,7 @@
36MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
37MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>"); 37MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>");
38MODULE_DESCRIPTION("Generic userspace <-> kernelspace connector."); 38MODULE_DESCRIPTION("Generic userspace <-> kernelspace connector.");
39MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_CONNECTOR);
39 40
40static struct cn_dev cdev; 41static struct cn_dev cdev;
41 42
diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c
index 88ee01510ec0..76141262ea1d 100644
--- a/drivers/crypto/n2_core.c
+++ b/drivers/crypto/n2_core.c
@@ -1832,7 +1832,7 @@ static int __devinit get_irq_props(struct mdesc_handle *mdesc, u64 node,
1832 return -ENODEV; 1832 return -ENODEV;
1833 1833
1834 ino = mdesc_get_property(mdesc, node, "ino", &ino_len); 1834 ino = mdesc_get_property(mdesc, node, "ino", &ino_len);
1835 if (!intr) 1835 if (!ino)
1836 return -ENODEV; 1836 return -ENODEV;
1837 1837
1838 if (intr_len != ino_len) 1838 if (intr_len != ino_len)
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 2e992bc8015b..8a515baa38f7 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -286,7 +286,7 @@ static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
286 if (initial) 286 if (initial)
287 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" /* rep xcryptcbc */ 287 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" /* rep xcryptcbc */
288 : "+S" (input), "+D" (output), "+a" (iv) 288 : "+S" (input), "+D" (output), "+a" (iv)
289 : "d" (control_word), "b" (key), "c" (count)); 289 : "d" (control_word), "b" (key), "c" (initial));
290 290
291 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" /* rep xcryptcbc */ 291 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" /* rep xcryptcbc */
292 : "+S" (input), "+D" (output), "+a" (iv) 292 : "+S" (input), "+D" (output), "+a" (iv)
diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
index a8a84f4587f2..64b21f5cd740 100644
--- a/drivers/dma/Makefile
+++ b/drivers/dma/Makefile
@@ -1,8 +1,8 @@
1ifeq ($(CONFIG_DMADEVICES_DEBUG),y) 1ifeq ($(CONFIG_DMADEVICES_DEBUG),y)
2 EXTRA_CFLAGS += -DDEBUG 2 ccflags-y += -DDEBUG
3endif 3endif
4ifeq ($(CONFIG_DMADEVICES_VDEBUG),y) 4ifeq ($(CONFIG_DMADEVICES_VDEBUG),y)
5 EXTRA_CFLAGS += -DVERBOSE_DEBUG 5 ccflags-y += -DVERBOSE_DEBUG
6endif 6endif
7 7
8obj-$(CONFIG_DMA_ENGINE) += dmaengine.o 8obj-$(CONFIG_DMA_ENGINE) += dmaengine.o
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index a0f3e6a06e06..ea0ee81cff53 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -722,7 +722,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
722 desc->lli.daddr = mem; 722 desc->lli.daddr = mem;
723 desc->lli.ctrla = ctrla 723 desc->lli.ctrla = ctrla
724 | ATC_DST_WIDTH(mem_width) 724 | ATC_DST_WIDTH(mem_width)
725 | len >> mem_width; 725 | len >> reg_width;
726 desc->lli.ctrlb = ctrlb; 726 desc->lli.ctrlb = ctrlb;
727 727
728 if (!first) { 728 if (!first) {
diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c
index 286c3ac6bdcc..e5e172d21692 100644
--- a/drivers/dma/fsldma.c
+++ b/drivers/dma/fsldma.c
@@ -50,9 +50,11 @@ static void dma_init(struct fsldma_chan *chan)
50 * EIE - Error interrupt enable 50 * EIE - Error interrupt enable
51 * EOSIE - End of segments interrupt enable (basic mode) 51 * EOSIE - End of segments interrupt enable (basic mode)
52 * EOLNIE - End of links interrupt enable 52 * EOLNIE - End of links interrupt enable
53 * BWC - Bandwidth sharing among channels
53 */ 54 */
54 DMA_OUT(chan, &chan->regs->mr, FSL_DMA_MR_EIE 55 DMA_OUT(chan, &chan->regs->mr, FSL_DMA_MR_BWC
55 | FSL_DMA_MR_EOLNIE | FSL_DMA_MR_EOSIE, 32); 56 | FSL_DMA_MR_EIE | FSL_DMA_MR_EOLNIE
57 | FSL_DMA_MR_EOSIE, 32);
56 break; 58 break;
57 case FSL_DMA_IP_83XX: 59 case FSL_DMA_IP_83XX:
58 /* Set the channel to below modes: 60 /* Set the channel to below modes:
diff --git a/drivers/dma/fsldma.h b/drivers/dma/fsldma.h
index cb4d6ff51597..ba9f403c0fbe 100644
--- a/drivers/dma/fsldma.h
+++ b/drivers/dma/fsldma.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved. 2 * Copyright (C) 2007-2010 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Author: 4 * Author:
5 * Zhang Wei <wei.zhang@freescale.com>, Jul 2007 5 * Zhang Wei <wei.zhang@freescale.com>, Jul 2007
@@ -36,6 +36,13 @@
36#define FSL_DMA_MR_DAHE 0x00002000 36#define FSL_DMA_MR_DAHE 0x00002000
37#define FSL_DMA_MR_SAHE 0x00001000 37#define FSL_DMA_MR_SAHE 0x00001000
38 38
39/*
40 * Bandwidth/pause control determines how many bytes a given
41 * channel is allowed to transfer before the DMA engine pauses
42 * the current channel and switches to the next channel
43 */
44#define FSL_DMA_MR_BWC 0x08000000
45
39/* Special MR definition for MPC8349 */ 46/* Special MR definition for MPC8349 */
40#define FSL_DMA_MR_EOTIE 0x00000080 47#define FSL_DMA_MR_EOTIE 0x00000080
41#define FSL_DMA_MR_PRC_RM 0x00000800 48#define FSL_DMA_MR_PRC_RM 0x00000800
diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c
index f629e4961af5..e53d438142bb 100644
--- a/drivers/dma/imx-dma.c
+++ b/drivers/dma/imx-dma.c
@@ -379,7 +379,7 @@ static int __init imxdma_probe(struct platform_device *pdev)
379 return 0; 379 return 0;
380 380
381err_init: 381err_init:
382 while (i-- >= 0) { 382 while (--i >= 0) {
383 struct imxdma_channel *imxdmac = &imxdma->channel[i]; 383 struct imxdma_channel *imxdmac = &imxdma->channel[i];
384 imx_dma_free(imxdmac->imxdma_channel); 384 imx_dma_free(imxdmac->imxdma_channel);
385 } 385 }
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 0834323a0599..d0602dd5d1b2 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -951,7 +951,7 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
951 struct sdma_buffer_descriptor *bd = &sdmac->bd[i]; 951 struct sdma_buffer_descriptor *bd = &sdmac->bd[i];
952 int param; 952 int param;
953 953
954 bd->buffer_addr = sgl->dma_address; 954 bd->buffer_addr = sg->dma_address;
955 955
956 count = sg->length; 956 count = sg->length;
957 957
@@ -1385,7 +1385,7 @@ static int __init sdma_module_init(void)
1385{ 1385{
1386 return platform_driver_probe(&sdma_driver, sdma_probe); 1386 return platform_driver_probe(&sdma_driver, sdma_probe);
1387} 1387}
1388subsys_initcall(sdma_module_init); 1388module_init(sdma_module_init);
1389 1389
1390MODULE_AUTHOR("Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>"); 1390MODULE_AUTHOR("Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>");
1391MODULE_DESCRIPTION("i.MX SDMA driver"); 1391MODULE_DESCRIPTION("i.MX SDMA driver");
diff --git a/drivers/dma/intel_mid_dma.c b/drivers/dma/intel_mid_dma.c
index da8b7f161cdb..78266382797e 100644
--- a/drivers/dma/intel_mid_dma.c
+++ b/drivers/dma/intel_mid_dma.c
@@ -1075,7 +1075,6 @@ static int mid_setup_dma(struct pci_dev *pdev)
1075 if (NULL == dma->dma_pool) { 1075 if (NULL == dma->dma_pool) {
1076 pr_err("ERR_MDMA:pci_pool_create failed\n"); 1076 pr_err("ERR_MDMA:pci_pool_create failed\n");
1077 err = -ENOMEM; 1077 err = -ENOMEM;
1078 kfree(dma);
1079 goto err_dma_pool; 1078 goto err_dma_pool;
1080 } 1079 }
1081 1080
@@ -1186,7 +1185,6 @@ err_engine:
1186 free_irq(pdev->irq, dma); 1185 free_irq(pdev->irq, dma);
1187err_irq: 1186err_irq:
1188 pci_pool_destroy(dma->dma_pool); 1187 pci_pool_destroy(dma->dma_pool);
1189 kfree(dma);
1190err_dma_pool: 1188err_dma_pool:
1191 pr_err("ERR_MDMA:setup_dma failed: %d\n", err); 1189 pr_err("ERR_MDMA:setup_dma failed: %d\n", err);
1192 return err; 1190 return err;
@@ -1413,7 +1411,7 @@ static const struct dev_pm_ops intel_mid_dma_pm = {
1413 .runtime_idle = dma_runtime_idle, 1411 .runtime_idle = dma_runtime_idle,
1414}; 1412};
1415 1413
1416static struct pci_driver intel_mid_dma_pci = { 1414static struct pci_driver intel_mid_dma_pci_driver = {
1417 .name = "Intel MID DMA", 1415 .name = "Intel MID DMA",
1418 .id_table = intel_mid_dma_ids, 1416 .id_table = intel_mid_dma_ids,
1419 .probe = intel_mid_dma_probe, 1417 .probe = intel_mid_dma_probe,
@@ -1431,13 +1429,13 @@ static int __init intel_mid_dma_init(void)
1431{ 1429{
1432 pr_debug("INFO_MDMA: LNW DMA Driver Version %s\n", 1430 pr_debug("INFO_MDMA: LNW DMA Driver Version %s\n",
1433 INTEL_MID_DMA_DRIVER_VERSION); 1431 INTEL_MID_DMA_DRIVER_VERSION);
1434 return pci_register_driver(&intel_mid_dma_pci); 1432 return pci_register_driver(&intel_mid_dma_pci_driver);
1435} 1433}
1436fs_initcall(intel_mid_dma_init); 1434fs_initcall(intel_mid_dma_init);
1437 1435
1438static void __exit intel_mid_dma_exit(void) 1436static void __exit intel_mid_dma_exit(void)
1439{ 1437{
1440 pci_unregister_driver(&intel_mid_dma_pci); 1438 pci_unregister_driver(&intel_mid_dma_pci_driver);
1441} 1439}
1442module_exit(intel_mid_dma_exit); 1440module_exit(intel_mid_dma_exit);
1443 1441
diff --git a/drivers/dma/ioat/Makefile b/drivers/dma/ioat/Makefile
index 8997d3fb9051..0ff7270af25b 100644
--- a/drivers/dma/ioat/Makefile
+++ b/drivers/dma/ioat/Makefile
@@ -1,2 +1,2 @@
1obj-$(CONFIG_INTEL_IOATDMA) += ioatdma.o 1obj-$(CONFIG_INTEL_IOATDMA) += ioatdma.o
2ioatdma-objs := pci.o dma.o dma_v2.o dma_v3.o dca.o 2ioatdma-y := pci.o dma.o dma_v2.o dma_v3.o dca.o
diff --git a/drivers/dma/pch_dma.c b/drivers/dma/pch_dma.c
index 92b679024fed..c064c89420d0 100644
--- a/drivers/dma/pch_dma.c
+++ b/drivers/dma/pch_dma.c
@@ -259,11 +259,6 @@ static void pdc_dostart(struct pch_dma_chan *pd_chan, struct pch_dma_desc* desc)
259 return; 259 return;
260 } 260 }
261 261
262 channel_writel(pd_chan, DEV_ADDR, desc->regs.dev_addr);
263 channel_writel(pd_chan, MEM_ADDR, desc->regs.mem_addr);
264 channel_writel(pd_chan, SIZE, desc->regs.size);
265 channel_writel(pd_chan, NEXT, desc->regs.next);
266
267 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> dev_addr: %x\n", 262 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> dev_addr: %x\n",
268 pd_chan->chan.chan_id, desc->regs.dev_addr); 263 pd_chan->chan.chan_id, desc->regs.dev_addr);
269 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> mem_addr: %x\n", 264 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> mem_addr: %x\n",
@@ -273,10 +268,16 @@ static void pdc_dostart(struct pch_dma_chan *pd_chan, struct pch_dma_desc* desc)
273 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> next: %x\n", 268 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> next: %x\n",
274 pd_chan->chan.chan_id, desc->regs.next); 269 pd_chan->chan.chan_id, desc->regs.next);
275 270
276 if (list_empty(&desc->tx_list)) 271 if (list_empty(&desc->tx_list)) {
272 channel_writel(pd_chan, DEV_ADDR, desc->regs.dev_addr);
273 channel_writel(pd_chan, MEM_ADDR, desc->regs.mem_addr);
274 channel_writel(pd_chan, SIZE, desc->regs.size);
275 channel_writel(pd_chan, NEXT, desc->regs.next);
277 pdc_set_mode(&pd_chan->chan, DMA_CTL0_ONESHOT); 276 pdc_set_mode(&pd_chan->chan, DMA_CTL0_ONESHOT);
278 else 277 } else {
278 channel_writel(pd_chan, NEXT, desc->txd.phys);
279 pdc_set_mode(&pd_chan->chan, DMA_CTL0_SG); 279 pdc_set_mode(&pd_chan->chan, DMA_CTL0_SG);
280 }
280 281
281 val = dma_readl(pd, CTL2); 282 val = dma_readl(pd, CTL2);
282 val |= 1 << (DMA_CTL2_START_SHIFT_BITS + pd_chan->chan.chan_id); 283 val |= 1 << (DMA_CTL2_START_SHIFT_BITS + pd_chan->chan.chan_id);
diff --git a/drivers/dma/ppc4xx/adma.c b/drivers/dma/ppc4xx/adma.c
index 0d58a4a4487f..cef584533ee8 100644
--- a/drivers/dma/ppc4xx/adma.c
+++ b/drivers/dma/ppc4xx/adma.c
@@ -4449,9 +4449,8 @@ static int __devinit ppc440spe_adma_probe(struct platform_device *ofdev,
4449 4449
4450 if (!request_mem_region(res.start, resource_size(&res), 4450 if (!request_mem_region(res.start, resource_size(&res),
4451 dev_driver_string(&ofdev->dev))) { 4451 dev_driver_string(&ofdev->dev))) {
4452 dev_err(&ofdev->dev, "failed to request memory region " 4452 dev_err(&ofdev->dev, "failed to request memory region %pR\n",
4453 "(0x%016llx-0x%016llx)\n", 4453 &res);
4454 (u64)res.start, (u64)res.end);
4455 initcode = PPC_ADMA_INIT_MEMREG; 4454 initcode = PPC_ADMA_INIT_MEMREG;
4456 ret = -EBUSY; 4455 ret = -EBUSY;
4457 goto out; 4456 goto out;
diff --git a/drivers/dma/shdma.c b/drivers/dma/shdma.c
index eb6b54dbb806..85ffd5e38c50 100644
--- a/drivers/dma/shdma.c
+++ b/drivers/dma/shdma.c
@@ -1213,3 +1213,4 @@ module_exit(sh_dmae_exit);
1213MODULE_AUTHOR("Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>"); 1213MODULE_AUTHOR("Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>");
1214MODULE_DESCRIPTION("Renesas SH DMA Engine driver"); 1214MODULE_DESCRIPTION("Renesas SH DMA Engine driver");
1215MODULE_LICENSE("GPL"); 1215MODULE_LICENSE("GPL");
1216MODULE_ALIAS("platform:sh-dma-engine");
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index b3781399b38a..ba2898b3639b 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -10,16 +10,16 @@ obj-$(CONFIG_EDAC) := edac_stub.o
10obj-$(CONFIG_EDAC_MM_EDAC) += edac_core.o 10obj-$(CONFIG_EDAC_MM_EDAC) += edac_core.o
11obj-$(CONFIG_EDAC_MCE) += edac_mce.o 11obj-$(CONFIG_EDAC_MCE) += edac_mce.o
12 12
13edac_core-objs := edac_mc.o edac_device.o edac_mc_sysfs.o edac_pci_sysfs.o 13edac_core-y := edac_mc.o edac_device.o edac_mc_sysfs.o edac_pci_sysfs.o
14edac_core-objs += edac_module.o edac_device_sysfs.o 14edac_core-y += edac_module.o edac_device_sysfs.o
15 15
16ifdef CONFIG_PCI 16ifdef CONFIG_PCI
17edac_core-objs += edac_pci.o edac_pci_sysfs.o 17edac_core-y += edac_pci.o edac_pci_sysfs.o
18endif 18endif
19 19
20obj-$(CONFIG_EDAC_MCE_INJ) += mce_amd_inj.o 20obj-$(CONFIG_EDAC_MCE_INJ) += mce_amd_inj.o
21 21
22edac_mce_amd-objs := mce_amd.o 22edac_mce_amd-y := mce_amd.o
23obj-$(CONFIG_EDAC_DECODE_MCE) += edac_mce_amd.o 23obj-$(CONFIG_EDAC_DECODE_MCE) += edac_mce_amd.o
24 24
25obj-$(CONFIG_EDAC_AMD76X) += amd76x_edac.o 25obj-$(CONFIG_EDAC_AMD76X) += amd76x_edac.o
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 8521401bbd75..eca9ba193e94 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -1572,7 +1572,7 @@ static int f10_match_to_this_node(struct amd64_pvt *pvt, int dram_range,
1572 debugf1(" HoleOffset=0x%x HoleValid=0x%x IntlvSel=0x%x\n", 1572 debugf1(" HoleOffset=0x%x HoleValid=0x%x IntlvSel=0x%x\n",
1573 hole_off, hole_valid, intlv_sel); 1573 hole_off, hole_valid, intlv_sel);
1574 1574
1575 if (intlv_en || 1575 if (intlv_en &&
1576 (intlv_sel != ((sys_addr >> 12) & intlv_en))) 1576 (intlv_sel != ((sys_addr >> 12) & intlv_en)))
1577 return -EINVAL; 1577 return -EINVAL;
1578 1578
diff --git a/drivers/edac/edac_core.h b/drivers/edac/edac_core.h
index 035eaaf2d906..26db9ec5c44f 100644
--- a/drivers/edac/edac_core.h
+++ b/drivers/edac/edac_core.h
@@ -41,10 +41,10 @@
41#define MC_PROC_NAME_MAX_LEN 7 41#define MC_PROC_NAME_MAX_LEN 7
42 42
43#if PAGE_SHIFT < 20 43#if PAGE_SHIFT < 20
44#define PAGES_TO_MiB( pages ) ( ( pages ) >> ( 20 - PAGE_SHIFT ) ) 44#define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT))
45#define MiB_TO_PAGES(mb) ((mb) >> (20 - PAGE_SHIFT)) 45#define MiB_TO_PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
46#else /* PAGE_SHIFT > 20 */ 46#else /* PAGE_SHIFT > 20 */
47#define PAGES_TO_MiB( pages ) ( ( pages ) << ( PAGE_SHIFT - 20 ) ) 47#define PAGES_TO_MiB(pages) ((pages) << (PAGE_SHIFT - 20))
48#define MiB_TO_PAGES(mb) ((mb) >> (PAGE_SHIFT - 20)) 48#define MiB_TO_PAGES(mb) ((mb) >> (PAGE_SHIFT - 20))
49#endif 49#endif
50 50
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index ba6586a69ccc..795ea69c4d8f 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -586,14 +586,16 @@ struct mem_ctl_info *edac_mc_del_mc(struct device *dev)
586 return NULL; 586 return NULL;
587 } 587 }
588 588
589 /* marking MCI offline */
590 mci->op_state = OP_OFFLINE;
591
592 del_mc_from_global_list(mci); 589 del_mc_from_global_list(mci);
593 mutex_unlock(&mem_ctls_mutex); 590 mutex_unlock(&mem_ctls_mutex);
594 591
595 /* flush workq processes and remove sysfs */ 592 /* flush workq processes */
596 edac_mc_workq_teardown(mci); 593 edac_mc_workq_teardown(mci);
594
595 /* marking MCI offline */
596 mci->op_state = OP_OFFLINE;
597
598 /* remove from sysfs */
597 edac_remove_sysfs_mci_device(mci); 599 edac_remove_sysfs_mci_device(mci);
598 600
599 edac_printk(KERN_INFO, EDAC_MC, 601 edac_printk(KERN_INFO, EDAC_MC,
diff --git a/drivers/edac/mce_amd_inj.c b/drivers/edac/mce_amd_inj.c
index 8d0688f36d4c..39faded3cadd 100644
--- a/drivers/edac/mce_amd_inj.c
+++ b/drivers/edac/mce_amd_inj.c
@@ -139,7 +139,7 @@ static int __init edac_init_mce_inject(void)
139 return 0; 139 return 0;
140 140
141err_sysfs_create: 141err_sysfs_create:
142 while (i-- >= 0) 142 while (--i >= 0)
143 sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr); 143 sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr);
144 144
145 kobject_del(mce_kobj); 145 kobject_del(mce_kobj);
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index 18fdd9703b48..1a467a91fb0b 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/bug.h> 9#include <linux/bug.h>
10#include <linux/delay.h>
10#include <linux/device.h> 11#include <linux/device.h>
11#include <linux/firewire.h> 12#include <linux/firewire.h>
12#include <linux/firewire-constants.h> 13#include <linux/firewire-constants.h>
@@ -26,8 +27,14 @@
26#include <asm/unaligned.h> 27#include <asm/unaligned.h>
27#include <net/arp.h> 28#include <net/arp.h>
28 29
29#define FWNET_MAX_FRAGMENTS 25 /* arbitrary limit */ 30/* rx limits */
30#define FWNET_ISO_PAGE_COUNT (PAGE_SIZE < 16 * 1024 ? 4 : 2) 31#define FWNET_MAX_FRAGMENTS 30 /* arbitrary, > TX queue depth */
32#define FWNET_ISO_PAGE_COUNT (PAGE_SIZE < 16*1024 ? 4 : 2)
33
34/* tx limits */
35#define FWNET_MAX_QUEUED_DATAGRAMS 20 /* < 64 = number of tlabels */
36#define FWNET_MIN_QUEUED_DATAGRAMS 10 /* should keep AT DMA busy enough */
37#define FWNET_TX_QUEUE_LEN FWNET_MAX_QUEUED_DATAGRAMS /* ? */
31 38
32#define IEEE1394_BROADCAST_CHANNEL 31 39#define IEEE1394_BROADCAST_CHANNEL 31
33#define IEEE1394_ALL_NODES (0xffc0 | 0x003f) 40#define IEEE1394_ALL_NODES (0xffc0 | 0x003f)
@@ -169,15 +176,8 @@ struct fwnet_device {
169 struct fw_address_handler handler; 176 struct fw_address_handler handler;
170 u64 local_fifo; 177 u64 local_fifo;
171 178
172 /* List of packets to be sent */ 179 /* Number of tx datagrams that have been queued but not yet acked */
173 struct list_head packet_list; 180 int queued_datagrams;
174 /*
175 * List of packets that were broadcasted. When we get an ISO interrupt
176 * one of them has been sent
177 */
178 struct list_head broadcasted_list;
179 /* List of packets that have been sent but not yet acked */
180 struct list_head sent_list;
181 181
182 struct list_head peer_list; 182 struct list_head peer_list;
183 struct fw_card *card; 183 struct fw_card *card;
@@ -195,7 +195,7 @@ struct fwnet_peer {
195 unsigned pdg_size; /* pd_list size */ 195 unsigned pdg_size; /* pd_list size */
196 196
197 u16 datagram_label; /* outgoing datagram label */ 197 u16 datagram_label; /* outgoing datagram label */
198 unsigned max_payload; /* includes RFC2374_FRAG_HDR_SIZE overhead */ 198 u16 max_payload; /* includes RFC2374_FRAG_HDR_SIZE overhead */
199 int node_id; 199 int node_id;
200 int generation; 200 int generation;
201 unsigned speed; 201 unsigned speed;
@@ -203,22 +203,18 @@ struct fwnet_peer {
203 203
204/* This is our task struct. It's used for the packet complete callback. */ 204/* This is our task struct. It's used for the packet complete callback. */
205struct fwnet_packet_task { 205struct fwnet_packet_task {
206 /*
207 * ptask can actually be on dev->packet_list, dev->broadcasted_list,
208 * or dev->sent_list depending on its current state.
209 */
210 struct list_head pt_link;
211 struct fw_transaction transaction; 206 struct fw_transaction transaction;
212 struct rfc2734_header hdr; 207 struct rfc2734_header hdr;
213 struct sk_buff *skb; 208 struct sk_buff *skb;
214 struct fwnet_device *dev; 209 struct fwnet_device *dev;
215 210
216 int outstanding_pkts; 211 int outstanding_pkts;
217 unsigned max_payload;
218 u64 fifo_addr; 212 u64 fifo_addr;
219 u16 dest_node; 213 u16 dest_node;
214 u16 max_payload;
220 u8 generation; 215 u8 generation;
221 u8 speed; 216 u8 speed;
217 u8 enqueued;
222}; 218};
223 219
224/* 220/*
@@ -650,8 +646,6 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
650 net->stats.rx_packets++; 646 net->stats.rx_packets++;
651 net->stats.rx_bytes += skb->len; 647 net->stats.rx_bytes += skb->len;
652 } 648 }
653 if (netif_queue_stopped(net))
654 netif_wake_queue(net);
655 649
656 return 0; 650 return 0;
657 651
@@ -660,8 +654,6 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
660 net->stats.rx_dropped++; 654 net->stats.rx_dropped++;
661 655
662 dev_kfree_skb_any(skb); 656 dev_kfree_skb_any(skb);
663 if (netif_queue_stopped(net))
664 netif_wake_queue(net);
665 657
666 return -ENOENT; 658 return -ENOENT;
667} 659}
@@ -793,15 +785,10 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,
793 * Datagram is not complete, we're done for the 785 * Datagram is not complete, we're done for the
794 * moment. 786 * moment.
795 */ 787 */
796 spin_unlock_irqrestore(&dev->lock, flags); 788 retval = 0;
797
798 return 0;
799 fail: 789 fail:
800 spin_unlock_irqrestore(&dev->lock, flags); 790 spin_unlock_irqrestore(&dev->lock, flags);
801 791
802 if (netif_queue_stopped(net))
803 netif_wake_queue(net);
804
805 return retval; 792 return retval;
806} 793}
807 794
@@ -901,11 +888,19 @@ static void fwnet_free_ptask(struct fwnet_packet_task *ptask)
901 kmem_cache_free(fwnet_packet_task_cache, ptask); 888 kmem_cache_free(fwnet_packet_task_cache, ptask);
902} 889}
903 890
891/* Caller must hold dev->lock. */
892static void dec_queued_datagrams(struct fwnet_device *dev)
893{
894 if (--dev->queued_datagrams == FWNET_MIN_QUEUED_DATAGRAMS)
895 netif_wake_queue(dev->netdev);
896}
897
904static int fwnet_send_packet(struct fwnet_packet_task *ptask); 898static int fwnet_send_packet(struct fwnet_packet_task *ptask);
905 899
906static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask) 900static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
907{ 901{
908 struct fwnet_device *dev = ptask->dev; 902 struct fwnet_device *dev = ptask->dev;
903 struct sk_buff *skb = ptask->skb;
909 unsigned long flags; 904 unsigned long flags;
910 bool free; 905 bool free;
911 906
@@ -914,10 +909,14 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
914 ptask->outstanding_pkts--; 909 ptask->outstanding_pkts--;
915 910
916 /* Check whether we or the networking TX soft-IRQ is last user. */ 911 /* Check whether we or the networking TX soft-IRQ is last user. */
917 free = (ptask->outstanding_pkts == 0 && !list_empty(&ptask->pt_link)); 912 free = (ptask->outstanding_pkts == 0 && ptask->enqueued);
913 if (free)
914 dec_queued_datagrams(dev);
918 915
919 if (ptask->outstanding_pkts == 0) 916 if (ptask->outstanding_pkts == 0) {
920 list_del(&ptask->pt_link); 917 dev->netdev->stats.tx_packets++;
918 dev->netdev->stats.tx_bytes += skb->len;
919 }
921 920
922 spin_unlock_irqrestore(&dev->lock, flags); 921 spin_unlock_irqrestore(&dev->lock, flags);
923 922
@@ -926,7 +925,6 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
926 u16 fg_off; 925 u16 fg_off;
927 u16 datagram_label; 926 u16 datagram_label;
928 u16 lf; 927 u16 lf;
929 struct sk_buff *skb;
930 928
931 /* Update the ptask to point to the next fragment and send it */ 929 /* Update the ptask to point to the next fragment and send it */
932 lf = fwnet_get_hdr_lf(&ptask->hdr); 930 lf = fwnet_get_hdr_lf(&ptask->hdr);
@@ -953,7 +951,7 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
953 datagram_label = fwnet_get_hdr_dgl(&ptask->hdr); 951 datagram_label = fwnet_get_hdr_dgl(&ptask->hdr);
954 break; 952 break;
955 } 953 }
956 skb = ptask->skb; 954
957 skb_pull(skb, ptask->max_payload); 955 skb_pull(skb, ptask->max_payload);
958 if (ptask->outstanding_pkts > 1) { 956 if (ptask->outstanding_pkts > 1) {
959 fwnet_make_sf_hdr(&ptask->hdr, RFC2374_HDR_INTFRAG, 957 fwnet_make_sf_hdr(&ptask->hdr, RFC2374_HDR_INTFRAG,
@@ -970,6 +968,31 @@ static void fwnet_transmit_packet_done(struct fwnet_packet_task *ptask)
970 fwnet_free_ptask(ptask); 968 fwnet_free_ptask(ptask);
971} 969}
972 970
971static void fwnet_transmit_packet_failed(struct fwnet_packet_task *ptask)
972{
973 struct fwnet_device *dev = ptask->dev;
974 unsigned long flags;
975 bool free;
976
977 spin_lock_irqsave(&dev->lock, flags);
978
979 /* One fragment failed; don't try to send remaining fragments. */
980 ptask->outstanding_pkts = 0;
981
982 /* Check whether we or the networking TX soft-IRQ is last user. */
983 free = ptask->enqueued;
984 if (free)
985 dec_queued_datagrams(dev);
986
987 dev->netdev->stats.tx_dropped++;
988 dev->netdev->stats.tx_errors++;
989
990 spin_unlock_irqrestore(&dev->lock, flags);
991
992 if (free)
993 fwnet_free_ptask(ptask);
994}
995
973static void fwnet_write_complete(struct fw_card *card, int rcode, 996static void fwnet_write_complete(struct fw_card *card, int rcode,
974 void *payload, size_t length, void *data) 997 void *payload, size_t length, void *data)
975{ 998{
@@ -977,11 +1000,12 @@ static void fwnet_write_complete(struct fw_card *card, int rcode,
977 1000
978 ptask = data; 1001 ptask = data;
979 1002
980 if (rcode == RCODE_COMPLETE) 1003 if (rcode == RCODE_COMPLETE) {
981 fwnet_transmit_packet_done(ptask); 1004 fwnet_transmit_packet_done(ptask);
982 else 1005 } else {
983 fw_error("fwnet_write_complete: failed: %x\n", rcode); 1006 fw_error("fwnet_write_complete: failed: %x\n", rcode);
984 /* ??? error recovery */ 1007 fwnet_transmit_packet_failed(ptask);
1008 }
985} 1009}
986 1010
987static int fwnet_send_packet(struct fwnet_packet_task *ptask) 1011static int fwnet_send_packet(struct fwnet_packet_task *ptask)
@@ -1039,9 +1063,11 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)
1039 spin_lock_irqsave(&dev->lock, flags); 1063 spin_lock_irqsave(&dev->lock, flags);
1040 1064
1041 /* If the AT tasklet already ran, we may be last user. */ 1065 /* If the AT tasklet already ran, we may be last user. */
1042 free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link)); 1066 free = (ptask->outstanding_pkts == 0 && !ptask->enqueued);
1043 if (!free) 1067 if (!free)
1044 list_add_tail(&ptask->pt_link, &dev->broadcasted_list); 1068 ptask->enqueued = true;
1069 else
1070 dec_queued_datagrams(dev);
1045 1071
1046 spin_unlock_irqrestore(&dev->lock, flags); 1072 spin_unlock_irqrestore(&dev->lock, flags);
1047 1073
@@ -1056,9 +1082,11 @@ static int fwnet_send_packet(struct fwnet_packet_task *ptask)
1056 spin_lock_irqsave(&dev->lock, flags); 1082 spin_lock_irqsave(&dev->lock, flags);
1057 1083
1058 /* If the AT tasklet already ran, we may be last user. */ 1084 /* If the AT tasklet already ran, we may be last user. */
1059 free = (ptask->outstanding_pkts == 0 && list_empty(&ptask->pt_link)); 1085 free = (ptask->outstanding_pkts == 0 && !ptask->enqueued);
1060 if (!free) 1086 if (!free)
1061 list_add_tail(&ptask->pt_link, &dev->sent_list); 1087 ptask->enqueued = true;
1088 else
1089 dec_queued_datagrams(dev);
1062 1090
1063 spin_unlock_irqrestore(&dev->lock, flags); 1091 spin_unlock_irqrestore(&dev->lock, flags);
1064 1092
@@ -1224,6 +1252,15 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
1224 struct fwnet_peer *peer; 1252 struct fwnet_peer *peer;
1225 unsigned long flags; 1253 unsigned long flags;
1226 1254
1255 spin_lock_irqsave(&dev->lock, flags);
1256
1257 /* Can this happen? */
1258 if (netif_queue_stopped(dev->netdev)) {
1259 spin_unlock_irqrestore(&dev->lock, flags);
1260
1261 return NETDEV_TX_BUSY;
1262 }
1263
1227 ptask = kmem_cache_alloc(fwnet_packet_task_cache, GFP_ATOMIC); 1264 ptask = kmem_cache_alloc(fwnet_packet_task_cache, GFP_ATOMIC);
1228 if (ptask == NULL) 1265 if (ptask == NULL)
1229 goto fail; 1266 goto fail;
@@ -1242,9 +1279,6 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
1242 proto = hdr_buf.h_proto; 1279 proto = hdr_buf.h_proto;
1243 dg_size = skb->len; 1280 dg_size = skb->len;
1244 1281
1245 /* serialize access to peer, including peer->datagram_label */
1246 spin_lock_irqsave(&dev->lock, flags);
1247
1248 /* 1282 /*
1249 * Set the transmission type for the packet. ARP packets and IP 1283 * Set the transmission type for the packet. ARP packets and IP
1250 * broadcast packets are sent via GASP. 1284 * broadcast packets are sent via GASP.
@@ -1266,7 +1300,7 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
1266 1300
1267 peer = fwnet_peer_find_by_guid(dev, be64_to_cpu(guid)); 1301 peer = fwnet_peer_find_by_guid(dev, be64_to_cpu(guid));
1268 if (!peer || peer->fifo == FWNET_NO_FIFO_ADDR) 1302 if (!peer || peer->fifo == FWNET_NO_FIFO_ADDR)
1269 goto fail_unlock; 1303 goto fail;
1270 1304
1271 generation = peer->generation; 1305 generation = peer->generation;
1272 dest_node = peer->node_id; 1306 dest_node = peer->node_id;
@@ -1320,18 +1354,21 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
1320 max_payload += RFC2374_FRAG_HDR_SIZE; 1354 max_payload += RFC2374_FRAG_HDR_SIZE;
1321 } 1355 }
1322 1356
1357 if (++dev->queued_datagrams == FWNET_MAX_QUEUED_DATAGRAMS)
1358 netif_stop_queue(dev->netdev);
1359
1323 spin_unlock_irqrestore(&dev->lock, flags); 1360 spin_unlock_irqrestore(&dev->lock, flags);
1324 1361
1325 ptask->max_payload = max_payload; 1362 ptask->max_payload = max_payload;
1326 INIT_LIST_HEAD(&ptask->pt_link); 1363 ptask->enqueued = 0;
1327 1364
1328 fwnet_send_packet(ptask); 1365 fwnet_send_packet(ptask);
1329 1366
1330 return NETDEV_TX_OK; 1367 return NETDEV_TX_OK;
1331 1368
1332 fail_unlock:
1333 spin_unlock_irqrestore(&dev->lock, flags);
1334 fail: 1369 fail:
1370 spin_unlock_irqrestore(&dev->lock, flags);
1371
1335 if (ptask) 1372 if (ptask)
1336 kmem_cache_free(fwnet_packet_task_cache, ptask); 1373 kmem_cache_free(fwnet_packet_task_cache, ptask);
1337 1374
@@ -1377,7 +1414,7 @@ static void fwnet_init_dev(struct net_device *net)
1377 net->addr_len = FWNET_ALEN; 1414 net->addr_len = FWNET_ALEN;
1378 net->hard_header_len = FWNET_HLEN; 1415 net->hard_header_len = FWNET_HLEN;
1379 net->type = ARPHRD_IEEE1394; 1416 net->type = ARPHRD_IEEE1394;
1380 net->tx_queue_len = 10; 1417 net->tx_queue_len = FWNET_TX_QUEUE_LEN;
1381} 1418}
1382 1419
1383/* caller must hold fwnet_device_mutex */ 1420/* caller must hold fwnet_device_mutex */
@@ -1457,14 +1494,9 @@ static int fwnet_probe(struct device *_dev)
1457 dev->broadcast_rcv_context = NULL; 1494 dev->broadcast_rcv_context = NULL;
1458 dev->broadcast_xmt_max_payload = 0; 1495 dev->broadcast_xmt_max_payload = 0;
1459 dev->broadcast_xmt_datagramlabel = 0; 1496 dev->broadcast_xmt_datagramlabel = 0;
1460
1461 dev->local_fifo = FWNET_NO_FIFO_ADDR; 1497 dev->local_fifo = FWNET_NO_FIFO_ADDR;
1462 1498 dev->queued_datagrams = 0;
1463 INIT_LIST_HEAD(&dev->packet_list);
1464 INIT_LIST_HEAD(&dev->broadcasted_list);
1465 INIT_LIST_HEAD(&dev->sent_list);
1466 INIT_LIST_HEAD(&dev->peer_list); 1499 INIT_LIST_HEAD(&dev->peer_list);
1467
1468 dev->card = card; 1500 dev->card = card;
1469 dev->netdev = net; 1501 dev->netdev = net;
1470 1502
@@ -1522,7 +1554,7 @@ static int fwnet_remove(struct device *_dev)
1522 struct fwnet_peer *peer = dev_get_drvdata(_dev); 1554 struct fwnet_peer *peer = dev_get_drvdata(_dev);
1523 struct fwnet_device *dev = peer->dev; 1555 struct fwnet_device *dev = peer->dev;
1524 struct net_device *net; 1556 struct net_device *net;
1525 struct fwnet_packet_task *ptask, *pt_next; 1557 int i;
1526 1558
1527 mutex_lock(&fwnet_device_mutex); 1559 mutex_lock(&fwnet_device_mutex);
1528 1560
@@ -1540,21 +1572,9 @@ static int fwnet_remove(struct device *_dev)
1540 dev->card); 1572 dev->card);
1541 fw_iso_context_destroy(dev->broadcast_rcv_context); 1573 fw_iso_context_destroy(dev->broadcast_rcv_context);
1542 } 1574 }
1543 list_for_each_entry_safe(ptask, pt_next, 1575 for (i = 0; dev->queued_datagrams && i < 5; i++)
1544 &dev->packet_list, pt_link) { 1576 ssleep(1);
1545 dev_kfree_skb_any(ptask->skb); 1577 WARN_ON(dev->queued_datagrams);
1546 kmem_cache_free(fwnet_packet_task_cache, ptask);
1547 }
1548 list_for_each_entry_safe(ptask, pt_next,
1549 &dev->broadcasted_list, pt_link) {
1550 dev_kfree_skb_any(ptask->skb);
1551 kmem_cache_free(fwnet_packet_task_cache, ptask);
1552 }
1553 list_for_each_entry_safe(ptask, pt_next,
1554 &dev->sent_list, pt_link) {
1555 dev_kfree_skb_any(ptask->skb);
1556 kmem_cache_free(fwnet_packet_task_cache, ptask);
1557 }
1558 list_del(&dev->dev_link); 1578 list_del(&dev->dev_link);
1559 1579
1560 free_netdev(net); 1580 free_netdev(net);
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index 9dcb17d51aee..e3c8b60bd86b 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -242,6 +242,7 @@ static inline struct fw_ohci *fw_ohci(struct fw_card *card)
242 242
243static char ohci_driver_name[] = KBUILD_MODNAME; 243static char ohci_driver_name[] = KBUILD_MODNAME;
244 244
245#define PCI_DEVICE_ID_AGERE_FW643 0x5901
245#define PCI_DEVICE_ID_JMICRON_JMB38X_FW 0x2380 246#define PCI_DEVICE_ID_JMICRON_JMB38X_FW 0x2380
246#define PCI_DEVICE_ID_TI_TSB12LV22 0x8009 247#define PCI_DEVICE_ID_TI_TSB12LV22 0x8009
247 248
@@ -253,18 +254,34 @@ static char ohci_driver_name[] = KBUILD_MODNAME;
253 254
254/* In case of multiple matches in ohci_quirks[], only the first one is used. */ 255/* In case of multiple matches in ohci_quirks[], only the first one is used. */
255static const struct { 256static const struct {
256 unsigned short vendor, device, flags; 257 unsigned short vendor, device, revision, flags;
257} ohci_quirks[] = { 258} ohci_quirks[] = {
258 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, QUIRK_CYCLE_TIMER | 259 {PCI_VENDOR_ID_AL, PCI_ANY_ID, PCI_ANY_ID,
259 QUIRK_RESET_PACKET | 260 QUIRK_CYCLE_TIMER},
260 QUIRK_NO_1394A}, 261
261 {PCI_VENDOR_ID_TI, PCI_ANY_ID, QUIRK_RESET_PACKET}, 262 {PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_FW, PCI_ANY_ID,
262 {PCI_VENDOR_ID_AL, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, 263 QUIRK_BE_HEADERS},
263 {PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB38X_FW, QUIRK_NO_MSI}, 264
264 {PCI_VENDOR_ID_NEC, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, 265 {PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_AGERE_FW643, 6,
265 {PCI_VENDOR_ID_VIA, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, 266 QUIRK_NO_MSI},
266 {PCI_VENDOR_ID_RICOH, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, 267
267 {PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_FW, QUIRK_BE_HEADERS}, 268 {PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB38X_FW, PCI_ANY_ID,
269 QUIRK_NO_MSI},
270
271 {PCI_VENDOR_ID_NEC, PCI_ANY_ID, PCI_ANY_ID,
272 QUIRK_CYCLE_TIMER},
273
274 {PCI_VENDOR_ID_RICOH, PCI_ANY_ID, PCI_ANY_ID,
275 QUIRK_CYCLE_TIMER},
276
277 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, PCI_ANY_ID,
278 QUIRK_CYCLE_TIMER | QUIRK_RESET_PACKET | QUIRK_NO_1394A},
279
280 {PCI_VENDOR_ID_TI, PCI_ANY_ID, PCI_ANY_ID,
281 QUIRK_RESET_PACKET},
282
283 {PCI_VENDOR_ID_VIA, PCI_ANY_ID, PCI_ANY_ID,
284 QUIRK_CYCLE_TIMER | QUIRK_NO_MSI},
268}; 285};
269 286
270/* This overrides anything that was found in ohci_quirks[]. */ 287/* This overrides anything that was found in ohci_quirks[]. */
@@ -577,17 +594,11 @@ static int ohci_update_phy_reg(struct fw_card *card, int addr,
577 return ret; 594 return ret;
578} 595}
579 596
580static int ar_context_add_page(struct ar_context *ctx) 597static void ar_context_link_page(struct ar_context *ctx,
598 struct ar_buffer *ab, dma_addr_t ab_bus)
581{ 599{
582 struct device *dev = ctx->ohci->card.device;
583 struct ar_buffer *ab;
584 dma_addr_t uninitialized_var(ab_bus);
585 size_t offset; 600 size_t offset;
586 601
587 ab = dma_alloc_coherent(dev, PAGE_SIZE, &ab_bus, GFP_ATOMIC);
588 if (ab == NULL)
589 return -ENOMEM;
590
591 ab->next = NULL; 602 ab->next = NULL;
592 memset(&ab->descriptor, 0, sizeof(ab->descriptor)); 603 memset(&ab->descriptor, 0, sizeof(ab->descriptor));
593 ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE | 604 ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
@@ -606,6 +617,19 @@ static int ar_context_add_page(struct ar_context *ctx)
606 617
607 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE); 618 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE);
608 flush_writes(ctx->ohci); 619 flush_writes(ctx->ohci);
620}
621
622static int ar_context_add_page(struct ar_context *ctx)
623{
624 struct device *dev = ctx->ohci->card.device;
625 struct ar_buffer *ab;
626 dma_addr_t uninitialized_var(ab_bus);
627
628 ab = dma_alloc_coherent(dev, PAGE_SIZE, &ab_bus, GFP_ATOMIC);
629 if (ab == NULL)
630 return -ENOMEM;
631
632 ar_context_link_page(ctx, ab, ab_bus);
609 633
610 return 0; 634 return 0;
611} 635}
@@ -730,16 +754,17 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
730static void ar_context_tasklet(unsigned long data) 754static void ar_context_tasklet(unsigned long data)
731{ 755{
732 struct ar_context *ctx = (struct ar_context *)data; 756 struct ar_context *ctx = (struct ar_context *)data;
733 struct fw_ohci *ohci = ctx->ohci;
734 struct ar_buffer *ab; 757 struct ar_buffer *ab;
735 struct descriptor *d; 758 struct descriptor *d;
736 void *buffer, *end; 759 void *buffer, *end;
760 __le16 res_count;
737 761
738 ab = ctx->current_buffer; 762 ab = ctx->current_buffer;
739 d = &ab->descriptor; 763 d = &ab->descriptor;
740 764
741 if (d->res_count == 0) { 765 res_count = ACCESS_ONCE(d->res_count);
742 size_t size, rest, offset; 766 if (res_count == 0) {
767 size_t size, size2, rest, pktsize, size3, offset;
743 dma_addr_t start_bus; 768 dma_addr_t start_bus;
744 void *start; 769 void *start;
745 770
@@ -750,29 +775,63 @@ static void ar_context_tasklet(unsigned long data)
750 */ 775 */
751 776
752 offset = offsetof(struct ar_buffer, data); 777 offset = offsetof(struct ar_buffer, data);
753 start = buffer = ab; 778 start = ab;
754 start_bus = le32_to_cpu(ab->descriptor.data_address) - offset; 779 start_bus = le32_to_cpu(ab->descriptor.data_address) - offset;
780 buffer = ab->data;
755 781
756 ab = ab->next; 782 ab = ab->next;
757 d = &ab->descriptor; 783 d = &ab->descriptor;
758 size = buffer + PAGE_SIZE - ctx->pointer; 784 size = start + PAGE_SIZE - ctx->pointer;
785 /* valid buffer data in the next page */
759 rest = le16_to_cpu(d->req_count) - le16_to_cpu(d->res_count); 786 rest = le16_to_cpu(d->req_count) - le16_to_cpu(d->res_count);
787 /* what actually fits in this page */
788 size2 = min(rest, (size_t)PAGE_SIZE - offset - size);
760 memmove(buffer, ctx->pointer, size); 789 memmove(buffer, ctx->pointer, size);
761 memcpy(buffer + size, ab->data, rest); 790 memcpy(buffer + size, ab->data, size2);
762 ctx->current_buffer = ab; 791
763 ctx->pointer = (void *) ab->data + rest; 792 while (size > 0) {
764 end = buffer + size + rest; 793 void *next = handle_ar_packet(ctx, buffer);
794 pktsize = next - buffer;
795 if (pktsize >= size) {
796 /*
797 * We have handled all the data that was
798 * originally in this page, so we can now
799 * continue in the next page.
800 */
801 buffer = next;
802 break;
803 }
804 /* move the next packet to the start of the buffer */
805 memmove(buffer, next, size + size2 - pktsize);
806 size -= pktsize;
807 /* fill up this page again */
808 size3 = min(rest - size2,
809 (size_t)PAGE_SIZE - offset - size - size2);
810 memcpy(buffer + size + size2,
811 (void *) ab->data + size2, size3);
812 size2 += size3;
813 }
765 814
766 while (buffer < end) 815 if (rest > 0) {
767 buffer = handle_ar_packet(ctx, buffer); 816 /* handle the packets that are fully in the next page */
817 buffer = (void *) ab->data +
818 (buffer - (start + offset + size));
819 end = (void *) ab->data + rest;
768 820
769 dma_free_coherent(ohci->card.device, PAGE_SIZE, 821 while (buffer < end)
770 start, start_bus); 822 buffer = handle_ar_packet(ctx, buffer);
771 ar_context_add_page(ctx); 823
824 ctx->current_buffer = ab;
825 ctx->pointer = end;
826
827 ar_context_link_page(ctx, start, start_bus);
828 } else {
829 ctx->pointer = start + PAGE_SIZE;
830 }
772 } else { 831 } else {
773 buffer = ctx->pointer; 832 buffer = ctx->pointer;
774 ctx->pointer = end = 833 ctx->pointer = end =
775 (void *) ab + PAGE_SIZE - le16_to_cpu(d->res_count); 834 (void *) ab + PAGE_SIZE - le16_to_cpu(res_count);
776 835
777 while (buffer < end) 836 while (buffer < end)
778 buffer = handle_ar_packet(ctx, buffer); 837 buffer = handle_ar_packet(ctx, buffer);
@@ -2885,9 +2944,11 @@ static int __devinit pci_probe(struct pci_dev *dev,
2885 } 2944 }
2886 2945
2887 for (i = 0; i < ARRAY_SIZE(ohci_quirks); i++) 2946 for (i = 0; i < ARRAY_SIZE(ohci_quirks); i++)
2888 if (ohci_quirks[i].vendor == dev->vendor && 2947 if ((ohci_quirks[i].vendor == dev->vendor) &&
2889 (ohci_quirks[i].device == dev->device || 2948 (ohci_quirks[i].device == (unsigned short)PCI_ANY_ID ||
2890 ohci_quirks[i].device == (unsigned short)PCI_ANY_ID)) { 2949 ohci_quirks[i].device == dev->device) &&
2950 (ohci_quirks[i].revision == (unsigned short)PCI_ANY_ID ||
2951 ohci_quirks[i].revision >= dev->revision)) {
2891 ohci->quirks = ohci_quirks[i].flags; 2952 ohci->quirks = ohci_quirks[i].flags;
2892 break; 2953 break;
2893 } 2954 }
diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c
index bfae4b309791..afa576a75a8e 100644
--- a/drivers/firewire/sbp2.c
+++ b/drivers/firewire/sbp2.c
@@ -1468,7 +1468,7 @@ static int sbp2_map_scatterlist(struct sbp2_command_orb *orb,
1468 1468
1469/* SCSI stack integration */ 1469/* SCSI stack integration */
1470 1470
1471static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) 1471static int sbp2_scsi_queuecommand_lck(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1472{ 1472{
1473 struct sbp2_logical_unit *lu = cmd->device->hostdata; 1473 struct sbp2_logical_unit *lu = cmd->device->hostdata;
1474 struct fw_device *device = target_device(lu->tgt); 1474 struct fw_device *device = target_device(lu->tgt);
@@ -1534,6 +1534,8 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1534 return retval; 1534 return retval;
1535} 1535}
1536 1536
1537static DEF_SCSI_QCMD(sbp2_scsi_queuecommand)
1538
1537static int sbp2_scsi_slave_alloc(struct scsi_device *sdev) 1539static int sbp2_scsi_slave_alloc(struct scsi_device *sdev)
1538{ 1540{
1539 struct sbp2_logical_unit *lu = sdev->hostdata; 1541 struct sbp2_logical_unit *lu = sdev->hostdata;
diff --git a/drivers/gpio/cs5535-gpio.c b/drivers/gpio/cs5535-gpio.c
index e23c06893d19..599f6c9e0fbf 100644
--- a/drivers/gpio/cs5535-gpio.c
+++ b/drivers/gpio/cs5535-gpio.c
@@ -56,6 +56,18 @@ static struct cs5535_gpio_chip {
56 * registers, see include/linux/cs5535.h. 56 * registers, see include/linux/cs5535.h.
57 */ 57 */
58 58
59static void errata_outl(u32 val, unsigned long addr)
60{
61 /*
62 * According to the CS5536 errata (#36), after suspend
63 * a write to the high bank GPIO register will clear all
64 * non-selected bits; the recommended workaround is a
65 * read-modify-write operation.
66 */
67 val |= inl(addr);
68 outl(val, addr);
69}
70
59static void __cs5535_gpio_set(struct cs5535_gpio_chip *chip, unsigned offset, 71static void __cs5535_gpio_set(struct cs5535_gpio_chip *chip, unsigned offset,
60 unsigned int reg) 72 unsigned int reg)
61{ 73{
@@ -64,7 +76,7 @@ static void __cs5535_gpio_set(struct cs5535_gpio_chip *chip, unsigned offset,
64 outl(1 << offset, chip->base + reg); 76 outl(1 << offset, chip->base + reg);
65 else 77 else
66 /* high bank register */ 78 /* high bank register */
67 outl(1 << (offset - 16), chip->base + 0x80 + reg); 79 errata_outl(1 << (offset - 16), chip->base + 0x80 + reg);
68} 80}
69 81
70void cs5535_gpio_set(unsigned offset, unsigned int reg) 82void cs5535_gpio_set(unsigned offset, unsigned int reg)
@@ -86,7 +98,7 @@ static void __cs5535_gpio_clear(struct cs5535_gpio_chip *chip, unsigned offset,
86 outl(1 << (offset + 16), chip->base + reg); 98 outl(1 << (offset + 16), chip->base + reg);
87 else 99 else
88 /* high bank register */ 100 /* high bank register */
89 outl(1 << offset, chip->base + 0x80 + reg); 101 errata_outl(1 << offset, chip->base + 0x80 + reg);
90} 102}
91 103
92void cs5535_gpio_clear(unsigned offset, unsigned int reg) 104void cs5535_gpio_clear(unsigned offset, unsigned int reg)
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 6985cb1da72c..2baa6708e44c 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -156,12 +156,12 @@ static struct drm_conn_prop_enum_list drm_connector_enum_list[] =
156 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO", 0 }, 156 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO", 0 },
157 { DRM_MODE_CONNECTOR_LVDS, "LVDS", 0 }, 157 { DRM_MODE_CONNECTOR_LVDS, "LVDS", 0 },
158 { DRM_MODE_CONNECTOR_Component, "Component", 0 }, 158 { DRM_MODE_CONNECTOR_Component, "Component", 0 },
159 { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN", 0 }, 159 { DRM_MODE_CONNECTOR_9PinDIN, "DIN", 0 },
160 { DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort", 0 }, 160 { DRM_MODE_CONNECTOR_DisplayPort, "DP", 0 },
161 { DRM_MODE_CONNECTOR_HDMIA, "HDMI Type A", 0 }, 161 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A", 0 },
162 { DRM_MODE_CONNECTOR_HDMIB, "HDMI Type B", 0 }, 162 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B", 0 },
163 { DRM_MODE_CONNECTOR_TV, "TV", 0 }, 163 { DRM_MODE_CONNECTOR_TV, "TV", 0 },
164 { DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort", 0 }, 164 { DRM_MODE_CONNECTOR_eDP, "eDP", 0 },
165}; 165};
166 166
167static struct drm_prop_enum_list drm_encoder_enum_list[] = 167static struct drm_prop_enum_list drm_encoder_enum_list[] =
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index dcbeb98f195a..bede10a03407 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -241,7 +241,7 @@ void drm_helper_disable_unused_functions(struct drm_device *dev)
241 } 241 }
242 242
243 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 243 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
244 if (!drm_helper_encoder_in_use(encoder)) { 244 if (encoder->crtc && !drm_helper_encoder_in_use(encoder)) {
245 drm_encoder_disable(encoder); 245 drm_encoder_disable(encoder);
246 /* disconnector encoder from any connector */ 246 /* disconnector encoder from any connector */
247 encoder->crtc = NULL; 247 encoder->crtc = NULL;
@@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
276 struct drm_crtc *tmp; 276 struct drm_crtc *tmp;
277 int crtc_mask = 1; 277 int crtc_mask = 1;
278 278
279 WARN(!crtc, "checking null crtc?"); 279 WARN(!crtc, "checking null crtc?\n");
280 280
281 dev = crtc->dev; 281 dev = crtc->dev;
282 282
@@ -471,6 +471,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
471 int count = 0, ro, fail = 0; 471 int count = 0, ro, fail = 0;
472 struct drm_crtc_helper_funcs *crtc_funcs; 472 struct drm_crtc_helper_funcs *crtc_funcs;
473 int ret = 0; 473 int ret = 0;
474 int i;
474 475
475 DRM_DEBUG_KMS("\n"); 476 DRM_DEBUG_KMS("\n");
476 477
@@ -666,6 +667,12 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
666 if (ret != 0) 667 if (ret != 0)
667 goto fail; 668 goto fail;
668 } 669 }
670 DRM_DEBUG_KMS("Setting connector DPMS state to on\n");
671 for (i = 0; i < set->num_connectors; i++) {
672 DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set->connectors[i]->base.id,
673 drm_get_connector_name(set->connectors[i]));
674 set->connectors[i]->dpms = DRM_MODE_DPMS_ON;
675 }
669 676
670 kfree(save_connectors); 677 kfree(save_connectors);
671 kfree(save_encoders); 678 kfree(save_encoders);
@@ -841,7 +848,7 @@ static void output_poll_execute(struct work_struct *work)
841 struct delayed_work *delayed_work = to_delayed_work(work); 848 struct delayed_work *delayed_work = to_delayed_work(work);
842 struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_work); 849 struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_work);
843 struct drm_connector *connector; 850 struct drm_connector *connector;
844 enum drm_connector_status old_status, status; 851 enum drm_connector_status old_status;
845 bool repoll = false, changed = false; 852 bool repoll = false, changed = false;
846 853
847 if (!drm_kms_helper_poll) 854 if (!drm_kms_helper_poll)
@@ -866,8 +873,9 @@ static void output_poll_execute(struct work_struct *work)
866 !(connector->polled & DRM_CONNECTOR_POLL_HPD)) 873 !(connector->polled & DRM_CONNECTOR_POLL_HPD))
867 continue; 874 continue;
868 875
869 status = connector->funcs->detect(connector, false); 876 connector->status = connector->funcs->detect(connector, false);
870 if (old_status != status) 877 DRM_DEBUG_KMS("connector status updated to %d\n", connector->status);
878 if (old_status != connector->status)
871 changed = true; 879 changed = true;
872 } 880 }
873 881
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index c1a26217a530..a245d17165ae 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -240,7 +240,7 @@ drm_do_probe_ddc_edid(struct i2c_adapter *adapter, unsigned char *buf,
240 .addr = DDC_ADDR, 240 .addr = DDC_ADDR,
241 .flags = I2C_M_RD, 241 .flags = I2C_M_RD,
242 .len = len, 242 .len = len,
243 .buf = buf + start, 243 .buf = buf,
244 } 244 }
245 }; 245 };
246 246
@@ -253,7 +253,7 @@ drm_do_probe_ddc_edid(struct i2c_adapter *adapter, unsigned char *buf,
253static u8 * 253static u8 *
254drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) 254drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
255{ 255{
256 int i, j = 0; 256 int i, j = 0, valid_extensions = 0;
257 u8 *block, *new; 257 u8 *block, *new;
258 258
259 if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL) 259 if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
@@ -280,14 +280,28 @@ drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
280 280
281 for (j = 1; j <= block[0x7e]; j++) { 281 for (j = 1; j <= block[0x7e]; j++) {
282 for (i = 0; i < 4; i++) { 282 for (i = 0; i < 4; i++) {
283 if (drm_do_probe_ddc_edid(adapter, block, j, 283 if (drm_do_probe_ddc_edid(adapter,
284 EDID_LENGTH)) 284 block + (valid_extensions + 1) * EDID_LENGTH,
285 j, EDID_LENGTH))
285 goto out; 286 goto out;
286 if (drm_edid_block_valid(block + j * EDID_LENGTH)) 287 if (drm_edid_block_valid(block + (valid_extensions + 1) * EDID_LENGTH)) {
288 valid_extensions++;
287 break; 289 break;
290 }
288 } 291 }
289 if (i == 4) 292 if (i == 4)
290 goto carp; 293 dev_warn(connector->dev->dev,
294 "%s: Ignoring invalid EDID block %d.\n",
295 drm_get_connector_name(connector), j);
296 }
297
298 if (valid_extensions != block[0x7e]) {
299 block[EDID_LENGTH-1] += block[0x7e] - valid_extensions;
300 block[0x7e] = valid_extensions;
301 new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
302 if (!new)
303 goto out;
304 block = new;
291 } 305 }
292 306
293 return block; 307 return block;
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index b744dad5c237..a39794bac04b 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -37,7 +37,6 @@
37#include "drmP.h" 37#include "drmP.h"
38#include <linux/poll.h> 38#include <linux/poll.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/smp_lock.h>
41 40
42/* from BKL pushdown: note that nothing else serializes idr_find() */ 41/* from BKL pushdown: note that nothing else serializes idr_find() */
43DEFINE_MUTEX(drm_global_mutex); 42DEFINE_MUTEX(drm_global_mutex);
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 9d3a5030b6e1..16d5155edad1 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -585,10 +585,13 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
585 struct timeval now; 585 struct timeval now;
586 unsigned long flags; 586 unsigned long flags;
587 unsigned int seq; 587 unsigned int seq;
588 int ret;
588 589
589 e = kzalloc(sizeof *e, GFP_KERNEL); 590 e = kzalloc(sizeof *e, GFP_KERNEL);
590 if (e == NULL) 591 if (e == NULL) {
591 return -ENOMEM; 592 ret = -ENOMEM;
593 goto err_put;
594 }
592 595
593 e->pipe = pipe; 596 e->pipe = pipe;
594 e->base.pid = current->pid; 597 e->base.pid = current->pid;
@@ -603,9 +606,8 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
603 spin_lock_irqsave(&dev->event_lock, flags); 606 spin_lock_irqsave(&dev->event_lock, flags);
604 607
605 if (file_priv->event_space < sizeof e->event) { 608 if (file_priv->event_space < sizeof e->event) {
606 spin_unlock_irqrestore(&dev->event_lock, flags); 609 ret = -EBUSY;
607 kfree(e); 610 goto err_unlock;
608 return -ENOMEM;
609 } 611 }
610 612
611 file_priv->event_space -= sizeof e->event; 613 file_priv->event_space -= sizeof e->event;
@@ -626,7 +628,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
626 if ((seq - vblwait->request.sequence) <= (1 << 23)) { 628 if ((seq - vblwait->request.sequence) <= (1 << 23)) {
627 e->event.tv_sec = now.tv_sec; 629 e->event.tv_sec = now.tv_sec;
628 e->event.tv_usec = now.tv_usec; 630 e->event.tv_usec = now.tv_usec;
629 drm_vblank_put(dev, e->pipe); 631 drm_vblank_put(dev, pipe);
630 list_add_tail(&e->base.link, &e->base.file_priv->event_list); 632 list_add_tail(&e->base.link, &e->base.file_priv->event_list);
631 wake_up_interruptible(&e->base.file_priv->event_wait); 633 wake_up_interruptible(&e->base.file_priv->event_wait);
632 trace_drm_vblank_event_delivered(current->pid, pipe, 634 trace_drm_vblank_event_delivered(current->pid, pipe,
@@ -638,6 +640,13 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
638 spin_unlock_irqrestore(&dev->event_lock, flags); 640 spin_unlock_irqrestore(&dev->event_lock, flags);
639 641
640 return 0; 642 return 0;
643
644err_unlock:
645 spin_unlock_irqrestore(&dev->event_lock, flags);
646 kfree(e);
647err_put:
648 drm_vblank_put(dev, pipe);
649 return ret;
641} 650}
642 651
643/** 652/**
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 7a26f4dd21ae..e6800819bca8 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -767,6 +767,9 @@ static int i915_getparam(struct drm_device *dev, void *data,
767 case I915_PARAM_HAS_BLT: 767 case I915_PARAM_HAS_BLT:
768 value = HAS_BLT(dev); 768 value = HAS_BLT(dev);
769 break; 769 break;
770 case I915_PARAM_HAS_COHERENT_RINGS:
771 value = 1;
772 break;
770 default: 773 default:
771 DRM_DEBUG_DRIVER("Unknown parameter %d\n", 774 DRM_DEBUG_DRIVER("Unknown parameter %d\n",
772 param->param); 775 param->param);
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 3467dd420760..f737960712e6 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -44,7 +44,7 @@ unsigned int i915_fbpercrtc = 0;
44module_param_named(fbpercrtc, i915_fbpercrtc, int, 0400); 44module_param_named(fbpercrtc, i915_fbpercrtc, int, 0400);
45 45
46unsigned int i915_powersave = 1; 46unsigned int i915_powersave = 1;
47module_param_named(powersave, i915_powersave, int, 0400); 47module_param_named(powersave, i915_powersave, int, 0600);
48 48
49unsigned int i915_lvds_downclock = 0; 49unsigned int i915_lvds_downclock = 0;
50module_param_named(lvds_downclock, i915_lvds_downclock, int, 0400); 50module_param_named(lvds_downclock, i915_lvds_downclock, int, 0400);
@@ -150,7 +150,8 @@ static const struct intel_device_info intel_ironlake_d_info = {
150 150
151static const struct intel_device_info intel_ironlake_m_info = { 151static const struct intel_device_info intel_ironlake_m_info = {
152 .gen = 5, .is_mobile = 1, 152 .gen = 5, .is_mobile = 1,
153 .need_gfx_hws = 1, .has_fbc = 1, .has_rc6 = 1, .has_hotplug = 1, 153 .need_gfx_hws = 1, .has_rc6 = 1, .has_hotplug = 1,
154 .has_fbc = 0, /* disabled due to buggy hardware */
154 .has_bsd_ring = 1, 155 .has_bsd_ring = 1,
155}; 156};
156 157
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 2c2c19b6285e..409826da3099 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1045,6 +1045,8 @@ void i915_gem_clflush_object(struct drm_gem_object *obj);
1045int i915_gem_object_set_domain(struct drm_gem_object *obj, 1045int i915_gem_object_set_domain(struct drm_gem_object *obj,
1046 uint32_t read_domains, 1046 uint32_t read_domains,
1047 uint32_t write_domain); 1047 uint32_t write_domain);
1048int i915_gem_object_flush_gpu(struct drm_i915_gem_object *obj,
1049 bool interruptible);
1048int i915_gem_init_ringbuffer(struct drm_device *dev); 1050int i915_gem_init_ringbuffer(struct drm_device *dev);
1049void i915_gem_cleanup_ringbuffer(struct drm_device *dev); 1051void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
1050int i915_gem_do_init(struct drm_device *dev, unsigned long start, 1052int i915_gem_do_init(struct drm_device *dev, unsigned long start,
@@ -1321,6 +1323,7 @@ static inline void i915_write(struct drm_i915_private *dev_priv, u32 reg,
1321 1323
1322#define INTEL_PCH_TYPE(dev) (((struct drm_i915_private *)(dev)->dev_private)->pch_type) 1324#define INTEL_PCH_TYPE(dev) (((struct drm_i915_private *)(dev)->dev_private)->pch_type)
1323#define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT) 1325#define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
1326#define HAS_PCH_IBX(dev) (INTEL_PCH_TYPE(dev) == PCH_IBX)
1324 1327
1325#define PRIMARY_RINGBUFFER_SIZE (128*1024) 1328#define PRIMARY_RINGBUFFER_SIZE (128*1024)
1326 1329
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 8eb8453208b5..275ec6ed43ae 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -38,8 +38,7 @@
38 38
39static uint32_t i915_gem_get_gtt_alignment(struct drm_gem_object *obj); 39static uint32_t i915_gem_get_gtt_alignment(struct drm_gem_object *obj);
40 40
41static int i915_gem_object_flush_gpu_write_domain(struct drm_gem_object *obj, 41static int i915_gem_object_flush_gpu_write_domain(struct drm_gem_object *obj);
42 bool pipelined);
43static void i915_gem_object_flush_gtt_write_domain(struct drm_gem_object *obj); 42static void i915_gem_object_flush_gtt_write_domain(struct drm_gem_object *obj);
44static void i915_gem_object_flush_cpu_write_domain(struct drm_gem_object *obj); 43static void i915_gem_object_flush_cpu_write_domain(struct drm_gem_object *obj);
45static int i915_gem_object_set_to_cpu_domain(struct drm_gem_object *obj, 44static int i915_gem_object_set_to_cpu_domain(struct drm_gem_object *obj,
@@ -547,6 +546,19 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
547 struct drm_i915_gem_object *obj_priv; 546 struct drm_i915_gem_object *obj_priv;
548 int ret = 0; 547 int ret = 0;
549 548
549 if (args->size == 0)
550 return 0;
551
552 if (!access_ok(VERIFY_WRITE,
553 (char __user *)(uintptr_t)args->data_ptr,
554 args->size))
555 return -EFAULT;
556
557 ret = fault_in_pages_writeable((char __user *)(uintptr_t)args->data_ptr,
558 args->size);
559 if (ret)
560 return -EFAULT;
561
550 ret = i915_mutex_lock_interruptible(dev); 562 ret = i915_mutex_lock_interruptible(dev);
551 if (ret) 563 if (ret)
552 return ret; 564 return ret;
@@ -564,23 +576,6 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
564 goto out; 576 goto out;
565 } 577 }
566 578
567 if (args->size == 0)
568 goto out;
569
570 if (!access_ok(VERIFY_WRITE,
571 (char __user *)(uintptr_t)args->data_ptr,
572 args->size)) {
573 ret = -EFAULT;
574 goto out;
575 }
576
577 ret = fault_in_pages_writeable((char __user *)(uintptr_t)args->data_ptr,
578 args->size);
579 if (ret) {
580 ret = -EFAULT;
581 goto out;
582 }
583
584 ret = i915_gem_object_get_pages_or_evict(obj); 579 ret = i915_gem_object_get_pages_or_evict(obj);
585 if (ret) 580 if (ret)
586 goto out; 581 goto out;
@@ -981,7 +976,20 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
981 struct drm_i915_gem_pwrite *args = data; 976 struct drm_i915_gem_pwrite *args = data;
982 struct drm_gem_object *obj; 977 struct drm_gem_object *obj;
983 struct drm_i915_gem_object *obj_priv; 978 struct drm_i915_gem_object *obj_priv;
984 int ret = 0; 979 int ret;
980
981 if (args->size == 0)
982 return 0;
983
984 if (!access_ok(VERIFY_READ,
985 (char __user *)(uintptr_t)args->data_ptr,
986 args->size))
987 return -EFAULT;
988
989 ret = fault_in_pages_readable((char __user *)(uintptr_t)args->data_ptr,
990 args->size);
991 if (ret)
992 return -EFAULT;
985 993
986 ret = i915_mutex_lock_interruptible(dev); 994 ret = i915_mutex_lock_interruptible(dev);
987 if (ret) 995 if (ret)
@@ -994,30 +1002,12 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
994 } 1002 }
995 obj_priv = to_intel_bo(obj); 1003 obj_priv = to_intel_bo(obj);
996 1004
997
998 /* Bounds check destination. */ 1005 /* Bounds check destination. */
999 if (args->offset > obj->size || args->size > obj->size - args->offset) { 1006 if (args->offset > obj->size || args->size > obj->size - args->offset) {
1000 ret = -EINVAL; 1007 ret = -EINVAL;
1001 goto out; 1008 goto out;
1002 } 1009 }
1003 1010
1004 if (args->size == 0)
1005 goto out;
1006
1007 if (!access_ok(VERIFY_READ,
1008 (char __user *)(uintptr_t)args->data_ptr,
1009 args->size)) {
1010 ret = -EFAULT;
1011 goto out;
1012 }
1013
1014 ret = fault_in_pages_readable((char __user *)(uintptr_t)args->data_ptr,
1015 args->size);
1016 if (ret) {
1017 ret = -EFAULT;
1018 goto out;
1019 }
1020
1021 /* We can only do the GTT pwrite on untiled buffers, as otherwise 1011 /* We can only do the GTT pwrite on untiled buffers, as otherwise
1022 * it would end up going through the fenced access, and we'll get 1012 * it would end up going through the fenced access, and we'll get
1023 * different detiling behavior between reading and writing. 1013 * different detiling behavior between reading and writing.
@@ -2172,7 +2162,7 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
2172static int i915_ring_idle(struct drm_device *dev, 2162static int i915_ring_idle(struct drm_device *dev,
2173 struct intel_ring_buffer *ring) 2163 struct intel_ring_buffer *ring)
2174{ 2164{
2175 if (list_empty(&ring->gpu_write_list)) 2165 if (list_empty(&ring->gpu_write_list) && list_empty(&ring->active_list))
2176 return 0; 2166 return 0;
2177 2167
2178 i915_gem_flush_ring(dev, NULL, ring, 2168 i915_gem_flush_ring(dev, NULL, ring,
@@ -2190,9 +2180,7 @@ i915_gpu_idle(struct drm_device *dev)
2190 int ret; 2180 int ret;
2191 2181
2192 lists_empty = (list_empty(&dev_priv->mm.flushing_list) && 2182 lists_empty = (list_empty(&dev_priv->mm.flushing_list) &&
2193 list_empty(&dev_priv->render_ring.active_list) && 2183 list_empty(&dev_priv->mm.active_list));
2194 list_empty(&dev_priv->bsd_ring.active_list) &&
2195 list_empty(&dev_priv->blt_ring.active_list));
2196 if (lists_empty) 2184 if (lists_empty)
2197 return 0; 2185 return 0;
2198 2186
@@ -2605,7 +2593,7 @@ i915_gem_object_put_fence_reg(struct drm_gem_object *obj,
2605 if (reg->gpu) { 2593 if (reg->gpu) {
2606 int ret; 2594 int ret;
2607 2595
2608 ret = i915_gem_object_flush_gpu_write_domain(obj, true); 2596 ret = i915_gem_object_flush_gpu_write_domain(obj);
2609 if (ret) 2597 if (ret)
2610 return ret; 2598 return ret;
2611 2599
@@ -2753,8 +2741,7 @@ i915_gem_clflush_object(struct drm_gem_object *obj)
2753 2741
2754/** Flushes any GPU write domain for the object if it's dirty. */ 2742/** Flushes any GPU write domain for the object if it's dirty. */
2755static int 2743static int
2756i915_gem_object_flush_gpu_write_domain(struct drm_gem_object *obj, 2744i915_gem_object_flush_gpu_write_domain(struct drm_gem_object *obj)
2757 bool pipelined)
2758{ 2745{
2759 struct drm_device *dev = obj->dev; 2746 struct drm_device *dev = obj->dev;
2760 uint32_t old_write_domain; 2747 uint32_t old_write_domain;
@@ -2773,10 +2760,7 @@ i915_gem_object_flush_gpu_write_domain(struct drm_gem_object *obj,
2773 obj->read_domains, 2760 obj->read_domains,
2774 old_write_domain); 2761 old_write_domain);
2775 2762
2776 if (pipelined) 2763 return 0;
2777 return 0;
2778
2779 return i915_gem_object_wait_rendering(obj, true);
2780} 2764}
2781 2765
2782/** Flushes the GTT write domain for the object if it's dirty. */ 2766/** Flushes the GTT write domain for the object if it's dirty. */
@@ -2837,18 +2821,15 @@ i915_gem_object_set_to_gtt_domain(struct drm_gem_object *obj, int write)
2837 if (obj_priv->gtt_space == NULL) 2821 if (obj_priv->gtt_space == NULL)
2838 return -EINVAL; 2822 return -EINVAL;
2839 2823
2840 ret = i915_gem_object_flush_gpu_write_domain(obj, false); 2824 ret = i915_gem_object_flush_gpu_write_domain(obj);
2841 if (ret != 0) 2825 if (ret != 0)
2842 return ret; 2826 return ret;
2827 ret = i915_gem_object_wait_rendering(obj, true);
2828 if (ret)
2829 return ret;
2843 2830
2844 i915_gem_object_flush_cpu_write_domain(obj); 2831 i915_gem_object_flush_cpu_write_domain(obj);
2845 2832
2846 if (write) {
2847 ret = i915_gem_object_wait_rendering(obj, true);
2848 if (ret)
2849 return ret;
2850 }
2851
2852 old_write_domain = obj->write_domain; 2833 old_write_domain = obj->write_domain;
2853 old_read_domains = obj->read_domains; 2834 old_read_domains = obj->read_domains;
2854 2835
@@ -2886,7 +2867,7 @@ i915_gem_object_set_to_display_plane(struct drm_gem_object *obj,
2886 if (obj_priv->gtt_space == NULL) 2867 if (obj_priv->gtt_space == NULL)
2887 return -EINVAL; 2868 return -EINVAL;
2888 2869
2889 ret = i915_gem_object_flush_gpu_write_domain(obj, true); 2870 ret = i915_gem_object_flush_gpu_write_domain(obj);
2890 if (ret) 2871 if (ret)
2891 return ret; 2872 return ret;
2892 2873
@@ -2909,6 +2890,20 @@ i915_gem_object_set_to_display_plane(struct drm_gem_object *obj,
2909 return 0; 2890 return 0;
2910} 2891}
2911 2892
2893int
2894i915_gem_object_flush_gpu(struct drm_i915_gem_object *obj,
2895 bool interruptible)
2896{
2897 if (!obj->active)
2898 return 0;
2899
2900 if (obj->base.write_domain & I915_GEM_GPU_DOMAINS)
2901 i915_gem_flush_ring(obj->base.dev, NULL, obj->ring,
2902 0, obj->base.write_domain);
2903
2904 return i915_gem_object_wait_rendering(&obj->base, interruptible);
2905}
2906
2912/** 2907/**
2913 * Moves a single object to the CPU read, and possibly write domain. 2908 * Moves a single object to the CPU read, and possibly write domain.
2914 * 2909 *
@@ -2921,9 +2916,12 @@ i915_gem_object_set_to_cpu_domain(struct drm_gem_object *obj, int write)
2921 uint32_t old_write_domain, old_read_domains; 2916 uint32_t old_write_domain, old_read_domains;
2922 int ret; 2917 int ret;
2923 2918
2924 ret = i915_gem_object_flush_gpu_write_domain(obj, false); 2919 ret = i915_gem_object_flush_gpu_write_domain(obj);
2925 if (ret != 0) 2920 if (ret != 0)
2926 return ret; 2921 return ret;
2922 ret = i915_gem_object_wait_rendering(obj, true);
2923 if (ret)
2924 return ret;
2927 2925
2928 i915_gem_object_flush_gtt_write_domain(obj); 2926 i915_gem_object_flush_gtt_write_domain(obj);
2929 2927
@@ -2932,12 +2930,6 @@ i915_gem_object_set_to_cpu_domain(struct drm_gem_object *obj, int write)
2932 */ 2930 */
2933 i915_gem_object_set_to_full_cpu_read_domain(obj); 2931 i915_gem_object_set_to_full_cpu_read_domain(obj);
2934 2932
2935 if (write) {
2936 ret = i915_gem_object_wait_rendering(obj, true);
2937 if (ret)
2938 return ret;
2939 }
2940
2941 old_write_domain = obj->write_domain; 2933 old_write_domain = obj->write_domain;
2942 old_read_domains = obj->read_domains; 2934 old_read_domains = obj->read_domains;
2943 2935
@@ -3108,7 +3100,8 @@ i915_gem_object_set_to_gpu_domain(struct drm_gem_object *obj,
3108 * write domain 3100 * write domain
3109 */ 3101 */
3110 if (obj->write_domain && 3102 if (obj->write_domain &&
3111 obj->write_domain != obj->pending_read_domains) { 3103 (obj->write_domain != obj->pending_read_domains ||
3104 obj_priv->ring != ring)) {
3112 flush_domains |= obj->write_domain; 3105 flush_domains |= obj->write_domain;
3113 invalidate_domains |= 3106 invalidate_domains |=
3114 obj->pending_read_domains & ~obj->write_domain; 3107 obj->pending_read_domains & ~obj->write_domain;
@@ -3201,9 +3194,13 @@ i915_gem_object_set_cpu_read_domain_range(struct drm_gem_object *obj,
3201 if (offset == 0 && size == obj->size) 3194 if (offset == 0 && size == obj->size)
3202 return i915_gem_object_set_to_cpu_domain(obj, 0); 3195 return i915_gem_object_set_to_cpu_domain(obj, 0);
3203 3196
3204 ret = i915_gem_object_flush_gpu_write_domain(obj, false); 3197 ret = i915_gem_object_flush_gpu_write_domain(obj);
3205 if (ret != 0) 3198 if (ret != 0)
3206 return ret; 3199 return ret;
3200 ret = i915_gem_object_wait_rendering(obj, true);
3201 if (ret)
3202 return ret;
3203
3207 i915_gem_object_flush_gtt_write_domain(obj); 3204 i915_gem_object_flush_gtt_write_domain(obj);
3208 3205
3209 /* If we're already fully in the CPU read domain, we're done. */ 3206 /* If we're already fully in the CPU read domain, we're done. */
@@ -3250,192 +3247,230 @@ i915_gem_object_set_cpu_read_domain_range(struct drm_gem_object *obj,
3250 return 0; 3247 return 0;
3251} 3248}
3252 3249
3253/**
3254 * Pin an object to the GTT and evaluate the relocations landing in it.
3255 */
3256static int 3250static int
3257i915_gem_execbuffer_relocate(struct drm_i915_gem_object *obj, 3251i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
3258 struct drm_file *file_priv, 3252 struct drm_file *file_priv,
3259 struct drm_i915_gem_exec_object2 *entry) 3253 struct drm_i915_gem_exec_object2 *entry,
3254 struct drm_i915_gem_relocation_entry *reloc)
3260{ 3255{
3261 struct drm_device *dev = obj->base.dev; 3256 struct drm_device *dev = obj->base.dev;
3262 drm_i915_private_t *dev_priv = dev->dev_private; 3257 struct drm_gem_object *target_obj;
3263 struct drm_i915_gem_relocation_entry __user *user_relocs; 3258 uint32_t target_offset;
3264 struct drm_gem_object *target_obj = NULL; 3259 int ret = -EINVAL;
3265 uint32_t target_handle = 0;
3266 int i, ret = 0;
3267 3260
3268 user_relocs = (void __user *)(uintptr_t)entry->relocs_ptr; 3261 target_obj = drm_gem_object_lookup(dev, file_priv,
3269 for (i = 0; i < entry->relocation_count; i++) { 3262 reloc->target_handle);
3270 struct drm_i915_gem_relocation_entry reloc; 3263 if (target_obj == NULL)
3271 uint32_t target_offset; 3264 return -ENOENT;
3272 3265
3273 if (__copy_from_user_inatomic(&reloc, 3266 target_offset = to_intel_bo(target_obj)->gtt_offset;
3274 user_relocs+i,
3275 sizeof(reloc))) {
3276 ret = -EFAULT;
3277 break;
3278 }
3279 3267
3280 if (reloc.target_handle != target_handle) { 3268#if WATCH_RELOC
3281 drm_gem_object_unreference(target_obj); 3269 DRM_INFO("%s: obj %p offset %08x target %d "
3270 "read %08x write %08x gtt %08x "
3271 "presumed %08x delta %08x\n",
3272 __func__,
3273 obj,
3274 (int) reloc->offset,
3275 (int) reloc->target_handle,
3276 (int) reloc->read_domains,
3277 (int) reloc->write_domain,
3278 (int) target_offset,
3279 (int) reloc->presumed_offset,
3280 reloc->delta);
3281#endif
3282 3282
3283 target_obj = drm_gem_object_lookup(dev, file_priv, 3283 /* The target buffer should have appeared before us in the
3284 reloc.target_handle); 3284 * exec_object list, so it should have a GTT space bound by now.
3285 if (target_obj == NULL) { 3285 */
3286 ret = -ENOENT; 3286 if (target_offset == 0) {
3287 break; 3287 DRM_ERROR("No GTT space found for object %d\n",
3288 } 3288 reloc->target_handle);
3289 goto err;
3290 }
3289 3291
3290 target_handle = reloc.target_handle; 3292 /* Validate that the target is in a valid r/w GPU domain */
3291 } 3293 if (reloc->write_domain & (reloc->write_domain - 1)) {
3292 target_offset = to_intel_bo(target_obj)->gtt_offset; 3294 DRM_ERROR("reloc with multiple write domains: "
3295 "obj %p target %d offset %d "
3296 "read %08x write %08x",
3297 obj, reloc->target_handle,
3298 (int) reloc->offset,
3299 reloc->read_domains,
3300 reloc->write_domain);
3301 goto err;
3302 }
3303 if (reloc->write_domain & I915_GEM_DOMAIN_CPU ||
3304 reloc->read_domains & I915_GEM_DOMAIN_CPU) {
3305 DRM_ERROR("reloc with read/write CPU domains: "
3306 "obj %p target %d offset %d "
3307 "read %08x write %08x",
3308 obj, reloc->target_handle,
3309 (int) reloc->offset,
3310 reloc->read_domains,
3311 reloc->write_domain);
3312 goto err;
3313 }
3314 if (reloc->write_domain && target_obj->pending_write_domain &&
3315 reloc->write_domain != target_obj->pending_write_domain) {
3316 DRM_ERROR("Write domain conflict: "
3317 "obj %p target %d offset %d "
3318 "new %08x old %08x\n",
3319 obj, reloc->target_handle,
3320 (int) reloc->offset,
3321 reloc->write_domain,
3322 target_obj->pending_write_domain);
3323 goto err;
3324 }
3293 3325
3294#if WATCH_RELOC 3326 target_obj->pending_read_domains |= reloc->read_domains;
3295 DRM_INFO("%s: obj %p offset %08x target %d " 3327 target_obj->pending_write_domain |= reloc->write_domain;
3296 "read %08x write %08x gtt %08x "
3297 "presumed %08x delta %08x\n",
3298 __func__,
3299 obj,
3300 (int) reloc.offset,
3301 (int) reloc.target_handle,
3302 (int) reloc.read_domains,
3303 (int) reloc.write_domain,
3304 (int) target_offset,
3305 (int) reloc.presumed_offset,
3306 reloc.delta);
3307#endif
3308 3328
3309 /* The target buffer should have appeared before us in the 3329 /* If the relocation already has the right value in it, no
3310 * exec_object list, so it should have a GTT space bound by now. 3330 * more work needs to be done.
3311 */ 3331 */
3312 if (target_offset == 0) { 3332 if (target_offset == reloc->presumed_offset)
3313 DRM_ERROR("No GTT space found for object %d\n", 3333 goto out;
3314 reloc.target_handle);
3315 ret = -EINVAL;
3316 break;
3317 }
3318 3334
3319 /* Validate that the target is in a valid r/w GPU domain */ 3335 /* Check that the relocation address is valid... */
3320 if (reloc.write_domain & (reloc.write_domain - 1)) { 3336 if (reloc->offset > obj->base.size - 4) {
3321 DRM_ERROR("reloc with multiple write domains: " 3337 DRM_ERROR("Relocation beyond object bounds: "
3322 "obj %p target %d offset %d " 3338 "obj %p target %d offset %d size %d.\n",
3323 "read %08x write %08x", 3339 obj, reloc->target_handle,
3324 obj, reloc.target_handle, 3340 (int) reloc->offset,
3325 (int) reloc.offset, 3341 (int) obj->base.size);
3326 reloc.read_domains, 3342 goto err;
3327 reloc.write_domain); 3343 }
3328 ret = -EINVAL; 3344 if (reloc->offset & 3) {
3329 break; 3345 DRM_ERROR("Relocation not 4-byte aligned: "
3330 } 3346 "obj %p target %d offset %d.\n",
3331 if (reloc.write_domain & I915_GEM_DOMAIN_CPU || 3347 obj, reloc->target_handle,
3332 reloc.read_domains & I915_GEM_DOMAIN_CPU) { 3348 (int) reloc->offset);
3333 DRM_ERROR("reloc with read/write CPU domains: " 3349 goto err;
3334 "obj %p target %d offset %d " 3350 }
3335 "read %08x write %08x",
3336 obj, reloc.target_handle,
3337 (int) reloc.offset,
3338 reloc.read_domains,
3339 reloc.write_domain);
3340 ret = -EINVAL;
3341 break;
3342 }
3343 if (reloc.write_domain && target_obj->pending_write_domain &&
3344 reloc.write_domain != target_obj->pending_write_domain) {
3345 DRM_ERROR("Write domain conflict: "
3346 "obj %p target %d offset %d "
3347 "new %08x old %08x\n",
3348 obj, reloc.target_handle,
3349 (int) reloc.offset,
3350 reloc.write_domain,
3351 target_obj->pending_write_domain);
3352 ret = -EINVAL;
3353 break;
3354 }
3355 3351
3356 target_obj->pending_read_domains |= reloc.read_domains; 3352 /* and points to somewhere within the target object. */
3357 target_obj->pending_write_domain |= reloc.write_domain; 3353 if (reloc->delta >= target_obj->size) {
3354 DRM_ERROR("Relocation beyond target object bounds: "
3355 "obj %p target %d delta %d size %d.\n",
3356 obj, reloc->target_handle,
3357 (int) reloc->delta,
3358 (int) target_obj->size);
3359 goto err;
3360 }
3358 3361
3359 /* If the relocation already has the right value in it, no 3362 reloc->delta += target_offset;
3360 * more work needs to be done. 3363 if (obj->base.write_domain == I915_GEM_DOMAIN_CPU) {
3361 */ 3364 uint32_t page_offset = reloc->offset & ~PAGE_MASK;
3362 if (target_offset == reloc.presumed_offset) 3365 char *vaddr;
3363 continue;
3364 3366
3365 /* Check that the relocation address is valid... */ 3367 vaddr = kmap_atomic(obj->pages[reloc->offset >> PAGE_SHIFT]);
3366 if (reloc.offset > obj->base.size - 4) { 3368 *(uint32_t *)(vaddr + page_offset) = reloc->delta;
3367 DRM_ERROR("Relocation beyond object bounds: " 3369 kunmap_atomic(vaddr);
3368 "obj %p target %d offset %d size %d.\n", 3370 } else {
3369 obj, reloc.target_handle, 3371 struct drm_i915_private *dev_priv = dev->dev_private;
3370 (int) reloc.offset, (int) obj->base.size); 3372 uint32_t __iomem *reloc_entry;
3371 ret = -EINVAL; 3373 void __iomem *reloc_page;
3372 break;
3373 }
3374 if (reloc.offset & 3) {
3375 DRM_ERROR("Relocation not 4-byte aligned: "
3376 "obj %p target %d offset %d.\n",
3377 obj, reloc.target_handle,
3378 (int) reloc.offset);
3379 ret = -EINVAL;
3380 break;
3381 }
3382 3374
3383 /* and points to somewhere within the target object. */ 3375 ret = i915_gem_object_set_to_gtt_domain(&obj->base, 1);
3384 if (reloc.delta >= target_obj->size) { 3376 if (ret)
3385 DRM_ERROR("Relocation beyond target object bounds: " 3377 goto err;
3386 "obj %p target %d delta %d size %d.\n",
3387 obj, reloc.target_handle,
3388 (int) reloc.delta, (int) target_obj->size);
3389 ret = -EINVAL;
3390 break;
3391 }
3392 3378
3393 reloc.delta += target_offset; 3379 /* Map the page containing the relocation we're going to perform. */
3394 if (obj->base.write_domain == I915_GEM_DOMAIN_CPU) { 3380 reloc->offset += obj->gtt_offset;
3395 uint32_t page_offset = reloc.offset & ~PAGE_MASK; 3381 reloc_page = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
3396 char *vaddr; 3382 reloc->offset & PAGE_MASK);
3383 reloc_entry = (uint32_t __iomem *)
3384 (reloc_page + (reloc->offset & ~PAGE_MASK));
3385 iowrite32(reloc->delta, reloc_entry);
3386 io_mapping_unmap_atomic(reloc_page);
3387 }
3397 3388
3398 vaddr = kmap_atomic(obj->pages[reloc.offset >> PAGE_SHIFT]); 3389 /* and update the user's relocation entry */
3399 *(uint32_t *)(vaddr + page_offset) = reloc.delta; 3390 reloc->presumed_offset = target_offset;
3400 kunmap_atomic(vaddr);
3401 } else {
3402 uint32_t __iomem *reloc_entry;
3403 void __iomem *reloc_page;
3404 3391
3405 ret = i915_gem_object_set_to_gtt_domain(&obj->base, 1); 3392out:
3406 if (ret) 3393 ret = 0;
3407 break; 3394err:
3395 drm_gem_object_unreference(target_obj);
3396 return ret;
3397}
3408 3398
3409 /* Map the page containing the relocation we're going to perform. */ 3399static int
3410 reloc.offset += obj->gtt_offset; 3400i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj,
3411 reloc_page = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, 3401 struct drm_file *file_priv,
3412 reloc.offset & PAGE_MASK); 3402 struct drm_i915_gem_exec_object2 *entry)
3413 reloc_entry = (uint32_t __iomem *) 3403{
3414 (reloc_page + (reloc.offset & ~PAGE_MASK)); 3404 struct drm_i915_gem_relocation_entry __user *user_relocs;
3415 iowrite32(reloc.delta, reloc_entry); 3405 int i, ret;
3416 io_mapping_unmap_atomic(reloc_page); 3406
3417 } 3407 user_relocs = (void __user *)(uintptr_t)entry->relocs_ptr;
3408 for (i = 0; i < entry->relocation_count; i++) {
3409 struct drm_i915_gem_relocation_entry reloc;
3410
3411 if (__copy_from_user_inatomic(&reloc,
3412 user_relocs+i,
3413 sizeof(reloc)))
3414 return -EFAULT;
3415
3416 ret = i915_gem_execbuffer_relocate_entry(obj, file_priv, entry, &reloc);
3417 if (ret)
3418 return ret;
3418 3419
3419 /* and update the user's relocation entry */
3420 reloc.presumed_offset = target_offset;
3421 if (__copy_to_user_inatomic(&user_relocs[i].presumed_offset, 3420 if (__copy_to_user_inatomic(&user_relocs[i].presumed_offset,
3422 &reloc.presumed_offset, 3421 &reloc.presumed_offset,
3423 sizeof(reloc.presumed_offset))) { 3422 sizeof(reloc.presumed_offset)))
3424 ret = -EFAULT; 3423 return -EFAULT;
3425 break;
3426 }
3427 } 3424 }
3428 3425
3429 drm_gem_object_unreference(target_obj); 3426 return 0;
3430 return ret; 3427}
3428
3429static int
3430i915_gem_execbuffer_relocate_object_slow(struct drm_i915_gem_object *obj,
3431 struct drm_file *file_priv,
3432 struct drm_i915_gem_exec_object2 *entry,
3433 struct drm_i915_gem_relocation_entry *relocs)
3434{
3435 int i, ret;
3436
3437 for (i = 0; i < entry->relocation_count; i++) {
3438 ret = i915_gem_execbuffer_relocate_entry(obj, file_priv, entry, &relocs[i]);
3439 if (ret)
3440 return ret;
3441 }
3442
3443 return 0;
3431} 3444}
3432 3445
3433static int 3446static int
3434i915_gem_execbuffer_pin(struct drm_device *dev, 3447i915_gem_execbuffer_relocate(struct drm_device *dev,
3435 struct drm_file *file, 3448 struct drm_file *file,
3436 struct drm_gem_object **object_list, 3449 struct drm_gem_object **object_list,
3437 struct drm_i915_gem_exec_object2 *exec_list, 3450 struct drm_i915_gem_exec_object2 *exec_list,
3438 int count) 3451 int count)
3452{
3453 int i, ret;
3454
3455 for (i = 0; i < count; i++) {
3456 struct drm_i915_gem_object *obj = to_intel_bo(object_list[i]);
3457 obj->base.pending_read_domains = 0;
3458 obj->base.pending_write_domain = 0;
3459 ret = i915_gem_execbuffer_relocate_object(obj, file,
3460 &exec_list[i]);
3461 if (ret)
3462 return ret;
3463 }
3464
3465 return 0;
3466}
3467
3468static int
3469i915_gem_execbuffer_reserve(struct drm_device *dev,
3470 struct drm_file *file,
3471 struct drm_gem_object **object_list,
3472 struct drm_i915_gem_exec_object2 *exec_list,
3473 int count)
3439{ 3474{
3440 struct drm_i915_private *dev_priv = dev->dev_private; 3475 struct drm_i915_private *dev_priv = dev->dev_private;
3441 int ret, i, retry; 3476 int ret, i, retry;
@@ -3497,6 +3532,133 @@ i915_gem_execbuffer_pin(struct drm_device *dev,
3497 return 0; 3532 return 0;
3498} 3533}
3499 3534
3535static int
3536i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
3537 struct drm_file *file,
3538 struct drm_gem_object **object_list,
3539 struct drm_i915_gem_exec_object2 *exec_list,
3540 int count)
3541{
3542 struct drm_i915_gem_relocation_entry *reloc;
3543 int i, total, ret;
3544
3545 for (i = 0; i < count; i++) {
3546 struct drm_i915_gem_object *obj = to_intel_bo(object_list[i]);
3547 obj->in_execbuffer = false;
3548 }
3549
3550 mutex_unlock(&dev->struct_mutex);
3551
3552 total = 0;
3553 for (i = 0; i < count; i++)
3554 total += exec_list[i].relocation_count;
3555
3556 reloc = drm_malloc_ab(total, sizeof(*reloc));
3557 if (reloc == NULL) {
3558 mutex_lock(&dev->struct_mutex);
3559 return -ENOMEM;
3560 }
3561
3562 total = 0;
3563 for (i = 0; i < count; i++) {
3564 struct drm_i915_gem_relocation_entry __user *user_relocs;
3565
3566 user_relocs = (void __user *)(uintptr_t)exec_list[i].relocs_ptr;
3567
3568 if (copy_from_user(reloc+total, user_relocs,
3569 exec_list[i].relocation_count *
3570 sizeof(*reloc))) {
3571 ret = -EFAULT;
3572 mutex_lock(&dev->struct_mutex);
3573 goto err;
3574 }
3575
3576 total += exec_list[i].relocation_count;
3577 }
3578
3579 ret = i915_mutex_lock_interruptible(dev);
3580 if (ret) {
3581 mutex_lock(&dev->struct_mutex);
3582 goto err;
3583 }
3584
3585 ret = i915_gem_execbuffer_reserve(dev, file,
3586 object_list, exec_list,
3587 count);
3588 if (ret)
3589 goto err;
3590
3591 total = 0;
3592 for (i = 0; i < count; i++) {
3593 struct drm_i915_gem_object *obj = to_intel_bo(object_list[i]);
3594 obj->base.pending_read_domains = 0;
3595 obj->base.pending_write_domain = 0;
3596 ret = i915_gem_execbuffer_relocate_object_slow(obj, file,
3597 &exec_list[i],
3598 reloc + total);
3599 if (ret)
3600 goto err;
3601
3602 total += exec_list[i].relocation_count;
3603 }
3604
3605 /* Leave the user relocations as are, this is the painfully slow path,
3606 * and we want to avoid the complication of dropping the lock whilst
3607 * having buffers reserved in the aperture and so causing spurious
3608 * ENOSPC for random operations.
3609 */
3610
3611err:
3612 drm_free_large(reloc);
3613 return ret;
3614}
3615
3616static int
3617i915_gem_execbuffer_move_to_gpu(struct drm_device *dev,
3618 struct drm_file *file,
3619 struct intel_ring_buffer *ring,
3620 struct drm_gem_object **objects,
3621 int count)
3622{
3623 struct drm_i915_private *dev_priv = dev->dev_private;
3624 int ret, i;
3625
3626 /* Zero the global flush/invalidate flags. These
3627 * will be modified as new domains are computed
3628 * for each object
3629 */
3630 dev->invalidate_domains = 0;
3631 dev->flush_domains = 0;
3632 dev_priv->mm.flush_rings = 0;
3633 for (i = 0; i < count; i++)
3634 i915_gem_object_set_to_gpu_domain(objects[i], ring);
3635
3636 if (dev->invalidate_domains | dev->flush_domains) {
3637#if WATCH_EXEC
3638 DRM_INFO("%s: invalidate_domains %08x flush_domains %08x\n",
3639 __func__,
3640 dev->invalidate_domains,
3641 dev->flush_domains);
3642#endif
3643 i915_gem_flush(dev, file,
3644 dev->invalidate_domains,
3645 dev->flush_domains,
3646 dev_priv->mm.flush_rings);
3647 }
3648
3649 for (i = 0; i < count; i++) {
3650 struct drm_i915_gem_object *obj = to_intel_bo(objects[i]);
3651 /* XXX replace with semaphores */
3652 if (obj->ring && ring != obj->ring) {
3653 ret = i915_gem_object_wait_rendering(&obj->base, true);
3654 if (ret)
3655 return ret;
3656 }
3657 }
3658
3659 return 0;
3660}
3661
3500/* Throttle our rendering by waiting until the ring has completed our requests 3662/* Throttle our rendering by waiting until the ring has completed our requests
3501 * emitted over 20 msec ago. 3663 * emitted over 20 msec ago.
3502 * 3664 *
@@ -3580,8 +3742,15 @@ validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
3580 3742
3581 for (i = 0; i < count; i++) { 3743 for (i = 0; i < count; i++) {
3582 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr; 3744 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
3583 size_t length = exec[i].relocation_count * sizeof(struct drm_i915_gem_relocation_entry); 3745 int length; /* limited by fault_in_pages_readable() */
3746
3747 /* First check for malicious input causing overflow */
3748 if (exec[i].relocation_count >
3749 INT_MAX / sizeof(struct drm_i915_gem_relocation_entry))
3750 return -EINVAL;
3584 3751
3752 length = exec[i].relocation_count *
3753 sizeof(struct drm_i915_gem_relocation_entry);
3585 if (!access_ok(VERIFY_READ, ptr, length)) 3754 if (!access_ok(VERIFY_READ, ptr, length))
3586 return -EFAULT; 3755 return -EFAULT;
3587 3756
@@ -3724,18 +3893,24 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
3724 } 3893 }
3725 3894
3726 /* Move the objects en-masse into the GTT, evicting if necessary. */ 3895 /* Move the objects en-masse into the GTT, evicting if necessary. */
3727 ret = i915_gem_execbuffer_pin(dev, file, 3896 ret = i915_gem_execbuffer_reserve(dev, file,
3728 object_list, exec_list, 3897 object_list, exec_list,
3729 args->buffer_count); 3898 args->buffer_count);
3730 if (ret) 3899 if (ret)
3731 goto err; 3900 goto err;
3732 3901
3733 /* The objects are in their final locations, apply the relocations. */ 3902 /* The objects are in their final locations, apply the relocations. */
3734 for (i = 0; i < args->buffer_count; i++) { 3903 ret = i915_gem_execbuffer_relocate(dev, file,
3735 struct drm_i915_gem_object *obj = to_intel_bo(object_list[i]); 3904 object_list, exec_list,
3736 obj->base.pending_read_domains = 0; 3905 args->buffer_count);
3737 obj->base.pending_write_domain = 0; 3906 if (ret) {
3738 ret = i915_gem_execbuffer_relocate(obj, file, &exec_list[i]); 3907 if (ret == -EFAULT) {
3908 ret = i915_gem_execbuffer_relocate_slow(dev, file,
3909 object_list,
3910 exec_list,
3911 args->buffer_count);
3912 BUG_ON(!mutex_is_locked(&dev->struct_mutex));
3913 }
3739 if (ret) 3914 if (ret)
3740 goto err; 3915 goto err;
3741 } 3916 }
@@ -3757,33 +3932,10 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
3757 goto err; 3932 goto err;
3758 } 3933 }
3759 3934
3760 /* Zero the global flush/invalidate flags. These 3935 ret = i915_gem_execbuffer_move_to_gpu(dev, file, ring,
3761 * will be modified as new domains are computed 3936 object_list, args->buffer_count);
3762 * for each object 3937 if (ret)
3763 */ 3938 goto err;
3764 dev->invalidate_domains = 0;
3765 dev->flush_domains = 0;
3766 dev_priv->mm.flush_rings = 0;
3767
3768 for (i = 0; i < args->buffer_count; i++) {
3769 struct drm_gem_object *obj = object_list[i];
3770
3771 /* Compute new gpu domains and update invalidate/flush */
3772 i915_gem_object_set_to_gpu_domain(obj, ring);
3773 }
3774
3775 if (dev->invalidate_domains | dev->flush_domains) {
3776#if WATCH_EXEC
3777 DRM_INFO("%s: invalidate_domains %08x flush_domains %08x\n",
3778 __func__,
3779 dev->invalidate_domains,
3780 dev->flush_domains);
3781#endif
3782 i915_gem_flush(dev, file,
3783 dev->invalidate_domains,
3784 dev->flush_domains,
3785 dev_priv->mm.flush_rings);
3786 }
3787 3939
3788 for (i = 0; i < args->buffer_count; i++) { 3940 for (i = 0; i < args->buffer_count; i++) {
3789 struct drm_gem_object *obj = object_list[i]; 3941 struct drm_gem_object *obj = object_list[i];
@@ -4043,8 +4195,7 @@ i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment)
4043 alignment = i915_gem_get_gtt_alignment(obj); 4195 alignment = i915_gem_get_gtt_alignment(obj);
4044 if (obj_priv->gtt_offset & (alignment - 1)) { 4196 if (obj_priv->gtt_offset & (alignment - 1)) {
4045 WARN(obj_priv->pin_count, 4197 WARN(obj_priv->pin_count,
4046 "bo is already pinned with incorrect alignment:" 4198 "bo is already pinned with incorrect alignment: offset=%x, req.alignment=%x\n",
4047 " offset=%x, req.alignment=%x\n",
4048 obj_priv->gtt_offset, alignment); 4199 obj_priv->gtt_offset, alignment);
4049 ret = i915_gem_object_unbind(obj); 4200 ret = i915_gem_object_unbind(obj);
4050 if (ret) 4201 if (ret)
@@ -4223,10 +4374,20 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
4223 * use this buffer rather sooner than later, so issuing the required 4374 * use this buffer rather sooner than later, so issuing the required
4224 * flush earlier is beneficial. 4375 * flush earlier is beneficial.
4225 */ 4376 */
4226 if (obj->write_domain & I915_GEM_GPU_DOMAINS) 4377 if (obj->write_domain & I915_GEM_GPU_DOMAINS) {
4227 i915_gem_flush_ring(dev, file_priv, 4378 i915_gem_flush_ring(dev, file_priv,
4228 obj_priv->ring, 4379 obj_priv->ring,
4229 0, obj->write_domain); 4380 0, obj->write_domain);
4381 } else if (obj_priv->ring->outstanding_lazy_request) {
4382 /* This ring is not being cleared by active usage,
4383 * so emit a request to do so.
4384 */
4385 u32 seqno = i915_add_request(dev,
4386 NULL, NULL,
4387 obj_priv->ring);
4388 if (seqno == 0)
4389 ret = -ENOMEM;
4390 }
4230 4391
4231 /* Update the active list for the hardware's current position. 4392 /* Update the active list for the hardware's current position.
4232 * Otherwise this only updates on a delayed timer or when irqs 4393 * Otherwise this only updates on a delayed timer or when irqs
@@ -4856,17 +5017,24 @@ i915_gem_phys_pwrite(struct drm_device *dev, struct drm_gem_object *obj,
4856 struct drm_file *file_priv) 5017 struct drm_file *file_priv)
4857{ 5018{
4858 struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); 5019 struct drm_i915_gem_object *obj_priv = to_intel_bo(obj);
4859 void *obj_addr; 5020 void *vaddr = obj_priv->phys_obj->handle->vaddr + args->offset;
4860 int ret; 5021 char __user *user_data = (char __user *) (uintptr_t) args->data_ptr;
4861 char __user *user_data;
4862 5022
4863 user_data = (char __user *) (uintptr_t) args->data_ptr; 5023 DRM_DEBUG_DRIVER("vaddr %p, %lld\n", vaddr, args->size);
4864 obj_addr = obj_priv->phys_obj->handle->vaddr + args->offset;
4865 5024
4866 DRM_DEBUG_DRIVER("obj_addr %p, %lld\n", obj_addr, args->size); 5025 if (__copy_from_user_inatomic_nocache(vaddr, user_data, args->size)) {
4867 ret = copy_from_user(obj_addr, user_data, args->size); 5026 unsigned long unwritten;
4868 if (ret) 5027
4869 return -EFAULT; 5028 /* The physical object once assigned is fixed for the lifetime
5029 * of the obj, so we can safely drop the lock and continue
5030 * to access vaddr.
5031 */
5032 mutex_unlock(&dev->struct_mutex);
5033 unwritten = copy_from_user(vaddr, user_data, args->size);
5034 mutex_lock(&dev->struct_mutex);
5035 if (unwritten)
5036 return -EFAULT;
5037 }
4870 5038
4871 drm_agp_chipset_flush(dev); 5039 drm_agp_chipset_flush(dev);
4872 return 0; 5040 return 0;
@@ -4900,9 +5068,7 @@ i915_gpu_is_active(struct drm_device *dev)
4900 int lists_empty; 5068 int lists_empty;
4901 5069
4902 lists_empty = list_empty(&dev_priv->mm.flushing_list) && 5070 lists_empty = list_empty(&dev_priv->mm.flushing_list) &&
4903 list_empty(&dev_priv->render_ring.active_list) && 5071 list_empty(&dev_priv->mm.active_list);
4904 list_empty(&dev_priv->bsd_ring.active_list) &&
4905 list_empty(&dev_priv->blt_ring.active_list);
4906 5072
4907 return !lists_empty; 5073 return !lists_empty;
4908} 5074}
diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
index 43a4013f53fa..d8ae7d1d0cc6 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -165,9 +165,7 @@ i915_gem_evict_everything(struct drm_device *dev)
165 165
166 lists_empty = (list_empty(&dev_priv->mm.inactive_list) && 166 lists_empty = (list_empty(&dev_priv->mm.inactive_list) &&
167 list_empty(&dev_priv->mm.flushing_list) && 167 list_empty(&dev_priv->mm.flushing_list) &&
168 list_empty(&dev_priv->render_ring.active_list) && 168 list_empty(&dev_priv->mm.active_list));
169 list_empty(&dev_priv->bsd_ring.active_list) &&
170 list_empty(&dev_priv->blt_ring.active_list));
171 if (lists_empty) 169 if (lists_empty)
172 return -ENOSPC; 170 return -ENOSPC;
173 171
@@ -184,9 +182,7 @@ i915_gem_evict_everything(struct drm_device *dev)
184 182
185 lists_empty = (list_empty(&dev_priv->mm.inactive_list) && 183 lists_empty = (list_empty(&dev_priv->mm.inactive_list) &&
186 list_empty(&dev_priv->mm.flushing_list) && 184 list_empty(&dev_priv->mm.flushing_list) &&
187 list_empty(&dev_priv->render_ring.active_list) && 185 list_empty(&dev_priv->mm.active_list));
188 list_empty(&dev_priv->bsd_ring.active_list) &&
189 list_empty(&dev_priv->blt_ring.active_list));
190 BUG_ON(!lists_empty); 186 BUG_ON(!lists_empty);
191 187
192 return 0; 188 return 0;
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 25ed911a3112..878fc766a12c 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -3033,6 +3033,7 @@
3033#define TRANS_DP_10BPC (1<<9) 3033#define TRANS_DP_10BPC (1<<9)
3034#define TRANS_DP_6BPC (2<<9) 3034#define TRANS_DP_6BPC (2<<9)
3035#define TRANS_DP_12BPC (3<<9) 3035#define TRANS_DP_12BPC (3<<9)
3036#define TRANS_DP_BPC_MASK (3<<9)
3036#define TRANS_DP_VSYNC_ACTIVE_HIGH (1<<4) 3037#define TRANS_DP_VSYNC_ACTIVE_HIGH (1<<4)
3037#define TRANS_DP_VSYNC_ACTIVE_LOW 0 3038#define TRANS_DP_VSYNC_ACTIVE_LOW 0
3038#define TRANS_DP_HSYNC_ACTIVE_HIGH (1<<3) 3039#define TRANS_DP_HSYNC_ACTIVE_HIGH (1<<3)
diff --git a/drivers/gpu/drm/i915/i915_suspend.c b/drivers/gpu/drm/i915/i915_suspend.c
index 989c19d2d959..42729d25da58 100644
--- a/drivers/gpu/drm/i915/i915_suspend.c
+++ b/drivers/gpu/drm/i915/i915_suspend.c
@@ -239,6 +239,16 @@ static void i915_save_modeset_reg(struct drm_device *dev)
239 if (drm_core_check_feature(dev, DRIVER_MODESET)) 239 if (drm_core_check_feature(dev, DRIVER_MODESET))
240 return; 240 return;
241 241
242 /* Cursor state */
243 dev_priv->saveCURACNTR = I915_READ(CURACNTR);
244 dev_priv->saveCURAPOS = I915_READ(CURAPOS);
245 dev_priv->saveCURABASE = I915_READ(CURABASE);
246 dev_priv->saveCURBCNTR = I915_READ(CURBCNTR);
247 dev_priv->saveCURBPOS = I915_READ(CURBPOS);
248 dev_priv->saveCURBBASE = I915_READ(CURBBASE);
249 if (IS_GEN2(dev))
250 dev_priv->saveCURSIZE = I915_READ(CURSIZE);
251
242 if (HAS_PCH_SPLIT(dev)) { 252 if (HAS_PCH_SPLIT(dev)) {
243 dev_priv->savePCH_DREF_CONTROL = I915_READ(PCH_DREF_CONTROL); 253 dev_priv->savePCH_DREF_CONTROL = I915_READ(PCH_DREF_CONTROL);
244 dev_priv->saveDISP_ARB_CTL = I915_READ(DISP_ARB_CTL); 254 dev_priv->saveDISP_ARB_CTL = I915_READ(DISP_ARB_CTL);
@@ -529,6 +539,16 @@ static void i915_restore_modeset_reg(struct drm_device *dev)
529 I915_WRITE(DSPBCNTR, dev_priv->saveDSPBCNTR); 539 I915_WRITE(DSPBCNTR, dev_priv->saveDSPBCNTR);
530 I915_WRITE(DSPBADDR, I915_READ(DSPBADDR)); 540 I915_WRITE(DSPBADDR, I915_READ(DSPBADDR));
531 541
542 /* Cursor state */
543 I915_WRITE(CURAPOS, dev_priv->saveCURAPOS);
544 I915_WRITE(CURACNTR, dev_priv->saveCURACNTR);
545 I915_WRITE(CURABASE, dev_priv->saveCURABASE);
546 I915_WRITE(CURBPOS, dev_priv->saveCURBPOS);
547 I915_WRITE(CURBCNTR, dev_priv->saveCURBCNTR);
548 I915_WRITE(CURBBASE, dev_priv->saveCURBBASE);
549 if (IS_GEN2(dev))
550 I915_WRITE(CURSIZE, dev_priv->saveCURSIZE);
551
532 return; 552 return;
533} 553}
534 554
@@ -543,16 +563,6 @@ void i915_save_display(struct drm_device *dev)
543 /* Don't save them in KMS mode */ 563 /* Don't save them in KMS mode */
544 i915_save_modeset_reg(dev); 564 i915_save_modeset_reg(dev);
545 565
546 /* Cursor state */
547 dev_priv->saveCURACNTR = I915_READ(CURACNTR);
548 dev_priv->saveCURAPOS = I915_READ(CURAPOS);
549 dev_priv->saveCURABASE = I915_READ(CURABASE);
550 dev_priv->saveCURBCNTR = I915_READ(CURBCNTR);
551 dev_priv->saveCURBPOS = I915_READ(CURBPOS);
552 dev_priv->saveCURBBASE = I915_READ(CURBBASE);
553 if (IS_GEN2(dev))
554 dev_priv->saveCURSIZE = I915_READ(CURSIZE);
555
556 /* CRT state */ 566 /* CRT state */
557 if (HAS_PCH_SPLIT(dev)) { 567 if (HAS_PCH_SPLIT(dev)) {
558 dev_priv->saveADPA = I915_READ(PCH_ADPA); 568 dev_priv->saveADPA = I915_READ(PCH_ADPA);
@@ -657,16 +667,6 @@ void i915_restore_display(struct drm_device *dev)
657 /* Don't restore them in KMS mode */ 667 /* Don't restore them in KMS mode */
658 i915_restore_modeset_reg(dev); 668 i915_restore_modeset_reg(dev);
659 669
660 /* Cursor state */
661 I915_WRITE(CURAPOS, dev_priv->saveCURAPOS);
662 I915_WRITE(CURACNTR, dev_priv->saveCURACNTR);
663 I915_WRITE(CURABASE, dev_priv->saveCURABASE);
664 I915_WRITE(CURBPOS, dev_priv->saveCURBPOS);
665 I915_WRITE(CURBCNTR, dev_priv->saveCURBCNTR);
666 I915_WRITE(CURBBASE, dev_priv->saveCURBBASE);
667 if (IS_GEN2(dev))
668 I915_WRITE(CURSIZE, dev_priv->saveCURSIZE);
669
670 /* CRT state */ 670 /* CRT state */
671 if (HAS_PCH_SPLIT(dev)) 671 if (HAS_PCH_SPLIT(dev))
672 I915_WRITE(PCH_ADPA, dev_priv->saveADPA); 672 I915_WRITE(PCH_ADPA, dev_priv->saveADPA);
@@ -862,8 +862,10 @@ int i915_restore_state(struct drm_device *dev)
862 /* Clock gating state */ 862 /* Clock gating state */
863 intel_init_clock_gating(dev); 863 intel_init_clock_gating(dev);
864 864
865 if (HAS_PCH_SPLIT(dev)) 865 if (HAS_PCH_SPLIT(dev)) {
866 ironlake_enable_drps(dev); 866 ironlake_enable_drps(dev);
867 intel_init_emon(dev);
868 }
867 869
868 /* Cache mode state */ 870 /* Cache mode state */
869 I915_WRITE (CACHE_MODE_0, dev_priv->saveCACHE_MODE_0 | 0xffff0000); 871 I915_WRITE (CACHE_MODE_0, dev_priv->saveCACHE_MODE_0 | 0xffff0000);
diff --git a/drivers/gpu/drm/i915/intel_acpi.c b/drivers/gpu/drm/i915/intel_acpi.c
index 65c88f9ba12c..2cb8e0b9f1ee 100644
--- a/drivers/gpu/drm/i915/intel_acpi.c
+++ b/drivers/gpu/drm/i915/intel_acpi.c
@@ -190,37 +190,6 @@ out:
190 kfree(output.pointer); 190 kfree(output.pointer);
191} 191}
192 192
193static int intel_dsm_switchto(enum vga_switcheroo_client_id id)
194{
195 return 0;
196}
197
198static int intel_dsm_power_state(enum vga_switcheroo_client_id id,
199 enum vga_switcheroo_state state)
200{
201 return 0;
202}
203
204static int intel_dsm_init(void)
205{
206 return 0;
207}
208
209static int intel_dsm_get_client_id(struct pci_dev *pdev)
210{
211 if (intel_dsm_priv.dhandle == DEVICE_ACPI_HANDLE(&pdev->dev))
212 return VGA_SWITCHEROO_IGD;
213 else
214 return VGA_SWITCHEROO_DIS;
215}
216
217static struct vga_switcheroo_handler intel_dsm_handler = {
218 .switchto = intel_dsm_switchto,
219 .power_state = intel_dsm_power_state,
220 .init = intel_dsm_init,
221 .get_client_id = intel_dsm_get_client_id,
222};
223
224static bool intel_dsm_pci_probe(struct pci_dev *pdev) 193static bool intel_dsm_pci_probe(struct pci_dev *pdev)
225{ 194{
226 acpi_handle dhandle, intel_handle; 195 acpi_handle dhandle, intel_handle;
@@ -276,11 +245,8 @@ void intel_register_dsm_handler(void)
276{ 245{
277 if (!intel_dsm_detect()) 246 if (!intel_dsm_detect())
278 return; 247 return;
279
280 vga_switcheroo_register_handler(&intel_dsm_handler);
281} 248}
282 249
283void intel_unregister_dsm_handler(void) 250void intel_unregister_dsm_handler(void)
284{ 251{
285 vga_switcheroo_unregister_handler();
286} 252}
diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
index c55c77043357..8df574316063 100644
--- a/drivers/gpu/drm/i915/intel_crt.c
+++ b/drivers/gpu/drm/i915/intel_crt.c
@@ -34,6 +34,25 @@
34#include "i915_drm.h" 34#include "i915_drm.h"
35#include "i915_drv.h" 35#include "i915_drv.h"
36 36
37/* Here's the desired hotplug mode */
38#define ADPA_HOTPLUG_BITS (ADPA_CRT_HOTPLUG_PERIOD_128 | \
39 ADPA_CRT_HOTPLUG_WARMUP_10MS | \
40 ADPA_CRT_HOTPLUG_SAMPLE_4S | \
41 ADPA_CRT_HOTPLUG_VOLTAGE_50 | \
42 ADPA_CRT_HOTPLUG_VOLREF_325MV | \
43 ADPA_CRT_HOTPLUG_ENABLE)
44
45struct intel_crt {
46 struct intel_encoder base;
47 bool force_hotplug_required;
48};
49
50static struct intel_crt *intel_attached_crt(struct drm_connector *connector)
51{
52 return container_of(intel_attached_encoder(connector),
53 struct intel_crt, base);
54}
55
37static void intel_crt_dpms(struct drm_encoder *encoder, int mode) 56static void intel_crt_dpms(struct drm_encoder *encoder, int mode)
38{ 57{
39 struct drm_device *dev = encoder->dev; 58 struct drm_device *dev = encoder->dev;
@@ -129,7 +148,7 @@ static void intel_crt_mode_set(struct drm_encoder *encoder,
129 dpll_md & ~DPLL_MD_UDI_MULTIPLIER_MASK); 148 dpll_md & ~DPLL_MD_UDI_MULTIPLIER_MASK);
130 } 149 }
131 150
132 adpa = 0; 151 adpa = ADPA_HOTPLUG_BITS;
133 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) 152 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
134 adpa |= ADPA_HSYNC_ACTIVE_HIGH; 153 adpa |= ADPA_HSYNC_ACTIVE_HIGH;
135 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) 154 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
@@ -157,53 +176,44 @@ static void intel_crt_mode_set(struct drm_encoder *encoder,
157static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector) 176static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector)
158{ 177{
159 struct drm_device *dev = connector->dev; 178 struct drm_device *dev = connector->dev;
179 struct intel_crt *crt = intel_attached_crt(connector);
160 struct drm_i915_private *dev_priv = dev->dev_private; 180 struct drm_i915_private *dev_priv = dev->dev_private;
161 u32 adpa, temp; 181 u32 adpa;
162 bool ret; 182 bool ret;
163 bool turn_off_dac = false;
164 183
165 temp = adpa = I915_READ(PCH_ADPA); 184 /* The first time through, trigger an explicit detection cycle */
185 if (crt->force_hotplug_required) {
186 bool turn_off_dac = HAS_PCH_SPLIT(dev);
187 u32 save_adpa;
166 188
167 if (HAS_PCH_SPLIT(dev)) 189 crt->force_hotplug_required = 0;
168 turn_off_dac = true; 190
169 191 save_adpa = adpa = I915_READ(PCH_ADPA);
170 adpa &= ~ADPA_CRT_HOTPLUG_MASK; 192 DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa);
171 if (turn_off_dac) 193
172 adpa &= ~ADPA_DAC_ENABLE; 194 adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
173 195 if (turn_off_dac)
174 /* disable HPD first */ 196 adpa &= ~ADPA_DAC_ENABLE;
175 I915_WRITE(PCH_ADPA, adpa); 197
176 (void)I915_READ(PCH_ADPA); 198 I915_WRITE(PCH_ADPA, adpa);
177 199
178 adpa |= (ADPA_CRT_HOTPLUG_PERIOD_128 | 200 if (wait_for((I915_READ(PCH_ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
179 ADPA_CRT_HOTPLUG_WARMUP_10MS | 201 1000))
180 ADPA_CRT_HOTPLUG_SAMPLE_4S | 202 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
181 ADPA_CRT_HOTPLUG_VOLTAGE_50 | /* default */ 203
182 ADPA_CRT_HOTPLUG_VOLREF_325MV | 204 if (turn_off_dac) {
183 ADPA_CRT_HOTPLUG_ENABLE | 205 I915_WRITE(PCH_ADPA, save_adpa);
184 ADPA_CRT_HOTPLUG_FORCE_TRIGGER); 206 POSTING_READ(PCH_ADPA);
185 207 }
186 DRM_DEBUG_KMS("pch crt adpa 0x%x", adpa);
187 I915_WRITE(PCH_ADPA, adpa);
188
189 if (wait_for((I915_READ(PCH_ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
190 1000))
191 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
192
193 if (turn_off_dac) {
194 /* Make sure hotplug is enabled */
195 I915_WRITE(PCH_ADPA, temp | ADPA_CRT_HOTPLUG_ENABLE);
196 (void)I915_READ(PCH_ADPA);
197 } 208 }
198 209
199 /* Check the status to see if both blue and green are on now */ 210 /* Check the status to see if both blue and green are on now */
200 adpa = I915_READ(PCH_ADPA); 211 adpa = I915_READ(PCH_ADPA);
201 adpa &= ADPA_CRT_HOTPLUG_MONITOR_MASK; 212 if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
202 if ((adpa == ADPA_CRT_HOTPLUG_MONITOR_COLOR) ||
203 (adpa == ADPA_CRT_HOTPLUG_MONITOR_MONO))
204 ret = true; 213 ret = true;
205 else 214 else
206 ret = false; 215 ret = false;
216 DRM_DEBUG_KMS("ironlake hotplug adpa=0x%x, result %d\n", adpa, ret);
207 217
208 return ret; 218 return ret;
209} 219}
@@ -277,13 +287,12 @@ static bool intel_crt_ddc_probe(struct drm_i915_private *dev_priv, int ddc_bus)
277 return i2c_transfer(&dev_priv->gmbus[ddc_bus].adapter, msgs, 1) == 1; 287 return i2c_transfer(&dev_priv->gmbus[ddc_bus].adapter, msgs, 1) == 1;
278} 288}
279 289
280static bool intel_crt_detect_ddc(struct drm_encoder *encoder) 290static bool intel_crt_detect_ddc(struct intel_crt *crt)
281{ 291{
282 struct intel_encoder *intel_encoder = to_intel_encoder(encoder); 292 struct drm_i915_private *dev_priv = crt->base.base.dev->dev_private;
283 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
284 293
285 /* CRT should always be at 0, but check anyway */ 294 /* CRT should always be at 0, but check anyway */
286 if (intel_encoder->type != INTEL_OUTPUT_ANALOG) 295 if (crt->base.type != INTEL_OUTPUT_ANALOG)
287 return false; 296 return false;
288 297
289 if (intel_crt_ddc_probe(dev_priv, dev_priv->crt_ddc_pin)) { 298 if (intel_crt_ddc_probe(dev_priv, dev_priv->crt_ddc_pin)) {
@@ -291,7 +300,7 @@ static bool intel_crt_detect_ddc(struct drm_encoder *encoder)
291 return true; 300 return true;
292 } 301 }
293 302
294 if (intel_ddc_probe(intel_encoder, dev_priv->crt_ddc_pin)) { 303 if (intel_ddc_probe(&crt->base, dev_priv->crt_ddc_pin)) {
295 DRM_DEBUG_KMS("CRT detected via DDC:0x50 [EDID]\n"); 304 DRM_DEBUG_KMS("CRT detected via DDC:0x50 [EDID]\n");
296 return true; 305 return true;
297 } 306 }
@@ -300,9 +309,9 @@ static bool intel_crt_detect_ddc(struct drm_encoder *encoder)
300} 309}
301 310
302static enum drm_connector_status 311static enum drm_connector_status
303intel_crt_load_detect(struct drm_crtc *crtc, struct intel_encoder *intel_encoder) 312intel_crt_load_detect(struct drm_crtc *crtc, struct intel_crt *crt)
304{ 313{
305 struct drm_encoder *encoder = &intel_encoder->base; 314 struct drm_encoder *encoder = &crt->base.base;
306 struct drm_device *dev = encoder->dev; 315 struct drm_device *dev = encoder->dev;
307 struct drm_i915_private *dev_priv = dev->dev_private; 316 struct drm_i915_private *dev_priv = dev->dev_private;
308 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 317 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
@@ -434,7 +443,7 @@ static enum drm_connector_status
434intel_crt_detect(struct drm_connector *connector, bool force) 443intel_crt_detect(struct drm_connector *connector, bool force)
435{ 444{
436 struct drm_device *dev = connector->dev; 445 struct drm_device *dev = connector->dev;
437 struct intel_encoder *encoder = intel_attached_encoder(connector); 446 struct intel_crt *crt = intel_attached_crt(connector);
438 struct drm_crtc *crtc; 447 struct drm_crtc *crtc;
439 int dpms_mode; 448 int dpms_mode;
440 enum drm_connector_status status; 449 enum drm_connector_status status;
@@ -443,28 +452,31 @@ intel_crt_detect(struct drm_connector *connector, bool force)
443 if (intel_crt_detect_hotplug(connector)) { 452 if (intel_crt_detect_hotplug(connector)) {
444 DRM_DEBUG_KMS("CRT detected via hotplug\n"); 453 DRM_DEBUG_KMS("CRT detected via hotplug\n");
445 return connector_status_connected; 454 return connector_status_connected;
446 } else 455 } else {
456 DRM_DEBUG_KMS("CRT not detected via hotplug\n");
447 return connector_status_disconnected; 457 return connector_status_disconnected;
458 }
448 } 459 }
449 460
450 if (intel_crt_detect_ddc(&encoder->base)) 461 if (intel_crt_detect_ddc(crt))
451 return connector_status_connected; 462 return connector_status_connected;
452 463
453 if (!force) 464 if (!force)
454 return connector->status; 465 return connector->status;
455 466
456 /* for pre-945g platforms use load detect */ 467 /* for pre-945g platforms use load detect */
457 if (encoder->base.crtc && encoder->base.crtc->enabled) { 468 crtc = crt->base.base.crtc;
458 status = intel_crt_load_detect(encoder->base.crtc, encoder); 469 if (crtc && crtc->enabled) {
470 status = intel_crt_load_detect(crtc, crt);
459 } else { 471 } else {
460 crtc = intel_get_load_detect_pipe(encoder, connector, 472 crtc = intel_get_load_detect_pipe(&crt->base, connector,
461 NULL, &dpms_mode); 473 NULL, &dpms_mode);
462 if (crtc) { 474 if (crtc) {
463 if (intel_crt_detect_ddc(&encoder->base)) 475 if (intel_crt_detect_ddc(crt))
464 status = connector_status_connected; 476 status = connector_status_connected;
465 else 477 else
466 status = intel_crt_load_detect(crtc, encoder); 478 status = intel_crt_load_detect(crtc, crt);
467 intel_release_load_detect_pipe(encoder, 479 intel_release_load_detect_pipe(&crt->base,
468 connector, dpms_mode); 480 connector, dpms_mode);
469 } else 481 } else
470 status = connector_status_unknown; 482 status = connector_status_unknown;
@@ -536,17 +548,17 @@ static const struct drm_encoder_funcs intel_crt_enc_funcs = {
536void intel_crt_init(struct drm_device *dev) 548void intel_crt_init(struct drm_device *dev)
537{ 549{
538 struct drm_connector *connector; 550 struct drm_connector *connector;
539 struct intel_encoder *intel_encoder; 551 struct intel_crt *crt;
540 struct intel_connector *intel_connector; 552 struct intel_connector *intel_connector;
541 struct drm_i915_private *dev_priv = dev->dev_private; 553 struct drm_i915_private *dev_priv = dev->dev_private;
542 554
543 intel_encoder = kzalloc(sizeof(struct intel_encoder), GFP_KERNEL); 555 crt = kzalloc(sizeof(struct intel_crt), GFP_KERNEL);
544 if (!intel_encoder) 556 if (!crt)
545 return; 557 return;
546 558
547 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); 559 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
548 if (!intel_connector) { 560 if (!intel_connector) {
549 kfree(intel_encoder); 561 kfree(crt);
550 return; 562 return;
551 } 563 }
552 564
@@ -554,20 +566,20 @@ void intel_crt_init(struct drm_device *dev)
554 drm_connector_init(dev, &intel_connector->base, 566 drm_connector_init(dev, &intel_connector->base,
555 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA); 567 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
556 568
557 drm_encoder_init(dev, &intel_encoder->base, &intel_crt_enc_funcs, 569 drm_encoder_init(dev, &crt->base.base, &intel_crt_enc_funcs,
558 DRM_MODE_ENCODER_DAC); 570 DRM_MODE_ENCODER_DAC);
559 571
560 intel_connector_attach_encoder(intel_connector, intel_encoder); 572 intel_connector_attach_encoder(intel_connector, &crt->base);
561 573
562 intel_encoder->type = INTEL_OUTPUT_ANALOG; 574 crt->base.type = INTEL_OUTPUT_ANALOG;
563 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | 575 crt->base.clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT |
564 (1 << INTEL_ANALOG_CLONE_BIT) | 576 1 << INTEL_ANALOG_CLONE_BIT |
565 (1 << INTEL_SDVO_LVDS_CLONE_BIT); 577 1 << INTEL_SDVO_LVDS_CLONE_BIT);
566 intel_encoder->crtc_mask = (1 << 0) | (1 << 1); 578 crt->base.crtc_mask = (1 << 0) | (1 << 1);
567 connector->interlace_allowed = 1; 579 connector->interlace_allowed = 1;
568 connector->doublescan_allowed = 0; 580 connector->doublescan_allowed = 0;
569 581
570 drm_encoder_helper_add(&intel_encoder->base, &intel_crt_helper_funcs); 582 drm_encoder_helper_add(&crt->base.base, &intel_crt_helper_funcs);
571 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs); 583 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
572 584
573 drm_sysfs_connector_add(connector); 585 drm_sysfs_connector_add(connector);
@@ -577,5 +589,22 @@ void intel_crt_init(struct drm_device *dev)
577 else 589 else
578 connector->polled = DRM_CONNECTOR_POLL_CONNECT; 590 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
579 591
592 /*
593 * Configure the automatic hotplug detection stuff
594 */
595 crt->force_hotplug_required = 0;
596 if (HAS_PCH_SPLIT(dev)) {
597 u32 adpa;
598
599 adpa = I915_READ(PCH_ADPA);
600 adpa &= ~ADPA_CRT_HOTPLUG_MASK;
601 adpa |= ADPA_HOTPLUG_BITS;
602 I915_WRITE(PCH_ADPA, adpa);
603 POSTING_READ(PCH_ADPA);
604
605 DRM_DEBUG_KMS("pch crt adpa set to 0x%x\n", adpa);
606 crt->force_hotplug_required = 1;
607 }
608
580 dev_priv->hotplug_supported_mask |= CRT_HOTPLUG_INT_STATUS; 609 dev_priv->hotplug_supported_mask |= CRT_HOTPLUG_INT_STATUS;
581} 610}
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 990f065374b2..d9b7092439ef 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -1611,6 +1611,18 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
1611 1611
1612 wait_event(dev_priv->pending_flip_queue, 1612 wait_event(dev_priv->pending_flip_queue,
1613 atomic_read(&obj_priv->pending_flip) == 0); 1613 atomic_read(&obj_priv->pending_flip) == 0);
1614
1615 /* Big Hammer, we also need to ensure that any pending
1616 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
1617 * current scanout is retired before unpinning the old
1618 * framebuffer.
1619 */
1620 ret = i915_gem_object_flush_gpu(obj_priv, false);
1621 if (ret) {
1622 i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
1623 mutex_unlock(&dev->struct_mutex);
1624 return ret;
1625 }
1614 } 1626 }
1615 1627
1616 ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y, 1628 ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y,
@@ -1681,6 +1693,37 @@ static void ironlake_set_pll_edp(struct drm_crtc *crtc, int clock)
1681 udelay(500); 1693 udelay(500);
1682} 1694}
1683 1695
1696static void intel_fdi_normal_train(struct drm_crtc *crtc)
1697{
1698 struct drm_device *dev = crtc->dev;
1699 struct drm_i915_private *dev_priv = dev->dev_private;
1700 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1701 int pipe = intel_crtc->pipe;
1702 u32 reg, temp;
1703
1704 /* enable normal train */
1705 reg = FDI_TX_CTL(pipe);
1706 temp = I915_READ(reg);
1707 temp &= ~FDI_LINK_TRAIN_NONE;
1708 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
1709 I915_WRITE(reg, temp);
1710
1711 reg = FDI_RX_CTL(pipe);
1712 temp = I915_READ(reg);
1713 if (HAS_PCH_CPT(dev)) {
1714 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
1715 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
1716 } else {
1717 temp &= ~FDI_LINK_TRAIN_NONE;
1718 temp |= FDI_LINK_TRAIN_NONE;
1719 }
1720 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
1721
1722 /* wait one idle pattern time */
1723 POSTING_READ(reg);
1724 udelay(1000);
1725}
1726
1684/* The FDI link training functions for ILK/Ibexpeak. */ 1727/* The FDI link training functions for ILK/Ibexpeak. */
1685static void ironlake_fdi_link_train(struct drm_crtc *crtc) 1728static void ironlake_fdi_link_train(struct drm_crtc *crtc)
1686{ 1729{
@@ -1767,27 +1810,6 @@ static void ironlake_fdi_link_train(struct drm_crtc *crtc)
1767 1810
1768 DRM_DEBUG_KMS("FDI train done\n"); 1811 DRM_DEBUG_KMS("FDI train done\n");
1769 1812
1770 /* enable normal train */
1771 reg = FDI_TX_CTL(pipe);
1772 temp = I915_READ(reg);
1773 temp &= ~FDI_LINK_TRAIN_NONE;
1774 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
1775 I915_WRITE(reg, temp);
1776
1777 reg = FDI_RX_CTL(pipe);
1778 temp = I915_READ(reg);
1779 if (HAS_PCH_CPT(dev)) {
1780 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
1781 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
1782 } else {
1783 temp &= ~FDI_LINK_TRAIN_NONE;
1784 temp |= FDI_LINK_TRAIN_NONE;
1785 }
1786 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
1787
1788 /* wait one idle pattern time */
1789 POSTING_READ(reg);
1790 udelay(1000);
1791} 1813}
1792 1814
1793static const int const snb_b_fdi_train_param [] = { 1815static const int const snb_b_fdi_train_param [] = {
@@ -2090,15 +2112,19 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
2090 I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe))); 2112 I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
2091 I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe))); 2113 I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
2092 2114
2115 intel_fdi_normal_train(crtc);
2116
2093 /* For PCH DP, enable TRANS_DP_CTL */ 2117 /* For PCH DP, enable TRANS_DP_CTL */
2094 if (HAS_PCH_CPT(dev) && 2118 if (HAS_PCH_CPT(dev) &&
2095 intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { 2119 intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
2096 reg = TRANS_DP_CTL(pipe); 2120 reg = TRANS_DP_CTL(pipe);
2097 temp = I915_READ(reg); 2121 temp = I915_READ(reg);
2098 temp &= ~(TRANS_DP_PORT_SEL_MASK | 2122 temp &= ~(TRANS_DP_PORT_SEL_MASK |
2099 TRANS_DP_SYNC_MASK); 2123 TRANS_DP_SYNC_MASK |
2124 TRANS_DP_BPC_MASK);
2100 temp |= (TRANS_DP_OUTPUT_ENABLE | 2125 temp |= (TRANS_DP_OUTPUT_ENABLE |
2101 TRANS_DP_ENH_FRAMING); 2126 TRANS_DP_ENH_FRAMING);
2127 temp |= TRANS_DP_8BPC;
2102 2128
2103 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) 2129 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
2104 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; 2130 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
@@ -2200,9 +2226,10 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
2200 udelay(100); 2226 udelay(100);
2201 2227
2202 /* Ironlake workaround, disable clock pointer after downing FDI */ 2228 /* Ironlake workaround, disable clock pointer after downing FDI */
2203 I915_WRITE(FDI_RX_CHICKEN(pipe), 2229 if (HAS_PCH_IBX(dev))
2204 I915_READ(FDI_RX_CHICKEN(pipe) & 2230 I915_WRITE(FDI_RX_CHICKEN(pipe),
2205 ~FDI_RX_PHASE_SYNC_POINTER_ENABLE)); 2231 I915_READ(FDI_RX_CHICKEN(pipe) &
2232 ~FDI_RX_PHASE_SYNC_POINTER_ENABLE));
2206 2233
2207 /* still set train pattern 1 */ 2234 /* still set train pattern 1 */
2208 reg = FDI_TX_CTL(pipe); 2235 reg = FDI_TX_CTL(pipe);
@@ -2687,27 +2714,19 @@ fdi_reduce_ratio(u32 *num, u32 *den)
2687 } 2714 }
2688} 2715}
2689 2716
2690#define DATA_N 0x800000
2691#define LINK_N 0x80000
2692
2693static void 2717static void
2694ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock, 2718ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock,
2695 int link_clock, struct fdi_m_n *m_n) 2719 int link_clock, struct fdi_m_n *m_n)
2696{ 2720{
2697 u64 temp;
2698
2699 m_n->tu = 64; /* default size */ 2721 m_n->tu = 64; /* default size */
2700 2722
2701 temp = (u64) DATA_N * pixel_clock; 2723 /* BUG_ON(pixel_clock > INT_MAX / 36); */
2702 temp = div_u64(temp, link_clock); 2724 m_n->gmch_m = bits_per_pixel * pixel_clock;
2703 m_n->gmch_m = div_u64(temp * bits_per_pixel, nlanes); 2725 m_n->gmch_n = link_clock * nlanes * 8;
2704 m_n->gmch_m >>= 3; /* convert to bytes_per_pixel */
2705 m_n->gmch_n = DATA_N;
2706 fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n); 2726 fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
2707 2727
2708 temp = (u64) LINK_N * pixel_clock; 2728 m_n->link_m = pixel_clock;
2709 m_n->link_m = div_u64(temp, link_clock); 2729 m_n->link_n = link_clock;
2710 m_n->link_n = LINK_N;
2711 fdi_reduce_ratio(&m_n->link_m, &m_n->link_n); 2730 fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
2712} 2731}
2713 2732
@@ -3691,6 +3710,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
3691 3710
3692 /* FDI link */ 3711 /* FDI link */
3693 if (HAS_PCH_SPLIT(dev)) { 3712 if (HAS_PCH_SPLIT(dev)) {
3713 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
3694 int lane = 0, link_bw, bpp; 3714 int lane = 0, link_bw, bpp;
3695 /* CPU eDP doesn't require FDI link, so just set DP M/N 3715 /* CPU eDP doesn't require FDI link, so just set DP M/N
3696 according to current link config */ 3716 according to current link config */
@@ -3774,6 +3794,8 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
3774 3794
3775 intel_crtc->fdi_lanes = lane; 3795 intel_crtc->fdi_lanes = lane;
3776 3796
3797 if (pixel_multiplier > 1)
3798 link_bw *= pixel_multiplier;
3777 ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n); 3799 ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n);
3778 } 3800 }
3779 3801
@@ -5211,6 +5233,55 @@ static const struct drm_crtc_funcs intel_crtc_funcs = {
5211 .page_flip = intel_crtc_page_flip, 5233 .page_flip = intel_crtc_page_flip,
5212}; 5234};
5213 5235
5236static void intel_sanitize_modesetting(struct drm_device *dev,
5237 int pipe, int plane)
5238{
5239 struct drm_i915_private *dev_priv = dev->dev_private;
5240 u32 reg, val;
5241
5242 if (HAS_PCH_SPLIT(dev))
5243 return;
5244
5245 /* Who knows what state these registers were left in by the BIOS or
5246 * grub?
5247 *
5248 * If we leave the registers in a conflicting state (e.g. with the
5249 * display plane reading from the other pipe than the one we intend
5250 * to use) then when we attempt to teardown the active mode, we will
5251 * not disable the pipes and planes in the correct order -- leaving
5252 * a plane reading from a disabled pipe and possibly leading to
5253 * undefined behaviour.
5254 */
5255
5256 reg = DSPCNTR(plane);
5257 val = I915_READ(reg);
5258
5259 if ((val & DISPLAY_PLANE_ENABLE) == 0)
5260 return;
5261 if (!!(val & DISPPLANE_SEL_PIPE_MASK) == pipe)
5262 return;
5263
5264 /* This display plane is active and attached to the other CPU pipe. */
5265 pipe = !pipe;
5266
5267 /* Disable the plane and wait for it to stop reading from the pipe. */
5268 I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
5269 intel_flush_display_plane(dev, plane);
5270
5271 if (IS_GEN2(dev))
5272 intel_wait_for_vblank(dev, pipe);
5273
5274 if (pipe == 0 && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
5275 return;
5276
5277 /* Switch off the pipe. */
5278 reg = PIPECONF(pipe);
5279 val = I915_READ(reg);
5280 if (val & PIPECONF_ENABLE) {
5281 I915_WRITE(reg, val & ~PIPECONF_ENABLE);
5282 intel_wait_for_pipe_off(dev, pipe);
5283 }
5284}
5214 5285
5215static void intel_crtc_init(struct drm_device *dev, int pipe) 5286static void intel_crtc_init(struct drm_device *dev, int pipe)
5216{ 5287{
@@ -5262,6 +5333,8 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
5262 5333
5263 setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer, 5334 setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
5264 (unsigned long)intel_crtc); 5335 (unsigned long)intel_crtc);
5336
5337 intel_sanitize_modesetting(dev, intel_crtc->pipe, intel_crtc->plane);
5265} 5338}
5266 5339
5267int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, 5340int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
@@ -5311,9 +5384,14 @@ static void intel_setup_outputs(struct drm_device *dev)
5311 struct drm_i915_private *dev_priv = dev->dev_private; 5384 struct drm_i915_private *dev_priv = dev->dev_private;
5312 struct intel_encoder *encoder; 5385 struct intel_encoder *encoder;
5313 bool dpd_is_edp = false; 5386 bool dpd_is_edp = false;
5387 bool has_lvds = false;
5314 5388
5315 if (IS_MOBILE(dev) && !IS_I830(dev)) 5389 if (IS_MOBILE(dev) && !IS_I830(dev))
5316 intel_lvds_init(dev); 5390 has_lvds = intel_lvds_init(dev);
5391 if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
5392 /* disable the panel fitter on everything but LVDS */
5393 I915_WRITE(PFIT_CONTROL, 0);
5394 }
5317 5395
5318 if (HAS_PCH_SPLIT(dev)) { 5396 if (HAS_PCH_SPLIT(dev)) {
5319 dpd_is_edp = intel_dpd_is_edp(dev); 5397 dpd_is_edp = intel_dpd_is_edp(dev);
@@ -5581,20 +5659,19 @@ void ironlake_enable_drps(struct drm_device *dev)
5581 fmin = (rgvmodectl & MEMMODE_FMIN_MASK); 5659 fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
5582 fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> 5660 fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
5583 MEMMODE_FSTART_SHIFT; 5661 MEMMODE_FSTART_SHIFT;
5584 fstart = fmax;
5585 5662
5586 vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> 5663 vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
5587 PXVFREQ_PX_SHIFT; 5664 PXVFREQ_PX_SHIFT;
5588 5665
5589 dev_priv->fmax = fstart; /* IPS callback will increase this */ 5666 dev_priv->fmax = fmax; /* IPS callback will increase this */
5590 dev_priv->fstart = fstart; 5667 dev_priv->fstart = fstart;
5591 5668
5592 dev_priv->max_delay = fmax; 5669 dev_priv->max_delay = fstart;
5593 dev_priv->min_delay = fmin; 5670 dev_priv->min_delay = fmin;
5594 dev_priv->cur_delay = fstart; 5671 dev_priv->cur_delay = fstart;
5595 5672
5596 DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", fmax, fmin, 5673 DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
5597 fstart); 5674 fmax, fmin, fstart);
5598 5675
5599 I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); 5676 I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
5600 5677
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 891f4f1d63b1..df648cb4c296 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -584,17 +584,6 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
584 mode->clock = dev_priv->panel_fixed_mode->clock; 584 mode->clock = dev_priv->panel_fixed_mode->clock;
585 } 585 }
586 586
587 /* Just use VBT values for eDP */
588 if (is_edp(intel_dp)) {
589 intel_dp->lane_count = dev_priv->edp.lanes;
590 intel_dp->link_bw = dev_priv->edp.rate;
591 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
592 DRM_DEBUG_KMS("eDP link bw %02x lane count %d clock %d\n",
593 intel_dp->link_bw, intel_dp->lane_count,
594 adjusted_mode->clock);
595 return true;
596 }
597
598 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { 587 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
599 for (clock = 0; clock <= max_clock; clock++) { 588 for (clock = 0; clock <= max_clock; clock++) {
600 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count); 589 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
@@ -613,6 +602,19 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
613 } 602 }
614 } 603 }
615 604
605 if (is_edp(intel_dp)) {
606 /* okay we failed just pick the highest */
607 intel_dp->lane_count = max_lane_count;
608 intel_dp->link_bw = bws[max_clock];
609 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
610 DRM_DEBUG_KMS("Force picking display port link bw %02x lane "
611 "count %d clock %d\n",
612 intel_dp->link_bw, intel_dp->lane_count,
613 adjusted_mode->clock);
614
615 return true;
616 }
617
616 return false; 618 return false;
617} 619}
618 620
@@ -1087,21 +1089,11 @@ intel_get_adjust_train(struct intel_dp *intel_dp)
1087} 1089}
1088 1090
1089static uint32_t 1091static uint32_t
1090intel_dp_signal_levels(struct intel_dp *intel_dp) 1092intel_dp_signal_levels(uint8_t train_set, int lane_count)
1091{ 1093{
1092 struct drm_device *dev = intel_dp->base.base.dev; 1094 uint32_t signal_levels = 0;
1093 struct drm_i915_private *dev_priv = dev->dev_private;
1094 uint32_t signal_levels = 0;
1095 u8 train_set = intel_dp->train_set[0];
1096 u32 vswing = train_set & DP_TRAIN_VOLTAGE_SWING_MASK;
1097 u32 preemphasis = train_set & DP_TRAIN_PRE_EMPHASIS_MASK;
1098 1095
1099 if (is_edp(intel_dp)) { 1096 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
1100 vswing = dev_priv->edp.vswing;
1101 preemphasis = dev_priv->edp.preemphasis;
1102 }
1103
1104 switch (vswing) {
1105 case DP_TRAIN_VOLTAGE_SWING_400: 1097 case DP_TRAIN_VOLTAGE_SWING_400:
1106 default: 1098 default:
1107 signal_levels |= DP_VOLTAGE_0_4; 1099 signal_levels |= DP_VOLTAGE_0_4;
@@ -1116,7 +1108,7 @@ intel_dp_signal_levels(struct intel_dp *intel_dp)
1116 signal_levels |= DP_VOLTAGE_1_2; 1108 signal_levels |= DP_VOLTAGE_1_2;
1117 break; 1109 break;
1118 } 1110 }
1119 switch (preemphasis) { 1111 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
1120 case DP_TRAIN_PRE_EMPHASIS_0: 1112 case DP_TRAIN_PRE_EMPHASIS_0:
1121 default: 1113 default:
1122 signal_levels |= DP_PRE_EMPHASIS_0; 1114 signal_levels |= DP_PRE_EMPHASIS_0;
@@ -1203,18 +1195,6 @@ intel_channel_eq_ok(struct intel_dp *intel_dp)
1203} 1195}
1204 1196
1205static bool 1197static bool
1206intel_dp_aux_handshake_required(struct intel_dp *intel_dp)
1207{
1208 struct drm_device *dev = intel_dp->base.base.dev;
1209 struct drm_i915_private *dev_priv = dev->dev_private;
1210
1211 if (is_edp(intel_dp) && dev_priv->no_aux_handshake)
1212 return false;
1213
1214 return true;
1215}
1216
1217static bool
1218intel_dp_set_link_train(struct intel_dp *intel_dp, 1198intel_dp_set_link_train(struct intel_dp *intel_dp,
1219 uint32_t dp_reg_value, 1199 uint32_t dp_reg_value,
1220 uint8_t dp_train_pat) 1200 uint8_t dp_train_pat)
@@ -1226,9 +1206,6 @@ intel_dp_set_link_train(struct intel_dp *intel_dp,
1226 I915_WRITE(intel_dp->output_reg, dp_reg_value); 1206 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1227 POSTING_READ(intel_dp->output_reg); 1207 POSTING_READ(intel_dp->output_reg);
1228 1208
1229 if (!intel_dp_aux_handshake_required(intel_dp))
1230 return true;
1231
1232 intel_dp_aux_native_write_1(intel_dp, 1209 intel_dp_aux_native_write_1(intel_dp,
1233 DP_TRAINING_PATTERN_SET, 1210 DP_TRAINING_PATTERN_SET,
1234 dp_train_pat); 1211 dp_train_pat);
@@ -1261,11 +1238,10 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1261 POSTING_READ(intel_dp->output_reg); 1238 POSTING_READ(intel_dp->output_reg);
1262 intel_wait_for_vblank(dev, intel_crtc->pipe); 1239 intel_wait_for_vblank(dev, intel_crtc->pipe);
1263 1240
1264 if (intel_dp_aux_handshake_required(intel_dp)) 1241 /* Write the link configuration data */
1265 /* Write the link configuration data */ 1242 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1266 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET, 1243 intel_dp->link_configuration,
1267 intel_dp->link_configuration, 1244 DP_LINK_CONFIGURATION_SIZE);
1268 DP_LINK_CONFIGURATION_SIZE);
1269 1245
1270 DP |= DP_PORT_EN; 1246 DP |= DP_PORT_EN;
1271 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) 1247 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
@@ -1283,7 +1259,7 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1283 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]); 1259 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
1284 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; 1260 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1285 } else { 1261 } else {
1286 signal_levels = intel_dp_signal_levels(intel_dp); 1262 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
1287 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; 1263 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1288 } 1264 }
1289 1265
@@ -1297,37 +1273,33 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1297 break; 1273 break;
1298 /* Set training pattern 1 */ 1274 /* Set training pattern 1 */
1299 1275
1300 udelay(500); 1276 udelay(100);
1301 if (intel_dp_aux_handshake_required(intel_dp)) { 1277 if (!intel_dp_get_link_status(intel_dp))
1302 break; 1278 break;
1303 } else {
1304 if (!intel_dp_get_link_status(intel_dp))
1305 break;
1306 1279
1307 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) { 1280 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1308 clock_recovery = true; 1281 clock_recovery = true;
1309 break; 1282 break;
1310 } 1283 }
1311 1284
1312 /* Check to see if we've tried the max voltage */ 1285 /* Check to see if we've tried the max voltage */
1313 for (i = 0; i < intel_dp->lane_count; i++) 1286 for (i = 0; i < intel_dp->lane_count; i++)
1314 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0) 1287 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1315 break;
1316 if (i == intel_dp->lane_count)
1317 break; 1288 break;
1289 if (i == intel_dp->lane_count)
1290 break;
1318 1291
1319 /* Check to see if we've tried the same voltage 5 times */ 1292 /* Check to see if we've tried the same voltage 5 times */
1320 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) { 1293 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
1321 ++tries; 1294 ++tries;
1322 if (tries == 5) 1295 if (tries == 5)
1323 break; 1296 break;
1324 } else 1297 } else
1325 tries = 0; 1298 tries = 0;
1326 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK; 1299 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1327 1300
1328 /* Compute new intel_dp->train_set as requested by target */ 1301 /* Compute new intel_dp->train_set as requested by target */
1329 intel_get_adjust_train(intel_dp); 1302 intel_get_adjust_train(intel_dp);
1330 }
1331 } 1303 }
1332 1304
1333 intel_dp->DP = DP; 1305 intel_dp->DP = DP;
@@ -1354,7 +1326,7 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1354 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]); 1326 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
1355 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; 1327 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1356 } else { 1328 } else {
1357 signal_levels = intel_dp_signal_levels(intel_dp); 1329 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
1358 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; 1330 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1359 } 1331 }
1360 1332
@@ -1368,28 +1340,24 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1368 DP_TRAINING_PATTERN_2)) 1340 DP_TRAINING_PATTERN_2))
1369 break; 1341 break;
1370 1342
1371 udelay(500); 1343 udelay(400);
1372 1344 if (!intel_dp_get_link_status(intel_dp))
1373 if (!intel_dp_aux_handshake_required(intel_dp)) {
1374 break; 1345 break;
1375 } else {
1376 if (!intel_dp_get_link_status(intel_dp))
1377 break;
1378 1346
1379 if (intel_channel_eq_ok(intel_dp)) { 1347 if (intel_channel_eq_ok(intel_dp)) {
1380 channel_eq = true; 1348 channel_eq = true;
1381 break; 1349 break;
1382 } 1350 }
1383 1351
1384 /* Try 5 times */ 1352 /* Try 5 times */
1385 if (tries > 5) 1353 if (tries > 5)
1386 break; 1354 break;
1387 1355
1388 /* Compute new intel_dp->train_set as requested by target */ 1356 /* Compute new intel_dp->train_set as requested by target */
1389 intel_get_adjust_train(intel_dp); 1357 intel_get_adjust_train(intel_dp);
1390 ++tries; 1358 ++tries;
1391 }
1392 } 1359 }
1360
1393 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) 1361 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
1394 reg = DP | DP_LINK_TRAIN_OFF_CPT; 1362 reg = DP | DP_LINK_TRAIN_OFF_CPT;
1395 else 1363 else
@@ -1408,6 +1376,9 @@ intel_dp_link_down(struct intel_dp *intel_dp)
1408 struct drm_i915_private *dev_priv = dev->dev_private; 1376 struct drm_i915_private *dev_priv = dev->dev_private;
1409 uint32_t DP = intel_dp->DP; 1377 uint32_t DP = intel_dp->DP;
1410 1378
1379 if ((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0)
1380 return;
1381
1411 DRM_DEBUG_KMS("\n"); 1382 DRM_DEBUG_KMS("\n");
1412 1383
1413 if (is_edp(intel_dp)) { 1384 if (is_edp(intel_dp)) {
@@ -1430,6 +1401,28 @@ intel_dp_link_down(struct intel_dp *intel_dp)
1430 1401
1431 if (is_edp(intel_dp)) 1402 if (is_edp(intel_dp))
1432 DP |= DP_LINK_TRAIN_OFF; 1403 DP |= DP_LINK_TRAIN_OFF;
1404
1405 if (!HAS_PCH_CPT(dev) &&
1406 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
1407 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc);
1408 /* Hardware workaround: leaving our transcoder select
1409 * set to transcoder B while it's off will prevent the
1410 * corresponding HDMI output on transcoder A.
1411 *
1412 * Combine this with another hardware workaround:
1413 * transcoder select bit can only be cleared while the
1414 * port is enabled.
1415 */
1416 DP &= ~DP_PIPEB_SELECT;
1417 I915_WRITE(intel_dp->output_reg, DP);
1418
1419 /* Changes to enable or select take place the vblank
1420 * after being written.
1421 */
1422 intel_wait_for_vblank(intel_dp->base.base.dev,
1423 intel_crtc->pipe);
1424 }
1425
1433 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); 1426 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
1434 POSTING_READ(intel_dp->output_reg); 1427 POSTING_READ(intel_dp->output_reg);
1435} 1428}
@@ -1517,7 +1510,7 @@ g4x_dp_detect(struct intel_dp *intel_dp)
1517 status = connector_status_connected; 1510 status = connector_status_connected;
1518 } 1511 }
1519 1512
1520 return bit; 1513 return status;
1521} 1514}
1522 1515
1523/** 1516/**
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 9af9f86a8765..e52c6125bb1f 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -237,7 +237,7 @@ extern bool intel_sdvo_init(struct drm_device *dev, int output_device);
237extern void intel_dvo_init(struct drm_device *dev); 237extern void intel_dvo_init(struct drm_device *dev);
238extern void intel_tv_init(struct drm_device *dev); 238extern void intel_tv_init(struct drm_device *dev);
239extern void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj); 239extern void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj);
240extern void intel_lvds_init(struct drm_device *dev); 240extern bool intel_lvds_init(struct drm_device *dev);
241extern void intel_dp_init(struct drm_device *dev, int dp_reg); 241extern void intel_dp_init(struct drm_device *dev, int dp_reg);
242void 242void
243intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode, 243intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
@@ -296,6 +296,7 @@ extern void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
296extern void intel_init_clock_gating(struct drm_device *dev); 296extern void intel_init_clock_gating(struct drm_device *dev);
297extern void ironlake_enable_drps(struct drm_device *dev); 297extern void ironlake_enable_drps(struct drm_device *dev);
298extern void ironlake_disable_drps(struct drm_device *dev); 298extern void ironlake_disable_drps(struct drm_device *dev);
299extern void intel_init_emon(struct drm_device *dev);
299 300
300extern int intel_pin_and_fence_fb_obj(struct drm_device *dev, 301extern int intel_pin_and_fence_fb_obj(struct drm_device *dev,
301 struct drm_gem_object *obj, 302 struct drm_gem_object *obj,
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index 2be4f728ed0c..3dba086e7eea 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -160,7 +160,7 @@ intel_gpio_create(struct drm_i915_private *dev_priv, u32 pin)
160 }; 160 };
161 struct intel_gpio *gpio; 161 struct intel_gpio *gpio;
162 162
163 if (pin < 1 || pin > 7) 163 if (pin >= ARRAY_SIZE(map_pin_to_reg) || !map_pin_to_reg[pin])
164 return NULL; 164 return NULL;
165 165
166 gpio = kzalloc(sizeof(struct intel_gpio), GFP_KERNEL); 166 gpio = kzalloc(sizeof(struct intel_gpio), GFP_KERNEL);
@@ -172,7 +172,8 @@ intel_gpio_create(struct drm_i915_private *dev_priv, u32 pin)
172 gpio->reg += PCH_GPIOA - GPIOA; 172 gpio->reg += PCH_GPIOA - GPIOA;
173 gpio->dev_priv = dev_priv; 173 gpio->dev_priv = dev_priv;
174 174
175 snprintf(gpio->adapter.name, I2C_NAME_SIZE, "GPIO%c", "?BACDEF?"[pin]); 175 snprintf(gpio->adapter.name, sizeof(gpio->adapter.name),
176 "i915 GPIO%c", "?BACDE?F"[pin]);
176 gpio->adapter.owner = THIS_MODULE; 177 gpio->adapter.owner = THIS_MODULE;
177 gpio->adapter.algo_data = &gpio->algo; 178 gpio->adapter.algo_data = &gpio->algo;
178 gpio->adapter.dev.parent = &dev_priv->dev->pdev->dev; 179 gpio->adapter.dev.parent = &dev_priv->dev->pdev->dev;
@@ -349,7 +350,7 @@ int intel_setup_gmbus(struct drm_device *dev)
349 "panel", 350 "panel",
350 "dpc", 351 "dpc",
351 "dpb", 352 "dpb",
352 "reserved" 353 "reserved",
353 "dpd", 354 "dpd",
354 }; 355 };
355 struct drm_i915_private *dev_priv = dev->dev_private; 356 struct drm_i915_private *dev_priv = dev->dev_private;
@@ -366,8 +367,8 @@ int intel_setup_gmbus(struct drm_device *dev)
366 bus->adapter.owner = THIS_MODULE; 367 bus->adapter.owner = THIS_MODULE;
367 bus->adapter.class = I2C_CLASS_DDC; 368 bus->adapter.class = I2C_CLASS_DDC;
368 snprintf(bus->adapter.name, 369 snprintf(bus->adapter.name,
369 I2C_NAME_SIZE, 370 sizeof(bus->adapter.name),
370 "gmbus %s", 371 "i915 gmbus %s",
371 names[i]); 372 names[i]);
372 373
373 bus->adapter.dev.parent = &dev->pdev->dev; 374 bus->adapter.dev.parent = &dev->pdev->dev;
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index f1a649990ea9..25bcedf386fd 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -68,7 +68,7 @@ static struct intel_lvds *intel_attached_lvds(struct drm_connector *connector)
68/** 68/**
69 * Sets the power state for the panel. 69 * Sets the power state for the panel.
70 */ 70 */
71static void intel_lvds_set_power(struct intel_lvds *intel_lvds, bool on) 71static void intel_lvds_enable(struct intel_lvds *intel_lvds)
72{ 72{
73 struct drm_device *dev = intel_lvds->base.base.dev; 73 struct drm_device *dev = intel_lvds->base.base.dev;
74 struct drm_i915_private *dev_priv = dev->dev_private; 74 struct drm_i915_private *dev_priv = dev->dev_private;
@@ -82,26 +82,61 @@ static void intel_lvds_set_power(struct intel_lvds *intel_lvds, bool on)
82 lvds_reg = LVDS; 82 lvds_reg = LVDS;
83 } 83 }
84 84
85 if (on) { 85 I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN);
86 I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN);
87 I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
88 intel_panel_set_backlight(dev, dev_priv->backlight_level);
89 } else {
90 dev_priv->backlight_level = intel_panel_get_backlight(dev);
91
92 intel_panel_set_backlight(dev, 0);
93 I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
94 86
95 if (intel_lvds->pfit_control) { 87 if (intel_lvds->pfit_dirty) {
96 if (wait_for((I915_READ(PP_STATUS) & PP_ON) == 0, 1000)) 88 /*
97 DRM_ERROR("timed out waiting for panel to power off\n"); 89 * Enable automatic panel scaling so that non-native modes
98 I915_WRITE(PFIT_CONTROL, 0); 90 * fill the screen. The panel fitter should only be
99 intel_lvds->pfit_control = 0; 91 * adjusted whilst the pipe is disabled, according to
92 * register description and PRM.
93 */
94 DRM_DEBUG_KMS("applying panel-fitter: %x, %x\n",
95 intel_lvds->pfit_control,
96 intel_lvds->pfit_pgm_ratios);
97 if (wait_for((I915_READ(PP_STATUS) & PP_ON) == 0, 1000)) {
98 DRM_ERROR("timed out waiting for panel to power off\n");
99 } else {
100 I915_WRITE(PFIT_PGM_RATIOS, intel_lvds->pfit_pgm_ratios);
101 I915_WRITE(PFIT_CONTROL, intel_lvds->pfit_control);
100 intel_lvds->pfit_dirty = false; 102 intel_lvds->pfit_dirty = false;
101 } 103 }
104 }
105
106 I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
107 POSTING_READ(lvds_reg);
108
109 intel_panel_set_backlight(dev, dev_priv->backlight_level);
110}
111
112static void intel_lvds_disable(struct intel_lvds *intel_lvds)
113{
114 struct drm_device *dev = intel_lvds->base.base.dev;
115 struct drm_i915_private *dev_priv = dev->dev_private;
116 u32 ctl_reg, lvds_reg;
117
118 if (HAS_PCH_SPLIT(dev)) {
119 ctl_reg = PCH_PP_CONTROL;
120 lvds_reg = PCH_LVDS;
121 } else {
122 ctl_reg = PP_CONTROL;
123 lvds_reg = LVDS;
124 }
125
126 dev_priv->backlight_level = intel_panel_get_backlight(dev);
127 intel_panel_set_backlight(dev, 0);
102 128
103 I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN); 129 I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
130
131 if (intel_lvds->pfit_control) {
132 if (wait_for((I915_READ(PP_STATUS) & PP_ON) == 0, 1000))
133 DRM_ERROR("timed out waiting for panel to power off\n");
134
135 I915_WRITE(PFIT_CONTROL, 0);
136 intel_lvds->pfit_dirty = true;
104 } 137 }
138
139 I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN);
105 POSTING_READ(lvds_reg); 140 POSTING_READ(lvds_reg);
106} 141}
107 142
@@ -110,9 +145,9 @@ static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
110 struct intel_lvds *intel_lvds = to_intel_lvds(encoder); 145 struct intel_lvds *intel_lvds = to_intel_lvds(encoder);
111 146
112 if (mode == DRM_MODE_DPMS_ON) 147 if (mode == DRM_MODE_DPMS_ON)
113 intel_lvds_set_power(intel_lvds, true); 148 intel_lvds_enable(intel_lvds);
114 else 149 else
115 intel_lvds_set_power(intel_lvds, false); 150 intel_lvds_disable(intel_lvds);
116 151
117 /* XXX: We never power down the LVDS pairs. */ 152 /* XXX: We never power down the LVDS pairs. */
118} 153}
@@ -411,43 +446,18 @@ static void intel_lvds_commit(struct drm_encoder *encoder)
411 /* Always do a full power on as we do not know what state 446 /* Always do a full power on as we do not know what state
412 * we were left in. 447 * we were left in.
413 */ 448 */
414 intel_lvds_set_power(intel_lvds, true); 449 intel_lvds_enable(intel_lvds);
415} 450}
416 451
417static void intel_lvds_mode_set(struct drm_encoder *encoder, 452static void intel_lvds_mode_set(struct drm_encoder *encoder,
418 struct drm_display_mode *mode, 453 struct drm_display_mode *mode,
419 struct drm_display_mode *adjusted_mode) 454 struct drm_display_mode *adjusted_mode)
420{ 455{
421 struct drm_device *dev = encoder->dev;
422 struct drm_i915_private *dev_priv = dev->dev_private;
423 struct intel_lvds *intel_lvds = to_intel_lvds(encoder);
424
425 /* 456 /*
426 * The LVDS pin pair will already have been turned on in the 457 * The LVDS pin pair will already have been turned on in the
427 * intel_crtc_mode_set since it has a large impact on the DPLL 458 * intel_crtc_mode_set since it has a large impact on the DPLL
428 * settings. 459 * settings.
429 */ 460 */
430
431 if (HAS_PCH_SPLIT(dev))
432 return;
433
434 if (!intel_lvds->pfit_dirty)
435 return;
436
437 /*
438 * Enable automatic panel scaling so that non-native modes fill the
439 * screen. Should be enabled before the pipe is enabled, according to
440 * register description and PRM.
441 */
442 DRM_DEBUG_KMS("applying panel-fitter: %x, %x\n",
443 intel_lvds->pfit_control,
444 intel_lvds->pfit_pgm_ratios);
445 if (wait_for((I915_READ(PP_STATUS) & PP_ON) == 0, 1000))
446 DRM_ERROR("timed out waiting for panel to power off\n");
447
448 I915_WRITE(PFIT_PGM_RATIOS, intel_lvds->pfit_pgm_ratios);
449 I915_WRITE(PFIT_CONTROL, intel_lvds->pfit_control);
450 intel_lvds->pfit_dirty = false;
451} 461}
452 462
453/** 463/**
@@ -481,11 +491,8 @@ static int intel_lvds_get_modes(struct drm_connector *connector)
481 struct drm_device *dev = connector->dev; 491 struct drm_device *dev = connector->dev;
482 struct drm_display_mode *mode; 492 struct drm_display_mode *mode;
483 493
484 if (intel_lvds->edid) { 494 if (intel_lvds->edid)
485 drm_mode_connector_update_edid_property(connector,
486 intel_lvds->edid);
487 return drm_add_edid_modes(connector, intel_lvds->edid); 495 return drm_add_edid_modes(connector, intel_lvds->edid);
488 }
489 496
490 mode = drm_mode_duplicate(dev, intel_lvds->fixed_mode); 497 mode = drm_mode_duplicate(dev, intel_lvds->fixed_mode);
491 if (mode == 0) 498 if (mode == 0)
@@ -840,7 +847,7 @@ static bool intel_lvds_ddc_probe(struct drm_device *dev, u8 pin)
840 * Create the connector, register the LVDS DDC bus, and try to figure out what 847 * Create the connector, register the LVDS DDC bus, and try to figure out what
841 * modes we can display on the LVDS panel (if present). 848 * modes we can display on the LVDS panel (if present).
842 */ 849 */
843void intel_lvds_init(struct drm_device *dev) 850bool intel_lvds_init(struct drm_device *dev)
844{ 851{
845 struct drm_i915_private *dev_priv = dev->dev_private; 852 struct drm_i915_private *dev_priv = dev->dev_private;
846 struct intel_lvds *intel_lvds; 853 struct intel_lvds *intel_lvds;
@@ -856,37 +863,37 @@ void intel_lvds_init(struct drm_device *dev)
856 863
857 /* Skip init on machines we know falsely report LVDS */ 864 /* Skip init on machines we know falsely report LVDS */
858 if (dmi_check_system(intel_no_lvds)) 865 if (dmi_check_system(intel_no_lvds))
859 return; 866 return false;
860 867
861 pin = GMBUS_PORT_PANEL; 868 pin = GMBUS_PORT_PANEL;
862 if (!lvds_is_present_in_vbt(dev, &pin)) { 869 if (!lvds_is_present_in_vbt(dev, &pin)) {
863 DRM_DEBUG_KMS("LVDS is not present in VBT\n"); 870 DRM_DEBUG_KMS("LVDS is not present in VBT\n");
864 return; 871 return false;
865 } 872 }
866 873
867 if (HAS_PCH_SPLIT(dev)) { 874 if (HAS_PCH_SPLIT(dev)) {
868 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0) 875 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
869 return; 876 return false;
870 if (dev_priv->edp.support) { 877 if (dev_priv->edp.support) {
871 DRM_DEBUG_KMS("disable LVDS for eDP support\n"); 878 DRM_DEBUG_KMS("disable LVDS for eDP support\n");
872 return; 879 return false;
873 } 880 }
874 } 881 }
875 882
876 if (!intel_lvds_ddc_probe(dev, pin)) { 883 if (!intel_lvds_ddc_probe(dev, pin)) {
877 DRM_DEBUG_KMS("LVDS did not respond to DDC probe\n"); 884 DRM_DEBUG_KMS("LVDS did not respond to DDC probe\n");
878 return; 885 return false;
879 } 886 }
880 887
881 intel_lvds = kzalloc(sizeof(struct intel_lvds), GFP_KERNEL); 888 intel_lvds = kzalloc(sizeof(struct intel_lvds), GFP_KERNEL);
882 if (!intel_lvds) { 889 if (!intel_lvds) {
883 return; 890 return false;
884 } 891 }
885 892
886 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); 893 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
887 if (!intel_connector) { 894 if (!intel_connector) {
888 kfree(intel_lvds); 895 kfree(intel_lvds);
889 return; 896 return false;
890 } 897 }
891 898
892 if (!HAS_PCH_SPLIT(dev)) { 899 if (!HAS_PCH_SPLIT(dev)) {
@@ -939,7 +946,16 @@ void intel_lvds_init(struct drm_device *dev)
939 */ 946 */
940 intel_lvds->edid = drm_get_edid(connector, 947 intel_lvds->edid = drm_get_edid(connector,
941 &dev_priv->gmbus[pin].adapter); 948 &dev_priv->gmbus[pin].adapter);
942 949 if (intel_lvds->edid) {
950 if (drm_add_edid_modes(connector,
951 intel_lvds->edid)) {
952 drm_mode_connector_update_edid_property(connector,
953 intel_lvds->edid);
954 } else {
955 kfree(intel_lvds->edid);
956 intel_lvds->edid = NULL;
957 }
958 }
943 if (!intel_lvds->edid) { 959 if (!intel_lvds->edid) {
944 /* Didn't get an EDID, so 960 /* Didn't get an EDID, so
945 * Set wide sync ranges so we get all modes 961 * Set wide sync ranges so we get all modes
@@ -1020,7 +1036,7 @@ out:
1020 /* keep the LVDS connector */ 1036 /* keep the LVDS connector */
1021 dev_priv->int_lvds_connector = connector; 1037 dev_priv->int_lvds_connector = connector;
1022 drm_sysfs_connector_add(connector); 1038 drm_sysfs_connector_add(connector);
1023 return; 1039 return true;
1024 1040
1025failed: 1041failed:
1026 DRM_DEBUG_KMS("No LVDS modes found, disabling.\n"); 1042 DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
@@ -1028,4 +1044,5 @@ failed:
1028 drm_encoder_cleanup(encoder); 1044 drm_encoder_cleanup(encoder);
1029 kfree(intel_lvds); 1045 kfree(intel_lvds);
1030 kfree(intel_connector); 1046 kfree(intel_connector);
1047 return false;
1031} 1048}
diff --git a/drivers/gpu/drm/i915/intel_opregion.c b/drivers/gpu/drm/i915/intel_opregion.c
index 917c7dc3cd6b..9b0d9a867aea 100644
--- a/drivers/gpu/drm/i915/intel_opregion.c
+++ b/drivers/gpu/drm/i915/intel_opregion.c
@@ -512,6 +512,6 @@ int intel_opregion_setup(struct drm_device *dev)
512 return 0; 512 return 0;
513 513
514err_out: 514err_out:
515 iounmap(opregion->header); 515 iounmap(base);
516 return err; 516 return err;
517} 517}
diff --git a/drivers/gpu/drm/i915/intel_overlay.c b/drivers/gpu/drm/i915/intel_overlay.c
index afb96d25219a..02ff0a481f47 100644
--- a/drivers/gpu/drm/i915/intel_overlay.c
+++ b/drivers/gpu/drm/i915/intel_overlay.c
@@ -946,7 +946,9 @@ static int check_overlay_src(struct drm_device *dev,
946{ 946{
947 int uv_hscale = uv_hsubsampling(rec->flags); 947 int uv_hscale = uv_hsubsampling(rec->flags);
948 int uv_vscale = uv_vsubsampling(rec->flags); 948 int uv_vscale = uv_vsubsampling(rec->flags);
949 u32 stride_mask, depth, tmp; 949 u32 stride_mask;
950 int depth;
951 u32 tmp;
950 952
951 /* check src dimensions */ 953 /* check src dimensions */
952 if (IS_845G(dev) || IS_I830(dev)) { 954 if (IS_845G(dev) || IS_I830(dev)) {
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index 09f2dc353ae2..89a65be8a3f3 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -156,28 +156,30 @@ static int init_ring_common(struct drm_device *dev,
156 156
157 /* G45 ring initialization fails to reset head to zero */ 157 /* G45 ring initialization fails to reset head to zero */
158 if (head != 0) { 158 if (head != 0) {
159 DRM_ERROR("%s head not reset to zero " 159 DRM_DEBUG_KMS("%s head not reset to zero "
160 "ctl %08x head %08x tail %08x start %08x\n", 160 "ctl %08x head %08x tail %08x start %08x\n",
161 ring->name, 161 ring->name,
162 I915_READ_CTL(ring), 162 I915_READ_CTL(ring),
163 I915_READ_HEAD(ring), 163 I915_READ_HEAD(ring),
164 I915_READ_TAIL(ring), 164 I915_READ_TAIL(ring),
165 I915_READ_START(ring)); 165 I915_READ_START(ring));
166 166
167 I915_WRITE_HEAD(ring, 0); 167 I915_WRITE_HEAD(ring, 0);
168 168
169 DRM_ERROR("%s head forced to zero " 169 if (I915_READ_HEAD(ring) & HEAD_ADDR) {
170 "ctl %08x head %08x tail %08x start %08x\n", 170 DRM_ERROR("failed to set %s head to zero "
171 ring->name, 171 "ctl %08x head %08x tail %08x start %08x\n",
172 I915_READ_CTL(ring), 172 ring->name,
173 I915_READ_HEAD(ring), 173 I915_READ_CTL(ring),
174 I915_READ_TAIL(ring), 174 I915_READ_HEAD(ring),
175 I915_READ_START(ring)); 175 I915_READ_TAIL(ring),
176 I915_READ_START(ring));
177 }
176 } 178 }
177 179
178 I915_WRITE_CTL(ring, 180 I915_WRITE_CTL(ring,
179 ((ring->gem_object->size - PAGE_SIZE) & RING_NR_PAGES) 181 ((ring->gem_object->size - PAGE_SIZE) & RING_NR_PAGES)
180 | RING_NO_REPORT | RING_VALID); 182 | RING_REPORT_64K | RING_VALID);
181 183
182 head = I915_READ_HEAD(ring) & HEAD_ADDR; 184 head = I915_READ_HEAD(ring) & HEAD_ADDR;
183 /* If the head is still not zero, the ring is dead */ 185 /* If the head is still not zero, the ring is dead */
@@ -654,6 +656,10 @@ void intel_cleanup_ring_buffer(struct drm_device *dev,
654 i915_gem_object_unpin(ring->gem_object); 656 i915_gem_object_unpin(ring->gem_object);
655 drm_gem_object_unreference(ring->gem_object); 657 drm_gem_object_unreference(ring->gem_object);
656 ring->gem_object = NULL; 658 ring->gem_object = NULL;
659
660 if (ring->cleanup)
661 ring->cleanup(ring);
662
657 cleanup_status_page(dev, ring); 663 cleanup_status_page(dev, ring);
658} 664}
659 665
@@ -688,6 +694,17 @@ int intel_wait_ring_buffer(struct drm_device *dev,
688{ 694{
689 unsigned long end; 695 unsigned long end;
690 drm_i915_private_t *dev_priv = dev->dev_private; 696 drm_i915_private_t *dev_priv = dev->dev_private;
697 u32 head;
698
699 head = intel_read_status_page(ring, 4);
700 if (head) {
701 ring->head = head & HEAD_ADDR;
702 ring->space = ring->head - (ring->tail + 8);
703 if (ring->space < 0)
704 ring->space += ring->size;
705 if (ring->space >= n)
706 return 0;
707 }
691 708
692 trace_i915_ring_wait_begin (dev); 709 trace_i915_ring_wait_begin (dev);
693 end = jiffies + 3 * HZ; 710 end = jiffies + 3 * HZ;
@@ -854,19 +871,125 @@ blt_ring_put_user_irq(struct drm_device *dev,
854 /* do nothing */ 871 /* do nothing */
855} 872}
856 873
874
875/* Workaround for some stepping of SNB,
876 * each time when BLT engine ring tail moved,
877 * the first command in the ring to be parsed
878 * should be MI_BATCH_BUFFER_START
879 */
880#define NEED_BLT_WORKAROUND(dev) \
881 (IS_GEN6(dev) && (dev->pdev->revision < 8))
882
883static inline struct drm_i915_gem_object *
884to_blt_workaround(struct intel_ring_buffer *ring)
885{
886 return ring->private;
887}
888
889static int blt_ring_init(struct drm_device *dev,
890 struct intel_ring_buffer *ring)
891{
892 if (NEED_BLT_WORKAROUND(dev)) {
893 struct drm_i915_gem_object *obj;
894 u32 __iomem *ptr;
895 int ret;
896
897 obj = to_intel_bo(i915_gem_alloc_object(dev, 4096));
898 if (obj == NULL)
899 return -ENOMEM;
900
901 ret = i915_gem_object_pin(&obj->base, 4096);
902 if (ret) {
903 drm_gem_object_unreference(&obj->base);
904 return ret;
905 }
906
907 ptr = kmap(obj->pages[0]);
908 iowrite32(MI_BATCH_BUFFER_END, ptr);
909 iowrite32(MI_NOOP, ptr+1);
910 kunmap(obj->pages[0]);
911
912 ret = i915_gem_object_set_to_gtt_domain(&obj->base, false);
913 if (ret) {
914 i915_gem_object_unpin(&obj->base);
915 drm_gem_object_unreference(&obj->base);
916 return ret;
917 }
918
919 ring->private = obj;
920 }
921
922 return init_ring_common(dev, ring);
923}
924
925static void blt_ring_begin(struct drm_device *dev,
926 struct intel_ring_buffer *ring,
927 int num_dwords)
928{
929 if (ring->private) {
930 intel_ring_begin(dev, ring, num_dwords+2);
931 intel_ring_emit(dev, ring, MI_BATCH_BUFFER_START);
932 intel_ring_emit(dev, ring, to_blt_workaround(ring)->gtt_offset);
933 } else
934 intel_ring_begin(dev, ring, 4);
935}
936
937static void blt_ring_flush(struct drm_device *dev,
938 struct intel_ring_buffer *ring,
939 u32 invalidate_domains,
940 u32 flush_domains)
941{
942 blt_ring_begin(dev, ring, 4);
943 intel_ring_emit(dev, ring, MI_FLUSH_DW);
944 intel_ring_emit(dev, ring, 0);
945 intel_ring_emit(dev, ring, 0);
946 intel_ring_emit(dev, ring, 0);
947 intel_ring_advance(dev, ring);
948}
949
950static u32
951blt_ring_add_request(struct drm_device *dev,
952 struct intel_ring_buffer *ring,
953 u32 flush_domains)
954{
955 u32 seqno = i915_gem_get_seqno(dev);
956
957 blt_ring_begin(dev, ring, 4);
958 intel_ring_emit(dev, ring, MI_STORE_DWORD_INDEX);
959 intel_ring_emit(dev, ring,
960 I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
961 intel_ring_emit(dev, ring, seqno);
962 intel_ring_emit(dev, ring, MI_USER_INTERRUPT);
963 intel_ring_advance(dev, ring);
964
965 DRM_DEBUG_DRIVER("%s %d\n", ring->name, seqno);
966 return seqno;
967}
968
969static void blt_ring_cleanup(struct intel_ring_buffer *ring)
970{
971 if (!ring->private)
972 return;
973
974 i915_gem_object_unpin(ring->private);
975 drm_gem_object_unreference(ring->private);
976 ring->private = NULL;
977}
978
857static const struct intel_ring_buffer gen6_blt_ring = { 979static const struct intel_ring_buffer gen6_blt_ring = {
858 .name = "blt ring", 980 .name = "blt ring",
859 .id = RING_BLT, 981 .id = RING_BLT,
860 .mmio_base = BLT_RING_BASE, 982 .mmio_base = BLT_RING_BASE,
861 .size = 32 * PAGE_SIZE, 983 .size = 32 * PAGE_SIZE,
862 .init = init_ring_common, 984 .init = blt_ring_init,
863 .write_tail = ring_write_tail, 985 .write_tail = ring_write_tail,
864 .flush = gen6_ring_flush, 986 .flush = blt_ring_flush,
865 .add_request = ring_add_request, 987 .add_request = blt_ring_add_request,
866 .get_seqno = ring_status_page_get_seqno, 988 .get_seqno = ring_status_page_get_seqno,
867 .user_irq_get = blt_ring_get_user_irq, 989 .user_irq_get = blt_ring_get_user_irq,
868 .user_irq_put = blt_ring_put_user_irq, 990 .user_irq_put = blt_ring_put_user_irq,
869 .dispatch_gem_execbuffer = gen6_ring_dispatch_gem_execbuffer, 991 .dispatch_gem_execbuffer = gen6_ring_dispatch_gem_execbuffer,
992 .cleanup = blt_ring_cleanup,
870}; 993};
871 994
872int intel_init_render_ring_buffer(struct drm_device *dev) 995int intel_init_render_ring_buffer(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index a05aff0e5764..3126c2681983 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -63,6 +63,7 @@ struct intel_ring_buffer {
63 struct drm_i915_gem_execbuffer2 *exec, 63 struct drm_i915_gem_execbuffer2 *exec,
64 struct drm_clip_rect *cliprects, 64 struct drm_clip_rect *cliprects,
65 uint64_t exec_offset); 65 uint64_t exec_offset);
66 void (*cleanup)(struct intel_ring_buffer *ring);
66 67
67 /** 68 /**
68 * List of objects currently involved in rendering from the 69 * List of objects currently involved in rendering from the
@@ -98,6 +99,8 @@ struct intel_ring_buffer {
98 99
99 wait_queue_head_t irq_queue; 100 wait_queue_head_t irq_queue;
100 drm_local_map_t map; 101 drm_local_map_t map;
102
103 void *private;
101}; 104};
102 105
103static inline u32 106static inline u32
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index de158b76bcd5..d97e6cb52d34 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -107,7 +107,8 @@ struct intel_sdvo {
107 * This is set if we treat the device as HDMI, instead of DVI. 107 * This is set if we treat the device as HDMI, instead of DVI.
108 */ 108 */
109 bool is_hdmi; 109 bool is_hdmi;
110 bool has_audio; 110 bool has_hdmi_monitor;
111 bool has_hdmi_audio;
111 112
112 /** 113 /**
113 * This is set if we detect output of sdvo device as LVDS and 114 * This is set if we detect output of sdvo device as LVDS and
@@ -1023,7 +1024,7 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1023 if (!intel_sdvo_set_target_input(intel_sdvo)) 1024 if (!intel_sdvo_set_target_input(intel_sdvo))
1024 return; 1025 return;
1025 1026
1026 if (intel_sdvo->is_hdmi && 1027 if (intel_sdvo->has_hdmi_monitor &&
1027 !intel_sdvo_set_avi_infoframe(intel_sdvo)) 1028 !intel_sdvo_set_avi_infoframe(intel_sdvo))
1028 return; 1029 return;
1029 1030
@@ -1063,7 +1064,7 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1063 } 1064 }
1064 if (intel_crtc->pipe == 1) 1065 if (intel_crtc->pipe == 1)
1065 sdvox |= SDVO_PIPE_B_SELECT; 1066 sdvox |= SDVO_PIPE_B_SELECT;
1066 if (intel_sdvo->has_audio) 1067 if (intel_sdvo->has_hdmi_audio)
1067 sdvox |= SDVO_AUDIO_ENABLE; 1068 sdvox |= SDVO_AUDIO_ENABLE;
1068 1069
1069 if (INTEL_INFO(dev)->gen >= 4) { 1070 if (INTEL_INFO(dev)->gen >= 4) {
@@ -1295,55 +1296,14 @@ intel_sdvo_get_edid(struct drm_connector *connector)
1295 return drm_get_edid(connector, &sdvo->ddc); 1296 return drm_get_edid(connector, &sdvo->ddc);
1296} 1297}
1297 1298
1298static struct drm_connector *
1299intel_find_analog_connector(struct drm_device *dev)
1300{
1301 struct drm_connector *connector;
1302 struct intel_sdvo *encoder;
1303
1304 list_for_each_entry(encoder,
1305 &dev->mode_config.encoder_list,
1306 base.base.head) {
1307 if (encoder->base.type == INTEL_OUTPUT_ANALOG) {
1308 list_for_each_entry(connector,
1309 &dev->mode_config.connector_list,
1310 head) {
1311 if (&encoder->base ==
1312 intel_attached_encoder(connector))
1313 return connector;
1314 }
1315 }
1316 }
1317
1318 return NULL;
1319}
1320
1321static int
1322intel_analog_is_connected(struct drm_device *dev)
1323{
1324 struct drm_connector *analog_connector;
1325
1326 analog_connector = intel_find_analog_connector(dev);
1327 if (!analog_connector)
1328 return false;
1329
1330 if (analog_connector->funcs->detect(analog_connector, false) ==
1331 connector_status_disconnected)
1332 return false;
1333
1334 return true;
1335}
1336
1337/* Mac mini hack -- use the same DDC as the analog connector */ 1299/* Mac mini hack -- use the same DDC as the analog connector */
1338static struct edid * 1300static struct edid *
1339intel_sdvo_get_analog_edid(struct drm_connector *connector) 1301intel_sdvo_get_analog_edid(struct drm_connector *connector)
1340{ 1302{
1341 struct drm_i915_private *dev_priv = connector->dev->dev_private; 1303 struct drm_i915_private *dev_priv = connector->dev->dev_private;
1342 1304
1343 if (!intel_analog_is_connected(connector->dev)) 1305 return drm_get_edid(connector,
1344 return NULL; 1306 &dev_priv->gmbus[dev_priv->crt_ddc_pin].adapter);
1345
1346 return drm_get_edid(connector, &dev_priv->gmbus[dev_priv->crt_ddc_pin].adapter);
1347} 1307}
1348 1308
1349enum drm_connector_status 1309enum drm_connector_status
@@ -1388,8 +1348,10 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
1388 /* DDC bus is shared, match EDID to connector type */ 1348 /* DDC bus is shared, match EDID to connector type */
1389 if (edid->input & DRM_EDID_INPUT_DIGITAL) { 1349 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
1390 status = connector_status_connected; 1350 status = connector_status_connected;
1391 intel_sdvo->is_hdmi = drm_detect_hdmi_monitor(edid); 1351 if (intel_sdvo->is_hdmi) {
1392 intel_sdvo->has_audio = drm_detect_monitor_audio(edid); 1352 intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid);
1353 intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid);
1354 }
1393 } 1355 }
1394 connector->display_info.raw_edid = NULL; 1356 connector->display_info.raw_edid = NULL;
1395 kfree(edid); 1357 kfree(edid);
@@ -1398,7 +1360,7 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
1398 if (status == connector_status_connected) { 1360 if (status == connector_status_connected) {
1399 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); 1361 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
1400 if (intel_sdvo_connector->force_audio) 1362 if (intel_sdvo_connector->force_audio)
1401 intel_sdvo->has_audio = intel_sdvo_connector->force_audio > 0; 1363 intel_sdvo->has_hdmi_audio = intel_sdvo_connector->force_audio > 0;
1402 } 1364 }
1403 1365
1404 return status; 1366 return status;
@@ -1415,10 +1377,12 @@ intel_sdvo_detect(struct drm_connector *connector, bool force)
1415 if (!intel_sdvo_write_cmd(intel_sdvo, 1377 if (!intel_sdvo_write_cmd(intel_sdvo,
1416 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0)) 1378 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0))
1417 return connector_status_unknown; 1379 return connector_status_unknown;
1418 if (intel_sdvo->is_tv) { 1380
1419 /* add 30ms delay when the output type is SDVO-TV */ 1381 /* add 30ms delay when the output type might be TV */
1382 if (intel_sdvo->caps.output_flags &
1383 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_CVBS0))
1420 mdelay(30); 1384 mdelay(30);
1421 } 1385
1422 if (!intel_sdvo_read_response(intel_sdvo, &response, 2)) 1386 if (!intel_sdvo_read_response(intel_sdvo, &response, 2))
1423 return connector_status_unknown; 1387 return connector_status_unknown;
1424 1388
@@ -1472,8 +1436,10 @@ static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
1472 edid = intel_sdvo_get_analog_edid(connector); 1436 edid = intel_sdvo_get_analog_edid(connector);
1473 1437
1474 if (edid != NULL) { 1438 if (edid != NULL) {
1475 drm_mode_connector_update_edid_property(connector, edid); 1439 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
1476 drm_add_edid_modes(connector, edid); 1440 drm_mode_connector_update_edid_property(connector, edid);
1441 drm_add_edid_modes(connector, edid);
1442 }
1477 connector->display_info.raw_edid = NULL; 1443 connector->display_info.raw_edid = NULL;
1478 kfree(edid); 1444 kfree(edid);
1479 } 1445 }
@@ -1713,12 +1679,12 @@ intel_sdvo_set_property(struct drm_connector *connector,
1713 1679
1714 intel_sdvo_connector->force_audio = val; 1680 intel_sdvo_connector->force_audio = val;
1715 1681
1716 if (val > 0 && intel_sdvo->has_audio) 1682 if (val > 0 && intel_sdvo->has_hdmi_audio)
1717 return 0; 1683 return 0;
1718 if (val < 0 && !intel_sdvo->has_audio) 1684 if (val < 0 && !intel_sdvo->has_hdmi_audio)
1719 return 0; 1685 return 0;
1720 1686
1721 intel_sdvo->has_audio = val > 0; 1687 intel_sdvo->has_hdmi_audio = val > 0;
1722 goto done; 1688 goto done;
1723 } 1689 }
1724 1690
@@ -2070,6 +2036,8 @@ intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
2070 intel_sdvo_set_colorimetry(intel_sdvo, 2036 intel_sdvo_set_colorimetry(intel_sdvo,
2071 SDVO_COLORIMETRY_RGB256); 2037 SDVO_COLORIMETRY_RGB256);
2072 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; 2038 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2039
2040 intel_sdvo_add_hdmi_properties(intel_sdvo_connector);
2073 intel_sdvo->is_hdmi = true; 2041 intel_sdvo->is_hdmi = true;
2074 } 2042 }
2075 intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | 2043 intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
@@ -2077,8 +2045,6 @@ intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
2077 2045
2078 intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo); 2046 intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
2079 2047
2080 intel_sdvo_add_hdmi_properties(intel_sdvo_connector);
2081
2082 return true; 2048 return true;
2083} 2049}
2084 2050
diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c b/drivers/gpu/drm/nouveau/nouveau_backlight.c
index 8933e985c227..d3a9c6e02477 100644
--- a/drivers/gpu/drm/nouveau/nouveau_backlight.c
+++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c
@@ -31,6 +31,7 @@
31 */ 31 */
32 32
33#include <linux/backlight.h> 33#include <linux/backlight.h>
34#include <linux/acpi.h>
34 35
35#include "drmP.h" 36#include "drmP.h"
36#include "nouveau_drv.h" 37#include "nouveau_drv.h"
@@ -136,6 +137,14 @@ int nouveau_backlight_init(struct drm_device *dev)
136{ 137{
137 struct drm_nouveau_private *dev_priv = dev->dev_private; 138 struct drm_nouveau_private *dev_priv = dev->dev_private;
138 139
140#ifdef CONFIG_ACPI
141 if (acpi_video_backlight_support()) {
142 NV_INFO(dev, "ACPI backlight interface available, "
143 "not registering our own\n");
144 return 0;
145 }
146#endif
147
139 switch (dev_priv->card_type) { 148 switch (dev_priv->card_type) {
140 case NV_40: 149 case NV_40:
141 return nouveau_nv40_backlight_init(dev); 150 return nouveau_nv40_backlight_init(dev);
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index 5f21030a293b..b2293576f278 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -6829,7 +6829,7 @@ nouveau_bios_posted(struct drm_device *dev)
6829 struct drm_nouveau_private *dev_priv = dev->dev_private; 6829 struct drm_nouveau_private *dev_priv = dev->dev_private;
6830 unsigned htotal; 6830 unsigned htotal;
6831 6831
6832 if (dev_priv->chipset >= NV_50) { 6832 if (dev_priv->card_type >= NV_50) {
6833 if (NVReadVgaCrtc(dev, 0, 0x00) == 0 && 6833 if (NVReadVgaCrtc(dev, 0, 0x00) == 0 &&
6834 NVReadVgaCrtc(dev, 0, 0x1a) == 0) 6834 NVReadVgaCrtc(dev, 0, 0x1a) == 0)
6835 return false; 6835 return false;
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 80353e2b8409..c41e1c200ef5 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -143,8 +143,10 @@ nouveau_bo_new(struct drm_device *dev, struct nouveau_channel *chan,
143 nvbo->no_vm = no_vm; 143 nvbo->no_vm = no_vm;
144 nvbo->tile_mode = tile_mode; 144 nvbo->tile_mode = tile_mode;
145 nvbo->tile_flags = tile_flags; 145 nvbo->tile_flags = tile_flags;
146 nvbo->bo.bdev = &dev_priv->ttm.bdev;
146 147
147 nouveau_bo_fixup_align(dev, tile_mode, tile_flags, &align, &size); 148 nouveau_bo_fixup_align(dev, tile_mode, nouveau_bo_tile_layout(nvbo),
149 &align, &size);
148 align >>= PAGE_SHIFT; 150 align >>= PAGE_SHIFT;
149 151
150 nouveau_bo_placement_set(nvbo, flags, 0); 152 nouveau_bo_placement_set(nvbo, flags, 0);
@@ -176,6 +178,31 @@ set_placement_list(uint32_t *pl, unsigned *n, uint32_t type, uint32_t flags)
176 pl[(*n)++] = TTM_PL_FLAG_SYSTEM | flags; 178 pl[(*n)++] = TTM_PL_FLAG_SYSTEM | flags;
177} 179}
178 180
181static void
182set_placement_range(struct nouveau_bo *nvbo, uint32_t type)
183{
184 struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev);
185
186 if (dev_priv->card_type == NV_10 &&
187 nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM)) {
188 /*
189 * Make sure that the color and depth buffers are handled
190 * by independent memory controller units. Up to a 9x
191 * speed up when alpha-blending and depth-test are enabled
192 * at the same time.
193 */
194 int vram_pages = dev_priv->vram_size >> PAGE_SHIFT;
195
196 if (nvbo->tile_flags & NOUVEAU_GEM_TILE_ZETA) {
197 nvbo->placement.fpfn = vram_pages / 2;
198 nvbo->placement.lpfn = ~0;
199 } else {
200 nvbo->placement.fpfn = 0;
201 nvbo->placement.lpfn = vram_pages / 2;
202 }
203 }
204}
205
179void 206void
180nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy) 207nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy)
181{ 208{
@@ -190,6 +217,8 @@ nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy)
190 pl->busy_placement = nvbo->busy_placements; 217 pl->busy_placement = nvbo->busy_placements;
191 set_placement_list(nvbo->busy_placements, &pl->num_busy_placement, 218 set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
192 type | busy, flags); 219 type | busy, flags);
220
221 set_placement_range(nvbo, type);
193} 222}
194 223
195int 224int
@@ -525,7 +554,8 @@ nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
525 stride = 16 * 4; 554 stride = 16 * 4;
526 height = amount / stride; 555 height = amount / stride;
527 556
528 if (new_mem->mem_type == TTM_PL_VRAM && nvbo->tile_flags) { 557 if (new_mem->mem_type == TTM_PL_VRAM &&
558 nouveau_bo_tile_layout(nvbo)) {
529 ret = RING_SPACE(chan, 8); 559 ret = RING_SPACE(chan, 8);
530 if (ret) 560 if (ret)
531 return ret; 561 return ret;
@@ -546,7 +576,8 @@ nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo,
546 BEGIN_RING(chan, NvSubM2MF, 0x0200, 1); 576 BEGIN_RING(chan, NvSubM2MF, 0x0200, 1);
547 OUT_RING (chan, 1); 577 OUT_RING (chan, 1);
548 } 578 }
549 if (old_mem->mem_type == TTM_PL_VRAM && nvbo->tile_flags) { 579 if (old_mem->mem_type == TTM_PL_VRAM &&
580 nouveau_bo_tile_layout(nvbo)) {
550 ret = RING_SPACE(chan, 8); 581 ret = RING_SPACE(chan, 8);
551 if (ret) 582 if (ret)
552 return ret; 583 return ret;
@@ -753,7 +784,8 @@ nouveau_bo_vm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem,
753 if (dev_priv->card_type == NV_50) { 784 if (dev_priv->card_type == NV_50) {
754 ret = nv50_mem_vm_bind_linear(dev, 785 ret = nv50_mem_vm_bind_linear(dev,
755 offset + dev_priv->vm_vram_base, 786 offset + dev_priv->vm_vram_base,
756 new_mem->size, nvbo->tile_flags, 787 new_mem->size,
788 nouveau_bo_tile_layout(nvbo),
757 offset); 789 offset);
758 if (ret) 790 if (ret)
759 return ret; 791 return ret;
@@ -894,7 +926,8 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
894 * nothing to do here. 926 * nothing to do here.
895 */ 927 */
896 if (bo->mem.mem_type != TTM_PL_VRAM) { 928 if (bo->mem.mem_type != TTM_PL_VRAM) {
897 if (dev_priv->card_type < NV_50 || !nvbo->tile_flags) 929 if (dev_priv->card_type < NV_50 ||
930 !nouveau_bo_tile_layout(nvbo))
898 return 0; 931 return 0;
899 } 932 }
900 933
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index 0871495096fa..52c356e9a3d1 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -281,7 +281,7 @@ detect_analog:
281 nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG); 281 nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG);
282 if (!nv_encoder && !nouveau_tv_disable) 282 if (!nv_encoder && !nouveau_tv_disable)
283 nv_encoder = find_encoder_by_type(connector, OUTPUT_TV); 283 nv_encoder = find_encoder_by_type(connector, OUTPUT_TV);
284 if (nv_encoder) { 284 if (nv_encoder && force) {
285 struct drm_encoder *encoder = to_drm_encoder(nv_encoder); 285 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
286 struct drm_encoder_helper_funcs *helper = 286 struct drm_encoder_helper_funcs *helper =
287 encoder->helper_private; 287 encoder->helper_private;
@@ -641,11 +641,28 @@ nouveau_connector_get_modes(struct drm_connector *connector)
641 return ret; 641 return ret;
642} 642}
643 643
644static unsigned
645get_tmds_link_bandwidth(struct drm_connector *connector)
646{
647 struct nouveau_connector *nv_connector = nouveau_connector(connector);
648 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
649 struct dcb_entry *dcb = nv_connector->detected_encoder->dcb;
650
651 if (dcb->location != DCB_LOC_ON_CHIP ||
652 dev_priv->chipset >= 0x46)
653 return 165000;
654 else if (dev_priv->chipset >= 0x40)
655 return 155000;
656 else if (dev_priv->chipset >= 0x18)
657 return 135000;
658 else
659 return 112000;
660}
661
644static int 662static int
645nouveau_connector_mode_valid(struct drm_connector *connector, 663nouveau_connector_mode_valid(struct drm_connector *connector,
646 struct drm_display_mode *mode) 664 struct drm_display_mode *mode)
647{ 665{
648 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
649 struct nouveau_connector *nv_connector = nouveau_connector(connector); 666 struct nouveau_connector *nv_connector = nouveau_connector(connector);
650 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; 667 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
651 struct drm_encoder *encoder = to_drm_encoder(nv_encoder); 668 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
@@ -663,11 +680,9 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
663 max_clock = 400000; 680 max_clock = 400000;
664 break; 681 break;
665 case OUTPUT_TMDS: 682 case OUTPUT_TMDS:
666 if ((dev_priv->card_type >= NV_50 && !nouveau_duallink) || 683 max_clock = get_tmds_link_bandwidth(connector);
667 !nv_encoder->dcb->duallink_possible) 684 if (nouveau_duallink && nv_encoder->dcb->duallink_possible)
668 max_clock = 165000; 685 max_clock *= 2;
669 else
670 max_clock = 330000;
671 break; 686 break;
672 case OUTPUT_ANALOG: 687 case OUTPUT_ANALOG:
673 max_clock = nv_encoder->dcb->crtconf.maxfreq; 688 max_clock = nv_encoder->dcb->crtconf.maxfreq;
@@ -709,44 +724,6 @@ nouveau_connector_best_encoder(struct drm_connector *connector)
709 return NULL; 724 return NULL;
710} 725}
711 726
712void
713nouveau_connector_set_polling(struct drm_connector *connector)
714{
715 struct drm_device *dev = connector->dev;
716 struct drm_nouveau_private *dev_priv = dev->dev_private;
717 struct drm_crtc *crtc;
718 bool spare_crtc = false;
719
720 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
721 spare_crtc |= !crtc->enabled;
722
723 connector->polled = 0;
724
725 switch (connector->connector_type) {
726 case DRM_MODE_CONNECTOR_VGA:
727 case DRM_MODE_CONNECTOR_TV:
728 if (dev_priv->card_type >= NV_50 ||
729 (nv_gf4_disp_arch(dev) && spare_crtc))
730 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
731 break;
732
733 case DRM_MODE_CONNECTOR_DVII:
734 case DRM_MODE_CONNECTOR_DVID:
735 case DRM_MODE_CONNECTOR_HDMIA:
736 case DRM_MODE_CONNECTOR_DisplayPort:
737 case DRM_MODE_CONNECTOR_eDP:
738 if (dev_priv->card_type >= NV_50)
739 connector->polled = DRM_CONNECTOR_POLL_HPD;
740 else if (connector->connector_type == DRM_MODE_CONNECTOR_DVID ||
741 spare_crtc)
742 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
743 break;
744
745 default:
746 break;
747 }
748}
749
750static const struct drm_connector_helper_funcs 727static const struct drm_connector_helper_funcs
751nouveau_connector_helper_funcs = { 728nouveau_connector_helper_funcs = {
752 .get_modes = nouveau_connector_get_modes, 729 .get_modes = nouveau_connector_get_modes,
@@ -872,6 +849,7 @@ nouveau_connector_create(struct drm_device *dev, int index)
872 dev->mode_config.scaling_mode_property, 849 dev->mode_config.scaling_mode_property,
873 nv_connector->scaling_mode); 850 nv_connector->scaling_mode);
874 } 851 }
852 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
875 /* fall-through */ 853 /* fall-through */
876 case DCB_CONNECTOR_TV_0: 854 case DCB_CONNECTOR_TV_0:
877 case DCB_CONNECTOR_TV_1: 855 case DCB_CONNECTOR_TV_1:
@@ -888,11 +866,16 @@ nouveau_connector_create(struct drm_device *dev, int index)
888 dev->mode_config.dithering_mode_property, 866 dev->mode_config.dithering_mode_property,
889 nv_connector->use_dithering ? 867 nv_connector->use_dithering ?
890 DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF); 868 DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF);
869
870 if (dcb->type != DCB_CONNECTOR_LVDS) {
871 if (dev_priv->card_type >= NV_50)
872 connector->polled = DRM_CONNECTOR_POLL_HPD;
873 else
874 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
875 }
891 break; 876 break;
892 } 877 }
893 878
894 nouveau_connector_set_polling(connector);
895
896 drm_sysfs_connector_add(connector); 879 drm_sysfs_connector_add(connector);
897 dcb->drm = connector; 880 dcb->drm = connector;
898 return dcb->drm; 881 return dcb->drm;
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.h b/drivers/gpu/drm/nouveau/nouveau_connector.h
index c21ed6b16f88..711b1e9203af 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.h
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.h
@@ -52,9 +52,6 @@ static inline struct nouveau_connector *nouveau_connector(
52struct drm_connector * 52struct drm_connector *
53nouveau_connector_create(struct drm_device *, int index); 53nouveau_connector_create(struct drm_device *, int index);
54 54
55void
56nouveau_connector_set_polling(struct drm_connector *);
57
58int 55int
59nouveau_connector_bpp(struct drm_connector *); 56nouveau_connector_bpp(struct drm_connector *);
60 57
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index 3a07e580d27a..1c7db64c03bf 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -100,6 +100,9 @@ struct nouveau_bo {
100 int pin_refcnt; 100 int pin_refcnt;
101}; 101};
102 102
103#define nouveau_bo_tile_layout(nvbo) \
104 ((nvbo)->tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK)
105
103static inline struct nouveau_bo * 106static inline struct nouveau_bo *
104nouveau_bo(struct ttm_buffer_object *bo) 107nouveau_bo(struct ttm_buffer_object *bo)
105{ 108{
@@ -304,6 +307,7 @@ struct nouveau_fifo_engine {
304 void (*destroy_context)(struct nouveau_channel *); 307 void (*destroy_context)(struct nouveau_channel *);
305 int (*load_context)(struct nouveau_channel *); 308 int (*load_context)(struct nouveau_channel *);
306 int (*unload_context)(struct drm_device *); 309 int (*unload_context)(struct drm_device *);
310 void (*tlb_flush)(struct drm_device *dev);
307}; 311};
308 312
309struct nouveau_pgraph_object_method { 313struct nouveau_pgraph_object_method {
@@ -336,6 +340,7 @@ struct nouveau_pgraph_engine {
336 void (*destroy_context)(struct nouveau_channel *); 340 void (*destroy_context)(struct nouveau_channel *);
337 int (*load_context)(struct nouveau_channel *); 341 int (*load_context)(struct nouveau_channel *);
338 int (*unload_context)(struct drm_device *); 342 int (*unload_context)(struct drm_device *);
343 void (*tlb_flush)(struct drm_device *dev);
339 344
340 void (*set_region_tiling)(struct drm_device *dev, int i, uint32_t addr, 345 void (*set_region_tiling)(struct drm_device *dev, int i, uint32_t addr,
341 uint32_t size, uint32_t pitch); 346 uint32_t size, uint32_t pitch);
@@ -485,13 +490,13 @@ enum nv04_fp_display_regs {
485}; 490};
486 491
487struct nv04_crtc_reg { 492struct nv04_crtc_reg {
488 unsigned char MiscOutReg; /* */ 493 unsigned char MiscOutReg;
489 uint8_t CRTC[0xa0]; 494 uint8_t CRTC[0xa0];
490 uint8_t CR58[0x10]; 495 uint8_t CR58[0x10];
491 uint8_t Sequencer[5]; 496 uint8_t Sequencer[5];
492 uint8_t Graphics[9]; 497 uint8_t Graphics[9];
493 uint8_t Attribute[21]; 498 uint8_t Attribute[21];
494 unsigned char DAC[768]; /* Internal Colorlookuptable */ 499 unsigned char DAC[768];
495 500
496 /* PCRTC regs */ 501 /* PCRTC regs */
497 uint32_t fb_start; 502 uint32_t fb_start;
@@ -539,43 +544,9 @@ struct nv04_output_reg {
539}; 544};
540 545
541struct nv04_mode_state { 546struct nv04_mode_state {
542 uint32_t bpp; 547 struct nv04_crtc_reg crtc_reg[2];
543 uint32_t width;
544 uint32_t height;
545 uint32_t interlace;
546 uint32_t repaint0;
547 uint32_t repaint1;
548 uint32_t screen;
549 uint32_t scale;
550 uint32_t dither;
551 uint32_t extra;
552 uint32_t fifo;
553 uint32_t pixel;
554 uint32_t horiz;
555 int arbitration0;
556 int arbitration1;
557 uint32_t pll;
558 uint32_t pllB;
559 uint32_t vpll;
560 uint32_t vpll2;
561 uint32_t vpllB;
562 uint32_t vpll2B;
563 uint32_t pllsel; 548 uint32_t pllsel;
564 uint32_t sel_clk; 549 uint32_t sel_clk;
565 uint32_t general;
566 uint32_t crtcOwner;
567 uint32_t head;
568 uint32_t head2;
569 uint32_t cursorConfig;
570 uint32_t cursor0;
571 uint32_t cursor1;
572 uint32_t cursor2;
573 uint32_t timingH;
574 uint32_t timingV;
575 uint32_t displayV;
576 uint32_t crtcSync;
577
578 struct nv04_crtc_reg crtc_reg[2];
579}; 550};
580 551
581enum nouveau_card_type { 552enum nouveau_card_type {
@@ -613,6 +584,12 @@ struct drm_nouveau_private {
613 struct work_struct irq_work; 584 struct work_struct irq_work;
614 struct work_struct hpd_work; 585 struct work_struct hpd_work;
615 586
587 struct {
588 spinlock_t lock;
589 uint32_t hpd0_bits;
590 uint32_t hpd1_bits;
591 } hpd_state;
592
616 struct list_head vbl_waiting; 593 struct list_head vbl_waiting;
617 594
618 struct { 595 struct {
@@ -1045,6 +1022,7 @@ extern int nv50_fifo_create_context(struct nouveau_channel *);
1045extern void nv50_fifo_destroy_context(struct nouveau_channel *); 1022extern void nv50_fifo_destroy_context(struct nouveau_channel *);
1046extern int nv50_fifo_load_context(struct nouveau_channel *); 1023extern int nv50_fifo_load_context(struct nouveau_channel *);
1047extern int nv50_fifo_unload_context(struct drm_device *); 1024extern int nv50_fifo_unload_context(struct drm_device *);
1025extern void nv50_fifo_tlb_flush(struct drm_device *dev);
1048 1026
1049/* nvc0_fifo.c */ 1027/* nvc0_fifo.c */
1050extern int nvc0_fifo_init(struct drm_device *); 1028extern int nvc0_fifo_init(struct drm_device *);
@@ -1122,6 +1100,8 @@ extern int nv50_graph_load_context(struct nouveau_channel *);
1122extern int nv50_graph_unload_context(struct drm_device *); 1100extern int nv50_graph_unload_context(struct drm_device *);
1123extern void nv50_graph_context_switch(struct drm_device *); 1101extern void nv50_graph_context_switch(struct drm_device *);
1124extern int nv50_grctx_init(struct nouveau_grctx *); 1102extern int nv50_grctx_init(struct nouveau_grctx *);
1103extern void nv50_graph_tlb_flush(struct drm_device *dev);
1104extern void nv86_graph_tlb_flush(struct drm_device *dev);
1125 1105
1126/* nvc0_graph.c */ 1106/* nvc0_graph.c */
1127extern int nvc0_graph_init(struct drm_device *); 1107extern int nvc0_graph_init(struct drm_device *);
@@ -1239,7 +1219,6 @@ extern u16 nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index);
1239extern void nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val); 1219extern void nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val);
1240extern u32 nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index); 1220extern u32 nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index);
1241extern void nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val); 1221extern void nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val);
1242extern int nouveau_bo_sync_gpu(struct nouveau_bo *, struct nouveau_channel *);
1243 1222
1244/* nouveau_fence.c */ 1223/* nouveau_fence.c */
1245struct nouveau_fence; 1224struct nouveau_fence;
diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
index 441b12420bb1..ab1bbfbf266e 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
@@ -249,6 +249,7 @@ alloc_semaphore(struct drm_device *dev)
249{ 249{
250 struct drm_nouveau_private *dev_priv = dev->dev_private; 250 struct drm_nouveau_private *dev_priv = dev->dev_private;
251 struct nouveau_semaphore *sema; 251 struct nouveau_semaphore *sema;
252 int ret;
252 253
253 if (!USE_SEMA(dev)) 254 if (!USE_SEMA(dev))
254 return NULL; 255 return NULL;
@@ -257,10 +258,14 @@ alloc_semaphore(struct drm_device *dev)
257 if (!sema) 258 if (!sema)
258 goto fail; 259 goto fail;
259 260
261 ret = drm_mm_pre_get(&dev_priv->fence.heap);
262 if (ret)
263 goto fail;
264
260 spin_lock(&dev_priv->fence.lock); 265 spin_lock(&dev_priv->fence.lock);
261 sema->mem = drm_mm_search_free(&dev_priv->fence.heap, 4, 0, 0); 266 sema->mem = drm_mm_search_free(&dev_priv->fence.heap, 4, 0, 0);
262 if (sema->mem) 267 if (sema->mem)
263 sema->mem = drm_mm_get_block(sema->mem, 4, 0); 268 sema->mem = drm_mm_get_block_atomic(sema->mem, 4, 0);
264 spin_unlock(&dev_priv->fence.lock); 269 spin_unlock(&dev_priv->fence.lock);
265 270
266 if (!sema->mem) 271 if (!sema->mem)
diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 5c4c929d7f74..9a1fdcf400c2 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -107,23 +107,29 @@ nouveau_gem_info(struct drm_gem_object *gem, struct drm_nouveau_gem_info *rep)
107} 107}
108 108
109static bool 109static bool
110nouveau_gem_tile_flags_valid(struct drm_device *dev, uint32_t tile_flags) { 110nouveau_gem_tile_flags_valid(struct drm_device *dev, uint32_t tile_flags)
111 switch (tile_flags) { 111{
112 case 0x0000: 112 struct drm_nouveau_private *dev_priv = dev->dev_private;
113 case 0x1800: 113
114 case 0x2800: 114 if (dev_priv->card_type >= NV_50) {
115 case 0x4800: 115 switch (tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK) {
116 case 0x7000: 116 case 0x0000:
117 case 0x7400: 117 case 0x1800:
118 case 0x7a00: 118 case 0x2800:
119 case 0xe000: 119 case 0x4800:
120 break; 120 case 0x7000:
121 default: 121 case 0x7400:
122 NV_ERROR(dev, "bad page flags: 0x%08x\n", tile_flags); 122 case 0x7a00:
123 return false; 123 case 0xe000:
124 return true;
125 }
126 } else {
127 if (!(tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK))
128 return true;
124 } 129 }
125 130
126 return true; 131 NV_ERROR(dev, "bad page flags: 0x%08x\n", tile_flags);
132 return false;
127} 133}
128 134
129int 135int
diff --git a/drivers/gpu/drm/nouveau/nouveau_hw.c b/drivers/gpu/drm/nouveau/nouveau_hw.c
index bed669a54a2d..b9672a05c411 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hw.c
+++ b/drivers/gpu/drm/nouveau/nouveau_hw.c
@@ -519,11 +519,11 @@ nouveau_hw_fix_bad_vpll(struct drm_device *dev, int head)
519 519
520 struct pll_lims pll_lim; 520 struct pll_lims pll_lim;
521 struct nouveau_pll_vals pv; 521 struct nouveau_pll_vals pv;
522 uint32_t pllreg = head ? NV_RAMDAC_VPLL2 : NV_PRAMDAC_VPLL_COEFF; 522 enum pll_types pll = head ? PLL_VPLL1 : PLL_VPLL0;
523 523
524 if (get_pll_limits(dev, pllreg, &pll_lim)) 524 if (get_pll_limits(dev, pll, &pll_lim))
525 return; 525 return;
526 nouveau_hw_get_pllvals(dev, pllreg, &pv); 526 nouveau_hw_get_pllvals(dev, pll, &pv);
527 527
528 if (pv.M1 >= pll_lim.vco1.min_m && pv.M1 <= pll_lim.vco1.max_m && 528 if (pv.M1 >= pll_lim.vco1.min_m && pv.M1 <= pll_lim.vco1.max_m &&
529 pv.N1 >= pll_lim.vco1.min_n && pv.N1 <= pll_lim.vco1.max_n && 529 pv.N1 >= pll_lim.vco1.min_n && pv.N1 <= pll_lim.vco1.max_n &&
@@ -536,7 +536,7 @@ nouveau_hw_fix_bad_vpll(struct drm_device *dev, int head)
536 pv.M1 = pll_lim.vco1.max_m; 536 pv.M1 = pll_lim.vco1.max_m;
537 pv.N1 = pll_lim.vco1.min_n; 537 pv.N1 = pll_lim.vco1.min_n;
538 pv.log2P = pll_lim.max_usable_log2p; 538 pv.log2P = pll_lim.max_usable_log2p;
539 nouveau_hw_setpll(dev, pllreg, &pv); 539 nouveau_hw_setpll(dev, pll_lim.reg, &pv);
540} 540}
541 541
542/* 542/*
diff --git a/drivers/gpu/drm/nouveau/nouveau_hw.h b/drivers/gpu/drm/nouveau/nouveau_hw.h
index 869130f83602..2989090b9434 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hw.h
+++ b/drivers/gpu/drm/nouveau/nouveau_hw.h
@@ -416,6 +416,25 @@ nv_fix_nv40_hw_cursor(struct drm_device *dev, int head)
416} 416}
417 417
418static inline void 418static inline void
419nv_set_crtc_base(struct drm_device *dev, int head, uint32_t offset)
420{
421 struct drm_nouveau_private *dev_priv = dev->dev_private;
422
423 NVWriteCRTC(dev, head, NV_PCRTC_START, offset);
424
425 if (dev_priv->card_type == NV_04) {
426 /*
427 * Hilarious, the 24th bit doesn't want to stick to
428 * PCRTC_START...
429 */
430 int cre_heb = NVReadVgaCrtc(dev, head, NV_CIO_CRE_HEB__INDEX);
431
432 NVWriteVgaCrtc(dev, head, NV_CIO_CRE_HEB__INDEX,
433 (cre_heb & ~0x40) | ((offset >> 18) & 0x40));
434 }
435}
436
437static inline void
419nv_show_cursor(struct drm_device *dev, int head, bool show) 438nv_show_cursor(struct drm_device *dev, int head, bool show)
420{ 439{
421 struct drm_nouveau_private *dev_priv = dev->dev_private; 440 struct drm_nouveau_private *dev_priv = dev->dev_private;
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.c b/drivers/gpu/drm/nouveau/nouveau_i2c.c
index fdd7e3de79c8..cb389d014326 100644
--- a/drivers/gpu/drm/nouveau/nouveau_i2c.c
+++ b/drivers/gpu/drm/nouveau/nouveau_i2c.c
@@ -256,7 +256,7 @@ nouveau_i2c_find(struct drm_device *dev, int index)
256 if (index >= DCB_MAX_NUM_I2C_ENTRIES) 256 if (index >= DCB_MAX_NUM_I2C_ENTRIES)
257 return NULL; 257 return NULL;
258 258
259 if (dev_priv->chipset >= NV_50 && (i2c->entry & 0x00000100)) { 259 if (dev_priv->card_type >= NV_50 && (i2c->entry & 0x00000100)) {
260 uint32_t reg = 0xe500, val; 260 uint32_t reg = 0xe500, val;
261 261
262 if (i2c->port_type == 6) { 262 if (i2c->port_type == 6) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_irq.c b/drivers/gpu/drm/nouveau/nouveau_irq.c
index 6fd51a51c608..7bfd9e6c9d67 100644
--- a/drivers/gpu/drm/nouveau/nouveau_irq.c
+++ b/drivers/gpu/drm/nouveau/nouveau_irq.c
@@ -42,6 +42,13 @@
42#include "nouveau_connector.h" 42#include "nouveau_connector.h"
43#include "nv50_display.h" 43#include "nv50_display.h"
44 44
45static DEFINE_RATELIMIT_STATE(nouveau_ratelimit_state, 3 * HZ, 20);
46
47static int nouveau_ratelimit(void)
48{
49 return __ratelimit(&nouveau_ratelimit_state);
50}
51
45void 52void
46nouveau_irq_preinstall(struct drm_device *dev) 53nouveau_irq_preinstall(struct drm_device *dev)
47{ 54{
@@ -53,6 +60,7 @@ nouveau_irq_preinstall(struct drm_device *dev)
53 if (dev_priv->card_type >= NV_50) { 60 if (dev_priv->card_type >= NV_50) {
54 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh); 61 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh);
55 INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh); 62 INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh);
63 spin_lock_init(&dev_priv->hpd_state.lock);
56 INIT_LIST_HEAD(&dev_priv->vbl_waiting); 64 INIT_LIST_HEAD(&dev_priv->vbl_waiting);
57 } 65 }
58} 66}
@@ -202,8 +210,8 @@ nouveau_fifo_irq_handler(struct drm_device *dev)
202 } 210 }
203 211
204 if (status & NV_PFIFO_INTR_DMA_PUSHER) { 212 if (status & NV_PFIFO_INTR_DMA_PUSHER) {
205 u32 get = nv_rd32(dev, 0x003244); 213 u32 dma_get = nv_rd32(dev, 0x003244);
206 u32 put = nv_rd32(dev, 0x003240); 214 u32 dma_put = nv_rd32(dev, 0x003240);
207 u32 push = nv_rd32(dev, 0x003220); 215 u32 push = nv_rd32(dev, 0x003220);
208 u32 state = nv_rd32(dev, 0x003228); 216 u32 state = nv_rd32(dev, 0x003228);
209 217
@@ -213,16 +221,18 @@ nouveau_fifo_irq_handler(struct drm_device *dev)
213 u32 ib_get = nv_rd32(dev, 0x003334); 221 u32 ib_get = nv_rd32(dev, 0x003334);
214 u32 ib_put = nv_rd32(dev, 0x003330); 222 u32 ib_put = nv_rd32(dev, 0x003330);
215 223
216 NV_INFO(dev, "PFIFO_DMA_PUSHER - Ch %d Get 0x%02x%08x " 224 if (nouveau_ratelimit())
225 NV_INFO(dev, "PFIFO_DMA_PUSHER - Ch %d Get 0x%02x%08x "
217 "Put 0x%02x%08x IbGet 0x%08x IbPut 0x%08x " 226 "Put 0x%02x%08x IbGet 0x%08x IbPut 0x%08x "
218 "State 0x%08x Push 0x%08x\n", 227 "State 0x%08x Push 0x%08x\n",
219 chid, ho_get, get, ho_put, put, ib_get, ib_put, 228 chid, ho_get, dma_get, ho_put,
220 state, push); 229 dma_put, ib_get, ib_put, state,
230 push);
221 231
222 /* METHOD_COUNT, in DMA_STATE on earlier chipsets */ 232 /* METHOD_COUNT, in DMA_STATE on earlier chipsets */
223 nv_wr32(dev, 0x003364, 0x00000000); 233 nv_wr32(dev, 0x003364, 0x00000000);
224 if (get != put || ho_get != ho_put) { 234 if (dma_get != dma_put || ho_get != ho_put) {
225 nv_wr32(dev, 0x003244, put); 235 nv_wr32(dev, 0x003244, dma_put);
226 nv_wr32(dev, 0x003328, ho_put); 236 nv_wr32(dev, 0x003328, ho_put);
227 } else 237 } else
228 if (ib_get != ib_put) { 238 if (ib_get != ib_put) {
@@ -231,10 +241,10 @@ nouveau_fifo_irq_handler(struct drm_device *dev)
231 } else { 241 } else {
232 NV_INFO(dev, "PFIFO_DMA_PUSHER - Ch %d Get 0x%08x " 242 NV_INFO(dev, "PFIFO_DMA_PUSHER - Ch %d Get 0x%08x "
233 "Put 0x%08x State 0x%08x Push 0x%08x\n", 243 "Put 0x%08x State 0x%08x Push 0x%08x\n",
234 chid, get, put, state, push); 244 chid, dma_get, dma_put, state, push);
235 245
236 if (get != put) 246 if (dma_get != dma_put)
237 nv_wr32(dev, 0x003244, put); 247 nv_wr32(dev, 0x003244, dma_put);
238 } 248 }
239 249
240 nv_wr32(dev, 0x003228, 0x00000000); 250 nv_wr32(dev, 0x003228, 0x00000000);
@@ -266,8 +276,9 @@ nouveau_fifo_irq_handler(struct drm_device *dev)
266 } 276 }
267 277
268 if (status) { 278 if (status) {
269 NV_INFO(dev, "PFIFO_INTR 0x%08x - Ch %d\n", 279 if (nouveau_ratelimit())
270 status, chid); 280 NV_INFO(dev, "PFIFO_INTR 0x%08x - Ch %d\n",
281 status, chid);
271 nv_wr32(dev, NV03_PFIFO_INTR_0, status); 282 nv_wr32(dev, NV03_PFIFO_INTR_0, status);
272 status = 0; 283 status = 0;
273 } 284 }
@@ -544,13 +555,6 @@ nouveau_pgraph_intr_notify(struct drm_device *dev, uint32_t nsource)
544 nouveau_graph_dump_trap_info(dev, "PGRAPH_NOTIFY", &trap); 555 nouveau_graph_dump_trap_info(dev, "PGRAPH_NOTIFY", &trap);
545} 556}
546 557
547static DEFINE_RATELIMIT_STATE(nouveau_ratelimit_state, 3 * HZ, 20);
548
549static int nouveau_ratelimit(void)
550{
551 return __ratelimit(&nouveau_ratelimit_state);
552}
553
554 558
555static inline void 559static inline void
556nouveau_pgraph_intr_error(struct drm_device *dev, uint32_t nsource) 560nouveau_pgraph_intr_error(struct drm_device *dev, uint32_t nsource)
diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.c b/drivers/gpu/drm/nouveau/nouveau_mem.c
index a163c7c612e7..fe4a30dc4b42 100644
--- a/drivers/gpu/drm/nouveau/nouveau_mem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_mem.c
@@ -33,9 +33,9 @@
33#include "drmP.h" 33#include "drmP.h"
34#include "drm.h" 34#include "drm.h"
35#include "drm_sarea.h" 35#include "drm_sarea.h"
36#include "nouveau_drv.h"
37 36
38#define MIN(a,b) a < b ? a : b 37#include "nouveau_drv.h"
38#include "nouveau_pm.h"
39 39
40/* 40/*
41 * NV10-NV40 tiling helpers 41 * NV10-NV40 tiling helpers
@@ -175,11 +175,10 @@ nv50_mem_vm_bind_linear(struct drm_device *dev, uint64_t virt, uint32_t size,
175 } 175 }
176 } 176 }
177 } 177 }
178 dev_priv->engine.instmem.flush(dev);
179 178
180 nv50_vm_flush(dev, 5); 179 dev_priv->engine.instmem.flush(dev);
181 nv50_vm_flush(dev, 0); 180 dev_priv->engine.fifo.tlb_flush(dev);
182 nv50_vm_flush(dev, 4); 181 dev_priv->engine.graph.tlb_flush(dev);
183 nv50_vm_flush(dev, 6); 182 nv50_vm_flush(dev, 6);
184 return 0; 183 return 0;
185} 184}
@@ -209,11 +208,10 @@ nv50_mem_vm_unbind(struct drm_device *dev, uint64_t virt, uint32_t size)
209 pte++; 208 pte++;
210 } 209 }
211 } 210 }
212 dev_priv->engine.instmem.flush(dev);
213 211
214 nv50_vm_flush(dev, 5); 212 dev_priv->engine.instmem.flush(dev);
215 nv50_vm_flush(dev, 0); 213 dev_priv->engine.fifo.tlb_flush(dev);
216 nv50_vm_flush(dev, 4); 214 dev_priv->engine.graph.tlb_flush(dev);
217 nv50_vm_flush(dev, 6); 215 nv50_vm_flush(dev, 6);
218} 216}
219 217
@@ -653,6 +651,7 @@ nouveau_mem_gart_init(struct drm_device *dev)
653void 651void
654nouveau_mem_timing_init(struct drm_device *dev) 652nouveau_mem_timing_init(struct drm_device *dev)
655{ 653{
654 /* cards < NVC0 only */
656 struct drm_nouveau_private *dev_priv = dev->dev_private; 655 struct drm_nouveau_private *dev_priv = dev->dev_private;
657 struct nouveau_pm_engine *pm = &dev_priv->engine.pm; 656 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
658 struct nouveau_pm_memtimings *memtimings = &pm->memtimings; 657 struct nouveau_pm_memtimings *memtimings = &pm->memtimings;
@@ -719,14 +718,14 @@ nouveau_mem_timing_init(struct drm_device *dev)
719 tUNK_19 = 1; 718 tUNK_19 = 1;
720 tUNK_20 = 0; 719 tUNK_20 = 0;
721 tUNK_21 = 0; 720 tUNK_21 = 0;
722 switch (MIN(recordlen,21)) { 721 switch (min(recordlen, 22)) {
723 case 21: 722 case 22:
724 tUNK_21 = entry[21]; 723 tUNK_21 = entry[21];
725 case 20: 724 case 21:
726 tUNK_20 = entry[20]; 725 tUNK_20 = entry[20];
727 case 19: 726 case 20:
728 tUNK_19 = entry[19]; 727 tUNK_19 = entry[19];
729 case 18: 728 case 19:
730 tUNK_18 = entry[18]; 729 tUNK_18 = entry[18];
731 default: 730 default:
732 tUNK_0 = entry[0]; 731 tUNK_0 = entry[0];
@@ -756,24 +755,30 @@ nouveau_mem_timing_init(struct drm_device *dev)
756 timing->reg_100228 = (tUNK_12 << 16 | tUNK_11 << 8 | tUNK_10); 755 timing->reg_100228 = (tUNK_12 << 16 | tUNK_11 << 8 | tUNK_10);
757 if(recordlen > 19) { 756 if(recordlen > 19) {
758 timing->reg_100228 += (tUNK_19 - 1) << 24; 757 timing->reg_100228 += (tUNK_19 - 1) << 24;
759 } else { 758 }/* I cannot back-up this else-statement right now
759 else {
760 timing->reg_100228 += tUNK_12 << 24; 760 timing->reg_100228 += tUNK_12 << 24;
761 } 761 }*/
762 762
763 /* XXX: reg_10022c */ 763 /* XXX: reg_10022c */
764 timing->reg_10022c = tUNK_2 - 1;
764 765
765 timing->reg_100230 = (tUNK_20 << 24 | tUNK_21 << 16 | 766 timing->reg_100230 = (tUNK_20 << 24 | tUNK_21 << 16 |
766 tUNK_13 << 8 | tUNK_13); 767 tUNK_13 << 8 | tUNK_13);
767 768
768 /* XXX: +6? */ 769 /* XXX: +6? */
769 timing->reg_100234 = (tRAS << 24 | (tUNK_19 + 6) << 8 | tRC); 770 timing->reg_100234 = (tRAS << 24 | (tUNK_19 + 6) << 8 | tRC);
770 if(tUNK_10 > tUNK_11) { 771 timing->reg_100234 += max(tUNK_10,tUNK_11) << 16;
771 timing->reg_100234 += tUNK_10 << 16; 772
772 } else { 773 /* XXX; reg_100238, reg_10023c
773 timing->reg_100234 += tUNK_11 << 16; 774 * reg: 0x00??????
775 * reg_10023c:
776 * 0 for pre-NV50 cards
777 * 0x????0202 for NV50+ cards (empirical evidence) */
778 if(dev_priv->card_type >= NV_50) {
779 timing->reg_10023c = 0x202;
774 } 780 }
775 781
776 /* XXX; reg_100238, reg_10023c */
777 NV_DEBUG(dev, "Entry %d: 220: %08x %08x %08x %08x\n", i, 782 NV_DEBUG(dev, "Entry %d: 220: %08x %08x %08x %08x\n", i,
778 timing->reg_100220, timing->reg_100224, 783 timing->reg_100220, timing->reg_100224,
779 timing->reg_100228, timing->reg_10022c); 784 timing->reg_100228, timing->reg_10022c);
diff --git a/drivers/gpu/drm/nouveau/nouveau_object.c b/drivers/gpu/drm/nouveau/nouveau_object.c
index 896cf8634144..dd572adca02a 100644
--- a/drivers/gpu/drm/nouveau/nouveau_object.c
+++ b/drivers/gpu/drm/nouveau/nouveau_object.c
@@ -129,7 +129,7 @@ nouveau_gpuobj_new(struct drm_device *dev, struct nouveau_channel *chan,
129 if (ramin == NULL) { 129 if (ramin == NULL) {
130 spin_unlock(&dev_priv->ramin_lock); 130 spin_unlock(&dev_priv->ramin_lock);
131 nouveau_gpuobj_ref(NULL, &gpuobj); 131 nouveau_gpuobj_ref(NULL, &gpuobj);
132 return ret; 132 return -ENOMEM;
133 } 133 }
134 134
135 ramin = drm_mm_get_block_atomic(ramin, size, align); 135 ramin = drm_mm_get_block_atomic(ramin, size, align);
diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.c b/drivers/gpu/drm/nouveau/nouveau_pm.c
index 1c99c55d6d46..9f7b158f5825 100644
--- a/drivers/gpu/drm/nouveau/nouveau_pm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_pm.c
@@ -284,6 +284,7 @@ nouveau_sysfs_fini(struct drm_device *dev)
284 } 284 }
285} 285}
286 286
287#ifdef CONFIG_HWMON
287static ssize_t 288static ssize_t
288nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf) 289nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
289{ 290{
@@ -395,10 +396,12 @@ static struct attribute *hwmon_attributes[] = {
395static const struct attribute_group hwmon_attrgroup = { 396static const struct attribute_group hwmon_attrgroup = {
396 .attrs = hwmon_attributes, 397 .attrs = hwmon_attributes,
397}; 398};
399#endif
398 400
399static int 401static int
400nouveau_hwmon_init(struct drm_device *dev) 402nouveau_hwmon_init(struct drm_device *dev)
401{ 403{
404#ifdef CONFIG_HWMON
402 struct drm_nouveau_private *dev_priv = dev->dev_private; 405 struct drm_nouveau_private *dev_priv = dev->dev_private;
403 struct nouveau_pm_engine *pm = &dev_priv->engine.pm; 406 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
404 struct device *hwmon_dev; 407 struct device *hwmon_dev;
@@ -425,13 +428,14 @@ nouveau_hwmon_init(struct drm_device *dev)
425 } 428 }
426 429
427 pm->hwmon = hwmon_dev; 430 pm->hwmon = hwmon_dev;
428 431#endif
429 return 0; 432 return 0;
430} 433}
431 434
432static void 435static void
433nouveau_hwmon_fini(struct drm_device *dev) 436nouveau_hwmon_fini(struct drm_device *dev)
434{ 437{
438#ifdef CONFIG_HWMON
435 struct drm_nouveau_private *dev_priv = dev->dev_private; 439 struct drm_nouveau_private *dev_priv = dev->dev_private;
436 struct nouveau_pm_engine *pm = &dev_priv->engine.pm; 440 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
437 441
@@ -439,6 +443,7 @@ nouveau_hwmon_fini(struct drm_device *dev)
439 sysfs_remove_group(&pm->hwmon->kobj, &hwmon_attrgroup); 443 sysfs_remove_group(&pm->hwmon->kobj, &hwmon_attrgroup);
440 hwmon_device_unregister(pm->hwmon); 444 hwmon_device_unregister(pm->hwmon);
441 } 445 }
446#endif
442} 447}
443 448
444int 449int
diff --git a/drivers/gpu/drm/nouveau/nouveau_ramht.c b/drivers/gpu/drm/nouveau/nouveau_ramht.c
index 7f16697cc96c..2d8580927ca4 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ramht.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ramht.c
@@ -153,26 +153,42 @@ nouveau_ramht_insert(struct nouveau_channel *chan, u32 handle,
153 return -ENOMEM; 153 return -ENOMEM;
154} 154}
155 155
156static struct nouveau_ramht_entry *
157nouveau_ramht_remove_entry(struct nouveau_channel *chan, u32 handle)
158{
159 struct nouveau_ramht *ramht = chan ? chan->ramht : NULL;
160 struct nouveau_ramht_entry *entry;
161 unsigned long flags;
162
163 if (!ramht)
164 return NULL;
165
166 spin_lock_irqsave(&ramht->lock, flags);
167 list_for_each_entry(entry, &ramht->entries, head) {
168 if (entry->channel == chan &&
169 (!handle || entry->handle == handle)) {
170 list_del(&entry->head);
171 spin_unlock_irqrestore(&ramht->lock, flags);
172
173 return entry;
174 }
175 }
176 spin_unlock_irqrestore(&ramht->lock, flags);
177
178 return NULL;
179}
180
156static void 181static void
157nouveau_ramht_remove_locked(struct nouveau_channel *chan, u32 handle) 182nouveau_ramht_remove_hash(struct nouveau_channel *chan, u32 handle)
158{ 183{
159 struct drm_device *dev = chan->dev; 184 struct drm_device *dev = chan->dev;
160 struct drm_nouveau_private *dev_priv = dev->dev_private; 185 struct drm_nouveau_private *dev_priv = dev->dev_private;
161 struct nouveau_instmem_engine *instmem = &dev_priv->engine.instmem; 186 struct nouveau_instmem_engine *instmem = &dev_priv->engine.instmem;
162 struct nouveau_gpuobj *ramht = chan->ramht->gpuobj; 187 struct nouveau_gpuobj *ramht = chan->ramht->gpuobj;
163 struct nouveau_ramht_entry *entry, *tmp; 188 unsigned long flags;
164 u32 co, ho; 189 u32 co, ho;
165 190
166 list_for_each_entry_safe(entry, tmp, &chan->ramht->entries, head) { 191 spin_lock_irqsave(&chan->ramht->lock, flags);
167 if (entry->channel != chan || entry->handle != handle)
168 continue;
169
170 nouveau_gpuobj_ref(NULL, &entry->gpuobj);
171 list_del(&entry->head);
172 kfree(entry);
173 break;
174 }
175
176 co = ho = nouveau_ramht_hash_handle(chan, handle); 192 co = ho = nouveau_ramht_hash_handle(chan, handle);
177 do { 193 do {
178 if (nouveau_ramht_entry_valid(dev, ramht, co) && 194 if (nouveau_ramht_entry_valid(dev, ramht, co) &&
@@ -184,7 +200,7 @@ nouveau_ramht_remove_locked(struct nouveau_channel *chan, u32 handle)
184 nv_wo32(ramht, co + 0, 0x00000000); 200 nv_wo32(ramht, co + 0, 0x00000000);
185 nv_wo32(ramht, co + 4, 0x00000000); 201 nv_wo32(ramht, co + 4, 0x00000000);
186 instmem->flush(dev); 202 instmem->flush(dev);
187 return; 203 goto out;
188 } 204 }
189 205
190 co += 8; 206 co += 8;
@@ -194,17 +210,22 @@ nouveau_ramht_remove_locked(struct nouveau_channel *chan, u32 handle)
194 210
195 NV_ERROR(dev, "RAMHT entry not found. ch=%d, handle=0x%08x\n", 211 NV_ERROR(dev, "RAMHT entry not found. ch=%d, handle=0x%08x\n",
196 chan->id, handle); 212 chan->id, handle);
213out:
214 spin_unlock_irqrestore(&chan->ramht->lock, flags);
197} 215}
198 216
199void 217void
200nouveau_ramht_remove(struct nouveau_channel *chan, u32 handle) 218nouveau_ramht_remove(struct nouveau_channel *chan, u32 handle)
201{ 219{
202 struct nouveau_ramht *ramht = chan->ramht; 220 struct nouveau_ramht_entry *entry;
203 unsigned long flags;
204 221
205 spin_lock_irqsave(&ramht->lock, flags); 222 entry = nouveau_ramht_remove_entry(chan, handle);
206 nouveau_ramht_remove_locked(chan, handle); 223 if (!entry)
207 spin_unlock_irqrestore(&ramht->lock, flags); 224 return;
225
226 nouveau_ramht_remove_hash(chan, entry->handle);
227 nouveau_gpuobj_ref(NULL, &entry->gpuobj);
228 kfree(entry);
208} 229}
209 230
210struct nouveau_gpuobj * 231struct nouveau_gpuobj *
@@ -265,23 +286,19 @@ void
265nouveau_ramht_ref(struct nouveau_ramht *ref, struct nouveau_ramht **ptr, 286nouveau_ramht_ref(struct nouveau_ramht *ref, struct nouveau_ramht **ptr,
266 struct nouveau_channel *chan) 287 struct nouveau_channel *chan)
267{ 288{
268 struct nouveau_ramht_entry *entry, *tmp; 289 struct nouveau_ramht_entry *entry;
269 struct nouveau_ramht *ramht; 290 struct nouveau_ramht *ramht;
270 unsigned long flags;
271 291
272 if (ref) 292 if (ref)
273 kref_get(&ref->refcount); 293 kref_get(&ref->refcount);
274 294
275 ramht = *ptr; 295 ramht = *ptr;
276 if (ramht) { 296 if (ramht) {
277 spin_lock_irqsave(&ramht->lock, flags); 297 while ((entry = nouveau_ramht_remove_entry(chan, 0))) {
278 list_for_each_entry_safe(entry, tmp, &ramht->entries, head) { 298 nouveau_ramht_remove_hash(chan, entry->handle);
279 if (entry->channel != chan) 299 nouveau_gpuobj_ref(NULL, &entry->gpuobj);
280 continue; 300 kfree(entry);
281
282 nouveau_ramht_remove_locked(chan, entry->handle);
283 } 301 }
284 spin_unlock_irqrestore(&ramht->lock, flags);
285 302
286 kref_put(&ramht->refcount, nouveau_ramht_del); 303 kref_put(&ramht->refcount, nouveau_ramht_del);
287 } 304 }
diff --git a/drivers/gpu/drm/nouveau/nouveau_sgdma.c b/drivers/gpu/drm/nouveau/nouveau_sgdma.c
index 288bacac7e5a..d4ac97007038 100644
--- a/drivers/gpu/drm/nouveau/nouveau_sgdma.c
+++ b/drivers/gpu/drm/nouveau/nouveau_sgdma.c
@@ -120,8 +120,8 @@ nouveau_sgdma_bind(struct ttm_backend *be, struct ttm_mem_reg *mem)
120 dev_priv->engine.instmem.flush(nvbe->dev); 120 dev_priv->engine.instmem.flush(nvbe->dev);
121 121
122 if (dev_priv->card_type == NV_50) { 122 if (dev_priv->card_type == NV_50) {
123 nv50_vm_flush(dev, 5); /* PGRAPH */ 123 dev_priv->engine.fifo.tlb_flush(dev);
124 nv50_vm_flush(dev, 0); /* PFIFO */ 124 dev_priv->engine.graph.tlb_flush(dev);
125 } 125 }
126 126
127 nvbe->bound = true; 127 nvbe->bound = true;
@@ -162,8 +162,8 @@ nouveau_sgdma_unbind(struct ttm_backend *be)
162 dev_priv->engine.instmem.flush(nvbe->dev); 162 dev_priv->engine.instmem.flush(nvbe->dev);
163 163
164 if (dev_priv->card_type == NV_50) { 164 if (dev_priv->card_type == NV_50) {
165 nv50_vm_flush(dev, 5); 165 dev_priv->engine.fifo.tlb_flush(dev);
166 nv50_vm_flush(dev, 0); 166 dev_priv->engine.graph.tlb_flush(dev);
167 } 167 }
168 168
169 nvbe->bound = false; 169 nvbe->bound = false;
@@ -224,7 +224,11 @@ nouveau_sgdma_init(struct drm_device *dev)
224 int i, ret; 224 int i, ret;
225 225
226 if (dev_priv->card_type < NV_50) { 226 if (dev_priv->card_type < NV_50) {
227 aper_size = (64 * 1024 * 1024); 227 if(dev_priv->ramin_rsvd_vram < 2 * 1024 * 1024)
228 aper_size = 64 * 1024 * 1024;
229 else
230 aper_size = 512 * 1024 * 1024;
231
228 obj_size = (aper_size >> NV_CTXDMA_PAGE_SHIFT) * 4; 232 obj_size = (aper_size >> NV_CTXDMA_PAGE_SHIFT) * 4;
229 obj_size += 8; /* ctxdma header */ 233 obj_size += 8; /* ctxdma header */
230 } else { 234 } else {
diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
index ed7757f14083..049f755567e5 100644
--- a/drivers/gpu/drm/nouveau/nouveau_state.c
+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
@@ -354,6 +354,15 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev)
354 engine->graph.destroy_context = nv50_graph_destroy_context; 354 engine->graph.destroy_context = nv50_graph_destroy_context;
355 engine->graph.load_context = nv50_graph_load_context; 355 engine->graph.load_context = nv50_graph_load_context;
356 engine->graph.unload_context = nv50_graph_unload_context; 356 engine->graph.unload_context = nv50_graph_unload_context;
357 if (dev_priv->chipset != 0x86)
358 engine->graph.tlb_flush = nv50_graph_tlb_flush;
359 else {
360 /* from what i can see nvidia do this on every
361 * pre-NVA3 board except NVAC, but, we've only
362 * ever seen problems on NV86
363 */
364 engine->graph.tlb_flush = nv86_graph_tlb_flush;
365 }
357 engine->fifo.channels = 128; 366 engine->fifo.channels = 128;
358 engine->fifo.init = nv50_fifo_init; 367 engine->fifo.init = nv50_fifo_init;
359 engine->fifo.takedown = nv50_fifo_takedown; 368 engine->fifo.takedown = nv50_fifo_takedown;
@@ -365,6 +374,7 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev)
365 engine->fifo.destroy_context = nv50_fifo_destroy_context; 374 engine->fifo.destroy_context = nv50_fifo_destroy_context;
366 engine->fifo.load_context = nv50_fifo_load_context; 375 engine->fifo.load_context = nv50_fifo_load_context;
367 engine->fifo.unload_context = nv50_fifo_unload_context; 376 engine->fifo.unload_context = nv50_fifo_unload_context;
377 engine->fifo.tlb_flush = nv50_fifo_tlb_flush;
368 engine->display.early_init = nv50_display_early_init; 378 engine->display.early_init = nv50_display_early_init;
369 engine->display.late_takedown = nv50_display_late_takedown; 379 engine->display.late_takedown = nv50_display_late_takedown;
370 engine->display.create = nv50_display_create; 380 engine->display.create = nv50_display_create;
@@ -1041,6 +1051,9 @@ int nouveau_ioctl_getparam(struct drm_device *dev, void *data,
1041 case NOUVEAU_GETPARAM_PTIMER_TIME: 1051 case NOUVEAU_GETPARAM_PTIMER_TIME:
1042 getparam->value = dev_priv->engine.timer.read(dev); 1052 getparam->value = dev_priv->engine.timer.read(dev);
1043 break; 1053 break;
1054 case NOUVEAU_GETPARAM_HAS_BO_USAGE:
1055 getparam->value = 1;
1056 break;
1044 case NOUVEAU_GETPARAM_GRAPH_UNITS: 1057 case NOUVEAU_GETPARAM_GRAPH_UNITS:
1045 /* NV40 and NV50 versions are quite different, but register 1058 /* NV40 and NV50 versions are quite different, but register
1046 * address is the same. User is supposed to know the card 1059 * address is the same. User is supposed to know the card
@@ -1051,7 +1064,7 @@ int nouveau_ioctl_getparam(struct drm_device *dev, void *data,
1051 } 1064 }
1052 /* FALLTHRU */ 1065 /* FALLTHRU */
1053 default: 1066 default:
1054 NV_ERROR(dev, "unknown parameter %lld\n", getparam->param); 1067 NV_DEBUG(dev, "unknown parameter %lld\n", getparam->param);
1055 return -EINVAL; 1068 return -EINVAL;
1056 } 1069 }
1057 1070
@@ -1066,7 +1079,7 @@ nouveau_ioctl_setparam(struct drm_device *dev, void *data,
1066 1079
1067 switch (setparam->param) { 1080 switch (setparam->param) {
1068 default: 1081 default:
1069 NV_ERROR(dev, "unknown parameter %lld\n", setparam->param); 1082 NV_DEBUG(dev, "unknown parameter %lld\n", setparam->param);
1070 return -EINVAL; 1083 return -EINVAL;
1071 } 1084 }
1072 1085
diff --git a/drivers/gpu/drm/nouveau/nouveau_temp.c b/drivers/gpu/drm/nouveau/nouveau_temp.c
index 16bbbf1eff63..7ecc4adc1e45 100644
--- a/drivers/gpu/drm/nouveau/nouveau_temp.c
+++ b/drivers/gpu/drm/nouveau/nouveau_temp.c
@@ -191,7 +191,7 @@ nv40_temp_get(struct drm_device *dev)
191 int offset = sensor->offset_mult / sensor->offset_div; 191 int offset = sensor->offset_mult / sensor->offset_div;
192 int core_temp; 192 int core_temp;
193 193
194 if (dev_priv->chipset >= 0x50) { 194 if (dev_priv->card_type >= NV_50) {
195 core_temp = nv_rd32(dev, 0x20008); 195 core_temp = nv_rd32(dev, 0x20008);
196 } else { 196 } else {
197 core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff; 197 core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff;
diff --git a/drivers/gpu/drm/nouveau/nv04_crtc.c b/drivers/gpu/drm/nouveau/nv04_crtc.c
index c71abc2a34d5..40e180741629 100644
--- a/drivers/gpu/drm/nouveau/nv04_crtc.c
+++ b/drivers/gpu/drm/nouveau/nv04_crtc.c
@@ -158,7 +158,6 @@ nv_crtc_dpms(struct drm_crtc *crtc, int mode)
158{ 158{
159 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); 159 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
160 struct drm_device *dev = crtc->dev; 160 struct drm_device *dev = crtc->dev;
161 struct drm_connector *connector;
162 unsigned char seq1 = 0, crtc17 = 0; 161 unsigned char seq1 = 0, crtc17 = 0;
163 unsigned char crtc1A; 162 unsigned char crtc1A;
164 163
@@ -213,10 +212,6 @@ nv_crtc_dpms(struct drm_crtc *crtc, int mode)
213 NVVgaSeqReset(dev, nv_crtc->index, false); 212 NVVgaSeqReset(dev, nv_crtc->index, false);
214 213
215 NVWriteVgaCrtc(dev, nv_crtc->index, NV_CIO_CRE_RPC1_INDEX, crtc1A); 214 NVWriteVgaCrtc(dev, nv_crtc->index, NV_CIO_CRE_RPC1_INDEX, crtc1A);
216
217 /* Update connector polling modes */
218 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
219 nouveau_connector_set_polling(connector);
220} 215}
221 216
222static bool 217static bool
@@ -831,7 +826,7 @@ nv04_crtc_do_mode_set_base(struct drm_crtc *crtc,
831 /* Update the framebuffer location. */ 826 /* Update the framebuffer location. */
832 regp->fb_start = nv_crtc->fb.offset & ~3; 827 regp->fb_start = nv_crtc->fb.offset & ~3;
833 regp->fb_start += (y * drm_fb->pitch) + (x * drm_fb->bits_per_pixel / 8); 828 regp->fb_start += (y * drm_fb->pitch) + (x * drm_fb->bits_per_pixel / 8);
834 NVWriteCRTC(dev, nv_crtc->index, NV_PCRTC_START, regp->fb_start); 829 nv_set_crtc_base(dev, nv_crtc->index, regp->fb_start);
835 830
836 /* Update the arbitration parameters. */ 831 /* Update the arbitration parameters. */
837 nouveau_calc_arb(dev, crtc->mode.clock, drm_fb->bits_per_pixel, 832 nouveau_calc_arb(dev, crtc->mode.clock, drm_fb->bits_per_pixel,
diff --git a/drivers/gpu/drm/nouveau/nv04_dfp.c b/drivers/gpu/drm/nouveau/nv04_dfp.c
index c936403b26e2..ef23550407b5 100644
--- a/drivers/gpu/drm/nouveau/nv04_dfp.c
+++ b/drivers/gpu/drm/nouveau/nv04_dfp.c
@@ -185,14 +185,15 @@ static bool nv04_dfp_mode_fixup(struct drm_encoder *encoder,
185 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 185 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
186 struct nouveau_connector *nv_connector = nouveau_encoder_connector_get(nv_encoder); 186 struct nouveau_connector *nv_connector = nouveau_encoder_connector_get(nv_encoder);
187 187
188 /* For internal panels and gpu scaling on DVI we need the native mode */ 188 if (!nv_connector->native_mode ||
189 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) { 189 nv_connector->scaling_mode == DRM_MODE_SCALE_NONE ||
190 if (!nv_connector->native_mode) 190 mode->hdisplay > nv_connector->native_mode->hdisplay ||
191 return false; 191 mode->vdisplay > nv_connector->native_mode->vdisplay) {
192 nv_encoder->mode = *adjusted_mode;
193
194 } else {
192 nv_encoder->mode = *nv_connector->native_mode; 195 nv_encoder->mode = *nv_connector->native_mode;
193 adjusted_mode->clock = nv_connector->native_mode->clock; 196 adjusted_mode->clock = nv_connector->native_mode->clock;
194 } else {
195 nv_encoder->mode = *adjusted_mode;
196 } 197 }
197 198
198 return true; 199 return true;
diff --git a/drivers/gpu/drm/nouveau/nv04_pm.c b/drivers/gpu/drm/nouveau/nv04_pm.c
index 6a6eb697d38e..eb1c70dd82ed 100644
--- a/drivers/gpu/drm/nouveau/nv04_pm.c
+++ b/drivers/gpu/drm/nouveau/nv04_pm.c
@@ -76,6 +76,15 @@ nv04_pm_clock_set(struct drm_device *dev, void *pre_state)
76 reg += 4; 76 reg += 4;
77 77
78 nouveau_hw_setpll(dev, reg, &state->calc); 78 nouveau_hw_setpll(dev, reg, &state->calc);
79
80 if (dev_priv->card_type < NV_30 && reg == NV_PRAMDAC_MPLL_COEFF) {
81 if (dev_priv->card_type == NV_20)
82 nv_mask(dev, 0x1002c4, 0, 1 << 20);
83
84 /* Reset the DLLs */
85 nv_mask(dev, 0x1002c0, 0, 1 << 8);
86 }
87
79 kfree(state); 88 kfree(state);
80} 89}
81 90
diff --git a/drivers/gpu/drm/nouveau/nv50_calc.c b/drivers/gpu/drm/nouveau/nv50_calc.c
index 2cdc2bfe7179..de81151648f8 100644
--- a/drivers/gpu/drm/nouveau/nv50_calc.c
+++ b/drivers/gpu/drm/nouveau/nv50_calc.c
@@ -51,24 +51,28 @@ nv50_calc_pll2(struct drm_device *dev, struct pll_lims *pll, int clk,
51 int *N, int *fN, int *M, int *P) 51 int *N, int *fN, int *M, int *P)
52{ 52{
53 fixed20_12 fb_div, a, b; 53 fixed20_12 fb_div, a, b;
54 u32 refclk = pll->refclk / 10;
55 u32 max_vco_freq = pll->vco1.maxfreq / 10;
56 u32 max_vco_inputfreq = pll->vco1.max_inputfreq / 10;
57 clk /= 10;
54 58
55 *P = pll->vco1.maxfreq / clk; 59 *P = max_vco_freq / clk;
56 if (*P > pll->max_p) 60 if (*P > pll->max_p)
57 *P = pll->max_p; 61 *P = pll->max_p;
58 if (*P < pll->min_p) 62 if (*P < pll->min_p)
59 *P = pll->min_p; 63 *P = pll->min_p;
60 64
61 /* *M = ceil(refclk / pll->vco.max_inputfreq); */ 65 /* *M = floor((refclk + max_vco_inputfreq) / max_vco_inputfreq); */
62 a.full = dfixed_const(pll->refclk); 66 a.full = dfixed_const(refclk + max_vco_inputfreq);
63 b.full = dfixed_const(pll->vco1.max_inputfreq); 67 b.full = dfixed_const(max_vco_inputfreq);
64 a.full = dfixed_div(a, b); 68 a.full = dfixed_div(a, b);
65 a.full = dfixed_ceil(a); 69 a.full = dfixed_floor(a);
66 *M = dfixed_trunc(a); 70 *M = dfixed_trunc(a);
67 71
68 /* fb_div = (vco * *M) / refclk; */ 72 /* fb_div = (vco * *M) / refclk; */
69 fb_div.full = dfixed_const(clk * *P); 73 fb_div.full = dfixed_const(clk * *P);
70 fb_div.full = dfixed_mul(fb_div, a); 74 fb_div.full = dfixed_mul(fb_div, a);
71 a.full = dfixed_const(pll->refclk); 75 a.full = dfixed_const(refclk);
72 fb_div.full = dfixed_div(fb_div, a); 76 fb_div.full = dfixed_div(fb_div, a);
73 77
74 /* *N = floor(fb_div); */ 78 /* *N = floor(fb_div); */
diff --git a/drivers/gpu/drm/nouveau/nv50_crtc.c b/drivers/gpu/drm/nouveau/nv50_crtc.c
index 16380d52cd88..56476d0c6de8 100644
--- a/drivers/gpu/drm/nouveau/nv50_crtc.c
+++ b/drivers/gpu/drm/nouveau/nv50_crtc.c
@@ -546,7 +546,7 @@ nv50_crtc_do_mode_set_base(struct drm_crtc *crtc,
546 } 546 }
547 547
548 nv_crtc->fb.offset = fb->nvbo->bo.offset - dev_priv->vm_vram_base; 548 nv_crtc->fb.offset = fb->nvbo->bo.offset - dev_priv->vm_vram_base;
549 nv_crtc->fb.tile_flags = fb->nvbo->tile_flags; 549 nv_crtc->fb.tile_flags = nouveau_bo_tile_layout(fb->nvbo);
550 nv_crtc->fb.cpp = drm_fb->bits_per_pixel / 8; 550 nv_crtc->fb.cpp = drm_fb->bits_per_pixel / 8;
551 if (!nv_crtc->fb.blanked && dev_priv->chipset != 0x50) { 551 if (!nv_crtc->fb.blanked && dev_priv->chipset != 0x50) {
552 ret = RING_SPACE(evo, 2); 552 ret = RING_SPACE(evo, 2);
@@ -578,7 +578,7 @@ nv50_crtc_do_mode_set_base(struct drm_crtc *crtc,
578 fb->nvbo->tile_mode); 578 fb->nvbo->tile_mode);
579 } 579 }
580 if (dev_priv->chipset == 0x50) 580 if (dev_priv->chipset == 0x50)
581 OUT_RING(evo, (fb->nvbo->tile_flags << 8) | format); 581 OUT_RING(evo, (nv_crtc->fb.tile_flags << 8) | format);
582 else 582 else
583 OUT_RING(evo, format); 583 OUT_RING(evo, format);
584 584
diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
index 55c9663ef2bf..f624c611ddea 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -1032,11 +1032,18 @@ nv50_display_irq_hotplug_bh(struct work_struct *work)
1032 struct drm_connector *connector; 1032 struct drm_connector *connector;
1033 const uint32_t gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 }; 1033 const uint32_t gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 };
1034 uint32_t unplug_mask, plug_mask, change_mask; 1034 uint32_t unplug_mask, plug_mask, change_mask;
1035 uint32_t hpd0, hpd1 = 0; 1035 uint32_t hpd0, hpd1;
1036 1036
1037 hpd0 = nv_rd32(dev, 0xe054) & nv_rd32(dev, 0xe050); 1037 spin_lock_irq(&dev_priv->hpd_state.lock);
1038 hpd0 = dev_priv->hpd_state.hpd0_bits;
1039 dev_priv->hpd_state.hpd0_bits = 0;
1040 hpd1 = dev_priv->hpd_state.hpd1_bits;
1041 dev_priv->hpd_state.hpd1_bits = 0;
1042 spin_unlock_irq(&dev_priv->hpd_state.lock);
1043
1044 hpd0 &= nv_rd32(dev, 0xe050);
1038 if (dev_priv->chipset >= 0x90) 1045 if (dev_priv->chipset >= 0x90)
1039 hpd1 = nv_rd32(dev, 0xe074) & nv_rd32(dev, 0xe070); 1046 hpd1 &= nv_rd32(dev, 0xe070);
1040 1047
1041 plug_mask = (hpd0 & 0x0000ffff) | (hpd1 << 16); 1048 plug_mask = (hpd0 & 0x0000ffff) | (hpd1 << 16);
1042 unplug_mask = (hpd0 >> 16) | (hpd1 & 0xffff0000); 1049 unplug_mask = (hpd0 >> 16) | (hpd1 & 0xffff0000);
@@ -1078,10 +1085,6 @@ nv50_display_irq_hotplug_bh(struct work_struct *work)
1078 helper->dpms(connector->encoder, DRM_MODE_DPMS_OFF); 1085 helper->dpms(connector->encoder, DRM_MODE_DPMS_OFF);
1079 } 1086 }
1080 1087
1081 nv_wr32(dev, 0xe054, nv_rd32(dev, 0xe054));
1082 if (dev_priv->chipset >= 0x90)
1083 nv_wr32(dev, 0xe074, nv_rd32(dev, 0xe074));
1084
1085 drm_helper_hpd_irq_event(dev); 1088 drm_helper_hpd_irq_event(dev);
1086} 1089}
1087 1090
@@ -1092,8 +1095,22 @@ nv50_display_irq_handler(struct drm_device *dev)
1092 uint32_t delayed = 0; 1095 uint32_t delayed = 0;
1093 1096
1094 if (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_HOTPLUG) { 1097 if (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_HOTPLUG) {
1095 if (!work_pending(&dev_priv->hpd_work)) 1098 uint32_t hpd0_bits, hpd1_bits = 0;
1096 queue_work(dev_priv->wq, &dev_priv->hpd_work); 1099
1100 hpd0_bits = nv_rd32(dev, 0xe054);
1101 nv_wr32(dev, 0xe054, hpd0_bits);
1102
1103 if (dev_priv->chipset >= 0x90) {
1104 hpd1_bits = nv_rd32(dev, 0xe074);
1105 nv_wr32(dev, 0xe074, hpd1_bits);
1106 }
1107
1108 spin_lock(&dev_priv->hpd_state.lock);
1109 dev_priv->hpd_state.hpd0_bits |= hpd0_bits;
1110 dev_priv->hpd_state.hpd1_bits |= hpd1_bits;
1111 spin_unlock(&dev_priv->hpd_state.lock);
1112
1113 queue_work(dev_priv->wq, &dev_priv->hpd_work);
1097 } 1114 }
1098 1115
1099 while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) { 1116 while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) {
diff --git a/drivers/gpu/drm/nouveau/nv50_fifo.c b/drivers/gpu/drm/nouveau/nv50_fifo.c
index a46a961102f3..1da65bd60c10 100644
--- a/drivers/gpu/drm/nouveau/nv50_fifo.c
+++ b/drivers/gpu/drm/nouveau/nv50_fifo.c
@@ -464,3 +464,8 @@ nv50_fifo_unload_context(struct drm_device *dev)
464 return 0; 464 return 0;
465} 465}
466 466
467void
468nv50_fifo_tlb_flush(struct drm_device *dev)
469{
470 nv50_vm_flush(dev, 5);
471}
diff --git a/drivers/gpu/drm/nouveau/nv50_graph.c b/drivers/gpu/drm/nouveau/nv50_graph.c
index cbf5ae2f67d4..8b669d0af610 100644
--- a/drivers/gpu/drm/nouveau/nv50_graph.c
+++ b/drivers/gpu/drm/nouveau/nv50_graph.c
@@ -402,3 +402,55 @@ struct nouveau_pgraph_object_class nv50_graph_grclass[] = {
402 { 0x8597, false, NULL }, /* tesla (nva3, nva5, nva8) */ 402 { 0x8597, false, NULL }, /* tesla (nva3, nva5, nva8) */
403 {} 403 {}
404}; 404};
405
406void
407nv50_graph_tlb_flush(struct drm_device *dev)
408{
409 nv50_vm_flush(dev, 0);
410}
411
412void
413nv86_graph_tlb_flush(struct drm_device *dev)
414{
415 struct drm_nouveau_private *dev_priv = dev->dev_private;
416 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
417 bool idle, timeout = false;
418 unsigned long flags;
419 u64 start;
420 u32 tmp;
421
422 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
423 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
424
425 start = ptimer->read(dev);
426 do {
427 idle = true;
428
429 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
430 if ((tmp & 7) == 1)
431 idle = false;
432 }
433
434 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
435 if ((tmp & 7) == 1)
436 idle = false;
437 }
438
439 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
440 if ((tmp & 7) == 1)
441 idle = false;
442 }
443 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
444
445 if (timeout) {
446 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
447 "0x%08x 0x%08x 0x%08x 0x%08x\n",
448 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
449 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
450 }
451
452 nv50_vm_flush(dev, 0);
453
454 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
455 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
456}
diff --git a/drivers/gpu/drm/nouveau/nv50_instmem.c b/drivers/gpu/drm/nouveau/nv50_instmem.c
index a53fc974332b..b773229b7647 100644
--- a/drivers/gpu/drm/nouveau/nv50_instmem.c
+++ b/drivers/gpu/drm/nouveau/nv50_instmem.c
@@ -402,7 +402,6 @@ nv50_instmem_bind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
402 } 402 }
403 dev_priv->engine.instmem.flush(dev); 403 dev_priv->engine.instmem.flush(dev);
404 404
405 nv50_vm_flush(dev, 4);
406 nv50_vm_flush(dev, 6); 405 nv50_vm_flush(dev, 6);
407 406
408 gpuobj->im_bound = 1; 407 gpuobj->im_bound = 1;
diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
index 8e421f644a54..05efb5b9f13e 100644
--- a/drivers/gpu/drm/radeon/atom.c
+++ b/drivers/gpu/drm/radeon/atom.c
@@ -112,6 +112,7 @@ static uint32_t atom_iio_execute(struct atom_context *ctx, int base,
112 base += 3; 112 base += 3;
113 break; 113 break;
114 case ATOM_IIO_WRITE: 114 case ATOM_IIO_WRITE:
115 (void)ctx->card->ioreg_read(ctx->card, CU16(base + 1));
115 ctx->card->ioreg_write(ctx->card, CU16(base + 1), temp); 116 ctx->card->ioreg_write(ctx->card, CU16(base + 1), temp);
116 base += 3; 117 base += 3;
117 break; 118 break;
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index f12a5b3ec050..4dc5b4714c5a 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -1650,7 +1650,36 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1650 } 1650 }
1651 } 1651 }
1652 1652
1653 rdev->config.evergreen.tile_config = gb_addr_config; 1653 /* setup tiling info dword. gb_addr_config is not adequate since it does
1654 * not have bank info, so create a custom tiling dword.
1655 * bits 3:0 num_pipes
1656 * bits 7:4 num_banks
1657 * bits 11:8 group_size
1658 * bits 15:12 row_size
1659 */
1660 rdev->config.evergreen.tile_config = 0;
1661 switch (rdev->config.evergreen.max_tile_pipes) {
1662 case 1:
1663 default:
1664 rdev->config.evergreen.tile_config |= (0 << 0);
1665 break;
1666 case 2:
1667 rdev->config.evergreen.tile_config |= (1 << 0);
1668 break;
1669 case 4:
1670 rdev->config.evergreen.tile_config |= (2 << 0);
1671 break;
1672 case 8:
1673 rdev->config.evergreen.tile_config |= (3 << 0);
1674 break;
1675 }
1676 rdev->config.evergreen.tile_config |=
1677 ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4;
1678 rdev->config.evergreen.tile_config |=
1679 ((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT) << 8;
1680 rdev->config.evergreen.tile_config |=
1681 ((gb_addr_config & 0x30000000) >> 28) << 12;
1682
1654 WREG32(GB_BACKEND_MAP, gb_backend_map); 1683 WREG32(GB_BACKEND_MAP, gb_backend_map);
1655 WREG32(GB_ADDR_CONFIG, gb_addr_config); 1684 WREG32(GB_ADDR_CONFIG, gb_addr_config);
1656 WREG32(DMIF_ADDR_CONFIG, gb_addr_config); 1685 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
@@ -2033,7 +2062,7 @@ int evergreen_irq_set(struct radeon_device *rdev)
2033 u32 grbm_int_cntl = 0; 2062 u32 grbm_int_cntl = 0;
2034 2063
2035 if (!rdev->irq.installed) { 2064 if (!rdev->irq.installed) {
2036 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n"); 2065 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
2037 return -EINVAL; 2066 return -EINVAL;
2038 } 2067 }
2039 /* don't enable anything if the ih is disabled */ 2068 /* don't enable anything if the ih is disabled */
@@ -2295,6 +2324,7 @@ restart_ih:
2295 case 0: /* D1 vblank */ 2324 case 0: /* D1 vblank */
2296 if (disp_int & LB_D1_VBLANK_INTERRUPT) { 2325 if (disp_int & LB_D1_VBLANK_INTERRUPT) {
2297 drm_handle_vblank(rdev->ddev, 0); 2326 drm_handle_vblank(rdev->ddev, 0);
2327 rdev->pm.vblank_sync = true;
2298 wake_up(&rdev->irq.vblank_queue); 2328 wake_up(&rdev->irq.vblank_queue);
2299 disp_int &= ~LB_D1_VBLANK_INTERRUPT; 2329 disp_int &= ~LB_D1_VBLANK_INTERRUPT;
2300 DRM_DEBUG("IH: D1 vblank\n"); 2330 DRM_DEBUG("IH: D1 vblank\n");
@@ -2316,6 +2346,7 @@ restart_ih:
2316 case 0: /* D2 vblank */ 2346 case 0: /* D2 vblank */
2317 if (disp_int_cont & LB_D2_VBLANK_INTERRUPT) { 2347 if (disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
2318 drm_handle_vblank(rdev->ddev, 1); 2348 drm_handle_vblank(rdev->ddev, 1);
2349 rdev->pm.vblank_sync = true;
2319 wake_up(&rdev->irq.vblank_queue); 2350 wake_up(&rdev->irq.vblank_queue);
2320 disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT; 2351 disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
2321 DRM_DEBUG("IH: D2 vblank\n"); 2352 DRM_DEBUG("IH: D2 vblank\n");
@@ -2337,6 +2368,7 @@ restart_ih:
2337 case 0: /* D3 vblank */ 2368 case 0: /* D3 vblank */
2338 if (disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) { 2369 if (disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
2339 drm_handle_vblank(rdev->ddev, 2); 2370 drm_handle_vblank(rdev->ddev, 2);
2371 rdev->pm.vblank_sync = true;
2340 wake_up(&rdev->irq.vblank_queue); 2372 wake_up(&rdev->irq.vblank_queue);
2341 disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT; 2373 disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
2342 DRM_DEBUG("IH: D3 vblank\n"); 2374 DRM_DEBUG("IH: D3 vblank\n");
@@ -2358,6 +2390,7 @@ restart_ih:
2358 case 0: /* D4 vblank */ 2390 case 0: /* D4 vblank */
2359 if (disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) { 2391 if (disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
2360 drm_handle_vblank(rdev->ddev, 3); 2392 drm_handle_vblank(rdev->ddev, 3);
2393 rdev->pm.vblank_sync = true;
2361 wake_up(&rdev->irq.vblank_queue); 2394 wake_up(&rdev->irq.vblank_queue);
2362 disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT; 2395 disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
2363 DRM_DEBUG("IH: D4 vblank\n"); 2396 DRM_DEBUG("IH: D4 vblank\n");
@@ -2379,6 +2412,7 @@ restart_ih:
2379 case 0: /* D5 vblank */ 2412 case 0: /* D5 vblank */
2380 if (disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) { 2413 if (disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
2381 drm_handle_vblank(rdev->ddev, 4); 2414 drm_handle_vblank(rdev->ddev, 4);
2415 rdev->pm.vblank_sync = true;
2382 wake_up(&rdev->irq.vblank_queue); 2416 wake_up(&rdev->irq.vblank_queue);
2383 disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT; 2417 disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
2384 DRM_DEBUG("IH: D5 vblank\n"); 2418 DRM_DEBUG("IH: D5 vblank\n");
@@ -2400,6 +2434,7 @@ restart_ih:
2400 case 0: /* D6 vblank */ 2434 case 0: /* D6 vblank */
2401 if (disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) { 2435 if (disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
2402 drm_handle_vblank(rdev->ddev, 5); 2436 drm_handle_vblank(rdev->ddev, 5);
2437 rdev->pm.vblank_sync = true;
2403 wake_up(&rdev->irq.vblank_queue); 2438 wake_up(&rdev->irq.vblank_queue);
2404 disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT; 2439 disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
2405 DRM_DEBUG("IH: D6 vblank\n"); 2440 DRM_DEBUG("IH: D6 vblank\n");
diff --git a/drivers/gpu/drm/radeon/evergreen_blit_kms.c b/drivers/gpu/drm/radeon/evergreen_blit_kms.c
index ac3b6dde23db..e0e590110dd4 100644
--- a/drivers/gpu/drm/radeon/evergreen_blit_kms.c
+++ b/drivers/gpu/drm/radeon/evergreen_blit_kms.c
@@ -459,7 +459,7 @@ int evergreen_blit_init(struct radeon_device *rdev)
459 obj_size += evergreen_ps_size * 4; 459 obj_size += evergreen_ps_size * 4;
460 obj_size = ALIGN(obj_size, 256); 460 obj_size = ALIGN(obj_size, 256);
461 461
462 r = radeon_bo_create(rdev, NULL, obj_size, true, RADEON_GEM_DOMAIN_VRAM, 462 r = radeon_bo_create(rdev, NULL, obj_size, PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
463 &rdev->r600_blit.shader_obj); 463 &rdev->r600_blit.shader_obj);
464 if (r) { 464 if (r) {
465 DRM_ERROR("evergreen failed to allocate shader\n"); 465 DRM_ERROR("evergreen failed to allocate shader\n");
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 0e8f28a68927..8e10aa9f74b0 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -442,7 +442,7 @@ int r100_pci_gart_init(struct radeon_device *rdev)
442 int r; 442 int r;
443 443
444 if (rdev->gart.table.ram.ptr) { 444 if (rdev->gart.table.ram.ptr) {
445 WARN(1, "R100 PCI GART already initialized.\n"); 445 WARN(1, "R100 PCI GART already initialized\n");
446 return 0; 446 return 0;
447 } 447 }
448 /* Initialize common gart structure */ 448 /* Initialize common gart structure */
@@ -516,7 +516,7 @@ int r100_irq_set(struct radeon_device *rdev)
516 uint32_t tmp = 0; 516 uint32_t tmp = 0;
517 517
518 if (!rdev->irq.installed) { 518 if (!rdev->irq.installed) {
519 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n"); 519 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
520 WREG32(R_000040_GEN_INT_CNTL, 0); 520 WREG32(R_000040_GEN_INT_CNTL, 0);
521 return -EINVAL; 521 return -EINVAL;
522 } 522 }
diff --git a/drivers/gpu/drm/radeon/r300.c b/drivers/gpu/drm/radeon/r300.c
index 34527e600fe9..cde1d3480d93 100644
--- a/drivers/gpu/drm/radeon/r300.c
+++ b/drivers/gpu/drm/radeon/r300.c
@@ -91,7 +91,7 @@ int rv370_pcie_gart_init(struct radeon_device *rdev)
91 int r; 91 int r;
92 92
93 if (rdev->gart.table.vram.robj) { 93 if (rdev->gart.table.vram.robj) {
94 WARN(1, "RV370 PCIE GART already initialized.\n"); 94 WARN(1, "RV370 PCIE GART already initialized\n");
95 return 0; 95 return 0;
96 } 96 }
97 /* Initialize common gart structure */ 97 /* Initialize common gart structure */
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index 33952a12f0a3..4d7a2e1bdb90 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -97,14 +97,8 @@ u32 rv6xx_get_temp(struct radeon_device *rdev)
97{ 97{
98 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >> 98 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
99 ASIC_T_SHIFT; 99 ASIC_T_SHIFT;
100 u32 actual_temp = 0;
101 100
102 if ((temp >> 7) & 1) 101 return temp * 1000;
103 actual_temp = 0;
104 else
105 actual_temp = (temp >> 1) & 0xff;
106
107 return actual_temp * 1000;
108} 102}
109 103
110void r600_pm_get_dynpm_state(struct radeon_device *rdev) 104void r600_pm_get_dynpm_state(struct radeon_device *rdev)
@@ -884,12 +878,15 @@ void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
884 u32 tmp; 878 u32 tmp;
885 879
886 /* flush hdp cache so updates hit vram */ 880 /* flush hdp cache so updates hit vram */
887 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740)) { 881 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
882 !(rdev->flags & RADEON_IS_AGP)) {
888 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr; 883 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
889 u32 tmp; 884 u32 tmp;
890 885
891 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read 886 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
892 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL 887 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
888 * This seems to cause problems on some AGP cards. Just use the old
889 * method for them.
893 */ 890 */
894 WREG32(HDP_DEBUG1, 0); 891 WREG32(HDP_DEBUG1, 0);
895 tmp = readl((void __iomem *)ptr); 892 tmp = readl((void __iomem *)ptr);
@@ -919,7 +916,7 @@ int r600_pcie_gart_init(struct radeon_device *rdev)
919 int r; 916 int r;
920 917
921 if (rdev->gart.table.vram.robj) { 918 if (rdev->gart.table.vram.robj) {
922 WARN(1, "R600 PCIE GART already initialized.\n"); 919 WARN(1, "R600 PCIE GART already initialized\n");
923 return 0; 920 return 0;
924 } 921 }
925 /* Initialize common gart structure */ 922 /* Initialize common gart structure */
@@ -1201,8 +1198,10 @@ void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
1201 mc->vram_end, mc->real_vram_size >> 20); 1198 mc->vram_end, mc->real_vram_size >> 20);
1202 } else { 1199 } else {
1203 u64 base = 0; 1200 u64 base = 0;
1204 if (rdev->flags & RADEON_IS_IGP) 1201 if (rdev->flags & RADEON_IS_IGP) {
1205 base = (RREG32(MC_VM_FB_LOCATION) & 0xFFFF) << 24; 1202 base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
1203 base <<= 24;
1204 }
1206 radeon_vram_location(rdev, &rdev->mc, base); 1205 radeon_vram_location(rdev, &rdev->mc, base);
1207 rdev->mc.gtt_base_align = 0; 1206 rdev->mc.gtt_base_align = 0;
1208 radeon_gtt_location(rdev, mc); 1207 radeon_gtt_location(rdev, mc);
@@ -2724,7 +2723,7 @@ static int r600_ih_ring_alloc(struct radeon_device *rdev)
2724 /* Allocate ring buffer */ 2723 /* Allocate ring buffer */
2725 if (rdev->ih.ring_obj == NULL) { 2724 if (rdev->ih.ring_obj == NULL) {
2726 r = radeon_bo_create(rdev, NULL, rdev->ih.ring_size, 2725 r = radeon_bo_create(rdev, NULL, rdev->ih.ring_size,
2727 true, 2726 PAGE_SIZE, true,
2728 RADEON_GEM_DOMAIN_GTT, 2727 RADEON_GEM_DOMAIN_GTT,
2729 &rdev->ih.ring_obj); 2728 &rdev->ih.ring_obj);
2730 if (r) { 2729 if (r) {
@@ -2995,7 +2994,7 @@ int r600_irq_set(struct radeon_device *rdev)
2995 u32 hdmi1, hdmi2; 2994 u32 hdmi1, hdmi2;
2996 2995
2997 if (!rdev->irq.installed) { 2996 if (!rdev->irq.installed) {
2998 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n"); 2997 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
2999 return -EINVAL; 2998 return -EINVAL;
3000 } 2999 }
3001 /* don't enable anything if the ih is disabled */ 3000 /* don't enable anything if the ih is disabled */
@@ -3489,10 +3488,12 @@ int r600_debugfs_mc_info_init(struct radeon_device *rdev)
3489void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo) 3488void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
3490{ 3489{
3491 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read 3490 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
3492 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL 3491 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
3492 * This seems to cause problems on some AGP cards. Just use the old
3493 * method for them.
3493 */ 3494 */
3494 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) && 3495 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
3495 rdev->vram_scratch.ptr) { 3496 rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
3496 void __iomem *ptr = (void *)rdev->vram_scratch.ptr; 3497 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
3497 u32 tmp; 3498 u32 tmp;
3498 3499
diff --git a/drivers/gpu/drm/radeon/r600_blit_kms.c b/drivers/gpu/drm/radeon/r600_blit_kms.c
index 8362974ef41a..86e5aa07f0db 100644
--- a/drivers/gpu/drm/radeon/r600_blit_kms.c
+++ b/drivers/gpu/drm/radeon/r600_blit_kms.c
@@ -501,7 +501,7 @@ int r600_blit_init(struct radeon_device *rdev)
501 obj_size += r6xx_ps_size * 4; 501 obj_size += r6xx_ps_size * 4;
502 obj_size = ALIGN(obj_size, 256); 502 obj_size = ALIGN(obj_size, 256);
503 503
504 r = radeon_bo_create(rdev, NULL, obj_size, true, RADEON_GEM_DOMAIN_VRAM, 504 r = radeon_bo_create(rdev, NULL, obj_size, PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
505 &rdev->r600_blit.shader_obj); 505 &rdev->r600_blit.shader_obj);
506 if (r) { 506 if (r) {
507 DRM_ERROR("r600 failed to allocate shader\n"); 507 DRM_ERROR("r600 failed to allocate shader\n");
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index 37cc2aa9f923..0f90fc3482ce 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -50,6 +50,7 @@ struct r600_cs_track {
50 u32 nsamples; 50 u32 nsamples;
51 u32 cb_color_base_last[8]; 51 u32 cb_color_base_last[8];
52 struct radeon_bo *cb_color_bo[8]; 52 struct radeon_bo *cb_color_bo[8];
53 u64 cb_color_bo_mc[8];
53 u32 cb_color_bo_offset[8]; 54 u32 cb_color_bo_offset[8];
54 struct radeon_bo *cb_color_frag_bo[8]; 55 struct radeon_bo *cb_color_frag_bo[8];
55 struct radeon_bo *cb_color_tile_bo[8]; 56 struct radeon_bo *cb_color_tile_bo[8];
@@ -67,6 +68,7 @@ struct r600_cs_track {
67 u32 db_depth_size; 68 u32 db_depth_size;
68 u32 db_offset; 69 u32 db_offset;
69 struct radeon_bo *db_bo; 70 struct radeon_bo *db_bo;
71 u64 db_bo_mc;
70}; 72};
71 73
72static inline int r600_bpe_from_format(u32 *bpe, u32 format) 74static inline int r600_bpe_from_format(u32 *bpe, u32 format)
@@ -140,6 +142,68 @@ static inline int r600_bpe_from_format(u32 *bpe, u32 format)
140 return 0; 142 return 0;
141} 143}
142 144
145struct array_mode_checker {
146 int array_mode;
147 u32 group_size;
148 u32 nbanks;
149 u32 npipes;
150 u32 nsamples;
151 u32 bpe;
152};
153
154/* returns alignment in pixels for pitch/height/depth and bytes for base */
155static inline int r600_get_array_mode_alignment(struct array_mode_checker *values,
156 u32 *pitch_align,
157 u32 *height_align,
158 u32 *depth_align,
159 u64 *base_align)
160{
161 u32 tile_width = 8;
162 u32 tile_height = 8;
163 u32 macro_tile_width = values->nbanks;
164 u32 macro_tile_height = values->npipes;
165 u32 tile_bytes = tile_width * tile_height * values->bpe * values->nsamples;
166 u32 macro_tile_bytes = macro_tile_width * macro_tile_height * tile_bytes;
167
168 switch (values->array_mode) {
169 case ARRAY_LINEAR_GENERAL:
170 /* technically tile_width/_height for pitch/height */
171 *pitch_align = 1; /* tile_width */
172 *height_align = 1; /* tile_height */
173 *depth_align = 1;
174 *base_align = 1;
175 break;
176 case ARRAY_LINEAR_ALIGNED:
177 *pitch_align = max((u32)64, (u32)(values->group_size / values->bpe));
178 *height_align = tile_height;
179 *depth_align = 1;
180 *base_align = values->group_size;
181 break;
182 case ARRAY_1D_TILED_THIN1:
183 *pitch_align = max((u32)tile_width,
184 (u32)(values->group_size /
185 (tile_height * values->bpe * values->nsamples)));
186 *height_align = tile_height;
187 *depth_align = 1;
188 *base_align = values->group_size;
189 break;
190 case ARRAY_2D_TILED_THIN1:
191 *pitch_align = max((u32)macro_tile_width,
192 (u32)(((values->group_size / tile_height) /
193 (values->bpe * values->nsamples)) *
194 values->nbanks)) * tile_width;
195 *height_align = macro_tile_height * tile_height;
196 *depth_align = 1;
197 *base_align = max(macro_tile_bytes,
198 (*pitch_align) * values->bpe * (*height_align) * values->nsamples);
199 break;
200 default:
201 return -EINVAL;
202 }
203
204 return 0;
205}
206
143static void r600_cs_track_init(struct r600_cs_track *track) 207static void r600_cs_track_init(struct r600_cs_track *track)
144{ 208{
145 int i; 209 int i;
@@ -153,10 +217,12 @@ static void r600_cs_track_init(struct r600_cs_track *track)
153 track->cb_color_info[i] = 0; 217 track->cb_color_info[i] = 0;
154 track->cb_color_bo[i] = NULL; 218 track->cb_color_bo[i] = NULL;
155 track->cb_color_bo_offset[i] = 0xFFFFFFFF; 219 track->cb_color_bo_offset[i] = 0xFFFFFFFF;
220 track->cb_color_bo_mc[i] = 0xFFFFFFFF;
156 } 221 }
157 track->cb_target_mask = 0xFFFFFFFF; 222 track->cb_target_mask = 0xFFFFFFFF;
158 track->cb_shader_mask = 0xFFFFFFFF; 223 track->cb_shader_mask = 0xFFFFFFFF;
159 track->db_bo = NULL; 224 track->db_bo = NULL;
225 track->db_bo_mc = 0xFFFFFFFF;
160 /* assume the biggest format and that htile is enabled */ 226 /* assume the biggest format and that htile is enabled */
161 track->db_depth_info = 7 | (1 << 25); 227 track->db_depth_info = 7 | (1 << 25);
162 track->db_depth_view = 0xFFFFC000; 228 track->db_depth_view = 0xFFFFC000;
@@ -168,7 +234,10 @@ static void r600_cs_track_init(struct r600_cs_track *track)
168static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i) 234static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
169{ 235{
170 struct r600_cs_track *track = p->track; 236 struct r600_cs_track *track = p->track;
171 u32 bpe = 0, pitch, slice_tile_max, size, tmp, height, pitch_align; 237 u32 bpe = 0, slice_tile_max, size, tmp;
238 u32 height, height_align, pitch, pitch_align, depth_align;
239 u64 base_offset, base_align;
240 struct array_mode_checker array_check;
172 volatile u32 *ib = p->ib->ptr; 241 volatile u32 *ib = p->ib->ptr;
173 unsigned array_mode; 242 unsigned array_mode;
174 243
@@ -183,60 +252,40 @@ static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
183 i, track->cb_color_info[i]); 252 i, track->cb_color_info[i]);
184 return -EINVAL; 253 return -EINVAL;
185 } 254 }
186 /* pitch is the number of 8x8 tiles per row */ 255 /* pitch in pixels */
187 pitch = G_028060_PITCH_TILE_MAX(track->cb_color_size[i]) + 1; 256 pitch = (G_028060_PITCH_TILE_MAX(track->cb_color_size[i]) + 1) * 8;
188 slice_tile_max = G_028060_SLICE_TILE_MAX(track->cb_color_size[i]) + 1; 257 slice_tile_max = G_028060_SLICE_TILE_MAX(track->cb_color_size[i]) + 1;
189 slice_tile_max *= 64; 258 slice_tile_max *= 64;
190 height = slice_tile_max / (pitch * 8); 259 height = slice_tile_max / pitch;
191 if (height > 8192) 260 if (height > 8192)
192 height = 8192; 261 height = 8192;
193 array_mode = G_0280A0_ARRAY_MODE(track->cb_color_info[i]); 262 array_mode = G_0280A0_ARRAY_MODE(track->cb_color_info[i]);
263
264 base_offset = track->cb_color_bo_mc[i] + track->cb_color_bo_offset[i];
265 array_check.array_mode = array_mode;
266 array_check.group_size = track->group_size;
267 array_check.nbanks = track->nbanks;
268 array_check.npipes = track->npipes;
269 array_check.nsamples = track->nsamples;
270 array_check.bpe = bpe;
271 if (r600_get_array_mode_alignment(&array_check,
272 &pitch_align, &height_align, &depth_align, &base_align)) {
273 dev_warn(p->dev, "%s invalid tiling %d for %d (0x%08X)\n", __func__,
274 G_0280A0_ARRAY_MODE(track->cb_color_info[i]), i,
275 track->cb_color_info[i]);
276 return -EINVAL;
277 }
194 switch (array_mode) { 278 switch (array_mode) {
195 case V_0280A0_ARRAY_LINEAR_GENERAL: 279 case V_0280A0_ARRAY_LINEAR_GENERAL:
196 /* technically height & 0x7 */
197 break; 280 break;
198 case V_0280A0_ARRAY_LINEAR_ALIGNED: 281 case V_0280A0_ARRAY_LINEAR_ALIGNED:
199 pitch_align = max((u32)64, (u32)(track->group_size / bpe)) / 8;
200 if (!IS_ALIGNED(pitch, pitch_align)) {
201 dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
202 __func__, __LINE__, pitch);
203 return -EINVAL;
204 }
205 if (!IS_ALIGNED(height, 8)) {
206 dev_warn(p->dev, "%s:%d cb height (%d) invalid\n",
207 __func__, __LINE__, height);
208 return -EINVAL;
209 }
210 break; 282 break;
211 case V_0280A0_ARRAY_1D_TILED_THIN1: 283 case V_0280A0_ARRAY_1D_TILED_THIN1:
212 pitch_align = max((u32)8, (u32)(track->group_size / (8 * bpe * track->nsamples))) / 8;
213 if (!IS_ALIGNED(pitch, pitch_align)) {
214 dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
215 __func__, __LINE__, pitch);
216 return -EINVAL;
217 }
218 /* avoid breaking userspace */ 284 /* avoid breaking userspace */
219 if (height > 7) 285 if (height > 7)
220 height &= ~0x7; 286 height &= ~0x7;
221 if (!IS_ALIGNED(height, 8)) {
222 dev_warn(p->dev, "%s:%d cb height (%d) invalid\n",
223 __func__, __LINE__, height);
224 return -EINVAL;
225 }
226 break; 287 break;
227 case V_0280A0_ARRAY_2D_TILED_THIN1: 288 case V_0280A0_ARRAY_2D_TILED_THIN1:
228 pitch_align = max((u32)track->nbanks,
229 (u32)(((track->group_size / 8) / (bpe * track->nsamples)) * track->nbanks)) / 8;
230 if (!IS_ALIGNED(pitch, pitch_align)) {
231 dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
232 __func__, __LINE__, pitch);
233 return -EINVAL;
234 }
235 if (!IS_ALIGNED((height / 8), track->npipes)) {
236 dev_warn(p->dev, "%s:%d cb height (%d) invalid\n",
237 __func__, __LINE__, height);
238 return -EINVAL;
239 }
240 break; 289 break;
241 default: 290 default:
242 dev_warn(p->dev, "%s invalid tiling %d for %d (0x%08X)\n", __func__, 291 dev_warn(p->dev, "%s invalid tiling %d for %d (0x%08X)\n", __func__,
@@ -244,8 +293,24 @@ static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
244 track->cb_color_info[i]); 293 track->cb_color_info[i]);
245 return -EINVAL; 294 return -EINVAL;
246 } 295 }
296
297 if (!IS_ALIGNED(pitch, pitch_align)) {
298 dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
299 __func__, __LINE__, pitch);
300 return -EINVAL;
301 }
302 if (!IS_ALIGNED(height, height_align)) {
303 dev_warn(p->dev, "%s:%d cb height (%d) invalid\n",
304 __func__, __LINE__, height);
305 return -EINVAL;
306 }
307 if (!IS_ALIGNED(base_offset, base_align)) {
308 dev_warn(p->dev, "%s offset[%d] 0x%llx not aligned\n", __func__, i, base_offset);
309 return -EINVAL;
310 }
311
247 /* check offset */ 312 /* check offset */
248 tmp = height * pitch * 8 * bpe; 313 tmp = height * pitch * bpe;
249 if ((tmp + track->cb_color_bo_offset[i]) > radeon_bo_size(track->cb_color_bo[i])) { 314 if ((tmp + track->cb_color_bo_offset[i]) > radeon_bo_size(track->cb_color_bo[i])) {
250 if (array_mode == V_0280A0_ARRAY_LINEAR_GENERAL) { 315 if (array_mode == V_0280A0_ARRAY_LINEAR_GENERAL) {
251 /* the initial DDX does bad things with the CB size occasionally */ 316 /* the initial DDX does bad things with the CB size occasionally */
@@ -260,15 +325,11 @@ static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
260 return -EINVAL; 325 return -EINVAL;
261 } 326 }
262 } 327 }
263 if (!IS_ALIGNED(track->cb_color_bo_offset[i], track->group_size)) {
264 dev_warn(p->dev, "%s offset[%d] %d not aligned\n", __func__, i, track->cb_color_bo_offset[i]);
265 return -EINVAL;
266 }
267 /* limit max tile */ 328 /* limit max tile */
268 tmp = (height * pitch * 8) >> 6; 329 tmp = (height * pitch) >> 6;
269 if (tmp < slice_tile_max) 330 if (tmp < slice_tile_max)
270 slice_tile_max = tmp; 331 slice_tile_max = tmp;
271 tmp = S_028060_PITCH_TILE_MAX(pitch - 1) | 332 tmp = S_028060_PITCH_TILE_MAX((pitch / 8) - 1) |
272 S_028060_SLICE_TILE_MAX(slice_tile_max - 1); 333 S_028060_SLICE_TILE_MAX(slice_tile_max - 1);
273 ib[track->cb_color_size_idx[i]] = tmp; 334 ib[track->cb_color_size_idx[i]] = tmp;
274 return 0; 335 return 0;
@@ -310,7 +371,12 @@ static int r600_cs_track_check(struct radeon_cs_parser *p)
310 /* Check depth buffer */ 371 /* Check depth buffer */
311 if (G_028800_STENCIL_ENABLE(track->db_depth_control) || 372 if (G_028800_STENCIL_ENABLE(track->db_depth_control) ||
312 G_028800_Z_ENABLE(track->db_depth_control)) { 373 G_028800_Z_ENABLE(track->db_depth_control)) {
313 u32 nviews, bpe, ntiles, pitch, pitch_align, height, size, slice_tile_max; 374 u32 nviews, bpe, ntiles, size, slice_tile_max;
375 u32 height, height_align, pitch, pitch_align, depth_align;
376 u64 base_offset, base_align;
377 struct array_mode_checker array_check;
378 int array_mode;
379
314 if (track->db_bo == NULL) { 380 if (track->db_bo == NULL) {
315 dev_warn(p->dev, "z/stencil with no depth buffer\n"); 381 dev_warn(p->dev, "z/stencil with no depth buffer\n");
316 return -EINVAL; 382 return -EINVAL;
@@ -353,41 +419,34 @@ static int r600_cs_track_check(struct radeon_cs_parser *p)
353 ib[track->db_depth_size_idx] = S_028000_SLICE_TILE_MAX(tmp - 1) | (track->db_depth_size & 0x3FF); 419 ib[track->db_depth_size_idx] = S_028000_SLICE_TILE_MAX(tmp - 1) | (track->db_depth_size & 0x3FF);
354 } else { 420 } else {
355 size = radeon_bo_size(track->db_bo); 421 size = radeon_bo_size(track->db_bo);
356 pitch = G_028000_PITCH_TILE_MAX(track->db_depth_size) + 1; 422 /* pitch in pixels */
423 pitch = (G_028000_PITCH_TILE_MAX(track->db_depth_size) + 1) * 8;
357 slice_tile_max = G_028000_SLICE_TILE_MAX(track->db_depth_size) + 1; 424 slice_tile_max = G_028000_SLICE_TILE_MAX(track->db_depth_size) + 1;
358 slice_tile_max *= 64; 425 slice_tile_max *= 64;
359 height = slice_tile_max / (pitch * 8); 426 height = slice_tile_max / pitch;
360 if (height > 8192) 427 if (height > 8192)
361 height = 8192; 428 height = 8192;
362 switch (G_028010_ARRAY_MODE(track->db_depth_info)) { 429 base_offset = track->db_bo_mc + track->db_offset;
430 array_mode = G_028010_ARRAY_MODE(track->db_depth_info);
431 array_check.array_mode = array_mode;
432 array_check.group_size = track->group_size;
433 array_check.nbanks = track->nbanks;
434 array_check.npipes = track->npipes;
435 array_check.nsamples = track->nsamples;
436 array_check.bpe = bpe;
437 if (r600_get_array_mode_alignment(&array_check,
438 &pitch_align, &height_align, &depth_align, &base_align)) {
439 dev_warn(p->dev, "%s invalid tiling %d (0x%08X)\n", __func__,
440 G_028010_ARRAY_MODE(track->db_depth_info),
441 track->db_depth_info);
442 return -EINVAL;
443 }
444 switch (array_mode) {
363 case V_028010_ARRAY_1D_TILED_THIN1: 445 case V_028010_ARRAY_1D_TILED_THIN1:
364 pitch_align = (max((u32)8, (u32)(track->group_size / (8 * bpe))) / 8);
365 if (!IS_ALIGNED(pitch, pitch_align)) {
366 dev_warn(p->dev, "%s:%d db pitch (%d) invalid\n",
367 __func__, __LINE__, pitch);
368 return -EINVAL;
369 }
370 /* don't break userspace */ 446 /* don't break userspace */
371 height &= ~0x7; 447 height &= ~0x7;
372 if (!IS_ALIGNED(height, 8)) {
373 dev_warn(p->dev, "%s:%d db height (%d) invalid\n",
374 __func__, __LINE__, height);
375 return -EINVAL;
376 }
377 break; 448 break;
378 case V_028010_ARRAY_2D_TILED_THIN1: 449 case V_028010_ARRAY_2D_TILED_THIN1:
379 pitch_align = max((u32)track->nbanks,
380 (u32)(((track->group_size / 8) / bpe) * track->nbanks)) / 8;
381 if (!IS_ALIGNED(pitch, pitch_align)) {
382 dev_warn(p->dev, "%s:%d db pitch (%d) invalid\n",
383 __func__, __LINE__, pitch);
384 return -EINVAL;
385 }
386 if (!IS_ALIGNED((height / 8), track->npipes)) {
387 dev_warn(p->dev, "%s:%d db height (%d) invalid\n",
388 __func__, __LINE__, height);
389 return -EINVAL;
390 }
391 break; 450 break;
392 default: 451 default:
393 dev_warn(p->dev, "%s invalid tiling %d (0x%08X)\n", __func__, 452 dev_warn(p->dev, "%s invalid tiling %d (0x%08X)\n", __func__,
@@ -395,15 +454,27 @@ static int r600_cs_track_check(struct radeon_cs_parser *p)
395 track->db_depth_info); 454 track->db_depth_info);
396 return -EINVAL; 455 return -EINVAL;
397 } 456 }
398 if (!IS_ALIGNED(track->db_offset, track->group_size)) { 457
399 dev_warn(p->dev, "%s offset[%d] %d not aligned\n", __func__, i, track->db_offset); 458 if (!IS_ALIGNED(pitch, pitch_align)) {
459 dev_warn(p->dev, "%s:%d db pitch (%d) invalid\n",
460 __func__, __LINE__, pitch);
461 return -EINVAL;
462 }
463 if (!IS_ALIGNED(height, height_align)) {
464 dev_warn(p->dev, "%s:%d db height (%d) invalid\n",
465 __func__, __LINE__, height);
400 return -EINVAL; 466 return -EINVAL;
401 } 467 }
468 if (!IS_ALIGNED(base_offset, base_align)) {
469 dev_warn(p->dev, "%s offset[%d] 0x%llx not aligned\n", __func__, i, base_offset);
470 return -EINVAL;
471 }
472
402 ntiles = G_028000_SLICE_TILE_MAX(track->db_depth_size) + 1; 473 ntiles = G_028000_SLICE_TILE_MAX(track->db_depth_size) + 1;
403 nviews = G_028004_SLICE_MAX(track->db_depth_view) + 1; 474 nviews = G_028004_SLICE_MAX(track->db_depth_view) + 1;
404 tmp = ntiles * bpe * 64 * nviews; 475 tmp = ntiles * bpe * 64 * nviews;
405 if ((tmp + track->db_offset) > radeon_bo_size(track->db_bo)) { 476 if ((tmp + track->db_offset) > radeon_bo_size(track->db_bo)) {
406 dev_warn(p->dev, "z/stencil buffer too small (0x%08X %d %d %d -> %d have %ld)\n", 477 dev_warn(p->dev, "z/stencil buffer too small (0x%08X %d %d %d -> %u have %lu)\n",
407 track->db_depth_size, ntiles, nviews, bpe, tmp + track->db_offset, 478 track->db_depth_size, ntiles, nviews, bpe, tmp + track->db_offset,
408 radeon_bo_size(track->db_bo)); 479 radeon_bo_size(track->db_bo));
409 return -EINVAL; 480 return -EINVAL;
@@ -954,6 +1025,7 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
954 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1025 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
955 track->cb_color_base_last[tmp] = ib[idx]; 1026 track->cb_color_base_last[tmp] = ib[idx];
956 track->cb_color_bo[tmp] = reloc->robj; 1027 track->cb_color_bo[tmp] = reloc->robj;
1028 track->cb_color_bo_mc[tmp] = reloc->lobj.gpu_offset;
957 break; 1029 break;
958 case DB_DEPTH_BASE: 1030 case DB_DEPTH_BASE:
959 r = r600_cs_packet_next_reloc(p, &reloc); 1031 r = r600_cs_packet_next_reloc(p, &reloc);
@@ -965,6 +1037,7 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
965 track->db_offset = radeon_get_ib_value(p, idx) << 8; 1037 track->db_offset = radeon_get_ib_value(p, idx) << 8;
966 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1038 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
967 track->db_bo = reloc->robj; 1039 track->db_bo = reloc->robj;
1040 track->db_bo_mc = reloc->lobj.gpu_offset;
968 break; 1041 break;
969 case DB_HTILE_DATA_BASE: 1042 case DB_HTILE_DATA_BASE:
970 case SQ_PGM_START_FS: 1043 case SQ_PGM_START_FS:
@@ -1086,16 +1159,25 @@ static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels
1086static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx, 1159static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
1087 struct radeon_bo *texture, 1160 struct radeon_bo *texture,
1088 struct radeon_bo *mipmap, 1161 struct radeon_bo *mipmap,
1162 u64 base_offset,
1163 u64 mip_offset,
1089 u32 tiling_flags) 1164 u32 tiling_flags)
1090{ 1165{
1091 struct r600_cs_track *track = p->track; 1166 struct r600_cs_track *track = p->track;
1092 u32 nfaces, nlevels, blevel, w0, h0, d0, bpe = 0; 1167 u32 nfaces, nlevels, blevel, w0, h0, d0, bpe = 0;
1093 u32 word0, word1, l0_size, mipmap_size, pitch, pitch_align; 1168 u32 word0, word1, l0_size, mipmap_size;
1169 u32 height_align, pitch, pitch_align, depth_align;
1170 u64 base_align;
1171 struct array_mode_checker array_check;
1094 1172
1095 /* on legacy kernel we don't perform advanced check */ 1173 /* on legacy kernel we don't perform advanced check */
1096 if (p->rdev == NULL) 1174 if (p->rdev == NULL)
1097 return 0; 1175 return 0;
1098 1176
1177 /* convert to bytes */
1178 base_offset <<= 8;
1179 mip_offset <<= 8;
1180
1099 word0 = radeon_get_ib_value(p, idx + 0); 1181 word0 = radeon_get_ib_value(p, idx + 0);
1100 if (tiling_flags & RADEON_TILING_MACRO) 1182 if (tiling_flags & RADEON_TILING_MACRO)
1101 word0 |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1); 1183 word0 |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1);
@@ -1128,46 +1210,38 @@ static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 i
1128 return -EINVAL; 1210 return -EINVAL;
1129 } 1211 }
1130 1212
1131 pitch = G_038000_PITCH(word0) + 1; 1213 /* pitch in texels */
1132 switch (G_038000_TILE_MODE(word0)) { 1214 pitch = (G_038000_PITCH(word0) + 1) * 8;
1133 case V_038000_ARRAY_LINEAR_GENERAL: 1215 array_check.array_mode = G_038000_TILE_MODE(word0);
1134 pitch_align = 1; 1216 array_check.group_size = track->group_size;
1135 /* XXX check height align */ 1217 array_check.nbanks = track->nbanks;
1136 break; 1218 array_check.npipes = track->npipes;
1137 case V_038000_ARRAY_LINEAR_ALIGNED: 1219 array_check.nsamples = 1;
1138 pitch_align = max((u32)64, (u32)(track->group_size / bpe)) / 8; 1220 array_check.bpe = bpe;
1139 if (!IS_ALIGNED(pitch, pitch_align)) { 1221 if (r600_get_array_mode_alignment(&array_check,
1140 dev_warn(p->dev, "%s:%d tex pitch (%d) invalid\n", 1222 &pitch_align, &height_align, &depth_align, &base_align)) {
1141 __func__, __LINE__, pitch); 1223 dev_warn(p->dev, "%s:%d tex array mode (%d) invalid\n",
1142 return -EINVAL; 1224 __func__, __LINE__, G_038000_TILE_MODE(word0));
1143 } 1225 return -EINVAL;
1144 /* XXX check height align */ 1226 }
1145 break; 1227
1146 case V_038000_ARRAY_1D_TILED_THIN1: 1228 /* XXX check height as well... */
1147 pitch_align = max((u32)8, (u32)(track->group_size / (8 * bpe))) / 8; 1229
1148 if (!IS_ALIGNED(pitch, pitch_align)) { 1230 if (!IS_ALIGNED(pitch, pitch_align)) {
1149 dev_warn(p->dev, "%s:%d tex pitch (%d) invalid\n", 1231 dev_warn(p->dev, "%s:%d tex pitch (%d) invalid\n",
1150 __func__, __LINE__, pitch); 1232 __func__, __LINE__, pitch);
1151 return -EINVAL; 1233 return -EINVAL;
1152 } 1234 }
1153 /* XXX check height align */ 1235 if (!IS_ALIGNED(base_offset, base_align)) {
1154 break; 1236 dev_warn(p->dev, "%s:%d tex base offset (0x%llx) invalid\n",
1155 case V_038000_ARRAY_2D_TILED_THIN1: 1237 __func__, __LINE__, base_offset);
1156 pitch_align = max((u32)track->nbanks, 1238 return -EINVAL;
1157 (u32)(((track->group_size / 8) / bpe) * track->nbanks)) / 8; 1239 }
1158 if (!IS_ALIGNED(pitch, pitch_align)) { 1240 if (!IS_ALIGNED(mip_offset, base_align)) {
1159 dev_warn(p->dev, "%s:%d tex pitch (%d) invalid\n", 1241 dev_warn(p->dev, "%s:%d tex mip offset (0x%llx) invalid\n",
1160 __func__, __LINE__, pitch); 1242 __func__, __LINE__, mip_offset);
1161 return -EINVAL;
1162 }
1163 /* XXX check height align */
1164 break;
1165 default:
1166 dev_warn(p->dev, "%s invalid tiling %d (0x%08X)\n", __func__,
1167 G_038000_TILE_MODE(word0), word0);
1168 return -EINVAL; 1243 return -EINVAL;
1169 } 1244 }
1170 /* XXX check offset align */
1171 1245
1172 word0 = radeon_get_ib_value(p, idx + 4); 1246 word0 = radeon_get_ib_value(p, idx + 4);
1173 word1 = radeon_get_ib_value(p, idx + 5); 1247 word1 = radeon_get_ib_value(p, idx + 5);
@@ -1402,7 +1476,10 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1402 mip_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1476 mip_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1403 mipmap = reloc->robj; 1477 mipmap = reloc->robj;
1404 r = r600_check_texture_resource(p, idx+(i*7)+1, 1478 r = r600_check_texture_resource(p, idx+(i*7)+1,
1405 texture, mipmap, reloc->lobj.tiling_flags); 1479 texture, mipmap,
1480 base_offset + radeon_get_ib_value(p, idx+1+(i*7)+2),
1481 mip_offset + radeon_get_ib_value(p, idx+1+(i*7)+3),
1482 reloc->lobj.tiling_flags);
1406 if (r) 1483 if (r)
1407 return r; 1484 return r;
1408 ib[idx+1+(i*7)+2] += base_offset; 1485 ib[idx+1+(i*7)+2] += base_offset;
diff --git a/drivers/gpu/drm/radeon/r600_reg.h b/drivers/gpu/drm/radeon/r600_reg.h
index d84612ae47e0..33cda016b083 100644
--- a/drivers/gpu/drm/radeon/r600_reg.h
+++ b/drivers/gpu/drm/radeon/r600_reg.h
@@ -86,6 +86,7 @@
86#define R600_HDP_NONSURFACE_BASE 0x2c04 86#define R600_HDP_NONSURFACE_BASE 0x2c04
87 87
88#define R600_BUS_CNTL 0x5420 88#define R600_BUS_CNTL 0x5420
89# define R600_BIOS_ROM_DIS (1 << 1)
89#define R600_CONFIG_CNTL 0x5424 90#define R600_CONFIG_CNTL 0x5424
90#define R600_CONFIG_MEMSIZE 0x5428 91#define R600_CONFIG_MEMSIZE 0x5428
91#define R600_CONFIG_F0_BASE 0x542C 92#define R600_CONFIG_F0_BASE 0x542C
diff --git a/drivers/gpu/drm/radeon/r600d.h b/drivers/gpu/drm/radeon/r600d.h
index 966a793e225b..bff4dc4f410f 100644
--- a/drivers/gpu/drm/radeon/r600d.h
+++ b/drivers/gpu/drm/radeon/r600d.h
@@ -51,6 +51,12 @@
51#define PTE_READABLE (1 << 5) 51#define PTE_READABLE (1 << 5)
52#define PTE_WRITEABLE (1 << 6) 52#define PTE_WRITEABLE (1 << 6)
53 53
54/* tiling bits */
55#define ARRAY_LINEAR_GENERAL 0x00000000
56#define ARRAY_LINEAR_ALIGNED 0x00000001
57#define ARRAY_1D_TILED_THIN1 0x00000002
58#define ARRAY_2D_TILED_THIN1 0x00000004
59
54/* Registers */ 60/* Registers */
55#define ARB_POP 0x2418 61#define ARB_POP 0x2418
56#define ENABLE_TC128 (1 << 30) 62#define ENABLE_TC128 (1 << 30)
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 73f600d39ad4..3a7095743d44 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -1262,6 +1262,10 @@ void r100_pll_errata_after_index(struct radeon_device *rdev);
1262 (rdev->family == CHIP_RS400) || \ 1262 (rdev->family == CHIP_RS400) || \
1263 (rdev->family == CHIP_RS480)) 1263 (rdev->family == CHIP_RS480))
1264#define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600)) 1264#define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
1265#define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
1266 (rdev->family == CHIP_RS690) || \
1267 (rdev->family == CHIP_RS740) || \
1268 (rdev->family >= CHIP_R600))
1265#define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620)) 1269#define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
1266#define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730)) 1270#define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
1267#define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR)) 1271#define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index 04cac7ec9039..bc5a2c3382d9 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -98,6 +98,14 @@ static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_dev
98 } 98 }
99 } 99 }
100 100
101 /* some DCE3 boards have bad data for this entry */
102 if (ASIC_IS_DCE3(rdev)) {
103 if ((i == 4) &&
104 (gpio->usClkMaskRegisterIndex == 0x1fda) &&
105 (gpio->sucI2cId.ucAccess == 0x94))
106 gpio->sucI2cId.ucAccess = 0x14;
107 }
108
101 if (gpio->sucI2cId.ucAccess == id) { 109 if (gpio->sucI2cId.ucAccess == id) {
102 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4; 110 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
103 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4; 111 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
@@ -174,6 +182,14 @@ void radeon_atombios_i2c_init(struct radeon_device *rdev)
174 } 182 }
175 } 183 }
176 184
185 /* some DCE3 boards have bad data for this entry */
186 if (ASIC_IS_DCE3(rdev)) {
187 if ((i == 4) &&
188 (gpio->usClkMaskRegisterIndex == 0x1fda) &&
189 (gpio->sucI2cId.ucAccess == 0x94))
190 gpio->sucI2cId.ucAccess = 0x14;
191 }
192
177 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4; 193 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
178 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4; 194 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
179 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4; 195 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
@@ -526,8 +542,6 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
526 if (crev < 2) 542 if (crev < 2)
527 return false; 543 return false;
528 544
529 router.valid = false;
530
531 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset); 545 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
532 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *) 546 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
533 (ctx->bios + data_offset + 547 (ctx->bios + data_offset +
@@ -624,6 +638,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
624 if (connector_type == DRM_MODE_CONNECTOR_Unknown) 638 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
625 continue; 639 continue;
626 640
641 router.ddc_valid = false;
642 router.cd_valid = false;
627 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) { 643 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
628 uint8_t grph_obj_id, grph_obj_num, grph_obj_type; 644 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
629 645
@@ -647,9 +663,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
647 usDeviceTag)); 663 usDeviceTag));
648 664
649 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) { 665 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
650 router.valid = false;
651 for (k = 0; k < router_obj->ucNumberOfObjects; k++) { 666 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
652 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].usObjectID); 667 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
653 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) { 668 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
654 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *) 669 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
655 (ctx->bios + data_offset + 670 (ctx->bios + data_offset +
@@ -657,6 +672,7 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
657 ATOM_I2C_RECORD *i2c_record; 672 ATOM_I2C_RECORD *i2c_record;
658 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config; 673 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
659 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path; 674 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
675 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
660 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table = 676 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
661 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *) 677 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
662 (ctx->bios + data_offset + 678 (ctx->bios + data_offset +
@@ -690,10 +706,18 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
690 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE: 706 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
691 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *) 707 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
692 record; 708 record;
693 router.valid = true; 709 router.ddc_valid = true;
694 router.mux_type = ddc_path->ucMuxType; 710 router.ddc_mux_type = ddc_path->ucMuxType;
695 router.mux_control_pin = ddc_path->ucMuxControlPin; 711 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
696 router.mux_state = ddc_path->ucMuxState[enum_id]; 712 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
713 break;
714 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
715 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
716 record;
717 router.cd_valid = true;
718 router.cd_mux_type = cd_path->ucMuxType;
719 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
720 router.cd_mux_state = cd_path->ucMuxState[enum_id];
697 break; 721 break;
698 } 722 }
699 record = (ATOM_COMMON_RECORD_HEADER *) 723 record = (ATOM_COMMON_RECORD_HEADER *)
@@ -860,7 +884,8 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
860 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE; 884 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
861 struct radeon_router router; 885 struct radeon_router router;
862 886
863 router.valid = false; 887 router.ddc_valid = false;
888 router.cd_valid = false;
864 889
865 bios_connectors = kzalloc(bc_size, GFP_KERNEL); 890 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
866 if (!bios_connectors) 891 if (!bios_connectors)
diff --git a/drivers/gpu/drm/radeon/radeon_benchmark.c b/drivers/gpu/drm/radeon/radeon_benchmark.c
index 7932dc4d6b90..c558685cc637 100644
--- a/drivers/gpu/drm/radeon/radeon_benchmark.c
+++ b/drivers/gpu/drm/radeon/radeon_benchmark.c
@@ -41,7 +41,7 @@ void radeon_benchmark_move(struct radeon_device *rdev, unsigned bsize,
41 41
42 size = bsize; 42 size = bsize;
43 n = 1024; 43 n = 1024;
44 r = radeon_bo_create(rdev, NULL, size, true, sdomain, &sobj); 44 r = radeon_bo_create(rdev, NULL, size, PAGE_SIZE, true, sdomain, &sobj);
45 if (r) { 45 if (r) {
46 goto out_cleanup; 46 goto out_cleanup;
47 } 47 }
@@ -53,7 +53,7 @@ void radeon_benchmark_move(struct radeon_device *rdev, unsigned bsize,
53 if (r) { 53 if (r) {
54 goto out_cleanup; 54 goto out_cleanup;
55 } 55 }
56 r = radeon_bo_create(rdev, NULL, size, true, ddomain, &dobj); 56 r = radeon_bo_create(rdev, NULL, size, PAGE_SIZE, true, ddomain, &dobj);
57 if (r) { 57 if (r) {
58 goto out_cleanup; 58 goto out_cleanup;
59 } 59 }
diff --git a/drivers/gpu/drm/radeon/radeon_bios.c b/drivers/gpu/drm/radeon/radeon_bios.c
index 654787ec43f4..8f2c7b50dcf5 100644
--- a/drivers/gpu/drm/radeon/radeon_bios.c
+++ b/drivers/gpu/drm/radeon/radeon_bios.c
@@ -130,6 +130,7 @@ static bool radeon_atrm_get_bios(struct radeon_device *rdev)
130 } 130 }
131 return true; 131 return true;
132} 132}
133
133static bool r700_read_disabled_bios(struct radeon_device *rdev) 134static bool r700_read_disabled_bios(struct radeon_device *rdev)
134{ 135{
135 uint32_t viph_control; 136 uint32_t viph_control;
@@ -143,7 +144,7 @@ static bool r700_read_disabled_bios(struct radeon_device *rdev)
143 bool r; 144 bool r;
144 145
145 viph_control = RREG32(RADEON_VIPH_CONTROL); 146 viph_control = RREG32(RADEON_VIPH_CONTROL);
146 bus_cntl = RREG32(RADEON_BUS_CNTL); 147 bus_cntl = RREG32(R600_BUS_CNTL);
147 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL); 148 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
148 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL); 149 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
149 vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL); 150 vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
@@ -152,7 +153,7 @@ static bool r700_read_disabled_bios(struct radeon_device *rdev)
152 /* disable VIP */ 153 /* disable VIP */
153 WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN)); 154 WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
154 /* enable the rom */ 155 /* enable the rom */
155 WREG32(RADEON_BUS_CNTL, (bus_cntl & ~RADEON_BUS_BIOS_DIS_ROM)); 156 WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
156 /* Disable VGA mode */ 157 /* Disable VGA mode */
157 WREG32(AVIVO_D1VGA_CONTROL, 158 WREG32(AVIVO_D1VGA_CONTROL,
158 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 159 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
@@ -191,7 +192,7 @@ static bool r700_read_disabled_bios(struct radeon_device *rdev)
191 cg_spll_status = RREG32(R600_CG_SPLL_STATUS); 192 cg_spll_status = RREG32(R600_CG_SPLL_STATUS);
192 } 193 }
193 WREG32(RADEON_VIPH_CONTROL, viph_control); 194 WREG32(RADEON_VIPH_CONTROL, viph_control);
194 WREG32(RADEON_BUS_CNTL, bus_cntl); 195 WREG32(R600_BUS_CNTL, bus_cntl);
195 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control); 196 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
196 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control); 197 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
197 WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control); 198 WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
@@ -216,7 +217,7 @@ static bool r600_read_disabled_bios(struct radeon_device *rdev)
216 bool r; 217 bool r;
217 218
218 viph_control = RREG32(RADEON_VIPH_CONTROL); 219 viph_control = RREG32(RADEON_VIPH_CONTROL);
219 bus_cntl = RREG32(RADEON_BUS_CNTL); 220 bus_cntl = RREG32(R600_BUS_CNTL);
220 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL); 221 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
221 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL); 222 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
222 vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL); 223 vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
@@ -231,7 +232,7 @@ static bool r600_read_disabled_bios(struct radeon_device *rdev)
231 /* disable VIP */ 232 /* disable VIP */
232 WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN)); 233 WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
233 /* enable the rom */ 234 /* enable the rom */
234 WREG32(RADEON_BUS_CNTL, (bus_cntl & ~RADEON_BUS_BIOS_DIS_ROM)); 235 WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
235 /* Disable VGA mode */ 236 /* Disable VGA mode */
236 WREG32(AVIVO_D1VGA_CONTROL, 237 WREG32(AVIVO_D1VGA_CONTROL,
237 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 238 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
@@ -262,7 +263,7 @@ static bool r600_read_disabled_bios(struct radeon_device *rdev)
262 263
263 /* restore regs */ 264 /* restore regs */
264 WREG32(RADEON_VIPH_CONTROL, viph_control); 265 WREG32(RADEON_VIPH_CONTROL, viph_control);
265 WREG32(RADEON_BUS_CNTL, bus_cntl); 266 WREG32(R600_BUS_CNTL, bus_cntl);
266 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control); 267 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
267 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control); 268 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
268 WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control); 269 WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index 7b7ea269549c..137b8075f6e7 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -571,6 +571,7 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
571 } 571 }
572 572
573 if (clk_mask && data_mask) { 573 if (clk_mask && data_mask) {
574 /* system specific masks */
574 i2c.mask_clk_mask = clk_mask; 575 i2c.mask_clk_mask = clk_mask;
575 i2c.mask_data_mask = data_mask; 576 i2c.mask_data_mask = data_mask;
576 i2c.a_clk_mask = clk_mask; 577 i2c.a_clk_mask = clk_mask;
@@ -579,7 +580,19 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
579 i2c.en_data_mask = data_mask; 580 i2c.en_data_mask = data_mask;
580 i2c.y_clk_mask = clk_mask; 581 i2c.y_clk_mask = clk_mask;
581 i2c.y_data_mask = data_mask; 582 i2c.y_data_mask = data_mask;
583 } else if ((ddc_line == RADEON_GPIOPAD_MASK) ||
584 (ddc_line == RADEON_MDGPIO_MASK)) {
585 /* default gpiopad masks */
586 i2c.mask_clk_mask = (0x20 << 8);
587 i2c.mask_data_mask = 0x80;
588 i2c.a_clk_mask = (0x20 << 8);
589 i2c.a_data_mask = 0x80;
590 i2c.en_clk_mask = (0x20 << 8);
591 i2c.en_data_mask = 0x80;
592 i2c.y_clk_mask = (0x20 << 8);
593 i2c.y_data_mask = 0x80;
582 } else { 594 } else {
595 /* default masks for ddc pads */
583 i2c.mask_clk_mask = RADEON_GPIO_EN_1; 596 i2c.mask_clk_mask = RADEON_GPIO_EN_1;
584 i2c.mask_data_mask = RADEON_GPIO_EN_0; 597 i2c.mask_data_mask = RADEON_GPIO_EN_0;
585 i2c.a_clk_mask = RADEON_GPIO_A_1; 598 i2c.a_clk_mask = RADEON_GPIO_A_1;
@@ -716,7 +729,7 @@ void radeon_combios_i2c_init(struct radeon_device *rdev)
716 clk = RBIOS8(offset + 3 + (i * 5) + 3); 729 clk = RBIOS8(offset + 3 + (i * 5) + 3);
717 data = RBIOS8(offset + 3 + (i * 5) + 4); 730 data = RBIOS8(offset + 3 + (i * 5) + 4);
718 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 731 i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
719 clk, data); 732 (1 << clk), (1 << data));
720 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK"); 733 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
721 break; 734 break;
722 } 735 }
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 4dac4b0a02ee..8afaf7a7459e 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -183,13 +183,13 @@ radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
183 continue; 183 continue;
184 184
185 if (priority == true) { 185 if (priority == true) {
186 DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict)); 186 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
187 DRM_INFO("in favor of %s\n", drm_get_connector_name(connector)); 187 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(connector));
188 conflict->status = connector_status_disconnected; 188 conflict->status = connector_status_disconnected;
189 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected); 189 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
190 } else { 190 } else {
191 DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector)); 191 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
192 DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict)); 192 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(conflict));
193 current_status = connector_status_disconnected; 193 current_status = connector_status_disconnected;
194 } 194 }
195 break; 195 break;
@@ -432,13 +432,13 @@ static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
432 mode->vdisplay == native_mode->vdisplay) { 432 mode->vdisplay == native_mode->vdisplay) {
433 *native_mode = *mode; 433 *native_mode = *mode;
434 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V); 434 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
435 DRM_INFO("Determined LVDS native mode details from EDID\n"); 435 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
436 break; 436 break;
437 } 437 }
438 } 438 }
439 } 439 }
440 if (!native_mode->clock) { 440 if (!native_mode->clock) {
441 DRM_INFO("No LVDS native mode details, disabling RMX\n"); 441 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
442 radeon_encoder->rmx_type = RMX_OFF; 442 radeon_encoder->rmx_type = RMX_OFF;
443 } 443 }
444} 444}
@@ -1008,9 +1008,21 @@ static void radeon_dp_connector_destroy(struct drm_connector *connector)
1008static int radeon_dp_get_modes(struct drm_connector *connector) 1008static int radeon_dp_get_modes(struct drm_connector *connector)
1009{ 1009{
1010 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1010 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1011 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1011 int ret; 1012 int ret;
1012 1013
1014 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1015 if (!radeon_dig_connector->edp_on)
1016 atombios_set_edp_panel_power(connector,
1017 ATOM_TRANSMITTER_ACTION_POWER_ON);
1018 }
1013 ret = radeon_ddc_get_modes(radeon_connector); 1019 ret = radeon_ddc_get_modes(radeon_connector);
1020 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1021 if (!radeon_dig_connector->edp_on)
1022 atombios_set_edp_panel_power(connector,
1023 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1024 }
1025
1014 return ret; 1026 return ret;
1015} 1027}
1016 1028
@@ -1029,8 +1041,14 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
1029 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) { 1041 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1030 /* eDP is always DP */ 1042 /* eDP is always DP */
1031 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT; 1043 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1044 if (!radeon_dig_connector->edp_on)
1045 atombios_set_edp_panel_power(connector,
1046 ATOM_TRANSMITTER_ACTION_POWER_ON);
1032 if (radeon_dp_getdpcd(radeon_connector)) 1047 if (radeon_dp_getdpcd(radeon_connector))
1033 ret = connector_status_connected; 1048 ret = connector_status_connected;
1049 if (!radeon_dig_connector->edp_on)
1050 atombios_set_edp_panel_power(connector,
1051 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1034 } else { 1052 } else {
1035 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector); 1053 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1036 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) { 1054 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
@@ -1116,7 +1134,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1116 radeon_connector->shared_ddc = true; 1134 radeon_connector->shared_ddc = true;
1117 shared_ddc = true; 1135 shared_ddc = true;
1118 } 1136 }
1119 if (radeon_connector->router_bus && router->valid && 1137 if (radeon_connector->router_bus && router->ddc_valid &&
1120 (radeon_connector->router.router_id == router->router_id)) { 1138 (radeon_connector->router.router_id == router->router_id)) {
1121 radeon_connector->shared_ddc = false; 1139 radeon_connector->shared_ddc = false;
1122 shared_ddc = false; 1140 shared_ddc = false;
@@ -1136,7 +1154,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1136 radeon_connector->connector_object_id = connector_object_id; 1154 radeon_connector->connector_object_id = connector_object_id;
1137 radeon_connector->hpd = *hpd; 1155 radeon_connector->hpd = *hpd;
1138 radeon_connector->router = *router; 1156 radeon_connector->router = *router;
1139 if (router->valid) { 1157 if (router->ddc_valid || router->cd_valid) {
1140 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info); 1158 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1141 if (!radeon_connector->router_bus) 1159 if (!radeon_connector->router_bus)
1142 goto failed; 1160 goto failed;
@@ -1157,6 +1175,8 @@ radeon_add_atom_connector(struct drm_device *dev,
1157 /* no HPD on analog connectors */ 1175 /* no HPD on analog connectors */
1158 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 1176 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1159 connector->polled = DRM_CONNECTOR_POLL_CONNECT; 1177 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1178 connector->interlace_allowed = true;
1179 connector->doublescan_allowed = true;
1160 break; 1180 break;
1161 case DRM_MODE_CONNECTOR_DVIA: 1181 case DRM_MODE_CONNECTOR_DVIA:
1162 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1182 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
@@ -1172,6 +1192,8 @@ radeon_add_atom_connector(struct drm_device *dev,
1172 1); 1192 1);
1173 /* no HPD on analog connectors */ 1193 /* no HPD on analog connectors */
1174 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 1194 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1195 connector->interlace_allowed = true;
1196 connector->doublescan_allowed = true;
1175 break; 1197 break;
1176 case DRM_MODE_CONNECTOR_DVII: 1198 case DRM_MODE_CONNECTOR_DVII:
1177 case DRM_MODE_CONNECTOR_DVID: 1199 case DRM_MODE_CONNECTOR_DVID:
@@ -1208,6 +1230,11 @@ radeon_add_atom_connector(struct drm_device *dev,
1208 rdev->mode_info.load_detect_property, 1230 rdev->mode_info.load_detect_property,
1209 1); 1231 1);
1210 } 1232 }
1233 connector->interlace_allowed = true;
1234 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1235 connector->doublescan_allowed = true;
1236 else
1237 connector->doublescan_allowed = false;
1211 break; 1238 break;
1212 case DRM_MODE_CONNECTOR_HDMIA: 1239 case DRM_MODE_CONNECTOR_HDMIA:
1213 case DRM_MODE_CONNECTOR_HDMIB: 1240 case DRM_MODE_CONNECTOR_HDMIB:
@@ -1238,6 +1265,11 @@ radeon_add_atom_connector(struct drm_device *dev,
1238 0); 1265 0);
1239 } 1266 }
1240 subpixel_order = SubPixelHorizontalRGB; 1267 subpixel_order = SubPixelHorizontalRGB;
1268 connector->interlace_allowed = true;
1269 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1270 connector->doublescan_allowed = true;
1271 else
1272 connector->doublescan_allowed = false;
1241 break; 1273 break;
1242 case DRM_MODE_CONNECTOR_DisplayPort: 1274 case DRM_MODE_CONNECTOR_DisplayPort:
1243 case DRM_MODE_CONNECTOR_eDP: 1275 case DRM_MODE_CONNECTOR_eDP:
@@ -1275,6 +1307,9 @@ radeon_add_atom_connector(struct drm_device *dev,
1275 rdev->mode_info.underscan_vborder_property, 1307 rdev->mode_info.underscan_vborder_property,
1276 0); 1308 0);
1277 } 1309 }
1310 connector->interlace_allowed = true;
1311 /* in theory with a DP to VGA converter... */
1312 connector->doublescan_allowed = false;
1278 break; 1313 break;
1279 case DRM_MODE_CONNECTOR_SVIDEO: 1314 case DRM_MODE_CONNECTOR_SVIDEO:
1280 case DRM_MODE_CONNECTOR_Composite: 1315 case DRM_MODE_CONNECTOR_Composite:
@@ -1290,6 +1325,8 @@ radeon_add_atom_connector(struct drm_device *dev,
1290 radeon_atombios_get_tv_info(rdev)); 1325 radeon_atombios_get_tv_info(rdev));
1291 /* no HPD on analog connectors */ 1326 /* no HPD on analog connectors */
1292 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 1327 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1328 connector->interlace_allowed = false;
1329 connector->doublescan_allowed = false;
1293 break; 1330 break;
1294 case DRM_MODE_CONNECTOR_LVDS: 1331 case DRM_MODE_CONNECTOR_LVDS:
1295 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); 1332 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
@@ -1308,6 +1345,8 @@ radeon_add_atom_connector(struct drm_device *dev,
1308 dev->mode_config.scaling_mode_property, 1345 dev->mode_config.scaling_mode_property,
1309 DRM_MODE_SCALE_FULLSCREEN); 1346 DRM_MODE_SCALE_FULLSCREEN);
1310 subpixel_order = SubPixelHorizontalRGB; 1347 subpixel_order = SubPixelHorizontalRGB;
1348 connector->interlace_allowed = false;
1349 connector->doublescan_allowed = false;
1311 break; 1350 break;
1312 } 1351 }
1313 1352
@@ -1385,6 +1424,8 @@ radeon_add_legacy_connector(struct drm_device *dev,
1385 /* no HPD on analog connectors */ 1424 /* no HPD on analog connectors */
1386 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 1425 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1387 connector->polled = DRM_CONNECTOR_POLL_CONNECT; 1426 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1427 connector->interlace_allowed = true;
1428 connector->doublescan_allowed = true;
1388 break; 1429 break;
1389 case DRM_MODE_CONNECTOR_DVIA: 1430 case DRM_MODE_CONNECTOR_DVIA:
1390 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1431 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
@@ -1400,6 +1441,8 @@ radeon_add_legacy_connector(struct drm_device *dev,
1400 1); 1441 1);
1401 /* no HPD on analog connectors */ 1442 /* no HPD on analog connectors */
1402 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 1443 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1444 connector->interlace_allowed = true;
1445 connector->doublescan_allowed = true;
1403 break; 1446 break;
1404 case DRM_MODE_CONNECTOR_DVII: 1447 case DRM_MODE_CONNECTOR_DVII:
1405 case DRM_MODE_CONNECTOR_DVID: 1448 case DRM_MODE_CONNECTOR_DVID:
@@ -1417,6 +1460,11 @@ radeon_add_legacy_connector(struct drm_device *dev,
1417 1); 1460 1);
1418 } 1461 }
1419 subpixel_order = SubPixelHorizontalRGB; 1462 subpixel_order = SubPixelHorizontalRGB;
1463 connector->interlace_allowed = true;
1464 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1465 connector->doublescan_allowed = true;
1466 else
1467 connector->doublescan_allowed = false;
1420 break; 1468 break;
1421 case DRM_MODE_CONNECTOR_SVIDEO: 1469 case DRM_MODE_CONNECTOR_SVIDEO:
1422 case DRM_MODE_CONNECTOR_Composite: 1470 case DRM_MODE_CONNECTOR_Composite:
@@ -1439,6 +1487,8 @@ radeon_add_legacy_connector(struct drm_device *dev,
1439 radeon_combios_get_tv_info(rdev)); 1487 radeon_combios_get_tv_info(rdev));
1440 /* no HPD on analog connectors */ 1488 /* no HPD on analog connectors */
1441 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 1489 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1490 connector->interlace_allowed = false;
1491 connector->doublescan_allowed = false;
1442 break; 1492 break;
1443 case DRM_MODE_CONNECTOR_LVDS: 1493 case DRM_MODE_CONNECTOR_LVDS:
1444 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); 1494 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
@@ -1452,6 +1502,8 @@ radeon_add_legacy_connector(struct drm_device *dev,
1452 dev->mode_config.scaling_mode_property, 1502 dev->mode_config.scaling_mode_property,
1453 DRM_MODE_SCALE_FULLSCREEN); 1503 DRM_MODE_SCALE_FULLSCREEN);
1454 subpixel_order = SubPixelHorizontalRGB; 1504 subpixel_order = SubPixelHorizontalRGB;
1505 connector->interlace_allowed = false;
1506 connector->doublescan_allowed = false;
1455 break; 1507 break;
1456 } 1508 }
1457 1509
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index 8adfedfe547f..e12e79326cb1 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -180,7 +180,7 @@ int radeon_wb_init(struct radeon_device *rdev)
180 int r; 180 int r;
181 181
182 if (rdev->wb.wb_obj == NULL) { 182 if (rdev->wb.wb_obj == NULL) {
183 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true, 183 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
184 RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj); 184 RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj);
185 if (r) { 185 if (r) {
186 dev_warn(rdev->dev, "(%d) create WB bo failed\n", r); 186 dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
@@ -286,7 +286,7 @@ void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64
286 mc->mc_vram_size = mc->aper_size; 286 mc->mc_vram_size = mc->aper_size;
287 } 287 }
288 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; 288 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
289 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n", 289 dev_info(rdev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
290 mc->mc_vram_size >> 20, mc->vram_start, 290 mc->mc_vram_size >> 20, mc->vram_start,
291 mc->vram_end, mc->real_vram_size >> 20); 291 mc->vram_end, mc->real_vram_size >> 20);
292} 292}
@@ -323,7 +323,7 @@ void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
323 mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align; 323 mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align;
324 } 324 }
325 mc->gtt_end = mc->gtt_start + mc->gtt_size - 1; 325 mc->gtt_end = mc->gtt_start + mc->gtt_size - 1;
326 dev_info(rdev->dev, "GTT: %lluM 0x%08llX - 0x%08llX\n", 326 dev_info(rdev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
327 mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end); 327 mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end);
328} 328}
329 329
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index 0383631da69c..1df4dc6c063c 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -315,10 +315,14 @@ static void radeon_print_display_setup(struct drm_device *dev)
315 radeon_connector->ddc_bus->rec.en_data_reg, 315 radeon_connector->ddc_bus->rec.en_data_reg,
316 radeon_connector->ddc_bus->rec.y_clk_reg, 316 radeon_connector->ddc_bus->rec.y_clk_reg,
317 radeon_connector->ddc_bus->rec.y_data_reg); 317 radeon_connector->ddc_bus->rec.y_data_reg);
318 if (radeon_connector->router_bus) 318 if (radeon_connector->router.ddc_valid)
319 DRM_INFO(" DDC Router 0x%x/0x%x\n", 319 DRM_INFO(" DDC Router 0x%x/0x%x\n",
320 radeon_connector->router.mux_control_pin, 320 radeon_connector->router.ddc_mux_control_pin,
321 radeon_connector->router.mux_state); 321 radeon_connector->router.ddc_mux_state);
322 if (radeon_connector->router.cd_valid)
323 DRM_INFO(" Clock/Data Router 0x%x/0x%x\n",
324 radeon_connector->router.cd_mux_control_pin,
325 radeon_connector->router.cd_mux_state);
322 } else { 326 } else {
323 if (connector->connector_type == DRM_MODE_CONNECTOR_VGA || 327 if (connector->connector_type == DRM_MODE_CONNECTOR_VGA ||
324 connector->connector_type == DRM_MODE_CONNECTOR_DVII || 328 connector->connector_type == DRM_MODE_CONNECTOR_DVII ||
@@ -398,8 +402,8 @@ int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
398 int ret = 0; 402 int ret = 0;
399 403
400 /* on hw with routers, select right port */ 404 /* on hw with routers, select right port */
401 if (radeon_connector->router.valid) 405 if (radeon_connector->router.ddc_valid)
402 radeon_router_select_port(radeon_connector); 406 radeon_router_select_ddc_port(radeon_connector);
403 407
404 if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) || 408 if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
405 (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) { 409 (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) {
@@ -432,8 +436,8 @@ static int radeon_ddc_dump(struct drm_connector *connector)
432 int ret = 0; 436 int ret = 0;
433 437
434 /* on hw with routers, select right port */ 438 /* on hw with routers, select right port */
435 if (radeon_connector->router.valid) 439 if (radeon_connector->router.ddc_valid)
436 radeon_router_select_port(radeon_connector); 440 radeon_router_select_ddc_port(radeon_connector);
437 441
438 if (!radeon_connector->ddc_bus) 442 if (!radeon_connector->ddc_bus)
439 return -1; 443 return -1;
diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c b/drivers/gpu/drm/radeon/radeon_encoders.c
index ae58b6849a2e..041943df966b 100644
--- a/drivers/gpu/drm/radeon/radeon_encoders.c
+++ b/drivers/gpu/drm/radeon/radeon_encoders.c
@@ -176,6 +176,7 @@ static inline bool radeon_encoder_is_digital(struct drm_encoder *encoder)
176 return false; 176 return false;
177 } 177 }
178} 178}
179
179void 180void
180radeon_link_encoder_connector(struct drm_device *dev) 181radeon_link_encoder_connector(struct drm_device *dev)
181{ 182{
@@ -228,6 +229,27 @@ radeon_get_connector_for_encoder(struct drm_encoder *encoder)
228 return NULL; 229 return NULL;
229} 230}
230 231
232struct drm_encoder *radeon_atom_get_external_encoder(struct drm_encoder *encoder)
233{
234 struct drm_device *dev = encoder->dev;
235 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
236 struct drm_encoder *other_encoder;
237 struct radeon_encoder *other_radeon_encoder;
238
239 if (radeon_encoder->is_ext_encoder)
240 return NULL;
241
242 list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
243 if (other_encoder == encoder)
244 continue;
245 other_radeon_encoder = to_radeon_encoder(other_encoder);
246 if (other_radeon_encoder->is_ext_encoder &&
247 (radeon_encoder->devices & other_radeon_encoder->devices))
248 return other_encoder;
249 }
250 return NULL;
251}
252
231void radeon_panel_mode_fixup(struct drm_encoder *encoder, 253void radeon_panel_mode_fixup(struct drm_encoder *encoder,
232 struct drm_display_mode *adjusted_mode) 254 struct drm_display_mode *adjusted_mode)
233{ 255{
@@ -426,52 +448,49 @@ atombios_tv_setup(struct drm_encoder *encoder, int action)
426 448
427} 449}
428 450
429void 451union dvo_encoder_control {
430atombios_external_tmds_setup(struct drm_encoder *encoder, int action) 452 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds;
431{ 453 DVO_ENCODER_CONTROL_PS_ALLOCATION dvo;
432 struct drm_device *dev = encoder->dev; 454 DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3;
433 struct radeon_device *rdev = dev->dev_private; 455};
434 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
435 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION args;
436 int index = 0;
437
438 memset(&args, 0, sizeof(args));
439
440 index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl);
441
442 args.sXTmdsEncoder.ucEnable = action;
443
444 if (radeon_encoder->pixel_clock > 165000)
445 args.sXTmdsEncoder.ucMisc = PANEL_ENCODER_MISC_DUAL;
446
447 /*if (pScrn->rgbBits == 8)*/
448 args.sXTmdsEncoder.ucMisc |= (1 << 1);
449
450 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
451
452}
453 456
454static void 457void
455atombios_ddia_setup(struct drm_encoder *encoder, int action) 458atombios_dvo_setup(struct drm_encoder *encoder, int action)
456{ 459{
457 struct drm_device *dev = encoder->dev; 460 struct drm_device *dev = encoder->dev;
458 struct radeon_device *rdev = dev->dev_private; 461 struct radeon_device *rdev = dev->dev_private;
459 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 462 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
460 DVO_ENCODER_CONTROL_PS_ALLOCATION args; 463 union dvo_encoder_control args;
461 int index = 0; 464 int index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl);
462 465
463 memset(&args, 0, sizeof(args)); 466 memset(&args, 0, sizeof(args));
464 467
465 index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl); 468 if (ASIC_IS_DCE3(rdev)) {
469 /* DCE3+ */
470 args.dvo_v3.ucAction = action;
471 args.dvo_v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
472 args.dvo_v3.ucDVOConfig = 0; /* XXX */
473 } else if (ASIC_IS_DCE2(rdev)) {
474 /* DCE2 (pre-DCE3 R6xx, RS600/690/740 */
475 args.dvo.sDVOEncoder.ucAction = action;
476 args.dvo.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
477 /* DFP1, CRT1, TV1 depending on the type of port */
478 args.dvo.sDVOEncoder.ucDeviceType = ATOM_DEVICE_DFP1_INDEX;
479
480 if (radeon_encoder->pixel_clock > 165000)
481 args.dvo.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute |= PANEL_ENCODER_MISC_DUAL;
482 } else {
483 /* R4xx, R5xx */
484 args.ext_tmds.sXTmdsEncoder.ucEnable = action;
466 485
467 args.sDVOEncoder.ucAction = action; 486 if (radeon_encoder->pixel_clock > 165000)
468 args.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 487 args.ext_tmds.sXTmdsEncoder.ucMisc |= PANEL_ENCODER_MISC_DUAL;
469 488
470 if (radeon_encoder->pixel_clock > 165000) 489 /*if (pScrn->rgbBits == 8)*/
471 args.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute = PANEL_ENCODER_MISC_DUAL; 490 args.ext_tmds.sXTmdsEncoder.ucMisc |= ATOM_PANEL_MISC_888RGB;
491 }
472 492
473 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 493 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
474
475} 494}
476 495
477union lvds_encoder_control { 496union lvds_encoder_control {
@@ -532,14 +551,14 @@ atombios_digital_setup(struct drm_encoder *encoder, int action)
532 if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL) 551 if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
533 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; 552 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
534 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB) 553 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
535 args.v1.ucMisc |= (1 << 1); 554 args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
536 } else { 555 } else {
537 if (dig->linkb) 556 if (dig->linkb)
538 args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; 557 args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
539 if (radeon_encoder->pixel_clock > 165000) 558 if (radeon_encoder->pixel_clock > 165000)
540 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; 559 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
541 /*if (pScrn->rgbBits == 8) */ 560 /*if (pScrn->rgbBits == 8) */
542 args.v1.ucMisc |= (1 << 1); 561 args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
543 } 562 }
544 break; 563 break;
545 case 2: 564 case 2:
@@ -595,6 +614,7 @@ atombios_digital_setup(struct drm_encoder *encoder, int action)
595int 614int
596atombios_get_encoder_mode(struct drm_encoder *encoder) 615atombios_get_encoder_mode(struct drm_encoder *encoder)
597{ 616{
617 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
598 struct drm_device *dev = encoder->dev; 618 struct drm_device *dev = encoder->dev;
599 struct radeon_device *rdev = dev->dev_private; 619 struct radeon_device *rdev = dev->dev_private;
600 struct drm_connector *connector; 620 struct drm_connector *connector;
@@ -602,9 +622,20 @@ atombios_get_encoder_mode(struct drm_encoder *encoder)
602 struct radeon_connector_atom_dig *dig_connector; 622 struct radeon_connector_atom_dig *dig_connector;
603 623
604 connector = radeon_get_connector_for_encoder(encoder); 624 connector = radeon_get_connector_for_encoder(encoder);
605 if (!connector) 625 if (!connector) {
606 return 0; 626 switch (radeon_encoder->encoder_id) {
607 627 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
628 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
629 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
630 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
631 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
632 return ATOM_ENCODER_MODE_DVI;
633 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
634 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
635 default:
636 return ATOM_ENCODER_MODE_CRT;
637 }
638 }
608 radeon_connector = to_radeon_connector(connector); 639 radeon_connector = to_radeon_connector(connector);
609 640
610 switch (connector->connector_type) { 641 switch (connector->connector_type) {
@@ -834,6 +865,9 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t
834 memset(&args, 0, sizeof(args)); 865 memset(&args, 0, sizeof(args));
835 866
836 switch (radeon_encoder->encoder_id) { 867 switch (radeon_encoder->encoder_id) {
868 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
869 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
870 break;
837 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 871 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
838 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 872 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
839 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 873 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
@@ -978,6 +1012,105 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t
978 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 1012 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
979} 1013}
980 1014
1015void
1016atombios_set_edp_panel_power(struct drm_connector *connector, int action)
1017{
1018 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1019 struct drm_device *dev = radeon_connector->base.dev;
1020 struct radeon_device *rdev = dev->dev_private;
1021 union dig_transmitter_control args;
1022 int index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
1023 uint8_t frev, crev;
1024
1025 if (connector->connector_type != DRM_MODE_CONNECTOR_eDP)
1026 return;
1027
1028 if (!ASIC_IS_DCE4(rdev))
1029 return;
1030
1031 if ((action != ATOM_TRANSMITTER_ACTION_POWER_ON) ||
1032 (action != ATOM_TRANSMITTER_ACTION_POWER_OFF))
1033 return;
1034
1035 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1036 return;
1037
1038 memset(&args, 0, sizeof(args));
1039
1040 args.v1.ucAction = action;
1041
1042 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1043}
1044
1045union external_encoder_control {
1046 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1;
1047};
1048
1049static void
1050atombios_external_encoder_setup(struct drm_encoder *encoder,
1051 struct drm_encoder *ext_encoder,
1052 int action)
1053{
1054 struct drm_device *dev = encoder->dev;
1055 struct radeon_device *rdev = dev->dev_private;
1056 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1057 union external_encoder_control args;
1058 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1059 int index = GetIndexIntoMasterTable(COMMAND, ExternalEncoderControl);
1060 u8 frev, crev;
1061 int dp_clock = 0;
1062 int dp_lane_count = 0;
1063 int connector_object_id = 0;
1064
1065 if (connector) {
1066 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1067 struct radeon_connector_atom_dig *dig_connector =
1068 radeon_connector->con_priv;
1069
1070 dp_clock = dig_connector->dp_clock;
1071 dp_lane_count = dig_connector->dp_lane_count;
1072 connector_object_id =
1073 (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
1074 }
1075
1076 memset(&args, 0, sizeof(args));
1077
1078 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1079 return;
1080
1081 switch (frev) {
1082 case 1:
1083 /* no params on frev 1 */
1084 break;
1085 case 2:
1086 switch (crev) {
1087 case 1:
1088 case 2:
1089 args.v1.sDigEncoder.ucAction = action;
1090 args.v1.sDigEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1091 args.v1.sDigEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
1092
1093 if (args.v1.sDigEncoder.ucEncoderMode == ATOM_ENCODER_MODE_DP) {
1094 if (dp_clock == 270000)
1095 args.v1.sDigEncoder.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
1096 args.v1.sDigEncoder.ucLaneNum = dp_lane_count;
1097 } else if (radeon_encoder->pixel_clock > 165000)
1098 args.v1.sDigEncoder.ucLaneNum = 8;
1099 else
1100 args.v1.sDigEncoder.ucLaneNum = 4;
1101 break;
1102 default:
1103 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1104 return;
1105 }
1106 break;
1107 default:
1108 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1109 return;
1110 }
1111 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1112}
1113
981static void 1114static void
982atombios_yuv_setup(struct drm_encoder *encoder, bool enable) 1115atombios_yuv_setup(struct drm_encoder *encoder, bool enable)
983{ 1116{
@@ -1021,6 +1154,7 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
1021 struct drm_device *dev = encoder->dev; 1154 struct drm_device *dev = encoder->dev;
1022 struct radeon_device *rdev = dev->dev_private; 1155 struct radeon_device *rdev = dev->dev_private;
1023 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1156 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1157 struct drm_encoder *ext_encoder = radeon_atom_get_external_encoder(encoder);
1024 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args; 1158 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
1025 int index = 0; 1159 int index = 0;
1026 bool is_dig = false; 1160 bool is_dig = false;
@@ -1043,9 +1177,14 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
1043 break; 1177 break;
1044 case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1178 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1045 case ENCODER_OBJECT_ID_INTERNAL_DDI: 1179 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1046 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1047 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl); 1180 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
1048 break; 1181 break;
1182 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1183 if (ASIC_IS_DCE3(rdev))
1184 is_dig = true;
1185 else
1186 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
1187 break;
1049 case ENCODER_OBJECT_ID_INTERNAL_LVDS: 1188 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1050 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); 1189 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
1051 break; 1190 break;
@@ -1082,34 +1221,85 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
1082 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) { 1221 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) {
1083 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 1222 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1084 1223
1224 if (connector &&
1225 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
1226 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1227 struct radeon_connector_atom_dig *radeon_dig_connector =
1228 radeon_connector->con_priv;
1229 atombios_set_edp_panel_power(connector,
1230 ATOM_TRANSMITTER_ACTION_POWER_ON);
1231 radeon_dig_connector->edp_on = true;
1232 }
1085 dp_link_train(encoder, connector); 1233 dp_link_train(encoder, connector);
1086 if (ASIC_IS_DCE4(rdev)) 1234 if (ASIC_IS_DCE4(rdev))
1087 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON); 1235 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON);
1088 } 1236 }
1237 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1238 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0);
1089 break; 1239 break;
1090 case DRM_MODE_DPMS_STANDBY: 1240 case DRM_MODE_DPMS_STANDBY:
1091 case DRM_MODE_DPMS_SUSPEND: 1241 case DRM_MODE_DPMS_SUSPEND:
1092 case DRM_MODE_DPMS_OFF: 1242 case DRM_MODE_DPMS_OFF:
1093 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0); 1243 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0);
1094 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) { 1244 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) {
1245 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1246
1095 if (ASIC_IS_DCE4(rdev)) 1247 if (ASIC_IS_DCE4(rdev))
1096 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF); 1248 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF);
1249 if (connector &&
1250 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
1251 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1252 struct radeon_connector_atom_dig *radeon_dig_connector =
1253 radeon_connector->con_priv;
1254 atombios_set_edp_panel_power(connector,
1255 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1256 radeon_dig_connector->edp_on = false;
1257 }
1097 } 1258 }
1259 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1260 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0);
1098 break; 1261 break;
1099 } 1262 }
1100 } else { 1263 } else {
1101 switch (mode) { 1264 switch (mode) {
1102 case DRM_MODE_DPMS_ON: 1265 case DRM_MODE_DPMS_ON:
1103 args.ucAction = ATOM_ENABLE; 1266 args.ucAction = ATOM_ENABLE;
1267 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1268 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1269 args.ucAction = ATOM_LCD_BLON;
1270 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1271 }
1104 break; 1272 break;
1105 case DRM_MODE_DPMS_STANDBY: 1273 case DRM_MODE_DPMS_STANDBY:
1106 case DRM_MODE_DPMS_SUSPEND: 1274 case DRM_MODE_DPMS_SUSPEND:
1107 case DRM_MODE_DPMS_OFF: 1275 case DRM_MODE_DPMS_OFF:
1108 args.ucAction = ATOM_DISABLE; 1276 args.ucAction = ATOM_DISABLE;
1277 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1278 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1279 args.ucAction = ATOM_LCD_BLOFF;
1280 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1281 }
1109 break; 1282 break;
1110 } 1283 }
1111 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1112 } 1284 }
1285
1286 if (ext_encoder) {
1287 int action;
1288
1289 switch (mode) {
1290 case DRM_MODE_DPMS_ON:
1291 default:
1292 action = ATOM_ENABLE;
1293 break;
1294 case DRM_MODE_DPMS_STANDBY:
1295 case DRM_MODE_DPMS_SUSPEND:
1296 case DRM_MODE_DPMS_OFF:
1297 action = ATOM_DISABLE;
1298 break;
1299 }
1300 atombios_external_encoder_setup(encoder, ext_encoder, action);
1301 }
1302
1113 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 1303 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
1114 1304
1115} 1305}
@@ -1242,7 +1432,7 @@ atombios_set_encoder_crtc_source(struct drm_encoder *encoder)
1242 break; 1432 break;
1243 default: 1433 default:
1244 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev); 1434 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1245 break; 1435 return;
1246 } 1436 }
1247 1437
1248 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 1438 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
@@ -1357,6 +1547,7 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
1357 struct drm_device *dev = encoder->dev; 1547 struct drm_device *dev = encoder->dev;
1358 struct radeon_device *rdev = dev->dev_private; 1548 struct radeon_device *rdev = dev->dev_private;
1359 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1549 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1550 struct drm_encoder *ext_encoder = radeon_atom_get_external_encoder(encoder);
1360 1551
1361 radeon_encoder->pixel_clock = adjusted_mode->clock; 1552 radeon_encoder->pixel_clock = adjusted_mode->clock;
1362 1553
@@ -1400,11 +1591,9 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
1400 } 1591 }
1401 break; 1592 break;
1402 case ENCODER_OBJECT_ID_INTERNAL_DDI: 1593 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1403 atombios_ddia_setup(encoder, ATOM_ENABLE);
1404 break;
1405 case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1594 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1406 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1595 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1407 atombios_external_tmds_setup(encoder, ATOM_ENABLE); 1596 atombios_dvo_setup(encoder, ATOM_ENABLE);
1408 break; 1597 break;
1409 case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1598 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1410 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 1599 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
@@ -1419,6 +1608,11 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
1419 } 1608 }
1420 break; 1609 break;
1421 } 1610 }
1611
1612 if (ext_encoder) {
1613 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE);
1614 }
1615
1422 atombios_apply_encoder_quirks(encoder, adjusted_mode); 1616 atombios_apply_encoder_quirks(encoder, adjusted_mode);
1423 1617
1424 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) { 1618 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
@@ -1520,6 +1714,7 @@ radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connec
1520static void radeon_atom_encoder_prepare(struct drm_encoder *encoder) 1714static void radeon_atom_encoder_prepare(struct drm_encoder *encoder)
1521{ 1715{
1522 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1716 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1717 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1523 1718
1524 if (radeon_encoder->active_device & 1719 if (radeon_encoder->active_device &
1525 (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) { 1720 (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) {
@@ -1531,6 +1726,13 @@ static void radeon_atom_encoder_prepare(struct drm_encoder *encoder)
1531 radeon_atom_output_lock(encoder, true); 1726 radeon_atom_output_lock(encoder, true);
1532 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 1727 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
1533 1728
1729 /* select the clock/data port if it uses a router */
1730 if (connector) {
1731 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1732 if (radeon_connector->router.cd_valid)
1733 radeon_router_select_cd_port(radeon_connector);
1734 }
1735
1534 /* this is needed for the pll/ss setup to work correctly in some cases */ 1736 /* this is needed for the pll/ss setup to work correctly in some cases */
1535 atombios_set_encoder_crtc_source(encoder); 1737 atombios_set_encoder_crtc_source(encoder);
1536} 1738}
@@ -1547,6 +1749,23 @@ static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
1547 struct radeon_device *rdev = dev->dev_private; 1749 struct radeon_device *rdev = dev->dev_private;
1548 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1750 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1549 struct radeon_encoder_atom_dig *dig; 1751 struct radeon_encoder_atom_dig *dig;
1752
1753 /* check for pre-DCE3 cards with shared encoders;
1754 * can't really use the links individually, so don't disable
1755 * the encoder if it's in use by another connector
1756 */
1757 if (!ASIC_IS_DCE3(rdev)) {
1758 struct drm_encoder *other_encoder;
1759 struct radeon_encoder *other_radeon_encoder;
1760
1761 list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
1762 other_radeon_encoder = to_radeon_encoder(other_encoder);
1763 if ((radeon_encoder->encoder_id == other_radeon_encoder->encoder_id) &&
1764 drm_helper_encoder_in_use(other_encoder))
1765 goto disable_done;
1766 }
1767 }
1768
1550 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 1769 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
1551 1770
1552 switch (radeon_encoder->encoder_id) { 1771 switch (radeon_encoder->encoder_id) {
@@ -1570,11 +1789,9 @@ static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
1570 } 1789 }
1571 break; 1790 break;
1572 case ENCODER_OBJECT_ID_INTERNAL_DDI: 1791 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1573 atombios_ddia_setup(encoder, ATOM_DISABLE);
1574 break;
1575 case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1792 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1576 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1793 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1577 atombios_external_tmds_setup(encoder, ATOM_DISABLE); 1794 atombios_dvo_setup(encoder, ATOM_DISABLE);
1578 break; 1795 break;
1579 case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1796 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1580 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 1797 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
@@ -1586,6 +1803,7 @@ static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
1586 break; 1803 break;
1587 } 1804 }
1588 1805
1806disable_done:
1589 if (radeon_encoder_is_digital(encoder)) { 1807 if (radeon_encoder_is_digital(encoder)) {
1590 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) 1808 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
1591 r600_hdmi_disable(encoder); 1809 r600_hdmi_disable(encoder);
@@ -1595,6 +1813,53 @@ static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
1595 radeon_encoder->active_device = 0; 1813 radeon_encoder->active_device = 0;
1596} 1814}
1597 1815
1816/* these are handled by the primary encoders */
1817static void radeon_atom_ext_prepare(struct drm_encoder *encoder)
1818{
1819
1820}
1821
1822static void radeon_atom_ext_commit(struct drm_encoder *encoder)
1823{
1824
1825}
1826
1827static void
1828radeon_atom_ext_mode_set(struct drm_encoder *encoder,
1829 struct drm_display_mode *mode,
1830 struct drm_display_mode *adjusted_mode)
1831{
1832
1833}
1834
1835static void radeon_atom_ext_disable(struct drm_encoder *encoder)
1836{
1837
1838}
1839
1840static void
1841radeon_atom_ext_dpms(struct drm_encoder *encoder, int mode)
1842{
1843
1844}
1845
1846static bool radeon_atom_ext_mode_fixup(struct drm_encoder *encoder,
1847 struct drm_display_mode *mode,
1848 struct drm_display_mode *adjusted_mode)
1849{
1850 return true;
1851}
1852
1853static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs = {
1854 .dpms = radeon_atom_ext_dpms,
1855 .mode_fixup = radeon_atom_ext_mode_fixup,
1856 .prepare = radeon_atom_ext_prepare,
1857 .mode_set = radeon_atom_ext_mode_set,
1858 .commit = radeon_atom_ext_commit,
1859 .disable = radeon_atom_ext_disable,
1860 /* no detect for TMDS/LVDS yet */
1861};
1862
1598static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = { 1863static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = {
1599 .dpms = radeon_atom_encoder_dpms, 1864 .dpms = radeon_atom_encoder_dpms,
1600 .mode_fixup = radeon_atom_mode_fixup, 1865 .mode_fixup = radeon_atom_mode_fixup,
@@ -1704,6 +1969,7 @@ radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum, uint32_t
1704 radeon_encoder->devices = supported_device; 1969 radeon_encoder->devices = supported_device;
1705 radeon_encoder->rmx_type = RMX_OFF; 1970 radeon_encoder->rmx_type = RMX_OFF;
1706 radeon_encoder->underscan_type = UNDERSCAN_OFF; 1971 radeon_encoder->underscan_type = UNDERSCAN_OFF;
1972 radeon_encoder->is_ext_encoder = false;
1707 1973
1708 switch (radeon_encoder->encoder_id) { 1974 switch (radeon_encoder->encoder_id) {
1709 case ENCODER_OBJECT_ID_INTERNAL_LVDS: 1975 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
@@ -1745,6 +2011,9 @@ radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum, uint32_t
1745 radeon_encoder->rmx_type = RMX_FULL; 2011 radeon_encoder->rmx_type = RMX_FULL;
1746 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS); 2012 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
1747 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); 2013 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
2014 } else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
2015 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2016 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
1748 } else { 2017 } else {
1749 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS); 2018 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
1750 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); 2019 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
@@ -1753,5 +2022,22 @@ radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum, uint32_t
1753 } 2022 }
1754 drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); 2023 drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
1755 break; 2024 break;
2025 case ENCODER_OBJECT_ID_SI170B:
2026 case ENCODER_OBJECT_ID_CH7303:
2027 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
2028 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
2029 case ENCODER_OBJECT_ID_TITFP513:
2030 case ENCODER_OBJECT_ID_VT1623:
2031 case ENCODER_OBJECT_ID_HDMI_SI1930:
2032 /* these are handled by the primary encoders */
2033 radeon_encoder->is_ext_encoder = true;
2034 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
2035 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2036 else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
2037 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2038 else
2039 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2040 drm_encoder_helper_add(encoder, &radeon_atom_ext_helper_funcs);
2041 break;
1756 } 2042 }
1757} 2043}
diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
index 216392d0353b..daacb281dfaf 100644
--- a/drivers/gpu/drm/radeon/radeon_fence.c
+++ b/drivers/gpu/drm/radeon/radeon_fence.c
@@ -240,7 +240,8 @@ retry:
240 */ 240 */
241 if (seq == rdev->fence_drv.last_seq && radeon_gpu_is_lockup(rdev)) { 241 if (seq == rdev->fence_drv.last_seq && radeon_gpu_is_lockup(rdev)) {
242 /* good news we believe it's a lockup */ 242 /* good news we believe it's a lockup */
243 WARN(1, "GPU lockup (waiting for 0x%08X last fence id 0x%08X)\n", fence->seq, seq); 243 WARN(1, "GPU lockup (waiting for 0x%08X last fence id 0x%08X)\n",
244 fence->seq, seq);
244 /* FIXME: what should we do ? marking everyone 245 /* FIXME: what should we do ? marking everyone
245 * as signaled for now 246 * as signaled for now
246 */ 247 */
diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c
index e65b90317fab..65016117d95f 100644
--- a/drivers/gpu/drm/radeon/radeon_gart.c
+++ b/drivers/gpu/drm/radeon/radeon_gart.c
@@ -79,8 +79,8 @@ int radeon_gart_table_vram_alloc(struct radeon_device *rdev)
79 79
80 if (rdev->gart.table.vram.robj == NULL) { 80 if (rdev->gart.table.vram.robj == NULL) {
81 r = radeon_bo_create(rdev, NULL, rdev->gart.table_size, 81 r = radeon_bo_create(rdev, NULL, rdev->gart.table_size,
82 true, RADEON_GEM_DOMAIN_VRAM, 82 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
83 &rdev->gart.table.vram.robj); 83 &rdev->gart.table.vram.robj);
84 if (r) { 84 if (r) {
85 return r; 85 return r;
86 } 86 }
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index d1e595d91723..df95eb83dac6 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -67,7 +67,7 @@ int radeon_gem_object_create(struct radeon_device *rdev, int size,
67 if (alignment < PAGE_SIZE) { 67 if (alignment < PAGE_SIZE) {
68 alignment = PAGE_SIZE; 68 alignment = PAGE_SIZE;
69 } 69 }
70 r = radeon_bo_create(rdev, gobj, size, kernel, initial_domain, &robj); 70 r = radeon_bo_create(rdev, gobj, size, alignment, kernel, initial_domain, &robj);
71 if (r) { 71 if (r) {
72 if (r != -ERESTARTSYS) 72 if (r != -ERESTARTSYS)
73 DRM_ERROR("Failed to allocate GEM object (%d, %d, %u, %d)\n", 73 DRM_ERROR("Failed to allocate GEM object (%d, %d, %u, %d)\n",
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c
index 6a13ee38a5b9..ded2a45bc95c 100644
--- a/drivers/gpu/drm/radeon/radeon_i2c.c
+++ b/drivers/gpu/drm/radeon/radeon_i2c.c
@@ -53,8 +53,8 @@ bool radeon_ddc_probe(struct radeon_connector *radeon_connector)
53 }; 53 };
54 54
55 /* on hw with routers, select right port */ 55 /* on hw with routers, select right port */
56 if (radeon_connector->router.valid) 56 if (radeon_connector->router.ddc_valid)
57 radeon_router_select_port(radeon_connector); 57 radeon_router_select_ddc_port(radeon_connector);
58 58
59 ret = i2c_transfer(&radeon_connector->ddc_bus->adapter, msgs, 2); 59 ret = i2c_transfer(&radeon_connector->ddc_bus->adapter, msgs, 2);
60 if (ret == 2) 60 if (ret == 2)
@@ -896,7 +896,8 @@ struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
896 ((rdev->family <= CHIP_RS480) || 896 ((rdev->family <= CHIP_RS480) ||
897 ((rdev->family >= CHIP_RV515) && (rdev->family <= CHIP_R580))))) { 897 ((rdev->family >= CHIP_RV515) && (rdev->family <= CHIP_R580))))) {
898 /* set the radeon hw i2c adapter */ 898 /* set the radeon hw i2c adapter */
899 sprintf(i2c->adapter.name, "Radeon i2c hw bus %s", name); 899 snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
900 "Radeon i2c hw bus %s", name);
900 i2c->adapter.algo = &radeon_i2c_algo; 901 i2c->adapter.algo = &radeon_i2c_algo;
901 ret = i2c_add_adapter(&i2c->adapter); 902 ret = i2c_add_adapter(&i2c->adapter);
902 if (ret) { 903 if (ret) {
@@ -905,7 +906,8 @@ struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
905 } 906 }
906 } else { 907 } else {
907 /* set the radeon bit adapter */ 908 /* set the radeon bit adapter */
908 sprintf(i2c->adapter.name, "Radeon i2c bit bus %s", name); 909 snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
910 "Radeon i2c bit bus %s", name);
909 i2c->adapter.algo_data = &i2c->algo.bit; 911 i2c->adapter.algo_data = &i2c->algo.bit;
910 i2c->algo.bit.pre_xfer = pre_xfer; 912 i2c->algo.bit.pre_xfer = pre_xfer;
911 i2c->algo.bit.post_xfer = post_xfer; 913 i2c->algo.bit.post_xfer = post_xfer;
@@ -946,6 +948,8 @@ struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
946 i2c->rec = *rec; 948 i2c->rec = *rec;
947 i2c->adapter.owner = THIS_MODULE; 949 i2c->adapter.owner = THIS_MODULE;
948 i2c->dev = dev; 950 i2c->dev = dev;
951 snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
952 "Radeon aux bus %s", name);
949 i2c_set_adapdata(&i2c->adapter, i2c); 953 i2c_set_adapdata(&i2c->adapter, i2c);
950 i2c->adapter.algo_data = &i2c->algo.dp; 954 i2c->adapter.algo_data = &i2c->algo.dp;
951 i2c->algo.dp.aux_ch = radeon_dp_i2c_aux_ch; 955 i2c->algo.dp.aux_ch = radeon_dp_i2c_aux_ch;
@@ -1084,26 +1088,51 @@ void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c_bus,
1084 addr, val); 1088 addr, val);
1085} 1089}
1086 1090
1087/* router switching */ 1091/* ddc router switching */
1088void radeon_router_select_port(struct radeon_connector *radeon_connector) 1092void radeon_router_select_ddc_port(struct radeon_connector *radeon_connector)
1089{ 1093{
1090 u8 val; 1094 u8 val;
1091 1095
1092 if (!radeon_connector->router.valid) 1096 if (!radeon_connector->router.ddc_valid)
1093 return; 1097 return;
1094 1098
1095 radeon_i2c_get_byte(radeon_connector->router_bus, 1099 radeon_i2c_get_byte(radeon_connector->router_bus,
1096 radeon_connector->router.i2c_addr, 1100 radeon_connector->router.i2c_addr,
1097 0x3, &val); 1101 0x3, &val);
1098 val &= radeon_connector->router.mux_control_pin; 1102 val &= ~radeon_connector->router.ddc_mux_control_pin;
1099 radeon_i2c_put_byte(radeon_connector->router_bus, 1103 radeon_i2c_put_byte(radeon_connector->router_bus,
1100 radeon_connector->router.i2c_addr, 1104 radeon_connector->router.i2c_addr,
1101 0x3, val); 1105 0x3, val);
1102 radeon_i2c_get_byte(radeon_connector->router_bus, 1106 radeon_i2c_get_byte(radeon_connector->router_bus,
1103 radeon_connector->router.i2c_addr, 1107 radeon_connector->router.i2c_addr,
1104 0x1, &val); 1108 0x1, &val);
1105 val &= radeon_connector->router.mux_control_pin; 1109 val &= ~radeon_connector->router.ddc_mux_control_pin;
1106 val |= radeon_connector->router.mux_state; 1110 val |= radeon_connector->router.ddc_mux_state;
1111 radeon_i2c_put_byte(radeon_connector->router_bus,
1112 radeon_connector->router.i2c_addr,
1113 0x1, val);
1114}
1115
1116/* clock/data router switching */
1117void radeon_router_select_cd_port(struct radeon_connector *radeon_connector)
1118{
1119 u8 val;
1120
1121 if (!radeon_connector->router.cd_valid)
1122 return;
1123
1124 radeon_i2c_get_byte(radeon_connector->router_bus,
1125 radeon_connector->router.i2c_addr,
1126 0x3, &val);
1127 val &= ~radeon_connector->router.cd_mux_control_pin;
1128 radeon_i2c_put_byte(radeon_connector->router_bus,
1129 radeon_connector->router.i2c_addr,
1130 0x3, val);
1131 radeon_i2c_get_byte(radeon_connector->router_bus,
1132 radeon_connector->router.i2c_addr,
1133 0x1, &val);
1134 val &= ~radeon_connector->router.cd_mux_control_pin;
1135 val |= radeon_connector->router.cd_mux_state;
1107 radeon_i2c_put_byte(radeon_connector->router_bus, 1136 radeon_i2c_put_byte(radeon_connector->router_bus,
1108 radeon_connector->router.i2c_addr, 1137 radeon_connector->router.i2c_addr,
1109 0x1, val); 1138 0x1, val);
diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
index 2f349a300195..465746bd51b7 100644
--- a/drivers/gpu/drm/radeon/radeon_irq.c
+++ b/drivers/gpu/drm/radeon/radeon_irq.c
@@ -76,7 +76,7 @@ int radeon_enable_vblank(struct drm_device *dev, int crtc)
76 default: 76 default:
77 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n", 77 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n",
78 crtc); 78 crtc);
79 return EINVAL; 79 return -EINVAL;
80 } 80 }
81 } else { 81 } else {
82 switch (crtc) { 82 switch (crtc) {
@@ -89,7 +89,7 @@ int radeon_enable_vblank(struct drm_device *dev, int crtc)
89 default: 89 default:
90 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n", 90 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n",
91 crtc); 91 crtc);
92 return EINVAL; 92 return -EINVAL;
93 } 93 }
94 } 94 }
95 95
diff --git a/drivers/gpu/drm/radeon/radeon_legacy_encoders.c b/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
index 0b8397000f4c..59f834ba283d 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
@@ -670,7 +670,7 @@ static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
670 670
671 if (rdev->is_atom_bios) { 671 if (rdev->is_atom_bios) {
672 radeon_encoder->pixel_clock = adjusted_mode->clock; 672 radeon_encoder->pixel_clock = adjusted_mode->clock;
673 atombios_external_tmds_setup(encoder, ATOM_ENABLE); 673 atombios_dvo_setup(encoder, ATOM_ENABLE);
674 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 674 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
675 } else { 675 } else {
676 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 676 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h
index 92457163d070..e301c6f9e059 100644
--- a/drivers/gpu/drm/radeon/radeon_mode.h
+++ b/drivers/gpu/drm/radeon/radeon_mode.h
@@ -375,6 +375,7 @@ struct radeon_encoder {
375 int hdmi_config_offset; 375 int hdmi_config_offset;
376 int hdmi_audio_workaround; 376 int hdmi_audio_workaround;
377 int hdmi_buffer_status; 377 int hdmi_buffer_status;
378 bool is_ext_encoder;
378}; 379};
379 380
380struct radeon_connector_atom_dig { 381struct radeon_connector_atom_dig {
@@ -385,6 +386,7 @@ struct radeon_connector_atom_dig {
385 u8 dp_sink_type; 386 u8 dp_sink_type;
386 int dp_clock; 387 int dp_clock;
387 int dp_lane_count; 388 int dp_lane_count;
389 bool edp_on;
388}; 390};
389 391
390struct radeon_gpio_rec { 392struct radeon_gpio_rec {
@@ -401,13 +403,19 @@ struct radeon_hpd {
401}; 403};
402 404
403struct radeon_router { 405struct radeon_router {
404 bool valid;
405 u32 router_id; 406 u32 router_id;
406 struct radeon_i2c_bus_rec i2c_info; 407 struct radeon_i2c_bus_rec i2c_info;
407 u8 i2c_addr; 408 u8 i2c_addr;
408 u8 mux_type; 409 /* i2c mux */
409 u8 mux_control_pin; 410 bool ddc_valid;
410 u8 mux_state; 411 u8 ddc_mux_type;
412 u8 ddc_mux_control_pin;
413 u8 ddc_mux_state;
414 /* clock/data mux */
415 bool cd_valid;
416 u8 cd_mux_type;
417 u8 cd_mux_control_pin;
418 u8 cd_mux_state;
411}; 419};
412 420
413struct radeon_connector { 421struct radeon_connector {
@@ -488,7 +496,8 @@ extern void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c,
488 u8 slave_addr, 496 u8 slave_addr,
489 u8 addr, 497 u8 addr,
490 u8 val); 498 u8 val);
491extern void radeon_router_select_port(struct radeon_connector *radeon_connector); 499extern void radeon_router_select_ddc_port(struct radeon_connector *radeon_connector);
500extern void radeon_router_select_cd_port(struct radeon_connector *radeon_connector);
492extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector); 501extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector);
493extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector); 502extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
494 503
@@ -516,9 +525,10 @@ struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev
516struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int with_tv); 525struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int with_tv);
517struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index); 526struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index);
518struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index); 527struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index);
519extern void atombios_external_tmds_setup(struct drm_encoder *encoder, int action); 528extern void atombios_dvo_setup(struct drm_encoder *encoder, int action);
520extern void atombios_digital_setup(struct drm_encoder *encoder, int action); 529extern void atombios_digital_setup(struct drm_encoder *encoder, int action);
521extern int atombios_get_encoder_mode(struct drm_encoder *encoder); 530extern int atombios_get_encoder_mode(struct drm_encoder *encoder);
531extern void atombios_set_edp_panel_power(struct drm_connector *connector, int action);
522extern void radeon_encoder_set_active_device(struct drm_encoder *encoder); 532extern void radeon_encoder_set_active_device(struct drm_encoder *encoder);
523 533
524extern void radeon_crtc_load_lut(struct drm_crtc *crtc); 534extern void radeon_crtc_load_lut(struct drm_crtc *crtc);
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index d7ab91416410..a598d0049aa5 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -69,7 +69,7 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
69 u32 c = 0; 69 u32 c = 0;
70 70
71 rbo->placement.fpfn = 0; 71 rbo->placement.fpfn = 0;
72 rbo->placement.lpfn = rbo->rdev->mc.active_vram_size >> PAGE_SHIFT; 72 rbo->placement.lpfn = 0;
73 rbo->placement.placement = rbo->placements; 73 rbo->placement.placement = rbo->placements;
74 rbo->placement.busy_placement = rbo->placements; 74 rbo->placement.busy_placement = rbo->placements;
75 if (domain & RADEON_GEM_DOMAIN_VRAM) 75 if (domain & RADEON_GEM_DOMAIN_VRAM)
@@ -86,11 +86,13 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
86} 86}
87 87
88int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, 88int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
89 unsigned long size, bool kernel, u32 domain, 89 unsigned long size, int byte_align, bool kernel, u32 domain,
90 struct radeon_bo **bo_ptr) 90 struct radeon_bo **bo_ptr)
91{ 91{
92 struct radeon_bo *bo; 92 struct radeon_bo *bo;
93 enum ttm_bo_type type; 93 enum ttm_bo_type type;
94 unsigned long page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
95 unsigned long max_size = 0;
94 int r; 96 int r;
95 97
96 if (unlikely(rdev->mman.bdev.dev_mapping == NULL)) { 98 if (unlikely(rdev->mman.bdev.dev_mapping == NULL)) {
@@ -102,6 +104,16 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
102 type = ttm_bo_type_device; 104 type = ttm_bo_type_device;
103 } 105 }
104 *bo_ptr = NULL; 106 *bo_ptr = NULL;
107
108 /* maximun bo size is the minimun btw visible vram and gtt size */
109 max_size = min(rdev->mc.visible_vram_size, rdev->mc.gtt_size);
110 if ((page_align << PAGE_SHIFT) >= max_size) {
111 printk(KERN_WARNING "%s:%d alloc size %ldM bigger than %ldMb limit\n",
112 __func__, __LINE__, page_align >> (20 - PAGE_SHIFT), max_size >> 20);
113 return -ENOMEM;
114 }
115
116retry:
105 bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL); 117 bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
106 if (bo == NULL) 118 if (bo == NULL)
107 return -ENOMEM; 119 return -ENOMEM;
@@ -109,13 +121,11 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
109 bo->gobj = gobj; 121 bo->gobj = gobj;
110 bo->surface_reg = -1; 122 bo->surface_reg = -1;
111 INIT_LIST_HEAD(&bo->list); 123 INIT_LIST_HEAD(&bo->list);
112
113retry:
114 radeon_ttm_placement_from_domain(bo, domain); 124 radeon_ttm_placement_from_domain(bo, domain);
115 /* Kernel allocation are uninterruptible */ 125 /* Kernel allocation are uninterruptible */
116 mutex_lock(&rdev->vram_mutex); 126 mutex_lock(&rdev->vram_mutex);
117 r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type, 127 r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
118 &bo->placement, 0, 0, !kernel, NULL, size, 128 &bo->placement, page_align, 0, !kernel, NULL, size,
119 &radeon_ttm_bo_destroy); 129 &radeon_ttm_bo_destroy);
120 mutex_unlock(&rdev->vram_mutex); 130 mutex_unlock(&rdev->vram_mutex);
121 if (unlikely(r != 0)) { 131 if (unlikely(r != 0)) {
diff --git a/drivers/gpu/drm/radeon/radeon_object.h b/drivers/gpu/drm/radeon/radeon_object.h
index 3481bc7f6f58..d143702b244a 100644
--- a/drivers/gpu/drm/radeon/radeon_object.h
+++ b/drivers/gpu/drm/radeon/radeon_object.h
@@ -137,9 +137,10 @@ static inline int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type,
137} 137}
138 138
139extern int radeon_bo_create(struct radeon_device *rdev, 139extern int radeon_bo_create(struct radeon_device *rdev,
140 struct drm_gem_object *gobj, unsigned long size, 140 struct drm_gem_object *gobj, unsigned long size,
141 bool kernel, u32 domain, 141 int byte_align,
142 struct radeon_bo **bo_ptr); 142 bool kernel, u32 domain,
143 struct radeon_bo **bo_ptr);
143extern int radeon_bo_kmap(struct radeon_bo *bo, void **ptr); 144extern int radeon_bo_kmap(struct radeon_bo *bo, void **ptr);
144extern void radeon_bo_kunmap(struct radeon_bo *bo); 145extern void radeon_bo_kunmap(struct radeon_bo *bo);
145extern void radeon_bo_unref(struct radeon_bo **bo); 146extern void radeon_bo_unref(struct radeon_bo **bo);
diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
index 6ea798ce8218..06e79822a2bf 100644
--- a/drivers/gpu/drm/radeon/radeon_ring.c
+++ b/drivers/gpu/drm/radeon/radeon_ring.c
@@ -176,8 +176,8 @@ int radeon_ib_pool_init(struct radeon_device *rdev)
176 INIT_LIST_HEAD(&rdev->ib_pool.bogus_ib); 176 INIT_LIST_HEAD(&rdev->ib_pool.bogus_ib);
177 /* Allocate 1M object buffer */ 177 /* Allocate 1M object buffer */
178 r = radeon_bo_create(rdev, NULL, RADEON_IB_POOL_SIZE*64*1024, 178 r = radeon_bo_create(rdev, NULL, RADEON_IB_POOL_SIZE*64*1024,
179 true, RADEON_GEM_DOMAIN_GTT, 179 PAGE_SIZE, true, RADEON_GEM_DOMAIN_GTT,
180 &rdev->ib_pool.robj); 180 &rdev->ib_pool.robj);
181 if (r) { 181 if (r) {
182 DRM_ERROR("radeon: failed to ib pool (%d).\n", r); 182 DRM_ERROR("radeon: failed to ib pool (%d).\n", r);
183 return r; 183 return r;
@@ -332,7 +332,7 @@ int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size)
332 rdev->cp.ring_size = ring_size; 332 rdev->cp.ring_size = ring_size;
333 /* Allocate ring buffer */ 333 /* Allocate ring buffer */
334 if (rdev->cp.ring_obj == NULL) { 334 if (rdev->cp.ring_obj == NULL) {
335 r = radeon_bo_create(rdev, NULL, rdev->cp.ring_size, true, 335 r = radeon_bo_create(rdev, NULL, rdev->cp.ring_size, PAGE_SIZE, true,
336 RADEON_GEM_DOMAIN_GTT, 336 RADEON_GEM_DOMAIN_GTT,
337 &rdev->cp.ring_obj); 337 &rdev->cp.ring_obj);
338 if (r) { 338 if (r) {
diff --git a/drivers/gpu/drm/radeon/radeon_test.c b/drivers/gpu/drm/radeon/radeon_test.c
index 313c96bc09da..5b44f652145c 100644
--- a/drivers/gpu/drm/radeon/radeon_test.c
+++ b/drivers/gpu/drm/radeon/radeon_test.c
@@ -52,7 +52,7 @@ void radeon_test_moves(struct radeon_device *rdev)
52 goto out_cleanup; 52 goto out_cleanup;
53 } 53 }
54 54
55 r = radeon_bo_create(rdev, NULL, size, true, RADEON_GEM_DOMAIN_VRAM, 55 r = radeon_bo_create(rdev, NULL, size, PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
56 &vram_obj); 56 &vram_obj);
57 if (r) { 57 if (r) {
58 DRM_ERROR("Failed to create VRAM object\n"); 58 DRM_ERROR("Failed to create VRAM object\n");
@@ -71,7 +71,7 @@ void radeon_test_moves(struct radeon_device *rdev)
71 void **gtt_start, **gtt_end; 71 void **gtt_start, **gtt_end;
72 void **vram_start, **vram_end; 72 void **vram_start, **vram_end;
73 73
74 r = radeon_bo_create(rdev, NULL, size, true, 74 r = radeon_bo_create(rdev, NULL, size, PAGE_SIZE, true,
75 RADEON_GEM_DOMAIN_GTT, gtt_obj + i); 75 RADEON_GEM_DOMAIN_GTT, gtt_obj + i);
76 if (r) { 76 if (r) {
77 DRM_ERROR("Failed to create GTT object %d\n", i); 77 DRM_ERROR("Failed to create GTT object %d\n", i);
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index fe95bb35317e..1272e4b6a1d4 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -529,7 +529,7 @@ int radeon_ttm_init(struct radeon_device *rdev)
529 DRM_ERROR("Failed initializing VRAM heap.\n"); 529 DRM_ERROR("Failed initializing VRAM heap.\n");
530 return r; 530 return r;
531 } 531 }
532 r = radeon_bo_create(rdev, NULL, 256 * 1024, true, 532 r = radeon_bo_create(rdev, NULL, 256 * 1024, PAGE_SIZE, true,
533 RADEON_GEM_DOMAIN_VRAM, 533 RADEON_GEM_DOMAIN_VRAM,
534 &rdev->stollen_vga_memory); 534 &rdev->stollen_vga_memory);
535 if (r) { 535 if (r) {
@@ -689,7 +689,8 @@ static int radeon_ttm_backend_bind(struct ttm_backend *backend,
689 gtt = container_of(backend, struct radeon_ttm_backend, backend); 689 gtt = container_of(backend, struct radeon_ttm_backend, backend);
690 gtt->offset = bo_mem->start << PAGE_SHIFT; 690 gtt->offset = bo_mem->start << PAGE_SHIFT;
691 if (!gtt->num_pages) { 691 if (!gtt->num_pages) {
692 WARN(1, "nothing to bind %lu pages for mreg %p back %p!\n", gtt->num_pages, bo_mem, backend); 692 WARN(1, "nothing to bind %lu pages for mreg %p back %p!\n",
693 gtt->num_pages, bo_mem, backend);
693 } 694 }
694 r = radeon_gart_bind(gtt->rdev, gtt->offset, 695 r = radeon_gart_bind(gtt->rdev, gtt->offset,
695 gtt->num_pages, gtt->pages); 696 gtt->num_pages, gtt->pages);
diff --git a/drivers/gpu/drm/radeon/rs400.c b/drivers/gpu/drm/radeon/rs400.c
index f683e51a2a06..5512e4e5e636 100644
--- a/drivers/gpu/drm/radeon/rs400.c
+++ b/drivers/gpu/drm/radeon/rs400.c
@@ -78,7 +78,7 @@ int rs400_gart_init(struct radeon_device *rdev)
78 int r; 78 int r;
79 79
80 if (rdev->gart.table.ram.ptr) { 80 if (rdev->gart.table.ram.ptr) {
81 WARN(1, "RS400 GART already initialized.\n"); 81 WARN(1, "RS400 GART already initialized\n");
82 return 0; 82 return 0;
83 } 83 }
84 /* Check gart size */ 84 /* Check gart size */
diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c
index b091a1f6fa4e..f1c6e02c2e6b 100644
--- a/drivers/gpu/drm/radeon/rs600.c
+++ b/drivers/gpu/drm/radeon/rs600.c
@@ -375,7 +375,7 @@ int rs600_gart_init(struct radeon_device *rdev)
375 int r; 375 int r;
376 376
377 if (rdev->gart.table.vram.robj) { 377 if (rdev->gart.table.vram.robj) {
378 WARN(1, "RS600 GART already initialized.\n"); 378 WARN(1, "RS600 GART already initialized\n");
379 return 0; 379 return 0;
380 } 380 }
381 /* Initialize common gart structure */ 381 /* Initialize common gart structure */
@@ -505,7 +505,7 @@ int rs600_irq_set(struct radeon_device *rdev)
505 ~S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1); 505 ~S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
506 506
507 if (!rdev->irq.installed) { 507 if (!rdev->irq.installed) {
508 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n"); 508 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
509 WREG32(R_000040_GEN_INT_CNTL, 0); 509 WREG32(R_000040_GEN_INT_CNTL, 0);
510 return -EINVAL; 510 return -EINVAL;
511 } 511 }
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index 245374e2b778..4dfead8cee33 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -915,8 +915,8 @@ static int rv770_vram_scratch_init(struct radeon_device *rdev)
915 915
916 if (rdev->vram_scratch.robj == NULL) { 916 if (rdev->vram_scratch.robj == NULL) {
917 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, 917 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE,
918 true, RADEON_GEM_DOMAIN_VRAM, 918 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
919 &rdev->vram_scratch.robj); 919 &rdev->vram_scratch.robj);
920 if (r) { 920 if (r) {
921 return r; 921 return r;
922 } 922 }
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index a1cb783c7131..148a322d8f5d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -27,14 +27,6 @@
27/* 27/*
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29 */ 29 */
30/* Notes:
31 *
32 * We store bo pointer in drm_mm_node struct so we know which bo own a
33 * specific node. There is no protection on the pointer, thus to make
34 * sure things don't go berserk you have to access this pointer while
35 * holding the global lru lock and make sure anytime you free a node you
36 * reset the pointer to NULL.
37 */
38 30
39#include "ttm/ttm_module.h" 31#include "ttm/ttm_module.h"
40#include "ttm/ttm_bo_driver.h" 32#include "ttm/ttm_bo_driver.h"
@@ -45,6 +37,7 @@
45#include <linux/mm.h> 37#include <linux/mm.h>
46#include <linux/file.h> 38#include <linux/file.h>
47#include <linux/module.h> 39#include <linux/module.h>
40#include <asm/atomic.h>
48 41
49#define TTM_ASSERT_LOCKED(param) 42#define TTM_ASSERT_LOCKED(param)
50#define TTM_DEBUG(fmt, arg...) 43#define TTM_DEBUG(fmt, arg...)
@@ -231,6 +224,9 @@ int ttm_bo_reserve_locked(struct ttm_buffer_object *bo,
231 int ret; 224 int ret;
232 225
233 while (unlikely(atomic_cmpxchg(&bo->reserved, 0, 1) != 0)) { 226 while (unlikely(atomic_cmpxchg(&bo->reserved, 0, 1) != 0)) {
227 /**
228 * Deadlock avoidance for multi-bo reserving.
229 */
234 if (use_sequence && bo->seq_valid && 230 if (use_sequence && bo->seq_valid &&
235 (sequence - bo->val_seq < (1 << 31))) { 231 (sequence - bo->val_seq < (1 << 31))) {
236 return -EAGAIN; 232 return -EAGAIN;
@@ -248,6 +244,14 @@ int ttm_bo_reserve_locked(struct ttm_buffer_object *bo,
248 } 244 }
249 245
250 if (use_sequence) { 246 if (use_sequence) {
247 /**
248 * Wake up waiters that may need to recheck for deadlock,
249 * if we decreased the sequence number.
250 */
251 if (unlikely((bo->val_seq - sequence < (1 << 31))
252 || !bo->seq_valid))
253 wake_up_all(&bo->event_queue);
254
251 bo->val_seq = sequence; 255 bo->val_seq = sequence;
252 bo->seq_valid = true; 256 bo->seq_valid = true;
253 } else { 257 } else {
@@ -452,6 +456,11 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo)
452 ttm_bo_mem_put(bo, &bo->mem); 456 ttm_bo_mem_put(bo, &bo->mem);
453 457
454 atomic_set(&bo->reserved, 0); 458 atomic_set(&bo->reserved, 0);
459
460 /*
461 * Make processes trying to reserve really pick it up.
462 */
463 smp_mb__after_atomic_dec();
455 wake_up_all(&bo->event_queue); 464 wake_up_all(&bo->event_queue);
456} 465}
457 466
@@ -460,7 +469,7 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
460 struct ttm_bo_device *bdev = bo->bdev; 469 struct ttm_bo_device *bdev = bo->bdev;
461 struct ttm_bo_global *glob = bo->glob; 470 struct ttm_bo_global *glob = bo->glob;
462 struct ttm_bo_driver *driver; 471 struct ttm_bo_driver *driver;
463 void *sync_obj; 472 void *sync_obj = NULL;
464 void *sync_obj_arg; 473 void *sync_obj_arg;
465 int put_count; 474 int put_count;
466 int ret; 475 int ret;
@@ -495,17 +504,20 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
495 spin_lock(&glob->lru_lock); 504 spin_lock(&glob->lru_lock);
496 } 505 }
497queue: 506queue:
498 sync_obj = bo->sync_obj;
499 sync_obj_arg = bo->sync_obj_arg;
500 driver = bdev->driver; 507 driver = bdev->driver;
508 if (bo->sync_obj)
509 sync_obj = driver->sync_obj_ref(bo->sync_obj);
510 sync_obj_arg = bo->sync_obj_arg;
501 511
502 kref_get(&bo->list_kref); 512 kref_get(&bo->list_kref);
503 list_add_tail(&bo->ddestroy, &bdev->ddestroy); 513 list_add_tail(&bo->ddestroy, &bdev->ddestroy);
504 spin_unlock(&glob->lru_lock); 514 spin_unlock(&glob->lru_lock);
505 spin_unlock(&bo->lock); 515 spin_unlock(&bo->lock);
506 516
507 if (sync_obj) 517 if (sync_obj) {
508 driver->sync_obj_flush(sync_obj, sync_obj_arg); 518 driver->sync_obj_flush(sync_obj, sync_obj_arg);
519 driver->sync_obj_unref(&sync_obj);
520 }
509 schedule_delayed_work(&bdev->wq, 521 schedule_delayed_work(&bdev->wq,
510 ((HZ / 100) < 1) ? 1 : HZ / 100); 522 ((HZ / 100) < 1) ? 1 : HZ / 100);
511} 523}
@@ -822,7 +834,6 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
822 bool no_wait_gpu) 834 bool no_wait_gpu)
823{ 835{
824 struct ttm_bo_device *bdev = bo->bdev; 836 struct ttm_bo_device *bdev = bo->bdev;
825 struct ttm_bo_global *glob = bdev->glob;
826 struct ttm_mem_type_manager *man = &bdev->man[mem_type]; 837 struct ttm_mem_type_manager *man = &bdev->man[mem_type];
827 int ret; 838 int ret;
828 839
@@ -832,12 +843,6 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
832 return ret; 843 return ret;
833 if (mem->mm_node) 844 if (mem->mm_node)
834 break; 845 break;
835 spin_lock(&glob->lru_lock);
836 if (list_empty(&man->lru)) {
837 spin_unlock(&glob->lru_lock);
838 break;
839 }
840 spin_unlock(&glob->lru_lock);
841 ret = ttm_mem_evict_first(bdev, mem_type, interruptible, 846 ret = ttm_mem_evict_first(bdev, mem_type, interruptible,
842 no_wait_reserve, no_wait_gpu); 847 no_wait_reserve, no_wait_gpu);
843 if (unlikely(ret != 0)) 848 if (unlikely(ret != 0))
@@ -1125,35 +1130,9 @@ EXPORT_SYMBOL(ttm_bo_validate);
1125int ttm_bo_check_placement(struct ttm_buffer_object *bo, 1130int ttm_bo_check_placement(struct ttm_buffer_object *bo,
1126 struct ttm_placement *placement) 1131 struct ttm_placement *placement)
1127{ 1132{
1128 int i; 1133 BUG_ON((placement->fpfn || placement->lpfn) &&
1134 (bo->mem.num_pages > (placement->lpfn - placement->fpfn)));
1129 1135
1130 if (placement->fpfn || placement->lpfn) {
1131 if (bo->mem.num_pages > (placement->lpfn - placement->fpfn)) {
1132 printk(KERN_ERR TTM_PFX "Page number range to small "
1133 "Need %lu pages, range is [%u, %u]\n",
1134 bo->mem.num_pages, placement->fpfn,
1135 placement->lpfn);
1136 return -EINVAL;
1137 }
1138 }
1139 for (i = 0; i < placement->num_placement; i++) {
1140 if (!capable(CAP_SYS_ADMIN)) {
1141 if (placement->placement[i] & TTM_PL_FLAG_NO_EVICT) {
1142 printk(KERN_ERR TTM_PFX "Need to be root to "
1143 "modify NO_EVICT status.\n");
1144 return -EINVAL;
1145 }
1146 }
1147 }
1148 for (i = 0; i < placement->num_busy_placement; i++) {
1149 if (!capable(CAP_SYS_ADMIN)) {
1150 if (placement->busy_placement[i] & TTM_PL_FLAG_NO_EVICT) {
1151 printk(KERN_ERR TTM_PFX "Need to be root to "
1152 "modify NO_EVICT status.\n");
1153 return -EINVAL;
1154 }
1155 }
1156 }
1157 return 0; 1136 return 0;
1158} 1137}
1159 1138
@@ -1176,6 +1155,10 @@ int ttm_bo_init(struct ttm_bo_device *bdev,
1176 num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; 1155 num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
1177 if (num_pages == 0) { 1156 if (num_pages == 0) {
1178 printk(KERN_ERR TTM_PFX "Illegal buffer object size.\n"); 1157 printk(KERN_ERR TTM_PFX "Illegal buffer object size.\n");
1158 if (destroy)
1159 (*destroy)(bo);
1160 else
1161 kfree(bo);
1179 return -EINVAL; 1162 return -EINVAL;
1180 } 1163 }
1181 bo->destroy = destroy; 1164 bo->destroy = destroy;
@@ -1369,18 +1352,9 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
1369 int ret = -EINVAL; 1352 int ret = -EINVAL;
1370 struct ttm_mem_type_manager *man; 1353 struct ttm_mem_type_manager *man;
1371 1354
1372 if (type >= TTM_NUM_MEM_TYPES) { 1355 BUG_ON(type >= TTM_NUM_MEM_TYPES);
1373 printk(KERN_ERR TTM_PFX "Illegal memory type %d\n", type);
1374 return ret;
1375 }
1376
1377 man = &bdev->man[type]; 1356 man = &bdev->man[type];
1378 if (man->has_type) { 1357 BUG_ON(man->has_type);
1379 printk(KERN_ERR TTM_PFX
1380 "Memory manager already initialized for type %d\n",
1381 type);
1382 return ret;
1383 }
1384 1358
1385 ret = bdev->driver->init_mem_type(bdev, type, man); 1359 ret = bdev->driver->init_mem_type(bdev, type, man);
1386 if (ret) 1360 if (ret)
@@ -1389,13 +1363,6 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
1389 1363
1390 ret = 0; 1364 ret = 0;
1391 if (type != TTM_PL_SYSTEM) { 1365 if (type != TTM_PL_SYSTEM) {
1392 if (!p_size) {
1393 printk(KERN_ERR TTM_PFX
1394 "Zero size memory manager type %d\n",
1395 type);
1396 return ret;
1397 }
1398
1399 ret = (*man->func->init)(man, p_size); 1366 ret = (*man->func->init)(man, p_size);
1400 if (ret) 1367 if (ret)
1401 return ret; 1368 return ret;
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 7410c190c891..038e947d00f9 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -1,6 +1,6 @@
1/************************************************************************** 1/**************************************************************************
2 * 2 *
3 * Copyright (c) 2007-2009 VMware, Inc., Palo Alto, CA., USA 3 * Copyright (c) 2007-2010 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved. 4 * All Rights Reserved.
5 * 5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a 6 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -31,20 +31,29 @@
31#include "ttm/ttm_module.h" 31#include "ttm/ttm_module.h"
32#include "ttm/ttm_bo_driver.h" 32#include "ttm/ttm_bo_driver.h"
33#include "ttm/ttm_placement.h" 33#include "ttm/ttm_placement.h"
34#include <linux/jiffies.h> 34#include "drm_mm.h"
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/sched.h> 36#include <linux/spinlock.h>
37#include <linux/mm.h>
38#include <linux/file.h>
39#include <linux/module.h> 37#include <linux/module.h>
40 38
39/**
40 * Currently we use a spinlock for the lock, but a mutex *may* be
41 * more appropriate to reduce scheduling latency if the range manager
42 * ends up with very fragmented allocation patterns.
43 */
44
45struct ttm_range_manager {
46 struct drm_mm mm;
47 spinlock_t lock;
48};
49
41static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man, 50static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
42 struct ttm_buffer_object *bo, 51 struct ttm_buffer_object *bo,
43 struct ttm_placement *placement, 52 struct ttm_placement *placement,
44 struct ttm_mem_reg *mem) 53 struct ttm_mem_reg *mem)
45{ 54{
46 struct ttm_bo_global *glob = man->bdev->glob; 55 struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
47 struct drm_mm *mm = man->priv; 56 struct drm_mm *mm = &rman->mm;
48 struct drm_mm_node *node = NULL; 57 struct drm_mm_node *node = NULL;
49 unsigned long lpfn; 58 unsigned long lpfn;
50 int ret; 59 int ret;
@@ -57,19 +66,19 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
57 if (unlikely(ret)) 66 if (unlikely(ret))
58 return ret; 67 return ret;
59 68
60 spin_lock(&glob->lru_lock); 69 spin_lock(&rman->lock);
61 node = drm_mm_search_free_in_range(mm, 70 node = drm_mm_search_free_in_range(mm,
62 mem->num_pages, mem->page_alignment, 71 mem->num_pages, mem->page_alignment,
63 placement->fpfn, lpfn, 1); 72 placement->fpfn, lpfn, 1);
64 if (unlikely(node == NULL)) { 73 if (unlikely(node == NULL)) {
65 spin_unlock(&glob->lru_lock); 74 spin_unlock(&rman->lock);
66 return 0; 75 return 0;
67 } 76 }
68 node = drm_mm_get_block_atomic_range(node, mem->num_pages, 77 node = drm_mm_get_block_atomic_range(node, mem->num_pages,
69 mem->page_alignment, 78 mem->page_alignment,
70 placement->fpfn, 79 placement->fpfn,
71 lpfn); 80 lpfn);
72 spin_unlock(&glob->lru_lock); 81 spin_unlock(&rman->lock);
73 } while (node == NULL); 82 } while (node == NULL);
74 83
75 mem->mm_node = node; 84 mem->mm_node = node;
@@ -80,12 +89,12 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
80static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man, 89static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
81 struct ttm_mem_reg *mem) 90 struct ttm_mem_reg *mem)
82{ 91{
83 struct ttm_bo_global *glob = man->bdev->glob; 92 struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
84 93
85 if (mem->mm_node) { 94 if (mem->mm_node) {
86 spin_lock(&glob->lru_lock); 95 spin_lock(&rman->lock);
87 drm_mm_put_block(mem->mm_node); 96 drm_mm_put_block(mem->mm_node);
88 spin_unlock(&glob->lru_lock); 97 spin_unlock(&rman->lock);
89 mem->mm_node = NULL; 98 mem->mm_node = NULL;
90 } 99 }
91} 100}
@@ -93,49 +102,49 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
93static int ttm_bo_man_init(struct ttm_mem_type_manager *man, 102static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
94 unsigned long p_size) 103 unsigned long p_size)
95{ 104{
96 struct drm_mm *mm; 105 struct ttm_range_manager *rman;
97 int ret; 106 int ret;
98 107
99 mm = kzalloc(sizeof(*mm), GFP_KERNEL); 108 rman = kzalloc(sizeof(*rman), GFP_KERNEL);
100 if (!mm) 109 if (!rman)
101 return -ENOMEM; 110 return -ENOMEM;
102 111
103 ret = drm_mm_init(mm, 0, p_size); 112 ret = drm_mm_init(&rman->mm, 0, p_size);
104 if (ret) { 113 if (ret) {
105 kfree(mm); 114 kfree(rman);
106 return ret; 115 return ret;
107 } 116 }
108 117
109 man->priv = mm; 118 spin_lock_init(&rman->lock);
119 man->priv = rman;
110 return 0; 120 return 0;
111} 121}
112 122
113static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man) 123static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
114{ 124{
115 struct ttm_bo_global *glob = man->bdev->glob; 125 struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
116 struct drm_mm *mm = man->priv; 126 struct drm_mm *mm = &rman->mm;
117 int ret = 0;
118 127
119 spin_lock(&glob->lru_lock); 128 spin_lock(&rman->lock);
120 if (drm_mm_clean(mm)) { 129 if (drm_mm_clean(mm)) {
121 drm_mm_takedown(mm); 130 drm_mm_takedown(mm);
122 kfree(mm); 131 spin_unlock(&rman->lock);
132 kfree(rman);
123 man->priv = NULL; 133 man->priv = NULL;
124 } else 134 return 0;
125 ret = -EBUSY; 135 }
126 spin_unlock(&glob->lru_lock); 136 spin_unlock(&rman->lock);
127 return ret; 137 return -EBUSY;
128} 138}
129 139
130static void ttm_bo_man_debug(struct ttm_mem_type_manager *man, 140static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
131 const char *prefix) 141 const char *prefix)
132{ 142{
133 struct ttm_bo_global *glob = man->bdev->glob; 143 struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
134 struct drm_mm *mm = man->priv;
135 144
136 spin_lock(&glob->lru_lock); 145 spin_lock(&rman->lock);
137 drm_mm_debug_table(mm, prefix); 146 drm_mm_debug_table(&rman->mm, prefix);
138 spin_unlock(&glob->lru_lock); 147 spin_unlock(&rman->lock);
139} 148}
140 149
141const struct ttm_mem_type_manager_func ttm_bo_manager_func = { 150const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index a7bab87a548b..af789dc869b9 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -440,10 +440,8 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
440 return ret; 440 return ret;
441 441
442 ret = be->func->bind(be, bo_mem); 442 ret = be->func->bind(be, bo_mem);
443 if (ret) { 443 if (unlikely(ret != 0))
444 printk(KERN_ERR TTM_PFX "Couldn't bind backend.\n");
445 return ret; 444 return ret;
446 }
447 445
448 ttm->state = tt_bound; 446 ttm->state = tt_bound;
449 447
diff --git a/drivers/gpu/drm/via/via_dmablit.c b/drivers/gpu/drm/via/via_dmablit.c
index 9b5b4d9dd62c..3e038a394c51 100644
--- a/drivers/gpu/drm/via/via_dmablit.c
+++ b/drivers/gpu/drm/via/via_dmablit.c
@@ -235,9 +235,9 @@ via_lock_all_dma_pages(drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer)
235 vsg->num_pages = VIA_PFN(xfer->mem_addr + (xfer->num_lines * xfer->mem_stride - 1)) - 235 vsg->num_pages = VIA_PFN(xfer->mem_addr + (xfer->num_lines * xfer->mem_stride - 1)) -
236 first_pfn + 1; 236 first_pfn + 1;
237 237
238 if (NULL == (vsg->pages = vmalloc(sizeof(struct page *) * vsg->num_pages))) 238 vsg->pages = vzalloc(sizeof(struct page *) * vsg->num_pages);
239 if (NULL == vsg->pages)
239 return -ENOMEM; 240 return -ENOMEM;
240 memset(vsg->pages, 0, sizeof(struct page *) * vsg->num_pages);
241 down_read(&current->mm->mmap_sem); 241 down_read(&current->mm->mmap_sem);
242 ret = get_user_pages(current, current->mm, 242 ret = get_user_pages(current, current->mm,
243 (unsigned long)xfer->mem_addr, 243 (unsigned long)xfer->mem_addr,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index 51d9f9f1d7f2..76954e3528c1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -691,6 +691,7 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
691 691
692 fence_rep.error = ret; 692 fence_rep.error = ret;
693 fence_rep.fence_seq = (uint64_t) sequence; 693 fence_rep.fence_seq = (uint64_t) sequence;
694 fence_rep.pad64 = 0;
694 695
695 user_fence_rep = (struct drm_vmw_fence_rep __user *) 696 user_fence_rep = (struct drm_vmw_fence_rep __user *)
696 (unsigned long)arg->fence_rep; 697 (unsigned long)arg->fence_rep;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 87c6e6156d7d..cceeb42789b6 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -720,6 +720,8 @@ static int vmw_surface_dmabuf_pin(struct vmw_framebuffer *vfb)
720 &vmw_vram_ne_placement, 720 &vmw_vram_ne_placement,
721 false, &vmw_dmabuf_bo_free); 721 false, &vmw_dmabuf_bo_free);
722 vmw_overlay_resume_all(dev_priv); 722 vmw_overlay_resume_all(dev_priv);
723 if (unlikely(ret != 0))
724 vfbs->buffer = NULL;
723 725
724 return ret; 726 return ret;
725} 727}
@@ -730,6 +732,9 @@ static int vmw_surface_dmabuf_unpin(struct vmw_framebuffer *vfb)
730 struct vmw_framebuffer_surface *vfbs = 732 struct vmw_framebuffer_surface *vfbs =
731 vmw_framebuffer_to_vfbs(&vfb->base); 733 vmw_framebuffer_to_vfbs(&vfb->base);
732 734
735 if (unlikely(vfbs->buffer == NULL))
736 return 0;
737
733 bo = &vfbs->buffer->base; 738 bo = &vfbs->buffer->base;
734 ttm_bo_unref(&bo); 739 ttm_bo_unref(&bo);
735 vfbs->buffer = NULL; 740 vfbs->buffer = NULL;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
index a01c47ddb5bc..29113c9b26a8 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
@@ -557,7 +557,7 @@ int vmw_kms_init_legacy_display_system(struct vmw_private *dev_priv)
557 return -EINVAL; 557 return -EINVAL;
558 } 558 }
559 559
560 dev_priv->ldu_priv = kmalloc(GFP_KERNEL, sizeof(*dev_priv->ldu_priv)); 560 dev_priv->ldu_priv = kmalloc(sizeof(*dev_priv->ldu_priv), GFP_KERNEL);
561 561
562 if (!dev_priv->ldu_priv) 562 if (!dev_priv->ldu_priv)
563 return -ENOMEM; 563 return -ENOMEM;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c b/drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c
index df2036ed18d5..f1a52f9e7298 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c
@@ -585,7 +585,7 @@ int vmw_overlay_init(struct vmw_private *dev_priv)
585 return -ENOSYS; 585 return -ENOSYS;
586 } 586 }
587 587
588 overlay = kmalloc(GFP_KERNEL, sizeof(*overlay)); 588 overlay = kmalloc(sizeof(*overlay), GFP_KERNEL);
589 if (!overlay) 589 if (!overlay)
590 return -ENOMEM; 590 return -ENOMEM;
591 591
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 36e129f0023f..5408b1b7996f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -862,7 +862,7 @@ int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
862 &vmw_vram_sys_placement, true, 862 &vmw_vram_sys_placement, true,
863 &vmw_user_dmabuf_destroy); 863 &vmw_user_dmabuf_destroy);
864 if (unlikely(ret != 0)) 864 if (unlikely(ret != 0))
865 return ret; 865 goto out_no_dmabuf;
866 866
867 tmp = ttm_bo_reference(&vmw_user_bo->dma.base); 867 tmp = ttm_bo_reference(&vmw_user_bo->dma.base);
868 ret = ttm_base_object_init(vmw_fpriv(file_priv)->tfile, 868 ret = ttm_base_object_init(vmw_fpriv(file_priv)->tfile,
@@ -870,19 +870,21 @@ int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
870 false, 870 false,
871 ttm_buffer_type, 871 ttm_buffer_type,
872 &vmw_user_dmabuf_release, NULL); 872 &vmw_user_dmabuf_release, NULL);
873 if (unlikely(ret != 0)) { 873 if (unlikely(ret != 0))
874 ttm_bo_unref(&tmp); 874 goto out_no_base_object;
875 } else { 875 else {
876 rep->handle = vmw_user_bo->base.hash.key; 876 rep->handle = vmw_user_bo->base.hash.key;
877 rep->map_handle = vmw_user_bo->dma.base.addr_space_offset; 877 rep->map_handle = vmw_user_bo->dma.base.addr_space_offset;
878 rep->cur_gmr_id = vmw_user_bo->base.hash.key; 878 rep->cur_gmr_id = vmw_user_bo->base.hash.key;
879 rep->cur_gmr_offset = 0; 879 rep->cur_gmr_offset = 0;
880 } 880 }
881 ttm_bo_unref(&tmp);
882 881
882out_no_base_object:
883 ttm_bo_unref(&tmp);
884out_no_dmabuf:
883 ttm_read_unlock(&vmaster->lock); 885 ttm_read_unlock(&vmaster->lock);
884 886
885 return 0; 887 return ret;
886} 888}
887 889
888int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data, 890int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
diff --git a/drivers/gpu/stub/Kconfig b/drivers/gpu/stub/Kconfig
index 742c423567cf..0e1edd7311ff 100644
--- a/drivers/gpu/stub/Kconfig
+++ b/drivers/gpu/stub/Kconfig
@@ -3,6 +3,9 @@ config STUB_POULSBO
3 depends on PCI 3 depends on PCI
4 # Poulsbo stub depends on ACPI_VIDEO when ACPI is enabled 4 # Poulsbo stub depends on ACPI_VIDEO when ACPI is enabled
5 # but for select to work, need to select ACPI_VIDEO's dependencies, ick 5 # but for select to work, need to select ACPI_VIDEO's dependencies, ick
6 select VIDEO_OUTPUT_CONTROL if ACPI
7 select BACKLIGHT_CLASS_DEVICE if ACPI
8 select INPUT if ACPI
6 select ACPI_VIDEO if ACPI 9 select ACPI_VIDEO if ACPI
7 help 10 help
8 Choose this option if you have a system that has Intel GMA500 11 Choose this option if you have a system that has Intel GMA500
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 515345b11ac9..88cb04e7962b 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1386,6 +1386,7 @@ static const struct hid_device_id hid_blacklist[] = {
1386 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) }, 1386 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
1387 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) }, 1387 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1388 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) }, 1388 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1389 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
1389 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) }, 1390 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
1390 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) }, 1391 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1391 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) }, 1392 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
diff --git a/drivers/hid/hid-egalax.c b/drivers/hid/hid-egalax.c
index 54b017ad258d..5a1b52e0eb85 100644
--- a/drivers/hid/hid-egalax.c
+++ b/drivers/hid/hid-egalax.c
@@ -221,7 +221,7 @@ static int egalax_probe(struct hid_device *hdev, const struct hid_device_id *id)
221 struct egalax_data *td; 221 struct egalax_data *td;
222 struct hid_report *report; 222 struct hid_report *report;
223 223
224 td = kmalloc(sizeof(struct egalax_data), GFP_KERNEL); 224 td = kzalloc(sizeof(struct egalax_data), GFP_KERNEL);
225 if (!td) { 225 if (!td) {
226 dev_err(&hdev->dev, "cannot allocate eGalax data\n"); 226 dev_err(&hdev->dev, "cannot allocate eGalax data\n");
227 return -ENOMEM; 227 return -ENOMEM;
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index bb0b3659437b..d8d372bae3cc 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -174,7 +174,7 @@ static int hidinput_setkeycode(struct input_dev *dev,
174 174
175 clear_bit(*old_keycode, dev->keybit); 175 clear_bit(*old_keycode, dev->keybit);
176 set_bit(usage->code, dev->keybit); 176 set_bit(usage->code, dev->keybit);
177 dbg_hid(KERN_DEBUG "Assigned keycode %d to HID usage code %x\n", 177 dbg_hid("Assigned keycode %d to HID usage code %x\n",
178 usage->code, usage->hid); 178 usage->code, usage->hid);
179 179
180 /* 180 /*
@@ -203,8 +203,8 @@ static int hidinput_setkeycode(struct input_dev *dev,
203 * 203 *
204 * as seen in the HID specification v1.11 6.2.2.7 Global Items. 204 * as seen in the HID specification v1.11 6.2.2.7 Global Items.
205 * 205 *
206 * Only exponent 1 length units are processed. Centimeters are converted to 206 * Only exponent 1 length units are processed. Centimeters and inches are
207 * inches. Degrees are converted to radians. 207 * converted to millimeters. Degrees are converted to radians.
208 */ 208 */
209static __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code) 209static __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
210{ 210{
@@ -225,13 +225,16 @@ static __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
225 */ 225 */
226 if (code == ABS_X || code == ABS_Y || code == ABS_Z) { 226 if (code == ABS_X || code == ABS_Y || code == ABS_Z) {
227 if (field->unit == 0x11) { /* If centimeters */ 227 if (field->unit == 0x11) { /* If centimeters */
228 /* Convert to inches */ 228 /* Convert to millimeters */
229 prev = logical_extents; 229 unit_exponent += 1;
230 logical_extents *= 254; 230 } else if (field->unit == 0x13) { /* If inches */
231 if (logical_extents < prev) 231 /* Convert to millimeters */
232 prev = physical_extents;
233 physical_extents *= 254;
234 if (physical_extents < prev)
232 return 0; 235 return 0;
233 unit_exponent += 2; 236 unit_exponent -= 1;
234 } else if (field->unit != 0x13) { /* If not inches */ 237 } else {
235 return 0; 238 return 0;
236 } 239 }
237 } else if (code == ABS_RX || code == ABS_RY || code == ABS_RZ) { 240 } else if (code == ABS_RX || code == ABS_RY || code == ABS_RZ) {
diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
index 15434c814793..25be4e1461bd 100644
--- a/drivers/hid/hid-tmff.c
+++ b/drivers/hid/hid-tmff.c
@@ -256,6 +256,8 @@ static const struct hid_device_id tm_devices[] = {
256 .driver_data = (unsigned long)ff_joystick }, 256 .driver_data = (unsigned long)ff_joystick },
257 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654), /* FGT Force Feedback Wheel */ 257 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654), /* FGT Force Feedback Wheel */
258 .driver_data = (unsigned long)ff_joystick }, 258 .driver_data = (unsigned long)ff_joystick },
259 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a), /* F430 Force Feedback Wheel */
260 .driver_data = (unsigned long)ff_joystick },
259 { } 261 { }
260}; 262};
261MODULE_DEVICE_TABLE(hid, tm_devices); 263MODULE_DEVICE_TABLE(hid, tm_devices);
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 8a4b32dca9f7..e1f07483691f 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -32,7 +32,6 @@
32#include <linux/hid.h> 32#include <linux/hid.h>
33#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <linux/sched.h> 34#include <linux/sched.h>
35#include <linux/smp_lock.h>
36 35
37#include <linux/hidraw.h> 36#include <linux/hidraw.h>
38 37
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index fedd88df9a18..984feb351a5a 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -29,7 +29,6 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/smp_lock.h>
33#include <linux/input.h> 32#include <linux/input.h>
34#include <linux/usb.h> 33#include <linux/usb.h>
35#include <linux/hid.h> 34#include <linux/hid.h>
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c
index 1e4c21fc1a89..86d822aa9bbf 100644
--- a/drivers/hwmon/ad7414.c
+++ b/drivers/hwmon/ad7414.c
@@ -178,11 +178,13 @@ static int ad7414_probe(struct i2c_client *client,
178{ 178{
179 struct ad7414_data *data; 179 struct ad7414_data *data;
180 int conf; 180 int conf;
181 int err = 0; 181 int err;
182 182
183 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | 183 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
184 I2C_FUNC_SMBUS_READ_WORD_DATA)) 184 I2C_FUNC_SMBUS_READ_WORD_DATA)) {
185 err = -EOPNOTSUPP;
185 goto exit; 186 goto exit;
187 }
186 188
187 data = kzalloc(sizeof(struct ad7414_data), GFP_KERNEL); 189 data = kzalloc(sizeof(struct ad7414_data), GFP_KERNEL);
188 if (!data) { 190 if (!data) {
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 4bf969c0a32b..be0fdd58aa29 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -916,27 +916,27 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
916 int nr = sensor_attr->index; 916 int nr = sensor_attr->index;
917 struct i2c_client *client = to_i2c_client(dev); 917 struct i2c_client *client = to_i2c_client(dev);
918 struct adm1026_data *data = i2c_get_clientdata(client); 918 struct adm1026_data *data = i2c_get_clientdata(client);
919 int val, orig_div, new_div, shift; 919 int val, orig_div, new_div;
920 920
921 val = simple_strtol(buf, NULL, 10); 921 val = simple_strtol(buf, NULL, 10);
922 new_div = DIV_TO_REG(val); 922 new_div = DIV_TO_REG(val);
923 if (new_div == 0) { 923
924 return -EINVAL;
925 }
926 mutex_lock(&data->update_lock); 924 mutex_lock(&data->update_lock);
927 orig_div = data->fan_div[nr]; 925 orig_div = data->fan_div[nr];
928 data->fan_div[nr] = DIV_FROM_REG(new_div); 926 data->fan_div[nr] = DIV_FROM_REG(new_div);
929 927
930 if (nr < 4) { /* 0 <= nr < 4 */ 928 if (nr < 4) { /* 0 <= nr < 4 */
931 shift = 2 * nr;
932 adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3, 929 adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
933 ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) | 930 (DIV_TO_REG(data->fan_div[0]) << 0) |
934 (new_div << shift))); 931 (DIV_TO_REG(data->fan_div[1]) << 2) |
932 (DIV_TO_REG(data->fan_div[2]) << 4) |
933 (DIV_TO_REG(data->fan_div[3]) << 6));
935 } else { /* 3 < nr < 8 */ 934 } else { /* 3 < nr < 8 */
936 shift = 2 * (nr - 4);
937 adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7, 935 adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
938 ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) | 936 (DIV_TO_REG(data->fan_div[4]) << 0) |
939 (new_div << shift))); 937 (DIV_TO_REG(data->fan_div[5]) << 2) |
938 (DIV_TO_REG(data->fan_div[6]) << 4) |
939 (DIV_TO_REG(data->fan_div[7]) << 6));
940 } 940 }
941 941
942 if (data->fan_div[nr] != orig_div) { 942 if (data->fan_div[nr] != orig_div) {
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 9e775717abb7..87d92a56a939 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -1286,8 +1286,10 @@ static int adt7470_probe(struct i2c_client *client,
1286 init_completion(&data->auto_update_stop); 1286 init_completion(&data->auto_update_stop);
1287 data->auto_update = kthread_run(adt7470_update_thread, client, 1287 data->auto_update = kthread_run(adt7470_update_thread, client,
1288 dev_name(data->hwmon_dev)); 1288 dev_name(data->hwmon_dev));
1289 if (IS_ERR(data->auto_update)) 1289 if (IS_ERR(data->auto_update)) {
1290 err = PTR_ERR(data->auto_update);
1290 goto exit_unregister; 1291 goto exit_unregister;
1292 }
1291 1293
1292 return 0; 1294 return 0;
1293 1295
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index fa9708c2d723..4033974d1bb3 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -4,7 +4,7 @@
4 Copyright (C) 2009 T. Mertelj <tomaz.mertelj@guest.arnes.si> 4 Copyright (C) 2009 T. Mertelj <tomaz.mertelj@guest.arnes.si>
5 5
6 Based on max6650.c: 6 Based on max6650.c:
7 Copyright (C) 2007 Hans J. Koch <hjk@linutronix.de> 7 Copyright (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index aa701a183707..f141a1de519c 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -376,10 +376,6 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
376 } 376 }
377 } 377 }
378 378
379 err = sysfs_create_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
380 if (err)
381 goto err_free_gpio;
382
383 fan_data->num_ctrl = num_ctrl; 379 fan_data->num_ctrl = num_ctrl;
384 fan_data->ctrl = ctrl; 380 fan_data->ctrl = ctrl;
385 fan_data->num_speed = pdata->num_speed; 381 fan_data->num_speed = pdata->num_speed;
@@ -391,6 +387,10 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
391 goto err_free_gpio; 387 goto err_free_gpio;
392 } 388 }
393 389
390 err = sysfs_create_group(&pdev->dev.kobj, &gpio_fan_ctrl_group);
391 if (err)
392 goto err_free_gpio;
393
394 return 0; 394 return 0;
395 395
396err_free_gpio: 396err_free_gpio:
diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c
index 937983407e2a..c4c40be0edbf 100644
--- a/drivers/hwmon/i5k_amb.c
+++ b/drivers/hwmon/i5k_amb.c
@@ -497,12 +497,14 @@ static unsigned long chipset_ids[] = {
497 0 497 0
498}; 498};
499 499
500#ifdef MODULE
500static struct pci_device_id i5k_amb_ids[] __devinitdata = { 501static struct pci_device_id i5k_amb_ids[] __devinitdata = {
501 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) }, 502 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },
502 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR) }, 503 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR) },
503 { 0, } 504 { 0, }
504}; 505};
505MODULE_DEVICE_TABLE(pci, i5k_amb_ids); 506MODULE_DEVICE_TABLE(pci, i5k_amb_ids);
507#endif
506 508
507static int __devinit i5k_amb_probe(struct platform_device *pdev) 509static int __devinit i5k_amb_probe(struct platform_device *pdev)
508{ 510{
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 14a5d981be7d..a428a9264195 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -187,6 +187,7 @@ static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
187#define IT87_REG_FAN_MAIN_CTRL 0x13 187#define IT87_REG_FAN_MAIN_CTRL 0x13
188#define IT87_REG_FAN_CTL 0x14 188#define IT87_REG_FAN_CTL 0x14
189#define IT87_REG_PWM(nr) (0x15 + (nr)) 189#define IT87_REG_PWM(nr) (0x15 + (nr))
190#define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8)
190 191
191#define IT87_REG_VIN(nr) (0x20 + (nr)) 192#define IT87_REG_VIN(nr) (0x20 + (nr))
192#define IT87_REG_TEMP(nr) (0x29 + (nr)) 193#define IT87_REG_TEMP(nr) (0x29 + (nr))
@@ -251,12 +252,16 @@ struct it87_data {
251 u8 fan_main_ctrl; /* Register value */ 252 u8 fan_main_ctrl; /* Register value */
252 u8 fan_ctl; /* Register value */ 253 u8 fan_ctl; /* Register value */
253 254
254 /* The following 3 arrays correspond to the same registers. The 255 /* The following 3 arrays correspond to the same registers up to
255 * meaning of bits 6-0 depends on the value of bit 7, and we want 256 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
256 * to preserve settings on mode changes, so we have to track all 257 * 7, and we want to preserve settings on mode changes, so we have
257 * values separately. */ 258 * to track all values separately.
259 * Starting with the IT8721F, the manual PWM duty cycles are stored
260 * in separate registers (8-bit values), so the separate tracking
261 * is no longer needed, but it is still done to keep the driver
262 * simple. */
258 u8 pwm_ctrl[3]; /* Register value */ 263 u8 pwm_ctrl[3]; /* Register value */
259 u8 pwm_duty[3]; /* Manual PWM value set by user (bit 6-0) */ 264 u8 pwm_duty[3]; /* Manual PWM value set by user */
260 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */ 265 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
261 266
262 /* Automatic fan speed control registers */ 267 /* Automatic fan speed control registers */
@@ -832,7 +837,9 @@ static ssize_t set_pwm_enable(struct device *dev,
832 data->fan_main_ctrl); 837 data->fan_main_ctrl);
833 } else { 838 } else {
834 if (val == 1) /* Manual mode */ 839 if (val == 1) /* Manual mode */
835 data->pwm_ctrl[nr] = data->pwm_duty[nr]; 840 data->pwm_ctrl[nr] = data->type == it8721 ?
841 data->pwm_temp_map[nr] :
842 data->pwm_duty[nr];
836 else /* Automatic mode */ 843 else /* Automatic mode */
837 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; 844 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
838 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); 845 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
@@ -858,12 +865,25 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
858 return -EINVAL; 865 return -EINVAL;
859 866
860 mutex_lock(&data->update_lock); 867 mutex_lock(&data->update_lock);
861 data->pwm_duty[nr] = pwm_to_reg(data, val); 868 if (data->type == it8721) {
862 /* If we are in manual mode, write the duty cycle immediately; 869 /* If we are in automatic mode, the PWM duty cycle register
863 * otherwise, just store it for later use. */ 870 * is read-only so we can't write the value */
864 if (!(data->pwm_ctrl[nr] & 0x80)) { 871 if (data->pwm_ctrl[nr] & 0x80) {
865 data->pwm_ctrl[nr] = data->pwm_duty[nr]; 872 mutex_unlock(&data->update_lock);
866 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); 873 return -EBUSY;
874 }
875 data->pwm_duty[nr] = pwm_to_reg(data, val);
876 it87_write_value(data, IT87_REG_PWM_DUTY(nr),
877 data->pwm_duty[nr]);
878 } else {
879 data->pwm_duty[nr] = pwm_to_reg(data, val);
880 /* If we are in manual mode, write the duty cycle immediately;
881 * otherwise, just store it for later use. */
882 if (!(data->pwm_ctrl[nr] & 0x80)) {
883 data->pwm_ctrl[nr] = data->pwm_duty[nr];
884 it87_write_value(data, IT87_REG_PWM(nr),
885 data->pwm_ctrl[nr]);
886 }
867 } 887 }
868 mutex_unlock(&data->update_lock); 888 mutex_unlock(&data->update_lock);
869 return count; 889 return count;
@@ -1958,7 +1978,10 @@ static void __devinit it87_init_device(struct platform_device *pdev)
1958 * channels to use when later setting to automatic mode later. 1978 * channels to use when later setting to automatic mode later.
1959 * Use a 1:1 mapping by default (we are clueless.) 1979 * Use a 1:1 mapping by default (we are clueless.)
1960 * In both cases, the value can (and should) be changed by the user 1980 * In both cases, the value can (and should) be changed by the user
1961 * prior to switching to a different mode. */ 1981 * prior to switching to a different mode.
1982 * Note that this is no longer needed for the IT8721F and later, as
1983 * these have separate registers for the temperature mapping and the
1984 * manual duty cycle. */
1962 for (i = 0; i < 3; i++) { 1985 for (i = 0; i < 3; i++) {
1963 data->pwm_temp_map[i] = i; 1986 data->pwm_temp_map[i] = i;
1964 data->pwm_duty[i] = 0x7f; /* Full speed */ 1987 data->pwm_duty[i] = 0x7f; /* Full speed */
@@ -2034,10 +2057,16 @@ static void __devinit it87_init_device(struct platform_device *pdev)
2034static void it87_update_pwm_ctrl(struct it87_data *data, int nr) 2057static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
2035{ 2058{
2036 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr)); 2059 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
2037 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ 2060 if (data->type == it8721) {
2038 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; 2061 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2039 else /* Manual mode */ 2062 data->pwm_duty[nr] = it87_read_value(data,
2040 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; 2063 IT87_REG_PWM_DUTY(nr));
2064 } else {
2065 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
2066 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2067 else /* Manual mode */
2068 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
2069 }
2041 2070
2042 if (has_old_autopwm(data)) { 2071 if (has_old_autopwm(data)) {
2043 int i; 2072 int i;
diff --git a/drivers/hwmon/lis3lv02d_i2c.c b/drivers/hwmon/lis3lv02d_i2c.c
index 9f4bae07f719..8853afce85ce 100644
--- a/drivers/hwmon/lis3lv02d_i2c.c
+++ b/drivers/hwmon/lis3lv02d_i2c.c
@@ -186,7 +186,7 @@ static int __devexit lis3lv02d_i2c_remove(struct i2c_client *client)
186 return 0; 186 return 0;
187} 187}
188 188
189#ifdef CONFIG_PM 189#ifdef CONFIG_PM_SLEEP
190static int lis3lv02d_i2c_suspend(struct device *dev) 190static int lis3lv02d_i2c_suspend(struct device *dev)
191{ 191{
192 struct i2c_client *client = container_of(dev, struct i2c_client, dev); 192 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
@@ -213,12 +213,9 @@ static int lis3lv02d_i2c_resume(struct device *dev)
213 213
214 return 0; 214 return 0;
215} 215}
216#else 216#endif /* CONFIG_PM_SLEEP */
217#define lis3lv02d_i2c_suspend NULL
218#define lis3lv02d_i2c_resume NULL
219#define lis3lv02d_i2c_shutdown NULL
220#endif
221 217
218#ifdef CONFIG_PM_RUNTIME
222static int lis3_i2c_runtime_suspend(struct device *dev) 219static int lis3_i2c_runtime_suspend(struct device *dev)
223{ 220{
224 struct i2c_client *client = container_of(dev, struct i2c_client, dev); 221 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
@@ -236,6 +233,7 @@ static int lis3_i2c_runtime_resume(struct device *dev)
236 lis3lv02d_poweron(lis3); 233 lis3lv02d_poweron(lis3);
237 return 0; 234 return 0;
238} 235}
236#endif /* CONFIG_PM_RUNTIME */
239 237
240static const struct i2c_device_id lis3lv02d_id[] = { 238static const struct i2c_device_id lis3lv02d_id[] = {
241 {"lis3lv02d", 0 }, 239 {"lis3lv02d", 0 },
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c
index 6669255aadcf..c9ed14eba5a6 100644
--- a/drivers/hwmon/lm93.c
+++ b/drivers/hwmon/lm93.c
@@ -20,7 +20,7 @@
20 Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org> 20 Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org>
21 Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab 21 Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab
22 22
23 Modified for mainline integration by Hans J. Koch <hjk@linutronix.de> 23 Modified for mainline integration by Hans J. Koch <hjk@hansjkoch.de>
24 Copyright (c) 2007 Hans J. Koch, Linutronix GmbH 24 Copyright (c) 2007 Hans J. Koch, Linutronix GmbH
25 25
26 This program is free software; you can redistribute it and/or modify 26 This program is free software; you can redistribute it and/or modify
@@ -2629,7 +2629,7 @@ static void __exit lm93_exit(void)
2629} 2629}
2630 2630
2631MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, " 2631MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, "
2632 "Hans J. Koch <hjk@linutronix.de"); 2632 "Hans J. Koch <hjk@hansjkoch.de>");
2633MODULE_DESCRIPTION("LM93 driver"); 2633MODULE_DESCRIPTION("LM93 driver");
2634MODULE_LICENSE("GPL"); 2634MODULE_LICENSE("GPL");
2635 2635
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 464340f25496..4546d82f024a 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -128,9 +128,12 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
128{ 128{
129 struct i2c_client *client = to_i2c_client(dev); 129 struct i2c_client *client = to_i2c_client(dev);
130 struct lm95241_data *data = i2c_get_clientdata(client); 130 struct lm95241_data *data = i2c_get_clientdata(client);
131 unsigned long val;
131 132
132 strict_strtol(buf, 10, &data->interval); 133 if (strict_strtoul(buf, 10, &val) < 0)
133 data->interval = data->interval * HZ / 1000; 134 return -EINVAL;
135
136 data->interval = val * HZ / 1000;
134 137
135 return count; 138 return count;
136} 139}
@@ -188,7 +191,9 @@ static ssize_t set_type##flag(struct device *dev, \
188 struct lm95241_data *data = i2c_get_clientdata(client); \ 191 struct lm95241_data *data = i2c_get_clientdata(client); \
189\ 192\
190 long val; \ 193 long val; \
191 strict_strtol(buf, 10, &val); \ 194\
195 if (strict_strtol(buf, 10, &val) < 0) \
196 return -EINVAL; \
192\ 197\
193 if ((val == 1) || (val == 2)) { \ 198 if ((val == 1) || (val == 2)) { \
194\ 199\
@@ -227,7 +232,9 @@ static ssize_t set_min##flag(struct device *dev, \
227 struct lm95241_data *data = i2c_get_clientdata(client); \ 232 struct lm95241_data *data = i2c_get_clientdata(client); \
228\ 233\
229 long val; \ 234 long val; \
230 strict_strtol(buf, 10, &val); \ 235\
236 if (strict_strtol(buf, 10, &val) < 0) \
237 return -EINVAL;\
231\ 238\
232 mutex_lock(&data->update_lock); \ 239 mutex_lock(&data->update_lock); \
233\ 240\
@@ -256,7 +263,9 @@ static ssize_t set_max##flag(struct device *dev, \
256 struct lm95241_data *data = i2c_get_clientdata(client); \ 263 struct lm95241_data *data = i2c_get_clientdata(client); \
257\ 264\
258 long val; \ 265 long val; \
259 strict_strtol(buf, 10, &val); \ 266\
267 if (strict_strtol(buf, 10, &val) < 0) \
268 return -EINVAL; \
260\ 269\
261 mutex_lock(&data->update_lock); \ 270 mutex_lock(&data->update_lock); \
262\ 271\
diff --git a/drivers/hwmon/ltc4215.c b/drivers/hwmon/ltc4215.c
index 00d975eb5b83..c7e6d8e81656 100644
--- a/drivers/hwmon/ltc4215.c
+++ b/drivers/hwmon/ltc4215.c
@@ -205,7 +205,6 @@ LTC4215_ALARM(curr1_max_alarm, (1 << 2), LTC4215_STATUS);
205 205
206/* Power (virtual) */ 206/* Power (virtual) */
207LTC4215_POWER(power1_input); 207LTC4215_POWER(power1_input);
208LTC4215_ALARM(power1_alarm, (1 << 3), LTC4215_STATUS);
209 208
210/* Input Voltage */ 209/* Input Voltage */
211LTC4215_VOLTAGE(in1_input, LTC4215_ADIN); 210LTC4215_VOLTAGE(in1_input, LTC4215_ADIN);
@@ -214,6 +213,7 @@ LTC4215_ALARM(in1_min_alarm, (1 << 1), LTC4215_STATUS);
214 213
215/* Output Voltage */ 214/* Output Voltage */
216LTC4215_VOLTAGE(in2_input, LTC4215_SOURCE); 215LTC4215_VOLTAGE(in2_input, LTC4215_SOURCE);
216LTC4215_ALARM(in2_min_alarm, (1 << 3), LTC4215_STATUS);
217 217
218/* Finally, construct an array of pointers to members of the above objects, 218/* Finally, construct an array of pointers to members of the above objects,
219 * as required for sysfs_create_group() 219 * as required for sysfs_create_group()
@@ -223,13 +223,13 @@ static struct attribute *ltc4215_attributes[] = {
223 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, 223 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr,
224 224
225 &sensor_dev_attr_power1_input.dev_attr.attr, 225 &sensor_dev_attr_power1_input.dev_attr.attr,
226 &sensor_dev_attr_power1_alarm.dev_attr.attr,
227 226
228 &sensor_dev_attr_in1_input.dev_attr.attr, 227 &sensor_dev_attr_in1_input.dev_attr.attr,
229 &sensor_dev_attr_in1_max_alarm.dev_attr.attr, 228 &sensor_dev_attr_in1_max_alarm.dev_attr.attr,
230 &sensor_dev_attr_in1_min_alarm.dev_attr.attr, 229 &sensor_dev_attr_in1_min_alarm.dev_attr.attr,
231 230
232 &sensor_dev_attr_in2_input.dev_attr.attr, 231 &sensor_dev_attr_in2_input.dev_attr.attr,
232 &sensor_dev_attr_in2_min_alarm.dev_attr.attr,
233 233
234 NULL, 234 NULL,
235}; 235};
diff --git a/drivers/hwmon/ltc4261.c b/drivers/hwmon/ltc4261.c
index 267626178678..4b50601027d3 100644
--- a/drivers/hwmon/ltc4261.c
+++ b/drivers/hwmon/ltc4261.c
@@ -82,7 +82,7 @@ static struct ltc4261_data *ltc4261_update_device(struct device *dev)
82 val = i2c_smbus_read_byte_data(client, i); 82 val = i2c_smbus_read_byte_data(client, i);
83 if (unlikely(val < 0)) { 83 if (unlikely(val < 0)) {
84 dev_dbg(dev, 84 dev_dbg(dev,
85 "Failed to read ADC value: error %d", 85 "Failed to read ADC value: error %d\n",
86 val); 86 val);
87 ret = ERR_PTR(val); 87 ret = ERR_PTR(val);
88 goto abort; 88 goto abort;
@@ -230,8 +230,7 @@ static int ltc4261_probe(struct i2c_client *client,
230 return -ENODEV; 230 return -ENODEV;
231 231
232 if (i2c_smbus_read_byte_data(client, LTC4261_STATUS) < 0) { 232 if (i2c_smbus_read_byte_data(client, LTC4261_STATUS) < 0) {
233 dev_err(&client->dev, "Failed to read register %d:%02x:%02x\n", 233 dev_err(&client->dev, "Failed to read status register\n");
234 adapter->id, client->addr, LTC4261_STATUS);
235 return -ENODEV; 234 return -ENODEV;
236 } 235 }
237 236
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
index a0160ee5caef..9a11532ecae8 100644
--- a/drivers/hwmon/max6650.c
+++ b/drivers/hwmon/max6650.c
@@ -2,7 +2,7 @@
2 * max6650.c - Part of lm_sensors, Linux kernel modules for hardware 2 * max6650.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring. 3 * monitoring.
4 * 4 *
5 * (C) 2007 by Hans J. Koch <hjk@linutronix.de> 5 * (C) 2007 by Hans J. Koch <hjk@hansjkoch.de>
6 * 6 *
7 * based on code written by John Morris <john.morris@spirentcom.com> 7 * based on code written by John Morris <john.morris@spirentcom.com>
8 * Copyright (c) 2003 Spirent Communications 8 * Copyright (c) 2003 Spirent Communications
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 1d840aa83782..cdbc7448491e 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -165,10 +165,14 @@ static const u8 IN_LSB_SHIFT_IDX[][2] = {
165 165
166#define W83795_REG_VID_CTRL 0x6A 166#define W83795_REG_VID_CTRL 0x6A
167 167
168#define W83795_REG_ALARM_CTRL 0x40
169#define ALARM_CTRL_RTSACS (1 << 7)
168#define W83795_REG_ALARM(index) (0x41 + (index)) 170#define W83795_REG_ALARM(index) (0x41 + (index))
171#define W83795_REG_CLR_CHASSIS 0x4D
169#define W83795_REG_BEEP(index) (0x50 + (index)) 172#define W83795_REG_BEEP(index) (0x50 + (index))
170 173
171#define W83795_REG_CLR_CHASSIS 0x4D 174#define W83795_REG_OVT_CFG 0x58
175#define OVT_CFG_SEL (1 << 7)
172 176
173 177
174#define W83795_REG_FCMS1 0x201 178#define W83795_REG_FCMS1 0x201
@@ -178,6 +182,14 @@ static const u8 IN_LSB_SHIFT_IDX[][2] = {
178 182
179#define W83795_REG_TSS(index) (0x209 + (index)) 183#define W83795_REG_TSS(index) (0x209 + (index))
180 184
185#define TSS_MAP_RESERVED 0xff
186static const u8 tss_map[4][6] = {
187 { 0, 1, 2, 3, 4, 5},
188 { 6, 7, 8, 9, 0, 1},
189 {10, 11, 12, 13, 2, 3},
190 { 4, 5, 4, 5, TSS_MAP_RESERVED, TSS_MAP_RESERVED},
191};
192
181#define PWM_OUTPUT 0 193#define PWM_OUTPUT 0
182#define PWM_FREQ 1 194#define PWM_FREQ 1
183#define PWM_START 2 195#define PWM_START 2
@@ -369,6 +381,7 @@ struct w83795_data {
369 u8 setup_pwm[3]; /* Register value */ 381 u8 setup_pwm[3]; /* Register value */
370 382
371 u8 alarms[6]; /* Register value */ 383 u8 alarms[6]; /* Register value */
384 u8 enable_beep;
372 u8 beeps[6]; /* Register value */ 385 u8 beeps[6]; /* Register value */
373 386
374 char valid; 387 char valid;
@@ -499,8 +512,11 @@ static void w83795_update_limits(struct i2c_client *client)
499 } 512 }
500 513
501 /* Read beep settings */ 514 /* Read beep settings */
502 for (i = 0; i < ARRAY_SIZE(data->beeps); i++) 515 if (data->enable_beep) {
503 data->beeps[i] = w83795_read(client, W83795_REG_BEEP(i)); 516 for (i = 0; i < ARRAY_SIZE(data->beeps); i++)
517 data->beeps[i] =
518 w83795_read(client, W83795_REG_BEEP(i));
519 }
504 520
505 data->valid_limits = 1; 521 data->valid_limits = 1;
506} 522}
@@ -577,6 +593,7 @@ static struct w83795_data *w83795_update_device(struct device *dev)
577 struct i2c_client *client = to_i2c_client(dev); 593 struct i2c_client *client = to_i2c_client(dev);
578 struct w83795_data *data = i2c_get_clientdata(client); 594 struct w83795_data *data = i2c_get_clientdata(client);
579 u16 tmp; 595 u16 tmp;
596 u8 intrusion;
580 int i; 597 int i;
581 598
582 mutex_lock(&data->update_lock); 599 mutex_lock(&data->update_lock);
@@ -648,9 +665,24 @@ static struct w83795_data *w83795_update_device(struct device *dev)
648 w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT)); 665 w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT));
649 } 666 }
650 667
651 /* update alarm */ 668 /* Update intrusion and alarms
669 * It is important to read intrusion first, because reading from
670 * register SMI STS6 clears the interrupt status temporarily. */
671 tmp = w83795_read(client, W83795_REG_ALARM_CTRL);
672 /* Switch to interrupt status for intrusion if needed */
673 if (tmp & ALARM_CTRL_RTSACS)
674 w83795_write(client, W83795_REG_ALARM_CTRL,
675 tmp & ~ALARM_CTRL_RTSACS);
676 intrusion = w83795_read(client, W83795_REG_ALARM(5)) & (1 << 6);
677 /* Switch to real-time alarms */
678 w83795_write(client, W83795_REG_ALARM_CTRL, tmp | ALARM_CTRL_RTSACS);
652 for (i = 0; i < ARRAY_SIZE(data->alarms); i++) 679 for (i = 0; i < ARRAY_SIZE(data->alarms); i++)
653 data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i)); 680 data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i));
681 data->alarms[5] |= intrusion;
682 /* Restore original configuration if needed */
683 if (!(tmp & ALARM_CTRL_RTSACS))
684 w83795_write(client, W83795_REG_ALARM_CTRL,
685 tmp & ~ALARM_CTRL_RTSACS);
654 686
655 data->last_updated = jiffies; 687 data->last_updated = jiffies;
656 data->valid = 1; 688 data->valid = 1;
@@ -730,6 +762,10 @@ store_chassis_clear(struct device *dev,
730 val = w83795_read(client, W83795_REG_CLR_CHASSIS); 762 val = w83795_read(client, W83795_REG_CLR_CHASSIS);
731 val |= 0x80; 763 val |= 0x80;
732 w83795_write(client, W83795_REG_CLR_CHASSIS, val); 764 w83795_write(client, W83795_REG_CLR_CHASSIS, val);
765
766 /* Clear status and force cache refresh */
767 w83795_read(client, W83795_REG_ALARM(5));
768 data->valid = 0;
733 mutex_unlock(&data->update_lock); 769 mutex_unlock(&data->update_lock);
734 return count; 770 return count;
735} 771}
@@ -857,20 +893,20 @@ show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
857 int index = sensor_attr->index; 893 int index = sensor_attr->index;
858 u8 tmp; 894 u8 tmp;
859 895
860 if (1 == (data->pwm_fcms[0] & (1 << index))) { 896 /* Speed cruise mode */
897 if (data->pwm_fcms[0] & (1 << index)) {
861 tmp = 2; 898 tmp = 2;
862 goto out; 899 goto out;
863 } 900 }
901 /* Thermal cruise or SmartFan IV mode */
864 for (tmp = 0; tmp < 6; tmp++) { 902 for (tmp = 0; tmp < 6; tmp++) {
865 if (data->pwm_tfmr[tmp] & (1 << index)) { 903 if (data->pwm_tfmr[tmp] & (1 << index)) {
866 tmp = 3; 904 tmp = 3;
867 goto out; 905 goto out;
868 } 906 }
869 } 907 }
870 if (data->pwm_fomc & (1 << index)) 908 /* Manual mode */
871 tmp = 0; 909 tmp = 1;
872 else
873 tmp = 1;
874 910
875out: 911out:
876 return sprintf(buf, "%u\n", tmp); 912 return sprintf(buf, "%u\n", tmp);
@@ -890,23 +926,21 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
890 926
891 if (strict_strtoul(buf, 10, &val) < 0) 927 if (strict_strtoul(buf, 10, &val) < 0)
892 return -EINVAL; 928 return -EINVAL;
893 if (val > 2) 929 if (val < 1 || val > 2)
894 return -EINVAL; 930 return -EINVAL;
895 931
896 mutex_lock(&data->update_lock); 932 mutex_lock(&data->update_lock);
897 switch (val) { 933 switch (val) {
898 case 0:
899 case 1: 934 case 1:
935 /* Clear speed cruise mode bits */
900 data->pwm_fcms[0] &= ~(1 << index); 936 data->pwm_fcms[0] &= ~(1 << index);
901 w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]); 937 w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]);
938 /* Clear thermal cruise mode bits */
902 for (i = 0; i < 6; i++) { 939 for (i = 0; i < 6; i++) {
903 data->pwm_tfmr[i] &= ~(1 << index); 940 data->pwm_tfmr[i] &= ~(1 << index);
904 w83795_write(client, W83795_REG_TFMR(i), 941 w83795_write(client, W83795_REG_TFMR(i),
905 data->pwm_tfmr[i]); 942 data->pwm_tfmr[i]);
906 } 943 }
907 data->pwm_fomc |= 1 << index;
908 data->pwm_fomc ^= val << index;
909 w83795_write(client, W83795_REG_FOMC, data->pwm_fomc);
910 break; 944 break;
911 case 2: 945 case 2:
912 data->pwm_fcms[0] |= (1 << index); 946 data->pwm_fcms[0] |= (1 << index);
@@ -918,23 +952,60 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
918} 952}
919 953
920static ssize_t 954static ssize_t
955show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf)
956{
957 struct w83795_data *data = w83795_update_pwm_config(dev);
958 int index = to_sensor_dev_attr_2(attr)->index;
959 unsigned int mode;
960
961 if (data->pwm_fomc & (1 << index))
962 mode = 0; /* DC */
963 else
964 mode = 1; /* PWM */
965
966 return sprintf(buf, "%u\n", mode);
967}
968
969/*
970 * Check whether a given temperature source can ever be useful.
971 * Returns the number of selectable temperature channels which are
972 * enabled.
973 */
974static int w83795_tss_useful(const struct w83795_data *data, int tsrc)
975{
976 int useful = 0, i;
977
978 for (i = 0; i < 4; i++) {
979 if (tss_map[i][tsrc] == TSS_MAP_RESERVED)
980 continue;
981 if (tss_map[i][tsrc] < 6) /* Analog */
982 useful += (data->has_temp >> tss_map[i][tsrc]) & 1;
983 else /* Digital */
984 useful += (data->has_dts >> (tss_map[i][tsrc] - 6)) & 1;
985 }
986
987 return useful;
988}
989
990static ssize_t
921show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) 991show_temp_src(struct device *dev, struct device_attribute *attr, char *buf)
922{ 992{
923 struct sensor_device_attribute_2 *sensor_attr = 993 struct sensor_device_attribute_2 *sensor_attr =
924 to_sensor_dev_attr_2(attr); 994 to_sensor_dev_attr_2(attr);
925 struct w83795_data *data = w83795_update_pwm_config(dev); 995 struct w83795_data *data = w83795_update_pwm_config(dev);
926 int index = sensor_attr->index; 996 int index = sensor_attr->index;
927 u8 val = index / 2; 997 u8 tmp = data->temp_src[index / 2];
928 u8 tmp = data->temp_src[val];
929 998
930 if (index & 1) 999 if (index & 1)
931 val = 4; 1000 tmp >>= 4; /* Pick high nibble */
932 else 1001 else
933 val = 0; 1002 tmp &= 0x0f; /* Pick low nibble */
934 tmp >>= val;
935 tmp &= 0x0f;
936 1003
937 return sprintf(buf, "%u\n", tmp); 1004 /* Look-up the actual temperature channel number */
1005 if (tmp >= 4 || tss_map[tmp][index] == TSS_MAP_RESERVED)
1006 return -EINVAL; /* Shouldn't happen */
1007
1008 return sprintf(buf, "%u\n", (unsigned int)tss_map[tmp][index] + 1);
938} 1009}
939 1010
940static ssize_t 1011static ssize_t
@@ -946,12 +1017,21 @@ store_temp_src(struct device *dev, struct device_attribute *attr,
946 struct sensor_device_attribute_2 *sensor_attr = 1017 struct sensor_device_attribute_2 *sensor_attr =
947 to_sensor_dev_attr_2(attr); 1018 to_sensor_dev_attr_2(attr);
948 int index = sensor_attr->index; 1019 int index = sensor_attr->index;
949 unsigned long tmp; 1020 int tmp;
1021 unsigned long channel;
950 u8 val = index / 2; 1022 u8 val = index / 2;
951 1023
952 if (strict_strtoul(buf, 10, &tmp) < 0) 1024 if (strict_strtoul(buf, 10, &channel) < 0 ||
1025 channel < 1 || channel > 14)
1026 return -EINVAL;
1027
1028 /* Check if request can be fulfilled */
1029 for (tmp = 0; tmp < 4; tmp++) {
1030 if (tss_map[tmp][index] == channel - 1)
1031 break;
1032 }
1033 if (tmp == 4) /* No match */
953 return -EINVAL; 1034 return -EINVAL;
954 tmp = SENSORS_LIMIT(tmp, 0, 15);
955 1035
956 mutex_lock(&data->update_lock); 1036 mutex_lock(&data->update_lock);
957 if (index & 1) { 1037 if (index & 1) {
@@ -1515,7 +1595,7 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1515 1595
1516#define NOT_USED -1 1596#define NOT_USED -1
1517 1597
1518/* Don't change the attribute order, _max and _min are accessed by index 1598/* Don't change the attribute order, _max, _min and _beep are accessed by index
1519 * somewhere else in the code */ 1599 * somewhere else in the code */
1520#define SENSOR_ATTR_IN(index) { \ 1600#define SENSOR_ATTR_IN(index) { \
1521 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \ 1601 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \
@@ -1530,6 +1610,8 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1530 show_alarm_beep, store_beep, BEEP_ENABLE, \ 1610 show_alarm_beep, store_beep, BEEP_ENABLE, \
1531 index + ((index > 14) ? 1 : 0)) } 1611 index + ((index > 14) ? 1 : 0)) }
1532 1612
1613/* Don't change the attribute order, _beep is accessed by index
1614 * somewhere else in the code */
1533#define SENSOR_ATTR_FAN(index) { \ 1615#define SENSOR_ATTR_FAN(index) { \
1534 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \ 1616 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \
1535 NULL, FAN_INPUT, index - 1), \ 1617 NULL, FAN_INPUT, index - 1), \
@@ -1553,9 +1635,13 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1553 show_pwm, store_pwm, PWM_FREQ, index - 1), \ 1635 show_pwm, store_pwm, PWM_FREQ, index - 1), \
1554 SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \ 1636 SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \
1555 show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \ 1637 show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \
1638 SENSOR_ATTR_2(pwm##index##_mode, S_IRUGO, \
1639 show_pwm_mode, NULL, NOT_USED, index - 1), \
1556 SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \ 1640 SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \
1557 show_fanin, store_fanin, FANIN_TARGET, index - 1) } 1641 show_fanin, store_fanin, FANIN_TARGET, index - 1) }
1558 1642
1643/* Don't change the attribute order, _beep is accessed by index
1644 * somewhere else in the code */
1559#define SENSOR_ATTR_DTS(index) { \ 1645#define SENSOR_ATTR_DTS(index) { \
1560 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \ 1646 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \
1561 show_dts_mode, NULL, NOT_USED, index - 7), \ 1647 show_dts_mode, NULL, NOT_USED, index - 7), \
@@ -1574,6 +1660,8 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1574 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ 1660 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1575 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } 1661 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) }
1576 1662
1663/* Don't change the attribute order, _beep is accessed by index
1664 * somewhere else in the code */
1577#define SENSOR_ATTR_TEMP(index) { \ 1665#define SENSOR_ATTR_TEMP(index) { \
1578 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \ 1666 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \
1579 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ 1667 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \
@@ -1593,8 +1681,6 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
1593 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ 1681 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1594 show_alarm_beep, store_beep, BEEP_ENABLE, \ 1682 show_alarm_beep, store_beep, BEEP_ENABLE, \
1595 index + (index > 4 ? 11 : 17)), \ 1683 index + (index > 4 ? 11 : 17)), \
1596 SENSOR_ATTR_2(temp##index##_source_sel, S_IWUSR | S_IRUGO, \
1597 show_temp_src, store_temp_src, NOT_USED, index - 1), \
1598 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ 1684 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \
1599 show_temp_pwm_enable, store_temp_pwm_enable, \ 1685 show_temp_pwm_enable, store_temp_pwm_enable, \
1600 TEMP_PWM_ENABLE, index - 1), \ 1686 TEMP_PWM_ENABLE, index - 1), \
@@ -1680,7 +1766,7 @@ static const struct sensor_device_attribute_2 w83795_fan[][4] = {
1680 SENSOR_ATTR_FAN(14), 1766 SENSOR_ATTR_FAN(14),
1681}; 1767};
1682 1768
1683static const struct sensor_device_attribute_2 w83795_temp[][29] = { 1769static const struct sensor_device_attribute_2 w83795_temp[][28] = {
1684 SENSOR_ATTR_TEMP(1), 1770 SENSOR_ATTR_TEMP(1),
1685 SENSOR_ATTR_TEMP(2), 1771 SENSOR_ATTR_TEMP(2),
1686 SENSOR_ATTR_TEMP(3), 1772 SENSOR_ATTR_TEMP(3),
@@ -1700,7 +1786,7 @@ static const struct sensor_device_attribute_2 w83795_dts[][8] = {
1700 SENSOR_ATTR_DTS(14), 1786 SENSOR_ATTR_DTS(14),
1701}; 1787};
1702 1788
1703static const struct sensor_device_attribute_2 w83795_pwm[][7] = { 1789static const struct sensor_device_attribute_2 w83795_pwm[][8] = {
1704 SENSOR_ATTR_PWM(1), 1790 SENSOR_ATTR_PWM(1),
1705 SENSOR_ATTR_PWM(2), 1791 SENSOR_ATTR_PWM(2),
1706 SENSOR_ATTR_PWM(3), 1792 SENSOR_ATTR_PWM(3),
@@ -1711,13 +1797,24 @@ static const struct sensor_device_attribute_2 w83795_pwm[][7] = {
1711 SENSOR_ATTR_PWM(8), 1797 SENSOR_ATTR_PWM(8),
1712}; 1798};
1713 1799
1800static const struct sensor_device_attribute_2 w83795_tss[6] = {
1801 SENSOR_ATTR_2(temp1_source_sel, S_IWUSR | S_IRUGO,
1802 show_temp_src, store_temp_src, NOT_USED, 0),
1803 SENSOR_ATTR_2(temp2_source_sel, S_IWUSR | S_IRUGO,
1804 show_temp_src, store_temp_src, NOT_USED, 1),
1805 SENSOR_ATTR_2(temp3_source_sel, S_IWUSR | S_IRUGO,
1806 show_temp_src, store_temp_src, NOT_USED, 2),
1807 SENSOR_ATTR_2(temp4_source_sel, S_IWUSR | S_IRUGO,
1808 show_temp_src, store_temp_src, NOT_USED, 3),
1809 SENSOR_ATTR_2(temp5_source_sel, S_IWUSR | S_IRUGO,
1810 show_temp_src, store_temp_src, NOT_USED, 4),
1811 SENSOR_ATTR_2(temp6_source_sel, S_IWUSR | S_IRUGO,
1812 show_temp_src, store_temp_src, NOT_USED, 5),
1813};
1814
1714static const struct sensor_device_attribute_2 sda_single_files[] = { 1815static const struct sensor_device_attribute_2 sda_single_files[] = {
1715 SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep, 1816 SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep,
1716 store_chassis_clear, ALARM_STATUS, 46), 1817 store_chassis_clear, ALARM_STATUS, 46),
1717 SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep,
1718 store_beep, BEEP_ENABLE, 46),
1719 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep,
1720 store_beep, BEEP_ENABLE, 47),
1721#ifdef CONFIG_SENSORS_W83795_FANCTRL 1818#ifdef CONFIG_SENSORS_W83795_FANCTRL
1722 SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin, 1819 SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin,
1723 store_fanin, FANIN_TOL, NOT_USED), 1820 store_fanin, FANIN_TOL, NOT_USED),
@@ -1730,6 +1827,13 @@ static const struct sensor_device_attribute_2 sda_single_files[] = {
1730#endif 1827#endif
1731}; 1828};
1732 1829
1830static const struct sensor_device_attribute_2 sda_beep_files[] = {
1831 SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep,
1832 store_beep, BEEP_ENABLE, 46),
1833 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep,
1834 store_beep, BEEP_ENABLE, 47),
1835};
1836
1733/* 1837/*
1734 * Driver interface 1838 * Driver interface
1735 */ 1839 */
@@ -1859,6 +1963,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
1859 if (!(data->has_in & (1 << i))) 1963 if (!(data->has_in & (1 << i)))
1860 continue; 1964 continue;
1861 for (j = 0; j < ARRAY_SIZE(w83795_in[0]); j++) { 1965 for (j = 0; j < ARRAY_SIZE(w83795_in[0]); j++) {
1966 if (j == 4 && !data->enable_beep)
1967 continue;
1862 err = fn(dev, &w83795_in[i][j].dev_attr); 1968 err = fn(dev, &w83795_in[i][j].dev_attr);
1863 if (err) 1969 if (err)
1864 return err; 1970 return err;
@@ -1869,18 +1975,37 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
1869 if (!(data->has_fan & (1 << i))) 1975 if (!(data->has_fan & (1 << i)))
1870 continue; 1976 continue;
1871 for (j = 0; j < ARRAY_SIZE(w83795_fan[0]); j++) { 1977 for (j = 0; j < ARRAY_SIZE(w83795_fan[0]); j++) {
1978 if (j == 3 && !data->enable_beep)
1979 continue;
1872 err = fn(dev, &w83795_fan[i][j].dev_attr); 1980 err = fn(dev, &w83795_fan[i][j].dev_attr);
1873 if (err) 1981 if (err)
1874 return err; 1982 return err;
1875 } 1983 }
1876 } 1984 }
1877 1985
1986 for (i = 0; i < ARRAY_SIZE(w83795_tss); i++) {
1987 j = w83795_tss_useful(data, i);
1988 if (!j)
1989 continue;
1990 err = fn(dev, &w83795_tss[i].dev_attr);
1991 if (err)
1992 return err;
1993 }
1994
1878 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { 1995 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
1879 err = fn(dev, &sda_single_files[i].dev_attr); 1996 err = fn(dev, &sda_single_files[i].dev_attr);
1880 if (err) 1997 if (err)
1881 return err; 1998 return err;
1882 } 1999 }
1883 2000
2001 if (data->enable_beep) {
2002 for (i = 0; i < ARRAY_SIZE(sda_beep_files); i++) {
2003 err = fn(dev, &sda_beep_files[i].dev_attr);
2004 if (err)
2005 return err;
2006 }
2007 }
2008
1884#ifdef CONFIG_SENSORS_W83795_FANCTRL 2009#ifdef CONFIG_SENSORS_W83795_FANCTRL
1885 for (i = 0; i < data->has_pwm; i++) { 2010 for (i = 0; i < data->has_pwm; i++) {
1886 for (j = 0; j < ARRAY_SIZE(w83795_pwm[0]); j++) { 2011 for (j = 0; j < ARRAY_SIZE(w83795_pwm[0]); j++) {
@@ -1899,6 +2024,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
1899#else 2024#else
1900 for (j = 0; j < 8; j++) { 2025 for (j = 0; j < 8; j++) {
1901#endif 2026#endif
2027 if (j == 7 && !data->enable_beep)
2028 continue;
1902 err = fn(dev, &w83795_temp[i][j].dev_attr); 2029 err = fn(dev, &w83795_temp[i][j].dev_attr);
1903 if (err) 2030 if (err)
1904 return err; 2031 return err;
@@ -1910,6 +2037,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
1910 if (!(data->has_dts & (1 << i))) 2037 if (!(data->has_dts & (1 << i)))
1911 continue; 2038 continue;
1912 for (j = 0; j < ARRAY_SIZE(w83795_dts[0]); j++) { 2039 for (j = 0; j < ARRAY_SIZE(w83795_dts[0]); j++) {
2040 if (j == 7 && !data->enable_beep)
2041 continue;
1913 err = fn(dev, &w83795_dts[i][j].dev_attr); 2042 err = fn(dev, &w83795_dts[i][j].dev_attr);
1914 if (err) 2043 if (err)
1915 return err; 2044 return err;
@@ -2049,6 +2178,18 @@ static int w83795_probe(struct i2c_client *client,
2049 else 2178 else
2050 data->has_pwm = 2; 2179 data->has_pwm = 2;
2051 2180
2181 /* Check if BEEP pin is available */
2182 if (data->chip_type == w83795g) {
2183 /* The W83795G has a dedicated BEEP pin */
2184 data->enable_beep = 1;
2185 } else {
2186 /* The W83795ADG has a shared pin for OVT# and BEEP, so you
2187 * can't have both */
2188 tmp = w83795_read(client, W83795_REG_OVT_CFG);
2189 if ((tmp & OVT_CFG_SEL) == 0)
2190 data->enable_beep = 1;
2191 }
2192
2052 err = w83795_handle_files(dev, device_create_file); 2193 err = w83795_handle_files(dev, device_create_file);
2053 if (err) 2194 if (err)
2054 goto exit_remove; 2195 goto exit_remove;
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index b923074b2cbe..30f06e956bfb 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -75,8 +75,7 @@ config I2C_HELPER_AUTO
75 In doubt, say Y. 75 In doubt, say Y.
76 76
77config I2C_SMBUS 77config I2C_SMBUS
78 tristate 78 tristate "SMBus-specific protocols" if !I2C_HELPER_AUTO
79 prompt "SMBus-specific protocols" if !I2C_HELPER_AUTO
80 help 79 help
81 Say Y here if you want support for SMBus extensions to the I2C 80 Say Y here if you want support for SMBus extensions to the I2C
82 specification. At the moment, the only supported extension is 81 specification. At the moment, the only supported extension is
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index 3998dd620a03..f1cfe7e5508b 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5menu "I2C Algorithms" 5menu "I2C Algorithms"
6 depends on !I2C_HELPER_AUTO 6 visible if !I2C_HELPER_AUTO
7 7
8config I2C_ALGOBIT 8config I2C_ALGOBIT
9 tristate "I2C bit-banging interfaces" 9 tristate "I2C bit-banging interfaces"
@@ -15,15 +15,3 @@ config I2C_ALGOPCA
15 tristate "I2C PCA 9564 interfaces" 15 tristate "I2C PCA 9564 interfaces"
16 16
17endmenu 17endmenu
18
19# In automatic configuration mode, we still have to define the
20# symbols to avoid unmet dependencies.
21
22if I2C_HELPER_AUTO
23config I2C_ALGOBIT
24 tristate
25config I2C_ALGOPCF
26 tristate
27config I2C_ALGOPCA
28 tristate
29endif
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index c950be3cce21..3a6321cb8030 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -99,6 +99,7 @@ config I2C_I801
99 ICH10 99 ICH10
100 5/3400 Series (PCH) 100 5/3400 Series (PCH)
101 Cougar Point (PCH) 101 Cougar Point (PCH)
102 Patsburg (PCH)
102 103
103 This driver can also be built as a module. If so, the module 104 This driver can also be built as a module. If so, the module
104 will be called i2c-i801. 105 will be called i2c-i801.
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 59d65981eed7..02835ce7ff4b 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -3,6 +3,8 @@
3 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker 3 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
4 <mdsxyz123@yahoo.com> 4 <mdsxyz123@yahoo.com>
5 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org> 5 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
6 Copyright (C) 2010 Intel Corporation,
7 David Woodhouse <dwmw2@infradead.org>
6 8
7 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
@@ -43,6 +45,10 @@
43 ICH10 0x3a60 32 hard yes yes yes 45 ICH10 0x3a60 32 hard yes yes yes
44 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes 46 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes
45 Cougar Point (PCH) 0x1c22 32 hard yes yes yes 47 Cougar Point (PCH) 0x1c22 32 hard yes yes yes
48 Patsburg (PCH) 0x1d22 32 hard yes yes yes
49 Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes
50 Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes
51 Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes
46 52
47 Features supported by this driver: 53 Features supported by this driver:
48 Software PEC no 54 Software PEC no
@@ -50,12 +56,11 @@
50 Block buffer yes 56 Block buffer yes
51 Block process call transaction no 57 Block process call transaction no
52 I2C block read transaction yes (doesn't use the block buffer) 58 I2C block read transaction yes (doesn't use the block buffer)
59 Slave mode no
53 60
54 See the file Documentation/i2c/busses/i2c-i801 for details. 61 See the file Documentation/i2c/busses/i2c-i801 for details.
55*/ 62*/
56 63
57/* Note: we assume there can only be one I801, with one SMBus interface */
58
59#include <linux/module.h> 64#include <linux/module.h>
60#include <linux/pci.h> 65#include <linux/pci.h>
61#include <linux/kernel.h> 66#include <linux/kernel.h>
@@ -69,16 +74,16 @@
69#include <linux/dmi.h> 74#include <linux/dmi.h>
70 75
71/* I801 SMBus address offsets */ 76/* I801 SMBus address offsets */
72#define SMBHSTSTS (0 + i801_smba) 77#define SMBHSTSTS(p) (0 + (p)->smba)
73#define SMBHSTCNT (2 + i801_smba) 78#define SMBHSTCNT(p) (2 + (p)->smba)
74#define SMBHSTCMD (3 + i801_smba) 79#define SMBHSTCMD(p) (3 + (p)->smba)
75#define SMBHSTADD (4 + i801_smba) 80#define SMBHSTADD(p) (4 + (p)->smba)
76#define SMBHSTDAT0 (5 + i801_smba) 81#define SMBHSTDAT0(p) (5 + (p)->smba)
77#define SMBHSTDAT1 (6 + i801_smba) 82#define SMBHSTDAT1(p) (6 + (p)->smba)
78#define SMBBLKDAT (7 + i801_smba) 83#define SMBBLKDAT(p) (7 + (p)->smba)
79#define SMBPEC (8 + i801_smba) /* ICH3 and later */ 84#define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */
80#define SMBAUXSTS (12 + i801_smba) /* ICH4 and later */ 85#define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */
81#define SMBAUXCTL (13 + i801_smba) /* ICH4 and later */ 86#define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */
82 87
83/* PCI Address Constants */ 88/* PCI Address Constants */
84#define SMBBAR 4 89#define SMBBAR 4
@@ -127,16 +132,25 @@
127 SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \ 132 SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \
128 SMBHSTSTS_INTR) 133 SMBHSTSTS_INTR)
129 134
130static unsigned long i801_smba; 135/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
131static unsigned char i801_original_hstcfg; 136#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
137#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
138#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
139
140struct i801_priv {
141 struct i2c_adapter adapter;
142 unsigned long smba;
143 unsigned char original_hstcfg;
144 struct pci_dev *pci_dev;
145 unsigned int features;
146};
147
132static struct pci_driver i801_driver; 148static struct pci_driver i801_driver;
133static struct pci_dev *I801_dev;
134 149
135#define FEATURE_SMBUS_PEC (1 << 0) 150#define FEATURE_SMBUS_PEC (1 << 0)
136#define FEATURE_BLOCK_BUFFER (1 << 1) 151#define FEATURE_BLOCK_BUFFER (1 << 1)
137#define FEATURE_BLOCK_PROC (1 << 2) 152#define FEATURE_BLOCK_PROC (1 << 2)
138#define FEATURE_I2C_BLOCK_READ (1 << 3) 153#define FEATURE_I2C_BLOCK_READ (1 << 3)
139static unsigned int i801_features;
140 154
141static const char *i801_feature_names[] = { 155static const char *i801_feature_names[] = {
142 "SMBus PEC", 156 "SMBus PEC",
@@ -151,24 +165,24 @@ MODULE_PARM_DESC(disable_features, "Disable selected driver features");
151 165
152/* Make sure the SMBus host is ready to start transmitting. 166/* Make sure the SMBus host is ready to start transmitting.
153 Return 0 if it is, -EBUSY if it is not. */ 167 Return 0 if it is, -EBUSY if it is not. */
154static int i801_check_pre(void) 168static int i801_check_pre(struct i801_priv *priv)
155{ 169{
156 int status; 170 int status;
157 171
158 status = inb_p(SMBHSTSTS); 172 status = inb_p(SMBHSTSTS(priv));
159 if (status & SMBHSTSTS_HOST_BUSY) { 173 if (status & SMBHSTSTS_HOST_BUSY) {
160 dev_err(&I801_dev->dev, "SMBus is busy, can't use it!\n"); 174 dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n");
161 return -EBUSY; 175 return -EBUSY;
162 } 176 }
163 177
164 status &= STATUS_FLAGS; 178 status &= STATUS_FLAGS;
165 if (status) { 179 if (status) {
166 dev_dbg(&I801_dev->dev, "Clearing status flags (%02x)\n", 180 dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n",
167 status); 181 status);
168 outb_p(status, SMBHSTSTS); 182 outb_p(status, SMBHSTSTS(priv));
169 status = inb_p(SMBHSTSTS) & STATUS_FLAGS; 183 status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
170 if (status) { 184 if (status) {
171 dev_err(&I801_dev->dev, 185 dev_err(&priv->pci_dev->dev,
172 "Failed clearing status flags (%02x)\n", 186 "Failed clearing status flags (%02x)\n",
173 status); 187 status);
174 return -EBUSY; 188 return -EBUSY;
@@ -179,48 +193,50 @@ static int i801_check_pre(void)
179} 193}
180 194
181/* Convert the status register to an error code, and clear it. */ 195/* Convert the status register to an error code, and clear it. */
182static int i801_check_post(int status, int timeout) 196static int i801_check_post(struct i801_priv *priv, int status, int timeout)
183{ 197{
184 int result = 0; 198 int result = 0;
185 199
186 /* If the SMBus is still busy, we give up */ 200 /* If the SMBus is still busy, we give up */
187 if (timeout) { 201 if (timeout) {
188 dev_err(&I801_dev->dev, "Transaction timeout\n"); 202 dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
189 /* try to stop the current command */ 203 /* try to stop the current command */
190 dev_dbg(&I801_dev->dev, "Terminating the current operation\n"); 204 dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
191 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT); 205 outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
206 SMBHSTCNT(priv));
192 msleep(1); 207 msleep(1);
193 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), SMBHSTCNT); 208 outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
209 SMBHSTCNT(priv));
194 210
195 /* Check if it worked */ 211 /* Check if it worked */
196 status = inb_p(SMBHSTSTS); 212 status = inb_p(SMBHSTSTS(priv));
197 if ((status & SMBHSTSTS_HOST_BUSY) || 213 if ((status & SMBHSTSTS_HOST_BUSY) ||
198 !(status & SMBHSTSTS_FAILED)) 214 !(status & SMBHSTSTS_FAILED))
199 dev_err(&I801_dev->dev, 215 dev_err(&priv->pci_dev->dev,
200 "Failed terminating the transaction\n"); 216 "Failed terminating the transaction\n");
201 outb_p(STATUS_FLAGS, SMBHSTSTS); 217 outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
202 return -ETIMEDOUT; 218 return -ETIMEDOUT;
203 } 219 }
204 220
205 if (status & SMBHSTSTS_FAILED) { 221 if (status & SMBHSTSTS_FAILED) {
206 result = -EIO; 222 result = -EIO;
207 dev_err(&I801_dev->dev, "Transaction failed\n"); 223 dev_err(&priv->pci_dev->dev, "Transaction failed\n");
208 } 224 }
209 if (status & SMBHSTSTS_DEV_ERR) { 225 if (status & SMBHSTSTS_DEV_ERR) {
210 result = -ENXIO; 226 result = -ENXIO;
211 dev_dbg(&I801_dev->dev, "No response\n"); 227 dev_dbg(&priv->pci_dev->dev, "No response\n");
212 } 228 }
213 if (status & SMBHSTSTS_BUS_ERR) { 229 if (status & SMBHSTSTS_BUS_ERR) {
214 result = -EAGAIN; 230 result = -EAGAIN;
215 dev_dbg(&I801_dev->dev, "Lost arbitration\n"); 231 dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
216 } 232 }
217 233
218 if (result) { 234 if (result) {
219 /* Clear error flags */ 235 /* Clear error flags */
220 outb_p(status & STATUS_FLAGS, SMBHSTSTS); 236 outb_p(status & STATUS_FLAGS, SMBHSTSTS(priv));
221 status = inb_p(SMBHSTSTS) & STATUS_FLAGS; 237 status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
222 if (status) { 238 if (status) {
223 dev_warn(&I801_dev->dev, "Failed clearing status " 239 dev_warn(&priv->pci_dev->dev, "Failed clearing status "
224 "flags at end of transaction (%02x)\n", 240 "flags at end of transaction (%02x)\n",
225 status); 241 status);
226 } 242 }
@@ -229,86 +245,88 @@ static int i801_check_post(int status, int timeout)
229 return result; 245 return result;
230} 246}
231 247
232static int i801_transaction(int xact) 248static int i801_transaction(struct i801_priv *priv, int xact)
233{ 249{
234 int status; 250 int status;
235 int result; 251 int result;
236 int timeout = 0; 252 int timeout = 0;
237 253
238 result = i801_check_pre(); 254 result = i801_check_pre(priv);
239 if (result < 0) 255 if (result < 0)
240 return result; 256 return result;
241 257
242 /* the current contents of SMBHSTCNT can be overwritten, since PEC, 258 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
243 * INTREN, SMBSCMD are passed in xact */ 259 * INTREN, SMBSCMD are passed in xact */
244 outb_p(xact | I801_START, SMBHSTCNT); 260 outb_p(xact | I801_START, SMBHSTCNT(priv));
245 261
246 /* We will always wait for a fraction of a second! */ 262 /* We will always wait for a fraction of a second! */
247 do { 263 do {
248 msleep(1); 264 msleep(1);
249 status = inb_p(SMBHSTSTS); 265 status = inb_p(SMBHSTSTS(priv));
250 } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT)); 266 } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT));
251 267
252 result = i801_check_post(status, timeout > MAX_TIMEOUT); 268 result = i801_check_post(priv, status, timeout > MAX_TIMEOUT);
253 if (result < 0) 269 if (result < 0)
254 return result; 270 return result;
255 271
256 outb_p(SMBHSTSTS_INTR, SMBHSTSTS); 272 outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
257 return 0; 273 return 0;
258} 274}
259 275
260/* wait for INTR bit as advised by Intel */ 276/* wait for INTR bit as advised by Intel */
261static void i801_wait_hwpec(void) 277static void i801_wait_hwpec(struct i801_priv *priv)
262{ 278{
263 int timeout = 0; 279 int timeout = 0;
264 int status; 280 int status;
265 281
266 do { 282 do {
267 msleep(1); 283 msleep(1);
268 status = inb_p(SMBHSTSTS); 284 status = inb_p(SMBHSTSTS(priv));
269 } while ((!(status & SMBHSTSTS_INTR)) 285 } while ((!(status & SMBHSTSTS_INTR))
270 && (timeout++ < MAX_TIMEOUT)); 286 && (timeout++ < MAX_TIMEOUT));
271 287
272 if (timeout > MAX_TIMEOUT) 288 if (timeout > MAX_TIMEOUT)
273 dev_dbg(&I801_dev->dev, "PEC Timeout!\n"); 289 dev_dbg(&priv->pci_dev->dev, "PEC Timeout!\n");
274 290
275 outb_p(status, SMBHSTSTS); 291 outb_p(status, SMBHSTSTS(priv));
276} 292}
277 293
278static int i801_block_transaction_by_block(union i2c_smbus_data *data, 294static int i801_block_transaction_by_block(struct i801_priv *priv,
295 union i2c_smbus_data *data,
279 char read_write, int hwpec) 296 char read_write, int hwpec)
280{ 297{
281 int i, len; 298 int i, len;
282 int status; 299 int status;
283 300
284 inb_p(SMBHSTCNT); /* reset the data buffer index */ 301 inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
285 302
286 /* Use 32-byte buffer to process this transaction */ 303 /* Use 32-byte buffer to process this transaction */
287 if (read_write == I2C_SMBUS_WRITE) { 304 if (read_write == I2C_SMBUS_WRITE) {
288 len = data->block[0]; 305 len = data->block[0];
289 outb_p(len, SMBHSTDAT0); 306 outb_p(len, SMBHSTDAT0(priv));
290 for (i = 0; i < len; i++) 307 for (i = 0; i < len; i++)
291 outb_p(data->block[i+1], SMBBLKDAT); 308 outb_p(data->block[i+1], SMBBLKDAT(priv));
292 } 309 }
293 310
294 status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | 311 status = i801_transaction(priv, I801_BLOCK_DATA | ENABLE_INT9 |
295 I801_PEC_EN * hwpec); 312 I801_PEC_EN * hwpec);
296 if (status) 313 if (status)
297 return status; 314 return status;
298 315
299 if (read_write == I2C_SMBUS_READ) { 316 if (read_write == I2C_SMBUS_READ) {
300 len = inb_p(SMBHSTDAT0); 317 len = inb_p(SMBHSTDAT0(priv));
301 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 318 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
302 return -EPROTO; 319 return -EPROTO;
303 320
304 data->block[0] = len; 321 data->block[0] = len;
305 for (i = 0; i < len; i++) 322 for (i = 0; i < len; i++)
306 data->block[i + 1] = inb_p(SMBBLKDAT); 323 data->block[i + 1] = inb_p(SMBBLKDAT(priv));
307 } 324 }
308 return 0; 325 return 0;
309} 326}
310 327
311static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, 328static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
329 union i2c_smbus_data *data,
312 char read_write, int command, 330 char read_write, int command,
313 int hwpec) 331 int hwpec)
314{ 332{
@@ -318,15 +336,15 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
318 int result; 336 int result;
319 int timeout; 337 int timeout;
320 338
321 result = i801_check_pre(); 339 result = i801_check_pre(priv);
322 if (result < 0) 340 if (result < 0)
323 return result; 341 return result;
324 342
325 len = data->block[0]; 343 len = data->block[0];
326 344
327 if (read_write == I2C_SMBUS_WRITE) { 345 if (read_write == I2C_SMBUS_WRITE) {
328 outb_p(len, SMBHSTDAT0); 346 outb_p(len, SMBHSTDAT0(priv));
329 outb_p(data->block[1], SMBBLKDAT); 347 outb_p(data->block[1], SMBBLKDAT(priv));
330 } 348 }
331 349
332 for (i = 1; i <= len; i++) { 350 for (i = 1; i <= len; i++) {
@@ -342,34 +360,37 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
342 else 360 else
343 smbcmd = I801_BLOCK_DATA; 361 smbcmd = I801_BLOCK_DATA;
344 } 362 }
345 outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT); 363 outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT(priv));
346 364
347 if (i == 1) 365 if (i == 1)
348 outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT); 366 outb_p(inb(SMBHSTCNT(priv)) | I801_START,
367 SMBHSTCNT(priv));
349 368
350 /* We will always wait for a fraction of a second! */ 369 /* We will always wait for a fraction of a second! */
351 timeout = 0; 370 timeout = 0;
352 do { 371 do {
353 msleep(1); 372 msleep(1);
354 status = inb_p(SMBHSTSTS); 373 status = inb_p(SMBHSTSTS(priv));
355 } while ((!(status & SMBHSTSTS_BYTE_DONE)) 374 } while ((!(status & SMBHSTSTS_BYTE_DONE))
356 && (timeout++ < MAX_TIMEOUT)); 375 && (timeout++ < MAX_TIMEOUT));
357 376
358 result = i801_check_post(status, timeout > MAX_TIMEOUT); 377 result = i801_check_post(priv, status, timeout > MAX_TIMEOUT);
359 if (result < 0) 378 if (result < 0)
360 return result; 379 return result;
361 380
362 if (i == 1 && read_write == I2C_SMBUS_READ 381 if (i == 1 && read_write == I2C_SMBUS_READ
363 && command != I2C_SMBUS_I2C_BLOCK_DATA) { 382 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
364 len = inb_p(SMBHSTDAT0); 383 len = inb_p(SMBHSTDAT0(priv));
365 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) { 384 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
366 dev_err(&I801_dev->dev, 385 dev_err(&priv->pci_dev->dev,
367 "Illegal SMBus block read size %d\n", 386 "Illegal SMBus block read size %d\n",
368 len); 387 len);
369 /* Recover */ 388 /* Recover */
370 while (inb_p(SMBHSTSTS) & SMBHSTSTS_HOST_BUSY) 389 while (inb_p(SMBHSTSTS(priv)) &
371 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS); 390 SMBHSTSTS_HOST_BUSY)
372 outb_p(SMBHSTSTS_INTR, SMBHSTSTS); 391 outb_p(SMBHSTSTS_BYTE_DONE,
392 SMBHSTSTS(priv));
393 outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
373 return -EPROTO; 394 return -EPROTO;
374 } 395 }
375 data->block[0] = len; 396 data->block[0] = len;
@@ -377,27 +398,28 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
377 398
378 /* Retrieve/store value in SMBBLKDAT */ 399 /* Retrieve/store value in SMBBLKDAT */
379 if (read_write == I2C_SMBUS_READ) 400 if (read_write == I2C_SMBUS_READ)
380 data->block[i] = inb_p(SMBBLKDAT); 401 data->block[i] = inb_p(SMBBLKDAT(priv));
381 if (read_write == I2C_SMBUS_WRITE && i+1 <= len) 402 if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
382 outb_p(data->block[i+1], SMBBLKDAT); 403 outb_p(data->block[i+1], SMBBLKDAT(priv));
383 404
384 /* signals SMBBLKDAT ready */ 405 /* signals SMBBLKDAT ready */
385 outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS); 406 outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS(priv));
386 } 407 }
387 408
388 return 0; 409 return 0;
389} 410}
390 411
391static int i801_set_block_buffer_mode(void) 412static int i801_set_block_buffer_mode(struct i801_priv *priv)
392{ 413{
393 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL); 414 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
394 if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0) 415 if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
395 return -EIO; 416 return -EIO;
396 return 0; 417 return 0;
397} 418}
398 419
399/* Block transaction function */ 420/* Block transaction function */
400static int i801_block_transaction(union i2c_smbus_data *data, char read_write, 421static int i801_block_transaction(struct i801_priv *priv,
422 union i2c_smbus_data *data, char read_write,
401 int command, int hwpec) 423 int command, int hwpec)
402{ 424{
403 int result = 0; 425 int result = 0;
@@ -406,11 +428,11 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
406 if (command == I2C_SMBUS_I2C_BLOCK_DATA) { 428 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
407 if (read_write == I2C_SMBUS_WRITE) { 429 if (read_write == I2C_SMBUS_WRITE) {
408 /* set I2C_EN bit in configuration register */ 430 /* set I2C_EN bit in configuration register */
409 pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc); 431 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
410 pci_write_config_byte(I801_dev, SMBHSTCFG, 432 pci_write_config_byte(priv->pci_dev, SMBHSTCFG,
411 hostc | SMBHSTCFG_I2C_EN); 433 hostc | SMBHSTCFG_I2C_EN);
412 } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) { 434 } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
413 dev_err(&I801_dev->dev, 435 dev_err(&priv->pci_dev->dev,
414 "I2C block read is unsupported!\n"); 436 "I2C block read is unsupported!\n");
415 return -EOPNOTSUPP; 437 return -EOPNOTSUPP;
416 } 438 }
@@ -429,22 +451,23 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
429 /* Experience has shown that the block buffer can only be used for 451 /* Experience has shown that the block buffer can only be used for
430 SMBus (not I2C) block transactions, even though the datasheet 452 SMBus (not I2C) block transactions, even though the datasheet
431 doesn't mention this limitation. */ 453 doesn't mention this limitation. */
432 if ((i801_features & FEATURE_BLOCK_BUFFER) 454 if ((priv->features & FEATURE_BLOCK_BUFFER)
433 && command != I2C_SMBUS_I2C_BLOCK_DATA 455 && command != I2C_SMBUS_I2C_BLOCK_DATA
434 && i801_set_block_buffer_mode() == 0) 456 && i801_set_block_buffer_mode(priv) == 0)
435 result = i801_block_transaction_by_block(data, read_write, 457 result = i801_block_transaction_by_block(priv, data,
436 hwpec); 458 read_write, hwpec);
437 else 459 else
438 result = i801_block_transaction_byte_by_byte(data, read_write, 460 result = i801_block_transaction_byte_by_byte(priv, data,
461 read_write,
439 command, hwpec); 462 command, hwpec);
440 463
441 if (result == 0 && hwpec) 464 if (result == 0 && hwpec)
442 i801_wait_hwpec(); 465 i801_wait_hwpec(priv);
443 466
444 if (command == I2C_SMBUS_I2C_BLOCK_DATA 467 if (command == I2C_SMBUS_I2C_BLOCK_DATA
445 && read_write == I2C_SMBUS_WRITE) { 468 && read_write == I2C_SMBUS_WRITE) {
446 /* restore saved configuration register value */ 469 /* restore saved configuration register value */
447 pci_write_config_byte(I801_dev, SMBHSTCFG, hostc); 470 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
448 } 471 }
449 return result; 472 return result;
450} 473}
@@ -457,81 +480,85 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
457 int hwpec; 480 int hwpec;
458 int block = 0; 481 int block = 0;
459 int ret, xact = 0; 482 int ret, xact = 0;
483 struct i801_priv *priv = i2c_get_adapdata(adap);
460 484
461 hwpec = (i801_features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) 485 hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
462 && size != I2C_SMBUS_QUICK 486 && size != I2C_SMBUS_QUICK
463 && size != I2C_SMBUS_I2C_BLOCK_DATA; 487 && size != I2C_SMBUS_I2C_BLOCK_DATA;
464 488
465 switch (size) { 489 switch (size) {
466 case I2C_SMBUS_QUICK: 490 case I2C_SMBUS_QUICK:
467 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 491 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
468 SMBHSTADD); 492 SMBHSTADD(priv));
469 xact = I801_QUICK; 493 xact = I801_QUICK;
470 break; 494 break;
471 case I2C_SMBUS_BYTE: 495 case I2C_SMBUS_BYTE:
472 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 496 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
473 SMBHSTADD); 497 SMBHSTADD(priv));
474 if (read_write == I2C_SMBUS_WRITE) 498 if (read_write == I2C_SMBUS_WRITE)
475 outb_p(command, SMBHSTCMD); 499 outb_p(command, SMBHSTCMD(priv));
476 xact = I801_BYTE; 500 xact = I801_BYTE;
477 break; 501 break;
478 case I2C_SMBUS_BYTE_DATA: 502 case I2C_SMBUS_BYTE_DATA:
479 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 503 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
480 SMBHSTADD); 504 SMBHSTADD(priv));
481 outb_p(command, SMBHSTCMD); 505 outb_p(command, SMBHSTCMD(priv));
482 if (read_write == I2C_SMBUS_WRITE) 506 if (read_write == I2C_SMBUS_WRITE)
483 outb_p(data->byte, SMBHSTDAT0); 507 outb_p(data->byte, SMBHSTDAT0(priv));
484 xact = I801_BYTE_DATA; 508 xact = I801_BYTE_DATA;
485 break; 509 break;
486 case I2C_SMBUS_WORD_DATA: 510 case I2C_SMBUS_WORD_DATA:
487 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 511 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
488 SMBHSTADD); 512 SMBHSTADD(priv));
489 outb_p(command, SMBHSTCMD); 513 outb_p(command, SMBHSTCMD(priv));
490 if (read_write == I2C_SMBUS_WRITE) { 514 if (read_write == I2C_SMBUS_WRITE) {
491 outb_p(data->word & 0xff, SMBHSTDAT0); 515 outb_p(data->word & 0xff, SMBHSTDAT0(priv));
492 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); 516 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
493 } 517 }
494 xact = I801_WORD_DATA; 518 xact = I801_WORD_DATA;
495 break; 519 break;
496 case I2C_SMBUS_BLOCK_DATA: 520 case I2C_SMBUS_BLOCK_DATA:
497 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 521 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
498 SMBHSTADD); 522 SMBHSTADD(priv));
499 outb_p(command, SMBHSTCMD); 523 outb_p(command, SMBHSTCMD(priv));
500 block = 1; 524 block = 1;
501 break; 525 break;
502 case I2C_SMBUS_I2C_BLOCK_DATA: 526 case I2C_SMBUS_I2C_BLOCK_DATA:
503 /* NB: page 240 of ICH5 datasheet shows that the R/#W 527 /* NB: page 240 of ICH5 datasheet shows that the R/#W
504 * bit should be cleared here, even when reading */ 528 * bit should be cleared here, even when reading */
505 outb_p((addr & 0x7f) << 1, SMBHSTADD); 529 outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
506 if (read_write == I2C_SMBUS_READ) { 530 if (read_write == I2C_SMBUS_READ) {
507 /* NB: page 240 of ICH5 datasheet also shows 531 /* NB: page 240 of ICH5 datasheet also shows
508 * that DATA1 is the cmd field when reading */ 532 * that DATA1 is the cmd field when reading */
509 outb_p(command, SMBHSTDAT1); 533 outb_p(command, SMBHSTDAT1(priv));
510 } else 534 } else
511 outb_p(command, SMBHSTCMD); 535 outb_p(command, SMBHSTCMD(priv));
512 block = 1; 536 block = 1;
513 break; 537 break;
514 default: 538 default:
515 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); 539 dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
540 size);
516 return -EOPNOTSUPP; 541 return -EOPNOTSUPP;
517 } 542 }
518 543
519 if (hwpec) /* enable/disable hardware PEC */ 544 if (hwpec) /* enable/disable hardware PEC */
520 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_CRC, SMBAUXCTL); 545 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
521 else 546 else
522 outb_p(inb_p(SMBAUXCTL) & (~SMBAUXCTL_CRC), SMBAUXCTL); 547 outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
548 SMBAUXCTL(priv));
523 549
524 if (block) 550 if (block)
525 ret = i801_block_transaction(data, read_write, size, hwpec); 551 ret = i801_block_transaction(priv, data, read_write, size,
552 hwpec);
526 else 553 else
527 ret = i801_transaction(xact | ENABLE_INT9); 554 ret = i801_transaction(priv, xact | ENABLE_INT9);
528 555
529 /* Some BIOSes don't like it when PEC is enabled at reboot or resume 556 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
530 time, so we forcibly disable it after every transaction. Turn off 557 time, so we forcibly disable it after every transaction. Turn off
531 E32B for the same reason. */ 558 E32B for the same reason. */
532 if (hwpec || block) 559 if (hwpec || block)
533 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), 560 outb_p(inb_p(SMBAUXCTL(priv)) &
534 SMBAUXCTL); 561 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
535 562
536 if (block) 563 if (block)
537 return ret; 564 return ret;
@@ -543,10 +570,11 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
543 switch (xact & 0x7f) { 570 switch (xact & 0x7f) {
544 case I801_BYTE: /* Result put in SMBHSTDAT0 */ 571 case I801_BYTE: /* Result put in SMBHSTDAT0 */
545 case I801_BYTE_DATA: 572 case I801_BYTE_DATA:
546 data->byte = inb_p(SMBHSTDAT0); 573 data->byte = inb_p(SMBHSTDAT0(priv));
547 break; 574 break;
548 case I801_WORD_DATA: 575 case I801_WORD_DATA:
549 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 576 data->word = inb_p(SMBHSTDAT0(priv)) +
577 (inb_p(SMBHSTDAT1(priv)) << 8);
550 break; 578 break;
551 } 579 }
552 return 0; 580 return 0;
@@ -555,11 +583,13 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
555 583
556static u32 i801_func(struct i2c_adapter *adapter) 584static u32 i801_func(struct i2c_adapter *adapter)
557{ 585{
586 struct i801_priv *priv = i2c_get_adapdata(adapter);
587
558 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 588 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
559 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 589 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
560 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK | 590 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
561 ((i801_features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | 591 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
562 ((i801_features & FEATURE_I2C_BLOCK_READ) ? 592 ((priv->features & FEATURE_I2C_BLOCK_READ) ?
563 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0); 593 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
564} 594}
565 595
@@ -568,12 +598,6 @@ static const struct i2c_algorithm smbus_algorithm = {
568 .functionality = i801_func, 598 .functionality = i801_func,
569}; 599};
570 600
571static struct i2c_adapter i801_adapter = {
572 .owner = THIS_MODULE,
573 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
574 .algo = &smbus_algorithm,
575};
576
577static const struct pci_device_id i801_ids[] = { 601static const struct pci_device_id i801_ids[] = {
578 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) }, 602 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
579 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) }, 603 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
@@ -592,6 +616,10 @@ static const struct pci_device_id i801_ids[] = {
592 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) }, 616 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
593 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) }, 617 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) },
594 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) }, 618 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) },
619 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) },
620 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
621 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
622 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
595 { 0, } 623 { 0, }
596}; 624};
597 625
@@ -704,16 +732,25 @@ static int __devinit i801_probe(struct pci_dev *dev,
704{ 732{
705 unsigned char temp; 733 unsigned char temp;
706 int err, i; 734 int err, i;
735 struct i801_priv *priv;
736
737 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
738 if (!priv)
739 return -ENOMEM;
740
741 i2c_set_adapdata(&priv->adapter, priv);
742 priv->adapter.owner = THIS_MODULE;
743 priv->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
744 priv->adapter.algo = &smbus_algorithm;
707 745
708 I801_dev = dev; 746 priv->pci_dev = dev;
709 i801_features = 0;
710 switch (dev->device) { 747 switch (dev->device) {
711 default: 748 default:
712 i801_features |= FEATURE_I2C_BLOCK_READ; 749 priv->features |= FEATURE_I2C_BLOCK_READ;
713 /* fall through */ 750 /* fall through */
714 case PCI_DEVICE_ID_INTEL_82801DB_3: 751 case PCI_DEVICE_ID_INTEL_82801DB_3:
715 i801_features |= FEATURE_SMBUS_PEC; 752 priv->features |= FEATURE_SMBUS_PEC;
716 i801_features |= FEATURE_BLOCK_BUFFER; 753 priv->features |= FEATURE_BLOCK_BUFFER;
717 /* fall through */ 754 /* fall through */
718 case PCI_DEVICE_ID_INTEL_82801CA_3: 755 case PCI_DEVICE_ID_INTEL_82801CA_3:
719 case PCI_DEVICE_ID_INTEL_82801BA_2: 756 case PCI_DEVICE_ID_INTEL_82801BA_2:
@@ -724,11 +761,11 @@ static int __devinit i801_probe(struct pci_dev *dev,
724 761
725 /* Disable features on user request */ 762 /* Disable features on user request */
726 for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) { 763 for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
727 if (i801_features & disable_features & (1 << i)) 764 if (priv->features & disable_features & (1 << i))
728 dev_notice(&dev->dev, "%s disabled by user\n", 765 dev_notice(&dev->dev, "%s disabled by user\n",
729 i801_feature_names[i]); 766 i801_feature_names[i]);
730 } 767 }
731 i801_features &= ~disable_features; 768 priv->features &= ~disable_features;
732 769
733 err = pci_enable_device(dev); 770 err = pci_enable_device(dev);
734 if (err) { 771 if (err) {
@@ -738,8 +775,8 @@ static int __devinit i801_probe(struct pci_dev *dev,
738 } 775 }
739 776
740 /* Determine the address of the SMBus area */ 777 /* Determine the address of the SMBus area */
741 i801_smba = pci_resource_start(dev, SMBBAR); 778 priv->smba = pci_resource_start(dev, SMBBAR);
742 if (!i801_smba) { 779 if (!priv->smba) {
743 dev_err(&dev->dev, "SMBus base address uninitialized, " 780 dev_err(&dev->dev, "SMBus base address uninitialized, "
744 "upgrade BIOS\n"); 781 "upgrade BIOS\n");
745 err = -ENODEV; 782 err = -ENODEV;
@@ -755,19 +792,19 @@ static int __devinit i801_probe(struct pci_dev *dev,
755 err = pci_request_region(dev, SMBBAR, i801_driver.name); 792 err = pci_request_region(dev, SMBBAR, i801_driver.name);
756 if (err) { 793 if (err) {
757 dev_err(&dev->dev, "Failed to request SMBus region " 794 dev_err(&dev->dev, "Failed to request SMBus region "
758 "0x%lx-0x%Lx\n", i801_smba, 795 "0x%lx-0x%Lx\n", priv->smba,
759 (unsigned long long)pci_resource_end(dev, SMBBAR)); 796 (unsigned long long)pci_resource_end(dev, SMBBAR));
760 goto exit; 797 goto exit;
761 } 798 }
762 799
763 pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); 800 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp);
764 i801_original_hstcfg = temp; 801 priv->original_hstcfg = temp;
765 temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */ 802 temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
766 if (!(temp & SMBHSTCFG_HST_EN)) { 803 if (!(temp & SMBHSTCFG_HST_EN)) {
767 dev_info(&dev->dev, "Enabling SMBus device\n"); 804 dev_info(&dev->dev, "Enabling SMBus device\n");
768 temp |= SMBHSTCFG_HST_EN; 805 temp |= SMBHSTCFG_HST_EN;
769 } 806 }
770 pci_write_config_byte(I801_dev, SMBHSTCFG, temp); 807 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp);
771 808
772 if (temp & SMBHSTCFG_SMB_SMI_EN) 809 if (temp & SMBHSTCFG_SMB_SMI_EN)
773 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n"); 810 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
@@ -775,19 +812,19 @@ static int __devinit i801_probe(struct pci_dev *dev,
775 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); 812 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n");
776 813
777 /* Clear special mode bits */ 814 /* Clear special mode bits */
778 if (i801_features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER)) 815 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
779 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), 816 outb_p(inb_p(SMBAUXCTL(priv)) &
780 SMBAUXCTL); 817 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
781 818
782 /* set up the sysfs linkage to our parent device */ 819 /* set up the sysfs linkage to our parent device */
783 i801_adapter.dev.parent = &dev->dev; 820 priv->adapter.dev.parent = &dev->dev;
784 821
785 /* Retry up to 3 times on lost arbitration */ 822 /* Retry up to 3 times on lost arbitration */
786 i801_adapter.retries = 3; 823 priv->adapter.retries = 3;
787 824
788 snprintf(i801_adapter.name, sizeof(i801_adapter.name), 825 snprintf(priv->adapter.name, sizeof(priv->adapter.name),
789 "SMBus I801 adapter at %04lx", i801_smba); 826 "SMBus I801 adapter at %04lx", priv->smba);
790 err = i2c_add_adapter(&i801_adapter); 827 err = i2c_add_adapter(&priv->adapter);
791 if (err) { 828 if (err) {
792 dev_err(&dev->dev, "Failed to add SMBus adapter\n"); 829 dev_err(&dev->dev, "Failed to add SMBus adapter\n");
793 goto exit_release; 830 goto exit_release;
@@ -801,27 +838,33 @@ static int __devinit i801_probe(struct pci_dev *dev,
801 memset(&info, 0, sizeof(struct i2c_board_info)); 838 memset(&info, 0, sizeof(struct i2c_board_info));
802 info.addr = apanel_addr; 839 info.addr = apanel_addr;
803 strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE); 840 strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
804 i2c_new_device(&i801_adapter, &info); 841 i2c_new_device(&priv->adapter, &info);
805 } 842 }
806#endif 843#endif
807#if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE 844#if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE
808 if (dmi_name_in_vendors("FUJITSU")) 845 if (dmi_name_in_vendors("FUJITSU"))
809 dmi_walk(dmi_check_onboard_devices, &i801_adapter); 846 dmi_walk(dmi_check_onboard_devices, &priv->adapter);
810#endif 847#endif
811 848
849 pci_set_drvdata(dev, priv);
812 return 0; 850 return 0;
813 851
814exit_release: 852exit_release:
815 pci_release_region(dev, SMBBAR); 853 pci_release_region(dev, SMBBAR);
816exit: 854exit:
855 kfree(priv);
817 return err; 856 return err;
818} 857}
819 858
820static void __devexit i801_remove(struct pci_dev *dev) 859static void __devexit i801_remove(struct pci_dev *dev)
821{ 860{
822 i2c_del_adapter(&i801_adapter); 861 struct i801_priv *priv = pci_get_drvdata(dev);
823 pci_write_config_byte(I801_dev, SMBHSTCFG, i801_original_hstcfg); 862
863 i2c_del_adapter(&priv->adapter);
864 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
824 pci_release_region(dev, SMBBAR); 865 pci_release_region(dev, SMBBAR);
866 pci_set_drvdata(dev, NULL);
867 kfree(priv);
825 /* 868 /*
826 * do not call pci_disable_device(dev) since it can cause hard hangs on 869 * do not call pci_disable_device(dev) since it can cause hard hangs on
827 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010) 870 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
@@ -831,8 +874,10 @@ static void __devexit i801_remove(struct pci_dev *dev)
831#ifdef CONFIG_PM 874#ifdef CONFIG_PM
832static int i801_suspend(struct pci_dev *dev, pm_message_t mesg) 875static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
833{ 876{
877 struct i801_priv *priv = pci_get_drvdata(dev);
878
834 pci_save_state(dev); 879 pci_save_state(dev);
835 pci_write_config_byte(dev, SMBHSTCFG, i801_original_hstcfg); 880 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
836 pci_set_power_state(dev, pci_choose_state(dev, mesg)); 881 pci_set_power_state(dev, pci_choose_state(dev, mesg));
837 return 0; 882 return 0;
838} 883}
diff --git a/drivers/i2c/busses/i2c-intel-mid.c b/drivers/i2c/busses/i2c-intel-mid.c
index 80f70d3a744d..c71492782bbd 100644
--- a/drivers/i2c/busses/i2c-intel-mid.c
+++ b/drivers/i2c/busses/i2c-intel-mid.c
@@ -999,7 +999,7 @@ static int __devinit intel_mid_i2c_probe(struct pci_dev *dev,
999 999
1000 /* Initialize struct members */ 1000 /* Initialize struct members */
1001 snprintf(mrst->adap.name, sizeof(mrst->adap.name), 1001 snprintf(mrst->adap.name, sizeof(mrst->adap.name),
1002 "MRST/Medfield I2C at %lx", start); 1002 "Intel MID I2C at %lx", start);
1003 mrst->adap.owner = THIS_MODULE; 1003 mrst->adap.owner = THIS_MODULE;
1004 mrst->adap.algo = &intel_mid_i2c_algorithm; 1004 mrst->adap.algo = &intel_mid_i2c_algorithm;
1005 mrst->adap.dev.parent = &dev->dev; 1005 mrst->adap.dev.parent = &dev->dev;
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index d231f683f576..6b4cc567645b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -848,6 +848,18 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
848 goto out_list; 848 goto out_list;
849 } 849 }
850 850
851 /* Sanity checks */
852 if (unlikely(adap->name[0] == '\0')) {
853 pr_err("i2c-core: Attempt to register an adapter with "
854 "no name!\n");
855 return -EINVAL;
856 }
857 if (unlikely(!adap->algo)) {
858 pr_err("i2c-core: Attempt to register adapter '%s' with "
859 "no algo!\n", adap->name);
860 return -EINVAL;
861 }
862
851 rt_mutex_init(&adap->bus_lock); 863 rt_mutex_init(&adap->bus_lock);
852 mutex_init(&adap->userspace_clients_lock); 864 mutex_init(&adap->userspace_clients_lock);
853 INIT_LIST_HEAD(&adap->userspace_clients); 865 INIT_LIST_HEAD(&adap->userspace_clients);
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index d32a4843fc3a..d7a4833be416 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -120,7 +120,6 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
120 snprintf(priv->adap.name, sizeof(priv->adap.name), 120 snprintf(priv->adap.name, sizeof(priv->adap.name),
121 "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id); 121 "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id);
122 priv->adap.owner = THIS_MODULE; 122 priv->adap.owner = THIS_MODULE;
123 priv->adap.id = parent->id;
124 priv->adap.algo = &priv->algo; 123 priv->adap.algo = &priv->algo;
125 priv->adap.algo_data = priv; 124 priv->adap.algo_data = priv;
126 priv->adap.dev.parent = &parent->dev; 125 priv->adap.dev.parent = &parent->dev;
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 41665d2f9f93..c131d58bcb50 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -273,8 +273,6 @@ static int intel_idle_probe(void)
273 273
274 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates); 274 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
275 275
276 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
277 lapic_timer_reliable_states = 0xFFFFFFFF;
278 276
279 if (boot_cpu_data.x86 != 6) /* family 6 */ 277 if (boot_cpu_data.x86 != 6) /* family 6 */
280 return -ENODEV; 278 return -ENODEV;
@@ -286,8 +284,6 @@ static int intel_idle_probe(void)
286 case 0x1F: /* Core i7 and i5 Processor - Nehalem */ 284 case 0x1F: /* Core i7 and i5 Processor - Nehalem */
287 case 0x2E: /* Nehalem-EX Xeon */ 285 case 0x2E: /* Nehalem-EX Xeon */
288 case 0x2F: /* Westmere-EX Xeon */ 286 case 0x2F: /* Westmere-EX Xeon */
289 lapic_timer_reliable_states = (1 << 1); /* C1 */
290
291 case 0x25: /* Westmere */ 287 case 0x25: /* Westmere */
292 case 0x2C: /* Westmere */ 288 case 0x2C: /* Westmere */
293 cpuidle_state_table = nehalem_cstates; 289 cpuidle_state_table = nehalem_cstates;
@@ -295,7 +291,6 @@ static int intel_idle_probe(void)
295 291
296 case 0x1C: /* 28 - Atom Processor */ 292 case 0x1C: /* 28 - Atom Processor */
297 case 0x26: /* 38 - Lincroft Atom Processor */ 293 case 0x26: /* 38 - Lincroft Atom Processor */
298 lapic_timer_reliable_states = (1 << 1); /* C1 */
299 cpuidle_state_table = atom_cstates; 294 cpuidle_state_table = atom_cstates;
300 break; 295 break;
301 296
@@ -303,10 +298,6 @@ static int intel_idle_probe(void)
303 case 0x2D: /* SNB Xeon */ 298 case 0x2D: /* SNB Xeon */
304 cpuidle_state_table = snb_cstates; 299 cpuidle_state_table = snb_cstates;
305 break; 300 break;
306#ifdef FUTURE_USE
307 case 0x17: /* 23 - Core 2 Duo */
308 lapic_timer_reliable_states = (1 << 2) | (1 << 1); /* C2, C1 */
309#endif
310 301
311 default: 302 default:
312 pr_debug(PREFIX "does not run on family %d model %d\n", 303 pr_debug(PREFIX "does not run on family %d model %d\n",
@@ -314,6 +305,9 @@ static int intel_idle_probe(void)
314 return -ENODEV; 305 return -ENODEV;
315 } 306 }
316 307
308 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
309 lapic_timer_reliable_states = 0xFFFFFFFF;
310
317 pr_debug(PREFIX "v" INTEL_IDLE_VERSION 311 pr_debug(PREFIX "v" INTEL_IDLE_VERSION
318 " model 0x%X\n", boot_cpu_data.x86_model); 312 " model 0x%X\n", boot_cpu_data.x86_model);
319 313
diff --git a/drivers/infiniband/core/ud_header.c b/drivers/infiniband/core/ud_header.c
index bb7e19280821..9b737ff133e2 100644
--- a/drivers/infiniband/core/ud_header.c
+++ b/drivers/infiniband/core/ud_header.c
@@ -278,36 +278,6 @@ void ib_ud_header_init(int payload_bytes,
278EXPORT_SYMBOL(ib_ud_header_init); 278EXPORT_SYMBOL(ib_ud_header_init);
279 279
280/** 280/**
281 * ib_lrh_header_pack - Pack LRH header struct into wire format
282 * @lrh:unpacked LRH header struct
283 * @buf:Buffer to pack into
284 *
285 * ib_lrh_header_pack() packs the LRH header structure @lrh into
286 * wire format in the buffer @buf.
287 */
288int ib_lrh_header_pack(struct ib_unpacked_lrh *lrh, void *buf)
289{
290 ib_pack(lrh_table, ARRAY_SIZE(lrh_table), lrh, buf);
291 return 0;
292}
293EXPORT_SYMBOL(ib_lrh_header_pack);
294
295/**
296 * ib_lrh_header_unpack - Unpack LRH structure from wire format
297 * @lrh:unpacked LRH header struct
298 * @buf:Buffer to pack into
299 *
300 * ib_lrh_header_unpack() unpacks the LRH header structure from
301 * wire format (in buf) into @lrh.
302 */
303int ib_lrh_header_unpack(void *buf, struct ib_unpacked_lrh *lrh)
304{
305 ib_unpack(lrh_table, ARRAY_SIZE(lrh_table), buf, lrh);
306 return 0;
307}
308EXPORT_SYMBOL(ib_lrh_header_unpack);
309
310/**
311 * ib_ud_header_pack - Pack UD header struct into wire format 281 * ib_ud_header_pack - Pack UD header struct into wire format
312 * @header:UD header struct 282 * @header:UD header struct
313 * @buf:Buffer to pack into 283 * @buf:Buffer to pack into
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index b342248aec05..c42699285f8e 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -893,68 +893,81 @@ out:
893 return ret ? ret : in_len; 893 return ret ? ret : in_len;
894} 894}
895 895
896static int copy_wc_to_user(void __user *dest, struct ib_wc *wc)
897{
898 struct ib_uverbs_wc tmp;
899
900 tmp.wr_id = wc->wr_id;
901 tmp.status = wc->status;
902 tmp.opcode = wc->opcode;
903 tmp.vendor_err = wc->vendor_err;
904 tmp.byte_len = wc->byte_len;
905 tmp.ex.imm_data = (__u32 __force) wc->ex.imm_data;
906 tmp.qp_num = wc->qp->qp_num;
907 tmp.src_qp = wc->src_qp;
908 tmp.wc_flags = wc->wc_flags;
909 tmp.pkey_index = wc->pkey_index;
910 tmp.slid = wc->slid;
911 tmp.sl = wc->sl;
912 tmp.dlid_path_bits = wc->dlid_path_bits;
913 tmp.port_num = wc->port_num;
914 tmp.reserved = 0;
915
916 if (copy_to_user(dest, &tmp, sizeof tmp))
917 return -EFAULT;
918
919 return 0;
920}
921
896ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, 922ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
897 const char __user *buf, int in_len, 923 const char __user *buf, int in_len,
898 int out_len) 924 int out_len)
899{ 925{
900 struct ib_uverbs_poll_cq cmd; 926 struct ib_uverbs_poll_cq cmd;
901 struct ib_uverbs_poll_cq_resp *resp; 927 struct ib_uverbs_poll_cq_resp resp;
928 u8 __user *header_ptr;
929 u8 __user *data_ptr;
902 struct ib_cq *cq; 930 struct ib_cq *cq;
903 struct ib_wc *wc; 931 struct ib_wc wc;
904 int ret = 0; 932 int ret;
905 int i;
906 int rsize;
907 933
908 if (copy_from_user(&cmd, buf, sizeof cmd)) 934 if (copy_from_user(&cmd, buf, sizeof cmd))
909 return -EFAULT; 935 return -EFAULT;
910 936
911 wc = kmalloc(cmd.ne * sizeof *wc, GFP_KERNEL);
912 if (!wc)
913 return -ENOMEM;
914
915 rsize = sizeof *resp + cmd.ne * sizeof(struct ib_uverbs_wc);
916 resp = kmalloc(rsize, GFP_KERNEL);
917 if (!resp) {
918 ret = -ENOMEM;
919 goto out_wc;
920 }
921
922 cq = idr_read_cq(cmd.cq_handle, file->ucontext, 0); 937 cq = idr_read_cq(cmd.cq_handle, file->ucontext, 0);
923 if (!cq) { 938 if (!cq)
924 ret = -EINVAL; 939 return -EINVAL;
925 goto out;
926 }
927 940
928 resp->count = ib_poll_cq(cq, cmd.ne, wc); 941 /* we copy a struct ib_uverbs_poll_cq_resp to user space */
942 header_ptr = (void __user *)(unsigned long) cmd.response;
943 data_ptr = header_ptr + sizeof resp;
929 944
930 put_cq_read(cq); 945 memset(&resp, 0, sizeof resp);
946 while (resp.count < cmd.ne) {
947 ret = ib_poll_cq(cq, 1, &wc);
948 if (ret < 0)
949 goto out_put;
950 if (!ret)
951 break;
952
953 ret = copy_wc_to_user(data_ptr, &wc);
954 if (ret)
955 goto out_put;
931 956
932 for (i = 0; i < resp->count; i++) { 957 data_ptr += sizeof(struct ib_uverbs_wc);
933 resp->wc[i].wr_id = wc[i].wr_id; 958 ++resp.count;
934 resp->wc[i].status = wc[i].status;
935 resp->wc[i].opcode = wc[i].opcode;
936 resp->wc[i].vendor_err = wc[i].vendor_err;
937 resp->wc[i].byte_len = wc[i].byte_len;
938 resp->wc[i].ex.imm_data = (__u32 __force) wc[i].ex.imm_data;
939 resp->wc[i].qp_num = wc[i].qp->qp_num;
940 resp->wc[i].src_qp = wc[i].src_qp;
941 resp->wc[i].wc_flags = wc[i].wc_flags;
942 resp->wc[i].pkey_index = wc[i].pkey_index;
943 resp->wc[i].slid = wc[i].slid;
944 resp->wc[i].sl = wc[i].sl;
945 resp->wc[i].dlid_path_bits = wc[i].dlid_path_bits;
946 resp->wc[i].port_num = wc[i].port_num;
947 } 959 }
948 960
949 if (copy_to_user((void __user *) (unsigned long) cmd.response, resp, rsize)) 961 if (copy_to_user(header_ptr, &resp, sizeof resp)) {
950 ret = -EFAULT; 962 ret = -EFAULT;
963 goto out_put;
964 }
951 965
952out: 966 ret = in_len;
953 kfree(resp);
954 967
955out_wc: 968out_put:
956 kfree(wc); 969 put_cq_read(cq);
957 return ret ? ret : in_len; 970 return ret;
958} 971}
959 972
960ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file, 973ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file,
diff --git a/drivers/infiniband/core/uverbs_marshall.c b/drivers/infiniband/core/uverbs_marshall.c
index 5440da0e59b4..1b1146f87124 100644
--- a/drivers/infiniband/core/uverbs_marshall.c
+++ b/drivers/infiniband/core/uverbs_marshall.c
@@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
40 dst->grh.sgid_index = src->grh.sgid_index; 40 dst->grh.sgid_index = src->grh.sgid_index;
41 dst->grh.hop_limit = src->grh.hop_limit; 41 dst->grh.hop_limit = src->grh.hop_limit;
42 dst->grh.traffic_class = src->grh.traffic_class; 42 dst->grh.traffic_class = src->grh.traffic_class;
43 memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
43 dst->dlid = src->dlid; 44 dst->dlid = src->dlid;
44 dst->sl = src->sl; 45 dst->sl = src->sl;
45 dst->src_path_bits = src->src_path_bits; 46 dst->src_path_bits = src->src_path_bits;
46 dst->static_rate = src->static_rate; 47 dst->static_rate = src->static_rate;
47 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0; 48 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
48 dst->port_num = src->port_num; 49 dst->port_num = src->port_num;
50 dst->reserved = 0;
49} 51}
50EXPORT_SYMBOL(ib_copy_ah_attr_to_user); 52EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
51 53
52void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst, 54void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
53 struct ib_qp_attr *src) 55 struct ib_qp_attr *src)
54{ 56{
57 dst->qp_state = src->qp_state;
55 dst->cur_qp_state = src->cur_qp_state; 58 dst->cur_qp_state = src->cur_qp_state;
56 dst->path_mtu = src->path_mtu; 59 dst->path_mtu = src->path_mtu;
57 dst->path_mig_state = src->path_mig_state; 60 dst->path_mig_state = src->path_mig_state;
@@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
83 dst->rnr_retry = src->rnr_retry; 86 dst->rnr_retry = src->rnr_retry;
84 dst->alt_port_num = src->alt_port_num; 87 dst->alt_port_num = src->alt_port_num;
85 dst->alt_timeout = src->alt_timeout; 88 dst->alt_timeout = src->alt_timeout;
89 memset(dst->reserved, 0, sizeof(dst->reserved));
86} 90}
87EXPORT_SYMBOL(ib_copy_qp_attr_to_user); 91EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
88 92
diff --git a/drivers/infiniband/hw/ipath/ipath_file_ops.c b/drivers/infiniband/hw/ipath/ipath_file_ops.c
index 6078992da3f0..9292a15ad7c4 100644
--- a/drivers/infiniband/hw/ipath/ipath_file_ops.c
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -40,7 +40,6 @@
40#include <linux/highmem.h> 40#include <linux/highmem.h>
41#include <linux/io.h> 41#include <linux/io.h>
42#include <linux/jiffies.h> 42#include <linux/jiffies.h>
43#include <linux/smp_lock.h>
44#include <asm/pgtable.h> 43#include <asm/pgtable.h>
45 44
46#include "ipath_kernel.h" 45#include "ipath_kernel.h"
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index bf3e20cd0298..30e09caf0da9 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -219,7 +219,7 @@ static int eth_link_query_port(struct ib_device *ibdev, u8 port,
219 struct net_device *ndev; 219 struct net_device *ndev;
220 enum ib_mtu tmp; 220 enum ib_mtu tmp;
221 221
222 props->active_width = IB_WIDTH_4X; 222 props->active_width = IB_WIDTH_1X;
223 props->active_speed = 4; 223 props->active_speed = 4;
224 props->port_cap_flags = IB_PORT_CM_SUP; 224 props->port_cap_flags = IB_PORT_CM_SUP;
225 props->gid_tbl_len = to_mdev(ibdev)->dev->caps.gid_table_len[port]; 225 props->gid_tbl_len = to_mdev(ibdev)->dev->caps.gid_table_len[port];
@@ -242,7 +242,7 @@ static int eth_link_query_port(struct ib_device *ibdev, u8 port,
242 tmp = iboe_get_mtu(ndev->mtu); 242 tmp = iboe_get_mtu(ndev->mtu);
243 props->active_mtu = tmp ? min(props->max_mtu, tmp) : IB_MTU_256; 243 props->active_mtu = tmp ? min(props->max_mtu, tmp) : IB_MTU_256;
244 244
245 props->state = netif_running(ndev) && netif_oper_up(ndev) ? 245 props->state = (netif_running(ndev) && netif_carrier_ok(ndev)) ?
246 IB_PORT_ACTIVE : IB_PORT_DOWN; 246 IB_PORT_ACTIVE : IB_PORT_DOWN;
247 props->phys_state = state_to_phys_state(props->state); 247 props->phys_state = state_to_phys_state(props->state);
248 248
diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
index 9a7794ac34c1..2001f20a4361 100644
--- a/drivers/infiniband/hw/mlx4/qp.c
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -1816,6 +1816,11 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1816 ctrl->fence_size = (wr->send_flags & IB_SEND_FENCE ? 1816 ctrl->fence_size = (wr->send_flags & IB_SEND_FENCE ?
1817 MLX4_WQE_CTRL_FENCE : 0) | size; 1817 MLX4_WQE_CTRL_FENCE : 0) | size;
1818 1818
1819 if (be16_to_cpu(vlan) < 0x1000) {
1820 ctrl->ins_vlan = 1 << 6;
1821 ctrl->vlan_tag = vlan;
1822 }
1823
1819 /* 1824 /*
1820 * Make sure descriptor is fully written before 1825 * Make sure descriptor is fully written before
1821 * setting ownership bit (because HW can start 1826 * setting ownership bit (because HW can start
@@ -1831,11 +1836,6 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1831 ctrl->owner_opcode = mlx4_ib_opcode[wr->opcode] | 1836 ctrl->owner_opcode = mlx4_ib_opcode[wr->opcode] |
1832 (ind & qp->sq.wqe_cnt ? cpu_to_be32(1 << 31) : 0) | blh; 1837 (ind & qp->sq.wqe_cnt ? cpu_to_be32(1 << 31) : 0) | blh;
1833 1838
1834 if (be16_to_cpu(vlan) < 0x1000) {
1835 ctrl->ins_vlan = 1 << 6;
1836 ctrl->vlan_tag = vlan;
1837 }
1838
1839 stamp = ind + qp->sq_spare_wqes; 1839 stamp = ind + qp->sq_spare_wqes;
1840 ind += DIV_ROUND_UP(size * 16, 1U << qp->sq.wqe_shift); 1840 ind += DIV_ROUND_UP(size * 16, 1U << qp->sq.wqe_shift);
1841 1841
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index cfc1d65c4577..1e1e347a7715 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -1123,7 +1123,7 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
1123 } 1123 }
1124} 1124}
1125 1125
1126static int srp_queuecommand(struct scsi_cmnd *scmnd, 1126static int srp_queuecommand_lck(struct scsi_cmnd *scmnd,
1127 void (*done)(struct scsi_cmnd *)) 1127 void (*done)(struct scsi_cmnd *))
1128{ 1128{
1129 struct srp_target_port *target = host_to_target(scmnd->device->host); 1129 struct srp_target_port *target = host_to_target(scmnd->device->host);
@@ -1196,6 +1196,8 @@ err:
1196 return SCSI_MLQUEUE_HOST_BUSY; 1196 return SCSI_MLQUEUE_HOST_BUSY;
1197} 1197}
1198 1198
1199static DEF_SCSI_QCMD(srp_queuecommand)
1200
1199static int srp_alloc_iu_bufs(struct srp_target_port *target) 1201static int srp_alloc_iu_bufs(struct srp_target_port *target)
1200{ 1202{
1201 int i; 1203 int i;
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index e3f7fc6f9565..68f09a868434 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -534,76 +534,73 @@ static int handle_eviocgbit(struct input_dev *dev,
534} 534}
535#undef OLD_KEY_MAX 535#undef OLD_KEY_MAX
536 536
537static int evdev_handle_get_keycode(struct input_dev *dev, 537static int evdev_handle_get_keycode(struct input_dev *dev, void __user *p)
538 void __user *p, size_t size)
539{ 538{
540 struct input_keymap_entry ke; 539 struct input_keymap_entry ke = {
540 .len = sizeof(unsigned int),
541 .flags = 0,
542 };
543 int __user *ip = (int __user *)p;
541 int error; 544 int error;
542 545
543 memset(&ke, 0, sizeof(ke)); 546 /* legacy case */
544 547 if (copy_from_user(ke.scancode, p, sizeof(unsigned int)))
545 if (size == sizeof(unsigned int[2])) { 548 return -EFAULT;
546 /* legacy case */
547 int __user *ip = (int __user *)p;
548 549
549 if (copy_from_user(ke.scancode, p, sizeof(unsigned int))) 550 error = input_get_keycode(dev, &ke);
550 return -EFAULT; 551 if (error)
552 return error;
551 553
552 ke.len = sizeof(unsigned int); 554 if (put_user(ke.keycode, ip + 1))
553 ke.flags = 0; 555 return -EFAULT;
554 556
555 error = input_get_keycode(dev, &ke); 557 return 0;
556 if (error) 558}
557 return error;
558 559
559 if (put_user(ke.keycode, ip + 1)) 560static int evdev_handle_get_keycode_v2(struct input_dev *dev, void __user *p)
560 return -EFAULT; 561{
562 struct input_keymap_entry ke;
563 int error;
561 564
562 } else { 565 if (copy_from_user(&ke, p, sizeof(ke)))
563 size = min(size, sizeof(ke)); 566 return -EFAULT;
564 567
565 if (copy_from_user(&ke, p, size)) 568 error = input_get_keycode(dev, &ke);
566 return -EFAULT; 569 if (error)
570 return error;
567 571
568 error = input_get_keycode(dev, &ke); 572 if (copy_to_user(p, &ke, sizeof(ke)))
569 if (error) 573 return -EFAULT;
570 return error;
571 574
572 if (copy_to_user(p, &ke, size))
573 return -EFAULT;
574 }
575 return 0; 575 return 0;
576} 576}
577 577
578static int evdev_handle_set_keycode(struct input_dev *dev, 578static int evdev_handle_set_keycode(struct input_dev *dev, void __user *p)
579 void __user *p, size_t size)
580{ 579{
581 struct input_keymap_entry ke; 580 struct input_keymap_entry ke = {
582 581 .len = sizeof(unsigned int),
583 memset(&ke, 0, sizeof(ke)); 582 .flags = 0,
583 };
584 int __user *ip = (int __user *)p;
584 585
585 if (size == sizeof(unsigned int[2])) { 586 if (copy_from_user(ke.scancode, p, sizeof(unsigned int)))
586 /* legacy case */ 587 return -EFAULT;
587 int __user *ip = (int __user *)p;
588 588
589 if (copy_from_user(ke.scancode, p, sizeof(unsigned int))) 589 if (get_user(ke.keycode, ip + 1))
590 return -EFAULT; 590 return -EFAULT;
591 591
592 if (get_user(ke.keycode, ip + 1)) 592 return input_set_keycode(dev, &ke);
593 return -EFAULT; 593}
594 594
595 ke.len = sizeof(unsigned int); 595static int evdev_handle_set_keycode_v2(struct input_dev *dev, void __user *p)
596 ke.flags = 0; 596{
597 struct input_keymap_entry ke;
597 598
598 } else { 599 if (copy_from_user(&ke, p, sizeof(ke)))
599 size = min(size, sizeof(ke)); 600 return -EFAULT;
600 601
601 if (copy_from_user(&ke, p, size)) 602 if (ke.len > sizeof(ke.scancode))
602 return -EFAULT; 603 return -EINVAL;
603
604 if (ke.len > sizeof(ke.scancode))
605 return -EINVAL;
606 }
607 604
608 return input_set_keycode(dev, &ke); 605 return input_set_keycode(dev, &ke);
609} 606}
@@ -669,6 +666,18 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
669 return evdev_grab(evdev, client); 666 return evdev_grab(evdev, client);
670 else 667 else
671 return evdev_ungrab(evdev, client); 668 return evdev_ungrab(evdev, client);
669
670 case EVIOCGKEYCODE:
671 return evdev_handle_get_keycode(dev, p);
672
673 case EVIOCSKEYCODE:
674 return evdev_handle_set_keycode(dev, p);
675
676 case EVIOCGKEYCODE_V2:
677 return evdev_handle_get_keycode_v2(dev, p);
678
679 case EVIOCSKEYCODE_V2:
680 return evdev_handle_set_keycode_v2(dev, p);
672 } 681 }
673 682
674 size = _IOC_SIZE(cmd); 683 size = _IOC_SIZE(cmd);
@@ -708,12 +717,6 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
708 return -EFAULT; 717 return -EFAULT;
709 718
710 return error; 719 return error;
711
712 case EVIOC_MASK_SIZE(EVIOCGKEYCODE):
713 return evdev_handle_get_keycode(dev, p, size);
714
715 case EVIOC_MASK_SIZE(EVIOCSKEYCODE):
716 return evdev_handle_set_keycode(dev, p, size);
717 } 720 }
718 721
719 /* Multi-number variable-length handlers */ 722 /* Multi-number variable-length handlers */
diff --git a/drivers/input/input.c b/drivers/input/input.c
index d092ef9291da..db409d6bd5d2 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -24,7 +24,6 @@
24#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/rcupdate.h> 26#include <linux/rcupdate.h>
27#include <linux/smp_lock.h>
28#include "input-compat.h" 27#include "input-compat.h"
29 28
30MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 29MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
@@ -74,6 +73,7 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz)
74 * dev->event_lock held and interrupts disabled. 73 * dev->event_lock held and interrupts disabled.
75 */ 74 */
76static void input_pass_event(struct input_dev *dev, 75static void input_pass_event(struct input_dev *dev,
76 struct input_handler *src_handler,
77 unsigned int type, unsigned int code, int value) 77 unsigned int type, unsigned int code, int value)
78{ 78{
79 struct input_handler *handler; 79 struct input_handler *handler;
@@ -92,6 +92,15 @@ static void input_pass_event(struct input_dev *dev,
92 continue; 92 continue;
93 93
94 handler = handle->handler; 94 handler = handle->handler;
95
96 /*
97 * If this is the handler that injected this
98 * particular event we want to skip it to avoid
99 * filters firing again and again.
100 */
101 if (handler == src_handler)
102 continue;
103
95 if (!handler->filter) { 104 if (!handler->filter) {
96 if (filtered) 105 if (filtered)
97 break; 106 break;
@@ -121,7 +130,7 @@ static void input_repeat_key(unsigned long data)
121 if (test_bit(dev->repeat_key, dev->key) && 130 if (test_bit(dev->repeat_key, dev->key) &&
122 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 131 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
123 132
124 input_pass_event(dev, EV_KEY, dev->repeat_key, 2); 133 input_pass_event(dev, NULL, EV_KEY, dev->repeat_key, 2);
125 134
126 if (dev->sync) { 135 if (dev->sync) {
127 /* 136 /*
@@ -130,7 +139,7 @@ static void input_repeat_key(unsigned long data)
130 * Otherwise assume that the driver will send 139 * Otherwise assume that the driver will send
131 * SYN_REPORT once it's done. 140 * SYN_REPORT once it's done.
132 */ 141 */
133 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 142 input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
134 } 143 }
135 144
136 if (dev->rep[REP_PERIOD]) 145 if (dev->rep[REP_PERIOD])
@@ -163,6 +172,7 @@ static void input_stop_autorepeat(struct input_dev *dev)
163#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 172#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
164 173
165static int input_handle_abs_event(struct input_dev *dev, 174static int input_handle_abs_event(struct input_dev *dev,
175 struct input_handler *src_handler,
166 unsigned int code, int *pval) 176 unsigned int code, int *pval)
167{ 177{
168 bool is_mt_event; 178 bool is_mt_event;
@@ -206,13 +216,15 @@ static int input_handle_abs_event(struct input_dev *dev,
206 /* Flush pending "slot" event */ 216 /* Flush pending "slot" event */
207 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { 217 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
208 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot); 218 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
209 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot); 219 input_pass_event(dev, src_handler,
220 EV_ABS, ABS_MT_SLOT, dev->slot);
210 } 221 }
211 222
212 return INPUT_PASS_TO_HANDLERS; 223 return INPUT_PASS_TO_HANDLERS;
213} 224}
214 225
215static void input_handle_event(struct input_dev *dev, 226static void input_handle_event(struct input_dev *dev,
227 struct input_handler *src_handler,
216 unsigned int type, unsigned int code, int value) 228 unsigned int type, unsigned int code, int value)
217{ 229{
218 int disposition = INPUT_IGNORE_EVENT; 230 int disposition = INPUT_IGNORE_EVENT;
@@ -265,7 +277,8 @@ static void input_handle_event(struct input_dev *dev,
265 277
266 case EV_ABS: 278 case EV_ABS:
267 if (is_event_supported(code, dev->absbit, ABS_MAX)) 279 if (is_event_supported(code, dev->absbit, ABS_MAX))
268 disposition = input_handle_abs_event(dev, code, &value); 280 disposition = input_handle_abs_event(dev, src_handler,
281 code, &value);
269 282
270 break; 283 break;
271 284
@@ -323,7 +336,7 @@ static void input_handle_event(struct input_dev *dev,
323 dev->event(dev, type, code, value); 336 dev->event(dev, type, code, value);
324 337
325 if (disposition & INPUT_PASS_TO_HANDLERS) 338 if (disposition & INPUT_PASS_TO_HANDLERS)
326 input_pass_event(dev, type, code, value); 339 input_pass_event(dev, src_handler, type, code, value);
327} 340}
328 341
329/** 342/**
@@ -352,7 +365,7 @@ void input_event(struct input_dev *dev,
352 365
353 spin_lock_irqsave(&dev->event_lock, flags); 366 spin_lock_irqsave(&dev->event_lock, flags);
354 add_input_randomness(type, code, value); 367 add_input_randomness(type, code, value);
355 input_handle_event(dev, type, code, value); 368 input_handle_event(dev, NULL, type, code, value);
356 spin_unlock_irqrestore(&dev->event_lock, flags); 369 spin_unlock_irqrestore(&dev->event_lock, flags);
357 } 370 }
358} 371}
@@ -382,7 +395,8 @@ void input_inject_event(struct input_handle *handle,
382 rcu_read_lock(); 395 rcu_read_lock();
383 grab = rcu_dereference(dev->grab); 396 grab = rcu_dereference(dev->grab);
384 if (!grab || grab == handle) 397 if (!grab || grab == handle)
385 input_handle_event(dev, type, code, value); 398 input_handle_event(dev, handle->handler,
399 type, code, value);
386 rcu_read_unlock(); 400 rcu_read_unlock();
387 401
388 spin_unlock_irqrestore(&dev->event_lock, flags); 402 spin_unlock_irqrestore(&dev->event_lock, flags);
@@ -595,10 +609,10 @@ static void input_dev_release_keys(struct input_dev *dev)
595 for (code = 0; code <= KEY_MAX; code++) { 609 for (code = 0; code <= KEY_MAX; code++) {
596 if (is_event_supported(code, dev->keybit, KEY_MAX) && 610 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
597 __test_and_clear_bit(code, dev->key)) { 611 __test_and_clear_bit(code, dev->key)) {
598 input_pass_event(dev, EV_KEY, code, 0); 612 input_pass_event(dev, NULL, EV_KEY, code, 0);
599 } 613 }
600 } 614 }
601 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 615 input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
602 } 616 }
603} 617}
604 618
@@ -738,7 +752,7 @@ static int input_default_setkeycode(struct input_dev *dev,
738 if (index >= dev->keycodemax) 752 if (index >= dev->keycodemax)
739 return -EINVAL; 753 return -EINVAL;
740 754
741 if (dev->keycodesize < sizeof(dev->keycode) && 755 if (dev->keycodesize < sizeof(ke->keycode) &&
742 (ke->keycode >> (dev->keycodesize * 8))) 756 (ke->keycode >> (dev->keycodesize * 8)))
743 return -EINVAL; 757 return -EINVAL;
744 758
@@ -873,9 +887,9 @@ int input_set_keycode(struct input_dev *dev,
873 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && 887 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
874 __test_and_clear_bit(old_keycode, dev->key)) { 888 __test_and_clear_bit(old_keycode, dev->key)) {
875 889
876 input_pass_event(dev, EV_KEY, old_keycode, 0); 890 input_pass_event(dev, NULL, EV_KEY, old_keycode, 0);
877 if (dev->sync) 891 if (dev->sync)
878 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 892 input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
879 } 893 }
880 894
881 out: 895 out:
@@ -1565,8 +1579,7 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env)
1565 } \ 1579 } \
1566 } while (0) 1580 } while (0)
1567 1581
1568#ifdef CONFIG_PM 1582static void input_dev_toggle(struct input_dev *dev, bool activate)
1569static void input_dev_reset(struct input_dev *dev, bool activate)
1570{ 1583{
1571 if (!dev->event) 1584 if (!dev->event)
1572 return; 1585 return;
@@ -1580,12 +1593,44 @@ static void input_dev_reset(struct input_dev *dev, bool activate)
1580 } 1593 }
1581} 1594}
1582 1595
1596/**
1597 * input_reset_device() - reset/restore the state of input device
1598 * @dev: input device whose state needs to be reset
1599 *
1600 * This function tries to reset the state of an opened input device and
1601 * bring internal state and state if the hardware in sync with each other.
1602 * We mark all keys as released, restore LED state, repeat rate, etc.
1603 */
1604void input_reset_device(struct input_dev *dev)
1605{
1606 mutex_lock(&dev->mutex);
1607
1608 if (dev->users) {
1609 input_dev_toggle(dev, true);
1610
1611 /*
1612 * Keys that have been pressed at suspend time are unlikely
1613 * to be still pressed when we resume.
1614 */
1615 spin_lock_irq(&dev->event_lock);
1616 input_dev_release_keys(dev);
1617 spin_unlock_irq(&dev->event_lock);
1618 }
1619
1620 mutex_unlock(&dev->mutex);
1621}
1622EXPORT_SYMBOL(input_reset_device);
1623
1624#ifdef CONFIG_PM
1583static int input_dev_suspend(struct device *dev) 1625static int input_dev_suspend(struct device *dev)
1584{ 1626{
1585 struct input_dev *input_dev = to_input_dev(dev); 1627 struct input_dev *input_dev = to_input_dev(dev);
1586 1628
1587 mutex_lock(&input_dev->mutex); 1629 mutex_lock(&input_dev->mutex);
1588 input_dev_reset(input_dev, false); 1630
1631 if (input_dev->users)
1632 input_dev_toggle(input_dev, false);
1633
1589 mutex_unlock(&input_dev->mutex); 1634 mutex_unlock(&input_dev->mutex);
1590 1635
1591 return 0; 1636 return 0;
@@ -1595,18 +1640,7 @@ static int input_dev_resume(struct device *dev)
1595{ 1640{
1596 struct input_dev *input_dev = to_input_dev(dev); 1641 struct input_dev *input_dev = to_input_dev(dev);
1597 1642
1598 mutex_lock(&input_dev->mutex); 1643 input_reset_device(input_dev);
1599 input_dev_reset(input_dev, true);
1600
1601 /*
1602 * Keys that have been pressed at suspend time are unlikely
1603 * to be still pressed when we resume.
1604 */
1605 spin_lock_irq(&input_dev->event_lock);
1606 input_dev_release_keys(input_dev);
1607 spin_unlock_irq(&input_dev->event_lock);
1608
1609 mutex_unlock(&input_dev->mutex);
1610 1644
1611 return 0; 1645 return 0;
1612} 1646}
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index d53b9e900234..27b6a3ce18ca 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -245,6 +245,7 @@ static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
245 goto err_free_tgfx; 245 goto err_free_tgfx;
246 } 246 }
247 247
248 parport_put_port(pp);
248 return tgfx; 249 return tgfx;
249 250
250 err_free_dev: 251 err_free_dev:
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index b8c51b9781db..3a87f3ba5f75 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -179,6 +179,22 @@ config KEYBOARD_GPIO
179 To compile this driver as a module, choose M here: the 179 To compile this driver as a module, choose M here: the
180 module will be called gpio_keys. 180 module will be called gpio_keys.
181 181
182config KEYBOARD_GPIO_POLLED
183 tristate "Polled GPIO buttons"
184 depends on GENERIC_GPIO
185 select INPUT_POLLDEV
186 help
187 This driver implements support for buttons connected
188 to GPIO pins that are not capable of generating interrupts.
189
190 Say Y here if your device has buttons connected
191 directly to such GPIO pins. Your board-specific
192 setup logic must also provide a platform device,
193 with configuration data saying which GPIOs are used.
194
195 To compile this driver as a module, choose M here: the
196 module will be called gpio_keys_polled.
197
182config KEYBOARD_TCA6416 198config KEYBOARD_TCA6416
183 tristate "TCA6416 Keypad Support" 199 tristate "TCA6416 Keypad Support"
184 depends on I2C 200 depends on I2C
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index a34452e8ebe2..622de73a445d 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o
14obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o 14obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o
15obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o 15obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o
16obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o 16obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
17obj-$(CONFIG_KEYBOARD_GPIO_POLLED) += gpio_keys_polled.o
17obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o 18obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o
18obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 19obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
19obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o 20obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index b92d1cd5cba1..af45d275f686 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -4,7 +4,7 @@
4 * I2C QWERTY Keypad and IO Expander 4 * I2C QWERTY Keypad and IO Expander
5 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 5 * Bugs: Enter bugs at http://blackfin.uclinux.org/
6 * 6 *
7 * Copyright (C) 2008-2009 Analog Devices Inc. 7 * Copyright (C) 2008-2010 Analog Devices Inc.
8 * Licensed under the GPL-2 or later. 8 * Licensed under the GPL-2 or later.
9 */ 9 */
10 10
@@ -24,29 +24,6 @@
24 24
25#include <linux/i2c/adp5588.h> 25#include <linux/i2c/adp5588.h>
26 26
27 /* Configuration Register1 */
28#define AUTO_INC (1 << 7)
29#define GPIEM_CFG (1 << 6)
30#define OVR_FLOW_M (1 << 5)
31#define INT_CFG (1 << 4)
32#define OVR_FLOW_IEN (1 << 3)
33#define K_LCK_IM (1 << 2)
34#define GPI_IEN (1 << 1)
35#define KE_IEN (1 << 0)
36
37/* Interrupt Status Register */
38#define CMP2_INT (1 << 5)
39#define CMP1_INT (1 << 4)
40#define OVR_FLOW_INT (1 << 3)
41#define K_LCK_INT (1 << 2)
42#define GPI_INT (1 << 1)
43#define KE_INT (1 << 0)
44
45/* Key Lock and Event Counter Register */
46#define K_LCK_EN (1 << 6)
47#define LCK21 0x30
48#define KEC 0xF
49
50/* Key Event Register xy */ 27/* Key Event Register xy */
51#define KEY_EV_PRESSED (1 << 7) 28#define KEY_EV_PRESSED (1 << 7)
52#define KEY_EV_MASK (0x7F) 29#define KEY_EV_MASK (0x7F)
@@ -55,10 +32,6 @@
55 32
56#define KEYP_MAX_EVENT 10 33#define KEYP_MAX_EVENT 10
57 34
58#define MAXGPIO 18
59#define ADP_BANK(offs) ((offs) >> 3)
60#define ADP_BIT(offs) (1u << ((offs) & 0x7))
61
62/* 35/*
63 * Early pre 4.0 Silicon required to delay readout by at least 25ms, 36 * Early pre 4.0 Silicon required to delay readout by at least 25ms,
64 * since the Event Counter Register updated 25ms after the interrupt 37 * since the Event Counter Register updated 25ms after the interrupt
@@ -75,7 +48,7 @@ struct adp5588_kpad {
75 const struct adp5588_gpi_map *gpimap; 48 const struct adp5588_gpi_map *gpimap;
76 unsigned short gpimapsize; 49 unsigned short gpimapsize;
77#ifdef CONFIG_GPIOLIB 50#ifdef CONFIG_GPIOLIB
78 unsigned char gpiomap[MAXGPIO]; 51 unsigned char gpiomap[ADP5588_MAXGPIO];
79 bool export_gpio; 52 bool export_gpio;
80 struct gpio_chip gc; 53 struct gpio_chip gc;
81 struct mutex gpio_lock; /* Protect cached dir, dat_out */ 54 struct mutex gpio_lock; /* Protect cached dir, dat_out */
@@ -103,8 +76,8 @@ static int adp5588_write(struct i2c_client *client, u8 reg, u8 val)
103static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off) 76static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
104{ 77{
105 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 78 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
106 unsigned int bank = ADP_BANK(kpad->gpiomap[off]); 79 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
107 unsigned int bit = ADP_BIT(kpad->gpiomap[off]); 80 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
108 81
109 return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit); 82 return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit);
110} 83}
@@ -113,8 +86,8 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
113 unsigned off, int val) 86 unsigned off, int val)
114{ 87{
115 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 88 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
116 unsigned int bank = ADP_BANK(kpad->gpiomap[off]); 89 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
117 unsigned int bit = ADP_BIT(kpad->gpiomap[off]); 90 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
118 91
119 mutex_lock(&kpad->gpio_lock); 92 mutex_lock(&kpad->gpio_lock);
120 93
@@ -132,8 +105,8 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
132static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off) 105static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
133{ 106{
134 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 107 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
135 unsigned int bank = ADP_BANK(kpad->gpiomap[off]); 108 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
136 unsigned int bit = ADP_BIT(kpad->gpiomap[off]); 109 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
137 int ret; 110 int ret;
138 111
139 mutex_lock(&kpad->gpio_lock); 112 mutex_lock(&kpad->gpio_lock);
@@ -150,8 +123,8 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
150 unsigned off, int val) 123 unsigned off, int val)
151{ 124{
152 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 125 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
153 unsigned int bank = ADP_BANK(kpad->gpiomap[off]); 126 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
154 unsigned int bit = ADP_BIT(kpad->gpiomap[off]); 127 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
155 int ret; 128 int ret;
156 129
157 mutex_lock(&kpad->gpio_lock); 130 mutex_lock(&kpad->gpio_lock);
@@ -176,7 +149,7 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
176static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad, 149static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad,
177 const struct adp5588_kpad_platform_data *pdata) 150 const struct adp5588_kpad_platform_data *pdata)
178{ 151{
179 bool pin_used[MAXGPIO]; 152 bool pin_used[ADP5588_MAXGPIO];
180 int n_unused = 0; 153 int n_unused = 0;
181 int i; 154 int i;
182 155
@@ -191,7 +164,7 @@ static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad,
191 for (i = 0; i < kpad->gpimapsize; i++) 164 for (i = 0; i < kpad->gpimapsize; i++)
192 pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true; 165 pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true;
193 166
194 for (i = 0; i < MAXGPIO; i++) 167 for (i = 0; i < ADP5588_MAXGPIO; i++)
195 if (!pin_used[i]) 168 if (!pin_used[i])
196 kpad->gpiomap[n_unused++] = i; 169 kpad->gpiomap[n_unused++] = i;
197 170
@@ -234,7 +207,7 @@ static int __devinit adp5588_gpio_add(struct adp5588_kpad *kpad)
234 return error; 207 return error;
235 } 208 }
236 209
237 for (i = 0; i <= ADP_BANK(MAXGPIO); i++) { 210 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
238 kpad->dat_out[i] = adp5588_read(kpad->client, 211 kpad->dat_out[i] = adp5588_read(kpad->client,
239 GPIO_DAT_OUT1 + i); 212 GPIO_DAT_OUT1 + i);
240 kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i); 213 kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i);
@@ -318,11 +291,11 @@ static void adp5588_work(struct work_struct *work)
318 291
319 status = adp5588_read(client, INT_STAT); 292 status = adp5588_read(client, INT_STAT);
320 293
321 if (status & OVR_FLOW_INT) /* Unlikely and should never happen */ 294 if (status & ADP5588_OVR_FLOW_INT) /* Unlikely and should never happen */
322 dev_err(&client->dev, "Event Overflow Error\n"); 295 dev_err(&client->dev, "Event Overflow Error\n");
323 296
324 if (status & KE_INT) { 297 if (status & ADP5588_KE_INT) {
325 ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & KEC; 298 ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & ADP5588_KEC;
326 if (ev_cnt) { 299 if (ev_cnt) {
327 adp5588_report_events(kpad, ev_cnt); 300 adp5588_report_events(kpad, ev_cnt);
328 input_sync(kpad->input); 301 input_sync(kpad->input);
@@ -360,7 +333,7 @@ static int __devinit adp5588_setup(struct i2c_client *client)
360 if (pdata->en_keylock) { 333 if (pdata->en_keylock) {
361 ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1); 334 ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1);
362 ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2); 335 ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2);
363 ret |= adp5588_write(client, KEY_LCK_EC_STAT, K_LCK_EN); 336 ret |= adp5588_write(client, KEY_LCK_EC_STAT, ADP5588_K_LCK_EN);
364 } 337 }
365 338
366 for (i = 0; i < KEYP_MAX_EVENT; i++) 339 for (i = 0; i < KEYP_MAX_EVENT; i++)
@@ -384,7 +357,7 @@ static int __devinit adp5588_setup(struct i2c_client *client)
384 } 357 }
385 358
386 if (gpio_data) { 359 if (gpio_data) {
387 for (i = 0; i <= ADP_BANK(MAXGPIO); i++) { 360 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
388 int pull_mask = gpio_data->pullup_dis_mask; 361 int pull_mask = gpio_data->pullup_dis_mask;
389 362
390 ret |= adp5588_write(client, GPIO_PULL1 + i, 363 ret |= adp5588_write(client, GPIO_PULL1 + i,
@@ -392,11 +365,14 @@ static int __devinit adp5588_setup(struct i2c_client *client)
392 } 365 }
393 } 366 }
394 367
395 ret |= adp5588_write(client, INT_STAT, CMP2_INT | CMP1_INT | 368 ret |= adp5588_write(client, INT_STAT,
396 OVR_FLOW_INT | K_LCK_INT | 369 ADP5588_CMP2_INT | ADP5588_CMP1_INT |
397 GPI_INT | KE_INT); /* Status is W1C */ 370 ADP5588_OVR_FLOW_INT | ADP5588_K_LCK_INT |
371 ADP5588_GPI_INT | ADP5588_KE_INT); /* Status is W1C */
398 372
399 ret |= adp5588_write(client, CFG, INT_CFG | OVR_FLOW_IEN | KE_IEN); 373 ret |= adp5588_write(client, CFG, ADP5588_INT_CFG |
374 ADP5588_OVR_FLOW_IEN |
375 ADP5588_KE_IEN);
400 376
401 if (ret < 0) { 377 if (ret < 0) {
402 dev_err(&client->dev, "Write Error\n"); 378 dev_err(&client->dev, "Write Error\n");
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index d358ef8623f4..11478eb2c27d 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -63,6 +63,10 @@ static bool atkbd_extra;
63module_param_named(extra, atkbd_extra, bool, 0); 63module_param_named(extra, atkbd_extra, bool, 0);
64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards"); 64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards");
65 65
66static bool atkbd_terminal;
67module_param_named(terminal, atkbd_terminal, bool, 0);
68MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2");
69
66/* 70/*
67 * Scancode to keycode tables. These are just the default setting, and 71 * Scancode to keycode tables. These are just the default setting, and
68 * are loadable via a userland utility. 72 * are loadable via a userland utility.
@@ -136,7 +140,8 @@ static const unsigned short atkbd_unxlate_table[128] = {
136#define ATKBD_CMD_ENABLE 0x00f4 140#define ATKBD_CMD_ENABLE 0x00f4
137#define ATKBD_CMD_RESET_DIS 0x00f5 /* Reset to defaults and disable */ 141#define ATKBD_CMD_RESET_DIS 0x00f5 /* Reset to defaults and disable */
138#define ATKBD_CMD_RESET_DEF 0x00f6 /* Reset to defaults */ 142#define ATKBD_CMD_RESET_DEF 0x00f6 /* Reset to defaults */
139#define ATKBD_CMD_SETALL_MBR 0x00fa 143#define ATKBD_CMD_SETALL_MB 0x00f8 /* Set all keys to give break codes */
144#define ATKBD_CMD_SETALL_MBR 0x00fa /* ... and repeat */
140#define ATKBD_CMD_RESET_BAT 0x02ff 145#define ATKBD_CMD_RESET_BAT 0x02ff
141#define ATKBD_CMD_RESEND 0x00fe 146#define ATKBD_CMD_RESEND 0x00fe
142#define ATKBD_CMD_EX_ENABLE 0x10ea 147#define ATKBD_CMD_EX_ENABLE 0x10ea
@@ -764,6 +769,11 @@ static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra
764 } 769 }
765 } 770 }
766 771
772 if (atkbd_terminal) {
773 ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MB);
774 return 3;
775 }
776
767 if (target_set != 3) 777 if (target_set != 3)
768 return 2; 778 return 2;
769 779
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
new file mode 100644
index 000000000000..4c17aff20657
--- /dev/null
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -0,0 +1,261 @@
1/*
2 * Driver for buttons on GPIO lines not capable of generating interrupts
3 *
4 * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2010 Nuno Goncalves <nunojpg@gmail.com>
6 *
7 * This file was based on: /drivers/input/misc/cobalt_btns.c
8 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
9 *
10 * also was based on: /drivers/input/keyboard/gpio_keys.c
11 * Copyright 2005 Phil Blundell
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/input.h>
23#include <linux/input-polldev.h>
24#include <linux/ioport.h>
25#include <linux/platform_device.h>
26#include <linux/gpio.h>
27#include <linux/gpio_keys.h>
28
29#define DRV_NAME "gpio-keys-polled"
30
31struct gpio_keys_button_data {
32 int last_state;
33 int count;
34 int threshold;
35 int can_sleep;
36};
37
38struct gpio_keys_polled_dev {
39 struct input_polled_dev *poll_dev;
40 struct device *dev;
41 struct gpio_keys_platform_data *pdata;
42 struct gpio_keys_button_data data[0];
43};
44
45static void gpio_keys_polled_check_state(struct input_dev *input,
46 struct gpio_keys_button *button,
47 struct gpio_keys_button_data *bdata)
48{
49 int state;
50
51 if (bdata->can_sleep)
52 state = !!gpio_get_value_cansleep(button->gpio);
53 else
54 state = !!gpio_get_value(button->gpio);
55
56 if (state != bdata->last_state) {
57 unsigned int type = button->type ?: EV_KEY;
58
59 input_event(input, type, button->code,
60 !!(state ^ button->active_low));
61 input_sync(input);
62 bdata->count = 0;
63 bdata->last_state = state;
64 }
65}
66
67static void gpio_keys_polled_poll(struct input_polled_dev *dev)
68{
69 struct gpio_keys_polled_dev *bdev = dev->private;
70 struct gpio_keys_platform_data *pdata = bdev->pdata;
71 struct input_dev *input = dev->input;
72 int i;
73
74 for (i = 0; i < bdev->pdata->nbuttons; i++) {
75 struct gpio_keys_button_data *bdata = &bdev->data[i];
76
77 if (bdata->count < bdata->threshold)
78 bdata->count++;
79 else
80 gpio_keys_polled_check_state(input, &pdata->buttons[i],
81 bdata);
82 }
83}
84
85static void gpio_keys_polled_open(struct input_polled_dev *dev)
86{
87 struct gpio_keys_polled_dev *bdev = dev->private;
88 struct gpio_keys_platform_data *pdata = bdev->pdata;
89
90 if (pdata->enable)
91 pdata->enable(bdev->dev);
92}
93
94static void gpio_keys_polled_close(struct input_polled_dev *dev)
95{
96 struct gpio_keys_polled_dev *bdev = dev->private;
97 struct gpio_keys_platform_data *pdata = bdev->pdata;
98
99 if (pdata->disable)
100 pdata->disable(bdev->dev);
101}
102
103static int __devinit gpio_keys_polled_probe(struct platform_device *pdev)
104{
105 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
106 struct device *dev = &pdev->dev;
107 struct gpio_keys_polled_dev *bdev;
108 struct input_polled_dev *poll_dev;
109 struct input_dev *input;
110 int error;
111 int i;
112
113 if (!pdata || !pdata->poll_interval)
114 return -EINVAL;
115
116 bdev = kzalloc(sizeof(struct gpio_keys_polled_dev) +
117 pdata->nbuttons * sizeof(struct gpio_keys_button_data),
118 GFP_KERNEL);
119 if (!bdev) {
120 dev_err(dev, "no memory for private data\n");
121 return -ENOMEM;
122 }
123
124 poll_dev = input_allocate_polled_device();
125 if (!poll_dev) {
126 dev_err(dev, "no memory for polled device\n");
127 error = -ENOMEM;
128 goto err_free_bdev;
129 }
130
131 poll_dev->private = bdev;
132 poll_dev->poll = gpio_keys_polled_poll;
133 poll_dev->poll_interval = pdata->poll_interval;
134 poll_dev->open = gpio_keys_polled_open;
135 poll_dev->close = gpio_keys_polled_close;
136
137 input = poll_dev->input;
138
139 input->evbit[0] = BIT(EV_KEY);
140 input->name = pdev->name;
141 input->phys = DRV_NAME"/input0";
142 input->dev.parent = &pdev->dev;
143
144 input->id.bustype = BUS_HOST;
145 input->id.vendor = 0x0001;
146 input->id.product = 0x0001;
147 input->id.version = 0x0100;
148
149 for (i = 0; i < pdata->nbuttons; i++) {
150 struct gpio_keys_button *button = &pdata->buttons[i];
151 struct gpio_keys_button_data *bdata = &bdev->data[i];
152 unsigned int gpio = button->gpio;
153 unsigned int type = button->type ?: EV_KEY;
154
155 if (button->wakeup) {
156 dev_err(dev, DRV_NAME " does not support wakeup\n");
157 error = -EINVAL;
158 goto err_free_gpio;
159 }
160
161 error = gpio_request(gpio,
162 button->desc ? button->desc : DRV_NAME);
163 if (error) {
164 dev_err(dev, "unable to claim gpio %u, err=%d\n",
165 gpio, error);
166 goto err_free_gpio;
167 }
168
169 error = gpio_direction_input(gpio);
170 if (error) {
171 dev_err(dev,
172 "unable to set direction on gpio %u, err=%d\n",
173 gpio, error);
174 goto err_free_gpio;
175 }
176
177 bdata->can_sleep = gpio_cansleep(gpio);
178 bdata->last_state = -1;
179 bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
180 pdata->poll_interval);
181
182 input_set_capability(input, type, button->code);
183 }
184
185 bdev->poll_dev = poll_dev;
186 bdev->dev = dev;
187 bdev->pdata = pdata;
188 platform_set_drvdata(pdev, bdev);
189
190 error = input_register_polled_device(poll_dev);
191 if (error) {
192 dev_err(dev, "unable to register polled device, err=%d\n",
193 error);
194 goto err_free_gpio;
195 }
196
197 /* report initial state of the buttons */
198 for (i = 0; i < pdata->nbuttons; i++)
199 gpio_keys_polled_check_state(input, &pdata->buttons[i],
200 &bdev->data[i]);
201
202 return 0;
203
204err_free_gpio:
205 while (--i >= 0)
206 gpio_free(pdata->buttons[i].gpio);
207
208 input_free_polled_device(poll_dev);
209
210err_free_bdev:
211 kfree(bdev);
212
213 platform_set_drvdata(pdev, NULL);
214 return error;
215}
216
217static int __devexit gpio_keys_polled_remove(struct platform_device *pdev)
218{
219 struct gpio_keys_polled_dev *bdev = platform_get_drvdata(pdev);
220 struct gpio_keys_platform_data *pdata = bdev->pdata;
221 int i;
222
223 input_unregister_polled_device(bdev->poll_dev);
224
225 for (i = 0; i < pdata->nbuttons; i++)
226 gpio_free(pdata->buttons[i].gpio);
227
228 input_free_polled_device(bdev->poll_dev);
229
230 kfree(bdev);
231 platform_set_drvdata(pdev, NULL);
232
233 return 0;
234}
235
236static struct platform_driver gpio_keys_polled_driver = {
237 .probe = gpio_keys_polled_probe,
238 .remove = __devexit_p(gpio_keys_polled_remove),
239 .driver = {
240 .name = DRV_NAME,
241 .owner = THIS_MODULE,
242 },
243};
244
245static int __init gpio_keys_polled_init(void)
246{
247 return platform_driver_register(&gpio_keys_polled_driver);
248}
249
250static void __exit gpio_keys_polled_exit(void)
251{
252 platform_driver_unregister(&gpio_keys_polled_driver);
253}
254
255module_init(gpio_keys_polled_init);
256module_exit(gpio_keys_polled_exit);
257
258MODULE_LICENSE("GPL v2");
259MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
260MODULE_DESCRIPTION("Polled GPIO Buttons driver");
261MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/input/misc/pcf8574_keypad.c b/drivers/input/misc/pcf8574_keypad.c
index 4b42ffc0532a..d1583aea1721 100644
--- a/drivers/input/misc/pcf8574_keypad.c
+++ b/drivers/input/misc/pcf8574_keypad.c
@@ -127,14 +127,6 @@ static int __devinit pcf8574_kp_probe(struct i2c_client *client, const struct i2
127 idev->id.product = 0x0001; 127 idev->id.product = 0x0001;
128 idev->id.version = 0x0100; 128 idev->id.version = 0x0100;
129 129
130 input_set_drvdata(idev, lp);
131
132 ret = input_register_device(idev);
133 if (ret) {
134 dev_err(&client->dev, "input_register_device() failed\n");
135 goto fail_register;
136 }
137
138 lp->laststate = read_state(lp); 130 lp->laststate = read_state(lp);
139 131
140 ret = request_threaded_irq(client->irq, NULL, pcf8574_kp_irq_handler, 132 ret = request_threaded_irq(client->irq, NULL, pcf8574_kp_irq_handler,
@@ -142,16 +134,21 @@ static int __devinit pcf8574_kp_probe(struct i2c_client *client, const struct i2
142 DRV_NAME, lp); 134 DRV_NAME, lp);
143 if (ret) { 135 if (ret) {
144 dev_err(&client->dev, "IRQ %d is not free\n", client->irq); 136 dev_err(&client->dev, "IRQ %d is not free\n", client->irq);
145 goto fail_irq; 137 goto fail_free_device;
138 }
139
140 ret = input_register_device(idev);
141 if (ret) {
142 dev_err(&client->dev, "input_register_device() failed\n");
143 goto fail_free_irq;
146 } 144 }
147 145
148 i2c_set_clientdata(client, lp); 146 i2c_set_clientdata(client, lp);
149 return 0; 147 return 0;
150 148
151 fail_irq: 149 fail_free_irq:
152 input_unregister_device(idev); 150 free_irq(client->irq, lp);
153 fail_register: 151 fail_free_device:
154 input_set_drvdata(idev, NULL);
155 input_free_device(idev); 152 input_free_device(idev);
156 fail_allocate: 153 fail_allocate:
157 kfree(lp); 154 kfree(lp);
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index a9cf76831634..b77f9991278e 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -630,7 +630,7 @@ static void atp_complete_geyser_3_4(struct urb *urb)
630 /* Just update the base values (i.e. touchpad in untouched state) */ 630 /* Just update the base values (i.e. touchpad in untouched state) */
631 if (dev->data[dev->info->datalen - 1] & ATP_STATUS_BASE_UPDATE) { 631 if (dev->data[dev->info->datalen - 1] & ATP_STATUS_BASE_UPDATE) {
632 632
633 dprintk(KERN_DEBUG "appletouch: updated base values\n"); 633 dprintk("appletouch: updated base values\n");
634 634
635 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); 635 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
636 goto exit; 636 goto exit;
diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
index 613a3652f98f..0aefaa885871 100644
--- a/drivers/input/mouse/synaptics.h
+++ b/drivers/input/mouse/synaptics.h
@@ -51,7 +51,8 @@
51#define SYN_EXT_CAP_REQUESTS(c) (((c) & 0x700000) >> 20) 51#define SYN_EXT_CAP_REQUESTS(c) (((c) & 0x700000) >> 20)
52#define SYN_CAP_MULTI_BUTTON_NO(ec) (((ec) & 0x00f000) >> 12) 52#define SYN_CAP_MULTI_BUTTON_NO(ec) (((ec) & 0x00f000) >> 12)
53#define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16) 53#define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16)
54#define SYN_CAP_CLICKPAD(ex0c) ((ex0c) & 0x100100) 54#define SYN_CAP_CLICKPAD(ex0c) ((ex0c) & 0x100000) /* 1-button ClickPad */
55#define SYN_CAP_CLICKPAD2BTN(ex0c) ((ex0c) & 0x000100) /* 2-button ClickPad */
55#define SYN_CAP_MAX_DIMENSIONS(ex0c) ((ex0c) & 0x020000) 56#define SYN_CAP_MAX_DIMENSIONS(ex0c) ((ex0c) & 0x020000)
56 57
57/* synaptics modes query bits */ 58/* synaptics modes query bits */
diff --git a/drivers/input/serio/gscps2.c b/drivers/input/serio/gscps2.c
index 3c287dd879d3..4225f5d6b15f 100644
--- a/drivers/input/serio/gscps2.c
+++ b/drivers/input/serio/gscps2.c
@@ -358,7 +358,7 @@ static int __devinit gscps2_probe(struct parisc_device *dev)
358 gscps2_reset(ps2port); 358 gscps2_reset(ps2port);
359 ps2port->id = readb(ps2port->addr + GSC_ID) & 0x0f; 359 ps2port->id = readb(ps2port->addr + GSC_ID) & 0x0f;
360 360
361 snprintf(serio->name, sizeof(serio->name), "GSC PS/2 %s", 361 snprintf(serio->name, sizeof(serio->name), "gsc-ps2-%s",
362 (ps2port->id == GSC_ID_KEYBOARD) ? "keyboard" : "mouse"); 362 (ps2port->id == GSC_ID_KEYBOARD) ? "keyboard" : "mouse");
363 strlcpy(serio->phys, dev_name(&dev->dev), sizeof(serio->phys)); 363 strlcpy(serio->phys, dev_name(&dev->dev), sizeof(serio->phys));
364 serio->id.type = SERIO_8042; 364 serio->id.type = SERIO_8042;
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index ed7ad7416b24..a5475b577086 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -351,6 +351,17 @@ static const struct dmi_system_id __initconst i8042_dmi_nomux_table[] = {
351 }, 351 },
352 }, 352 },
353 { 353 {
354 /*
355 * Most (all?) VAIOs do not have external PS/2 ports nor
356 * they implement active multiplexing properly, and
357 * MUX discovery usually messes up keyboard/touchpad.
358 */
359 .matches = {
360 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
361 DMI_MATCH(DMI_BOARD_NAME, "VAIO"),
362 },
363 },
364 {
354 /* Amoi M636/A737 */ 365 /* Amoi M636/A737 */
355 .matches = { 366 .matches = {
356 DMI_MATCH(DMI_SYS_VENDOR, "Amoi Electronics CO.,LTD."), 367 DMI_MATCH(DMI_SYS_VENDOR, "Amoi Electronics CO.,LTD."),
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
index cd82bb125915..b7ba4597f7f0 100644
--- a/drivers/input/serio/serio_raw.c
+++ b/drivers/input/serio/serio_raw.c
@@ -11,7 +11,6 @@
11 11
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/smp_lock.h>
15#include <linux/poll.h> 14#include <linux/poll.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/serio.h> 16#include <linux/serio.h>
diff --git a/drivers/input/tablet/acecad.c b/drivers/input/tablet/acecad.c
index aea9a9399a36..d94f7e9aa997 100644
--- a/drivers/input/tablet/acecad.c
+++ b/drivers/input/tablet/acecad.c
@@ -229,12 +229,13 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
229 229
230 err = input_register_device(acecad->input); 230 err = input_register_device(acecad->input);
231 if (err) 231 if (err)
232 goto fail2; 232 goto fail3;
233 233
234 usb_set_intfdata(intf, acecad); 234 usb_set_intfdata(intf, acecad);
235 235
236 return 0; 236 return 0;
237 237
238 fail3: usb_free_urb(acecad->irq);
238 fail2: usb_free_coherent(dev, 8, acecad->data, acecad->data_dma); 239 fail2: usb_free_coherent(dev, 8, acecad->data, acecad->data_dma);
239 fail1: input_free_device(input_dev); 240 fail1: input_free_device(input_dev);
240 kfree(acecad); 241 kfree(acecad);
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 57b25b84d1fc..0a619c558bfb 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -1097,7 +1097,7 @@ store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const
1097} 1097}
1098 1098
1099static DEVICE_ATTR(pointer_mode, 1099static DEVICE_ATTR(pointer_mode,
1100 S_IRUGO | S_IWUGO, 1100 S_IRUGO | S_IWUSR,
1101 show_tabletPointerMode, store_tabletPointerMode); 1101 show_tabletPointerMode, store_tabletPointerMode);
1102 1102
1103/*********************************************************************** 1103/***********************************************************************
@@ -1134,7 +1134,7 @@ store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, co
1134} 1134}
1135 1135
1136static DEVICE_ATTR(coordinate_mode, 1136static DEVICE_ATTR(coordinate_mode,
1137 S_IRUGO | S_IWUGO, 1137 S_IRUGO | S_IWUSR,
1138 show_tabletCoordinateMode, store_tabletCoordinateMode); 1138 show_tabletCoordinateMode, store_tabletCoordinateMode);
1139 1139
1140/*********************************************************************** 1140/***********************************************************************
@@ -1176,7 +1176,7 @@ store_tabletToolMode(struct device *dev, struct device_attribute *attr, const ch
1176} 1176}
1177 1177
1178static DEVICE_ATTR(tool_mode, 1178static DEVICE_ATTR(tool_mode,
1179 S_IRUGO | S_IWUGO, 1179 S_IRUGO | S_IWUSR,
1180 show_tabletToolMode, store_tabletToolMode); 1180 show_tabletToolMode, store_tabletToolMode);
1181 1181
1182/*********************************************************************** 1182/***********************************************************************
@@ -1219,7 +1219,7 @@ store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char
1219} 1219}
1220 1220
1221static DEVICE_ATTR(xtilt, 1221static DEVICE_ATTR(xtilt,
1222 S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt); 1222 S_IRUGO | S_IWUSR, show_tabletXtilt, store_tabletXtilt);
1223 1223
1224/*********************************************************************** 1224/***********************************************************************
1225 * support routines for the 'ytilt' file. Note that this file 1225 * support routines for the 'ytilt' file. Note that this file
@@ -1261,7 +1261,7 @@ store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char
1261} 1261}
1262 1262
1263static DEVICE_ATTR(ytilt, 1263static DEVICE_ATTR(ytilt,
1264 S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt); 1264 S_IRUGO | S_IWUSR, show_tabletYtilt, store_tabletYtilt);
1265 1265
1266/*********************************************************************** 1266/***********************************************************************
1267 * support routines for the 'jitter' file. Note that this file 1267 * support routines for the 'jitter' file. Note that this file
@@ -1288,7 +1288,7 @@ store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const
1288} 1288}
1289 1289
1290static DEVICE_ATTR(jitter, 1290static DEVICE_ATTR(jitter,
1291 S_IRUGO | S_IWUGO, 1291 S_IRUGO | S_IWUSR,
1292 show_tabletJitterDelay, store_tabletJitterDelay); 1292 show_tabletJitterDelay, store_tabletJitterDelay);
1293 1293
1294/*********************************************************************** 1294/***********************************************************************
@@ -1317,7 +1317,7 @@ store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr,
1317} 1317}
1318 1318
1319static DEVICE_ATTR(delay, 1319static DEVICE_ATTR(delay,
1320 S_IRUGO | S_IWUGO, 1320 S_IRUGO | S_IWUSR,
1321 show_tabletProgrammableDelay, store_tabletProgrammableDelay); 1321 show_tabletProgrammableDelay, store_tabletProgrammableDelay);
1322 1322
1323/*********************************************************************** 1323/***********************************************************************
@@ -1406,7 +1406,7 @@ store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const
1406} 1406}
1407 1407
1408static DEVICE_ATTR(stylus_upper, 1408static DEVICE_ATTR(stylus_upper,
1409 S_IRUGO | S_IWUGO, 1409 S_IRUGO | S_IWUSR,
1410 show_tabletStylusUpper, store_tabletStylusUpper); 1410 show_tabletStylusUpper, store_tabletStylusUpper);
1411 1411
1412/*********************************************************************** 1412/***********************************************************************
@@ -1437,7 +1437,7 @@ store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const
1437} 1437}
1438 1438
1439static DEVICE_ATTR(stylus_lower, 1439static DEVICE_ATTR(stylus_lower,
1440 S_IRUGO | S_IWUGO, 1440 S_IRUGO | S_IWUSR,
1441 show_tabletStylusLower, store_tabletStylusLower); 1441 show_tabletStylusLower, store_tabletStylusLower);
1442 1442
1443/*********************************************************************** 1443/***********************************************************************
@@ -1475,7 +1475,7 @@ store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const c
1475} 1475}
1476 1476
1477static DEVICE_ATTR(mouse_left, 1477static DEVICE_ATTR(mouse_left,
1478 S_IRUGO | S_IWUGO, 1478 S_IRUGO | S_IWUSR,
1479 show_tabletMouseLeft, store_tabletMouseLeft); 1479 show_tabletMouseLeft, store_tabletMouseLeft);
1480 1480
1481/*********************************************************************** 1481/***********************************************************************
@@ -1505,7 +1505,7 @@ store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const
1505} 1505}
1506 1506
1507static DEVICE_ATTR(mouse_middle, 1507static DEVICE_ATTR(mouse_middle,
1508 S_IRUGO | S_IWUGO, 1508 S_IRUGO | S_IWUSR,
1509 show_tabletMouseMiddle, store_tabletMouseMiddle); 1509 show_tabletMouseMiddle, store_tabletMouseMiddle);
1510 1510
1511/*********************************************************************** 1511/***********************************************************************
@@ -1535,7 +1535,7 @@ store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const
1535} 1535}
1536 1536
1537static DEVICE_ATTR(mouse_right, 1537static DEVICE_ATTR(mouse_right,
1538 S_IRUGO | S_IWUGO, 1538 S_IRUGO | S_IWUSR,
1539 show_tabletMouseRight, store_tabletMouseRight); 1539 show_tabletMouseRight, store_tabletMouseRight);
1540 1540
1541/*********************************************************************** 1541/***********************************************************************
@@ -1567,7 +1567,7 @@ store_tabletWheel(struct device *dev, struct device_attribute *attr, const char
1567} 1567}
1568 1568
1569static DEVICE_ATTR(wheel, 1569static DEVICE_ATTR(wheel,
1570 S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel); 1570 S_IRUGO | S_IWUSR, show_tabletWheel, store_tabletWheel);
1571 1571
1572/*********************************************************************** 1572/***********************************************************************
1573 * support routines for the 'execute' file. Note that this file 1573 * support routines for the 'execute' file. Note that this file
@@ -1600,7 +1600,7 @@ store_tabletExecute(struct device *dev, struct device_attribute *attr, const cha
1600} 1600}
1601 1601
1602static DEVICE_ATTR(execute, 1602static DEVICE_ATTR(execute,
1603 S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute); 1603 S_IRUGO | S_IWUSR, show_tabletExecute, store_tabletExecute);
1604 1604
1605/*********************************************************************** 1605/***********************************************************************
1606 * support routines for the 'odm_code' file. Note that this file 1606 * support routines for the 'odm_code' file. Note that this file
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index b3252ef1e279..435b0af401e4 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -1436,6 +1436,14 @@ static struct wacom_features wacom_features_0xD2 =
1436 { "Wacom Bamboo Craft", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023, 63, BAMBOO_PT }; 1436 { "Wacom Bamboo Craft", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023, 63, BAMBOO_PT };
1437static struct wacom_features wacom_features_0xD3 = 1437static struct wacom_features wacom_features_0xD3 =
1438 { "Wacom Bamboo 2FG 6x8", WACOM_PKGLEN_BBFUN, 21648, 13530, 1023, 63, BAMBOO_PT }; 1438 { "Wacom Bamboo 2FG 6x8", WACOM_PKGLEN_BBFUN, 21648, 13530, 1023, 63, BAMBOO_PT };
1439static const struct wacom_features wacom_features_0xD4 =
1440 { "Wacom Bamboo Pen", WACOM_PKGLEN_BBFUN, 14720, 9200, 255, 63, BAMBOO_PT };
1441static struct wacom_features wacom_features_0xD8 =
1442 { "Wacom Bamboo Comic 2FG", WACOM_PKGLEN_BBFUN, 21648, 13530, 1023, 63, BAMBOO_PT };
1443static struct wacom_features wacom_features_0xDA =
1444 { "Wacom Bamboo 2FG 4x5 SE", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023, 63, BAMBOO_PT };
1445static struct wacom_features wacom_features_0xDB =
1446 { "Wacom Bamboo 2FG 6x8 SE", WACOM_PKGLEN_BBFUN, 21648, 13530, 1023, 63, BAMBOO_PT };
1439 1447
1440#define USB_DEVICE_WACOM(prod) \ 1448#define USB_DEVICE_WACOM(prod) \
1441 USB_DEVICE(USB_VENDOR_ID_WACOM, prod), \ 1449 USB_DEVICE(USB_VENDOR_ID_WACOM, prod), \
@@ -1504,6 +1512,10 @@ const struct usb_device_id wacom_ids[] = {
1504 { USB_DEVICE_WACOM(0xD1) }, 1512 { USB_DEVICE_WACOM(0xD1) },
1505 { USB_DEVICE_WACOM(0xD2) }, 1513 { USB_DEVICE_WACOM(0xD2) },
1506 { USB_DEVICE_WACOM(0xD3) }, 1514 { USB_DEVICE_WACOM(0xD3) },
1515 { USB_DEVICE_WACOM(0xD4) },
1516 { USB_DEVICE_WACOM(0xD8) },
1517 { USB_DEVICE_WACOM(0xDA) },
1518 { USB_DEVICE_WACOM(0xDB) },
1507 { USB_DEVICE_WACOM(0xF0) }, 1519 { USB_DEVICE_WACOM(0xF0) },
1508 { USB_DEVICE_WACOM(0xCC) }, 1520 { USB_DEVICE_WACOM(0xCC) },
1509 { USB_DEVICE_WACOM(0x90) }, 1521 { USB_DEVICE_WACOM(0x90) },
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index ba6f0bd1e762..bc3b5187f3a3 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -129,6 +129,9 @@ struct ad7879 {
129 u16 cmd_crtl1; 129 u16 cmd_crtl1;
130 u16 cmd_crtl2; 130 u16 cmd_crtl2;
131 u16 cmd_crtl3; 131 u16 cmd_crtl3;
132 int x;
133 int y;
134 int Rt;
132}; 135};
133 136
134static int ad7879_read(struct ad7879 *ts, u8 reg) 137static int ad7879_read(struct ad7879 *ts, u8 reg)
@@ -175,13 +178,32 @@ static int ad7879_report(struct ad7879 *ts)
175 Rt /= z1; 178 Rt /= z1;
176 Rt = (Rt + 2047) >> 12; 179 Rt = (Rt + 2047) >> 12;
177 180
178 if (!timer_pending(&ts->timer)) 181 /*
182 * Sample found inconsistent, pressure is beyond
183 * the maximum. Don't report it to user space.
184 */
185 if (Rt > ts->pressure_max)
186 return -EINVAL;
187
188 /*
189 * Note that we delay reporting events by one sample.
190 * This is done to avoid reporting last sample of the
191 * touch sequence, which may be incomplete if finger
192 * leaves the surface before last reading is taken.
193 */
194 if (timer_pending(&ts->timer)) {
195 /* Touch continues */
179 input_report_key(input_dev, BTN_TOUCH, 1); 196 input_report_key(input_dev, BTN_TOUCH, 1);
197 input_report_abs(input_dev, ABS_X, ts->x);
198 input_report_abs(input_dev, ABS_Y, ts->y);
199 input_report_abs(input_dev, ABS_PRESSURE, ts->Rt);
200 input_sync(input_dev);
201 }
202
203 ts->x = x;
204 ts->y = y;
205 ts->Rt = Rt;
180 206
181 input_report_abs(input_dev, ABS_X, x);
182 input_report_abs(input_dev, ABS_Y, y);
183 input_report_abs(input_dev, ABS_PRESSURE, Rt);
184 input_sync(input_dev);
185 return 0; 207 return 0;
186 } 208 }
187 209
diff --git a/drivers/input/touchscreen/bu21013_ts.c b/drivers/input/touchscreen/bu21013_ts.c
index ccde58602563..2ca9e5d66460 100644
--- a/drivers/input/touchscreen/bu21013_ts.c
+++ b/drivers/input/touchscreen/bu21013_ts.c
@@ -514,7 +514,7 @@ err_free_irq:
514err_cs_disable: 514err_cs_disable:
515 pdata->cs_dis(pdata->cs_pin); 515 pdata->cs_dis(pdata->cs_pin);
516err_free_mem: 516err_free_mem:
517 input_free_device(bu21013_data->in_dev); 517 input_free_device(in_dev);
518 kfree(bu21013_data); 518 kfree(bu21013_data);
519 519
520 return error; 520 return error;
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index f45f80f6d336..73fd6642b681 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -178,6 +178,7 @@ static const struct usb_device_id usbtouch_devices[] = {
178 178
179#ifdef CONFIG_TOUCHSCREEN_USB_ITM 179#ifdef CONFIG_TOUCHSCREEN_USB_ITM
180 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM}, 180 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
181 {USB_DEVICE(0x16e3, 0xf9e9), .driver_info = DEVTYPE_ITM},
181#endif 182#endif
182 183
183#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO 184#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
index 2e847a90bad0..f2b5bab5e6a1 100644
--- a/drivers/isdn/icn/icn.c
+++ b/drivers/isdn/icn/icn.c
@@ -1627,7 +1627,7 @@ __setup("icn=", icn_setup);
1627static int __init icn_init(void) 1627static int __init icn_init(void)
1628{ 1628{
1629 char *p; 1629 char *p;
1630 char rev[10]; 1630 char rev[20];
1631 1631
1632 memset(&dev, 0, sizeof(icn_dev)); 1632 memset(&dev, 0, sizeof(icn_dev));
1633 dev.memaddr = (membase & 0x0ffc000); 1633 dev.memaddr = (membase & 0x0ffc000);
@@ -1637,9 +1637,10 @@ static int __init icn_init(void)
1637 spin_lock_init(&dev.devlock); 1637 spin_lock_init(&dev.devlock);
1638 1638
1639 if ((p = strchr(revision, ':'))) { 1639 if ((p = strchr(revision, ':'))) {
1640 strcpy(rev, p + 1); 1640 strncpy(rev, p + 1, 20);
1641 p = strchr(rev, '$'); 1641 p = strchr(rev, '$');
1642 *p = 0; 1642 if (p)
1643 *p = 0;
1643 } else 1644 } else
1644 strcpy(rev, " ??? "); 1645 strcpy(rev, " ??? ");
1645 printk(KERN_NOTICE "ICN-ISDN-driver Rev%smem=0x%08lx\n", rev, 1646 printk(KERN_NOTICE "ICN-ISDN-driver Rev%smem=0x%08lx\n", rev,
diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
index 3232206406b1..7446d8b4282d 100644
--- a/drivers/isdn/mISDN/socket.c
+++ b/drivers/isdn/mISDN/socket.c
@@ -392,6 +392,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
392 if (dev) { 392 if (dev) {
393 struct mISDN_devinfo di; 393 struct mISDN_devinfo di;
394 394
395 memset(&di, 0, sizeof(di));
395 di.id = dev->id; 396 di.id = dev->id;
396 di.Dprotocols = dev->Dprotocols; 397 di.Dprotocols = dev->Dprotocols;
397 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols(); 398 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
@@ -672,6 +673,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
672 if (dev) { 673 if (dev) {
673 struct mISDN_devinfo di; 674 struct mISDN_devinfo di;
674 675
676 memset(&di, 0, sizeof(di));
675 di.id = dev->id; 677 di.id = dev->id;
676 di.Dprotocols = dev->Dprotocols; 678 di.Dprotocols = dev->Dprotocols;
677 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols(); 679 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index cc2a88d5192f..6f190f4cdbc0 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -7,20 +7,20 @@ menuconfig NEW_LEDS
7 This is not related to standard keyboard LEDs which are controlled 7 This is not related to standard keyboard LEDs which are controlled
8 via the input system. 8 via the input system.
9 9
10if NEW_LEDS
11
12config LEDS_CLASS 10config LEDS_CLASS
13 tristate "LED Class Support" 11 bool "LED Class Support"
12 depends on NEW_LEDS
14 help 13 help
15 This option enables the led sysfs class in /sys/class/leds. You'll 14 This option enables the led sysfs class in /sys/class/leds. You'll
16 need this to do anything useful with LEDs. If unsure, say N. 15 need this to do anything useful with LEDs. If unsure, say N.
17 16
18if LEDS_CLASS 17if NEW_LEDS
19 18
20comment "LED drivers" 19comment "LED drivers"
21 20
22config LEDS_88PM860X 21config LEDS_88PM860X
23 tristate "LED Support for Marvell 88PM860x PMIC" 22 tristate "LED Support for Marvell 88PM860x PMIC"
23 depends on LEDS_CLASS
24 depends on MFD_88PM860X 24 depends on MFD_88PM860X
25 help 25 help
26 This option enables support for on-chip LED drivers found on Marvell 26 This option enables support for on-chip LED drivers found on Marvell
@@ -28,6 +28,7 @@ config LEDS_88PM860X
28 28
29config LEDS_ATMEL_PWM 29config LEDS_ATMEL_PWM
30 tristate "LED Support using Atmel PWM outputs" 30 tristate "LED Support using Atmel PWM outputs"
31 depends on LEDS_CLASS
31 depends on ATMEL_PWM 32 depends on ATMEL_PWM
32 help 33 help
33 This option enables support for LEDs driven using outputs 34 This option enables support for LEDs driven using outputs
@@ -35,6 +36,7 @@ config LEDS_ATMEL_PWM
35 36
36config LEDS_LOCOMO 37config LEDS_LOCOMO
37 tristate "LED Support for Locomo device" 38 tristate "LED Support for Locomo device"
39 depends on LEDS_CLASS
38 depends on SHARP_LOCOMO 40 depends on SHARP_LOCOMO
39 help 41 help
40 This option enables support for the LEDs on Sharp Locomo. 42 This option enables support for the LEDs on Sharp Locomo.
@@ -42,6 +44,7 @@ config LEDS_LOCOMO
42 44
43config LEDS_MIKROTIK_RB532 45config LEDS_MIKROTIK_RB532
44 tristate "LED Support for Mikrotik Routerboard 532" 46 tristate "LED Support for Mikrotik Routerboard 532"
47 depends on LEDS_CLASS
45 depends on MIKROTIK_RB532 48 depends on MIKROTIK_RB532
46 help 49 help
47 This option enables support for the so called "User LED" of 50 This option enables support for the so called "User LED" of
@@ -49,6 +52,7 @@ config LEDS_MIKROTIK_RB532
49 52
50config LEDS_S3C24XX 53config LEDS_S3C24XX
51 tristate "LED Support for Samsung S3C24XX GPIO LEDs" 54 tristate "LED Support for Samsung S3C24XX GPIO LEDs"
55 depends on LEDS_CLASS
52 depends on ARCH_S3C2410 56 depends on ARCH_S3C2410
53 help 57 help
54 This option enables support for LEDs connected to GPIO lines 58 This option enables support for LEDs connected to GPIO lines
@@ -56,12 +60,14 @@ config LEDS_S3C24XX
56 60
57config LEDS_AMS_DELTA 61config LEDS_AMS_DELTA
58 tristate "LED Support for the Amstrad Delta (E3)" 62 tristate "LED Support for the Amstrad Delta (E3)"
63 depends on LEDS_CLASS
59 depends on MACH_AMS_DELTA 64 depends on MACH_AMS_DELTA
60 help 65 help
61 This option enables support for the LEDs on Amstrad Delta (E3). 66 This option enables support for the LEDs on Amstrad Delta (E3).
62 67
63config LEDS_NET48XX 68config LEDS_NET48XX
64 tristate "LED Support for Soekris net48xx series Error LED" 69 tristate "LED Support for Soekris net48xx series Error LED"
70 depends on LEDS_CLASS
65 depends on SCx200_GPIO 71 depends on SCx200_GPIO
66 help 72 help
67 This option enables support for the Soekris net4801 and net4826 error 73 This option enables support for the Soekris net4801 and net4826 error
@@ -79,18 +85,21 @@ config LEDS_NET5501
79 85
80config LEDS_FSG 86config LEDS_FSG
81 tristate "LED Support for the Freecom FSG-3" 87 tristate "LED Support for the Freecom FSG-3"
88 depends on LEDS_CLASS
82 depends on MACH_FSG 89 depends on MACH_FSG
83 help 90 help
84 This option enables support for the LEDs on the Freecom FSG-3. 91 This option enables support for the LEDs on the Freecom FSG-3.
85 92
86config LEDS_WRAP 93config LEDS_WRAP
87 tristate "LED Support for the WRAP series LEDs" 94 tristate "LED Support for the WRAP series LEDs"
95 depends on LEDS_CLASS
88 depends on SCx200_GPIO 96 depends on SCx200_GPIO
89 help 97 help
90 This option enables support for the PCEngines WRAP programmable LEDs. 98 This option enables support for the PCEngines WRAP programmable LEDs.
91 99
92config LEDS_ALIX2 100config LEDS_ALIX2
93 tristate "LED Support for ALIX.2 and ALIX.3 series" 101 tristate "LED Support for ALIX.2 and ALIX.3 series"
102 depends on LEDS_CLASS
94 depends on X86 && !GPIO_CS5535 && !CS5535_GPIO 103 depends on X86 && !GPIO_CS5535 && !CS5535_GPIO
95 help 104 help
96 This option enables support for the PCEngines ALIX.2 and ALIX.3 LEDs. 105 This option enables support for the PCEngines ALIX.2 and ALIX.3 LEDs.
@@ -98,12 +107,14 @@ config LEDS_ALIX2
98 107
99config LEDS_H1940 108config LEDS_H1940
100 tristate "LED Support for iPAQ H1940 device" 109 tristate "LED Support for iPAQ H1940 device"
110 depends on LEDS_CLASS
101 depends on ARCH_H1940 111 depends on ARCH_H1940
102 help 112 help
103 This option enables support for the LEDs on the h1940. 113 This option enables support for the LEDs on the h1940.
104 114
105config LEDS_COBALT_QUBE 115config LEDS_COBALT_QUBE
106 tristate "LED Support for the Cobalt Qube series front LED" 116 tristate "LED Support for the Cobalt Qube series front LED"
117 depends on LEDS_CLASS
107 depends on MIPS_COBALT 118 depends on MIPS_COBALT
108 help 119 help
109 This option enables support for the front LED on Cobalt Qube series 120 This option enables support for the front LED on Cobalt Qube series
@@ -117,6 +128,7 @@ config LEDS_COBALT_RAQ
117 128
118config LEDS_SUNFIRE 129config LEDS_SUNFIRE
119 tristate "LED support for SunFire servers." 130 tristate "LED support for SunFire servers."
131 depends on LEDS_CLASS
120 depends on SPARC64 132 depends on SPARC64
121 select LEDS_TRIGGERS 133 select LEDS_TRIGGERS
122 help 134 help
@@ -125,6 +137,7 @@ config LEDS_SUNFIRE
125 137
126config LEDS_HP6XX 138config LEDS_HP6XX
127 tristate "LED Support for the HP Jornada 6xx" 139 tristate "LED Support for the HP Jornada 6xx"
140 depends on LEDS_CLASS
128 depends on SH_HP6XX 141 depends on SH_HP6XX
129 help 142 help
130 This option enables LED support for the handheld 143 This option enables LED support for the handheld
@@ -132,6 +145,7 @@ config LEDS_HP6XX
132 145
133config LEDS_PCA9532 146config LEDS_PCA9532
134 tristate "LED driver for PCA9532 dimmer" 147 tristate "LED driver for PCA9532 dimmer"
148 depends on LEDS_CLASS
135 depends on I2C && INPUT && EXPERIMENTAL 149 depends on I2C && INPUT && EXPERIMENTAL
136 help 150 help
137 This option enables support for NXP pca9532 151 This option enables support for NXP pca9532
@@ -140,6 +154,7 @@ config LEDS_PCA9532
140 154
141config LEDS_GPIO 155config LEDS_GPIO
142 tristate "LED Support for GPIO connected LEDs" 156 tristate "LED Support for GPIO connected LEDs"
157 depends on LEDS_CLASS
143 depends on GENERIC_GPIO 158 depends on GENERIC_GPIO
144 help 159 help
145 This option enables support for the LEDs connected to GPIO 160 This option enables support for the LEDs connected to GPIO
@@ -167,6 +182,7 @@ config LEDS_GPIO_OF
167 182
168config LEDS_LP3944 183config LEDS_LP3944
169 tristate "LED Support for N.S. LP3944 (Fun Light) I2C chip" 184 tristate "LED Support for N.S. LP3944 (Fun Light) I2C chip"
185 depends on LEDS_CLASS
170 depends on I2C 186 depends on I2C
171 help 187 help
172 This option enables support for LEDs connected to the National 188 This option enables support for LEDs connected to the National
@@ -176,8 +192,27 @@ config LEDS_LP3944
176 To compile this driver as a module, choose M here: the 192 To compile this driver as a module, choose M here: the
177 module will be called leds-lp3944. 193 module will be called leds-lp3944.
178 194
195config LEDS_LP5521
196 tristate "LED Support for N.S. LP5521 LED driver chip"
197 depends on LEDS_CLASS && I2C
198 help
199 If you say yes here you get support for the National Semiconductor
200 LP5521 LED driver. It is 3 channel chip with programmable engines.
201 Driver provides direct control via LED class and interface for
202 programming the engines.
203
204config LEDS_LP5523
205 tristate "LED Support for N.S. LP5523 LED driver chip"
206 depends on LEDS_CLASS && I2C
207 help
208 If you say yes here you get support for the National Semiconductor
209 LP5523 LED driver. It is 9 channel chip with programmable engines.
210 Driver provides direct control via LED class and interface for
211 programming the engines.
212
179config LEDS_CLEVO_MAIL 213config LEDS_CLEVO_MAIL
180 tristate "Mail LED on Clevo notebook" 214 tristate "Mail LED on Clevo notebook"
215 depends on LEDS_CLASS
181 depends on X86 && SERIO_I8042 && DMI 216 depends on X86 && SERIO_I8042 && DMI
182 help 217 help
183 This driver makes the mail LED accessible from userspace 218 This driver makes the mail LED accessible from userspace
@@ -208,6 +243,7 @@ config LEDS_CLEVO_MAIL
208 243
209config LEDS_PCA955X 244config LEDS_PCA955X
210 tristate "LED Support for PCA955x I2C chips" 245 tristate "LED Support for PCA955x I2C chips"
246 depends on LEDS_CLASS
211 depends on I2C 247 depends on I2C
212 help 248 help
213 This option enables support for LEDs connected to PCA955x 249 This option enables support for LEDs connected to PCA955x
@@ -216,6 +252,7 @@ config LEDS_PCA955X
216 252
217config LEDS_WM831X_STATUS 253config LEDS_WM831X_STATUS
218 tristate "LED support for status LEDs on WM831x PMICs" 254 tristate "LED support for status LEDs on WM831x PMICs"
255 depends on LEDS_CLASS
219 depends on MFD_WM831X 256 depends on MFD_WM831X
220 help 257 help
221 This option enables support for the status LEDs of the WM831x 258 This option enables support for the status LEDs of the WM831x
@@ -223,6 +260,7 @@ config LEDS_WM831X_STATUS
223 260
224config LEDS_WM8350 261config LEDS_WM8350
225 tristate "LED Support for WM8350 AudioPlus PMIC" 262 tristate "LED Support for WM8350 AudioPlus PMIC"
263 depends on LEDS_CLASS
226 depends on MFD_WM8350 264 depends on MFD_WM8350
227 help 265 help
228 This option enables support for LEDs driven by the Wolfson 266 This option enables support for LEDs driven by the Wolfson
@@ -230,6 +268,7 @@ config LEDS_WM8350
230 268
231config LEDS_DA903X 269config LEDS_DA903X
232 tristate "LED Support for DA9030/DA9034 PMIC" 270 tristate "LED Support for DA9030/DA9034 PMIC"
271 depends on LEDS_CLASS
233 depends on PMIC_DA903X 272 depends on PMIC_DA903X
234 help 273 help
235 This option enables support for on-chip LED drivers found 274 This option enables support for on-chip LED drivers found
@@ -237,6 +276,7 @@ config LEDS_DA903X
237 276
238config LEDS_DAC124S085 277config LEDS_DAC124S085
239 tristate "LED Support for DAC124S085 SPI DAC" 278 tristate "LED Support for DAC124S085 SPI DAC"
279 depends on LEDS_CLASS
240 depends on SPI 280 depends on SPI
241 help 281 help
242 This option enables support for DAC124S085 SPI DAC from NatSemi, 282 This option enables support for DAC124S085 SPI DAC from NatSemi,
@@ -244,18 +284,21 @@ config LEDS_DAC124S085
244 284
245config LEDS_PWM 285config LEDS_PWM
246 tristate "PWM driven LED Support" 286 tristate "PWM driven LED Support"
287 depends on LEDS_CLASS
247 depends on HAVE_PWM 288 depends on HAVE_PWM
248 help 289 help
249 This option enables support for pwm driven LEDs 290 This option enables support for pwm driven LEDs
250 291
251config LEDS_REGULATOR 292config LEDS_REGULATOR
252 tristate "REGULATOR driven LED support" 293 tristate "REGULATOR driven LED support"
294 depends on LEDS_CLASS
253 depends on REGULATOR 295 depends on REGULATOR
254 help 296 help
255 This option enables support for regulator driven LEDs. 297 This option enables support for regulator driven LEDs.
256 298
257config LEDS_BD2802 299config LEDS_BD2802
258 tristate "LED driver for BD2802 RGB LED" 300 tristate "LED driver for BD2802 RGB LED"
301 depends on LEDS_CLASS
259 depends on I2C 302 depends on I2C
260 help 303 help
261 This option enables support for BD2802GU RGB LED driver chips 304 This option enables support for BD2802GU RGB LED driver chips
@@ -263,6 +306,7 @@ config LEDS_BD2802
263 306
264config LEDS_INTEL_SS4200 307config LEDS_INTEL_SS4200
265 tristate "LED driver for Intel NAS SS4200 series" 308 tristate "LED driver for Intel NAS SS4200 series"
309 depends on LEDS_CLASS
266 depends on PCI && DMI 310 depends on PCI && DMI
267 help 311 help
268 This option enables support for the Intel SS4200 series of 312 This option enables support for the Intel SS4200 series of
@@ -272,6 +316,7 @@ config LEDS_INTEL_SS4200
272 316
273config LEDS_LT3593 317config LEDS_LT3593
274 tristate "LED driver for LT3593 controllers" 318 tristate "LED driver for LT3593 controllers"
319 depends on LEDS_CLASS
275 depends on GENERIC_GPIO 320 depends on GENERIC_GPIO
276 help 321 help
277 This option enables support for LEDs driven by a Linear Technology 322 This option enables support for LEDs driven by a Linear Technology
@@ -280,6 +325,7 @@ config LEDS_LT3593
280 325
281config LEDS_ADP5520 326config LEDS_ADP5520
282 tristate "LED Support for ADP5520/ADP5501 PMIC" 327 tristate "LED Support for ADP5520/ADP5501 PMIC"
328 depends on LEDS_CLASS
283 depends on PMIC_ADP5520 329 depends on PMIC_ADP5520
284 help 330 help
285 This option enables support for on-chip LED drivers found 331 This option enables support for on-chip LED drivers found
@@ -290,6 +336,7 @@ config LEDS_ADP5520
290 336
291config LEDS_DELL_NETBOOKS 337config LEDS_DELL_NETBOOKS
292 tristate "External LED on Dell Business Netbooks" 338 tristate "External LED on Dell Business Netbooks"
339 depends on LEDS_CLASS
293 depends on X86 && ACPI_WMI 340 depends on X86 && ACPI_WMI
294 help 341 help
295 This adds support for the Latitude 2100 and similar 342 This adds support for the Latitude 2100 and similar
@@ -297,6 +344,7 @@ config LEDS_DELL_NETBOOKS
297 344
298config LEDS_MC13783 345config LEDS_MC13783
299 tristate "LED Support for MC13783 PMIC" 346 tristate "LED Support for MC13783 PMIC"
347 depends on LEDS_CLASS
300 depends on MFD_MC13783 348 depends on MFD_MC13783
301 help 349 help
302 This option enable support for on-chip LED drivers found 350 This option enable support for on-chip LED drivers found
@@ -304,6 +352,7 @@ config LEDS_MC13783
304 352
305config LEDS_NS2 353config LEDS_NS2
306 tristate "LED support for Network Space v2 GPIO LEDs" 354 tristate "LED support for Network Space v2 GPIO LEDs"
355 depends on LEDS_CLASS
307 depends on MACH_NETSPACE_V2 || MACH_INETSPACE_V2 || MACH_NETSPACE_MAX_V2 || D2NET_V2 356 depends on MACH_NETSPACE_V2 || MACH_INETSPACE_V2 || MACH_NETSPACE_MAX_V2 || D2NET_V2
308 default y 357 default y
309 help 358 help
@@ -322,17 +371,17 @@ config LEDS_NETXBIG
322 371
323config LEDS_TRIGGERS 372config LEDS_TRIGGERS
324 bool "LED Trigger support" 373 bool "LED Trigger support"
374 depends on LEDS_CLASS
325 help 375 help
326 This option enables trigger support for the leds class. 376 This option enables trigger support for the leds class.
327 These triggers allow kernel events to drive the LEDs and can 377 These triggers allow kernel events to drive the LEDs and can
328 be configured via sysfs. If unsure, say Y. 378 be configured via sysfs. If unsure, say Y.
329 379
330if LEDS_TRIGGERS
331
332comment "LED Triggers" 380comment "LED Triggers"
333 381
334config LEDS_TRIGGER_TIMER 382config LEDS_TRIGGER_TIMER
335 tristate "LED Timer Trigger" 383 tristate "LED Timer Trigger"
384 depends on LEDS_TRIGGERS
336 help 385 help
337 This allows LEDs to be controlled by a programmable timer 386 This allows LEDs to be controlled by a programmable timer
338 via sysfs. Some LED hardware can be programmed to start 387 via sysfs. Some LED hardware can be programmed to start
@@ -344,12 +393,14 @@ config LEDS_TRIGGER_TIMER
344config LEDS_TRIGGER_IDE_DISK 393config LEDS_TRIGGER_IDE_DISK
345 bool "LED IDE Disk Trigger" 394 bool "LED IDE Disk Trigger"
346 depends on IDE_GD_ATA 395 depends on IDE_GD_ATA
396 depends on LEDS_TRIGGERS
347 help 397 help
348 This allows LEDs to be controlled by IDE disk activity. 398 This allows LEDs to be controlled by IDE disk activity.
349 If unsure, say Y. 399 If unsure, say Y.
350 400
351config LEDS_TRIGGER_HEARTBEAT 401config LEDS_TRIGGER_HEARTBEAT
352 tristate "LED Heartbeat Trigger" 402 tristate "LED Heartbeat Trigger"
403 depends on LEDS_TRIGGERS
353 help 404 help
354 This allows LEDs to be controlled by a CPU load average. 405 This allows LEDs to be controlled by a CPU load average.
355 The flash frequency is a hyperbolic function of the 1-minute 406 The flash frequency is a hyperbolic function of the 1-minute
@@ -358,6 +409,7 @@ config LEDS_TRIGGER_HEARTBEAT
358 409
359config LEDS_TRIGGER_BACKLIGHT 410config LEDS_TRIGGER_BACKLIGHT
360 tristate "LED backlight Trigger" 411 tristate "LED backlight Trigger"
412 depends on LEDS_TRIGGERS
361 help 413 help
362 This allows LEDs to be controlled as a backlight device: they 414 This allows LEDs to be controlled as a backlight device: they
363 turn off and on when the display is blanked and unblanked. 415 turn off and on when the display is blanked and unblanked.
@@ -366,6 +418,7 @@ config LEDS_TRIGGER_BACKLIGHT
366 418
367config LEDS_TRIGGER_GPIO 419config LEDS_TRIGGER_GPIO
368 tristate "LED GPIO Trigger" 420 tristate "LED GPIO Trigger"
421 depends on LEDS_TRIGGERS
369 depends on GPIOLIB 422 depends on GPIOLIB
370 help 423 help
371 This allows LEDs to be controlled by gpio events. It's good 424 This allows LEDs to be controlled by gpio events. It's good
@@ -378,6 +431,7 @@ config LEDS_TRIGGER_GPIO
378 431
379config LEDS_TRIGGER_DEFAULT_ON 432config LEDS_TRIGGER_DEFAULT_ON
380 tristate "LED Default ON Trigger" 433 tristate "LED Default ON Trigger"
434 depends on LEDS_TRIGGERS
381 help 435 help
382 This allows LEDs to be initialised in the ON state. 436 This allows LEDs to be initialised in the ON state.
383 If unsure, say Y. 437 If unsure, say Y.
@@ -385,8 +439,4 @@ config LEDS_TRIGGER_DEFAULT_ON
385comment "iptables trigger is under Netfilter config (LED target)" 439comment "iptables trigger is under Netfilter config (LED target)"
386 depends on LEDS_TRIGGERS 440 depends on LEDS_TRIGGERS
387 441
388endif # LEDS_TRIGGERS
389
390endif # LEDS_CLASS
391
392endif # NEW_LEDS 442endif # NEW_LEDS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 9c96db40ef6d..aae6989ff6b6 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -23,6 +23,8 @@ obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o
23obj-$(CONFIG_LEDS_PCA9532) += leds-pca9532.o 23obj-$(CONFIG_LEDS_PCA9532) += leds-pca9532.o
24obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o 24obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
25obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o 25obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o
26obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o
27obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o
26obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o 28obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
27obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o 29obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
28obj-$(CONFIG_LEDS_FSG) += leds-fsg.o 30obj-$(CONFIG_LEDS_FSG) += leds-fsg.o
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 260660076507..211e21f34bd5 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -81,6 +81,79 @@ static struct device_attribute led_class_attrs[] = {
81 __ATTR_NULL, 81 __ATTR_NULL,
82}; 82};
83 83
84static void led_timer_function(unsigned long data)
85{
86 struct led_classdev *led_cdev = (void *)data;
87 unsigned long brightness;
88 unsigned long delay;
89
90 if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) {
91 led_set_brightness(led_cdev, LED_OFF);
92 return;
93 }
94
95 brightness = led_get_brightness(led_cdev);
96 if (!brightness) {
97 /* Time to switch the LED on. */
98 brightness = led_cdev->blink_brightness;
99 delay = led_cdev->blink_delay_on;
100 } else {
101 /* Store the current brightness value to be able
102 * to restore it when the delay_off period is over.
103 */
104 led_cdev->blink_brightness = brightness;
105 brightness = LED_OFF;
106 delay = led_cdev->blink_delay_off;
107 }
108
109 led_set_brightness(led_cdev, brightness);
110
111 mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay));
112}
113
114static void led_stop_software_blink(struct led_classdev *led_cdev)
115{
116 /* deactivate previous settings */
117 del_timer_sync(&led_cdev->blink_timer);
118 led_cdev->blink_delay_on = 0;
119 led_cdev->blink_delay_off = 0;
120}
121
122static void led_set_software_blink(struct led_classdev *led_cdev,
123 unsigned long delay_on,
124 unsigned long delay_off)
125{
126 int current_brightness;
127
128 current_brightness = led_get_brightness(led_cdev);
129 if (current_brightness)
130 led_cdev->blink_brightness = current_brightness;
131 if (!led_cdev->blink_brightness)
132 led_cdev->blink_brightness = led_cdev->max_brightness;
133
134 if (delay_on == led_cdev->blink_delay_on &&
135 delay_off == led_cdev->blink_delay_off)
136 return;
137
138 led_stop_software_blink(led_cdev);
139
140 led_cdev->blink_delay_on = delay_on;
141 led_cdev->blink_delay_off = delay_off;
142
143 /* never on - don't blink */
144 if (!delay_on)
145 return;
146
147 /* never off - just set to brightness */
148 if (!delay_off) {
149 led_set_brightness(led_cdev, led_cdev->blink_brightness);
150 return;
151 }
152
153 mod_timer(&led_cdev->blink_timer, jiffies + 1);
154}
155
156
84/** 157/**
85 * led_classdev_suspend - suspend an led_classdev. 158 * led_classdev_suspend - suspend an led_classdev.
86 * @led_cdev: the led_classdev to suspend. 159 * @led_cdev: the led_classdev to suspend.
@@ -148,6 +221,10 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
148 221
149 led_update_brightness(led_cdev); 222 led_update_brightness(led_cdev);
150 223
224 init_timer(&led_cdev->blink_timer);
225 led_cdev->blink_timer.function = led_timer_function;
226 led_cdev->blink_timer.data = (unsigned long)led_cdev;
227
151#ifdef CONFIG_LEDS_TRIGGERS 228#ifdef CONFIG_LEDS_TRIGGERS
152 led_trigger_set_default(led_cdev); 229 led_trigger_set_default(led_cdev);
153#endif 230#endif
@@ -157,7 +234,6 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
157 234
158 return 0; 235 return 0;
159} 236}
160
161EXPORT_SYMBOL_GPL(led_classdev_register); 237EXPORT_SYMBOL_GPL(led_classdev_register);
162 238
163/** 239/**
@@ -175,6 +251,9 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
175 up_write(&led_cdev->trigger_lock); 251 up_write(&led_cdev->trigger_lock);
176#endif 252#endif
177 253
254 /* Stop blinking */
255 led_brightness_set(led_cdev, LED_OFF);
256
178 device_unregister(led_cdev->dev); 257 device_unregister(led_cdev->dev);
179 258
180 down_write(&leds_list_lock); 259 down_write(&leds_list_lock);
@@ -183,6 +262,30 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
183} 262}
184EXPORT_SYMBOL_GPL(led_classdev_unregister); 263EXPORT_SYMBOL_GPL(led_classdev_unregister);
185 264
265void led_blink_set(struct led_classdev *led_cdev,
266 unsigned long *delay_on,
267 unsigned long *delay_off)
268{
269 if (led_cdev->blink_set &&
270 led_cdev->blink_set(led_cdev, delay_on, delay_off))
271 return;
272
273 /* blink with 1 Hz as default if nothing specified */
274 if (!*delay_on && !*delay_off)
275 *delay_on = *delay_off = 500;
276
277 led_set_software_blink(led_cdev, *delay_on, *delay_off);
278}
279EXPORT_SYMBOL(led_blink_set);
280
281void led_brightness_set(struct led_classdev *led_cdev,
282 enum led_brightness brightness)
283{
284 led_stop_software_blink(led_cdev);
285 led_cdev->brightness_set(led_cdev, brightness);
286}
287EXPORT_SYMBOL(led_brightness_set);
288
186static int __init leds_init(void) 289static int __init leds_init(void)
187{ 290{
188 leds_class = class_create(THIS_MODULE, "leds"); 291 leds_class = class_create(THIS_MODULE, "leds");
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index f1c00db88b5e..c41eb6180c9c 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -113,7 +113,7 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
113 if (led_cdev->trigger->deactivate) 113 if (led_cdev->trigger->deactivate)
114 led_cdev->trigger->deactivate(led_cdev); 114 led_cdev->trigger->deactivate(led_cdev);
115 led_cdev->trigger = NULL; 115 led_cdev->trigger = NULL;
116 led_set_brightness(led_cdev, LED_OFF); 116 led_brightness_set(led_cdev, LED_OFF);
117 } 117 }
118 if (trigger) { 118 if (trigger) {
119 write_lock_irqsave(&trigger->leddev_list_lock, flags); 119 write_lock_irqsave(&trigger->leddev_list_lock, flags);
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index ea57e05d08f3..4d9fa38d9ff6 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -316,7 +316,7 @@ static struct of_platform_driver of_gpio_leds_driver = {
316 316
317static int __init gpio_led_init(void) 317static int __init gpio_led_init(void)
318{ 318{
319 int ret; 319 int ret = 0;
320 320
321#ifdef CONFIG_LEDS_GPIO_PLATFORM 321#ifdef CONFIG_LEDS_GPIO_PLATFORM
322 ret = platform_driver_register(&gpio_led_driver); 322 ret = platform_driver_register(&gpio_led_driver);
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
new file mode 100644
index 000000000000..33facd0c45d1
--- /dev/null
+++ b/drivers/leds/leds-lp5521.c
@@ -0,0 +1,837 @@
1/*
2 * LP5521 LED chip driver.
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/i2c.h>
26#include <linux/mutex.h>
27#include <linux/gpio.h>
28#include <linux/interrupt.h>
29#include <linux/delay.h>
30#include <linux/ctype.h>
31#include <linux/spinlock.h>
32#include <linux/wait.h>
33#include <linux/leds.h>
34#include <linux/leds-lp5521.h>
35#include <linux/workqueue.h>
36#include <linux/slab.h>
37
38#define LP5521_PROGRAM_LENGTH 32 /* in bytes */
39
40#define LP5521_MAX_LEDS 3 /* Maximum number of LEDs */
41#define LP5521_MAX_ENGINES 3 /* Maximum number of engines */
42
43#define LP5521_ENG_MASK_BASE 0x30 /* 00110000 */
44#define LP5521_ENG_STATUS_MASK 0x07 /* 00000111 */
45
46#define LP5521_CMD_LOAD 0x15 /* 00010101 */
47#define LP5521_CMD_RUN 0x2a /* 00101010 */
48#define LP5521_CMD_DIRECT 0x3f /* 00111111 */
49#define LP5521_CMD_DISABLED 0x00 /* 00000000 */
50
51/* Registers */
52#define LP5521_REG_ENABLE 0x00
53#define LP5521_REG_OP_MODE 0x01
54#define LP5521_REG_R_PWM 0x02
55#define LP5521_REG_G_PWM 0x03
56#define LP5521_REG_B_PWM 0x04
57#define LP5521_REG_R_CURRENT 0x05
58#define LP5521_REG_G_CURRENT 0x06
59#define LP5521_REG_B_CURRENT 0x07
60#define LP5521_REG_CONFIG 0x08
61#define LP5521_REG_R_CHANNEL_PC 0x09
62#define LP5521_REG_G_CHANNEL_PC 0x0A
63#define LP5521_REG_B_CHANNEL_PC 0x0B
64#define LP5521_REG_STATUS 0x0C
65#define LP5521_REG_RESET 0x0D
66#define LP5521_REG_GPO 0x0E
67#define LP5521_REG_R_PROG_MEM 0x10
68#define LP5521_REG_G_PROG_MEM 0x30
69#define LP5521_REG_B_PROG_MEM 0x50
70
71#define LP5521_PROG_MEM_BASE LP5521_REG_R_PROG_MEM
72#define LP5521_PROG_MEM_SIZE 0x20
73
74/* Base register to set LED current */
75#define LP5521_REG_LED_CURRENT_BASE LP5521_REG_R_CURRENT
76
77/* Base register to set the brightness */
78#define LP5521_REG_LED_PWM_BASE LP5521_REG_R_PWM
79
80/* Bits in ENABLE register */
81#define LP5521_MASTER_ENABLE 0x40 /* Chip master enable */
82#define LP5521_LOGARITHMIC_PWM 0x80 /* Logarithmic PWM adjustment */
83#define LP5521_EXEC_RUN 0x2A
84
85/* Bits in CONFIG register */
86#define LP5521_PWM_HF 0x40 /* PWM: 0 = 256Hz, 1 = 558Hz */
87#define LP5521_PWRSAVE_EN 0x20 /* 1 = Power save mode */
88#define LP5521_CP_MODE_OFF 0 /* Charge pump (CP) off */
89#define LP5521_CP_MODE_BYPASS 8 /* CP forced to bypass mode */
90#define LP5521_CP_MODE_1X5 0x10 /* CP forced to 1.5x mode */
91#define LP5521_CP_MODE_AUTO 0x18 /* Automatic mode selection */
92#define LP5521_R_TO_BATT 4 /* R out: 0 = CP, 1 = Vbat */
93#define LP5521_CLK_SRC_EXT 0 /* Ext-clk source (CLK_32K) */
94#define LP5521_CLK_INT 1 /* Internal clock */
95#define LP5521_CLK_AUTO 2 /* Automatic clock selection */
96
97/* Status */
98#define LP5521_EXT_CLK_USED 0x08
99
100struct lp5521_engine {
101 const struct attribute_group *attributes;
102 int id;
103 u8 mode;
104 u8 prog_page;
105 u8 engine_mask;
106};
107
108struct lp5521_led {
109 int id;
110 u8 chan_nr;
111 u8 led_current;
112 u8 max_current;
113 struct led_classdev cdev;
114 struct work_struct brightness_work;
115 u8 brightness;
116};
117
118struct lp5521_chip {
119 struct lp5521_platform_data *pdata;
120 struct mutex lock; /* Serialize control */
121 struct i2c_client *client;
122 struct lp5521_engine engines[LP5521_MAX_ENGINES];
123 struct lp5521_led leds[LP5521_MAX_LEDS];
124 u8 num_channels;
125 u8 num_leds;
126};
127
128static inline struct lp5521_led *cdev_to_led(struct led_classdev *cdev)
129{
130 return container_of(cdev, struct lp5521_led, cdev);
131}
132
133static inline struct lp5521_chip *engine_to_lp5521(struct lp5521_engine *engine)
134{
135 return container_of(engine, struct lp5521_chip,
136 engines[engine->id - 1]);
137}
138
139static inline struct lp5521_chip *led_to_lp5521(struct lp5521_led *led)
140{
141 return container_of(led, struct lp5521_chip,
142 leds[led->id]);
143}
144
145static void lp5521_led_brightness_work(struct work_struct *work);
146
147static inline int lp5521_write(struct i2c_client *client, u8 reg, u8 value)
148{
149 return i2c_smbus_write_byte_data(client, reg, value);
150}
151
152static int lp5521_read(struct i2c_client *client, u8 reg, u8 *buf)
153{
154 s32 ret;
155
156 ret = i2c_smbus_read_byte_data(client, reg);
157 if (ret < 0)
158 return -EIO;
159
160 *buf = ret;
161 return 0;
162}
163
164static int lp5521_set_engine_mode(struct lp5521_engine *engine, u8 mode)
165{
166 struct lp5521_chip *chip = engine_to_lp5521(engine);
167 struct i2c_client *client = chip->client;
168 int ret;
169 u8 engine_state;
170
171 /* Only transition between RUN and DIRECT mode are handled here */
172 if (mode == LP5521_CMD_LOAD)
173 return 0;
174
175 if (mode == LP5521_CMD_DISABLED)
176 mode = LP5521_CMD_DIRECT;
177
178 ret = lp5521_read(client, LP5521_REG_OP_MODE, &engine_state);
179
180 /* set mode only for this engine */
181 engine_state &= ~(engine->engine_mask);
182 mode &= engine->engine_mask;
183 engine_state |= mode;
184 ret |= lp5521_write(client, LP5521_REG_OP_MODE, engine_state);
185
186 return ret;
187}
188
189static int lp5521_load_program(struct lp5521_engine *eng, const u8 *pattern)
190{
191 struct lp5521_chip *chip = engine_to_lp5521(eng);
192 struct i2c_client *client = chip->client;
193 int ret;
194 int addr;
195 u8 mode;
196
197 /* move current engine to direct mode and remember the state */
198 ret = lp5521_set_engine_mode(eng, LP5521_CMD_DIRECT);
199 /* Mode change requires min 500 us delay. 1 - 2 ms with margin */
200 usleep_range(1000, 2000);
201 ret |= lp5521_read(client, LP5521_REG_OP_MODE, &mode);
202
203 /* For loading, all the engines to load mode */
204 lp5521_write(client, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT);
205 /* Mode change requires min 500 us delay. 1 - 2 ms with margin */
206 usleep_range(1000, 2000);
207 lp5521_write(client, LP5521_REG_OP_MODE, LP5521_CMD_LOAD);
208 /* Mode change requires min 500 us delay. 1 - 2 ms with margin */
209 usleep_range(1000, 2000);
210
211 addr = LP5521_PROG_MEM_BASE + eng->prog_page * LP5521_PROG_MEM_SIZE;
212 i2c_smbus_write_i2c_block_data(client,
213 addr,
214 LP5521_PROG_MEM_SIZE,
215 pattern);
216
217 ret |= lp5521_write(client, LP5521_REG_OP_MODE, mode);
218 return ret;
219}
220
221static int lp5521_set_led_current(struct lp5521_chip *chip, int led, u8 curr)
222{
223 return lp5521_write(chip->client,
224 LP5521_REG_LED_CURRENT_BASE + chip->leds[led].chan_nr,
225 curr);
226}
227
228static void lp5521_init_engine(struct lp5521_chip *chip,
229 const struct attribute_group *attr_group)
230{
231 int i;
232 for (i = 0; i < ARRAY_SIZE(chip->engines); i++) {
233 chip->engines[i].id = i + 1;
234 chip->engines[i].engine_mask = LP5521_ENG_MASK_BASE >> (i * 2);
235 chip->engines[i].prog_page = i;
236 chip->engines[i].attributes = &attr_group[i];
237 }
238}
239
240static int lp5521_configure(struct i2c_client *client,
241 const struct attribute_group *attr_group)
242{
243 struct lp5521_chip *chip = i2c_get_clientdata(client);
244 int ret;
245
246 lp5521_init_engine(chip, attr_group);
247
248 /* Set all PWMs to direct control mode */
249 ret = lp5521_write(client, LP5521_REG_OP_MODE, 0x3F);
250
251 /* Enable auto-powersave, set charge pump to auto, red to battery */
252 ret |= lp5521_write(client, LP5521_REG_CONFIG,
253 LP5521_PWRSAVE_EN | LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT);
254
255 /* Initialize all channels PWM to zero -> leds off */
256 ret |= lp5521_write(client, LP5521_REG_R_PWM, 0);
257 ret |= lp5521_write(client, LP5521_REG_G_PWM, 0);
258 ret |= lp5521_write(client, LP5521_REG_B_PWM, 0);
259
260 /* Set engines are set to run state when OP_MODE enables engines */
261 ret |= lp5521_write(client, LP5521_REG_ENABLE,
262 LP5521_MASTER_ENABLE | LP5521_LOGARITHMIC_PWM |
263 LP5521_EXEC_RUN);
264 /* enable takes 500us. 1 - 2 ms leaves some margin */
265 usleep_range(1000, 2000);
266
267 return ret;
268}
269
270static int lp5521_run_selftest(struct lp5521_chip *chip, char *buf)
271{
272 int ret;
273 u8 status;
274
275 ret = lp5521_read(chip->client, LP5521_REG_STATUS, &status);
276 if (ret < 0)
277 return ret;
278
279 /* Check that ext clock is really in use if requested */
280 if (chip->pdata && chip->pdata->clock_mode == LP5521_CLOCK_EXT)
281 if ((status & LP5521_EXT_CLK_USED) == 0)
282 return -EIO;
283 return 0;
284}
285
286static void lp5521_set_brightness(struct led_classdev *cdev,
287 enum led_brightness brightness)
288{
289 struct lp5521_led *led = cdev_to_led(cdev);
290 led->brightness = (u8)brightness;
291 schedule_work(&led->brightness_work);
292}
293
294static void lp5521_led_brightness_work(struct work_struct *work)
295{
296 struct lp5521_led *led = container_of(work,
297 struct lp5521_led,
298 brightness_work);
299 struct lp5521_chip *chip = led_to_lp5521(led);
300 struct i2c_client *client = chip->client;
301
302 mutex_lock(&chip->lock);
303 lp5521_write(client, LP5521_REG_LED_PWM_BASE + led->chan_nr,
304 led->brightness);
305 mutex_unlock(&chip->lock);
306}
307
308/* Detect the chip by setting its ENABLE register and reading it back. */
309static int lp5521_detect(struct i2c_client *client)
310{
311 int ret;
312 u8 buf;
313
314 ret = lp5521_write(client, LP5521_REG_ENABLE,
315 LP5521_MASTER_ENABLE | LP5521_LOGARITHMIC_PWM);
316 if (ret)
317 return ret;
318 /* enable takes 500us. 1 - 2 ms leaves some margin */
319 usleep_range(1000, 2000);
320 ret = lp5521_read(client, LP5521_REG_ENABLE, &buf);
321 if (ret)
322 return ret;
323 if (buf != (LP5521_MASTER_ENABLE | LP5521_LOGARITHMIC_PWM))
324 return -ENODEV;
325
326 return 0;
327}
328
329/* Set engine mode and create appropriate sysfs attributes, if required. */
330static int lp5521_set_mode(struct lp5521_engine *engine, u8 mode)
331{
332 struct lp5521_chip *chip = engine_to_lp5521(engine);
333 struct i2c_client *client = chip->client;
334 struct device *dev = &client->dev;
335 int ret = 0;
336
337 /* if in that mode already do nothing, except for run */
338 if (mode == engine->mode && mode != LP5521_CMD_RUN)
339 return 0;
340
341 if (mode == LP5521_CMD_RUN) {
342 ret = lp5521_set_engine_mode(engine, LP5521_CMD_RUN);
343 } else if (mode == LP5521_CMD_LOAD) {
344 lp5521_set_engine_mode(engine, LP5521_CMD_DISABLED);
345 lp5521_set_engine_mode(engine, LP5521_CMD_LOAD);
346
347 ret = sysfs_create_group(&dev->kobj, engine->attributes);
348 if (ret)
349 return ret;
350 } else if (mode == LP5521_CMD_DISABLED) {
351 lp5521_set_engine_mode(engine, LP5521_CMD_DISABLED);
352 }
353
354 /* remove load attribute from sysfs if not in load mode */
355 if (engine->mode == LP5521_CMD_LOAD && mode != LP5521_CMD_LOAD)
356 sysfs_remove_group(&dev->kobj, engine->attributes);
357
358 engine->mode = mode;
359
360 return ret;
361}
362
363static int lp5521_do_store_load(struct lp5521_engine *engine,
364 const char *buf, size_t len)
365{
366 struct lp5521_chip *chip = engine_to_lp5521(engine);
367 struct i2c_client *client = chip->client;
368 int ret, nrchars, offset = 0, i = 0;
369 char c[3];
370 unsigned cmd;
371 u8 pattern[LP5521_PROGRAM_LENGTH] = {0};
372
373 while ((offset < len - 1) && (i < LP5521_PROGRAM_LENGTH)) {
374 /* separate sscanfs because length is working only for %s */
375 ret = sscanf(buf + offset, "%2s%n ", c, &nrchars);
376 ret = sscanf(c, "%2x", &cmd);
377 if (ret != 1)
378 goto fail;
379 pattern[i] = (u8)cmd;
380
381 offset += nrchars;
382 i++;
383 }
384
385 /* Each instruction is 16bit long. Check that length is even */
386 if (i % 2)
387 goto fail;
388
389 mutex_lock(&chip->lock);
390 ret = lp5521_load_program(engine, pattern);
391 mutex_unlock(&chip->lock);
392
393 if (ret) {
394 dev_err(&client->dev, "failed loading pattern\n");
395 return ret;
396 }
397
398 return len;
399fail:
400 dev_err(&client->dev, "wrong pattern format\n");
401 return -EINVAL;
402}
403
404static ssize_t store_engine_load(struct device *dev,
405 struct device_attribute *attr,
406 const char *buf, size_t len, int nr)
407{
408 struct i2c_client *client = to_i2c_client(dev);
409 struct lp5521_chip *chip = i2c_get_clientdata(client);
410 return lp5521_do_store_load(&chip->engines[nr - 1], buf, len);
411}
412
413#define store_load(nr) \
414static ssize_t store_engine##nr##_load(struct device *dev, \
415 struct device_attribute *attr, \
416 const char *buf, size_t len) \
417{ \
418 return store_engine_load(dev, attr, buf, len, nr); \
419}
420store_load(1)
421store_load(2)
422store_load(3)
423
424static ssize_t show_engine_mode(struct device *dev,
425 struct device_attribute *attr,
426 char *buf, int nr)
427{
428 struct i2c_client *client = to_i2c_client(dev);
429 struct lp5521_chip *chip = i2c_get_clientdata(client);
430 switch (chip->engines[nr - 1].mode) {
431 case LP5521_CMD_RUN:
432 return sprintf(buf, "run\n");
433 case LP5521_CMD_LOAD:
434 return sprintf(buf, "load\n");
435 case LP5521_CMD_DISABLED:
436 return sprintf(buf, "disabled\n");
437 default:
438 return sprintf(buf, "disabled\n");
439 }
440}
441
442#define show_mode(nr) \
443static ssize_t show_engine##nr##_mode(struct device *dev, \
444 struct device_attribute *attr, \
445 char *buf) \
446{ \
447 return show_engine_mode(dev, attr, buf, nr); \
448}
449show_mode(1)
450show_mode(2)
451show_mode(3)
452
453static ssize_t store_engine_mode(struct device *dev,
454 struct device_attribute *attr,
455 const char *buf, size_t len, int nr)
456{
457 struct i2c_client *client = to_i2c_client(dev);
458 struct lp5521_chip *chip = i2c_get_clientdata(client);
459 struct lp5521_engine *engine = &chip->engines[nr - 1];
460 mutex_lock(&chip->lock);
461
462 if (!strncmp(buf, "run", 3))
463 lp5521_set_mode(engine, LP5521_CMD_RUN);
464 else if (!strncmp(buf, "load", 4))
465 lp5521_set_mode(engine, LP5521_CMD_LOAD);
466 else if (!strncmp(buf, "disabled", 8))
467 lp5521_set_mode(engine, LP5521_CMD_DISABLED);
468
469 mutex_unlock(&chip->lock);
470 return len;
471}
472
473#define store_mode(nr) \
474static ssize_t store_engine##nr##_mode(struct device *dev, \
475 struct device_attribute *attr, \
476 const char *buf, size_t len) \
477{ \
478 return store_engine_mode(dev, attr, buf, len, nr); \
479}
480store_mode(1)
481store_mode(2)
482store_mode(3)
483
484static ssize_t show_max_current(struct device *dev,
485 struct device_attribute *attr,
486 char *buf)
487{
488 struct led_classdev *led_cdev = dev_get_drvdata(dev);
489 struct lp5521_led *led = cdev_to_led(led_cdev);
490
491 return sprintf(buf, "%d\n", led->max_current);
492}
493
494static ssize_t show_current(struct device *dev,
495 struct device_attribute *attr,
496 char *buf)
497{
498 struct led_classdev *led_cdev = dev_get_drvdata(dev);
499 struct lp5521_led *led = cdev_to_led(led_cdev);
500
501 return sprintf(buf, "%d\n", led->led_current);
502}
503
504static ssize_t store_current(struct device *dev,
505 struct device_attribute *attr,
506 const char *buf, size_t len)
507{
508 struct led_classdev *led_cdev = dev_get_drvdata(dev);
509 struct lp5521_led *led = cdev_to_led(led_cdev);
510 struct lp5521_chip *chip = led_to_lp5521(led);
511 ssize_t ret;
512 unsigned long curr;
513
514 if (strict_strtoul(buf, 0, &curr))
515 return -EINVAL;
516
517 if (curr > led->max_current)
518 return -EINVAL;
519
520 mutex_lock(&chip->lock);
521 ret = lp5521_set_led_current(chip, led->id, curr);
522 mutex_unlock(&chip->lock);
523
524 if (ret < 0)
525 return ret;
526
527 led->led_current = (u8)curr;
528
529 return len;
530}
531
532static ssize_t lp5521_selftest(struct device *dev,
533 struct device_attribute *attr,
534 char *buf)
535{
536 struct i2c_client *client = to_i2c_client(dev);
537 struct lp5521_chip *chip = i2c_get_clientdata(client);
538 int ret;
539
540 mutex_lock(&chip->lock);
541 ret = lp5521_run_selftest(chip, buf);
542 mutex_unlock(&chip->lock);
543 return sprintf(buf, "%s\n", ret ? "FAIL" : "OK");
544}
545
546/* led class device attributes */
547static DEVICE_ATTR(led_current, S_IRUGO | S_IWUGO, show_current, store_current);
548static DEVICE_ATTR(max_current, S_IRUGO , show_max_current, NULL);
549
550static struct attribute *lp5521_led_attributes[] = {
551 &dev_attr_led_current.attr,
552 &dev_attr_max_current.attr,
553 NULL,
554};
555
556static struct attribute_group lp5521_led_attribute_group = {
557 .attrs = lp5521_led_attributes
558};
559
560/* device attributes */
561static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUGO,
562 show_engine1_mode, store_engine1_mode);
563static DEVICE_ATTR(engine2_mode, S_IRUGO | S_IWUGO,
564 show_engine2_mode, store_engine2_mode);
565static DEVICE_ATTR(engine3_mode, S_IRUGO | S_IWUGO,
566 show_engine3_mode, store_engine3_mode);
567static DEVICE_ATTR(engine1_load, S_IWUGO, NULL, store_engine1_load);
568static DEVICE_ATTR(engine2_load, S_IWUGO, NULL, store_engine2_load);
569static DEVICE_ATTR(engine3_load, S_IWUGO, NULL, store_engine3_load);
570static DEVICE_ATTR(selftest, S_IRUGO, lp5521_selftest, NULL);
571
572static struct attribute *lp5521_attributes[] = {
573 &dev_attr_engine1_mode.attr,
574 &dev_attr_engine2_mode.attr,
575 &dev_attr_engine3_mode.attr,
576 &dev_attr_selftest.attr,
577 NULL
578};
579
580static struct attribute *lp5521_engine1_attributes[] = {
581 &dev_attr_engine1_load.attr,
582 NULL
583};
584
585static struct attribute *lp5521_engine2_attributes[] = {
586 &dev_attr_engine2_load.attr,
587 NULL
588};
589
590static struct attribute *lp5521_engine3_attributes[] = {
591 &dev_attr_engine3_load.attr,
592 NULL
593};
594
595static const struct attribute_group lp5521_group = {
596 .attrs = lp5521_attributes,
597};
598
599static const struct attribute_group lp5521_engine_group[] = {
600 {.attrs = lp5521_engine1_attributes },
601 {.attrs = lp5521_engine2_attributes },
602 {.attrs = lp5521_engine3_attributes },
603};
604
605static int lp5521_register_sysfs(struct i2c_client *client)
606{
607 struct device *dev = &client->dev;
608 return sysfs_create_group(&dev->kobj, &lp5521_group);
609}
610
611static void lp5521_unregister_sysfs(struct i2c_client *client)
612{
613 struct lp5521_chip *chip = i2c_get_clientdata(client);
614 struct device *dev = &client->dev;
615 int i;
616
617 sysfs_remove_group(&dev->kobj, &lp5521_group);
618
619 for (i = 0; i < ARRAY_SIZE(chip->engines); i++) {
620 if (chip->engines[i].mode == LP5521_CMD_LOAD)
621 sysfs_remove_group(&dev->kobj,
622 chip->engines[i].attributes);
623 }
624
625 for (i = 0; i < chip->num_leds; i++)
626 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
627 &lp5521_led_attribute_group);
628}
629
630static int __init lp5521_init_led(struct lp5521_led *led,
631 struct i2c_client *client,
632 int chan, struct lp5521_platform_data *pdata)
633{
634 struct device *dev = &client->dev;
635 char name[32];
636 int res;
637
638 if (chan >= LP5521_MAX_LEDS)
639 return -EINVAL;
640
641 if (pdata->led_config[chan].led_current == 0)
642 return 0;
643
644 led->led_current = pdata->led_config[chan].led_current;
645 led->max_current = pdata->led_config[chan].max_current;
646 led->chan_nr = pdata->led_config[chan].chan_nr;
647
648 if (led->chan_nr >= LP5521_MAX_LEDS) {
649 dev_err(dev, "Use channel numbers between 0 and %d\n",
650 LP5521_MAX_LEDS - 1);
651 return -EINVAL;
652 }
653
654 snprintf(name, sizeof(name), "%s:channel%d", client->name, chan);
655 led->cdev.brightness_set = lp5521_set_brightness;
656 led->cdev.name = name;
657 res = led_classdev_register(dev, &led->cdev);
658 if (res < 0) {
659 dev_err(dev, "couldn't register led on channel %d\n", chan);
660 return res;
661 }
662
663 res = sysfs_create_group(&led->cdev.dev->kobj,
664 &lp5521_led_attribute_group);
665 if (res < 0) {
666 dev_err(dev, "couldn't register current attribute\n");
667 led_classdev_unregister(&led->cdev);
668 return res;
669 }
670 return 0;
671}
672
673static int lp5521_probe(struct i2c_client *client,
674 const struct i2c_device_id *id)
675{
676 struct lp5521_chip *chip;
677 struct lp5521_platform_data *pdata;
678 int ret, i, led;
679
680 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
681 if (!chip)
682 return -ENOMEM;
683
684 i2c_set_clientdata(client, chip);
685 chip->client = client;
686
687 pdata = client->dev.platform_data;
688
689 if (!pdata) {
690 dev_err(&client->dev, "no platform data\n");
691 ret = -EINVAL;
692 goto fail1;
693 }
694
695 mutex_init(&chip->lock);
696
697 chip->pdata = pdata;
698
699 if (pdata->setup_resources) {
700 ret = pdata->setup_resources();
701 if (ret < 0)
702 goto fail1;
703 }
704
705 if (pdata->enable) {
706 pdata->enable(0);
707 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
708 pdata->enable(1);
709 usleep_range(1000, 2000); /* 500us abs min. */
710 }
711
712 lp5521_write(client, LP5521_REG_RESET, 0xff);
713 usleep_range(10000, 20000); /*
714 * Exact value is not available. 10 - 20ms
715 * appears to be enough for reset.
716 */
717 ret = lp5521_detect(client);
718
719 if (ret) {
720 dev_err(&client->dev, "Chip not found\n");
721 goto fail2;
722 }
723
724 dev_info(&client->dev, "%s programmable led chip found\n", id->name);
725
726 ret = lp5521_configure(client, lp5521_engine_group);
727 if (ret < 0) {
728 dev_err(&client->dev, "error configuring chip\n");
729 goto fail2;
730 }
731
732 /* Initialize leds */
733 chip->num_channels = pdata->num_channels;
734 chip->num_leds = 0;
735 led = 0;
736 for (i = 0; i < pdata->num_channels; i++) {
737 /* Do not initialize channels that are not connected */
738 if (pdata->led_config[i].led_current == 0)
739 continue;
740
741 ret = lp5521_init_led(&chip->leds[led], client, i, pdata);
742 if (ret) {
743 dev_err(&client->dev, "error initializing leds\n");
744 goto fail3;
745 }
746 chip->num_leds++;
747
748 chip->leds[led].id = led;
749 /* Set initial LED current */
750 lp5521_set_led_current(chip, led,
751 chip->leds[led].led_current);
752
753 INIT_WORK(&(chip->leds[led].brightness_work),
754 lp5521_led_brightness_work);
755
756 led++;
757 }
758
759 ret = lp5521_register_sysfs(client);
760 if (ret) {
761 dev_err(&client->dev, "registering sysfs failed\n");
762 goto fail3;
763 }
764 return ret;
765fail3:
766 for (i = 0; i < chip->num_leds; i++) {
767 led_classdev_unregister(&chip->leds[i].cdev);
768 cancel_work_sync(&chip->leds[i].brightness_work);
769 }
770fail2:
771 if (pdata->enable)
772 pdata->enable(0);
773 if (pdata->release_resources)
774 pdata->release_resources();
775fail1:
776 kfree(chip);
777 return ret;
778}
779
780static int lp5521_remove(struct i2c_client *client)
781{
782 struct lp5521_chip *chip = i2c_get_clientdata(client);
783 int i;
784
785 lp5521_unregister_sysfs(client);
786
787 for (i = 0; i < chip->num_leds; i++) {
788 led_classdev_unregister(&chip->leds[i].cdev);
789 cancel_work_sync(&chip->leds[i].brightness_work);
790 }
791
792 if (chip->pdata->enable)
793 chip->pdata->enable(0);
794 if (chip->pdata->release_resources)
795 chip->pdata->release_resources();
796 kfree(chip);
797 return 0;
798}
799
800static const struct i2c_device_id lp5521_id[] = {
801 { "lp5521", 0 }, /* Three channel chip */
802 { }
803};
804MODULE_DEVICE_TABLE(i2c, lp5521_id);
805
806static struct i2c_driver lp5521_driver = {
807 .driver = {
808 .name = "lp5521",
809 },
810 .probe = lp5521_probe,
811 .remove = lp5521_remove,
812 .id_table = lp5521_id,
813};
814
815static int __init lp5521_init(void)
816{
817 int ret;
818
819 ret = i2c_add_driver(&lp5521_driver);
820
821 if (ret < 0)
822 printk(KERN_ALERT "Adding lp5521 driver failed\n");
823
824 return ret;
825}
826
827static void __exit lp5521_exit(void)
828{
829 i2c_del_driver(&lp5521_driver);
830}
831
832module_init(lp5521_init);
833module_exit(lp5521_exit);
834
835MODULE_AUTHOR("Mathias Nyman, Yuri Zaporozhets, Samu Onkalo");
836MODULE_DESCRIPTION("LP5521 LED engine");
837MODULE_LICENSE("GPL v2");
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
new file mode 100644
index 000000000000..0cc4ead2fd8b
--- /dev/null
+++ b/drivers/leds/leds-lp5523.c
@@ -0,0 +1,1069 @@
1/*
2 * lp5523.c - LP5523 LED Driver
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/i2c.h>
26#include <linux/mutex.h>
27#include <linux/gpio.h>
28#include <linux/interrupt.h>
29#include <linux/delay.h>
30#include <linux/ctype.h>
31#include <linux/spinlock.h>
32#include <linux/wait.h>
33#include <linux/leds.h>
34#include <linux/leds-lp5523.h>
35#include <linux/workqueue.h>
36#include <linux/slab.h>
37
38#define LP5523_REG_ENABLE 0x00
39#define LP5523_REG_OP_MODE 0x01
40#define LP5523_REG_RATIOMETRIC_MSB 0x02
41#define LP5523_REG_RATIOMETRIC_LSB 0x03
42#define LP5523_REG_ENABLE_LEDS_MSB 0x04
43#define LP5523_REG_ENABLE_LEDS_LSB 0x05
44#define LP5523_REG_LED_CNTRL_BASE 0x06
45#define LP5523_REG_LED_PWM_BASE 0x16
46#define LP5523_REG_LED_CURRENT_BASE 0x26
47#define LP5523_REG_CONFIG 0x36
48#define LP5523_REG_CHANNEL1_PC 0x37
49#define LP5523_REG_CHANNEL2_PC 0x38
50#define LP5523_REG_CHANNEL3_PC 0x39
51#define LP5523_REG_STATUS 0x3a
52#define LP5523_REG_GPO 0x3b
53#define LP5523_REG_VARIABLE 0x3c
54#define LP5523_REG_RESET 0x3d
55#define LP5523_REG_TEMP_CTRL 0x3e
56#define LP5523_REG_TEMP_READ 0x3f
57#define LP5523_REG_TEMP_WRITE 0x40
58#define LP5523_REG_LED_TEST_CTRL 0x41
59#define LP5523_REG_LED_TEST_ADC 0x42
60#define LP5523_REG_ENG1_VARIABLE 0x45
61#define LP5523_REG_ENG2_VARIABLE 0x46
62#define LP5523_REG_ENG3_VARIABLE 0x47
63#define LP5523_REG_MASTER_FADER1 0x48
64#define LP5523_REG_MASTER_FADER2 0x49
65#define LP5523_REG_MASTER_FADER3 0x4a
66#define LP5523_REG_CH1_PROG_START 0x4c
67#define LP5523_REG_CH2_PROG_START 0x4d
68#define LP5523_REG_CH3_PROG_START 0x4e
69#define LP5523_REG_PROG_PAGE_SEL 0x4f
70#define LP5523_REG_PROG_MEM 0x50
71
72#define LP5523_CMD_LOAD 0x15 /* 00010101 */
73#define LP5523_CMD_RUN 0x2a /* 00101010 */
74#define LP5523_CMD_DISABLED 0x00 /* 00000000 */
75
76#define LP5523_ENABLE 0x40
77#define LP5523_AUTO_INC 0x40
78#define LP5523_PWR_SAVE 0x20
79#define LP5523_PWM_PWR_SAVE 0x04
80#define LP5523_CP_1 0x08
81#define LP5523_CP_1_5 0x10
82#define LP5523_CP_AUTO 0x18
83#define LP5523_INT_CLK 0x01
84#define LP5523_AUTO_CLK 0x02
85#define LP5523_EN_LEDTEST 0x80
86#define LP5523_LEDTEST_DONE 0x80
87
88#define LP5523_DEFAULT_CURRENT 50 /* microAmps */
89#define LP5523_PROGRAM_LENGTH 32 /* in bytes */
90#define LP5523_PROGRAM_PAGES 6
91#define LP5523_ADC_SHORTCIRC_LIM 80
92
93#define LP5523_LEDS 9
94#define LP5523_ENGINES 3
95
96#define LP5523_ENG_MASK_BASE 0x30 /* 00110000 */
97
98#define LP5523_ENG_STATUS_MASK 0x07 /* 00000111 */
99
100#define LP5523_IRQ_FLAGS IRQF_TRIGGER_FALLING
101
102#define LP5523_EXT_CLK_USED 0x08
103
104#define LED_ACTIVE(mux, led) (!!(mux & (0x0001 << led)))
105#define SHIFT_MASK(id) (((id) - 1) * 2)
106
107struct lp5523_engine {
108 const struct attribute_group *attributes;
109 int id;
110 u8 mode;
111 u8 prog_page;
112 u8 mux_page;
113 u16 led_mux;
114 u8 engine_mask;
115};
116
117struct lp5523_led {
118 int id;
119 u8 chan_nr;
120 u8 led_current;
121 u8 max_current;
122 struct led_classdev cdev;
123 struct work_struct brightness_work;
124 u8 brightness;
125};
126
127struct lp5523_chip {
128 struct mutex lock; /* Serialize control */
129 struct i2c_client *client;
130 struct lp5523_engine engines[LP5523_ENGINES];
131 struct lp5523_led leds[LP5523_LEDS];
132 struct lp5523_platform_data *pdata;
133 u8 num_channels;
134 u8 num_leds;
135};
136
137static inline struct lp5523_led *cdev_to_led(struct led_classdev *cdev)
138{
139 return container_of(cdev, struct lp5523_led, cdev);
140}
141
142static inline struct lp5523_chip *engine_to_lp5523(struct lp5523_engine *engine)
143{
144 return container_of(engine, struct lp5523_chip,
145 engines[engine->id - 1]);
146}
147
148static inline struct lp5523_chip *led_to_lp5523(struct lp5523_led *led)
149{
150 return container_of(led, struct lp5523_chip,
151 leds[led->id]);
152}
153
154static int lp5523_set_mode(struct lp5523_engine *engine, u8 mode);
155static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode);
156static int lp5523_load_program(struct lp5523_engine *engine, u8 *pattern);
157
158static void lp5523_led_brightness_work(struct work_struct *work);
159
160static int lp5523_write(struct i2c_client *client, u8 reg, u8 value)
161{
162 return i2c_smbus_write_byte_data(client, reg, value);
163}
164
165static int lp5523_read(struct i2c_client *client, u8 reg, u8 *buf)
166{
167 s32 ret = i2c_smbus_read_byte_data(client, reg);
168
169 if (ret < 0)
170 return -EIO;
171
172 *buf = ret;
173 return 0;
174}
175
176static int lp5523_detect(struct i2c_client *client)
177{
178 int ret;
179 u8 buf;
180
181 ret = lp5523_write(client, LP5523_REG_ENABLE, 0x40);
182 if (ret)
183 return ret;
184 ret = lp5523_read(client, LP5523_REG_ENABLE, &buf);
185 if (ret)
186 return ret;
187 if (buf == 0x40)
188 return 0;
189 else
190 return -ENODEV;
191}
192
193static int lp5523_configure(struct i2c_client *client)
194{
195 struct lp5523_chip *chip = i2c_get_clientdata(client);
196 int ret = 0;
197 u8 status;
198
199 /* one pattern per engine setting led mux start and stop addresses */
200 u8 pattern[][LP5523_PROGRAM_LENGTH] = {
201 { 0x9c, 0x30, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0},
202 { 0x9c, 0x40, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0},
203 { 0x9c, 0x50, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0},
204 };
205
206 ret |= lp5523_write(client, LP5523_REG_ENABLE, LP5523_ENABLE);
207 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */
208 usleep_range(1000, 2000);
209
210 ret |= lp5523_write(client, LP5523_REG_CONFIG,
211 LP5523_AUTO_INC | LP5523_PWR_SAVE |
212 LP5523_CP_AUTO | LP5523_AUTO_CLK |
213 LP5523_PWM_PWR_SAVE);
214
215 /* turn on all leds */
216 ret |= lp5523_write(client, LP5523_REG_ENABLE_LEDS_MSB, 0x01);
217 ret |= lp5523_write(client, LP5523_REG_ENABLE_LEDS_LSB, 0xff);
218
219 /* hardcode 32 bytes of memory for each engine from program memory */
220 ret |= lp5523_write(client, LP5523_REG_CH1_PROG_START, 0x00);
221 ret |= lp5523_write(client, LP5523_REG_CH2_PROG_START, 0x10);
222 ret |= lp5523_write(client, LP5523_REG_CH3_PROG_START, 0x20);
223
224 /* write led mux address space for each channel */
225 ret |= lp5523_load_program(&chip->engines[0], pattern[0]);
226 ret |= lp5523_load_program(&chip->engines[1], pattern[1]);
227 ret |= lp5523_load_program(&chip->engines[2], pattern[2]);
228
229 if (ret) {
230 dev_err(&client->dev, "could not load mux programs\n");
231 return -1;
232 }
233
234 /* set all engines exec state and mode to run 00101010 */
235 ret |= lp5523_write(client, LP5523_REG_ENABLE,
236 (LP5523_CMD_RUN | LP5523_ENABLE));
237
238 ret |= lp5523_write(client, LP5523_REG_OP_MODE, LP5523_CMD_RUN);
239
240 if (ret) {
241 dev_err(&client->dev, "could not start mux programs\n");
242 return -1;
243 }
244
245 /* Let the programs run for couple of ms and check the engine status */
246 usleep_range(3000, 6000);
247 lp5523_read(client, LP5523_REG_STATUS, &status);
248 status &= LP5523_ENG_STATUS_MASK;
249
250 if (status == LP5523_ENG_STATUS_MASK) {
251 dev_dbg(&client->dev, "all engines configured\n");
252 } else {
253 dev_info(&client->dev, "status == %x\n", status);
254 dev_err(&client->dev, "cound not configure LED engine\n");
255 return -1;
256 }
257
258 dev_info(&client->dev, "disabling engines\n");
259
260 ret |= lp5523_write(client, LP5523_REG_OP_MODE, LP5523_CMD_DISABLED);
261
262 return ret;
263}
264
265static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode)
266{
267 struct lp5523_chip *chip = engine_to_lp5523(engine);
268 struct i2c_client *client = chip->client;
269 int ret;
270 u8 engine_state;
271
272 ret = lp5523_read(client, LP5523_REG_OP_MODE, &engine_state);
273 if (ret)
274 goto fail;
275
276 engine_state &= ~(engine->engine_mask);
277
278 /* set mode only for this engine */
279 mode &= engine->engine_mask;
280
281 engine_state |= mode;
282
283 ret |= lp5523_write(client, LP5523_REG_OP_MODE, engine_state);
284fail:
285 return ret;
286}
287
288static int lp5523_load_mux(struct lp5523_engine *engine, u16 mux)
289{
290 struct lp5523_chip *chip = engine_to_lp5523(engine);
291 struct i2c_client *client = chip->client;
292 int ret = 0;
293
294 ret |= lp5523_set_engine_mode(engine, LP5523_CMD_LOAD);
295
296 ret |= lp5523_write(client, LP5523_REG_PROG_PAGE_SEL, engine->mux_page);
297 ret |= lp5523_write(client, LP5523_REG_PROG_MEM,
298 (u8)(mux >> 8));
299 ret |= lp5523_write(client, LP5523_REG_PROG_MEM + 1, (u8)(mux));
300 engine->led_mux = mux;
301
302 return ret;
303}
304
305static int lp5523_load_program(struct lp5523_engine *engine, u8 *pattern)
306{
307 struct lp5523_chip *chip = engine_to_lp5523(engine);
308 struct i2c_client *client = chip->client;
309
310 int ret = 0;
311
312 ret |= lp5523_set_engine_mode(engine, LP5523_CMD_LOAD);
313
314 ret |= lp5523_write(client, LP5523_REG_PROG_PAGE_SEL,
315 engine->prog_page);
316 ret |= i2c_smbus_write_i2c_block_data(client, LP5523_REG_PROG_MEM,
317 LP5523_PROGRAM_LENGTH, pattern);
318
319 return ret;
320}
321
322static int lp5523_run_program(struct lp5523_engine *engine)
323{
324 struct lp5523_chip *chip = engine_to_lp5523(engine);
325 struct i2c_client *client = chip->client;
326 int ret;
327
328 ret = lp5523_write(client, LP5523_REG_ENABLE,
329 LP5523_CMD_RUN | LP5523_ENABLE);
330 if (ret)
331 goto fail;
332
333 ret = lp5523_set_engine_mode(engine, LP5523_CMD_RUN);
334fail:
335 return ret;
336}
337
338static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len)
339{
340 int i;
341 u16 tmp_mux = 0;
342 len = len < LP5523_LEDS ? len : LP5523_LEDS;
343 for (i = 0; i < len; i++) {
344 switch (buf[i]) {
345 case '1':
346 tmp_mux |= (1 << i);
347 break;
348 case '0':
349 break;
350 case '\n':
351 i = len;
352 break;
353 default:
354 return -1;
355 }
356 }
357 *mux = tmp_mux;
358
359 return 0;
360}
361
362static void lp5523_mux_to_array(u16 led_mux, char *array)
363{
364 int i, pos = 0;
365 for (i = 0; i < LP5523_LEDS; i++)
366 pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i));
367
368 array[pos] = '\0';
369}
370
371/*--------------------------------------------------------------*/
372/* Sysfs interface */
373/*--------------------------------------------------------------*/
374
375static ssize_t show_engine_leds(struct device *dev,
376 struct device_attribute *attr,
377 char *buf, int nr)
378{
379 struct i2c_client *client = to_i2c_client(dev);
380 struct lp5523_chip *chip = i2c_get_clientdata(client);
381 char mux[LP5523_LEDS + 1];
382
383 lp5523_mux_to_array(chip->engines[nr - 1].led_mux, mux);
384
385 return sprintf(buf, "%s\n", mux);
386}
387
388#define show_leds(nr) \
389static ssize_t show_engine##nr##_leds(struct device *dev, \
390 struct device_attribute *attr, \
391 char *buf) \
392{ \
393 return show_engine_leds(dev, attr, buf, nr); \
394}
395show_leds(1)
396show_leds(2)
397show_leds(3)
398
399static ssize_t store_engine_leds(struct device *dev,
400 struct device_attribute *attr,
401 const char *buf, size_t len, int nr)
402{
403 struct i2c_client *client = to_i2c_client(dev);
404 struct lp5523_chip *chip = i2c_get_clientdata(client);
405 u16 mux = 0;
406
407 if (lp5523_mux_parse(buf, &mux, len))
408 return -EINVAL;
409
410 if (lp5523_load_mux(&chip->engines[nr - 1], mux))
411 return -EINVAL;
412
413 return len;
414}
415
416#define store_leds(nr) \
417static ssize_t store_engine##nr##_leds(struct device *dev, \
418 struct device_attribute *attr, \
419 const char *buf, size_t len) \
420{ \
421 return store_engine_leds(dev, attr, buf, len, nr); \
422}
423store_leds(1)
424store_leds(2)
425store_leds(3)
426
427static ssize_t lp5523_selftest(struct device *dev,
428 struct device_attribute *attr,
429 char *buf)
430{
431 struct i2c_client *client = to_i2c_client(dev);
432 struct lp5523_chip *chip = i2c_get_clientdata(client);
433 int i, ret, pos = 0;
434 int led = 0;
435 u8 status, adc, vdd;
436
437 mutex_lock(&chip->lock);
438
439 ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
440 if (ret < 0)
441 goto fail;
442
443 /* Check that ext clock is really in use if requested */
444 if ((chip->pdata) && (chip->pdata->clock_mode == LP5523_CLOCK_EXT))
445 if ((status & LP5523_EXT_CLK_USED) == 0)
446 goto fail;
447
448 /* Measure VDD (i.e. VBAT) first (channel 16 corresponds to VDD) */
449 lp5523_write(chip->client, LP5523_REG_LED_TEST_CTRL,
450 LP5523_EN_LEDTEST | 16);
451 usleep_range(3000, 6000); /* ADC conversion time is typically 2.7 ms */
452 ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
453 if (!(status & LP5523_LEDTEST_DONE))
454 usleep_range(3000, 6000); /* Was not ready. Wait little bit */
455
456 ret |= lp5523_read(chip->client, LP5523_REG_LED_TEST_ADC, &vdd);
457 vdd--; /* There may be some fluctuation in measurement */
458
459 for (i = 0; i < LP5523_LEDS; i++) {
460 /* Skip non-existing channels */
461 if (chip->pdata->led_config[i].led_current == 0)
462 continue;
463
464 /* Set default current */
465 lp5523_write(chip->client,
466 LP5523_REG_LED_CURRENT_BASE + i,
467 chip->pdata->led_config[i].led_current);
468
469 lp5523_write(chip->client, LP5523_REG_LED_PWM_BASE + i, 0xff);
470 /* let current stabilize 2 - 4ms before measurements start */
471 usleep_range(2000, 4000);
472 lp5523_write(chip->client,
473 LP5523_REG_LED_TEST_CTRL,
474 LP5523_EN_LEDTEST | i);
475 /* ADC conversion time is 2.7 ms typically */
476 usleep_range(3000, 6000);
477 ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
478 if (!(status & LP5523_LEDTEST_DONE))
479 usleep_range(3000, 6000);/* Was not ready. Wait. */
480 ret |= lp5523_read(chip->client, LP5523_REG_LED_TEST_ADC, &adc);
481
482 if (adc >= vdd || adc < LP5523_ADC_SHORTCIRC_LIM)
483 pos += sprintf(buf + pos, "LED %d FAIL\n", i);
484
485 lp5523_write(chip->client, LP5523_REG_LED_PWM_BASE + i, 0x00);
486
487 /* Restore current */
488 lp5523_write(chip->client,
489 LP5523_REG_LED_CURRENT_BASE + i,
490 chip->leds[led].led_current);
491 led++;
492 }
493 if (pos == 0)
494 pos = sprintf(buf, "OK\n");
495 goto release_lock;
496fail:
497 pos = sprintf(buf, "FAIL\n");
498
499release_lock:
500 mutex_unlock(&chip->lock);
501
502 return pos;
503}
504
505static void lp5523_set_brightness(struct led_classdev *cdev,
506 enum led_brightness brightness)
507{
508 struct lp5523_led *led = cdev_to_led(cdev);
509
510 led->brightness = (u8)brightness;
511
512 schedule_work(&led->brightness_work);
513}
514
515static void lp5523_led_brightness_work(struct work_struct *work)
516{
517 struct lp5523_led *led = container_of(work,
518 struct lp5523_led,
519 brightness_work);
520 struct lp5523_chip *chip = led_to_lp5523(led);
521 struct i2c_client *client = chip->client;
522
523 mutex_lock(&chip->lock);
524
525 lp5523_write(client, LP5523_REG_LED_PWM_BASE + led->chan_nr,
526 led->brightness);
527
528 mutex_unlock(&chip->lock);
529}
530
531static int lp5523_do_store_load(struct lp5523_engine *engine,
532 const char *buf, size_t len)
533{
534 struct lp5523_chip *chip = engine_to_lp5523(engine);
535 struct i2c_client *client = chip->client;
536 int ret, nrchars, offset = 0, i = 0;
537 char c[3];
538 unsigned cmd;
539 u8 pattern[LP5523_PROGRAM_LENGTH] = {0};
540
541 while ((offset < len - 1) && (i < LP5523_PROGRAM_LENGTH)) {
542 /* separate sscanfs because length is working only for %s */
543 ret = sscanf(buf + offset, "%2s%n ", c, &nrchars);
544 ret = sscanf(c, "%2x", &cmd);
545 if (ret != 1)
546 goto fail;
547 pattern[i] = (u8)cmd;
548
549 offset += nrchars;
550 i++;
551 }
552
553 /* Each instruction is 16bit long. Check that length is even */
554 if (i % 2)
555 goto fail;
556
557 mutex_lock(&chip->lock);
558
559 ret = lp5523_load_program(engine, pattern);
560 mutex_unlock(&chip->lock);
561
562 if (ret) {
563 dev_err(&client->dev, "failed loading pattern\n");
564 return ret;
565 }
566
567 return len;
568fail:
569 dev_err(&client->dev, "wrong pattern format\n");
570 return -EINVAL;
571}
572
573static ssize_t store_engine_load(struct device *dev,
574 struct device_attribute *attr,
575 const char *buf, size_t len, int nr)
576{
577 struct i2c_client *client = to_i2c_client(dev);
578 struct lp5523_chip *chip = i2c_get_clientdata(client);
579 return lp5523_do_store_load(&chip->engines[nr - 1], buf, len);
580}
581
582#define store_load(nr) \
583static ssize_t store_engine##nr##_load(struct device *dev, \
584 struct device_attribute *attr, \
585 const char *buf, size_t len) \
586{ \
587 return store_engine_load(dev, attr, buf, len, nr); \
588}
589store_load(1)
590store_load(2)
591store_load(3)
592
593static ssize_t show_engine_mode(struct device *dev,
594 struct device_attribute *attr,
595 char *buf, int nr)
596{
597 struct i2c_client *client = to_i2c_client(dev);
598 struct lp5523_chip *chip = i2c_get_clientdata(client);
599 switch (chip->engines[nr - 1].mode) {
600 case LP5523_CMD_RUN:
601 return sprintf(buf, "run\n");
602 case LP5523_CMD_LOAD:
603 return sprintf(buf, "load\n");
604 case LP5523_CMD_DISABLED:
605 return sprintf(buf, "disabled\n");
606 default:
607 return sprintf(buf, "disabled\n");
608 }
609}
610
611#define show_mode(nr) \
612static ssize_t show_engine##nr##_mode(struct device *dev, \
613 struct device_attribute *attr, \
614 char *buf) \
615{ \
616 return show_engine_mode(dev, attr, buf, nr); \
617}
618show_mode(1)
619show_mode(2)
620show_mode(3)
621
622static ssize_t store_engine_mode(struct device *dev,
623 struct device_attribute *attr,
624 const char *buf, size_t len, int nr)
625{
626 struct i2c_client *client = to_i2c_client(dev);
627 struct lp5523_chip *chip = i2c_get_clientdata(client);
628 struct lp5523_engine *engine = &chip->engines[nr - 1];
629 mutex_lock(&chip->lock);
630
631 if (!strncmp(buf, "run", 3))
632 lp5523_set_mode(engine, LP5523_CMD_RUN);
633 else if (!strncmp(buf, "load", 4))
634 lp5523_set_mode(engine, LP5523_CMD_LOAD);
635 else if (!strncmp(buf, "disabled", 8))
636 lp5523_set_mode(engine, LP5523_CMD_DISABLED);
637
638 mutex_unlock(&chip->lock);
639 return len;
640}
641
642#define store_mode(nr) \
643static ssize_t store_engine##nr##_mode(struct device *dev, \
644 struct device_attribute *attr, \
645 const char *buf, size_t len) \
646{ \
647 return store_engine_mode(dev, attr, buf, len, nr); \
648}
649store_mode(1)
650store_mode(2)
651store_mode(3)
652
653static ssize_t show_max_current(struct device *dev,
654 struct device_attribute *attr,
655 char *buf)
656{
657 struct led_classdev *led_cdev = dev_get_drvdata(dev);
658 struct lp5523_led *led = cdev_to_led(led_cdev);
659
660 return sprintf(buf, "%d\n", led->max_current);
661}
662
663static ssize_t show_current(struct device *dev,
664 struct device_attribute *attr,
665 char *buf)
666{
667 struct led_classdev *led_cdev = dev_get_drvdata(dev);
668 struct lp5523_led *led = cdev_to_led(led_cdev);
669
670 return sprintf(buf, "%d\n", led->led_current);
671}
672
673static ssize_t store_current(struct device *dev,
674 struct device_attribute *attr,
675 const char *buf, size_t len)
676{
677 struct led_classdev *led_cdev = dev_get_drvdata(dev);
678 struct lp5523_led *led = cdev_to_led(led_cdev);
679 struct lp5523_chip *chip = led_to_lp5523(led);
680 ssize_t ret;
681 unsigned long curr;
682
683 if (strict_strtoul(buf, 0, &curr))
684 return -EINVAL;
685
686 if (curr > led->max_current)
687 return -EINVAL;
688
689 mutex_lock(&chip->lock);
690 ret = lp5523_write(chip->client,
691 LP5523_REG_LED_CURRENT_BASE + led->chan_nr,
692 (u8)curr);
693 mutex_unlock(&chip->lock);
694
695 if (ret < 0)
696 return ret;
697
698 led->led_current = (u8)curr;
699
700 return len;
701}
702
703/* led class device attributes */
704static DEVICE_ATTR(led_current, S_IRUGO | S_IWUGO, show_current, store_current);
705static DEVICE_ATTR(max_current, S_IRUGO , show_max_current, NULL);
706
707static struct attribute *lp5523_led_attributes[] = {
708 &dev_attr_led_current.attr,
709 &dev_attr_max_current.attr,
710 NULL,
711};
712
713static struct attribute_group lp5523_led_attribute_group = {
714 .attrs = lp5523_led_attributes
715};
716
717/* device attributes */
718static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUGO,
719 show_engine1_mode, store_engine1_mode);
720static DEVICE_ATTR(engine2_mode, S_IRUGO | S_IWUGO,
721 show_engine2_mode, store_engine2_mode);
722static DEVICE_ATTR(engine3_mode, S_IRUGO | S_IWUGO,
723 show_engine3_mode, store_engine3_mode);
724static DEVICE_ATTR(engine1_leds, S_IRUGO | S_IWUGO,
725 show_engine1_leds, store_engine1_leds);
726static DEVICE_ATTR(engine2_leds, S_IRUGO | S_IWUGO,
727 show_engine2_leds, store_engine2_leds);
728static DEVICE_ATTR(engine3_leds, S_IRUGO | S_IWUGO,
729 show_engine3_leds, store_engine3_leds);
730static DEVICE_ATTR(engine1_load, S_IWUGO, NULL, store_engine1_load);
731static DEVICE_ATTR(engine2_load, S_IWUGO, NULL, store_engine2_load);
732static DEVICE_ATTR(engine3_load, S_IWUGO, NULL, store_engine3_load);
733static DEVICE_ATTR(selftest, S_IRUGO, lp5523_selftest, NULL);
734
735static struct attribute *lp5523_attributes[] = {
736 &dev_attr_engine1_mode.attr,
737 &dev_attr_engine2_mode.attr,
738 &dev_attr_engine3_mode.attr,
739 &dev_attr_selftest.attr,
740 NULL
741};
742
743static struct attribute *lp5523_engine1_attributes[] = {
744 &dev_attr_engine1_load.attr,
745 &dev_attr_engine1_leds.attr,
746 NULL
747};
748
749static struct attribute *lp5523_engine2_attributes[] = {
750 &dev_attr_engine2_load.attr,
751 &dev_attr_engine2_leds.attr,
752 NULL
753};
754
755static struct attribute *lp5523_engine3_attributes[] = {
756 &dev_attr_engine3_load.attr,
757 &dev_attr_engine3_leds.attr,
758 NULL
759};
760
761static const struct attribute_group lp5523_group = {
762 .attrs = lp5523_attributes,
763};
764
765static const struct attribute_group lp5523_engine_group[] = {
766 {.attrs = lp5523_engine1_attributes },
767 {.attrs = lp5523_engine2_attributes },
768 {.attrs = lp5523_engine3_attributes },
769};
770
771static int lp5523_register_sysfs(struct i2c_client *client)
772{
773 struct device *dev = &client->dev;
774 int ret;
775
776 ret = sysfs_create_group(&dev->kobj, &lp5523_group);
777 if (ret < 0)
778 return ret;
779
780 return 0;
781}
782
783static void lp5523_unregister_sysfs(struct i2c_client *client)
784{
785 struct lp5523_chip *chip = i2c_get_clientdata(client);
786 struct device *dev = &client->dev;
787 int i;
788
789 sysfs_remove_group(&dev->kobj, &lp5523_group);
790
791 for (i = 0; i < ARRAY_SIZE(chip->engines); i++)
792 if (chip->engines[i].mode == LP5523_CMD_LOAD)
793 sysfs_remove_group(&dev->kobj, &lp5523_engine_group[i]);
794
795 for (i = 0; i < chip->num_leds; i++)
796 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
797 &lp5523_led_attribute_group);
798}
799
800/*--------------------------------------------------------------*/
801/* Set chip operating mode */
802/*--------------------------------------------------------------*/
803static int lp5523_set_mode(struct lp5523_engine *engine, u8 mode)
804{
805 /* engine to chip */
806 struct lp5523_chip *chip = engine_to_lp5523(engine);
807 struct i2c_client *client = chip->client;
808 struct device *dev = &client->dev;
809 int ret = 0;
810
811 /* if in that mode already do nothing, except for run */
812 if (mode == engine->mode && mode != LP5523_CMD_RUN)
813 return 0;
814
815 if (mode == LP5523_CMD_RUN) {
816 ret = lp5523_run_program(engine);
817 } else if (mode == LP5523_CMD_LOAD) {
818 lp5523_set_engine_mode(engine, LP5523_CMD_DISABLED);
819 lp5523_set_engine_mode(engine, LP5523_CMD_LOAD);
820
821 ret = sysfs_create_group(&dev->kobj, engine->attributes);
822 if (ret)
823 return ret;
824 } else if (mode == LP5523_CMD_DISABLED) {
825 lp5523_set_engine_mode(engine, LP5523_CMD_DISABLED);
826 }
827
828 /* remove load attribute from sysfs if not in load mode */
829 if (engine->mode == LP5523_CMD_LOAD && mode != LP5523_CMD_LOAD)
830 sysfs_remove_group(&dev->kobj, engine->attributes);
831
832 engine->mode = mode;
833
834 return ret;
835}
836
837/*--------------------------------------------------------------*/
838/* Probe, Attach, Remove */
839/*--------------------------------------------------------------*/
840static int __init lp5523_init_engine(struct lp5523_engine *engine, int id)
841{
842 if (id < 1 || id > LP5523_ENGINES)
843 return -1;
844 engine->id = id;
845 engine->engine_mask = LP5523_ENG_MASK_BASE >> SHIFT_MASK(id);
846 engine->prog_page = id - 1;
847 engine->mux_page = id + 2;
848 engine->attributes = &lp5523_engine_group[id - 1];
849
850 return 0;
851}
852
853static int __init lp5523_init_led(struct lp5523_led *led, struct device *dev,
854 int chan, struct lp5523_platform_data *pdata)
855{
856 char name[32];
857 int res;
858
859 if (chan >= LP5523_LEDS)
860 return -EINVAL;
861
862 if (pdata->led_config[chan].led_current) {
863 led->led_current = pdata->led_config[chan].led_current;
864 led->max_current = pdata->led_config[chan].max_current;
865 led->chan_nr = pdata->led_config[chan].chan_nr;
866
867 if (led->chan_nr >= LP5523_LEDS) {
868 dev_err(dev, "Use channel numbers between 0 and %d\n",
869 LP5523_LEDS - 1);
870 return -EINVAL;
871 }
872
873 snprintf(name, 32, "lp5523:channel%d", chan);
874
875 led->cdev.name = name;
876 led->cdev.brightness_set = lp5523_set_brightness;
877 res = led_classdev_register(dev, &led->cdev);
878 if (res < 0) {
879 dev_err(dev, "couldn't register led on channel %d\n",
880 chan);
881 return res;
882 }
883 res = sysfs_create_group(&led->cdev.dev->kobj,
884 &lp5523_led_attribute_group);
885 if (res < 0) {
886 dev_err(dev, "couldn't register current attribute\n");
887 led_classdev_unregister(&led->cdev);
888 return res;
889 }
890 } else {
891 led->led_current = 0;
892 }
893 return 0;
894}
895
896static struct i2c_driver lp5523_driver;
897
898static int lp5523_probe(struct i2c_client *client,
899 const struct i2c_device_id *id)
900{
901 struct lp5523_chip *chip;
902 struct lp5523_platform_data *pdata;
903 int ret, i, led;
904
905 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
906 if (!chip)
907 return -ENOMEM;
908
909 i2c_set_clientdata(client, chip);
910 chip->client = client;
911
912 pdata = client->dev.platform_data;
913
914 if (!pdata) {
915 dev_err(&client->dev, "no platform data\n");
916 ret = -EINVAL;
917 goto fail1;
918 }
919
920 mutex_init(&chip->lock);
921
922 chip->pdata = pdata;
923
924 if (pdata->setup_resources) {
925 ret = pdata->setup_resources();
926 if (ret < 0)
927 goto fail1;
928 }
929
930 if (pdata->enable) {
931 pdata->enable(0);
932 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
933 pdata->enable(1);
934 usleep_range(1000, 2000); /* 500us abs min. */
935 }
936
937 lp5523_write(client, LP5523_REG_RESET, 0xff);
938 usleep_range(10000, 20000); /*
939 * Exact value is not available. 10 - 20ms
940 * appears to be enough for reset.
941 */
942 ret = lp5523_detect(client);
943 if (ret)
944 goto fail2;
945
946 dev_info(&client->dev, "LP5523 Programmable led chip found\n");
947
948 /* Initialize engines */
949 for (i = 0; i < ARRAY_SIZE(chip->engines); i++) {
950 ret = lp5523_init_engine(&chip->engines[i], i + 1);
951 if (ret) {
952 dev_err(&client->dev, "error initializing engine\n");
953 goto fail2;
954 }
955 }
956 ret = lp5523_configure(client);
957 if (ret < 0) {
958 dev_err(&client->dev, "error configuring chip\n");
959 goto fail2;
960 }
961
962 /* Initialize leds */
963 chip->num_channels = pdata->num_channels;
964 chip->num_leds = 0;
965 led = 0;
966 for (i = 0; i < pdata->num_channels; i++) {
967 /* Do not initialize channels that are not connected */
968 if (pdata->led_config[i].led_current == 0)
969 continue;
970
971 ret = lp5523_init_led(&chip->leds[led], &client->dev, i, pdata);
972 if (ret) {
973 dev_err(&client->dev, "error initializing leds\n");
974 goto fail3;
975 }
976 chip->num_leds++;
977
978 chip->leds[led].id = led;
979 /* Set LED current */
980 lp5523_write(client,
981 LP5523_REG_LED_CURRENT_BASE + chip->leds[led].chan_nr,
982 chip->leds[led].led_current);
983
984 INIT_WORK(&(chip->leds[led].brightness_work),
985 lp5523_led_brightness_work);
986
987 led++;
988 }
989
990 ret = lp5523_register_sysfs(client);
991 if (ret) {
992 dev_err(&client->dev, "registering sysfs failed\n");
993 goto fail3;
994 }
995 return ret;
996fail3:
997 for (i = 0; i < chip->num_leds; i++) {
998 led_classdev_unregister(&chip->leds[i].cdev);
999 cancel_work_sync(&chip->leds[i].brightness_work);
1000 }
1001fail2:
1002 if (pdata->enable)
1003 pdata->enable(0);
1004 if (pdata->release_resources)
1005 pdata->release_resources();
1006fail1:
1007 kfree(chip);
1008 return ret;
1009}
1010
1011static int lp5523_remove(struct i2c_client *client)
1012{
1013 struct lp5523_chip *chip = i2c_get_clientdata(client);
1014 int i;
1015
1016 lp5523_unregister_sysfs(client);
1017
1018 for (i = 0; i < chip->num_leds; i++) {
1019 led_classdev_unregister(&chip->leds[i].cdev);
1020 cancel_work_sync(&chip->leds[i].brightness_work);
1021 }
1022
1023 if (chip->pdata->enable)
1024 chip->pdata->enable(0);
1025 if (chip->pdata->release_resources)
1026 chip->pdata->release_resources();
1027 kfree(chip);
1028 return 0;
1029}
1030
1031static const struct i2c_device_id lp5523_id[] = {
1032 { "lp5523", 0 },
1033 { }
1034};
1035
1036MODULE_DEVICE_TABLE(i2c, lp5523_id);
1037
1038static struct i2c_driver lp5523_driver = {
1039 .driver = {
1040 .name = "lp5523",
1041 },
1042 .probe = lp5523_probe,
1043 .remove = lp5523_remove,
1044 .id_table = lp5523_id,
1045};
1046
1047static int __init lp5523_init(void)
1048{
1049 int ret;
1050
1051 ret = i2c_add_driver(&lp5523_driver);
1052
1053 if (ret < 0)
1054 printk(KERN_ALERT "Adding lp5523 driver failed\n");
1055
1056 return ret;
1057}
1058
1059static void __exit lp5523_exit(void)
1060{
1061 i2c_del_driver(&lp5523_driver);
1062}
1063
1064module_init(lp5523_init);
1065module_exit(lp5523_exit);
1066
1067MODULE_AUTHOR("Mathias Nyman <mathias.nyman@nokia.com>");
1068MODULE_DESCRIPTION("LP5523 LED engine");
1069MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-net5501.c b/drivers/leds/leds-net5501.c
index 3063f591f0dc..1739557a9038 100644
--- a/drivers/leds/leds-net5501.c
+++ b/drivers/leds/leds-net5501.c
@@ -92,3 +92,5 @@ unmap:
92} 92}
93 93
94arch_initcall(soekris_init); 94arch_initcall(soekris_init);
95
96MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
index a688293abd0b..614ebebaaa28 100644
--- a/drivers/leds/leds-ss4200.c
+++ b/drivers/leds/leds-ss4200.c
@@ -102,6 +102,7 @@ static struct dmi_system_id __initdata nas_led_whitelist[] = {
102 DMI_MATCH(DMI_PRODUCT_VERSION, "1.00.00") 102 DMI_MATCH(DMI_PRODUCT_VERSION, "1.00.00")
103 } 103 }
104 }, 104 },
105 {}
105}; 106};
106 107
107/* 108/*
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index 82b77bd482ff..b09bcbeade9c 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -12,73 +12,25 @@
12 */ 12 */
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/jiffies.h>
16#include <linux/kernel.h> 15#include <linux/kernel.h>
17#include <linux/init.h> 16#include <linux/init.h>
18#include <linux/list.h>
19#include <linux/spinlock.h>
20#include <linux/device.h> 17#include <linux/device.h>
21#include <linux/sysdev.h>
22#include <linux/timer.h>
23#include <linux/ctype.h> 18#include <linux/ctype.h>
24#include <linux/leds.h> 19#include <linux/leds.h>
25#include <linux/slab.h>
26#include "leds.h" 20#include "leds.h"
27 21
28struct timer_trig_data {
29 int brightness_on; /* LED brightness during "on" period.
30 * (LED_OFF < brightness_on <= LED_FULL)
31 */
32 unsigned long delay_on; /* milliseconds on */
33 unsigned long delay_off; /* milliseconds off */
34 struct timer_list timer;
35};
36
37static void led_timer_function(unsigned long data)
38{
39 struct led_classdev *led_cdev = (struct led_classdev *) data;
40 struct timer_trig_data *timer_data = led_cdev->trigger_data;
41 unsigned long brightness;
42 unsigned long delay;
43
44 if (!timer_data->delay_on || !timer_data->delay_off) {
45 led_set_brightness(led_cdev, LED_OFF);
46 return;
47 }
48
49 brightness = led_get_brightness(led_cdev);
50 if (!brightness) {
51 /* Time to switch the LED on. */
52 brightness = timer_data->brightness_on;
53 delay = timer_data->delay_on;
54 } else {
55 /* Store the current brightness value to be able
56 * to restore it when the delay_off period is over.
57 */
58 timer_data->brightness_on = brightness;
59 brightness = LED_OFF;
60 delay = timer_data->delay_off;
61 }
62
63 led_set_brightness(led_cdev, brightness);
64
65 mod_timer(&timer_data->timer, jiffies + msecs_to_jiffies(delay));
66}
67
68static ssize_t led_delay_on_show(struct device *dev, 22static ssize_t led_delay_on_show(struct device *dev,
69 struct device_attribute *attr, char *buf) 23 struct device_attribute *attr, char *buf)
70{ 24{
71 struct led_classdev *led_cdev = dev_get_drvdata(dev); 25 struct led_classdev *led_cdev = dev_get_drvdata(dev);
72 struct timer_trig_data *timer_data = led_cdev->trigger_data;
73 26
74 return sprintf(buf, "%lu\n", timer_data->delay_on); 27 return sprintf(buf, "%lu\n", led_cdev->blink_delay_on);
75} 28}
76 29
77static ssize_t led_delay_on_store(struct device *dev, 30static ssize_t led_delay_on_store(struct device *dev,
78 struct device_attribute *attr, const char *buf, size_t size) 31 struct device_attribute *attr, const char *buf, size_t size)
79{ 32{
80 struct led_classdev *led_cdev = dev_get_drvdata(dev); 33 struct led_classdev *led_cdev = dev_get_drvdata(dev);
81 struct timer_trig_data *timer_data = led_cdev->trigger_data;
82 int ret = -EINVAL; 34 int ret = -EINVAL;
83 char *after; 35 char *after;
84 unsigned long state = simple_strtoul(buf, &after, 10); 36 unsigned long state = simple_strtoul(buf, &after, 10);
@@ -88,21 +40,7 @@ static ssize_t led_delay_on_store(struct device *dev,
88 count++; 40 count++;
89 41
90 if (count == size) { 42 if (count == size) {
91 if (timer_data->delay_on != state) { 43 led_blink_set(led_cdev, &state, &led_cdev->blink_delay_off);
92 /* the new value differs from the previous */
93 timer_data->delay_on = state;
94
95 /* deactivate previous settings */
96 del_timer_sync(&timer_data->timer);
97
98 /* try to activate hardware acceleration, if any */
99 if (!led_cdev->blink_set ||
100 led_cdev->blink_set(led_cdev,
101 &timer_data->delay_on, &timer_data->delay_off)) {
102 /* no hardware acceleration, blink via timer */
103 mod_timer(&timer_data->timer, jiffies + 1);
104 }
105 }
106 ret = count; 44 ret = count;
107 } 45 }
108 46
@@ -113,16 +51,14 @@ static ssize_t led_delay_off_show(struct device *dev,
113 struct device_attribute *attr, char *buf) 51 struct device_attribute *attr, char *buf)
114{ 52{
115 struct led_classdev *led_cdev = dev_get_drvdata(dev); 53 struct led_classdev *led_cdev = dev_get_drvdata(dev);
116 struct timer_trig_data *timer_data = led_cdev->trigger_data;
117 54
118 return sprintf(buf, "%lu\n", timer_data->delay_off); 55 return sprintf(buf, "%lu\n", led_cdev->blink_delay_off);
119} 56}
120 57
121static ssize_t led_delay_off_store(struct device *dev, 58static ssize_t led_delay_off_store(struct device *dev,
122 struct device_attribute *attr, const char *buf, size_t size) 59 struct device_attribute *attr, const char *buf, size_t size)
123{ 60{
124 struct led_classdev *led_cdev = dev_get_drvdata(dev); 61 struct led_classdev *led_cdev = dev_get_drvdata(dev);
125 struct timer_trig_data *timer_data = led_cdev->trigger_data;
126 int ret = -EINVAL; 62 int ret = -EINVAL;
127 char *after; 63 char *after;
128 unsigned long state = simple_strtoul(buf, &after, 10); 64 unsigned long state = simple_strtoul(buf, &after, 10);
@@ -132,21 +68,7 @@ static ssize_t led_delay_off_store(struct device *dev,
132 count++; 68 count++;
133 69
134 if (count == size) { 70 if (count == size) {
135 if (timer_data->delay_off != state) { 71 led_blink_set(led_cdev, &led_cdev->blink_delay_on, &state);
136 /* the new value differs from the previous */
137 timer_data->delay_off = state;
138
139 /* deactivate previous settings */
140 del_timer_sync(&timer_data->timer);
141
142 /* try to activate hardware acceleration, if any */
143 if (!led_cdev->blink_set ||
144 led_cdev->blink_set(led_cdev,
145 &timer_data->delay_on, &timer_data->delay_off)) {
146 /* no hardware acceleration, blink via timer */
147 mod_timer(&timer_data->timer, jiffies + 1);
148 }
149 }
150 ret = count; 72 ret = count;
151 } 73 }
152 74
@@ -158,60 +80,34 @@ static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
158 80
159static void timer_trig_activate(struct led_classdev *led_cdev) 81static void timer_trig_activate(struct led_classdev *led_cdev)
160{ 82{
161 struct timer_trig_data *timer_data;
162 int rc; 83 int rc;
163 84
164 timer_data = kzalloc(sizeof(struct timer_trig_data), GFP_KERNEL); 85 led_cdev->trigger_data = NULL;
165 if (!timer_data)
166 return;
167
168 timer_data->brightness_on = led_get_brightness(led_cdev);
169 if (timer_data->brightness_on == LED_OFF)
170 timer_data->brightness_on = led_cdev->max_brightness;
171 led_cdev->trigger_data = timer_data;
172
173 init_timer(&timer_data->timer);
174 timer_data->timer.function = led_timer_function;
175 timer_data->timer.data = (unsigned long) led_cdev;
176 86
177 rc = device_create_file(led_cdev->dev, &dev_attr_delay_on); 87 rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
178 if (rc) 88 if (rc)
179 goto err_out; 89 return;
180 rc = device_create_file(led_cdev->dev, &dev_attr_delay_off); 90 rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
181 if (rc) 91 if (rc)
182 goto err_out_delayon; 92 goto err_out_delayon;
183 93
184 /* If there is hardware support for blinking, start one 94 led_cdev->trigger_data = (void *)1;
185 * user friendly blink rate chosen by the driver.
186 */
187 if (led_cdev->blink_set)
188 led_cdev->blink_set(led_cdev,
189 &timer_data->delay_on, &timer_data->delay_off);
190 95
191 return; 96 return;
192 97
193err_out_delayon: 98err_out_delayon:
194 device_remove_file(led_cdev->dev, &dev_attr_delay_on); 99 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
195err_out:
196 led_cdev->trigger_data = NULL;
197 kfree(timer_data);
198} 100}
199 101
200static void timer_trig_deactivate(struct led_classdev *led_cdev) 102static void timer_trig_deactivate(struct led_classdev *led_cdev)
201{ 103{
202 struct timer_trig_data *timer_data = led_cdev->trigger_data; 104 if (led_cdev->trigger_data) {
203 unsigned long on = 0, off = 0;
204
205 if (timer_data) {
206 device_remove_file(led_cdev->dev, &dev_attr_delay_on); 105 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
207 device_remove_file(led_cdev->dev, &dev_attr_delay_off); 106 device_remove_file(led_cdev->dev, &dev_attr_delay_off);
208 del_timer_sync(&timer_data->timer);
209 kfree(timer_data);
210 } 107 }
211 108
212 /* If there is hardware support for blinking, stop it */ 109 /* Stop blinking */
213 if (led_cdev->blink_set) 110 led_brightness_set(led_cdev, LED_OFF);
214 led_cdev->blink_set(led_cdev, &on, &off);
215} 111}
216 112
217static struct led_trigger timer_led_trigger = { 113static struct led_trigger timer_led_trigger = {
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 3d7355ff7308..fa51af11c6f1 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -102,6 +102,7 @@ config ADB_PMU_LED
102config ADB_PMU_LED_IDE 102config ADB_PMU_LED_IDE
103 bool "Use front LED as IDE LED by default" 103 bool "Use front LED as IDE LED by default"
104 depends on ADB_PMU_LED 104 depends on ADB_PMU_LED
105 depends on LEDS_CLASS
105 select LEDS_TRIGGERS 106 select LEDS_TRIGGERS
106 select LEDS_TRIGGER_IDE_DISK 107 select LEDS_TRIGGER_IDE_DISK
107 help 108 help
diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index 444696625171..f5f4da3d0b67 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -80,7 +80,7 @@ static void adb_iop_end_req(struct adb_request *req, int state)
80static void adb_iop_complete(struct iop_msg *msg) 80static void adb_iop_complete(struct iop_msg *msg)
81{ 81{
82 struct adb_request *req; 82 struct adb_request *req;
83 uint flags; 83 unsigned long flags;
84 84
85 local_irq_save(flags); 85 local_irq_save(flags);
86 86
@@ -103,7 +103,7 @@ static void adb_iop_listen(struct iop_msg *msg)
103{ 103{
104 struct adb_iopmsg *amsg = (struct adb_iopmsg *) msg->message; 104 struct adb_iopmsg *amsg = (struct adb_iopmsg *) msg->message;
105 struct adb_request *req; 105 struct adb_request *req;
106 uint flags; 106 unsigned long flags;
107#ifdef DEBUG_ADB_IOP 107#ifdef DEBUG_ADB_IOP
108 int i; 108 int i;
109#endif 109#endif
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 90267f8d64ee..4d705cea0f8c 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -517,9 +517,8 @@ int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
517 */ 517 */
518 518
519 if (q->merge_bvec_fn && !ti->type->merge) 519 if (q->merge_bvec_fn && !ti->type->merge)
520 limits->max_sectors = 520 blk_limits_max_hw_sectors(limits,
521 min_not_zero(limits->max_sectors, 521 (unsigned int) (PAGE_SIZE >> 9));
522 (unsigned int) (PAGE_SIZE >> 9));
523 return 0; 522 return 0;
524} 523}
525EXPORT_SYMBOL_GPL(dm_set_device_limits); 524EXPORT_SYMBOL_GPL(dm_set_device_limits);
@@ -1131,11 +1130,6 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
1131 */ 1130 */
1132 q->limits = *limits; 1131 q->limits = *limits;
1133 1132
1134 if (limits->no_cluster)
1135 queue_flag_clear_unlocked(QUEUE_FLAG_CLUSTER, q);
1136 else
1137 queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q);
1138
1139 if (!dm_table_supports_discards(t)) 1133 if (!dm_table_supports_discards(t))
1140 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q); 1134 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
1141 else 1135 else
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 4e957f3140a8..175c424f201f 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -371,10 +371,15 @@ static void md_end_flush(struct bio *bio, int err)
371 bio_put(bio); 371 bio_put(bio);
372} 372}
373 373
374static void submit_flushes(mddev_t *mddev) 374static void md_submit_flush_data(struct work_struct *ws);
375
376static void submit_flushes(struct work_struct *ws)
375{ 377{
378 mddev_t *mddev = container_of(ws, mddev_t, flush_work);
376 mdk_rdev_t *rdev; 379 mdk_rdev_t *rdev;
377 380
381 INIT_WORK(&mddev->flush_work, md_submit_flush_data);
382 atomic_set(&mddev->flush_pending, 1);
378 rcu_read_lock(); 383 rcu_read_lock();
379 list_for_each_entry_rcu(rdev, &mddev->disks, same_set) 384 list_for_each_entry_rcu(rdev, &mddev->disks, same_set)
380 if (rdev->raid_disk >= 0 && 385 if (rdev->raid_disk >= 0 &&
@@ -397,6 +402,8 @@ static void submit_flushes(mddev_t *mddev)
397 rdev_dec_pending(rdev, mddev); 402 rdev_dec_pending(rdev, mddev);
398 } 403 }
399 rcu_read_unlock(); 404 rcu_read_unlock();
405 if (atomic_dec_and_test(&mddev->flush_pending))
406 queue_work(md_wq, &mddev->flush_work);
400} 407}
401 408
402static void md_submit_flush_data(struct work_struct *ws) 409static void md_submit_flush_data(struct work_struct *ws)
@@ -404,8 +411,6 @@ static void md_submit_flush_data(struct work_struct *ws)
404 mddev_t *mddev = container_of(ws, mddev_t, flush_work); 411 mddev_t *mddev = container_of(ws, mddev_t, flush_work);
405 struct bio *bio = mddev->flush_bio; 412 struct bio *bio = mddev->flush_bio;
406 413
407 atomic_set(&mddev->flush_pending, 1);
408
409 if (bio->bi_size == 0) 414 if (bio->bi_size == 0)
410 /* an empty barrier - all done */ 415 /* an empty barrier - all done */
411 bio_endio(bio, 0); 416 bio_endio(bio, 0);
@@ -414,10 +419,9 @@ static void md_submit_flush_data(struct work_struct *ws)
414 if (mddev->pers->make_request(mddev, bio)) 419 if (mddev->pers->make_request(mddev, bio))
415 generic_make_request(bio); 420 generic_make_request(bio);
416 } 421 }
417 if (atomic_dec_and_test(&mddev->flush_pending)) { 422
418 mddev->flush_bio = NULL; 423 mddev->flush_bio = NULL;
419 wake_up(&mddev->sb_wait); 424 wake_up(&mddev->sb_wait);
420 }
421} 425}
422 426
423void md_flush_request(mddev_t *mddev, struct bio *bio) 427void md_flush_request(mddev_t *mddev, struct bio *bio)
@@ -429,13 +433,8 @@ void md_flush_request(mddev_t *mddev, struct bio *bio)
429 mddev->flush_bio = bio; 433 mddev->flush_bio = bio;
430 spin_unlock_irq(&mddev->write_lock); 434 spin_unlock_irq(&mddev->write_lock);
431 435
432 atomic_set(&mddev->flush_pending, 1); 436 INIT_WORK(&mddev->flush_work, submit_flushes);
433 INIT_WORK(&mddev->flush_work, md_submit_flush_data); 437 queue_work(md_wq, &mddev->flush_work);
434
435 submit_flushes(mddev);
436
437 if (atomic_dec_and_test(&mddev->flush_pending))
438 queue_work(md_wq, &mddev->flush_work);
439} 438}
440EXPORT_SYMBOL(md_flush_request); 439EXPORT_SYMBOL(md_flush_request);
441 440
@@ -706,7 +705,7 @@ static struct mdk_personality *find_pers(int level, char *clevel)
706/* return the offset of the super block in 512byte sectors */ 705/* return the offset of the super block in 512byte sectors */
707static inline sector_t calc_dev_sboffset(struct block_device *bdev) 706static inline sector_t calc_dev_sboffset(struct block_device *bdev)
708{ 707{
709 sector_t num_sectors = bdev->bd_inode->i_size / 512; 708 sector_t num_sectors = i_size_read(bdev->bd_inode) / 512;
710 return MD_NEW_SIZE_SECTORS(num_sectors); 709 return MD_NEW_SIZE_SECTORS(num_sectors);
711} 710}
712 711
@@ -1337,7 +1336,7 @@ super_90_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1337 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, 1336 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size,
1338 rdev->sb_page); 1337 rdev->sb_page);
1339 md_super_wait(rdev->mddev); 1338 md_super_wait(rdev->mddev);
1340 return num_sectors / 2; /* kB for sysfs */ 1339 return num_sectors;
1341} 1340}
1342 1341
1343 1342
@@ -1386,7 +1385,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1386 */ 1385 */
1387 switch(minor_version) { 1386 switch(minor_version) {
1388 case 0: 1387 case 0:
1389 sb_start = rdev->bdev->bd_inode->i_size >> 9; 1388 sb_start = i_size_read(rdev->bdev->bd_inode) >> 9;
1390 sb_start -= 8*2; 1389 sb_start -= 8*2;
1391 sb_start &= ~(sector_t)(4*2-1); 1390 sb_start &= ~(sector_t)(4*2-1);
1392 break; 1391 break;
@@ -1472,7 +1471,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1472 ret = 0; 1471 ret = 0;
1473 } 1472 }
1474 if (minor_version) 1473 if (minor_version)
1475 rdev->sectors = (rdev->bdev->bd_inode->i_size >> 9) - 1474 rdev->sectors = (i_size_read(rdev->bdev->bd_inode) >> 9) -
1476 le64_to_cpu(sb->data_offset); 1475 le64_to_cpu(sb->data_offset);
1477 else 1476 else
1478 rdev->sectors = rdev->sb_start; 1477 rdev->sectors = rdev->sb_start;
@@ -1680,7 +1679,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1680 return 0; /* component must fit device */ 1679 return 0; /* component must fit device */
1681 if (rdev->sb_start < rdev->data_offset) { 1680 if (rdev->sb_start < rdev->data_offset) {
1682 /* minor versions 1 and 2; superblock before data */ 1681 /* minor versions 1 and 2; superblock before data */
1683 max_sectors = rdev->bdev->bd_inode->i_size >> 9; 1682 max_sectors = i_size_read(rdev->bdev->bd_inode) >> 9;
1684 max_sectors -= rdev->data_offset; 1683 max_sectors -= rdev->data_offset;
1685 if (!num_sectors || num_sectors > max_sectors) 1684 if (!num_sectors || num_sectors > max_sectors)
1686 num_sectors = max_sectors; 1685 num_sectors = max_sectors;
@@ -1690,7 +1689,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1690 } else { 1689 } else {
1691 /* minor version 0; superblock after data */ 1690 /* minor version 0; superblock after data */
1692 sector_t sb_start; 1691 sector_t sb_start;
1693 sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; 1692 sb_start = (i_size_read(rdev->bdev->bd_inode) >> 9) - 8*2;
1694 sb_start &= ~(sector_t)(4*2 - 1); 1693 sb_start &= ~(sector_t)(4*2 - 1);
1695 max_sectors = rdev->sectors + sb_start - rdev->sb_start; 1694 max_sectors = rdev->sectors + sb_start - rdev->sb_start;
1696 if (!num_sectors || num_sectors > max_sectors) 1695 if (!num_sectors || num_sectors > max_sectors)
@@ -1704,7 +1703,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1704 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size, 1703 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size,
1705 rdev->sb_page); 1704 rdev->sb_page);
1706 md_super_wait(rdev->mddev); 1705 md_super_wait(rdev->mddev);
1707 return num_sectors / 2; /* kB for sysfs */ 1706 return num_sectors;
1708} 1707}
1709 1708
1710static struct super_type super_types[] = { 1709static struct super_type super_types[] = {
@@ -2584,7 +2583,7 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2584 if (!sectors) 2583 if (!sectors)
2585 return -EBUSY; 2584 return -EBUSY;
2586 } else if (!sectors) 2585 } else if (!sectors)
2587 sectors = (rdev->bdev->bd_inode->i_size >> 9) - 2586 sectors = (i_size_read(rdev->bdev->bd_inode) >> 9) -
2588 rdev->data_offset; 2587 rdev->data_offset;
2589 } 2588 }
2590 if (sectors < my_mddev->dev_sectors) 2589 if (sectors < my_mddev->dev_sectors)
@@ -2797,7 +2796,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
2797 2796
2798 kobject_init(&rdev->kobj, &rdev_ktype); 2797 kobject_init(&rdev->kobj, &rdev_ktype);
2799 2798
2800 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; 2799 size = i_size_read(rdev->bdev->bd_inode) >> BLOCK_SIZE_BITS;
2801 if (!size) { 2800 if (!size) {
2802 printk(KERN_WARNING 2801 printk(KERN_WARNING
2803 "md: %s has zero or unknown size, marking faulty!\n", 2802 "md: %s has zero or unknown size, marking faulty!\n",
@@ -4296,9 +4295,6 @@ static int md_alloc(dev_t dev, char *name)
4296 goto abort; 4295 goto abort;
4297 mddev->queue->queuedata = mddev; 4296 mddev->queue->queuedata = mddev;
4298 4297
4299 /* Can be unlocked because the queue is new: no concurrency */
4300 queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, mddev->queue);
4301
4302 blk_queue_make_request(mddev->queue, md_make_request); 4298 blk_queue_make_request(mddev->queue, md_make_request);
4303 4299
4304 disk = alloc_disk(1 << shift); 4300 disk = alloc_disk(1 << shift);
@@ -4338,6 +4334,8 @@ static int md_alloc(dev_t dev, char *name)
4338 if (mddev->kobj.sd && 4334 if (mddev->kobj.sd &&
4339 sysfs_create_group(&mddev->kobj, &md_bitmap_group)) 4335 sysfs_create_group(&mddev->kobj, &md_bitmap_group))
4340 printk(KERN_DEBUG "pointless warning\n"); 4336 printk(KERN_DEBUG "pointless warning\n");
4337
4338 blk_queue_flush(mddev->queue, REQ_FLUSH | REQ_FUA);
4341 abort: 4339 abort:
4342 mutex_unlock(&disks_mutex); 4340 mutex_unlock(&disks_mutex);
4343 if (!error && mddev->kobj.sd) { 4341 if (!error && mddev->kobj.sd) {
@@ -5158,7 +5156,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
5158 PTR_ERR(rdev)); 5156 PTR_ERR(rdev));
5159 return PTR_ERR(rdev); 5157 return PTR_ERR(rdev);
5160 } 5158 }
5161 /* set save_raid_disk if appropriate */ 5159 /* set saved_raid_disk if appropriate */
5162 if (!mddev->persistent) { 5160 if (!mddev->persistent) {
5163 if (info->state & (1<<MD_DISK_SYNC) && 5161 if (info->state & (1<<MD_DISK_SYNC) &&
5164 info->raid_disk < mddev->raid_disks) 5162 info->raid_disk < mddev->raid_disks)
@@ -5168,7 +5166,10 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
5168 } else 5166 } else
5169 super_types[mddev->major_version]. 5167 super_types[mddev->major_version].
5170 validate_super(mddev, rdev); 5168 validate_super(mddev, rdev);
5171 rdev->saved_raid_disk = rdev->raid_disk; 5169 if (test_bit(In_sync, &rdev->flags))
5170 rdev->saved_raid_disk = rdev->raid_disk;
5171 else
5172 rdev->saved_raid_disk = -1;
5172 5173
5173 clear_bit(In_sync, &rdev->flags); /* just to be sure */ 5174 clear_bit(In_sync, &rdev->flags); /* just to be sure */
5174 if (info->state & (1<<MD_DISK_WRITEMOSTLY)) 5175 if (info->state & (1<<MD_DISK_WRITEMOSTLY))
@@ -5235,8 +5236,8 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
5235 5236
5236 if (!mddev->persistent) { 5237 if (!mddev->persistent) {
5237 printk(KERN_INFO "md: nonpersistent superblock ...\n"); 5238 printk(KERN_INFO "md: nonpersistent superblock ...\n");
5238 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; 5239 rdev->sb_start = i_size_read(rdev->bdev->bd_inode) / 512;
5239 } else 5240 } else
5240 rdev->sb_start = calc_dev_sboffset(rdev->bdev); 5241 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
5241 rdev->sectors = rdev->sb_start; 5242 rdev->sectors = rdev->sb_start;
5242 5243
@@ -5306,7 +5307,7 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
5306 if (mddev->persistent) 5307 if (mddev->persistent)
5307 rdev->sb_start = calc_dev_sboffset(rdev->bdev); 5308 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
5308 else 5309 else
5309 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; 5310 rdev->sb_start = i_size_read(rdev->bdev->bd_inode) / 512;
5310 5311
5311 rdev->sectors = rdev->sb_start; 5312 rdev->sectors = rdev->sb_start;
5312 5313
@@ -6040,9 +6041,8 @@ static int md_thread(void * arg)
6040 || kthread_should_stop(), 6041 || kthread_should_stop(),
6041 thread->timeout); 6042 thread->timeout);
6042 6043
6043 clear_bit(THREAD_WAKEUP, &thread->flags); 6044 if (test_and_clear_bit(THREAD_WAKEUP, &thread->flags))
6044 6045 thread->run(thread->mddev);
6045 thread->run(thread->mddev);
6046 } 6046 }
6047 6047
6048 return 0; 6048 return 0;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 45f8324196ec..845cf95b612c 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1161,6 +1161,7 @@ static int raid1_remove_disk(mddev_t *mddev, int number)
1161 * is not possible. 1161 * is not possible.
1162 */ 1162 */
1163 if (!test_bit(Faulty, &rdev->flags) && 1163 if (!test_bit(Faulty, &rdev->flags) &&
1164 !mddev->recovery_disabled &&
1164 mddev->degraded < conf->raid_disks) { 1165 mddev->degraded < conf->raid_disks) {
1165 err = -EBUSY; 1166 err = -EBUSY;
1166 goto abort; 1167 goto abort;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index c67aa54694ae..0641674827f0 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -2397,13 +2397,13 @@ static int run(mddev_t *mddev)
2397 return 0; 2397 return 0;
2398 2398
2399out_free_conf: 2399out_free_conf:
2400 md_unregister_thread(mddev->thread);
2400 if (conf->r10bio_pool) 2401 if (conf->r10bio_pool)
2401 mempool_destroy(conf->r10bio_pool); 2402 mempool_destroy(conf->r10bio_pool);
2402 safe_put_page(conf->tmppage); 2403 safe_put_page(conf->tmppage);
2403 kfree(conf->mirrors); 2404 kfree(conf->mirrors);
2404 kfree(conf); 2405 kfree(conf);
2405 mddev->private = NULL; 2406 mddev->private = NULL;
2406 md_unregister_thread(mddev->thread);
2407out: 2407out:
2408 return -EIO; 2408 return -EIO;
2409} 2409}
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 9186b45132ed..f60107c3b091 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -325,9 +325,9 @@ static int ir_setkeytable(struct ir_input_dev *ir_dev,
325static unsigned int ir_lookup_by_scancode(const struct ir_scancode_table *rc_tab, 325static unsigned int ir_lookup_by_scancode(const struct ir_scancode_table *rc_tab,
326 unsigned int scancode) 326 unsigned int scancode)
327{ 327{
328 unsigned int start = 0; 328 int start = 0;
329 unsigned int end = rc_tab->len - 1; 329 int end = rc_tab->len - 1;
330 unsigned int mid; 330 int mid;
331 331
332 while (start <= end) { 332 while (start <= end) {
333 mid = (start + end) / 2; 333 mid = (start + end) / 2;
@@ -389,6 +389,8 @@ static int ir_getkeycode(struct input_dev *dev,
389 ke->len = sizeof(entry->scancode); 389 ke->len = sizeof(entry->scancode);
390 memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode)); 390 memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
391 391
392 retval = 0;
393
392out: 394out:
393 spin_unlock_irqrestore(&rc_tab->lock, flags); 395 spin_unlock_irqrestore(&rc_tab->lock, flags);
394 return retval; 396 return retval;
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index bad2cedb8d96..a28541b2b1a2 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -19,7 +19,6 @@ comment "Multimedia core support"
19 19
20config VIDEO_DEV 20config VIDEO_DEV
21 tristate "Video For Linux" 21 tristate "Video For Linux"
22 depends on BKL # used in many drivers for ioctl handling, need to kill
23 ---help--- 22 ---help---
24 V4L core support for video capture and overlay devices, webcams and 23 V4L core support for video capture and overlay devices, webcams and
25 AM/FM radio cards. 24 AM/FM radio cards.
diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
index 05bde9ccb770..1d1d8d200755 100644
--- a/drivers/media/common/saa7146_hlp.c
+++ b/drivers/media/common/saa7146_hlp.c
@@ -558,7 +558,7 @@ static void saa7146_set_window(struct saa7146_dev *dev, int width, int height, e
558static void saa7146_set_position(struct saa7146_dev *dev, int w_x, int w_y, int w_height, enum v4l2_field field, u32 pixelformat) 558static void saa7146_set_position(struct saa7146_dev *dev, int w_x, int w_y, int w_height, enum v4l2_field field, u32 pixelformat)
559{ 559{
560 struct saa7146_vv *vv = dev->vv_data; 560 struct saa7146_vv *vv = dev->vv_data;
561 struct saa7146_format *sfmt = format_by_fourcc(dev, pixelformat); 561 struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev, pixelformat);
562 562
563 int b_depth = vv->ov_fmt->depth; 563 int b_depth = vv->ov_fmt->depth;
564 int b_bpl = vv->ov_fb.fmt.bytesperline; 564 int b_bpl = vv->ov_fb.fmt.bytesperline;
@@ -702,7 +702,7 @@ static int calculate_video_dma_grab_packed(struct saa7146_dev* dev, struct saa71
702 struct saa7146_vv *vv = dev->vv_data; 702 struct saa7146_vv *vv = dev->vv_data;
703 struct saa7146_video_dma vdma1; 703 struct saa7146_video_dma vdma1;
704 704
705 struct saa7146_format *sfmt = format_by_fourcc(dev,buf->fmt->pixelformat); 705 struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev,buf->fmt->pixelformat);
706 706
707 int width = buf->fmt->width; 707 int width = buf->fmt->width;
708 int height = buf->fmt->height; 708 int height = buf->fmt->height;
@@ -827,7 +827,7 @@ static int calculate_video_dma_grab_planar(struct saa7146_dev* dev, struct saa71
827 struct saa7146_video_dma vdma2; 827 struct saa7146_video_dma vdma2;
828 struct saa7146_video_dma vdma3; 828 struct saa7146_video_dma vdma3;
829 829
830 struct saa7146_format *sfmt = format_by_fourcc(dev,buf->fmt->pixelformat); 830 struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev,buf->fmt->pixelformat);
831 831
832 int width = buf->fmt->width; 832 int width = buf->fmt->width;
833 int height = buf->fmt->height; 833 int height = buf->fmt->height;
@@ -994,7 +994,7 @@ static void program_capture_engine(struct saa7146_dev *dev, int planar)
994 994
995void saa7146_set_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next) 995void saa7146_set_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next)
996{ 996{
997 struct saa7146_format *sfmt = format_by_fourcc(dev,buf->fmt->pixelformat); 997 struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev,buf->fmt->pixelformat);
998 struct saa7146_vv *vv = dev->vv_data; 998 struct saa7146_vv *vv = dev->vv_data;
999 u32 vdma1_prot_addr; 999 u32 vdma1_prot_addr;
1000 1000
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 3d88542612ea..74ee172b5bc9 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -391,7 +391,6 @@ static int saa7146_i2c_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, in
391 391
392/*****************************************************************************/ 392/*****************************************************************************/
393/* i2c-adapter helper functions */ 393/* i2c-adapter helper functions */
394#include <linux/i2c-id.h>
395 394
396/* exported algorithm data */ 395/* exported algorithm data */
397static struct i2c_algorithm saa7146_algo = { 396static struct i2c_algorithm saa7146_algo = {
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 741c5732b430..d246910129e8 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -84,7 +84,7 @@ static struct saa7146_format formats[] = {
84 84
85static int NUM_FORMATS = sizeof(formats)/sizeof(struct saa7146_format); 85static int NUM_FORMATS = sizeof(formats)/sizeof(struct saa7146_format);
86 86
87struct saa7146_format* format_by_fourcc(struct saa7146_dev *dev, int fourcc) 87struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc)
88{ 88{
89 int i, j = NUM_FORMATS; 89 int i, j = NUM_FORMATS;
90 90
@@ -266,7 +266,7 @@ static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *bu
266 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); 266 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
267 struct scatterlist *list = dma->sglist; 267 struct scatterlist *list = dma->sglist;
268 int length = dma->sglen; 268 int length = dma->sglen;
269 struct saa7146_format *sfmt = format_by_fourcc(dev,buf->fmt->pixelformat); 269 struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev,buf->fmt->pixelformat);
270 270
271 DEB_EE(("dev:%p, buf:%p, sg_len:%d\n",dev,buf,length)); 271 DEB_EE(("dev:%p, buf:%p, sg_len:%d\n",dev,buf,length));
272 272
@@ -408,7 +408,7 @@ static int video_begin(struct saa7146_fh *fh)
408 } 408 }
409 } 409 }
410 410
411 fmt = format_by_fourcc(dev,fh->video_fmt.pixelformat); 411 fmt = saa7146_format_by_fourcc(dev,fh->video_fmt.pixelformat);
412 /* we need to have a valid format set here */ 412 /* we need to have a valid format set here */
413 BUG_ON(NULL == fmt); 413 BUG_ON(NULL == fmt);
414 414
@@ -460,7 +460,7 @@ static int video_end(struct saa7146_fh *fh, struct file *file)
460 return -EBUSY; 460 return -EBUSY;
461 } 461 }
462 462
463 fmt = format_by_fourcc(dev,fh->video_fmt.pixelformat); 463 fmt = saa7146_format_by_fourcc(dev,fh->video_fmt.pixelformat);
464 /* we need to have a valid format set here */ 464 /* we need to have a valid format set here */
465 BUG_ON(NULL == fmt); 465 BUG_ON(NULL == fmt);
466 466
@@ -536,7 +536,7 @@ static int vidioc_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *f
536 return -EPERM; 536 return -EPERM;
537 537
538 /* check args */ 538 /* check args */
539 fmt = format_by_fourcc(dev, fb->fmt.pixelformat); 539 fmt = saa7146_format_by_fourcc(dev, fb->fmt.pixelformat);
540 if (NULL == fmt) 540 if (NULL == fmt)
541 return -EINVAL; 541 return -EINVAL;
542 542
@@ -760,7 +760,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
760 760
761 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh)); 761 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh));
762 762
763 fmt = format_by_fourcc(dev, f->fmt.pix.pixelformat); 763 fmt = saa7146_format_by_fourcc(dev, f->fmt.pix.pixelformat);
764 if (NULL == fmt) 764 if (NULL == fmt)
765 return -EINVAL; 765 return -EINVAL;
766 766
@@ -1264,7 +1264,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1264 buf->fmt = &fh->video_fmt; 1264 buf->fmt = &fh->video_fmt;
1265 buf->vb.field = fh->video_fmt.field; 1265 buf->vb.field = fh->video_fmt.field;
1266 1266
1267 sfmt = format_by_fourcc(dev,buf->fmt->pixelformat); 1267 sfmt = saa7146_format_by_fourcc(dev,buf->fmt->pixelformat);
1268 1268
1269 release_all_pagetables(dev, buf); 1269 release_all_pagetables(dev, buf);
1270 if( 0 != IS_PLANAR(sfmt->trans)) { 1270 if( 0 != IS_PLANAR(sfmt->trans)) {
@@ -1378,7 +1378,7 @@ static int video_open(struct saa7146_dev *dev, struct file *file)
1378 fh->video_fmt.pixelformat = V4L2_PIX_FMT_BGR24; 1378 fh->video_fmt.pixelformat = V4L2_PIX_FMT_BGR24;
1379 fh->video_fmt.bytesperline = 0; 1379 fh->video_fmt.bytesperline = 0;
1380 fh->video_fmt.field = V4L2_FIELD_ANY; 1380 fh->video_fmt.field = V4L2_FIELD_ANY;
1381 sfmt = format_by_fourcc(dev,fh->video_fmt.pixelformat); 1381 sfmt = saa7146_format_by_fourcc(dev,fh->video_fmt.pixelformat);
1382 fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8; 1382 fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8;
1383 1383
1384 videobuf_queue_sg_init(&fh->video_q, &video_qops, 1384 videobuf_queue_sg_init(&fh->video_q, &video_qops,
diff --git a/drivers/media/common/tuners/Kconfig b/drivers/media/common/tuners/Kconfig
index 2385e6cca635..78b089526e02 100644
--- a/drivers/media/common/tuners/Kconfig
+++ b/drivers/media/common/tuners/Kconfig
@@ -31,7 +31,7 @@ config MEDIA_TUNER
31 select MEDIA_TUNER_TDA9887 if !MEDIA_TUNER_CUSTOMISE 31 select MEDIA_TUNER_TDA9887 if !MEDIA_TUNER_CUSTOMISE
32 select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMISE 32 select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMISE
33 33
34menuconfig MEDIA_TUNER_CUSTOMISE 34config MEDIA_TUNER_CUSTOMISE
35 bool "Customize analog and hybrid tuner modules to build" 35 bool "Customize analog and hybrid tuner modules to build"
36 depends on MEDIA_TUNER 36 depends on MEDIA_TUNER
37 default y if EMBEDDED 37 default y if EMBEDDED
@@ -44,7 +44,8 @@ menuconfig MEDIA_TUNER_CUSTOMISE
44 44
45 If unsure say N. 45 If unsure say N.
46 46
47if MEDIA_TUNER_CUSTOMISE 47menu "Customize TV tuners"
48 visible if MEDIA_TUNER_CUSTOMISE
48 49
49config MEDIA_TUNER_SIMPLE 50config MEDIA_TUNER_SIMPLE
50 tristate "Simple tuner support" 51 tristate "Simple tuner support"
@@ -185,5 +186,4 @@ config MEDIA_TUNER_TDA18218
185 default m if MEDIA_TUNER_CUSTOMISE 186 default m if MEDIA_TUNER_CUSTOMISE
186 help 187 help
187 NXP TDA18218 silicon tuner driver. 188 NXP TDA18218 silicon tuner driver.
188 189endmenu
189endif # MEDIA_TUNER_CUSTOMISE
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index 4d0646da6087..7ea517b7e186 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -36,7 +36,6 @@
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/spinlock.h> 37#include <linux/spinlock.h>
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/smp_lock.h>
40#include <linux/kthread.h> 39#include <linux/kthread.h>
41 40
42#include "dvb_ca_en50221.h" 41#include "dvb_ca_en50221.h"
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 1589d5a5cb46..cad6634610ea 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -36,7 +36,6 @@
36#include <linux/list.h> 36#include <linux/list.h>
37#include <linux/freezer.h> 37#include <linux/freezer.h>
38#include <linux/jiffies.h> 38#include <linux/jiffies.h>
39#include <linux/smp_lock.h>
40#include <linux/kthread.h> 39#include <linux/kthread.h>
41#include <asm/processor.h> 40#include <asm/processor.h>
42 41
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index e9062b08a485..96b27016670e 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -12,9 +12,8 @@ config DVB_FE_CUSTOMISE
12 12
13 If unsure say N. 13 If unsure say N.
14 14
15if DVB_FE_CUSTOMISE
16
17menu "Customise DVB Frontends" 15menu "Customise DVB Frontends"
16 visible if DVB_FE_CUSTOMISE
18 17
19comment "Multistandard (satellite) frontends" 18comment "Multistandard (satellite) frontends"
20 depends on DVB_CORE 19 depends on DVB_CORE
@@ -619,5 +618,3 @@ config DVB_DUMMY_FE
619 tristate "Dummy frontend driver" 618 tristate "Dummy frontend driver"
620 default n 619 default n
621endmenu 620endmenu
622
623endif
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c
index a4991026254d..2311c0a3406c 100644
--- a/drivers/media/dvb/frontends/dibx000_common.c
+++ b/drivers/media/dvb/frontends/dibx000_common.c
@@ -130,6 +130,7 @@ static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
130 struct dibx000_i2c_master *mst) 130 struct dibx000_i2c_master *mst)
131{ 131{
132 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name)); 132 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
133 i2c_adap->algo = algo;
133 i2c_adap->algo_data = NULL; 134 i2c_adap->algo_data = NULL;
134 i2c_set_adapdata(i2c_adap, mst); 135 i2c_set_adapdata(i2c_adap, mst);
135 if (i2c_add_adapter(i2c_adap) < 0) 136 if (i2c_add_adapter(i2c_adap) < 0)
diff --git a/drivers/media/dvb/ngene/ngene-core.c b/drivers/media/dvb/ngene/ngene-core.c
index 4caeb163a666..3a7ef71087be 100644
--- a/drivers/media/dvb/ngene/ngene-core.c
+++ b/drivers/media/dvb/ngene/ngene-core.c
@@ -34,7 +34,6 @@
34#include <linux/io.h> 34#include <linux/io.h>
35#include <asm/div64.h> 35#include <asm/div64.h>
36#include <linux/pci.h> 36#include <linux/pci.h>
37#include <linux/smp_lock.h>
38#include <linux/timer.h> 37#include <linux/timer.h>
39#include <linux/byteorder/generic.h> 38#include <linux/byteorder/generic.h>
40#include <linux/firmware.h> 39#include <linux/firmware.h>
diff --git a/drivers/media/dvb/ngene/ngene-dvb.c b/drivers/media/dvb/ngene/ngene-dvb.c
index 48f980b21d66..3832e5983c19 100644
--- a/drivers/media/dvb/ngene/ngene-dvb.c
+++ b/drivers/media/dvb/ngene/ngene-dvb.c
@@ -35,7 +35,6 @@
35#include <linux/io.h> 35#include <linux/io.h>
36#include <asm/div64.h> 36#include <asm/div64.h>
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/smp_lock.h>
39#include <linux/timer.h> 38#include <linux/timer.h>
40#include <linux/byteorder/generic.h> 39#include <linux/byteorder/generic.h>
41#include <linux/firmware.h> 40#include <linux/firmware.h>
diff --git a/drivers/media/dvb/ngene/ngene-i2c.c b/drivers/media/dvb/ngene/ngene-i2c.c
index c3ae956714e7..d28554f8ce99 100644
--- a/drivers/media/dvb/ngene/ngene-i2c.c
+++ b/drivers/media/dvb/ngene/ngene-i2c.c
@@ -37,7 +37,6 @@
37#include <asm/div64.h> 37#include <asm/div64.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/pci_ids.h> 39#include <linux/pci_ids.h>
40#include <linux/smp_lock.h>
41#include <linux/timer.h> 40#include <linux/timer.h>
42#include <linux/byteorder/generic.h> 41#include <linux/byteorder/generic.h>
43#include <linux/firmware.h> 42#include <linux/firmware.h>
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index 5bf4985daede..05e832f61c3e 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -361,7 +361,7 @@ static int vidioc_s_audio(struct file *file, void *priv,
361 361
362static const struct v4l2_file_operations rtrack_fops = { 362static const struct v4l2_file_operations rtrack_fops = {
363 .owner = THIS_MODULE, 363 .owner = THIS_MODULE,
364 .ioctl = video_ioctl2, 364 .unlocked_ioctl = video_ioctl2,
365}; 365};
366 366
367static const struct v4l2_ioctl_ops rtrack_ioctl_ops = { 367static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
@@ -412,13 +412,6 @@ static int __init rtrack_init(void)
412 rt->vdev.release = video_device_release_empty; 412 rt->vdev.release = video_device_release_empty;
413 video_set_drvdata(&rt->vdev, rt); 413 video_set_drvdata(&rt->vdev, rt);
414 414
415 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
416 v4l2_device_unregister(&rt->v4l2_dev);
417 release_region(rt->io, 2);
418 return -EINVAL;
419 }
420 v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n");
421
422 /* Set up the I/O locking */ 415 /* Set up the I/O locking */
423 416
424 mutex_init(&rt->lock); 417 mutex_init(&rt->lock);
@@ -430,6 +423,13 @@ static int __init rtrack_init(void)
430 sleep_delay(2000000); /* make sure it's totally down */ 423 sleep_delay(2000000); /* make sure it's totally down */
431 outb(0xc0, rt->io); /* steady volume, mute card */ 424 outb(0xc0, rt->io); /* steady volume, mute card */
432 425
426 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
427 v4l2_device_unregister(&rt->v4l2_dev);
428 release_region(rt->io, 2);
429 return -EINVAL;
430 }
431 v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n");
432
433 return 0; 433 return 0;
434} 434}
435 435
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index c22311393624..dd8a6ab0d437 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -324,7 +324,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
324 324
325static const struct v4l2_file_operations aztech_fops = { 325static const struct v4l2_file_operations aztech_fops = {
326 .owner = THIS_MODULE, 326 .owner = THIS_MODULE,
327 .ioctl = video_ioctl2, 327 .unlocked_ioctl = video_ioctl2,
328}; 328};
329 329
330static const struct v4l2_ioctl_ops aztech_ioctl_ops = { 330static const struct v4l2_ioctl_ops aztech_ioctl_ops = {
@@ -375,6 +375,8 @@ static int __init aztech_init(void)
375 az->vdev.ioctl_ops = &aztech_ioctl_ops; 375 az->vdev.ioctl_ops = &aztech_ioctl_ops;
376 az->vdev.release = video_device_release_empty; 376 az->vdev.release = video_device_release_empty;
377 video_set_drvdata(&az->vdev, az); 377 video_set_drvdata(&az->vdev, az);
378 /* mute card - prevents noisy bootups */
379 outb(0, az->io);
378 380
379 if (video_register_device(&az->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 381 if (video_register_device(&az->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
380 v4l2_device_unregister(v4l2_dev); 382 v4l2_device_unregister(v4l2_dev);
@@ -383,8 +385,6 @@ static int __init aztech_init(void)
383 } 385 }
384 386
385 v4l2_info(v4l2_dev, "Aztech radio card driver v1.00/19990224 rkroll@exploits.org\n"); 387 v4l2_info(v4l2_dev, "Aztech radio card driver v1.00/19990224 rkroll@exploits.org\n");
386 /* mute card - prevents noisy bootups */
387 outb(0, az->io);
388 return 0; 388 return 0;
389} 389}
390 390
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index b701ea6e7c73..bc9ad0897c55 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -328,11 +328,10 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
328 unsigned char readbuf[RDS_BUFFER]; 328 unsigned char readbuf[RDS_BUFFER];
329 int i = 0; 329 int i = 0;
330 330
331 mutex_lock(&dev->lock);
331 if (dev->rdsstat == 0) { 332 if (dev->rdsstat == 0) {
332 mutex_lock(&dev->lock);
333 dev->rdsstat = 1; 333 dev->rdsstat = 1;
334 outb(0x80, dev->io); /* Select RDS fifo */ 334 outb(0x80, dev->io); /* Select RDS fifo */
335 mutex_unlock(&dev->lock);
336 init_timer(&dev->readtimer); 335 init_timer(&dev->readtimer);
337 dev->readtimer.function = cadet_handler; 336 dev->readtimer.function = cadet_handler;
338 dev->readtimer.data = (unsigned long)dev; 337 dev->readtimer.data = (unsigned long)dev;
@@ -340,12 +339,15 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
340 add_timer(&dev->readtimer); 339 add_timer(&dev->readtimer);
341 } 340 }
342 if (dev->rdsin == dev->rdsout) { 341 if (dev->rdsin == dev->rdsout) {
342 mutex_unlock(&dev->lock);
343 if (file->f_flags & O_NONBLOCK) 343 if (file->f_flags & O_NONBLOCK)
344 return -EWOULDBLOCK; 344 return -EWOULDBLOCK;
345 interruptible_sleep_on(&dev->read_queue); 345 interruptible_sleep_on(&dev->read_queue);
346 mutex_lock(&dev->lock);
346 } 347 }
347 while (i < count && dev->rdsin != dev->rdsout) 348 while (i < count && dev->rdsin != dev->rdsout)
348 readbuf[i++] = dev->rdsbuf[dev->rdsout++]; 349 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
350 mutex_unlock(&dev->lock);
349 351
350 if (copy_to_user(data, readbuf, i)) 352 if (copy_to_user(data, readbuf, i))
351 return -EFAULT; 353 return -EFAULT;
@@ -525,9 +527,11 @@ static int cadet_open(struct file *file)
525{ 527{
526 struct cadet *dev = video_drvdata(file); 528 struct cadet *dev = video_drvdata(file);
527 529
530 mutex_lock(&dev->lock);
528 dev->users++; 531 dev->users++;
529 if (1 == dev->users) 532 if (1 == dev->users)
530 init_waitqueue_head(&dev->read_queue); 533 init_waitqueue_head(&dev->read_queue);
534 mutex_unlock(&dev->lock);
531 return 0; 535 return 0;
532} 536}
533 537
@@ -535,11 +539,13 @@ static int cadet_release(struct file *file)
535{ 539{
536 struct cadet *dev = video_drvdata(file); 540 struct cadet *dev = video_drvdata(file);
537 541
542 mutex_lock(&dev->lock);
538 dev->users--; 543 dev->users--;
539 if (0 == dev->users) { 544 if (0 == dev->users) {
540 del_timer_sync(&dev->readtimer); 545 del_timer_sync(&dev->readtimer);
541 dev->rdsstat = 0; 546 dev->rdsstat = 0;
542 } 547 }
548 mutex_unlock(&dev->lock);
543 return 0; 549 return 0;
544} 550}
545 551
@@ -559,7 +565,7 @@ static const struct v4l2_file_operations cadet_fops = {
559 .open = cadet_open, 565 .open = cadet_open,
560 .release = cadet_release, 566 .release = cadet_release,
561 .read = cadet_read, 567 .read = cadet_read,
562 .ioctl = video_ioctl2, 568 .unlocked_ioctl = video_ioctl2,
563 .poll = cadet_poll, 569 .poll = cadet_poll,
564}; 570};
565 571
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index 79039674a0e0..28fa85ba2087 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -361,7 +361,7 @@ MODULE_DEVICE_TABLE(pci, gemtek_pci_id);
361 361
362static const struct v4l2_file_operations gemtek_pci_fops = { 362static const struct v4l2_file_operations gemtek_pci_fops = {
363 .owner = THIS_MODULE, 363 .owner = THIS_MODULE,
364 .ioctl = video_ioctl2, 364 .unlocked_ioctl = video_ioctl2,
365}; 365};
366 366
367static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = { 367static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = {
@@ -422,11 +422,11 @@ static int __devinit gemtek_pci_probe(struct pci_dev *pdev, const struct pci_dev
422 card->vdev.release = video_device_release_empty; 422 card->vdev.release = video_device_release_empty;
423 video_set_drvdata(&card->vdev, card); 423 video_set_drvdata(&card->vdev, card);
424 424
425 gemtek_pci_mute(card);
426
425 if (video_register_device(&card->vdev, VFL_TYPE_RADIO, nr_radio) < 0) 427 if (video_register_device(&card->vdev, VFL_TYPE_RADIO, nr_radio) < 0)
426 goto err_video; 428 goto err_video;
427 429
428 gemtek_pci_mute(card);
429
430 v4l2_info(v4l2_dev, "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n", 430 v4l2_info(v4l2_dev, "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n",
431 pdev->revision, card->iobase, card->iobase + card->length - 1); 431 pdev->revision, card->iobase, card->iobase + card->length - 1);
432 432
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index 73985f641f07..259936422e49 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -378,7 +378,7 @@ static int gemtek_probe(struct gemtek *gt)
378 378
379static const struct v4l2_file_operations gemtek_fops = { 379static const struct v4l2_file_operations gemtek_fops = {
380 .owner = THIS_MODULE, 380 .owner = THIS_MODULE,
381 .ioctl = video_ioctl2, 381 .unlocked_ioctl = video_ioctl2,
382}; 382};
383 383
384static int vidioc_querycap(struct file *file, void *priv, 384static int vidioc_querycap(struct file *file, void *priv,
@@ -577,12 +577,6 @@ static int __init gemtek_init(void)
577 gt->vdev.release = video_device_release_empty; 577 gt->vdev.release = video_device_release_empty;
578 video_set_drvdata(&gt->vdev, gt); 578 video_set_drvdata(&gt->vdev, gt);
579 579
580 if (video_register_device(&gt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
581 v4l2_device_unregister(v4l2_dev);
582 release_region(gt->io, 1);
583 return -EBUSY;
584 }
585
586 /* Set defaults */ 580 /* Set defaults */
587 gt->lastfreq = GEMTEK_LOWFREQ; 581 gt->lastfreq = GEMTEK_LOWFREQ;
588 gt->bu2614data = 0; 582 gt->bu2614data = 0;
@@ -590,6 +584,12 @@ static int __init gemtek_init(void)
590 if (initmute) 584 if (initmute)
591 gemtek_mute(gt); 585 gemtek_mute(gt);
592 586
587 if (video_register_device(&gt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
588 v4l2_device_unregister(v4l2_dev);
589 release_region(gt->io, 1);
590 return -EBUSY;
591 }
592
593 return 0; 593 return 0;
594} 594}
595 595
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index 08f1051979ca..6af61bfeb178 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -299,7 +299,7 @@ static int vidioc_s_audio(struct file *file, void *priv,
299 299
300static const struct v4l2_file_operations maestro_fops = { 300static const struct v4l2_file_operations maestro_fops = {
301 .owner = THIS_MODULE, 301 .owner = THIS_MODULE,
302 .ioctl = video_ioctl2, 302 .unlocked_ioctl = video_ioctl2,
303}; 303};
304 304
305static const struct v4l2_ioctl_ops maestro_ioctl_ops = { 305static const struct v4l2_ioctl_ops maestro_ioctl_ops = {
@@ -383,22 +383,20 @@ static int __devinit maestro_probe(struct pci_dev *pdev,
383 dev->vdev.release = video_device_release_empty; 383 dev->vdev.release = video_device_release_empty;
384 video_set_drvdata(&dev->vdev, dev); 384 video_set_drvdata(&dev->vdev, dev);
385 385
386 if (!radio_power_on(dev)) {
387 retval = -EIO;
388 goto errfr1;
389 }
390
386 retval = video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr); 391 retval = video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr);
387 if (retval) { 392 if (retval) {
388 v4l2_err(v4l2_dev, "can't register video device!\n"); 393 v4l2_err(v4l2_dev, "can't register video device!\n");
389 goto errfr1; 394 goto errfr1;
390 } 395 }
391 396
392 if (!radio_power_on(dev)) {
393 retval = -EIO;
394 goto errunr;
395 }
396
397 v4l2_info(v4l2_dev, "version " DRIVER_VERSION "\n"); 397 v4l2_info(v4l2_dev, "version " DRIVER_VERSION "\n");
398 398
399 return 0; 399 return 0;
400errunr:
401 video_unregister_device(&dev->vdev);
402errfr1: 400errfr1:
403 v4l2_device_unregister(v4l2_dev); 401 v4l2_device_unregister(v4l2_dev);
404errfr: 402errfr:
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index 255d40df4b46..6459a220b0dd 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -346,7 +346,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
346 346
347static const struct v4l2_file_operations maxiradio_fops = { 347static const struct v4l2_file_operations maxiradio_fops = {
348 .owner = THIS_MODULE, 348 .owner = THIS_MODULE,
349 .ioctl = video_ioctl2, 349 .unlocked_ioctl = video_ioctl2,
350}; 350};
351 351
352static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = { 352static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
diff --git a/drivers/media/radio/radio-miropcm20.c b/drivers/media/radio/radio-miropcm20.c
index 4ff885445fd4..3fb76e3834c9 100644
--- a/drivers/media/radio/radio-miropcm20.c
+++ b/drivers/media/radio/radio-miropcm20.c
@@ -33,6 +33,7 @@ struct pcm20 {
33 unsigned long freq; 33 unsigned long freq;
34 int muted; 34 int muted;
35 struct snd_miro_aci *aci; 35 struct snd_miro_aci *aci;
36 struct mutex lock;
36}; 37};
37 38
38static struct pcm20 pcm20_card = { 39static struct pcm20 pcm20_card = {
@@ -72,7 +73,7 @@ static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)
72 73
73static const struct v4l2_file_operations pcm20_fops = { 74static const struct v4l2_file_operations pcm20_fops = {
74 .owner = THIS_MODULE, 75 .owner = THIS_MODULE,
75 .ioctl = video_ioctl2, 76 .unlocked_ioctl = video_ioctl2,
76}; 77};
77 78
78static int vidioc_querycap(struct file *file, void *priv, 79static int vidioc_querycap(struct file *file, void *priv,
@@ -229,7 +230,7 @@ static int __init pcm20_init(void)
229 return -ENODEV; 230 return -ENODEV;
230 } 231 }
231 strlcpy(v4l2_dev->name, "miropcm20", sizeof(v4l2_dev->name)); 232 strlcpy(v4l2_dev->name, "miropcm20", sizeof(v4l2_dev->name));
232 233 mutex_init(&dev->lock);
233 234
234 res = v4l2_device_register(NULL, v4l2_dev); 235 res = v4l2_device_register(NULL, v4l2_dev);
235 if (res < 0) { 236 if (res < 0) {
@@ -242,6 +243,7 @@ static int __init pcm20_init(void)
242 dev->vdev.fops = &pcm20_fops; 243 dev->vdev.fops = &pcm20_fops;
243 dev->vdev.ioctl_ops = &pcm20_ioctl_ops; 244 dev->vdev.ioctl_ops = &pcm20_ioctl_ops;
244 dev->vdev.release = video_device_release_empty; 245 dev->vdev.release = video_device_release_empty;
246 dev->vdev.lock = &dev->lock;
245 video_set_drvdata(&dev->vdev, dev); 247 video_set_drvdata(&dev->vdev, dev);
246 248
247 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) 249 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0)
diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
index b540e8072e92..e6b2d085a449 100644
--- a/drivers/media/radio/radio-mr800.c
+++ b/drivers/media/radio/radio-mr800.c
@@ -58,7 +58,6 @@
58#include <linux/module.h> 58#include <linux/module.h>
59#include <linux/init.h> 59#include <linux/init.h>
60#include <linux/slab.h> 60#include <linux/slab.h>
61#include <linux/smp_lock.h>
62#include <linux/input.h> 61#include <linux/input.h>
63#include <linux/videodev2.h> 62#include <linux/videodev2.h>
64#include <media/v4l2-device.h> 63#include <media/v4l2-device.h>
diff --git a/drivers/media/radio/radio-rtrack2.c b/drivers/media/radio/radio-rtrack2.c
index a79296aac9a9..8d6ea591bd18 100644
--- a/drivers/media/radio/radio-rtrack2.c
+++ b/drivers/media/radio/radio-rtrack2.c
@@ -266,7 +266,7 @@ static int vidioc_s_audio(struct file *file, void *priv,
266 266
267static const struct v4l2_file_operations rtrack2_fops = { 267static const struct v4l2_file_operations rtrack2_fops = {
268 .owner = THIS_MODULE, 268 .owner = THIS_MODULE,
269 .ioctl = video_ioctl2, 269 .unlocked_ioctl = video_ioctl2,
270}; 270};
271 271
272static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = { 272static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = {
@@ -315,6 +315,10 @@ static int __init rtrack2_init(void)
315 dev->vdev.release = video_device_release_empty; 315 dev->vdev.release = video_device_release_empty;
316 video_set_drvdata(&dev->vdev, dev); 316 video_set_drvdata(&dev->vdev, dev);
317 317
318 /* mute card - prevents noisy bootups */
319 outb(1, dev->io);
320 dev->muted = 1;
321
318 mutex_init(&dev->lock); 322 mutex_init(&dev->lock);
319 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 323 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
320 v4l2_device_unregister(v4l2_dev); 324 v4l2_device_unregister(v4l2_dev);
@@ -324,10 +328,6 @@ static int __init rtrack2_init(void)
324 328
325 v4l2_info(v4l2_dev, "AIMSlab Radiotrack II card driver.\n"); 329 v4l2_info(v4l2_dev, "AIMSlab Radiotrack II card driver.\n");
326 330
327 /* mute card - prevents noisy bootups */
328 outb(1, dev->io);
329 dev->muted = 1;
330
331 return 0; 331 return 0;
332} 332}
333 333
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index 985359d18aa5..b5a5f89e238a 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -260,7 +260,7 @@ static int vidioc_s_audio(struct file *file, void *priv,
260 260
261static const struct v4l2_file_operations fmi_fops = { 261static const struct v4l2_file_operations fmi_fops = {
262 .owner = THIS_MODULE, 262 .owner = THIS_MODULE,
263 .ioctl = video_ioctl2, 263 .unlocked_ioctl = video_ioctl2,
264}; 264};
265 265
266static const struct v4l2_ioctl_ops fmi_ioctl_ops = { 266static const struct v4l2_ioctl_ops fmi_ioctl_ops = {
@@ -382,6 +382,9 @@ static int __init fmi_init(void)
382 382
383 mutex_init(&fmi->lock); 383 mutex_init(&fmi->lock);
384 384
385 /* mute card - prevents noisy bootups */
386 fmi_mute(fmi);
387
385 if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 388 if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
386 v4l2_device_unregister(v4l2_dev); 389 v4l2_device_unregister(v4l2_dev);
387 release_region(fmi->io, 2); 390 release_region(fmi->io, 2);
@@ -391,8 +394,6 @@ static int __init fmi_init(void)
391 } 394 }
392 395
393 v4l2_info(v4l2_dev, "card driver at 0x%x\n", fmi->io); 396 v4l2_info(v4l2_dev, "card driver at 0x%x\n", fmi->io);
394 /* mute card - prevents noisy bootups */
395 fmi_mute(fmi);
396 return 0; 397 return 0;
397} 398}
398 399
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index 52c7bbb32b8b..dc3f04c52d5e 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -376,7 +376,7 @@ static int vidioc_s_audio(struct file *file, void *priv,
376 376
377static const struct v4l2_file_operations fmr2_fops = { 377static const struct v4l2_file_operations fmr2_fops = {
378 .owner = THIS_MODULE, 378 .owner = THIS_MODULE,
379 .ioctl = video_ioctl2, 379 .unlocked_ioctl = video_ioctl2,
380}; 380};
381 381
382static const struct v4l2_ioctl_ops fmr2_ioctl_ops = { 382static const struct v4l2_ioctl_ops fmr2_ioctl_ops = {
@@ -424,6 +424,10 @@ static int __init fmr2_init(void)
424 fmr2->vdev.release = video_device_release_empty; 424 fmr2->vdev.release = video_device_release_empty;
425 video_set_drvdata(&fmr2->vdev, fmr2); 425 video_set_drvdata(&fmr2->vdev, fmr2);
426 426
427 /* mute card - prevents noisy bootups */
428 fmr2_mute(fmr2->io);
429 fmr2_product_info(fmr2);
430
427 if (video_register_device(&fmr2->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 431 if (video_register_device(&fmr2->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
428 v4l2_device_unregister(v4l2_dev); 432 v4l2_device_unregister(v4l2_dev);
429 release_region(fmr2->io, 2); 433 release_region(fmr2->io, 2);
@@ -431,11 +435,6 @@ static int __init fmr2_init(void)
431 } 435 }
432 436
433 v4l2_info(v4l2_dev, "SF16FMR2 radio card driver at 0x%x.\n", fmr2->io); 437 v4l2_info(v4l2_dev, "SF16FMR2 radio card driver at 0x%x.\n", fmr2->io);
434 /* mute card - prevents noisy bootups */
435 mutex_lock(&fmr2->lock);
436 fmr2_mute(fmr2->io);
437 fmr2_product_info(fmr2);
438 mutex_unlock(&fmr2->lock);
439 debug_print((KERN_DEBUG "card_type %d\n", fmr2->card_type)); 438 debug_print((KERN_DEBUG "card_type %d\n", fmr2->card_type));
440 return 0; 439 return 0;
441} 440}
diff --git a/drivers/media/radio/radio-si4713.c b/drivers/media/radio/radio-si4713.c
index 6a435786b63d..726d367ad8d0 100644
--- a/drivers/media/radio/radio-si4713.c
+++ b/drivers/media/radio/radio-si4713.c
@@ -53,7 +53,8 @@ struct radio_si4713_device {
53/* radio_si4713_fops - file operations interface */ 53/* radio_si4713_fops - file operations interface */
54static const struct v4l2_file_operations radio_si4713_fops = { 54static const struct v4l2_file_operations radio_si4713_fops = {
55 .owner = THIS_MODULE, 55 .owner = THIS_MODULE,
56 .ioctl = video_ioctl2, 56 /* Note: locking is done at the subdev level in the i2c driver. */
57 .unlocked_ioctl = video_ioctl2,
57}; 58};
58 59
59/* Video4Linux Interface */ 60/* Video4Linux Interface */
@@ -291,7 +292,7 @@ static int radio_si4713_pdriver_probe(struct platform_device *pdev)
291 goto unregister_v4l2_dev; 292 goto unregister_v4l2_dev;
292 } 293 }
293 294
294 sd = v4l2_i2c_new_subdev_board(&rsdev->v4l2_dev, adapter, NULL, 295 sd = v4l2_i2c_new_subdev_board(&rsdev->v4l2_dev, adapter,
295 pdata->subdev_board_info, NULL); 296 pdata->subdev_board_info, NULL);
296 if (!sd) { 297 if (!sd) {
297 dev_err(&pdev->dev, "Cannot get v4l2 subdevice\n"); 298 dev_err(&pdev->dev, "Cannot get v4l2 subdevice\n");
diff --git a/drivers/media/radio/radio-tea5764.c b/drivers/media/radio/radio-tea5764.c
index 789d2ec66e19..0e71d816c725 100644
--- a/drivers/media/radio/radio-tea5764.c
+++ b/drivers/media/radio/radio-tea5764.c
@@ -142,7 +142,6 @@ struct tea5764_device {
142 struct video_device *videodev; 142 struct video_device *videodev;
143 struct tea5764_regs regs; 143 struct tea5764_regs regs;
144 struct mutex mutex; 144 struct mutex mutex;
145 int users;
146}; 145};
147 146
148/* I2C code related */ 147/* I2C code related */
@@ -458,41 +457,10 @@ static int vidioc_s_audio(struct file *file, void *priv,
458 return 0; 457 return 0;
459} 458}
460 459
461static int tea5764_open(struct file *file)
462{
463 /* Currently we support only one device */
464 struct tea5764_device *radio = video_drvdata(file);
465
466 mutex_lock(&radio->mutex);
467 /* Only exclusive access */
468 if (radio->users) {
469 mutex_unlock(&radio->mutex);
470 return -EBUSY;
471 }
472 radio->users++;
473 mutex_unlock(&radio->mutex);
474 file->private_data = radio;
475 return 0;
476}
477
478static int tea5764_close(struct file *file)
479{
480 struct tea5764_device *radio = video_drvdata(file);
481
482 if (!radio)
483 return -ENODEV;
484 mutex_lock(&radio->mutex);
485 radio->users--;
486 mutex_unlock(&radio->mutex);
487 return 0;
488}
489
490/* File system interface */ 460/* File system interface */
491static const struct v4l2_file_operations tea5764_fops = { 461static const struct v4l2_file_operations tea5764_fops = {
492 .owner = THIS_MODULE, 462 .owner = THIS_MODULE,
493 .open = tea5764_open, 463 .unlocked_ioctl = video_ioctl2,
494 .release = tea5764_close,
495 .ioctl = video_ioctl2,
496}; 464};
497 465
498static const struct v4l2_ioctl_ops tea5764_ioctl_ops = { 466static const struct v4l2_ioctl_ops tea5764_ioctl_ops = {
@@ -527,7 +495,7 @@ static int __devinit tea5764_i2c_probe(struct i2c_client *client,
527 int ret; 495 int ret;
528 496
529 PDEBUG("probe"); 497 PDEBUG("probe");
530 radio = kmalloc(sizeof(struct tea5764_device), GFP_KERNEL); 498 radio = kzalloc(sizeof(struct tea5764_device), GFP_KERNEL);
531 if (!radio) 499 if (!radio)
532 return -ENOMEM; 500 return -ENOMEM;
533 501
@@ -555,12 +523,7 @@ static int __devinit tea5764_i2c_probe(struct i2c_client *client,
555 523
556 i2c_set_clientdata(client, radio); 524 i2c_set_clientdata(client, radio);
557 video_set_drvdata(radio->videodev, radio); 525 video_set_drvdata(radio->videodev, radio);
558 526 radio->videodev->lock = &radio->mutex;
559 ret = video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr);
560 if (ret < 0) {
561 PWARN("Could not register video device!");
562 goto errrel;
563 }
564 527
565 /* initialize and power off the chip */ 528 /* initialize and power off the chip */
566 tea5764_i2c_read(radio); 529 tea5764_i2c_read(radio);
@@ -568,6 +531,12 @@ static int __devinit tea5764_i2c_probe(struct i2c_client *client,
568 tea5764_mute(radio, 1); 531 tea5764_mute(radio, 1);
569 tea5764_power_down(radio); 532 tea5764_power_down(radio);
570 533
534 ret = video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr);
535 if (ret < 0) {
536 PWARN("Could not register video device!");
537 goto errrel;
538 }
539
571 PINFO("registered."); 540 PINFO("registered.");
572 return 0; 541 return 0;
573errrel: 542errrel:
diff --git a/drivers/media/radio/radio-terratec.c b/drivers/media/radio/radio-terratec.c
index fc1c860fd438..a32663917059 100644
--- a/drivers/media/radio/radio-terratec.c
+++ b/drivers/media/radio/radio-terratec.c
@@ -338,7 +338,7 @@ static int vidioc_s_audio(struct file *file, void *priv,
338 338
339static const struct v4l2_file_operations terratec_fops = { 339static const struct v4l2_file_operations terratec_fops = {
340 .owner = THIS_MODULE, 340 .owner = THIS_MODULE,
341 .ioctl = video_ioctl2, 341 .unlocked_ioctl = video_ioctl2,
342}; 342};
343 343
344static const struct v4l2_ioctl_ops terratec_ioctl_ops = { 344static const struct v4l2_ioctl_ops terratec_ioctl_ops = {
@@ -389,6 +389,9 @@ static int __init terratec_init(void)
389 389
390 mutex_init(&tt->lock); 390 mutex_init(&tt->lock);
391 391
392 /* mute card - prevents noisy bootups */
393 tt_write_vol(tt, 0);
394
392 if (video_register_device(&tt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 395 if (video_register_device(&tt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
393 v4l2_device_unregister(&tt->v4l2_dev); 396 v4l2_device_unregister(&tt->v4l2_dev);
394 release_region(tt->io, 2); 397 release_region(tt->io, 2);
@@ -396,9 +399,6 @@ static int __init terratec_init(void)
396 } 399 }
397 400
398 v4l2_info(v4l2_dev, "TERRATEC ActivRadio Standalone card driver.\n"); 401 v4l2_info(v4l2_dev, "TERRATEC ActivRadio Standalone card driver.\n");
399
400 /* mute card - prevents noisy bootups */
401 tt_write_vol(tt, 0);
402 return 0; 402 return 0;
403} 403}
404 404
diff --git a/drivers/media/radio/radio-timb.c b/drivers/media/radio/radio-timb.c
index b8bb3ef47df5..a185610b376b 100644
--- a/drivers/media/radio/radio-timb.c
+++ b/drivers/media/radio/radio-timb.c
@@ -34,6 +34,7 @@ struct timbradio {
34 struct v4l2_subdev *sd_dsp; 34 struct v4l2_subdev *sd_dsp;
35 struct video_device video_dev; 35 struct video_device video_dev;
36 struct v4l2_device v4l2_dev; 36 struct v4l2_device v4l2_dev;
37 struct mutex lock;
37}; 38};
38 39
39 40
@@ -142,7 +143,7 @@ static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
142 143
143static const struct v4l2_file_operations timbradio_fops = { 144static const struct v4l2_file_operations timbradio_fops = {
144 .owner = THIS_MODULE, 145 .owner = THIS_MODULE,
145 .ioctl = video_ioctl2, 146 .unlocked_ioctl = video_ioctl2,
146}; 147};
147 148
148static int __devinit timbradio_probe(struct platform_device *pdev) 149static int __devinit timbradio_probe(struct platform_device *pdev)
@@ -164,6 +165,7 @@ static int __devinit timbradio_probe(struct platform_device *pdev)
164 } 165 }
165 166
166 tr->pdata = *pdata; 167 tr->pdata = *pdata;
168 mutex_init(&tr->lock);
167 169
168 strlcpy(tr->video_dev.name, "Timberdale Radio", 170 strlcpy(tr->video_dev.name, "Timberdale Radio",
169 sizeof(tr->video_dev.name)); 171 sizeof(tr->video_dev.name));
@@ -171,6 +173,7 @@ static int __devinit timbradio_probe(struct platform_device *pdev)
171 tr->video_dev.ioctl_ops = &timbradio_ioctl_ops; 173 tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
172 tr->video_dev.release = video_device_release_empty; 174 tr->video_dev.release = video_device_release_empty;
173 tr->video_dev.minor = -1; 175 tr->video_dev.minor = -1;
176 tr->video_dev.lock = &tr->lock;
174 177
175 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name)); 178 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
176 err = v4l2_device_register(NULL, &tr->v4l2_dev); 179 err = v4l2_device_register(NULL, &tr->v4l2_dev);
diff --git a/drivers/media/radio/radio-trust.c b/drivers/media/radio/radio-trust.c
index 9d6dcf8af5b0..22fa9cc28abe 100644
--- a/drivers/media/radio/radio-trust.c
+++ b/drivers/media/radio/radio-trust.c
@@ -344,7 +344,7 @@ static int vidioc_s_audio(struct file *file, void *priv,
344 344
345static const struct v4l2_file_operations trust_fops = { 345static const struct v4l2_file_operations trust_fops = {
346 .owner = THIS_MODULE, 346 .owner = THIS_MODULE,
347 .ioctl = video_ioctl2, 347 .unlocked_ioctl = video_ioctl2,
348}; 348};
349 349
350static const struct v4l2_ioctl_ops trust_ioctl_ops = { 350static const struct v4l2_ioctl_ops trust_ioctl_ops = {
@@ -396,14 +396,6 @@ static int __init trust_init(void)
396 tr->vdev.release = video_device_release_empty; 396 tr->vdev.release = video_device_release_empty;
397 video_set_drvdata(&tr->vdev, tr); 397 video_set_drvdata(&tr->vdev, tr);
398 398
399 if (video_register_device(&tr->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
400 v4l2_device_unregister(v4l2_dev);
401 release_region(tr->io, 2);
402 return -EINVAL;
403 }
404
405 v4l2_info(v4l2_dev, "Trust FM Radio card driver v1.0.\n");
406
407 write_i2c(tr, 2, TDA7318_ADDR, 0x80); /* speaker att. LF = 0 dB */ 399 write_i2c(tr, 2, TDA7318_ADDR, 0x80); /* speaker att. LF = 0 dB */
408 write_i2c(tr, 2, TDA7318_ADDR, 0xa0); /* speaker att. RF = 0 dB */ 400 write_i2c(tr, 2, TDA7318_ADDR, 0xa0); /* speaker att. RF = 0 dB */
409 write_i2c(tr, 2, TDA7318_ADDR, 0xc0); /* speaker att. LR = 0 dB */ 401 write_i2c(tr, 2, TDA7318_ADDR, 0xc0); /* speaker att. LR = 0 dB */
@@ -418,6 +410,14 @@ static int __init trust_init(void)
418 /* mute card - prevents noisy bootups */ 410 /* mute card - prevents noisy bootups */
419 tr_setmute(tr, 1); 411 tr_setmute(tr, 1);
420 412
413 if (video_register_device(&tr->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
414 v4l2_device_unregister(v4l2_dev);
415 release_region(tr->io, 2);
416 return -EINVAL;
417 }
418
419 v4l2_info(v4l2_dev, "Trust FM Radio card driver v1.0.\n");
420
421 return 0; 421 return 0;
422} 422}
423 423
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c
index b1f630527dc1..8dbbf08f2207 100644
--- a/drivers/media/radio/radio-typhoon.c
+++ b/drivers/media/radio/radio-typhoon.c
@@ -317,7 +317,7 @@ static int vidioc_log_status(struct file *file, void *priv)
317 317
318static const struct v4l2_file_operations typhoon_fops = { 318static const struct v4l2_file_operations typhoon_fops = {
319 .owner = THIS_MODULE, 319 .owner = THIS_MODULE,
320 .ioctl = video_ioctl2, 320 .unlocked_ioctl = video_ioctl2,
321}; 321};
322 322
323static const struct v4l2_ioctl_ops typhoon_ioctl_ops = { 323static const struct v4l2_ioctl_ops typhoon_ioctl_ops = {
@@ -344,18 +344,18 @@ static int __init typhoon_init(void)
344 344
345 strlcpy(v4l2_dev->name, "typhoon", sizeof(v4l2_dev->name)); 345 strlcpy(v4l2_dev->name, "typhoon", sizeof(v4l2_dev->name));
346 dev->io = io; 346 dev->io = io;
347 dev->curfreq = dev->mutefreq = mutefreq;
348 347
349 if (dev->io == -1) { 348 if (dev->io == -1) {
350 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x316 or io=0x336\n"); 349 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x316 or io=0x336\n");
351 return -EINVAL; 350 return -EINVAL;
352 } 351 }
353 352
354 if (dev->mutefreq < 87000 || dev->mutefreq > 108500) { 353 if (mutefreq < 87000 || mutefreq > 108500) {
355 v4l2_err(v4l2_dev, "You must set a frequency (in kHz) used when muting the card,\n"); 354 v4l2_err(v4l2_dev, "You must set a frequency (in kHz) used when muting the card,\n");
356 v4l2_err(v4l2_dev, "e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n"); 355 v4l2_err(v4l2_dev, "e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n");
357 return -EINVAL; 356 return -EINVAL;
358 } 357 }
358 dev->curfreq = dev->mutefreq = mutefreq << 4;
359 359
360 mutex_init(&dev->lock); 360 mutex_init(&dev->lock);
361 if (!request_region(dev->io, 8, "typhoon")) { 361 if (!request_region(dev->io, 8, "typhoon")) {
@@ -378,17 +378,17 @@ static int __init typhoon_init(void)
378 dev->vdev.ioctl_ops = &typhoon_ioctl_ops; 378 dev->vdev.ioctl_ops = &typhoon_ioctl_ops;
379 dev->vdev.release = video_device_release_empty; 379 dev->vdev.release = video_device_release_empty;
380 video_set_drvdata(&dev->vdev, dev); 380 video_set_drvdata(&dev->vdev, dev);
381
382 /* mute card - prevents noisy bootups */
383 typhoon_mute(dev);
384
381 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 385 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
382 v4l2_device_unregister(&dev->v4l2_dev); 386 v4l2_device_unregister(&dev->v4l2_dev);
383 release_region(dev->io, 8); 387 release_region(dev->io, 8);
384 return -EINVAL; 388 return -EINVAL;
385 } 389 }
386 v4l2_info(v4l2_dev, "port 0x%x.\n", dev->io); 390 v4l2_info(v4l2_dev, "port 0x%x.\n", dev->io);
387 v4l2_info(v4l2_dev, "mute frequency is %lu kHz.\n", dev->mutefreq); 391 v4l2_info(v4l2_dev, "mute frequency is %lu kHz.\n", mutefreq);
388 dev->mutefreq <<= 4;
389
390 /* mute card - prevents noisy bootups */
391 typhoon_mute(dev);
392 392
393 return 0; 393 return 0;
394} 394}
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index f31eab99c943..af99c5bd88c1 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -377,7 +377,7 @@ static int vidioc_s_audio(struct file *file, void *priv,
377static const struct v4l2_file_operations zoltrix_fops = 377static const struct v4l2_file_operations zoltrix_fops =
378{ 378{
379 .owner = THIS_MODULE, 379 .owner = THIS_MODULE,
380 .ioctl = video_ioctl2, 380 .unlocked_ioctl = video_ioctl2,
381}; 381};
382 382
383static const struct v4l2_ioctl_ops zoltrix_ioctl_ops = { 383static const struct v4l2_ioctl_ops zoltrix_ioctl_ops = {
@@ -424,20 +424,6 @@ static int __init zoltrix_init(void)
424 return res; 424 return res;
425 } 425 }
426 426
427 strlcpy(zol->vdev.name, v4l2_dev->name, sizeof(zol->vdev.name));
428 zol->vdev.v4l2_dev = v4l2_dev;
429 zol->vdev.fops = &zoltrix_fops;
430 zol->vdev.ioctl_ops = &zoltrix_ioctl_ops;
431 zol->vdev.release = video_device_release_empty;
432 video_set_drvdata(&zol->vdev, zol);
433
434 if (video_register_device(&zol->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
435 v4l2_device_unregister(v4l2_dev);
436 release_region(zol->io, 2);
437 return -EINVAL;
438 }
439 v4l2_info(v4l2_dev, "Zoltrix Radio Plus card driver.\n");
440
441 mutex_init(&zol->lock); 427 mutex_init(&zol->lock);
442 428
443 /* mute card - prevents noisy bootups */ 429 /* mute card - prevents noisy bootups */
@@ -452,6 +438,20 @@ static int __init zoltrix_init(void)
452 zol->curvol = 0; 438 zol->curvol = 0;
453 zol->stereo = 1; 439 zol->stereo = 1;
454 440
441 strlcpy(zol->vdev.name, v4l2_dev->name, sizeof(zol->vdev.name));
442 zol->vdev.v4l2_dev = v4l2_dev;
443 zol->vdev.fops = &zoltrix_fops;
444 zol->vdev.ioctl_ops = &zoltrix_ioctl_ops;
445 zol->vdev.release = video_device_release_empty;
446 video_set_drvdata(&zol->vdev, zol);
447
448 if (video_register_device(&zol->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
449 v4l2_device_unregister(v4l2_dev);
450 release_region(zol->io, 2);
451 return -EINVAL;
452 }
453 v4l2_info(v4l2_dev, "Zoltrix Radio Plus card driver.\n");
454
455 return 0; 455 return 0;
456} 456}
457 457
diff --git a/drivers/media/radio/si470x/radio-si470x.h b/drivers/media/radio/si470x/radio-si470x.h
index ea12782359a0..b9914d7a0c9f 100644
--- a/drivers/media/radio/si470x/radio-si470x.h
+++ b/drivers/media/radio/si470x/radio-si470x.h
@@ -31,7 +31,6 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/sched.h> 32#include <linux/sched.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/smp_lock.h>
35#include <linux/input.h> 34#include <linux/input.h>
36#include <linux/version.h> 35#include <linux/version.h>
37#include <linux/videodev2.h> 36#include <linux/videodev2.h>
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index ac16e815e275..6830d2848bd7 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -112,7 +112,7 @@ config VIDEO_IR_I2C
112# 112#
113 113
114menu "Encoders/decoders and other helper chips" 114menu "Encoders/decoders and other helper chips"
115 depends on !VIDEO_HELPER_CHIPS_AUTO 115 visible if !VIDEO_HELPER_CHIPS_AUTO
116 116
117comment "Audio decoders" 117comment "Audio decoders"
118 118
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index 31e7a123d19a..f989f2820d88 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -712,7 +712,7 @@ static int ar_initialize(struct ar *ar)
712static const struct v4l2_file_operations ar_fops = { 712static const struct v4l2_file_operations ar_fops = {
713 .owner = THIS_MODULE, 713 .owner = THIS_MODULE,
714 .read = ar_read, 714 .read = ar_read,
715 .ioctl = video_ioctl2, 715 .unlocked_ioctl = video_ioctl2,
716}; 716};
717 717
718static const struct v4l2_ioctl_ops ar_ioctl_ops = { 718static const struct v4l2_ioctl_ops ar_ioctl_ops = {
diff --git a/drivers/media/video/au0828/au0828-cards.c b/drivers/media/video/au0828/au0828-cards.c
index 0453816d4ec3..01be89fa5c78 100644
--- a/drivers/media/video/au0828/au0828-cards.c
+++ b/drivers/media/video/au0828/au0828-cards.c
@@ -212,7 +212,7 @@ void au0828_card_setup(struct au0828_dev *dev)
212 be abstracted out if we ever need to support a different 212 be abstracted out if we ever need to support a different
213 demod) */ 213 demod) */
214 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 214 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
215 NULL, "au8522", 0x8e >> 1, NULL); 215 "au8522", 0x8e >> 1, NULL);
216 if (sd == NULL) 216 if (sd == NULL)
217 printk(KERN_ERR "analog subdev registration failed\n"); 217 printk(KERN_ERR "analog subdev registration failed\n");
218 } 218 }
@@ -221,7 +221,7 @@ void au0828_card_setup(struct au0828_dev *dev)
221 if (dev->board.tuner_type != TUNER_ABSENT) { 221 if (dev->board.tuner_type != TUNER_ABSENT) {
222 /* Load the tuner module, which does the attach */ 222 /* Load the tuner module, which does the attach */
223 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 223 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
224 NULL, "tuner", dev->board.tuner_addr, NULL); 224 "tuner", dev->board.tuner_addr, NULL);
225 if (sd == NULL) 225 if (sd == NULL)
226 printk(KERN_ERR "tuner subdev registration fail\n"); 226 printk(KERN_ERR "tuner subdev registration fail\n");
227 227
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index 87d8b006ef77..49efcf660ba6 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -3529,7 +3529,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
3529 struct v4l2_subdev *sd; 3529 struct v4l2_subdev *sd;
3530 3530
3531 sd = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3531 sd = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3532 &btv->c.i2c_adap, NULL, "saa6588", 0, addrs); 3532 &btv->c.i2c_adap, "saa6588", 0, addrs);
3533 btv->has_saa6588 = (sd != NULL); 3533 btv->has_saa6588 = (sd != NULL);
3534 } 3534 }
3535 3535
@@ -3554,7 +3554,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
3554 }; 3554 };
3555 3555
3556 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3556 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3557 &btv->c.i2c_adap, NULL, "msp3400", 0, addrs); 3557 &btv->c.i2c_adap, "msp3400", 0, addrs);
3558 if (btv->sd_msp34xx) 3558 if (btv->sd_msp34xx)
3559 return; 3559 return;
3560 goto no_audio; 3560 goto no_audio;
@@ -3568,7 +3568,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
3568 }; 3568 };
3569 3569
3570 if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3570 if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3571 &btv->c.i2c_adap, NULL, "tda7432", 0, addrs)) 3571 &btv->c.i2c_adap, "tda7432", 0, addrs))
3572 return; 3572 return;
3573 goto no_audio; 3573 goto no_audio;
3574 } 3574 }
@@ -3576,7 +3576,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
3576 case 3: { 3576 case 3: {
3577 /* The user specified that we should probe for tvaudio */ 3577 /* The user specified that we should probe for tvaudio */
3578 btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3578 btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3579 &btv->c.i2c_adap, NULL, "tvaudio", 0, tvaudio_addrs()); 3579 &btv->c.i2c_adap, "tvaudio", 0, tvaudio_addrs());
3580 if (btv->sd_tvaudio) 3580 if (btv->sd_tvaudio)
3581 return; 3581 return;
3582 goto no_audio; 3582 goto no_audio;
@@ -3596,11 +3596,11 @@ void __devinit bttv_init_card2(struct bttv *btv)
3596 found is really something else (e.g. a tea6300). */ 3596 found is really something else (e.g. a tea6300). */
3597 if (!bttv_tvcards[btv->c.type].no_msp34xx) { 3597 if (!bttv_tvcards[btv->c.type].no_msp34xx) {
3598 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3598 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3599 &btv->c.i2c_adap, NULL, "msp3400", 3599 &btv->c.i2c_adap, "msp3400",
3600 0, I2C_ADDRS(I2C_ADDR_MSP3400 >> 1)); 3600 0, I2C_ADDRS(I2C_ADDR_MSP3400 >> 1));
3601 } else if (bttv_tvcards[btv->c.type].msp34xx_alt) { 3601 } else if (bttv_tvcards[btv->c.type].msp34xx_alt) {
3602 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3602 btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3603 &btv->c.i2c_adap, NULL, "msp3400", 3603 &btv->c.i2c_adap, "msp3400",
3604 0, I2C_ADDRS(I2C_ADDR_MSP3400_ALT >> 1)); 3604 0, I2C_ADDRS(I2C_ADDR_MSP3400_ALT >> 1));
3605 } 3605 }
3606 3606
@@ -3616,13 +3616,13 @@ void __devinit bttv_init_card2(struct bttv *btv)
3616 }; 3616 };
3617 3617
3618 if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3618 if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3619 &btv->c.i2c_adap, NULL, "tda7432", 0, addrs)) 3619 &btv->c.i2c_adap, "tda7432", 0, addrs))
3620 return; 3620 return;
3621 } 3621 }
3622 3622
3623 /* Now see if we can find one of the tvaudio devices. */ 3623 /* Now see if we can find one of the tvaudio devices. */
3624 btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3624 btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3625 &btv->c.i2c_adap, NULL, "tvaudio", 0, tvaudio_addrs()); 3625 &btv->c.i2c_adap, "tvaudio", 0, tvaudio_addrs());
3626 if (btv->sd_tvaudio) 3626 if (btv->sd_tvaudio)
3627 return; 3627 return;
3628 3628
@@ -3646,13 +3646,13 @@ void __devinit bttv_init_tuner(struct bttv *btv)
3646 /* Load tuner module before issuing tuner config call! */ 3646 /* Load tuner module before issuing tuner config call! */
3647 if (bttv_tvcards[btv->c.type].has_radio) 3647 if (bttv_tvcards[btv->c.type].has_radio)
3648 v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3648 v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3649 &btv->c.i2c_adap, NULL, "tuner", 3649 &btv->c.i2c_adap, "tuner",
3650 0, v4l2_i2c_tuner_addrs(ADDRS_RADIO)); 3650 0, v4l2_i2c_tuner_addrs(ADDRS_RADIO));
3651 v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3651 v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3652 &btv->c.i2c_adap, NULL, "tuner", 3652 &btv->c.i2c_adap, "tuner",
3653 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); 3653 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
3654 v4l2_i2c_new_subdev(&btv->c.v4l2_dev, 3654 v4l2_i2c_new_subdev(&btv->c.v4l2_dev,
3655 &btv->c.i2c_adap, NULL, "tuner", 3655 &btv->c.i2c_adap, "tuner",
3656 0, v4l2_i2c_tuner_addrs(ADDRS_TV_WITH_DEMOD)); 3656 0, v4l2_i2c_tuner_addrs(ADDRS_TV_WITH_DEMOD));
3657 3657
3658 tun_setup.mode_mask = T_ANALOG_TV | T_DIGITAL_TV; 3658 tun_setup.mode_mask = T_ANALOG_TV | T_DIGITAL_TV;
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 3da6e80e1041..0902ec041c7a 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -42,7 +42,6 @@
42#include <linux/fs.h> 42#include <linux/fs.h>
43#include <linux/kernel.h> 43#include <linux/kernel.h>
44#include <linux/sched.h> 44#include <linux/sched.h>
45#include <linux/smp_lock.h>
46#include <linux/interrupt.h> 45#include <linux/interrupt.h>
47#include <linux/kdev_t.h> 46#include <linux/kdev_t.h>
48#include "bttvp.h" 47#include "bttvp.h"
@@ -855,7 +854,6 @@ int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit)
855 xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM; 854 xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM;
856 855
857 /* is it free? */ 856 /* is it free? */
858 mutex_lock(&btv->lock);
859 if (btv->resources & xbits) { 857 if (btv->resources & xbits) {
860 /* no, someone else uses it */ 858 /* no, someone else uses it */
861 goto fail; 859 goto fail;
@@ -885,11 +883,9 @@ int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit)
885 /* it's free, grab it */ 883 /* it's free, grab it */
886 fh->resources |= bit; 884 fh->resources |= bit;
887 btv->resources |= bit; 885 btv->resources |= bit;
888 mutex_unlock(&btv->lock);
889 return 1; 886 return 1;
890 887
891 fail: 888 fail:
892 mutex_unlock(&btv->lock);
893 return 0; 889 return 0;
894} 890}
895 891
@@ -941,7 +937,6 @@ void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits)
941 /* trying to free ressources not allocated by us ... */ 937 /* trying to free ressources not allocated by us ... */
942 printk("bttv: BUG! (btres)\n"); 938 printk("bttv: BUG! (btres)\n");
943 } 939 }
944 mutex_lock(&btv->lock);
945 fh->resources &= ~bits; 940 fh->resources &= ~bits;
946 btv->resources &= ~bits; 941 btv->resources &= ~bits;
947 942
@@ -952,8 +947,6 @@ void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits)
952 947
953 if (0 == (bits & VBI_RESOURCES)) 948 if (0 == (bits & VBI_RESOURCES))
954 disclaim_vbi_lines(btv); 949 disclaim_vbi_lines(btv);
955
956 mutex_unlock(&btv->lock);
957} 950}
958 951
959/* ----------------------------------------------------------------------- */ 952/* ----------------------------------------------------------------------- */
@@ -1714,28 +1707,20 @@ static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1714 1707
1715 /* Make sure tvnorm and vbi_end remain consistent 1708 /* Make sure tvnorm and vbi_end remain consistent
1716 until we're done. */ 1709 until we're done. */
1717 mutex_lock(&btv->lock);
1718 1710
1719 norm = btv->tvnorm; 1711 norm = btv->tvnorm;
1720 1712
1721 /* In this mode capturing always starts at defrect.top 1713 /* In this mode capturing always starts at defrect.top
1722 (default VDELAY), ignoring cropping parameters. */ 1714 (default VDELAY), ignoring cropping parameters. */
1723 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) { 1715 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) {
1724 mutex_unlock(&btv->lock);
1725 return -EINVAL; 1716 return -EINVAL;
1726 } 1717 }
1727 1718
1728 mutex_unlock(&btv->lock);
1729
1730 c.rect = bttv_tvnorms[norm].cropcap.defrect; 1719 c.rect = bttv_tvnorms[norm].cropcap.defrect;
1731 } else { 1720 } else {
1732 mutex_lock(&btv->lock);
1733
1734 norm = btv->tvnorm; 1721 norm = btv->tvnorm;
1735 c = btv->crop[!!fh->do_crop]; 1722 c = btv->crop[!!fh->do_crop];
1736 1723
1737 mutex_unlock(&btv->lock);
1738
1739 if (width < c.min_scaled_width || 1724 if (width < c.min_scaled_width ||
1740 width > c.max_scaled_width || 1725 width > c.max_scaled_width ||
1741 height < c.min_scaled_height) 1726 height < c.min_scaled_height)
@@ -1859,7 +1844,6 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id)
1859 unsigned int i; 1844 unsigned int i;
1860 int err; 1845 int err;
1861 1846
1862 mutex_lock(&btv->lock);
1863 err = v4l2_prio_check(&btv->prio, fh->prio); 1847 err = v4l2_prio_check(&btv->prio, fh->prio);
1864 if (err) 1848 if (err)
1865 goto err; 1849 goto err;
@@ -1875,7 +1859,6 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id)
1875 set_tvnorm(btv, i); 1859 set_tvnorm(btv, i);
1876 1860
1877err: 1861err:
1878 mutex_unlock(&btv->lock);
1879 1862
1880 return err; 1863 return err;
1881} 1864}
@@ -1899,7 +1882,6 @@ static int bttv_enum_input(struct file *file, void *priv,
1899 struct bttv *btv = fh->btv; 1882 struct bttv *btv = fh->btv;
1900 int rc = 0; 1883 int rc = 0;
1901 1884
1902 mutex_lock(&btv->lock);
1903 if (i->index >= bttv_tvcards[btv->c.type].video_inputs) { 1885 if (i->index >= bttv_tvcards[btv->c.type].video_inputs) {
1904 rc = -EINVAL; 1886 rc = -EINVAL;
1905 goto err; 1887 goto err;
@@ -1929,7 +1911,6 @@ static int bttv_enum_input(struct file *file, void *priv,
1929 i->std = BTTV_NORMS; 1911 i->std = BTTV_NORMS;
1930 1912
1931err: 1913err:
1932 mutex_unlock(&btv->lock);
1933 1914
1934 return rc; 1915 return rc;
1935} 1916}
@@ -1939,9 +1920,7 @@ static int bttv_g_input(struct file *file, void *priv, unsigned int *i)
1939 struct bttv_fh *fh = priv; 1920 struct bttv_fh *fh = priv;
1940 struct bttv *btv = fh->btv; 1921 struct bttv *btv = fh->btv;
1941 1922
1942 mutex_lock(&btv->lock);
1943 *i = btv->input; 1923 *i = btv->input;
1944 mutex_unlock(&btv->lock);
1945 1924
1946 return 0; 1925 return 0;
1947} 1926}
@@ -1953,7 +1932,6 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i)
1953 1932
1954 int err; 1933 int err;
1955 1934
1956 mutex_lock(&btv->lock);
1957 err = v4l2_prio_check(&btv->prio, fh->prio); 1935 err = v4l2_prio_check(&btv->prio, fh->prio);
1958 if (unlikely(err)) 1936 if (unlikely(err))
1959 goto err; 1937 goto err;
@@ -1966,7 +1944,6 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i)
1966 set_input(btv, i, btv->tvnorm); 1944 set_input(btv, i, btv->tvnorm);
1967 1945
1968err: 1946err:
1969 mutex_unlock(&btv->lock);
1970 return 0; 1947 return 0;
1971} 1948}
1972 1949
@@ -1980,7 +1957,6 @@ static int bttv_s_tuner(struct file *file, void *priv,
1980 if (unlikely(0 != t->index)) 1957 if (unlikely(0 != t->index))
1981 return -EINVAL; 1958 return -EINVAL;
1982 1959
1983 mutex_lock(&btv->lock);
1984 if (unlikely(btv->tuner_type == TUNER_ABSENT)) { 1960 if (unlikely(btv->tuner_type == TUNER_ABSENT)) {
1985 err = -EINVAL; 1961 err = -EINVAL;
1986 goto err; 1962 goto err;
@@ -1996,7 +1972,6 @@ static int bttv_s_tuner(struct file *file, void *priv,
1996 btv->audio_mode_gpio(btv, t, 1); 1972 btv->audio_mode_gpio(btv, t, 1);
1997 1973
1998err: 1974err:
1999 mutex_unlock(&btv->lock);
2000 1975
2001 return 0; 1976 return 0;
2002} 1977}
@@ -2007,10 +1982,8 @@ static int bttv_g_frequency(struct file *file, void *priv,
2007 struct bttv_fh *fh = priv; 1982 struct bttv_fh *fh = priv;
2008 struct bttv *btv = fh->btv; 1983 struct bttv *btv = fh->btv;
2009 1984
2010 mutex_lock(&btv->lock);
2011 f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1985 f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
2012 f->frequency = btv->freq; 1986 f->frequency = btv->freq;
2013 mutex_unlock(&btv->lock);
2014 1987
2015 return 0; 1988 return 0;
2016} 1989}
@@ -2025,7 +1998,6 @@ static int bttv_s_frequency(struct file *file, void *priv,
2025 if (unlikely(f->tuner != 0)) 1998 if (unlikely(f->tuner != 0))
2026 return -EINVAL; 1999 return -EINVAL;
2027 2000
2028 mutex_lock(&btv->lock);
2029 err = v4l2_prio_check(&btv->prio, fh->prio); 2001 err = v4l2_prio_check(&btv->prio, fh->prio);
2030 if (unlikely(err)) 2002 if (unlikely(err))
2031 goto err; 2003 goto err;
@@ -2040,7 +2012,6 @@ static int bttv_s_frequency(struct file *file, void *priv,
2040 if (btv->has_matchbox && btv->radio_user) 2012 if (btv->has_matchbox && btv->radio_user)
2041 tea5757_set_freq(btv, btv->freq); 2013 tea5757_set_freq(btv, btv->freq);
2042err: 2014err:
2043 mutex_unlock(&btv->lock);
2044 2015
2045 return 0; 2016 return 0;
2046} 2017}
@@ -2173,7 +2144,6 @@ limit_scaled_size_lock (struct bttv_fh * fh,
2173 2144
2174 /* Make sure tvnorm, vbi_end and the current cropping parameters 2145 /* Make sure tvnorm, vbi_end and the current cropping parameters
2175 remain consistent until we're done. */ 2146 remain consistent until we're done. */
2176 mutex_lock(&btv->lock);
2177 2147
2178 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; 2148 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2179 2149
@@ -2251,7 +2221,6 @@ limit_scaled_size_lock (struct bttv_fh * fh,
2251 rc = 0; /* success */ 2221 rc = 0; /* success */
2252 2222
2253 fail: 2223 fail:
2254 mutex_unlock(&btv->lock);
2255 2224
2256 return rc; 2225 return rc;
2257} 2226}
@@ -2283,9 +2252,7 @@ verify_window_lock (struct bttv_fh * fh,
2283 if (V4L2_FIELD_ANY == field) { 2252 if (V4L2_FIELD_ANY == field) {
2284 __s32 height2; 2253 __s32 height2;
2285 2254
2286 mutex_lock(&fh->btv->lock);
2287 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1; 2255 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1;
2288 mutex_unlock(&fh->btv->lock);
2289 field = (win->w.height > height2) 2256 field = (win->w.height > height2)
2290 ? V4L2_FIELD_INTERLACED 2257 ? V4L2_FIELD_INTERLACED
2291 : V4L2_FIELD_TOP; 2258 : V4L2_FIELD_TOP;
@@ -2361,7 +2328,6 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv,
2361 } 2328 }
2362 } 2329 }
2363 2330
2364 mutex_lock(&fh->cap.vb_lock);
2365 /* clip against screen */ 2331 /* clip against screen */
2366 if (NULL != btv->fbuf.base) 2332 if (NULL != btv->fbuf.base)
2367 n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height, 2333 n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height,
@@ -2392,13 +2358,6 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv,
2392 fh->ov.field = win->field; 2358 fh->ov.field = win->field;
2393 fh->ov.setup_ok = 1; 2359 fh->ov.setup_ok = 1;
2394 2360
2395 /*
2396 * FIXME: btv is protected by btv->lock mutex, while btv->init
2397 * is protected by fh->cap.vb_lock. This seems to open the
2398 * possibility for some race situations. Maybe the better would
2399 * be to unify those locks or to use another way to store the
2400 * init values that will be consumed by videobuf callbacks
2401 */
2402 btv->init.ov.w.width = win->w.width; 2361 btv->init.ov.w.width = win->w.width;
2403 btv->init.ov.w.height = win->w.height; 2362 btv->init.ov.w.height = win->w.height;
2404 btv->init.ov.field = win->field; 2363 btv->init.ov.field = win->field;
@@ -2413,7 +2372,6 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv,
2413 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 2372 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2414 retval = bttv_switch_overlay(btv,fh,new); 2373 retval = bttv_switch_overlay(btv,fh,new);
2415 } 2374 }
2416 mutex_unlock(&fh->cap.vb_lock);
2417 return retval; 2375 return retval;
2418} 2376}
2419 2377
@@ -2527,9 +2485,7 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv,
2527 if (V4L2_FIELD_ANY == field) { 2485 if (V4L2_FIELD_ANY == field) {
2528 __s32 height2; 2486 __s32 height2;
2529 2487
2530 mutex_lock(&btv->lock);
2531 height2 = btv->crop[!!fh->do_crop].rect.height >> 1; 2488 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2532 mutex_unlock(&btv->lock);
2533 field = (f->fmt.pix.height > height2) 2489 field = (f->fmt.pix.height > height2)
2534 ? V4L2_FIELD_INTERLACED 2490 ? V4L2_FIELD_INTERLACED
2535 : V4L2_FIELD_BOTTOM; 2491 : V4L2_FIELD_BOTTOM;
@@ -2615,7 +2571,6 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv,
2615 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 2571 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
2616 2572
2617 /* update our state informations */ 2573 /* update our state informations */
2618 mutex_lock(&fh->cap.vb_lock);
2619 fh->fmt = fmt; 2574 fh->fmt = fmt;
2620 fh->cap.field = f->fmt.pix.field; 2575 fh->cap.field = f->fmt.pix.field;
2621 fh->cap.last = V4L2_FIELD_NONE; 2576 fh->cap.last = V4L2_FIELD_NONE;
@@ -2624,7 +2579,6 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv,
2624 btv->init.fmt = fmt; 2579 btv->init.fmt = fmt;
2625 btv->init.width = f->fmt.pix.width; 2580 btv->init.width = f->fmt.pix.width;
2626 btv->init.height = f->fmt.pix.height; 2581 btv->init.height = f->fmt.pix.height;
2627 mutex_unlock(&fh->cap.vb_lock);
2628 2582
2629 return 0; 2583 return 0;
2630} 2584}
@@ -2650,11 +2604,9 @@ static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2650 unsigned int i; 2604 unsigned int i;
2651 struct bttv_fh *fh = priv; 2605 struct bttv_fh *fh = priv;
2652 2606
2653 mutex_lock(&fh->cap.vb_lock);
2654 retval = __videobuf_mmap_setup(&fh->cap, gbuffers, gbufsize, 2607 retval = __videobuf_mmap_setup(&fh->cap, gbuffers, gbufsize,
2655 V4L2_MEMORY_MMAP); 2608 V4L2_MEMORY_MMAP);
2656 if (retval < 0) { 2609 if (retval < 0) {
2657 mutex_unlock(&fh->cap.vb_lock);
2658 return retval; 2610 return retval;
2659 } 2611 }
2660 2612
@@ -2666,7 +2618,6 @@ static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2666 for (i = 0; i < gbuffers; i++) 2618 for (i = 0; i < gbuffers; i++)
2667 mbuf->offsets[i] = i * gbufsize; 2619 mbuf->offsets[i] = i * gbufsize;
2668 2620
2669 mutex_unlock(&fh->cap.vb_lock);
2670 return 0; 2621 return 0;
2671} 2622}
2672#endif 2623#endif
@@ -2776,10 +2727,8 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on)
2776 int retval = 0; 2727 int retval = 0;
2777 2728
2778 if (on) { 2729 if (on) {
2779 mutex_lock(&fh->cap.vb_lock);
2780 /* verify args */ 2730 /* verify args */
2781 if (unlikely(!btv->fbuf.base)) { 2731 if (unlikely(!btv->fbuf.base)) {
2782 mutex_unlock(&fh->cap.vb_lock);
2783 return -EINVAL; 2732 return -EINVAL;
2784 } 2733 }
2785 if (unlikely(!fh->ov.setup_ok)) { 2734 if (unlikely(!fh->ov.setup_ok)) {
@@ -2788,13 +2737,11 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on)
2788 } 2737 }
2789 if (retval) 2738 if (retval)
2790 return retval; 2739 return retval;
2791 mutex_unlock(&fh->cap.vb_lock);
2792 } 2740 }
2793 2741
2794 if (!check_alloc_btres_lock(btv, fh, RESOURCE_OVERLAY)) 2742 if (!check_alloc_btres_lock(btv, fh, RESOURCE_OVERLAY))
2795 return -EBUSY; 2743 return -EBUSY;
2796 2744
2797 mutex_lock(&fh->cap.vb_lock);
2798 if (on) { 2745 if (on) {
2799 fh->ov.tvnorm = btv->tvnorm; 2746 fh->ov.tvnorm = btv->tvnorm;
2800 new = videobuf_sg_alloc(sizeof(*new)); 2747 new = videobuf_sg_alloc(sizeof(*new));
@@ -2806,7 +2753,6 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on)
2806 2753
2807 /* switch over */ 2754 /* switch over */
2808 retval = bttv_switch_overlay(btv, fh, new); 2755 retval = bttv_switch_overlay(btv, fh, new);
2809 mutex_unlock(&fh->cap.vb_lock);
2810 return retval; 2756 return retval;
2811} 2757}
2812 2758
@@ -2845,7 +2791,6 @@ static int bttv_s_fbuf(struct file *file, void *f,
2845 } 2791 }
2846 2792
2847 /* ok, accept it */ 2793 /* ok, accept it */
2848 mutex_lock(&fh->cap.vb_lock);
2849 btv->fbuf.base = fb->base; 2794 btv->fbuf.base = fb->base;
2850 btv->fbuf.fmt.width = fb->fmt.width; 2795 btv->fbuf.fmt.width = fb->fmt.width;
2851 btv->fbuf.fmt.height = fb->fmt.height; 2796 btv->fbuf.fmt.height = fb->fmt.height;
@@ -2877,7 +2822,6 @@ static int bttv_s_fbuf(struct file *file, void *f,
2877 retval = bttv_switch_overlay(btv, fh, new); 2822 retval = bttv_switch_overlay(btv, fh, new);
2878 } 2823 }
2879 } 2824 }
2880 mutex_unlock(&fh->cap.vb_lock);
2881 return retval; 2825 return retval;
2882} 2826}
2883 2827
@@ -2956,7 +2900,6 @@ static int bttv_queryctrl(struct file *file, void *priv,
2956 c->id >= V4L2_CID_PRIVATE_LASTP1)) 2900 c->id >= V4L2_CID_PRIVATE_LASTP1))
2957 return -EINVAL; 2901 return -EINVAL;
2958 2902
2959 mutex_lock(&btv->lock);
2960 if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME)) 2903 if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME))
2961 *c = no_ctl; 2904 *c = no_ctl;
2962 else { 2905 else {
@@ -2964,7 +2907,6 @@ static int bttv_queryctrl(struct file *file, void *priv,
2964 2907
2965 *c = (NULL != ctrl) ? *ctrl : no_ctl; 2908 *c = (NULL != ctrl) ? *ctrl : no_ctl;
2966 } 2909 }
2967 mutex_unlock(&btv->lock);
2968 2910
2969 return 0; 2911 return 0;
2970} 2912}
@@ -2975,10 +2917,8 @@ static int bttv_g_parm(struct file *file, void *f,
2975 struct bttv_fh *fh = f; 2917 struct bttv_fh *fh = f;
2976 struct bttv *btv = fh->btv; 2918 struct bttv *btv = fh->btv;
2977 2919
2978 mutex_lock(&btv->lock);
2979 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, 2920 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id,
2980 &parm->parm.capture.timeperframe); 2921 &parm->parm.capture.timeperframe);
2981 mutex_unlock(&btv->lock);
2982 2922
2983 return 0; 2923 return 0;
2984} 2924}
@@ -2994,7 +2934,6 @@ static int bttv_g_tuner(struct file *file, void *priv,
2994 if (0 != t->index) 2934 if (0 != t->index)
2995 return -EINVAL; 2935 return -EINVAL;
2996 2936
2997 mutex_lock(&btv->lock);
2998 t->rxsubchans = V4L2_TUNER_SUB_MONO; 2937 t->rxsubchans = V4L2_TUNER_SUB_MONO;
2999 bttv_call_all(btv, tuner, g_tuner, t); 2938 bttv_call_all(btv, tuner, g_tuner, t);
3000 strcpy(t->name, "Television"); 2939 strcpy(t->name, "Television");
@@ -3006,7 +2945,6 @@ static int bttv_g_tuner(struct file *file, void *priv,
3006 if (btv->audio_mode_gpio) 2945 if (btv->audio_mode_gpio)
3007 btv->audio_mode_gpio(btv, t, 0); 2946 btv->audio_mode_gpio(btv, t, 0);
3008 2947
3009 mutex_unlock(&btv->lock);
3010 return 0; 2948 return 0;
3011} 2949}
3012 2950
@@ -3015,9 +2953,7 @@ static int bttv_g_priority(struct file *file, void *f, enum v4l2_priority *p)
3015 struct bttv_fh *fh = f; 2953 struct bttv_fh *fh = f;
3016 struct bttv *btv = fh->btv; 2954 struct bttv *btv = fh->btv;
3017 2955
3018 mutex_lock(&btv->lock);
3019 *p = v4l2_prio_max(&btv->prio); 2956 *p = v4l2_prio_max(&btv->prio);
3020 mutex_unlock(&btv->lock);
3021 2957
3022 return 0; 2958 return 0;
3023} 2959}
@@ -3029,9 +2965,7 @@ static int bttv_s_priority(struct file *file, void *f,
3029 struct bttv *btv = fh->btv; 2965 struct bttv *btv = fh->btv;
3030 int rc; 2966 int rc;
3031 2967
3032 mutex_lock(&btv->lock);
3033 rc = v4l2_prio_change(&btv->prio, &fh->prio, prio); 2968 rc = v4l2_prio_change(&btv->prio, &fh->prio, prio);
3034 mutex_unlock(&btv->lock);
3035 2969
3036 return rc; 2970 return rc;
3037} 2971}
@@ -3046,9 +2980,7 @@ static int bttv_cropcap(struct file *file, void *priv,
3046 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) 2980 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3047 return -EINVAL; 2981 return -EINVAL;
3048 2982
3049 mutex_lock(&btv->lock);
3050 *cap = bttv_tvnorms[btv->tvnorm].cropcap; 2983 *cap = bttv_tvnorms[btv->tvnorm].cropcap;
3051 mutex_unlock(&btv->lock);
3052 2984
3053 return 0; 2985 return 0;
3054} 2986}
@@ -3066,9 +2998,7 @@ static int bttv_g_crop(struct file *file, void *f, struct v4l2_crop *crop)
3066 inconsistent with fh->width or fh->height and apps 2998 inconsistent with fh->width or fh->height and apps
3067 do not expect a change here. */ 2999 do not expect a change here. */
3068 3000
3069 mutex_lock(&btv->lock);
3070 crop->c = btv->crop[!!fh->do_crop].rect; 3001 crop->c = btv->crop[!!fh->do_crop].rect;
3071 mutex_unlock(&btv->lock);
3072 3002
3073 return 0; 3003 return 0;
3074} 3004}
@@ -3092,17 +3022,14 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
3092 /* Make sure tvnorm, vbi_end and the current cropping 3022 /* Make sure tvnorm, vbi_end and the current cropping
3093 parameters remain consistent until we're done. Note 3023 parameters remain consistent until we're done. Note
3094 read() may change vbi_end in check_alloc_btres_lock(). */ 3024 read() may change vbi_end in check_alloc_btres_lock(). */
3095 mutex_lock(&btv->lock);
3096 retval = v4l2_prio_check(&btv->prio, fh->prio); 3025 retval = v4l2_prio_check(&btv->prio, fh->prio);
3097 if (0 != retval) { 3026 if (0 != retval) {
3098 mutex_unlock(&btv->lock);
3099 return retval; 3027 return retval;
3100 } 3028 }
3101 3029
3102 retval = -EBUSY; 3030 retval = -EBUSY;
3103 3031
3104 if (locked_btres(fh->btv, VIDEO_RESOURCES)) { 3032 if (locked_btres(fh->btv, VIDEO_RESOURCES)) {
3105 mutex_unlock(&btv->lock);
3106 return retval; 3033 return retval;
3107 } 3034 }
3108 3035
@@ -3114,7 +3041,6 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
3114 3041
3115 b_top = max(b->top, btv->vbi_end); 3042 b_top = max(b->top, btv->vbi_end);
3116 if (b_top + 32 >= b_bottom) { 3043 if (b_top + 32 >= b_bottom) {
3117 mutex_unlock(&btv->lock);
3118 return retval; 3044 return retval;
3119 } 3045 }
3120 3046
@@ -3137,12 +3063,8 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
3137 3063
3138 btv->crop[1] = c; 3064 btv->crop[1] = c;
3139 3065
3140 mutex_unlock(&btv->lock);
3141
3142 fh->do_crop = 1; 3066 fh->do_crop = 1;
3143 3067
3144 mutex_lock(&fh->cap.vb_lock);
3145
3146 if (fh->width < c.min_scaled_width) { 3068 if (fh->width < c.min_scaled_width) {
3147 fh->width = c.min_scaled_width; 3069 fh->width = c.min_scaled_width;
3148 btv->init.width = c.min_scaled_width; 3070 btv->init.width = c.min_scaled_width;
@@ -3159,8 +3081,6 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
3159 btv->init.height = c.max_scaled_height; 3081 btv->init.height = c.max_scaled_height;
3160 } 3082 }
3161 3083
3162 mutex_unlock(&fh->cap.vb_lock);
3163
3164 return 0; 3084 return 0;
3165} 3085}
3166 3086
@@ -3228,7 +3148,6 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3228 return videobuf_poll_stream(file, &fh->vbi, wait); 3148 return videobuf_poll_stream(file, &fh->vbi, wait);
3229 } 3149 }
3230 3150
3231 mutex_lock(&fh->cap.vb_lock);
3232 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { 3151 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) {
3233 /* streaming capture */ 3152 /* streaming capture */
3234 if (list_empty(&fh->cap.stream)) 3153 if (list_empty(&fh->cap.stream))
@@ -3263,7 +3182,6 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3263 else 3182 else
3264 rc = 0; 3183 rc = 0;
3265err: 3184err:
3266 mutex_unlock(&fh->cap.vb_lock);
3267 return rc; 3185 return rc;
3268} 3186}
3269 3187
@@ -3294,23 +3212,11 @@ static int bttv_open(struct file *file)
3294 return -ENOMEM; 3212 return -ENOMEM;
3295 file->private_data = fh; 3213 file->private_data = fh;
3296 3214
3297 /*
3298 * btv is protected by btv->lock mutex, while btv->init and other
3299 * streaming vars are protected by fh->cap.vb_lock. We need to take
3300 * care of both locks to avoid troubles. However, vb_lock is used also
3301 * inside videobuf, without calling buf->lock. So, it is a very bad
3302 * idea to hold both locks at the same time.
3303 * Let's first copy btv->init at fh, holding cap.vb_lock, and then work
3304 * with the rest of init, holding btv->lock.
3305 */
3306 mutex_lock(&fh->cap.vb_lock);
3307 *fh = btv->init; 3215 *fh = btv->init;
3308 mutex_unlock(&fh->cap.vb_lock);
3309 3216
3310 fh->type = type; 3217 fh->type = type;
3311 fh->ov.setup_ok = 0; 3218 fh->ov.setup_ok = 0;
3312 3219
3313 mutex_lock(&btv->lock);
3314 v4l2_prio_open(&btv->prio, &fh->prio); 3220 v4l2_prio_open(&btv->prio, &fh->prio);
3315 3221
3316 videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, 3222 videobuf_queue_sg_init(&fh->cap, &bttv_video_qops,
@@ -3318,13 +3224,13 @@ static int bttv_open(struct file *file)
3318 V4L2_BUF_TYPE_VIDEO_CAPTURE, 3224 V4L2_BUF_TYPE_VIDEO_CAPTURE,
3319 V4L2_FIELD_INTERLACED, 3225 V4L2_FIELD_INTERLACED,
3320 sizeof(struct bttv_buffer), 3226 sizeof(struct bttv_buffer),
3321 fh, NULL); 3227 fh, &btv->lock);
3322 videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, 3228 videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops,
3323 &btv->c.pci->dev, &btv->s_lock, 3229 &btv->c.pci->dev, &btv->s_lock,
3324 V4L2_BUF_TYPE_VBI_CAPTURE, 3230 V4L2_BUF_TYPE_VBI_CAPTURE,
3325 V4L2_FIELD_SEQ_TB, 3231 V4L2_FIELD_SEQ_TB,
3326 sizeof(struct bttv_buffer), 3232 sizeof(struct bttv_buffer),
3327 fh, NULL); 3233 fh, &btv->lock);
3328 set_tvnorm(btv,btv->tvnorm); 3234 set_tvnorm(btv,btv->tvnorm);
3329 set_input(btv, btv->input, btv->tvnorm); 3235 set_input(btv, btv->input, btv->tvnorm);
3330 3236
@@ -3347,7 +3253,6 @@ static int bttv_open(struct file *file)
3347 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); 3253 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
3348 3254
3349 bttv_field_count(btv); 3255 bttv_field_count(btv);
3350 mutex_unlock(&btv->lock);
3351 return 0; 3256 return 0;
3352} 3257}
3353 3258
@@ -3356,7 +3261,6 @@ static int bttv_release(struct file *file)
3356 struct bttv_fh *fh = file->private_data; 3261 struct bttv_fh *fh = file->private_data;
3357 struct bttv *btv = fh->btv; 3262 struct bttv *btv = fh->btv;
3358 3263
3359 mutex_lock(&btv->lock);
3360 /* turn off overlay */ 3264 /* turn off overlay */
3361 if (check_btres(fh, RESOURCE_OVERLAY)) 3265 if (check_btres(fh, RESOURCE_OVERLAY))
3362 bttv_switch_overlay(btv,fh,NULL); 3266 bttv_switch_overlay(btv,fh,NULL);
@@ -3382,14 +3286,8 @@ static int bttv_release(struct file *file)
3382 3286
3383 /* free stuff */ 3287 /* free stuff */
3384 3288
3385 /*
3386 * videobuf uses cap.vb_lock - we should avoid holding btv->lock,
3387 * otherwise we may have dead lock conditions
3388 */
3389 mutex_unlock(&btv->lock);
3390 videobuf_mmap_free(&fh->cap); 3289 videobuf_mmap_free(&fh->cap);
3391 videobuf_mmap_free(&fh->vbi); 3290 videobuf_mmap_free(&fh->vbi);
3392 mutex_lock(&btv->lock);
3393 v4l2_prio_close(&btv->prio, fh->prio); 3291 v4l2_prio_close(&btv->prio, fh->prio);
3394 file->private_data = NULL; 3292 file->private_data = NULL;
3395 kfree(fh); 3293 kfree(fh);
@@ -3399,7 +3297,6 @@ static int bttv_release(struct file *file)
3399 3297
3400 if (!btv->users) 3298 if (!btv->users)
3401 audio_mute(btv, 1); 3299 audio_mute(btv, 1);
3402 mutex_unlock(&btv->lock);
3403 3300
3404 return 0; 3301 return 0;
3405} 3302}
@@ -3503,11 +3400,8 @@ static int radio_open(struct file *file)
3503 if (unlikely(!fh)) 3400 if (unlikely(!fh))
3504 return -ENOMEM; 3401 return -ENOMEM;
3505 file->private_data = fh; 3402 file->private_data = fh;
3506 mutex_lock(&fh->cap.vb_lock);
3507 *fh = btv->init; 3403 *fh = btv->init;
3508 mutex_unlock(&fh->cap.vb_lock);
3509 3404
3510 mutex_lock(&btv->lock);
3511 v4l2_prio_open(&btv->prio, &fh->prio); 3405 v4l2_prio_open(&btv->prio, &fh->prio);
3512 3406
3513 btv->radio_user++; 3407 btv->radio_user++;
@@ -3515,7 +3409,6 @@ static int radio_open(struct file *file)
3515 bttv_call_all(btv, tuner, s_radio); 3409 bttv_call_all(btv, tuner, s_radio);
3516 audio_input(btv,TVAUDIO_INPUT_RADIO); 3410 audio_input(btv,TVAUDIO_INPUT_RADIO);
3517 3411
3518 mutex_unlock(&btv->lock);
3519 return 0; 3412 return 0;
3520} 3413}
3521 3414
@@ -3525,7 +3418,6 @@ static int radio_release(struct file *file)
3525 struct bttv *btv = fh->btv; 3418 struct bttv *btv = fh->btv;
3526 struct rds_command cmd; 3419 struct rds_command cmd;
3527 3420
3528 mutex_lock(&btv->lock);
3529 v4l2_prio_close(&btv->prio, fh->prio); 3421 v4l2_prio_close(&btv->prio, fh->prio);
3530 file->private_data = NULL; 3422 file->private_data = NULL;
3531 kfree(fh); 3423 kfree(fh);
@@ -3533,7 +3425,6 @@ static int radio_release(struct file *file)
3533 btv->radio_user--; 3425 btv->radio_user--;
3534 3426
3535 bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd); 3427 bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd);
3536 mutex_unlock(&btv->lock);
3537 3428
3538 return 0; 3429 return 0;
3539} 3430}
@@ -3562,7 +3453,6 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3562 return -EINVAL; 3453 return -EINVAL;
3563 if (0 != t->index) 3454 if (0 != t->index)
3564 return -EINVAL; 3455 return -EINVAL;
3565 mutex_lock(&btv->lock);
3566 strcpy(t->name, "Radio"); 3456 strcpy(t->name, "Radio");
3567 t->type = V4L2_TUNER_RADIO; 3457 t->type = V4L2_TUNER_RADIO;
3568 3458
@@ -3571,8 +3461,6 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3571 if (btv->audio_mode_gpio) 3461 if (btv->audio_mode_gpio)
3572 btv->audio_mode_gpio(btv, t, 0); 3462 btv->audio_mode_gpio(btv, t, 0);
3573 3463
3574 mutex_unlock(&btv->lock);
3575
3576 return 0; 3464 return 0;
3577} 3465}
3578 3466
@@ -3693,7 +3581,7 @@ static const struct v4l2_file_operations radio_fops =
3693 .open = radio_open, 3581 .open = radio_open,
3694 .read = radio_read, 3582 .read = radio_read,
3695 .release = radio_release, 3583 .release = radio_release,
3696 .ioctl = video_ioctl2, 3584 .unlocked_ioctl = video_ioctl2,
3697 .poll = radio_poll, 3585 .poll = radio_poll,
3698}; 3586};
3699 3587
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index 935e0c9a9674..c1193506131c 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -860,7 +860,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
860 860
861static const struct v4l2_file_operations qcam_fops = { 861static const struct v4l2_file_operations qcam_fops = {
862 .owner = THIS_MODULE, 862 .owner = THIS_MODULE,
863 .ioctl = video_ioctl2, 863 .unlocked_ioctl = video_ioctl2,
864 .read = qcam_read, 864 .read = qcam_read,
865}; 865};
866 866
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c
index 6e4b19698c13..24fc00965a12 100644
--- a/drivers/media/video/c-qcam.c
+++ b/drivers/media/video/c-qcam.c
@@ -718,7 +718,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
718 718
719static const struct v4l2_file_operations qcam_fops = { 719static const struct v4l2_file_operations qcam_fops = {
720 .owner = THIS_MODULE, 720 .owner = THIS_MODULE,
721 .ioctl = video_ioctl2, 721 .unlocked_ioctl = video_ioctl2,
722 .read = qcam_read, 722 .read = qcam_read,
723}; 723};
724 724
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 2934770dacc3..0dfff50891e4 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -1775,7 +1775,7 @@ static const struct v4l2_file_operations cafe_v4l_fops = {
1775 .read = cafe_v4l_read, 1775 .read = cafe_v4l_read,
1776 .poll = cafe_v4l_poll, 1776 .poll = cafe_v4l_poll,
1777 .mmap = cafe_v4l_mmap, 1777 .mmap = cafe_v4l_mmap,
1778 .ioctl = video_ioctl2, 1778 .unlocked_ioctl = video_ioctl2,
1779}; 1779};
1780 1780
1781static const struct v4l2_ioctl_ops cafe_v4l_ioctl_ops = { 1781static const struct v4l2_ioctl_ops cafe_v4l_ioctl_ops = {
@@ -2065,8 +2065,8 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2065 sensor_cfg.clock_speed = 45; 2065 sensor_cfg.clock_speed = 45;
2066 2066
2067 cam->sensor_addr = 0x42; 2067 cam->sensor_addr = 0x42;
2068 cam->sensor = v4l2_i2c_new_subdev(&cam->v4l2_dev, &cam->i2c_adapter, 2068 cam->sensor = v4l2_i2c_new_subdev_cfg(&cam->v4l2_dev, &cam->i2c_adapter,
2069 NULL, "ov7670", cam->sensor_addr, NULL); 2069 "ov7670", 0, &sensor_cfg, cam->sensor_addr, NULL);
2070 if (cam->sensor == NULL) { 2070 if (cam->sensor == NULL) {
2071 ret = -ENODEV; 2071 ret = -ENODEV;
2072 goto out_smbus; 2072 goto out_smbus;
diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.c b/drivers/media/video/cx18/cx18-alsa-pcm.c
index 8f55692db36d..82d195be9197 100644
--- a/drivers/media/video/cx18/cx18-alsa-pcm.c
+++ b/drivers/media/video/cx18/cx18-alsa-pcm.c
@@ -218,7 +218,13 @@ static int snd_cx18_pcm_capture_close(struct snd_pcm_substream *substream)
218static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream, 218static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
219 unsigned int cmd, void *arg) 219 unsigned int cmd, void *arg)
220{ 220{
221 return snd_pcm_lib_ioctl(substream, cmd, arg); 221 struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream);
222 int ret;
223
224 snd_cx18_lock(cxsc);
225 ret = snd_pcm_lib_ioctl(substream, cmd, arg);
226 snd_cx18_unlock(cxsc);
227 return ret;
222} 228}
223 229
224 230
diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c
index a09caf883170..e71a026f3419 100644
--- a/drivers/media/video/cx18/cx18-i2c.c
+++ b/drivers/media/video/cx18/cx18-i2c.c
@@ -122,15 +122,15 @@ int cx18_i2c_register(struct cx18 *cx, unsigned idx)
122 if (hw == CX18_HW_TUNER) { 122 if (hw == CX18_HW_TUNER) {
123 /* special tuner group handling */ 123 /* special tuner group handling */
124 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, 124 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev,
125 adap, NULL, type, 0, cx->card_i2c->radio); 125 adap, type, 0, cx->card_i2c->radio);
126 if (sd != NULL) 126 if (sd != NULL)
127 sd->grp_id = hw; 127 sd->grp_id = hw;
128 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, 128 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev,
129 adap, NULL, type, 0, cx->card_i2c->demod); 129 adap, type, 0, cx->card_i2c->demod);
130 if (sd != NULL) 130 if (sd != NULL)
131 sd->grp_id = hw; 131 sd->grp_id = hw;
132 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, 132 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev,
133 adap, NULL, type, 0, cx->card_i2c->tv); 133 adap, type, 0, cx->card_i2c->tv);
134 if (sd != NULL) 134 if (sd != NULL)
135 sd->grp_id = hw; 135 sd->grp_id = hw;
136 return sd != NULL ? 0 : -1; 136 return sd != NULL ? 0 : -1;
@@ -144,7 +144,7 @@ int cx18_i2c_register(struct cx18 *cx, unsigned idx)
144 return -1; 144 return -1;
145 145
146 /* It's an I2C device other than an analog tuner or IR chip */ 146 /* It's an I2C device other than an analog tuner or IR chip */
147 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, adap, NULL, type, hw_addrs[idx], 147 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, adap, type, hw_addrs[idx],
148 NULL); 148 NULL);
149 if (sd != NULL) 149 if (sd != NULL)
150 sd->grp_id = hw; 150 sd->grp_id = hw;
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index 9045f1ece0eb..ab461e27d9dd 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -41,7 +41,7 @@ static struct v4l2_file_operations cx18_v4l2_enc_fops = {
41 .read = cx18_v4l2_read, 41 .read = cx18_v4l2_read,
42 .open = cx18_v4l2_open, 42 .open = cx18_v4l2_open,
43 /* FIXME change to video_ioctl2 if serialization lock can be removed */ 43 /* FIXME change to video_ioctl2 if serialization lock can be removed */
44 .ioctl = cx18_v4l2_ioctl, 44 .unlocked_ioctl = cx18_v4l2_ioctl,
45 .release = cx18_v4l2_close, 45 .release = cx18_v4l2_close,
46 .poll = cx18_v4l2_enc_poll, 46 .poll = cx18_v4l2_enc_poll,
47}; 47};
diff --git a/drivers/media/video/cx231xx/cx231xx-417.c b/drivers/media/video/cx231xx/cx231xx-417.c
index aab21f3ce472..4c7cac3b6254 100644
--- a/drivers/media/video/cx231xx/cx231xx-417.c
+++ b/drivers/media/video/cx231xx/cx231xx-417.c
@@ -31,7 +31,6 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/device.h> 32#include <linux/device.h>
33#include <linux/firmware.h> 33#include <linux/firmware.h>
34#include <linux/smp_lock.h>
35#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
36#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 36#include <media/v4l2-ioctl.h>
@@ -1927,10 +1926,9 @@ static int mpeg_open(struct file *file)
1927 dev = h; 1926 dev = h;
1928 } 1927 }
1929 1928
1930 if (dev == NULL) { 1929 if (dev == NULL)
1931 unlock_kernel();
1932 return -ENODEV; 1930 return -ENODEV;
1933 } 1931
1934 mutex_lock(&dev->lock); 1932 mutex_lock(&dev->lock);
1935 1933
1936 /* allocate + initialize per filehandle data */ 1934 /* allocate + initialize per filehandle data */
diff --git a/drivers/media/video/cx231xx/cx231xx-cards.c b/drivers/media/video/cx231xx/cx231xx-cards.c
index 56c2d8195ac6..2c78d188bb06 100644
--- a/drivers/media/video/cx231xx/cx231xx-cards.c
+++ b/drivers/media/video/cx231xx/cx231xx-cards.c
@@ -560,7 +560,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
560 if (dev->board.decoder == CX231XX_AVDECODER) { 560 if (dev->board.decoder == CX231XX_AVDECODER) {
561 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, 561 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
562 &dev->i2c_bus[0].i2c_adap, 562 &dev->i2c_bus[0].i2c_adap,
563 NULL, "cx25840", 0x88 >> 1, NULL); 563 "cx25840", 0x88 >> 1, NULL);
564 if (dev->sd_cx25840 == NULL) 564 if (dev->sd_cx25840 == NULL)
565 cx231xx_info("cx25840 subdev registration failure\n"); 565 cx231xx_info("cx25840 subdev registration failure\n");
566 cx25840_call(dev, core, load_fw); 566 cx25840_call(dev, core, load_fw);
@@ -571,7 +571,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
571 if (dev->board.tuner_type != TUNER_ABSENT) { 571 if (dev->board.tuner_type != TUNER_ABSENT) {
572 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev, 572 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
573 &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, 573 &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
574 NULL, "tuner", 574 "tuner",
575 dev->tuner_addr, NULL); 575 dev->tuner_addr, NULL);
576 if (dev->sd_tuner == NULL) 576 if (dev->sd_tuner == NULL)
577 cx231xx_info("tuner subdev registration failure\n"); 577 cx231xx_info("tuner subdev registration failure\n");
diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c
index a6cc12f8736c..9a98dc55f657 100644
--- a/drivers/media/video/cx23885/cx23885-417.c
+++ b/drivers/media/video/cx23885/cx23885-417.c
@@ -31,7 +31,6 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/device.h> 32#include <linux/device.h>
33#include <linux/firmware.h> 33#include <linux/firmware.h>
34#include <linux/smp_lock.h>
35#include <linux/slab.h> 34#include <linux/slab.h>
36#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 36#include <media/v4l2-ioctl.h>
@@ -1576,12 +1575,8 @@ static int mpeg_open(struct file *file)
1576 1575
1577 /* allocate + initialize per filehandle data */ 1576 /* allocate + initialize per filehandle data */
1578 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 1577 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1579 if (NULL == fh) { 1578 if (!fh)
1580 unlock_kernel();
1581 return -ENOMEM; 1579 return -ENOMEM;
1582 }
1583
1584 lock_kernel();
1585 1580
1586 file->private_data = fh; 1581 file->private_data = fh;
1587 fh->dev = dev; 1582 fh->dev = dev;
@@ -1592,8 +1587,6 @@ static int mpeg_open(struct file *file)
1592 V4L2_FIELD_INTERLACED, 1587 V4L2_FIELD_INTERLACED,
1593 sizeof(struct cx23885_buffer), 1588 sizeof(struct cx23885_buffer),
1594 fh, NULL); 1589 fh, NULL);
1595 unlock_kernel();
1596
1597 return 0; 1590 return 0;
1598} 1591}
1599 1592
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index db054004e462..8861309268b1 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -1247,7 +1247,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1247 case CX23885_BOARD_LEADTEK_WINFAST_PXTV1200: 1247 case CX23885_BOARD_LEADTEK_WINFAST_PXTV1200:
1248 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1248 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1249 &dev->i2c_bus[2].i2c_adap, 1249 &dev->i2c_bus[2].i2c_adap,
1250 NULL, "cx25840", 0x88 >> 1, NULL); 1250 "cx25840", 0x88 >> 1, NULL);
1251 if (dev->sd_cx25840) { 1251 if (dev->sd_cx25840) {
1252 dev->sd_cx25840->grp_id = CX23885_HW_AV_CORE; 1252 dev->sd_cx25840->grp_id = CX23885_HW_AV_CORE;
1253 v4l2_subdev_call(dev->sd_cx25840, core, load_fw); 1253 v4l2_subdev_call(dev->sd_cx25840, core, load_fw);
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index 93af9c65b484..8b2fb8a4375c 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -26,7 +26,6 @@
26#include <linux/kmod.h> 26#include <linux/kmod.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/smp_lock.h>
30#include <linux/interrupt.h> 29#include <linux/interrupt.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <linux/kthread.h> 31#include <linux/kthread.h>
@@ -743,8 +742,6 @@ static int video_open(struct file *file)
743 if (NULL == fh) 742 if (NULL == fh)
744 return -ENOMEM; 743 return -ENOMEM;
745 744
746 lock_kernel();
747
748 file->private_data = fh; 745 file->private_data = fh;
749 fh->dev = dev; 746 fh->dev = dev;
750 fh->radio = radio; 747 fh->radio = radio;
@@ -762,8 +759,6 @@ static int video_open(struct file *file)
762 759
763 dprintk(1, "post videobuf_queue_init()\n"); 760 dprintk(1, "post videobuf_queue_init()\n");
764 761
765 unlock_kernel();
766
767 return 0; 762 return 0;
768} 763}
769 764
@@ -1512,10 +1507,10 @@ int cx23885_video_register(struct cx23885_dev *dev)
1512 if (dev->tuner_addr) 1507 if (dev->tuner_addr)
1513 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1508 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1514 &dev->i2c_bus[1].i2c_adap, 1509 &dev->i2c_bus[1].i2c_adap,
1515 NULL, "tuner", dev->tuner_addr, NULL); 1510 "tuner", dev->tuner_addr, NULL);
1516 else 1511 else
1517 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1512 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1518 &dev->i2c_bus[1].i2c_adap, NULL, 1513 &dev->i2c_bus[1].i2c_adap,
1519 "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_TV)); 1514 "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_TV));
1520 if (sd) { 1515 if (sd) {
1521 struct tuner_setup tun_setup; 1516 struct tuner_setup tun_setup;
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 417d1d5c73c4..d7c94848249e 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -33,7 +33,6 @@
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/device.h> 34#include <linux/device.h>
35#include <linux/firmware.h> 35#include <linux/firmware.h>
36#include <linux/smp_lock.h>
37#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
38#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
39#include <media/cx2341x.h> 38#include <media/cx2341x.h>
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index b26fcba8600c..9b9e169cce90 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -3515,19 +3515,18 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3515 later code configures a tea5767. 3515 later code configures a tea5767.
3516 */ 3516 */
3517 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, 3517 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
3518 NULL, "tuner", 3518 "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_RADIO));
3519 0, v4l2_i2c_tuner_addrs(ADDRS_RADIO));
3520 if (has_demod) 3519 if (has_demod)
3521 v4l2_i2c_new_subdev(&core->v4l2_dev, 3520 v4l2_i2c_new_subdev(&core->v4l2_dev,
3522 &core->i2c_adap, NULL, "tuner", 3521 &core->i2c_adap, "tuner",
3523 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); 3522 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
3524 if (core->board.tuner_addr == ADDR_UNSET) { 3523 if (core->board.tuner_addr == ADDR_UNSET) {
3525 v4l2_i2c_new_subdev(&core->v4l2_dev, 3524 v4l2_i2c_new_subdev(&core->v4l2_dev,
3526 &core->i2c_adap, NULL, "tuner", 3525 &core->i2c_adap, "tuner",
3527 0, has_demod ? tv_addrs + 4 : tv_addrs); 3526 0, has_demod ? tv_addrs + 4 : tv_addrs);
3528 } else { 3527 } else {
3529 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, 3528 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
3530 NULL, "tuner", core->board.tuner_addr, NULL); 3529 "tuner", core->board.tuner_addr, NULL);
3531 } 3530 }
3532 } 3531 }
3533 3532
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index d2f159daa8b5..62cea9549404 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -31,7 +31,6 @@
31#include <linux/kmod.h> 31#include <linux/kmod.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/smp_lock.h>
35#include <linux/interrupt.h> 34#include <linux/interrupt.h>
36#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
37#include <linux/delay.h> 36#include <linux/delay.h>
@@ -1896,14 +1895,13 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1896 1895
1897 if (core->board.audio_chip == V4L2_IDENT_WM8775) 1896 if (core->board.audio_chip == V4L2_IDENT_WM8775)
1898 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, 1897 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
1899 NULL, "wm8775", 0x36 >> 1, NULL); 1898 "wm8775", 0x36 >> 1, NULL);
1900 1899
1901 if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) { 1900 if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) {
1902 /* This probes for a tda9874 as is used on some 1901 /* This probes for a tda9874 as is used on some
1903 Pixelview Ultra boards. */ 1902 Pixelview Ultra boards. */
1904 v4l2_i2c_new_subdev(&core->v4l2_dev, 1903 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
1905 &core->i2c_adap, 1904 "tvaudio", 0, I2C_ADDRS(0xb0 >> 1));
1906 NULL, "tvaudio", 0, I2C_ADDRS(0xb0 >> 1));
1907 } 1905 }
1908 1906
1909 switch (core->boardnr) { 1907 switch (core->boardnr) {
diff --git a/drivers/media/video/davinci/vpfe_capture.c b/drivers/media/video/davinci/vpfe_capture.c
index d8e38cc4ec40..7333a9bb2549 100644
--- a/drivers/media/video/davinci/vpfe_capture.c
+++ b/drivers/media/video/davinci/vpfe_capture.c
@@ -1986,7 +1986,6 @@ static __init int vpfe_probe(struct platform_device *pdev)
1986 vpfe_dev->sd[i] = 1986 vpfe_dev->sd[i] =
1987 v4l2_i2c_new_subdev_board(&vpfe_dev->v4l2_dev, 1987 v4l2_i2c_new_subdev_board(&vpfe_dev->v4l2_dev,
1988 i2c_adap, 1988 i2c_adap,
1989 NULL,
1990 &sdinfo->board_info, 1989 &sdinfo->board_info,
1991 NULL); 1990 NULL);
1992 if (vpfe_dev->sd[i]) { 1991 if (vpfe_dev->sd[i]) {
diff --git a/drivers/media/video/davinci/vpif_capture.c b/drivers/media/video/davinci/vpif_capture.c
index 6ac6acd16352..193abab6b355 100644
--- a/drivers/media/video/davinci/vpif_capture.c
+++ b/drivers/media/video/davinci/vpif_capture.c
@@ -2013,7 +2013,6 @@ static __init int vpif_probe(struct platform_device *pdev)
2013 vpif_obj.sd[i] = 2013 vpif_obj.sd[i] =
2014 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, 2014 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
2015 i2c_adap, 2015 i2c_adap,
2016 NULL,
2017 &subdevdata->board_info, 2016 &subdevdata->board_info,
2018 NULL); 2017 NULL);
2019 2018
diff --git a/drivers/media/video/davinci/vpif_display.c b/drivers/media/video/davinci/vpif_display.c
index 685f6a6ee603..412c65d54fe1 100644
--- a/drivers/media/video/davinci/vpif_display.c
+++ b/drivers/media/video/davinci/vpif_display.c
@@ -1553,7 +1553,7 @@ static __init int vpif_probe(struct platform_device *pdev)
1553 1553
1554 for (i = 0; i < subdev_count; i++) { 1554 for (i = 0; i < subdev_count; i++) {
1555 vpif_obj.sd[i] = v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, 1555 vpif_obj.sd[i] = v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1556 i2c_adap, NULL, 1556 i2c_adap,
1557 &subdevdata[i].board_info, 1557 &subdevdata[i].board_info,
1558 NULL); 1558 NULL);
1559 if (!vpif_obj.sd[i]) { 1559 if (!vpif_obj.sd[i]) {
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 54859233f311..f7e9168157a5 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -2554,39 +2554,39 @@ void em28xx_card_setup(struct em28xx *dev)
2554 /* request some modules */ 2554 /* request some modules */
2555 if (dev->board.has_msp34xx) 2555 if (dev->board.has_msp34xx)
2556 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2556 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2557 NULL, "msp3400", 0, msp3400_addrs); 2557 "msp3400", 0, msp3400_addrs);
2558 2558
2559 if (dev->board.decoder == EM28XX_SAA711X) 2559 if (dev->board.decoder == EM28XX_SAA711X)
2560 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2560 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2561 NULL, "saa7115_auto", 0, saa711x_addrs); 2561 "saa7115_auto", 0, saa711x_addrs);
2562 2562
2563 if (dev->board.decoder == EM28XX_TVP5150) 2563 if (dev->board.decoder == EM28XX_TVP5150)
2564 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2564 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2565 NULL, "tvp5150", 0, tvp5150_addrs); 2565 "tvp5150", 0, tvp5150_addrs);
2566 2566
2567 if (dev->em28xx_sensor == EM28XX_MT9V011) { 2567 if (dev->em28xx_sensor == EM28XX_MT9V011) {
2568 struct v4l2_subdev *sd; 2568 struct v4l2_subdev *sd;
2569 2569
2570 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, 2570 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
2571 &dev->i2c_adap, NULL, "mt9v011", 0, mt9v011_addrs); 2571 &dev->i2c_adap, "mt9v011", 0, mt9v011_addrs);
2572 v4l2_subdev_call(sd, core, s_config, 0, &dev->sensor_xtal); 2572 v4l2_subdev_call(sd, core, s_config, 0, &dev->sensor_xtal);
2573 } 2573 }
2574 2574
2575 2575
2576 if (dev->board.adecoder == EM28XX_TVAUDIO) 2576 if (dev->board.adecoder == EM28XX_TVAUDIO)
2577 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2577 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2578 NULL, "tvaudio", dev->board.tvaudio_addr, NULL); 2578 "tvaudio", dev->board.tvaudio_addr, NULL);
2579 2579
2580 if (dev->board.tuner_type != TUNER_ABSENT) { 2580 if (dev->board.tuner_type != TUNER_ABSENT) {
2581 int has_demod = (dev->tda9887_conf & TDA9887_PRESENT); 2581 int has_demod = (dev->tda9887_conf & TDA9887_PRESENT);
2582 2582
2583 if (dev->board.radio.type) 2583 if (dev->board.radio.type)
2584 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2584 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2585 NULL, "tuner", dev->board.radio_addr, NULL); 2585 "tuner", dev->board.radio_addr, NULL);
2586 2586
2587 if (has_demod) 2587 if (has_demod)
2588 v4l2_i2c_new_subdev(&dev->v4l2_dev, 2588 v4l2_i2c_new_subdev(&dev->v4l2_dev,
2589 &dev->i2c_adap, NULL, "tuner", 2589 &dev->i2c_adap, "tuner",
2590 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); 2590 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
2591 if (dev->tuner_addr == 0) { 2591 if (dev->tuner_addr == 0) {
2592 enum v4l2_i2c_tuner_type type = 2592 enum v4l2_i2c_tuner_type type =
@@ -2594,14 +2594,14 @@ void em28xx_card_setup(struct em28xx *dev)
2594 struct v4l2_subdev *sd; 2594 struct v4l2_subdev *sd;
2595 2595
2596 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, 2596 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
2597 &dev->i2c_adap, NULL, "tuner", 2597 &dev->i2c_adap, "tuner",
2598 0, v4l2_i2c_tuner_addrs(type)); 2598 0, v4l2_i2c_tuner_addrs(type));
2599 2599
2600 if (sd) 2600 if (sd)
2601 dev->tuner_addr = v4l2_i2c_subdev_addr(sd); 2601 dev->tuner_addr = v4l2_i2c_subdev_addr(sd);
2602 } else { 2602 } else {
2603 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 2603 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2604 NULL, "tuner", dev->tuner_addr, NULL); 2604 "tuner", dev->tuner_addr, NULL);
2605 } 2605 }
2606 } 2606 }
2607 2607
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index a5cfc76b40b7..bb164099ea2c 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -2530,7 +2530,7 @@ static const struct v4l2_file_operations et61x251_fops = {
2530 .owner = THIS_MODULE, 2530 .owner = THIS_MODULE,
2531 .open = et61x251_open, 2531 .open = et61x251_open,
2532 .release = et61x251_release, 2532 .release = et61x251_release,
2533 .ioctl = et61x251_ioctl, 2533 .unlocked_ioctl = et61x251_ioctl,
2534 .read = et61x251_read, 2534 .read = et61x251_read,
2535 .poll = et61x251_poll, 2535 .poll = et61x251_poll,
2536 .mmap = et61x251_mmap, 2536 .mmap = et61x251_mmap,
diff --git a/drivers/media/video/fsl-viu.c b/drivers/media/video/fsl-viu.c
index 9a075d83dd1f..b8faff2dd711 100644
--- a/drivers/media/video/fsl-viu.c
+++ b/drivers/media/video/fsl-viu.c
@@ -1486,7 +1486,7 @@ static int __devinit viu_of_probe(struct platform_device *op,
1486 1486
1487 ad = i2c_get_adapter(0); 1487 ad = i2c_get_adapter(0);
1488 viu_dev->decoder = v4l2_i2c_new_subdev(&viu_dev->v4l2_dev, ad, 1488 viu_dev->decoder = v4l2_i2c_new_subdev(&viu_dev->v4l2_dev, ad,
1489 NULL, "saa7113", VIU_VIDEO_DECODER_ADDR, NULL); 1489 "saa7113", VIU_VIDEO_DECODER_ADDR, NULL);
1490 1490
1491 viu_dev->vidq.timeout.function = viu_vid_timeout; 1491 viu_dev->vidq.timeout.function = viu_vid_timeout;
1492 viu_dev->vidq.timeout.data = (unsigned long)viu_dev; 1492 viu_dev->vidq.timeout.data = (unsigned long)viu_dev;
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index 330dadc00106..e23de57e2c73 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -63,7 +63,10 @@ struct sd {
63#define QUALITY_DEF 80 63#define QUALITY_DEF 80
64 u8 jpegqual; /* webcam quality */ 64 u8 jpegqual; /* webcam quality */
65 65
66 u8 reg01;
67 u8 reg17;
66 u8 reg18; 68 u8 reg18;
69 u8 flags;
67 70
68 s8 ag_cnt; 71 s8 ag_cnt;
69#define AG_CNT_START 13 72#define AG_CNT_START 13
@@ -96,6 +99,22 @@ enum sensors {
96 SENSOR_SP80708, 99 SENSOR_SP80708,
97}; 100};
98 101
102/* device flags */
103#define PDN_INV 1 /* inverse pin S_PWR_DN / sn_xxx tables */
104
105/* sn9c1xx definitions */
106/* register 0x01 */
107#define S_PWR_DN 0x01 /* sensor power down */
108#define S_PDN_INV 0x02 /* inverse pin S_PWR_DN */
109#define V_TX_EN 0x04 /* video transfer enable */
110#define LED 0x08 /* output to pin LED */
111#define SCL_SEL_OD 0x20 /* open-drain mode */
112#define SYS_SEL_48M 0x40 /* system clock 0: 24MHz, 1: 48MHz */
113/* register 0x17 */
114#define MCK_SIZE_MASK 0x1f /* sensor master clock */
115#define SEN_CLK_EN 0x20 /* enable sensor clock */
116#define DEF_EN 0x80 /* defect pixel by 0: soft, 1: hard */
117
99/* V4L2 controls supported by the driver */ 118/* V4L2 controls supported by the driver */
100static void setbrightness(struct gspca_dev *gspca_dev); 119static void setbrightness(struct gspca_dev *gspca_dev);
101static void setcontrast(struct gspca_dev *gspca_dev); 120static void setcontrast(struct gspca_dev *gspca_dev);
@@ -1755,141 +1774,6 @@ static void po2030n_probe(struct gspca_dev *gspca_dev)
1755 } 1774 }
1756} 1775}
1757 1776
1758static void bridge_init(struct gspca_dev *gspca_dev,
1759 const u8 *sn9c1xx)
1760{
1761 struct sd *sd = (struct sd *) gspca_dev;
1762 u8 reg0102[2];
1763 const u8 *reg9a;
1764 static const u8 reg9a_def[] =
1765 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
1766 static const u8 reg9a_spec[] =
1767 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
1768 static const u8 regd4[] = {0x60, 0x00, 0x00};
1769
1770 /* sensor clock already enabled in sd_init */
1771 /* reg_w1(gspca_dev, 0xf1, 0x00); */
1772 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1773
1774 /* configure gpio */
1775 reg0102[0] = sn9c1xx[1];
1776 reg0102[1] = sn9c1xx[2];
1777 if (gspca_dev->audio)
1778 reg0102[1] |= 0x04; /* keep the audio connection */
1779 reg_w(gspca_dev, 0x01, reg0102, 2);
1780 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
1781 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
1782 switch (sd->sensor) {
1783 case SENSOR_GC0307:
1784 case SENSOR_OV7660:
1785 case SENSOR_PO1030:
1786 case SENSOR_PO2030N:
1787 case SENSOR_SOI768:
1788 case SENSOR_SP80708:
1789 reg9a = reg9a_spec;
1790 break;
1791 default:
1792 reg9a = reg9a_def;
1793 break;
1794 }
1795 reg_w(gspca_dev, 0x9a, reg9a, 6);
1796
1797 reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
1798
1799 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
1800
1801 switch (sd->sensor) {
1802 case SENSOR_ADCM1700:
1803 reg_w1(gspca_dev, 0x01, 0x43);
1804 reg_w1(gspca_dev, 0x17, 0x62);
1805 reg_w1(gspca_dev, 0x01, 0x42);
1806 reg_w1(gspca_dev, 0x01, 0x42);
1807 break;
1808 case SENSOR_GC0307:
1809 msleep(50);
1810 reg_w1(gspca_dev, 0x01, 0x61);
1811 reg_w1(gspca_dev, 0x17, 0x22);
1812 reg_w1(gspca_dev, 0x01, 0x60);
1813 reg_w1(gspca_dev, 0x01, 0x40);
1814 msleep(50);
1815 break;
1816 case SENSOR_MI0360B:
1817 reg_w1(gspca_dev, 0x01, 0x61);
1818 reg_w1(gspca_dev, 0x17, 0x60);
1819 reg_w1(gspca_dev, 0x01, 0x60);
1820 reg_w1(gspca_dev, 0x01, 0x40);
1821 break;
1822 case SENSOR_MT9V111:
1823 reg_w1(gspca_dev, 0x01, 0x61);
1824 reg_w1(gspca_dev, 0x17, 0x61);
1825 reg_w1(gspca_dev, 0x01, 0x60);
1826 reg_w1(gspca_dev, 0x01, 0x40);
1827 break;
1828 case SENSOR_OM6802:
1829 msleep(10);
1830 reg_w1(gspca_dev, 0x02, 0x73);
1831 reg_w1(gspca_dev, 0x17, 0x60);
1832 reg_w1(gspca_dev, 0x01, 0x22);
1833 msleep(100);
1834 reg_w1(gspca_dev, 0x01, 0x62);
1835 reg_w1(gspca_dev, 0x17, 0x64);
1836 reg_w1(gspca_dev, 0x17, 0x64);
1837 reg_w1(gspca_dev, 0x01, 0x42);
1838 msleep(10);
1839 reg_w1(gspca_dev, 0x01, 0x42);
1840 i2c_w8(gspca_dev, om6802_init0[0]);
1841 i2c_w8(gspca_dev, om6802_init0[1]);
1842 msleep(15);
1843 reg_w1(gspca_dev, 0x02, 0x71);
1844 msleep(150);
1845 break;
1846 case SENSOR_OV7630:
1847 reg_w1(gspca_dev, 0x01, 0x61);
1848 reg_w1(gspca_dev, 0x17, 0xe2);
1849 reg_w1(gspca_dev, 0x01, 0x60);
1850 reg_w1(gspca_dev, 0x01, 0x40);
1851 break;
1852 case SENSOR_OV7648:
1853 reg_w1(gspca_dev, 0x01, 0x63);
1854 reg_w1(gspca_dev, 0x17, 0x20);
1855 reg_w1(gspca_dev, 0x01, 0x62);
1856 reg_w1(gspca_dev, 0x01, 0x42);
1857 break;
1858 case SENSOR_PO1030:
1859 case SENSOR_SOI768:
1860 reg_w1(gspca_dev, 0x01, 0x61);
1861 reg_w1(gspca_dev, 0x17, 0x20);
1862 reg_w1(gspca_dev, 0x01, 0x60);
1863 reg_w1(gspca_dev, 0x01, 0x40);
1864 break;
1865 case SENSOR_PO2030N:
1866 case SENSOR_OV7660:
1867 reg_w1(gspca_dev, 0x01, 0x63);
1868 reg_w1(gspca_dev, 0x17, 0x20);
1869 reg_w1(gspca_dev, 0x01, 0x62);
1870 reg_w1(gspca_dev, 0x01, 0x42);
1871 break;
1872 case SENSOR_SP80708:
1873 reg_w1(gspca_dev, 0x01, 0x63);
1874 reg_w1(gspca_dev, 0x17, 0x20);
1875 reg_w1(gspca_dev, 0x01, 0x62);
1876 reg_w1(gspca_dev, 0x01, 0x42);
1877 msleep(100);
1878 reg_w1(gspca_dev, 0x02, 0x62);
1879 break;
1880 default:
1881/* case SENSOR_HV7131R: */
1882/* case SENSOR_MI0360: */
1883/* case SENSOR_MO4000: */
1884 reg_w1(gspca_dev, 0x01, 0x43);
1885 reg_w1(gspca_dev, 0x17, 0x61);
1886 reg_w1(gspca_dev, 0x01, 0x42);
1887 if (sd->sensor == SENSOR_HV7131R)
1888 hv7131r_probe(gspca_dev);
1889 break;
1890 }
1891}
1892
1893/* this function is called at probe time */ 1777/* this function is called at probe time */
1894static int sd_config(struct gspca_dev *gspca_dev, 1778static int sd_config(struct gspca_dev *gspca_dev,
1895 const struct usb_device_id *id) 1779 const struct usb_device_id *id)
@@ -1898,7 +1782,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
1898 struct cam *cam; 1782 struct cam *cam;
1899 1783
1900 sd->bridge = id->driver_info >> 16; 1784 sd->bridge = id->driver_info >> 16;
1901 sd->sensor = id->driver_info; 1785 sd->sensor = id->driver_info >> 8;
1786 sd->flags = id->driver_info;
1902 1787
1903 cam = &gspca_dev->cam; 1788 cam = &gspca_dev->cam;
1904 if (sd->sensor == SENSOR_ADCM1700) { 1789 if (sd->sensor == SENSOR_ADCM1700) {
@@ -1929,7 +1814,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
1929 /* setup a selector by bridge */ 1814 /* setup a selector by bridge */
1930 reg_w1(gspca_dev, 0xf1, 0x01); 1815 reg_w1(gspca_dev, 0xf1, 0x01);
1931 reg_r(gspca_dev, 0x00, 1); 1816 reg_r(gspca_dev, 0x00, 1);
1932 reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]); 1817 reg_w1(gspca_dev, 0xf1, 0x00);
1933 reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */ 1818 reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
1934 regF1 = gspca_dev->usb_buf[0]; 1819 regF1 = gspca_dev->usb_buf[0];
1935 if (gspca_dev->usb_err < 0) 1820 if (gspca_dev->usb_err < 0)
@@ -2423,10 +2308,17 @@ static int sd_start(struct gspca_dev *gspca_dev)
2423{ 2308{
2424 struct sd *sd = (struct sd *) gspca_dev; 2309 struct sd *sd = (struct sd *) gspca_dev;
2425 int i; 2310 int i;
2426 u8 reg1, reg17; 2311 u8 reg01, reg17;
2312 u8 reg0102[2];
2427 const u8 *sn9c1xx; 2313 const u8 *sn9c1xx;
2428 const u8 (*init)[8]; 2314 const u8 (*init)[8];
2315 const u8 *reg9a;
2429 int mode; 2316 int mode;
2317 static const u8 reg9a_def[] =
2318 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
2319 static const u8 reg9a_spec[] =
2320 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
2321 static const u8 regd4[] = {0x60, 0x00, 0x00};
2430 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f }; 2322 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
2431 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec }; 2323 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
2432 static const u8 CA_adcm1700[] = 2324 static const u8 CA_adcm1700[] =
@@ -2448,7 +2340,85 @@ static int sd_start(struct gspca_dev *gspca_dev)
2448 2340
2449 /* initialize the bridge */ 2341 /* initialize the bridge */
2450 sn9c1xx = sn_tb[sd->sensor]; 2342 sn9c1xx = sn_tb[sd->sensor];
2451 bridge_init(gspca_dev, sn9c1xx); 2343
2344 /* sensor clock already enabled in sd_init */
2345 /* reg_w1(gspca_dev, 0xf1, 0x00); */
2346 reg01 = sn9c1xx[1];
2347 if (sd->flags & PDN_INV)
2348 reg01 ^= S_PDN_INV; /* power down inverted */
2349 reg_w1(gspca_dev, 0x01, reg01);
2350
2351 /* configure gpio */
2352 reg0102[0] = reg01;
2353 reg0102[1] = sn9c1xx[2];
2354 if (gspca_dev->audio)
2355 reg0102[1] |= 0x04; /* keep the audio connection */
2356 reg_w(gspca_dev, 0x01, reg0102, 2);
2357 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
2358 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
2359 switch (sd->sensor) {
2360 case SENSOR_GC0307:
2361 case SENSOR_OV7660:
2362 case SENSOR_PO1030:
2363 case SENSOR_PO2030N:
2364 case SENSOR_SOI768:
2365 case SENSOR_SP80708:
2366 reg9a = reg9a_spec;
2367 break;
2368 default:
2369 reg9a = reg9a_def;
2370 break;
2371 }
2372 reg_w(gspca_dev, 0x9a, reg9a, 6);
2373
2374 reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
2375
2376 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
2377
2378 reg17 = sn9c1xx[0x17];
2379 switch (sd->sensor) {
2380 case SENSOR_GC0307:
2381 msleep(50); /*fixme: is it useful? */
2382 break;
2383 case SENSOR_OM6802:
2384 msleep(10);
2385 reg_w1(gspca_dev, 0x02, 0x73);
2386 reg17 |= SEN_CLK_EN;
2387 reg_w1(gspca_dev, 0x17, reg17);
2388 reg_w1(gspca_dev, 0x01, 0x22);
2389 msleep(100);
2390 reg01 = SCL_SEL_OD | S_PDN_INV;
2391 reg17 &= MCK_SIZE_MASK;
2392 reg17 |= 0x04; /* clock / 4 */
2393 break;
2394 }
2395 reg01 |= SYS_SEL_48M;
2396 reg_w1(gspca_dev, 0x01, reg01);
2397 reg17 |= SEN_CLK_EN;
2398 reg_w1(gspca_dev, 0x17, reg17);
2399 reg01 &= ~S_PWR_DN; /* sensor power on */
2400 reg_w1(gspca_dev, 0x01, reg01);
2401 reg01 &= ~SYS_SEL_48M;
2402 reg_w1(gspca_dev, 0x01, reg01);
2403
2404 switch (sd->sensor) {
2405 case SENSOR_HV7131R:
2406 hv7131r_probe(gspca_dev); /*fixme: is it useful? */
2407 break;
2408 case SENSOR_OM6802:
2409 msleep(10);
2410 reg_w1(gspca_dev, 0x01, reg01);
2411 i2c_w8(gspca_dev, om6802_init0[0]);
2412 i2c_w8(gspca_dev, om6802_init0[1]);
2413 msleep(15);
2414 reg_w1(gspca_dev, 0x02, 0x71);
2415 msleep(150);
2416 break;
2417 case SENSOR_SP80708:
2418 msleep(100);
2419 reg_w1(gspca_dev, 0x02, 0x62);
2420 break;
2421 }
2452 2422
2453 /* initialize the sensor */ 2423 /* initialize the sensor */
2454 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]); 2424 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
@@ -2476,30 +2446,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
2476 } 2446 }
2477 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]); 2447 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
2478 switch (sd->sensor) { 2448 switch (sd->sensor) {
2479 case SENSOR_GC0307: 2449 case SENSOR_OM6802:
2480 reg17 = 0xa2; 2450/* case SENSOR_OV7648: * fixme: sometimes */
2481 break;
2482 case SENSOR_MT9V111:
2483 case SENSOR_MI0360B:
2484 reg17 = 0xe0;
2485 break;
2486 case SENSOR_ADCM1700:
2487 case SENSOR_OV7630:
2488 reg17 = 0xe2;
2489 break;
2490 case SENSOR_OV7648:
2491 reg17 = 0x20;
2492 break;
2493 case SENSOR_OV7660:
2494 case SENSOR_SOI768:
2495 reg17 = 0xa0;
2496 break;
2497 case SENSOR_PO1030:
2498 case SENSOR_PO2030N:
2499 reg17 = 0xa0;
2500 break; 2451 break;
2501 default: 2452 default:
2502 reg17 = 0x60; 2453 reg17 |= DEF_EN;
2503 break; 2454 break;
2504 } 2455 }
2505 reg_w1(gspca_dev, 0x17, reg17); 2456 reg_w1(gspca_dev, 0x17, reg17);
@@ -2546,95 +2497,67 @@ static int sd_start(struct gspca_dev *gspca_dev)
2546 2497
2547 init = NULL; 2498 init = NULL;
2548 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; 2499 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
2549 if (mode) 2500 reg01 |= SYS_SEL_48M | V_TX_EN;
2550 reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */ 2501 reg17 &= ~MCK_SIZE_MASK;
2551 else 2502 reg17 |= 0x02; /* clock / 2 */
2552 reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
2553 reg17 = 0x61; /* 0x:20: enable sensor clock */
2554 switch (sd->sensor) { 2503 switch (sd->sensor) {
2555 case SENSOR_ADCM1700: 2504 case SENSOR_ADCM1700:
2556 init = adcm1700_sensor_param1; 2505 init = adcm1700_sensor_param1;
2557 reg1 = 0x46;
2558 reg17 = 0xe2;
2559 break; 2506 break;
2560 case SENSOR_GC0307: 2507 case SENSOR_GC0307:
2561 init = gc0307_sensor_param1; 2508 init = gc0307_sensor_param1;
2562 reg17 = 0xa2; 2509 break;
2563 reg1 = 0x44; 2510 case SENSOR_HV7131R:
2511 case SENSOR_MI0360:
2512 if (mode)
2513 reg01 |= SYS_SEL_48M; /* 320x240: clk 48Mhz */
2514 else
2515 reg01 &= ~SYS_SEL_48M; /* 640x480: clk 24Mhz */
2516 reg17 &= ~MCK_SIZE_MASK;
2517 reg17 |= 0x01; /* clock / 1 */
2564 break; 2518 break;
2565 case SENSOR_MI0360B: 2519 case SENSOR_MI0360B:
2566 init = mi0360b_sensor_param1; 2520 init = mi0360b_sensor_param1;
2567 reg1 &= ~0x02; /* don't inverse pin S_PWR_DN */
2568 reg17 = 0xe2;
2569 break; 2521 break;
2570 case SENSOR_MO4000: 2522 case SENSOR_MO4000:
2571 if (mode) { 2523 if (mode) { /* if 320x240 */
2572/* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */ 2524 reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
2573 reg1 = 0x06; /* clk 24Mz */ 2525 reg17 &= ~MCK_SIZE_MASK;
2574 } else { 2526 reg17 |= 0x01; /* clock / 1 */
2575 reg17 = 0x22; /* 640 MCKSIZE */
2576/* reg1 = 0x06; * 640 clk 24Mz (done) */
2577 } 2527 }
2578 break; 2528 break;
2579 case SENSOR_MT9V111: 2529 case SENSOR_MT9V111:
2580 init = mt9v111_sensor_param1; 2530 init = mt9v111_sensor_param1;
2581 if (mode) {
2582 reg1 = 0x04; /* 320 clk 48Mhz */
2583 } else {
2584/* reg1 = 0x06; * 640 clk 24Mz (done) */
2585 reg17 = 0xc2;
2586 }
2587 break; 2531 break;
2588 case SENSOR_OM6802: 2532 case SENSOR_OM6802:
2589 init = om6802_sensor_param1; 2533 init = om6802_sensor_param1;
2590 reg17 = 0x64; /* 640 MCKSIZE */ 2534 if (!mode) { /* if 640x480 */
2535 reg17 &= ~MCK_SIZE_MASK;
2536 reg17 |= 0x01; /* clock / 4 */
2537 }
2591 break; 2538 break;
2592 case SENSOR_OV7630: 2539 case SENSOR_OV7630:
2593 init = ov7630_sensor_param1; 2540 init = ov7630_sensor_param1;
2594 reg17 = 0xe2;
2595 reg1 = 0x44;
2596 break; 2541 break;
2597 case SENSOR_OV7648: 2542 case SENSOR_OV7648:
2598 init = ov7648_sensor_param1; 2543 init = ov7648_sensor_param1;
2599 reg17 = 0x21; 2544 reg17 &= ~MCK_SIZE_MASK;
2600/* reg1 = 0x42; * 42 - 46? */ 2545 reg17 |= 0x01; /* clock / 1 */
2601 break; 2546 break;
2602 case SENSOR_OV7660: 2547 case SENSOR_OV7660:
2603 init = ov7660_sensor_param1; 2548 init = ov7660_sensor_param1;
2604 if (sd->bridge == BRIDGE_SN9C120) {
2605 if (mode) { /* 320x240 - 160x120 */
2606 reg17 = 0xa2;
2607 reg1 = 0x44; /* 48 Mhz, video trf eneble */
2608 }
2609 } else {
2610 reg17 = 0x22;
2611 reg1 = 0x06; /* 24 Mhz, video trf eneble
2612 * inverse power down */
2613 }
2614 break; 2549 break;
2615 case SENSOR_PO1030: 2550 case SENSOR_PO1030:
2616 init = po1030_sensor_param1; 2551 init = po1030_sensor_param1;
2617 reg17 = 0xa2;
2618 reg1 = 0x44;
2619 break; 2552 break;
2620 case SENSOR_PO2030N: 2553 case SENSOR_PO2030N:
2621 init = po2030n_sensor_param1; 2554 init = po2030n_sensor_param1;
2622 reg1 = 0x46;
2623 reg17 = 0xa2;
2624 break; 2555 break;
2625 case SENSOR_SOI768: 2556 case SENSOR_SOI768:
2626 init = soi768_sensor_param1; 2557 init = soi768_sensor_param1;
2627 reg1 = 0x44;
2628 reg17 = 0xa2;
2629 break; 2558 break;
2630 case SENSOR_SP80708: 2559 case SENSOR_SP80708:
2631 init = sp80708_sensor_param1; 2560 init = sp80708_sensor_param1;
2632 if (mode) {
2633/*?? reg1 = 0x04; * 320 clk 48Mhz */
2634 } else {
2635 reg1 = 0x46; /* 640 clk 48Mz */
2636 reg17 = 0xa2;
2637 }
2638 break; 2561 break;
2639 } 2562 }
2640 2563
@@ -2684,7 +2607,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
2684 setjpegqual(gspca_dev); 2607 setjpegqual(gspca_dev);
2685 2608
2686 reg_w1(gspca_dev, 0x17, reg17); 2609 reg_w1(gspca_dev, 0x17, reg17);
2687 reg_w1(gspca_dev, 0x01, reg1); 2610 reg_w1(gspca_dev, 0x01, reg01);
2611 sd->reg01 = reg01;
2612 sd->reg17 = reg17;
2688 2613
2689 sethvflip(gspca_dev); 2614 sethvflip(gspca_dev);
2690 setbrightness(gspca_dev); 2615 setbrightness(gspca_dev);
@@ -2706,41 +2631,64 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
2706 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 }; 2631 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
2707 static const u8 stopsoi768[] = 2632 static const u8 stopsoi768[] =
2708 { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 }; 2633 { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
2709 u8 data; 2634 u8 reg01;
2710 const u8 *sn9c1xx; 2635 u8 reg17;
2711 2636
2712 data = 0x0b; 2637 reg01 = sd->reg01;
2638 reg17 = sd->reg17 & ~SEN_CLK_EN;
2713 switch (sd->sensor) { 2639 switch (sd->sensor) {
2640 case SENSOR_ADCM1700:
2714 case SENSOR_GC0307: 2641 case SENSOR_GC0307:
2715 data = 0x29; 2642 case SENSOR_PO2030N:
2643 case SENSOR_SP80708:
2644 reg01 |= LED;
2645 reg_w1(gspca_dev, 0x01, reg01);
2646 reg01 &= ~(LED | V_TX_EN);
2647 reg_w1(gspca_dev, 0x01, reg01);
2648/* reg_w1(gspca_dev, 0x02, 0x??); * LED off ? */
2716 break; 2649 break;
2717 case SENSOR_HV7131R: 2650 case SENSOR_HV7131R:
2651 reg01 &= ~V_TX_EN;
2652 reg_w1(gspca_dev, 0x01, reg01);
2718 i2c_w8(gspca_dev, stophv7131); 2653 i2c_w8(gspca_dev, stophv7131);
2719 data = 0x2b;
2720 break; 2654 break;
2721 case SENSOR_MI0360: 2655 case SENSOR_MI0360:
2722 case SENSOR_MI0360B: 2656 case SENSOR_MI0360B:
2657 reg01 &= ~V_TX_EN;
2658 reg_w1(gspca_dev, 0x01, reg01);
2659/* reg_w1(gspca_dev, 0x02, 0x40); * LED off ? */
2723 i2c_w8(gspca_dev, stopmi0360); 2660 i2c_w8(gspca_dev, stopmi0360);
2724 data = 0x29;
2725 break; 2661 break;
2726 case SENSOR_OV7648:
2727 i2c_w8(gspca_dev, stopov7648);
2728 /* fall thru */
2729 case SENSOR_MT9V111: 2662 case SENSOR_MT9V111:
2730 case SENSOR_OV7630: 2663 case SENSOR_OM6802:
2731 case SENSOR_PO1030: 2664 case SENSOR_PO1030:
2732 data = 0x29; 2665 reg01 &= ~V_TX_EN;
2666 reg_w1(gspca_dev, 0x01, reg01);
2667 break;
2668 case SENSOR_OV7630:
2669 case SENSOR_OV7648:
2670 reg01 &= ~V_TX_EN;
2671 reg_w1(gspca_dev, 0x01, reg01);
2672 i2c_w8(gspca_dev, stopov7648);
2673 break;
2674 case SENSOR_OV7660:
2675 reg01 &= ~V_TX_EN;
2676 reg_w1(gspca_dev, 0x01, reg01);
2733 break; 2677 break;
2734 case SENSOR_SOI768: 2678 case SENSOR_SOI768:
2735 i2c_w8(gspca_dev, stopsoi768); 2679 i2c_w8(gspca_dev, stopsoi768);
2736 data = 0x29;
2737 break; 2680 break;
2738 } 2681 }
2739 sn9c1xx = sn_tb[sd->sensor]; 2682
2740 reg_w1(gspca_dev, 0x01, sn9c1xx[1]); 2683 reg01 |= SCL_SEL_OD;
2741 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]); 2684 reg_w1(gspca_dev, 0x01, reg01);
2742 reg_w1(gspca_dev, 0x01, sn9c1xx[1]); 2685 reg01 |= S_PWR_DN; /* sensor power down */
2743 reg_w1(gspca_dev, 0x01, data); 2686 reg_w1(gspca_dev, 0x01, reg01);
2687 reg_w1(gspca_dev, 0x17, reg17);
2688 reg01 &= ~SYS_SEL_48M; /* clock 24MHz */
2689 reg_w1(gspca_dev, 0x01, reg01);
2690 reg01 |= LED;
2691 reg_w1(gspca_dev, 0x01, reg01);
2744 /* Don't disable sensor clock as that disables the button on the cam */ 2692 /* Don't disable sensor clock as that disables the button on the cam */
2745 /* reg_w1(gspca_dev, 0xf1, 0x01); */ 2693 /* reg_w1(gspca_dev, 0xf1, 0x01); */
2746} 2694}
@@ -2954,14 +2902,18 @@ static const struct sd_desc sd_desc = {
2954/* -- module initialisation -- */ 2902/* -- module initialisation -- */
2955#define BS(bridge, sensor) \ 2903#define BS(bridge, sensor) \
2956 .driver_info = (BRIDGE_ ## bridge << 16) \ 2904 .driver_info = (BRIDGE_ ## bridge << 16) \
2957 | SENSOR_ ## sensor 2905 | (SENSOR_ ## sensor << 8)
2906#define BSF(bridge, sensor, flags) \
2907 .driver_info = (BRIDGE_ ## bridge << 16) \
2908 | (SENSOR_ ## sensor << 8) \
2909 | (flags)
2958static const __devinitdata struct usb_device_id device_table[] = { 2910static const __devinitdata struct usb_device_id device_table[] = {
2959#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 2911#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2960 {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)}, 2912 {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
2961 {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)}, 2913 {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
2962#endif 2914#endif
2963 {USB_DEVICE(0x045e, 0x00f5), BS(SN9C105, OV7660)}, 2915 {USB_DEVICE(0x045e, 0x00f5), BSF(SN9C105, OV7660, PDN_INV)},
2964 {USB_DEVICE(0x045e, 0x00f7), BS(SN9C105, OV7660)}, 2916 {USB_DEVICE(0x045e, 0x00f7), BSF(SN9C105, OV7660, PDN_INV)},
2965 {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)}, 2917 {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
2966 {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)}, 2918 {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
2967 {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)}, 2919 {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
diff --git a/drivers/media/video/imx074.c b/drivers/media/video/imx074.c
index 380e459f899d..27b5dfdfbb93 100644
--- a/drivers/media/video/imx074.c
+++ b/drivers/media/video/imx074.c
@@ -451,7 +451,6 @@ static int imx074_probe(struct i2c_client *client,
451 ret = imx074_video_probe(icd, client); 451 ret = imx074_video_probe(icd, client);
452 if (ret < 0) { 452 if (ret < 0) {
453 icd->ops = NULL; 453 icd->ops = NULL;
454 i2c_set_clientdata(client, NULL);
455 kfree(priv); 454 kfree(priv);
456 return ret; 455 return ret;
457 } 456 }
@@ -468,7 +467,6 @@ static int imx074_remove(struct i2c_client *client)
468 icd->ops = NULL; 467 icd->ops = NULL;
469 if (icl->free_bus) 468 if (icl->free_bus)
470 icl->free_bus(icl); 469 icl->free_bus(icl);
471 i2c_set_clientdata(client, NULL);
472 client->driver = NULL; 470 client->driver = NULL;
473 kfree(priv); 471 kfree(priv);
474 472
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 5a000c65ae98..ce4a75375909 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -44,7 +44,6 @@
44#include <linux/errno.h> 44#include <linux/errno.h>
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/i2c.h> 46#include <linux/i2c.h>
47#include <linux/i2c-id.h>
48#include <linux/workqueue.h> 47#include <linux/workqueue.h>
49 48
50#include <media/ir-core.h> 49#include <media/ir-core.h>
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index 9e8039ac909e..665191c9b407 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -239,19 +239,16 @@ int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
239 return -1; 239 return -1;
240 if (hw == IVTV_HW_TUNER) { 240 if (hw == IVTV_HW_TUNER) {
241 /* special tuner handling */ 241 /* special tuner handling */
242 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, 242 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, adap, type, 0,
243 adap, NULL, type, 243 itv->card_i2c->radio);
244 0, itv->card_i2c->radio);
245 if (sd) 244 if (sd)
246 sd->grp_id = 1 << idx; 245 sd->grp_id = 1 << idx;
247 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, 246 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, adap, type, 0,
248 adap, NULL, type, 247 itv->card_i2c->demod);
249 0, itv->card_i2c->demod);
250 if (sd) 248 if (sd)
251 sd->grp_id = 1 << idx; 249 sd->grp_id = 1 << idx;
252 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, 250 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, adap, type, 0,
253 adap, NULL, type, 251 itv->card_i2c->tv);
254 0, itv->card_i2c->tv);
255 if (sd) 252 if (sd)
256 sd->grp_id = 1 << idx; 253 sd->grp_id = 1 << idx;
257 return sd ? 0 : -1; 254 return sd ? 0 : -1;
@@ -267,17 +264,16 @@ int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
267 /* It's an I2C device other than an analog tuner or IR chip */ 264 /* It's an I2C device other than an analog tuner or IR chip */
268 if (hw == IVTV_HW_UPD64031A || hw == IVTV_HW_UPD6408X) { 265 if (hw == IVTV_HW_UPD64031A || hw == IVTV_HW_UPD6408X) {
269 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, 266 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
270 adap, NULL, type, 0, I2C_ADDRS(hw_addrs[idx])); 267 adap, type, 0, I2C_ADDRS(hw_addrs[idx]));
271 } else if (hw == IVTV_HW_CX25840) { 268 } else if (hw == IVTV_HW_CX25840) {
272 struct cx25840_platform_data pdata; 269 struct cx25840_platform_data pdata;
273 270
274 pdata.pvr150_workaround = itv->pvr150_workaround; 271 pdata.pvr150_workaround = itv->pvr150_workaround;
275 sd = v4l2_i2c_new_subdev_cfg(&itv->v4l2_dev, 272 sd = v4l2_i2c_new_subdev_cfg(&itv->v4l2_dev,
276 adap, NULL, type, 0, &pdata, hw_addrs[idx], 273 adap, type, 0, &pdata, hw_addrs[idx], NULL);
277 NULL);
278 } else { 274 } else {
279 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, 275 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
280 adap, NULL, type, hw_addrs[idx], NULL); 276 adap, type, hw_addrs[idx], NULL);
281 } 277 }
282 if (sd) 278 if (sd)
283 sd->grp_id = 1 << idx; 279 sd->grp_id = 1 << idx;
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 2be23bccd3c8..48d2c2419c13 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -1659,7 +1659,7 @@ static const struct v4l2_file_operations meye_fops = {
1659 .open = meye_open, 1659 .open = meye_open,
1660 .release = meye_release, 1660 .release = meye_release,
1661 .mmap = meye_mmap, 1661 .mmap = meye_mmap,
1662 .ioctl = video_ioctl2, 1662 .unlocked_ioctl = video_ioctl2,
1663 .poll = meye_poll, 1663 .poll = meye_poll,
1664}; 1664};
1665 1665
@@ -1831,12 +1831,6 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1831 msleep(1); 1831 msleep(1);
1832 mchip_set(MCHIP_MM_INTA, MCHIP_MM_INTA_HIC_1_MASK); 1832 mchip_set(MCHIP_MM_INTA, MCHIP_MM_INTA_HIC_1_MASK);
1833 1833
1834 if (video_register_device(meye.vdev, VFL_TYPE_GRABBER,
1835 video_nr) < 0) {
1836 v4l2_err(v4l2_dev, "video_register_device failed\n");
1837 goto outvideoreg;
1838 }
1839
1840 mutex_init(&meye.lock); 1834 mutex_init(&meye.lock);
1841 init_waitqueue_head(&meye.proc_list); 1835 init_waitqueue_head(&meye.proc_list);
1842 meye.brightness = 32 << 10; 1836 meye.brightness = 32 << 10;
@@ -1858,6 +1852,12 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1858 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE, 0); 1852 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE, 0);
1859 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC, 48); 1853 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC, 48);
1860 1854
1855 if (video_register_device(meye.vdev, VFL_TYPE_GRABBER,
1856 video_nr) < 0) {
1857 v4l2_err(v4l2_dev, "video_register_device failed\n");
1858 goto outvideoreg;
1859 }
1860
1861 v4l2_info(v4l2_dev, "Motion Eye Camera Driver v%s.\n", 1861 v4l2_info(v4l2_dev, "Motion Eye Camera Driver v%s.\n",
1862 MEYE_DRIVER_VERSION); 1862 MEYE_DRIVER_VERSION);
1863 v4l2_info(v4l2_dev, "mchip KL5A72002 rev. %d, base %lx, irq %d\n", 1863 v4l2_info(v4l2_dev, "mchip KL5A72002 rev. %d, base %lx, irq %d\n",
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index 4a27862da30d..072bd2d1cfad 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -31,6 +31,7 @@
31 31
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-dev.h> 33#include <media/v4l2-dev.h>
34#include <media/videobuf-core.h>
34#include <media/videobuf-dma-contig.h> 35#include <media/videobuf-dma-contig.h>
35#include <media/soc_camera.h> 36#include <media/soc_camera.h>
36#include <media/soc_mediabus.h> 37#include <media/soc_mediabus.h>
@@ -903,8 +904,6 @@ static int mx2_camera_set_crop(struct soc_camera_device *icd,
903static int mx2_camera_set_fmt(struct soc_camera_device *icd, 904static int mx2_camera_set_fmt(struct soc_camera_device *icd,
904 struct v4l2_format *f) 905 struct v4l2_format *f)
905{ 906{
906 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
907 struct mx2_camera_dev *pcdev = ici->priv;
908 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 907 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
909 const struct soc_camera_format_xlate *xlate; 908 const struct soc_camera_format_xlate *xlate;
910 struct v4l2_pix_format *pix = &f->fmt.pix; 909 struct v4l2_pix_format *pix = &f->fmt.pix;
@@ -943,8 +942,6 @@ static int mx2_camera_set_fmt(struct soc_camera_device *icd,
943static int mx2_camera_try_fmt(struct soc_camera_device *icd, 942static int mx2_camera_try_fmt(struct soc_camera_device *icd,
944 struct v4l2_format *f) 943 struct v4l2_format *f)
945{ 944{
946 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
947 struct mx2_camera_dev *pcdev = ici->priv;
948 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 945 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
949 const struct soc_camera_format_xlate *xlate; 946 const struct soc_camera_format_xlate *xlate;
950 struct v4l2_pix_format *pix = &f->fmt.pix; 947 struct v4l2_pix_format *pix = &f->fmt.pix;
@@ -1024,13 +1021,13 @@ static int mx2_camera_querycap(struct soc_camera_host *ici,
1024 return 0; 1021 return 0;
1025} 1022}
1026 1023
1027static int mx2_camera_reqbufs(struct soc_camera_file *icf, 1024static int mx2_camera_reqbufs(struct soc_camera_device *icd,
1028 struct v4l2_requestbuffers *p) 1025 struct v4l2_requestbuffers *p)
1029{ 1026{
1030 int i; 1027 int i;
1031 1028
1032 for (i = 0; i < p->count; i++) { 1029 for (i = 0; i < p->count; i++) {
1033 struct mx2_buffer *buf = container_of(icf->vb_vidq.bufs[i], 1030 struct mx2_buffer *buf = container_of(icd->vb_vidq.bufs[i],
1034 struct mx2_buffer, vb); 1031 struct mx2_buffer, vb);
1035 INIT_LIST_HEAD(&buf->vb.queue); 1032 INIT_LIST_HEAD(&buf->vb.queue);
1036 } 1033 }
@@ -1151,9 +1148,9 @@ err_out:
1151 1148
1152static unsigned int mx2_camera_poll(struct file *file, poll_table *pt) 1149static unsigned int mx2_camera_poll(struct file *file, poll_table *pt)
1153{ 1150{
1154 struct soc_camera_file *icf = file->private_data; 1151 struct soc_camera_device *icd = file->private_data;
1155 1152
1156 return videobuf_poll_stream(file, &icf->vb_vidq, pt); 1153 return videobuf_poll_stream(file, &icd->vb_vidq, pt);
1157} 1154}
1158 1155
1159static struct soc_camera_host_ops mx2_soc_camera_host_ops = { 1156static struct soc_camera_host_ops mx2_soc_camera_host_ops = {
diff --git a/drivers/media/video/mx3_camera.c b/drivers/media/video/mx3_camera.c
index 29c5fc348133..aa871c2936b3 100644
--- a/drivers/media/video/mx3_camera.c
+++ b/drivers/media/video/mx3_camera.c
@@ -27,6 +27,7 @@
27 27
28#include <mach/ipu.h> 28#include <mach/ipu.h>
29#include <mach/mx3_camera.h> 29#include <mach/mx3_camera.h>
30#include <mach/dma.h>
30 31
31#define MX3_CAM_DRV_NAME "mx3-camera" 32#define MX3_CAM_DRV_NAME "mx3-camera"
32 33
@@ -638,6 +639,9 @@ static bool chan_filter(struct dma_chan *chan, void *arg)
638 struct dma_chan_request *rq = arg; 639 struct dma_chan_request *rq = arg;
639 struct mx3_camera_pdata *pdata; 640 struct mx3_camera_pdata *pdata;
640 641
642 if (!imx_dma_is_ipu(chan))
643 return false;
644
641 if (!rq) 645 if (!rq)
642 return false; 646 return false;
643 647
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 94ba698d0ad4..4e8fd965f151 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -185,17 +185,17 @@ static int mxb_probe(struct saa7146_dev *dev)
185 } 185 }
186 186
187 mxb->saa7111a = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter, 187 mxb->saa7111a = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
188 NULL, "saa7111", I2C_SAA7111A, NULL); 188 "saa7111", I2C_SAA7111A, NULL);
189 mxb->tea6420_1 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter, 189 mxb->tea6420_1 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
190 NULL, "tea6420", I2C_TEA6420_1, NULL); 190 "tea6420", I2C_TEA6420_1, NULL);
191 mxb->tea6420_2 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter, 191 mxb->tea6420_2 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
192 NULL, "tea6420", I2C_TEA6420_2, NULL); 192 "tea6420", I2C_TEA6420_2, NULL);
193 mxb->tea6415c = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter, 193 mxb->tea6415c = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
194 NULL, "tea6415c", I2C_TEA6415C, NULL); 194 "tea6415c", I2C_TEA6415C, NULL);
195 mxb->tda9840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter, 195 mxb->tda9840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
196 NULL, "tda9840", I2C_TDA9840, NULL); 196 "tda9840", I2C_TDA9840, NULL);
197 mxb->tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter, 197 mxb->tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
198 NULL, "tuner", I2C_TUNER, NULL); 198 "tuner", I2C_TUNER, NULL);
199 199
200 /* check if all devices are present */ 200 /* check if all devices are present */
201 if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c || 201 if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c ||
diff --git a/drivers/media/video/omap1_camera.c b/drivers/media/video/omap1_camera.c
index 7c30e62b50db..cbfd07f2d9da 100644
--- a/drivers/media/video/omap1_camera.c
+++ b/drivers/media/video/omap1_camera.c
@@ -235,7 +235,7 @@ static void free_buffer(struct videobuf_queue *vq, struct omap1_cam_buf *buf,
235 235
236 BUG_ON(in_interrupt()); 236 BUG_ON(in_interrupt());
237 237
238 videobuf_waiton(vb, 0, 0); 238 videobuf_waiton(vq, vb, 0, 0);
239 239
240 if (vb_mode == OMAP1_CAM_DMA_CONTIG) { 240 if (vb_mode == OMAP1_CAM_DMA_CONTIG) {
241 videobuf_dma_contig_free(vq, vb); 241 videobuf_dma_contig_free(vq, vb);
@@ -504,7 +504,7 @@ static void omap1_videobuf_queue(struct videobuf_queue *vq,
504 * empty. Since the transfer of the DMA programming register set 504 * empty. Since the transfer of the DMA programming register set
505 * content to the DMA working register set is done automatically 505 * content to the DMA working register set is done automatically
506 * by the DMA hardware, this can pretty well happen while we 506 * by the DMA hardware, this can pretty well happen while we
507 * are keeping the lock here. Levae fetching it from the queue 507 * are keeping the lock here. Leave fetching it from the queue
508 * to be done when a next DMA interrupt occures instead. 508 * to be done when a next DMA interrupt occures instead.
509 */ 509 */
510 return; 510 return;
@@ -1365,12 +1365,12 @@ static void omap1_cam_init_videobuf(struct videobuf_queue *q,
1365 videobuf_queue_dma_contig_init(q, &omap1_videobuf_ops, 1365 videobuf_queue_dma_contig_init(q, &omap1_videobuf_ops,
1366 icd->dev.parent, &pcdev->lock, 1366 icd->dev.parent, &pcdev->lock,
1367 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 1367 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
1368 sizeof(struct omap1_cam_buf), icd); 1368 sizeof(struct omap1_cam_buf), icd, NULL);
1369 else 1369 else
1370 videobuf_queue_sg_init(q, &omap1_videobuf_ops, 1370 videobuf_queue_sg_init(q, &omap1_videobuf_ops,
1371 icd->dev.parent, &pcdev->lock, 1371 icd->dev.parent, &pcdev->lock,
1372 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 1372 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
1373 sizeof(struct omap1_cam_buf), icd); 1373 sizeof(struct omap1_cam_buf), icd, NULL);
1374 1374
1375 /* use videobuf mode (auto)selected with the module parameter */ 1375 /* use videobuf mode (auto)selected with the module parameter */
1376 pcdev->vb_mode = sg_mode ? OMAP1_CAM_DMA_SG : OMAP1_CAM_DMA_CONTIG; 1376 pcdev->vb_mode = sg_mode ? OMAP1_CAM_DMA_SG : OMAP1_CAM_DMA_CONTIG;
@@ -1386,7 +1386,7 @@ static void omap1_cam_init_videobuf(struct videobuf_queue *q,
1386 } 1386 }
1387} 1387}
1388 1388
1389static int omap1_cam_reqbufs(struct soc_camera_file *icf, 1389static int omap1_cam_reqbufs(struct soc_camera_device *icd,
1390 struct v4l2_requestbuffers *p) 1390 struct v4l2_requestbuffers *p)
1391{ 1391{
1392 int i; 1392 int i;
@@ -1398,7 +1398,7 @@ static int omap1_cam_reqbufs(struct soc_camera_file *icf,
1398 * it hadn't triggered 1398 * it hadn't triggered
1399 */ 1399 */
1400 for (i = 0; i < p->count; i++) { 1400 for (i = 0; i < p->count; i++) {
1401 struct omap1_cam_buf *buf = container_of(icf->vb_vidq.bufs[i], 1401 struct omap1_cam_buf *buf = container_of(icd->vb_vidq.bufs[i],
1402 struct omap1_cam_buf, vb); 1402 struct omap1_cam_buf, vb);
1403 buf->inwork = 0; 1403 buf->inwork = 0;
1404 INIT_LIST_HEAD(&buf->vb.queue); 1404 INIT_LIST_HEAD(&buf->vb.queue);
@@ -1485,10 +1485,10 @@ static int omap1_cam_set_bus_param(struct soc_camera_device *icd,
1485 1485
1486static unsigned int omap1_cam_poll(struct file *file, poll_table *pt) 1486static unsigned int omap1_cam_poll(struct file *file, poll_table *pt)
1487{ 1487{
1488 struct soc_camera_file *icf = file->private_data; 1488 struct soc_camera_device *icd = file->private_data;
1489 struct omap1_cam_buf *buf; 1489 struct omap1_cam_buf *buf;
1490 1490
1491 buf = list_entry(icf->vb_vidq.stream.next, struct omap1_cam_buf, 1491 buf = list_entry(icd->vb_vidq.stream.next, struct omap1_cam_buf,
1492 vb.stream); 1492 vb.stream);
1493 1493
1494 poll_wait(file, &buf->vb.done, pt); 1494 poll_wait(file, &buf->vb.done, pt);
diff --git a/drivers/media/video/ov6650.c b/drivers/media/video/ov6650.c
index b7cfeab0948c..cf93de988068 100644
--- a/drivers/media/video/ov6650.c
+++ b/drivers/media/video/ov6650.c
@@ -754,7 +754,7 @@ static int ov6650_g_fmt(struct v4l2_subdev *sd,
754 754
755static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect) 755static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect)
756{ 756{
757 return (width > rect->width >> 1 || height > rect->height >> 1); 757 return width > rect->width >> 1 || height > rect->height >> 1;
758} 758}
759 759
760static u8 to_clkrc(struct v4l2_fract *timeperframe, 760static u8 to_clkrc(struct v4l2_fract *timeperframe,
@@ -840,8 +840,6 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
840 coma_mask |= COMA_BW | COMA_BYTE_SWAP | COMA_WORD_SWAP; 840 coma_mask |= COMA_BW | COMA_BYTE_SWAP | COMA_WORD_SWAP;
841 coma_set |= COMA_RAW_RGB | COMA_RGB; 841 coma_set |= COMA_RAW_RGB | COMA_RGB;
842 break; 842 break;
843 case 0:
844 break;
845 default: 843 default:
846 dev_err(&client->dev, "Pixel format not handled: 0x%x\n", code); 844 dev_err(&client->dev, "Pixel format not handled: 0x%x\n", code);
847 return -EINVAL; 845 return -EINVAL;
@@ -1176,7 +1174,6 @@ static int ov6650_probe(struct i2c_client *client,
1176 1174
1177 if (ret) { 1175 if (ret) {
1178 icd->ops = NULL; 1176 icd->ops = NULL;
1179 i2c_set_clientdata(client, NULL);
1180 kfree(priv); 1177 kfree(priv);
1181 } 1178 }
1182 1179
@@ -1187,7 +1184,6 @@ static int ov6650_remove(struct i2c_client *client)
1187{ 1184{
1188 struct ov6650 *priv = to_ov6650(client); 1185 struct ov6650 *priv = to_ov6650(client);
1189 1186
1190 i2c_set_clientdata(client, NULL);
1191 kfree(priv); 1187 kfree(priv);
1192 return 0; 1188 return 0;
1193} 1189}
diff --git a/drivers/media/video/pms.c b/drivers/media/video/pms.c
index 7129b50757db..7551907f8c28 100644
--- a/drivers/media/video/pms.c
+++ b/drivers/media/video/pms.c
@@ -932,7 +932,7 @@ static ssize_t pms_read(struct file *file, char __user *buf,
932 932
933static const struct v4l2_file_operations pms_fops = { 933static const struct v4l2_file_operations pms_fops = {
934 .owner = THIS_MODULE, 934 .owner = THIS_MODULE,
935 .ioctl = video_ioctl2, 935 .unlocked_ioctl = video_ioctl2,
936 .read = pms_read, 936 .read = pms_read,
937}; 937};
938 938
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index bef202752cc8..66ad516bdfd9 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -2088,16 +2088,14 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
2088 " Setting up with specified i2c address 0x%x", 2088 " Setting up with specified i2c address 0x%x",
2089 mid, i2caddr[0]); 2089 mid, i2caddr[0]);
2090 sd = v4l2_i2c_new_subdev(&hdw->v4l2_dev, &hdw->i2c_adap, 2090 sd = v4l2_i2c_new_subdev(&hdw->v4l2_dev, &hdw->i2c_adap,
2091 NULL, fname, 2091 fname, i2caddr[0], NULL);
2092 i2caddr[0], NULL);
2093 } else { 2092 } else {
2094 pvr2_trace(PVR2_TRACE_INIT, 2093 pvr2_trace(PVR2_TRACE_INIT,
2095 "Module ID %u:" 2094 "Module ID %u:"
2096 " Setting up with address probe list", 2095 " Setting up with address probe list",
2097 mid); 2096 mid);
2098 sd = v4l2_i2c_new_subdev(&hdw->v4l2_dev, &hdw->i2c_adap, 2097 sd = v4l2_i2c_new_subdev(&hdw->v4l2_dev, &hdw->i2c_adap,
2099 NULL, fname, 2098 fname, 0, i2caddr);
2100 0, i2caddr);
2101 } 2099 }
2102 2100
2103 if (!sd) { 2101 if (!sd) {
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index e62beb4efdb4..f3dc89da4c4e 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -62,7 +62,6 @@
62#include <linux/module.h> 62#include <linux/module.h>
63#include <linux/poll.h> 63#include <linux/poll.h>
64#include <linux/slab.h> 64#include <linux/slab.h>
65#include <linux/smp_lock.h>
66#ifdef CONFIG_USB_PWC_INPUT_EVDEV 65#ifdef CONFIG_USB_PWC_INPUT_EVDEV
67#include <linux/usb/input.h> 66#include <linux/usb/input.h>
68#endif 67#endif
diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c
index f5a46c458717..a845753665c1 100644
--- a/drivers/media/video/s2255drv.c
+++ b/drivers/media/video/s2255drv.c
@@ -49,7 +49,6 @@
49#include <linux/videodev2.h> 49#include <linux/videodev2.h>
50#include <linux/version.h> 50#include <linux/version.h>
51#include <linux/mm.h> 51#include <linux/mm.h>
52#include <linux/smp_lock.h>
53#include <media/videobuf-vmalloc.h> 52#include <media/videobuf-vmalloc.h>
54#include <media/v4l2-common.h> 53#include <media/v4l2-common.h>
55#include <media/v4l2-device.h> 54#include <media/v4l2-device.h>
diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c
index e8f13d3e2df1..1b93207c89e8 100644
--- a/drivers/media/video/s5p-fimc/fimc-capture.c
+++ b/drivers/media/video/s5p-fimc/fimc-capture.c
@@ -44,7 +44,7 @@ static struct v4l2_subdev *fimc_subdev_register(struct fimc_dev *fimc,
44 return ERR_PTR(-ENOMEM); 44 return ERR_PTR(-ENOMEM);
45 45
46 sd = v4l2_i2c_new_subdev_board(&vid_cap->v4l2_dev, i2c_adap, 46 sd = v4l2_i2c_new_subdev_board(&vid_cap->v4l2_dev, i2c_adap,
47 MODULE_NAME, isp_info->board_info, NULL); 47 isp_info->board_info, NULL);
48 if (!sd) { 48 if (!sd) {
49 v4l2_err(&vid_cap->v4l2_dev, "failed to acquire subdev\n"); 49 v4l2_err(&vid_cap->v4l2_dev, "failed to acquire subdev\n");
50 return NULL; 50 return NULL;
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 10a6cbf6a790..1d4d0a49ea52 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -6661,6 +6661,18 @@ struct pci_device_id saa7134_pci_tbl[] = {
6661 .subdevice = 0x2804, 6661 .subdevice = 0x2804,
6662 .driver_data = SAA7134_BOARD_TECHNOTREND_BUDGET_T3000, 6662 .driver_data = SAA7134_BOARD_TECHNOTREND_BUDGET_T3000,
6663 }, { 6663 }, {
6664 .vendor = PCI_VENDOR_ID_PHILIPS,
6665 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
6666 .subvendor = 0x5ace, /* Beholder Intl. Ltd. */
6667 .subdevice = 0x7190,
6668 .driver_data = SAA7134_BOARD_BEHOLD_H7,
6669 }, {
6670 .vendor = PCI_VENDOR_ID_PHILIPS,
6671 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
6672 .subvendor = 0x5ace, /* Beholder Intl. Ltd. */
6673 .subdevice = 0x7090,
6674 .driver_data = SAA7134_BOARD_BEHOLD_A7,
6675 }, {
6664 /* --- boards without eeprom + subsystem ID --- */ 6676 /* --- boards without eeprom + subsystem ID --- */
6665 .vendor = PCI_VENDOR_ID_PHILIPS, 6677 .vendor = PCI_VENDOR_ID_PHILIPS,
6666 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 6678 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -6698,18 +6710,6 @@ struct pci_device_id saa7134_pci_tbl[] = {
6698 .subvendor = PCI_ANY_ID, 6710 .subvendor = PCI_ANY_ID,
6699 .subdevice = PCI_ANY_ID, 6711 .subdevice = PCI_ANY_ID,
6700 .driver_data = SAA7134_BOARD_UNKNOWN, 6712 .driver_data = SAA7134_BOARD_UNKNOWN,
6701 }, {
6702 .vendor = PCI_VENDOR_ID_PHILIPS,
6703 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
6704 .subvendor = 0x5ace, /* Beholder Intl. Ltd. */
6705 .subdevice = 0x7190,
6706 .driver_data = SAA7134_BOARD_BEHOLD_H7,
6707 }, {
6708 .vendor = PCI_VENDOR_ID_PHILIPS,
6709 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
6710 .subvendor = 0x5ace, /* Beholder Intl. Ltd. */
6711 .subdevice = 0x7090,
6712 .driver_data = SAA7134_BOARD_BEHOLD_A7,
6713 },{ 6713 },{
6714 /* --- end of list --- */ 6714 /* --- end of list --- */
6715 } 6715 }
@@ -7551,22 +7551,22 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7551 so we do not need to probe for a radio tuner device. */ 7551 so we do not need to probe for a radio tuner device. */
7552 if (dev->radio_type != UNSET) 7552 if (dev->radio_type != UNSET)
7553 v4l2_i2c_new_subdev(&dev->v4l2_dev, 7553 v4l2_i2c_new_subdev(&dev->v4l2_dev,
7554 &dev->i2c_adap, NULL, "tuner", 7554 &dev->i2c_adap, "tuner",
7555 dev->radio_addr, NULL); 7555 dev->radio_addr, NULL);
7556 if (has_demod) 7556 if (has_demod)
7557 v4l2_i2c_new_subdev(&dev->v4l2_dev, 7557 v4l2_i2c_new_subdev(&dev->v4l2_dev,
7558 &dev->i2c_adap, NULL, "tuner", 7558 &dev->i2c_adap, "tuner",
7559 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); 7559 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
7560 if (dev->tuner_addr == ADDR_UNSET) { 7560 if (dev->tuner_addr == ADDR_UNSET) {
7561 enum v4l2_i2c_tuner_type type = 7561 enum v4l2_i2c_tuner_type type =
7562 has_demod ? ADDRS_TV_WITH_DEMOD : ADDRS_TV; 7562 has_demod ? ADDRS_TV_WITH_DEMOD : ADDRS_TV;
7563 7563
7564 v4l2_i2c_new_subdev(&dev->v4l2_dev, 7564 v4l2_i2c_new_subdev(&dev->v4l2_dev,
7565 &dev->i2c_adap, NULL, "tuner", 7565 &dev->i2c_adap, "tuner",
7566 0, v4l2_i2c_tuner_addrs(type)); 7566 0, v4l2_i2c_tuner_addrs(type));
7567 } else { 7567 } else {
7568 v4l2_i2c_new_subdev(&dev->v4l2_dev, 7568 v4l2_i2c_new_subdev(&dev->v4l2_dev,
7569 &dev->i2c_adap, NULL, "tuner", 7569 &dev->i2c_adap, "tuner",
7570 dev->tuner_addr, NULL); 7570 dev->tuner_addr, NULL);
7571 } 7571 }
7572 } 7572 }
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 764d7d219fed..756a27812260 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -991,7 +991,7 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
991 if (card_is_empress(dev)) { 991 if (card_is_empress(dev)) {
992 struct v4l2_subdev *sd = 992 struct v4l2_subdev *sd =
993 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 993 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
994 NULL, "saa6752hs", 994 "saa6752hs",
995 saa7134_boards[dev->board].empress_addr, NULL); 995 saa7134_boards[dev->board].empress_addr, NULL);
996 996
997 if (sd) 997 if (sd)
@@ -1002,7 +1002,7 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1002 struct v4l2_subdev *sd; 1002 struct v4l2_subdev *sd;
1003 1003
1004 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1004 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1005 &dev->i2c_adap, NULL, "saa6588", 1005 &dev->i2c_adap, "saa6588",
1006 0, I2C_ADDRS(saa7134_boards[dev->board].rds_addr)); 1006 0, I2C_ADDRS(saa7134_boards[dev->board].rds_addr));
1007 if (sd) { 1007 if (sd) {
1008 printk(KERN_INFO "%s: found RDS decoder\n", dev->name); 1008 printk(KERN_INFO "%s: found RDS decoder\n", dev->name);
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index 1467a30a434f..b890aafe7d64 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -21,7 +21,6 @@
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/smp_lock.h>
25#include <linux/delay.h> 24#include <linux/delay.h>
26 25
27#include "saa7134-reg.h" 26#include "saa7134-reg.h"
diff --git a/drivers/media/video/saa7164/saa7164.h b/drivers/media/video/saa7164/saa7164.h
index 1d9c5cbbbc52..041ae8e20f68 100644
--- a/drivers/media/video/saa7164/saa7164.h
+++ b/drivers/media/video/saa7164/saa7164.h
@@ -58,7 +58,6 @@
58#include <media/tveeprom.h> 58#include <media/tveeprom.h>
59#include <media/videobuf-dma-sg.h> 59#include <media/videobuf-dma-sg.h>
60#include <media/videobuf-dvb.h> 60#include <media/videobuf-dvb.h>
61#include <linux/smp_lock.h>
62#include <dvb_demux.h> 61#include <dvb_demux.h>
63#include <dvb_frontend.h> 62#include <dvb_frontend.h>
64#include <dvb_net.h> 63#include <dvb_net.h>
diff --git a/drivers/media/video/se401.c b/drivers/media/video/se401.c
index 41d0166c0f95..41360d7c3e96 100644
--- a/drivers/media/video/se401.c
+++ b/drivers/media/video/se401.c
@@ -31,7 +31,6 @@ static const char version[] = "0.24";
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/vmalloc.h> 32#include <linux/vmalloc.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/smp_lock.h>
35#include <linux/pagemap.h> 34#include <linux/pagemap.h>
36#include <linux/usb.h> 35#include <linux/usb.h>
37#include "se401.h" 36#include "se401.h"
@@ -951,9 +950,9 @@ static int se401_open(struct file *file)
951 struct usb_se401 *se401 = (struct usb_se401 *)dev; 950 struct usb_se401 *se401 = (struct usb_se401 *)dev;
952 int err = 0; 951 int err = 0;
953 952
954 lock_kernel(); 953 mutex_lock(&se401->lock);
955 if (se401->user) { 954 if (se401->user) {
956 unlock_kernel(); 955 mutex_unlock(&se401->lock);
957 return -EBUSY; 956 return -EBUSY;
958 } 957 }
959 se401->fbuf = rvmalloc(se401->maxframesize * SE401_NUMFRAMES); 958 se401->fbuf = rvmalloc(se401->maxframesize * SE401_NUMFRAMES);
@@ -962,7 +961,7 @@ static int se401_open(struct file *file)
962 else 961 else
963 err = -ENOMEM; 962 err = -ENOMEM;
964 se401->user = !err; 963 se401->user = !err;
965 unlock_kernel(); 964 mutex_unlock(&se401->lock);
966 965
967 return err; 966 return err;
968} 967}
diff --git a/drivers/media/video/sh_vou.c b/drivers/media/video/sh_vou.c
index 0f4906136b8f..07cf0c6c7c1f 100644
--- a/drivers/media/video/sh_vou.c
+++ b/drivers/media/video/sh_vou.c
@@ -75,6 +75,7 @@ struct sh_vou_device {
75 int pix_idx; 75 int pix_idx;
76 struct videobuf_buffer *active; 76 struct videobuf_buffer *active;
77 enum sh_vou_status status; 77 enum sh_vou_status status;
78 struct mutex fop_lock;
78}; 79};
79 80
80struct sh_vou_file { 81struct sh_vou_file {
@@ -235,7 +236,7 @@ static void free_buffer(struct videobuf_queue *vq, struct videobuf_buffer *vb)
235 vb->state = VIDEOBUF_NEEDS_INIT; 236 vb->state = VIDEOBUF_NEEDS_INIT;
236} 237}
237 238
238/* Locking: caller holds vq->vb_lock mutex */ 239/* Locking: caller holds fop_lock mutex */
239static int sh_vou_buf_setup(struct videobuf_queue *vq, unsigned int *count, 240static int sh_vou_buf_setup(struct videobuf_queue *vq, unsigned int *count,
240 unsigned int *size) 241 unsigned int *size)
241{ 242{
@@ -257,7 +258,7 @@ static int sh_vou_buf_setup(struct videobuf_queue *vq, unsigned int *count,
257 return 0; 258 return 0;
258} 259}
259 260
260/* Locking: caller holds vq->vb_lock mutex */ 261/* Locking: caller holds fop_lock mutex */
261static int sh_vou_buf_prepare(struct videobuf_queue *vq, 262static int sh_vou_buf_prepare(struct videobuf_queue *vq,
262 struct videobuf_buffer *vb, 263 struct videobuf_buffer *vb,
263 enum v4l2_field field) 264 enum v4l2_field field)
@@ -306,7 +307,7 @@ static int sh_vou_buf_prepare(struct videobuf_queue *vq,
306 return 0; 307 return 0;
307} 308}
308 309
309/* Locking: caller holds vq->vb_lock mutex and vq->irqlock spinlock */ 310/* Locking: caller holds fop_lock mutex and vq->irqlock spinlock */
310static void sh_vou_buf_queue(struct videobuf_queue *vq, 311static void sh_vou_buf_queue(struct videobuf_queue *vq,
311 struct videobuf_buffer *vb) 312 struct videobuf_buffer *vb)
312{ 313{
@@ -1190,7 +1191,7 @@ static int sh_vou_open(struct file *file)
1190 V4L2_BUF_TYPE_VIDEO_OUTPUT, 1191 V4L2_BUF_TYPE_VIDEO_OUTPUT,
1191 V4L2_FIELD_NONE, 1192 V4L2_FIELD_NONE,
1192 sizeof(struct videobuf_buffer), vdev, 1193 sizeof(struct videobuf_buffer), vdev,
1193 NULL); 1194 &vou_dev->fop_lock);
1194 1195
1195 return 0; 1196 return 0;
1196} 1197}
@@ -1292,7 +1293,7 @@ static const struct v4l2_file_operations sh_vou_fops = {
1292 .owner = THIS_MODULE, 1293 .owner = THIS_MODULE,
1293 .open = sh_vou_open, 1294 .open = sh_vou_open,
1294 .release = sh_vou_release, 1295 .release = sh_vou_release,
1295 .ioctl = video_ioctl2, 1296 .unlocked_ioctl = video_ioctl2,
1296 .mmap = sh_vou_mmap, 1297 .mmap = sh_vou_mmap,
1297 .poll = sh_vou_poll, 1298 .poll = sh_vou_poll,
1298}; 1299};
@@ -1331,6 +1332,7 @@ static int __devinit sh_vou_probe(struct platform_device *pdev)
1331 1332
1332 INIT_LIST_HEAD(&vou_dev->queue); 1333 INIT_LIST_HEAD(&vou_dev->queue);
1333 spin_lock_init(&vou_dev->lock); 1334 spin_lock_init(&vou_dev->lock);
1335 mutex_init(&vou_dev->fop_lock);
1334 atomic_set(&vou_dev->use_count, 0); 1336 atomic_set(&vou_dev->use_count, 0);
1335 vou_dev->pdata = vou_pdata; 1337 vou_dev->pdata = vou_pdata;
1336 vou_dev->status = SH_VOU_IDLE; 1338 vou_dev->status = SH_VOU_IDLE;
@@ -1388,6 +1390,7 @@ static int __devinit sh_vou_probe(struct platform_device *pdev)
1388 vdev->tvnorms |= V4L2_STD_PAL; 1390 vdev->tvnorms |= V4L2_STD_PAL;
1389 vdev->v4l2_dev = &vou_dev->v4l2_dev; 1391 vdev->v4l2_dev = &vou_dev->v4l2_dev;
1390 vdev->release = video_device_release; 1392 vdev->release = video_device_release;
1393 vdev->lock = &vou_dev->fop_lock;
1391 1394
1392 vou_dev->vdev = vdev; 1395 vou_dev->vdev = vdev;
1393 video_set_drvdata(vdev, vou_dev); 1396 video_set_drvdata(vdev, vou_dev);
@@ -1406,7 +1409,7 @@ static int __devinit sh_vou_probe(struct platform_device *pdev)
1406 goto ereset; 1409 goto ereset;
1407 1410
1408 subdev = v4l2_i2c_new_subdev_board(&vou_dev->v4l2_dev, i2c_adap, 1411 subdev = v4l2_i2c_new_subdev_board(&vou_dev->v4l2_dev, i2c_adap,
1409 NULL, vou_pdata->board_info, NULL); 1412 vou_pdata->board_info, NULL);
1410 if (!subdev) { 1413 if (!subdev) {
1411 ret = -ENOMEM; 1414 ret = -ENOMEM;
1412 goto ei2cnd; 1415 goto ei2cnd;
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 28e19daadec9..f49fbfb7dc13 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -3238,7 +3238,7 @@ static const struct v4l2_file_operations sn9c102_fops = {
3238 .owner = THIS_MODULE, 3238 .owner = THIS_MODULE,
3239 .open = sn9c102_open, 3239 .open = sn9c102_open,
3240 .release = sn9c102_release, 3240 .release = sn9c102_release,
3241 .ioctl = sn9c102_ioctl, 3241 .unlocked_ioctl = sn9c102_ioctl,
3242 .read = sn9c102_read, 3242 .read = sn9c102_read,
3243 .poll = sn9c102_poll, 3243 .poll = sn9c102_poll,
3244 .mmap = sn9c102_mmap, 3244 .mmap = sn9c102_mmap,
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 43848a751d11..335120c2021b 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -896,7 +896,7 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
896 icl->board_info->platform_data = icd; 896 icl->board_info->platform_data = icd;
897 897
898 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap, 898 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap,
899 NULL, icl->board_info, NULL); 899 icl->board_info, NULL);
900 if (!subdev) 900 if (!subdev)
901 goto ei2cnd; 901 goto ei2cnd;
902 902
diff --git a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c
index f07a0f6b71c4..b5afe5f841ce 100644
--- a/drivers/media/video/stk-webcam.c
+++ b/drivers/media/video/stk-webcam.c
@@ -27,7 +27,6 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/smp_lock.h>
31 30
32#include <linux/usb.h> 31#include <linux/usb.h>
33#include <linux/mm.h> 32#include <linux/mm.h>
@@ -673,14 +672,11 @@ static int v4l_stk_open(struct file *fp)
673 vdev = video_devdata(fp); 672 vdev = video_devdata(fp);
674 dev = vdev_to_camera(vdev); 673 dev = vdev_to_camera(vdev);
675 674
676 lock_kernel();
677 if (dev == NULL || !is_present(dev)) { 675 if (dev == NULL || !is_present(dev)) {
678 unlock_kernel();
679 return -ENXIO; 676 return -ENXIO;
680 } 677 }
681 fp->private_data = dev; 678 fp->private_data = dev;
682 usb_autopm_get_interface(dev->interface); 679 usb_autopm_get_interface(dev->interface);
683 unlock_kernel();
684 680
685 return 0; 681 return 0;
686} 682}
diff --git a/drivers/media/video/tlg2300/pd-main.c b/drivers/media/video/tlg2300/pd-main.c
index 4555f4a5f4c8..c91424c0c135 100644
--- a/drivers/media/video/tlg2300/pd-main.c
+++ b/drivers/media/video/tlg2300/pd-main.c
@@ -36,7 +36,6 @@
36#include <linux/string.h> 36#include <linux/string.h>
37#include <linux/types.h> 37#include <linux/types.h>
38#include <linux/firmware.h> 38#include <linux/firmware.h>
39#include <linux/smp_lock.h>
40 39
41#include "vendorcmds.h" 40#include "vendorcmds.h"
42#include "pd-common.h" 41#include "pd-common.h"
@@ -485,15 +484,11 @@ static void poseidon_disconnect(struct usb_interface *interface)
485 /*unregister v4l2 device */ 484 /*unregister v4l2 device */
486 v4l2_device_unregister(&pd->v4l2_dev); 485 v4l2_device_unregister(&pd->v4l2_dev);
487 486
488 lock_kernel(); 487 pd_dvb_usb_device_exit(pd);
489 { 488 poseidon_fm_exit(pd);
490 pd_dvb_usb_device_exit(pd);
491 poseidon_fm_exit(pd);
492 489
493 poseidon_audio_free(pd); 490 poseidon_audio_free(pd);
494 pd_video_exit(pd); 491 pd_video_exit(pd);
495 }
496 unlock_kernel();
497 492
498 usb_set_intfdata(interface, NULL); 493 usb_set_intfdata(interface, NULL);
499 kref_put(&pd->kref, poseidon_delete); 494 kref_put(&pd->kref, poseidon_delete);
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 5d6fd01f918a..dc17cce2fbb6 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -43,7 +43,6 @@
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44#include <linux/mm.h> 44#include <linux/mm.h>
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/smp_lock.h>
47#include <linux/mutex.h> 46#include <linux/mutex.h>
48#include <linux/firmware.h> 47#include <linux/firmware.h>
49#include <linux/ihex.h> 48#include <linux/ihex.h>
@@ -483,29 +482,28 @@ vicam_open(struct file *file)
483 return -EINVAL; 482 return -EINVAL;
484 } 483 }
485 484
486 /* the videodev_lock held above us protects us from 485 /* cam_lock/open_count protects us from simultaneous opens
487 * simultaneous opens...for now. we probably shouldn't 486 * ... for now. we probably shouldn't rely on this fact forever.
488 * rely on this fact forever.
489 */ 487 */
490 488
491 lock_kernel(); 489 mutex_lock(&cam->cam_lock);
492 if (cam->open_count > 0) { 490 if (cam->open_count > 0) {
493 printk(KERN_INFO 491 printk(KERN_INFO
494 "vicam_open called on already opened camera"); 492 "vicam_open called on already opened camera");
495 unlock_kernel(); 493 mutex_unlock(&cam->cam_lock);
496 return -EBUSY; 494 return -EBUSY;
497 } 495 }
498 496
499 cam->raw_image = kmalloc(VICAM_MAX_READ_SIZE, GFP_KERNEL); 497 cam->raw_image = kmalloc(VICAM_MAX_READ_SIZE, GFP_KERNEL);
500 if (!cam->raw_image) { 498 if (!cam->raw_image) {
501 unlock_kernel(); 499 mutex_unlock(&cam->cam_lock);
502 return -ENOMEM; 500 return -ENOMEM;
503 } 501 }
504 502
505 cam->framebuf = rvmalloc(VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); 503 cam->framebuf = rvmalloc(VICAM_MAX_FRAME_SIZE * VICAM_FRAMES);
506 if (!cam->framebuf) { 504 if (!cam->framebuf) {
507 kfree(cam->raw_image); 505 kfree(cam->raw_image);
508 unlock_kernel(); 506 mutex_unlock(&cam->cam_lock);
509 return -ENOMEM; 507 return -ENOMEM;
510 } 508 }
511 509
@@ -513,10 +511,17 @@ vicam_open(struct file *file)
513 if (!cam->cntrlbuf) { 511 if (!cam->cntrlbuf) {
514 kfree(cam->raw_image); 512 kfree(cam->raw_image);
515 rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); 513 rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES);
516 unlock_kernel(); 514 mutex_unlock(&cam->cam_lock);
517 return -ENOMEM; 515 return -ENOMEM;
518 } 516 }
519 517
518 cam->needsDummyRead = 1;
519 cam->open_count++;
520
521 file->private_data = cam;
522 mutex_unlock(&cam->cam_lock);
523
524
520 // First upload firmware, then turn the camera on 525 // First upload firmware, then turn the camera on
521 526
522 if (!cam->is_initialized) { 527 if (!cam->is_initialized) {
@@ -527,12 +532,6 @@ vicam_open(struct file *file)
527 532
528 set_camera_power(cam, 1); 533 set_camera_power(cam, 1);
529 534
530 cam->needsDummyRead = 1;
531 cam->open_count++;
532
533 file->private_data = cam;
534 unlock_kernel();
535
536 return 0; 535 return 0;
537} 536}
538 537
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index e3bbae26e3ce..81dd53bb5267 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -251,7 +251,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
251 hit-and-miss. */ 251 hit-and-miss. */
252 mdelay(10); 252 mdelay(10);
253 v4l2_i2c_new_subdev(&usbvision->v4l2_dev, 253 v4l2_i2c_new_subdev(&usbvision->v4l2_dev,
254 &usbvision->i2c_adap, NULL, 254 &usbvision->i2c_adap,
255 "saa7115_auto", 0, saa711x_addrs); 255 "saa7115_auto", 0, saa711x_addrs);
256 break; 256 break;
257 } 257 }
@@ -261,14 +261,14 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
261 struct tuner_setup tun_setup; 261 struct tuner_setup tun_setup;
262 262
263 sd = v4l2_i2c_new_subdev(&usbvision->v4l2_dev, 263 sd = v4l2_i2c_new_subdev(&usbvision->v4l2_dev,
264 &usbvision->i2c_adap, NULL, 264 &usbvision->i2c_adap,
265 "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); 265 "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
266 /* depending on whether we found a demod or not, select 266 /* depending on whether we found a demod or not, select
267 the tuner type. */ 267 the tuner type. */
268 type = sd ? ADDRS_TV_WITH_DEMOD : ADDRS_TV; 268 type = sd ? ADDRS_TV_WITH_DEMOD : ADDRS_TV;
269 269
270 sd = v4l2_i2c_new_subdev(&usbvision->v4l2_dev, 270 sd = v4l2_i2c_new_subdev(&usbvision->v4l2_dev,
271 &usbvision->i2c_adap, NULL, 271 &usbvision->i2c_adap,
272 "tuner", 0, v4l2_i2c_tuner_addrs(type)); 272 "tuner", 0, v4l2_i2c_tuner_addrs(type));
273 273
274 if (sd == NULL) 274 if (sd == NULL)
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index db6b828594f5..011c0c386995 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -50,7 +50,6 @@
50#include <linux/list.h> 50#include <linux/list.h>
51#include <linux/timer.h> 51#include <linux/timer.h>
52#include <linux/slab.h> 52#include <linux/slab.h>
53#include <linux/smp_lock.h>
54#include <linux/mm.h> 53#include <linux/mm.h>
55#include <linux/highmem.h> 54#include <linux/highmem.h>
56#include <linux/vmalloc.h> 55#include <linux/vmalloc.h>
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index f169f7736677..59f8a9ad3796 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -785,7 +785,7 @@ static void __uvc_find_control(struct uvc_entity *entity, __u32 v4l2_id,
785 } 785 }
786} 786}
787 787
788struct uvc_control *uvc_find_control(struct uvc_video_chain *chain, 788static struct uvc_control *uvc_find_control(struct uvc_video_chain *chain,
789 __u32 v4l2_id, struct uvc_control_mapping **mapping) 789 __u32 v4l2_id, struct uvc_control_mapping **mapping)
790{ 790{
791 struct uvc_control *ctrl = NULL; 791 struct uvc_control *ctrl = NULL;
@@ -944,6 +944,52 @@ done:
944 return ret; 944 return ret;
945} 945}
946 946
947/*
948 * Mapping V4L2 controls to UVC controls can be straighforward if done well.
949 * Most of the UVC controls exist in V4L2, and can be mapped directly. Some
950 * must be grouped (for instance the Red Balance, Blue Balance and Do White
951 * Balance V4L2 controls use the White Balance Component UVC control) or
952 * otherwise translated. The approach we take here is to use a translation
953 * table for the controls that can be mapped directly, and handle the others
954 * manually.
955 */
956int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
957 struct v4l2_querymenu *query_menu)
958{
959 struct uvc_menu_info *menu_info;
960 struct uvc_control_mapping *mapping;
961 struct uvc_control *ctrl;
962 u32 index = query_menu->index;
963 u32 id = query_menu->id;
964 int ret;
965
966 memset(query_menu, 0, sizeof(*query_menu));
967 query_menu->id = id;
968 query_menu->index = index;
969
970 ret = mutex_lock_interruptible(&chain->ctrl_mutex);
971 if (ret < 0)
972 return -ERESTARTSYS;
973
974 ctrl = uvc_find_control(chain, query_menu->id, &mapping);
975 if (ctrl == NULL || mapping->v4l2_type != V4L2_CTRL_TYPE_MENU) {
976 ret = -EINVAL;
977 goto done;
978 }
979
980 if (query_menu->index >= mapping->menu_count) {
981 ret = -EINVAL;
982 goto done;
983 }
984
985 menu_info = &mapping->menu_info[query_menu->index];
986 strlcpy(query_menu->name, menu_info->name, sizeof query_menu->name);
987
988done:
989 mutex_unlock(&chain->ctrl_mutex);
990 return ret;
991}
992
947 993
948/* -------------------------------------------------------------------------- 994/* --------------------------------------------------------------------------
949 * Control transactions 995 * Control transactions
diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c
index ed6d5449741c..f14581bd707f 100644
--- a/drivers/media/video/uvc/uvc_queue.c
+++ b/drivers/media/video/uvc/uvc_queue.c
@@ -90,6 +90,39 @@ void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
90} 90}
91 91
92/* 92/*
93 * Free the video buffers.
94 *
95 * This function must be called with the queue lock held.
96 */
97static int __uvc_free_buffers(struct uvc_video_queue *queue)
98{
99 unsigned int i;
100
101 for (i = 0; i < queue->count; ++i) {
102 if (queue->buffer[i].vma_use_count != 0)
103 return -EBUSY;
104 }
105
106 if (queue->count) {
107 vfree(queue->mem);
108 queue->count = 0;
109 }
110
111 return 0;
112}
113
114int uvc_free_buffers(struct uvc_video_queue *queue)
115{
116 int ret;
117
118 mutex_lock(&queue->mutex);
119 ret = __uvc_free_buffers(queue);
120 mutex_unlock(&queue->mutex);
121
122 return ret;
123}
124
125/*
93 * Allocate the video buffers. 126 * Allocate the video buffers.
94 * 127 *
95 * Pages are reserved to make sure they will not be swapped, as they will be 128 * Pages are reserved to make sure they will not be swapped, as they will be
@@ -110,7 +143,7 @@ int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers,
110 143
111 mutex_lock(&queue->mutex); 144 mutex_lock(&queue->mutex);
112 145
113 if ((ret = uvc_free_buffers(queue)) < 0) 146 if ((ret = __uvc_free_buffers(queue)) < 0)
114 goto done; 147 goto done;
115 148
116 /* Bail out if no buffers should be allocated. */ 149 /* Bail out if no buffers should be allocated. */
@@ -152,28 +185,6 @@ done:
152} 185}
153 186
154/* 187/*
155 * Free the video buffers.
156 *
157 * This function must be called with the queue lock held.
158 */
159int uvc_free_buffers(struct uvc_video_queue *queue)
160{
161 unsigned int i;
162
163 for (i = 0; i < queue->count; ++i) {
164 if (queue->buffer[i].vma_use_count != 0)
165 return -EBUSY;
166 }
167
168 if (queue->count) {
169 vfree(queue->mem);
170 queue->count = 0;
171 }
172
173 return 0;
174}
175
176/*
177 * Check if buffers have been allocated. 188 * Check if buffers have been allocated.
178 */ 189 */
179int uvc_queue_allocated(struct uvc_video_queue *queue) 190int uvc_queue_allocated(struct uvc_video_queue *queue)
@@ -369,6 +380,82 @@ done:
369} 380}
370 381
371/* 382/*
383 * VMA operations.
384 */
385static void uvc_vm_open(struct vm_area_struct *vma)
386{
387 struct uvc_buffer *buffer = vma->vm_private_data;
388 buffer->vma_use_count++;
389}
390
391static void uvc_vm_close(struct vm_area_struct *vma)
392{
393 struct uvc_buffer *buffer = vma->vm_private_data;
394 buffer->vma_use_count--;
395}
396
397static const struct vm_operations_struct uvc_vm_ops = {
398 .open = uvc_vm_open,
399 .close = uvc_vm_close,
400};
401
402/*
403 * Memory-map a video buffer.
404 *
405 * This function implements video buffers memory mapping and is intended to be
406 * used by the device mmap handler.
407 */
408int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma)
409{
410 struct uvc_buffer *uninitialized_var(buffer);
411 struct page *page;
412 unsigned long addr, start, size;
413 unsigned int i;
414 int ret = 0;
415
416 start = vma->vm_start;
417 size = vma->vm_end - vma->vm_start;
418
419 mutex_lock(&queue->mutex);
420
421 for (i = 0; i < queue->count; ++i) {
422 buffer = &queue->buffer[i];
423 if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
424 break;
425 }
426
427 if (i == queue->count || size != queue->buf_size) {
428 ret = -EINVAL;
429 goto done;
430 }
431
432 /*
433 * VM_IO marks the area as being an mmaped region for I/O to a
434 * device. It also prevents the region from being core dumped.
435 */
436 vma->vm_flags |= VM_IO;
437
438 addr = (unsigned long)queue->mem + buffer->buf.m.offset;
439 while (size > 0) {
440 page = vmalloc_to_page((void *)addr);
441 if ((ret = vm_insert_page(vma, start, page)) < 0)
442 goto done;
443
444 start += PAGE_SIZE;
445 addr += PAGE_SIZE;
446 size -= PAGE_SIZE;
447 }
448
449 vma->vm_ops = &uvc_vm_ops;
450 vma->vm_private_data = buffer;
451 uvc_vm_open(vma);
452
453done:
454 mutex_unlock(&queue->mutex);
455 return ret;
456}
457
458/*
372 * Poll the video queue. 459 * Poll the video queue.
373 * 460 *
374 * This function implements video queue polling and is intended to be used by 461 * This function implements video queue polling and is intended to be used by
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index 6d15de9b5204..8cf61e8a634f 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -101,40 +101,6 @@ done:
101 */ 101 */
102 102
103/* 103/*
104 * Mapping V4L2 controls to UVC controls can be straighforward if done well.
105 * Most of the UVC controls exist in V4L2, and can be mapped directly. Some
106 * must be grouped (for instance the Red Balance, Blue Balance and Do White
107 * Balance V4L2 controls use the White Balance Component UVC control) or
108 * otherwise translated. The approach we take here is to use a translation
109 * table for the controls that can be mapped directly, and handle the others
110 * manually.
111 */
112static int uvc_v4l2_query_menu(struct uvc_video_chain *chain,
113 struct v4l2_querymenu *query_menu)
114{
115 struct uvc_menu_info *menu_info;
116 struct uvc_control_mapping *mapping;
117 struct uvc_control *ctrl;
118 u32 index = query_menu->index;
119 u32 id = query_menu->id;
120
121 ctrl = uvc_find_control(chain, query_menu->id, &mapping);
122 if (ctrl == NULL || mapping->v4l2_type != V4L2_CTRL_TYPE_MENU)
123 return -EINVAL;
124
125 if (query_menu->index >= mapping->menu_count)
126 return -EINVAL;
127
128 memset(query_menu, 0, sizeof(*query_menu));
129 query_menu->id = id;
130 query_menu->index = index;
131
132 menu_info = &mapping->menu_info[query_menu->index];
133 strlcpy(query_menu->name, menu_info->name, sizeof query_menu->name);
134 return 0;
135}
136
137/*
138 * Find the frame interval closest to the requested frame interval for the 104 * Find the frame interval closest to the requested frame interval for the
139 * given frame format and size. This should be done by the device as part of 105 * given frame format and size. This should be done by the device as part of
140 * the Video Probe and Commit negotiation, but some hardware don't implement 106 * the Video Probe and Commit negotiation, but some hardware don't implement
@@ -260,12 +226,14 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,
260 * developers test their webcams with the Linux driver as well as with 226 * developers test their webcams with the Linux driver as well as with
261 * the Windows driver). 227 * the Windows driver).
262 */ 228 */
229 mutex_lock(&stream->mutex);
263 if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS) 230 if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS)
264 probe->dwMaxVideoFrameSize = 231 probe->dwMaxVideoFrameSize =
265 stream->ctrl.dwMaxVideoFrameSize; 232 stream->ctrl.dwMaxVideoFrameSize;
266 233
267 /* Probe the device. */ 234 /* Probe the device. */
268 ret = uvc_probe_video(stream, probe); 235 ret = uvc_probe_video(stream, probe);
236 mutex_unlock(&stream->mutex);
269 if (ret < 0) 237 if (ret < 0)
270 goto done; 238 goto done;
271 239
@@ -289,14 +257,21 @@ done:
289static int uvc_v4l2_get_format(struct uvc_streaming *stream, 257static int uvc_v4l2_get_format(struct uvc_streaming *stream,
290 struct v4l2_format *fmt) 258 struct v4l2_format *fmt)
291{ 259{
292 struct uvc_format *format = stream->cur_format; 260 struct uvc_format *format;
293 struct uvc_frame *frame = stream->cur_frame; 261 struct uvc_frame *frame;
262 int ret = 0;
294 263
295 if (fmt->type != stream->type) 264 if (fmt->type != stream->type)
296 return -EINVAL; 265 return -EINVAL;
297 266
298 if (format == NULL || frame == NULL) 267 mutex_lock(&stream->mutex);
299 return -EINVAL; 268 format = stream->cur_format;
269 frame = stream->cur_frame;
270
271 if (format == NULL || frame == NULL) {
272 ret = -EINVAL;
273 goto done;
274 }
300 275
301 fmt->fmt.pix.pixelformat = format->fcc; 276 fmt->fmt.pix.pixelformat = format->fcc;
302 fmt->fmt.pix.width = frame->wWidth; 277 fmt->fmt.pix.width = frame->wWidth;
@@ -307,7 +282,9 @@ static int uvc_v4l2_get_format(struct uvc_streaming *stream,
307 fmt->fmt.pix.colorspace = format->colorspace; 282 fmt->fmt.pix.colorspace = format->colorspace;
308 fmt->fmt.pix.priv = 0; 283 fmt->fmt.pix.priv = 0;
309 284
310 return 0; 285done:
286 mutex_unlock(&stream->mutex);
287 return ret;
311} 288}
312 289
313static int uvc_v4l2_set_format(struct uvc_streaming *stream, 290static int uvc_v4l2_set_format(struct uvc_streaming *stream,
@@ -321,18 +298,24 @@ static int uvc_v4l2_set_format(struct uvc_streaming *stream,
321 if (fmt->type != stream->type) 298 if (fmt->type != stream->type)
322 return -EINVAL; 299 return -EINVAL;
323 300
324 if (uvc_queue_allocated(&stream->queue))
325 return -EBUSY;
326
327 ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame); 301 ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame);
328 if (ret < 0) 302 if (ret < 0)
329 return ret; 303 return ret;
330 304
305 mutex_lock(&stream->mutex);
306
307 if (uvc_queue_allocated(&stream->queue)) {
308 ret = -EBUSY;
309 goto done;
310 }
311
331 memcpy(&stream->ctrl, &probe, sizeof probe); 312 memcpy(&stream->ctrl, &probe, sizeof probe);
332 stream->cur_format = format; 313 stream->cur_format = format;
333 stream->cur_frame = frame; 314 stream->cur_frame = frame;
334 315
335 return 0; 316done:
317 mutex_unlock(&stream->mutex);
318 return ret;
336} 319}
337 320
338static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream, 321static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
@@ -343,7 +326,10 @@ static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
343 if (parm->type != stream->type) 326 if (parm->type != stream->type)
344 return -EINVAL; 327 return -EINVAL;
345 328
329 mutex_lock(&stream->mutex);
346 numerator = stream->ctrl.dwFrameInterval; 330 numerator = stream->ctrl.dwFrameInterval;
331 mutex_unlock(&stream->mutex);
332
347 denominator = 10000000; 333 denominator = 10000000;
348 uvc_simplify_fraction(&numerator, &denominator, 8, 333); 334 uvc_simplify_fraction(&numerator, &denominator, 8, 333);
349 335
@@ -370,7 +356,6 @@ static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
370static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream, 356static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
371 struct v4l2_streamparm *parm) 357 struct v4l2_streamparm *parm)
372{ 358{
373 struct uvc_frame *frame = stream->cur_frame;
374 struct uvc_streaming_control probe; 359 struct uvc_streaming_control probe;
375 struct v4l2_fract timeperframe; 360 struct v4l2_fract timeperframe;
376 uint32_t interval; 361 uint32_t interval;
@@ -379,28 +364,36 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
379 if (parm->type != stream->type) 364 if (parm->type != stream->type)
380 return -EINVAL; 365 return -EINVAL;
381 366
382 if (uvc_queue_streaming(&stream->queue))
383 return -EBUSY;
384
385 if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 367 if (parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
386 timeperframe = parm->parm.capture.timeperframe; 368 timeperframe = parm->parm.capture.timeperframe;
387 else 369 else
388 timeperframe = parm->parm.output.timeperframe; 370 timeperframe = parm->parm.output.timeperframe;
389 371
390 memcpy(&probe, &stream->ctrl, sizeof probe);
391 interval = uvc_fraction_to_interval(timeperframe.numerator, 372 interval = uvc_fraction_to_interval(timeperframe.numerator,
392 timeperframe.denominator); 373 timeperframe.denominator);
393
394 uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n", 374 uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n",
395 timeperframe.numerator, timeperframe.denominator, interval); 375 timeperframe.numerator, timeperframe.denominator, interval);
396 probe.dwFrameInterval = uvc_try_frame_interval(frame, interval); 376
377 mutex_lock(&stream->mutex);
378
379 if (uvc_queue_streaming(&stream->queue)) {
380 mutex_unlock(&stream->mutex);
381 return -EBUSY;
382 }
383
384 memcpy(&probe, &stream->ctrl, sizeof probe);
385 probe.dwFrameInterval =
386 uvc_try_frame_interval(stream->cur_frame, interval);
397 387
398 /* Probe the device with the new settings. */ 388 /* Probe the device with the new settings. */
399 ret = uvc_probe_video(stream, &probe); 389 ret = uvc_probe_video(stream, &probe);
400 if (ret < 0) 390 if (ret < 0) {
391 mutex_unlock(&stream->mutex);
401 return ret; 392 return ret;
393 }
402 394
403 memcpy(&stream->ctrl, &probe, sizeof probe); 395 memcpy(&stream->ctrl, &probe, sizeof probe);
396 mutex_unlock(&stream->mutex);
404 397
405 /* Return the actual frame period. */ 398 /* Return the actual frame period. */
406 timeperframe.numerator = probe.dwFrameInterval; 399 timeperframe.numerator = probe.dwFrameInterval;
@@ -528,11 +521,9 @@ static int uvc_v4l2_release(struct file *file)
528 if (uvc_has_privileges(handle)) { 521 if (uvc_has_privileges(handle)) {
529 uvc_video_enable(stream, 0); 522 uvc_video_enable(stream, 0);
530 523
531 mutex_lock(&stream->queue.mutex);
532 if (uvc_free_buffers(&stream->queue) < 0) 524 if (uvc_free_buffers(&stream->queue) < 0)
533 uvc_printk(KERN_ERR, "uvc_v4l2_release: Unable to " 525 uvc_printk(KERN_ERR, "uvc_v4l2_release: Unable to "
534 "free buffers.\n"); 526 "free buffers.\n");
535 mutex_unlock(&stream->queue.mutex);
536 } 527 }
537 528
538 /* Release the file handle. */ 529 /* Release the file handle. */
@@ -624,7 +615,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
624 } 615 }
625 616
626 case VIDIOC_QUERYMENU: 617 case VIDIOC_QUERYMENU:
627 return uvc_v4l2_query_menu(chain, arg); 618 return uvc_query_v4l2_menu(chain, arg);
628 619
629 case VIDIOC_G_EXT_CTRLS: 620 case VIDIOC_G_EXT_CTRLS:
630 { 621 {
@@ -905,15 +896,17 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
905 case VIDIOC_CROPCAP: 896 case VIDIOC_CROPCAP:
906 { 897 {
907 struct v4l2_cropcap *ccap = arg; 898 struct v4l2_cropcap *ccap = arg;
908 struct uvc_frame *frame = stream->cur_frame;
909 899
910 if (ccap->type != stream->type) 900 if (ccap->type != stream->type)
911 return -EINVAL; 901 return -EINVAL;
912 902
913 ccap->bounds.left = 0; 903 ccap->bounds.left = 0;
914 ccap->bounds.top = 0; 904 ccap->bounds.top = 0;
915 ccap->bounds.width = frame->wWidth; 905
916 ccap->bounds.height = frame->wHeight; 906 mutex_lock(&stream->mutex);
907 ccap->bounds.width = stream->cur_frame->wWidth;
908 ccap->bounds.height = stream->cur_frame->wHeight;
909 mutex_unlock(&stream->mutex);
917 910
918 ccap->defrect = ccap->bounds; 911 ccap->defrect = ccap->bounds;
919 912
@@ -930,8 +923,6 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
930 case VIDIOC_REQBUFS: 923 case VIDIOC_REQBUFS:
931 { 924 {
932 struct v4l2_requestbuffers *rb = arg; 925 struct v4l2_requestbuffers *rb = arg;
933 unsigned int bufsize =
934 stream->ctrl.dwMaxVideoFrameSize;
935 926
936 if (rb->type != stream->type || 927 if (rb->type != stream->type ||
937 rb->memory != V4L2_MEMORY_MMAP) 928 rb->memory != V4L2_MEMORY_MMAP)
@@ -940,7 +931,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
940 if ((ret = uvc_acquire_privileges(handle)) < 0) 931 if ((ret = uvc_acquire_privileges(handle)) < 0)
941 return ret; 932 return ret;
942 933
943 ret = uvc_alloc_buffers(&stream->queue, rb->count, bufsize); 934 mutex_lock(&stream->mutex);
935 ret = uvc_alloc_buffers(&stream->queue, rb->count,
936 stream->ctrl.dwMaxVideoFrameSize);
937 mutex_unlock(&stream->mutex);
944 if (ret < 0) 938 if (ret < 0)
945 return ret; 939 return ret;
946 940
@@ -988,7 +982,9 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
988 if (!uvc_has_privileges(handle)) 982 if (!uvc_has_privileges(handle))
989 return -EBUSY; 983 return -EBUSY;
990 984
985 mutex_lock(&stream->mutex);
991 ret = uvc_video_enable(stream, 1); 986 ret = uvc_video_enable(stream, 1);
987 mutex_unlock(&stream->mutex);
992 if (ret < 0) 988 if (ret < 0)
993 return ret; 989 return ret;
994 break; 990 break;
@@ -1068,79 +1064,14 @@ static ssize_t uvc_v4l2_read(struct file *file, char __user *data,
1068 return -EINVAL; 1064 return -EINVAL;
1069} 1065}
1070 1066
1071/*
1072 * VMA operations.
1073 */
1074static void uvc_vm_open(struct vm_area_struct *vma)
1075{
1076 struct uvc_buffer *buffer = vma->vm_private_data;
1077 buffer->vma_use_count++;
1078}
1079
1080static void uvc_vm_close(struct vm_area_struct *vma)
1081{
1082 struct uvc_buffer *buffer = vma->vm_private_data;
1083 buffer->vma_use_count--;
1084}
1085
1086static const struct vm_operations_struct uvc_vm_ops = {
1087 .open = uvc_vm_open,
1088 .close = uvc_vm_close,
1089};
1090
1091static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) 1067static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1092{ 1068{
1093 struct uvc_fh *handle = file->private_data; 1069 struct uvc_fh *handle = file->private_data;
1094 struct uvc_streaming *stream = handle->stream; 1070 struct uvc_streaming *stream = handle->stream;
1095 struct uvc_video_queue *queue = &stream->queue;
1096 struct uvc_buffer *uninitialized_var(buffer);
1097 struct page *page;
1098 unsigned long addr, start, size;
1099 unsigned int i;
1100 int ret = 0;
1101 1071
1102 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n"); 1072 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n");
1103 1073
1104 start = vma->vm_start; 1074 return uvc_queue_mmap(&stream->queue, vma);
1105 size = vma->vm_end - vma->vm_start;
1106
1107 mutex_lock(&queue->mutex);
1108
1109 for (i = 0; i < queue->count; ++i) {
1110 buffer = &queue->buffer[i];
1111 if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
1112 break;
1113 }
1114
1115 if (i == queue->count || size != queue->buf_size) {
1116 ret = -EINVAL;
1117 goto done;
1118 }
1119
1120 /*
1121 * VM_IO marks the area as being an mmaped region for I/O to a
1122 * device. It also prevents the region from being core dumped.
1123 */
1124 vma->vm_flags |= VM_IO;
1125
1126 addr = (unsigned long)queue->mem + buffer->buf.m.offset;
1127 while (size > 0) {
1128 page = vmalloc_to_page((void *)addr);
1129 if ((ret = vm_insert_page(vma, start, page)) < 0)
1130 goto done;
1131
1132 start += PAGE_SIZE;
1133 addr += PAGE_SIZE;
1134 size -= PAGE_SIZE;
1135 }
1136
1137 vma->vm_ops = &uvc_vm_ops;
1138 vma->vm_private_data = buffer;
1139 uvc_vm_open(vma);
1140
1141done:
1142 mutex_unlock(&queue->mutex);
1143 return ret;
1144} 1075}
1145 1076
1146static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait) 1077static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
@@ -1157,7 +1088,7 @@ const struct v4l2_file_operations uvc_fops = {
1157 .owner = THIS_MODULE, 1088 .owner = THIS_MODULE,
1158 .open = uvc_v4l2_open, 1089 .open = uvc_v4l2_open,
1159 .release = uvc_v4l2_release, 1090 .release = uvc_v4l2_release,
1160 .ioctl = uvc_v4l2_ioctl, 1091 .unlocked_ioctl = uvc_v4l2_ioctl,
1161 .read = uvc_v4l2_read, 1092 .read = uvc_v4l2_read,
1162 .mmap = uvc_v4l2_mmap, 1093 .mmap = uvc_v4l2_mmap,
1163 .poll = uvc_v4l2_poll, 1094 .poll = uvc_v4l2_poll,
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
index 5555f0102838..5673d673504b 100644
--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -293,8 +293,6 @@ int uvc_probe_video(struct uvc_streaming *stream,
293 unsigned int i; 293 unsigned int i;
294 int ret; 294 int ret;
295 295
296 mutex_lock(&stream->mutex);
297
298 /* Perform probing. The device should adjust the requested values 296 /* Perform probing. The device should adjust the requested values
299 * according to its capabilities. However, some devices, namely the 297 * according to its capabilities. However, some devices, namely the
300 * first generation UVC Logitech webcams, don't implement the Video 298 * first generation UVC Logitech webcams, don't implement the Video
@@ -346,7 +344,6 @@ int uvc_probe_video(struct uvc_streaming *stream,
346 } 344 }
347 345
348done: 346done:
349 mutex_unlock(&stream->mutex);
350 return ret; 347 return ret;
351} 348}
352 349
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
index d97cf6d6a4f9..45f01e7e13d2 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -436,7 +436,9 @@ struct uvc_streaming {
436 struct uvc_streaming_control ctrl; 436 struct uvc_streaming_control ctrl;
437 struct uvc_format *cur_format; 437 struct uvc_format *cur_format;
438 struct uvc_frame *cur_frame; 438 struct uvc_frame *cur_frame;
439 439 /* Protect access to ctrl, cur_format, cur_frame and hardware video
440 * probe control.
441 */
440 struct mutex mutex; 442 struct mutex mutex;
441 443
442 unsigned int frozen : 1; 444 unsigned int frozen : 1;
@@ -574,6 +576,8 @@ extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
574extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); 576extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
575extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, 577extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
576 struct uvc_buffer *buf); 578 struct uvc_buffer *buf);
579extern int uvc_queue_mmap(struct uvc_video_queue *queue,
580 struct vm_area_struct *vma);
577extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, 581extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
578 struct file *file, poll_table *wait); 582 struct file *file, poll_table *wait);
579extern int uvc_queue_allocated(struct uvc_video_queue *queue); 583extern int uvc_queue_allocated(struct uvc_video_queue *queue);
@@ -606,10 +610,10 @@ extern int uvc_status_suspend(struct uvc_device *dev);
606extern int uvc_status_resume(struct uvc_device *dev); 610extern int uvc_status_resume(struct uvc_device *dev);
607 611
608/* Controls */ 612/* Controls */
609extern struct uvc_control *uvc_find_control(struct uvc_video_chain *chain,
610 __u32 v4l2_id, struct uvc_control_mapping **mapping);
611extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, 613extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
612 struct v4l2_queryctrl *v4l2_ctrl); 614 struct v4l2_queryctrl *v4l2_ctrl);
615extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
616 struct v4l2_querymenu *query_menu);
613 617
614extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, 618extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
615 const struct uvc_control_mapping *mapping); 619 const struct uvc_control_mapping *mapping);
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 9294282b5add..b5eb1f3950b1 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -368,18 +368,15 @@ EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
368 368
369/* Load an i2c sub-device. */ 369/* Load an i2c sub-device. */
370struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, 370struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
371 struct i2c_adapter *adapter, const char *module_name, 371 struct i2c_adapter *adapter, struct i2c_board_info *info,
372 struct i2c_board_info *info, const unsigned short *probe_addrs) 372 const unsigned short *probe_addrs)
373{ 373{
374 struct v4l2_subdev *sd = NULL; 374 struct v4l2_subdev *sd = NULL;
375 struct i2c_client *client; 375 struct i2c_client *client;
376 376
377 BUG_ON(!v4l2_dev); 377 BUG_ON(!v4l2_dev);
378 378
379 if (module_name) 379 request_module(I2C_MODULE_PREFIX "%s", info->type);
380 request_module(module_name);
381 else
382 request_module(I2C_MODULE_PREFIX "%s", info->type);
383 380
384 /* Create the i2c client */ 381 /* Create the i2c client */
385 if (info->addr == 0 && probe_addrs) 382 if (info->addr == 0 && probe_addrs)
@@ -432,8 +429,7 @@ error:
432EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_board); 429EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_board);
433 430
434struct v4l2_subdev *v4l2_i2c_new_subdev_cfg(struct v4l2_device *v4l2_dev, 431struct v4l2_subdev *v4l2_i2c_new_subdev_cfg(struct v4l2_device *v4l2_dev,
435 struct i2c_adapter *adapter, 432 struct i2c_adapter *adapter, const char *client_type,
436 const char *module_name, const char *client_type,
437 int irq, void *platform_data, 433 int irq, void *platform_data,
438 u8 addr, const unsigned short *probe_addrs) 434 u8 addr, const unsigned short *probe_addrs)
439{ 435{
@@ -447,8 +443,7 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_cfg(struct v4l2_device *v4l2_dev,
447 info.irq = irq; 443 info.irq = irq;
448 info.platform_data = platform_data; 444 info.platform_data = platform_data;
449 445
450 return v4l2_i2c_new_subdev_board(v4l2_dev, adapter, module_name, 446 return v4l2_i2c_new_subdev_board(v4l2_dev, adapter, &info, probe_addrs);
451 &info, probe_addrs);
452} 447}
453EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_cfg); 448EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_cfg);
454 449
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index 86294ed35c9b..e30e8dfb6205 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -18,7 +18,6 @@
18#include <linux/videodev.h> 18#include <linux/videodev.h>
19#include <linux/videodev2.h> 19#include <linux/videodev2.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/smp_lock.h>
22#include <media/v4l2-ioctl.h> 21#include <media/v4l2-ioctl.h>
23 22
24#ifdef CONFIG_COMPAT 23#ifdef CONFIG_COMPAT
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 0ca7978654b5..359e23290a7e 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -25,7 +25,6 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/kmod.h> 26#include <linux/kmod.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/smp_lock.h>
29#include <asm/uaccess.h> 28#include <asm/uaccess.h>
30#include <asm/system.h> 29#include <asm/system.h>
31 30
@@ -187,12 +186,12 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf,
187 size_t sz, loff_t *off) 186 size_t sz, loff_t *off)
188{ 187{
189 struct video_device *vdev = video_devdata(filp); 188 struct video_device *vdev = video_devdata(filp);
190 int ret = -EIO; 189 int ret = -ENODEV;
191 190
192 if (!vdev->fops->read) 191 if (!vdev->fops->read)
193 return -EINVAL; 192 return -EINVAL;
194 if (vdev->lock) 193 if (vdev->lock && mutex_lock_interruptible(vdev->lock))
195 mutex_lock(vdev->lock); 194 return -ERESTARTSYS;
196 if (video_is_registered(vdev)) 195 if (video_is_registered(vdev))
197 ret = vdev->fops->read(filp, buf, sz, off); 196 ret = vdev->fops->read(filp, buf, sz, off);
198 if (vdev->lock) 197 if (vdev->lock)
@@ -204,12 +203,12 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,
204 size_t sz, loff_t *off) 203 size_t sz, loff_t *off)
205{ 204{
206 struct video_device *vdev = video_devdata(filp); 205 struct video_device *vdev = video_devdata(filp);
207 int ret = -EIO; 206 int ret = -ENODEV;
208 207
209 if (!vdev->fops->write) 208 if (!vdev->fops->write)
210 return -EINVAL; 209 return -EINVAL;
211 if (vdev->lock) 210 if (vdev->lock && mutex_lock_interruptible(vdev->lock))
212 mutex_lock(vdev->lock); 211 return -ERESTARTSYS;
213 if (video_is_registered(vdev)) 212 if (video_is_registered(vdev))
214 ret = vdev->fops->write(filp, buf, sz, off); 213 ret = vdev->fops->write(filp, buf, sz, off);
215 if (vdev->lock) 214 if (vdev->lock)
@@ -220,10 +219,10 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,
220static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll) 219static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
221{ 220{
222 struct video_device *vdev = video_devdata(filp); 221 struct video_device *vdev = video_devdata(filp);
223 int ret = DEFAULT_POLLMASK; 222 int ret = POLLERR | POLLHUP;
224 223
225 if (!vdev->fops->poll) 224 if (!vdev->fops->poll)
226 return ret; 225 return DEFAULT_POLLMASK;
227 if (vdev->lock) 226 if (vdev->lock)
228 mutex_lock(vdev->lock); 227 mutex_lock(vdev->lock);
229 if (video_is_registered(vdev)) 228 if (video_is_registered(vdev))
@@ -239,18 +238,45 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
239 int ret = -ENODEV; 238 int ret = -ENODEV;
240 239
241 if (vdev->fops->unlocked_ioctl) { 240 if (vdev->fops->unlocked_ioctl) {
242 if (vdev->lock) 241 if (vdev->lock && mutex_lock_interruptible(vdev->lock))
243 mutex_lock(vdev->lock); 242 return -ERESTARTSYS;
244 if (video_is_registered(vdev)) 243 if (video_is_registered(vdev))
245 ret = vdev->fops->unlocked_ioctl(filp, cmd, arg); 244 ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
246 if (vdev->lock) 245 if (vdev->lock)
247 mutex_unlock(vdev->lock); 246 mutex_unlock(vdev->lock);
248 } else if (vdev->fops->ioctl) { 247 } else if (vdev->fops->ioctl) {
249 /* TODO: convert all drivers to unlocked_ioctl */ 248 /* This code path is a replacement for the BKL. It is a major
250 lock_kernel(); 249 * hack but it will have to do for those drivers that are not
250 * yet converted to use unlocked_ioctl.
251 *
252 * There are two options: if the driver implements struct
253 * v4l2_device, then the lock defined there is used to
254 * serialize the ioctls. Otherwise the v4l2 core lock defined
255 * below is used. This lock is really bad since it serializes
256 * completely independent devices.
257 *
258 * Both variants suffer from the same problem: if the driver
259 * sleeps, then it blocks all ioctls since the lock is still
260 * held. This is very common for VIDIOC_DQBUF since that
261 * normally waits for a frame to arrive. As a result any other
262 * ioctl calls will proceed very, very slowly since each call
263 * will have to wait for the VIDIOC_QBUF to finish. Things that
264 * should take 0.01s may now take 10-20 seconds.
265 *
266 * The workaround is to *not* take the lock for VIDIOC_DQBUF.
267 * This actually works OK for videobuf-based drivers, since
268 * videobuf will take its own internal lock.
269 */
270 static DEFINE_MUTEX(v4l2_ioctl_mutex);
271 struct mutex *m = vdev->v4l2_dev ?
272 &vdev->v4l2_dev->ioctl_lock : &v4l2_ioctl_mutex;
273
274 if (cmd != VIDIOC_DQBUF && mutex_lock_interruptible(m))
275 return -ERESTARTSYS;
251 if (video_is_registered(vdev)) 276 if (video_is_registered(vdev))
252 ret = vdev->fops->ioctl(filp, cmd, arg); 277 ret = vdev->fops->ioctl(filp, cmd, arg);
253 unlock_kernel(); 278 if (cmd != VIDIOC_DQBUF)
279 mutex_unlock(m);
254 } else 280 } else
255 ret = -ENOTTY; 281 ret = -ENOTTY;
256 282
@@ -264,8 +290,8 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
264 290
265 if (!vdev->fops->mmap) 291 if (!vdev->fops->mmap)
266 return ret; 292 return ret;
267 if (vdev->lock) 293 if (vdev->lock && mutex_lock_interruptible(vdev->lock))
268 mutex_lock(vdev->lock); 294 return -ERESTARTSYS;
269 if (video_is_registered(vdev)) 295 if (video_is_registered(vdev))
270 ret = vdev->fops->mmap(filp, vm); 296 ret = vdev->fops->mmap(filp, vm);
271 if (vdev->lock) 297 if (vdev->lock)
@@ -283,7 +309,7 @@ static int v4l2_open(struct inode *inode, struct file *filp)
283 mutex_lock(&videodev_lock); 309 mutex_lock(&videodev_lock);
284 vdev = video_devdata(filp); 310 vdev = video_devdata(filp);
285 /* return ENODEV if the video device has already been removed. */ 311 /* return ENODEV if the video device has already been removed. */
286 if (vdev == NULL) { 312 if (vdev == NULL || !video_is_registered(vdev)) {
287 mutex_unlock(&videodev_lock); 313 mutex_unlock(&videodev_lock);
288 return -ENODEV; 314 return -ENODEV;
289 } 315 }
@@ -291,8 +317,10 @@ static int v4l2_open(struct inode *inode, struct file *filp)
291 video_get(vdev); 317 video_get(vdev);
292 mutex_unlock(&videodev_lock); 318 mutex_unlock(&videodev_lock);
293 if (vdev->fops->open) { 319 if (vdev->fops->open) {
294 if (vdev->lock) 320 if (vdev->lock && mutex_lock_interruptible(vdev->lock)) {
295 mutex_lock(vdev->lock); 321 ret = -ERESTARTSYS;
322 goto err;
323 }
296 if (video_is_registered(vdev)) 324 if (video_is_registered(vdev))
297 ret = vdev->fops->open(filp); 325 ret = vdev->fops->open(filp);
298 else 326 else
@@ -301,6 +329,7 @@ static int v4l2_open(struct inode *inode, struct file *filp)
301 mutex_unlock(vdev->lock); 329 mutex_unlock(vdev->lock);
302 } 330 }
303 331
332err:
304 /* decrease the refcount in case of an error */ 333 /* decrease the refcount in case of an error */
305 if (ret) 334 if (ret)
306 video_put(vdev); 335 video_put(vdev);
@@ -595,7 +624,12 @@ void video_unregister_device(struct video_device *vdev)
595 if (!vdev || !video_is_registered(vdev)) 624 if (!vdev || !video_is_registered(vdev))
596 return; 625 return;
597 626
627 mutex_lock(&videodev_lock);
628 /* This must be in a critical section to prevent a race with v4l2_open.
629 * Once this bit has been cleared video_get may never be called again.
630 */
598 clear_bit(V4L2_FL_REGISTERED, &vdev->flags); 631 clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
632 mutex_unlock(&videodev_lock);
599 device_unregister(&vdev->dev); 633 device_unregister(&vdev->dev);
600} 634}
601EXPORT_SYMBOL(video_unregister_device); 635EXPORT_SYMBOL(video_unregister_device);
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index 0b08f96b74a5..7fe6f92af480 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -35,6 +35,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
35 35
36 INIT_LIST_HEAD(&v4l2_dev->subdevs); 36 INIT_LIST_HEAD(&v4l2_dev->subdevs);
37 spin_lock_init(&v4l2_dev->lock); 37 spin_lock_init(&v4l2_dev->lock);
38 mutex_init(&v4l2_dev->ioctl_lock);
38 v4l2_dev->dev = dev; 39 v4l2_dev->dev = dev;
39 if (dev == NULL) { 40 if (dev == NULL) {
40 /* If dev == NULL, then name must be filled in by the caller */ 41 /* If dev == NULL, then name must be filled in by the caller */
diff --git a/drivers/media/video/via-camera.c b/drivers/media/video/via-camera.c
index 6f52818d5917..222e72db0445 100644
--- a/drivers/media/video/via-camera.c
+++ b/drivers/media/video/via-camera.c
@@ -1358,7 +1358,7 @@ static __devinit int viacam_probe(struct platform_device *pdev)
1358 */ 1358 */
1359 sensor_adapter = viafb_find_i2c_adapter(VIA_PORT_31); 1359 sensor_adapter = viafb_find_i2c_adapter(VIA_PORT_31);
1360 cam->sensor = v4l2_i2c_new_subdev(&cam->v4l2_dev, sensor_adapter, 1360 cam->sensor = v4l2_i2c_new_subdev(&cam->v4l2_dev, sensor_adapter,
1361 "ov7670", "ov7670", 0x42 >> 1, NULL); 1361 "ov7670", 0x42 >> 1, NULL);
1362 if (cam->sensor == NULL) { 1362 if (cam->sensor == NULL) {
1363 dev_err(&pdev->dev, "Unable to find the sensor!\n"); 1363 dev_err(&pdev->dev, "Unable to find the sensor!\n");
1364 ret = -ENODEV; 1364 ret = -ENODEV;
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index e5e005dc1554..7e7eec48f8b1 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -4334,10 +4334,10 @@ static int __init vino_module_init(void)
4334 4334
4335 vino_drvdata->decoder = 4335 vino_drvdata->decoder =
4336 v4l2_i2c_new_subdev(&vino_drvdata->v4l2_dev, &vino_i2c_adapter, 4336 v4l2_i2c_new_subdev(&vino_drvdata->v4l2_dev, &vino_i2c_adapter,
4337 NULL, "saa7191", 0, I2C_ADDRS(0x45)); 4337 "saa7191", 0, I2C_ADDRS(0x45));
4338 vino_drvdata->camera = 4338 vino_drvdata->camera =
4339 v4l2_i2c_new_subdev(&vino_drvdata->v4l2_dev, &vino_i2c_adapter, 4339 v4l2_i2c_new_subdev(&vino_drvdata->v4l2_dev, &vino_i2c_adapter,
4340 NULL, "indycam", 0, I2C_ADDRS(0x2b)); 4340 "indycam", 0, I2C_ADDRS(0x2b));
4341 4341
4342 dprintk("init complete!\n"); 4342 dprintk("init complete!\n");
4343 4343
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index 635420d8d84a..019ee206cbee 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -815,7 +815,7 @@ out:
815 815
816static const struct v4l2_file_operations w9966_fops = { 816static const struct v4l2_file_operations w9966_fops = {
817 .owner = THIS_MODULE, 817 .owner = THIS_MODULE,
818 .ioctl = video_ioctl2, 818 .unlocked_ioctl = video_ioctl2,
819 .read = w9966_v4l_read, 819 .read = w9966_v4l_read,
820}; 820};
821 821
diff --git a/drivers/media/video/zoran/zoran.h b/drivers/media/video/zoran/zoran.h
index 1f04438695dd..b336259ce20c 100644
--- a/drivers/media/video/zoran/zoran.h
+++ b/drivers/media/video/zoran/zoran.h
@@ -388,6 +388,7 @@ struct zoran {
388 struct videocodec *vfe; /* video front end */ 388 struct videocodec *vfe; /* video front end */
389 389
390 struct mutex resource_lock; /* prevent evil stuff */ 390 struct mutex resource_lock; /* prevent evil stuff */
391 struct mutex other_lock; /* please merge with above */
391 392
392 u8 initialized; /* flag if zoran has been correctly initialized */ 393 u8 initialized; /* flag if zoran has been correctly initialized */
393 int user; /* number of current users */ 394 int user; /* number of current users */
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c
index 0aac376c3f7a..e520abf9f4c3 100644
--- a/drivers/media/video/zoran/zoran_card.c
+++ b/drivers/media/video/zoran/zoran_card.c
@@ -1227,6 +1227,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1227 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); 1227 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
1228 spin_lock_init(&zr->spinlock); 1228 spin_lock_init(&zr->spinlock);
1229 mutex_init(&zr->resource_lock); 1229 mutex_init(&zr->resource_lock);
1230 mutex_init(&zr->other_lock);
1230 if (pci_enable_device(pdev)) 1231 if (pci_enable_device(pdev))
1231 goto zr_unreg; 1232 goto zr_unreg;
1232 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision); 1233 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision);
@@ -1342,13 +1343,12 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1342 } 1343 }
1343 1344
1344 zr->decoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, 1345 zr->decoder = v4l2_i2c_new_subdev(&zr->v4l2_dev,
1345 &zr->i2c_adapter, NULL, zr->card.i2c_decoder, 1346 &zr->i2c_adapter, zr->card.i2c_decoder,
1346 0, zr->card.addrs_decoder); 1347 0, zr->card.addrs_decoder);
1347 1348
1348 if (zr->card.i2c_encoder) 1349 if (zr->card.i2c_encoder)
1349 zr->encoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, 1350 zr->encoder = v4l2_i2c_new_subdev(&zr->v4l2_dev,
1350 &zr->i2c_adapter, 1351 &zr->i2c_adapter, zr->card.i2c_encoder,
1351 NULL, zr->card.i2c_encoder,
1352 0, zr->card.addrs_encoder); 1352 0, zr->card.addrs_encoder);
1353 1353
1354 dprintk(2, 1354 dprintk(2,
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index 401082b853f0..67a52e844ae6 100644
--- a/drivers/media/video/zoran/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -49,7 +49,6 @@
49#include <linux/module.h> 49#include <linux/module.h>
50#include <linux/delay.h> 50#include <linux/delay.h>
51#include <linux/slab.h> 51#include <linux/slab.h>
52#include <linux/smp_lock.h>
53#include <linux/pci.h> 52#include <linux/pci.h>
54#include <linux/vmalloc.h> 53#include <linux/vmalloc.h>
55#include <linux/wait.h> 54#include <linux/wait.h>
@@ -913,7 +912,7 @@ static int zoran_open(struct file *file)
913 dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(-)=%d\n", 912 dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(-)=%d\n",
914 ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user + 1); 913 ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user + 1);
915 914
916 lock_kernel(); 915 mutex_lock(&zr->other_lock);
917 916
918 if (zr->user >= 2048) { 917 if (zr->user >= 2048) {
919 dprintk(1, KERN_ERR "%s: too many users (%d) on device\n", 918 dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
@@ -963,14 +962,14 @@ static int zoran_open(struct file *file)
963 file->private_data = fh; 962 file->private_data = fh;
964 fh->zr = zr; 963 fh->zr = zr;
965 zoran_open_init_session(fh); 964 zoran_open_init_session(fh);
966 unlock_kernel(); 965 mutex_unlock(&zr->other_lock);
967 966
968 return 0; 967 return 0;
969 968
970fail_fh: 969fail_fh:
971 kfree(fh); 970 kfree(fh);
972fail_unlock: 971fail_unlock:
973 unlock_kernel(); 972 mutex_unlock(&zr->other_lock);
974 973
975 dprintk(2, KERN_INFO "%s: open failed (%d), users(-)=%d\n", 974 dprintk(2, KERN_INFO "%s: open failed (%d), users(-)=%d\n",
976 ZR_DEVNAME(zr), res, zr->user); 975 ZR_DEVNAME(zr), res, zr->user);
@@ -989,7 +988,7 @@ zoran_close(struct file *file)
989 988
990 /* kernel locks (fs/device.c), so don't do that ourselves 989 /* kernel locks (fs/device.c), so don't do that ourselves
991 * (prevents deadlocks) */ 990 * (prevents deadlocks) */
992 /*mutex_lock(&zr->resource_lock);*/ 991 mutex_lock(&zr->other_lock);
993 992
994 zoran_close_end_session(fh); 993 zoran_close_end_session(fh);
995 994
@@ -1023,6 +1022,7 @@ zoran_close(struct file *file)
1023 encoder_call(zr, video, s_routing, 2, 0, 0); 1022 encoder_call(zr, video, s_routing, 2, 0, 0);
1024 } 1023 }
1025 } 1024 }
1025 mutex_unlock(&zr->other_lock);
1026 1026
1027 file->private_data = NULL; 1027 file->private_data = NULL;
1028 kfree(fh->overlay_mask); 1028 kfree(fh->overlay_mask);
@@ -3370,11 +3370,26 @@ static const struct v4l2_ioctl_ops zoran_ioctl_ops = {
3370#endif 3370#endif
3371}; 3371};
3372 3372
3373/* please use zr->resource_lock consistently and kill this wrapper */
3374static long zoran_ioctl(struct file *file, unsigned int cmd,
3375 unsigned long arg)
3376{
3377 struct zoran_fh *fh = file->private_data;
3378 struct zoran *zr = fh->zr;
3379 int ret;
3380
3381 mutex_lock(&zr->other_lock);
3382 ret = video_ioctl2(file, cmd, arg);
3383 mutex_unlock(&zr->other_lock);
3384
3385 return ret;
3386}
3387
3373static const struct v4l2_file_operations zoran_fops = { 3388static const struct v4l2_file_operations zoran_fops = {
3374 .owner = THIS_MODULE, 3389 .owner = THIS_MODULE,
3375 .open = zoran_open, 3390 .open = zoran_open,
3376 .release = zoran_close, 3391 .release = zoran_close,
3377 .ioctl = video_ioctl2, 3392 .unlocked_ioctl = zoran_ioctl,
3378 .read = zoran_read, 3393 .read = zoran_read,
3379 .write = zoran_write, 3394 .write = zoran_write,
3380 .mmap = zoran_mmap, 3395 .mmap = zoran_mmap,
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index e15220ff52fc..d784c36707c0 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -97,8 +97,7 @@ static u8 mptfcInternalCtx = MPT_MAX_PROTOCOL_DRIVERS;
97 97
98static int mptfc_target_alloc(struct scsi_target *starget); 98static int mptfc_target_alloc(struct scsi_target *starget);
99static int mptfc_slave_alloc(struct scsi_device *sdev); 99static int mptfc_slave_alloc(struct scsi_device *sdev);
100static int mptfc_qcmd(struct scsi_cmnd *SCpnt, 100static int mptfc_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt);
101 void (*done)(struct scsi_cmnd *));
102static void mptfc_target_destroy(struct scsi_target *starget); 101static void mptfc_target_destroy(struct scsi_target *starget);
103static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout); 102static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
104static void __devexit mptfc_remove(struct pci_dev *pdev); 103static void __devexit mptfc_remove(struct pci_dev *pdev);
@@ -650,7 +649,7 @@ mptfc_slave_alloc(struct scsi_device *sdev)
650} 649}
651 650
652static int 651static int
653mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 652mptfc_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
654{ 653{
655 struct mptfc_rport_info *ri; 654 struct mptfc_rport_info *ri;
656 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device)); 655 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
@@ -681,6 +680,8 @@ mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
681 return mptscsih_qcmd(SCpnt,done); 680 return mptscsih_qcmd(SCpnt,done);
682} 681}
683 682
683static DEF_SCSI_QCMD(mptfc_qcmd)
684
684/* 685/*
685 * mptfc_display_port_link_speed - displaying link speed 686 * mptfc_display_port_link_speed - displaying link speed
686 * @ioc: Pointer to MPT_ADAPTER structure 687 * @ioc: Pointer to MPT_ADAPTER structure
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 5651f77a8cc1..8aefb1829fcd 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -1889,7 +1889,7 @@ mptsas_slave_alloc(struct scsi_device *sdev)
1889} 1889}
1890 1890
1891static int 1891static int
1892mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 1892mptsas_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1893{ 1893{
1894 MPT_SCSI_HOST *hd; 1894 MPT_SCSI_HOST *hd;
1895 MPT_ADAPTER *ioc; 1895 MPT_ADAPTER *ioc;
@@ -1913,6 +1913,8 @@ mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1913 return mptscsih_qcmd(SCpnt,done); 1913 return mptscsih_qcmd(SCpnt,done);
1914} 1914}
1915 1915
1916static DEF_SCSI_QCMD(mptsas_qcmd)
1917
1916/** 1918/**
1917 * mptsas_mptsas_eh_timed_out - resets the scsi_cmnd timeout 1919 * mptsas_mptsas_eh_timed_out - resets the scsi_cmnd timeout
1918 * if the device under question is currently in the 1920 * if the device under question is currently in the
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index 0e2803155ae2..6d9568d2ec59 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -780,7 +780,7 @@ static int mptspi_slave_configure(struct scsi_device *sdev)
780} 780}
781 781
782static int 782static int
783mptspi_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 783mptspi_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
784{ 784{
785 struct _MPT_SCSI_HOST *hd = shost_priv(SCpnt->device->host); 785 struct _MPT_SCSI_HOST *hd = shost_priv(SCpnt->device->host);
786 VirtDevice *vdevice = SCpnt->device->hostdata; 786 VirtDevice *vdevice = SCpnt->device->hostdata;
@@ -805,6 +805,8 @@ mptspi_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
805 return mptscsih_qcmd(SCpnt,done); 805 return mptscsih_qcmd(SCpnt,done);
806} 806}
807 807
808static DEF_SCSI_QCMD(mptspi_qcmd)
809
808static void mptspi_slave_destroy(struct scsi_device *sdev) 810static void mptspi_slave_destroy(struct scsi_device *sdev)
809{ 811{
810 struct scsi_target *starget = scsi_target(sdev); 812 struct scsi_target *starget = scsi_target(sdev);
diff --git a/drivers/message/i2o/i2o_scsi.c b/drivers/message/i2o/i2o_scsi.c
index ea6b2197da8a..97bdf82ec905 100644
--- a/drivers/message/i2o/i2o_scsi.c
+++ b/drivers/message/i2o/i2o_scsi.c
@@ -506,7 +506,7 @@ static struct i2o_driver i2o_scsi_driver = {
506 * Locks: takes the controller lock on error path only 506 * Locks: takes the controller lock on error path only
507 */ 507 */
508 508
509static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt, 509static int i2o_scsi_queuecommand_lck(struct scsi_cmnd *SCpnt,
510 void (*done) (struct scsi_cmnd *)) 510 void (*done) (struct scsi_cmnd *))
511{ 511{
512 struct i2o_controller *c; 512 struct i2o_controller *c;
@@ -688,7 +688,9 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
688 688
689 exit: 689 exit:
690 return rc; 690 return rc;
691}; 691}
692
693static DEF_SCSI_QCMD(i2o_scsi_queuecommand)
692 694
693/** 695/**
694 * i2o_scsi_abort - abort a running command 696 * i2o_scsi_abort - abort a running command
diff --git a/drivers/misc/apds9802als.c b/drivers/misc/apds9802als.c
index f9b91ba8900c..644d4cd071cc 100644
--- a/drivers/misc/apds9802als.c
+++ b/drivers/misc/apds9802als.c
@@ -123,7 +123,7 @@ static ssize_t als_sensing_range_store(struct device *dev,
123{ 123{
124 struct i2c_client *client = to_i2c_client(dev); 124 struct i2c_client *client = to_i2c_client(dev);
125 struct als_data *data = i2c_get_clientdata(client); 125 struct als_data *data = i2c_get_clientdata(client);
126 unsigned int ret_val; 126 int ret_val;
127 unsigned long val; 127 unsigned long val;
128 128
129 if (strict_strtoul(buf, 10, &val)) 129 if (strict_strtoul(buf, 10, &val))
@@ -251,7 +251,6 @@ static int apds9802als_probe(struct i2c_client *client,
251 251
252 return res; 252 return res;
253als_error1: 253als_error1:
254 i2c_set_clientdata(client, NULL);
255 kfree(data); 254 kfree(data);
256 return res; 255 return res;
257} 256}
diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c
index cee632e645e1..d79a972f2c79 100644
--- a/drivers/misc/bh1770glc.c
+++ b/drivers/misc/bh1770glc.c
@@ -649,7 +649,7 @@ static ssize_t bh1770_power_state_store(struct device *dev,
649{ 649{
650 struct bh1770_chip *chip = dev_get_drvdata(dev); 650 struct bh1770_chip *chip = dev_get_drvdata(dev);
651 unsigned long value; 651 unsigned long value;
652 size_t ret; 652 ssize_t ret;
653 653
654 if (strict_strtoul(buf, 0, &value)) 654 if (strict_strtoul(buf, 0, &value))
655 return -EINVAL; 655 return -EINVAL;
@@ -659,8 +659,12 @@ static ssize_t bh1770_power_state_store(struct device *dev,
659 pm_runtime_get_sync(dev); 659 pm_runtime_get_sync(dev);
660 660
661 ret = bh1770_lux_rate(chip, chip->lux_rate_index); 661 ret = bh1770_lux_rate(chip, chip->lux_rate_index);
662 ret |= bh1770_lux_interrupt_control(chip, BH1770_ENABLE); 662 if (ret < 0) {
663 pm_runtime_put(dev);
664 goto leave;
665 }
663 666
667 ret = bh1770_lux_interrupt_control(chip, BH1770_ENABLE);
664 if (ret < 0) { 668 if (ret < 0) {
665 pm_runtime_put(dev); 669 pm_runtime_put(dev);
666 goto leave; 670 goto leave;
diff --git a/drivers/misc/isl29020.c b/drivers/misc/isl29020.c
index 34fe835921c4..307aada5fffe 100644
--- a/drivers/misc/isl29020.c
+++ b/drivers/misc/isl29020.c
@@ -87,7 +87,7 @@ static ssize_t als_sensing_range_store(struct device *dev,
87 struct device_attribute *attr, const char *buf, size_t count) 87 struct device_attribute *attr, const char *buf, size_t count)
88{ 88{
89 struct i2c_client *client = to_i2c_client(dev); 89 struct i2c_client *client = to_i2c_client(dev);
90 unsigned int ret_val; 90 int ret_val;
91 unsigned long val; 91 unsigned long val;
92 92
93 if (strict_strtoul(buf, 10, &val)) 93 if (strict_strtoul(buf, 10, &val))
@@ -106,6 +106,8 @@ static ssize_t als_sensing_range_store(struct device *dev,
106 val = 4; 106 val = 4;
107 107
108 ret_val = i2c_smbus_read_byte_data(client, 0x00); 108 ret_val = i2c_smbus_read_byte_data(client, 0x00);
109 if (ret_val < 0)
110 return ret_val;
109 111
110 ret_val &= 0xFC; /*reset the bit before setting them */ 112 ret_val &= 0xFC; /*reset the bit before setting them */
111 ret_val |= val - 1; 113 ret_val |= val - 1;
@@ -181,9 +183,7 @@ static int isl29020_probe(struct i2c_client *client,
181 183
182static int isl29020_remove(struct i2c_client *client) 184static int isl29020_remove(struct i2c_client *client)
183{ 185{
184 struct als_data *data = i2c_get_clientdata(client);
185 sysfs_remove_group(&client->dev.kobj, &m_als_gr); 186 sysfs_remove_group(&client->dev.kobj, &m_als_gr);
186 kfree(data);
187 return 0; 187 return 0;
188} 188}
189 189
@@ -243,6 +243,6 @@ static void __exit sensor_isl29020_exit(void)
243module_init(sensor_isl29020_init); 243module_init(sensor_isl29020_init);
244module_exit(sensor_isl29020_exit); 244module_exit(sensor_isl29020_exit);
245 245
246MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal@intel.com"); 246MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal@intel.com>");
247MODULE_DESCRIPTION("Intersil isl29020 ALS Driver"); 247MODULE_DESCRIPTION("Intersil isl29020 ALS Driver");
248MODULE_LICENSE("GPL v2"); 248MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/sgi-xp/xpc_partition.c b/drivers/misc/sgi-xp/xpc_partition.c
index d551f09ccb79..6956f7e7d439 100644
--- a/drivers/misc/sgi-xp/xpc_partition.c
+++ b/drivers/misc/sgi-xp/xpc_partition.c
@@ -439,18 +439,23 @@ xpc_discovery(void)
439 * nodes that can comprise an access protection grouping. The access 439 * nodes that can comprise an access protection grouping. The access
440 * protection is in regards to memory, IOI and IPI. 440 * protection is in regards to memory, IOI and IPI.
441 */ 441 */
442 max_regions = 64;
443 region_size = xp_region_size; 442 region_size = xp_region_size;
444 443
445 switch (region_size) { 444 if (is_uv())
446 case 128: 445 max_regions = 256;
447 max_regions *= 2; 446 else {
448 case 64: 447 max_regions = 64;
449 max_regions *= 2; 448
450 case 32: 449 switch (region_size) {
451 max_regions *= 2; 450 case 128:
452 region_size = 16; 451 max_regions *= 2;
453 DBUG_ON(!is_shub2()); 452 case 64:
453 max_regions *= 2;
454 case 32:
455 max_regions *= 2;
456 region_size = 16;
457 DBUG_ON(!is_shub2());
458 }
454 } 459 }
455 460
456 for (region = 0; region < max_regions; region++) { 461 for (region = 0; region < max_regions; region++) {
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 8f86d702e46e..31ae07a36576 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1559,7 +1559,7 @@ void mmc_stop_host(struct mmc_host *host)
1559 1559
1560 if (host->caps & MMC_CAP_DISABLE) 1560 if (host->caps & MMC_CAP_DISABLE)
1561 cancel_delayed_work(&host->disable); 1561 cancel_delayed_work(&host->disable);
1562 cancel_delayed_work(&host->detect); 1562 cancel_delayed_work_sync(&host->detect);
1563 mmc_flush_scheduled_work(); 1563 mmc_flush_scheduled_work();
1564 1564
1565 /* clear pm flags now and let card drivers set them as needed */ 1565 /* clear pm flags now and let card drivers set them as needed */
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 995261f7fd70..77f93c3b8808 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -375,7 +375,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
375 struct mmc_card *oldcard) 375 struct mmc_card *oldcard)
376{ 376{
377 struct mmc_card *card; 377 struct mmc_card *card;
378 int err, ddr = MMC_SDR_MODE; 378 int err, ddr = 0;
379 u32 cid[4]; 379 u32 cid[4];
380 unsigned int max_dtr; 380 unsigned int max_dtr;
381 381
@@ -562,7 +562,11 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
562 1 << bus_width, ddr); 562 1 << bus_width, ddr);
563 err = 0; 563 err = 0;
564 } else { 564 } else {
565 mmc_card_set_ddr_mode(card); 565 if (ddr)
566 mmc_card_set_ddr_mode(card);
567 else
568 ddr = MMC_SDR_MODE;
569
566 mmc_set_bus_width_ddr(card->host, bus_width, ddr); 570 mmc_set_bus_width_ddr(card->host, bus_width, ddr);
567 } 571 }
568 } 572 }
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index c3ad1058cd31..efef5f94ac42 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -547,9 +547,11 @@ static void mmc_sdio_detect(struct mmc_host *host)
547 BUG_ON(!host->card); 547 BUG_ON(!host->card);
548 548
549 /* Make sure card is powered before detecting it */ 549 /* Make sure card is powered before detecting it */
550 err = pm_runtime_get_sync(&host->card->dev); 550 if (host->caps & MMC_CAP_POWER_OFF_CARD) {
551 if (err < 0) 551 err = pm_runtime_get_sync(&host->card->dev);
552 goto out; 552 if (err < 0)
553 goto out;
554 }
553 555
554 mmc_claim_host(host); 556 mmc_claim_host(host);
555 557
@@ -560,6 +562,20 @@ static void mmc_sdio_detect(struct mmc_host *host)
560 562
561 mmc_release_host(host); 563 mmc_release_host(host);
562 564
565 /*
566 * Tell PM core it's OK to power off the card now.
567 *
568 * The _sync variant is used in order to ensure that the card
569 * is left powered off in case an error occurred, and the card
570 * is going to be removed.
571 *
572 * Since there is no specific reason to believe a new user
573 * is about to show up at this point, the _sync variant is
574 * desirable anyway.
575 */
576 if (host->caps & MMC_CAP_POWER_OFF_CARD)
577 pm_runtime_put_sync(&host->card->dev);
578
563out: 579out:
564 if (err) { 580 if (err) {
565 mmc_sdio_remove(host); 581 mmc_sdio_remove(host);
@@ -568,9 +584,6 @@ out:
568 mmc_detach_bus(host); 584 mmc_detach_bus(host);
569 mmc_release_host(host); 585 mmc_release_host(host);
570 } 586 }
571
572 /* Tell PM core that we're done */
573 pm_runtime_put(&host->card->dev);
574} 587}
575 588
576/* 589/*
@@ -718,16 +731,21 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
718 card = host->card; 731 card = host->card;
719 732
720 /* 733 /*
721 * Let runtime PM core know our card is active 734 * Enable runtime PM only if supported by host+card+board
722 */ 735 */
723 err = pm_runtime_set_active(&card->dev); 736 if (host->caps & MMC_CAP_POWER_OFF_CARD) {
724 if (err) 737 /*
725 goto remove; 738 * Let runtime PM core know our card is active
739 */
740 err = pm_runtime_set_active(&card->dev);
741 if (err)
742 goto remove;
726 743
727 /* 744 /*
728 * Enable runtime PM for this card 745 * Enable runtime PM for this card
729 */ 746 */
730 pm_runtime_enable(&card->dev); 747 pm_runtime_enable(&card->dev);
748 }
731 749
732 /* 750 /*
733 * The number of functions on the card is encoded inside 751 * The number of functions on the card is encoded inside
@@ -745,9 +763,10 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
745 goto remove; 763 goto remove;
746 764
747 /* 765 /*
748 * Enable Runtime PM for this func 766 * Enable Runtime PM for this func (if supported)
749 */ 767 */
750 pm_runtime_enable(&card->sdio_func[i]->dev); 768 if (host->caps & MMC_CAP_POWER_OFF_CARD)
769 pm_runtime_enable(&card->sdio_func[i]->dev);
751 } 770 }
752 771
753 mmc_release_host(host); 772 mmc_release_host(host);
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 2716c7ab6bbf..203da443e339 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -17,6 +17,7 @@
17#include <linux/pm_runtime.h> 17#include <linux/pm_runtime.h>
18 18
19#include <linux/mmc/card.h> 19#include <linux/mmc/card.h>
20#include <linux/mmc/host.h>
20#include <linux/mmc/sdio_func.h> 21#include <linux/mmc/sdio_func.h>
21 22
22#include "sdio_cis.h" 23#include "sdio_cis.h"
@@ -132,9 +133,11 @@ static int sdio_bus_probe(struct device *dev)
132 * it should call pm_runtime_put_noidle() in its probe routine and 133 * it should call pm_runtime_put_noidle() in its probe routine and
133 * pm_runtime_get_noresume() in its remove routine. 134 * pm_runtime_get_noresume() in its remove routine.
134 */ 135 */
135 ret = pm_runtime_get_sync(dev); 136 if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD) {
136 if (ret < 0) 137 ret = pm_runtime_get_sync(dev);
137 goto out; 138 if (ret < 0)
139 goto out;
140 }
138 141
139 /* Set the default block size so the driver is sure it's something 142 /* Set the default block size so the driver is sure it's something
140 * sensible. */ 143 * sensible. */
@@ -151,7 +154,8 @@ static int sdio_bus_probe(struct device *dev)
151 return 0; 154 return 0;
152 155
153disable_runtimepm: 156disable_runtimepm:
154 pm_runtime_put_noidle(dev); 157 if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD)
158 pm_runtime_put_noidle(dev);
155out: 159out:
156 return ret; 160 return ret;
157} 161}
@@ -160,12 +164,14 @@ static int sdio_bus_remove(struct device *dev)
160{ 164{
161 struct sdio_driver *drv = to_sdio_driver(dev->driver); 165 struct sdio_driver *drv = to_sdio_driver(dev->driver);
162 struct sdio_func *func = dev_to_sdio_func(dev); 166 struct sdio_func *func = dev_to_sdio_func(dev);
163 int ret; 167 int ret = 0;
164 168
165 /* Make sure card is powered before invoking ->remove() */ 169 /* Make sure card is powered before invoking ->remove() */
166 ret = pm_runtime_get_sync(dev); 170 if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD) {
167 if (ret < 0) 171 ret = pm_runtime_get_sync(dev);
168 goto out; 172 if (ret < 0)
173 goto out;
174 }
169 175
170 drv->remove(func); 176 drv->remove(func);
171 177
@@ -178,10 +184,12 @@ static int sdio_bus_remove(struct device *dev)
178 } 184 }
179 185
180 /* First, undo the increment made directly above */ 186 /* First, undo the increment made directly above */
181 pm_runtime_put_noidle(dev); 187 if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD)
188 pm_runtime_put_noidle(dev);
182 189
183 /* Then undo the runtime PM settings in sdio_bus_probe() */ 190 /* Then undo the runtime PM settings in sdio_bus_probe() */
184 pm_runtime_put_noidle(dev); 191 if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD)
192 pm_runtime_put_noidle(dev);
185 193
186out: 194out:
187 return ret; 195 return ret;
@@ -191,6 +199,8 @@ out:
191 199
192static int sdio_bus_pm_prepare(struct device *dev) 200static int sdio_bus_pm_prepare(struct device *dev)
193{ 201{
202 struct sdio_func *func = dev_to_sdio_func(dev);
203
194 /* 204 /*
195 * Resume an SDIO device which was suspended at run time at this 205 * Resume an SDIO device which was suspended at run time at this
196 * point, in order to allow standard SDIO suspend/resume paths 206 * point, in order to allow standard SDIO suspend/resume paths
@@ -212,7 +222,8 @@ static int sdio_bus_pm_prepare(struct device *dev)
212 * since there is little point in failing system suspend if a 222 * since there is little point in failing system suspend if a
213 * device can't be resumed. 223 * device can't be resumed.
214 */ 224 */
215 pm_runtime_resume(dev); 225 if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD)
226 pm_runtime_resume(dev);
216 227
217 return 0; 228 return 0;
218} 229}
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 82a1079bbdc7..5d46021cbb57 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -1002,7 +1002,7 @@ static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
1002 * Monitor a 0->1 transition first 1002 * Monitor a 0->1 transition first
1003 */ 1003 */
1004 if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) { 1004 if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) {
1005 while ((!(OMAP_HSMMC_READ(host, SYSCTL) & bit)) 1005 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit))
1006 && (i++ < limit)) 1006 && (i++ < limit))
1007 cpu_relax(); 1007 cpu_relax();
1008 } 1008 }
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 2e9cca19c90b..9b82910b9dbb 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -17,6 +17,7 @@
17#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/mmc/host.h> 18#include <linux/mmc/host.h>
19#include <linux/mmc/sdhci-pltfm.h> 19#include <linux/mmc/sdhci-pltfm.h>
20#include <mach/hardware.h>
20#include "sdhci.h" 21#include "sdhci.h"
21#include "sdhci-pltfm.h" 22#include "sdhci-pltfm.h"
22#include "sdhci-esdhc.h" 23#include "sdhci-esdhc.h"
@@ -112,6 +113,13 @@ static int esdhc_pltfm_init(struct sdhci_host *host, struct sdhci_pltfm_data *pd
112 clk_enable(clk); 113 clk_enable(clk);
113 pltfm_host->clk = clk; 114 pltfm_host->clk = clk;
114 115
116 if (cpu_is_mx35() || cpu_is_mx51())
117 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
118
119 /* Fix errata ENGcm07207 which is present on i.MX25 and i.MX35 */
120 if (cpu_is_mx25() || cpu_is_mx35())
121 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK;
122
115 return 0; 123 return 0;
116} 124}
117 125
@@ -133,10 +141,8 @@ static struct sdhci_ops sdhci_esdhc_ops = {
133}; 141};
134 142
135struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { 143struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
136 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_MULTIBLOCK 144 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA,
137 | SDHCI_QUIRK_BROKEN_ADMA,
138 /* ADMA has issues. Might be fixable */ 145 /* ADMA has issues. Might be fixable */
139 /* NO_MULTIBLOCK might be MX35 only (Errata: ENGcm07207) */
140 .ops = &sdhci_esdhc_ops, 146 .ops = &sdhci_esdhc_ops,
141 .init = esdhc_pltfm_init, 147 .init = esdhc_pltfm_init,
142 .exit = esdhc_pltfm_exit, 148 .exit = esdhc_pltfm_exit,
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 55746bac2f44..3d9c2460d437 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -149,11 +149,11 @@ static const struct sdhci_pci_fixes sdhci_cafe = {
149 * ADMA operation is disabled for Moorestown platform due to 149 * ADMA operation is disabled for Moorestown platform due to
150 * hardware bugs. 150 * hardware bugs.
151 */ 151 */
152static int mrst_hc1_probe(struct sdhci_pci_chip *chip) 152static int mrst_hc_probe(struct sdhci_pci_chip *chip)
153{ 153{
154 /* 154 /*
155 * slots number is fixed here for MRST as SDIO3 is never used and has 155 * slots number is fixed here for MRST as SDIO3/5 are never used and
156 * hardware bugs. 156 * have hardware bugs.
157 */ 157 */
158 chip->num_slots = 1; 158 chip->num_slots = 1;
159 return 0; 159 return 0;
@@ -163,9 +163,9 @@ static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
163 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT, 163 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
164}; 164};
165 165
166static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1 = { 166static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
167 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT, 167 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
168 .probe = mrst_hc1_probe, 168 .probe = mrst_hc_probe,
169}; 169};
170 170
171static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = { 171static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
@@ -538,7 +538,15 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
538 .device = PCI_DEVICE_ID_INTEL_MRST_SD1, 538 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
539 .subvendor = PCI_ANY_ID, 539 .subvendor = PCI_ANY_ID,
540 .subdevice = PCI_ANY_ID, 540 .subdevice = PCI_ANY_ID,
541 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1, 541 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
542 },
543
544 {
545 .vendor = PCI_VENDOR_ID_INTEL,
546 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
547 .subvendor = PCI_ANY_ID,
548 .subdevice = PCI_ANY_ID,
549 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
542 }, 550 },
543 551
544 { 552 {
@@ -637,6 +645,7 @@ static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state)
637{ 645{
638 struct sdhci_pci_chip *chip; 646 struct sdhci_pci_chip *chip;
639 struct sdhci_pci_slot *slot; 647 struct sdhci_pci_slot *slot;
648 mmc_pm_flag_t slot_pm_flags;
640 mmc_pm_flag_t pm_flags = 0; 649 mmc_pm_flag_t pm_flags = 0;
641 int i, ret; 650 int i, ret;
642 651
@@ -657,7 +666,11 @@ static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state)
657 return ret; 666 return ret;
658 } 667 }
659 668
660 pm_flags |= slot->host->mmc->pm_flags; 669 slot_pm_flags = slot->host->mmc->pm_flags;
670 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
671 sdhci_enable_irq_wakeups(slot->host);
672
673 pm_flags |= slot_pm_flags;
661 } 674 }
662 675
663 if (chip->fixes && chip->fixes->suspend) { 676 if (chip->fixes && chip->fixes->suspend) {
@@ -671,8 +684,10 @@ static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state)
671 684
672 pci_save_state(pdev); 685 pci_save_state(pdev);
673 if (pm_flags & MMC_PM_KEEP_POWER) { 686 if (pm_flags & MMC_PM_KEEP_POWER) {
674 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) 687 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) {
688 pci_pme_active(pdev, true);
675 pci_enable_wake(pdev, PCI_D3hot, 1); 689 pci_enable_wake(pdev, PCI_D3hot, 1);
690 }
676 pci_set_power_state(pdev, PCI_D3hot); 691 pci_set_power_state(pdev, PCI_D3hot);
677 } else { 692 } else {
678 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0); 693 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
diff --git a/drivers/mmc/host/sdhci-pxa.c b/drivers/mmc/host/sdhci-pxa.c
index fc406ac5d193..5a61208cbc66 100644
--- a/drivers/mmc/host/sdhci-pxa.c
+++ b/drivers/mmc/host/sdhci-pxa.c
@@ -141,6 +141,10 @@ static int __devinit sdhci_pxa_probe(struct platform_device *pdev)
141 if (pdata->quirks) 141 if (pdata->quirks)
142 host->quirks |= pdata->quirks; 142 host->quirks |= pdata->quirks;
143 143
144 /* If slot design supports 8 bit data, indicate this to MMC. */
145 if (pdata->flags & PXA_FLAG_SD_8_BIT_CAPABLE_SLOT)
146 host->mmc->caps |= MMC_CAP_8_BIT_DATA;
147
144 ret = sdhci_add_host(host); 148 ret = sdhci_add_host(host);
145 if (ret) { 149 if (ret) {
146 dev_err(&pdev->dev, "failed to add host\n"); 150 dev_err(&pdev->dev, "failed to add host\n");
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 782c0ee3c925..a25db426c910 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1185,17 +1185,31 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1185 if (host->ops->platform_send_init_74_clocks) 1185 if (host->ops->platform_send_init_74_clocks)
1186 host->ops->platform_send_init_74_clocks(host, ios->power_mode); 1186 host->ops->platform_send_init_74_clocks(host, ios->power_mode);
1187 1187
1188 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); 1188 /*
1189 1189 * If your platform has 8-bit width support but is not a v3 controller,
1190 if (ios->bus_width == MMC_BUS_WIDTH_8) 1190 * or if it requires special setup code, you should implement that in
1191 ctrl |= SDHCI_CTRL_8BITBUS; 1191 * platform_8bit_width().
1192 else 1192 */
1193 ctrl &= ~SDHCI_CTRL_8BITBUS; 1193 if (host->ops->platform_8bit_width)
1194 host->ops->platform_8bit_width(host, ios->bus_width);
1195 else {
1196 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1197 if (ios->bus_width == MMC_BUS_WIDTH_8) {
1198 ctrl &= ~SDHCI_CTRL_4BITBUS;
1199 if (host->version >= SDHCI_SPEC_300)
1200 ctrl |= SDHCI_CTRL_8BITBUS;
1201 } else {
1202 if (host->version >= SDHCI_SPEC_300)
1203 ctrl &= ~SDHCI_CTRL_8BITBUS;
1204 if (ios->bus_width == MMC_BUS_WIDTH_4)
1205 ctrl |= SDHCI_CTRL_4BITBUS;
1206 else
1207 ctrl &= ~SDHCI_CTRL_4BITBUS;
1208 }
1209 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
1210 }
1194 1211
1195 if (ios->bus_width == MMC_BUS_WIDTH_4) 1212 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1196 ctrl |= SDHCI_CTRL_4BITBUS;
1197 else
1198 ctrl &= ~SDHCI_CTRL_4BITBUS;
1199 1213
1200 if ((ios->timing == MMC_TIMING_SD_HS || 1214 if ((ios->timing == MMC_TIMING_SD_HS ||
1201 ios->timing == MMC_TIMING_MMC_HS) 1215 ios->timing == MMC_TIMING_MMC_HS)
@@ -1681,6 +1695,16 @@ int sdhci_resume_host(struct sdhci_host *host)
1681 1695
1682EXPORT_SYMBOL_GPL(sdhci_resume_host); 1696EXPORT_SYMBOL_GPL(sdhci_resume_host);
1683 1697
1698void sdhci_enable_irq_wakeups(struct sdhci_host *host)
1699{
1700 u8 val;
1701 val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL);
1702 val |= SDHCI_WAKE_ON_INT;
1703 sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL);
1704}
1705
1706EXPORT_SYMBOL_GPL(sdhci_enable_irq_wakeups);
1707
1684#endif /* CONFIG_PM */ 1708#endif /* CONFIG_PM */
1685 1709
1686/*****************************************************************************\ 1710/*****************************************************************************\
@@ -1845,11 +1869,19 @@ int sdhci_add_host(struct sdhci_host *host)
1845 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300; 1869 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
1846 else 1870 else
1847 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200; 1871 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200;
1872
1848 mmc->f_max = host->max_clk; 1873 mmc->f_max = host->max_clk;
1849 mmc->caps |= MMC_CAP_SDIO_IRQ; 1874 mmc->caps |= MMC_CAP_SDIO_IRQ;
1850 1875
1876 /*
1877 * A controller may support 8-bit width, but the board itself
1878 * might not have the pins brought out. Boards that support
1879 * 8-bit width must set "mmc->caps |= MMC_CAP_8_BIT_DATA;" in
1880 * their platform code before calling sdhci_add_host(), and we
1881 * won't assume 8-bit width for hosts without that CAP.
1882 */
1851 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) 1883 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
1852 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; 1884 mmc->caps |= MMC_CAP_4_BIT_DATA;
1853 1885
1854 if (caps & SDHCI_CAN_DO_HISPD) 1886 if (caps & SDHCI_CAN_DO_HISPD)
1855 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 1887 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index b7b8a3b28b01..e42d7f00c060 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -76,7 +76,7 @@
76#define SDHCI_CTRL_ADMA1 0x08 76#define SDHCI_CTRL_ADMA1 0x08
77#define SDHCI_CTRL_ADMA32 0x10 77#define SDHCI_CTRL_ADMA32 0x10
78#define SDHCI_CTRL_ADMA64 0x18 78#define SDHCI_CTRL_ADMA64 0x18
79#define SDHCI_CTRL_8BITBUS 0x20 79#define SDHCI_CTRL_8BITBUS 0x20
80 80
81#define SDHCI_POWER_CONTROL 0x29 81#define SDHCI_POWER_CONTROL 0x29
82#define SDHCI_POWER_ON 0x01 82#define SDHCI_POWER_ON 0x01
@@ -87,6 +87,9 @@
87#define SDHCI_BLOCK_GAP_CONTROL 0x2A 87#define SDHCI_BLOCK_GAP_CONTROL 0x2A
88 88
89#define SDHCI_WAKE_UP_CONTROL 0x2B 89#define SDHCI_WAKE_UP_CONTROL 0x2B
90#define SDHCI_WAKE_ON_INT 0x01
91#define SDHCI_WAKE_ON_INSERT 0x02
92#define SDHCI_WAKE_ON_REMOVE 0x04
90 93
91#define SDHCI_CLOCK_CONTROL 0x2C 94#define SDHCI_CLOCK_CONTROL 0x2C
92#define SDHCI_DIVIDER_SHIFT 8 95#define SDHCI_DIVIDER_SHIFT 8
@@ -152,6 +155,7 @@
152#define SDHCI_CLOCK_BASE_SHIFT 8 155#define SDHCI_CLOCK_BASE_SHIFT 8
153#define SDHCI_MAX_BLOCK_MASK 0x00030000 156#define SDHCI_MAX_BLOCK_MASK 0x00030000
154#define SDHCI_MAX_BLOCK_SHIFT 16 157#define SDHCI_MAX_BLOCK_SHIFT 16
158#define SDHCI_CAN_DO_8BIT 0x00040000
155#define SDHCI_CAN_DO_ADMA2 0x00080000 159#define SDHCI_CAN_DO_ADMA2 0x00080000
156#define SDHCI_CAN_DO_ADMA1 0x00100000 160#define SDHCI_CAN_DO_ADMA1 0x00100000
157#define SDHCI_CAN_DO_HISPD 0x00200000 161#define SDHCI_CAN_DO_HISPD 0x00200000
@@ -212,6 +216,8 @@ struct sdhci_ops {
212 unsigned int (*get_max_clock)(struct sdhci_host *host); 216 unsigned int (*get_max_clock)(struct sdhci_host *host);
213 unsigned int (*get_min_clock)(struct sdhci_host *host); 217 unsigned int (*get_min_clock)(struct sdhci_host *host);
214 unsigned int (*get_timeout_clock)(struct sdhci_host *host); 218 unsigned int (*get_timeout_clock)(struct sdhci_host *host);
219 int (*platform_8bit_width)(struct sdhci_host *host,
220 int width);
215 void (*platform_send_init_74_clocks)(struct sdhci_host *host, 221 void (*platform_send_init_74_clocks)(struct sdhci_host *host,
216 u8 power_mode); 222 u8 power_mode);
217 unsigned int (*get_ro)(struct sdhci_host *host); 223 unsigned int (*get_ro)(struct sdhci_host *host);
@@ -317,6 +323,7 @@ extern void sdhci_remove_host(struct sdhci_host *host, int dead);
317#ifdef CONFIG_PM 323#ifdef CONFIG_PM
318extern int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state); 324extern int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state);
319extern int sdhci_resume_host(struct sdhci_host *host); 325extern int sdhci_resume_host(struct sdhci_host *host);
326extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
320#endif 327#endif
321 328
322#endif /* __SDHCI_HW_H */ 329#endif /* __SDHCI_HW_H */
diff --git a/drivers/mmc/host/ushc.c b/drivers/mmc/host/ushc.c
index b4ead4a13c98..f8f65df9b017 100644
--- a/drivers/mmc/host/ushc.c
+++ b/drivers/mmc/host/ushc.c
@@ -425,7 +425,7 @@ static int ushc_probe(struct usb_interface *intf, const struct usb_device_id *id
425 struct usb_device *usb_dev = interface_to_usbdev(intf); 425 struct usb_device *usb_dev = interface_to_usbdev(intf);
426 struct mmc_host *mmc; 426 struct mmc_host *mmc;
427 struct ushc_data *ushc; 427 struct ushc_data *ushc;
428 int ret = -ENOMEM; 428 int ret;
429 429
430 mmc = mmc_alloc_host(sizeof(struct ushc_data), &intf->dev); 430 mmc = mmc_alloc_host(sizeof(struct ushc_data), &intf->dev);
431 if (mmc == NULL) 431 if (mmc == NULL)
@@ -462,11 +462,15 @@ static int ushc_probe(struct usb_interface *intf, const struct usb_device_id *id
462 mmc->max_blk_count = 511; 462 mmc->max_blk_count = 511;
463 463
464 ushc->int_urb = usb_alloc_urb(0, GFP_KERNEL); 464 ushc->int_urb = usb_alloc_urb(0, GFP_KERNEL);
465 if (ushc->int_urb == NULL) 465 if (ushc->int_urb == NULL) {
466 ret = -ENOMEM;
466 goto err; 467 goto err;
468 }
467 ushc->int_data = kzalloc(sizeof(struct ushc_int_data), GFP_KERNEL); 469 ushc->int_data = kzalloc(sizeof(struct ushc_int_data), GFP_KERNEL);
468 if (ushc->int_data == NULL) 470 if (ushc->int_data == NULL) {
471 ret = -ENOMEM;
469 goto err; 472 goto err;
473 }
470 usb_fill_int_urb(ushc->int_urb, ushc->usb_dev, 474 usb_fill_int_urb(ushc->int_urb, ushc->usb_dev,
471 usb_rcvintpipe(usb_dev, 475 usb_rcvintpipe(usb_dev,
472 intf->cur_altsetting->endpoint[0].desc.bEndpointAddress), 476 intf->cur_altsetting->endpoint[0].desc.bEndpointAddress),
@@ -475,11 +479,15 @@ static int ushc_probe(struct usb_interface *intf, const struct usb_device_id *id
475 intf->cur_altsetting->endpoint[0].desc.bInterval); 479 intf->cur_altsetting->endpoint[0].desc.bInterval);
476 480
477 ushc->cbw_urb = usb_alloc_urb(0, GFP_KERNEL); 481 ushc->cbw_urb = usb_alloc_urb(0, GFP_KERNEL);
478 if (ushc->cbw_urb == NULL) 482 if (ushc->cbw_urb == NULL) {
483 ret = -ENOMEM;
479 goto err; 484 goto err;
485 }
480 ushc->cbw = kzalloc(sizeof(struct ushc_cbw), GFP_KERNEL); 486 ushc->cbw = kzalloc(sizeof(struct ushc_cbw), GFP_KERNEL);
481 if (ushc->cbw == NULL) 487 if (ushc->cbw == NULL) {
488 ret = -ENOMEM;
482 goto err; 489 goto err;
490 }
483 ushc->cbw->signature = USHC_CBW_SIGNATURE; 491 ushc->cbw->signature = USHC_CBW_SIGNATURE;
484 492
485 usb_fill_bulk_urb(ushc->cbw_urb, ushc->usb_dev, usb_sndbulkpipe(usb_dev, 2), 493 usb_fill_bulk_urb(ushc->cbw_urb, ushc->usb_dev, usb_sndbulkpipe(usb_dev, 2),
@@ -487,15 +495,21 @@ static int ushc_probe(struct usb_interface *intf, const struct usb_device_id *id
487 cbw_callback, ushc); 495 cbw_callback, ushc);
488 496
489 ushc->data_urb = usb_alloc_urb(0, GFP_KERNEL); 497 ushc->data_urb = usb_alloc_urb(0, GFP_KERNEL);
490 if (ushc->data_urb == NULL) 498 if (ushc->data_urb == NULL) {
499 ret = -ENOMEM;
491 goto err; 500 goto err;
501 }
492 502
493 ushc->csw_urb = usb_alloc_urb(0, GFP_KERNEL); 503 ushc->csw_urb = usb_alloc_urb(0, GFP_KERNEL);
494 if (ushc->csw_urb == NULL) 504 if (ushc->csw_urb == NULL) {
505 ret = -ENOMEM;
495 goto err; 506 goto err;
507 }
496 ushc->csw = kzalloc(sizeof(struct ushc_cbw), GFP_KERNEL); 508 ushc->csw = kzalloc(sizeof(struct ushc_cbw), GFP_KERNEL);
497 if (ushc->csw == NULL) 509 if (ushc->csw == NULL) {
510 ret = -ENOMEM;
498 goto err; 511 goto err;
512 }
499 usb_fill_bulk_urb(ushc->csw_urb, ushc->usb_dev, usb_rcvbulkpipe(usb_dev, 6), 513 usb_fill_bulk_urb(ushc->csw_urb, ushc->usb_dev, usb_rcvbulkpipe(usb_dev, 6),
500 ushc->csw, sizeof(struct ushc_csw), 514 ushc->csw, sizeof(struct ushc_csw),
501 csw_callback, ushc); 515 csw_callback, ushc);
diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c
index dd90880048cf..d8ae634d347e 100644
--- a/drivers/mtd/maps/pxa2xx-flash.c
+++ b/drivers/mtd/maps/pxa2xx-flash.c
@@ -51,7 +51,7 @@ struct pxa2xx_flash_info {
51static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 51static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
52 52
53 53
54static int __init pxa2xx_flash_probe(struct platform_device *pdev) 54static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
55{ 55{
56 struct flash_platform_data *flash = pdev->dev.platform_data; 56 struct flash_platform_data *flash = pdev->dev.platform_data;
57 struct pxa2xx_flash_info *info; 57 struct pxa2xx_flash_info *info;
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index cd41c58b5bbd..15682ec8530e 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -7,7 +7,6 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#define CONFIG_MTD_NAND_OMAP_HWECC
11 10
12#include <linux/platform_device.h> 11#include <linux/platform_device.h>
13#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index c2960ac9f39c..811775aa8ee8 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -482,10 +482,17 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum)
482 uint32_t data = 0; 482 uint32_t data = 0;
483 struct ubi_vid_hdr vid_hdr; 483 struct ubi_vid_hdr vid_hdr;
484 484
485 addr = (loff_t)pnum * ubi->peb_size + ubi->vid_hdr_aloffset; 485 /*
486 * It is important to first invalidate the EC header, and then the VID
487 * header. Otherwise a power cut may lead to valid EC header and
488 * invalid VID header, in which case UBI will treat this PEB as
489 * corrupted and will try to preserve it, and print scary warnings (see
490 * the header comment in scan.c for more information).
491 */
492 addr = (loff_t)pnum * ubi->peb_size;
486 err = ubi->mtd->write(ubi->mtd, addr, 4, &written, (void *)&data); 493 err = ubi->mtd->write(ubi->mtd, addr, 4, &written, (void *)&data);
487 if (!err) { 494 if (!err) {
488 addr -= ubi->vid_hdr_aloffset; 495 addr += ubi->vid_hdr_aloffset;
489 err = ubi->mtd->write(ubi->mtd, addr, 4, &written, 496 err = ubi->mtd->write(ubi->mtd, addr, 4, &written,
490 (void *)&data); 497 (void *)&data);
491 if (!err) 498 if (!err)
@@ -494,18 +501,24 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum)
494 501
495 /* 502 /*
496 * We failed to write to the media. This was observed with Spansion 503 * We failed to write to the media. This was observed with Spansion
497 * S29GL512N NOR flash. Most probably the eraseblock erasure was 504 * S29GL512N NOR flash. Most probably the previously eraseblock erasure
498 * interrupted at a very inappropriate moment, so it became unwritable. 505 * was interrupted at a very inappropriate moment, so it became
499 * In this case we probably anyway have garbage in this PEB. 506 * unwritable. In this case we probably anyway have garbage in this
507 * PEB.
500 */ 508 */
501 err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0); 509 err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0);
502 if (err1 == UBI_IO_BAD_HDR_EBADMSG || err1 == UBI_IO_BAD_HDR) 510 if (err1 == UBI_IO_BAD_HDR_EBADMSG || err1 == UBI_IO_BAD_HDR) {
503 /* 511 struct ubi_ec_hdr ec_hdr;
504 * The VID header is corrupted, so we can safely erase this 512
505 * PEB and not afraid that it will be treated as a valid PEB in 513 err1 = ubi_io_read_ec_hdr(ubi, pnum, &ec_hdr, 0);
506 * case of an unclean reboot. 514 if (err1 == UBI_IO_BAD_HDR_EBADMSG || err1 == UBI_IO_BAD_HDR)
507 */ 515 /*
508 return 0; 516 * Both VID and EC headers are corrupted, so we can
517 * safely erase this PEB and not afraid that it will be
518 * treated as a valid PEB in case of an unclean reboot.
519 */
520 return 0;
521 }
509 522
510 /* 523 /*
511 * The PEB contains a valid VID header, but we cannot invalidate it. 524 * The PEB contains a valid VID header, but we cannot invalidate it.
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 3c631863bf40..79ca304fc4db 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -787,16 +787,15 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
787 * erased, so it became unstable and corrupted, and should be 787 * erased, so it became unstable and corrupted, and should be
788 * erased. 788 * erased.
789 */ 789 */
790 return 0; 790 err = 0;
791 goto out_unlock;
791 } 792 }
792 793
793 if (err) 794 if (err)
794 return err; 795 goto out_unlock;
795 796
796 if (ubi_check_pattern(ubi->peb_buf1, 0xFF, ubi->leb_size)) { 797 if (ubi_check_pattern(ubi->peb_buf1, 0xFF, ubi->leb_size))
797 mutex_unlock(&ubi->buf_mutex); 798 goto out_unlock;
798 return 0;
799 }
800 799
801 ubi_err("PEB %d contains corrupted VID header, and the data does not " 800 ubi_err("PEB %d contains corrupted VID header, and the data does not "
802 "contain all 0xFF, this may be a non-UBI PEB or a severe VID " 801 "contain all 0xFF, this may be a non-UBI PEB or a severe VID "
@@ -806,8 +805,11 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
806 pnum, ubi->leb_start, ubi->leb_size); 805 pnum, ubi->leb_start, ubi->leb_size);
807 ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 806 ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
808 ubi->peb_buf1, ubi->leb_size, 1); 807 ubi->peb_buf1, ubi->leb_size, 1);
808 err = 1;
809
810out_unlock:
809 mutex_unlock(&ubi->buf_mutex); 811 mutex_unlock(&ubi->buf_mutex);
810 return 1; 812 return err;
811} 813}
812 814
813/** 815/**
@@ -951,6 +953,10 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
951 * impossible to distinguish it from a PEB which just 953 * impossible to distinguish it from a PEB which just
952 * contains garbage because of a power cut during erase 954 * contains garbage because of a power cut during erase
953 * operation. So we just schedule this PEB for erasure. 955 * operation. So we just schedule this PEB for erasure.
956 *
957 * Besides, in case of NOR flash, we deliberatly
958 * corrupt both headers because NOR flash erasure is
959 * slow and can start from the end.
954 */ 960 */
955 err = 0; 961 err = 0;
956 else 962 else
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index e1da258bbfb7..0a92436f0538 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -699,7 +699,8 @@ DEFINE_WINDOW_IO(32)
699#define DEVICE_PCI(dev) NULL 699#define DEVICE_PCI(dev) NULL
700#endif 700#endif
701 701
702#define VORTEX_PCI(vp) (((vp)->gendev) ? DEVICE_PCI((vp)->gendev) : NULL) 702#define VORTEX_PCI(vp) \
703 ((struct pci_dev *) (((vp)->gendev) ? DEVICE_PCI((vp)->gendev) : NULL))
703 704
704#ifdef CONFIG_EISA 705#ifdef CONFIG_EISA
705#define DEVICE_EISA(dev) (((dev)->bus == &eisa_bus_type) ? to_eisa_device((dev)) : NULL) 706#define DEVICE_EISA(dev) (((dev)->bus == &eisa_bus_type) ? to_eisa_device((dev)) : NULL)
@@ -707,7 +708,8 @@ DEFINE_WINDOW_IO(32)
707#define DEVICE_EISA(dev) NULL 708#define DEVICE_EISA(dev) NULL
708#endif 709#endif
709 710
710#define VORTEX_EISA(vp) (((vp)->gendev) ? DEVICE_EISA((vp)->gendev) : NULL) 711#define VORTEX_EISA(vp) \
712 ((struct eisa_device *) (((vp)->gendev) ? DEVICE_EISA((vp)->gendev) : NULL))
711 713
712/* The action to take with a media selection timer tick. 714/* The action to take with a media selection timer tick.
713 Note that we deviate from the 3Com order by checking 10base2 before AUI. 715 Note that we deviate from the 3Com order by checking 10base2 before AUI.
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index ac422cd332ea..dd16e83933a2 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -490,13 +490,11 @@ static inline unsigned int cp_rx_csum_ok (u32 status)
490{ 490{
491 unsigned int protocol = (status >> 16) & 0x3; 491 unsigned int protocol = (status >> 16) & 0x3;
492 492
493 if (likely((protocol == RxProtoTCP) && (!(status & TCPFail)))) 493 if (((protocol == RxProtoTCP) && !(status & TCPFail)) ||
494 ((protocol == RxProtoUDP) && !(status & UDPFail)))
494 return 1; 495 return 1;
495 else if ((protocol == RxProtoUDP) && (!(status & UDPFail))) 496 else
496 return 1; 497 return 0;
497 else if ((protocol == RxProtoIP) && (!(status & IPFail)))
498 return 1;
499 return 0;
500} 498}
501 499
502static int cp_rx_poll(struct napi_struct *napi, int budget) 500static int cp_rx_poll(struct napi_struct *napi, int budget)
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index f6668cdaac85..4f1755bddf6b 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2543,10 +2543,10 @@ config PCH_GBE
2543 depends on PCI 2543 depends on PCI
2544 select MII 2544 select MII
2545 ---help--- 2545 ---help---
2546 This is a gigabit ethernet driver for Topcliff PCH. 2546 This is a gigabit ethernet driver for EG20T PCH.
2547 Topcliff PCH is the platform controller hub that is used in Intel's 2547 EG20T PCH is the platform controller hub that is used in Intel's
2548 general embedded platform. 2548 general embedded platform.
2549 Topcliff PCH has Gigabit Ethernet interface. 2549 EG20T PCH has Gigabit Ethernet interface.
2550 Using this interface, it is able to access system devices connected 2550 Using this interface, it is able to access system devices connected
2551 to Gigabit Ethernet. 2551 to Gigabit Ethernet.
2552 This driver enables Gigabit Ethernet function. 2552 This driver enables Gigabit Ethernet function.
@@ -2945,6 +2945,18 @@ source "drivers/s390/net/Kconfig"
2945 2945
2946source "drivers/net/caif/Kconfig" 2946source "drivers/net/caif/Kconfig"
2947 2947
2948config TILE_NET
2949 tristate "Tilera GBE/XGBE network driver support"
2950 depends on TILE
2951 default y
2952 select CRC32
2953 help
2954 This is a standard Linux network device driver for the
2955 on-chip Tilera Gigabit Ethernet and XAUI interfaces.
2956
2957 To compile this driver as a module, choose M here: the module
2958 will be called tile_net.
2959
2948config XEN_NETDEV_FRONTEND 2960config XEN_NETDEV_FRONTEND
2949 tristate "Xen network device frontend driver" 2961 tristate "Xen network device frontend driver"
2950 depends on XEN 2962 depends on XEN
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 652fc6b98039..b90738d13994 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -301,3 +301,4 @@ obj-$(CONFIG_CAIF) += caif/
301 301
302obj-$(CONFIG_OCTEON_MGMT_ETHERNET) += octeon/ 302obj-$(CONFIG_OCTEON_MGMT_ETHERNET) += octeon/
303obj-$(CONFIG_PCH_GBE) += pch_gbe/ 303obj-$(CONFIG_PCH_GBE) += pch_gbe/
304obj-$(CONFIG_TILE_NET) += tile/
diff --git a/drivers/net/atl1c/atl1c_hw.c b/drivers/net/atl1c/atl1c_hw.c
index 919080b2c3a5..1bf672009948 100644
--- a/drivers/net/atl1c/atl1c_hw.c
+++ b/drivers/net/atl1c/atl1c_hw.c
@@ -82,7 +82,7 @@ static int atl1c_get_permanent_address(struct atl1c_hw *hw)
82 addr[0] = addr[1] = 0; 82 addr[0] = addr[1] = 0;
83 AT_READ_REG(hw, REG_OTP_CTRL, &otp_ctrl_data); 83 AT_READ_REG(hw, REG_OTP_CTRL, &otp_ctrl_data);
84 if (atl1c_check_eeprom_exist(hw)) { 84 if (atl1c_check_eeprom_exist(hw)) {
85 if (hw->nic_type == athr_l1c || hw->nic_type == athr_l2c_b) { 85 if (hw->nic_type == athr_l1c || hw->nic_type == athr_l2c) {
86 /* Enable OTP CLK */ 86 /* Enable OTP CLK */
87 if (!(otp_ctrl_data & OTP_CTRL_CLK_EN)) { 87 if (!(otp_ctrl_data & OTP_CTRL_CLK_EN)) {
88 otp_ctrl_data |= OTP_CTRL_CLK_EN; 88 otp_ctrl_data |= OTP_CTRL_CLK_EN;
diff --git a/drivers/net/atlx/atl1.c b/drivers/net/atlx/atl1.c
index 43579b3b24ac..53363108994e 100644
--- a/drivers/net/atlx/atl1.c
+++ b/drivers/net/atlx/atl1.c
@@ -3043,7 +3043,6 @@ static int __devinit atl1_probe(struct pci_dev *pdev,
3043 atl1_pcie_patch(adapter); 3043 atl1_pcie_patch(adapter);
3044 /* assume we have no link for now */ 3044 /* assume we have no link for now */
3045 netif_carrier_off(netdev); 3045 netif_carrier_off(netdev);
3046 netif_stop_queue(netdev);
3047 3046
3048 setup_timer(&adapter->phy_config_timer, atl1_phy_config, 3047 setup_timer(&adapter->phy_config_timer, atl1_phy_config,
3049 (unsigned long)adapter); 3048 (unsigned long)adapter);
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index 43489f89c142..53eff9ba6e95 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -155,10 +155,10 @@ static void au1000_enable_mac(struct net_device *dev, int force_reset)
155 spin_lock_irqsave(&aup->lock, flags); 155 spin_lock_irqsave(&aup->lock, flags);
156 156
157 if (force_reset || (!aup->mac_enabled)) { 157 if (force_reset || (!aup->mac_enabled)) {
158 writel(MAC_EN_CLOCK_ENABLE, &aup->enable); 158 writel(MAC_EN_CLOCK_ENABLE, aup->enable);
159 au_sync_delay(2); 159 au_sync_delay(2);
160 writel((MAC_EN_RESET0 | MAC_EN_RESET1 | MAC_EN_RESET2 160 writel((MAC_EN_RESET0 | MAC_EN_RESET1 | MAC_EN_RESET2
161 | MAC_EN_CLOCK_ENABLE), &aup->enable); 161 | MAC_EN_CLOCK_ENABLE), aup->enable);
162 au_sync_delay(2); 162 au_sync_delay(2);
163 163
164 aup->mac_enabled = 1; 164 aup->mac_enabled = 1;
@@ -503,9 +503,9 @@ static void au1000_reset_mac_unlocked(struct net_device *dev)
503 503
504 au1000_hard_stop(dev); 504 au1000_hard_stop(dev);
505 505
506 writel(MAC_EN_CLOCK_ENABLE, &aup->enable); 506 writel(MAC_EN_CLOCK_ENABLE, aup->enable);
507 au_sync_delay(2); 507 au_sync_delay(2);
508 writel(0, &aup->enable); 508 writel(0, aup->enable);
509 au_sync_delay(2); 509 au_sync_delay(2);
510 510
511 aup->tx_full = 0; 511 aup->tx_full = 0;
@@ -1119,7 +1119,7 @@ static int __devinit au1000_probe(struct platform_device *pdev)
1119 /* set a random MAC now in case platform_data doesn't provide one */ 1119 /* set a random MAC now in case platform_data doesn't provide one */
1120 random_ether_addr(dev->dev_addr); 1120 random_ether_addr(dev->dev_addr);
1121 1121
1122 writel(0, &aup->enable); 1122 writel(0, aup->enable);
1123 aup->mac_enabled = 0; 1123 aup->mac_enabled = 0;
1124 1124
1125 pd = pdev->dev.platform_data; 1125 pd = pdev->dev.platform_data;
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index c6e86315b3f8..2e2b76258ab4 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -381,11 +381,11 @@ static void b44_set_flow_ctrl(struct b44 *bp, u32 local, u32 remote)
381 __b44_set_flow_ctrl(bp, pause_enab); 381 __b44_set_flow_ctrl(bp, pause_enab);
382} 382}
383 383
384#ifdef SSB_DRIVER_MIPS 384#ifdef CONFIG_BCM47XX
385extern char *nvram_get(char *name); 385#include <asm/mach-bcm47xx/nvram.h>
386static void b44_wap54g10_workaround(struct b44 *bp) 386static void b44_wap54g10_workaround(struct b44 *bp)
387{ 387{
388 const char *str; 388 char buf[20];
389 u32 val; 389 u32 val;
390 int err; 390 int err;
391 391
@@ -394,10 +394,9 @@ static void b44_wap54g10_workaround(struct b44 *bp)
394 * see https://dev.openwrt.org/ticket/146 394 * see https://dev.openwrt.org/ticket/146
395 * check and reset bit "isolate" 395 * check and reset bit "isolate"
396 */ 396 */
397 str = nvram_get("boardnum"); 397 if (nvram_getenv("boardnum", buf, sizeof(buf)) < 0)
398 if (!str)
399 return; 398 return;
400 if (simple_strtoul(str, NULL, 0) == 2) { 399 if (simple_strtoul(buf, NULL, 0) == 2) {
401 err = __b44_readphy(bp, 0, MII_BMCR, &val); 400 err = __b44_readphy(bp, 0, MII_BMCR, &val);
402 if (err) 401 if (err)
403 goto error; 402 goto error;
diff --git a/drivers/net/benet/be_cmds.c b/drivers/net/benet/be_cmds.c
index 36eca1ce75d4..e4465d222a7d 100644
--- a/drivers/net/benet/be_cmds.c
+++ b/drivers/net/benet/be_cmds.c
@@ -1235,7 +1235,7 @@ int be_cmd_multicast_set(struct be_adapter *adapter, u32 if_id,
1235 1235
1236 i = 0; 1236 i = 0;
1237 netdev_for_each_mc_addr(ha, netdev) 1237 netdev_for_each_mc_addr(ha, netdev)
1238 memcpy(req->mac[i].byte, ha->addr, ETH_ALEN); 1238 memcpy(req->mac[i++].byte, ha->addr, ETH_ALEN);
1239 } else { 1239 } else {
1240 req->promiscuous = 1; 1240 req->promiscuous = 1;
1241 } 1241 }
diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c
index c36cd2ffbadc..93354eee2cfd 100644
--- a/drivers/net/benet/be_main.c
+++ b/drivers/net/benet/be_main.c
@@ -2458,6 +2458,12 @@ int be_load_fw(struct be_adapter *adapter, u8 *func)
2458 int status, i = 0, num_imgs = 0; 2458 int status, i = 0, num_imgs = 0;
2459 const u8 *p; 2459 const u8 *p;
2460 2460
2461 if (!netif_running(adapter->netdev)) {
2462 dev_err(&adapter->pdev->dev,
2463 "Firmware load not allowed (interface is down)\n");
2464 return -EPERM;
2465 }
2466
2461 strcpy(fw_file, func); 2467 strcpy(fw_file, func);
2462 2468
2463 status = request_firmware(&fw, fw_file, &adapter->pdev->dev); 2469 status = request_firmware(&fw, fw_file, &adapter->pdev->dev);
diff --git a/drivers/net/bnx2x/bnx2x.h b/drivers/net/bnx2x/bnx2x.h
index 9eea225decaf..d255428122fc 100644
--- a/drivers/net/bnx2x/bnx2x.h
+++ b/drivers/net/bnx2x/bnx2x.h
@@ -20,8 +20,8 @@
20 * (you will need to reboot afterwards) */ 20 * (you will need to reboot afterwards) */
21/* #define BNX2X_STOP_ON_ERROR */ 21/* #define BNX2X_STOP_ON_ERROR */
22 22
23#define DRV_MODULE_VERSION "1.60.00-3" 23#define DRV_MODULE_VERSION "1.60.01-0"
24#define DRV_MODULE_RELDATE "2010/10/19" 24#define DRV_MODULE_RELDATE "2010/11/12"
25#define BNX2X_BC_VER 0x040200 25#define BNX2X_BC_VER 0x040200
26 26
27#define BNX2X_MULTI_QUEUE 27#define BNX2X_MULTI_QUEUE
diff --git a/drivers/net/bnx2x/bnx2x_cmn.c b/drivers/net/bnx2x/bnx2x_cmn.c
index 459614d2d7bc..0af361e4e3d1 100644
--- a/drivers/net/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/bnx2x/bnx2x_cmn.c
@@ -1680,7 +1680,7 @@ static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
1680 rc = XMIT_PLAIN; 1680 rc = XMIT_PLAIN;
1681 1681
1682 else { 1682 else {
1683 if (skb->protocol == htons(ETH_P_IPV6)) { 1683 if (vlan_get_protocol(skb) == htons(ETH_P_IPV6)) {
1684 rc = XMIT_CSUM_V6; 1684 rc = XMIT_CSUM_V6;
1685 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) 1685 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
1686 rc |= XMIT_CSUM_TCP; 1686 rc |= XMIT_CSUM_TCP;
@@ -1782,15 +1782,15 @@ exit_lbl:
1782} 1782}
1783#endif 1783#endif
1784 1784
1785static inline void bnx2x_set_pbd_gso_e2(struct sk_buff *skb, 1785static inline void bnx2x_set_pbd_gso_e2(struct sk_buff *skb, u32 *parsing_data,
1786 struct eth_tx_parse_bd_e2 *pbd, 1786 u32 xmit_type)
1787 u32 xmit_type)
1788{ 1787{
1789 pbd->parsing_data |= cpu_to_le16(skb_shinfo(skb)->gso_size) << 1788 *parsing_data |= (skb_shinfo(skb)->gso_size <<
1790 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT; 1789 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
1790 ETH_TX_PARSE_BD_E2_LSO_MSS;
1791 if ((xmit_type & XMIT_GSO_V6) && 1791 if ((xmit_type & XMIT_GSO_V6) &&
1792 (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6)) 1792 (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
1793 pbd->parsing_data |= ETH_TX_PARSE_BD_E2_IPV6_WITH_EXT_HDR; 1793 *parsing_data |= ETH_TX_PARSE_BD_E2_IPV6_WITH_EXT_HDR;
1794} 1794}
1795 1795
1796/** 1796/**
@@ -1835,15 +1835,15 @@ static inline void bnx2x_set_pbd_gso(struct sk_buff *skb,
1835 * @return header len 1835 * @return header len
1836 */ 1836 */
1837static inline u8 bnx2x_set_pbd_csum_e2(struct bnx2x *bp, struct sk_buff *skb, 1837static inline u8 bnx2x_set_pbd_csum_e2(struct bnx2x *bp, struct sk_buff *skb,
1838 struct eth_tx_parse_bd_e2 *pbd, 1838 u32 *parsing_data, u32 xmit_type)
1839 u32 xmit_type)
1840{ 1839{
1841 pbd->parsing_data |= cpu_to_le16(tcp_hdrlen(skb)/4) << 1840 *parsing_data |= ((tcp_hdrlen(skb)/4) <<
1842 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT; 1841 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
1842 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW;
1843 1843
1844 pbd->parsing_data |= cpu_to_le16(((unsigned char *)tcp_hdr(skb) - 1844 *parsing_data |= ((((u8 *)tcp_hdr(skb) - skb->data) / 2) <<
1845 skb->data) / 2) << 1845 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W_SHIFT) &
1846 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W_SHIFT; 1846 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W;
1847 1847
1848 return skb_transport_header(skb) + tcp_hdrlen(skb) - skb->data; 1848 return skb_transport_header(skb) + tcp_hdrlen(skb) - skb->data;
1849} 1849}
@@ -1912,6 +1912,7 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
1912 struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL; 1912 struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL;
1913 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL; 1913 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
1914 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL; 1914 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
1915 u32 pbd_e2_parsing_data = 0;
1915 u16 pkt_prod, bd_prod; 1916 u16 pkt_prod, bd_prod;
1916 int nbd, fp_index; 1917 int nbd, fp_index;
1917 dma_addr_t mapping; 1918 dma_addr_t mapping;
@@ -2033,8 +2034,9 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
2033 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2)); 2034 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
2034 /* Set PBD in checksum offload case */ 2035 /* Set PBD in checksum offload case */
2035 if (xmit_type & XMIT_CSUM) 2036 if (xmit_type & XMIT_CSUM)
2036 hlen = bnx2x_set_pbd_csum_e2(bp, 2037 hlen = bnx2x_set_pbd_csum_e2(bp, skb,
2037 skb, pbd_e2, xmit_type); 2038 &pbd_e2_parsing_data,
2039 xmit_type);
2038 } else { 2040 } else {
2039 pbd_e1x = &fp->tx_desc_ring[bd_prod].parse_bd_e1x; 2041 pbd_e1x = &fp->tx_desc_ring[bd_prod].parse_bd_e1x;
2040 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x)); 2042 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
@@ -2076,10 +2078,18 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
2076 bd_prod = bnx2x_tx_split(bp, fp, tx_buf, &tx_start_bd, 2078 bd_prod = bnx2x_tx_split(bp, fp, tx_buf, &tx_start_bd,
2077 hlen, bd_prod, ++nbd); 2079 hlen, bd_prod, ++nbd);
2078 if (CHIP_IS_E2(bp)) 2080 if (CHIP_IS_E2(bp))
2079 bnx2x_set_pbd_gso_e2(skb, pbd_e2, xmit_type); 2081 bnx2x_set_pbd_gso_e2(skb, &pbd_e2_parsing_data,
2082 xmit_type);
2080 else 2083 else
2081 bnx2x_set_pbd_gso(skb, pbd_e1x, xmit_type); 2084 bnx2x_set_pbd_gso(skb, pbd_e1x, xmit_type);
2082 } 2085 }
2086
2087 /* Set the PBD's parsing_data field if not zero
2088 * (for the chips newer than 57711).
2089 */
2090 if (pbd_e2_parsing_data)
2091 pbd_e2->parsing_data = cpu_to_le32(pbd_e2_parsing_data);
2092
2083 tx_data_bd = (struct eth_tx_bd *)tx_start_bd; 2093 tx_data_bd = (struct eth_tx_bd *)tx_start_bd;
2084 2094
2085 /* Handle fragmented skb */ 2095 /* Handle fragmented skb */
diff --git a/drivers/net/bnx2x/bnx2x_hsi.h b/drivers/net/bnx2x/bnx2x_hsi.h
index 18c8e23a0e82..4cfd4e9b5586 100644
--- a/drivers/net/bnx2x/bnx2x_hsi.h
+++ b/drivers/net/bnx2x/bnx2x_hsi.h
@@ -244,7 +244,14 @@ struct port_hw_cfg { /* port 0: 0x12c port 1: 0x2bc */
244 244
245 u16 xgxs_config_tx[4]; /* 0x1A0 */ 245 u16 xgxs_config_tx[4]; /* 0x1A0 */
246 246
247 u32 Reserved1[57]; /* 0x1A8 */ 247 u32 Reserved1[56]; /* 0x1A8 */
248 u32 default_cfg; /* 0x288 */
249 /* Enable BAM on KR */
250#define PORT_HW_CFG_ENABLE_BAM_ON_KR_MASK 0x00100000
251#define PORT_HW_CFG_ENABLE_BAM_ON_KR_SHIFT 20
252#define PORT_HW_CFG_ENABLE_BAM_ON_KR_DISABLED 0x00000000
253#define PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED 0x00100000
254
248 u32 speed_capability_mask2; /* 0x28C */ 255 u32 speed_capability_mask2; /* 0x28C */
249#define PORT_HW_CFG_SPEED_CAPABILITY2_D3_MASK 0x0000FFFF 256#define PORT_HW_CFG_SPEED_CAPABILITY2_D3_MASK 0x0000FFFF
250#define PORT_HW_CFG_SPEED_CAPABILITY2_D3_SHIFT 0 257#define PORT_HW_CFG_SPEED_CAPABILITY2_D3_SHIFT 0
diff --git a/drivers/net/bnx2x/bnx2x_init_ops.h b/drivers/net/bnx2x/bnx2x_init_ops.h
index a306b0e46b61..66df29fcf751 100644
--- a/drivers/net/bnx2x/bnx2x_init_ops.h
+++ b/drivers/net/bnx2x/bnx2x_init_ops.h
@@ -838,7 +838,7 @@ static void bnx2x_qm_init_ptr_table(struct bnx2x *bp, int qm_cid_count,
838/**************************************************************************** 838/****************************************************************************
839* SRC initializations 839* SRC initializations
840****************************************************************************/ 840****************************************************************************/
841 841#ifdef BCM_CNIC
842/* called during init func stage */ 842/* called during init func stage */
843static void bnx2x_src_init_t2(struct bnx2x *bp, struct src_ent *t2, 843static void bnx2x_src_init_t2(struct bnx2x *bp, struct src_ent *t2,
844 dma_addr_t t2_mapping, int src_cid_count) 844 dma_addr_t t2_mapping, int src_cid_count)
@@ -862,5 +862,5 @@ static void bnx2x_src_init_t2(struct bnx2x *bp, struct src_ent *t2,
862 U64_HI((u64)t2_mapping + 862 U64_HI((u64)t2_mapping +
863 (src_cid_count-1) * sizeof(struct src_ent))); 863 (src_cid_count-1) * sizeof(struct src_ent)));
864} 864}
865 865#endif
866#endif /* BNX2X_INIT_OPS_H */ 866#endif /* BNX2X_INIT_OPS_H */
diff --git a/drivers/net/bnx2x/bnx2x_link.c b/drivers/net/bnx2x/bnx2x_link.c
index 2326774df843..580919619252 100644
--- a/drivers/net/bnx2x/bnx2x_link.c
+++ b/drivers/net/bnx2x/bnx2x_link.c
@@ -610,7 +610,7 @@ static u8 bnx2x_bmac_enable(struct link_params *params,
610 /* reset and unreset the BigMac */ 610 /* reset and unreset the BigMac */
611 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 611 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
612 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port)); 612 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
613 udelay(10); 613 msleep(1);
614 614
615 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 615 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
616 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port)); 616 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
@@ -3525,13 +3525,19 @@ static u8 bnx2x_8073_config_init(struct bnx2x_phy *phy,
3525 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1); 3525 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
3526 3526
3527 /* Enable CL37 BAM */ 3527 /* Enable CL37 BAM */
3528 bnx2x_cl45_read(bp, phy, 3528 if (REG_RD(bp, params->shmem_base +
3529 MDIO_AN_DEVAD, 3529 offsetof(struct shmem_region, dev_info.
3530 MDIO_AN_REG_8073_BAM, &val); 3530 port_hw_config[params->port].default_cfg)) &
3531 bnx2x_cl45_write(bp, phy, 3531 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
3532 MDIO_AN_DEVAD,
3533 MDIO_AN_REG_8073_BAM, val | 1);
3534 3532
3533 bnx2x_cl45_read(bp, phy,
3534 MDIO_AN_DEVAD,
3535 MDIO_AN_REG_8073_BAM, &val);
3536 bnx2x_cl45_write(bp, phy,
3537 MDIO_AN_DEVAD,
3538 MDIO_AN_REG_8073_BAM, val | 1);
3539 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
3540 }
3535 if (params->loopback_mode == LOOPBACK_EXT) { 3541 if (params->loopback_mode == LOOPBACK_EXT) {
3536 bnx2x_807x_force_10G(bp, phy); 3542 bnx2x_807x_force_10G(bp, phy);
3537 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n"); 3543 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
@@ -5302,7 +5308,7 @@ static u8 bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
5302{ 5308{
5303 struct bnx2x *bp = params->bp; 5309 struct bnx2x *bp = params->bp;
5304 u16 autoneg_val, an_1000_val, an_10_100_val; 5310 u16 autoneg_val, an_1000_val, an_10_100_val;
5305 bnx2x_wait_reset_complete(bp, phy); 5311
5306 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4, 5312 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
5307 1 << NIG_LATCH_BC_ENABLE_MI_INT); 5313 1 << NIG_LATCH_BC_ENABLE_MI_INT);
5308 5314
@@ -5431,6 +5437,7 @@ static u8 bnx2x_8481_config_init(struct bnx2x_phy *phy,
5431 5437
5432 /* HW reset */ 5438 /* HW reset */
5433 bnx2x_ext_phy_hw_reset(bp, params->port); 5439 bnx2x_ext_phy_hw_reset(bp, params->port);
5440 bnx2x_wait_reset_complete(bp, phy);
5434 5441
5435 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15); 5442 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
5436 return bnx2x_848xx_cmn_config_init(phy, params, vars); 5443 return bnx2x_848xx_cmn_config_init(phy, params, vars);
@@ -5441,7 +5448,7 @@ static u8 bnx2x_848x3_config_init(struct bnx2x_phy *phy,
5441 struct link_vars *vars) 5448 struct link_vars *vars)
5442{ 5449{
5443 struct bnx2x *bp = params->bp; 5450 struct bnx2x *bp = params->bp;
5444 u8 port = params->port, initialize = 1; 5451 u8 port, initialize = 1;
5445 u16 val; 5452 u16 val;
5446 u16 temp; 5453 u16 temp;
5447 u32 actual_phy_selection; 5454 u32 actual_phy_selection;
@@ -5450,11 +5457,16 @@ static u8 bnx2x_848x3_config_init(struct bnx2x_phy *phy,
5450 /* This is just for MDIO_CTL_REG_84823_MEDIA register. */ 5457 /* This is just for MDIO_CTL_REG_84823_MEDIA register. */
5451 5458
5452 msleep(1); 5459 msleep(1);
5460 if (CHIP_IS_E2(bp))
5461 port = BP_PATH(bp);
5462 else
5463 port = params->port;
5453 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3, 5464 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
5454 MISC_REGISTERS_GPIO_OUTPUT_HIGH, 5465 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
5455 port); 5466 port);
5456 msleep(200); /* 100 is not enough */ 5467 bnx2x_wait_reset_complete(bp, phy);
5457 5468 /* Wait for GPHY to come out of reset */
5469 msleep(50);
5458 /* BCM84823 requires that XGXS links up first @ 10G for normal 5470 /* BCM84823 requires that XGXS links up first @ 10G for normal
5459 behavior */ 5471 behavior */
5460 temp = vars->line_speed; 5472 temp = vars->line_speed;
@@ -5625,7 +5637,11 @@ static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
5625 struct link_params *params) 5637 struct link_params *params)
5626{ 5638{
5627 struct bnx2x *bp = params->bp; 5639 struct bnx2x *bp = params->bp;
5628 u8 port = params->port; 5640 u8 port;
5641 if (CHIP_IS_E2(bp))
5642 port = BP_PATH(bp);
5643 else
5644 port = params->port;
5629 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3, 5645 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
5630 MISC_REGISTERS_GPIO_OUTPUT_LOW, 5646 MISC_REGISTERS_GPIO_OUTPUT_LOW,
5631 port); 5647 port);
@@ -6928,7 +6944,7 @@ u8 bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
6928 u8 reset_ext_phy) 6944 u8 reset_ext_phy)
6929{ 6945{
6930 struct bnx2x *bp = params->bp; 6946 struct bnx2x *bp = params->bp;
6931 u8 phy_index, port = params->port; 6947 u8 phy_index, port = params->port, clear_latch_ind = 0;
6932 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port); 6948 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
6933 /* disable attentions */ 6949 /* disable attentions */
6934 vars->link_status = 0; 6950 vars->link_status = 0;
@@ -6966,9 +6982,18 @@ u8 bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
6966 params->phy[phy_index].link_reset( 6982 params->phy[phy_index].link_reset(
6967 &params->phy[phy_index], 6983 &params->phy[phy_index],
6968 params); 6984 params);
6985 if (params->phy[phy_index].flags &
6986 FLAGS_REARM_LATCH_SIGNAL)
6987 clear_latch_ind = 1;
6969 } 6988 }
6970 } 6989 }
6971 6990
6991 if (clear_latch_ind) {
6992 /* Clear latching indication */
6993 bnx2x_rearm_latch_signal(bp, port, 0);
6994 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
6995 1 << NIG_LATCH_BC_ENABLE_MI_INT);
6996 }
6972 if (params->phy[INT_PHY].link_reset) 6997 if (params->phy[INT_PHY].link_reset)
6973 params->phy[INT_PHY].link_reset( 6998 params->phy[INT_PHY].link_reset(
6974 &params->phy[INT_PHY], params); 6999 &params->phy[INT_PHY], params);
@@ -6999,6 +7024,7 @@ static u8 bnx2x_8073_common_init_phy(struct bnx2x *bp,
6999 s8 port; 7024 s8 port;
7000 s8 port_of_path = 0; 7025 s8 port_of_path = 0;
7001 7026
7027 bnx2x_ext_phy_hw_reset(bp, 0);
7002 /* PART1 - Reset both phys */ 7028 /* PART1 - Reset both phys */
7003 for (port = PORT_MAX - 1; port >= PORT_0; port--) { 7029 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
7004 u32 shmem_base, shmem2_base; 7030 u32 shmem_base, shmem2_base;
@@ -7021,7 +7047,8 @@ static u8 bnx2x_8073_common_init_phy(struct bnx2x *bp,
7021 return -EINVAL; 7047 return -EINVAL;
7022 } 7048 }
7023 /* disable attentions */ 7049 /* disable attentions */
7024 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 7050 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
7051 port_of_path*4,
7025 (NIG_MASK_XGXS0_LINK_STATUS | 7052 (NIG_MASK_XGXS0_LINK_STATUS |
7026 NIG_MASK_XGXS0_LINK10G | 7053 NIG_MASK_XGXS0_LINK10G |
7027 NIG_MASK_SERDES0_LINK_STATUS | 7054 NIG_MASK_SERDES0_LINK_STATUS |
@@ -7132,7 +7159,7 @@ static u8 bnx2x_8726_common_init_phy(struct bnx2x *bp,
7132 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT))); 7159 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
7133 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val); 7160 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
7134 7161
7135 bnx2x_ext_phy_hw_reset(bp, 1); 7162 bnx2x_ext_phy_hw_reset(bp, 0);
7136 msleep(5); 7163 msleep(5);
7137 for (port = 0; port < PORT_MAX; port++) { 7164 for (port = 0; port < PORT_MAX; port++) {
7138 u32 shmem_base, shmem2_base; 7165 u32 shmem_base, shmem2_base;
diff --git a/drivers/net/bnx2x/bnx2x_main.c b/drivers/net/bnx2x/bnx2x_main.c
index 4a6f0eac8b12..be52edcf8346 100644
--- a/drivers/net/bnx2x/bnx2x_main.c
+++ b/drivers/net/bnx2x/bnx2x_main.c
@@ -9064,7 +9064,7 @@ static int __devinit bnx2x_init_one(struct pci_dev *pdev,
9064 default: 9064 default:
9065 pr_err("Unknown board_type (%ld), aborting\n", 9065 pr_err("Unknown board_type (%ld), aborting\n",
9066 ent->driver_data); 9066 ent->driver_data);
9067 return ENODEV; 9067 return -ENODEV;
9068 } 9068 }
9069 9069
9070 cid_count += CNIC_CONTEXT_USE; 9070 cid_count += CNIC_CONTEXT_USE;
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index bdb68a600382..d0ea760ce419 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -171,7 +171,7 @@ MODULE_PARM_DESC(resend_igmp, "Number of IGMP membership reports to send on link
171/*----------------------------- Global variables ----------------------------*/ 171/*----------------------------- Global variables ----------------------------*/
172 172
173#ifdef CONFIG_NET_POLL_CONTROLLER 173#ifdef CONFIG_NET_POLL_CONTROLLER
174cpumask_var_t netpoll_block_tx; 174atomic_t netpoll_block_tx = ATOMIC_INIT(0);
175#endif 175#endif
176 176
177static const char * const version = 177static const char * const version =
@@ -878,8 +878,10 @@ static void __bond_resend_igmp_join_requests(struct net_device *dev)
878 rcu_read_lock(); 878 rcu_read_lock();
879 in_dev = __in_dev_get_rcu(dev); 879 in_dev = __in_dev_get_rcu(dev);
880 if (in_dev) { 880 if (in_dev) {
881 read_lock(&in_dev->mc_list_lock);
881 for (im = in_dev->mc_list; im; im = im->next) 882 for (im = in_dev->mc_list; im; im = im->next)
882 ip_mc_rejoin_group(im); 883 ip_mc_rejoin_group(im);
884 read_unlock(&in_dev->mc_list_lock);
883 } 885 }
884 886
885 rcu_read_unlock(); 887 rcu_read_unlock();
@@ -1574,7 +1576,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1574 1576
1575 /* If this is the first slave, then we need to set the master's hardware 1577 /* If this is the first slave, then we need to set the master's hardware
1576 * address to be the same as the slave's. */ 1578 * address to be the same as the slave's. */
1577 if (bond->slave_cnt == 0) 1579 if (is_zero_ether_addr(bond->dev->dev_addr))
1578 memcpy(bond->dev->dev_addr, slave_dev->dev_addr, 1580 memcpy(bond->dev->dev_addr, slave_dev->dev_addr,
1579 slave_dev->addr_len); 1581 slave_dev->addr_len);
1580 1582
@@ -5297,13 +5299,6 @@ static int __init bonding_init(void)
5297 if (res) 5299 if (res)
5298 goto out; 5300 goto out;
5299 5301
5300#ifdef CONFIG_NET_POLL_CONTROLLER
5301 if (!alloc_cpumask_var(&netpoll_block_tx, GFP_KERNEL)) {
5302 res = -ENOMEM;
5303 goto out;
5304 }
5305#endif
5306
5307 res = register_pernet_subsys(&bond_net_ops); 5302 res = register_pernet_subsys(&bond_net_ops);
5308 if (res) 5303 if (res)
5309 goto out; 5304 goto out;
@@ -5332,9 +5327,6 @@ err:
5332 rtnl_link_unregister(&bond_link_ops); 5327 rtnl_link_unregister(&bond_link_ops);
5333err_link: 5328err_link:
5334 unregister_pernet_subsys(&bond_net_ops); 5329 unregister_pernet_subsys(&bond_net_ops);
5335#ifdef CONFIG_NET_POLL_CONTROLLER
5336 free_cpumask_var(netpoll_block_tx);
5337#endif
5338 goto out; 5330 goto out;
5339 5331
5340} 5332}
@@ -5351,7 +5343,10 @@ static void __exit bonding_exit(void)
5351 unregister_pernet_subsys(&bond_net_ops); 5343 unregister_pernet_subsys(&bond_net_ops);
5352 5344
5353#ifdef CONFIG_NET_POLL_CONTROLLER 5345#ifdef CONFIG_NET_POLL_CONTROLLER
5354 free_cpumask_var(netpoll_block_tx); 5346 /*
5347 * Make sure we don't have an imbalance on our netpoll blocking
5348 */
5349 WARN_ON(atomic_read(&netpoll_block_tx));
5355#endif 5350#endif
5356} 5351}
5357 5352
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 4eedb12df6ca..c2f081352a03 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -119,26 +119,22 @@
119 119
120 120
121#ifdef CONFIG_NET_POLL_CONTROLLER 121#ifdef CONFIG_NET_POLL_CONTROLLER
122extern cpumask_var_t netpoll_block_tx; 122extern atomic_t netpoll_block_tx;
123 123
124static inline void block_netpoll_tx(void) 124static inline void block_netpoll_tx(void)
125{ 125{
126 preempt_disable(); 126 atomic_inc(&netpoll_block_tx);
127 BUG_ON(cpumask_test_and_set_cpu(smp_processor_id(),
128 netpoll_block_tx));
129} 127}
130 128
131static inline void unblock_netpoll_tx(void) 129static inline void unblock_netpoll_tx(void)
132{ 130{
133 BUG_ON(!cpumask_test_and_clear_cpu(smp_processor_id(), 131 atomic_dec(&netpoll_block_tx);
134 netpoll_block_tx));
135 preempt_enable();
136} 132}
137 133
138static inline int is_netpoll_tx_blocked(struct net_device *dev) 134static inline int is_netpoll_tx_blocked(struct net_device *dev)
139{ 135{
140 if (unlikely(dev->priv_flags & IFF_IN_NETPOLL)) 136 if (unlikely(dev->priv_flags & IFF_IN_NETPOLL))
141 return cpumask_test_cpu(smp_processor_id(), netpoll_block_tx); 137 return atomic_read(&netpoll_block_tx);
142 return 0; 138 return 0;
143} 139}
144#else 140#else
diff --git a/drivers/net/caif/caif_shm_u5500.c b/drivers/net/caif/caif_shm_u5500.c
index 1cd90da86f13..32b1c6fb2de1 100644
--- a/drivers/net/caif/caif_shm_u5500.c
+++ b/drivers/net/caif/caif_shm_u5500.c
@@ -5,7 +5,7 @@
5 * License terms: GNU General Public License (GPL) version 2 5 * License terms: GNU General Public License (GPL) version 2
6 */ 6 */
7 7
8#define pr_fmt(fmt) KBUILD_MODNAME ":" __func__ "():" fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ":" fmt
9 9
10#include <linux/version.h> 10#include <linux/version.h>
11#include <linux/init.h> 11#include <linux/init.h>
diff --git a/drivers/net/caif/caif_shmcore.c b/drivers/net/caif/caif_shmcore.c
index 19f9c0656667..80511167f35b 100644
--- a/drivers/net/caif/caif_shmcore.c
+++ b/drivers/net/caif/caif_shmcore.c
@@ -6,7 +6,7 @@
6 * License terms: GNU General Public License (GPL) version 2 6 * License terms: GNU General Public License (GPL) version 2
7 */ 7 */
8 8
9#define pr_fmt(fmt) KBUILD_MODNAME ":" __func__ "():" fmt 9#define pr_fmt(fmt) KBUILD_MODNAME ":" fmt
10 10
11#include <linux/spinlock.h> 11#include <linux/spinlock.h>
12#include <linux/sched.h> 12#include <linux/sched.h>
diff --git a/drivers/net/caif/caif_spi.c b/drivers/net/caif/caif_spi.c
index 8427533fe313..20da1996d354 100644
--- a/drivers/net/caif/caif_spi.c
+++ b/drivers/net/caif/caif_spi.c
@@ -33,6 +33,9 @@ MODULE_LICENSE("GPL");
33MODULE_AUTHOR("Daniel Martensson<daniel.martensson@stericsson.com>"); 33MODULE_AUTHOR("Daniel Martensson<daniel.martensson@stericsson.com>");
34MODULE_DESCRIPTION("CAIF SPI driver"); 34MODULE_DESCRIPTION("CAIF SPI driver");
35 35
36/* Returns the number of padding bytes for alignment. */
37#define PAD_POW2(x, pow) ((((x)&((pow)-1))==0) ? 0 : (((pow)-((x)&((pow)-1)))))
38
36static int spi_loop; 39static int spi_loop;
37module_param(spi_loop, bool, S_IRUGO); 40module_param(spi_loop, bool, S_IRUGO);
38MODULE_PARM_DESC(spi_loop, "SPI running in loopback mode."); 41MODULE_PARM_DESC(spi_loop, "SPI running in loopback mode.");
@@ -41,7 +44,10 @@ MODULE_PARM_DESC(spi_loop, "SPI running in loopback mode.");
41module_param(spi_frm_align, int, S_IRUGO); 44module_param(spi_frm_align, int, S_IRUGO);
42MODULE_PARM_DESC(spi_frm_align, "SPI frame alignment."); 45MODULE_PARM_DESC(spi_frm_align, "SPI frame alignment.");
43 46
44/* SPI padding options. */ 47/*
48 * SPI padding options.
49 * Warning: must be a base of 2 (& operation used) and can not be zero !
50 */
45module_param(spi_up_head_align, int, S_IRUGO); 51module_param(spi_up_head_align, int, S_IRUGO);
46MODULE_PARM_DESC(spi_up_head_align, "SPI uplink head alignment."); 52MODULE_PARM_DESC(spi_up_head_align, "SPI uplink head alignment.");
47 53
@@ -240,15 +246,13 @@ static ssize_t dbgfs_frame(struct file *file, char __user *user_buf,
240static const struct file_operations dbgfs_state_fops = { 246static const struct file_operations dbgfs_state_fops = {
241 .open = dbgfs_open, 247 .open = dbgfs_open,
242 .read = dbgfs_state, 248 .read = dbgfs_state,
243 .owner = THIS_MODULE, 249 .owner = THIS_MODULE
244 .llseek = default_llseek,
245}; 250};
246 251
247static const struct file_operations dbgfs_frame_fops = { 252static const struct file_operations dbgfs_frame_fops = {
248 .open = dbgfs_open, 253 .open = dbgfs_open,
249 .read = dbgfs_frame, 254 .read = dbgfs_frame,
250 .owner = THIS_MODULE, 255 .owner = THIS_MODULE
251 .llseek = default_llseek,
252}; 256};
253 257
254static inline void dev_debugfs_add(struct cfspi *cfspi) 258static inline void dev_debugfs_add(struct cfspi *cfspi)
@@ -337,6 +341,9 @@ int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len)
337 u8 *dst = buf; 341 u8 *dst = buf;
338 caif_assert(buf); 342 caif_assert(buf);
339 343
344 if (cfspi->slave && !cfspi->slave_talked)
345 cfspi->slave_talked = true;
346
340 do { 347 do {
341 struct sk_buff *skb; 348 struct sk_buff *skb;
342 struct caif_payload_info *info; 349 struct caif_payload_info *info;
@@ -357,8 +364,8 @@ int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len)
357 * Compute head offset i.e. number of bytes to add to 364 * Compute head offset i.e. number of bytes to add to
358 * get the start of the payload aligned. 365 * get the start of the payload aligned.
359 */ 366 */
360 if (spi_up_head_align) { 367 if (spi_up_head_align > 1) {
361 spad = 1 + ((info->hdr_len + 1) & spi_up_head_align); 368 spad = 1 + PAD_POW2((info->hdr_len + 1), spi_up_head_align);
362 *dst = (u8)(spad - 1); 369 *dst = (u8)(spad - 1);
363 dst += spad; 370 dst += spad;
364 } 371 }
@@ -373,7 +380,7 @@ int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len)
373 * Compute tail offset i.e. number of bytes to add to 380 * Compute tail offset i.e. number of bytes to add to
374 * get the complete CAIF frame aligned. 381 * get the complete CAIF frame aligned.
375 */ 382 */
376 epad = (skb->len + spad) & spi_up_tail_align; 383 epad = PAD_POW2((skb->len + spad), spi_up_tail_align);
377 dst += epad; 384 dst += epad;
378 385
379 dev_kfree_skb(skb); 386 dev_kfree_skb(skb);
@@ -417,14 +424,14 @@ int cfspi_xmitlen(struct cfspi *cfspi)
417 * Compute head offset i.e. number of bytes to add to 424 * Compute head offset i.e. number of bytes to add to
418 * get the start of the payload aligned. 425 * get the start of the payload aligned.
419 */ 426 */
420 if (spi_up_head_align) 427 if (spi_up_head_align > 1)
421 spad = 1 + ((info->hdr_len + 1) & spi_up_head_align); 428 spad = 1 + PAD_POW2((info->hdr_len + 1), spi_up_head_align);
422 429
423 /* 430 /*
424 * Compute tail offset i.e. number of bytes to add to 431 * Compute tail offset i.e. number of bytes to add to
425 * get the complete CAIF frame aligned. 432 * get the complete CAIF frame aligned.
426 */ 433 */
427 epad = (skb->len + spad) & spi_up_tail_align; 434 epad = PAD_POW2((skb->len + spad), spi_up_tail_align);
428 435
429 if ((skb->len + spad + epad + frm_len) <= CAIF_MAX_SPI_FRAME) { 436 if ((skb->len + spad + epad + frm_len) <= CAIF_MAX_SPI_FRAME) {
430 skb_queue_tail(&cfspi->chead, skb); 437 skb_queue_tail(&cfspi->chead, skb);
@@ -433,6 +440,7 @@ int cfspi_xmitlen(struct cfspi *cfspi)
433 } else { 440 } else {
434 /* Put back packet. */ 441 /* Put back packet. */
435 skb_queue_head(&cfspi->qhead, skb); 442 skb_queue_head(&cfspi->qhead, skb);
443 break;
436 } 444 }
437 } while (pkts <= CAIF_MAX_SPI_PKTS); 445 } while (pkts <= CAIF_MAX_SPI_PKTS);
438 446
@@ -453,6 +461,15 @@ static void cfspi_ss_cb(bool assert, struct cfspi_ifc *ifc)
453{ 461{
454 struct cfspi *cfspi = (struct cfspi *)ifc->priv; 462 struct cfspi *cfspi = (struct cfspi *)ifc->priv;
455 463
464 /*
465 * The slave device is the master on the link. Interrupts before the
466 * slave has transmitted are considered spurious.
467 */
468 if (cfspi->slave && !cfspi->slave_talked) {
469 printk(KERN_WARNING "CFSPI: Spurious SS interrupt.\n");
470 return;
471 }
472
456 if (!in_interrupt()) 473 if (!in_interrupt())
457 spin_lock(&cfspi->lock); 474 spin_lock(&cfspi->lock);
458 if (assert) { 475 if (assert) {
@@ -465,7 +482,8 @@ static void cfspi_ss_cb(bool assert, struct cfspi_ifc *ifc)
465 spin_unlock(&cfspi->lock); 482 spin_unlock(&cfspi->lock);
466 483
467 /* Wake up the xfer thread. */ 484 /* Wake up the xfer thread. */
468 wake_up_interruptible(&cfspi->wait); 485 if (assert)
486 wake_up_interruptible(&cfspi->wait);
469} 487}
470 488
471static void cfspi_xfer_done_cb(struct cfspi_ifc *ifc) 489static void cfspi_xfer_done_cb(struct cfspi_ifc *ifc)
@@ -523,7 +541,7 @@ int cfspi_rxfrm(struct cfspi *cfspi, u8 *buf, size_t len)
523 * Compute head offset i.e. number of bytes added to 541 * Compute head offset i.e. number of bytes added to
524 * get the start of the payload aligned. 542 * get the start of the payload aligned.
525 */ 543 */
526 if (spi_down_head_align) { 544 if (spi_down_head_align > 1) {
527 spad = 1 + *src; 545 spad = 1 + *src;
528 src += spad; 546 src += spad;
529 } 547 }
@@ -564,7 +582,7 @@ int cfspi_rxfrm(struct cfspi *cfspi, u8 *buf, size_t len)
564 * Compute tail offset i.e. number of bytes added to 582 * Compute tail offset i.e. number of bytes added to
565 * get the complete CAIF frame aligned. 583 * get the complete CAIF frame aligned.
566 */ 584 */
567 epad = (pkt_len + spad) & spi_down_tail_align; 585 epad = PAD_POW2((pkt_len + spad), spi_down_tail_align);
568 src += epad; 586 src += epad;
569 } while ((src - buf) < len); 587 } while ((src - buf) < len);
570 588
@@ -617,19 +635,28 @@ int cfspi_spi_probe(struct platform_device *pdev)
617 635
618 ndev = alloc_netdev(sizeof(struct cfspi), 636 ndev = alloc_netdev(sizeof(struct cfspi),
619 "cfspi%d", cfspi_setup); 637 "cfspi%d", cfspi_setup);
620 if (!dev) 638 if (!ndev)
621 return -ENODEV; 639 return -ENOMEM;
622 640
623 cfspi = netdev_priv(ndev); 641 cfspi = netdev_priv(ndev);
624 netif_stop_queue(ndev); 642 netif_stop_queue(ndev);
625 cfspi->ndev = ndev; 643 cfspi->ndev = ndev;
626 cfspi->pdev = pdev; 644 cfspi->pdev = pdev;
627 645
628 /* Set flow info */ 646 /* Set flow info. */
629 cfspi->flow_off_sent = 0; 647 cfspi->flow_off_sent = 0;
630 cfspi->qd_low_mark = LOW_WATER_MARK; 648 cfspi->qd_low_mark = LOW_WATER_MARK;
631 cfspi->qd_high_mark = HIGH_WATER_MARK; 649 cfspi->qd_high_mark = HIGH_WATER_MARK;
632 650
651 /* Set slave info. */
652 if (!strncmp(cfspi_spi_driver.driver.name, "cfspi_sspi", 10)) {
653 cfspi->slave = true;
654 cfspi->slave_talked = false;
655 } else {
656 cfspi->slave = false;
657 cfspi->slave_talked = false;
658 }
659
633 /* Assign the SPI device. */ 660 /* Assign the SPI device. */
634 cfspi->dev = dev; 661 cfspi->dev = dev;
635 /* Assign the device ifc to this SPI interface. */ 662 /* Assign the device ifc to this SPI interface. */
diff --git a/drivers/net/caif/caif_spi_slave.c b/drivers/net/caif/caif_spi_slave.c
index 2111dbfea6fe..1b9943a4edab 100644
--- a/drivers/net/caif/caif_spi_slave.c
+++ b/drivers/net/caif/caif_spi_slave.c
@@ -36,10 +36,15 @@ static inline int forward_to_spi_cmd(struct cfspi *cfspi)
36#endif 36#endif
37 37
38int spi_frm_align = 2; 38int spi_frm_align = 2;
39int spi_up_head_align = 1; 39
40int spi_up_tail_align; 40/*
41int spi_down_head_align = 3; 41 * SPI padding options.
42int spi_down_tail_align = 1; 42 * Warning: must be a base of 2 (& operation used) and can not be zero !
43 */
44int spi_up_head_align = 1 << 1;
45int spi_up_tail_align = 1 << 0;
46int spi_down_head_align = 1 << 2;
47int spi_down_tail_align = 1 << 1;
43 48
44#ifdef CONFIG_DEBUG_FS 49#ifdef CONFIG_DEBUG_FS
45static inline void debugfs_store_prev(struct cfspi *cfspi) 50static inline void debugfs_store_prev(struct cfspi *cfspi)
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
index cee98fa668bd..7ef83d06f7ed 100644
--- a/drivers/net/can/at91_can.c
+++ b/drivers/net/can/at91_can.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * at91_can.c - CAN network driver for AT91 SoC CAN controller 2 * at91_can.c - CAN network driver for AT91 SoC CAN controller
3 * 3 *
4 * (C) 2007 by Hans J. Koch <hjk@linutronix.de> 4 * (C) 2007 by Hans J. Koch <hjk@hansjkoch.de>
5 * (C) 2008, 2009, 2010 by Marc Kleine-Budde <kernel@pengutronix.de> 5 * (C) 2008, 2009, 2010 by Marc Kleine-Budde <kernel@pengutronix.de>
6 * 6 *
7 * This software may be distributed under the terms of the GNU General 7 * This software may be distributed under the terms of the GNU General
diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c
index 55ec324caaf4..672718261c68 100644
--- a/drivers/net/can/pch_can.c
+++ b/drivers/net/can/pch_can.c
@@ -213,12 +213,12 @@ static DEFINE_PCI_DEVICE_TABLE(pch_pci_tbl) = {
213}; 213};
214MODULE_DEVICE_TABLE(pci, pch_pci_tbl); 214MODULE_DEVICE_TABLE(pci, pch_pci_tbl);
215 215
216static inline void pch_can_bit_set(u32 *addr, u32 mask) 216static inline void pch_can_bit_set(void __iomem *addr, u32 mask)
217{ 217{
218 iowrite32(ioread32(addr) | mask, addr); 218 iowrite32(ioread32(addr) | mask, addr);
219} 219}
220 220
221static inline void pch_can_bit_clear(u32 *addr, u32 mask) 221static inline void pch_can_bit_clear(void __iomem *addr, u32 mask)
222{ 222{
223 iowrite32(ioread32(addr) & ~mask, addr); 223 iowrite32(ioread32(addr) & ~mask, addr);
224} 224}
@@ -1437,7 +1437,7 @@ probe_exit_endev:
1437 return rc; 1437 return rc;
1438} 1438}
1439 1439
1440static struct pci_driver pch_can_pcidev = { 1440static struct pci_driver pch_can_pci_driver = {
1441 .name = "pch_can", 1441 .name = "pch_can",
1442 .id_table = pch_pci_tbl, 1442 .id_table = pch_pci_tbl,
1443 .probe = pch_can_probe, 1443 .probe = pch_can_probe,
@@ -1448,13 +1448,13 @@ static struct pci_driver pch_can_pcidev = {
1448 1448
1449static int __init pch_can_pci_init(void) 1449static int __init pch_can_pci_init(void)
1450{ 1450{
1451 return pci_register_driver(&pch_can_pcidev); 1451 return pci_register_driver(&pch_can_pci_driver);
1452} 1452}
1453module_init(pch_can_pci_init); 1453module_init(pch_can_pci_init);
1454 1454
1455static void __exit pch_can_pci_exit(void) 1455static void __exit pch_can_pci_exit(void)
1456{ 1456{
1457 pci_unregister_driver(&pch_can_pcidev); 1457 pci_unregister_driver(&pch_can_pci_driver);
1458} 1458}
1459module_exit(pch_can_pci_exit); 1459module_exit(pch_can_pci_exit);
1460 1460
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c
index 407d4e272075..046d846c652d 100644
--- a/drivers/net/cxgb3/cxgb3_main.c
+++ b/drivers/net/cxgb3/cxgb3_main.c
@@ -3341,7 +3341,6 @@ static int __devinit init_one(struct pci_dev *pdev,
3341 adapter->name = adapter->port[i]->name; 3341 adapter->name = adapter->port[i]->name;
3342 3342
3343 __set_bit(i, &adapter->registered_device_map); 3343 __set_bit(i, &adapter->registered_device_map);
3344 netif_tx_stop_all_queues(adapter->port[i]);
3345 } 3344 }
3346 } 3345 }
3347 if (!adapter->registered_device_map) { 3346 if (!adapter->registered_device_map) {
diff --git a/drivers/net/cxgb4/cxgb4_main.c b/drivers/net/cxgb4/cxgb4_main.c
index f17703f410b3..f50bc98310f8 100644
--- a/drivers/net/cxgb4/cxgb4_main.c
+++ b/drivers/net/cxgb4/cxgb4_main.c
@@ -3736,7 +3736,6 @@ static int __devinit init_one(struct pci_dev *pdev,
3736 3736
3737 __set_bit(i, &adapter->registered_device_map); 3737 __set_bit(i, &adapter->registered_device_map);
3738 adapter->chan_map[adap2pinfo(adapter, i)->tx_chan] = i; 3738 adapter->chan_map[adap2pinfo(adapter, i)->tx_chan] = i;
3739 netif_tx_stop_all_queues(adapter->port[i]);
3740 } 3739 }
3741 } 3740 }
3742 if (!adapter->registered_device_map) { 3741 if (!adapter->registered_device_map) {
diff --git a/drivers/net/cxgb4/t4_hw.c b/drivers/net/cxgb4/t4_hw.c
index bb813d94aea8..e97521c801ea 100644
--- a/drivers/net/cxgb4/t4_hw.c
+++ b/drivers/net/cxgb4/t4_hw.c
@@ -2408,7 +2408,7 @@ int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
2408 if (index < NEXACT_MAC) 2408 if (index < NEXACT_MAC)
2409 ret++; 2409 ret++;
2410 else if (hash) 2410 else if (hash)
2411 *hash |= (1 << hash_mac_addr(addr[i])); 2411 *hash |= (1ULL << hash_mac_addr(addr[i]));
2412 } 2412 }
2413 return ret; 2413 return ret;
2414} 2414}
diff --git a/drivers/net/cxgb4vf/cxgb4vf_main.c b/drivers/net/cxgb4vf/cxgb4vf_main.c
index 555ecc5a2e93..6bf464afa90e 100644
--- a/drivers/net/cxgb4vf/cxgb4vf_main.c
+++ b/drivers/net/cxgb4vf/cxgb4vf_main.c
@@ -753,7 +753,9 @@ static int cxgb4vf_open(struct net_device *dev)
753 if (err) 753 if (err)
754 return err; 754 return err;
755 set_bit(pi->port_id, &adapter->open_device_map); 755 set_bit(pi->port_id, &adapter->open_device_map);
756 link_start(dev); 756 err = link_start(dev);
757 if (err)
758 return err;
757 netif_tx_start_all_queues(dev); 759 netif_tx_start_all_queues(dev);
758 return 0; 760 return 0;
759} 761}
@@ -814,40 +816,48 @@ static struct net_device_stats *cxgb4vf_get_stats(struct net_device *dev)
814} 816}
815 817
816/* 818/*
817 * Collect up to maxaddrs worth of a netdevice's unicast addresses into an 819 * Collect up to maxaddrs worth of a netdevice's unicast addresses, starting
818 * array of addrss pointers and return the number collected. 820 * at a specified offset within the list, into an array of addrss pointers and
821 * return the number collected.
819 */ 822 */
820static inline int collect_netdev_uc_list_addrs(const struct net_device *dev, 823static inline unsigned int collect_netdev_uc_list_addrs(const struct net_device *dev,
821 const u8 **addr, 824 const u8 **addr,
822 unsigned int maxaddrs) 825 unsigned int offset,
826 unsigned int maxaddrs)
823{ 827{
828 unsigned int index = 0;
824 unsigned int naddr = 0; 829 unsigned int naddr = 0;
825 const struct netdev_hw_addr *ha; 830 const struct netdev_hw_addr *ha;
826 831
827 for_each_dev_addr(dev, ha) { 832 for_each_dev_addr(dev, ha)
828 addr[naddr++] = ha->addr; 833 if (index++ >= offset) {
829 if (naddr >= maxaddrs) 834 addr[naddr++] = ha->addr;
830 break; 835 if (naddr >= maxaddrs)
831 } 836 break;
837 }
832 return naddr; 838 return naddr;
833} 839}
834 840
835/* 841/*
836 * Collect up to maxaddrs worth of a netdevice's multicast addresses into an 842 * Collect up to maxaddrs worth of a netdevice's multicast addresses, starting
837 * array of addrss pointers and return the number collected. 843 * at a specified offset within the list, into an array of addrss pointers and
844 * return the number collected.
838 */ 845 */
839static inline int collect_netdev_mc_list_addrs(const struct net_device *dev, 846static inline unsigned int collect_netdev_mc_list_addrs(const struct net_device *dev,
840 const u8 **addr, 847 const u8 **addr,
841 unsigned int maxaddrs) 848 unsigned int offset,
849 unsigned int maxaddrs)
842{ 850{
851 unsigned int index = 0;
843 unsigned int naddr = 0; 852 unsigned int naddr = 0;
844 const struct netdev_hw_addr *ha; 853 const struct netdev_hw_addr *ha;
845 854
846 netdev_for_each_mc_addr(ha, dev) { 855 netdev_for_each_mc_addr(ha, dev)
847 addr[naddr++] = ha->addr; 856 if (index++ >= offset) {
848 if (naddr >= maxaddrs) 857 addr[naddr++] = ha->addr;
849 break; 858 if (naddr >= maxaddrs)
850 } 859 break;
860 }
851 return naddr; 861 return naddr;
852} 862}
853 863
@@ -860,16 +870,20 @@ static int set_addr_filters(const struct net_device *dev, bool sleep)
860 u64 mhash = 0; 870 u64 mhash = 0;
861 u64 uhash = 0; 871 u64 uhash = 0;
862 bool free = true; 872 bool free = true;
863 u16 filt_idx[7]; 873 unsigned int offset, naddr;
864 const u8 *addr[7]; 874 const u8 *addr[7];
865 int ret, naddr = 0; 875 int ret;
866 const struct port_info *pi = netdev_priv(dev); 876 const struct port_info *pi = netdev_priv(dev);
867 877
868 /* first do the secondary unicast addresses */ 878 /* first do the secondary unicast addresses */
869 naddr = collect_netdev_uc_list_addrs(dev, addr, ARRAY_SIZE(addr)); 879 for (offset = 0; ; offset += naddr) {
870 if (naddr > 0) { 880 naddr = collect_netdev_uc_list_addrs(dev, addr, offset,
881 ARRAY_SIZE(addr));
882 if (naddr == 0)
883 break;
884
871 ret = t4vf_alloc_mac_filt(pi->adapter, pi->viid, free, 885 ret = t4vf_alloc_mac_filt(pi->adapter, pi->viid, free,
872 naddr, addr, filt_idx, &uhash, sleep); 886 naddr, addr, NULL, &uhash, sleep);
873 if (ret < 0) 887 if (ret < 0)
874 return ret; 888 return ret;
875 889
@@ -877,12 +891,17 @@ static int set_addr_filters(const struct net_device *dev, bool sleep)
877 } 891 }
878 892
879 /* next set up the multicast addresses */ 893 /* next set up the multicast addresses */
880 naddr = collect_netdev_mc_list_addrs(dev, addr, ARRAY_SIZE(addr)); 894 for (offset = 0; ; offset += naddr) {
881 if (naddr > 0) { 895 naddr = collect_netdev_mc_list_addrs(dev, addr, offset,
896 ARRAY_SIZE(addr));
897 if (naddr == 0)
898 break;
899
882 ret = t4vf_alloc_mac_filt(pi->adapter, pi->viid, free, 900 ret = t4vf_alloc_mac_filt(pi->adapter, pi->viid, free,
883 naddr, addr, filt_idx, &mhash, sleep); 901 naddr, addr, NULL, &mhash, sleep);
884 if (ret < 0) 902 if (ret < 0)
885 return ret; 903 return ret;
904 free = false;
886 } 905 }
887 906
888 return t4vf_set_addr_hash(pi->adapter, pi->viid, uhash != 0, 907 return t4vf_set_addr_hash(pi->adapter, pi->viid, uhash != 0,
@@ -1103,18 +1122,6 @@ static int cxgb4vf_set_mac_addr(struct net_device *dev, void *_addr)
1103 return 0; 1122 return 0;
1104} 1123}
1105 1124
1106/*
1107 * Return a TX Queue on which to send the specified skb.
1108 */
1109static u16 cxgb4vf_select_queue(struct net_device *dev, struct sk_buff *skb)
1110{
1111 /*
1112 * XXX For now just use the default hash but we probably want to
1113 * XXX look at other possibilities ...
1114 */
1115 return skb_tx_hash(dev, skb);
1116}
1117
1118#ifdef CONFIG_NET_POLL_CONTROLLER 1125#ifdef CONFIG_NET_POLL_CONTROLLER
1119/* 1126/*
1120 * Poll all of our receive queues. This is called outside of normal interrupt 1127 * Poll all of our receive queues. This is called outside of normal interrupt
@@ -2075,6 +2082,22 @@ static int adap_init0(struct adapter *adapter)
2075 } 2082 }
2076 2083
2077 /* 2084 /*
2085 * Some environments do not properly handle PCIE FLRs -- e.g. in Linux
2086 * 2.6.31 and later we can't call pci_reset_function() in order to
2087 * issue an FLR because of a self- deadlock on the device semaphore.
2088 * Meanwhile, the OS infrastructure doesn't issue FLRs in all the
2089 * cases where they're needed -- for instance, some versions of KVM
2090 * fail to reset "Assigned Devices" when the VM reboots. Therefore we
2091 * use the firmware based reset in order to reset any per function
2092 * state.
2093 */
2094 err = t4vf_fw_reset(adapter);
2095 if (err < 0) {
2096 dev_err(adapter->pdev_dev, "FW reset failed: err=%d\n", err);
2097 return err;
2098 }
2099
2100 /*
2078 * Grab basic operational parameters. These will predominantly have 2101 * Grab basic operational parameters. These will predominantly have
2079 * been set up by the Physical Function Driver or will be hard coded 2102 * been set up by the Physical Function Driver or will be hard coded
2080 * into the adapter. We just have to live with them ... Note that 2103 * into the adapter. We just have to live with them ... Note that
@@ -2246,6 +2269,7 @@ static void __devinit cfg_queues(struct adapter *adapter)
2246{ 2269{
2247 struct sge *s = &adapter->sge; 2270 struct sge *s = &adapter->sge;
2248 int q10g, n10g, qidx, pidx, qs; 2271 int q10g, n10g, qidx, pidx, qs;
2272 size_t iqe_size;
2249 2273
2250 /* 2274 /*
2251 * We should not be called till we know how many Queue Sets we can 2275 * We should not be called till we know how many Queue Sets we can
@@ -2290,6 +2314,13 @@ static void __devinit cfg_queues(struct adapter *adapter)
2290 s->ethqsets = qidx; 2314 s->ethqsets = qidx;
2291 2315
2292 /* 2316 /*
2317 * The Ingress Queue Entry Size for our various Response Queues needs
2318 * to be big enough to accommodate the largest message we can receive
2319 * from the chip/firmware; which is 64 bytes ...
2320 */
2321 iqe_size = 64;
2322
2323 /*
2293 * Set up default Queue Set parameters ... Start off with the 2324 * Set up default Queue Set parameters ... Start off with the
2294 * shortest interrupt holdoff timer. 2325 * shortest interrupt holdoff timer.
2295 */ 2326 */
@@ -2297,7 +2328,7 @@ static void __devinit cfg_queues(struct adapter *adapter)
2297 struct sge_eth_rxq *rxq = &s->ethrxq[qs]; 2328 struct sge_eth_rxq *rxq = &s->ethrxq[qs];
2298 struct sge_eth_txq *txq = &s->ethtxq[qs]; 2329 struct sge_eth_txq *txq = &s->ethtxq[qs];
2299 2330
2300 init_rspq(&rxq->rspq, 0, 0, 1024, L1_CACHE_BYTES); 2331 init_rspq(&rxq->rspq, 0, 0, 1024, iqe_size);
2301 rxq->fl.size = 72; 2332 rxq->fl.size = 72;
2302 txq->q.size = 1024; 2333 txq->q.size = 1024;
2303 } 2334 }
@@ -2306,8 +2337,7 @@ static void __devinit cfg_queues(struct adapter *adapter)
2306 * The firmware event queue is used for link state changes and 2337 * The firmware event queue is used for link state changes and
2307 * notifications of TX DMA completions. 2338 * notifications of TX DMA completions.
2308 */ 2339 */
2309 init_rspq(&s->fw_evtq, SGE_TIMER_RSTRT_CNTR, 0, 512, 2340 init_rspq(&s->fw_evtq, SGE_TIMER_RSTRT_CNTR, 0, 512, iqe_size);
2310 L1_CACHE_BYTES);
2311 2341
2312 /* 2342 /*
2313 * The forwarded interrupt queue is used when we're in MSI interrupt 2343 * The forwarded interrupt queue is used when we're in MSI interrupt
@@ -2323,7 +2353,7 @@ static void __devinit cfg_queues(struct adapter *adapter)
2323 * any time ... 2353 * any time ...
2324 */ 2354 */
2325 init_rspq(&s->intrq, SGE_TIMER_RSTRT_CNTR, 0, MSIX_ENTRIES + 1, 2355 init_rspq(&s->intrq, SGE_TIMER_RSTRT_CNTR, 0, MSIX_ENTRIES + 1,
2326 L1_CACHE_BYTES); 2356 iqe_size);
2327} 2357}
2328 2358
2329/* 2359/*
@@ -2417,7 +2447,6 @@ static const struct net_device_ops cxgb4vf_netdev_ops = {
2417 .ndo_get_stats = cxgb4vf_get_stats, 2447 .ndo_get_stats = cxgb4vf_get_stats,
2418 .ndo_set_rx_mode = cxgb4vf_set_rxmode, 2448 .ndo_set_rx_mode = cxgb4vf_set_rxmode,
2419 .ndo_set_mac_address = cxgb4vf_set_mac_addr, 2449 .ndo_set_mac_address = cxgb4vf_set_mac_addr,
2420 .ndo_select_queue = cxgb4vf_select_queue,
2421 .ndo_validate_addr = eth_validate_addr, 2450 .ndo_validate_addr = eth_validate_addr,
2422 .ndo_do_ioctl = cxgb4vf_do_ioctl, 2451 .ndo_do_ioctl = cxgb4vf_do_ioctl,
2423 .ndo_change_mtu = cxgb4vf_change_mtu, 2452 .ndo_change_mtu = cxgb4vf_change_mtu,
@@ -2600,7 +2629,6 @@ static int __devinit cxgb4vf_pci_probe(struct pci_dev *pdev,
2600 pi->xact_addr_filt = -1; 2629 pi->xact_addr_filt = -1;
2601 pi->rx_offload = RX_CSO; 2630 pi->rx_offload = RX_CSO;
2602 netif_carrier_off(netdev); 2631 netif_carrier_off(netdev);
2603 netif_tx_stop_all_queues(netdev);
2604 netdev->irq = pdev->irq; 2632 netdev->irq = pdev->irq;
2605 2633
2606 netdev->features = (NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | 2634 netdev->features = (NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 |
@@ -2625,7 +2653,6 @@ static int __devinit cxgb4vf_pci_probe(struct pci_dev *pdev,
2625 netdev->do_ioctl = cxgb4vf_do_ioctl; 2653 netdev->do_ioctl = cxgb4vf_do_ioctl;
2626 netdev->change_mtu = cxgb4vf_change_mtu; 2654 netdev->change_mtu = cxgb4vf_change_mtu;
2627 netdev->set_mac_address = cxgb4vf_set_mac_addr; 2655 netdev->set_mac_address = cxgb4vf_set_mac_addr;
2628 netdev->select_queue = cxgb4vf_select_queue;
2629#ifdef CONFIG_NET_POLL_CONTROLLER 2656#ifdef CONFIG_NET_POLL_CONTROLLER
2630 netdev->poll_controller = cxgb4vf_poll_controller; 2657 netdev->poll_controller = cxgb4vf_poll_controller;
2631#endif 2658#endif
@@ -2844,6 +2871,14 @@ static struct pci_device_id cxgb4vf_pci_tbl[] = {
2844 CH_DEVICE(0x4800, 0), /* T440-dbg */ 2871 CH_DEVICE(0x4800, 0), /* T440-dbg */
2845 CH_DEVICE(0x4801, 0), /* T420-cr */ 2872 CH_DEVICE(0x4801, 0), /* T420-cr */
2846 CH_DEVICE(0x4802, 0), /* T422-cr */ 2873 CH_DEVICE(0x4802, 0), /* T422-cr */
2874 CH_DEVICE(0x4803, 0), /* T440-cr */
2875 CH_DEVICE(0x4804, 0), /* T420-bch */
2876 CH_DEVICE(0x4805, 0), /* T440-bch */
2877 CH_DEVICE(0x4806, 0), /* T460-ch */
2878 CH_DEVICE(0x4807, 0), /* T420-so */
2879 CH_DEVICE(0x4808, 0), /* T420-cx */
2880 CH_DEVICE(0x4809, 0), /* T420-bt */
2881 CH_DEVICE(0x480a, 0), /* T404-bt */
2847 { 0, } 2882 { 0, }
2848}; 2883};
2849 2884
diff --git a/drivers/net/cxgb4vf/sge.c b/drivers/net/cxgb4vf/sge.c
index f10864ddafbe..ecf0770bf0ff 100644
--- a/drivers/net/cxgb4vf/sge.c
+++ b/drivers/net/cxgb4vf/sge.c
@@ -154,13 +154,14 @@ enum {
154 */ 154 */
155 RX_COPY_THRES = 256, 155 RX_COPY_THRES = 256,
156 RX_PULL_LEN = 128, 156 RX_PULL_LEN = 128,
157};
158 157
159/* 158 /*
160 * Can't define this in the above enum because PKTSHIFT isn't a constant in 159 * Main body length for sk_buffs used for RX Ethernet packets with
161 * the VF Driver ... 160 * fragments. Should be >= RX_PULL_LEN but possibly bigger to give
162 */ 161 * pskb_may_pull() some room.
163#define RX_PKT_PULL_LEN (RX_PULL_LEN + PKTSHIFT) 162 */
163 RX_SKB_LEN = 512,
164};
164 165
165/* 166/*
166 * Software state per TX descriptor. 167 * Software state per TX descriptor.
@@ -1355,6 +1356,67 @@ out_free:
1355} 1356}
1356 1357
1357/** 1358/**
1359 * t4vf_pktgl_to_skb - build an sk_buff from a packet gather list
1360 * @gl: the gather list
1361 * @skb_len: size of sk_buff main body if it carries fragments
1362 * @pull_len: amount of data to move to the sk_buff's main body
1363 *
1364 * Builds an sk_buff from the given packet gather list. Returns the
1365 * sk_buff or %NULL if sk_buff allocation failed.
1366 */
1367struct sk_buff *t4vf_pktgl_to_skb(const struct pkt_gl *gl,
1368 unsigned int skb_len, unsigned int pull_len)
1369{
1370 struct sk_buff *skb;
1371 struct skb_shared_info *ssi;
1372
1373 /*
1374 * If the ingress packet is small enough, allocate an skb large enough
1375 * for all of the data and copy it inline. Otherwise, allocate an skb
1376 * with enough room to pull in the header and reference the rest of
1377 * the data via the skb fragment list.
1378 *
1379 * Below we rely on RX_COPY_THRES being less than the smallest Rx
1380 * buff! size, which is expected since buffers are at least
1381 * PAGE_SIZEd. In this case packets up to RX_COPY_THRES have only one
1382 * fragment.
1383 */
1384 if (gl->tot_len <= RX_COPY_THRES) {
1385 /* small packets have only one fragment */
1386 skb = alloc_skb(gl->tot_len, GFP_ATOMIC);
1387 if (unlikely(!skb))
1388 goto out;
1389 __skb_put(skb, gl->tot_len);
1390 skb_copy_to_linear_data(skb, gl->va, gl->tot_len);
1391 } else {
1392 skb = alloc_skb(skb_len, GFP_ATOMIC);
1393 if (unlikely(!skb))
1394 goto out;
1395 __skb_put(skb, pull_len);
1396 skb_copy_to_linear_data(skb, gl->va, pull_len);
1397
1398 ssi = skb_shinfo(skb);
1399 ssi->frags[0].page = gl->frags[0].page;
1400 ssi->frags[0].page_offset = gl->frags[0].page_offset + pull_len;
1401 ssi->frags[0].size = gl->frags[0].size - pull_len;
1402 if (gl->nfrags > 1)
1403 memcpy(&ssi->frags[1], &gl->frags[1],
1404 (gl->nfrags-1) * sizeof(skb_frag_t));
1405 ssi->nr_frags = gl->nfrags;
1406
1407 skb->len = gl->tot_len;
1408 skb->data_len = skb->len - pull_len;
1409 skb->truesize += skb->data_len;
1410
1411 /* Get a reference for the last page, we don't own it */
1412 get_page(gl->frags[gl->nfrags - 1].page);
1413 }
1414
1415out:
1416 return skb;
1417}
1418
1419/**
1358 * t4vf_pktgl_free - free a packet gather list 1420 * t4vf_pktgl_free - free a packet gather list
1359 * @gl: the gather list 1421 * @gl: the gather list
1360 * 1422 *
@@ -1463,10 +1525,8 @@ int t4vf_ethrx_handler(struct sge_rspq *rspq, const __be64 *rsp,
1463{ 1525{
1464 struct sk_buff *skb; 1526 struct sk_buff *skb;
1465 struct port_info *pi; 1527 struct port_info *pi;
1466 struct skb_shared_info *ssi;
1467 const struct cpl_rx_pkt *pkt = (void *)&rsp[1]; 1528 const struct cpl_rx_pkt *pkt = (void *)&rsp[1];
1468 bool csum_ok = pkt->csum_calc && !pkt->err_vec; 1529 bool csum_ok = pkt->csum_calc && !pkt->err_vec;
1469 unsigned int len = be16_to_cpu(pkt->len);
1470 struct sge_eth_rxq *rxq = container_of(rspq, struct sge_eth_rxq, rspq); 1530 struct sge_eth_rxq *rxq = container_of(rspq, struct sge_eth_rxq, rspq);
1471 1531
1472 /* 1532 /*
@@ -1481,42 +1541,14 @@ int t4vf_ethrx_handler(struct sge_rspq *rspq, const __be64 *rsp,
1481 } 1541 }
1482 1542
1483 /* 1543 /*
1484 * If the ingress packet is small enough, allocate an skb large enough 1544 * Convert the Packet Gather List into an skb.
1485 * for all of the data and copy it inline. Otherwise, allocate an skb
1486 * with enough room to pull in the header and reference the rest of
1487 * the data via the skb fragment list.
1488 */ 1545 */
1489 if (len <= RX_COPY_THRES) { 1546 skb = t4vf_pktgl_to_skb(gl, RX_SKB_LEN, RX_PULL_LEN);
1490 /* small packets have only one fragment */ 1547 if (unlikely(!skb)) {
1491 skb = alloc_skb(gl->frags[0].size, GFP_ATOMIC); 1548 t4vf_pktgl_free(gl);
1492 if (!skb) 1549 rxq->stats.rx_drops++;
1493 goto nomem; 1550 return 0;
1494 __skb_put(skb, gl->frags[0].size);
1495 skb_copy_to_linear_data(skb, gl->va, gl->frags[0].size);
1496 } else {
1497 skb = alloc_skb(RX_PKT_PULL_LEN, GFP_ATOMIC);
1498 if (!skb)
1499 goto nomem;
1500 __skb_put(skb, RX_PKT_PULL_LEN);
1501 skb_copy_to_linear_data(skb, gl->va, RX_PKT_PULL_LEN);
1502
1503 ssi = skb_shinfo(skb);
1504 ssi->frags[0].page = gl->frags[0].page;
1505 ssi->frags[0].page_offset = (gl->frags[0].page_offset +
1506 RX_PKT_PULL_LEN);
1507 ssi->frags[0].size = gl->frags[0].size - RX_PKT_PULL_LEN;
1508 if (gl->nfrags > 1)
1509 memcpy(&ssi->frags[1], &gl->frags[1],
1510 (gl->nfrags-1) * sizeof(skb_frag_t));
1511 ssi->nr_frags = gl->nfrags;
1512 skb->len = len + PKTSHIFT;
1513 skb->data_len = skb->len - RX_PKT_PULL_LEN;
1514 skb->truesize += skb->data_len;
1515
1516 /* Get a reference for the last page, we don't own it */
1517 get_page(gl->frags[gl->nfrags - 1].page);
1518 } 1551 }
1519
1520 __skb_pull(skb, PKTSHIFT); 1552 __skb_pull(skb, PKTSHIFT);
1521 skb->protocol = eth_type_trans(skb, rspq->netdev); 1553 skb->protocol = eth_type_trans(skb, rspq->netdev);
1522 skb_record_rx_queue(skb, rspq->idx); 1554 skb_record_rx_queue(skb, rspq->idx);
@@ -1549,11 +1581,6 @@ int t4vf_ethrx_handler(struct sge_rspq *rspq, const __be64 *rsp,
1549 netif_receive_skb(skb); 1581 netif_receive_skb(skb);
1550 1582
1551 return 0; 1583 return 0;
1552
1553nomem:
1554 t4vf_pktgl_free(gl);
1555 rxq->stats.rx_drops++;
1556 return 0;
1557} 1584}
1558 1585
1559/** 1586/**
@@ -1679,6 +1706,7 @@ int process_responses(struct sge_rspq *rspq, int budget)
1679 } 1706 }
1680 len = RSPD_LEN(len); 1707 len = RSPD_LEN(len);
1681 } 1708 }
1709 gl.tot_len = len;
1682 1710
1683 /* 1711 /*
1684 * Gather packet fragments. 1712 * Gather packet fragments.
diff --git a/drivers/net/cxgb4vf/t4vf_common.h b/drivers/net/cxgb4vf/t4vf_common.h
index 873cb7d86c57..a65c80aed1f2 100644
--- a/drivers/net/cxgb4vf/t4vf_common.h
+++ b/drivers/net/cxgb4vf/t4vf_common.h
@@ -235,6 +235,7 @@ static inline int t4vf_wr_mbox_ns(struct adapter *adapter, const void *cmd,
235int __devinit t4vf_wait_dev_ready(struct adapter *); 235int __devinit t4vf_wait_dev_ready(struct adapter *);
236int __devinit t4vf_port_init(struct adapter *, int); 236int __devinit t4vf_port_init(struct adapter *, int);
237 237
238int t4vf_fw_reset(struct adapter *);
238int t4vf_query_params(struct adapter *, unsigned int, const u32 *, u32 *); 239int t4vf_query_params(struct adapter *, unsigned int, const u32 *, u32 *);
239int t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *); 240int t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *);
240 241
diff --git a/drivers/net/cxgb4vf/t4vf_hw.c b/drivers/net/cxgb4vf/t4vf_hw.c
index ea1c123f0cb4..19520afe1a12 100644
--- a/drivers/net/cxgb4vf/t4vf_hw.c
+++ b/drivers/net/cxgb4vf/t4vf_hw.c
@@ -326,6 +326,25 @@ int __devinit t4vf_port_init(struct adapter *adapter, int pidx)
326} 326}
327 327
328/** 328/**
329 * t4vf_fw_reset - issue a reset to FW
330 * @adapter: the adapter
331 *
332 * Issues a reset command to FW. For a Physical Function this would
333 * result in the Firmware reseting all of its state. For a Virtual
334 * Function this just resets the state associated with the VF.
335 */
336int t4vf_fw_reset(struct adapter *adapter)
337{
338 struct fw_reset_cmd cmd;
339
340 memset(&cmd, 0, sizeof(cmd));
341 cmd.op_to_write = cpu_to_be32(FW_CMD_OP(FW_RESET_CMD) |
342 FW_CMD_WRITE);
343 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
344 return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
345}
346
347/**
329 * t4vf_query_params - query FW or device parameters 348 * t4vf_query_params - query FW or device parameters
330 * @adapter: the adapter 349 * @adapter: the adapter
331 * @nparams: the number of parameters 350 * @nparams: the number of parameters
@@ -995,48 +1014,72 @@ int t4vf_alloc_mac_filt(struct adapter *adapter, unsigned int viid, bool free,
995 unsigned int naddr, const u8 **addr, u16 *idx, 1014 unsigned int naddr, const u8 **addr, u16 *idx,
996 u64 *hash, bool sleep_ok) 1015 u64 *hash, bool sleep_ok)
997{ 1016{
998 int i, ret; 1017 int offset, ret = 0;
1018 unsigned nfilters = 0;
1019 unsigned int rem = naddr;
999 struct fw_vi_mac_cmd cmd, rpl; 1020 struct fw_vi_mac_cmd cmd, rpl;
1000 struct fw_vi_mac_exact *p;
1001 size_t len16;
1002 1021
1003 if (naddr > ARRAY_SIZE(cmd.u.exact)) 1022 if (naddr > FW_CLS_TCAM_NUM_ENTRIES)
1004 return -EINVAL; 1023 return -EINVAL;
1005 len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
1006 u.exact[naddr]), 16);
1007 1024
1008 memset(&cmd, 0, sizeof(cmd)); 1025 for (offset = 0; offset < naddr; /**/) {
1009 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_MAC_CMD) | 1026 unsigned int fw_naddr = (rem < ARRAY_SIZE(cmd.u.exact)
1010 FW_CMD_REQUEST | 1027 ? rem
1011 FW_CMD_WRITE | 1028 : ARRAY_SIZE(cmd.u.exact));
1012 (free ? FW_CMD_EXEC : 0) | 1029 size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
1013 FW_VI_MAC_CMD_VIID(viid)); 1030 u.exact[fw_naddr]), 16);
1014 cmd.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_FREEMACS(free) | 1031 struct fw_vi_mac_exact *p;
1015 FW_CMD_LEN16(len16)); 1032 int i;
1033
1034 memset(&cmd, 0, sizeof(cmd));
1035 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP(FW_VI_MAC_CMD) |
1036 FW_CMD_REQUEST |
1037 FW_CMD_WRITE |
1038 (free ? FW_CMD_EXEC : 0) |
1039 FW_VI_MAC_CMD_VIID(viid));
1040 cmd.freemacs_to_len16 =
1041 cpu_to_be32(FW_VI_MAC_CMD_FREEMACS(free) |
1042 FW_CMD_LEN16(len16));
1043
1044 for (i = 0, p = cmd.u.exact; i < fw_naddr; i++, p++) {
1045 p->valid_to_idx = cpu_to_be16(
1046 FW_VI_MAC_CMD_VALID |
1047 FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
1048 memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
1049 }
1016 1050
1017 for (i = 0, p = cmd.u.exact; i < naddr; i++, p++) {
1018 p->valid_to_idx =
1019 cpu_to_be16(FW_VI_MAC_CMD_VALID |
1020 FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
1021 memcpy(p->macaddr, addr[i], sizeof(p->macaddr));
1022 }
1023 1051
1024 ret = t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), &rpl, sleep_ok); 1052 ret = t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), &rpl,
1025 if (ret) 1053 sleep_ok);
1026 return ret; 1054 if (ret && ret != -ENOMEM)
1027 1055 break;
1028 for (i = 0, p = rpl.u.exact; i < naddr; i++, p++) { 1056
1029 u16 index = FW_VI_MAC_CMD_IDX_GET(be16_to_cpu(p->valid_to_idx)); 1057 for (i = 0, p = rpl.u.exact; i < fw_naddr; i++, p++) {
1030 1058 u16 index = FW_VI_MAC_CMD_IDX_GET(
1031 if (idx) 1059 be16_to_cpu(p->valid_to_idx));
1032 idx[i] = (index >= FW_CLS_TCAM_NUM_ENTRIES 1060
1033 ? 0xffff 1061 if (idx)
1034 : index); 1062 idx[offset+i] =
1035 if (index < FW_CLS_TCAM_NUM_ENTRIES) 1063 (index >= FW_CLS_TCAM_NUM_ENTRIES
1036 ret++; 1064 ? 0xffff
1037 else if (hash) 1065 : index);
1038 *hash |= (1 << hash_mac_addr(addr[i])); 1066 if (index < FW_CLS_TCAM_NUM_ENTRIES)
1067 nfilters++;
1068 else if (hash)
1069 *hash |= (1ULL << hash_mac_addr(addr[offset+i]));
1070 }
1071
1072 free = false;
1073 offset += fw_naddr;
1074 rem -= fw_naddr;
1039 } 1075 }
1076
1077 /*
1078 * If there were no errors or we merely ran out of room in our MAC
1079 * address arena, return the number of filters actually written.
1080 */
1081 if (ret == 0 || ret == -ENOMEM)
1082 ret = nfilters;
1040 return ret; 1083 return ret;
1041} 1084}
1042 1085
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 1b8a43a29c01..e02c5d17af07 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -31,7 +31,7 @@
31 31
32char e1000_driver_name[] = "e1000"; 32char e1000_driver_name[] = "e1000";
33static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; 33static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
34#define DRV_VERSION "7.3.21-k6-NAPI" 34#define DRV_VERSION "7.3.21-k8-NAPI"
35const char e1000_driver_version[] = DRV_VERSION; 35const char e1000_driver_version[] = DRV_VERSION;
36static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; 36static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
37 37
@@ -485,9 +485,6 @@ void e1000_down(struct e1000_adapter *adapter)
485 struct net_device *netdev = adapter->netdev; 485 struct net_device *netdev = adapter->netdev;
486 u32 rctl, tctl; 486 u32 rctl, tctl;
487 487
488 /* signal that we're down so the interrupt handler does not
489 * reschedule our watchdog timer */
490 set_bit(__E1000_DOWN, &adapter->flags);
491 488
492 /* disable receives in the hardware */ 489 /* disable receives in the hardware */
493 rctl = er32(RCTL); 490 rctl = er32(RCTL);
@@ -508,6 +505,13 @@ void e1000_down(struct e1000_adapter *adapter)
508 505
509 e1000_irq_disable(adapter); 506 e1000_irq_disable(adapter);
510 507
508 /*
509 * Setting DOWN must be after irq_disable to prevent
510 * a screaming interrupt. Setting DOWN also prevents
511 * timers and tasks from rescheduling.
512 */
513 set_bit(__E1000_DOWN, &adapter->flags);
514
511 del_timer_sync(&adapter->tx_fifo_stall_timer); 515 del_timer_sync(&adapter->tx_fifo_stall_timer);
512 del_timer_sync(&adapter->watchdog_timer); 516 del_timer_sync(&adapter->watchdog_timer);
513 del_timer_sync(&adapter->phy_info_timer); 517 del_timer_sync(&adapter->phy_info_timer);
diff --git a/drivers/net/ehea/ehea_ethtool.c b/drivers/net/ehea/ehea_ethtool.c
index 75b099ce49c9..1f37ee6b2a26 100644
--- a/drivers/net/ehea/ehea_ethtool.c
+++ b/drivers/net/ehea/ehea_ethtool.c
@@ -261,6 +261,13 @@ static void ehea_get_ethtool_stats(struct net_device *dev,
261 261
262} 262}
263 263
264static int ehea_set_flags(struct net_device *dev, u32 data)
265{
266 return ethtool_op_set_flags(dev, data, ETH_FLAG_LRO
267 | ETH_FLAG_TXVLAN
268 | ETH_FLAG_RXVLAN);
269}
270
264const struct ethtool_ops ehea_ethtool_ops = { 271const struct ethtool_ops ehea_ethtool_ops = {
265 .get_settings = ehea_get_settings, 272 .get_settings = ehea_get_settings,
266 .get_drvinfo = ehea_get_drvinfo, 273 .get_drvinfo = ehea_get_drvinfo,
@@ -273,6 +280,8 @@ const struct ethtool_ops ehea_ethtool_ops = {
273 .get_ethtool_stats = ehea_get_ethtool_stats, 280 .get_ethtool_stats = ehea_get_ethtool_stats,
274 .get_rx_csum = ehea_get_rx_csum, 281 .get_rx_csum = ehea_get_rx_csum,
275 .set_settings = ehea_set_settings, 282 .set_settings = ehea_set_settings,
283 .get_flags = ethtool_op_get_flags,
284 .set_flags = ehea_set_flags,
276 .nway_reset = ehea_nway_reset, /* Restart autonegotiation */ 285 .nway_reset = ehea_nway_reset, /* Restart autonegotiation */
277}; 286};
278 287
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 182b2a7be8dc..b95f087cd5a9 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -400,6 +400,7 @@ static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
400 skb_arr_rq1[index] = netdev_alloc_skb(dev, 400 skb_arr_rq1[index] = netdev_alloc_skb(dev,
401 EHEA_L_PKT_SIZE); 401 EHEA_L_PKT_SIZE);
402 if (!skb_arr_rq1[index]) { 402 if (!skb_arr_rq1[index]) {
403 ehea_info("Unable to allocate enough skb in the array\n");
403 pr->rq1_skba.os_skbs = fill_wqes - i; 404 pr->rq1_skba.os_skbs = fill_wqes - i;
404 break; 405 break;
405 } 406 }
@@ -422,13 +423,20 @@ static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
422 struct net_device *dev = pr->port->netdev; 423 struct net_device *dev = pr->port->netdev;
423 int i; 424 int i;
424 425
425 for (i = 0; i < pr->rq1_skba.len; i++) { 426 if (nr_rq1a > pr->rq1_skba.len) {
427 ehea_error("NR_RQ1A bigger than skb array len\n");
428 return;
429 }
430
431 for (i = 0; i < nr_rq1a; i++) {
426 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE); 432 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
427 if (!skb_arr_rq1[i]) 433 if (!skb_arr_rq1[i]) {
434 ehea_info("No enough memory to allocate skb array\n");
428 break; 435 break;
436 }
429 } 437 }
430 /* Ring doorbell */ 438 /* Ring doorbell */
431 ehea_update_rq1a(pr->qp, nr_rq1a); 439 ehea_update_rq1a(pr->qp, i);
432} 440}
433 441
434static int ehea_refill_rq_def(struct ehea_port_res *pr, 442static int ehea_refill_rq_def(struct ehea_port_res *pr,
@@ -675,7 +683,7 @@ static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
675 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) && 683 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
676 pr->port->vgrp); 684 pr->port->vgrp);
677 685
678 if (use_lro) { 686 if (skb->dev->features & NETIF_F_LRO) {
679 if (vlan_extracted) 687 if (vlan_extracted)
680 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb, 688 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
681 pr->port->vgrp, 689 pr->port->vgrp,
@@ -735,8 +743,10 @@ static int ehea_proc_rwqes(struct net_device *dev,
735 743
736 skb = netdev_alloc_skb(dev, 744 skb = netdev_alloc_skb(dev,
737 EHEA_L_PKT_SIZE); 745 EHEA_L_PKT_SIZE);
738 if (!skb) 746 if (!skb) {
747 ehea_info("Not enough memory to allocate skb\n");
739 break; 748 break;
749 }
740 } 750 }
741 skb_copy_to_linear_data(skb, ((char *)cqe) + 64, 751 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
742 cqe->num_bytes_transfered - 4); 752 cqe->num_bytes_transfered - 4);
@@ -777,7 +787,7 @@ static int ehea_proc_rwqes(struct net_device *dev,
777 } 787 }
778 cqe = ehea_poll_rq1(qp, &wqe_index); 788 cqe = ehea_poll_rq1(qp, &wqe_index);
779 } 789 }
780 if (use_lro) 790 if (dev->features & NETIF_F_LRO)
781 lro_flush_all(&pr->lro_mgr); 791 lro_flush_all(&pr->lro_mgr);
782 792
783 pr->rx_packets += processed; 793 pr->rx_packets += processed;
@@ -3268,6 +3278,9 @@ struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3268 | NETIF_F_LLTX; 3278 | NETIF_F_LLTX;
3269 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT; 3279 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3270 3280
3281 if (use_lro)
3282 dev->features |= NETIF_F_LRO;
3283
3271 INIT_WORK(&port->reset_task, ehea_reset_port); 3284 INIT_WORK(&port->reset_task, ehea_reset_port);
3272 3285
3273 ret = register_netdev(dev); 3286 ret = register_netdev(dev);
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c
index a466ef91dd43..aa28b270c045 100644
--- a/drivers/net/enic/enic_main.c
+++ b/drivers/net/enic/enic_main.c
@@ -1962,7 +1962,8 @@ static void enic_poll_controller(struct net_device *netdev)
1962 case VNIC_DEV_INTR_MODE_MSIX: 1962 case VNIC_DEV_INTR_MODE_MSIX:
1963 for (i = 0; i < enic->rq_count; i++) { 1963 for (i = 0; i < enic->rq_count; i++) {
1964 intr = enic_msix_rq_intr(enic, i); 1964 intr = enic_msix_rq_intr(enic, i);
1965 enic_isr_msix_rq(enic->msix_entry[intr].vector, enic); 1965 enic_isr_msix_rq(enic->msix_entry[intr].vector,
1966 &enic->napi[i]);
1966 } 1967 }
1967 intr = enic_msix_wq_intr(enic, i); 1968 intr = enic_msix_wq_intr(enic, i);
1968 enic_isr_msix_wq(enic->msix_entry[intr].vector, enic); 1969 enic_isr_msix_wq(enic->msix_entry[intr].vector, enic);
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 49e4ce1246a7..d1bec6269173 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -577,11 +577,10 @@ static int gfar_parse_group(struct device_node *np,
577 irq_of_parse_and_map(np, 1); 577 irq_of_parse_and_map(np, 1);
578 priv->gfargrp[priv->num_grps].interruptError = 578 priv->gfargrp[priv->num_grps].interruptError =
579 irq_of_parse_and_map(np,2); 579 irq_of_parse_and_map(np,2);
580 if (priv->gfargrp[priv->num_grps].interruptTransmit < 0 || 580 if (priv->gfargrp[priv->num_grps].interruptTransmit == NO_IRQ ||
581 priv->gfargrp[priv->num_grps].interruptReceive < 0 || 581 priv->gfargrp[priv->num_grps].interruptReceive == NO_IRQ ||
582 priv->gfargrp[priv->num_grps].interruptError < 0) { 582 priv->gfargrp[priv->num_grps].interruptError == NO_IRQ)
583 return -EINVAL; 583 return -EINVAL;
584 }
585 } 584 }
586 585
587 priv->gfargrp[priv->num_grps].grp_id = priv->num_grps; 586 priv->gfargrp[priv->num_grps].grp_id = priv->num_grps;
diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
index 5c566ebc54b8..3bc8e276ba4d 100644
--- a/drivers/net/gianfar_ethtool.c
+++ b/drivers/net/gianfar_ethtool.c
@@ -635,9 +635,10 @@ static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
635 if (wol->wolopts & ~WAKE_MAGIC) 635 if (wol->wolopts & ~WAKE_MAGIC)
636 return -EINVAL; 636 return -EINVAL;
637 637
638 device_set_wakeup_enable(&dev->dev, wol->wolopts & WAKE_MAGIC);
639
638 spin_lock_irqsave(&priv->bflock, flags); 640 spin_lock_irqsave(&priv->bflock, flags);
639 priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0; 641 priv->wol_en = !!device_may_wakeup(&dev->dev);
640 device_set_wakeup_enable(&dev->dev, priv->wol_en);
641 spin_unlock_irqrestore(&priv->bflock, flags); 642 spin_unlock_irqrestore(&priv->bflock, flags);
642 643
643 return 0; 644 return 0;
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 385dc3204cb7..06bb9b799458 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -2871,7 +2871,6 @@ static int __devinit emac_probe(struct platform_device *ofdev,
2871 SET_ETHTOOL_OPS(ndev, &emac_ethtool_ops); 2871 SET_ETHTOOL_OPS(ndev, &emac_ethtool_ops);
2872 2872
2873 netif_carrier_off(ndev); 2873 netif_carrier_off(ndev);
2874 netif_stop_queue(ndev);
2875 2874
2876 err = register_netdev(ndev); 2875 err = register_netdev(ndev);
2877 if (err) { 2876 if (err) {
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index ab9f675c5b8b..fe337bd121aa 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -104,6 +104,8 @@ static void ri_tasklet(unsigned long dev)
104 rcu_read_unlock(); 104 rcu_read_unlock();
105 dev_kfree_skb(skb); 105 dev_kfree_skb(skb);
106 stats->tx_dropped++; 106 stats->tx_dropped++;
107 if (skb_queue_len(&dp->tq) != 0)
108 goto resched;
107 break; 109 break;
108 } 110 }
109 rcu_read_unlock(); 111 rcu_read_unlock();
diff --git a/drivers/net/ipg.c b/drivers/net/ipg.c
index dc0198092343..aa93655c3aa7 100644
--- a/drivers/net/ipg.c
+++ b/drivers/net/ipg.c
@@ -88,16 +88,14 @@ static const char *ipg_brand_name[] = {
88 "IC PLUS IP1000 1000/100/10 based NIC", 88 "IC PLUS IP1000 1000/100/10 based NIC",
89 "Sundance Technology ST2021 based NIC", 89 "Sundance Technology ST2021 based NIC",
90 "Tamarack Microelectronics TC9020/9021 based NIC", 90 "Tamarack Microelectronics TC9020/9021 based NIC",
91 "Tamarack Microelectronics TC9020/9021 based NIC",
92 "D-Link NIC IP1000A" 91 "D-Link NIC IP1000A"
93}; 92};
94 93
95static DEFINE_PCI_DEVICE_TABLE(ipg_pci_tbl) = { 94static DEFINE_PCI_DEVICE_TABLE(ipg_pci_tbl) = {
96 { PCI_VDEVICE(SUNDANCE, 0x1023), 0 }, 95 { PCI_VDEVICE(SUNDANCE, 0x1023), 0 },
97 { PCI_VDEVICE(SUNDANCE, 0x2021), 1 }, 96 { PCI_VDEVICE(SUNDANCE, 0x2021), 1 },
98 { PCI_VDEVICE(SUNDANCE, 0x1021), 2 }, 97 { PCI_VDEVICE(DLINK, 0x9021), 2 },
99 { PCI_VDEVICE(DLINK, 0x9021), 3 }, 98 { PCI_VDEVICE(DLINK, 0x4020), 3 },
100 { PCI_VDEVICE(DLINK, 0x4020), 4 },
101 { 0, } 99 { 0, }
102}; 100};
103 101
diff --git a/drivers/net/irda/sh_sir.c b/drivers/net/irda/sh_sir.c
index 00b38bccd6d0..52a7c86af663 100644
--- a/drivers/net/irda/sh_sir.c
+++ b/drivers/net/irda/sh_sir.c
@@ -258,7 +258,7 @@ static int sh_sir_set_baudrate(struct sh_sir_self *self, u32 baudrate)
258 258
259 /* Baud Rate Error Correction x 10000 */ 259 /* Baud Rate Error Correction x 10000 */
260 u32 rate_err_array[] = { 260 u32 rate_err_array[] = {
261 0000, 0625, 1250, 1875, 261 0, 625, 1250, 1875,
262 2500, 3125, 3750, 4375, 262 2500, 3125, 3750, 4375,
263 5000, 5625, 6250, 6875, 263 5000, 5625, 6250, 6875,
264 7500, 8125, 8750, 9375, 264 7500, 8125, 8750, 9375,
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c
index 2bd3eb4ee5a1..eee0b298bd36 100644
--- a/drivers/net/ixgbe/ixgbe_main.c
+++ b/drivers/net/ixgbe/ixgbe_main.c
@@ -764,8 +764,9 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
764#ifdef IXGBE_FCOE 764#ifdef IXGBE_FCOE
765 /* adjust for FCoE Sequence Offload */ 765 /* adjust for FCoE Sequence Offload */
766 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) 766 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
767 && (skb->protocol == htons(ETH_P_FCOE)) && 767 && skb_is_gso(skb)
768 skb_is_gso(skb)) { 768 && vlan_get_protocol(skb) ==
769 htons(ETH_P_FCOE)) {
769 hlen = skb_transport_offset(skb) + 770 hlen = skb_transport_offset(skb) +
770 sizeof(struct fc_frame_header) + 771 sizeof(struct fc_frame_header) +
771 sizeof(struct fcoe_crc_eof); 772 sizeof(struct fcoe_crc_eof);
@@ -4770,6 +4771,9 @@ void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
4770 adapter->rx_ring[i] = NULL; 4771 adapter->rx_ring[i] = NULL;
4771 } 4772 }
4772 4773
4774 adapter->num_tx_queues = 0;
4775 adapter->num_rx_queues = 0;
4776
4773 ixgbe_free_q_vectors(adapter); 4777 ixgbe_free_q_vectors(adapter);
4774 ixgbe_reset_interrupt_capability(adapter); 4778 ixgbe_reset_interrupt_capability(adapter);
4775} 4779}
@@ -5823,7 +5827,7 @@ static void ixgbe_watchdog_task(struct work_struct *work)
5823 5827
5824static int ixgbe_tso(struct ixgbe_adapter *adapter, 5828static int ixgbe_tso(struct ixgbe_adapter *adapter,
5825 struct ixgbe_ring *tx_ring, struct sk_buff *skb, 5829 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
5826 u32 tx_flags, u8 *hdr_len) 5830 u32 tx_flags, u8 *hdr_len, __be16 protocol)
5827{ 5831{
5828 struct ixgbe_adv_tx_context_desc *context_desc; 5832 struct ixgbe_adv_tx_context_desc *context_desc;
5829 unsigned int i; 5833 unsigned int i;
@@ -5841,7 +5845,7 @@ static int ixgbe_tso(struct ixgbe_adapter *adapter,
5841 l4len = tcp_hdrlen(skb); 5845 l4len = tcp_hdrlen(skb);
5842 *hdr_len += l4len; 5846 *hdr_len += l4len;
5843 5847
5844 if (skb->protocol == htons(ETH_P_IP)) { 5848 if (protocol == htons(ETH_P_IP)) {
5845 struct iphdr *iph = ip_hdr(skb); 5849 struct iphdr *iph = ip_hdr(skb);
5846 iph->tot_len = 0; 5850 iph->tot_len = 0;
5847 iph->check = 0; 5851 iph->check = 0;
@@ -5880,7 +5884,7 @@ static int ixgbe_tso(struct ixgbe_adapter *adapter,
5880 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | 5884 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
5881 IXGBE_ADVTXD_DTYP_CTXT); 5885 IXGBE_ADVTXD_DTYP_CTXT);
5882 5886
5883 if (skb->protocol == htons(ETH_P_IP)) 5887 if (protocol == htons(ETH_P_IP))
5884 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; 5888 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
5885 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; 5889 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5886 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); 5890 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
@@ -5906,16 +5910,10 @@ static int ixgbe_tso(struct ixgbe_adapter *adapter,
5906 return false; 5910 return false;
5907} 5911}
5908 5912
5909static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb) 5913static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
5914 __be16 protocol)
5910{ 5915{
5911 u32 rtn = 0; 5916 u32 rtn = 0;
5912 __be16 protocol;
5913
5914 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5915 protocol = ((const struct vlan_ethhdr *)skb->data)->
5916 h_vlan_encapsulated_proto;
5917 else
5918 protocol = skb->protocol;
5919 5917
5920 switch (protocol) { 5918 switch (protocol) {
5921 case cpu_to_be16(ETH_P_IP): 5919 case cpu_to_be16(ETH_P_IP):
@@ -5943,7 +5941,7 @@ static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb)
5943 default: 5941 default:
5944 if (unlikely(net_ratelimit())) 5942 if (unlikely(net_ratelimit()))
5945 e_warn(probe, "partial checksum but proto=%x!\n", 5943 e_warn(probe, "partial checksum but proto=%x!\n",
5946 skb->protocol); 5944 protocol);
5947 break; 5945 break;
5948 } 5946 }
5949 5947
@@ -5952,7 +5950,8 @@ static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb)
5952 5950
5953static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, 5951static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
5954 struct ixgbe_ring *tx_ring, 5952 struct ixgbe_ring *tx_ring,
5955 struct sk_buff *skb, u32 tx_flags) 5953 struct sk_buff *skb, u32 tx_flags,
5954 __be16 protocol)
5956{ 5955{
5957 struct ixgbe_adv_tx_context_desc *context_desc; 5956 struct ixgbe_adv_tx_context_desc *context_desc;
5958 unsigned int i; 5957 unsigned int i;
@@ -5981,7 +5980,7 @@ static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
5981 IXGBE_ADVTXD_DTYP_CTXT); 5980 IXGBE_ADVTXD_DTYP_CTXT);
5982 5981
5983 if (skb->ip_summed == CHECKSUM_PARTIAL) 5982 if (skb->ip_summed == CHECKSUM_PARTIAL)
5984 type_tucmd_mlhl |= ixgbe_psum(adapter, skb); 5983 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
5985 5984
5986 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); 5985 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
5987 /* use index zero for tx checksum offload */ 5986 /* use index zero for tx checksum offload */
@@ -6179,7 +6178,7 @@ static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
6179} 6178}
6180 6179
6181static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, 6180static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6182 int queue, u32 tx_flags) 6181 int queue, u32 tx_flags, __be16 protocol)
6183{ 6182{
6184 struct ixgbe_atr_input atr_input; 6183 struct ixgbe_atr_input atr_input;
6185 struct tcphdr *th; 6184 struct tcphdr *th;
@@ -6190,7 +6189,7 @@ static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6190 u8 l4type = 0; 6189 u8 l4type = 0;
6191 6190
6192 /* Right now, we support IPv4 only */ 6191 /* Right now, we support IPv4 only */
6193 if (skb->protocol != htons(ETH_P_IP)) 6192 if (protocol != htons(ETH_P_IP))
6194 return; 6193 return;
6195 /* check if we're UDP or TCP */ 6194 /* check if we're UDP or TCP */
6196 if (iph->protocol == IPPROTO_TCP) { 6195 if (iph->protocol == IPPROTO_TCP) {
@@ -6257,10 +6256,13 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6257{ 6256{
6258 struct ixgbe_adapter *adapter = netdev_priv(dev); 6257 struct ixgbe_adapter *adapter = netdev_priv(dev);
6259 int txq = smp_processor_id(); 6258 int txq = smp_processor_id();
6260
6261#ifdef IXGBE_FCOE 6259#ifdef IXGBE_FCOE
6262 if ((skb->protocol == htons(ETH_P_FCOE)) || 6260 __be16 protocol;
6263 (skb->protocol == htons(ETH_P_FIP))) { 6261
6262 protocol = vlan_get_protocol(skb);
6263
6264 if ((protocol == htons(ETH_P_FCOE)) ||
6265 (protocol == htons(ETH_P_FIP))) {
6264 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { 6266 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
6265 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); 6267 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6266 txq += adapter->ring_feature[RING_F_FCOE].mask; 6268 txq += adapter->ring_feature[RING_F_FCOE].mask;
@@ -6303,6 +6305,9 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, struct net_device *netdev
6303 int tso; 6305 int tso;
6304 int count = 0; 6306 int count = 0;
6305 unsigned int f; 6307 unsigned int f;
6308 __be16 protocol;
6309
6310 protocol = vlan_get_protocol(skb);
6306 6311
6307 if (vlan_tx_tag_present(skb)) { 6312 if (vlan_tx_tag_present(skb)) {
6308 tx_flags |= vlan_tx_tag_get(skb); 6313 tx_flags |= vlan_tx_tag_get(skb);
@@ -6323,8 +6328,8 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, struct net_device *netdev
6323 /* for FCoE with DCB, we force the priority to what 6328 /* for FCoE with DCB, we force the priority to what
6324 * was specified by the switch */ 6329 * was specified by the switch */
6325 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED && 6330 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
6326 (skb->protocol == htons(ETH_P_FCOE) || 6331 (protocol == htons(ETH_P_FCOE) ||
6327 skb->protocol == htons(ETH_P_FIP))) { 6332 protocol == htons(ETH_P_FIP))) {
6328#ifdef CONFIG_IXGBE_DCB 6333#ifdef CONFIG_IXGBE_DCB
6329 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { 6334 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6330 tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK 6335 tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
@@ -6334,7 +6339,7 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, struct net_device *netdev
6334 } 6339 }
6335#endif 6340#endif
6336 /* flag for FCoE offloads */ 6341 /* flag for FCoE offloads */
6337 if (skb->protocol == htons(ETH_P_FCOE)) 6342 if (protocol == htons(ETH_P_FCOE))
6338 tx_flags |= IXGBE_TX_FLAGS_FCOE; 6343 tx_flags |= IXGBE_TX_FLAGS_FCOE;
6339 } 6344 }
6340#endif 6345#endif
@@ -6368,9 +6373,10 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, struct net_device *netdev
6368 tx_flags |= IXGBE_TX_FLAGS_FSO; 6373 tx_flags |= IXGBE_TX_FLAGS_FSO;
6369#endif /* IXGBE_FCOE */ 6374#endif /* IXGBE_FCOE */
6370 } else { 6375 } else {
6371 if (skb->protocol == htons(ETH_P_IP)) 6376 if (protocol == htons(ETH_P_IP))
6372 tx_flags |= IXGBE_TX_FLAGS_IPV4; 6377 tx_flags |= IXGBE_TX_FLAGS_IPV4;
6373 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); 6378 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6379 protocol);
6374 if (tso < 0) { 6380 if (tso < 0) {
6375 dev_kfree_skb_any(skb); 6381 dev_kfree_skb_any(skb);
6376 return NETDEV_TX_OK; 6382 return NETDEV_TX_OK;
@@ -6378,7 +6384,8 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, struct net_device *netdev
6378 6384
6379 if (tso) 6385 if (tso)
6380 tx_flags |= IXGBE_TX_FLAGS_TSO; 6386 tx_flags |= IXGBE_TX_FLAGS_TSO;
6381 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && 6387 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6388 protocol) &&
6382 (skb->ip_summed == CHECKSUM_PARTIAL)) 6389 (skb->ip_summed == CHECKSUM_PARTIAL))
6383 tx_flags |= IXGBE_TX_FLAGS_CSUM; 6390 tx_flags |= IXGBE_TX_FLAGS_CSUM;
6384 } 6391 }
@@ -6392,7 +6399,7 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, struct net_device *netdev
6392 test_bit(__IXGBE_FDIR_INIT_DONE, 6399 test_bit(__IXGBE_FDIR_INIT_DONE,
6393 &tx_ring->reinit_state)) { 6400 &tx_ring->reinit_state)) {
6394 ixgbe_atr(adapter, skb, tx_ring->queue_index, 6401 ixgbe_atr(adapter, skb, tx_ring->queue_index,
6395 tx_flags); 6402 tx_flags, protocol);
6396 tx_ring->atr_count = 0; 6403 tx_ring->atr_count = 0;
6397 } 6404 }
6398 } 6405 }
diff --git a/drivers/net/jme.c b/drivers/net/jme.c
index d85edf3119c2..c57d9a43ceca 100644
--- a/drivers/net/jme.c
+++ b/drivers/net/jme.c
@@ -2955,11 +2955,7 @@ jme_init_one(struct pci_dev *pdev,
2955 * Tell stack that we are not ready to work until open() 2955 * Tell stack that we are not ready to work until open()
2956 */ 2956 */
2957 netif_carrier_off(netdev); 2957 netif_carrier_off(netdev);
2958 netif_stop_queue(netdev);
2959 2958
2960 /*
2961 * Register netdev
2962 */
2963 rc = register_netdev(netdev); 2959 rc = register_netdev(netdev);
2964 if (rc) { 2960 if (rc) {
2965 pr_err("Cannot register net device\n"); 2961 pr_err("Cannot register net device\n");
diff --git a/drivers/net/mlx4/fw.c b/drivers/net/mlx4/fw.c
index b68eee2414c2..7a7e18ba278a 100644
--- a/drivers/net/mlx4/fw.c
+++ b/drivers/net/mlx4/fw.c
@@ -289,6 +289,10 @@ int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
289 MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET); 289 MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET);
290 dev_cap->bf_reg_size = 1 << (field & 0x1f); 290 dev_cap->bf_reg_size = 1 << (field & 0x1f);
291 MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET); 291 MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET);
292 if ((1 << (field & 0x3f)) > (PAGE_SIZE / dev_cap->bf_reg_size)) {
293 mlx4_warn(dev, "firmware bug: log2 # of blue flame regs is invalid (%d), forcing 3\n", field & 0x1f);
294 field = 3;
295 }
292 dev_cap->bf_regs_per_page = 1 << (field & 0x3f); 296 dev_cap->bf_regs_per_page = 1 << (field & 0x3f);
293 mlx4_dbg(dev, "BlueFlame available (reg size %d, regs/page %d)\n", 297 mlx4_dbg(dev, "BlueFlame available (reg size %d, regs/page %d)\n",
294 dev_cap->bf_reg_size, dev_cap->bf_regs_per_page); 298 dev_cap->bf_reg_size, dev_cap->bf_regs_per_page);
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 35ae1aa12896..e1d30d7f2071 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -41,9 +41,6 @@
41MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Converged Ethernet Driver"); 41MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Converged Ethernet Driver");
42MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
43MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); 43MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
44MODULE_FIRMWARE(NX_P2_MN_ROMIMAGE_NAME);
45MODULE_FIRMWARE(NX_P3_CT_ROMIMAGE_NAME);
46MODULE_FIRMWARE(NX_P3_MN_ROMIMAGE_NAME);
47MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME); 44MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME);
48 45
49char netxen_nic_driver_name[] = "netxen_nic"; 46char netxen_nic_driver_name[] = "netxen_nic";
@@ -1240,7 +1237,6 @@ netxen_setup_netdev(struct netxen_adapter *adapter,
1240 dev_warn(&pdev->dev, "failed to read mac addr\n"); 1237 dev_warn(&pdev->dev, "failed to read mac addr\n");
1241 1238
1242 netif_carrier_off(netdev); 1239 netif_carrier_off(netdev);
1243 netif_stop_queue(netdev);
1244 1240
1245 err = register_netdev(netdev); 1241 err = register_netdev(netdev);
1246 if (err) { 1242 if (err) {
diff --git a/drivers/net/pch_gbe/pch_gbe_main.c b/drivers/net/pch_gbe/pch_gbe_main.c
index 472056b47440..03a1d280105f 100644
--- a/drivers/net/pch_gbe/pch_gbe_main.c
+++ b/drivers/net/pch_gbe/pch_gbe_main.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation. 2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. 3 * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD.
4 * 4 *
5 * This code was derived from the Intel e1000e Linux driver. 5 * This code was derived from the Intel e1000e Linux driver.
6 * 6 *
@@ -2464,8 +2464,8 @@ static void __exit pch_gbe_exit_module(void)
2464module_init(pch_gbe_init_module); 2464module_init(pch_gbe_init_module);
2465module_exit(pch_gbe_exit_module); 2465module_exit(pch_gbe_exit_module);
2466 2466
2467MODULE_DESCRIPTION("OKI semiconductor PCH Gigabit ethernet Driver"); 2467MODULE_DESCRIPTION("EG20T PCH Gigabit ethernet Driver");
2468MODULE_AUTHOR("OKI semiconductor, <masa-korg@dsn.okisemi.com>"); 2468MODULE_AUTHOR("OKI SEMICONDUCTOR, <toshiharu-linux@dsn.okisemi.com>");
2469MODULE_LICENSE("GPL"); 2469MODULE_LICENSE("GPL");
2470MODULE_VERSION(DRV_VERSION); 2470MODULE_VERSION(DRV_VERSION);
2471MODULE_DEVICE_TABLE(pci, pch_gbe_pcidev_id); 2471MODULE_DEVICE_TABLE(pci, pch_gbe_pcidev_id);
diff --git a/drivers/net/pch_gbe/pch_gbe_param.c b/drivers/net/pch_gbe/pch_gbe_param.c
index 2510146fc560..ef0996a0eaaa 100644
--- a/drivers/net/pch_gbe/pch_gbe_param.c
+++ b/drivers/net/pch_gbe/pch_gbe_param.c
@@ -434,8 +434,8 @@ void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
434 .err = "using default of " 434 .err = "using default of "
435 __MODULE_STRING(PCH_GBE_DEFAULT_TXD), 435 __MODULE_STRING(PCH_GBE_DEFAULT_TXD),
436 .def = PCH_GBE_DEFAULT_TXD, 436 .def = PCH_GBE_DEFAULT_TXD,
437 .arg = { .r = { .min = PCH_GBE_MIN_TXD } }, 437 .arg = { .r = { .min = PCH_GBE_MIN_TXD,
438 .arg = { .r = { .max = PCH_GBE_MAX_TXD } } 438 .max = PCH_GBE_MAX_TXD } }
439 }; 439 };
440 struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring; 440 struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
441 tx_ring->count = TxDescriptors; 441 tx_ring->count = TxDescriptors;
@@ -450,8 +450,8 @@ void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
450 .err = "using default of " 450 .err = "using default of "
451 __MODULE_STRING(PCH_GBE_DEFAULT_RXD), 451 __MODULE_STRING(PCH_GBE_DEFAULT_RXD),
452 .def = PCH_GBE_DEFAULT_RXD, 452 .def = PCH_GBE_DEFAULT_RXD,
453 .arg = { .r = { .min = PCH_GBE_MIN_RXD } }, 453 .arg = { .r = { .min = PCH_GBE_MIN_RXD,
454 .arg = { .r = { .max = PCH_GBE_MAX_RXD } } 454 .max = PCH_GBE_MAX_RXD } }
455 }; 455 };
456 struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring; 456 struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
457 rx_ring->count = RxDescriptors; 457 rx_ring->count = RxDescriptors;
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index d2e166e29dda..8a4d19e5de06 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -111,13 +111,14 @@ static irqreturn_t ax_interrupt(int irq, void *dev_id);
111 111
112typedef struct axnet_dev_t { 112typedef struct axnet_dev_t {
113 struct pcmcia_device *p_dev; 113 struct pcmcia_device *p_dev;
114 caddr_t base; 114 caddr_t base;
115 struct timer_list watchdog; 115 struct timer_list watchdog;
116 int stale, fast_poll; 116 int stale, fast_poll;
117 u_short link_status; 117 u_short link_status;
118 u_char duplex_flag; 118 u_char duplex_flag;
119 int phy_id; 119 int phy_id;
120 int flags; 120 int flags;
121 int active_low;
121} axnet_dev_t; 122} axnet_dev_t;
122 123
123static inline axnet_dev_t *PRIV(struct net_device *dev) 124static inline axnet_dev_t *PRIV(struct net_device *dev)
@@ -322,6 +323,8 @@ static int axnet_config(struct pcmcia_device *link)
322 if (info->flags & IS_AX88790) 323 if (info->flags & IS_AX88790)
323 outb(0x10, dev->base_addr + AXNET_GPIO); /* select Internal PHY */ 324 outb(0x10, dev->base_addr + AXNET_GPIO); /* select Internal PHY */
324 325
326 info->active_low = 0;
327
325 for (i = 0; i < 32; i++) { 328 for (i = 0; i < 32; i++) {
326 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1); 329 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
327 j2 = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 2); 330 j2 = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 2);
@@ -329,15 +332,18 @@ static int axnet_config(struct pcmcia_device *link)
329 if ((j != 0) && (j != 0xffff)) break; 332 if ((j != 0) && (j != 0xffff)) break;
330 } 333 }
331 334
332 /* Maybe PHY is in power down mode. (PPD_SET = 1)
333 Bit 2 of CCSR is active low. */
334 if (i == 32) { 335 if (i == 32) {
336 /* Maybe PHY is in power down mode. (PPD_SET = 1)
337 Bit 2 of CCSR is active low. */
335 pcmcia_write_config_byte(link, CISREG_CCSR, 0x04); 338 pcmcia_write_config_byte(link, CISREG_CCSR, 0x04);
336 for (i = 0; i < 32; i++) { 339 for (i = 0; i < 32; i++) {
337 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1); 340 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
338 j2 = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 2); 341 j2 = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 2);
339 if (j == j2) continue; 342 if (j == j2) continue;
340 if ((j != 0) && (j != 0xffff)) break; 343 if ((j != 0) && (j != 0xffff)) {
344 info->active_low = 1;
345 break;
346 }
341 } 347 }
342 } 348 }
343 349
@@ -383,8 +389,12 @@ static int axnet_suspend(struct pcmcia_device *link)
383static int axnet_resume(struct pcmcia_device *link) 389static int axnet_resume(struct pcmcia_device *link)
384{ 390{
385 struct net_device *dev = link->priv; 391 struct net_device *dev = link->priv;
392 axnet_dev_t *info = PRIV(dev);
386 393
387 if (link->open) { 394 if (link->open) {
395 if (info->active_low == 1)
396 pcmcia_write_config_byte(link, CISREG_CCSR, 0x04);
397
388 axnet_reset_8390(dev); 398 axnet_reset_8390(dev);
389 AX88190_init(dev, 1); 399 AX88190_init(dev, 1);
390 netif_device_attach(dev); 400 netif_device_attach(dev);
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index 03096c80103d..d05c44692f08 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -1536,6 +1536,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1536 PCMCIA_DEVICE_PROD_ID12("COMPU-SHACK", "FASTline PCMCIA 10/100 Fast-Ethernet", 0xfa2e424d, 0x3953d9b9), 1536 PCMCIA_DEVICE_PROD_ID12("COMPU-SHACK", "FASTline PCMCIA 10/100 Fast-Ethernet", 0xfa2e424d, 0x3953d9b9),
1537 PCMCIA_DEVICE_PROD_ID12("CONTEC", "C-NET(PC)C-10L", 0x21cab552, 0xf6f90722), 1537 PCMCIA_DEVICE_PROD_ID12("CONTEC", "C-NET(PC)C-10L", 0x21cab552, 0xf6f90722),
1538 PCMCIA_DEVICE_PROD_ID12("corega", "FEther PCC-TXF", 0x0a21501a, 0xa51564a2), 1538 PCMCIA_DEVICE_PROD_ID12("corega", "FEther PCC-TXF", 0x0a21501a, 0xa51564a2),
1539 PCMCIA_DEVICE_PROD_ID12("corega", "Ether CF-TD", 0x0a21501a, 0x6589340a),
1539 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega EtherII PCC-T", 0x5261440f, 0xfa9d85bd), 1540 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega EtherII PCC-T", 0x5261440f, 0xfa9d85bd),
1540 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega EtherII PCC-TD", 0x5261440f, 0xc49bd73d), 1541 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega EtherII PCC-TD", 0x5261440f, 0xc49bd73d),
1541 PCMCIA_DEVICE_PROD_ID12("Corega K.K.", "corega EtherII PCC-TD", 0xd4fdcbd8, 0xc49bd73d), 1542 PCMCIA_DEVICE_PROD_ID12("Corega K.K.", "corega EtherII PCC-TD", 0xd4fdcbd8, 0xc49bd73d),
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index cb3d13e4e074..35fda5ac8120 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -64,7 +64,7 @@ config BCM63XX_PHY
64config ICPLUS_PHY 64config ICPLUS_PHY
65 tristate "Drivers for ICPlus PHYs" 65 tristate "Drivers for ICPlus PHYs"
66 ---help--- 66 ---help---
67 Currently supports the IP175C PHY. 67 Currently supports the IP175C and IP1001 PHYs.
68 68
69config REALTEK_PHY 69config REALTEK_PHY
70 tristate "Drivers for Realtek PHYs" 70 tristate "Drivers for Realtek PHYs"
diff --git a/drivers/net/phy/icplus.c b/drivers/net/phy/icplus.c
index c1d2d251fe8b..9a09e24c30bc 100644
--- a/drivers/net/phy/icplus.c
+++ b/drivers/net/phy/icplus.c
@@ -30,7 +30,7 @@
30#include <asm/irq.h> 30#include <asm/irq.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32 32
33MODULE_DESCRIPTION("ICPlus IP175C PHY driver"); 33MODULE_DESCRIPTION("ICPlus IP175C/IC1001 PHY drivers");
34MODULE_AUTHOR("Michael Barkowski"); 34MODULE_AUTHOR("Michael Barkowski");
35MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
36 36
@@ -89,6 +89,33 @@ static int ip175c_config_init(struct phy_device *phydev)
89 return 0; 89 return 0;
90} 90}
91 91
92static int ip1001_config_init(struct phy_device *phydev)
93{
94 int err, value;
95
96 /* Software Reset PHY */
97 value = phy_read(phydev, MII_BMCR);
98 value |= BMCR_RESET;
99 err = phy_write(phydev, MII_BMCR, value);
100 if (err < 0)
101 return err;
102
103 do {
104 value = phy_read(phydev, MII_BMCR);
105 } while (value & BMCR_RESET);
106
107 /* Additional delay (2ns) used to adjust RX clock phase
108 * at GMII/ RGMII interface */
109 value = phy_read(phydev, 16);
110 value |= 0x3;
111
112 err = phy_write(phydev, 16, value);
113 if (err < 0)
114 return err;
115
116 return err;
117}
118
92static int ip175c_read_status(struct phy_device *phydev) 119static int ip175c_read_status(struct phy_device *phydev)
93{ 120{
94 if (phydev->addr == 4) /* WAN port */ 121 if (phydev->addr == 4) /* WAN port */
@@ -121,21 +148,43 @@ static struct phy_driver ip175c_driver = {
121 .driver = { .owner = THIS_MODULE,}, 148 .driver = { .owner = THIS_MODULE,},
122}; 149};
123 150
124static int __init ip175c_init(void) 151static struct phy_driver ip1001_driver = {
152 .phy_id = 0x02430d90,
153 .name = "ICPlus IP1001",
154 .phy_id_mask = 0x0ffffff0,
155 .features = PHY_GBIT_FEATURES | SUPPORTED_Pause |
156 SUPPORTED_Asym_Pause,
157 .config_init = &ip1001_config_init,
158 .config_aneg = &genphy_config_aneg,
159 .read_status = &genphy_read_status,
160 .suspend = genphy_suspend,
161 .resume = genphy_resume,
162 .driver = { .owner = THIS_MODULE,},
163};
164
165static int __init icplus_init(void)
125{ 166{
167 int ret = 0;
168
169 ret = phy_driver_register(&ip1001_driver);
170 if (ret < 0)
171 return -ENODEV;
172
126 return phy_driver_register(&ip175c_driver); 173 return phy_driver_register(&ip175c_driver);
127} 174}
128 175
129static void __exit ip175c_exit(void) 176static void __exit icplus_exit(void)
130{ 177{
178 phy_driver_unregister(&ip1001_driver);
131 phy_driver_unregister(&ip175c_driver); 179 phy_driver_unregister(&ip175c_driver);
132} 180}
133 181
134module_init(ip175c_init); 182module_init(icplus_init);
135module_exit(ip175c_exit); 183module_exit(icplus_exit);
136 184
137static struct mdio_device_id __maybe_unused icplus_tbl[] = { 185static struct mdio_device_id __maybe_unused icplus_tbl[] = {
138 { 0x02430d80, 0x0ffffff0 }, 186 { 0x02430d80, 0x0ffffff0 },
187 { 0x02430d90, 0x0ffffff0 },
139 { } 188 { }
140}; 189};
141 190
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index e2afdce0a437..e8b9c53c304b 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -30,11 +30,14 @@
30#include <linux/ethtool.h> 30#include <linux/ethtool.h>
31#include <linux/phy.h> 31#include <linux/phy.h>
32#include <linux/marvell_phy.h> 32#include <linux/marvell_phy.h>
33#include <linux/of.h>
33 34
34#include <asm/io.h> 35#include <asm/io.h>
35#include <asm/irq.h> 36#include <asm/irq.h>
36#include <asm/uaccess.h> 37#include <asm/uaccess.h>
37 38
39#define MII_MARVELL_PHY_PAGE 22
40
38#define MII_M1011_IEVENT 0x13 41#define MII_M1011_IEVENT 0x13
39#define MII_M1011_IEVENT_CLEAR 0x0000 42#define MII_M1011_IEVENT_CLEAR 0x0000
40 43
@@ -74,13 +77,12 @@
74#define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4) 77#define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
75#define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4)) 78#define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4))
76 79
77#define MII_88EC048_PHY_MSCR1_REG 16 80#define MII_88E1318S_PHY_MSCR1_REG 16
78#define MII_88EC048_PHY_MSCR1_PAD_ODD BIT(6) 81#define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
79 82
80#define MII_88E1121_PHY_LED_CTRL 16 83#define MII_88E1121_PHY_LED_CTRL 16
81#define MII_88E1121_PHY_LED_PAGE 3 84#define MII_88E1121_PHY_LED_PAGE 3
82#define MII_88E1121_PHY_LED_DEF 0x0030 85#define MII_88E1121_PHY_LED_DEF 0x0030
83#define MII_88E1121_PHY_PAGE 22
84 86
85#define MII_M1011_PHY_STATUS 0x11 87#define MII_M1011_PHY_STATUS 0x11
86#define MII_M1011_PHY_STATUS_1000 0x8000 88#define MII_M1011_PHY_STATUS_1000 0x8000
@@ -186,13 +188,94 @@ static int marvell_config_aneg(struct phy_device *phydev)
186 return 0; 188 return 0;
187} 189}
188 190
191#ifdef CONFIG_OF_MDIO
192/*
193 * Set and/or override some configuration registers based on the
194 * marvell,reg-init property stored in the of_node for the phydev.
195 *
196 * marvell,reg-init = <reg-page reg mask value>,...;
197 *
198 * There may be one or more sets of <reg-page reg mask value>:
199 *
200 * reg-page: which register bank to use.
201 * reg: the register.
202 * mask: if non-zero, ANDed with existing register value.
203 * value: ORed with the masked value and written to the regiser.
204 *
205 */
206static int marvell_of_reg_init(struct phy_device *phydev)
207{
208 const __be32 *paddr;
209 int len, i, saved_page, current_page, page_changed, ret;
210
211 if (!phydev->dev.of_node)
212 return 0;
213
214 paddr = of_get_property(phydev->dev.of_node, "marvell,reg-init", &len);
215 if (!paddr || len < (4 * sizeof(*paddr)))
216 return 0;
217
218 saved_page = phy_read(phydev, MII_MARVELL_PHY_PAGE);
219 if (saved_page < 0)
220 return saved_page;
221 page_changed = 0;
222 current_page = saved_page;
223
224 ret = 0;
225 len /= sizeof(*paddr);
226 for (i = 0; i < len - 3; i += 4) {
227 u16 reg_page = be32_to_cpup(paddr + i);
228 u16 reg = be32_to_cpup(paddr + i + 1);
229 u16 mask = be32_to_cpup(paddr + i + 2);
230 u16 val_bits = be32_to_cpup(paddr + i + 3);
231 int val;
232
233 if (reg_page != current_page) {
234 current_page = reg_page;
235 page_changed = 1;
236 ret = phy_write(phydev, MII_MARVELL_PHY_PAGE, reg_page);
237 if (ret < 0)
238 goto err;
239 }
240
241 val = 0;
242 if (mask) {
243 val = phy_read(phydev, reg);
244 if (val < 0) {
245 ret = val;
246 goto err;
247 }
248 val &= mask;
249 }
250 val |= val_bits;
251
252 ret = phy_write(phydev, reg, val);
253 if (ret < 0)
254 goto err;
255
256 }
257err:
258 if (page_changed) {
259 i = phy_write(phydev, MII_MARVELL_PHY_PAGE, saved_page);
260 if (ret == 0)
261 ret = i;
262 }
263 return ret;
264}
265#else
266static int marvell_of_reg_init(struct phy_device *phydev)
267{
268 return 0;
269}
270#endif /* CONFIG_OF_MDIO */
271
189static int m88e1121_config_aneg(struct phy_device *phydev) 272static int m88e1121_config_aneg(struct phy_device *phydev)
190{ 273{
191 int err, oldpage, mscr; 274 int err, oldpage, mscr;
192 275
193 oldpage = phy_read(phydev, MII_88E1121_PHY_PAGE); 276 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
194 277
195 err = phy_write(phydev, MII_88E1121_PHY_PAGE, 278 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
196 MII_88E1121_PHY_MSCR_PAGE); 279 MII_88E1121_PHY_MSCR_PAGE);
197 if (err < 0) 280 if (err < 0)
198 return err; 281 return err;
@@ -218,7 +301,7 @@ static int m88e1121_config_aneg(struct phy_device *phydev)
218 return err; 301 return err;
219 } 302 }
220 303
221 phy_write(phydev, MII_88E1121_PHY_PAGE, oldpage); 304 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
222 305
223 err = phy_write(phydev, MII_BMCR, BMCR_RESET); 306 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
224 if (err < 0) 307 if (err < 0)
@@ -229,36 +312,36 @@ static int m88e1121_config_aneg(struct phy_device *phydev)
229 if (err < 0) 312 if (err < 0)
230 return err; 313 return err;
231 314
232 oldpage = phy_read(phydev, MII_88E1121_PHY_PAGE); 315 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
233 316
234 phy_write(phydev, MII_88E1121_PHY_PAGE, MII_88E1121_PHY_LED_PAGE); 317 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_88E1121_PHY_LED_PAGE);
235 phy_write(phydev, MII_88E1121_PHY_LED_CTRL, MII_88E1121_PHY_LED_DEF); 318 phy_write(phydev, MII_88E1121_PHY_LED_CTRL, MII_88E1121_PHY_LED_DEF);
236 phy_write(phydev, MII_88E1121_PHY_PAGE, oldpage); 319 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
237 320
238 err = genphy_config_aneg(phydev); 321 err = genphy_config_aneg(phydev);
239 322
240 return err; 323 return err;
241} 324}
242 325
243static int m88ec048_config_aneg(struct phy_device *phydev) 326static int m88e1318_config_aneg(struct phy_device *phydev)
244{ 327{
245 int err, oldpage, mscr; 328 int err, oldpage, mscr;
246 329
247 oldpage = phy_read(phydev, MII_88E1121_PHY_PAGE); 330 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
248 331
249 err = phy_write(phydev, MII_88E1121_PHY_PAGE, 332 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
250 MII_88E1121_PHY_MSCR_PAGE); 333 MII_88E1121_PHY_MSCR_PAGE);
251 if (err < 0) 334 if (err < 0)
252 return err; 335 return err;
253 336
254 mscr = phy_read(phydev, MII_88EC048_PHY_MSCR1_REG); 337 mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG);
255 mscr |= MII_88EC048_PHY_MSCR1_PAD_ODD; 338 mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD;
256 339
257 err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr); 340 err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr);
258 if (err < 0) 341 if (err < 0)
259 return err; 342 return err;
260 343
261 err = phy_write(phydev, MII_88E1121_PHY_PAGE, oldpage); 344 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
262 if (err < 0) 345 if (err < 0)
263 return err; 346 return err;
264 347
@@ -368,6 +451,9 @@ static int m88e1111_config_init(struct phy_device *phydev)
368 return err; 451 return err;
369 } 452 }
370 453
454 err = marvell_of_reg_init(phydev);
455 if (err < 0)
456 return err;
371 457
372 err = phy_write(phydev, MII_BMCR, BMCR_RESET); 458 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
373 if (err < 0) 459 if (err < 0)
@@ -398,7 +484,7 @@ static int m88e1118_config_init(struct phy_device *phydev)
398 int err; 484 int err;
399 485
400 /* Change address */ 486 /* Change address */
401 err = phy_write(phydev, 0x16, 0x0002); 487 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
402 if (err < 0) 488 if (err < 0)
403 return err; 489 return err;
404 490
@@ -408,7 +494,7 @@ static int m88e1118_config_init(struct phy_device *phydev)
408 return err; 494 return err;
409 495
410 /* Change address */ 496 /* Change address */
411 err = phy_write(phydev, 0x16, 0x0003); 497 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0003);
412 if (err < 0) 498 if (err < 0)
413 return err; 499 return err;
414 500
@@ -420,8 +506,42 @@ static int m88e1118_config_init(struct phy_device *phydev)
420 if (err < 0) 506 if (err < 0)
421 return err; 507 return err;
422 508
509 err = marvell_of_reg_init(phydev);
510 if (err < 0)
511 return err;
512
423 /* Reset address */ 513 /* Reset address */
424 err = phy_write(phydev, 0x16, 0x0); 514 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
515 if (err < 0)
516 return err;
517
518 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
519 if (err < 0)
520 return err;
521
522 return 0;
523}
524
525static int m88e1149_config_init(struct phy_device *phydev)
526{
527 int err;
528
529 /* Change address */
530 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
531 if (err < 0)
532 return err;
533
534 /* Enable 1000 Mbit */
535 err = phy_write(phydev, 0x15, 0x1048);
536 if (err < 0)
537 return err;
538
539 err = marvell_of_reg_init(phydev);
540 if (err < 0)
541 return err;
542
543 /* Reset address */
544 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
425 if (err < 0) 545 if (err < 0)
426 return err; 546 return err;
427 547
@@ -491,6 +611,10 @@ static int m88e1145_config_init(struct phy_device *phydev)
491 } 611 }
492 } 612 }
493 613
614 err = marvell_of_reg_init(phydev);
615 if (err < 0)
616 return err;
617
494 return 0; 618 return 0;
495} 619}
496 620
@@ -659,12 +783,12 @@ static struct phy_driver marvell_drivers[] = {
659 .driver = { .owner = THIS_MODULE }, 783 .driver = { .owner = THIS_MODULE },
660 }, 784 },
661 { 785 {
662 .phy_id = MARVELL_PHY_ID_88EC048, 786 .phy_id = MARVELL_PHY_ID_88E1318S,
663 .phy_id_mask = MARVELL_PHY_ID_MASK, 787 .phy_id_mask = MARVELL_PHY_ID_MASK,
664 .name = "Marvell 88EC048", 788 .name = "Marvell 88E1318S",
665 .features = PHY_GBIT_FEATURES, 789 .features = PHY_GBIT_FEATURES,
666 .flags = PHY_HAS_INTERRUPT, 790 .flags = PHY_HAS_INTERRUPT,
667 .config_aneg = &m88ec048_config_aneg, 791 .config_aneg = &m88e1318_config_aneg,
668 .read_status = &marvell_read_status, 792 .read_status = &marvell_read_status,
669 .ack_interrupt = &marvell_ack_interrupt, 793 .ack_interrupt = &marvell_ack_interrupt,
670 .config_intr = &marvell_config_intr, 794 .config_intr = &marvell_config_intr,
@@ -685,6 +809,19 @@ static struct phy_driver marvell_drivers[] = {
685 .driver = { .owner = THIS_MODULE }, 809 .driver = { .owner = THIS_MODULE },
686 }, 810 },
687 { 811 {
812 .phy_id = MARVELL_PHY_ID_88E1149R,
813 .phy_id_mask = MARVELL_PHY_ID_MASK,
814 .name = "Marvell 88E1149R",
815 .features = PHY_GBIT_FEATURES,
816 .flags = PHY_HAS_INTERRUPT,
817 .config_init = &m88e1149_config_init,
818 .config_aneg = &m88e1118_config_aneg,
819 .read_status = &genphy_read_status,
820 .ack_interrupt = &marvell_ack_interrupt,
821 .config_intr = &marvell_config_intr,
822 .driver = { .owner = THIS_MODULE },
823 },
824 {
688 .phy_id = MARVELL_PHY_ID_88E1240, 825 .phy_id = MARVELL_PHY_ID_88E1240,
689 .phy_id_mask = MARVELL_PHY_ID_MASK, 826 .phy_id_mask = MARVELL_PHY_ID_MASK,
690 .name = "Marvell 88E1240", 827 .name = "Marvell 88E1240",
@@ -735,6 +872,7 @@ static struct mdio_device_id __maybe_unused marvell_tbl[] = {
735 { 0x01410e10, 0xfffffff0 }, 872 { 0x01410e10, 0xfffffff0 },
736 { 0x01410cb0, 0xfffffff0 }, 873 { 0x01410cb0, 0xfffffff0 },
737 { 0x01410cd0, 0xfffffff0 }, 874 { 0x01410cd0, 0xfffffff0 },
875 { 0x01410e50, 0xfffffff0 },
738 { 0x01410e30, 0xfffffff0 }, 876 { 0x01410e30, 0xfffffff0 },
739 { 0x01410e90, 0xfffffff0 }, 877 { 0x01410e90, 0xfffffff0 },
740 { } 878 { }
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 09cf56d0416a..39659976a1ac 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -2584,16 +2584,16 @@ ppp_create_interface(struct net *net, int unit, int *retp)
2584 */ 2584 */
2585 dev_net_set(dev, net); 2585 dev_net_set(dev, net);
2586 2586
2587 ret = -EEXIST;
2588 mutex_lock(&pn->all_ppp_mutex); 2587 mutex_lock(&pn->all_ppp_mutex);
2589 2588
2590 if (unit < 0) { 2589 if (unit < 0) {
2591 unit = unit_get(&pn->units_idr, ppp); 2590 unit = unit_get(&pn->units_idr, ppp);
2592 if (unit < 0) { 2591 if (unit < 0) {
2593 *retp = unit; 2592 ret = unit;
2594 goto out2; 2593 goto out2;
2595 } 2594 }
2596 } else { 2595 } else {
2596 ret = -EEXIST;
2597 if (unit_find(&pn->units_idr, unit)) 2597 if (unit_find(&pn->units_idr, unit))
2598 goto out2; /* unit already exists */ 2598 goto out2; /* unit already exists */
2599 /* 2599 /*
@@ -2668,10 +2668,10 @@ static void ppp_shutdown_interface(struct ppp *ppp)
2668 ppp->closing = 1; 2668 ppp->closing = 1;
2669 ppp_unlock(ppp); 2669 ppp_unlock(ppp);
2670 unregister_netdev(ppp->dev); 2670 unregister_netdev(ppp->dev);
2671 unit_put(&pn->units_idr, ppp->file.index);
2671 } else 2672 } else
2672 ppp_unlock(ppp); 2673 ppp_unlock(ppp);
2673 2674
2674 unit_put(&pn->units_idr, ppp->file.index);
2675 ppp->file.dead = 1; 2675 ppp->file.dead = 1;
2676 ppp->owner = NULL; 2676 ppp->owner = NULL;
2677 wake_up_interruptible(&ppp->file.rwait); 2677 wake_up_interruptible(&ppp->file.rwait);
@@ -2859,8 +2859,7 @@ static void __exit ppp_cleanup(void)
2859 * by holding all_ppp_mutex 2859 * by holding all_ppp_mutex
2860 */ 2860 */
2861 2861
2862/* associate pointer with specified number */ 2862static int __unit_alloc(struct idr *p, void *ptr, int n)
2863static int unit_set(struct idr *p, void *ptr, int n)
2864{ 2863{
2865 int unit, err; 2864 int unit, err;
2866 2865
@@ -2871,10 +2870,24 @@ again:
2871 } 2870 }
2872 2871
2873 err = idr_get_new_above(p, ptr, n, &unit); 2872 err = idr_get_new_above(p, ptr, n, &unit);
2874 if (err == -EAGAIN) 2873 if (err < 0) {
2875 goto again; 2874 if (err == -EAGAIN)
2875 goto again;
2876 return err;
2877 }
2878
2879 return unit;
2880}
2881
2882/* associate pointer with specified number */
2883static int unit_set(struct idr *p, void *ptr, int n)
2884{
2885 int unit;
2876 2886
2877 if (unit != n) { 2887 unit = __unit_alloc(p, ptr, n);
2888 if (unit < 0)
2889 return unit;
2890 else if (unit != n) {
2878 idr_remove(p, unit); 2891 idr_remove(p, unit);
2879 return -EINVAL; 2892 return -EINVAL;
2880 } 2893 }
@@ -2885,19 +2898,7 @@ again:
2885/* get new free unit number and associate pointer with it */ 2898/* get new free unit number and associate pointer with it */
2886static int unit_get(struct idr *p, void *ptr) 2899static int unit_get(struct idr *p, void *ptr)
2887{ 2900{
2888 int unit, err; 2901 return __unit_alloc(p, ptr, 0);
2889
2890again:
2891 if (!idr_pre_get(p, GFP_KERNEL)) {
2892 printk(KERN_ERR "PPP: No free memory for idr\n");
2893 return -ENOMEM;
2894 }
2895
2896 err = idr_get_new_above(p, ptr, 0, &unit);
2897 if (err == -EAGAIN)
2898 goto again;
2899
2900 return unit;
2901} 2902}
2902 2903
2903/* put unit number back to a pool */ 2904/* put unit number back to a pool */
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index d72fb0519a2a..78c0e3c9b2b5 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -948,7 +948,7 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
948 948
949abort: 949abort:
950 kfree_skb(skb); 950 kfree_skb(skb);
951 return 0; 951 return 1;
952} 952}
953 953
954/************************************************************************ 954/************************************************************************
diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c
index 7a298cdf9ab3..a3dcd04be22f 100644
--- a/drivers/net/qlcnic/qlcnic_main.c
+++ b/drivers/net/qlcnic/qlcnic_main.c
@@ -1450,7 +1450,6 @@ qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
1450 netdev->irq = adapter->msix_entries[0].vector; 1450 netdev->irq = adapter->msix_entries[0].vector;
1451 1451
1452 netif_carrier_off(netdev); 1452 netif_carrier_off(netdev);
1453 netif_stop_queue(netdev);
1454 1453
1455 err = register_netdev(netdev); 1454 err = register_netdev(netdev);
1456 if (err) { 1455 if (err) {
diff --git a/drivers/net/qlge/qlge.h b/drivers/net/qlge/qlge.h
index 22821398fc63..9787dff90d3f 100644
--- a/drivers/net/qlge/qlge.h
+++ b/drivers/net/qlge/qlge.h
@@ -2083,6 +2083,7 @@ struct ql_adapter {
2083 u32 mailbox_in; 2083 u32 mailbox_in;
2084 u32 mailbox_out; 2084 u32 mailbox_out;
2085 struct mbox_params idc_mbc; 2085 struct mbox_params idc_mbc;
2086 struct mutex mpi_mutex;
2086 2087
2087 int tx_ring_size; 2088 int tx_ring_size;
2088 int rx_ring_size; 2089 int rx_ring_size;
diff --git a/drivers/net/qlge/qlge_main.c b/drivers/net/qlge/qlge_main.c
index c30e0fe55a31..2555b1d34f34 100644
--- a/drivers/net/qlge/qlge_main.c
+++ b/drivers/net/qlge/qlge_main.c
@@ -62,15 +62,15 @@ static const u32 default_msg =
62/* NETIF_MSG_PKTDATA | */ 62/* NETIF_MSG_PKTDATA | */
63 NETIF_MSG_HW | NETIF_MSG_WOL | 0; 63 NETIF_MSG_HW | NETIF_MSG_WOL | 0;
64 64
65static int debug = 0x00007fff; /* defaults above */ 65static int debug = -1; /* defaults above */
66module_param(debug, int, 0); 66module_param(debug, int, 0664);
67MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 67MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
68 68
69#define MSIX_IRQ 0 69#define MSIX_IRQ 0
70#define MSI_IRQ 1 70#define MSI_IRQ 1
71#define LEG_IRQ 2 71#define LEG_IRQ 2
72static int qlge_irq_type = MSIX_IRQ; 72static int qlge_irq_type = MSIX_IRQ;
73module_param(qlge_irq_type, int, MSIX_IRQ); 73module_param(qlge_irq_type, int, 0664);
74MODULE_PARM_DESC(qlge_irq_type, "0 = MSI-X, 1 = MSI, 2 = Legacy."); 74MODULE_PARM_DESC(qlge_irq_type, "0 = MSI-X, 1 = MSI, 2 = Legacy.");
75 75
76static int qlge_mpi_coredump; 76static int qlge_mpi_coredump;
@@ -4629,6 +4629,7 @@ static int __devinit ql_init_device(struct pci_dev *pdev,
4629 INIT_DELAYED_WORK(&qdev->mpi_idc_work, ql_mpi_idc_work); 4629 INIT_DELAYED_WORK(&qdev->mpi_idc_work, ql_mpi_idc_work);
4630 INIT_DELAYED_WORK(&qdev->mpi_core_to_log, ql_mpi_core_to_log); 4630 INIT_DELAYED_WORK(&qdev->mpi_core_to_log, ql_mpi_core_to_log);
4631 init_completion(&qdev->ide_completion); 4631 init_completion(&qdev->ide_completion);
4632 mutex_init(&qdev->mpi_mutex);
4632 4633
4633 if (!cards_found) { 4634 if (!cards_found) {
4634 dev_info(&pdev->dev, "%s\n", DRV_STRING); 4635 dev_info(&pdev->dev, "%s\n", DRV_STRING);
diff --git a/drivers/net/qlge/qlge_mpi.c b/drivers/net/qlge/qlge_mpi.c
index 0e7c7c7ee164..a2e919bcb3c6 100644
--- a/drivers/net/qlge/qlge_mpi.c
+++ b/drivers/net/qlge/qlge_mpi.c
@@ -534,6 +534,7 @@ static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
534 int status; 534 int status;
535 unsigned long count; 535 unsigned long count;
536 536
537 mutex_lock(&qdev->mpi_mutex);
537 538
538 /* Begin polled mode for MPI */ 539 /* Begin polled mode for MPI */
539 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16)); 540 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
@@ -603,6 +604,7 @@ done:
603end: 604end:
604 /* End polled mode for MPI */ 605 /* End polled mode for MPI */
605 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI); 606 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
607 mutex_unlock(&qdev->mpi_mutex);
606 return status; 608 return status;
607} 609}
608 610
@@ -1099,9 +1101,7 @@ int ql_wait_fifo_empty(struct ql_adapter *qdev)
1099static int ql_set_port_cfg(struct ql_adapter *qdev) 1101static int ql_set_port_cfg(struct ql_adapter *qdev)
1100{ 1102{
1101 int status; 1103 int status;
1102 rtnl_lock();
1103 status = ql_mb_set_port_cfg(qdev); 1104 status = ql_mb_set_port_cfg(qdev);
1104 rtnl_unlock();
1105 if (status) 1105 if (status)
1106 return status; 1106 return status;
1107 status = ql_idc_wait(qdev); 1107 status = ql_idc_wait(qdev);
@@ -1122,9 +1122,7 @@ void ql_mpi_port_cfg_work(struct work_struct *work)
1122 container_of(work, struct ql_adapter, mpi_port_cfg_work.work); 1122 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
1123 int status; 1123 int status;
1124 1124
1125 rtnl_lock();
1126 status = ql_mb_get_port_cfg(qdev); 1125 status = ql_mb_get_port_cfg(qdev);
1127 rtnl_unlock();
1128 if (status) { 1126 if (status) {
1129 netif_err(qdev, drv, qdev->ndev, 1127 netif_err(qdev, drv, qdev->ndev,
1130 "Bug: Failed to get port config data.\n"); 1128 "Bug: Failed to get port config data.\n");
@@ -1167,7 +1165,6 @@ void ql_mpi_idc_work(struct work_struct *work)
1167 u32 aen; 1165 u32 aen;
1168 int timeout; 1166 int timeout;
1169 1167
1170 rtnl_lock();
1171 aen = mbcp->mbox_out[1] >> 16; 1168 aen = mbcp->mbox_out[1] >> 16;
1172 timeout = (mbcp->mbox_out[1] >> 8) & 0xf; 1169 timeout = (mbcp->mbox_out[1] >> 8) & 0xf;
1173 1170
@@ -1231,7 +1228,6 @@ void ql_mpi_idc_work(struct work_struct *work)
1231 } 1228 }
1232 break; 1229 break;
1233 } 1230 }
1234 rtnl_unlock();
1235} 1231}
1236 1232
1237void ql_mpi_work(struct work_struct *work) 1233void ql_mpi_work(struct work_struct *work)
@@ -1242,7 +1238,7 @@ void ql_mpi_work(struct work_struct *work)
1242 struct mbox_params *mbcp = &mbc; 1238 struct mbox_params *mbcp = &mbc;
1243 int err = 0; 1239 int err = 0;
1244 1240
1245 rtnl_lock(); 1241 mutex_lock(&qdev->mpi_mutex);
1246 /* Begin polled mode for MPI */ 1242 /* Begin polled mode for MPI */
1247 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16)); 1243 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
1248 1244
@@ -1259,7 +1255,7 @@ void ql_mpi_work(struct work_struct *work)
1259 1255
1260 /* End polled mode for MPI */ 1256 /* End polled mode for MPI */
1261 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI); 1257 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
1262 rtnl_unlock(); 1258 mutex_unlock(&qdev->mpi_mutex);
1263 ql_enable_completion_interrupt(qdev, 0); 1259 ql_enable_completion_interrupt(qdev, 0);
1264} 1260}
1265 1261
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index d88ce9fb1cbd..53b13deade95 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -744,26 +744,36 @@ static void rtl8169_xmii_reset_enable(void __iomem *ioaddr)
744 mdio_write(ioaddr, MII_BMCR, val & 0xffff); 744 mdio_write(ioaddr, MII_BMCR, val & 0xffff);
745} 745}
746 746
747static void rtl8169_check_link_status(struct net_device *dev, 747static void __rtl8169_check_link_status(struct net_device *dev,
748 struct rtl8169_private *tp, 748 struct rtl8169_private *tp,
749 void __iomem *ioaddr) 749 void __iomem *ioaddr,
750 bool pm)
750{ 751{
751 unsigned long flags; 752 unsigned long flags;
752 753
753 spin_lock_irqsave(&tp->lock, flags); 754 spin_lock_irqsave(&tp->lock, flags);
754 if (tp->link_ok(ioaddr)) { 755 if (tp->link_ok(ioaddr)) {
755 /* This is to cancel a scheduled suspend if there's one. */ 756 /* This is to cancel a scheduled suspend if there's one. */
756 pm_request_resume(&tp->pci_dev->dev); 757 if (pm)
758 pm_request_resume(&tp->pci_dev->dev);
757 netif_carrier_on(dev); 759 netif_carrier_on(dev);
758 netif_info(tp, ifup, dev, "link up\n"); 760 netif_info(tp, ifup, dev, "link up\n");
759 } else { 761 } else {
760 netif_carrier_off(dev); 762 netif_carrier_off(dev);
761 netif_info(tp, ifdown, dev, "link down\n"); 763 netif_info(tp, ifdown, dev, "link down\n");
762 pm_schedule_suspend(&tp->pci_dev->dev, 100); 764 if (pm)
765 pm_schedule_suspend(&tp->pci_dev->dev, 100);
763 } 766 }
764 spin_unlock_irqrestore(&tp->lock, flags); 767 spin_unlock_irqrestore(&tp->lock, flags);
765} 768}
766 769
770static void rtl8169_check_link_status(struct net_device *dev,
771 struct rtl8169_private *tp,
772 void __iomem *ioaddr)
773{
774 __rtl8169_check_link_status(dev, tp, ioaddr, false);
775}
776
767#define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) 777#define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST)
768 778
769static u32 __rtl8169_get_wol(struct rtl8169_private *tp) 779static u32 __rtl8169_get_wol(struct rtl8169_private *tp)
@@ -846,10 +856,10 @@ static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
846 else 856 else
847 tp->features &= ~RTL_FEATURE_WOL; 857 tp->features &= ~RTL_FEATURE_WOL;
848 __rtl8169_set_wol(tp, wol->wolopts); 858 __rtl8169_set_wol(tp, wol->wolopts);
849 device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts);
850
851 spin_unlock_irq(&tp->lock); 859 spin_unlock_irq(&tp->lock);
852 860
861 device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts);
862
853 return 0; 863 return 0;
854} 864}
855 865
@@ -2931,7 +2941,7 @@ static const struct rtl_cfg_info {
2931 .hw_start = rtl_hw_start_8168, 2941 .hw_start = rtl_hw_start_8168,
2932 .region = 2, 2942 .region = 2,
2933 .align = 8, 2943 .align = 8,
2934 .intr_event = SYSErr | RxFIFOOver | LinkChg | RxOverflow | 2944 .intr_event = SYSErr | LinkChg | RxOverflow |
2935 TxErr | TxOK | RxOK | RxErr, 2945 TxErr | TxOK | RxOK | RxErr,
2936 .napi_event = TxErr | TxOK | RxOK | RxOverflow, 2946 .napi_event = TxErr | TxOK | RxOK | RxOverflow,
2937 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, 2947 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI,
@@ -4440,8 +4450,7 @@ static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1)
4440 u32 status = opts1 & RxProtoMask; 4450 u32 status = opts1 & RxProtoMask;
4441 4451
4442 if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || 4452 if (((status == RxProtoTCP) && !(opts1 & TCPFail)) ||
4443 ((status == RxProtoUDP) && !(opts1 & UDPFail)) || 4453 ((status == RxProtoUDP) && !(opts1 & UDPFail)))
4444 ((status == RxProtoIP) && !(opts1 & IPFail)))
4445 skb->ip_summed = CHECKSUM_UNNECESSARY; 4454 skb->ip_summed = CHECKSUM_UNNECESSARY;
4446 else 4455 else
4447 skb_checksum_none_assert(skb); 4456 skb_checksum_none_assert(skb);
@@ -4588,7 +4597,8 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
4588 } 4597 }
4589 4598
4590 /* Work around for rx fifo overflow */ 4599 /* Work around for rx fifo overflow */
4591 if (unlikely(status & RxFIFOOver)) { 4600 if (unlikely(status & RxFIFOOver) &&
4601 (tp->mac_version == RTL_GIGA_MAC_VER_11)) {
4592 netif_stop_queue(dev); 4602 netif_stop_queue(dev);
4593 rtl8169_tx_timeout(dev); 4603 rtl8169_tx_timeout(dev);
4594 break; 4604 break;
@@ -4600,7 +4610,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
4600 } 4610 }
4601 4611
4602 if (status & LinkChg) 4612 if (status & LinkChg)
4603 rtl8169_check_link_status(dev, tp, ioaddr); 4613 __rtl8169_check_link_status(dev, tp, ioaddr, true);
4604 4614
4605 /* We need to see the lastest version of tp->intr_mask to 4615 /* We need to see the lastest version of tp->intr_mask to
4606 * avoid ignoring an MSI interrupt and having to wait for 4616 * avoid ignoring an MSI interrupt and having to wait for
@@ -4890,11 +4900,7 @@ static int rtl8169_runtime_idle(struct device *device)
4890 struct net_device *dev = pci_get_drvdata(pdev); 4900 struct net_device *dev = pci_get_drvdata(pdev);
4891 struct rtl8169_private *tp = netdev_priv(dev); 4901 struct rtl8169_private *tp = netdev_priv(dev);
4892 4902
4893 if (!tp->TxDescArray) 4903 return tp->TxDescArray ? -EBUSY : 0;
4894 return 0;
4895
4896 rtl8169_check_link_status(dev, tp, tp->mmio_addr);
4897 return -EBUSY;
4898} 4904}
4899 4905
4900static const struct dev_pm_ops rtl8169_pm_ops = { 4906static const struct dev_pm_ops rtl8169_pm_ops = {
diff --git a/drivers/net/sfc/efx.c b/drivers/net/sfc/efx.c
index 05df20e47976..fb83cdd94643 100644
--- a/drivers/net/sfc/efx.c
+++ b/drivers/net/sfc/efx.c
@@ -197,7 +197,9 @@ MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
197 197
198static void efx_remove_channels(struct efx_nic *efx); 198static void efx_remove_channels(struct efx_nic *efx);
199static void efx_remove_port(struct efx_nic *efx); 199static void efx_remove_port(struct efx_nic *efx);
200static void efx_init_napi(struct efx_nic *efx);
200static void efx_fini_napi(struct efx_nic *efx); 201static void efx_fini_napi(struct efx_nic *efx);
202static void efx_fini_napi_channel(struct efx_channel *channel);
201static void efx_fini_struct(struct efx_nic *efx); 203static void efx_fini_struct(struct efx_nic *efx);
202static void efx_start_all(struct efx_nic *efx); 204static void efx_start_all(struct efx_nic *efx);
203static void efx_stop_all(struct efx_nic *efx); 205static void efx_stop_all(struct efx_nic *efx);
@@ -335,8 +337,10 @@ void efx_process_channel_now(struct efx_channel *channel)
335 337
336 /* Disable interrupts and wait for ISRs to complete */ 338 /* Disable interrupts and wait for ISRs to complete */
337 efx_nic_disable_interrupts(efx); 339 efx_nic_disable_interrupts(efx);
338 if (efx->legacy_irq) 340 if (efx->legacy_irq) {
339 synchronize_irq(efx->legacy_irq); 341 synchronize_irq(efx->legacy_irq);
342 efx->legacy_irq_enabled = false;
343 }
340 if (channel->irq) 344 if (channel->irq)
341 synchronize_irq(channel->irq); 345 synchronize_irq(channel->irq);
342 346
@@ -351,6 +355,8 @@ void efx_process_channel_now(struct efx_channel *channel)
351 efx_channel_processed(channel); 355 efx_channel_processed(channel);
352 356
353 napi_enable(&channel->napi_str); 357 napi_enable(&channel->napi_str);
358 if (efx->legacy_irq)
359 efx->legacy_irq_enabled = true;
354 efx_nic_enable_interrupts(efx); 360 efx_nic_enable_interrupts(efx);
355} 361}
356 362
@@ -426,6 +432,7 @@ efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
426 432
427 *channel = *old_channel; 433 *channel = *old_channel;
428 434
435 channel->napi_dev = NULL;
429 memset(&channel->eventq, 0, sizeof(channel->eventq)); 436 memset(&channel->eventq, 0, sizeof(channel->eventq));
430 437
431 rx_queue = &channel->rx_queue; 438 rx_queue = &channel->rx_queue;
@@ -736,9 +743,13 @@ efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
736 if (rc) 743 if (rc)
737 goto rollback; 744 goto rollback;
738 745
746 efx_init_napi(efx);
747
739 /* Destroy old channels */ 748 /* Destroy old channels */
740 for (i = 0; i < efx->n_channels; i++) 749 for (i = 0; i < efx->n_channels; i++) {
750 efx_fini_napi_channel(other_channel[i]);
741 efx_remove_channel(other_channel[i]); 751 efx_remove_channel(other_channel[i]);
752 }
742out: 753out:
743 /* Free unused channel structures */ 754 /* Free unused channel structures */
744 for (i = 0; i < efx->n_channels; i++) 755 for (i = 0; i < efx->n_channels; i++)
@@ -1400,6 +1411,8 @@ static void efx_start_all(struct efx_nic *efx)
1400 efx_start_channel(channel); 1411 efx_start_channel(channel);
1401 } 1412 }
1402 1413
1414 if (efx->legacy_irq)
1415 efx->legacy_irq_enabled = true;
1403 efx_nic_enable_interrupts(efx); 1416 efx_nic_enable_interrupts(efx);
1404 1417
1405 /* Switch to event based MCDI completions after enabling interrupts. 1418 /* Switch to event based MCDI completions after enabling interrupts.
@@ -1460,8 +1473,10 @@ static void efx_stop_all(struct efx_nic *efx)
1460 1473
1461 /* Disable interrupts and wait for ISR to complete */ 1474 /* Disable interrupts and wait for ISR to complete */
1462 efx_nic_disable_interrupts(efx); 1475 efx_nic_disable_interrupts(efx);
1463 if (efx->legacy_irq) 1476 if (efx->legacy_irq) {
1464 synchronize_irq(efx->legacy_irq); 1477 synchronize_irq(efx->legacy_irq);
1478 efx->legacy_irq_enabled = false;
1479 }
1465 efx_for_each_channel(channel, efx) { 1480 efx_for_each_channel(channel, efx) {
1466 if (channel->irq) 1481 if (channel->irq)
1467 synchronize_irq(channel->irq); 1482 synchronize_irq(channel->irq);
@@ -1593,7 +1608,7 @@ static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1593 * 1608 *
1594 **************************************************************************/ 1609 **************************************************************************/
1595 1610
1596static int efx_init_napi(struct efx_nic *efx) 1611static void efx_init_napi(struct efx_nic *efx)
1597{ 1612{
1598 struct efx_channel *channel; 1613 struct efx_channel *channel;
1599 1614
@@ -1602,18 +1617,21 @@ static int efx_init_napi(struct efx_nic *efx)
1602 netif_napi_add(channel->napi_dev, &channel->napi_str, 1617 netif_napi_add(channel->napi_dev, &channel->napi_str,
1603 efx_poll, napi_weight); 1618 efx_poll, napi_weight);
1604 } 1619 }
1605 return 0; 1620}
1621
1622static void efx_fini_napi_channel(struct efx_channel *channel)
1623{
1624 if (channel->napi_dev)
1625 netif_napi_del(&channel->napi_str);
1626 channel->napi_dev = NULL;
1606} 1627}
1607 1628
1608static void efx_fini_napi(struct efx_nic *efx) 1629static void efx_fini_napi(struct efx_nic *efx)
1609{ 1630{
1610 struct efx_channel *channel; 1631 struct efx_channel *channel;
1611 1632
1612 efx_for_each_channel(channel, efx) { 1633 efx_for_each_channel(channel, efx)
1613 if (channel->napi_dev) 1634 efx_fini_napi_channel(channel);
1614 netif_napi_del(&channel->napi_str);
1615 channel->napi_dev = NULL;
1616 }
1617} 1635}
1618 1636
1619/************************************************************************** 1637/**************************************************************************
@@ -2335,9 +2353,7 @@ static int efx_pci_probe_main(struct efx_nic *efx)
2335 if (rc) 2353 if (rc)
2336 goto fail1; 2354 goto fail1;
2337 2355
2338 rc = efx_init_napi(efx); 2356 efx_init_napi(efx);
2339 if (rc)
2340 goto fail2;
2341 2357
2342 rc = efx->type->init(efx); 2358 rc = efx->type->init(efx);
2343 if (rc) { 2359 if (rc) {
@@ -2368,7 +2384,6 @@ static int efx_pci_probe_main(struct efx_nic *efx)
2368 efx->type->fini(efx); 2384 efx->type->fini(efx);
2369 fail3: 2385 fail3:
2370 efx_fini_napi(efx); 2386 efx_fini_napi(efx);
2371 fail2:
2372 efx_remove_all(efx); 2387 efx_remove_all(efx);
2373 fail1: 2388 fail1:
2374 return rc; 2389 return rc;
diff --git a/drivers/net/sfc/net_driver.h b/drivers/net/sfc/net_driver.h
index 0a7e26d73b52..b137c889152b 100644
--- a/drivers/net/sfc/net_driver.h
+++ b/drivers/net/sfc/net_driver.h
@@ -621,6 +621,7 @@ struct efx_filter_state;
621 * @pci_dev: The PCI device 621 * @pci_dev: The PCI device
622 * @type: Controller type attributes 622 * @type: Controller type attributes
623 * @legacy_irq: IRQ number 623 * @legacy_irq: IRQ number
624 * @legacy_irq_enabled: Are IRQs enabled on NIC (INT_EN_KER register)?
624 * @workqueue: Workqueue for port reconfigures and the HW monitor. 625 * @workqueue: Workqueue for port reconfigures and the HW monitor.
625 * Work items do not hold and must not acquire RTNL. 626 * Work items do not hold and must not acquire RTNL.
626 * @workqueue_name: Name of workqueue 627 * @workqueue_name: Name of workqueue
@@ -709,6 +710,7 @@ struct efx_nic {
709 struct pci_dev *pci_dev; 710 struct pci_dev *pci_dev;
710 const struct efx_nic_type *type; 711 const struct efx_nic_type *type;
711 int legacy_irq; 712 int legacy_irq;
713 bool legacy_irq_enabled;
712 struct workqueue_struct *workqueue; 714 struct workqueue_struct *workqueue;
713 char workqueue_name[16]; 715 char workqueue_name[16];
714 struct work_struct reset_work; 716 struct work_struct reset_work;
diff --git a/drivers/net/sfc/nic.c b/drivers/net/sfc/nic.c
index 41c36b9a4244..67cb0c96838c 100644
--- a/drivers/net/sfc/nic.c
+++ b/drivers/net/sfc/nic.c
@@ -1418,6 +1418,12 @@ static irqreturn_t efx_legacy_interrupt(int irq, void *dev_id)
1418 u32 queues; 1418 u32 queues;
1419 int syserr; 1419 int syserr;
1420 1420
1421 /* Could this be ours? If interrupts are disabled then the
1422 * channel state may not be valid.
1423 */
1424 if (!efx->legacy_irq_enabled)
1425 return result;
1426
1421 /* Read the ISR which also ACKs the interrupts */ 1427 /* Read the ISR which also ACKs the interrupts */
1422 efx_readd(efx, &reg, FR_BZ_INT_ISR0); 1428 efx_readd(efx, &reg, FR_BZ_INT_ISR0);
1423 queues = EFX_EXTRACT_DWORD(reg, 0, 31); 1429 queues = EFX_EXTRACT_DWORD(reg, 0, 31);
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index bfec2e0f5275..220e0398f1d5 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -3858,7 +3858,6 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3858 3858
3859 /* device is off until link detection */ 3859 /* device is off until link detection */
3860 netif_carrier_off(dev); 3860 netif_carrier_off(dev);
3861 netif_stop_queue(dev);
3862 3861
3863 return dev; 3862 return dev;
3864} 3863}
diff --git a/drivers/net/smsc911x.h b/drivers/net/smsc911x.h
index 52f38e12a879..50f712e99e96 100644
--- a/drivers/net/smsc911x.h
+++ b/drivers/net/smsc911x.h
@@ -22,7 +22,7 @@
22#define __SMSC911X_H__ 22#define __SMSC911X_H__
23 23
24#define TX_FIFO_LOW_THRESHOLD ((u32)1600) 24#define TX_FIFO_LOW_THRESHOLD ((u32)1600)
25#define SMSC911X_EEPROM_SIZE ((u32)7) 25#define SMSC911X_EEPROM_SIZE ((u32)128)
26#define USE_DEBUG 0 26#define USE_DEBUG 0
27 27
28/* This is the maximum number of packets to be received every 28/* This is the maximum number of packets to be received every
diff --git a/drivers/net/stmmac/stmmac_main.c b/drivers/net/stmmac/stmmac_main.c
index 06bc6034ce81..2114837809e7 100644
--- a/drivers/net/stmmac/stmmac_main.c
+++ b/drivers/net/stmmac/stmmac_main.c
@@ -1509,6 +1509,8 @@ static int stmmac_probe(struct net_device *dev)
1509 pr_warning("\tno valid MAC address;" 1509 pr_warning("\tno valid MAC address;"
1510 "please, use ifconfig or nwhwconfig!\n"); 1510 "please, use ifconfig or nwhwconfig!\n");
1511 1511
1512 spin_lock_init(&priv->lock);
1513
1512 ret = register_netdev(dev); 1514 ret = register_netdev(dev);
1513 if (ret) { 1515 if (ret) {
1514 pr_err("%s: ERROR %i registering the device\n", 1516 pr_err("%s: ERROR %i registering the device\n",
@@ -1520,8 +1522,6 @@ static int stmmac_probe(struct net_device *dev)
1520 dev->name, (dev->features & NETIF_F_SG) ? "on" : "off", 1522 dev->name, (dev->features & NETIF_F_SG) ? "on" : "off",
1521 (dev->features & NETIF_F_HW_CSUM) ? "on" : "off"); 1523 (dev->features & NETIF_F_HW_CSUM) ? "on" : "off");
1522 1524
1523 spin_lock_init(&priv->lock);
1524
1525 return ret; 1525 return ret;
1526} 1526}
1527 1527
diff --git a/drivers/net/tile/Makefile b/drivers/net/tile/Makefile
new file mode 100644
index 000000000000..f634f142cab4
--- /dev/null
+++ b/drivers/net/tile/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for the TILE on-chip networking support.
3#
4
5obj-$(CONFIG_TILE_NET) += tile_net.o
6ifdef CONFIG_TILEGX
7tile_net-objs := tilegx.o mpipe.o iorpc_mpipe.o dma_queue.o
8else
9tile_net-objs := tilepro.o
10endif
diff --git a/drivers/net/tile/tilepro.c b/drivers/net/tile/tilepro.c
new file mode 100644
index 000000000000..0e6bac5ec65b
--- /dev/null
+++ b/drivers/net/tile/tilepro.c
@@ -0,0 +1,2406 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/moduleparam.h>
18#include <linux/sched.h>
19#include <linux/kernel.h> /* printk() */
20#include <linux/slab.h> /* kmalloc() */
21#include <linux/errno.h> /* error codes */
22#include <linux/types.h> /* size_t */
23#include <linux/interrupt.h>
24#include <linux/in.h>
25#include <linux/netdevice.h> /* struct device, and other headers */
26#include <linux/etherdevice.h> /* eth_type_trans */
27#include <linux/skbuff.h>
28#include <linux/ioctl.h>
29#include <linux/cdev.h>
30#include <linux/hugetlb.h>
31#include <linux/in6.h>
32#include <linux/timer.h>
33#include <linux/io.h>
34#include <asm/checksum.h>
35#include <asm/homecache.h>
36
37#include <hv/drv_xgbe_intf.h>
38#include <hv/drv_xgbe_impl.h>
39#include <hv/hypervisor.h>
40#include <hv/netio_intf.h>
41
42/* For TSO */
43#include <linux/ip.h>
44#include <linux/tcp.h>
45
46
47/* There is no singlethread_cpu, so schedule work on the current cpu. */
48#define singlethread_cpu -1
49
50
51/*
52 * First, "tile_net_init_module()" initializes all four "devices" which
53 * can be used by linux.
54 *
55 * Then, "ifconfig DEVICE up" calls "tile_net_open()", which analyzes
56 * the network cpus, then uses "tile_net_open_aux()" to initialize
57 * LIPP/LEPP, and then uses "tile_net_open_inner()" to register all
58 * the tiles, provide buffers to LIPP, allow ingress to start, and
59 * turn on hypervisor interrupt handling (and NAPI) on all tiles.
60 *
61 * If registration fails due to the link being down, then "retry_work"
62 * is used to keep calling "tile_net_open_inner()" until it succeeds.
63 *
64 * If "ifconfig DEVICE down" is called, it uses "tile_net_stop()" to
65 * stop egress, drain the LIPP buffers, unregister all the tiles, stop
66 * LIPP/LEPP, and wipe the LEPP queue.
67 *
68 * We start out with the ingress interrupt enabled on each CPU. When
69 * this interrupt fires, we disable it, and call "napi_schedule()".
70 * This will cause "tile_net_poll()" to be called, which will pull
71 * packets from the netio queue, filtering them out, or passing them
72 * to "netif_receive_skb()". If our budget is exhausted, we will
73 * return, knowing we will be called again later. Otherwise, we
74 * reenable the ingress interrupt, and call "napi_complete()".
75 *
76 *
77 * NOTE: The use of "native_driver" ensures that EPP exists, and that
78 * "epp_sendv" is legal, and that "LIPP" is being used.
79 *
80 * NOTE: Failing to free completions for an arbitrarily long time
81 * (which is defined to be illegal) does in fact cause bizarre
82 * problems. The "egress_timer" helps prevent this from happening.
83 *
84 * NOTE: The egress code can be interrupted by the interrupt handler.
85 */
86
87
88/* HACK: Allow use of "jumbo" packets. */
89/* This should be 1500 if "jumbo" is not set in LIPP. */
90/* This should be at most 10226 (10240 - 14) if "jumbo" is set in LIPP. */
91/* ISSUE: This has not been thoroughly tested (except at 1500). */
92#define TILE_NET_MTU 1500
93
94/* HACK: Define to support GSO. */
95/* ISSUE: This may actually hurt performance of the TCP blaster. */
96/* #define TILE_NET_GSO */
97
98/* Define this to collapse "duplicate" acks. */
99/* #define IGNORE_DUP_ACKS */
100
101/* HACK: Define this to verify incoming packets. */
102/* #define TILE_NET_VERIFY_INGRESS */
103
104/* Use 3000 to enable the Linux Traffic Control (QoS) layer, else 0. */
105#define TILE_NET_TX_QUEUE_LEN 0
106
107/* Define to dump packets (prints out the whole packet on tx and rx). */
108/* #define TILE_NET_DUMP_PACKETS */
109
110/* Define to enable debug spew (all PDEBUG's are enabled). */
111/* #define TILE_NET_DEBUG */
112
113
114/* Define to activate paranoia checks. */
115/* #define TILE_NET_PARANOIA */
116
117/* Default transmit lockup timeout period, in jiffies. */
118#define TILE_NET_TIMEOUT (5 * HZ)
119
120/* Default retry interval for bringing up the NetIO interface, in jiffies. */
121#define TILE_NET_RETRY_INTERVAL (5 * HZ)
122
123/* Number of ports (xgbe0, xgbe1, gbe0, gbe1). */
124#define TILE_NET_DEVS 4
125
126
127
128/* Paranoia. */
129#if NET_IP_ALIGN != LIPP_PACKET_PADDING
130#error "NET_IP_ALIGN must match LIPP_PACKET_PADDING."
131#endif
132
133
134/* Debug print. */
135#ifdef TILE_NET_DEBUG
136#define PDEBUG(fmt, args...) net_printk(fmt, ## args)
137#else
138#define PDEBUG(fmt, args...)
139#endif
140
141
142MODULE_AUTHOR("Tilera");
143MODULE_LICENSE("GPL");
144
145
146#define IS_MULTICAST(mac_addr) \
147 (((u8 *)(mac_addr))[0] & 0x01)
148
149#define IS_BROADCAST(mac_addr) \
150 (((u16 *)(mac_addr))[0] == 0xffff)
151
152
153/*
154 * Queue of incoming packets for a specific cpu and device.
155 *
156 * Includes a pointer to the "system" data, and the actual "user" data.
157 */
158struct tile_netio_queue {
159 netio_queue_impl_t *__system_part;
160 netio_queue_user_impl_t __user_part;
161
162};
163
164
165/*
166 * Statistics counters for a specific cpu and device.
167 */
168struct tile_net_stats_t {
169 u32 rx_packets;
170 u32 rx_bytes;
171 u32 tx_packets;
172 u32 tx_bytes;
173};
174
175
176/*
177 * Info for a specific cpu and device.
178 *
179 * ISSUE: There is a "dev" pointer in "napi" as well.
180 */
181struct tile_net_cpu {
182 /* The NAPI struct. */
183 struct napi_struct napi;
184 /* Packet queue. */
185 struct tile_netio_queue queue;
186 /* Statistics. */
187 struct tile_net_stats_t stats;
188 /* ISSUE: Is this needed? */
189 bool napi_enabled;
190 /* True if this tile has succcessfully registered with the IPP. */
191 bool registered;
192 /* True if the link was down last time we tried to register. */
193 bool link_down;
194 /* True if "egress_timer" is scheduled. */
195 bool egress_timer_scheduled;
196 /* Number of small sk_buffs which must still be provided. */
197 unsigned int num_needed_small_buffers;
198 /* Number of large sk_buffs which must still be provided. */
199 unsigned int num_needed_large_buffers;
200 /* A timer for handling egress completions. */
201 struct timer_list egress_timer;
202};
203
204
205/*
206 * Info for a specific device.
207 */
208struct tile_net_priv {
209 /* Our network device. */
210 struct net_device *dev;
211 /* The actual egress queue. */
212 lepp_queue_t *epp_queue;
213 /* Protects "epp_queue->cmd_tail" and "epp_queue->comp_tail" */
214 spinlock_t cmd_lock;
215 /* Protects "epp_queue->comp_head". */
216 spinlock_t comp_lock;
217 /* The hypervisor handle for this interface. */
218 int hv_devhdl;
219 /* The intr bit mask that IDs this device. */
220 u32 intr_id;
221 /* True iff "tile_net_open_aux()" has succeeded. */
222 int partly_opened;
223 /* True iff "tile_net_open_inner()" has succeeded. */
224 int fully_opened;
225 /* Effective network cpus. */
226 struct cpumask network_cpus_map;
227 /* Number of network cpus. */
228 int network_cpus_count;
229 /* Credits per network cpu. */
230 int network_cpus_credits;
231 /* Network stats. */
232 struct net_device_stats stats;
233 /* For NetIO bringup retries. */
234 struct delayed_work retry_work;
235 /* Quick access to per cpu data. */
236 struct tile_net_cpu *cpu[NR_CPUS];
237};
238
239
240/*
241 * The actual devices (xgbe0, xgbe1, gbe0, gbe1).
242 */
243static struct net_device *tile_net_devs[TILE_NET_DEVS];
244
245/*
246 * The "tile_net_cpu" structures for each device.
247 */
248static DEFINE_PER_CPU(struct tile_net_cpu, hv_xgbe0);
249static DEFINE_PER_CPU(struct tile_net_cpu, hv_xgbe1);
250static DEFINE_PER_CPU(struct tile_net_cpu, hv_gbe0);
251static DEFINE_PER_CPU(struct tile_net_cpu, hv_gbe1);
252
253
254/*
255 * True if "network_cpus" was specified.
256 */
257static bool network_cpus_used;
258
259/*
260 * The actual cpus in "network_cpus".
261 */
262static struct cpumask network_cpus_map;
263
264
265
266#ifdef TILE_NET_DEBUG
267/*
268 * printk with extra stuff.
269 *
270 * We print the CPU we're running in brackets.
271 */
272static void net_printk(char *fmt, ...)
273{
274 int i;
275 int len;
276 va_list args;
277 static char buf[256];
278
279 len = sprintf(buf, "tile_net[%2.2d]: ", smp_processor_id());
280 va_start(args, fmt);
281 i = vscnprintf(buf + len, sizeof(buf) - len - 1, fmt, args);
282 va_end(args);
283 buf[255] = '\0';
284 pr_notice(buf);
285}
286#endif
287
288
289#ifdef TILE_NET_DUMP_PACKETS
290/*
291 * Dump a packet.
292 */
293static void dump_packet(unsigned char *data, unsigned long length, char *s)
294{
295 unsigned long i;
296 static unsigned int count;
297
298 pr_info("dump_packet(data %p, length 0x%lx s %s count 0x%x)\n",
299 data, length, s, count++);
300
301 pr_info("\n");
302
303 for (i = 0; i < length; i++) {
304 if ((i & 0xf) == 0)
305 sprintf(buf, "%8.8lx:", i);
306 sprintf(buf + strlen(buf), " %2.2x", data[i]);
307 if ((i & 0xf) == 0xf || i == length - 1)
308 pr_info("%s\n", buf);
309 }
310}
311#endif
312
313
314/*
315 * Provide support for the __netio_fastio1() swint
316 * (see <hv/drv_xgbe_intf.h> for how it is used).
317 *
318 * The fastio swint2 call may clobber all the caller-saved registers.
319 * It rarely clobbers memory, but we allow for the possibility in
320 * the signature just to be on the safe side.
321 *
322 * Also, gcc doesn't seem to allow an input operand to be
323 * clobbered, so we fake it with dummy outputs.
324 *
325 * This function can't be static because of the way it is declared
326 * in the netio header.
327 */
328inline int __netio_fastio1(u32 fastio_index, u32 arg0)
329{
330 long result, clobber_r1, clobber_r10;
331 asm volatile("swint2"
332 : "=R00" (result),
333 "=R01" (clobber_r1), "=R10" (clobber_r10)
334 : "R10" (fastio_index), "R01" (arg0)
335 : "memory", "r2", "r3", "r4",
336 "r5", "r6", "r7", "r8", "r9",
337 "r11", "r12", "r13", "r14",
338 "r15", "r16", "r17", "r18", "r19",
339 "r20", "r21", "r22", "r23", "r24",
340 "r25", "r26", "r27", "r28", "r29");
341 return result;
342}
343
344
345/*
346 * Provide a linux buffer to LIPP.
347 */
348static void tile_net_provide_linux_buffer(struct tile_net_cpu *info,
349 void *va, bool small)
350{
351 struct tile_netio_queue *queue = &info->queue;
352
353 /* Convert "va" and "small" to "linux_buffer_t". */
354 unsigned int buffer = ((unsigned int)(__pa(va) >> 7) << 1) + small;
355
356 __netio_fastio_free_buffer(queue->__user_part.__fastio_index, buffer);
357}
358
359
360/*
361 * Provide a linux buffer for LIPP.
362 */
363static bool tile_net_provide_needed_buffer(struct tile_net_cpu *info,
364 bool small)
365{
366 /* ISSUE: What should we use here? */
367 unsigned int large_size = NET_IP_ALIGN + TILE_NET_MTU + 100;
368
369 /* Round up to ensure to avoid "false sharing" with last cache line. */
370 unsigned int buffer_size =
371 (((small ? LIPP_SMALL_PACKET_SIZE : large_size) +
372 CHIP_L2_LINE_SIZE() - 1) & -CHIP_L2_LINE_SIZE());
373
374 /*
375 * ISSUE: Since CPAs are 38 bits, and we can only encode the
376 * high 31 bits in a "linux_buffer_t", the low 7 bits must be
377 * zero, and thus, we must align the actual "va" mod 128.
378 */
379 const unsigned long align = 128;
380
381 struct sk_buff *skb;
382 void *va;
383
384 struct sk_buff **skb_ptr;
385
386 /* Note that "dev_alloc_skb()" adds NET_SKB_PAD more bytes, */
387 /* and also "reserves" that many bytes. */
388 /* ISSUE: Can we "share" the NET_SKB_PAD bytes with "skb_ptr"? */
389 int len = sizeof(*skb_ptr) + align + buffer_size;
390
391 while (1) {
392
393 /* Allocate (or fail). */
394 skb = dev_alloc_skb(len);
395 if (skb == NULL)
396 return false;
397
398 /* Make room for a back-pointer to 'skb'. */
399 skb_reserve(skb, sizeof(*skb_ptr));
400
401 /* Make sure we are aligned. */
402 skb_reserve(skb, -(long)skb->data & (align - 1));
403
404 /* This address is given to IPP. */
405 va = skb->data;
406
407 if (small)
408 break;
409
410 /* ISSUE: This has never been observed! */
411 /* Large buffers must not span a huge page. */
412 if (((((long)va & ~HPAGE_MASK) + 1535) & HPAGE_MASK) == 0)
413 break;
414 pr_err("Leaking unaligned linux buffer at %p.\n", va);
415 }
416
417 /* Skip two bytes to satisfy LIPP assumptions. */
418 /* Note that this aligns IP on a 16 byte boundary. */
419 /* ISSUE: Do this when the packet arrives? */
420 skb_reserve(skb, NET_IP_ALIGN);
421
422 /* Save a back-pointer to 'skb'. */
423 skb_ptr = va - sizeof(*skb_ptr);
424 *skb_ptr = skb;
425
426 /* Invalidate the packet buffer. */
427 if (!hash_default)
428 __inv_buffer(skb->data, buffer_size);
429
430 /* Make sure "skb_ptr" has been flushed. */
431 __insn_mf();
432
433#ifdef TILE_NET_PARANOIA
434#if CHIP_HAS_CBOX_HOME_MAP()
435 if (hash_default) {
436 HV_PTE pte = *virt_to_pte(current->mm, (unsigned long)va);
437 if (hv_pte_get_mode(pte) != HV_PTE_MODE_CACHE_HASH_L3)
438 panic("Non-coherent ingress buffer!");
439 }
440#endif
441#endif
442
443 /* Provide the new buffer. */
444 tile_net_provide_linux_buffer(info, va, small);
445
446 return true;
447}
448
449
450/*
451 * Provide linux buffers for LIPP.
452 */
453static void tile_net_provide_needed_buffers(struct tile_net_cpu *info)
454{
455 while (info->num_needed_small_buffers != 0) {
456 if (!tile_net_provide_needed_buffer(info, true))
457 goto oops;
458 info->num_needed_small_buffers--;
459 }
460
461 while (info->num_needed_large_buffers != 0) {
462 if (!tile_net_provide_needed_buffer(info, false))
463 goto oops;
464 info->num_needed_large_buffers--;
465 }
466
467 return;
468
469oops:
470
471 /* Add a description to the page allocation failure dump. */
472 pr_notice("Could not provide a linux buffer to LIPP.\n");
473}
474
475
476/*
477 * Grab some LEPP completions, and store them in "comps", of size
478 * "comps_size", and return the number of completions which were
479 * stored, so the caller can free them.
480 *
481 * If "pending" is not NULL, it will be set to true if there might
482 * still be some pending completions caused by this tile, else false.
483 */
484static unsigned int tile_net_lepp_grab_comps(struct net_device *dev,
485 struct sk_buff *comps[],
486 unsigned int comps_size,
487 bool *pending)
488{
489 struct tile_net_priv *priv = netdev_priv(dev);
490
491 lepp_queue_t *eq = priv->epp_queue;
492
493 unsigned int n = 0;
494
495 unsigned int comp_head;
496 unsigned int comp_busy;
497 unsigned int comp_tail;
498
499 spin_lock(&priv->comp_lock);
500
501 comp_head = eq->comp_head;
502 comp_busy = eq->comp_busy;
503 comp_tail = eq->comp_tail;
504
505 while (comp_head != comp_busy && n < comps_size) {
506 comps[n++] = eq->comps[comp_head];
507 LEPP_QINC(comp_head);
508 }
509
510 if (pending != NULL)
511 *pending = (comp_head != comp_tail);
512
513 eq->comp_head = comp_head;
514
515 spin_unlock(&priv->comp_lock);
516
517 return n;
518}
519
520
521/*
522 * Make sure the egress timer is scheduled.
523 *
524 * Note that we use "schedule if not scheduled" logic instead of the more
525 * obvious "reschedule" logic, because "reschedule" is fairly expensive.
526 */
527static void tile_net_schedule_egress_timer(struct tile_net_cpu *info)
528{
529 if (!info->egress_timer_scheduled) {
530 mod_timer_pinned(&info->egress_timer, jiffies + 1);
531 info->egress_timer_scheduled = true;
532 }
533}
534
535
536/*
537 * The "function" for "info->egress_timer".
538 *
539 * This timer will reschedule itself as long as there are any pending
540 * completions expected (on behalf of any tile).
541 *
542 * ISSUE: Realistically, will the timer ever stop scheduling itself?
543 *
544 * ISSUE: This timer is almost never actually needed, so just use a global
545 * timer that can run on any tile.
546 *
547 * ISSUE: Maybe instead track number of expected completions, and free
548 * only that many, resetting to zero if "pending" is ever false.
549 */
550static void tile_net_handle_egress_timer(unsigned long arg)
551{
552 struct tile_net_cpu *info = (struct tile_net_cpu *)arg;
553 struct net_device *dev = info->napi.dev;
554
555 struct sk_buff *olds[32];
556 unsigned int wanted = 32;
557 unsigned int i, nolds = 0;
558 bool pending;
559
560 /* The timer is no longer scheduled. */
561 info->egress_timer_scheduled = false;
562
563 nolds = tile_net_lepp_grab_comps(dev, olds, wanted, &pending);
564
565 for (i = 0; i < nolds; i++)
566 kfree_skb(olds[i]);
567
568 /* Reschedule timer if needed. */
569 if (pending)
570 tile_net_schedule_egress_timer(info);
571}
572
573
574#ifdef IGNORE_DUP_ACKS
575
576/*
577 * Help detect "duplicate" ACKs. These are sequential packets (for a
578 * given flow) which are exactly 66 bytes long, sharing everything but
579 * ID=2@0x12, Hsum=2@0x18, Ack=4@0x2a, WinSize=2@0x30, Csum=2@0x32,
580 * Tstamps=10@0x38. The ID's are +1, the Hsum's are -1, the Ack's are
581 * +N, and the Tstamps are usually identical.
582 *
583 * NOTE: Apparently truly duplicate acks (with identical "ack" values),
584 * should not be collapsed, as they are used for some kind of flow control.
585 */
586static bool is_dup_ack(char *s1, char *s2, unsigned int len)
587{
588 int i;
589
590 unsigned long long ignorable = 0;
591
592 /* Identification. */
593 ignorable |= (1ULL << 0x12);
594 ignorable |= (1ULL << 0x13);
595
596 /* Header checksum. */
597 ignorable |= (1ULL << 0x18);
598 ignorable |= (1ULL << 0x19);
599
600 /* ACK. */
601 ignorable |= (1ULL << 0x2a);
602 ignorable |= (1ULL << 0x2b);
603 ignorable |= (1ULL << 0x2c);
604 ignorable |= (1ULL << 0x2d);
605
606 /* WinSize. */
607 ignorable |= (1ULL << 0x30);
608 ignorable |= (1ULL << 0x31);
609
610 /* Checksum. */
611 ignorable |= (1ULL << 0x32);
612 ignorable |= (1ULL << 0x33);
613
614 for (i = 0; i < len; i++, ignorable >>= 1) {
615
616 if ((ignorable & 1) || (s1[i] == s2[i]))
617 continue;
618
619#ifdef TILE_NET_DEBUG
620 /* HACK: Mention non-timestamp diffs. */
621 if (i < 0x38 && i != 0x2f &&
622 net_ratelimit())
623 pr_info("Diff at 0x%x\n", i);
624#endif
625
626 return false;
627 }
628
629#ifdef TILE_NET_NO_SUPPRESS_DUP_ACKS
630 /* HACK: Do not suppress truly duplicate ACKs. */
631 /* ISSUE: Is this actually necessary or helpful? */
632 if (s1[0x2a] == s2[0x2a] &&
633 s1[0x2b] == s2[0x2b] &&
634 s1[0x2c] == s2[0x2c] &&
635 s1[0x2d] == s2[0x2d]) {
636 return false;
637 }
638#endif
639
640 return true;
641}
642
643#endif
644
645
646
647/*
648 * Like "tile_net_handle_packets()", but just discard packets.
649 */
650static void tile_net_discard_packets(struct net_device *dev)
651{
652 struct tile_net_priv *priv = netdev_priv(dev);
653 int my_cpu = smp_processor_id();
654 struct tile_net_cpu *info = priv->cpu[my_cpu];
655 struct tile_netio_queue *queue = &info->queue;
656 netio_queue_impl_t *qsp = queue->__system_part;
657 netio_queue_user_impl_t *qup = &queue->__user_part;
658
659 while (qup->__packet_receive_read !=
660 qsp->__packet_receive_queue.__packet_write) {
661
662 int index = qup->__packet_receive_read;
663
664 int index2_aux = index + sizeof(netio_pkt_t);
665 int index2 =
666 ((index2_aux ==
667 qsp->__packet_receive_queue.__last_packet_plus_one) ?
668 0 : index2_aux);
669
670 netio_pkt_t *pkt = (netio_pkt_t *)
671 ((unsigned long) &qsp[1] + index);
672
673 /* Extract the "linux_buffer_t". */
674 unsigned int buffer = pkt->__packet.word;
675
676 /* Convert "linux_buffer_t" to "va". */
677 void *va = __va((phys_addr_t)(buffer >> 1) << 7);
678
679 /* Acquire the associated "skb". */
680 struct sk_buff **skb_ptr = va - sizeof(*skb_ptr);
681 struct sk_buff *skb = *skb_ptr;
682
683 kfree_skb(skb);
684
685 /* Consume this packet. */
686 qup->__packet_receive_read = index2;
687 }
688}
689
690
691/*
692 * Handle the next packet. Return true if "processed", false if "filtered".
693 */
694static bool tile_net_poll_aux(struct tile_net_cpu *info, int index)
695{
696 struct net_device *dev = info->napi.dev;
697
698 struct tile_netio_queue *queue = &info->queue;
699 netio_queue_impl_t *qsp = queue->__system_part;
700 netio_queue_user_impl_t *qup = &queue->__user_part;
701 struct tile_net_stats_t *stats = &info->stats;
702
703 int filter;
704
705 int index2_aux = index + sizeof(netio_pkt_t);
706 int index2 =
707 ((index2_aux ==
708 qsp->__packet_receive_queue.__last_packet_plus_one) ?
709 0 : index2_aux);
710
711 netio_pkt_t *pkt = (netio_pkt_t *)((unsigned long) &qsp[1] + index);
712
713 netio_pkt_metadata_t *metadata = NETIO_PKT_METADATA(pkt);
714
715 /* Extract the packet size. */
716 unsigned long len =
717 (NETIO_PKT_CUSTOM_LENGTH(pkt) +
718 NET_IP_ALIGN - NETIO_PACKET_PADDING);
719
720 /* Extract the "linux_buffer_t". */
721 unsigned int buffer = pkt->__packet.word;
722
723 /* Extract "small" (vs "large"). */
724 bool small = ((buffer & 1) != 0);
725
726 /* Convert "linux_buffer_t" to "va". */
727 void *va = __va((phys_addr_t)(buffer >> 1) << 7);
728
729 /* Extract the packet data pointer. */
730 /* Compare to "NETIO_PKT_CUSTOM_DATA(pkt)". */
731 unsigned char *buf = va + NET_IP_ALIGN;
732
733#ifdef IGNORE_DUP_ACKS
734
735 static int other;
736 static int final;
737 static int keep;
738 static int skip;
739
740#endif
741
742 /* Invalidate the packet buffer. */
743 if (!hash_default)
744 __inv_buffer(buf, len);
745
746 /* ISSUE: Is this needed? */
747 dev->last_rx = jiffies;
748
749#ifdef TILE_NET_DUMP_PACKETS
750 dump_packet(buf, len, "rx");
751#endif /* TILE_NET_DUMP_PACKETS */
752
753#ifdef TILE_NET_VERIFY_INGRESS
754 if (!NETIO_PKT_L4_CSUM_CORRECT_M(metadata, pkt) &&
755 NETIO_PKT_L4_CSUM_CALCULATED_M(metadata, pkt)) {
756 /*
757 * FIXME: This complains about UDP packets
758 * with a "zero" checksum (bug 6624).
759 */
760#ifdef TILE_NET_PANIC_ON_BAD
761 dump_packet(buf, len, "rx");
762 panic("Bad L4 checksum.");
763#else
764 pr_warning("Bad L4 checksum on %d byte packet.\n", len);
765#endif
766 }
767 if (!NETIO_PKT_L3_CSUM_CORRECT_M(metadata, pkt) &&
768 NETIO_PKT_L3_CSUM_CALCULATED_M(metadata, pkt)) {
769 dump_packet(buf, len, "rx");
770 panic("Bad L3 checksum.");
771 }
772 switch (NETIO_PKT_STATUS_M(metadata, pkt)) {
773 case NETIO_PKT_STATUS_OVERSIZE:
774 if (len >= 64) {
775 dump_packet(buf, len, "rx");
776 panic("Unexpected OVERSIZE.");
777 }
778 break;
779 case NETIO_PKT_STATUS_BAD:
780#ifdef TILE_NET_PANIC_ON_BAD
781 dump_packet(buf, len, "rx");
782 panic("Unexpected BAD packet.");
783#else
784 pr_warning("Unexpected BAD %d byte packet.\n", len);
785#endif
786 }
787#endif
788
789 filter = 0;
790
791 if (!(dev->flags & IFF_UP)) {
792 /* Filter packets received before we're up. */
793 filter = 1;
794 } else if (!(dev->flags & IFF_PROMISC)) {
795 /*
796 * FIXME: Implement HW multicast filter.
797 */
798 if (!IS_MULTICAST(buf) && !IS_BROADCAST(buf)) {
799 /* Filter packets not for our address. */
800 const u8 *mine = dev->dev_addr;
801 filter = compare_ether_addr(mine, buf);
802 }
803 }
804
805#ifdef IGNORE_DUP_ACKS
806
807 if (len != 66) {
808 /* FIXME: Must check "is_tcp_ack(buf, len)" somehow. */
809
810 other++;
811
812 } else if (index2 ==
813 qsp->__packet_receive_queue.__packet_write) {
814
815 final++;
816
817 } else {
818
819 netio_pkt_t *pkt2 = (netio_pkt_t *)
820 ((unsigned long) &qsp[1] + index2);
821
822 netio_pkt_metadata_t *metadata2 =
823 NETIO_PKT_METADATA(pkt2);
824
825 /* Extract the packet size. */
826 unsigned long len2 =
827 (NETIO_PKT_CUSTOM_LENGTH(pkt2) +
828 NET_IP_ALIGN - NETIO_PACKET_PADDING);
829
830 if (len2 == 66 &&
831 NETIO_PKT_FLOW_HASH_M(metadata, pkt) ==
832 NETIO_PKT_FLOW_HASH_M(metadata2, pkt2)) {
833
834 /* Extract the "linux_buffer_t". */
835 unsigned int buffer2 = pkt2->__packet.word;
836
837 /* Convert "linux_buffer_t" to "va". */
838 void *va2 =
839 __va((phys_addr_t)(buffer2 >> 1) << 7);
840
841 /* Extract the packet data pointer. */
842 /* Compare to "NETIO_PKT_CUSTOM_DATA(pkt)". */
843 unsigned char *buf2 = va2 + NET_IP_ALIGN;
844
845 /* Invalidate the packet buffer. */
846 if (!hash_default)
847 __inv_buffer(buf2, len2);
848
849 if (is_dup_ack(buf, buf2, len)) {
850 skip++;
851 filter = 1;
852 } else {
853 keep++;
854 }
855 }
856 }
857
858 if (net_ratelimit())
859 pr_info("Other %d Final %d Keep %d Skip %d.\n",
860 other, final, keep, skip);
861
862#endif
863
864 if (filter) {
865
866 /* ISSUE: Update "drop" statistics? */
867
868 tile_net_provide_linux_buffer(info, va, small);
869
870 } else {
871
872 /* Acquire the associated "skb". */
873 struct sk_buff **skb_ptr = va - sizeof(*skb_ptr);
874 struct sk_buff *skb = *skb_ptr;
875
876 /* Paranoia. */
877 if (skb->data != buf)
878 panic("Corrupt linux buffer from LIPP! "
879 "VA=%p, skb=%p, skb->data=%p\n",
880 va, skb, skb->data);
881
882 /* Encode the actual packet length. */
883 skb_put(skb, len);
884
885 /* NOTE: This call also sets "skb->dev = dev". */
886 skb->protocol = eth_type_trans(skb, dev);
887
888 /* ISSUE: Discard corrupt packets? */
889 /* ISSUE: Discard packets with bad checksums? */
890
891 /* Avoid recomputing TCP/UDP checksums. */
892 if (NETIO_PKT_L4_CSUM_CORRECT_M(metadata, pkt))
893 skb->ip_summed = CHECKSUM_UNNECESSARY;
894
895 netif_receive_skb(skb);
896
897 stats->rx_packets++;
898 stats->rx_bytes += len;
899
900 if (small)
901 info->num_needed_small_buffers++;
902 else
903 info->num_needed_large_buffers++;
904 }
905
906 /* Return four credits after every fourth packet. */
907 if (--qup->__receive_credit_remaining == 0) {
908 u32 interval = qup->__receive_credit_interval;
909 qup->__receive_credit_remaining = interval;
910 __netio_fastio_return_credits(qup->__fastio_index, interval);
911 }
912
913 /* Consume this packet. */
914 qup->__packet_receive_read = index2;
915
916 return !filter;
917}
918
919
920/*
921 * Handle some packets for the given device on the current CPU.
922 *
923 * ISSUE: The "rotting packet" race condition occurs if a packet
924 * arrives after the queue appears to be empty, and before the
925 * hypervisor interrupt is re-enabled.
926 */
927static int tile_net_poll(struct napi_struct *napi, int budget)
928{
929 struct net_device *dev = napi->dev;
930 struct tile_net_priv *priv = netdev_priv(dev);
931 int my_cpu = smp_processor_id();
932 struct tile_net_cpu *info = priv->cpu[my_cpu];
933 struct tile_netio_queue *queue = &info->queue;
934 netio_queue_impl_t *qsp = queue->__system_part;
935 netio_queue_user_impl_t *qup = &queue->__user_part;
936
937 unsigned int work = 0;
938
939 while (1) {
940 int index = qup->__packet_receive_read;
941 if (index == qsp->__packet_receive_queue.__packet_write)
942 break;
943
944 if (tile_net_poll_aux(info, index)) {
945 if (++work >= budget)
946 goto done;
947 }
948 }
949
950 napi_complete(&info->napi);
951
952 /* Re-enable hypervisor interrupts. */
953 enable_percpu_irq(priv->intr_id);
954
955 /* HACK: Avoid the "rotting packet" problem. */
956 if (qup->__packet_receive_read !=
957 qsp->__packet_receive_queue.__packet_write)
958 napi_schedule(&info->napi);
959
960 /* ISSUE: Handle completions? */
961
962done:
963
964 tile_net_provide_needed_buffers(info);
965
966 return work;
967}
968
969
970/*
971 * Handle an ingress interrupt for the given device on the current cpu.
972 */
973static irqreturn_t tile_net_handle_ingress_interrupt(int irq, void *dev_ptr)
974{
975 struct net_device *dev = (struct net_device *)dev_ptr;
976 struct tile_net_priv *priv = netdev_priv(dev);
977 int my_cpu = smp_processor_id();
978 struct tile_net_cpu *info = priv->cpu[my_cpu];
979
980 /* Disable hypervisor interrupt. */
981 disable_percpu_irq(priv->intr_id);
982
983 napi_schedule(&info->napi);
984
985 return IRQ_HANDLED;
986}
987
988
989/*
990 * One time initialization per interface.
991 */
992static int tile_net_open_aux(struct net_device *dev)
993{
994 struct tile_net_priv *priv = netdev_priv(dev);
995
996 int ret;
997 int dummy;
998 unsigned int epp_lotar;
999
1000 /*
1001 * Find out where EPP memory should be homed.
1002 */
1003 ret = hv_dev_pread(priv->hv_devhdl, 0,
1004 (HV_VirtAddr)&epp_lotar, sizeof(epp_lotar),
1005 NETIO_EPP_SHM_OFF);
1006 if (ret < 0) {
1007 pr_err("could not read epp_shm_queue lotar.\n");
1008 return -EIO;
1009 }
1010
1011 /*
1012 * Home the page on the EPP.
1013 */
1014 {
1015 int epp_home = hv_lotar_to_cpu(epp_lotar);
1016 struct page *page = virt_to_page(priv->epp_queue);
1017 homecache_change_page_home(page, 0, epp_home);
1018 }
1019
1020 /*
1021 * Register the EPP shared memory queue.
1022 */
1023 {
1024 netio_ipp_address_t ea = {
1025 .va = 0,
1026 .pa = __pa(priv->epp_queue),
1027 .pte = hv_pte(0),
1028 .size = PAGE_SIZE,
1029 };
1030 ea.pte = hv_pte_set_lotar(ea.pte, epp_lotar);
1031 ea.pte = hv_pte_set_mode(ea.pte, HV_PTE_MODE_CACHE_TILE_L3);
1032 ret = hv_dev_pwrite(priv->hv_devhdl, 0,
1033 (HV_VirtAddr)&ea,
1034 sizeof(ea),
1035 NETIO_EPP_SHM_OFF);
1036 if (ret < 0)
1037 return -EIO;
1038 }
1039
1040 /*
1041 * Start LIPP/LEPP.
1042 */
1043 if (hv_dev_pwrite(priv->hv_devhdl, 0, (HV_VirtAddr)&dummy,
1044 sizeof(dummy), NETIO_IPP_START_SHIM_OFF) < 0) {
1045 pr_warning("Failed to start LIPP/LEPP.\n");
1046 return -EIO;
1047 }
1048
1049 return 0;
1050}
1051
1052
1053/*
1054 * Register with hypervisor on each CPU.
1055 *
1056 * Strangely, this function does important things even if it "fails",
1057 * which is especially common if the link is not up yet. Hopefully
1058 * these things are all "harmless" if done twice!
1059 */
1060static void tile_net_register(void *dev_ptr)
1061{
1062 struct net_device *dev = (struct net_device *)dev_ptr;
1063 struct tile_net_priv *priv = netdev_priv(dev);
1064 int my_cpu = smp_processor_id();
1065 struct tile_net_cpu *info;
1066
1067 struct tile_netio_queue *queue;
1068
1069 /* Only network cpus can receive packets. */
1070 int queue_id =
1071 cpumask_test_cpu(my_cpu, &priv->network_cpus_map) ? 0 : 255;
1072
1073 netio_input_config_t config = {
1074 .flags = 0,
1075 .num_receive_packets = priv->network_cpus_credits,
1076 .queue_id = queue_id
1077 };
1078
1079 int ret = 0;
1080 netio_queue_impl_t *queuep;
1081
1082 PDEBUG("tile_net_register(queue_id %d)\n", queue_id);
1083
1084 if (!strcmp(dev->name, "xgbe0"))
1085 info = &__get_cpu_var(hv_xgbe0);
1086 else if (!strcmp(dev->name, "xgbe1"))
1087 info = &__get_cpu_var(hv_xgbe1);
1088 else if (!strcmp(dev->name, "gbe0"))
1089 info = &__get_cpu_var(hv_gbe0);
1090 else if (!strcmp(dev->name, "gbe1"))
1091 info = &__get_cpu_var(hv_gbe1);
1092 else
1093 BUG();
1094
1095 /* Initialize the egress timer. */
1096 init_timer(&info->egress_timer);
1097 info->egress_timer.data = (long)info;
1098 info->egress_timer.function = tile_net_handle_egress_timer;
1099
1100 priv->cpu[my_cpu] = info;
1101
1102 /*
1103 * Register ourselves with the IPP.
1104 */
1105 ret = hv_dev_pwrite(priv->hv_devhdl, 0,
1106 (HV_VirtAddr)&config,
1107 sizeof(netio_input_config_t),
1108 NETIO_IPP_INPUT_REGISTER_OFF);
1109 PDEBUG("hv_dev_pwrite(NETIO_IPP_INPUT_REGISTER_OFF) returned %d\n",
1110 ret);
1111 if (ret < 0) {
1112 printk(KERN_DEBUG "hv_dev_pwrite NETIO_IPP_INPUT_REGISTER_OFF"
1113 " failure %d\n", ret);
1114 info->link_down = (ret == NETIO_LINK_DOWN);
1115 return;
1116 }
1117
1118 /*
1119 * Get the pointer to our queue's system part.
1120 */
1121
1122 ret = hv_dev_pread(priv->hv_devhdl, 0,
1123 (HV_VirtAddr)&queuep,
1124 sizeof(netio_queue_impl_t *),
1125 NETIO_IPP_INPUT_REGISTER_OFF);
1126 PDEBUG("hv_dev_pread(NETIO_IPP_INPUT_REGISTER_OFF) returned %d\n",
1127 ret);
1128 PDEBUG("queuep %p\n", queuep);
1129 if (ret <= 0) {
1130 /* ISSUE: Shouldn't this be a fatal error? */
1131 pr_err("hv_dev_pread NETIO_IPP_INPUT_REGISTER_OFF failure\n");
1132 return;
1133 }
1134
1135 queue = &info->queue;
1136
1137 queue->__system_part = queuep;
1138
1139 memset(&queue->__user_part, 0, sizeof(netio_queue_user_impl_t));
1140
1141 /* This is traditionally "config.num_receive_packets / 2". */
1142 queue->__user_part.__receive_credit_interval = 4;
1143 queue->__user_part.__receive_credit_remaining =
1144 queue->__user_part.__receive_credit_interval;
1145
1146 /*
1147 * Get a fastio index from the hypervisor.
1148 * ISSUE: Shouldn't this check the result?
1149 */
1150 ret = hv_dev_pread(priv->hv_devhdl, 0,
1151 (HV_VirtAddr)&queue->__user_part.__fastio_index,
1152 sizeof(queue->__user_part.__fastio_index),
1153 NETIO_IPP_GET_FASTIO_OFF);
1154 PDEBUG("hv_dev_pread(NETIO_IPP_GET_FASTIO_OFF) returned %d\n", ret);
1155
1156 netif_napi_add(dev, &info->napi, tile_net_poll, 64);
1157
1158 /* Now we are registered. */
1159 info->registered = true;
1160}
1161
1162
1163/*
1164 * Unregister with hypervisor on each CPU.
1165 */
1166static void tile_net_unregister(void *dev_ptr)
1167{
1168 struct net_device *dev = (struct net_device *)dev_ptr;
1169 struct tile_net_priv *priv = netdev_priv(dev);
1170 int my_cpu = smp_processor_id();
1171 struct tile_net_cpu *info = priv->cpu[my_cpu];
1172
1173 int ret = 0;
1174 int dummy = 0;
1175
1176 /* Do nothing if never registered. */
1177 if (info == NULL)
1178 return;
1179
1180 /* Do nothing if already unregistered. */
1181 if (!info->registered)
1182 return;
1183
1184 /*
1185 * Unregister ourselves with LIPP.
1186 */
1187 ret = hv_dev_pwrite(priv->hv_devhdl, 0, (HV_VirtAddr)&dummy,
1188 sizeof(dummy), NETIO_IPP_INPUT_UNREGISTER_OFF);
1189 PDEBUG("hv_dev_pwrite(NETIO_IPP_INPUT_UNREGISTER_OFF) returned %d\n",
1190 ret);
1191 if (ret < 0) {
1192 /* FIXME: Just panic? */
1193 pr_err("hv_dev_pwrite NETIO_IPP_INPUT_UNREGISTER_OFF"
1194 " failure %d\n", ret);
1195 }
1196
1197 /*
1198 * Discard all packets still in our NetIO queue. Hopefully,
1199 * once the unregister call is complete, there will be no
1200 * packets still in flight on the IDN.
1201 */
1202 tile_net_discard_packets(dev);
1203
1204 /* Reset state. */
1205 info->num_needed_small_buffers = 0;
1206 info->num_needed_large_buffers = 0;
1207
1208 /* Cancel egress timer. */
1209 del_timer(&info->egress_timer);
1210 info->egress_timer_scheduled = false;
1211
1212 netif_napi_del(&info->napi);
1213
1214 /* Now we are unregistered. */
1215 info->registered = false;
1216}
1217
1218
1219/*
1220 * Helper function for "tile_net_stop()".
1221 *
1222 * Also used to handle registration failure in "tile_net_open_inner()",
1223 * when "fully_opened" is known to be false, and the various extra
1224 * steps in "tile_net_stop()" are not necessary. ISSUE: It might be
1225 * simpler if we could just call "tile_net_stop()" anyway.
1226 */
1227static void tile_net_stop_aux(struct net_device *dev)
1228{
1229 struct tile_net_priv *priv = netdev_priv(dev);
1230
1231 int dummy = 0;
1232
1233 /* Unregister all tiles, so LIPP will stop delivering packets. */
1234 on_each_cpu(tile_net_unregister, (void *)dev, 1);
1235
1236 /* Stop LIPP/LEPP. */
1237 if (hv_dev_pwrite(priv->hv_devhdl, 0, (HV_VirtAddr)&dummy,
1238 sizeof(dummy), NETIO_IPP_STOP_SHIM_OFF) < 0)
1239 panic("Failed to stop LIPP/LEPP!\n");
1240
1241 priv->partly_opened = 0;
1242}
1243
1244
1245/*
1246 * Disable ingress interrupts for the given device on the current cpu.
1247 */
1248static void tile_net_disable_intr(void *dev_ptr)
1249{
1250 struct net_device *dev = (struct net_device *)dev_ptr;
1251 struct tile_net_priv *priv = netdev_priv(dev);
1252 int my_cpu = smp_processor_id();
1253 struct tile_net_cpu *info = priv->cpu[my_cpu];
1254
1255 /* Disable hypervisor interrupt. */
1256 disable_percpu_irq(priv->intr_id);
1257
1258 /* Disable NAPI if needed. */
1259 if (info != NULL && info->napi_enabled) {
1260 napi_disable(&info->napi);
1261 info->napi_enabled = false;
1262 }
1263}
1264
1265
1266/*
1267 * Enable ingress interrupts for the given device on the current cpu.
1268 */
1269static void tile_net_enable_intr(void *dev_ptr)
1270{
1271 struct net_device *dev = (struct net_device *)dev_ptr;
1272 struct tile_net_priv *priv = netdev_priv(dev);
1273 int my_cpu = smp_processor_id();
1274 struct tile_net_cpu *info = priv->cpu[my_cpu];
1275
1276 /* Enable hypervisor interrupt. */
1277 enable_percpu_irq(priv->intr_id);
1278
1279 /* Enable NAPI. */
1280 napi_enable(&info->napi);
1281 info->napi_enabled = true;
1282}
1283
1284
1285/*
1286 * tile_net_open_inner does most of the work of bringing up the interface.
1287 * It's called from tile_net_open(), and also from tile_net_retry_open().
1288 * The return value is 0 if the interface was brought up, < 0 if
1289 * tile_net_open() should return the return value as an error, and > 0 if
1290 * tile_net_open() should return success and schedule a work item to
1291 * periodically retry the bringup.
1292 */
1293static int tile_net_open_inner(struct net_device *dev)
1294{
1295 struct tile_net_priv *priv = netdev_priv(dev);
1296 int my_cpu = smp_processor_id();
1297 struct tile_net_cpu *info;
1298 struct tile_netio_queue *queue;
1299 unsigned int irq;
1300 int i;
1301
1302 /*
1303 * First try to register just on the local CPU, and handle any
1304 * semi-expected "link down" failure specially. Note that we
1305 * do NOT call "tile_net_stop_aux()", unlike below.
1306 */
1307 tile_net_register(dev);
1308 info = priv->cpu[my_cpu];
1309 if (!info->registered) {
1310 if (info->link_down)
1311 return 1;
1312 return -EAGAIN;
1313 }
1314
1315 /*
1316 * Now register everywhere else. If any registration fails,
1317 * even for "link down" (which might not be possible), we
1318 * clean up using "tile_net_stop_aux()".
1319 */
1320 smp_call_function(tile_net_register, (void *)dev, 1);
1321 for_each_online_cpu(i) {
1322 if (!priv->cpu[i]->registered) {
1323 tile_net_stop_aux(dev);
1324 return -EAGAIN;
1325 }
1326 }
1327
1328 queue = &info->queue;
1329
1330 /*
1331 * Set the device intr bit mask.
1332 * The tile_net_register above sets per tile __intr_id.
1333 */
1334 priv->intr_id = queue->__system_part->__intr_id;
1335 BUG_ON(!priv->intr_id);
1336
1337 /*
1338 * Register the device interrupt handler.
1339 * The __ffs() function returns the index into the interrupt handler
1340 * table from the interrupt bit mask which should have one bit
1341 * and one bit only set.
1342 */
1343 irq = __ffs(priv->intr_id);
1344 tile_irq_activate(irq, TILE_IRQ_PERCPU);
1345 BUG_ON(request_irq(irq, tile_net_handle_ingress_interrupt,
1346 0, dev->name, (void *)dev) != 0);
1347
1348 /* ISSUE: How could "priv->fully_opened" ever be "true" here? */
1349
1350 if (!priv->fully_opened) {
1351
1352 int dummy = 0;
1353
1354 /* Allocate initial buffers. */
1355
1356 int max_buffers =
1357 priv->network_cpus_count * priv->network_cpus_credits;
1358
1359 info->num_needed_small_buffers =
1360 min(LIPP_SMALL_BUFFERS, max_buffers);
1361
1362 info->num_needed_large_buffers =
1363 min(LIPP_LARGE_BUFFERS, max_buffers);
1364
1365 tile_net_provide_needed_buffers(info);
1366
1367 if (info->num_needed_small_buffers != 0 ||
1368 info->num_needed_large_buffers != 0)
1369 panic("Insufficient memory for buffer stack!");
1370
1371 /* Start LIPP/LEPP and activate "ingress" at the shim. */
1372 if (hv_dev_pwrite(priv->hv_devhdl, 0, (HV_VirtAddr)&dummy,
1373 sizeof(dummy), NETIO_IPP_INPUT_INIT_OFF) < 0)
1374 panic("Failed to activate the LIPP Shim!\n");
1375
1376 priv->fully_opened = 1;
1377 }
1378
1379 /* On each tile, enable the hypervisor to trigger interrupts. */
1380 /* ISSUE: Do this before starting LIPP/LEPP? */
1381 on_each_cpu(tile_net_enable_intr, (void *)dev, 1);
1382
1383 /* Start our transmit queue. */
1384 netif_start_queue(dev);
1385
1386 return 0;
1387}
1388
1389
1390/*
1391 * Called periodically to retry bringing up the NetIO interface,
1392 * if it doesn't come up cleanly during tile_net_open().
1393 */
1394static void tile_net_open_retry(struct work_struct *w)
1395{
1396 struct delayed_work *dw =
1397 container_of(w, struct delayed_work, work);
1398
1399 struct tile_net_priv *priv =
1400 container_of(dw, struct tile_net_priv, retry_work);
1401
1402 /*
1403 * Try to bring the NetIO interface up. If it fails, reschedule
1404 * ourselves to try again later; otherwise, tell Linux we now have
1405 * a working link. ISSUE: What if the return value is negative?
1406 */
1407 if (tile_net_open_inner(priv->dev))
1408 schedule_delayed_work_on(singlethread_cpu, &priv->retry_work,
1409 TILE_NET_RETRY_INTERVAL);
1410 else
1411 netif_carrier_on(priv->dev);
1412}
1413
1414
1415/*
1416 * Called when a network interface is made active.
1417 *
1418 * Returns 0 on success, negative value on failure.
1419 *
1420 * The open entry point is called when a network interface is made
1421 * active by the system (IFF_UP). At this point all resources needed
1422 * for transmit and receive operations are allocated, the interrupt
1423 * handler is registered with the OS, the watchdog timer is started,
1424 * and the stack is notified that the interface is ready.
1425 *
1426 * If the actual link is not available yet, then we tell Linux that
1427 * we have no carrier, and we keep checking until the link comes up.
1428 */
1429static int tile_net_open(struct net_device *dev)
1430{
1431 int ret = 0;
1432 struct tile_net_priv *priv = netdev_priv(dev);
1433
1434 /*
1435 * We rely on priv->partly_opened to tell us if this is the
1436 * first time this interface is being brought up. If it is
1437 * set, the IPP was already initialized and should not be
1438 * initialized again.
1439 */
1440 if (!priv->partly_opened) {
1441
1442 int count;
1443 int credits;
1444
1445 /* Initialize LIPP/LEPP, and start the Shim. */
1446 ret = tile_net_open_aux(dev);
1447 if (ret < 0) {
1448 pr_err("tile_net_open_aux failed: %d\n", ret);
1449 return ret;
1450 }
1451
1452 /* Analyze the network cpus. */
1453
1454 if (network_cpus_used)
1455 cpumask_copy(&priv->network_cpus_map,
1456 &network_cpus_map);
1457 else
1458 cpumask_copy(&priv->network_cpus_map, cpu_online_mask);
1459
1460
1461 count = cpumask_weight(&priv->network_cpus_map);
1462
1463 /* Limit credits to available buffers, and apply min. */
1464 credits = max(16, (LIPP_LARGE_BUFFERS / count) & ~1);
1465
1466 /* Apply "GBE" max limit. */
1467 /* ISSUE: Use higher limit for XGBE? */
1468 credits = min(NETIO_MAX_RECEIVE_PKTS, credits);
1469
1470 priv->network_cpus_count = count;
1471 priv->network_cpus_credits = credits;
1472
1473#ifdef TILE_NET_DEBUG
1474 pr_info("Using %d network cpus, with %d credits each\n",
1475 priv->network_cpus_count, priv->network_cpus_credits);
1476#endif
1477
1478 priv->partly_opened = 1;
1479 }
1480
1481 /*
1482 * Attempt to bring up the link.
1483 */
1484 ret = tile_net_open_inner(dev);
1485 if (ret <= 0) {
1486 if (ret == 0)
1487 netif_carrier_on(dev);
1488 return ret;
1489 }
1490
1491 /*
1492 * We were unable to bring up the NetIO interface, but we want to
1493 * try again in a little bit. Tell Linux that we have no carrier
1494 * so it doesn't try to use the interface before the link comes up
1495 * and then remember to try again later.
1496 */
1497 netif_carrier_off(dev);
1498 schedule_delayed_work_on(singlethread_cpu, &priv->retry_work,
1499 TILE_NET_RETRY_INTERVAL);
1500
1501 return 0;
1502}
1503
1504
1505/*
1506 * Disables a network interface.
1507 *
1508 * Returns 0, this is not allowed to fail.
1509 *
1510 * The close entry point is called when an interface is de-activated
1511 * by the OS. The hardware is still under the drivers control, but
1512 * needs to be disabled. A global MAC reset is issued to stop the
1513 * hardware, and all transmit and receive resources are freed.
1514 *
1515 * ISSUE: Can this can be called while "tile_net_poll()" is running?
1516 */
1517static int tile_net_stop(struct net_device *dev)
1518{
1519 struct tile_net_priv *priv = netdev_priv(dev);
1520
1521 bool pending = true;
1522
1523 PDEBUG("tile_net_stop()\n");
1524
1525 /* ISSUE: Only needed if not yet fully open. */
1526 cancel_delayed_work_sync(&priv->retry_work);
1527
1528 /* Can't transmit any more. */
1529 netif_stop_queue(dev);
1530
1531 /*
1532 * Disable hypervisor interrupts on each tile.
1533 */
1534 on_each_cpu(tile_net_disable_intr, (void *)dev, 1);
1535
1536 /*
1537 * Unregister the interrupt handler.
1538 * The __ffs() function returns the index into the interrupt handler
1539 * table from the interrupt bit mask which should have one bit
1540 * and one bit only set.
1541 */
1542 if (priv->intr_id)
1543 free_irq(__ffs(priv->intr_id), dev);
1544
1545 /*
1546 * Drain all the LIPP buffers.
1547 */
1548
1549 while (true) {
1550 int buffer;
1551
1552 /* NOTE: This should never fail. */
1553 if (hv_dev_pread(priv->hv_devhdl, 0, (HV_VirtAddr)&buffer,
1554 sizeof(buffer), NETIO_IPP_DRAIN_OFF) < 0)
1555 break;
1556
1557 /* Stop when done. */
1558 if (buffer == 0)
1559 break;
1560
1561 {
1562 /* Convert "linux_buffer_t" to "va". */
1563 void *va = __va((phys_addr_t)(buffer >> 1) << 7);
1564
1565 /* Acquire the associated "skb". */
1566 struct sk_buff **skb_ptr = va - sizeof(*skb_ptr);
1567 struct sk_buff *skb = *skb_ptr;
1568
1569 kfree_skb(skb);
1570 }
1571 }
1572
1573 /* Stop LIPP/LEPP. */
1574 tile_net_stop_aux(dev);
1575
1576
1577 priv->fully_opened = 0;
1578
1579
1580 /*
1581 * XXX: ISSUE: It appears that, in practice anyway, by the
1582 * time we get here, there are no pending completions.
1583 */
1584 while (pending) {
1585
1586 struct sk_buff *olds[32];
1587 unsigned int wanted = 32;
1588 unsigned int i, nolds = 0;
1589
1590 nolds = tile_net_lepp_grab_comps(dev, olds,
1591 wanted, &pending);
1592
1593 /* ISSUE: We have never actually seen this debug spew. */
1594 if (nolds != 0)
1595 pr_info("During tile_net_stop(), grabbed %d comps.\n",
1596 nolds);
1597
1598 for (i = 0; i < nolds; i++)
1599 kfree_skb(olds[i]);
1600 }
1601
1602
1603 /* Wipe the EPP queue. */
1604 memset(priv->epp_queue, 0, sizeof(lepp_queue_t));
1605
1606 /* Evict the EPP queue. */
1607 finv_buffer(priv->epp_queue, PAGE_SIZE);
1608
1609 return 0;
1610}
1611
1612
1613/*
1614 * Prepare the "frags" info for the resulting LEPP command.
1615 *
1616 * If needed, flush the memory used by the frags.
1617 */
1618static unsigned int tile_net_tx_frags(lepp_frag_t *frags,
1619 struct sk_buff *skb,
1620 void *b_data, unsigned int b_len)
1621{
1622 unsigned int i, n = 0;
1623
1624 struct skb_shared_info *sh = skb_shinfo(skb);
1625
1626 phys_addr_t cpa;
1627
1628 if (b_len != 0) {
1629
1630 if (!hash_default)
1631 finv_buffer_remote(b_data, b_len);
1632
1633 cpa = __pa(b_data);
1634 frags[n].cpa_lo = cpa;
1635 frags[n].cpa_hi = cpa >> 32;
1636 frags[n].length = b_len;
1637 frags[n].hash_for_home = hash_default;
1638 n++;
1639 }
1640
1641 for (i = 0; i < sh->nr_frags; i++) {
1642
1643 skb_frag_t *f = &sh->frags[i];
1644 unsigned long pfn = page_to_pfn(f->page);
1645
1646 /* FIXME: Compute "hash_for_home" properly. */
1647 /* ISSUE: The hypervisor checks CHIP_HAS_REV1_DMA_PACKETS(). */
1648 int hash_for_home = hash_default;
1649
1650 /* FIXME: Hmmm. */
1651 if (!hash_default) {
1652 void *va = pfn_to_kaddr(pfn) + f->page_offset;
1653 BUG_ON(PageHighMem(f->page));
1654 finv_buffer_remote(va, f->size);
1655 }
1656
1657 cpa = ((phys_addr_t)pfn << PAGE_SHIFT) + f->page_offset;
1658 frags[n].cpa_lo = cpa;
1659 frags[n].cpa_hi = cpa >> 32;
1660 frags[n].length = f->size;
1661 frags[n].hash_for_home = hash_for_home;
1662 n++;
1663 }
1664
1665 return n;
1666}
1667
1668
1669/*
1670 * This function takes "skb", consisting of a header template and a
1671 * payload, and hands it to LEPP, to emit as one or more segments,
1672 * each consisting of a possibly modified header, plus a piece of the
1673 * payload, via a process known as "tcp segmentation offload".
1674 *
1675 * Usually, "data" will contain the header template, of size "sh_len",
1676 * and "sh->frags" will contain "skb->data_len" bytes of payload, and
1677 * there will be "sh->gso_segs" segments.
1678 *
1679 * Sometimes, if "sendfile()" requires copying, we will be called with
1680 * "data" containing the header and payload, with "frags" being empty.
1681 *
1682 * In theory, "sh->nr_frags" could be 3, but in practice, it seems
1683 * that this will never actually happen.
1684 *
1685 * See "emulate_large_send_offload()" for some reference code, which
1686 * does not handle checksumming.
1687 *
1688 * ISSUE: How do we make sure that high memory DMA does not migrate?
1689 */
1690static int tile_net_tx_tso(struct sk_buff *skb, struct net_device *dev)
1691{
1692 struct tile_net_priv *priv = netdev_priv(dev);
1693 int my_cpu = smp_processor_id();
1694 struct tile_net_cpu *info = priv->cpu[my_cpu];
1695 struct tile_net_stats_t *stats = &info->stats;
1696
1697 struct skb_shared_info *sh = skb_shinfo(skb);
1698
1699 unsigned char *data = skb->data;
1700
1701 /* The ip header follows the ethernet header. */
1702 struct iphdr *ih = ip_hdr(skb);
1703 unsigned int ih_len = ih->ihl * 4;
1704
1705 /* Note that "nh == ih", by definition. */
1706 unsigned char *nh = skb_network_header(skb);
1707 unsigned int eh_len = nh - data;
1708
1709 /* The tcp header follows the ip header. */
1710 struct tcphdr *th = (struct tcphdr *)(nh + ih_len);
1711 unsigned int th_len = th->doff * 4;
1712
1713 /* The total number of header bytes. */
1714 /* NOTE: This may be less than skb_headlen(skb). */
1715 unsigned int sh_len = eh_len + ih_len + th_len;
1716
1717 /* The number of payload bytes at "skb->data + sh_len". */
1718 /* This is non-zero for sendfile() without HIGHDMA. */
1719 unsigned int b_len = skb_headlen(skb) - sh_len;
1720
1721 /* The total number of payload bytes. */
1722 unsigned int d_len = b_len + skb->data_len;
1723
1724 /* The maximum payload size. */
1725 unsigned int p_len = sh->gso_size;
1726
1727 /* The total number of segments. */
1728 unsigned int num_segs = sh->gso_segs;
1729
1730 /* The temporary copy of the command. */
1731 u32 cmd_body[(LEPP_MAX_CMD_SIZE + 3) / 4];
1732 lepp_tso_cmd_t *cmd = (lepp_tso_cmd_t *)cmd_body;
1733
1734 /* Analyze the "frags". */
1735 unsigned int num_frags =
1736 tile_net_tx_frags(cmd->frags, skb, data + sh_len, b_len);
1737
1738 /* The size of the command, including frags and header. */
1739 size_t cmd_size = LEPP_TSO_CMD_SIZE(num_frags, sh_len);
1740
1741 /* The command header. */
1742 lepp_tso_cmd_t cmd_init = {
1743 .tso = true,
1744 .header_size = sh_len,
1745 .ip_offset = eh_len,
1746 .tcp_offset = eh_len + ih_len,
1747 .payload_size = p_len,
1748 .num_frags = num_frags,
1749 };
1750
1751 unsigned long irqflags;
1752
1753 lepp_queue_t *eq = priv->epp_queue;
1754
1755 struct sk_buff *olds[4];
1756 unsigned int wanted = 4;
1757 unsigned int i, nolds = 0;
1758
1759 unsigned int cmd_head, cmd_tail, cmd_next;
1760 unsigned int comp_tail;
1761
1762 unsigned int free_slots;
1763
1764
1765 /* Paranoia. */
1766 BUG_ON(skb->protocol != htons(ETH_P_IP));
1767 BUG_ON(ih->protocol != IPPROTO_TCP);
1768 BUG_ON(skb->ip_summed != CHECKSUM_PARTIAL);
1769 BUG_ON(num_frags > LEPP_MAX_FRAGS);
1770 /*--BUG_ON(num_segs != (d_len + (p_len - 1)) / p_len); */
1771 BUG_ON(num_segs <= 1);
1772
1773
1774 /* Finish preparing the command. */
1775
1776 /* Copy the command header. */
1777 *cmd = cmd_init;
1778
1779 /* Copy the "header". */
1780 memcpy(&cmd->frags[num_frags], data, sh_len);
1781
1782
1783 /* Prefetch and wait, to minimize time spent holding the spinlock. */
1784 prefetch_L1(&eq->comp_tail);
1785 prefetch_L1(&eq->cmd_tail);
1786 mb();
1787
1788
1789 /* Enqueue the command. */
1790
1791 spin_lock_irqsave(&priv->cmd_lock, irqflags);
1792
1793 /*
1794 * Handle completions if needed to make room.
1795 * HACK: Spin until there is sufficient room.
1796 */
1797 free_slots = lepp_num_free_comp_slots(eq);
1798 if (free_slots < 1) {
1799spin:
1800 nolds += tile_net_lepp_grab_comps(dev, olds + nolds,
1801 wanted - nolds, NULL);
1802 if (lepp_num_free_comp_slots(eq) < 1)
1803 goto spin;
1804 }
1805
1806 cmd_head = eq->cmd_head;
1807 cmd_tail = eq->cmd_tail;
1808
1809 /* NOTE: The "gotos" below are untested. */
1810
1811 /* Prepare to advance, detecting full queue. */
1812 cmd_next = cmd_tail + cmd_size;
1813 if (cmd_tail < cmd_head && cmd_next >= cmd_head)
1814 goto spin;
1815 if (cmd_next > LEPP_CMD_LIMIT) {
1816 cmd_next = 0;
1817 if (cmd_next == cmd_head)
1818 goto spin;
1819 }
1820
1821 /* Copy the command. */
1822 memcpy(&eq->cmds[cmd_tail], cmd, cmd_size);
1823
1824 /* Advance. */
1825 cmd_tail = cmd_next;
1826
1827 /* Record "skb" for eventual freeing. */
1828 comp_tail = eq->comp_tail;
1829 eq->comps[comp_tail] = skb;
1830 LEPP_QINC(comp_tail);
1831 eq->comp_tail = comp_tail;
1832
1833 /* Flush before allowing LEPP to handle the command. */
1834 __insn_mf();
1835
1836 eq->cmd_tail = cmd_tail;
1837
1838 spin_unlock_irqrestore(&priv->cmd_lock, irqflags);
1839
1840 if (nolds == 0)
1841 nolds = tile_net_lepp_grab_comps(dev, olds, wanted, NULL);
1842
1843 /* Handle completions. */
1844 for (i = 0; i < nolds; i++)
1845 kfree_skb(olds[i]);
1846
1847 /* Update stats. */
1848 stats->tx_packets += num_segs;
1849 stats->tx_bytes += (num_segs * sh_len) + d_len;
1850
1851 /* Make sure the egress timer is scheduled. */
1852 tile_net_schedule_egress_timer(info);
1853
1854 return NETDEV_TX_OK;
1855}
1856
1857
1858/*
1859 * Transmit a packet (called by the kernel via "hard_start_xmit" hook).
1860 */
1861static int tile_net_tx(struct sk_buff *skb, struct net_device *dev)
1862{
1863 struct tile_net_priv *priv = netdev_priv(dev);
1864 int my_cpu = smp_processor_id();
1865 struct tile_net_cpu *info = priv->cpu[my_cpu];
1866 struct tile_net_stats_t *stats = &info->stats;
1867
1868 unsigned long irqflags;
1869
1870 struct skb_shared_info *sh = skb_shinfo(skb);
1871
1872 unsigned int len = skb->len;
1873 unsigned char *data = skb->data;
1874
1875 unsigned int csum_start = skb->csum_start - skb_headroom(skb);
1876
1877 lepp_frag_t frags[LEPP_MAX_FRAGS];
1878
1879 unsigned int num_frags;
1880
1881 lepp_queue_t *eq = priv->epp_queue;
1882
1883 struct sk_buff *olds[4];
1884 unsigned int wanted = 4;
1885 unsigned int i, nolds = 0;
1886
1887 unsigned int cmd_size = sizeof(lepp_cmd_t);
1888
1889 unsigned int cmd_head, cmd_tail, cmd_next;
1890 unsigned int comp_tail;
1891
1892 lepp_cmd_t cmds[LEPP_MAX_FRAGS];
1893
1894 unsigned int free_slots;
1895
1896
1897 /*
1898 * This is paranoia, since we think that if the link doesn't come
1899 * up, telling Linux we have no carrier will keep it from trying
1900 * to transmit. If it does, though, we can't execute this routine,
1901 * since data structures we depend on aren't set up yet.
1902 */
1903 if (!info->registered)
1904 return NETDEV_TX_BUSY;
1905
1906
1907 /* Save the timestamp. */
1908 dev->trans_start = jiffies;
1909
1910
1911#ifdef TILE_NET_PARANOIA
1912#if CHIP_HAS_CBOX_HOME_MAP()
1913 if (hash_default) {
1914 HV_PTE pte = *virt_to_pte(current->mm, (unsigned long)data);
1915 if (hv_pte_get_mode(pte) != HV_PTE_MODE_CACHE_HASH_L3)
1916 panic("Non-coherent egress buffer!");
1917 }
1918#endif
1919#endif
1920
1921
1922#ifdef TILE_NET_DUMP_PACKETS
1923 /* ISSUE: Does not dump the "frags". */
1924 dump_packet(data, skb_headlen(skb), "tx");
1925#endif /* TILE_NET_DUMP_PACKETS */
1926
1927
1928 if (sh->gso_size != 0)
1929 return tile_net_tx_tso(skb, dev);
1930
1931
1932 /* Prepare the commands. */
1933
1934 num_frags = tile_net_tx_frags(frags, skb, data, skb_headlen(skb));
1935
1936 for (i = 0; i < num_frags; i++) {
1937
1938 bool final = (i == num_frags - 1);
1939
1940 lepp_cmd_t cmd = {
1941 .cpa_lo = frags[i].cpa_lo,
1942 .cpa_hi = frags[i].cpa_hi,
1943 .length = frags[i].length,
1944 .hash_for_home = frags[i].hash_for_home,
1945 .send_completion = final,
1946 .end_of_packet = final
1947 };
1948
1949 if (i == 0 && skb->ip_summed == CHECKSUM_PARTIAL) {
1950 cmd.compute_checksum = 1;
1951 cmd.checksum_data.bits.start_byte = csum_start;
1952 cmd.checksum_data.bits.count = len - csum_start;
1953 cmd.checksum_data.bits.destination_byte =
1954 csum_start + skb->csum_offset;
1955 }
1956
1957 cmds[i] = cmd;
1958 }
1959
1960
1961 /* Prefetch and wait, to minimize time spent holding the spinlock. */
1962 prefetch_L1(&eq->comp_tail);
1963 prefetch_L1(&eq->cmd_tail);
1964 mb();
1965
1966
1967 /* Enqueue the commands. */
1968
1969 spin_lock_irqsave(&priv->cmd_lock, irqflags);
1970
1971 /*
1972 * Handle completions if needed to make room.
1973 * HACK: Spin until there is sufficient room.
1974 */
1975 free_slots = lepp_num_free_comp_slots(eq);
1976 if (free_slots < 1) {
1977spin:
1978 nolds += tile_net_lepp_grab_comps(dev, olds + nolds,
1979 wanted - nolds, NULL);
1980 if (lepp_num_free_comp_slots(eq) < 1)
1981 goto spin;
1982 }
1983
1984 cmd_head = eq->cmd_head;
1985 cmd_tail = eq->cmd_tail;
1986
1987 /* NOTE: The "gotos" below are untested. */
1988
1989 /* Copy the commands, or fail. */
1990 for (i = 0; i < num_frags; i++) {
1991
1992 /* Prepare to advance, detecting full queue. */
1993 cmd_next = cmd_tail + cmd_size;
1994 if (cmd_tail < cmd_head && cmd_next >= cmd_head)
1995 goto spin;
1996 if (cmd_next > LEPP_CMD_LIMIT) {
1997 cmd_next = 0;
1998 if (cmd_next == cmd_head)
1999 goto spin;
2000 }
2001
2002 /* Copy the command. */
2003 *(lepp_cmd_t *)&eq->cmds[cmd_tail] = cmds[i];
2004
2005 /* Advance. */
2006 cmd_tail = cmd_next;
2007 }
2008
2009 /* Record "skb" for eventual freeing. */
2010 comp_tail = eq->comp_tail;
2011 eq->comps[comp_tail] = skb;
2012 LEPP_QINC(comp_tail);
2013 eq->comp_tail = comp_tail;
2014
2015 /* Flush before allowing LEPP to handle the command. */
2016 __insn_mf();
2017
2018 eq->cmd_tail = cmd_tail;
2019
2020 spin_unlock_irqrestore(&priv->cmd_lock, irqflags);
2021
2022 if (nolds == 0)
2023 nolds = tile_net_lepp_grab_comps(dev, olds, wanted, NULL);
2024
2025 /* Handle completions. */
2026 for (i = 0; i < nolds; i++)
2027 kfree_skb(olds[i]);
2028
2029 /* HACK: Track "expanded" size for short packets (e.g. 42 < 60). */
2030 stats->tx_packets++;
2031 stats->tx_bytes += ((len >= ETH_ZLEN) ? len : ETH_ZLEN);
2032
2033 /* Make sure the egress timer is scheduled. */
2034 tile_net_schedule_egress_timer(info);
2035
2036 return NETDEV_TX_OK;
2037}
2038
2039
2040/*
2041 * Deal with a transmit timeout.
2042 */
2043static void tile_net_tx_timeout(struct net_device *dev)
2044{
2045 PDEBUG("tile_net_tx_timeout()\n");
2046 PDEBUG("Transmit timeout at %ld, latency %ld\n", jiffies,
2047 jiffies - dev->trans_start);
2048
2049 /* XXX: ISSUE: This doesn't seem useful for us. */
2050 netif_wake_queue(dev);
2051}
2052
2053
2054/*
2055 * Ioctl commands.
2056 */
2057static int tile_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2058{
2059 return -EOPNOTSUPP;
2060}
2061
2062
2063/*
2064 * Get System Network Statistics.
2065 *
2066 * Returns the address of the device statistics structure.
2067 */
2068static struct net_device_stats *tile_net_get_stats(struct net_device *dev)
2069{
2070 struct tile_net_priv *priv = netdev_priv(dev);
2071 u32 rx_packets = 0;
2072 u32 tx_packets = 0;
2073 u32 rx_bytes = 0;
2074 u32 tx_bytes = 0;
2075 int i;
2076
2077 for_each_online_cpu(i) {
2078 if (priv->cpu[i]) {
2079 rx_packets += priv->cpu[i]->stats.rx_packets;
2080 rx_bytes += priv->cpu[i]->stats.rx_bytes;
2081 tx_packets += priv->cpu[i]->stats.tx_packets;
2082 tx_bytes += priv->cpu[i]->stats.tx_bytes;
2083 }
2084 }
2085
2086 priv->stats.rx_packets = rx_packets;
2087 priv->stats.rx_bytes = rx_bytes;
2088 priv->stats.tx_packets = tx_packets;
2089 priv->stats.tx_bytes = tx_bytes;
2090
2091 return &priv->stats;
2092}
2093
2094
2095/*
2096 * Change the "mtu".
2097 *
2098 * The "change_mtu" method is usually not needed.
2099 * If you need it, it must be like this.
2100 */
2101static int tile_net_change_mtu(struct net_device *dev, int new_mtu)
2102{
2103 PDEBUG("tile_net_change_mtu()\n");
2104
2105 /* Check ranges. */
2106 if ((new_mtu < 68) || (new_mtu > 1500))
2107 return -EINVAL;
2108
2109 /* Accept the value. */
2110 dev->mtu = new_mtu;
2111
2112 return 0;
2113}
2114
2115
2116/*
2117 * Change the Ethernet Address of the NIC.
2118 *
2119 * The hypervisor driver does not support changing MAC address. However,
2120 * the IPP does not do anything with the MAC address, so the address which
2121 * gets used on outgoing packets, and which is accepted on incoming packets,
2122 * is completely up to the NetIO program or kernel driver which is actually
2123 * handling them.
2124 *
2125 * Returns 0 on success, negative on failure.
2126 */
2127static int tile_net_set_mac_address(struct net_device *dev, void *p)
2128{
2129 struct sockaddr *addr = p;
2130
2131 if (!is_valid_ether_addr(addr->sa_data))
2132 return -EINVAL;
2133
2134 /* ISSUE: Note that "dev_addr" is now a pointer. */
2135 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
2136
2137 return 0;
2138}
2139
2140
2141/*
2142 * Obtain the MAC address from the hypervisor.
2143 * This must be done before opening the device.
2144 */
2145static int tile_net_get_mac(struct net_device *dev)
2146{
2147 struct tile_net_priv *priv = netdev_priv(dev);
2148
2149 char hv_dev_name[32];
2150 int len;
2151
2152 __netio_getset_offset_t offset = { .word = NETIO_IPP_PARAM_OFF };
2153
2154 int ret;
2155
2156 /* For example, "xgbe0". */
2157 strcpy(hv_dev_name, dev->name);
2158 len = strlen(hv_dev_name);
2159
2160 /* For example, "xgbe/0". */
2161 hv_dev_name[len] = hv_dev_name[len - 1];
2162 hv_dev_name[len - 1] = '/';
2163 len++;
2164
2165 /* For example, "xgbe/0/native_hash". */
2166 strcpy(hv_dev_name + len, hash_default ? "/native_hash" : "/native");
2167
2168 /* Get the hypervisor handle for this device. */
2169 priv->hv_devhdl = hv_dev_open((HV_VirtAddr)hv_dev_name, 0);
2170 PDEBUG("hv_dev_open(%s) returned %d %p\n",
2171 hv_dev_name, priv->hv_devhdl, &priv->hv_devhdl);
2172 if (priv->hv_devhdl < 0) {
2173 if (priv->hv_devhdl == HV_ENODEV)
2174 printk(KERN_DEBUG "Ignoring unconfigured device %s\n",
2175 hv_dev_name);
2176 else
2177 printk(KERN_DEBUG "hv_dev_open(%s) returned %d\n",
2178 hv_dev_name, priv->hv_devhdl);
2179 return -1;
2180 }
2181
2182 /*
2183 * Read the hardware address from the hypervisor.
2184 * ISSUE: Note that "dev_addr" is now a pointer.
2185 */
2186 offset.bits.class = NETIO_PARAM;
2187 offset.bits.addr = NETIO_PARAM_MAC;
2188 ret = hv_dev_pread(priv->hv_devhdl, 0,
2189 (HV_VirtAddr)dev->dev_addr, dev->addr_len,
2190 offset.word);
2191 PDEBUG("hv_dev_pread(NETIO_PARAM_MAC) returned %d\n", ret);
2192 if (ret <= 0) {
2193 printk(KERN_DEBUG "hv_dev_pread(NETIO_PARAM_MAC) %s failed\n",
2194 dev->name);
2195 /*
2196 * Since the device is configured by the hypervisor but we
2197 * can't get its MAC address, we are most likely running
2198 * the simulator, so let's generate a random MAC address.
2199 */
2200 random_ether_addr(dev->dev_addr);
2201 }
2202
2203 return 0;
2204}
2205
2206
2207static struct net_device_ops tile_net_ops = {
2208 .ndo_open = tile_net_open,
2209 .ndo_stop = tile_net_stop,
2210 .ndo_start_xmit = tile_net_tx,
2211 .ndo_do_ioctl = tile_net_ioctl,
2212 .ndo_get_stats = tile_net_get_stats,
2213 .ndo_change_mtu = tile_net_change_mtu,
2214 .ndo_tx_timeout = tile_net_tx_timeout,
2215 .ndo_set_mac_address = tile_net_set_mac_address
2216};
2217
2218
2219/*
2220 * The setup function.
2221 *
2222 * This uses ether_setup() to assign various fields in dev, including
2223 * setting IFF_BROADCAST and IFF_MULTICAST, then sets some extra fields.
2224 */
2225static void tile_net_setup(struct net_device *dev)
2226{
2227 PDEBUG("tile_net_setup()\n");
2228
2229 ether_setup(dev);
2230
2231 dev->netdev_ops = &tile_net_ops;
2232
2233 dev->watchdog_timeo = TILE_NET_TIMEOUT;
2234
2235 /* We want lockless xmit. */
2236 dev->features |= NETIF_F_LLTX;
2237
2238 /* We support hardware tx checksums. */
2239 dev->features |= NETIF_F_HW_CSUM;
2240
2241 /* We support scatter/gather. */
2242 dev->features |= NETIF_F_SG;
2243
2244 /* We support TSO. */
2245 dev->features |= NETIF_F_TSO;
2246
2247#ifdef TILE_NET_GSO
2248 /* We support GSO. */
2249 dev->features |= NETIF_F_GSO;
2250#endif
2251
2252 if (hash_default)
2253 dev->features |= NETIF_F_HIGHDMA;
2254
2255 /* ISSUE: We should support NETIF_F_UFO. */
2256
2257 dev->tx_queue_len = TILE_NET_TX_QUEUE_LEN;
2258
2259 dev->mtu = TILE_NET_MTU;
2260}
2261
2262
2263/*
2264 * Allocate the device structure, register the device, and obtain the
2265 * MAC address from the hypervisor.
2266 */
2267static struct net_device *tile_net_dev_init(const char *name)
2268{
2269 int ret;
2270 struct net_device *dev;
2271 struct tile_net_priv *priv;
2272 struct page *page;
2273
2274 /*
2275 * Allocate the device structure. This allocates "priv", calls
2276 * tile_net_setup(), and saves "name". Normally, "name" is a
2277 * template, instantiated by register_netdev(), but not for us.
2278 */
2279 dev = alloc_netdev(sizeof(*priv), name, tile_net_setup);
2280 if (!dev) {
2281 pr_err("alloc_netdev(%s) failed\n", name);
2282 return NULL;
2283 }
2284
2285 priv = netdev_priv(dev);
2286
2287 /* Initialize "priv". */
2288
2289 memset(priv, 0, sizeof(*priv));
2290
2291 /* Save "dev" for "tile_net_open_retry()". */
2292 priv->dev = dev;
2293
2294 INIT_DELAYED_WORK(&priv->retry_work, tile_net_open_retry);
2295
2296 spin_lock_init(&priv->cmd_lock);
2297 spin_lock_init(&priv->comp_lock);
2298
2299 /* Allocate "epp_queue". */
2300 BUG_ON(get_order(sizeof(lepp_queue_t)) != 0);
2301 page = alloc_pages(GFP_KERNEL | __GFP_ZERO, 0);
2302 if (!page) {
2303 free_netdev(dev);
2304 return NULL;
2305 }
2306 priv->epp_queue = page_address(page);
2307
2308 /* Register the network device. */
2309 ret = register_netdev(dev);
2310 if (ret) {
2311 pr_err("register_netdev %s failed %d\n", dev->name, ret);
2312 free_page((unsigned long)priv->epp_queue);
2313 free_netdev(dev);
2314 return NULL;
2315 }
2316
2317 /* Get the MAC address. */
2318 ret = tile_net_get_mac(dev);
2319 if (ret < 0) {
2320 unregister_netdev(dev);
2321 free_page((unsigned long)priv->epp_queue);
2322 free_netdev(dev);
2323 return NULL;
2324 }
2325
2326 return dev;
2327}
2328
2329
2330/*
2331 * Module cleanup.
2332 */
2333static void tile_net_cleanup(void)
2334{
2335 int i;
2336
2337 for (i = 0; i < TILE_NET_DEVS; i++) {
2338 if (tile_net_devs[i]) {
2339 struct net_device *dev = tile_net_devs[i];
2340 struct tile_net_priv *priv = netdev_priv(dev);
2341 unregister_netdev(dev);
2342 finv_buffer(priv->epp_queue, PAGE_SIZE);
2343 free_page((unsigned long)priv->epp_queue);
2344 free_netdev(dev);
2345 }
2346 }
2347}
2348
2349
2350/*
2351 * Module initialization.
2352 */
2353static int tile_net_init_module(void)
2354{
2355 pr_info("Tilera IPP Net Driver\n");
2356
2357 tile_net_devs[0] = tile_net_dev_init("xgbe0");
2358 tile_net_devs[1] = tile_net_dev_init("xgbe1");
2359 tile_net_devs[2] = tile_net_dev_init("gbe0");
2360 tile_net_devs[3] = tile_net_dev_init("gbe1");
2361
2362 return 0;
2363}
2364
2365
2366#ifndef MODULE
2367/*
2368 * The "network_cpus" boot argument specifies the cpus that are dedicated
2369 * to handle ingress packets.
2370 *
2371 * The parameter should be in the form "network_cpus=m-n[,x-y]", where
2372 * m, n, x, y are integer numbers that represent the cpus that can be
2373 * neither a dedicated cpu nor a dataplane cpu.
2374 */
2375static int __init network_cpus_setup(char *str)
2376{
2377 int rc = cpulist_parse_crop(str, &network_cpus_map);
2378 if (rc != 0) {
2379 pr_warning("network_cpus=%s: malformed cpu list\n",
2380 str);
2381 } else {
2382
2383 /* Remove dedicated cpus. */
2384 cpumask_and(&network_cpus_map, &network_cpus_map,
2385 cpu_possible_mask);
2386
2387
2388 if (cpumask_empty(&network_cpus_map)) {
2389 pr_warning("Ignoring network_cpus='%s'.\n",
2390 str);
2391 } else {
2392 char buf[1024];
2393 cpulist_scnprintf(buf, sizeof(buf), &network_cpus_map);
2394 pr_info("Linux network CPUs: %s\n", buf);
2395 network_cpus_used = true;
2396 }
2397 }
2398
2399 return 0;
2400}
2401__setup("network_cpus=", network_cpus_setup);
2402#endif
2403
2404
2405module_init(tile_net_init_module);
2406module_exit(tile_net_cleanup);
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
index 28e1ffb13db9..c78a50586c1d 100644
--- a/drivers/net/tulip/de2104x.c
+++ b/drivers/net/tulip/de2104x.c
@@ -2021,7 +2021,6 @@ static int __devinit de_init_one (struct pci_dev *pdev,
2021 de->media_timer.data = (unsigned long) de; 2021 de->media_timer.data = (unsigned long) de;
2022 2022
2023 netif_carrier_off(dev); 2023 netif_carrier_off(dev);
2024 netif_stop_queue(dev);
2025 2024
2026 /* wake up device, assign resources */ 2025 /* wake up device, assign resources */
2027 rc = pci_enable_device(pdev); 2026 rc = pci_enable_device(pdev);
diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c
index a9f7d5d1a269..7064e035757a 100644
--- a/drivers/net/tulip/dmfe.c
+++ b/drivers/net/tulip/dmfe.c
@@ -688,9 +688,6 @@ static netdev_tx_t dmfe_start_xmit(struct sk_buff *skb,
688 688
689 DMFE_DBUG(0, "dmfe_start_xmit", 0); 689 DMFE_DBUG(0, "dmfe_start_xmit", 0);
690 690
691 /* Resource flag check */
692 netif_stop_queue(dev);
693
694 /* Too large packet check */ 691 /* Too large packet check */
695 if (skb->len > MAX_PACKET_SIZE) { 692 if (skb->len > MAX_PACKET_SIZE) {
696 pr_err("big packet = %d\n", (u16)skb->len); 693 pr_err("big packet = %d\n", (u16)skb->len);
@@ -698,6 +695,9 @@ static netdev_tx_t dmfe_start_xmit(struct sk_buff *skb,
698 return NETDEV_TX_OK; 695 return NETDEV_TX_OK;
699 } 696 }
700 697
698 /* Resource flag check */
699 netif_stop_queue(dev);
700
701 spin_lock_irqsave(&db->lock, flags); 701 spin_lock_irqsave(&db->lock, flags);
702 702
703 /* No Tx resource check, it never happen nromally */ 703 /* No Tx resource check, it never happen nromally */
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index a4c3f5708246..acbdab3d66ca 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -2050,12 +2050,16 @@ static void ucc_geth_stop(struct ucc_geth_private *ugeth)
2050 2050
2051 ugeth_vdbg("%s: IN", __func__); 2051 ugeth_vdbg("%s: IN", __func__);
2052 2052
2053 /*
2054 * Tell the kernel the link is down.
2055 * Must be done before disabling the controller
2056 * or deadlock may happen.
2057 */
2058 phy_stop(phydev);
2059
2053 /* Disable the controller */ 2060 /* Disable the controller */
2054 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX); 2061 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
2055 2062
2056 /* Tell the kernel the link is down */
2057 phy_stop(phydev);
2058
2059 /* Mask all interrupts */ 2063 /* Mask all interrupts */
2060 out_be32(ugeth->uccf->p_uccm, 0x00000000); 2064 out_be32(ugeth->uccf->p_uccm, 0x00000000);
2061 2065
@@ -2065,9 +2069,6 @@ static void ucc_geth_stop(struct ucc_geth_private *ugeth)
2065 /* Disable Rx and Tx */ 2069 /* Disable Rx and Tx */
2066 clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX); 2070 clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
2067 2071
2068 phy_disconnect(ugeth->phydev);
2069 ugeth->phydev = NULL;
2070
2071 ucc_geth_memclean(ugeth); 2072 ucc_geth_memclean(ugeth);
2072} 2073}
2073 2074
@@ -3550,7 +3551,10 @@ static int ucc_geth_close(struct net_device *dev)
3550 3551
3551 napi_disable(&ugeth->napi); 3552 napi_disable(&ugeth->napi);
3552 3553
3554 cancel_work_sync(&ugeth->timeout_work);
3553 ucc_geth_stop(ugeth); 3555 ucc_geth_stop(ugeth);
3556 phy_disconnect(ugeth->phydev);
3557 ugeth->phydev = NULL;
3554 3558
3555 free_irq(ugeth->ug_info->uf_info.irq, ugeth->ndev); 3559 free_irq(ugeth->ug_info->uf_info.irq, ugeth->ndev);
3556 3560
@@ -3579,8 +3583,12 @@ static void ucc_geth_timeout_work(struct work_struct *work)
3579 * Must reset MAC *and* PHY. This is done by reopening 3583 * Must reset MAC *and* PHY. This is done by reopening
3580 * the device. 3584 * the device.
3581 */ 3585 */
3582 ucc_geth_close(dev); 3586 netif_tx_stop_all_queues(dev);
3583 ucc_geth_open(dev); 3587 ucc_geth_stop(ugeth);
3588 ucc_geth_init_mac(ugeth);
3589 /* Must start PHY here */
3590 phy_start(ugeth->phydev);
3591 netif_tx_start_all_queues(dev);
3584 } 3592 }
3585 3593
3586 netif_tx_schedule_all(dev); 3594 netif_tx_schedule_all(dev);
@@ -3594,7 +3602,6 @@ static void ucc_geth_timeout(struct net_device *dev)
3594{ 3602{
3595 struct ucc_geth_private *ugeth = netdev_priv(dev); 3603 struct ucc_geth_private *ugeth = netdev_priv(dev);
3596 3604
3597 netif_carrier_off(dev);
3598 schedule_work(&ugeth->timeout_work); 3605 schedule_work(&ugeth->timeout_work);
3599} 3606}
3600 3607
diff --git a/drivers/net/ucc_geth.h b/drivers/net/ucc_geth.h
index 05a95586f3c5..055b87ab4f07 100644
--- a/drivers/net/ucc_geth.h
+++ b/drivers/net/ucc_geth.h
@@ -899,7 +899,8 @@ struct ucc_geth_hardware_statistics {
899#define UCC_GETH_UTFS_INIT 512 /* Tx virtual FIFO size 899#define UCC_GETH_UTFS_INIT 512 /* Tx virtual FIFO size
900 */ 900 */
901#define UCC_GETH_UTFET_INIT 256 /* 1/2 utfs */ 901#define UCC_GETH_UTFET_INIT 256 /* 1/2 utfs */
902#define UCC_GETH_UTFTT_INIT 512 902#define UCC_GETH_UTFTT_INIT 256 /* 1/2 utfs
903 due to errata */
903/* Gigabit Ethernet (1000 Mbps) */ 904/* Gigabit Ethernet (1000 Mbps) */
904#define UCC_GETH_URFS_GIGA_INIT 4096/*2048*/ /* Rx virtual 905#define UCC_GETH_URFS_GIGA_INIT 4096/*2048*/ /* Rx virtual
905 FIFO size */ 906 FIFO size */
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index b154a94de03e..812edf85d6d3 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -958,10 +958,6 @@ static void packetizeRx(struct hso_net *odev, unsigned char *ip_pkt,
958 /* Packet is complete. Inject into stack. */ 958 /* Packet is complete. Inject into stack. */
959 /* We have IP packet here */ 959 /* We have IP packet here */
960 odev->skb_rx_buf->protocol = cpu_to_be16(ETH_P_IP); 960 odev->skb_rx_buf->protocol = cpu_to_be16(ETH_P_IP);
961 /* don't check it */
962 odev->skb_rx_buf->ip_summed =
963 CHECKSUM_UNNECESSARY;
964
965 skb_reset_mac_header(odev->skb_rx_buf); 961 skb_reset_mac_header(odev->skb_rx_buf);
966 962
967 /* Ship it off to the kernel */ 963 /* Ship it off to the kernel */
@@ -2994,12 +2990,14 @@ static int hso_probe(struct usb_interface *interface,
2994 2990
2995 case HSO_INTF_BULK: 2991 case HSO_INTF_BULK:
2996 /* It's a regular bulk interface */ 2992 /* It's a regular bulk interface */
2997 if (((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) && 2993 if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
2998 !disable_net) 2994 if (!disable_net)
2999 hso_dev = hso_create_net_device(interface, port_spec); 2995 hso_dev =
3000 else 2996 hso_create_net_device(interface, port_spec);
2997 } else {
3001 hso_dev = 2998 hso_dev =
3002 hso_create_bulk_serial_device(interface, port_spec); 2999 hso_create_bulk_serial_device(interface, port_spec);
3000 }
3003 if (!hso_dev) 3001 if (!hso_dev)
3004 goto exit; 3002 goto exit;
3005 break; 3003 break;
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index ca7fc9df1ccf..c04d49e31f81 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -45,6 +45,7 @@
45#include <linux/usb/usbnet.h> 45#include <linux/usb/usbnet.h>
46#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/kernel.h> 47#include <linux/kernel.h>
48#include <linux/pm_runtime.h>
48 49
49#define DRIVER_VERSION "22-Aug-2005" 50#define DRIVER_VERSION "22-Aug-2005"
50 51
@@ -1273,6 +1274,16 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1273 struct usb_device *xdev; 1274 struct usb_device *xdev;
1274 int status; 1275 int status;
1275 const char *name; 1276 const char *name;
1277 struct usb_driver *driver = to_usb_driver(udev->dev.driver);
1278
1279 /* usbnet already took usb runtime pm, so have to enable the feature
1280 * for usb interface, otherwise usb_autopm_get_interface may return
1281 * failure if USB_SUSPEND(RUNTIME_PM) is enabled.
1282 */
1283 if (!driver->supports_autosuspend) {
1284 driver->supports_autosuspend = 1;
1285 pm_runtime_enable(&udev->dev);
1286 }
1276 1287
1277 name = udev->dev.driver->name; 1288 name = udev->dev.driver->name;
1278 info = (struct driver_info *) prod->driver_info; 1289 info = (struct driver_info *) prod->driver_info;
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index bb6b67f6b0cc..b6d402806ae6 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -986,9 +986,15 @@ static int virtnet_probe(struct virtio_device *vdev)
986 goto unregister; 986 goto unregister;
987 } 987 }
988 988
989 vi->status = VIRTIO_NET_S_LINK_UP; 989 /* Assume link up if device can't report link status,
990 virtnet_update_status(vi); 990 otherwise get link status from config. */
991 netif_carrier_on(dev); 991 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) {
992 netif_carrier_off(dev);
993 virtnet_update_status(vi);
994 } else {
995 vi->status = VIRTIO_NET_S_LINK_UP;
996 netif_carrier_on(dev);
997 }
992 998
993 pr_debug("virtnet: registered device %s\n", dev->name); 999 pr_debug("virtnet: registered device %s\n", dev->name);
994 return 0; 1000 return 0;
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index e3658e10db39..21314e06e6d7 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -873,7 +873,7 @@ vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
873 count = VMXNET3_TXD_NEEDED(skb_headlen(skb)) + 873 count = VMXNET3_TXD_NEEDED(skb_headlen(skb)) +
874 skb_shinfo(skb)->nr_frags + 1; 874 skb_shinfo(skb)->nr_frags + 1;
875 875
876 ctx.ipv4 = (skb->protocol == __constant_ntohs(ETH_P_IP)); 876 ctx.ipv4 = (skb->protocol == cpu_to_be16(ETH_P_IP));
877 877
878 ctx.mss = skb_shinfo(skb)->gso_size; 878 ctx.mss = skb_shinfo(skb)->gso_size;
879 if (ctx.mss) { 879 if (ctx.mss) {
diff --git a/drivers/net/vmxnet3/vmxnet3_int.h b/drivers/net/vmxnet3/vmxnet3_int.h
index 8a2f4712284c..edf228843afc 100644
--- a/drivers/net/vmxnet3/vmxnet3_int.h
+++ b/drivers/net/vmxnet3/vmxnet3_int.h
@@ -330,14 +330,14 @@ struct vmxnet3_adapter {
330}; 330};
331 331
332#define VMXNET3_WRITE_BAR0_REG(adapter, reg, val) \ 332#define VMXNET3_WRITE_BAR0_REG(adapter, reg, val) \
333 writel(cpu_to_le32(val), (adapter)->hw_addr0 + (reg)) 333 writel((val), (adapter)->hw_addr0 + (reg))
334#define VMXNET3_READ_BAR0_REG(adapter, reg) \ 334#define VMXNET3_READ_BAR0_REG(adapter, reg) \
335 le32_to_cpu(readl((adapter)->hw_addr0 + (reg))) 335 readl((adapter)->hw_addr0 + (reg))
336 336
337#define VMXNET3_WRITE_BAR1_REG(adapter, reg, val) \ 337#define VMXNET3_WRITE_BAR1_REG(adapter, reg, val) \
338 writel(cpu_to_le32(val), (adapter)->hw_addr1 + (reg)) 338 writel((val), (adapter)->hw_addr1 + (reg))
339#define VMXNET3_READ_BAR1_REG(adapter, reg) \ 339#define VMXNET3_READ_BAR1_REG(adapter, reg) \
340 le32_to_cpu(readl((adapter)->hw_addr1 + (reg))) 340 readl((adapter)->hw_addr1 + (reg))
341 341
342#define VMXNET3_WAKE_QUEUE_THRESHOLD(tq) (5) 342#define VMXNET3_WAKE_QUEUE_THRESHOLD(tq) (5)
343#define VMXNET3_RX_ALLOC_THRESHOLD(rq, ring_idx, adapter) \ 343#define VMXNET3_RX_ALLOC_THRESHOLD(rq, ring_idx, adapter) \
diff --git a/drivers/net/wan/hd64572.c b/drivers/net/wan/hd64572.c
index ea476cbd38b5..e305274f83fb 100644
--- a/drivers/net/wan/hd64572.c
+++ b/drivers/net/wan/hd64572.c
@@ -293,6 +293,7 @@ static inline void sca_tx_done(port_t *port)
293 struct net_device *dev = port->netdev; 293 struct net_device *dev = port->netdev;
294 card_t* card = port->card; 294 card_t* card = port->card;
295 u8 stat; 295 u8 stat;
296 unsigned count = 0;
296 297
297 spin_lock(&port->lock); 298 spin_lock(&port->lock);
298 299
@@ -316,10 +317,12 @@ static inline void sca_tx_done(port_t *port)
316 dev->stats.tx_bytes += readw(&desc->len); 317 dev->stats.tx_bytes += readw(&desc->len);
317 } 318 }
318 writeb(0, &desc->stat); /* Free descriptor */ 319 writeb(0, &desc->stat); /* Free descriptor */
320 count++;
319 port->txlast = (port->txlast + 1) % card->tx_ring_buffers; 321 port->txlast = (port->txlast + 1) % card->tx_ring_buffers;
320 } 322 }
321 323
322 netif_wake_queue(dev); 324 if (count)
325 netif_wake_queue(dev);
323 spin_unlock(&port->lock); 326 spin_unlock(&port->lock);
324} 327}
325 328
diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
index d81ad8397885..24297b274cd4 100644
--- a/drivers/net/wan/x25_asy.c
+++ b/drivers/net/wan/x25_asy.c
@@ -498,7 +498,6 @@ norbuff:
498static int x25_asy_close(struct net_device *dev) 498static int x25_asy_close(struct net_device *dev)
499{ 499{
500 struct x25_asy *sl = netdev_priv(dev); 500 struct x25_asy *sl = netdev_priv(dev);
501 int err;
502 501
503 spin_lock(&sl->lock); 502 spin_lock(&sl->lock);
504 if (sl->tty) 503 if (sl->tty)
@@ -507,10 +506,6 @@ static int x25_asy_close(struct net_device *dev)
507 netif_stop_queue(dev); 506 netif_stop_queue(dev);
508 sl->rcount = 0; 507 sl->rcount = 0;
509 sl->xleft = 0; 508 sl->xleft = 0;
510 err = lapb_unregister(dev);
511 if (err != LAPB_OK)
512 printk(KERN_ERR "x25_asy_close: lapb_unregister error -%d\n",
513 err);
514 spin_unlock(&sl->lock); 509 spin_unlock(&sl->lock);
515 return 0; 510 return 0;
516} 511}
@@ -582,7 +577,7 @@ static int x25_asy_open_tty(struct tty_struct *tty)
582 if (err) 577 if (err)
583 return err; 578 return err;
584 /* Done. We have linked the TTY line to a channel. */ 579 /* Done. We have linked the TTY line to a channel. */
585 return sl->dev->base_addr; 580 return 0;
586} 581}
587 582
588 583
@@ -595,6 +590,7 @@ static int x25_asy_open_tty(struct tty_struct *tty)
595static void x25_asy_close_tty(struct tty_struct *tty) 590static void x25_asy_close_tty(struct tty_struct *tty)
596{ 591{
597 struct x25_asy *sl = tty->disc_data; 592 struct x25_asy *sl = tty->disc_data;
593 int err;
598 594
599 /* First make sure we're connected. */ 595 /* First make sure we're connected. */
600 if (!sl || sl->magic != X25_ASY_MAGIC) 596 if (!sl || sl->magic != X25_ASY_MAGIC)
@@ -605,6 +601,11 @@ static void x25_asy_close_tty(struct tty_struct *tty)
605 dev_close(sl->dev); 601 dev_close(sl->dev);
606 rtnl_unlock(); 602 rtnl_unlock();
607 603
604 err = lapb_unregister(sl->dev);
605 if (err != LAPB_OK)
606 printk(KERN_ERR "x25_asy_close: lapb_unregister error -%d\n",
607 err);
608
608 tty->disc_data = NULL; 609 tty->disc_data = NULL;
609 sl->tty = NULL; 610 sl->tty = NULL;
610 x25_asy_free(sl); 611 x25_asy_free(sl);
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index 8251946842e6..42ed923cdb1a 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -1917,7 +1917,8 @@ ath5k_beacon_send(struct ath5k_softc *sc)
1917 sc->bmisscount = 0; 1917 sc->bmisscount = 0;
1918 } 1918 }
1919 1919
1920 if (sc->opmode == NL80211_IFTYPE_AP && sc->num_ap_vifs > 1) { 1920 if ((sc->opmode == NL80211_IFTYPE_AP && sc->num_ap_vifs > 1) ||
1921 sc->opmode == NL80211_IFTYPE_MESH_POINT) {
1921 u64 tsf = ath5k_hw_get_tsf64(ah); 1922 u64 tsf = ath5k_hw_get_tsf64(ah);
1922 u32 tsftu = TSF_TO_TU(tsf); 1923 u32 tsftu = TSF_TO_TU(tsf);
1923 int slot = ((tsftu % sc->bintval) * ATH_BCBUF) / sc->bintval; 1924 int slot = ((tsftu % sc->bintval) * ATH_BCBUF) / sc->bintval;
@@ -1949,8 +1950,9 @@ ath5k_beacon_send(struct ath5k_softc *sc)
1949 /* NB: hw still stops DMA, so proceed */ 1950 /* NB: hw still stops DMA, so proceed */
1950 } 1951 }
1951 1952
1952 /* refresh the beacon for AP mode */ 1953 /* refresh the beacon for AP or MESH mode */
1953 if (sc->opmode == NL80211_IFTYPE_AP) 1954 if (sc->opmode == NL80211_IFTYPE_AP ||
1955 sc->opmode == NL80211_IFTYPE_MESH_POINT)
1954 ath5k_beacon_update(sc->hw, vif); 1956 ath5k_beacon_update(sc->hw, vif);
1955 1957
1956 ath5k_hw_set_txdp(ah, sc->bhalq, bf->daddr); 1958 ath5k_hw_set_txdp(ah, sc->bhalq, bf->daddr);
@@ -2851,7 +2853,8 @@ static int ath5k_add_interface(struct ieee80211_hw *hw,
2851 2853
2852 /* Assign the vap/adhoc to a beacon xmit slot. */ 2854 /* Assign the vap/adhoc to a beacon xmit slot. */
2853 if ((avf->opmode == NL80211_IFTYPE_AP) || 2855 if ((avf->opmode == NL80211_IFTYPE_AP) ||
2854 (avf->opmode == NL80211_IFTYPE_ADHOC)) { 2856 (avf->opmode == NL80211_IFTYPE_ADHOC) ||
2857 (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
2855 int slot; 2858 int slot;
2856 2859
2857 WARN_ON(list_empty(&sc->bcbuf)); 2860 WARN_ON(list_empty(&sc->bcbuf));
@@ -2870,7 +2873,7 @@ static int ath5k_add_interface(struct ieee80211_hw *hw,
2870 sc->bslot[avf->bslot] = vif; 2873 sc->bslot[avf->bslot] = vif;
2871 if (avf->opmode == NL80211_IFTYPE_AP) 2874 if (avf->opmode == NL80211_IFTYPE_AP)
2872 sc->num_ap_vifs++; 2875 sc->num_ap_vifs++;
2873 else 2876 else if (avf->opmode == NL80211_IFTYPE_ADHOC)
2874 sc->num_adhoc_vifs++; 2877 sc->num_adhoc_vifs++;
2875 } 2878 }
2876 2879
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_hw.c b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
index a0471f2e1c7a..48261b7252d0 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_hw.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
@@ -410,6 +410,9 @@ static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
410 val &= ~(AR_WA_BIT6 | AR_WA_BIT7); 410 val &= ~(AR_WA_BIT6 | AR_WA_BIT7);
411 } 411 }
412 412
413 if (AR_SREV_9280(ah))
414 val |= AR_WA_BIT22;
415
413 if (AR_SREV_9285E_20(ah)) 416 if (AR_SREV_9285E_20(ah))
414 val |= AR_WA_BIT23; 417 val |= AR_WA_BIT23;
415 418
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index c4182359bee4..a7b82f0085d2 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -55,6 +55,8 @@
55#define SUB_NUM_CTL_MODES_AT_5G_40 2 /* excluding HT40, EXT-OFDM */ 55#define SUB_NUM_CTL_MODES_AT_5G_40 2 /* excluding HT40, EXT-OFDM */
56#define SUB_NUM_CTL_MODES_AT_2G_40 3 /* excluding HT40, EXT-OFDM, EXT-CCK */ 56#define SUB_NUM_CTL_MODES_AT_2G_40 3 /* excluding HT40, EXT-OFDM, EXT-CCK */
57 57
58#define CTL(_tpower, _flag) ((_tpower) | ((_flag) << 6))
59
58static const struct ar9300_eeprom ar9300_default = { 60static const struct ar9300_eeprom ar9300_default = {
59 .eepromVersion = 2, 61 .eepromVersion = 2,
60 .templateVersion = 2, 62 .templateVersion = 2,
@@ -290,20 +292,21 @@ static const struct ar9300_eeprom ar9300_default = {
290 } 292 }
291 }, 293 },
292 .ctlPowerData_2G = { 294 .ctlPowerData_2G = {
293 { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } }, 295 { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
294 { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } }, 296 { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
295 { { {60, 1}, {60, 0}, {60, 0}, {60, 1} } }, 297 { { CTL(60, 1), CTL(60, 0), CTL(60, 0), CTL(60, 1) } },
296 298
297 { { {60, 1}, {60, 0}, {0, 0}, {0, 0} } }, 299 { { CTL(60, 1), CTL(60, 0), CTL(0, 0), CTL(0, 0) } },
298 { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } }, 300 { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
299 { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } }, 301 { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
300 302
301 { { {60, 0}, {60, 1}, {60, 1}, {60, 0} } }, 303 { { CTL(60, 0), CTL(60, 1), CTL(60, 1), CTL(60, 0) } },
302 { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } }, 304 { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
303 { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } }, 305 { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
304 306
305 { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } }, 307 { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
306 { { {60, 0}, {60, 1}, {60, 1}, {60, 1} } }, 308 { { CTL(60, 0), CTL(60, 1), CTL(60, 1), CTL(60, 1) } },
309 { { CTL(60, 0), CTL(60, 1), CTL(60, 1), CTL(60, 1) } },
307 }, 310 },
308 .modalHeader5G = { 311 .modalHeader5G = {
309 /* 4 idle,t1,t2,b (4 bits per setting) */ 312 /* 4 idle,t1,t2,b (4 bits per setting) */
@@ -568,56 +571,56 @@ static const struct ar9300_eeprom ar9300_default = {
568 .ctlPowerData_5G = { 571 .ctlPowerData_5G = {
569 { 572 {
570 { 573 {
571 {60, 1}, {60, 1}, {60, 1}, {60, 1}, 574 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
572 {60, 1}, {60, 1}, {60, 1}, {60, 0}, 575 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 0),
573 } 576 }
574 }, 577 },
575 { 578 {
576 { 579 {
577 {60, 1}, {60, 1}, {60, 1}, {60, 1}, 580 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
578 {60, 1}, {60, 1}, {60, 1}, {60, 0}, 581 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 0),
579 } 582 }
580 }, 583 },
581 { 584 {
582 { 585 {
583 {60, 0}, {60, 1}, {60, 0}, {60, 1}, 586 CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 1),
584 {60, 1}, {60, 1}, {60, 1}, {60, 1}, 587 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
585 } 588 }
586 }, 589 },
587 { 590 {
588 { 591 {
589 {60, 0}, {60, 1}, {60, 1}, {60, 0}, 592 CTL(60, 0), CTL(60, 1), CTL(60, 1), CTL(60, 0),
590 {60, 1}, {60, 0}, {60, 0}, {60, 0}, 593 CTL(60, 1), CTL(60, 0), CTL(60, 0), CTL(60, 0),
591 } 594 }
592 }, 595 },
593 { 596 {
594 { 597 {
595 {60, 1}, {60, 1}, {60, 1}, {60, 0}, 598 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 0),
596 {60, 0}, {60, 0}, {60, 0}, {60, 0}, 599 CTL(60, 0), CTL(60, 0), CTL(60, 0), CTL(60, 0),
597 } 600 }
598 }, 601 },
599 { 602 {
600 { 603 {
601 {60, 1}, {60, 1}, {60, 1}, {60, 1}, 604 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
602 {60, 1}, {60, 0}, {60, 0}, {60, 0}, 605 CTL(60, 1), CTL(60, 0), CTL(60, 0), CTL(60, 0),
603 } 606 }
604 }, 607 },
605 { 608 {
606 { 609 {
607 {60, 1}, {60, 1}, {60, 1}, {60, 1}, 610 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
608 {60, 1}, {60, 1}, {60, 1}, {60, 1}, 611 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
609 } 612 }
610 }, 613 },
611 { 614 {
612 { 615 {
613 {60, 1}, {60, 1}, {60, 0}, {60, 1}, 616 CTL(60, 1), CTL(60, 1), CTL(60, 0), CTL(60, 1),
614 {60, 1}, {60, 1}, {60, 1}, {60, 0}, 617 CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 0),
615 } 618 }
616 }, 619 },
617 { 620 {
618 { 621 {
619 {60, 1}, {60, 0}, {60, 1}, {60, 1}, 622 CTL(60, 1), CTL(60, 0), CTL(60, 1), CTL(60, 1),
620 {60, 1}, {60, 1}, {60, 0}, {60, 1}, 623 CTL(60, 1), CTL(60, 1), CTL(60, 0), CTL(60, 1),
621 } 624 }
622 }, 625 },
623 } 626 }
@@ -1827,9 +1830,9 @@ static u16 ar9003_hw_get_direct_edge_power(struct ar9300_eeprom *eep,
1827 struct cal_ctl_data_5g *ctl_5g = eep->ctlPowerData_5G; 1830 struct cal_ctl_data_5g *ctl_5g = eep->ctlPowerData_5G;
1828 1831
1829 if (is2GHz) 1832 if (is2GHz)
1830 return ctl_2g[idx].ctlEdges[edge].tPower; 1833 return CTL_EDGE_TPOWER(ctl_2g[idx].ctlEdges[edge]);
1831 else 1834 else
1832 return ctl_5g[idx].ctlEdges[edge].tPower; 1835 return CTL_EDGE_TPOWER(ctl_5g[idx].ctlEdges[edge]);
1833} 1836}
1834 1837
1835static u16 ar9003_hw_get_indirect_edge_power(struct ar9300_eeprom *eep, 1838static u16 ar9003_hw_get_indirect_edge_power(struct ar9300_eeprom *eep,
@@ -1847,12 +1850,12 @@ static u16 ar9003_hw_get_indirect_edge_power(struct ar9300_eeprom *eep,
1847 1850
1848 if (is2GHz) { 1851 if (is2GHz) {
1849 if (ath9k_hw_fbin2freq(ctl_freqbin[edge - 1], 1) < freq && 1852 if (ath9k_hw_fbin2freq(ctl_freqbin[edge - 1], 1) < freq &&
1850 ctl_2g[idx].ctlEdges[edge - 1].flag) 1853 CTL_EDGE_FLAGS(ctl_2g[idx].ctlEdges[edge - 1]))
1851 return ctl_2g[idx].ctlEdges[edge - 1].tPower; 1854 return CTL_EDGE_TPOWER(ctl_2g[idx].ctlEdges[edge - 1]);
1852 } else { 1855 } else {
1853 if (ath9k_hw_fbin2freq(ctl_freqbin[edge - 1], 0) < freq && 1856 if (ath9k_hw_fbin2freq(ctl_freqbin[edge - 1], 0) < freq &&
1854 ctl_5g[idx].ctlEdges[edge - 1].flag) 1857 CTL_EDGE_FLAGS(ctl_5g[idx].ctlEdges[edge - 1]))
1855 return ctl_5g[idx].ctlEdges[edge - 1].tPower; 1858 return CTL_EDGE_TPOWER(ctl_5g[idx].ctlEdges[edge - 1]);
1856 } 1859 }
1857 1860
1858 return AR9300_MAX_RATE_POWER; 1861 return AR9300_MAX_RATE_POWER;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
index 3c533bb983c7..655b3033396c 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
@@ -261,17 +261,12 @@ struct cal_tgt_pow_ht {
261 u8 tPow2x[14]; 261 u8 tPow2x[14];
262} __packed; 262} __packed;
263 263
264struct cal_ctl_edge_pwr {
265 u8 tPower:6,
266 flag:2;
267} __packed;
268
269struct cal_ctl_data_2g { 264struct cal_ctl_data_2g {
270 struct cal_ctl_edge_pwr ctlEdges[AR9300_NUM_BAND_EDGES_2G]; 265 u8 ctlEdges[AR9300_NUM_BAND_EDGES_2G];
271} __packed; 266} __packed;
272 267
273struct cal_ctl_data_5g { 268struct cal_ctl_data_5g {
274 struct cal_ctl_edge_pwr ctlEdges[AR9300_NUM_BAND_EDGES_5G]; 269 u8 ctlEdges[AR9300_NUM_BAND_EDGES_5G];
275} __packed; 270} __packed;
276 271
277struct ar9300_eeprom { 272struct ar9300_eeprom {
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index 9b8e7e3fcebd..0963071e8f90 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -21,6 +21,7 @@
21#include <linux/device.h> 21#include <linux/device.h>
22#include <linux/leds.h> 22#include <linux/leds.h>
23#include <linux/completion.h> 23#include <linux/completion.h>
24#include <linux/pm_qos_params.h>
24 25
25#include "debug.h" 26#include "debug.h"
26#include "common.h" 27#include "common.h"
@@ -328,7 +329,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp);
328struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype); 329struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype);
329void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq); 330void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq);
330int ath_tx_setup(struct ath_softc *sc, int haltype); 331int ath_tx_setup(struct ath_softc *sc, int haltype);
331void ath_drain_all_txq(struct ath_softc *sc, bool retry_tx); 332bool ath_drain_all_txq(struct ath_softc *sc, bool retry_tx);
332void ath_draintxq(struct ath_softc *sc, 333void ath_draintxq(struct ath_softc *sc,
333 struct ath_txq *txq, bool retry_tx); 334 struct ath_txq *txq, bool retry_tx);
334void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an); 335void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an);
@@ -646,6 +647,8 @@ struct ath_softc {
646 struct ath_descdma txsdma; 647 struct ath_descdma txsdma;
647 648
648 struct ath_ant_comb ant_comb; 649 struct ath_ant_comb ant_comb;
650
651 struct pm_qos_request_list pm_qos_req;
649}; 652};
650 653
651struct ath_wiphy { 654struct ath_wiphy {
diff --git a/drivers/net/wireless/ath/ath9k/eeprom.c b/drivers/net/wireless/ath/ath9k/eeprom.c
index 1266333f586d..2bbf94d0191e 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom.c
@@ -240,16 +240,16 @@ u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower,
240 for (i = 0; (i < num_band_edges) && 240 for (i = 0; (i < num_band_edges) &&
241 (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) { 241 (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
242 if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) { 242 if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
243 twiceMaxEdgePower = pRdEdgesPower[i].tPower; 243 twiceMaxEdgePower = CTL_EDGE_TPOWER(pRdEdgesPower[i].ctl);
244 break; 244 break;
245 } else if ((i > 0) && 245 } else if ((i > 0) &&
246 (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, 246 (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
247 is2GHz))) { 247 is2GHz))) {
248 if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel, 248 if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
249 is2GHz) < freq && 249 is2GHz) < freq &&
250 pRdEdgesPower[i - 1].flag) { 250 CTL_EDGE_FLAGS(pRdEdgesPower[i - 1].ctl)) {
251 twiceMaxEdgePower = 251 twiceMaxEdgePower =
252 pRdEdgesPower[i - 1].tPower; 252 CTL_EDGE_TPOWER(pRdEdgesPower[i - 1].ctl);
253 } 253 }
254 break; 254 break;
255 } 255 }
diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h
index dacb45e1b906..dd59f09441a3 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom.h
+++ b/drivers/net/wireless/ath/ath9k/eeprom.h
@@ -233,6 +233,18 @@
233 233
234#define AR9287_CHECKSUM_LOCATION (AR9287_EEP_START_LOC + 1) 234#define AR9287_CHECKSUM_LOCATION (AR9287_EEP_START_LOC + 1)
235 235
236#define CTL_EDGE_TPOWER(_ctl) ((_ctl) & 0x3f)
237#define CTL_EDGE_FLAGS(_ctl) (((_ctl) >> 6) & 0x03)
238
239#define LNA_CTL_BUF_MODE BIT(0)
240#define LNA_CTL_ISEL_LO BIT(1)
241#define LNA_CTL_ISEL_HI BIT(2)
242#define LNA_CTL_BUF_IN BIT(3)
243#define LNA_CTL_FEM_BAND BIT(4)
244#define LNA_CTL_LOCAL_BIAS BIT(5)
245#define LNA_CTL_FORCE_XPA BIT(6)
246#define LNA_CTL_USE_ANT1 BIT(7)
247
236enum eeprom_param { 248enum eeprom_param {
237 EEP_NFTHRESH_5, 249 EEP_NFTHRESH_5,
238 EEP_NFTHRESH_2, 250 EEP_NFTHRESH_2,
@@ -378,10 +390,7 @@ struct modal_eep_header {
378 u8 xatten2Margin[AR5416_MAX_CHAINS]; 390 u8 xatten2Margin[AR5416_MAX_CHAINS];
379 u8 ob_ch1; 391 u8 ob_ch1;
380 u8 db_ch1; 392 u8 db_ch1;
381 u8 useAnt1:1, 393 u8 lna_ctl;
382 force_xpaon:1,
383 local_bias:1,
384 femBandSelectUsed:1, xlnabufin:1, xlnaisel:2, xlnabufmode:1;
385 u8 miscBits; 394 u8 miscBits;
386 u16 xpaBiasLvlFreq[3]; 395 u16 xpaBiasLvlFreq[3];
387 u8 futureModal[6]; 396 u8 futureModal[6];
@@ -535,18 +544,10 @@ struct cal_target_power_ht {
535 u8 tPow2x[8]; 544 u8 tPow2x[8];
536} __packed; 545} __packed;
537 546
538
539#ifdef __BIG_ENDIAN_BITFIELD
540struct cal_ctl_edges {
541 u8 bChannel;
542 u8 flag:2, tPower:6;
543} __packed;
544#else
545struct cal_ctl_edges { 547struct cal_ctl_edges {
546 u8 bChannel; 548 u8 bChannel;
547 u8 tPower:6, flag:2; 549 u8 ctl;
548} __packed; 550} __packed;
549#endif
550 551
551struct cal_data_op_loop_ar9287 { 552struct cal_data_op_loop_ar9287 {
552 u8 pwrPdg[2][5]; 553 u8 pwrPdg[2][5];
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_9287.c b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
index 966b9496a9dd..195406db3bd8 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
@@ -37,7 +37,7 @@ static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
37 int addr, eep_start_loc; 37 int addr, eep_start_loc;
38 eep_data = (u16 *)eep; 38 eep_data = (u16 *)eep;
39 39
40 if (ah->hw_version.devid == 0x7015) 40 if (AR9287_HTC_DEVID(ah))
41 eep_start_loc = AR9287_HTC_EEP_START_LOC; 41 eep_start_loc = AR9287_HTC_EEP_START_LOC;
42 else 42 else
43 eep_start_loc = AR9287_EEP_START_LOC; 43 eep_start_loc = AR9287_EEP_START_LOC;
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_def.c b/drivers/net/wireless/ath/ath9k/eeprom_def.c
index 76b4d65472dd..a3ccb1b9638d 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
@@ -451,9 +451,10 @@ static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
451 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2, 451 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
452 AR_AN_TOP2_LOCALBIAS, 452 AR_AN_TOP2_LOCALBIAS,
453 AR_AN_TOP2_LOCALBIAS_S, 453 AR_AN_TOP2_LOCALBIAS_S,
454 pModal->local_bias); 454 !!(pModal->lna_ctl &
455 LNA_CTL_LOCAL_BIAS));
455 REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG, 456 REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
456 pModal->force_xpaon); 457 !!(pModal->lna_ctl & LNA_CTL_FORCE_XPA));
457 } 458 }
458 459
459 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH, 460 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
@@ -1062,15 +1063,19 @@ static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
1062 case 1: 1063 case 1:
1063 break; 1064 break;
1064 case 2: 1065 case 2:
1065 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN; 1066 if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
1067 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
1068 else
1069 scaledPower = 0;
1066 break; 1070 break;
1067 case 3: 1071 case 3:
1068 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN; 1072 if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
1073 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
1074 else
1075 scaledPower = 0;
1069 break; 1076 break;
1070 } 1077 }
1071 1078
1072 scaledPower = max((u16)0, scaledPower);
1073
1074 if (IS_CHAN_2GHZ(chan)) { 1079 if (IS_CHAN_2GHZ(chan)) {
1075 numCtlModes = ARRAY_SIZE(ctlModesFor11g) - 1080 numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
1076 SUB_NUM_CTL_MODES_AT_2G_40; 1081 SUB_NUM_CTL_MODES_AT_2G_40;
@@ -1428,9 +1433,9 @@ static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
1428 1433
1429 num_ant_config = 1; 1434 num_ant_config = 1;
1430 1435
1431 if (pBase->version >= 0x0E0D) 1436 if (pBase->version >= 0x0E0D &&
1432 if (pModal->useAnt1) 1437 (pModal->lna_ctl & LNA_CTL_USE_ANT1))
1433 num_ant_config += 1; 1438 num_ant_config += 1;
1434 1439
1435 return num_ant_config; 1440 return num_ant_config;
1436} 1441}
diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c
index 6576f683dba0..0de3c3d3c245 100644
--- a/drivers/net/wireless/ath/ath9k/hif_usb.c
+++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
@@ -35,8 +35,14 @@ static struct usb_device_id ath9k_hif_usb_ids[] = {
35 { USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */ 35 { USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */
36 { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */ 36 { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */
37 { USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */ 37 { USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */
38 { USB_DEVICE(0x13D3, 0x3346) }, /* IMC Networks */
39 { USB_DEVICE(0x13D3, 0x3348) }, /* Azurewave */
40 { USB_DEVICE(0x13D3, 0x3349) }, /* Azurewave */
41 { USB_DEVICE(0x13D3, 0x3350) }, /* Azurewave */
38 { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */ 42 { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */
39 { USB_DEVICE(0x083A, 0xA704) }, /* SMC Networks */ 43 { USB_DEVICE(0x083A, 0xA704) }, /* SMC Networks */
44 { USB_DEVICE(0x040D, 0x3801) }, /* VIA */
45 { USB_DEVICE(0x1668, 0x1200) }, /* Verizon */
40 { }, 46 { },
41}; 47};
42 48
@@ -540,11 +546,11 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
540 return; 546 return;
541 } 547 }
542 548
543 usb_fill_int_urb(urb, hif_dev->udev, 549 usb_fill_bulk_urb(urb, hif_dev->udev,
544 usb_rcvbulkpipe(hif_dev->udev, 550 usb_rcvbulkpipe(hif_dev->udev,
545 USB_REG_IN_PIPE), 551 USB_REG_IN_PIPE),
546 nskb->data, MAX_REG_IN_BUF_SIZE, 552 nskb->data, MAX_REG_IN_BUF_SIZE,
547 ath9k_hif_usb_reg_in_cb, nskb, 1); 553 ath9k_hif_usb_reg_in_cb, nskb);
548 554
549 ret = usb_submit_urb(urb, GFP_ATOMIC); 555 ret = usb_submit_urb(urb, GFP_ATOMIC);
550 if (ret) { 556 if (ret) {
@@ -720,11 +726,11 @@ static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb *hif_dev)
720 if (!skb) 726 if (!skb)
721 goto err; 727 goto err;
722 728
723 usb_fill_int_urb(hif_dev->reg_in_urb, hif_dev->udev, 729 usb_fill_bulk_urb(hif_dev->reg_in_urb, hif_dev->udev,
724 usb_rcvbulkpipe(hif_dev->udev, 730 usb_rcvbulkpipe(hif_dev->udev,
725 USB_REG_IN_PIPE), 731 USB_REG_IN_PIPE),
726 skb->data, MAX_REG_IN_BUF_SIZE, 732 skb->data, MAX_REG_IN_BUF_SIZE,
727 ath9k_hif_usb_reg_in_cb, skb, 1); 733 ath9k_hif_usb_reg_in_cb, skb);
728 734
729 if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0) 735 if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0)
730 goto err; 736 goto err;
@@ -805,6 +811,8 @@ static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
805 case 0x7010: 811 case 0x7010:
806 case 0x7015: 812 case 0x7015:
807 case 0x9018: 813 case 0x9018:
814 case 0xA704:
815 case 0x1200:
808 firm_offset = AR7010_FIRMWARE_TEXT; 816 firm_offset = AR7010_FIRMWARE_TEXT;
809 break; 817 break;
810 default: 818 default:
@@ -843,14 +851,6 @@ static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev)
843 goto err_fw_req; 851 goto err_fw_req;
844 } 852 }
845 853
846 /* Alloc URBs */
847 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
848 if (ret) {
849 dev_err(&hif_dev->udev->dev,
850 "ath9k_htc: Unable to allocate URBs\n");
851 goto err_urb;
852 }
853
854 /* Download firmware */ 854 /* Download firmware */
855 ret = ath9k_hif_usb_download_fw(hif_dev); 855 ret = ath9k_hif_usb_download_fw(hif_dev);
856 if (ret) { 856 if (ret) {
@@ -866,16 +866,22 @@ static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev)
866 */ 866 */
867 for (idx = 0; idx < alt->desc.bNumEndpoints; idx++) { 867 for (idx = 0; idx < alt->desc.bNumEndpoints; idx++) {
868 endp = &alt->endpoint[idx].desc; 868 endp = &alt->endpoint[idx].desc;
869 if (((endp->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) 869 if ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
870 == 0x04) && 870 == USB_ENDPOINT_XFER_INT) {
871 ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
872 == USB_ENDPOINT_XFER_INT)) {
873 endp->bmAttributes &= ~USB_ENDPOINT_XFERTYPE_MASK; 871 endp->bmAttributes &= ~USB_ENDPOINT_XFERTYPE_MASK;
874 endp->bmAttributes |= USB_ENDPOINT_XFER_BULK; 872 endp->bmAttributes |= USB_ENDPOINT_XFER_BULK;
875 endp->bInterval = 0; 873 endp->bInterval = 0;
876 } 874 }
877 } 875 }
878 876
877 /* Alloc URBs */
878 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
879 if (ret) {
880 dev_err(&hif_dev->udev->dev,
881 "ath9k_htc: Unable to allocate URBs\n");
882 goto err_urb;
883 }
884
879 return 0; 885 return 0;
880 886
881err_fw_download: 887err_fw_download:
@@ -929,6 +935,8 @@ static int ath9k_hif_usb_probe(struct usb_interface *interface,
929 case 0x7010: 935 case 0x7010:
930 case 0x7015: 936 case 0x7015:
931 case 0x9018: 937 case 0x9018:
938 case 0xA704:
939 case 0x1200:
932 if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x0202) 940 if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x0202)
933 hif_dev->fw_name = FIRMWARE_AR7010_1_1; 941 hif_dev->fw_name = FIRMWARE_AR7010_1_1;
934 else 942 else
@@ -1016,6 +1024,13 @@ static int ath9k_hif_usb_suspend(struct usb_interface *interface,
1016 struct hif_device_usb *hif_dev = 1024 struct hif_device_usb *hif_dev =
1017 (struct hif_device_usb *) usb_get_intfdata(interface); 1025 (struct hif_device_usb *) usb_get_intfdata(interface);
1018 1026
1027 /*
1028 * The device has to be set to FULLSLEEP mode in case no
1029 * interface is up.
1030 */
1031 if (!(hif_dev->flags & HIF_USB_START))
1032 ath9k_htc_suspend(hif_dev->htc_handle);
1033
1019 ath9k_hif_usb_dealloc_urbs(hif_dev); 1034 ath9k_hif_usb_dealloc_urbs(hif_dev);
1020 1035
1021 return 0; 1036 return 0;
diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h
index 75ecf6a30d25..c3b561daa6c1 100644
--- a/drivers/net/wireless/ath/ath9k/htc.h
+++ b/drivers/net/wireless/ath/ath9k/htc.h
@@ -455,6 +455,8 @@ u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv);
455void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv); 455void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv);
456void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv); 456void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv);
457void ath9k_ps_work(struct work_struct *work); 457void ath9k_ps_work(struct work_struct *work);
458bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
459 enum ath9k_power_mode mode);
458 460
459void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv); 461void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv);
460void ath9k_init_leds(struct ath9k_htc_priv *priv); 462void ath9k_init_leds(struct ath9k_htc_priv *priv);
@@ -464,6 +466,7 @@ int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
464 u16 devid, char *product); 466 u16 devid, char *product);
465void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug); 467void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug);
466#ifdef CONFIG_PM 468#ifdef CONFIG_PM
469void ath9k_htc_suspend(struct htc_target *htc_handle);
467int ath9k_htc_resume(struct htc_target *htc_handle); 470int ath9k_htc_resume(struct htc_target *htc_handle);
468#endif 471#endif
469#ifdef CONFIG_ATH9K_HTC_DEBUGFS 472#ifdef CONFIG_ATH9K_HTC_DEBUGFS
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_init.c b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
index 3d7b97f1b3ae..8776f49ffd41 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
@@ -249,6 +249,8 @@ static int ath9k_init_htc_services(struct ath9k_htc_priv *priv, u16 devid)
249 case 0x7010: 249 case 0x7010:
250 case 0x7015: 250 case 0x7015:
251 case 0x9018: 251 case 0x9018:
252 case 0xA704:
253 case 0x1200:
252 priv->htc->credits = 45; 254 priv->htc->credits = 45;
253 break; 255 break;
254 default: 256 default:
@@ -889,6 +891,12 @@ void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug)
889} 891}
890 892
891#ifdef CONFIG_PM 893#ifdef CONFIG_PM
894
895void ath9k_htc_suspend(struct htc_target *htc_handle)
896{
897 ath9k_htc_setpower(htc_handle->drv_priv, ATH9K_PM_FULL_SLEEP);
898}
899
892int ath9k_htc_resume(struct htc_target *htc_handle) 900int ath9k_htc_resume(struct htc_target *htc_handle)
893{ 901{
894 int ret; 902 int ret;
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
index 9a3be8da755d..51977caca47f 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
@@ -63,8 +63,8 @@ static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
63 return mode; 63 return mode;
64} 64}
65 65
66static bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, 66bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
67 enum ath9k_power_mode mode) 67 enum ath9k_power_mode mode)
68{ 68{
69 bool ret; 69 bool ret;
70 70
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
index 3d19b5bc937f..29d80ca78393 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
@@ -121,7 +121,7 @@ int ath9k_htc_tx_start(struct ath9k_htc_priv *priv, struct sk_buff *skb)
121 tx_hdr.data_type = ATH9K_HTC_NORMAL; 121 tx_hdr.data_type = ATH9K_HTC_NORMAL;
122 } 122 }
123 123
124 if (ieee80211_is_data(fc)) { 124 if (ieee80211_is_data_qos(fc)) {
125 qc = ieee80211_get_qos_ctl(hdr); 125 qc = ieee80211_get_qos_ctl(hdr);
126 tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 126 tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
127 } 127 }
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index cc13ee117823..c7fbe25cc128 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -484,6 +484,7 @@ static int ath9k_hw_post_init(struct ath_hw *ah)
484 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, 484 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
485 "Failed allocating banks for " 485 "Failed allocating banks for "
486 "external radio\n"); 486 "external radio\n");
487 ath9k_hw_rf_free_ext_banks(ah);
487 return ecode; 488 return ecode;
488 } 489 }
489 490
@@ -952,9 +953,12 @@ static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
952 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); 953 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
953 break; 954 break;
954 case NL80211_IFTYPE_STATION: 955 case NL80211_IFTYPE_STATION:
955 case NL80211_IFTYPE_MONITOR:
956 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE); 956 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
957 break; 957 break;
958 default:
959 if (ah->is_monitoring)
960 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
961 break;
958 } 962 }
959} 963}
960 964
@@ -1634,7 +1638,6 @@ void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
1634 1638
1635 switch (ah->opmode) { 1639 switch (ah->opmode) {
1636 case NL80211_IFTYPE_STATION: 1640 case NL80211_IFTYPE_STATION:
1637 case NL80211_IFTYPE_MONITOR:
1638 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); 1641 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
1639 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff); 1642 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
1640 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff); 1643 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
@@ -1663,6 +1666,14 @@ void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
1663 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN; 1666 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
1664 break; 1667 break;
1665 default: 1668 default:
1669 if (ah->is_monitoring) {
1670 REG_WRITE(ah, AR_NEXT_TBTT_TIMER,
1671 TU_TO_USEC(next_beacon));
1672 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
1673 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
1674 flags |= AR_TBTT_TIMER_EN;
1675 break;
1676 }
1666 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON, 1677 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
1667 "%s: unsupported opmode: %d\n", 1678 "%s: unsupported opmode: %d\n",
1668 __func__, ah->opmode); 1679 __func__, ah->opmode);
@@ -2033,7 +2044,8 @@ u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
2033 val = REG_READ(ah, AR7010_GPIO_IN); 2044 val = REG_READ(ah, AR7010_GPIO_IN);
2034 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0; 2045 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2035 } else if (AR_SREV_9300_20_OR_LATER(ah)) 2046 } else if (AR_SREV_9300_20_OR_LATER(ah))
2036 return MS_REG_READ(AR9300, gpio) != 0; 2047 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2048 AR_GPIO_BIT(gpio)) != 0;
2037 else if (AR_SREV_9271(ah)) 2049 else if (AR_SREV_9271(ah))
2038 return MS_REG_READ(AR9271, gpio) != 0; 2050 return MS_REG_READ(AR9271, gpio) != 0;
2039 else if (AR_SREV_9287_11_OR_LATER(ah)) 2051 else if (AR_SREV_9287_11_OR_LATER(ah))
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index d032939768b0..d47d1b4b6002 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -622,6 +622,7 @@ struct ath_hw {
622 622
623 bool sw_mgmt_crypto; 623 bool sw_mgmt_crypto;
624 bool is_pciexpress; 624 bool is_pciexpress;
625 bool is_monitoring;
625 bool need_an_top2_fixup; 626 bool need_an_top2_fixup;
626 u16 tx_trig_level; 627 u16 tx_trig_level;
627 628
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index 95b41db0d86b..14b8ab386daf 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -661,6 +661,8 @@ void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
661 hw->flags |= IEEE80211_HW_MFP_CAPABLE; 661 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
662 662
663 hw->wiphy->interface_modes = 663 hw->wiphy->interface_modes =
664 BIT(NL80211_IFTYPE_P2P_GO) |
665 BIT(NL80211_IFTYPE_P2P_CLIENT) |
664 BIT(NL80211_IFTYPE_AP) | 666 BIT(NL80211_IFTYPE_AP) |
665 BIT(NL80211_IFTYPE_WDS) | 667 BIT(NL80211_IFTYPE_WDS) |
666 BIT(NL80211_IFTYPE_STATION) | 668 BIT(NL80211_IFTYPE_STATION) |
@@ -756,6 +758,9 @@ int ath9k_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
756 ath_init_leds(sc); 758 ath_init_leds(sc);
757 ath_start_rfkill_poll(sc); 759 ath_start_rfkill_poll(sc);
758 760
761 pm_qos_add_request(&sc->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
762 PM_QOS_DEFAULT_VALUE);
763
759 return 0; 764 return 0;
760 765
761error_world: 766error_world:
@@ -824,6 +829,7 @@ void ath9k_deinit_device(struct ath_softc *sc)
824 } 829 }
825 830
826 ieee80211_unregister_hw(hw); 831 ieee80211_unregister_hw(hw);
832 pm_qos_remove_request(&sc->pm_qos_req);
827 ath_rx_cleanup(sc); 833 ath_rx_cleanup(sc);
828 ath_tx_cleanup(sc); 834 ath_tx_cleanup(sc);
829 ath9k_deinit_softc(sc); 835 ath9k_deinit_softc(sc);
diff --git a/drivers/net/wireless/ath/ath9k/mac.c b/drivers/net/wireless/ath/ath9k/mac.c
index 8c13479b17cd..c996963ab339 100644
--- a/drivers/net/wireless/ath/ath9k/mac.c
+++ b/drivers/net/wireless/ath/ath9k/mac.c
@@ -703,8 +703,7 @@ int ath9k_hw_rxprocdesc(struct ath_hw *ah, struct ath_desc *ds,
703 rs->rs_phyerr = phyerr; 703 rs->rs_phyerr = phyerr;
704 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr) 704 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
705 rs->rs_status |= ATH9K_RXERR_DECRYPT; 705 rs->rs_status |= ATH9K_RXERR_DECRYPT;
706 else if ((ads.ds_rxstatus8 & AR_MichaelErr) && 706 else if (ads.ds_rxstatus8 & AR_MichaelErr)
707 rs->rs_keyix != ATH9K_RXKEYIX_INVALID)
708 rs->rs_status |= ATH9K_RXERR_MIC; 707 rs->rs_status |= ATH9K_RXERR_MIC;
709 else if (ads.ds_rxstatus8 & AR_KeyMiss) 708 else if (ads.ds_rxstatus8 & AR_KeyMiss)
710 rs->rs_status |= ATH9K_RXERR_DECRYPT; 709 rs->rs_status |= ATH9K_RXERR_DECRYPT;
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index b52f1cf8a603..c0c3464d3a86 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -93,11 +93,13 @@ void ath9k_ps_wakeup(struct ath_softc *sc)
93{ 93{
94 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 94 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
95 unsigned long flags; 95 unsigned long flags;
96 enum ath9k_power_mode power_mode;
96 97
97 spin_lock_irqsave(&sc->sc_pm_lock, flags); 98 spin_lock_irqsave(&sc->sc_pm_lock, flags);
98 if (++sc->ps_usecount != 1) 99 if (++sc->ps_usecount != 1)
99 goto unlock; 100 goto unlock;
100 101
102 power_mode = sc->sc_ah->power_mode;
101 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); 103 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
102 104
103 /* 105 /*
@@ -105,10 +107,12 @@ void ath9k_ps_wakeup(struct ath_softc *sc)
105 * useful data. Better clear them now so that they don't mess up 107 * useful data. Better clear them now so that they don't mess up
106 * survey data results. 108 * survey data results.
107 */ 109 */
108 spin_lock(&common->cc_lock); 110 if (power_mode != ATH9K_PM_AWAKE) {
109 ath_hw_cycle_counters_update(common); 111 spin_lock(&common->cc_lock);
110 memset(&common->cc_survey, 0, sizeof(common->cc_survey)); 112 ath_hw_cycle_counters_update(common);
111 spin_unlock(&common->cc_lock); 113 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
114 spin_unlock(&common->cc_lock);
115 }
112 116
113 unlock: 117 unlock:
114 spin_unlock_irqrestore(&sc->sc_pm_lock, flags); 118 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
@@ -240,11 +244,12 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
240 * the relevant bits of the h/w. 244 * the relevant bits of the h/w.
241 */ 245 */
242 ath9k_hw_set_interrupts(ah, 0); 246 ath9k_hw_set_interrupts(ah, 0);
243 ath_drain_all_txq(sc, false); 247 stopped = ath_drain_all_txq(sc, false);
244 248
245 spin_lock_bh(&sc->rx.pcu_lock); 249 spin_lock_bh(&sc->rx.pcu_lock);
246 250
247 stopped = ath_stoprecv(sc); 251 if (!ath_stoprecv(sc))
252 stopped = false;
248 253
249 /* XXX: do not flush receive queue here. We don't want 254 /* XXX: do not flush receive queue here. We don't want
250 * to flush data frames already in queue because of 255 * to flush data frames already in queue because of
@@ -1217,6 +1222,7 @@ static int ath9k_start(struct ieee80211_hw *hw)
1217 ah->imask |= ATH9K_INT_CST; 1222 ah->imask |= ATH9K_INT_CST;
1218 1223
1219 sc->sc_flags &= ~SC_OP_INVALID; 1224 sc->sc_flags &= ~SC_OP_INVALID;
1225 sc->sc_ah->is_monitoring = false;
1220 1226
1221 /* Disable BMISS interrupt when we're not associated */ 1227 /* Disable BMISS interrupt when we're not associated */
1222 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS); 1228 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
@@ -1238,6 +1244,8 @@ static int ath9k_start(struct ieee80211_hw *hw)
1238 ath9k_btcoex_timer_resume(sc); 1244 ath9k_btcoex_timer_resume(sc);
1239 } 1245 }
1240 1246
1247 pm_qos_update_request(&sc->pm_qos_req, 55);
1248
1241mutex_unlock: 1249mutex_unlock:
1242 mutex_unlock(&sc->mutex); 1250 mutex_unlock(&sc->mutex);
1243 1251
@@ -1415,6 +1423,8 @@ static void ath9k_stop(struct ieee80211_hw *hw)
1415 1423
1416 sc->sc_flags |= SC_OP_INVALID; 1424 sc->sc_flags |= SC_OP_INVALID;
1417 1425
1426 pm_qos_update_request(&sc->pm_qos_req, PM_QOS_DEFAULT_VALUE);
1427
1418 mutex_unlock(&sc->mutex); 1428 mutex_unlock(&sc->mutex);
1419 1429
1420 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n"); 1430 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
@@ -1493,8 +1503,7 @@ static int ath9k_add_interface(struct ieee80211_hw *hw,
1493 ath9k_hw_set_interrupts(ah, ah->imask); 1503 ath9k_hw_set_interrupts(ah, ah->imask);
1494 1504
1495 if (vif->type == NL80211_IFTYPE_AP || 1505 if (vif->type == NL80211_IFTYPE_AP ||
1496 vif->type == NL80211_IFTYPE_ADHOC || 1506 vif->type == NL80211_IFTYPE_ADHOC) {
1497 vif->type == NL80211_IFTYPE_MONITOR) {
1498 sc->sc_flags |= SC_OP_ANI_RUN; 1507 sc->sc_flags |= SC_OP_ANI_RUN;
1499 ath_start_ani(common); 1508 ath_start_ani(common);
1500 } 1509 }
@@ -1511,7 +1520,6 @@ static void ath9k_remove_interface(struct ieee80211_hw *hw,
1511 struct ath_softc *sc = aphy->sc; 1520 struct ath_softc *sc = aphy->sc;
1512 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 1521 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1513 struct ath_vif *avp = (void *)vif->drv_priv; 1522 struct ath_vif *avp = (void *)vif->drv_priv;
1514 int i;
1515 1523
1516 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n"); 1524 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1517 1525
@@ -1525,21 +1533,24 @@ static void ath9k_remove_interface(struct ieee80211_hw *hw,
1525 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) || 1533 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
1526 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) || 1534 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
1527 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) { 1535 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
1536 /* Disable SWBA interrupt */
1537 sc->sc_ah->imask &= ~ATH9K_INT_SWBA;
1528 ath9k_ps_wakeup(sc); 1538 ath9k_ps_wakeup(sc);
1539 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_ah->imask);
1529 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); 1540 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1530 ath9k_ps_restore(sc); 1541 ath9k_ps_restore(sc);
1542 tasklet_kill(&sc->bcon_tasklet);
1531 } 1543 }
1532 1544
1533 ath_beacon_return(sc, avp); 1545 ath_beacon_return(sc, avp);
1534 sc->sc_flags &= ~SC_OP_BEACONS; 1546 sc->sc_flags &= ~SC_OP_BEACONS;
1535 1547
1536 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) { 1548 if (sc->nbcnvifs) {
1537 if (sc->beacon.bslot[i] == vif) { 1549 /* Re-enable SWBA interrupt */
1538 printk(KERN_DEBUG "%s: vif had allocated beacon " 1550 sc->sc_ah->imask |= ATH9K_INT_SWBA;
1539 "slot\n", __func__); 1551 ath9k_ps_wakeup(sc);
1540 sc->beacon.bslot[i] = NULL; 1552 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_ah->imask);
1541 sc->beacon.bslot_aphy[i] = NULL; 1553 ath9k_ps_restore(sc);
1542 }
1543 } 1554 }
1544 1555
1545 sc->nvifs--; 1556 sc->nvifs--;
@@ -1644,8 +1655,12 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1644 if (changed & IEEE80211_CONF_CHANGE_MONITOR) { 1655 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1645 if (conf->flags & IEEE80211_CONF_MONITOR) { 1656 if (conf->flags & IEEE80211_CONF_MONITOR) {
1646 ath_print(common, ATH_DBG_CONFIG, 1657 ath_print(common, ATH_DBG_CONFIG,
1647 "HW opmode set to Monitor mode\n"); 1658 "Monitor mode is enabled\n");
1648 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR; 1659 sc->sc_ah->is_monitoring = true;
1660 } else {
1661 ath_print(common, ATH_DBG_CONFIG,
1662 "Monitor mode is disabled\n");
1663 sc->sc_ah->is_monitoring = false;
1649 } 1664 }
1650 } 1665 }
1651 1666
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index fddb0129bb57..fdc2ec52b42f 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -441,7 +441,7 @@ u32 ath_calcrxfilter(struct ath_softc *sc)
441 */ 441 */
442 if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) && 442 if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) &&
443 (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) || 443 (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) ||
444 (sc->sc_ah->opmode == NL80211_IFTYPE_MONITOR)) 444 (sc->sc_ah->is_monitoring))
445 rfilt |= ATH9K_RX_FILTER_PROM; 445 rfilt |= ATH9K_RX_FILTER_PROM;
446 446
447 if (sc->rx.rxfilter & FIF_CONTROL) 447 if (sc->rx.rxfilter & FIF_CONTROL)
@@ -518,7 +518,7 @@ bool ath_stoprecv(struct ath_softc *sc)
518 bool stopped; 518 bool stopped;
519 519
520 spin_lock_bh(&sc->rx.rxbuflock); 520 spin_lock_bh(&sc->rx.rxbuflock);
521 ath9k_hw_stoppcurecv(ah); 521 ath9k_hw_abortpcurecv(ah);
522 ath9k_hw_setrxfilter(ah, 0); 522 ath9k_hw_setrxfilter(ah, 0);
523 stopped = ath9k_hw_stopdmarecv(ah); 523 stopped = ath9k_hw_stopdmarecv(ah);
524 524
@@ -838,6 +838,10 @@ static bool ath9k_rx_accept(struct ath_common *common,
838 struct ath_rx_status *rx_stats, 838 struct ath_rx_status *rx_stats,
839 bool *decrypt_error) 839 bool *decrypt_error)
840{ 840{
841#define is_mc_or_valid_tkip_keyix ((is_mc || \
842 (rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && \
843 test_bit(rx_stats->rs_keyix, common->tkip_keymap))))
844
841 struct ath_hw *ah = common->ah; 845 struct ath_hw *ah = common->ah;
842 __le16 fc; 846 __le16 fc;
843 u8 rx_status_len = ah->caps.rx_status_len; 847 u8 rx_status_len = ah->caps.rx_status_len;
@@ -879,15 +883,18 @@ static bool ath9k_rx_accept(struct ath_common *common,
879 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) { 883 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
880 *decrypt_error = true; 884 *decrypt_error = true;
881 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) { 885 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
886 bool is_mc;
882 /* 887 /*
883 * The MIC error bit is only valid if the frame 888 * The MIC error bit is only valid if the frame
884 * is not a control frame or fragment, and it was 889 * is not a control frame or fragment, and it was
885 * decrypted using a valid TKIP key. 890 * decrypted using a valid TKIP key.
886 */ 891 */
892 is_mc = !!is_multicast_ether_addr(hdr->addr1);
893
887 if (!ieee80211_is_ctl(fc) && 894 if (!ieee80211_is_ctl(fc) &&
888 !ieee80211_has_morefrags(fc) && 895 !ieee80211_has_morefrags(fc) &&
889 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) && 896 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
890 test_bit(rx_stats->rs_keyix, common->tkip_keymap)) 897 is_mc_or_valid_tkip_keyix)
891 rxs->flag |= RX_FLAG_MMIC_ERROR; 898 rxs->flag |= RX_FLAG_MMIC_ERROR;
892 else 899 else
893 rx_stats->rs_status &= ~ATH9K_RXERR_MIC; 900 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
@@ -897,7 +904,7 @@ static bool ath9k_rx_accept(struct ath_common *common,
897 * decryption and MIC failures. For monitor mode, 904 * decryption and MIC failures. For monitor mode,
898 * we also ignore the CRC error. 905 * we also ignore the CRC error.
899 */ 906 */
900 if (ah->opmode == NL80211_IFTYPE_MONITOR) { 907 if (ah->is_monitoring) {
901 if (rx_stats->rs_status & 908 if (rx_stats->rs_status &
902 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC | 909 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
903 ATH9K_RXERR_CRC)) 910 ATH9K_RXERR_CRC))
diff --git a/drivers/net/wireless/ath/ath9k/reg.h b/drivers/net/wireless/ath/ath9k/reg.h
index 42976b0a01c1..2c6a22fbb0f0 100644
--- a/drivers/net/wireless/ath/ath9k/reg.h
+++ b/drivers/net/wireless/ath/ath9k/reg.h
@@ -703,6 +703,7 @@
703#define AR_WA_RESET_EN (1 << 18) /* Sw Control to enable PCI-Reset to POR (bit 15) */ 703#define AR_WA_RESET_EN (1 << 18) /* Sw Control to enable PCI-Reset to POR (bit 15) */
704#define AR_WA_ANALOG_SHIFT (1 << 20) 704#define AR_WA_ANALOG_SHIFT (1 << 20)
705#define AR_WA_POR_SHORT (1 << 21) /* PCI-E Phy reset control */ 705#define AR_WA_POR_SHORT (1 << 21) /* PCI-E Phy reset control */
706#define AR_WA_BIT22 (1 << 22)
706#define AR9285_WA_DEFAULT 0x004a050b 707#define AR9285_WA_DEFAULT 0x004a050b
707#define AR9280_WA_DEFAULT 0x0040073b 708#define AR9280_WA_DEFAULT 0x0040073b
708#define AR_WA_DEFAULT 0x0000073f 709#define AR_WA_DEFAULT 0x0000073f
@@ -865,7 +866,13 @@
865#define AR_DEVID_7010(_ah) \ 866#define AR_DEVID_7010(_ah) \
866 (((_ah)->hw_version.devid == 0x7010) || \ 867 (((_ah)->hw_version.devid == 0x7010) || \
867 ((_ah)->hw_version.devid == 0x7015) || \ 868 ((_ah)->hw_version.devid == 0x7015) || \
868 ((_ah)->hw_version.devid == 0x9018)) 869 ((_ah)->hw_version.devid == 0x9018) || \
870 ((_ah)->hw_version.devid == 0xA704) || \
871 ((_ah)->hw_version.devid == 0x1200))
872
873#define AR9287_HTC_DEVID(_ah) \
874 (((_ah)->hw_version.devid == 0x7015) || \
875 ((_ah)->hw_version.devid == 0x1200))
869 876
870#define AR_RADIO_SREV_MAJOR 0xf0 877#define AR_RADIO_SREV_MAJOR 0xf0
871#define AR_RAD5133_SREV_MAJOR 0xc0 878#define AR_RAD5133_SREV_MAJOR 0xc0
@@ -977,11 +984,13 @@ enum {
977#define AR9287_GPIO_IN_VAL_S 11 984#define AR9287_GPIO_IN_VAL_S 11
978#define AR9271_GPIO_IN_VAL 0xFFFF0000 985#define AR9271_GPIO_IN_VAL 0xFFFF0000
979#define AR9271_GPIO_IN_VAL_S 16 986#define AR9271_GPIO_IN_VAL_S 16
980#define AR9300_GPIO_IN_VAL 0x0001FFFF
981#define AR9300_GPIO_IN_VAL_S 0
982#define AR7010_GPIO_IN_VAL 0x0000FFFF 987#define AR7010_GPIO_IN_VAL 0x0000FFFF
983#define AR7010_GPIO_IN_VAL_S 0 988#define AR7010_GPIO_IN_VAL_S 0
984 989
990#define AR_GPIO_IN 0x404c
991#define AR9300_GPIO_IN_VAL 0x0001FFFF
992#define AR9300_GPIO_IN_VAL_S 0
993
985#define AR_GPIO_OE_OUT (AR_SREV_9300_20_OR_LATER(ah) ? 0x4050 : 0x404c) 994#define AR_GPIO_OE_OUT (AR_SREV_9300_20_OR_LATER(ah) ? 0x4050 : 0x404c)
986#define AR_GPIO_OE_OUT_DRV 0x3 995#define AR_GPIO_OE_OUT_DRV 0x3
987#define AR_GPIO_OE_OUT_DRV_NO 0x0 996#define AR_GPIO_OE_OUT_DRV_NO 0x0
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index f2ade2402ce2..aff04789f794 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1120,7 +1120,7 @@ void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq, bool retry_tx)
1120 } 1120 }
1121} 1121}
1122 1122
1123void ath_drain_all_txq(struct ath_softc *sc, bool retry_tx) 1123bool ath_drain_all_txq(struct ath_softc *sc, bool retry_tx)
1124{ 1124{
1125 struct ath_hw *ah = sc->sc_ah; 1125 struct ath_hw *ah = sc->sc_ah;
1126 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 1126 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
@@ -1128,7 +1128,7 @@ void ath_drain_all_txq(struct ath_softc *sc, bool retry_tx)
1128 int i, npend = 0; 1128 int i, npend = 0;
1129 1129
1130 if (sc->sc_flags & SC_OP_INVALID) 1130 if (sc->sc_flags & SC_OP_INVALID)
1131 return; 1131 return true;
1132 1132
1133 /* Stop beacon queue */ 1133 /* Stop beacon queue */
1134 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); 1134 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
@@ -1142,25 +1142,15 @@ void ath_drain_all_txq(struct ath_softc *sc, bool retry_tx)
1142 } 1142 }
1143 } 1143 }
1144 1144
1145 if (npend) { 1145 if (npend)
1146 int r; 1146 ath_print(common, ATH_DBG_FATAL, "Failed to stop TX DMA!\n");
1147
1148 ath_print(common, ATH_DBG_FATAL,
1149 "Failed to stop TX DMA. Resetting hardware!\n");
1150
1151 spin_lock_bh(&sc->sc_resetlock);
1152 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
1153 if (r)
1154 ath_print(common, ATH_DBG_FATAL,
1155 "Unable to reset hardware; reset status %d\n",
1156 r);
1157 spin_unlock_bh(&sc->sc_resetlock);
1158 }
1159 1147
1160 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { 1148 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1161 if (ATH_TXQ_SETUP(sc, i)) 1149 if (ATH_TXQ_SETUP(sc, i))
1162 ath_draintxq(sc, &sc->tx.txq[i], retry_tx); 1150 ath_draintxq(sc, &sc->tx.txq[i], retry_tx);
1163 } 1151 }
1152
1153 return !npend;
1164} 1154}
1165 1155
1166void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq) 1156void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
diff --git a/drivers/net/wireless/ath/carl9170/fw.c b/drivers/net/wireless/ath/carl9170/fw.c
index ae6c006bbc56..546b4e4ec5ea 100644
--- a/drivers/net/wireless/ath/carl9170/fw.c
+++ b/drivers/net/wireless/ath/carl9170/fw.c
@@ -291,7 +291,8 @@ static int carl9170_fw(struct ar9170 *ar, const __u8 *data, size_t len)
291 291
292 if (SUPP(CARL9170FW_WLANTX_CAB)) { 292 if (SUPP(CARL9170FW_WLANTX_CAB)) {
293 ar->hw->wiphy->interface_modes |= 293 ar->hw->wiphy->interface_modes |=
294 BIT(NL80211_IFTYPE_AP); 294 BIT(NL80211_IFTYPE_AP) |
295 BIT(NL80211_IFTYPE_P2P_GO);
295 } 296 }
296 } 297 }
297 298
diff --git a/drivers/net/wireless/ath/carl9170/main.c b/drivers/net/wireless/ath/carl9170/main.c
index 980ae70ea424..dc7b30b170d0 100644
--- a/drivers/net/wireless/ath/carl9170/main.c
+++ b/drivers/net/wireless/ath/carl9170/main.c
@@ -647,7 +647,7 @@ init:
647 } 647 }
648 648
649unlock: 649unlock:
650 if (err && (vif_id != -1)) { 650 if (err && (vif_id >= 0)) {
651 vif_priv->active = false; 651 vif_priv->active = false;
652 bitmap_release_region(&ar->vif_bitmap, vif_id, 0); 652 bitmap_release_region(&ar->vif_bitmap, vif_id, 0);
653 ar->vifs--; 653 ar->vifs--;
@@ -1631,7 +1631,8 @@ void *carl9170_alloc(size_t priv_size)
1631 * supports these modes. The code which will add the 1631 * supports these modes. The code which will add the
1632 * additional interface_modes is in fw.c. 1632 * additional interface_modes is in fw.c.
1633 */ 1633 */
1634 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); 1634 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1635 BIT(NL80211_IFTYPE_P2P_CLIENT);
1635 1636
1636 hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS | 1637 hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS |
1637 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 1638 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
diff --git a/drivers/net/wireless/ath/carl9170/tx.c b/drivers/net/wireless/ath/carl9170/tx.c
index b575c865142d..7e6506a77bbb 100644
--- a/drivers/net/wireless/ath/carl9170/tx.c
+++ b/drivers/net/wireless/ath/carl9170/tx.c
@@ -810,7 +810,7 @@ static int carl9170_tx_prepare(struct ar9170 *ar, struct sk_buff *skb)
810 810
811 mac_tmp = cpu_to_le16(AR9170_TX_MAC_HW_DURATION | 811 mac_tmp = cpu_to_le16(AR9170_TX_MAC_HW_DURATION |
812 AR9170_TX_MAC_BACKOFF); 812 AR9170_TX_MAC_BACKOFF);
813 mac_tmp |= cpu_to_le16((hw_queue << AR9170_TX_MAC_QOS_S) && 813 mac_tmp |= cpu_to_le16((hw_queue << AR9170_TX_MAC_QOS_S) &
814 AR9170_TX_MAC_QOS); 814 AR9170_TX_MAC_QOS);
815 815
816 no_ack = !!(info->flags & IEEE80211_TX_CTL_NO_ACK); 816 no_ack = !!(info->flags & IEEE80211_TX_CTL_NO_ACK);
diff --git a/drivers/net/wireless/ath/carl9170/usb.c b/drivers/net/wireless/ath/carl9170/usb.c
index d8607f4c144d..7504ed14c725 100644
--- a/drivers/net/wireless/ath/carl9170/usb.c
+++ b/drivers/net/wireless/ath/carl9170/usb.c
@@ -82,9 +82,11 @@ static struct usb_device_id carl9170_usb_ids[] = {
82 { USB_DEVICE(0x07d1, 0x3c10) }, 82 { USB_DEVICE(0x07d1, 0x3c10) },
83 /* D-Link DWA 160 A2 */ 83 /* D-Link DWA 160 A2 */
84 { USB_DEVICE(0x07d1, 0x3a09) }, 84 { USB_DEVICE(0x07d1, 0x3a09) },
85 /* D-Link DWA 130 D */
86 { USB_DEVICE(0x07d1, 0x3a0f) },
85 /* Netgear WNA1000 */ 87 /* Netgear WNA1000 */
86 { USB_DEVICE(0x0846, 0x9040) }, 88 { USB_DEVICE(0x0846, 0x9040) },
87 /* Netgear WNDA3100 */ 89 /* Netgear WNDA3100 (v1) */
88 { USB_DEVICE(0x0846, 0x9010) }, 90 { USB_DEVICE(0x0846, 0x9010) },
89 /* Netgear WN111 v2 */ 91 /* Netgear WN111 v2 */
90 { USB_DEVICE(0x0846, 0x9001), .driver_info = CARL9170_ONE_LED }, 92 { USB_DEVICE(0x0846, 0x9001), .driver_info = CARL9170_ONE_LED },
@@ -551,12 +553,12 @@ static int carl9170_usb_flush(struct ar9170 *ar)
551 usb_free_urb(urb); 553 usb_free_urb(urb);
552 } 554 }
553 555
554 ret = usb_wait_anchor_empty_timeout(&ar->tx_cmd, HZ); 556 ret = usb_wait_anchor_empty_timeout(&ar->tx_cmd, 1000);
555 if (ret == 0) 557 if (ret == 0)
556 err = -ETIMEDOUT; 558 err = -ETIMEDOUT;
557 559
558 /* lets wait a while until the tx - queues are dried out */ 560 /* lets wait a while until the tx - queues are dried out */
559 ret = usb_wait_anchor_empty_timeout(&ar->tx_anch, HZ); 561 ret = usb_wait_anchor_empty_timeout(&ar->tx_anch, 1000);
560 if (ret == 0) 562 if (ret == 0)
561 err = -ETIMEDOUT; 563 err = -ETIMEDOUT;
562 564
diff --git a/drivers/net/wireless/b43/sdio.c b/drivers/net/wireless/b43/sdio.c
index 9a55338d957f..09e2dfd7b175 100644
--- a/drivers/net/wireless/b43/sdio.c
+++ b/drivers/net/wireless/b43/sdio.c
@@ -163,6 +163,7 @@ static int b43_sdio_probe(struct sdio_func *func,
163err_free_ssb: 163err_free_ssb:
164 kfree(sdio); 164 kfree(sdio);
165err_disable_func: 165err_disable_func:
166 sdio_claim_host(func);
166 sdio_disable_func(func); 167 sdio_disable_func(func);
167err_release_host: 168err_release_host:
168 sdio_release_host(func); 169 sdio_release_host(func);
diff --git a/drivers/net/wireless/ipw2x00/libipw_module.c b/drivers/net/wireless/ipw2x00/libipw_module.c
index 32dee2ce5d31..d5ef696298ee 100644
--- a/drivers/net/wireless/ipw2x00/libipw_module.c
+++ b/drivers/net/wireless/ipw2x00/libipw_module.c
@@ -54,6 +54,7 @@
54 54
55#define DRV_DESCRIPTION "802.11 data/management/control stack" 55#define DRV_DESCRIPTION "802.11 data/management/control stack"
56#define DRV_NAME "libipw" 56#define DRV_NAME "libipw"
57#define DRV_PROCNAME "ieee80211"
57#define DRV_VERSION LIBIPW_VERSION 58#define DRV_VERSION LIBIPW_VERSION
58#define DRV_COPYRIGHT "Copyright (C) 2004-2005 Intel Corporation <jketreno@linux.intel.com>" 59#define DRV_COPYRIGHT "Copyright (C) 2004-2005 Intel Corporation <jketreno@linux.intel.com>"
59 60
@@ -293,16 +294,16 @@ static int __init libipw_init(void)
293 struct proc_dir_entry *e; 294 struct proc_dir_entry *e;
294 295
295 libipw_debug_level = debug; 296 libipw_debug_level = debug;
296 libipw_proc = proc_mkdir("ieee80211", init_net.proc_net); 297 libipw_proc = proc_mkdir(DRV_PROCNAME, init_net.proc_net);
297 if (libipw_proc == NULL) { 298 if (libipw_proc == NULL) {
298 LIBIPW_ERROR("Unable to create " DRV_NAME 299 LIBIPW_ERROR("Unable to create " DRV_PROCNAME
299 " proc directory\n"); 300 " proc directory\n");
300 return -EIO; 301 return -EIO;
301 } 302 }
302 e = proc_create("debug_level", S_IRUGO | S_IWUSR, libipw_proc, 303 e = proc_create("debug_level", S_IRUGO | S_IWUSR, libipw_proc,
303 &debug_level_proc_fops); 304 &debug_level_proc_fops);
304 if (!e) { 305 if (!e) {
305 remove_proc_entry(DRV_NAME, init_net.proc_net); 306 remove_proc_entry(DRV_PROCNAME, init_net.proc_net);
306 libipw_proc = NULL; 307 libipw_proc = NULL;
307 return -EIO; 308 return -EIO;
308 } 309 }
@@ -319,7 +320,7 @@ static void __exit libipw_exit(void)
319#ifdef CONFIG_LIBIPW_DEBUG 320#ifdef CONFIG_LIBIPW_DEBUG
320 if (libipw_proc) { 321 if (libipw_proc) {
321 remove_proc_entry("debug_level", libipw_proc); 322 remove_proc_entry("debug_level", libipw_proc);
322 remove_proc_entry(DRV_NAME, init_net.proc_net); 323 remove_proc_entry(DRV_PROCNAME, init_net.proc_net);
323 libipw_proc = NULL; 324 libipw_proc = NULL;
324 } 325 }
325#endif /* CONFIG_LIBIPW_DEBUG */ 326#endif /* CONFIG_LIBIPW_DEBUG */
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 8f8c4b73f8b9..7edf8c2fb8c7 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -4000,7 +4000,8 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4000 * "the hard way", rather than using device's scan. 4000 * "the hard way", rather than using device's scan.
4001 */ 4001 */
4002 if (iwl3945_mod_params.disable_hw_scan) { 4002 if (iwl3945_mod_params.disable_hw_scan) {
4003 IWL_ERR(priv, "sw scan support is deprecated\n"); 4003 dev_printk(KERN_DEBUG, &(pdev->dev),
4004 "sw scan support is deprecated\n");
4004 iwl3945_hw_ops.hw_scan = NULL; 4005 iwl3945_hw_ops.hw_scan = NULL;
4005 } 4006 }
4006 4007
diff --git a/drivers/net/wireless/libertas/cfg.c b/drivers/net/wireless/libertas/cfg.c
index 5046a0005034..373930afc26b 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -700,8 +700,9 @@ static void lbs_scan_worker(struct work_struct *work)
700 700
701 if (priv->scan_channel < priv->scan_req->n_channels) { 701 if (priv->scan_channel < priv->scan_req->n_channels) {
702 cancel_delayed_work(&priv->scan_work); 702 cancel_delayed_work(&priv->scan_work);
703 queue_delayed_work(priv->work_thread, &priv->scan_work, 703 if (!priv->stopping)
704 msecs_to_jiffies(300)); 704 queue_delayed_work(priv->work_thread, &priv->scan_work,
705 msecs_to_jiffies(300));
705 } 706 }
706 707
707 /* This is the final data we are about to send */ 708 /* This is the final data we are about to send */
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index f062ed583901..cb14c38caf3a 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -36,6 +36,7 @@ struct lbs_private {
36 /* CFG80211 */ 36 /* CFG80211 */
37 struct wireless_dev *wdev; 37 struct wireless_dev *wdev;
38 bool wiphy_registered; 38 bool wiphy_registered;
39 bool stopping;
39 struct cfg80211_scan_request *scan_req; 40 struct cfg80211_scan_request *scan_req;
40 u8 assoc_bss[ETH_ALEN]; 41 u8 assoc_bss[ETH_ALEN];
41 u8 disassoc_reason; 42 u8 disassoc_reason;
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c
index e5685dc317a8..b4de0ca10feb 100644
--- a/drivers/net/wireless/libertas/if_sdio.c
+++ b/drivers/net/wireless/libertas/if_sdio.c
@@ -1170,7 +1170,6 @@ static void if_sdio_remove(struct sdio_func *func)
1170 lbs_deb_sdio("call remove card\n"); 1170 lbs_deb_sdio("call remove card\n");
1171 lbs_stop_card(card->priv); 1171 lbs_stop_card(card->priv);
1172 lbs_remove_card(card->priv); 1172 lbs_remove_card(card->priv);
1173 card->priv->surpriseremoved = 1;
1174 1173
1175 flush_workqueue(card->workqueue); 1174 flush_workqueue(card->workqueue);
1176 destroy_workqueue(card->workqueue); 1175 destroy_workqueue(card->workqueue);
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index 79bcb4e5d2ca..ecd4d04b2c3c 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -1055,7 +1055,6 @@ static int __devexit libertas_spi_remove(struct spi_device *spi)
1055 lbs_stop_card(priv); 1055 lbs_stop_card(priv);
1056 lbs_remove_card(priv); /* will call free_netdev */ 1056 lbs_remove_card(priv); /* will call free_netdev */
1057 1057
1058 priv->surpriseremoved = 1;
1059 free_irq(spi->irq, card); 1058 free_irq(spi->irq, card);
1060 if_spi_terminate_spi_thread(card); 1059 if_spi_terminate_spi_thread(card);
1061 if (card->pdata->teardown) 1060 if (card->pdata->teardown)
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 47ce5a6ba120..fcd1bbfc632d 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -104,6 +104,7 @@ static int lbs_dev_open(struct net_device *dev)
104 lbs_deb_enter(LBS_DEB_NET); 104 lbs_deb_enter(LBS_DEB_NET);
105 105
106 spin_lock_irq(&priv->driver_lock); 106 spin_lock_irq(&priv->driver_lock);
107 priv->stopping = false;
107 108
108 if (priv->connect_status == LBS_CONNECTED) 109 if (priv->connect_status == LBS_CONNECTED)
109 netif_carrier_on(dev); 110 netif_carrier_on(dev);
@@ -131,10 +132,16 @@ static int lbs_eth_stop(struct net_device *dev)
131 lbs_deb_enter(LBS_DEB_NET); 132 lbs_deb_enter(LBS_DEB_NET);
132 133
133 spin_lock_irq(&priv->driver_lock); 134 spin_lock_irq(&priv->driver_lock);
135 priv->stopping = true;
134 netif_stop_queue(dev); 136 netif_stop_queue(dev);
135 spin_unlock_irq(&priv->driver_lock); 137 spin_unlock_irq(&priv->driver_lock);
136 138
137 schedule_work(&priv->mcast_work); 139 schedule_work(&priv->mcast_work);
140 cancel_delayed_work_sync(&priv->scan_work);
141 if (priv->scan_req) {
142 cfg80211_scan_done(priv->scan_req, false);
143 priv->scan_req = NULL;
144 }
138 145
139 lbs_deb_leave(LBS_DEB_NET); 146 lbs_deb_leave(LBS_DEB_NET);
140 return 0; 147 return 0;
@@ -908,8 +915,6 @@ void lbs_remove_card(struct lbs_private *priv)
908 915
909 lbs_free_adapter(priv); 916 lbs_free_adapter(priv);
910 lbs_cfg_free(priv); 917 lbs_cfg_free(priv);
911
912 priv->dev = NULL;
913 free_netdev(dev); 918 free_netdev(dev);
914 919
915 lbs_deb_leave(LBS_DEB_MAIN); 920 lbs_deb_leave(LBS_DEB_MAIN);
diff --git a/drivers/net/wireless/orinoco/main.c b/drivers/net/wireless/orinoco/main.c
index e8e2d0f4763d..f3d396e7544b 100644
--- a/drivers/net/wireless/orinoco/main.c
+++ b/drivers/net/wireless/orinoco/main.c
@@ -1392,10 +1392,9 @@ static void orinoco_process_scan_results(struct work_struct *work)
1392 orinoco_add_hostscan_results(priv, buf, len); 1392 orinoco_add_hostscan_results(priv, buf, len);
1393 1393
1394 kfree(buf); 1394 kfree(buf);
1395 } else if (priv->scan_request) { 1395 } else {
1396 /* Either abort or complete the scan */ 1396 /* Either abort or complete the scan */
1397 cfg80211_scan_done(priv->scan_request, (len < 0)); 1397 orinoco_scan_done(priv, (len < 0));
1398 priv->scan_request = NULL;
1399 } 1398 }
1400 1399
1401 spin_lock_irqsave(&priv->scan_lock, flags); 1400 spin_lock_irqsave(&priv->scan_lock, flags);
@@ -1684,6 +1683,8 @@ static int __orinoco_down(struct orinoco_private *priv)
1684 hermes_write_regn(hw, EVACK, 0xffff); 1683 hermes_write_regn(hw, EVACK, 0xffff);
1685 } 1684 }
1686 1685
1686 orinoco_scan_done(priv, true);
1687
1687 /* firmware will have to reassociate */ 1688 /* firmware will have to reassociate */
1688 netif_carrier_off(dev); 1689 netif_carrier_off(dev);
1689 priv->last_linkstatus = 0xffff; 1690 priv->last_linkstatus = 0xffff;
@@ -1762,10 +1763,7 @@ void orinoco_reset(struct work_struct *work)
1762 orinoco_unlock(priv, &flags); 1763 orinoco_unlock(priv, &flags);
1763 1764
1764 /* Scanning support: Notify scan cancellation */ 1765 /* Scanning support: Notify scan cancellation */
1765 if (priv->scan_request) { 1766 orinoco_scan_done(priv, true);
1766 cfg80211_scan_done(priv->scan_request, 1);
1767 priv->scan_request = NULL;
1768 }
1769 1767
1770 if (priv->hard_reset) { 1768 if (priv->hard_reset) {
1771 err = (*priv->hard_reset)(priv); 1769 err = (*priv->hard_reset)(priv);
@@ -1813,6 +1811,12 @@ static int __orinoco_commit(struct orinoco_private *priv)
1813 struct net_device *dev = priv->ndev; 1811 struct net_device *dev = priv->ndev;
1814 int err = 0; 1812 int err = 0;
1815 1813
1814 /* If we've called commit, we are reconfiguring or bringing the
1815 * interface up. Maintaining countermeasures across this would
1816 * be confusing, so note that we've disabled them. The port will
1817 * be enabled later in orinoco_commit or __orinoco_up. */
1818 priv->tkip_cm_active = 0;
1819
1816 err = orinoco_hw_program_rids(priv); 1820 err = orinoco_hw_program_rids(priv);
1817 1821
1818 /* FIXME: what about netif_tx_lock */ 1822 /* FIXME: what about netif_tx_lock */
diff --git a/drivers/net/wireless/orinoco/orinoco_cs.c b/drivers/net/wireless/orinoco/orinoco_cs.c
index 71b3d68b9403..32954c4b243a 100644
--- a/drivers/net/wireless/orinoco/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco/orinoco_cs.c
@@ -151,20 +151,20 @@ orinoco_cs_config(struct pcmcia_device *link)
151 goto failed; 151 goto failed;
152 } 152 }
153 153
154 ret = pcmcia_request_irq(link, orinoco_interrupt);
155 if (ret)
156 goto failed;
157
158 /* We initialize the hermes structure before completing PCMCIA
159 * configuration just in case the interrupt handler gets
160 * called. */
161 mem = ioport_map(link->resource[0]->start, 154 mem = ioport_map(link->resource[0]->start,
162 resource_size(link->resource[0])); 155 resource_size(link->resource[0]));
163 if (!mem) 156 if (!mem)
164 goto failed; 157 goto failed;
165 158
159 /* We initialize the hermes structure before completing PCMCIA
160 * configuration just in case the interrupt handler gets
161 * called. */
166 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); 162 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
167 163
164 ret = pcmcia_request_irq(link, orinoco_interrupt);
165 if (ret)
166 goto failed;
167
168 ret = pcmcia_enable_device(link); 168 ret = pcmcia_enable_device(link);
169 if (ret) 169 if (ret)
170 goto failed; 170 goto failed;
diff --git a/drivers/net/wireless/orinoco/orinoco_usb.c b/drivers/net/wireless/orinoco/orinoco_usb.c
index a38a7bd25f19..b9aedf18a046 100644
--- a/drivers/net/wireless/orinoco/orinoco_usb.c
+++ b/drivers/net/wireless/orinoco/orinoco_usb.c
@@ -57,7 +57,6 @@
57#include <linux/fcntl.h> 57#include <linux/fcntl.h>
58#include <linux/spinlock.h> 58#include <linux/spinlock.h>
59#include <linux/list.h> 59#include <linux/list.h>
60#include <linux/smp_lock.h>
61#include <linux/usb.h> 60#include <linux/usb.h>
62#include <linux/timer.h> 61#include <linux/timer.h>
63 62
diff --git a/drivers/net/wireless/orinoco/scan.c b/drivers/net/wireless/orinoco/scan.c
index 4300d9db7d8c..86cb54c842e7 100644
--- a/drivers/net/wireless/orinoco/scan.c
+++ b/drivers/net/wireless/orinoco/scan.c
@@ -229,3 +229,11 @@ void orinoco_add_hostscan_results(struct orinoco_private *priv,
229 priv->scan_request = NULL; 229 priv->scan_request = NULL;
230 } 230 }
231} 231}
232
233void orinoco_scan_done(struct orinoco_private *priv, bool abort)
234{
235 if (priv->scan_request) {
236 cfg80211_scan_done(priv->scan_request, abort);
237 priv->scan_request = NULL;
238 }
239}
diff --git a/drivers/net/wireless/orinoco/scan.h b/drivers/net/wireless/orinoco/scan.h
index 2dc4e046dbdb..27281fb0a6dc 100644
--- a/drivers/net/wireless/orinoco/scan.h
+++ b/drivers/net/wireless/orinoco/scan.h
@@ -16,5 +16,6 @@ void orinoco_add_extscan_result(struct orinoco_private *priv,
16void orinoco_add_hostscan_results(struct orinoco_private *dev, 16void orinoco_add_hostscan_results(struct orinoco_private *dev,
17 unsigned char *buf, 17 unsigned char *buf,
18 size_t len); 18 size_t len);
19void orinoco_scan_done(struct orinoco_private *priv, bool abort);
19 20
20#endif /* _ORINOCO_SCAN_H_ */ 21#endif /* _ORINOCO_SCAN_H_ */
diff --git a/drivers/net/wireless/orinoco/spectrum_cs.c b/drivers/net/wireless/orinoco/spectrum_cs.c
index fb859a5ad2eb..db34c282e59b 100644
--- a/drivers/net/wireless/orinoco/spectrum_cs.c
+++ b/drivers/net/wireless/orinoco/spectrum_cs.c
@@ -214,21 +214,21 @@ spectrum_cs_config(struct pcmcia_device *link)
214 goto failed; 214 goto failed;
215 } 215 }
216 216
217 ret = pcmcia_request_irq(link, orinoco_interrupt);
218 if (ret)
219 goto failed;
220
221 /* We initialize the hermes structure before completing PCMCIA
222 * configuration just in case the interrupt handler gets
223 * called. */
224 mem = ioport_map(link->resource[0]->start, 217 mem = ioport_map(link->resource[0]->start,
225 resource_size(link->resource[0])); 218 resource_size(link->resource[0]));
226 if (!mem) 219 if (!mem)
227 goto failed; 220 goto failed;
228 221
222 /* We initialize the hermes structure before completing PCMCIA
223 * configuration just in case the interrupt handler gets
224 * called. */
229 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); 225 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
230 hw->eeprom_pda = true; 226 hw->eeprom_pda = true;
231 227
228 ret = pcmcia_request_irq(link, orinoco_interrupt);
229 if (ret)
230 goto failed;
231
232 ret = pcmcia_enable_device(link); 232 ret = pcmcia_enable_device(link);
233 if (ret) 233 if (ret)
234 goto failed; 234 goto failed;
diff --git a/drivers/net/wireless/orinoco/wext.c b/drivers/net/wireless/orinoco/wext.c
index 93505f93bf97..e5afabee60d1 100644
--- a/drivers/net/wireless/orinoco/wext.c
+++ b/drivers/net/wireless/orinoco/wext.c
@@ -911,10 +911,10 @@ static int orinoco_ioctl_set_auth(struct net_device *dev,
911 */ 911 */
912 if (param->value) { 912 if (param->value) {
913 priv->tkip_cm_active = 1; 913 priv->tkip_cm_active = 1;
914 ret = hermes_enable_port(hw, 0); 914 ret = hermes_disable_port(hw, 0);
915 } else { 915 } else {
916 priv->tkip_cm_active = 0; 916 priv->tkip_cm_active = 0;
917 ret = hermes_disable_port(hw, 0); 917 ret = hermes_enable_port(hw, 0);
918 } 918 }
919 break; 919 break;
920 920
diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig
index eea1ef2f502b..4396d4b9bfb9 100644
--- a/drivers/net/wireless/rt2x00/Kconfig
+++ b/drivers/net/wireless/rt2x00/Kconfig
@@ -221,9 +221,6 @@ config RT2X00_LIB_LEDS
221 boolean 221 boolean
222 default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n) 222 default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n)
223 223
224comment "rt2x00 leds support disabled due to modularized LEDS_CLASS and built-in rt2x00"
225 depends on RT2X00_LIB=y && LEDS_CLASS=m
226
227config RT2X00_LIB_DEBUGFS 224config RT2X00_LIB_DEBUGFS
228 bool "Ralink debugfs support" 225 bool "Ralink debugfs support"
229 depends on RT2X00_LIB && MAC80211_DEBUGFS 226 depends on RT2X00_LIB && MAC80211_DEBUGFS
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 458bb57914a3..cdbeec9f83ea 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -66,8 +66,8 @@ struct netfront_cb {
66 66
67#define GRANT_INVALID_REF 0 67#define GRANT_INVALID_REF 0
68 68
69#define NET_TX_RING_SIZE __RING_SIZE((struct xen_netif_tx_sring *)0, PAGE_SIZE) 69#define NET_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE)
70#define NET_RX_RING_SIZE __RING_SIZE((struct xen_netif_rx_sring *)0, PAGE_SIZE) 70#define NET_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)
71#define TX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256) 71#define TX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
72 72
73struct netfront_info { 73struct netfront_info {
diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c
index d9f51485beee..9383063d2b16 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -349,7 +349,6 @@ static struct irq_chip dino_interrupt_type = {
349 .name = "GSC-PCI", 349 .name = "GSC-PCI",
350 .unmask = dino_unmask_irq, 350 .unmask = dino_unmask_irq,
351 .mask = dino_mask_irq, 351 .mask = dino_mask_irq,
352 .ack = no_ack_irq,
353}; 352};
354 353
355 354
diff --git a/drivers/parisc/eisa.c b/drivers/parisc/eisa.c
index 1211974f55aa..e860038b0b84 100644
--- a/drivers/parisc/eisa.c
+++ b/drivers/parisc/eisa.c
@@ -186,7 +186,6 @@ static struct irq_chip eisa_interrupt_type = {
186 .name = "EISA", 186 .name = "EISA",
187 .unmask = eisa_unmask_irq, 187 .unmask = eisa_unmask_irq,
188 .mask = eisa_mask_irq, 188 .mask = eisa_mask_irq,
189 .ack = no_ack_irq,
190}; 189};
191 190
192static irqreturn_t eisa_irq(int wax_irq, void *intr_dev) 191static irqreturn_t eisa_irq(int wax_irq, void *intr_dev)
@@ -340,7 +339,7 @@ static int __init eisa_probe(struct parisc_device *dev)
340 setup_irq(2, &irq2_action); 339 setup_irq(2, &irq2_action);
341 for (i = 0; i < 16; i++) { 340 for (i = 0; i < 16; i++) {
342 set_irq_chip_and_handler(i, &eisa_interrupt_type, 341 set_irq_chip_and_handler(i, &eisa_interrupt_type,
343 handle_level_irq); 342 handle_simple_irq);
344 } 343 }
345 344
346 EISA_bus = 1; 345 EISA_bus = 1;
diff --git a/drivers/parisc/eisa_eeprom.c b/drivers/parisc/eisa_eeprom.c
index cce00ed81f37..af212c6a6158 100644
--- a/drivers/parisc/eisa_eeprom.c
+++ b/drivers/parisc/eisa_eeprom.c
@@ -24,7 +24,6 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/miscdevice.h> 25#include <linux/miscdevice.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/smp_lock.h>
28#include <linux/fs.h> 27#include <linux/fs.h>
29#include <asm/io.h> 28#include <asm/io.h>
30#include <asm/uaccess.h> 29#include <asm/uaccess.h>
diff --git a/drivers/parisc/gsc.c b/drivers/parisc/gsc.c
index e605298e3aee..772b1939ac21 100644
--- a/drivers/parisc/gsc.c
+++ b/drivers/parisc/gsc.c
@@ -143,7 +143,6 @@ static struct irq_chip gsc_asic_interrupt_type = {
143 .name = "GSC-ASIC", 143 .name = "GSC-ASIC",
144 .unmask = gsc_asic_unmask_irq, 144 .unmask = gsc_asic_unmask_irq,
145 .mask = gsc_asic_mask_irq, 145 .mask = gsc_asic_mask_irq,
146 .ack = no_ack_irq,
147}; 146};
148 147
149int gsc_assign_irq(struct irq_chip *type, void *data) 148int gsc_assign_irq(struct irq_chip *type, void *data)
@@ -153,7 +152,7 @@ int gsc_assign_irq(struct irq_chip *type, void *data)
153 if (irq > GSC_IRQ_MAX) 152 if (irq > GSC_IRQ_MAX)
154 return NO_IRQ; 153 return NO_IRQ;
155 154
156 set_irq_chip_and_handler(irq, type, handle_level_irq); 155 set_irq_chip_and_handler(irq, type, handle_simple_irq);
157 set_irq_chip_data(irq, data); 156 set_irq_chip_data(irq, data);
158 157
159 return irq++; 158 return irq++;
diff --git a/drivers/parisc/iosapic.c b/drivers/parisc/iosapic.c
index a3120a09c43d..0327894bf235 100644
--- a/drivers/parisc/iosapic.c
+++ b/drivers/parisc/iosapic.c
@@ -669,6 +669,13 @@ printk("\n");
669 DBG(KERN_DEBUG "enable_irq(%d): eoi(%p, 0x%x)\n", irq, 669 DBG(KERN_DEBUG "enable_irq(%d): eoi(%p, 0x%x)\n", irq,
670 vi->eoi_addr, vi->eoi_data); 670 vi->eoi_addr, vi->eoi_data);
671 iosapic_eoi(vi->eoi_addr, vi->eoi_data); 671 iosapic_eoi(vi->eoi_addr, vi->eoi_data);
672}
673
674static void iosapic_eoi_irq(unsigned int irq)
675{
676 struct vector_info *vi = get_irq_chip_data(irq);
677
678 iosapic_eoi(vi->eoi_addr, vi->eoi_data);
672 cpu_eoi_irq(irq); 679 cpu_eoi_irq(irq);
673} 680}
674 681
@@ -705,6 +712,7 @@ static struct irq_chip iosapic_interrupt_type = {
705 .unmask = iosapic_unmask_irq, 712 .unmask = iosapic_unmask_irq,
706 .mask = iosapic_mask_irq, 713 .mask = iosapic_mask_irq,
707 .ack = cpu_ack_irq, 714 .ack = cpu_ack_irq,
715 .eoi = iosapic_eoi_irq,
708#ifdef CONFIG_SMP 716#ifdef CONFIG_SMP
709 .set_affinity = iosapic_set_affinity_irq, 717 .set_affinity = iosapic_set_affinity_irq,
710#endif 718#endif
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 2350e8a86eef..f2f501e5b6a0 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -64,6 +64,7 @@ static unsigned int led_diskio __read_mostly = 1;
64static unsigned int led_lanrxtx __read_mostly = 1; 64static unsigned int led_lanrxtx __read_mostly = 1;
65static char lcd_text[32] __read_mostly; 65static char lcd_text[32] __read_mostly;
66static char lcd_text_default[32] __read_mostly; 66static char lcd_text_default[32] __read_mostly;
67static int lcd_no_led_support __read_mostly = 0; /* KittyHawk doesn't support LED on its LCD */
67 68
68 69
69static struct workqueue_struct *led_wq; 70static struct workqueue_struct *led_wq;
@@ -115,7 +116,7 @@ lcd_info __attribute__((aligned(8))) __read_mostly =
115 .lcd_width = 16, 116 .lcd_width = 16,
116 .lcd_cmd_reg_addr = KITTYHAWK_LCD_CMD, 117 .lcd_cmd_reg_addr = KITTYHAWK_LCD_CMD,
117 .lcd_data_reg_addr = KITTYHAWK_LCD_DATA, 118 .lcd_data_reg_addr = KITTYHAWK_LCD_DATA,
118 .min_cmd_delay = 40, 119 .min_cmd_delay = 80,
119 .reset_cmd1 = 0x80, 120 .reset_cmd1 = 0x80,
120 .reset_cmd2 = 0xc0, 121 .reset_cmd2 = 0xc0,
121}; 122};
@@ -135,6 +136,9 @@ static int start_task(void)
135 /* Display the default text now */ 136 /* Display the default text now */
136 if (led_type == LED_HASLCD) lcd_print( lcd_text_default ); 137 if (led_type == LED_HASLCD) lcd_print( lcd_text_default );
137 138
139 /* KittyHawk has no LED support on its LCD */
140 if (lcd_no_led_support) return 0;
141
138 /* Create the work queue and queue the LED task */ 142 /* Create the work queue and queue the LED task */
139 led_wq = create_singlethread_workqueue("led_wq"); 143 led_wq = create_singlethread_workqueue("led_wq");
140 queue_delayed_work(led_wq, &led_task, 0); 144 queue_delayed_work(led_wq, &led_task, 0);
@@ -248,9 +252,13 @@ static int __init led_create_procfs(void)
248 252
249 proc_pdc_root = proc_mkdir("pdc", 0); 253 proc_pdc_root = proc_mkdir("pdc", 0);
250 if (!proc_pdc_root) return -1; 254 if (!proc_pdc_root) return -1;
251 ent = proc_create_data("led", S_IRUGO|S_IWUSR, proc_pdc_root, 255
252 &led_proc_fops, (void *)LED_NOLCD); /* LED */ 256 if (!lcd_no_led_support)
253 if (!ent) return -1; 257 {
258 ent = proc_create_data("led", S_IRUGO|S_IWUSR, proc_pdc_root,
259 &led_proc_fops, (void *)LED_NOLCD); /* LED */
260 if (!ent) return -1;
261 }
254 262
255 if (led_type == LED_HASLCD) 263 if (led_type == LED_HASLCD)
256 { 264 {
@@ -692,6 +700,7 @@ int __init led_init(void)
692 case 0x58B: /* KittyHawk DC2 100 (K200) */ 700 case 0x58B: /* KittyHawk DC2 100 (K200) */
693 printk(KERN_INFO "%s: KittyHawk-Machine (hversion 0x%x) found, " 701 printk(KERN_INFO "%s: KittyHawk-Machine (hversion 0x%x) found, "
694 "LED detection skipped.\n", __FILE__, CPU_HVERSION); 702 "LED detection skipped.\n", __FILE__, CPU_HVERSION);
703 lcd_no_led_support = 1;
695 goto found; /* use the preinitialized values of lcd_info */ 704 goto found; /* use the preinitialized values of lcd_info */
696 } 705 }
697 706
diff --git a/drivers/parisc/superio.c b/drivers/parisc/superio.c
index 0846dafdfff1..28241532c0fd 100644
--- a/drivers/parisc/superio.c
+++ b/drivers/parisc/superio.c
@@ -323,7 +323,6 @@ static struct irq_chip superio_interrupt_type = {
323 .name = SUPERIO, 323 .name = SUPERIO,
324 .unmask = superio_unmask_irq, 324 .unmask = superio_unmask_irq,
325 .mask = superio_mask_irq, 325 .mask = superio_mask_irq,
326 .ack = no_ack_irq,
327}; 326};
328 327
329#ifdef DEBUG_SUPERIO_INIT 328#ifdef DEBUG_SUPERIO_INIT
@@ -354,7 +353,7 @@ int superio_fixup_irq(struct pci_dev *pcidev)
354#endif 353#endif
355 354
356 for (i = 0; i < 16; i++) { 355 for (i = 0; i < 16; i++) {
357 set_irq_chip_and_handler(i, &superio_interrupt_type, handle_level_irq); 356 set_irq_chip_and_handler(i, &superio_interrupt_type, handle_simple_irq);
358 } 357 }
359 358
360 /* 359 /*
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index f01e344cf4bd..98e6fdf34d30 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -49,6 +49,7 @@ obj-$(CONFIG_MIPS) += setup-bus.o setup-irq.o
49obj-$(CONFIG_X86_VISWS) += setup-irq.o 49obj-$(CONFIG_X86_VISWS) += setup-irq.o
50obj-$(CONFIG_MN10300) += setup-bus.o 50obj-$(CONFIG_MN10300) += setup-bus.o
51obj-$(CONFIG_MICROBLAZE) += setup-bus.o 51obj-$(CONFIG_MICROBLAZE) += setup-bus.o
52obj-$(CONFIG_TILE) += setup-bus.o setup-irq.o
52 53
53# 54#
54# ACPI Related PCI FW Functions 55# ACPI Related PCI FW Functions
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 5624db8c9ad0..69546e9213dd 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -64,49 +64,6 @@ void pci_bus_remove_resources(struct pci_bus *bus)
64 } 64 }
65} 65}
66 66
67/*
68 * Find the highest-address bus resource below the cursor "res". If the
69 * cursor is NULL, return the highest resource.
70 */
71static struct resource *pci_bus_find_resource_prev(struct pci_bus *bus,
72 unsigned int type,
73 struct resource *res)
74{
75 struct resource *r, *prev = NULL;
76 int i;
77
78 pci_bus_for_each_resource(bus, r, i) {
79 if (!r)
80 continue;
81
82 if ((r->flags & IORESOURCE_TYPE_BITS) != type)
83 continue;
84
85 /* If this resource is at or past the cursor, skip it */
86 if (res) {
87 if (r == res)
88 continue;
89 if (r->end > res->end)
90 continue;
91 if (r->end == res->end && r->start > res->start)
92 continue;
93 }
94
95 if (!prev)
96 prev = r;
97
98 /*
99 * A small resource is higher than a large one that ends at
100 * the same address.
101 */
102 if (r->end > prev->end ||
103 (r->end == prev->end && r->start > prev->start))
104 prev = r;
105 }
106
107 return prev;
108}
109
110/** 67/**
111 * pci_bus_alloc_resource - allocate a resource from a parent bus 68 * pci_bus_alloc_resource - allocate a resource from a parent bus
112 * @bus: PCI bus 69 * @bus: PCI bus
@@ -132,10 +89,9 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
132 resource_size_t), 89 resource_size_t),
133 void *alignf_data) 90 void *alignf_data)
134{ 91{
135 int ret = -ENOMEM; 92 int i, ret = -ENOMEM;
136 struct resource *r; 93 struct resource *r;
137 resource_size_t max = -1; 94 resource_size_t max = -1;
138 unsigned int type = res->flags & IORESOURCE_TYPE_BITS;
139 95
140 type_mask |= IORESOURCE_IO | IORESOURCE_MEM; 96 type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
141 97
@@ -143,9 +99,10 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
143 if (!(res->flags & IORESOURCE_MEM_64)) 99 if (!(res->flags & IORESOURCE_MEM_64))
144 max = PCIBIOS_MAX_MEM_32; 100 max = PCIBIOS_MAX_MEM_32;
145 101
146 /* Look for space at highest addresses first */ 102 pci_bus_for_each_resource(bus, r, i) {
147 r = pci_bus_find_resource_prev(bus, type, NULL); 103 if (!r)
148 for ( ; r; r = pci_bus_find_resource_prev(bus, type, r)) { 104 continue;
105
149 /* type_mask must match */ 106 /* type_mask must match */
150 if ((res->flags ^ r->flags) & type_mask) 107 if ((res->flags ^ r->flags) & type_mask)
151 continue; 108 continue;
diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
index 0157708d474d..09933eb9126b 100644
--- a/drivers/pci/dmar.c
+++ b/drivers/pci/dmar.c
@@ -1417,6 +1417,11 @@ int __init enable_drhd_fault_handling(void)
1417 (unsigned long long)drhd->reg_base_addr, ret); 1417 (unsigned long long)drhd->reg_base_addr, ret);
1418 return -1; 1418 return -1;
1419 } 1419 }
1420
1421 /*
1422 * Clear any previous faults.
1423 */
1424 dmar_fault(iommu->irq, iommu);
1420 } 1425 }
1421 1426
1422 return 0; 1427 return 0;
diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c
index 5becbdee4027..2850e64dedae 100644
--- a/drivers/pci/hotplug/ibmphp_ebda.c
+++ b/drivers/pci/hotplug/ibmphp_ebda.c
@@ -276,6 +276,12 @@ int __init ibmphp_access_ebda (void)
276 276
277 for (;;) { 277 for (;;) {
278 offset = next_offset; 278 offset = next_offset;
279
280 /* Make sure what we read is still in the mapped section */
281 if (WARN(offset > (ebda_sz * 1024 - 4),
282 "ibmphp_ebda: next read is beyond ebda_sz\n"))
283 break;
284
279 next_offset = readw (io_mem + offset); /* offset of next blk */ 285 next_offset = readw (io_mem + offset); /* offset of next blk */
280 286
281 offset += 2; 287 offset += 2;
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index b5a7d9bfcb24..63d5042f2079 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -705,17 +705,21 @@ void pci_remove_legacy_files(struct pci_bus *b)
705 705
706#ifdef HAVE_PCI_MMAP 706#ifdef HAVE_PCI_MMAP
707 707
708int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma) 708int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
709 enum pci_mmap_api mmap_api)
709{ 710{
710 unsigned long nr, start, size; 711 unsigned long nr, start, size, pci_start;
711 712
713 if (pci_resource_len(pdev, resno) == 0)
714 return 0;
712 nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; 715 nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
713 start = vma->vm_pgoff; 716 start = vma->vm_pgoff;
714 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1; 717 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
715 if (start < size && size - start >= nr) 718 pci_start = (mmap_api == PCI_MMAP_PROCFS) ?
719 pci_resource_start(pdev, resno) >> PAGE_SHIFT : 0;
720 if (start >= pci_start && start < pci_start + size &&
721 start + nr <= pci_start + size)
716 return 1; 722 return 1;
717 WARN(1, "process \"%s\" tried to map 0x%08lx-0x%08lx on %s BAR %d (size 0x%08lx)\n",
718 current->comm, start, start+nr, pci_name(pdev), resno, size);
719 return 0; 723 return 0;
720} 724}
721 725
@@ -745,8 +749,15 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
745 if (i >= PCI_ROM_RESOURCE) 749 if (i >= PCI_ROM_RESOURCE)
746 return -ENODEV; 750 return -ENODEV;
747 751
748 if (!pci_mmap_fits(pdev, i, vma)) 752 if (!pci_mmap_fits(pdev, i, vma, PCI_MMAP_SYSFS)) {
753 WARN(1, "process \"%s\" tried to map 0x%08lx bytes "
754 "at page 0x%08lx on %s BAR %d (start 0x%16Lx, size 0x%16Lx)\n",
755 current->comm, vma->vm_end-vma->vm_start, vma->vm_pgoff,
756 pci_name(pdev), i,
757 (u64)pci_resource_start(pdev, i),
758 (u64)pci_resource_len(pdev, i));
749 return -EINVAL; 759 return -EINVAL;
760 }
750 761
751 /* pci_mmap_page_range() expects the same kind of entry as coming 762 /* pci_mmap_page_range() expects the same kind of entry as coming
752 * from /proc/bus/pci/ which is a "user visible" value. If this is 763 * from /proc/bus/pci/ which is a "user visible" value. If this is
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e98c8104297b..710c8a29be0d 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1007,6 +1007,18 @@ static int __pci_enable_device_flags(struct pci_dev *dev,
1007 int err; 1007 int err;
1008 int i, bars = 0; 1008 int i, bars = 0;
1009 1009
1010 /*
1011 * Power state could be unknown at this point, either due to a fresh
1012 * boot or a device removal call. So get the current power state
1013 * so that things like MSI message writing will behave as expected
1014 * (e.g. if the device really is in D0 at enable time).
1015 */
1016 if (dev->pm_cap) {
1017 u16 pmcsr;
1018 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
1019 dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
1020 }
1021
1010 if (atomic_add_return(1, &dev->enable_cnt) > 1) 1022 if (atomic_add_return(1, &dev->enable_cnt) > 1)
1011 return 0; /* already enabled */ 1023 return 0; /* already enabled */
1012 1024
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index f5c7c382765f..7d33f6673868 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -22,8 +22,13 @@ extern void pci_remove_firmware_label_files(struct pci_dev *pdev);
22#endif 22#endif
23extern void pci_cleanup_rom(struct pci_dev *dev); 23extern void pci_cleanup_rom(struct pci_dev *dev);
24#ifdef HAVE_PCI_MMAP 24#ifdef HAVE_PCI_MMAP
25enum pci_mmap_api {
26 PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
27 PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */
28};
25extern int pci_mmap_fits(struct pci_dev *pdev, int resno, 29extern int pci_mmap_fits(struct pci_dev *pdev, int resno,
26 struct vm_area_struct *vma); 30 struct vm_area_struct *vmai,
31 enum pci_mmap_api mmap_api);
27#endif 32#endif
28int pci_probe_reset_function(struct pci_dev *dev); 33int pci_probe_reset_function(struct pci_dev *dev);
29 34
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 297b72c880a1..27911b55c2a5 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -10,7 +10,6 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/proc_fs.h> 11#include <linux/proc_fs.h>
12#include <linux/seq_file.h> 12#include <linux/seq_file.h>
13#include <linux/smp_lock.h>
14#include <linux/capability.h> 13#include <linux/capability.h>
15#include <asm/uaccess.h> 14#include <asm/uaccess.h>
16#include <asm/byteorder.h> 15#include <asm/byteorder.h>
@@ -257,7 +256,7 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)
257 256
258 /* Make sure the caller is mapping a real resource for this device */ 257 /* Make sure the caller is mapping a real resource for this device */
259 for (i = 0; i < PCI_ROM_RESOURCE; i++) { 258 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
260 if (pci_mmap_fits(dev, i, vma)) 259 if (pci_mmap_fits(dev, i, vma, PCI_MMAP_PROCFS))
261 break; 260 break;
262 } 261 }
263 262
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index f5c63fe9db5c..53a786fd0d40 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -2136,6 +2136,24 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB,
2136DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82875_HB, 2136DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82875_HB,
2137 quirk_unhide_mch_dev6); 2137 quirk_unhide_mch_dev6);
2138 2138
2139#ifdef CONFIG_TILE
2140/*
2141 * The Tilera TILEmpower platform needs to set the link speed
2142 * to 2.5GT(Giga-Transfers)/s (Gen 1). The default link speed
2143 * setting is 5GT/s (Gen 2). 0x98 is the Link Control2 PCIe
2144 * capability register of the PEX8624 PCIe switch. The switch
2145 * supports link speed auto negotiation, but falsely sets
2146 * the link speed to 5GT/s.
2147 */
2148static void __devinit quirk_tile_plx_gen1(struct pci_dev *dev)
2149{
2150 if (tile_plx_gen1) {
2151 pci_write_config_dword(dev, 0x98, 0x1);
2152 mdelay(50);
2153 }
2154}
2155DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8624, quirk_tile_plx_gen1);
2156#endif /* CONFIG_TILE */
2139 2157
2140#ifdef CONFIG_PCI_MSI 2158#ifdef CONFIG_PCI_MSI
2141/* Some chipsets do not support MSI. We cannot easily rely on setting 2159/* Some chipsets do not support MSI. We cannot easily rely on setting
@@ -2311,6 +2329,9 @@ static void __devinit nvbridge_check_legacy_irq_routing(struct pci_dev *dev)
2311{ 2329{
2312 u32 cfg; 2330 u32 cfg;
2313 2331
2332 if (!pci_find_capability(dev, PCI_CAP_ID_HT))
2333 return;
2334
2314 pci_read_config_dword(dev, 0x74, &cfg); 2335 pci_read_config_dword(dev, 0x74, &cfg);
2315 2336
2316 if (cfg & ((1 << 2) | (1 << 15))) { 2337 if (cfg & ((1 << 2) | (1 << 15))) {
@@ -2746,6 +2767,29 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_m
2746DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832); 2767DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
2747#endif /*CONFIG_MMC_RICOH_MMC*/ 2768#endif /*CONFIG_MMC_RICOH_MMC*/
2748 2769
2770#if defined(CONFIG_DMAR) || defined(CONFIG_INTR_REMAP)
2771#define VTUNCERRMSK_REG 0x1ac
2772#define VTD_MSK_SPEC_ERRORS (1 << 31)
2773/*
2774 * This is a quirk for masking vt-d spec defined errors to platform error
2775 * handling logic. With out this, platforms using Intel 7500, 5500 chipsets
2776 * (and the derivative chipsets like X58 etc) seem to generate NMI/SMI (based
2777 * on the RAS config settings of the platform) when a vt-d fault happens.
2778 * The resulting SMI caused the system to hang.
2779 *
2780 * VT-d spec related errors are already handled by the VT-d OS code, so no
2781 * need to report the same error through other channels.
2782 */
2783static void vtd_mask_spec_errors(struct pci_dev *dev)
2784{
2785 u32 word;
2786
2787 pci_read_config_dword(dev, VTUNCERRMSK_REG, &word);
2788 pci_write_config_dword(dev, VTUNCERRMSK_REG, word | VTD_MSK_SPEC_ERRORS);
2789}
2790DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x342e, vtd_mask_spec_errors);
2791DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x3c28, vtd_mask_spec_errors);
2792#endif
2749 2793
2750static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, 2794static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
2751 struct pci_fixup *end) 2795 struct pci_fixup *end)
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index a87c4985326e..3a5a6fcc0ead 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -13,7 +13,6 @@
13#include <linux/spinlock.h> 13#include <linux/spinlock.h>
14#include <linux/pci.h> 14#include <linux/pci.h>
15#include <linux/msi.h> 15#include <linux/msi.h>
16#include <xen/xenbus.h>
17#include <xen/interface/io/pciif.h> 16#include <xen/interface/io/pciif.h>
18#include <asm/xen/pci.h> 17#include <asm/xen/pci.h>
19#include <linux/interrupt.h> 18#include <linux/interrupt.h>
@@ -576,8 +575,9 @@ static pci_ers_result_t pcifront_common_process(int cmd,
576 575
577 pcidev = pci_get_bus_and_slot(bus, devfn); 576 pcidev = pci_get_bus_and_slot(bus, devfn);
578 if (!pcidev || !pcidev->driver) { 577 if (!pcidev || !pcidev->driver) {
579 dev_err(&pcidev->dev, 578 dev_err(&pdev->xdev->dev, "device or AER driver is NULL\n");
580 "device or driver is NULL\n"); 579 if (pcidev)
580 pci_dev_put(pcidev);
581 return result; 581 return result;
582 } 582 }
583 pdrv = pcidev->driver; 583 pdrv = pcidev->driver;
diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c
index 8cbfa067171f..96c72e90b79c 100644
--- a/drivers/pcmcia/pd6729.c
+++ b/drivers/pcmcia/pd6729.c
@@ -725,17 +725,17 @@ static int __devinit pd6729_pci_probe(struct pci_dev *dev,
725 725
726 return 0; 726 return 0;
727 727
728 err_out_free_res2: 728err_out_free_res2:
729 if (irq_mode == 1) 729 if (irq_mode == 1)
730 free_irq(dev->irq, socket); 730 free_irq(dev->irq, socket);
731 else 731 else
732 del_timer_sync(&socket->poll_timer); 732 del_timer_sync(&socket->poll_timer);
733 err_out_free_res: 733err_out_free_res:
734 pci_release_regions(dev); 734 pci_release_regions(dev);
735 err_out_disable: 735err_out_disable:
736 pci_disable_device(dev); 736 pci_disable_device(dev);
737 737
738 err_out_free_mem: 738err_out_free_mem:
739 kfree(socket); 739 kfree(socket);
740 return ret; 740 return ret;
741} 741}
diff --git a/drivers/pcmcia/pd6729.h b/drivers/pcmcia/pd6729.h
index 41418d394c55..c8e84bdece38 100644
--- a/drivers/pcmcia/pd6729.h
+++ b/drivers/pcmcia/pd6729.h
@@ -15,7 +15,7 @@
15struct pd6729_socket { 15struct pd6729_socket {
16 int number; 16 int number;
17 int card_irq; 17 int card_irq;
18 unsigned long io_base; /* base io address of the socket */ 18 unsigned long io_base; /* base io address of the socket */
19 struct pcmcia_socket socket; 19 struct pcmcia_socket socket;
20 struct timer_list poll_timer; 20 struct timer_list poll_timer;
21}; 21};
diff --git a/drivers/pcmcia/pxa2xx_sharpsl.c b/drivers/pcmcia/pxa2xx_sharpsl.c
index 0ea3b29440e6..81af2b3bcc00 100644
--- a/drivers/pcmcia/pxa2xx_sharpsl.c
+++ b/drivers/pcmcia/pxa2xx_sharpsl.c
@@ -237,7 +237,7 @@ static struct pcmcia_low_level sharpsl_pcmcia_ops __initdata = {
237#ifdef CONFIG_SA1100_COLLIE 237#ifdef CONFIG_SA1100_COLLIE
238#include "sa11xx_base.h" 238#include "sa11xx_base.h"
239 239
240int __init pcmcia_collie_init(struct device *dev) 240int __devinit pcmcia_collie_init(struct device *dev)
241{ 241{
242 int ret = -ENODEV; 242 int ret = -ENODEV;
243 243
diff --git a/drivers/pcmcia/sa1100_assabet.c b/drivers/pcmcia/sa1100_assabet.c
index fd013a1ef47a..f1e882272ab0 100644
--- a/drivers/pcmcia/sa1100_assabet.c
+++ b/drivers/pcmcia/sa1100_assabet.c
@@ -130,7 +130,7 @@ static struct pcmcia_low_level assabet_pcmcia_ops = {
130 .socket_suspend = assabet_pcmcia_socket_suspend, 130 .socket_suspend = assabet_pcmcia_socket_suspend,
131}; 131};
132 132
133int pcmcia_assabet_init(struct device *dev) 133int __devinit pcmcia_assabet_init(struct device *dev)
134{ 134{
135 int ret = -ENODEV; 135 int ret = -ENODEV;
136 136
diff --git a/drivers/pcmcia/sa1100_cerf.c b/drivers/pcmcia/sa1100_cerf.c
index 9bf088b17275..30560df8c76b 100644
--- a/drivers/pcmcia/sa1100_cerf.c
+++ b/drivers/pcmcia/sa1100_cerf.c
@@ -97,7 +97,7 @@ static struct pcmcia_low_level cerf_pcmcia_ops = {
97 .socket_suspend = cerf_pcmcia_socket_suspend, 97 .socket_suspend = cerf_pcmcia_socket_suspend,
98}; 98};
99 99
100int __init pcmcia_cerf_init(struct device *dev) 100int __devinit pcmcia_cerf_init(struct device *dev)
101{ 101{
102 int ret = -ENODEV; 102 int ret = -ENODEV;
103 103
diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c
index 945857f8c284..6b228590b3fd 100644
--- a/drivers/pcmcia/sa1100_generic.c
+++ b/drivers/pcmcia/sa1100_generic.c
@@ -64,7 +64,7 @@ static int (*sa11x0_pcmcia_hw_init[])(struct device *dev) = {
64#endif 64#endif
65}; 65};
66 66
67static int sa11x0_drv_pcmcia_probe(struct platform_device *dev) 67static int __devinit sa11x0_drv_pcmcia_probe(struct platform_device *dev)
68{ 68{
69 int i, ret = -ENODEV; 69 int i, ret = -ENODEV;
70 70
diff --git a/drivers/pcmcia/sa1100_h3600.c b/drivers/pcmcia/sa1100_h3600.c
index 56329ad575a9..edf8f0028898 100644
--- a/drivers/pcmcia/sa1100_h3600.c
+++ b/drivers/pcmcia/sa1100_h3600.c
@@ -219,7 +219,7 @@ struct pcmcia_low_level h3600_pcmcia_ops = {
219 .socket_suspend = h3600_pcmcia_socket_suspend, 219 .socket_suspend = h3600_pcmcia_socket_suspend,
220}; 220};
221 221
222int __init pcmcia_h3600_init(struct device *dev) 222int __devinit pcmcia_h3600_init(struct device *dev)
223{ 223{
224 int ret = -ENODEV; 224 int ret = -ENODEV;
225 225
diff --git a/drivers/pcmcia/sa1100_shannon.c b/drivers/pcmcia/sa1100_shannon.c
index c4d51867a050..7ff1b43540b8 100644
--- a/drivers/pcmcia/sa1100_shannon.c
+++ b/drivers/pcmcia/sa1100_shannon.c
@@ -113,7 +113,7 @@ static struct pcmcia_low_level shannon_pcmcia_ops = {
113 .socket_suspend = shannon_pcmcia_socket_suspend, 113 .socket_suspend = shannon_pcmcia_socket_suspend,
114}; 114};
115 115
116int __init pcmcia_shannon_init(struct device *dev) 116int __devinit pcmcia_shannon_init(struct device *dev)
117{ 117{
118 int ret = -ENODEV; 118 int ret = -ENODEV;
119 119
diff --git a/drivers/pcmcia/sa1100_simpad.c b/drivers/pcmcia/sa1100_simpad.c
index 05bd504e6f18..c998f7aaadbc 100644
--- a/drivers/pcmcia/sa1100_simpad.c
+++ b/drivers/pcmcia/sa1100_simpad.c
@@ -123,7 +123,7 @@ static struct pcmcia_low_level simpad_pcmcia_ops = {
123 .socket_suspend = simpad_pcmcia_socket_suspend, 123 .socket_suspend = simpad_pcmcia_socket_suspend,
124}; 124};
125 125
126int __init pcmcia_simpad_init(struct device *dev) 126int __devinit pcmcia_simpad_init(struct device *dev)
127{ 127{
128 int ret = -ENODEV; 128 int ret = -ENODEV;
129 129
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index 689e3c02edb8..2fe8cb8e95cd 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -57,14 +57,20 @@ module_param(pc_debug, int, 0644);
57void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func, 57void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
58 int lvl, const char *fmt, ...) 58 int lvl, const char *fmt, ...)
59{ 59{
60 struct va_format vaf;
60 va_list args; 61 va_list args;
61 if (pc_debug > lvl) { 62 if (pc_debug > lvl) {
62 printk(KERN_DEBUG "skt%u: %s: ", skt->nr, func);
63 va_start(args, fmt); 63 va_start(args, fmt);
64 vprintk(fmt, args); 64
65 vaf.fmt = fmt;
66 vaf.va = &args;
67
68 printk(KERN_DEBUG "skt%u: %s: %pV", skt->nr, func, &vaf);
69
65 va_end(args); 70 va_end(args);
66 } 71 }
67} 72}
73EXPORT_SYMBOL(soc_pcmcia_debug);
68 74
69#endif 75#endif
70 76
diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
index 3640599446fc..f3aa6a7fdab6 100644
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -81,6 +81,8 @@ MODULE_PARM_DESC(wapf, "WAPF value");
81 81
82static int wlan_status = 1; 82static int wlan_status = 1;
83static int bluetooth_status = 1; 83static int bluetooth_status = 1;
84static int wimax_status = -1;
85static int wwan_status = -1;
84 86
85module_param(wlan_status, int, 0444); 87module_param(wlan_status, int, 0444);
86MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot " 88MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
@@ -92,6 +94,16 @@ MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
92 "(0 = disabled, 1 = enabled, -1 = don't do anything). " 94 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
93 "default is 1"); 95 "default is 1");
94 96
97module_param(wimax_status, int, 0444);
98MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
99 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
100 "default is 1");
101
102module_param(wwan_status, int, 0444);
103MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
104 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
105 "default is 1");
106
95/* 107/*
96 * Some events we use, same for all Asus 108 * Some events we use, same for all Asus
97 */ 109 */
@@ -114,6 +126,8 @@ MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
114 */ 126 */
115#define WL_RSTS 0x01 /* internal Wifi */ 127#define WL_RSTS 0x01 /* internal Wifi */
116#define BT_RSTS 0x02 /* internal Bluetooth */ 128#define BT_RSTS 0x02 /* internal Bluetooth */
129#define WM_RSTS 0x08 /* internal wimax */
130#define WW_RSTS 0x20 /* internal wwan */
117 131
118/* LED */ 132/* LED */
119#define METHOD_MLED "MLED" 133#define METHOD_MLED "MLED"
@@ -132,6 +146,11 @@ MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
132 */ 146 */
133#define METHOD_WLAN "WLED" 147#define METHOD_WLAN "WLED"
134#define METHOD_BLUETOOTH "BLED" 148#define METHOD_BLUETOOTH "BLED"
149
150/* WWAN and WIMAX */
151#define METHOD_WWAN "GSMC"
152#define METHOD_WIMAX "WMXC"
153
135#define METHOD_WL_STATUS "RSTS" 154#define METHOD_WL_STATUS "RSTS"
136 155
137/* Brightness */ 156/* Brightness */
@@ -883,6 +902,64 @@ static ssize_t store_bluetooth(struct device *dev,
883} 902}
884 903
885/* 904/*
905 * Wimax
906 */
907static int asus_wimax_set(struct asus_laptop *asus, int status)
908{
909 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
910 pr_warning("Error setting wimax status to %d", status);
911 return -EIO;
912 }
913 return 0;
914}
915
916static ssize_t show_wimax(struct device *dev,
917 struct device_attribute *attr, char *buf)
918{
919 struct asus_laptop *asus = dev_get_drvdata(dev);
920
921 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
922}
923
924static ssize_t store_wimax(struct device *dev,
925 struct device_attribute *attr, const char *buf,
926 size_t count)
927{
928 struct asus_laptop *asus = dev_get_drvdata(dev);
929
930 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
931}
932
933/*
934 * Wwan
935 */
936static int asus_wwan_set(struct asus_laptop *asus, int status)
937{
938 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
939 pr_warning("Error setting wwan status to %d", status);
940 return -EIO;
941 }
942 return 0;
943}
944
945static ssize_t show_wwan(struct device *dev,
946 struct device_attribute *attr, char *buf)
947{
948 struct asus_laptop *asus = dev_get_drvdata(dev);
949
950 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
951}
952
953static ssize_t store_wwan(struct device *dev,
954 struct device_attribute *attr, const char *buf,
955 size_t count)
956{
957 struct asus_laptop *asus = dev_get_drvdata(dev);
958
959 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
960}
961
962/*
886 * Display 963 * Display
887 */ 964 */
888static void asus_set_display(struct asus_laptop *asus, int value) 965static void asus_set_display(struct asus_laptop *asus, int value)
@@ -1202,6 +1279,8 @@ static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1202static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan); 1279static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
1203static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR, 1280static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1204 show_bluetooth, store_bluetooth); 1281 show_bluetooth, store_bluetooth);
1282static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1283static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
1205static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp); 1284static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp);
1206static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd); 1285static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
1207static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl); 1286static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
@@ -1212,6 +1291,8 @@ static struct attribute *asus_attributes[] = {
1212 &dev_attr_infos.attr, 1291 &dev_attr_infos.attr,
1213 &dev_attr_wlan.attr, 1292 &dev_attr_wlan.attr,
1214 &dev_attr_bluetooth.attr, 1293 &dev_attr_bluetooth.attr,
1294 &dev_attr_wimax.attr,
1295 &dev_attr_wwan.attr,
1215 &dev_attr_display.attr, 1296 &dev_attr_display.attr,
1216 &dev_attr_ledd.attr, 1297 &dev_attr_ledd.attr,
1217 &dev_attr_ls_level.attr, 1298 &dev_attr_ls_level.attr,
@@ -1239,6 +1320,13 @@ static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1239 } else if (attr == &dev_attr_display.attr) { 1320 } else if (attr == &dev_attr_display.attr) {
1240 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL); 1321 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1241 1322
1323 } else if (attr == &dev_attr_wimax.attr) {
1324 supported =
1325 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1326
1327 } else if (attr == &dev_attr_wwan.attr) {
1328 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1329
1242 } else if (attr == &dev_attr_ledd.attr) { 1330 } else if (attr == &dev_attr_ledd.attr) {
1243 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL); 1331 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1244 1332
@@ -1397,7 +1485,8 @@ static int asus_laptop_get_info(struct asus_laptop *asus)
1397 1485
1398 /* 1486 /*
1399 * The HWRS method return informations about the hardware. 1487 * The HWRS method return informations about the hardware.
1400 * 0x80 bit is for WLAN, 0x100 for Bluetooth. 1488 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1489 * 0x40 for WWAN, 0x10 for WIMAX.
1401 * The significance of others is yet to be found. 1490 * The significance of others is yet to be found.
1402 */ 1491 */
1403 status = 1492 status =
@@ -1440,6 +1529,12 @@ static int __devinit asus_acpi_init(struct asus_laptop *asus)
1440 if (wlan_status >= 0) 1529 if (wlan_status >= 0)
1441 asus_wlan_set(asus, !!wlan_status); 1530 asus_wlan_set(asus, !!wlan_status);
1442 1531
1532 if (wimax_status >= 0)
1533 asus_wimax_set(asus, !!wimax_status);
1534
1535 if (wwan_status >= 0)
1536 asus_wwan_set(asus, !!wwan_status);
1537
1443 /* Keyboard Backlight is on by default */ 1538 /* Keyboard Backlight is on by default */
1444 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL)) 1539 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
1445 asus_kled_set(asus, 1); 1540 asus_kled_set(asus, 1);
diff --git a/drivers/platform/x86/eeepc-wmi.c b/drivers/platform/x86/eeepc-wmi.c
index 462ceab93f87..0d50fbbe2478 100644
--- a/drivers/platform/x86/eeepc-wmi.c
+++ b/drivers/platform/x86/eeepc-wmi.c
@@ -298,8 +298,8 @@ static void eeepc_wmi_notify(u32 value, void *context)
298 kfree(obj); 298 kfree(obj);
299} 299}
300 300
301static int store_cpufv(struct device *dev, struct device_attribute *attr, 301static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr,
302 const char *buf, size_t count) 302 const char *buf, size_t count)
303{ 303{
304 int value; 304 int value;
305 struct acpi_buffer input = { (acpi_size)sizeof(value), &value }; 305 struct acpi_buffer input = { (acpi_size)sizeof(value), &value };
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 1dac659b5e0c..9e05af9c41cb 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -172,6 +172,8 @@ static int hp_wmi_perform_query(int query, int write, u32 *buffer,
172 bios_return = *((struct bios_return *)obj->buffer.pointer); 172 bios_return = *((struct bios_return *)obj->buffer.pointer);
173 173
174 memcpy(buffer, &bios_return.value, sizeof(bios_return.value)); 174 memcpy(buffer, &bios_return.value, sizeof(bios_return.value));
175
176 kfree(obj);
175 return 0; 177 return 0;
176} 178}
177 179
diff --git a/drivers/platform/x86/ibm_rtl.c b/drivers/platform/x86/ibm_rtl.c
index 3c2c6b91ecb3..94a114aa8e28 100644
--- a/drivers/platform/x86/ibm_rtl.c
+++ b/drivers/platform/x86/ibm_rtl.c
@@ -28,6 +28,7 @@
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/sysdev.h> 29#include <linux/sysdev.h>
30#include <linux/dmi.h> 30#include <linux/dmi.h>
31#include <linux/efi.h>
31#include <linux/mutex.h> 32#include <linux/mutex.h>
32#include <asm/bios_ebda.h> 33#include <asm/bios_ebda.h>
33 34
@@ -220,32 +221,13 @@ static void rtl_teardown_sysfs(void) {
220 sysdev_class_unregister(&class_rtl); 221 sysdev_class_unregister(&class_rtl);
221} 222}
222 223
223static int dmi_check_cb(const struct dmi_system_id *id)
224{
225 RTL_DEBUG("found IBM server '%s'\n", id->ident);
226 return 0;
227}
228
229#define ibm_dmi_entry(NAME, TYPE) \
230{ \
231 .ident = NAME, \
232 .matches = { \
233 DMI_MATCH(DMI_SYS_VENDOR, "IBM"), \
234 DMI_MATCH(DMI_PRODUCT_NAME, TYPE), \
235 }, \
236 .callback = dmi_check_cb \
237}
238 224
239static struct dmi_system_id __initdata ibm_rtl_dmi_table[] = { 225static struct dmi_system_id __initdata ibm_rtl_dmi_table[] = {
240 ibm_dmi_entry("BladeCenter LS21", "7971"), 226 { \
241 ibm_dmi_entry("BladeCenter LS22", "7901"), 227 .matches = { \
242 ibm_dmi_entry("BladeCenter HS21 XM", "7995"), 228 DMI_MATCH(DMI_SYS_VENDOR, "IBM"), \
243 ibm_dmi_entry("BladeCenter HS22", "7870"), 229 }, \
244 ibm_dmi_entry("BladeCenter HS22V", "7871"), 230 },
245 ibm_dmi_entry("System x3550 M2", "7946"),
246 ibm_dmi_entry("System x3650 M2", "7947"),
247 ibm_dmi_entry("System x3550 M3", "7944"),
248 ibm_dmi_entry("System x3650 M3", "7945"),
249 { } 231 { }
250}; 232};
251 233
@@ -257,7 +239,7 @@ static int __init ibm_rtl_init(void) {
257 if (force) 239 if (force)
258 pr_warning("ibm-rtl: module loaded by force\n"); 240 pr_warning("ibm-rtl: module loaded by force\n");
259 /* first ensure that we are running on IBM HW */ 241 /* first ensure that we are running on IBM HW */
260 else if (!dmi_check_system(ibm_rtl_dmi_table)) 242 else if (efi_enabled || !dmi_check_system(ibm_rtl_dmi_table))
261 return -ENODEV; 243 return -ENODEV;
262 244
263 /* Get the address for the Extended BIOS Data Area */ 245 /* Get the address for the Extended BIOS Data Area */
@@ -302,7 +284,7 @@ static int __init ibm_rtl_init(void) {
302 RTL_DEBUG("rtl_cmd_width = %u, rtl_cmd_type = %u\n", 284 RTL_DEBUG("rtl_cmd_width = %u, rtl_cmd_type = %u\n",
303 rtl_cmd_width, rtl_cmd_type); 285 rtl_cmd_width, rtl_cmd_type);
304 addr = ioread32(&rtl_table->cmd_port_address); 286 addr = ioread32(&rtl_table->cmd_port_address);
305 RTL_DEBUG("addr = %#llx\n", addr); 287 RTL_DEBUG("addr = %#llx\n", (unsigned long long)addr);
306 plen = rtl_cmd_width/sizeof(char); 288 plen = rtl_cmd_width/sizeof(char);
307 rtl_cmd_addr = rtl_port_map(addr, plen); 289 rtl_cmd_addr = rtl_port_map(addr, plen);
308 RTL_DEBUG("rtl_cmd_addr = %#llx\n", (u64)rtl_cmd_addr); 290 RTL_DEBUG("rtl_cmd_addr = %#llx\n", (u64)rtl_cmd_addr);
diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
index 42a5469a2459..35278ad7e628 100644
--- a/drivers/platform/x86/msi-wmi.c
+++ b/drivers/platform/x86/msi-wmi.c
@@ -43,16 +43,18 @@ MODULE_ALIAS("wmi:B6F3EEF2-3D2F-49DC-9DE3-85BCE18C62F2");
43 43
44#define dprintk(msg...) pr_debug(DRV_PFX msg) 44#define dprintk(msg...) pr_debug(DRV_PFX msg)
45 45
46#define KEYCODE_BASE 0xD0 46#define SCANCODE_BASE 0xD0
47#define MSI_WMI_BRIGHTNESSUP KEYCODE_BASE 47#define MSI_WMI_BRIGHTNESSUP SCANCODE_BASE
48#define MSI_WMI_BRIGHTNESSDOWN (KEYCODE_BASE + 1) 48#define MSI_WMI_BRIGHTNESSDOWN (SCANCODE_BASE + 1)
49#define MSI_WMI_VOLUMEUP (KEYCODE_BASE + 2) 49#define MSI_WMI_VOLUMEUP (SCANCODE_BASE + 2)
50#define MSI_WMI_VOLUMEDOWN (KEYCODE_BASE + 3) 50#define MSI_WMI_VOLUMEDOWN (SCANCODE_BASE + 3)
51#define MSI_WMI_MUTE (SCANCODE_BASE + 4)
51static struct key_entry msi_wmi_keymap[] = { 52static struct key_entry msi_wmi_keymap[] = {
52 { KE_KEY, MSI_WMI_BRIGHTNESSUP, {KEY_BRIGHTNESSUP} }, 53 { KE_KEY, MSI_WMI_BRIGHTNESSUP, {KEY_BRIGHTNESSUP} },
53 { KE_KEY, MSI_WMI_BRIGHTNESSDOWN, {KEY_BRIGHTNESSDOWN} }, 54 { KE_KEY, MSI_WMI_BRIGHTNESSDOWN, {KEY_BRIGHTNESSDOWN} },
54 { KE_KEY, MSI_WMI_VOLUMEUP, {KEY_VOLUMEUP} }, 55 { KE_KEY, MSI_WMI_VOLUMEUP, {KEY_VOLUMEUP} },
55 { KE_KEY, MSI_WMI_VOLUMEDOWN, {KEY_VOLUMEDOWN} }, 56 { KE_KEY, MSI_WMI_VOLUMEDOWN, {KEY_VOLUMEDOWN} },
57 { KE_KEY, MSI_WMI_MUTE, {KEY_MUTE} },
56 { KE_END, 0} 58 { KE_END, 0}
57}; 59};
58static ktime_t last_pressed[ARRAY_SIZE(msi_wmi_keymap) - 1]; 60static ktime_t last_pressed[ARRAY_SIZE(msi_wmi_keymap) - 1];
@@ -169,7 +171,7 @@ static void msi_wmi_notify(u32 value, void *context)
169 ktime_t diff; 171 ktime_t diff;
170 cur = ktime_get_real(); 172 cur = ktime_get_real();
171 diff = ktime_sub(cur, last_pressed[key->code - 173 diff = ktime_sub(cur, last_pressed[key->code -
172 KEYCODE_BASE]); 174 SCANCODE_BASE]);
173 /* Ignore event if the same event happened in a 50 ms 175 /* Ignore event if the same event happened in a 50 ms
174 timeframe -> Key press may result in 10-20 GPEs */ 176 timeframe -> Key press may result in 10-20 GPEs */
175 if (ktime_to_us(diff) < 1000 * 50) { 177 if (ktime_to_us(diff) < 1000 * 50) {
@@ -178,7 +180,7 @@ static void msi_wmi_notify(u32 value, void *context)
178 key->code, ktime_to_us(diff)); 180 key->code, ktime_to_us(diff));
179 return; 181 return;
180 } 182 }
181 last_pressed[key->code - KEYCODE_BASE] = cur; 183 last_pressed[key->code - SCANCODE_BASE] = cur;
182 184
183 if (key->type == KE_KEY && 185 if (key->type == KE_KEY &&
184 /* Brightness is served via acpi video driver */ 186 /* Brightness is served via acpi video driver */
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index efda9c54e0e2..ecd503f3557e 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -8497,7 +8497,6 @@ static void ibm_exit(struct ibm_struct *ibm)
8497 ibm->acpi->type, 8497 ibm->acpi->type,
8498 dispatch_acpi_notify); 8498 dispatch_acpi_notify);
8499 ibm->flags.acpi_notify_installed = 0; 8499 ibm->flags.acpi_notify_installed = 0;
8500 ibm->flags.acpi_notify_installed = 0;
8501 } 8500 }
8502 8501
8503 if (ibm->flags.proc_created) { 8502 if (ibm->flags.proc_created) {
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index 81bca5a4d8aa..209cced786c6 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -135,6 +135,7 @@ static const struct key_entry toshiba_acpi_keymap[] __initconst = {
135 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } }, 135 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
136 { KE_KEY, 0x142, { KEY_WLAN } }, 136 { KE_KEY, 0x142, { KEY_WLAN } },
137 { KE_KEY, 0x143, { KEY_PROG1 } }, 137 { KE_KEY, 0x143, { KEY_PROG1 } },
138 { KE_KEY, 0x17f, { KEY_FN } },
138 { KE_KEY, 0xb05, { KEY_PROG2 } }, 139 { KE_KEY, 0xb05, { KEY_PROG2 } },
139 { KE_KEY, 0xb06, { KEY_WWW } }, 140 { KE_KEY, 0xb06, { KEY_WWW } },
140 { KE_KEY, 0xb07, { KEY_MAIL } }, 141 { KE_KEY, 0xb07, { KEY_MAIL } },
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 104b77c87ef5..aecd9a9b549f 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -755,7 +755,7 @@ static bool guid_already_parsed(const char *guid_string)
755 struct wmi_block *wblock; 755 struct wmi_block *wblock;
756 756
757 list_for_each_entry(wblock, &wmi_block_list, list) 757 list_for_each_entry(wblock, &wmi_block_list, list)
758 if (strncmp(wblock->gblock.guid, guid_string, 16) == 0) 758 if (memcmp(wblock->gblock.guid, guid_string, 16) == 0)
759 return true; 759 return true;
760 760
761 return false; 761 return false;
diff --git a/drivers/pnp/isapnp/proc.c b/drivers/pnp/isapnp/proc.c
index e73ebefdf3e0..315b3112aca8 100644
--- a/drivers/pnp/isapnp/proc.c
+++ b/drivers/pnp/isapnp/proc.c
@@ -21,7 +21,6 @@
21#include <linux/isapnp.h> 21#include <linux/isapnp.h>
22#include <linux/proc_fs.h> 22#include <linux/proc_fs.h>
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/smp_lock.h>
25#include <asm/uaccess.h> 24#include <asm/uaccess.h>
26 25
27extern struct pnp_protocol isapnp_protocol; 26extern struct pnp_protocol isapnp_protocol;
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index 2d73dfcecdbb..57313f4658bc 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -180,7 +180,7 @@ struct pnp_protocol pnpacpi_protocol = {
180}; 180};
181EXPORT_SYMBOL(pnpacpi_protocol); 181EXPORT_SYMBOL(pnpacpi_protocol);
182 182
183static char *pnpacpi_get_id(struct acpi_device *device) 183static char *__init pnpacpi_get_id(struct acpi_device *device)
184{ 184{
185 struct acpi_hardware_id *id; 185 struct acpi_hardware_id *id;
186 186
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index 68cf0c99138a..7b5080c45569 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -1159,11 +1159,11 @@ int __devinit rio_init_mports(void)
1159 1159
1160 list_for_each_entry(port, &rio_mports, node) { 1160 list_for_each_entry(port, &rio_mports, node) {
1161 if (!request_mem_region(port->iores.start, 1161 if (!request_mem_region(port->iores.start,
1162 port->iores.end - port->iores.start, 1162 resource_size(&port->iores),
1163 port->name)) { 1163 port->name)) {
1164 printk(KERN_ERR 1164 printk(KERN_ERR
1165 "RIO: Error requesting master port region 0x%016llx-0x%016llx\n", 1165 "RIO: Error requesting master port region 0x%016llx-0x%016llx\n",
1166 (u64)port->iores.start, (u64)port->iores.end - 1); 1166 (u64)port->iores.start, (u64)port->iores.end);
1167 rc = -ENOMEM; 1167 rc = -ENOMEM;
1168 goto out; 1168 goto out;
1169 } 1169 }
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index f1d10c974cd4..ba521f0f0fac 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -911,7 +911,7 @@ out:
911} 911}
912 912
913/** 913/**
914 * set_consumer_device_supply: Bind a regulator to a symbolic supply 914 * set_consumer_device_supply - Bind a regulator to a symbolic supply
915 * @rdev: regulator source 915 * @rdev: regulator source
916 * @consumer_dev: device the supply applies to 916 * @consumer_dev: device the supply applies to
917 * @consumer_dev_name: dev_name() string for device supply applies to 917 * @consumer_dev_name: dev_name() string for device supply applies to
@@ -1052,7 +1052,6 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
1052 printk(KERN_WARNING 1052 printk(KERN_WARNING
1053 "%s: could not add device link %s err %d\n", 1053 "%s: could not add device link %s err %d\n",
1054 __func__, dev->kobj.name, err); 1054 __func__, dev->kobj.name, err);
1055 device_remove_file(dev, &regulator->dev_attr);
1056 goto link_name_err; 1055 goto link_name_err;
1057 } 1056 }
1058 } 1057 }
@@ -1268,13 +1267,17 @@ static int _regulator_enable(struct regulator_dev *rdev)
1268{ 1267{
1269 int ret, delay; 1268 int ret, delay;
1270 1269
1271 /* do we need to enable the supply regulator first */ 1270 if (rdev->use_count == 0) {
1272 if (rdev->supply) { 1271 /* do we need to enable the supply regulator first */
1273 ret = _regulator_enable(rdev->supply); 1272 if (rdev->supply) {
1274 if (ret < 0) { 1273 mutex_lock(&rdev->supply->mutex);
1275 printk(KERN_ERR "%s: failed to enable %s: %d\n", 1274 ret = _regulator_enable(rdev->supply);
1276 __func__, rdev_get_name(rdev), ret); 1275 mutex_unlock(&rdev->supply->mutex);
1277 return ret; 1276 if (ret < 0) {
1277 printk(KERN_ERR "%s: failed to enable %s: %d\n",
1278 __func__, rdev_get_name(rdev), ret);
1279 return ret;
1280 }
1278 } 1281 }
1279 } 1282 }
1280 1283
@@ -1313,10 +1316,12 @@ static int _regulator_enable(struct regulator_dev *rdev)
1313 if (ret < 0) 1316 if (ret < 0)
1314 return ret; 1317 return ret;
1315 1318
1316 if (delay >= 1000) 1319 if (delay >= 1000) {
1317 mdelay(delay / 1000); 1320 mdelay(delay / 1000);
1318 else if (delay) 1321 udelay(delay % 1000);
1322 } else if (delay) {
1319 udelay(delay); 1323 udelay(delay);
1324 }
1320 1325
1321 } else if (ret < 0) { 1326 } else if (ret < 0) {
1322 printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", 1327 printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n",
@@ -1359,6 +1364,7 @@ static int _regulator_disable(struct regulator_dev *rdev,
1359 struct regulator_dev **supply_rdev_ptr) 1364 struct regulator_dev **supply_rdev_ptr)
1360{ 1365{
1361 int ret = 0; 1366 int ret = 0;
1367 *supply_rdev_ptr = NULL;
1362 1368
1363 if (WARN(rdev->use_count <= 0, 1369 if (WARN(rdev->use_count <= 0,
1364 "unbalanced disables for %s\n", 1370 "unbalanced disables for %s\n",
@@ -2346,6 +2352,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2346 if (init_data->supply_regulator && init_data->supply_regulator_dev) { 2352 if (init_data->supply_regulator && init_data->supply_regulator_dev) {
2347 dev_err(dev, 2353 dev_err(dev,
2348 "Supply regulator specified by both name and dev\n"); 2354 "Supply regulator specified by both name and dev\n");
2355 ret = -EINVAL;
2349 goto scrub; 2356 goto scrub;
2350 } 2357 }
2351 2358
@@ -2364,6 +2371,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2364 if (!found) { 2371 if (!found) {
2365 dev_err(dev, "Failed to find supply %s\n", 2372 dev_err(dev, "Failed to find supply %s\n",
2366 init_data->supply_regulator); 2373 init_data->supply_regulator);
2374 ret = -ENODEV;
2367 goto scrub; 2375 goto scrub;
2368 } 2376 }
2369 2377
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index 4597d508a229..ecd99f59dba8 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -465,8 +465,8 @@ static struct regulator_ops mc13783_fixed_regulator_ops = {
465 .get_voltage = mc13783_fixed_regulator_get_voltage, 465 .get_voltage = mc13783_fixed_regulator_get_voltage,
466}; 466};
467 467
468int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask, 468static int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask,
469 u32 val) 469 u32 val)
470{ 470{
471 struct mc13783 *mc13783 = priv->mc13783; 471 struct mc13783 *mc13783 = priv->mc13783;
472 int ret; 472 int ret;
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 51237fbb1bbb..6d20b0454a1d 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -231,8 +231,7 @@ static int tps6586x_dvm_voltages[] = {
231}; 231};
232 232
233#define TPS6586X_REGULATOR(_id, vdata, _ops, vreg, shift, nbits, \ 233#define TPS6586X_REGULATOR(_id, vdata, _ops, vreg, shift, nbits, \
234 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ 234 ereg0, ebit0, ereg1, ebit1) \
235{ \
236 .desc = { \ 235 .desc = { \
237 .name = "REG-" #_id, \ 236 .name = "REG-" #_id, \
238 .ops = &tps6586x_regulator_##_ops, \ 237 .ops = &tps6586x_regulator_##_ops, \
@@ -248,18 +247,26 @@ static int tps6586x_dvm_voltages[] = {
248 .enable_bit[0] = (ebit0), \ 247 .enable_bit[0] = (ebit0), \
249 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \ 248 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \
250 .enable_bit[1] = (ebit1), \ 249 .enable_bit[1] = (ebit1), \
251 .voltages = tps6586x_##vdata##_voltages, \ 250 .voltages = tps6586x_##vdata##_voltages,
252} 251
252#define TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \
253 .go_reg = TPS6586X_##goreg, \
254 .go_bit = (gobit),
253 255
254#define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \ 256#define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \
255 ereg0, ebit0, ereg1, ebit1) \ 257 ereg0, ebit0, ereg1, ebit1) \
258{ \
256 TPS6586X_REGULATOR(_id, vdata, ldo_ops, vreg, shift, nbits, \ 259 TPS6586X_REGULATOR(_id, vdata, ldo_ops, vreg, shift, nbits, \
257 ereg0, ebit0, ereg1, ebit1, 0, 0) 260 ereg0, ebit0, ereg1, ebit1) \
261}
258 262
259#define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \ 263#define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \
260 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ 264 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \
265{ \
261 TPS6586X_REGULATOR(_id, vdata, dvm_ops, vreg, shift, nbits, \ 266 TPS6586X_REGULATOR(_id, vdata, dvm_ops, vreg, shift, nbits, \
262 ereg0, ebit0, ereg1, ebit1, goreg, gobit) 267 ereg0, ebit0, ereg1, ebit1) \
268 TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \
269}
263 270
264static struct tps6586x_regulator tps6586x_regulator[] = { 271static struct tps6586x_regulator tps6586x_regulator[] = {
265 TPS6586X_LDO(LDO_0, ldo, SUPPLYV1, 5, 3, ENC, 0, END, 0), 272 TPS6586X_LDO(LDO_0, ldo, SUPPLYV1, 5, 3, ENC, 0, END, 0),
@@ -267,11 +274,11 @@ static struct tps6586x_regulator tps6586x_regulator[] = {
267 TPS6586X_LDO(LDO_5, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6), 274 TPS6586X_LDO(LDO_5, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6),
268 TPS6586X_LDO(LDO_6, ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4), 275 TPS6586X_LDO(LDO_6, ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4),
269 TPS6586X_LDO(LDO_7, ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5), 276 TPS6586X_LDO(LDO_7, ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5),
270 TPS6586X_LDO(LDO_8, ldo, SUPPLYV1, 5, 3, ENC, 6, END, 6), 277 TPS6586X_LDO(LDO_8, ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6),
271 TPS6586X_LDO(LDO_9, ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7), 278 TPS6586X_LDO(LDO_9, ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7),
272 TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, ENE, 7, ENE, 7), 279 TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7),
273 TPS6586X_LDO(LDO_1, dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1), 280 TPS6586X_LDO(LDO_1, dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1),
274 TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 1, END, 1), 281 TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7),
275 282
276 TPS6586X_DVM(LDO_2, dvm, LDO2BV1, 0, 5, ENA, 3, ENB, 3, VCC2, 6), 283 TPS6586X_DVM(LDO_2, dvm, LDO2BV1, 0, 5, ENA, 3, ENB, 3, VCC2, 6),
277 TPS6586X_DVM(LDO_4, ldo4, LDO4V1, 0, 5, ENC, 3, END, 3, VCC1, 6), 284 TPS6586X_DVM(LDO_4, ldo4, LDO4V1, 0, 5, ENC, 3, END, 3, VCC1, 6),
@@ -290,6 +297,10 @@ static inline int tps6586x_regulator_preinit(struct device *parent,
290 uint8_t val1, val2; 297 uint8_t val1, val2;
291 int ret; 298 int ret;
292 299
300 if (ri->enable_reg[0] == ri->enable_reg[1] &&
301 ri->enable_bit[0] == ri->enable_bit[1])
302 return 0;
303
293 ret = tps6586x_read(parent, ri->enable_reg[0], &val1); 304 ret = tps6586x_read(parent, ri->enable_reg[0], &val1);
294 if (ret) 305 if (ret)
295 return ret; 306 return ret;
@@ -298,14 +309,14 @@ static inline int tps6586x_regulator_preinit(struct device *parent,
298 if (ret) 309 if (ret)
299 return ret; 310 return ret;
300 311
301 if (!(val2 & ri->enable_bit[1])) 312 if (!(val2 & (1 << ri->enable_bit[1])))
302 return 0; 313 return 0;
303 314
304 /* 315 /*
305 * The regulator is on, but it's enabled with the bit we don't 316 * The regulator is on, but it's enabled with the bit we don't
306 * want to use, so we switch the enable bits 317 * want to use, so we switch the enable bits
307 */ 318 */
308 if (!(val1 & ri->enable_bit[0])) { 319 if (!(val1 & (1 << ri->enable_bit[0]))) {
309 ret = tps6586x_set_bits(parent, ri->enable_reg[0], 320 ret = tps6586x_set_bits(parent, ri->enable_reg[0],
310 1 << ri->enable_bit[0]); 321 1 << ri->enable_bit[0]);
311 if (ret) 322 if (ret)
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 7e5892efc437..a57262a4fa6c 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -219,12 +219,12 @@ static int twlreg_set_mode(struct regulator_dev *rdev, unsigned mode)
219 return -EACCES; 219 return -EACCES;
220 220
221 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 221 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
222 message >> 8, 0x15 /* PB_WORD_MSB */ ); 222 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
223 if (status >= 0) 223 if (status < 0)
224 return status; 224 return status;
225 225
226 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 226 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
227 message, 0x16 /* PB_WORD_LSB */ ); 227 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
228} 228}
229 229
230/*----------------------------------------------------------------------*/ 230/*----------------------------------------------------------------------*/
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index 359d1e04626c..f0d638922644 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -35,7 +35,7 @@
35 35
36#ifdef CONFIG_SH_SECUREEDGE5410 36#ifdef CONFIG_SH_SECUREEDGE5410
37#include <asm/rtc.h> 37#include <asm/rtc.h>
38#include <mach/snapgear.h> 38#include <mach/secureedge5410.h>
39 39
40#define RTC_RESET 0x1000 40#define RTC_RESET 0x1000
41#define RTC_IODATA 0x0800 41#define RTC_IODATA 0x0800
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 5efbd5990ff8..06e41ed93230 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -761,7 +761,7 @@ err_unmap:
761 clk_put(rtc->clk); 761 clk_put(rtc->clk);
762 iounmap(rtc->regbase); 762 iounmap(rtc->regbase);
763err_badmap: 763err_badmap:
764 release_resource(rtc->res); 764 release_mem_region(rtc->res->start, rtc->regsize);
765err_badres: 765err_badres:
766 kfree(rtc); 766 kfree(rtc);
767 767
@@ -786,7 +786,7 @@ static int __exit sh_rtc_remove(struct platform_device *pdev)
786 } 786 }
787 787
788 iounmap(rtc->regbase); 788 iounmap(rtc->regbase);
789 release_resource(rtc->res); 789 release_mem_region(rtc->res->start, rtc->regsize);
790 790
791 clk_disable(rtc->clk); 791 clk_disable(rtc->clk);
792 clk_put(rtc->clk); 792 clk_put(rtc->clk);
diff --git a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
index c71d89dba302..83b4615a3b62 100644
--- a/drivers/s390/block/dasd_eer.c
+++ b/drivers/s390/block/dasd_eer.c
@@ -17,7 +17,6 @@
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/poll.h> 18#include <linux/poll.h>
19#include <linux/mutex.h> 19#include <linux/mutex.h>
20#include <linux/smp_lock.h>
21#include <linux/err.h> 20#include <linux/err.h>
22#include <linux/slab.h> 21#include <linux/slab.h>
23 22
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index eb28fb01a38a..f6489eb7e976 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -14,7 +14,6 @@
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/smp_lock.h>
18 17
19#include <asm/compat.h> 18#include <asm/compat.h>
20#include <asm/ccwdev.h> 19#include <asm/ccwdev.h>
diff --git a/drivers/s390/char/tape_char.c b/drivers/s390/char/tape_char.c
index 883e2db02bd3..e090a307fdee 100644
--- a/drivers/s390/char/tape_char.c
+++ b/drivers/s390/char/tape_char.c
@@ -17,7 +17,6 @@
17#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/proc_fs.h> 18#include <linux/proc_fs.h>
19#include <linux/mtio.h> 19#include <linux/mtio.h>
20#include <linux/smp_lock.h>
21#include <linux/compat.h> 20#include <linux/compat.h>
22 21
23#include <asm/uaccess.h> 22#include <asm/uaccess.h>
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index 6c408670e08d..b3a3e8e8656e 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -209,29 +209,79 @@ tape_state_set(struct tape_device *device, enum tape_state newstate)
209 wake_up(&device->state_change_wq); 209 wake_up(&device->state_change_wq);
210} 210}
211 211
212struct tape_med_state_work_data {
213 struct tape_device *device;
214 enum tape_medium_state state;
215 struct work_struct work;
216};
217
218static void
219tape_med_state_work_handler(struct work_struct *work)
220{
221 static char env_state_loaded[] = "MEDIUM_STATE=LOADED";
222 static char env_state_unloaded[] = "MEDIUM_STATE=UNLOADED";
223 struct tape_med_state_work_data *p =
224 container_of(work, struct tape_med_state_work_data, work);
225 struct tape_device *device = p->device;
226 char *envp[] = { NULL, NULL };
227
228 switch (p->state) {
229 case MS_UNLOADED:
230 pr_info("%s: The tape cartridge has been successfully "
231 "unloaded\n", dev_name(&device->cdev->dev));
232 envp[0] = env_state_unloaded;
233 kobject_uevent_env(&device->cdev->dev.kobj, KOBJ_CHANGE, envp);
234 break;
235 case MS_LOADED:
236 pr_info("%s: A tape cartridge has been mounted\n",
237 dev_name(&device->cdev->dev));
238 envp[0] = env_state_loaded;
239 kobject_uevent_env(&device->cdev->dev.kobj, KOBJ_CHANGE, envp);
240 break;
241 default:
242 break;
243 }
244 tape_put_device(device);
245 kfree(p);
246}
247
248static void
249tape_med_state_work(struct tape_device *device, enum tape_medium_state state)
250{
251 struct tape_med_state_work_data *p;
252
253 p = kzalloc(sizeof(*p), GFP_ATOMIC);
254 if (p) {
255 INIT_WORK(&p->work, tape_med_state_work_handler);
256 p->device = tape_get_device(device);
257 p->state = state;
258 schedule_work(&p->work);
259 }
260}
261
212void 262void
213tape_med_state_set(struct tape_device *device, enum tape_medium_state newstate) 263tape_med_state_set(struct tape_device *device, enum tape_medium_state newstate)
214{ 264{
215 if (device->medium_state == newstate) 265 enum tape_medium_state oldstate;
266
267 oldstate = device->medium_state;
268 if (oldstate == newstate)
216 return; 269 return;
270 device->medium_state = newstate;
217 switch(newstate){ 271 switch(newstate){
218 case MS_UNLOADED: 272 case MS_UNLOADED:
219 device->tape_generic_status |= GMT_DR_OPEN(~0); 273 device->tape_generic_status |= GMT_DR_OPEN(~0);
220 if (device->medium_state == MS_LOADED) 274 if (oldstate == MS_LOADED)
221 pr_info("%s: The tape cartridge has been successfully " 275 tape_med_state_work(device, MS_UNLOADED);
222 "unloaded\n", dev_name(&device->cdev->dev));
223 break; 276 break;
224 case MS_LOADED: 277 case MS_LOADED:
225 device->tape_generic_status &= ~GMT_DR_OPEN(~0); 278 device->tape_generic_status &= ~GMT_DR_OPEN(~0);
226 if (device->medium_state == MS_UNLOADED) 279 if (oldstate == MS_UNLOADED)
227 pr_info("%s: A tape cartridge has been mounted\n", 280 tape_med_state_work(device, MS_LOADED);
228 dev_name(&device->cdev->dev));
229 break; 281 break;
230 default: 282 default:
231 // print nothing
232 break; 283 break;
233 } 284 }
234 device->medium_state = newstate;
235 wake_up(&device->state_change_wq); 285 wake_up(&device->state_change_wq);
236} 286}
237 287
diff --git a/drivers/s390/char/vmlogrdr.c b/drivers/s390/char/vmlogrdr.c
index 9f661426e4a1..c837d7419a6a 100644
--- a/drivers/s390/char/vmlogrdr.c
+++ b/drivers/s390/char/vmlogrdr.c
@@ -30,7 +30,6 @@
30#include <linux/kmod.h> 30#include <linux/kmod.h>
31#include <linux/cdev.h> 31#include <linux/cdev.h>
32#include <linux/device.h> 32#include <linux/device.h>
33#include <linux/smp_lock.h>
34#include <linux/string.h> 33#include <linux/string.h>
35 34
36MODULE_AUTHOR 35MODULE_AUTHOR
@@ -249,27 +248,25 @@ static int vmlogrdr_recording(struct vmlogrdr_priv_t * logptr,
249 char cp_command[80]; 248 char cp_command[80];
250 char cp_response[160]; 249 char cp_response[160];
251 char *onoff, *qid_string; 250 char *onoff, *qid_string;
251 int rc;
252 252
253 memset(cp_command, 0x00, sizeof(cp_command)); 253 onoff = ((action == 1) ? "ON" : "OFF");
254 memset(cp_response, 0x00, sizeof(cp_response));
255
256 onoff = ((action == 1) ? "ON" : "OFF");
257 qid_string = ((recording_class_AB == 1) ? " QID * " : ""); 254 qid_string = ((recording_class_AB == 1) ? " QID * " : "");
258 255
259 /* 256 /*
260 * The recording commands needs to be called with option QID 257 * The recording commands needs to be called with option QID
261 * for guests that have previlege classes A or B. 258 * for guests that have previlege classes A or B.
262 * Purging has to be done as separate step, because recording 259 * Purging has to be done as separate step, because recording
263 * can't be switched on as long as records are on the queue. 260 * can't be switched on as long as records are on the queue.
264 * Doing both at the same time doesn't work. 261 * Doing both at the same time doesn't work.
265 */ 262 */
266 263 if (purge && (action == 1)) {
267 if (purge) { 264 memset(cp_command, 0x00, sizeof(cp_command));
265 memset(cp_response, 0x00, sizeof(cp_response));
268 snprintf(cp_command, sizeof(cp_command), 266 snprintf(cp_command, sizeof(cp_command),
269 "RECORDING %s PURGE %s", 267 "RECORDING %s PURGE %s",
270 logptr->recording_name, 268 logptr->recording_name,
271 qid_string); 269 qid_string);
272
273 cpcmd(cp_command, cp_response, sizeof(cp_response), NULL); 270 cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
274 } 271 }
275 272
@@ -279,19 +276,33 @@ static int vmlogrdr_recording(struct vmlogrdr_priv_t * logptr,
279 logptr->recording_name, 276 logptr->recording_name,
280 onoff, 277 onoff,
281 qid_string); 278 qid_string);
282
283 cpcmd(cp_command, cp_response, sizeof(cp_response), NULL); 279 cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
284 /* The recording command will usually answer with 'Command complete' 280 /* The recording command will usually answer with 'Command complete'
285 * on success, but when the specific service was never connected 281 * on success, but when the specific service was never connected
286 * before then there might be an additional informational message 282 * before then there might be an additional informational message
287 * 'HCPCRC8072I Recording entry not found' before the 283 * 'HCPCRC8072I Recording entry not found' before the
288 * 'Command complete'. So I use strstr rather then the strncmp. 284 * 'Command complete'. So I use strstr rather then the strncmp.
289 */ 285 */
290 if (strstr(cp_response,"Command complete")) 286 if (strstr(cp_response,"Command complete"))
291 return 0; 287 rc = 0;
292 else 288 else
293 return -EIO; 289 rc = -EIO;
290 /*
291 * If we turn recording off, we have to purge any remaining records
292 * afterwards, as a large number of queued records may impact z/VM
293 * performance.
294 */
295 if (purge && (action == 0)) {
296 memset(cp_command, 0x00, sizeof(cp_command));
297 memset(cp_response, 0x00, sizeof(cp_response));
298 snprintf(cp_command, sizeof(cp_command),
299 "RECORDING %s PURGE %s",
300 logptr->recording_name,
301 qid_string);
302 cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
303 }
294 304
305 return rc;
295} 306}
296 307
297 308
diff --git a/drivers/s390/char/vmur.c b/drivers/s390/char/vmur.c
index 1de672f21037..f7e4ae6bf15a 100644
--- a/drivers/s390/char/vmur.c
+++ b/drivers/s390/char/vmur.c
@@ -13,7 +13,6 @@
13 13
14#include <linux/cdev.h> 14#include <linux/cdev.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/smp_lock.h>
17 16
18#include <asm/uaccess.h> 17#include <asm/uaccess.h>
19#include <asm/cio.h> 18#include <asm/cio.h>
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index a5050e217150..825951b6b83f 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -635,7 +635,7 @@ static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
635 init_subchannel_id(&mchk_schid); 635 init_subchannel_id(&mchk_schid);
636 mchk_schid.sch_no = crw0->rsid; 636 mchk_schid.sch_no = crw0->rsid;
637 if (crw1) 637 if (crw1)
638 mchk_schid.ssid = (crw1->rsid >> 8) & 3; 638 mchk_schid.ssid = (crw1->rsid >> 4) & 3;
639 639
640 /* 640 /*
641 * Since we are always presented with IPI in the CRW, we have to 641 * Since we are always presented with IPI in the CRW, we have to
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 2ff8a22d4257..e8391b89eff4 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1455,7 +1455,16 @@ static int io_subchannel_sch_event(struct subchannel *sch, int process)
1455 break; 1455 break;
1456 case IO_SCH_UNREG_ATTACH: 1456 case IO_SCH_UNREG_ATTACH:
1457 case IO_SCH_UNREG: 1457 case IO_SCH_UNREG:
1458 if (cdev) 1458 if (!cdev)
1459 break;
1460 if (cdev->private->state == DEV_STATE_SENSE_ID) {
1461 /*
1462 * Note: delayed work triggered by this event
1463 * and repeated calls to sch_event are synchronized
1464 * by the above check for work_pending(cdev).
1465 */
1466 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1467 } else
1459 ccw_device_set_notoper(cdev); 1468 ccw_device_set_notoper(cdev);
1460 break; 1469 break;
1461 case IO_SCH_NOP: 1470 case IO_SCH_NOP:
diff --git a/drivers/s390/cio/qdio_thinint.c b/drivers/s390/cio/qdio_thinint.c
index 752dbee06af5..5d9c66627b6e 100644
--- a/drivers/s390/cio/qdio_thinint.c
+++ b/drivers/s390/cio/qdio_thinint.c
@@ -292,8 +292,8 @@ void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
292 return; 292 return;
293 293
294 /* reset adapter interrupt indicators */ 294 /* reset adapter interrupt indicators */
295 put_indicator(irq_ptr->dsci);
296 set_subchannel_ind(irq_ptr, 1); 295 set_subchannel_ind(irq_ptr, 1);
296 put_indicator(irq_ptr->dsci);
297} 297}
298 298
299void __exit tiqdio_unregister_thinints(void) 299void __exit tiqdio_unregister_thinints(void)
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index f5221749d180..7fca9c10ffcf 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -35,7 +35,6 @@
35#include <linux/proc_fs.h> 35#include <linux/proc_fs.h>
36#include <linux/seq_file.h> 36#include <linux/seq_file.h>
37#include <linux/compat.h> 37#include <linux/compat.h>
38#include <linux/smp_lock.h>
39#include <linux/slab.h> 38#include <linux/slab.h>
40#include <asm/atomic.h> 39#include <asm/atomic.h>
41#include <asm/uaccess.h> 40#include <asm/uaccess.h>
diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h
index 6be43eb126b4..f47a714538db 100644
--- a/drivers/s390/net/qeth_core.h
+++ b/drivers/s390/net/qeth_core.h
@@ -440,7 +440,6 @@ struct qeth_qdio_out_q {
440 * index of buffer to be filled by driver; state EMPTY or PACKING 440 * index of buffer to be filled by driver; state EMPTY or PACKING
441 */ 441 */
442 int next_buf_to_fill; 442 int next_buf_to_fill;
443 int sync_iqdio_error;
444 /* 443 /*
445 * number of buffers that are currently filled (PRIMED) 444 * number of buffers that are currently filled (PRIMED)
446 * -> these buffers are hardware-owned 445 * -> these buffers are hardware-owned
@@ -695,14 +694,6 @@ struct qeth_mc_mac {
695 int is_vmac; 694 int is_vmac;
696}; 695};
697 696
698struct qeth_skb_data {
699 __u32 magic;
700 int count;
701};
702
703#define QETH_SKB_MAGIC 0x71657468
704#define QETH_SIGA_CC2_RETRIES 3
705
706struct qeth_rx { 697struct qeth_rx {
707 int b_count; 698 int b_count;
708 int b_index; 699 int b_index;
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 764267062601..e6b2df0e73f5 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -877,8 +877,8 @@ out:
877 return; 877 return;
878} 878}
879 879
880static void __qeth_clear_output_buffer(struct qeth_qdio_out_q *queue, 880static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
881 struct qeth_qdio_out_buffer *buf, unsigned int qeth_skip_skb) 881 struct qeth_qdio_out_buffer *buf)
882{ 882{
883 int i; 883 int i;
884 struct sk_buff *skb; 884 struct sk_buff *skb;
@@ -887,13 +887,11 @@ static void __qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
887 if (buf->buffer->element[0].flags & 0x40) 887 if (buf->buffer->element[0].flags & 0x40)
888 atomic_dec(&queue->set_pci_flags_count); 888 atomic_dec(&queue->set_pci_flags_count);
889 889
890 if (!qeth_skip_skb) { 890 skb = skb_dequeue(&buf->skb_list);
891 while (skb) {
892 atomic_dec(&skb->users);
893 dev_kfree_skb_any(skb);
891 skb = skb_dequeue(&buf->skb_list); 894 skb = skb_dequeue(&buf->skb_list);
892 while (skb) {
893 atomic_dec(&skb->users);
894 dev_kfree_skb_any(skb);
895 skb = skb_dequeue(&buf->skb_list);
896 }
897 } 895 }
898 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i) { 896 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i) {
899 if (buf->buffer->element[i].addr && buf->is_header[i]) 897 if (buf->buffer->element[i].addr && buf->is_header[i])
@@ -909,12 +907,6 @@ static void __qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
909 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY); 907 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
910} 908}
911 909
912static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
913 struct qeth_qdio_out_buffer *buf)
914{
915 __qeth_clear_output_buffer(queue, buf, 0);
916}
917
918void qeth_clear_qdio_buffers(struct qeth_card *card) 910void qeth_clear_qdio_buffers(struct qeth_card *card)
919{ 911{
920 int i, j; 912 int i, j;
@@ -2833,7 +2825,6 @@ static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
2833 } 2825 }
2834 } 2826 }
2835 2827
2836 queue->sync_iqdio_error = 0;
2837 queue->card->dev->trans_start = jiffies; 2828 queue->card->dev->trans_start = jiffies;
2838 if (queue->card->options.performance_stats) { 2829 if (queue->card->options.performance_stats) {
2839 queue->card->perf_stats.outbound_do_qdio_cnt++; 2830 queue->card->perf_stats.outbound_do_qdio_cnt++;
@@ -2849,10 +2840,6 @@ static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
2849 queue->card->perf_stats.outbound_do_qdio_time += 2840 queue->card->perf_stats.outbound_do_qdio_time +=
2850 qeth_get_micros() - 2841 qeth_get_micros() -
2851 queue->card->perf_stats.outbound_do_qdio_start_time; 2842 queue->card->perf_stats.outbound_do_qdio_start_time;
2852 if (rc > 0) {
2853 if (!(rc & QDIO_ERROR_SIGA_BUSY))
2854 queue->sync_iqdio_error = rc & 3;
2855 }
2856 if (rc) { 2843 if (rc) {
2857 queue->card->stats.tx_errors += count; 2844 queue->card->stats.tx_errors += count;
2858 /* ignore temporary SIGA errors without busy condition */ 2845 /* ignore temporary SIGA errors without busy condition */
@@ -2916,7 +2903,7 @@ void qeth_qdio_start_poll(struct ccw_device *ccwdev, int queue,
2916{ 2903{
2917 struct qeth_card *card = (struct qeth_card *)card_ptr; 2904 struct qeth_card *card = (struct qeth_card *)card_ptr;
2918 2905
2919 if (card->dev) 2906 if (card->dev && (card->dev->flags & IFF_UP))
2920 napi_schedule(&card->napi); 2907 napi_schedule(&card->napi);
2921} 2908}
2922EXPORT_SYMBOL_GPL(qeth_qdio_start_poll); 2909EXPORT_SYMBOL_GPL(qeth_qdio_start_poll);
@@ -2940,7 +2927,6 @@ void qeth_qdio_output_handler(struct ccw_device *ccwdev,
2940 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue]; 2927 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
2941 struct qeth_qdio_out_buffer *buffer; 2928 struct qeth_qdio_out_buffer *buffer;
2942 int i; 2929 int i;
2943 unsigned qeth_send_err;
2944 2930
2945 QETH_CARD_TEXT(card, 6, "qdouhdl"); 2931 QETH_CARD_TEXT(card, 6, "qdouhdl");
2946 if (qdio_error & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) { 2932 if (qdio_error & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
@@ -2956,9 +2942,8 @@ void qeth_qdio_output_handler(struct ccw_device *ccwdev,
2956 } 2942 }
2957 for (i = first_element; i < (first_element + count); ++i) { 2943 for (i = first_element; i < (first_element + count); ++i) {
2958 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; 2944 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2959 qeth_send_err = qeth_handle_send_error(card, buffer, qdio_error); 2945 qeth_handle_send_error(card, buffer, qdio_error);
2960 __qeth_clear_output_buffer(queue, buffer, 2946 qeth_clear_output_buffer(queue, buffer);
2961 (qeth_send_err == QETH_SEND_ERROR_RETRY) ? 1 : 0);
2962 } 2947 }
2963 atomic_sub(count, &queue->used_buffers); 2948 atomic_sub(count, &queue->used_buffers);
2964 /* check if we need to do something on this outbound queue */ 2949 /* check if we need to do something on this outbound queue */
@@ -3183,10 +3168,7 @@ int qeth_do_send_packet_fast(struct qeth_card *card,
3183 int offset, int hd_len) 3168 int offset, int hd_len)
3184{ 3169{
3185 struct qeth_qdio_out_buffer *buffer; 3170 struct qeth_qdio_out_buffer *buffer;
3186 struct sk_buff *skb1;
3187 struct qeth_skb_data *retry_ctrl;
3188 int index; 3171 int index;
3189 int rc;
3190 3172
3191 /* spin until we get the queue ... */ 3173 /* spin until we get the queue ... */
3192 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED, 3174 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
@@ -3205,25 +3187,6 @@ int qeth_do_send_packet_fast(struct qeth_card *card,
3205 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); 3187 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3206 qeth_fill_buffer(queue, buffer, skb, hdr, offset, hd_len); 3188 qeth_fill_buffer(queue, buffer, skb, hdr, offset, hd_len);
3207 qeth_flush_buffers(queue, index, 1); 3189 qeth_flush_buffers(queue, index, 1);
3208 if (queue->sync_iqdio_error == 2) {
3209 skb1 = skb_dequeue(&buffer->skb_list);
3210 while (skb1) {
3211 atomic_dec(&skb1->users);
3212 skb1 = skb_dequeue(&buffer->skb_list);
3213 }
3214 retry_ctrl = (struct qeth_skb_data *) &skb->cb[16];
3215 if (retry_ctrl->magic != QETH_SKB_MAGIC) {
3216 retry_ctrl->magic = QETH_SKB_MAGIC;
3217 retry_ctrl->count = 0;
3218 }
3219 if (retry_ctrl->count < QETH_SIGA_CC2_RETRIES) {
3220 retry_ctrl->count++;
3221 rc = dev_queue_xmit(skb);
3222 } else {
3223 dev_kfree_skb_any(skb);
3224 QETH_CARD_TEXT(card, 2, "qrdrop");
3225 }
3226 }
3227 return 0; 3190 return 0;
3228out: 3191out:
3229 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); 3192 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index d37c7331f244..0bcd5806bd9a 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -156,6 +156,8 @@ static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
156 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) || 156 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
157 a_status & ZFCP_STATUS_COMMON_ERP_FAILED) 157 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
158 return 0; 158 return 0;
159 if (p_status & ZFCP_STATUS_COMMON_NOESC)
160 return need;
159 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED)) 161 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
160 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER; 162 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
161 /* fall through */ 163 /* fall through */
@@ -188,6 +190,9 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need, u32 act_status,
188 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, 190 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
189 &zfcp_sdev->status); 191 &zfcp_sdev->status);
190 erp_action = &zfcp_sdev->erp_action; 192 erp_action = &zfcp_sdev->erp_action;
193 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
194 erp_action->port = port;
195 erp_action->sdev = sdev;
191 if (!(atomic_read(&zfcp_sdev->status) & 196 if (!(atomic_read(&zfcp_sdev->status) &
192 ZFCP_STATUS_COMMON_RUNNING)) 197 ZFCP_STATUS_COMMON_RUNNING))
193 act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY; 198 act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY;
@@ -200,6 +205,8 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need, u32 act_status,
200 zfcp_erp_action_dismiss_port(port); 205 zfcp_erp_action_dismiss_port(port);
201 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status); 206 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
202 erp_action = &port->erp_action; 207 erp_action = &port->erp_action;
208 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
209 erp_action->port = port;
203 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING)) 210 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
204 act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY; 211 act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY;
205 break; 212 break;
@@ -209,6 +216,7 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need, u32 act_status,
209 zfcp_erp_action_dismiss_adapter(adapter); 216 zfcp_erp_action_dismiss_adapter(adapter);
210 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status); 217 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
211 erp_action = &adapter->erp_action; 218 erp_action = &adapter->erp_action;
219 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
212 if (!(atomic_read(&adapter->status) & 220 if (!(atomic_read(&adapter->status) &
213 ZFCP_STATUS_COMMON_RUNNING)) 221 ZFCP_STATUS_COMMON_RUNNING))
214 act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY; 222 act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY;
@@ -218,10 +226,7 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need, u32 act_status,
218 return NULL; 226 return NULL;
219 } 227 }
220 228
221 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
222 erp_action->adapter = adapter; 229 erp_action->adapter = adapter;
223 erp_action->port = port;
224 erp_action->sdev = sdev;
225 erp_action->action = need; 230 erp_action->action = need;
226 erp_action->status = act_status; 231 erp_action->status = act_status;
227 232
diff --git a/drivers/s390/scsi/zfcp_fc.h b/drivers/s390/scsi/zfcp_fc.h
index 938d50360166..b464ae01086c 100644
--- a/drivers/s390/scsi/zfcp_fc.h
+++ b/drivers/s390/scsi/zfcp_fc.h
@@ -270,7 +270,7 @@ void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
270 if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) { 270 if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
271 sense = (char *) &fcp_rsp[1]; 271 sense = (char *) &fcp_rsp[1];
272 if (rsp_flags & FCP_RSP_LEN_VAL) 272 if (rsp_flags & FCP_RSP_LEN_VAL)
273 sense += fcp_rsp->ext.fr_sns_len; 273 sense += fcp_rsp->ext.fr_rsp_len;
274 sense_len = min(fcp_rsp->ext.fr_sns_len, 274 sense_len = min(fcp_rsp->ext.fr_sns_len,
275 (u32) SCSI_SENSE_BUFFERSIZE); 275 (u32) SCSI_SENSE_BUFFERSIZE);
276 memcpy(scsi->sense_buffer, sense, sense_len); 276 memcpy(scsi->sense_buffer, sense, sense_len);
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index beaf0916ceab..2eb7dd56ab80 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -532,9 +532,6 @@ static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
532 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; 532 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
533 adapter->hydra_version = 0; 533 adapter->hydra_version = 0;
534 534
535 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
536 &adapter->status);
537
538 zfcp_fsf_link_down_info_eval(req, 535 zfcp_fsf_link_down_info_eval(req,
539 &qtcb->header.fsf_status_qual.link_down_info); 536 &qtcb->header.fsf_status_qual.link_down_info);
540 break; 537 break;
@@ -854,7 +851,7 @@ struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
854 851
855 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); 852 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
856 853
857 req->data = zfcp_sdev; 854 req->data = sdev;
858 req->handler = zfcp_fsf_abort_fcp_command_handler; 855 req->handler = zfcp_fsf_abort_fcp_command_handler;
859 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; 856 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
860 req->qtcb->header.port_handle = zfcp_sdev->port->handle; 857 req->qtcb->header.port_handle = zfcp_sdev->port->handle;
@@ -2072,8 +2069,6 @@ static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2072 struct fcp_resp_with_ext *fcp_rsp; 2069 struct fcp_resp_with_ext *fcp_rsp;
2073 unsigned long flags; 2070 unsigned long flags;
2074 2071
2075 zfcp_fsf_fcp_handler_common(req);
2076
2077 read_lock_irqsave(&req->adapter->abort_lock, flags); 2072 read_lock_irqsave(&req->adapter->abort_lock, flags);
2078 2073
2079 scpnt = req->data; 2074 scpnt = req->data;
@@ -2082,6 +2077,8 @@ static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
2082 return; 2077 return;
2083 } 2078 }
2084 2079
2080 zfcp_fsf_fcp_handler_common(req);
2081
2085 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { 2082 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2086 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED); 2083 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2087 goto skip_fsfstatus; 2084 goto skip_fsfstatus;
@@ -2173,12 +2170,13 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
2173 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; 2170 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
2174 struct zfcp_qdio *qdio = adapter->qdio; 2171 struct zfcp_qdio *qdio = adapter->qdio;
2175 struct fsf_qtcb_bottom_io *io; 2172 struct fsf_qtcb_bottom_io *io;
2173 unsigned long flags;
2176 2174
2177 if (unlikely(!(atomic_read(&zfcp_sdev->status) & 2175 if (unlikely(!(atomic_read(&zfcp_sdev->status) &
2178 ZFCP_STATUS_COMMON_UNBLOCKED))) 2176 ZFCP_STATUS_COMMON_UNBLOCKED)))
2179 return -EBUSY; 2177 return -EBUSY;
2180 2178
2181 spin_lock(&qdio->req_q_lock); 2179 spin_lock_irqsave(&qdio->req_q_lock, flags);
2182 if (atomic_read(&qdio->req_q_free) <= 0) { 2180 if (atomic_read(&qdio->req_q_free) <= 0) {
2183 atomic_inc(&qdio->req_q_full); 2181 atomic_inc(&qdio->req_q_full);
2184 goto out; 2182 goto out;
@@ -2242,7 +2240,7 @@ failed_scsi_cmnd:
2242 zfcp_fsf_req_free(req); 2240 zfcp_fsf_req_free(req);
2243 scsi_cmnd->host_scribble = NULL; 2241 scsi_cmnd->host_scribble = NULL;
2244out: 2242out:
2245 spin_unlock(&qdio->req_q_lock); 2243 spin_unlock_irqrestore(&qdio->req_q_lock, flags);
2246 return retval; 2244 return retval;
2247} 2245}
2248 2246
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 50286d8707f3..63529ed801eb 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -76,8 +76,8 @@ static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
76 scpnt->scsi_done(scpnt); 76 scpnt->scsi_done(scpnt);
77} 77}
78 78
79static int zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt, 79static
80 void (*done) (struct scsi_cmnd *)) 80int zfcp_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scpnt)
81{ 81{
82 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); 82 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
83 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; 83 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
@@ -87,7 +87,6 @@ static int zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
87 /* reset the status for this request */ 87 /* reset the status for this request */
88 scpnt->result = 0; 88 scpnt->result = 0;
89 scpnt->host_scribble = NULL; 89 scpnt->host_scribble = NULL;
90 scpnt->scsi_done = done;
91 90
92 scsi_result = fc_remote_port_chkready(rport); 91 scsi_result = fc_remote_port_chkready(rport);
93 if (unlikely(scsi_result)) { 92 if (unlikely(scsi_result)) {
diff --git a/drivers/s390/scsi/zfcp_unit.c b/drivers/s390/scsi/zfcp_unit.c
index 1119c535a667..20796ebc33ce 100644
--- a/drivers/s390/scsi/zfcp_unit.c
+++ b/drivers/s390/scsi/zfcp_unit.c
@@ -142,6 +142,8 @@ int zfcp_unit_add(struct zfcp_port *port, u64 fcp_lun)
142 return -ENOMEM; 142 return -ENOMEM;
143 } 143 }
144 144
145 get_device(&port->dev);
146
145 if (device_register(&unit->dev)) { 147 if (device_register(&unit->dev)) {
146 put_device(&unit->dev); 148 put_device(&unit->dev);
147 return -ENOMEM; 149 return -ENOMEM;
@@ -152,8 +154,6 @@ int zfcp_unit_add(struct zfcp_port *port, u64 fcp_lun)
152 return -EINVAL; 154 return -EINVAL;
153 } 155 }
154 156
155 get_device(&port->dev);
156
157 write_lock_irq(&port->unit_list_lock); 157 write_lock_irq(&port->unit_list_lock);
158 list_add_tail(&unit->list, &port->unit_list); 158 list_add_tail(&unit->list, &port->unit_list);
159 write_unlock_irq(&port->unit_list_lock); 159 write_unlock_irq(&port->unit_list_lock);
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index fcf08b3f52c1..b7bd5b0cc7aa 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1765,7 +1765,7 @@ out:
1765} /* End twa_scsi_eh_reset() */ 1765} /* End twa_scsi_eh_reset() */
1766 1766
1767/* This is the main scsi queue function to handle scsi opcodes */ 1767/* This is the main scsi queue function to handle scsi opcodes */
1768static int twa_scsi_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 1768static int twa_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1769{ 1769{
1770 int request_id, retval; 1770 int request_id, retval;
1771 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; 1771 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
@@ -1812,6 +1812,8 @@ out:
1812 return retval; 1812 return retval;
1813} /* End twa_scsi_queue() */ 1813} /* End twa_scsi_queue() */
1814 1814
1815static DEF_SCSI_QCMD(twa_scsi_queue)
1816
1815/* This function hands scsi cdb's to the firmware */ 1817/* This function hands scsi cdb's to the firmware */
1816static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_sg, TW_SG_Entry *sglistarg) 1818static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_sg, TW_SG_Entry *sglistarg)
1817{ 1819{
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 6a95d111d207..13e39e1fdfe2 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -1501,7 +1501,7 @@ out:
1501} /* End twl_scsi_eh_reset() */ 1501} /* End twl_scsi_eh_reset() */
1502 1502
1503/* This is the main scsi queue function to handle scsi opcodes */ 1503/* This is the main scsi queue function to handle scsi opcodes */
1504static int twl_scsi_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 1504static int twl_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1505{ 1505{
1506 int request_id, retval; 1506 int request_id, retval;
1507 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; 1507 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
@@ -1536,6 +1536,8 @@ out:
1536 return retval; 1536 return retval;
1537} /* End twl_scsi_queue() */ 1537} /* End twl_scsi_queue() */
1538 1538
1539static DEF_SCSI_QCMD(twl_scsi_queue)
1540
1539/* This function tells the controller to shut down */ 1541/* This function tells the controller to shut down */
1540static void __twl_shutdown(TW_Device_Extension *tw_dev) 1542static void __twl_shutdown(TW_Device_Extension *tw_dev)
1541{ 1543{
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index b1125341f4c8..7fe96ff60c58 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1947,7 +1947,7 @@ static int tw_scsiop_test_unit_ready_complete(TW_Device_Extension *tw_dev, int r
1947} /* End tw_scsiop_test_unit_ready_complete() */ 1947} /* End tw_scsiop_test_unit_ready_complete() */
1948 1948
1949/* This is the main scsi queue function to handle scsi opcodes */ 1949/* This is the main scsi queue function to handle scsi opcodes */
1950static int tw_scsi_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 1950static int tw_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1951{ 1951{
1952 unsigned char *command = SCpnt->cmnd; 1952 unsigned char *command = SCpnt->cmnd;
1953 int request_id = 0; 1953 int request_id = 0;
@@ -2023,6 +2023,8 @@ static int tw_scsi_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd
2023 return retval; 2023 return retval;
2024} /* End tw_scsi_queue() */ 2024} /* End tw_scsi_queue() */
2025 2025
2026static DEF_SCSI_QCMD(tw_scsi_queue)
2027
2026/* This function is the interrupt service routine */ 2028/* This function is the interrupt service routine */
2027static irqreturn_t tw_interrupt(int irq, void *dev_instance) 2029static irqreturn_t tw_interrupt(int irq, void *dev_instance)
2028{ 2030{
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index 89fc1c8af86b..f672491774eb 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -167,7 +167,7 @@ MODULE_LICENSE("GPL");
167#include "53c700_d.h" 167#include "53c700_d.h"
168 168
169 169
170STATIC int NCR_700_queuecommand(struct scsi_cmnd *, void (*done)(struct scsi_cmnd *)); 170STATIC int NCR_700_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *);
171STATIC int NCR_700_abort(struct scsi_cmnd * SCpnt); 171STATIC int NCR_700_abort(struct scsi_cmnd * SCpnt);
172STATIC int NCR_700_bus_reset(struct scsi_cmnd * SCpnt); 172STATIC int NCR_700_bus_reset(struct scsi_cmnd * SCpnt);
173STATIC int NCR_700_host_reset(struct scsi_cmnd * SCpnt); 173STATIC int NCR_700_host_reset(struct scsi_cmnd * SCpnt);
@@ -1749,8 +1749,8 @@ NCR_700_intr(int irq, void *dev_id)
1749 return IRQ_RETVAL(handled); 1749 return IRQ_RETVAL(handled);
1750} 1750}
1751 1751
1752STATIC int 1752static int
1753NCR_700_queuecommand(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *)) 1753NCR_700_queuecommand_lck(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *))
1754{ 1754{
1755 struct NCR_700_Host_Parameters *hostdata = 1755 struct NCR_700_Host_Parameters *hostdata =
1756 (struct NCR_700_Host_Parameters *)SCp->device->host->hostdata[0]; 1756 (struct NCR_700_Host_Parameters *)SCp->device->host->hostdata[0];
@@ -1904,6 +1904,8 @@ NCR_700_queuecommand(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *))
1904 return 0; 1904 return 0;
1905} 1905}
1906 1906
1907STATIC DEF_SCSI_QCMD(NCR_700_queuecommand)
1908
1907STATIC int 1909STATIC int
1908NCR_700_abort(struct scsi_cmnd * SCp) 1910NCR_700_abort(struct scsi_cmnd * SCp)
1909{ 1911{
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index fc0b4b81d552..f66c33b9ab41 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -2807,7 +2807,7 @@ static int BusLogic_host_reset(struct scsi_cmnd * SCpnt)
2807 Outgoing Mailbox for execution by the associated Host Adapter. 2807 Outgoing Mailbox for execution by the associated Host Adapter.
2808*/ 2808*/
2809 2809
2810static int BusLogic_QueueCommand(struct scsi_cmnd *Command, void (*CompletionRoutine) (struct scsi_cmnd *)) 2810static int BusLogic_QueueCommand_lck(struct scsi_cmnd *Command, void (*CompletionRoutine) (struct scsi_cmnd *))
2811{ 2811{
2812 struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) Command->device->host->hostdata; 2812 struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) Command->device->host->hostdata;
2813 struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[Command->device->id]; 2813 struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[Command->device->id];
@@ -2994,6 +2994,7 @@ static int BusLogic_QueueCommand(struct scsi_cmnd *Command, void (*CompletionRou
2994 return 0; 2994 return 0;
2995} 2995}
2996 2996
2997static DEF_SCSI_QCMD(BusLogic_QueueCommand)
2997 2998
2998#if 0 2999#if 0
2999/* 3000/*
diff --git a/drivers/scsi/BusLogic.h b/drivers/scsi/BusLogic.h
index 73f237a1ed94..649fcb31f26d 100644
--- a/drivers/scsi/BusLogic.h
+++ b/drivers/scsi/BusLogic.h
@@ -1319,7 +1319,7 @@ static inline void BusLogic_IncrementSizeBucket(BusLogic_CommandSizeBuckets_T Co
1319*/ 1319*/
1320 1320
1321static const char *BusLogic_DriverInfo(struct Scsi_Host *); 1321static const char *BusLogic_DriverInfo(struct Scsi_Host *);
1322static int BusLogic_QueueCommand(struct scsi_cmnd *, void (*CompletionRoutine) (struct scsi_cmnd *)); 1322static int BusLogic_QueueCommand(struct Scsi_Host *h, struct scsi_cmnd *);
1323static int BusLogic_BIOSDiskParameters(struct scsi_device *, struct block_device *, sector_t, int *); 1323static int BusLogic_BIOSDiskParameters(struct scsi_device *, struct block_device *, sector_t, int *);
1324static int BusLogic_ProcDirectoryInfo(struct Scsi_Host *, char *, char **, off_t, int, int); 1324static int BusLogic_ProcDirectoryInfo(struct Scsi_Host *, char *, char **, off_t, int, int);
1325static int BusLogic_SlaveConfigure(struct scsi_device *); 1325static int BusLogic_SlaveConfigure(struct scsi_device *);
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 5d2f148889ad..9a5629f94f95 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -952,7 +952,7 @@ static void NCR5380_exit(struct Scsi_Host *instance)
952 * Locks: host lock taken by caller 952 * Locks: host lock taken by caller
953 */ 953 */
954 954
955static int NCR5380_queue_command(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) 955static int NCR5380_queue_command_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
956{ 956{
957 struct Scsi_Host *instance = cmd->device->host; 957 struct Scsi_Host *instance = cmd->device->host;
958 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata; 958 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata;
@@ -1021,6 +1021,7 @@ static int NCR5380_queue_command(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
1021 return 0; 1021 return 0;
1022} 1022}
1023 1023
1024static DEF_SCSI_QCMD(NCR5380_queue_command)
1024 1025
1025/** 1026/**
1026 * NCR5380_main - NCR state machines 1027 * NCR5380_main - NCR state machines
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index bdc468c9e1d9..fd40a32b1f6f 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -313,7 +313,7 @@ static void NCR5380_print(struct Scsi_Host *instance);
313#endif 313#endif
314static int NCR5380_abort(Scsi_Cmnd * cmd); 314static int NCR5380_abort(Scsi_Cmnd * cmd);
315static int NCR5380_bus_reset(Scsi_Cmnd * cmd); 315static int NCR5380_bus_reset(Scsi_Cmnd * cmd);
316static int NCR5380_queue_command(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)); 316static int NCR5380_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
317static int __maybe_unused NCR5380_proc_info(struct Scsi_Host *instance, 317static int __maybe_unused NCR5380_proc_info(struct Scsi_Host *instance,
318 char *buffer, char **start, off_t offset, int length, int inout); 318 char *buffer, char **start, off_t offset, int length, int inout);
319 319
diff --git a/drivers/scsi/NCR53c406a.c b/drivers/scsi/NCR53c406a.c
index 6961f78742ae..c91888a0a23c 100644
--- a/drivers/scsi/NCR53c406a.c
+++ b/drivers/scsi/NCR53c406a.c
@@ -693,7 +693,7 @@ static void wait_intr(void)
693} 693}
694#endif 694#endif
695 695
696static int NCR53c406a_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *)) 696static int NCR53c406a_queue_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
697{ 697{
698 int i; 698 int i;
699 699
@@ -726,6 +726,8 @@ static int NCR53c406a_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
726 return 0; 726 return 0;
727} 727}
728 728
729static DEF_SCSI_QCMD(NCR53c406a_queue)
730
729static int NCR53c406a_host_reset(Scsi_Cmnd * SCpnt) 731static int NCR53c406a_host_reset(Scsi_Cmnd * SCpnt)
730{ 732{
731 DEB(printk("NCR53c406a_reset called\n")); 733 DEB(printk("NCR53c406a_reset called\n"));
diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index 7cb575654e40..a391090a17c5 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -911,7 +911,7 @@ static int inia100_build_scb(struct orc_host * host, struct orc_scb * scb, struc
911 * queue the command down to the controller 911 * queue the command down to the controller
912 */ 912 */
913 913
914static int inia100_queue(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *)) 914static int inia100_queue_lck(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
915{ 915{
916 struct orc_scb *scb; 916 struct orc_scb *scb;
917 struct orc_host *host; /* Point to Host adapter control block */ 917 struct orc_host *host; /* Point to Host adapter control block */
@@ -930,6 +930,8 @@ static int inia100_queue(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd
930 return 0; 930 return 0;
931} 931}
932 932
933static DEF_SCSI_QCMD(inia100_queue)
934
933/***************************************************************************** 935/*****************************************************************************
934 Function name : inia100_abort 936 Function name : inia100_abort
935 Description : Abort a queued command. 937 Description : Abort a queued command.
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 29c0ed1cf507..2c93d9496d62 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -248,7 +248,7 @@ static struct aac_driver_ident aac_drivers[] = {
248 * TODO: unify with aac_scsi_cmd(). 248 * TODO: unify with aac_scsi_cmd().
249 */ 249 */
250 250
251static int aac_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 251static int aac_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
252{ 252{
253 struct Scsi_Host *host = cmd->device->host; 253 struct Scsi_Host *host = cmd->device->host;
254 struct aac_dev *dev = (struct aac_dev *)host->hostdata; 254 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
@@ -267,6 +267,8 @@ static int aac_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd
267 return (aac_scsi_cmd(cmd) ? FAILED : 0); 267 return (aac_scsi_cmd(cmd) ? FAILED : 0);
268} 268}
269 269
270static DEF_SCSI_QCMD(aac_queuecommand)
271
270/** 272/**
271 * aac_info - Returns the host adapter name 273 * aac_info - Returns the host adapter name
272 * @shost: Scsi host to report on 274 * @shost: Scsi host to report on
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 0ec3da6f3e12..081c6de92bc5 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -9500,7 +9500,7 @@ static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
9500 * in the 'scp' result field. 9500 * in the 'scp' result field.
9501 */ 9501 */
9502static int 9502static int
9503advansys_queuecommand(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *)) 9503advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
9504{ 9504{
9505 struct Scsi_Host *shost = scp->device->host; 9505 struct Scsi_Host *shost = scp->device->host;
9506 int asc_res, result = 0; 9506 int asc_res, result = 0;
@@ -9525,6 +9525,8 @@ advansys_queuecommand(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
9525 return result; 9525 return result;
9526} 9526}
9527 9527
9528static DEF_SCSI_QCMD(advansys_queuecommand)
9529
9528static ushort __devinit AscGetEisaChipCfg(PortAddr iop_base) 9530static ushort __devinit AscGetEisaChipCfg(PortAddr iop_base)
9529{ 9531{
9530 PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) | 9532 PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index 8eab8587ff21..c5169f01c1cd 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -1056,7 +1056,7 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
1056 * queue a command 1056 * queue a command
1057 * 1057 *
1058 */ 1058 */
1059static int aha152x_queue(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) 1059static int aha152x_queue_lck(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
1060{ 1060{
1061#if 0 1061#if 0
1062 if(*SCpnt->cmnd == REQUEST_SENSE) { 1062 if(*SCpnt->cmnd == REQUEST_SENSE) {
@@ -1070,6 +1070,8 @@ static int aha152x_queue(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
1070 return aha152x_internal_queue(SCpnt, NULL, 0, done); 1070 return aha152x_internal_queue(SCpnt, NULL, 0, done);
1071} 1071}
1072 1072
1073static DEF_SCSI_QCMD(aha152x_queue)
1074
1073 1075
1074/* 1076/*
1075 * 1077 *
diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index 4f785f254c1f..195823a51aab 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -558,7 +558,7 @@ static void aha1542_intr_handle(struct Scsi_Host *shost)
558 }; 558 };
559} 559}
560 560
561static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *)) 561static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
562{ 562{
563 unchar ahacmd = CMD_START_SCSI; 563 unchar ahacmd = CMD_START_SCSI;
564 unchar direction; 564 unchar direction;
@@ -718,6 +718,8 @@ static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
718 return 0; 718 return 0;
719} 719}
720 720
721static DEF_SCSI_QCMD(aha1542_queuecommand)
722
721/* Initialize mailboxes */ 723/* Initialize mailboxes */
722static void setup_mailboxes(int bse, struct Scsi_Host *shpnt) 724static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)
723{ 725{
diff --git a/drivers/scsi/aha1542.h b/drivers/scsi/aha1542.h
index 1db538552d56..b871d2b57f93 100644
--- a/drivers/scsi/aha1542.h
+++ b/drivers/scsi/aha1542.h
@@ -132,7 +132,7 @@ struct ccb { /* Command Control Block 5.3 */
132}; 132};
133 133
134static int aha1542_detect(struct scsi_host_template *); 134static int aha1542_detect(struct scsi_host_template *);
135static int aha1542_queuecommand(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *)); 135static int aha1542_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
136static int aha1542_bus_reset(Scsi_Cmnd * SCpnt); 136static int aha1542_bus_reset(Scsi_Cmnd * SCpnt);
137static int aha1542_dev_reset(Scsi_Cmnd * SCpnt); 137static int aha1542_dev_reset(Scsi_Cmnd * SCpnt);
138static int aha1542_host_reset(Scsi_Cmnd * SCpnt); 138static int aha1542_host_reset(Scsi_Cmnd * SCpnt);
diff --git a/drivers/scsi/aha1740.c b/drivers/scsi/aha1740.c
index 0107a4cc3331..d058f1ab82b5 100644
--- a/drivers/scsi/aha1740.c
+++ b/drivers/scsi/aha1740.c
@@ -331,7 +331,7 @@ static irqreturn_t aha1740_intr_handle(int irq, void *dev_id)
331 return IRQ_RETVAL(handled); 331 return IRQ_RETVAL(handled);
332} 332}
333 333
334static int aha1740_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *)) 334static int aha1740_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
335{ 335{
336 unchar direction; 336 unchar direction;
337 unchar *cmd = (unchar *) SCpnt->cmnd; 337 unchar *cmd = (unchar *) SCpnt->cmnd;
@@ -503,6 +503,8 @@ static int aha1740_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
503 return 0; 503 return 0;
504} 504}
505 505
506static DEF_SCSI_QCMD(aha1740_queuecommand)
507
506/* Query the board for its irq_level and irq_type. Nothing else matters 508/* Query the board for its irq_level and irq_type. Nothing else matters
507 in enhanced mode on an EISA bus. */ 509 in enhanced mode on an EISA bus. */
508 510
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 88ad8482ef59..25d066624476 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -573,7 +573,7 @@ ahd_linux_info(struct Scsi_Host *host)
573 * Queue an SCB to the controller. 573 * Queue an SCB to the controller.
574 */ 574 */
575static int 575static int
576ahd_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *)) 576ahd_linux_queue_lck(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
577{ 577{
578 struct ahd_softc *ahd; 578 struct ahd_softc *ahd;
579 struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device); 579 struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device);
@@ -588,6 +588,8 @@ ahd_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
588 return rtn; 588 return rtn;
589} 589}
590 590
591static DEF_SCSI_QCMD(ahd_linux_queue)
592
591static struct scsi_target ** 593static struct scsi_target **
592ahd_linux_target_in_softc(struct scsi_target *starget) 594ahd_linux_target_in_softc(struct scsi_target *starget)
593{ 595{
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index aeea7a61478e..4a359bb307c6 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -528,7 +528,7 @@ ahc_linux_info(struct Scsi_Host *host)
528 * Queue an SCB to the controller. 528 * Queue an SCB to the controller.
529 */ 529 */
530static int 530static int
531ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *)) 531ahc_linux_queue_lck(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
532{ 532{
533 struct ahc_softc *ahc; 533 struct ahc_softc *ahc;
534 struct ahc_linux_device *dev = scsi_transport_device_data(cmd->device); 534 struct ahc_linux_device *dev = scsi_transport_device_data(cmd->device);
@@ -548,6 +548,8 @@ ahc_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
548 return rtn; 548 return rtn;
549} 549}
550 550
551static DEF_SCSI_QCMD(ahc_linux_queue)
552
551static inline struct scsi_target ** 553static inline struct scsi_target **
552ahc_linux_target_in_softc(struct scsi_target *starget) 554ahc_linux_target_in_softc(struct scsi_target *starget)
553{ 555{
diff --git a/drivers/scsi/aic7xxx_old.c b/drivers/scsi/aic7xxx_old.c
index aee73fafccc8..4ff60a08df0f 100644
--- a/drivers/scsi/aic7xxx_old.c
+++ b/drivers/scsi/aic7xxx_old.c
@@ -10234,7 +10234,7 @@ static void aic7xxx_buildscb(struct aic7xxx_host *p, struct scsi_cmnd *cmd,
10234 * Description: 10234 * Description:
10235 * Queue a SCB to the controller. 10235 * Queue a SCB to the controller.
10236 *-F*************************************************************************/ 10236 *-F*************************************************************************/
10237static int aic7xxx_queue(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *)) 10237static int aic7xxx_queue_lck(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
10238{ 10238{
10239 struct aic7xxx_host *p; 10239 struct aic7xxx_host *p;
10240 struct aic7xxx_scb *scb; 10240 struct aic7xxx_scb *scb;
@@ -10292,6 +10292,8 @@ static int aic7xxx_queue(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
10292 return (0); 10292 return (0);
10293} 10293}
10294 10294
10295static DEF_SCSI_QCMD(aic7xxx_queue)
10296
10295/*+F************************************************************************* 10297/*+F*************************************************************************
10296 * Function: 10298 * Function:
10297 * aic7xxx_bus_device_reset 10299 * aic7xxx_bus_device_reset
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 05a78e515a24..17e3df4f016f 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -85,8 +85,7 @@ static int arcmsr_abort(struct scsi_cmnd *);
85static int arcmsr_bus_reset(struct scsi_cmnd *); 85static int arcmsr_bus_reset(struct scsi_cmnd *);
86static int arcmsr_bios_param(struct scsi_device *sdev, 86static int arcmsr_bios_param(struct scsi_device *sdev,
87 struct block_device *bdev, sector_t capacity, int *info); 87 struct block_device *bdev, sector_t capacity, int *info);
88static int arcmsr_queue_command(struct scsi_cmnd *cmd, 88static int arcmsr_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd);
89 void (*done) (struct scsi_cmnd *));
90static int arcmsr_probe(struct pci_dev *pdev, 89static int arcmsr_probe(struct pci_dev *pdev,
91 const struct pci_device_id *id); 90 const struct pci_device_id *id);
92static void arcmsr_remove(struct pci_dev *pdev); 91static void arcmsr_remove(struct pci_dev *pdev);
@@ -2081,7 +2080,7 @@ static void arcmsr_handle_virtual_command(struct AdapterControlBlock *acb,
2081 } 2080 }
2082} 2081}
2083 2082
2084static int arcmsr_queue_command(struct scsi_cmnd *cmd, 2083static int arcmsr_queue_command_lck(struct scsi_cmnd *cmd,
2085 void (* done)(struct scsi_cmnd *)) 2084 void (* done)(struct scsi_cmnd *))
2086{ 2085{
2087 struct Scsi_Host *host = cmd->device->host; 2086 struct Scsi_Host *host = cmd->device->host;
@@ -2124,6 +2123,8 @@ static int arcmsr_queue_command(struct scsi_cmnd *cmd,
2124 return 0; 2123 return 0;
2125} 2124}
2126 2125
2126static DEF_SCSI_QCMD(arcmsr_queue_command)
2127
2127static bool arcmsr_get_hba_config(struct AdapterControlBlock *acb) 2128static bool arcmsr_get_hba_config(struct AdapterControlBlock *acb)
2128{ 2129{
2129 struct MessageUnit_A __iomem *reg = acb->pmuA; 2130 struct MessageUnit_A __iomem *reg = acb->pmuA;
diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index 918ccf818757..ec166726b314 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -2511,7 +2511,7 @@ acornscsi_intr(int irq, void *dev_id)
2511 * done - function called on completion, with pointer to command descriptor 2511 * done - function called on completion, with pointer to command descriptor
2512 * Returns : 0, or < 0 on error. 2512 * Returns : 0, or < 0 on error.
2513 */ 2513 */
2514int acornscsi_queuecmd(struct scsi_cmnd *SCpnt, 2514static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt,
2515 void (*done)(struct scsi_cmnd *)) 2515 void (*done)(struct scsi_cmnd *))
2516{ 2516{
2517 AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata; 2517 AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
@@ -2561,6 +2561,8 @@ int acornscsi_queuecmd(struct scsi_cmnd *SCpnt,
2561 return 0; 2561 return 0;
2562} 2562}
2563 2563
2564DEF_SCSI_QCMD(acornscsi_queuecmd)
2565
2564/* 2566/*
2565 * Prototype: void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, struct scsi_cmnd **SCpntp2, int result) 2567 * Prototype: void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, struct scsi_cmnd **SCpntp2, int result)
2566 * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2 2568 * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 9e71ac611146..2b2ce21e227e 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2198,7 +2198,7 @@ no_command:
2198 * Returns: 0 on success, else error. 2198 * Returns: 0 on success, else error.
2199 * Notes: io_request_lock is held, interrupts are disabled. 2199 * Notes: io_request_lock is held, interrupts are disabled.
2200 */ 2200 */
2201int fas216_queue_command(struct scsi_cmnd *SCpnt, 2201static int fas216_queue_command_lck(struct scsi_cmnd *SCpnt,
2202 void (*done)(struct scsi_cmnd *)) 2202 void (*done)(struct scsi_cmnd *))
2203{ 2203{
2204 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata; 2204 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
@@ -2240,6 +2240,8 @@ int fas216_queue_command(struct scsi_cmnd *SCpnt,
2240 return result; 2240 return result;
2241} 2241}
2242 2242
2243DEF_SCSI_QCMD(fas216_queue_command)
2244
2243/** 2245/**
2244 * fas216_internal_done - trigger restart of a waiting thread in fas216_noqueue_command 2246 * fas216_internal_done - trigger restart of a waiting thread in fas216_noqueue_command
2245 * @SCpnt: Command to wake 2247 * @SCpnt: Command to wake
@@ -2263,7 +2265,7 @@ static void fas216_internal_done(struct scsi_cmnd *SCpnt)
2263 * Returns: scsi result code. 2265 * Returns: scsi result code.
2264 * Notes: io_request_lock is held, interrupts are disabled. 2266 * Notes: io_request_lock is held, interrupts are disabled.
2265 */ 2267 */
2266int fas216_noqueue_command(struct scsi_cmnd *SCpnt, 2268static int fas216_noqueue_command_lck(struct scsi_cmnd *SCpnt,
2267 void (*done)(struct scsi_cmnd *)) 2269 void (*done)(struct scsi_cmnd *))
2268{ 2270{
2269 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata; 2271 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
@@ -2277,7 +2279,7 @@ int fas216_noqueue_command(struct scsi_cmnd *SCpnt,
2277 BUG_ON(info->scsi.irq != NO_IRQ); 2279 BUG_ON(info->scsi.irq != NO_IRQ);
2278 2280
2279 info->internal_done = 0; 2281 info->internal_done = 0;
2280 fas216_queue_command(SCpnt, fas216_internal_done); 2282 fas216_queue_command_lck(SCpnt, fas216_internal_done);
2281 2283
2282 /* 2284 /*
2283 * This wastes time, since we can't return until the command is 2285 * This wastes time, since we can't return until the command is
@@ -2310,6 +2312,8 @@ int fas216_noqueue_command(struct scsi_cmnd *SCpnt,
2310 return 0; 2312 return 0;
2311} 2313}
2312 2314
2315DEF_SCSI_QCMD(fas216_noqueue_command)
2316
2313/* 2317/*
2314 * Error handler timeout function. Indicate that we timed out, 2318 * Error handler timeout function. Indicate that we timed out,
2315 * and wake up any error handler process so it can continue. 2319 * and wake up any error handler process so it can continue.
diff --git a/drivers/scsi/arm/fas216.h b/drivers/scsi/arm/fas216.h
index b65f4cf0eec9..f30f8d659dc4 100644
--- a/drivers/scsi/arm/fas216.h
+++ b/drivers/scsi/arm/fas216.h
@@ -331,23 +331,21 @@ extern int fas216_init (struct Scsi_Host *instance);
331 */ 331 */
332extern int fas216_add (struct Scsi_Host *instance, struct device *dev); 332extern int fas216_add (struct Scsi_Host *instance, struct device *dev);
333 333
334/* Function: int fas216_queue_command(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 334/* Function: int fas216_queue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt)
335 * Purpose : queue a command for adapter to process. 335 * Purpose : queue a command for adapter to process.
336 * Params : SCpnt - Command to queue 336 * Params : h - host adapter
337 * done - done function to call once command is complete 337 * : SCpnt - Command to queue
338 * Returns : 0 - success, else error 338 * Returns : 0 - success, else error
339 */ 339 */
340extern int fas216_queue_command(struct scsi_cmnd *, 340extern int fas216_queue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt);
341 void (*done)(struct scsi_cmnd *));
342 341
343/* Function: int fas216_noqueue_command(istruct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 342/* Function: int fas216_noqueue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt)
344 * Purpose : queue a command for adapter to process, and process it to completion. 343 * Purpose : queue a command for adapter to process, and process it to completion.
345 * Params : SCpnt - Command to queue 344 * Params : h - host adapter
346 * done - done function to call once command is complete 345 * : SCpnt - Command to queue
347 * Returns : 0 - success, else error 346 * Returns : 0 - success, else error
348 */ 347 */
349extern int fas216_noqueue_command(struct scsi_cmnd *, 348extern int fas216_noqueue_command(struct Scsi_Host *, struct scsi_cmnd *);
350 void (*done)(struct scsi_cmnd *));
351 349
352/* Function: irqreturn_t fas216_intr (FAS216_Info *info) 350/* Function: irqreturn_t fas216_intr (FAS216_Info *info)
353 * Purpose : handle interrupts from the interface to progress a command 351 * Purpose : handle interrupts from the interface to progress a command
diff --git a/drivers/scsi/atari_NCR5380.c b/drivers/scsi/atari_NCR5380.c
index 158ebc3644d8..88b2928b4d3b 100644
--- a/drivers/scsi/atari_NCR5380.c
+++ b/drivers/scsi/atari_NCR5380.c
@@ -910,7 +910,7 @@ static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
910 * 910 *
911 */ 911 */
912 912
913static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *)) 913static int NCR5380_queue_command_lck(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
914{ 914{
915 SETUP_HOSTDATA(cmd->device->host); 915 SETUP_HOSTDATA(cmd->device->host);
916 Scsi_Cmnd *tmp; 916 Scsi_Cmnd *tmp;
@@ -1022,6 +1022,8 @@ static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
1022 return 0; 1022 return 0;
1023} 1023}
1024 1024
1025static DEF_SCSI_QCMD(NCR5380_queue_command)
1026
1025/* 1027/*
1026 * Function : NCR5380_main (void) 1028 * Function : NCR5380_main (void)
1027 * 1029 *
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index ad7a23aef0ec..3e8658e2f154 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -572,23 +572,6 @@ static void falcon_get_lock(void)
572} 572}
573 573
574 574
575/* This is the wrapper function for NCR5380_queue_command(). It just
576 * tries to get the lock on the ST-DMA (see above) and then calls the
577 * original function.
578 */
579
580#if 0
581int atari_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
582{
583 /* falcon_get_lock();
584 * ++guenther: moved to NCR5380_queue_command() to prevent
585 * race condition, see there for an explanation.
586 */
587 return NCR5380_queue_command(cmd, done);
588}
589#endif
590
591
592int __init atari_scsi_detect(struct scsi_host_template *host) 575int __init atari_scsi_detect(struct scsi_host_template *host)
593{ 576{
594 static int called = 0; 577 static int called = 0;
diff --git a/drivers/scsi/atp870u.c b/drivers/scsi/atp870u.c
index ab5bdda6903e..76029d570beb 100644
--- a/drivers/scsi/atp870u.c
+++ b/drivers/scsi/atp870u.c
@@ -605,7 +605,7 @@ handled:
605 * 605 *
606 * Queue a command to the ATP queue. Called with the host lock held. 606 * Queue a command to the ATP queue. Called with the host lock held.
607 */ 607 */
608static int atp870u_queuecommand(struct scsi_cmnd * req_p, 608static int atp870u_queuecommand_lck(struct scsi_cmnd *req_p,
609 void (*done) (struct scsi_cmnd *)) 609 void (*done) (struct scsi_cmnd *))
610{ 610{
611 unsigned char c; 611 unsigned char c;
@@ -694,6 +694,8 @@ static int atp870u_queuecommand(struct scsi_cmnd * req_p,
694 return 0; 694 return 0;
695} 695}
696 696
697static DEF_SCSI_QCMD(atp870u_queuecommand)
698
697/** 699/**
698 * send_s870 - send a command to the controller 700 * send_s870 - send a command to the controller
699 * @host: host 701 * @host: host
diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
index ceaac65a91ff..ff2bd07161f7 100644
--- a/drivers/scsi/bfa/bfa.h
+++ b/drivers/scsi/bfa/bfa.h
@@ -29,13 +29,13 @@ struct bfa_s;
29typedef void (*bfa_isr_func_t) (struct bfa_s *bfa, struct bfi_msg_s *m); 29typedef void (*bfa_isr_func_t) (struct bfa_s *bfa, struct bfi_msg_s *m);
30typedef void (*bfa_cb_cbfn_t) (void *cbarg, bfa_boolean_t complete); 30typedef void (*bfa_cb_cbfn_t) (void *cbarg, bfa_boolean_t complete);
31 31
32/** 32/*
33 * Interrupt message handlers 33 * Interrupt message handlers
34 */ 34 */
35void bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m); 35void bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m);
36void bfa_isr_bind(enum bfi_mclass mc, bfa_isr_func_t isr_func); 36void bfa_isr_bind(enum bfi_mclass mc, bfa_isr_func_t isr_func);
37 37
38/** 38/*
39 * Request and response queue related defines 39 * Request and response queue related defines
40 */ 40 */
41#define BFA_REQQ_NELEMS_MIN (4) 41#define BFA_REQQ_NELEMS_MIN (4)
@@ -58,9 +58,9 @@ void bfa_isr_bind(enum bfi_mclass mc, bfa_isr_func_t isr_func);
58#define bfa_reqq_produce(__bfa, __reqq) do { \ 58#define bfa_reqq_produce(__bfa, __reqq) do { \
59 (__bfa)->iocfc.req_cq_pi[__reqq]++; \ 59 (__bfa)->iocfc.req_cq_pi[__reqq]++; \
60 (__bfa)->iocfc.req_cq_pi[__reqq] &= \ 60 (__bfa)->iocfc.req_cq_pi[__reqq] &= \
61 ((__bfa)->iocfc.cfg.drvcfg.num_reqq_elems - 1); \ 61 ((__bfa)->iocfc.cfg.drvcfg.num_reqq_elems - 1); \
62 bfa_reg_write((__bfa)->iocfc.bfa_regs.cpe_q_pi[__reqq], \ 62 writel((__bfa)->iocfc.req_cq_pi[__reqq], \
63 (__bfa)->iocfc.req_cq_pi[__reqq]); \ 63 (__bfa)->iocfc.bfa_regs.cpe_q_pi[__reqq]); \
64 mmiowb(); \ 64 mmiowb(); \
65 } while (0) 65 } while (0)
66 66
@@ -76,7 +76,7 @@ void bfa_isr_bind(enum bfi_mclass mc, bfa_isr_func_t isr_func);
76 (__index) &= ((__size) - 1); \ 76 (__index) &= ((__size) - 1); \
77} while (0) 77} while (0)
78 78
79/** 79/*
80 * Queue element to wait for room in request queue. FIFO order is 80 * Queue element to wait for room in request queue. FIFO order is
81 * maintained when fullfilling requests. 81 * maintained when fullfilling requests.
82 */ 82 */
@@ -86,7 +86,7 @@ struct bfa_reqq_wait_s {
86 void *cbarg; 86 void *cbarg;
87}; 87};
88 88
89/** 89/*
90 * Circular queue usage assignments 90 * Circular queue usage assignments
91 */ 91 */
92enum { 92enum {
@@ -113,7 +113,7 @@ bfa_reqq_winit(struct bfa_reqq_wait_s *wqe, void (*qresume) (void *cbarg),
113 113
114#define bfa_reqq(__bfa, __reqq) (&(__bfa)->reqq_waitq[__reqq]) 114#define bfa_reqq(__bfa, __reqq) (&(__bfa)->reqq_waitq[__reqq])
115 115
116/** 116/*
117 * static inline void 117 * static inline void
118 * bfa_reqq_wait(struct bfa_s *bfa, int reqq, struct bfa_reqq_wait_s *wqe) 118 * bfa_reqq_wait(struct bfa_s *bfa, int reqq, struct bfa_reqq_wait_s *wqe)
119 */ 119 */
@@ -130,7 +130,7 @@ bfa_reqq_winit(struct bfa_reqq_wait_s *wqe, void (*qresume) (void *cbarg),
130#define bfa_reqq_wcancel(__wqe) list_del(&(__wqe)->qe) 130#define bfa_reqq_wcancel(__wqe) list_del(&(__wqe)->qe)
131 131
132 132
133/** 133/*
134 * Generic BFA callback element. 134 * Generic BFA callback element.
135 */ 135 */
136struct bfa_cb_qe_s { 136struct bfa_cb_qe_s {
@@ -163,7 +163,7 @@ struct bfa_cb_qe_s {
163 } while (0) 163 } while (0)
164 164
165 165
166/** 166/*
167 * PCI devices supported by the current BFA 167 * PCI devices supported by the current BFA
168 */ 168 */
169struct bfa_pciid_s { 169struct bfa_pciid_s {
@@ -173,7 +173,7 @@ struct bfa_pciid_s {
173 173
174extern char bfa_version[]; 174extern char bfa_version[];
175 175
176/** 176/*
177 * BFA memory resources 177 * BFA memory resources
178 */ 178 */
179enum bfa_mem_type { 179enum bfa_mem_type {
@@ -202,19 +202,19 @@ struct bfa_meminfo_s {
202 ((_m)->meminfo[BFA_MEM_TYPE_DMA - 1].dma_curp) 202 ((_m)->meminfo[BFA_MEM_TYPE_DMA - 1].dma_curp)
203 203
204struct bfa_iocfc_regs_s { 204struct bfa_iocfc_regs_s {
205 bfa_os_addr_t intr_status; 205 void __iomem *intr_status;
206 bfa_os_addr_t intr_mask; 206 void __iomem *intr_mask;
207 bfa_os_addr_t cpe_q_pi[BFI_IOC_MAX_CQS]; 207 void __iomem *cpe_q_pi[BFI_IOC_MAX_CQS];
208 bfa_os_addr_t cpe_q_ci[BFI_IOC_MAX_CQS]; 208 void __iomem *cpe_q_ci[BFI_IOC_MAX_CQS];
209 bfa_os_addr_t cpe_q_depth[BFI_IOC_MAX_CQS]; 209 void __iomem *cpe_q_depth[BFI_IOC_MAX_CQS];
210 bfa_os_addr_t cpe_q_ctrl[BFI_IOC_MAX_CQS]; 210 void __iomem *cpe_q_ctrl[BFI_IOC_MAX_CQS];
211 bfa_os_addr_t rme_q_ci[BFI_IOC_MAX_CQS]; 211 void __iomem *rme_q_ci[BFI_IOC_MAX_CQS];
212 bfa_os_addr_t rme_q_pi[BFI_IOC_MAX_CQS]; 212 void __iomem *rme_q_pi[BFI_IOC_MAX_CQS];
213 bfa_os_addr_t rme_q_depth[BFI_IOC_MAX_CQS]; 213 void __iomem *rme_q_depth[BFI_IOC_MAX_CQS];
214 bfa_os_addr_t rme_q_ctrl[BFI_IOC_MAX_CQS]; 214 void __iomem *rme_q_ctrl[BFI_IOC_MAX_CQS];
215}; 215};
216 216
217/** 217/*
218 * MSIX vector handlers 218 * MSIX vector handlers
219 */ 219 */
220#define BFA_MSIX_MAX_VECTORS 22 220#define BFA_MSIX_MAX_VECTORS 22
@@ -224,7 +224,7 @@ struct bfa_msix_s {
224 bfa_msix_handler_t handler[BFA_MSIX_MAX_VECTORS]; 224 bfa_msix_handler_t handler[BFA_MSIX_MAX_VECTORS];
225}; 225};
226 226
227/** 227/*
228 * Chip specific interfaces 228 * Chip specific interfaces
229 */ 229 */
230struct bfa_hwif_s { 230struct bfa_hwif_s {
@@ -343,7 +343,7 @@ int bfa_iocfc_get_pbc_vports(struct bfa_s *bfa,
343 struct bfi_pbc_vport_s *pbc_vport); 343 struct bfi_pbc_vport_s *pbc_vport);
344 344
345 345
346/** 346/*
347 *---------------------------------------------------------------------- 347 *----------------------------------------------------------------------
348 * BFA public interfaces 348 * BFA public interfaces
349 *---------------------------------------------------------------------- 349 *----------------------------------------------------------------------
diff --git a/drivers/scsi/bfa/bfa_cb_ioim.h b/drivers/scsi/bfa/bfa_cb_ioim.h
index a989a94c38da..6f021015f1f6 100644
--- a/drivers/scsi/bfa/bfa_cb_ioim.h
+++ b/drivers/scsi/bfa/bfa_cb_ioim.h
@@ -37,18 +37,18 @@ bfad_int_to_lun(u32 luno)
37 } lun; 37 } lun;
38 38
39 lun.bfa_lun = 0; 39 lun.bfa_lun = 0;
40 lun.scsi_lun[0] = bfa_os_htons(luno); 40 lun.scsi_lun[0] = cpu_to_be16(luno);
41 41
42 return lun.bfa_lun; 42 return lun.bfa_lun;
43} 43}
44 44
45/** 45/*
46 * Get LUN for the I/O request 46 * Get LUN for the I/O request
47 */ 47 */
48#define bfa_cb_ioim_get_lun(__dio) \ 48#define bfa_cb_ioim_get_lun(__dio) \
49 bfad_int_to_lun(((struct scsi_cmnd *)__dio)->device->lun) 49 bfad_int_to_lun(((struct scsi_cmnd *)__dio)->device->lun)
50 50
51/** 51/*
52 * Get CDB for the I/O request 52 * Get CDB for the I/O request
53 */ 53 */
54static inline u8 * 54static inline u8 *
@@ -59,7 +59,7 @@ bfa_cb_ioim_get_cdb(struct bfad_ioim_s *dio)
59 return (u8 *) cmnd->cmnd; 59 return (u8 *) cmnd->cmnd;
60} 60}
61 61
62/** 62/*
63 * Get I/O direction (read/write) for the I/O request 63 * Get I/O direction (read/write) for the I/O request
64 */ 64 */
65static inline enum fcp_iodir 65static inline enum fcp_iodir
@@ -77,7 +77,7 @@ bfa_cb_ioim_get_iodir(struct bfad_ioim_s *dio)
77 return FCP_IODIR_NONE; 77 return FCP_IODIR_NONE;
78} 78}
79 79
80/** 80/*
81 * Get IO size in bytes for the I/O request 81 * Get IO size in bytes for the I/O request
82 */ 82 */
83static inline u32 83static inline u32
@@ -88,7 +88,7 @@ bfa_cb_ioim_get_size(struct bfad_ioim_s *dio)
88 return scsi_bufflen(cmnd); 88 return scsi_bufflen(cmnd);
89} 89}
90 90
91/** 91/*
92 * Get timeout for the I/O request 92 * Get timeout for the I/O request
93 */ 93 */
94static inline u8 94static inline u8
@@ -104,7 +104,7 @@ bfa_cb_ioim_get_timeout(struct bfad_ioim_s *dio)
104 return 0; 104 return 0;
105} 105}
106 106
107/** 107/*
108 * Get Command Reference Number for the I/O request. 0 if none. 108 * Get Command Reference Number for the I/O request. 0 if none.
109 */ 109 */
110static inline u8 110static inline u8
@@ -113,7 +113,7 @@ bfa_cb_ioim_get_crn(struct bfad_ioim_s *dio)
113 return 0; 113 return 0;
114} 114}
115 115
116/** 116/*
117 * Get SAM-3 priority for the I/O request. 0 is default. 117 * Get SAM-3 priority for the I/O request. 0 is default.
118 */ 118 */
119static inline u8 119static inline u8
@@ -122,7 +122,7 @@ bfa_cb_ioim_get_priority(struct bfad_ioim_s *dio)
122 return 0; 122 return 0;
123} 123}
124 124
125/** 125/*
126 * Get task attributes for the I/O request. Default is FCP_TASK_ATTR_SIMPLE(0). 126 * Get task attributes for the I/O request. Default is FCP_TASK_ATTR_SIMPLE(0).
127 */ 127 */
128static inline u8 128static inline u8
@@ -148,7 +148,7 @@ bfa_cb_ioim_get_taskattr(struct bfad_ioim_s *dio)
148 return task_attr; 148 return task_attr;
149} 149}
150 150
151/** 151/*
152 * Get CDB length in bytes for the I/O request. Default is FCP_CMND_CDB_LEN(16). 152 * Get CDB length in bytes for the I/O request. Default is FCP_CMND_CDB_LEN(16).
153 */ 153 */
154static inline u8 154static inline u8
@@ -159,7 +159,7 @@ bfa_cb_ioim_get_cdblen(struct bfad_ioim_s *dio)
159 return cmnd->cmd_len; 159 return cmnd->cmd_len;
160} 160}
161 161
162/** 162/*
163 * Assign queue to be used for the I/O request. This value depends on whether 163 * Assign queue to be used for the I/O request. This value depends on whether
164 * the driver wants to use the queues via any specific algorithm. Currently, 164 * the driver wants to use the queues via any specific algorithm. Currently,
165 * this is not supported. 165 * this is not supported.
diff --git a/drivers/scsi/bfa/bfa_core.c b/drivers/scsi/bfa/bfa_core.c
index c2fa07f2485d..2345f48dc57f 100644
--- a/drivers/scsi/bfa/bfa_core.c
+++ b/drivers/scsi/bfa/bfa_core.c
@@ -21,11 +21,11 @@
21 21
22BFA_TRC_FILE(HAL, CORE); 22BFA_TRC_FILE(HAL, CORE);
23 23
24/** 24/*
25 * BFA IOC FC related definitions 25 * BFA IOC FC related definitions
26 */ 26 */
27 27
28/** 28/*
29 * IOC local definitions 29 * IOC local definitions
30 */ 30 */
31#define BFA_IOCFC_TOV 5000 /* msecs */ 31#define BFA_IOCFC_TOV 5000 /* msecs */
@@ -54,7 +54,7 @@ enum {
54#define DEF_CFG_NUM_SBOOT_TGTS 16 54#define DEF_CFG_NUM_SBOOT_TGTS 16
55#define DEF_CFG_NUM_SBOOT_LUNS 16 55#define DEF_CFG_NUM_SBOOT_LUNS 16
56 56
57/** 57/*
58 * forward declaration for IOC FC functions 58 * forward declaration for IOC FC functions
59 */ 59 */
60static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status); 60static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
@@ -63,7 +63,7 @@ static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
63static void bfa_iocfc_reset_cbfn(void *bfa_arg); 63static void bfa_iocfc_reset_cbfn(void *bfa_arg);
64static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn; 64static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
65 65
66/** 66/*
67 * BFA Interrupt handling functions 67 * BFA Interrupt handling functions
68 */ 68 */
69static void 69static void
@@ -86,7 +86,7 @@ bfa_reqq_resume(struct bfa_s *bfa, int qid)
86 86
87 waitq = bfa_reqq(bfa, qid); 87 waitq = bfa_reqq(bfa, qid);
88 list_for_each_safe(qe, qen, waitq) { 88 list_for_each_safe(qe, qen, waitq) {
89 /** 89 /*
90 * Callback only as long as there is room in request queue 90 * Callback only as long as there is room in request queue
91 */ 91 */
92 if (bfa_reqq_full(bfa, qid)) 92 if (bfa_reqq_full(bfa, qid))
@@ -104,7 +104,7 @@ bfa_msix_all(struct bfa_s *bfa, int vec)
104 bfa_intx(bfa); 104 bfa_intx(bfa);
105} 105}
106 106
107/** 107/*
108 * hal_intr_api 108 * hal_intr_api
109 */ 109 */
110bfa_boolean_t 110bfa_boolean_t
@@ -113,15 +113,15 @@ bfa_intx(struct bfa_s *bfa)
113 u32 intr, qintr; 113 u32 intr, qintr;
114 int queue; 114 int queue;
115 115
116 intr = bfa_reg_read(bfa->iocfc.bfa_regs.intr_status); 116 intr = readl(bfa->iocfc.bfa_regs.intr_status);
117 if (!intr) 117 if (!intr)
118 return BFA_FALSE; 118 return BFA_FALSE;
119 119
120 /** 120 /*
121 * RME completion queue interrupt 121 * RME completion queue interrupt
122 */ 122 */
123 qintr = intr & __HFN_INT_RME_MASK; 123 qintr = intr & __HFN_INT_RME_MASK;
124 bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, qintr); 124 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
125 125
126 for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) { 126 for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
127 if (intr & (__HFN_INT_RME_Q0 << queue)) 127 if (intr & (__HFN_INT_RME_Q0 << queue))
@@ -131,11 +131,11 @@ bfa_intx(struct bfa_s *bfa)
131 if (!intr) 131 if (!intr)
132 return BFA_TRUE; 132 return BFA_TRUE;
133 133
134 /** 134 /*
135 * CPE completion queue interrupt 135 * CPE completion queue interrupt
136 */ 136 */
137 qintr = intr & __HFN_INT_CPE_MASK; 137 qintr = intr & __HFN_INT_CPE_MASK;
138 bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, qintr); 138 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
139 139
140 for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) { 140 for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
141 if (intr & (__HFN_INT_CPE_Q0 << queue)) 141 if (intr & (__HFN_INT_CPE_Q0 << queue))
@@ -153,13 +153,13 @@ bfa_intx(struct bfa_s *bfa)
153void 153void
154bfa_intx_enable(struct bfa_s *bfa) 154bfa_intx_enable(struct bfa_s *bfa)
155{ 155{
156 bfa_reg_write(bfa->iocfc.bfa_regs.intr_mask, bfa->iocfc.intr_mask); 156 writel(bfa->iocfc.intr_mask, bfa->iocfc.bfa_regs.intr_mask);
157} 157}
158 158
159void 159void
160bfa_intx_disable(struct bfa_s *bfa) 160bfa_intx_disable(struct bfa_s *bfa)
161{ 161{
162 bfa_reg_write(bfa->iocfc.bfa_regs.intr_mask, -1L); 162 writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
163} 163}
164 164
165void 165void
@@ -188,8 +188,8 @@ bfa_isr_enable(struct bfa_s *bfa)
188 __HFN_INT_RME_Q6 | __HFN_INT_RME_Q7 | 188 __HFN_INT_RME_Q6 | __HFN_INT_RME_Q7 |
189 __HFN_INT_MBOX_LPU1); 189 __HFN_INT_MBOX_LPU1);
190 190
191 bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, intr_unmask); 191 writel(intr_unmask, bfa->iocfc.bfa_regs.intr_status);
192 bfa_reg_write(bfa->iocfc.bfa_regs.intr_mask, ~intr_unmask); 192 writel(~intr_unmask, bfa->iocfc.bfa_regs.intr_mask);
193 bfa->iocfc.intr_mask = ~intr_unmask; 193 bfa->iocfc.intr_mask = ~intr_unmask;
194 bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0); 194 bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
195} 195}
@@ -198,7 +198,7 @@ void
198bfa_isr_disable(struct bfa_s *bfa) 198bfa_isr_disable(struct bfa_s *bfa)
199{ 199{
200 bfa_isr_mode_set(bfa, BFA_FALSE); 200 bfa_isr_mode_set(bfa, BFA_FALSE);
201 bfa_reg_write(bfa->iocfc.bfa_regs.intr_mask, -1L); 201 writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
202 bfa_msix_uninstall(bfa); 202 bfa_msix_uninstall(bfa);
203} 203}
204 204
@@ -211,7 +211,7 @@ bfa_msix_reqq(struct bfa_s *bfa, int qid)
211 211
212 bfa->iocfc.hwif.hw_reqq_ack(bfa, qid); 212 bfa->iocfc.hwif.hw_reqq_ack(bfa, qid);
213 213
214 /** 214 /*
215 * Resume any pending requests in the corresponding reqq. 215 * Resume any pending requests in the corresponding reqq.
216 */ 216 */
217 waitq = bfa_reqq(bfa, qid); 217 waitq = bfa_reqq(bfa, qid);
@@ -259,14 +259,14 @@ bfa_msix_rspq(struct bfa_s *bfa, int qid)
259 } 259 }
260 } 260 }
261 261
262 /** 262 /*
263 * update CI 263 * update CI
264 */ 264 */
265 bfa_rspq_ci(bfa, qid) = pi; 265 bfa_rspq_ci(bfa, qid) = pi;
266 bfa_reg_write(bfa->iocfc.bfa_regs.rme_q_ci[qid], pi); 266 writel(pi, bfa->iocfc.bfa_regs.rme_q_ci[qid]);
267 mmiowb(); 267 mmiowb();
268 268
269 /** 269 /*
270 * Resume any pending requests in the corresponding reqq. 270 * Resume any pending requests in the corresponding reqq.
271 */ 271 */
272 waitq = bfa_reqq(bfa, qid); 272 waitq = bfa_reqq(bfa, qid);
@@ -279,7 +279,7 @@ bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
279{ 279{
280 u32 intr, curr_value; 280 u32 intr, curr_value;
281 281
282 intr = bfa_reg_read(bfa->iocfc.bfa_regs.intr_status); 282 intr = readl(bfa->iocfc.bfa_regs.intr_status);
283 283
284 if (intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1)) 284 if (intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1))
285 bfa_msix_lpu(bfa); 285 bfa_msix_lpu(bfa);
@@ -289,30 +289,30 @@ bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
289 289
290 if (intr) { 290 if (intr) {
291 if (intr & __HFN_INT_LL_HALT) { 291 if (intr & __HFN_INT_LL_HALT) {
292 /** 292 /*
293 * If LL_HALT bit is set then FW Init Halt LL Port 293 * If LL_HALT bit is set then FW Init Halt LL Port
294 * Register needs to be cleared as well so Interrupt 294 * Register needs to be cleared as well so Interrupt
295 * Status Register will be cleared. 295 * Status Register will be cleared.
296 */ 296 */
297 curr_value = bfa_reg_read(bfa->ioc.ioc_regs.ll_halt); 297 curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
298 curr_value &= ~__FW_INIT_HALT_P; 298 curr_value &= ~__FW_INIT_HALT_P;
299 bfa_reg_write(bfa->ioc.ioc_regs.ll_halt, curr_value); 299 writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
300 } 300 }
301 301
302 if (intr & __HFN_INT_ERR_PSS) { 302 if (intr & __HFN_INT_ERR_PSS) {
303 /** 303 /*
304 * ERR_PSS bit needs to be cleared as well in case 304 * ERR_PSS bit needs to be cleared as well in case
305 * interrups are shared so driver's interrupt handler is 305 * interrups are shared so driver's interrupt handler is
306 * still called eventhough it is already masked out. 306 * still called eventhough it is already masked out.
307 */ 307 */
308 curr_value = bfa_reg_read( 308 curr_value = readl(
309 bfa->ioc.ioc_regs.pss_err_status_reg); 309 bfa->ioc.ioc_regs.pss_err_status_reg);
310 curr_value &= __PSS_ERR_STATUS_SET; 310 curr_value &= __PSS_ERR_STATUS_SET;
311 bfa_reg_write(bfa->ioc.ioc_regs.pss_err_status_reg, 311 writel(curr_value,
312 curr_value); 312 bfa->ioc.ioc_regs.pss_err_status_reg);
313 } 313 }
314 314
315 bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, intr); 315 writel(intr, bfa->iocfc.bfa_regs.intr_status);
316 bfa_msix_errint(bfa, intr); 316 bfa_msix_errint(bfa, intr);
317 } 317 }
318} 318}
@@ -323,11 +323,11 @@ bfa_isr_bind(enum bfi_mclass mc, bfa_isr_func_t isr_func)
323 bfa_isrs[mc] = isr_func; 323 bfa_isrs[mc] = isr_func;
324} 324}
325 325
326/** 326/*
327 * BFA IOC FC related functions 327 * BFA IOC FC related functions
328 */ 328 */
329 329
330/** 330/*
331 * hal_ioc_pvt BFA IOC private functions 331 * hal_ioc_pvt BFA IOC private functions
332 */ 332 */
333 333
@@ -366,7 +366,7 @@ bfa_iocfc_fw_cfg_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
366 BFA_CACHELINE_SZ); 366 BFA_CACHELINE_SZ);
367} 367}
368 368
369/** 369/*
370 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ 370 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
371 */ 371 */
372static void 372static void
@@ -384,14 +384,14 @@ bfa_iocfc_send_cfg(void *bfa_arg)
384 384
385 bfa_iocfc_reset_queues(bfa); 385 bfa_iocfc_reset_queues(bfa);
386 386
387 /** 387 /*
388 * initialize IOC configuration info 388 * initialize IOC configuration info
389 */ 389 */
390 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG; 390 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
391 cfg_info->num_cqs = cfg->fwcfg.num_cqs; 391 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
392 392
393 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa); 393 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
394 /** 394 /*
395 * dma map REQ and RSP circular queues and shadow pointers 395 * dma map REQ and RSP circular queues and shadow pointers
396 */ 396 */
397 for (i = 0; i < cfg->fwcfg.num_cqs; i++) { 397 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
@@ -400,17 +400,17 @@ bfa_iocfc_send_cfg(void *bfa_arg)
400 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i], 400 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
401 iocfc->req_cq_shadow_ci[i].pa); 401 iocfc->req_cq_shadow_ci[i].pa);
402 cfg_info->req_cq_elems[i] = 402 cfg_info->req_cq_elems[i] =
403 bfa_os_htons(cfg->drvcfg.num_reqq_elems); 403 cpu_to_be16(cfg->drvcfg.num_reqq_elems);
404 404
405 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i], 405 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
406 iocfc->rsp_cq_ba[i].pa); 406 iocfc->rsp_cq_ba[i].pa);
407 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i], 407 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
408 iocfc->rsp_cq_shadow_pi[i].pa); 408 iocfc->rsp_cq_shadow_pi[i].pa);
409 cfg_info->rsp_cq_elems[i] = 409 cfg_info->rsp_cq_elems[i] =
410 bfa_os_htons(cfg->drvcfg.num_rspq_elems); 410 cpu_to_be16(cfg->drvcfg.num_rspq_elems);
411 } 411 }
412 412
413 /** 413 /*
414 * Enable interrupt coalescing if it is driver init path 414 * Enable interrupt coalescing if it is driver init path
415 * and not ioc disable/enable path. 415 * and not ioc disable/enable path.
416 */ 416 */
@@ -419,7 +419,7 @@ bfa_iocfc_send_cfg(void *bfa_arg)
419 419
420 iocfc->cfgdone = BFA_FALSE; 420 iocfc->cfgdone = BFA_FALSE;
421 421
422 /** 422 /*
423 * dma map IOC configuration itself 423 * dma map IOC configuration itself
424 */ 424 */
425 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ, 425 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
@@ -440,9 +440,9 @@ bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
440 iocfc->bfa = bfa; 440 iocfc->bfa = bfa;
441 iocfc->action = BFA_IOCFC_ACT_NONE; 441 iocfc->action = BFA_IOCFC_ACT_NONE;
442 442
443 bfa_os_assign(iocfc->cfg, *cfg); 443 iocfc->cfg = *cfg;
444 444
445 /** 445 /*
446 * Initialize chip specific handlers. 446 * Initialize chip specific handlers.
447 */ 447 */
448 if (bfa_asic_id_ct(bfa_ioc_devid(&bfa->ioc))) { 448 if (bfa_asic_id_ct(bfa_ioc_devid(&bfa->ioc))) {
@@ -503,13 +503,13 @@ bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg,
503 for (i = 0; i < cfg->fwcfg.num_cqs; i++) { 503 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
504 iocfc->req_cq_ba[i].kva = dm_kva; 504 iocfc->req_cq_ba[i].kva = dm_kva;
505 iocfc->req_cq_ba[i].pa = dm_pa; 505 iocfc->req_cq_ba[i].pa = dm_pa;
506 bfa_os_memset(dm_kva, 0, per_reqq_sz); 506 memset(dm_kva, 0, per_reqq_sz);
507 dm_kva += per_reqq_sz; 507 dm_kva += per_reqq_sz;
508 dm_pa += per_reqq_sz; 508 dm_pa += per_reqq_sz;
509 509
510 iocfc->rsp_cq_ba[i].kva = dm_kva; 510 iocfc->rsp_cq_ba[i].kva = dm_kva;
511 iocfc->rsp_cq_ba[i].pa = dm_pa; 511 iocfc->rsp_cq_ba[i].pa = dm_pa;
512 bfa_os_memset(dm_kva, 0, per_rspq_sz); 512 memset(dm_kva, 0, per_rspq_sz);
513 dm_kva += per_rspq_sz; 513 dm_kva += per_rspq_sz;
514 dm_pa += per_rspq_sz; 514 dm_pa += per_rspq_sz;
515 } 515 }
@@ -559,7 +559,7 @@ bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg,
559 } 559 }
560} 560}
561 561
562/** 562/*
563 * Start BFA submodules. 563 * Start BFA submodules.
564 */ 564 */
565static void 565static void
@@ -573,7 +573,7 @@ bfa_iocfc_start_submod(struct bfa_s *bfa)
573 hal_mods[i]->start(bfa); 573 hal_mods[i]->start(bfa);
574} 574}
575 575
576/** 576/*
577 * Disable BFA submodules. 577 * Disable BFA submodules.
578 */ 578 */
579static void 579static void
@@ -623,7 +623,7 @@ bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
623 complete(&bfad->disable_comp); 623 complete(&bfad->disable_comp);
624} 624}
625 625
626/** 626/*
627 * Update BFA configuration from firmware configuration. 627 * Update BFA configuration from firmware configuration.
628 */ 628 */
629static void 629static void
@@ -634,15 +634,15 @@ bfa_iocfc_cfgrsp(struct bfa_s *bfa)
634 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg; 634 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
635 635
636 fwcfg->num_cqs = fwcfg->num_cqs; 636 fwcfg->num_cqs = fwcfg->num_cqs;
637 fwcfg->num_ioim_reqs = bfa_os_ntohs(fwcfg->num_ioim_reqs); 637 fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
638 fwcfg->num_tskim_reqs = bfa_os_ntohs(fwcfg->num_tskim_reqs); 638 fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
639 fwcfg->num_fcxp_reqs = bfa_os_ntohs(fwcfg->num_fcxp_reqs); 639 fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
640 fwcfg->num_uf_bufs = bfa_os_ntohs(fwcfg->num_uf_bufs); 640 fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
641 fwcfg->num_rports = bfa_os_ntohs(fwcfg->num_rports); 641 fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
642 642
643 iocfc->cfgdone = BFA_TRUE; 643 iocfc->cfgdone = BFA_TRUE;
644 644
645 /** 645 /*
646 * Configuration is complete - initialize/start submodules 646 * Configuration is complete - initialize/start submodules
647 */ 647 */
648 bfa_fcport_init(bfa); 648 bfa_fcport_init(bfa);
@@ -665,7 +665,7 @@ bfa_iocfc_reset_queues(struct bfa_s *bfa)
665 } 665 }
666} 666}
667 667
668/** 668/*
669 * IOC enable request is complete 669 * IOC enable request is complete
670 */ 670 */
671static void 671static void
@@ -684,7 +684,7 @@ bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
684 bfa_iocfc_send_cfg(bfa); 684 bfa_iocfc_send_cfg(bfa);
685} 685}
686 686
687/** 687/*
688 * IOC disable request is complete 688 * IOC disable request is complete
689 */ 689 */
690static void 690static void
@@ -705,7 +705,7 @@ bfa_iocfc_disable_cbfn(void *bfa_arg)
705 } 705 }
706} 706}
707 707
708/** 708/*
709 * Notify sub-modules of hardware failure. 709 * Notify sub-modules of hardware failure.
710 */ 710 */
711static void 711static void
@@ -723,7 +723,7 @@ bfa_iocfc_hbfail_cbfn(void *bfa_arg)
723 bfa); 723 bfa);
724} 724}
725 725
726/** 726/*
727 * Actions on chip-reset completion. 727 * Actions on chip-reset completion.
728 */ 728 */
729static void 729static void
@@ -735,11 +735,11 @@ bfa_iocfc_reset_cbfn(void *bfa_arg)
735 bfa_isr_enable(bfa); 735 bfa_isr_enable(bfa);
736} 736}
737 737
738/** 738/*
739 * hal_ioc_public 739 * hal_ioc_public
740 */ 740 */
741 741
742/** 742/*
743 * Query IOC memory requirement information. 743 * Query IOC memory requirement information.
744 */ 744 */
745void 745void
@@ -754,7 +754,7 @@ bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
754 *km_len += bfa_ioc_debug_trcsz(bfa_auto_recover); 754 *km_len += bfa_ioc_debug_trcsz(bfa_auto_recover);
755} 755}
756 756
757/** 757/*
758 * Query IOC memory requirement information. 758 * Query IOC memory requirement information.
759 */ 759 */
760void 760void
@@ -772,7 +772,7 @@ bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
772 ioc->trcmod = bfa->trcmod; 772 ioc->trcmod = bfa->trcmod;
773 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod); 773 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
774 774
775 /** 775 /*
776 * Set FC mode for BFA_PCI_DEVICE_ID_CT_FC. 776 * Set FC mode for BFA_PCI_DEVICE_ID_CT_FC.
777 */ 777 */
778 if (pcidev->device_id == BFA_PCI_DEVICE_ID_CT_FC) 778 if (pcidev->device_id == BFA_PCI_DEVICE_ID_CT_FC)
@@ -790,7 +790,7 @@ bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
790 INIT_LIST_HEAD(&bfa->reqq_waitq[i]); 790 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
791} 791}
792 792
793/** 793/*
794 * Query IOC memory requirement information. 794 * Query IOC memory requirement information.
795 */ 795 */
796void 796void
@@ -799,7 +799,7 @@ bfa_iocfc_detach(struct bfa_s *bfa)
799 bfa_ioc_detach(&bfa->ioc); 799 bfa_ioc_detach(&bfa->ioc);
800} 800}
801 801
802/** 802/*
803 * Query IOC memory requirement information. 803 * Query IOC memory requirement information.
804 */ 804 */
805void 805void
@@ -809,7 +809,7 @@ bfa_iocfc_init(struct bfa_s *bfa)
809 bfa_ioc_enable(&bfa->ioc); 809 bfa_ioc_enable(&bfa->ioc);
810} 810}
811 811
812/** 812/*
813 * IOC start called from bfa_start(). Called to start IOC operations 813 * IOC start called from bfa_start(). Called to start IOC operations
814 * at driver instantiation for this instance. 814 * at driver instantiation for this instance.
815 */ 815 */
@@ -820,7 +820,7 @@ bfa_iocfc_start(struct bfa_s *bfa)
820 bfa_iocfc_start_submod(bfa); 820 bfa_iocfc_start_submod(bfa);
821} 821}
822 822
823/** 823/*
824 * IOC stop called from bfa_stop(). Called only when driver is unloaded 824 * IOC stop called from bfa_stop(). Called only when driver is unloaded
825 * for this instance. 825 * for this instance.
826 */ 826 */
@@ -876,12 +876,12 @@ bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
876 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce; 876 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
877 877
878 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ? 878 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
879 bfa_os_ntohs(iocfc->cfginfo->intr_attr.delay) : 879 be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
880 bfa_os_ntohs(iocfc->cfgrsp->intr_attr.delay); 880 be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
881 881
882 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ? 882 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
883 bfa_os_ntohs(iocfc->cfginfo->intr_attr.latency) : 883 be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
884 bfa_os_ntohs(iocfc->cfgrsp->intr_attr.latency); 884 be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
885 885
886 attr->config = iocfc->cfg; 886 attr->config = iocfc->cfg;
887} 887}
@@ -893,8 +893,8 @@ bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
893 struct bfi_iocfc_set_intr_req_s *m; 893 struct bfi_iocfc_set_intr_req_s *m;
894 894
895 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce; 895 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
896 iocfc->cfginfo->intr_attr.delay = bfa_os_htons(attr->delay); 896 iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
897 iocfc->cfginfo->intr_attr.latency = bfa_os_htons(attr->latency); 897 iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
898 898
899 if (!bfa_iocfc_is_operational(bfa)) 899 if (!bfa_iocfc_is_operational(bfa))
900 return BFA_STATUS_OK; 900 return BFA_STATUS_OK;
@@ -924,7 +924,7 @@ bfa_iocfc_set_snsbase(struct bfa_s *bfa, u64 snsbase_pa)
924 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1); 924 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
925 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase, snsbase_pa); 925 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase, snsbase_pa);
926} 926}
927/** 927/*
928 * Enable IOC after it is disabled. 928 * Enable IOC after it is disabled.
929 */ 929 */
930void 930void
@@ -953,7 +953,7 @@ bfa_iocfc_is_operational(struct bfa_s *bfa)
953 return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone; 953 return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
954} 954}
955 955
956/** 956/*
957 * Return boot target port wwns -- read from boot information in flash. 957 * Return boot target port wwns -- read from boot information in flash.
958 */ 958 */
959void 959void
@@ -998,11 +998,11 @@ bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
998 return cfgrsp->pbc_cfg.nvports; 998 return cfgrsp->pbc_cfg.nvports;
999} 999}
1000 1000
1001/** 1001/*
1002 * hal_api 1002 * hal_api
1003 */ 1003 */
1004 1004
1005/** 1005/*
1006 * Use this function query the memory requirement of the BFA library. 1006 * Use this function query the memory requirement of the BFA library.
1007 * This function needs to be called before bfa_attach() to get the 1007 * This function needs to be called before bfa_attach() to get the
1008 * memory required of the BFA layer for a given driver configuration. 1008 * memory required of the BFA layer for a given driver configuration.
@@ -1038,7 +1038,7 @@ bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo)
1038 1038
1039 bfa_assert((cfg != NULL) && (meminfo != NULL)); 1039 bfa_assert((cfg != NULL) && (meminfo != NULL));
1040 1040
1041 bfa_os_memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s)); 1041 memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
1042 meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_type = 1042 meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_type =
1043 BFA_MEM_TYPE_KVA; 1043 BFA_MEM_TYPE_KVA;
1044 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_type = 1044 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_type =
@@ -1055,7 +1055,7 @@ bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo)
1055 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_len = dm_len; 1055 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_len = dm_len;
1056} 1056}
1057 1057
1058/** 1058/*
1059 * Use this function to do attach the driver instance with the BFA 1059 * Use this function to do attach the driver instance with the BFA
1060 * library. This function will not trigger any HW initialization 1060 * library. This function will not trigger any HW initialization
1061 * process (which will be done in bfa_init() call) 1061 * process (which will be done in bfa_init() call)
@@ -1092,7 +1092,7 @@ bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1092 1092
1093 bfa_assert((cfg != NULL) && (meminfo != NULL)); 1093 bfa_assert((cfg != NULL) && (meminfo != NULL));
1094 1094
1095 /** 1095 /*
1096 * initialize all memory pointers for iterative allocation 1096 * initialize all memory pointers for iterative allocation
1097 */ 1097 */
1098 for (i = 0; i < BFA_MEM_TYPE_MAX; i++) { 1098 for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
@@ -1109,7 +1109,7 @@ bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1109 bfa_com_port_attach(bfa, meminfo); 1109 bfa_com_port_attach(bfa, meminfo);
1110} 1110}
1111 1111
1112/** 1112/*
1113 * Use this function to delete a BFA IOC. IOC should be stopped (by 1113 * Use this function to delete a BFA IOC. IOC should be stopped (by
1114 * calling bfa_stop()) before this function call. 1114 * calling bfa_stop()) before this function call.
1115 * 1115 *
@@ -1146,7 +1146,7 @@ bfa_init_plog(struct bfa_s *bfa, struct bfa_plog_s *plog)
1146 bfa->plog = plog; 1146 bfa->plog = plog;
1147} 1147}
1148 1148
1149/** 1149/*
1150 * Initialize IOC. 1150 * Initialize IOC.
1151 * 1151 *
1152 * This function will return immediately, when the IOC initialization is 1152 * This function will return immediately, when the IOC initialization is
@@ -1169,7 +1169,7 @@ bfa_init(struct bfa_s *bfa)
1169 bfa_iocfc_init(bfa); 1169 bfa_iocfc_init(bfa);
1170} 1170}
1171 1171
1172/** 1172/*
1173 * Use this function initiate the IOC configuration setup. This function 1173 * Use this function initiate the IOC configuration setup. This function
1174 * will return immediately. 1174 * will return immediately.
1175 * 1175 *
@@ -1183,7 +1183,7 @@ bfa_start(struct bfa_s *bfa)
1183 bfa_iocfc_start(bfa); 1183 bfa_iocfc_start(bfa);
1184} 1184}
1185 1185
1186/** 1186/*
1187 * Use this function quiese the IOC. This function will return immediately, 1187 * Use this function quiese the IOC. This function will return immediately,
1188 * when the IOC is actually stopped, the bfad->comp will be set. 1188 * when the IOC is actually stopped, the bfad->comp will be set.
1189 * 1189 *
@@ -1243,7 +1243,7 @@ bfa_attach_fcs(struct bfa_s *bfa)
1243 bfa->fcs = BFA_TRUE; 1243 bfa->fcs = BFA_TRUE;
1244} 1244}
1245 1245
1246/** 1246/*
1247 * Periodic timer heart beat from driver 1247 * Periodic timer heart beat from driver
1248 */ 1248 */
1249void 1249void
@@ -1252,7 +1252,7 @@ bfa_timer_tick(struct bfa_s *bfa)
1252 bfa_timer_beat(&bfa->timer_mod); 1252 bfa_timer_beat(&bfa->timer_mod);
1253} 1253}
1254 1254
1255/** 1255/*
1256 * Return the list of PCI vendor/device id lists supported by this 1256 * Return the list of PCI vendor/device id lists supported by this
1257 * BFA instance. 1257 * BFA instance.
1258 */ 1258 */
@@ -1270,7 +1270,7 @@ bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
1270 *pciids = __pciids; 1270 *pciids = __pciids;
1271} 1271}
1272 1272
1273/** 1273/*
1274 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled 1274 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
1275 * into BFA layer). The OS driver can then turn back and overwrite entries that 1275 * into BFA layer). The OS driver can then turn back and overwrite entries that
1276 * have been configured by the user. 1276 * have been configured by the user.
@@ -1328,7 +1328,7 @@ bfa_get_attr(struct bfa_s *bfa, struct bfa_ioc_attr_s *ioc_attr)
1328 bfa_ioc_get_attr(&bfa->ioc, ioc_attr); 1328 bfa_ioc_get_attr(&bfa->ioc, ioc_attr);
1329} 1329}
1330 1330
1331/** 1331/*
1332 * Retrieve firmware trace information on IOC failure. 1332 * Retrieve firmware trace information on IOC failure.
1333 */ 1333 */
1334bfa_status_t 1334bfa_status_t
@@ -1337,7 +1337,7 @@ bfa_debug_fwsave(struct bfa_s *bfa, void *trcdata, int *trclen)
1337 return bfa_ioc_debug_fwsave(&bfa->ioc, trcdata, trclen); 1337 return bfa_ioc_debug_fwsave(&bfa->ioc, trcdata, trclen);
1338} 1338}
1339 1339
1340/** 1340/*
1341 * Clear the saved firmware trace information of an IOC. 1341 * Clear the saved firmware trace information of an IOC.
1342 */ 1342 */
1343void 1343void
@@ -1346,7 +1346,7 @@ bfa_debug_fwsave_clear(struct bfa_s *bfa)
1346 bfa_ioc_debug_fwsave_clear(&bfa->ioc); 1346 bfa_ioc_debug_fwsave_clear(&bfa->ioc);
1347} 1347}
1348 1348
1349/** 1349/*
1350 * Fetch firmware trace data. 1350 * Fetch firmware trace data.
1351 * 1351 *
1352 * @param[in] bfa BFA instance 1352 * @param[in] bfa BFA instance
@@ -1362,7 +1362,7 @@ bfa_debug_fwtrc(struct bfa_s *bfa, void *trcdata, int *trclen)
1362 return bfa_ioc_debug_fwtrc(&bfa->ioc, trcdata, trclen); 1362 return bfa_ioc_debug_fwtrc(&bfa->ioc, trcdata, trclen);
1363} 1363}
1364 1364
1365/** 1365/*
1366 * Dump firmware memory. 1366 * Dump firmware memory.
1367 * 1367 *
1368 * @param[in] bfa BFA instance 1368 * @param[in] bfa BFA instance
@@ -1378,7 +1378,7 @@ bfa_debug_fwcore(struct bfa_s *bfa, void *buf, u32 *offset, int *buflen)
1378{ 1378{
1379 return bfa_ioc_debug_fwcore(&bfa->ioc, buf, offset, buflen); 1379 return bfa_ioc_debug_fwcore(&bfa->ioc, buf, offset, buflen);
1380} 1380}
1381/** 1381/*
1382 * Reset hw semaphore & usage cnt regs and initialize. 1382 * Reset hw semaphore & usage cnt regs and initialize.
1383 */ 1383 */
1384void 1384void
@@ -1388,7 +1388,7 @@ bfa_chip_reset(struct bfa_s *bfa)
1388 bfa_ioc_pll_init(&bfa->ioc); 1388 bfa_ioc_pll_init(&bfa->ioc);
1389} 1389}
1390 1390
1391/** 1391/*
1392 * Fetch firmware statistics data. 1392 * Fetch firmware statistics data.
1393 * 1393 *
1394 * @param[in] bfa BFA instance 1394 * @param[in] bfa BFA instance
diff --git a/drivers/scsi/bfa/bfa_cs.h b/drivers/scsi/bfa/bfa_cs.h
index 7260c74620f8..99f242b9aa31 100644
--- a/drivers/scsi/bfa/bfa_cs.h
+++ b/drivers/scsi/bfa/bfa_cs.h
@@ -15,7 +15,7 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * bfa_cs.h BFA common services 19 * bfa_cs.h BFA common services
20 */ 20 */
21 21
@@ -24,7 +24,7 @@
24 24
25#include "bfa_os_inc.h" 25#include "bfa_os_inc.h"
26 26
27/** 27/*
28 * BFA TRC 28 * BFA TRC
29 */ 29 */
30 30
@@ -73,7 +73,7 @@ enum {
73#define BFA_TRC_MOD_SH 10 73#define BFA_TRC_MOD_SH 10
74#define BFA_TRC_MOD(__mod) ((BFA_TRC_ ## __mod) << BFA_TRC_MOD_SH) 74#define BFA_TRC_MOD(__mod) ((BFA_TRC_ ## __mod) << BFA_TRC_MOD_SH)
75 75
76/** 76/*
77 * Define a new tracing file (module). Module should match one defined above. 77 * Define a new tracing file (module). Module should match one defined above.
78 */ 78 */
79#define BFA_TRC_FILE(__mod, __submod) \ 79#define BFA_TRC_FILE(__mod, __submod) \
@@ -155,7 +155,7 @@ __bfa_trc32(struct bfa_trc_mod_s *trcm, int fileno, int line, u32 data)
155#define bfa_trc_fp(_trcp, _data) 155#define bfa_trc_fp(_trcp, _data)
156#endif 156#endif
157 157
158/** 158/*
159 * @ BFA LOG interfaces 159 * @ BFA LOG interfaces
160 */ 160 */
161#define bfa_assert(__cond) do { \ 161#define bfa_assert(__cond) do { \
@@ -249,13 +249,13 @@ bfa_q_is_on_q_func(struct list_head *q, struct list_head *qe)
249#define bfa_q_is_on_q(_q, _qe) \ 249#define bfa_q_is_on_q(_q, _qe) \
250 bfa_q_is_on_q_func(_q, (struct list_head *)(_qe)) 250 bfa_q_is_on_q_func(_q, (struct list_head *)(_qe))
251 251
252/** 252/*
253 * @ BFA state machine interfaces 253 * @ BFA state machine interfaces
254 */ 254 */
255 255
256typedef void (*bfa_sm_t)(void *sm, int event); 256typedef void (*bfa_sm_t)(void *sm, int event);
257 257
258/** 258/*
259 * oc - object class eg. bfa_ioc 259 * oc - object class eg. bfa_ioc
260 * st - state, eg. reset 260 * st - state, eg. reset
261 * otype - object type, eg. struct bfa_ioc_s 261 * otype - object type, eg. struct bfa_ioc_s
@@ -269,7 +269,7 @@ typedef void (*bfa_sm_t)(void *sm, int event);
269#define bfa_sm_get_state(_sm) ((_sm)->sm) 269#define bfa_sm_get_state(_sm) ((_sm)->sm)
270#define bfa_sm_cmp_state(_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state)) 270#define bfa_sm_cmp_state(_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state))
271 271
272/** 272/*
273 * For converting from state machine function to state encoding. 273 * For converting from state machine function to state encoding.
274 */ 274 */
275struct bfa_sm_table_s { 275struct bfa_sm_table_s {
@@ -279,12 +279,12 @@ struct bfa_sm_table_s {
279}; 279};
280#define BFA_SM(_sm) ((bfa_sm_t)(_sm)) 280#define BFA_SM(_sm) ((bfa_sm_t)(_sm))
281 281
282/** 282/*
283 * State machine with entry actions. 283 * State machine with entry actions.
284 */ 284 */
285typedef void (*bfa_fsm_t)(void *fsm, int event); 285typedef void (*bfa_fsm_t)(void *fsm, int event);
286 286
287/** 287/*
288 * oc - object class eg. bfa_ioc 288 * oc - object class eg. bfa_ioc
289 * st - state, eg. reset 289 * st - state, eg. reset
290 * otype - object type, eg. struct bfa_ioc_s 290 * otype - object type, eg. struct bfa_ioc_s
@@ -314,7 +314,7 @@ bfa_sm_to_state(struct bfa_sm_table_s *smt, bfa_sm_t sm)
314 return smt[i].state; 314 return smt[i].state;
315} 315}
316 316
317/** 317/*
318 * @ Generic wait counter. 318 * @ Generic wait counter.
319 */ 319 */
320 320
@@ -340,7 +340,7 @@ bfa_wc_down(struct bfa_wc_s *wc)
340 wc->wc_resume(wc->wc_cbarg); 340 wc->wc_resume(wc->wc_cbarg);
341} 341}
342 342
343/** 343/*
344 * Initialize a waiting counter. 344 * Initialize a waiting counter.
345 */ 345 */
346static inline void 346static inline void
@@ -352,7 +352,7 @@ bfa_wc_init(struct bfa_wc_s *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg)
352 bfa_wc_up(wc); 352 bfa_wc_up(wc);
353} 353}
354 354
355/** 355/*
356 * Wait for counter to reach zero 356 * Wait for counter to reach zero
357 */ 357 */
358static inline void 358static inline void
diff --git a/drivers/scsi/bfa/bfa_defs.h b/drivers/scsi/bfa/bfa_defs.h
index d49877ff5140..4b5b9e35abb9 100644
--- a/drivers/scsi/bfa/bfa_defs.h
+++ b/drivers/scsi/bfa/bfa_defs.h
@@ -24,7 +24,7 @@
24#define BFA_MFG_SERIALNUM_SIZE 11 24#define BFA_MFG_SERIALNUM_SIZE 11
25#define STRSZ(_n) (((_n) + 4) & ~3) 25#define STRSZ(_n) (((_n) + 4) & ~3)
26 26
27/** 27/*
28 * Manufacturing card type 28 * Manufacturing card type
29 */ 29 */
30enum { 30enum {
@@ -45,7 +45,7 @@ enum {
45 45
46#pragma pack(1) 46#pragma pack(1)
47 47
48/** 48/*
49 * Check if Mezz card 49 * Check if Mezz card
50 */ 50 */
51#define bfa_mfg_is_mezz(type) (( \ 51#define bfa_mfg_is_mezz(type) (( \
@@ -55,7 +55,7 @@ enum {
55 (type) == BFA_MFG_TYPE_LIGHTNING_P0 || \ 55 (type) == BFA_MFG_TYPE_LIGHTNING_P0 || \
56 (type) == BFA_MFG_TYPE_LIGHTNING)) 56 (type) == BFA_MFG_TYPE_LIGHTNING))
57 57
58/** 58/*
59 * Check if the card having old wwn/mac handling 59 * Check if the card having old wwn/mac handling
60 */ 60 */
61#define bfa_mfg_is_old_wwn_mac_model(type) (( \ 61#define bfa_mfg_is_old_wwn_mac_model(type) (( \
@@ -78,12 +78,12 @@ do { \
78 (m)[2] = t & 0xFF; \ 78 (m)[2] = t & 0xFF; \
79} while (0) 79} while (0)
80 80
81/** 81/*
82 * VPD data length 82 * VPD data length
83 */ 83 */
84#define BFA_MFG_VPD_LEN 512 84#define BFA_MFG_VPD_LEN 512
85 85
86/** 86/*
87 * VPD vendor tag 87 * VPD vendor tag
88 */ 88 */
89enum { 89enum {
@@ -97,7 +97,7 @@ enum {
97 BFA_MFG_VPD_PCI_BRCD = 0xf8, /* PCI VPD Brocade */ 97 BFA_MFG_VPD_PCI_BRCD = 0xf8, /* PCI VPD Brocade */
98}; 98};
99 99
100/** 100/*
101 * All numerical fields are in big-endian format. 101 * All numerical fields are in big-endian format.
102 */ 102 */
103struct bfa_mfg_vpd_s { 103struct bfa_mfg_vpd_s {
@@ -112,7 +112,7 @@ struct bfa_mfg_vpd_s {
112 112
113#pragma pack() 113#pragma pack()
114 114
115/** 115/*
116 * Status return values 116 * Status return values
117 */ 117 */
118enum bfa_status { 118enum bfa_status {
@@ -167,11 +167,11 @@ enum bfa_boolean {
167#define BFA_STRING_32 32 167#define BFA_STRING_32 32
168#define BFA_VERSION_LEN 64 168#define BFA_VERSION_LEN 64
169 169
170/** 170/*
171 * ---------------------- adapter definitions ------------ 171 * ---------------------- adapter definitions ------------
172 */ 172 */
173 173
174/** 174/*
175 * BFA adapter level attributes. 175 * BFA adapter level attributes.
176 */ 176 */
177enum { 177enum {
@@ -215,7 +215,7 @@ struct bfa_adapter_attr_s {
215 u8 trunk_capable; 215 u8 trunk_capable;
216}; 216};
217 217
218/** 218/*
219 * ---------------------- IOC definitions ------------ 219 * ---------------------- IOC definitions ------------
220 */ 220 */
221 221
@@ -224,7 +224,7 @@ enum {
224 BFA_IOC_CHIP_REV_LEN = 8, 224 BFA_IOC_CHIP_REV_LEN = 8,
225}; 225};
226 226
227/** 227/*
228 * Driver and firmware versions. 228 * Driver and firmware versions.
229 */ 229 */
230struct bfa_ioc_driver_attr_s { 230struct bfa_ioc_driver_attr_s {
@@ -236,7 +236,7 @@ struct bfa_ioc_driver_attr_s {
236 char ob_ver[BFA_VERSION_LEN]; /* openboot version */ 236 char ob_ver[BFA_VERSION_LEN]; /* openboot version */
237}; 237};
238 238
239/** 239/*
240 * IOC PCI device attributes 240 * IOC PCI device attributes
241 */ 241 */
242struct bfa_ioc_pci_attr_s { 242struct bfa_ioc_pci_attr_s {
@@ -249,7 +249,7 @@ struct bfa_ioc_pci_attr_s {
249 char chip_rev[BFA_IOC_CHIP_REV_LEN]; /* chip revision */ 249 char chip_rev[BFA_IOC_CHIP_REV_LEN]; /* chip revision */
250}; 250};
251 251
252/** 252/*
253 * IOC states 253 * IOC states
254 */ 254 */
255enum bfa_ioc_state { 255enum bfa_ioc_state {
@@ -267,7 +267,7 @@ enum bfa_ioc_state {
267 BFA_IOC_ENABLING = 12, /* IOC is being enabled */ 267 BFA_IOC_ENABLING = 12, /* IOC is being enabled */
268}; 268};
269 269
270/** 270/*
271 * IOC firmware stats 271 * IOC firmware stats
272 */ 272 */
273struct bfa_fw_ioc_stats_s { 273struct bfa_fw_ioc_stats_s {
@@ -279,7 +279,7 @@ struct bfa_fw_ioc_stats_s {
279 u32 unknown_reqs; 279 u32 unknown_reqs;
280}; 280};
281 281
282/** 282/*
283 * IOC driver stats 283 * IOC driver stats
284 */ 284 */
285struct bfa_ioc_drv_stats_s { 285struct bfa_ioc_drv_stats_s {
@@ -296,7 +296,7 @@ struct bfa_ioc_drv_stats_s {
296 u32 enable_replies; 296 u32 enable_replies;
297}; 297};
298 298
299/** 299/*
300 * IOC statistics 300 * IOC statistics
301 */ 301 */
302struct bfa_ioc_stats_s { 302struct bfa_ioc_stats_s {
@@ -310,7 +310,7 @@ enum bfa_ioc_type_e {
310 BFA_IOC_TYPE_LL = 3, 310 BFA_IOC_TYPE_LL = 3,
311}; 311};
312 312
313/** 313/*
314 * IOC attributes returned in queries 314 * IOC attributes returned in queries
315 */ 315 */
316struct bfa_ioc_attr_s { 316struct bfa_ioc_attr_s {
@@ -323,11 +323,11 @@ struct bfa_ioc_attr_s {
323 u8 rsvd[7]; /* 64bit align */ 323 u8 rsvd[7]; /* 64bit align */
324}; 324};
325 325
326/** 326/*
327 * ---------------------- mfg definitions ------------ 327 * ---------------------- mfg definitions ------------
328 */ 328 */
329 329
330/** 330/*
331 * Checksum size 331 * Checksum size
332 */ 332 */
333#define BFA_MFG_CHKSUM_SIZE 16 333#define BFA_MFG_CHKSUM_SIZE 16
@@ -340,7 +340,7 @@ struct bfa_ioc_attr_s {
340 340
341#pragma pack(1) 341#pragma pack(1)
342 342
343/** 343/*
344 * All numerical fields are in big-endian format. 344 * All numerical fields are in big-endian format.
345 */ 345 */
346struct bfa_mfg_block_s { 346struct bfa_mfg_block_s {
@@ -373,11 +373,11 @@ struct bfa_mfg_block_s {
373 373
374#pragma pack() 374#pragma pack()
375 375
376/** 376/*
377 * ---------------------- pci definitions ------------ 377 * ---------------------- pci definitions ------------
378 */ 378 */
379 379
380/** 380/*
381 * PCI device and vendor ID information 381 * PCI device and vendor ID information
382 */ 382 */
383enum { 383enum {
@@ -392,14 +392,14 @@ enum {
392 ((devid) == BFA_PCI_DEVICE_ID_CT || \ 392 ((devid) == BFA_PCI_DEVICE_ID_CT || \
393 (devid) == BFA_PCI_DEVICE_ID_CT_FC) 393 (devid) == BFA_PCI_DEVICE_ID_CT_FC)
394 394
395/** 395/*
396 * PCI sub-system device and vendor ID information 396 * PCI sub-system device and vendor ID information
397 */ 397 */
398enum { 398enum {
399 BFA_PCI_FCOE_SSDEVICE_ID = 0x14, 399 BFA_PCI_FCOE_SSDEVICE_ID = 0x14,
400}; 400};
401 401
402/** 402/*
403 * Maximum number of device address ranges mapped through different BAR(s) 403 * Maximum number of device address ranges mapped through different BAR(s)
404 */ 404 */
405#define BFA_PCI_ACCESS_RANGES 1 405#define BFA_PCI_ACCESS_RANGES 1
@@ -430,7 +430,7 @@ enum {
430#define BOOT_CFG_REV1 1 430#define BOOT_CFG_REV1 1
431#define BOOT_CFG_VLAN 1 431#define BOOT_CFG_VLAN 1
432 432
433/** 433/*
434 * Boot options setting. Boot options setting determines from where 434 * Boot options setting. Boot options setting determines from where
435 * to get the boot lun information 435 * to get the boot lun information
436 */ 436 */
@@ -442,7 +442,7 @@ enum bfa_boot_bootopt {
442}; 442};
443 443
444#pragma pack(1) 444#pragma pack(1)
445/** 445/*
446 * Boot lun information. 446 * Boot lun information.
447 */ 447 */
448struct bfa_boot_bootlun_s { 448struct bfa_boot_bootlun_s {
@@ -451,7 +451,7 @@ struct bfa_boot_bootlun_s {
451}; 451};
452#pragma pack() 452#pragma pack()
453 453
454/** 454/*
455 * BOOT boot configuraton 455 * BOOT boot configuraton
456 */ 456 */
457struct bfa_boot_pbc_s { 457struct bfa_boot_pbc_s {
diff --git a/drivers/scsi/bfa/bfa_defs_fcs.h b/drivers/scsi/bfa/bfa_defs_fcs.h
index 96905d301828..191d34a58b9c 100644
--- a/drivers/scsi/bfa/bfa_defs_fcs.h
+++ b/drivers/scsi/bfa/bfa_defs_fcs.h
@@ -21,7 +21,7 @@
21#include "bfa_fc.h" 21#include "bfa_fc.h"
22#include "bfa_defs_svc.h" 22#include "bfa_defs_svc.h"
23 23
24/** 24/*
25 * VF states 25 * VF states
26 */ 26 */
27enum bfa_vf_state { 27enum bfa_vf_state {
@@ -35,7 +35,7 @@ enum bfa_vf_state {
35 BFA_VF_ISOLATED = 7, /* port isolated due to vf_id mismatch */ 35 BFA_VF_ISOLATED = 7, /* port isolated due to vf_id mismatch */
36}; 36};
37 37
38/** 38/*
39 * VF statistics 39 * VF statistics
40 */ 40 */
41struct bfa_vf_stats_s { 41struct bfa_vf_stats_s {
@@ -55,7 +55,7 @@ struct bfa_vf_stats_s {
55 u32 resvd; /* padding for 64 bit alignment */ 55 u32 resvd; /* padding for 64 bit alignment */
56}; 56};
57 57
58/** 58/*
59 * VF attributes returned in queries 59 * VF attributes returned in queries
60 */ 60 */
61struct bfa_vf_attr_s { 61struct bfa_vf_attr_s {
@@ -67,7 +67,7 @@ struct bfa_vf_attr_s {
67#define BFA_FCS_MAX_LPORTS 256 67#define BFA_FCS_MAX_LPORTS 256
68#define BFA_FCS_FABRIC_IPADDR_SZ 16 68#define BFA_FCS_FABRIC_IPADDR_SZ 16
69 69
70/** 70/*
71 * symbolic names for base port/virtual port 71 * symbolic names for base port/virtual port
72 */ 72 */
73#define BFA_SYMNAME_MAXLEN 128 /* 128 bytes */ 73#define BFA_SYMNAME_MAXLEN 128 /* 128 bytes */
@@ -75,7 +75,7 @@ struct bfa_lport_symname_s {
75 char symname[BFA_SYMNAME_MAXLEN]; 75 char symname[BFA_SYMNAME_MAXLEN];
76}; 76};
77 77
78/** 78/*
79* Roles of FCS port: 79* Roles of FCS port:
80 * - FCP IM and FCP TM roles cannot be enabled together for a FCS port 80 * - FCP IM and FCP TM roles cannot be enabled together for a FCS port
81 * - Create multiple ports if both IM and TM functions required. 81 * - Create multiple ports if both IM and TM functions required.
@@ -86,19 +86,19 @@ enum bfa_lport_role {
86 BFA_LPORT_ROLE_FCP_MAX = BFA_LPORT_ROLE_FCP_IM, 86 BFA_LPORT_ROLE_FCP_MAX = BFA_LPORT_ROLE_FCP_IM,
87}; 87};
88 88
89/** 89/*
90 * FCS port configuration. 90 * FCS port configuration.
91 */ 91 */
92struct bfa_lport_cfg_s { 92struct bfa_lport_cfg_s {
93 wwn_t pwwn; /* port wwn */ 93 wwn_t pwwn; /* port wwn */
94 wwn_t nwwn; /* node wwn */ 94 wwn_t nwwn; /* node wwn */
95 struct bfa_lport_symname_s sym_name; /* vm port symbolic name */ 95 struct bfa_lport_symname_s sym_name; /* vm port symbolic name */
96 bfa_boolean_t preboot_vp; /* vport created from PBC */ 96 bfa_boolean_t preboot_vp; /* vport created from PBC */
97 enum bfa_lport_role roles; /* FCS port roles */ 97 enum bfa_lport_role roles; /* FCS port roles */
98 u8 tag[16]; /* opaque tag from application */ 98 u8 tag[16]; /* opaque tag from application */
99}; 99};
100 100
101/** 101/*
102 * FCS port states 102 * FCS port states
103 */ 103 */
104enum bfa_lport_state { 104enum bfa_lport_state {
@@ -108,7 +108,7 @@ enum bfa_lport_state {
108 BFA_LPORT_OFFLINE = 3, /* No login to fabric */ 108 BFA_LPORT_OFFLINE = 3, /* No login to fabric */
109}; 109};
110 110
111/** 111/*
112 * FCS port type. 112 * FCS port type.
113 */ 113 */
114enum bfa_lport_type { 114enum bfa_lport_type {
@@ -116,7 +116,7 @@ enum bfa_lport_type {
116 BFA_LPORT_TYPE_VIRTUAL, 116 BFA_LPORT_TYPE_VIRTUAL,
117}; 117};
118 118
119/** 119/*
120 * FCS port offline reason. 120 * FCS port offline reason.
121 */ 121 */
122enum bfa_lport_offline_reason { 122enum bfa_lport_offline_reason {
@@ -128,7 +128,7 @@ enum bfa_lport_offline_reason {
128 BFA_LPORT_OFFLINE_FAB_LOGOUT, 128 BFA_LPORT_OFFLINE_FAB_LOGOUT,
129}; 129};
130 130
131/** 131/*
132 * FCS lport info. 132 * FCS lport info.
133 */ 133 */
134struct bfa_lport_info_s { 134struct bfa_lport_info_s {
@@ -150,7 +150,7 @@ struct bfa_lport_info_s {
150 150
151}; 151};
152 152
153/** 153/*
154 * FCS port statistics 154 * FCS port statistics
155 */ 155 */
156struct bfa_lport_stats_s { 156struct bfa_lport_stats_s {
@@ -222,7 +222,7 @@ struct bfa_lport_stats_s {
222 * (max retry of plogi) */ 222 * (max retry of plogi) */
223}; 223};
224 224
225/** 225/*
226 * BFA port attribute returned in queries 226 * BFA port attribute returned in queries
227 */ 227 */
228struct bfa_lport_attr_s { 228struct bfa_lport_attr_s {
@@ -239,7 +239,7 @@ struct bfa_lport_attr_s {
239}; 239};
240 240
241 241
242/** 242/*
243 * VPORT states 243 * VPORT states
244 */ 244 */
245enum bfa_vport_state { 245enum bfa_vport_state {
@@ -258,7 +258,7 @@ enum bfa_vport_state {
258 BFA_FCS_VPORT_MAX_STATE, 258 BFA_FCS_VPORT_MAX_STATE,
259}; 259};
260 260
261/** 261/*
262 * vport statistics 262 * vport statistics
263 */ 263 */
264struct bfa_vport_stats_s { 264struct bfa_vport_stats_s {
@@ -296,7 +296,7 @@ struct bfa_vport_stats_s {
296 u32 rsvd; 296 u32 rsvd;
297}; 297};
298 298
299/** 299/*
300 * BFA vport attribute returned in queries 300 * BFA vport attribute returned in queries
301 */ 301 */
302struct bfa_vport_attr_s { 302struct bfa_vport_attr_s {
@@ -305,7 +305,7 @@ struct bfa_vport_attr_s {
305 u32 rsvd; 305 u32 rsvd;
306}; 306};
307 307
308/** 308/*
309 * FCS remote port states 309 * FCS remote port states
310 */ 310 */
311enum bfa_rport_state { 311enum bfa_rport_state {
@@ -321,7 +321,7 @@ enum bfa_rport_state {
321 BFA_RPORT_NSDISC = 9, /* re-discover rport */ 321 BFA_RPORT_NSDISC = 9, /* re-discover rport */
322}; 322};
323 323
324/** 324/*
325 * Rport Scsi Function : Initiator/Target. 325 * Rport Scsi Function : Initiator/Target.
326 */ 326 */
327enum bfa_rport_function { 327enum bfa_rport_function {
@@ -329,7 +329,7 @@ enum bfa_rport_function {
329 BFA_RPORT_TARGET = 0x02, /* SCSI Target */ 329 BFA_RPORT_TARGET = 0x02, /* SCSI Target */
330}; 330};
331 331
332/** 332/*
333 * port/node symbolic names for rport 333 * port/node symbolic names for rport
334 */ 334 */
335#define BFA_RPORT_SYMNAME_MAXLEN 255 335#define BFA_RPORT_SYMNAME_MAXLEN 255
@@ -337,7 +337,7 @@ struct bfa_rport_symname_s {
337 char symname[BFA_RPORT_SYMNAME_MAXLEN]; 337 char symname[BFA_RPORT_SYMNAME_MAXLEN];
338}; 338};
339 339
340/** 340/*
341 * FCS remote port statistics 341 * FCS remote port statistics
342 */ 342 */
343struct bfa_rport_stats_s { 343struct bfa_rport_stats_s {
@@ -374,7 +374,7 @@ struct bfa_rport_stats_s {
374 struct bfa_rport_hal_stats_s hal_stats; /* BFA rport stats */ 374 struct bfa_rport_hal_stats_s hal_stats; /* BFA rport stats */
375}; 375};
376 376
377/** 377/*
378 * FCS remote port attributes returned in queries 378 * FCS remote port attributes returned in queries
379 */ 379 */
380struct bfa_rport_attr_s { 380struct bfa_rport_attr_s {
@@ -411,7 +411,7 @@ struct bfa_rport_remote_link_stats_s {
411#define BFA_MAX_IO_INDEX 7 411#define BFA_MAX_IO_INDEX 7
412#define BFA_NO_IO_INDEX 9 412#define BFA_NO_IO_INDEX 9
413 413
414/** 414/*
415 * FCS itnim states 415 * FCS itnim states
416 */ 416 */
417enum bfa_itnim_state { 417enum bfa_itnim_state {
@@ -425,7 +425,7 @@ enum bfa_itnim_state {
425 BFA_ITNIM_INITIATIOR = 7, /* initiator */ 425 BFA_ITNIM_INITIATIOR = 7, /* initiator */
426}; 426};
427 427
428/** 428/*
429 * FCS remote port statistics 429 * FCS remote port statistics
430 */ 430 */
431struct bfa_itnim_stats_s { 431struct bfa_itnim_stats_s {
@@ -443,7 +443,7 @@ struct bfa_itnim_stats_s {
443 u32 rsvd; /* padding for 64 bit alignment */ 443 u32 rsvd; /* padding for 64 bit alignment */
444}; 444};
445 445
446/** 446/*
447 * FCS itnim attributes returned in queries 447 * FCS itnim attributes returned in queries
448 */ 448 */
449struct bfa_itnim_attr_s { 449struct bfa_itnim_attr_s {
diff --git a/drivers/scsi/bfa/bfa_defs_svc.h b/drivers/scsi/bfa/bfa_defs_svc.h
index 56226fcf9470..e24e9f7ca81f 100644
--- a/drivers/scsi/bfa/bfa_defs_svc.h
+++ b/drivers/scsi/bfa/bfa_defs_svc.h
@@ -27,7 +27,7 @@
27#define BFA_IOCFCOE_INTR_DELAY 25 27#define BFA_IOCFCOE_INTR_DELAY 25
28#define BFA_IOCFCOE_INTR_LATENCY 5 28#define BFA_IOCFCOE_INTR_LATENCY 5
29 29
30/** 30/*
31 * Interrupt coalescing configuration. 31 * Interrupt coalescing configuration.
32 */ 32 */
33#pragma pack(1) 33#pragma pack(1)
@@ -38,7 +38,7 @@ struct bfa_iocfc_intr_attr_s {
38 u16 delay; /* delay in microseconds */ 38 u16 delay; /* delay in microseconds */
39}; 39};
40 40
41/** 41/*
42 * IOC firmware configuraton 42 * IOC firmware configuraton
43 */ 43 */
44struct bfa_iocfc_fwcfg_s { 44struct bfa_iocfc_fwcfg_s {
@@ -71,7 +71,7 @@ struct bfa_iocfc_drvcfg_s {
71 u32 rsvd; 71 u32 rsvd;
72}; 72};
73 73
74/** 74/*
75 * IOC configuration 75 * IOC configuration
76 */ 76 */
77struct bfa_iocfc_cfg_s { 77struct bfa_iocfc_cfg_s {
@@ -79,7 +79,7 @@ struct bfa_iocfc_cfg_s {
79 struct bfa_iocfc_drvcfg_s drvcfg; /* driver side config */ 79 struct bfa_iocfc_drvcfg_s drvcfg; /* driver side config */
80}; 80};
81 81
82/** 82/*
83 * IOC firmware IO stats 83 * IOC firmware IO stats
84 */ 84 */
85struct bfa_fw_io_stats_s { 85struct bfa_fw_io_stats_s {
@@ -152,7 +152,7 @@ struct bfa_fw_io_stats_s {
152 */ 152 */
153}; 153};
154 154
155/** 155/*
156 * IOC port firmware stats 156 * IOC port firmware stats
157 */ 157 */
158 158
@@ -262,7 +262,7 @@ struct bfa_fw_fcoe_stats_s {
262 u32 mac_invalids; /* Invalid mac assigned */ 262 u32 mac_invalids; /* Invalid mac assigned */
263}; 263};
264 264
265/** 265/*
266 * IOC firmware FCoE port stats 266 * IOC firmware FCoE port stats
267 */ 267 */
268struct bfa_fw_fcoe_port_stats_s { 268struct bfa_fw_fcoe_port_stats_s {
@@ -270,7 +270,7 @@ struct bfa_fw_fcoe_port_stats_s {
270 struct bfa_fw_fip_stats_s fip_stats; 270 struct bfa_fw_fip_stats_s fip_stats;
271}; 271};
272 272
273/** 273/*
274 * IOC firmware FC uport stats 274 * IOC firmware FC uport stats
275 */ 275 */
276struct bfa_fw_fc_uport_stats_s { 276struct bfa_fw_fc_uport_stats_s {
@@ -278,7 +278,7 @@ struct bfa_fw_fc_uport_stats_s {
278 struct bfa_fw_port_lksm_stats_s lksm_stats; 278 struct bfa_fw_port_lksm_stats_s lksm_stats;
279}; 279};
280 280
281/** 281/*
282 * IOC firmware FC port stats 282 * IOC firmware FC port stats
283 */ 283 */
284union bfa_fw_fc_port_stats_s { 284union bfa_fw_fc_port_stats_s {
@@ -286,7 +286,7 @@ union bfa_fw_fc_port_stats_s {
286 struct bfa_fw_fcoe_port_stats_s fcoe_stats; 286 struct bfa_fw_fcoe_port_stats_s fcoe_stats;
287}; 287};
288 288
289/** 289/*
290 * IOC firmware port stats 290 * IOC firmware port stats
291 */ 291 */
292struct bfa_fw_port_stats_s { 292struct bfa_fw_port_stats_s {
@@ -295,7 +295,7 @@ struct bfa_fw_port_stats_s {
295 union bfa_fw_fc_port_stats_s fc_port; 295 union bfa_fw_fc_port_stats_s fc_port;
296}; 296};
297 297
298/** 298/*
299 * fcxchg module statistics 299 * fcxchg module statistics
300 */ 300 */
301struct bfa_fw_fcxchg_stats_s { 301struct bfa_fw_fcxchg_stats_s {
@@ -308,7 +308,7 @@ struct bfa_fw_lpsm_stats_s {
308 u32 cls_tx; 308 u32 cls_tx;
309}; 309};
310 310
311/** 311/*
312 * Trunk statistics 312 * Trunk statistics
313 */ 313 */
314struct bfa_fw_trunk_stats_s { 314struct bfa_fw_trunk_stats_s {
@@ -334,7 +334,7 @@ struct bfa_fw_advsm_stats_s {
334 u32 elp_dropped; /* ELP dropped */ 334 u32 elp_dropped; /* ELP dropped */
335}; 335};
336 336
337/** 337/*
338 * IOCFC firmware stats 338 * IOCFC firmware stats
339 */ 339 */
340struct bfa_fw_iocfc_stats_s { 340struct bfa_fw_iocfc_stats_s {
@@ -345,7 +345,7 @@ struct bfa_fw_iocfc_stats_s {
345 u32 set_intr_reqs; /* set interrupt reqs */ 345 u32 set_intr_reqs; /* set interrupt reqs */
346}; 346};
347 347
348/** 348/*
349 * IOC attributes returned in queries 349 * IOC attributes returned in queries
350 */ 350 */
351struct bfa_iocfc_attr_s { 351struct bfa_iocfc_attr_s {
@@ -353,7 +353,7 @@ struct bfa_iocfc_attr_s {
353 struct bfa_iocfc_intr_attr_s intr_attr; /* interrupt attr */ 353 struct bfa_iocfc_intr_attr_s intr_attr; /* interrupt attr */
354}; 354};
355 355
356/** 356/*
357 * Eth_sndrcv mod stats 357 * Eth_sndrcv mod stats
358 */ 358 */
359struct bfa_fw_eth_sndrcv_stats_s { 359struct bfa_fw_eth_sndrcv_stats_s {
@@ -361,7 +361,7 @@ struct bfa_fw_eth_sndrcv_stats_s {
361 u32 rsvd; /* 64bit align */ 361 u32 rsvd; /* 64bit align */
362}; 362};
363 363
364/** 364/*
365 * CT MAC mod stats 365 * CT MAC mod stats
366 */ 366 */
367struct bfa_fw_mac_mod_stats_s { 367struct bfa_fw_mac_mod_stats_s {
@@ -379,7 +379,7 @@ struct bfa_fw_mac_mod_stats_s {
379 u32 rsvd; /* 64bit align */ 379 u32 rsvd; /* 64bit align */
380}; 380};
381 381
382/** 382/*
383 * CT MOD stats 383 * CT MOD stats
384 */ 384 */
385struct bfa_fw_ct_mod_stats_s { 385struct bfa_fw_ct_mod_stats_s {
@@ -391,7 +391,7 @@ struct bfa_fw_ct_mod_stats_s {
391 u32 rsvd; /* 64bit align */ 391 u32 rsvd; /* 64bit align */
392}; 392};
393 393
394/** 394/*
395 * IOC firmware stats 395 * IOC firmware stats
396 */ 396 */
397struct bfa_fw_stats_s { 397struct bfa_fw_stats_s {
@@ -412,7 +412,7 @@ struct bfa_fw_stats_s {
412#define BFA_IOCFC_PATHTOV_MAX 60 412#define BFA_IOCFC_PATHTOV_MAX 60
413#define BFA_IOCFC_QDEPTH_MAX 2000 413#define BFA_IOCFC_QDEPTH_MAX 2000
414 414
415/** 415/*
416 * QoS states 416 * QoS states
417 */ 417 */
418enum bfa_qos_state { 418enum bfa_qos_state {
@@ -420,7 +420,7 @@ enum bfa_qos_state {
420 BFA_QOS_OFFLINE = 2, /* QoS is offline */ 420 BFA_QOS_OFFLINE = 2, /* QoS is offline */
421}; 421};
422 422
423/** 423/*
424 * QoS Priority levels. 424 * QoS Priority levels.
425 */ 425 */
426enum bfa_qos_priority { 426enum bfa_qos_priority {
@@ -430,7 +430,7 @@ enum bfa_qos_priority {
430 BFA_QOS_LOW = 3, /* QoS Priority Level Low */ 430 BFA_QOS_LOW = 3, /* QoS Priority Level Low */
431}; 431};
432 432
433/** 433/*
434 * QoS bandwidth allocation for each priority level 434 * QoS bandwidth allocation for each priority level
435 */ 435 */
436enum bfa_qos_bw_alloc { 436enum bfa_qos_bw_alloc {
@@ -439,7 +439,7 @@ enum bfa_qos_bw_alloc {
439 BFA_QOS_BW_LOW = 10, /* bandwidth allocation for Low */ 439 BFA_QOS_BW_LOW = 10, /* bandwidth allocation for Low */
440}; 440};
441#pragma pack(1) 441#pragma pack(1)
442/** 442/*
443 * QoS attribute returned in QoS Query 443 * QoS attribute returned in QoS Query
444 */ 444 */
445struct bfa_qos_attr_s { 445struct bfa_qos_attr_s {
@@ -448,7 +448,7 @@ struct bfa_qos_attr_s {
448 u32 total_bb_cr; /* Total BB Credits */ 448 u32 total_bb_cr; /* Total BB Credits */
449}; 449};
450 450
451/** 451/*
452 * These fields should be displayed only from the CLI. 452 * These fields should be displayed only from the CLI.
453 * There will be a separate BFAL API (get_qos_vc_attr ?) 453 * There will be a separate BFAL API (get_qos_vc_attr ?)
454 * to retrieve this. 454 * to retrieve this.
@@ -471,7 +471,7 @@ struct bfa_qos_vc_attr_s {
471 * total_vc_count */ 471 * total_vc_count */
472}; 472};
473 473
474/** 474/*
475 * QoS statistics 475 * QoS statistics
476 */ 476 */
477struct bfa_qos_stats_s { 477struct bfa_qos_stats_s {
@@ -489,7 +489,7 @@ struct bfa_qos_stats_s {
489 u32 rsvd; /* padding for 64 bit alignment */ 489 u32 rsvd; /* padding for 64 bit alignment */
490}; 490};
491 491
492/** 492/*
493 * FCoE statistics 493 * FCoE statistics
494 */ 494 */
495struct bfa_fcoe_stats_s { 495struct bfa_fcoe_stats_s {
@@ -540,7 +540,7 @@ struct bfa_fcoe_stats_s {
540 u64 rxf_bcast_vlan; /* Rx FCoE broadcast vlan frames */ 540 u64 rxf_bcast_vlan; /* Rx FCoE broadcast vlan frames */
541}; 541};
542 542
543/** 543/*
544 * QoS or FCoE stats (fcport stats excluding physical FC port stats) 544 * QoS or FCoE stats (fcport stats excluding physical FC port stats)
545 */ 545 */
546union bfa_fcport_stats_u { 546union bfa_fcport_stats_u {
@@ -639,7 +639,7 @@ enum bfa_port_states {
639 BFA_PORT_ST_MAX_STATE, 639 BFA_PORT_ST_MAX_STATE,
640}; 640};
641 641
642/** 642/*
643 * Port operational type (in sync with SNIA port type). 643 * Port operational type (in sync with SNIA port type).
644 */ 644 */
645enum bfa_port_type { 645enum bfa_port_type {
@@ -651,7 +651,7 @@ enum bfa_port_type {
651 BFA_PORT_TYPE_VPORT = 22, /* NPIV - virtual port */ 651 BFA_PORT_TYPE_VPORT = 22, /* NPIV - virtual port */
652}; 652};
653 653
654/** 654/*
655 * Port topology setting. A port's topology and fabric login status 655 * Port topology setting. A port's topology and fabric login status
656 * determine its operational type. 656 * determine its operational type.
657 */ 657 */
@@ -662,7 +662,7 @@ enum bfa_port_topology {
662 BFA_PORT_TOPOLOGY_AUTO = 3, /* auto topology selection */ 662 BFA_PORT_TOPOLOGY_AUTO = 3, /* auto topology selection */
663}; 663};
664 664
665/** 665/*
666 * Physical port loopback types. 666 * Physical port loopback types.
667 */ 667 */
668enum bfa_port_opmode { 668enum bfa_port_opmode {
@@ -679,7 +679,7 @@ enum bfa_port_opmode {
679 (_mode == BFA_PORT_OPMODE_LB_SLW) || \ 679 (_mode == BFA_PORT_OPMODE_LB_SLW) || \
680 (_mode == BFA_PORT_OPMODE_LB_EXT)) 680 (_mode == BFA_PORT_OPMODE_LB_EXT))
681 681
682/** 682/*
683 * Port link state 683 * Port link state
684 */ 684 */
685enum bfa_port_linkstate { 685enum bfa_port_linkstate {
@@ -687,7 +687,7 @@ enum bfa_port_linkstate {
687 BFA_PORT_LINKDOWN = 2, /* Physical port/Trunk link down */ 687 BFA_PORT_LINKDOWN = 2, /* Physical port/Trunk link down */
688}; 688};
689 689
690/** 690/*
691 * Port link state reason code 691 * Port link state reason code
692 */ 692 */
693enum bfa_port_linkstate_rsn { 693enum bfa_port_linkstate_rsn {
@@ -733,7 +733,7 @@ enum bfa_port_linkstate_rsn {
733 CEE_ISCSI_PRI_OVERLAP_FCOE_PRI = 43 733 CEE_ISCSI_PRI_OVERLAP_FCOE_PRI = 43
734}; 734};
735#pragma pack(1) 735#pragma pack(1)
736/** 736/*
737 * Physical port configuration 737 * Physical port configuration
738 */ 738 */
739struct bfa_port_cfg_s { 739struct bfa_port_cfg_s {
@@ -753,7 +753,7 @@ struct bfa_port_cfg_s {
753}; 753};
754#pragma pack() 754#pragma pack()
755 755
756/** 756/*
757 * Port attribute values. 757 * Port attribute values.
758 */ 758 */
759struct bfa_port_attr_s { 759struct bfa_port_attr_s {
@@ -800,7 +800,7 @@ struct bfa_port_attr_s {
800 u8 rsvd1[6]; 800 u8 rsvd1[6];
801}; 801};
802 802
803/** 803/*
804 * Port FCP mappings. 804 * Port FCP mappings.
805 */ 805 */
806struct bfa_port_fcpmap_s { 806struct bfa_port_fcpmap_s {
@@ -815,7 +815,7 @@ struct bfa_port_fcpmap_s {
815 char luid[256]; 815 char luid[256];
816}; 816};
817 817
818/** 818/*
819 * Port RNID info. 819 * Port RNID info.
820 */ 820 */
821struct bfa_port_rnid_s { 821struct bfa_port_rnid_s {
@@ -848,7 +848,7 @@ struct bfa_fcport_fcf_s {
848 mac_t mac; /* FCF mac */ 848 mac_t mac; /* FCF mac */
849}; 849};
850 850
851/** 851/*
852 * Trunk states for BCU/BFAL 852 * Trunk states for BCU/BFAL
853 */ 853 */
854enum bfa_trunk_state { 854enum bfa_trunk_state {
@@ -857,7 +857,7 @@ enum bfa_trunk_state {
857 BFA_TRUNK_OFFLINE = 2, /* Trunk is offline */ 857 BFA_TRUNK_OFFLINE = 2, /* Trunk is offline */
858}; 858};
859 859
860/** 860/*
861 * VC attributes for trunked link 861 * VC attributes for trunked link
862 */ 862 */
863struct bfa_trunk_vc_attr_s { 863struct bfa_trunk_vc_attr_s {
@@ -867,7 +867,7 @@ struct bfa_trunk_vc_attr_s {
867 u16 vc_credits[8]; 867 u16 vc_credits[8];
868}; 868};
869 869
870/** 870/*
871 * Link state information 871 * Link state information
872 */ 872 */
873struct bfa_port_link_s { 873struct bfa_port_link_s {
@@ -959,7 +959,7 @@ struct bfa_rport_hal_stats_s {
959 u32 rsvd; 959 u32 rsvd;
960}; 960};
961#pragma pack(1) 961#pragma pack(1)
962/** 962/*
963 * Rport's QoS attributes 963 * Rport's QoS attributes
964 */ 964 */
965struct bfa_rport_qos_attr_s { 965struct bfa_rport_qos_attr_s {
@@ -987,7 +987,7 @@ struct bfa_itnim_ioprofile_s {
987 struct bfa_itnim_latency_s io_latency; 987 struct bfa_itnim_latency_s io_latency;
988}; 988};
989 989
990/** 990/*
991 * FC physical port statistics. 991 * FC physical port statistics.
992 */ 992 */
993struct bfa_port_fc_stats_s { 993struct bfa_port_fc_stats_s {
@@ -1022,7 +1022,7 @@ struct bfa_port_fc_stats_s {
1022 u64 err_enc; /* Encoding err frame_8b10b */ 1022 u64 err_enc; /* Encoding err frame_8b10b */
1023}; 1023};
1024 1024
1025/** 1025/*
1026 * Eth Physical Port statistics. 1026 * Eth Physical Port statistics.
1027 */ 1027 */
1028struct bfa_port_eth_stats_s { 1028struct bfa_port_eth_stats_s {
@@ -1070,7 +1070,7 @@ struct bfa_port_eth_stats_s {
1070 u64 tx_iscsi_zero_pause; /* Tx iSCSI zero pause */ 1070 u64 tx_iscsi_zero_pause; /* Tx iSCSI zero pause */
1071}; 1071};
1072 1072
1073/** 1073/*
1074 * Port statistics. 1074 * Port statistics.
1075 */ 1075 */
1076union bfa_port_stats_u { 1076union bfa_port_stats_u {
diff --git a/drivers/scsi/bfa/bfa_drv.c b/drivers/scsi/bfa/bfa_drv.c
index 14127646dc54..0222d7c88a9a 100644
--- a/drivers/scsi/bfa/bfa_drv.c
+++ b/drivers/scsi/bfa/bfa_drv.c
@@ -17,7 +17,7 @@
17 17
18#include "bfa_modules.h" 18#include "bfa_modules.h"
19 19
20/** 20/*
21 * BFA module list terminated by NULL 21 * BFA module list terminated by NULL
22 */ 22 */
23struct bfa_module_s *hal_mods[] = { 23struct bfa_module_s *hal_mods[] = {
@@ -31,7 +31,7 @@ struct bfa_module_s *hal_mods[] = {
31 NULL 31 NULL
32}; 32};
33 33
34/** 34/*
35 * Message handlers for various modules. 35 * Message handlers for various modules.
36 */ 36 */
37bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = { 37bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = {
@@ -70,7 +70,7 @@ bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = {
70}; 70};
71 71
72 72
73/** 73/*
74 * Message handlers for mailbox command classes 74 * Message handlers for mailbox command classes
75 */ 75 */
76bfa_ioc_mbox_mcfunc_t bfa_mbox_isrs[BFI_MC_MAX] = { 76bfa_ioc_mbox_mcfunc_t bfa_mbox_isrs[BFI_MC_MAX] = {
diff --git a/drivers/scsi/bfa/bfa_fc.h b/drivers/scsi/bfa/bfa_fc.h
index 6eff705564eb..e929d25b09e3 100644
--- a/drivers/scsi/bfa/bfa_fc.h
+++ b/drivers/scsi/bfa/bfa_fc.h
@@ -1029,7 +1029,7 @@ struct link_e2e_beacon_req_s {
1029 struct link_e2e_beacon_param_s beacon_parm; 1029 struct link_e2e_beacon_param_s beacon_parm;
1030}; 1030};
1031 1031
1032/** 1032/*
1033 * If RPSC request is sent to the Domain Controller, the request is for 1033 * If RPSC request is sent to the Domain Controller, the request is for
1034 * all the ports within that domain (TODO - I don't think FOS implements 1034 * all the ports within that domain (TODO - I don't think FOS implements
1035 * this...). 1035 * this...).
@@ -1049,7 +1049,7 @@ struct fc_rpsc_acc_s {
1049 struct fc_rpsc_speed_info_s speed_info[1]; 1049 struct fc_rpsc_speed_info_s speed_info[1];
1050}; 1050};
1051 1051
1052/** 1052/*
1053 * If RPSC2 request is sent to the Domain Controller, 1053 * If RPSC2 request is sent to the Domain Controller,
1054 */ 1054 */
1055#define FC_BRCD_TOKEN 0x42524344 1055#define FC_BRCD_TOKEN 0x42524344
@@ -1094,7 +1094,7 @@ struct fc_rpsc2_acc_s {
1094 struct fc_rpsc2_port_info_s port_info[1]; /* port information */ 1094 struct fc_rpsc2_port_info_s port_info[1]; /* port information */
1095}; 1095};
1096 1096
1097/** 1097/*
1098 * bit fields so that multiple classes can be specified 1098 * bit fields so that multiple classes can be specified
1099 */ 1099 */
1100enum fc_cos { 1100enum fc_cos {
@@ -1131,7 +1131,7 @@ struct fc_alpabm_s {
1131#define FC_VF_ID_MAX 0xEFF 1131#define FC_VF_ID_MAX 0xEFF
1132#define FC_VF_ID_CTL 0xFEF /* control VF_ID */ 1132#define FC_VF_ID_CTL 0xFEF /* control VF_ID */
1133 1133
1134/** 1134/*
1135 * Virtual Fabric Tagging header format 1135 * Virtual Fabric Tagging header format
1136 * @caution This is defined only in BIG ENDIAN format. 1136 * @caution This is defined only in BIG ENDIAN format.
1137 */ 1137 */
@@ -1463,7 +1463,7 @@ struct fcgs_gidpn_resp_s {
1463 u32 dap:24; /* port identifier */ 1463 u32 dap:24; /* port identifier */
1464}; 1464};
1465 1465
1466/** 1466/*
1467 * RFT_ID 1467 * RFT_ID
1468 */ 1468 */
1469struct fcgs_rftid_req_s { 1469struct fcgs_rftid_req_s {
@@ -1472,7 +1472,7 @@ struct fcgs_rftid_req_s {
1472 u32 fc4_type[8]; /* fc4 types */ 1472 u32 fc4_type[8]; /* fc4 types */
1473}; 1473};
1474 1474
1475/** 1475/*
1476 * RFF_ID : Register FC4 features. 1476 * RFF_ID : Register FC4 features.
1477 */ 1477 */
1478 1478
@@ -1487,7 +1487,7 @@ struct fcgs_rffid_req_s {
1487 u32 fc4_type:8; /* corresponding FC4 Type */ 1487 u32 fc4_type:8; /* corresponding FC4 Type */
1488}; 1488};
1489 1489
1490/** 1490/*
1491 * GID_FT Request 1491 * GID_FT Request
1492 */ 1492 */
1493struct fcgs_gidft_req_s { 1493struct fcgs_gidft_req_s {
@@ -1497,7 +1497,7 @@ struct fcgs_gidft_req_s {
1497 u8 fc4_type; /* FC_TYPE_FCP for SCSI devices */ 1497 u8 fc4_type; /* FC_TYPE_FCP for SCSI devices */
1498}; /* GID_FT Request */ 1498}; /* GID_FT Request */
1499 1499
1500/** 1500/*
1501 * GID_FT Response 1501 * GID_FT Response
1502 */ 1502 */
1503struct fcgs_gidft_resp_s { 1503struct fcgs_gidft_resp_s {
@@ -1506,7 +1506,7 @@ struct fcgs_gidft_resp_s {
1506 u32 pid:24; /* port identifier */ 1506 u32 pid:24; /* port identifier */
1507}; /* GID_FT Response */ 1507}; /* GID_FT Response */
1508 1508
1509/** 1509/*
1510 * RSPN_ID 1510 * RSPN_ID
1511 */ 1511 */
1512struct fcgs_rspnid_req_s { 1512struct fcgs_rspnid_req_s {
@@ -1516,7 +1516,7 @@ struct fcgs_rspnid_req_s {
1516 u8 spn[256]; /* symbolic port name */ 1516 u8 spn[256]; /* symbolic port name */
1517}; 1517};
1518 1518
1519/** 1519/*
1520 * RPN_ID 1520 * RPN_ID
1521 */ 1521 */
1522struct fcgs_rpnid_req_s { 1522struct fcgs_rpnid_req_s {
@@ -1525,7 +1525,7 @@ struct fcgs_rpnid_req_s {
1525 wwn_t port_name; 1525 wwn_t port_name;
1526}; 1526};
1527 1527
1528/** 1528/*
1529 * RNN_ID 1529 * RNN_ID
1530 */ 1530 */
1531struct fcgs_rnnid_req_s { 1531struct fcgs_rnnid_req_s {
@@ -1534,7 +1534,7 @@ struct fcgs_rnnid_req_s {
1534 wwn_t node_name; 1534 wwn_t node_name;
1535}; 1535};
1536 1536
1537/** 1537/*
1538 * RCS_ID 1538 * RCS_ID
1539 */ 1539 */
1540struct fcgs_rcsid_req_s { 1540struct fcgs_rcsid_req_s {
@@ -1543,7 +1543,7 @@ struct fcgs_rcsid_req_s {
1543 u32 cos; 1543 u32 cos;
1544}; 1544};
1545 1545
1546/** 1546/*
1547 * RPT_ID 1547 * RPT_ID
1548 */ 1548 */
1549struct fcgs_rptid_req_s { 1549struct fcgs_rptid_req_s {
@@ -1553,7 +1553,7 @@ struct fcgs_rptid_req_s {
1553 u32 rsvd1:24; 1553 u32 rsvd1:24;
1554}; 1554};
1555 1555
1556/** 1556/*
1557 * GA_NXT Request 1557 * GA_NXT Request
1558 */ 1558 */
1559struct fcgs_ganxt_req_s { 1559struct fcgs_ganxt_req_s {
@@ -1561,7 +1561,7 @@ struct fcgs_ganxt_req_s {
1561 u32 port_id:24; 1561 u32 port_id:24;
1562}; 1562};
1563 1563
1564/** 1564/*
1565 * GA_NXT Response 1565 * GA_NXT Response
1566 */ 1566 */
1567struct fcgs_ganxt_rsp_s { 1567struct fcgs_ganxt_rsp_s {
diff --git a/drivers/scsi/bfa/bfa_fcbuild.c b/drivers/scsi/bfa/bfa_fcbuild.c
index b7d2657ca82a..9c725314b513 100644
--- a/drivers/scsi/bfa/bfa_fcbuild.c
+++ b/drivers/scsi/bfa/bfa_fcbuild.c
@@ -94,13 +94,13 @@ fcbuild_init(void)
94 */ 94 */
95 plogi_tmpl.csp.verhi = FC_PH_VER_PH_3; 95 plogi_tmpl.csp.verhi = FC_PH_VER_PH_3;
96 plogi_tmpl.csp.verlo = FC_PH_VER_4_3; 96 plogi_tmpl.csp.verlo = FC_PH_VER_4_3;
97 plogi_tmpl.csp.bbcred = bfa_os_htons(0x0004); 97 plogi_tmpl.csp.bbcred = cpu_to_be16(0x0004);
98 plogi_tmpl.csp.ciro = 0x1; 98 plogi_tmpl.csp.ciro = 0x1;
99 plogi_tmpl.csp.cisc = 0x0; 99 plogi_tmpl.csp.cisc = 0x0;
100 plogi_tmpl.csp.altbbcred = 0x0; 100 plogi_tmpl.csp.altbbcred = 0x0;
101 plogi_tmpl.csp.conseq = bfa_os_htons(0x00FF); 101 plogi_tmpl.csp.conseq = cpu_to_be16(0x00FF);
102 plogi_tmpl.csp.ro_bitmap = bfa_os_htons(0x0002); 102 plogi_tmpl.csp.ro_bitmap = cpu_to_be16(0x0002);
103 plogi_tmpl.csp.e_d_tov = bfa_os_htonl(2000); 103 plogi_tmpl.csp.e_d_tov = cpu_to_be32(2000);
104 104
105 plogi_tmpl.class3.class_valid = 1; 105 plogi_tmpl.class3.class_valid = 1;
106 plogi_tmpl.class3.sequential = 1; 106 plogi_tmpl.class3.sequential = 1;
@@ -112,7 +112,7 @@ fcbuild_init(void)
112 */ 112 */
113 prli_tmpl.command = FC_ELS_PRLI; 113 prli_tmpl.command = FC_ELS_PRLI;
114 prli_tmpl.pglen = 0x10; 114 prli_tmpl.pglen = 0x10;
115 prli_tmpl.pagebytes = bfa_os_htons(0x0014); 115 prli_tmpl.pagebytes = cpu_to_be16(0x0014);
116 prli_tmpl.parampage.type = FC_TYPE_FCP; 116 prli_tmpl.parampage.type = FC_TYPE_FCP;
117 prli_tmpl.parampage.imagepair = 1; 117 prli_tmpl.parampage.imagepair = 1;
118 prli_tmpl.parampage.servparams.rxrdisab = 1; 118 prli_tmpl.parampage.servparams.rxrdisab = 1;
@@ -137,7 +137,7 @@ fcbuild_init(void)
137static void 137static void
138fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id) 138fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id)
139{ 139{
140 bfa_os_memset(fchs, 0, sizeof(struct fchs_s)); 140 memset(fchs, 0, sizeof(struct fchs_s));
141 141
142 fchs->routing = FC_RTG_FC4_DEV_DATA; 142 fchs->routing = FC_RTG_FC4_DEV_DATA;
143 fchs->cat_info = FC_CAT_UNSOLICIT_CTRL; 143 fchs->cat_info = FC_CAT_UNSOLICIT_CTRL;
@@ -148,9 +148,9 @@ fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id)
148 fchs->rx_id = FC_RXID_ANY; 148 fchs->rx_id = FC_RXID_ANY;
149 fchs->d_id = (d_id); 149 fchs->d_id = (d_id);
150 fchs->s_id = (s_id); 150 fchs->s_id = (s_id);
151 fchs->ox_id = bfa_os_htons(ox_id); 151 fchs->ox_id = cpu_to_be16(ox_id);
152 152
153 /** 153 /*
154 * @todo no need to set ox_id for request 154 * @todo no need to set ox_id for request
155 * no need to set rx_id for response 155 * no need to set rx_id for response
156 */ 156 */
@@ -159,16 +159,16 @@ fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id)
159void 159void
160fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id) 160fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
161{ 161{
162 bfa_os_memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s)); 162 memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s));
163 fchs->d_id = (d_id); 163 fchs->d_id = (d_id);
164 fchs->s_id = (s_id); 164 fchs->s_id = (s_id);
165 fchs->ox_id = bfa_os_htons(ox_id); 165 fchs->ox_id = cpu_to_be16(ox_id);
166} 166}
167 167
168static void 168static void
169fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id) 169fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
170{ 170{
171 bfa_os_memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s)); 171 memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s));
172 fchs->d_id = d_id; 172 fchs->d_id = d_id;
173 fchs->s_id = s_id; 173 fchs->s_id = s_id;
174 fchs->ox_id = ox_id; 174 fchs->ox_id = ox_id;
@@ -198,7 +198,7 @@ fc_els_rsp_parse(struct fchs_s *fchs, int len)
198static void 198static void
199fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id) 199fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
200{ 200{
201 bfa_os_memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s)); 201 memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s));
202 fchs->d_id = d_id; 202 fchs->d_id = d_id;
203 fchs->s_id = s_id; 203 fchs->s_id = s_id;
204 fchs->ox_id = ox_id; 204 fchs->ox_id = ox_id;
@@ -211,7 +211,7 @@ fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
211{ 211{
212 struct fc_logi_s *plogi = (struct fc_logi_s *) (pld); 212 struct fc_logi_s *plogi = (struct fc_logi_s *) (pld);
213 213
214 bfa_os_memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s)); 214 memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s));
215 215
216 plogi->els_cmd.els_code = els_code; 216 plogi->els_cmd.els_code = els_code;
217 if (els_code == FC_ELS_PLOGI) 217 if (els_code == FC_ELS_PLOGI)
@@ -219,10 +219,10 @@ fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
219 else 219 else
220 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 220 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
221 221
222 plogi->csp.rxsz = plogi->class3.rxsz = bfa_os_htons(pdu_size); 222 plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size);
223 223
224 bfa_os_memcpy(&plogi->port_name, &port_name, sizeof(wwn_t)); 224 memcpy(&plogi->port_name, &port_name, sizeof(wwn_t));
225 bfa_os_memcpy(&plogi->node_name, &node_name, sizeof(wwn_t)); 225 memcpy(&plogi->node_name, &node_name, sizeof(wwn_t));
226 226
227 return sizeof(struct fc_logi_s); 227 return sizeof(struct fc_logi_s);
228} 228}
@@ -235,12 +235,12 @@ fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
235 u32 d_id = bfa_os_hton3b(FC_FABRIC_PORT); 235 u32 d_id = bfa_os_hton3b(FC_FABRIC_PORT);
236 u32 *vvl_info; 236 u32 *vvl_info;
237 237
238 bfa_os_memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s)); 238 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
239 239
240 flogi->els_cmd.els_code = FC_ELS_FLOGI; 240 flogi->els_cmd.els_code = FC_ELS_FLOGI;
241 fc_els_req_build(fchs, d_id, s_id, ox_id); 241 fc_els_req_build(fchs, d_id, s_id, ox_id);
242 242
243 flogi->csp.rxsz = flogi->class3.rxsz = bfa_os_htons(pdu_size); 243 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
244 flogi->port_name = port_name; 244 flogi->port_name = port_name;
245 flogi->node_name = node_name; 245 flogi->node_name = node_name;
246 246
@@ -253,14 +253,14 @@ fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
253 /* set AUTH capability */ 253 /* set AUTH capability */
254 flogi->csp.security = set_auth; 254 flogi->csp.security = set_auth;
255 255
256 flogi->csp.bbcred = bfa_os_htons(local_bb_credits); 256 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
257 257
258 /* Set brcd token in VVL */ 258 /* Set brcd token in VVL */
259 vvl_info = (u32 *)&flogi->vvl[0]; 259 vvl_info = (u32 *)&flogi->vvl[0];
260 260
261 /* set the flag to indicate the presence of VVL */ 261 /* set the flag to indicate the presence of VVL */
262 flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */ 262 flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */
263 vvl_info[0] = bfa_os_htonl(FLOGI_VVL_BRCD); 263 vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
264 264
265 return sizeof(struct fc_logi_s); 265 return sizeof(struct fc_logi_s);
266} 266}
@@ -272,15 +272,15 @@ fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
272{ 272{
273 u32 d_id = 0; 273 u32 d_id = 0;
274 274
275 bfa_os_memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s)); 275 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
276 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 276 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
277 277
278 flogi->els_cmd.els_code = FC_ELS_ACC; 278 flogi->els_cmd.els_code = FC_ELS_ACC;
279 flogi->csp.rxsz = flogi->class3.rxsz = bfa_os_htons(pdu_size); 279 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
280 flogi->port_name = port_name; 280 flogi->port_name = port_name;
281 flogi->node_name = node_name; 281 flogi->node_name = node_name;
282 282
283 flogi->csp.bbcred = bfa_os_htons(local_bb_credits); 283 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
284 284
285 return sizeof(struct fc_logi_s); 285 return sizeof(struct fc_logi_s);
286} 286}
@@ -291,12 +291,12 @@ fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
291{ 291{
292 u32 d_id = bfa_os_hton3b(FC_FABRIC_PORT); 292 u32 d_id = bfa_os_hton3b(FC_FABRIC_PORT);
293 293
294 bfa_os_memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s)); 294 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
295 295
296 flogi->els_cmd.els_code = FC_ELS_FDISC; 296 flogi->els_cmd.els_code = FC_ELS_FDISC;
297 fc_els_req_build(fchs, d_id, s_id, ox_id); 297 fc_els_req_build(fchs, d_id, s_id, ox_id);
298 298
299 flogi->csp.rxsz = flogi->class3.rxsz = bfa_os_htons(pdu_size); 299 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
300 flogi->port_name = port_name; 300 flogi->port_name = port_name;
301 flogi->node_name = node_name; 301 flogi->node_name = node_name;
302 302
@@ -346,7 +346,7 @@ fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
346 if (!plogi->class3.class_valid) 346 if (!plogi->class3.class_valid)
347 return FC_PARSE_FAILURE; 347 return FC_PARSE_FAILURE;
348 348
349 if (bfa_os_ntohs(plogi->class3.rxsz) < (FC_MIN_PDUSZ)) 349 if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ))
350 return FC_PARSE_FAILURE; 350 return FC_PARSE_FAILURE;
351 351
352 return FC_PARSE_OK; 352 return FC_PARSE_OK;
@@ -363,8 +363,8 @@ fc_plogi_parse(struct fchs_s *fchs)
363 if (plogi->class3.class_valid != 1) 363 if (plogi->class3.class_valid != 1)
364 return FC_PARSE_FAILURE; 364 return FC_PARSE_FAILURE;
365 365
366 if ((bfa_os_ntohs(plogi->class3.rxsz) < FC_MIN_PDUSZ) 366 if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ)
367 || (bfa_os_ntohs(plogi->class3.rxsz) > FC_MAX_PDUSZ) 367 || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ)
368 || (plogi->class3.rxsz == 0)) 368 || (plogi->class3.rxsz == 0))
369 return FC_PARSE_FAILURE; 369 return FC_PARSE_FAILURE;
370 370
@@ -378,7 +378,7 @@ fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
378 struct fc_prli_s *prli = (struct fc_prli_s *) (pld); 378 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
379 379
380 fc_els_req_build(fchs, d_id, s_id, ox_id); 380 fc_els_req_build(fchs, d_id, s_id, ox_id);
381 bfa_os_memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s)); 381 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
382 382
383 prli->command = FC_ELS_PRLI; 383 prli->command = FC_ELS_PRLI;
384 prli->parampage.servparams.initiator = 1; 384 prli->parampage.servparams.initiator = 1;
@@ -397,7 +397,7 @@ fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
397 struct fc_prli_s *prli = (struct fc_prli_s *) (pld); 397 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
398 398
399 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 399 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
400 bfa_os_memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s)); 400 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
401 401
402 prli->command = FC_ELS_ACC; 402 prli->command = FC_ELS_ACC;
403 403
@@ -448,7 +448,7 @@ fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id, u32 s_id,
448{ 448{
449 fc_els_req_build(fchs, d_id, s_id, ox_id); 449 fc_els_req_build(fchs, d_id, s_id, ox_id);
450 450
451 bfa_os_memset(logo, '\0', sizeof(struct fc_logo_s)); 451 memset(logo, '\0', sizeof(struct fc_logo_s));
452 logo->els_cmd.els_code = FC_ELS_LOGO; 452 logo->els_cmd.els_code = FC_ELS_LOGO;
453 logo->nport_id = (s_id); 453 logo->nport_id = (s_id);
454 logo->orig_port_name = port_name; 454 logo->orig_port_name = port_name;
@@ -461,7 +461,7 @@ fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
461 u32 s_id, u16 ox_id, wwn_t port_name, 461 u32 s_id, u16 ox_id, wwn_t port_name,
462 wwn_t node_name, u8 els_code) 462 wwn_t node_name, u8 els_code)
463{ 463{
464 bfa_os_memset(adisc, '\0', sizeof(struct fc_adisc_s)); 464 memset(adisc, '\0', sizeof(struct fc_adisc_s));
465 465
466 adisc->els_cmd.els_code = els_code; 466 adisc->els_cmd.els_code = els_code;
467 467
@@ -537,7 +537,7 @@ fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
537 if (pdisc->class3.class_valid != 1) 537 if (pdisc->class3.class_valid != 1)
538 return FC_PARSE_FAILURE; 538 return FC_PARSE_FAILURE;
539 539
540 if ((bfa_os_ntohs(pdisc->class3.rxsz) < 540 if ((be16_to_cpu(pdisc->class3.rxsz) <
541 (FC_MIN_PDUSZ - sizeof(struct fchs_s))) 541 (FC_MIN_PDUSZ - sizeof(struct fchs_s)))
542 || (pdisc->class3.rxsz == 0)) 542 || (pdisc->class3.rxsz == 0))
543 return FC_PARSE_FAILURE; 543 return FC_PARSE_FAILURE;
@@ -554,11 +554,11 @@ fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
554u16 554u16
555fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id) 555fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
556{ 556{
557 bfa_os_memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s)); 557 memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s));
558 fchs->cat_info = FC_CAT_ABTS; 558 fchs->cat_info = FC_CAT_ABTS;
559 fchs->d_id = (d_id); 559 fchs->d_id = (d_id);
560 fchs->s_id = (s_id); 560 fchs->s_id = (s_id);
561 fchs->ox_id = bfa_os_htons(ox_id); 561 fchs->ox_id = cpu_to_be16(ox_id);
562 562
563 return sizeof(struct fchs_s); 563 return sizeof(struct fchs_s);
564} 564}
@@ -582,9 +582,9 @@ fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id,
582 /* 582 /*
583 * build rrq payload 583 * build rrq payload
584 */ 584 */
585 bfa_os_memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s)); 585 memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s));
586 rrq->s_id = (s_id); 586 rrq->s_id = (s_id);
587 rrq->ox_id = bfa_os_htons(rrq_oxid); 587 rrq->ox_id = cpu_to_be16(rrq_oxid);
588 rrq->rx_id = FC_RXID_ANY; 588 rrq->rx_id = FC_RXID_ANY;
589 589
590 return sizeof(struct fc_rrq_s); 590 return sizeof(struct fc_rrq_s);
@@ -598,7 +598,7 @@ fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
598 598
599 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 599 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
600 600
601 bfa_os_memset(acc, 0, sizeof(struct fc_els_cmd_s)); 601 memset(acc, 0, sizeof(struct fc_els_cmd_s));
602 acc->els_code = FC_ELS_ACC; 602 acc->els_code = FC_ELS_ACC;
603 603
604 return sizeof(struct fc_els_cmd_s); 604 return sizeof(struct fc_els_cmd_s);
@@ -610,7 +610,7 @@ fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id,
610 u8 reason_code_expl) 610 u8 reason_code_expl)
611{ 611{
612 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 612 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
613 bfa_os_memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s)); 613 memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s));
614 614
615 ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT; 615 ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT;
616 ls_rjt->reason_code = reason_code; 616 ls_rjt->reason_code = reason_code;
@@ -626,7 +626,7 @@ fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
626{ 626{
627 fc_bls_rsp_build(fchs, d_id, s_id, ox_id); 627 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
628 628
629 bfa_os_memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s)); 629 memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s));
630 630
631 fchs->rx_id = rx_id; 631 fchs->rx_id = rx_id;
632 632
@@ -641,7 +641,7 @@ fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id,
641 u32 s_id, u16 ox_id) 641 u32 s_id, u16 ox_id)
642{ 642{
643 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 643 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
644 bfa_os_memset(els_cmd, 0, sizeof(struct fc_els_cmd_s)); 644 memset(els_cmd, 0, sizeof(struct fc_els_cmd_s));
645 els_cmd->els_code = FC_ELS_ACC; 645 els_cmd->els_code = FC_ELS_ACC;
646 646
647 return sizeof(struct fc_els_cmd_s); 647 return sizeof(struct fc_els_cmd_s);
@@ -656,10 +656,10 @@ fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code)
656 656
657 if (els_code == FC_ELS_PRLO) { 657 if (els_code == FC_ELS_PRLO) {
658 prlo = (struct fc_prlo_s *) (fc_frame + 1); 658 prlo = (struct fc_prlo_s *) (fc_frame + 1);
659 num_pages = (bfa_os_ntohs(prlo->payload_len) - 4) / 16; 659 num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16;
660 } else { 660 } else {
661 tprlo = (struct fc_tprlo_s *) (fc_frame + 1); 661 tprlo = (struct fc_tprlo_s *) (fc_frame + 1);
662 num_pages = (bfa_os_ntohs(tprlo->payload_len) - 4) / 16; 662 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
663 } 663 }
664 return num_pages; 664 return num_pages;
665} 665}
@@ -672,11 +672,11 @@ fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
672 672
673 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 673 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
674 674
675 bfa_os_memset(tprlo_acc, 0, (num_pages * 16) + 4); 675 memset(tprlo_acc, 0, (num_pages * 16) + 4);
676 tprlo_acc->command = FC_ELS_ACC; 676 tprlo_acc->command = FC_ELS_ACC;
677 677
678 tprlo_acc->page_len = 0x10; 678 tprlo_acc->page_len = 0x10;
679 tprlo_acc->payload_len = bfa_os_htons((num_pages * 16) + 4); 679 tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
680 680
681 for (page = 0; page < num_pages; page++) { 681 for (page = 0; page < num_pages; page++) {
682 tprlo_acc->tprlo_acc_params[page].opa_valid = 0; 682 tprlo_acc->tprlo_acc_params[page].opa_valid = 0;
@@ -685,7 +685,7 @@ fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
685 tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0; 685 tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0;
686 tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0; 686 tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0;
687 } 687 }
688 return bfa_os_ntohs(tprlo_acc->payload_len); 688 return be16_to_cpu(tprlo_acc->payload_len);
689} 689}
690 690
691u16 691u16
@@ -696,10 +696,10 @@ fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
696 696
697 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 697 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
698 698
699 bfa_os_memset(prlo_acc, 0, (num_pages * 16) + 4); 699 memset(prlo_acc, 0, (num_pages * 16) + 4);
700 prlo_acc->command = FC_ELS_ACC; 700 prlo_acc->command = FC_ELS_ACC;
701 prlo_acc->page_len = 0x10; 701 prlo_acc->page_len = 0x10;
702 prlo_acc->payload_len = bfa_os_htons((num_pages * 16) + 4); 702 prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
703 703
704 for (page = 0; page < num_pages; page++) { 704 for (page = 0; page < num_pages; page++) {
705 prlo_acc->prlo_acc_params[page].opa_valid = 0; 705 prlo_acc->prlo_acc_params[page].opa_valid = 0;
@@ -709,7 +709,7 @@ fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
709 prlo_acc->prlo_acc_params[page].resp_process_assc = 0; 709 prlo_acc->prlo_acc_params[page].resp_process_assc = 0;
710 } 710 }
711 711
712 return bfa_os_ntohs(prlo_acc->payload_len); 712 return be16_to_cpu(prlo_acc->payload_len);
713} 713}
714 714
715u16 715u16
@@ -718,7 +718,7 @@ fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id,
718{ 718{
719 fc_els_req_build(fchs, d_id, s_id, ox_id); 719 fc_els_req_build(fchs, d_id, s_id, ox_id);
720 720
721 bfa_os_memset(rnid, 0, sizeof(struct fc_rnid_cmd_s)); 721 memset(rnid, 0, sizeof(struct fc_rnid_cmd_s));
722 722
723 rnid->els_cmd.els_code = FC_ELS_RNID; 723 rnid->els_cmd.els_code = FC_ELS_RNID;
724 rnid->node_id_data_format = data_format; 724 rnid->node_id_data_format = data_format;
@@ -732,7 +732,7 @@ fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
732 struct fc_rnid_common_id_data_s *common_id_data, 732 struct fc_rnid_common_id_data_s *common_id_data,
733 struct fc_rnid_general_topology_data_s *gen_topo_data) 733 struct fc_rnid_general_topology_data_s *gen_topo_data)
734{ 734{
735 bfa_os_memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s)); 735 memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s));
736 736
737 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 737 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
738 738
@@ -745,7 +745,7 @@ fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
745 if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) { 745 if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
746 rnid_acc->specific_id_data_length = 746 rnid_acc->specific_id_data_length =
747 sizeof(struct fc_rnid_general_topology_data_s); 747 sizeof(struct fc_rnid_general_topology_data_s);
748 bfa_os_assign(rnid_acc->gen_topology_data, *gen_topo_data); 748 rnid_acc->gen_topology_data = *gen_topo_data;
749 return sizeof(struct fc_rnid_acc_s); 749 return sizeof(struct fc_rnid_acc_s);
750 } else { 750 } else {
751 return sizeof(struct fc_rnid_acc_s) - 751 return sizeof(struct fc_rnid_acc_s) -
@@ -760,7 +760,7 @@ fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id,
760{ 760{
761 fc_els_req_build(fchs, d_id, s_id, ox_id); 761 fc_els_req_build(fchs, d_id, s_id, ox_id);
762 762
763 bfa_os_memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s)); 763 memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s));
764 764
765 rpsc->els_cmd.els_code = FC_ELS_RPSC; 765 rpsc->els_cmd.els_code = FC_ELS_RPSC;
766 return sizeof(struct fc_rpsc_cmd_s); 766 return sizeof(struct fc_rpsc_cmd_s);
@@ -775,11 +775,11 @@ fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id,
775 775
776 fc_els_req_build(fchs, bfa_os_hton3b(dctlr_id), s_id, 0); 776 fc_els_req_build(fchs, bfa_os_hton3b(dctlr_id), s_id, 0);
777 777
778 bfa_os_memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s)); 778 memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s));
779 779
780 rpsc2->els_cmd.els_code = FC_ELS_RPSC; 780 rpsc2->els_cmd.els_code = FC_ELS_RPSC;
781 rpsc2->token = bfa_os_htonl(FC_BRCD_TOKEN); 781 rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN);
782 rpsc2->num_pids = bfa_os_htons(npids); 782 rpsc2->num_pids = cpu_to_be16(npids);
783 for (i = 0; i < npids; i++) 783 for (i = 0; i < npids; i++)
784 rpsc2->pid_list[i].pid = pid_list[i]; 784 rpsc2->pid_list[i].pid = pid_list[i];
785 785
@@ -791,18 +791,18 @@ fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
791 u32 d_id, u32 s_id, u16 ox_id, 791 u32 d_id, u32 s_id, u16 ox_id,
792 struct fc_rpsc_speed_info_s *oper_speed) 792 struct fc_rpsc_speed_info_s *oper_speed)
793{ 793{
794 bfa_os_memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s)); 794 memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s));
795 795
796 fc_els_rsp_build(fchs, d_id, s_id, ox_id); 796 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
797 797
798 rpsc_acc->command = FC_ELS_ACC; 798 rpsc_acc->command = FC_ELS_ACC;
799 rpsc_acc->num_entries = bfa_os_htons(1); 799 rpsc_acc->num_entries = cpu_to_be16(1);
800 800
801 rpsc_acc->speed_info[0].port_speed_cap = 801 rpsc_acc->speed_info[0].port_speed_cap =
802 bfa_os_htons(oper_speed->port_speed_cap); 802 cpu_to_be16(oper_speed->port_speed_cap);
803 803
804 rpsc_acc->speed_info[0].port_op_speed = 804 rpsc_acc->speed_info[0].port_op_speed =
805 bfa_os_htons(oper_speed->port_op_speed); 805 cpu_to_be16(oper_speed->port_op_speed);
806 806
807 return sizeof(struct fc_rpsc_acc_s); 807 return sizeof(struct fc_rpsc_acc_s);
808} 808}
@@ -830,12 +830,12 @@ fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
830{ 830{
831 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1); 831 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
832 832
833 bfa_os_memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s)); 833 memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s));
834 834
835 pdisc->els_cmd.els_code = FC_ELS_PDISC; 835 pdisc->els_cmd.els_code = FC_ELS_PDISC;
836 fc_els_req_build(fchs, d_id, s_id, ox_id); 836 fc_els_req_build(fchs, d_id, s_id, ox_id);
837 837
838 pdisc->csp.rxsz = pdisc->class3.rxsz = bfa_os_htons(pdu_size); 838 pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size);
839 pdisc->port_name = port_name; 839 pdisc->port_name = port_name;
840 pdisc->node_name = node_name; 840 pdisc->node_name = node_name;
841 841
@@ -859,7 +859,7 @@ fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
859 if (!pdisc->class3.class_valid) 859 if (!pdisc->class3.class_valid)
860 return FC_PARSE_NWWN_NOT_EQUAL; 860 return FC_PARSE_NWWN_NOT_EQUAL;
861 861
862 if (bfa_os_ntohs(pdisc->class3.rxsz) < (FC_MIN_PDUSZ)) 862 if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ))
863 return FC_PARSE_RXSZ_INVAL; 863 return FC_PARSE_RXSZ_INVAL;
864 864
865 return FC_PARSE_OK; 865 return FC_PARSE_OK;
@@ -873,10 +873,10 @@ fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
873 int page; 873 int page;
874 874
875 fc_els_req_build(fchs, d_id, s_id, ox_id); 875 fc_els_req_build(fchs, d_id, s_id, ox_id);
876 bfa_os_memset(prlo, 0, (num_pages * 16) + 4); 876 memset(prlo, 0, (num_pages * 16) + 4);
877 prlo->command = FC_ELS_PRLO; 877 prlo->command = FC_ELS_PRLO;
878 prlo->page_len = 0x10; 878 prlo->page_len = 0x10;
879 prlo->payload_len = bfa_os_htons((num_pages * 16) + 4); 879 prlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
880 880
881 for (page = 0; page < num_pages; page++) { 881 for (page = 0; page < num_pages; page++) {
882 prlo->prlo_params[page].type = FC_TYPE_FCP; 882 prlo->prlo_params[page].type = FC_TYPE_FCP;
@@ -886,7 +886,7 @@ fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
886 prlo->prlo_params[page].resp_process_assc = 0; 886 prlo->prlo_params[page].resp_process_assc = 0;
887 } 887 }
888 888
889 return bfa_os_ntohs(prlo->payload_len); 889 return be16_to_cpu(prlo->payload_len);
890} 890}
891 891
892u16 892u16
@@ -901,7 +901,7 @@ fc_prlo_rsp_parse(struct fchs_s *fchs, int len)
901 if (prlo->command != FC_ELS_ACC) 901 if (prlo->command != FC_ELS_ACC)
902 return FC_PARSE_FAILURE; 902 return FC_PARSE_FAILURE;
903 903
904 num_pages = ((bfa_os_ntohs(prlo->payload_len)) - 4) / 16; 904 num_pages = ((be16_to_cpu(prlo->payload_len)) - 4) / 16;
905 905
906 for (page = 0; page < num_pages; page++) { 906 for (page = 0; page < num_pages; page++) {
907 if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP) 907 if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP)
@@ -931,10 +931,10 @@ fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
931 int page; 931 int page;
932 932
933 fc_els_req_build(fchs, d_id, s_id, ox_id); 933 fc_els_req_build(fchs, d_id, s_id, ox_id);
934 bfa_os_memset(tprlo, 0, (num_pages * 16) + 4); 934 memset(tprlo, 0, (num_pages * 16) + 4);
935 tprlo->command = FC_ELS_TPRLO; 935 tprlo->command = FC_ELS_TPRLO;
936 tprlo->page_len = 0x10; 936 tprlo->page_len = 0x10;
937 tprlo->payload_len = bfa_os_htons((num_pages * 16) + 4); 937 tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
938 938
939 for (page = 0; page < num_pages; page++) { 939 for (page = 0; page < num_pages; page++) {
940 tprlo->tprlo_params[page].type = FC_TYPE_FCP; 940 tprlo->tprlo_params[page].type = FC_TYPE_FCP;
@@ -950,7 +950,7 @@ fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
950 } 950 }
951 } 951 }
952 952
953 return bfa_os_ntohs(tprlo->payload_len); 953 return be16_to_cpu(tprlo->payload_len);
954} 954}
955 955
956u16 956u16
@@ -965,7 +965,7 @@ fc_tprlo_rsp_parse(struct fchs_s *fchs, int len)
965 if (tprlo->command != FC_ELS_ACC) 965 if (tprlo->command != FC_ELS_ACC)
966 return FC_PARSE_ACC_INVAL; 966 return FC_PARSE_ACC_INVAL;
967 967
968 num_pages = (bfa_os_ntohs(tprlo->payload_len) - 4) / 16; 968 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
969 969
970 for (page = 0; page < num_pages; page++) { 970 for (page = 0; page < num_pages; page++) {
971 if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP) 971 if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP)
@@ -1011,32 +1011,32 @@ fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
1011static void 1011static void
1012fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code) 1012fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1013{ 1013{
1014 bfa_os_memset(cthdr, 0, sizeof(struct ct_hdr_s)); 1014 memset(cthdr, 0, sizeof(struct ct_hdr_s));
1015 cthdr->rev_id = CT_GS3_REVISION; 1015 cthdr->rev_id = CT_GS3_REVISION;
1016 cthdr->gs_type = CT_GSTYPE_DIRSERVICE; 1016 cthdr->gs_type = CT_GSTYPE_DIRSERVICE;
1017 cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER; 1017 cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER;
1018 cthdr->cmd_rsp_code = bfa_os_htons(cmd_code); 1018 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
1019} 1019}
1020 1020
1021static void 1021static void
1022fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code) 1022fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1023{ 1023{
1024 bfa_os_memset(cthdr, 0, sizeof(struct ct_hdr_s)); 1024 memset(cthdr, 0, sizeof(struct ct_hdr_s));
1025 cthdr->rev_id = CT_GS3_REVISION; 1025 cthdr->rev_id = CT_GS3_REVISION;
1026 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE; 1026 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1027 cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER; 1027 cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER;
1028 cthdr->cmd_rsp_code = bfa_os_htons(cmd_code); 1028 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
1029} 1029}
1030 1030
1031static void 1031static void
1032fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code, 1032fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code,
1033 u8 sub_type) 1033 u8 sub_type)
1034{ 1034{
1035 bfa_os_memset(cthdr, 0, sizeof(struct ct_hdr_s)); 1035 memset(cthdr, 0, sizeof(struct ct_hdr_s));
1036 cthdr->rev_id = CT_GS3_REVISION; 1036 cthdr->rev_id = CT_GS3_REVISION;
1037 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE; 1037 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1038 cthdr->gs_sub_type = sub_type; 1038 cthdr->gs_sub_type = sub_type;
1039 cthdr->cmd_rsp_code = bfa_os_htons(cmd_code); 1039 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
1040} 1040}
1041 1041
1042u16 1042u16
@@ -1050,7 +1050,7 @@ fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1050 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); 1050 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1051 fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN); 1051 fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN);
1052 1052
1053 bfa_os_memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s)); 1053 memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s));
1054 gidpn->port_name = port_name; 1054 gidpn->port_name = port_name;
1055 return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s); 1055 return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s);
1056} 1056}
@@ -1066,7 +1066,7 @@ fc_gpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1066 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); 1066 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1067 fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID); 1067 fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID);
1068 1068
1069 bfa_os_memset(gpnid, 0, sizeof(fcgs_gpnid_req_t)); 1069 memset(gpnid, 0, sizeof(fcgs_gpnid_req_t));
1070 gpnid->dap = port_id; 1070 gpnid->dap = port_id;
1071 return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s); 1071 return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s);
1072} 1072}
@@ -1082,7 +1082,7 @@ fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1082 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); 1082 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1083 fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID); 1083 fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID);
1084 1084
1085 bfa_os_memset(gnnid, 0, sizeof(fcgs_gnnid_req_t)); 1085 memset(gnnid, 0, sizeof(fcgs_gnnid_req_t));
1086 gnnid->dap = port_id; 1086 gnnid->dap = port_id;
1087 return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s); 1087 return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s);
1088} 1088}
@@ -1090,7 +1090,7 @@ fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1090u16 1090u16
1091fc_ct_rsp_parse(struct ct_hdr_s *cthdr) 1091fc_ct_rsp_parse(struct ct_hdr_s *cthdr)
1092{ 1092{
1093 if (bfa_os_ntohs(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) { 1093 if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) {
1094 if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY) 1094 if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY)
1095 return FC_PARSE_BUSY; 1095 return FC_PARSE_BUSY;
1096 else 1096 else
@@ -1108,7 +1108,7 @@ fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
1108 1108
1109 fc_els_req_build(fchs, d_id, s_id, ox_id); 1109 fc_els_req_build(fchs, d_id, s_id, ox_id);
1110 1110
1111 bfa_os_memset(scr, 0, sizeof(struct fc_scr_s)); 1111 memset(scr, 0, sizeof(struct fc_scr_s));
1112 scr->command = FC_ELS_SCR; 1112 scr->command = FC_ELS_SCR;
1113 scr->reg_func = FC_SCR_REG_FUNC_FULL; 1113 scr->reg_func = FC_SCR_REG_FUNC_FULL;
1114 if (set_br_reg) 1114 if (set_br_reg)
@@ -1129,7 +1129,7 @@ fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
1129 rscn->pagelen = sizeof(rscn->event[0]); 1129 rscn->pagelen = sizeof(rscn->event[0]);
1130 1130
1131 payldlen = sizeof(u32) + rscn->pagelen; 1131 payldlen = sizeof(u32) + rscn->pagelen;
1132 rscn->payldlen = bfa_os_htons(payldlen); 1132 rscn->payldlen = cpu_to_be16(payldlen);
1133 1133
1134 rscn->event[0].format = FC_RSCN_FORMAT_PORTID; 1134 rscn->event[0].format = FC_RSCN_FORMAT_PORTID;
1135 rscn->event[0].portid = s_id; 1135 rscn->event[0].portid = s_id;
@@ -1149,14 +1149,14 @@ fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1149 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); 1149 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1150 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID); 1150 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1151 1151
1152 bfa_os_memset(rftid, 0, sizeof(struct fcgs_rftid_req_s)); 1152 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
1153 1153
1154 rftid->dap = s_id; 1154 rftid->dap = s_id;
1155 1155
1156 /* By default, FCP FC4 Type is registered */ 1156 /* By default, FCP FC4 Type is registered */
1157 index = FC_TYPE_FCP >> 5; 1157 index = FC_TYPE_FCP >> 5;
1158 type_value = 1 << (FC_TYPE_FCP % 32); 1158 type_value = 1 << (FC_TYPE_FCP % 32);
1159 rftid->fc4_type[index] = bfa_os_htonl(type_value); 1159 rftid->fc4_type[index] = cpu_to_be32(type_value);
1160 1160
1161 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s); 1161 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
1162} 1162}
@@ -1172,10 +1172,10 @@ fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1172 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); 1172 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1173 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID); 1173 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1174 1174
1175 bfa_os_memset(rftid, 0, sizeof(struct fcgs_rftid_req_s)); 1175 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
1176 1176
1177 rftid->dap = s_id; 1177 rftid->dap = s_id;
1178 bfa_os_memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap, 1178 memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap,
1179 (bitmap_size < 32 ? bitmap_size : 32)); 1179 (bitmap_size < 32 ? bitmap_size : 32));
1180 1180
1181 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s); 1181 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
@@ -1192,7 +1192,7 @@ fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1192 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); 1192 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1193 fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID); 1193 fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID);
1194 1194
1195 bfa_os_memset(rffid, 0, sizeof(struct fcgs_rffid_req_s)); 1195 memset(rffid, 0, sizeof(struct fcgs_rffid_req_s));
1196 1196
1197 rffid->dap = s_id; 1197 rffid->dap = s_id;
1198 rffid->fc4ftr_bits = fc4_ftrs; 1198 rffid->fc4ftr_bits = fc4_ftrs;
@@ -1214,7 +1214,7 @@ fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1214 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); 1214 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1215 fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID); 1215 fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID);
1216 1216
1217 bfa_os_memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s)); 1217 memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
1218 1218
1219 rspnid->dap = s_id; 1219 rspnid->dap = s_id;
1220 rspnid->spn_len = (u8) strlen((char *)name); 1220 rspnid->spn_len = (u8) strlen((char *)name);
@@ -1235,7 +1235,7 @@ fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type)
1235 1235
1236 fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT); 1236 fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT);
1237 1237
1238 bfa_os_memset(gidft, 0, sizeof(struct fcgs_gidft_req_s)); 1238 memset(gidft, 0, sizeof(struct fcgs_gidft_req_s));
1239 gidft->fc4_type = fc4_type; 1239 gidft->fc4_type = fc4_type;
1240 gidft->domain_id = 0; 1240 gidft->domain_id = 0;
1241 gidft->area_id = 0; 1241 gidft->area_id = 0;
@@ -1254,7 +1254,7 @@ fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1254 fc_gs_fchdr_build(fchs, d_id, s_id, 0); 1254 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1255 fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID); 1255 fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID);
1256 1256
1257 bfa_os_memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s)); 1257 memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s));
1258 rpnid->port_id = port_id; 1258 rpnid->port_id = port_id;
1259 rpnid->port_name = port_name; 1259 rpnid->port_name = port_name;
1260 1260
@@ -1272,7 +1272,7 @@ fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1272 fc_gs_fchdr_build(fchs, d_id, s_id, 0); 1272 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1273 fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID); 1273 fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID);
1274 1274
1275 bfa_os_memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s)); 1275 memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s));
1276 rnnid->port_id = port_id; 1276 rnnid->port_id = port_id;
1277 rnnid->node_name = node_name; 1277 rnnid->node_name = node_name;
1278 1278
@@ -1291,7 +1291,7 @@ fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1291 fc_gs_fchdr_build(fchs, d_id, s_id, 0); 1291 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1292 fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID); 1292 fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID);
1293 1293
1294 bfa_os_memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s)); 1294 memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s));
1295 rcsid->port_id = port_id; 1295 rcsid->port_id = port_id;
1296 rcsid->cos = cos; 1296 rcsid->cos = cos;
1297 1297
@@ -1309,7 +1309,7 @@ fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1309 fc_gs_fchdr_build(fchs, d_id, s_id, 0); 1309 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1310 fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID); 1310 fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID);
1311 1311
1312 bfa_os_memset(rptid, 0, sizeof(struct fcgs_rptid_req_s)); 1312 memset(rptid, 0, sizeof(struct fcgs_rptid_req_s));
1313 rptid->port_id = port_id; 1313 rptid->port_id = port_id;
1314 rptid->port_type = port_type; 1314 rptid->port_type = port_type;
1315 1315
@@ -1326,7 +1326,7 @@ fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id)
1326 fc_gs_fchdr_build(fchs, d_id, s_id, 0); 1326 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1327 fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT); 1327 fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT);
1328 1328
1329 bfa_os_memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s)); 1329 memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s));
1330 ganxt->port_id = port_id; 1330 ganxt->port_id = port_id;
1331 1331
1332 return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s); 1332 return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s);
@@ -1365,7 +1365,7 @@ fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask)
1365 1365
1366 index = fc4_type >> 5; 1366 index = fc4_type >> 5;
1367 type_value = 1 << (fc4_type % 32); 1367 type_value = 1 << (fc4_type % 32);
1368 ptr[index] = bfa_os_htonl(type_value); 1368 ptr[index] = cpu_to_be32(type_value);
1369 1369
1370} 1370}
1371 1371
@@ -1383,7 +1383,7 @@ fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1383 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD, 1383 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD,
1384 CT_GSSUBTYPE_CFGSERVER); 1384 CT_GSSUBTYPE_CFGSERVER);
1385 1385
1386 bfa_os_memset(gmal, 0, sizeof(fcgs_gmal_req_t)); 1386 memset(gmal, 0, sizeof(fcgs_gmal_req_t));
1387 gmal->wwn = wwn; 1387 gmal->wwn = wwn;
1388 1388
1389 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t); 1389 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t);
@@ -1403,7 +1403,7 @@ fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1403 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD, 1403 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD,
1404 CT_GSSUBTYPE_CFGSERVER); 1404 CT_GSSUBTYPE_CFGSERVER);
1405 1405
1406 bfa_os_memset(gfn, 0, sizeof(fcgs_gfn_req_t)); 1406 memset(gfn, 0, sizeof(fcgs_gfn_req_t));
1407 gfn->wwn = wwn; 1407 gfn->wwn = wwn;
1408 1408
1409 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t); 1409 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t);
diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
index aabbf3d3b394..cd7ef4818940 100644
--- a/drivers/scsi/bfa/bfa_fcpim.c
+++ b/drivers/scsi/bfa/bfa_fcpim.c
@@ -26,7 +26,7 @@ BFA_MODULE(fcpim);
26 (__l->__stats += __r->__stats) 26 (__l->__stats += __r->__stats)
27 27
28 28
29/** 29/*
30 * BFA ITNIM Related definitions 30 * BFA ITNIM Related definitions
31 */ 31 */
32static void bfa_itnim_update_del_itn_stats(struct bfa_itnim_s *itnim); 32static void bfa_itnim_update_del_itn_stats(struct bfa_itnim_s *itnim);
@@ -72,7 +72,7 @@ static void bfa_itnim_update_del_itn_stats(struct bfa_itnim_s *itnim);
72 } \ 72 } \
73} while (0) 73} while (0)
74 74
75/** 75/*
76 * bfa_itnim_sm BFA itnim state machine 76 * bfa_itnim_sm BFA itnim state machine
77 */ 77 */
78 78
@@ -89,7 +89,7 @@ enum bfa_itnim_event {
89 BFA_ITNIM_SM_QRESUME = 9, /* queue space available */ 89 BFA_ITNIM_SM_QRESUME = 9, /* queue space available */
90}; 90};
91 91
92/** 92/*
93 * BFA IOIM related definitions 93 * BFA IOIM related definitions
94 */ 94 */
95#define bfa_ioim_move_to_comp_q(__ioim) do { \ 95#define bfa_ioim_move_to_comp_q(__ioim) do { \
@@ -107,11 +107,11 @@ enum bfa_itnim_event {
107 if ((__fcpim)->profile_start) \ 107 if ((__fcpim)->profile_start) \
108 (__fcpim)->profile_start(__ioim); \ 108 (__fcpim)->profile_start(__ioim); \
109} while (0) 109} while (0)
110/** 110/*
111 * hal_ioim_sm 111 * hal_ioim_sm
112 */ 112 */
113 113
114/** 114/*
115 * IO state machine events 115 * IO state machine events
116 */ 116 */
117enum bfa_ioim_event { 117enum bfa_ioim_event {
@@ -136,11 +136,11 @@ enum bfa_ioim_event {
136}; 136};
137 137
138 138
139/** 139/*
140 * BFA TSKIM related definitions 140 * BFA TSKIM related definitions
141 */ 141 */
142 142
143/** 143/*
144 * task management completion handling 144 * task management completion handling
145 */ 145 */
146#define bfa_tskim_qcomp(__tskim, __cbfn) do { \ 146#define bfa_tskim_qcomp(__tskim, __cbfn) do { \
@@ -165,7 +165,7 @@ enum bfa_tskim_event {
165 BFA_TSKIM_SM_CLEANUP_DONE = 9, /* TM abort completion */ 165 BFA_TSKIM_SM_CLEANUP_DONE = 9, /* TM abort completion */
166}; 166};
167 167
168/** 168/*
169 * forward declaration for BFA ITNIM functions 169 * forward declaration for BFA ITNIM functions
170 */ 170 */
171static void bfa_itnim_iocdisable_cleanup(struct bfa_itnim_s *itnim); 171static void bfa_itnim_iocdisable_cleanup(struct bfa_itnim_s *itnim);
@@ -183,7 +183,7 @@ static void bfa_itnim_iotov_start(struct bfa_itnim_s *itnim);
183static void bfa_itnim_iotov_stop(struct bfa_itnim_s *itnim); 183static void bfa_itnim_iotov_stop(struct bfa_itnim_s *itnim);
184static void bfa_itnim_iotov_delete(struct bfa_itnim_s *itnim); 184static void bfa_itnim_iotov_delete(struct bfa_itnim_s *itnim);
185 185
186/** 186/*
187 * forward declaration of ITNIM state machine 187 * forward declaration of ITNIM state machine
188 */ 188 */
189static void bfa_itnim_sm_uninit(struct bfa_itnim_s *itnim, 189static void bfa_itnim_sm_uninit(struct bfa_itnim_s *itnim,
@@ -217,7 +217,7 @@ static void bfa_itnim_sm_fwdelete_qfull(struct bfa_itnim_s *itnim,
217static void bfa_itnim_sm_deleting_qfull(struct bfa_itnim_s *itnim, 217static void bfa_itnim_sm_deleting_qfull(struct bfa_itnim_s *itnim,
218 enum bfa_itnim_event event); 218 enum bfa_itnim_event event);
219 219
220/** 220/*
221 * forward declaration for BFA IOIM functions 221 * forward declaration for BFA IOIM functions
222 */ 222 */
223static bfa_boolean_t bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim); 223static bfa_boolean_t bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim);
@@ -233,7 +233,7 @@ static void __bfa_cb_ioim_pathtov(void *cbarg, bfa_boolean_t complete);
233static bfa_boolean_t bfa_ioim_is_abortable(struct bfa_ioim_s *ioim); 233static bfa_boolean_t bfa_ioim_is_abortable(struct bfa_ioim_s *ioim);
234 234
235 235
236/** 236/*
237 * forward declaration of BFA IO state machine 237 * forward declaration of BFA IO state machine
238 */ 238 */
239static void bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim, 239static void bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim,
@@ -261,7 +261,7 @@ static void bfa_ioim_sm_resfree(struct bfa_ioim_s *ioim,
261static void bfa_ioim_sm_cmnd_retry(struct bfa_ioim_s *ioim, 261static void bfa_ioim_sm_cmnd_retry(struct bfa_ioim_s *ioim,
262 enum bfa_ioim_event event); 262 enum bfa_ioim_event event);
263 263
264/** 264/*
265 * forward declaration for BFA TSKIM functions 265 * forward declaration for BFA TSKIM functions
266 */ 266 */
267static void __bfa_cb_tskim_done(void *cbarg, bfa_boolean_t complete); 267static void __bfa_cb_tskim_done(void *cbarg, bfa_boolean_t complete);
@@ -276,7 +276,7 @@ static bfa_boolean_t bfa_tskim_send_abort(struct bfa_tskim_s *tskim);
276static void bfa_tskim_iocdisable_ios(struct bfa_tskim_s *tskim); 276static void bfa_tskim_iocdisable_ios(struct bfa_tskim_s *tskim);
277 277
278 278
279/** 279/*
280 * forward declaration of BFA TSKIM state machine 280 * forward declaration of BFA TSKIM state machine
281 */ 281 */
282static void bfa_tskim_sm_uninit(struct bfa_tskim_s *tskim, 282static void bfa_tskim_sm_uninit(struct bfa_tskim_s *tskim,
@@ -294,11 +294,11 @@ static void bfa_tskim_sm_cleanup_qfull(struct bfa_tskim_s *tskim,
294static void bfa_tskim_sm_hcb(struct bfa_tskim_s *tskim, 294static void bfa_tskim_sm_hcb(struct bfa_tskim_s *tskim,
295 enum bfa_tskim_event event); 295 enum bfa_tskim_event event);
296 296
297/** 297/*
298 * hal_fcpim_mod BFA FCP Initiator Mode module 298 * hal_fcpim_mod BFA FCP Initiator Mode module
299 */ 299 */
300 300
301/** 301/*
302 * Compute and return memory needed by FCP(im) module. 302 * Compute and return memory needed by FCP(im) module.
303 */ 303 */
304static void 304static void
@@ -307,7 +307,7 @@ bfa_fcpim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
307{ 307{
308 bfa_itnim_meminfo(cfg, km_len, dm_len); 308 bfa_itnim_meminfo(cfg, km_len, dm_len);
309 309
310 /** 310 /*
311 * IO memory 311 * IO memory
312 */ 312 */
313 if (cfg->fwcfg.num_ioim_reqs < BFA_IOIM_MIN) 313 if (cfg->fwcfg.num_ioim_reqs < BFA_IOIM_MIN)
@@ -320,7 +320,7 @@ bfa_fcpim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
320 320
321 *dm_len += cfg->fwcfg.num_ioim_reqs * BFI_IOIM_SNSLEN; 321 *dm_len += cfg->fwcfg.num_ioim_reqs * BFI_IOIM_SNSLEN;
322 322
323 /** 323 /*
324 * task management command memory 324 * task management command memory
325 */ 325 */
326 if (cfg->fwcfg.num_tskim_reqs < BFA_TSKIM_MIN) 326 if (cfg->fwcfg.num_tskim_reqs < BFA_TSKIM_MIN)
@@ -463,7 +463,7 @@ bfa_fcpim_port_iostats(struct bfa_s *bfa, struct bfa_itnim_iostats_s *stats,
463 struct bfa_itnim_s *itnim; 463 struct bfa_itnim_s *itnim;
464 464
465 /* accumulate IO stats from itnim */ 465 /* accumulate IO stats from itnim */
466 bfa_os_memset(stats, 0, sizeof(struct bfa_itnim_iostats_s)); 466 memset(stats, 0, sizeof(struct bfa_itnim_iostats_s));
467 list_for_each_safe(qe, qen, &fcpim->itnim_q) { 467 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
468 itnim = (struct bfa_itnim_s *) qe; 468 itnim = (struct bfa_itnim_s *) qe;
469 if (itnim->rport->rport_info.lp_tag != lp_tag) 469 if (itnim->rport->rport_info.lp_tag != lp_tag)
@@ -480,7 +480,7 @@ bfa_fcpim_get_modstats(struct bfa_s *bfa, struct bfa_itnim_iostats_s *modstats)
480 struct bfa_itnim_s *itnim; 480 struct bfa_itnim_s *itnim;
481 481
482 /* accumulate IO stats from itnim */ 482 /* accumulate IO stats from itnim */
483 bfa_os_memset(modstats, 0, sizeof(struct bfa_itnim_iostats_s)); 483 memset(modstats, 0, sizeof(struct bfa_itnim_iostats_s));
484 list_for_each_safe(qe, qen, &fcpim->itnim_q) { 484 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
485 itnim = (struct bfa_itnim_s *) qe; 485 itnim = (struct bfa_itnim_s *) qe;
486 bfa_fcpim_add_stats(modstats, &(itnim->stats)); 486 bfa_fcpim_add_stats(modstats, &(itnim->stats));
@@ -560,7 +560,7 @@ bfa_fcpim_clr_modstats(struct bfa_s *bfa)
560 itnim = (struct bfa_itnim_s *) qe; 560 itnim = (struct bfa_itnim_s *) qe;
561 bfa_itnim_clear_stats(itnim); 561 bfa_itnim_clear_stats(itnim);
562 } 562 }
563 bfa_os_memset(&fcpim->del_itn_stats, 0, 563 memset(&fcpim->del_itn_stats, 0,
564 sizeof(struct bfa_fcpim_del_itn_stats_s)); 564 sizeof(struct bfa_fcpim_del_itn_stats_s));
565 565
566 return BFA_STATUS_OK; 566 return BFA_STATUS_OK;
@@ -604,11 +604,11 @@ bfa_fcpim_set_ioredirect(struct bfa_s *bfa, bfa_boolean_t state)
604 604
605 605
606 606
607/** 607/*
608 * BFA ITNIM module state machine functions 608 * BFA ITNIM module state machine functions
609 */ 609 */
610 610
611/** 611/*
612 * Beginning/unallocated state - no events expected. 612 * Beginning/unallocated state - no events expected.
613 */ 613 */
614static void 614static void
@@ -629,7 +629,7 @@ bfa_itnim_sm_uninit(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
629 } 629 }
630} 630}
631 631
632/** 632/*
633 * Beginning state, only online event expected. 633 * Beginning state, only online event expected.
634 */ 634 */
635static void 635static void
@@ -660,7 +660,7 @@ bfa_itnim_sm_created(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
660 } 660 }
661} 661}
662 662
663/** 663/*
664 * Waiting for itnim create response from firmware. 664 * Waiting for itnim create response from firmware.
665 */ 665 */
666static void 666static void
@@ -732,7 +732,7 @@ bfa_itnim_sm_fwcreate_qfull(struct bfa_itnim_s *itnim,
732 } 732 }
733} 733}
734 734
735/** 735/*
736 * Waiting for itnim create response from firmware, a delete is pending. 736 * Waiting for itnim create response from firmware, a delete is pending.
737 */ 737 */
738static void 738static void
@@ -760,7 +760,7 @@ bfa_itnim_sm_delete_pending(struct bfa_itnim_s *itnim,
760 } 760 }
761} 761}
762 762
763/** 763/*
764 * Online state - normal parking state. 764 * Online state - normal parking state.
765 */ 765 */
766static void 766static void
@@ -802,7 +802,7 @@ bfa_itnim_sm_online(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
802 } 802 }
803} 803}
804 804
805/** 805/*
806 * Second level error recovery need. 806 * Second level error recovery need.
807 */ 807 */
808static void 808static void
@@ -833,7 +833,7 @@ bfa_itnim_sm_sler(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
833 } 833 }
834} 834}
835 835
836/** 836/*
837 * Going offline. Waiting for active IO cleanup. 837 * Going offline. Waiting for active IO cleanup.
838 */ 838 */
839static void 839static void
@@ -870,7 +870,7 @@ bfa_itnim_sm_cleanup_offline(struct bfa_itnim_s *itnim,
870 } 870 }
871} 871}
872 872
873/** 873/*
874 * Deleting itnim. Waiting for active IO cleanup. 874 * Deleting itnim. Waiting for active IO cleanup.
875 */ 875 */
876static void 876static void
@@ -898,7 +898,7 @@ bfa_itnim_sm_cleanup_delete(struct bfa_itnim_s *itnim,
898 } 898 }
899} 899}
900 900
901/** 901/*
902 * Rport offline. Fimrware itnim is being deleted - awaiting f/w response. 902 * Rport offline. Fimrware itnim is being deleted - awaiting f/w response.
903 */ 903 */
904static void 904static void
@@ -955,7 +955,7 @@ bfa_itnim_sm_fwdelete_qfull(struct bfa_itnim_s *itnim,
955 } 955 }
956} 956}
957 957
958/** 958/*
959 * Offline state. 959 * Offline state.
960 */ 960 */
961static void 961static void
@@ -987,7 +987,7 @@ bfa_itnim_sm_offline(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
987 } 987 }
988} 988}
989 989
990/** 990/*
991 * IOC h/w failed state. 991 * IOC h/w failed state.
992 */ 992 */
993static void 993static void
@@ -1023,7 +1023,7 @@ bfa_itnim_sm_iocdisable(struct bfa_itnim_s *itnim,
1023 } 1023 }
1024} 1024}
1025 1025
1026/** 1026/*
1027 * Itnim is deleted, waiting for firmware response to delete. 1027 * Itnim is deleted, waiting for firmware response to delete.
1028 */ 1028 */
1029static void 1029static void
@@ -1068,7 +1068,7 @@ bfa_itnim_sm_deleting_qfull(struct bfa_itnim_s *itnim,
1068 } 1068 }
1069} 1069}
1070 1070
1071/** 1071/*
1072 * Initiate cleanup of all IOs on an IOC failure. 1072 * Initiate cleanup of all IOs on an IOC failure.
1073 */ 1073 */
1074static void 1074static void
@@ -1088,7 +1088,7 @@ bfa_itnim_iocdisable_cleanup(struct bfa_itnim_s *itnim)
1088 bfa_ioim_iocdisable(ioim); 1088 bfa_ioim_iocdisable(ioim);
1089 } 1089 }
1090 1090
1091 /** 1091 /*
1092 * For IO request in pending queue, we pretend an early timeout. 1092 * For IO request in pending queue, we pretend an early timeout.
1093 */ 1093 */
1094 list_for_each_safe(qe, qen, &itnim->pending_q) { 1094 list_for_each_safe(qe, qen, &itnim->pending_q) {
@@ -1102,7 +1102,7 @@ bfa_itnim_iocdisable_cleanup(struct bfa_itnim_s *itnim)
1102 } 1102 }
1103} 1103}
1104 1104
1105/** 1105/*
1106 * IO cleanup completion 1106 * IO cleanup completion
1107 */ 1107 */
1108static void 1108static void
@@ -1114,7 +1114,7 @@ bfa_itnim_cleanp_comp(void *itnim_cbarg)
1114 bfa_sm_send_event(itnim, BFA_ITNIM_SM_CLEANUP); 1114 bfa_sm_send_event(itnim, BFA_ITNIM_SM_CLEANUP);
1115} 1115}
1116 1116
1117/** 1117/*
1118 * Initiate cleanup of all IOs. 1118 * Initiate cleanup of all IOs.
1119 */ 1119 */
1120static void 1120static void
@@ -1129,7 +1129,7 @@ bfa_itnim_cleanup(struct bfa_itnim_s *itnim)
1129 list_for_each_safe(qe, qen, &itnim->io_q) { 1129 list_for_each_safe(qe, qen, &itnim->io_q) {
1130 ioim = (struct bfa_ioim_s *) qe; 1130 ioim = (struct bfa_ioim_s *) qe;
1131 1131
1132 /** 1132 /*
1133 * Move IO to a cleanup queue from active queue so that a later 1133 * Move IO to a cleanup queue from active queue so that a later
1134 * TM will not pickup this IO. 1134 * TM will not pickup this IO.
1135 */ 1135 */
@@ -1176,7 +1176,7 @@ __bfa_cb_itnim_sler(void *cbarg, bfa_boolean_t complete)
1176 bfa_cb_itnim_sler(itnim->ditn); 1176 bfa_cb_itnim_sler(itnim->ditn);
1177} 1177}
1178 1178
1179/** 1179/*
1180 * Call to resume any I/O requests waiting for room in request queue. 1180 * Call to resume any I/O requests waiting for room in request queue.
1181 */ 1181 */
1182static void 1182static void
@@ -1190,7 +1190,7 @@ bfa_itnim_qresume(void *cbarg)
1190 1190
1191 1191
1192 1192
1193/** 1193/*
1194 * bfa_itnim_public 1194 * bfa_itnim_public
1195 */ 1195 */
1196 1196
@@ -1210,7 +1210,7 @@ void
1210bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len, 1210bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
1211 u32 *dm_len) 1211 u32 *dm_len)
1212{ 1212{
1213 /** 1213 /*
1214 * ITN memory 1214 * ITN memory
1215 */ 1215 */
1216 *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_itnim_s); 1216 *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_itnim_s);
@@ -1229,7 +1229,7 @@ bfa_itnim_attach(struct bfa_fcpim_mod_s *fcpim, struct bfa_meminfo_s *minfo)
1229 fcpim->itnim_arr = itnim; 1229 fcpim->itnim_arr = itnim;
1230 1230
1231 for (i = 0; i < fcpim->num_itnims; i++, itnim++) { 1231 for (i = 0; i < fcpim->num_itnims; i++, itnim++) {
1232 bfa_os_memset(itnim, 0, sizeof(struct bfa_itnim_s)); 1232 memset(itnim, 0, sizeof(struct bfa_itnim_s));
1233 itnim->bfa = bfa; 1233 itnim->bfa = bfa;
1234 itnim->fcpim = fcpim; 1234 itnim->fcpim = fcpim;
1235 itnim->reqq = BFA_REQQ_QOS_LO; 1235 itnim->reqq = BFA_REQQ_QOS_LO;
@@ -1264,7 +1264,7 @@ bfa_itnim_send_fwcreate(struct bfa_itnim_s *itnim)
1264 1264
1265 itnim->msg_no++; 1265 itnim->msg_no++;
1266 1266
1267 /** 1267 /*
1268 * check for room in queue to send request now 1268 * check for room in queue to send request now
1269 */ 1269 */
1270 m = bfa_reqq_next(itnim->bfa, itnim->reqq); 1270 m = bfa_reqq_next(itnim->bfa, itnim->reqq);
@@ -1281,7 +1281,7 @@ bfa_itnim_send_fwcreate(struct bfa_itnim_s *itnim)
1281 m->msg_no = itnim->msg_no; 1281 m->msg_no = itnim->msg_no;
1282 bfa_stats(itnim, fw_create); 1282 bfa_stats(itnim, fw_create);
1283 1283
1284 /** 1284 /*
1285 * queue I/O message to firmware 1285 * queue I/O message to firmware
1286 */ 1286 */
1287 bfa_reqq_produce(itnim->bfa, itnim->reqq); 1287 bfa_reqq_produce(itnim->bfa, itnim->reqq);
@@ -1293,7 +1293,7 @@ bfa_itnim_send_fwdelete(struct bfa_itnim_s *itnim)
1293{ 1293{
1294 struct bfi_itnim_delete_req_s *m; 1294 struct bfi_itnim_delete_req_s *m;
1295 1295
1296 /** 1296 /*
1297 * check for room in queue to send request now 1297 * check for room in queue to send request now
1298 */ 1298 */
1299 m = bfa_reqq_next(itnim->bfa, itnim->reqq); 1299 m = bfa_reqq_next(itnim->bfa, itnim->reqq);
@@ -1307,14 +1307,14 @@ bfa_itnim_send_fwdelete(struct bfa_itnim_s *itnim)
1307 m->fw_handle = itnim->rport->fw_handle; 1307 m->fw_handle = itnim->rport->fw_handle;
1308 bfa_stats(itnim, fw_delete); 1308 bfa_stats(itnim, fw_delete);
1309 1309
1310 /** 1310 /*
1311 * queue I/O message to firmware 1311 * queue I/O message to firmware
1312 */ 1312 */
1313 bfa_reqq_produce(itnim->bfa, itnim->reqq); 1313 bfa_reqq_produce(itnim->bfa, itnim->reqq);
1314 return BFA_TRUE; 1314 return BFA_TRUE;
1315} 1315}
1316 1316
1317/** 1317/*
1318 * Cleanup all pending failed inflight requests. 1318 * Cleanup all pending failed inflight requests.
1319 */ 1319 */
1320static void 1320static void
@@ -1329,7 +1329,7 @@ bfa_itnim_delayed_comp(struct bfa_itnim_s *itnim, bfa_boolean_t iotov)
1329 } 1329 }
1330} 1330}
1331 1331
1332/** 1332/*
1333 * Start all pending IO requests. 1333 * Start all pending IO requests.
1334 */ 1334 */
1335static void 1335static void
@@ -1339,12 +1339,12 @@ bfa_itnim_iotov_online(struct bfa_itnim_s *itnim)
1339 1339
1340 bfa_itnim_iotov_stop(itnim); 1340 bfa_itnim_iotov_stop(itnim);
1341 1341
1342 /** 1342 /*
1343 * Abort all inflight IO requests in the queue 1343 * Abort all inflight IO requests in the queue
1344 */ 1344 */
1345 bfa_itnim_delayed_comp(itnim, BFA_FALSE); 1345 bfa_itnim_delayed_comp(itnim, BFA_FALSE);
1346 1346
1347 /** 1347 /*
1348 * Start all pending IO requests. 1348 * Start all pending IO requests.
1349 */ 1349 */
1350 while (!list_empty(&itnim->pending_q)) { 1350 while (!list_empty(&itnim->pending_q)) {
@@ -1354,7 +1354,7 @@ bfa_itnim_iotov_online(struct bfa_itnim_s *itnim)
1354 } 1354 }
1355} 1355}
1356 1356
1357/** 1357/*
1358 * Fail all pending IO requests 1358 * Fail all pending IO requests
1359 */ 1359 */
1360static void 1360static void
@@ -1362,12 +1362,12 @@ bfa_itnim_iotov_cleanup(struct bfa_itnim_s *itnim)
1362{ 1362{
1363 struct bfa_ioim_s *ioim; 1363 struct bfa_ioim_s *ioim;
1364 1364
1365 /** 1365 /*
1366 * Fail all inflight IO requests in the queue 1366 * Fail all inflight IO requests in the queue
1367 */ 1367 */
1368 bfa_itnim_delayed_comp(itnim, BFA_TRUE); 1368 bfa_itnim_delayed_comp(itnim, BFA_TRUE);
1369 1369
1370 /** 1370 /*
1371 * Fail any pending IO requests. 1371 * Fail any pending IO requests.
1372 */ 1372 */
1373 while (!list_empty(&itnim->pending_q)) { 1373 while (!list_empty(&itnim->pending_q)) {
@@ -1377,7 +1377,7 @@ bfa_itnim_iotov_cleanup(struct bfa_itnim_s *itnim)
1377 } 1377 }
1378} 1378}
1379 1379
1380/** 1380/*
1381 * IO TOV timer callback. Fail any pending IO requests. 1381 * IO TOV timer callback. Fail any pending IO requests.
1382 */ 1382 */
1383static void 1383static void
@@ -1392,7 +1392,7 @@ bfa_itnim_iotov(void *itnim_arg)
1392 bfa_cb_itnim_tov(itnim->ditn); 1392 bfa_cb_itnim_tov(itnim->ditn);
1393} 1393}
1394 1394
1395/** 1395/*
1396 * Start IO TOV timer for failing back pending IO requests in offline state. 1396 * Start IO TOV timer for failing back pending IO requests in offline state.
1397 */ 1397 */
1398static void 1398static void
@@ -1407,7 +1407,7 @@ bfa_itnim_iotov_start(struct bfa_itnim_s *itnim)
1407 } 1407 }
1408} 1408}
1409 1409
1410/** 1410/*
1411 * Stop IO TOV timer. 1411 * Stop IO TOV timer.
1412 */ 1412 */
1413static void 1413static void
@@ -1419,7 +1419,7 @@ bfa_itnim_iotov_stop(struct bfa_itnim_s *itnim)
1419 } 1419 }
1420} 1420}
1421 1421
1422/** 1422/*
1423 * Stop IO TOV timer. 1423 * Stop IO TOV timer.
1424 */ 1424 */
1425static void 1425static void
@@ -1459,11 +1459,11 @@ bfa_itnim_update_del_itn_stats(struct bfa_itnim_s *itnim)
1459 1459
1460 1460
1461 1461
1462/** 1462/*
1463 * bfa_itnim_public 1463 * bfa_itnim_public
1464 */ 1464 */
1465 1465
1466/** 1466/*
1467 * Itnim interrupt processing. 1467 * Itnim interrupt processing.
1468 */ 1468 */
1469void 1469void
@@ -1509,7 +1509,7 @@ bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
1509 1509
1510 1510
1511 1511
1512/** 1512/*
1513 * bfa_itnim_api 1513 * bfa_itnim_api
1514 */ 1514 */
1515 1515
@@ -1552,7 +1552,7 @@ bfa_itnim_offline(struct bfa_itnim_s *itnim)
1552 bfa_sm_send_event(itnim, BFA_ITNIM_SM_OFFLINE); 1552 bfa_sm_send_event(itnim, BFA_ITNIM_SM_OFFLINE);
1553} 1553}
1554 1554
1555/** 1555/*
1556 * Return true if itnim is considered offline for holding off IO request. 1556 * Return true if itnim is considered offline for holding off IO request.
1557 * IO is not held if itnim is being deleted. 1557 * IO is not held if itnim is being deleted.
1558 */ 1558 */
@@ -1597,17 +1597,17 @@ void
1597bfa_itnim_clear_stats(struct bfa_itnim_s *itnim) 1597bfa_itnim_clear_stats(struct bfa_itnim_s *itnim)
1598{ 1598{
1599 int j; 1599 int j;
1600 bfa_os_memset(&itnim->stats, 0, sizeof(itnim->stats)); 1600 memset(&itnim->stats, 0, sizeof(itnim->stats));
1601 bfa_os_memset(&itnim->ioprofile, 0, sizeof(itnim->ioprofile)); 1601 memset(&itnim->ioprofile, 0, sizeof(itnim->ioprofile));
1602 for (j = 0; j < BFA_IOBUCKET_MAX; j++) 1602 for (j = 0; j < BFA_IOBUCKET_MAX; j++)
1603 itnim->ioprofile.io_latency.min[j] = ~0; 1603 itnim->ioprofile.io_latency.min[j] = ~0;
1604} 1604}
1605 1605
1606/** 1606/*
1607 * BFA IO module state machine functions 1607 * BFA IO module state machine functions
1608 */ 1608 */
1609 1609
1610/** 1610/*
1611 * IO is not started (unallocated). 1611 * IO is not started (unallocated).
1612 */ 1612 */
1613static void 1613static void
@@ -1657,7 +1657,7 @@ bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1657 break; 1657 break;
1658 1658
1659 case BFA_IOIM_SM_ABORT: 1659 case BFA_IOIM_SM_ABORT:
1660 /** 1660 /*
1661 * IO in pending queue can get abort requests. Complete abort 1661 * IO in pending queue can get abort requests. Complete abort
1662 * requests immediately. 1662 * requests immediately.
1663 */ 1663 */
@@ -1672,7 +1672,7 @@ bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1672 } 1672 }
1673} 1673}
1674 1674
1675/** 1675/*
1676 * IO is waiting for SG pages. 1676 * IO is waiting for SG pages.
1677 */ 1677 */
1678static void 1678static void
@@ -1719,7 +1719,7 @@ bfa_ioim_sm_sgalloc(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1719 } 1719 }
1720} 1720}
1721 1721
1722/** 1722/*
1723 * IO is active. 1723 * IO is active.
1724 */ 1724 */
1725static void 1725static void
@@ -1803,7 +1803,7 @@ bfa_ioim_sm_active(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1803 } 1803 }
1804} 1804}
1805 1805
1806/** 1806/*
1807* IO is retried with new tag. 1807* IO is retried with new tag.
1808*/ 1808*/
1809static void 1809static void
@@ -1844,7 +1844,7 @@ bfa_ioim_sm_cmnd_retry(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1844 break; 1844 break;
1845 1845
1846 case BFA_IOIM_SM_ABORT: 1846 case BFA_IOIM_SM_ABORT:
1847 /** in this state IO abort is done. 1847 /* in this state IO abort is done.
1848 * Waiting for IO tag resource free. 1848 * Waiting for IO tag resource free.
1849 */ 1849 */
1850 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free); 1850 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
@@ -1857,7 +1857,7 @@ bfa_ioim_sm_cmnd_retry(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1857 } 1857 }
1858} 1858}
1859 1859
1860/** 1860/*
1861 * IO is being aborted, waiting for completion from firmware. 1861 * IO is being aborted, waiting for completion from firmware.
1862 */ 1862 */
1863static void 1863static void
@@ -1919,7 +1919,7 @@ bfa_ioim_sm_abort(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1919 } 1919 }
1920} 1920}
1921 1921
1922/** 1922/*
1923 * IO is being cleaned up (implicit abort), waiting for completion from 1923 * IO is being cleaned up (implicit abort), waiting for completion from
1924 * firmware. 1924 * firmware.
1925 */ 1925 */
@@ -1937,7 +1937,7 @@ bfa_ioim_sm_cleanup(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1937 break; 1937 break;
1938 1938
1939 case BFA_IOIM_SM_ABORT: 1939 case BFA_IOIM_SM_ABORT:
1940 /** 1940 /*
1941 * IO is already being aborted implicitly 1941 * IO is already being aborted implicitly
1942 */ 1942 */
1943 ioim->io_cbfn = __bfa_cb_ioim_abort; 1943 ioim->io_cbfn = __bfa_cb_ioim_abort;
@@ -1969,7 +1969,7 @@ bfa_ioim_sm_cleanup(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1969 break; 1969 break;
1970 1970
1971 case BFA_IOIM_SM_CLEANUP: 1971 case BFA_IOIM_SM_CLEANUP:
1972 /** 1972 /*
1973 * IO can be in cleanup state already due to TM command. 1973 * IO can be in cleanup state already due to TM command.
1974 * 2nd cleanup request comes from ITN offline event. 1974 * 2nd cleanup request comes from ITN offline event.
1975 */ 1975 */
@@ -1980,7 +1980,7 @@ bfa_ioim_sm_cleanup(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1980 } 1980 }
1981} 1981}
1982 1982
1983/** 1983/*
1984 * IO is waiting for room in request CQ 1984 * IO is waiting for room in request CQ
1985 */ 1985 */
1986static void 1986static void
@@ -2024,7 +2024,7 @@ bfa_ioim_sm_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2024 } 2024 }
2025} 2025}
2026 2026
2027/** 2027/*
2028 * Active IO is being aborted, waiting for room in request CQ. 2028 * Active IO is being aborted, waiting for room in request CQ.
2029 */ 2029 */
2030static void 2030static void
@@ -2075,7 +2075,7 @@ bfa_ioim_sm_abort_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2075 } 2075 }
2076} 2076}
2077 2077
2078/** 2078/*
2079 * Active IO is being cleaned up, waiting for room in request CQ. 2079 * Active IO is being cleaned up, waiting for room in request CQ.
2080 */ 2080 */
2081static void 2081static void
@@ -2091,7 +2091,7 @@ bfa_ioim_sm_cleanup_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2091 break; 2091 break;
2092 2092
2093 case BFA_IOIM_SM_ABORT: 2093 case BFA_IOIM_SM_ABORT:
2094 /** 2094 /*
2095 * IO is already being cleaned up implicitly 2095 * IO is already being cleaned up implicitly
2096 */ 2096 */
2097 ioim->io_cbfn = __bfa_cb_ioim_abort; 2097 ioim->io_cbfn = __bfa_cb_ioim_abort;
@@ -2125,7 +2125,7 @@ bfa_ioim_sm_cleanup_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2125 } 2125 }
2126} 2126}
2127 2127
2128/** 2128/*
2129 * IO bfa callback is pending. 2129 * IO bfa callback is pending.
2130 */ 2130 */
2131static void 2131static void
@@ -2152,7 +2152,7 @@ bfa_ioim_sm_hcb(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2152 } 2152 }
2153} 2153}
2154 2154
2155/** 2155/*
2156 * IO bfa callback is pending. IO resource cannot be freed. 2156 * IO bfa callback is pending. IO resource cannot be freed.
2157 */ 2157 */
2158static void 2158static void
@@ -2185,7 +2185,7 @@ bfa_ioim_sm_hcb_free(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2185 } 2185 }
2186} 2186}
2187 2187
2188/** 2188/*
2189 * IO is completed, waiting resource free from firmware. 2189 * IO is completed, waiting resource free from firmware.
2190 */ 2190 */
2191static void 2191static void
@@ -2214,7 +2214,7 @@ bfa_ioim_sm_resfree(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2214 2214
2215 2215
2216 2216
2217/** 2217/*
2218 * hal_ioim_private 2218 * hal_ioim_private
2219 */ 2219 */
2220 2220
@@ -2247,7 +2247,7 @@ __bfa_cb_ioim_comp(void *cbarg, bfa_boolean_t complete)
2247 2247
2248 m = (struct bfi_ioim_rsp_s *) &ioim->iosp->comp_rspmsg; 2248 m = (struct bfi_ioim_rsp_s *) &ioim->iosp->comp_rspmsg;
2249 if (m->io_status == BFI_IOIM_STS_OK) { 2249 if (m->io_status == BFI_IOIM_STS_OK) {
2250 /** 2250 /*
2251 * setup sense information, if present 2251 * setup sense information, if present
2252 */ 2252 */
2253 if ((m->scsi_status == SCSI_STATUS_CHECK_CONDITION) && 2253 if ((m->scsi_status == SCSI_STATUS_CHECK_CONDITION) &&
@@ -2256,15 +2256,15 @@ __bfa_cb_ioim_comp(void *cbarg, bfa_boolean_t complete)
2256 snsinfo = ioim->iosp->snsinfo; 2256 snsinfo = ioim->iosp->snsinfo;
2257 } 2257 }
2258 2258
2259 /** 2259 /*
2260 * setup residue value correctly for normal completions 2260 * setup residue value correctly for normal completions
2261 */ 2261 */
2262 if (m->resid_flags == FCP_RESID_UNDER) { 2262 if (m->resid_flags == FCP_RESID_UNDER) {
2263 residue = bfa_os_ntohl(m->residue); 2263 residue = be32_to_cpu(m->residue);
2264 bfa_stats(ioim->itnim, iocomp_underrun); 2264 bfa_stats(ioim->itnim, iocomp_underrun);
2265 } 2265 }
2266 if (m->resid_flags == FCP_RESID_OVER) { 2266 if (m->resid_flags == FCP_RESID_OVER) {
2267 residue = bfa_os_ntohl(m->residue); 2267 residue = be32_to_cpu(m->residue);
2268 residue = -residue; 2268 residue = -residue;
2269 bfa_stats(ioim->itnim, iocomp_overrun); 2269 bfa_stats(ioim->itnim, iocomp_overrun);
2270 } 2270 }
@@ -2327,7 +2327,7 @@ bfa_ioim_sgpg_alloced(void *cbarg)
2327 bfa_sm_send_event(ioim, BFA_IOIM_SM_SGALLOCED); 2327 bfa_sm_send_event(ioim, BFA_IOIM_SM_SGALLOCED);
2328} 2328}
2329 2329
2330/** 2330/*
2331 * Send I/O request to firmware. 2331 * Send I/O request to firmware.
2332 */ 2332 */
2333static bfa_boolean_t 2333static bfa_boolean_t
@@ -2343,7 +2343,7 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
2343 struct scatterlist *sg; 2343 struct scatterlist *sg;
2344 struct scsi_cmnd *cmnd = (struct scsi_cmnd *) ioim->dio; 2344 struct scsi_cmnd *cmnd = (struct scsi_cmnd *) ioim->dio;
2345 2345
2346 /** 2346 /*
2347 * check for room in queue to send request now 2347 * check for room in queue to send request now
2348 */ 2348 */
2349 m = bfa_reqq_next(ioim->bfa, ioim->reqq); 2349 m = bfa_reqq_next(ioim->bfa, ioim->reqq);
@@ -2354,14 +2354,14 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
2354 return BFA_FALSE; 2354 return BFA_FALSE;
2355 } 2355 }
2356 2356
2357 /** 2357 /*
2358 * build i/o request message next 2358 * build i/o request message next
2359 */ 2359 */
2360 m->io_tag = bfa_os_htons(ioim->iotag); 2360 m->io_tag = cpu_to_be16(ioim->iotag);
2361 m->rport_hdl = ioim->itnim->rport->fw_handle; 2361 m->rport_hdl = ioim->itnim->rport->fw_handle;
2362 m->io_timeout = bfa_cb_ioim_get_timeout(ioim->dio); 2362 m->io_timeout = bfa_cb_ioim_get_timeout(ioim->dio);
2363 2363
2364 /** 2364 /*
2365 * build inline IO SG element here 2365 * build inline IO SG element here
2366 */ 2366 */
2367 sge = &m->sges[0]; 2367 sge = &m->sges[0];
@@ -2387,18 +2387,17 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
2387 sge->flags = BFI_SGE_PGDLEN; 2387 sge->flags = BFI_SGE_PGDLEN;
2388 bfa_sge_to_be(sge); 2388 bfa_sge_to_be(sge);
2389 2389
2390 /** 2390 /*
2391 * set up I/O command parameters 2391 * set up I/O command parameters
2392 */ 2392 */
2393 bfa_os_assign(m->cmnd, cmnd_z0); 2393 m->cmnd = cmnd_z0;
2394 m->cmnd.lun = bfa_cb_ioim_get_lun(ioim->dio); 2394 m->cmnd.lun = bfa_cb_ioim_get_lun(ioim->dio);
2395 m->cmnd.iodir = bfa_cb_ioim_get_iodir(ioim->dio); 2395 m->cmnd.iodir = bfa_cb_ioim_get_iodir(ioim->dio);
2396 bfa_os_assign(m->cmnd.cdb, 2396 m->cmnd.cdb = *(scsi_cdb_t *)bfa_cb_ioim_get_cdb(ioim->dio);
2397 *(scsi_cdb_t *)bfa_cb_ioim_get_cdb(ioim->dio));
2398 fcp_dl = bfa_cb_ioim_get_size(ioim->dio); 2397 fcp_dl = bfa_cb_ioim_get_size(ioim->dio);
2399 m->cmnd.fcp_dl = bfa_os_htonl(fcp_dl); 2398 m->cmnd.fcp_dl = cpu_to_be32(fcp_dl);
2400 2399
2401 /** 2400 /*
2402 * set up I/O message header 2401 * set up I/O message header
2403 */ 2402 */
2404 switch (m->cmnd.iodir) { 2403 switch (m->cmnd.iodir) {
@@ -2427,28 +2426,28 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
2427 m->cmnd.priority = bfa_cb_ioim_get_priority(ioim->dio); 2426 m->cmnd.priority = bfa_cb_ioim_get_priority(ioim->dio);
2428 m->cmnd.taskattr = bfa_cb_ioim_get_taskattr(ioim->dio); 2427 m->cmnd.taskattr = bfa_cb_ioim_get_taskattr(ioim->dio);
2429 2428
2430 /** 2429 /*
2431 * Handle large CDB (>16 bytes). 2430 * Handle large CDB (>16 bytes).
2432 */ 2431 */
2433 m->cmnd.addl_cdb_len = (bfa_cb_ioim_get_cdblen(ioim->dio) - 2432 m->cmnd.addl_cdb_len = (bfa_cb_ioim_get_cdblen(ioim->dio) -
2434 FCP_CMND_CDB_LEN) / sizeof(u32); 2433 FCP_CMND_CDB_LEN) / sizeof(u32);
2435 if (m->cmnd.addl_cdb_len) { 2434 if (m->cmnd.addl_cdb_len) {
2436 bfa_os_memcpy(&m->cmnd.cdb + 1, (scsi_cdb_t *) 2435 memcpy(&m->cmnd.cdb + 1, (scsi_cdb_t *)
2437 bfa_cb_ioim_get_cdb(ioim->dio) + 1, 2436 bfa_cb_ioim_get_cdb(ioim->dio) + 1,
2438 m->cmnd.addl_cdb_len * sizeof(u32)); 2437 m->cmnd.addl_cdb_len * sizeof(u32));
2439 fcp_cmnd_fcpdl(&m->cmnd) = 2438 fcp_cmnd_fcpdl(&m->cmnd) =
2440 bfa_os_htonl(bfa_cb_ioim_get_size(ioim->dio)); 2439 cpu_to_be32(bfa_cb_ioim_get_size(ioim->dio));
2441 } 2440 }
2442#endif 2441#endif
2443 2442
2444 /** 2443 /*
2445 * queue I/O message to firmware 2444 * queue I/O message to firmware
2446 */ 2445 */
2447 bfa_reqq_produce(ioim->bfa, ioim->reqq); 2446 bfa_reqq_produce(ioim->bfa, ioim->reqq);
2448 return BFA_TRUE; 2447 return BFA_TRUE;
2449} 2448}
2450 2449
2451/** 2450/*
2452 * Setup any additional SG pages needed.Inline SG element is setup 2451 * Setup any additional SG pages needed.Inline SG element is setup
2453 * at queuing time. 2452 * at queuing time.
2454 */ 2453 */
@@ -2459,7 +2458,7 @@ bfa_ioim_sge_setup(struct bfa_ioim_s *ioim)
2459 2458
2460 bfa_assert(ioim->nsges > BFI_SGE_INLINE); 2459 bfa_assert(ioim->nsges > BFI_SGE_INLINE);
2461 2460
2462 /** 2461 /*
2463 * allocate SG pages needed 2462 * allocate SG pages needed
2464 */ 2463 */
2465 nsgpgs = BFA_SGPG_NPAGE(ioim->nsges); 2464 nsgpgs = BFA_SGPG_NPAGE(ioim->nsges);
@@ -2508,7 +2507,7 @@ bfa_ioim_sgpg_setup(struct bfa_ioim_s *ioim)
2508 sge->sg_len = sg_dma_len(sg); 2507 sge->sg_len = sg_dma_len(sg);
2509 pgcumsz += sge->sg_len; 2508 pgcumsz += sge->sg_len;
2510 2509
2511 /** 2510 /*
2512 * set flags 2511 * set flags
2513 */ 2512 */
2514 if (i < (nsges - 1)) 2513 if (i < (nsges - 1))
@@ -2523,7 +2522,7 @@ bfa_ioim_sgpg_setup(struct bfa_ioim_s *ioim)
2523 2522
2524 sgpg = (struct bfa_sgpg_s *) bfa_q_next(sgpg); 2523 sgpg = (struct bfa_sgpg_s *) bfa_q_next(sgpg);
2525 2524
2526 /** 2525 /*
2527 * set the link element of each page 2526 * set the link element of each page
2528 */ 2527 */
2529 if (sgeid == ioim->nsges) { 2528 if (sgeid == ioim->nsges) {
@@ -2540,7 +2539,7 @@ bfa_ioim_sgpg_setup(struct bfa_ioim_s *ioim)
2540 } while (sgeid < ioim->nsges); 2539 } while (sgeid < ioim->nsges);
2541} 2540}
2542 2541
2543/** 2542/*
2544 * Send I/O abort request to firmware. 2543 * Send I/O abort request to firmware.
2545 */ 2544 */
2546static bfa_boolean_t 2545static bfa_boolean_t
@@ -2549,14 +2548,14 @@ bfa_ioim_send_abort(struct bfa_ioim_s *ioim)
2549 struct bfi_ioim_abort_req_s *m; 2548 struct bfi_ioim_abort_req_s *m;
2550 enum bfi_ioim_h2i msgop; 2549 enum bfi_ioim_h2i msgop;
2551 2550
2552 /** 2551 /*
2553 * check for room in queue to send request now 2552 * check for room in queue to send request now
2554 */ 2553 */
2555 m = bfa_reqq_next(ioim->bfa, ioim->reqq); 2554 m = bfa_reqq_next(ioim->bfa, ioim->reqq);
2556 if (!m) 2555 if (!m)
2557 return BFA_FALSE; 2556 return BFA_FALSE;
2558 2557
2559 /** 2558 /*
2560 * build i/o request message next 2559 * build i/o request message next
2561 */ 2560 */
2562 if (ioim->iosp->abort_explicit) 2561 if (ioim->iosp->abort_explicit)
@@ -2565,17 +2564,17 @@ bfa_ioim_send_abort(struct bfa_ioim_s *ioim)
2565 msgop = BFI_IOIM_H2I_IOCLEANUP_REQ; 2564 msgop = BFI_IOIM_H2I_IOCLEANUP_REQ;
2566 2565
2567 bfi_h2i_set(m->mh, BFI_MC_IOIM, msgop, bfa_lpuid(ioim->bfa)); 2566 bfi_h2i_set(m->mh, BFI_MC_IOIM, msgop, bfa_lpuid(ioim->bfa));
2568 m->io_tag = bfa_os_htons(ioim->iotag); 2567 m->io_tag = cpu_to_be16(ioim->iotag);
2569 m->abort_tag = ++ioim->abort_tag; 2568 m->abort_tag = ++ioim->abort_tag;
2570 2569
2571 /** 2570 /*
2572 * queue I/O message to firmware 2571 * queue I/O message to firmware
2573 */ 2572 */
2574 bfa_reqq_produce(ioim->bfa, ioim->reqq); 2573 bfa_reqq_produce(ioim->bfa, ioim->reqq);
2575 return BFA_TRUE; 2574 return BFA_TRUE;
2576} 2575}
2577 2576
2578/** 2577/*
2579 * Call to resume any I/O requests waiting for room in request queue. 2578 * Call to resume any I/O requests waiting for room in request queue.
2580 */ 2579 */
2581static void 2580static void
@@ -2591,7 +2590,7 @@ bfa_ioim_qresume(void *cbarg)
2591static void 2590static void
2592bfa_ioim_notify_cleanup(struct bfa_ioim_s *ioim) 2591bfa_ioim_notify_cleanup(struct bfa_ioim_s *ioim)
2593{ 2592{
2594 /** 2593 /*
2595 * Move IO from itnim queue to fcpim global queue since itnim will be 2594 * Move IO from itnim queue to fcpim global queue since itnim will be
2596 * freed. 2595 * freed.
2597 */ 2596 */
@@ -2624,13 +2623,13 @@ bfa_ioim_is_abortable(struct bfa_ioim_s *ioim)
2624 return BFA_TRUE; 2623 return BFA_TRUE;
2625} 2624}
2626 2625
2627/** 2626/*
2628 * or after the link comes back. 2627 * or after the link comes back.
2629 */ 2628 */
2630void 2629void
2631bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim, bfa_boolean_t iotov) 2630bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim, bfa_boolean_t iotov)
2632{ 2631{
2633 /** 2632 /*
2634 * If path tov timer expired, failback with PATHTOV status - these 2633 * If path tov timer expired, failback with PATHTOV status - these
2635 * IO requests are not normally retried by IO stack. 2634 * IO requests are not normally retried by IO stack.
2636 * 2635 *
@@ -2645,7 +2644,7 @@ bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim, bfa_boolean_t iotov)
2645 } 2644 }
2646 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim); 2645 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
2647 2646
2648 /** 2647 /*
2649 * Move IO to fcpim global queue since itnim will be 2648 * Move IO to fcpim global queue since itnim will be
2650 * freed. 2649 * freed.
2651 */ 2650 */
@@ -2655,11 +2654,11 @@ bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim, bfa_boolean_t iotov)
2655 2654
2656 2655
2657 2656
2658/** 2657/*
2659 * hal_ioim_friend 2658 * hal_ioim_friend
2660 */ 2659 */
2661 2660
2662/** 2661/*
2663 * Memory allocation and initialization. 2662 * Memory allocation and initialization.
2664 */ 2663 */
2665void 2664void
@@ -2671,7 +2670,7 @@ bfa_ioim_attach(struct bfa_fcpim_mod_s *fcpim, struct bfa_meminfo_s *minfo)
2671 u8 *snsinfo; 2670 u8 *snsinfo;
2672 u32 snsbufsz; 2671 u32 snsbufsz;
2673 2672
2674 /** 2673 /*
2675 * claim memory first 2674 * claim memory first
2676 */ 2675 */
2677 ioim = (struct bfa_ioim_s *) bfa_meminfo_kva(minfo); 2676 ioim = (struct bfa_ioim_s *) bfa_meminfo_kva(minfo);
@@ -2682,7 +2681,7 @@ bfa_ioim_attach(struct bfa_fcpim_mod_s *fcpim, struct bfa_meminfo_s *minfo)
2682 fcpim->ioim_sp_arr = iosp; 2681 fcpim->ioim_sp_arr = iosp;
2683 bfa_meminfo_kva(minfo) = (u8 *) (iosp + fcpim->num_ioim_reqs); 2682 bfa_meminfo_kva(minfo) = (u8 *) (iosp + fcpim->num_ioim_reqs);
2684 2683
2685 /** 2684 /*
2686 * Claim DMA memory for per IO sense data. 2685 * Claim DMA memory for per IO sense data.
2687 */ 2686 */
2688 snsbufsz = fcpim->num_ioim_reqs * BFI_IOIM_SNSLEN; 2687 snsbufsz = fcpim->num_ioim_reqs * BFI_IOIM_SNSLEN;
@@ -2694,7 +2693,7 @@ bfa_ioim_attach(struct bfa_fcpim_mod_s *fcpim, struct bfa_meminfo_s *minfo)
2694 snsinfo = fcpim->snsbase.kva; 2693 snsinfo = fcpim->snsbase.kva;
2695 bfa_iocfc_set_snsbase(fcpim->bfa, fcpim->snsbase.pa); 2694 bfa_iocfc_set_snsbase(fcpim->bfa, fcpim->snsbase.pa);
2696 2695
2697 /** 2696 /*
2698 * Initialize ioim free queues 2697 * Initialize ioim free queues
2699 */ 2698 */
2700 INIT_LIST_HEAD(&fcpim->ioim_free_q); 2699 INIT_LIST_HEAD(&fcpim->ioim_free_q);
@@ -2706,7 +2705,7 @@ bfa_ioim_attach(struct bfa_fcpim_mod_s *fcpim, struct bfa_meminfo_s *minfo)
2706 /* 2705 /*
2707 * initialize IOIM 2706 * initialize IOIM
2708 */ 2707 */
2709 bfa_os_memset(ioim, 0, sizeof(struct bfa_ioim_s)); 2708 memset(ioim, 0, sizeof(struct bfa_ioim_s));
2710 ioim->iotag = i; 2709 ioim->iotag = i;
2711 ioim->bfa = fcpim->bfa; 2710 ioim->bfa = fcpim->bfa;
2712 ioim->fcpim = fcpim; 2711 ioim->fcpim = fcpim;
@@ -2723,7 +2722,7 @@ bfa_ioim_attach(struct bfa_fcpim_mod_s *fcpim, struct bfa_meminfo_s *minfo)
2723 } 2722 }
2724} 2723}
2725 2724
2726/** 2725/*
2727 * Driver detach time call. 2726 * Driver detach time call.
2728 */ 2727 */
2729void 2728void
@@ -2740,7 +2739,7 @@ bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2740 u16 iotag; 2739 u16 iotag;
2741 enum bfa_ioim_event evt = BFA_IOIM_SM_COMP; 2740 enum bfa_ioim_event evt = BFA_IOIM_SM_COMP;
2742 2741
2743 iotag = bfa_os_ntohs(rsp->io_tag); 2742 iotag = be16_to_cpu(rsp->io_tag);
2744 2743
2745 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag); 2744 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag);
2746 bfa_assert(ioim->iotag == iotag); 2745 bfa_assert(ioim->iotag == iotag);
@@ -2750,7 +2749,7 @@ bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2750 bfa_trc(ioim->bfa, rsp->reuse_io_tag); 2749 bfa_trc(ioim->bfa, rsp->reuse_io_tag);
2751 2750
2752 if (bfa_sm_cmp_state(ioim, bfa_ioim_sm_active)) 2751 if (bfa_sm_cmp_state(ioim, bfa_ioim_sm_active))
2753 bfa_os_assign(ioim->iosp->comp_rspmsg, *m); 2752 ioim->iosp->comp_rspmsg = *m;
2754 2753
2755 switch (rsp->io_status) { 2754 switch (rsp->io_status) {
2756 case BFI_IOIM_STS_OK: 2755 case BFI_IOIM_STS_OK:
@@ -2823,7 +2822,7 @@ bfa_ioim_good_comp_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2823 struct bfa_ioim_s *ioim; 2822 struct bfa_ioim_s *ioim;
2824 u16 iotag; 2823 u16 iotag;
2825 2824
2826 iotag = bfa_os_ntohs(rsp->io_tag); 2825 iotag = be16_to_cpu(rsp->io_tag);
2827 2826
2828 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag); 2827 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag);
2829 bfa_assert(ioim->iotag == iotag); 2828 bfa_assert(ioim->iotag == iotag);
@@ -2837,7 +2836,7 @@ bfa_ioim_good_comp_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2837void 2836void
2838bfa_ioim_profile_start(struct bfa_ioim_s *ioim) 2837bfa_ioim_profile_start(struct bfa_ioim_s *ioim)
2839{ 2838{
2840 ioim->start_time = bfa_os_get_clock(); 2839 ioim->start_time = jiffies;
2841} 2840}
2842 2841
2843void 2842void
@@ -2845,7 +2844,7 @@ bfa_ioim_profile_comp(struct bfa_ioim_s *ioim)
2845{ 2844{
2846 u32 fcp_dl = bfa_cb_ioim_get_size(ioim->dio); 2845 u32 fcp_dl = bfa_cb_ioim_get_size(ioim->dio);
2847 u32 index = bfa_ioim_get_index(fcp_dl); 2846 u32 index = bfa_ioim_get_index(fcp_dl);
2848 u64 end_time = bfa_os_get_clock(); 2847 u64 end_time = jiffies;
2849 struct bfa_itnim_latency_s *io_lat = 2848 struct bfa_itnim_latency_s *io_lat =
2850 &(ioim->itnim->ioprofile.io_latency); 2849 &(ioim->itnim->ioprofile.io_latency);
2851 u32 val = (u32)(end_time - ioim->start_time); 2850 u32 val = (u32)(end_time - ioim->start_time);
@@ -2859,7 +2858,7 @@ bfa_ioim_profile_comp(struct bfa_ioim_s *ioim)
2859 io_lat->max[index] : val; 2858 io_lat->max[index] : val;
2860 io_lat->avg[index] += val; 2859 io_lat->avg[index] += val;
2861} 2860}
2862/** 2861/*
2863 * Called by itnim to clean up IO while going offline. 2862 * Called by itnim to clean up IO while going offline.
2864 */ 2863 */
2865void 2864void
@@ -2882,7 +2881,7 @@ bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim, struct bfa_tskim_s *tskim)
2882 bfa_sm_send_event(ioim, BFA_IOIM_SM_CLEANUP); 2881 bfa_sm_send_event(ioim, BFA_IOIM_SM_CLEANUP);
2883} 2882}
2884 2883
2885/** 2884/*
2886 * IOC failure handling. 2885 * IOC failure handling.
2887 */ 2886 */
2888void 2887void
@@ -2893,7 +2892,7 @@ bfa_ioim_iocdisable(struct bfa_ioim_s *ioim)
2893 bfa_sm_send_event(ioim, BFA_IOIM_SM_HWFAIL); 2892 bfa_sm_send_event(ioim, BFA_IOIM_SM_HWFAIL);
2894} 2893}
2895 2894
2896/** 2895/*
2897 * IO offline TOV popped. Fail the pending IO. 2896 * IO offline TOV popped. Fail the pending IO.
2898 */ 2897 */
2899void 2898void
@@ -2905,11 +2904,11 @@ bfa_ioim_tov(struct bfa_ioim_s *ioim)
2905 2904
2906 2905
2907 2906
2908/** 2907/*
2909 * hal_ioim_api 2908 * hal_ioim_api
2910 */ 2909 */
2911 2910
2912/** 2911/*
2913 * Allocate IOIM resource for initiator mode I/O request. 2912 * Allocate IOIM resource for initiator mode I/O request.
2914 */ 2913 */
2915struct bfa_ioim_s * 2914struct bfa_ioim_s *
@@ -2919,7 +2918,7 @@ bfa_ioim_alloc(struct bfa_s *bfa, struct bfad_ioim_s *dio,
2919 struct bfa_fcpim_mod_s *fcpim = BFA_FCPIM_MOD(bfa); 2918 struct bfa_fcpim_mod_s *fcpim = BFA_FCPIM_MOD(bfa);
2920 struct bfa_ioim_s *ioim; 2919 struct bfa_ioim_s *ioim;
2921 2920
2922 /** 2921 /*
2923 * alocate IOIM resource 2922 * alocate IOIM resource
2924 */ 2923 */
2925 bfa_q_deq(&fcpim->ioim_free_q, &ioim); 2924 bfa_q_deq(&fcpim->ioim_free_q, &ioim);
@@ -2970,7 +2969,7 @@ bfa_ioim_start(struct bfa_ioim_s *ioim)
2970 2969
2971 bfa_ioim_cb_profile_start(ioim->fcpim, ioim); 2970 bfa_ioim_cb_profile_start(ioim->fcpim, ioim);
2972 2971
2973 /** 2972 /*
2974 * Obtain the queue over which this request has to be issued 2973 * Obtain the queue over which this request has to be issued
2975 */ 2974 */
2976 ioim->reqq = bfa_fcpim_ioredirect_enabled(ioim->bfa) ? 2975 ioim->reqq = bfa_fcpim_ioredirect_enabled(ioim->bfa) ?
@@ -2980,7 +2979,7 @@ bfa_ioim_start(struct bfa_ioim_s *ioim)
2980 bfa_sm_send_event(ioim, BFA_IOIM_SM_START); 2979 bfa_sm_send_event(ioim, BFA_IOIM_SM_START);
2981} 2980}
2982 2981
2983/** 2982/*
2984 * Driver I/O abort request. 2983 * Driver I/O abort request.
2985 */ 2984 */
2986bfa_status_t 2985bfa_status_t
@@ -2999,11 +2998,11 @@ bfa_ioim_abort(struct bfa_ioim_s *ioim)
2999} 2998}
3000 2999
3001 3000
3002/** 3001/*
3003 * BFA TSKIM state machine functions 3002 * BFA TSKIM state machine functions
3004 */ 3003 */
3005 3004
3006/** 3005/*
3007 * Task management command beginning state. 3006 * Task management command beginning state.
3008 */ 3007 */
3009static void 3008static void
@@ -3016,7 +3015,7 @@ bfa_tskim_sm_uninit(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3016 bfa_sm_set_state(tskim, bfa_tskim_sm_active); 3015 bfa_sm_set_state(tskim, bfa_tskim_sm_active);
3017 bfa_tskim_gather_ios(tskim); 3016 bfa_tskim_gather_ios(tskim);
3018 3017
3019 /** 3018 /*
3020 * If device is offline, do not send TM on wire. Just cleanup 3019 * If device is offline, do not send TM on wire. Just cleanup
3021 * any pending IO requests and complete TM request. 3020 * any pending IO requests and complete TM request.
3022 */ 3021 */
@@ -3040,7 +3039,7 @@ bfa_tskim_sm_uninit(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3040 } 3039 }
3041} 3040}
3042 3041
3043/** 3042/*
3044 * brief 3043 * brief
3045 * TM command is active, awaiting completion from firmware to 3044 * TM command is active, awaiting completion from firmware to
3046 * cleanup IO requests in TM scope. 3045 * cleanup IO requests in TM scope.
@@ -3077,7 +3076,7 @@ bfa_tskim_sm_active(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3077 } 3076 }
3078} 3077}
3079 3078
3080/** 3079/*
3081 * An active TM is being cleaned up since ITN is offline. Awaiting cleanup 3080 * An active TM is being cleaned up since ITN is offline. Awaiting cleanup
3082 * completion event from firmware. 3081 * completion event from firmware.
3083 */ 3082 */
@@ -3088,7 +3087,7 @@ bfa_tskim_sm_cleanup(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3088 3087
3089 switch (event) { 3088 switch (event) {
3090 case BFA_TSKIM_SM_DONE: 3089 case BFA_TSKIM_SM_DONE:
3091 /** 3090 /*
3092 * Ignore and wait for ABORT completion from firmware. 3091 * Ignore and wait for ABORT completion from firmware.
3093 */ 3092 */
3094 break; 3093 break;
@@ -3121,7 +3120,7 @@ bfa_tskim_sm_iocleanup(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3121 break; 3120 break;
3122 3121
3123 case BFA_TSKIM_SM_CLEANUP: 3122 case BFA_TSKIM_SM_CLEANUP:
3124 /** 3123 /*
3125 * Ignore, TM command completed on wire. 3124 * Ignore, TM command completed on wire.
3126 * Notify TM conmpletion on IO cleanup completion. 3125 * Notify TM conmpletion on IO cleanup completion.
3127 */ 3126 */
@@ -3138,7 +3137,7 @@ bfa_tskim_sm_iocleanup(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3138 } 3137 }
3139} 3138}
3140 3139
3141/** 3140/*
3142 * Task management command is waiting for room in request CQ 3141 * Task management command is waiting for room in request CQ
3143 */ 3142 */
3144static void 3143static void
@@ -3153,7 +3152,7 @@ bfa_tskim_sm_qfull(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3153 break; 3152 break;
3154 3153
3155 case BFA_TSKIM_SM_CLEANUP: 3154 case BFA_TSKIM_SM_CLEANUP:
3156 /** 3155 /*
3157 * No need to send TM on wire since ITN is offline. 3156 * No need to send TM on wire since ITN is offline.
3158 */ 3157 */
3159 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup); 3158 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
@@ -3173,7 +3172,7 @@ bfa_tskim_sm_qfull(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3173 } 3172 }
3174} 3173}
3175 3174
3176/** 3175/*
3177 * Task management command is active, awaiting for room in request CQ 3176 * Task management command is active, awaiting for room in request CQ
3178 * to send clean up request. 3177 * to send clean up request.
3179 */ 3178 */
@@ -3186,7 +3185,7 @@ bfa_tskim_sm_cleanup_qfull(struct bfa_tskim_s *tskim,
3186 switch (event) { 3185 switch (event) {
3187 case BFA_TSKIM_SM_DONE: 3186 case BFA_TSKIM_SM_DONE:
3188 bfa_reqq_wcancel(&tskim->reqq_wait); 3187 bfa_reqq_wcancel(&tskim->reqq_wait);
3189 /** 3188 /*
3190 * 3189 *
3191 * Fall through !!! 3190 * Fall through !!!
3192 */ 3191 */
@@ -3208,7 +3207,7 @@ bfa_tskim_sm_cleanup_qfull(struct bfa_tskim_s *tskim,
3208 } 3207 }
3209} 3208}
3210 3209
3211/** 3210/*
3212 * BFA callback is pending 3211 * BFA callback is pending
3213 */ 3212 */
3214static void 3213static void
@@ -3236,7 +3235,7 @@ bfa_tskim_sm_hcb(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3236 3235
3237 3236
3238 3237
3239/** 3238/*
3240 * hal_tskim_private 3239 * hal_tskim_private
3241 */ 3240 */
3242 3241
@@ -3289,7 +3288,7 @@ bfa_tskim_match_scope(struct bfa_tskim_s *tskim, lun_t lun)
3289 return BFA_FALSE; 3288 return BFA_FALSE;
3290} 3289}
3291 3290
3292/** 3291/*
3293 * Gather affected IO requests and task management commands. 3292 * Gather affected IO requests and task management commands.
3294 */ 3293 */
3295static void 3294static void
@@ -3301,7 +3300,7 @@ bfa_tskim_gather_ios(struct bfa_tskim_s *tskim)
3301 3300
3302 INIT_LIST_HEAD(&tskim->io_q); 3301 INIT_LIST_HEAD(&tskim->io_q);
3303 3302
3304 /** 3303 /*
3305 * Gather any active IO requests first. 3304 * Gather any active IO requests first.
3306 */ 3305 */
3307 list_for_each_safe(qe, qen, &itnim->io_q) { 3306 list_for_each_safe(qe, qen, &itnim->io_q) {
@@ -3313,7 +3312,7 @@ bfa_tskim_gather_ios(struct bfa_tskim_s *tskim)
3313 } 3312 }
3314 } 3313 }
3315 3314
3316 /** 3315 /*
3317 * Failback any pending IO requests immediately. 3316 * Failback any pending IO requests immediately.
3318 */ 3317 */
3319 list_for_each_safe(qe, qen, &itnim->pending_q) { 3318 list_for_each_safe(qe, qen, &itnim->pending_q) {
@@ -3327,7 +3326,7 @@ bfa_tskim_gather_ios(struct bfa_tskim_s *tskim)
3327 } 3326 }
3328} 3327}
3329 3328
3330/** 3329/*
3331 * IO cleanup completion 3330 * IO cleanup completion
3332 */ 3331 */
3333static void 3332static void
@@ -3339,7 +3338,7 @@ bfa_tskim_cleanp_comp(void *tskim_cbarg)
3339 bfa_sm_send_event(tskim, BFA_TSKIM_SM_IOS_DONE); 3338 bfa_sm_send_event(tskim, BFA_TSKIM_SM_IOS_DONE);
3340} 3339}
3341 3340
3342/** 3341/*
3343 * Gather affected IO requests and task management commands. 3342 * Gather affected IO requests and task management commands.
3344 */ 3343 */
3345static void 3344static void
@@ -3359,7 +3358,7 @@ bfa_tskim_cleanup_ios(struct bfa_tskim_s *tskim)
3359 bfa_wc_wait(&tskim->wc); 3358 bfa_wc_wait(&tskim->wc);
3360} 3359}
3361 3360
3362/** 3361/*
3363 * Send task management request to firmware. 3362 * Send task management request to firmware.
3364 */ 3363 */
3365static bfa_boolean_t 3364static bfa_boolean_t
@@ -3368,33 +3367,33 @@ bfa_tskim_send(struct bfa_tskim_s *tskim)
3368 struct bfa_itnim_s *itnim = tskim->itnim; 3367 struct bfa_itnim_s *itnim = tskim->itnim;
3369 struct bfi_tskim_req_s *m; 3368 struct bfi_tskim_req_s *m;
3370 3369
3371 /** 3370 /*
3372 * check for room in queue to send request now 3371 * check for room in queue to send request now
3373 */ 3372 */
3374 m = bfa_reqq_next(tskim->bfa, itnim->reqq); 3373 m = bfa_reqq_next(tskim->bfa, itnim->reqq);
3375 if (!m) 3374 if (!m)
3376 return BFA_FALSE; 3375 return BFA_FALSE;
3377 3376
3378 /** 3377 /*
3379 * build i/o request message next 3378 * build i/o request message next
3380 */ 3379 */
3381 bfi_h2i_set(m->mh, BFI_MC_TSKIM, BFI_TSKIM_H2I_TM_REQ, 3380 bfi_h2i_set(m->mh, BFI_MC_TSKIM, BFI_TSKIM_H2I_TM_REQ,
3382 bfa_lpuid(tskim->bfa)); 3381 bfa_lpuid(tskim->bfa));
3383 3382
3384 m->tsk_tag = bfa_os_htons(tskim->tsk_tag); 3383 m->tsk_tag = cpu_to_be16(tskim->tsk_tag);
3385 m->itn_fhdl = tskim->itnim->rport->fw_handle; 3384 m->itn_fhdl = tskim->itnim->rport->fw_handle;
3386 m->t_secs = tskim->tsecs; 3385 m->t_secs = tskim->tsecs;
3387 m->lun = tskim->lun; 3386 m->lun = tskim->lun;
3388 m->tm_flags = tskim->tm_cmnd; 3387 m->tm_flags = tskim->tm_cmnd;
3389 3388
3390 /** 3389 /*
3391 * queue I/O message to firmware 3390 * queue I/O message to firmware
3392 */ 3391 */
3393 bfa_reqq_produce(tskim->bfa, itnim->reqq); 3392 bfa_reqq_produce(tskim->bfa, itnim->reqq);
3394 return BFA_TRUE; 3393 return BFA_TRUE;
3395} 3394}
3396 3395
3397/** 3396/*
3398 * Send abort request to cleanup an active TM to firmware. 3397 * Send abort request to cleanup an active TM to firmware.
3399 */ 3398 */
3400static bfa_boolean_t 3399static bfa_boolean_t
@@ -3403,29 +3402,29 @@ bfa_tskim_send_abort(struct bfa_tskim_s *tskim)
3403 struct bfa_itnim_s *itnim = tskim->itnim; 3402 struct bfa_itnim_s *itnim = tskim->itnim;
3404 struct bfi_tskim_abortreq_s *m; 3403 struct bfi_tskim_abortreq_s *m;
3405 3404
3406 /** 3405 /*
3407 * check for room in queue to send request now 3406 * check for room in queue to send request now
3408 */ 3407 */
3409 m = bfa_reqq_next(tskim->bfa, itnim->reqq); 3408 m = bfa_reqq_next(tskim->bfa, itnim->reqq);
3410 if (!m) 3409 if (!m)
3411 return BFA_FALSE; 3410 return BFA_FALSE;
3412 3411
3413 /** 3412 /*
3414 * build i/o request message next 3413 * build i/o request message next
3415 */ 3414 */
3416 bfi_h2i_set(m->mh, BFI_MC_TSKIM, BFI_TSKIM_H2I_ABORT_REQ, 3415 bfi_h2i_set(m->mh, BFI_MC_TSKIM, BFI_TSKIM_H2I_ABORT_REQ,
3417 bfa_lpuid(tskim->bfa)); 3416 bfa_lpuid(tskim->bfa));
3418 3417
3419 m->tsk_tag = bfa_os_htons(tskim->tsk_tag); 3418 m->tsk_tag = cpu_to_be16(tskim->tsk_tag);
3420 3419
3421 /** 3420 /*
3422 * queue I/O message to firmware 3421 * queue I/O message to firmware
3423 */ 3422 */
3424 bfa_reqq_produce(tskim->bfa, itnim->reqq); 3423 bfa_reqq_produce(tskim->bfa, itnim->reqq);
3425 return BFA_TRUE; 3424 return BFA_TRUE;
3426} 3425}
3427 3426
3428/** 3427/*
3429 * Call to resume task management cmnd waiting for room in request queue. 3428 * Call to resume task management cmnd waiting for room in request queue.
3430 */ 3429 */
3431static void 3430static void
@@ -3437,7 +3436,7 @@ bfa_tskim_qresume(void *cbarg)
3437 bfa_sm_send_event(tskim, BFA_TSKIM_SM_QRESUME); 3436 bfa_sm_send_event(tskim, BFA_TSKIM_SM_QRESUME);
3438} 3437}
3439 3438
3440/** 3439/*
3441 * Cleanup IOs associated with a task mangement command on IOC failures. 3440 * Cleanup IOs associated with a task mangement command on IOC failures.
3442 */ 3441 */
3443static void 3442static void
@@ -3454,11 +3453,11 @@ bfa_tskim_iocdisable_ios(struct bfa_tskim_s *tskim)
3454 3453
3455 3454
3456 3455
3457/** 3456/*
3458 * hal_tskim_friend 3457 * hal_tskim_friend
3459 */ 3458 */
3460 3459
3461/** 3460/*
3462 * Notification on completions from related ioim. 3461 * Notification on completions from related ioim.
3463 */ 3462 */
3464void 3463void
@@ -3467,7 +3466,7 @@ bfa_tskim_iodone(struct bfa_tskim_s *tskim)
3467 bfa_wc_down(&tskim->wc); 3466 bfa_wc_down(&tskim->wc);
3468} 3467}
3469 3468
3470/** 3469/*
3471 * Handle IOC h/w failure notification from itnim. 3470 * Handle IOC h/w failure notification from itnim.
3472 */ 3471 */
3473void 3472void
@@ -3478,7 +3477,7 @@ bfa_tskim_iocdisable(struct bfa_tskim_s *tskim)
3478 bfa_sm_send_event(tskim, BFA_TSKIM_SM_HWFAIL); 3477 bfa_sm_send_event(tskim, BFA_TSKIM_SM_HWFAIL);
3479} 3478}
3480 3479
3481/** 3480/*
3482 * Cleanup TM command and associated IOs as part of ITNIM offline. 3481 * Cleanup TM command and associated IOs as part of ITNIM offline.
3483 */ 3482 */
3484void 3483void
@@ -3489,7 +3488,7 @@ bfa_tskim_cleanup(struct bfa_tskim_s *tskim)
3489 bfa_sm_send_event(tskim, BFA_TSKIM_SM_CLEANUP); 3488 bfa_sm_send_event(tskim, BFA_TSKIM_SM_CLEANUP);
3490} 3489}
3491 3490
3492/** 3491/*
3493 * Memory allocation and initialization. 3492 * Memory allocation and initialization.
3494 */ 3493 */
3495void 3494void
@@ -3507,7 +3506,7 @@ bfa_tskim_attach(struct bfa_fcpim_mod_s *fcpim, struct bfa_meminfo_s *minfo)
3507 /* 3506 /*
3508 * initialize TSKIM 3507 * initialize TSKIM
3509 */ 3508 */
3510 bfa_os_memset(tskim, 0, sizeof(struct bfa_tskim_s)); 3509 memset(tskim, 0, sizeof(struct bfa_tskim_s));
3511 tskim->tsk_tag = i; 3510 tskim->tsk_tag = i;
3512 tskim->bfa = fcpim->bfa; 3511 tskim->bfa = fcpim->bfa;
3513 tskim->fcpim = fcpim; 3512 tskim->fcpim = fcpim;
@@ -3525,7 +3524,7 @@ bfa_tskim_attach(struct bfa_fcpim_mod_s *fcpim, struct bfa_meminfo_s *minfo)
3525void 3524void
3526bfa_tskim_detach(struct bfa_fcpim_mod_s *fcpim) 3525bfa_tskim_detach(struct bfa_fcpim_mod_s *fcpim)
3527{ 3526{
3528 /** 3527 /*
3529 * @todo 3528 * @todo
3530 */ 3529 */
3531} 3530}
@@ -3536,14 +3535,14 @@ bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
3536 struct bfa_fcpim_mod_s *fcpim = BFA_FCPIM_MOD(bfa); 3535 struct bfa_fcpim_mod_s *fcpim = BFA_FCPIM_MOD(bfa);
3537 struct bfi_tskim_rsp_s *rsp = (struct bfi_tskim_rsp_s *) m; 3536 struct bfi_tskim_rsp_s *rsp = (struct bfi_tskim_rsp_s *) m;
3538 struct bfa_tskim_s *tskim; 3537 struct bfa_tskim_s *tskim;
3539 u16 tsk_tag = bfa_os_ntohs(rsp->tsk_tag); 3538 u16 tsk_tag = be16_to_cpu(rsp->tsk_tag);
3540 3539
3541 tskim = BFA_TSKIM_FROM_TAG(fcpim, tsk_tag); 3540 tskim = BFA_TSKIM_FROM_TAG(fcpim, tsk_tag);
3542 bfa_assert(tskim->tsk_tag == tsk_tag); 3541 bfa_assert(tskim->tsk_tag == tsk_tag);
3543 3542
3544 tskim->tsk_status = rsp->tsk_status; 3543 tskim->tsk_status = rsp->tsk_status;
3545 3544
3546 /** 3545 /*
3547 * Firmware sends BFI_TSKIM_STS_ABORTED status for abort 3546 * Firmware sends BFI_TSKIM_STS_ABORTED status for abort
3548 * requests. All other statuses are for normal completions. 3547 * requests. All other statuses are for normal completions.
3549 */ 3548 */
@@ -3558,7 +3557,7 @@ bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
3558 3557
3559 3558
3560 3559
3561/** 3560/*
3562 * hal_tskim_api 3561 * hal_tskim_api
3563 */ 3562 */
3564 3563
@@ -3585,7 +3584,7 @@ bfa_tskim_free(struct bfa_tskim_s *tskim)
3585 list_add_tail(&tskim->qe, &tskim->fcpim->tskim_free_q); 3584 list_add_tail(&tskim->qe, &tskim->fcpim->tskim_free_q);
3586} 3585}
3587 3586
3588/** 3587/*
3589 * Start a task management command. 3588 * Start a task management command.
3590 * 3589 *
3591 * @param[in] tskim BFA task management command instance 3590 * @param[in] tskim BFA task management command instance
diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
index 3bf343160aac..db53717eeb4b 100644
--- a/drivers/scsi/bfa/bfa_fcpim.h
+++ b/drivers/scsi/bfa/bfa_fcpim.h
@@ -104,7 +104,7 @@ struct bfa_fcpim_mod_s {
104 bfa_fcpim_profile_t profile_start; 104 bfa_fcpim_profile_t profile_start;
105}; 105};
106 106
107/** 107/*
108 * BFA IO (initiator mode) 108 * BFA IO (initiator mode)
109 */ 109 */
110struct bfa_ioim_s { 110struct bfa_ioim_s {
@@ -137,7 +137,7 @@ struct bfa_ioim_sp_s {
137 struct bfa_tskim_s *tskim; /* Relevant TM cmd */ 137 struct bfa_tskim_s *tskim; /* Relevant TM cmd */
138}; 138};
139 139
140/** 140/*
141 * BFA Task management command (initiator mode) 141 * BFA Task management command (initiator mode)
142 */ 142 */
143struct bfa_tskim_s { 143struct bfa_tskim_s {
@@ -160,7 +160,7 @@ struct bfa_tskim_s {
160}; 160};
161 161
162 162
163/** 163/*
164 * BFA i-t-n (initiator mode) 164 * BFA i-t-n (initiator mode)
165 */ 165 */
166struct bfa_itnim_s { 166struct bfa_itnim_s {
@@ -303,7 +303,7 @@ bfa_status_t bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
303 struct bfa_itnim_ioprofile_s *ioprofile); 303 struct bfa_itnim_ioprofile_s *ioprofile);
304#define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq) 304#define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq)
305 305
306/** 306/*
307 * BFA completion callback for bfa_itnim_online(). 307 * BFA completion callback for bfa_itnim_online().
308 * 308 *
309 * @param[in] itnim FCS or driver itnim instance 309 * @param[in] itnim FCS or driver itnim instance
@@ -312,7 +312,7 @@ bfa_status_t bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
312 */ 312 */
313void bfa_cb_itnim_online(void *itnim); 313void bfa_cb_itnim_online(void *itnim);
314 314
315/** 315/*
316 * BFA completion callback for bfa_itnim_offline(). 316 * BFA completion callback for bfa_itnim_offline().
317 * 317 *
318 * @param[in] itnim FCS or driver itnim instance 318 * @param[in] itnim FCS or driver itnim instance
@@ -323,7 +323,7 @@ void bfa_cb_itnim_offline(void *itnim);
323void bfa_cb_itnim_tov_begin(void *itnim); 323void bfa_cb_itnim_tov_begin(void *itnim);
324void bfa_cb_itnim_tov(void *itnim); 324void bfa_cb_itnim_tov(void *itnim);
325 325
326/** 326/*
327 * BFA notification to FCS/driver for second level error recovery. 327 * BFA notification to FCS/driver for second level error recovery.
328 * 328 *
329 * Atleast one I/O request has timedout and target is unresponsive to 329 * Atleast one I/O request has timedout and target is unresponsive to
@@ -351,7 +351,7 @@ void bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim,
351 bfa_boolean_t iotov); 351 bfa_boolean_t iotov);
352 352
353 353
354/** 354/*
355 * I/O completion notification. 355 * I/O completion notification.
356 * 356 *
357 * @param[in] dio driver IO structure 357 * @param[in] dio driver IO structure
@@ -368,7 +368,7 @@ void bfa_cb_ioim_done(void *bfad, struct bfad_ioim_s *dio,
368 u8 scsi_status, int sns_len, 368 u8 scsi_status, int sns_len,
369 u8 *sns_info, s32 residue); 369 u8 *sns_info, s32 residue);
370 370
371/** 371/*
372 * I/O good completion notification. 372 * I/O good completion notification.
373 * 373 *
374 * @param[in] dio driver IO structure 374 * @param[in] dio driver IO structure
@@ -377,7 +377,7 @@ void bfa_cb_ioim_done(void *bfad, struct bfad_ioim_s *dio,
377 */ 377 */
378void bfa_cb_ioim_good_comp(void *bfad, struct bfad_ioim_s *dio); 378void bfa_cb_ioim_good_comp(void *bfad, struct bfad_ioim_s *dio);
379 379
380/** 380/*
381 * I/O abort completion notification 381 * I/O abort completion notification
382 * 382 *
383 * @param[in] dio driver IO that was aborted 383 * @param[in] dio driver IO that was aborted
diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
index 9cebbe30a678..c94502dfac66 100644
--- a/drivers/scsi/bfa/bfa_fcs.c
+++ b/drivers/scsi/bfa/bfa_fcs.c
@@ -15,7 +15,7 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * bfa_fcs.c BFA FCS main 19 * bfa_fcs.c BFA FCS main
20 */ 20 */
21 21
@@ -25,7 +25,7 @@
25 25
26BFA_TRC_FILE(FCS, FCS); 26BFA_TRC_FILE(FCS, FCS);
27 27
28/** 28/*
29 * FCS sub-modules 29 * FCS sub-modules
30 */ 30 */
31struct bfa_fcs_mod_s { 31struct bfa_fcs_mod_s {
@@ -43,7 +43,7 @@ static struct bfa_fcs_mod_s fcs_modules[] = {
43 bfa_fcs_fabric_modexit }, 43 bfa_fcs_fabric_modexit },
44}; 44};
45 45
46/** 46/*
47 * fcs_api BFA FCS API 47 * fcs_api BFA FCS API
48 */ 48 */
49 49
@@ -58,11 +58,11 @@ bfa_fcs_exit_comp(void *fcs_cbarg)
58 58
59 59
60 60
61/** 61/*
62 * fcs_api BFA FCS API 62 * fcs_api BFA FCS API
63 */ 63 */
64 64
65/** 65/*
66 * fcs attach -- called once to initialize data structures at driver attach time 66 * fcs attach -- called once to initialize data structures at driver attach time
67 */ 67 */
68void 68void
@@ -86,7 +86,7 @@ bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
86 } 86 }
87} 87}
88 88
89/** 89/*
90 * fcs initialization, called once after bfa initialization is complete 90 * fcs initialization, called once after bfa initialization is complete
91 */ 91 */
92void 92void
@@ -110,7 +110,7 @@ bfa_fcs_init(struct bfa_fcs_s *fcs)
110 } 110 }
111} 111}
112 112
113/** 113/*
114 * Start FCS operations. 114 * Start FCS operations.
115 */ 115 */
116void 116void
@@ -119,7 +119,7 @@ bfa_fcs_start(struct bfa_fcs_s *fcs)
119 bfa_fcs_fabric_modstart(fcs); 119 bfa_fcs_fabric_modstart(fcs);
120} 120}
121 121
122/** 122/*
123 * brief 123 * brief
124 * FCS driver details initialization. 124 * FCS driver details initialization.
125 * 125 *
@@ -138,7 +138,7 @@ bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
138 bfa_fcs_fabric_psymb_init(&fcs->fabric); 138 bfa_fcs_fabric_psymb_init(&fcs->fabric);
139} 139}
140 140
141/** 141/*
142 * brief 142 * brief
143 * FCS FDMI Driver Parameter Initialization 143 * FCS FDMI Driver Parameter Initialization
144 * 144 *
@@ -154,7 +154,7 @@ bfa_fcs_set_fdmi_param(struct bfa_fcs_s *fcs, bfa_boolean_t fdmi_enable)
154 fcs->fdmi_enabled = fdmi_enable; 154 fcs->fdmi_enabled = fdmi_enable;
155 155
156} 156}
157/** 157/*
158 * brief 158 * brief
159 * FCS instance cleanup and exit. 159 * FCS instance cleanup and exit.
160 * 160 *
@@ -196,7 +196,7 @@ bfa_fcs_modexit_comp(struct bfa_fcs_s *fcs)
196 bfa_wc_down(&fcs->wc); 196 bfa_wc_down(&fcs->wc);
197} 197}
198 198
199/** 199/*
200 * Fabric module implementation. 200 * Fabric module implementation.
201 */ 201 */
202 202
@@ -232,11 +232,11 @@ static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
232 u32 rsp_len, 232 u32 rsp_len,
233 u32 resid_len, 233 u32 resid_len,
234 struct fchs_s *rspfchs); 234 struct fchs_s *rspfchs);
235/** 235/*
236 * fcs_fabric_sm fabric state machine functions 236 * fcs_fabric_sm fabric state machine functions
237 */ 237 */
238 238
239/** 239/*
240 * Fabric state machine events 240 * Fabric state machine events
241 */ 241 */
242enum bfa_fcs_fabric_event { 242enum bfa_fcs_fabric_event {
@@ -286,7 +286,7 @@ static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
286 enum bfa_fcs_fabric_event event); 286 enum bfa_fcs_fabric_event event);
287static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric, 287static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
288 enum bfa_fcs_fabric_event event); 288 enum bfa_fcs_fabric_event event);
289/** 289/*
290 * Beginning state before fabric creation. 290 * Beginning state before fabric creation.
291 */ 291 */
292static void 292static void
@@ -312,7 +312,7 @@ bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
312 } 312 }
313} 313}
314 314
315/** 315/*
316 * Beginning state before fabric creation. 316 * Beginning state before fabric creation.
317 */ 317 */
318static void 318static void
@@ -345,7 +345,7 @@ bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
345 } 345 }
346} 346}
347 347
348/** 348/*
349 * Link is down, awaiting LINK UP event from port. This is also the 349 * Link is down, awaiting LINK UP event from port. This is also the
350 * first state at fabric creation. 350 * first state at fabric creation.
351 */ 351 */
@@ -375,7 +375,7 @@ bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
375 } 375 }
376} 376}
377 377
378/** 378/*
379 * FLOGI is in progress, awaiting FLOGI reply. 379 * FLOGI is in progress, awaiting FLOGI reply.
380 */ 380 */
381static void 381static void
@@ -468,7 +468,7 @@ bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
468 } 468 }
469} 469}
470 470
471/** 471/*
472 * Authentication is in progress, awaiting authentication results. 472 * Authentication is in progress, awaiting authentication results.
473 */ 473 */
474static void 474static void
@@ -508,7 +508,7 @@ bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
508 } 508 }
509} 509}
510 510
511/** 511/*
512 * Authentication failed 512 * Authentication failed
513 */ 513 */
514static void 514static void
@@ -534,7 +534,7 @@ bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
534 } 534 }
535} 535}
536 536
537/** 537/*
538 * Port is in loopback mode. 538 * Port is in loopback mode.
539 */ 539 */
540static void 540static void
@@ -560,7 +560,7 @@ bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
560 } 560 }
561} 561}
562 562
563/** 563/*
564 * There is no attached fabric - private loop or NPort-to-NPort topology. 564 * There is no attached fabric - private loop or NPort-to-NPort topology.
565 */ 565 */
566static void 566static void
@@ -593,7 +593,7 @@ bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
593 } 593 }
594} 594}
595 595
596/** 596/*
597 * Fabric is online - normal operating state. 597 * Fabric is online - normal operating state.
598 */ 598 */
599static void 599static void
@@ -628,7 +628,7 @@ bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
628 } 628 }
629} 629}
630 630
631/** 631/*
632 * Exchanging virtual fabric parameters. 632 * Exchanging virtual fabric parameters.
633 */ 633 */
634static void 634static void
@@ -652,7 +652,7 @@ bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
652 } 652 }
653} 653}
654 654
655/** 655/*
656 * EVFP exchange complete and VFT tagging is enabled. 656 * EVFP exchange complete and VFT tagging is enabled.
657 */ 657 */
658static void 658static void
@@ -663,7 +663,7 @@ bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
663 bfa_trc(fabric->fcs, event); 663 bfa_trc(fabric->fcs, event);
664} 664}
665 665
666/** 666/*
667 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F). 667 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
668 */ 668 */
669static void 669static void
@@ -684,7 +684,7 @@ bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
684 fabric->event_arg.swp_vfid); 684 fabric->event_arg.swp_vfid);
685} 685}
686 686
687/** 687/*
688 * Fabric is being deleted, awaiting vport delete completions. 688 * Fabric is being deleted, awaiting vport delete completions.
689 */ 689 */
690static void 690static void
@@ -714,7 +714,7 @@ bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
714 714
715 715
716 716
717/** 717/*
718 * fcs_fabric_private fabric private functions 718 * fcs_fabric_private fabric private functions
719 */ 719 */
720 720
@@ -728,7 +728,7 @@ bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
728 port_cfg->pwwn = bfa_ioc_get_pwwn(&fabric->fcs->bfa->ioc); 728 port_cfg->pwwn = bfa_ioc_get_pwwn(&fabric->fcs->bfa->ioc);
729} 729}
730 730
731/** 731/*
732 * Port Symbolic Name Creation for base port. 732 * Port Symbolic Name Creation for base port.
733 */ 733 */
734void 734void
@@ -789,7 +789,7 @@ bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
789 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0; 789 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
790} 790}
791 791
792/** 792/*
793 * bfa lps login completion callback 793 * bfa lps login completion callback
794 */ 794 */
795void 795void
@@ -867,7 +867,7 @@ bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
867 bfa_trc(fabric->fcs, fabric->is_npiv); 867 bfa_trc(fabric->fcs, fabric->is_npiv);
868 bfa_trc(fabric->fcs, fabric->is_auth); 868 bfa_trc(fabric->fcs, fabric->is_auth);
869} 869}
870/** 870/*
871 * Allocate and send FLOGI. 871 * Allocate and send FLOGI.
872 */ 872 */
873static void 873static void
@@ -897,7 +897,7 @@ bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
897 bfa_fcs_fabric_set_opertype(fabric); 897 bfa_fcs_fabric_set_opertype(fabric);
898 fabric->stats.fabric_onlines++; 898 fabric->stats.fabric_onlines++;
899 899
900 /** 900 /*
901 * notify online event to base and then virtual ports 901 * notify online event to base and then virtual ports
902 */ 902 */
903 bfa_fcs_lport_online(&fabric->bport); 903 bfa_fcs_lport_online(&fabric->bport);
@@ -917,7 +917,7 @@ bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
917 bfa_trc(fabric->fcs, fabric->fabric_name); 917 bfa_trc(fabric->fcs, fabric->fabric_name);
918 fabric->stats.fabric_offlines++; 918 fabric->stats.fabric_offlines++;
919 919
920 /** 920 /*
921 * notify offline event first to vports and then base port. 921 * notify offline event first to vports and then base port.
922 */ 922 */
923 list_for_each_safe(qe, qen, &fabric->vport_q) { 923 list_for_each_safe(qe, qen, &fabric->vport_q) {
@@ -939,7 +939,7 @@ bfa_fcs_fabric_delay(void *cbarg)
939 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED); 939 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
940} 940}
941 941
942/** 942/*
943 * Delete all vports and wait for vport delete completions. 943 * Delete all vports and wait for vport delete completions.
944 */ 944 */
945static void 945static void
@@ -965,11 +965,11 @@ bfa_fcs_fabric_delete_comp(void *cbarg)
965 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP); 965 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
966} 966}
967 967
968/** 968/*
969 * fcs_fabric_public fabric public functions 969 * fcs_fabric_public fabric public functions
970 */ 970 */
971 971
972/** 972/*
973 * Attach time initialization. 973 * Attach time initialization.
974 */ 974 */
975void 975void
@@ -978,9 +978,9 @@ bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
978 struct bfa_fcs_fabric_s *fabric; 978 struct bfa_fcs_fabric_s *fabric;
979 979
980 fabric = &fcs->fabric; 980 fabric = &fcs->fabric;
981 bfa_os_memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s)); 981 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
982 982
983 /** 983 /*
984 * Initialize base fabric. 984 * Initialize base fabric.
985 */ 985 */
986 fabric->fcs = fcs; 986 fabric->fcs = fcs;
@@ -989,7 +989,7 @@ bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
989 fabric->lps = bfa_lps_alloc(fcs->bfa); 989 fabric->lps = bfa_lps_alloc(fcs->bfa);
990 bfa_assert(fabric->lps); 990 bfa_assert(fabric->lps);
991 991
992 /** 992 /*
993 * Initialize fabric delete completion handler. Fabric deletion is 993 * Initialize fabric delete completion handler. Fabric deletion is
994 * complete when the last vport delete is complete. 994 * complete when the last vport delete is complete.
995 */ 995 */
@@ -1007,7 +1007,7 @@ bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1007 bfa_trc(fcs, 0); 1007 bfa_trc(fcs, 0);
1008} 1008}
1009 1009
1010/** 1010/*
1011 * Module cleanup 1011 * Module cleanup
1012 */ 1012 */
1013void 1013void
@@ -1017,7 +1017,7 @@ bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1017 1017
1018 bfa_trc(fcs, 0); 1018 bfa_trc(fcs, 0);
1019 1019
1020 /** 1020 /*
1021 * Cleanup base fabric. 1021 * Cleanup base fabric.
1022 */ 1022 */
1023 fabric = &fcs->fabric; 1023 fabric = &fcs->fabric;
@@ -1025,7 +1025,7 @@ bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1025 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE); 1025 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1026} 1026}
1027 1027
1028/** 1028/*
1029 * Fabric module start -- kick starts FCS actions 1029 * Fabric module start -- kick starts FCS actions
1030 */ 1030 */
1031void 1031void
@@ -1038,7 +1038,7 @@ bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1038 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START); 1038 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1039} 1039}
1040 1040
1041/** 1041/*
1042 * Suspend fabric activity as part of driver suspend. 1042 * Suspend fabric activity as part of driver suspend.
1043 */ 1043 */
1044void 1044void
@@ -1064,7 +1064,7 @@ bfa_fcs_fabric_port_type(struct bfa_fcs_fabric_s *fabric)
1064 return fabric->oper_type; 1064 return fabric->oper_type;
1065} 1065}
1066 1066
1067/** 1067/*
1068 * Link up notification from BFA physical port module. 1068 * Link up notification from BFA physical port module.
1069 */ 1069 */
1070void 1070void
@@ -1074,7 +1074,7 @@ bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1074 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP); 1074 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1075} 1075}
1076 1076
1077/** 1077/*
1078 * Link down notification from BFA physical port module. 1078 * Link down notification from BFA physical port module.
1079 */ 1079 */
1080void 1080void
@@ -1084,7 +1084,7 @@ bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1084 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN); 1084 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1085} 1085}
1086 1086
1087/** 1087/*
1088 * A child vport is being created in the fabric. 1088 * A child vport is being created in the fabric.
1089 * 1089 *
1090 * Call from vport module at vport creation. A list of base port and vports 1090 * Call from vport module at vport creation. A list of base port and vports
@@ -1099,7 +1099,7 @@ void
1099bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric, 1099bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1100 struct bfa_fcs_vport_s *vport) 1100 struct bfa_fcs_vport_s *vport)
1101{ 1101{
1102 /** 1102 /*
1103 * - add vport to fabric's vport_q 1103 * - add vport to fabric's vport_q
1104 */ 1104 */
1105 bfa_trc(fabric->fcs, fabric->vf_id); 1105 bfa_trc(fabric->fcs, fabric->vf_id);
@@ -1109,7 +1109,7 @@ bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1109 bfa_wc_up(&fabric->wc); 1109 bfa_wc_up(&fabric->wc);
1110} 1110}
1111 1111
1112/** 1112/*
1113 * A child vport is being deleted from fabric. 1113 * A child vport is being deleted from fabric.
1114 * 1114 *
1115 * Vport is being deleted. 1115 * Vport is being deleted.
@@ -1123,7 +1123,7 @@ bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1123 bfa_wc_down(&fabric->wc); 1123 bfa_wc_down(&fabric->wc);
1124} 1124}
1125 1125
1126/** 1126/*
1127 * Base port is deleted. 1127 * Base port is deleted.
1128 */ 1128 */
1129void 1129void
@@ -1133,7 +1133,7 @@ bfa_fcs_fabric_port_delete_comp(struct bfa_fcs_fabric_s *fabric)
1133} 1133}
1134 1134
1135 1135
1136/** 1136/*
1137 * Check if fabric is online. 1137 * Check if fabric is online.
1138 * 1138 *
1139 * param[in] fabric - Fabric instance. This can be a base fabric or vf. 1139 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
@@ -1146,7 +1146,7 @@ bfa_fcs_fabric_is_online(struct bfa_fcs_fabric_s *fabric)
1146 return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_online); 1146 return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_online);
1147} 1147}
1148 1148
1149/** 1149/*
1150 * brief 1150 * brief
1151 * 1151 *
1152 */ 1152 */
@@ -1158,7 +1158,7 @@ bfa_fcs_fabric_addvf(struct bfa_fcs_fabric_s *vf, struct bfa_fcs_s *fcs,
1158 return BFA_STATUS_OK; 1158 return BFA_STATUS_OK;
1159} 1159}
1160 1160
1161/** 1161/*
1162 * Lookup for a vport withing a fabric given its pwwn 1162 * Lookup for a vport withing a fabric given its pwwn
1163 */ 1163 */
1164struct bfa_fcs_vport_s * 1164struct bfa_fcs_vport_s *
@@ -1176,7 +1176,7 @@ bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1176 return NULL; 1176 return NULL;
1177} 1177}
1178 1178
1179/** 1179/*
1180 * In a given fabric, return the number of lports. 1180 * In a given fabric, return the number of lports.
1181 * 1181 *
1182 * param[in] fabric - Fabric instance. This can be a base fabric or vf. 1182 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
@@ -1214,7 +1214,7 @@ bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1214 1214
1215 return oui; 1215 return oui;
1216} 1216}
1217/** 1217/*
1218 * Unsolicited frame receive handling. 1218 * Unsolicited frame receive handling.
1219 */ 1219 */
1220void 1220void
@@ -1230,7 +1230,7 @@ bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1230 bfa_trc(fabric->fcs, len); 1230 bfa_trc(fabric->fcs, len);
1231 bfa_trc(fabric->fcs, pid); 1231 bfa_trc(fabric->fcs, pid);
1232 1232
1233 /** 1233 /*
1234 * Look for our own FLOGI frames being looped back. This means an 1234 * Look for our own FLOGI frames being looped back. This means an
1235 * external loopback cable is in place. Our own FLOGI frames are 1235 * external loopback cable is in place. Our own FLOGI frames are
1236 * sometimes looped back when switch port gets temporarily bypassed. 1236 * sometimes looped back when switch port gets temporarily bypassed.
@@ -1242,7 +1242,7 @@ bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1242 return; 1242 return;
1243 } 1243 }
1244 1244
1245 /** 1245 /*
1246 * FLOGI/EVFP exchanges should be consumed by base fabric. 1246 * FLOGI/EVFP exchanges should be consumed by base fabric.
1247 */ 1247 */
1248 if (fchs->d_id == bfa_os_hton3b(FC_FABRIC_PORT)) { 1248 if (fchs->d_id == bfa_os_hton3b(FC_FABRIC_PORT)) {
@@ -1252,7 +1252,7 @@ bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1252 } 1252 }
1253 1253
1254 if (fabric->bport.pid == pid) { 1254 if (fabric->bport.pid == pid) {
1255 /** 1255 /*
1256 * All authentication frames should be routed to auth 1256 * All authentication frames should be routed to auth
1257 */ 1257 */
1258 bfa_trc(fabric->fcs, els_cmd->els_code); 1258 bfa_trc(fabric->fcs, els_cmd->els_code);
@@ -1266,7 +1266,7 @@ bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1266 return; 1266 return;
1267 } 1267 }
1268 1268
1269 /** 1269 /*
1270 * look for a matching local port ID 1270 * look for a matching local port ID
1271 */ 1271 */
1272 list_for_each(qe, &fabric->vport_q) { 1272 list_for_each(qe, &fabric->vport_q) {
@@ -1280,7 +1280,7 @@ bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1280 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len); 1280 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1281} 1281}
1282 1282
1283/** 1283/*
1284 * Unsolicited frames to be processed by fabric. 1284 * Unsolicited frames to be processed by fabric.
1285 */ 1285 */
1286static void 1286static void
@@ -1304,7 +1304,7 @@ bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1304 } 1304 }
1305} 1305}
1306 1306
1307/** 1307/*
1308 * Process incoming FLOGI 1308 * Process incoming FLOGI
1309 */ 1309 */
1310static void 1310static void
@@ -1329,7 +1329,7 @@ bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1329 return; 1329 return;
1330 } 1330 }
1331 1331
1332 fabric->bb_credit = bfa_os_ntohs(flogi->csp.bbcred); 1332 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
1333 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name; 1333 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1334 bport->port_topo.pn2n.reply_oxid = fchs->ox_id; 1334 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1335 1335
@@ -1351,7 +1351,7 @@ bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1351 struct fchs_s fchs; 1351 struct fchs_s fchs;
1352 1352
1353 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs); 1353 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs);
1354 /** 1354 /*
1355 * Do not expect this failure -- expect remote node to retry 1355 * Do not expect this failure -- expect remote node to retry
1356 */ 1356 */
1357 if (!fcxp) 1357 if (!fcxp)
@@ -1370,7 +1370,7 @@ bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1370 FC_MAX_PDUSZ, 0); 1370 FC_MAX_PDUSZ, 0);
1371} 1371}
1372 1372
1373/** 1373/*
1374 * Flogi Acc completion callback. 1374 * Flogi Acc completion callback.
1375 */ 1375 */
1376static void 1376static void
@@ -1417,130 +1417,7 @@ bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1417 } 1417 }
1418} 1418}
1419 1419
1420/** 1420/*
1421 * fcs_vf_api virtual fabrics API
1422 */
1423
1424/**
1425 * Enable VF mode.
1426 *
1427 * @param[in] fcs fcs module instance
1428 * @param[in] vf_id default vf_id of port, FC_VF_ID_NULL
1429 * to use standard default vf_id of 1.
1430 *
1431 * @retval BFA_STATUS_OK vf mode is enabled
1432 * @retval BFA_STATUS_BUSY Port is active. Port must be disabled
1433 * before VF mode can be enabled.
1434 */
1435bfa_status_t
1436bfa_fcs_vf_mode_enable(struct bfa_fcs_s *fcs, u16 vf_id)
1437{
1438 return BFA_STATUS_OK;
1439}
1440
1441/**
1442 * Disable VF mode.
1443 *
1444 * @param[in] fcs fcs module instance
1445 *
1446 * @retval BFA_STATUS_OK vf mode is disabled
1447 * @retval BFA_STATUS_BUSY VFs are present and being used. All
1448 * VFs must be deleted before disabling
1449 * VF mode.
1450 */
1451bfa_status_t
1452bfa_fcs_vf_mode_disable(struct bfa_fcs_s *fcs)
1453{
1454 return BFA_STATUS_OK;
1455}
1456
1457/**
1458 * Create a new VF instance.
1459 *
1460 * A new VF is created using the given VF configuration. A VF is identified
1461 * by VF id. No duplicate VF creation is allowed with the same VF id. Once
1462 * a VF is created, VF is automatically started after link initialization
1463 * and EVFP exchange is completed.
1464 *
1465 * param[in] vf - FCS vf data structure. Memory is
1466 * allocated by caller (driver)
1467 * param[in] fcs - FCS module
1468 * param[in] vf_cfg - VF configuration
1469 * param[in] vf_drv - Opaque handle back to the driver's
1470 * virtual vf structure
1471 *
1472 * retval BFA_STATUS_OK VF creation is successful
1473 * retval BFA_STATUS_FAILED VF creation failed
1474 * retval BFA_STATUS_EEXIST A VF exists with the given vf_id
1475 */
1476bfa_status_t
1477bfa_fcs_vf_create(bfa_fcs_vf_t *vf, struct bfa_fcs_s *fcs, u16 vf_id,
1478 struct bfa_lport_cfg_s *port_cfg, struct bfad_vf_s *vf_drv)
1479{
1480 bfa_trc(fcs, vf_id);
1481 return BFA_STATUS_OK;
1482}
1483
1484/**
1485 * Use this function to delete a BFA VF object. VF object should
1486 * be stopped before this function call.
1487 *
1488 * param[in] vf - pointer to bfa_vf_t.
1489 *
1490 * retval BFA_STATUS_OK On vf deletion success
1491 * retval BFA_STATUS_BUSY VF is not in a stopped state
1492 * retval BFA_STATUS_INPROGRESS VF deletion in in progress
1493 */
1494bfa_status_t
1495bfa_fcs_vf_delete(bfa_fcs_vf_t *vf)
1496{
1497 bfa_trc(vf->fcs, vf->vf_id);
1498 return BFA_STATUS_OK;
1499}
1500
1501
1502/**
1503 * Returns attributes of the given VF.
1504 *
1505 * param[in] vf pointer to bfa_vf_t.
1506 * param[out] vf_attr vf attributes returned
1507 *
1508 * return None
1509 */
1510void
1511bfa_fcs_vf_get_attr(bfa_fcs_vf_t *vf, struct bfa_vf_attr_s *vf_attr)
1512{
1513 bfa_trc(vf->fcs, vf->vf_id);
1514}
1515
1516/**
1517 * Return statistics associated with the given vf.
1518 *
1519 * param[in] vf pointer to bfa_vf_t.
1520 * param[out] vf_stats vf statistics returned
1521 *
1522 * @return None
1523 */
1524void
1525bfa_fcs_vf_get_stats(bfa_fcs_vf_t *vf, struct bfa_vf_stats_s *vf_stats)
1526{
1527 bfa_os_memcpy(vf_stats, &vf->stats, sizeof(struct bfa_vf_stats_s));
1528}
1529
1530/**
1531 * clear statistics associated with the given vf.
1532 *
1533 * param[in] vf pointer to bfa_vf_t.
1534 *
1535 * @return None
1536 */
1537void
1538bfa_fcs_vf_clear_stats(bfa_fcs_vf_t *vf)
1539{
1540 bfa_os_memset(&vf->stats, 0, sizeof(struct bfa_vf_stats_s));
1541}
1542
1543/**
1544 * Returns FCS vf structure for a given vf_id. 1421 * Returns FCS vf structure for a given vf_id.
1545 * 1422 *
1546 * param[in] vf_id - VF_ID 1423 * param[in] vf_id - VF_ID
@@ -1558,81 +1435,7 @@ bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1558 return NULL; 1435 return NULL;
1559} 1436}
1560 1437
1561/** 1438/*
1562 * Return the list of VFs configured.
1563 *
1564 * param[in] fcs fcs module instance
1565 * param[out] vf_ids returned list of vf_ids
1566 * param[in,out] nvfs in:size of vf_ids array,
1567 * out:total elements present,
1568 * actual elements returned is limited by the size
1569 *
1570 * return Driver VF structure
1571 */
1572void
1573bfa_fcs_vf_list(struct bfa_fcs_s *fcs, u16 *vf_ids, int *nvfs)
1574{
1575 bfa_trc(fcs, *nvfs);
1576}
1577
1578/**
1579 * Return the list of all VFs visible from fabric.
1580 *
1581 * param[in] fcs fcs module instance
1582 * param[out] vf_ids returned list of vf_ids
1583 * param[in,out] nvfs in:size of vf_ids array,
1584 * out:total elements present,
1585 * actual elements returned is limited by the size
1586 *
1587 * return Driver VF structure
1588 */
1589void
1590bfa_fcs_vf_list_all(struct bfa_fcs_s *fcs, u16 *vf_ids, int *nvfs)
1591{
1592 bfa_trc(fcs, *nvfs);
1593}
1594
1595/**
1596 * Return the list of local logical ports present in the given VF.
1597 *
1598 * param[in] vf vf for which logical ports are returned
1599 * param[out] lpwwn returned logical port wwn list
1600 * param[in,out] nlports in:size of lpwwn list;
1601 * out:total elements present,
1602 * actual elements returned is limited by the size
1603 */
1604void
1605bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1606{
1607 struct list_head *qe;
1608 struct bfa_fcs_vport_s *vport;
1609 int i;
1610 struct bfa_fcs_s *fcs;
1611
1612 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1613 return;
1614
1615 fcs = vf->fcs;
1616
1617 bfa_trc(fcs, vf->vf_id);
1618 bfa_trc(fcs, (u32) *nlports);
1619
1620 i = 0;
1621 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1622
1623 list_for_each(qe, &vf->vport_q) {
1624 if (i >= *nlports)
1625 break;
1626
1627 vport = (struct bfa_fcs_vport_s *) qe;
1628 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1629 }
1630
1631 bfa_trc(fcs, i);
1632 *nlports = i;
1633}
1634
1635/**
1636 * BFA FCS PPORT ( physical port) 1439 * BFA FCS PPORT ( physical port)
1637 */ 1440 */
1638static void 1441static void
@@ -1662,11 +1465,11 @@ bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1662 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs); 1465 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1663} 1466}
1664 1467
1665/** 1468/*
1666 * BFA FCS UF ( Unsolicited Frames) 1469 * BFA FCS UF ( Unsolicited Frames)
1667 */ 1470 */
1668 1471
1669/** 1472/*
1670 * BFA callback for unsolicited frame receive handler. 1473 * BFA callback for unsolicited frame receive handler.
1671 * 1474 *
1672 * @param[in] cbarg callback arg for receive handler 1475 * @param[in] cbarg callback arg for receive handler
@@ -1683,7 +1486,7 @@ bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1683 struct fc_vft_s *vft; 1486 struct fc_vft_s *vft;
1684 struct bfa_fcs_fabric_s *fabric; 1487 struct bfa_fcs_fabric_s *fabric;
1685 1488
1686 /** 1489 /*
1687 * check for VFT header 1490 * check for VFT header
1688 */ 1491 */
1689 if (fchs->routing == FC_RTG_EXT_HDR && 1492 if (fchs->routing == FC_RTG_EXT_HDR &&
@@ -1695,7 +1498,7 @@ bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1695 else 1498 else
1696 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id); 1499 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1697 1500
1698 /** 1501 /*
1699 * drop frame if vfid is unknown 1502 * drop frame if vfid is unknown
1700 */ 1503 */
1701 if (!fabric) { 1504 if (!fabric) {
@@ -1705,7 +1508,7 @@ bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1705 return; 1508 return;
1706 } 1509 }
1707 1510
1708 /** 1511 /*
1709 * skip vft header 1512 * skip vft header
1710 */ 1513 */
1711 fchs = (struct fchs_s *) (vft + 1); 1514 fchs = (struct fchs_s *) (vft + 1);
diff --git a/drivers/scsi/bfa/bfa_fcs.h b/drivers/scsi/bfa/bfa_fcs.h
index d75045df1e7e..9cb6a55977c3 100644
--- a/drivers/scsi/bfa/bfa_fcs.h
+++ b/drivers/scsi/bfa/bfa_fcs.h
@@ -196,7 +196,7 @@ struct bfa_fcs_fabric_s {
196#define bfa_fcs_fabric_is_switched(__f) \ 196#define bfa_fcs_fabric_is_switched(__f) \
197 ((__f)->fab_type == BFA_FCS_FABRIC_SWITCHED) 197 ((__f)->fab_type == BFA_FCS_FABRIC_SWITCHED)
198 198
199/** 199/*
200 * The design calls for a single implementation of base fabric and vf. 200 * The design calls for a single implementation of base fabric and vf.
201 */ 201 */
202#define bfa_fcs_vf_t struct bfa_fcs_fabric_s 202#define bfa_fcs_vf_t struct bfa_fcs_fabric_s
@@ -216,7 +216,7 @@ struct bfa_fcs_fabric_s;
216 216
217#define bfa_fcs_lport_t struct bfa_fcs_lport_s 217#define bfa_fcs_lport_t struct bfa_fcs_lport_s
218 218
219/** 219/*
220 * Symbolic Name related defines 220 * Symbolic Name related defines
221 * Total bytes 255. 221 * Total bytes 255.
222 * Physical Port's symbolic name 128 bytes. 222 * Physical Port's symbolic name 128 bytes.
@@ -239,7 +239,7 @@ struct bfa_fcs_fabric_s;
239#define BFA_FCS_PORT_SYMBNAME_OSINFO_SZ 48 239#define BFA_FCS_PORT_SYMBNAME_OSINFO_SZ 48
240#define BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ 16 240#define BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ 16
241 241
242/** 242/*
243 * Get FC port ID for a logical port. 243 * Get FC port ID for a logical port.
244 */ 244 */
245#define bfa_fcs_lport_get_fcid(_lport) ((_lport)->pid) 245#define bfa_fcs_lport_get_fcid(_lport) ((_lport)->pid)
@@ -262,7 +262,7 @@ bfa_fcs_lport_get_drvport(struct bfa_fcs_lport_s *port)
262#define bfa_fcs_lport_get_fabric_ipaddr(_lport) \ 262#define bfa_fcs_lport_get_fabric_ipaddr(_lport) \
263 ((_lport)->fabric->fabric_ip_addr) 263 ((_lport)->fabric->fabric_ip_addr)
264 264
265/** 265/*
266 * bfa fcs port public functions 266 * bfa fcs port public functions
267 */ 267 */
268 268
@@ -342,7 +342,7 @@ struct bfa_fcs_vport_s {
342#define bfa_fcs_vport_get_port(vport) \ 342#define bfa_fcs_vport_get_port(vport) \
343 ((struct bfa_fcs_lport_s *)(&vport->port)) 343 ((struct bfa_fcs_lport_s *)(&vport->port))
344 344
345/** 345/*
346 * bfa fcs vport public functions 346 * bfa fcs vport public functions
347 */ 347 */
348bfa_status_t bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, 348bfa_status_t bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport,
@@ -393,7 +393,7 @@ struct bfa_fcs_rpf_s {
393 enum bfa_port_speed rpsc_speed; 393 enum bfa_port_speed rpsc_speed;
394 /* Current Speed from RPSC. O if RPSC fails */ 394 /* Current Speed from RPSC. O if RPSC fails */
395 enum bfa_port_speed assigned_speed; 395 enum bfa_port_speed assigned_speed;
396 /** 396 /*
397 * Speed assigned by the user. will be used if RPSC is 397 * Speed assigned by the user. will be used if RPSC is
398 * not supported by the rport. 398 * not supported by the rport.
399 */ 399 */
@@ -434,7 +434,7 @@ bfa_fcs_rport_get_halrport(struct bfa_fcs_rport_s *rport)
434 return rport->bfa_rport; 434 return rport->bfa_rport;
435} 435}
436 436
437/** 437/*
438 * bfa fcs rport API functions 438 * bfa fcs rport API functions
439 */ 439 */
440bfa_status_t bfa_fcs_rport_add(struct bfa_fcs_lport_s *port, wwn_t *pwwn, 440bfa_status_t bfa_fcs_rport_add(struct bfa_fcs_lport_s *port, wwn_t *pwwn,
@@ -573,7 +573,7 @@ bfa_fcs_itnim_get_halitn(struct bfa_fcs_itnim_s *itnim)
573 return itnim->bfa_itnim; 573 return itnim->bfa_itnim;
574} 574}
575 575
576/** 576/*
577 * bfa fcs FCP Initiator mode API functions 577 * bfa fcs FCP Initiator mode API functions
578 */ 578 */
579void bfa_fcs_itnim_get_attr(struct bfa_fcs_itnim_s *itnim, 579void bfa_fcs_itnim_get_attr(struct bfa_fcs_itnim_s *itnim,
@@ -677,22 +677,9 @@ void bfa_fcs_exit(struct bfa_fcs_s *fcs);
677void bfa_fcs_trc_init(struct bfa_fcs_s *fcs, struct bfa_trc_mod_s *trcmod); 677void bfa_fcs_trc_init(struct bfa_fcs_s *fcs, struct bfa_trc_mod_s *trcmod);
678void bfa_fcs_start(struct bfa_fcs_s *fcs); 678void bfa_fcs_start(struct bfa_fcs_s *fcs);
679 679
680/** 680/*
681 * bfa fcs vf public functions 681 * bfa fcs vf public functions
682 */ 682 */
683bfa_status_t bfa_fcs_vf_mode_enable(struct bfa_fcs_s *fcs, u16 vf_id);
684bfa_status_t bfa_fcs_vf_mode_disable(struct bfa_fcs_s *fcs);
685bfa_status_t bfa_fcs_vf_create(bfa_fcs_vf_t *vf, struct bfa_fcs_s *fcs,
686 u16 vf_id, struct bfa_lport_cfg_s *port_cfg,
687 struct bfad_vf_s *vf_drv);
688bfa_status_t bfa_fcs_vf_delete(bfa_fcs_vf_t *vf);
689void bfa_fcs_vf_list(struct bfa_fcs_s *fcs, u16 *vf_ids, int *nvfs);
690void bfa_fcs_vf_list_all(struct bfa_fcs_s *fcs, u16 *vf_ids, int *nvfs);
691void bfa_fcs_vf_get_attr(bfa_fcs_vf_t *vf, struct bfa_vf_attr_s *vf_attr);
692void bfa_fcs_vf_get_stats(bfa_fcs_vf_t *vf,
693 struct bfa_vf_stats_s *vf_stats);
694void bfa_fcs_vf_clear_stats(bfa_fcs_vf_t *vf);
695void bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t vpwwn[], int *nports);
696bfa_fcs_vf_t *bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id); 683bfa_fcs_vf_t *bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id);
697u16 bfa_fcs_fabric_vport_count(struct bfa_fcs_fabric_s *fabric); 684u16 bfa_fcs_fabric_vport_count(struct bfa_fcs_fabric_s *fabric);
698 685
@@ -729,11 +716,11 @@ u16 bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric);
729void bfa_fcs_uf_attach(struct bfa_fcs_s *fcs); 716void bfa_fcs_uf_attach(struct bfa_fcs_s *fcs);
730void bfa_fcs_port_attach(struct bfa_fcs_s *fcs); 717void bfa_fcs_port_attach(struct bfa_fcs_s *fcs);
731 718
732/** 719/*
733 * BFA FCS callback interfaces 720 * BFA FCS callback interfaces
734 */ 721 */
735 722
736/** 723/*
737 * fcb Main fcs callbacks 724 * fcb Main fcs callbacks
738 */ 725 */
739 726
@@ -742,7 +729,7 @@ struct bfad_vf_s;
742struct bfad_vport_s; 729struct bfad_vport_s;
743struct bfad_rport_s; 730struct bfad_rport_s;
744 731
745/** 732/*
746 * lport callbacks 733 * lport callbacks
747 */ 734 */
748struct bfad_port_s *bfa_fcb_lport_new(struct bfad_s *bfad, 735struct bfad_port_s *bfa_fcb_lport_new(struct bfad_s *bfad,
@@ -754,19 +741,19 @@ void bfa_fcb_lport_delete(struct bfad_s *bfad, enum bfa_lport_role roles,
754 struct bfad_vf_s *vf_drv, 741 struct bfad_vf_s *vf_drv,
755 struct bfad_vport_s *vp_drv); 742 struct bfad_vport_s *vp_drv);
756 743
757/** 744/*
758 * vport callbacks 745 * vport callbacks
759 */ 746 */
760void bfa_fcb_pbc_vport_create(struct bfad_s *bfad, struct bfi_pbc_vport_s); 747void bfa_fcb_pbc_vport_create(struct bfad_s *bfad, struct bfi_pbc_vport_s);
761 748
762/** 749/*
763 * rport callbacks 750 * rport callbacks
764 */ 751 */
765bfa_status_t bfa_fcb_rport_alloc(struct bfad_s *bfad, 752bfa_status_t bfa_fcb_rport_alloc(struct bfad_s *bfad,
766 struct bfa_fcs_rport_s **rport, 753 struct bfa_fcs_rport_s **rport,
767 struct bfad_rport_s **rport_drv); 754 struct bfad_rport_s **rport_drv);
768 755
769/** 756/*
770 * itnim callbacks 757 * itnim callbacks
771 */ 758 */
772void bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim, 759void bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
diff --git a/drivers/scsi/bfa/bfa_fcs_fcpim.c b/drivers/scsi/bfa/bfa_fcs_fcpim.c
index 569dfefab70d..9662bcdeb41d 100644
--- a/drivers/scsi/bfa/bfa_fcs_fcpim.c
+++ b/drivers/scsi/bfa/bfa_fcs_fcpim.c
@@ -15,7 +15,7 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * fcpim.c - FCP initiator mode i-t nexus state machine 19 * fcpim.c - FCP initiator mode i-t nexus state machine
20 */ 20 */
21 21
@@ -38,7 +38,7 @@ static void bfa_fcs_itnim_prli_response(void *fcsarg,
38 bfa_status_t req_status, u32 rsp_len, 38 bfa_status_t req_status, u32 rsp_len,
39 u32 resid_len, struct fchs_s *rsp_fchs); 39 u32 resid_len, struct fchs_s *rsp_fchs);
40 40
41/** 41/*
42 * fcs_itnim_sm FCS itnim state machine events 42 * fcs_itnim_sm FCS itnim state machine events
43 */ 43 */
44 44
@@ -84,7 +84,7 @@ static struct bfa_sm_table_s itnim_sm_table[] = {
84 {BFA_SM(bfa_fcs_itnim_sm_initiator), BFA_ITNIM_INITIATIOR}, 84 {BFA_SM(bfa_fcs_itnim_sm_initiator), BFA_ITNIM_INITIATIOR},
85}; 85};
86 86
87/** 87/*
88 * fcs_itnim_sm FCS itnim state machine 88 * fcs_itnim_sm FCS itnim state machine
89 */ 89 */
90 90
@@ -494,11 +494,11 @@ bfa_fcs_itnim_free(struct bfa_fcs_itnim_s *itnim)
494 494
495 495
496 496
497/** 497/*
498 * itnim_public FCS ITNIM public interfaces 498 * itnim_public FCS ITNIM public interfaces
499 */ 499 */
500 500
501/** 501/*
502 * Called by rport when a new rport is created. 502 * Called by rport when a new rport is created.
503 * 503 *
504 * @param[in] rport - remote port. 504 * @param[in] rport - remote port.
@@ -554,7 +554,7 @@ bfa_fcs_itnim_create(struct bfa_fcs_rport_s *rport)
554 return itnim; 554 return itnim;
555} 555}
556 556
557/** 557/*
558 * Called by rport to delete the instance of FCPIM. 558 * Called by rport to delete the instance of FCPIM.
559 * 559 *
560 * @param[in] rport - remote port. 560 * @param[in] rport - remote port.
@@ -566,7 +566,7 @@ bfa_fcs_itnim_delete(struct bfa_fcs_itnim_s *itnim)
566 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_DELETE); 566 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_DELETE);
567} 567}
568 568
569/** 569/*
570 * Notification from rport that PLOGI is complete to initiate FC-4 session. 570 * Notification from rport that PLOGI is complete to initiate FC-4 session.
571 */ 571 */
572void 572void
@@ -586,7 +586,7 @@ bfa_fcs_itnim_rport_online(struct bfa_fcs_itnim_s *itnim)
586 } 586 }
587} 587}
588 588
589/** 589/*
590 * Called by rport to handle a remote device offline. 590 * Called by rport to handle a remote device offline.
591 */ 591 */
592void 592void
@@ -596,7 +596,7 @@ bfa_fcs_itnim_rport_offline(struct bfa_fcs_itnim_s *itnim)
596 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_OFFLINE); 596 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_OFFLINE);
597} 597}
598 598
599/** 599/*
600 * Called by rport when remote port is known to be an initiator from 600 * Called by rport when remote port is known to be an initiator from
601 * PRLI received. 601 * PRLI received.
602 */ 602 */
@@ -608,7 +608,7 @@ bfa_fcs_itnim_is_initiator(struct bfa_fcs_itnim_s *itnim)
608 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_INITIATOR); 608 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_INITIATOR);
609} 609}
610 610
611/** 611/*
612 * Called by rport to check if the itnim is online. 612 * Called by rport to check if the itnim is online.
613 */ 613 */
614bfa_status_t 614bfa_status_t
@@ -625,7 +625,7 @@ bfa_fcs_itnim_get_online_state(struct bfa_fcs_itnim_s *itnim)
625 } 625 }
626} 626}
627 627
628/** 628/*
629 * BFA completion callback for bfa_itnim_online(). 629 * BFA completion callback for bfa_itnim_online().
630 */ 630 */
631void 631void
@@ -637,7 +637,7 @@ bfa_cb_itnim_online(void *cbarg)
637 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HCB_ONLINE); 637 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HCB_ONLINE);
638} 638}
639 639
640/** 640/*
641 * BFA completion callback for bfa_itnim_offline(). 641 * BFA completion callback for bfa_itnim_offline().
642 */ 642 */
643void 643void
@@ -649,7 +649,7 @@ bfa_cb_itnim_offline(void *cb_arg)
649 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HCB_OFFLINE); 649 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HCB_OFFLINE);
650} 650}
651 651
652/** 652/*
653 * Mark the beginning of PATH TOV handling. IO completion callbacks 653 * Mark the beginning of PATH TOV handling. IO completion callbacks
654 * are still pending. 654 * are still pending.
655 */ 655 */
@@ -661,7 +661,7 @@ bfa_cb_itnim_tov_begin(void *cb_arg)
661 bfa_trc(itnim->fcs, itnim->rport->pwwn); 661 bfa_trc(itnim->fcs, itnim->rport->pwwn);
662} 662}
663 663
664/** 664/*
665 * Mark the end of PATH TOV handling. All pending IOs are already cleaned up. 665 * Mark the end of PATH TOV handling. All pending IOs are already cleaned up.
666 */ 666 */
667void 667void
@@ -674,7 +674,7 @@ bfa_cb_itnim_tov(void *cb_arg)
674 itnim_drv->state = ITNIM_STATE_TIMEOUT; 674 itnim_drv->state = ITNIM_STATE_TIMEOUT;
675} 675}
676 676
677/** 677/*
678 * BFA notification to FCS/driver for second level error recovery. 678 * BFA notification to FCS/driver for second level error recovery.
679 * 679 *
680 * Atleast one I/O request has timedout and target is unresponsive to 680 * Atleast one I/O request has timedout and target is unresponsive to
@@ -736,7 +736,7 @@ bfa_fcs_itnim_stats_get(struct bfa_fcs_lport_s *port, wwn_t rpwwn,
736 if (itnim == NULL) 736 if (itnim == NULL)
737 return BFA_STATUS_NO_FCPIM_NEXUS; 737 return BFA_STATUS_NO_FCPIM_NEXUS;
738 738
739 bfa_os_memcpy(stats, &itnim->stats, sizeof(struct bfa_itnim_stats_s)); 739 memcpy(stats, &itnim->stats, sizeof(struct bfa_itnim_stats_s));
740 740
741 return BFA_STATUS_OK; 741 return BFA_STATUS_OK;
742} 742}
@@ -753,7 +753,7 @@ bfa_fcs_itnim_stats_clear(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
753 if (itnim == NULL) 753 if (itnim == NULL)
754 return BFA_STATUS_NO_FCPIM_NEXUS; 754 return BFA_STATUS_NO_FCPIM_NEXUS;
755 755
756 bfa_os_memset(&itnim->stats, 0, sizeof(struct bfa_itnim_stats_s)); 756 memset(&itnim->stats, 0, sizeof(struct bfa_itnim_stats_s));
757 return BFA_STATUS_OK; 757 return BFA_STATUS_OK;
758} 758}
759 759
diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
index b7aa23a3b1e8..de989fc158dd 100644
--- a/drivers/scsi/bfa/bfa_fcs_lport.c
+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -15,10 +15,6 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/**
19 * bfa_fcs_lport.c BFA FCS port
20 */
21
22#include "bfa_fcs.h" 18#include "bfa_fcs.h"
23#include "bfa_fcbuild.h" 19#include "bfa_fcbuild.h"
24#include "bfa_fc.h" 20#include "bfa_fc.h"
@@ -26,10 +22,6 @@
26 22
27BFA_TRC_FILE(FCS, PORT); 23BFA_TRC_FILE(FCS, PORT);
28 24
29/**
30 * Forward declarations
31 */
32
33static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, 25static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
34 struct fchs_s *rx_fchs, u8 reason_code, 26 struct fchs_s *rx_fchs, u8 reason_code,
35 u8 reason_code_expl); 27 u8 reason_code_expl);
@@ -72,7 +64,7 @@ static struct {
72 bfa_fcs_lport_n2n_offline}, 64 bfa_fcs_lport_n2n_offline},
73 }; 65 };
74 66
75/** 67/*
76 * fcs_port_sm FCS logical port state machine 68 * fcs_port_sm FCS logical port state machine
77 */ 69 */
78 70
@@ -240,7 +232,7 @@ bfa_fcs_lport_sm_deleting(
240 } 232 }
241} 233}
242 234
243/** 235/*
244 * fcs_port_pvt 236 * fcs_port_pvt
245 */ 237 */
246 238
@@ -272,7 +264,7 @@ bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
272 FC_MAX_PDUSZ, 0); 264 FC_MAX_PDUSZ, 0);
273} 265}
274 266
275/** 267/*
276 * Process incoming plogi from a remote port. 268 * Process incoming plogi from a remote port.
277 */ 269 */
278static void 270static void
@@ -303,7 +295,7 @@ bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
303 return; 295 return;
304 } 296 }
305 297
306 /** 298 /*
307 * Direct Attach P2P mode : verify address assigned by the r-port. 299 * Direct Attach P2P mode : verify address assigned by the r-port.
308 */ 300 */
309 if ((!bfa_fcs_fabric_is_switched(port->fabric)) && 301 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
@@ -319,12 +311,12 @@ bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
319 port->pid = rx_fchs->d_id; 311 port->pid = rx_fchs->d_id;
320 } 312 }
321 313
322 /** 314 /*
323 * First, check if we know the device by pwwn. 315 * First, check if we know the device by pwwn.
324 */ 316 */
325 rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name); 317 rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
326 if (rport) { 318 if (rport) {
327 /** 319 /*
328 * Direct Attach P2P mode : handle address assigned by r-port. 320 * Direct Attach P2P mode : handle address assigned by r-port.
329 */ 321 */
330 if ((!bfa_fcs_fabric_is_switched(port->fabric)) && 322 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
@@ -337,37 +329,37 @@ bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
337 return; 329 return;
338 } 330 }
339 331
340 /** 332 /*
341 * Next, lookup rport by PID. 333 * Next, lookup rport by PID.
342 */ 334 */
343 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id); 335 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
344 if (!rport) { 336 if (!rport) {
345 /** 337 /*
346 * Inbound PLOGI from a new device. 338 * Inbound PLOGI from a new device.
347 */ 339 */
348 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi); 340 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
349 return; 341 return;
350 } 342 }
351 343
352 /** 344 /*
353 * Rport is known only by PID. 345 * Rport is known only by PID.
354 */ 346 */
355 if (rport->pwwn) { 347 if (rport->pwwn) {
356 /** 348 /*
357 * This is a different device with the same pid. Old device 349 * This is a different device with the same pid. Old device
358 * disappeared. Send implicit LOGO to old device. 350 * disappeared. Send implicit LOGO to old device.
359 */ 351 */
360 bfa_assert(rport->pwwn != plogi->port_name); 352 bfa_assert(rport->pwwn != plogi->port_name);
361 bfa_fcs_rport_logo_imp(rport); 353 bfa_fcs_rport_logo_imp(rport);
362 354
363 /** 355 /*
364 * Inbound PLOGI from a new device (with old PID). 356 * Inbound PLOGI from a new device (with old PID).
365 */ 357 */
366 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi); 358 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
367 return; 359 return;
368 } 360 }
369 361
370 /** 362 /*
371 * PLOGI crossing each other. 363 * PLOGI crossing each other.
372 */ 364 */
373 bfa_assert(rport->pwwn == WWN_NULL); 365 bfa_assert(rport->pwwn == WWN_NULL);
@@ -479,12 +471,12 @@ static void
479bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port, 471bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
480 struct fc_rnid_general_topology_data_s *gen_topo_data) 472 struct fc_rnid_general_topology_data_s *gen_topo_data)
481{ 473{
482 bfa_os_memset(gen_topo_data, 0, 474 memset(gen_topo_data, 0,
483 sizeof(struct fc_rnid_general_topology_data_s)); 475 sizeof(struct fc_rnid_general_topology_data_s));
484 476
485 gen_topo_data->asso_type = bfa_os_htonl(RNID_ASSOCIATED_TYPE_HOST); 477 gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
486 gen_topo_data->phy_port_num = 0; /* @todo */ 478 gen_topo_data->phy_port_num = 0; /* @todo */
487 gen_topo_data->num_attached_nodes = bfa_os_htonl(1); 479 gen_topo_data->num_attached_nodes = cpu_to_be32(1);
488} 480}
489 481
490static void 482static void
@@ -598,10 +590,10 @@ bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
598 590
599 591
600 592
601/** 593/*
602 * fcs_lport_api BFA FCS port API 594 * fcs_lport_api BFA FCS port API
603 */ 595 */
604/** 596/*
605 * Module initialization 597 * Module initialization
606 */ 598 */
607void 599void
@@ -610,7 +602,7 @@ bfa_fcs_lport_modinit(struct bfa_fcs_s *fcs)
610 602
611} 603}
612 604
613/** 605/*
614 * Module cleanup 606 * Module cleanup
615 */ 607 */
616void 608void
@@ -619,7 +611,7 @@ bfa_fcs_lport_modexit(struct bfa_fcs_s *fcs)
619 bfa_fcs_modexit_comp(fcs); 611 bfa_fcs_modexit_comp(fcs);
620} 612}
621 613
622/** 614/*
623 * Unsolicited frame receive handling. 615 * Unsolicited frame receive handling.
624 */ 616 */
625void 617void
@@ -637,7 +629,7 @@ bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
637 return; 629 return;
638 } 630 }
639 631
640 /** 632 /*
641 * First, handle ELSs that donot require a login. 633 * First, handle ELSs that donot require a login.
642 */ 634 */
643 /* 635 /*
@@ -673,7 +665,7 @@ bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
673 bfa_fcs_lport_abts_acc(lport, fchs); 665 bfa_fcs_lport_abts_acc(lport, fchs);
674 return; 666 return;
675 } 667 }
676 /** 668 /*
677 * look for a matching remote port ID 669 * look for a matching remote port ID
678 */ 670 */
679 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid); 671 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
@@ -686,7 +678,7 @@ bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
686 return; 678 return;
687 } 679 }
688 680
689 /** 681 /*
690 * Only handles ELS frames for now. 682 * Only handles ELS frames for now.
691 */ 683 */
692 if (fchs->type != FC_TYPE_ELS) { 684 if (fchs->type != FC_TYPE_ELS) {
@@ -702,20 +694,20 @@ bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
702 } 694 }
703 695
704 if (els_cmd->els_code == FC_ELS_LOGO) { 696 if (els_cmd->els_code == FC_ELS_LOGO) {
705 /** 697 /*
706 * @todo Handle LOGO frames received. 698 * @todo Handle LOGO frames received.
707 */ 699 */
708 return; 700 return;
709 } 701 }
710 702
711 if (els_cmd->els_code == FC_ELS_PRLI) { 703 if (els_cmd->els_code == FC_ELS_PRLI) {
712 /** 704 /*
713 * @todo Handle PRLI frames received. 705 * @todo Handle PRLI frames received.
714 */ 706 */
715 return; 707 return;
716 } 708 }
717 709
718 /** 710 /*
719 * Unhandled ELS frames. Send a LS_RJT. 711 * Unhandled ELS frames. Send a LS_RJT.
720 */ 712 */
721 bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP, 713 bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
@@ -723,7 +715,7 @@ bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
723 715
724} 716}
725 717
726/** 718/*
727 * PID based Lookup for a R-Port in the Port R-Port Queue 719 * PID based Lookup for a R-Port in the Port R-Port Queue
728 */ 720 */
729struct bfa_fcs_rport_s * 721struct bfa_fcs_rport_s *
@@ -742,7 +734,7 @@ bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
742 return NULL; 734 return NULL;
743} 735}
744 736
745/** 737/*
746 * PWWN based Lookup for a R-Port in the Port R-Port Queue 738 * PWWN based Lookup for a R-Port in the Port R-Port Queue
747 */ 739 */
748struct bfa_fcs_rport_s * 740struct bfa_fcs_rport_s *
@@ -761,7 +753,7 @@ bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
761 return NULL; 753 return NULL;
762} 754}
763 755
764/** 756/*
765 * NWWN based Lookup for a R-Port in the Port R-Port Queue 757 * NWWN based Lookup for a R-Port in the Port R-Port Queue
766 */ 758 */
767struct bfa_fcs_rport_s * 759struct bfa_fcs_rport_s *
@@ -780,7 +772,7 @@ bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t nwwn)
780 return NULL; 772 return NULL;
781} 773}
782 774
783/** 775/*
784 * Called by rport module when new rports are discovered. 776 * Called by rport module when new rports are discovered.
785 */ 777 */
786void 778void
@@ -792,7 +784,7 @@ bfa_fcs_lport_add_rport(
792 port->num_rports++; 784 port->num_rports++;
793} 785}
794 786
795/** 787/*
796 * Called by rport module to when rports are deleted. 788 * Called by rport module to when rports are deleted.
797 */ 789 */
798void 790void
@@ -807,7 +799,7 @@ bfa_fcs_lport_del_rport(
807 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT); 799 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
808} 800}
809 801
810/** 802/*
811 * Called by fabric for base port when fabric login is complete. 803 * Called by fabric for base port when fabric login is complete.
812 * Called by vport for virtual ports when FDISC is complete. 804 * Called by vport for virtual ports when FDISC is complete.
813 */ 805 */
@@ -817,7 +809,7 @@ bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
817 bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE); 809 bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
818} 810}
819 811
820/** 812/*
821 * Called by fabric for base port when fabric goes offline. 813 * Called by fabric for base port when fabric goes offline.
822 * Called by vport for virtual ports when virtual port becomes offline. 814 * Called by vport for virtual ports when virtual port becomes offline.
823 */ 815 */
@@ -827,7 +819,7 @@ bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
827 bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE); 819 bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
828} 820}
829 821
830/** 822/*
831 * Called by fabric to delete base lport and associated resources. 823 * Called by fabric to delete base lport and associated resources.
832 * 824 *
833 * Called by vport to delete lport and associated resources. Should call 825 * Called by vport to delete lport and associated resources. Should call
@@ -839,7 +831,7 @@ bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
839 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE); 831 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
840} 832}
841 833
842/** 834/*
843 * Return TRUE if port is online, else return FALSE 835 * Return TRUE if port is online, else return FALSE
844 */ 836 */
845bfa_boolean_t 837bfa_boolean_t
@@ -848,7 +840,7 @@ bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
848 return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online); 840 return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
849} 841}
850 842
851/** 843/*
852 * Attach time initialization of logical ports. 844 * Attach time initialization of logical ports.
853 */ 845 */
854void 846void
@@ -865,7 +857,7 @@ bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
865 lport->num_rports = 0; 857 lport->num_rports = 0;
866} 858}
867 859
868/** 860/*
869 * Logical port initialization of base or virtual port. 861 * Logical port initialization of base or virtual port.
870 * Called by fabric for base port or by vport for virtual ports. 862 * Called by fabric for base port or by vport for virtual ports.
871 */ 863 */
@@ -878,7 +870,7 @@ bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
878 struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad; 870 struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
879 char lpwwn_buf[BFA_STRING_32]; 871 char lpwwn_buf[BFA_STRING_32];
880 872
881 bfa_os_assign(lport->port_cfg, *port_cfg); 873 lport->port_cfg = *port_cfg;
882 874
883 lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport, 875 lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
884 lport->port_cfg.roles, 876 lport->port_cfg.roles,
@@ -894,7 +886,7 @@ bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
894 bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE); 886 bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
895} 887}
896 888
897/** 889/*
898 * fcs_lport_api 890 * fcs_lport_api
899 */ 891 */
900 892
@@ -934,11 +926,11 @@ bfa_fcs_lport_get_attr(
934 } 926 }
935} 927}
936 928
937/** 929/*
938 * bfa_fcs_lport_fab port fab functions 930 * bfa_fcs_lport_fab port fab functions
939 */ 931 */
940 932
941/** 933/*
942 * Called by port to initialize fabric services of the base port. 934 * Called by port to initialize fabric services of the base port.
943 */ 935 */
944static void 936static void
@@ -949,7 +941,7 @@ bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
949 bfa_fcs_lport_ms_init(port); 941 bfa_fcs_lport_ms_init(port);
950} 942}
951 943
952/** 944/*
953 * Called by port to notify transition to online state. 945 * Called by port to notify transition to online state.
954 */ 946 */
955static void 947static void
@@ -959,7 +951,7 @@ bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
959 bfa_fcs_lport_scn_online(port); 951 bfa_fcs_lport_scn_online(port);
960} 952}
961 953
962/** 954/*
963 * Called by port to notify transition to offline state. 955 * Called by port to notify transition to offline state.
964 */ 956 */
965static void 957static void
@@ -970,11 +962,11 @@ bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
970 bfa_fcs_lport_ms_offline(port); 962 bfa_fcs_lport_ms_offline(port);
971} 963}
972 964
973/** 965/*
974 * bfa_fcs_lport_n2n functions 966 * bfa_fcs_lport_n2n functions
975 */ 967 */
976 968
977/** 969/*
978 * Called by fcs/port to initialize N2N topology. 970 * Called by fcs/port to initialize N2N topology.
979 */ 971 */
980static void 972static void
@@ -982,7 +974,7 @@ bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
982{ 974{
983} 975}
984 976
985/** 977/*
986 * Called by fcs/port to notify transition to online state. 978 * Called by fcs/port to notify transition to online state.
987 */ 979 */
988static void 980static void
@@ -1006,7 +998,7 @@ bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
1006 ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn, 998 ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
1007 sizeof(wwn_t)) > 0) { 999 sizeof(wwn_t)) > 0) {
1008 port->pid = N2N_LOCAL_PID; 1000 port->pid = N2N_LOCAL_PID;
1009 /** 1001 /*
1010 * First, check if we know the device by pwwn. 1002 * First, check if we know the device by pwwn.
1011 */ 1003 */
1012 rport = bfa_fcs_lport_get_rport_by_pwwn(port, 1004 rport = bfa_fcs_lport_get_rport_by_pwwn(port,
@@ -1035,7 +1027,7 @@ bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
1035 } 1027 }
1036} 1028}
1037 1029
1038/** 1030/*
1039 * Called by fcs/port to notify transition to offline state. 1031 * Called by fcs/port to notify transition to offline state.
1040 */ 1032 */
1041static void 1033static void
@@ -1094,11 +1086,11 @@ static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1094 struct bfa_fcs_fdmi_hba_attr_s *hba_attr); 1086 struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
1095static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi, 1087static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1096 struct bfa_fcs_fdmi_port_attr_s *port_attr); 1088 struct bfa_fcs_fdmi_port_attr_s *port_attr);
1097/** 1089/*
1098 * fcs_fdmi_sm FCS FDMI state machine 1090 * fcs_fdmi_sm FCS FDMI state machine
1099 */ 1091 */
1100 1092
1101/** 1093/*
1102 * FDMI State Machine events 1094 * FDMI State Machine events
1103 */ 1095 */
1104enum port_fdmi_event { 1096enum port_fdmi_event {
@@ -1143,7 +1135,7 @@ static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1143static void bfa_fcs_lport_fdmi_sm_disabled( 1135static void bfa_fcs_lport_fdmi_sm_disabled(
1144 struct bfa_fcs_lport_fdmi_s *fdmi, 1136 struct bfa_fcs_lport_fdmi_s *fdmi,
1145 enum port_fdmi_event event); 1137 enum port_fdmi_event event);
1146/** 1138/*
1147 * Start in offline state - awaiting MS to send start. 1139 * Start in offline state - awaiting MS to send start.
1148 */ 1140 */
1149static void 1141static void
@@ -1510,7 +1502,7 @@ bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1510 bfa_sm_fault(port->fcs, event); 1502 bfa_sm_fault(port->fcs, event);
1511 } 1503 }
1512} 1504}
1513/** 1505/*
1514 * FDMI is disabled state. 1506 * FDMI is disabled state.
1515 */ 1507 */
1516static void 1508static void
@@ -1525,7 +1517,7 @@ bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
1525 /* No op State. It can only be enabled at Driver Init. */ 1517 /* No op State. It can only be enabled at Driver Init. */
1526} 1518}
1527 1519
1528/** 1520/*
1529* RHBA : Register HBA Attributes. 1521* RHBA : Register HBA Attributes.
1530 */ 1522 */
1531static void 1523static void
@@ -1549,7 +1541,7 @@ bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1549 fdmi->fcxp = fcxp; 1541 fdmi->fcxp = fcxp;
1550 1542
1551 pyld = bfa_fcxp_get_reqbuf(fcxp); 1543 pyld = bfa_fcxp_get_reqbuf(fcxp);
1552 bfa_os_memset(pyld, 0, FC_MAX_PDUSZ); 1544 memset(pyld, 0, FC_MAX_PDUSZ);
1553 1545
1554 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port), 1546 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
1555 FDMI_RHBA); 1547 FDMI_RHBA);
@@ -1584,7 +1576,7 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1584 bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr); 1576 bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
1585 1577
1586 rhba->hba_id = bfa_fcs_lport_get_pwwn(port); 1578 rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
1587 rhba->port_list.num_ports = bfa_os_htonl(1); 1579 rhba->port_list.num_ports = cpu_to_be32(1);
1588 rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port); 1580 rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
1589 1581
1590 len = sizeof(rhba->hba_id) + sizeof(rhba->port_list); 1582 len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
@@ -1601,86 +1593,69 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1601 * Node Name 1593 * Node Name
1602 */ 1594 */
1603 attr = (struct fdmi_attr_s *) curr_ptr; 1595 attr = (struct fdmi_attr_s *) curr_ptr;
1604 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_NODENAME); 1596 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
1605 attr->len = sizeof(wwn_t); 1597 attr->len = sizeof(wwn_t);
1606 memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), attr->len); 1598 memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), attr->len);
1607 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1599 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1608 len += attr->len; 1600 len += attr->len;
1609 count++; 1601 count++;
1610 attr->len = 1602 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1611 bfa_os_htons(attr->len + sizeof(attr->type) +
1612 sizeof(attr->len)); 1603 sizeof(attr->len));
1613 1604
1614 /* 1605 /*
1615 * Manufacturer 1606 * Manufacturer
1616 */ 1607 */
1617 attr = (struct fdmi_attr_s *) curr_ptr; 1608 attr = (struct fdmi_attr_s *) curr_ptr;
1618 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_MANUFACTURER); 1609 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER);
1619 attr->len = (u16) strlen(fcs_hba_attr->manufacturer); 1610 attr->len = (u16) strlen(fcs_hba_attr->manufacturer);
1620 memcpy(attr->value, fcs_hba_attr->manufacturer, attr->len); 1611 memcpy(attr->value, fcs_hba_attr->manufacturer, attr->len);
1621 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1612 attr->len = fc_roundup(attr->len, sizeof(u32));
1622 *fields need
1623 *to be 4 byte
1624 *aligned */
1625 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1613 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1626 len += attr->len; 1614 len += attr->len;
1627 count++; 1615 count++;
1628 attr->len = 1616 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1629 bfa_os_htons(attr->len + sizeof(attr->type) +
1630 sizeof(attr->len)); 1617 sizeof(attr->len));
1631 1618
1632 /* 1619 /*
1633 * Serial Number 1620 * Serial Number
1634 */ 1621 */
1635 attr = (struct fdmi_attr_s *) curr_ptr; 1622 attr = (struct fdmi_attr_s *) curr_ptr;
1636 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_SERIALNUM); 1623 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM);
1637 attr->len = (u16) strlen(fcs_hba_attr->serial_num); 1624 attr->len = (u16) strlen(fcs_hba_attr->serial_num);
1638 memcpy(attr->value, fcs_hba_attr->serial_num, attr->len); 1625 memcpy(attr->value, fcs_hba_attr->serial_num, attr->len);
1639 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1626 attr->len = fc_roundup(attr->len, sizeof(u32));
1640 *fields need
1641 *to be 4 byte
1642 *aligned */
1643 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1627 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1644 len += attr->len; 1628 len += attr->len;
1645 count++; 1629 count++;
1646 attr->len = 1630 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1647 bfa_os_htons(attr->len + sizeof(attr->type) +
1648 sizeof(attr->len)); 1631 sizeof(attr->len));
1649 1632
1650 /* 1633 /*
1651 * Model 1634 * Model
1652 */ 1635 */
1653 attr = (struct fdmi_attr_s *) curr_ptr; 1636 attr = (struct fdmi_attr_s *) curr_ptr;
1654 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_MODEL); 1637 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL);
1655 attr->len = (u16) strlen(fcs_hba_attr->model); 1638 attr->len = (u16) strlen(fcs_hba_attr->model);
1656 memcpy(attr->value, fcs_hba_attr->model, attr->len); 1639 memcpy(attr->value, fcs_hba_attr->model, attr->len);
1657 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1640 attr->len = fc_roundup(attr->len, sizeof(u32));
1658 *fields need
1659 *to be 4 byte
1660 *aligned */
1661 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1641 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1662 len += attr->len; 1642 len += attr->len;
1663 count++; 1643 count++;
1664 attr->len = 1644 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1665 bfa_os_htons(attr->len + sizeof(attr->type) +
1666 sizeof(attr->len)); 1645 sizeof(attr->len));
1667 1646
1668 /* 1647 /*
1669 * Model Desc 1648 * Model Desc
1670 */ 1649 */
1671 attr = (struct fdmi_attr_s *) curr_ptr; 1650 attr = (struct fdmi_attr_s *) curr_ptr;
1672 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_MODEL_DESC); 1651 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
1673 attr->len = (u16) strlen(fcs_hba_attr->model_desc); 1652 attr->len = (u16) strlen(fcs_hba_attr->model_desc);
1674 memcpy(attr->value, fcs_hba_attr->model_desc, attr->len); 1653 memcpy(attr->value, fcs_hba_attr->model_desc, attr->len);
1675 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1654 attr->len = fc_roundup(attr->len, sizeof(u32));
1676 *fields need
1677 *to be 4 byte
1678 *aligned */
1679 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1655 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1680 len += attr->len; 1656 len += attr->len;
1681 count++; 1657 count++;
1682 attr->len = 1658 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1683 bfa_os_htons(attr->len + sizeof(attr->type) +
1684 sizeof(attr->len)); 1659 sizeof(attr->len));
1685 1660
1686 /* 1661 /*
@@ -1688,18 +1663,14 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1688 */ 1663 */
1689 if (fcs_hba_attr->hw_version[0] != '\0') { 1664 if (fcs_hba_attr->hw_version[0] != '\0') {
1690 attr = (struct fdmi_attr_s *) curr_ptr; 1665 attr = (struct fdmi_attr_s *) curr_ptr;
1691 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_HW_VERSION); 1666 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
1692 attr->len = (u16) strlen(fcs_hba_attr->hw_version); 1667 attr->len = (u16) strlen(fcs_hba_attr->hw_version);
1693 memcpy(attr->value, fcs_hba_attr->hw_version, attr->len); 1668 memcpy(attr->value, fcs_hba_attr->hw_version, attr->len);
1694 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1669 attr->len = fc_roundup(attr->len, sizeof(u32));
1695 *fields need
1696 *to be 4 byte
1697 *aligned */
1698 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1670 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1699 len += attr->len; 1671 len += attr->len;
1700 count++; 1672 count++;
1701 attr->len = 1673 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1702 bfa_os_htons(attr->len + sizeof(attr->type) +
1703 sizeof(attr->len)); 1674 sizeof(attr->len));
1704 } 1675 }
1705 1676
@@ -1707,18 +1678,14 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1707 * Driver Version 1678 * Driver Version
1708 */ 1679 */
1709 attr = (struct fdmi_attr_s *) curr_ptr; 1680 attr = (struct fdmi_attr_s *) curr_ptr;
1710 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_DRIVER_VERSION); 1681 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
1711 attr->len = (u16) strlen(fcs_hba_attr->driver_version); 1682 attr->len = (u16) strlen(fcs_hba_attr->driver_version);
1712 memcpy(attr->value, fcs_hba_attr->driver_version, attr->len); 1683 memcpy(attr->value, fcs_hba_attr->driver_version, attr->len);
1713 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1684 attr->len = fc_roundup(attr->len, sizeof(u32));
1714 *fields need
1715 *to be 4 byte
1716 *aligned */
1717 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1685 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1718 len += attr->len;; 1686 len += attr->len;;
1719 count++; 1687 count++;
1720 attr->len = 1688 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1721 bfa_os_htons(attr->len + sizeof(attr->type) +
1722 sizeof(attr->len)); 1689 sizeof(attr->len));
1723 1690
1724 /* 1691 /*
@@ -1726,18 +1693,14 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1726 */ 1693 */
1727 if (fcs_hba_attr->option_rom_ver[0] != '\0') { 1694 if (fcs_hba_attr->option_rom_ver[0] != '\0') {
1728 attr = (struct fdmi_attr_s *) curr_ptr; 1695 attr = (struct fdmi_attr_s *) curr_ptr;
1729 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_ROM_VERSION); 1696 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
1730 attr->len = (u16) strlen(fcs_hba_attr->option_rom_ver); 1697 attr->len = (u16) strlen(fcs_hba_attr->option_rom_ver);
1731 memcpy(attr->value, fcs_hba_attr->option_rom_ver, attr->len); 1698 memcpy(attr->value, fcs_hba_attr->option_rom_ver, attr->len);
1732 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1699 attr->len = fc_roundup(attr->len, sizeof(u32));
1733 *fields need
1734 *to be 4 byte
1735 *aligned */
1736 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1700 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1737 len += attr->len; 1701 len += attr->len;
1738 count++; 1702 count++;
1739 attr->len = 1703 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1740 bfa_os_htons(attr->len + sizeof(attr->type) +
1741 sizeof(attr->len)); 1704 sizeof(attr->len));
1742 } 1705 }
1743 1706
@@ -1745,18 +1708,14 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1745 * f/w Version = driver version 1708 * f/w Version = driver version
1746 */ 1709 */
1747 attr = (struct fdmi_attr_s *) curr_ptr; 1710 attr = (struct fdmi_attr_s *) curr_ptr;
1748 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_FW_VERSION); 1711 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
1749 attr->len = (u16) strlen(fcs_hba_attr->driver_version); 1712 attr->len = (u16) strlen(fcs_hba_attr->driver_version);
1750 memcpy(attr->value, fcs_hba_attr->driver_version, attr->len); 1713 memcpy(attr->value, fcs_hba_attr->driver_version, attr->len);
1751 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1714 attr->len = fc_roundup(attr->len, sizeof(u32));
1752 *fields need
1753 *to be 4 byte
1754 *aligned */
1755 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1715 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1756 len += attr->len; 1716 len += attr->len;
1757 count++; 1717 count++;
1758 attr->len = 1718 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1759 bfa_os_htons(attr->len + sizeof(attr->type) +
1760 sizeof(attr->len)); 1719 sizeof(attr->len));
1761 1720
1762 /* 1721 /*
@@ -1764,18 +1723,14 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1764 */ 1723 */
1765 if (fcs_hba_attr->os_name[0] != '\0') { 1724 if (fcs_hba_attr->os_name[0] != '\0') {
1766 attr = (struct fdmi_attr_s *) curr_ptr; 1725 attr = (struct fdmi_attr_s *) curr_ptr;
1767 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_OS_NAME); 1726 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
1768 attr->len = (u16) strlen(fcs_hba_attr->os_name); 1727 attr->len = (u16) strlen(fcs_hba_attr->os_name);
1769 memcpy(attr->value, fcs_hba_attr->os_name, attr->len); 1728 memcpy(attr->value, fcs_hba_attr->os_name, attr->len);
1770 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1729 attr->len = fc_roundup(attr->len, sizeof(u32));
1771 *fields need
1772 *to be 4 byte
1773 *aligned */
1774 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1730 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1775 len += attr->len; 1731 len += attr->len;
1776 count++; 1732 count++;
1777 attr->len = 1733 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1778 bfa_os_htons(attr->len + sizeof(attr->type) +
1779 sizeof(attr->len)); 1734 sizeof(attr->len));
1780 } 1735 }
1781 1736
@@ -1783,22 +1738,20 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1783 * MAX_CT_PAYLOAD 1738 * MAX_CT_PAYLOAD
1784 */ 1739 */
1785 attr = (struct fdmi_attr_s *) curr_ptr; 1740 attr = (struct fdmi_attr_s *) curr_ptr;
1786 attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_MAX_CT); 1741 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
1787 attr->len = sizeof(fcs_hba_attr->max_ct_pyld); 1742 attr->len = sizeof(fcs_hba_attr->max_ct_pyld);
1788 memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, attr->len); 1743 memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, attr->len);
1789 len += attr->len; 1744 len += attr->len;
1790 count++; 1745 count++;
1791 attr->len = 1746 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1792 bfa_os_htons(attr->len + sizeof(attr->type) +
1793 sizeof(attr->len)); 1747 sizeof(attr->len));
1794 1748
1795 /* 1749 /*
1796 * Update size of payload 1750 * Update size of payload
1797 */ 1751 */
1798 len += ((sizeof(attr->type) + 1752 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
1799 sizeof(attr->len)) * count);
1800 1753
1801 rhba->hba_attr_blk.attr_count = bfa_os_htonl(count); 1754 rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
1802 return len; 1755 return len;
1803} 1756}
1804 1757
@@ -1825,7 +1778,7 @@ bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
1825 } 1778 }
1826 1779
1827 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 1780 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1828 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 1781 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1829 1782
1830 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 1783 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1831 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK); 1784 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
@@ -1837,7 +1790,7 @@ bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
1837 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR); 1790 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
1838} 1791}
1839 1792
1840/** 1793/*
1841* RPRT : Register Port 1794* RPRT : Register Port
1842 */ 1795 */
1843static void 1796static void
@@ -1861,7 +1814,7 @@ bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1861 fdmi->fcxp = fcxp; 1814 fdmi->fcxp = fcxp;
1862 1815
1863 pyld = bfa_fcxp_get_reqbuf(fcxp); 1816 pyld = bfa_fcxp_get_reqbuf(fcxp);
1864 bfa_os_memset(pyld, 0, FC_MAX_PDUSZ); 1817 memset(pyld, 0, FC_MAX_PDUSZ);
1865 1818
1866 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port), 1819 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
1867 FDMI_RPRT); 1820 FDMI_RPRT);
@@ -1879,7 +1832,7 @@ bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1879 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT); 1832 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
1880} 1833}
1881 1834
1882/** 1835/*
1883 * This routine builds Port Attribute Block that used in RPA, RPRT commands. 1836 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
1884 */ 1837 */
1885static u16 1838static u16
@@ -1909,56 +1862,54 @@ bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
1909 * FC4 Types 1862 * FC4 Types
1910 */ 1863 */
1911 attr = (struct fdmi_attr_s *) curr_ptr; 1864 attr = (struct fdmi_attr_s *) curr_ptr;
1912 attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_FC4_TYPES); 1865 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES);
1913 attr->len = sizeof(fcs_port_attr.supp_fc4_types); 1866 attr->len = sizeof(fcs_port_attr.supp_fc4_types);
1914 memcpy(attr->value, fcs_port_attr.supp_fc4_types, attr->len); 1867 memcpy(attr->value, fcs_port_attr.supp_fc4_types, attr->len);
1915 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1868 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1916 len += attr->len; 1869 len += attr->len;
1917 ++count; 1870 ++count;
1918 attr->len = 1871 attr->len =
1919 bfa_os_htons(attr->len + sizeof(attr->type) + 1872 cpu_to_be16(attr->len + sizeof(attr->type) +
1920 sizeof(attr->len)); 1873 sizeof(attr->len));
1921 1874
1922 /* 1875 /*
1923 * Supported Speed 1876 * Supported Speed
1924 */ 1877 */
1925 attr = (struct fdmi_attr_s *) curr_ptr; 1878 attr = (struct fdmi_attr_s *) curr_ptr;
1926 attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_SUPP_SPEED); 1879 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED);
1927 attr->len = sizeof(fcs_port_attr.supp_speed); 1880 attr->len = sizeof(fcs_port_attr.supp_speed);
1928 memcpy(attr->value, &fcs_port_attr.supp_speed, attr->len); 1881 memcpy(attr->value, &fcs_port_attr.supp_speed, attr->len);
1929 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1882 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1930 len += attr->len; 1883 len += attr->len;
1931 ++count; 1884 ++count;
1932 attr->len = 1885 attr->len =
1933 bfa_os_htons(attr->len + sizeof(attr->type) + 1886 cpu_to_be16(attr->len + sizeof(attr->type) +
1934 sizeof(attr->len)); 1887 sizeof(attr->len));
1935 1888
1936 /* 1889 /*
1937 * current Port Speed 1890 * current Port Speed
1938 */ 1891 */
1939 attr = (struct fdmi_attr_s *) curr_ptr; 1892 attr = (struct fdmi_attr_s *) curr_ptr;
1940 attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_PORT_SPEED); 1893 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
1941 attr->len = sizeof(fcs_port_attr.curr_speed); 1894 attr->len = sizeof(fcs_port_attr.curr_speed);
1942 memcpy(attr->value, &fcs_port_attr.curr_speed, attr->len); 1895 memcpy(attr->value, &fcs_port_attr.curr_speed, attr->len);
1943 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1896 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1944 len += attr->len; 1897 len += attr->len;
1945 ++count; 1898 ++count;
1946 attr->len = 1899 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1947 bfa_os_htons(attr->len + sizeof(attr->type) +
1948 sizeof(attr->len)); 1900 sizeof(attr->len));
1949 1901
1950 /* 1902 /*
1951 * max frame size 1903 * max frame size
1952 */ 1904 */
1953 attr = (struct fdmi_attr_s *) curr_ptr; 1905 attr = (struct fdmi_attr_s *) curr_ptr;
1954 attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_FRAME_SIZE); 1906 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
1955 attr->len = sizeof(fcs_port_attr.max_frm_size); 1907 attr->len = sizeof(fcs_port_attr.max_frm_size);
1956 memcpy(attr->value, &fcs_port_attr.max_frm_size, attr->len); 1908 memcpy(attr->value, &fcs_port_attr.max_frm_size, attr->len);
1957 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1909 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1958 len += attr->len; 1910 len += attr->len;
1959 ++count; 1911 ++count;
1960 attr->len = 1912 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1961 bfa_os_htons(attr->len + sizeof(attr->type) +
1962 sizeof(attr->len)); 1913 sizeof(attr->len));
1963 1914
1964 /* 1915 /*
@@ -1966,18 +1917,14 @@ bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
1966 */ 1917 */
1967 if (fcs_port_attr.os_device_name[0] != '\0') { 1918 if (fcs_port_attr.os_device_name[0] != '\0') {
1968 attr = (struct fdmi_attr_s *) curr_ptr; 1919 attr = (struct fdmi_attr_s *) curr_ptr;
1969 attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_DEV_NAME); 1920 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
1970 attr->len = (u16) strlen(fcs_port_attr.os_device_name); 1921 attr->len = (u16) strlen(fcs_port_attr.os_device_name);
1971 memcpy(attr->value, fcs_port_attr.os_device_name, attr->len); 1922 memcpy(attr->value, fcs_port_attr.os_device_name, attr->len);
1972 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1923 attr->len = fc_roundup(attr->len, sizeof(u32));
1973 *fields need
1974 *to be 4 byte
1975 *aligned */
1976 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1924 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1977 len += attr->len; 1925 len += attr->len;
1978 ++count; 1926 ++count;
1979 attr->len = 1927 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1980 bfa_os_htons(attr->len + sizeof(attr->type) +
1981 sizeof(attr->len)); 1928 sizeof(attr->len));
1982 } 1929 }
1983 /* 1930 /*
@@ -1985,27 +1932,22 @@ bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
1985 */ 1932 */
1986 if (fcs_port_attr.host_name[0] != '\0') { 1933 if (fcs_port_attr.host_name[0] != '\0') {
1987 attr = (struct fdmi_attr_s *) curr_ptr; 1934 attr = (struct fdmi_attr_s *) curr_ptr;
1988 attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_HOST_NAME); 1935 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
1989 attr->len = (u16) strlen(fcs_port_attr.host_name); 1936 attr->len = (u16) strlen(fcs_port_attr.host_name);
1990 memcpy(attr->value, fcs_port_attr.host_name, attr->len); 1937 memcpy(attr->value, fcs_port_attr.host_name, attr->len);
1991 attr->len = fc_roundup(attr->len, sizeof(u32)); /* variable 1938 attr->len = fc_roundup(attr->len, sizeof(u32));
1992 *fields need
1993 *to be 4 byte
1994 *aligned */
1995 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len; 1939 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
1996 len += attr->len; 1940 len += attr->len;
1997 ++count; 1941 ++count;
1998 attr->len = 1942 attr->len = cpu_to_be16(attr->len + sizeof(attr->type) +
1999 bfa_os_htons(attr->len + sizeof(attr->type) +
2000 sizeof(attr->len)); 1943 sizeof(attr->len));
2001 } 1944 }
2002 1945
2003 /* 1946 /*
2004 * Update size of payload 1947 * Update size of payload
2005 */ 1948 */
2006 port_attrib->attr_count = bfa_os_htonl(count); 1949 port_attrib->attr_count = cpu_to_be32(count);
2007 len += ((sizeof(attr->type) + 1950 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
2008 sizeof(attr->len)) * count);
2009 return len; 1951 return len;
2010} 1952}
2011 1953
@@ -2050,7 +1992,7 @@ bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2050 } 1992 }
2051 1993
2052 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 1994 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2053 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 1995 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2054 1996
2055 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 1997 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2056 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK); 1998 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
@@ -2062,7 +2004,7 @@ bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2062 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR); 2004 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2063} 2005}
2064 2006
2065/** 2007/*
2066* RPA : Register Port Attributes. 2008* RPA : Register Port Attributes.
2067 */ 2009 */
2068static void 2010static void
@@ -2086,15 +2028,13 @@ bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2086 fdmi->fcxp = fcxp; 2028 fdmi->fcxp = fcxp;
2087 2029
2088 pyld = bfa_fcxp_get_reqbuf(fcxp); 2030 pyld = bfa_fcxp_get_reqbuf(fcxp);
2089 bfa_os_memset(pyld, 0, FC_MAX_PDUSZ); 2031 memset(pyld, 0, FC_MAX_PDUSZ);
2090 2032
2091 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port), 2033 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2092 FDMI_RPA); 2034 FDMI_RPA);
2093 2035
2094 attr_len = 2036 attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
2095 bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi, 2037 (u8 *) ((struct ct_hdr_s *) pyld + 1));
2096 (u8 *) ((struct ct_hdr_s *) pyld
2097 + 1));
2098 2038
2099 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, 2039 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2100 FC_CLASS_3, len + attr_len, &fchs, 2040 FC_CLASS_3, len + attr_len, &fchs,
@@ -2143,7 +2083,7 @@ bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2143 } 2083 }
2144 2084
2145 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 2085 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2146 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 2086 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2147 2087
2148 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 2088 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2149 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK); 2089 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
@@ -2170,7 +2110,7 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2170 struct bfa_fcs_lport_s *port = fdmi->ms->port; 2110 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2171 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info; 2111 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2172 2112
2173 bfa_os_memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s)); 2113 memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
2174 2114
2175 bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc, 2115 bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
2176 hba_attr->manufacturer); 2116 hba_attr->manufacturer);
@@ -2204,7 +2144,7 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2204 sizeof(driver_info->host_os_patch)); 2144 sizeof(driver_info->host_os_patch));
2205 } 2145 }
2206 2146
2207 hba_attr->max_ct_pyld = bfa_os_htonl(FC_MAX_PDUSZ); 2147 hba_attr->max_ct_pyld = cpu_to_be32(FC_MAX_PDUSZ);
2208} 2148}
2209 2149
2210void 2150void
@@ -2215,7 +2155,7 @@ bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2215 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info; 2155 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2216 struct bfa_port_attr_s pport_attr; 2156 struct bfa_port_attr_s pport_attr;
2217 2157
2218 bfa_os_memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s)); 2158 memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
2219 2159
2220 /* 2160 /*
2221 * get pport attributes from hal 2161 * get pport attributes from hal
@@ -2230,17 +2170,17 @@ bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2230 /* 2170 /*
2231 * Supported Speeds 2171 * Supported Speeds
2232 */ 2172 */
2233 port_attr->supp_speed = bfa_os_htonl(BFA_FCS_FDMI_SUPORTED_SPEEDS); 2173 port_attr->supp_speed = cpu_to_be32(BFA_FCS_FDMI_SUPORTED_SPEEDS);
2234 2174
2235 /* 2175 /*
2236 * Current Speed 2176 * Current Speed
2237 */ 2177 */
2238 port_attr->curr_speed = bfa_os_htonl(pport_attr.speed); 2178 port_attr->curr_speed = cpu_to_be32(pport_attr.speed);
2239 2179
2240 /* 2180 /*
2241 * Max PDU Size. 2181 * Max PDU Size.
2242 */ 2182 */
2243 port_attr->max_frm_size = bfa_os_htonl(FC_MAX_PDUSZ); 2183 port_attr->max_frm_size = cpu_to_be32(FC_MAX_PDUSZ);
2244 2184
2245 /* 2185 /*
2246 * OS device Name 2186 * OS device Name
@@ -2321,11 +2261,11 @@ static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
2321 u32 rsp_len, 2261 u32 rsp_len,
2322 u32 resid_len, 2262 u32 resid_len,
2323 struct fchs_s *rsp_fchs); 2263 struct fchs_s *rsp_fchs);
2324/** 2264/*
2325 * fcs_ms_sm FCS MS state machine 2265 * fcs_ms_sm FCS MS state machine
2326 */ 2266 */
2327 2267
2328/** 2268/*
2329 * MS State Machine events 2269 * MS State Machine events
2330 */ 2270 */
2331enum port_ms_event { 2271enum port_ms_event {
@@ -2360,7 +2300,7 @@ static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2360 enum port_ms_event event); 2300 enum port_ms_event event);
2361static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms, 2301static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2362 enum port_ms_event event); 2302 enum port_ms_event event);
2363/** 2303/*
2364 * Start in offline state - awaiting NS to send start. 2304 * Start in offline state - awaiting NS to send start.
2365 */ 2305 */
2366static void 2306static void
@@ -2432,7 +2372,7 @@ bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2432 */ 2372 */
2433 bfa_fcs_lport_fdmi_online(ms); 2373 bfa_fcs_lport_fdmi_online(ms);
2434 2374
2435 /** 2375 /*
2436 * if this is a Vport, go to online state. 2376 * if this is a Vport, go to online state.
2437 */ 2377 */
2438 if (ms->port->vport) { 2378 if (ms->port->vport) {
@@ -2595,7 +2535,7 @@ bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
2595 bfa_sm_fault(ms->port->fcs, event); 2535 bfa_sm_fault(ms->port->fcs, event);
2596 } 2536 }
2597} 2537}
2598/** 2538/*
2599 * ms_pvt MS local functions 2539 * ms_pvt MS local functions
2600 */ 2540 */
2601 2541
@@ -2657,12 +2597,12 @@ bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2657 } 2597 }
2658 2598
2659 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 2599 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2660 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 2600 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2661 2601
2662 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 2602 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2663 gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1); 2603 gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
2664 2604
2665 num_entries = bfa_os_ntohl(gmal_resp->ms_len); 2605 num_entries = be32_to_cpu(gmal_resp->ms_len);
2666 if (num_entries == 0) { 2606 if (num_entries == 0) {
2667 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR); 2607 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
2668 return; 2608 return;
@@ -2795,7 +2735,7 @@ bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2795 bfa_sm_fault(ms->port->fcs, event); 2735 bfa_sm_fault(ms->port->fcs, event);
2796 } 2736 }
2797} 2737}
2798/** 2738/*
2799 * ms_pvt MS local functions 2739 * ms_pvt MS local functions
2800 */ 2740 */
2801 2741
@@ -2853,7 +2793,7 @@ bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2853 } 2793 }
2854 2794
2855 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 2795 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2856 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 2796 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2857 2797
2858 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 2798 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2859 gfn_resp = (wwn_t *)(cthdr + 1); 2799 gfn_resp = (wwn_t *)(cthdr + 1);
@@ -2871,7 +2811,7 @@ bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2871 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR); 2811 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
2872} 2812}
2873 2813
2874/** 2814/*
2875 * ms_pvt MS local functions 2815 * ms_pvt MS local functions
2876 */ 2816 */
2877 2817
@@ -3017,7 +2957,7 @@ bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
3017 bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN); 2957 bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
3018} 2958}
3019 2959
3020/** 2960/*
3021 * @page ns_sm_info VPORT NS State Machine 2961 * @page ns_sm_info VPORT NS State Machine
3022 * 2962 *
3023 * @section ns_sm_interactions VPORT NS State Machine Interactions 2963 * @section ns_sm_interactions VPORT NS State Machine Interactions
@@ -3080,11 +3020,11 @@ static void bfa_fcs_lport_ns_process_gidft_pids(
3080 u32 *pid_buf, u32 n_pids); 3020 u32 *pid_buf, u32 n_pids);
3081 3021
3082static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port); 3022static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
3083/** 3023/*
3084 * fcs_ns_sm FCS nameserver interface state machine 3024 * fcs_ns_sm FCS nameserver interface state machine
3085 */ 3025 */
3086 3026
3087/** 3027/*
3088 * VPort NS State Machine events 3028 * VPort NS State Machine events
3089 */ 3029 */
3090enum vport_ns_event { 3030enum vport_ns_event {
@@ -3139,7 +3079,7 @@ static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
3139 enum vport_ns_event event); 3079 enum vport_ns_event event);
3140static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns, 3080static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3141 enum vport_ns_event event); 3081 enum vport_ns_event event);
3142/** 3082/*
3143 * Start in offline state - awaiting linkup 3083 * Start in offline state - awaiting linkup
3144 */ 3084 */
3145static void 3085static void
@@ -3628,7 +3568,7 @@ bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3628 3568
3629 3569
3630 3570
3631/** 3571/*
3632 * ns_pvt Nameserver local functions 3572 * ns_pvt Nameserver local functions
3633 */ 3573 */
3634 3574
@@ -3724,7 +3664,7 @@ bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3724 } 3664 }
3725} 3665}
3726 3666
3727/** 3667/*
3728 * Register the symbolic port name. 3668 * Register the symbolic port name.
3729 */ 3669 */
3730static void 3670static void
@@ -3738,7 +3678,7 @@ bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3738 u8 symbl[256]; 3678 u8 symbl[256];
3739 u8 *psymbl = &symbl[0]; 3679 u8 *psymbl = &symbl[0];
3740 3680
3741 bfa_os_memset(symbl, 0, sizeof(symbl)); 3681 memset(symbl, 0, sizeof(symbl));
3742 3682
3743 bfa_trc(port->fcs, port->port_cfg.pwwn); 3683 bfa_trc(port->fcs, port->port_cfg.pwwn);
3744 3684
@@ -3755,7 +3695,7 @@ bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3755 * for V-Port, form a Port Symbolic Name 3695 * for V-Port, form a Port Symbolic Name
3756 */ 3696 */
3757 if (port->vport) { 3697 if (port->vport) {
3758 /** 3698 /*
3759 * For Vports, we append the vport's port symbolic name 3699 * For Vports, we append the vport's port symbolic name
3760 * to that of the base port. 3700 * to that of the base port.
3761 */ 3701 */
@@ -3815,7 +3755,7 @@ bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3815 } 3755 }
3816 3756
3817 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 3757 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3818 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 3758 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3819 3759
3820 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 3760 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3821 port->stats.ns_rspnid_accepts++; 3761 port->stats.ns_rspnid_accepts++;
@@ -3829,7 +3769,7 @@ bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3829 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR); 3769 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
3830} 3770}
3831 3771
3832/** 3772/*
3833 * Register FC4-Types 3773 * Register FC4-Types
3834 */ 3774 */
3835static void 3775static void
@@ -3887,7 +3827,7 @@ bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3887 } 3827 }
3888 3828
3889 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 3829 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3890 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 3830 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3891 3831
3892 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 3832 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3893 port->stats.ns_rftid_accepts++; 3833 port->stats.ns_rftid_accepts++;
@@ -3901,7 +3841,7 @@ bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3901 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR); 3841 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
3902} 3842}
3903 3843
3904/** 3844/*
3905 * Register FC4-Features : Should be done after RFT_ID 3845 * Register FC4-Features : Should be done after RFT_ID
3906 */ 3846 */
3907static void 3847static void
@@ -3964,7 +3904,7 @@ bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3964 } 3904 }
3965 3905
3966 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 3906 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3967 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 3907 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3968 3908
3969 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 3909 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3970 port->stats.ns_rffid_accepts++; 3910 port->stats.ns_rffid_accepts++;
@@ -3982,7 +3922,7 @@ bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3982 } else 3922 } else
3983 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR); 3923 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
3984} 3924}
3985/** 3925/*
3986 * Query Fabric for FC4-Types Devices. 3926 * Query Fabric for FC4-Types Devices.
3987 * 3927 *
3988* TBD : Need to use a local (FCS private) response buffer, since the response 3928* TBD : Need to use a local (FCS private) response buffer, since the response
@@ -4058,7 +3998,7 @@ bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4058 } 3998 }
4059 3999
4060 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 4000 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4061 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 4001 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4062 4002
4063 switch (cthdr->cmd_rsp_code) { 4003 switch (cthdr->cmd_rsp_code) {
4064 4004
@@ -4102,7 +4042,7 @@ bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4102 } 4042 }
4103} 4043}
4104 4044
4105/** 4045/*
4106 * This routine will be called by bfa_timer on timer timeouts. 4046 * This routine will be called by bfa_timer on timer timeouts.
4107 * 4047 *
4108 * param[in] port - pointer to bfa_fcs_lport_t. 4048 * param[in] port - pointer to bfa_fcs_lport_t.
@@ -4166,7 +4106,7 @@ bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
4166 } 4106 }
4167} 4107}
4168 4108
4169/** 4109/*
4170 * fcs_ns_public FCS nameserver public interfaces 4110 * fcs_ns_public FCS nameserver public interfaces
4171 */ 4111 */
4172 4112
@@ -4227,7 +4167,7 @@ bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
4227 } 4167 }
4228} 4168}
4229 4169
4230/** 4170/*
4231 * FCS SCN 4171 * FCS SCN
4232 */ 4172 */
4233 4173
@@ -4250,11 +4190,11 @@ static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
4250 struct fchs_s *rx_fchs); 4190 struct fchs_s *rx_fchs);
4251static void bfa_fcs_lport_scn_timeout(void *arg); 4191static void bfa_fcs_lport_scn_timeout(void *arg);
4252 4192
4253/** 4193/*
4254 * fcs_scm_sm FCS SCN state machine 4194 * fcs_scm_sm FCS SCN state machine
4255 */ 4195 */
4256 4196
4257/** 4197/*
4258 * VPort SCN State Machine events 4198 * VPort SCN State Machine events
4259 */ 4199 */
4260enum port_scn_event { 4200enum port_scn_event {
@@ -4278,7 +4218,7 @@ static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
4278static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn, 4218static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
4279 enum port_scn_event event); 4219 enum port_scn_event event);
4280 4220
4281/** 4221/*
4282 * Starting state - awaiting link up. 4222 * Starting state - awaiting link up.
4283 */ 4223 */
4284static void 4224static void
@@ -4382,11 +4322,11 @@ bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
4382 4322
4383 4323
4384 4324
4385/** 4325/*
4386 * fcs_scn_private FCS SCN private functions 4326 * fcs_scn_private FCS SCN private functions
4387 */ 4327 */
4388 4328
4389/** 4329/*
4390 * This routine will be called to send a SCR command. 4330 * This routine will be called to send a SCR command.
4391 */ 4331 */
4392static void 4332static void
@@ -4499,7 +4439,7 @@ bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
4499 FC_MAX_PDUSZ, 0); 4439 FC_MAX_PDUSZ, 0);
4500} 4440}
4501 4441
4502/** 4442/*
4503 * This routine will be called by bfa_timer on timer timeouts. 4443 * This routine will be called by bfa_timer on timer timeouts.
4504 * 4444 *
4505 * param[in] vport - pointer to bfa_fcs_lport_t. 4445 * param[in] vport - pointer to bfa_fcs_lport_t.
@@ -4522,7 +4462,7 @@ bfa_fcs_lport_scn_timeout(void *arg)
4522 4462
4523 4463
4524 4464
4525/** 4465/*
4526 * fcs_scn_public FCS state change notification public interfaces 4466 * fcs_scn_public FCS state change notification public interfaces
4527 */ 4467 */
4528 4468
@@ -4563,7 +4503,7 @@ bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
4563 4503
4564 bfa_trc(port->fcs, rpid); 4504 bfa_trc(port->fcs, rpid);
4565 4505
4566 /** 4506 /*
4567 * If this is an unknown device, then it just came online. 4507 * If this is an unknown device, then it just came online.
4568 * Otherwise let rport handle the RSCN event. 4508 * Otherwise let rport handle the RSCN event.
4569 */ 4509 */
@@ -4579,7 +4519,7 @@ bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
4579 bfa_fcs_rport_scn(rport); 4519 bfa_fcs_rport_scn(rport);
4580} 4520}
4581 4521
4582/** 4522/*
4583 * rscn format based PID comparison 4523 * rscn format based PID comparison
4584 */ 4524 */
4585#define __fc_pid_match(__c0, __c1, __fmt) \ 4525#define __fc_pid_match(__c0, __c1, __fmt) \
@@ -4624,7 +4564,7 @@ bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
4624 int i = 0, j; 4564 int i = 0, j;
4625 4565
4626 num_entries = 4566 num_entries =
4627 (bfa_os_ntohs(rscn->payldlen) - 4567 (be16_to_cpu(rscn->payldlen) -
4628 sizeof(u32)) / sizeof(rscn->event[0]); 4568 sizeof(u32)) / sizeof(rscn->event[0]);
4629 4569
4630 bfa_trc(port->fcs, num_entries); 4570 bfa_trc(port->fcs, num_entries);
@@ -4691,18 +4631,18 @@ bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
4691 } 4631 }
4692 } 4632 }
4693 4633
4694 /** 4634 /*
4695 * If any of area, domain or fabric RSCN is received, do a fresh discovery 4635 * If any of area, domain or fabric RSCN is received, do a fresh
4696 * to find new devices. 4636 * discovery to find new devices.
4697 */ 4637 */
4698 if (nsquery) 4638 if (nsquery)
4699 bfa_fcs_lport_ns_query(port); 4639 bfa_fcs_lport_ns_query(port);
4700} 4640}
4701 4641
4702/** 4642/*
4703 * BFA FCS port 4643 * BFA FCS port
4704 */ 4644 */
4705/** 4645/*
4706 * fcs_port_api BFA FCS port API 4646 * fcs_port_api BFA FCS port API
4707 */ 4647 */
4708struct bfa_fcs_lport_s * 4648struct bfa_fcs_lport_s *
@@ -4943,10 +4883,10 @@ bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
4943void 4883void
4944bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port) 4884bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
4945{ 4885{
4946 bfa_os_memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s)); 4886 memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
4947} 4887}
4948 4888
4949/** 4889/*
4950 * FCS virtual port state machine 4890 * FCS virtual port state machine
4951 */ 4891 */
4952 4892
@@ -4967,11 +4907,11 @@ static void bfa_fcs_vport_timeout(void *vport_arg);
4967static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport); 4907static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
4968static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport); 4908static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
4969 4909
4970/** 4910/*
4971 * fcs_vport_sm FCS virtual port state machine 4911 * fcs_vport_sm FCS virtual port state machine
4972 */ 4912 */
4973 4913
4974/** 4914/*
4975 * VPort State Machine events 4915 * VPort State Machine events
4976 */ 4916 */
4977enum bfa_fcs_vport_event { 4917enum bfa_fcs_vport_event {
@@ -5024,7 +4964,7 @@ static struct bfa_sm_table_s vport_sm_table[] = {
5024 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR} 4964 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
5025}; 4965};
5026 4966
5027/** 4967/*
5028 * Beginning state. 4968 * Beginning state.
5029 */ 4969 */
5030static void 4970static void
@@ -5045,7 +4985,7 @@ bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
5045 } 4985 }
5046} 4986}
5047 4987
5048/** 4988/*
5049 * Created state - a start event is required to start up the state machine. 4989 * Created state - a start event is required to start up the state machine.
5050 */ 4990 */
5051static void 4991static void
@@ -5062,7 +5002,7 @@ bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
5062 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc); 5002 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
5063 bfa_fcs_vport_do_fdisc(vport); 5003 bfa_fcs_vport_do_fdisc(vport);
5064 } else { 5004 } else {
5065 /** 5005 /*
5066 * Fabric is offline or not NPIV capable, stay in 5006 * Fabric is offline or not NPIV capable, stay in
5067 * offline state. 5007 * offline state.
5068 */ 5008 */
@@ -5078,7 +5018,7 @@ bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
5078 5018
5079 case BFA_FCS_VPORT_SM_ONLINE: 5019 case BFA_FCS_VPORT_SM_ONLINE:
5080 case BFA_FCS_VPORT_SM_OFFLINE: 5020 case BFA_FCS_VPORT_SM_OFFLINE:
5081 /** 5021 /*
5082 * Ignore ONLINE/OFFLINE events from fabric 5022 * Ignore ONLINE/OFFLINE events from fabric
5083 * till vport is started. 5023 * till vport is started.
5084 */ 5024 */
@@ -5089,7 +5029,7 @@ bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
5089 } 5029 }
5090} 5030}
5091 5031
5092/** 5032/*
5093 * Offline state - awaiting ONLINE event from fabric SM. 5033 * Offline state - awaiting ONLINE event from fabric SM.
5094 */ 5034 */
5095static void 5035static void
@@ -5127,7 +5067,7 @@ bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
5127} 5067}
5128 5068
5129 5069
5130/** 5070/*
5131 * FDISC is sent and awaiting reply from fabric. 5071 * FDISC is sent and awaiting reply from fabric.
5132 */ 5072 */
5133static void 5073static void
@@ -5174,7 +5114,7 @@ bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
5174 } 5114 }
5175} 5115}
5176 5116
5177/** 5117/*
5178 * FDISC attempt failed - a timer is active to retry FDISC. 5118 * FDISC attempt failed - a timer is active to retry FDISC.
5179 */ 5119 */
5180static void 5120static void
@@ -5208,7 +5148,7 @@ bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
5208 } 5148 }
5209} 5149}
5210 5150
5211/** 5151/*
5212 * Vport is online (FDISC is complete). 5152 * Vport is online (FDISC is complete).
5213 */ 5153 */
5214static void 5154static void
@@ -5235,7 +5175,7 @@ bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
5235 } 5175 }
5236} 5176}
5237 5177
5238/** 5178/*
5239 * Vport is being deleted - awaiting lport delete completion to send 5179 * Vport is being deleted - awaiting lport delete completion to send
5240 * LOGO to fabric. 5180 * LOGO to fabric.
5241 */ 5181 */
@@ -5264,7 +5204,7 @@ bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
5264 } 5204 }
5265} 5205}
5266 5206
5267/** 5207/*
5268 * Error State. 5208 * Error State.
5269 * This state will be set when the Vport Creation fails due 5209 * This state will be set when the Vport Creation fails due
5270 * to errors like Dup WWN. In this state only operation allowed 5210 * to errors like Dup WWN. In this state only operation allowed
@@ -5288,7 +5228,7 @@ bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
5288 } 5228 }
5289} 5229}
5290 5230
5291/** 5231/*
5292 * Lport cleanup is in progress since vport is being deleted. Fabric is 5232 * Lport cleanup is in progress since vport is being deleted. Fabric is
5293 * offline, so no LOGO is needed to complete vport deletion. 5233 * offline, so no LOGO is needed to complete vport deletion.
5294 */ 5234 */
@@ -5313,7 +5253,7 @@ bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
5313 } 5253 }
5314} 5254}
5315 5255
5316/** 5256/*
5317 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup 5257 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
5318 * is done. 5258 * is done.
5319 */ 5259 */
@@ -5347,10 +5287,10 @@ bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
5347 5287
5348 5288
5349 5289
5350/** 5290/*
5351 * fcs_vport_private FCS virtual port private functions 5291 * fcs_vport_private FCS virtual port private functions
5352 */ 5292 */
5353/** 5293/*
5354 * This routine will be called to send a FDISC command. 5294 * This routine will be called to send a FDISC command.
5355 */ 5295 */
5356static void 5296static void
@@ -5397,7 +5337,7 @@ bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
5397 } 5337 }
5398} 5338}
5399 5339
5400/** 5340/*
5401 * Called to send a logout to the fabric. Used when a V-Port is 5341 * Called to send a logout to the fabric. Used when a V-Port is
5402 * deleted/stopped. 5342 * deleted/stopped.
5403 */ 5343 */
@@ -5411,7 +5351,7 @@ bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
5411} 5351}
5412 5352
5413 5353
5414/** 5354/*
5415 * This routine will be called by bfa_timer on timer timeouts. 5355 * This routine will be called by bfa_timer on timer timeouts.
5416 * 5356 *
5417 * param[in] vport - pointer to bfa_fcs_vport_t. 5357 * param[in] vport - pointer to bfa_fcs_vport_t.
@@ -5449,11 +5389,11 @@ bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
5449 5389
5450 5390
5451 5391
5452/** 5392/*
5453 * fcs_vport_public FCS virtual port public interfaces 5393 * fcs_vport_public FCS virtual port public interfaces
5454 */ 5394 */
5455 5395
5456/** 5396/*
5457 * Online notification from fabric SM. 5397 * Online notification from fabric SM.
5458 */ 5398 */
5459void 5399void
@@ -5463,7 +5403,7 @@ bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
5463 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE); 5403 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
5464} 5404}
5465 5405
5466/** 5406/*
5467 * Offline notification from fabric SM. 5407 * Offline notification from fabric SM.
5468 */ 5408 */
5469void 5409void
@@ -5473,7 +5413,7 @@ bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
5473 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE); 5413 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
5474} 5414}
5475 5415
5476/** 5416/*
5477 * Cleanup notification from fabric SM on link timer expiry. 5417 * Cleanup notification from fabric SM on link timer expiry.
5478 */ 5418 */
5479void 5419void
@@ -5481,7 +5421,7 @@ bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
5481{ 5421{
5482 vport->vport_stats.fab_cleanup++; 5422 vport->vport_stats.fab_cleanup++;
5483} 5423}
5484/** 5424/*
5485 * delete notification from fabric SM. To be invoked from within FCS. 5425 * delete notification from fabric SM. To be invoked from within FCS.
5486 */ 5426 */
5487void 5427void
@@ -5490,7 +5430,7 @@ bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
5490 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE); 5430 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
5491} 5431}
5492 5432
5493/** 5433/*
5494 * Delete completion callback from associated lport 5434 * Delete completion callback from associated lport
5495 */ 5435 */
5496void 5436void
@@ -5501,11 +5441,11 @@ bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
5501 5441
5502 5442
5503 5443
5504/** 5444/*
5505 * fcs_vport_api Virtual port API 5445 * fcs_vport_api Virtual port API
5506 */ 5446 */
5507 5447
5508/** 5448/*
5509 * Use this function to instantiate a new FCS vport object. This 5449 * Use this function to instantiate a new FCS vport object. This
5510 * function will not trigger any HW initialization process (which will be 5450 * function will not trigger any HW initialization process (which will be
5511 * done in vport_start() call) 5451 * done in vport_start() call)
@@ -5555,7 +5495,7 @@ bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
5555 return BFA_STATUS_OK; 5495 return BFA_STATUS_OK;
5556} 5496}
5557 5497
5558/** 5498/*
5559 * Use this function to instantiate a new FCS PBC vport object. This 5499 * Use this function to instantiate a new FCS PBC vport object. This
5560 * function will not trigger any HW initialization process (which will be 5500 * function will not trigger any HW initialization process (which will be
5561 * done in vport_start() call) 5501 * done in vport_start() call)
@@ -5585,7 +5525,7 @@ bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
5585 return rc; 5525 return rc;
5586} 5526}
5587 5527
5588/** 5528/*
5589 * Use this function to findout if this is a pbc vport or not. 5529 * Use this function to findout if this is a pbc vport or not.
5590 * 5530 *
5591 * @param[in] vport - pointer to bfa_fcs_vport_t. 5531 * @param[in] vport - pointer to bfa_fcs_vport_t.
@@ -5603,7 +5543,7 @@ bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport)
5603 5543
5604} 5544}
5605 5545
5606/** 5546/*
5607 * Use this function initialize the vport. 5547 * Use this function initialize the vport.
5608 * 5548 *
5609 * @param[in] vport - pointer to bfa_fcs_vport_t. 5549 * @param[in] vport - pointer to bfa_fcs_vport_t.
@@ -5618,7 +5558,7 @@ bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
5618 return BFA_STATUS_OK; 5558 return BFA_STATUS_OK;
5619} 5559}
5620 5560
5621/** 5561/*
5622 * Use this function quiese the vport object. This function will return 5562 * Use this function quiese the vport object. This function will return
5623 * immediately, when the vport is actually stopped, the 5563 * immediately, when the vport is actually stopped, the
5624 * bfa_drv_vport_stop_cb() will be called. 5564 * bfa_drv_vport_stop_cb() will be called.
@@ -5635,7 +5575,7 @@ bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
5635 return BFA_STATUS_OK; 5575 return BFA_STATUS_OK;
5636} 5576}
5637 5577
5638/** 5578/*
5639 * Use this function to delete a vport object. Fabric object should 5579 * Use this function to delete a vport object. Fabric object should
5640 * be stopped before this function call. 5580 * be stopped before this function call.
5641 * 5581 *
@@ -5657,7 +5597,7 @@ bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
5657 return BFA_STATUS_OK; 5597 return BFA_STATUS_OK;
5658} 5598}
5659 5599
5660/** 5600/*
5661 * Use this function to get vport's current status info. 5601 * Use this function to get vport's current status info.
5662 * 5602 *
5663 * param[in] vport pointer to bfa_fcs_vport_t. 5603 * param[in] vport pointer to bfa_fcs_vport_t.
@@ -5672,13 +5612,13 @@ bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
5672 if (vport == NULL || attr == NULL) 5612 if (vport == NULL || attr == NULL)
5673 return; 5613 return;
5674 5614
5675 bfa_os_memset(attr, 0, sizeof(struct bfa_vport_attr_s)); 5615 memset(attr, 0, sizeof(struct bfa_vport_attr_s));
5676 5616
5677 bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr); 5617 bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
5678 attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm); 5618 attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
5679} 5619}
5680 5620
5681/** 5621/*
5682 * Use this function to get vport's statistics. 5622 * Use this function to get vport's statistics.
5683 * 5623 *
5684 * param[in] vport pointer to bfa_fcs_vport_t. 5624 * param[in] vport pointer to bfa_fcs_vport_t.
@@ -5693,7 +5633,7 @@ bfa_fcs_vport_get_stats(struct bfa_fcs_vport_s *vport,
5693 *stats = vport->vport_stats; 5633 *stats = vport->vport_stats;
5694} 5634}
5695 5635
5696/** 5636/*
5697 * Use this function to clear vport's statistics. 5637 * Use this function to clear vport's statistics.
5698 * 5638 *
5699 * param[in] vport pointer to bfa_fcs_vport_t. 5639 * param[in] vport pointer to bfa_fcs_vport_t.
@@ -5703,10 +5643,10 @@ bfa_fcs_vport_get_stats(struct bfa_fcs_vport_s *vport,
5703void 5643void
5704bfa_fcs_vport_clr_stats(struct bfa_fcs_vport_s *vport) 5644bfa_fcs_vport_clr_stats(struct bfa_fcs_vport_s *vport)
5705{ 5645{
5706 bfa_os_memset(&vport->vport_stats, 0, sizeof(struct bfa_vport_stats_s)); 5646 memset(&vport->vport_stats, 0, sizeof(struct bfa_vport_stats_s));
5707} 5647}
5708 5648
5709/** 5649/*
5710 * Lookup a virtual port. Excludes base port from lookup. 5650 * Lookup a virtual port. Excludes base port from lookup.
5711 */ 5651 */
5712struct bfa_fcs_vport_s * 5652struct bfa_fcs_vport_s *
@@ -5728,7 +5668,7 @@ bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
5728 return vport; 5668 return vport;
5729} 5669}
5730 5670
5731/** 5671/*
5732 * FDISC Response 5672 * FDISC Response
5733 */ 5673 */
5734void 5674void
@@ -5784,7 +5724,7 @@ bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
5784 } 5724 }
5785} 5725}
5786 5726
5787/** 5727/*
5788 * LOGO response 5728 * LOGO response
5789 */ 5729 */
5790void 5730void
@@ -5794,7 +5734,7 @@ bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
5794 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK); 5734 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
5795} 5735}
5796 5736
5797/** 5737/*
5798 * Received clear virtual link 5738 * Received clear virtual link
5799 */ 5739 */
5800void 5740void
diff --git a/drivers/scsi/bfa/bfa_fcs_rport.c b/drivers/scsi/bfa/bfa_fcs_rport.c
index 635f0cd88714..47f35c0ef29a 100644
--- a/drivers/scsi/bfa/bfa_fcs_rport.c
+++ b/drivers/scsi/bfa/bfa_fcs_rport.c
@@ -15,7 +15,7 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * rport.c Remote port implementation. 19 * rport.c Remote port implementation.
20 */ 20 */
21 21
@@ -75,7 +75,7 @@ static void bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport,
75static void bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport, 75static void bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
76 struct fchs_s *rx_fchs, u16 len); 76 struct fchs_s *rx_fchs, u16 len);
77static void bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport); 77static void bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport);
78/** 78/*
79 * fcs_rport_sm FCS rport state machine events 79 * fcs_rport_sm FCS rport state machine events
80 */ 80 */
81 81
@@ -172,7 +172,7 @@ static struct bfa_sm_table_s rport_sm_table[] = {
172 {BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC}, 172 {BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC},
173}; 173};
174 174
175/** 175/*
176 * Beginning state. 176 * Beginning state.
177 */ 177 */
178static void 178static void
@@ -210,7 +210,7 @@ bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event)
210 } 210 }
211} 211}
212 212
213/** 213/*
214 * PLOGI is being sent. 214 * PLOGI is being sent.
215 */ 215 */
216static void 216static void
@@ -262,7 +262,7 @@ bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
262 } 262 }
263} 263}
264 264
265/** 265/*
266 * PLOGI is being sent. 266 * PLOGI is being sent.
267 */ 267 */
268static void 268static void
@@ -287,7 +287,7 @@ bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
287 287
288 case RPSM_EVENT_PLOGI_RCVD: 288 case RPSM_EVENT_PLOGI_RCVD:
289 case RPSM_EVENT_SCN: 289 case RPSM_EVENT_SCN:
290 /** 290 /*
291 * Ignore, SCN is possibly online notification. 291 * Ignore, SCN is possibly online notification.
292 */ 292 */
293 break; 293 break;
@@ -309,7 +309,7 @@ bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
309 break; 309 break;
310 310
311 case RPSM_EVENT_HCB_OFFLINE: 311 case RPSM_EVENT_HCB_OFFLINE:
312 /** 312 /*
313 * Ignore BFA callback, on a PLOGI receive we call bfa offline. 313 * Ignore BFA callback, on a PLOGI receive we call bfa offline.
314 */ 314 */
315 break; 315 break;
@@ -319,7 +319,7 @@ bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
319 } 319 }
320} 320}
321 321
322/** 322/*
323 * PLOGI is sent. 323 * PLOGI is sent.
324 */ 324 */
325static void 325static void
@@ -380,7 +380,7 @@ bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
380 } 380 }
381} 381}
382 382
383/** 383/*
384 * PLOGI is sent. 384 * PLOGI is sent.
385 */ 385 */
386static void 386static void
@@ -475,7 +475,7 @@ bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
475 } 475 }
476} 476}
477 477
478/** 478/*
479 * PLOGI is complete. Awaiting BFA rport online callback. FC-4s 479 * PLOGI is complete. Awaiting BFA rport online callback. FC-4s
480 * are offline. 480 * are offline.
481 */ 481 */
@@ -519,7 +519,7 @@ bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
519 break; 519 break;
520 520
521 case RPSM_EVENT_SCN: 521 case RPSM_EVENT_SCN:
522 /** 522 /*
523 * @todo 523 * @todo
524 * Ignore SCN - PLOGI just completed, FC-4 login should detect 524 * Ignore SCN - PLOGI just completed, FC-4 login should detect
525 * device failures. 525 * device failures.
@@ -531,7 +531,7 @@ bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
531 } 531 }
532} 532}
533 533
534/** 534/*
535 * Rport is ONLINE. FC-4s active. 535 * Rport is ONLINE. FC-4s active.
536 */ 536 */
537static void 537static void
@@ -580,7 +580,7 @@ bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
580 } 580 }
581} 581}
582 582
583/** 583/*
584 * An SCN event is received in ONLINE state. NS query is being sent 584 * An SCN event is received in ONLINE state. NS query is being sent
585 * prior to ADISC authentication with rport. FC-4s are paused. 585 * prior to ADISC authentication with rport. FC-4s are paused.
586 */ 586 */
@@ -604,7 +604,7 @@ bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
604 break; 604 break;
605 605
606 case RPSM_EVENT_SCN: 606 case RPSM_EVENT_SCN:
607 /** 607 /*
608 * ignore SCN, wait for response to query itself 608 * ignore SCN, wait for response to query itself
609 */ 609 */
610 break; 610 break;
@@ -638,7 +638,7 @@ bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
638 } 638 }
639} 639}
640 640
641/** 641/*
642 * An SCN event is received in ONLINE state. NS query is sent to rport. 642 * An SCN event is received in ONLINE state. NS query is sent to rport.
643 * FC-4s are paused. 643 * FC-4s are paused.
644 */ 644 */
@@ -697,7 +697,7 @@ bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
697 } 697 }
698} 698}
699 699
700/** 700/*
701 * An SCN event is received in ONLINE state. ADISC is being sent for 701 * An SCN event is received in ONLINE state. ADISC is being sent for
702 * authenticating with rport. FC-4s are paused. 702 * authenticating with rport. FC-4s are paused.
703 */ 703 */
@@ -748,7 +748,7 @@ bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
748 } 748 }
749} 749}
750 750
751/** 751/*
752 * An SCN event is received in ONLINE state. ADISC is to rport. 752 * An SCN event is received in ONLINE state. ADISC is to rport.
753 * FC-4s are paused. 753 * FC-4s are paused.
754 */ 754 */
@@ -765,7 +765,7 @@ bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
765 break; 765 break;
766 766
767 case RPSM_EVENT_PLOGI_RCVD: 767 case RPSM_EVENT_PLOGI_RCVD:
768 /** 768 /*
769 * Too complex to cleanup FC-4 & rport and then acc to PLOGI. 769 * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
770 * At least go offline when a PLOGI is received. 770 * At least go offline when a PLOGI is received.
771 */ 771 */
@@ -787,7 +787,7 @@ bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
787 break; 787 break;
788 788
789 case RPSM_EVENT_SCN: 789 case RPSM_EVENT_SCN:
790 /** 790 /*
791 * already processing RSCN 791 * already processing RSCN
792 */ 792 */
793 break; 793 break;
@@ -810,7 +810,7 @@ bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
810 } 810 }
811} 811}
812 812
813/** 813/*
814 * Rport has sent LOGO. Awaiting FC-4 offline completion callback. 814 * Rport has sent LOGO. Awaiting FC-4 offline completion callback.
815 */ 815 */
816static void 816static void
@@ -841,7 +841,7 @@ bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
841 } 841 }
842} 842}
843 843
844/** 844/*
845 * LOGO needs to be sent to rport. Awaiting FC-4 offline completion 845 * LOGO needs to be sent to rport. Awaiting FC-4 offline completion
846 * callback. 846 * callback.
847 */ 847 */
@@ -864,7 +864,7 @@ bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
864 } 864 }
865} 865}
866 866
867/** 867/*
868 * Rport is going offline. Awaiting FC-4 offline completion callback. 868 * Rport is going offline. Awaiting FC-4 offline completion callback.
869 */ 869 */
870static void 870static void
@@ -886,7 +886,7 @@ bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
886 case RPSM_EVENT_LOGO_RCVD: 886 case RPSM_EVENT_LOGO_RCVD:
887 case RPSM_EVENT_PRLO_RCVD: 887 case RPSM_EVENT_PRLO_RCVD:
888 case RPSM_EVENT_ADDRESS_CHANGE: 888 case RPSM_EVENT_ADDRESS_CHANGE:
889 /** 889 /*
890 * rport is already going offline. 890 * rport is already going offline.
891 * SCN - ignore and wait till transitioning to offline state 891 * SCN - ignore and wait till transitioning to offline state
892 */ 892 */
@@ -901,7 +901,7 @@ bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
901 } 901 }
902} 902}
903 903
904/** 904/*
905 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline 905 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
906 * callback. 906 * callback.
907 */ 907 */
@@ -945,7 +945,7 @@ bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
945 case RPSM_EVENT_SCN: 945 case RPSM_EVENT_SCN:
946 case RPSM_EVENT_LOGO_RCVD: 946 case RPSM_EVENT_LOGO_RCVD:
947 case RPSM_EVENT_PRLO_RCVD: 947 case RPSM_EVENT_PRLO_RCVD:
948 /** 948 /*
949 * Ignore, already offline. 949 * Ignore, already offline.
950 */ 950 */
951 break; 951 break;
@@ -955,7 +955,7 @@ bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
955 } 955 }
956} 956}
957 957
958/** 958/*
959 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline 959 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
960 * callback to send LOGO accept. 960 * callback to send LOGO accept.
961 */ 961 */
@@ -1009,7 +1009,7 @@ bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
1009 1009
1010 case RPSM_EVENT_LOGO_RCVD: 1010 case RPSM_EVENT_LOGO_RCVD:
1011 case RPSM_EVENT_PRLO_RCVD: 1011 case RPSM_EVENT_PRLO_RCVD:
1012 /** 1012 /*
1013 * Ignore - already processing a LOGO. 1013 * Ignore - already processing a LOGO.
1014 */ 1014 */
1015 break; 1015 break;
@@ -1019,7 +1019,7 @@ bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
1019 } 1019 }
1020} 1020}
1021 1021
1022/** 1022/*
1023 * Rport is being deleted. FC-4s are offline. 1023 * Rport is being deleted. FC-4s are offline.
1024 * Awaiting BFA rport offline 1024 * Awaiting BFA rport offline
1025 * callback to send LOGO. 1025 * callback to send LOGO.
@@ -1048,7 +1048,7 @@ bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
1048 } 1048 }
1049} 1049}
1050 1050
1051/** 1051/*
1052 * Rport is being deleted. FC-4s are offline. LOGO is being sent. 1052 * Rport is being deleted. FC-4s are offline. LOGO is being sent.
1053 */ 1053 */
1054static void 1054static void
@@ -1082,7 +1082,7 @@ bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
1082 } 1082 }
1083} 1083}
1084 1084
1085/** 1085/*
1086 * Rport is offline. FC-4s are offline. BFA rport is offline. 1086 * Rport is offline. FC-4s are offline. BFA rport is offline.
1087 * Timer active to delete stale rport. 1087 * Timer active to delete stale rport.
1088 */ 1088 */
@@ -1142,7 +1142,7 @@ bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event)
1142 } 1142 }
1143} 1143}
1144 1144
1145/** 1145/*
1146 * Rport address has changed. Nameserver discovery request is being sent. 1146 * Rport address has changed. Nameserver discovery request is being sent.
1147 */ 1147 */
1148static void 1148static void
@@ -1199,7 +1199,7 @@ bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
1199 } 1199 }
1200} 1200}
1201 1201
1202/** 1202/*
1203 * Nameserver discovery failed. Waiting for timeout to retry. 1203 * Nameserver discovery failed. Waiting for timeout to retry.
1204 */ 1204 */
1205static void 1205static void
@@ -1263,7 +1263,7 @@ bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
1263 } 1263 }
1264} 1264}
1265 1265
1266/** 1266/*
1267 * Rport address has changed. Nameserver discovery request is sent. 1267 * Rport address has changed. Nameserver discovery request is sent.
1268 */ 1268 */
1269static void 1269static void
@@ -1329,13 +1329,13 @@ bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
1329 bfa_fcs_rport_send_prlo_acc(rport); 1329 bfa_fcs_rport_send_prlo_acc(rport);
1330 break; 1330 break;
1331 case RPSM_EVENT_SCN: 1331 case RPSM_EVENT_SCN:
1332 /** 1332 /*
1333 * ignore, wait for NS query response 1333 * ignore, wait for NS query response
1334 */ 1334 */
1335 break; 1335 break;
1336 1336
1337 case RPSM_EVENT_LOGO_RCVD: 1337 case RPSM_EVENT_LOGO_RCVD:
1338 /** 1338 /*
1339 * Not logged-in yet. Accept LOGO. 1339 * Not logged-in yet. Accept LOGO.
1340 */ 1340 */
1341 bfa_fcs_rport_send_logo_acc(rport); 1341 bfa_fcs_rport_send_logo_acc(rport);
@@ -1354,7 +1354,7 @@ bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
1354 1354
1355 1355
1356 1356
1357/** 1357/*
1358 * fcs_rport_private FCS RPORT provate functions 1358 * fcs_rport_private FCS RPORT provate functions
1359 */ 1359 */
1360 1360
@@ -1415,7 +1415,7 @@ bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1415 1415
1416 plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp); 1416 plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp);
1417 1417
1418 /** 1418 /*
1419 * Check for failure first. 1419 * Check for failure first.
1420 */ 1420 */
1421 if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) { 1421 if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) {
@@ -1436,7 +1436,7 @@ bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1436 return; 1436 return;
1437 } 1437 }
1438 1438
1439 /** 1439 /*
1440 * PLOGI is complete. Make sure this device is not one of the known 1440 * PLOGI is complete. Make sure this device is not one of the known
1441 * device with a new FC port address. 1441 * device with a new FC port address.
1442 */ 1442 */
@@ -1468,7 +1468,7 @@ bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1468 } 1468 }
1469 } 1469 }
1470 1470
1471 /** 1471 /*
1472 * Normal login path -- no evil twins. 1472 * Normal login path -- no evil twins.
1473 */ 1473 */
1474 rport->stats.plogi_accs++; 1474 rport->stats.plogi_accs++;
@@ -1621,7 +1621,7 @@ bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1621 bfa_trc(rport->fcs, rport->pwwn); 1621 bfa_trc(rport->fcs, rport->pwwn);
1622 1622
1623 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 1623 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1624 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 1624 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1625 1625
1626 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 1626 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1627 /* Check if the pid is the same as before. */ 1627 /* Check if the pid is the same as before. */
@@ -1691,7 +1691,7 @@ bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1691 bfa_trc(rport->fcs, rport->pwwn); 1691 bfa_trc(rport->fcs, rport->pwwn);
1692 1692
1693 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); 1693 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1694 cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code); 1694 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1695 1695
1696 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { 1696 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1697 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED); 1697 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
@@ -1722,7 +1722,7 @@ bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1722 } 1722 }
1723} 1723}
1724 1724
1725/** 1725/*
1726 * Called to send a logout to the rport. 1726 * Called to send a logout to the rport.
1727 */ 1727 */
1728static void 1728static void
@@ -1759,7 +1759,7 @@ bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1759 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT); 1759 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1760} 1760}
1761 1761
1762/** 1762/*
1763 * Send ACC for a LOGO received. 1763 * Send ACC for a LOGO received.
1764 */ 1764 */
1765static void 1765static void
@@ -1788,7 +1788,7 @@ bfa_fcs_rport_send_logo_acc(void *rport_cbarg)
1788 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0); 1788 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1789} 1789}
1790 1790
1791/** 1791/*
1792 * brief 1792 * brief
1793 * This routine will be called by bfa_timer on timer timeouts. 1793 * This routine will be called by bfa_timer on timer timeouts.
1794 * 1794 *
@@ -1961,7 +1961,7 @@ bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
1961 struct bfa_fcs_rport_s *rport; 1961 struct bfa_fcs_rport_s *rport;
1962 struct bfad_rport_s *rport_drv; 1962 struct bfad_rport_s *rport_drv;
1963 1963
1964 /** 1964 /*
1965 * allocate rport 1965 * allocate rport
1966 */ 1966 */
1967 if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv) 1967 if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
@@ -1979,7 +1979,7 @@ bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
1979 rport->pid = rpid; 1979 rport->pid = rpid;
1980 rport->pwwn = pwwn; 1980 rport->pwwn = pwwn;
1981 1981
1982 /** 1982 /*
1983 * allocate BFA rport 1983 * allocate BFA rport
1984 */ 1984 */
1985 rport->bfa_rport = bfa_rport_create(port->fcs->bfa, rport); 1985 rport->bfa_rport = bfa_rport_create(port->fcs->bfa, rport);
@@ -1989,7 +1989,7 @@ bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
1989 return NULL; 1989 return NULL;
1990 } 1990 }
1991 1991
1992 /** 1992 /*
1993 * allocate FC-4s 1993 * allocate FC-4s
1994 */ 1994 */
1995 bfa_assert(bfa_fcs_lport_is_initiator(port)); 1995 bfa_assert(bfa_fcs_lport_is_initiator(port));
@@ -2021,7 +2021,7 @@ bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
2021{ 2021{
2022 struct bfa_fcs_lport_s *port = rport->port; 2022 struct bfa_fcs_lport_s *port = rport->port;
2023 2023
2024 /** 2024 /*
2025 * - delete FC-4s 2025 * - delete FC-4s
2026 * - delete BFA rport 2026 * - delete BFA rport
2027 * - remove from queue of rports 2027 * - remove from queue of rports
@@ -2093,7 +2093,7 @@ bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport)
2093 } 2093 }
2094} 2094}
2095 2095
2096/** 2096/*
2097 * Update rport parameters from PLOGI or PLOGI accept. 2097 * Update rport parameters from PLOGI or PLOGI accept.
2098 */ 2098 */
2099static void 2099static void
@@ -2101,14 +2101,14 @@ bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
2101{ 2101{
2102 bfa_fcs_lport_t *port = rport->port; 2102 bfa_fcs_lport_t *port = rport->port;
2103 2103
2104 /** 2104 /*
2105 * - port name 2105 * - port name
2106 * - node name 2106 * - node name
2107 */ 2107 */
2108 rport->pwwn = plogi->port_name; 2108 rport->pwwn = plogi->port_name;
2109 rport->nwwn = plogi->node_name; 2109 rport->nwwn = plogi->node_name;
2110 2110
2111 /** 2111 /*
2112 * - class of service 2112 * - class of service
2113 */ 2113 */
2114 rport->fc_cos = 0; 2114 rport->fc_cos = 0;
@@ -2118,16 +2118,16 @@ bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
2118 if (plogi->class2.class_valid) 2118 if (plogi->class2.class_valid)
2119 rport->fc_cos |= FC_CLASS_2; 2119 rport->fc_cos |= FC_CLASS_2;
2120 2120
2121 /** 2121 /*
2122 * - CISC 2122 * - CISC
2123 * - MAX receive frame size 2123 * - MAX receive frame size
2124 */ 2124 */
2125 rport->cisc = plogi->csp.cisc; 2125 rport->cisc = plogi->csp.cisc;
2126 rport->maxfrsize = bfa_os_ntohs(plogi->class3.rxsz); 2126 rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
2127 2127
2128 bfa_trc(port->fcs, bfa_os_ntohs(plogi->csp.bbcred)); 2128 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
2129 bfa_trc(port->fcs, port->fabric->bb_credit); 2129 bfa_trc(port->fcs, port->fabric->bb_credit);
2130 /** 2130 /*
2131 * Direct Attach P2P mode : 2131 * Direct Attach P2P mode :
2132 * This is to handle a bug (233476) in IBM targets in Direct Attach 2132 * This is to handle a bug (233476) in IBM targets in Direct Attach
2133 * Mode. Basically, in FLOGI Accept the target would have 2133 * Mode. Basically, in FLOGI Accept the target would have
@@ -2136,19 +2136,19 @@ bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
2136 * in PLOGI. 2136 * in PLOGI.
2137 */ 2137 */
2138 if ((!bfa_fcs_fabric_is_switched(port->fabric)) && 2138 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
2139 (bfa_os_ntohs(plogi->csp.bbcred) < port->fabric->bb_credit)) { 2139 (be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) {
2140 2140
2141 bfa_trc(port->fcs, bfa_os_ntohs(plogi->csp.bbcred)); 2141 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
2142 bfa_trc(port->fcs, port->fabric->bb_credit); 2142 bfa_trc(port->fcs, port->fabric->bb_credit);
2143 2143
2144 port->fabric->bb_credit = bfa_os_ntohs(plogi->csp.bbcred); 2144 port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred);
2145 bfa_fcport_set_tx_bbcredit(port->fcs->bfa, 2145 bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
2146 port->fabric->bb_credit); 2146 port->fabric->bb_credit);
2147 } 2147 }
2148 2148
2149} 2149}
2150 2150
2151/** 2151/*
2152 * Called to handle LOGO received from an existing remote port. 2152 * Called to handle LOGO received from an existing remote port.
2153 */ 2153 */
2154static void 2154static void
@@ -2164,11 +2164,11 @@ bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
2164 2164
2165 2165
2166 2166
2167/** 2167/*
2168 * fcs_rport_public FCS rport public interfaces 2168 * fcs_rport_public FCS rport public interfaces
2169 */ 2169 */
2170 2170
2171/** 2171/*
2172 * Called by bport/vport to create a remote port instance for a discovered 2172 * Called by bport/vport to create a remote port instance for a discovered
2173 * remote device. 2173 * remote device.
2174 * 2174 *
@@ -2191,7 +2191,7 @@ bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid)
2191 return rport; 2191 return rport;
2192} 2192}
2193 2193
2194/** 2194/*
2195 * Called to create a rport for which only the wwn is known. 2195 * Called to create a rport for which only the wwn is known.
2196 * 2196 *
2197 * @param[in] port - base port 2197 * @param[in] port - base port
@@ -2211,7 +2211,7 @@ bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2211 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC); 2211 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
2212 return rport; 2212 return rport;
2213} 2213}
2214/** 2214/*
2215 * Called by bport in private loop topology to indicate that a 2215 * Called by bport in private loop topology to indicate that a
2216 * rport has been discovered and plogi has been completed. 2216 * rport has been discovered and plogi has been completed.
2217 * 2217 *
@@ -2233,7 +2233,7 @@ bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2233 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP); 2233 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
2234} 2234}
2235 2235
2236/** 2236/*
2237 * Called by bport/vport to handle PLOGI received from a new remote port. 2237 * Called by bport/vport to handle PLOGI received from a new remote port.
2238 * If an existing rport does a plogi, it will be handled separately. 2238 * If an existing rport does a plogi, it will be handled separately.
2239 */ 2239 */
@@ -2272,7 +2272,7 @@ wwn_compare(wwn_t wwn1, wwn_t wwn2)
2272 return 0; 2272 return 0;
2273} 2273}
2274 2274
2275/** 2275/*
2276 * Called by bport/vport to handle PLOGI received from an existing 2276 * Called by bport/vport to handle PLOGI received from an existing
2277 * remote port. 2277 * remote port.
2278 */ 2278 */
@@ -2280,7 +2280,7 @@ void
2280bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs, 2280bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2281 struct fc_logi_s *plogi) 2281 struct fc_logi_s *plogi)
2282{ 2282{
2283 /** 2283 /*
2284 * @todo Handle P2P and initiator-initiator. 2284 * @todo Handle P2P and initiator-initiator.
2285 */ 2285 */
2286 2286
@@ -2289,7 +2289,7 @@ bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2289 rport->reply_oxid = rx_fchs->ox_id; 2289 rport->reply_oxid = rx_fchs->ox_id;
2290 bfa_trc(rport->fcs, rport->reply_oxid); 2290 bfa_trc(rport->fcs, rport->reply_oxid);
2291 2291
2292 /** 2292 /*
2293 * In Switched fabric topology, 2293 * In Switched fabric topology,
2294 * PLOGI to each other. If our pwwn is smaller, ignore it, 2294 * PLOGI to each other. If our pwwn is smaller, ignore it,
2295 * if it is not a well known address. 2295 * if it is not a well known address.
@@ -2307,7 +2307,7 @@ bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2307 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD); 2307 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2308} 2308}
2309 2309
2310/** 2310/*
2311 * Called by bport/vport to delete a remote port instance. 2311 * Called by bport/vport to delete a remote port instance.
2312 * 2312 *
2313 * Rport delete is called under the following conditions: 2313 * Rport delete is called under the following conditions:
@@ -2321,7 +2321,7 @@ bfa_fcs_rport_delete(struct bfa_fcs_rport_s *rport)
2321 bfa_sm_send_event(rport, RPSM_EVENT_DELETE); 2321 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
2322} 2322}
2323 2323
2324/** 2324/*
2325 * Called by bport/vport to when a target goes offline. 2325 * Called by bport/vport to when a target goes offline.
2326 * 2326 *
2327 */ 2327 */
@@ -2331,7 +2331,7 @@ bfa_fcs_rport_offline(struct bfa_fcs_rport_s *rport)
2331 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP); 2331 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
2332} 2332}
2333 2333
2334/** 2334/*
2335 * Called by bport in n2n when a target (attached port) becomes online. 2335 * Called by bport in n2n when a target (attached port) becomes online.
2336 * 2336 *
2337 */ 2337 */
@@ -2340,7 +2340,7 @@ bfa_fcs_rport_online(struct bfa_fcs_rport_s *rport)
2340{ 2340{
2341 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND); 2341 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
2342} 2342}
2343/** 2343/*
2344 * Called by bport/vport to notify SCN for the remote port 2344 * Called by bport/vport to notify SCN for the remote port
2345 */ 2345 */
2346void 2346void
@@ -2350,7 +2350,7 @@ bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
2350 bfa_sm_send_event(rport, RPSM_EVENT_SCN); 2350 bfa_sm_send_event(rport, RPSM_EVENT_SCN);
2351} 2351}
2352 2352
2353/** 2353/*
2354 * Called by fcpim to notify that the ITN cleanup is done. 2354 * Called by fcpim to notify that the ITN cleanup is done.
2355 */ 2355 */
2356void 2356void
@@ -2359,7 +2359,7 @@ bfa_fcs_rport_itnim_ack(struct bfa_fcs_rport_s *rport)
2359 bfa_sm_send_event(rport, RPSM_EVENT_FC4_OFFLINE); 2359 bfa_sm_send_event(rport, RPSM_EVENT_FC4_OFFLINE);
2360} 2360}
2361 2361
2362/** 2362/*
2363 * Called by fcptm to notify that the ITN cleanup is done. 2363 * Called by fcptm to notify that the ITN cleanup is done.
2364 */ 2364 */
2365void 2365void
@@ -2368,7 +2368,7 @@ bfa_fcs_rport_tin_ack(struct bfa_fcs_rport_s *rport)
2368 bfa_sm_send_event(rport, RPSM_EVENT_FC4_OFFLINE); 2368 bfa_sm_send_event(rport, RPSM_EVENT_FC4_OFFLINE);
2369} 2369}
2370 2370
2371/** 2371/*
2372 * brief 2372 * brief
2373 * This routine BFA callback for bfa_rport_online() call. 2373 * This routine BFA callback for bfa_rport_online() call.
2374 * 2374 *
@@ -2391,7 +2391,7 @@ bfa_cb_rport_online(void *cbarg)
2391 bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE); 2391 bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
2392} 2392}
2393 2393
2394/** 2394/*
2395 * brief 2395 * brief
2396 * This routine BFA callback for bfa_rport_offline() call. 2396 * This routine BFA callback for bfa_rport_offline() call.
2397 * 2397 *
@@ -2413,7 +2413,7 @@ bfa_cb_rport_offline(void *cbarg)
2413 bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE); 2413 bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
2414} 2414}
2415 2415
2416/** 2416/*
2417 * brief 2417 * brief
2418 * This routine is a static BFA callback when there is a QoS flow_id 2418 * This routine is a static BFA callback when there is a QoS flow_id
2419 * change notification 2419 * change notification
@@ -2437,7 +2437,7 @@ bfa_cb_rport_qos_scn_flowid(void *cbarg,
2437 bfa_trc(rport->fcs, rport->pwwn); 2437 bfa_trc(rport->fcs, rport->pwwn);
2438} 2438}
2439 2439
2440/** 2440/*
2441 * brief 2441 * brief
2442 * This routine is a static BFA callback when there is a QoS priority 2442 * This routine is a static BFA callback when there is a QoS priority
2443 * change notification 2443 * change notification
@@ -2461,7 +2461,7 @@ bfa_cb_rport_qos_scn_prio(void *cbarg,
2461 bfa_trc(rport->fcs, rport->pwwn); 2461 bfa_trc(rport->fcs, rport->pwwn);
2462} 2462}
2463 2463
2464/** 2464/*
2465 * Called to process any unsolicted frames from this remote port 2465 * Called to process any unsolicted frames from this remote port
2466 */ 2466 */
2467void 2467void
@@ -2470,7 +2470,7 @@ bfa_fcs_rport_logo_imp(struct bfa_fcs_rport_s *rport)
2470 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP); 2470 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
2471} 2471}
2472 2472
2473/** 2473/*
2474 * Called to process any unsolicted frames from this remote port 2474 * Called to process any unsolicted frames from this remote port
2475 */ 2475 */
2476void 2476void
@@ -2577,7 +2577,7 @@ bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2577 FC_MAX_PDUSZ, 0); 2577 FC_MAX_PDUSZ, 0);
2578} 2578}
2579 2579
2580/** 2580/*
2581 * Return state of rport. 2581 * Return state of rport.
2582 */ 2582 */
2583int 2583int
@@ -2586,7 +2586,7 @@ bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
2586 return bfa_sm_to_state(rport_sm_table, rport->sm); 2586 return bfa_sm_to_state(rport_sm_table, rport->sm);
2587} 2587}
2588 2588
2589/** 2589/*
2590 * brief 2590 * brief
2591 * Called by the Driver to set rport delete/ageout timeout 2591 * Called by the Driver to set rport delete/ageout timeout
2592 * 2592 *
@@ -2613,15 +2613,15 @@ bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, u16 ox_id)
2613 2613
2614 2614
2615 2615
2616/** 2616/*
2617 * Remote port implementation. 2617 * Remote port implementation.
2618 */ 2618 */
2619 2619
2620/** 2620/*
2621 * fcs_rport_api FCS rport API. 2621 * fcs_rport_api FCS rport API.
2622 */ 2622 */
2623 2623
2624/** 2624/*
2625 * Direct API to add a target by port wwn. This interface is used, for 2625 * Direct API to add a target by port wwn. This interface is used, for
2626 * example, by bios when target pwwn is known from boot lun configuration. 2626 * example, by bios when target pwwn is known from boot lun configuration.
2627 */ 2627 */
@@ -2634,7 +2634,7 @@ bfa_fcs_rport_add(struct bfa_fcs_lport_s *port, wwn_t *pwwn,
2634 return BFA_STATUS_OK; 2634 return BFA_STATUS_OK;
2635} 2635}
2636 2636
2637/** 2637/*
2638 * Direct API to remove a target and its associated resources. This 2638 * Direct API to remove a target and its associated resources. This
2639 * interface is used, for example, by driver to remove target 2639 * interface is used, for example, by driver to remove target
2640 * ports from the target list for a VM. 2640 * ports from the target list for a VM.
@@ -2663,7 +2663,7 @@ bfa_fcs_rport_remove(struct bfa_fcs_rport_s *rport_in)
2663 2663
2664} 2664}
2665 2665
2666/** 2666/*
2667 * Remote device status for display/debug. 2667 * Remote device status for display/debug.
2668 */ 2668 */
2669void 2669void
@@ -2674,7 +2674,7 @@ bfa_fcs_rport_get_attr(struct bfa_fcs_rport_s *rport,
2674 bfa_fcs_lport_t *port = rport->port; 2674 bfa_fcs_lport_t *port = rport->port;
2675 bfa_port_speed_t rport_speed = rport->rpf.rpsc_speed; 2675 bfa_port_speed_t rport_speed = rport->rpf.rpsc_speed;
2676 2676
2677 bfa_os_memset(rport_attr, 0, sizeof(struct bfa_rport_attr_s)); 2677 memset(rport_attr, 0, sizeof(struct bfa_rport_attr_s));
2678 2678
2679 rport_attr->pid = rport->pid; 2679 rport_attr->pid = rport->pid;
2680 rport_attr->pwwn = rport->pwwn; 2680 rport_attr->pwwn = rport->pwwn;
@@ -2704,7 +2704,7 @@ bfa_fcs_rport_get_attr(struct bfa_fcs_rport_s *rport,
2704 } 2704 }
2705} 2705}
2706 2706
2707/** 2707/*
2708 * Per remote device statistics. 2708 * Per remote device statistics.
2709 */ 2709 */
2710void 2710void
@@ -2717,7 +2717,7 @@ bfa_fcs_rport_get_stats(struct bfa_fcs_rport_s *rport,
2717void 2717void
2718bfa_fcs_rport_clear_stats(struct bfa_fcs_rport_s *rport) 2718bfa_fcs_rport_clear_stats(struct bfa_fcs_rport_s *rport)
2719{ 2719{
2720 bfa_os_memset((char *)&rport->stats, 0, 2720 memset((char *)&rport->stats, 0,
2721 sizeof(struct bfa_rport_stats_s)); 2721 sizeof(struct bfa_rport_stats_s));
2722} 2722}
2723 2723
@@ -2767,7 +2767,7 @@ bfa_fcs_rport_set_speed(struct bfa_fcs_rport_s *rport, bfa_port_speed_t speed)
2767 2767
2768 2768
2769 2769
2770/** 2770/*
2771 * Remote port features (RPF) implementation. 2771 * Remote port features (RPF) implementation.
2772 */ 2772 */
2773 2773
@@ -2786,7 +2786,7 @@ static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,
2786 2786
2787static void bfa_fcs_rpf_timeout(void *arg); 2787static void bfa_fcs_rpf_timeout(void *arg);
2788 2788
2789/** 2789/*
2790 * fcs_rport_ftrs_sm FCS rport state machine events 2790 * fcs_rport_ftrs_sm FCS rport state machine events
2791 */ 2791 */
2792 2792
@@ -2981,7 +2981,7 @@ bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2981 bfa_sm_fault(rport->fcs, event); 2981 bfa_sm_fault(rport->fcs, event);
2982 } 2982 }
2983} 2983}
2984/** 2984/*
2985 * Called when Rport is created. 2985 * Called when Rport is created.
2986 */ 2986 */
2987void 2987void
@@ -2995,7 +2995,7 @@ bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
2995 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit); 2995 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
2996} 2996}
2997 2997
2998/** 2998/*
2999 * Called when Rport becomes online 2999 * Called when Rport becomes online
3000 */ 3000 */
3001void 3001void
@@ -3010,7 +3010,7 @@ bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
3010 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE); 3010 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
3011} 3011}
3012 3012
3013/** 3013/*
3014 * Called when Rport becomes offline 3014 * Called when Rport becomes offline
3015 */ 3015 */
3016void 3016void
@@ -3090,16 +3090,16 @@ bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
3090 rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp); 3090 rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
3091 if (rpsc2_acc->els_cmd == FC_ELS_ACC) { 3091 if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
3092 rport->stats.rpsc_accs++; 3092 rport->stats.rpsc_accs++;
3093 num_ents = bfa_os_ntohs(rpsc2_acc->num_pids); 3093 num_ents = be16_to_cpu(rpsc2_acc->num_pids);
3094 bfa_trc(rport->fcs, num_ents); 3094 bfa_trc(rport->fcs, num_ents);
3095 if (num_ents > 0) { 3095 if (num_ents > 0) {
3096 bfa_assert(rpsc2_acc->port_info[0].pid != rport->pid); 3096 bfa_assert(rpsc2_acc->port_info[0].pid != rport->pid);
3097 bfa_trc(rport->fcs, 3097 bfa_trc(rport->fcs,
3098 bfa_os_ntohs(rpsc2_acc->port_info[0].pid)); 3098 be16_to_cpu(rpsc2_acc->port_info[0].pid));
3099 bfa_trc(rport->fcs, 3099 bfa_trc(rport->fcs,
3100 bfa_os_ntohs(rpsc2_acc->port_info[0].speed)); 3100 be16_to_cpu(rpsc2_acc->port_info[0].speed));
3101 bfa_trc(rport->fcs, 3101 bfa_trc(rport->fcs,
3102 bfa_os_ntohs(rpsc2_acc->port_info[0].index)); 3102 be16_to_cpu(rpsc2_acc->port_info[0].index));
3103 bfa_trc(rport->fcs, 3103 bfa_trc(rport->fcs,
3104 rpsc2_acc->port_info[0].type); 3104 rpsc2_acc->port_info[0].type);
3105 3105
@@ -3109,7 +3109,7 @@ bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
3109 } 3109 }
3110 3110
3111 rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed( 3111 rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
3112 bfa_os_ntohs(rpsc2_acc->port_info[0].speed)); 3112 be16_to_cpu(rpsc2_acc->port_info[0].speed));
3113 3113
3114 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP); 3114 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
3115 } 3115 }
diff --git a/drivers/scsi/bfa/bfa_hw_cb.c b/drivers/scsi/bfa/bfa_hw_cb.c
index c787d3af0886..d8464ae60070 100644
--- a/drivers/scsi/bfa/bfa_hw_cb.c
+++ b/drivers/scsi/bfa/bfa_hw_cb.c
@@ -22,7 +22,7 @@ void
22bfa_hwcb_reginit(struct bfa_s *bfa) 22bfa_hwcb_reginit(struct bfa_s *bfa)
23{ 23{
24 struct bfa_iocfc_regs_s *bfa_regs = &bfa->iocfc.bfa_regs; 24 struct bfa_iocfc_regs_s *bfa_regs = &bfa->iocfc.bfa_regs;
25 bfa_os_addr_t kva = bfa_ioc_bar0(&bfa->ioc); 25 void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
26 int i, q, fn = bfa_ioc_pcifn(&bfa->ioc); 26 int i, q, fn = bfa_ioc_pcifn(&bfa->ioc);
27 27
28 if (fn == 0) { 28 if (fn == 0) {
@@ -60,8 +60,8 @@ bfa_hwcb_reqq_ack(struct bfa_s *bfa, int reqq)
60static void 60static void
61bfa_hwcb_reqq_ack_msix(struct bfa_s *bfa, int reqq) 61bfa_hwcb_reqq_ack_msix(struct bfa_s *bfa, int reqq)
62{ 62{
63 bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, 63 writel(__HFN_INT_CPE_Q0 << CPE_Q_NUM(bfa_ioc_pcifn(&bfa->ioc), reqq),
64 __HFN_INT_CPE_Q0 << CPE_Q_NUM(bfa_ioc_pcifn(&bfa->ioc), reqq)); 64 bfa->iocfc.bfa_regs.intr_status);
65} 65}
66 66
67void 67void
@@ -72,8 +72,8 @@ bfa_hwcb_rspq_ack(struct bfa_s *bfa, int rspq)
72static void 72static void
73bfa_hwcb_rspq_ack_msix(struct bfa_s *bfa, int rspq) 73bfa_hwcb_rspq_ack_msix(struct bfa_s *bfa, int rspq)
74{ 74{
75 bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, 75 writel(__HFN_INT_RME_Q0 << RME_Q_NUM(bfa_ioc_pcifn(&bfa->ioc), rspq),
76 __HFN_INT_RME_Q0 << RME_Q_NUM(bfa_ioc_pcifn(&bfa->ioc), rspq)); 76 bfa->iocfc.bfa_regs.intr_status);
77} 77}
78 78
79void 79void
@@ -102,7 +102,7 @@ bfa_hwcb_msix_getvecs(struct bfa_s *bfa, u32 *msix_vecs_bmap,
102 *num_vecs = __HFN_NUMINTS; 102 *num_vecs = __HFN_NUMINTS;
103} 103}
104 104
105/** 105/*
106 * No special setup required for crossbow -- vector assignments are implicit. 106 * No special setup required for crossbow -- vector assignments are implicit.
107 */ 107 */
108void 108void
@@ -129,7 +129,7 @@ bfa_hwcb_msix_init(struct bfa_s *bfa, int nvecs)
129 bfa->msix.handler[i] = bfa_msix_lpu_err; 129 bfa->msix.handler[i] = bfa_msix_lpu_err;
130} 130}
131 131
132/** 132/*
133 * Crossbow -- dummy, interrupts are masked 133 * Crossbow -- dummy, interrupts are masked
134 */ 134 */
135void 135void
@@ -142,7 +142,7 @@ bfa_hwcb_msix_uninstall(struct bfa_s *bfa)
142{ 142{
143} 143}
144 144
145/** 145/*
146 * No special enable/disable -- vector assignments are implicit. 146 * No special enable/disable -- vector assignments are implicit.
147 */ 147 */
148void 148void
diff --git a/drivers/scsi/bfa/bfa_hw_ct.c b/drivers/scsi/bfa/bfa_hw_ct.c
index c97ebafec5ea..b0efbc713ffe 100644
--- a/drivers/scsi/bfa/bfa_hw_ct.c
+++ b/drivers/scsi/bfa/bfa_hw_ct.c
@@ -31,15 +31,15 @@ static void
31bfa_hwct_msix_lpu_err_set(struct bfa_s *bfa, bfa_boolean_t msix, int vec) 31bfa_hwct_msix_lpu_err_set(struct bfa_s *bfa, bfa_boolean_t msix, int vec)
32{ 32{
33 int fn = bfa_ioc_pcifn(&bfa->ioc); 33 int fn = bfa_ioc_pcifn(&bfa->ioc);
34 bfa_os_addr_t kva = bfa_ioc_bar0(&bfa->ioc); 34 void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
35 35
36 if (msix) 36 if (msix)
37 bfa_reg_write(kva + __ct_msix_err_vec_reg[fn], vec); 37 writel(vec, kva + __ct_msix_err_vec_reg[fn]);
38 else 38 else
39 bfa_reg_write(kva + __ct_msix_err_vec_reg[fn], 0); 39 writel(0, kva + __ct_msix_err_vec_reg[fn]);
40} 40}
41 41
42/** 42/*
43 * Dummy interrupt handler for handling spurious interrupt during chip-reinit. 43 * Dummy interrupt handler for handling spurious interrupt during chip-reinit.
44 */ 44 */
45static void 45static void
@@ -51,7 +51,7 @@ void
51bfa_hwct_reginit(struct bfa_s *bfa) 51bfa_hwct_reginit(struct bfa_s *bfa)
52{ 52{
53 struct bfa_iocfc_regs_s *bfa_regs = &bfa->iocfc.bfa_regs; 53 struct bfa_iocfc_regs_s *bfa_regs = &bfa->iocfc.bfa_regs;
54 bfa_os_addr_t kva = bfa_ioc_bar0(&bfa->ioc); 54 void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
55 int i, q, fn = bfa_ioc_pcifn(&bfa->ioc); 55 int i, q, fn = bfa_ioc_pcifn(&bfa->ioc);
56 56
57 if (fn == 0) { 57 if (fn == 0) {
@@ -88,8 +88,8 @@ bfa_hwct_reqq_ack(struct bfa_s *bfa, int reqq)
88{ 88{
89 u32 r32; 89 u32 r32;
90 90
91 r32 = bfa_reg_read(bfa->iocfc.bfa_regs.cpe_q_ctrl[reqq]); 91 r32 = readl(bfa->iocfc.bfa_regs.cpe_q_ctrl[reqq]);
92 bfa_reg_write(bfa->iocfc.bfa_regs.cpe_q_ctrl[reqq], r32); 92 writel(r32, bfa->iocfc.bfa_regs.cpe_q_ctrl[reqq]);
93} 93}
94 94
95void 95void
@@ -97,8 +97,8 @@ bfa_hwct_rspq_ack(struct bfa_s *bfa, int rspq)
97{ 97{
98 u32 r32; 98 u32 r32;
99 99
100 r32 = bfa_reg_read(bfa->iocfc.bfa_regs.rme_q_ctrl[rspq]); 100 r32 = readl(bfa->iocfc.bfa_regs.rme_q_ctrl[rspq]);
101 bfa_reg_write(bfa->iocfc.bfa_regs.rme_q_ctrl[rspq], r32); 101 writel(r32, bfa->iocfc.bfa_regs.rme_q_ctrl[rspq]);
102} 102}
103 103
104void 104void
@@ -110,7 +110,7 @@ bfa_hwct_msix_getvecs(struct bfa_s *bfa, u32 *msix_vecs_bmap,
110 *num_vecs = BFA_MSIX_CT_MAX; 110 *num_vecs = BFA_MSIX_CT_MAX;
111} 111}
112 112
113/** 113/*
114 * Setup MSI-X vector for catapult 114 * Setup MSI-X vector for catapult
115 */ 115 */
116void 116void
@@ -156,7 +156,7 @@ bfa_hwct_msix_uninstall(struct bfa_s *bfa)
156 bfa->msix.handler[i] = bfa_hwct_msix_dummy; 156 bfa->msix.handler[i] = bfa_hwct_msix_dummy;
157} 157}
158 158
159/** 159/*
160 * Enable MSI-X vectors 160 * Enable MSI-X vectors
161 */ 161 */
162void 162void
diff --git a/drivers/scsi/bfa/bfa_ioc.c b/drivers/scsi/bfa/bfa_ioc.c
index 6795b247791a..54475b53a5ab 100644
--- a/drivers/scsi/bfa/bfa_ioc.c
+++ b/drivers/scsi/bfa/bfa_ioc.c
@@ -23,7 +23,7 @@
23 23
24BFA_TRC_FILE(CNA, IOC); 24BFA_TRC_FILE(CNA, IOC);
25 25
26/** 26/*
27 * IOC local definitions 27 * IOC local definitions
28 */ 28 */
29#define BFA_IOC_TOV 3000 /* msecs */ 29#define BFA_IOC_TOV 3000 /* msecs */
@@ -49,7 +49,7 @@ BFA_TRC_FILE(CNA, IOC);
49 BFA_TRC_MAX * sizeof(struct bfa_trc_s))) 49 BFA_TRC_MAX * sizeof(struct bfa_trc_s)))
50#define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn)) 50#define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
51 51
52/** 52/*
53 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details. 53 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
54 */ 54 */
55 55
@@ -73,7 +73,7 @@ BFA_TRC_FILE(CNA, IOC);
73 73
74#define bfa_ioc_mbox_cmd_pending(__ioc) \ 74#define bfa_ioc_mbox_cmd_pending(__ioc) \
75 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \ 75 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
76 bfa_reg_read((__ioc)->ioc_regs.hfn_mbox_cmd)) 76 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
77 77
78bfa_boolean_t bfa_auto_recover = BFA_TRUE; 78bfa_boolean_t bfa_auto_recover = BFA_TRUE;
79 79
@@ -101,11 +101,11 @@ static void bfa_ioc_pf_disabled(struct bfa_ioc_s *ioc);
101static void bfa_ioc_pf_failed(struct bfa_ioc_s *ioc); 101static void bfa_ioc_pf_failed(struct bfa_ioc_s *ioc);
102static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc); 102static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
103 103
104/** 104/*
105 * hal_ioc_sm 105 * hal_ioc_sm
106 */ 106 */
107 107
108/** 108/*
109 * IOC state machine definitions/declarations 109 * IOC state machine definitions/declarations
110 */ 110 */
111enum ioc_event { 111enum ioc_event {
@@ -144,7 +144,7 @@ static struct bfa_sm_table_s ioc_sm_table[] = {
144 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED}, 144 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
145}; 145};
146 146
147/** 147/*
148 * IOCPF state machine definitions/declarations 148 * IOCPF state machine definitions/declarations
149 */ 149 */
150 150
@@ -174,7 +174,7 @@ static void bfa_iocpf_stop(struct bfa_ioc_s *ioc);
174static void bfa_iocpf_timeout(void *ioc_arg); 174static void bfa_iocpf_timeout(void *ioc_arg);
175static void bfa_iocpf_sem_timeout(void *ioc_arg); 175static void bfa_iocpf_sem_timeout(void *ioc_arg);
176 176
177/** 177/*
178 * IOCPF state machine events 178 * IOCPF state machine events
179 */ 179 */
180enum iocpf_event { 180enum iocpf_event {
@@ -191,7 +191,7 @@ enum iocpf_event {
191 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */ 191 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
192}; 192};
193 193
194/** 194/*
195 * IOCPF states 195 * IOCPF states
196 */ 196 */
197enum bfa_iocpf_state { 197enum bfa_iocpf_state {
@@ -232,11 +232,11 @@ static struct bfa_sm_table_s iocpf_sm_table[] = {
232 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED}, 232 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
233}; 233};
234 234
235/** 235/*
236 * IOC State Machine 236 * IOC State Machine
237 */ 237 */
238 238
239/** 239/*
240 * Beginning state. IOC uninit state. 240 * Beginning state. IOC uninit state.
241 */ 241 */
242 242
@@ -245,7 +245,7 @@ bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
245{ 245{
246} 246}
247 247
248/** 248/*
249 * IOC is in uninit state. 249 * IOC is in uninit state.
250 */ 250 */
251static void 251static void
@@ -262,7 +262,7 @@ bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
262 bfa_sm_fault(ioc, event); 262 bfa_sm_fault(ioc, event);
263 } 263 }
264} 264}
265/** 265/*
266 * Reset entry actions -- initialize state machine 266 * Reset entry actions -- initialize state machine
267 */ 267 */
268static void 268static void
@@ -271,7 +271,7 @@ bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
271 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset); 271 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
272} 272}
273 273
274/** 274/*
275 * IOC is in reset state. 275 * IOC is in reset state.
276 */ 276 */
277static void 277static void
@@ -304,7 +304,7 @@ bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
304 bfa_iocpf_enable(ioc); 304 bfa_iocpf_enable(ioc);
305} 305}
306 306
307/** 307/*
308 * Host IOC function is being enabled, awaiting response from firmware. 308 * Host IOC function is being enabled, awaiting response from firmware.
309 * Semaphore is acquired. 309 * Semaphore is acquired.
310 */ 310 */
@@ -352,7 +352,7 @@ bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
352 bfa_ioc_send_getattr(ioc); 352 bfa_ioc_send_getattr(ioc);
353} 353}
354 354
355/** 355/*
356 * IOC configuration in progress. Timer is active. 356 * IOC configuration in progress. Timer is active.
357 */ 357 */
358static void 358static void
@@ -447,7 +447,7 @@ bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
447 BFA_LOG(KERN_INFO, bfad, log_level, "IOC disabled\n"); 447 BFA_LOG(KERN_INFO, bfad, log_level, "IOC disabled\n");
448} 448}
449 449
450/** 450/*
451 * IOC is being disabled 451 * IOC is being disabled
452 */ 452 */
453static void 453static void
@@ -474,7 +474,7 @@ bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
474 } 474 }
475} 475}
476 476
477/** 477/*
478 * IOC disable completion entry. 478 * IOC disable completion entry.
479 */ 479 */
480static void 480static void
@@ -514,7 +514,7 @@ bfa_ioc_sm_initfail_entry(struct bfa_ioc_s *ioc)
514 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); 514 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
515} 515}
516 516
517/** 517/*
518 * Hardware initialization failed. 518 * Hardware initialization failed.
519 */ 519 */
520static void 520static void
@@ -528,7 +528,7 @@ bfa_ioc_sm_initfail(struct bfa_ioc_s *ioc, enum ioc_event event)
528 break; 528 break;
529 529
530 case IOC_E_FAILED: 530 case IOC_E_FAILED:
531 /** 531 /*
532 * Initialization failure during iocpf init retry. 532 * Initialization failure during iocpf init retry.
533 */ 533 */
534 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); 534 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
@@ -556,7 +556,7 @@ bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
556 struct bfa_ioc_hbfail_notify_s *notify; 556 struct bfa_ioc_hbfail_notify_s *notify;
557 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; 557 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
558 558
559 /** 559 /*
560 * Notify driver and common modules registered for notification. 560 * Notify driver and common modules registered for notification.
561 */ 561 */
562 ioc->cbfn->hbfail_cbfn(ioc->bfa); 562 ioc->cbfn->hbfail_cbfn(ioc->bfa);
@@ -569,7 +569,7 @@ bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
569 "Heart Beat of IOC has failed\n"); 569 "Heart Beat of IOC has failed\n");
570} 570}
571 571
572/** 572/*
573 * IOC failure. 573 * IOC failure.
574 */ 574 */
575static void 575static void
@@ -580,7 +580,7 @@ bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
580 switch (event) { 580 switch (event) {
581 581
582 case IOC_E_FAILED: 582 case IOC_E_FAILED:
583 /** 583 /*
584 * Initialization failure during iocpf recovery. 584 * Initialization failure during iocpf recovery.
585 * !!! Fall through !!! 585 * !!! Fall through !!!
586 */ 586 */
@@ -608,12 +608,12 @@ bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
608 608
609 609
610 610
611/** 611/*
612 * IOCPF State Machine 612 * IOCPF State Machine
613 */ 613 */
614 614
615 615
616/** 616/*
617 * Reset entry actions -- initialize state machine 617 * Reset entry actions -- initialize state machine
618 */ 618 */
619static void 619static void
@@ -623,7 +623,7 @@ bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
623 iocpf->auto_recover = bfa_auto_recover; 623 iocpf->auto_recover = bfa_auto_recover;
624} 624}
625 625
626/** 626/*
627 * Beginning state. IOC is in reset state. 627 * Beginning state. IOC is in reset state.
628 */ 628 */
629static void 629static void
@@ -646,7 +646,7 @@ bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
646 } 646 }
647} 647}
648 648
649/** 649/*
650 * Semaphore should be acquired for version check. 650 * Semaphore should be acquired for version check.
651 */ 651 */
652static void 652static void
@@ -655,7 +655,7 @@ bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
655 bfa_ioc_hw_sem_get(iocpf->ioc); 655 bfa_ioc_hw_sem_get(iocpf->ioc);
656} 656}
657 657
658/** 658/*
659 * Awaiting h/w semaphore to continue with version check. 659 * Awaiting h/w semaphore to continue with version check.
660 */ 660 */
661static void 661static void
@@ -692,7 +692,7 @@ bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
692 } 692 }
693} 693}
694 694
695/** 695/*
696 * Notify enable completion callback. 696 * Notify enable completion callback.
697 */ 697 */
698static void 698static void
@@ -708,7 +708,7 @@ bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
708 bfa_iocpf_timer_start(iocpf->ioc); 708 bfa_iocpf_timer_start(iocpf->ioc);
709} 709}
710 710
711/** 711/*
712 * Awaiting firmware version match. 712 * Awaiting firmware version match.
713 */ 713 */
714static void 714static void
@@ -739,7 +739,7 @@ bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
739 } 739 }
740} 740}
741 741
742/** 742/*
743 * Request for semaphore. 743 * Request for semaphore.
744 */ 744 */
745static void 745static void
@@ -748,7 +748,7 @@ bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
748 bfa_ioc_hw_sem_get(iocpf->ioc); 748 bfa_ioc_hw_sem_get(iocpf->ioc);
749} 749}
750 750
751/** 751/*
752 * Awaiting semaphore for h/w initialzation. 752 * Awaiting semaphore for h/w initialzation.
753 */ 753 */
754static void 754static void
@@ -782,7 +782,7 @@ bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
782 bfa_ioc_reset(iocpf->ioc, BFA_FALSE); 782 bfa_ioc_reset(iocpf->ioc, BFA_FALSE);
783} 783}
784 784
785/** 785/*
786 * Hardware is being initialized. Interrupts are enabled. 786 * Hardware is being initialized. Interrupts are enabled.
787 * Holding hardware semaphore lock. 787 * Holding hardware semaphore lock.
788 */ 788 */
@@ -839,7 +839,7 @@ bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
839 bfa_ioc_send_enable(iocpf->ioc); 839 bfa_ioc_send_enable(iocpf->ioc);
840} 840}
841 841
842/** 842/*
843 * Host IOC function is being enabled, awaiting response from firmware. 843 * Host IOC function is being enabled, awaiting response from firmware.
844 * Semaphore is acquired. 844 * Semaphore is acquired.
845 */ 845 */
@@ -866,8 +866,7 @@ bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
866 case IOCPF_E_TIMEOUT: 866 case IOCPF_E_TIMEOUT:
867 iocpf->retry_count++; 867 iocpf->retry_count++;
868 if (iocpf->retry_count < BFA_IOC_HWINIT_MAX) { 868 if (iocpf->retry_count < BFA_IOC_HWINIT_MAX) {
869 bfa_reg_write(ioc->ioc_regs.ioc_fwstate, 869 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
870 BFI_IOC_UNINIT);
871 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit); 870 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
872 break; 871 break;
873 } 872 }
@@ -944,7 +943,7 @@ bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
944 bfa_ioc_send_disable(iocpf->ioc); 943 bfa_ioc_send_disable(iocpf->ioc);
945} 944}
946 945
947/** 946/*
948 * IOC is being disabled 947 * IOC is being disabled
949 */ 948 */
950static void 949static void
@@ -968,7 +967,7 @@ bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
968 */ 967 */
969 968
970 case IOCPF_E_TIMEOUT: 969 case IOCPF_E_TIMEOUT:
971 bfa_reg_write(ioc->ioc_regs.ioc_fwstate, BFI_IOC_FAIL); 970 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
972 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); 971 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
973 break; 972 break;
974 973
@@ -980,7 +979,7 @@ bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
980 } 979 }
981} 980}
982 981
983/** 982/*
984 * IOC disable completion entry. 983 * IOC disable completion entry.
985 */ 984 */
986static void 985static void
@@ -1018,7 +1017,7 @@ bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1018 bfa_iocpf_timer_start(iocpf->ioc); 1017 bfa_iocpf_timer_start(iocpf->ioc);
1019} 1018}
1020 1019
1021/** 1020/*
1022 * Hardware initialization failed. 1021 * Hardware initialization failed.
1023 */ 1022 */
1024static void 1023static void
@@ -1053,18 +1052,18 @@ bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1053static void 1052static void
1054bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf) 1053bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1055{ 1054{
1056 /** 1055 /*
1057 * Mark IOC as failed in hardware and stop firmware. 1056 * Mark IOC as failed in hardware and stop firmware.
1058 */ 1057 */
1059 bfa_ioc_lpu_stop(iocpf->ioc); 1058 bfa_ioc_lpu_stop(iocpf->ioc);
1060 bfa_reg_write(iocpf->ioc->ioc_regs.ioc_fwstate, BFI_IOC_FAIL); 1059 writel(BFI_IOC_FAIL, iocpf->ioc->ioc_regs.ioc_fwstate);
1061 1060
1062 /** 1061 /*
1063 * Notify other functions on HB failure. 1062 * Notify other functions on HB failure.
1064 */ 1063 */
1065 bfa_ioc_notify_hbfail(iocpf->ioc); 1064 bfa_ioc_notify_hbfail(iocpf->ioc);
1066 1065
1067 /** 1066 /*
1068 * Flush any queued up mailbox requests. 1067 * Flush any queued up mailbox requests.
1069 */ 1068 */
1070 bfa_ioc_mbox_hbfail(iocpf->ioc); 1069 bfa_ioc_mbox_hbfail(iocpf->ioc);
@@ -1073,7 +1072,7 @@ bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1073 bfa_iocpf_recovery_timer_start(iocpf->ioc); 1072 bfa_iocpf_recovery_timer_start(iocpf->ioc);
1074} 1073}
1075 1074
1076/** 1075/*
1077 * IOC is in failed state. 1076 * IOC is in failed state.
1078 */ 1077 */
1079static void 1078static void
@@ -1101,7 +1100,7 @@ bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1101 1100
1102 1101
1103 1102
1104/** 1103/*
1105 * hal_ioc_pvt BFA IOC private functions 1104 * hal_ioc_pvt BFA IOC private functions
1106 */ 1105 */
1107 1106
@@ -1113,7 +1112,7 @@ bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1113 1112
1114 ioc->cbfn->disable_cbfn(ioc->bfa); 1113 ioc->cbfn->disable_cbfn(ioc->bfa);
1115 1114
1116 /** 1115 /*
1117 * Notify common modules registered for notification. 1116 * Notify common modules registered for notification.
1118 */ 1117 */
1119 list_for_each(qe, &ioc->hb_notify_q) { 1118 list_for_each(qe, &ioc->hb_notify_q) {
@@ -1123,18 +1122,18 @@ bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1123} 1122}
1124 1123
1125bfa_boolean_t 1124bfa_boolean_t
1126bfa_ioc_sem_get(bfa_os_addr_t sem_reg) 1125bfa_ioc_sem_get(void __iomem *sem_reg)
1127{ 1126{
1128 u32 r32; 1127 u32 r32;
1129 int cnt = 0; 1128 int cnt = 0;
1130#define BFA_SEM_SPINCNT 3000 1129#define BFA_SEM_SPINCNT 3000
1131 1130
1132 r32 = bfa_reg_read(sem_reg); 1131 r32 = readl(sem_reg);
1133 1132
1134 while (r32 && (cnt < BFA_SEM_SPINCNT)) { 1133 while (r32 && (cnt < BFA_SEM_SPINCNT)) {
1135 cnt++; 1134 cnt++;
1136 bfa_os_udelay(2); 1135 udelay(2);
1137 r32 = bfa_reg_read(sem_reg); 1136 r32 = readl(sem_reg);
1138 } 1137 }
1139 1138
1140 if (r32 == 0) 1139 if (r32 == 0)
@@ -1145,9 +1144,9 @@ bfa_ioc_sem_get(bfa_os_addr_t sem_reg)
1145} 1144}
1146 1145
1147void 1146void
1148bfa_ioc_sem_release(bfa_os_addr_t sem_reg) 1147bfa_ioc_sem_release(void __iomem *sem_reg)
1149{ 1148{
1150 bfa_reg_write(sem_reg, 1); 1149 writel(1, sem_reg);
1151} 1150}
1152 1151
1153static void 1152static void
@@ -1155,11 +1154,11 @@ bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1155{ 1154{
1156 u32 r32; 1155 u32 r32;
1157 1156
1158 /** 1157 /*
1159 * First read to the semaphore register will return 0, subsequent reads 1158 * First read to the semaphore register will return 0, subsequent reads
1160 * will return 1. Semaphore is released by writing 1 to the register 1159 * will return 1. Semaphore is released by writing 1 to the register
1161 */ 1160 */
1162 r32 = bfa_reg_read(ioc->ioc_regs.ioc_sem_reg); 1161 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
1163 if (r32 == 0) { 1162 if (r32 == 0) {
1164 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED); 1163 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
1165 return; 1164 return;
@@ -1171,7 +1170,7 @@ bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1171void 1170void
1172bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc) 1171bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc)
1173{ 1172{
1174 bfa_reg_write(ioc->ioc_regs.ioc_sem_reg, 1); 1173 writel(1, ioc->ioc_regs.ioc_sem_reg);
1175} 1174}
1176 1175
1177static void 1176static void
@@ -1180,7 +1179,7 @@ bfa_ioc_hw_sem_get_cancel(struct bfa_ioc_s *ioc)
1180 bfa_sem_timer_stop(ioc); 1179 bfa_sem_timer_stop(ioc);
1181} 1180}
1182 1181
1183/** 1182/*
1184 * Initialize LPU local memory (aka secondary memory / SRAM) 1183 * Initialize LPU local memory (aka secondary memory / SRAM)
1185 */ 1184 */
1186static void 1185static void
@@ -1190,7 +1189,7 @@ bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1190 int i; 1189 int i;
1191#define PSS_LMEM_INIT_TIME 10000 1190#define PSS_LMEM_INIT_TIME 10000
1192 1191
1193 pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg); 1192 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1194 pss_ctl &= ~__PSS_LMEM_RESET; 1193 pss_ctl &= ~__PSS_LMEM_RESET;
1195 pss_ctl |= __PSS_LMEM_INIT_EN; 1194 pss_ctl |= __PSS_LMEM_INIT_EN;
1196 1195
@@ -1198,18 +1197,18 @@ bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1198 * i2c workaround 12.5khz clock 1197 * i2c workaround 12.5khz clock
1199 */ 1198 */
1200 pss_ctl |= __PSS_I2C_CLK_DIV(3UL); 1199 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
1201 bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl); 1200 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1202 1201
1203 /** 1202 /*
1204 * wait for memory initialization to be complete 1203 * wait for memory initialization to be complete
1205 */ 1204 */
1206 i = 0; 1205 i = 0;
1207 do { 1206 do {
1208 pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg); 1207 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1209 i++; 1208 i++;
1210 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME)); 1209 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1211 1210
1212 /** 1211 /*
1213 * If memory initialization is not successful, IOC timeout will catch 1212 * If memory initialization is not successful, IOC timeout will catch
1214 * such failures. 1213 * such failures.
1215 */ 1214 */
@@ -1217,7 +1216,7 @@ bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1217 bfa_trc(ioc, pss_ctl); 1216 bfa_trc(ioc, pss_ctl);
1218 1217
1219 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN); 1218 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
1220 bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl); 1219 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1221} 1220}
1222 1221
1223static void 1222static void
@@ -1225,13 +1224,13 @@ bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1225{ 1224{
1226 u32 pss_ctl; 1225 u32 pss_ctl;
1227 1226
1228 /** 1227 /*
1229 * Take processor out of reset. 1228 * Take processor out of reset.
1230 */ 1229 */
1231 pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg); 1230 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1232 pss_ctl &= ~__PSS_LPU0_RESET; 1231 pss_ctl &= ~__PSS_LPU0_RESET;
1233 1232
1234 bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl); 1233 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1235} 1234}
1236 1235
1237static void 1236static void
@@ -1239,16 +1238,16 @@ bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1239{ 1238{
1240 u32 pss_ctl; 1239 u32 pss_ctl;
1241 1240
1242 /** 1241 /*
1243 * Put processors in reset. 1242 * Put processors in reset.
1244 */ 1243 */
1245 pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg); 1244 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1246 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET); 1245 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1247 1246
1248 bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl); 1247 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1249} 1248}
1250 1249
1251/** 1250/*
1252 * Get driver and firmware versions. 1251 * Get driver and firmware versions.
1253 */ 1252 */
1254void 1253void
@@ -1261,7 +1260,7 @@ bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1261 1260
1262 pgnum = bfa_ioc_smem_pgnum(ioc, loff); 1261 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1263 pgoff = bfa_ioc_smem_pgoff(ioc, loff); 1262 pgoff = bfa_ioc_smem_pgoff(ioc, loff);
1264 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum); 1263 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1265 1264
1266 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32)); 1265 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1267 i++) { 1266 i++) {
@@ -1271,7 +1270,7 @@ bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1271 } 1270 }
1272} 1271}
1273 1272
1274/** 1273/*
1275 * Returns TRUE if same. 1274 * Returns TRUE if same.
1276 */ 1275 */
1277bfa_boolean_t 1276bfa_boolean_t
@@ -1296,7 +1295,7 @@ bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1296 return BFA_TRUE; 1295 return BFA_TRUE;
1297} 1296}
1298 1297
1299/** 1298/*
1300 * Return true if current running version is valid. Firmware signature and 1299 * Return true if current running version is valid. Firmware signature and
1301 * execution context (driver/bios) must match. 1300 * execution context (driver/bios) must match.
1302 */ 1301 */
@@ -1305,7 +1304,7 @@ bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
1305{ 1304{
1306 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr; 1305 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1307 1306
1308 /** 1307 /*
1309 * If bios/efi boot (flash based) -- return true 1308 * If bios/efi boot (flash based) -- return true
1310 */ 1309 */
1311 if (bfa_ioc_is_bios_optrom(ioc)) 1310 if (bfa_ioc_is_bios_optrom(ioc))
@@ -1321,7 +1320,7 @@ bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
1321 return BFA_FALSE; 1320 return BFA_FALSE;
1322 } 1321 }
1323 1322
1324 if (bfa_os_swap32(fwhdr.param) != boot_env) { 1323 if (swab32(fwhdr.param) != boot_env) {
1325 bfa_trc(ioc, fwhdr.param); 1324 bfa_trc(ioc, fwhdr.param);
1326 bfa_trc(ioc, boot_env); 1325 bfa_trc(ioc, boot_env);
1327 return BFA_FALSE; 1326 return BFA_FALSE;
@@ -1330,7 +1329,7 @@ bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
1330 return bfa_ioc_fwver_cmp(ioc, &fwhdr); 1329 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1331} 1330}
1332 1331
1333/** 1332/*
1334 * Conditionally flush any pending message from firmware at start. 1333 * Conditionally flush any pending message from firmware at start.
1335 */ 1334 */
1336static void 1335static void
@@ -1338,9 +1337,9 @@ bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1338{ 1337{
1339 u32 r32; 1338 u32 r32;
1340 1339
1341 r32 = bfa_reg_read(ioc->ioc_regs.lpu_mbox_cmd); 1340 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1342 if (r32) 1341 if (r32)
1343 bfa_reg_write(ioc->ioc_regs.lpu_mbox_cmd, 1); 1342 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1344} 1343}
1345 1344
1346 1345
@@ -1352,7 +1351,7 @@ bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1352 u32 boot_type; 1351 u32 boot_type;
1353 u32 boot_env; 1352 u32 boot_env;
1354 1353
1355 ioc_fwstate = bfa_reg_read(ioc->ioc_regs.ioc_fwstate); 1354 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1356 1355
1357 if (force) 1356 if (force)
1358 ioc_fwstate = BFI_IOC_UNINIT; 1357 ioc_fwstate = BFI_IOC_UNINIT;
@@ -1362,7 +1361,7 @@ bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1362 boot_type = BFI_BOOT_TYPE_NORMAL; 1361 boot_type = BFI_BOOT_TYPE_NORMAL;
1363 boot_env = BFI_BOOT_LOADER_OS; 1362 boot_env = BFI_BOOT_LOADER_OS;
1364 1363
1365 /** 1364 /*
1366 * Flash based firmware boot BIOS env. 1365 * Flash based firmware boot BIOS env.
1367 */ 1366 */
1368 if (bfa_ioc_is_bios_optrom(ioc)) { 1367 if (bfa_ioc_is_bios_optrom(ioc)) {
@@ -1370,7 +1369,7 @@ bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1370 boot_env = BFI_BOOT_LOADER_BIOS; 1369 boot_env = BFI_BOOT_LOADER_BIOS;
1371 } 1370 }
1372 1371
1373 /** 1372 /*
1374 * Flash based firmware boot UEFI env. 1373 * Flash based firmware boot UEFI env.
1375 */ 1374 */
1376 if (bfa_ioc_is_uefi(ioc)) { 1375 if (bfa_ioc_is_uefi(ioc)) {
@@ -1378,7 +1377,7 @@ bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1378 boot_env = BFI_BOOT_LOADER_UEFI; 1377 boot_env = BFI_BOOT_LOADER_UEFI;
1379 } 1378 }
1380 1379
1381 /** 1380 /*
1382 * check if firmware is valid 1381 * check if firmware is valid
1383 */ 1382 */
1384 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ? 1383 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
@@ -1389,7 +1388,7 @@ bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1389 return; 1388 return;
1390 } 1389 }
1391 1390
1392 /** 1391 /*
1393 * If hardware initialization is in progress (initialized by other IOC), 1392 * If hardware initialization is in progress (initialized by other IOC),
1394 * just wait for an initialization completion interrupt. 1393 * just wait for an initialization completion interrupt.
1395 */ 1394 */
@@ -1398,7 +1397,7 @@ bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1398 return; 1397 return;
1399 } 1398 }
1400 1399
1401 /** 1400 /*
1402 * If IOC function is disabled and firmware version is same, 1401 * If IOC function is disabled and firmware version is same,
1403 * just re-enable IOC. 1402 * just re-enable IOC.
1404 * 1403 *
@@ -1409,7 +1408,7 @@ bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1409 if (ioc_fwstate == BFI_IOC_DISABLED || 1408 if (ioc_fwstate == BFI_IOC_DISABLED ||
1410 (!bfa_ioc_is_bios_optrom(ioc) && ioc_fwstate == BFI_IOC_OP)) { 1409 (!bfa_ioc_is_bios_optrom(ioc) && ioc_fwstate == BFI_IOC_OP)) {
1411 1410
1412 /** 1411 /*
1413 * When using MSI-X any pending firmware ready event should 1412 * When using MSI-X any pending firmware ready event should
1414 * be flushed. Otherwise MSI-X interrupts are not delivered. 1413 * be flushed. Otherwise MSI-X interrupts are not delivered.
1415 */ 1414 */
@@ -1419,7 +1418,7 @@ bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1419 return; 1418 return;
1420 } 1419 }
1421 1420
1422 /** 1421 /*
1423 * Initialize the h/w for any other states. 1422 * Initialize the h/w for any other states.
1424 */ 1423 */
1425 bfa_ioc_boot(ioc, boot_type, boot_env); 1424 bfa_ioc_boot(ioc, boot_type, boot_env);
@@ -1449,17 +1448,17 @@ bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1449 * first write msg to mailbox registers 1448 * first write msg to mailbox registers
1450 */ 1449 */
1451 for (i = 0; i < len / sizeof(u32); i++) 1450 for (i = 0; i < len / sizeof(u32); i++)
1452 bfa_reg_write(ioc->ioc_regs.hfn_mbox + i * sizeof(u32), 1451 writel(cpu_to_le32(msgp[i]),
1453 bfa_os_wtole(msgp[i])); 1452 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1454 1453
1455 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++) 1454 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
1456 bfa_reg_write(ioc->ioc_regs.hfn_mbox + i * sizeof(u32), 0); 1455 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1457 1456
1458 /* 1457 /*
1459 * write 1 to mailbox CMD to trigger LPU event 1458 * write 1 to mailbox CMD to trigger LPU event
1460 */ 1459 */
1461 bfa_reg_write(ioc->ioc_regs.hfn_mbox_cmd, 1); 1460 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1462 (void) bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd); 1461 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
1463} 1462}
1464 1463
1465static void 1464static void
@@ -1472,7 +1471,7 @@ bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1472 bfa_ioc_portid(ioc)); 1471 bfa_ioc_portid(ioc));
1473 enable_req.ioc_class = ioc->ioc_mc; 1472 enable_req.ioc_class = ioc->ioc_mc;
1474 bfa_os_gettimeofday(&tv); 1473 bfa_os_gettimeofday(&tv);
1475 enable_req.tv_sec = bfa_os_ntohl(tv.tv_sec); 1474 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
1476 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s)); 1475 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1477} 1476}
1478 1477
@@ -1503,7 +1502,7 @@ bfa_ioc_hb_check(void *cbarg)
1503 struct bfa_ioc_s *ioc = cbarg; 1502 struct bfa_ioc_s *ioc = cbarg;
1504 u32 hb_count; 1503 u32 hb_count;
1505 1504
1506 hb_count = bfa_reg_read(ioc->ioc_regs.heartbeat); 1505 hb_count = readl(ioc->ioc_regs.heartbeat);
1507 if (ioc->hb_count == hb_count) { 1506 if (ioc->hb_count == hb_count) {
1508 printk(KERN_CRIT "Firmware heartbeat failure at %d", hb_count); 1507 printk(KERN_CRIT "Firmware heartbeat failure at %d", hb_count);
1509 bfa_ioc_recover(ioc); 1508 bfa_ioc_recover(ioc);
@@ -1519,7 +1518,7 @@ bfa_ioc_hb_check(void *cbarg)
1519static void 1518static void
1520bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc) 1519bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1521{ 1520{
1522 ioc->hb_count = bfa_reg_read(ioc->ioc_regs.heartbeat); 1521 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
1523 bfa_hb_timer_start(ioc); 1522 bfa_hb_timer_start(ioc);
1524} 1523}
1525 1524
@@ -1530,7 +1529,7 @@ bfa_ioc_hb_stop(struct bfa_ioc_s *ioc)
1530} 1529}
1531 1530
1532 1531
1533/** 1532/*
1534 * Initiate a full firmware download. 1533 * Initiate a full firmware download.
1535 */ 1534 */
1536static void 1535static void
@@ -1543,7 +1542,7 @@ bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
1543 u32 chunkno = 0; 1542 u32 chunkno = 0;
1544 u32 i; 1543 u32 i;
1545 1544
1546 /** 1545 /*
1547 * Initialize LMEM first before code download 1546 * Initialize LMEM first before code download
1548 */ 1547 */
1549 bfa_ioc_lmem_init(ioc); 1548 bfa_ioc_lmem_init(ioc);
@@ -1554,7 +1553,7 @@ bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
1554 pgnum = bfa_ioc_smem_pgnum(ioc, loff); 1553 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1555 pgoff = bfa_ioc_smem_pgoff(ioc, loff); 1554 pgoff = bfa_ioc_smem_pgoff(ioc, loff);
1556 1555
1557 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum); 1556 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1558 1557
1559 for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) { 1558 for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
1560 1559
@@ -1564,7 +1563,7 @@ bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
1564 BFA_IOC_FLASH_CHUNK_ADDR(chunkno)); 1563 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
1565 } 1564 }
1566 1565
1567 /** 1566 /*
1568 * write smem 1567 * write smem
1569 */ 1568 */
1570 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 1569 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
@@ -1572,27 +1571,25 @@ bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
1572 1571
1573 loff += sizeof(u32); 1572 loff += sizeof(u32);
1574 1573
1575 /** 1574 /*
1576 * handle page offset wrap around 1575 * handle page offset wrap around
1577 */ 1576 */
1578 loff = PSS_SMEM_PGOFF(loff); 1577 loff = PSS_SMEM_PGOFF(loff);
1579 if (loff == 0) { 1578 if (loff == 0) {
1580 pgnum++; 1579 pgnum++;
1581 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, 1580 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1582 pgnum);
1583 } 1581 }
1584 } 1582 }
1585 1583
1586 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, 1584 writel(bfa_ioc_smem_pgnum(ioc, 0), ioc->ioc_regs.host_page_num_fn);
1587 bfa_ioc_smem_pgnum(ioc, 0));
1588 1585
1589 /* 1586 /*
1590 * Set boot type and boot param at the end. 1587 * Set boot type and boot param at the end.
1591 */ 1588 */
1592 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF, 1589 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
1593 bfa_os_swap32(boot_type)); 1590 swab32(boot_type));
1594 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF, 1591 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF,
1595 bfa_os_swap32(boot_env)); 1592 swab32(boot_env));
1596} 1593}
1597 1594
1598static void 1595static void
@@ -1601,7 +1598,7 @@ bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1601 bfa_ioc_hwinit(ioc, force); 1598 bfa_ioc_hwinit(ioc, force);
1602} 1599}
1603 1600
1604/** 1601/*
1605 * Update BFA configuration from firmware configuration. 1602 * Update BFA configuration from firmware configuration.
1606 */ 1603 */
1607static void 1604static void
@@ -1609,14 +1606,14 @@ bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1609{ 1606{
1610 struct bfi_ioc_attr_s *attr = ioc->attr; 1607 struct bfi_ioc_attr_s *attr = ioc->attr;
1611 1608
1612 attr->adapter_prop = bfa_os_ntohl(attr->adapter_prop); 1609 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1613 attr->card_type = bfa_os_ntohl(attr->card_type); 1610 attr->card_type = be32_to_cpu(attr->card_type);
1614 attr->maxfrsize = bfa_os_ntohs(attr->maxfrsize); 1611 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
1615 1612
1616 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR); 1613 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1617} 1614}
1618 1615
1619/** 1616/*
1620 * Attach time initialization of mbox logic. 1617 * Attach time initialization of mbox logic.
1621 */ 1618 */
1622static void 1619static void
@@ -1632,7 +1629,7 @@ bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1632 } 1629 }
1633} 1630}
1634 1631
1635/** 1632/*
1636 * Mbox poll timer -- restarts any pending mailbox requests. 1633 * Mbox poll timer -- restarts any pending mailbox requests.
1637 */ 1634 */
1638static void 1635static void
@@ -1642,27 +1639,27 @@ bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1642 struct bfa_mbox_cmd_s *cmd; 1639 struct bfa_mbox_cmd_s *cmd;
1643 u32 stat; 1640 u32 stat;
1644 1641
1645 /** 1642 /*
1646 * If no command pending, do nothing 1643 * If no command pending, do nothing
1647 */ 1644 */
1648 if (list_empty(&mod->cmd_q)) 1645 if (list_empty(&mod->cmd_q))
1649 return; 1646 return;
1650 1647
1651 /** 1648 /*
1652 * If previous command is not yet fetched by firmware, do nothing 1649 * If previous command is not yet fetched by firmware, do nothing
1653 */ 1650 */
1654 stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd); 1651 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
1655 if (stat) 1652 if (stat)
1656 return; 1653 return;
1657 1654
1658 /** 1655 /*
1659 * Enqueue command to firmware. 1656 * Enqueue command to firmware.
1660 */ 1657 */
1661 bfa_q_deq(&mod->cmd_q, &cmd); 1658 bfa_q_deq(&mod->cmd_q, &cmd);
1662 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg)); 1659 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1663} 1660}
1664 1661
1665/** 1662/*
1666 * Cleanup any pending requests. 1663 * Cleanup any pending requests.
1667 */ 1664 */
1668static void 1665static void
@@ -1675,7 +1672,7 @@ bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
1675 bfa_q_deq(&mod->cmd_q, &cmd); 1672 bfa_q_deq(&mod->cmd_q, &cmd);
1676} 1673}
1677 1674
1678/** 1675/*
1679 * Read data from SMEM to host through PCI memmap 1676 * Read data from SMEM to host through PCI memmap
1680 * 1677 *
1681 * @param[in] ioc memory for IOC 1678 * @param[in] ioc memory for IOC
@@ -1704,26 +1701,25 @@ bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1704 return BFA_STATUS_FAILED; 1701 return BFA_STATUS_FAILED;
1705 } 1702 }
1706 1703
1707 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum); 1704 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1708 1705
1709 len = sz/sizeof(u32); 1706 len = sz/sizeof(u32);
1710 bfa_trc(ioc, len); 1707 bfa_trc(ioc, len);
1711 for (i = 0; i < len; i++) { 1708 for (i = 0; i < len; i++) {
1712 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff); 1709 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
1713 buf[i] = bfa_os_ntohl(r32); 1710 buf[i] = be32_to_cpu(r32);
1714 loff += sizeof(u32); 1711 loff += sizeof(u32);
1715 1712
1716 /** 1713 /*
1717 * handle page offset wrap around 1714 * handle page offset wrap around
1718 */ 1715 */
1719 loff = PSS_SMEM_PGOFF(loff); 1716 loff = PSS_SMEM_PGOFF(loff);
1720 if (loff == 0) { 1717 if (loff == 0) {
1721 pgnum++; 1718 pgnum++;
1722 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum); 1719 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1723 } 1720 }
1724 } 1721 }
1725 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, 1722 writel(bfa_ioc_smem_pgnum(ioc, 0), ioc->ioc_regs.host_page_num_fn);
1726 bfa_ioc_smem_pgnum(ioc, 0));
1727 /* 1723 /*
1728 * release semaphore. 1724 * release semaphore.
1729 */ 1725 */
@@ -1733,7 +1729,7 @@ bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1733 return BFA_STATUS_OK; 1729 return BFA_STATUS_OK;
1734} 1730}
1735 1731
1736/** 1732/*
1737 * Clear SMEM data from host through PCI memmap 1733 * Clear SMEM data from host through PCI memmap
1738 * 1734 *
1739 * @param[in] ioc memory for IOC 1735 * @param[in] ioc memory for IOC
@@ -1760,7 +1756,7 @@ bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1760 return BFA_STATUS_FAILED; 1756 return BFA_STATUS_FAILED;
1761 } 1757 }
1762 1758
1763 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum); 1759 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1764 1760
1765 len = sz/sizeof(u32); /* len in words */ 1761 len = sz/sizeof(u32); /* len in words */
1766 bfa_trc(ioc, len); 1762 bfa_trc(ioc, len);
@@ -1768,17 +1764,16 @@ bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1768 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0); 1764 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1769 loff += sizeof(u32); 1765 loff += sizeof(u32);
1770 1766
1771 /** 1767 /*
1772 * handle page offset wrap around 1768 * handle page offset wrap around
1773 */ 1769 */
1774 loff = PSS_SMEM_PGOFF(loff); 1770 loff = PSS_SMEM_PGOFF(loff);
1775 if (loff == 0) { 1771 if (loff == 0) {
1776 pgnum++; 1772 pgnum++;
1777 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum); 1773 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1778 } 1774 }
1779 } 1775 }
1780 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, 1776 writel(bfa_ioc_smem_pgnum(ioc, 0), ioc->ioc_regs.host_page_num_fn);
1781 bfa_ioc_smem_pgnum(ioc, 0));
1782 1777
1783 /* 1778 /*
1784 * release semaphore. 1779 * release semaphore.
@@ -1788,7 +1783,7 @@ bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1788 return BFA_STATUS_OK; 1783 return BFA_STATUS_OK;
1789} 1784}
1790 1785
1791/** 1786/*
1792 * hal iocpf to ioc interface 1787 * hal iocpf to ioc interface
1793 */ 1788 */
1794static void 1789static void
@@ -1813,7 +1808,7 @@ static void
1813bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc) 1808bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1814{ 1809{
1815 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; 1810 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1816 /** 1811 /*
1817 * Provide enable completion callback. 1812 * Provide enable completion callback.
1818 */ 1813 */
1819 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); 1814 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
@@ -1824,7 +1819,7 @@ bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1824 1819
1825 1820
1826 1821
1827/** 1822/*
1828 * hal_ioc_public 1823 * hal_ioc_public
1829 */ 1824 */
1830 1825
@@ -1848,43 +1843,43 @@ bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1848 return BFA_STATUS_OK; 1843 return BFA_STATUS_OK;
1849} 1844}
1850 1845
1851/** 1846/*
1852 * Interface used by diag module to do firmware boot with memory test 1847 * Interface used by diag module to do firmware boot with memory test
1853 * as the entry vector. 1848 * as the entry vector.
1854 */ 1849 */
1855void 1850void
1856bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env) 1851bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
1857{ 1852{
1858 bfa_os_addr_t rb; 1853 void __iomem *rb;
1859 1854
1860 bfa_ioc_stats(ioc, ioc_boots); 1855 bfa_ioc_stats(ioc, ioc_boots);
1861 1856
1862 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK) 1857 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1863 return; 1858 return;
1864 1859
1865 /** 1860 /*
1866 * Initialize IOC state of all functions on a chip reset. 1861 * Initialize IOC state of all functions on a chip reset.
1867 */ 1862 */
1868 rb = ioc->pcidev.pci_bar_kva; 1863 rb = ioc->pcidev.pci_bar_kva;
1869 if (boot_type == BFI_BOOT_TYPE_MEMTEST) { 1864 if (boot_type == BFI_BOOT_TYPE_MEMTEST) {
1870 bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_MEMTEST); 1865 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
1871 bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_MEMTEST); 1866 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
1872 } else { 1867 } else {
1873 bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_INITING); 1868 writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
1874 bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_INITING); 1869 writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
1875 } 1870 }
1876 1871
1877 bfa_ioc_msgflush(ioc); 1872 bfa_ioc_msgflush(ioc);
1878 bfa_ioc_download_fw(ioc, boot_type, boot_env); 1873 bfa_ioc_download_fw(ioc, boot_type, boot_env);
1879 1874
1880 /** 1875 /*
1881 * Enable interrupts just before starting LPU 1876 * Enable interrupts just before starting LPU
1882 */ 1877 */
1883 ioc->cbfn->reset_cbfn(ioc->bfa); 1878 ioc->cbfn->reset_cbfn(ioc->bfa);
1884 bfa_ioc_lpu_start(ioc); 1879 bfa_ioc_lpu_start(ioc);
1885} 1880}
1886 1881
1887/** 1882/*
1888 * Enable/disable IOC failure auto recovery. 1883 * Enable/disable IOC failure auto recovery.
1889 */ 1884 */
1890void 1885void
@@ -1904,7 +1899,7 @@ bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
1904bfa_boolean_t 1899bfa_boolean_t
1905bfa_ioc_is_initialized(struct bfa_ioc_s *ioc) 1900bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
1906{ 1901{
1907 u32 r32 = bfa_reg_read(ioc->ioc_regs.ioc_fwstate); 1902 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
1908 1903
1909 return ((r32 != BFI_IOC_UNINIT) && 1904 return ((r32 != BFI_IOC_UNINIT) &&
1910 (r32 != BFI_IOC_INITING) && 1905 (r32 != BFI_IOC_INITING) &&
@@ -1918,21 +1913,21 @@ bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
1918 u32 r32; 1913 u32 r32;
1919 int i; 1914 int i;
1920 1915
1921 /** 1916 /*
1922 * read the MBOX msg 1917 * read the MBOX msg
1923 */ 1918 */
1924 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32)); 1919 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1925 i++) { 1920 i++) {
1926 r32 = bfa_reg_read(ioc->ioc_regs.lpu_mbox + 1921 r32 = readl(ioc->ioc_regs.lpu_mbox +
1927 i * sizeof(u32)); 1922 i * sizeof(u32));
1928 msgp[i] = bfa_os_htonl(r32); 1923 msgp[i] = cpu_to_be32(r32);
1929 } 1924 }
1930 1925
1931 /** 1926 /*
1932 * turn off mailbox interrupt by clearing mailbox status 1927 * turn off mailbox interrupt by clearing mailbox status
1933 */ 1928 */
1934 bfa_reg_write(ioc->ioc_regs.lpu_mbox_cmd, 1); 1929 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1935 bfa_reg_read(ioc->ioc_regs.lpu_mbox_cmd); 1930 readl(ioc->ioc_regs.lpu_mbox_cmd);
1936} 1931}
1937 1932
1938void 1933void
@@ -1971,7 +1966,7 @@ bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
1971 } 1966 }
1972} 1967}
1973 1968
1974/** 1969/*
1975 * IOC attach time initialization and setup. 1970 * IOC attach time initialization and setup.
1976 * 1971 *
1977 * @param[in] ioc memory for IOC 1972 * @param[in] ioc memory for IOC
@@ -1996,7 +1991,7 @@ bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
1996 bfa_fsm_send_event(ioc, IOC_E_RESET); 1991 bfa_fsm_send_event(ioc, IOC_E_RESET);
1997} 1992}
1998 1993
1999/** 1994/*
2000 * Driver detach time IOC cleanup. 1995 * Driver detach time IOC cleanup.
2001 */ 1996 */
2002void 1997void
@@ -2005,7 +2000,7 @@ bfa_ioc_detach(struct bfa_ioc_s *ioc)
2005 bfa_fsm_send_event(ioc, IOC_E_DETACH); 2000 bfa_fsm_send_event(ioc, IOC_E_DETACH);
2006} 2001}
2007 2002
2008/** 2003/*
2009 * Setup IOC PCI properties. 2004 * Setup IOC PCI properties.
2010 * 2005 *
2011 * @param[in] pcidev PCI device information for this IOC 2006 * @param[in] pcidev PCI device information for this IOC
@@ -2019,7 +2014,7 @@ bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
2019 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id); 2014 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
2020 ioc->cna = ioc->ctdev && !ioc->fcmode; 2015 ioc->cna = ioc->ctdev && !ioc->fcmode;
2021 2016
2022 /** 2017 /*
2023 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c 2018 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2024 */ 2019 */
2025 if (ioc->ctdev) 2020 if (ioc->ctdev)
@@ -2031,7 +2026,7 @@ bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
2031 bfa_ioc_reg_init(ioc); 2026 bfa_ioc_reg_init(ioc);
2032} 2027}
2033 2028
2034/** 2029/*
2035 * Initialize IOC dma memory 2030 * Initialize IOC dma memory
2036 * 2031 *
2037 * @param[in] dm_kva kernel virtual address of IOC dma memory 2032 * @param[in] dm_kva kernel virtual address of IOC dma memory
@@ -2040,7 +2035,7 @@ bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
2040void 2035void
2041bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa) 2036bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
2042{ 2037{
2043 /** 2038 /*
2044 * dma memory for firmware attribute 2039 * dma memory for firmware attribute
2045 */ 2040 */
2046 ioc->attr_dma.kva = dm_kva; 2041 ioc->attr_dma.kva = dm_kva;
@@ -2048,7 +2043,7 @@ bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
2048 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva; 2043 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
2049} 2044}
2050 2045
2051/** 2046/*
2052 * Return size of dma memory required. 2047 * Return size of dma memory required.
2053 */ 2048 */
2054u32 2049u32
@@ -2073,7 +2068,7 @@ bfa_ioc_disable(struct bfa_ioc_s *ioc)
2073 bfa_fsm_send_event(ioc, IOC_E_DISABLE); 2068 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2074} 2069}
2075 2070
2076/** 2071/*
2077 * Returns memory required for saving firmware trace in case of crash. 2072 * Returns memory required for saving firmware trace in case of crash.
2078 * Driver must call this interface to allocate memory required for 2073 * Driver must call this interface to allocate memory required for
2079 * automatic saving of firmware trace. Driver should call 2074 * automatic saving of firmware trace. Driver should call
@@ -2086,7 +2081,7 @@ bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover)
2086 return (auto_recover) ? BFA_DBG_FWTRC_LEN : 0; 2081 return (auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
2087} 2082}
2088 2083
2089/** 2084/*
2090 * Initialize memory for saving firmware trace. Driver must initialize 2085 * Initialize memory for saving firmware trace. Driver must initialize
2091 * trace memory before call bfa_ioc_enable(). 2086 * trace memory before call bfa_ioc_enable().
2092 */ 2087 */
@@ -2109,7 +2104,7 @@ bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr)
2109 return PSS_SMEM_PGOFF(fmaddr); 2104 return PSS_SMEM_PGOFF(fmaddr);
2110} 2105}
2111 2106
2112/** 2107/*
2113 * Register mailbox message handler functions 2108 * Register mailbox message handler functions
2114 * 2109 *
2115 * @param[in] ioc IOC instance 2110 * @param[in] ioc IOC instance
@@ -2125,7 +2120,7 @@ bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2125 mod->mbhdlr[mc].cbfn = mcfuncs[mc]; 2120 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2126} 2121}
2127 2122
2128/** 2123/*
2129 * Register mailbox message handler function, to be called by common modules 2124 * Register mailbox message handler function, to be called by common modules
2130 */ 2125 */
2131void 2126void
@@ -2138,7 +2133,7 @@ bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2138 mod->mbhdlr[mc].cbarg = cbarg; 2133 mod->mbhdlr[mc].cbarg = cbarg;
2139} 2134}
2140 2135
2141/** 2136/*
2142 * Queue a mailbox command request to firmware. Waits if mailbox is busy. 2137 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2143 * Responsibility of caller to serialize 2138 * Responsibility of caller to serialize
2144 * 2139 *
@@ -2151,7 +2146,7 @@ bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2151 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; 2146 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2152 u32 stat; 2147 u32 stat;
2153 2148
2154 /** 2149 /*
2155 * If a previous command is pending, queue new command 2150 * If a previous command is pending, queue new command
2156 */ 2151 */
2157 if (!list_empty(&mod->cmd_q)) { 2152 if (!list_empty(&mod->cmd_q)) {
@@ -2159,22 +2154,22 @@ bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2159 return; 2154 return;
2160 } 2155 }
2161 2156
2162 /** 2157 /*
2163 * If mailbox is busy, queue command for poll timer 2158 * If mailbox is busy, queue command for poll timer
2164 */ 2159 */
2165 stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd); 2160 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
2166 if (stat) { 2161 if (stat) {
2167 list_add_tail(&cmd->qe, &mod->cmd_q); 2162 list_add_tail(&cmd->qe, &mod->cmd_q);
2168 return; 2163 return;
2169 } 2164 }
2170 2165
2171 /** 2166 /*
2172 * mailbox is free -- queue command to firmware 2167 * mailbox is free -- queue command to firmware
2173 */ 2168 */
2174 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg)); 2169 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2175} 2170}
2176 2171
2177/** 2172/*
2178 * Handle mailbox interrupts 2173 * Handle mailbox interrupts
2179 */ 2174 */
2180void 2175void
@@ -2186,7 +2181,7 @@ bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2186 2181
2187 bfa_ioc_msgget(ioc, &m); 2182 bfa_ioc_msgget(ioc, &m);
2188 2183
2189 /** 2184 /*
2190 * Treat IOC message class as special. 2185 * Treat IOC message class as special.
2191 */ 2186 */
2192 mc = m.mh.msg_class; 2187 mc = m.mh.msg_class;
@@ -2214,7 +2209,7 @@ bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
2214 ioc->port_id = bfa_ioc_pcifn(ioc); 2209 ioc->port_id = bfa_ioc_pcifn(ioc);
2215} 2210}
2216 2211
2217/** 2212/*
2218 * return true if IOC is disabled 2213 * return true if IOC is disabled
2219 */ 2214 */
2220bfa_boolean_t 2215bfa_boolean_t
@@ -2224,7 +2219,7 @@ bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2224 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled); 2219 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
2225} 2220}
2226 2221
2227/** 2222/*
2228 * return true if IOC firmware is different. 2223 * return true if IOC firmware is different.
2229 */ 2224 */
2230bfa_boolean_t 2225bfa_boolean_t
@@ -2243,7 +2238,7 @@ bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2243 ((__sm) == BFI_IOC_FAIL) || \ 2238 ((__sm) == BFI_IOC_FAIL) || \
2244 ((__sm) == BFI_IOC_CFG_DISABLED)) 2239 ((__sm) == BFI_IOC_CFG_DISABLED))
2245 2240
2246/** 2241/*
2247 * Check if adapter is disabled -- both IOCs should be in a disabled 2242 * Check if adapter is disabled -- both IOCs should be in a disabled
2248 * state. 2243 * state.
2249 */ 2244 */
@@ -2251,17 +2246,17 @@ bfa_boolean_t
2251bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc) 2246bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2252{ 2247{
2253 u32 ioc_state; 2248 u32 ioc_state;
2254 bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva; 2249 void __iomem *rb = ioc->pcidev.pci_bar_kva;
2255 2250
2256 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled)) 2251 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2257 return BFA_FALSE; 2252 return BFA_FALSE;
2258 2253
2259 ioc_state = bfa_reg_read(rb + BFA_IOC0_STATE_REG); 2254 ioc_state = readl(rb + BFA_IOC0_STATE_REG);
2260 if (!bfa_ioc_state_disabled(ioc_state)) 2255 if (!bfa_ioc_state_disabled(ioc_state))
2261 return BFA_FALSE; 2256 return BFA_FALSE;
2262 2257
2263 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) { 2258 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
2264 ioc_state = bfa_reg_read(rb + BFA_IOC1_STATE_REG); 2259 ioc_state = readl(rb + BFA_IOC1_STATE_REG);
2265 if (!bfa_ioc_state_disabled(ioc_state)) 2260 if (!bfa_ioc_state_disabled(ioc_state))
2266 return BFA_FALSE; 2261 return BFA_FALSE;
2267 } 2262 }
@@ -2269,7 +2264,7 @@ bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2269 return BFA_TRUE; 2264 return BFA_TRUE;
2270} 2265}
2271 2266
2272/** 2267/*
2273 * Add to IOC heartbeat failure notification queue. To be used by common 2268 * Add to IOC heartbeat failure notification queue. To be used by common
2274 * modules such as cee, port, diag. 2269 * modules such as cee, port, diag.
2275 */ 2270 */
@@ -2293,7 +2288,7 @@ bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2293 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver); 2288 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2294 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver); 2289 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2295 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer); 2290 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
2296 bfa_os_memcpy(&ad_attr->vpd, &ioc_attr->vpd, 2291 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
2297 sizeof(struct bfa_mfg_vpd_s)); 2292 sizeof(struct bfa_mfg_vpd_s));
2298 2293
2299 ad_attr->nports = bfa_ioc_get_nports(ioc); 2294 ad_attr->nports = bfa_ioc_get_nports(ioc);
@@ -2343,8 +2338,8 @@ bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2343void 2338void
2344bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num) 2339bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2345{ 2340{
2346 bfa_os_memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN); 2341 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2347 bfa_os_memcpy((void *)serial_num, 2342 memcpy((void *)serial_num,
2348 (void *)ioc->attr->brcd_serialnum, 2343 (void *)ioc->attr->brcd_serialnum,
2349 BFA_ADAPTER_SERIAL_NUM_LEN); 2344 BFA_ADAPTER_SERIAL_NUM_LEN);
2350} 2345}
@@ -2352,8 +2347,8 @@ bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2352void 2347void
2353bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver) 2348bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2354{ 2349{
2355 bfa_os_memset((void *)fw_ver, 0, BFA_VERSION_LEN); 2350 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2356 bfa_os_memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN); 2351 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
2357} 2352}
2358 2353
2359void 2354void
@@ -2361,7 +2356,7 @@ bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2361{ 2356{
2362 bfa_assert(chip_rev); 2357 bfa_assert(chip_rev);
2363 2358
2364 bfa_os_memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN); 2359 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
2365 2360
2366 chip_rev[0] = 'R'; 2361 chip_rev[0] = 'R';
2367 chip_rev[1] = 'e'; 2362 chip_rev[1] = 'e';
@@ -2374,16 +2369,16 @@ bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2374void 2369void
2375bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver) 2370bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2376{ 2371{
2377 bfa_os_memset((void *)optrom_ver, 0, BFA_VERSION_LEN); 2372 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2378 bfa_os_memcpy(optrom_ver, ioc->attr->optrom_version, 2373 memcpy(optrom_ver, ioc->attr->optrom_version,
2379 BFA_VERSION_LEN); 2374 BFA_VERSION_LEN);
2380} 2375}
2381 2376
2382void 2377void
2383bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer) 2378bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2384{ 2379{
2385 bfa_os_memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN); 2380 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2386 bfa_os_memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); 2381 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
2387} 2382}
2388 2383
2389void 2384void
@@ -2392,14 +2387,14 @@ bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2392 struct bfi_ioc_attr_s *ioc_attr; 2387 struct bfi_ioc_attr_s *ioc_attr;
2393 2388
2394 bfa_assert(model); 2389 bfa_assert(model);
2395 bfa_os_memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN); 2390 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
2396 2391
2397 ioc_attr = ioc->attr; 2392 ioc_attr = ioc->attr;
2398 2393
2399 /** 2394 /*
2400 * model name 2395 * model name
2401 */ 2396 */
2402 bfa_os_snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u", 2397 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2403 BFA_MFG_NAME, ioc_attr->card_type); 2398 BFA_MFG_NAME, ioc_attr->card_type);
2404} 2399}
2405 2400
@@ -2446,7 +2441,7 @@ bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2446void 2441void
2447bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr) 2442bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2448{ 2443{
2449 bfa_os_memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s)); 2444 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
2450 2445
2451 ioc_attr->state = bfa_ioc_get_state(ioc); 2446 ioc_attr->state = bfa_ioc_get_state(ioc);
2452 ioc_attr->port_id = ioc->port_id; 2447 ioc_attr->port_id = ioc->port_id;
@@ -2460,7 +2455,7 @@ bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2460 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev); 2455 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
2461} 2456}
2462 2457
2463/** 2458/*
2464 * hal_wwn_public 2459 * hal_wwn_public
2465 */ 2460 */
2466wwn_t 2461wwn_t
@@ -2526,7 +2521,7 @@ bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
2526 return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id); 2521 return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
2527} 2522}
2528 2523
2529/** 2524/*
2530 * Retrieve saved firmware trace from a prior IOC failure. 2525 * Retrieve saved firmware trace from a prior IOC failure.
2531 */ 2526 */
2532bfa_status_t 2527bfa_status_t
@@ -2541,12 +2536,12 @@ bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2541 if (tlen > ioc->dbg_fwsave_len) 2536 if (tlen > ioc->dbg_fwsave_len)
2542 tlen = ioc->dbg_fwsave_len; 2537 tlen = ioc->dbg_fwsave_len;
2543 2538
2544 bfa_os_memcpy(trcdata, ioc->dbg_fwsave, tlen); 2539 memcpy(trcdata, ioc->dbg_fwsave, tlen);
2545 *trclen = tlen; 2540 *trclen = tlen;
2546 return BFA_STATUS_OK; 2541 return BFA_STATUS_OK;
2547} 2542}
2548 2543
2549/** 2544/*
2550 * Clear saved firmware trace 2545 * Clear saved firmware trace
2551 */ 2546 */
2552void 2547void
@@ -2555,7 +2550,7 @@ bfa_ioc_debug_fwsave_clear(struct bfa_ioc_s *ioc)
2555 ioc->dbg_fwsave_once = BFA_TRUE; 2550 ioc->dbg_fwsave_once = BFA_TRUE;
2556} 2551}
2557 2552
2558/** 2553/*
2559 * Retrieve saved firmware trace from a prior IOC failure. 2554 * Retrieve saved firmware trace from a prior IOC failure.
2560 */ 2555 */
2561bfa_status_t 2556bfa_status_t
@@ -2595,7 +2590,7 @@ bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2595 2590
2596 bfa_ioc_send_fwsync(ioc); 2591 bfa_ioc_send_fwsync(ioc);
2597 2592
2598 /** 2593 /*
2599 * After sending a fw sync mbox command wait for it to 2594 * After sending a fw sync mbox command wait for it to
2600 * take effect. We will not wait for a response because 2595 * take effect. We will not wait for a response because
2601 * 1. fw_sync mbox cmd doesn't have a response. 2596 * 1. fw_sync mbox cmd doesn't have a response.
@@ -2610,7 +2605,7 @@ bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2610 fwsync_iter--; 2605 fwsync_iter--;
2611} 2606}
2612 2607
2613/** 2608/*
2614 * Dump firmware smem 2609 * Dump firmware smem
2615 */ 2610 */
2616bfa_status_t 2611bfa_status_t
@@ -2630,7 +2625,7 @@ bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2630 loff = *offset; 2625 loff = *offset;
2631 dlen = *buflen; 2626 dlen = *buflen;
2632 2627
2633 /** 2628 /*
2634 * First smem read, sync smem before proceeding 2629 * First smem read, sync smem before proceeding
2635 * No need to sync before reading every chunk. 2630 * No need to sync before reading every chunk.
2636 */ 2631 */
@@ -2657,7 +2652,7 @@ bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2657 return status; 2652 return status;
2658} 2653}
2659 2654
2660/** 2655/*
2661 * Firmware statistics 2656 * Firmware statistics
2662 */ 2657 */
2663bfa_status_t 2658bfa_status_t
@@ -2702,7 +2697,7 @@ bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2702 return status; 2697 return status;
2703} 2698}
2704 2699
2705/** 2700/*
2706 * Save firmware trace if configured. 2701 * Save firmware trace if configured.
2707 */ 2702 */
2708static void 2703static void
@@ -2716,7 +2711,7 @@ bfa_ioc_debug_save(struct bfa_ioc_s *ioc)
2716 } 2711 }
2717} 2712}
2718 2713
2719/** 2714/*
2720 * Firmware failure detected. Start recovery actions. 2715 * Firmware failure detected. Start recovery actions.
2721 */ 2716 */
2722static void 2717static void
@@ -2738,7 +2733,7 @@ bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
2738 return; 2733 return;
2739} 2734}
2740 2735
2741/** 2736/*
2742 * hal_iocpf_pvt BFA IOC PF private functions 2737 * hal_iocpf_pvt BFA IOC PF private functions
2743 */ 2738 */
2744 2739
@@ -2795,7 +2790,7 @@ bfa_iocpf_sem_timeout(void *ioc_arg)
2795 bfa_ioc_hw_sem_get(ioc); 2790 bfa_ioc_hw_sem_get(ioc);
2796} 2791}
2797 2792
2798/** 2793/*
2799 * bfa timer function 2794 * bfa timer function
2800 */ 2795 */
2801void 2796void
@@ -2840,7 +2835,7 @@ bfa_timer_beat(struct bfa_timer_mod_s *mod)
2840 } 2835 }
2841} 2836}
2842 2837
2843/** 2838/*
2844 * Should be called with lock protection 2839 * Should be called with lock protection
2845 */ 2840 */
2846void 2841void
@@ -2858,7 +2853,7 @@ bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2858 list_add_tail(&timer->qe, &mod->timer_q); 2853 list_add_tail(&timer->qe, &mod->timer_q);
2859} 2854}
2860 2855
2861/** 2856/*
2862 * Should be called with lock protection 2857 * Should be called with lock protection
2863 */ 2858 */
2864void 2859void
diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
index 288c5801aace..9c407a87a1a1 100644
--- a/drivers/scsi/bfa/bfa_ioc.h
+++ b/drivers/scsi/bfa/bfa_ioc.h
@@ -22,29 +22,29 @@
22#include "bfa_cs.h" 22#include "bfa_cs.h"
23#include "bfi.h" 23#include "bfi.h"
24 24
25/** 25/*
26 * BFA timer declarations 26 * BFA timer declarations
27 */ 27 */
28typedef void (*bfa_timer_cbfn_t)(void *); 28typedef void (*bfa_timer_cbfn_t)(void *);
29 29
30/** 30/*
31 * BFA timer data structure 31 * BFA timer data structure
32 */ 32 */
33struct bfa_timer_s { 33struct bfa_timer_s {
34 struct list_head qe; 34 struct list_head qe;
35 bfa_timer_cbfn_t timercb; 35 bfa_timer_cbfn_t timercb;
36 void *arg; 36 void *arg;
37 int timeout; /**< in millisecs. */ 37 int timeout; /* in millisecs */
38}; 38};
39 39
40/** 40/*
41 * Timer module structure 41 * Timer module structure
42 */ 42 */
43struct bfa_timer_mod_s { 43struct bfa_timer_mod_s {
44 struct list_head timer_q; 44 struct list_head timer_q;
45}; 45};
46 46
47#define BFA_TIMER_FREQ 200 /**< specified in millisecs */ 47#define BFA_TIMER_FREQ 200 /* specified in millisecs */
48 48
49void bfa_timer_beat(struct bfa_timer_mod_s *mod); 49void bfa_timer_beat(struct bfa_timer_mod_s *mod);
50void bfa_timer_init(struct bfa_timer_mod_s *mod); 50void bfa_timer_init(struct bfa_timer_mod_s *mod);
@@ -53,7 +53,7 @@ void bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
53 unsigned int timeout); 53 unsigned int timeout);
54void bfa_timer_stop(struct bfa_timer_s *timer); 54void bfa_timer_stop(struct bfa_timer_s *timer);
55 55
56/** 56/*
57 * Generic Scatter Gather Element used by driver 57 * Generic Scatter Gather Element used by driver
58 */ 58 */
59struct bfa_sge_s { 59struct bfa_sge_s {
@@ -62,9 +62,9 @@ struct bfa_sge_s {
62}; 62};
63 63
64#define bfa_sge_word_swap(__sge) do { \ 64#define bfa_sge_word_swap(__sge) do { \
65 ((u32 *)(__sge))[0] = bfa_os_swap32(((u32 *)(__sge))[0]); \ 65 ((u32 *)(__sge))[0] = swab32(((u32 *)(__sge))[0]); \
66 ((u32 *)(__sge))[1] = bfa_os_swap32(((u32 *)(__sge))[1]); \ 66 ((u32 *)(__sge))[1] = swab32(((u32 *)(__sge))[1]); \
67 ((u32 *)(__sge))[2] = bfa_os_swap32(((u32 *)(__sge))[2]); \ 67 ((u32 *)(__sge))[2] = swab32(((u32 *)(__sge))[2]); \
68} while (0) 68} while (0)
69 69
70#define bfa_swap_words(_x) ( \ 70#define bfa_swap_words(_x) ( \
@@ -80,17 +80,17 @@ struct bfa_sge_s {
80#define bfa_sgaddr_le(_x) (_x) 80#define bfa_sgaddr_le(_x) (_x)
81#endif 81#endif
82 82
83/** 83/*
84 * PCI device information required by IOC 84 * PCI device information required by IOC
85 */ 85 */
86struct bfa_pcidev_s { 86struct bfa_pcidev_s {
87 int pci_slot; 87 int pci_slot;
88 u8 pci_func; 88 u8 pci_func;
89 u16 device_id; 89 u16 device_id;
90 bfa_os_addr_t pci_bar_kva; 90 void __iomem *pci_bar_kva;
91}; 91};
92 92
93/** 93/*
94 * Structure used to remember the DMA-able memory block's KVA and Physical 94 * Structure used to remember the DMA-able memory block's KVA and Physical
95 * Address 95 * Address
96 */ 96 */
@@ -102,7 +102,7 @@ struct bfa_dma_s {
102#define BFA_DMA_ALIGN_SZ 256 102#define BFA_DMA_ALIGN_SZ 256
103#define BFA_ROUNDUP(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1)) 103#define BFA_ROUNDUP(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
104 104
105/** 105/*
106 * smem size for Crossbow and Catapult 106 * smem size for Crossbow and Catapult
107 */ 107 */
108#define BFI_SMEM_CB_SIZE 0x200000U /* ! 2MB for crossbow */ 108#define BFI_SMEM_CB_SIZE 0x200000U /* ! 2MB for crossbow */
@@ -125,40 +125,38 @@ __bfa_dma_addr_set(union bfi_addr_u *dma_addr, u64 pa)
125static inline void 125static inline void
126__bfa_dma_be_addr_set(union bfi_addr_u *dma_addr, u64 pa) 126__bfa_dma_be_addr_set(union bfi_addr_u *dma_addr, u64 pa)
127{ 127{
128 dma_addr->a32.addr_lo = (u32) bfa_os_htonl(pa); 128 dma_addr->a32.addr_lo = (u32) cpu_to_be32(pa);
129 dma_addr->a32.addr_hi = (u32) bfa_os_htonl(bfa_os_u32(pa)); 129 dma_addr->a32.addr_hi = (u32) cpu_to_be32(bfa_os_u32(pa));
130} 130}
131 131
132struct bfa_ioc_regs_s { 132struct bfa_ioc_regs_s {
133 bfa_os_addr_t hfn_mbox_cmd; 133 void __iomem *hfn_mbox_cmd;
134 bfa_os_addr_t hfn_mbox; 134 void __iomem *hfn_mbox;
135 bfa_os_addr_t lpu_mbox_cmd; 135 void __iomem *lpu_mbox_cmd;
136 bfa_os_addr_t lpu_mbox; 136 void __iomem *lpu_mbox;
137 bfa_os_addr_t pss_ctl_reg; 137 void __iomem *pss_ctl_reg;
138 bfa_os_addr_t pss_err_status_reg; 138 void __iomem *pss_err_status_reg;
139 bfa_os_addr_t app_pll_fast_ctl_reg; 139 void __iomem *app_pll_fast_ctl_reg;
140 bfa_os_addr_t app_pll_slow_ctl_reg; 140 void __iomem *app_pll_slow_ctl_reg;
141 bfa_os_addr_t ioc_sem_reg; 141 void __iomem *ioc_sem_reg;
142 bfa_os_addr_t ioc_usage_sem_reg; 142 void __iomem *ioc_usage_sem_reg;
143 bfa_os_addr_t ioc_init_sem_reg; 143 void __iomem *ioc_init_sem_reg;
144 bfa_os_addr_t ioc_usage_reg; 144 void __iomem *ioc_usage_reg;
145 bfa_os_addr_t host_page_num_fn; 145 void __iomem *host_page_num_fn;
146 bfa_os_addr_t heartbeat; 146 void __iomem *heartbeat;
147 bfa_os_addr_t ioc_fwstate; 147 void __iomem *ioc_fwstate;
148 bfa_os_addr_t ll_halt; 148 void __iomem *ll_halt;
149 bfa_os_addr_t err_set; 149 void __iomem *err_set;
150 bfa_os_addr_t shirq_isr_next; 150 void __iomem *shirq_isr_next;
151 bfa_os_addr_t shirq_msk_next; 151 void __iomem *shirq_msk_next;
152 bfa_os_addr_t smem_page_start; 152 void __iomem *smem_page_start;
153 u32 smem_pg0; 153 u32 smem_pg0;
154}; 154};
155 155
156#define bfa_reg_read(_raddr) bfa_os_reg_read(_raddr) 156#define bfa_mem_read(_raddr, _off) swab32(readl(((_raddr) + (_off))))
157#define bfa_reg_write(_raddr, _val) bfa_os_reg_write(_raddr, _val)
158#define bfa_mem_read(_raddr, _off) bfa_os_mem_read(_raddr, _off)
159#define bfa_mem_write(_raddr, _off, _val) \ 157#define bfa_mem_write(_raddr, _off, _val) \
160 bfa_os_mem_write(_raddr, _off, _val) 158 writel(swab32((_val)), ((_raddr) + (_off)))
161/** 159/*
162 * IOC Mailbox structures 160 * IOC Mailbox structures
163 */ 161 */
164struct bfa_mbox_cmd_s { 162struct bfa_mbox_cmd_s {
@@ -166,7 +164,7 @@ struct bfa_mbox_cmd_s {
166 u32 msg[BFI_IOC_MSGSZ]; 164 u32 msg[BFI_IOC_MSGSZ];
167}; 165};
168 166
169/** 167/*
170 * IOC mailbox module 168 * IOC mailbox module
171 */ 169 */
172typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m); 170typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m);
@@ -179,7 +177,7 @@ struct bfa_ioc_mbox_mod_s {
179 } mbhdlr[BFI_MC_MAX]; 177 } mbhdlr[BFI_MC_MAX];
180}; 178};
181 179
182/** 180/*
183 * IOC callback function interfaces 181 * IOC callback function interfaces
184 */ 182 */
185typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status); 183typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
@@ -193,7 +191,7 @@ struct bfa_ioc_cbfn_s {
193 bfa_ioc_reset_cbfn_t reset_cbfn; 191 bfa_ioc_reset_cbfn_t reset_cbfn;
194}; 192};
195 193
196/** 194/*
197 * Heartbeat failure notification queue element. 195 * Heartbeat failure notification queue element.
198 */ 196 */
199struct bfa_ioc_hbfail_notify_s { 197struct bfa_ioc_hbfail_notify_s {
@@ -202,7 +200,7 @@ struct bfa_ioc_hbfail_notify_s {
202 void *cbarg; 200 void *cbarg;
203}; 201};
204 202
205/** 203/*
206 * Initialize a heartbeat failure notification structure 204 * Initialize a heartbeat failure notification structure
207 */ 205 */
208#define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \ 206#define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \
@@ -249,7 +247,7 @@ struct bfa_ioc_s {
249}; 247};
250 248
251struct bfa_ioc_hwif_s { 249struct bfa_ioc_hwif_s {
252 bfa_status_t (*ioc_pll_init) (bfa_os_addr_t rb, bfa_boolean_t fcmode); 250 bfa_status_t (*ioc_pll_init) (void __iomem *rb, bfa_boolean_t fcmode);
253 bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc); 251 bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc);
254 void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc); 252 void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc);
255 void (*ioc_reg_init) (struct bfa_ioc_s *ioc); 253 void (*ioc_reg_init) (struct bfa_ioc_s *ioc);
@@ -267,7 +265,7 @@ struct bfa_ioc_hwif_s {
267#define bfa_ioc_fetch_stats(__ioc, __stats) \ 265#define bfa_ioc_fetch_stats(__ioc, __stats) \
268 (((__stats)->drv_stats) = (__ioc)->stats) 266 (((__stats)->drv_stats) = (__ioc)->stats)
269#define bfa_ioc_clr_stats(__ioc) \ 267#define bfa_ioc_clr_stats(__ioc) \
270 bfa_os_memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats)) 268 memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
271#define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize) 269#define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
272#define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit) 270#define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
273#define bfa_ioc_speed_sup(__ioc) \ 271#define bfa_ioc_speed_sup(__ioc) \
@@ -287,7 +285,7 @@ struct bfa_ioc_hwif_s {
287#define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS) 285#define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS)
288#define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS) 286#define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
289 287
290/** 288/*
291 * IOC mailbox interface 289 * IOC mailbox interface
292 */ 290 */
293void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd); 291void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd);
@@ -299,7 +297,7 @@ void bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg);
299void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc, 297void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
300 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg); 298 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
301 299
302/** 300/*
303 * IOC interfaces 301 * IOC interfaces
304 */ 302 */
305 303
@@ -308,9 +306,9 @@ void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
308 (__ioc)->fcmode)) 306 (__ioc)->fcmode))
309 307
310bfa_status_t bfa_ioc_pll_init(struct bfa_ioc_s *ioc); 308bfa_status_t bfa_ioc_pll_init(struct bfa_ioc_s *ioc);
311bfa_status_t bfa_ioc_cb_pll_init(bfa_os_addr_t rb, bfa_boolean_t fcmode); 309bfa_status_t bfa_ioc_cb_pll_init(void __iomem *rb, bfa_boolean_t fcmode);
312bfa_boolean_t bfa_ioc_ct_pll_init_complete(bfa_os_addr_t rb); 310bfa_boolean_t bfa_ioc_ct_pll_init_complete(void __iomem *rb);
313bfa_status_t bfa_ioc_ct_pll_init(bfa_os_addr_t rb, bfa_boolean_t fcmode); 311bfa_status_t bfa_ioc_ct_pll_init(void __iomem *rb, bfa_boolean_t fcmode);
314 312
315#define bfa_ioc_isr_mode_set(__ioc, __msix) \ 313#define bfa_ioc_isr_mode_set(__ioc, __msix) \
316 ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix)) 314 ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix))
@@ -370,8 +368,8 @@ void bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc);
370bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc); 368bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc);
371void bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc, 369void bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
372 struct bfa_ioc_hbfail_notify_s *notify); 370 struct bfa_ioc_hbfail_notify_s *notify);
373bfa_boolean_t bfa_ioc_sem_get(bfa_os_addr_t sem_reg); 371bfa_boolean_t bfa_ioc_sem_get(void __iomem *sem_reg);
374void bfa_ioc_sem_release(bfa_os_addr_t sem_reg); 372void bfa_ioc_sem_release(void __iomem *sem_reg);
375void bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc); 373void bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc);
376void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, 374void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc,
377 struct bfi_ioc_image_hdr_s *fwhdr); 375 struct bfi_ioc_image_hdr_s *fwhdr);
@@ -441,7 +439,7 @@ bfa_cb_image_get_size(int type)
441 } 439 }
442} 440}
443 441
444/** 442/*
445 * CNA TRCMOD declaration 443 * CNA TRCMOD declaration
446 */ 444 */
447/* 445/*
diff --git a/drivers/scsi/bfa/bfa_ioc_cb.c b/drivers/scsi/bfa/bfa_ioc_cb.c
index d7ac864d8539..909945043850 100644
--- a/drivers/scsi/bfa/bfa_ioc_cb.c
+++ b/drivers/scsi/bfa/bfa_ioc_cb.c
@@ -34,7 +34,7 @@ static void bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc);
34 34
35struct bfa_ioc_hwif_s hwif_cb; 35struct bfa_ioc_hwif_s hwif_cb;
36 36
37/** 37/*
38 * Called from bfa_ioc_attach() to map asic specific calls. 38 * Called from bfa_ioc_attach() to map asic specific calls.
39 */ 39 */
40void 40void
@@ -52,7 +52,7 @@ bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc)
52 ioc->ioc_hwif = &hwif_cb; 52 ioc->ioc_hwif = &hwif_cb;
53} 53}
54 54
55/** 55/*
56 * Return true if firmware of current driver matches the running firmware. 56 * Return true if firmware of current driver matches the running firmware.
57 */ 57 */
58static bfa_boolean_t 58static bfa_boolean_t
@@ -66,17 +66,17 @@ bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc)
66{ 66{
67} 67}
68 68
69/** 69/*
70 * Notify other functions on HB failure. 70 * Notify other functions on HB failure.
71 */ 71 */
72static void 72static void
73bfa_ioc_cb_notify_hbfail(struct bfa_ioc_s *ioc) 73bfa_ioc_cb_notify_hbfail(struct bfa_ioc_s *ioc)
74{ 74{
75 bfa_reg_write(ioc->ioc_regs.err_set, __PSS_ERR_STATUS_SET); 75 writel(__PSS_ERR_STATUS_SET, ioc->ioc_regs.err_set);
76 bfa_reg_read(ioc->ioc_regs.err_set); 76 readl(ioc->ioc_regs.err_set);
77} 77}
78 78
79/** 79/*
80 * Host to LPU mailbox message addresses 80 * Host to LPU mailbox message addresses
81 */ 81 */
82static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = { 82static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
@@ -84,7 +84,7 @@ static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
84 { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 } 84 { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }
85}; 85};
86 86
87/** 87/*
88 * Host <-> LPU mailbox command/status registers 88 * Host <-> LPU mailbox command/status registers
89 */ 89 */
90static struct { u32 hfn, lpu; } iocreg_mbcmd[] = { 90static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
@@ -96,7 +96,7 @@ static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
96static void 96static void
97bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc) 97bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
98{ 98{
99 bfa_os_addr_t rb; 99 void __iomem *rb;
100 int pcifn = bfa_ioc_pcifn(ioc); 100 int pcifn = bfa_ioc_pcifn(ioc);
101 101
102 rb = bfa_ioc_bar0(ioc); 102 rb = bfa_ioc_bar0(ioc);
@@ -113,7 +113,7 @@ bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
113 ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG); 113 ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
114 } 114 }
115 115
116 /** 116 /*
117 * Host <-> LPU mailbox command/status registers 117 * Host <-> LPU mailbox command/status registers
118 */ 118 */
119 ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn; 119 ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn;
@@ -133,7 +133,7 @@ bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
133 ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG); 133 ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
134 ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG); 134 ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
135 135
136 /** 136 /*
137 * sram memory access 137 * sram memory access
138 */ 138 */
139 ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START); 139 ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
@@ -145,14 +145,14 @@ bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
145 ioc->ioc_regs.err_set = (rb + ERR_SET_REG); 145 ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
146} 146}
147 147
148/** 148/*
149 * Initialize IOC to port mapping. 149 * Initialize IOC to port mapping.
150 */ 150 */
151 151
152static void 152static void
153bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc) 153bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc)
154{ 154{
155 /** 155 /*
156 * For crossbow, port id is same as pci function. 156 * For crossbow, port id is same as pci function.
157 */ 157 */
158 ioc->port_id = bfa_ioc_pcifn(ioc); 158 ioc->port_id = bfa_ioc_pcifn(ioc);
@@ -160,7 +160,7 @@ bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc)
160 bfa_trc(ioc, ioc->port_id); 160 bfa_trc(ioc, ioc->port_id);
161} 161}
162 162
163/** 163/*
164 * Set interrupt mode for a function: INTX or MSIX 164 * Set interrupt mode for a function: INTX or MSIX
165 */ 165 */
166static void 166static void
@@ -168,7 +168,7 @@ bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
168{ 168{
169} 169}
170 170
171/** 171/*
172 * Cleanup hw semaphore and usecnt registers 172 * Cleanup hw semaphore and usecnt registers
173 */ 173 */
174static void 174static void
@@ -180,14 +180,14 @@ bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc)
180 * before we clear it. If it is not locked, writing 1 180 * before we clear it. If it is not locked, writing 1
181 * will lock it instead of clearing it. 181 * will lock it instead of clearing it.
182 */ 182 */
183 bfa_reg_read(ioc->ioc_regs.ioc_sem_reg); 183 readl(ioc->ioc_regs.ioc_sem_reg);
184 bfa_ioc_hw_sem_release(ioc); 184 bfa_ioc_hw_sem_release(ioc);
185} 185}
186 186
187 187
188 188
189bfa_status_t 189bfa_status_t
190bfa_ioc_cb_pll_init(bfa_os_addr_t rb, bfa_boolean_t fcmode) 190bfa_ioc_cb_pll_init(void __iomem *rb, bfa_boolean_t fcmode)
191{ 191{
192 u32 pll_sclk, pll_fclk; 192 u32 pll_sclk, pll_fclk;
193 193
@@ -199,38 +199,32 @@ bfa_ioc_cb_pll_init(bfa_os_addr_t rb, bfa_boolean_t fcmode)
199 __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) | 199 __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) |
200 __APP_PLL_400_JITLMT0_1(3U) | 200 __APP_PLL_400_JITLMT0_1(3U) |
201 __APP_PLL_400_CNTLMT0_1(3U); 201 __APP_PLL_400_CNTLMT0_1(3U);
202 bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_UNINIT); 202 writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
203 bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_UNINIT); 203 writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
204 bfa_reg_write((rb + HOSTFN0_INT_MSK), 0xffffffffU); 204 writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
205 bfa_reg_write((rb + HOSTFN1_INT_MSK), 0xffffffffU); 205 writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
206 bfa_reg_write((rb + HOSTFN0_INT_STATUS), 0xffffffffU); 206 writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
207 bfa_reg_write((rb + HOSTFN1_INT_STATUS), 0xffffffffU); 207 writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
208 bfa_reg_write((rb + HOSTFN0_INT_MSK), 0xffffffffU); 208 writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
209 bfa_reg_write((rb + HOSTFN1_INT_MSK), 0xffffffffU); 209 writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
210 bfa_reg_write(rb + APP_PLL_212_CTL_REG, 210 writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
211 __APP_PLL_212_LOGIC_SOFT_RESET); 211 writel(__APP_PLL_212_BYPASS | __APP_PLL_212_LOGIC_SOFT_RESET,
212 bfa_reg_write(rb + APP_PLL_212_CTL_REG, 212 rb + APP_PLL_212_CTL_REG);
213 __APP_PLL_212_BYPASS | 213 writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
214 __APP_PLL_212_LOGIC_SOFT_RESET); 214 writel(__APP_PLL_400_BYPASS | __APP_PLL_400_LOGIC_SOFT_RESET,
215 bfa_reg_write(rb + APP_PLL_400_CTL_REG, 215 rb + APP_PLL_400_CTL_REG);
216 __APP_PLL_400_LOGIC_SOFT_RESET); 216 udelay(2);
217 bfa_reg_write(rb + APP_PLL_400_CTL_REG, 217 writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
218 __APP_PLL_400_BYPASS | 218 writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
219 __APP_PLL_400_LOGIC_SOFT_RESET); 219 writel(pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET,
220 bfa_os_udelay(2); 220 rb + APP_PLL_212_CTL_REG);
221 bfa_reg_write(rb + APP_PLL_212_CTL_REG, 221 writel(pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET,
222 __APP_PLL_212_LOGIC_SOFT_RESET); 222 rb + APP_PLL_400_CTL_REG);
223 bfa_reg_write(rb + APP_PLL_400_CTL_REG, 223 udelay(2000);
224 __APP_PLL_400_LOGIC_SOFT_RESET); 224 writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
225 bfa_reg_write(rb + APP_PLL_212_CTL_REG, 225 writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
226 pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET); 226 writel(pll_sclk, (rb + APP_PLL_212_CTL_REG));
227 bfa_reg_write(rb + APP_PLL_400_CTL_REG, 227 writel(pll_fclk, (rb + APP_PLL_400_CTL_REG));
228 pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET);
229 bfa_os_udelay(2000);
230 bfa_reg_write((rb + HOSTFN0_INT_STATUS), 0xffffffffU);
231 bfa_reg_write((rb + HOSTFN1_INT_STATUS), 0xffffffffU);
232 bfa_reg_write((rb + APP_PLL_212_CTL_REG), pll_sclk);
233 bfa_reg_write((rb + APP_PLL_400_CTL_REG), pll_fclk);
234 228
235 return BFA_STATUS_OK; 229 return BFA_STATUS_OK;
236} 230}
diff --git a/drivers/scsi/bfa/bfa_ioc_ct.c b/drivers/scsi/bfa/bfa_ioc_ct.c
index f21b82c5f64c..115730c0aa77 100644
--- a/drivers/scsi/bfa/bfa_ioc_ct.c
+++ b/drivers/scsi/bfa/bfa_ioc_ct.c
@@ -34,7 +34,7 @@ static void bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc);
34 34
35struct bfa_ioc_hwif_s hwif_ct; 35struct bfa_ioc_hwif_s hwif_ct;
36 36
37/** 37/*
38 * Called from bfa_ioc_attach() to map asic specific calls. 38 * Called from bfa_ioc_attach() to map asic specific calls.
39 */ 39 */
40void 40void
@@ -52,7 +52,7 @@ bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc)
52 ioc->ioc_hwif = &hwif_ct; 52 ioc->ioc_hwif = &hwif_ct;
53} 53}
54 54
55/** 55/*
56 * Return true if firmware of current driver matches the running firmware. 56 * Return true if firmware of current driver matches the running firmware.
57 */ 57 */
58static bfa_boolean_t 58static bfa_boolean_t
@@ -62,13 +62,13 @@ bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc)
62 u32 usecnt; 62 u32 usecnt;
63 struct bfi_ioc_image_hdr_s fwhdr; 63 struct bfi_ioc_image_hdr_s fwhdr;
64 64
65 /** 65 /*
66 * Firmware match check is relevant only for CNA. 66 * Firmware match check is relevant only for CNA.
67 */ 67 */
68 if (!ioc->cna) 68 if (!ioc->cna)
69 return BFA_TRUE; 69 return BFA_TRUE;
70 70
71 /** 71 /*
72 * If bios boot (flash based) -- do not increment usage count 72 * If bios boot (flash based) -- do not increment usage count
73 */ 73 */
74 if (bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)) < 74 if (bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)) <
@@ -76,27 +76,27 @@ bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc)
76 return BFA_TRUE; 76 return BFA_TRUE;
77 77
78 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); 78 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
79 usecnt = bfa_reg_read(ioc->ioc_regs.ioc_usage_reg); 79 usecnt = readl(ioc->ioc_regs.ioc_usage_reg);
80 80
81 /** 81 /*
82 * If usage count is 0, always return TRUE. 82 * If usage count is 0, always return TRUE.
83 */ 83 */
84 if (usecnt == 0) { 84 if (usecnt == 0) {
85 bfa_reg_write(ioc->ioc_regs.ioc_usage_reg, 1); 85 writel(1, ioc->ioc_regs.ioc_usage_reg);
86 bfa_ioc_sem_release(ioc->ioc_regs.ioc_usage_sem_reg); 86 bfa_ioc_sem_release(ioc->ioc_regs.ioc_usage_sem_reg);
87 bfa_trc(ioc, usecnt); 87 bfa_trc(ioc, usecnt);
88 return BFA_TRUE; 88 return BFA_TRUE;
89 } 89 }
90 90
91 ioc_fwstate = bfa_reg_read(ioc->ioc_regs.ioc_fwstate); 91 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
92 bfa_trc(ioc, ioc_fwstate); 92 bfa_trc(ioc, ioc_fwstate);
93 93
94 /** 94 /*
95 * Use count cannot be non-zero and chip in uninitialized state. 95 * Use count cannot be non-zero and chip in uninitialized state.
96 */ 96 */
97 bfa_assert(ioc_fwstate != BFI_IOC_UNINIT); 97 bfa_assert(ioc_fwstate != BFI_IOC_UNINIT);
98 98
99 /** 99 /*
100 * Check if another driver with a different firmware is active 100 * Check if another driver with a different firmware is active
101 */ 101 */
102 bfa_ioc_fwver_get(ioc, &fwhdr); 102 bfa_ioc_fwver_get(ioc, &fwhdr);
@@ -106,11 +106,11 @@ bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc)
106 return BFA_FALSE; 106 return BFA_FALSE;
107 } 107 }
108 108
109 /** 109 /*
110 * Same firmware version. Increment the reference count. 110 * Same firmware version. Increment the reference count.
111 */ 111 */
112 usecnt++; 112 usecnt++;
113 bfa_reg_write(ioc->ioc_regs.ioc_usage_reg, usecnt); 113 writel(usecnt, ioc->ioc_regs.ioc_usage_reg);
114 bfa_ioc_sem_release(ioc->ioc_regs.ioc_usage_sem_reg); 114 bfa_ioc_sem_release(ioc->ioc_regs.ioc_usage_sem_reg);
115 bfa_trc(ioc, usecnt); 115 bfa_trc(ioc, usecnt);
116 return BFA_TRUE; 116 return BFA_TRUE;
@@ -121,50 +121,50 @@ bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc)
121{ 121{
122 u32 usecnt; 122 u32 usecnt;
123 123
124 /** 124 /*
125 * Firmware lock is relevant only for CNA. 125 * Firmware lock is relevant only for CNA.
126 */ 126 */
127 if (!ioc->cna) 127 if (!ioc->cna)
128 return; 128 return;
129 129
130 /** 130 /*
131 * If bios boot (flash based) -- do not decrement usage count 131 * If bios boot (flash based) -- do not decrement usage count
132 */ 132 */
133 if (bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)) < 133 if (bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)) <
134 BFA_IOC_FWIMG_MINSZ) 134 BFA_IOC_FWIMG_MINSZ)
135 return; 135 return;
136 136
137 /** 137 /*
138 * decrement usage count 138 * decrement usage count
139 */ 139 */
140 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); 140 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
141 usecnt = bfa_reg_read(ioc->ioc_regs.ioc_usage_reg); 141 usecnt = readl(ioc->ioc_regs.ioc_usage_reg);
142 bfa_assert(usecnt > 0); 142 bfa_assert(usecnt > 0);
143 143
144 usecnt--; 144 usecnt--;
145 bfa_reg_write(ioc->ioc_regs.ioc_usage_reg, usecnt); 145 writel(usecnt, ioc->ioc_regs.ioc_usage_reg);
146 bfa_trc(ioc, usecnt); 146 bfa_trc(ioc, usecnt);
147 147
148 bfa_ioc_sem_release(ioc->ioc_regs.ioc_usage_sem_reg); 148 bfa_ioc_sem_release(ioc->ioc_regs.ioc_usage_sem_reg);
149} 149}
150 150
151/** 151/*
152 * Notify other functions on HB failure. 152 * Notify other functions on HB failure.
153 */ 153 */
154static void 154static void
155bfa_ioc_ct_notify_hbfail(struct bfa_ioc_s *ioc) 155bfa_ioc_ct_notify_hbfail(struct bfa_ioc_s *ioc)
156{ 156{
157 if (ioc->cna) { 157 if (ioc->cna) {
158 bfa_reg_write(ioc->ioc_regs.ll_halt, __FW_INIT_HALT_P); 158 writel(__FW_INIT_HALT_P, ioc->ioc_regs.ll_halt);
159 /* Wait for halt to take effect */ 159 /* Wait for halt to take effect */
160 bfa_reg_read(ioc->ioc_regs.ll_halt); 160 readl(ioc->ioc_regs.ll_halt);
161 } else { 161 } else {
162 bfa_reg_write(ioc->ioc_regs.err_set, __PSS_ERR_STATUS_SET); 162 writel(__PSS_ERR_STATUS_SET, ioc->ioc_regs.err_set);
163 bfa_reg_read(ioc->ioc_regs.err_set); 163 readl(ioc->ioc_regs.err_set);
164 } 164 }
165} 165}
166 166
167/** 167/*
168 * Host to LPU mailbox message addresses 168 * Host to LPU mailbox message addresses
169 */ 169 */
170static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = { 170static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
@@ -174,7 +174,7 @@ static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
174 { HOSTFN3_LPU_MBOX0_8, LPU_HOSTFN3_MBOX0_8, HOST_PAGE_NUM_FN3 } 174 { HOSTFN3_LPU_MBOX0_8, LPU_HOSTFN3_MBOX0_8, HOST_PAGE_NUM_FN3 }
175}; 175};
176 176
177/** 177/*
178 * Host <-> LPU mailbox command/status registers - port 0 178 * Host <-> LPU mailbox command/status registers - port 0
179 */ 179 */
180static struct { u32 hfn, lpu; } iocreg_mbcmd_p0[] = { 180static struct { u32 hfn, lpu; } iocreg_mbcmd_p0[] = {
@@ -184,7 +184,7 @@ static struct { u32 hfn, lpu; } iocreg_mbcmd_p0[] = {
184 { HOSTFN3_LPU0_MBOX0_CMD_STAT, LPU0_HOSTFN3_MBOX0_CMD_STAT } 184 { HOSTFN3_LPU0_MBOX0_CMD_STAT, LPU0_HOSTFN3_MBOX0_CMD_STAT }
185}; 185};
186 186
187/** 187/*
188 * Host <-> LPU mailbox command/status registers - port 1 188 * Host <-> LPU mailbox command/status registers - port 1
189 */ 189 */
190static struct { u32 hfn, lpu; } iocreg_mbcmd_p1[] = { 190static struct { u32 hfn, lpu; } iocreg_mbcmd_p1[] = {
@@ -197,7 +197,7 @@ static struct { u32 hfn, lpu; } iocreg_mbcmd_p1[] = {
197static void 197static void
198bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc) 198bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc)
199{ 199{
200 bfa_os_addr_t rb; 200 void __iomem *rb;
201 int pcifn = bfa_ioc_pcifn(ioc); 201 int pcifn = bfa_ioc_pcifn(ioc);
202 202
203 rb = bfa_ioc_bar0(ioc); 203 rb = bfa_ioc_bar0(ioc);
@@ -236,7 +236,7 @@ bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc)
236 ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG); 236 ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
237 ioc->ioc_regs.ioc_usage_reg = (rb + BFA_FW_USE_COUNT); 237 ioc->ioc_regs.ioc_usage_reg = (rb + BFA_FW_USE_COUNT);
238 238
239 /** 239 /*
240 * sram memory access 240 * sram memory access
241 */ 241 */
242 ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START); 242 ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
@@ -248,7 +248,7 @@ bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc)
248 ioc->ioc_regs.err_set = (rb + ERR_SET_REG); 248 ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
249} 249}
250 250
251/** 251/*
252 * Initialize IOC to port mapping. 252 * Initialize IOC to port mapping.
253 */ 253 */
254 254
@@ -256,13 +256,13 @@ bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc)
256static void 256static void
257bfa_ioc_ct_map_port(struct bfa_ioc_s *ioc) 257bfa_ioc_ct_map_port(struct bfa_ioc_s *ioc)
258{ 258{
259 bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva; 259 void __iomem *rb = ioc->pcidev.pci_bar_kva;
260 u32 r32; 260 u32 r32;
261 261
262 /** 262 /*
263 * For catapult, base port id on personality register and IOC type 263 * For catapult, base port id on personality register and IOC type
264 */ 264 */
265 r32 = bfa_reg_read(rb + FNC_PERS_REG); 265 r32 = readl(rb + FNC_PERS_REG);
266 r32 >>= FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)); 266 r32 >>= FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc));
267 ioc->port_id = (r32 & __F0_PORT_MAP_MK) >> __F0_PORT_MAP_SH; 267 ioc->port_id = (r32 & __F0_PORT_MAP_MK) >> __F0_PORT_MAP_SH;
268 268
@@ -270,22 +270,22 @@ bfa_ioc_ct_map_port(struct bfa_ioc_s *ioc)
270 bfa_trc(ioc, ioc->port_id); 270 bfa_trc(ioc, ioc->port_id);
271} 271}
272 272
273/** 273/*
274 * Set interrupt mode for a function: INTX or MSIX 274 * Set interrupt mode for a function: INTX or MSIX
275 */ 275 */
276static void 276static void
277bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix) 277bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
278{ 278{
279 bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva; 279 void __iomem *rb = ioc->pcidev.pci_bar_kva;
280 u32 r32, mode; 280 u32 r32, mode;
281 281
282 r32 = bfa_reg_read(rb + FNC_PERS_REG); 282 r32 = readl(rb + FNC_PERS_REG);
283 bfa_trc(ioc, r32); 283 bfa_trc(ioc, r32);
284 284
285 mode = (r32 >> FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))) & 285 mode = (r32 >> FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))) &
286 __F0_INTX_STATUS; 286 __F0_INTX_STATUS;
287 287
288 /** 288 /*
289 * If already in desired mode, do not change anything 289 * If already in desired mode, do not change anything
290 */ 290 */
291 if (!msix && mode) 291 if (!msix && mode)
@@ -300,10 +300,10 @@ bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
300 r32 |= (mode << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))); 300 r32 |= (mode << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)));
301 bfa_trc(ioc, r32); 301 bfa_trc(ioc, r32);
302 302
303 bfa_reg_write(rb + FNC_PERS_REG, r32); 303 writel(r32, rb + FNC_PERS_REG);
304} 304}
305 305
306/** 306/*
307 * Cleanup hw semaphore and usecnt registers 307 * Cleanup hw semaphore and usecnt registers
308 */ 308 */
309static void 309static void
@@ -312,7 +312,7 @@ bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc)
312 312
313 if (ioc->cna) { 313 if (ioc->cna) {
314 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); 314 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
315 bfa_reg_write(ioc->ioc_regs.ioc_usage_reg, 0); 315 writel(0, ioc->ioc_regs.ioc_usage_reg);
316 bfa_ioc_sem_release(ioc->ioc_regs.ioc_usage_sem_reg); 316 bfa_ioc_sem_release(ioc->ioc_regs.ioc_usage_sem_reg);
317 } 317 }
318 318
@@ -321,7 +321,7 @@ bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc)
321 * before we clear it. If it is not locked, writing 1 321 * before we clear it. If it is not locked, writing 1
322 * will lock it instead of clearing it. 322 * will lock it instead of clearing it.
323 */ 323 */
324 bfa_reg_read(ioc->ioc_regs.ioc_sem_reg); 324 readl(ioc->ioc_regs.ioc_sem_reg);
325 bfa_ioc_hw_sem_release(ioc); 325 bfa_ioc_hw_sem_release(ioc);
326} 326}
327 327
@@ -331,17 +331,17 @@ bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc)
331 * Check the firmware state to know if pll_init has been completed already 331 * Check the firmware state to know if pll_init has been completed already
332 */ 332 */
333bfa_boolean_t 333bfa_boolean_t
334bfa_ioc_ct_pll_init_complete(bfa_os_addr_t rb) 334bfa_ioc_ct_pll_init_complete(void __iomem *rb)
335{ 335{
336 if ((bfa_reg_read(rb + BFA_IOC0_STATE_REG) == BFI_IOC_OP) || 336 if ((readl(rb + BFA_IOC0_STATE_REG) == BFI_IOC_OP) ||
337 (bfa_reg_read(rb + BFA_IOC1_STATE_REG) == BFI_IOC_OP)) 337 (readl(rb + BFA_IOC1_STATE_REG) == BFI_IOC_OP))
338 return BFA_TRUE; 338 return BFA_TRUE;
339 339
340 return BFA_FALSE; 340 return BFA_FALSE;
341} 341}
342 342
343bfa_status_t 343bfa_status_t
344bfa_ioc_ct_pll_init(bfa_os_addr_t rb, bfa_boolean_t fcmode) 344bfa_ioc_ct_pll_init(void __iomem *rb, bfa_boolean_t fcmode)
345{ 345{
346 u32 pll_sclk, pll_fclk, r32; 346 u32 pll_sclk, pll_fclk, r32;
347 347
@@ -354,56 +354,51 @@ bfa_ioc_ct_pll_init(bfa_os_addr_t rb, bfa_boolean_t fcmode)
354 __APP_PLL_425_JITLMT0_1(3U) | 354 __APP_PLL_425_JITLMT0_1(3U) |
355 __APP_PLL_425_CNTLMT0_1(1U); 355 __APP_PLL_425_CNTLMT0_1(1U);
356 if (fcmode) { 356 if (fcmode) {
357 bfa_reg_write((rb + OP_MODE), 0); 357 writel(0, (rb + OP_MODE));
358 bfa_reg_write((rb + ETH_MAC_SER_REG), 358 writel(__APP_EMS_CMLCKSEL | __APP_EMS_REFCKBUFEN2 |
359 __APP_EMS_CMLCKSEL | 359 __APP_EMS_CHANNEL_SEL, (rb + ETH_MAC_SER_REG));
360 __APP_EMS_REFCKBUFEN2 |
361 __APP_EMS_CHANNEL_SEL);
362 } else { 360 } else {
363 bfa_reg_write((rb + OP_MODE), __GLOBAL_FCOE_MODE); 361 writel(__GLOBAL_FCOE_MODE, (rb + OP_MODE));
364 bfa_reg_write((rb + ETH_MAC_SER_REG), 362 writel(__APP_EMS_REFCKBUFEN1, (rb + ETH_MAC_SER_REG));
365 __APP_EMS_REFCKBUFEN1);
366 } 363 }
367 bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_UNINIT); 364 writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
368 bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_UNINIT); 365 writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
369 bfa_reg_write((rb + HOSTFN0_INT_MSK), 0xffffffffU); 366 writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
370 bfa_reg_write((rb + HOSTFN1_INT_MSK), 0xffffffffU); 367 writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
371 bfa_reg_write((rb + HOSTFN0_INT_STATUS), 0xffffffffU); 368 writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
372 bfa_reg_write((rb + HOSTFN1_INT_STATUS), 0xffffffffU); 369 writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
373 bfa_reg_write((rb + HOSTFN0_INT_MSK), 0xffffffffU); 370 writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
374 bfa_reg_write((rb + HOSTFN1_INT_MSK), 0xffffffffU); 371 writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
375 bfa_reg_write(rb + APP_PLL_312_CTL_REG, pll_sclk | 372 writel(pll_sclk | __APP_PLL_312_LOGIC_SOFT_RESET,
376 __APP_PLL_312_LOGIC_SOFT_RESET); 373 rb + APP_PLL_312_CTL_REG);
377 bfa_reg_write(rb + APP_PLL_425_CTL_REG, pll_fclk | 374 writel(pll_fclk | __APP_PLL_425_LOGIC_SOFT_RESET,
378 __APP_PLL_425_LOGIC_SOFT_RESET); 375 rb + APP_PLL_425_CTL_REG);
379 bfa_reg_write(rb + APP_PLL_312_CTL_REG, pll_sclk | 376 writel(pll_sclk | __APP_PLL_312_LOGIC_SOFT_RESET | __APP_PLL_312_ENABLE,
380 __APP_PLL_312_LOGIC_SOFT_RESET | __APP_PLL_312_ENABLE); 377 rb + APP_PLL_312_CTL_REG);
381 bfa_reg_write(rb + APP_PLL_425_CTL_REG, pll_fclk | 378 writel(pll_fclk | __APP_PLL_425_LOGIC_SOFT_RESET | __APP_PLL_425_ENABLE,
382 __APP_PLL_425_LOGIC_SOFT_RESET | __APP_PLL_425_ENABLE); 379 rb + APP_PLL_425_CTL_REG);
383 bfa_reg_read(rb + HOSTFN0_INT_MSK); 380 readl(rb + HOSTFN0_INT_MSK);
384 bfa_os_udelay(2000); 381 udelay(2000);
385 bfa_reg_write((rb + HOSTFN0_INT_STATUS), 0xffffffffU); 382 writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
386 bfa_reg_write((rb + HOSTFN1_INT_STATUS), 0xffffffffU); 383 writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
387 bfa_reg_write(rb + APP_PLL_312_CTL_REG, pll_sclk | 384 writel(pll_sclk | __APP_PLL_312_ENABLE, rb + APP_PLL_312_CTL_REG);
388 __APP_PLL_312_ENABLE); 385 writel(pll_fclk | __APP_PLL_425_ENABLE, rb + APP_PLL_425_CTL_REG);
389 bfa_reg_write(rb + APP_PLL_425_CTL_REG, pll_fclk |
390 __APP_PLL_425_ENABLE);
391 if (!fcmode) { 386 if (!fcmode) {
392 bfa_reg_write((rb + PMM_1T_RESET_REG_P0), __PMM_1T_RESET_P); 387 writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P0));
393 bfa_reg_write((rb + PMM_1T_RESET_REG_P1), __PMM_1T_RESET_P); 388 writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P1));
394 } 389 }
395 r32 = bfa_reg_read((rb + PSS_CTL_REG)); 390 r32 = readl((rb + PSS_CTL_REG));
396 r32 &= ~__PSS_LMEM_RESET; 391 r32 &= ~__PSS_LMEM_RESET;
397 bfa_reg_write((rb + PSS_CTL_REG), r32); 392 writel(r32, (rb + PSS_CTL_REG));
398 bfa_os_udelay(1000); 393 udelay(1000);
399 if (!fcmode) { 394 if (!fcmode) {
400 bfa_reg_write((rb + PMM_1T_RESET_REG_P0), 0); 395 writel(0, (rb + PMM_1T_RESET_REG_P0));
401 bfa_reg_write((rb + PMM_1T_RESET_REG_P1), 0); 396 writel(0, (rb + PMM_1T_RESET_REG_P1));
402 } 397 }
403 398
404 bfa_reg_write((rb + MBIST_CTL_REG), __EDRAM_BISTR_START); 399 writel(__EDRAM_BISTR_START, (rb + MBIST_CTL_REG));
405 bfa_os_udelay(1000); 400 udelay(1000);
406 r32 = bfa_reg_read((rb + MBIST_STAT_REG)); 401 r32 = readl((rb + MBIST_STAT_REG));
407 bfa_reg_write((rb + MBIST_CTL_REG), 0); 402 writel(0, (rb + MBIST_CTL_REG));
408 return BFA_STATUS_OK; 403 return BFA_STATUS_OK;
409} 404}
diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
index 2cd527338677..15407ab39e77 100644
--- a/drivers/scsi/bfa/bfa_modules.h
+++ b/drivers/scsi/bfa/bfa_modules.h
@@ -15,7 +15,7 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * bfa_modules.h BFA modules 19 * bfa_modules.h BFA modules
20 */ 20 */
21 21
@@ -52,7 +52,7 @@ enum {
52}; 52};
53 53
54 54
55/** 55/*
56 * Macro to define a new BFA module 56 * Macro to define a new BFA module
57 */ 57 */
58#define BFA_MODULE(__mod) \ 58#define BFA_MODULE(__mod) \
@@ -80,7 +80,7 @@ enum {
80 80
81#define BFA_CACHELINE_SZ (256) 81#define BFA_CACHELINE_SZ (256)
82 82
83/** 83/*
84 * Structure used to interact between different BFA sub modules 84 * Structure used to interact between different BFA sub modules
85 * 85 *
86 * Each sub module needs to implement only the entry points relevant to it (and 86 * Each sub module needs to implement only the entry points relevant to it (and
diff --git a/drivers/scsi/bfa/bfa_os_inc.h b/drivers/scsi/bfa/bfa_os_inc.h
index 788a250ffb8a..65df62ef437f 100644
--- a/drivers/scsi/bfa/bfa_os_inc.h
+++ b/drivers/scsi/bfa/bfa_os_inc.h
@@ -15,10 +15,6 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/**
19 * Contains declarations all OS Specific files needed for BFA layer
20 */
21
22#ifndef __BFA_OS_INC_H__ 18#ifndef __BFA_OS_INC_H__
23#define __BFA_OS_INC_H__ 19#define __BFA_OS_INC_H__
24 20
@@ -44,11 +40,6 @@
44#define __BIGENDIAN 40#define __BIGENDIAN
45#endif 41#endif
46 42
47static inline u64 bfa_os_get_clock(void)
48{
49 return jiffies;
50}
51
52static inline u64 bfa_os_get_log_time(void) 43static inline u64 bfa_os_get_log_time(void)
53{ 44{
54 u64 system_time = 0; 45 u64 system_time = 0;
@@ -63,13 +54,6 @@ static inline u64 bfa_os_get_log_time(void)
63#define bfa_io_lat_clock_res_div HZ 54#define bfa_io_lat_clock_res_div HZ
64#define bfa_io_lat_clock_res_mul 1000 55#define bfa_io_lat_clock_res_mul 1000
65 56
66#define BFA_ASSERT(p) do { \
67 if (!(p)) { \
68 printk(KERN_ERR "assert(%s) failed at %s:%d\n", \
69 #p, __FILE__, __LINE__); \
70 } \
71} while (0)
72
73#define BFA_LOG(level, bfad, mask, fmt, arg...) \ 57#define BFA_LOG(level, bfad, mask, fmt, arg...) \
74do { \ 58do { \
75 if (((mask) == 4) || (level[1] <= '4')) \ 59 if (((mask) == 4) || (level[1] <= '4')) \
@@ -81,22 +65,6 @@ do { \
81 ((_x) & 0x00ff00) | \ 65 ((_x) & 0x00ff00) | \
82 (((_x) & 0xff0000) >> 16)) 66 (((_x) & 0xff0000) >> 16))
83 67
84#define bfa_swap_8b(_x) \
85 ((((_x) & 0xff00000000000000ull) >> 56) \
86 | (((_x) & 0x00ff000000000000ull) >> 40) \
87 | (((_x) & 0x0000ff0000000000ull) >> 24) \
88 | (((_x) & 0x000000ff00000000ull) >> 8) \
89 | (((_x) & 0x00000000ff000000ull) << 8) \
90 | (((_x) & 0x0000000000ff0000ull) << 24) \
91 | (((_x) & 0x000000000000ff00ull) << 40) \
92 | (((_x) & 0x00000000000000ffull) << 56))
93
94#define bfa_os_swap32(_x) \
95 ((((_x) & 0xff) << 24) | \
96 (((_x) & 0x0000ff00) << 8) | \
97 (((_x) & 0x00ff0000) >> 8) | \
98 (((_x) & 0xff000000) >> 24))
99
100#define bfa_os_swap_sgaddr(_x) ((u64)( \ 68#define bfa_os_swap_sgaddr(_x) ((u64)( \
101 (((u64)(_x) & (u64)0x00000000000000ffull) << 32) | \ 69 (((u64)(_x) & (u64)0x00000000000000ffull) << 32) | \
102 (((u64)(_x) & (u64)0x000000000000ff00ull) << 32) | \ 70 (((u64)(_x) & (u64)0x000000000000ff00ull) << 32) | \
@@ -108,59 +76,27 @@ do { \
108 (((u64)(_x) & (u64)0xff00000000000000ull) >> 32))) 76 (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
109 77
110#ifndef __BIGENDIAN 78#ifndef __BIGENDIAN
111#define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \ 79#define bfa_os_hton3b(_x) bfa_swap_3b(_x)
112 (((_x) & 0x00ff) << 8)))
113#define bfa_os_htonl(_x) bfa_os_swap32(_x)
114#define bfa_os_htonll(_x) bfa_swap_8b(_x)
115#define bfa_os_hton3b(_x) bfa_swap_3b(_x)
116#define bfa_os_wtole(_x) (_x)
117#define bfa_os_sgaddr(_x) (_x) 80#define bfa_os_sgaddr(_x) (_x)
118
119#else 81#else
120
121#define bfa_os_htons(_x) (_x)
122#define bfa_os_htonl(_x) (_x)
123#define bfa_os_hton3b(_x) (_x) 82#define bfa_os_hton3b(_x) (_x)
124#define bfa_os_htonll(_x) (_x)
125#define bfa_os_wtole(_x) bfa_os_swap32(_x)
126#define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x) 83#define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x)
127
128#endif 84#endif
129 85
130#define bfa_os_ntohs(_x) bfa_os_htons(_x)
131#define bfa_os_ntohl(_x) bfa_os_htonl(_x)
132#define bfa_os_ntohll(_x) bfa_os_htonll(_x)
133#define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x) 86#define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x)
134
135#define bfa_os_u32(__pa64) ((__pa64) >> 32) 87#define bfa_os_u32(__pa64) ((__pa64) >> 32)
136 88
137#define bfa_os_memset memset 89#define BFA_TRC_TS(_trcm) \
138#define bfa_os_memcpy memcpy 90 ({ \
139#define bfa_os_udelay udelay 91 struct timeval tv; \
140#define bfa_os_vsprintf vsprintf 92 \
141#define bfa_os_snprintf snprintf 93 do_gettimeofday(&tv); \
142 94 (tv.tv_sec*1000000+tv.tv_usec); \
143#define bfa_os_assign(__t, __s) __t = __s 95 })
144#define bfa_os_addr_t void __iomem *
145
146#define bfa_os_reg_read(_raddr) readl(_raddr)
147#define bfa_os_reg_write(_raddr, _val) writel((_val), (_raddr))
148#define bfa_os_mem_read(_raddr, _off) \
149 bfa_os_swap32(readl(((_raddr) + (_off))))
150#define bfa_os_mem_write(_raddr, _off, _val) \
151 writel(bfa_os_swap32((_val)), ((_raddr) + (_off)))
152
153#define BFA_TRC_TS(_trcm) \
154 ({ \
155 struct timeval tv; \
156 \
157 do_gettimeofday(&tv); \
158 (tv.tv_sec*1000000+tv.tv_usec); \
159 })
160 96
161#define boolean_t int 97#define boolean_t int
162 98
163/** 99/*
164 * For current time stamp, OS API will fill-in 100 * For current time stamp, OS API will fill-in
165 */ 101 */
166struct bfa_timeval_s { 102struct bfa_timeval_s {
diff --git a/drivers/scsi/bfa/bfa_port.c b/drivers/scsi/bfa/bfa_port.c
index b6d170a13bea..fff96226a383 100644
--- a/drivers/scsi/bfa/bfa_port.c
+++ b/drivers/scsi/bfa/bfa_port.c
@@ -37,16 +37,16 @@ bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats)
37 t0 = dip[i]; 37 t0 = dip[i];
38 t1 = dip[i + 1]; 38 t1 = dip[i + 1];
39#ifdef __BIGENDIAN 39#ifdef __BIGENDIAN
40 dip[i] = bfa_os_ntohl(t0); 40 dip[i] = be32_to_cpu(t0);
41 dip[i + 1] = bfa_os_ntohl(t1); 41 dip[i + 1] = be32_to_cpu(t1);
42#else 42#else
43 dip[i] = bfa_os_ntohl(t1); 43 dip[i] = be32_to_cpu(t1);
44 dip[i + 1] = bfa_os_ntohl(t0); 44 dip[i + 1] = be32_to_cpu(t0);
45#endif 45#endif
46 } 46 }
47} 47}
48 48
49/** 49/*
50 * bfa_port_enable_isr() 50 * bfa_port_enable_isr()
51 * 51 *
52 * 52 *
@@ -63,7 +63,7 @@ bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status)
63 port->endis_cbfn(port->endis_cbarg, status); 63 port->endis_cbfn(port->endis_cbarg, status);
64} 64}
65 65
66/** 66/*
67 * bfa_port_disable_isr() 67 * bfa_port_disable_isr()
68 * 68 *
69 * 69 *
@@ -80,7 +80,7 @@ bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status)
80 port->endis_cbfn(port->endis_cbarg, status); 80 port->endis_cbfn(port->endis_cbarg, status);
81} 81}
82 82
83/** 83/*
84 * bfa_port_get_stats_isr() 84 * bfa_port_get_stats_isr()
85 * 85 *
86 * 86 *
@@ -112,7 +112,7 @@ bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status)
112 } 112 }
113} 113}
114 114
115/** 115/*
116 * bfa_port_clear_stats_isr() 116 * bfa_port_clear_stats_isr()
117 * 117 *
118 * 118 *
@@ -129,7 +129,7 @@ bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
129 port->stats_status = status; 129 port->stats_status = status;
130 port->stats_busy = BFA_FALSE; 130 port->stats_busy = BFA_FALSE;
131 131
132 /** 132 /*
133 * re-initialize time stamp for stats reset 133 * re-initialize time stamp for stats reset
134 */ 134 */
135 bfa_os_gettimeofday(&tv); 135 bfa_os_gettimeofday(&tv);
@@ -141,7 +141,7 @@ bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
141 } 141 }
142} 142}
143 143
144/** 144/*
145 * bfa_port_isr() 145 * bfa_port_isr()
146 * 146 *
147 * 147 *
@@ -189,7 +189,7 @@ bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
189 } 189 }
190} 190}
191 191
192/** 192/*
193 * bfa_port_meminfo() 193 * bfa_port_meminfo()
194 * 194 *
195 * 195 *
@@ -203,7 +203,7 @@ bfa_port_meminfo(void)
203 return BFA_ROUNDUP(sizeof(union bfa_port_stats_u), BFA_DMA_ALIGN_SZ); 203 return BFA_ROUNDUP(sizeof(union bfa_port_stats_u), BFA_DMA_ALIGN_SZ);
204} 204}
205 205
206/** 206/*
207 * bfa_port_mem_claim() 207 * bfa_port_mem_claim()
208 * 208 *
209 * 209 *
@@ -220,7 +220,7 @@ bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
220 port->stats_dma.pa = dma_pa; 220 port->stats_dma.pa = dma_pa;
221} 221}
222 222
223/** 223/*
224 * bfa_port_enable() 224 * bfa_port_enable()
225 * 225 *
226 * Send the Port enable request to the f/w 226 * Send the Port enable request to the f/w
@@ -264,7 +264,7 @@ bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
264 return BFA_STATUS_OK; 264 return BFA_STATUS_OK;
265} 265}
266 266
267/** 267/*
268 * bfa_port_disable() 268 * bfa_port_disable()
269 * 269 *
270 * Send the Port disable request to the f/w 270 * Send the Port disable request to the f/w
@@ -308,7 +308,7 @@ bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
308 return BFA_STATUS_OK; 308 return BFA_STATUS_OK;
309} 309}
310 310
311/** 311/*
312 * bfa_port_get_stats() 312 * bfa_port_get_stats()
313 * 313 *
314 * Send the request to the f/w to fetch Port statistics. 314 * Send the request to the f/w to fetch Port statistics.
@@ -348,7 +348,7 @@ bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats,
348 return BFA_STATUS_OK; 348 return BFA_STATUS_OK;
349} 349}
350 350
351/** 351/*
352 * bfa_port_clear_stats() 352 * bfa_port_clear_stats()
353 * 353 *
354 * 354 *
@@ -385,7 +385,7 @@ bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
385 return BFA_STATUS_OK; 385 return BFA_STATUS_OK;
386} 386}
387 387
388/** 388/*
389 * bfa_port_hbfail() 389 * bfa_port_hbfail()
390 * 390 *
391 * 391 *
@@ -415,7 +415,7 @@ bfa_port_hbfail(void *arg)
415 } 415 }
416} 416}
417 417
418/** 418/*
419 * bfa_port_attach() 419 * bfa_port_attach()
420 * 420 *
421 * 421 *
@@ -449,7 +449,7 @@ bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
449 bfa_ioc_hbfail_init(&port->hbfail, bfa_port_hbfail, port); 449 bfa_ioc_hbfail_init(&port->hbfail, bfa_port_hbfail, port);
450 bfa_ioc_hbfail_register(port->ioc, &port->hbfail); 450 bfa_ioc_hbfail_register(port->ioc, &port->hbfail);
451 451
452 /** 452 /*
453 * initialize time stamp for stats reset 453 * initialize time stamp for stats reset
454 */ 454 */
455 bfa_os_gettimeofday(&tv); 455 bfa_os_gettimeofday(&tv);
@@ -458,7 +458,7 @@ bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
458 bfa_trc(port, 0); 458 bfa_trc(port, 0);
459} 459}
460 460
461/** 461/*
462 * bfa_port_detach() 462 * bfa_port_detach()
463 * 463 *
464 * 464 *
diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c
index aa1dc749b281..c768143f4805 100644
--- a/drivers/scsi/bfa/bfa_svc.c
+++ b/drivers/scsi/bfa/bfa_svc.c
@@ -29,7 +29,7 @@ BFA_MODULE(fcport);
29BFA_MODULE(rport); 29BFA_MODULE(rport);
30BFA_MODULE(uf); 30BFA_MODULE(uf);
31 31
32/** 32/*
33 * LPS related definitions 33 * LPS related definitions
34 */ 34 */
35#define BFA_LPS_MIN_LPORTS (1) 35#define BFA_LPS_MIN_LPORTS (1)
@@ -41,7 +41,7 @@ BFA_MODULE(uf);
41#define BFA_LPS_MAX_VPORTS_SUPP_CB 255 41#define BFA_LPS_MAX_VPORTS_SUPP_CB 255
42#define BFA_LPS_MAX_VPORTS_SUPP_CT 190 42#define BFA_LPS_MAX_VPORTS_SUPP_CT 190
43 43
44/** 44/*
45 * lps_pvt BFA LPS private functions 45 * lps_pvt BFA LPS private functions
46 */ 46 */
47 47
@@ -55,7 +55,7 @@ enum bfa_lps_event {
55 BFA_LPS_SM_RX_CVL = 7, /* Rx clear virtual link */ 55 BFA_LPS_SM_RX_CVL = 7, /* Rx clear virtual link */
56}; 56};
57 57
58/** 58/*
59 * FC PORT related definitions 59 * FC PORT related definitions
60 */ 60 */
61/* 61/*
@@ -67,7 +67,7 @@ enum bfa_lps_event {
67 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE)) 67 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
68 68
69 69
70/** 70/*
71 * BFA port state machine events 71 * BFA port state machine events
72 */ 72 */
73enum bfa_fcport_sm_event { 73enum bfa_fcport_sm_event {
@@ -82,7 +82,7 @@ enum bfa_fcport_sm_event {
82 BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */ 82 BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
83}; 83};
84 84
85/** 85/*
86 * BFA port link notification state machine events 86 * BFA port link notification state machine events
87 */ 87 */
88 88
@@ -92,7 +92,7 @@ enum bfa_fcport_ln_sm_event {
92 BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */ 92 BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
93}; 93};
94 94
95/** 95/*
96 * RPORT related definitions 96 * RPORT related definitions
97 */ 97 */
98#define bfa_rport_offline_cb(__rp) do { \ 98#define bfa_rport_offline_cb(__rp) do { \
@@ -126,7 +126,7 @@ enum bfa_rport_event {
126 BFA_RPORT_SM_QRESUME = 9, /* space in requeue queue */ 126 BFA_RPORT_SM_QRESUME = 9, /* space in requeue queue */
127}; 127};
128 128
129/** 129/*
130 * forward declarations FCXP related functions 130 * forward declarations FCXP related functions
131 */ 131 */
132static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete); 132static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
@@ -138,7 +138,7 @@ static void bfa_fcxp_qresume(void *cbarg);
138static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, 138static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
139 struct bfi_fcxp_send_req_s *send_req); 139 struct bfi_fcxp_send_req_s *send_req);
140 140
141/** 141/*
142 * forward declarations for LPS functions 142 * forward declarations for LPS functions
143 */ 143 */
144static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, 144static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
@@ -163,7 +163,7 @@ static void bfa_lps_login_comp(struct bfa_lps_s *lps);
163static void bfa_lps_logout_comp(struct bfa_lps_s *lps); 163static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
164static void bfa_lps_cvl_event(struct bfa_lps_s *lps); 164static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
165 165
166/** 166/*
167 * forward declaration for LPS state machine 167 * forward declaration for LPS state machine
168 */ 168 */
169static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event); 169static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
@@ -175,7 +175,7 @@ static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
175static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event 175static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
176 event); 176 event);
177 177
178/** 178/*
179 * forward declaration for FC Port functions 179 * forward declaration for FC Port functions
180 */ 180 */
181static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport); 181static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
@@ -193,7 +193,7 @@ static void bfa_fcport_stats_get_timeout(void *cbarg);
193static void bfa_fcport_stats_clr_timeout(void *cbarg); 193static void bfa_fcport_stats_clr_timeout(void *cbarg);
194static void bfa_trunk_iocdisable(struct bfa_s *bfa); 194static void bfa_trunk_iocdisable(struct bfa_s *bfa);
195 195
196/** 196/*
197 * forward declaration for FC PORT state machine 197 * forward declaration for FC PORT state machine
198 */ 198 */
199static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport, 199static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
@@ -252,7 +252,7 @@ static struct bfa_sm_table_s hal_port_sm_table[] = {
252}; 252};
253 253
254 254
255/** 255/*
256 * forward declaration for RPORT related functions 256 * forward declaration for RPORT related functions
257 */ 257 */
258static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod); 258static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
@@ -265,7 +265,7 @@ static void __bfa_cb_rport_online(void *cbarg,
265static void __bfa_cb_rport_offline(void *cbarg, 265static void __bfa_cb_rport_offline(void *cbarg,
266 bfa_boolean_t complete); 266 bfa_boolean_t complete);
267 267
268/** 268/*
269 * forward declaration for RPORT state machine 269 * forward declaration for RPORT state machine
270 */ 270 */
271static void bfa_rport_sm_uninit(struct bfa_rport_s *rp, 271static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
@@ -295,7 +295,7 @@ static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
295static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, 295static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
296 enum bfa_rport_event event); 296 enum bfa_rport_event event);
297 297
298/** 298/*
299 * PLOG related definitions 299 * PLOG related definitions
300 */ 300 */
301static int 301static int
@@ -330,7 +330,7 @@ bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
330 330
331 pl_recp = &(plog->plog_recs[tail]); 331 pl_recp = &(plog->plog_recs[tail]);
332 332
333 bfa_os_memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s)); 333 memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
334 334
335 pl_recp->tv = bfa_os_get_log_time(); 335 pl_recp->tv = bfa_os_get_log_time();
336 BFA_PL_LOG_REC_INCR(plog->tail); 336 BFA_PL_LOG_REC_INCR(plog->tail);
@@ -342,9 +342,9 @@ bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
342void 342void
343bfa_plog_init(struct bfa_plog_s *plog) 343bfa_plog_init(struct bfa_plog_s *plog)
344{ 344{
345 bfa_os_memset((char *)plog, 0, sizeof(struct bfa_plog_s)); 345 memset((char *)plog, 0, sizeof(struct bfa_plog_s));
346 346
347 bfa_os_memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN); 347 memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
348 plog->head = plog->tail = 0; 348 plog->head = plog->tail = 0;
349 plog->plog_enabled = 1; 349 plog->plog_enabled = 1;
350} 350}
@@ -357,7 +357,7 @@ bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
357 struct bfa_plog_rec_s lp; 357 struct bfa_plog_rec_s lp;
358 358
359 if (plog->plog_enabled) { 359 if (plog->plog_enabled) {
360 bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); 360 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
361 lp.mid = mid; 361 lp.mid = mid;
362 lp.eid = event; 362 lp.eid = event;
363 lp.log_type = BFA_PL_LOG_TYPE_STRING; 363 lp.log_type = BFA_PL_LOG_TYPE_STRING;
@@ -381,15 +381,14 @@ bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
381 num_ints = BFA_PL_INT_LOG_SZ; 381 num_ints = BFA_PL_INT_LOG_SZ;
382 382
383 if (plog->plog_enabled) { 383 if (plog->plog_enabled) {
384 bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); 384 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
385 lp.mid = mid; 385 lp.mid = mid;
386 lp.eid = event; 386 lp.eid = event;
387 lp.log_type = BFA_PL_LOG_TYPE_INT; 387 lp.log_type = BFA_PL_LOG_TYPE_INT;
388 lp.misc = misc; 388 lp.misc = misc;
389 389
390 for (i = 0; i < num_ints; i++) 390 for (i = 0; i < num_ints; i++)
391 bfa_os_assign(lp.log_entry.int_log[i], 391 lp.log_entry.int_log[i] = intarr[i];
392 intarr[i]);
393 392
394 lp.log_num_ints = (u8) num_ints; 393 lp.log_num_ints = (u8) num_ints;
395 394
@@ -407,7 +406,7 @@ bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
407 u32 ints[BFA_PL_INT_LOG_SZ]; 406 u32 ints[BFA_PL_INT_LOG_SZ];
408 407
409 if (plog->plog_enabled) { 408 if (plog->plog_enabled) {
410 bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); 409 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
411 410
412 ints[0] = tmp_int[0]; 411 ints[0] = tmp_int[0];
413 ints[1] = tmp_int[1]; 412 ints[1] = tmp_int[1];
@@ -427,7 +426,7 @@ bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
427 u32 ints[BFA_PL_INT_LOG_SZ]; 426 u32 ints[BFA_PL_INT_LOG_SZ];
428 427
429 if (plog->plog_enabled) { 428 if (plog->plog_enabled) {
430 bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); 429 memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
431 430
432 ints[0] = tmp_int[0]; 431 ints[0] = tmp_int[0];
433 ints[1] = tmp_int[1]; 432 ints[1] = tmp_int[1];
@@ -462,7 +461,7 @@ bfa_plog_get_setting(struct bfa_plog_s *plog)
462 return (bfa_boolean_t)plog->plog_enabled; 461 return (bfa_boolean_t)plog->plog_enabled;
463} 462}
464 463
465/** 464/*
466 * fcxp_pvt BFA FCXP private functions 465 * fcxp_pvt BFA FCXP private functions
467 */ 466 */
468 467
@@ -485,7 +484,7 @@ claim_fcxp_req_rsp_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
485 mod->req_pld_list_pa = dm_pa; 484 mod->req_pld_list_pa = dm_pa;
486 dm_kva += buf_pool_sz; 485 dm_kva += buf_pool_sz;
487 dm_pa += buf_pool_sz; 486 dm_pa += buf_pool_sz;
488 bfa_os_memset(mod->req_pld_list_kva, 0, buf_pool_sz); 487 memset(mod->req_pld_list_kva, 0, buf_pool_sz);
489 488
490 /* 489 /*
491 * Initialize the fcxp rsp payload list 490 * Initialize the fcxp rsp payload list
@@ -495,7 +494,7 @@ claim_fcxp_req_rsp_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
495 mod->rsp_pld_list_pa = dm_pa; 494 mod->rsp_pld_list_pa = dm_pa;
496 dm_kva += buf_pool_sz; 495 dm_kva += buf_pool_sz;
497 dm_pa += buf_pool_sz; 496 dm_pa += buf_pool_sz;
498 bfa_os_memset(mod->rsp_pld_list_kva, 0, buf_pool_sz); 497 memset(mod->rsp_pld_list_kva, 0, buf_pool_sz);
499 498
500 bfa_meminfo_dma_virt(mi) = dm_kva; 499 bfa_meminfo_dma_virt(mi) = dm_kva;
501 bfa_meminfo_dma_phys(mi) = dm_pa; 500 bfa_meminfo_dma_phys(mi) = dm_pa;
@@ -508,7 +507,7 @@ claim_fcxps_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
508 struct bfa_fcxp_s *fcxp; 507 struct bfa_fcxp_s *fcxp;
509 508
510 fcxp = (struct bfa_fcxp_s *) bfa_meminfo_kva(mi); 509 fcxp = (struct bfa_fcxp_s *) bfa_meminfo_kva(mi);
511 bfa_os_memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps); 510 memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
512 511
513 INIT_LIST_HEAD(&mod->fcxp_free_q); 512 INIT_LIST_HEAD(&mod->fcxp_free_q);
514 INIT_LIST_HEAD(&mod->fcxp_active_q); 513 INIT_LIST_HEAD(&mod->fcxp_active_q);
@@ -559,11 +558,11 @@ bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
559{ 558{
560 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); 559 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
561 560
562 bfa_os_memset(mod, 0, sizeof(struct bfa_fcxp_mod_s)); 561 memset(mod, 0, sizeof(struct bfa_fcxp_mod_s));
563 mod->bfa = bfa; 562 mod->bfa = bfa;
564 mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs; 563 mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
565 564
566 /** 565 /*
567 * Initialize FCXP request and response payload sizes. 566 * Initialize FCXP request and response payload sizes.
568 */ 567 */
569 mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ; 568 mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
@@ -741,20 +740,20 @@ hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
741{ 740{
742 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); 741 struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
743 struct bfa_fcxp_s *fcxp; 742 struct bfa_fcxp_s *fcxp;
744 u16 fcxp_tag = bfa_os_ntohs(fcxp_rsp->fcxp_tag); 743 u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
745 744
746 bfa_trc(bfa, fcxp_tag); 745 bfa_trc(bfa, fcxp_tag);
747 746
748 fcxp_rsp->rsp_len = bfa_os_ntohl(fcxp_rsp->rsp_len); 747 fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
749 748
750 /** 749 /*
751 * @todo f/w should not set residue to non-0 when everything 750 * @todo f/w should not set residue to non-0 when everything
752 * is received. 751 * is received.
753 */ 752 */
754 if (fcxp_rsp->req_status == BFA_STATUS_OK) 753 if (fcxp_rsp->req_status == BFA_STATUS_OK)
755 fcxp_rsp->residue_len = 0; 754 fcxp_rsp->residue_len = 0;
756 else 755 else
757 fcxp_rsp->residue_len = bfa_os_ntohl(fcxp_rsp->residue_len); 756 fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
758 757
759 fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag); 758 fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
760 759
@@ -856,7 +855,7 @@ hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
856 } 855 }
857} 856}
858 857
859/** 858/*
860 * Handler to resume sending fcxp when space in available in cpe queue. 859 * Handler to resume sending fcxp when space in available in cpe queue.
861 */ 860 */
862static void 861static void
@@ -871,7 +870,7 @@ bfa_fcxp_qresume(void *cbarg)
871 bfa_fcxp_queue(fcxp, send_req); 870 bfa_fcxp_queue(fcxp, send_req);
872} 871}
873 872
874/** 873/*
875 * Queue fcxp send request to foimrware. 874 * Queue fcxp send request to foimrware.
876 */ 875 */
877static void 876static void
@@ -885,26 +884,26 @@ bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
885 bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ, 884 bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
886 bfa_lpuid(bfa)); 885 bfa_lpuid(bfa));
887 886
888 send_req->fcxp_tag = bfa_os_htons(fcxp->fcxp_tag); 887 send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
889 if (rport) { 888 if (rport) {
890 send_req->rport_fw_hndl = rport->fw_handle; 889 send_req->rport_fw_hndl = rport->fw_handle;
891 send_req->max_frmsz = bfa_os_htons(rport->rport_info.max_frmsz); 890 send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
892 if (send_req->max_frmsz == 0) 891 if (send_req->max_frmsz == 0)
893 send_req->max_frmsz = bfa_os_htons(FC_MAX_PDUSZ); 892 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
894 } else { 893 } else {
895 send_req->rport_fw_hndl = 0; 894 send_req->rport_fw_hndl = 0;
896 send_req->max_frmsz = bfa_os_htons(FC_MAX_PDUSZ); 895 send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
897 } 896 }
898 897
899 send_req->vf_id = bfa_os_htons(reqi->vf_id); 898 send_req->vf_id = cpu_to_be16(reqi->vf_id);
900 send_req->lp_tag = reqi->lp_tag; 899 send_req->lp_tag = reqi->lp_tag;
901 send_req->class = reqi->class; 900 send_req->class = reqi->class;
902 send_req->rsp_timeout = rspi->rsp_timeout; 901 send_req->rsp_timeout = rspi->rsp_timeout;
903 send_req->cts = reqi->cts; 902 send_req->cts = reqi->cts;
904 send_req->fchs = reqi->fchs; 903 send_req->fchs = reqi->fchs;
905 904
906 send_req->req_len = bfa_os_htonl(reqi->req_tot_len); 905 send_req->req_len = cpu_to_be32(reqi->req_tot_len);
907 send_req->rsp_maxlen = bfa_os_htonl(rspi->rsp_maxlen); 906 send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
908 907
909 /* 908 /*
910 * setup req sgles 909 * setup req sgles
@@ -955,11 +954,11 @@ bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
955 bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP)); 954 bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
956} 955}
957 956
958/** 957/*
959 * hal_fcxp_api BFA FCXP API 958 * hal_fcxp_api BFA FCXP API
960 */ 959 */
961 960
962/** 961/*
963 * Allocate an FCXP instance to send a response or to send a request 962 * Allocate an FCXP instance to send a response or to send a request
964 * that has a response. Request/response buffers are allocated by caller. 963 * that has a response. Request/response buffers are allocated by caller.
965 * 964 *
@@ -1005,7 +1004,7 @@ bfa_fcxp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
1005 return fcxp; 1004 return fcxp;
1006} 1005}
1007 1006
1008/** 1007/*
1009 * Get the internal request buffer pointer 1008 * Get the internal request buffer pointer
1010 * 1009 *
1011 * @param[in] fcxp BFA fcxp pointer 1010 * @param[in] fcxp BFA fcxp pointer
@@ -1032,7 +1031,7 @@ bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
1032 return mod->req_pld_sz; 1031 return mod->req_pld_sz;
1033} 1032}
1034 1033
1035/** 1034/*
1036 * Get the internal response buffer pointer 1035 * Get the internal response buffer pointer
1037 * 1036 *
1038 * @param[in] fcxp BFA fcxp pointer 1037 * @param[in] fcxp BFA fcxp pointer
@@ -1052,7 +1051,7 @@ bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
1052 return rspbuf; 1051 return rspbuf;
1053} 1052}
1054 1053
1055/** 1054/*
1056 * Free the BFA FCXP 1055 * Free the BFA FCXP
1057 * 1056 *
1058 * @param[in] fcxp BFA fcxp pointer 1057 * @param[in] fcxp BFA fcxp pointer
@@ -1069,7 +1068,7 @@ bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
1069 bfa_fcxp_put(fcxp); 1068 bfa_fcxp_put(fcxp);
1070} 1069}
1071 1070
1072/** 1071/*
1073 * Send a FCXP request 1072 * Send a FCXP request
1074 * 1073 *
1075 * @param[in] fcxp BFA fcxp pointer 1074 * @param[in] fcxp BFA fcxp pointer
@@ -1103,7 +1102,7 @@ bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1103 1102
1104 bfa_trc(bfa, fcxp->fcxp_tag); 1103 bfa_trc(bfa, fcxp->fcxp_tag);
1105 1104
1106 /** 1105 /*
1107 * setup request/response info 1106 * setup request/response info
1108 */ 1107 */
1109 reqi->bfa_rport = rport; 1108 reqi->bfa_rport = rport;
@@ -1118,7 +1117,7 @@ bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1118 fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp; 1117 fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
1119 fcxp->send_cbarg = cbarg; 1118 fcxp->send_cbarg = cbarg;
1120 1119
1121 /** 1120 /*
1122 * If no room in CPE queue, wait for space in request queue 1121 * If no room in CPE queue, wait for space in request queue
1123 */ 1122 */
1124 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP); 1123 send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
@@ -1132,7 +1131,7 @@ bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
1132 bfa_fcxp_queue(fcxp, send_req); 1131 bfa_fcxp_queue(fcxp, send_req);
1133} 1132}
1134 1133
1135/** 1134/*
1136 * Abort a BFA FCXP 1135 * Abort a BFA FCXP
1137 * 1136 *
1138 * @param[in] fcxp BFA fcxp pointer 1137 * @param[in] fcxp BFA fcxp pointer
@@ -1186,7 +1185,7 @@ bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
1186void 1185void
1187bfa_fcxp_discard(struct bfa_fcxp_s *fcxp) 1186bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
1188{ 1187{
1189 /** 1188 /*
1190 * If waiting for room in request queue, cancel reqq wait 1189 * If waiting for room in request queue, cancel reqq wait
1191 * and free fcxp. 1190 * and free fcxp.
1192 */ 1191 */
@@ -1202,7 +1201,7 @@ bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
1202 1201
1203 1202
1204 1203
1205/** 1204/*
1206 * hal_fcxp_public BFA FCXP public functions 1205 * hal_fcxp_public BFA FCXP public functions
1207 */ 1206 */
1208 1207
@@ -1229,11 +1228,11 @@ bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
1229} 1228}
1230 1229
1231 1230
1232/** 1231/*
1233 * BFA LPS state machine functions 1232 * BFA LPS state machine functions
1234 */ 1233 */
1235 1234
1236/** 1235/*
1237 * Init state -- no login 1236 * Init state -- no login
1238 */ 1237 */
1239static void 1238static void
@@ -1285,7 +1284,7 @@ bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
1285 } 1284 }
1286} 1285}
1287 1286
1288/** 1287/*
1289 * login is in progress -- awaiting response from firmware 1288 * login is in progress -- awaiting response from firmware
1290 */ 1289 */
1291static void 1290static void
@@ -1327,7 +1326,7 @@ bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
1327 } 1326 }
1328} 1327}
1329 1328
1330/** 1329/*
1331 * login pending - awaiting space in request queue 1330 * login pending - awaiting space in request queue
1332 */ 1331 */
1333static void 1332static void
@@ -1359,7 +1358,7 @@ bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1359 } 1358 }
1360} 1359}
1361 1360
1362/** 1361/*
1363 * login complete 1362 * login complete
1364 */ 1363 */
1365static void 1364static void
@@ -1400,7 +1399,7 @@ bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
1400 } 1399 }
1401} 1400}
1402 1401
1403/** 1402/*
1404 * logout in progress - awaiting firmware response 1403 * logout in progress - awaiting firmware response
1405 */ 1404 */
1406static void 1405static void
@@ -1424,7 +1423,7 @@ bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
1424 } 1423 }
1425} 1424}
1426 1425
1427/** 1426/*
1428 * logout pending -- awaiting space in request queue 1427 * logout pending -- awaiting space in request queue
1429 */ 1428 */
1430static void 1429static void
@@ -1451,11 +1450,11 @@ bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
1451 1450
1452 1451
1453 1452
1454/** 1453/*
1455 * lps_pvt BFA LPS private functions 1454 * lps_pvt BFA LPS private functions
1456 */ 1455 */
1457 1456
1458/** 1457/*
1459 * return memory requirement 1458 * return memory requirement
1460 */ 1459 */
1461static void 1460static void
@@ -1468,7 +1467,7 @@ bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
1468 *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS; 1467 *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS;
1469} 1468}
1470 1469
1471/** 1470/*
1472 * bfa module attach at initialization time 1471 * bfa module attach at initialization time
1473 */ 1472 */
1474static void 1473static void
@@ -1479,7 +1478,7 @@ bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1479 struct bfa_lps_s *lps; 1478 struct bfa_lps_s *lps;
1480 int i; 1479 int i;
1481 1480
1482 bfa_os_memset(mod, 0, sizeof(struct bfa_lps_mod_s)); 1481 memset(mod, 0, sizeof(struct bfa_lps_mod_s));
1483 mod->num_lps = BFA_LPS_MAX_LPORTS; 1482 mod->num_lps = BFA_LPS_MAX_LPORTS;
1484 if (cfg->drvcfg.min_cfg) 1483 if (cfg->drvcfg.min_cfg)
1485 mod->num_lps = BFA_LPS_MIN_LPORTS; 1484 mod->num_lps = BFA_LPS_MIN_LPORTS;
@@ -1516,7 +1515,7 @@ bfa_lps_stop(struct bfa_s *bfa)
1516{ 1515{
1517} 1516}
1518 1517
1519/** 1518/*
1520 * IOC in disabled state -- consider all lps offline 1519 * IOC in disabled state -- consider all lps offline
1521 */ 1520 */
1522static void 1521static void
@@ -1532,7 +1531,7 @@ bfa_lps_iocdisable(struct bfa_s *bfa)
1532 } 1531 }
1533} 1532}
1534 1533
1535/** 1534/*
1536 * Firmware login response 1535 * Firmware login response
1537 */ 1536 */
1538static void 1537static void
@@ -1550,7 +1549,7 @@ bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1550 lps->fport = rsp->f_port; 1549 lps->fport = rsp->f_port;
1551 lps->npiv_en = rsp->npiv_en; 1550 lps->npiv_en = rsp->npiv_en;
1552 lps->lp_pid = rsp->lp_pid; 1551 lps->lp_pid = rsp->lp_pid;
1553 lps->pr_bbcred = bfa_os_ntohs(rsp->bb_credit); 1552 lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
1554 lps->pr_pwwn = rsp->port_name; 1553 lps->pr_pwwn = rsp->port_name;
1555 lps->pr_nwwn = rsp->node_name; 1554 lps->pr_nwwn = rsp->node_name;
1556 lps->auth_req = rsp->auth_req; 1555 lps->auth_req = rsp->auth_req;
@@ -1579,7 +1578,7 @@ bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
1579 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP); 1578 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1580} 1579}
1581 1580
1582/** 1581/*
1583 * Firmware logout response 1582 * Firmware logout response
1584 */ 1583 */
1585static void 1584static void
@@ -1594,7 +1593,7 @@ bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
1594 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP); 1593 bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
1595} 1594}
1596 1595
1597/** 1596/*
1598 * Firmware received a Clear virtual link request (for FCoE) 1597 * Firmware received a Clear virtual link request (for FCoE)
1599 */ 1598 */
1600static void 1599static void
@@ -1608,7 +1607,7 @@ bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
1608 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL); 1607 bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
1609} 1608}
1610 1609
1611/** 1610/*
1612 * Space is available in request queue, resume queueing request to firmware. 1611 * Space is available in request queue, resume queueing request to firmware.
1613 */ 1612 */
1614static void 1613static void
@@ -1619,7 +1618,7 @@ bfa_lps_reqq_resume(void *lps_arg)
1619 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME); 1618 bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
1620} 1619}
1621 1620
1622/** 1621/*
1623 * lps is freed -- triggered by vport delete 1622 * lps is freed -- triggered by vport delete
1624 */ 1623 */
1625static void 1624static void
@@ -1632,7 +1631,7 @@ bfa_lps_free(struct bfa_lps_s *lps)
1632 list_add_tail(&lps->qe, &mod->lps_free_q); 1631 list_add_tail(&lps->qe, &mod->lps_free_q);
1633} 1632}
1634 1633
1635/** 1634/*
1636 * send login request to firmware 1635 * send login request to firmware
1637 */ 1636 */
1638static void 1637static void
@@ -1648,7 +1647,7 @@ bfa_lps_send_login(struct bfa_lps_s *lps)
1648 1647
1649 m->lp_tag = lps->lp_tag; 1648 m->lp_tag = lps->lp_tag;
1650 m->alpa = lps->alpa; 1649 m->alpa = lps->alpa;
1651 m->pdu_size = bfa_os_htons(lps->pdusz); 1650 m->pdu_size = cpu_to_be16(lps->pdusz);
1652 m->pwwn = lps->pwwn; 1651 m->pwwn = lps->pwwn;
1653 m->nwwn = lps->nwwn; 1652 m->nwwn = lps->nwwn;
1654 m->fdisc = lps->fdisc; 1653 m->fdisc = lps->fdisc;
@@ -1657,7 +1656,7 @@ bfa_lps_send_login(struct bfa_lps_s *lps)
1657 bfa_reqq_produce(lps->bfa, lps->reqq); 1656 bfa_reqq_produce(lps->bfa, lps->reqq);
1658} 1657}
1659 1658
1660/** 1659/*
1661 * send logout request to firmware 1660 * send logout request to firmware
1662 */ 1661 */
1663static void 1662static void
@@ -1676,7 +1675,7 @@ bfa_lps_send_logout(struct bfa_lps_s *lps)
1676 bfa_reqq_produce(lps->bfa, lps->reqq); 1675 bfa_reqq_produce(lps->bfa, lps->reqq);
1677} 1676}
1678 1677
1679/** 1678/*
1680 * Indirect login completion handler for non-fcs 1679 * Indirect login completion handler for non-fcs
1681 */ 1680 */
1682static void 1681static void
@@ -1693,7 +1692,7 @@ bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
1693 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status); 1692 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1694} 1693}
1695 1694
1696/** 1695/*
1697 * Login completion handler -- direct call for fcs, queue for others 1696 * Login completion handler -- direct call for fcs, queue for others
1698 */ 1697 */
1699static void 1698static void
@@ -1711,7 +1710,7 @@ bfa_lps_login_comp(struct bfa_lps_s *lps)
1711 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status); 1710 bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
1712} 1711}
1713 1712
1714/** 1713/*
1715 * Indirect logout completion handler for non-fcs 1714 * Indirect logout completion handler for non-fcs
1716 */ 1715 */
1717static void 1716static void
@@ -1726,7 +1725,7 @@ bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
1726 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg); 1725 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1727} 1726}
1728 1727
1729/** 1728/*
1730 * Logout completion handler -- direct call for fcs, queue for others 1729 * Logout completion handler -- direct call for fcs, queue for others
1731 */ 1730 */
1732static void 1731static void
@@ -1741,7 +1740,7 @@ bfa_lps_logout_comp(struct bfa_lps_s *lps)
1741 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg); 1740 bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
1742} 1741}
1743 1742
1744/** 1743/*
1745 * Clear virtual link completion handler for non-fcs 1744 * Clear virtual link completion handler for non-fcs
1746 */ 1745 */
1747static void 1746static void
@@ -1757,7 +1756,7 @@ bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
1757 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg); 1756 bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
1758} 1757}
1759 1758
1760/** 1759/*
1761 * Received Clear virtual link event --direct call for fcs, 1760 * Received Clear virtual link event --direct call for fcs,
1762 * queue for others 1761 * queue for others
1763 */ 1762 */
@@ -1777,7 +1776,7 @@ bfa_lps_cvl_event(struct bfa_lps_s *lps)
1777 1776
1778 1777
1779 1778
1780/** 1779/*
1781 * lps_public BFA LPS public functions 1780 * lps_public BFA LPS public functions
1782 */ 1781 */
1783 1782
@@ -1790,7 +1789,7 @@ bfa_lps_get_max_vport(struct bfa_s *bfa)
1790 return BFA_LPS_MAX_VPORTS_SUPP_CB; 1789 return BFA_LPS_MAX_VPORTS_SUPP_CB;
1791} 1790}
1792 1791
1793/** 1792/*
1794 * Allocate a lport srvice tag. 1793 * Allocate a lport srvice tag.
1795 */ 1794 */
1796struct bfa_lps_s * 1795struct bfa_lps_s *
@@ -1810,7 +1809,7 @@ bfa_lps_alloc(struct bfa_s *bfa)
1810 return lps; 1809 return lps;
1811} 1810}
1812 1811
1813/** 1812/*
1814 * Free lport service tag. This can be called anytime after an alloc. 1813 * Free lport service tag. This can be called anytime after an alloc.
1815 * No need to wait for any pending login/logout completions. 1814 * No need to wait for any pending login/logout completions.
1816 */ 1815 */
@@ -1820,7 +1819,7 @@ bfa_lps_delete(struct bfa_lps_s *lps)
1820 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE); 1819 bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
1821} 1820}
1822 1821
1823/** 1822/*
1824 * Initiate a lport login. 1823 * Initiate a lport login.
1825 */ 1824 */
1826void 1825void
@@ -1837,7 +1836,7 @@ bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
1837 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN); 1836 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1838} 1837}
1839 1838
1840/** 1839/*
1841 * Initiate a lport fdisc login. 1840 * Initiate a lport fdisc login.
1842 */ 1841 */
1843void 1842void
@@ -1854,7 +1853,7 @@ bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
1854 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN); 1853 bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
1855} 1854}
1856 1855
1857/** 1856/*
1858 * Initiate a lport logout (flogi). 1857 * Initiate a lport logout (flogi).
1859 */ 1858 */
1860void 1859void
@@ -1863,7 +1862,7 @@ bfa_lps_flogo(struct bfa_lps_s *lps)
1863 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT); 1862 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1864} 1863}
1865 1864
1866/** 1865/*
1867 * Initiate a lport FDSIC logout. 1866 * Initiate a lport FDSIC logout.
1868 */ 1867 */
1869void 1868void
@@ -1872,7 +1871,7 @@ bfa_lps_fdisclogo(struct bfa_lps_s *lps)
1872 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT); 1871 bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
1873} 1872}
1874 1873
1875/** 1874/*
1876 * Discard a pending login request -- should be called only for 1875 * Discard a pending login request -- should be called only for
1877 * link down handling. 1876 * link down handling.
1878 */ 1877 */
@@ -1882,7 +1881,7 @@ bfa_lps_discard(struct bfa_lps_s *lps)
1882 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE); 1881 bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
1883} 1882}
1884 1883
1885/** 1884/*
1886 * Return lport services tag 1885 * Return lport services tag
1887 */ 1886 */
1888u8 1887u8
@@ -1891,7 +1890,7 @@ bfa_lps_get_tag(struct bfa_lps_s *lps)
1891 return lps->lp_tag; 1890 return lps->lp_tag;
1892} 1891}
1893 1892
1894/** 1893/*
1895 * Return lport services tag given the pid 1894 * Return lport services tag given the pid
1896 */ 1895 */
1897u8 1896u8
@@ -1910,7 +1909,7 @@ bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
1910 return 0; 1909 return 0;
1911} 1910}
1912 1911
1913/** 1912/*
1914 * return if fabric login indicates support for NPIV 1913 * return if fabric login indicates support for NPIV
1915 */ 1914 */
1916bfa_boolean_t 1915bfa_boolean_t
@@ -1919,7 +1918,7 @@ bfa_lps_is_npiv_en(struct bfa_lps_s *lps)
1919 return lps->npiv_en; 1918 return lps->npiv_en;
1920} 1919}
1921 1920
1922/** 1921/*
1923 * Return TRUE if attached to F-Port, else return FALSE 1922 * Return TRUE if attached to F-Port, else return FALSE
1924 */ 1923 */
1925bfa_boolean_t 1924bfa_boolean_t
@@ -1928,7 +1927,7 @@ bfa_lps_is_fport(struct bfa_lps_s *lps)
1928 return lps->fport; 1927 return lps->fport;
1929} 1928}
1930 1929
1931/** 1930/*
1932 * Return TRUE if attached to a Brocade Fabric 1931 * Return TRUE if attached to a Brocade Fabric
1933 */ 1932 */
1934bfa_boolean_t 1933bfa_boolean_t
@@ -1936,7 +1935,7 @@ bfa_lps_is_brcd_fabric(struct bfa_lps_s *lps)
1936{ 1935{
1937 return lps->brcd_switch; 1936 return lps->brcd_switch;
1938} 1937}
1939/** 1938/*
1940 * return TRUE if authentication is required 1939 * return TRUE if authentication is required
1941 */ 1940 */
1942bfa_boolean_t 1941bfa_boolean_t
@@ -1951,7 +1950,7 @@ bfa_lps_get_extstatus(struct bfa_lps_s *lps)
1951 return lps->ext_status; 1950 return lps->ext_status;
1952} 1951}
1953 1952
1954/** 1953/*
1955 * return port id assigned to the lport 1954 * return port id assigned to the lport
1956 */ 1955 */
1957u32 1956u32
@@ -1960,7 +1959,7 @@ bfa_lps_get_pid(struct bfa_lps_s *lps)
1960 return lps->lp_pid; 1959 return lps->lp_pid;
1961} 1960}
1962 1961
1963/** 1962/*
1964 * return port id assigned to the base lport 1963 * return port id assigned to the base lport
1965 */ 1964 */
1966u32 1965u32
@@ -1971,7 +1970,7 @@ bfa_lps_get_base_pid(struct bfa_s *bfa)
1971 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid; 1970 return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
1972} 1971}
1973 1972
1974/** 1973/*
1975 * Return bb_credit assigned in FLOGI response 1974 * Return bb_credit assigned in FLOGI response
1976 */ 1975 */
1977u16 1976u16
@@ -1980,7 +1979,7 @@ bfa_lps_get_peer_bbcredit(struct bfa_lps_s *lps)
1980 return lps->pr_bbcred; 1979 return lps->pr_bbcred;
1981} 1980}
1982 1981
1983/** 1982/*
1984 * Return peer port name 1983 * Return peer port name
1985 */ 1984 */
1986wwn_t 1985wwn_t
@@ -1989,7 +1988,7 @@ bfa_lps_get_peer_pwwn(struct bfa_lps_s *lps)
1989 return lps->pr_pwwn; 1988 return lps->pr_pwwn;
1990} 1989}
1991 1990
1992/** 1991/*
1993 * Return peer node name 1992 * Return peer node name
1994 */ 1993 */
1995wwn_t 1994wwn_t
@@ -1998,7 +1997,7 @@ bfa_lps_get_peer_nwwn(struct bfa_lps_s *lps)
1998 return lps->pr_nwwn; 1997 return lps->pr_nwwn;
1999} 1998}
2000 1999
2001/** 2000/*
2002 * return reason code if login request is rejected 2001 * return reason code if login request is rejected
2003 */ 2002 */
2004u8 2003u8
@@ -2007,7 +2006,7 @@ bfa_lps_get_lsrjt_rsn(struct bfa_lps_s *lps)
2007 return lps->lsrjt_rsn; 2006 return lps->lsrjt_rsn;
2008} 2007}
2009 2008
2010/** 2009/*
2011 * return explanation code if login request is rejected 2010 * return explanation code if login request is rejected
2012 */ 2011 */
2013u8 2012u8
@@ -2016,7 +2015,7 @@ bfa_lps_get_lsrjt_expl(struct bfa_lps_s *lps)
2016 return lps->lsrjt_expl; 2015 return lps->lsrjt_expl;
2017} 2016}
2018 2017
2019/** 2018/*
2020 * Return fpma/spma MAC for lport 2019 * Return fpma/spma MAC for lport
2021 */ 2020 */
2022mac_t 2021mac_t
@@ -2025,7 +2024,7 @@ bfa_lps_get_lp_mac(struct bfa_lps_s *lps)
2025 return lps->lp_mac; 2024 return lps->lp_mac;
2026} 2025}
2027 2026
2028/** 2027/*
2029 * LPS firmware message class handler. 2028 * LPS firmware message class handler.
2030 */ 2029 */
2031void 2030void
@@ -2055,7 +2054,7 @@ bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2055 } 2054 }
2056} 2055}
2057 2056
2058/** 2057/*
2059 * FC PORT state machine functions 2058 * FC PORT state machine functions
2060 */ 2059 */
2061static void 2060static void
@@ -2066,7 +2065,7 @@ bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2066 2065
2067 switch (event) { 2066 switch (event) {
2068 case BFA_FCPORT_SM_START: 2067 case BFA_FCPORT_SM_START:
2069 /** 2068 /*
2070 * Start event after IOC is configured and BFA is started. 2069 * Start event after IOC is configured and BFA is started.
2071 */ 2070 */
2072 if (bfa_fcport_send_enable(fcport)) { 2071 if (bfa_fcport_send_enable(fcport)) {
@@ -2080,7 +2079,7 @@ bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2080 break; 2079 break;
2081 2080
2082 case BFA_FCPORT_SM_ENABLE: 2081 case BFA_FCPORT_SM_ENABLE:
2083 /** 2082 /*
2084 * Port is persistently configured to be in enabled state. Do 2083 * Port is persistently configured to be in enabled state. Do
2085 * not change state. Port enabling is done when START event is 2084 * not change state. Port enabling is done when START event is
2086 * received. 2085 * received.
@@ -2088,7 +2087,7 @@ bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
2088 break; 2087 break;
2089 2088
2090 case BFA_FCPORT_SM_DISABLE: 2089 case BFA_FCPORT_SM_DISABLE:
2091 /** 2090 /*
2092 * If a port is persistently configured to be disabled, the 2091 * If a port is persistently configured to be disabled, the
2093 * first event will a port disable request. 2092 * first event will a port disable request.
2094 */ 2093 */
@@ -2124,13 +2123,13 @@ bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2124 break; 2123 break;
2125 2124
2126 case BFA_FCPORT_SM_ENABLE: 2125 case BFA_FCPORT_SM_ENABLE:
2127 /** 2126 /*
2128 * Already enable is in progress. 2127 * Already enable is in progress.
2129 */ 2128 */
2130 break; 2129 break;
2131 2130
2132 case BFA_FCPORT_SM_DISABLE: 2131 case BFA_FCPORT_SM_DISABLE:
2133 /** 2132 /*
2134 * Just send disable request to firmware when room becomes 2133 * Just send disable request to firmware when room becomes
2135 * available in request queue. 2134 * available in request queue.
2136 */ 2135 */
@@ -2145,7 +2144,7 @@ bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
2145 2144
2146 case BFA_FCPORT_SM_LINKUP: 2145 case BFA_FCPORT_SM_LINKUP:
2147 case BFA_FCPORT_SM_LINKDOWN: 2146 case BFA_FCPORT_SM_LINKDOWN:
2148 /** 2147 /*
2149 * Possible to get link events when doing back-to-back 2148 * Possible to get link events when doing back-to-back
2150 * enable/disables. 2149 * enable/disables.
2151 */ 2150 */
@@ -2184,7 +2183,7 @@ bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
2184 break; 2183 break;
2185 2184
2186 case BFA_FCPORT_SM_ENABLE: 2185 case BFA_FCPORT_SM_ENABLE:
2187 /** 2186 /*
2188 * Already being enabled. 2187 * Already being enabled.
2189 */ 2188 */
2190 break; 2189 break;
@@ -2257,13 +2256,13 @@ bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
2257 break; 2256 break;
2258 2257
2259 case BFA_FCPORT_SM_LINKDOWN: 2258 case BFA_FCPORT_SM_LINKDOWN:
2260 /** 2259 /*
2261 * Possible to get link down event. 2260 * Possible to get link down event.
2262 */ 2261 */
2263 break; 2262 break;
2264 2263
2265 case BFA_FCPORT_SM_ENABLE: 2264 case BFA_FCPORT_SM_ENABLE:
2266 /** 2265 /*
2267 * Already enabled. 2266 * Already enabled.
2268 */ 2267 */
2269 break; 2268 break;
@@ -2306,7 +2305,7 @@ bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
2306 2305
2307 switch (event) { 2306 switch (event) {
2308 case BFA_FCPORT_SM_ENABLE: 2307 case BFA_FCPORT_SM_ENABLE:
2309 /** 2308 /*
2310 * Already enabled. 2309 * Already enabled.
2311 */ 2310 */
2312 break; 2311 break;
@@ -2399,14 +2398,14 @@ bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
2399 break; 2398 break;
2400 2399
2401 case BFA_FCPORT_SM_DISABLE: 2400 case BFA_FCPORT_SM_DISABLE:
2402 /** 2401 /*
2403 * Already being disabled. 2402 * Already being disabled.
2404 */ 2403 */
2405 break; 2404 break;
2406 2405
2407 case BFA_FCPORT_SM_LINKUP: 2406 case BFA_FCPORT_SM_LINKUP:
2408 case BFA_FCPORT_SM_LINKDOWN: 2407 case BFA_FCPORT_SM_LINKDOWN:
2409 /** 2408 /*
2410 * Possible to get link events when doing back-to-back 2409 * Possible to get link events when doing back-to-back
2411 * enable/disables. 2410 * enable/disables.
2412 */ 2411 */
@@ -2453,7 +2452,7 @@ bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
2453 2452
2454 case BFA_FCPORT_SM_LINKUP: 2453 case BFA_FCPORT_SM_LINKUP:
2455 case BFA_FCPORT_SM_LINKDOWN: 2454 case BFA_FCPORT_SM_LINKDOWN:
2456 /** 2455 /*
2457 * Possible to get link events when doing back-to-back 2456 * Possible to get link events when doing back-to-back
2458 * enable/disables. 2457 * enable/disables.
2459 */ 2458 */
@@ -2483,7 +2482,7 @@ bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2483 break; 2482 break;
2484 2483
2485 case BFA_FCPORT_SM_DISABLE: 2484 case BFA_FCPORT_SM_DISABLE:
2486 /** 2485 /*
2487 * Already being disabled. 2486 * Already being disabled.
2488 */ 2487 */
2489 break; 2488 break;
@@ -2508,7 +2507,7 @@ bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
2508 2507
2509 case BFA_FCPORT_SM_LINKUP: 2508 case BFA_FCPORT_SM_LINKUP:
2510 case BFA_FCPORT_SM_LINKDOWN: 2509 case BFA_FCPORT_SM_LINKDOWN:
2511 /** 2510 /*
2512 * Possible to get link events when doing back-to-back 2511 * Possible to get link events when doing back-to-back
2513 * enable/disables. 2512 * enable/disables.
2514 */ 2513 */
@@ -2533,7 +2532,7 @@ bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2533 2532
2534 switch (event) { 2533 switch (event) {
2535 case BFA_FCPORT_SM_START: 2534 case BFA_FCPORT_SM_START:
2536 /** 2535 /*
2537 * Ignore start event for a port that is disabled. 2536 * Ignore start event for a port that is disabled.
2538 */ 2537 */
2539 break; 2538 break;
@@ -2557,7 +2556,7 @@ bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
2557 break; 2556 break;
2558 2557
2559 case BFA_FCPORT_SM_DISABLE: 2558 case BFA_FCPORT_SM_DISABLE:
2560 /** 2559 /*
2561 * Already disabled. 2560 * Already disabled.
2562 */ 2561 */
2563 break; 2562 break;
@@ -2587,14 +2586,14 @@ bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
2587 break; 2586 break;
2588 2587
2589 default: 2588 default:
2590 /** 2589 /*
2591 * Ignore all other events. 2590 * Ignore all other events.
2592 */ 2591 */
2593 ; 2592 ;
2594 } 2593 }
2595} 2594}
2596 2595
2597/** 2596/*
2598 * Port is enabled. IOC is down/failed. 2597 * Port is enabled. IOC is down/failed.
2599 */ 2598 */
2600static void 2599static void
@@ -2613,14 +2612,14 @@ bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
2613 break; 2612 break;
2614 2613
2615 default: 2614 default:
2616 /** 2615 /*
2617 * Ignore all events. 2616 * Ignore all events.
2618 */ 2617 */
2619 ; 2618 ;
2620 } 2619 }
2621} 2620}
2622 2621
2623/** 2622/*
2624 * Port is disabled. IOC is down/failed. 2623 * Port is disabled. IOC is down/failed.
2625 */ 2624 */
2626static void 2625static void
@@ -2639,14 +2638,14 @@ bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
2639 break; 2638 break;
2640 2639
2641 default: 2640 default:
2642 /** 2641 /*
2643 * Ignore all events. 2642 * Ignore all events.
2644 */ 2643 */
2645 ; 2644 ;
2646 } 2645 }
2647} 2646}
2648 2647
2649/** 2648/*
2650 * Link state is down 2649 * Link state is down
2651 */ 2650 */
2652static void 2651static void
@@ -2666,7 +2665,7 @@ bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
2666 } 2665 }
2667} 2666}
2668 2667
2669/** 2668/*
2670 * Link state is waiting for down notification 2669 * Link state is waiting for down notification
2671 */ 2670 */
2672static void 2671static void
@@ -2689,7 +2688,7 @@ bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
2689 } 2688 }
2690} 2689}
2691 2690
2692/** 2691/*
2693 * Link state is waiting for down notification and there is a pending up 2692 * Link state is waiting for down notification and there is a pending up
2694 */ 2693 */
2695static void 2694static void
@@ -2713,7 +2712,7 @@ bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
2713 } 2712 }
2714} 2713}
2715 2714
2716/** 2715/*
2717 * Link state is up 2716 * Link state is up
2718 */ 2717 */
2719static void 2718static void
@@ -2733,7 +2732,7 @@ bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
2733 } 2732 }
2734} 2733}
2735 2734
2736/** 2735/*
2737 * Link state is waiting for up notification 2736 * Link state is waiting for up notification
2738 */ 2737 */
2739static void 2738static void
@@ -2756,7 +2755,7 @@ bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
2756 } 2755 }
2757} 2756}
2758 2757
2759/** 2758/*
2760 * Link state is waiting for up notification and there is a pending down 2759 * Link state is waiting for up notification and there is a pending down
2761 */ 2760 */
2762static void 2761static void
@@ -2780,7 +2779,7 @@ bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
2780 } 2779 }
2781} 2780}
2782 2781
2783/** 2782/*
2784 * Link state is waiting for up notification and there are pending down and up 2783 * Link state is waiting for up notification and there are pending down and up
2785 */ 2784 */
2786static void 2785static void
@@ -2806,7 +2805,7 @@ bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
2806 2805
2807 2806
2808 2807
2809/** 2808/*
2810 * hal_port_private 2809 * hal_port_private
2811 */ 2810 */
2812 2811
@@ -2821,7 +2820,7 @@ __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
2821 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION); 2820 bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
2822} 2821}
2823 2822
2824/** 2823/*
2825 * Send SCN notification to upper layers. 2824 * Send SCN notification to upper layers.
2826 * trunk - false if caller is fcport to ignore fcport event in trunked mode 2825 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2827 */ 2826 */
@@ -2897,7 +2896,7 @@ bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo)
2897 bfa_meminfo_dma_phys(meminfo) = dm_pa; 2896 bfa_meminfo_dma_phys(meminfo) = dm_pa;
2898} 2897}
2899 2898
2900/** 2899/*
2901 * Memory initialization. 2900 * Memory initialization.
2902 */ 2901 */
2903static void 2902static void
@@ -2909,7 +2908,7 @@ bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
2909 struct bfa_fcport_ln_s *ln = &fcport->ln; 2908 struct bfa_fcport_ln_s *ln = &fcport->ln;
2910 struct bfa_timeval_s tv; 2909 struct bfa_timeval_s tv;
2911 2910
2912 bfa_os_memset(fcport, 0, sizeof(struct bfa_fcport_s)); 2911 memset(fcport, 0, sizeof(struct bfa_fcport_s));
2913 fcport->bfa = bfa; 2912 fcport->bfa = bfa;
2914 ln->fcport = fcport; 2913 ln->fcport = fcport;
2915 2914
@@ -2918,13 +2917,13 @@ bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
2918 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit); 2917 bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
2919 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn); 2918 bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
2920 2919
2921 /** 2920 /*
2922 * initialize time stamp for stats reset 2921 * initialize time stamp for stats reset
2923 */ 2922 */
2924 bfa_os_gettimeofday(&tv); 2923 bfa_os_gettimeofday(&tv);
2925 fcport->stats_reset_time = tv.tv_sec; 2924 fcport->stats_reset_time = tv.tv_sec;
2926 2925
2927 /** 2926 /*
2928 * initialize and set default configuration 2927 * initialize and set default configuration
2929 */ 2928 */
2930 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P; 2929 port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
@@ -2942,7 +2941,7 @@ bfa_fcport_detach(struct bfa_s *bfa)
2942{ 2941{
2943} 2942}
2944 2943
2945/** 2944/*
2946 * Called when IOC is ready. 2945 * Called when IOC is ready.
2947 */ 2946 */
2948static void 2947static void
@@ -2951,7 +2950,7 @@ bfa_fcport_start(struct bfa_s *bfa)
2951 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START); 2950 bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
2952} 2951}
2953 2952
2954/** 2953/*
2955 * Called before IOC is stopped. 2954 * Called before IOC is stopped.
2956 */ 2955 */
2957static void 2956static void
@@ -2961,7 +2960,7 @@ bfa_fcport_stop(struct bfa_s *bfa)
2961 bfa_trunk_iocdisable(bfa); 2960 bfa_trunk_iocdisable(bfa);
2962} 2961}
2963 2962
2964/** 2963/*
2965 * Called when IOC failure is detected. 2964 * Called when IOC failure is detected.
2966 */ 2965 */
2967static void 2966static void
@@ -2986,18 +2985,17 @@ bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
2986 fcport->myalpa = 0; 2985 fcport->myalpa = 0;
2987 2986
2988 /* QoS Details */ 2987 /* QoS Details */
2989 bfa_os_assign(fcport->qos_attr, pevent->link_state.qos_attr); 2988 fcport->qos_attr = pevent->link_state.qos_attr;
2990 bfa_os_assign(fcport->qos_vc_attr, 2989 fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
2991 pevent->link_state.vc_fcf.qos_vc_attr);
2992 2990
2993 /** 2991 /*
2994 * update trunk state if applicable 2992 * update trunk state if applicable
2995 */ 2993 */
2996 if (!fcport->cfg.trunked) 2994 if (!fcport->cfg.trunked)
2997 trunk->attr.state = BFA_TRUNK_DISABLED; 2995 trunk->attr.state = BFA_TRUNK_DISABLED;
2998 2996
2999 /* update FCoE specific */ 2997 /* update FCoE specific */
3000 fcport->fcoe_vlan = bfa_os_ntohs(pevent->link_state.vc_fcf.fcf.vlan); 2998 fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
3001 2999
3002 bfa_trc(fcport->bfa, fcport->speed); 3000 bfa_trc(fcport->bfa, fcport->speed);
3003 bfa_trc(fcport->bfa, fcport->topology); 3001 bfa_trc(fcport->bfa, fcport->topology);
@@ -3010,7 +3008,7 @@ bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
3010 fcport->topology = BFA_PORT_TOPOLOGY_NONE; 3008 fcport->topology = BFA_PORT_TOPOLOGY_NONE;
3011} 3009}
3012 3010
3013/** 3011/*
3014 * Send port enable message to firmware. 3012 * Send port enable message to firmware.
3015 */ 3013 */
3016static bfa_boolean_t 3014static bfa_boolean_t
@@ -3018,13 +3016,13 @@ bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
3018{ 3016{
3019 struct bfi_fcport_enable_req_s *m; 3017 struct bfi_fcport_enable_req_s *m;
3020 3018
3021 /** 3019 /*
3022 * Increment message tag before queue check, so that responses to old 3020 * Increment message tag before queue check, so that responses to old
3023 * requests are discarded. 3021 * requests are discarded.
3024 */ 3022 */
3025 fcport->msgtag++; 3023 fcport->msgtag++;
3026 3024
3027 /** 3025 /*
3028 * check for room in queue to send request now 3026 * check for room in queue to send request now
3029 */ 3027 */
3030 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); 3028 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
@@ -3040,19 +3038,19 @@ bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
3040 m->pwwn = fcport->pwwn; 3038 m->pwwn = fcport->pwwn;
3041 m->port_cfg = fcport->cfg; 3039 m->port_cfg = fcport->cfg;
3042 m->msgtag = fcport->msgtag; 3040 m->msgtag = fcport->msgtag;
3043 m->port_cfg.maxfrsize = bfa_os_htons(fcport->cfg.maxfrsize); 3041 m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
3044 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa); 3042 bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
3045 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo); 3043 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
3046 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi); 3044 bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
3047 3045
3048 /** 3046 /*
3049 * queue I/O message to firmware 3047 * queue I/O message to firmware
3050 */ 3048 */
3051 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); 3049 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
3052 return BFA_TRUE; 3050 return BFA_TRUE;
3053} 3051}
3054 3052
3055/** 3053/*
3056 * Send port disable message to firmware. 3054 * Send port disable message to firmware.
3057 */ 3055 */
3058static bfa_boolean_t 3056static bfa_boolean_t
@@ -3060,13 +3058,13 @@ bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
3060{ 3058{
3061 struct bfi_fcport_req_s *m; 3059 struct bfi_fcport_req_s *m;
3062 3060
3063 /** 3061 /*
3064 * Increment message tag before queue check, so that responses to old 3062 * Increment message tag before queue check, so that responses to old
3065 * requests are discarded. 3063 * requests are discarded.
3066 */ 3064 */
3067 fcport->msgtag++; 3065 fcport->msgtag++;
3068 3066
3069 /** 3067 /*
3070 * check for room in queue to send request now 3068 * check for room in queue to send request now
3071 */ 3069 */
3072 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); 3070 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
@@ -3080,7 +3078,7 @@ bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
3080 bfa_lpuid(fcport->bfa)); 3078 bfa_lpuid(fcport->bfa));
3081 m->msgtag = fcport->msgtag; 3079 m->msgtag = fcport->msgtag;
3082 3080
3083 /** 3081 /*
3084 * queue I/O message to firmware 3082 * queue I/O message to firmware
3085 */ 3083 */
3086 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); 3084 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
@@ -3105,7 +3103,7 @@ bfa_fcport_send_txcredit(void *port_cbarg)
3105 struct bfa_fcport_s *fcport = port_cbarg; 3103 struct bfa_fcport_s *fcport = port_cbarg;
3106 struct bfi_fcport_set_svc_params_req_s *m; 3104 struct bfi_fcport_set_svc_params_req_s *m;
3107 3105
3108 /** 3106 /*
3109 * check for room in queue to send request now 3107 * check for room in queue to send request now
3110 */ 3108 */
3111 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); 3109 m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
@@ -3116,9 +3114,9 @@ bfa_fcport_send_txcredit(void *port_cbarg)
3116 3114
3117 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ, 3115 bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
3118 bfa_lpuid(fcport->bfa)); 3116 bfa_lpuid(fcport->bfa));
3119 m->tx_bbcredit = bfa_os_htons((u16)fcport->cfg.tx_bbcredit); 3117 m->tx_bbcredit = cpu_to_be16((u16)fcport->cfg.tx_bbcredit);
3120 3118
3121 /** 3119 /*
3122 * queue I/O message to firmware 3120 * queue I/O message to firmware
3123 */ 3121 */
3124 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); 3122 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
@@ -3134,7 +3132,7 @@ bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
3134 3132
3135 /* Now swap the 32 bit fields */ 3133 /* Now swap the 32 bit fields */
3136 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i) 3134 for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
3137 dip[i] = bfa_os_ntohl(sip[i]); 3135 dip[i] = be32_to_cpu(sip[i]);
3138} 3136}
3139 3137
3140static void 3138static void
@@ -3148,11 +3146,11 @@ bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
3148 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32)); 3146 for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
3149 i = i + 2) { 3147 i = i + 2) {
3150#ifdef __BIGENDIAN 3148#ifdef __BIGENDIAN
3151 dip[i] = bfa_os_ntohl(sip[i]); 3149 dip[i] = be32_to_cpu(sip[i]);
3152 dip[i + 1] = bfa_os_ntohl(sip[i + 1]); 3150 dip[i + 1] = be32_to_cpu(sip[i + 1]);
3153#else 3151#else
3154 dip[i] = bfa_os_ntohl(sip[i + 1]); 3152 dip[i] = be32_to_cpu(sip[i + 1]);
3155 dip[i + 1] = bfa_os_ntohl(sip[i]); 3153 dip[i + 1] = be32_to_cpu(sip[i]);
3156#endif 3154#endif
3157 } 3155 }
3158} 3156}
@@ -3223,7 +3221,7 @@ bfa_fcport_send_stats_get(void *cbarg)
3223 } 3221 }
3224 fcport->stats_qfull = BFA_FALSE; 3222 fcport->stats_qfull = BFA_FALSE;
3225 3223
3226 bfa_os_memset(msg, 0, sizeof(struct bfi_fcport_req_s)); 3224 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
3227 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ, 3225 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
3228 bfa_lpuid(fcport->bfa)); 3226 bfa_lpuid(fcport->bfa));
3229 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); 3227 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
@@ -3237,7 +3235,7 @@ __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
3237 if (complete) { 3235 if (complete) {
3238 struct bfa_timeval_s tv; 3236 struct bfa_timeval_s tv;
3239 3237
3240 /** 3238 /*
3241 * re-initialize time stamp for stats reset 3239 * re-initialize time stamp for stats reset
3242 */ 3240 */
3243 bfa_os_gettimeofday(&tv); 3241 bfa_os_gettimeofday(&tv);
@@ -3285,13 +3283,13 @@ bfa_fcport_send_stats_clear(void *cbarg)
3285 } 3283 }
3286 fcport->stats_qfull = BFA_FALSE; 3284 fcport->stats_qfull = BFA_FALSE;
3287 3285
3288 bfa_os_memset(msg, 0, sizeof(struct bfi_fcport_req_s)); 3286 memset(msg, 0, sizeof(struct bfi_fcport_req_s));
3289 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ, 3287 bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
3290 bfa_lpuid(fcport->bfa)); 3288 bfa_lpuid(fcport->bfa));
3291 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); 3289 bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
3292} 3290}
3293 3291
3294/** 3292/*
3295 * Handle trunk SCN event from firmware. 3293 * Handle trunk SCN event from firmware.
3296 */ 3294 */
3297static void 3295static void
@@ -3312,7 +3310,7 @@ bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3312 bfa_trc(fcport->bfa, scn->trunk_state); 3310 bfa_trc(fcport->bfa, scn->trunk_state);
3313 bfa_trc(fcport->bfa, scn->trunk_speed); 3311 bfa_trc(fcport->bfa, scn->trunk_speed);
3314 3312
3315 /** 3313 /*
3316 * Save off new state for trunk attribute query 3314 * Save off new state for trunk attribute query
3317 */ 3315 */
3318 state_prev = trunk->attr.state; 3316 state_prev = trunk->attr.state;
@@ -3327,7 +3325,7 @@ bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3327 lattr->trunk_wwn = tlink->trunk_wwn; 3325 lattr->trunk_wwn = tlink->trunk_wwn;
3328 lattr->fctl = tlink->fctl; 3326 lattr->fctl = tlink->fctl;
3329 lattr->speed = tlink->speed; 3327 lattr->speed = tlink->speed;
3330 lattr->deskew = bfa_os_ntohl(tlink->deskew); 3328 lattr->deskew = be32_to_cpu(tlink->deskew);
3331 3329
3332 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) { 3330 if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
3333 fcport->speed = tlink->speed; 3331 fcport->speed = tlink->speed;
@@ -3360,7 +3358,7 @@ bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
3360 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down"); 3358 BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
3361 } 3359 }
3362 3360
3363 /** 3361 /*
3364 * Notify upper layers if trunk state changed. 3362 * Notify upper layers if trunk state changed.
3365 */ 3363 */
3366 if ((state_prev != trunk->attr.state) || 3364 if ((state_prev != trunk->attr.state) ||
@@ -3376,7 +3374,7 @@ bfa_trunk_iocdisable(struct bfa_s *bfa)
3376 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); 3374 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3377 int i = 0; 3375 int i = 0;
3378 3376
3379 /** 3377 /*
3380 * In trunked mode, notify upper layers that link is down 3378 * In trunked mode, notify upper layers that link is down
3381 */ 3379 */
3382 if (fcport->cfg.trunked) { 3380 if (fcport->cfg.trunked) {
@@ -3400,11 +3398,11 @@ bfa_trunk_iocdisable(struct bfa_s *bfa)
3400 3398
3401 3399
3402 3400
3403/** 3401/*
3404 * hal_port_public 3402 * hal_port_public
3405 */ 3403 */
3406 3404
3407/** 3405/*
3408 * Called to initialize port attributes 3406 * Called to initialize port attributes
3409 */ 3407 */
3410void 3408void
@@ -3412,7 +3410,7 @@ bfa_fcport_init(struct bfa_s *bfa)
3412{ 3410{
3413 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); 3411 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3414 3412
3415 /** 3413 /*
3416 * Initialize port attributes from IOC hardware data. 3414 * Initialize port attributes from IOC hardware data.
3417 */ 3415 */
3418 bfa_fcport_set_wwns(fcport); 3416 bfa_fcport_set_wwns(fcport);
@@ -3426,7 +3424,7 @@ bfa_fcport_init(struct bfa_s *bfa)
3426 bfa_assert(fcport->speed_sup); 3424 bfa_assert(fcport->speed_sup);
3427} 3425}
3428 3426
3429/** 3427/*
3430 * Firmware message handler. 3428 * Firmware message handler.
3431 */ 3429 */
3432void 3430void
@@ -3507,11 +3505,11 @@ bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
3507 3505
3508 3506
3509 3507
3510/** 3508/*
3511 * hal_port_api 3509 * hal_port_api
3512 */ 3510 */
3513 3511
3514/** 3512/*
3515 * Registered callback for port events. 3513 * Registered callback for port events.
3516 */ 3514 */
3517void 3515void
@@ -3552,7 +3550,7 @@ bfa_fcport_disable(struct bfa_s *bfa)
3552 return BFA_STATUS_OK; 3550 return BFA_STATUS_OK;
3553} 3551}
3554 3552
3555/** 3553/*
3556 * Configure port speed. 3554 * Configure port speed.
3557 */ 3555 */
3558bfa_status_t 3556bfa_status_t
@@ -3574,7 +3572,7 @@ bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3574 return BFA_STATUS_OK; 3572 return BFA_STATUS_OK;
3575} 3573}
3576 3574
3577/** 3575/*
3578 * Get current speed. 3576 * Get current speed.
3579 */ 3577 */
3580enum bfa_port_speed 3578enum bfa_port_speed
@@ -3585,7 +3583,7 @@ bfa_fcport_get_speed(struct bfa_s *bfa)
3585 return fcport->speed; 3583 return fcport->speed;
3586} 3584}
3587 3585
3588/** 3586/*
3589 * Configure port topology. 3587 * Configure port topology.
3590 */ 3588 */
3591bfa_status_t 3589bfa_status_t
@@ -3610,7 +3608,7 @@ bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
3610 return BFA_STATUS_OK; 3608 return BFA_STATUS_OK;
3611} 3609}
3612 3610
3613/** 3611/*
3614 * Get current topology. 3612 * Get current topology.
3615 */ 3613 */
3616enum bfa_port_topology 3614enum bfa_port_topology
@@ -3710,7 +3708,7 @@ bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
3710 bfa_fcport_send_txcredit(fcport); 3708 bfa_fcport_send_txcredit(fcport);
3711} 3709}
3712 3710
3713/** 3711/*
3714 * Get port attributes. 3712 * Get port attributes.
3715 */ 3713 */
3716 3714
@@ -3729,7 +3727,7 @@ bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3729{ 3727{
3730 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); 3728 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3731 3729
3732 bfa_os_memset(attr, 0, sizeof(struct bfa_port_attr_s)); 3730 memset(attr, 0, sizeof(struct bfa_port_attr_s));
3733 3731
3734 attr->nwwn = fcport->nwwn; 3732 attr->nwwn = fcport->nwwn;
3735 attr->pwwn = fcport->pwwn; 3733 attr->pwwn = fcport->pwwn;
@@ -3737,7 +3735,7 @@ bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3737 attr->factorypwwn = bfa_ioc_get_mfg_pwwn(&bfa->ioc); 3735 attr->factorypwwn = bfa_ioc_get_mfg_pwwn(&bfa->ioc);
3738 attr->factorynwwn = bfa_ioc_get_mfg_nwwn(&bfa->ioc); 3736 attr->factorynwwn = bfa_ioc_get_mfg_nwwn(&bfa->ioc);
3739 3737
3740 bfa_os_memcpy(&attr->pport_cfg, &fcport->cfg, 3738 memcpy(&attr->pport_cfg, &fcport->cfg,
3741 sizeof(struct bfa_port_cfg_s)); 3739 sizeof(struct bfa_port_cfg_s));
3742 /* speed attributes */ 3740 /* speed attributes */
3743 attr->pport_cfg.speed = fcport->cfg.speed; 3741 attr->pport_cfg.speed = fcport->cfg.speed;
@@ -3770,7 +3768,7 @@ bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
3770 3768
3771#define BFA_FCPORT_STATS_TOV 1000 3769#define BFA_FCPORT_STATS_TOV 1000
3772 3770
3773/** 3771/*
3774 * Fetch port statistics (FCQoS or FCoE). 3772 * Fetch port statistics (FCQoS or FCoE).
3775 */ 3773 */
3776bfa_status_t 3774bfa_status_t
@@ -3796,7 +3794,7 @@ bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
3796 return BFA_STATUS_OK; 3794 return BFA_STATUS_OK;
3797} 3795}
3798 3796
3799/** 3797/*
3800 * Reset port statistics (FCQoS or FCoE). 3798 * Reset port statistics (FCQoS or FCoE).
3801 */ 3799 */
3802bfa_status_t 3800bfa_status_t
@@ -3820,7 +3818,7 @@ bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg)
3820 return BFA_STATUS_OK; 3818 return BFA_STATUS_OK;
3821} 3819}
3822 3820
3823/** 3821/*
3824 * Fetch FCQoS port statistics 3822 * Fetch FCQoS port statistics
3825 */ 3823 */
3826bfa_status_t 3824bfa_status_t
@@ -3833,7 +3831,7 @@ bfa_fcport_get_qos_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
3833 return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg); 3831 return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg);
3834} 3832}
3835 3833
3836/** 3834/*
3837 * Reset FCoE port statistics 3835 * Reset FCoE port statistics
3838 */ 3836 */
3839bfa_status_t 3837bfa_status_t
@@ -3845,7 +3843,7 @@ bfa_fcport_clear_qos_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg)
3845 return bfa_fcport_clear_stats(bfa, cbfn, cbarg); 3843 return bfa_fcport_clear_stats(bfa, cbfn, cbarg);
3846} 3844}
3847 3845
3848/** 3846/*
3849 * Fetch FCQoS port statistics 3847 * Fetch FCQoS port statistics
3850 */ 3848 */
3851bfa_status_t 3849bfa_status_t
@@ -3858,7 +3856,7 @@ bfa_fcport_get_fcoe_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
3858 return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg); 3856 return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg);
3859} 3857}
3860 3858
3861/** 3859/*
3862 * Reset FCoE port statistics 3860 * Reset FCoE port statistics
3863 */ 3861 */
3864bfa_status_t 3862bfa_status_t
@@ -3876,7 +3874,7 @@ bfa_fcport_qos_get_attr(struct bfa_s *bfa, struct bfa_qos_attr_s *qos_attr)
3876 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); 3874 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
3877 3875
3878 qos_attr->state = fcport->qos_attr.state; 3876 qos_attr->state = fcport->qos_attr.state;
3879 qos_attr->total_bb_cr = bfa_os_ntohl(fcport->qos_attr.total_bb_cr); 3877 qos_attr->total_bb_cr = be32_to_cpu(fcport->qos_attr.total_bb_cr);
3880} 3878}
3881 3879
3882void 3880void
@@ -3887,10 +3885,10 @@ bfa_fcport_qos_get_vc_attr(struct bfa_s *bfa,
3887 struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr; 3885 struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr;
3888 u32 i = 0; 3886 u32 i = 0;
3889 3887
3890 qos_vc_attr->total_vc_count = bfa_os_ntohs(bfa_vc_attr->total_vc_count); 3888 qos_vc_attr->total_vc_count = be16_to_cpu(bfa_vc_attr->total_vc_count);
3891 qos_vc_attr->shared_credit = bfa_os_ntohs(bfa_vc_attr->shared_credit); 3889 qos_vc_attr->shared_credit = be16_to_cpu(bfa_vc_attr->shared_credit);
3892 qos_vc_attr->elp_opmode_flags = 3890 qos_vc_attr->elp_opmode_flags =
3893 bfa_os_ntohl(bfa_vc_attr->elp_opmode_flags); 3891 be32_to_cpu(bfa_vc_attr->elp_opmode_flags);
3894 3892
3895 /* Individual VC info */ 3893 /* Individual VC info */
3896 while (i < qos_vc_attr->total_vc_count) { 3894 while (i < qos_vc_attr->total_vc_count) {
@@ -3904,7 +3902,7 @@ bfa_fcport_qos_get_vc_attr(struct bfa_s *bfa,
3904 } 3902 }
3905} 3903}
3906 3904
3907/** 3905/*
3908 * Fetch port attributes. 3906 * Fetch port attributes.
3909 */ 3907 */
3910bfa_boolean_t 3908bfa_boolean_t
@@ -3939,7 +3937,7 @@ bfa_fcport_cfg_qos(struct bfa_s *bfa, bfa_boolean_t on_off)
3939 3937
3940 if (ioc_type == BFA_IOC_TYPE_FC) { 3938 if (ioc_type == BFA_IOC_TYPE_FC) {
3941 fcport->cfg.qos_enabled = on_off; 3939 fcport->cfg.qos_enabled = on_off;
3942 /** 3940 /*
3943 * Notify fcpim of the change in QoS state 3941 * Notify fcpim of the change in QoS state
3944 */ 3942 */
3945 bfa_fcpim_update_ioredirect(bfa); 3943 bfa_fcpim_update_ioredirect(bfa);
@@ -3959,7 +3957,7 @@ bfa_fcport_cfg_ratelim(struct bfa_s *bfa, bfa_boolean_t on_off)
3959 fcport->cfg.trl_def_speed = BFA_PORT_SPEED_1GBPS; 3957 fcport->cfg.trl_def_speed = BFA_PORT_SPEED_1GBPS;
3960} 3958}
3961 3959
3962/** 3960/*
3963 * Configure default minimum ratelim speed 3961 * Configure default minimum ratelim speed
3964 */ 3962 */
3965bfa_status_t 3963bfa_status_t
@@ -3980,7 +3978,7 @@ bfa_fcport_cfg_ratelim_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
3980 return BFA_STATUS_OK; 3978 return BFA_STATUS_OK;
3981} 3979}
3982 3980
3983/** 3981/*
3984 * Get default minimum ratelim speed 3982 * Get default minimum ratelim speed
3985 */ 3983 */
3986enum bfa_port_speed 3984enum bfa_port_speed
@@ -4095,10 +4093,10 @@ bfa_trunk_disable(struct bfa_s *bfa)
4095} 4093}
4096 4094
4097 4095
4098/** 4096/*
4099 * Rport State machine functions 4097 * Rport State machine functions
4100 */ 4098 */
4101/** 4099/*
4102 * Beginning state, only online event expected. 4100 * Beginning state, only online event expected.
4103 */ 4101 */
4104static void 4102static void
@@ -4151,7 +4149,7 @@ bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
4151 } 4149 }
4152} 4150}
4153 4151
4154/** 4152/*
4155 * Waiting for rport create response from firmware. 4153 * Waiting for rport create response from firmware.
4156 */ 4154 */
4157static void 4155static void
@@ -4188,7 +4186,7 @@ bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
4188 } 4186 }
4189} 4187}
4190 4188
4191/** 4189/*
4192 * Request queue is full, awaiting queue resume to send create request. 4190 * Request queue is full, awaiting queue resume to send create request.
4193 */ 4191 */
4194static void 4192static void
@@ -4229,7 +4227,7 @@ bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4229 } 4227 }
4230} 4228}
4231 4229
4232/** 4230/*
4233 * Online state - normal parking state. 4231 * Online state - normal parking state.
4234 */ 4232 */
4235static void 4233static void
@@ -4275,9 +4273,9 @@ bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4275 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority); 4273 bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
4276 4274
4277 qos_scn->old_qos_attr.qos_flow_id = 4275 qos_scn->old_qos_attr.qos_flow_id =
4278 bfa_os_ntohl(qos_scn->old_qos_attr.qos_flow_id); 4276 be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
4279 qos_scn->new_qos_attr.qos_flow_id = 4277 qos_scn->new_qos_attr.qos_flow_id =
4280 bfa_os_ntohl(qos_scn->new_qos_attr.qos_flow_id); 4278 be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
4281 4279
4282 if (qos_scn->old_qos_attr.qos_flow_id != 4280 if (qos_scn->old_qos_attr.qos_flow_id !=
4283 qos_scn->new_qos_attr.qos_flow_id) 4281 qos_scn->new_qos_attr.qos_flow_id)
@@ -4297,7 +4295,7 @@ bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
4297 } 4295 }
4298} 4296}
4299 4297
4300/** 4298/*
4301 * Firmware rport is being deleted - awaiting f/w response. 4299 * Firmware rport is being deleted - awaiting f/w response.
4302 */ 4300 */
4303static void 4301static void
@@ -4360,7 +4358,7 @@ bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4360 } 4358 }
4361} 4359}
4362 4360
4363/** 4361/*
4364 * Offline state. 4362 * Offline state.
4365 */ 4363 */
4366static void 4364static void
@@ -4395,7 +4393,7 @@ bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
4395 } 4393 }
4396} 4394}
4397 4395
4398/** 4396/*
4399 * Rport is deleted, waiting for firmware response to delete. 4397 * Rport is deleted, waiting for firmware response to delete.
4400 */ 4398 */
4401static void 4399static void
@@ -4447,7 +4445,7 @@ bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
4447 } 4445 }
4448} 4446}
4449 4447
4450/** 4448/*
4451 * Waiting for rport create response from firmware. A delete is pending. 4449 * Waiting for rport create response from firmware. A delete is pending.
4452 */ 4450 */
4453static void 4451static void
@@ -4478,7 +4476,7 @@ bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
4478 } 4476 }
4479} 4477}
4480 4478
4481/** 4479/*
4482 * Waiting for rport create response from firmware. Rport offline is pending. 4480 * Waiting for rport create response from firmware. Rport offline is pending.
4483 */ 4481 */
4484static void 4482static void
@@ -4513,7 +4511,7 @@ bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
4513 } 4511 }
4514} 4512}
4515 4513
4516/** 4514/*
4517 * IOC h/w failed. 4515 * IOC h/w failed.
4518 */ 4516 */
4519static void 4517static void
@@ -4553,7 +4551,7 @@ bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
4553 4551
4554 4552
4555 4553
4556/** 4554/*
4557 * bfa_rport_private BFA rport private functions 4555 * bfa_rport_private BFA rport private functions
4558 */ 4556 */
4559 4557
@@ -4612,12 +4610,12 @@ bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4612 !(mod->num_rports & (mod->num_rports - 1))); 4610 !(mod->num_rports & (mod->num_rports - 1)));
4613 4611
4614 for (i = 0; i < mod->num_rports; i++, rp++) { 4612 for (i = 0; i < mod->num_rports; i++, rp++) {
4615 bfa_os_memset(rp, 0, sizeof(struct bfa_rport_s)); 4613 memset(rp, 0, sizeof(struct bfa_rport_s));
4616 rp->bfa = bfa; 4614 rp->bfa = bfa;
4617 rp->rport_tag = i; 4615 rp->rport_tag = i;
4618 bfa_sm_set_state(rp, bfa_rport_sm_uninit); 4616 bfa_sm_set_state(rp, bfa_rport_sm_uninit);
4619 4617
4620 /** 4618 /*
4621 * - is unused 4619 * - is unused
4622 */ 4620 */
4623 if (i) 4621 if (i)
@@ -4626,7 +4624,7 @@ bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4626 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp); 4624 bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
4627 } 4625 }
4628 4626
4629 /** 4627 /*
4630 * consume memory 4628 * consume memory
4631 */ 4629 */
4632 bfa_meminfo_kva(meminfo) = (u8 *) rp; 4630 bfa_meminfo_kva(meminfo) = (u8 *) rp;
@@ -4687,7 +4685,7 @@ bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4687{ 4685{
4688 struct bfi_rport_create_req_s *m; 4686 struct bfi_rport_create_req_s *m;
4689 4687
4690 /** 4688 /*
4691 * check for room in queue to send request now 4689 * check for room in queue to send request now
4692 */ 4690 */
4693 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); 4691 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
@@ -4699,7 +4697,7 @@ bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4699 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ, 4697 bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
4700 bfa_lpuid(rp->bfa)); 4698 bfa_lpuid(rp->bfa));
4701 m->bfa_handle = rp->rport_tag; 4699 m->bfa_handle = rp->rport_tag;
4702 m->max_frmsz = bfa_os_htons(rp->rport_info.max_frmsz); 4700 m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
4703 m->pid = rp->rport_info.pid; 4701 m->pid = rp->rport_info.pid;
4704 m->lp_tag = rp->rport_info.lp_tag; 4702 m->lp_tag = rp->rport_info.lp_tag;
4705 m->local_pid = rp->rport_info.local_pid; 4703 m->local_pid = rp->rport_info.local_pid;
@@ -4708,7 +4706,7 @@ bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
4708 m->vf_id = rp->rport_info.vf_id; 4706 m->vf_id = rp->rport_info.vf_id;
4709 m->cisc = rp->rport_info.cisc; 4707 m->cisc = rp->rport_info.cisc;
4710 4708
4711 /** 4709 /*
4712 * queue I/O message to firmware 4710 * queue I/O message to firmware
4713 */ 4711 */
4714 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT); 4712 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
@@ -4720,7 +4718,7 @@ bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4720{ 4718{
4721 struct bfi_rport_delete_req_s *m; 4719 struct bfi_rport_delete_req_s *m;
4722 4720
4723 /** 4721 /*
4724 * check for room in queue to send request now 4722 * check for room in queue to send request now
4725 */ 4723 */
4726 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); 4724 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
@@ -4733,7 +4731,7 @@ bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
4733 bfa_lpuid(rp->bfa)); 4731 bfa_lpuid(rp->bfa));
4734 m->fw_handle = rp->fw_handle; 4732 m->fw_handle = rp->fw_handle;
4735 4733
4736 /** 4734 /*
4737 * queue I/O message to firmware 4735 * queue I/O message to firmware
4738 */ 4736 */
4739 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT); 4737 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
@@ -4745,7 +4743,7 @@ bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4745{ 4743{
4746 struct bfa_rport_speed_req_s *m; 4744 struct bfa_rport_speed_req_s *m;
4747 4745
4748 /** 4746 /*
4749 * check for room in queue to send request now 4747 * check for room in queue to send request now
4750 */ 4748 */
4751 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); 4749 m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
@@ -4759,7 +4757,7 @@ bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4759 m->fw_handle = rp->fw_handle; 4757 m->fw_handle = rp->fw_handle;
4760 m->speed = (u8)rp->rport_info.speed; 4758 m->speed = (u8)rp->rport_info.speed;
4761 4759
4762 /** 4760 /*
4763 * queue I/O message to firmware 4761 * queue I/O message to firmware
4764 */ 4762 */
4765 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT); 4763 bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
@@ -4768,11 +4766,11 @@ bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
4768 4766
4769 4767
4770 4768
4771/** 4769/*
4772 * bfa_rport_public 4770 * bfa_rport_public
4773 */ 4771 */
4774 4772
4775/** 4773/*
4776 * Rport interrupt processing. 4774 * Rport interrupt processing.
4777 */ 4775 */
4778void 4776void
@@ -4814,7 +4812,7 @@ bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
4814 4812
4815 4813
4816 4814
4817/** 4815/*
4818 * bfa_rport_api 4816 * bfa_rport_api
4819 */ 4817 */
4820 4818
@@ -4849,7 +4847,7 @@ bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4849{ 4847{
4850 bfa_assert(rport_info->max_frmsz != 0); 4848 bfa_assert(rport_info->max_frmsz != 0);
4851 4849
4852 /** 4850 /*
4853 * Some JBODs are seen to be not setting PDU size correctly in PLOGI 4851 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
4854 * responses. Default to minimum size. 4852 * responses. Default to minimum size.
4855 */ 4853 */
@@ -4858,7 +4856,7 @@ bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
4858 rport_info->max_frmsz = FC_MIN_PDUSZ; 4856 rport_info->max_frmsz = FC_MIN_PDUSZ;
4859 } 4857 }
4860 4858
4861 bfa_os_assign(rport->rport_info, *rport_info); 4859 rport->rport_info = *rport_info;
4862 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE); 4860 bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
4863} 4861}
4864 4862
@@ -4890,22 +4888,22 @@ bfa_rport_get_qos_attr(struct bfa_rport_s *rport,
4890 struct bfa_rport_qos_attr_s *qos_attr) 4888 struct bfa_rport_qos_attr_s *qos_attr)
4891{ 4889{
4892 qos_attr->qos_priority = rport->qos_attr.qos_priority; 4890 qos_attr->qos_priority = rport->qos_attr.qos_priority;
4893 qos_attr->qos_flow_id = bfa_os_ntohl(rport->qos_attr.qos_flow_id); 4891 qos_attr->qos_flow_id = be32_to_cpu(rport->qos_attr.qos_flow_id);
4894 4892
4895} 4893}
4896 4894
4897void 4895void
4898bfa_rport_clear_stats(struct bfa_rport_s *rport) 4896bfa_rport_clear_stats(struct bfa_rport_s *rport)
4899{ 4897{
4900 bfa_os_memset(&rport->stats, 0, sizeof(rport->stats)); 4898 memset(&rport->stats, 0, sizeof(rport->stats));
4901} 4899}
4902 4900
4903 4901
4904/** 4902/*
4905 * SGPG related functions 4903 * SGPG related functions
4906 */ 4904 */
4907 4905
4908/** 4906/*
4909 * Compute and return memory needed by FCP(im) module. 4907 * Compute and return memory needed by FCP(im) module.
4910 */ 4908 */
4911static void 4909static void
@@ -4957,8 +4955,8 @@ bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
4957 bfa_assert(!(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1))); 4955 bfa_assert(!(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1)));
4958 4956
4959 for (i = 0; i < mod->num_sgpgs; i++) { 4957 for (i = 0; i < mod->num_sgpgs; i++) {
4960 bfa_os_memset(hsgpg, 0, sizeof(*hsgpg)); 4958 memset(hsgpg, 0, sizeof(*hsgpg));
4961 bfa_os_memset(sgpg, 0, sizeof(*sgpg)); 4959 memset(sgpg, 0, sizeof(*sgpg));
4962 4960
4963 hsgpg->sgpg = sgpg; 4961 hsgpg->sgpg = sgpg;
4964 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa); 4962 sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
@@ -4997,7 +4995,7 @@ bfa_sgpg_iocdisable(struct bfa_s *bfa)
4997 4995
4998 4996
4999 4997
5000/** 4998/*
5001 * hal_sgpg_public BFA SGPG public functions 4999 * hal_sgpg_public BFA SGPG public functions
5002 */ 5000 */
5003 5001
@@ -5039,7 +5037,7 @@ bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
5039 if (list_empty(&mod->sgpg_wait_q)) 5037 if (list_empty(&mod->sgpg_wait_q))
5040 return; 5038 return;
5041 5039
5042 /** 5040 /*
5043 * satisfy as many waiting requests as possible 5041 * satisfy as many waiting requests as possible
5044 */ 5042 */
5045 do { 5043 do {
@@ -5067,11 +5065,11 @@ bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
5067 5065
5068 wqe->nsgpg_total = wqe->nsgpg = nsgpg; 5066 wqe->nsgpg_total = wqe->nsgpg = nsgpg;
5069 5067
5070 /** 5068 /*
5071 * allocate any left to this one first 5069 * allocate any left to this one first
5072 */ 5070 */
5073 if (mod->free_sgpgs) { 5071 if (mod->free_sgpgs) {
5074 /** 5072 /*
5075 * no one else is waiting for SGPG 5073 * no one else is waiting for SGPG
5076 */ 5074 */
5077 bfa_assert(list_empty(&mod->sgpg_wait_q)); 5075 bfa_assert(list_empty(&mod->sgpg_wait_q));
@@ -5105,7 +5103,7 @@ bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
5105 wqe->cbarg = cbarg; 5103 wqe->cbarg = cbarg;
5106} 5104}
5107 5105
5108/** 5106/*
5109 * UF related functions 5107 * UF related functions
5110 */ 5108 */
5111/* 5109/*
@@ -5136,7 +5134,7 @@ claim_uf_pbs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
5136 bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz; 5134 bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz;
5137 bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz; 5135 bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz;
5138 5136
5139 bfa_os_memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz); 5137 memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz);
5140} 5138}
5141 5139
5142static void 5140static void
@@ -5153,11 +5151,11 @@ claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
5153 5151
5154 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs; 5152 for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
5155 i++, uf_bp_msg++) { 5153 i++, uf_bp_msg++) {
5156 bfa_os_memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s)); 5154 memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
5157 5155
5158 uf_bp_msg->buf_tag = i; 5156 uf_bp_msg->buf_tag = i;
5159 buf_len = sizeof(struct bfa_uf_buf_s); 5157 buf_len = sizeof(struct bfa_uf_buf_s);
5160 uf_bp_msg->buf_len = bfa_os_htons(buf_len); 5158 uf_bp_msg->buf_len = cpu_to_be16(buf_len);
5161 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST, 5159 bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
5162 bfa_lpuid(ufm->bfa)); 5160 bfa_lpuid(ufm->bfa));
5163 5161
@@ -5173,7 +5171,7 @@ claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
5173 bfa_sge_to_be(&sge[1]); 5171 bfa_sge_to_be(&sge[1]);
5174 } 5172 }
5175 5173
5176 /** 5174 /*
5177 * advance pointer beyond consumed memory 5175 * advance pointer beyond consumed memory
5178 */ 5176 */
5179 bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg; 5177 bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg;
@@ -5194,7 +5192,7 @@ claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
5194 * Initialize UFs and queue it in UF free queue 5192 * Initialize UFs and queue it in UF free queue
5195 */ 5193 */
5196 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) { 5194 for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
5197 bfa_os_memset(uf, 0, sizeof(struct bfa_uf_s)); 5195 memset(uf, 0, sizeof(struct bfa_uf_s));
5198 uf->bfa = ufm->bfa; 5196 uf->bfa = ufm->bfa;
5199 uf->uf_tag = i; 5197 uf->uf_tag = i;
5200 uf->pb_len = sizeof(struct bfa_uf_buf_s); 5198 uf->pb_len = sizeof(struct bfa_uf_buf_s);
@@ -5203,7 +5201,7 @@ claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
5203 list_add_tail(&uf->qe, &ufm->uf_free_q); 5201 list_add_tail(&uf->qe, &ufm->uf_free_q);
5204 } 5202 }
5205 5203
5206 /** 5204 /*
5207 * advance memory pointer 5205 * advance memory pointer
5208 */ 5206 */
5209 bfa_meminfo_kva(mi) = (u8 *) uf; 5207 bfa_meminfo_kva(mi) = (u8 *) uf;
@@ -5241,7 +5239,7 @@ bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5241{ 5239{
5242 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); 5240 struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
5243 5241
5244 bfa_os_memset(ufm, 0, sizeof(struct bfa_uf_mod_s)); 5242 memset(ufm, 0, sizeof(struct bfa_uf_mod_s));
5245 ufm->bfa = bfa; 5243 ufm->bfa = bfa;
5246 ufm->num_ufs = cfg->fwcfg.num_uf_bufs; 5244 ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
5247 INIT_LIST_HEAD(&ufm->uf_free_q); 5245 INIT_LIST_HEAD(&ufm->uf_free_q);
@@ -5279,7 +5277,7 @@ bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
5279 if (!uf_post_msg) 5277 if (!uf_post_msg)
5280 return BFA_STATUS_FAILED; 5278 return BFA_STATUS_FAILED;
5281 5279
5282 bfa_os_memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag], 5280 memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
5283 sizeof(struct bfi_uf_buf_post_s)); 5281 sizeof(struct bfi_uf_buf_post_s));
5284 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP); 5282 bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP);
5285 5283
@@ -5310,8 +5308,8 @@ uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
5310 u8 *buf = &uf_buf->d[0]; 5308 u8 *buf = &uf_buf->d[0];
5311 struct fchs_s *fchs; 5309 struct fchs_s *fchs;
5312 5310
5313 m->frm_len = bfa_os_ntohs(m->frm_len); 5311 m->frm_len = be16_to_cpu(m->frm_len);
5314 m->xfr_len = bfa_os_ntohs(m->xfr_len); 5312 m->xfr_len = be16_to_cpu(m->xfr_len);
5315 5313
5316 fchs = (struct fchs_s *)uf_buf; 5314 fchs = (struct fchs_s *)uf_buf;
5317 5315
@@ -5365,11 +5363,11 @@ bfa_uf_start(struct bfa_s *bfa)
5365 5363
5366 5364
5367 5365
5368/** 5366/*
5369 * hal_uf_api 5367 * hal_uf_api
5370 */ 5368 */
5371 5369
5372/** 5370/*
5373 * Register handler for all unsolicted recieve frames. 5371 * Register handler for all unsolicted recieve frames.
5374 * 5372 *
5375 * @param[in] bfa BFA instance 5373 * @param[in] bfa BFA instance
@@ -5385,7 +5383,7 @@ bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
5385 ufm->cbarg = cbarg; 5383 ufm->cbarg = cbarg;
5386} 5384}
5387 5385
5388/** 5386/*
5389 * Free an unsolicited frame back to BFA. 5387 * Free an unsolicited frame back to BFA.
5390 * 5388 *
5391 * @param[in] uf unsolicited frame to be freed 5389 * @param[in] uf unsolicited frame to be freed
@@ -5401,7 +5399,7 @@ bfa_uf_free(struct bfa_uf_s *uf)
5401 5399
5402 5400
5403 5401
5404/** 5402/*
5405 * uf_pub BFA uf module public functions 5403 * uf_pub BFA uf module public functions
5406 */ 5404 */
5407void 5405void
diff --git a/drivers/scsi/bfa/bfa_svc.h b/drivers/scsi/bfa/bfa_svc.h
index 9921dad0d039..e2349d5cdb93 100644
--- a/drivers/scsi/bfa/bfa_svc.h
+++ b/drivers/scsi/bfa/bfa_svc.h
@@ -22,12 +22,12 @@
22#include "bfi_ms.h" 22#include "bfi_ms.h"
23 23
24 24
25/** 25/*
26 * Scatter-gather DMA related defines 26 * Scatter-gather DMA related defines
27 */ 27 */
28#define BFA_SGPG_MIN (16) 28#define BFA_SGPG_MIN (16)
29 29
30/** 30/*
31 * Alignment macro for SG page allocation 31 * Alignment macro for SG page allocation
32 */ 32 */
33#define BFA_SGPG_ROUNDUP(_l) (((_l) + (sizeof(struct bfi_sgpg_s) - 1)) \ 33#define BFA_SGPG_ROUNDUP(_l) (((_l) + (sizeof(struct bfi_sgpg_s) - 1)) \
@@ -48,7 +48,7 @@ struct bfa_sgpg_s {
48 union bfi_addr_u sgpg_pa; /* pa of SG page */ 48 union bfi_addr_u sgpg_pa; /* pa of SG page */
49}; 49};
50 50
51/** 51/*
52 * Given number of SG elements, BFA_SGPG_NPAGE() returns the number of 52 * Given number of SG elements, BFA_SGPG_NPAGE() returns the number of
53 * SG pages required. 53 * SG pages required.
54 */ 54 */
@@ -75,7 +75,7 @@ void bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpgs);
75void bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe); 75void bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe);
76 76
77 77
78/** 78/*
79 * FCXP related defines 79 * FCXP related defines
80 */ 80 */
81#define BFA_FCXP_MIN (1) 81#define BFA_FCXP_MIN (1)
@@ -115,12 +115,12 @@ typedef void (*bfa_fcxp_alloc_cbfn_t) (void *cbarg, struct bfa_fcxp_s *fcxp);
115 115
116 116
117 117
118/** 118/*
119 * Information needed for a FCXP request 119 * Information needed for a FCXP request
120 */ 120 */
121struct bfa_fcxp_req_info_s { 121struct bfa_fcxp_req_info_s {
122 struct bfa_rport_s *bfa_rport; 122 struct bfa_rport_s *bfa_rport;
123 /** Pointer to the bfa rport that was 123 /* Pointer to the bfa rport that was
124 * returned from bfa_rport_create(). 124 * returned from bfa_rport_create().
125 * This could be left NULL for WKA or 125 * This could be left NULL for WKA or
126 * for FCXP interactions before the 126 * for FCXP interactions before the
@@ -137,11 +137,10 @@ struct bfa_fcxp_req_info_s {
137 137
138struct bfa_fcxp_rsp_info_s { 138struct bfa_fcxp_rsp_info_s {
139 struct fchs_s rsp_fchs; 139 struct fchs_s rsp_fchs;
140 /** !< Response frame's FC header will 140 /* Response frame's FC header will
141 * be sent back in this field */ 141 * be sent back in this field */
142 u8 rsp_timeout; 142 u8 rsp_timeout;
143 /** !< timeout in seconds, 0-no response 143 /* timeout in seconds, 0-no response */
144 */
145 u8 rsvd2[3]; 144 u8 rsvd2[3];
146 u32 rsp_maxlen; /* max response length expected */ 145 u32 rsp_maxlen; /* max response length expected */
147}; 146};
@@ -218,7 +217,7 @@ struct bfa_fcxp_wqe_s {
218void bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg); 217void bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
219 218
220 219
221/** 220/*
222 * RPORT related defines 221 * RPORT related defines
223 */ 222 */
224#define BFA_RPORT_MIN 4 223#define BFA_RPORT_MIN 4
@@ -232,7 +231,7 @@ struct bfa_rport_mod_s {
232 231
233#define BFA_RPORT_MOD(__bfa) (&(__bfa)->modules.rport_mod) 232#define BFA_RPORT_MOD(__bfa) (&(__bfa)->modules.rport_mod)
234 233
235/** 234/*
236 * Convert rport tag to RPORT 235 * Convert rport tag to RPORT
237 */ 236 */
238#define BFA_RPORT_FROM_TAG(__bfa, _tag) \ 237#define BFA_RPORT_FROM_TAG(__bfa, _tag) \
@@ -244,7 +243,7 @@ struct bfa_rport_mod_s {
244 */ 243 */
245void bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg); 244void bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
246 245
247/** 246/*
248 * BFA rport information. 247 * BFA rport information.
249 */ 248 */
250struct bfa_rport_info_s { 249struct bfa_rport_info_s {
@@ -259,7 +258,7 @@ struct bfa_rport_info_s {
259 enum bfa_port_speed speed; /* Rport's current speed */ 258 enum bfa_port_speed speed; /* Rport's current speed */
260}; 259};
261 260
262/** 261/*
263 * BFA rport data structure 262 * BFA rport data structure
264 */ 263 */
265struct bfa_rport_s { 264struct bfa_rport_s {
@@ -282,7 +281,7 @@ struct bfa_rport_s {
282#define BFA_RPORT_FC_COS(_rport) ((_rport)->rport_info.fc_class) 281#define BFA_RPORT_FC_COS(_rport) ((_rport)->rport_info.fc_class)
283 282
284 283
285/** 284/*
286 * UF - unsolicited receive related defines 285 * UF - unsolicited receive related defines
287 */ 286 */
288 287
@@ -305,7 +304,7 @@ struct bfa_uf_s {
305 struct bfa_sge_s sges[BFI_SGE_INLINE_MAX]; 304 struct bfa_sge_s sges[BFI_SGE_INLINE_MAX];
306}; 305};
307 306
308/** 307/*
309 * Callback prototype for unsolicited frame receive handler. 308 * Callback prototype for unsolicited frame receive handler.
310 * 309 *
311 * @param[in] cbarg callback arg for receive handler 310 * @param[in] cbarg callback arg for receive handler
@@ -338,7 +337,7 @@ void bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
338 337
339#define BFA_UF_BUFSZ (2 * 1024 + 256) 338#define BFA_UF_BUFSZ (2 * 1024 + 256)
340 339
341/** 340/*
342 * @todo private 341 * @todo private
343 */ 342 */
344struct bfa_uf_buf_s { 343struct bfa_uf_buf_s {
@@ -346,7 +345,7 @@ struct bfa_uf_buf_s {
346}; 345};
347 346
348 347
349/** 348/*
350 * LPS - bfa lport login/logout service interface 349 * LPS - bfa lport login/logout service interface
351 */ 350 */
352struct bfa_lps_s { 351struct bfa_lps_s {
@@ -397,14 +396,14 @@ struct bfa_lps_mod_s {
397void bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *msg); 396void bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
398 397
399 398
400/** 399/*
401 * FCPORT related defines 400 * FCPORT related defines
402 */ 401 */
403 402
404#define BFA_FCPORT(_bfa) (&((_bfa)->modules.port)) 403#define BFA_FCPORT(_bfa) (&((_bfa)->modules.port))
405typedef void (*bfa_cb_port_t) (void *cbarg, enum bfa_status status); 404typedef void (*bfa_cb_port_t) (void *cbarg, enum bfa_status status);
406 405
407/** 406/*
408 * Link notification data structure 407 * Link notification data structure
409 */ 408 */
410struct bfa_fcport_ln_s { 409struct bfa_fcport_ln_s {
@@ -418,7 +417,7 @@ struct bfa_fcport_trunk_s {
418 struct bfa_trunk_attr_s attr; 417 struct bfa_trunk_attr_s attr;
419}; 418};
420 419
421/** 420/*
422 * BFA FC port data structure 421 * BFA FC port data structure
423 */ 422 */
424struct bfa_fcport_s { 423struct bfa_fcport_s {
@@ -613,7 +612,7 @@ void bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv,
613 void *cbarg); 612 void *cbarg);
614void bfa_uf_free(struct bfa_uf_s *uf); 613void bfa_uf_free(struct bfa_uf_s *uf);
615 614
616/** 615/*
617 * bfa lport service api 616 * bfa lport service api
618 */ 617 */
619 618
diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index 4d8784e06e14..1f938974b848 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -15,7 +15,7 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * bfad.c Linux driver PCI interface module. 19 * bfad.c Linux driver PCI interface module.
20 */ 20 */
21#include <linux/module.h> 21#include <linux/module.h>
@@ -151,7 +151,7 @@ bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event event);
151static void 151static void
152bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event); 152bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event);
153 153
154/** 154/*
155 * Beginning state for the driver instance, awaiting the pci_probe event 155 * Beginning state for the driver instance, awaiting the pci_probe event
156 */ 156 */
157static void 157static void
@@ -181,7 +181,7 @@ bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event event)
181 } 181 }
182} 182}
183 183
184/** 184/*
185 * Driver Instance is created, awaiting event INIT to initialize the bfad 185 * Driver Instance is created, awaiting event INIT to initialize the bfad
186 */ 186 */
187static void 187static void
@@ -364,7 +364,7 @@ bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event event)
364 } 364 }
365} 365}
366 366
367/** 367/*
368 * BFA callbacks 368 * BFA callbacks
369 */ 369 */
370void 370void
@@ -376,7 +376,7 @@ bfad_hcb_comp(void *arg, bfa_status_t status)
376 complete(&fcomp->comp); 376 complete(&fcomp->comp);
377} 377}
378 378
379/** 379/*
380 * bfa_init callback 380 * bfa_init callback
381 */ 381 */
382void 382void
@@ -401,7 +401,7 @@ bfa_cb_init(void *drv, bfa_status_t init_status)
401 complete(&bfad->comp); 401 complete(&bfad->comp);
402} 402}
403 403
404/** 404/*
405 * BFA_FCS callbacks 405 * BFA_FCS callbacks
406 */ 406 */
407struct bfad_port_s * 407struct bfad_port_s *
@@ -457,7 +457,7 @@ bfa_fcb_lport_delete(struct bfad_s *bfad, enum bfa_lport_role roles,
457 } 457 }
458} 458}
459 459
460/** 460/*
461 * FCS RPORT alloc callback, after successful PLOGI by FCS 461 * FCS RPORT alloc callback, after successful PLOGI by FCS
462 */ 462 */
463bfa_status_t 463bfa_status_t
@@ -478,7 +478,7 @@ ext:
478 return rc; 478 return rc;
479} 479}
480 480
481/** 481/*
482 * FCS PBC VPORT Create 482 * FCS PBC VPORT Create
483 */ 483 */
484void 484void
@@ -663,7 +663,7 @@ ext:
663 return rc; 663 return rc;
664} 664}
665 665
666/** 666/*
667 * Create a vport under a vf. 667 * Create a vport under a vf.
668 */ 668 */
669bfa_status_t 669bfa_status_t
@@ -716,30 +716,6 @@ ext:
716 return rc; 716 return rc;
717} 717}
718 718
719/**
720 * Create a vf and its base vport implicitely.
721 */
722bfa_status_t
723bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
724 struct bfa_lport_cfg_s *port_cfg)
725{
726 struct bfad_vf_s *vf;
727 int rc = BFA_STATUS_OK;
728
729 vf = kzalloc(sizeof(struct bfad_vf_s), GFP_KERNEL);
730 if (!vf) {
731 rc = BFA_STATUS_FAILED;
732 goto ext;
733 }
734
735 rc = bfa_fcs_vf_create(&vf->fcs_vf, &bfad->bfa_fcs, vf_id, port_cfg,
736 vf);
737 if (rc != BFA_STATUS_OK)
738 kfree(vf);
739ext:
740 return rc;
741}
742
743void 719void
744bfad_bfa_tmo(unsigned long data) 720bfad_bfa_tmo(unsigned long data)
745{ 721{
@@ -885,20 +861,6 @@ bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
885 pci_set_drvdata(pdev, NULL); 861 pci_set_drvdata(pdev, NULL);
886} 862}
887 863
888void
889bfad_fcs_port_cfg(struct bfad_s *bfad)
890{
891 struct bfa_lport_cfg_s port_cfg;
892 struct bfa_port_attr_s attr;
893 char symname[BFA_SYMNAME_MAXLEN];
894
895 sprintf(symname, "%s-%d", BFAD_DRIVER_NAME, bfad->inst_no);
896 memcpy(port_cfg.sym_name.symname, symname, strlen(symname));
897 bfa_fcport_get_attr(&bfad->bfa, &attr);
898 port_cfg.nwwn = attr.nwwn;
899 port_cfg.pwwn = attr.pwwn;
900}
901
902bfa_status_t 864bfa_status_t
903bfad_drv_init(struct bfad_s *bfad) 865bfad_drv_init(struct bfad_s *bfad)
904{ 866{
@@ -1089,9 +1051,6 @@ bfad_start_ops(struct bfad_s *bfad) {
1089 bfa_fcs_init(&bfad->bfa_fcs); 1051 bfa_fcs_init(&bfad->bfa_fcs);
1090 spin_unlock_irqrestore(&bfad->bfad_lock, flags); 1052 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1091 1053
1092 /* PPORT FCS config */
1093 bfad_fcs_port_cfg(bfad);
1094
1095 retval = bfad_cfg_pport(bfad, BFA_LPORT_ROLE_FCP_IM); 1054 retval = bfad_cfg_pport(bfad, BFA_LPORT_ROLE_FCP_IM);
1096 if (retval != BFA_STATUS_OK) { 1055 if (retval != BFA_STATUS_OK) {
1097 if (bfa_sm_cmp_state(bfad, bfad_sm_initializing)) 1056 if (bfa_sm_cmp_state(bfad, bfad_sm_initializing))
@@ -1181,7 +1140,7 @@ bfad_worker(void *ptr)
1181 return 0; 1140 return 0;
1182} 1141}
1183 1142
1184/** 1143/*
1185 * BFA driver interrupt functions 1144 * BFA driver interrupt functions
1186 */ 1145 */
1187irqreturn_t 1146irqreturn_t
@@ -1240,7 +1199,7 @@ bfad_msix(int irq, void *dev_id)
1240 return IRQ_HANDLED; 1199 return IRQ_HANDLED;
1241} 1200}
1242 1201
1243/** 1202/*
1244 * Initialize the MSIX entry table. 1203 * Initialize the MSIX entry table.
1245 */ 1204 */
1246static void 1205static void
@@ -1293,7 +1252,7 @@ bfad_install_msix_handler(struct bfad_s *bfad)
1293 return 0; 1252 return 0;
1294} 1253}
1295 1254
1296/** 1255/*
1297 * Setup MSIX based interrupt. 1256 * Setup MSIX based interrupt.
1298 */ 1257 */
1299int 1258int
@@ -1374,7 +1333,7 @@ bfad_remove_intr(struct bfad_s *bfad)
1374 } 1333 }
1375} 1334}
1376 1335
1377/** 1336/*
1378 * PCI probe entry. 1337 * PCI probe entry.
1379 */ 1338 */
1380int 1339int
@@ -1460,7 +1419,7 @@ out:
1460 return error; 1419 return error;
1461} 1420}
1462 1421
1463/** 1422/*
1464 * PCI remove entry. 1423 * PCI remove entry.
1465 */ 1424 */
1466void 1425void
@@ -1541,7 +1500,7 @@ static struct pci_driver bfad_pci_driver = {
1541 .remove = __devexit_p(bfad_pci_remove), 1500 .remove = __devexit_p(bfad_pci_remove),
1542}; 1501};
1543 1502
1544/** 1503/*
1545 * Driver module init. 1504 * Driver module init.
1546 */ 1505 */
1547static int __init 1506static int __init
@@ -1581,7 +1540,7 @@ ext:
1581 return error; 1540 return error;
1582} 1541}
1583 1542
1584/** 1543/*
1585 * Driver module exit. 1544 * Driver module exit.
1586 */ 1545 */
1587static void __exit 1546static void __exit
diff --git a/drivers/scsi/bfa/bfad_attr.c b/drivers/scsi/bfa/bfad_attr.c
index d8843720eac1..ed9fff440b5c 100644
--- a/drivers/scsi/bfa/bfad_attr.c
+++ b/drivers/scsi/bfa/bfad_attr.c
@@ -15,14 +15,14 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * bfa_attr.c Linux driver configuration interface module. 19 * bfa_attr.c Linux driver configuration interface module.
20 */ 20 */
21 21
22#include "bfad_drv.h" 22#include "bfad_drv.h"
23#include "bfad_im.h" 23#include "bfad_im.h"
24 24
25/** 25/*
26 * FC transport template entry, get SCSI target port ID. 26 * FC transport template entry, get SCSI target port ID.
27 */ 27 */
28void 28void
@@ -48,7 +48,7 @@ bfad_im_get_starget_port_id(struct scsi_target *starget)
48 spin_unlock_irqrestore(&bfad->bfad_lock, flags); 48 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
49} 49}
50 50
51/** 51/*
52 * FC transport template entry, get SCSI target nwwn. 52 * FC transport template entry, get SCSI target nwwn.
53 */ 53 */
54void 54void
@@ -70,11 +70,11 @@ bfad_im_get_starget_node_name(struct scsi_target *starget)
70 if (itnim) 70 if (itnim)
71 node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim); 71 node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim);
72 72
73 fc_starget_node_name(starget) = bfa_os_htonll(node_name); 73 fc_starget_node_name(starget) = cpu_to_be64(node_name);
74 spin_unlock_irqrestore(&bfad->bfad_lock, flags); 74 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
75} 75}
76 76
77/** 77/*
78 * FC transport template entry, get SCSI target pwwn. 78 * FC transport template entry, get SCSI target pwwn.
79 */ 79 */
80void 80void
@@ -96,11 +96,11 @@ bfad_im_get_starget_port_name(struct scsi_target *starget)
96 if (itnim) 96 if (itnim)
97 port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim); 97 port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
98 98
99 fc_starget_port_name(starget) = bfa_os_htonll(port_name); 99 fc_starget_port_name(starget) = cpu_to_be64(port_name);
100 spin_unlock_irqrestore(&bfad->bfad_lock, flags); 100 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
101} 101}
102 102
103/** 103/*
104 * FC transport template entry, get SCSI host port ID. 104 * FC transport template entry, get SCSI host port ID.
105 */ 105 */
106void 106void
@@ -114,7 +114,7 @@ bfad_im_get_host_port_id(struct Scsi_Host *shost)
114 bfa_os_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port)); 114 bfa_os_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port));
115} 115}
116 116
117/** 117/*
118 * FC transport template entry, get SCSI host port type. 118 * FC transport template entry, get SCSI host port type.
119 */ 119 */
120static void 120static void
@@ -146,7 +146,7 @@ bfad_im_get_host_port_type(struct Scsi_Host *shost)
146 } 146 }
147} 147}
148 148
149/** 149/*
150 * FC transport template entry, get SCSI host port state. 150 * FC transport template entry, get SCSI host port state.
151 */ 151 */
152static void 152static void
@@ -183,7 +183,7 @@ bfad_im_get_host_port_state(struct Scsi_Host *shost)
183 } 183 }
184} 184}
185 185
186/** 186/*
187 * FC transport template entry, get SCSI host active fc4s. 187 * FC transport template entry, get SCSI host active fc4s.
188 */ 188 */
189static void 189static void
@@ -202,7 +202,7 @@ bfad_im_get_host_active_fc4s(struct Scsi_Host *shost)
202 fc_host_active_fc4s(shost)[7] = 1; 202 fc_host_active_fc4s(shost)[7] = 1;
203} 203}
204 204
205/** 205/*
206 * FC transport template entry, get SCSI host link speed. 206 * FC transport template entry, get SCSI host link speed.
207 */ 207 */
208static void 208static void
@@ -236,7 +236,7 @@ bfad_im_get_host_speed(struct Scsi_Host *shost)
236 } 236 }
237} 237}
238 238
239/** 239/*
240 * FC transport template entry, get SCSI host port type. 240 * FC transport template entry, get SCSI host port type.
241 */ 241 */
242static void 242static void
@@ -249,11 +249,11 @@ bfad_im_get_host_fabric_name(struct Scsi_Host *shost)
249 249
250 fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port); 250 fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port);
251 251
252 fc_host_fabric_name(shost) = bfa_os_htonll(fabric_nwwn); 252 fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn);
253 253
254} 254}
255 255
256/** 256/*
257 * FC transport template entry, get BFAD statistics. 257 * FC transport template entry, get BFAD statistics.
258 */ 258 */
259static struct fc_host_statistics * 259static struct fc_host_statistics *
@@ -304,7 +304,7 @@ bfad_im_get_stats(struct Scsi_Host *shost)
304 return hstats; 304 return hstats;
305} 305}
306 306
307/** 307/*
308 * FC transport template entry, reset BFAD statistics. 308 * FC transport template entry, reset BFAD statistics.
309 */ 309 */
310static void 310static void
@@ -331,7 +331,7 @@ bfad_im_reset_stats(struct Scsi_Host *shost)
331 return; 331 return;
332} 332}
333 333
334/** 334/*
335 * FC transport template entry, get rport loss timeout. 335 * FC transport template entry, get rport loss timeout.
336 */ 336 */
337static void 337static void
@@ -347,7 +347,7 @@ bfad_im_get_rport_loss_tmo(struct fc_rport *rport)
347 spin_unlock_irqrestore(&bfad->bfad_lock, flags); 347 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
348} 348}
349 349
350/** 350/*
351 * FC transport template entry, set rport loss timeout. 351 * FC transport template entry, set rport loss timeout.
352 */ 352 */
353static void 353static void
@@ -633,7 +633,7 @@ struct fc_function_template bfad_im_vport_fc_function_template = {
633 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo, 633 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
634}; 634};
635 635
636/** 636/*
637 * Scsi_Host_attrs SCSI host attributes 637 * Scsi_Host_attrs SCSI host attributes
638 */ 638 */
639static ssize_t 639static ssize_t
@@ -733,7 +733,7 @@ bfad_im_node_name_show(struct device *dev, struct device_attribute *attr,
733 u64 nwwn; 733 u64 nwwn;
734 734
735 nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port); 735 nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port);
736 return snprintf(buf, PAGE_SIZE, "0x%llx\n", bfa_os_htonll(nwwn)); 736 return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn));
737} 737}
738 738
739static ssize_t 739static ssize_t
diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
index 69ed1c4a903e..1fedeeb4ac1f 100644
--- a/drivers/scsi/bfa/bfad_debugfs.c
+++ b/drivers/scsi/bfa/bfad_debugfs.c
@@ -318,7 +318,7 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
318 regbuf = (u32 *)bfad->regdata; 318 regbuf = (u32 *)bfad->regdata;
319 spin_lock_irqsave(&bfad->bfad_lock, flags); 319 spin_lock_irqsave(&bfad->bfad_lock, flags);
320 for (i = 0; i < len; i++) { 320 for (i = 0; i < len; i++) {
321 *regbuf = bfa_reg_read(reg_addr); 321 *regbuf = readl(reg_addr);
322 regbuf++; 322 regbuf++;
323 reg_addr += sizeof(u32); 323 reg_addr += sizeof(u32);
324 } 324 }
@@ -361,7 +361,7 @@ bfad_debugfs_write_regwr(struct file *file, const char __user *buf,
361 361
362 reg_addr = (u32 *) ((u8 *) bfa_ioc_bar0(ioc) + addr); 362 reg_addr = (u32 *) ((u8 *) bfa_ioc_bar0(ioc) + addr);
363 spin_lock_irqsave(&bfad->bfad_lock, flags); 363 spin_lock_irqsave(&bfad->bfad_lock, flags);
364 bfa_reg_write(reg_addr, val); 364 writel(val, reg_addr);
365 spin_unlock_irqrestore(&bfad->bfad_lock, flags); 365 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
366 366
367 return nbytes; 367 return nbytes;
diff --git a/drivers/scsi/bfa/bfad_drv.h b/drivers/scsi/bfa/bfad_drv.h
index 98420bbb4f3f..97f9b6c0937e 100644
--- a/drivers/scsi/bfa/bfad_drv.h
+++ b/drivers/scsi/bfa/bfad_drv.h
@@ -15,11 +15,11 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * Contains base driver definitions. 19 * Contains base driver definitions.
20 */ 20 */
21 21
22/** 22/*
23 * bfa_drv.h Linux driver data structures. 23 * bfa_drv.h Linux driver data structures.
24 */ 24 */
25 25
@@ -309,7 +309,6 @@ void bfad_bfa_tmo(unsigned long data);
309void bfad_init_timer(struct bfad_s *bfad); 309void bfad_init_timer(struct bfad_s *bfad);
310int bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad); 310int bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad);
311void bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad); 311void bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad);
312void bfad_fcs_port_cfg(struct bfad_s *bfad);
313void bfad_drv_uninit(struct bfad_s *bfad); 312void bfad_drv_uninit(struct bfad_s *bfad);
314int bfad_worker(void *ptr); 313int bfad_worker(void *ptr);
315void bfad_debugfs_init(struct bfad_port_s *port); 314void bfad_debugfs_init(struct bfad_port_s *port);
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index d950ee44016e..8ca967dee66d 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -15,7 +15,7 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18/** 18/*
19 * bfad_im.c Linux driver IM module. 19 * bfad_im.c Linux driver IM module.
20 */ 20 */
21 21
@@ -30,8 +30,7 @@ DEFINE_IDR(bfad_im_port_index);
30struct scsi_transport_template *bfad_im_scsi_transport_template; 30struct scsi_transport_template *bfad_im_scsi_transport_template;
31struct scsi_transport_template *bfad_im_scsi_vport_transport_template; 31struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
32static void bfad_im_itnim_work_handler(struct work_struct *work); 32static void bfad_im_itnim_work_handler(struct work_struct *work);
33static int bfad_im_queuecommand(struct scsi_cmnd *cmnd, 33static int bfad_im_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmnd);
34 void (*done)(struct scsi_cmnd *));
35static int bfad_im_slave_alloc(struct scsi_device *sdev); 34static int bfad_im_slave_alloc(struct scsi_device *sdev);
36static void bfad_im_fc_rport_add(struct bfad_im_port_s *im_port, 35static void bfad_im_fc_rport_add(struct bfad_im_port_s *im_port,
37 struct bfad_itnim_s *itnim); 36 struct bfad_itnim_s *itnim);
@@ -164,10 +163,10 @@ bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
164 wake_up(wq); 163 wake_up(wq);
165} 164}
166 165
167/** 166/*
168 * Scsi_Host_template SCSI host template 167 * Scsi_Host_template SCSI host template
169 */ 168 */
170/** 169/*
171 * Scsi_Host template entry, returns BFAD PCI info. 170 * Scsi_Host template entry, returns BFAD PCI info.
172 */ 171 */
173static const char * 172static const char *
@@ -196,7 +195,7 @@ bfad_im_info(struct Scsi_Host *shost)
196 return bfa_buf; 195 return bfa_buf;
197} 196}
198 197
199/** 198/*
200 * Scsi_Host template entry, aborts the specified SCSI command. 199 * Scsi_Host template entry, aborts the specified SCSI command.
201 * 200 *
202 * Returns: SUCCESS or FAILED. 201 * Returns: SUCCESS or FAILED.
@@ -280,7 +279,7 @@ out:
280 return rc; 279 return rc;
281} 280}
282 281
283/** 282/*
284 * Scsi_Host template entry, resets a LUN and abort its all commands. 283 * Scsi_Host template entry, resets a LUN and abort its all commands.
285 * 284 *
286 * Returns: SUCCESS or FAILED. 285 * Returns: SUCCESS or FAILED.
@@ -319,7 +318,7 @@ bfad_im_reset_lun_handler(struct scsi_cmnd *cmnd)
319 goto out; 318 goto out;
320 } 319 }
321 320
322 /** 321 /*
323 * Set host_scribble to NULL to avoid aborting a task command 322 * Set host_scribble to NULL to avoid aborting a task command
324 * if happens. 323 * if happens.
325 */ 324 */
@@ -346,7 +345,7 @@ out:
346 return rc; 345 return rc;
347} 346}
348 347
349/** 348/*
350 * Scsi_Host template entry, resets the bus and abort all commands. 349 * Scsi_Host template entry, resets the bus and abort all commands.
351 */ 350 */
352static int 351static int
@@ -396,7 +395,7 @@ bfad_im_reset_bus_handler(struct scsi_cmnd *cmnd)
396 return SUCCESS; 395 return SUCCESS;
397} 396}
398 397
399/** 398/*
400 * Scsi_Host template entry slave_destroy. 399 * Scsi_Host template entry slave_destroy.
401 */ 400 */
402static void 401static void
@@ -406,11 +405,11 @@ bfad_im_slave_destroy(struct scsi_device *sdev)
406 return; 405 return;
407} 406}
408 407
409/** 408/*
410 * BFA FCS itnim callbacks 409 * BFA FCS itnim callbacks
411 */ 410 */
412 411
413/** 412/*
414 * BFA FCS itnim alloc callback, after successful PRLI 413 * BFA FCS itnim alloc callback, after successful PRLI
415 * Context: Interrupt 414 * Context: Interrupt
416 */ 415 */
@@ -433,7 +432,7 @@ bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
433 bfad->bfad_flags |= BFAD_RPORT_ONLINE; 432 bfad->bfad_flags |= BFAD_RPORT_ONLINE;
434} 433}
435 434
436/** 435/*
437 * BFA FCS itnim free callback. 436 * BFA FCS itnim free callback.
438 * Context: Interrupt. bfad_lock is held 437 * Context: Interrupt. bfad_lock is held
439 */ 438 */
@@ -471,7 +470,7 @@ bfa_fcb_itnim_free(struct bfad_s *bfad, struct bfad_itnim_s *itnim_drv)
471 queue_work(im->drv_workq, &itnim_drv->itnim_work); 470 queue_work(im->drv_workq, &itnim_drv->itnim_work);
472} 471}
473 472
474/** 473/*
475 * BFA FCS itnim online callback. 474 * BFA FCS itnim online callback.
476 * Context: Interrupt. bfad_lock is held 475 * Context: Interrupt. bfad_lock is held
477 */ 476 */
@@ -492,7 +491,7 @@ bfa_fcb_itnim_online(struct bfad_itnim_s *itnim_drv)
492 queue_work(im->drv_workq, &itnim_drv->itnim_work); 491 queue_work(im->drv_workq, &itnim_drv->itnim_work);
493} 492}
494 493
495/** 494/*
496 * BFA FCS itnim offline callback. 495 * BFA FCS itnim offline callback.
497 * Context: Interrupt. bfad_lock is held 496 * Context: Interrupt. bfad_lock is held
498 */ 497 */
@@ -519,7 +518,7 @@ bfa_fcb_itnim_offline(struct bfad_itnim_s *itnim_drv)
519 queue_work(im->drv_workq, &itnim_drv->itnim_work); 518 queue_work(im->drv_workq, &itnim_drv->itnim_work);
520} 519}
521 520
522/** 521/*
523 * Allocate a Scsi_Host for a port. 522 * Allocate a Scsi_Host for a port.
524 */ 523 */
525int 524int
@@ -751,7 +750,7 @@ bfad_os_thread_workq(struct bfad_s *bfad)
751 return BFA_STATUS_OK; 750 return BFA_STATUS_OK;
752} 751}
753 752
754/** 753/*
755 * Scsi_Host template entry. 754 * Scsi_Host template entry.
756 * 755 *
757 * Description: 756 * Description:
@@ -896,7 +895,7 @@ bfad_os_get_itnim(struct bfad_im_port_s *im_port, int id)
896 return NULL; 895 return NULL;
897} 896}
898 897
899/** 898/*
900 * Scsi_Host template entry slave_alloc 899 * Scsi_Host template entry slave_alloc
901 */ 900 */
902static int 901static int
@@ -915,12 +914,16 @@ bfad_im_slave_alloc(struct scsi_device *sdev)
915static u32 914static u32
916bfad_im_supported_speeds(struct bfa_s *bfa) 915bfad_im_supported_speeds(struct bfa_s *bfa)
917{ 916{
918 struct bfa_ioc_attr_s ioc_attr; 917 struct bfa_ioc_attr_s *ioc_attr;
919 u32 supported_speed = 0; 918 u32 supported_speed = 0;
920 919
921 bfa_get_attr(bfa, &ioc_attr); 920 ioc_attr = kzalloc(sizeof(struct bfa_ioc_attr_s), GFP_KERNEL);
922 if (ioc_attr.adapter_attr.max_speed == BFA_PORT_SPEED_8GBPS) { 921 if (!ioc_attr)
923 if (ioc_attr.adapter_attr.is_mezz) { 922 return 0;
923
924 bfa_get_attr(bfa, ioc_attr);
925 if (ioc_attr->adapter_attr.max_speed == BFA_PORT_SPEED_8GBPS) {
926 if (ioc_attr->adapter_attr.is_mezz) {
924 supported_speed |= FC_PORTSPEED_8GBIT | 927 supported_speed |= FC_PORTSPEED_8GBIT |
925 FC_PORTSPEED_4GBIT | 928 FC_PORTSPEED_4GBIT |
926 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT; 929 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
@@ -929,12 +932,13 @@ bfad_im_supported_speeds(struct bfa_s *bfa)
929 FC_PORTSPEED_4GBIT | 932 FC_PORTSPEED_4GBIT |
930 FC_PORTSPEED_2GBIT; 933 FC_PORTSPEED_2GBIT;
931 } 934 }
932 } else if (ioc_attr.adapter_attr.max_speed == BFA_PORT_SPEED_4GBPS) { 935 } else if (ioc_attr->adapter_attr.max_speed == BFA_PORT_SPEED_4GBPS) {
933 supported_speed |= FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT | 936 supported_speed |= FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
934 FC_PORTSPEED_1GBIT; 937 FC_PORTSPEED_1GBIT;
935 } else if (ioc_attr.adapter_attr.max_speed == BFA_PORT_SPEED_10GBPS) { 938 } else if (ioc_attr->adapter_attr.max_speed == BFA_PORT_SPEED_10GBPS) {
936 supported_speed |= FC_PORTSPEED_10GBIT; 939 supported_speed |= FC_PORTSPEED_10GBIT;
937 } 940 }
941 kfree(ioc_attr);
938 return supported_speed; 942 return supported_speed;
939} 943}
940 944
@@ -944,14 +948,13 @@ bfad_os_fc_host_init(struct bfad_im_port_s *im_port)
944 struct Scsi_Host *host = im_port->shost; 948 struct Scsi_Host *host = im_port->shost;
945 struct bfad_s *bfad = im_port->bfad; 949 struct bfad_s *bfad = im_port->bfad;
946 struct bfad_port_s *port = im_port->port; 950 struct bfad_port_s *port = im_port->port;
947 struct bfa_port_attr_s pattr;
948 struct bfa_lport_attr_s port_attr;
949 char symname[BFA_SYMNAME_MAXLEN]; 951 char symname[BFA_SYMNAME_MAXLEN];
952 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
950 953
951 fc_host_node_name(host) = 954 fc_host_node_name(host) =
952 bfa_os_htonll((bfa_fcs_lport_get_nwwn(port->fcs_port))); 955 cpu_to_be64((bfa_fcs_lport_get_nwwn(port->fcs_port)));
953 fc_host_port_name(host) = 956 fc_host_port_name(host) =
954 bfa_os_htonll((bfa_fcs_lport_get_pwwn(port->fcs_port))); 957 cpu_to_be64((bfa_fcs_lport_get_pwwn(port->fcs_port)));
955 fc_host_max_npiv_vports(host) = bfa_lps_get_max_vport(&bfad->bfa); 958 fc_host_max_npiv_vports(host) = bfa_lps_get_max_vport(&bfad->bfa);
956 959
957 fc_host_supported_classes(host) = FC_COS_CLASS3; 960 fc_host_supported_classes(host) = FC_COS_CLASS3;
@@ -964,15 +967,12 @@ bfad_os_fc_host_init(struct bfad_im_port_s *im_port)
964 /* For fibre channel services type 0x20 */ 967 /* For fibre channel services type 0x20 */
965 fc_host_supported_fc4s(host)[7] = 1; 968 fc_host_supported_fc4s(host)[7] = 1;
966 969
967 bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); 970 strncpy(symname, bfad->bfa_fcs.fabric.bport.port_cfg.sym_name.symname,
968 strncpy(symname, port_attr.port_cfg.sym_name.symname,
969 BFA_SYMNAME_MAXLEN); 971 BFA_SYMNAME_MAXLEN);
970 sprintf(fc_host_symbolic_name(host), "%s", symname); 972 sprintf(fc_host_symbolic_name(host), "%s", symname);
971 973
972 fc_host_supported_speeds(host) = bfad_im_supported_speeds(&bfad->bfa); 974 fc_host_supported_speeds(host) = bfad_im_supported_speeds(&bfad->bfa);
973 975 fc_host_maxframe_size(host) = fcport->cfg.maxfrsize;
974 bfa_fcport_get_attr(&bfad->bfa, &pattr);
975 fc_host_maxframe_size(host) = pattr.pport_cfg.maxfrsize;
976} 976}
977 977
978static void 978static void
@@ -983,9 +983,9 @@ bfad_im_fc_rport_add(struct bfad_im_port_s *im_port, struct bfad_itnim_s *itnim)
983 struct bfad_itnim_data_s *itnim_data; 983 struct bfad_itnim_data_s *itnim_data;
984 984
985 rport_ids.node_name = 985 rport_ids.node_name =
986 bfa_os_htonll(bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim)); 986 cpu_to_be64(bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim));
987 rport_ids.port_name = 987 rport_ids.port_name =
988 bfa_os_htonll(bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim)); 988 cpu_to_be64(bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
989 rport_ids.port_id = 989 rport_ids.port_id =
990 bfa_os_hton3b(bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim)); 990 bfa_os_hton3b(bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim));
991 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; 991 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
@@ -1015,7 +1015,7 @@ bfad_im_fc_rport_add(struct bfad_im_port_s *im_port, struct bfad_itnim_s *itnim)
1015 return; 1015 return;
1016} 1016}
1017 1017
1018/** 1018/*
1019 * Work queue handler using FC transport service 1019 * Work queue handler using FC transport service
1020* Context: kernel 1020* Context: kernel
1021 */ 1021 */
@@ -1115,11 +1115,11 @@ bfad_im_itnim_work_handler(struct work_struct *work)
1115 spin_unlock_irqrestore(&bfad->bfad_lock, flags); 1115 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1116} 1116}
1117 1117
1118/** 1118/*
1119 * Scsi_Host template entry, queue a SCSI command to the BFAD. 1119 * Scsi_Host template entry, queue a SCSI command to the BFAD.
1120 */ 1120 */
1121static int 1121static int
1122bfad_im_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) 1122bfad_im_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
1123{ 1123{
1124 struct bfad_im_port_s *im_port = 1124 struct bfad_im_port_s *im_port =
1125 (struct bfad_im_port_s *) cmnd->device->host->hostdata[0]; 1125 (struct bfad_im_port_s *) cmnd->device->host->hostdata[0];
@@ -1186,6 +1186,8 @@ out_fail_cmd:
1186 return 0; 1186 return 0;
1187} 1187}
1188 1188
1189static DEF_SCSI_QCMD(bfad_im_queuecommand)
1190
1189void 1191void
1190bfad_os_rport_online_wait(struct bfad_s *bfad) 1192bfad_os_rport_online_wait(struct bfad_s *bfad)
1191{ 1193{
diff --git a/drivers/scsi/bfa/bfi.h b/drivers/scsi/bfa/bfi.h
index 85f2224a5733..58796d1284b7 100644
--- a/drivers/scsi/bfa/bfi.h
+++ b/drivers/scsi/bfa/bfi.h
@@ -23,7 +23,7 @@
23 23
24#pragma pack(1) 24#pragma pack(1)
25 25
26/** 26/*
27 * BFI FW image type 27 * BFI FW image type
28 */ 28 */
29#define BFI_FLASH_CHUNK_SZ 256 /* Flash chunk size */ 29#define BFI_FLASH_CHUNK_SZ 256 /* Flash chunk size */
@@ -35,7 +35,7 @@ enum {
35 BFI_IMAGE_MAX, 35 BFI_IMAGE_MAX,
36}; 36};
37 37
38/** 38/*
39 * Msg header common to all msgs 39 * Msg header common to all msgs
40 */ 40 */
41struct bfi_mhdr_s { 41struct bfi_mhdr_s {
@@ -68,7 +68,7 @@ struct bfi_mhdr_s {
68#define BFI_I2H_OPCODE_BASE 128 68#define BFI_I2H_OPCODE_BASE 128
69#define BFA_I2HM(_x) ((_x) + BFI_I2H_OPCODE_BASE) 69#define BFA_I2HM(_x) ((_x) + BFI_I2H_OPCODE_BASE)
70 70
71/** 71/*
72 **************************************************************************** 72 ****************************************************************************
73 * 73 *
74 * Scatter Gather Element and Page definition 74 * Scatter Gather Element and Page definition
@@ -79,7 +79,7 @@ struct bfi_mhdr_s {
79#define BFI_SGE_INLINE 1 79#define BFI_SGE_INLINE 1
80#define BFI_SGE_INLINE_MAX (BFI_SGE_INLINE + 1) 80#define BFI_SGE_INLINE_MAX (BFI_SGE_INLINE + 1)
81 81
82/** 82/*
83 * SG Flags 83 * SG Flags
84 */ 84 */
85enum { 85enum {
@@ -90,7 +90,7 @@ enum {
90 BFI_SGE_PGDLEN = 2, /* cumulative data length for page */ 90 BFI_SGE_PGDLEN = 2, /* cumulative data length for page */
91}; 91};
92 92
93/** 93/*
94 * DMA addresses 94 * DMA addresses
95 */ 95 */
96union bfi_addr_u { 96union bfi_addr_u {
@@ -100,7 +100,7 @@ union bfi_addr_u {
100 } a32; 100 } a32;
101}; 101};
102 102
103/** 103/*
104 * Scatter Gather Element 104 * Scatter Gather Element
105 */ 105 */
106struct bfi_sge_s { 106struct bfi_sge_s {
@@ -116,7 +116,7 @@ struct bfi_sge_s {
116 union bfi_addr_u sga; 116 union bfi_addr_u sga;
117}; 117};
118 118
119/** 119/*
120 * Scatter Gather Page 120 * Scatter Gather Page
121 */ 121 */
122#define BFI_SGPG_DATA_SGES 7 122#define BFI_SGPG_DATA_SGES 7
@@ -139,7 +139,7 @@ struct bfi_msg_s {
139 u32 pl[BFI_LMSG_PL_WSZ]; 139 u32 pl[BFI_LMSG_PL_WSZ];
140}; 140};
141 141
142/** 142/*
143 * Mailbox message structure 143 * Mailbox message structure
144 */ 144 */
145#define BFI_MBMSG_SZ 7 145#define BFI_MBMSG_SZ 7
@@ -148,7 +148,7 @@ struct bfi_mbmsg_s {
148 u32 pl[BFI_MBMSG_SZ]; 148 u32 pl[BFI_MBMSG_SZ];
149}; 149};
150 150
151/** 151/*
152 * Message Classes 152 * Message Classes
153 */ 153 */
154enum bfi_mclass { 154enum bfi_mclass {
@@ -186,7 +186,7 @@ enum bfi_mclass {
186#define BFI_BOOT_LOADER_BIOS 1 186#define BFI_BOOT_LOADER_BIOS 1
187#define BFI_BOOT_LOADER_UEFI 2 187#define BFI_BOOT_LOADER_UEFI 2
188 188
189/** 189/*
190 *---------------------------------------------------------------------- 190 *----------------------------------------------------------------------
191 * IOC 191 * IOC
192 *---------------------------------------------------------------------- 192 *----------------------------------------------------------------------
@@ -208,7 +208,7 @@ enum bfi_ioc_i2h_msgs {
208 BFI_IOC_I2H_HBEAT = BFA_I2HM(5), 208 BFI_IOC_I2H_HBEAT = BFA_I2HM(5),
209}; 209};
210 210
211/** 211/*
212 * BFI_IOC_H2I_GETATTR_REQ message 212 * BFI_IOC_H2I_GETATTR_REQ message
213 */ 213 */
214struct bfi_ioc_getattr_req_s { 214struct bfi_ioc_getattr_req_s {
@@ -242,7 +242,7 @@ struct bfi_ioc_attr_s {
242 u32 card_type; /* card type */ 242 u32 card_type; /* card type */
243}; 243};
244 244
245/** 245/*
246 * BFI_IOC_I2H_GETATTR_REPLY message 246 * BFI_IOC_I2H_GETATTR_REPLY message
247 */ 247 */
248struct bfi_ioc_getattr_reply_s { 248struct bfi_ioc_getattr_reply_s {
@@ -251,19 +251,19 @@ struct bfi_ioc_getattr_reply_s {
251 u8 rsvd[3]; 251 u8 rsvd[3];
252}; 252};
253 253
254/** 254/*
255 * Firmware memory page offsets 255 * Firmware memory page offsets
256 */ 256 */
257#define BFI_IOC_SMEM_PG0_CB (0x40) 257#define BFI_IOC_SMEM_PG0_CB (0x40)
258#define BFI_IOC_SMEM_PG0_CT (0x180) 258#define BFI_IOC_SMEM_PG0_CT (0x180)
259 259
260/** 260/*
261 * Firmware statistic offset 261 * Firmware statistic offset
262 */ 262 */
263#define BFI_IOC_FWSTATS_OFF (0x6B40) 263#define BFI_IOC_FWSTATS_OFF (0x6B40)
264#define BFI_IOC_FWSTATS_SZ (4096) 264#define BFI_IOC_FWSTATS_SZ (4096)
265 265
266/** 266/*
267 * Firmware trace offset 267 * Firmware trace offset
268 */ 268 */
269#define BFI_IOC_TRC_OFF (0x4b00) 269#define BFI_IOC_TRC_OFF (0x4b00)
@@ -280,7 +280,7 @@ struct bfi_ioc_image_hdr_s {
280 u32 md5sum[BFI_IOC_MD5SUM_SZ]; 280 u32 md5sum[BFI_IOC_MD5SUM_SZ];
281}; 281};
282 282
283/** 283/*
284 * BFI_IOC_I2H_READY_EVENT message 284 * BFI_IOC_I2H_READY_EVENT message
285 */ 285 */
286struct bfi_ioc_rdy_event_s { 286struct bfi_ioc_rdy_event_s {
@@ -294,7 +294,7 @@ struct bfi_ioc_hbeat_s {
294 u32 hb_count; /* current heart beat count */ 294 u32 hb_count; /* current heart beat count */
295}; 295};
296 296
297/** 297/*
298 * IOC hardware/firmware state 298 * IOC hardware/firmware state
299 */ 299 */
300enum bfi_ioc_state { 300enum bfi_ioc_state {
@@ -340,7 +340,7 @@ enum {
340 ((__adap_type) & (BFI_ADAPTER_TTV | BFI_ADAPTER_PROTO | \ 340 ((__adap_type) & (BFI_ADAPTER_TTV | BFI_ADAPTER_PROTO | \
341 BFI_ADAPTER_UNSUPP)) 341 BFI_ADAPTER_UNSUPP))
342 342
343/** 343/*
344 * BFI_IOC_H2I_ENABLE_REQ & BFI_IOC_H2I_DISABLE_REQ messages 344 * BFI_IOC_H2I_ENABLE_REQ & BFI_IOC_H2I_DISABLE_REQ messages
345 */ 345 */
346struct bfi_ioc_ctrl_req_s { 346struct bfi_ioc_ctrl_req_s {
@@ -352,7 +352,7 @@ struct bfi_ioc_ctrl_req_s {
352#define bfi_ioc_enable_req_t struct bfi_ioc_ctrl_req_s; 352#define bfi_ioc_enable_req_t struct bfi_ioc_ctrl_req_s;
353#define bfi_ioc_disable_req_t struct bfi_ioc_ctrl_req_s; 353#define bfi_ioc_disable_req_t struct bfi_ioc_ctrl_req_s;
354 354
355/** 355/*
356 * BFI_IOC_I2H_ENABLE_REPLY & BFI_IOC_I2H_DISABLE_REPLY messages 356 * BFI_IOC_I2H_ENABLE_REPLY & BFI_IOC_I2H_DISABLE_REPLY messages
357 */ 357 */
358struct bfi_ioc_ctrl_reply_s { 358struct bfi_ioc_ctrl_reply_s {
@@ -364,7 +364,7 @@ struct bfi_ioc_ctrl_reply_s {
364#define bfi_ioc_disable_reply_t struct bfi_ioc_ctrl_reply_s; 364#define bfi_ioc_disable_reply_t struct bfi_ioc_ctrl_reply_s;
365 365
366#define BFI_IOC_MSGSZ 8 366#define BFI_IOC_MSGSZ 8
367/** 367/*
368 * H2I Messages 368 * H2I Messages
369 */ 369 */
370union bfi_ioc_h2i_msg_u { 370union bfi_ioc_h2i_msg_u {
@@ -375,7 +375,7 @@ union bfi_ioc_h2i_msg_u {
375 u32 mboxmsg[BFI_IOC_MSGSZ]; 375 u32 mboxmsg[BFI_IOC_MSGSZ];
376}; 376};
377 377
378/** 378/*
379 * I2H Messages 379 * I2H Messages
380 */ 380 */
381union bfi_ioc_i2h_msg_u { 381union bfi_ioc_i2h_msg_u {
@@ -385,7 +385,7 @@ union bfi_ioc_i2h_msg_u {
385}; 385};
386 386
387 387
388/** 388/*
389 *---------------------------------------------------------------------- 389 *----------------------------------------------------------------------
390 * PBC 390 * PBC
391 *---------------------------------------------------------------------- 391 *----------------------------------------------------------------------
@@ -394,7 +394,7 @@ union bfi_ioc_i2h_msg_u {
394#define BFI_PBC_MAX_BLUNS 8 394#define BFI_PBC_MAX_BLUNS 8
395#define BFI_PBC_MAX_VPORTS 16 395#define BFI_PBC_MAX_VPORTS 16
396 396
397/** 397/*
398 * PBC boot lun configuration 398 * PBC boot lun configuration
399 */ 399 */
400struct bfi_pbc_blun_s { 400struct bfi_pbc_blun_s {
@@ -402,7 +402,7 @@ struct bfi_pbc_blun_s {
402 lun_t tgt_lun; 402 lun_t tgt_lun;
403}; 403};
404 404
405/** 405/*
406 * PBC virtual port configuration 406 * PBC virtual port configuration
407 */ 407 */
408struct bfi_pbc_vport_s { 408struct bfi_pbc_vport_s {
@@ -410,7 +410,7 @@ struct bfi_pbc_vport_s {
410 wwn_t vp_nwwn; 410 wwn_t vp_nwwn;
411}; 411};
412 412
413/** 413/*
414 * BFI pre-boot configuration information 414 * BFI pre-boot configuration information
415 */ 415 */
416struct bfi_pbc_s { 416struct bfi_pbc_s {
@@ -427,7 +427,7 @@ struct bfi_pbc_s {
427 struct bfi_pbc_vport_s vport[BFI_PBC_MAX_VPORTS]; 427 struct bfi_pbc_vport_s vport[BFI_PBC_MAX_VPORTS];
428}; 428};
429 429
430/** 430/*
431 *---------------------------------------------------------------------- 431 *----------------------------------------------------------------------
432 * MSGQ 432 * MSGQ
433 *---------------------------------------------------------------------- 433 *----------------------------------------------------------------------
@@ -531,7 +531,7 @@ enum bfi_port_i2h {
531 BFI_PORT_I2H_CLEAR_STATS_RSP = BFA_I2HM(4), 531 BFI_PORT_I2H_CLEAR_STATS_RSP = BFA_I2HM(4),
532}; 532};
533 533
534/** 534/*
535 * Generic REQ type 535 * Generic REQ type
536 */ 536 */
537struct bfi_port_generic_req_s { 537struct bfi_port_generic_req_s {
@@ -540,7 +540,7 @@ struct bfi_port_generic_req_s {
540 u32 rsvd; 540 u32 rsvd;
541}; 541};
542 542
543/** 543/*
544 * Generic RSP type 544 * Generic RSP type
545 */ 545 */
546struct bfi_port_generic_rsp_s { 546struct bfi_port_generic_rsp_s {
@@ -550,7 +550,7 @@ struct bfi_port_generic_rsp_s {
550 u32 msgtag; /* msgtag for reply */ 550 u32 msgtag; /* msgtag for reply */
551}; 551};
552 552
553/** 553/*
554 * BFI_PORT_H2I_GET_STATS_REQ 554 * BFI_PORT_H2I_GET_STATS_REQ
555 */ 555 */
556struct bfi_port_get_stats_req_s { 556struct bfi_port_get_stats_req_s {
diff --git a/drivers/scsi/bfa/bfi_ms.h b/drivers/scsi/bfa/bfi_ms.h
index 69ac85f9e938..fa9f6fb9d45b 100644
--- a/drivers/scsi/bfa/bfi_ms.h
+++ b/drivers/scsi/bfa/bfi_ms.h
@@ -41,7 +41,7 @@ struct bfi_iocfc_cfg_s {
41 u16 rsvd_1; 41 u16 rsvd_1;
42 u32 endian_sig; /* endian signature of host */ 42 u32 endian_sig; /* endian signature of host */
43 43
44 /** 44 /*
45 * Request and response circular queue base addresses, size and 45 * Request and response circular queue base addresses, size and
46 * shadow index pointers. 46 * shadow index pointers.
47 */ 47 */
@@ -58,7 +58,7 @@ struct bfi_iocfc_cfg_s {
58 struct bfa_iocfc_intr_attr_s intr_attr; /* IOC interrupt attributes */ 58 struct bfa_iocfc_intr_attr_s intr_attr; /* IOC interrupt attributes */
59}; 59};
60 60
61/** 61/*
62 * Boot target wwn information for this port. This contains either the stored 62 * Boot target wwn information for this port. This contains either the stored
63 * or discovered boot target port wwns for the port. 63 * or discovered boot target port wwns for the port.
64 */ 64 */
@@ -75,7 +75,7 @@ struct bfi_iocfc_cfgrsp_s {
75 struct bfi_pbc_s pbc_cfg; 75 struct bfi_pbc_s pbc_cfg;
76}; 76};
77 77
78/** 78/*
79 * BFI_IOCFC_H2I_CFG_REQ message 79 * BFI_IOCFC_H2I_CFG_REQ message
80 */ 80 */
81struct bfi_iocfc_cfg_req_s { 81struct bfi_iocfc_cfg_req_s {
@@ -84,7 +84,7 @@ struct bfi_iocfc_cfg_req_s {
84}; 84};
85 85
86 86
87/** 87/*
88 * BFI_IOCFC_I2H_CFG_REPLY message 88 * BFI_IOCFC_I2H_CFG_REPLY message
89 */ 89 */
90struct bfi_iocfc_cfg_reply_s { 90struct bfi_iocfc_cfg_reply_s {
@@ -95,7 +95,7 @@ struct bfi_iocfc_cfg_reply_s {
95}; 95};
96 96
97 97
98/** 98/*
99 * BFI_IOCFC_H2I_SET_INTR_REQ message 99 * BFI_IOCFC_H2I_SET_INTR_REQ message
100 */ 100 */
101struct bfi_iocfc_set_intr_req_s { 101struct bfi_iocfc_set_intr_req_s {
@@ -107,7 +107,7 @@ struct bfi_iocfc_set_intr_req_s {
107}; 107};
108 108
109 109
110/** 110/*
111 * BFI_IOCFC_H2I_UPDATEQ_REQ message 111 * BFI_IOCFC_H2I_UPDATEQ_REQ message
112 */ 112 */
113struct bfi_iocfc_updateq_req_s { 113struct bfi_iocfc_updateq_req_s {
@@ -119,7 +119,7 @@ struct bfi_iocfc_updateq_req_s {
119}; 119};
120 120
121 121
122/** 122/*
123 * BFI_IOCFC_I2H_UPDATEQ_RSP message 123 * BFI_IOCFC_I2H_UPDATEQ_RSP message
124 */ 124 */
125struct bfi_iocfc_updateq_rsp_s { 125struct bfi_iocfc_updateq_rsp_s {
@@ -129,7 +129,7 @@ struct bfi_iocfc_updateq_rsp_s {
129}; 129};
130 130
131 131
132/** 132/*
133 * H2I Messages 133 * H2I Messages
134 */ 134 */
135union bfi_iocfc_h2i_msg_u { 135union bfi_iocfc_h2i_msg_u {
@@ -140,7 +140,7 @@ union bfi_iocfc_h2i_msg_u {
140}; 140};
141 141
142 142
143/** 143/*
144 * I2H Messages 144 * I2H Messages
145 */ 145 */
146union bfi_iocfc_i2h_msg_u { 146union bfi_iocfc_i2h_msg_u {
@@ -173,7 +173,7 @@ enum bfi_fcport_i2h {
173}; 173};
174 174
175 175
176/** 176/*
177 * Generic REQ type 177 * Generic REQ type
178 */ 178 */
179struct bfi_fcport_req_s { 179struct bfi_fcport_req_s {
@@ -181,7 +181,7 @@ struct bfi_fcport_req_s {
181 u32 msgtag; /* msgtag for reply */ 181 u32 msgtag; /* msgtag for reply */
182}; 182};
183 183
184/** 184/*
185 * Generic RSP type 185 * Generic RSP type
186 */ 186 */
187struct bfi_fcport_rsp_s { 187struct bfi_fcport_rsp_s {
@@ -191,7 +191,7 @@ struct bfi_fcport_rsp_s {
191 u32 msgtag; /* msgtag for reply */ 191 u32 msgtag; /* msgtag for reply */
192}; 192};
193 193
194/** 194/*
195 * BFI_FCPORT_H2I_ENABLE_REQ 195 * BFI_FCPORT_H2I_ENABLE_REQ
196 */ 196 */
197struct bfi_fcport_enable_req_s { 197struct bfi_fcport_enable_req_s {
@@ -205,7 +205,7 @@ struct bfi_fcport_enable_req_s {
205 u32 rsvd2; 205 u32 rsvd2;
206}; 206};
207 207
208/** 208/*
209 * BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ 209 * BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ
210 */ 210 */
211struct bfi_fcport_set_svc_params_req_s { 211struct bfi_fcport_set_svc_params_req_s {
@@ -214,7 +214,7 @@ struct bfi_fcport_set_svc_params_req_s {
214 u16 rsvd; 214 u16 rsvd;
215}; 215};
216 216
217/** 217/*
218 * BFI_FCPORT_I2H_EVENT 218 * BFI_FCPORT_I2H_EVENT
219 */ 219 */
220struct bfi_fcport_event_s { 220struct bfi_fcport_event_s {
@@ -222,7 +222,7 @@ struct bfi_fcport_event_s {
222 struct bfa_port_link_s link_state; 222 struct bfa_port_link_s link_state;
223}; 223};
224 224
225/** 225/*
226 * BFI_FCPORT_I2H_TRUNK_SCN 226 * BFI_FCPORT_I2H_TRUNK_SCN
227 */ 227 */
228struct bfi_fcport_trunk_link_s { 228struct bfi_fcport_trunk_link_s {
@@ -243,7 +243,7 @@ struct bfi_fcport_trunk_scn_s {
243 struct bfi_fcport_trunk_link_s tlink[BFI_FCPORT_MAX_LINKS]; 243 struct bfi_fcport_trunk_link_s tlink[BFI_FCPORT_MAX_LINKS];
244}; 244};
245 245
246/** 246/*
247 * fcport H2I message 247 * fcport H2I message
248 */ 248 */
249union bfi_fcport_h2i_msg_u { 249union bfi_fcport_h2i_msg_u {
@@ -255,7 +255,7 @@ union bfi_fcport_h2i_msg_u {
255 struct bfi_fcport_req_s *pstatsclear; 255 struct bfi_fcport_req_s *pstatsclear;
256}; 256};
257 257
258/** 258/*
259 * fcport I2H message 259 * fcport I2H message
260 */ 260 */
261union bfi_fcport_i2h_msg_u { 261union bfi_fcport_i2h_msg_u {
@@ -279,7 +279,7 @@ enum bfi_fcxp_i2h {
279 279
280#define BFA_FCXP_MAX_SGES 2 280#define BFA_FCXP_MAX_SGES 2
281 281
282/** 282/*
283 * FCXP send request structure 283 * FCXP send request structure
284 */ 284 */
285struct bfi_fcxp_send_req_s { 285struct bfi_fcxp_send_req_s {
@@ -299,7 +299,7 @@ struct bfi_fcxp_send_req_s {
299 struct bfi_sge_s rsp_sge[BFA_FCXP_MAX_SGES]; /* response buf */ 299 struct bfi_sge_s rsp_sge[BFA_FCXP_MAX_SGES]; /* response buf */
300}; 300};
301 301
302/** 302/*
303 * FCXP send response structure 303 * FCXP send response structure
304 */ 304 */
305struct bfi_fcxp_send_rsp_s { 305struct bfi_fcxp_send_rsp_s {
@@ -565,14 +565,14 @@ enum bfi_ioim_i2h {
565 BFI_IOIM_I2H_IOABORT_RSP = BFA_I2HM(2), /* ABORT rsp */ 565 BFI_IOIM_I2H_IOABORT_RSP = BFA_I2HM(2), /* ABORT rsp */
566}; 566};
567 567
568/** 568/*
569 * IO command DIF info 569 * IO command DIF info
570 */ 570 */
571struct bfi_ioim_dif_s { 571struct bfi_ioim_dif_s {
572 u32 dif_info[4]; 572 u32 dif_info[4];
573}; 573};
574 574
575/** 575/*
576 * FCP IO messages overview 576 * FCP IO messages overview
577 * 577 *
578 * @note 578 * @note
@@ -587,7 +587,7 @@ struct bfi_ioim_req_s {
587 u16 rport_hdl; /* itnim/rport firmware handle */ 587 u16 rport_hdl; /* itnim/rport firmware handle */
588 struct fcp_cmnd_s cmnd; /* IO request info */ 588 struct fcp_cmnd_s cmnd; /* IO request info */
589 589
590 /** 590 /*
591 * SG elements array within the IO request must be double word 591 * SG elements array within the IO request must be double word
592 * aligned. This aligment is required to optimize SGM setup for the IO. 592 * aligned. This aligment is required to optimize SGM setup for the IO.
593 */ 593 */
@@ -598,7 +598,7 @@ struct bfi_ioim_req_s {
598 struct bfi_ioim_dif_s dif; 598 struct bfi_ioim_dif_s dif;
599}; 599};
600 600
601/** 601/*
602 * This table shows various IO status codes from firmware and their 602 * This table shows various IO status codes from firmware and their
603 * meaning. Host driver can use these status codes to further process 603 * meaning. Host driver can use these status codes to further process
604 * IO completions. 604 * IO completions.
@@ -684,7 +684,7 @@ enum bfi_ioim_status {
684}; 684};
685 685
686#define BFI_IOIM_SNSLEN (256) 686#define BFI_IOIM_SNSLEN (256)
687/** 687/*
688 * I/O response message 688 * I/O response message
689 */ 689 */
690struct bfi_ioim_rsp_s { 690struct bfi_ioim_rsp_s {
@@ -746,7 +746,7 @@ enum bfi_tskim_status {
746 BFI_TSKIM_STS_NOT_SUPP = 4, 746 BFI_TSKIM_STS_NOT_SUPP = 4,
747 BFI_TSKIM_STS_FAILED = 5, 747 BFI_TSKIM_STS_FAILED = 5,
748 748
749 /** 749 /*
750 * Defined by BFA 750 * Defined by BFA
751 */ 751 */
752 BFI_TSKIM_STS_TIMEOUT = 10, /* TM request timedout */ 752 BFI_TSKIM_STS_TIMEOUT = 10, /* TM request timedout */
diff --git a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
index 99f2b8c5dd63..8c04fada710b 100644
--- a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
+++ b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
@@ -692,6 +692,9 @@ static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
692 &csk->daddr.sin_addr.s_addr, ntohs(csk->daddr.sin_port), 692 &csk->daddr.sin_addr.s_addr, ntohs(csk->daddr.sin_port),
693 atid, tid, status, csk, csk->state, csk->flags); 693 atid, tid, status, csk, csk->state, csk->flags);
694 694
695 if (status == CPL_ERR_RTX_NEG_ADVICE)
696 goto rel_skb;
697
695 if (status && status != CPL_ERR_TCAM_FULL && 698 if (status && status != CPL_ERR_TCAM_FULL &&
696 status != CPL_ERR_CONN_EXIST && 699 status != CPL_ERR_CONN_EXIST &&
697 status != CPL_ERR_ARP_MISS) 700 status != CPL_ERR_ARP_MISS)
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index 31bbfb244bc4..b0f8523e665f 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -1080,7 +1080,7 @@ static void build_srb(struct scsi_cmnd *cmd, struct DeviceCtlBlk *dcb,
1080 * and is expected to be held on return. 1080 * and is expected to be held on return.
1081 * 1081 *
1082 **/ 1082 **/
1083static int dc395x_queue_command(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 1083static int dc395x_queue_command_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
1084{ 1084{
1085 struct DeviceCtlBlk *dcb; 1085 struct DeviceCtlBlk *dcb;
1086 struct ScsiReqBlk *srb; 1086 struct ScsiReqBlk *srb;
@@ -1154,6 +1154,7 @@ complete:
1154 return 0; 1154 return 0;
1155} 1155}
1156 1156
1157static DEF_SCSI_QCMD(dc395x_queue_command)
1157 1158
1158/* 1159/*
1159 * Return the disk geometry for the given SCSI device. 1160 * Return the disk geometry for the given SCSI device.
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index b9bcfa4c7d26..5be3ae15cb71 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -773,6 +773,8 @@ static const struct scsi_dh_devlist rdac_dev_list[] = {
773 {"ENGENIO", "INF-01-00"}, 773 {"ENGENIO", "INF-01-00"},
774 {"STK", "FLEXLINE 380"}, 774 {"STK", "FLEXLINE 380"},
775 {"SUN", "CSM100_R_FC"}, 775 {"SUN", "CSM100_R_FC"},
776 {"SUN", "STK6580_6780"},
777 {"SUN", "SUN_6180"},
776 {NULL, NULL}, 778 {NULL, NULL},
777}; 779};
778 780
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 23dec0063385..cffcb108ac96 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -423,7 +423,7 @@ static int adpt_slave_configure(struct scsi_device * device)
423 return 0; 423 return 0;
424} 424}
425 425
426static int adpt_queue(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *)) 426static int adpt_queue_lck(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
427{ 427{
428 adpt_hba* pHba = NULL; 428 adpt_hba* pHba = NULL;
429 struct adpt_device* pDev = NULL; /* dpt per device information */ 429 struct adpt_device* pDev = NULL; /* dpt per device information */
@@ -491,6 +491,8 @@ static int adpt_queue(struct scsi_cmnd * cmd, void (*done) (struct scsi_cmnd *))
491 return adpt_scsi_to_i2o(pHba, cmd, pDev); 491 return adpt_scsi_to_i2o(pHba, cmd, pDev);
492} 492}
493 493
494static DEF_SCSI_QCMD(adpt_queue)
495
494static int adpt_bios_param(struct scsi_device *sdev, struct block_device *dev, 496static int adpt_bios_param(struct scsi_device *sdev, struct block_device *dev,
495 sector_t capacity, int geom[]) 497 sector_t capacity, int geom[])
496{ 498{
diff --git a/drivers/scsi/dpti.h b/drivers/scsi/dpti.h
index 337746d46043..beded716f93f 100644
--- a/drivers/scsi/dpti.h
+++ b/drivers/scsi/dpti.h
@@ -29,7 +29,7 @@
29 */ 29 */
30 30
31static int adpt_detect(struct scsi_host_template * sht); 31static int adpt_detect(struct scsi_host_template * sht);
32static int adpt_queue(struct scsi_cmnd * cmd, void (*cmdcomplete) (struct scsi_cmnd *)); 32static int adpt_queue(struct Scsi_Host *h, struct scsi_cmnd * cmd);
33static int adpt_abort(struct scsi_cmnd * cmd); 33static int adpt_abort(struct scsi_cmnd * cmd);
34static int adpt_reset(struct scsi_cmnd* cmd); 34static int adpt_reset(struct scsi_cmnd* cmd);
35static int adpt_release(struct Scsi_Host *host); 35static int adpt_release(struct Scsi_Host *host);
diff --git a/drivers/scsi/dtc.h b/drivers/scsi/dtc.h
index 0b205f8c7326..cdc621204b66 100644
--- a/drivers/scsi/dtc.h
+++ b/drivers/scsi/dtc.h
@@ -36,7 +36,7 @@ static int dtc_abort(Scsi_Cmnd *);
36static int dtc_biosparam(struct scsi_device *, struct block_device *, 36static int dtc_biosparam(struct scsi_device *, struct block_device *,
37 sector_t, int*); 37 sector_t, int*);
38static int dtc_detect(struct scsi_host_template *); 38static int dtc_detect(struct scsi_host_template *);
39static int dtc_queue_command(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *)); 39static int dtc_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
40static int dtc_bus_reset(Scsi_Cmnd *); 40static int dtc_bus_reset(Scsi_Cmnd *);
41 41
42#ifndef CMD_PER_LUN 42#ifndef CMD_PER_LUN
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index d1c31378f6da..53925ac178fd 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -505,8 +505,7 @@
505 505
506static int eata2x_detect(struct scsi_host_template *); 506static int eata2x_detect(struct scsi_host_template *);
507static int eata2x_release(struct Scsi_Host *); 507static int eata2x_release(struct Scsi_Host *);
508static int eata2x_queuecommand(struct scsi_cmnd *, 508static int eata2x_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
509 void (*done) (struct scsi_cmnd *));
510static int eata2x_eh_abort(struct scsi_cmnd *); 509static int eata2x_eh_abort(struct scsi_cmnd *);
511static int eata2x_eh_host_reset(struct scsi_cmnd *); 510static int eata2x_eh_host_reset(struct scsi_cmnd *);
512static int eata2x_bios_param(struct scsi_device *, struct block_device *, 511static int eata2x_bios_param(struct scsi_device *, struct block_device *,
@@ -1758,7 +1757,7 @@ static void scsi_to_dev_dir(unsigned int i, struct hostdata *ha)
1758 1757
1759} 1758}
1760 1759
1761static int eata2x_queuecommand(struct scsi_cmnd *SCpnt, 1760static int eata2x_queuecommand_lck(struct scsi_cmnd *SCpnt,
1762 void (*done) (struct scsi_cmnd *)) 1761 void (*done) (struct scsi_cmnd *))
1763{ 1762{
1764 struct Scsi_Host *shost = SCpnt->device->host; 1763 struct Scsi_Host *shost = SCpnt->device->host;
@@ -1843,6 +1842,8 @@ static int eata2x_queuecommand(struct scsi_cmnd *SCpnt,
1843 return 0; 1842 return 0;
1844} 1843}
1845 1844
1845static DEF_SCSI_QCMD(eata2x_queuecommand)
1846
1846static int eata2x_eh_abort(struct scsi_cmnd *SCarg) 1847static int eata2x_eh_abort(struct scsi_cmnd *SCarg)
1847{ 1848{
1848 struct Scsi_Host *shost = SCarg->device->host; 1849 struct Scsi_Host *shost = SCarg->device->host;
diff --git a/drivers/scsi/eata_pio.c b/drivers/scsi/eata_pio.c
index 60886c19065e..4a9641e69f54 100644
--- a/drivers/scsi/eata_pio.c
+++ b/drivers/scsi/eata_pio.c
@@ -335,7 +335,7 @@ static inline unsigned int eata_pio_send_command(unsigned long base, unsigned ch
335 return 0; 335 return 0;
336} 336}
337 337
338static int eata_pio_queue(struct scsi_cmnd *cmd, 338static int eata_pio_queue_lck(struct scsi_cmnd *cmd,
339 void (*done)(struct scsi_cmnd *)) 339 void (*done)(struct scsi_cmnd *))
340{ 340{
341 unsigned int x, y; 341 unsigned int x, y;
@@ -438,6 +438,8 @@ static int eata_pio_queue(struct scsi_cmnd *cmd,
438 return 0; 438 return 0;
439} 439}
440 440
441static DEF_SCSI_QCMD(eata_pio_queue)
442
441static int eata_pio_abort(struct scsi_cmnd *cmd) 443static int eata_pio_abort(struct scsi_cmnd *cmd)
442{ 444{
443 unsigned int loop = 100; 445 unsigned int loop = 100;
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index e2bc779f86c1..57558523c1b8 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -916,7 +916,7 @@ static void esp_event_queue_full(struct esp *esp, struct esp_cmd_entry *ent)
916 scsi_track_queue_full(dev, lp->num_tagged - 1); 916 scsi_track_queue_full(dev, lp->num_tagged - 1);
917} 917}
918 918
919static int esp_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 919static int esp_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
920{ 920{
921 struct scsi_device *dev = cmd->device; 921 struct scsi_device *dev = cmd->device;
922 struct esp *esp = shost_priv(dev->host); 922 struct esp *esp = shost_priv(dev->host);
@@ -941,6 +941,8 @@ static int esp_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd
941 return 0; 941 return 0;
942} 942}
943 943
944static DEF_SCSI_QCMD(esp_queuecommand)
945
944static int esp_check_gross_error(struct esp *esp) 946static int esp_check_gross_error(struct esp *esp)
945{ 947{
946 if (esp->sreg & ESP_STAT_SPAM) { 948 if (esp->sreg & ESP_STAT_SPAM) {
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 844d618b84bd..d23a538a9dfc 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -117,7 +117,7 @@ static void fcoe_recv_frame(struct sk_buff *skb);
117 117
118static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *); 118static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *);
119 119
120module_param_call(create, fcoe_create, NULL, (void *)FIP_MODE_AUTO, S_IWUSR); 120module_param_call(create, fcoe_create, NULL, (void *)FIP_MODE_FABRIC, S_IWUSR);
121__MODULE_PARM_TYPE(create, "string"); 121__MODULE_PARM_TYPE(create, "string");
122MODULE_PARM_DESC(create, " Creates fcoe instance on a ethernet interface"); 122MODULE_PARM_DESC(create, " Creates fcoe instance on a ethernet interface");
123module_param_call(create_vn2vn, fcoe_create, NULL, 123module_param_call(create_vn2vn, fcoe_create, NULL,
@@ -1243,7 +1243,6 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
1243 struct fcoe_interface *fcoe; 1243 struct fcoe_interface *fcoe;
1244 struct fc_frame_header *fh; 1244 struct fc_frame_header *fh;
1245 struct fcoe_percpu_s *fps; 1245 struct fcoe_percpu_s *fps;
1246 struct fcoe_port *port;
1247 struct ethhdr *eh; 1246 struct ethhdr *eh;
1248 unsigned int cpu; 1247 unsigned int cpu;
1249 1248
@@ -1262,16 +1261,7 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
1262 skb_tail_pointer(skb), skb_end_pointer(skb), 1261 skb_tail_pointer(skb), skb_end_pointer(skb),
1263 skb->csum, skb->dev ? skb->dev->name : "<NULL>"); 1262 skb->csum, skb->dev ? skb->dev->name : "<NULL>");
1264 1263
1265 /* check for mac addresses */
1266 eh = eth_hdr(skb); 1264 eh = eth_hdr(skb);
1267 port = lport_priv(lport);
1268 if (compare_ether_addr(eh->h_dest, port->data_src_addr) &&
1269 compare_ether_addr(eh->h_dest, fcoe->ctlr.ctl_src_addr) &&
1270 compare_ether_addr(eh->h_dest, (u8[6])FC_FCOE_FLOGI_MAC)) {
1271 FCOE_NETDEV_DBG(netdev, "wrong destination mac address:%pM\n",
1272 eh->h_dest);
1273 goto err;
1274 }
1275 1265
1276 if (is_fip_mode(&fcoe->ctlr) && 1266 if (is_fip_mode(&fcoe->ctlr) &&
1277 compare_ether_addr(eh->h_source, fcoe->ctlr.dest_addr)) { 1267 compare_ether_addr(eh->h_source, fcoe->ctlr.dest_addr)) {
@@ -1291,6 +1281,12 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
1291 skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); 1281 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
1292 fh = (struct fc_frame_header *) skb_transport_header(skb); 1282 fh = (struct fc_frame_header *) skb_transport_header(skb);
1293 1283
1284 if (ntoh24(&eh->h_dest[3]) != ntoh24(fh->fh_d_id)) {
1285 FCOE_NETDEV_DBG(netdev, "FC frame d_id mismatch with MAC:%pM\n",
1286 eh->h_dest);
1287 goto err;
1288 }
1289
1294 fr = fcoe_dev_from_skb(skb); 1290 fr = fcoe_dev_from_skb(skb);
1295 fr->fr_dev = lport; 1291 fr->fr_dev = lport;
1296 fr->ptype = ptype; 1292 fr->ptype = ptype;
diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
index aa503d83092a..bc17c7123202 100644
--- a/drivers/scsi/fcoe/libfcoe.c
+++ b/drivers/scsi/fcoe/libfcoe.c
@@ -2296,7 +2296,7 @@ static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
2296{ 2296{
2297 struct fip_header *fiph; 2297 struct fip_header *fiph;
2298 enum fip_vn2vn_subcode sub; 2298 enum fip_vn2vn_subcode sub;
2299 union { 2299 struct {
2300 struct fc_rport_priv rdata; 2300 struct fc_rport_priv rdata;
2301 struct fcoe_rport frport; 2301 struct fcoe_rport frport;
2302 } buf; 2302 } buf;
diff --git a/drivers/scsi/fd_mcs.c b/drivers/scsi/fd_mcs.c
index 2ad95aa8f585..a2c6135d337e 100644
--- a/drivers/scsi/fd_mcs.c
+++ b/drivers/scsi/fd_mcs.c
@@ -1072,7 +1072,7 @@ static int fd_mcs_release(struct Scsi_Host *shpnt)
1072 return 0; 1072 return 0;
1073} 1073}
1074 1074
1075static int fd_mcs_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *)) 1075static int fd_mcs_queue_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
1076{ 1076{
1077 struct Scsi_Host *shpnt = SCpnt->device->host; 1077 struct Scsi_Host *shpnt = SCpnt->device->host;
1078 1078
@@ -1122,6 +1122,8 @@ static int fd_mcs_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
1122 return 0; 1122 return 0;
1123} 1123}
1124 1124
1125static DEF_SCSI_QCMD(fd_mcs_queue)
1126
1125#if DEBUG_ABORT || DEBUG_RESET 1127#if DEBUG_ABORT || DEBUG_RESET
1126static void fd_mcs_print_info(Scsi_Cmnd * SCpnt) 1128static void fd_mcs_print_info(Scsi_Cmnd * SCpnt)
1127{ 1129{
diff --git a/drivers/scsi/fdomain.c b/drivers/scsi/fdomain.c
index e296bcc57d5c..69b7aa54f43f 100644
--- a/drivers/scsi/fdomain.c
+++ b/drivers/scsi/fdomain.c
@@ -1419,7 +1419,7 @@ static irqreturn_t do_fdomain_16x0_intr(int irq, void *dev_id)
1419 return IRQ_HANDLED; 1419 return IRQ_HANDLED;
1420} 1420}
1421 1421
1422static int fdomain_16x0_queue(struct scsi_cmnd *SCpnt, 1422static int fdomain_16x0_queue_lck(struct scsi_cmnd *SCpnt,
1423 void (*done)(struct scsi_cmnd *)) 1423 void (*done)(struct scsi_cmnd *))
1424{ 1424{
1425 if (in_command) { 1425 if (in_command) {
@@ -1469,6 +1469,8 @@ static int fdomain_16x0_queue(struct scsi_cmnd *SCpnt,
1469 return 0; 1469 return 0;
1470} 1470}
1471 1471
1472static DEF_SCSI_QCMD(fdomain_16x0_queue)
1473
1472#if DEBUG_ABORT 1474#if DEBUG_ABORT
1473static void print_info(struct scsi_cmnd *SCpnt) 1475static void print_info(struct scsi_cmnd *SCpnt)
1474{ 1476{
diff --git a/drivers/scsi/fnic/fnic.h b/drivers/scsi/fnic/fnic.h
index cbb20b13b228..92f185081e62 100644
--- a/drivers/scsi/fnic/fnic.h
+++ b/drivers/scsi/fnic/fnic.h
@@ -246,7 +246,7 @@ void fnic_set_port_id(struct fc_lport *, u32, struct fc_frame *);
246void fnic_update_mac(struct fc_lport *, u8 *new); 246void fnic_update_mac(struct fc_lport *, u8 *new);
247void fnic_update_mac_locked(struct fnic *, u8 *new); 247void fnic_update_mac_locked(struct fnic *, u8 *new);
248 248
249int fnic_queuecommand(struct scsi_cmnd *, void (*done)(struct scsi_cmnd *)); 249int fnic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
250int fnic_abort_cmd(struct scsi_cmnd *); 250int fnic_abort_cmd(struct scsi_cmnd *);
251int fnic_device_reset(struct scsi_cmnd *); 251int fnic_device_reset(struct scsi_cmnd *);
252int fnic_host_reset(struct scsi_cmnd *); 252int fnic_host_reset(struct scsi_cmnd *);
diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index 198cbab3e894..22d02404d15f 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -349,7 +349,7 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
349 * Routine to send a scsi cdb 349 * Routine to send a scsi cdb
350 * Called with host_lock held and interrupts disabled. 350 * Called with host_lock held and interrupts disabled.
351 */ 351 */
352int fnic_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) 352static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
353{ 353{
354 struct fc_lport *lp; 354 struct fc_lport *lp;
355 struct fc_rport *rport; 355 struct fc_rport *rport;
@@ -457,6 +457,8 @@ out:
457 return ret; 457 return ret;
458} 458}
459 459
460DEF_SCSI_QCMD(fnic_queuecommand)
461
460/* 462/*
461 * fnic_fcpio_fw_reset_cmpl_handler 463 * fnic_fcpio_fw_reset_cmpl_handler
462 * Routine to handle fw reset completion 464 * Routine to handle fw reset completion
diff --git a/drivers/scsi/g_NCR5380.h b/drivers/scsi/g_NCR5380.h
index 921764c9ab24..1bcdb7beb77b 100644
--- a/drivers/scsi/g_NCR5380.h
+++ b/drivers/scsi/g_NCR5380.h
@@ -46,7 +46,7 @@
46static int generic_NCR5380_abort(Scsi_Cmnd *); 46static int generic_NCR5380_abort(Scsi_Cmnd *);
47static int generic_NCR5380_detect(struct scsi_host_template *); 47static int generic_NCR5380_detect(struct scsi_host_template *);
48static int generic_NCR5380_release_resources(struct Scsi_Host *); 48static int generic_NCR5380_release_resources(struct Scsi_Host *);
49static int generic_NCR5380_queue_command(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *)); 49static int generic_NCR5380_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
50static int generic_NCR5380_bus_reset(Scsi_Cmnd *); 50static int generic_NCR5380_bus_reset(Scsi_Cmnd *);
51static const char* generic_NCR5380_info(struct Scsi_Host *); 51static const char* generic_NCR5380_info(struct Scsi_Host *);
52 52
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 5a3f93101017..76365700e2d5 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -185,7 +185,7 @@ static long gdth_unlocked_ioctl(struct file *filep, unsigned int cmd,
185 unsigned long arg); 185 unsigned long arg);
186 186
187static void gdth_flush(gdth_ha_str *ha); 187static void gdth_flush(gdth_ha_str *ha);
188static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *)); 188static int gdth_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
189static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp, 189static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp,
190 struct gdth_cmndinfo *cmndinfo); 190 struct gdth_cmndinfo *cmndinfo);
191static void gdth_scsi_done(struct scsi_cmnd *scp); 191static void gdth_scsi_done(struct scsi_cmnd *scp);
@@ -4004,7 +4004,7 @@ static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,se
4004} 4004}
4005 4005
4006 4006
4007static int gdth_queuecommand(struct scsi_cmnd *scp, 4007static int gdth_queuecommand_lck(struct scsi_cmnd *scp,
4008 void (*done)(struct scsi_cmnd *)) 4008 void (*done)(struct scsi_cmnd *))
4009{ 4009{
4010 gdth_ha_str *ha = shost_priv(scp->device->host); 4010 gdth_ha_str *ha = shost_priv(scp->device->host);
@@ -4022,6 +4022,8 @@ static int gdth_queuecommand(struct scsi_cmnd *scp,
4022 return __gdth_queuecommand(ha, scp, cmndinfo); 4022 return __gdth_queuecommand(ha, scp, cmndinfo);
4023} 4023}
4024 4024
4025static DEF_SCSI_QCMD(gdth_queuecommand)
4026
4025static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp, 4027static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp,
4026 struct gdth_cmndinfo *cmndinfo) 4028 struct gdth_cmndinfo *cmndinfo)
4027{ 4029{
@@ -4177,6 +4179,14 @@ static int ioc_general(void __user *arg, char *cmnd)
4177 ha = gdth_find_ha(gen.ionode); 4179 ha = gdth_find_ha(gen.ionode);
4178 if (!ha) 4180 if (!ha)
4179 return -EFAULT; 4181 return -EFAULT;
4182
4183 if (gen.data_len > INT_MAX)
4184 return -EINVAL;
4185 if (gen.sense_len > INT_MAX)
4186 return -EINVAL;
4187 if (gen.data_len + gen.sense_len > INT_MAX)
4188 return -EINVAL;
4189
4180 if (gen.data_len + gen.sense_len != 0) { 4190 if (gen.data_len + gen.sense_len != 0) {
4181 if (!(buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len, 4191 if (!(buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len,
4182 FALSE, &paddr))) 4192 FALSE, &paddr)))
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index c5d0606ad097..a6dea08664fc 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -31,7 +31,6 @@
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/smp_lock.h>
35#include <linux/compat.h> 34#include <linux/compat.h>
36#include <linux/blktrace_api.h> 35#include <linux/blktrace_api.h>
37#include <linux/uaccess.h> 36#include <linux/uaccess.h>
@@ -91,11 +90,7 @@ static const struct pci_device_id hpsa_pci_device_id[] = {
91 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3252}, 90 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3252},
92 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3253}, 91 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3253},
93 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3254}, 92 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3254},
94#define PCI_DEVICE_ID_HP_CISSF 0x333f 93 {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
95 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x333F},
96 {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
97 PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0},
98 {PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
99 PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0}, 94 PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0},
100 {0,} 95 {0,}
101}; 96};
@@ -114,8 +109,6 @@ static struct board_type products[] = {
114 {0x3249103C, "Smart Array P812", &SA5_access}, 109 {0x3249103C, "Smart Array P812", &SA5_access},
115 {0x324a103C, "Smart Array P712m", &SA5_access}, 110 {0x324a103C, "Smart Array P712m", &SA5_access},
116 {0x324b103C, "Smart Array P711m", &SA5_access}, 111 {0x324b103C, "Smart Array P711m", &SA5_access},
117 {0x3233103C, "StorageWorks P1210m", &SA5_access},
118 {0x333F103C, "StorageWorks P1210m", &SA5_access},
119 {0x3250103C, "Smart Array", &SA5_access}, 112 {0x3250103C, "Smart Array", &SA5_access},
120 {0x3250113C, "Smart Array", &SA5_access}, 113 {0x3250113C, "Smart Array", &SA5_access},
121 {0x3250123C, "Smart Array", &SA5_access}, 114 {0x3250123C, "Smart Array", &SA5_access},
@@ -143,8 +136,7 @@ static void fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
143 void *buff, size_t size, u8 page_code, unsigned char *scsi3addr, 136 void *buff, size_t size, u8 page_code, unsigned char *scsi3addr,
144 int cmd_type); 137 int cmd_type);
145 138
146static int hpsa_scsi_queue_command(struct scsi_cmnd *cmd, 139static int hpsa_scsi_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd);
147 void (*done)(struct scsi_cmnd *));
148static void hpsa_scan_start(struct Scsi_Host *); 140static void hpsa_scan_start(struct Scsi_Host *);
149static int hpsa_scan_finished(struct Scsi_Host *sh, 141static int hpsa_scan_finished(struct Scsi_Host *sh,
150 unsigned long elapsed_time); 142 unsigned long elapsed_time);
@@ -1926,7 +1918,7 @@ sglist_finished:
1926} 1918}
1927 1919
1928 1920
1929static int hpsa_scsi_queue_command(struct scsi_cmnd *cmd, 1921static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
1930 void (*done)(struct scsi_cmnd *)) 1922 void (*done)(struct scsi_cmnd *))
1931{ 1923{
1932 struct ctlr_info *h; 1924 struct ctlr_info *h;
@@ -2020,6 +2012,8 @@ static int hpsa_scsi_queue_command(struct scsi_cmnd *cmd,
2020 return 0; 2012 return 0;
2021} 2013}
2022 2014
2015static DEF_SCSI_QCMD(hpsa_scsi_queue_command)
2016
2023static void hpsa_scan_start(struct Scsi_Host *sh) 2017static void hpsa_scan_start(struct Scsi_Host *sh)
2024{ 2018{
2025 struct ctlr_info *h = shost_to_hba(sh); 2019 struct ctlr_info *h = shost_to_hba(sh);
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index 0729f150b33a..10b65556937b 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -751,7 +751,7 @@ static void hptiop_post_req_mv(struct hptiop_hba *hba,
751 MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba); 751 MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
752} 752}
753 753
754static int hptiop_queuecommand(struct scsi_cmnd *scp, 754static int hptiop_queuecommand_lck(struct scsi_cmnd *scp,
755 void (*done)(struct scsi_cmnd *)) 755 void (*done)(struct scsi_cmnd *))
756{ 756{
757 struct Scsi_Host *host = scp->device->host; 757 struct Scsi_Host *host = scp->device->host;
@@ -819,6 +819,8 @@ cmd_done:
819 return 0; 819 return 0;
820} 820}
821 821
822static DEF_SCSI_QCMD(hptiop_queuecommand)
823
822static const char *hptiop_info(struct Scsi_Host *host) 824static const char *hptiop_info(struct Scsi_Host *host)
823{ 825{
824 return driver_name_long; 826 return driver_name_long;
diff --git a/drivers/scsi/ibmmca.c b/drivers/scsi/ibmmca.c
index 9a4b69d4f4eb..67fc8ffd52e6 100644
--- a/drivers/scsi/ibmmca.c
+++ b/drivers/scsi/ibmmca.c
@@ -39,7 +39,7 @@
39#include <scsi/scsi_host.h> 39#include <scsi/scsi_host.h>
40 40
41/* Common forward declarations for all Linux-versions: */ 41/* Common forward declarations for all Linux-versions: */
42static int ibmmca_queuecommand (Scsi_Cmnd *, void (*done) (Scsi_Cmnd *)); 42static int ibmmca_queuecommand (struct Scsi_Host *, struct scsi_cmnd *);
43static int ibmmca_abort (Scsi_Cmnd *); 43static int ibmmca_abort (Scsi_Cmnd *);
44static int ibmmca_host_reset (Scsi_Cmnd *); 44static int ibmmca_host_reset (Scsi_Cmnd *);
45static int ibmmca_biosparam (struct scsi_device *, struct block_device *, sector_t, int *); 45static int ibmmca_biosparam (struct scsi_device *, struct block_device *, sector_t, int *);
@@ -1691,7 +1691,7 @@ static int __devexit ibmmca_remove(struct device *dev)
1691} 1691}
1692 1692
1693/* The following routine is the SCSI command queue for the midlevel driver */ 1693/* The following routine is the SCSI command queue for the midlevel driver */
1694static int ibmmca_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) 1694static int ibmmca_queuecommand_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
1695{ 1695{
1696 unsigned int ldn; 1696 unsigned int ldn;
1697 unsigned int scsi_cmd; 1697 unsigned int scsi_cmd;
@@ -1996,6 +1996,8 @@ static int ibmmca_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
1996 return 0; 1996 return 0;
1997} 1997}
1998 1998
1999static DEF_SCSI_QCMD(ibmmca_queuecommand)
2000
1999static int __ibmmca_abort(Scsi_Cmnd * cmd) 2001static int __ibmmca_abort(Scsi_Cmnd * cmd)
2000{ 2002{
2001 /* Abort does not work, as the adapter never generates an interrupt on 2003 /* Abort does not work, as the adapter never generates an interrupt on
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 00d08b25425f..57cad7e20caa 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1606,7 +1606,7 @@ static inline int ibmvfc_host_chkready(struct ibmvfc_host *vhost)
1606 * Returns: 1606 * Returns:
1607 * 0 on success / other on failure 1607 * 0 on success / other on failure
1608 **/ 1608 **/
1609static int ibmvfc_queuecommand(struct scsi_cmnd *cmnd, 1609static int ibmvfc_queuecommand_lck(struct scsi_cmnd *cmnd,
1610 void (*done) (struct scsi_cmnd *)) 1610 void (*done) (struct scsi_cmnd *))
1611{ 1611{
1612 struct ibmvfc_host *vhost = shost_priv(cmnd->device->host); 1612 struct ibmvfc_host *vhost = shost_priv(cmnd->device->host);
@@ -1672,6 +1672,8 @@ static int ibmvfc_queuecommand(struct scsi_cmnd *cmnd,
1672 return 0; 1672 return 0;
1673} 1673}
1674 1674
1675static DEF_SCSI_QCMD(ibmvfc_queuecommand)
1676
1675/** 1677/**
1676 * ibmvfc_sync_completion - Signal that a synchronous command has completed 1678 * ibmvfc_sync_completion - Signal that a synchronous command has completed
1677 * @evt: ibmvfc event struct 1679 * @evt: ibmvfc event struct
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 67f78a470f5f..041958453e2a 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -713,7 +713,7 @@ static inline u16 lun_from_dev(struct scsi_device *dev)
713 * @cmd: struct scsi_cmnd to be executed 713 * @cmd: struct scsi_cmnd to be executed
714 * @done: Callback function to be called when cmd is completed 714 * @done: Callback function to be called when cmd is completed
715*/ 715*/
716static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd, 716static int ibmvscsi_queuecommand_lck(struct scsi_cmnd *cmnd,
717 void (*done) (struct scsi_cmnd *)) 717 void (*done) (struct scsi_cmnd *))
718{ 718{
719 struct srp_cmd *srp_cmd; 719 struct srp_cmd *srp_cmd;
@@ -766,6 +766,8 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
766 return ibmvscsi_send_srp_event(evt_struct, hostdata, 0); 766 return ibmvscsi_send_srp_event(evt_struct, hostdata, 0);
767} 767}
768 768
769static DEF_SCSI_QCMD(ibmvscsi_queuecommand)
770
769/* ------------------------------------------------------------ 771/* ------------------------------------------------------------
770 * Routines for driver initialization 772 * Routines for driver initialization
771 */ 773 */
diff --git a/drivers/scsi/imm.c b/drivers/scsi/imm.c
index 4734ab0b3ff6..99aa0e5699bc 100644
--- a/drivers/scsi/imm.c
+++ b/drivers/scsi/imm.c
@@ -926,7 +926,7 @@ static int imm_engine(imm_struct *dev, struct scsi_cmnd *cmd)
926 return 0; 926 return 0;
927} 927}
928 928
929static int imm_queuecommand(struct scsi_cmnd *cmd, 929static int imm_queuecommand_lck(struct scsi_cmnd *cmd,
930 void (*done)(struct scsi_cmnd *)) 930 void (*done)(struct scsi_cmnd *))
931{ 931{
932 imm_struct *dev = imm_dev(cmd->device->host); 932 imm_struct *dev = imm_dev(cmd->device->host);
@@ -949,6 +949,8 @@ static int imm_queuecommand(struct scsi_cmnd *cmd,
949 return 0; 949 return 0;
950} 950}
951 951
952static DEF_SCSI_QCMD(imm_queuecommand)
953
952/* 954/*
953 * Apparently the disk->capacity attribute is off by 1 sector 955 * Apparently the disk->capacity attribute is off by 1 sector
954 * for all disk drives. We add the one here, but it should really 956 * for all disk drives. We add the one here, but it should really
diff --git a/drivers/scsi/in2000.c b/drivers/scsi/in2000.c
index 52bdc6df6b92..6568aab745a0 100644
--- a/drivers/scsi/in2000.c
+++ b/drivers/scsi/in2000.c
@@ -334,7 +334,7 @@ static uchar calc_sync_xfer(unsigned int period, unsigned int offset)
334 334
335static void in2000_execute(struct Scsi_Host *instance); 335static void in2000_execute(struct Scsi_Host *instance);
336 336
337static int in2000_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) 337static int in2000_queuecommand_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
338{ 338{
339 struct Scsi_Host *instance; 339 struct Scsi_Host *instance;
340 struct IN2000_hostdata *hostdata; 340 struct IN2000_hostdata *hostdata;
@@ -431,6 +431,8 @@ static int in2000_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
431 return 0; 431 return 0;
432} 432}
433 433
434static DEF_SCSI_QCMD(in2000_queuecommand)
435
434 436
435 437
436/* 438/*
diff --git a/drivers/scsi/in2000.h b/drivers/scsi/in2000.h
index 0fb8b06b8392..5821e1fbce08 100644
--- a/drivers/scsi/in2000.h
+++ b/drivers/scsi/in2000.h
@@ -396,7 +396,7 @@ struct IN2000_hostdata {
396 flags) 396 flags)
397 397
398static int in2000_detect(struct scsi_host_template *) in2000__INIT; 398static int in2000_detect(struct scsi_host_template *) in2000__INIT;
399static int in2000_queuecommand(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *)); 399static int in2000_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
400static int in2000_abort(Scsi_Cmnd *); 400static int in2000_abort(Scsi_Cmnd *);
401static void in2000_setup(char *, int *) in2000__INIT; 401static void in2000_setup(char *, int *) in2000__INIT;
402static int in2000_biosparam(struct scsi_device *, struct block_device *, 402static int in2000_biosparam(struct scsi_device *, struct block_device *,
diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index 108797761b95..9627d062e16b 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -2639,7 +2639,7 @@ static void initio_build_scb(struct initio_host * host, struct scsi_ctrl_blk * c
2639 * will cause the mid layer to call us again later with the command) 2639 * will cause the mid layer to call us again later with the command)
2640 */ 2640 */
2641 2641
2642static int i91u_queuecommand(struct scsi_cmnd *cmd, 2642static int i91u_queuecommand_lck(struct scsi_cmnd *cmd,
2643 void (*done)(struct scsi_cmnd *)) 2643 void (*done)(struct scsi_cmnd *))
2644{ 2644{
2645 struct initio_host *host = (struct initio_host *) cmd->device->host->hostdata; 2645 struct initio_host *host = (struct initio_host *) cmd->device->host->hostdata;
@@ -2656,6 +2656,8 @@ static int i91u_queuecommand(struct scsi_cmnd *cmd,
2656 return 0; 2656 return 0;
2657} 2657}
2658 2658
2659static DEF_SCSI_QCMD(i91u_queuecommand)
2660
2659/** 2661/**
2660 * i91u_bus_reset - reset the SCSI bus 2662 * i91u_bus_reset - reset the SCSI bus
2661 * @cmnd: Command block we want to trigger the reset for 2663 * @cmnd: Command block we want to trigger the reset for
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index df9a12c8b373..5bbaee597e88 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -5709,7 +5709,7 @@ static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
5709 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy 5709 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
5710 * SCSI_MLQUEUE_HOST_BUSY if host is busy 5710 * SCSI_MLQUEUE_HOST_BUSY if host is busy
5711 **/ 5711 **/
5712static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd, 5712static int ipr_queuecommand_lck(struct scsi_cmnd *scsi_cmd,
5713 void (*done) (struct scsi_cmnd *)) 5713 void (*done) (struct scsi_cmnd *))
5714{ 5714{
5715 struct ipr_ioa_cfg *ioa_cfg; 5715 struct ipr_ioa_cfg *ioa_cfg;
@@ -5792,6 +5792,8 @@ static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
5792 return 0; 5792 return 0;
5793} 5793}
5794 5794
5795static DEF_SCSI_QCMD(ipr_queuecommand)
5796
5795/** 5797/**
5796 * ipr_ioctl - IOCTL handler 5798 * ipr_ioctl - IOCTL handler
5797 * @sdev: scsi device struct 5799 * @sdev: scsi device struct
@@ -9025,6 +9027,8 @@ static struct pci_device_id ipr_pci_table[] __devinitdata = {
9025 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 }, 9027 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
9026 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, 9028 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9027 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 }, 9029 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
9030 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9031 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
9028 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_ASIC_E2, 9032 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_ASIC_E2,
9029 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 }, 9033 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
9030 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_ASIC_E2, 9034 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_ASIC_E2,
diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h
index aa8bb2f2c6ee..b28a00f1082c 100644
--- a/drivers/scsi/ipr.h
+++ b/drivers/scsi/ipr.h
@@ -82,6 +82,7 @@
82 82
83#define IPR_SUBS_DEV_ID_57B4 0x033B 83#define IPR_SUBS_DEV_ID_57B4 0x033B
84#define IPR_SUBS_DEV_ID_57B2 0x035F 84#define IPR_SUBS_DEV_ID_57B2 0x035F
85#define IPR_SUBS_DEV_ID_57C4 0x0354
85#define IPR_SUBS_DEV_ID_57C6 0x0357 86#define IPR_SUBS_DEV_ID_57C6 0x0357
86#define IPR_SUBS_DEV_ID_57CC 0x035C 87#define IPR_SUBS_DEV_ID_57CC 0x035C
87 88
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index f83a116955f2..b2511acd39bd 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -232,7 +232,7 @@ static int ips_detect(struct scsi_host_template *);
232static int ips_release(struct Scsi_Host *); 232static int ips_release(struct Scsi_Host *);
233static int ips_eh_abort(struct scsi_cmnd *); 233static int ips_eh_abort(struct scsi_cmnd *);
234static int ips_eh_reset(struct scsi_cmnd *); 234static int ips_eh_reset(struct scsi_cmnd *);
235static int ips_queue(struct scsi_cmnd *, void (*)(struct scsi_cmnd *)); 235static int ips_queue(struct Scsi_Host *, struct scsi_cmnd *);
236static const char *ips_info(struct Scsi_Host *); 236static const char *ips_info(struct Scsi_Host *);
237static irqreturn_t do_ipsintr(int, void *); 237static irqreturn_t do_ipsintr(int, void *);
238static int ips_hainit(ips_ha_t *); 238static int ips_hainit(ips_ha_t *);
@@ -1046,7 +1046,7 @@ static int ips_eh_reset(struct scsi_cmnd *SC)
1046/* Linux obtains io_request_lock before calling this function */ 1046/* Linux obtains io_request_lock before calling this function */
1047/* */ 1047/* */
1048/****************************************************************************/ 1048/****************************************************************************/
1049static int ips_queue(struct scsi_cmnd *SC, void (*done) (struct scsi_cmnd *)) 1049static int ips_queue_lck(struct scsi_cmnd *SC, void (*done) (struct scsi_cmnd *))
1050{ 1050{
1051 ips_ha_t *ha; 1051 ips_ha_t *ha;
1052 ips_passthru_t *pt; 1052 ips_passthru_t *pt;
@@ -1137,6 +1137,8 @@ static int ips_queue(struct scsi_cmnd *SC, void (*done) (struct scsi_cmnd *))
1137 return (0); 1137 return (0);
1138} 1138}
1139 1139
1140static DEF_SCSI_QCMD(ips_queue)
1141
1140/****************************************************************************/ 1142/****************************************************************************/
1141/* */ 1143/* */
1142/* Routine Name: ips_biosparam */ 1144/* Routine Name: ips_biosparam */
diff --git a/drivers/scsi/libfc/fc_disc.c b/drivers/scsi/libfc/fc_disc.c
index 32f67c4b03fc..911b2736cafa 100644
--- a/drivers/scsi/libfc/fc_disc.c
+++ b/drivers/scsi/libfc/fc_disc.c
@@ -684,10 +684,9 @@ void fc_disc_stop(struct fc_lport *lport)
684{ 684{
685 struct fc_disc *disc = &lport->disc; 685 struct fc_disc *disc = &lport->disc;
686 686
687 if (disc) { 687 if (disc->pending)
688 cancel_delayed_work_sync(&disc->disc_work); 688 cancel_delayed_work_sync(&disc->disc_work);
689 fc_disc_stop_rports(disc); 689 fc_disc_stop_rports(disc);
690 }
691} 690}
692 691
693/** 692/**
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 54a6ec8e131d..071cf082d342 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -58,8 +58,7 @@ struct kmem_cache *scsi_pkt_cachep;
58#define FC_SRB_WRITE (1 << 0) 58#define FC_SRB_WRITE (1 << 0)
59 59
60/* 60/*
61 * The SCp.ptr should be tested and set under the host lock. NULL indicates 61 * The SCp.ptr should be tested and set under the scsi_pkt_queue lock
62 * that the command has been retruned to the scsi layer.
63 */ 62 */
64#define CMD_SP(Cmnd) ((struct fc_fcp_pkt *)(Cmnd)->SCp.ptr) 63#define CMD_SP(Cmnd) ((struct fc_fcp_pkt *)(Cmnd)->SCp.ptr)
65#define CMD_ENTRY_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in) 64#define CMD_ENTRY_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in)
@@ -1754,7 +1753,7 @@ static inline int fc_fcp_lport_queue_ready(struct fc_lport *lport)
1754 * This is the i/o strategy routine, called by the SCSI layer. This routine 1753 * This is the i/o strategy routine, called by the SCSI layer. This routine
1755 * is called with the host_lock held. 1754 * is called with the host_lock held.
1756 */ 1755 */
1757int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) 1756static int fc_queuecommand_lck(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *))
1758{ 1757{
1759 struct fc_lport *lport; 1758 struct fc_lport *lport;
1760 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); 1759 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
@@ -1852,6 +1851,8 @@ out:
1852 spin_lock_irq(lport->host->host_lock); 1851 spin_lock_irq(lport->host->host_lock);
1853 return rc; 1852 return rc;
1854} 1853}
1854
1855DEF_SCSI_QCMD(fc_queuecommand)
1855EXPORT_SYMBOL(fc_queuecommand); 1856EXPORT_SYMBOL(fc_queuecommand);
1856 1857
1857/** 1858/**
@@ -1880,8 +1881,6 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp)
1880 1881
1881 lport = fsp->lp; 1882 lport = fsp->lp;
1882 si = fc_get_scsi_internal(lport); 1883 si = fc_get_scsi_internal(lport);
1883 if (!fsp->cmd)
1884 return;
1885 1884
1886 /* 1885 /*
1887 * if can_queue ramp down is done then try can_queue ramp up 1886 * if can_queue ramp down is done then try can_queue ramp up
@@ -1891,11 +1890,6 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp)
1891 fc_fcp_can_queue_ramp_up(lport); 1890 fc_fcp_can_queue_ramp_up(lport);
1892 1891
1893 sc_cmd = fsp->cmd; 1892 sc_cmd = fsp->cmd;
1894 fsp->cmd = NULL;
1895
1896 if (!sc_cmd->SCp.ptr)
1897 return;
1898
1899 CMD_SCSI_STATUS(sc_cmd) = fsp->cdb_status; 1893 CMD_SCSI_STATUS(sc_cmd) = fsp->cdb_status;
1900 switch (fsp->status_code) { 1894 switch (fsp->status_code) {
1901 case FC_COMPLETE: 1895 case FC_COMPLETE:
@@ -1971,15 +1965,13 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp)
1971 break; 1965 break;
1972 } 1966 }
1973 1967
1974 if (lport->state != LPORT_ST_READY && fsp->status_code != FC_COMPLETE) { 1968 if (lport->state != LPORT_ST_READY && fsp->status_code != FC_COMPLETE)
1975 sc_cmd->result = (DID_REQUEUE << 16); 1969 sc_cmd->result = (DID_TRANSPORT_DISRUPTED << 16);
1976 FC_FCP_DBG(fsp, "Returning DID_REQUEUE to scsi-ml\n");
1977 }
1978 1970
1979 spin_lock_irqsave(&si->scsi_queue_lock, flags); 1971 spin_lock_irqsave(&si->scsi_queue_lock, flags);
1980 list_del(&fsp->list); 1972 list_del(&fsp->list);
1981 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
1982 sc_cmd->SCp.ptr = NULL; 1973 sc_cmd->SCp.ptr = NULL;
1974 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
1983 sc_cmd->scsi_done(sc_cmd); 1975 sc_cmd->scsi_done(sc_cmd);
1984 1976
1985 /* release ref from initial allocation in queue command */ 1977 /* release ref from initial allocation in queue command */
@@ -1997,6 +1989,7 @@ int fc_eh_abort(struct scsi_cmnd *sc_cmd)
1997{ 1989{
1998 struct fc_fcp_pkt *fsp; 1990 struct fc_fcp_pkt *fsp;
1999 struct fc_lport *lport; 1991 struct fc_lport *lport;
1992 struct fc_fcp_internal *si;
2000 int rc = FAILED; 1993 int rc = FAILED;
2001 unsigned long flags; 1994 unsigned long flags;
2002 1995
@@ -2006,7 +1999,8 @@ int fc_eh_abort(struct scsi_cmnd *sc_cmd)
2006 else if (!lport->link_up) 1999 else if (!lport->link_up)
2007 return rc; 2000 return rc;
2008 2001
2009 spin_lock_irqsave(lport->host->host_lock, flags); 2002 si = fc_get_scsi_internal(lport);
2003 spin_lock_irqsave(&si->scsi_queue_lock, flags);
2010 fsp = CMD_SP(sc_cmd); 2004 fsp = CMD_SP(sc_cmd);
2011 if (!fsp) { 2005 if (!fsp) {
2012 /* command completed while scsi eh was setting up */ 2006 /* command completed while scsi eh was setting up */
@@ -2015,7 +2009,7 @@ int fc_eh_abort(struct scsi_cmnd *sc_cmd)
2015 } 2009 }
2016 /* grab a ref so the fsp and sc_cmd cannot be relased from under us */ 2010 /* grab a ref so the fsp and sc_cmd cannot be relased from under us */
2017 fc_fcp_pkt_hold(fsp); 2011 fc_fcp_pkt_hold(fsp);
2018 spin_unlock_irqrestore(lport->host->host_lock, flags); 2012 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
2019 2013
2020 if (fc_fcp_lock_pkt(fsp)) { 2014 if (fc_fcp_lock_pkt(fsp)) {
2021 /* completed while we were waiting for timer to be deleted */ 2015 /* completed while we were waiting for timer to be deleted */
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index d9b6e11b0e88..9be63edbf8fb 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1447,13 +1447,7 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1447 } 1447 }
1448 1448
1449 did = fc_frame_did(fp); 1449 did = fc_frame_did(fp);
1450 1450 if (fc_frame_payload_op(fp) == ELS_LS_ACC && did) {
1451 if (!did) {
1452 FC_LPORT_DBG(lport, "Bad FLOGI response\n");
1453 goto out;
1454 }
1455
1456 if (fc_frame_payload_op(fp) == ELS_LS_ACC) {
1457 flp = fc_frame_payload_get(fp, sizeof(*flp)); 1451 flp = fc_frame_payload_get(fp, sizeof(*flp));
1458 if (flp) { 1452 if (flp) {
1459 mfs = ntohs(flp->fl_csp.sp_bb_data) & 1453 mfs = ntohs(flp->fl_csp.sp_bb_data) &
@@ -1492,8 +1486,10 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1492 fc_lport_enter_dns(lport); 1486 fc_lport_enter_dns(lport);
1493 } 1487 }
1494 } 1488 }
1495 } else 1489 } else {
1490 FC_LPORT_DBG(lport, "FLOGI RJT or bad response\n");
1496 fc_lport_error(lport, fp); 1491 fc_lport_error(lport, fp);
1492 }
1497 1493
1498out: 1494out:
1499 fc_frame_free(fp); 1495 fc_frame_free(fp);
diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index b9f2286fe0cb..a84ef13ed74a 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -196,9 +196,9 @@ static const char *fc_rport_state(struct fc_rport_priv *rdata)
196void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) 196void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
197{ 197{
198 if (timeout) 198 if (timeout)
199 rport->dev_loss_tmo = timeout + 5; 199 rport->dev_loss_tmo = timeout;
200 else 200 else
201 rport->dev_loss_tmo = 30; 201 rport->dev_loss_tmo = 1;
202} 202}
203EXPORT_SYMBOL(fc_set_rport_loss_tmo); 203EXPORT_SYMBOL(fc_set_rport_loss_tmo);
204 204
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 633e09036357..c15fde808c33 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -1599,7 +1599,7 @@ enum {
1599 FAILURE_SESSION_NOT_READY, 1599 FAILURE_SESSION_NOT_READY,
1600}; 1600};
1601 1601
1602int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) 1602static int iscsi_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1603{ 1603{
1604 struct iscsi_cls_session *cls_session; 1604 struct iscsi_cls_session *cls_session;
1605 struct Scsi_Host *host; 1605 struct Scsi_Host *host;
@@ -1736,6 +1736,8 @@ fault:
1736 spin_lock(host->host_lock); 1736 spin_lock(host->host_lock);
1737 return 0; 1737 return 0;
1738} 1738}
1739
1740DEF_SCSI_QCMD(iscsi_queuecommand)
1739EXPORT_SYMBOL_GPL(iscsi_queuecommand); 1741EXPORT_SYMBOL_GPL(iscsi_queuecommand);
1740 1742
1741int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, int reason) 1743int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, int reason)
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 55f09e92ab59..29251fabecc6 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -189,7 +189,7 @@ int sas_queue_up(struct sas_task *task)
189 * Note: XXX: Remove the host unlock/lock pair when SCSI Core can 189 * Note: XXX: Remove the host unlock/lock pair when SCSI Core can
190 * call us without holding an IRQ spinlock... 190 * call us without holding an IRQ spinlock...
191 */ 191 */
192int sas_queuecommand(struct scsi_cmnd *cmd, 192static int sas_queuecommand_lck(struct scsi_cmnd *cmd,
193 void (*scsi_done)(struct scsi_cmnd *)) 193 void (*scsi_done)(struct scsi_cmnd *))
194 __releases(host->host_lock) 194 __releases(host->host_lock)
195 __acquires(dev->sata_dev.ap->lock) 195 __acquires(dev->sata_dev.ap->lock)
@@ -254,6 +254,8 @@ out:
254 return res; 254 return res;
255} 255}
256 256
257DEF_SCSI_QCMD(sas_queuecommand)
258
257static void sas_eh_finish_cmd(struct scsi_cmnd *cmd) 259static void sas_eh_finish_cmd(struct scsi_cmnd *cmd)
258{ 260{
259 struct sas_task *task = TO_SAS_TASK(cmd); 261 struct sas_task *task = TO_SAS_TASK(cmd);
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index a50aa03b8ac1..196de40b906c 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -202,9 +202,12 @@ struct lpfc_stats {
202 uint32_t elsRcvPRLO; 202 uint32_t elsRcvPRLO;
203 uint32_t elsRcvPRLI; 203 uint32_t elsRcvPRLI;
204 uint32_t elsRcvLIRR; 204 uint32_t elsRcvLIRR;
205 uint32_t elsRcvRLS;
205 uint32_t elsRcvRPS; 206 uint32_t elsRcvRPS;
206 uint32_t elsRcvRPL; 207 uint32_t elsRcvRPL;
207 uint32_t elsRcvRRQ; 208 uint32_t elsRcvRRQ;
209 uint32_t elsRcvRTV;
210 uint32_t elsRcvECHO;
208 uint32_t elsXmitFLOGI; 211 uint32_t elsXmitFLOGI;
209 uint32_t elsXmitFDISC; 212 uint32_t elsXmitFDISC;
210 uint32_t elsXmitPLOGI; 213 uint32_t elsXmitPLOGI;
@@ -549,9 +552,11 @@ struct lpfc_hba {
549#define ELS_XRI_ABORT_EVENT 0x40 552#define ELS_XRI_ABORT_EVENT 0x40
550#define ASYNC_EVENT 0x80 553#define ASYNC_EVENT 0x80
551#define LINK_DISABLED 0x100 /* Link disabled by user */ 554#define LINK_DISABLED 0x100 /* Link disabled by user */
552#define FCF_DISC_INPROGRESS 0x200 /* FCF discovery in progress */ 555#define FCF_TS_INPROG 0x200 /* FCF table scan in progress */
553#define HBA_FIP_SUPPORT 0x400 /* FIP support in HBA */ 556#define FCF_RR_INPROG 0x400 /* FCF roundrobin flogi in progress */
554#define HBA_AER_ENABLED 0x800 /* AER enabled with HBA */ 557#define HBA_FIP_SUPPORT 0x800 /* FIP support in HBA */
558#define HBA_AER_ENABLED 0x1000 /* AER enabled with HBA */
559#define HBA_DEVLOSS_TMO 0x2000 /* HBA in devloss timeout */
555 uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/ 560 uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/
556 struct lpfc_dmabuf slim2p; 561 struct lpfc_dmabuf slim2p;
557 562
@@ -573,6 +578,7 @@ struct lpfc_hba {
573 /* These fields used to be binfo */ 578 /* These fields used to be binfo */
574 uint32_t fc_pref_DID; /* preferred D_ID */ 579 uint32_t fc_pref_DID; /* preferred D_ID */
575 uint8_t fc_pref_ALPA; /* preferred AL_PA */ 580 uint8_t fc_pref_ALPA; /* preferred AL_PA */
581 uint32_t fc_edtovResol; /* E_D_TOV timer resolution */
576 uint32_t fc_edtov; /* E_D_TOV timer value */ 582 uint32_t fc_edtov; /* E_D_TOV timer value */
577 uint32_t fc_arbtov; /* ARB_TOV timer value */ 583 uint32_t fc_arbtov; /* ARB_TOV timer value */
578 uint32_t fc_ratov; /* R_A_TOV timer value */ 584 uint32_t fc_ratov; /* R_A_TOV timer value */
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 0e4abb96d68e..2d7b01a2bb2b 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -3789,8 +3789,13 @@ sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3789 break; 3789 break;
3790 case MBX_SECURITY_MGMT: 3790 case MBX_SECURITY_MGMT:
3791 case MBX_AUTH_PORT: 3791 case MBX_AUTH_PORT:
3792 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) 3792 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3793 printk(KERN_WARNING "mbox_read:Command 0x%x "
3794 "is not permitted\n", pmb->mbxCommand);
3795 sysfs_mbox_idle(phba);
3796 spin_unlock_irq(&phba->hbalock);
3793 return -EPERM; 3797 return -EPERM;
3798 }
3794 break; 3799 break;
3795 case MBX_READ_SPARM64: 3800 case MBX_READ_SPARM64:
3796 case MBX_READ_LA: 3801 case MBX_READ_LA:
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index f5d60b55f53a..7260c3af555a 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -3142,12 +3142,12 @@ lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba *phba,
3142 job = menlo->set_job; 3142 job = menlo->set_job;
3143 job->dd_data = NULL; /* so timeout handler does not reply */ 3143 job->dd_data = NULL; /* so timeout handler does not reply */
3144 3144
3145 spin_lock_irqsave(&phba->hbalock, flags); 3145 spin_lock(&phba->hbalock);
3146 cmdiocbq->iocb_flag |= LPFC_IO_WAKE; 3146 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3147 if (cmdiocbq->context2 && rspiocbq) 3147 if (cmdiocbq->context2 && rspiocbq)
3148 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, 3148 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3149 &rspiocbq->iocb, sizeof(IOCB_t)); 3149 &rspiocbq->iocb, sizeof(IOCB_t));
3150 spin_unlock_irqrestore(&phba->hbalock, flags); 3150 spin_unlock(&phba->hbalock);
3151 3151
3152 bmp = menlo->bmp; 3152 bmp = menlo->bmp;
3153 rspiocbq = menlo->rspiocbq; 3153 rspiocbq = menlo->rspiocbq;
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index 03f4ddc18572..a5f5a093a8a4 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -44,6 +44,8 @@ int lpfc_reg_rpi(struct lpfc_hba *, uint16_t, uint32_t, uint8_t *,
44void lpfc_set_var(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t); 44void lpfc_set_var(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t);
45void lpfc_unreg_login(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *); 45void lpfc_unreg_login(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *);
46void lpfc_unreg_did(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *); 46void lpfc_unreg_did(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *);
47void lpfc_sli4_unreg_all_rpis(struct lpfc_vport *);
48
47void lpfc_reg_vpi(struct lpfc_vport *, LPFC_MBOXQ_t *); 49void lpfc_reg_vpi(struct lpfc_vport *, LPFC_MBOXQ_t *);
48void lpfc_register_new_vport(struct lpfc_hba *, struct lpfc_vport *, 50void lpfc_register_new_vport(struct lpfc_hba *, struct lpfc_vport *,
49 struct lpfc_nodelist *); 51 struct lpfc_nodelist *);
@@ -229,6 +231,7 @@ void lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *);
229uint16_t lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *); 231uint16_t lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *);
230int lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *, uint16_t); 232int lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *, uint16_t);
231void lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *, uint16_t); 233void lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *, uint16_t);
234int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *, uint16_t);
232 235
233int lpfc_mem_alloc(struct lpfc_hba *, int align); 236int lpfc_mem_alloc(struct lpfc_hba *, int align);
234void lpfc_mem_free(struct lpfc_hba *); 237void lpfc_mem_free(struct lpfc_hba *);
@@ -271,6 +274,7 @@ int lpfc_sli_issue_iocb(struct lpfc_hba *, uint32_t,
271void lpfc_sli_pcimem_bcopy(void *, void *, uint32_t); 274void lpfc_sli_pcimem_bcopy(void *, void *, uint32_t);
272void lpfc_sli_bemem_bcopy(void *, void *, uint32_t); 275void lpfc_sli_bemem_bcopy(void *, void *, uint32_t);
273void lpfc_sli_abort_iocb_ring(struct lpfc_hba *, struct lpfc_sli_ring *); 276void lpfc_sli_abort_iocb_ring(struct lpfc_hba *, struct lpfc_sli_ring *);
277void lpfc_sli_hba_iocb_abort(struct lpfc_hba *);
274void lpfc_sli_flush_fcp_rings(struct lpfc_hba *); 278void lpfc_sli_flush_fcp_rings(struct lpfc_hba *);
275int lpfc_sli_ringpostbuf_put(struct lpfc_hba *, struct lpfc_sli_ring *, 279int lpfc_sli_ringpostbuf_put(struct lpfc_hba *, struct lpfc_sli_ring *,
276 struct lpfc_dmabuf *); 280 struct lpfc_dmabuf *);
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index e6ca12f6c6cb..884f4d321799 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -177,15 +177,18 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
177 (elscmd == ELS_CMD_LOGO))) 177 (elscmd == ELS_CMD_LOGO)))
178 switch (elscmd) { 178 switch (elscmd) {
179 case ELS_CMD_FLOGI: 179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) 180 elsiocb->iocb_flag |=
181 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK); 182 & LPFC_FIP_ELS_ID_MASK);
182 break; 183 break;
183 case ELS_CMD_FDISC: 184 case ELS_CMD_FDISC:
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) 185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK); 187 & LPFC_FIP_ELS_ID_MASK);
186 break; 188 break;
187 case ELS_CMD_LOGO: 189 case ELS_CMD_LOGO:
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) 190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK); 192 & LPFC_FIP_ELS_ID_MASK);
190 break; 193 break;
191 } 194 }
@@ -517,18 +520,13 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ 520 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; 521 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519 522
523 phba->fc_edtovResol = sp->cmn.edtovResolution;
520 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; 524 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
521 525
522 if (phba->fc_topology == TOPOLOGY_LOOP) { 526 if (phba->fc_topology == TOPOLOGY_LOOP) {
523 spin_lock_irq(shost->host_lock); 527 spin_lock_irq(shost->host_lock);
524 vport->fc_flag |= FC_PUBLIC_LOOP; 528 vport->fc_flag |= FC_PUBLIC_LOOP;
525 spin_unlock_irq(shost->host_lock); 529 spin_unlock_irq(shost->host_lock);
526 } else {
527 /*
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
530 */
531 vport->fc_sparam.cmn.altBbCredit = 1;
532 } 530 }
533 531
534 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; 532 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
@@ -585,6 +583,10 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
585 lpfc_unreg_rpi(vport, np); 583 lpfc_unreg_rpi(vport, np);
586 } 584 }
587 lpfc_cleanup_pending_mbox(vport); 585 lpfc_cleanup_pending_mbox(vport);
586
587 if (phba->sli_rev == LPFC_SLI_REV4)
588 lpfc_sli4_unreg_all_rpis(vport);
589
588 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { 590 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
589 lpfc_mbx_unreg_vpi(vport); 591 lpfc_mbx_unreg_vpi(vport);
590 spin_lock_irq(shost->host_lock); 592 spin_lock_irq(shost->host_lock);
@@ -800,7 +802,7 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
800 802
801 if (irsp->ulpStatus) { 803 if (irsp->ulpStatus) {
802 /* 804 /*
803 * In case of FIP mode, perform round robin FCF failover 805 * In case of FIP mode, perform roundrobin FCF failover
804 * due to new FCF discovery 806 * due to new FCF discovery
805 */ 807 */
806 if ((phba->hba_flag & HBA_FIP_SUPPORT) && 808 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
@@ -808,48 +810,16 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
808 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) && 810 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
809 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { 811 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
810 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, 812 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
811 "2611 FLOGI failed on registered " 813 "2611 FLOGI failed on FCF (x%x), "
812 "FCF record fcf_index(%d), status: " 814 "status:x%x/x%x, tmo:x%x, perform "
813 "x%x/x%x, tmo:x%x, trying to perform " 815 "roundrobin FCF failover\n",
814 "round robin failover\n",
815 phba->fcf.current_rec.fcf_indx, 816 phba->fcf.current_rec.fcf_indx,
816 irsp->ulpStatus, irsp->un.ulpWord[4], 817 irsp->ulpStatus, irsp->un.ulpWord[4],
817 irsp->ulpTimeout); 818 irsp->ulpTimeout);
818 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); 819 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
819 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { 820 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
820 /* 821 if (rc)
821 * Exhausted the eligible FCF record list, 822 goto out;
822 * fail through to retry FLOGI on current
823 * FCF record.
824 */
825 lpfc_printf_log(phba, KERN_WARNING,
826 LOG_FIP | LOG_ELS,
827 "2760 Completed one round "
828 "of FLOGI FCF round robin "
829 "failover list, retry FLOGI "
830 "on currently registered "
831 "FCF index:%d\n",
832 phba->fcf.current_rec.fcf_indx);
833 } else {
834 lpfc_printf_log(phba, KERN_INFO,
835 LOG_FIP | LOG_ELS,
836 "2794 FLOGI FCF round robin "
837 "failover to FCF index x%x\n",
838 fcf_index);
839 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
840 fcf_index);
841 if (rc)
842 lpfc_printf_log(phba, KERN_WARNING,
843 LOG_FIP | LOG_ELS,
844 "2761 FLOGI round "
845 "robin FCF failover "
846 "read FCF failed "
847 "rc:x%x, fcf_index:"
848 "%d\n", rc,
849 phba->fcf.current_rec.fcf_indx);
850 else
851 goto out;
852 }
853 } 823 }
854 824
855 /* FLOGI failure */ 825 /* FLOGI failure */
@@ -939,6 +909,7 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
939 lpfc_nlp_put(ndlp); 909 lpfc_nlp_put(ndlp);
940 spin_lock_irq(&phba->hbalock); 910 spin_lock_irq(&phba->hbalock);
941 phba->fcf.fcf_flag &= ~FCF_DISCOVERY; 911 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
912 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
942 spin_unlock_irq(&phba->hbalock); 913 spin_unlock_irq(&phba->hbalock);
943 goto out; 914 goto out;
944 } 915 }
@@ -947,13 +918,12 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
947 if (phba->hba_flag & HBA_FIP_SUPPORT) 918 if (phba->hba_flag & HBA_FIP_SUPPORT)
948 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | 919 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
949 LOG_ELS, 920 LOG_ELS,
950 "2769 FLOGI successful on FCF " 921 "2769 FLOGI to FCF (x%x) "
951 "record: current_fcf_index:" 922 "completed successfully\n",
952 "x%x, terminate FCF round "
953 "robin failover process\n",
954 phba->fcf.current_rec.fcf_indx); 923 phba->fcf.current_rec.fcf_indx);
955 spin_lock_irq(&phba->hbalock); 924 spin_lock_irq(&phba->hbalock);
956 phba->fcf.fcf_flag &= ~FCF_DISCOVERY; 925 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
926 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
957 spin_unlock_irq(&phba->hbalock); 927 spin_unlock_irq(&phba->hbalock);
958 goto out; 928 goto out;
959 } 929 }
@@ -1175,12 +1145,13 @@ lpfc_initial_flogi(struct lpfc_vport *vport)
1175 return 0; 1145 return 0;
1176 } 1146 }
1177 1147
1178 if (lpfc_issue_els_flogi(vport, ndlp, 0)) 1148 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1179 /* This decrement of reference count to node shall kick off 1149 /* This decrement of reference count to node shall kick off
1180 * the release of the node. 1150 * the release of the node.
1181 */ 1151 */
1182 lpfc_nlp_put(ndlp); 1152 lpfc_nlp_put(ndlp);
1183 1153 return 0;
1154 }
1184 return 1; 1155 return 1;
1185} 1156}
1186 1157
@@ -1645,6 +1616,13 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1645 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); 1616 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1646 sp = (struct serv_parm *) pcmd; 1617 sp = (struct serv_parm *) pcmd;
1647 1618
1619 /*
1620 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1621 * to device on remote loops work.
1622 */
1623 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1624 sp->cmn.altBbCredit = 1;
1625
1648 if (sp->cmn.fcphLow < FC_PH_4_3) 1626 if (sp->cmn.fcphLow < FC_PH_4_3)
1649 sp->cmn.fcphLow = FC_PH_4_3; 1627 sp->cmn.fcphLow = FC_PH_4_3;
1650 1628
@@ -3926,6 +3904,64 @@ lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3926} 3904}
3927 3905
3928/** 3906/**
3907 * lpfc_els_rsp_echo_acc - Issue echo acc response
3908 * @vport: pointer to a virtual N_Port data structure.
3909 * @data: pointer to echo data to return in the accept.
3910 * @oldiocb: pointer to the original lpfc command iocb data structure.
3911 * @ndlp: pointer to a node-list data structure.
3912 *
3913 * Return code
3914 * 0 - Successfully issued acc echo response
3915 * 1 - Failed to issue acc echo response
3916 **/
3917static int
3918lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
3919 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3920{
3921 struct lpfc_hba *phba = vport->phba;
3922 struct lpfc_iocbq *elsiocb;
3923 struct lpfc_sli *psli;
3924 uint8_t *pcmd;
3925 uint16_t cmdsize;
3926 int rc;
3927
3928 psli = &phba->sli;
3929 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
3930
3931 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3932 ndlp->nlp_DID, ELS_CMD_ACC);
3933 if (!elsiocb)
3934 return 1;
3935
3936 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
3937 /* Xmit ECHO ACC response tag <ulpIoTag> */
3938 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3939 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
3940 elsiocb->iotag, elsiocb->iocb.ulpContext);
3941 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3942 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3943 pcmd += sizeof(uint32_t);
3944 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
3945
3946 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3947 "Issue ACC ECHO: did:x%x flg:x%x",
3948 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3949
3950 phba->fc_stat.elsXmitACC++;
3951 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3952 lpfc_nlp_put(ndlp);
3953 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3954 * it could be freed */
3955
3956 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3957 if (rc == IOCB_ERROR) {
3958 lpfc_els_free_iocb(phba, elsiocb);
3959 return 1;
3960 }
3961 return 0;
3962}
3963
3964/**
3929 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport 3965 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
3930 * @vport: pointer to a host virtual N_Port data structure. 3966 * @vport: pointer to a host virtual N_Port data structure.
3931 * 3967 *
@@ -4684,6 +4720,30 @@ lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4684} 4720}
4685 4721
4686/** 4722/**
4723 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4724 * @vport: pointer to a host virtual N_Port data structure.
4725 * @cmdiocb: pointer to lpfc command iocb data structure.
4726 * @ndlp: pointer to a node-list data structure.
4727 *
4728 * Return code
4729 * 0 - Successfully processed echo iocb (currently always return 0)
4730 **/
4731static int
4732lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4733 struct lpfc_nodelist *ndlp)
4734{
4735 uint8_t *pcmd;
4736
4737 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4738
4739 /* skip over first word of echo command to find echo data */
4740 pcmd += sizeof(uint32_t);
4741
4742 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4743 return 0;
4744}
4745
4746/**
4687 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb 4747 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4688 * @vport: pointer to a host virtual N_Port data structure. 4748 * @vport: pointer to a host virtual N_Port data structure.
4689 * @cmdiocb: pointer to lpfc command iocb data structure. 4749 * @cmdiocb: pointer to lpfc command iocb data structure.
@@ -4735,6 +4795,89 @@ lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4735} 4795}
4736 4796
4737/** 4797/**
4798 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4799 * @phba: pointer to lpfc hba data structure.
4800 * @pmb: pointer to the driver internal queue element for mailbox command.
4801 *
4802 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4803 * mailbox command. This callback function is to actually send the Accept
4804 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4805 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4806 * mailbox command, constructs the RPS response with the link statistics
4807 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4808 * response to the RPS.
4809 *
4810 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4811 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4812 * will be stored into the context1 field of the IOCB for the completion
4813 * callback function to the RPS Accept Response ELS IOCB command.
4814 *
4815 **/
4816static void
4817lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4818{
4819 MAILBOX_t *mb;
4820 IOCB_t *icmd;
4821 struct RLS_RSP *rls_rsp;
4822 uint8_t *pcmd;
4823 struct lpfc_iocbq *elsiocb;
4824 struct lpfc_nodelist *ndlp;
4825 uint16_t xri;
4826 uint32_t cmdsize;
4827
4828 mb = &pmb->u.mb;
4829
4830 ndlp = (struct lpfc_nodelist *) pmb->context2;
4831 xri = (uint16_t) ((unsigned long)(pmb->context1));
4832 pmb->context1 = NULL;
4833 pmb->context2 = NULL;
4834
4835 if (mb->mbxStatus) {
4836 mempool_free(pmb, phba->mbox_mem_pool);
4837 return;
4838 }
4839
4840 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4841 mempool_free(pmb, phba->mbox_mem_pool);
4842 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4843 lpfc_max_els_tries, ndlp,
4844 ndlp->nlp_DID, ELS_CMD_ACC);
4845
4846 /* Decrement the ndlp reference count from previous mbox command */
4847 lpfc_nlp_put(ndlp);
4848
4849 if (!elsiocb)
4850 return;
4851
4852 icmd = &elsiocb->iocb;
4853 icmd->ulpContext = xri;
4854
4855 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4856 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4857 pcmd += sizeof(uint32_t); /* Skip past command */
4858 rls_rsp = (struct RLS_RSP *)pcmd;
4859
4860 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4861 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4862 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4863 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4864 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4865 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4866
4867 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
4868 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4869 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
4870 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4871 elsiocb->iotag, elsiocb->iocb.ulpContext,
4872 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4873 ndlp->nlp_rpi);
4874 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4875 phba->fc_stat.elsXmitACC++;
4876 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4877 lpfc_els_free_iocb(phba, elsiocb);
4878}
4879
4880/**
4738 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd 4881 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4739 * @phba: pointer to lpfc hba data structure. 4882 * @phba: pointer to lpfc hba data structure.
4740 * @pmb: pointer to the driver internal queue element for mailbox command. 4883 * @pmb: pointer to the driver internal queue element for mailbox command.
@@ -4827,7 +4970,155 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4827} 4970}
4828 4971
4829/** 4972/**
4830 * lpfc_els_rcv_rps - Process an unsolicited rps iocb 4973 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
4974 * @vport: pointer to a host virtual N_Port data structure.
4975 * @cmdiocb: pointer to lpfc command iocb data structure.
4976 * @ndlp: pointer to a node-list data structure.
4977 *
4978 * This routine processes Read Port Status (RPL) IOCB received as an
4979 * ELS unsolicited event. It first checks the remote port state. If the
4980 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4981 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
4982 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4983 * for reading the HBA link statistics. It is for the callback function,
4984 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
4985 * to actually sending out RPL Accept (ACC) response.
4986 *
4987 * Return codes
4988 * 0 - Successfully processed rls iocb (currently always return 0)
4989 **/
4990static int
4991lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4992 struct lpfc_nodelist *ndlp)
4993{
4994 struct lpfc_hba *phba = vport->phba;
4995 LPFC_MBOXQ_t *mbox;
4996 struct lpfc_dmabuf *pcmd;
4997 struct ls_rjt stat;
4998
4999 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5000 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5001 /* reject the unsolicited RPS request and done with it */
5002 goto reject_out;
5003
5004 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5005
5006 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5007 if (mbox) {
5008 lpfc_read_lnk_stat(phba, mbox);
5009 mbox->context1 =
5010 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5011 mbox->context2 = lpfc_nlp_get(ndlp);
5012 mbox->vport = vport;
5013 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5014 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5015 != MBX_NOT_FINISHED)
5016 /* Mbox completion will send ELS Response */
5017 return 0;
5018 /* Decrement reference count used for the failed mbox
5019 * command.
5020 */
5021 lpfc_nlp_put(ndlp);
5022 mempool_free(mbox, phba->mbox_mem_pool);
5023 }
5024reject_out:
5025 /* issue rejection response */
5026 stat.un.b.lsRjtRsvd0 = 0;
5027 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5028 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5029 stat.un.b.vendorUnique = 0;
5030 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5031 return 0;
5032}
5033
5034/**
5035 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5036 * @vport: pointer to a host virtual N_Port data structure.
5037 * @cmdiocb: pointer to lpfc command iocb data structure.
5038 * @ndlp: pointer to a node-list data structure.
5039 *
5040 * This routine processes Read Timout Value (RTV) IOCB received as an
5041 * ELS unsolicited event. It first checks the remote port state. If the
5042 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5043 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5044 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5045 * Value (RTV) unsolicited IOCB event.
5046 *
5047 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5048 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5049 * will be stored into the context1 field of the IOCB for the completion
5050 * callback function to the RPS Accept Response ELS IOCB command.
5051 *
5052 * Return codes
5053 * 0 - Successfully processed rtv iocb (currently always return 0)
5054 **/
5055static int
5056lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5057 struct lpfc_nodelist *ndlp)
5058{
5059 struct lpfc_hba *phba = vport->phba;
5060 struct ls_rjt stat;
5061 struct RTV_RSP *rtv_rsp;
5062 uint8_t *pcmd;
5063 struct lpfc_iocbq *elsiocb;
5064 uint32_t cmdsize;
5065
5066
5067 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5068 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5069 /* reject the unsolicited RPS request and done with it */
5070 goto reject_out;
5071
5072 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5073 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5074 lpfc_max_els_tries, ndlp,
5075 ndlp->nlp_DID, ELS_CMD_ACC);
5076
5077 if (!elsiocb)
5078 return 1;
5079
5080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5081 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5082 pcmd += sizeof(uint32_t); /* Skip past command */
5083
5084 /* use the command's xri in the response */
5085 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5086
5087 rtv_rsp = (struct RTV_RSP *)pcmd;
5088
5089 /* populate RTV payload */
5090 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5091 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5092 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5093 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5094 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5095
5096 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5097 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5098 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5099 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5100 "Data: x%x x%x x%x\n",
5101 elsiocb->iotag, elsiocb->iocb.ulpContext,
5102 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5103 ndlp->nlp_rpi,
5104 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5105 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5106 phba->fc_stat.elsXmitACC++;
5107 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5108 lpfc_els_free_iocb(phba, elsiocb);
5109 return 0;
5110
5111reject_out:
5112 /* issue rejection response */
5113 stat.un.b.lsRjtRsvd0 = 0;
5114 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5115 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5116 stat.un.b.vendorUnique = 0;
5117 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5118 return 0;
5119}
5120
5121/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
4831 * @vport: pointer to a host virtual N_Port data structure. 5122 * @vport: pointer to a host virtual N_Port data structure.
4832 * @cmdiocb: pointer to lpfc command iocb data structure. 5123 * @cmdiocb: pointer to lpfc command iocb data structure.
4833 * @ndlp: pointer to a node-list data structure. 5124 * @ndlp: pointer to a node-list data structure.
@@ -5017,7 +5308,6 @@ lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5017 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; 5308 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5018 lp = (uint32_t *) pcmd->virt; 5309 lp = (uint32_t *) pcmd->virt;
5019 rpl = (RPL *) (lp + 1); 5310 rpl = (RPL *) (lp + 1);
5020
5021 maxsize = be32_to_cpu(rpl->maxsize); 5311 maxsize = be32_to_cpu(rpl->maxsize);
5022 5312
5023 /* We support only one port */ 5313 /* We support only one port */
@@ -5836,6 +6126,16 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5836 if (newnode) 6126 if (newnode)
5837 lpfc_nlp_put(ndlp); 6127 lpfc_nlp_put(ndlp);
5838 break; 6128 break;
6129 case ELS_CMD_RLS:
6130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6131 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6132 did, vport->port_state, ndlp->nlp_flag);
6133
6134 phba->fc_stat.elsRcvRLS++;
6135 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6136 if (newnode)
6137 lpfc_nlp_put(ndlp);
6138 break;
5839 case ELS_CMD_RPS: 6139 case ELS_CMD_RPS:
5840 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 6140 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5841 "RCV RPS: did:x%x/ste:x%x flg:x%x", 6141 "RCV RPS: did:x%x/ste:x%x flg:x%x",
@@ -5866,6 +6166,15 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5866 if (newnode) 6166 if (newnode)
5867 lpfc_nlp_put(ndlp); 6167 lpfc_nlp_put(ndlp);
5868 break; 6168 break;
6169 case ELS_CMD_RTV:
6170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6171 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6172 did, vport->port_state, ndlp->nlp_flag);
6173 phba->fc_stat.elsRcvRTV++;
6174 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6175 if (newnode)
6176 lpfc_nlp_put(ndlp);
6177 break;
5869 case ELS_CMD_RRQ: 6178 case ELS_CMD_RRQ:
5870 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 6179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5871 "RCV RRQ: did:x%x/ste:x%x flg:x%x", 6180 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
@@ -5876,6 +6185,16 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5876 if (newnode) 6185 if (newnode)
5877 lpfc_nlp_put(ndlp); 6186 lpfc_nlp_put(ndlp);
5878 break; 6187 break;
6188 case ELS_CMD_ECHO:
6189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6190 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6191 did, vport->port_state, ndlp->nlp_flag);
6192
6193 phba->fc_stat.elsRcvECHO++;
6194 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6195 if (newnode)
6196 lpfc_nlp_put(ndlp);
6197 break;
5879 default: 6198 default:
5880 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 6199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5881 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", 6200 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
@@ -6170,6 +6489,8 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6170 6489
6171 default: 6490 default:
6172 /* Try to recover from this error */ 6491 /* Try to recover from this error */
6492 if (phba->sli_rev == LPFC_SLI_REV4)
6493 lpfc_sli4_unreg_all_rpis(vport);
6173 lpfc_mbx_unreg_vpi(vport); 6494 lpfc_mbx_unreg_vpi(vport);
6174 spin_lock_irq(shost->host_lock); 6495 spin_lock_irq(shost->host_lock);
6175 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 6496 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
@@ -6437,6 +6758,10 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6437 lpfc_unreg_rpi(vport, np); 6758 lpfc_unreg_rpi(vport, np);
6438 } 6759 }
6439 lpfc_cleanup_pending_mbox(vport); 6760 lpfc_cleanup_pending_mbox(vport);
6761
6762 if (phba->sli_rev == LPFC_SLI_REV4)
6763 lpfc_sli4_unreg_all_rpis(vport);
6764
6440 lpfc_mbx_unreg_vpi(vport); 6765 lpfc_mbx_unreg_vpi(vport);
6441 spin_lock_irq(shost->host_lock); 6766 spin_lock_irq(shost->host_lock);
6442 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 6767 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
@@ -6452,7 +6777,7 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6452 * to update the MAC address. 6777 * to update the MAC address.
6453 */ 6778 */
6454 lpfc_register_new_vport(phba, vport, ndlp); 6779 lpfc_register_new_vport(phba, vport, ndlp);
6455 return ; 6780 goto out;
6456 } 6781 }
6457 6782
6458 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) 6783 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index 2a6866e63aae..0873fbd19e18 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -20,6 +20,7 @@
20 *******************************************************************/ 20 *******************************************************************/
21 21
22#include <linux/blkdev.h> 22#include <linux/blkdev.h>
23#include <linux/delay.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <linux/pci.h> 25#include <linux/pci.h>
25#include <linux/kthread.h> 26#include <linux/kthread.h>
@@ -63,6 +64,7 @@ static uint8_t lpfcAlpaArray[] = {
63static void lpfc_disc_timeout_handler(struct lpfc_vport *); 64static void lpfc_disc_timeout_handler(struct lpfc_vport *);
64static void lpfc_disc_flush_list(struct lpfc_vport *vport); 65static void lpfc_disc_flush_list(struct lpfc_vport *vport);
65static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); 66static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
67static int lpfc_fcf_inuse(struct lpfc_hba *);
66 68
67void 69void
68lpfc_terminate_rport_io(struct fc_rport *rport) 70lpfc_terminate_rport_io(struct fc_rport *rport)
@@ -160,11 +162,17 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
160 return; 162 return;
161} 163}
162 164
163/* 165/**
164 * This function is called from the worker thread when dev_loss_tmo 166 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
165 * expire. 167 * @ndlp: Pointer to remote node object.
166 */ 168 *
167static void 169 * This function is called from the worker thread when devloss timeout timer
170 * expires. For SLI4 host, this routine shall return 1 when at lease one
171 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
172 * routine shall return 0 when there is no remote node is still in use of FCF
173 * when devloss timeout happened to this @ndlp.
174 **/
175static int
168lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) 176lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
169{ 177{
170 struct lpfc_rport_data *rdata; 178 struct lpfc_rport_data *rdata;
@@ -175,17 +183,21 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
175 int put_node; 183 int put_node;
176 int put_rport; 184 int put_rport;
177 int warn_on = 0; 185 int warn_on = 0;
186 int fcf_inuse = 0;
178 187
179 rport = ndlp->rport; 188 rport = ndlp->rport;
180 189
181 if (!rport) 190 if (!rport)
182 return; 191 return fcf_inuse;
183 192
184 rdata = rport->dd_data; 193 rdata = rport->dd_data;
185 name = (uint8_t *) &ndlp->nlp_portname; 194 name = (uint8_t *) &ndlp->nlp_portname;
186 vport = ndlp->vport; 195 vport = ndlp->vport;
187 phba = vport->phba; 196 phba = vport->phba;
188 197
198 if (phba->sli_rev == LPFC_SLI_REV4)
199 fcf_inuse = lpfc_fcf_inuse(phba);
200
189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, 201 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
190 "rport devlosstmo:did:x%x type:x%x id:x%x", 202 "rport devlosstmo:did:x%x type:x%x id:x%x",
191 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); 203 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
@@ -209,7 +221,7 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
209 lpfc_nlp_put(ndlp); 221 lpfc_nlp_put(ndlp);
210 if (put_rport) 222 if (put_rport)
211 put_device(&rport->dev); 223 put_device(&rport->dev);
212 return; 224 return fcf_inuse;
213 } 225 }
214 226
215 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { 227 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
@@ -220,7 +232,7 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
220 *name, *(name+1), *(name+2), *(name+3), 232 *name, *(name+1), *(name+2), *(name+3),
221 *(name+4), *(name+5), *(name+6), *(name+7), 233 *(name+4), *(name+5), *(name+6), *(name+7),
222 ndlp->nlp_DID); 234 ndlp->nlp_DID);
223 return; 235 return fcf_inuse;
224 } 236 }
225 237
226 if (ndlp->nlp_type & NLP_FABRIC) { 238 if (ndlp->nlp_type & NLP_FABRIC) {
@@ -233,7 +245,7 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
233 lpfc_nlp_put(ndlp); 245 lpfc_nlp_put(ndlp);
234 if (put_rport) 246 if (put_rport)
235 put_device(&rport->dev); 247 put_device(&rport->dev);
236 return; 248 return fcf_inuse;
237 } 249 }
238 250
239 if (ndlp->nlp_sid != NLP_NO_SID) { 251 if (ndlp->nlp_sid != NLP_NO_SID) {
@@ -280,6 +292,74 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
280 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) 292 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
281 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); 293 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
282 294
295 return fcf_inuse;
296}
297
298/**
299 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
300 * @phba: Pointer to hba context object.
301 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
302 * @nlp_did: remote node identifer with devloss timeout.
303 *
304 * This function is called from the worker thread after invoking devloss
305 * timeout handler and releasing the reference count for the ndlp with
306 * which the devloss timeout was handled for SLI4 host. For the devloss
307 * timeout of the last remote node which had been in use of FCF, when this
308 * routine is invoked, it shall be guaranteed that none of the remote are
309 * in-use of FCF. When devloss timeout to the last remote using the FCF,
310 * if the FIP engine is neither in FCF table scan process nor roundrobin
311 * failover process, the in-use FCF shall be unregistered. If the FIP
312 * engine is in FCF discovery process, the devloss timeout state shall
313 * be set for either the FCF table scan process or roundrobin failover
314 * process to unregister the in-use FCF.
315 **/
316static void
317lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
318 uint32_t nlp_did)
319{
320 /* If devloss timeout happened to a remote node when FCF had no
321 * longer been in-use, do nothing.
322 */
323 if (!fcf_inuse)
324 return;
325
326 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
327 spin_lock_irq(&phba->hbalock);
328 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
329 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
330 spin_unlock_irq(&phba->hbalock);
331 return;
332 }
333 phba->hba_flag |= HBA_DEVLOSS_TMO;
334 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
335 "2847 Last remote node (x%x) using "
336 "FCF devloss tmo\n", nlp_did);
337 }
338 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
339 spin_unlock_irq(&phba->hbalock);
340 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
341 "2868 Devloss tmo to FCF rediscovery "
342 "in progress\n");
343 return;
344 }
345 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
346 spin_unlock_irq(&phba->hbalock);
347 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
348 "2869 Devloss tmo to idle FIP engine, "
349 "unreg in-use FCF and rescan.\n");
350 /* Unregister in-use FCF and rescan */
351 lpfc_unregister_fcf_rescan(phba);
352 return;
353 }
354 spin_unlock_irq(&phba->hbalock);
355 if (phba->hba_flag & FCF_TS_INPROG)
356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
357 "2870 FCF table scan in progress\n");
358 if (phba->hba_flag & FCF_RR_INPROG)
359 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
360 "2871 FLOGI roundrobin FCF failover "
361 "in progress\n");
362 }
283 lpfc_unregister_unused_fcf(phba); 363 lpfc_unregister_unused_fcf(phba);
284} 364}
285 365
@@ -408,6 +488,8 @@ lpfc_work_list_done(struct lpfc_hba *phba)
408 struct lpfc_work_evt *evtp = NULL; 488 struct lpfc_work_evt *evtp = NULL;
409 struct lpfc_nodelist *ndlp; 489 struct lpfc_nodelist *ndlp;
410 int free_evt; 490 int free_evt;
491 int fcf_inuse;
492 uint32_t nlp_did;
411 493
412 spin_lock_irq(&phba->hbalock); 494 spin_lock_irq(&phba->hbalock);
413 while (!list_empty(&phba->work_list)) { 495 while (!list_empty(&phba->work_list)) {
@@ -427,12 +509,17 @@ lpfc_work_list_done(struct lpfc_hba *phba)
427 break; 509 break;
428 case LPFC_EVT_DEV_LOSS: 510 case LPFC_EVT_DEV_LOSS:
429 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); 511 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
430 lpfc_dev_loss_tmo_handler(ndlp); 512 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
431 free_evt = 0; 513 free_evt = 0;
432 /* decrement the node reference count held for 514 /* decrement the node reference count held for
433 * this queued work 515 * this queued work
434 */ 516 */
517 nlp_did = ndlp->nlp_DID;
435 lpfc_nlp_put(ndlp); 518 lpfc_nlp_put(ndlp);
519 if (phba->sli_rev == LPFC_SLI_REV4)
520 lpfc_sli4_post_dev_loss_tmo_handler(phba,
521 fcf_inuse,
522 nlp_did);
436 break; 523 break;
437 case LPFC_EVT_ONLINE: 524 case LPFC_EVT_ONLINE:
438 if (phba->link_state < LPFC_LINK_DOWN) 525 if (phba->link_state < LPFC_LINK_DOWN)
@@ -707,6 +794,8 @@ lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
707 : NLP_EVT_DEVICE_RECOVERY); 794 : NLP_EVT_DEVICE_RECOVERY);
708 } 795 }
709 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { 796 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
797 if (phba->sli_rev == LPFC_SLI_REV4)
798 lpfc_sli4_unreg_all_rpis(vport);
710 lpfc_mbx_unreg_vpi(vport); 799 lpfc_mbx_unreg_vpi(vport);
711 spin_lock_irq(shost->host_lock); 800 spin_lock_irq(shost->host_lock);
712 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 801 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
@@ -1021,8 +1110,7 @@ lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1021 "2017 REG_FCFI mbxStatus error x%x " 1110 "2017 REG_FCFI mbxStatus error x%x "
1022 "HBA state x%x\n", 1111 "HBA state x%x\n",
1023 mboxq->u.mb.mbxStatus, vport->port_state); 1112 mboxq->u.mb.mbxStatus, vport->port_state);
1024 mempool_free(mboxq, phba->mbox_mem_pool); 1113 goto fail_out;
1025 return;
1026 } 1114 }
1027 1115
1028 /* Start FCoE discovery by sending a FLOGI. */ 1116 /* Start FCoE discovery by sending a FLOGI. */
@@ -1031,20 +1119,30 @@ lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1031 spin_lock_irq(&phba->hbalock); 1119 spin_lock_irq(&phba->hbalock);
1032 phba->fcf.fcf_flag |= FCF_REGISTERED; 1120 phba->fcf.fcf_flag |= FCF_REGISTERED;
1033 spin_unlock_irq(&phba->hbalock); 1121 spin_unlock_irq(&phba->hbalock);
1122
1034 /* If there is a pending FCoE event, restart FCF table scan. */ 1123 /* If there is a pending FCoE event, restart FCF table scan. */
1035 if (lpfc_check_pending_fcoe_event(phba, 1)) { 1124 if (lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1036 mempool_free(mboxq, phba->mbox_mem_pool); 1125 goto fail_out;
1037 return; 1126
1038 } 1127 /* Mark successful completion of FCF table scan */
1039 spin_lock_irq(&phba->hbalock); 1128 spin_lock_irq(&phba->hbalock);
1040 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); 1129 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1041 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1130 phba->hba_flag &= ~FCF_TS_INPROG;
1042 spin_unlock_irq(&phba->hbalock); 1131 if (vport->port_state != LPFC_FLOGI) {
1043 if (vport->port_state != LPFC_FLOGI) 1132 phba->hba_flag |= FCF_RR_INPROG;
1133 spin_unlock_irq(&phba->hbalock);
1044 lpfc_initial_flogi(vport); 1134 lpfc_initial_flogi(vport);
1135 goto out;
1136 }
1137 spin_unlock_irq(&phba->hbalock);
1138 goto out;
1045 1139
1140fail_out:
1141 spin_lock_irq(&phba->hbalock);
1142 phba->hba_flag &= ~FCF_RR_INPROG;
1143 spin_unlock_irq(&phba->hbalock);
1144out:
1046 mempool_free(mboxq, phba->mbox_mem_pool); 1145 mempool_free(mboxq, phba->mbox_mem_pool);
1047 return;
1048} 1146}
1049 1147
1050/** 1148/**
@@ -1241,10 +1339,9 @@ lpfc_register_fcf(struct lpfc_hba *phba)
1241 int rc; 1339 int rc;
1242 1340
1243 spin_lock_irq(&phba->hbalock); 1341 spin_lock_irq(&phba->hbalock);
1244
1245 /* If the FCF is not availabe do nothing. */ 1342 /* If the FCF is not availabe do nothing. */
1246 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { 1343 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1247 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1344 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1248 spin_unlock_irq(&phba->hbalock); 1345 spin_unlock_irq(&phba->hbalock);
1249 return; 1346 return;
1250 } 1347 }
@@ -1252,19 +1349,22 @@ lpfc_register_fcf(struct lpfc_hba *phba)
1252 /* The FCF is already registered, start discovery */ 1349 /* The FCF is already registered, start discovery */
1253 if (phba->fcf.fcf_flag & FCF_REGISTERED) { 1350 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1254 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); 1351 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1255 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1352 phba->hba_flag &= ~FCF_TS_INPROG;
1256 spin_unlock_irq(&phba->hbalock); 1353 if (phba->pport->port_state != LPFC_FLOGI) {
1257 if (phba->pport->port_state != LPFC_FLOGI) 1354 phba->hba_flag |= FCF_RR_INPROG;
1355 spin_unlock_irq(&phba->hbalock);
1258 lpfc_initial_flogi(phba->pport); 1356 lpfc_initial_flogi(phba->pport);
1357 return;
1358 }
1359 spin_unlock_irq(&phba->hbalock);
1259 return; 1360 return;
1260 } 1361 }
1261 spin_unlock_irq(&phba->hbalock); 1362 spin_unlock_irq(&phba->hbalock);
1262 1363
1263 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, 1364 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1264 GFP_KERNEL);
1265 if (!fcf_mbxq) { 1365 if (!fcf_mbxq) {
1266 spin_lock_irq(&phba->hbalock); 1366 spin_lock_irq(&phba->hbalock);
1267 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1367 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1268 spin_unlock_irq(&phba->hbalock); 1368 spin_unlock_irq(&phba->hbalock);
1269 return; 1369 return;
1270 } 1370 }
@@ -1275,7 +1375,7 @@ lpfc_register_fcf(struct lpfc_hba *phba)
1275 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); 1375 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1276 if (rc == MBX_NOT_FINISHED) { 1376 if (rc == MBX_NOT_FINISHED) {
1277 spin_lock_irq(&phba->hbalock); 1377 spin_lock_irq(&phba->hbalock);
1278 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1378 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1279 spin_unlock_irq(&phba->hbalock); 1379 spin_unlock_irq(&phba->hbalock);
1280 mempool_free(fcf_mbxq, phba->mbox_mem_pool); 1380 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1281 } 1381 }
@@ -1493,7 +1593,7 @@ lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1493 * FCF discovery, no need to restart FCF discovery. 1593 * FCF discovery, no need to restart FCF discovery.
1494 */ 1594 */
1495 if ((phba->link_state >= LPFC_LINK_UP) && 1595 if ((phba->link_state >= LPFC_LINK_UP) &&
1496 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) 1596 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1497 return 0; 1597 return 0;
1498 1598
1499 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 1599 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
@@ -1517,14 +1617,14 @@ lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1517 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); 1617 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1518 } else { 1618 } else {
1519 /* 1619 /*
1520 * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS 1620 * Do not continue FCF discovery and clear FCF_TS_INPROG
1521 * flag 1621 * flag
1522 */ 1622 */
1523 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, 1623 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1524 "2833 Stop FCF discovery process due to link " 1624 "2833 Stop FCF discovery process due to link "
1525 "state change (x%x)\n", phba->link_state); 1625 "state change (x%x)\n", phba->link_state);
1526 spin_lock_irq(&phba->hbalock); 1626 spin_lock_irq(&phba->hbalock);
1527 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1627 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1528 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); 1628 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1529 spin_unlock_irq(&phba->hbalock); 1629 spin_unlock_irq(&phba->hbalock);
1530 } 1630 }
@@ -1729,6 +1829,65 @@ lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1729} 1829}
1730 1830
1731/** 1831/**
1832 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1833 * @vport: Pointer to vport object.
1834 * @fcf_index: index to next fcf.
1835 *
1836 * This function processing the roundrobin fcf failover to next fcf index.
1837 * When this function is invoked, there will be a current fcf registered
1838 * for flogi.
1839 * Return: 0 for continue retrying flogi on currently registered fcf;
1840 * 1 for stop flogi on currently registered fcf;
1841 */
1842int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1843{
1844 struct lpfc_hba *phba = vport->phba;
1845 int rc;
1846
1847 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1848 spin_lock_irq(&phba->hbalock);
1849 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1850 spin_unlock_irq(&phba->hbalock);
1851 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1852 "2872 Devloss tmo with no eligible "
1853 "FCF, unregister in-use FCF (x%x) "
1854 "and rescan FCF table\n",
1855 phba->fcf.current_rec.fcf_indx);
1856 lpfc_unregister_fcf_rescan(phba);
1857 goto stop_flogi_current_fcf;
1858 }
1859 /* Mark the end to FLOGI roundrobin failover */
1860 phba->hba_flag &= ~FCF_RR_INPROG;
1861 /* Allow action to new fcf asynchronous event */
1862 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1863 spin_unlock_irq(&phba->hbalock);
1864 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1865 "2865 No FCF available, stop roundrobin FCF "
1866 "failover and change port state:x%x/x%x\n",
1867 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1868 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1869 goto stop_flogi_current_fcf;
1870 } else {
1871 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1872 "2794 Try FLOGI roundrobin FCF failover to "
1873 "(x%x)\n", fcf_index);
1874 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1875 if (rc)
1876 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1877 "2761 FLOGI roundrobin FCF failover "
1878 "failed (rc:x%x) to read FCF (x%x)\n",
1879 rc, phba->fcf.current_rec.fcf_indx);
1880 else
1881 goto stop_flogi_current_fcf;
1882 }
1883 return 0;
1884
1885stop_flogi_current_fcf:
1886 lpfc_can_disctmo(vport);
1887 return 1;
1888}
1889
1890/**
1732 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. 1891 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
1733 * @phba: pointer to lpfc hba data structure. 1892 * @phba: pointer to lpfc hba data structure.
1734 * @mboxq: pointer to mailbox object. 1893 * @mboxq: pointer to mailbox object.
@@ -1756,7 +1915,7 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1756 int rc; 1915 int rc;
1757 1916
1758 /* If there is pending FCoE event restart FCF table scan */ 1917 /* If there is pending FCoE event restart FCF table scan */
1759 if (lpfc_check_pending_fcoe_event(phba, 0)) { 1918 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
1760 lpfc_sli4_mbox_cmd_free(phba, mboxq); 1919 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1761 return; 1920 return;
1762 } 1921 }
@@ -1765,12 +1924,12 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1765 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, 1924 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
1766 &next_fcf_index); 1925 &next_fcf_index);
1767 if (!new_fcf_record) { 1926 if (!new_fcf_record) {
1768 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, 1927 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1769 "2765 Mailbox command READ_FCF_RECORD " 1928 "2765 Mailbox command READ_FCF_RECORD "
1770 "failed to retrieve a FCF record.\n"); 1929 "failed to retrieve a FCF record.\n");
1771 /* Let next new FCF event trigger fast failover */ 1930 /* Let next new FCF event trigger fast failover */
1772 spin_lock_irq(&phba->hbalock); 1931 spin_lock_irq(&phba->hbalock);
1773 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1932 phba->hba_flag &= ~FCF_TS_INPROG;
1774 spin_unlock_irq(&phba->hbalock); 1933 spin_unlock_irq(&phba->hbalock);
1775 lpfc_sli4_mbox_cmd_free(phba, mboxq); 1934 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1776 return; 1935 return;
@@ -1787,13 +1946,12 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1787 /* 1946 /*
1788 * If the fcf record does not match with connect list entries 1947 * If the fcf record does not match with connect list entries
1789 * read the next entry; otherwise, this is an eligible FCF 1948 * read the next entry; otherwise, this is an eligible FCF
1790 * record for round robin FCF failover. 1949 * record for roundrobin FCF failover.
1791 */ 1950 */
1792 if (!rc) { 1951 if (!rc) {
1793 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, 1952 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1794 "2781 FCF record (x%x) failed FCF " 1953 "2781 FCF (x%x) failed connection "
1795 "connection list check, fcf_avail:x%x, " 1954 "list check: (x%x/x%x)\n",
1796 "fcf_valid:x%x\n",
1797 bf_get(lpfc_fcf_record_fcf_index, 1955 bf_get(lpfc_fcf_record_fcf_index,
1798 new_fcf_record), 1956 new_fcf_record),
1799 bf_get(lpfc_fcf_record_fcf_avail, 1957 bf_get(lpfc_fcf_record_fcf_avail,
@@ -1803,6 +1961,16 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1803 if ((phba->fcf.fcf_flag & FCF_IN_USE) && 1961 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
1804 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, 1962 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
1805 new_fcf_record, LPFC_FCOE_IGNORE_VID)) { 1963 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
1964 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
1965 phba->fcf.current_rec.fcf_indx) {
1966 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1967 "2862 FCF (x%x) matches property "
1968 "of in-use FCF (x%x)\n",
1969 bf_get(lpfc_fcf_record_fcf_index,
1970 new_fcf_record),
1971 phba->fcf.current_rec.fcf_indx);
1972 goto read_next_fcf;
1973 }
1806 /* 1974 /*
1807 * In case the current in-use FCF record becomes 1975 * In case the current in-use FCF record becomes
1808 * invalid/unavailable during FCF discovery that 1976 * invalid/unavailable during FCF discovery that
@@ -1813,9 +1981,8 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1813 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { 1981 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
1814 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, 1982 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1815 "2835 Invalid in-use FCF " 1983 "2835 Invalid in-use FCF "
1816 "record (x%x) reported, " 1984 "(x%x), enter FCF failover "
1817 "entering fast FCF failover " 1985 "table scan.\n",
1818 "mode scanning.\n",
1819 phba->fcf.current_rec.fcf_indx); 1986 phba->fcf.current_rec.fcf_indx);
1820 spin_lock_irq(&phba->hbalock); 1987 spin_lock_irq(&phba->hbalock);
1821 phba->fcf.fcf_flag |= FCF_REDISC_FOV; 1988 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
@@ -1844,22 +2011,29 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1844 if (phba->fcf.fcf_flag & FCF_IN_USE) { 2011 if (phba->fcf.fcf_flag & FCF_IN_USE) {
1845 if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, 2012 if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
1846 new_fcf_record, vlan_id)) { 2013 new_fcf_record, vlan_id)) {
1847 phba->fcf.fcf_flag |= FCF_AVAILABLE; 2014 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
1848 if (phba->fcf.fcf_flag & FCF_REDISC_PEND) 2015 phba->fcf.current_rec.fcf_indx) {
1849 /* Stop FCF redisc wait timer if pending */ 2016 phba->fcf.fcf_flag |= FCF_AVAILABLE;
1850 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); 2017 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
1851 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) 2018 /* Stop FCF redisc wait timer */
1852 /* If in fast failover, mark it's completed */ 2019 __lpfc_sli4_stop_fcf_redisc_wait_timer(
1853 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; 2020 phba);
1854 spin_unlock_irq(&phba->hbalock); 2021 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
1855 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 2022 /* Fast failover, mark completed */
1856 "2836 The new FCF record (x%x) " 2023 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1857 "matches the in-use FCF record " 2024 spin_unlock_irq(&phba->hbalock);
1858 "(x%x)\n", 2025 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1859 phba->fcf.current_rec.fcf_indx, 2026 "2836 New FCF matches in-use "
2027 "FCF (x%x)\n",
2028 phba->fcf.current_rec.fcf_indx);
2029 goto out;
2030 } else
2031 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2032 "2863 New FCF (x%x) matches "
2033 "property of in-use FCF (x%x)\n",
1860 bf_get(lpfc_fcf_record_fcf_index, 2034 bf_get(lpfc_fcf_record_fcf_index,
1861 new_fcf_record)); 2035 new_fcf_record),
1862 goto out; 2036 phba->fcf.current_rec.fcf_indx);
1863 } 2037 }
1864 /* 2038 /*
1865 * Read next FCF record from HBA searching for the matching 2039 * Read next FCF record from HBA searching for the matching
@@ -1953,8 +2127,8 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1953 */ 2127 */
1954 if (fcf_rec) { 2128 if (fcf_rec) {
1955 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 2129 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1956 "2840 Update current FCF record " 2130 "2840 Update initial FCF candidate "
1957 "with initial FCF record (x%x)\n", 2131 "with FCF (x%x)\n",
1958 bf_get(lpfc_fcf_record_fcf_index, 2132 bf_get(lpfc_fcf_record_fcf_index,
1959 new_fcf_record)); 2133 new_fcf_record));
1960 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, 2134 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
@@ -1984,20 +2158,28 @@ read_next_fcf:
1984 */ 2158 */
1985 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { 2159 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
1986 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, 2160 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1987 "2782 No suitable FCF record " 2161 "2782 No suitable FCF found: "
1988 "found during this round of " 2162 "(x%x/x%x)\n",
1989 "post FCF rediscovery scan: "
1990 "fcf_evt_tag:x%x, fcf_index: "
1991 "x%x\n",
1992 phba->fcoe_eventtag_at_fcf_scan, 2163 phba->fcoe_eventtag_at_fcf_scan,
1993 bf_get(lpfc_fcf_record_fcf_index, 2164 bf_get(lpfc_fcf_record_fcf_index,
1994 new_fcf_record)); 2165 new_fcf_record));
2166 spin_lock_irq(&phba->hbalock);
2167 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2168 phba->hba_flag &= ~FCF_TS_INPROG;
2169 spin_unlock_irq(&phba->hbalock);
2170 /* Unregister in-use FCF and rescan */
2171 lpfc_printf_log(phba, KERN_INFO,
2172 LOG_FIP,
2173 "2864 On devloss tmo "
2174 "unreg in-use FCF and "
2175 "rescan FCF table\n");
2176 lpfc_unregister_fcf_rescan(phba);
2177 return;
2178 }
1995 /* 2179 /*
1996 * Let next new FCF event trigger fast 2180 * Let next new FCF event trigger fast failover
1997 * failover
1998 */ 2181 */
1999 spin_lock_irq(&phba->hbalock); 2182 phba->hba_flag &= ~FCF_TS_INPROG;
2000 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
2001 spin_unlock_irq(&phba->hbalock); 2183 spin_unlock_irq(&phba->hbalock);
2002 return; 2184 return;
2003 } 2185 }
@@ -2015,9 +2197,8 @@ read_next_fcf:
2015 2197
2016 /* Replace in-use record with the new record */ 2198 /* Replace in-use record with the new record */
2017 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 2199 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2018 "2842 Replace the current in-use " 2200 "2842 Replace in-use FCF (x%x) "
2019 "FCF record (x%x) with failover FCF " 2201 "with failover FCF (x%x)\n",
2020 "record (x%x)\n",
2021 phba->fcf.current_rec.fcf_indx, 2202 phba->fcf.current_rec.fcf_indx,
2022 phba->fcf.failover_rec.fcf_indx); 2203 phba->fcf.failover_rec.fcf_indx);
2023 memcpy(&phba->fcf.current_rec, 2204 memcpy(&phba->fcf.current_rec,
@@ -2029,15 +2210,8 @@ read_next_fcf:
2029 * FCF failover. 2210 * FCF failover.
2030 */ 2211 */
2031 spin_lock_irq(&phba->hbalock); 2212 spin_lock_irq(&phba->hbalock);
2032 phba->fcf.fcf_flag &= 2213 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2033 ~(FCF_REDISC_FOV | FCF_REDISC_RRU);
2034 spin_unlock_irq(&phba->hbalock); 2214 spin_unlock_irq(&phba->hbalock);
2035 /*
2036 * Set up the initial registered FCF index for FLOGI
2037 * round robin FCF failover.
2038 */
2039 phba->fcf.fcf_rr_init_indx =
2040 phba->fcf.failover_rec.fcf_indx;
2041 /* Register to the new FCF record */ 2215 /* Register to the new FCF record */
2042 lpfc_register_fcf(phba); 2216 lpfc_register_fcf(phba);
2043 } else { 2217 } else {
@@ -2069,28 +2243,6 @@ read_next_fcf:
2069 LPFC_FCOE_FCF_GET_FIRST); 2243 LPFC_FCOE_FCF_GET_FIRST);
2070 return; 2244 return;
2071 } 2245 }
2072
2073 /*
2074 * Otherwise, initial scan or post linkdown rescan,
2075 * register with the best FCF record found so far
2076 * through the FCF scanning process.
2077 */
2078
2079 /*
2080 * Mark the initial FCF discovery completed and
2081 * the start of the first round of the roundrobin
2082 * FCF failover.
2083 */
2084 spin_lock_irq(&phba->hbalock);
2085 phba->fcf.fcf_flag &=
2086 ~(FCF_INIT_DISC | FCF_REDISC_RRU);
2087 spin_unlock_irq(&phba->hbalock);
2088 /*
2089 * Set up the initial registered FCF index for FLOGI
2090 * round robin FCF failover
2091 */
2092 phba->fcf.fcf_rr_init_indx =
2093 phba->fcf.current_rec.fcf_indx;
2094 /* Register to the new FCF record */ 2246 /* Register to the new FCF record */
2095 lpfc_register_fcf(phba); 2247 lpfc_register_fcf(phba);
2096 } 2248 }
@@ -2106,11 +2258,11 @@ out:
2106} 2258}
2107 2259
2108/** 2260/**
2109 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf round robin read_fcf mbox cmpl hdler 2261 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2110 * @phba: pointer to lpfc hba data structure. 2262 * @phba: pointer to lpfc hba data structure.
2111 * @mboxq: pointer to mailbox object. 2263 * @mboxq: pointer to mailbox object.
2112 * 2264 *
2113 * This is the callback function for FLOGI failure round robin FCF failover 2265 * This is the callback function for FLOGI failure roundrobin FCF failover
2114 * read FCF record mailbox command from the eligible FCF record bmask for 2266 * read FCF record mailbox command from the eligible FCF record bmask for
2115 * performing the failover. If the FCF read back is not valid/available, it 2267 * performing the failover. If the FCF read back is not valid/available, it
2116 * fails through to retrying FLOGI to the currently registered FCF again. 2268 * fails through to retrying FLOGI to the currently registered FCF again.
@@ -2125,17 +2277,18 @@ lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2125{ 2277{
2126 struct fcf_record *new_fcf_record; 2278 struct fcf_record *new_fcf_record;
2127 uint32_t boot_flag, addr_mode; 2279 uint32_t boot_flag, addr_mode;
2128 uint16_t next_fcf_index; 2280 uint16_t next_fcf_index, fcf_index;
2129 uint16_t current_fcf_index; 2281 uint16_t current_fcf_index;
2130 uint16_t vlan_id; 2282 uint16_t vlan_id;
2283 int rc;
2131 2284
2132 /* If link state is not up, stop the round robin failover process */ 2285 /* If link state is not up, stop the roundrobin failover process */
2133 if (phba->link_state < LPFC_LINK_UP) { 2286 if (phba->link_state < LPFC_LINK_UP) {
2134 spin_lock_irq(&phba->hbalock); 2287 spin_lock_irq(&phba->hbalock);
2135 phba->fcf.fcf_flag &= ~FCF_DISCOVERY; 2288 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2289 phba->hba_flag &= ~FCF_RR_INPROG;
2136 spin_unlock_irq(&phba->hbalock); 2290 spin_unlock_irq(&phba->hbalock);
2137 lpfc_sli4_mbox_cmd_free(phba, mboxq); 2291 goto out;
2138 return;
2139 } 2292 }
2140 2293
2141 /* Parse the FCF record from the non-embedded mailbox command */ 2294 /* Parse the FCF record from the non-embedded mailbox command */
@@ -2145,23 +2298,47 @@ lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2145 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, 2298 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2146 "2766 Mailbox command READ_FCF_RECORD " 2299 "2766 Mailbox command READ_FCF_RECORD "
2147 "failed to retrieve a FCF record.\n"); 2300 "failed to retrieve a FCF record.\n");
2148 goto out; 2301 goto error_out;
2149 } 2302 }
2150 2303
2151 /* Get the needed parameters from FCF record */ 2304 /* Get the needed parameters from FCF record */
2152 lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, 2305 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2153 &addr_mode, &vlan_id); 2306 &addr_mode, &vlan_id);
2154 2307
2155 /* Log the FCF record information if turned on */ 2308 /* Log the FCF record information if turned on */
2156 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, 2309 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2157 next_fcf_index); 2310 next_fcf_index);
2158 2311
2312 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2313 if (!rc) {
2314 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2315 "2848 Remove ineligible FCF (x%x) from "
2316 "from roundrobin bmask\n", fcf_index);
2317 /* Clear roundrobin bmask bit for ineligible FCF */
2318 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2319 /* Perform next round of roundrobin FCF failover */
2320 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2321 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2322 if (rc)
2323 goto out;
2324 goto error_out;
2325 }
2326
2327 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2328 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2329 "2760 Perform FLOGI roundrobin FCF failover: "
2330 "FCF (x%x) back to FCF (x%x)\n",
2331 phba->fcf.current_rec.fcf_indx, fcf_index);
2332 /* Wait 500 ms before retrying FLOGI to current FCF */
2333 msleep(500);
2334 lpfc_initial_flogi(phba->pport);
2335 goto out;
2336 }
2337
2159 /* Upload new FCF record to the failover FCF record */ 2338 /* Upload new FCF record to the failover FCF record */
2160 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 2339 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2161 "2834 Update the current FCF record (x%x) " 2340 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2162 "with the next FCF record (x%x)\n", 2341 phba->fcf.failover_rec.fcf_indx, fcf_index);
2163 phba->fcf.failover_rec.fcf_indx,
2164 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record));
2165 spin_lock_irq(&phba->hbalock); 2342 spin_lock_irq(&phba->hbalock);
2166 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, 2343 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2167 new_fcf_record, addr_mode, vlan_id, 2344 new_fcf_record, addr_mode, vlan_id,
@@ -2178,14 +2355,13 @@ lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2178 sizeof(struct lpfc_fcf_rec)); 2355 sizeof(struct lpfc_fcf_rec));
2179 2356
2180 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 2357 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2181 "2783 FLOGI round robin FCF failover from FCF " 2358 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2182 "(x%x) to FCF (x%x).\n", 2359 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2183 current_fcf_index,
2184 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record));
2185 2360
2361error_out:
2362 lpfc_register_fcf(phba);
2186out: 2363out:
2187 lpfc_sli4_mbox_cmd_free(phba, mboxq); 2364 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2188 lpfc_register_fcf(phba);
2189} 2365}
2190 2366
2191/** 2367/**
@@ -2194,10 +2370,10 @@ out:
2194 * @mboxq: pointer to mailbox object. 2370 * @mboxq: pointer to mailbox object.
2195 * 2371 *
2196 * This is the callback function of read FCF record mailbox command for 2372 * This is the callback function of read FCF record mailbox command for
2197 * updating the eligible FCF bmask for FLOGI failure round robin FCF 2373 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2198 * failover when a new FCF event happened. If the FCF read back is 2374 * failover when a new FCF event happened. If the FCF read back is
2199 * valid/available and it passes the connection list check, it updates 2375 * valid/available and it passes the connection list check, it updates
2200 * the bmask for the eligible FCF record for round robin failover. 2376 * the bmask for the eligible FCF record for roundrobin failover.
2201 */ 2377 */
2202void 2378void
2203lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 2379lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
@@ -2639,7 +2815,7 @@ lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
2639 * and get the FCF Table. 2815 * and get the FCF Table.
2640 */ 2816 */
2641 spin_lock_irq(&phba->hbalock); 2817 spin_lock_irq(&phba->hbalock);
2642 if (phba->hba_flag & FCF_DISC_INPROGRESS) { 2818 if (phba->hba_flag & FCF_TS_INPROG) {
2643 spin_unlock_irq(&phba->hbalock); 2819 spin_unlock_irq(&phba->hbalock);
2644 return; 2820 return;
2645 } 2821 }
@@ -3906,6 +4082,11 @@ lpfc_unreg_all_rpis(struct lpfc_vport *vport)
3906 LPFC_MBOXQ_t *mbox; 4082 LPFC_MBOXQ_t *mbox;
3907 int rc; 4083 int rc;
3908 4084
4085 if (phba->sli_rev == LPFC_SLI_REV4) {
4086 lpfc_sli4_unreg_all_rpis(vport);
4087 return;
4088 }
4089
3909 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 4090 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3910 if (mbox) { 4091 if (mbox) {
3911 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox); 4092 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
@@ -3992,6 +4173,16 @@ lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3992 } 4173 }
3993 4174
3994 spin_lock_irq(&phba->hbalock); 4175 spin_lock_irq(&phba->hbalock);
4176 /* Cleanup REG_LOGIN completions which are not yet processed */
4177 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4178 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
4179 (ndlp != (struct lpfc_nodelist *) mb->context2))
4180 continue;
4181
4182 mb->context2 = NULL;
4183 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4184 }
4185
3995 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { 4186 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
3996 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && 4187 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
3997 (ndlp == (struct lpfc_nodelist *) mb->context2)) { 4188 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
@@ -5170,6 +5361,8 @@ lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
5170 if (ndlp) 5361 if (ndlp)
5171 lpfc_cancel_retry_delay_tmo(vports[i], ndlp); 5362 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
5172 lpfc_cleanup_pending_mbox(vports[i]); 5363 lpfc_cleanup_pending_mbox(vports[i]);
5364 if (phba->sli_rev == LPFC_SLI_REV4)
5365 lpfc_sli4_unreg_all_rpis(vports[i]);
5173 lpfc_mbx_unreg_vpi(vports[i]); 5366 lpfc_mbx_unreg_vpi(vports[i]);
5174 shost = lpfc_shost_from_vport(vports[i]); 5367 shost = lpfc_shost_from_vport(vports[i]);
5175 spin_lock_irq(shost->host_lock); 5368 spin_lock_irq(shost->host_lock);
diff --git a/drivers/scsi/lpfc/lpfc_hw.h b/drivers/scsi/lpfc/lpfc_hw.h
index a631647051d9..9b8333456465 100644
--- a/drivers/scsi/lpfc/lpfc_hw.h
+++ b/drivers/scsi/lpfc/lpfc_hw.h
@@ -861,6 +861,47 @@ typedef struct _RPS_RSP { /* Structure is in Big Endian format */
861 uint32_t crcCnt; 861 uint32_t crcCnt;
862} RPS_RSP; 862} RPS_RSP;
863 863
864struct RLS { /* Structure is in Big Endian format */
865 uint32_t rls;
866#define rls_rsvd_SHIFT 24
867#define rls_rsvd_MASK 0x000000ff
868#define rls_rsvd_WORD rls
869#define rls_did_SHIFT 0
870#define rls_did_MASK 0x00ffffff
871#define rls_did_WORD rls
872};
873
874struct RLS_RSP { /* Structure is in Big Endian format */
875 uint32_t linkFailureCnt;
876 uint32_t lossSyncCnt;
877 uint32_t lossSignalCnt;
878 uint32_t primSeqErrCnt;
879 uint32_t invalidXmitWord;
880 uint32_t crcCnt;
881};
882
883struct RTV_RSP { /* Structure is in Big Endian format */
884 uint32_t ratov;
885 uint32_t edtov;
886 uint32_t qtov;
887#define qtov_rsvd0_SHIFT 28
888#define qtov_rsvd0_MASK 0x0000000f
889#define qtov_rsvd0_WORD qtov /* reserved */
890#define qtov_edtovres_SHIFT 27
891#define qtov_edtovres_MASK 0x00000001
892#define qtov_edtovres_WORD qtov /* E_D_TOV Resolution */
893#define qtov__rsvd1_SHIFT 19
894#define qtov_rsvd1_MASK 0x0000003f
895#define qtov_rsvd1_WORD qtov /* reserved */
896#define qtov_rttov_SHIFT 18
897#define qtov_rttov_MASK 0x00000001
898#define qtov_rttov_WORD qtov /* R_T_TOV value */
899#define qtov_rsvd2_SHIFT 0
900#define qtov_rsvd2_MASK 0x0003ffff
901#define qtov_rsvd2_WORD qtov /* reserved */
902};
903
904
864typedef struct _RPL { /* Structure is in Big Endian format */ 905typedef struct _RPL { /* Structure is in Big Endian format */
865 uint32_t maxsize; 906 uint32_t maxsize;
866 uint32_t index; 907 uint32_t index;
diff --git a/drivers/scsi/lpfc/lpfc_hw4.h b/drivers/scsi/lpfc/lpfc_hw4.h
index bbdcf96800f6..6e4bc34e1d0d 100644
--- a/drivers/scsi/lpfc/lpfc_hw4.h
+++ b/drivers/scsi/lpfc/lpfc_hw4.h
@@ -424,79 +424,6 @@ struct lpfc_rcqe {
424#define FCOE_SOFn3 0x36 424#define FCOE_SOFn3 0x36
425}; 425};
426 426
427struct lpfc_wqe_generic{
428 struct ulp_bde64 bde;
429 uint32_t word3;
430 uint32_t word4;
431 uint32_t word5;
432 uint32_t word6;
433#define lpfc_wqe_gen_context_SHIFT 16
434#define lpfc_wqe_gen_context_MASK 0x0000FFFF
435#define lpfc_wqe_gen_context_WORD word6
436#define lpfc_wqe_gen_xri_SHIFT 0
437#define lpfc_wqe_gen_xri_MASK 0x0000FFFF
438#define lpfc_wqe_gen_xri_WORD word6
439 uint32_t word7;
440#define lpfc_wqe_gen_lnk_SHIFT 23
441#define lpfc_wqe_gen_lnk_MASK 0x00000001
442#define lpfc_wqe_gen_lnk_WORD word7
443#define lpfc_wqe_gen_erp_SHIFT 22
444#define lpfc_wqe_gen_erp_MASK 0x00000001
445#define lpfc_wqe_gen_erp_WORD word7
446#define lpfc_wqe_gen_pu_SHIFT 20
447#define lpfc_wqe_gen_pu_MASK 0x00000003
448#define lpfc_wqe_gen_pu_WORD word7
449#define lpfc_wqe_gen_class_SHIFT 16
450#define lpfc_wqe_gen_class_MASK 0x00000007
451#define lpfc_wqe_gen_class_WORD word7
452#define lpfc_wqe_gen_command_SHIFT 8
453#define lpfc_wqe_gen_command_MASK 0x000000FF
454#define lpfc_wqe_gen_command_WORD word7
455#define lpfc_wqe_gen_status_SHIFT 4
456#define lpfc_wqe_gen_status_MASK 0x0000000F
457#define lpfc_wqe_gen_status_WORD word7
458#define lpfc_wqe_gen_ct_SHIFT 2
459#define lpfc_wqe_gen_ct_MASK 0x00000003
460#define lpfc_wqe_gen_ct_WORD word7
461 uint32_t abort_tag;
462 uint32_t word9;
463#define lpfc_wqe_gen_request_tag_SHIFT 0
464#define lpfc_wqe_gen_request_tag_MASK 0x0000FFFF
465#define lpfc_wqe_gen_request_tag_WORD word9
466 uint32_t word10;
467#define lpfc_wqe_gen_ccp_SHIFT 24
468#define lpfc_wqe_gen_ccp_MASK 0x000000FF
469#define lpfc_wqe_gen_ccp_WORD word10
470#define lpfc_wqe_gen_ccpe_SHIFT 23
471#define lpfc_wqe_gen_ccpe_MASK 0x00000001
472#define lpfc_wqe_gen_ccpe_WORD word10
473#define lpfc_wqe_gen_pv_SHIFT 19
474#define lpfc_wqe_gen_pv_MASK 0x00000001
475#define lpfc_wqe_gen_pv_WORD word10
476#define lpfc_wqe_gen_pri_SHIFT 16
477#define lpfc_wqe_gen_pri_MASK 0x00000007
478#define lpfc_wqe_gen_pri_WORD word10
479 uint32_t word11;
480#define lpfc_wqe_gen_cq_id_SHIFT 16
481#define lpfc_wqe_gen_cq_id_MASK 0x0000FFFF
482#define lpfc_wqe_gen_cq_id_WORD word11
483#define LPFC_WQE_CQ_ID_DEFAULT 0xffff
484#define lpfc_wqe_gen_wqec_SHIFT 7
485#define lpfc_wqe_gen_wqec_MASK 0x00000001
486#define lpfc_wqe_gen_wqec_WORD word11
487#define ELS_ID_FLOGI 3
488#define ELS_ID_FDISC 2
489#define ELS_ID_LOGO 1
490#define ELS_ID_DEFAULT 0
491#define lpfc_wqe_gen_els_id_SHIFT 4
492#define lpfc_wqe_gen_els_id_MASK 0x00000003
493#define lpfc_wqe_gen_els_id_WORD word11
494#define lpfc_wqe_gen_cmd_type_SHIFT 0
495#define lpfc_wqe_gen_cmd_type_MASK 0x0000000F
496#define lpfc_wqe_gen_cmd_type_WORD word11
497 uint32_t payload[4];
498};
499
500struct lpfc_rqe { 427struct lpfc_rqe {
501 uint32_t address_hi; 428 uint32_t address_hi;
502 uint32_t address_lo; 429 uint32_t address_lo;
@@ -2279,9 +2206,36 @@ struct wqe_common {
2279#define wqe_reqtag_MASK 0x0000FFFF 2206#define wqe_reqtag_MASK 0x0000FFFF
2280#define wqe_reqtag_WORD word9 2207#define wqe_reqtag_WORD word9
2281#define wqe_rcvoxid_SHIFT 16 2208#define wqe_rcvoxid_SHIFT 16
2282#define wqe_rcvoxid_MASK 0x0000FFFF 2209#define wqe_rcvoxid_MASK 0x0000FFFF
2283#define wqe_rcvoxid_WORD word9 2210#define wqe_rcvoxid_WORD word9
2284 uint32_t word10; 2211 uint32_t word10;
2212#define wqe_ebde_cnt_SHIFT 0
2213#define wqe_ebde_cnt_MASK 0x00000007
2214#define wqe_ebde_cnt_WORD word10
2215#define wqe_lenloc_SHIFT 7
2216#define wqe_lenloc_MASK 0x00000003
2217#define wqe_lenloc_WORD word10
2218#define LPFC_WQE_LENLOC_NONE 0
2219#define LPFC_WQE_LENLOC_WORD3 1
2220#define LPFC_WQE_LENLOC_WORD12 2
2221#define LPFC_WQE_LENLOC_WORD4 3
2222#define wqe_qosd_SHIFT 9
2223#define wqe_qosd_MASK 0x00000001
2224#define wqe_qosd_WORD word10
2225#define wqe_xbl_SHIFT 11
2226#define wqe_xbl_MASK 0x00000001
2227#define wqe_xbl_WORD word10
2228#define wqe_iod_SHIFT 13
2229#define wqe_iod_MASK 0x00000001
2230#define wqe_iod_WORD word10
2231#define LPFC_WQE_IOD_WRITE 0
2232#define LPFC_WQE_IOD_READ 1
2233#define wqe_dbde_SHIFT 14
2234#define wqe_dbde_MASK 0x00000001
2235#define wqe_dbde_WORD word10
2236#define wqe_wqes_SHIFT 15
2237#define wqe_wqes_MASK 0x00000001
2238#define wqe_wqes_WORD word10
2285#define wqe_pri_SHIFT 16 2239#define wqe_pri_SHIFT 16
2286#define wqe_pri_MASK 0x00000007 2240#define wqe_pri_MASK 0x00000007
2287#define wqe_pri_WORD word10 2241#define wqe_pri_WORD word10
@@ -2295,18 +2249,26 @@ struct wqe_common {
2295#define wqe_ccpe_MASK 0x00000001 2249#define wqe_ccpe_MASK 0x00000001
2296#define wqe_ccpe_WORD word10 2250#define wqe_ccpe_WORD word10
2297#define wqe_ccp_SHIFT 24 2251#define wqe_ccp_SHIFT 24
2298#define wqe_ccp_MASK 0x000000ff 2252#define wqe_ccp_MASK 0x000000ff
2299#define wqe_ccp_WORD word10 2253#define wqe_ccp_WORD word10
2300 uint32_t word11; 2254 uint32_t word11;
2301#define wqe_cmd_type_SHIFT 0 2255#define wqe_cmd_type_SHIFT 0
2302#define wqe_cmd_type_MASK 0x0000000f 2256#define wqe_cmd_type_MASK 0x0000000f
2303#define wqe_cmd_type_WORD word11 2257#define wqe_cmd_type_WORD word11
2304#define wqe_wqec_SHIFT 7 2258#define wqe_els_id_SHIFT 4
2305#define wqe_wqec_MASK 0x00000001 2259#define wqe_els_id_MASK 0x00000003
2306#define wqe_wqec_WORD word11 2260#define wqe_els_id_WORD word11
2307#define wqe_cqid_SHIFT 16 2261#define LPFC_ELS_ID_FLOGI 3
2308#define wqe_cqid_MASK 0x0000ffff 2262#define LPFC_ELS_ID_FDISC 2
2309#define wqe_cqid_WORD word11 2263#define LPFC_ELS_ID_LOGO 1
2264#define LPFC_ELS_ID_DEFAULT 0
2265#define wqe_wqec_SHIFT 7
2266#define wqe_wqec_MASK 0x00000001
2267#define wqe_wqec_WORD word11
2268#define wqe_cqid_SHIFT 16
2269#define wqe_cqid_MASK 0x0000ffff
2270#define wqe_cqid_WORD word11
2271#define LPFC_WQE_CQ_ID_DEFAULT 0xffff
2310}; 2272};
2311 2273
2312struct wqe_did { 2274struct wqe_did {
@@ -2325,6 +2287,15 @@ struct wqe_did {
2325#define wqe_xmit_bls_xo_WORD word5 2287#define wqe_xmit_bls_xo_WORD word5
2326}; 2288};
2327 2289
2290struct lpfc_wqe_generic{
2291 struct ulp_bde64 bde;
2292 uint32_t word3;
2293 uint32_t word4;
2294 uint32_t word5;
2295 struct wqe_common wqe_com;
2296 uint32_t payload[4];
2297};
2298
2328struct els_request64_wqe { 2299struct els_request64_wqe {
2329 struct ulp_bde64 bde; 2300 struct ulp_bde64 bde;
2330 uint32_t payload_len; 2301 uint32_t payload_len;
@@ -2356,9 +2327,9 @@ struct els_request64_wqe {
2356 2327
2357struct xmit_els_rsp64_wqe { 2328struct xmit_els_rsp64_wqe {
2358 struct ulp_bde64 bde; 2329 struct ulp_bde64 bde;
2359 uint32_t rsvd3; 2330 uint32_t response_payload_len;
2360 uint32_t rsvd4; 2331 uint32_t rsvd4;
2361 struct wqe_did wqe_dest; 2332 struct wqe_did wqe_dest;
2362 struct wqe_common wqe_com; /* words 6-11 */ 2333 struct wqe_common wqe_com; /* words 6-11 */
2363 uint32_t rsvd_12_15[4]; 2334 uint32_t rsvd_12_15[4];
2364}; 2335};
@@ -2427,7 +2398,7 @@ struct wqe_rctl_dfctl {
2427 2398
2428struct xmit_seq64_wqe { 2399struct xmit_seq64_wqe {
2429 struct ulp_bde64 bde; 2400 struct ulp_bde64 bde;
2430 uint32_t paylaod_offset; 2401 uint32_t rsvd3;
2431 uint32_t relative_offset; 2402 uint32_t relative_offset;
2432 struct wqe_rctl_dfctl wge_ctl; 2403 struct wqe_rctl_dfctl wge_ctl;
2433 struct wqe_common wqe_com; /* words 6-11 */ 2404 struct wqe_common wqe_com; /* words 6-11 */
@@ -2437,7 +2408,7 @@ struct xmit_seq64_wqe {
2437}; 2408};
2438struct xmit_bcast64_wqe { 2409struct xmit_bcast64_wqe {
2439 struct ulp_bde64 bde; 2410 struct ulp_bde64 bde;
2440 uint32_t paylaod_len; 2411 uint32_t seq_payload_len;
2441 uint32_t rsvd4; 2412 uint32_t rsvd4;
2442 struct wqe_rctl_dfctl wge_ctl; /* word 5 */ 2413 struct wqe_rctl_dfctl wge_ctl; /* word 5 */
2443 struct wqe_common wqe_com; /* words 6-11 */ 2414 struct wqe_common wqe_com; /* words 6-11 */
@@ -2446,8 +2417,8 @@ struct xmit_bcast64_wqe {
2446 2417
2447struct gen_req64_wqe { 2418struct gen_req64_wqe {
2448 struct ulp_bde64 bde; 2419 struct ulp_bde64 bde;
2449 uint32_t command_len; 2420 uint32_t request_payload_len;
2450 uint32_t payload_len; 2421 uint32_t relative_offset;
2451 struct wqe_rctl_dfctl wge_ctl; /* word 5 */ 2422 struct wqe_rctl_dfctl wge_ctl; /* word 5 */
2452 struct wqe_common wqe_com; /* words 6-11 */ 2423 struct wqe_common wqe_com; /* words 6-11 */
2453 uint32_t rsvd_12_15[4]; 2424 uint32_t rsvd_12_15[4];
@@ -2480,7 +2451,7 @@ struct abort_cmd_wqe {
2480 2451
2481struct fcp_iwrite64_wqe { 2452struct fcp_iwrite64_wqe {
2482 struct ulp_bde64 bde; 2453 struct ulp_bde64 bde;
2483 uint32_t payload_len; 2454 uint32_t payload_offset_len;
2484 uint32_t total_xfer_len; 2455 uint32_t total_xfer_len;
2485 uint32_t initial_xfer_len; 2456 uint32_t initial_xfer_len;
2486 struct wqe_common wqe_com; /* words 6-11 */ 2457 struct wqe_common wqe_com; /* words 6-11 */
@@ -2489,7 +2460,7 @@ struct fcp_iwrite64_wqe {
2489 2460
2490struct fcp_iread64_wqe { 2461struct fcp_iread64_wqe {
2491 struct ulp_bde64 bde; 2462 struct ulp_bde64 bde;
2492 uint32_t payload_len; /* word 3 */ 2463 uint32_t payload_offset_len; /* word 3 */
2493 uint32_t total_xfer_len; /* word 4 */ 2464 uint32_t total_xfer_len; /* word 4 */
2494 uint32_t rsrvd5; /* word 5 */ 2465 uint32_t rsrvd5; /* word 5 */
2495 struct wqe_common wqe_com; /* words 6-11 */ 2466 struct wqe_common wqe_com; /* words 6-11 */
@@ -2497,10 +2468,12 @@ struct fcp_iread64_wqe {
2497}; 2468};
2498 2469
2499struct fcp_icmnd64_wqe { 2470struct fcp_icmnd64_wqe {
2500 struct ulp_bde64 bde; /* words 0-2 */ 2471 struct ulp_bde64 bde; /* words 0-2 */
2501 uint32_t rsrvd[3]; /* words 3-5 */ 2472 uint32_t rsrvd3; /* word 3 */
2473 uint32_t rsrvd4; /* word 4 */
2474 uint32_t rsrvd5; /* word 5 */
2502 struct wqe_common wqe_com; /* words 6-11 */ 2475 struct wqe_common wqe_com; /* words 6-11 */
2503 uint32_t rsvd_12_15[4]; /* word 12-15 */ 2476 uint32_t rsvd_12_15[4]; /* word 12-15 */
2504}; 2477};
2505 2478
2506 2479
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 295c7ddb36c1..b3065791f303 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -813,6 +813,7 @@ lpfc_hba_down_post_s3(struct lpfc_hba *phba)
813 813
814 return 0; 814 return 0;
815} 815}
816
816/** 817/**
817 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset 818 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
818 * @phba: pointer to lpfc HBA data structure. 819 * @phba: pointer to lpfc HBA data structure.
@@ -2234,10 +2235,9 @@ lpfc_stop_vport_timers(struct lpfc_vport *vport)
2234void 2235void
2235__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) 2236__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2236{ 2237{
2237 /* Clear pending FCF rediscovery wait and failover in progress flags */ 2238 /* Clear pending FCF rediscovery wait flag */
2238 phba->fcf.fcf_flag &= ~(FCF_REDISC_PEND | 2239 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2239 FCF_DEAD_DISC | 2240
2240 FCF_ACVL_DISC);
2241 /* Now, try to stop the timer */ 2241 /* Now, try to stop the timer */
2242 del_timer(&phba->fcf.redisc_wait); 2242 del_timer(&phba->fcf.redisc_wait);
2243} 2243}
@@ -2261,6 +2261,8 @@ lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2261 return; 2261 return;
2262 } 2262 }
2263 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); 2263 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2264 /* Clear failover in progress flags */
2265 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
2264 spin_unlock_irq(&phba->hbalock); 2266 spin_unlock_irq(&phba->hbalock);
2265} 2267}
2266 2268
@@ -2935,8 +2937,7 @@ lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
2935 phba->fcf.fcf_flag |= FCF_REDISC_EVT; 2937 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
2936 spin_unlock_irq(&phba->hbalock); 2938 spin_unlock_irq(&phba->hbalock);
2937 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 2939 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2938 "2776 FCF rediscover wait timer expired, post " 2940 "2776 FCF rediscover quiescent timer expired\n");
2939 "a worker thread event for FCF table scan\n");
2940 /* wake up worker thread */ 2941 /* wake up worker thread */
2941 lpfc_worker_wake_up(phba); 2942 lpfc_worker_wake_up(phba);
2942} 2943}
@@ -3311,35 +3312,34 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3311 if (event_type == LPFC_FCOE_EVENT_TYPE_NEW_FCF) 3312 if (event_type == LPFC_FCOE_EVENT_TYPE_NEW_FCF)
3312 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | 3313 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
3313 LOG_DISCOVERY, 3314 LOG_DISCOVERY,
3314 "2546 New FCF found event: " 3315 "2546 New FCF event, evt_tag:x%x, "
3315 "evt_tag:x%x, fcf_index:x%x\n", 3316 "index:x%x\n",
3316 acqe_fcoe->event_tag, 3317 acqe_fcoe->event_tag,
3317 acqe_fcoe->index); 3318 acqe_fcoe->index);
3318 else 3319 else
3319 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | 3320 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
3320 LOG_DISCOVERY, 3321 LOG_DISCOVERY,
3321 "2788 FCF parameter modified event: " 3322 "2788 FCF param modified event, "
3322 "evt_tag:x%x, fcf_index:x%x\n", 3323 "evt_tag:x%x, index:x%x\n",
3323 acqe_fcoe->event_tag, 3324 acqe_fcoe->event_tag,
3324 acqe_fcoe->index); 3325 acqe_fcoe->index);
3325 if (phba->fcf.fcf_flag & FCF_DISCOVERY) { 3326 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3326 /* 3327 /*
3327 * During period of FCF discovery, read the FCF 3328 * During period of FCF discovery, read the FCF
3328 * table record indexed by the event to update 3329 * table record indexed by the event to update
3329 * FCF round robin failover eligible FCF bmask. 3330 * FCF roundrobin failover eligible FCF bmask.
3330 */ 3331 */
3331 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | 3332 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
3332 LOG_DISCOVERY, 3333 LOG_DISCOVERY,
3333 "2779 Read new FCF record with " 3334 "2779 Read FCF (x%x) for updating "
3334 "fcf_index:x%x for updating FCF " 3335 "roundrobin FCF failover bmask\n",
3335 "round robin failover bmask\n",
3336 acqe_fcoe->index); 3336 acqe_fcoe->index);
3337 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fcoe->index); 3337 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fcoe->index);
3338 } 3338 }
3339 3339
3340 /* If the FCF discovery is in progress, do nothing. */ 3340 /* If the FCF discovery is in progress, do nothing. */
3341 spin_lock_irq(&phba->hbalock); 3341 spin_lock_irq(&phba->hbalock);
3342 if (phba->hba_flag & FCF_DISC_INPROGRESS) { 3342 if (phba->hba_flag & FCF_TS_INPROG) {
3343 spin_unlock_irq(&phba->hbalock); 3343 spin_unlock_irq(&phba->hbalock);
3344 break; 3344 break;
3345 } 3345 }
@@ -3358,15 +3358,15 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3358 3358
3359 /* Otherwise, scan the entire FCF table and re-discover SAN */ 3359 /* Otherwise, scan the entire FCF table and re-discover SAN */
3360 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, 3360 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3361 "2770 Start FCF table scan due to new FCF " 3361 "2770 Start FCF table scan per async FCF "
3362 "event: evt_tag:x%x, fcf_index:x%x\n", 3362 "event, evt_tag:x%x, index:x%x\n",
3363 acqe_fcoe->event_tag, acqe_fcoe->index); 3363 acqe_fcoe->event_tag, acqe_fcoe->index);
3364 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, 3364 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3365 LPFC_FCOE_FCF_GET_FIRST); 3365 LPFC_FCOE_FCF_GET_FIRST);
3366 if (rc) 3366 if (rc)
3367 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, 3367 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
3368 "2547 Issue FCF scan read FCF mailbox " 3368 "2547 Issue FCF scan read FCF mailbox "
3369 "command failed 0x%x\n", rc); 3369 "command failed (x%x)\n", rc);
3370 break; 3370 break;
3371 3371
3372 case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL: 3372 case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL:
@@ -3378,9 +3378,8 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3378 3378
3379 case LPFC_FCOE_EVENT_TYPE_FCF_DEAD: 3379 case LPFC_FCOE_EVENT_TYPE_FCF_DEAD:
3380 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, 3380 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
3381 "2549 FCF disconnected from network index 0x%x" 3381 "2549 FCF (x%x) disconnected from network, "
3382 " tag 0x%x\n", acqe_fcoe->index, 3382 "tag:x%x\n", acqe_fcoe->index, acqe_fcoe->event_tag);
3383 acqe_fcoe->event_tag);
3384 /* 3383 /*
3385 * If we are in the middle of FCF failover process, clear 3384 * If we are in the middle of FCF failover process, clear
3386 * the corresponding FCF bit in the roundrobin bitmap. 3385 * the corresponding FCF bit in the roundrobin bitmap.
@@ -3494,9 +3493,8 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3494 spin_unlock_irq(&phba->hbalock); 3493 spin_unlock_irq(&phba->hbalock);
3495 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | 3494 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
3496 LOG_DISCOVERY, 3495 LOG_DISCOVERY,
3497 "2773 Start FCF fast failover due " 3496 "2773 Start FCF failover per CVL, "
3498 "to CVL event: evt_tag:x%x\n", 3497 "evt_tag:x%x\n", acqe_fcoe->event_tag);
3499 acqe_fcoe->event_tag);
3500 rc = lpfc_sli4_redisc_fcf_table(phba); 3498 rc = lpfc_sli4_redisc_fcf_table(phba);
3501 if (rc) { 3499 if (rc) {
3502 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | 3500 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
@@ -3646,8 +3644,7 @@ void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
3646 3644
3647 /* Scan FCF table from the first entry to re-discover SAN */ 3645 /* Scan FCF table from the first entry to re-discover SAN */
3648 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, 3646 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3649 "2777 Start FCF table scan after FCF " 3647 "2777 Start post-quiescent FCF table scan\n");
3650 "rediscovery quiescent period over\n");
3651 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); 3648 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
3652 if (rc) 3649 if (rc)
3653 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, 3650 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
@@ -4165,7 +4162,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4165 goto out_free_active_sgl; 4162 goto out_free_active_sgl;
4166 } 4163 }
4167 4164
4168 /* Allocate eligible FCF bmask memory for FCF round robin failover */ 4165 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
4169 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; 4166 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
4170 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), 4167 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
4171 GFP_KERNEL); 4168 GFP_KERNEL);
@@ -7271,6 +7268,51 @@ lpfc_sli4_unset_hba(struct lpfc_hba *phba)
7271} 7268}
7272 7269
7273/** 7270/**
7271 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
7272 * @phba: Pointer to HBA context object.
7273 *
7274 * This function is called in the SLI4 code path to wait for completion
7275 * of device's XRIs exchange busy. It will check the XRI exchange busy
7276 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
7277 * that, it will check the XRI exchange busy on outstanding FCP and ELS
7278 * I/Os every 30 seconds, log error message, and wait forever. Only when
7279 * all XRI exchange busy complete, the driver unload shall proceed with
7280 * invoking the function reset ioctl mailbox command to the CNA and the
7281 * the rest of the driver unload resource release.
7282 **/
7283static void
7284lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
7285{
7286 int wait_time = 0;
7287 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
7288 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
7289
7290 while (!fcp_xri_cmpl || !els_xri_cmpl) {
7291 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
7292 if (!fcp_xri_cmpl)
7293 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7294 "2877 FCP XRI exchange busy "
7295 "wait time: %d seconds.\n",
7296 wait_time/1000);
7297 if (!els_xri_cmpl)
7298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7299 "2878 ELS XRI exchange busy "
7300 "wait time: %d seconds.\n",
7301 wait_time/1000);
7302 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
7303 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
7304 } else {
7305 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
7306 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
7307 }
7308 fcp_xri_cmpl =
7309 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
7310 els_xri_cmpl =
7311 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
7312 }
7313}
7314
7315/**
7274 * lpfc_sli4_hba_unset - Unset the fcoe hba 7316 * lpfc_sli4_hba_unset - Unset the fcoe hba
7275 * @phba: Pointer to HBA context object. 7317 * @phba: Pointer to HBA context object.
7276 * 7318 *
@@ -7315,6 +7357,12 @@ lpfc_sli4_hba_unset(struct lpfc_hba *phba)
7315 spin_unlock_irq(&phba->hbalock); 7357 spin_unlock_irq(&phba->hbalock);
7316 } 7358 }
7317 7359
7360 /* Abort all iocbs associated with the hba */
7361 lpfc_sli_hba_iocb_abort(phba);
7362
7363 /* Wait for completion of device XRI exchange busy */
7364 lpfc_sli4_xri_exchange_busy_wait(phba);
7365
7318 /* Disable PCI subsystem interrupt */ 7366 /* Disable PCI subsystem interrupt */
7319 lpfc_sli4_disable_intr(phba); 7367 lpfc_sli4_disable_intr(phba);
7320 7368
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index 0dfa310cd609..62d0957e1d4c 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -797,6 +797,34 @@ lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
797} 797}
798 798
799/** 799/**
800 * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
801 * @vport: pointer to a vport object.
802 *
803 * This routine sends mailbox command to unregister all active RPIs for
804 * a vport.
805 **/
806void
807lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport)
808{
809 struct lpfc_hba *phba = vport->phba;
810 LPFC_MBOXQ_t *mbox;
811 int rc;
812
813 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
814 if (mbox) {
815 lpfc_unreg_login(phba, vport->vpi,
816 vport->vpi + phba->vpi_base, mbox);
817 mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000 ;
818 mbox->vport = vport;
819 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
820 mbox->context1 = NULL;
821 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
822 if (rc == MBX_NOT_FINISHED)
823 mempool_free(mbox, phba->mbox_mem_pool);
824 }
825}
826
827/**
800 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier 828 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
801 * @phba: pointer to lpfc hba data structure. 829 * @phba: pointer to lpfc hba data structure.
802 * @vpi: virtual N_Port identifier. 830 * @vpi: virtual N_Port identifier.
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 3a658953486c..581837b3c71a 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -169,6 +169,7 @@ lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
169 spin_lock_irqsave(shost->host_lock, flags); 169 spin_lock_irqsave(shost->host_lock, flags);
170 if (!vport->stat_data_enabled || 170 if (!vport->stat_data_enabled ||
171 vport->stat_data_blocked || 171 vport->stat_data_blocked ||
172 !pnode ||
172 !pnode->lat_data || 173 !pnode->lat_data ||
173 (phba->bucket_type == LPFC_NO_BUCKET)) { 174 (phba->bucket_type == LPFC_NO_BUCKET)) {
174 spin_unlock_irqrestore(shost->host_lock, flags); 175 spin_unlock_irqrestore(shost->host_lock, flags);
@@ -2040,6 +2041,9 @@ lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
2040 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; 2041 struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
2041 unsigned long flags; 2042 unsigned long flags;
2042 2043
2044 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
2045 return;
2046
2043 /* If there is queuefull or busy condition send a scsi event */ 2047 /* If there is queuefull or busy condition send a scsi event */
2044 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || 2048 if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
2045 (cmnd->result == SAM_STAT_BUSY)) { 2049 (cmnd->result == SAM_STAT_BUSY)) {
@@ -2895,7 +2899,7 @@ void lpfc_poll_timeout(unsigned long ptr)
2895 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. 2899 * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
2896 **/ 2900 **/
2897static int 2901static int
2898lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) 2902lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
2899{ 2903{
2900 struct Scsi_Host *shost = cmnd->device->host; 2904 struct Scsi_Host *shost = cmnd->device->host;
2901 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2905 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
@@ -3056,6 +3060,8 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
3056 return 0; 3060 return 0;
3057} 3061}
3058 3062
3063static DEF_SCSI_QCMD(lpfc_queuecommand)
3064
3059/** 3065/**
3060 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point 3066 * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
3061 * @cmnd: Pointer to scsi_cmnd data structure. 3067 * @cmnd: Pointer to scsi_cmnd data structure.
@@ -3226,10 +3232,11 @@ lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
3226 struct lpfc_scsi_buf *lpfc_cmd; 3232 struct lpfc_scsi_buf *lpfc_cmd;
3227 struct lpfc_iocbq *iocbq; 3233 struct lpfc_iocbq *iocbq;
3228 struct lpfc_iocbq *iocbqrsp; 3234 struct lpfc_iocbq *iocbqrsp;
3235 struct lpfc_nodelist *pnode = rdata->pnode;
3229 int ret; 3236 int ret;
3230 int status; 3237 int status;
3231 3238
3232 if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) 3239 if (!pnode || !NLP_CHK_NODE_ACT(pnode))
3233 return FAILED; 3240 return FAILED;
3234 3241
3235 lpfc_cmd = lpfc_get_scsi_buf(phba); 3242 lpfc_cmd = lpfc_get_scsi_buf(phba);
@@ -3256,7 +3263,7 @@ lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
3256 "0702 Issue %s to TGT %d LUN %d " 3263 "0702 Issue %s to TGT %d LUN %d "
3257 "rpi x%x nlp_flag x%x\n", 3264 "rpi x%x nlp_flag x%x\n",
3258 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, 3265 lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
3259 rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag); 3266 pnode->nlp_rpi, pnode->nlp_flag);
3260 3267
3261 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, 3268 status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
3262 iocbq, iocbqrsp, lpfc_cmd->timeout); 3269 iocbq, iocbqrsp, lpfc_cmd->timeout);
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index c5614cfcc6e9..22f17087883c 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -95,7 +95,7 @@ lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
95 return -ENOMEM; 95 return -ENOMEM;
96 /* set consumption flag every once in a while */ 96 /* set consumption flag every once in a while */
97 if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL)) 97 if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
98 bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1); 98 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
99 99
100 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); 100 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
101 101
@@ -1735,6 +1735,7 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1735 struct lpfc_vport *vport = pmb->vport; 1735 struct lpfc_vport *vport = pmb->vport;
1736 struct lpfc_dmabuf *mp; 1736 struct lpfc_dmabuf *mp;
1737 struct lpfc_nodelist *ndlp; 1737 struct lpfc_nodelist *ndlp;
1738 struct Scsi_Host *shost;
1738 uint16_t rpi, vpi; 1739 uint16_t rpi, vpi;
1739 int rc; 1740 int rc;
1740 1741
@@ -1746,7 +1747,8 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1746 } 1747 }
1747 1748
1748 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && 1749 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
1749 (phba->sli_rev == LPFC_SLI_REV4)) 1750 (phba->sli_rev == LPFC_SLI_REV4) &&
1751 (pmb->u.mb.un.varUnregLogin.rsvd1 == 0x0))
1750 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); 1752 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
1751 1753
1752 /* 1754 /*
@@ -1765,16 +1767,14 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1765 return; 1767 return;
1766 } 1768 }
1767 1769
1768 /* Unreg VPI, if the REG_VPI succeed after VLink failure */
1769 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && 1770 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
1770 !(phba->pport->load_flag & FC_UNLOADING) && 1771 !(phba->pport->load_flag & FC_UNLOADING) &&
1771 !pmb->u.mb.mbxStatus) { 1772 !pmb->u.mb.mbxStatus) {
1772 lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb); 1773 shost = lpfc_shost_from_vport(vport);
1773 pmb->vport = vport; 1774 spin_lock_irq(shost->host_lock);
1774 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 1775 vport->vpi_state |= LPFC_VPI_REGISTERED;
1775 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); 1776 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
1776 if (rc != MBX_NOT_FINISHED) 1777 spin_unlock_irq(shost->host_lock);
1777 return;
1778 } 1778 }
1779 1779
1780 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { 1780 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
@@ -5921,7 +5921,7 @@ lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
5921 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution 5921 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
5922 * @phba: Pointer to HBA context object. 5922 * @phba: Pointer to HBA context object.
5923 * 5923 *
5924 * This routine performs a round robin SCSI command to SLI4 FCP WQ index 5924 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
5925 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock 5925 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
5926 * held. 5926 * held.
5927 * 5927 *
@@ -5965,7 +5965,7 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
5965 uint16_t abrt_iotag; 5965 uint16_t abrt_iotag;
5966 struct lpfc_iocbq *abrtiocbq; 5966 struct lpfc_iocbq *abrtiocbq;
5967 struct ulp_bde64 *bpl = NULL; 5967 struct ulp_bde64 *bpl = NULL;
5968 uint32_t els_id = ELS_ID_DEFAULT; 5968 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
5969 int numBdes, i; 5969 int numBdes, i;
5970 struct ulp_bde64 bde; 5970 struct ulp_bde64 bde;
5971 5971
@@ -5982,7 +5982,7 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
5982 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); 5982 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
5983 abort_tag = (uint32_t) iocbq->iotag; 5983 abort_tag = (uint32_t) iocbq->iotag;
5984 xritag = iocbq->sli4_xritag; 5984 xritag = iocbq->sli4_xritag;
5985 wqe->words[7] = 0; /* The ct field has moved so reset */ 5985 wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
5986 /* words0-2 bpl convert bde */ 5986 /* words0-2 bpl convert bde */
5987 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { 5987 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
5988 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / 5988 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
@@ -6033,109 +6033,117 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
6033 * contains the FCFI and remote N_Port_ID is 6033 * contains the FCFI and remote N_Port_ID is
6034 * in word 5. 6034 * in word 5.
6035 */ 6035 */
6036
6037 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); 6036 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
6038 bf_set(lpfc_wqe_gen_context, &wqe->generic, 6037 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
6039 iocbq->iocb.ulpContext); 6038 iocbq->iocb.ulpContext);
6040 6039 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
6041 bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct); 6040 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
6042 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
6043 /* CCP CCPE PV PRI in word10 were set in the memcpy */ 6041 /* CCP CCPE PV PRI in word10 were set in the memcpy */
6044
6045 if (command_type == ELS_COMMAND_FIP) { 6042 if (command_type == ELS_COMMAND_FIP) {
6046 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) 6043 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
6047 >> LPFC_FIP_ELS_ID_SHIFT); 6044 >> LPFC_FIP_ELS_ID_SHIFT);
6048 } 6045 }
6049 bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id); 6046 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
6050 6047 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
6048 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
6049 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
6050 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
6051 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
6051 break; 6052 break;
6052 case CMD_XMIT_SEQUENCE64_CX: 6053 case CMD_XMIT_SEQUENCE64_CX:
6053 bf_set(lpfc_wqe_gen_context, &wqe->generic, 6054 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
6054 iocbq->iocb.un.ulpWord[3]); 6055 iocbq->iocb.un.ulpWord[3]);
6055 wqe->generic.word3 = 0; 6056 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
6056 bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext); 6057 iocbq->iocb.ulpContext);
6057 /* The entire sequence is transmitted for this IOCB */ 6058 /* The entire sequence is transmitted for this IOCB */
6058 xmit_len = total_len; 6059 xmit_len = total_len;
6059 cmnd = CMD_XMIT_SEQUENCE64_CR; 6060 cmnd = CMD_XMIT_SEQUENCE64_CR;
6060 case CMD_XMIT_SEQUENCE64_CR: 6061 case CMD_XMIT_SEQUENCE64_CR:
6061 /* word3 iocb=io_tag32 wqe=payload_offset */ 6062 /* word3 iocb=io_tag32 wqe=reserved */
6062 /* payload offset used for multilpe outstanding 6063 wqe->xmit_sequence.rsvd3 = 0;
6063 * sequences on the same exchange
6064 */
6065 wqe->words[3] = 0;
6066 /* word4 relative_offset memcpy */ 6064 /* word4 relative_offset memcpy */
6067 /* word5 r_ctl/df_ctl memcpy */ 6065 /* word5 r_ctl/df_ctl memcpy */
6068 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0); 6066 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
6067 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
6068 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
6069 LPFC_WQE_IOD_WRITE);
6070 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
6071 LPFC_WQE_LENLOC_WORD12);
6072 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
6069 wqe->xmit_sequence.xmit_len = xmit_len; 6073 wqe->xmit_sequence.xmit_len = xmit_len;
6070 command_type = OTHER_COMMAND; 6074 command_type = OTHER_COMMAND;
6071 break; 6075 break;
6072 case CMD_XMIT_BCAST64_CN: 6076 case CMD_XMIT_BCAST64_CN:
6073 /* word3 iocb=iotag32 wqe=payload_len */ 6077 /* word3 iocb=iotag32 wqe=seq_payload_len */
6074 wqe->words[3] = 0; /* no definition for this in wqe */ 6078 wqe->xmit_bcast64.seq_payload_len = xmit_len;
6075 /* word4 iocb=rsvd wqe=rsvd */ 6079 /* word4 iocb=rsvd wqe=rsvd */
6076 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ 6080 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
6077 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ 6081 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
6078 bf_set(lpfc_wqe_gen_ct, &wqe->generic, 6082 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
6079 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); 6083 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
6084 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
6085 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
6086 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
6087 LPFC_WQE_LENLOC_WORD3);
6088 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
6080 break; 6089 break;
6081 case CMD_FCP_IWRITE64_CR: 6090 case CMD_FCP_IWRITE64_CR:
6082 command_type = FCP_COMMAND_DATA_OUT; 6091 command_type = FCP_COMMAND_DATA_OUT;
6083 /* The struct for wqe fcp_iwrite has 3 fields that are somewhat 6092 /* word3 iocb=iotag wqe=payload_offset_len */
6084 * confusing. 6093 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
6085 * word3 is payload_len: byte offset to the sgl entry for the 6094 wqe->fcp_iwrite.payload_offset_len =
6086 * fcp_command. 6095 xmit_len + sizeof(struct fcp_rsp);
6087 * word4 is total xfer len, same as the IOCB->ulpParameter. 6096 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
6088 * word5 is initial xfer len 0 = wait for xfer-ready 6097 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
6089 */ 6098 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
6090 6099 iocbq->iocb.ulpFCP2Rcvy);
6091 /* Always wait for xfer-ready before sending data */ 6100 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
6092 wqe->fcp_iwrite.initial_xfer_len = 0; 6101 /* Always open the exchange */
6093 /* word 4 (xfer length) should have been set on the memcpy */ 6102 bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
6094 6103 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
6095 /* allow write to fall through to read */ 6104 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
6105 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
6106 LPFC_WQE_LENLOC_WORD4);
6107 bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
6108 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
6109 break;
6096 case CMD_FCP_IREAD64_CR: 6110 case CMD_FCP_IREAD64_CR:
6097 /* FCP_CMD is always the 1st sgl entry */ 6111 /* word3 iocb=iotag wqe=payload_offset_len */
6098 wqe->fcp_iread.payload_len = 6112 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
6113 wqe->fcp_iread.payload_offset_len =
6099 xmit_len + sizeof(struct fcp_rsp); 6114 xmit_len + sizeof(struct fcp_rsp);
6100 6115 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
6101 /* word 4 (xfer length) should have been set on the memcpy */ 6116 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
6102 6117 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
6103 bf_set(lpfc_wqe_gen_erp, &wqe->generic, 6118 iocbq->iocb.ulpFCP2Rcvy);
6104 iocbq->iocb.ulpFCP2Rcvy); 6119 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
6105 bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
6106 /* The XC bit and the XS bit are similar. The driver never
6107 * tracked whether or not the exchange was previouslly open.
6108 * XC = Exchange create, 0 is create. 1 is already open.
6109 * XS = link cmd: 1 do not close the exchange after command.
6110 * XS = 0 close exchange when command completes.
6111 * The only time we would not set the XC bit is when the XS bit
6112 * is set and we are sending our 2nd or greater command on
6113 * this exchange.
6114 */
6115 /* Always open the exchange */ 6120 /* Always open the exchange */
6116 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); 6121 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
6117 6122 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
6118 wqe->words[10] &= 0xffff0000; /* zero out ebde count */ 6123 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
6119 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); 6124 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
6120 break; 6125 LPFC_WQE_LENLOC_WORD4);
6126 bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
6127 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
6128 break;
6121 case CMD_FCP_ICMND64_CR: 6129 case CMD_FCP_ICMND64_CR:
6130 /* word3 iocb=IO_TAG wqe=reserved */
6131 wqe->fcp_icmd.rsrvd3 = 0;
6132 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
6122 /* Always open the exchange */ 6133 /* Always open the exchange */
6123 bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); 6134 bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
6124 6135 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
6125 wqe->words[4] = 0; 6136 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
6126 wqe->words[10] &= 0xffff0000; /* zero out ebde count */ 6137 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
6127 bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0); 6138 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
6139 LPFC_WQE_LENLOC_NONE);
6140 bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
6128 break; 6141 break;
6129 case CMD_GEN_REQUEST64_CR: 6142 case CMD_GEN_REQUEST64_CR:
6130 /* word3 command length is described as byte offset to the 6143 /* word3 iocb=IO_TAG wqe=request_payload_len */
6131 * rsp_data. Would always be 16, sizeof(struct sli4_sge) 6144 wqe->gen_req.request_payload_len = xmit_len;
6132 * sgl[0] = cmnd 6145 /* word4 iocb=parameter wqe=relative_offset memcpy */
6133 * sgl[1] = rsp. 6146 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
6134 *
6135 */
6136 wqe->gen_req.command_len = xmit_len;
6137 /* Word4 parameter copied in the memcpy */
6138 /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
6139 /* word6 context tag copied in memcpy */ 6147 /* word6 context tag copied in memcpy */
6140 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { 6148 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
6141 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); 6149 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
@@ -6144,31 +6152,39 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
6144 ct, iocbq->iocb.ulpCommand); 6152 ct, iocbq->iocb.ulpCommand);
6145 return IOCB_ERROR; 6153 return IOCB_ERROR;
6146 } 6154 }
6147 bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0); 6155 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
6148 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, 6156 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
6149 iocbq->iocb.ulpTimeout); 6157 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
6150 6158 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
6151 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); 6159 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
6160 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
6161 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
6162 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
6152 command_type = OTHER_COMMAND; 6163 command_type = OTHER_COMMAND;
6153 break; 6164 break;
6154 case CMD_XMIT_ELS_RSP64_CX: 6165 case CMD_XMIT_ELS_RSP64_CX:
6155 /* words0-2 BDE memcpy */ 6166 /* words0-2 BDE memcpy */
6156 /* word3 iocb=iotag32 wqe=rsvd */ 6167 /* word3 iocb=iotag32 wqe=response_payload_len */
6157 wqe->words[3] = 0; 6168 wqe->xmit_els_rsp.response_payload_len = xmit_len;
6158 /* word4 iocb=did wge=rsvd. */ 6169 /* word4 iocb=did wge=rsvd. */
6159 wqe->words[4] = 0; 6170 wqe->xmit_els_rsp.rsvd4 = 0;
6160 /* word5 iocb=rsvd wge=did */ 6171 /* word5 iocb=rsvd wge=did */
6161 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, 6172 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
6162 iocbq->iocb.un.elsreq64.remoteID); 6173 iocbq->iocb.un.elsreq64.remoteID);
6163 6174 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
6164 bf_set(lpfc_wqe_gen_ct, &wqe->generic, 6175 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
6165 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); 6176 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
6166 6177 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6167 bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); 6178 iocbq->iocb.ulpContext);
6168 bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
6169 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) 6179 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
6170 bf_set(lpfc_wqe_gen_context, &wqe->generic, 6180 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
6171 iocbq->vport->vpi + phba->vpi_base); 6181 iocbq->vport->vpi + phba->vpi_base);
6182 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
6183 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
6184 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
6185 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
6186 LPFC_WQE_LENLOC_WORD3);
6187 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
6172 command_type = OTHER_COMMAND; 6188 command_type = OTHER_COMMAND;
6173 break; 6189 break;
6174 case CMD_CLOSE_XRI_CN: 6190 case CMD_CLOSE_XRI_CN:
@@ -6193,15 +6209,19 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
6193 else 6209 else
6194 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); 6210 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
6195 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); 6211 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
6196 wqe->words[5] = 0; 6212 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
6197 bf_set(lpfc_wqe_gen_ct, &wqe->generic, 6213 wqe->abort_cmd.rsrvd5 = 0;
6214 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
6198 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); 6215 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
6199 abort_tag = iocbq->iocb.un.acxri.abortIoTag; 6216 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
6200 /* 6217 /*
6201 * The abort handler will send us CMD_ABORT_XRI_CN or 6218 * The abort handler will send us CMD_ABORT_XRI_CN or
6202 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX 6219 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
6203 */ 6220 */
6204 bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX); 6221 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
6222 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
6223 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
6224 LPFC_WQE_LENLOC_NONE);
6205 cmnd = CMD_ABORT_XRI_CX; 6225 cmnd = CMD_ABORT_XRI_CX;
6206 command_type = OTHER_COMMAND; 6226 command_type = OTHER_COMMAND;
6207 xritag = 0; 6227 xritag = 0;
@@ -6235,18 +6255,14 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
6235 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); 6255 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
6236 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, 6256 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
6237 iocbq->iocb.ulpContext); 6257 iocbq->iocb.ulpContext);
6258 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
6259 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
6260 LPFC_WQE_LENLOC_NONE);
6238 /* Overwrite the pre-set comnd type with OTHER_COMMAND */ 6261 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
6239 command_type = OTHER_COMMAND; 6262 command_type = OTHER_COMMAND;
6240 break; 6263 break;
6241 case CMD_XRI_ABORTED_CX: 6264 case CMD_XRI_ABORTED_CX:
6242 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ 6265 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
6243 /* words0-2 are all 0's no bde */
6244 /* word3 and word4 are rsvrd */
6245 wqe->words[3] = 0;
6246 wqe->words[4] = 0;
6247 /* word5 iocb=rsvd wge=did */
6248 /* There is no remote port id in the IOCB? */
6249 /* Let this fall through and fail */
6250 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ 6266 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
6251 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ 6267 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
6252 case CMD_FCP_TRSP64_CX: /* Target mode rcv */ 6268 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
@@ -6257,16 +6273,14 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
6257 iocbq->iocb.ulpCommand); 6273 iocbq->iocb.ulpCommand);
6258 return IOCB_ERROR; 6274 return IOCB_ERROR;
6259 break; 6275 break;
6260
6261 } 6276 }
6262 bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag); 6277 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
6263 bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag); 6278 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
6264 wqe->generic.abort_tag = abort_tag; 6279 wqe->generic.wqe_com.abort_tag = abort_tag;
6265 bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type); 6280 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
6266 bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd); 6281 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
6267 bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass); 6282 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
6268 bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT); 6283 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
6269
6270 return 0; 6284 return 0;
6271} 6285}
6272 6286
@@ -7257,25 +7271,26 @@ lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7257} 7271}
7258 7272
7259/** 7273/**
7260 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb 7274 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
7261 * @phba: Pointer to HBA context object. 7275 * @phba: Pointer to HBA context object.
7262 * @pring: Pointer to driver SLI ring object. 7276 * @pring: Pointer to driver SLI ring object.
7263 * @cmdiocb: Pointer to driver command iocb object. 7277 * @cmdiocb: Pointer to driver command iocb object.
7264 * 7278 *
7265 * This function issues an abort iocb for the provided command 7279 * This function issues an abort iocb for the provided command iocb down to
7266 * iocb. This function is called with hbalock held. 7280 * the port. Other than the case the outstanding command iocb is an abort
7267 * The function returns 0 when it fails due to memory allocation 7281 * request, this function issues abort out unconditionally. This function is
7268 * failure or when the command iocb is an abort request. 7282 * called with hbalock held. The function returns 0 when it fails due to
7283 * memory allocation failure or when the command iocb is an abort request.
7269 **/ 7284 **/
7270int 7285static int
7271lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 7286lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7272 struct lpfc_iocbq *cmdiocb) 7287 struct lpfc_iocbq *cmdiocb)
7273{ 7288{
7274 struct lpfc_vport *vport = cmdiocb->vport; 7289 struct lpfc_vport *vport = cmdiocb->vport;
7275 struct lpfc_iocbq *abtsiocbp; 7290 struct lpfc_iocbq *abtsiocbp;
7276 IOCB_t *icmd = NULL; 7291 IOCB_t *icmd = NULL;
7277 IOCB_t *iabt = NULL; 7292 IOCB_t *iabt = NULL;
7278 int retval = IOCB_ERROR; 7293 int retval;
7279 7294
7280 /* 7295 /*
7281 * There are certain command types we don't want to abort. And we 7296 * There are certain command types we don't want to abort. And we
@@ -7288,18 +7303,6 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7288 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) 7303 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
7289 return 0; 7304 return 0;
7290 7305
7291 /* If we're unloading, don't abort iocb on the ELS ring, but change the
7292 * callback so that nothing happens when it finishes.
7293 */
7294 if ((vport->load_flag & FC_UNLOADING) &&
7295 (pring->ringno == LPFC_ELS_RING)) {
7296 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
7297 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
7298 else
7299 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
7300 goto abort_iotag_exit;
7301 }
7302
7303 /* issue ABTS for this IOCB based on iotag */ 7306 /* issue ABTS for this IOCB based on iotag */
7304 abtsiocbp = __lpfc_sli_get_iocbq(phba); 7307 abtsiocbp = __lpfc_sli_get_iocbq(phba);
7305 if (abtsiocbp == NULL) 7308 if (abtsiocbp == NULL)
@@ -7344,6 +7347,63 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7344 7347
7345 if (retval) 7348 if (retval)
7346 __lpfc_sli_release_iocbq(phba, abtsiocbp); 7349 __lpfc_sli_release_iocbq(phba, abtsiocbp);
7350
7351 /*
7352 * Caller to this routine should check for IOCB_ERROR
7353 * and handle it properly. This routine no longer removes
7354 * iocb off txcmplq and call compl in case of IOCB_ERROR.
7355 */
7356 return retval;
7357}
7358
7359/**
7360 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
7361 * @phba: Pointer to HBA context object.
7362 * @pring: Pointer to driver SLI ring object.
7363 * @cmdiocb: Pointer to driver command iocb object.
7364 *
7365 * This function issues an abort iocb for the provided command iocb. In case
7366 * of unloading, the abort iocb will not be issued to commands on the ELS
7367 * ring. Instead, the callback function shall be changed to those commands
7368 * so that nothing happens when them finishes. This function is called with
7369 * hbalock held. The function returns 0 when the command iocb is an abort
7370 * request.
7371 **/
7372int
7373lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7374 struct lpfc_iocbq *cmdiocb)
7375{
7376 struct lpfc_vport *vport = cmdiocb->vport;
7377 int retval = IOCB_ERROR;
7378 IOCB_t *icmd = NULL;
7379
7380 /*
7381 * There are certain command types we don't want to abort. And we
7382 * don't want to abort commands that are already in the process of
7383 * being aborted.
7384 */
7385 icmd = &cmdiocb->iocb;
7386 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
7387 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7388 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
7389 return 0;
7390
7391 /*
7392 * If we're unloading, don't abort iocb on the ELS ring, but change
7393 * the callback so that nothing happens when it finishes.
7394 */
7395 if ((vport->load_flag & FC_UNLOADING) &&
7396 (pring->ringno == LPFC_ELS_RING)) {
7397 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
7398 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
7399 else
7400 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
7401 goto abort_iotag_exit;
7402 }
7403
7404 /* Now, we try to issue the abort to the cmdiocb out */
7405 retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
7406
7347abort_iotag_exit: 7407abort_iotag_exit:
7348 /* 7408 /*
7349 * Caller to this routine should check for IOCB_ERROR 7409 * Caller to this routine should check for IOCB_ERROR
@@ -7354,6 +7414,62 @@ abort_iotag_exit:
7354} 7414}
7355 7415
7356/** 7416/**
7417 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
7418 * @phba: Pointer to HBA context object.
7419 * @pring: Pointer to driver SLI ring object.
7420 *
7421 * This function aborts all iocbs in the given ring and frees all the iocb
7422 * objects in txq. This function issues abort iocbs unconditionally for all
7423 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
7424 * to complete before the return of this function. The caller is not required
7425 * to hold any locks.
7426 **/
7427static void
7428lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
7429{
7430 LIST_HEAD(completions);
7431 struct lpfc_iocbq *iocb, *next_iocb;
7432
7433 if (pring->ringno == LPFC_ELS_RING)
7434 lpfc_fabric_abort_hba(phba);
7435
7436 spin_lock_irq(&phba->hbalock);
7437
7438 /* Take off all the iocbs on txq for cancelling */
7439 list_splice_init(&pring->txq, &completions);
7440 pring->txq_cnt = 0;
7441
7442 /* Next issue ABTS for everything on the txcmplq */
7443 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
7444 lpfc_sli_abort_iotag_issue(phba, pring, iocb);
7445
7446 spin_unlock_irq(&phba->hbalock);
7447
7448 /* Cancel all the IOCBs from the completions list */
7449 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7450 IOERR_SLI_ABORTED);
7451}
7452
7453/**
7454 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
7455 * @phba: pointer to lpfc HBA data structure.
7456 *
7457 * This routine will abort all pending and outstanding iocbs to an HBA.
7458 **/
7459void
7460lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
7461{
7462 struct lpfc_sli *psli = &phba->sli;
7463 struct lpfc_sli_ring *pring;
7464 int i;
7465
7466 for (i = 0; i < psli->num_rings; i++) {
7467 pring = &psli->ring[i];
7468 lpfc_sli_iocb_ring_abort(phba, pring);
7469 }
7470}
7471
7472/**
7357 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN 7473 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
7358 * @iocbq: Pointer to driver iocb object. 7474 * @iocbq: Pointer to driver iocb object.
7359 * @vport: Pointer to driver virtual port object. 7475 * @vport: Pointer to driver virtual port object.
@@ -12242,13 +12358,15 @@ lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
12242 /* Issue the mailbox command asynchronously */ 12358 /* Issue the mailbox command asynchronously */
12243 mboxq->vport = phba->pport; 12359 mboxq->vport = phba->pport;
12244 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; 12360 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
12361
12362 spin_lock_irq(&phba->hbalock);
12363 phba->hba_flag |= FCF_TS_INPROG;
12364 spin_unlock_irq(&phba->hbalock);
12365
12245 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); 12366 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
12246 if (rc == MBX_NOT_FINISHED) 12367 if (rc == MBX_NOT_FINISHED)
12247 error = -EIO; 12368 error = -EIO;
12248 else { 12369 else {
12249 spin_lock_irq(&phba->hbalock);
12250 phba->hba_flag |= FCF_DISC_INPROGRESS;
12251 spin_unlock_irq(&phba->hbalock);
12252 /* Reset eligible FCF count for new scan */ 12370 /* Reset eligible FCF count for new scan */
12253 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) 12371 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
12254 phba->fcf.eligible_fcf_cnt = 0; 12372 phba->fcf.eligible_fcf_cnt = 0;
@@ -12258,21 +12376,21 @@ fail_fcf_scan:
12258 if (error) { 12376 if (error) {
12259 if (mboxq) 12377 if (mboxq)
12260 lpfc_sli4_mbox_cmd_free(phba, mboxq); 12378 lpfc_sli4_mbox_cmd_free(phba, mboxq);
12261 /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */ 12379 /* FCF scan failed, clear FCF_TS_INPROG flag */
12262 spin_lock_irq(&phba->hbalock); 12380 spin_lock_irq(&phba->hbalock);
12263 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 12381 phba->hba_flag &= ~FCF_TS_INPROG;
12264 spin_unlock_irq(&phba->hbalock); 12382 spin_unlock_irq(&phba->hbalock);
12265 } 12383 }
12266 return error; 12384 return error;
12267} 12385}
12268 12386
12269/** 12387/**
12270 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf. 12388 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
12271 * @phba: pointer to lpfc hba data structure. 12389 * @phba: pointer to lpfc hba data structure.
12272 * @fcf_index: FCF table entry offset. 12390 * @fcf_index: FCF table entry offset.
12273 * 12391 *
12274 * This routine is invoked to read an FCF record indicated by @fcf_index 12392 * This routine is invoked to read an FCF record indicated by @fcf_index
12275 * and to use it for FLOGI round robin FCF failover. 12393 * and to use it for FLOGI roundrobin FCF failover.
12276 * 12394 *
12277 * Return 0 if the mailbox command is submitted sucessfully, none 0 12395 * Return 0 if the mailbox command is submitted sucessfully, none 0
12278 * otherwise. 12396 * otherwise.
@@ -12318,7 +12436,7 @@ fail_fcf_read:
12318 * @fcf_index: FCF table entry offset. 12436 * @fcf_index: FCF table entry offset.
12319 * 12437 *
12320 * This routine is invoked to read an FCF record indicated by @fcf_index to 12438 * This routine is invoked to read an FCF record indicated by @fcf_index to
12321 * determine whether it's eligible for FLOGI round robin failover list. 12439 * determine whether it's eligible for FLOGI roundrobin failover list.
12322 * 12440 *
12323 * Return 0 if the mailbox command is submitted sucessfully, none 0 12441 * Return 0 if the mailbox command is submitted sucessfully, none 0
12324 * otherwise. 12442 * otherwise.
@@ -12364,7 +12482,7 @@ fail_fcf_read:
12364 * 12482 *
12365 * This routine is to get the next eligible FCF record index in a round 12483 * This routine is to get the next eligible FCF record index in a round
12366 * robin fashion. If the next eligible FCF record index equals to the 12484 * robin fashion. If the next eligible FCF record index equals to the
12367 * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) 12485 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
12368 * shall be returned, otherwise, the next eligible FCF record's index 12486 * shall be returned, otherwise, the next eligible FCF record's index
12369 * shall be returned. 12487 * shall be returned.
12370 **/ 12488 **/
@@ -12392,28 +12510,10 @@ lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
12392 return LPFC_FCOE_FCF_NEXT_NONE; 12510 return LPFC_FCOE_FCF_NEXT_NONE;
12393 } 12511 }
12394 12512
12395 /* Check roundrobin failover index bmask stop condition */
12396 if (next_fcf_index == phba->fcf.fcf_rr_init_indx) {
12397 if (!(phba->fcf.fcf_flag & FCF_REDISC_RRU)) {
12398 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
12399 "2847 Round robin failover FCF index "
12400 "search hit stop condition:x%x\n",
12401 next_fcf_index);
12402 return LPFC_FCOE_FCF_NEXT_NONE;
12403 }
12404 /* The roundrobin failover index bmask updated, start over */
12405 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
12406 "2848 Round robin failover FCF index bmask "
12407 "updated, start over\n");
12408 spin_lock_irq(&phba->hbalock);
12409 phba->fcf.fcf_flag &= ~FCF_REDISC_RRU;
12410 spin_unlock_irq(&phba->hbalock);
12411 return phba->fcf.fcf_rr_init_indx;
12412 }
12413
12414 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 12513 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
12415 "2845 Get next round robin failover " 12514 "2845 Get next roundrobin failover FCF (x%x)\n",
12416 "FCF index x%x\n", next_fcf_index); 12515 next_fcf_index);
12516
12417 return next_fcf_index; 12517 return next_fcf_index;
12418} 12518}
12419 12519
@@ -12422,7 +12522,7 @@ lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
12422 * @phba: pointer to lpfc hba data structure. 12522 * @phba: pointer to lpfc hba data structure.
12423 * 12523 *
12424 * This routine sets the FCF record index in to the eligible bmask for 12524 * This routine sets the FCF record index in to the eligible bmask for
12425 * round robin failover search. It checks to make sure that the index 12525 * roundrobin failover search. It checks to make sure that the index
12426 * does not go beyond the range of the driver allocated bmask dimension 12526 * does not go beyond the range of the driver allocated bmask dimension
12427 * before setting the bit. 12527 * before setting the bit.
12428 * 12528 *
@@ -12434,22 +12534,16 @@ lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
12434{ 12534{
12435 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { 12535 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
12436 lpfc_printf_log(phba, KERN_ERR, LOG_FIP, 12536 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
12437 "2610 HBA FCF index reached driver's " 12537 "2610 FCF (x%x) reached driver's book "
12438 "book keeping dimension: fcf_index:%d, " 12538 "keeping dimension:x%x\n",
12439 "driver_bmask_max:%d\n",
12440 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); 12539 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
12441 return -EINVAL; 12540 return -EINVAL;
12442 } 12541 }
12443 /* Set the eligible FCF record index bmask */ 12542 /* Set the eligible FCF record index bmask */
12444 set_bit(fcf_index, phba->fcf.fcf_rr_bmask); 12543 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
12445 12544
12446 /* Set the roundrobin index bmask updated */
12447 spin_lock_irq(&phba->hbalock);
12448 phba->fcf.fcf_flag |= FCF_REDISC_RRU;
12449 spin_unlock_irq(&phba->hbalock);
12450
12451 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 12545 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
12452 "2790 Set FCF index x%x to round robin failover " 12546 "2790 Set FCF (x%x) to roundrobin FCF failover "
12453 "bmask\n", fcf_index); 12547 "bmask\n", fcf_index);
12454 12548
12455 return 0; 12549 return 0;
@@ -12460,7 +12554,7 @@ lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
12460 * @phba: pointer to lpfc hba data structure. 12554 * @phba: pointer to lpfc hba data structure.
12461 * 12555 *
12462 * This routine clears the FCF record index from the eligible bmask for 12556 * This routine clears the FCF record index from the eligible bmask for
12463 * round robin failover search. It checks to make sure that the index 12557 * roundrobin failover search. It checks to make sure that the index
12464 * does not go beyond the range of the driver allocated bmask dimension 12558 * does not go beyond the range of the driver allocated bmask dimension
12465 * before clearing the bit. 12559 * before clearing the bit.
12466 **/ 12560 **/
@@ -12469,9 +12563,8 @@ lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
12469{ 12563{
12470 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { 12564 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
12471 lpfc_printf_log(phba, KERN_ERR, LOG_FIP, 12565 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
12472 "2762 HBA FCF index goes beyond driver's " 12566 "2762 FCF (x%x) reached driver's book "
12473 "book keeping dimension: fcf_index:%d, " 12567 "keeping dimension:x%x\n",
12474 "driver_bmask_max:%d\n",
12475 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); 12568 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
12476 return; 12569 return;
12477 } 12570 }
@@ -12479,7 +12572,7 @@ lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
12479 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); 12572 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
12480 12573
12481 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 12574 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
12482 "2791 Clear FCF index x%x from round robin failover " 12575 "2791 Clear FCF (x%x) from roundrobin failover "
12483 "bmask\n", fcf_index); 12576 "bmask\n", fcf_index);
12484} 12577}
12485 12578
@@ -12530,8 +12623,7 @@ lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
12530 } 12623 }
12531 } else { 12624 } else {
12532 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 12625 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
12533 "2775 Start FCF rediscovery quiescent period " 12626 "2775 Start FCF rediscover quiescent timer\n");
12534 "wait timer before scaning FCF table\n");
12535 /* 12627 /*
12536 * Start FCF rediscovery wait timer for pending FCF 12628 * Start FCF rediscovery wait timer for pending FCF
12537 * before rescan FCF record table. 12629 * before rescan FCF record table.
diff --git a/drivers/scsi/lpfc/lpfc_sli4.h b/drivers/scsi/lpfc/lpfc_sli4.h
index a0ca572ec28b..c4483feb8b71 100644
--- a/drivers/scsi/lpfc/lpfc_sli4.h
+++ b/drivers/scsi/lpfc/lpfc_sli4.h
@@ -19,10 +19,16 @@
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_ACTIVE_MBOX_WAIT_CNT 100 21#define LPFC_ACTIVE_MBOX_WAIT_CNT 100
22#define LPFC_XRI_EXCH_BUSY_WAIT_TMO 10000
23#define LPFC_XRI_EXCH_BUSY_WAIT_T1 10
24#define LPFC_XRI_EXCH_BUSY_WAIT_T2 30000
22#define LPFC_RELEASE_NOTIFICATION_INTERVAL 32 25#define LPFC_RELEASE_NOTIFICATION_INTERVAL 32
23#define LPFC_GET_QE_REL_INT 32 26#define LPFC_GET_QE_REL_INT 32
24#define LPFC_RPI_LOW_WATER_MARK 10 27#define LPFC_RPI_LOW_WATER_MARK 10
25 28
29#define LPFC_UNREG_FCF 1
30#define LPFC_SKIP_UNREG_FCF 0
31
26/* Amount of time in seconds for waiting FCF rediscovery to complete */ 32/* Amount of time in seconds for waiting FCF rediscovery to complete */
27#define LPFC_FCF_REDISCOVER_WAIT_TMO 2000 /* msec */ 33#define LPFC_FCF_REDISCOVER_WAIT_TMO 2000 /* msec */
28 34
@@ -163,9 +169,8 @@ struct lpfc_fcf {
163#define FCF_REDISC_PEND 0x80 /* FCF rediscovery pending */ 169#define FCF_REDISC_PEND 0x80 /* FCF rediscovery pending */
164#define FCF_REDISC_EVT 0x100 /* FCF rediscovery event to worker thread */ 170#define FCF_REDISC_EVT 0x100 /* FCF rediscovery event to worker thread */
165#define FCF_REDISC_FOV 0x200 /* Post FCF rediscovery fast failover */ 171#define FCF_REDISC_FOV 0x200 /* Post FCF rediscovery fast failover */
166#define FCF_REDISC_RRU 0x400 /* Roundrobin bitmap updated */ 172#define FCF_REDISC_PROG (FCF_REDISC_PEND | FCF_REDISC_EVT)
167 uint32_t addr_mode; 173 uint32_t addr_mode;
168 uint16_t fcf_rr_init_indx;
169 uint32_t eligible_fcf_cnt; 174 uint32_t eligible_fcf_cnt;
170 struct lpfc_fcf_rec current_rec; 175 struct lpfc_fcf_rec current_rec;
171 struct lpfc_fcf_rec failover_rec; 176 struct lpfc_fcf_rec failover_rec;
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index f93120e4c796..7a1b5b112a0b 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -18,7 +18,7 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_DRIVER_VERSION "8.3.17" 21#define LPFC_DRIVER_VERSION "8.3.18"
22#define LPFC_DRIVER_NAME "lpfc" 22#define LPFC_DRIVER_NAME "lpfc"
23#define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp" 23#define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp"
24#define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp" 24#define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp"
diff --git a/drivers/scsi/mac53c94.c b/drivers/scsi/mac53c94.c
index 3ddb4dc62d5d..6c42dff0f4d3 100644
--- a/drivers/scsi/mac53c94.c
+++ b/drivers/scsi/mac53c94.c
@@ -66,7 +66,7 @@ static void cmd_done(struct fsc_state *, int result);
66static void set_dma_cmds(struct fsc_state *, struct scsi_cmnd *); 66static void set_dma_cmds(struct fsc_state *, struct scsi_cmnd *);
67 67
68 68
69static int mac53c94_queue(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 69static int mac53c94_queue_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
70{ 70{
71 struct fsc_state *state; 71 struct fsc_state *state;
72 72
@@ -99,6 +99,8 @@ static int mac53c94_queue(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *
99 return 0; 99 return 0;
100} 100}
101 101
102static DEF_SCSI_QCMD(mac53c94_queue)
103
102static int mac53c94_host_reset(struct scsi_cmnd *cmd) 104static int mac53c94_host_reset(struct scsi_cmnd *cmd)
103{ 105{
104 struct fsc_state *state = (struct fsc_state *) cmd->device->host->hostdata; 106 struct fsc_state *state = (struct fsc_state *) cmd->device->host->hostdata;
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 7ceb5cf12c6b..9aa048525eb2 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -366,7 +366,7 @@ mega_runpendq(adapter_t *adapter)
366 * The command queuing entry point for the mid-layer. 366 * The command queuing entry point for the mid-layer.
367 */ 367 */
368static int 368static int
369megaraid_queue(Scsi_Cmnd *scmd, void (*done)(Scsi_Cmnd *)) 369megaraid_queue_lck(Scsi_Cmnd *scmd, void (*done)(Scsi_Cmnd *))
370{ 370{
371 adapter_t *adapter; 371 adapter_t *adapter;
372 scb_t *scb; 372 scb_t *scb;
@@ -409,6 +409,8 @@ megaraid_queue(Scsi_Cmnd *scmd, void (*done)(Scsi_Cmnd *))
409 return busy; 409 return busy;
410} 410}
411 411
412static DEF_SCSI_QCMD(megaraid_queue)
413
412/** 414/**
413 * mega_allocate_scb() 415 * mega_allocate_scb()
414 * @adapter - pointer to our soft state 416 * @adapter - pointer to our soft state
@@ -4456,7 +4458,7 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru)
4456 4458
4457 scb->idx = CMDID_INT_CMDS; 4459 scb->idx = CMDID_INT_CMDS;
4458 4460
4459 megaraid_queue(scmd, mega_internal_done); 4461 megaraid_queue_lck(scmd, mega_internal_done);
4460 4462
4461 wait_for_completion(&adapter->int_waitq); 4463 wait_for_completion(&adapter->int_waitq);
4462 4464
diff --git a/drivers/scsi/megaraid.h b/drivers/scsi/megaraid.h
index deb24ad1b8d2..853411911b2e 100644
--- a/drivers/scsi/megaraid.h
+++ b/drivers/scsi/megaraid.h
@@ -987,7 +987,7 @@ static int mega_query_adapter(adapter_t *);
987static int issue_scb(adapter_t *, scb_t *); 987static int issue_scb(adapter_t *, scb_t *);
988static int mega_setup_mailbox(adapter_t *); 988static int mega_setup_mailbox(adapter_t *);
989 989
990static int megaraid_queue (Scsi_Cmnd *, void (*)(Scsi_Cmnd *)); 990static int megaraid_queue (struct Scsi_Host *, struct scsi_cmnd *);
991static scb_t * mega_build_cmd(adapter_t *, Scsi_Cmnd *, int *); 991static scb_t * mega_build_cmd(adapter_t *, Scsi_Cmnd *, int *);
992static void __mega_runpendq(adapter_t *); 992static void __mega_runpendq(adapter_t *);
993static int issue_scb_block(adapter_t *, u_char *); 993static int issue_scb_block(adapter_t *, u_char *);
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index a7810a106b37..5708cb27d078 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -113,8 +113,7 @@ static int megaraid_mbox_fire_sync_cmd(adapter_t *);
113static void megaraid_mbox_display_scb(adapter_t *, scb_t *); 113static void megaraid_mbox_display_scb(adapter_t *, scb_t *);
114static void megaraid_mbox_setup_device_map(adapter_t *); 114static void megaraid_mbox_setup_device_map(adapter_t *);
115 115
116static int megaraid_queue_command(struct scsi_cmnd *, 116static int megaraid_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
117 void (*)(struct scsi_cmnd *));
118static scb_t *megaraid_mbox_build_cmd(adapter_t *, struct scsi_cmnd *, int *); 117static scb_t *megaraid_mbox_build_cmd(adapter_t *, struct scsi_cmnd *, int *);
119static void megaraid_mbox_runpendq(adapter_t *, scb_t *); 118static void megaraid_mbox_runpendq(adapter_t *, scb_t *);
120static void megaraid_mbox_prepare_pthru(adapter_t *, scb_t *, 119static void megaraid_mbox_prepare_pthru(adapter_t *, scb_t *,
@@ -1484,7 +1483,7 @@ mbox_post_cmd(adapter_t *adapter, scb_t *scb)
1484 * Queue entry point for mailbox based controllers. 1483 * Queue entry point for mailbox based controllers.
1485 */ 1484 */
1486static int 1485static int
1487megaraid_queue_command(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *)) 1486megaraid_queue_command_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
1488{ 1487{
1489 adapter_t *adapter; 1488 adapter_t *adapter;
1490 scb_t *scb; 1489 scb_t *scb;
@@ -1513,6 +1512,8 @@ megaraid_queue_command(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
1513 return if_busy; 1512 return if_busy;
1514} 1513}
1515 1514
1515static DEF_SCSI_QCMD(megaraid_queue_command)
1516
1516/** 1517/**
1517 * megaraid_mbox_build_cmd - transform the mid-layer scsi commands 1518 * megaraid_mbox_build_cmd - transform the mid-layer scsi commands
1518 * @adapter : controller's soft state 1519 * @adapter : controller's soft state
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index d3c9cdee292b..7451bc096a01 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -10,7 +10,7 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_sas.c 12 * FILE : megaraid_sas.c
13 * Version : v00.00.04.17.1-rc1 13 * Version : v00.00.04.31-rc1
14 * 14 *
15 * Authors: 15 * Authors:
16 * (email-id : megaraidlinux@lsi.com) 16 * (email-id : megaraidlinux@lsi.com)
@@ -56,6 +56,15 @@ module_param_named(poll_mode_io, poll_mode_io, int, 0);
56MODULE_PARM_DESC(poll_mode_io, 56MODULE_PARM_DESC(poll_mode_io,
57 "Complete cmds from IO path, (default=0)"); 57 "Complete cmds from IO path, (default=0)");
58 58
59/*
60 * Number of sectors per IO command
61 * Will be set in megasas_init_mfi if user does not provide
62 */
63static unsigned int max_sectors;
64module_param_named(max_sectors, max_sectors, int, 0);
65MODULE_PARM_DESC(max_sectors,
66 "Maximum number of sectors per IO command");
67
59MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
60MODULE_VERSION(MEGASAS_VERSION); 69MODULE_VERSION(MEGASAS_VERSION);
61MODULE_AUTHOR("megaraidlinux@lsi.com"); 70MODULE_AUTHOR("megaraidlinux@lsi.com");
@@ -103,6 +112,7 @@ static int megasas_poll_wait_aen;
103static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); 112static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait);
104static u32 support_poll_for_event; 113static u32 support_poll_for_event;
105static u32 megasas_dbg_lvl; 114static u32 megasas_dbg_lvl;
115static u32 support_device_change;
106 116
107/* define lock for aen poll */ 117/* define lock for aen poll */
108spinlock_t poll_aen_lock; 118spinlock_t poll_aen_lock;
@@ -718,6 +728,10 @@ static int
718megasas_check_reset_gen2(struct megasas_instance *instance, 728megasas_check_reset_gen2(struct megasas_instance *instance,
719 struct megasas_register_set __iomem *regs) 729 struct megasas_register_set __iomem *regs)
720{ 730{
731 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) {
732 return 1;
733 }
734
721 return 0; 735 return 0;
722} 736}
723 737
@@ -930,6 +944,7 @@ megasas_make_sgl_skinny(struct megasas_instance *instance,
930 mfi_sgl->sge_skinny[i].length = sg_dma_len(os_sgl); 944 mfi_sgl->sge_skinny[i].length = sg_dma_len(os_sgl);
931 mfi_sgl->sge_skinny[i].phys_addr = 945 mfi_sgl->sge_skinny[i].phys_addr =
932 sg_dma_address(os_sgl); 946 sg_dma_address(os_sgl);
947 mfi_sgl->sge_skinny[i].flag = 0;
933 } 948 }
934 } 949 }
935 return sge_count; 950 return sge_count;
@@ -1319,7 +1334,7 @@ megasas_dump_pending_frames(struct megasas_instance *instance)
1319 * @done: Callback entry point 1334 * @done: Callback entry point
1320 */ 1335 */
1321static int 1336static int
1322megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *)) 1337megasas_queue_command_lck(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *))
1323{ 1338{
1324 u32 frame_count; 1339 u32 frame_count;
1325 struct megasas_cmd *cmd; 1340 struct megasas_cmd *cmd;
@@ -1402,6 +1417,8 @@ megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *))
1402 return 0; 1417 return 0;
1403} 1418}
1404 1419
1420static DEF_SCSI_QCMD(megasas_queue_command)
1421
1405static struct megasas_instance *megasas_lookup_instance(u16 host_no) 1422static struct megasas_instance *megasas_lookup_instance(u16 host_no)
1406{ 1423{
1407 int i; 1424 int i;
@@ -1557,6 +1574,28 @@ static void megasas_complete_cmd_dpc(unsigned long instance_addr)
1557 } 1574 }
1558} 1575}
1559 1576
1577static void
1578megasas_internal_reset_defer_cmds(struct megasas_instance *instance);
1579
1580static void
1581process_fw_state_change_wq(struct work_struct *work);
1582
1583void megasas_do_ocr(struct megasas_instance *instance)
1584{
1585 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) ||
1586 (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) ||
1587 (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) {
1588 *instance->consumer = MEGASAS_ADPRESET_INPROG_SIGN;
1589 }
1590 instance->instancet->disable_intr(instance->reg_set);
1591 instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT;
1592 instance->issuepend_done = 0;
1593
1594 atomic_set(&instance->fw_outstanding, 0);
1595 megasas_internal_reset_defer_cmds(instance);
1596 process_fw_state_change_wq(&instance->work_init);
1597}
1598
1560/** 1599/**
1561 * megasas_wait_for_outstanding - Wait for all outstanding cmds 1600 * megasas_wait_for_outstanding - Wait for all outstanding cmds
1562 * @instance: Adapter soft state 1601 * @instance: Adapter soft state
@@ -1574,6 +1613,8 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance)
1574 unsigned long flags; 1613 unsigned long flags;
1575 struct list_head clist_local; 1614 struct list_head clist_local;
1576 struct megasas_cmd *reset_cmd; 1615 struct megasas_cmd *reset_cmd;
1616 u32 fw_state;
1617 u8 kill_adapter_flag;
1577 1618
1578 spin_lock_irqsave(&instance->hba_lock, flags); 1619 spin_lock_irqsave(&instance->hba_lock, flags);
1579 adprecovery = instance->adprecovery; 1620 adprecovery = instance->adprecovery;
@@ -1659,7 +1700,45 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance)
1659 msleep(1000); 1700 msleep(1000);
1660 } 1701 }
1661 1702
1662 if (atomic_read(&instance->fw_outstanding)) { 1703 i = 0;
1704 kill_adapter_flag = 0;
1705 do {
1706 fw_state = instance->instancet->read_fw_status_reg(
1707 instance->reg_set) & MFI_STATE_MASK;
1708 if ((fw_state == MFI_STATE_FAULT) &&
1709 (instance->disableOnlineCtrlReset == 0)) {
1710 if (i == 3) {
1711 kill_adapter_flag = 2;
1712 break;
1713 }
1714 megasas_do_ocr(instance);
1715 kill_adapter_flag = 1;
1716
1717 /* wait for 1 secs to let FW finish the pending cmds */
1718 msleep(1000);
1719 }
1720 i++;
1721 } while (i <= 3);
1722
1723 if (atomic_read(&instance->fw_outstanding) &&
1724 !kill_adapter_flag) {
1725 if (instance->disableOnlineCtrlReset == 0) {
1726
1727 megasas_do_ocr(instance);
1728
1729 /* wait for 5 secs to let FW finish the pending cmds */
1730 for (i = 0; i < wait_time; i++) {
1731 int outstanding =
1732 atomic_read(&instance->fw_outstanding);
1733 if (!outstanding)
1734 return SUCCESS;
1735 msleep(1000);
1736 }
1737 }
1738 }
1739
1740 if (atomic_read(&instance->fw_outstanding) ||
1741 (kill_adapter_flag == 2)) {
1663 printk(KERN_NOTICE "megaraid_sas: pending cmds after reset\n"); 1742 printk(KERN_NOTICE "megaraid_sas: pending cmds after reset\n");
1664 /* 1743 /*
1665 * Send signal to FW to stop processing any pending cmds. 1744 * Send signal to FW to stop processing any pending cmds.
@@ -2669,6 +2748,7 @@ static int megasas_create_frame_pool(struct megasas_instance *instance)
2669 return -ENOMEM; 2748 return -ENOMEM;
2670 } 2749 }
2671 2750
2751 memset(cmd->frame, 0, total_sz);
2672 cmd->frame->io.context = cmd->index; 2752 cmd->frame->io.context = cmd->index;
2673 cmd->frame->io.pad_0 = 0; 2753 cmd->frame->io.pad_0 = 0;
2674 } 2754 }
@@ -3585,6 +3665,27 @@ static int megasas_io_attach(struct megasas_instance *instance)
3585 instance->max_fw_cmds - MEGASAS_INT_CMDS; 3665 instance->max_fw_cmds - MEGASAS_INT_CMDS;
3586 host->this_id = instance->init_id; 3666 host->this_id = instance->init_id;
3587 host->sg_tablesize = instance->max_num_sge; 3667 host->sg_tablesize = instance->max_num_sge;
3668 /*
3669 * Check if the module parameter value for max_sectors can be used
3670 */
3671 if (max_sectors && max_sectors < instance->max_sectors_per_req)
3672 instance->max_sectors_per_req = max_sectors;
3673 else {
3674 if (max_sectors) {
3675 if (((instance->pdev->device ==
3676 PCI_DEVICE_ID_LSI_SAS1078GEN2) ||
3677 (instance->pdev->device ==
3678 PCI_DEVICE_ID_LSI_SAS0079GEN2)) &&
3679 (max_sectors <= MEGASAS_MAX_SECTORS)) {
3680 instance->max_sectors_per_req = max_sectors;
3681 } else {
3682 printk(KERN_INFO "megasas: max_sectors should be > 0"
3683 "and <= %d (or < 1MB for GEN2 controller)\n",
3684 instance->max_sectors_per_req);
3685 }
3686 }
3687 }
3688
3588 host->max_sectors = instance->max_sectors_per_req; 3689 host->max_sectors = instance->max_sectors_per_req;
3589 host->cmd_per_lun = 128; 3690 host->cmd_per_lun = 128;
3590 host->max_channel = MEGASAS_MAX_CHANNELS - 1; 3691 host->max_channel = MEGASAS_MAX_CHANNELS - 1;
@@ -4658,6 +4759,15 @@ megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf)
4658static DRIVER_ATTR(support_poll_for_event, S_IRUGO, 4759static DRIVER_ATTR(support_poll_for_event, S_IRUGO,
4659 megasas_sysfs_show_support_poll_for_event, NULL); 4760 megasas_sysfs_show_support_poll_for_event, NULL);
4660 4761
4762 static ssize_t
4763megasas_sysfs_show_support_device_change(struct device_driver *dd, char *buf)
4764{
4765 return sprintf(buf, "%u\n", support_device_change);
4766}
4767
4768static DRIVER_ATTR(support_device_change, S_IRUGO,
4769 megasas_sysfs_show_support_device_change, NULL);
4770
4661static ssize_t 4771static ssize_t
4662megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf) 4772megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf)
4663{ 4773{
@@ -4978,6 +5088,7 @@ static int __init megasas_init(void)
4978 MEGASAS_EXT_VERSION); 5088 MEGASAS_EXT_VERSION);
4979 5089
4980 support_poll_for_event = 2; 5090 support_poll_for_event = 2;
5091 support_device_change = 1;
4981 5092
4982 memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); 5093 memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info));
4983 5094
@@ -5026,8 +5137,17 @@ static int __init megasas_init(void)
5026 if (rval) 5137 if (rval)
5027 goto err_dcf_poll_mode_io; 5138 goto err_dcf_poll_mode_io;
5028 5139
5140 rval = driver_create_file(&megasas_pci_driver.driver,
5141 &driver_attr_support_device_change);
5142 if (rval)
5143 goto err_dcf_support_device_change;
5144
5029 return rval; 5145 return rval;
5030 5146
5147err_dcf_support_device_change:
5148 driver_remove_file(&megasas_pci_driver.driver,
5149 &driver_attr_poll_mode_io);
5150
5031err_dcf_poll_mode_io: 5151err_dcf_poll_mode_io:
5032 driver_remove_file(&megasas_pci_driver.driver, 5152 driver_remove_file(&megasas_pci_driver.driver,
5033 &driver_attr_dbg_lvl); 5153 &driver_attr_dbg_lvl);
@@ -5058,6 +5178,10 @@ static void __exit megasas_exit(void)
5058 driver_remove_file(&megasas_pci_driver.driver, 5178 driver_remove_file(&megasas_pci_driver.driver,
5059 &driver_attr_dbg_lvl); 5179 &driver_attr_dbg_lvl);
5060 driver_remove_file(&megasas_pci_driver.driver, 5180 driver_remove_file(&megasas_pci_driver.driver,
5181 &driver_attr_support_poll_for_event);
5182 driver_remove_file(&megasas_pci_driver.driver,
5183 &driver_attr_support_device_change);
5184 driver_remove_file(&megasas_pci_driver.driver,
5061 &driver_attr_release_date); 5185 &driver_attr_release_date);
5062 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); 5186 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version);
5063 5187
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 16a4f68a34b0..ad16f5e60046 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -18,9 +18,9 @@
18/* 18/*
19 * MegaRAID SAS Driver meta data 19 * MegaRAID SAS Driver meta data
20 */ 20 */
21#define MEGASAS_VERSION "00.00.04.17.1-rc1" 21#define MEGASAS_VERSION "00.00.04.31-rc1"
22#define MEGASAS_RELDATE "Oct. 29, 2009" 22#define MEGASAS_RELDATE "May 3, 2010"
23#define MEGASAS_EXT_VERSION "Thu. Oct. 29, 11:41:51 PST 2009" 23#define MEGASAS_EXT_VERSION "Mon. May 3, 11:41:51 PST 2010"
24 24
25/* 25/*
26 * Device IDs 26 * Device IDs
@@ -706,6 +706,7 @@ struct megasas_ctrl_info {
706#define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \ 706#define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \
707 MEGASAS_MAX_DEV_PER_CHANNEL) 707 MEGASAS_MAX_DEV_PER_CHANNEL)
708 708
709#define MEGASAS_MAX_SECTORS (2*1024)
709#define MEGASAS_DBG_LVL 1 710#define MEGASAS_DBG_LVL 1
710 711
711#define MEGASAS_FW_BUSY 1 712#define MEGASAS_FW_BUSY 1
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index 1f784fde2510..197aa1b3f0f3 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1627,7 +1627,7 @@ static void cmd_complete(struct mesh_state *ms)
1627 * Called by midlayer with host locked to queue a new 1627 * Called by midlayer with host locked to queue a new
1628 * request 1628 * request
1629 */ 1629 */
1630static int mesh_queue(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 1630static int mesh_queue_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
1631{ 1631{
1632 struct mesh_state *ms; 1632 struct mesh_state *ms;
1633 1633
@@ -1648,6 +1648,8 @@ static int mesh_queue(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
1648 return 0; 1648 return 0;
1649} 1649}
1650 1650
1651static DEF_SCSI_QCMD(mesh_queue)
1652
1651/* 1653/*
1652 * Called to handle interrupts, either call by the interrupt 1654 * Called to handle interrupts, either call by the interrupt
1653 * handler (do_mesh_interrupt) or by other functions in 1655 * handler (do_mesh_interrupt) or by other functions in
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index 16e99b686354..1a96a00418a4 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -3315,7 +3315,7 @@ _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3315 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full 3315 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3316 */ 3316 */
3317static int 3317static int
3318_scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) 3318_scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3319{ 3319{
3320 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); 3320 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3321 struct MPT2SAS_DEVICE *sas_device_priv_data; 3321 struct MPT2SAS_DEVICE *sas_device_priv_data;
@@ -3441,6 +3441,8 @@ _scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3441 return SCSI_MLQUEUE_HOST_BUSY; 3441 return SCSI_MLQUEUE_HOST_BUSY;
3442} 3442}
3443 3443
3444static DEF_SCSI_QCMD(_scsih_qcmd)
3445
3444/** 3446/**
3445 * _scsih_normalize_sense - normalize descriptor and fixed format sense data 3447 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3446 * @sense_buffer: sense data returned by target 3448 * @sense_buffer: sense data returned by target
diff --git a/drivers/scsi/ncr53c8xx.c b/drivers/scsi/ncr53c8xx.c
index d013a2aa2fd5..46cc3825638d 100644
--- a/drivers/scsi/ncr53c8xx.c
+++ b/drivers/scsi/ncr53c8xx.c
@@ -8029,7 +8029,7 @@ static int ncr53c8xx_slave_configure(struct scsi_device *device)
8029 return 0; 8029 return 0;
8030} 8030}
8031 8031
8032static int ncr53c8xx_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *)) 8032static int ncr53c8xx_queue_command_lck (struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
8033{ 8033{
8034 struct ncb *np = ((struct host_data *) cmd->device->host->hostdata)->ncb; 8034 struct ncb *np = ((struct host_data *) cmd->device->host->hostdata)->ncb;
8035 unsigned long flags; 8035 unsigned long flags;
@@ -8068,6 +8068,8 @@ printk("ncr53c8xx : command successfully queued\n");
8068 return sts; 8068 return sts;
8069} 8069}
8070 8070
8071static DEF_SCSI_QCMD(ncr53c8xx_queue_command)
8072
8071irqreturn_t ncr53c8xx_intr(int irq, void *dev_id) 8073irqreturn_t ncr53c8xx_intr(int irq, void *dev_id)
8072{ 8074{
8073 unsigned long flags; 8075 unsigned long flags;
diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index 4c1e54545200..6b8b021400f8 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -196,8 +196,7 @@ static void __exit exit_nsp32 (void);
196static int nsp32_proc_info (struct Scsi_Host *, char *, char **, off_t, int, int); 196static int nsp32_proc_info (struct Scsi_Host *, char *, char **, off_t, int, int);
197 197
198static int nsp32_detect (struct pci_dev *pdev); 198static int nsp32_detect (struct pci_dev *pdev);
199static int nsp32_queuecommand(struct scsi_cmnd *, 199static int nsp32_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
200 void (*done)(struct scsi_cmnd *));
201static const char *nsp32_info (struct Scsi_Host *); 200static const char *nsp32_info (struct Scsi_Host *);
202static int nsp32_release (struct Scsi_Host *); 201static int nsp32_release (struct Scsi_Host *);
203 202
@@ -909,7 +908,7 @@ static int nsp32_setup_sg_table(struct scsi_cmnd *SCpnt)
909 return TRUE; 908 return TRUE;
910} 909}
911 910
912static int nsp32_queuecommand(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 911static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
913{ 912{
914 nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata; 913 nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata;
915 nsp32_target *target; 914 nsp32_target *target;
@@ -1050,6 +1049,8 @@ static int nsp32_queuecommand(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_
1050 return 0; 1049 return 0;
1051} 1050}
1052 1051
1052static DEF_SCSI_QCMD(nsp32_queuecommand)
1053
1053/* initialize asic */ 1054/* initialize asic */
1054static int nsp32hw_init(nsp32_hw_data *data) 1055static int nsp32hw_init(nsp32_hw_data *data)
1055{ 1056{
diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
index e88bbdde49c5..b37c8a3c1bb0 100644
--- a/drivers/scsi/osd/osd_initiator.c
+++ b/drivers/scsi/osd/osd_initiator.c
@@ -452,10 +452,6 @@ void osd_end_request(struct osd_request *or)
452{ 452{
453 struct request *rq = or->request; 453 struct request *rq = or->request;
454 454
455 _osd_free_seg(or, &or->set_attr);
456 _osd_free_seg(or, &or->enc_get_attr);
457 _osd_free_seg(or, &or->get_attr);
458
459 if (rq) { 455 if (rq) {
460 if (rq->next_rq) { 456 if (rq->next_rq) {
461 _put_request(rq->next_rq); 457 _put_request(rq->next_rq);
@@ -464,6 +460,12 @@ void osd_end_request(struct osd_request *or)
464 460
465 _put_request(rq); 461 _put_request(rq);
466 } 462 }
463
464 _osd_free_seg(or, &or->get_attr);
465 _osd_free_seg(or, &or->enc_get_attr);
466 _osd_free_seg(or, &or->set_attr);
467 _osd_free_seg(or, &or->cdb_cont);
468
467 _osd_request_free(or); 469 _osd_request_free(or);
468} 470}
469EXPORT_SYMBOL(osd_end_request); 471EXPORT_SYMBOL(osd_end_request);
@@ -547,6 +549,12 @@ static int _osd_realloc_seg(struct osd_request *or,
547 return 0; 549 return 0;
548} 550}
549 551
552static int _alloc_cdb_cont(struct osd_request *or, unsigned total_bytes)
553{
554 OSD_DEBUG("total_bytes=%d\n", total_bytes);
555 return _osd_realloc_seg(or, &or->cdb_cont, total_bytes);
556}
557
550static int _alloc_set_attr_list(struct osd_request *or, 558static int _alloc_set_attr_list(struct osd_request *or,
551 const struct osd_attr *oa, unsigned nelem, unsigned add_bytes) 559 const struct osd_attr *oa, unsigned nelem, unsigned add_bytes)
552{ 560{
@@ -885,6 +893,199 @@ int osd_req_read_kern(struct osd_request *or,
885} 893}
886EXPORT_SYMBOL(osd_req_read_kern); 894EXPORT_SYMBOL(osd_req_read_kern);
887 895
896static int _add_sg_continuation_descriptor(struct osd_request *or,
897 const struct osd_sg_entry *sglist, unsigned numentries, u64 *len)
898{
899 struct osd_sg_continuation_descriptor *oscd;
900 u32 oscd_size;
901 unsigned i;
902 int ret;
903
904 oscd_size = sizeof(*oscd) + numentries * sizeof(oscd->entries[0]);
905
906 if (!or->cdb_cont.total_bytes) {
907 /* First time, jump over the header, we will write to:
908 * cdb_cont.buff + cdb_cont.total_bytes
909 */
910 or->cdb_cont.total_bytes =
911 sizeof(struct osd_continuation_segment_header);
912 }
913
914 ret = _alloc_cdb_cont(or, or->cdb_cont.total_bytes + oscd_size);
915 if (unlikely(ret))
916 return ret;
917
918 oscd = or->cdb_cont.buff + or->cdb_cont.total_bytes;
919 oscd->hdr.type = cpu_to_be16(SCATTER_GATHER_LIST);
920 oscd->hdr.pad_length = 0;
921 oscd->hdr.length = cpu_to_be32(oscd_size - sizeof(*oscd));
922
923 *len = 0;
924 /* copy the sg entries and convert to network byte order */
925 for (i = 0; i < numentries; i++) {
926 oscd->entries[i].offset = cpu_to_be64(sglist[i].offset);
927 oscd->entries[i].len = cpu_to_be64(sglist[i].len);
928 *len += sglist[i].len;
929 }
930
931 or->cdb_cont.total_bytes += oscd_size;
932 OSD_DEBUG("total_bytes=%d oscd_size=%d numentries=%d\n",
933 or->cdb_cont.total_bytes, oscd_size, numentries);
934 return 0;
935}
936
937static int _osd_req_finalize_cdb_cont(struct osd_request *or, const u8 *cap_key)
938{
939 struct request_queue *req_q = osd_request_queue(or->osd_dev);
940 struct bio *bio;
941 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
942 struct osd_continuation_segment_header *cont_seg_hdr;
943
944 if (!or->cdb_cont.total_bytes)
945 return 0;
946
947 cont_seg_hdr = or->cdb_cont.buff;
948 cont_seg_hdr->format = CDB_CONTINUATION_FORMAT_V2;
949 cont_seg_hdr->service_action = cdbh->varlen_cdb.service_action;
950
951 /* create a bio for continuation segment */
952 bio = bio_map_kern(req_q, or->cdb_cont.buff, or->cdb_cont.total_bytes,
953 GFP_KERNEL);
954 if (IS_ERR(bio))
955 return PTR_ERR(bio);
956
957 bio->bi_rw |= REQ_WRITE;
958
959 /* integrity check the continuation before the bio is linked
960 * with the other data segments since the continuation
961 * integrity is separate from the other data segments.
962 */
963 osd_sec_sign_data(cont_seg_hdr->integrity_check, bio, cap_key);
964
965 cdbh->v2.cdb_continuation_length = cpu_to_be32(or->cdb_cont.total_bytes);
966
967 /* we can't use _req_append_segment, because we need to link in the
968 * continuation bio to the head of the bio list - the
969 * continuation segment (if it exists) is always the first segment in
970 * the out data buffer.
971 */
972 bio->bi_next = or->out.bio;
973 or->out.bio = bio;
974 or->out.total_bytes += or->cdb_cont.total_bytes;
975
976 return 0;
977}
978
979/* osd_req_write_sg: Takes a @bio that points to the data out buffer and an
980 * @sglist that has the scatter gather entries. Scatter-gather enables a write
981 * of multiple none-contiguous areas of an object, in a single call. The extents
982 * may overlap and/or be in any order. The only constrain is that:
983 * total_bytes(sglist) >= total_bytes(bio)
984 */
985int osd_req_write_sg(struct osd_request *or,
986 const struct osd_obj_id *obj, struct bio *bio,
987 const struct osd_sg_entry *sglist, unsigned numentries)
988{
989 u64 len;
990 int ret = _add_sg_continuation_descriptor(or, sglist, numentries, &len);
991
992 if (ret)
993 return ret;
994 osd_req_write(or, obj, 0, bio, len);
995
996 return 0;
997}
998EXPORT_SYMBOL(osd_req_write_sg);
999
1000/* osd_req_read_sg: Read multiple extents of an object into @bio
1001 * See osd_req_write_sg
1002 */
1003int osd_req_read_sg(struct osd_request *or,
1004 const struct osd_obj_id *obj, struct bio *bio,
1005 const struct osd_sg_entry *sglist, unsigned numentries)
1006{
1007 u64 len;
1008 int ret = _add_sg_continuation_descriptor(or, sglist, numentries, &len);
1009
1010 if (ret)
1011 return ret;
1012 osd_req_read(or, obj, 0, bio, len);
1013
1014 return 0;
1015}
1016EXPORT_SYMBOL(osd_req_read_sg);
1017
1018/* SG-list write/read Kern API
1019 *
1020 * osd_req_{write,read}_sg_kern takes an array of @buff pointers and an array
1021 * of sg_entries. @numentries indicates how many pointers and sg_entries there
1022 * are. By requiring an array of buff pointers. This allows a caller to do a
1023 * single write/read and scatter into multiple buffers.
1024 * NOTE: Each buffer + len should not cross a page boundary.
1025 */
1026static struct bio *_create_sg_bios(struct osd_request *or,
1027 void **buff, const struct osd_sg_entry *sglist, unsigned numentries)
1028{
1029 struct request_queue *q = osd_request_queue(or->osd_dev);
1030 struct bio *bio;
1031 unsigned i;
1032
1033 bio = bio_kmalloc(GFP_KERNEL, numentries);
1034 if (unlikely(!bio)) {
1035 OSD_DEBUG("Faild to allocate BIO size=%u\n", numentries);
1036 return ERR_PTR(-ENOMEM);
1037 }
1038
1039 for (i = 0; i < numentries; i++) {
1040 unsigned offset = offset_in_page(buff[i]);
1041 struct page *page = virt_to_page(buff[i]);
1042 unsigned len = sglist[i].len;
1043 unsigned added_len;
1044
1045 BUG_ON(offset + len > PAGE_SIZE);
1046 added_len = bio_add_pc_page(q, bio, page, len, offset);
1047 if (unlikely(len != added_len)) {
1048 OSD_DEBUG("bio_add_pc_page len(%d) != added_len(%d)\n",
1049 len, added_len);
1050 bio_put(bio);
1051 return ERR_PTR(-ENOMEM);
1052 }
1053 }
1054
1055 return bio;
1056}
1057
1058int osd_req_write_sg_kern(struct osd_request *or,
1059 const struct osd_obj_id *obj, void **buff,
1060 const struct osd_sg_entry *sglist, unsigned numentries)
1061{
1062 struct bio *bio = _create_sg_bios(or, buff, sglist, numentries);
1063 if (IS_ERR(bio))
1064 return PTR_ERR(bio);
1065
1066 bio->bi_rw |= REQ_WRITE;
1067 osd_req_write_sg(or, obj, bio, sglist, numentries);
1068
1069 return 0;
1070}
1071EXPORT_SYMBOL(osd_req_write_sg_kern);
1072
1073int osd_req_read_sg_kern(struct osd_request *or,
1074 const struct osd_obj_id *obj, void **buff,
1075 const struct osd_sg_entry *sglist, unsigned numentries)
1076{
1077 struct bio *bio = _create_sg_bios(or, buff, sglist, numentries);
1078 if (IS_ERR(bio))
1079 return PTR_ERR(bio);
1080
1081 osd_req_read_sg(or, obj, bio, sglist, numentries);
1082
1083 return 0;
1084}
1085EXPORT_SYMBOL(osd_req_read_sg_kern);
1086
1087
1088
888void osd_req_get_attributes(struct osd_request *or, 1089void osd_req_get_attributes(struct osd_request *or,
889 const struct osd_obj_id *obj) 1090 const struct osd_obj_id *obj)
890{ 1091{
@@ -1218,17 +1419,18 @@ int osd_req_add_get_attr_page(struct osd_request *or,
1218 or->get_attr.buff = attar_page; 1419 or->get_attr.buff = attar_page;
1219 or->get_attr.total_bytes = max_page_len; 1420 or->get_attr.total_bytes = max_page_len;
1220 1421
1221 or->set_attr.buff = set_one_attr->val_ptr;
1222 or->set_attr.total_bytes = set_one_attr->len;
1223
1224 cdbh->attrs_page.get_attr_page = cpu_to_be32(page_id); 1422 cdbh->attrs_page.get_attr_page = cpu_to_be32(page_id);
1225 cdbh->attrs_page.get_attr_alloc_length = cpu_to_be32(max_page_len); 1423 cdbh->attrs_page.get_attr_alloc_length = cpu_to_be32(max_page_len);
1226 /* ocdb->attrs_page.get_attr_offset; */ 1424
1425 if (!set_one_attr || !set_one_attr->attr_page)
1426 return 0; /* The set is optional */
1427
1428 or->set_attr.buff = set_one_attr->val_ptr;
1429 or->set_attr.total_bytes = set_one_attr->len;
1227 1430
1228 cdbh->attrs_page.set_attr_page = cpu_to_be32(set_one_attr->attr_page); 1431 cdbh->attrs_page.set_attr_page = cpu_to_be32(set_one_attr->attr_page);
1229 cdbh->attrs_page.set_attr_id = cpu_to_be32(set_one_attr->attr_id); 1432 cdbh->attrs_page.set_attr_id = cpu_to_be32(set_one_attr->attr_id);
1230 cdbh->attrs_page.set_attr_length = cpu_to_be32(set_one_attr->len); 1433 cdbh->attrs_page.set_attr_length = cpu_to_be32(set_one_attr->len);
1231 /* ocdb->attrs_page.set_attr_offset; */
1232 return 0; 1434 return 0;
1233} 1435}
1234EXPORT_SYMBOL(osd_req_add_get_attr_page); 1436EXPORT_SYMBOL(osd_req_add_get_attr_page);
@@ -1248,11 +1450,14 @@ static int _osd_req_finalize_attr_page(struct osd_request *or)
1248 if (ret) 1450 if (ret)
1249 return ret; 1451 return ret;
1250 1452
1453 if (or->set_attr.total_bytes == 0)
1454 return 0;
1455
1251 /* set one value */ 1456 /* set one value */
1252 cdbh->attrs_page.set_attr_offset = 1457 cdbh->attrs_page.set_attr_offset =
1253 osd_req_encode_offset(or, or->out.total_bytes, &out_padding); 1458 osd_req_encode_offset(or, or->out.total_bytes, &out_padding);
1254 1459
1255 ret = _req_append_segment(or, out_padding, &or->enc_get_attr, NULL, 1460 ret = _req_append_segment(or, out_padding, &or->set_attr, NULL,
1256 &or->out); 1461 &or->out);
1257 return ret; 1462 return ret;
1258} 1463}
@@ -1276,7 +1481,8 @@ static inline void osd_sec_parms_set_in_offset(bool is_v1,
1276} 1481}
1277 1482
1278static int _osd_req_finalize_data_integrity(struct osd_request *or, 1483static int _osd_req_finalize_data_integrity(struct osd_request *or,
1279 bool has_in, bool has_out, u64 out_data_bytes, const u8 *cap_key) 1484 bool has_in, bool has_out, struct bio *out_data_bio, u64 out_data_bytes,
1485 const u8 *cap_key)
1280{ 1486{
1281 struct osd_security_parameters *sec_parms = _osd_req_sec_params(or); 1487 struct osd_security_parameters *sec_parms = _osd_req_sec_params(or);
1282 int ret; 1488 int ret;
@@ -1307,7 +1513,7 @@ static int _osd_req_finalize_data_integrity(struct osd_request *or,
1307 or->out.last_seg = NULL; 1513 or->out.last_seg = NULL;
1308 1514
1309 /* they are now all chained to request sign them all together */ 1515 /* they are now all chained to request sign them all together */
1310 osd_sec_sign_data(&or->out_data_integ, or->out.req->bio, 1516 osd_sec_sign_data(&or->out_data_integ, out_data_bio,
1311 cap_key); 1517 cap_key);
1312 } 1518 }
1313 1519
@@ -1403,6 +1609,8 @@ int osd_finalize_request(struct osd_request *or,
1403{ 1609{
1404 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb); 1610 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
1405 bool has_in, has_out; 1611 bool has_in, has_out;
1612 /* Save for data_integrity without the cdb_continuation */
1613 struct bio *out_data_bio = or->out.bio;
1406 u64 out_data_bytes = or->out.total_bytes; 1614 u64 out_data_bytes = or->out.total_bytes;
1407 int ret; 1615 int ret;
1408 1616
@@ -1418,9 +1626,14 @@ int osd_finalize_request(struct osd_request *or,
1418 osd_set_caps(&or->cdb, cap); 1626 osd_set_caps(&or->cdb, cap);
1419 1627
1420 has_in = or->in.bio || or->get_attr.total_bytes; 1628 has_in = or->in.bio || or->get_attr.total_bytes;
1421 has_out = or->out.bio || or->set_attr.total_bytes || 1629 has_out = or->out.bio || or->cdb_cont.total_bytes ||
1422 or->enc_get_attr.total_bytes; 1630 or->set_attr.total_bytes || or->enc_get_attr.total_bytes;
1423 1631
1632 ret = _osd_req_finalize_cdb_cont(or, cap_key);
1633 if (ret) {
1634 OSD_DEBUG("_osd_req_finalize_cdb_cont failed\n");
1635 return ret;
1636 }
1424 ret = _init_blk_request(or, has_in, has_out); 1637 ret = _init_blk_request(or, has_in, has_out);
1425 if (ret) { 1638 if (ret) {
1426 OSD_DEBUG("_init_blk_request failed\n"); 1639 OSD_DEBUG("_init_blk_request failed\n");
@@ -1458,7 +1671,8 @@ int osd_finalize_request(struct osd_request *or,
1458 } 1671 }
1459 1672
1460 ret = _osd_req_finalize_data_integrity(or, has_in, has_out, 1673 ret = _osd_req_finalize_data_integrity(or, has_in, has_out,
1461 out_data_bytes, cap_key); 1674 out_data_bio, out_data_bytes,
1675 cap_key);
1462 if (ret) 1676 if (ret)
1463 return ret; 1677 return ret;
1464 1678
diff --git a/drivers/scsi/pas16.h b/drivers/scsi/pas16.h
index 8dc5b1a5f5da..a04281cace2e 100644
--- a/drivers/scsi/pas16.h
+++ b/drivers/scsi/pas16.h
@@ -118,7 +118,7 @@ static int pas16_abort(Scsi_Cmnd *);
118static int pas16_biosparam(struct scsi_device *, struct block_device *, 118static int pas16_biosparam(struct scsi_device *, struct block_device *,
119 sector_t, int*); 119 sector_t, int*);
120static int pas16_detect(struct scsi_host_template *); 120static int pas16_detect(struct scsi_host_template *);
121static int pas16_queue_command(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *)); 121static int pas16_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
122static int pas16_bus_reset(Scsi_Cmnd *); 122static int pas16_bus_reset(Scsi_Cmnd *);
123 123
124#ifndef CMD_PER_LUN 124#ifndef CMD_PER_LUN
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 9326c2c14880..be3f33d31a99 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -184,7 +184,7 @@ static void nsp_scsi_done(struct scsi_cmnd *SCpnt)
184 SCpnt->scsi_done(SCpnt); 184 SCpnt->scsi_done(SCpnt);
185} 185}
186 186
187static int nsp_queuecommand(struct scsi_cmnd *SCpnt, 187static int nsp_queuecommand_lck(struct scsi_cmnd *SCpnt,
188 void (*done)(struct scsi_cmnd *)) 188 void (*done)(struct scsi_cmnd *))
189{ 189{
190#ifdef NSP_DEBUG 190#ifdef NSP_DEBUG
@@ -264,6 +264,8 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt,
264 return 0; 264 return 0;
265} 265}
266 266
267static DEF_SCSI_QCMD(nsp_queuecommand)
268
267/* 269/*
268 * setup PIO FIFO transfer mode and enable/disable to data out 270 * setup PIO FIFO transfer mode and enable/disable to data out
269 */ 271 */
diff --git a/drivers/scsi/pcmcia/nsp_cs.h b/drivers/scsi/pcmcia/nsp_cs.h
index d68c9f267c5e..7fc9a9d0a448 100644
--- a/drivers/scsi/pcmcia/nsp_cs.h
+++ b/drivers/scsi/pcmcia/nsp_cs.h
@@ -299,8 +299,7 @@ static int nsp_proc_info (
299 off_t offset, 299 off_t offset,
300 int length, 300 int length,
301 int inout); 301 int inout);
302static int nsp_queuecommand(struct scsi_cmnd *SCpnt, 302static int nsp_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *SCpnt);
303 void (* done)(struct scsi_cmnd *SCpnt));
304 303
305/* Error handler */ 304/* Error handler */
306/*static int nsp_eh_abort (struct scsi_cmnd *SCpnt);*/ 305/*static int nsp_eh_abort (struct scsi_cmnd *SCpnt);*/
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 0ae27cb5cd6f..8552296edaa1 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -547,7 +547,7 @@ SYM53C500_info(struct Scsi_Host *SChost)
547} 547}
548 548
549static int 549static int
550SYM53C500_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 550SYM53C500_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
551{ 551{
552 int i; 552 int i;
553 int port_base = SCpnt->device->host->io_port; 553 int port_base = SCpnt->device->host->io_port;
@@ -583,6 +583,8 @@ SYM53C500_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
583 return 0; 583 return 0;
584} 584}
585 585
586static DEF_SCSI_QCMD(SYM53C500_queue)
587
586static int 588static int
587SYM53C500_host_reset(struct scsi_cmnd *SCpnt) 589SYM53C500_host_reset(struct scsi_cmnd *SCpnt)
588{ 590{
diff --git a/drivers/scsi/pm8001/pm8001_sas.h b/drivers/scsi/pm8001/pm8001_sas.h
index 8e38ca8cd101..7f064f9ca828 100644
--- a/drivers/scsi/pm8001/pm8001_sas.h
+++ b/drivers/scsi/pm8001/pm8001_sas.h
@@ -50,7 +50,6 @@
50#include <linux/dma-mapping.h> 50#include <linux/dma-mapping.h>
51#include <linux/pci.h> 51#include <linux/pci.h>
52#include <linux/interrupt.h> 52#include <linux/interrupt.h>
53#include <linux/smp_lock.h>
54#include <scsi/libsas.h> 53#include <scsi/libsas.h>
55#include <scsi/scsi_tcq.h> 54#include <scsi/scsi_tcq.h>
56#include <scsi/sas_ata.h> 55#include <scsi/sas_ata.h>
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 4b8765785aeb..300d59f389da 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -62,6 +62,7 @@
62static unsigned int pmcraid_debug_log; 62static unsigned int pmcraid_debug_log;
63static unsigned int pmcraid_disable_aen; 63static unsigned int pmcraid_disable_aen;
64static unsigned int pmcraid_log_level = IOASC_LOG_LEVEL_MUST; 64static unsigned int pmcraid_log_level = IOASC_LOG_LEVEL_MUST;
65static unsigned int pmcraid_enable_msix;
65 66
66/* 67/*
67 * Data structures to support multiple adapters by the LLD. 68 * Data structures to support multiple adapters by the LLD.
@@ -1594,10 +1595,12 @@ static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
1594 cfg_entry = &ccn_hcam->cfg_entry; 1595 cfg_entry = &ccn_hcam->cfg_entry;
1595 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); 1596 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
1596 1597
1597 pmcraid_info 1598 pmcraid_info("CCN(%x): %x timestamp: %llx type: %x lost: %x flags: %x \
1598 ("CCN(%x): %x type: %x lost: %x flags: %x res: %x:%x:%x:%x\n", 1599 res: %x:%x:%x:%x\n",
1599 pinstance->ccn.hcam->ilid, 1600 pinstance->ccn.hcam->ilid,
1600 pinstance->ccn.hcam->op_code, 1601 pinstance->ccn.hcam->op_code,
1602 ((pinstance->ccn.hcam->timestamp1) |
1603 ((pinstance->ccn.hcam->timestamp2 & 0xffffffffLL) << 32)),
1601 pinstance->ccn.hcam->notification_type, 1604 pinstance->ccn.hcam->notification_type,
1602 pinstance->ccn.hcam->notification_lost, 1605 pinstance->ccn.hcam->notification_lost,
1603 pinstance->ccn.hcam->flags, 1606 pinstance->ccn.hcam->flags,
@@ -1850,6 +1853,7 @@ static void pmcraid_process_ccn(struct pmcraid_cmd *cmd)
1850 * none 1853 * none
1851 */ 1854 */
1852static void pmcraid_initiate_reset(struct pmcraid_instance *); 1855static void pmcraid_initiate_reset(struct pmcraid_instance *);
1856static void pmcraid_set_timestamp(struct pmcraid_cmd *cmd);
1853 1857
1854static void pmcraid_process_ldn(struct pmcraid_cmd *cmd) 1858static void pmcraid_process_ldn(struct pmcraid_cmd *cmd)
1855{ 1859{
@@ -1881,6 +1885,10 @@ static void pmcraid_process_ldn(struct pmcraid_cmd *cmd)
1881 lock_flags); 1885 lock_flags);
1882 return; 1886 return;
1883 } 1887 }
1888 if (fd_ioasc == PMCRAID_IOASC_TIME_STAMP_OUT_OF_SYNC) {
1889 pinstance->timestamp_error = 1;
1890 pmcraid_set_timestamp(cmd);
1891 }
1884 } else { 1892 } else {
1885 dev_info(&pinstance->pdev->dev, 1893 dev_info(&pinstance->pdev->dev,
1886 "Host RCB(LDN) failed with IOASC: 0x%08X\n", ioasc); 1894 "Host RCB(LDN) failed with IOASC: 0x%08X\n", ioasc);
@@ -3363,7 +3371,7 @@ static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen)
3363 sg_size = buflen; 3371 sg_size = buflen;
3364 3372
3365 for (i = 0; i < num_elem; i++) { 3373 for (i = 0; i < num_elem; i++) {
3366 page = alloc_pages(GFP_KERNEL|GFP_DMA, order); 3374 page = alloc_pages(GFP_KERNEL|GFP_DMA|__GFP_ZERO, order);
3367 if (!page) { 3375 if (!page) {
3368 for (j = i - 1; j >= 0; j--) 3376 for (j = i - 1; j >= 0; j--)
3369 __free_pages(sg_page(&scatterlist[j]), order); 3377 __free_pages(sg_page(&scatterlist[j]), order);
@@ -3471,7 +3479,7 @@ static int pmcraid_copy_sglist(
3471 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy 3479 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
3472 * SCSI_MLQUEUE_HOST_BUSY if host is busy 3480 * SCSI_MLQUEUE_HOST_BUSY if host is busy
3473 */ 3481 */
3474static int pmcraid_queuecommand( 3482static int pmcraid_queuecommand_lck(
3475 struct scsi_cmnd *scsi_cmd, 3483 struct scsi_cmnd *scsi_cmd,
3476 void (*done) (struct scsi_cmnd *) 3484 void (*done) (struct scsi_cmnd *)
3477) 3485)
@@ -3577,6 +3585,8 @@ static int pmcraid_queuecommand(
3577 return rc; 3585 return rc;
3578} 3586}
3579 3587
3588static DEF_SCSI_QCMD(pmcraid_queuecommand)
3589
3580/** 3590/**
3581 * pmcraid_open -char node "open" entry, allowed only users with admin access 3591 * pmcraid_open -char node "open" entry, allowed only users with admin access
3582 */ 3592 */
@@ -3739,6 +3749,7 @@ static long pmcraid_ioctl_passthrough(
3739 unsigned long request_buffer; 3749 unsigned long request_buffer;
3740 unsigned long request_offset; 3750 unsigned long request_offset;
3741 unsigned long lock_flags; 3751 unsigned long lock_flags;
3752 void *ioasa;
3742 u32 ioasc; 3753 u32 ioasc;
3743 int request_size; 3754 int request_size;
3744 int buffer_size; 3755 int buffer_size;
@@ -3780,6 +3791,11 @@ static long pmcraid_ioctl_passthrough(
3780 rc = __copy_from_user(buffer, 3791 rc = __copy_from_user(buffer,
3781 (struct pmcraid_passthrough_ioctl_buffer *) arg, 3792 (struct pmcraid_passthrough_ioctl_buffer *) arg,
3782 sizeof(struct pmcraid_passthrough_ioctl_buffer)); 3793 sizeof(struct pmcraid_passthrough_ioctl_buffer));
3794
3795 ioasa =
3796 (void *)(arg +
3797 offsetof(struct pmcraid_passthrough_ioctl_buffer, ioasa));
3798
3783 if (rc) { 3799 if (rc) {
3784 pmcraid_err("ioctl: can't copy passthrough buffer\n"); 3800 pmcraid_err("ioctl: can't copy passthrough buffer\n");
3785 rc = -EFAULT; 3801 rc = -EFAULT;
@@ -3947,22 +3963,14 @@ static long pmcraid_ioctl_passthrough(
3947 } 3963 }
3948 3964
3949out_handle_response: 3965out_handle_response:
3950 /* If the command failed for any reason, copy entire IOASA buffer and 3966 /* copy entire IOASA buffer and return IOCTL success.
3951 * return IOCTL success. If copying IOASA to user-buffer fails, return 3967 * If copying IOASA to user-buffer fails, return
3952 * EFAULT 3968 * EFAULT
3953 */ 3969 */
3954 if (PMCRAID_IOASC_SENSE_KEY(le32_to_cpu(cmd->ioa_cb->ioasa.ioasc))) { 3970 if (copy_to_user(ioasa, &cmd->ioa_cb->ioasa,
3955 void *ioasa = 3971 sizeof(struct pmcraid_ioasa))) {
3956 (void *)(arg + 3972 pmcraid_err("failed to copy ioasa buffer to user\n");
3957 offsetof(struct pmcraid_passthrough_ioctl_buffer, ioasa)); 3973 rc = -EFAULT;
3958
3959 pmcraid_info("command failed with %x\n",
3960 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc));
3961 if (copy_to_user(ioasa, &cmd->ioa_cb->ioasa,
3962 sizeof(struct pmcraid_ioasa))) {
3963 pmcraid_err("failed to copy ioasa buffer to user\n");
3964 rc = -EFAULT;
3965 }
3966 } 3974 }
3967 3975
3968 /* If the data transfer was from device, copy the data onto user 3976 /* If the data transfer was from device, copy the data onto user
@@ -4684,7 +4692,8 @@ pmcraid_register_interrupt_handler(struct pmcraid_instance *pinstance)
4684 int rc; 4692 int rc;
4685 struct pci_dev *pdev = pinstance->pdev; 4693 struct pci_dev *pdev = pinstance->pdev;
4686 4694
4687 if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) { 4695 if ((pmcraid_enable_msix) &&
4696 (pci_find_capability(pdev, PCI_CAP_ID_MSIX))) {
4688 int num_hrrq = PMCRAID_NUM_MSIX_VECTORS; 4697 int num_hrrq = PMCRAID_NUM_MSIX_VECTORS;
4689 struct msix_entry entries[PMCRAID_NUM_MSIX_VECTORS]; 4698 struct msix_entry entries[PMCRAID_NUM_MSIX_VECTORS];
4690 int i; 4699 int i;
@@ -5147,6 +5156,16 @@ static void pmcraid_release_buffers(struct pmcraid_instance *pinstance)
5147 pinstance->inq_data = NULL; 5156 pinstance->inq_data = NULL;
5148 pinstance->inq_data_baddr = 0; 5157 pinstance->inq_data_baddr = 0;
5149 } 5158 }
5159
5160 if (pinstance->timestamp_data != NULL) {
5161 pci_free_consistent(pinstance->pdev,
5162 sizeof(struct pmcraid_timestamp_data),
5163 pinstance->timestamp_data,
5164 pinstance->timestamp_data_baddr);
5165
5166 pinstance->timestamp_data = NULL;
5167 pinstance->timestamp_data_baddr = 0;
5168 }
5150} 5169}
5151 5170
5152/** 5171/**
@@ -5205,6 +5224,20 @@ static int __devinit pmcraid_init_buffers(struct pmcraid_instance *pinstance)
5205 return -ENOMEM; 5224 return -ENOMEM;
5206 } 5225 }
5207 5226
5227 /* allocate DMAable memory for set timestamp data buffer */
5228 pinstance->timestamp_data = pci_alloc_consistent(
5229 pinstance->pdev,
5230 sizeof(struct pmcraid_timestamp_data),
5231 &pinstance->timestamp_data_baddr);
5232
5233 if (pinstance->timestamp_data == NULL) {
5234 pmcraid_err("couldn't allocate DMA memory for \
5235 set time_stamp \n");
5236 pmcraid_release_buffers(pinstance);
5237 return -ENOMEM;
5238 }
5239
5240
5208 /* Initialize all the command blocks and add them to free pool. No 5241 /* Initialize all the command blocks and add them to free pool. No
5209 * need to lock (free_pool_lock) as this is done in initialization 5242 * need to lock (free_pool_lock) as this is done in initialization
5210 * itself 5243 * itself
@@ -5610,6 +5643,68 @@ static void pmcraid_set_supported_devs(struct pmcraid_cmd *cmd)
5610} 5643}
5611 5644
5612/** 5645/**
5646 * pmcraid_set_timestamp - set the timestamp to IOAFP
5647 *
5648 * @cmd: pointer to pmcraid_cmd structure
5649 *
5650 * Return Value
5651 * 0 for success or non-zero for failure cases
5652 */
5653static void pmcraid_set_timestamp(struct pmcraid_cmd *cmd)
5654{
5655 struct pmcraid_instance *pinstance = cmd->drv_inst;
5656 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb;
5657 __be32 time_stamp_len = cpu_to_be32(PMCRAID_TIMESTAMP_LEN);
5658 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl;
5659
5660 struct timeval tv;
5661 __le64 timestamp;
5662
5663 do_gettimeofday(&tv);
5664 timestamp = tv.tv_sec * 1000;
5665
5666 pinstance->timestamp_data->timestamp[0] = (__u8)(timestamp);
5667 pinstance->timestamp_data->timestamp[1] = (__u8)((timestamp) >> 8);
5668 pinstance->timestamp_data->timestamp[2] = (__u8)((timestamp) >> 16);
5669 pinstance->timestamp_data->timestamp[3] = (__u8)((timestamp) >> 24);
5670 pinstance->timestamp_data->timestamp[4] = (__u8)((timestamp) >> 32);
5671 pinstance->timestamp_data->timestamp[5] = (__u8)((timestamp) >> 40);
5672
5673 pmcraid_reinit_cmdblk(cmd);
5674 ioarcb->request_type = REQ_TYPE_SCSI;
5675 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE);
5676 ioarcb->cdb[0] = PMCRAID_SCSI_SET_TIMESTAMP;
5677 ioarcb->cdb[1] = PMCRAID_SCSI_SERVICE_ACTION;
5678 memcpy(&(ioarcb->cdb[6]), &time_stamp_len, sizeof(time_stamp_len));
5679
5680 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) +
5681 offsetof(struct pmcraid_ioarcb,
5682 add_data.u.ioadl[0]));
5683 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc));
5684 ioarcb->ioarcb_bus_addr &= ~(0x1FULL);
5685
5686 ioarcb->request_flags0 |= NO_LINK_DESCS;
5687 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE;
5688 ioarcb->data_transfer_length =
5689 cpu_to_le32(sizeof(struct pmcraid_timestamp_data));
5690 ioadl = &(ioarcb->add_data.u.ioadl[0]);
5691 ioadl->flags = IOADL_FLAGS_LAST_DESC;
5692 ioadl->address = cpu_to_le64(pinstance->timestamp_data_baddr);
5693 ioadl->data_len = cpu_to_le32(sizeof(struct pmcraid_timestamp_data));
5694
5695 if (!pinstance->timestamp_error) {
5696 pinstance->timestamp_error = 0;
5697 pmcraid_send_cmd(cmd, pmcraid_set_supported_devs,
5698 PMCRAID_INTERNAL_TIMEOUT, pmcraid_timeout_handler);
5699 } else {
5700 pmcraid_send_cmd(cmd, pmcraid_return_cmd,
5701 PMCRAID_INTERNAL_TIMEOUT, pmcraid_timeout_handler);
5702 return;
5703 }
5704}
5705
5706
5707/**
5613 * pmcraid_init_res_table - Initialize the resource table 5708 * pmcraid_init_res_table - Initialize the resource table
5614 * @cmd: pointer to pmcraid command struct 5709 * @cmd: pointer to pmcraid command struct
5615 * 5710 *
@@ -5720,7 +5815,7 @@ static void pmcraid_init_res_table(struct pmcraid_cmd *cmd)
5720 5815
5721 /* release the resource list lock */ 5816 /* release the resource list lock */
5722 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); 5817 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
5723 pmcraid_set_supported_devs(cmd); 5818 pmcraid_set_timestamp(cmd);
5724} 5819}
5725 5820
5726/** 5821/**
@@ -6054,10 +6149,10 @@ out_init:
6054static void __exit pmcraid_exit(void) 6149static void __exit pmcraid_exit(void)
6055{ 6150{
6056 pmcraid_netlink_release(); 6151 pmcraid_netlink_release();
6057 class_destroy(pmcraid_class);
6058 unregister_chrdev_region(MKDEV(pmcraid_major, 0), 6152 unregister_chrdev_region(MKDEV(pmcraid_major, 0),
6059 PMCRAID_MAX_ADAPTERS); 6153 PMCRAID_MAX_ADAPTERS);
6060 pci_unregister_driver(&pmcraid_driver); 6154 pci_unregister_driver(&pmcraid_driver);
6155 class_destroy(pmcraid_class);
6061} 6156}
6062 6157
6063module_init(pmcraid_init); 6158module_init(pmcraid_init);
diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
index 6cfa0145a1d7..4db210d93947 100644
--- a/drivers/scsi/pmcraid.h
+++ b/drivers/scsi/pmcraid.h
@@ -42,7 +42,7 @@
42 */ 42 */
43#define PMCRAID_DRIVER_NAME "PMC MaxRAID" 43#define PMCRAID_DRIVER_NAME "PMC MaxRAID"
44#define PMCRAID_DEVFILE "pmcsas" 44#define PMCRAID_DEVFILE "pmcsas"
45#define PMCRAID_DRIVER_VERSION "2.0.2" 45#define PMCRAID_DRIVER_VERSION "1.0.3"
46#define PMCRAID_DRIVER_DATE __DATE__ 46#define PMCRAID_DRIVER_DATE __DATE__
47 47
48#define PMCRAID_FW_VERSION_1 0x002 48#define PMCRAID_FW_VERSION_1 0x002
@@ -184,6 +184,7 @@
184#define PMCRAID_IOASC_IR_INVALID_RESOURCE_HANDLE 0x05250000 184#define PMCRAID_IOASC_IR_INVALID_RESOURCE_HANDLE 0x05250000
185#define PMCRAID_IOASC_AC_TERMINATED_BY_HOST 0x0B5A0000 185#define PMCRAID_IOASC_AC_TERMINATED_BY_HOST 0x0B5A0000
186#define PMCRAID_IOASC_UA_BUS_WAS_RESET 0x06290000 186#define PMCRAID_IOASC_UA_BUS_WAS_RESET 0x06290000
187#define PMCRAID_IOASC_TIME_STAMP_OUT_OF_SYNC 0x06908B00
187#define PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER 0x06298000 188#define PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER 0x06298000
188 189
189/* Driver defined IOASCs */ 190/* Driver defined IOASCs */
@@ -332,11 +333,9 @@ struct pmcraid_config_table_entry {
332 __u8 lun[PMCRAID_LUN_LEN]; 333 __u8 lun[PMCRAID_LUN_LEN];
333} __attribute__((packed, aligned(4))); 334} __attribute__((packed, aligned(4)));
334 335
335/* extended configuration table sizes are of 64 bytes in size */ 336/* extended configuration table sizes are also of 32 bytes in size */
336#define PMCRAID_CFGTE_EXT_SIZE 32
337struct pmcraid_config_table_entry_ext { 337struct pmcraid_config_table_entry_ext {
338 struct pmcraid_config_table_entry cfgte; 338 struct pmcraid_config_table_entry cfgte;
339 __u8 cfgte_ext[PMCRAID_CFGTE_EXT_SIZE];
340}; 339};
341 340
342/* resource types (config_table_entry.resource_type values) */ 341/* resource types (config_table_entry.resource_type values) */
@@ -561,6 +560,17 @@ struct pmcraid_inquiry_data {
561 __u8 reserved3[16]; 560 __u8 reserved3[16];
562}; 561};
563 562
563#define PMCRAID_TIMESTAMP_LEN 12
564#define PMCRAID_REQ_TM_STR_LEN 6
565#define PMCRAID_SCSI_SET_TIMESTAMP 0xA4
566#define PMCRAID_SCSI_SERVICE_ACTION 0x0F
567
568struct pmcraid_timestamp_data {
569 __u8 reserved1[4];
570 __u8 timestamp[PMCRAID_REQ_TM_STR_LEN]; /* current time value */
571 __u8 reserved2[2];
572};
573
564/* pmcraid_cmd - LLD representation of SCSI command */ 574/* pmcraid_cmd - LLD representation of SCSI command */
565struct pmcraid_cmd { 575struct pmcraid_cmd {
566 576
@@ -568,7 +578,6 @@ struct pmcraid_cmd {
568 struct pmcraid_control_block *ioa_cb; 578 struct pmcraid_control_block *ioa_cb;
569 dma_addr_t ioa_cb_bus_addr; 579 dma_addr_t ioa_cb_bus_addr;
570 dma_addr_t dma_handle; 580 dma_addr_t dma_handle;
571 u8 *sense_buffer;
572 581
573 /* pointer to mid layer structure of SCSI commands */ 582 /* pointer to mid layer structure of SCSI commands */
574 struct scsi_cmnd *scsi_cmd; 583 struct scsi_cmnd *scsi_cmd;
@@ -705,6 +714,9 @@ struct pmcraid_instance {
705 struct pmcraid_inquiry_data *inq_data; 714 struct pmcraid_inquiry_data *inq_data;
706 dma_addr_t inq_data_baddr; 715 dma_addr_t inq_data_baddr;
707 716
717 struct pmcraid_timestamp_data *timestamp_data;
718 dma_addr_t timestamp_data_baddr;
719
708 /* size of configuration table entry, varies based on the firmware */ 720 /* size of configuration table entry, varies based on the firmware */
709 u32 config_table_entry_size; 721 u32 config_table_entry_size;
710 722
@@ -791,6 +803,7 @@ struct pmcraid_instance {
791#define SHUTDOWN_NONE 0x0 803#define SHUTDOWN_NONE 0x0
792#define SHUTDOWN_NORMAL 0x1 804#define SHUTDOWN_NORMAL 0x1
793#define SHUTDOWN_ABBREV 0x2 805#define SHUTDOWN_ABBREV 0x2
806 u32 timestamp_error:1; /* indicate set timestamp for out of sync */
794 807
795}; 808};
796 809
@@ -1056,10 +1069,10 @@ struct pmcraid_passthrough_ioctl_buffer {
1056#define PMCRAID_PASSTHROUGH_IOCTL 'F' 1069#define PMCRAID_PASSTHROUGH_IOCTL 'F'
1057 1070
1058#define DRV_IOCTL(n, size) \ 1071#define DRV_IOCTL(n, size) \
1059 _IOC(_IOC_READ|_IOC_WRITE, PMCRAID_DRIVER_IOCTL, (n), (size)) 1072 _IOC(_IOC_READ|_IOC_WRITE, PMCRAID_DRIVER_IOCTL, (n), (size))
1060 1073
1061#define FMW_IOCTL(n, size) \ 1074#define FMW_IOCTL(n, size) \
1062 _IOC(_IOC_READ|_IOC_WRITE, PMCRAID_PASSTHROUGH_IOCTL, (n), (size)) 1075 _IOC(_IOC_READ|_IOC_WRITE, PMCRAID_PASSTHROUGH_IOCTL, (n), (size))
1063 1076
1064/* 1077/*
1065 * _ARGSIZE: macro that gives size of the argument type passed to an IOCTL cmd. 1078 * _ARGSIZE: macro that gives size of the argument type passed to an IOCTL cmd.
diff --git a/drivers/scsi/ppa.c b/drivers/scsi/ppa.c
index 7bc2d796e403..d164c9639361 100644
--- a/drivers/scsi/ppa.c
+++ b/drivers/scsi/ppa.c
@@ -798,7 +798,7 @@ static int ppa_engine(ppa_struct *dev, struct scsi_cmnd *cmd)
798 return 0; 798 return 0;
799} 799}
800 800
801static int ppa_queuecommand(struct scsi_cmnd *cmd, 801static int ppa_queuecommand_lck(struct scsi_cmnd *cmd,
802 void (*done) (struct scsi_cmnd *)) 802 void (*done) (struct scsi_cmnd *))
803{ 803{
804 ppa_struct *dev = ppa_dev(cmd->device->host); 804 ppa_struct *dev = ppa_dev(cmd->device->host);
@@ -821,6 +821,8 @@ static int ppa_queuecommand(struct scsi_cmnd *cmd,
821 return 0; 821 return 0;
822} 822}
823 823
824static DEF_SCSI_QCMD(ppa_queuecommand)
825
824/* 826/*
825 * Apparently the disk->capacity attribute is off by 1 sector 827 * Apparently the disk->capacity attribute is off by 1 sector
826 * for all disk drives. We add the one here, but it should really 828 * for all disk drives. We add the one here, but it should really
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index 92ffbb510498..cd178b9e40cd 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -211,7 +211,7 @@ static int ps3rom_write_request(struct ps3_storage_device *dev,
211 return 0; 211 return 0;
212} 212}
213 213
214static int ps3rom_queuecommand(struct scsi_cmnd *cmd, 214static int ps3rom_queuecommand_lck(struct scsi_cmnd *cmd,
215 void (*done)(struct scsi_cmnd *)) 215 void (*done)(struct scsi_cmnd *))
216{ 216{
217 struct ps3rom_private *priv = shost_priv(cmd->device->host); 217 struct ps3rom_private *priv = shost_priv(cmd->device->host);
@@ -260,6 +260,8 @@ static int ps3rom_queuecommand(struct scsi_cmnd *cmd,
260 return 0; 260 return 0;
261} 261}
262 262
263static DEF_SCSI_QCMD(ps3rom_queuecommand)
264
263static int decode_lv1_status(u64 status, unsigned char *sense_key, 265static int decode_lv1_status(u64 status, unsigned char *sense_key,
264 unsigned char *asc, unsigned char *ascq) 266 unsigned char *asc, unsigned char *ascq)
265{ 267{
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index b8166ecfd0e3..5dec684bf010 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -727,7 +727,7 @@ qla1280_info(struct Scsi_Host *host)
727 * context which is a big NO! NO!. 727 * context which is a big NO! NO!.
728 **************************************************************************/ 728 **************************************************************************/
729static int 729static int
730qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *)) 730qla1280_queuecommand_lck(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
731{ 731{
732 struct Scsi_Host *host = cmd->device->host; 732 struct Scsi_Host *host = cmd->device->host;
733 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata; 733 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
@@ -756,6 +756,8 @@ qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
756 return status; 756 return status;
757} 757}
758 758
759static DEF_SCSI_QCMD(qla1280_queuecommand)
760
759enum action { 761enum action {
760 ABORT_COMMAND, 762 ABORT_COMMAND,
761 DEVICE_RESET, 763 DEVICE_RESET,
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 2ff4342ae362..bc8194f74625 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -1538,6 +1538,10 @@ qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1538 if (!fcport) 1538 if (!fcport)
1539 return; 1539 return;
1540 1540
1541 /* Now that the rport has been deleted, set the fcport state to
1542 FCS_DEVICE_DEAD */
1543 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
1544
1541 /* 1545 /*
1542 * Transport has effectively 'deleted' the rport, clear 1546 * Transport has effectively 'deleted' the rport, clear
1543 * all local references. 1547 * all local references.
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index fdfbf83a6330..31a4121a2be1 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -1307,6 +1307,125 @@ qla24xx_iidma(struct fc_bsg_job *bsg_job)
1307} 1307}
1308 1308
1309static int 1309static int
1310qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, struct qla_hw_data *ha,
1311 uint8_t is_update)
1312{
1313 uint32_t start = 0;
1314 int valid = 0;
1315
1316 bsg_job->reply->reply_payload_rcv_len = 0;
1317
1318 if (unlikely(pci_channel_offline(ha->pdev)))
1319 return -EINVAL;
1320
1321 start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1322 if (start > ha->optrom_size)
1323 return -EINVAL;
1324
1325 if (ha->optrom_state != QLA_SWAITING)
1326 return -EBUSY;
1327
1328 ha->optrom_region_start = start;
1329
1330 if (is_update) {
1331 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1332 valid = 1;
1333 else if (start == (ha->flt_region_boot * 4) ||
1334 start == (ha->flt_region_fw * 4))
1335 valid = 1;
1336 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
1337 IS_QLA8XXX_TYPE(ha))
1338 valid = 1;
1339 if (!valid) {
1340 qla_printk(KERN_WARNING, ha,
1341 "Invalid start region 0x%x/0x%x.\n",
1342 start, bsg_job->request_payload.payload_len);
1343 return -EINVAL;
1344 }
1345
1346 ha->optrom_region_size = start +
1347 bsg_job->request_payload.payload_len > ha->optrom_size ?
1348 ha->optrom_size - start :
1349 bsg_job->request_payload.payload_len;
1350 ha->optrom_state = QLA_SWRITING;
1351 } else {
1352 ha->optrom_region_size = start +
1353 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1354 ha->optrom_size - start :
1355 bsg_job->reply_payload.payload_len;
1356 ha->optrom_state = QLA_SREADING;
1357 }
1358
1359 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1360 if (!ha->optrom_buffer) {
1361 qla_printk(KERN_WARNING, ha,
1362 "Read: Unable to allocate memory for optrom retrieval "
1363 "(%x).\n", ha->optrom_region_size);
1364
1365 ha->optrom_state = QLA_SWAITING;
1366 return -ENOMEM;
1367 }
1368
1369 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1370 return 0;
1371}
1372
1373static int
1374qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1375{
1376 struct Scsi_Host *host = bsg_job->shost;
1377 scsi_qla_host_t *vha = shost_priv(host);
1378 struct qla_hw_data *ha = vha->hw;
1379 int rval = 0;
1380
1381 rval = qla2x00_optrom_setup(bsg_job, ha, 0);
1382 if (rval)
1383 return rval;
1384
1385 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1386 ha->optrom_region_start, ha->optrom_region_size);
1387
1388 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1389 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1390 ha->optrom_region_size);
1391
1392 bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
1393 bsg_job->reply->result = DID_OK;
1394 vfree(ha->optrom_buffer);
1395 ha->optrom_buffer = NULL;
1396 ha->optrom_state = QLA_SWAITING;
1397 bsg_job->job_done(bsg_job);
1398 return rval;
1399}
1400
1401static int
1402qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1403{
1404 struct Scsi_Host *host = bsg_job->shost;
1405 scsi_qla_host_t *vha = shost_priv(host);
1406 struct qla_hw_data *ha = vha->hw;
1407 int rval = 0;
1408
1409 rval = qla2x00_optrom_setup(bsg_job, ha, 1);
1410 if (rval)
1411 return rval;
1412
1413 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1414 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1415 ha->optrom_region_size);
1416
1417 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1418 ha->optrom_region_start, ha->optrom_region_size);
1419
1420 bsg_job->reply->result = DID_OK;
1421 vfree(ha->optrom_buffer);
1422 ha->optrom_buffer = NULL;
1423 ha->optrom_state = QLA_SWAITING;
1424 bsg_job->job_done(bsg_job);
1425 return rval;
1426}
1427
1428static int
1310qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job) 1429qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
1311{ 1430{
1312 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) { 1431 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
@@ -1328,6 +1447,12 @@ qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
1328 case QL_VND_FCP_PRIO_CFG_CMD: 1447 case QL_VND_FCP_PRIO_CFG_CMD:
1329 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job); 1448 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
1330 1449
1450 case QL_VND_READ_FLASH:
1451 return qla2x00_read_optrom(bsg_job);
1452
1453 case QL_VND_UPDATE_FLASH:
1454 return qla2x00_update_optrom(bsg_job);
1455
1331 default: 1456 default:
1332 bsg_job->reply->result = (DID_ERROR << 16); 1457 bsg_job->reply->result = (DID_ERROR << 16);
1333 bsg_job->job_done(bsg_job); 1458 bsg_job->job_done(bsg_job);
diff --git a/drivers/scsi/qla2xxx/qla_bsg.h b/drivers/scsi/qla2xxx/qla_bsg.h
index cc7c52f87a11..074a999c7017 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.h
+++ b/drivers/scsi/qla2xxx/qla_bsg.h
@@ -14,6 +14,8 @@
14#define QL_VND_A84_MGMT_CMD 0x04 14#define QL_VND_A84_MGMT_CMD 0x04
15#define QL_VND_IIDMA 0x05 15#define QL_VND_IIDMA 0x05
16#define QL_VND_FCP_PRIO_CFG_CMD 0x06 16#define QL_VND_FCP_PRIO_CFG_CMD 0x06
17#define QL_VND_READ_FLASH 0x07
18#define QL_VND_UPDATE_FLASH 0x08
17 19
18/* BSG definations for interpreting CommandSent field */ 20/* BSG definations for interpreting CommandSent field */
19#define INT_DEF_LB_LOOPBACK_CMD 0 21#define INT_DEF_LB_LOOPBACK_CMD 0
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index e1d3ad40a946..9ce539d4557e 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -1700,9 +1700,7 @@ typedef struct fc_port {
1700 atomic_t state; 1700 atomic_t state;
1701 uint32_t flags; 1701 uint32_t flags;
1702 1702
1703 int port_login_retry_count;
1704 int login_retry; 1703 int login_retry;
1705 atomic_t port_down_timer;
1706 1704
1707 struct fc_rport *rport, *drport; 1705 struct fc_rport *rport, *drport;
1708 u32 supported_classes; 1706 u32 supported_classes;
@@ -2411,7 +2409,6 @@ struct qla_hw_data {
2411 uint32_t enable_target_reset :1; 2409 uint32_t enable_target_reset :1;
2412 uint32_t enable_lip_full_login :1; 2410 uint32_t enable_lip_full_login :1;
2413 uint32_t enable_led_scheme :1; 2411 uint32_t enable_led_scheme :1;
2414 uint32_t inta_enabled :1;
2415 uint32_t msi_enabled :1; 2412 uint32_t msi_enabled :1;
2416 uint32_t msix_enabled :1; 2413 uint32_t msix_enabled :1;
2417 uint32_t disable_serdes :1; 2414 uint32_t disable_serdes :1;
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index c33dec827e1e..9382a816c133 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -92,6 +92,7 @@ extern int ql2xshiftctondsd;
92extern int ql2xdbwr; 92extern int ql2xdbwr;
93extern int ql2xdontresethba; 93extern int ql2xdontresethba;
94extern int ql2xasynctmfenable; 94extern int ql2xasynctmfenable;
95extern int ql2xgffidenable;
95extern int ql2xenabledif; 96extern int ql2xenabledif;
96extern int ql2xenablehba_err_chk; 97extern int ql2xenablehba_err_chk;
97extern int ql2xtargetreset; 98extern int ql2xtargetreset;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 3cafbef40737..259f51137493 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -71,7 +71,7 @@ qla2x00_ctx_sp_free(srb_t *sp)
71 struct srb_iocb *iocb = ctx->u.iocb_cmd; 71 struct srb_iocb *iocb = ctx->u.iocb_cmd;
72 struct scsi_qla_host *vha = sp->fcport->vha; 72 struct scsi_qla_host *vha = sp->fcport->vha;
73 73
74 del_timer_sync(&iocb->timer); 74 del_timer(&iocb->timer);
75 kfree(iocb); 75 kfree(iocb);
76 kfree(ctx); 76 kfree(ctx);
77 mempool_free(sp, sp->fcport->vha->hw->srb_mempool); 77 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
@@ -1344,6 +1344,13 @@ cont_alloc:
1344 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for " 1344 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
1345 "firmware dump!!!\n", dump_size / 1024); 1345 "firmware dump!!!\n", dump_size / 1024);
1346 1346
1347 if (ha->fce) {
1348 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1349 ha->fce_dma);
1350 ha->fce = NULL;
1351 ha->fce_dma = 0;
1352 }
1353
1347 if (ha->eft) { 1354 if (ha->eft) {
1348 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, 1355 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1349 ha->eft_dma); 1356 ha->eft_dma);
@@ -1818,14 +1825,14 @@ qla2x00_init_rings(scsi_qla_host_t *vha)
1818 qla2x00_init_response_q_entries(rsp); 1825 qla2x00_init_response_q_entries(rsp);
1819 } 1826 }
1820 1827
1821 spin_lock_irqsave(&ha->vport_slock, flags); 1828 spin_lock(&ha->vport_slock);
1822 /* Clear RSCN queue. */ 1829 /* Clear RSCN queue. */
1823 list_for_each_entry(vp, &ha->vp_list, list) { 1830 list_for_each_entry(vp, &ha->vp_list, list) {
1824 vp->rscn_in_ptr = 0; 1831 vp->rscn_in_ptr = 0;
1825 vp->rscn_out_ptr = 0; 1832 vp->rscn_out_ptr = 0;
1826 } 1833 }
1827 1834
1828 spin_unlock_irqrestore(&ha->vport_slock, flags); 1835 spin_unlock(&ha->vport_slock);
1829 1836
1830 ha->isp_ops->config_rings(vha); 1837 ha->isp_ops->config_rings(vha);
1831 1838
@@ -2916,21 +2923,13 @@ qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2916void 2923void
2917qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) 2924qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2918{ 2925{
2919 struct qla_hw_data *ha = vha->hw;
2920
2921 fcport->vha = vha; 2926 fcport->vha = vha;
2922 fcport->login_retry = 0; 2927 fcport->login_retry = 0;
2923 fcport->port_login_retry_count = ha->port_down_retry_count *
2924 PORT_RETRY_TIME;
2925 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2926 PORT_RETRY_TIME);
2927 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); 2928 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
2928 2929
2929 qla2x00_iidma_fcport(vha, fcport); 2930 qla2x00_iidma_fcport(vha, fcport);
2930
2931 atomic_set(&fcport->state, FCS_ONLINE);
2932
2933 qla2x00_reg_remote_port(vha, fcport); 2931 qla2x00_reg_remote_port(vha, fcport);
2932 atomic_set(&fcport->state, FCS_ONLINE);
2934} 2933}
2935 2934
2936/* 2935/*
@@ -3292,8 +3291,9 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3292 continue; 3291 continue;
3293 3292
3294 /* Bypass ports whose FCP-4 type is not FCP_SCSI */ 3293 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3295 if (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && 3294 if (ql2xgffidenable &&
3296 new_fcport->fc4_type != FC4_TYPE_UNKNOWN) 3295 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3296 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
3297 continue; 3297 continue;
3298 3298
3299 /* Locate matching device in database. */ 3299 /* Locate matching device in database. */
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index 579f02854665..4c1ba6263eb3 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -992,8 +992,8 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
992 ha = vha->hw; 992 ha = vha->hw;
993 993
994 DEBUG18(printk(KERN_DEBUG 994 DEBUG18(printk(KERN_DEBUG
995 "%s(%ld): Executing cmd sp %p, pid=%ld, prot_op=%u.\n", __func__, 995 "%s(%ld): Executing cmd sp %p, prot_op=%u.\n", __func__,
996 vha->host_no, sp, cmd->serial_number, scsi_get_prot_op(sp->cmd))); 996 vha->host_no, sp, scsi_get_prot_op(sp->cmd)));
997 997
998 cmd_pkt->vp_index = sp->fcport->vp_idx; 998 cmd_pkt->vp_index = sp->fcport->vp_idx;
999 999
@@ -1061,6 +1061,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
1061 fcp_cmnd->additional_cdb_len |= 2; 1061 fcp_cmnd->additional_cdb_len |= 2;
1062 1062
1063 int_to_scsilun(sp->cmd->device->lun, &fcp_cmnd->lun); 1063 int_to_scsilun(sp->cmd->device->lun, &fcp_cmnd->lun);
1064 host_to_fcp_swap((uint8_t *)&fcp_cmnd->lun, sizeof(fcp_cmnd->lun));
1064 memcpy(fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len); 1065 memcpy(fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len);
1065 cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(fcp_cmnd_len); 1066 cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(fcp_cmnd_len);
1066 cmd_pkt->fcp_cmnd_dseg_address[0] = cpu_to_le32( 1067 cmd_pkt->fcp_cmnd_dseg_address[0] = cpu_to_le32(
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index e0e43d9e7ed1..7f77898486a9 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1240,12 +1240,6 @@ qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
1240 case LSC_SCODE_NPORT_USED: 1240 case LSC_SCODE_NPORT_USED:
1241 data[0] = MBS_LOOP_ID_USED; 1241 data[0] = MBS_LOOP_ID_USED;
1242 break; 1242 break;
1243 case LSC_SCODE_CMD_FAILED:
1244 if ((iop[1] & 0xff) == 0x05) {
1245 data[0] = MBS_NOT_LOGGED_IN;
1246 break;
1247 }
1248 /* Fall through. */
1249 default: 1243 default:
1250 data[0] = MBS_COMMAND_ERROR; 1244 data[0] = MBS_COMMAND_ERROR;
1251 break; 1245 break;
@@ -1431,9 +1425,8 @@ qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t par_sense_len,
1431 rsp->status_srb = sp; 1425 rsp->status_srb = sp;
1432 1426
1433 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) " 1427 DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
1434 "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no, 1428 "cmd=%p\n", __func__, sp->fcport->vha->host_no,
1435 cp->device->channel, cp->device->id, cp->device->lun, cp, 1429 cp->device->channel, cp->device->id, cp->device->lun, cp));
1436 cp->serial_number));
1437 if (sense_len) 1430 if (sense_len)
1438 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len)); 1431 DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
1439} 1432}
@@ -1757,6 +1750,8 @@ check_scsi_status:
1757 case CS_INCOMPLETE: 1750 case CS_INCOMPLETE:
1758 case CS_PORT_UNAVAILABLE: 1751 case CS_PORT_UNAVAILABLE:
1759 case CS_TIMEOUT: 1752 case CS_TIMEOUT:
1753 case CS_RESET:
1754
1760 /* 1755 /*
1761 * We are going to have the fc class block the rport 1756 * We are going to have the fc class block the rport
1762 * while we try to recover so instruct the mid layer 1757 * while we try to recover so instruct the mid layer
@@ -1781,10 +1776,6 @@ check_scsi_status:
1781 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1); 1776 qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
1782 break; 1777 break;
1783 1778
1784 case CS_RESET:
1785 cp->result = DID_TRANSPORT_DISRUPTED << 16;
1786 break;
1787
1788 case CS_ABORTED: 1779 case CS_ABORTED:
1789 cp->result = DID_RESET << 16; 1780 cp->result = DID_RESET << 16;
1790 break; 1781 break;
@@ -1801,10 +1792,10 @@ out:
1801 if (logit) 1792 if (logit)
1802 DEBUG2(qla_printk(KERN_INFO, ha, 1793 DEBUG2(qla_printk(KERN_INFO, ha,
1803 "scsi(%ld:%d:%d) FCP command status: 0x%x-0x%x (0x%x) " 1794 "scsi(%ld:%d:%d) FCP command status: 0x%x-0x%x (0x%x) "
1804 "oxid=0x%x ser=0x%lx cdb=%02x%02x%02x len=0x%x " 1795 "oxid=0x%x cdb=%02x%02x%02x len=0x%x "
1805 "rsp_info=0x%x resid=0x%x fw_resid=0x%x\n", vha->host_no, 1796 "rsp_info=0x%x resid=0x%x fw_resid=0x%x\n", vha->host_no,
1806 cp->device->id, cp->device->lun, comp_status, scsi_status, 1797 cp->device->id, cp->device->lun, comp_status, scsi_status,
1807 cp->result, ox_id, cp->serial_number, cp->cmnd[0], 1798 cp->result, ox_id, cp->cmnd[0],
1808 cp->cmnd[1], cp->cmnd[2], scsi_bufflen(cp), rsp_info_len, 1799 cp->cmnd[1], cp->cmnd[2], scsi_bufflen(cp), rsp_info_len,
1809 resid_len, fw_resid_len)); 1800 resid_len, fw_resid_len));
1810 1801
@@ -2500,14 +2491,15 @@ skip_msix:
2500skip_msi: 2491skip_msi:
2501 2492
2502 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler, 2493 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
2503 IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp); 2494 ha->flags.msi_enabled ? 0 : IRQF_SHARED,
2495 QLA2XXX_DRIVER_NAME, rsp);
2504 if (ret) { 2496 if (ret) {
2505 qla_printk(KERN_WARNING, ha, 2497 qla_printk(KERN_WARNING, ha,
2506 "Failed to reserve interrupt %d already in use.\n", 2498 "Failed to reserve interrupt %d already in use.\n",
2507 ha->pdev->irq); 2499 ha->pdev->irq);
2508 goto fail; 2500 goto fail;
2509 } 2501 }
2510 ha->flags.inta_enabled = 1; 2502
2511clear_risc_ints: 2503clear_risc_ints:
2512 2504
2513 /* 2505 /*
diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index 8d9edfb39803..ae2acacc0003 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -2749,6 +2749,7 @@ sufficient_dsds:
2749 goto queuing_error_fcp_cmnd; 2749 goto queuing_error_fcp_cmnd;
2750 2750
2751 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun); 2751 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
2752 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
2752 2753
2753 /* build FCP_CMND IU */ 2754 /* build FCP_CMND IU */
2754 memset(ctx->fcp_cmnd, 0, sizeof(struct fcp_cmnd)); 2755 memset(ctx->fcp_cmnd, 0, sizeof(struct fcp_cmnd));
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 800ea9269752..2c0876c81a3f 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -160,6 +160,11 @@ MODULE_PARM_DESC(ql2xtargetreset,
160 "Enable target reset." 160 "Enable target reset."
161 "Default is 1 - use hw defaults."); 161 "Default is 1 - use hw defaults.");
162 162
163int ql2xgffidenable;
164module_param(ql2xgffidenable, int, S_IRUGO|S_IRUSR);
165MODULE_PARM_DESC(ql2xgffidenable,
166 "Enables GFF_ID checks of port type. "
167 "Default is 0 - Do not use GFF_ID information.");
163 168
164int ql2xasynctmfenable; 169int ql2xasynctmfenable;
165module_param(ql2xasynctmfenable, int, S_IRUGO|S_IRUSR); 170module_param(ql2xasynctmfenable, int, S_IRUGO|S_IRUSR);
@@ -174,8 +179,7 @@ static int qla2xxx_slave_alloc(struct scsi_device *);
174static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time); 179static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
175static void qla2xxx_scan_start(struct Scsi_Host *); 180static void qla2xxx_scan_start(struct Scsi_Host *);
176static void qla2xxx_slave_destroy(struct scsi_device *); 181static void qla2xxx_slave_destroy(struct scsi_device *);
177static int qla2xxx_queuecommand(struct scsi_cmnd *cmd, 182static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
178 void (*fn)(struct scsi_cmnd *));
179static int qla2xxx_eh_abort(struct scsi_cmnd *); 183static int qla2xxx_eh_abort(struct scsi_cmnd *);
180static int qla2xxx_eh_device_reset(struct scsi_cmnd *); 184static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
181static int qla2xxx_eh_target_reset(struct scsi_cmnd *); 185static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
@@ -255,6 +259,7 @@ static void qla2x00_rst_aen(scsi_qla_host_t *);
255 259
256static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t, 260static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
257 struct req_que **, struct rsp_que **); 261 struct req_que **, struct rsp_que **);
262static void qla2x00_free_fw_dump(struct qla_hw_data *);
258static void qla2x00_mem_free(struct qla_hw_data *); 263static void qla2x00_mem_free(struct qla_hw_data *);
259static void qla2x00_sp_free_dma(srb_t *); 264static void qla2x00_sp_free_dma(srb_t *);
260 265
@@ -529,7 +534,7 @@ qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
529} 534}
530 535
531static int 536static int
532qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 537qla2xxx_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
533{ 538{
534 scsi_qla_host_t *vha = shost_priv(cmd->device->host); 539 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
535 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 540 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
@@ -539,6 +544,7 @@ qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
539 srb_t *sp; 544 srb_t *sp;
540 int rval; 545 int rval;
541 546
547 spin_unlock_irq(vha->host->host_lock);
542 if (ha->flags.eeh_busy) { 548 if (ha->flags.eeh_busy) {
543 if (ha->flags.pci_channel_io_perm_failure) 549 if (ha->flags.pci_channel_io_perm_failure)
544 cmd->result = DID_NO_CONNECT << 16; 550 cmd->result = DID_NO_CONNECT << 16;
@@ -553,10 +559,6 @@ qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
553 goto qc24_fail_command; 559 goto qc24_fail_command;
554 } 560 }
555 561
556 /* Close window on fcport/rport state-transitioning. */
557 if (fcport->drport)
558 goto qc24_target_busy;
559
560 if (!vha->flags.difdix_supported && 562 if (!vha->flags.difdix_supported &&
561 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { 563 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
562 DEBUG2(qla_printk(KERN_ERR, ha, 564 DEBUG2(qla_printk(KERN_ERR, ha,
@@ -567,15 +569,14 @@ qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
567 } 569 }
568 if (atomic_read(&fcport->state) != FCS_ONLINE) { 570 if (atomic_read(&fcport->state) != FCS_ONLINE) {
569 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || 571 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
570 atomic_read(&base_vha->loop_state) == LOOP_DEAD) { 572 atomic_read(&fcport->state) == FCS_DEVICE_LOST ||
573 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
571 cmd->result = DID_NO_CONNECT << 16; 574 cmd->result = DID_NO_CONNECT << 16;
572 goto qc24_fail_command; 575 goto qc24_fail_command;
573 } 576 }
574 goto qc24_target_busy; 577 goto qc24_target_busy;
575 } 578 }
576 579
577 spin_unlock_irq(vha->host->host_lock);
578
579 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done); 580 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
580 if (!sp) 581 if (!sp)
581 goto qc24_host_busy_lock; 582 goto qc24_host_busy_lock;
@@ -597,14 +598,18 @@ qc24_host_busy_lock:
597 return SCSI_MLQUEUE_HOST_BUSY; 598 return SCSI_MLQUEUE_HOST_BUSY;
598 599
599qc24_target_busy: 600qc24_target_busy:
601 spin_lock_irq(vha->host->host_lock);
600 return SCSI_MLQUEUE_TARGET_BUSY; 602 return SCSI_MLQUEUE_TARGET_BUSY;
601 603
602qc24_fail_command: 604qc24_fail_command:
605 spin_lock_irq(vha->host->host_lock);
603 done(cmd); 606 done(cmd);
604 607
605 return 0; 608 return 0;
606} 609}
607 610
611static DEF_SCSI_QCMD(qla2xxx_queuecommand)
612
608 613
609/* 614/*
610 * qla2x00_eh_wait_on_command 615 * qla2x00_eh_wait_on_command
@@ -824,81 +829,58 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
824{ 829{
825 scsi_qla_host_t *vha = shost_priv(cmd->device->host); 830 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
826 srb_t *sp; 831 srb_t *sp;
827 int ret, i; 832 int ret = SUCCESS;
828 unsigned int id, lun; 833 unsigned int id, lun;
829 unsigned long serial;
830 unsigned long flags; 834 unsigned long flags;
831 int wait = 0; 835 int wait = 0;
832 struct qla_hw_data *ha = vha->hw; 836 struct qla_hw_data *ha = vha->hw;
833 struct req_que *req = vha->req;
834 srb_t *spt;
835 int got_ref = 0;
836 837
837 fc_block_scsi_eh(cmd); 838 fc_block_scsi_eh(cmd);
838 839
839 if (!CMD_SP(cmd)) 840 if (!CMD_SP(cmd))
840 return SUCCESS; 841 return SUCCESS;
841 842
842 ret = SUCCESS;
843
844 id = cmd->device->id; 843 id = cmd->device->id;
845 lun = cmd->device->lun; 844 lun = cmd->device->lun;
846 serial = cmd->serial_number;
847 spt = (srb_t *) CMD_SP(cmd);
848 if (!spt)
849 return SUCCESS;
850 845
851 /* Check active list for command command. */
852 spin_lock_irqsave(&ha->hardware_lock, flags); 846 spin_lock_irqsave(&ha->hardware_lock, flags);
853 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) { 847 sp = (srb_t *) CMD_SP(cmd);
854 sp = req->outstanding_cmds[i]; 848 if (!sp) {
855 849 spin_unlock_irqrestore(&ha->hardware_lock, flags);
856 if (sp == NULL) 850 return SUCCESS;
857 continue; 851 }
858 if ((sp->ctx) && !(sp->flags & SRB_FCP_CMND_DMA_VALID) &&
859 !IS_PROT_IO(sp))
860 continue;
861 if (sp->cmd != cmd)
862 continue;
863 852
864 DEBUG2(printk("%s(%ld): aborting sp %p from RISC." 853 DEBUG2(printk("%s(%ld): aborting sp %p from RISC.",
865 " pid=%ld.\n", __func__, vha->host_no, sp, serial)); 854 __func__, vha->host_no, sp));
866 855
867 /* Get a reference to the sp and drop the lock.*/ 856 /* Get a reference to the sp and drop the lock.*/
868 sp_get(sp); 857 sp_get(sp);
869 got_ref++;
870 858
871 spin_unlock_irqrestore(&ha->hardware_lock, flags);
872 if (ha->isp_ops->abort_command(sp)) {
873 DEBUG2(printk("%s(%ld): abort_command "
874 "mbx failed.\n", __func__, vha->host_no));
875 ret = FAILED;
876 } else {
877 DEBUG3(printk("%s(%ld): abort_command "
878 "mbx success.\n", __func__, vha->host_no));
879 wait = 1;
880 }
881 spin_lock_irqsave(&ha->hardware_lock, flags);
882 break;
883 }
884 spin_unlock_irqrestore(&ha->hardware_lock, flags); 859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
860 if (ha->isp_ops->abort_command(sp)) {
861 DEBUG2(printk("%s(%ld): abort_command "
862 "mbx failed.\n", __func__, vha->host_no));
863 ret = FAILED;
864 } else {
865 DEBUG3(printk("%s(%ld): abort_command "
866 "mbx success.\n", __func__, vha->host_no));
867 wait = 1;
868 }
869 qla2x00_sp_compl(ha, sp);
885 870
886 /* Wait for the command to be returned. */ 871 /* Wait for the command to be returned. */
887 if (wait) { 872 if (wait) {
888 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) { 873 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
889 qla_printk(KERN_ERR, ha, 874 qla_printk(KERN_ERR, ha,
890 "scsi(%ld:%d:%d): Abort handler timed out -- %lx " 875 "scsi(%ld:%d:%d): Abort handler timed out -- %x.\n",
891 "%x.\n", vha->host_no, id, lun, serial, ret); 876 vha->host_no, id, lun, ret);
892 ret = FAILED; 877 ret = FAILED;
893 } 878 }
894 } 879 }
895 880
896 if (got_ref)
897 qla2x00_sp_compl(ha, sp);
898
899 qla_printk(KERN_INFO, ha, 881 qla_printk(KERN_INFO, ha,
900 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n", 882 "scsi(%ld:%d:%d): Abort command issued -- %d %x.\n",
901 vha->host_no, id, lun, wait, serial, ret); 883 vha->host_no, id, lun, wait, ret);
902 884
903 return ret; 885 return ret;
904} 886}
@@ -1043,13 +1025,11 @@ qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1043 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 1025 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1044 int ret = FAILED; 1026 int ret = FAILED;
1045 unsigned int id, lun; 1027 unsigned int id, lun;
1046 unsigned long serial;
1047 1028
1048 fc_block_scsi_eh(cmd); 1029 fc_block_scsi_eh(cmd);
1049 1030
1050 id = cmd->device->id; 1031 id = cmd->device->id;
1051 lun = cmd->device->lun; 1032 lun = cmd->device->lun;
1052 serial = cmd->serial_number;
1053 1033
1054 if (!fcport) 1034 if (!fcport)
1055 return ret; 1035 return ret;
@@ -1104,14 +1084,12 @@ qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1104 struct qla_hw_data *ha = vha->hw; 1084 struct qla_hw_data *ha = vha->hw;
1105 int ret = FAILED; 1085 int ret = FAILED;
1106 unsigned int id, lun; 1086 unsigned int id, lun;
1107 unsigned long serial;
1108 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); 1087 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1109 1088
1110 fc_block_scsi_eh(cmd); 1089 fc_block_scsi_eh(cmd);
1111 1090
1112 id = cmd->device->id; 1091 id = cmd->device->id;
1113 lun = cmd->device->lun; 1092 lun = cmd->device->lun;
1114 serial = cmd->serial_number;
1115 1093
1116 if (!fcport) 1094 if (!fcport)
1117 return ret; 1095 return ret;
@@ -1974,6 +1952,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1974 ha->bars = bars; 1952 ha->bars = bars;
1975 ha->mem_only = mem_only; 1953 ha->mem_only = mem_only;
1976 spin_lock_init(&ha->hardware_lock); 1954 spin_lock_init(&ha->hardware_lock);
1955 spin_lock_init(&ha->vport_slock);
1977 1956
1978 /* Set ISP-type information. */ 1957 /* Set ISP-type information. */
1979 qla2x00_set_isp_flags(ha); 1958 qla2x00_set_isp_flags(ha);
@@ -2085,6 +2064,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2085 ha->init_cb_size = sizeof(struct mid_init_cb_81xx); 2064 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2086 ha->gid_list_info_size = 8; 2065 ha->gid_list_info_size = 8;
2087 ha->optrom_size = OPTROM_SIZE_82XX; 2066 ha->optrom_size = OPTROM_SIZE_82XX;
2067 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2088 ha->isp_ops = &qla82xx_isp_ops; 2068 ha->isp_ops = &qla82xx_isp_ops;
2089 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; 2069 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2090 ha->flash_data_off = FARX_ACCESS_FLASH_DATA; 2070 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
@@ -2342,6 +2322,42 @@ probe_out:
2342} 2322}
2343 2323
2344static void 2324static void
2325qla2x00_shutdown(struct pci_dev *pdev)
2326{
2327 scsi_qla_host_t *vha;
2328 struct qla_hw_data *ha;
2329
2330 vha = pci_get_drvdata(pdev);
2331 ha = vha->hw;
2332
2333 /* Turn-off FCE trace */
2334 if (ha->flags.fce_enabled) {
2335 qla2x00_disable_fce_trace(vha, NULL, NULL);
2336 ha->flags.fce_enabled = 0;
2337 }
2338
2339 /* Turn-off EFT trace */
2340 if (ha->eft)
2341 qla2x00_disable_eft_trace(vha);
2342
2343 /* Stop currently executing firmware. */
2344 qla2x00_try_to_stop_firmware(vha);
2345
2346 /* Turn adapter off line */
2347 vha->flags.online = 0;
2348
2349 /* turn-off interrupts on the card */
2350 if (ha->interrupts_on) {
2351 vha->flags.init_done = 0;
2352 ha->isp_ops->disable_intrs(ha);
2353 }
2354
2355 qla2x00_free_irqs(vha);
2356
2357 qla2x00_free_fw_dump(ha);
2358}
2359
2360static void
2345qla2x00_remove_one(struct pci_dev *pdev) 2361qla2x00_remove_one(struct pci_dev *pdev)
2346{ 2362{
2347 scsi_qla_host_t *base_vha, *vha; 2363 scsi_qla_host_t *base_vha, *vha;
@@ -2597,12 +2613,12 @@ qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2597 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) 2613 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2598 continue; 2614 continue;
2599 if (atomic_read(&fcport->state) == FCS_ONLINE) { 2615 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2616 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2600 if (defer) 2617 if (defer)
2601 qla2x00_schedule_rport_del(vha, fcport, defer); 2618 qla2x00_schedule_rport_del(vha, fcport, defer);
2602 else if (vha->vp_idx == fcport->vp_idx) 2619 else if (vha->vp_idx == fcport->vp_idx)
2603 qla2x00_schedule_rport_del(vha, fcport, defer); 2620 qla2x00_schedule_rport_del(vha, fcport, defer);
2604 } 2621 }
2605 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2606 } 2622 }
2607} 2623}
2608 2624
@@ -2830,28 +2846,48 @@ fail:
2830} 2846}
2831 2847
2832/* 2848/*
2833* qla2x00_mem_free 2849* qla2x00_free_fw_dump
2834* Frees all adapter allocated memory. 2850* Frees fw dump stuff.
2835* 2851*
2836* Input: 2852* Input:
2837* ha = adapter block pointer. 2853* ha = adapter block pointer.
2838*/ 2854*/
2839static void 2855static void
2840qla2x00_mem_free(struct qla_hw_data *ha) 2856qla2x00_free_fw_dump(struct qla_hw_data *ha)
2841{ 2857{
2842 if (ha->srb_mempool)
2843 mempool_destroy(ha->srb_mempool);
2844
2845 if (ha->fce) 2858 if (ha->fce)
2846 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, 2859 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2847 ha->fce_dma); 2860 ha->fce_dma);
2848 2861
2849 if (ha->fw_dump) { 2862 if (ha->fw_dump) {
2850 if (ha->eft) 2863 if (ha->eft)
2851 dma_free_coherent(&ha->pdev->dev, 2864 dma_free_coherent(&ha->pdev->dev,
2852 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma); 2865 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2853 vfree(ha->fw_dump); 2866 vfree(ha->fw_dump);
2854 } 2867 }
2868 ha->fce = NULL;
2869 ha->fce_dma = 0;
2870 ha->eft = NULL;
2871 ha->eft_dma = 0;
2872 ha->fw_dump = NULL;
2873 ha->fw_dumped = 0;
2874 ha->fw_dump_reading = 0;
2875}
2876
2877/*
2878* qla2x00_mem_free
2879* Frees all adapter allocated memory.
2880*
2881* Input:
2882* ha = adapter block pointer.
2883*/
2884static void
2885qla2x00_mem_free(struct qla_hw_data *ha)
2886{
2887 qla2x00_free_fw_dump(ha);
2888
2889 if (ha->srb_mempool)
2890 mempool_destroy(ha->srb_mempool);
2855 2891
2856 if (ha->dcbx_tlv) 2892 if (ha->dcbx_tlv)
2857 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE, 2893 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
@@ -2925,8 +2961,6 @@ qla2x00_mem_free(struct qla_hw_data *ha)
2925 2961
2926 ha->srb_mempool = NULL; 2962 ha->srb_mempool = NULL;
2927 ha->ctx_mempool = NULL; 2963 ha->ctx_mempool = NULL;
2928 ha->eft = NULL;
2929 ha->eft_dma = 0;
2930 ha->sns_cmd = NULL; 2964 ha->sns_cmd = NULL;
2931 ha->sns_cmd_dma = 0; 2965 ha->sns_cmd_dma = 0;
2932 ha->ct_sns = NULL; 2966 ha->ct_sns = NULL;
@@ -2946,10 +2980,6 @@ qla2x00_mem_free(struct qla_hw_data *ha)
2946 2980
2947 ha->gid_list = NULL; 2981 ha->gid_list = NULL;
2948 ha->gid_list_dma = 0; 2982 ha->gid_list_dma = 0;
2949
2950 ha->fw_dump = NULL;
2951 ha->fw_dumped = 0;
2952 ha->fw_dump_reading = 0;
2953} 2983}
2954 2984
2955struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, 2985struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
@@ -3547,11 +3577,9 @@ void
3547qla2x00_timer(scsi_qla_host_t *vha) 3577qla2x00_timer(scsi_qla_host_t *vha)
3548{ 3578{
3549 unsigned long cpu_flags = 0; 3579 unsigned long cpu_flags = 0;
3550 fc_port_t *fcport;
3551 int start_dpc = 0; 3580 int start_dpc = 0;
3552 int index; 3581 int index;
3553 srb_t *sp; 3582 srb_t *sp;
3554 int t;
3555 uint16_t w; 3583 uint16_t w;
3556 struct qla_hw_data *ha = vha->hw; 3584 struct qla_hw_data *ha = vha->hw;
3557 struct req_que *req; 3585 struct req_que *req;
@@ -3567,34 +3595,6 @@ qla2x00_timer(scsi_qla_host_t *vha)
3567 /* Hardware read to raise pending EEH errors during mailbox waits. */ 3595 /* Hardware read to raise pending EEH errors during mailbox waits. */
3568 if (!pci_channel_offline(ha->pdev)) 3596 if (!pci_channel_offline(ha->pdev))
3569 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); 3597 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
3570 /*
3571 * Ports - Port down timer.
3572 *
3573 * Whenever, a port is in the LOST state we start decrementing its port
3574 * down timer every second until it reaches zero. Once it reaches zero
3575 * the port it marked DEAD.
3576 */
3577 t = 0;
3578 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3579 if (fcport->port_type != FCT_TARGET)
3580 continue;
3581
3582 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3583
3584 if (atomic_read(&fcport->port_down_timer) == 0)
3585 continue;
3586
3587 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3588 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3589
3590 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3591 "%d remaining\n",
3592 vha->host_no,
3593 t, atomic_read(&fcport->port_down_timer)));
3594 }
3595 t++;
3596 } /* End of for fcport */
3597
3598 3598
3599 /* Loop down handler. */ 3599 /* Loop down handler. */
3600 if (atomic_read(&vha->loop_down_timer) > 0 && 3600 if (atomic_read(&vha->loop_down_timer) > 0 &&
@@ -4079,6 +4079,7 @@ static struct pci_driver qla2xxx_pci_driver = {
4079 .id_table = qla2xxx_pci_tbl, 4079 .id_table = qla2xxx_pci_tbl,
4080 .probe = qla2x00_probe_one, 4080 .probe = qla2x00_probe_one,
4081 .remove = qla2x00_remove_one, 4081 .remove = qla2x00_remove_one,
4082 .shutdown = qla2x00_shutdown,
4082 .err_handler = &qla2xxx_err_handler, 4083 .err_handler = &qla2xxx_err_handler,
4083}; 4084};
4084 4085
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index 8edbccb3232d..cf0075a2d0c2 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,9 +7,9 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.03.04-k0" 10#define QLA2XXX_VERSION "8.03.05-k0"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 3 13#define QLA_DRIVER_MINOR_VER 3
14#define QLA_DRIVER_PATCH_VER 4 14#define QLA_DRIVER_PATCH_VER 5
15#define QLA_DRIVER_BETA_VER 0 15#define QLA_DRIVER_BETA_VER 0
diff --git a/drivers/scsi/qla4xxx/ql4_dbg.c b/drivers/scsi/qla4xxx/ql4_dbg.c
index cbceb0ebabf7..edcf048215dd 100644
--- a/drivers/scsi/qla4xxx/ql4_dbg.c
+++ b/drivers/scsi/qla4xxx/ql4_dbg.c
@@ -30,3 +30,104 @@ void qla4xxx_dump_buffer(void *b, uint32_t size)
30 printk(KERN_INFO "\n"); 30 printk(KERN_INFO "\n");
31} 31}
32 32
33void qla4xxx_dump_registers(struct scsi_qla_host *ha)
34{
35 uint8_t i;
36
37 if (is_qla8022(ha)) {
38 for (i = 1; i < MBOX_REG_COUNT; i++)
39 printk(KERN_INFO "mailbox[%d] = 0x%08X\n",
40 i, readl(&ha->qla4_8xxx_reg->mailbox_in[i]));
41 return;
42 }
43
44 for (i = 0; i < MBOX_REG_COUNT; i++) {
45 printk(KERN_INFO "0x%02X mailbox[%d] = 0x%08X\n",
46 (uint8_t) offsetof(struct isp_reg, mailbox[i]), i,
47 readw(&ha->reg->mailbox[i]));
48 }
49
50 printk(KERN_INFO "0x%02X flash_address = 0x%08X\n",
51 (uint8_t) offsetof(struct isp_reg, flash_address),
52 readw(&ha->reg->flash_address));
53 printk(KERN_INFO "0x%02X flash_data = 0x%08X\n",
54 (uint8_t) offsetof(struct isp_reg, flash_data),
55 readw(&ha->reg->flash_data));
56 printk(KERN_INFO "0x%02X ctrl_status = 0x%08X\n",
57 (uint8_t) offsetof(struct isp_reg, ctrl_status),
58 readw(&ha->reg->ctrl_status));
59
60 if (is_qla4010(ha)) {
61 printk(KERN_INFO "0x%02X nvram = 0x%08X\n",
62 (uint8_t) offsetof(struct isp_reg, u1.isp4010.nvram),
63 readw(&ha->reg->u1.isp4010.nvram));
64 } else if (is_qla4022(ha) | is_qla4032(ha)) {
65 printk(KERN_INFO "0x%02X intr_mask = 0x%08X\n",
66 (uint8_t) offsetof(struct isp_reg, u1.isp4022.intr_mask),
67 readw(&ha->reg->u1.isp4022.intr_mask));
68 printk(KERN_INFO "0x%02X nvram = 0x%08X\n",
69 (uint8_t) offsetof(struct isp_reg, u1.isp4022.nvram),
70 readw(&ha->reg->u1.isp4022.nvram));
71 printk(KERN_INFO "0x%02X semaphore = 0x%08X\n",
72 (uint8_t) offsetof(struct isp_reg, u1.isp4022.semaphore),
73 readw(&ha->reg->u1.isp4022.semaphore));
74 }
75 printk(KERN_INFO "0x%02X req_q_in = 0x%08X\n",
76 (uint8_t) offsetof(struct isp_reg, req_q_in),
77 readw(&ha->reg->req_q_in));
78 printk(KERN_INFO "0x%02X rsp_q_out = 0x%08X\n",
79 (uint8_t) offsetof(struct isp_reg, rsp_q_out),
80 readw(&ha->reg->rsp_q_out));
81
82 if (is_qla4010(ha)) {
83 printk(KERN_INFO "0x%02X ext_hw_conf = 0x%08X\n",
84 (uint8_t) offsetof(struct isp_reg, u2.isp4010.ext_hw_conf),
85 readw(&ha->reg->u2.isp4010.ext_hw_conf));
86 printk(KERN_INFO "0x%02X port_ctrl = 0x%08X\n",
87 (uint8_t) offsetof(struct isp_reg, u2.isp4010.port_ctrl),
88 readw(&ha->reg->u2.isp4010.port_ctrl));
89 printk(KERN_INFO "0x%02X port_status = 0x%08X\n",
90 (uint8_t) offsetof(struct isp_reg, u2.isp4010.port_status),
91 readw(&ha->reg->u2.isp4010.port_status));
92 printk(KERN_INFO "0x%02X req_q_out = 0x%08X\n",
93 (uint8_t) offsetof(struct isp_reg, u2.isp4010.req_q_out),
94 readw(&ha->reg->u2.isp4010.req_q_out));
95 printk(KERN_INFO "0x%02X gp_out = 0x%08X\n",
96 (uint8_t) offsetof(struct isp_reg, u2.isp4010.gp_out),
97 readw(&ha->reg->u2.isp4010.gp_out));
98 printk(KERN_INFO "0x%02X gp_in = 0x%08X\n",
99 (uint8_t) offsetof(struct isp_reg, u2.isp4010.gp_in),
100 readw(&ha->reg->u2.isp4010.gp_in));
101 printk(KERN_INFO "0x%02X port_err_status = 0x%08X\n", (uint8_t)
102 offsetof(struct isp_reg, u2.isp4010.port_err_status),
103 readw(&ha->reg->u2.isp4010.port_err_status));
104 } else if (is_qla4022(ha) | is_qla4032(ha)) {
105 printk(KERN_INFO "Page 0 Registers:\n");
106 printk(KERN_INFO "0x%02X ext_hw_conf = 0x%08X\n", (uint8_t)
107 offsetof(struct isp_reg, u2.isp4022.p0.ext_hw_conf),
108 readw(&ha->reg->u2.isp4022.p0.ext_hw_conf));
109 printk(KERN_INFO "0x%02X port_ctrl = 0x%08X\n", (uint8_t)
110 offsetof(struct isp_reg, u2.isp4022.p0.port_ctrl),
111 readw(&ha->reg->u2.isp4022.p0.port_ctrl));
112 printk(KERN_INFO "0x%02X port_status = 0x%08X\n", (uint8_t)
113 offsetof(struct isp_reg, u2.isp4022.p0.port_status),
114 readw(&ha->reg->u2.isp4022.p0.port_status));
115 printk(KERN_INFO "0x%02X gp_out = 0x%08X\n",
116 (uint8_t) offsetof(struct isp_reg, u2.isp4022.p0.gp_out),
117 readw(&ha->reg->u2.isp4022.p0.gp_out));
118 printk(KERN_INFO "0x%02X gp_in = 0x%08X\n",
119 (uint8_t) offsetof(struct isp_reg, u2.isp4022.p0.gp_in),
120 readw(&ha->reg->u2.isp4022.p0.gp_in));
121 printk(KERN_INFO "0x%02X port_err_status = 0x%08X\n", (uint8_t)
122 offsetof(struct isp_reg, u2.isp4022.p0.port_err_status),
123 readw(&ha->reg->u2.isp4022.p0.port_err_status));
124 printk(KERN_INFO "Page 1 Registers:\n");
125 writel(HOST_MEM_CFG_PAGE & set_rmask(CSR_SCSI_PAGE_SELECT),
126 &ha->reg->ctrl_status);
127 printk(KERN_INFO "0x%02X req_q_out = 0x%08X\n",
128 (uint8_t) offsetof(struct isp_reg, u2.isp4022.p1.req_q_out),
129 readw(&ha->reg->u2.isp4022.p1.req_q_out));
130 writel(PORT_CTRL_STAT_PAGE & set_rmask(CSR_SCSI_PAGE_SELECT),
131 &ha->reg->ctrl_status);
132 }
133}
diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
index 9dc0a6616edd..0f3bfc3da5cf 100644
--- a/drivers/scsi/qla4xxx/ql4_def.h
+++ b/drivers/scsi/qla4xxx/ql4_def.h
@@ -24,6 +24,7 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/aer.h>
27 28
28#include <net/tcp.h> 29#include <net/tcp.h>
29#include <scsi/scsi.h> 30#include <scsi/scsi.h>
@@ -36,24 +37,6 @@
36#include "ql4_dbg.h" 37#include "ql4_dbg.h"
37#include "ql4_nx.h" 38#include "ql4_nx.h"
38 39
39#if defined(CONFIG_PCIEAER)
40#include <linux/aer.h>
41#else
42/* AER releated */
43static inline int pci_enable_pcie_error_reporting(struct pci_dev *dev)
44{
45 return -EINVAL;
46}
47static inline int pci_disable_pcie_error_reporting(struct pci_dev *dev)
48{
49 return -EINVAL;
50}
51static inline int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
52{
53 return -EINVAL;
54}
55#endif
56
57#ifndef PCI_DEVICE_ID_QLOGIC_ISP4010 40#ifndef PCI_DEVICE_ID_QLOGIC_ISP4010
58#define PCI_DEVICE_ID_QLOGIC_ISP4010 0x4010 41#define PCI_DEVICE_ID_QLOGIC_ISP4010 0x4010
59#endif 42#endif
@@ -179,6 +162,7 @@ static inline int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
179#define IOCB_TOV_MARGIN 10 162#define IOCB_TOV_MARGIN 10
180#define RELOGIN_TOV 18 163#define RELOGIN_TOV 18
181#define ISNS_DEREG_TOV 5 164#define ISNS_DEREG_TOV 5
165#define HBA_ONLINE_TOV 30
182 166
183#define MAX_RESET_HA_RETRIES 2 167#define MAX_RESET_HA_RETRIES 2
184 168
diff --git a/drivers/scsi/qla4xxx/ql4_fw.h b/drivers/scsi/qla4xxx/ql4_fw.h
index 0336c6db8cb3..5e757d7fff7d 100644
--- a/drivers/scsi/qla4xxx/ql4_fw.h
+++ b/drivers/scsi/qla4xxx/ql4_fw.h
@@ -416,6 +416,8 @@ struct qla_flt_region {
416#define MBOX_ASTS_IPV6_ND_PREFIX_IGNORED 0x802C 416#define MBOX_ASTS_IPV6_ND_PREFIX_IGNORED 0x802C
417#define MBOX_ASTS_IPV6_LCL_PREFIX_IGNORED 0x802D 417#define MBOX_ASTS_IPV6_LCL_PREFIX_IGNORED 0x802D
418#define MBOX_ASTS_ICMPV6_ERROR_MSG_RCVD 0x802E 418#define MBOX_ASTS_ICMPV6_ERROR_MSG_RCVD 0x802E
419#define MBOX_ASTS_TXSCVR_INSERTED 0x8130
420#define MBOX_ASTS_TXSCVR_REMOVED 0x8131
419 421
420#define ISNS_EVENT_DATA_RECEIVED 0x0000 422#define ISNS_EVENT_DATA_RECEIVED 0x0000
421#define ISNS_EVENT_CONNECTION_OPENED 0x0001 423#define ISNS_EVENT_CONNECTION_OPENED 0x0001
@@ -446,6 +448,7 @@ struct addr_ctrl_blk {
446#define FWOPT_SESSION_MODE 0x0040 448#define FWOPT_SESSION_MODE 0x0040
447#define FWOPT_INITIATOR_MODE 0x0020 449#define FWOPT_INITIATOR_MODE 0x0020
448#define FWOPT_TARGET_MODE 0x0010 450#define FWOPT_TARGET_MODE 0x0010
451#define FWOPT_ENABLE_CRBDB 0x8000
449 452
450 uint16_t exec_throttle; /* 04-05 */ 453 uint16_t exec_throttle; /* 04-05 */
451 uint8_t zio_count; /* 06 */ 454 uint8_t zio_count; /* 06 */
diff --git a/drivers/scsi/qla4xxx/ql4_glbl.h b/drivers/scsi/qla4xxx/ql4_glbl.h
index 95a26fb1626c..6575a47501e5 100644
--- a/drivers/scsi/qla4xxx/ql4_glbl.h
+++ b/drivers/scsi/qla4xxx/ql4_glbl.h
@@ -94,6 +94,7 @@ void qla4xxx_process_response_queue(struct scsi_qla_host *ha);
94void qla4xxx_wake_dpc(struct scsi_qla_host *ha); 94void qla4xxx_wake_dpc(struct scsi_qla_host *ha);
95void qla4xxx_get_conn_event_log(struct scsi_qla_host *ha); 95void qla4xxx_get_conn_event_log(struct scsi_qla_host *ha);
96void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha); 96void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha);
97void qla4xxx_dump_registers(struct scsi_qla_host *ha);
97 98
98void qla4_8xxx_pci_config(struct scsi_qla_host *); 99void qla4_8xxx_pci_config(struct scsi_qla_host *);
99int qla4_8xxx_iospace_config(struct scsi_qla_host *ha); 100int qla4_8xxx_iospace_config(struct scsi_qla_host *ha);
diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
index 4c9be77ee70b..dc01fa3da5d1 100644
--- a/drivers/scsi/qla4xxx/ql4_init.c
+++ b/drivers/scsi/qla4xxx/ql4_init.c
@@ -1207,8 +1207,8 @@ static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host *ha)
1207 break; 1207 break;
1208 1208
1209 DEBUG2(printk(KERN_INFO "scsi%ld: %s: Waiting for boot " 1209 DEBUG2(printk(KERN_INFO "scsi%ld: %s: Waiting for boot "
1210 "firmware to complete... ctrl_sts=0x%x\n", 1210 "firmware to complete... ctrl_sts=0x%x, remaining=%ld\n",
1211 ha->host_no, __func__, ctrl_status)); 1211 ha->host_no, __func__, ctrl_status, max_wait_time));
1212 1212
1213 msleep_interruptible(250); 1213 msleep_interruptible(250);
1214 } while (!time_after_eq(jiffies, max_wait_time)); 1214 } while (!time_after_eq(jiffies, max_wait_time));
@@ -1459,6 +1459,12 @@ int qla4xxx_initialize_adapter(struct scsi_qla_host *ha,
1459exit_init_online: 1459exit_init_online:
1460 set_bit(AF_ONLINE, &ha->flags); 1460 set_bit(AF_ONLINE, &ha->flags);
1461exit_init_hba: 1461exit_init_hba:
1462 if (is_qla8022(ha) && (status == QLA_ERROR)) {
1463 /* Since interrupts are registered in start_firmware for
1464 * 82xx, release them here if initialize_adapter fails */
1465 qla4xxx_free_irqs(ha);
1466 }
1467
1462 DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha->host_no, 1468 DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha->host_no,
1463 status == QLA_ERROR ? "FAILED" : "SUCCEDED")); 1469 status == QLA_ERROR ? "FAILED" : "SUCCEDED"));
1464 return status; 1470 return status;
diff --git a/drivers/scsi/qla4xxx/ql4_iocb.c b/drivers/scsi/qla4xxx/ql4_iocb.c
index 4ef9ba112ee8..5ae49fd87846 100644
--- a/drivers/scsi/qla4xxx/ql4_iocb.c
+++ b/drivers/scsi/qla4xxx/ql4_iocb.c
@@ -202,19 +202,11 @@ static void qla4xxx_build_scsi_iocbs(struct srb *srb,
202void qla4_8xxx_queue_iocb(struct scsi_qla_host *ha) 202void qla4_8xxx_queue_iocb(struct scsi_qla_host *ha)
203{ 203{
204 uint32_t dbval = 0; 204 uint32_t dbval = 0;
205 unsigned long wtime;
206 205
207 dbval = 0x14 | (ha->func_num << 5); 206 dbval = 0x14 | (ha->func_num << 5);
208 dbval = dbval | (0 << 8) | (ha->request_in << 16); 207 dbval = dbval | (0 << 8) | (ha->request_in << 16);
209 writel(dbval, (unsigned long __iomem *)ha->nx_db_wr_ptr);
210 wmb();
211 208
212 wtime = jiffies + (2 * HZ); 209 qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, ha->request_in);
213 while (readl((void __iomem *)ha->nx_db_rd_ptr) != dbval &&
214 !time_after_eq(jiffies, wtime)) {
215 writel(dbval, (unsigned long __iomem *)ha->nx_db_wr_ptr);
216 wmb();
217 }
218} 210}
219 211
220/** 212/**
diff --git a/drivers/scsi/qla4xxx/ql4_isr.c b/drivers/scsi/qla4xxx/ql4_isr.c
index 2a1ab63f3eb0..7c33fd5943d5 100644
--- a/drivers/scsi/qla4xxx/ql4_isr.c
+++ b/drivers/scsi/qla4xxx/ql4_isr.c
@@ -72,7 +72,7 @@ qla4xxx_status_cont_entry(struct scsi_qla_host *ha,
72{ 72{
73 struct srb *srb = ha->status_srb; 73 struct srb *srb = ha->status_srb;
74 struct scsi_cmnd *cmd; 74 struct scsi_cmnd *cmd;
75 uint8_t sense_len; 75 uint16_t sense_len;
76 76
77 if (srb == NULL) 77 if (srb == NULL)
78 return; 78 return;
@@ -487,6 +487,8 @@ static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
487 case MBOX_ASTS_SYSTEM_ERROR: 487 case MBOX_ASTS_SYSTEM_ERROR:
488 /* Log Mailbox registers */ 488 /* Log Mailbox registers */
489 ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__); 489 ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
490 qla4xxx_dump_registers(ha);
491
490 if (ql4xdontresethba) { 492 if (ql4xdontresethba) {
491 DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n", 493 DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
492 ha->host_no, __func__)); 494 ha->host_no, __func__));
@@ -621,6 +623,18 @@ static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
621 } 623 }
622 break; 624 break;
623 625
626 case MBOX_ASTS_TXSCVR_INSERTED:
627 DEBUG2(printk(KERN_WARNING
628 "scsi%ld: AEN %04x Transceiver"
629 " inserted\n", ha->host_no, mbox_sts[0]));
630 break;
631
632 case MBOX_ASTS_TXSCVR_REMOVED:
633 DEBUG2(printk(KERN_WARNING
634 "scsi%ld: AEN %04x Transceiver"
635 " removed\n", ha->host_no, mbox_sts[0]));
636 break;
637
624 default: 638 default:
625 DEBUG2(printk(KERN_WARNING 639 DEBUG2(printk(KERN_WARNING
626 "scsi%ld: AEN %04x UNKNOWN\n", 640 "scsi%ld: AEN %04x UNKNOWN\n",
diff --git a/drivers/scsi/qla4xxx/ql4_mbx.c b/drivers/scsi/qla4xxx/ql4_mbx.c
index 90021704d8ca..2d2f9c879bfd 100644
--- a/drivers/scsi/qla4xxx/ql4_mbx.c
+++ b/drivers/scsi/qla4xxx/ql4_mbx.c
@@ -299,6 +299,10 @@ qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
299{ 299{
300 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT); 300 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
301 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT); 301 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
302
303 if (is_qla8022(ha))
304 qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
305
302 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE; 306 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
303 mbox_cmd[1] = 0; 307 mbox_cmd[1] = 0;
304 mbox_cmd[2] = LSDW(init_fw_cb_dma); 308 mbox_cmd[2] = LSDW(init_fw_cb_dma);
@@ -472,6 +476,11 @@ int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
472 init_fw_cb->fw_options |= 476 init_fw_cb->fw_options |=
473 __constant_cpu_to_le16(FWOPT_SESSION_MODE | 477 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
474 FWOPT_INITIATOR_MODE); 478 FWOPT_INITIATOR_MODE);
479
480 if (is_qla8022(ha))
481 init_fw_cb->fw_options |=
482 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
483
475 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE); 484 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
476 485
477 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) 486 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
@@ -592,7 +601,7 @@ int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
592 } 601 }
593 602
594 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n", 603 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
595 ha->host_no, mbox_cmd[2]); 604 ha->host_no, mbox_sts[2]);
596 605
597 return QLA_SUCCESS; 606 return QLA_SUCCESS;
598} 607}
diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c
index 449256f2c5f8..474b10d71364 100644
--- a/drivers/scsi/qla4xxx/ql4_nx.c
+++ b/drivers/scsi/qla4xxx/ql4_nx.c
@@ -839,8 +839,11 @@ qla4_8xxx_rom_lock(struct scsi_qla_host *ha)
839 done = qla4_8xxx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_LOCK)); 839 done = qla4_8xxx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_LOCK));
840 if (done == 1) 840 if (done == 1)
841 break; 841 break;
842 if (timeout >= qla4_8xxx_rom_lock_timeout) 842 if (timeout >= qla4_8xxx_rom_lock_timeout) {
843 ql4_printk(KERN_WARNING, ha,
844 "%s: Failed to acquire rom lock", __func__);
843 return -1; 845 return -1;
846 }
844 847
845 timeout++; 848 timeout++;
846 849
@@ -1078,21 +1081,6 @@ qla4_8xxx_pinit_from_rom(struct scsi_qla_host *ha, int verbose)
1078 return 0; 1081 return 0;
1079} 1082}
1080 1083
1081static int qla4_8xxx_check_for_bad_spd(struct scsi_qla_host *ha)
1082{
1083 u32 val = 0;
1084 val = qla4_8xxx_rd_32(ha, BOOT_LOADER_DIMM_STATUS) ;
1085 val &= QLA82XX_BOOT_LOADER_MN_ISSUE;
1086 if (val & QLA82XX_PEG_TUNE_MN_SPD_ZEROED) {
1087 printk("Memory DIMM SPD not programmed. Assumed valid.\n");
1088 return 1;
1089 } else if (val) {
1090 printk("Memory DIMM type incorrect. Info:%08X.\n", val);
1091 return 2;
1092 }
1093 return 0;
1094}
1095
1096static int 1084static int
1097qla4_8xxx_load_from_flash(struct scsi_qla_host *ha, uint32_t image_start) 1085qla4_8xxx_load_from_flash(struct scsi_qla_host *ha, uint32_t image_start)
1098{ 1086{
@@ -1377,8 +1365,6 @@ static int qla4_8xxx_cmdpeg_ready(struct scsi_qla_host *ha, int pegtune_val)
1377 1365
1378 } while (--retries); 1366 } while (--retries);
1379 1367
1380 qla4_8xxx_check_for_bad_spd(ha);
1381
1382 if (!retries) { 1368 if (!retries) {
1383 pegtune_val = qla4_8xxx_rd_32(ha, 1369 pegtune_val = qla4_8xxx_rd_32(ha,
1384 QLA82XX_ROMUSB_GLB_PEGTUNE_DONE); 1370 QLA82XX_ROMUSB_GLB_PEGTUNE_DONE);
@@ -1540,14 +1526,31 @@ qla4_8xxx_try_start_fw(struct scsi_qla_host *ha)
1540 ql4_printk(KERN_INFO, ha, 1526 ql4_printk(KERN_INFO, ha,
1541 "FW: Attempting to load firmware from flash...\n"); 1527 "FW: Attempting to load firmware from flash...\n");
1542 rval = qla4_8xxx_start_firmware(ha, ha->hw.flt_region_fw); 1528 rval = qla4_8xxx_start_firmware(ha, ha->hw.flt_region_fw);
1543 if (rval == QLA_SUCCESS)
1544 return rval;
1545 1529
1546 ql4_printk(KERN_ERR, ha, "FW: Load firmware from flash FAILED...\n"); 1530 if (rval != QLA_SUCCESS) {
1531 ql4_printk(KERN_ERR, ha, "FW: Load firmware from flash"
1532 " FAILED...\n");
1533 return rval;
1534 }
1547 1535
1548 return rval; 1536 return rval;
1549} 1537}
1550 1538
1539static void qla4_8xxx_rom_lock_recovery(struct scsi_qla_host *ha)
1540{
1541 if (qla4_8xxx_rom_lock(ha)) {
1542 /* Someone else is holding the lock. */
1543 dev_info(&ha->pdev->dev, "Resetting rom_lock\n");
1544 }
1545
1546 /*
1547 * Either we got the lock, or someone
1548 * else died while holding it.
1549 * In either case, unlock.
1550 */
1551 qla4_8xxx_rom_unlock(ha);
1552}
1553
1551/** 1554/**
1552 * qla4_8xxx_device_bootstrap - Initialize device, set DEV_READY, start fw 1555 * qla4_8xxx_device_bootstrap - Initialize device, set DEV_READY, start fw
1553 * @ha: pointer to adapter structure 1556 * @ha: pointer to adapter structure
@@ -1557,11 +1560,12 @@ qla4_8xxx_try_start_fw(struct scsi_qla_host *ha)
1557static int 1560static int
1558qla4_8xxx_device_bootstrap(struct scsi_qla_host *ha) 1561qla4_8xxx_device_bootstrap(struct scsi_qla_host *ha)
1559{ 1562{
1560 int rval, i, timeout; 1563 int rval = QLA_ERROR;
1564 int i, timeout;
1561 uint32_t old_count, count; 1565 uint32_t old_count, count;
1566 int need_reset = 0, peg_stuck = 1;
1562 1567
1563 if (qla4_8xxx_need_reset(ha)) 1568 need_reset = qla4_8xxx_need_reset(ha);
1564 goto dev_initialize;
1565 1569
1566 old_count = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); 1570 old_count = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
1567 1571
@@ -1570,12 +1574,30 @@ qla4_8xxx_device_bootstrap(struct scsi_qla_host *ha)
1570 if (timeout) { 1574 if (timeout) {
1571 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, 1575 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
1572 QLA82XX_DEV_FAILED); 1576 QLA82XX_DEV_FAILED);
1573 return QLA_ERROR; 1577 return rval;
1574 } 1578 }
1575 1579
1576 count = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); 1580 count = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
1577 if (count != old_count) 1581 if (count != old_count)
1582 peg_stuck = 0;
1583 }
1584
1585 if (need_reset) {
1586 /* We are trying to perform a recovery here. */
1587 if (peg_stuck)
1588 qla4_8xxx_rom_lock_recovery(ha);
1589 goto dev_initialize;
1590 } else {
1591 /* Start of day for this ha context. */
1592 if (peg_stuck) {
1593 /* Either we are the first or recovery in progress. */
1594 qla4_8xxx_rom_lock_recovery(ha);
1595 goto dev_initialize;
1596 } else {
1597 /* Firmware already running. */
1598 rval = QLA_SUCCESS;
1578 goto dev_ready; 1599 goto dev_ready;
1600 }
1579 } 1601 }
1580 1602
1581dev_initialize: 1603dev_initialize:
@@ -1601,7 +1623,7 @@ dev_ready:
1601 ql4_printk(KERN_INFO, ha, "HW State: READY\n"); 1623 ql4_printk(KERN_INFO, ha, "HW State: READY\n");
1602 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_READY); 1624 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_READY);
1603 1625
1604 return QLA_SUCCESS; 1626 return rval;
1605} 1627}
1606 1628
1607/** 1629/**
@@ -1764,20 +1786,9 @@ int qla4_8xxx_load_risc(struct scsi_qla_host *ha)
1764 int retval; 1786 int retval;
1765 retval = qla4_8xxx_device_state_handler(ha); 1787 retval = qla4_8xxx_device_state_handler(ha);
1766 1788
1767 if (retval == QLA_SUCCESS && 1789 if (retval == QLA_SUCCESS && !test_bit(AF_INIT_DONE, &ha->flags))
1768 !test_bit(AF_INIT_DONE, &ha->flags)) {
1769 retval = qla4xxx_request_irqs(ha); 1790 retval = qla4xxx_request_irqs(ha);
1770 if (retval != QLA_SUCCESS) { 1791
1771 ql4_printk(KERN_WARNING, ha,
1772 "Failed to reserve interrupt %d already in use.\n",
1773 ha->pdev->irq);
1774 } else {
1775 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1776 ha->host->irq = ha->pdev->irq;
1777 ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
1778 __func__, ha->pdev->irq);
1779 }
1780 }
1781 return retval; 1792 return retval;
1782} 1793}
1783 1794
diff --git a/drivers/scsi/qla4xxx/ql4_nx.h b/drivers/scsi/qla4xxx/ql4_nx.h
index 931ad3f1e918..ff689bf53007 100644
--- a/drivers/scsi/qla4xxx/ql4_nx.h
+++ b/drivers/scsi/qla4xxx/ql4_nx.h
@@ -24,7 +24,6 @@
24 24
25#define CRB_CMDPEG_STATE QLA82XX_REG(0x50) 25#define CRB_CMDPEG_STATE QLA82XX_REG(0x50)
26#define CRB_RCVPEG_STATE QLA82XX_REG(0x13c) 26#define CRB_RCVPEG_STATE QLA82XX_REG(0x13c)
27#define BOOT_LOADER_DIMM_STATUS QLA82XX_REG(0x54)
28#define CRB_DMA_SHIFT QLA82XX_REG(0xcc) 27#define CRB_DMA_SHIFT QLA82XX_REG(0xcc)
29 28
30#define QLA82XX_HW_H0_CH_HUB_ADR 0x05 29#define QLA82XX_HW_H0_CH_HUB_ADR 0x05
@@ -529,12 +528,12 @@
529# define QLA82XX_CAM_RAM_BASE (QLA82XX_CRB_CAM + 0x02000) 528# define QLA82XX_CAM_RAM_BASE (QLA82XX_CRB_CAM + 0x02000)
530# define QLA82XX_CAM_RAM(reg) (QLA82XX_CAM_RAM_BASE + (reg)) 529# define QLA82XX_CAM_RAM(reg) (QLA82XX_CAM_RAM_BASE + (reg))
531 530
532#define QLA82XX_PEG_TUNE_MN_SPD_ZEROED 0x80000000
533#define QLA82XX_BOOT_LOADER_MN_ISSUE 0xff00ffff
534#define QLA82XX_PORT_MODE_ADDR (QLA82XX_CAM_RAM(0x24)) 531#define QLA82XX_PORT_MODE_ADDR (QLA82XX_CAM_RAM(0x24))
535#define QLA82XX_PEG_HALT_STATUS1 (QLA82XX_CAM_RAM(0xa8)) 532#define QLA82XX_PEG_HALT_STATUS1 (QLA82XX_CAM_RAM(0xa8))
536#define QLA82XX_PEG_HALT_STATUS2 (QLA82XX_CAM_RAM(0xac)) 533#define QLA82XX_PEG_HALT_STATUS2 (QLA82XX_CAM_RAM(0xac))
537#define QLA82XX_PEG_ALIVE_COUNTER (QLA82XX_CAM_RAM(0xb0)) 534#define QLA82XX_PEG_ALIVE_COUNTER (QLA82XX_CAM_RAM(0xb0))
535#define QLA82XX_CAM_RAM_DB1 (QLA82XX_CAM_RAM(0x1b0))
536#define QLA82XX_CAM_RAM_DB2 (QLA82XX_CAM_RAM(0x1b4))
538 537
539#define HALT_STATUS_UNRECOVERABLE 0x80000000 538#define HALT_STATUS_UNRECOVERABLE 0x80000000
540#define HALT_STATUS_RECOVERABLE 0x40000000 539#define HALT_STATUS_RECOVERABLE 0x40000000
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 370d40ff1529..0d48fb4d1044 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -79,8 +79,7 @@ static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
79/* 79/*
80 * SCSI host template entry points 80 * SCSI host template entry points
81 */ 81 */
82static int qla4xxx_queuecommand(struct scsi_cmnd *cmd, 82static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
83 void (*done) (struct scsi_cmnd *));
84static int qla4xxx_eh_abort(struct scsi_cmnd *cmd); 83static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
85static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd); 84static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
86static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); 85static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
@@ -167,8 +166,6 @@ static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
167 "of (%d) secs exhausted, marking device DEAD.\n", 166 "of (%d) secs exhausted, marking device DEAD.\n",
168 ha->host_no, __func__, ddb_entry->fw_ddb_index, 167 ha->host_no, __func__, ddb_entry->fw_ddb_index,
169 QL4_SESS_RECOVERY_TMO)); 168 QL4_SESS_RECOVERY_TMO));
170
171 qla4xxx_wake_dpc(ha);
172 } 169 }
173} 170}
174 171
@@ -466,7 +463,7 @@ void qla4xxx_srb_compl(struct kref *ref)
466 * completion handling). Unfortunely, it sometimes calls the scheduler 463 * completion handling). Unfortunely, it sometimes calls the scheduler
467 * in interrupt context which is a big NO! NO!. 464 * in interrupt context which is a big NO! NO!.
468 **/ 465 **/
469static int qla4xxx_queuecommand(struct scsi_cmnd *cmd, 466static int qla4xxx_queuecommand_lck(struct scsi_cmnd *cmd,
470 void (*done)(struct scsi_cmnd *)) 467 void (*done)(struct scsi_cmnd *))
471{ 468{
472 struct scsi_qla_host *ha = to_qla_host(cmd->device->host); 469 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
@@ -540,6 +537,8 @@ qc_fail_command:
540 return 0; 537 return 0;
541} 538}
542 539
540static DEF_SCSI_QCMD(qla4xxx_queuecommand)
541
543/** 542/**
544 * qla4xxx_mem_free - frees memory allocated to adapter 543 * qla4xxx_mem_free - frees memory allocated to adapter
545 * @ha: Pointer to host adapter structure. 544 * @ha: Pointer to host adapter structure.
@@ -573,10 +572,6 @@ static void qla4xxx_mem_free(struct scsi_qla_host *ha)
573 if (ha->nx_pcibase) 572 if (ha->nx_pcibase)
574 iounmap( 573 iounmap(
575 (struct device_reg_82xx __iomem *)ha->nx_pcibase); 574 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
576
577 if (ha->nx_db_wr_ptr)
578 iounmap(
579 (struct device_reg_82xx __iomem *)ha->nx_db_wr_ptr);
580 } else if (ha->reg) 575 } else if (ha->reg)
581 iounmap(ha->reg); 576 iounmap(ha->reg);
582 pci_release_regions(ha->pdev); 577 pci_release_regions(ha->pdev);
@@ -692,7 +687,9 @@ static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
692 qla4xxx_wake_dpc(ha); 687 qla4xxx_wake_dpc(ha);
693 qla4xxx_mailbox_premature_completion(ha); 688 qla4xxx_mailbox_premature_completion(ha);
694 } 689 }
695 } 690 } else
691 ha->seconds_since_last_heartbeat = 0;
692
696 ha->fw_heartbeat_counter = fw_heartbeat_counter; 693 ha->fw_heartbeat_counter = fw_heartbeat_counter;
697} 694}
698 695
@@ -885,7 +882,13 @@ static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
885 /* Find a command that hasn't completed. */ 882 /* Find a command that hasn't completed. */
886 for (index = 0; index < ha->host->can_queue; index++) { 883 for (index = 0; index < ha->host->can_queue; index++) {
887 cmd = scsi_host_find_tag(ha->host, index); 884 cmd = scsi_host_find_tag(ha->host, index);
888 if (cmd != NULL) 885 /*
886 * We cannot just check if the index is valid,
887 * becase if we are run from the scsi eh, then
888 * the scsi/block layer is going to prevent
889 * the tag from being released.
890 */
891 if (cmd != NULL && CMD_SP(cmd))
889 break; 892 break;
890 } 893 }
891 spin_unlock_irqrestore(&ha->hardware_lock, flags); 894 spin_unlock_irqrestore(&ha->hardware_lock, flags);
@@ -937,11 +940,14 @@ int qla4xxx_soft_reset(struct scsi_qla_host *ha)
937{ 940{
938 uint32_t max_wait_time; 941 uint32_t max_wait_time;
939 unsigned long flags = 0; 942 unsigned long flags = 0;
940 int status = QLA_ERROR; 943 int status;
941 uint32_t ctrl_status; 944 uint32_t ctrl_status;
942 945
943 qla4xxx_hw_reset(ha); 946 status = qla4xxx_hw_reset(ha);
947 if (status != QLA_SUCCESS)
948 return status;
944 949
950 status = QLA_ERROR;
945 /* Wait until the Network Reset Intr bit is cleared */ 951 /* Wait until the Network Reset Intr bit is cleared */
946 max_wait_time = RESET_INTR_TOV; 952 max_wait_time = RESET_INTR_TOV;
947 do { 953 do {
@@ -1101,7 +1107,8 @@ static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
1101 ha->host_no, __func__)); 1107 ha->host_no, __func__));
1102 status = ha->isp_ops->reset_firmware(ha); 1108 status = ha->isp_ops->reset_firmware(ha);
1103 if (status == QLA_SUCCESS) { 1109 if (status == QLA_SUCCESS) {
1104 qla4xxx_cmd_wait(ha); 1110 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
1111 qla4xxx_cmd_wait(ha);
1105 ha->isp_ops->disable_intrs(ha); 1112 ha->isp_ops->disable_intrs(ha);
1106 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); 1113 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1107 qla4xxx_abort_active_cmds(ha, DID_RESET << 16); 1114 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
@@ -1118,7 +1125,8 @@ static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
1118 * or if stop_firmware fails for ISP-82xx. 1125 * or if stop_firmware fails for ISP-82xx.
1119 * This is the default case for ISP-4xxx */ 1126 * This is the default case for ISP-4xxx */
1120 if (!is_qla8022(ha) || reset_chip) { 1127 if (!is_qla8022(ha) || reset_chip) {
1121 qla4xxx_cmd_wait(ha); 1128 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
1129 qla4xxx_cmd_wait(ha);
1122 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); 1130 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1123 qla4xxx_abort_active_cmds(ha, DID_RESET << 16); 1131 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1124 DEBUG2(ql4_printk(KERN_INFO, ha, 1132 DEBUG2(ql4_printk(KERN_INFO, ha,
@@ -1471,24 +1479,10 @@ int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
1471 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ 1479 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
1472 db_len = pci_resource_len(pdev, 4); 1480 db_len = pci_resource_len(pdev, 4);
1473 1481
1474 /* mapping of doorbell write pointer */ 1482 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
1475 ha->nx_db_wr_ptr = (unsigned long)ioremap(db_base + 1483 QLA82XX_CAM_RAM_DB2);
1476 (ha->pdev->devfn << 12), 4);
1477 if (!ha->nx_db_wr_ptr) {
1478 printk(KERN_ERR
1479 "cannot remap MMIO doorbell-write (%s), aborting\n",
1480 pci_name(pdev));
1481 goto iospace_error_exit;
1482 }
1483 /* mapping of doorbell read pointer */
1484 ha->nx_db_rd_ptr = (uint8_t *) ha->nx_pcibase + (512 * 1024) +
1485 (ha->pdev->devfn * 8);
1486 if (!ha->nx_db_rd_ptr)
1487 printk(KERN_ERR
1488 "cannot remap MMIO doorbell-read (%s), aborting\n",
1489 pci_name(pdev));
1490 return 0;
1491 1484
1485 return 0;
1492iospace_error_exit: 1486iospace_error_exit:
1493 return -ENOMEM; 1487 return -ENOMEM;
1494} 1488}
@@ -1960,13 +1954,11 @@ static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
1960{ 1954{
1961 unsigned long wait_online; 1955 unsigned long wait_online;
1962 1956
1963 wait_online = jiffies + (30 * HZ); 1957 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
1964 while (time_before(jiffies, wait_online)) { 1958 while (time_before(jiffies, wait_online)) {
1965 1959
1966 if (adapter_up(ha)) 1960 if (adapter_up(ha))
1967 return QLA_SUCCESS; 1961 return QLA_SUCCESS;
1968 else if (ha->retry_reset_ha_cnt == 0)
1969 return QLA_ERROR;
1970 1962
1971 msleep(2000); 1963 msleep(2000);
1972 } 1964 }
@@ -2021,6 +2013,7 @@ static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
2021 unsigned int id = cmd->device->id; 2013 unsigned int id = cmd->device->id;
2022 unsigned int lun = cmd->device->lun; 2014 unsigned int lun = cmd->device->lun;
2023 unsigned long serial = cmd->serial_number; 2015 unsigned long serial = cmd->serial_number;
2016 unsigned long flags;
2024 struct srb *srb = NULL; 2017 struct srb *srb = NULL;
2025 int ret = SUCCESS; 2018 int ret = SUCCESS;
2026 int wait = 0; 2019 int wait = 0;
@@ -2029,12 +2022,14 @@ static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
2029 "scsi%ld:%d:%d: Abort command issued cmd=%p, pid=%ld\n", 2022 "scsi%ld:%d:%d: Abort command issued cmd=%p, pid=%ld\n",
2030 ha->host_no, id, lun, cmd, serial); 2023 ha->host_no, id, lun, cmd, serial);
2031 2024
2025 spin_lock_irqsave(&ha->hardware_lock, flags);
2032 srb = (struct srb *) CMD_SP(cmd); 2026 srb = (struct srb *) CMD_SP(cmd);
2033 2027 if (!srb) {
2034 if (!srb) 2028 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2035 return SUCCESS; 2029 return SUCCESS;
2036 2030 }
2037 kref_get(&srb->srb_ref); 2031 kref_get(&srb->srb_ref);
2032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2038 2033
2039 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) { 2034 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
2040 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n", 2035 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
@@ -2267,6 +2262,8 @@ qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2267 qla4xxx_mailbox_premature_completion(ha); 2262 qla4xxx_mailbox_premature_completion(ha);
2268 qla4xxx_free_irqs(ha); 2263 qla4xxx_free_irqs(ha);
2269 pci_disable_device(pdev); 2264 pci_disable_device(pdev);
2265 /* Return back all IOs */
2266 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2270 return PCI_ERS_RESULT_NEED_RESET; 2267 return PCI_ERS_RESULT_NEED_RESET;
2271 case pci_channel_io_perm_failure: 2268 case pci_channel_io_perm_failure:
2272 set_bit(AF_EEH_BUSY, &ha->flags); 2269 set_bit(AF_EEH_BUSY, &ha->flags);
@@ -2290,17 +2287,13 @@ qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
2290 if (!is_aer_supported(ha)) 2287 if (!is_aer_supported(ha))
2291 return PCI_ERS_RESULT_NONE; 2288 return PCI_ERS_RESULT_NONE;
2292 2289
2293 if (test_bit(AF_FW_RECOVERY, &ha->flags)) { 2290 return PCI_ERS_RESULT_RECOVERED;
2294 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: firmware hang -- "
2295 "mmio_enabled\n", ha->host_no, __func__);
2296 return PCI_ERS_RESULT_NEED_RESET;
2297 } else
2298 return PCI_ERS_RESULT_RECOVERED;
2299} 2291}
2300 2292
2301uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha) 2293static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
2302{ 2294{
2303 uint32_t rval = QLA_ERROR; 2295 uint32_t rval = QLA_ERROR;
2296 uint32_t ret = 0;
2304 int fn; 2297 int fn;
2305 struct pci_dev *other_pdev = NULL; 2298 struct pci_dev *other_pdev = NULL;
2306 2299
@@ -2312,7 +2305,6 @@ uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
2312 clear_bit(AF_ONLINE, &ha->flags); 2305 clear_bit(AF_ONLINE, &ha->flags);
2313 qla4xxx_mark_all_devices_missing(ha); 2306 qla4xxx_mark_all_devices_missing(ha);
2314 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); 2307 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2315 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2316 } 2308 }
2317 2309
2318 fn = PCI_FUNC(ha->pdev->devfn); 2310 fn = PCI_FUNC(ha->pdev->devfn);
@@ -2375,7 +2367,16 @@ uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
2375 /* Clear driver state register */ 2367 /* Clear driver state register */
2376 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0); 2368 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
2377 qla4_8xxx_set_drv_active(ha); 2369 qla4_8xxx_set_drv_active(ha);
2378 ha->isp_ops->enable_intrs(ha); 2370 ret = qla4xxx_request_irqs(ha);
2371 if (ret) {
2372 ql4_printk(KERN_WARNING, ha, "Failed to "
2373 "reserve interrupt %d already in use.\n",
2374 ha->pdev->irq);
2375 rval = QLA_ERROR;
2376 } else {
2377 ha->isp_ops->enable_intrs(ha);
2378 rval = QLA_SUCCESS;
2379 }
2379 } 2380 }
2380 qla4_8xxx_idc_unlock(ha); 2381 qla4_8xxx_idc_unlock(ha);
2381 } else { 2382 } else {
@@ -2387,8 +2388,18 @@ uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
2387 clear_bit(AF_FW_RECOVERY, &ha->flags); 2388 clear_bit(AF_FW_RECOVERY, &ha->flags);
2388 rval = qla4xxx_initialize_adapter(ha, 2389 rval = qla4xxx_initialize_adapter(ha,
2389 PRESERVE_DDB_LIST); 2390 PRESERVE_DDB_LIST);
2390 if (rval == QLA_SUCCESS) 2391 if (rval == QLA_SUCCESS) {
2391 ha->isp_ops->enable_intrs(ha); 2392 ret = qla4xxx_request_irqs(ha);
2393 if (ret) {
2394 ql4_printk(KERN_WARNING, ha, "Failed to"
2395 " reserve interrupt %d already in"
2396 " use.\n", ha->pdev->irq);
2397 rval = QLA_ERROR;
2398 } else {
2399 ha->isp_ops->enable_intrs(ha);
2400 rval = QLA_SUCCESS;
2401 }
2402 }
2392 qla4_8xxx_idc_lock(ha); 2403 qla4_8xxx_idc_lock(ha);
2393 qla4_8xxx_set_drv_active(ha); 2404 qla4_8xxx_set_drv_active(ha);
2394 qla4_8xxx_idc_unlock(ha); 2405 qla4_8xxx_idc_unlock(ha);
@@ -2430,12 +2441,7 @@ qla4xxx_pci_slot_reset(struct pci_dev *pdev)
2430 goto exit_slot_reset; 2441 goto exit_slot_reset;
2431 } 2442 }
2432 2443
2433 ret = qla4xxx_request_irqs(ha); 2444 ha->isp_ops->disable_intrs(ha);
2434 if (ret) {
2435 ql4_printk(KERN_WARNING, ha, "Failed to reserve interrupt %d"
2436 " already in use.\n", pdev->irq);
2437 goto exit_slot_reset;
2438 }
2439 2445
2440 if (is_qla8022(ha)) { 2446 if (is_qla8022(ha)) {
2441 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) { 2447 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
diff --git a/drivers/scsi/qla4xxx/ql4_version.h b/drivers/scsi/qla4xxx/ql4_version.h
index a77b973f2cbc..9bfacf4ed137 100644
--- a/drivers/scsi/qla4xxx/ql4_version.h
+++ b/drivers/scsi/qla4xxx/ql4_version.h
@@ -5,4 +5,4 @@
5 * See LICENSE.qla4xxx for copyright and licensing details. 5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */ 6 */
7 7
8#define QLA4XXX_DRIVER_VERSION "5.02.00-k3" 8#define QLA4XXX_DRIVER_VERSION "5.02.00-k4"
diff --git a/drivers/scsi/qlogicfas408.c b/drivers/scsi/qlogicfas408.c
index 1ad51552d6b1..c3a9151ca823 100644
--- a/drivers/scsi/qlogicfas408.c
+++ b/drivers/scsi/qlogicfas408.c
@@ -439,7 +439,7 @@ irqreturn_t qlogicfas408_ihandl(int irq, void *dev_id)
439 * Queued command 439 * Queued command
440 */ 440 */
441 441
442int qlogicfas408_queuecommand(struct scsi_cmnd *cmd, 442static int qlogicfas408_queuecommand_lck(struct scsi_cmnd *cmd,
443 void (*done) (struct scsi_cmnd *)) 443 void (*done) (struct scsi_cmnd *))
444{ 444{
445 struct qlogicfas408_priv *priv = get_priv_by_cmd(cmd); 445 struct qlogicfas408_priv *priv = get_priv_by_cmd(cmd);
@@ -459,6 +459,8 @@ int qlogicfas408_queuecommand(struct scsi_cmnd *cmd,
459 return 0; 459 return 0;
460} 460}
461 461
462DEF_SCSI_QCMD(qlogicfas408_queuecommand)
463
462/* 464/*
463 * Return bios parameters 465 * Return bios parameters
464 */ 466 */
diff --git a/drivers/scsi/qlogicfas408.h b/drivers/scsi/qlogicfas408.h
index 260626427a32..2f6c0a166200 100644
--- a/drivers/scsi/qlogicfas408.h
+++ b/drivers/scsi/qlogicfas408.h
@@ -103,8 +103,7 @@ struct qlogicfas408_priv {
103#define get_priv_by_host(x) (struct qlogicfas408_priv *)&((x)->hostdata[0]) 103#define get_priv_by_host(x) (struct qlogicfas408_priv *)&((x)->hostdata[0])
104 104
105irqreturn_t qlogicfas408_ihandl(int irq, void *dev_id); 105irqreturn_t qlogicfas408_ihandl(int irq, void *dev_id);
106int qlogicfas408_queuecommand(struct scsi_cmnd * cmd, 106int qlogicfas408_queuecommand(struct Scsi_Host *h, struct scsi_cmnd * cmd);
107 void (*done) (struct scsi_cmnd *));
108int qlogicfas408_biosparam(struct scsi_device * disk, 107int qlogicfas408_biosparam(struct scsi_device * disk,
109 struct block_device *dev, 108 struct block_device *dev,
110 sector_t capacity, int ip[]); 109 sector_t capacity, int ip[]);
diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c
index f8c561cf751e..664c9572d0c9 100644
--- a/drivers/scsi/qlogicpti.c
+++ b/drivers/scsi/qlogicpti.c
@@ -1003,7 +1003,7 @@ static int qlogicpti_slave_configure(struct scsi_device *sdev)
1003 * 1003 *
1004 * "This code must fly." -davem 1004 * "This code must fly." -davem
1005 */ 1005 */
1006static int qlogicpti_queuecommand(struct scsi_cmnd *Cmnd, void (*done)(struct scsi_cmnd *)) 1006static int qlogicpti_queuecommand_lck(struct scsi_cmnd *Cmnd, void (*done)(struct scsi_cmnd *))
1007{ 1007{
1008 struct Scsi_Host *host = Cmnd->device->host; 1008 struct Scsi_Host *host = Cmnd->device->host;
1009 struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata; 1009 struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata;
@@ -1052,6 +1052,8 @@ toss_command:
1052 return 1; 1052 return 1;
1053} 1053}
1054 1054
1055static DEF_SCSI_QCMD(qlogicpti_queuecommand)
1056
1055static int qlogicpti_return_status(struct Status_Entry *sts, int id) 1057static int qlogicpti_return_status(struct Status_Entry *sts, int id)
1056{ 1058{
1057 int host_status = DID_ERROR; 1059 int host_status = DID_ERROR;
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 348fba0a8976..2aeb2e9c4d3b 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -634,12 +634,13 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
634 * Description: a serial number identifies a request for error recovery 634 * Description: a serial number identifies a request for error recovery
635 * and debugging purposes. Protected by the Host_Lock of host. 635 * and debugging purposes. Protected by the Host_Lock of host.
636 */ 636 */
637static inline void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd *cmd) 637void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd *cmd)
638{ 638{
639 cmd->serial_number = host->cmd_serial_number++; 639 cmd->serial_number = host->cmd_serial_number++;
640 if (cmd->serial_number == 0) 640 if (cmd->serial_number == 0)
641 cmd->serial_number = host->cmd_serial_number++; 641 cmd->serial_number = host->cmd_serial_number++;
642} 642}
643EXPORT_SYMBOL(scsi_cmd_get_serial);
643 644
644/** 645/**
645 * scsi_dispatch_command - Dispatch a command to the low-level driver. 646 * scsi_dispatch_command - Dispatch a command to the low-level driver.
@@ -651,7 +652,6 @@ static inline void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd
651int scsi_dispatch_cmd(struct scsi_cmnd *cmd) 652int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
652{ 653{
653 struct Scsi_Host *host = cmd->device->host; 654 struct Scsi_Host *host = cmd->device->host;
654 unsigned long flags = 0;
655 unsigned long timeout; 655 unsigned long timeout;
656 int rtn = 0; 656 int rtn = 0;
657 657
@@ -737,23 +737,15 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
737 goto out; 737 goto out;
738 } 738 }
739 739
740 spin_lock_irqsave(host->host_lock, flags);
741 /*
742 * AK: unlikely race here: for some reason the timer could
743 * expire before the serial number is set up below.
744 *
745 * TODO: kill serial or move to blk layer
746 */
747 scsi_cmd_get_serial(host, cmd);
748
749 if (unlikely(host->shost_state == SHOST_DEL)) { 740 if (unlikely(host->shost_state == SHOST_DEL)) {
750 cmd->result = (DID_NO_CONNECT << 16); 741 cmd->result = (DID_NO_CONNECT << 16);
751 scsi_done(cmd); 742 scsi_done(cmd);
752 } else { 743 } else {
753 trace_scsi_dispatch_cmd_start(cmd); 744 trace_scsi_dispatch_cmd_start(cmd);
754 rtn = host->hostt->queuecommand(cmd, scsi_done); 745 cmd->scsi_done = scsi_done;
746 rtn = host->hostt->queuecommand(host, cmd);
755 } 747 }
756 spin_unlock_irqrestore(host->host_lock, flags); 748
757 if (rtn) { 749 if (rtn) {
758 trace_scsi_dispatch_cmd_error(cmd, rtn); 750 trace_scsi_dispatch_cmd_error(cmd, rtn);
759 if (rtn != SCSI_MLQUEUE_DEVICE_BUSY && 751 if (rtn != SCSI_MLQUEUE_DEVICE_BUSY &&
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 2c36bae3bd4b..2f1f9b079b10 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -3538,7 +3538,7 @@ static void sdebug_remove_adapter(void)
3538} 3538}
3539 3539
3540static 3540static
3541int scsi_debug_queuecommand(struct scsi_cmnd *SCpnt, done_funct_t done) 3541int scsi_debug_queuecommand_lck(struct scsi_cmnd *SCpnt, done_funct_t done)
3542{ 3542{
3543 unsigned char *cmd = (unsigned char *) SCpnt->cmnd; 3543 unsigned char *cmd = (unsigned char *) SCpnt->cmnd;
3544 int len, k; 3544 int len, k;
@@ -3884,6 +3884,8 @@ write:
3884 (delay_override ? 0 : scsi_debug_delay)); 3884 (delay_override ? 0 : scsi_debug_delay));
3885} 3885}
3886 3886
3887static DEF_SCSI_QCMD(scsi_debug_queuecommand)
3888
3887static struct scsi_host_template sdebug_driver_template = { 3889static struct scsi_host_template sdebug_driver_template = {
3888 .proc_info = scsi_debug_proc_info, 3890 .proc_info = scsi_debug_proc_info,
3889 .proc_name = sdebug_proc_name, 3891 .proc_name = sdebug_proc_name,
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 1de30eb83bb0..30ac116186f5 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -320,19 +320,11 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
320 "changed. The Linux SCSI layer does not " 320 "changed. The Linux SCSI layer does not "
321 "automatically adjust these parameters.\n"); 321 "automatically adjust these parameters.\n");
322 322
323 if (scmd->request->cmd_flags & REQ_HARDBARRIER) 323 /*
324 /* 324 * Pass the UA upwards for a determination in the completion
325 * barrier requests should always retry on UA 325 * functions.
326 * otherwise block will get a spurious error 326 */
327 */ 327 return SUCCESS;
328 return NEEDS_RETRY;
329 else
330 /*
331 * for normal (non barrier) commands, pass the
332 * UA upwards for a determination in the
333 * completion functions
334 */
335 return SUCCESS;
336 328
337 /* these three are not supported */ 329 /* these three are not supported */
338 case COPY_ABORTED: 330 case COPY_ABORTED:
@@ -623,7 +615,7 @@ static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
623 return rtn; 615 return rtn;
624} 616}
625 617
626static int __scsi_try_to_abort_cmd(struct scsi_cmnd *scmd) 618static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
627{ 619{
628 if (!scmd->device->host->hostt->eh_abort_handler) 620 if (!scmd->device->host->hostt->eh_abort_handler)
629 return FAILED; 621 return FAILED;
@@ -631,31 +623,9 @@ static int __scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
631 return scmd->device->host->hostt->eh_abort_handler(scmd); 623 return scmd->device->host->hostt->eh_abort_handler(scmd);
632} 624}
633 625
634/**
635 * scsi_try_to_abort_cmd - Ask host to abort a running command.
636 * @scmd: SCSI cmd to abort from Lower Level.
637 *
638 * Notes:
639 * This function will not return until the user's completion function
640 * has been called. there is no timeout on this operation. if the
641 * author of the low-level driver wishes this operation to be timed,
642 * they can provide this facility themselves. helper functions in
643 * scsi_error.c can be supplied to make this easier to do.
644 */
645static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
646{
647 /*
648 * scsi_done was called just after the command timed out and before
649 * we had a chance to process it. (db)
650 */
651 if (scmd->serial_number == 0)
652 return SUCCESS;
653 return __scsi_try_to_abort_cmd(scmd);
654}
655
656static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd) 626static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
657{ 627{
658 if (__scsi_try_to_abort_cmd(scmd) != SUCCESS) 628 if (scsi_try_to_abort_cmd(scmd) != SUCCESS)
659 if (scsi_try_bus_device_reset(scmd) != SUCCESS) 629 if (scsi_try_bus_device_reset(scmd) != SUCCESS)
660 if (scsi_try_target_reset(scmd) != SUCCESS) 630 if (scsi_try_target_reset(scmd) != SUCCESS)
661 if (scsi_try_bus_reset(scmd) != SUCCESS) 631 if (scsi_try_bus_reset(scmd) != SUCCESS)
@@ -781,17 +751,15 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd,
781 struct Scsi_Host *shost = sdev->host; 751 struct Scsi_Host *shost = sdev->host;
782 DECLARE_COMPLETION_ONSTACK(done); 752 DECLARE_COMPLETION_ONSTACK(done);
783 unsigned long timeleft; 753 unsigned long timeleft;
784 unsigned long flags;
785 struct scsi_eh_save ses; 754 struct scsi_eh_save ses;
786 int rtn; 755 int rtn;
787 756
788 scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes); 757 scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes);
789 shost->eh_action = &done; 758 shost->eh_action = &done;
790 759
791 spin_lock_irqsave(shost->host_lock, flags);
792 scsi_log_send(scmd); 760 scsi_log_send(scmd);
793 shost->hostt->queuecommand(scmd, scsi_eh_done); 761 scmd->scsi_done = scsi_eh_done;
794 spin_unlock_irqrestore(shost->host_lock, flags); 762 shost->hostt->queuecommand(shost, scmd);
795 763
796 timeleft = wait_for_completion_timeout(&done, timeout); 764 timeleft = wait_for_completion_timeout(&done, timeout);
797 765
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 8041fe1ab179..4a3842212c50 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1403,11 +1403,6 @@ static void scsi_softirq_done(struct request *rq)
1403 1403
1404 INIT_LIST_HEAD(&cmd->eh_entry); 1404 INIT_LIST_HEAD(&cmd->eh_entry);
1405 1405
1406 /*
1407 * Set the serial numbers back to zero
1408 */
1409 cmd->serial_number = 0;
1410
1411 atomic_inc(&cmd->device->iodone_cnt); 1406 atomic_inc(&cmd->device->iodone_cnt);
1412 if (cmd->result) 1407 if (cmd->result)
1413 atomic_inc(&cmd->device->ioerr_cnt); 1408 atomic_inc(&cmd->device->ioerr_cnt);
@@ -1642,9 +1637,8 @@ struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
1642 1637
1643 blk_queue_max_segment_size(q, dma_get_max_seg_size(dev)); 1638 blk_queue_max_segment_size(q, dma_get_max_seg_size(dev));
1644 1639
1645 /* New queue, no concurrency on queue_flags */
1646 if (!shost->use_clustering) 1640 if (!shost->use_clustering)
1647 queue_flag_clear_unlocked(QUEUE_FLAG_CLUSTER, q); 1641 q->limits.cluster = 0;
1648 1642
1649 /* 1643 /*
1650 * set a reasonable default alignment on word boundaries: the 1644 * set a reasonable default alignment on word boundaries: the
@@ -2438,7 +2432,8 @@ scsi_internal_device_unblock(struct scsi_device *sdev)
2438 sdev->sdev_state = SDEV_RUNNING; 2432 sdev->sdev_state = SDEV_RUNNING;
2439 else if (sdev->sdev_state == SDEV_CREATED_BLOCK) 2433 else if (sdev->sdev_state == SDEV_CREATED_BLOCK)
2440 sdev->sdev_state = SDEV_CREATED; 2434 sdev->sdev_state = SDEV_CREATED;
2441 else 2435 else if (sdev->sdev_state != SDEV_CANCEL &&
2436 sdev->sdev_state != SDEV_OFFLINE)
2442 return -EINVAL; 2437 return -EINVAL;
2443 2438
2444 spin_lock_irqsave(q->queue_lock, flags); 2439 spin_lock_irqsave(q->queue_lock, flags);
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 9c52ce4f7129..8dc1f00aa5e8 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -966,10 +966,11 @@ static void __scsi_remove_target(struct scsi_target *starget)
966 list_for_each_entry(sdev, &shost->__devices, siblings) { 966 list_for_each_entry(sdev, &shost->__devices, siblings) {
967 if (sdev->channel != starget->channel || 967 if (sdev->channel != starget->channel ||
968 sdev->id != starget->id || 968 sdev->id != starget->id ||
969 sdev->sdev_state == SDEV_DEL) 969 scsi_device_get(sdev))
970 continue; 970 continue;
971 spin_unlock_irqrestore(shost->host_lock, flags); 971 spin_unlock_irqrestore(shost->host_lock, flags);
972 scsi_remove_device(sdev); 972 scsi_remove_device(sdev);
973 scsi_device_put(sdev);
973 spin_lock_irqsave(shost->host_lock, flags); 974 spin_lock_irqsave(shost->host_lock, flags);
974 goto restart; 975 goto restart;
975 } 976 }
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 57d1e3e1bd44..956496182c80 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -46,7 +46,6 @@
46#include <linux/blkdev.h> 46#include <linux/blkdev.h>
47#include <linux/blkpg.h> 47#include <linux/blkpg.h>
48#include <linux/delay.h> 48#include <linux/delay.h>
49#include <linux/smp_lock.h>
50#include <linux/mutex.h> 49#include <linux/mutex.h>
51#include <linux/string_helpers.h> 50#include <linux/string_helpers.h>
52#include <linux/async.h> 51#include <linux/async.h>
@@ -259,6 +258,28 @@ sd_show_protection_type(struct device *dev, struct device_attribute *attr,
259} 258}
260 259
261static ssize_t 260static ssize_t
261sd_show_protection_mode(struct device *dev, struct device_attribute *attr,
262 char *buf)
263{
264 struct scsi_disk *sdkp = to_scsi_disk(dev);
265 struct scsi_device *sdp = sdkp->device;
266 unsigned int dif, dix;
267
268 dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type);
269 dix = scsi_host_dix_capable(sdp->host, sdkp->protection_type);
270
271 if (!dix && scsi_host_dix_capable(sdp->host, SD_DIF_TYPE0_PROTECTION)) {
272 dif = 0;
273 dix = 1;
274 }
275
276 if (!dif && !dix)
277 return snprintf(buf, 20, "none\n");
278
279 return snprintf(buf, 20, "%s%u\n", dix ? "dix" : "dif", dif);
280}
281
282static ssize_t
262sd_show_app_tag_own(struct device *dev, struct device_attribute *attr, 283sd_show_app_tag_own(struct device *dev, struct device_attribute *attr,
263 char *buf) 284 char *buf)
264{ 285{
@@ -285,6 +306,7 @@ static struct device_attribute sd_disk_attrs[] = {
285 __ATTR(manage_start_stop, S_IRUGO|S_IWUSR, sd_show_manage_start_stop, 306 __ATTR(manage_start_stop, S_IRUGO|S_IWUSR, sd_show_manage_start_stop,
286 sd_store_manage_start_stop), 307 sd_store_manage_start_stop),
287 __ATTR(protection_type, S_IRUGO, sd_show_protection_type, NULL), 308 __ATTR(protection_type, S_IRUGO, sd_show_protection_type, NULL),
309 __ATTR(protection_mode, S_IRUGO, sd_show_protection_mode, NULL),
288 __ATTR(app_tag_own, S_IRUGO, sd_show_app_tag_own, NULL), 310 __ATTR(app_tag_own, S_IRUGO, sd_show_app_tag_own, NULL),
289 __ATTR(thin_provisioning, S_IRUGO, sd_show_thin_provisioning, NULL), 311 __ATTR(thin_provisioning, S_IRUGO, sd_show_thin_provisioning, NULL),
290 __ATTR_NULL, 312 __ATTR_NULL,
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index cbb38c5197fa..3cd8ffbad577 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -325,6 +325,15 @@ int sr_drive_status(struct cdrom_device_info *cdi, int slot)
325 } 325 }
326 326
327 /* 327 /*
328 * SK/ASC/ASCQ of 2/4/2 means "initialization required"
329 * Using CD_TRAY_OPEN results in an START_STOP_UNIT to close
330 * the tray, which resolves the initialization requirement.
331 */
332 if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
333 && sshdr.asc == 0x04 && sshdr.ascq == 0x02)
334 return CDS_TRAY_OPEN;
335
336 /*
328 * 0x04 is format in progress .. but there must be a disc present! 337 * 0x04 is format in progress .. but there must be a disc present!
329 */ 338 */
330 if (sshdr.sense_key == NOT_READY && sshdr.asc == 0x04) 339 if (sshdr.sense_key == NOT_READY && sshdr.asc == 0x04)
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 9c73dbda3bbb..606215e54b88 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -572,7 +572,7 @@ stex_slave_destroy(struct scsi_device *sdev)
572} 572}
573 573
574static int 574static int
575stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *)) 575stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
576{ 576{
577 struct st_hba *hba; 577 struct st_hba *hba;
578 struct Scsi_Host *host; 578 struct Scsi_Host *host;
@@ -698,6 +698,8 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
698 return 0; 698 return 0;
699} 699}
700 700
701static DEF_SCSI_QCMD(stex_queuecommand)
702
701static void stex_scsi_done(struct st_ccb *ccb) 703static void stex_scsi_done(struct st_ccb *ccb)
702{ 704{
703 struct scsi_cmnd *cmd = ccb->cmd; 705 struct scsi_cmnd *cmd = ccb->cmd;
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index 713620ed70d9..4f0e5485ffde 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -908,7 +908,7 @@ static int NCR5380_init (struct Scsi_Host *instance, int flags)
908 */ 908 */
909 909
910/* Only make static if a wrapper function is used */ 910/* Only make static if a wrapper function is used */
911static int NCR5380_queue_command(struct scsi_cmnd *cmd, 911static int NCR5380_queue_command_lck(struct scsi_cmnd *cmd,
912 void (*done)(struct scsi_cmnd *)) 912 void (*done)(struct scsi_cmnd *))
913{ 913{
914 SETUP_HOSTDATA(cmd->device->host); 914 SETUP_HOSTDATA(cmd->device->host);
@@ -1019,6 +1019,8 @@ static int NCR5380_queue_command(struct scsi_cmnd *cmd,
1019 return 0; 1019 return 0;
1020} 1020}
1021 1021
1022static DEF_SCSI_QCMD(NCR5380_queue_command)
1023
1022/* 1024/*
1023 * Function : NCR5380_main (void) 1025 * Function : NCR5380_main (void)
1024 * 1026 *
diff --git a/drivers/scsi/sun3_scsi.h b/drivers/scsi/sun3_scsi.h
index b29a9d661ca4..bcefd8458e65 100644
--- a/drivers/scsi/sun3_scsi.h
+++ b/drivers/scsi/sun3_scsi.h
@@ -51,8 +51,7 @@ static int sun3scsi_abort(struct scsi_cmnd *);
51static int sun3scsi_detect (struct scsi_host_template *); 51static int sun3scsi_detect (struct scsi_host_template *);
52static const char *sun3scsi_info (struct Scsi_Host *); 52static const char *sun3scsi_info (struct Scsi_Host *);
53static int sun3scsi_bus_reset(struct scsi_cmnd *); 53static int sun3scsi_bus_reset(struct scsi_cmnd *);
54static int sun3scsi_queue_command(struct scsi_cmnd *, 54static int sun3scsi_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
55 void (*done)(struct scsi_cmnd *));
56static int sun3scsi_release (struct Scsi_Host *); 55static int sun3scsi_release (struct Scsi_Host *);
57 56
58#ifndef CMD_PER_LUN 57#ifndef CMD_PER_LUN
diff --git a/drivers/scsi/sym53c416.c b/drivers/scsi/sym53c416.c
index e5c369bb568f..190107ae120b 100644
--- a/drivers/scsi/sym53c416.c
+++ b/drivers/scsi/sym53c416.c
@@ -734,7 +734,7 @@ const char *sym53c416_info(struct Scsi_Host *SChost)
734 return info; 734 return info;
735} 735}
736 736
737int sym53c416_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) 737static int sym53c416_queuecommand_lck(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
738{ 738{
739 int base; 739 int base;
740 unsigned long flags = 0; 740 unsigned long flags = 0;
@@ -761,6 +761,8 @@ int sym53c416_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
761 return 0; 761 return 0;
762} 762}
763 763
764DEF_SCSI_QCMD(sym53c416_queuecommand)
765
764static int sym53c416_host_reset(Scsi_Cmnd *SCpnt) 766static int sym53c416_host_reset(Scsi_Cmnd *SCpnt)
765{ 767{
766 int base; 768 int base;
diff --git a/drivers/scsi/sym53c416.h b/drivers/scsi/sym53c416.h
index 77860d0748ff..387de5d80a70 100644
--- a/drivers/scsi/sym53c416.h
+++ b/drivers/scsi/sym53c416.h
@@ -25,7 +25,7 @@
25static int sym53c416_detect(struct scsi_host_template *); 25static int sym53c416_detect(struct scsi_host_template *);
26static const char *sym53c416_info(struct Scsi_Host *); 26static const char *sym53c416_info(struct Scsi_Host *);
27static int sym53c416_release(struct Scsi_Host *); 27static int sym53c416_release(struct Scsi_Host *);
28static int sym53c416_queuecommand(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *)); 28static int sym53c416_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
29static int sym53c416_host_reset(Scsi_Cmnd *); 29static int sym53c416_host_reset(Scsi_Cmnd *);
30static int sym53c416_bios_param(struct scsi_device *, struct block_device *, 30static int sym53c416_bios_param(struct scsi_device *, struct block_device *,
31 sector_t, int *); 31 sector_t, int *);
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 4afa81ad2caa..b4543f575f46 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -505,7 +505,7 @@ void sym_log_bus_error(struct Scsi_Host *shost)
505 * queuecommand method. Entered with the host adapter lock held and 505 * queuecommand method. Entered with the host adapter lock held and
506 * interrupts disabled. 506 * interrupts disabled.
507 */ 507 */
508static int sym53c8xx_queue_command(struct scsi_cmnd *cmd, 508static int sym53c8xx_queue_command_lck(struct scsi_cmnd *cmd,
509 void (*done)(struct scsi_cmnd *)) 509 void (*done)(struct scsi_cmnd *))
510{ 510{
511 struct sym_hcb *np = SYM_SOFTC_PTR(cmd); 511 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
@@ -536,6 +536,8 @@ static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
536 return 0; 536 return 0;
537} 537}
538 538
539static DEF_SCSI_QCMD(sym53c8xx_queue_command)
540
539/* 541/*
540 * Linux entry point of the interrupt handler. 542 * Linux entry point of the interrupt handler.
541 */ 543 */
diff --git a/drivers/scsi/t128.h b/drivers/scsi/t128.h
index 76a069b7ac0b..ada1115079c9 100644
--- a/drivers/scsi/t128.h
+++ b/drivers/scsi/t128.h
@@ -96,8 +96,7 @@ static int t128_abort(struct scsi_cmnd *);
96static int t128_biosparam(struct scsi_device *, struct block_device *, 96static int t128_biosparam(struct scsi_device *, struct block_device *,
97 sector_t, int*); 97 sector_t, int*);
98static int t128_detect(struct scsi_host_template *); 98static int t128_detect(struct scsi_host_template *);
99static int t128_queue_command(struct scsi_cmnd *, 99static int t128_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
100 void (*done)(struct scsi_cmnd *));
101static int t128_bus_reset(struct scsi_cmnd *); 100static int t128_bus_reset(struct scsi_cmnd *);
102 101
103#ifndef CMD_PER_LUN 102#ifndef CMD_PER_LUN
diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c
index 27866b0adfeb..a124a28f2ccb 100644
--- a/drivers/scsi/tmscsim.c
+++ b/drivers/scsi/tmscsim.c
@@ -1883,7 +1883,7 @@ dc390_ScsiRstDetect( struct dc390_acb* pACB )
1883 return; 1883 return;
1884} 1884}
1885 1885
1886static int DC390_queuecommand(struct scsi_cmnd *cmd, 1886static int DC390_queuecommand_lck(struct scsi_cmnd *cmd,
1887 void (*done)(struct scsi_cmnd *)) 1887 void (*done)(struct scsi_cmnd *))
1888{ 1888{
1889 struct scsi_device *sdev = cmd->device; 1889 struct scsi_device *sdev = cmd->device;
@@ -1944,6 +1944,8 @@ static int DC390_queuecommand(struct scsi_cmnd *cmd,
1944 return SCSI_MLQUEUE_DEVICE_BUSY; 1944 return SCSI_MLQUEUE_DEVICE_BUSY;
1945} 1945}
1946 1946
1947static DEF_SCSI_QCMD(DC390_queuecommand)
1948
1947static void dc390_dumpinfo (struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB) 1949static void dc390_dumpinfo (struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
1948{ 1950{
1949 struct pci_dev *pdev; 1951 struct pci_dev *pdev;
diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index 5d9fdeeb2315..edfc5da8be4c 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -433,7 +433,7 @@
433 433
434static int u14_34f_detect(struct scsi_host_template *); 434static int u14_34f_detect(struct scsi_host_template *);
435static int u14_34f_release(struct Scsi_Host *); 435static int u14_34f_release(struct Scsi_Host *);
436static int u14_34f_queuecommand(struct scsi_cmnd *, void (*done)(struct scsi_cmnd *)); 436static int u14_34f_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
437static int u14_34f_eh_abort(struct scsi_cmnd *); 437static int u14_34f_eh_abort(struct scsi_cmnd *);
438static int u14_34f_eh_host_reset(struct scsi_cmnd *); 438static int u14_34f_eh_host_reset(struct scsi_cmnd *);
439static int u14_34f_bios_param(struct scsi_device *, struct block_device *, 439static int u14_34f_bios_param(struct scsi_device *, struct block_device *,
@@ -1248,7 +1248,7 @@ static void scsi_to_dev_dir(unsigned int i, unsigned int j) {
1248 1248
1249} 1249}
1250 1250
1251static int u14_34f_queuecommand(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) { 1251static int u14_34f_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) {
1252 unsigned int i, j, k; 1252 unsigned int i, j, k;
1253 struct mscp *cpp; 1253 struct mscp *cpp;
1254 1254
@@ -1329,6 +1329,8 @@ static int u14_34f_queuecommand(struct scsi_cmnd *SCpnt, void (*done)(struct scs
1329 return 0; 1329 return 0;
1330} 1330}
1331 1331
1332static DEF_SCSI_QCMD(u14_34f_queuecommand)
1333
1332static int u14_34f_eh_abort(struct scsi_cmnd *SCarg) { 1334static int u14_34f_eh_abort(struct scsi_cmnd *SCarg) {
1333 unsigned int i, j; 1335 unsigned int i, j;
1334 1336
diff --git a/drivers/scsi/ultrastor.c b/drivers/scsi/ultrastor.c
index 27aa40f3980e..0571ef9639cb 100644
--- a/drivers/scsi/ultrastor.c
+++ b/drivers/scsi/ultrastor.c
@@ -700,7 +700,7 @@ static inline void build_sg_list(struct mscp *mscp, struct scsi_cmnd *SCpnt)
700 mscp->transfer_data_length = transfer_length; 700 mscp->transfer_data_length = transfer_length;
701} 701}
702 702
703static int ultrastor_queuecommand(struct scsi_cmnd *SCpnt, 703static int ultrastor_queuecommand_lck(struct scsi_cmnd *SCpnt,
704 void (*done) (struct scsi_cmnd *)) 704 void (*done) (struct scsi_cmnd *))
705{ 705{
706 struct mscp *my_mscp; 706 struct mscp *my_mscp;
@@ -825,6 +825,8 @@ retry:
825 return 0; 825 return 0;
826} 826}
827 827
828static DEF_SCSI_QCMD(ultrastor_queuecommand)
829
828/* This code must deal with 2 cases: 830/* This code must deal with 2 cases:
829 831
830 1. The command has not been written to the OGM. In this case, set 832 1. The command has not been written to the OGM. In this case, set
diff --git a/drivers/scsi/ultrastor.h b/drivers/scsi/ultrastor.h
index a692905f95f7..165c18b5cf5f 100644
--- a/drivers/scsi/ultrastor.h
+++ b/drivers/scsi/ultrastor.h
@@ -15,8 +15,7 @@
15 15
16static int ultrastor_detect(struct scsi_host_template *); 16static int ultrastor_detect(struct scsi_host_template *);
17static const char *ultrastor_info(struct Scsi_Host *shpnt); 17static const char *ultrastor_info(struct Scsi_Host *shpnt);
18static int ultrastor_queuecommand(struct scsi_cmnd *, 18static int ultrastor_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
19 void (*done)(struct scsi_cmnd *));
20static int ultrastor_abort(struct scsi_cmnd *); 19static int ultrastor_abort(struct scsi_cmnd *);
21static int ultrastor_host_reset(struct scsi_cmnd *); 20static int ultrastor_host_reset(struct scsi_cmnd *);
22static int ultrastor_biosparam(struct scsi_device *, struct block_device *, 21static int ultrastor_biosparam(struct scsi_device *, struct block_device *,
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 26894459c37f..a18996d24466 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -690,7 +690,7 @@ static int pvscsi_queue_ring(struct pvscsi_adapter *adapter,
690 return 0; 690 return 0;
691} 691}
692 692
693static int pvscsi_queue(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 693static int pvscsi_queue_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
694{ 694{
695 struct Scsi_Host *host = cmd->device->host; 695 struct Scsi_Host *host = cmd->device->host;
696 struct pvscsi_adapter *adapter = shost_priv(host); 696 struct pvscsi_adapter *adapter = shost_priv(host);
@@ -719,6 +719,8 @@ static int pvscsi_queue(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
719 return 0; 719 return 0;
720} 720}
721 721
722static DEF_SCSI_QCMD(pvscsi_queue)
723
722static int pvscsi_abort(struct scsi_cmnd *cmd) 724static int pvscsi_abort(struct scsi_cmnd *cmd)
723{ 725{
724 struct pvscsi_adapter *adapter = shost_priv(cmd->device->host); 726 struct pvscsi_adapter *adapter = shost_priv(cmd->device->host);
diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index b701bf2cc187..5f697e0bd009 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -371,8 +371,8 @@ calc_sync_msg(unsigned int period, unsigned int offset, unsigned int fast,
371 msg[1] = offset; 371 msg[1] = offset;
372} 372}
373 373
374int 374static int
375wd33c93_queuecommand(struct scsi_cmnd *cmd, 375wd33c93_queuecommand_lck(struct scsi_cmnd *cmd,
376 void (*done)(struct scsi_cmnd *)) 376 void (*done)(struct scsi_cmnd *))
377{ 377{
378 struct WD33C93_hostdata *hostdata; 378 struct WD33C93_hostdata *hostdata;
@@ -468,6 +468,8 @@ wd33c93_queuecommand(struct scsi_cmnd *cmd,
468 return 0; 468 return 0;
469} 469}
470 470
471DEF_SCSI_QCMD(wd33c93_queuecommand)
472
471/* 473/*
472 * This routine attempts to start a scsi command. If the host_card is 474 * This routine attempts to start a scsi command. If the host_card is
473 * already connected, we give up immediately. Otherwise, look through 475 * already connected, we give up immediately. Otherwise, look through
diff --git a/drivers/scsi/wd33c93.h b/drivers/scsi/wd33c93.h
index 1ed5f3bf388e..3b463d7304dc 100644
--- a/drivers/scsi/wd33c93.h
+++ b/drivers/scsi/wd33c93.h
@@ -343,8 +343,7 @@ struct WD33C93_hostdata {
343void wd33c93_init (struct Scsi_Host *instance, const wd33c93_regs regs, 343void wd33c93_init (struct Scsi_Host *instance, const wd33c93_regs regs,
344 dma_setup_t setup, dma_stop_t stop, int clock_freq); 344 dma_setup_t setup, dma_stop_t stop, int clock_freq);
345int wd33c93_abort (struct scsi_cmnd *cmd); 345int wd33c93_abort (struct scsi_cmnd *cmd);
346int wd33c93_queuecommand (struct scsi_cmnd *cmd, 346int wd33c93_queuecommand (struct Scsi_Host *h, struct scsi_cmnd *cmd);
347 void (*done)(struct scsi_cmnd *));
348void wd33c93_intr (struct Scsi_Host *instance); 347void wd33c93_intr (struct Scsi_Host *instance);
349int wd33c93_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int); 348int wd33c93_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
350int wd33c93_host_reset (struct scsi_cmnd *); 349int wd33c93_host_reset (struct scsi_cmnd *);
diff --git a/drivers/scsi/wd7000.c b/drivers/scsi/wd7000.c
index 333580bf37c5..db451ae0a368 100644
--- a/drivers/scsi/wd7000.c
+++ b/drivers/scsi/wd7000.c
@@ -1082,7 +1082,7 @@ static irqreturn_t wd7000_intr(int irq, void *dev_id)
1082 return IRQ_HANDLED; 1082 return IRQ_HANDLED;
1083} 1083}
1084 1084
1085static int wd7000_queuecommand(struct scsi_cmnd *SCpnt, 1085static int wd7000_queuecommand_lck(struct scsi_cmnd *SCpnt,
1086 void (*done)(struct scsi_cmnd *)) 1086 void (*done)(struct scsi_cmnd *))
1087{ 1087{
1088 Scb *scb; 1088 Scb *scb;
@@ -1139,6 +1139,8 @@ static int wd7000_queuecommand(struct scsi_cmnd *SCpnt,
1139 return 0; 1139 return 0;
1140} 1140}
1141 1141
1142static DEF_SCSI_QCMD(wd7000_queuecommand)
1143
1142static int wd7000_diagnostics(Adapter * host, int code) 1144static int wd7000_diagnostics(Adapter * host, int code)
1143{ 1145{
1144 static IcbDiag icb = { ICB_OP_DIAGNOSTICS }; 1146 static IcbDiag icb = { ICB_OP_DIAGNOSTICS };
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 4d8e14b7aa93..09a550860dcf 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -2872,7 +2872,7 @@ static struct console serial8250_console = {
2872 .device = uart_console_device, 2872 .device = uart_console_device,
2873 .setup = serial8250_console_setup, 2873 .setup = serial8250_console_setup,
2874 .early_setup = serial8250_console_early_setup, 2874 .early_setup = serial8250_console_early_setup,
2875 .flags = CON_PRINTBUFFER, 2875 .flags = CON_PRINTBUFFER | CON_ANYTIME,
2876 .index = -1, 2876 .index = -1,
2877 .data = &serial8250_reg, 2877 .data = &serial8250_reg,
2878}; 2878};
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 53be4d35a0aa..842e3b2a02b1 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -2285,6 +2285,8 @@ static struct pciserial_board pci_boards[] __devinitdata = {
2285 2285
2286static const struct pci_device_id softmodem_blacklist[] = { 2286static const struct pci_device_id softmodem_blacklist[] = {
2287 { PCI_VDEVICE(AL, 0x5457), }, /* ALi Corporation M5457 AC'97 Modem */ 2287 { PCI_VDEVICE(AL, 0x5457), }, /* ALi Corporation M5457 AC'97 Modem */
2288 { PCI_VDEVICE(MOTOROLA, 0x3052), }, /* Motorola Si3052-based modem */
2289 { PCI_DEVICE(0x1543, 0x3052), }, /* Si3052-based modem, default IDs */
2288}; 2290};
2289 2291
2290/* 2292/*
@@ -2863,6 +2865,9 @@ static struct pci_device_id serial_pci_tbl[] = {
2863 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL, 2865 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL,
2864 0, 0, 2866 0, 0,
2865 pbn_b0_4_1152000 }, 2867 pbn_b0_4_1152000 },
2868 { PCI_VENDOR_ID_OXSEMI, 0x9505,
2869 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2870 pbn_b0_bt_2_921600 },
2866 2871
2867 /* 2872 /*
2868 * The below card is a little controversial since it is the 2873 * The below card is a little controversial since it is the
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index a9eff2b18eab..19cac9f610fd 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -23,6 +23,7 @@
23#include <linux/tty.h> 23#include <linux/tty.h>
24#include <linux/tty_flip.h> 24#include <linux/tty_flip.h>
25#include <linux/serial_core.h> 25#include <linux/serial_core.h>
26#include <linux/dma-mapping.h>
26 27
27#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ 28#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
28 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) 29 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
@@ -33,12 +34,10 @@
33#include <asm/gpio.h> 34#include <asm/gpio.h>
34#include <mach/bfin_serial_5xx.h> 35#include <mach/bfin_serial_5xx.h>
35 36
36#ifdef CONFIG_SERIAL_BFIN_DMA 37#include <asm/dma.h>
37#include <linux/dma-mapping.h>
38#include <asm/io.h> 38#include <asm/io.h>
39#include <asm/irq.h> 39#include <asm/irq.h>
40#include <asm/cacheflush.h> 40#include <asm/cacheflush.h>
41#endif
42 41
43#ifdef CONFIG_SERIAL_BFIN_MODULE 42#ifdef CONFIG_SERIAL_BFIN_MODULE
44# undef CONFIG_EARLY_PRINTK 43# undef CONFIG_EARLY_PRINTK
@@ -360,7 +359,6 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
360 UART_PUT_CHAR(uart, xmit->buf[xmit->tail]); 359 UART_PUT_CHAR(uart, xmit->buf[xmit->tail]);
361 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 360 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
362 uart->port.icount.tx++; 361 uart->port.icount.tx++;
363 SSYNC();
364 } 362 }
365 363
366 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 364 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
@@ -688,6 +686,13 @@ static int bfin_serial_startup(struct uart_port *port)
688 686
689# ifdef CONFIG_BF54x 687# ifdef CONFIG_BF54x
690 { 688 {
689 /*
690 * UART2 and UART3 on BF548 share interrupt PINs and DMA
691 * controllers with SPORT2 and SPORT3. UART rx and tx
692 * interrupts are generated in PIO mode only when configure
693 * their peripheral mapping registers properly, which means
694 * request corresponding DMA channels in PIO mode as well.
695 */
691 unsigned uart_dma_ch_rx, uart_dma_ch_tx; 696 unsigned uart_dma_ch_rx, uart_dma_ch_tx;
692 697
693 switch (uart->port.irq) { 698 switch (uart->port.irq) {
@@ -734,8 +739,7 @@ static int bfin_serial_startup(struct uart_port *port)
734 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | 739 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
735 IRQF_DISABLED, "BFIN_UART_CTS", uart)) { 740 IRQF_DISABLED, "BFIN_UART_CTS", uart)) {
736 uart->cts_pin = -1; 741 uart->cts_pin = -1;
737 pr_info("Unable to attach BlackFin UART CTS interrupt.\ 742 pr_info("Unable to attach BlackFin UART CTS interrupt. So, disable it.\n");
738 So, disable it.\n");
739 } 743 }
740 } 744 }
741 if (uart->rts_pin >= 0) { 745 if (uart->rts_pin >= 0) {
@@ -747,8 +751,7 @@ static int bfin_serial_startup(struct uart_port *port)
747 if (request_irq(uart->status_irq, 751 if (request_irq(uart->status_irq,
748 bfin_serial_mctrl_cts_int, 752 bfin_serial_mctrl_cts_int,
749 IRQF_DISABLED, "BFIN_UART_MODEM_STATUS", uart)) { 753 IRQF_DISABLED, "BFIN_UART_MODEM_STATUS", uart)) {
750 pr_info("Unable to attach BlackFin UART Modem \ 754 pr_info("Unable to attach BlackFin UART Modem Status interrupt.\n");
751 Status interrupt.\n");
752 } 755 }
753 756
754 /* CTS RTS PINs are negative assertive. */ 757 /* CTS RTS PINs are negative assertive. */
@@ -846,6 +849,8 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
846 if (termios->c_cflag & CMSPAR) 849 if (termios->c_cflag & CMSPAR)
847 lcr |= STP; 850 lcr |= STP;
848 851
852 spin_lock_irqsave(&uart->port.lock, flags);
853
849 port->read_status_mask = OE; 854 port->read_status_mask = OE;
850 if (termios->c_iflag & INPCK) 855 if (termios->c_iflag & INPCK)
851 port->read_status_mask |= (FE | PE); 856 port->read_status_mask |= (FE | PE);
@@ -875,8 +880,6 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
875 if (termios->c_line != N_IRDA) 880 if (termios->c_line != N_IRDA)
876 quot -= ANOMALY_05000230; 881 quot -= ANOMALY_05000230;
877 882
878 spin_lock_irqsave(&uart->port.lock, flags);
879
880 UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15); 883 UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15);
881 884
882 /* Disable UART */ 885 /* Disable UART */
@@ -1321,6 +1324,14 @@ struct console __init *bfin_earlyserial_init(unsigned int port,
1321 struct bfin_serial_port *uart; 1324 struct bfin_serial_port *uart;
1322 struct ktermios t; 1325 struct ktermios t;
1323 1326
1327#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1328 /*
1329 * If we are using early serial, don't let the normal console rewind
1330 * log buffer, since that causes things to be printed multiple times
1331 */
1332 bfin_serial_console.flags &= ~CON_PRINTBUFFER;
1333#endif
1334
1324 if (port == -1 || port >= nr_active_ports) 1335 if (port == -1 || port >= nr_active_ports)
1325 port = 0; 1336 port = 0;
1326 bfin_serial_init_ports(); 1337 bfin_serial_init_ports();
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index c856905bb3bd..bcc31f2140ac 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -18,7 +18,6 @@ static char *serial_version = "$Revision: 1.25 $";
18#include <linux/tty.h> 18#include <linux/tty.h>
19#include <linux/tty_flip.h> 19#include <linux/tty_flip.h>
20#include <linux/major.h> 20#include <linux/major.h>
21#include <linux/smp_lock.h>
22#include <linux/string.h> 21#include <linux/string.h>
23#include <linux/fcntl.h> 22#include <linux/fcntl.h>
24#include <linux/mm.h> 23#include <linux/mm.h>
@@ -1411,11 +1410,12 @@ e100_enable_rs485(struct tty_struct *tty, struct serial_rs485 *r)
1411 CONFIG_ETRAX_RS485_LTC1387_RXEN_PORT_G_BIT, 1); 1410 CONFIG_ETRAX_RS485_LTC1387_RXEN_PORT_G_BIT, 1);
1412#endif 1411#endif
1413 1412
1414 info->rs485.flags = r->flags; 1413 info->rs485 = *r;
1415 if (r->delay_rts_before_send >= 1000) 1414
1415 /* Maximum delay before RTS equal to 1000 */
1416 if (info->rs485.delay_rts_before_send >= 1000)
1416 info->rs485.delay_rts_before_send = 1000; 1417 info->rs485.delay_rts_before_send = 1000;
1417 else 1418
1418 info->rs485.delay_rts_before_send = r->delay_rts_before_send;
1419/* printk("rts: on send = %i, after = %i, enabled = %i", 1419/* printk("rts: on send = %i, after = %i, enabled = %i",
1420 info->rs485.rts_on_send, 1420 info->rs485.rts_on_send,
1421 info->rs485.rts_after_sent, 1421 info->rs485.rts_after_sent,
@@ -3234,9 +3234,9 @@ rs_write(struct tty_struct *tty,
3234 e100_disable_rx(info); 3234 e100_disable_rx(info);
3235 e100_enable_rx_irq(info); 3235 e100_enable_rx_irq(info);
3236#endif 3236#endif
3237 3237 if ((info->rs485.flags & SER_RS485_RTS_BEFORE_SEND) &&
3238 if (info->rs485.delay_rts_before_send > 0) 3238 (info->rs485.delay_rts_before_send > 0))
3239 msleep(info->rs485.delay_rts_before_send); 3239 msleep(info->rs485.delay_rts_before_send);
3240 } 3240 }
3241#endif /* CONFIG_ETRAX_RS485 */ 3241#endif /* CONFIG_ETRAX_RS485 */
3242 3242
@@ -3694,6 +3694,11 @@ rs_ioctl(struct tty_struct *tty, struct file * file,
3694 3694
3695 rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send; 3695 rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send;
3696 rs485data.flags = 0; 3696 rs485data.flags = 0;
3697 if (rs485data.delay_rts_before_send != 0)
3698 rs485data.flags |= SER_RS485_RTS_BEFORE_SEND;
3699 else
3700 rs485data.flags &= ~(SER_RS485_RTS_BEFORE_SEND);
3701
3697 if (rs485ctrl.enabled) 3702 if (rs485ctrl.enabled)
3698 rs485data.flags |= SER_RS485_ENABLED; 3703 rs485data.flags |= SER_RS485_ENABLED;
3699 else 3704 else
@@ -3731,7 +3736,7 @@ rs_ioctl(struct tty_struct *tty, struct file * file,
3731 /* This is the ioctl to get RS485 data from user-space */ 3736 /* This is the ioctl to get RS485 data from user-space */
3732 if (copy_to_user((struct serial_rs485 *) arg, 3737 if (copy_to_user((struct serial_rs485 *) arg,
3733 rs485data, 3738 rs485data,
3734 sizeof(serial_rs485))) 3739 sizeof(struct serial_rs485)))
3735 return -EFAULT; 3740 return -EFAULT;
3736 break; 3741 break;
3737 } 3742 }
@@ -4527,6 +4532,7 @@ static int __init rs_init(void)
4527 /* Set sane defaults */ 4532 /* Set sane defaults */
4528 info->rs485.flags &= ~(SER_RS485_RTS_ON_SEND); 4533 info->rs485.flags &= ~(SER_RS485_RTS_ON_SEND);
4529 info->rs485.flags |= SER_RS485_RTS_AFTER_SEND; 4534 info->rs485.flags |= SER_RS485_RTS_AFTER_SEND;
4535 info->rs485.flags &= ~(SER_RS485_RTS_BEFORE_SEND);
4530 info->rs485.delay_rts_before_send = 0; 4536 info->rs485.delay_rts_before_send = 0;
4531 info->rs485.flags &= ~(SER_RS485_ENABLED); 4537 info->rs485.flags &= ~(SER_RS485_ENABLED);
4532#endif 4538#endif
diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
index d4b711c9a416..25a8bc565f40 100644
--- a/drivers/serial/kgdboc.c
+++ b/drivers/serial/kgdboc.c
@@ -18,6 +18,7 @@
18#include <linux/tty.h> 18#include <linux/tty.h>
19#include <linux/console.h> 19#include <linux/console.h>
20#include <linux/vt_kern.h> 20#include <linux/vt_kern.h>
21#include <linux/input.h>
21 22
22#define MAX_CONFIG_LEN 40 23#define MAX_CONFIG_LEN 40
23 24
@@ -37,6 +38,62 @@ static struct tty_driver *kgdb_tty_driver;
37static int kgdb_tty_line; 38static int kgdb_tty_line;
38 39
39#ifdef CONFIG_KDB_KEYBOARD 40#ifdef CONFIG_KDB_KEYBOARD
41static int kgdboc_reset_connect(struct input_handler *handler,
42 struct input_dev *dev,
43 const struct input_device_id *id)
44{
45 input_reset_device(dev);
46
47 /* Retrun an error - we do not want to bind, just to reset */
48 return -ENODEV;
49}
50
51static void kgdboc_reset_disconnect(struct input_handle *handle)
52{
53 /* We do not expect anyone to actually bind to us */
54 BUG();
55}
56
57static const struct input_device_id kgdboc_reset_ids[] = {
58 {
59 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
60 .evbit = { BIT_MASK(EV_KEY) },
61 },
62 { }
63};
64
65static struct input_handler kgdboc_reset_handler = {
66 .connect = kgdboc_reset_connect,
67 .disconnect = kgdboc_reset_disconnect,
68 .name = "kgdboc_reset",
69 .id_table = kgdboc_reset_ids,
70};
71
72static DEFINE_MUTEX(kgdboc_reset_mutex);
73
74static void kgdboc_restore_input_helper(struct work_struct *dummy)
75{
76 /*
77 * We need to take a mutex to prevent several instances of
78 * this work running on different CPUs so they don't try
79 * to register again already registered handler.
80 */
81 mutex_lock(&kgdboc_reset_mutex);
82
83 if (input_register_handler(&kgdboc_reset_handler) == 0)
84 input_unregister_handler(&kgdboc_reset_handler);
85
86 mutex_unlock(&kgdboc_reset_mutex);
87}
88
89static DECLARE_WORK(kgdboc_restore_input_work, kgdboc_restore_input_helper);
90
91static void kgdboc_restore_input(void)
92{
93 if (likely(system_state == SYSTEM_RUNNING))
94 schedule_work(&kgdboc_restore_input_work);
95}
96
40static int kgdboc_register_kbd(char **cptr) 97static int kgdboc_register_kbd(char **cptr)
41{ 98{
42 if (strncmp(*cptr, "kbd", 3) == 0) { 99 if (strncmp(*cptr, "kbd", 3) == 0) {
@@ -64,10 +121,12 @@ static void kgdboc_unregister_kbd(void)
64 i--; 121 i--;
65 } 122 }
66 } 123 }
124 flush_work_sync(&kgdboc_restore_input_work);
67} 125}
68#else /* ! CONFIG_KDB_KEYBOARD */ 126#else /* ! CONFIG_KDB_KEYBOARD */
69#define kgdboc_register_kbd(x) 0 127#define kgdboc_register_kbd(x) 0
70#define kgdboc_unregister_kbd() 128#define kgdboc_unregister_kbd()
129#define kgdboc_restore_input()
71#endif /* ! CONFIG_KDB_KEYBOARD */ 130#endif /* ! CONFIG_KDB_KEYBOARD */
72 131
73static int kgdboc_option_setup(char *opt) 132static int kgdboc_option_setup(char *opt)
@@ -231,6 +290,7 @@ static void kgdboc_post_exp_handler(void)
231 dbg_restore_graphics = 0; 290 dbg_restore_graphics = 0;
232 con_debug_leave(); 291 con_debug_leave();
233 } 292 }
293 kgdboc_restore_input();
234} 294}
235 295
236static struct kgdb_io kgdboc_io_ops = { 296static struct kgdb_io kgdboc_io_ops = {
diff --git a/drivers/serial/mfd.c b/drivers/serial/mfd.c
index 5fc699e929dc..d40010a22ecd 100644
--- a/drivers/serial/mfd.c
+++ b/drivers/serial/mfd.c
@@ -900,8 +900,7 @@ serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,
900 unsigned char cval, fcr = 0; 900 unsigned char cval, fcr = 0;
901 unsigned long flags; 901 unsigned long flags;
902 unsigned int baud, quot; 902 unsigned int baud, quot;
903 u32 mul = 0x3600; 903 u32 ps, mul;
904 u32 ps = 0x10;
905 904
906 switch (termios->c_cflag & CSIZE) { 905 switch (termios->c_cflag & CSIZE) {
907 case CS5: 906 case CS5:
@@ -943,31 +942,24 @@ serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,
943 baud = uart_get_baud_rate(port, termios, old, 0, 4000000); 942 baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
944 943
945 quot = 1; 944 quot = 1;
945 ps = 0x10;
946 mul = 0x3600;
946 switch (baud) { 947 switch (baud) {
947 case 3500000: 948 case 3500000:
948 mul = 0x3345; 949 mul = 0x3345;
949 ps = 0xC; 950 ps = 0xC;
950 break; 951 break;
951 case 3000000:
952 mul = 0x2EE0;
953 break;
954 case 2500000:
955 mul = 0x2710;
956 break;
957 case 2000000:
958 mul = 0x1F40;
959 break;
960 case 1843200: 952 case 1843200:
961 mul = 0x2400; 953 mul = 0x2400;
962 break; 954 break;
955 case 3000000:
956 case 2500000:
957 case 2000000:
963 case 1500000: 958 case 1500000:
964 mul = 0x1770;
965 break;
966 case 1000000: 959 case 1000000:
967 mul = 0xFA0;
968 break;
969 case 500000: 960 case 500000:
970 mul = 0x7D0; 961 /* mul/ps/quot = 0x9C4/0x10/0x1 will make a 500000 bps */
962 mul = baud / 500000 * 0x9C4;
971 break; 963 break;
972 default: 964 default:
973 /* Use uart_get_divisor to get quot for other baud rates */ 965 /* Use uart_get_divisor to get quot for other baud rates */
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index c4ea14670d44..9ffa5bee44ab 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -29,7 +29,6 @@
29#include <linux/console.h> 29#include <linux/console.h>
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/smp_lock.h>
33#include <linux/device.h> 32#include <linux/device.h>
34#include <linux/serial.h> /* for serial_state and serial_icounter_struct */ 33#include <linux/serial.h> /* for serial_state and serial_icounter_struct */
35#include <linux/serial_core.h> 34#include <linux/serial_core.h>
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index fd0d1b98901c..3f5e387ed564 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -90,8 +90,8 @@ struct clk_rate_round_data {
90static long clk_rate_round_helper(struct clk_rate_round_data *rounder) 90static long clk_rate_round_helper(struct clk_rate_round_data *rounder)
91{ 91{
92 unsigned long rate_error, rate_error_prev = ~0UL; 92 unsigned long rate_error, rate_error_prev = ~0UL;
93 unsigned long rate_best_fit = rounder->rate;
94 unsigned long highest, lowest, freq; 93 unsigned long highest, lowest, freq;
94 long rate_best_fit = -ENOENT;
95 int i; 95 int i;
96 96
97 highest = 0; 97 highest = 0;
@@ -146,7 +146,7 @@ long clk_rate_table_round(struct clk *clk,
146 }; 146 };
147 147
148 if (clk->nr_freqs < 1) 148 if (clk->nr_freqs < 1)
149 return 0; 149 return -ENOSYS;
150 150
151 return clk_rate_round_helper(&table_round); 151 return clk_rate_round_helper(&table_round);
152} 152}
@@ -418,8 +418,11 @@ int clk_register(struct clk *clk)
418 list_add(&clk->sibling, &root_clks); 418 list_add(&clk->sibling, &root_clks);
419 419
420 list_add(&clk->node, &clock_list); 420 list_add(&clk->node, &clock_list);
421
422#ifdef CONFIG_SH_CLK_CPG_LEGACY
421 if (clk->ops && clk->ops->init) 423 if (clk->ops && clk->ops->init)
422 clk->ops->init(clk); 424 clk->ops->init(clk);
425#endif
423 426
424out_unlock: 427out_unlock:
425 mutex_unlock(&clock_list_sem); 428 mutex_unlock(&clock_list_sem);
@@ -455,19 +458,13 @@ EXPORT_SYMBOL_GPL(clk_get_rate);
455 458
456int clk_set_rate(struct clk *clk, unsigned long rate) 459int clk_set_rate(struct clk *clk, unsigned long rate)
457{ 460{
458 return clk_set_rate_ex(clk, rate, 0);
459}
460EXPORT_SYMBOL_GPL(clk_set_rate);
461
462int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id)
463{
464 int ret = -EOPNOTSUPP; 461 int ret = -EOPNOTSUPP;
465 unsigned long flags; 462 unsigned long flags;
466 463
467 spin_lock_irqsave(&clock_lock, flags); 464 spin_lock_irqsave(&clock_lock, flags);
468 465
469 if (likely(clk->ops && clk->ops->set_rate)) { 466 if (likely(clk->ops && clk->ops->set_rate)) {
470 ret = clk->ops->set_rate(clk, rate, algo_id); 467 ret = clk->ops->set_rate(clk, rate);
471 if (ret != 0) 468 if (ret != 0)
472 goto out_unlock; 469 goto out_unlock;
473 } else { 470 } else {
@@ -485,7 +482,7 @@ out_unlock:
485 482
486 return ret; 483 return ret;
487} 484}
488EXPORT_SYMBOL_GPL(clk_set_rate_ex); 485EXPORT_SYMBOL_GPL(clk_set_rate);
489 486
490int clk_set_parent(struct clk *clk, struct clk *parent) 487int clk_set_parent(struct clk *clk, struct clk *parent)
491{ 488{
@@ -541,6 +538,98 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
541} 538}
542EXPORT_SYMBOL_GPL(clk_round_rate); 539EXPORT_SYMBOL_GPL(clk_round_rate);
543 540
541long clk_round_parent(struct clk *clk, unsigned long target,
542 unsigned long *best_freq, unsigned long *parent_freq,
543 unsigned int div_min, unsigned int div_max)
544{
545 struct cpufreq_frequency_table *freq, *best = NULL;
546 unsigned long error = ULONG_MAX, freq_high, freq_low, div;
547 struct clk *parent = clk_get_parent(clk);
548
549 if (!parent) {
550 *parent_freq = 0;
551 *best_freq = clk_round_rate(clk, target);
552 return abs(target - *best_freq);
553 }
554
555 for (freq = parent->freq_table; freq->frequency != CPUFREQ_TABLE_END;
556 freq++) {
557 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
558 continue;
559
560 if (unlikely(freq->frequency / target <= div_min - 1)) {
561 unsigned long freq_max;
562
563 freq_max = (freq->frequency + div_min / 2) / div_min;
564 if (error > target - freq_max) {
565 error = target - freq_max;
566 best = freq;
567 if (best_freq)
568 *best_freq = freq_max;
569 }
570
571 pr_debug("too low freq %u, error %lu\n", freq->frequency,
572 target - freq_max);
573
574 if (!error)
575 break;
576
577 continue;
578 }
579
580 if (unlikely(freq->frequency / target >= div_max)) {
581 unsigned long freq_min;
582
583 freq_min = (freq->frequency + div_max / 2) / div_max;
584 if (error > freq_min - target) {
585 error = freq_min - target;
586 best = freq;
587 if (best_freq)
588 *best_freq = freq_min;
589 }
590
591 pr_debug("too high freq %u, error %lu\n", freq->frequency,
592 freq_min - target);
593
594 if (!error)
595 break;
596
597 continue;
598 }
599
600 div = freq->frequency / target;
601 freq_high = freq->frequency / div;
602 freq_low = freq->frequency / (div + 1);
603
604 if (freq_high - target < error) {
605 error = freq_high - target;
606 best = freq;
607 if (best_freq)
608 *best_freq = freq_high;
609 }
610
611 if (target - freq_low < error) {
612 error = target - freq_low;
613 best = freq;
614 if (best_freq)
615 *best_freq = freq_low;
616 }
617
618 pr_debug("%u / %lu = %lu, / %lu = %lu, best %lu, parent %u\n",
619 freq->frequency, div, freq_high, div + 1, freq_low,
620 *best_freq, best->frequency);
621
622 if (!error)
623 break;
624 }
625
626 if (parent_freq)
627 *parent_freq = best->frequency;
628
629 return error;
630}
631EXPORT_SYMBOL_GPL(clk_round_parent);
632
544#ifdef CONFIG_PM 633#ifdef CONFIG_PM
545static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state) 634static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state)
546{ 635{
@@ -561,8 +650,7 @@ static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state)
561 clkp->ops->set_parent(clkp, 650 clkp->ops->set_parent(clkp,
562 clkp->parent); 651 clkp->parent);
563 if (likely(clkp->ops->set_rate)) 652 if (likely(clkp->ops->set_rate))
564 clkp->ops->set_rate(clkp, 653 clkp->ops->set_rate(clkp, rate);
565 rate, NO_CHANGE);
566 else if (likely(clkp->ops->recalc)) 654 else if (likely(clkp->ops->recalc))
567 clkp->rate = clkp->ops->recalc(clkp); 655 clkp->rate = clkp->ops->recalc(clkp);
568 } 656 }
diff --git a/drivers/sh/clk/cpg.c b/drivers/sh/clk/cpg.c
index 3aea5f0ceb09..6172335ae323 100644
--- a/drivers/sh/clk/cpg.c
+++ b/drivers/sh/clk/cpg.c
@@ -110,8 +110,7 @@ static int sh_clk_div6_set_parent(struct clk *clk, struct clk *parent)
110 return 0; 110 return 0;
111} 111}
112 112
113static int sh_clk_div6_set_rate(struct clk *clk, 113static int sh_clk_div6_set_rate(struct clk *clk, unsigned long rate)
114 unsigned long rate, int algo_id)
115{ 114{
116 unsigned long value; 115 unsigned long value;
117 int idx; 116 int idx;
@@ -132,7 +131,7 @@ static int sh_clk_div6_enable(struct clk *clk)
132 unsigned long value; 131 unsigned long value;
133 int ret; 132 int ret;
134 133
135 ret = sh_clk_div6_set_rate(clk, clk->rate, 0); 134 ret = sh_clk_div6_set_rate(clk, clk->rate);
136 if (ret == 0) { 135 if (ret == 0) {
137 value = __raw_readl(clk->enable_reg); 136 value = __raw_readl(clk->enable_reg);
138 value &= ~0x100; /* clear stop bit to enable clock */ 137 value &= ~0x100; /* clear stop bit to enable clock */
@@ -253,7 +252,7 @@ static int sh_clk_div4_set_parent(struct clk *clk, struct clk *parent)
253 return 0; 252 return 0;
254} 253}
255 254
256static int sh_clk_div4_set_rate(struct clk *clk, unsigned long rate, int algo_id) 255static int sh_clk_div4_set_rate(struct clk *clk, unsigned long rate)
257{ 256{
258 struct clk_div4_table *d4t = clk->priv; 257 struct clk_div4_table *d4t = clk->priv;
259 unsigned long value; 258 unsigned long value;
diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c
index 873a99ff8f64..e5e9e6735f7d 100644
--- a/drivers/sh/intc/core.c
+++ b/drivers/sh/intc/core.c
@@ -79,7 +79,7 @@ static void __init intc_register_irq(struct intc_desc *desc,
79 * Register the IRQ position with the global IRQ map, then insert 79 * Register the IRQ position with the global IRQ map, then insert
80 * it in to the radix tree. 80 * it in to the radix tree.
81 */ 81 */
82 irq_reserve_irqs(irq, 1); 82 irq_reserve_irq(irq);
83 83
84 raw_spin_lock_irqsave(&intc_big_lock, flags); 84 raw_spin_lock_irqsave(&intc_big_lock, flags);
85 radix_tree_insert(&d->tree, enum_id, intc_irq_xlate_get(irq)); 85 radix_tree_insert(&d->tree, enum_id, intc_irq_xlate_get(irq));
diff --git a/drivers/sh/intc/dynamic.c b/drivers/sh/intc/dynamic.c
index 4187cce20ffd..a3677c9dfe36 100644
--- a/drivers/sh/intc/dynamic.c
+++ b/drivers/sh/intc/dynamic.c
@@ -60,5 +60,5 @@ void reserve_intc_vectors(struct intc_vect *vectors, unsigned int nr_vecs)
60 int i; 60 int i;
61 61
62 for (i = 0; i < nr_vecs; i++) 62 for (i = 0; i < nr_vecs; i++)
63 irq_reserve_irqs(evt2irq(vectors[i].vect), 1); 63 irq_reserve_irq(evt2irq(vectors[i].vect));
64} 64}
diff --git a/drivers/sh/intc/virq.c b/drivers/sh/intc/virq.c
index e5bf5d3c698e..4e0ff7181164 100644
--- a/drivers/sh/intc/virq.c
+++ b/drivers/sh/intc/virq.c
@@ -215,7 +215,7 @@ restart:
215 entry = radix_tree_deref_slot((void **)entries[i]); 215 entry = radix_tree_deref_slot((void **)entries[i]);
216 if (unlikely(!entry)) 216 if (unlikely(!entry))
217 continue; 217 continue;
218 if (unlikely(entry == RADIX_TREE_RETRY)) 218 if (radix_tree_deref_retry(entry))
219 goto restart; 219 goto restart;
220 220
221 irq = create_irq(); 221 irq = create_irq();
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 49596a18f953..1a478bf88c9d 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -352,8 +352,12 @@ atmel_spi_dma_map_xfer(struct atmel_spi *as, struct spi_transfer *xfer)
352 352
353 xfer->tx_dma = xfer->rx_dma = INVALID_DMA_ADDRESS; 353 xfer->tx_dma = xfer->rx_dma = INVALID_DMA_ADDRESS;
354 if (xfer->tx_buf) { 354 if (xfer->tx_buf) {
355 /* tx_buf is a const void* where we need a void * for the dma
356 * mapping */
357 void *nonconst_tx = (void *)xfer->tx_buf;
358
355 xfer->tx_dma = dma_map_single(dev, 359 xfer->tx_dma = dma_map_single(dev,
356 (void *) xfer->tx_buf, xfer->len, 360 nonconst_tx, xfer->len,
357 DMA_TO_DEVICE); 361 DMA_TO_DEVICE);
358 if (dma_mapping_error(dev, xfer->tx_dma)) 362 if (dma_mapping_error(dev, xfer->tx_dma))
359 return -ENOMEM; 363 return -ENOMEM;
diff --git a/drivers/spi/dw_spi.c b/drivers/spi/dw_spi.c
index 90439314cf67..0838c79861e4 100644
--- a/drivers/spi/dw_spi.c
+++ b/drivers/spi/dw_spi.c
@@ -413,6 +413,11 @@ static void poll_transfer(struct dw_spi *dws)
413{ 413{
414 while (dws->write(dws)) 414 while (dws->write(dws))
415 dws->read(dws); 415 dws->read(dws);
416 /*
417 * There is a possibility that the last word of a transaction
418 * will be lost if data is not ready. Re-read to solve this issue.
419 */
420 dws->read(dws);
416 421
417 transfer_complete(dws); 422 transfer_complete(dws);
418} 423}
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b5a78a1f4421..709c836607de 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -29,11 +29,6 @@
29#include <linux/spi/spi.h> 29#include <linux/spi/spi.h>
30#include <linux/of_spi.h> 30#include <linux/of_spi.h>
31 31
32
33/* SPI bustype and spi_master class are registered after board init code
34 * provides the SPI device tables, ensuring that both are present by the
35 * time controller driver registration causes spi_devices to "enumerate".
36 */
37static void spidev_release(struct device *dev) 32static void spidev_release(struct device *dev)
38{ 33{
39 struct spi_device *spi = to_spi_device(dev); 34 struct spi_device *spi = to_spi_device(dev);
@@ -202,11 +197,16 @@ EXPORT_SYMBOL_GPL(spi_register_driver);
202 197
203struct boardinfo { 198struct boardinfo {
204 struct list_head list; 199 struct list_head list;
205 unsigned n_board_info; 200 struct spi_board_info board_info;
206 struct spi_board_info board_info[0];
207}; 201};
208 202
209static LIST_HEAD(board_list); 203static LIST_HEAD(board_list);
204static LIST_HEAD(spi_master_list);
205
206/*
207 * Used to protect add/del opertion for board_info list and
208 * spi_master list, and their matching process
209 */
210static DEFINE_MUTEX(board_lock); 210static DEFINE_MUTEX(board_lock);
211 211
212/** 212/**
@@ -300,16 +300,16 @@ int spi_add_device(struct spi_device *spi)
300 */ 300 */
301 status = spi_setup(spi); 301 status = spi_setup(spi);
302 if (status < 0) { 302 if (status < 0) {
303 dev_err(dev, "can't %s %s, status %d\n", 303 dev_err(dev, "can't setup %s, status %d\n",
304 "setup", dev_name(&spi->dev), status); 304 dev_name(&spi->dev), status);
305 goto done; 305 goto done;
306 } 306 }
307 307
308 /* Device may be bound to an active driver when this returns */ 308 /* Device may be bound to an active driver when this returns */
309 status = device_add(&spi->dev); 309 status = device_add(&spi->dev);
310 if (status < 0) 310 if (status < 0)
311 dev_err(dev, "can't %s %s, status %d\n", 311 dev_err(dev, "can't add %s, status %d\n",
312 "add", dev_name(&spi->dev), status); 312 dev_name(&spi->dev), status);
313 else 313 else
314 dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev)); 314 dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev));
315 315
@@ -371,6 +371,20 @@ struct spi_device *spi_new_device(struct spi_master *master,
371} 371}
372EXPORT_SYMBOL_GPL(spi_new_device); 372EXPORT_SYMBOL_GPL(spi_new_device);
373 373
374static void spi_match_master_to_boardinfo(struct spi_master *master,
375 struct spi_board_info *bi)
376{
377 struct spi_device *dev;
378
379 if (master->bus_num != bi->bus_num)
380 return;
381
382 dev = spi_new_device(master, bi);
383 if (!dev)
384 dev_err(master->dev.parent, "can't create new device for %s\n",
385 bi->modalias);
386}
387
374/** 388/**
375 * spi_register_board_info - register SPI devices for a given board 389 * spi_register_board_info - register SPI devices for a given board
376 * @info: array of chip descriptors 390 * @info: array of chip descriptors
@@ -393,43 +407,25 @@ EXPORT_SYMBOL_GPL(spi_new_device);
393int __init 407int __init
394spi_register_board_info(struct spi_board_info const *info, unsigned n) 408spi_register_board_info(struct spi_board_info const *info, unsigned n)
395{ 409{
396 struct boardinfo *bi; 410 struct boardinfo *bi;
411 int i;
397 412
398 bi = kmalloc(sizeof(*bi) + n * sizeof *info, GFP_KERNEL); 413 bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
399 if (!bi) 414 if (!bi)
400 return -ENOMEM; 415 return -ENOMEM;
401 bi->n_board_info = n;
402 memcpy(bi->board_info, info, n * sizeof *info);
403 416
404 mutex_lock(&board_lock); 417 for (i = 0; i < n; i++, bi++, info++) {
405 list_add_tail(&bi->list, &board_list); 418 struct spi_master *master;
406 mutex_unlock(&board_lock);
407 return 0;
408}
409 419
410/* FIXME someone should add support for a __setup("spi", ...) that 420 memcpy(&bi->board_info, info, sizeof(*info));
411 * creates board info from kernel command lines 421 mutex_lock(&board_lock);
412 */ 422 list_add_tail(&bi->list, &board_list);
413 423 list_for_each_entry(master, &spi_master_list, list)
414static void scan_boardinfo(struct spi_master *master) 424 spi_match_master_to_boardinfo(master, &bi->board_info);
415{ 425 mutex_unlock(&board_lock);
416 struct boardinfo *bi;
417
418 mutex_lock(&board_lock);
419 list_for_each_entry(bi, &board_list, list) {
420 struct spi_board_info *chip = bi->board_info;
421 unsigned n;
422
423 for (n = bi->n_board_info; n > 0; n--, chip++) {
424 if (chip->bus_num != master->bus_num)
425 continue;
426 /* NOTE: this relies on spi_new_device to
427 * issue diagnostics when given bogus inputs
428 */
429 (void) spi_new_device(master, chip);
430 }
431 } 426 }
432 mutex_unlock(&board_lock); 427
428 return 0;
433} 429}
434 430
435/*-------------------------------------------------------------------------*/ 431/*-------------------------------------------------------------------------*/
@@ -512,6 +508,7 @@ int spi_register_master(struct spi_master *master)
512{ 508{
513 static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1); 509 static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1);
514 struct device *dev = master->dev.parent; 510 struct device *dev = master->dev.parent;
511 struct boardinfo *bi;
515 int status = -ENODEV; 512 int status = -ENODEV;
516 int dynamic = 0; 513 int dynamic = 0;
517 514
@@ -547,8 +544,12 @@ int spi_register_master(struct spi_master *master)
547 dev_dbg(dev, "registered master %s%s\n", dev_name(&master->dev), 544 dev_dbg(dev, "registered master %s%s\n", dev_name(&master->dev),
548 dynamic ? " (dynamic)" : ""); 545 dynamic ? " (dynamic)" : "");
549 546
550 /* populate children from any spi device tables */ 547 mutex_lock(&board_lock);
551 scan_boardinfo(master); 548 list_add_tail(&master->list, &spi_master_list);
549 list_for_each_entry(bi, &board_list, list)
550 spi_match_master_to_boardinfo(master, &bi->board_info);
551 mutex_unlock(&board_lock);
552
552 status = 0; 553 status = 0;
553 554
554 /* Register devices from the device tree */ 555 /* Register devices from the device tree */
@@ -579,7 +580,12 @@ void spi_unregister_master(struct spi_master *master)
579{ 580{
580 int dummy; 581 int dummy;
581 582
582 dummy = device_for_each_child(&master->dev, NULL, __unregister); 583 mutex_lock(&board_lock);
584 list_del(&master->list);
585 mutex_unlock(&board_lock);
586
587 dummy = device_for_each_child(master->dev.parent, &master->dev,
588 __unregister);
583 device_unregister(&master->dev); 589 device_unregister(&master->dev);
584} 590}
585EXPORT_SYMBOL_GPL(spi_unregister_master); 591EXPORT_SYMBOL_GPL(spi_unregister_master);
@@ -652,7 +658,7 @@ int spi_setup(struct spi_device *spi)
652 */ 658 */
653 bad_bits = spi->mode & ~spi->master->mode_bits; 659 bad_bits = spi->mode & ~spi->master->mode_bits;
654 if (bad_bits) { 660 if (bad_bits) {
655 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n", 661 dev_err(&spi->dev, "setup: unsupported mode bits %x\n",
656 bad_bits); 662 bad_bits);
657 return -EINVAL; 663 return -EINVAL;
658 } 664 }
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index ab483a0ec6d0..3f223511127b 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -504,6 +504,15 @@ static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
504 "in dma_irq_handler dmastat:0x%x spistat:0x%x\n", 504 "in dma_irq_handler dmastat:0x%x spistat:0x%x\n",
505 dmastat, spistat); 505 dmastat, spistat);
506 506
507 if (drv_data->rx != NULL) {
508 u16 cr = read_CTRL(drv_data);
509 /* discard old RX data and clear RXS */
510 bfin_spi_dummy_read(drv_data);
511 write_CTRL(drv_data, cr & ~BIT_CTL_ENABLE); /* Disable SPI */
512 write_CTRL(drv_data, cr & ~BIT_CTL_TIMOD); /* Restore State */
513 write_STAT(drv_data, BIT_STAT_CLR); /* Clear Status */
514 }
515
507 clear_dma_irqstat(drv_data->dma_channel); 516 clear_dma_irqstat(drv_data->dma_channel);
508 517
509 /* 518 /*
@@ -1099,12 +1108,15 @@ static int bfin_spi_setup(struct spi_device *spi)
1099 } 1108 }
1100 1109
1101 if (chip->chip_select_num >= MAX_CTRL_CS) { 1110 if (chip->chip_select_num >= MAX_CTRL_CS) {
1102 ret = gpio_request(chip->cs_gpio, spi->modalias); 1111 /* Only request on first setup */
1103 if (ret) { 1112 if (spi_get_ctldata(spi) == NULL) {
1104 dev_err(&spi->dev, "gpio_request() error\n"); 1113 ret = gpio_request(chip->cs_gpio, spi->modalias);
1105 goto pin_error; 1114 if (ret) {
1115 dev_err(&spi->dev, "gpio_request() error\n");
1116 goto pin_error;
1117 }
1118 gpio_direction_output(chip->cs_gpio, 1);
1106 } 1119 }
1107 gpio_direction_output(chip->cs_gpio, 1);
1108 } 1120 }
1109 1121
1110 dev_dbg(&spi->dev, "setup spi chip %s, width is %d, dma is %d\n", 1122 dev_dbg(&spi->dev, "setup spi chip %s, width is %d, dma is %d\n",
diff --git a/drivers/ssb/b43_pci_bridge.c b/drivers/ssb/b43_pci_bridge.c
index ef9c6a04ad8f..744d3f6e4709 100644
--- a/drivers/ssb/b43_pci_bridge.c
+++ b/drivers/ssb/b43_pci_bridge.c
@@ -24,6 +24,7 @@ static const struct pci_device_id b43_pci_bridge_tbl[] = {
24 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4312) }, 24 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4312) },
25 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4315) }, 25 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4315) },
26 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4318) }, 26 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4318) },
27 { PCI_DEVICE(PCI_VENDOR_ID_BCM_GVC, 0x4318) },
27 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4319) }, 28 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4319) },
28 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4320) }, 29 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4320) },
29 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4321) }, 30 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4321) },
diff --git a/drivers/staging/asus_oled/asus_oled.c b/drivers/staging/asus_oled/asus_oled.c
index 8c95d8c2a4f4..016c6f7f8630 100644
--- a/drivers/staging/asus_oled/asus_oled.c
+++ b/drivers/staging/asus_oled/asus_oled.c
@@ -620,13 +620,13 @@ static ssize_t class_set_picture(struct device *device,
620 620
621#define ASUS_OLED_DEVICE_ATTR(_file) dev_attr_asus_oled_##_file 621#define ASUS_OLED_DEVICE_ATTR(_file) dev_attr_asus_oled_##_file
622 622
623static DEVICE_ATTR(asus_oled_enabled, S_IWUGO | S_IRUGO, 623static DEVICE_ATTR(asus_oled_enabled, S_IWUSR | S_IRUGO,
624 get_enabled, set_enabled); 624 get_enabled, set_enabled);
625static DEVICE_ATTR(asus_oled_picture, S_IWUGO , NULL, set_picture); 625static DEVICE_ATTR(asus_oled_picture, S_IWUSR , NULL, set_picture);
626 626
627static DEVICE_ATTR(enabled, S_IWUGO | S_IRUGO, 627static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO,
628 class_get_enabled, class_set_enabled); 628 class_get_enabled, class_set_enabled);
629static DEVICE_ATTR(picture, S_IWUGO, NULL, class_set_picture); 629static DEVICE_ATTR(picture, S_IWUSR, NULL, class_set_picture);
630 630
631static int asus_oled_probe(struct usb_interface *interface, 631static int asus_oled_probe(struct usb_interface *interface,
632 const struct usb_device_id *id) 632 const struct usb_device_id *id)
diff --git a/drivers/staging/ath6kl/Kconfig b/drivers/staging/ath6kl/Kconfig
index ae2cdf48b74c..8a5caa30b85f 100644
--- a/drivers/staging/ath6kl/Kconfig
+++ b/drivers/staging/ath6kl/Kconfig
@@ -102,7 +102,7 @@ config AR600x_BT_RESET_PIN
102 102
103config ATH6KL_CFG80211 103config ATH6KL_CFG80211
104 bool "CFG80211 support" 104 bool "CFG80211 support"
105 depends on ATH6K_LEGACY 105 depends on ATH6K_LEGACY && CFG80211
106 help 106 help
107 Enables support for CFG80211 APIs. The default option is to use WEXT. Even with this option enabled, WEXT is not explicitly disabled and the onus of not exercising WEXT lies on the application(s) running in the user space. 107 Enables support for CFG80211 APIs. The default option is to use WEXT. Even with this option enabled, WEXT is not explicitly disabled and the onus of not exercising WEXT lies on the application(s) running in the user space.
108 108
diff --git a/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c b/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c
index 22c6c6659f5b..ee8b47746a15 100644
--- a/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c
+++ b/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c
@@ -285,9 +285,9 @@ A_STATUS SetupHIFScatterSupport(HIF_DEVICE *device, HIF_DEVICE_SCATTER_SUPPORT_I
285 do { 285 do {
286 286
287 /* check if host supports scatter requests and it meets our requirements */ 287 /* check if host supports scatter requests and it meets our requirements */
288 if (device->func->card->host->max_hw_segs < MAX_SCATTER_ENTRIES_PER_REQ) { 288 if (device->func->card->host->max_segs < MAX_SCATTER_ENTRIES_PER_REQ) {
289 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HIF-SCATTER : host only supports scatter of : %d entries, need: %d \n", 289 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HIF-SCATTER : host only supports scatter of : %d entries, need: %d \n",
290 device->func->card->host->max_hw_segs, MAX_SCATTER_ENTRIES_PER_REQ)); 290 device->func->card->host->max_segs, MAX_SCATTER_ENTRIES_PER_REQ));
291 status = A_ENOTSUP; 291 status = A_ENOTSUP;
292 break; 292 break;
293 } 293 }
diff --git a/drivers/staging/ath6kl/os/linux/ar6000_drv.c b/drivers/staging/ath6kl/os/linux/ar6000_drv.c
index c5a6d6c16735..a659f7047373 100644
--- a/drivers/staging/ath6kl/os/linux/ar6000_drv.c
+++ b/drivers/staging/ath6kl/os/linux/ar6000_drv.c
@@ -1126,7 +1126,7 @@ ar6000_transfer_bin_file(AR_SOFTC_T *ar, AR6K_BIN_FILE file, A_UINT32 address, A
1126 if ((board_ext_address) && (fw_entry->size == (board_data_size + board_ext_data_size))) { 1126 if ((board_ext_address) && (fw_entry->size == (board_data_size + board_ext_data_size))) {
1127 A_UINT32 param; 1127 A_UINT32 param;
1128 1128
1129 status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (A_UCHAR *)(((A_UINT32)fw_entry->data) + board_data_size), board_ext_data_size); 1129 status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (A_UCHAR *)(fw_entry->data + board_data_size), board_ext_data_size);
1130 1130
1131 if (status != A_OK) { 1131 if (status != A_OK) {
1132 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); 1132 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
@@ -3030,7 +3030,8 @@ ar6000_data_tx(struct sk_buff *skb, struct net_device *dev)
3030 A_UINT8 csumDest=0; 3030 A_UINT8 csumDest=0;
3031 A_UINT8 csum=skb->ip_summed; 3031 A_UINT8 csum=skb->ip_summed;
3032 if(csumOffload && (csum==CHECKSUM_PARTIAL)){ 3032 if(csumOffload && (csum==CHECKSUM_PARTIAL)){
3033 csumStart=skb->csum_start-(skb->network_header-skb->head)+sizeof(ATH_LLC_SNAP_HDR); 3033 csumStart = (skb->head + skb->csum_start - skb_network_header(skb) +
3034 sizeof(ATH_LLC_SNAP_HDR));
3034 csumDest=skb->csum_offset+csumStart; 3035 csumDest=skb->csum_offset+csumStart;
3035 } 3036 }
3036#endif 3037#endif
diff --git a/drivers/staging/ath6kl/os/linux/ar6000_raw_if.c b/drivers/staging/ath6kl/os/linux/ar6000_raw_if.c
index c196098f0859..6b8eeea475cf 100644
--- a/drivers/staging/ath6kl/os/linux/ar6000_raw_if.c
+++ b/drivers/staging/ath6kl/os/linux/ar6000_raw_if.c
@@ -198,8 +198,8 @@ int ar6000_htc_raw_open(AR_SOFTC_T *ar)
198 198
199 for (streamID = HTC_RAW_STREAM_0; streamID < HTC_RAW_STREAM_NUM_MAX; streamID++) { 199 for (streamID = HTC_RAW_STREAM_0; streamID < HTC_RAW_STREAM_NUM_MAX; streamID++) {
200 /* Initialize the data structures */ 200 /* Initialize the data structures */
201 init_MUTEX(&arRaw->raw_htc_read_sem[streamID]); 201 sema_init(&arRaw->raw_htc_read_sem[streamID], 1);
202 init_MUTEX(&arRaw->raw_htc_write_sem[streamID]); 202 sema_init(&arRaw->raw_htc_write_sem[streamID], 1);
203 init_waitqueue_head(&arRaw->raw_htc_read_queue[streamID]); 203 init_waitqueue_head(&arRaw->raw_htc_read_queue[streamID]);
204 init_waitqueue_head(&arRaw->raw_htc_write_queue[streamID]); 204 init_waitqueue_head(&arRaw->raw_htc_write_queue[streamID]);
205 205
diff --git a/drivers/staging/ath6kl/os/linux/cfg80211.c b/drivers/staging/ath6kl/os/linux/cfg80211.c
index c94ad29eeb4d..7269d0a1d618 100644
--- a/drivers/staging/ath6kl/os/linux/cfg80211.c
+++ b/drivers/staging/ath6kl/os/linux/cfg80211.c
@@ -808,7 +808,7 @@ ar6k_cfg80211_scanComplete_event(AR_SOFTC_T *ar, A_STATUS status)
808 808
809static int 809static int
810ar6k_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, 810ar6k_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
811 A_UINT8 key_index, const A_UINT8 *mac_addr, 811 A_UINT8 key_index, bool pairwise, const A_UINT8 *mac_addr,
812 struct key_params *params) 812 struct key_params *params)
813{ 813{
814 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(ndev); 814 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(ndev);
@@ -901,7 +901,7 @@ ar6k_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
901 901
902static int 902static int
903ar6k_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, 903ar6k_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
904 A_UINT8 key_index, const A_UINT8 *mac_addr) 904 A_UINT8 key_index, bool pairwise, const A_UINT8 *mac_addr)
905{ 905{
906 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(ndev); 906 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(ndev);
907 907
@@ -936,7 +936,8 @@ ar6k_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
936 936
937static int 937static int
938ar6k_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, 938ar6k_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
939 A_UINT8 key_index, const A_UINT8 *mac_addr, void *cookie, 939 A_UINT8 key_index, bool pairwise, const A_UINT8 *mac_addr,
940 void *cookie,
940 void (*callback)(void *cookie, struct key_params*)) 941 void (*callback)(void *cookie, struct key_params*))
941{ 942{
942 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(ndev); 943 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(ndev);
diff --git a/drivers/staging/ath6kl/os/linux/include/athendpack_linux.h b/drivers/staging/ath6kl/os/linux/include/athendpack_linux.h
deleted file mode 100644
index e69de29bb2d1..000000000000
--- a/drivers/staging/ath6kl/os/linux/include/athendpack_linux.h
+++ /dev/null
diff --git a/drivers/staging/ath6kl/os/linux/include/athstartpack_linux.h b/drivers/staging/ath6kl/os/linux/include/athstartpack_linux.h
deleted file mode 100644
index e69de29bb2d1..000000000000
--- a/drivers/staging/ath6kl/os/linux/include/athstartpack_linux.h
+++ /dev/null
diff --git a/drivers/staging/batman-adv/hard-interface.c b/drivers/staging/batman-adv/hard-interface.c
index 80cfa8669585..d85de82f941a 100644
--- a/drivers/staging/batman-adv/hard-interface.c
+++ b/drivers/staging/batman-adv/hard-interface.c
@@ -165,7 +165,7 @@ static void update_mac_addresses(struct batman_if *batman_if)
165 batman_if->net_dev->dev_addr, ETH_ALEN); 165 batman_if->net_dev->dev_addr, ETH_ALEN);
166} 166}
167 167
168static void check_known_mac_addr(uint8_t *addr) 168static void check_known_mac_addr(struct net_device *net_dev)
169{ 169{
170 struct batman_if *batman_if; 170 struct batman_if *batman_if;
171 171
@@ -175,11 +175,16 @@ static void check_known_mac_addr(uint8_t *addr)
175 (batman_if->if_status != IF_TO_BE_ACTIVATED)) 175 (batman_if->if_status != IF_TO_BE_ACTIVATED))
176 continue; 176 continue;
177 177
178 if (!compare_orig(batman_if->net_dev->dev_addr, addr)) 178 if (batman_if->net_dev == net_dev)
179 continue;
180
181 if (!compare_orig(batman_if->net_dev->dev_addr,
182 net_dev->dev_addr))
179 continue; 183 continue;
180 184
181 pr_warning("The newly added mac address (%pM) already exists " 185 pr_warning("The newly added mac address (%pM) already exists "
182 "on: %s\n", addr, batman_if->net_dev->name); 186 "on: %s\n", net_dev->dev_addr,
187 batman_if->net_dev->name);
183 pr_warning("It is strongly recommended to keep mac addresses " 188 pr_warning("It is strongly recommended to keep mac addresses "
184 "unique to avoid problems!\n"); 189 "unique to avoid problems!\n");
185 } 190 }
@@ -430,7 +435,7 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev)
430 atomic_set(&batman_if->refcnt, 0); 435 atomic_set(&batman_if->refcnt, 0);
431 hardif_hold(batman_if); 436 hardif_hold(batman_if);
432 437
433 check_known_mac_addr(batman_if->net_dev->dev_addr); 438 check_known_mac_addr(batman_if->net_dev);
434 439
435 spin_lock(&if_list_lock); 440 spin_lock(&if_list_lock);
436 list_add_tail_rcu(&batman_if->list, &if_list); 441 list_add_tail_rcu(&batman_if->list, &if_list);
@@ -458,9 +463,6 @@ static void hardif_remove_interface(struct batman_if *batman_if)
458 return; 463 return;
459 464
460 batman_if->if_status = IF_TO_BE_REMOVED; 465 batman_if->if_status = IF_TO_BE_REMOVED;
461
462 /* caller must take if_list_lock */
463 list_del_rcu(&batman_if->list);
464 synchronize_rcu(); 466 synchronize_rcu();
465 sysfs_del_hardif(&batman_if->hardif_obj); 467 sysfs_del_hardif(&batman_if->hardif_obj);
466 hardif_put(batman_if); 468 hardif_put(batman_if);
@@ -469,13 +471,21 @@ static void hardif_remove_interface(struct batman_if *batman_if)
469void hardif_remove_interfaces(void) 471void hardif_remove_interfaces(void)
470{ 472{
471 struct batman_if *batman_if, *batman_if_tmp; 473 struct batman_if *batman_if, *batman_if_tmp;
474 struct list_head if_queue;
475
476 INIT_LIST_HEAD(&if_queue);
472 477
473 rtnl_lock();
474 spin_lock(&if_list_lock); 478 spin_lock(&if_list_lock);
475 list_for_each_entry_safe(batman_if, batman_if_tmp, &if_list, list) { 479 list_for_each_entry_safe(batman_if, batman_if_tmp, &if_list, list) {
476 hardif_remove_interface(batman_if); 480 list_del_rcu(&batman_if->list);
481 list_add_tail(&batman_if->list, &if_queue);
477 } 482 }
478 spin_unlock(&if_list_lock); 483 spin_unlock(&if_list_lock);
484
485 rtnl_lock();
486 list_for_each_entry_safe(batman_if, batman_if_tmp, &if_queue, list) {
487 hardif_remove_interface(batman_if);
488 }
479 rtnl_unlock(); 489 rtnl_unlock();
480} 490}
481 491
@@ -502,8 +512,10 @@ static int hard_if_event(struct notifier_block *this,
502 break; 512 break;
503 case NETDEV_UNREGISTER: 513 case NETDEV_UNREGISTER:
504 spin_lock(&if_list_lock); 514 spin_lock(&if_list_lock);
505 hardif_remove_interface(batman_if); 515 list_del_rcu(&batman_if->list);
506 spin_unlock(&if_list_lock); 516 spin_unlock(&if_list_lock);
517
518 hardif_remove_interface(batman_if);
507 break; 519 break;
508 case NETDEV_CHANGEMTU: 520 case NETDEV_CHANGEMTU:
509 if (batman_if->soft_iface) 521 if (batman_if->soft_iface)
@@ -515,7 +527,7 @@ static int hard_if_event(struct notifier_block *this,
515 goto out; 527 goto out;
516 } 528 }
517 529
518 check_known_mac_addr(batman_if->net_dev->dev_addr); 530 check_known_mac_addr(batman_if->net_dev);
519 update_mac_addresses(batman_if); 531 update_mac_addresses(batman_if);
520 532
521 bat_priv = netdev_priv(batman_if->soft_iface); 533 bat_priv = netdev_priv(batman_if->soft_iface);
diff --git a/drivers/staging/batman-adv/routing.c b/drivers/staging/batman-adv/routing.c
index 90102631330b..657b69e6b957 100644
--- a/drivers/staging/batman-adv/routing.c
+++ b/drivers/staging/batman-adv/routing.c
@@ -1000,10 +1000,10 @@ int recv_icmp_packet(struct sk_buff *skb, struct batman_if *recv_if)
1000 1000
1001/* find a suitable router for this originator, and use 1001/* find a suitable router for this originator, and use
1002 * bonding if possible. */ 1002 * bonding if possible. */
1003struct neigh_node *find_router(struct orig_node *orig_node, 1003struct neigh_node *find_router(struct bat_priv *bat_priv,
1004 struct orig_node *orig_node,
1004 struct batman_if *recv_if) 1005 struct batman_if *recv_if)
1005{ 1006{
1006 struct bat_priv *bat_priv;
1007 struct orig_node *primary_orig_node; 1007 struct orig_node *primary_orig_node;
1008 struct orig_node *router_orig; 1008 struct orig_node *router_orig;
1009 struct neigh_node *router, *first_candidate, *best_router; 1009 struct neigh_node *router, *first_candidate, *best_router;
@@ -1019,13 +1019,9 @@ struct neigh_node *find_router(struct orig_node *orig_node,
1019 /* without bonding, the first node should 1019 /* without bonding, the first node should
1020 * always choose the default router. */ 1020 * always choose the default router. */
1021 1021
1022 if (!recv_if)
1023 return orig_node->router;
1024
1025 bat_priv = netdev_priv(recv_if->soft_iface);
1026 bonding_enabled = atomic_read(&bat_priv->bonding_enabled); 1022 bonding_enabled = atomic_read(&bat_priv->bonding_enabled);
1027 1023
1028 if (!bonding_enabled) 1024 if ((!recv_if) && (!bonding_enabled))
1029 return orig_node->router; 1025 return orig_node->router;
1030 1026
1031 router_orig = orig_node->router->orig_node; 1027 router_orig = orig_node->router->orig_node;
@@ -1154,7 +1150,7 @@ static int route_unicast_packet(struct sk_buff *skb,
1154 orig_node = ((struct orig_node *) 1150 orig_node = ((struct orig_node *)
1155 hash_find(bat_priv->orig_hash, unicast_packet->dest)); 1151 hash_find(bat_priv->orig_hash, unicast_packet->dest));
1156 1152
1157 router = find_router(orig_node, recv_if); 1153 router = find_router(bat_priv, orig_node, recv_if);
1158 1154
1159 if (!router) { 1155 if (!router) {
1160 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags); 1156 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
diff --git a/drivers/staging/batman-adv/routing.h b/drivers/staging/batman-adv/routing.h
index 06ea99df3706..92674c8d9c03 100644
--- a/drivers/staging/batman-adv/routing.h
+++ b/drivers/staging/batman-adv/routing.h
@@ -38,8 +38,8 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if);
38int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if); 38int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if);
39int recv_vis_packet(struct sk_buff *skb, struct batman_if *recv_if); 39int recv_vis_packet(struct sk_buff *skb, struct batman_if *recv_if);
40int recv_bat_packet(struct sk_buff *skb, struct batman_if *recv_if); 40int recv_bat_packet(struct sk_buff *skb, struct batman_if *recv_if);
41struct neigh_node *find_router(struct orig_node *orig_node, 41struct neigh_node *find_router(struct bat_priv *bat_priv,
42 struct batman_if *recv_if); 42 struct orig_node *orig_node, struct batman_if *recv_if);
43void update_bonding_candidates(struct bat_priv *bat_priv, 43void update_bonding_candidates(struct bat_priv *bat_priv,
44 struct orig_node *orig_node); 44 struct orig_node *orig_node);
45 45
diff --git a/drivers/staging/batman-adv/soft-interface.c b/drivers/staging/batman-adv/soft-interface.c
index 3904db9ce7b1..0e996181daf7 100644
--- a/drivers/staging/batman-adv/soft-interface.c
+++ b/drivers/staging/batman-adv/soft-interface.c
@@ -194,14 +194,15 @@ void interface_rx(struct net_device *soft_iface,
194 struct bat_priv *priv = netdev_priv(soft_iface); 194 struct bat_priv *priv = netdev_priv(soft_iface);
195 195
196 /* check if enough space is available for pulling, and pull */ 196 /* check if enough space is available for pulling, and pull */
197 if (!pskb_may_pull(skb, hdr_size)) { 197 if (!pskb_may_pull(skb, hdr_size))
198 kfree_skb(skb); 198 goto dropped;
199 return; 199
200 }
201 skb_pull_rcsum(skb, hdr_size); 200 skb_pull_rcsum(skb, hdr_size);
202/* skb_set_mac_header(skb, -sizeof(struct ethhdr));*/ 201/* skb_set_mac_header(skb, -sizeof(struct ethhdr));*/
203 202
204 /* skb->dev & skb->pkt_type are set here */ 203 /* skb->dev & skb->pkt_type are set here */
204 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
205 goto dropped;
205 skb->protocol = eth_type_trans(skb, soft_iface); 206 skb->protocol = eth_type_trans(skb, soft_iface);
206 207
207 /* should not be neccesary anymore as we use skb_pull_rcsum() 208 /* should not be neccesary anymore as we use skb_pull_rcsum()
@@ -216,6 +217,11 @@ void interface_rx(struct net_device *soft_iface,
216 soft_iface->last_rx = jiffies; 217 soft_iface->last_rx = jiffies;
217 218
218 netif_rx(skb); 219 netif_rx(skb);
220 return;
221
222dropped:
223 kfree_skb(skb);
224 return;
219} 225}
220 226
221#ifdef HAVE_NET_DEVICE_OPS 227#ifdef HAVE_NET_DEVICE_OPS
diff --git a/drivers/staging/batman-adv/unicast.c b/drivers/staging/batman-adv/unicast.c
index 0dac50d69c03..0459413ff67f 100644
--- a/drivers/staging/batman-adv/unicast.c
+++ b/drivers/staging/batman-adv/unicast.c
@@ -224,7 +224,7 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
224 if (!orig_node) 224 if (!orig_node)
225 orig_node = transtable_search(bat_priv, ethhdr->h_dest); 225 orig_node = transtable_search(bat_priv, ethhdr->h_dest);
226 226
227 router = find_router(orig_node, NULL); 227 router = find_router(bat_priv, orig_node, NULL);
228 228
229 if (!router) 229 if (!router)
230 goto unlock; 230 goto unlock;
diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c
index 77fdfe24d999..fead9c56162e 100644
--- a/drivers/staging/bcm/Bcmchar.c
+++ b/drivers/staging/bcm/Bcmchar.c
@@ -1001,13 +1001,15 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1001 } 1001 }
1002#endif 1002#endif
1003 case IOCTL_BE_BUCKET_SIZE: 1003 case IOCTL_BE_BUCKET_SIZE:
1004 Adapter->BEBucketSize = *(PULONG)arg; 1004 Status = 0;
1005 Status = STATUS_SUCCESS; 1005 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
1006 Status = -EFAULT;
1006 break; 1007 break;
1007 1008
1008 case IOCTL_RTPS_BUCKET_SIZE: 1009 case IOCTL_RTPS_BUCKET_SIZE:
1009 Adapter->rtPSBucketSize = *(PULONG)arg; 1010 Status = 0;
1010 Status = STATUS_SUCCESS; 1011 if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
1012 Status = -EFAULT;
1011 break; 1013 break;
1012 case IOCTL_CHIP_RESET: 1014 case IOCTL_CHIP_RESET:
1013 { 1015 {
@@ -1028,11 +1030,15 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1028 case IOCTL_QOS_THRESHOLD: 1030 case IOCTL_QOS_THRESHOLD:
1029 { 1031 {
1030 USHORT uiLoopIndex; 1032 USHORT uiLoopIndex;
1031 for(uiLoopIndex = 0 ; uiLoopIndex < NO_OF_QUEUES ; uiLoopIndex++) 1033
1032 { 1034 Status = 0;
1033 Adapter->PackInfo[uiLoopIndex].uiThreshold = *(PULONG)arg; 1035 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
1036 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
1037 (unsigned long __user *)arg)) {
1038 Status = -EFAULT;
1039 break;
1040 }
1034 } 1041 }
1035 Status = STATUS_SUCCESS;
1036 break; 1042 break;
1037 } 1043 }
1038 1044
@@ -1093,7 +1099,8 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1093 } 1099 }
1094 case IOCTL_BCM_GET_CURRENT_STATUS: 1100 case IOCTL_BCM_GET_CURRENT_STATUS:
1095 { 1101 {
1096 LINK_STATE *plink_state = NULL; 1102 LINK_STATE plink_state;
1103
1097 /* Copy Ioctl Buffer structure */ 1104 /* Copy Ioctl Buffer structure */
1098 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 1105 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1099 { 1106 {
@@ -1101,13 +1108,19 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1101 Status = -EFAULT; 1108 Status = -EFAULT;
1102 break; 1109 break;
1103 } 1110 }
1104 plink_state = (LINK_STATE*)arg; 1111 if (IoBuffer.OutputLength != sizeof(plink_state)) {
1105 plink_state->bIdleMode = (UCHAR)Adapter->IdleMode; 1112 Status = -EINVAL;
1106 plink_state->bShutdownMode = Adapter->bShutStatus; 1113 break;
1107 plink_state->ucLinkStatus = (UCHAR)Adapter->LinkStatus; 1114 }
1108 if(copy_to_user(IoBuffer.OutputBuffer, 1115
1109 (PUCHAR)plink_state, (UINT)IoBuffer.OutputLength)) 1116 if (copy_from_user(&plink_state, (void __user *)arg, sizeof(plink_state))) {
1110 { 1117 Status = -EFAULT;
1118 break;
1119 }
1120 plink_state.bIdleMode = (UCHAR)Adapter->IdleMode;
1121 plink_state.bShutdownMode = Adapter->bShutStatus;
1122 plink_state.ucLinkStatus = (UCHAR)Adapter->LinkStatus;
1123 if (copy_to_user(IoBuffer.OutputBuffer, &plink_state, IoBuffer.OutputLength)) {
1111 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n"); 1124 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1112 Status = -EFAULT; 1125 Status = -EFAULT;
1113 break; 1126 break;
@@ -1331,7 +1344,9 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1331 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy From User space failed. status :%d", Status); 1344 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy From User space failed. status :%d", Status);
1332 return -EFAULT; 1345 return -EFAULT;
1333 } 1346 }
1334 uiSectorSize = *((PUINT)(IoBuffer.InputBuffer)); /* FIXME: unchecked __user access */ 1347 if (get_user(uiSectorSize, (unsigned int __user *)IoBuffer.InputBuffer))
1348 return -EFAULT;
1349
1335 if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE)) 1350 if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE))
1336 { 1351 {
1337 1352
diff --git a/drivers/staging/brcm80211/README b/drivers/staging/brcm80211/README
index c3ba9bb9b116..a27bb0b4f581 100644
--- a/drivers/staging/brcm80211/README
+++ b/drivers/staging/brcm80211/README
@@ -88,7 +88,9 @@ with the driver.
88 88
89Contact Info: 89Contact Info:
90============= 90=============
91Brett Rudley brudley@broadcom.com 91Brett Rudley brudley@broadcom.com
92Henry Ptasinski henryp@broadcom.com 92Henry Ptasinski henryp@broadcom.com
93Nohee Ko noheek@broadcom.com 93Dowan Kim dowan@broadcom.com
94Roland Vossen rvossen@broadcom.com
95Arend van Spriel arend@broadcom.com
94 96
diff --git a/drivers/staging/brcm80211/TODO b/drivers/staging/brcm80211/TODO
index 8803d300b531..24ebadbe4241 100644
--- a/drivers/staging/brcm80211/TODO
+++ b/drivers/staging/brcm80211/TODO
@@ -45,5 +45,7 @@ Contact
45===== 45=====
46Brett Rudley <brudley@broadcom.com> 46Brett Rudley <brudley@broadcom.com>
47Henry Ptasinski <henryp@broadcom.com> 47Henry Ptasinski <henryp@broadcom.com>
48Nohee Ko <noheek@broadcom.com> 48Dowan Kim <dowan@broadcom.com>
49Roland Vossen <rvossen@broadcom.com>
50Arend van Spriel <arend@broadcom.com>
49 51
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_linux.c b/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
index e5357875661f..9335f02029aa 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
@@ -1929,7 +1929,7 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1929 goto fail; 1929 goto fail;
1930 1930
1931 net->netdev_ops = NULL; 1931 net->netdev_ops = NULL;
1932 init_MUTEX(&dhd->proto_sem); 1932 sema_init(&dhd->proto_sem, 1);
1933 /* Initialize other structure content */ 1933 /* Initialize other structure content */
1934 init_waitqueue_head(&dhd->ioctl_resp_wait); 1934 init_waitqueue_head(&dhd->ioctl_resp_wait);
1935 init_waitqueue_head(&dhd->ctrl_wait); 1935 init_waitqueue_head(&dhd->ctrl_wait);
@@ -1977,7 +1977,7 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1977 dhd->timer.function = dhd_watchdog; 1977 dhd->timer.function = dhd_watchdog;
1978 1978
1979 /* Initialize thread based operation and lock */ 1979 /* Initialize thread based operation and lock */
1980 init_MUTEX(&dhd->sdsem); 1980 sema_init(&dhd->sdsem, 1);
1981 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)) 1981 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1982 dhd->threads_only = true; 1982 dhd->threads_only = true;
1983 else 1983 else
@@ -2222,8 +2222,6 @@ int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2222 ASSERT(net); 2222 ASSERT(net);
2223 2223
2224 ASSERT(!net->netdev_ops); 2224 ASSERT(!net->netdev_ops);
2225 net->netdev_ops = &dhd_ops_virt;
2226
2227 net->netdev_ops = &dhd_ops_pri; 2225 net->netdev_ops = &dhd_ops_pri;
2228 2226
2229 /* 2227 /*
diff --git a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
index 3f29488d9c72..ea0825238d53 100644
--- a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
@@ -95,12 +95,12 @@ static s32 wl_cfg80211_config_default_key(struct wiphy *wiphy,
95 struct net_device *dev, 95 struct net_device *dev,
96 u8 key_idx); 96 u8 key_idx);
97static s32 wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev, 97static s32 wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
98 u8 key_idx, const u8 *mac_addr, 98 u8 key_idx, bool pairwise, const u8 *mac_addr,
99 struct key_params *params); 99 struct key_params *params);
100static s32 wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev, 100static s32 wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
101 u8 key_idx, const u8 *mac_addr); 101 u8 key_idx, bool pairwise, const u8 *mac_addr);
102static s32 wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev, 102static s32 wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
103 u8 key_idx, const u8 *mac_addr, 103 u8 key_idx, bool pairwise, const u8 *mac_addr,
104 void *cookie, void (*callback) (void *cookie, 104 void *cookie, void (*callback) (void *cookie,
105 struct 105 struct
106 key_params * 106 key_params *
@@ -1615,7 +1615,7 @@ wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
1615 1615
1616static s32 1616static s32
1617wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev, 1617wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1618 u8 key_idx, const u8 *mac_addr, 1618 u8 key_idx, bool pairwise, const u8 *mac_addr,
1619 struct key_params *params) 1619 struct key_params *params)
1620{ 1620{
1621 struct wl_wsec_key key; 1621 struct wl_wsec_key key;
@@ -1700,7 +1700,7 @@ wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1700 1700
1701static s32 1701static s32
1702wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev, 1702wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
1703 u8 key_idx, const u8 *mac_addr) 1703 u8 key_idx, bool pairwise, const u8 *mac_addr)
1704{ 1704{
1705 struct wl_wsec_key key; 1705 struct wl_wsec_key key;
1706 s32 err = 0; 1706 s32 err = 0;
@@ -1756,7 +1756,7 @@ wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
1756 1756
1757static s32 1757static s32
1758wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev, 1758wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
1759 u8 key_idx, const u8 *mac_addr, void *cookie, 1759 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
1760 void (*callback) (void *cookie, struct key_params * params)) 1760 void (*callback) (void *cookie, struct key_params * params))
1761{ 1761{
1762 struct key_params params; 1762 struct key_params params;
diff --git a/drivers/staging/brcm80211/sys/wl_mac80211.c b/drivers/staging/brcm80211/sys/wl_mac80211.c
index ad635ee7758e..d060377629ac 100644
--- a/drivers/staging/brcm80211/sys/wl_mac80211.c
+++ b/drivers/staging/brcm80211/sys/wl_mac80211.c
@@ -866,7 +866,7 @@ static wl_info_t *wl_attach(u16 vendor, u16 device, unsigned long regs,
866 spin_lock_init(&wl->rpcq_lock); 866 spin_lock_init(&wl->rpcq_lock);
867 spin_lock_init(&wl->txq_lock); 867 spin_lock_init(&wl->txq_lock);
868 868
869 init_MUTEX(&wl->sem); 869 sema_init(&wl->sem, 1);
870#else 870#else
871 spin_lock_init(&wl->lock); 871 spin_lock_init(&wl->lock);
872 spin_lock_init(&wl->isr_lock); 872 spin_lock_init(&wl->isr_lock);
diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c
index 0560a7451512..06059850dae2 100644
--- a/drivers/staging/comedi/drivers/dt9812.c
+++ b/drivers/staging/comedi/drivers/dt9812.c
@@ -262,7 +262,7 @@ struct dt9812_usb_cmd {
262 262
263#define DT9812_NUM_SLOTS 16 263#define DT9812_NUM_SLOTS 16
264 264
265static DECLARE_MUTEX(dt9812_mutex); 265static DEFINE_SEMAPHORE(dt9812_mutex);
266 266
267static const struct usb_device_id dt9812_table[] = { 267static const struct usb_device_id dt9812_table[] = {
268 {USB_DEVICE(0x0867, 0x9812)}, 268 {USB_DEVICE(0x0867, 0x9812)},
diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c
index 6131e2dd0591..de784ff08caa 100644
--- a/drivers/staging/comedi/drivers/usbdux.c
+++ b/drivers/staging/comedi/drivers/usbdux.c
@@ -315,7 +315,7 @@ struct usbduxsub {
315 */ 315 */
316static struct usbduxsub usbduxsub[NUMUSBDUX]; 316static struct usbduxsub usbduxsub[NUMUSBDUX];
317 317
318static DECLARE_MUTEX(start_stop_sem); 318static DEFINE_SEMAPHORE(start_stop_sem);
319 319
320/* 320/*
321 * Stops the data acquision 321 * Stops the data acquision
@@ -2295,8 +2295,8 @@ static void tidy_up(struct usbduxsub *usbduxsub_tmp)
2295 usbduxsub_tmp->inBuffer = NULL; 2295 usbduxsub_tmp->inBuffer = NULL;
2296 kfree(usbduxsub_tmp->insnBuffer); 2296 kfree(usbduxsub_tmp->insnBuffer);
2297 usbduxsub_tmp->insnBuffer = NULL; 2297 usbduxsub_tmp->insnBuffer = NULL;
2298 kfree(usbduxsub_tmp->inBuffer); 2298 kfree(usbduxsub_tmp->outBuffer);
2299 usbduxsub_tmp->inBuffer = NULL; 2299 usbduxsub_tmp->outBuffer = NULL;
2300 kfree(usbduxsub_tmp->dac_commands); 2300 kfree(usbduxsub_tmp->dac_commands);
2301 usbduxsub_tmp->dac_commands = NULL; 2301 usbduxsub_tmp->dac_commands = NULL;
2302 kfree(usbduxsub_tmp->dux_commands); 2302 kfree(usbduxsub_tmp->dux_commands);
@@ -2367,7 +2367,7 @@ static int usbduxsub_probe(struct usb_interface *uinterf,
2367 dev_dbg(dev, "comedi_: usbdux: " 2367 dev_dbg(dev, "comedi_: usbdux: "
2368 "usbduxsub[%d] is ready to connect to comedi.\n", index); 2368 "usbduxsub[%d] is ready to connect to comedi.\n", index);
2369 2369
2370 init_MUTEX(&(usbduxsub[index].sem)); 2370 sema_init(&(usbduxsub[index].sem), 1);
2371 /* save a pointer to the usb device */ 2371 /* save a pointer to the usb device */
2372 usbduxsub[index].usbdev = udev; 2372 usbduxsub[index].usbdev = udev;
2373 2373
diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
index 0a164a9a66c3..5b15e6df54e6 100644
--- a/drivers/staging/comedi/drivers/usbduxfast.c
+++ b/drivers/staging/comedi/drivers/usbduxfast.c
@@ -199,7 +199,7 @@ struct usbduxfastsub_s {
199 */ 199 */
200static struct usbduxfastsub_s usbduxfastsub[NUMUSBDUXFAST]; 200static struct usbduxfastsub_s usbduxfastsub[NUMUSBDUXFAST];
201 201
202static DECLARE_MUTEX(start_stop_sem); 202static DEFINE_SEMAPHORE(start_stop_sem);
203 203
204/* 204/*
205 * bulk transfers to usbduxfast 205 * bulk transfers to usbduxfast
@@ -1504,7 +1504,7 @@ static int usbduxfastsub_probe(struct usb_interface *uinterf,
1504 "connect to comedi.\n", index); 1504 "connect to comedi.\n", index);
1505#endif 1505#endif
1506 1506
1507 init_MUTEX(&(usbduxfastsub[index].sem)); 1507 sema_init(&(usbduxfastsub[index].sem), 1);
1508 /* save a pointer to the usb device */ 1508 /* save a pointer to the usb device */
1509 usbduxfastsub[index].usbdev = udev; 1509 usbduxfastsub[index].usbdev = udev;
1510 1510
diff --git a/drivers/staging/cpia/cpia.c b/drivers/staging/cpia/cpia.c
index 933ae4c8cb9a..0e740b8dafc3 100644
--- a/drivers/staging/cpia/cpia.c
+++ b/drivers/staging/cpia/cpia.c
@@ -3184,13 +3184,9 @@ static int cpia_open(struct file *file)
3184 goto oops; 3184 goto oops;
3185 } 3185 }
3186 3186
3187 err = -EINTR;
3188 if(signal_pending(current))
3189 goto oops;
3190
3191 /* Set ownership of /proc/cpia/videoX to current user */ 3187 /* Set ownership of /proc/cpia/videoX to current user */
3192 if(cam->proc_entry) 3188 if(cam->proc_entry)
3193 cam->proc_entry->uid = current_uid(); 3189 cam->proc_entry->uid = current_euid();
3194 3190
3195 /* set mark for loading first frame uncompressed */ 3191 /* set mark for loading first frame uncompressed */
3196 cam->first_frame = 1; 3192 cam->first_frame = 1;
diff --git a/drivers/staging/cx25821/cx25821-video.c b/drivers/staging/cx25821/cx25821-video.c
index e7f1d5778cec..52389308f333 100644
--- a/drivers/staging/cx25821/cx25821-video.c
+++ b/drivers/staging/cx25821/cx25821-video.c
@@ -92,7 +92,7 @@ int cx25821_get_format_size(void)
92 return ARRAY_SIZE(formats); 92 return ARRAY_SIZE(formats);
93} 93}
94 94
95struct cx25821_fmt *format_by_fourcc(unsigned int fourcc) 95struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc)
96{ 96{
97 unsigned int i; 97 unsigned int i;
98 98
@@ -848,7 +848,7 @@ static int video_open(struct file *file)
848 pix_format = 848 pix_format =
849 (dev->channels[ch_id].pixel_formats == 849 (dev->channels[ch_id].pixel_formats ==
850 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV; 850 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
851 fh->fmt = format_by_fourcc(pix_format); 851 fh->fmt = cx25821_format_by_fourcc(pix_format);
852 852
853 v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio); 853 v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio);
854 854
@@ -1010,7 +1010,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1010 if (0 != err) 1010 if (0 != err)
1011 return err; 1011 return err;
1012 1012
1013 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); 1013 fh->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
1014 fh->vidq.field = f->fmt.pix.field; 1014 fh->vidq.field = f->fmt.pix.field;
1015 1015
1016 /* check if width and height is valid based on set standard */ 1016 /* check if width and height is valid based on set standard */
@@ -1119,7 +1119,7 @@ int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fo
1119 enum v4l2_field field; 1119 enum v4l2_field field;
1120 unsigned int maxw, maxh; 1120 unsigned int maxw, maxh;
1121 1121
1122 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 1122 fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
1123 if (NULL == fmt) 1123 if (NULL == fmt)
1124 return -EINVAL; 1124 return -EINVAL;
1125 1125
diff --git a/drivers/staging/cx25821/cx25821-video.h b/drivers/staging/cx25821/cx25821-video.h
index cc6034b1a95d..a2415d33235b 100644
--- a/drivers/staging/cx25821/cx25821-video.h
+++ b/drivers/staging/cx25821/cx25821-video.h
@@ -87,7 +87,7 @@ extern unsigned int vid_limit;
87 87
88#define FORMAT_FLAGS_PACKED 0x01 88#define FORMAT_FLAGS_PACKED 0x01
89extern struct cx25821_fmt formats[]; 89extern struct cx25821_fmt formats[];
90extern struct cx25821_fmt *format_by_fourcc(unsigned int fourcc); 90extern struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc);
91extern struct cx25821_data timeout_data[MAX_VID_CHANNEL_NUM]; 91extern struct cx25821_data timeout_data[MAX_VID_CHANNEL_NUM];
92 92
93extern void cx25821_dump_video_queue(struct cx25821_dev *dev, 93extern void cx25821_dump_video_queue(struct cx25821_dev *dev,
diff --git a/drivers/staging/easycap/easycap.h b/drivers/staging/easycap/easycap.h
index f3c827eb0abe..884263b2775d 100644
--- a/drivers/staging/easycap/easycap.h
+++ b/drivers/staging/easycap/easycap.h
@@ -75,9 +75,9 @@
75#include <linux/errno.h> 75#include <linux/errno.h>
76#include <linux/init.h> 76#include <linux/init.h>
77#include <linux/slab.h> 77#include <linux/slab.h>
78#include <linux/smp_lock.h>
78#include <linux/module.h> 79#include <linux/module.h>
79#include <linux/kref.h> 80#include <linux/kref.h>
80#include <linux/smp_lock.h>
81#include <linux/usb.h> 81#include <linux/usb.h>
82#include <linux/uaccess.h> 82#include <linux/uaccess.h>
83 83
diff --git a/drivers/staging/frontier/tranzport.c b/drivers/staging/frontier/tranzport.c
index a145a15cfdb3..8894ab14f167 100644
--- a/drivers/staging/frontier/tranzport.c
+++ b/drivers/staging/frontier/tranzport.c
@@ -204,7 +204,7 @@ static void usb_tranzport_abort_transfers(struct usb_tranzport *dev)
204 t->value = temp; \ 204 t->value = temp; \
205 return count; \ 205 return count; \
206 } \ 206 } \
207 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 207 static DEVICE_ATTR(value, S_IWUSR | S_IRUGO, show_##value, set_##value);
208 208
209show_int(enable); 209show_int(enable);
210show_int(offline); 210show_int(offline);
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c b/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c
index 87a6487531c2..20d509836d9e 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c
@@ -286,7 +286,6 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
286 pid = kernel_thread (exec_mknod, (void *)info, 0); 286 pid = kernel_thread (exec_mknod, (void *)info, 0);
287 287
288 // initialize application information 288 // initialize application information
289 info->appcnt = 0;
290 289
291// if (ft1000_flarion_cnt == 0) { 290// if (ft1000_flarion_cnt == 0) {
292// 291//
diff --git a/drivers/staging/go7007/go7007-driver.c b/drivers/staging/go7007/go7007-driver.c
index b3f42f37a313..48d4e483d8a4 100644
--- a/drivers/staging/go7007/go7007-driver.c
+++ b/drivers/staging/go7007/go7007-driver.c
@@ -199,7 +199,7 @@ static int init_i2c_module(struct i2c_adapter *adapter, const char *type,
199 struct go7007 *go = i2c_get_adapdata(adapter); 199 struct go7007 *go = i2c_get_adapdata(adapter);
200 struct v4l2_device *v4l2_dev = &go->v4l2_dev; 200 struct v4l2_device *v4l2_dev = &go->v4l2_dev;
201 201
202 if (v4l2_i2c_new_subdev(v4l2_dev, adapter, NULL, type, addr, NULL)) 202 if (v4l2_i2c_new_subdev(v4l2_dev, adapter, type, addr, NULL))
203 return 0; 203 return 0;
204 204
205 printk(KERN_INFO "go7007: probing for module i2c:%s failed\n", type); 205 printk(KERN_INFO "go7007: probing for module i2c:%s failed\n", type);
diff --git a/drivers/staging/hv/hv_utils.c b/drivers/staging/hv/hv_utils.c
index 702a478d5542..a99e900ec4c9 100644
--- a/drivers/staging/hv/hv_utils.c
+++ b/drivers/staging/hv/hv_utils.c
@@ -212,9 +212,6 @@ static void heartbeat_onchannelcallback(void *context)
212 recvlen, requestid); 212 recvlen, requestid);
213 213
214 icmsghdrp = (struct icmsg_hdr *)&buf[ 214 icmsghdrp = (struct icmsg_hdr *)&buf[
215 sizeof(struct vmbuspipe_hdr)];
216
217 icmsghdrp = (struct icmsg_hdr *)&buf[
218 sizeof(struct vmbuspipe_hdr)]; 215 sizeof(struct vmbuspipe_hdr)];
219 216
220 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { 217 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c
index 41d9acf4cd61..6f8d67d0d64f 100644
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -72,8 +72,7 @@ struct storvsc_driver_context {
72 72
73/* Static decl */ 73/* Static decl */
74static int storvsc_probe(struct device *dev); 74static int storvsc_probe(struct device *dev);
75static int storvsc_queuecommand(struct scsi_cmnd *scmnd, 75static int storvsc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd);
76 void (*done)(struct scsi_cmnd *));
77static int storvsc_device_alloc(struct scsi_device *); 76static int storvsc_device_alloc(struct scsi_device *);
78static int storvsc_device_configure(struct scsi_device *); 77static int storvsc_device_configure(struct scsi_device *);
79static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd); 78static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd);
@@ -595,7 +594,7 @@ static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl,
595/* 594/*
596 * storvsc_queuecommand - Initiate command processing 595 * storvsc_queuecommand - Initiate command processing
597 */ 596 */
598static int storvsc_queuecommand(struct scsi_cmnd *scmnd, 597static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd,
599 void (*done)(struct scsi_cmnd *)) 598 void (*done)(struct scsi_cmnd *))
600{ 599{
601 int ret; 600 int ret;
@@ -783,6 +782,8 @@ retry_request:
783 return ret; 782 return ret;
784} 783}
785 784
785static DEF_SCSI_QCMD(storvsc_queuecommand)
786
786static int storvsc_merge_bvec(struct request_queue *q, 787static int storvsc_merge_bvec(struct request_queue *q,
787 struct bvec_merge_data *bmd, struct bio_vec *bvec) 788 struct bvec_merge_data *bmd, struct bio_vec *bvec)
788{ 789{
diff --git a/drivers/staging/iio/accel/adis16220_core.c b/drivers/staging/iio/accel/adis16220_core.c
index c86d1498737d..1c1e98aee2d9 100644
--- a/drivers/staging/iio/accel/adis16220_core.c
+++ b/drivers/staging/iio/accel/adis16220_core.c
@@ -507,7 +507,7 @@ static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL,
507 adis16220_write_reset, 0); 507 adis16220_write_reset, 0);
508 508
509#define IIO_DEV_ATTR_CAPTURE(_store) \ 509#define IIO_DEV_ATTR_CAPTURE(_store) \
510 IIO_DEVICE_ATTR(capture, S_IWUGO, NULL, _store, 0) 510 IIO_DEVICE_ATTR(capture, S_IWUSR, NULL, _store, 0)
511 511
512static IIO_DEV_ATTR_CAPTURE(adis16220_write_capture); 512static IIO_DEV_ATTR_CAPTURE(adis16220_write_capture);
513 513
diff --git a/drivers/staging/intel_sst/intel_sst_app_interface.c b/drivers/staging/intel_sst/intel_sst_app_interface.c
index 463e5cba8307..991440015e92 100644
--- a/drivers/staging/intel_sst/intel_sst_app_interface.c
+++ b/drivers/staging/intel_sst/intel_sst_app_interface.c
@@ -34,7 +34,6 @@
34#include <linux/uaccess.h> 34#include <linux/uaccess.h>
35#include <linux/firmware.h> 35#include <linux/firmware.h>
36#include <linux/ioctl.h> 36#include <linux/ioctl.h>
37#include <linux/smp_lock.h>
38#ifdef CONFIG_MRST_RAR_HANDLER 37#ifdef CONFIG_MRST_RAR_HANDLER
39#include <linux/rar_register.h> 38#include <linux/rar_register.h>
40#include "../../../drivers/staging/memrar/memrar.h" 39#include "../../../drivers/staging/memrar/memrar.h"
@@ -244,12 +243,12 @@ static int intel_sst_mmap_play_capture(u32 str_id,
244 int retval, i; 243 int retval, i;
245 struct stream_info *stream; 244 struct stream_info *stream;
246 struct snd_sst_mmap_buff_entry *buf_entry; 245 struct snd_sst_mmap_buff_entry *buf_entry;
246 struct snd_sst_mmap_buff_entry *tmp_buf;
247 247
248 pr_debug("sst:called for str_id %d\n", str_id); 248 pr_debug("sst:called for str_id %d\n", str_id);
249 retval = sst_validate_strid(str_id); 249 retval = sst_validate_strid(str_id);
250 if (retval) 250 if (retval)
251 return -EINVAL; 251 return -EINVAL;
252 BUG_ON(!mmap_buf);
253 252
254 stream = &sst_drv_ctx->streams[str_id]; 253 stream = &sst_drv_ctx->streams[str_id];
255 if (stream->mmapped != true) 254 if (stream->mmapped != true)
@@ -262,14 +261,24 @@ static int intel_sst_mmap_play_capture(u32 str_id,
262 stream->curr_bytes = 0; 261 stream->curr_bytes = 0;
263 stream->cumm_bytes = 0; 262 stream->cumm_bytes = 0;
264 263
264 tmp_buf = kcalloc(mmap_buf->entries, sizeof(*tmp_buf), GFP_KERNEL);
265 if (!tmp_buf)
266 return -ENOMEM;
267 if (copy_from_user(tmp_buf, (void __user *)mmap_buf->buff,
268 mmap_buf->entries * sizeof(*tmp_buf))) {
269 retval = -EFAULT;
270 goto out_free;
271 }
272
265 pr_debug("sst:new buffers count %d status %d\n", 273 pr_debug("sst:new buffers count %d status %d\n",
266 mmap_buf->entries, stream->status); 274 mmap_buf->entries, stream->status);
267 buf_entry = mmap_buf->buff; 275 buf_entry = tmp_buf;
268 for (i = 0; i < mmap_buf->entries; i++) { 276 for (i = 0; i < mmap_buf->entries; i++) {
269 BUG_ON(!buf_entry);
270 bufs = kzalloc(sizeof(*bufs), GFP_KERNEL); 277 bufs = kzalloc(sizeof(*bufs), GFP_KERNEL);
271 if (!bufs) 278 if (!bufs) {
272 return -ENOMEM; 279 retval = -ENOMEM;
280 goto out_free;
281 }
273 bufs->size = buf_entry->size; 282 bufs->size = buf_entry->size;
274 bufs->offset = buf_entry->offset; 283 bufs->offset = buf_entry->offset;
275 bufs->addr = sst_drv_ctx->mmap_mem; 284 bufs->addr = sst_drv_ctx->mmap_mem;
@@ -293,13 +302,15 @@ static int intel_sst_mmap_play_capture(u32 str_id,
293 if (sst_play_frame(str_id) < 0) { 302 if (sst_play_frame(str_id) < 0) {
294 pr_warn("sst: play frames fail\n"); 303 pr_warn("sst: play frames fail\n");
295 mutex_unlock(&stream->lock); 304 mutex_unlock(&stream->lock);
296 return -EIO; 305 retval = -EIO;
306 goto out_free;
297 } 307 }
298 } else if (stream->ops == STREAM_OPS_CAPTURE) { 308 } else if (stream->ops == STREAM_OPS_CAPTURE) {
299 if (sst_capture_frame(str_id) < 0) { 309 if (sst_capture_frame(str_id) < 0) {
300 pr_warn("sst: capture frame fail\n"); 310 pr_warn("sst: capture frame fail\n");
301 mutex_unlock(&stream->lock); 311 mutex_unlock(&stream->lock);
302 return -EIO; 312 retval = -EIO;
313 goto out_free;
303 } 314 }
304 } 315 }
305 } 316 }
@@ -314,6 +325,9 @@ static int intel_sst_mmap_play_capture(u32 str_id,
314 if (retval >= 0) 325 if (retval >= 0)
315 retval = stream->cumm_bytes; 326 retval = stream->cumm_bytes;
316 pr_debug("sst:end of play/rec ioctl bytes = %d!!\n", retval); 327 pr_debug("sst:end of play/rec ioctl bytes = %d!!\n", retval);
328
329out_free:
330 kfree(tmp_buf);
317 return retval; 331 return retval;
318} 332}
319 333
@@ -377,7 +391,7 @@ static int snd_sst_fill_kernel_list(struct stream_info *stream,
377{ 391{
378 struct sst_stream_bufs *stream_bufs; 392 struct sst_stream_bufs *stream_bufs;
379 unsigned long index, mmap_len; 393 unsigned long index, mmap_len;
380 unsigned char *bufp; 394 unsigned char __user *bufp;
381 unsigned long size, copied_size; 395 unsigned long size, copied_size;
382 int retval = 0, add_to_list = 0; 396 int retval = 0, add_to_list = 0;
383 static int sent_offset; 397 static int sent_offset;
@@ -512,9 +526,7 @@ static int snd_sst_copy_userbuf_capture(struct stream_info *stream,
512 /* copy to user */ 526 /* copy to user */
513 list_for_each_entry_safe(entry, _entry, 527 list_for_each_entry_safe(entry, _entry,
514 copy_to_list, node) { 528 copy_to_list, node) {
515 if (copy_to_user((void *) 529 if (copy_to_user(iovec[entry->iov_index].iov_base + entry->iov_offset,
516 iovec[entry->iov_index].iov_base +
517 entry->iov_offset,
518 kbufs->addr + entry->offset, 530 kbufs->addr + entry->offset,
519 entry->size)) { 531 entry->size)) {
520 /* Clean up the list and return error */ 532 /* Clean up the list and return error */
@@ -590,7 +602,7 @@ static int intel_sst_read_write(unsigned int str_id, char __user *buf,
590 buf, (int) count, (int) stream->status); 602 buf, (int) count, (int) stream->status);
591 603
592 stream->buf_type = SST_BUF_USER_STATIC; 604 stream->buf_type = SST_BUF_USER_STATIC;
593 iovec.iov_base = (void *)buf; 605 iovec.iov_base = buf;
594 iovec.iov_len = count; 606 iovec.iov_len = count;
595 nr_segs = 1; 607 nr_segs = 1;
596 608
@@ -838,7 +850,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
838 break; 850 break;
839 851
840 case _IOC_NR(SNDRV_SST_STREAM_SET_PARAMS): { 852 case _IOC_NR(SNDRV_SST_STREAM_SET_PARAMS): {
841 struct snd_sst_params *str_param = (struct snd_sst_params *)arg; 853 struct snd_sst_params str_param;
842 854
843 pr_debug("sst: IOCTL_SET_PARAMS recieved!\n"); 855 pr_debug("sst: IOCTL_SET_PARAMS recieved!\n");
844 if (minor != STREAM_MODULE) { 856 if (minor != STREAM_MODULE) {
@@ -846,17 +858,25 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
846 break; 858 break;
847 } 859 }
848 860
861 if (copy_from_user(&str_param, (void __user *)arg,
862 sizeof(str_param))) {
863 retval = -EFAULT;
864 break;
865 }
866
849 if (!str_id) { 867 if (!str_id) {
850 868
851 retval = sst_get_stream(str_param); 869 retval = sst_get_stream(&str_param);
852 if (retval > 0) { 870 if (retval > 0) {
853 struct stream_info *str_info; 871 struct stream_info *str_info;
872 char __user *dest;
873
854 sst_drv_ctx->stream_cnt++; 874 sst_drv_ctx->stream_cnt++;
855 data->str_id = retval; 875 data->str_id = retval;
856 str_info = &sst_drv_ctx->streams[retval]; 876 str_info = &sst_drv_ctx->streams[retval];
857 str_info->src = SST_DRV; 877 str_info->src = SST_DRV;
858 retval = copy_to_user(&str_param->stream_id, 878 dest = (char __user *)arg + offsetof(struct snd_sst_params, stream_id);
859 &retval, sizeof(__u32)); 879 retval = copy_to_user(dest, &retval, sizeof(__u32));
860 if (retval) 880 if (retval)
861 retval = -EFAULT; 881 retval = -EFAULT;
862 } else { 882 } else {
@@ -866,16 +886,14 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
866 } else { 886 } else {
867 pr_debug("sst: SET_STREAM_PARAMS recieved!\n"); 887 pr_debug("sst: SET_STREAM_PARAMS recieved!\n");
868 /* allocated set params only */ 888 /* allocated set params only */
869 retval = sst_set_stream_param(str_id, str_param); 889 retval = sst_set_stream_param(str_id, &str_param);
870 /* Block the call for reply */ 890 /* Block the call for reply */
871 if (!retval) { 891 if (!retval) {
872 int sfreq = 0, word_size = 0, num_channel = 0; 892 int sfreq = 0, word_size = 0, num_channel = 0;
873 sfreq = str_param->sparams.uc.pcm_params.sfreq; 893 sfreq = str_param.sparams.uc.pcm_params.sfreq;
874 word_size = str_param->sparams. 894 word_size = str_param.sparams.uc.pcm_params.pcm_wd_sz;
875 uc.pcm_params.pcm_wd_sz; 895 num_channel = str_param.sparams.uc.pcm_params.num_chan;
876 num_channel = str_param-> 896 if (str_param.ops == STREAM_OPS_CAPTURE) {
877 sparams.uc.pcm_params.num_chan;
878 if (str_param->ops == STREAM_OPS_CAPTURE) {
879 sst_drv_ctx->scard_ops->\ 897 sst_drv_ctx->scard_ops->\
880 set_pcm_audio_params(sfreq, 898 set_pcm_audio_params(sfreq,
881 word_size, num_channel); 899 word_size, num_channel);
@@ -885,41 +903,39 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
885 break; 903 break;
886 } 904 }
887 case _IOC_NR(SNDRV_SST_SET_VOL): { 905 case _IOC_NR(SNDRV_SST_SET_VOL): {
888 struct snd_sst_vol *set_vol; 906 struct snd_sst_vol set_vol;
889 struct snd_sst_vol *rec_vol = (struct snd_sst_vol *)arg; 907
908 if (copy_from_user(&set_vol, (void __user *)arg,
909 sizeof(set_vol))) {
910 pr_debug("sst: copy failed\n");
911 retval = -EFAULT;
912 break;
913 }
890 pr_debug("sst: SET_VOLUME recieved for %d!\n", 914 pr_debug("sst: SET_VOLUME recieved for %d!\n",
891 rec_vol->stream_id); 915 set_vol.stream_id);
892 if (minor == STREAM_MODULE && rec_vol->stream_id == 0) { 916 if (minor == STREAM_MODULE && set_vol.stream_id == 0) {
893 pr_debug("sst: invalid operation!\n"); 917 pr_debug("sst: invalid operation!\n");
894 retval = -EPERM; 918 retval = -EPERM;
895 break; 919 break;
896 } 920 }
897 set_vol = kzalloc(sizeof(*set_vol), GFP_ATOMIC); 921 retval = sst_set_vol(&set_vol);
898 if (!set_vol) {
899 pr_debug("sst: mem allocation failed\n");
900 retval = -ENOMEM;
901 break;
902 }
903 if (copy_from_user(set_vol, rec_vol, sizeof(*set_vol))) {
904 pr_debug("sst: copy failed\n");
905 retval = -EFAULT;
906 break;
907 }
908 retval = sst_set_vol(set_vol);
909 kfree(set_vol);
910 break; 922 break;
911 } 923 }
912 case _IOC_NR(SNDRV_SST_GET_VOL): { 924 case _IOC_NR(SNDRV_SST_GET_VOL): {
913 struct snd_sst_vol *rec_vol = (struct snd_sst_vol *)arg;
914 struct snd_sst_vol get_vol; 925 struct snd_sst_vol get_vol;
926
927 if (copy_from_user(&get_vol, (void __user *)arg,
928 sizeof(get_vol))) {
929 retval = -EFAULT;
930 break;
931 }
915 pr_debug("sst: IOCTL_GET_VOLUME recieved for stream = %d!\n", 932 pr_debug("sst: IOCTL_GET_VOLUME recieved for stream = %d!\n",
916 rec_vol->stream_id); 933 get_vol.stream_id);
917 if (minor == STREAM_MODULE && rec_vol->stream_id == 0) { 934 if (minor == STREAM_MODULE && get_vol.stream_id == 0) {
918 pr_debug("sst: invalid operation!\n"); 935 pr_debug("sst: invalid operation!\n");
919 retval = -EPERM; 936 retval = -EPERM;
920 break; 937 break;
921 } 938 }
922 get_vol.stream_id = rec_vol->stream_id;
923 retval = sst_get_vol(&get_vol); 939 retval = sst_get_vol(&get_vol);
924 if (retval) { 940 if (retval) {
925 retval = -EIO; 941 retval = -EIO;
@@ -928,7 +944,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
928 pr_debug("sst: id:%d\n, vol:%d, ramp_dur:%d, ramp_type:%d\n", 944 pr_debug("sst: id:%d\n, vol:%d, ramp_dur:%d, ramp_type:%d\n",
929 get_vol.stream_id, get_vol.volume, 945 get_vol.stream_id, get_vol.volume,
930 get_vol.ramp_duration, get_vol.ramp_type); 946 get_vol.ramp_duration, get_vol.ramp_type);
931 if (copy_to_user((struct snd_sst_vol *)arg, 947 if (copy_to_user((struct snd_sst_vol __user *)arg,
932 &get_vol, sizeof(get_vol))) { 948 &get_vol, sizeof(get_vol))) {
933 retval = -EFAULT; 949 retval = -EFAULT;
934 break; 950 break;
@@ -938,25 +954,20 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
938 } 954 }
939 955
940 case _IOC_NR(SNDRV_SST_MUTE): { 956 case _IOC_NR(SNDRV_SST_MUTE): {
941 struct snd_sst_mute *set_mute; 957 struct snd_sst_mute set_mute;
942 struct snd_sst_vol *rec_mute = (struct snd_sst_vol *)arg; 958
943 pr_debug("sst: SNDRV_SST_SET_VOLUME recieved for %d!\n", 959 if (copy_from_user(&set_mute, (void __user *)arg,
944 rec_mute->stream_id); 960 sizeof(set_mute))) {
945 if (minor == STREAM_MODULE && rec_mute->stream_id == 0) { 961 retval = -EFAULT;
946 retval = -EPERM;
947 break;
948 }
949 set_mute = kzalloc(sizeof(*set_mute), GFP_ATOMIC);
950 if (!set_mute) {
951 retval = -ENOMEM;
952 break; 962 break;
953 } 963 }
954 if (copy_from_user(set_mute, rec_mute, sizeof(*set_mute))) { 964 pr_debug("sst: SNDRV_SST_SET_VOLUME recieved for %d!\n",
955 retval = -EFAULT; 965 set_mute.stream_id);
966 if (minor == STREAM_MODULE && set_mute.stream_id == 0) {
967 retval = -EPERM;
956 break; 968 break;
957 } 969 }
958 retval = sst_set_mute(set_mute); 970 retval = sst_set_mute(&set_mute);
959 kfree(set_mute);
960 break; 971 break;
961 } 972 }
962 case _IOC_NR(SNDRV_SST_STREAM_GET_PARAMS): { 973 case _IOC_NR(SNDRV_SST_STREAM_GET_PARAMS): {
@@ -973,7 +984,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
973 retval = -EIO; 984 retval = -EIO;
974 break; 985 break;
975 } 986 }
976 if (copy_to_user((struct snd_sst_get_stream_params *)arg, 987 if (copy_to_user((struct snd_sst_get_stream_params __user *)arg,
977 &get_params, sizeof(get_params))) { 988 &get_params, sizeof(get_params))) {
978 retval = -EFAULT; 989 retval = -EFAULT;
979 break; 990 break;
@@ -983,16 +994,22 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
983 } 994 }
984 995
985 case _IOC_NR(SNDRV_SST_MMAP_PLAY): 996 case _IOC_NR(SNDRV_SST_MMAP_PLAY):
986 case _IOC_NR(SNDRV_SST_MMAP_CAPTURE): 997 case _IOC_NR(SNDRV_SST_MMAP_CAPTURE): {
998 struct snd_sst_mmap_buffs mmap_buf;
999
987 pr_debug("sst: SNDRV_SST_MMAP_PLAY/CAPTURE recieved!\n"); 1000 pr_debug("sst: SNDRV_SST_MMAP_PLAY/CAPTURE recieved!\n");
988 if (minor != STREAM_MODULE) { 1001 if (minor != STREAM_MODULE) {
989 retval = -EBADRQC; 1002 retval = -EBADRQC;
990 break; 1003 break;
991 } 1004 }
992 retval = intel_sst_mmap_play_capture(str_id, 1005 if (copy_from_user(&mmap_buf, (void __user *)arg,
993 (struct snd_sst_mmap_buffs *)arg); 1006 sizeof(mmap_buf))) {
1007 retval = -EFAULT;
1008 break;
1009 }
1010 retval = intel_sst_mmap_play_capture(str_id, &mmap_buf);
994 break; 1011 break;
995 1012 }
996 case _IOC_NR(SNDRV_SST_STREAM_DROP): 1013 case _IOC_NR(SNDRV_SST_STREAM_DROP):
997 pr_debug("sst: SNDRV_SST_IOCTL_DROP recieved!\n"); 1014 pr_debug("sst: SNDRV_SST_IOCTL_DROP recieved!\n");
998 if (minor != STREAM_MODULE) { 1015 if (minor != STREAM_MODULE) {
@@ -1003,7 +1020,6 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1003 break; 1020 break;
1004 1021
1005 case _IOC_NR(SNDRV_SST_STREAM_GET_TSTAMP): { 1022 case _IOC_NR(SNDRV_SST_STREAM_GET_TSTAMP): {
1006 unsigned long long *ms = (unsigned long long *)arg;
1007 struct snd_sst_tstamp tstamp = {0}; 1023 struct snd_sst_tstamp tstamp = {0};
1008 unsigned long long time, freq, mod; 1024 unsigned long long time, freq, mod;
1009 1025
@@ -1013,14 +1029,14 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1013 break; 1029 break;
1014 } 1030 }
1015 memcpy_fromio(&tstamp, 1031 memcpy_fromio(&tstamp,
1016 ((void *)(sst_drv_ctx->mailbox + SST_TIME_STAMP) 1032 sst_drv_ctx->mailbox + SST_TIME_STAMP + str_id * sizeof(tstamp),
1017 +(str_id * sizeof(tstamp))),
1018 sizeof(tstamp)); 1033 sizeof(tstamp));
1019 time = tstamp.samples_rendered; 1034 time = tstamp.samples_rendered;
1020 freq = (unsigned long long) tstamp.sampling_frequency; 1035 freq = (unsigned long long) tstamp.sampling_frequency;
1021 time = time * 1000; /* converting it to ms */ 1036 time = time * 1000; /* converting it to ms */
1022 mod = do_div(time, freq); 1037 mod = do_div(time, freq);
1023 if (copy_to_user(ms, &time, sizeof(*ms))) 1038 if (copy_to_user((void __user *)arg, &time,
1039 sizeof(unsigned long long)))
1024 retval = -EFAULT; 1040 retval = -EFAULT;
1025 break; 1041 break;
1026 } 1042 }
@@ -1065,92 +1081,118 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1065 } 1081 }
1066 1082
1067 case _IOC_NR(SNDRV_SST_SET_TARGET_DEVICE): { 1083 case _IOC_NR(SNDRV_SST_SET_TARGET_DEVICE): {
1068 struct snd_sst_target_device *target_device; 1084 struct snd_sst_target_device target_device;
1069 1085
1070 pr_debug("sst: SET_TARGET_DEVICE recieved!\n"); 1086 pr_debug("sst: SET_TARGET_DEVICE recieved!\n");
1071 target_device = (struct snd_sst_target_device *)arg; 1087 if (copy_from_user(&target_device, (void __user *)arg,
1072 BUG_ON(!target_device); 1088 sizeof(target_device))) {
1089 retval = -EFAULT;
1090 break;
1091 }
1073 if (minor != AM_MODULE) { 1092 if (minor != AM_MODULE) {
1074 retval = -EBADRQC; 1093 retval = -EBADRQC;
1075 break; 1094 break;
1076 } 1095 }
1077 retval = sst_target_device_select(target_device); 1096 retval = sst_target_device_select(&target_device);
1078 break; 1097 break;
1079 } 1098 }
1080 1099
1081 case _IOC_NR(SNDRV_SST_DRIVER_INFO): { 1100 case _IOC_NR(SNDRV_SST_DRIVER_INFO): {
1082 struct snd_sst_driver_info *info = 1101 struct snd_sst_driver_info info;
1083 (struct snd_sst_driver_info *)arg;
1084 1102
1085 pr_debug("sst: SNDRV_SST_DRIVER_INFO recived\n"); 1103 pr_debug("sst: SNDRV_SST_DRIVER_INFO recived\n");
1086 info->version = SST_VERSION_NUM; 1104 info.version = SST_VERSION_NUM;
1087 /* hard coding, shud get sumhow later */ 1105 /* hard coding, shud get sumhow later */
1088 info->active_pcm_streams = sst_drv_ctx->stream_cnt - 1106 info.active_pcm_streams = sst_drv_ctx->stream_cnt -
1089 sst_drv_ctx->encoded_cnt; 1107 sst_drv_ctx->encoded_cnt;
1090 info->active_enc_streams = sst_drv_ctx->encoded_cnt; 1108 info.active_enc_streams = sst_drv_ctx->encoded_cnt;
1091 info->max_pcm_streams = MAX_ACTIVE_STREAM - MAX_ENC_STREAM; 1109 info.max_pcm_streams = MAX_ACTIVE_STREAM - MAX_ENC_STREAM;
1092 info->max_enc_streams = MAX_ENC_STREAM; 1110 info.max_enc_streams = MAX_ENC_STREAM;
1093 info->buf_per_stream = sst_drv_ctx->mmap_len; 1111 info.buf_per_stream = sst_drv_ctx->mmap_len;
1112 if (copy_to_user((void __user *)arg, &info,
1113 sizeof(info)))
1114 retval = -EFAULT;
1094 break; 1115 break;
1095 } 1116 }
1096 1117
1097 case _IOC_NR(SNDRV_SST_STREAM_DECODE): { 1118 case _IOC_NR(SNDRV_SST_STREAM_DECODE): {
1098 struct snd_sst_dbufs *param = 1119 struct snd_sst_dbufs param;
1099 (struct snd_sst_dbufs *)arg, dbufs_local; 1120 struct snd_sst_dbufs dbufs_local;
1100 int i;
1101 struct snd_sst_buffs ibufs, obufs; 1121 struct snd_sst_buffs ibufs, obufs;
1102 struct snd_sst_buff_entry ibuf_temp[param->ibufs->entries], 1122 struct snd_sst_buff_entry *ibuf_tmp, *obuf_tmp;
1103 obuf_temp[param->obufs->entries]; 1123 char __user *dest;
1104 1124
1105 pr_debug("sst: SNDRV_SST_STREAM_DECODE recived\n"); 1125 pr_debug("sst: SNDRV_SST_STREAM_DECODE recived\n");
1106 if (minor != STREAM_MODULE) { 1126 if (minor != STREAM_MODULE) {
1107 retval = -EBADRQC; 1127 retval = -EBADRQC;
1108 break; 1128 break;
1109 } 1129 }
1110 if (!param) { 1130 if (copy_from_user(&param, (void __user *)arg,
1111 retval = -EINVAL; 1131 sizeof(param))) {
1132 retval = -EFAULT;
1112 break; 1133 break;
1113 } 1134 }
1114 1135
1115 dbufs_local.input_bytes_consumed = param->input_bytes_consumed; 1136 dbufs_local.input_bytes_consumed = param.input_bytes_consumed;
1116 dbufs_local.output_bytes_produced = 1137 dbufs_local.output_bytes_produced =
1117 param->output_bytes_produced; 1138 param.output_bytes_produced;
1118 dbufs_local.ibufs = &ibufs; 1139
1119 dbufs_local.obufs = &obufs; 1140 if (copy_from_user(&ibufs, (void __user *)param.ibufs, sizeof(ibufs))) {
1120 dbufs_local.ibufs->entries = param->ibufs->entries; 1141 retval = -EFAULT;
1121 dbufs_local.ibufs->type = param->ibufs->type; 1142 break;
1122 dbufs_local.obufs->entries = param->obufs->entries; 1143 }
1123 dbufs_local.obufs->type = param->obufs->type; 1144 if (copy_from_user(&obufs, (void __user *)param.obufs, sizeof(obufs))) {
1124 1145 retval = -EFAULT;
1125 dbufs_local.ibufs->buff_entry = ibuf_temp; 1146 break;
1126 for (i = 0; i < dbufs_local.ibufs->entries; i++) {
1127 ibuf_temp[i].buffer =
1128 param->ibufs->buff_entry[i].buffer;
1129 ibuf_temp[i].size =
1130 param->ibufs->buff_entry[i].size;
1131 } 1147 }
1132 dbufs_local.obufs->buff_entry = obuf_temp; 1148
1133 for (i = 0; i < dbufs_local.obufs->entries; i++) { 1149 ibuf_tmp = kcalloc(ibufs.entries, sizeof(*ibuf_tmp), GFP_KERNEL);
1134 obuf_temp[i].buffer = 1150 obuf_tmp = kcalloc(obufs.entries, sizeof(*obuf_tmp), GFP_KERNEL);
1135 param->obufs->buff_entry[i].buffer; 1151 if (!ibuf_tmp || !obuf_tmp) {
1136 obuf_temp[i].size = 1152 retval = -ENOMEM;
1137 param->obufs->buff_entry[i].size; 1153 goto free_iobufs;
1154 }
1155
1156 if (copy_from_user(ibuf_tmp, (void __user *)ibufs.buff_entry,
1157 ibufs.entries * sizeof(*ibuf_tmp))) {
1158 retval = -EFAULT;
1159 goto free_iobufs;
1138 } 1160 }
1161 ibufs.buff_entry = ibuf_tmp;
1162 dbufs_local.ibufs = &ibufs;
1163
1164 if (copy_from_user(obuf_tmp, (void __user *)obufs.buff_entry,
1165 obufs.entries * sizeof(*obuf_tmp))) {
1166 retval = -EFAULT;
1167 goto free_iobufs;
1168 }
1169 obufs.buff_entry = obuf_tmp;
1170 dbufs_local.obufs = &obufs;
1171
1139 retval = sst_decode(str_id, &dbufs_local); 1172 retval = sst_decode(str_id, &dbufs_local);
1140 if (retval) 1173 if (retval) {
1141 retval = -EAGAIN; 1174 retval = -EAGAIN;
1142 if (copy_to_user(&param->input_bytes_consumed, 1175 goto free_iobufs;
1176 }
1177
1178 dest = (char __user *)arg + offsetof(struct snd_sst_dbufs, input_bytes_consumed);
1179 if (copy_to_user(dest,
1143 &dbufs_local.input_bytes_consumed, 1180 &dbufs_local.input_bytes_consumed,
1144 sizeof(unsigned long long))) { 1181 sizeof(unsigned long long))) {
1145 retval = -EFAULT; 1182 retval = -EFAULT;
1146 break; 1183 goto free_iobufs;
1147 } 1184 }
1148 if (copy_to_user(&param->output_bytes_produced, 1185
1186 dest = (char __user *)arg + offsetof(struct snd_sst_dbufs, input_bytes_consumed);
1187 if (copy_to_user(dest,
1149 &dbufs_local.output_bytes_produced, 1188 &dbufs_local.output_bytes_produced,
1150 sizeof(unsigned long long))) { 1189 sizeof(unsigned long long))) {
1151 retval = -EFAULT; 1190 retval = -EFAULT;
1152 break; 1191 goto free_iobufs;
1153 } 1192 }
1193free_iobufs:
1194 kfree(ibuf_tmp);
1195 kfree(obuf_tmp);
1154 break; 1196 break;
1155 } 1197 }
1156 1198
@@ -1164,7 +1206,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1164 break; 1206 break;
1165 1207
1166 case _IOC_NR(SNDRV_SST_STREAM_BYTES_DECODED): { 1208 case _IOC_NR(SNDRV_SST_STREAM_BYTES_DECODED): {
1167 unsigned long long *bytes = (unsigned long long *)arg; 1209 unsigned long long __user *bytes = (unsigned long long __user *)arg;
1168 struct snd_sst_tstamp tstamp = {0}; 1210 struct snd_sst_tstamp tstamp = {0};
1169 1211
1170 pr_debug("sst: STREAM_BYTES_DECODED recieved!\n"); 1212 pr_debug("sst: STREAM_BYTES_DECODED recieved!\n");
@@ -1173,8 +1215,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1173 break; 1215 break;
1174 } 1216 }
1175 memcpy_fromio(&tstamp, 1217 memcpy_fromio(&tstamp,
1176 ((void *)(sst_drv_ctx->mailbox + SST_TIME_STAMP) 1218 sst_drv_ctx->mailbox + SST_TIME_STAMP + str_id * sizeof(tstamp),
1177 +(str_id * sizeof(tstamp))),
1178 sizeof(tstamp)); 1219 sizeof(tstamp));
1179 if (copy_to_user(bytes, &tstamp.bytes_processed, 1220 if (copy_to_user(bytes, &tstamp.bytes_processed,
1180 sizeof(*bytes))) 1221 sizeof(*bytes)))
@@ -1197,7 +1238,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1197 kfree(fw_info); 1238 kfree(fw_info);
1198 break; 1239 break;
1199 } 1240 }
1200 if (copy_to_user((struct snd_sst_dbufs *)arg, 1241 if (copy_to_user((struct snd_sst_dbufs __user *)arg,
1201 fw_info, sizeof(*fw_info))) { 1242 fw_info, sizeof(*fw_info))) {
1202 kfree(fw_info); 1243 kfree(fw_info);
1203 retval = -EFAULT; 1244 retval = -EFAULT;
diff --git a/drivers/staging/intel_sst/intel_sst_common.h b/drivers/staging/intel_sst/intel_sst_common.h
index 73a98c851e4a..bf0ead78bfae 100644
--- a/drivers/staging/intel_sst/intel_sst_common.h
+++ b/drivers/staging/intel_sst/intel_sst_common.h
@@ -231,8 +231,8 @@ struct stream_info {
231 spinlock_t pcm_lock; 231 spinlock_t pcm_lock;
232 bool mmapped; 232 bool mmapped;
233 unsigned int sg_index; /* current buf Index */ 233 unsigned int sg_index; /* current buf Index */
234 unsigned char *cur_ptr; /* Current static bufs */ 234 unsigned char __user *cur_ptr; /* Current static bufs */
235 struct snd_sst_buf_entry *buf_entry; 235 struct snd_sst_buf_entry __user *buf_entry;
236 struct sst_block data_blk; /* stream ops block */ 236 struct sst_block data_blk; /* stream ops block */
237 struct sst_block ctrl_blk; /* stream control cmd block */ 237 struct sst_block ctrl_blk; /* stream control cmd block */
238 enum snd_sst_buf_type buf_type; 238 enum snd_sst_buf_type buf_type;
diff --git a/drivers/staging/intel_sst/intel_sst_stream_encoded.c b/drivers/staging/intel_sst/intel_sst_stream_encoded.c
index fbae39fda5c0..5c455608b024 100644
--- a/drivers/staging/intel_sst/intel_sst_stream_encoded.c
+++ b/drivers/staging/intel_sst/intel_sst_stream_encoded.c
@@ -1269,7 +1269,7 @@ finish:
1269 dbufs->output_bytes_produced = total_output; 1269 dbufs->output_bytes_produced = total_output;
1270 str_info->status = str_info->prev; 1270 str_info->status = str_info->prev;
1271 str_info->prev = STREAM_DECODE; 1271 str_info->prev = STREAM_DECODE;
1272 str_info->decode_ibuf = NULL;
1273 kfree(str_info->decode_ibuf); 1272 kfree(str_info->decode_ibuf);
1273 str_info->decode_ibuf = NULL;
1274 return retval; 1274 return retval;
1275} 1275}
diff --git a/drivers/staging/keucr/init.c b/drivers/staging/keucr/init.c
index 1934805844f2..978bf87ff13d 100644
--- a/drivers/staging/keucr/init.c
+++ b/drivers/staging/keucr/init.c
@@ -22,7 +22,7 @@ int ENE_InitMedia(struct us_data *us)
22 int result; 22 int result;
23 BYTE MiscReg03 = 0; 23 BYTE MiscReg03 = 0;
24 24
25 printk("--- Initial Nedia ---\n"); 25 printk("--- Init Media ---\n");
26 result = ENE_Read_BYTE(us, REG_CARD_STATUS, &MiscReg03); 26 result = ENE_Read_BYTE(us, REG_CARD_STATUS, &MiscReg03);
27 if (result != USB_STOR_XFER_GOOD) 27 if (result != USB_STOR_XFER_GOOD)
28 { 28 {
@@ -64,7 +64,7 @@ int ENE_Read_BYTE(struct us_data *us, WORD index, void *buf)
64 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 64 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
65 int result; 65 int result;
66 66
67 memset(bcb, 0, sizeof(bcb)); 67 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
68 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 68 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
69 bcb->DataTransferLength = 0x01; 69 bcb->DataTransferLength = 0x01;
70 bcb->Flags = 0x80; 70 bcb->Flags = 0x80;
@@ -92,7 +92,7 @@ int ENE_SDInit(struct us_data *us)
92 return USB_STOR_TRANSPORT_ERROR; 92 return USB_STOR_TRANSPORT_ERROR;
93 } 93 }
94 94
95 memset(bcb, 0, sizeof(bcb)); 95 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
96 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 96 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
97 bcb->Flags = 0x80; 97 bcb->Flags = 0x80;
98 bcb->CDB[0] = 0xF2; 98 bcb->CDB[0] = 0xF2;
@@ -112,7 +112,7 @@ int ENE_SDInit(struct us_data *us)
112 return USB_STOR_TRANSPORT_ERROR; 112 return USB_STOR_TRANSPORT_ERROR;
113 } 113 }
114 114
115 memset(bcb, 0, sizeof(bcb)); 115 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
116 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 116 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
117 bcb->DataTransferLength = 0x200; 117 bcb->DataTransferLength = 0x200;
118 bcb->Flags = 0x80; 118 bcb->Flags = 0x80;
@@ -161,7 +161,7 @@ int ENE_MSInit(struct us_data *us)
161 return USB_STOR_TRANSPORT_ERROR; 161 return USB_STOR_TRANSPORT_ERROR;
162 } 162 }
163 163
164 memset(bcb, 0, sizeof(bcb)); 164 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
165 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 165 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
166 bcb->DataTransferLength = 0x200; 166 bcb->DataTransferLength = 0x200;
167 bcb->Flags = 0x80; 167 bcb->Flags = 0x80;
@@ -219,7 +219,7 @@ int ENE_SMInit(struct us_data *us)
219 return USB_STOR_TRANSPORT_ERROR; 219 return USB_STOR_TRANSPORT_ERROR;
220 } 220 }
221 221
222 memset(bcb, 0, sizeof(bcb)); 222 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
223 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 223 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
224 bcb->DataTransferLength = 0x200; 224 bcb->DataTransferLength = 0x200;
225 bcb->Flags = 0x80; 225 bcb->Flags = 0x80;
@@ -341,7 +341,7 @@ int ENE_LoadBinCode(struct us_data *us, BYTE flag)
341 break; 341 break;
342 } 342 }
343 343
344 memset(bcb, 0, sizeof(bcb)); 344 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
345 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 345 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
346 bcb->DataTransferLength = 0x800; 346 bcb->DataTransferLength = 0x800;
347 bcb->Flags =0x00; 347 bcb->Flags =0x00;
@@ -433,7 +433,7 @@ int ENE_Read_Data(struct us_data *us, void *buf, unsigned int length)
433 433
434 //printk("transport --- ENE_Read_Data\n"); 434 //printk("transport --- ENE_Read_Data\n");
435 // set up the command wrapper 435 // set up the command wrapper
436 memset(bcb, 0, sizeof(bcb)); 436 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
437 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 437 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
438 bcb->DataTransferLength = length; 438 bcb->DataTransferLength = length;
439 bcb->Flags =0x80; 439 bcb->Flags =0x80;
@@ -470,7 +470,7 @@ int ENE_Write_Data(struct us_data *us, void *buf, unsigned int length)
470 470
471 //printk("transport --- ENE_Write_Data\n"); 471 //printk("transport --- ENE_Write_Data\n");
472 // set up the command wrapper 472 // set up the command wrapper
473 memset(bcb, 0, sizeof(bcb)); 473 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
474 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 474 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
475 bcb->DataTransferLength = length; 475 bcb->DataTransferLength = length;
476 bcb->Flags =0x00; 476 bcb->Flags =0x00;
diff --git a/drivers/staging/keucr/ms.c b/drivers/staging/keucr/ms.c
index d4340a9da87d..9a3fdb4e4fe4 100644
--- a/drivers/staging/keucr/ms.c
+++ b/drivers/staging/keucr/ms.c
@@ -15,7 +15,7 @@ int MS_ReaderCopyBlock(struct us_data *us, WORD oldphy, WORD newphy, WORD PhyBlo
15 if (result != USB_STOR_XFER_GOOD) 15 if (result != USB_STOR_XFER_GOOD)
16 return USB_STOR_TRANSPORT_ERROR; 16 return USB_STOR_TRANSPORT_ERROR;
17 17
18 memset(bcb, 0, sizeof(bcb)); 18 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
19 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 19 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
20 bcb->DataTransferLength = 0x200*len; 20 bcb->DataTransferLength = 0x200*len;
21 bcb->Flags = 0x00; 21 bcb->Flags = 0x00;
@@ -53,7 +53,7 @@ int MS_ReaderReadPage(struct us_data *us, DWORD PhyBlockAddr, BYTE PageNum, PDWO
53 return USB_STOR_TRANSPORT_ERROR; 53 return USB_STOR_TRANSPORT_ERROR;
54 54
55 // Read Page Data 55 // Read Page Data
56 memset(bcb, 0, sizeof(bcb)); 56 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
57 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 57 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
58 bcb->DataTransferLength = 0x200; 58 bcb->DataTransferLength = 0x200;
59 bcb->Flags = 0x80; 59 bcb->Flags = 0x80;
@@ -69,7 +69,7 @@ int MS_ReaderReadPage(struct us_data *us, DWORD PhyBlockAddr, BYTE PageNum, PDWO
69 return USB_STOR_TRANSPORT_ERROR; 69 return USB_STOR_TRANSPORT_ERROR;
70 70
71 // Read Extra Data 71 // Read Extra Data
72 memset(bcb, 0, sizeof(bcb)); 72 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
73 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 73 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
74 bcb->DataTransferLength = 0x4; 74 bcb->DataTransferLength = 0x4;
75 bcb->Flags = 0x80; 75 bcb->Flags = 0x80;
@@ -108,7 +108,7 @@ int MS_ReaderEraseBlock(struct us_data *us, DWORD PhyBlockAddr)
108 if (result != USB_STOR_XFER_GOOD) 108 if (result != USB_STOR_XFER_GOOD)
109 return USB_STOR_TRANSPORT_ERROR; 109 return USB_STOR_TRANSPORT_ERROR;
110 110
111 memset(bcb, 0, sizeof(bcb)); 111 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
112 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 112 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
113 bcb->DataTransferLength = 0x200; 113 bcb->DataTransferLength = 0x200;
114 bcb->Flags = 0x80; 114 bcb->Flags = 0x80;
@@ -673,7 +673,7 @@ int MS_LibReadExtraBlock(struct us_data *us, DWORD PhyBlock, BYTE PageNum, BYTE
673 //printk("MS_LibReadExtraBlock --- PhyBlock = %x, PageNum = %x, blen = %x\n", PhyBlock, PageNum, blen); 673 //printk("MS_LibReadExtraBlock --- PhyBlock = %x, PageNum = %x, blen = %x\n", PhyBlock, PageNum, blen);
674 674
675 // Read Extra Data 675 // Read Extra Data
676 memset(bcb, 0, sizeof(bcb)); 676 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
677 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 677 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
678 bcb->DataTransferLength = 0x4 * blen; 678 bcb->DataTransferLength = 0x4 * blen;
679 bcb->Flags = 0x80; 679 bcb->Flags = 0x80;
@@ -700,7 +700,7 @@ int MS_LibReadExtra(struct us_data *us, DWORD PhyBlock, BYTE PageNum, MS_LibType
700 BYTE ExtBuf[4]; 700 BYTE ExtBuf[4];
701 701
702 //printk("MS_LibReadExtra --- PhyBlock = %x, PageNum = %x\n", PhyBlock, PageNum); 702 //printk("MS_LibReadExtra --- PhyBlock = %x, PageNum = %x\n", PhyBlock, PageNum);
703 memset(bcb, 0, sizeof(bcb)); 703 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
704 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 704 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
705 bcb->DataTransferLength = 0x4; 705 bcb->DataTransferLength = 0x4;
706 bcb->Flags = 0x80; 706 bcb->Flags = 0x80;
@@ -807,7 +807,7 @@ int MS_LibOverwriteExtra(struct us_data *us, DWORD PhyBlockAddr, BYTE PageNum, B
807 if (result != USB_STOR_XFER_GOOD) 807 if (result != USB_STOR_XFER_GOOD)
808 return USB_STOR_TRANSPORT_ERROR; 808 return USB_STOR_TRANSPORT_ERROR;
809 809
810 memset(bcb, 0, sizeof(bcb)); 810 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
811 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 811 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
812 bcb->DataTransferLength = 0x4; 812 bcb->DataTransferLength = 0x4;
813 bcb->Flags = 0x80; 813 bcb->Flags = 0x80;
diff --git a/drivers/staging/keucr/msscsi.c b/drivers/staging/keucr/msscsi.c
index ad0c5c629935..cb92d25acee0 100644
--- a/drivers/staging/keucr/msscsi.c
+++ b/drivers/staging/keucr/msscsi.c
@@ -145,7 +145,7 @@ int MS_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb)
145 } 145 }
146 146
147 // set up the command wrapper 147 // set up the command wrapper
148 memset(bcb, 0, sizeof(bcb)); 148 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
149 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 149 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
150 bcb->DataTransferLength = blenByte; 150 bcb->DataTransferLength = blenByte;
151 bcb->Flags = 0x80; 151 bcb->Flags = 0x80;
@@ -193,7 +193,7 @@ int MS_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb)
193 blkno = phyblk * 0x20 + PageNum; 193 blkno = phyblk * 0x20 + PageNum;
194 194
195 // set up the command wrapper 195 // set up the command wrapper
196 memset(bcb, 0, sizeof(bcb)); 196 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
197 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 197 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
198 bcb->DataTransferLength = 0x200 * len; 198 bcb->DataTransferLength = 0x200 * len;
199 bcb->Flags = 0x80; 199 bcb->Flags = 0x80;
@@ -250,7 +250,7 @@ int MS_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb)
250 } 250 }
251 251
252 // set up the command wrapper 252 // set up the command wrapper
253 memset(bcb, 0, sizeof(bcb)); 253 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
254 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 254 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
255 bcb->DataTransferLength = blenByte; 255 bcb->DataTransferLength = blenByte;
256 bcb->Flags = 0x00; 256 bcb->Flags = 0x00;
diff --git a/drivers/staging/keucr/scsiglue.c b/drivers/staging/keucr/scsiglue.c
index a2671404f7ac..da4f42af3838 100644
--- a/drivers/staging/keucr/scsiglue.c
+++ b/drivers/staging/keucr/scsiglue.c
@@ -87,7 +87,7 @@ static int slave_configure(struct scsi_device *sdev)
87 87
88/* This is always called with scsi_lock(host) held */ 88/* This is always called with scsi_lock(host) held */
89//----- queuecommand() --------------------- 89//----- queuecommand() ---------------------
90static int queuecommand(struct scsi_cmnd *srb, void (*done)(struct scsi_cmnd *)) 90static int queuecommand_lck(struct scsi_cmnd *srb, void (*done)(struct scsi_cmnd *))
91{ 91{
92 struct us_data *us = host_to_us(srb->device->host); 92 struct us_data *us = host_to_us(srb->device->host);
93 93
@@ -117,6 +117,8 @@ static int queuecommand(struct scsi_cmnd *srb, void (*done)(struct scsi_cmnd *))
117 return 0; 117 return 0;
118} 118}
119 119
120static DEF_SCSI_QCMD(queuecommand)
121
120/*********************************************************************** 122/***********************************************************************
121 * Error handling functions 123 * Error handling functions
122 ***********************************************************************/ 124 ***********************************************************************/
diff --git a/drivers/staging/keucr/sdscsi.c b/drivers/staging/keucr/sdscsi.c
index 6c332f850ebe..d646507a3611 100644
--- a/drivers/staging/keucr/sdscsi.c
+++ b/drivers/staging/keucr/sdscsi.c
@@ -152,7 +152,7 @@ int SD_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb)
152 bnByte = bn; 152 bnByte = bn;
153 153
154 // set up the command wrapper 154 // set up the command wrapper
155 memset(bcb, 0, sizeof(bcb)); 155 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
156 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 156 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
157 bcb->DataTransferLength = blenByte; 157 bcb->DataTransferLength = blenByte;
158 bcb->Flags = 0x80; 158 bcb->Flags = 0x80;
@@ -192,7 +192,7 @@ int SD_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb)
192 bnByte = bn; 192 bnByte = bn;
193 193
194 // set up the command wrapper 194 // set up the command wrapper
195 memset(bcb, 0, sizeof(bcb)); 195 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
196 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 196 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
197 bcb->DataTransferLength = blenByte; 197 bcb->DataTransferLength = blenByte;
198 bcb->Flags = 0x00; 198 bcb->Flags = 0x00;
diff --git a/drivers/staging/keucr/smilsub.c b/drivers/staging/keucr/smilsub.c
index 844b65988636..1b52535a388f 100644
--- a/drivers/staging/keucr/smilsub.c
+++ b/drivers/staging/keucr/smilsub.c
@@ -266,7 +266,7 @@ int Ssfdc_D_ReadSect(struct us_data *us, BYTE *buf,BYTE *redundant)
266 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 266 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
267 267
268 // Read sect data 268 // Read sect data
269 memset(bcb, 0, sizeof(bcb)); 269 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
270 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 270 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
271 bcb->DataTransferLength = 0x200; 271 bcb->DataTransferLength = 0x200;
272 bcb->Flags = 0x80; 272 bcb->Flags = 0x80;
@@ -281,7 +281,7 @@ int Ssfdc_D_ReadSect(struct us_data *us, BYTE *buf,BYTE *redundant)
281 return USB_STOR_TRANSPORT_ERROR; 281 return USB_STOR_TRANSPORT_ERROR;
282 282
283 // Read redundant 283 // Read redundant
284 memset(bcb, 0, sizeof(bcb)); 284 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
285 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 285 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
286 bcb->DataTransferLength = 0x10; 286 bcb->DataTransferLength = 0x10;
287 bcb->Flags = 0x80; 287 bcb->Flags = 0x80;
@@ -319,7 +319,7 @@ int Ssfdc_D_ReadBlock(struct us_data *us, WORD count, BYTE *buf,BYTE *redundant)
319 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 319 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
320 320
321 // Read sect data 321 // Read sect data
322 memset(bcb, 0, sizeof(bcb)); 322 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
323 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 323 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
324 bcb->DataTransferLength = 0x200*count; 324 bcb->DataTransferLength = 0x200*count;
325 bcb->Flags = 0x80; 325 bcb->Flags = 0x80;
@@ -334,7 +334,7 @@ int Ssfdc_D_ReadBlock(struct us_data *us, WORD count, BYTE *buf,BYTE *redundant)
334 return USB_STOR_TRANSPORT_ERROR; 334 return USB_STOR_TRANSPORT_ERROR;
335 335
336 // Read redundant 336 // Read redundant
337 memset(bcb, 0, sizeof(bcb)); 337 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
338 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 338 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
339 bcb->DataTransferLength = 0x10; 339 bcb->DataTransferLength = 0x10;
340 bcb->Flags = 0x80; 340 bcb->Flags = 0x80;
@@ -536,7 +536,7 @@ int Ssfdc_D_CopyBlock(struct us_data *us, WORD count, BYTE *buf,BYTE *redundant)
536 WriteAddr = WriteAddr*(WORD)Ssfdc.MaxSectors; 536 WriteAddr = WriteAddr*(WORD)Ssfdc.MaxSectors;
537 537
538 // Write sect data 538 // Write sect data
539 memset(bcb, 0, sizeof(bcb)); 539 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
540 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 540 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
541 bcb->DataTransferLength = 0x200*count; 541 bcb->DataTransferLength = 0x200*count;
542 bcb->Flags = 0x00; 542 bcb->Flags = 0x00;
@@ -754,7 +754,7 @@ int Ssfdc_D_WriteSectForCopy(struct us_data *us, BYTE *buf, BYTE *redundant)
754 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 754 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
755 755
756 // Write sect data 756 // Write sect data
757 memset(bcb, 0, sizeof(bcb)); 757 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
758 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 758 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
759 bcb->DataTransferLength = 0x200; 759 bcb->DataTransferLength = 0x200;
760 bcb->Flags = 0x00; 760 bcb->Flags = 0x00;
@@ -791,7 +791,7 @@ int Ssfdc_D_EraseBlock(struct us_data *us)
791 addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 791 addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
792 addr=addr*(WORD)Ssfdc.MaxSectors; 792 addr=addr*(WORD)Ssfdc.MaxSectors;
793 793
794 memset(bcb, 0, sizeof(bcb)); 794 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
795 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 795 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
796 bcb->DataTransferLength = 0x200; 796 bcb->DataTransferLength = 0x200;
797 bcb->Flags = 0x80; 797 bcb->Flags = 0x80;
@@ -827,7 +827,7 @@ int Ssfdc_D_ReadRedtData(struct us_data *us, BYTE *redundant)
827 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 827 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
828 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 828 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
829 829
830 memset(bcb, 0, sizeof(bcb)); 830 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
831 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 831 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
832 bcb->DataTransferLength = 0x10; 832 bcb->DataTransferLength = 0x10;
833 bcb->Flags = 0x80; 833 bcb->Flags = 0x80;
@@ -870,7 +870,7 @@ int Ssfdc_D_WriteRedtData(struct us_data *us, BYTE *redundant)
870 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 870 addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock;
871 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 871 addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector;
872 872
873 memset(bcb, 0, sizeof(bcb)); 873 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
874 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 874 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
875 bcb->DataTransferLength = 0x10; 875 bcb->DataTransferLength = 0x10;
876 bcb->Flags = 0x80; 876 bcb->Flags = 0x80;
diff --git a/drivers/staging/keucr/transport.c b/drivers/staging/keucr/transport.c
index fd98df643ab0..111160cce441 100644
--- a/drivers/staging/keucr/transport.c
+++ b/drivers/staging/keucr/transport.c
@@ -40,7 +40,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
40 us->current_urb->error_count = 0; 40 us->current_urb->error_count = 0;
41 us->current_urb->status = 0; 41 us->current_urb->status = 0;
42 42
43// us->current_urb->transfer_flags = URB_NO_SETUP_DMA_MAP; 43 us->current_urb->transfer_flags = 0;
44 if (us->current_urb->transfer_buffer == us->iobuf) 44 if (us->current_urb->transfer_buffer == us->iobuf)
45 us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 45 us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
46 us->current_urb->transfer_dma = us->iobuf_dma; 46 us->current_urb->transfer_dma = us->iobuf_dma;
diff --git a/drivers/staging/line6/control.c b/drivers/staging/line6/control.c
index 040e25ca6d33..67e23b6e2d35 100644
--- a/drivers/staging/line6/control.c
+++ b/drivers/staging/line6/control.c
@@ -266,210 +266,210 @@ VARIAX_PARAM_R(float, mix2);
266VARIAX_PARAM_R(float, mix1); 266VARIAX_PARAM_R(float, mix1);
267VARIAX_PARAM_R(int, pickup_wiring); 267VARIAX_PARAM_R(int, pickup_wiring);
268 268
269static DEVICE_ATTR(tweak, S_IWUGO | S_IRUGO, pod_get_tweak, pod_set_tweak); 269static DEVICE_ATTR(tweak, S_IWUSR | S_IRUGO, pod_get_tweak, pod_set_tweak);
270static DEVICE_ATTR(wah_position, S_IWUGO | S_IRUGO, pod_get_wah_position, 270static DEVICE_ATTR(wah_position, S_IWUSR | S_IRUGO, pod_get_wah_position,
271 pod_set_wah_position); 271 pod_set_wah_position);
272static DEVICE_ATTR(compression_gain, S_IWUGO | S_IRUGO, 272static DEVICE_ATTR(compression_gain, S_IWUSR | S_IRUGO,
273 pod_get_compression_gain, pod_set_compression_gain); 273 pod_get_compression_gain, pod_set_compression_gain);
274static DEVICE_ATTR(vol_pedal_position, S_IWUGO | S_IRUGO, 274static DEVICE_ATTR(vol_pedal_position, S_IWUSR | S_IRUGO,
275 pod_get_vol_pedal_position, pod_set_vol_pedal_position); 275 pod_get_vol_pedal_position, pod_set_vol_pedal_position);
276static DEVICE_ATTR(compression_threshold, S_IWUGO | S_IRUGO, 276static DEVICE_ATTR(compression_threshold, S_IWUSR | S_IRUGO,
277 pod_get_compression_threshold, 277 pod_get_compression_threshold,
278 pod_set_compression_threshold); 278 pod_set_compression_threshold);
279static DEVICE_ATTR(pan, S_IWUGO | S_IRUGO, pod_get_pan, pod_set_pan); 279static DEVICE_ATTR(pan, S_IWUSR | S_IRUGO, pod_get_pan, pod_set_pan);
280static DEVICE_ATTR(amp_model_setup, S_IWUGO | S_IRUGO, pod_get_amp_model_setup, 280static DEVICE_ATTR(amp_model_setup, S_IWUSR | S_IRUGO, pod_get_amp_model_setup,
281 pod_set_amp_model_setup); 281 pod_set_amp_model_setup);
282static DEVICE_ATTR(amp_model, S_IWUGO | S_IRUGO, pod_get_amp_model, 282static DEVICE_ATTR(amp_model, S_IWUSR | S_IRUGO, pod_get_amp_model,
283 pod_set_amp_model); 283 pod_set_amp_model);
284static DEVICE_ATTR(drive, S_IWUGO | S_IRUGO, pod_get_drive, pod_set_drive); 284static DEVICE_ATTR(drive, S_IWUSR | S_IRUGO, pod_get_drive, pod_set_drive);
285static DEVICE_ATTR(bass, S_IWUGO | S_IRUGO, pod_get_bass, pod_set_bass); 285static DEVICE_ATTR(bass, S_IWUSR | S_IRUGO, pod_get_bass, pod_set_bass);
286static DEVICE_ATTR(mid, S_IWUGO | S_IRUGO, pod_get_mid, pod_set_mid); 286static DEVICE_ATTR(mid, S_IWUSR | S_IRUGO, pod_get_mid, pod_set_mid);
287static DEVICE_ATTR(lowmid, S_IWUGO | S_IRUGO, pod_get_lowmid, pod_set_lowmid); 287static DEVICE_ATTR(lowmid, S_IWUSR | S_IRUGO, pod_get_lowmid, pod_set_lowmid);
288static DEVICE_ATTR(treble, S_IWUGO | S_IRUGO, pod_get_treble, pod_set_treble); 288static DEVICE_ATTR(treble, S_IWUSR | S_IRUGO, pod_get_treble, pod_set_treble);
289static DEVICE_ATTR(highmid, S_IWUGO | S_IRUGO, pod_get_highmid, 289static DEVICE_ATTR(highmid, S_IWUSR | S_IRUGO, pod_get_highmid,
290 pod_set_highmid); 290 pod_set_highmid);
291static DEVICE_ATTR(chan_vol, S_IWUGO | S_IRUGO, pod_get_chan_vol, 291static DEVICE_ATTR(chan_vol, S_IWUSR | S_IRUGO, pod_get_chan_vol,
292 pod_set_chan_vol); 292 pod_set_chan_vol);
293static DEVICE_ATTR(reverb_mix, S_IWUGO | S_IRUGO, pod_get_reverb_mix, 293static DEVICE_ATTR(reverb_mix, S_IWUSR | S_IRUGO, pod_get_reverb_mix,
294 pod_set_reverb_mix); 294 pod_set_reverb_mix);
295static DEVICE_ATTR(effect_setup, S_IWUGO | S_IRUGO, pod_get_effect_setup, 295static DEVICE_ATTR(effect_setup, S_IWUSR | S_IRUGO, pod_get_effect_setup,
296 pod_set_effect_setup); 296 pod_set_effect_setup);
297static DEVICE_ATTR(band_1_frequency, S_IWUGO | S_IRUGO, 297static DEVICE_ATTR(band_1_frequency, S_IWUSR | S_IRUGO,
298 pod_get_band_1_frequency, pod_set_band_1_frequency); 298 pod_get_band_1_frequency, pod_set_band_1_frequency);
299static DEVICE_ATTR(presence, S_IWUGO | S_IRUGO, pod_get_presence, 299static DEVICE_ATTR(presence, S_IWUSR | S_IRUGO, pod_get_presence,
300 pod_set_presence); 300 pod_set_presence);
301static DEVICE_ATTR2(treble__bass, treble, S_IWUGO | S_IRUGO, 301static DEVICE_ATTR2(treble__bass, treble, S_IWUSR | S_IRUGO,
302 pod_get_treble__bass, pod_set_treble__bass); 302 pod_get_treble__bass, pod_set_treble__bass);
303static DEVICE_ATTR(noise_gate_enable, S_IWUGO | S_IRUGO, 303static DEVICE_ATTR(noise_gate_enable, S_IWUSR | S_IRUGO,
304 pod_get_noise_gate_enable, pod_set_noise_gate_enable); 304 pod_get_noise_gate_enable, pod_set_noise_gate_enable);
305static DEVICE_ATTR(gate_threshold, S_IWUGO | S_IRUGO, pod_get_gate_threshold, 305static DEVICE_ATTR(gate_threshold, S_IWUSR | S_IRUGO, pod_get_gate_threshold,
306 pod_set_gate_threshold); 306 pod_set_gate_threshold);
307static DEVICE_ATTR(gate_decay_time, S_IWUGO | S_IRUGO, pod_get_gate_decay_time, 307static DEVICE_ATTR(gate_decay_time, S_IWUSR | S_IRUGO, pod_get_gate_decay_time,
308 pod_set_gate_decay_time); 308 pod_set_gate_decay_time);
309static DEVICE_ATTR(stomp_enable, S_IWUGO | S_IRUGO, pod_get_stomp_enable, 309static DEVICE_ATTR(stomp_enable, S_IWUSR | S_IRUGO, pod_get_stomp_enable,
310 pod_set_stomp_enable); 310 pod_set_stomp_enable);
311static DEVICE_ATTR(comp_enable, S_IWUGO | S_IRUGO, pod_get_comp_enable, 311static DEVICE_ATTR(comp_enable, S_IWUSR | S_IRUGO, pod_get_comp_enable,
312 pod_set_comp_enable); 312 pod_set_comp_enable);
313static DEVICE_ATTR(stomp_time, S_IWUGO | S_IRUGO, pod_get_stomp_time, 313static DEVICE_ATTR(stomp_time, S_IWUSR | S_IRUGO, pod_get_stomp_time,
314 pod_set_stomp_time); 314 pod_set_stomp_time);
315static DEVICE_ATTR(delay_enable, S_IWUGO | S_IRUGO, pod_get_delay_enable, 315static DEVICE_ATTR(delay_enable, S_IWUSR | S_IRUGO, pod_get_delay_enable,
316 pod_set_delay_enable); 316 pod_set_delay_enable);
317static DEVICE_ATTR(mod_param_1, S_IWUGO | S_IRUGO, pod_get_mod_param_1, 317static DEVICE_ATTR(mod_param_1, S_IWUSR | S_IRUGO, pod_get_mod_param_1,
318 pod_set_mod_param_1); 318 pod_set_mod_param_1);
319static DEVICE_ATTR(delay_param_1, S_IWUGO | S_IRUGO, pod_get_delay_param_1, 319static DEVICE_ATTR(delay_param_1, S_IWUSR | S_IRUGO, pod_get_delay_param_1,
320 pod_set_delay_param_1); 320 pod_set_delay_param_1);
321static DEVICE_ATTR(delay_param_1_note_value, S_IWUGO | S_IRUGO, 321static DEVICE_ATTR(delay_param_1_note_value, S_IWUSR | S_IRUGO,
322 pod_get_delay_param_1_note_value, 322 pod_get_delay_param_1_note_value,
323 pod_set_delay_param_1_note_value); 323 pod_set_delay_param_1_note_value);
324static DEVICE_ATTR2(band_2_frequency__bass, band_2_frequency, S_IWUGO | S_IRUGO, 324static DEVICE_ATTR2(band_2_frequency__bass, band_2_frequency, S_IWUSR | S_IRUGO,
325 pod_get_band_2_frequency__bass, 325 pod_get_band_2_frequency__bass,
326 pod_set_band_2_frequency__bass); 326 pod_set_band_2_frequency__bass);
327static DEVICE_ATTR(delay_param_2, S_IWUGO | S_IRUGO, pod_get_delay_param_2, 327static DEVICE_ATTR(delay_param_2, S_IWUSR | S_IRUGO, pod_get_delay_param_2,
328 pod_set_delay_param_2); 328 pod_set_delay_param_2);
329static DEVICE_ATTR(delay_volume_mix, S_IWUGO | S_IRUGO, 329static DEVICE_ATTR(delay_volume_mix, S_IWUSR | S_IRUGO,
330 pod_get_delay_volume_mix, pod_set_delay_volume_mix); 330 pod_get_delay_volume_mix, pod_set_delay_volume_mix);
331static DEVICE_ATTR(delay_param_3, S_IWUGO | S_IRUGO, pod_get_delay_param_3, 331static DEVICE_ATTR(delay_param_3, S_IWUSR | S_IRUGO, pod_get_delay_param_3,
332 pod_set_delay_param_3); 332 pod_set_delay_param_3);
333static DEVICE_ATTR(reverb_enable, S_IWUGO | S_IRUGO, pod_get_reverb_enable, 333static DEVICE_ATTR(reverb_enable, S_IWUSR | S_IRUGO, pod_get_reverb_enable,
334 pod_set_reverb_enable); 334 pod_set_reverb_enable);
335static DEVICE_ATTR(reverb_type, S_IWUGO | S_IRUGO, pod_get_reverb_type, 335static DEVICE_ATTR(reverb_type, S_IWUSR | S_IRUGO, pod_get_reverb_type,
336 pod_set_reverb_type); 336 pod_set_reverb_type);
337static DEVICE_ATTR(reverb_decay, S_IWUGO | S_IRUGO, pod_get_reverb_decay, 337static DEVICE_ATTR(reverb_decay, S_IWUSR | S_IRUGO, pod_get_reverb_decay,
338 pod_set_reverb_decay); 338 pod_set_reverb_decay);
339static DEVICE_ATTR(reverb_tone, S_IWUGO | S_IRUGO, pod_get_reverb_tone, 339static DEVICE_ATTR(reverb_tone, S_IWUSR | S_IRUGO, pod_get_reverb_tone,
340 pod_set_reverb_tone); 340 pod_set_reverb_tone);
341static DEVICE_ATTR(reverb_pre_delay, S_IWUGO | S_IRUGO, 341static DEVICE_ATTR(reverb_pre_delay, S_IWUSR | S_IRUGO,
342 pod_get_reverb_pre_delay, pod_set_reverb_pre_delay); 342 pod_get_reverb_pre_delay, pod_set_reverb_pre_delay);
343static DEVICE_ATTR(reverb_pre_post, S_IWUGO | S_IRUGO, pod_get_reverb_pre_post, 343static DEVICE_ATTR(reverb_pre_post, S_IWUSR | S_IRUGO, pod_get_reverb_pre_post,
344 pod_set_reverb_pre_post); 344 pod_set_reverb_pre_post);
345static DEVICE_ATTR(band_2_frequency, S_IWUGO | S_IRUGO, 345static DEVICE_ATTR(band_2_frequency, S_IWUSR | S_IRUGO,
346 pod_get_band_2_frequency, pod_set_band_2_frequency); 346 pod_get_band_2_frequency, pod_set_band_2_frequency);
347static DEVICE_ATTR2(band_3_frequency__bass, band_3_frequency, S_IWUGO | S_IRUGO, 347static DEVICE_ATTR2(band_3_frequency__bass, band_3_frequency, S_IWUSR | S_IRUGO,
348 pod_get_band_3_frequency__bass, 348 pod_get_band_3_frequency__bass,
349 pod_set_band_3_frequency__bass); 349 pod_set_band_3_frequency__bass);
350static DEVICE_ATTR(wah_enable, S_IWUGO | S_IRUGO, pod_get_wah_enable, 350static DEVICE_ATTR(wah_enable, S_IWUSR | S_IRUGO, pod_get_wah_enable,
351 pod_set_wah_enable); 351 pod_set_wah_enable);
352static DEVICE_ATTR(modulation_lo_cut, S_IWUGO | S_IRUGO, 352static DEVICE_ATTR(modulation_lo_cut, S_IWUSR | S_IRUGO,
353 pod_get_modulation_lo_cut, pod_set_modulation_lo_cut); 353 pod_get_modulation_lo_cut, pod_set_modulation_lo_cut);
354static DEVICE_ATTR(delay_reverb_lo_cut, S_IWUGO | S_IRUGO, 354static DEVICE_ATTR(delay_reverb_lo_cut, S_IWUSR | S_IRUGO,
355 pod_get_delay_reverb_lo_cut, pod_set_delay_reverb_lo_cut); 355 pod_get_delay_reverb_lo_cut, pod_set_delay_reverb_lo_cut);
356static DEVICE_ATTR(volume_pedal_minimum, S_IWUGO | S_IRUGO, 356static DEVICE_ATTR(volume_pedal_minimum, S_IWUSR | S_IRUGO,
357 pod_get_volume_pedal_minimum, pod_set_volume_pedal_minimum); 357 pod_get_volume_pedal_minimum, pod_set_volume_pedal_minimum);
358static DEVICE_ATTR(eq_pre_post, S_IWUGO | S_IRUGO, pod_get_eq_pre_post, 358static DEVICE_ATTR(eq_pre_post, S_IWUSR | S_IRUGO, pod_get_eq_pre_post,
359 pod_set_eq_pre_post); 359 pod_set_eq_pre_post);
360static DEVICE_ATTR(volume_pre_post, S_IWUGO | S_IRUGO, pod_get_volume_pre_post, 360static DEVICE_ATTR(volume_pre_post, S_IWUSR | S_IRUGO, pod_get_volume_pre_post,
361 pod_set_volume_pre_post); 361 pod_set_volume_pre_post);
362static DEVICE_ATTR(di_model, S_IWUGO | S_IRUGO, pod_get_di_model, 362static DEVICE_ATTR(di_model, S_IWUSR | S_IRUGO, pod_get_di_model,
363 pod_set_di_model); 363 pod_set_di_model);
364static DEVICE_ATTR(di_delay, S_IWUGO | S_IRUGO, pod_get_di_delay, 364static DEVICE_ATTR(di_delay, S_IWUSR | S_IRUGO, pod_get_di_delay,
365 pod_set_di_delay); 365 pod_set_di_delay);
366static DEVICE_ATTR(mod_enable, S_IWUGO | S_IRUGO, pod_get_mod_enable, 366static DEVICE_ATTR(mod_enable, S_IWUSR | S_IRUGO, pod_get_mod_enable,
367 pod_set_mod_enable); 367 pod_set_mod_enable);
368static DEVICE_ATTR(mod_param_1_note_value, S_IWUGO | S_IRUGO, 368static DEVICE_ATTR(mod_param_1_note_value, S_IWUSR | S_IRUGO,
369 pod_get_mod_param_1_note_value, 369 pod_get_mod_param_1_note_value,
370 pod_set_mod_param_1_note_value); 370 pod_set_mod_param_1_note_value);
371static DEVICE_ATTR(mod_param_2, S_IWUGO | S_IRUGO, pod_get_mod_param_2, 371static DEVICE_ATTR(mod_param_2, S_IWUSR | S_IRUGO, pod_get_mod_param_2,
372 pod_set_mod_param_2); 372 pod_set_mod_param_2);
373static DEVICE_ATTR(mod_param_3, S_IWUGO | S_IRUGO, pod_get_mod_param_3, 373static DEVICE_ATTR(mod_param_3, S_IWUSR | S_IRUGO, pod_get_mod_param_3,
374 pod_set_mod_param_3); 374 pod_set_mod_param_3);
375static DEVICE_ATTR(mod_param_4, S_IWUGO | S_IRUGO, pod_get_mod_param_4, 375static DEVICE_ATTR(mod_param_4, S_IWUSR | S_IRUGO, pod_get_mod_param_4,
376 pod_set_mod_param_4); 376 pod_set_mod_param_4);
377static DEVICE_ATTR(mod_param_5, S_IWUGO | S_IRUGO, pod_get_mod_param_5, 377static DEVICE_ATTR(mod_param_5, S_IWUSR | S_IRUGO, pod_get_mod_param_5,
378 pod_set_mod_param_5); 378 pod_set_mod_param_5);
379static DEVICE_ATTR(mod_volume_mix, S_IWUGO | S_IRUGO, pod_get_mod_volume_mix, 379static DEVICE_ATTR(mod_volume_mix, S_IWUSR | S_IRUGO, pod_get_mod_volume_mix,
380 pod_set_mod_volume_mix); 380 pod_set_mod_volume_mix);
381static DEVICE_ATTR(mod_pre_post, S_IWUGO | S_IRUGO, pod_get_mod_pre_post, 381static DEVICE_ATTR(mod_pre_post, S_IWUSR | S_IRUGO, pod_get_mod_pre_post,
382 pod_set_mod_pre_post); 382 pod_set_mod_pre_post);
383static DEVICE_ATTR(modulation_model, S_IWUGO | S_IRUGO, 383static DEVICE_ATTR(modulation_model, S_IWUSR | S_IRUGO,
384 pod_get_modulation_model, pod_set_modulation_model); 384 pod_get_modulation_model, pod_set_modulation_model);
385static DEVICE_ATTR(band_3_frequency, S_IWUGO | S_IRUGO, 385static DEVICE_ATTR(band_3_frequency, S_IWUSR | S_IRUGO,
386 pod_get_band_3_frequency, pod_set_band_3_frequency); 386 pod_get_band_3_frequency, pod_set_band_3_frequency);
387static DEVICE_ATTR2(band_4_frequency__bass, band_4_frequency, S_IWUGO | S_IRUGO, 387static DEVICE_ATTR2(band_4_frequency__bass, band_4_frequency, S_IWUSR | S_IRUGO,
388 pod_get_band_4_frequency__bass, 388 pod_get_band_4_frequency__bass,
389 pod_set_band_4_frequency__bass); 389 pod_set_band_4_frequency__bass);
390static DEVICE_ATTR(mod_param_1_double_precision, S_IWUGO | S_IRUGO, 390static DEVICE_ATTR(mod_param_1_double_precision, S_IWUSR | S_IRUGO,
391 pod_get_mod_param_1_double_precision, 391 pod_get_mod_param_1_double_precision,
392 pod_set_mod_param_1_double_precision); 392 pod_set_mod_param_1_double_precision);
393static DEVICE_ATTR(delay_param_1_double_precision, S_IWUGO | S_IRUGO, 393static DEVICE_ATTR(delay_param_1_double_precision, S_IWUSR | S_IRUGO,
394 pod_get_delay_param_1_double_precision, 394 pod_get_delay_param_1_double_precision,
395 pod_set_delay_param_1_double_precision); 395 pod_set_delay_param_1_double_precision);
396static DEVICE_ATTR(eq_enable, S_IWUGO | S_IRUGO, pod_get_eq_enable, 396static DEVICE_ATTR(eq_enable, S_IWUSR | S_IRUGO, pod_get_eq_enable,
397 pod_set_eq_enable); 397 pod_set_eq_enable);
398static DEVICE_ATTR(tap, S_IWUGO | S_IRUGO, pod_get_tap, pod_set_tap); 398static DEVICE_ATTR(tap, S_IWUSR | S_IRUGO, pod_get_tap, pod_set_tap);
399static DEVICE_ATTR(volume_tweak_pedal_assign, S_IWUGO | S_IRUGO, 399static DEVICE_ATTR(volume_tweak_pedal_assign, S_IWUSR | S_IRUGO,
400 pod_get_volume_tweak_pedal_assign, 400 pod_get_volume_tweak_pedal_assign,
401 pod_set_volume_tweak_pedal_assign); 401 pod_set_volume_tweak_pedal_assign);
402static DEVICE_ATTR(band_5_frequency, S_IWUGO | S_IRUGO, 402static DEVICE_ATTR(band_5_frequency, S_IWUSR | S_IRUGO,
403 pod_get_band_5_frequency, pod_set_band_5_frequency); 403 pod_get_band_5_frequency, pod_set_band_5_frequency);
404static DEVICE_ATTR(tuner, S_IWUGO | S_IRUGO, pod_get_tuner, pod_set_tuner); 404static DEVICE_ATTR(tuner, S_IWUSR | S_IRUGO, pod_get_tuner, pod_set_tuner);
405static DEVICE_ATTR(mic_selection, S_IWUGO | S_IRUGO, pod_get_mic_selection, 405static DEVICE_ATTR(mic_selection, S_IWUSR | S_IRUGO, pod_get_mic_selection,
406 pod_set_mic_selection); 406 pod_set_mic_selection);
407static DEVICE_ATTR(cabinet_model, S_IWUGO | S_IRUGO, pod_get_cabinet_model, 407static DEVICE_ATTR(cabinet_model, S_IWUSR | S_IRUGO, pod_get_cabinet_model,
408 pod_set_cabinet_model); 408 pod_set_cabinet_model);
409static DEVICE_ATTR(stomp_model, S_IWUGO | S_IRUGO, pod_get_stomp_model, 409static DEVICE_ATTR(stomp_model, S_IWUSR | S_IRUGO, pod_get_stomp_model,
410 pod_set_stomp_model); 410 pod_set_stomp_model);
411static DEVICE_ATTR(roomlevel, S_IWUGO | S_IRUGO, pod_get_roomlevel, 411static DEVICE_ATTR(roomlevel, S_IWUSR | S_IRUGO, pod_get_roomlevel,
412 pod_set_roomlevel); 412 pod_set_roomlevel);
413static DEVICE_ATTR(band_4_frequency, S_IWUGO | S_IRUGO, 413static DEVICE_ATTR(band_4_frequency, S_IWUSR | S_IRUGO,
414 pod_get_band_4_frequency, pod_set_band_4_frequency); 414 pod_get_band_4_frequency, pod_set_band_4_frequency);
415static DEVICE_ATTR(band_6_frequency, S_IWUGO | S_IRUGO, 415static DEVICE_ATTR(band_6_frequency, S_IWUSR | S_IRUGO,
416 pod_get_band_6_frequency, pod_set_band_6_frequency); 416 pod_get_band_6_frequency, pod_set_band_6_frequency);
417static DEVICE_ATTR(stomp_param_1_note_value, S_IWUGO | S_IRUGO, 417static DEVICE_ATTR(stomp_param_1_note_value, S_IWUSR | S_IRUGO,
418 pod_get_stomp_param_1_note_value, 418 pod_get_stomp_param_1_note_value,
419 pod_set_stomp_param_1_note_value); 419 pod_set_stomp_param_1_note_value);
420static DEVICE_ATTR(stomp_param_2, S_IWUGO | S_IRUGO, pod_get_stomp_param_2, 420static DEVICE_ATTR(stomp_param_2, S_IWUSR | S_IRUGO, pod_get_stomp_param_2,
421 pod_set_stomp_param_2); 421 pod_set_stomp_param_2);
422static DEVICE_ATTR(stomp_param_3, S_IWUGO | S_IRUGO, pod_get_stomp_param_3, 422static DEVICE_ATTR(stomp_param_3, S_IWUSR | S_IRUGO, pod_get_stomp_param_3,
423 pod_set_stomp_param_3); 423 pod_set_stomp_param_3);
424static DEVICE_ATTR(stomp_param_4, S_IWUGO | S_IRUGO, pod_get_stomp_param_4, 424static DEVICE_ATTR(stomp_param_4, S_IWUSR | S_IRUGO, pod_get_stomp_param_4,
425 pod_set_stomp_param_4); 425 pod_set_stomp_param_4);
426static DEVICE_ATTR(stomp_param_5, S_IWUGO | S_IRUGO, pod_get_stomp_param_5, 426static DEVICE_ATTR(stomp_param_5, S_IWUSR | S_IRUGO, pod_get_stomp_param_5,
427 pod_set_stomp_param_5); 427 pod_set_stomp_param_5);
428static DEVICE_ATTR(stomp_param_6, S_IWUGO | S_IRUGO, pod_get_stomp_param_6, 428static DEVICE_ATTR(stomp_param_6, S_IWUSR | S_IRUGO, pod_get_stomp_param_6,
429 pod_set_stomp_param_6); 429 pod_set_stomp_param_6);
430static DEVICE_ATTR(amp_switch_select, S_IWUGO | S_IRUGO, 430static DEVICE_ATTR(amp_switch_select, S_IWUSR | S_IRUGO,
431 pod_get_amp_switch_select, pod_set_amp_switch_select); 431 pod_get_amp_switch_select, pod_set_amp_switch_select);
432static DEVICE_ATTR(delay_param_4, S_IWUGO | S_IRUGO, pod_get_delay_param_4, 432static DEVICE_ATTR(delay_param_4, S_IWUSR | S_IRUGO, pod_get_delay_param_4,
433 pod_set_delay_param_4); 433 pod_set_delay_param_4);
434static DEVICE_ATTR(delay_param_5, S_IWUGO | S_IRUGO, pod_get_delay_param_5, 434static DEVICE_ATTR(delay_param_5, S_IWUSR | S_IRUGO, pod_get_delay_param_5,
435 pod_set_delay_param_5); 435 pod_set_delay_param_5);
436static DEVICE_ATTR(delay_pre_post, S_IWUGO | S_IRUGO, pod_get_delay_pre_post, 436static DEVICE_ATTR(delay_pre_post, S_IWUSR | S_IRUGO, pod_get_delay_pre_post,
437 pod_set_delay_pre_post); 437 pod_set_delay_pre_post);
438static DEVICE_ATTR(delay_model, S_IWUGO | S_IRUGO, pod_get_delay_model, 438static DEVICE_ATTR(delay_model, S_IWUSR | S_IRUGO, pod_get_delay_model,
439 pod_set_delay_model); 439 pod_set_delay_model);
440static DEVICE_ATTR(delay_verb_model, S_IWUGO | S_IRUGO, 440static DEVICE_ATTR(delay_verb_model, S_IWUSR | S_IRUGO,
441 pod_get_delay_verb_model, pod_set_delay_verb_model); 441 pod_get_delay_verb_model, pod_set_delay_verb_model);
442static DEVICE_ATTR(tempo_msb, S_IWUGO | S_IRUGO, pod_get_tempo_msb, 442static DEVICE_ATTR(tempo_msb, S_IWUSR | S_IRUGO, pod_get_tempo_msb,
443 pod_set_tempo_msb); 443 pod_set_tempo_msb);
444static DEVICE_ATTR(tempo_lsb, S_IWUGO | S_IRUGO, pod_get_tempo_lsb, 444static DEVICE_ATTR(tempo_lsb, S_IWUSR | S_IRUGO, pod_get_tempo_lsb,
445 pod_set_tempo_lsb); 445 pod_set_tempo_lsb);
446static DEVICE_ATTR(wah_model, S_IWUGO | S_IRUGO, pod_get_wah_model, 446static DEVICE_ATTR(wah_model, S_IWUSR | S_IRUGO, pod_get_wah_model,
447 pod_set_wah_model); 447 pod_set_wah_model);
448static DEVICE_ATTR(bypass_volume, S_IWUGO | S_IRUGO, pod_get_bypass_volume, 448static DEVICE_ATTR(bypass_volume, S_IWUSR | S_IRUGO, pod_get_bypass_volume,
449 pod_set_bypass_volume); 449 pod_set_bypass_volume);
450static DEVICE_ATTR(fx_loop_on_off, S_IWUGO | S_IRUGO, pod_get_fx_loop_on_off, 450static DEVICE_ATTR(fx_loop_on_off, S_IWUSR | S_IRUGO, pod_get_fx_loop_on_off,
451 pod_set_fx_loop_on_off); 451 pod_set_fx_loop_on_off);
452static DEVICE_ATTR(tweak_param_select, S_IWUGO | S_IRUGO, 452static DEVICE_ATTR(tweak_param_select, S_IWUSR | S_IRUGO,
453 pod_get_tweak_param_select, pod_set_tweak_param_select); 453 pod_get_tweak_param_select, pod_set_tweak_param_select);
454static DEVICE_ATTR(amp1_engage, S_IWUGO | S_IRUGO, pod_get_amp1_engage, 454static DEVICE_ATTR(amp1_engage, S_IWUSR | S_IRUGO, pod_get_amp1_engage,
455 pod_set_amp1_engage); 455 pod_set_amp1_engage);
456static DEVICE_ATTR(band_1_gain, S_IWUGO | S_IRUGO, pod_get_band_1_gain, 456static DEVICE_ATTR(band_1_gain, S_IWUSR | S_IRUGO, pod_get_band_1_gain,
457 pod_set_band_1_gain); 457 pod_set_band_1_gain);
458static DEVICE_ATTR2(band_2_gain__bass, band_2_gain, S_IWUGO | S_IRUGO, 458static DEVICE_ATTR2(band_2_gain__bass, band_2_gain, S_IWUSR | S_IRUGO,
459 pod_get_band_2_gain__bass, pod_set_band_2_gain__bass); 459 pod_get_band_2_gain__bass, pod_set_band_2_gain__bass);
460static DEVICE_ATTR(band_2_gain, S_IWUGO | S_IRUGO, pod_get_band_2_gain, 460static DEVICE_ATTR(band_2_gain, S_IWUSR | S_IRUGO, pod_get_band_2_gain,
461 pod_set_band_2_gain); 461 pod_set_band_2_gain);
462static DEVICE_ATTR2(band_3_gain__bass, band_3_gain, S_IWUGO | S_IRUGO, 462static DEVICE_ATTR2(band_3_gain__bass, band_3_gain, S_IWUSR | S_IRUGO,
463 pod_get_band_3_gain__bass, pod_set_band_3_gain__bass); 463 pod_get_band_3_gain__bass, pod_set_band_3_gain__bass);
464static DEVICE_ATTR(band_3_gain, S_IWUGO | S_IRUGO, pod_get_band_3_gain, 464static DEVICE_ATTR(band_3_gain, S_IWUSR | S_IRUGO, pod_get_band_3_gain,
465 pod_set_band_3_gain); 465 pod_set_band_3_gain);
466static DEVICE_ATTR2(band_4_gain__bass, band_4_gain, S_IWUGO | S_IRUGO, 466static DEVICE_ATTR2(band_4_gain__bass, band_4_gain, S_IWUSR | S_IRUGO,
467 pod_get_band_4_gain__bass, pod_set_band_4_gain__bass); 467 pod_get_band_4_gain__bass, pod_set_band_4_gain__bass);
468static DEVICE_ATTR2(band_5_gain__bass, band_5_gain, S_IWUGO | S_IRUGO, 468static DEVICE_ATTR2(band_5_gain__bass, band_5_gain, S_IWUSR | S_IRUGO,
469 pod_get_band_5_gain__bass, pod_set_band_5_gain__bass); 469 pod_get_band_5_gain__bass, pod_set_band_5_gain__bass);
470static DEVICE_ATTR(band_4_gain, S_IWUGO | S_IRUGO, pod_get_band_4_gain, 470static DEVICE_ATTR(band_4_gain, S_IWUSR | S_IRUGO, pod_get_band_4_gain,
471 pod_set_band_4_gain); 471 pod_set_band_4_gain);
472static DEVICE_ATTR2(band_6_gain__bass, band_6_gain, S_IWUGO | S_IRUGO, 472static DEVICE_ATTR2(band_6_gain__bass, band_6_gain, S_IWUSR | S_IRUGO,
473 pod_get_band_6_gain__bass, pod_set_band_6_gain__bass); 473 pod_get_band_6_gain__bass, pod_set_band_6_gain__bass);
474static DEVICE_ATTR(body, S_IRUGO, variax_get_body, line6_nop_write); 474static DEVICE_ATTR(body, S_IRUGO, variax_get_body, line6_nop_write);
475static DEVICE_ATTR(pickup1_enable, S_IRUGO, variax_get_pickup1_enable, 475static DEVICE_ATTR(pickup1_enable, S_IRUGO, variax_get_pickup1_enable,
diff --git a/drivers/staging/line6/midi.c b/drivers/staging/line6/midi.c
index 4304dfe6c166..ab67e889d2c4 100644
--- a/drivers/staging/line6/midi.c
+++ b/drivers/staging/line6/midi.c
@@ -350,9 +350,9 @@ static ssize_t midi_set_midi_mask_receive(struct device *dev,
350 return count; 350 return count;
351} 351}
352 352
353static DEVICE_ATTR(midi_mask_transmit, S_IWUGO | S_IRUGO, 353static DEVICE_ATTR(midi_mask_transmit, S_IWUSR | S_IRUGO,
354 midi_get_midi_mask_transmit, midi_set_midi_mask_transmit); 354 midi_get_midi_mask_transmit, midi_set_midi_mask_transmit);
355static DEVICE_ATTR(midi_mask_receive, S_IWUGO | S_IRUGO, 355static DEVICE_ATTR(midi_mask_receive, S_IWUSR | S_IRUGO,
356 midi_get_midi_mask_receive, midi_set_midi_mask_receive); 356 midi_get_midi_mask_receive, midi_set_midi_mask_receive);
357 357
358/* MIDI device destructor */ 358/* MIDI device destructor */
diff --git a/drivers/staging/line6/pcm.c b/drivers/staging/line6/pcm.c
index e54770e34d2e..b9c55f9eb501 100644
--- a/drivers/staging/line6/pcm.c
+++ b/drivers/staging/line6/pcm.c
@@ -79,9 +79,9 @@ static ssize_t pcm_set_impulse_period(struct device *dev,
79 return count; 79 return count;
80} 80}
81 81
82static DEVICE_ATTR(impulse_volume, S_IWUGO | S_IRUGO, pcm_get_impulse_volume, 82static DEVICE_ATTR(impulse_volume, S_IWUSR | S_IRUGO, pcm_get_impulse_volume,
83 pcm_set_impulse_volume); 83 pcm_set_impulse_volume);
84static DEVICE_ATTR(impulse_period, S_IWUGO | S_IRUGO, pcm_get_impulse_period, 84static DEVICE_ATTR(impulse_period, S_IWUSR | S_IRUGO, pcm_get_impulse_period,
85 pcm_set_impulse_period); 85 pcm_set_impulse_period);
86 86
87#endif 87#endif
diff --git a/drivers/staging/line6/pod.c b/drivers/staging/line6/pod.c
index 22e2cedcacf7..d9b30212585c 100644
--- a/drivers/staging/line6/pod.c
+++ b/drivers/staging/line6/pod.c
@@ -1051,48 +1051,48 @@ POD_GET_SYSTEM_PARAM(tuner_pitch, 1);
1051#undef GET_SYSTEM_PARAM 1051#undef GET_SYSTEM_PARAM
1052 1052
1053/* POD special files: */ 1053/* POD special files: */
1054static DEVICE_ATTR(channel, S_IWUGO | S_IRUGO, pod_get_channel, 1054static DEVICE_ATTR(channel, S_IWUSR | S_IRUGO, pod_get_channel,
1055 pod_set_channel); 1055 pod_set_channel);
1056static DEVICE_ATTR(clip, S_IRUGO, pod_wait_for_clip, line6_nop_write); 1056static DEVICE_ATTR(clip, S_IRUGO, pod_wait_for_clip, line6_nop_write);
1057static DEVICE_ATTR(device_id, S_IRUGO, pod_get_device_id, line6_nop_write); 1057static DEVICE_ATTR(device_id, S_IRUGO, pod_get_device_id, line6_nop_write);
1058static DEVICE_ATTR(dirty, S_IRUGO, pod_get_dirty, line6_nop_write); 1058static DEVICE_ATTR(dirty, S_IRUGO, pod_get_dirty, line6_nop_write);
1059static DEVICE_ATTR(dump, S_IWUGO | S_IRUGO, pod_get_dump, pod_set_dump); 1059static DEVICE_ATTR(dump, S_IWUSR | S_IRUGO, pod_get_dump, pod_set_dump);
1060static DEVICE_ATTR(dump_buf, S_IWUGO | S_IRUGO, pod_get_dump_buf, 1060static DEVICE_ATTR(dump_buf, S_IWUSR | S_IRUGO, pod_get_dump_buf,
1061 pod_set_dump_buf); 1061 pod_set_dump_buf);
1062static DEVICE_ATTR(finish, S_IWUGO, line6_nop_read, pod_set_finish); 1062static DEVICE_ATTR(finish, S_IWUSR, line6_nop_read, pod_set_finish);
1063static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version, 1063static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version,
1064 line6_nop_write); 1064 line6_nop_write);
1065static DEVICE_ATTR(midi_postprocess, S_IWUGO | S_IRUGO, 1065static DEVICE_ATTR(midi_postprocess, S_IWUSR | S_IRUGO,
1066 pod_get_midi_postprocess, pod_set_midi_postprocess); 1066 pod_get_midi_postprocess, pod_set_midi_postprocess);
1067static DEVICE_ATTR(monitor_level, S_IWUGO | S_IRUGO, pod_get_monitor_level, 1067static DEVICE_ATTR(monitor_level, S_IWUSR | S_IRUGO, pod_get_monitor_level,
1068 pod_set_monitor_level); 1068 pod_set_monitor_level);
1069static DEVICE_ATTR(name, S_IRUGO, pod_get_name, line6_nop_write); 1069static DEVICE_ATTR(name, S_IRUGO, pod_get_name, line6_nop_write);
1070static DEVICE_ATTR(name_buf, S_IRUGO, pod_get_name_buf, line6_nop_write); 1070static DEVICE_ATTR(name_buf, S_IRUGO, pod_get_name_buf, line6_nop_write);
1071static DEVICE_ATTR(retrieve_amp_setup, S_IWUGO, line6_nop_read, 1071static DEVICE_ATTR(retrieve_amp_setup, S_IWUSR, line6_nop_read,
1072 pod_set_retrieve_amp_setup); 1072 pod_set_retrieve_amp_setup);
1073static DEVICE_ATTR(retrieve_channel, S_IWUGO, line6_nop_read, 1073static DEVICE_ATTR(retrieve_channel, S_IWUSR, line6_nop_read,
1074 pod_set_retrieve_channel); 1074 pod_set_retrieve_channel);
1075static DEVICE_ATTR(retrieve_effects_setup, S_IWUGO, line6_nop_read, 1075static DEVICE_ATTR(retrieve_effects_setup, S_IWUSR, line6_nop_read,
1076 pod_set_retrieve_effects_setup); 1076 pod_set_retrieve_effects_setup);
1077static DEVICE_ATTR(routing, S_IWUGO | S_IRUGO, pod_get_routing, 1077static DEVICE_ATTR(routing, S_IWUSR | S_IRUGO, pod_get_routing,
1078 pod_set_routing); 1078 pod_set_routing);
1079static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number, 1079static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number,
1080 line6_nop_write); 1080 line6_nop_write);
1081static DEVICE_ATTR(store_amp_setup, S_IWUGO, line6_nop_read, 1081static DEVICE_ATTR(store_amp_setup, S_IWUSR, line6_nop_read,
1082 pod_set_store_amp_setup); 1082 pod_set_store_amp_setup);
1083static DEVICE_ATTR(store_channel, S_IWUGO, line6_nop_read, 1083static DEVICE_ATTR(store_channel, S_IWUSR, line6_nop_read,
1084 pod_set_store_channel); 1084 pod_set_store_channel);
1085static DEVICE_ATTR(store_effects_setup, S_IWUGO, line6_nop_read, 1085static DEVICE_ATTR(store_effects_setup, S_IWUSR, line6_nop_read,
1086 pod_set_store_effects_setup); 1086 pod_set_store_effects_setup);
1087static DEVICE_ATTR(tuner_freq, S_IWUGO | S_IRUGO, pod_get_tuner_freq, 1087static DEVICE_ATTR(tuner_freq, S_IWUSR | S_IRUGO, pod_get_tuner_freq,
1088 pod_set_tuner_freq); 1088 pod_set_tuner_freq);
1089static DEVICE_ATTR(tuner_mute, S_IWUGO | S_IRUGO, pod_get_tuner_mute, 1089static DEVICE_ATTR(tuner_mute, S_IWUSR | S_IRUGO, pod_get_tuner_mute,
1090 pod_set_tuner_mute); 1090 pod_set_tuner_mute);
1091static DEVICE_ATTR(tuner_note, S_IRUGO, pod_get_tuner_note, line6_nop_write); 1091static DEVICE_ATTR(tuner_note, S_IRUGO, pod_get_tuner_note, line6_nop_write);
1092static DEVICE_ATTR(tuner_pitch, S_IRUGO, pod_get_tuner_pitch, line6_nop_write); 1092static DEVICE_ATTR(tuner_pitch, S_IRUGO, pod_get_tuner_pitch, line6_nop_write);
1093 1093
1094#ifdef CONFIG_LINE6_USB_RAW 1094#ifdef CONFIG_LINE6_USB_RAW
1095static DEVICE_ATTR(raw, S_IWUGO, line6_nop_read, line6_set_raw); 1095static DEVICE_ATTR(raw, S_IWUSR, line6_nop_read, line6_set_raw);
1096#endif 1096#endif
1097 1097
1098/* control info callback */ 1098/* control info callback */
diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c
index 6a10b0f9749a..879e6992bbc6 100644
--- a/drivers/staging/line6/toneport.c
+++ b/drivers/staging/line6/toneport.c
@@ -154,9 +154,9 @@ static ssize_t toneport_set_led_green(struct device *dev,
154 return count; 154 return count;
155} 155}
156 156
157static DEVICE_ATTR(led_red, S_IWUGO | S_IRUGO, line6_nop_read, 157static DEVICE_ATTR(led_red, S_IWUSR | S_IRUGO, line6_nop_read,
158 toneport_set_led_red); 158 toneport_set_led_red);
159static DEVICE_ATTR(led_green, S_IWUGO | S_IRUGO, line6_nop_read, 159static DEVICE_ATTR(led_green, S_IWUSR | S_IRUGO, line6_nop_read,
160 toneport_set_led_green); 160 toneport_set_led_green);
161 161
162static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2) 162static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2)
diff --git a/drivers/staging/line6/variax.c b/drivers/staging/line6/variax.c
index 894eee7f2317..81241cdf1be9 100644
--- a/drivers/staging/line6/variax.c
+++ b/drivers/staging/line6/variax.c
@@ -549,21 +549,21 @@ static ssize_t variax_set_raw2(struct device *dev,
549#endif 549#endif
550 550
551/* Variax workbench special files: */ 551/* Variax workbench special files: */
552static DEVICE_ATTR(model, S_IWUGO | S_IRUGO, variax_get_model, 552static DEVICE_ATTR(model, S_IWUSR | S_IRUGO, variax_get_model,
553 variax_set_model); 553 variax_set_model);
554static DEVICE_ATTR(volume, S_IWUGO | S_IRUGO, variax_get_volume, 554static DEVICE_ATTR(volume, S_IWUSR | S_IRUGO, variax_get_volume,
555 variax_set_volume); 555 variax_set_volume);
556static DEVICE_ATTR(tone, S_IWUGO | S_IRUGO, variax_get_tone, variax_set_tone); 556static DEVICE_ATTR(tone, S_IWUSR | S_IRUGO, variax_get_tone, variax_set_tone);
557static DEVICE_ATTR(name, S_IRUGO, variax_get_name, line6_nop_write); 557static DEVICE_ATTR(name, S_IRUGO, variax_get_name, line6_nop_write);
558static DEVICE_ATTR(bank, S_IRUGO, variax_get_bank, line6_nop_write); 558static DEVICE_ATTR(bank, S_IRUGO, variax_get_bank, line6_nop_write);
559static DEVICE_ATTR(dump, S_IRUGO, variax_get_dump, line6_nop_write); 559static DEVICE_ATTR(dump, S_IRUGO, variax_get_dump, line6_nop_write);
560static DEVICE_ATTR(active, S_IWUGO | S_IRUGO, variax_get_active, 560static DEVICE_ATTR(active, S_IWUSR | S_IRUGO, variax_get_active,
561 variax_set_active); 561 variax_set_active);
562static DEVICE_ATTR(guitar, S_IRUGO, variax_get_guitar, line6_nop_write); 562static DEVICE_ATTR(guitar, S_IRUGO, variax_get_guitar, line6_nop_write);
563 563
564#ifdef CONFIG_LINE6_USB_RAW 564#ifdef CONFIG_LINE6_USB_RAW
565static DEVICE_ATTR(raw, S_IWUGO, line6_nop_read, line6_set_raw); 565static DEVICE_ATTR(raw, S_IWUSR, line6_nop_read, line6_set_raw);
566static DEVICE_ATTR(raw2, S_IWUGO, line6_nop_read, variax_set_raw2); 566static DEVICE_ATTR(raw2, S_IWUSR, line6_nop_read, variax_set_raw2);
567#endif 567#endif
568 568
569/* 569/*
diff --git a/drivers/staging/msm/msm_fb.c b/drivers/staging/msm/msm_fb.c
index ea268edbf43b..23fa049b51f2 100644
--- a/drivers/staging/msm/msm_fb.c
+++ b/drivers/staging/msm/msm_fb.c
@@ -1158,7 +1158,7 @@ static int msm_fb_release(struct fb_info *info, int user)
1158 return ret; 1158 return ret;
1159} 1159}
1160 1160
1161DECLARE_MUTEX(msm_fb_pan_sem); 1161DEFINE_SEMAPHORE(msm_fb_pan_sem);
1162 1162
1163static int msm_fb_pan_display(struct fb_var_screeninfo *var, 1163static int msm_fb_pan_display(struct fb_var_screeninfo *var,
1164 struct fb_info *info) 1164 struct fb_info *info)
@@ -1962,7 +1962,7 @@ static int msmfb_overlay_play(struct fb_info *info, unsigned long *argp)
1962 1962
1963#endif 1963#endif
1964 1964
1965DECLARE_MUTEX(msm_fb_ioctl_ppp_sem); 1965DEFINE_SEMAPHORE(msm_fb_ioctl_ppp_sem);
1966DEFINE_MUTEX(msm_fb_ioctl_lut_sem); 1966DEFINE_MUTEX(msm_fb_ioctl_lut_sem);
1967DEFINE_MUTEX(msm_fb_ioctl_hist_sem); 1967DEFINE_MUTEX(msm_fb_ioctl_hist_sem);
1968 1968
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
index d40ff41774be..309c0ed4ef8a 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -17,7 +17,6 @@
17#include <linux/console.h> 17#include <linux/console.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/i2c-id.h>
21#include <linux/pci.h> 20#include <linux/pci.h>
22#include <linux/pci_ids.h> 21#include <linux/pci_ids.h>
23#include <linux/interrupt.h> 22#include <linux/interrupt.h>
@@ -733,7 +732,6 @@ static int dcon_probe(struct i2c_client *client, const struct i2c_device_id *id)
733 edev: 732 edev:
734 platform_device_unregister(dcon_device); 733 platform_device_unregister(dcon_device);
735 dcon_device = NULL; 734 dcon_device = NULL;
736 i2c_set_clientdata(client, NULL);
737 eirq: 735 eirq:
738 free_irq(DCON_IRQ, &dcon_driver); 736 free_irq(DCON_IRQ, &dcon_driver);
739 einit: 737 einit:
@@ -757,8 +755,6 @@ static int dcon_remove(struct i2c_client *client)
757 platform_device_unregister(dcon_device); 755 platform_device_unregister(dcon_device);
758 cancel_work_sync(&dcon_work); 756 cancel_work_sync(&dcon_work);
759 757
760 i2c_set_clientdata(client, NULL);
761
762 return 0; 758 return 0;
763} 759}
764 760
diff --git a/drivers/staging/quickstart/quickstart.c b/drivers/staging/quickstart/quickstart.c
index d746715d3d89..d83bec876d2e 100644
--- a/drivers/staging/quickstart/quickstart.c
+++ b/drivers/staging/quickstart/quickstart.c
@@ -355,7 +355,6 @@ static int quickstart_acpi_remove(struct acpi_device *device, int type)
355static void quickstart_exit(void) 355static void quickstart_exit(void)
356{ 356{
357 input_unregister_device(quickstart_input); 357 input_unregister_device(quickstart_input);
358 input_free_device(quickstart_input);
359 358
360 device_remove_file(&pf_device->dev, &dev_attr_pressed_button); 359 device_remove_file(&pf_device->dev, &dev_attr_pressed_button);
361 device_remove_file(&pf_device->dev, &dev_attr_buttons); 360 device_remove_file(&pf_device->dev, &dev_attr_buttons);
@@ -375,6 +374,7 @@ static int __init quickstart_init_input(void)
375{ 374{
376 struct quickstart_btn **ptr = &quickstart_data.btn_lst; 375 struct quickstart_btn **ptr = &quickstart_data.btn_lst;
377 int count; 376 int count;
377 int ret;
378 378
379 quickstart_input = input_allocate_device(); 379 quickstart_input = input_allocate_device();
380 380
@@ -391,7 +391,13 @@ static int __init quickstart_init_input(void)
391 ptr = &((*ptr)->next); 391 ptr = &((*ptr)->next);
392 } 392 }
393 393
394 return input_register_device(quickstart_input); 394 ret = input_register_device(quickstart_input);
395 if (ret) {
396 input_free_device(quickstart_input);
397 return ret;
398 }
399
400 return 0;
395} 401}
396 402
397static int __init quickstart_init(void) 403static int __init quickstart_init(void)
diff --git a/drivers/staging/rt2860/common/cmm_aes.c b/drivers/staging/rt2860/common/cmm_aes.c
index 1d159ff82fd2..a99879bada42 100644
--- a/drivers/staging/rt2860/common/cmm_aes.c
+++ b/drivers/staging/rt2860/common/cmm_aes.c
@@ -330,8 +330,6 @@ void construct_mic_iv(unsigned char *mic_iv,
330 for (i = 8; i < 14; i++) 330 for (i = 8; i < 14; i++)
331 mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */ 331 mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */
332#endif 332#endif
333 i = (payload_length / 256);
334 i = (payload_length % 256);
335 mic_iv[14] = (unsigned char)(payload_length / 256); 333 mic_iv[14] = (unsigned char)(payload_length / 256);
336 mic_iv[15] = (unsigned char)(payload_length % 256); 334 mic_iv[15] = (unsigned char)(payload_length % 256);
337 335
diff --git a/drivers/staging/rt2860/usb_main_dev.c b/drivers/staging/rt2860/usb_main_dev.c
index ebf9074a9083..cd15daae5412 100644
--- a/drivers/staging/rt2860/usb_main_dev.c
+++ b/drivers/staging/rt2860/usb_main_dev.c
@@ -65,6 +65,7 @@ struct usb_device_id rtusb_usb_id[] = {
65 {USB_DEVICE(0x14B2, 0x3C07)}, /* AL */ 65 {USB_DEVICE(0x14B2, 0x3C07)}, /* AL */
66 {USB_DEVICE(0x050D, 0x8053)}, /* Belkin */ 66 {USB_DEVICE(0x050D, 0x8053)}, /* Belkin */
67 {USB_DEVICE(0x050D, 0x825B)}, /* Belkin */ 67 {USB_DEVICE(0x050D, 0x825B)}, /* Belkin */
68 {USB_DEVICE(0x050D, 0x935A)}, /* Belkin F6D4050 v1 */
68 {USB_DEVICE(0x050D, 0x935B)}, /* Belkin F6D4050 v2 */ 69 {USB_DEVICE(0x050D, 0x935B)}, /* Belkin F6D4050 v2 */
69 {USB_DEVICE(0x14B2, 0x3C23)}, /* Airlink */ 70 {USB_DEVICE(0x14B2, 0x3C23)}, /* Airlink */
70 {USB_DEVICE(0x14B2, 0x3C27)}, /* Airlink */ 71 {USB_DEVICE(0x14B2, 0x3C27)}, /* Airlink */
@@ -181,6 +182,7 @@ struct usb_device_id rtusb_usb_id[] = {
181 {USB_DEVICE(0x2001, 0x3C09)}, /* D-Link */ 182 {USB_DEVICE(0x2001, 0x3C09)}, /* D-Link */
182 {USB_DEVICE(0x2001, 0x3C0A)}, /* D-Link 3072 */ 183 {USB_DEVICE(0x2001, 0x3C0A)}, /* D-Link 3072 */
183 {USB_DEVICE(0x2019, 0xED14)}, /* Planex Communications, Inc. */ 184 {USB_DEVICE(0x2019, 0xED14)}, /* Planex Communications, Inc. */
185 {USB_DEVICE(0x0411, 0x015D)}, /* Buffalo Airstation WLI-UC-GN */
184 {} /* Terminating entry */ 186 {} /* Terminating entry */
185}; 187};
186 188
diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c
index 46000d72f4c4..3bdf9b31cc4e 100644
--- a/drivers/staging/rtl8187se/r8185b_init.c
+++ b/drivers/staging/rtl8187se/r8185b_init.c
@@ -264,8 +264,12 @@ HwHSSIThreeWire(
264 264
265 udelay(10); 265 udelay(10);
266 } 266 }
267 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT) 267 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT) {
268 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp); 268 printk(KERN_ERR "rtl8187se: HwThreeWire(): CmdReg:"
269 " %#X RE|WE bits are not clear!!\n", u1bTmp);
270 dump_stack();
271 return 0;
272 }
269 273
270 /* RTL8187S HSSI Read/Write Function */ 274 /* RTL8187S HSSI Read/Write Function */
271 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG); 275 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
@@ -298,13 +302,23 @@ HwHSSIThreeWire(
298 int idx; 302 int idx;
299 int ByteCnt = nDataBufBitCnt / 8; 303 int ByteCnt = nDataBufBitCnt / 8;
300 /* printk("%d\n",nDataBufBitCnt); */ 304 /* printk("%d\n",nDataBufBitCnt); */
301 if ((nDataBufBitCnt % 8) != 0) 305 if ((nDataBufBitCnt % 8) != 0) {
302 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n", 306 printk(KERN_ERR "rtl8187se: "
303 nDataBufBitCnt); 307 "HwThreeWire(): nDataBufBitCnt(%d)"
308 " should be multiple of 8!!!\n",
309 nDataBufBitCnt);
310 dump_stack();
311 nDataBufBitCnt += 8;
312 nDataBufBitCnt &= ~7;
313 }
304 314
305 if (nDataBufBitCnt > 64) 315 if (nDataBufBitCnt > 64) {
306 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n", 316 printk(KERN_ERR "rtl8187se: HwThreeWire():"
307 nDataBufBitCnt); 317 " nDataBufBitCnt(%d) should <= 64!!!\n",
318 nDataBufBitCnt);
319 dump_stack();
320 nDataBufBitCnt = 64;
321 }
308 322
309 for (idx = 0; idx < ByteCnt; idx++) 323 for (idx = 0; idx < ByteCnt; idx++)
310 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx)); 324 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
diff --git a/drivers/staging/rtl8192e/r8192E_core.c b/drivers/staging/rtl8192e/r8192E_core.c
index a202194b5cbb..b1786dcac245 100644
--- a/drivers/staging/rtl8192e/r8192E_core.c
+++ b/drivers/staging/rtl8192e/r8192E_core.c
@@ -5829,6 +5829,9 @@ static void rtl8192_rx(struct net_device *dev)
5829 } 5829 }
5830 } 5830 }
5831 5831
5832 pci_unmap_single(priv->pdev, *((dma_addr_t *) skb->cb),
5833 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
5834
5832 skb = new_skb; 5835 skb = new_skb;
5833 priv->rx_buf[priv->rx_idx] = skb; 5836 priv->rx_buf[priv->rx_idx] = skb;
5834 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, skb_tail_pointer(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE); 5837 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, skb_tail_pointer(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE);
diff --git a/drivers/staging/rtl8712/osdep_service.h b/drivers/staging/rtl8712/osdep_service.h
index 7fca42c7c0d4..831d81e0e429 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -22,7 +22,6 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/sched.h> 23#include <linux/sched.h>
24#include <linux/kref.h> 24#include <linux/kref.h>
25#include <linux/smp_lock.h>
26#include <linux/netdevice.h> 25#include <linux/netdevice.h>
27#include <linux/skbuff.h> 26#include <linux/skbuff.h>
28#include <linux/usb.h> 27#include <linux/usb.h>
@@ -161,7 +160,7 @@ static inline u32 _down_sema(struct semaphore *sema)
161 160
162static inline void _rtl_rwlock_init(struct semaphore *prwlock) 161static inline void _rtl_rwlock_init(struct semaphore *prwlock)
163{ 162{
164 init_MUTEX(prwlock); 163 sema_init(prwlock, 1);
165} 164}
166 165
167static inline void _init_listhead(struct list_head *list) 166static inline void _init_listhead(struct list_head *list)
diff --git a/drivers/staging/rtl8712/usb_halinit.c b/drivers/staging/rtl8712/usb_halinit.c
index f6569dce3012..0e9483bbabe1 100644
--- a/drivers/staging/rtl8712/usb_halinit.c
+++ b/drivers/staging/rtl8712/usb_halinit.c
@@ -37,7 +37,7 @@ u8 r8712_usb_hal_bus_init(struct _adapter *padapter)
37{ 37{
38 u8 val8 = 0; 38 u8 val8 = 0;
39 u8 ret = _SUCCESS; 39 u8 ret = _SUCCESS;
40 u8 PollingCnt = 20; 40 int PollingCnt = 20;
41 struct registry_priv *pregistrypriv = &padapter->registrypriv; 41 struct registry_priv *pregistrypriv = &padapter->registrypriv;
42 42
43 if (pregistrypriv->chip_version == RTL8712_FPGA) { 43 if (pregistrypriv->chip_version == RTL8712_FPGA) {
diff --git a/drivers/staging/samsung-laptop/samsung-laptop.c b/drivers/staging/samsung-laptop/samsung-laptop.c
index 80eeec6d6719..701e8d52a9fa 100644
--- a/drivers/staging/samsung-laptop/samsung-laptop.c
+++ b/drivers/staging/samsung-laptop/samsung-laptop.c
@@ -356,7 +356,7 @@ static ssize_t set_silent_state(struct device *dev,
356 } 356 }
357 return count; 357 return count;
358} 358}
359static DEVICE_ATTR(silent, S_IWUGO | S_IRUGO, 359static DEVICE_ATTR(silent, S_IWUSR | S_IRUGO,
360 get_silent_state, set_silent_state); 360 get_silent_state, set_silent_state);
361 361
362 362
diff --git a/drivers/staging/smbfs/inode.c b/drivers/staging/smbfs/inode.c
index f9c493591ce7..540a984bb516 100644
--- a/drivers/staging/smbfs/inode.c
+++ b/drivers/staging/smbfs/inode.c
@@ -537,7 +537,7 @@ static int smb_fill_super(struct super_block *sb, void *raw_data, int silent)
537 server->mnt = NULL; 537 server->mnt = NULL;
538 server->sock_file = NULL; 538 server->sock_file = NULL;
539 init_waitqueue_head(&server->conn_wq); 539 init_waitqueue_head(&server->conn_wq);
540 init_MUTEX(&server->sem); 540 sema_init(&server->sem, 1);
541 INIT_LIST_HEAD(&server->entry); 541 INIT_LIST_HEAD(&server->entry);
542 INIT_LIST_HEAD(&server->xmitq); 542 INIT_LIST_HEAD(&server->xmitq);
543 INIT_LIST_HEAD(&server->recvq); 543 INIT_LIST_HEAD(&server->recvq);
diff --git a/drivers/staging/solo6x10/solo6010-v4l2-enc.c b/drivers/staging/solo6x10/solo6010-v4l2-enc.c
index bbf3d9c4abb0..097e82bc7a63 100644
--- a/drivers/staging/solo6x10/solo6010-v4l2-enc.c
+++ b/drivers/staging/solo6x10/solo6010-v4l2-enc.c
@@ -766,7 +766,7 @@ static int solo_enc_open(struct file *file)
766 &solo_enc->lock, 766 &solo_enc->lock,
767 V4L2_BUF_TYPE_VIDEO_CAPTURE, 767 V4L2_BUF_TYPE_VIDEO_CAPTURE,
768 V4L2_FIELD_INTERLACED, 768 V4L2_FIELD_INTERLACED,
769 sizeof(struct videobuf_buffer), fh); 769 sizeof(struct videobuf_buffer), fh, NULL);
770 770
771 spin_unlock(&solo_enc->lock); 771 spin_unlock(&solo_enc->lock);
772 772
diff --git a/drivers/staging/solo6x10/solo6010-v4l2.c b/drivers/staging/solo6x10/solo6010-v4l2.c
index 9731fa02b5e8..6ffd21de837d 100644
--- a/drivers/staging/solo6x10/solo6010-v4l2.c
+++ b/drivers/staging/solo6x10/solo6010-v4l2.c
@@ -437,7 +437,7 @@ static int solo_v4l2_open(struct file *file)
437 &solo_dev->pdev->dev, &fh->slock, 437 &solo_dev->pdev->dev, &fh->slock,
438 V4L2_BUF_TYPE_VIDEO_CAPTURE, 438 V4L2_BUF_TYPE_VIDEO_CAPTURE,
439 SOLO_DISP_PIX_FIELD, 439 SOLO_DISP_PIX_FIELD,
440 sizeof(struct videobuf_buffer), fh); 440 sizeof(struct videobuf_buffer), fh, NULL);
441 441
442 return 0; 442 return 0;
443} 443}
diff --git a/drivers/staging/speakup/buffers.c b/drivers/staging/speakup/buffers.c
index b7b60d5e8660..a2db956edd54 100644
--- a/drivers/staging/speakup/buffers.c
+++ b/drivers/staging/speakup/buffers.c
@@ -1,5 +1,4 @@
1#include <linux/console.h> 1#include <linux/console.h>
2#include <linux/smp_lock.h>
3#include <linux/types.h> 2#include <linux/types.h>
4#include <linux/wait.h> 3#include <linux/wait.h>
5 4
diff --git a/drivers/staging/speakup/fakekey.c b/drivers/staging/speakup/fakekey.c
index adb93f21c0d6..65b231178f05 100644
--- a/drivers/staging/speakup/fakekey.c
+++ b/drivers/staging/speakup/fakekey.c
@@ -62,7 +62,6 @@ void speakup_remove_virtual_keyboard(void)
62{ 62{
63 if (virt_keyboard != NULL) { 63 if (virt_keyboard != NULL) {
64 input_unregister_device(virt_keyboard); 64 input_unregister_device(virt_keyboard);
65 input_free_device(virt_keyboard);
66 virt_keyboard = NULL; 65 virt_keyboard = NULL;
67 } 66 }
68} 67}
diff --git a/drivers/staging/spectra/ffsport.c b/drivers/staging/spectra/ffsport.c
index c7932da03c56..63a9d0adf32d 100644
--- a/drivers/staging/spectra/ffsport.c
+++ b/drivers/staging/spectra/ffsport.c
@@ -656,7 +656,7 @@ static int SBD_setup_device(struct spectra_nand_dev *dev, int which)
656 /* Here we force report 512 byte hardware sector size to Kernel */ 656 /* Here we force report 512 byte hardware sector size to Kernel */
657 blk_queue_logical_block_size(dev->queue, 512); 657 blk_queue_logical_block_size(dev->queue, 512);
658 658
659 blk_queue_ordered(dev->queue, QUEUE_ORDERED_DRAIN_FLUSH); 659 blk_queue_flush(dev->queue, REQ_FLUSH);
660 660
661 dev->thread = kthread_run(spectra_trans_thread, dev, "nand_thd"); 661 dev->thread = kthread_run(spectra_trans_thread, dev, "nand_thd");
662 if (IS_ERR(dev->thread)) { 662 if (IS_ERR(dev->thread)) {
diff --git a/drivers/staging/stradis/Kconfig b/drivers/staging/stradis/Kconfig
index 92e891141896..02f0fc504cf5 100644
--- a/drivers/staging/stradis/Kconfig
+++ b/drivers/staging/stradis/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_STRADIS 1config VIDEO_STRADIS
2 tristate "Stradis 4:2:2 MPEG-2 video driver (DEPRECATED)" 2 tristate "Stradis 4:2:2 MPEG-2 video driver (DEPRECATED)"
3 depends on EXPERIMENTAL && PCI && VIDEO_V4L1 && VIRT_TO_BUS 3 depends on EXPERIMENTAL && PCI && VIDEO_V4L1 && VIRT_TO_BUS && BKL
4 help 4 help
5 Say Y here to enable support for the Stradis 4:2:2 MPEG-2 video 5 Say Y here to enable support for the Stradis 4:2:2 MPEG-2 video
6 driver for PCI. There is a product page at 6 driver for PCI. There is a product page at
diff --git a/drivers/staging/stradis/stradis.c b/drivers/staging/stradis/stradis.c
index dd3874b78263..2e74355d1ea1 100644
--- a/drivers/staging/stradis/stradis.c
+++ b/drivers/staging/stradis/stradis.c
@@ -1286,6 +1286,7 @@ static long saa_ioctl(struct file *file,
1286 case VIDIOCGCAP: 1286 case VIDIOCGCAP:
1287 { 1287 {
1288 struct video_capability b; 1288 struct video_capability b;
1289 memset(&b, 0, sizeof(b));
1289 strcpy(b.name, saa->video_dev.name); 1290 strcpy(b.name, saa->video_dev.name);
1290 b.type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY | 1291 b.type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY |
1291 VID_TYPE_CLIPPING | VID_TYPE_FRAMERAM | 1292 VID_TYPE_CLIPPING | VID_TYPE_FRAMERAM |
@@ -1416,6 +1417,7 @@ static long saa_ioctl(struct file *file,
1416 case VIDIOCGWIN: 1417 case VIDIOCGWIN:
1417 { 1418 {
1418 struct video_window vw; 1419 struct video_window vw;
1420 memset(&vw, 0, sizeof(vw));
1419 vw.x = saa->win.x; 1421 vw.x = saa->win.x;
1420 vw.y = saa->win.y; 1422 vw.y = saa->win.y;
1421 vw.width = saa->win.width; 1423 vw.width = saa->win.width;
@@ -1448,6 +1450,7 @@ static long saa_ioctl(struct file *file,
1448 case VIDIOCGFBUF: 1450 case VIDIOCGFBUF:
1449 { 1451 {
1450 struct video_buffer v; 1452 struct video_buffer v;
1453 memset(&v, 0, sizeof(v));
1451 v.base = (void *)saa->win.vidadr; 1454 v.base = (void *)saa->win.vidadr;
1452 v.height = saa->win.sheight; 1455 v.height = saa->win.sheight;
1453 v.width = saa->win.swidth; 1456 v.width = saa->win.swidth;
@@ -1492,6 +1495,7 @@ static long saa_ioctl(struct file *file,
1492 case VIDIOCGAUDIO: 1495 case VIDIOCGAUDIO:
1493 { 1496 {
1494 struct video_audio v; 1497 struct video_audio v;
1498 memset(&v, 0, sizeof(v));
1495 v = saa->audio_dev; 1499 v = saa->audio_dev;
1496 v.flags &= ~(VIDEO_AUDIO_MUTE | VIDEO_AUDIO_MUTABLE); 1500 v.flags &= ~(VIDEO_AUDIO_MUTE | VIDEO_AUDIO_MUTABLE);
1497 v.flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME; 1501 v.flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME;
@@ -1534,6 +1538,7 @@ static long saa_ioctl(struct file *file,
1534 case VIDIOCGUNIT: 1538 case VIDIOCGUNIT:
1535 { 1539 {
1536 struct video_unit vu; 1540 struct video_unit vu;
1541 memset(&vu, 0, sizeof(vu));
1537 vu.video = saa->video_dev.minor; 1542 vu.video = saa->video_dev.minor;
1538 vu.vbi = VIDEO_NO_UNIT; 1543 vu.vbi = VIDEO_NO_UNIT;
1539 vu.radio = VIDEO_NO_UNIT; 1544 vu.radio = VIDEO_NO_UNIT;
@@ -1888,6 +1893,7 @@ static int saa_open(struct file *file)
1888 1893
1889 saa->user++; 1894 saa->user++;
1890 if (saa->user > 1) { 1895 if (saa->user > 1) {
1896 saa->user--;
1891 unlock_kernel(); 1897 unlock_kernel();
1892 return 0; /* device open already, don't reset */ 1898 return 0; /* device open already, don't reset */
1893 } 1899 }
@@ -2000,10 +2006,13 @@ static int __devinit configure_saa7146(struct pci_dev *pdev, int num)
2000 if (retval < 0) { 2006 if (retval < 0) {
2001 dev_err(&pdev->dev, "%d: error in registering video device!\n", 2007 dev_err(&pdev->dev, "%d: error in registering video device!\n",
2002 num); 2008 num);
2003 goto errio; 2009 goto errirq;
2004 } 2010 }
2005 2011
2006 return 0; 2012 return 0;
2013
2014errirq:
2015 free_irq(saa->irq, saa);
2007errio: 2016errio:
2008 iounmap(saa->saa7146_mem); 2017 iounmap(saa->saa7146_mem);
2009err: 2018err:
diff --git a/drivers/staging/tidspbridge/Kconfig b/drivers/staging/tidspbridge/Kconfig
index ff64d464143c..93de4f2e8bf8 100644
--- a/drivers/staging/tidspbridge/Kconfig
+++ b/drivers/staging/tidspbridge/Kconfig
@@ -6,7 +6,6 @@ menuconfig TIDSPBRIDGE
6 tristate "DSP Bridge driver" 6 tristate "DSP Bridge driver"
7 depends on ARCH_OMAP3 7 depends on ARCH_OMAP3
8 select OMAP_MBOX_FWK 8 select OMAP_MBOX_FWK
9 select OMAP_IOMMU
10 help 9 help
11 DSP/BIOS Bridge is designed for platforms that contain a GPP and 10 DSP/BIOS Bridge is designed for platforms that contain a GPP and
12 one or more attached DSPs. The GPP is considered the master or 11 one or more attached DSPs. The GPP is considered the master or
diff --git a/drivers/staging/tidspbridge/Makefile b/drivers/staging/tidspbridge/Makefile
index 50decc2935c5..41c644c3318f 100644
--- a/drivers/staging/tidspbridge/Makefile
+++ b/drivers/staging/tidspbridge/Makefile
@@ -2,18 +2,19 @@ obj-$(CONFIG_TIDSPBRIDGE) += bridgedriver.o
2 2
3libgen = gen/gb.o gen/gs.o gen/gh.o gen/uuidutil.o 3libgen = gen/gb.o gen/gs.o gen/gh.o gen/uuidutil.o
4libcore = core/chnl_sm.o core/msg_sm.o core/io_sm.o core/tiomap3430.o \ 4libcore = core/chnl_sm.o core/msg_sm.o core/io_sm.o core/tiomap3430.o \
5 core/tiomap3430_pwr.o core/tiomap_io.o core/dsp-mmu.o \ 5 core/tiomap3430_pwr.o core/tiomap_io.o \
6 core/ue_deh.o core/wdt.o core/dsp-clock.o core/sync.o 6 core/ue_deh.o core/wdt.o core/dsp-clock.o core/sync.o
7libpmgr = pmgr/chnl.o pmgr/io.o pmgr/msg.o pmgr/cod.o pmgr/dev.o pmgr/dspapi.o \ 7libpmgr = pmgr/chnl.o pmgr/io.o pmgr/msg.o pmgr/cod.o pmgr/dev.o pmgr/dspapi.o \
8 pmgr/cmm.o pmgr/dbll.o 8 pmgr/dmm.o pmgr/cmm.o pmgr/dbll.o
9librmgr = rmgr/dbdcd.o rmgr/disp.o rmgr/drv.o rmgr/mgr.o rmgr/node.o \ 9librmgr = rmgr/dbdcd.o rmgr/disp.o rmgr/drv.o rmgr/mgr.o rmgr/node.o \
10 rmgr/proc.o rmgr/pwr.o rmgr/rmm.o rmgr/strm.o rmgr/dspdrv.o \ 10 rmgr/proc.o rmgr/pwr.o rmgr/rmm.o rmgr/strm.o rmgr/dspdrv.o \
11 rmgr/nldr.o rmgr/drv_interface.o 11 rmgr/nldr.o rmgr/drv_interface.o
12libdload = dynload/cload.o dynload/getsection.o dynload/reloc.o \ 12libdload = dynload/cload.o dynload/getsection.o dynload/reloc.o \
13 dynload/tramp.o 13 dynload/tramp.o
14libhw = hw/hw_mmu.o
14 15
15bridgedriver-y := $(libgen) $(libservices) $(libcore) $(libpmgr) $(librmgr) \ 16bridgedriver-y := $(libgen) $(libservices) $(libcore) $(libpmgr) $(librmgr) \
16 $(libdload) 17 $(libdload) $(libhw)
17 18
18#Machine dependent 19#Machine dependent
19ccflags-y += -D_TI_ -D_DB_TIOMAP -DTMS32060 \ 20ccflags-y += -D_TI_ -D_DB_TIOMAP -DTMS32060 \
diff --git a/drivers/staging/tidspbridge/core/_deh.h b/drivers/staging/tidspbridge/core/_deh.h
index 8ae263387a87..16723cd34831 100644
--- a/drivers/staging/tidspbridge/core/_deh.h
+++ b/drivers/staging/tidspbridge/core/_deh.h
@@ -27,8 +27,9 @@
27struct deh_mgr { 27struct deh_mgr {
28 struct bridge_dev_context *hbridge_context; /* Bridge context. */ 28 struct bridge_dev_context *hbridge_context; /* Bridge context. */
29 struct ntfy_object *ntfy_obj; /* NTFY object */ 29 struct ntfy_object *ntfy_obj; /* NTFY object */
30};
31 30
32int mmu_fault_isr(struct iommu *mmu); 31 /* MMU Fault DPC */
32 struct tasklet_struct dpc_tasklet;
33};
33 34
34#endif /* _DEH_ */ 35#endif /* _DEH_ */
diff --git a/drivers/staging/tidspbridge/core/_tiomap.h b/drivers/staging/tidspbridge/core/_tiomap.h
index e0a801c1cb98..1c1f157e167a 100644
--- a/drivers/staging/tidspbridge/core/_tiomap.h
+++ b/drivers/staging/tidspbridge/core/_tiomap.h
@@ -23,8 +23,8 @@
23#include <plat/clockdomain.h> 23#include <plat/clockdomain.h>
24#include <mach-omap2/prm-regbits-34xx.h> 24#include <mach-omap2/prm-regbits-34xx.h>
25#include <mach-omap2/cm-regbits-34xx.h> 25#include <mach-omap2/cm-regbits-34xx.h>
26#include <dspbridge/dsp-mmu.h>
27#include <dspbridge/devdefs.h> 26#include <dspbridge/devdefs.h>
27#include <hw_defs.h>
28#include <dspbridge/dspioctl.h> /* for bridge_ioctl_extproc defn */ 28#include <dspbridge/dspioctl.h> /* for bridge_ioctl_extproc defn */
29#include <dspbridge/sync.h> 29#include <dspbridge/sync.h>
30#include <dspbridge/clk.h> 30#include <dspbridge/clk.h>
@@ -306,18 +306,6 @@ static const struct bpwr_clk_t bpwr_clks[] = {
306 306
307#define CLEAR_BIT_INDEX(reg, index) (reg &= ~(1 << (index))) 307#define CLEAR_BIT_INDEX(reg, index) (reg &= ~(1 << (index)))
308 308
309struct shm_segs {
310 u32 seg0_da;
311 u32 seg0_pa;
312 u32 seg0_va;
313 u32 seg0_size;
314 u32 seg1_da;
315 u32 seg1_pa;
316 u32 seg1_va;
317 u32 seg1_size;
318};
319
320
321/* This Bridge driver's device context: */ 309/* This Bridge driver's device context: */
322struct bridge_dev_context { 310struct bridge_dev_context {
323 struct dev_object *hdev_obj; /* Handle to Bridge device object. */ 311 struct dev_object *hdev_obj; /* Handle to Bridge device object. */
@@ -328,6 +316,7 @@ struct bridge_dev_context {
328 */ 316 */
329 u32 dw_dsp_ext_base_addr; /* See the comment above */ 317 u32 dw_dsp_ext_base_addr; /* See the comment above */
330 u32 dw_api_reg_base; /* API mem map'd registers */ 318 u32 dw_api_reg_base; /* API mem map'd registers */
319 void __iomem *dw_dsp_mmu_base; /* DSP MMU Mapped registers */
331 u32 dw_api_clk_base; /* CLK Registers */ 320 u32 dw_api_clk_base; /* CLK Registers */
332 u32 dw_dsp_clk_m2_base; /* DSP Clock Module m2 */ 321 u32 dw_dsp_clk_m2_base; /* DSP Clock Module m2 */
333 u32 dw_public_rhea; /* Pub Rhea */ 322 u32 dw_public_rhea; /* Pub Rhea */
@@ -339,8 +328,7 @@ struct bridge_dev_context {
339 u32 dw_internal_size; /* Internal memory size */ 328 u32 dw_internal_size; /* Internal memory size */
340 329
341 struct omap_mbox *mbox; /* Mail box handle */ 330 struct omap_mbox *mbox; /* Mail box handle */
342 struct iommu *dsp_mmu; /* iommu for iva2 handler */ 331
343 struct shm_segs sh_s;
344 struct cfg_hostres *resources; /* Host Resources */ 332 struct cfg_hostres *resources; /* Host Resources */
345 333
346 /* 334 /*
@@ -353,6 +341,7 @@ struct bridge_dev_context {
353 341
354 /* TC Settings */ 342 /* TC Settings */
355 bool tc_word_swap_on; /* Traffic Controller Word Swap */ 343 bool tc_word_swap_on; /* Traffic Controller Word Swap */
344 struct pg_table_attrs *pt_attrs;
356 u32 dsp_per_clks; 345 u32 dsp_per_clks;
357}; 346};
358 347
diff --git a/drivers/staging/tidspbridge/core/dsp-mmu.c b/drivers/staging/tidspbridge/core/dsp-mmu.c
deleted file mode 100644
index 983c95adc8ff..000000000000
--- a/drivers/staging/tidspbridge/core/dsp-mmu.c
+++ /dev/null
@@ -1,317 +0,0 @@
1/*
2 * dsp-mmu.c
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * DSP iommu.
7 *
8 * Copyright (C) 2010 Texas Instruments, Inc.
9 *
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19#include <dspbridge/host_os.h>
20#include <plat/dmtimer.h>
21#include <dspbridge/dbdefs.h>
22#include <dspbridge/dev.h>
23#include <dspbridge/io_sm.h>
24#include <dspbridge/dspdeh.h>
25#include "_tiomap.h"
26
27#include <dspbridge/dsp-mmu.h>
28
29#define MMU_CNTL_TWL_EN (1 << 2)
30
31static struct tasklet_struct mmu_tasklet;
32
33#ifdef CONFIG_TIDSPBRIDGE_BACKTRACE
34static void mmu_fault_print_stack(struct bridge_dev_context *dev_context)
35{
36 void *dummy_addr;
37 u32 fa, tmp;
38 struct iotlb_entry e;
39 struct iommu *mmu = dev_context->dsp_mmu;
40 dummy_addr = (void *)__get_free_page(GFP_ATOMIC);
41
42 /*
43 * Before acking the MMU fault, let's make sure MMU can only
44 * access entry #0. Then add a new entry so that the DSP OS
45 * can continue in order to dump the stack.
46 */
47 tmp = iommu_read_reg(mmu, MMU_CNTL);
48 tmp &= ~MMU_CNTL_TWL_EN;
49 iommu_write_reg(mmu, tmp, MMU_CNTL);
50 fa = iommu_read_reg(mmu, MMU_FAULT_AD);
51 e.da = fa & PAGE_MASK;
52 e.pa = virt_to_phys(dummy_addr);
53 e.valid = 1;
54 e.prsvd = 1;
55 e.pgsz = IOVMF_PGSZ_4K & MMU_CAM_PGSZ_MASK;
56 e.endian = MMU_RAM_ENDIAN_LITTLE;
57 e.elsz = MMU_RAM_ELSZ_32;
58 e.mixed = 0;
59
60 load_iotlb_entry(mmu, &e);
61
62 dsp_clk_enable(DSP_CLK_GPT8);
63
64 dsp_gpt_wait_overflow(DSP_CLK_GPT8, 0xfffffffe);
65
66 /* Clear MMU interrupt */
67 tmp = iommu_read_reg(mmu, MMU_IRQSTATUS);
68 iommu_write_reg(mmu, tmp, MMU_IRQSTATUS);
69
70 dump_dsp_stack(dev_context);
71 dsp_clk_disable(DSP_CLK_GPT8);
72
73 iopgtable_clear_entry(mmu, fa);
74 free_page((unsigned long)dummy_addr);
75}
76#endif
77
78
79static void fault_tasklet(unsigned long data)
80{
81 struct iommu *mmu = (struct iommu *)data;
82 struct bridge_dev_context *dev_ctx;
83 struct deh_mgr *dm;
84 u32 fa;
85 dev_get_deh_mgr(dev_get_first(), &dm);
86 dev_get_bridge_context(dev_get_first(), &dev_ctx);
87
88 if (!dm || !dev_ctx)
89 return;
90
91 fa = iommu_read_reg(mmu, MMU_FAULT_AD);
92
93#ifdef CONFIG_TIDSPBRIDGE_BACKTRACE
94 print_dsp_trace_buffer(dev_ctx);
95 dump_dl_modules(dev_ctx);
96 mmu_fault_print_stack(dev_ctx);
97#endif
98
99 bridge_deh_notify(dm, DSP_MMUFAULT, fa);
100}
101
102/*
103 * ======== mmu_fault_isr ========
104 * ISR to be triggered by a DSP MMU fault interrupt.
105 */
106static int mmu_fault_callback(struct iommu *mmu)
107{
108 if (!mmu)
109 return -EPERM;
110
111 iommu_write_reg(mmu, 0, MMU_IRQENABLE);
112 tasklet_schedule(&mmu_tasklet);
113 return 0;
114}
115
116/**
117 * dsp_mmu_init() - initialize dsp_mmu module and returns a handle
118 *
119 * This function initialize dsp mmu module and returns a struct iommu
120 * handle to use it for dsp maps.
121 *
122 */
123struct iommu *dsp_mmu_init()
124{
125 struct iommu *mmu;
126
127 mmu = iommu_get("iva2");
128
129 if (!IS_ERR(mmu)) {
130 tasklet_init(&mmu_tasklet, fault_tasklet, (unsigned long)mmu);
131 mmu->isr = mmu_fault_callback;
132 }
133
134 return mmu;
135}
136
137/**
138 * dsp_mmu_exit() - destroy dsp mmu module
139 * @mmu: Pointer to iommu handle.
140 *
141 * This function destroys dsp mmu module.
142 *
143 */
144void dsp_mmu_exit(struct iommu *mmu)
145{
146 if (mmu)
147 iommu_put(mmu);
148 tasklet_kill(&mmu_tasklet);
149}
150
151/**
152 * user_va2_pa() - get physical address from userspace address.
153 * @mm: mm_struct Pointer of the process.
154 * @address: Virtual user space address.
155 *
156 */
157static u32 user_va2_pa(struct mm_struct *mm, u32 address)
158{
159 pgd_t *pgd;
160 pmd_t *pmd;
161 pte_t *ptep, pte;
162
163 pgd = pgd_offset(mm, address);
164 if (!(pgd_none(*pgd) || pgd_bad(*pgd))) {
165 pmd = pmd_offset(pgd, address);
166 if (!(pmd_none(*pmd) || pmd_bad(*pmd))) {
167 ptep = pte_offset_map(pmd, address);
168 if (ptep) {
169 pte = *ptep;
170 if (pte_present(pte))
171 return pte & PAGE_MASK;
172 }
173 }
174 }
175
176 return 0;
177}
178
179/**
180 * get_io_pages() - pin and get pages of io user's buffer.
181 * @mm: mm_struct Pointer of the process.
182 * @uva: Virtual user space address.
183 * @pages Pages to be pined.
184 * @usr_pgs struct page array pointer where the user pages will be stored
185 *
186 */
187static int get_io_pages(struct mm_struct *mm, u32 uva, unsigned pages,
188 struct page **usr_pgs)
189{
190 u32 pa;
191 int i;
192 struct page *pg;
193
194 for (i = 0; i < pages; i++) {
195 pa = user_va2_pa(mm, uva);
196
197 if (!pfn_valid(__phys_to_pfn(pa)))
198 break;
199
200 pg = phys_to_page(pa);
201 usr_pgs[i] = pg;
202 get_page(pg);
203 }
204 return i;
205}
206
207/**
208 * user_to_dsp_map() - maps user to dsp virtual address
209 * @mmu: Pointer to iommu handle.
210 * @uva: Virtual user space address.
211 * @da DSP address
212 * @size Buffer size to map.
213 * @usr_pgs struct page array pointer where the user pages will be stored
214 *
215 * This function maps a user space buffer into DSP virtual address.
216 *
217 */
218u32 user_to_dsp_map(struct iommu *mmu, u32 uva, u32 da, u32 size,
219 struct page **usr_pgs)
220{
221 int res, w;
222 unsigned pages;
223 int i;
224 struct vm_area_struct *vma;
225 struct mm_struct *mm = current->mm;
226 struct sg_table *sgt;
227 struct scatterlist *sg;
228
229 if (!size || !usr_pgs)
230 return -EINVAL;
231
232 pages = size / PG_SIZE4K;
233
234 down_read(&mm->mmap_sem);
235 vma = find_vma(mm, uva);
236 while (vma && (uva + size > vma->vm_end))
237 vma = find_vma(mm, vma->vm_end + 1);
238
239 if (!vma) {
240 pr_err("%s: Failed to get VMA region for 0x%x (%d)\n",
241 __func__, uva, size);
242 up_read(&mm->mmap_sem);
243 return -EINVAL;
244 }
245 if (vma->vm_flags & (VM_WRITE | VM_MAYWRITE))
246 w = 1;
247
248 if (vma->vm_flags & VM_IO)
249 i = get_io_pages(mm, uva, pages, usr_pgs);
250 else
251 i = get_user_pages(current, mm, uva, pages, w, 1,
252 usr_pgs, NULL);
253 up_read(&mm->mmap_sem);
254
255 if (i < 0)
256 return i;
257
258 if (i < pages) {
259 res = -EFAULT;
260 goto err_pages;
261 }
262
263 sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
264 if (!sgt) {
265 res = -ENOMEM;
266 goto err_pages;
267 }
268
269 res = sg_alloc_table(sgt, pages, GFP_KERNEL);
270
271 if (res < 0)
272 goto err_sg;
273
274 for_each_sg(sgt->sgl, sg, sgt->nents, i)
275 sg_set_page(sg, usr_pgs[i], PAGE_SIZE, 0);
276
277 da = iommu_vmap(mmu, da, sgt, IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_32);
278
279 if (!IS_ERR_VALUE(da))
280 return da;
281 res = (int)da;
282
283 sg_free_table(sgt);
284err_sg:
285 kfree(sgt);
286 i = pages;
287err_pages:
288 while (i--)
289 put_page(usr_pgs[i]);
290 return res;
291}
292
293/**
294 * user_to_dsp_unmap() - unmaps DSP virtual buffer.
295 * @mmu: Pointer to iommu handle.
296 * @da DSP address
297 *
298 * This function unmaps a user space buffer into DSP virtual address.
299 *
300 */
301int user_to_dsp_unmap(struct iommu *mmu, u32 da)
302{
303 unsigned i;
304 struct sg_table *sgt;
305 struct scatterlist *sg;
306
307 sgt = iommu_vunmap(mmu, da);
308 if (!sgt)
309 return -EFAULT;
310
311 for_each_sg(sgt->sgl, sg, sgt->nents, i)
312 put_page(sg_page(sg));
313 sg_free_table(sgt);
314 kfree(sgt);
315
316 return 0;
317}
diff --git a/drivers/staging/tidspbridge/core/io_sm.c b/drivers/staging/tidspbridge/core/io_sm.c
index 194badaba0ed..571864555ddd 100644
--- a/drivers/staging/tidspbridge/core/io_sm.c
+++ b/drivers/staging/tidspbridge/core/io_sm.c
@@ -39,6 +39,10 @@
39#include <dspbridge/ntfy.h> 39#include <dspbridge/ntfy.h>
40#include <dspbridge/sync.h> 40#include <dspbridge/sync.h>
41 41
42/* Hardware Abstraction Layer */
43#include <hw_defs.h>
44#include <hw_mmu.h>
45
42/* Bridge Driver */ 46/* Bridge Driver */
43#include <dspbridge/dspdeh.h> 47#include <dspbridge/dspdeh.h>
44#include <dspbridge/dspio.h> 48#include <dspbridge/dspio.h>
@@ -287,7 +291,6 @@ int bridge_io_on_loaded(struct io_mgr *hio_mgr)
287 struct cod_manager *cod_man; 291 struct cod_manager *cod_man;
288 struct chnl_mgr *hchnl_mgr; 292 struct chnl_mgr *hchnl_mgr;
289 struct msg_mgr *hmsg_mgr; 293 struct msg_mgr *hmsg_mgr;
290 struct shm_segs *sm_sg;
291 u32 ul_shm_base; 294 u32 ul_shm_base;
292 u32 ul_shm_base_offset; 295 u32 ul_shm_base_offset;
293 u32 ul_shm_limit; 296 u32 ul_shm_limit;
@@ -310,9 +313,18 @@ int bridge_io_on_loaded(struct io_mgr *hio_mgr)
310 struct bridge_ioctl_extproc ae_proc[BRDIOCTL_NUMOFMMUTLB]; 313 struct bridge_ioctl_extproc ae_proc[BRDIOCTL_NUMOFMMUTLB];
311 struct cfg_hostres *host_res; 314 struct cfg_hostres *host_res;
312 struct bridge_dev_context *pbridge_context; 315 struct bridge_dev_context *pbridge_context;
316 u32 map_attrs;
313 u32 shm0_end; 317 u32 shm0_end;
314 u32 ul_dyn_ext_base; 318 u32 ul_dyn_ext_base;
315 u32 ul_seg1_size = 0; 319 u32 ul_seg1_size = 0;
320 u32 pa_curr = 0;
321 u32 va_curr = 0;
322 u32 gpp_va_curr = 0;
323 u32 num_bytes = 0;
324 u32 all_bits = 0;
325 u32 page_size[] = { HW_PAGE_SIZE16MB, HW_PAGE_SIZE1MB,
326 HW_PAGE_SIZE64KB, HW_PAGE_SIZE4KB
327 };
316 328
317 status = dev_get_bridge_context(hio_mgr->hdev_obj, &pbridge_context); 329 status = dev_get_bridge_context(hio_mgr->hdev_obj, &pbridge_context);
318 if (!pbridge_context) { 330 if (!pbridge_context) {
@@ -325,8 +337,6 @@ int bridge_io_on_loaded(struct io_mgr *hio_mgr)
325 status = -EFAULT; 337 status = -EFAULT;
326 goto func_end; 338 goto func_end;
327 } 339 }
328 sm_sg = &pbridge_context->sh_s;
329
330 status = dev_get_cod_mgr(hio_mgr->hdev_obj, &cod_man); 340 status = dev_get_cod_mgr(hio_mgr->hdev_obj, &cod_man);
331 if (!cod_man) { 341 if (!cod_man) {
332 status = -EFAULT; 342 status = -EFAULT;
@@ -461,14 +471,129 @@ int bridge_io_on_loaded(struct io_mgr *hio_mgr)
461 if (status) 471 if (status)
462 goto func_end; 472 goto func_end;
463 473
464 sm_sg->seg1_pa = ul_gpp_pa; 474 pa_curr = ul_gpp_pa;
465 sm_sg->seg1_da = ul_dyn_ext_base; 475 va_curr = ul_dyn_ext_base * hio_mgr->word_size;
466 sm_sg->seg1_va = ul_gpp_va; 476 gpp_va_curr = ul_gpp_va;
467 sm_sg->seg1_size = ul_seg1_size; 477 num_bytes = ul_seg1_size;
468 sm_sg->seg0_pa = ul_gpp_pa + ul_pad_size + ul_seg1_size; 478
469 sm_sg->seg0_da = ul_dsp_va; 479 /*
470 sm_sg->seg0_va = ul_gpp_va + ul_pad_size + ul_seg1_size; 480 * Try to fit into TLB entries. If not possible, push them to page
471 sm_sg->seg0_size = ul_seg_size; 481 * tables. It is quite possible that if sections are not on
482 * bigger page boundary, we may end up making several small pages.
483 * So, push them onto page tables, if that is the case.
484 */
485 map_attrs = 0x00000000;
486 map_attrs = DSP_MAPLITTLEENDIAN;
487 map_attrs |= DSP_MAPPHYSICALADDR;
488 map_attrs |= DSP_MAPELEMSIZE32;
489 map_attrs |= DSP_MAPDONOTLOCK;
490
491 while (num_bytes) {
492 /*
493 * To find the max. page size with which both PA & VA are
494 * aligned.
495 */
496 all_bits = pa_curr | va_curr;
497 dev_dbg(bridge, "all_bits %x, pa_curr %x, va_curr %x, "
498 "num_bytes %x\n", all_bits, pa_curr, va_curr,
499 num_bytes);
500 for (i = 0; i < 4; i++) {
501 if ((num_bytes >= page_size[i]) && ((all_bits &
502 (page_size[i] -
503 1)) == 0)) {
504 status =
505 hio_mgr->intf_fxns->
506 pfn_brd_mem_map(hio_mgr->hbridge_context,
507 pa_curr, va_curr,
508 page_size[i], map_attrs,
509 NULL);
510 if (status)
511 goto func_end;
512 pa_curr += page_size[i];
513 va_curr += page_size[i];
514 gpp_va_curr += page_size[i];
515 num_bytes -= page_size[i];
516 /*
517 * Don't try smaller sizes. Hopefully we have
518 * reached an address aligned to a bigger page
519 * size.
520 */
521 break;
522 }
523 }
524 }
525 pa_curr += ul_pad_size;
526 va_curr += ul_pad_size;
527 gpp_va_curr += ul_pad_size;
528
529 /* Configure the TLB entries for the next cacheable segment */
530 num_bytes = ul_seg_size;
531 va_curr = ul_dsp_va * hio_mgr->word_size;
532 while (num_bytes) {
533 /*
534 * To find the max. page size with which both PA & VA are
535 * aligned.
536 */
537 all_bits = pa_curr | va_curr;
538 dev_dbg(bridge, "all_bits for Seg1 %x, pa_curr %x, "
539 "va_curr %x, num_bytes %x\n", all_bits, pa_curr,
540 va_curr, num_bytes);
541 for (i = 0; i < 4; i++) {
542 if (!(num_bytes >= page_size[i]) ||
543 !((all_bits & (page_size[i] - 1)) == 0))
544 continue;
545 if (ndx < MAX_LOCK_TLB_ENTRIES) {
546 /*
547 * This is the physical address written to
548 * DSP MMU.
549 */
550 ae_proc[ndx].ul_gpp_pa = pa_curr;
551 /*
552 * This is the virtual uncached ioremapped
553 * address!!!
554 */
555 ae_proc[ndx].ul_gpp_va = gpp_va_curr;
556 ae_proc[ndx].ul_dsp_va =
557 va_curr / hio_mgr->word_size;
558 ae_proc[ndx].ul_size = page_size[i];
559 ae_proc[ndx].endianism = HW_LITTLE_ENDIAN;
560 ae_proc[ndx].elem_size = HW_ELEM_SIZE16BIT;
561 ae_proc[ndx].mixed_mode = HW_MMU_CPUES;
562 dev_dbg(bridge, "shm MMU TLB entry PA %x"
563 " VA %x DSP_VA %x Size %x\n",
564 ae_proc[ndx].ul_gpp_pa,
565 ae_proc[ndx].ul_gpp_va,
566 ae_proc[ndx].ul_dsp_va *
567 hio_mgr->word_size, page_size[i]);
568 ndx++;
569 } else {
570 status =
571 hio_mgr->intf_fxns->
572 pfn_brd_mem_map(hio_mgr->hbridge_context,
573 pa_curr, va_curr,
574 page_size[i], map_attrs,
575 NULL);
576 dev_dbg(bridge,
577 "shm MMU PTE entry PA %x"
578 " VA %x DSP_VA %x Size %x\n",
579 ae_proc[ndx].ul_gpp_pa,
580 ae_proc[ndx].ul_gpp_va,
581 ae_proc[ndx].ul_dsp_va *
582 hio_mgr->word_size, page_size[i]);
583 if (status)
584 goto func_end;
585 }
586 pa_curr += page_size[i];
587 va_curr += page_size[i];
588 gpp_va_curr += page_size[i];
589 num_bytes -= page_size[i];
590 /*
591 * Don't try smaller sizes. Hopefully we have reached
592 * an address aligned to a bigger page size.
593 */
594 break;
595 }
596 }
472 597
473 /* 598 /*
474 * Copy remaining entries from CDB. All entries are 1 MB and 599 * Copy remaining entries from CDB. All entries are 1 MB and
@@ -509,12 +634,38 @@ int bridge_io_on_loaded(struct io_mgr *hio_mgr)
509 "DSP_VA 0x%x\n", ae_proc[ndx].ul_gpp_pa, 634 "DSP_VA 0x%x\n", ae_proc[ndx].ul_gpp_pa,
510 ae_proc[ndx].ul_dsp_va); 635 ae_proc[ndx].ul_dsp_va);
511 ndx++; 636 ndx++;
637 } else {
638 status = hio_mgr->intf_fxns->pfn_brd_mem_map
639 (hio_mgr->hbridge_context,
640 hio_mgr->ext_proc_info.ty_tlb[i].
641 ul_gpp_phys,
642 hio_mgr->ext_proc_info.ty_tlb[i].
643 ul_dsp_virt, 0x100000, map_attrs,
644 NULL);
512 } 645 }
513 } 646 }
514 if (status) 647 if (status)
515 goto func_end; 648 goto func_end;
516 } 649 }
517 650
651 map_attrs = 0x00000000;
652 map_attrs = DSP_MAPLITTLEENDIAN;
653 map_attrs |= DSP_MAPPHYSICALADDR;
654 map_attrs |= DSP_MAPELEMSIZE32;
655 map_attrs |= DSP_MAPDONOTLOCK;
656
657 /* Map the L4 peripherals */
658 i = 0;
659 while (l4_peripheral_table[i].phys_addr) {
660 status = hio_mgr->intf_fxns->pfn_brd_mem_map
661 (hio_mgr->hbridge_context, l4_peripheral_table[i].phys_addr,
662 l4_peripheral_table[i].dsp_virt_addr, HW_PAGE_SIZE4KB,
663 map_attrs, NULL);
664 if (status)
665 goto func_end;
666 i++;
667 }
668
518 for (i = ndx; i < BRDIOCTL_NUMOFMMUTLB; i++) { 669 for (i = ndx; i < BRDIOCTL_NUMOFMMUTLB; i++) {
519 ae_proc[i].ul_dsp_va = 0; 670 ae_proc[i].ul_dsp_va = 0;
520 ae_proc[i].ul_gpp_pa = 0; 671 ae_proc[i].ul_gpp_pa = 0;
@@ -537,12 +688,12 @@ int bridge_io_on_loaded(struct io_mgr *hio_mgr)
537 status = -EFAULT; 688 status = -EFAULT;
538 goto func_end; 689 goto func_end;
539 } else { 690 } else {
540 if (sm_sg->seg0_da > ul_shm_base) { 691 if (ae_proc[0].ul_dsp_va > ul_shm_base) {
541 status = -EPERM; 692 status = -EPERM;
542 goto func_end; 693 goto func_end;
543 } 694 }
544 /* ul_shm_base may not be at ul_dsp_va address */ 695 /* ul_shm_base may not be at ul_dsp_va address */
545 ul_shm_base_offset = (ul_shm_base - sm_sg->seg0_da) * 696 ul_shm_base_offset = (ul_shm_base - ae_proc[0].ul_dsp_va) *
546 hio_mgr->word_size; 697 hio_mgr->word_size;
547 /* 698 /*
548 * bridge_dev_ctrl() will set dev context dsp-mmu info. In 699 * bridge_dev_ctrl() will set dev context dsp-mmu info. In
@@ -566,7 +717,8 @@ int bridge_io_on_loaded(struct io_mgr *hio_mgr)
566 goto func_end; 717 goto func_end;
567 } 718 }
568 /* Register SM */ 719 /* Register SM */
569 status = register_shm_segs(hio_mgr, cod_man, sm_sg->seg0_pa); 720 status =
721 register_shm_segs(hio_mgr, cod_man, ae_proc[0].ul_gpp_pa);
570 } 722 }
571 723
572 hio_mgr->shared_mem = (struct shm *)ul_shm_base; 724 hio_mgr->shared_mem = (struct shm *)ul_shm_base;
diff --git a/drivers/staging/tidspbridge/core/tiomap3430.c b/drivers/staging/tidspbridge/core/tiomap3430.c
index f22bc12bc0d3..1be081f917a7 100644
--- a/drivers/staging/tidspbridge/core/tiomap3430.c
+++ b/drivers/staging/tidspbridge/core/tiomap3430.c
@@ -23,7 +23,6 @@
23#include <dspbridge/host_os.h> 23#include <dspbridge/host_os.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/mmzone.h> 25#include <linux/mmzone.h>
26#include <plat/control.h>
27 26
28/* ----------------------------------- DSP/BIOS Bridge */ 27/* ----------------------------------- DSP/BIOS Bridge */
29#include <dspbridge/dbdefs.h> 28#include <dspbridge/dbdefs.h>
@@ -35,6 +34,10 @@
35#include <dspbridge/drv.h> 34#include <dspbridge/drv.h>
36#include <dspbridge/sync.h> 35#include <dspbridge/sync.h>
37 36
37/* ------------------------------------ Hardware Abstraction Layer */
38#include <hw_defs.h>
39#include <hw_mmu.h>
40
38/* ----------------------------------- Link Driver */ 41/* ----------------------------------- Link Driver */
39#include <dspbridge/dspdefs.h> 42#include <dspbridge/dspdefs.h>
40#include <dspbridge/dspchnl.h> 43#include <dspbridge/dspchnl.h>
@@ -47,6 +50,7 @@
47/* ----------------------------------- Platform Manager */ 50/* ----------------------------------- Platform Manager */
48#include <dspbridge/dev.h> 51#include <dspbridge/dev.h>
49#include <dspbridge/dspapi.h> 52#include <dspbridge/dspapi.h>
53#include <dspbridge/dmm.h>
50#include <dspbridge/wdt.h> 54#include <dspbridge/wdt.h>
51 55
52/* ----------------------------------- Local */ 56/* ----------------------------------- Local */
@@ -67,6 +71,20 @@
67#define MMU_SMALL_PAGE_MASK 0xFFFFF000 71#define MMU_SMALL_PAGE_MASK 0xFFFFF000
68#define OMAP3_IVA2_BOOTADDR_MASK 0xFFFFFC00 72#define OMAP3_IVA2_BOOTADDR_MASK 0xFFFFFC00
69#define PAGES_II_LVL_TABLE 512 73#define PAGES_II_LVL_TABLE 512
74#define PHYS_TO_PAGE(phys) pfn_to_page((phys) >> PAGE_SHIFT)
75
76/*
77 * This is a totally ugly layer violation, but needed until
78 * omap_ctrl_set_dsp_boot*() are provided.
79 */
80#define OMAP3_IVA2_BOOTMOD_IDLE 1
81#define OMAP2_CONTROL_GENERAL 0x270
82#define OMAP343X_CONTROL_IVA2_BOOTADDR (OMAP2_CONTROL_GENERAL + 0x0190)
83#define OMAP343X_CONTROL_IVA2_BOOTMOD (OMAP2_CONTROL_GENERAL + 0x0194)
84
85#define OMAP343X_CTRL_REGADDR(reg) \
86 OMAP2_L4_IO_ADDRESS(OMAP343X_CTRL_BASE + (reg))
87
70 88
71/* Forward Declarations: */ 89/* Forward Declarations: */
72static int bridge_brd_monitor(struct bridge_dev_context *dev_ctxt); 90static int bridge_brd_monitor(struct bridge_dev_context *dev_ctxt);
@@ -91,6 +109,12 @@ static int bridge_brd_mem_copy(struct bridge_dev_context *dev_ctxt,
91static int bridge_brd_mem_write(struct bridge_dev_context *dev_ctxt, 109static int bridge_brd_mem_write(struct bridge_dev_context *dev_ctxt,
92 u8 *host_buff, u32 dsp_addr, 110 u8 *host_buff, u32 dsp_addr,
93 u32 ul_num_bytes, u32 mem_type); 111 u32 ul_num_bytes, u32 mem_type);
112static int bridge_brd_mem_map(struct bridge_dev_context *dev_ctxt,
113 u32 ul_mpu_addr, u32 virt_addr,
114 u32 ul_num_bytes, u32 ul_map_attr,
115 struct page **mapped_pages);
116static int bridge_brd_mem_un_map(struct bridge_dev_context *dev_ctxt,
117 u32 virt_addr, u32 ul_num_bytes);
94static int bridge_dev_create(struct bridge_dev_context 118static int bridge_dev_create(struct bridge_dev_context
95 **dev_cntxt, 119 **dev_cntxt,
96 struct dev_object *hdev_obj, 120 struct dev_object *hdev_obj,
@@ -98,8 +122,57 @@ static int bridge_dev_create(struct bridge_dev_context
98static int bridge_dev_ctrl(struct bridge_dev_context *dev_context, 122static int bridge_dev_ctrl(struct bridge_dev_context *dev_context,
99 u32 dw_cmd, void *pargs); 123 u32 dw_cmd, void *pargs);
100static int bridge_dev_destroy(struct bridge_dev_context *dev_ctxt); 124static int bridge_dev_destroy(struct bridge_dev_context *dev_ctxt);
125static u32 user_va2_pa(struct mm_struct *mm, u32 address);
126static int pte_update(struct bridge_dev_context *dev_ctxt, u32 pa,
127 u32 va, u32 size,
128 struct hw_mmu_map_attrs_t *map_attrs);
129static int pte_set(struct pg_table_attrs *pt, u32 pa, u32 va,
130 u32 size, struct hw_mmu_map_attrs_t *attrs);
131static int mem_map_vmalloc(struct bridge_dev_context *dev_context,
132 u32 ul_mpu_addr, u32 virt_addr,
133 u32 ul_num_bytes,
134 struct hw_mmu_map_attrs_t *hw_attrs);
135
101bool wait_for_start(struct bridge_dev_context *dev_context, u32 dw_sync_addr); 136bool wait_for_start(struct bridge_dev_context *dev_context, u32 dw_sync_addr);
102 137
138/* ----------------------------------- Globals */
139
140/* Attributes of L2 page tables for DSP MMU */
141struct page_info {
142 u32 num_entries; /* Number of valid PTEs in the L2 PT */
143};
144
145/* Attributes used to manage the DSP MMU page tables */
146struct pg_table_attrs {
147 spinlock_t pg_lock; /* Critical section object handle */
148
149 u32 l1_base_pa; /* Physical address of the L1 PT */
150 u32 l1_base_va; /* Virtual address of the L1 PT */
151 u32 l1_size; /* Size of the L1 PT */
152 u32 l1_tbl_alloc_pa;
153 /* Physical address of Allocated mem for L1 table. May not be aligned */
154 u32 l1_tbl_alloc_va;
155 /* Virtual address of Allocated mem for L1 table. May not be aligned */
156 u32 l1_tbl_alloc_sz;
157 /* Size of consistent memory allocated for L1 table.
158 * May not be aligned */
159
160 u32 l2_base_pa; /* Physical address of the L2 PT */
161 u32 l2_base_va; /* Virtual address of the L2 PT */
162 u32 l2_size; /* Size of the L2 PT */
163 u32 l2_tbl_alloc_pa;
164 /* Physical address of Allocated mem for L2 table. May not be aligned */
165 u32 l2_tbl_alloc_va;
166 /* Virtual address of Allocated mem for L2 table. May not be aligned */
167 u32 l2_tbl_alloc_sz;
168 /* Size of consistent memory allocated for L2 table.
169 * May not be aligned */
170
171 u32 l2_num_pages; /* Number of allocated L2 PT */
172 /* Array [l2_num_pages] of L2 PT info structs */
173 struct page_info *pg_info;
174};
175
103/* 176/*
104 * This Bridge driver's function interface table. 177 * This Bridge driver's function interface table.
105 */ 178 */
@@ -119,6 +192,8 @@ static struct bridge_drv_interface drv_interface_fxns = {
119 bridge_brd_set_state, 192 bridge_brd_set_state,
120 bridge_brd_mem_copy, 193 bridge_brd_mem_copy,
121 bridge_brd_mem_write, 194 bridge_brd_mem_write,
195 bridge_brd_mem_map,
196 bridge_brd_mem_un_map,
122 /* The following CHNL functions are provided by chnl_io.lib: */ 197 /* The following CHNL functions are provided by chnl_io.lib: */
123 bridge_chnl_create, 198 bridge_chnl_create,
124 bridge_chnl_destroy, 199 bridge_chnl_destroy,
@@ -148,6 +223,27 @@ static struct bridge_drv_interface drv_interface_fxns = {
148 bridge_msg_set_queue_id, 223 bridge_msg_set_queue_id,
149}; 224};
150 225
226static inline void flush_all(struct bridge_dev_context *dev_context)
227{
228 if (dev_context->dw_brd_state == BRD_DSP_HIBERNATION ||
229 dev_context->dw_brd_state == BRD_HIBERNATION)
230 wake_dsp(dev_context, NULL);
231
232 hw_mmu_tlb_flush_all(dev_context->dw_dsp_mmu_base);
233}
234
235static void bad_page_dump(u32 pa, struct page *pg)
236{
237 pr_emerg("DSPBRIDGE: MAP function: COUNT 0 FOR PA 0x%x\n", pa);
238 pr_emerg("Bad page state in process '%s'\n"
239 "page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n"
240 "Backtrace:\n",
241 current->comm, pg, (int)(2 * sizeof(unsigned long)),
242 (unsigned long)pg->flags, pg->mapping,
243 page_mapcount(pg), page_count(pg));
244 dump_stack();
245}
246
151/* 247/*
152 * ======== bridge_drv_entry ======== 248 * ======== bridge_drv_entry ========
153 * purpose: 249 * purpose:
@@ -203,7 +299,8 @@ static int bridge_brd_monitor(struct bridge_dev_context *dev_ctxt)
203 (*pdata->dsp_cm_write)(OMAP34XX_CLKSTCTRL_DISABLE_AUTO, 299 (*pdata->dsp_cm_write)(OMAP34XX_CLKSTCTRL_DISABLE_AUTO,
204 OMAP3430_IVA2_MOD, OMAP2_CM_CLKSTCTRL); 300 OMAP3430_IVA2_MOD, OMAP2_CM_CLKSTCTRL);
205 } 301 }
206 302 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST2_IVA2_MASK, 0,
303 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
207 dsp_clk_enable(DSP_CLK_IVA2); 304 dsp_clk_enable(DSP_CLK_IVA2);
208 305
209 /* set the device state to IDLE */ 306 /* set the device state to IDLE */
@@ -274,17 +371,14 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
274{ 371{
275 int status = 0; 372 int status = 0;
276 struct bridge_dev_context *dev_context = dev_ctxt; 373 struct bridge_dev_context *dev_context = dev_ctxt;
277 struct iommu *mmu = NULL;
278 struct shm_segs *sm_sg;
279 int l4_i = 0, tlb_i = 0;
280 u32 sg0_da = 0, sg1_da = 0;
281 struct bridge_ioctl_extproc *tlb = dev_context->atlb_entry;
282 u32 dw_sync_addr = 0; 374 u32 dw_sync_addr = 0;
283 u32 ul_shm_base; /* Gpp Phys SM base addr(byte) */ 375 u32 ul_shm_base; /* Gpp Phys SM base addr(byte) */
284 u32 ul_shm_base_virt; /* Dsp Virt SM base addr */ 376 u32 ul_shm_base_virt; /* Dsp Virt SM base addr */
285 u32 ul_tlb_base_virt; /* Base of MMU TLB entry */ 377 u32 ul_tlb_base_virt; /* Base of MMU TLB entry */
286 /* Offset of shm_base_virt from tlb_base_virt */ 378 /* Offset of shm_base_virt from tlb_base_virt */
287 u32 ul_shm_offset_virt; 379 u32 ul_shm_offset_virt;
380 s32 entry_ndx;
381 s32 itmp_entry_ndx = 0; /* DSP-MMU TLB entry base address */
288 struct cfg_hostres *resources = NULL; 382 struct cfg_hostres *resources = NULL;
289 u32 temp; 383 u32 temp;
290 u32 ul_dsp_clk_rate; 384 u32 ul_dsp_clk_rate;
@@ -305,12 +399,12 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
305 ul_shm_base_virt *= DSPWORDSIZE; 399 ul_shm_base_virt *= DSPWORDSIZE;
306 DBC_ASSERT(ul_shm_base_virt != 0); 400 DBC_ASSERT(ul_shm_base_virt != 0);
307 /* DSP Virtual address */ 401 /* DSP Virtual address */
308 ul_tlb_base_virt = dev_context->sh_s.seg0_da; 402 ul_tlb_base_virt = dev_context->atlb_entry[0].ul_dsp_va;
309 DBC_ASSERT(ul_tlb_base_virt <= ul_shm_base_virt); 403 DBC_ASSERT(ul_tlb_base_virt <= ul_shm_base_virt);
310 ul_shm_offset_virt = 404 ul_shm_offset_virt =
311 ul_shm_base_virt - (ul_tlb_base_virt * DSPWORDSIZE); 405 ul_shm_base_virt - (ul_tlb_base_virt * DSPWORDSIZE);
312 /* Kernel logical address */ 406 /* Kernel logical address */
313 ul_shm_base = dev_context->sh_s.seg0_va + ul_shm_offset_virt; 407 ul_shm_base = dev_context->atlb_entry[0].ul_gpp_va + ul_shm_offset_virt;
314 408
315 DBC_ASSERT(ul_shm_base != 0); 409 DBC_ASSERT(ul_shm_base != 0);
316 /* 2nd wd is used as sync field */ 410 /* 2nd wd is used as sync field */
@@ -345,83 +439,78 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
345 OMAP343X_CONTROL_IVA2_BOOTMOD)); 439 OMAP343X_CONTROL_IVA2_BOOTMOD));
346 } 440 }
347 } 441 }
348
349 if (!status) { 442 if (!status) {
443 /* Reset and Unreset the RST2, so that BOOTADDR is copied to
444 * IVA2 SYSC register */
445 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST2_IVA2_MASK,
446 OMAP3430_RST2_IVA2_MASK, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
447 udelay(100);
350 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST2_IVA2_MASK, 0, 448 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST2_IVA2_MASK, 0,
351 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL); 449 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
352 mmu = dev_context->dsp_mmu; 450 udelay(100);
353 if (mmu) 451
354 dsp_mmu_exit(mmu); 452 /* Disbale the DSP MMU */
355 mmu = dsp_mmu_init(); 453 hw_mmu_disable(resources->dw_dmmu_base);
356 if (IS_ERR(mmu)) { 454 /* Disable TWL */
357 dev_err(bridge, "dsp_mmu_init failed!\n"); 455 hw_mmu_twl_disable(resources->dw_dmmu_base);
358 dev_context->dsp_mmu = NULL; 456
359 status = (int)mmu; 457 /* Only make TLB entry if both addresses are non-zero */
360 } 458 for (entry_ndx = 0; entry_ndx < BRDIOCTL_NUMOFMMUTLB;
361 } 459 entry_ndx++) {
362 if (!status) { 460 struct bridge_ioctl_extproc *e = &dev_context->atlb_entry[entry_ndx];
363 dev_context->dsp_mmu = mmu; 461 struct hw_mmu_map_attrs_t map_attrs = {
364 sm_sg = &dev_context->sh_s; 462 .endianism = e->endianism,
365 sg0_da = iommu_kmap(mmu, sm_sg->seg0_da, sm_sg->seg0_pa, 463 .element_size = e->elem_size,
366 sm_sg->seg0_size, IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_32); 464 .mixed_size = e->mixed_mode,
367 if (IS_ERR_VALUE(sg0_da)) { 465 };
368 status = (int)sg0_da; 466
369 sg0_da = 0; 467 if (!e->ul_gpp_pa || !e->ul_dsp_va)
370 }
371 }
372 if (!status) {
373 sg1_da = iommu_kmap(mmu, sm_sg->seg1_da, sm_sg->seg1_pa,
374 sm_sg->seg1_size, IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_32);
375 if (IS_ERR_VALUE(sg1_da)) {
376 status = (int)sg1_da;
377 sg1_da = 0;
378 }
379 }
380 if (!status) {
381 u32 da;
382 for (tlb_i = 0; tlb_i < BRDIOCTL_NUMOFMMUTLB; tlb_i++) {
383 if (!tlb[tlb_i].ul_gpp_pa)
384 continue; 468 continue;
385 469
386 dev_dbg(bridge, "IOMMU %d GppPa: 0x%x DspVa 0x%x Size" 470 dev_dbg(bridge,
387 " 0x%x\n", tlb_i, tlb[tlb_i].ul_gpp_pa, 471 "MMU %d, pa: 0x%x, va: 0x%x, size: 0x%x",
388 tlb[tlb_i].ul_dsp_va, tlb[tlb_i].ul_size); 472 itmp_entry_ndx,
389 473 e->ul_gpp_pa,
390 da = iommu_kmap(mmu, tlb[tlb_i].ul_dsp_va, 474 e->ul_dsp_va,
391 tlb[tlb_i].ul_gpp_pa, PAGE_SIZE, 475 e->ul_size);
392 IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_32); 476
393 if (IS_ERR_VALUE(da)) { 477 hw_mmu_tlb_add(dev_context->dw_dsp_mmu_base,
394 status = (int)da; 478 e->ul_gpp_pa,
395 break; 479 e->ul_dsp_va,
396 } 480 e->ul_size,
397 } 481 itmp_entry_ndx,
398 } 482 &map_attrs, 1, 1);
399 if (!status) { 483
400 u32 da; 484 itmp_entry_ndx++;
401 l4_i = 0;
402 while (l4_peripheral_table[l4_i].phys_addr) {
403 da = iommu_kmap(mmu, l4_peripheral_table[l4_i].
404 dsp_virt_addr, l4_peripheral_table[l4_i].
405 phys_addr, PAGE_SIZE,
406 IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_32);
407 if (IS_ERR_VALUE(da)) {
408 status = (int)da;
409 break;
410 }
411 l4_i++;
412 } 485 }
413 } 486 }
414 487
415 /* Lock the above TLB entries and get the BIOS and load monitor timer 488 /* Lock the above TLB entries and get the BIOS and load monitor timer
416 * information */ 489 * information */
417 if (!status) { 490 if (!status) {
491 hw_mmu_num_locked_set(resources->dw_dmmu_base, itmp_entry_ndx);
492 hw_mmu_victim_num_set(resources->dw_dmmu_base, itmp_entry_ndx);
493 hw_mmu_ttb_set(resources->dw_dmmu_base,
494 dev_context->pt_attrs->l1_base_pa);
495 hw_mmu_twl_enable(resources->dw_dmmu_base);
496 /* Enable the SmartIdle and AutoIdle bit for MMU_SYSCONFIG */
497
498 temp = __raw_readl((resources->dw_dmmu_base) + 0x10);
499 temp = (temp & 0xFFFFFFEF) | 0x11;
500 __raw_writel(temp, (resources->dw_dmmu_base) + 0x10);
501
502 /* Let the DSP MMU run */
503 hw_mmu_enable(resources->dw_dmmu_base);
504
418 /* Enable the BIOS clock */ 505 /* Enable the BIOS clock */
419 (void)dev_get_symbol(dev_context->hdev_obj, 506 (void)dev_get_symbol(dev_context->hdev_obj,
420 BRIDGEINIT_BIOSGPTIMER, &ul_bios_gp_timer); 507 BRIDGEINIT_BIOSGPTIMER, &ul_bios_gp_timer);
421 (void)dev_get_symbol(dev_context->hdev_obj, 508 (void)dev_get_symbol(dev_context->hdev_obj,
422 BRIDGEINIT_LOADMON_GPTIMER, 509 BRIDGEINIT_LOADMON_GPTIMER,
423 &ul_load_monitor_timer); 510 &ul_load_monitor_timer);
511 }
424 512
513 if (!status) {
425 if (ul_load_monitor_timer != 0xFFFF) { 514 if (ul_load_monitor_timer != 0xFFFF) {
426 clk_cmd = (BPWR_ENABLE_CLOCK << MBX_PM_CLK_CMDSHIFT) | 515 clk_cmd = (BPWR_ENABLE_CLOCK << MBX_PM_CLK_CMDSHIFT) |
427 ul_load_monitor_timer; 516 ul_load_monitor_timer;
@@ -430,7 +519,9 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
430 dev_dbg(bridge, "Not able to get the symbol for Load " 519 dev_dbg(bridge, "Not able to get the symbol for Load "
431 "Monitor Timer\n"); 520 "Monitor Timer\n");
432 } 521 }
522 }
433 523
524 if (!status) {
434 if (ul_bios_gp_timer != 0xFFFF) { 525 if (ul_bios_gp_timer != 0xFFFF) {
435 clk_cmd = (BPWR_ENABLE_CLOCK << MBX_PM_CLK_CMDSHIFT) | 526 clk_cmd = (BPWR_ENABLE_CLOCK << MBX_PM_CLK_CMDSHIFT) |
436 ul_bios_gp_timer; 527 ul_bios_gp_timer;
@@ -439,7 +530,9 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
439 dev_dbg(bridge, 530 dev_dbg(bridge,
440 "Not able to get the symbol for BIOS Timer\n"); 531 "Not able to get the symbol for BIOS Timer\n");
441 } 532 }
533 }
442 534
535 if (!status) {
443 /* Set the DSP clock rate */ 536 /* Set the DSP clock rate */
444 (void)dev_get_symbol(dev_context->hdev_obj, 537 (void)dev_get_symbol(dev_context->hdev_obj,
445 "_BRIDGEINIT_DSP_FREQ", &ul_dsp_clk_addr); 538 "_BRIDGEINIT_DSP_FREQ", &ul_dsp_clk_addr);
@@ -492,6 +585,9 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
492 585
493 /* Let DSP go */ 586 /* Let DSP go */
494 dev_dbg(bridge, "%s Unreset\n", __func__); 587 dev_dbg(bridge, "%s Unreset\n", __func__);
588 /* Enable DSP MMU Interrupts */
589 hw_mmu_event_enable(resources->dw_dmmu_base,
590 HW_MMU_ALL_INTERRUPTS);
495 /* release the RST1, DSP starts executing now .. */ 591 /* release the RST1, DSP starts executing now .. */
496 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST1_IVA2_MASK, 0, 592 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST1_IVA2_MASK, 0,
497 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL); 593 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
@@ -521,23 +617,11 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
521 617
522 /* update board state */ 618 /* update board state */
523 dev_context->dw_brd_state = BRD_RUNNING; 619 dev_context->dw_brd_state = BRD_RUNNING;
524 return 0; 620 /* (void)chnlsm_enable_interrupt(dev_context); */
525 } else { 621 } else {
526 dev_context->dw_brd_state = BRD_UNKNOWN; 622 dev_context->dw_brd_state = BRD_UNKNOWN;
527 } 623 }
528 } 624 }
529
530 while (tlb_i--) {
531 if (!tlb[tlb_i].ul_gpp_pa)
532 continue;
533 iommu_kunmap(mmu, tlb[tlb_i].ul_gpp_va);
534 }
535 while (l4_i--)
536 iommu_kunmap(mmu, l4_peripheral_table[l4_i].dsp_virt_addr);
537 if (sg0_da)
538 iommu_kunmap(mmu, sg0_da);
539 if (sg1_da)
540 iommu_kunmap(mmu, sg1_da);
541 return status; 625 return status;
542} 626}
543 627
@@ -553,9 +637,8 @@ static int bridge_brd_stop(struct bridge_dev_context *dev_ctxt)
553{ 637{
554 int status = 0; 638 int status = 0;
555 struct bridge_dev_context *dev_context = dev_ctxt; 639 struct bridge_dev_context *dev_context = dev_ctxt;
640 struct pg_table_attrs *pt_attrs;
556 u32 dsp_pwr_state; 641 u32 dsp_pwr_state;
557 int i;
558 struct bridge_ioctl_extproc *tlb = dev_context->atlb_entry;
559 struct omap_dsp_platform_data *pdata = 642 struct omap_dsp_platform_data *pdata =
560 omap_dspbridge_dev->dev.platform_data; 643 omap_dspbridge_dev->dev.platform_data;
561 644
@@ -591,37 +674,23 @@ static int bridge_brd_stop(struct bridge_dev_context *dev_ctxt)
591 674
592 dsp_wdt_enable(false); 675 dsp_wdt_enable(false);
593 676
594 /* Reset DSP */ 677 /* This is a good place to clear the MMU page tables as well */
595 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST1_IVA2_MASK, 678 if (dev_context->pt_attrs) {
596 OMAP3430_RST1_IVA2_MASK, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL); 679 pt_attrs = dev_context->pt_attrs;
597 680 memset((u8 *) pt_attrs->l1_base_va, 0x00, pt_attrs->l1_size);
681 memset((u8 *) pt_attrs->l2_base_va, 0x00, pt_attrs->l2_size);
682 memset((u8 *) pt_attrs->pg_info, 0x00,
683 (pt_attrs->l2_num_pages * sizeof(struct page_info)));
684 }
598 /* Disable the mailbox interrupts */ 685 /* Disable the mailbox interrupts */
599 if (dev_context->mbox) { 686 if (dev_context->mbox) {
600 omap_mbox_disable_irq(dev_context->mbox, IRQ_RX); 687 omap_mbox_disable_irq(dev_context->mbox, IRQ_RX);
601 omap_mbox_put(dev_context->mbox); 688 omap_mbox_put(dev_context->mbox);
602 dev_context->mbox = NULL; 689 dev_context->mbox = NULL;
603 } 690 }
604 if (dev_context->dsp_mmu) { 691 /* Reset IVA2 clocks*/
605 pr_err("Proc stop mmu if statement\n"); 692 (*pdata->dsp_prm_write)(OMAP3430_RST1_IVA2_MASK | OMAP3430_RST2_IVA2_MASK |
606 for (i = 0; i < BRDIOCTL_NUMOFMMUTLB; i++) { 693 OMAP3430_RST3_IVA2_MASK, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
607 if (!tlb[i].ul_gpp_pa)
608 continue;
609 iommu_kunmap(dev_context->dsp_mmu, tlb[i].ul_gpp_va);
610 }
611 i = 0;
612 while (l4_peripheral_table[i].phys_addr) {
613 iommu_kunmap(dev_context->dsp_mmu,
614 l4_peripheral_table[i].dsp_virt_addr);
615 i++;
616 }
617 iommu_kunmap(dev_context->dsp_mmu, dev_context->sh_s.seg0_da);
618 iommu_kunmap(dev_context->dsp_mmu, dev_context->sh_s.seg1_da);
619 dsp_mmu_exit(dev_context->dsp_mmu);
620 dev_context->dsp_mmu = NULL;
621 }
622 /* Reset IVA IOMMU*/
623 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST2_IVA2_MASK,
624 OMAP3430_RST2_IVA2_MASK, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
625 694
626 dsp_clock_disable_all(dev_context->dsp_per_clks); 695 dsp_clock_disable_all(dev_context->dsp_per_clks);
627 dsp_clk_disable(DSP_CLK_IVA2); 696 dsp_clk_disable(DSP_CLK_IVA2);
@@ -681,6 +750,10 @@ static int bridge_dev_create(struct bridge_dev_context
681 struct bridge_dev_context *dev_context = NULL; 750 struct bridge_dev_context *dev_context = NULL;
682 s32 entry_ndx; 751 s32 entry_ndx;
683 struct cfg_hostres *resources = config_param; 752 struct cfg_hostres *resources = config_param;
753 struct pg_table_attrs *pt_attrs;
754 u32 pg_tbl_pa;
755 u32 pg_tbl_va;
756 u32 align_size;
684 struct drv_data *drv_datap = dev_get_drvdata(bridge); 757 struct drv_data *drv_datap = dev_get_drvdata(bridge);
685 758
686 /* Allocate and initialize a data structure to contain the bridge driver 759 /* Allocate and initialize a data structure to contain the bridge driver
@@ -711,8 +784,97 @@ static int bridge_dev_create(struct bridge_dev_context
711 if (!dev_context->dw_dsp_base_addr) 784 if (!dev_context->dw_dsp_base_addr)
712 status = -EPERM; 785 status = -EPERM;
713 786
787 pt_attrs = kzalloc(sizeof(struct pg_table_attrs), GFP_KERNEL);
788 if (pt_attrs != NULL) {
789 /* Assuming that we use only DSP's memory map
790 * until 0x4000:0000 , we would need only 1024
791 * L1 enties i.e L1 size = 4K */
792 pt_attrs->l1_size = 0x1000;
793 align_size = pt_attrs->l1_size;
794 /* Align sizes are expected to be power of 2 */
795 /* we like to get aligned on L1 table size */
796 pg_tbl_va = (u32) mem_alloc_phys_mem(pt_attrs->l1_size,
797 align_size, &pg_tbl_pa);
798
799 /* Check if the PA is aligned for us */
800 if ((pg_tbl_pa) & (align_size - 1)) {
801 /* PA not aligned to page table size ,
802 * try with more allocation and align */
803 mem_free_phys_mem((void *)pg_tbl_va, pg_tbl_pa,
804 pt_attrs->l1_size);
805 /* we like to get aligned on L1 table size */
806 pg_tbl_va =
807 (u32) mem_alloc_phys_mem((pt_attrs->l1_size) * 2,
808 align_size, &pg_tbl_pa);
809 /* We should be able to get aligned table now */
810 pt_attrs->l1_tbl_alloc_pa = pg_tbl_pa;
811 pt_attrs->l1_tbl_alloc_va = pg_tbl_va;
812 pt_attrs->l1_tbl_alloc_sz = pt_attrs->l1_size * 2;
813 /* Align the PA to the next 'align' boundary */
814 pt_attrs->l1_base_pa =
815 ((pg_tbl_pa) +
816 (align_size - 1)) & (~(align_size - 1));
817 pt_attrs->l1_base_va =
818 pg_tbl_va + (pt_attrs->l1_base_pa - pg_tbl_pa);
819 } else {
820 /* We got aligned PA, cool */
821 pt_attrs->l1_tbl_alloc_pa = pg_tbl_pa;
822 pt_attrs->l1_tbl_alloc_va = pg_tbl_va;
823 pt_attrs->l1_tbl_alloc_sz = pt_attrs->l1_size;
824 pt_attrs->l1_base_pa = pg_tbl_pa;
825 pt_attrs->l1_base_va = pg_tbl_va;
826 }
827 if (pt_attrs->l1_base_va)
828 memset((u8 *) pt_attrs->l1_base_va, 0x00,
829 pt_attrs->l1_size);
830
831 /* number of L2 page tables = DMM pool used + SHMMEM +EXTMEM +
832 * L4 pages */
833 pt_attrs->l2_num_pages = ((DMMPOOLSIZE >> 20) + 6);
834 pt_attrs->l2_size = HW_MMU_COARSE_PAGE_SIZE *
835 pt_attrs->l2_num_pages;
836 align_size = 4; /* Make it u32 aligned */
837 /* we like to get aligned on L1 table size */
838 pg_tbl_va = (u32) mem_alloc_phys_mem(pt_attrs->l2_size,
839 align_size, &pg_tbl_pa);
840 pt_attrs->l2_tbl_alloc_pa = pg_tbl_pa;
841 pt_attrs->l2_tbl_alloc_va = pg_tbl_va;
842 pt_attrs->l2_tbl_alloc_sz = pt_attrs->l2_size;
843 pt_attrs->l2_base_pa = pg_tbl_pa;
844 pt_attrs->l2_base_va = pg_tbl_va;
845
846 if (pt_attrs->l2_base_va)
847 memset((u8 *) pt_attrs->l2_base_va, 0x00,
848 pt_attrs->l2_size);
849
850 pt_attrs->pg_info = kzalloc(pt_attrs->l2_num_pages *
851 sizeof(struct page_info), GFP_KERNEL);
852 dev_dbg(bridge,
853 "L1 pa %x, va %x, size %x\n L2 pa %x, va "
854 "%x, size %x\n", pt_attrs->l1_base_pa,
855 pt_attrs->l1_base_va, pt_attrs->l1_size,
856 pt_attrs->l2_base_pa, pt_attrs->l2_base_va,
857 pt_attrs->l2_size);
858 dev_dbg(bridge, "pt_attrs %p L2 NumPages %x pg_info %p\n",
859 pt_attrs, pt_attrs->l2_num_pages, pt_attrs->pg_info);
860 }
861 if ((pt_attrs != NULL) && (pt_attrs->l1_base_va != 0) &&
862 (pt_attrs->l2_base_va != 0) && (pt_attrs->pg_info != NULL))
863 dev_context->pt_attrs = pt_attrs;
864 else
865 status = -ENOMEM;
866
714 if (!status) { 867 if (!status) {
868 spin_lock_init(&pt_attrs->pg_lock);
715 dev_context->tc_word_swap_on = drv_datap->tc_wordswapon; 869 dev_context->tc_word_swap_on = drv_datap->tc_wordswapon;
870
871 /* Set the Clock Divisor for the DSP module */
872 udelay(5);
873 /* MMU address is obtained from the host
874 * resources struct */
875 dev_context->dw_dsp_mmu_base = resources->dw_dmmu_base;
876 }
877 if (!status) {
716 dev_context->hdev_obj = hdev_obj; 878 dev_context->hdev_obj = hdev_obj;
717 /* Store current board state. */ 879 /* Store current board state. */
718 dev_context->dw_brd_state = BRD_UNKNOWN; 880 dev_context->dw_brd_state = BRD_UNKNOWN;
@@ -722,6 +884,23 @@ static int bridge_dev_create(struct bridge_dev_context
722 /* Return ptr to our device state to the DSP API for storage */ 884 /* Return ptr to our device state to the DSP API for storage */
723 *dev_cntxt = dev_context; 885 *dev_cntxt = dev_context;
724 } else { 886 } else {
887 if (pt_attrs != NULL) {
888 kfree(pt_attrs->pg_info);
889
890 if (pt_attrs->l2_tbl_alloc_va) {
891 mem_free_phys_mem((void *)
892 pt_attrs->l2_tbl_alloc_va,
893 pt_attrs->l2_tbl_alloc_pa,
894 pt_attrs->l2_tbl_alloc_sz);
895 }
896 if (pt_attrs->l1_tbl_alloc_va) {
897 mem_free_phys_mem((void *)
898 pt_attrs->l1_tbl_alloc_va,
899 pt_attrs->l1_tbl_alloc_pa,
900 pt_attrs->l1_tbl_alloc_sz);
901 }
902 }
903 kfree(pt_attrs);
725 kfree(dev_context); 904 kfree(dev_context);
726 } 905 }
727func_end: 906func_end:
@@ -789,6 +968,7 @@ static int bridge_dev_ctrl(struct bridge_dev_context *dev_context,
789 */ 968 */
790static int bridge_dev_destroy(struct bridge_dev_context *dev_ctxt) 969static int bridge_dev_destroy(struct bridge_dev_context *dev_ctxt)
791{ 970{
971 struct pg_table_attrs *pt_attrs;
792 int status = 0; 972 int status = 0;
793 struct bridge_dev_context *dev_context = (struct bridge_dev_context *) 973 struct bridge_dev_context *dev_context = (struct bridge_dev_context *)
794 dev_ctxt; 974 dev_ctxt;
@@ -802,6 +982,23 @@ static int bridge_dev_destroy(struct bridge_dev_context *dev_ctxt)
802 982
803 /* first put the device to stop state */ 983 /* first put the device to stop state */
804 bridge_brd_stop(dev_context); 984 bridge_brd_stop(dev_context);
985 if (dev_context->pt_attrs) {
986 pt_attrs = dev_context->pt_attrs;
987 kfree(pt_attrs->pg_info);
988
989 if (pt_attrs->l2_tbl_alloc_va) {
990 mem_free_phys_mem((void *)pt_attrs->l2_tbl_alloc_va,
991 pt_attrs->l2_tbl_alloc_pa,
992 pt_attrs->l2_tbl_alloc_sz);
993 }
994 if (pt_attrs->l1_tbl_alloc_va) {
995 mem_free_phys_mem((void *)pt_attrs->l1_tbl_alloc_va,
996 pt_attrs->l1_tbl_alloc_pa,
997 pt_attrs->l1_tbl_alloc_sz);
998 }
999 kfree(pt_attrs);
1000
1001 }
805 1002
806 if (dev_context->resources) { 1003 if (dev_context->resources) {
807 host_res = dev_context->resources; 1004 host_res = dev_context->resources;
@@ -832,6 +1029,8 @@ static int bridge_dev_destroy(struct bridge_dev_context *dev_ctxt)
832 iounmap((void *)host_res->dw_mem_base[3]); 1029 iounmap((void *)host_res->dw_mem_base[3]);
833 if (host_res->dw_mem_base[4]) 1030 if (host_res->dw_mem_base[4])
834 iounmap((void *)host_res->dw_mem_base[4]); 1031 iounmap((void *)host_res->dw_mem_base[4]);
1032 if (host_res->dw_dmmu_base)
1033 iounmap(host_res->dw_dmmu_base);
835 if (host_res->dw_per_base) 1034 if (host_res->dw_per_base)
836 iounmap(host_res->dw_per_base); 1035 iounmap(host_res->dw_per_base);
837 if (host_res->dw_per_pm_base) 1036 if (host_res->dw_per_pm_base)
@@ -845,6 +1044,7 @@ static int bridge_dev_destroy(struct bridge_dev_context *dev_ctxt)
845 host_res->dw_mem_base[2] = (u32) NULL; 1044 host_res->dw_mem_base[2] = (u32) NULL;
846 host_res->dw_mem_base[3] = (u32) NULL; 1045 host_res->dw_mem_base[3] = (u32) NULL;
847 host_res->dw_mem_base[4] = (u32) NULL; 1046 host_res->dw_mem_base[4] = (u32) NULL;
1047 host_res->dw_dmmu_base = NULL;
848 host_res->dw_sys_ctrl_base = NULL; 1048 host_res->dw_sys_ctrl_base = NULL;
849 1049
850 kfree(host_res); 1050 kfree(host_res);
@@ -928,6 +1128,673 @@ static int bridge_brd_mem_write(struct bridge_dev_context *dev_ctxt,
928} 1128}
929 1129
930/* 1130/*
1131 * ======== bridge_brd_mem_map ========
1132 * This function maps MPU buffer to the DSP address space. It performs
1133 * linear to physical address translation if required. It translates each
1134 * page since linear addresses can be physically non-contiguous
1135 * All address & size arguments are assumed to be page aligned (in proc.c)
1136 *
1137 * TODO: Disable MMU while updating the page tables (but that'll stall DSP)
1138 */
1139static int bridge_brd_mem_map(struct bridge_dev_context *dev_ctxt,
1140 u32 ul_mpu_addr, u32 virt_addr,
1141 u32 ul_num_bytes, u32 ul_map_attr,
1142 struct page **mapped_pages)
1143{
1144 u32 attrs;
1145 int status = 0;
1146 struct bridge_dev_context *dev_context = dev_ctxt;
1147 struct hw_mmu_map_attrs_t hw_attrs;
1148 struct vm_area_struct *vma;
1149 struct mm_struct *mm = current->mm;
1150 u32 write = 0;
1151 u32 num_usr_pgs = 0;
1152 struct page *mapped_page, *pg;
1153 s32 pg_num;
1154 u32 va = virt_addr;
1155 struct task_struct *curr_task = current;
1156 u32 pg_i = 0;
1157 u32 mpu_addr, pa;
1158
1159 dev_dbg(bridge,
1160 "%s hDevCtxt %p, pa %x, va %x, size %x, ul_map_attr %x\n",
1161 __func__, dev_ctxt, ul_mpu_addr, virt_addr, ul_num_bytes,
1162 ul_map_attr);
1163 if (ul_num_bytes == 0)
1164 return -EINVAL;
1165
1166 if (ul_map_attr & DSP_MAP_DIR_MASK) {
1167 attrs = ul_map_attr;
1168 } else {
1169 /* Assign default attributes */
1170 attrs = ul_map_attr | (DSP_MAPVIRTUALADDR | DSP_MAPELEMSIZE16);
1171 }
1172 /* Take mapping properties */
1173 if (attrs & DSP_MAPBIGENDIAN)
1174 hw_attrs.endianism = HW_BIG_ENDIAN;
1175 else
1176 hw_attrs.endianism = HW_LITTLE_ENDIAN;
1177
1178 hw_attrs.mixed_size = (enum hw_mmu_mixed_size_t)
1179 ((attrs & DSP_MAPMIXEDELEMSIZE) >> 2);
1180 /* Ignore element_size if mixed_size is enabled */
1181 if (hw_attrs.mixed_size == 0) {
1182 if (attrs & DSP_MAPELEMSIZE8) {
1183 /* Size is 8 bit */
1184 hw_attrs.element_size = HW_ELEM_SIZE8BIT;
1185 } else if (attrs & DSP_MAPELEMSIZE16) {
1186 /* Size is 16 bit */
1187 hw_attrs.element_size = HW_ELEM_SIZE16BIT;
1188 } else if (attrs & DSP_MAPELEMSIZE32) {
1189 /* Size is 32 bit */
1190 hw_attrs.element_size = HW_ELEM_SIZE32BIT;
1191 } else if (attrs & DSP_MAPELEMSIZE64) {
1192 /* Size is 64 bit */
1193 hw_attrs.element_size = HW_ELEM_SIZE64BIT;
1194 } else {
1195 /*
1196 * Mixedsize isn't enabled, so size can't be
1197 * zero here
1198 */
1199 return -EINVAL;
1200 }
1201 }
1202 if (attrs & DSP_MAPDONOTLOCK)
1203 hw_attrs.donotlockmpupage = 1;
1204 else
1205 hw_attrs.donotlockmpupage = 0;
1206
1207 if (attrs & DSP_MAPVMALLOCADDR) {
1208 return mem_map_vmalloc(dev_ctxt, ul_mpu_addr, virt_addr,
1209 ul_num_bytes, &hw_attrs);
1210 }
1211 /*
1212 * Do OS-specific user-va to pa translation.
1213 * Combine physically contiguous regions to reduce TLBs.
1214 * Pass the translated pa to pte_update.
1215 */
1216 if ((attrs & DSP_MAPPHYSICALADDR)) {
1217 status = pte_update(dev_context, ul_mpu_addr, virt_addr,
1218 ul_num_bytes, &hw_attrs);
1219 goto func_cont;
1220 }
1221
1222 /*
1223 * Important Note: ul_mpu_addr is mapped from user application process
1224 * to current process - it must lie completely within the current
1225 * virtual memory address space in order to be of use to us here!
1226 */
1227 down_read(&mm->mmap_sem);
1228 vma = find_vma(mm, ul_mpu_addr);
1229 if (vma)
1230 dev_dbg(bridge,
1231 "VMAfor UserBuf: ul_mpu_addr=%x, ul_num_bytes=%x, "
1232 "vm_start=%lx, vm_end=%lx, vm_flags=%lx\n", ul_mpu_addr,
1233 ul_num_bytes, vma->vm_start, vma->vm_end,
1234 vma->vm_flags);
1235
1236 /*
1237 * It is observed that under some circumstances, the user buffer is
1238 * spread across several VMAs. So loop through and check if the entire
1239 * user buffer is covered
1240 */
1241 while ((vma) && (ul_mpu_addr + ul_num_bytes > vma->vm_end)) {
1242 /* jump to the next VMA region */
1243 vma = find_vma(mm, vma->vm_end + 1);
1244 dev_dbg(bridge,
1245 "VMA for UserBuf ul_mpu_addr=%x ul_num_bytes=%x, "
1246 "vm_start=%lx, vm_end=%lx, vm_flags=%lx\n", ul_mpu_addr,
1247 ul_num_bytes, vma->vm_start, vma->vm_end,
1248 vma->vm_flags);
1249 }
1250 if (!vma) {
1251 pr_err("%s: Failed to get VMA region for 0x%x (%d)\n",
1252 __func__, ul_mpu_addr, ul_num_bytes);
1253 status = -EINVAL;
1254 up_read(&mm->mmap_sem);
1255 goto func_cont;
1256 }
1257
1258 if (vma->vm_flags & VM_IO) {
1259 num_usr_pgs = ul_num_bytes / PG_SIZE4K;
1260 mpu_addr = ul_mpu_addr;
1261
1262 /* Get the physical addresses for user buffer */
1263 for (pg_i = 0; pg_i < num_usr_pgs; pg_i++) {
1264 pa = user_va2_pa(mm, mpu_addr);
1265 if (!pa) {
1266 status = -EPERM;
1267 pr_err("DSPBRIDGE: VM_IO mapping physical"
1268 "address is invalid\n");
1269 break;
1270 }
1271 if (pfn_valid(__phys_to_pfn(pa))) {
1272 pg = PHYS_TO_PAGE(pa);
1273 get_page(pg);
1274 if (page_count(pg) < 1) {
1275 pr_err("Bad page in VM_IO buffer\n");
1276 bad_page_dump(pa, pg);
1277 }
1278 }
1279 status = pte_set(dev_context->pt_attrs, pa,
1280 va, HW_PAGE_SIZE4KB, &hw_attrs);
1281 if (status)
1282 break;
1283
1284 va += HW_PAGE_SIZE4KB;
1285 mpu_addr += HW_PAGE_SIZE4KB;
1286 pa += HW_PAGE_SIZE4KB;
1287 }
1288 } else {
1289 num_usr_pgs = ul_num_bytes / PG_SIZE4K;
1290 if (vma->vm_flags & (VM_WRITE | VM_MAYWRITE))
1291 write = 1;
1292
1293 for (pg_i = 0; pg_i < num_usr_pgs; pg_i++) {
1294 pg_num = get_user_pages(curr_task, mm, ul_mpu_addr, 1,
1295 write, 1, &mapped_page, NULL);
1296 if (pg_num > 0) {
1297 if (page_count(mapped_page) < 1) {
1298 pr_err("Bad page count after doing"
1299 "get_user_pages on"
1300 "user buffer\n");
1301 bad_page_dump(page_to_phys(mapped_page),
1302 mapped_page);
1303 }
1304 status = pte_set(dev_context->pt_attrs,
1305 page_to_phys(mapped_page), va,
1306 HW_PAGE_SIZE4KB, &hw_attrs);
1307 if (status)
1308 break;
1309
1310 if (mapped_pages)
1311 mapped_pages[pg_i] = mapped_page;
1312
1313 va += HW_PAGE_SIZE4KB;
1314 ul_mpu_addr += HW_PAGE_SIZE4KB;
1315 } else {
1316 pr_err("DSPBRIDGE: get_user_pages FAILED,"
1317 "MPU addr = 0x%x,"
1318 "vma->vm_flags = 0x%lx,"
1319 "get_user_pages Err"
1320 "Value = %d, Buffer"
1321 "size=0x%x\n", ul_mpu_addr,
1322 vma->vm_flags, pg_num, ul_num_bytes);
1323 status = -EPERM;
1324 break;
1325 }
1326 }
1327 }
1328 up_read(&mm->mmap_sem);
1329func_cont:
1330 if (status) {
1331 /*
1332 * Roll out the mapped pages incase it failed in middle of
1333 * mapping
1334 */
1335 if (pg_i) {
1336 bridge_brd_mem_un_map(dev_context, virt_addr,
1337 (pg_i * PG_SIZE4K));
1338 }
1339 status = -EPERM;
1340 }
1341 /*
1342 * In any case, flush the TLB
1343 * This is called from here instead from pte_update to avoid unnecessary
1344 * repetition while mapping non-contiguous physical regions of a virtual
1345 * region
1346 */
1347 flush_all(dev_context);
1348 dev_dbg(bridge, "%s status %x\n", __func__, status);
1349 return status;
1350}
1351
1352/*
1353 * ======== bridge_brd_mem_un_map ========
1354 * Invalidate the PTEs for the DSP VA block to be unmapped.
1355 *
1356 * PTEs of a mapped memory block are contiguous in any page table
1357 * So, instead of looking up the PTE address for every 4K block,
1358 * we clear consecutive PTEs until we unmap all the bytes
1359 */
1360static int bridge_brd_mem_un_map(struct bridge_dev_context *dev_ctxt,
1361 u32 virt_addr, u32 ul_num_bytes)
1362{
1363 u32 l1_base_va;
1364 u32 l2_base_va;
1365 u32 l2_base_pa;
1366 u32 l2_page_num;
1367 u32 pte_val;
1368 u32 pte_size;
1369 u32 pte_count;
1370 u32 pte_addr_l1;
1371 u32 pte_addr_l2 = 0;
1372 u32 rem_bytes;
1373 u32 rem_bytes_l2;
1374 u32 va_curr;
1375 struct page *pg = NULL;
1376 int status = 0;
1377 struct bridge_dev_context *dev_context = dev_ctxt;
1378 struct pg_table_attrs *pt = dev_context->pt_attrs;
1379 u32 temp;
1380 u32 paddr;
1381 u32 numof4k_pages = 0;
1382
1383 va_curr = virt_addr;
1384 rem_bytes = ul_num_bytes;
1385 rem_bytes_l2 = 0;
1386 l1_base_va = pt->l1_base_va;
1387 pte_addr_l1 = hw_mmu_pte_addr_l1(l1_base_va, va_curr);
1388 dev_dbg(bridge, "%s dev_ctxt %p, va %x, NumBytes %x l1_base_va %x, "
1389 "pte_addr_l1 %x\n", __func__, dev_ctxt, virt_addr,
1390 ul_num_bytes, l1_base_va, pte_addr_l1);
1391
1392 while (rem_bytes && !status) {
1393 u32 va_curr_orig = va_curr;
1394 /* Find whether the L1 PTE points to a valid L2 PT */
1395 pte_addr_l1 = hw_mmu_pte_addr_l1(l1_base_va, va_curr);
1396 pte_val = *(u32 *) pte_addr_l1;
1397 pte_size = hw_mmu_pte_size_l1(pte_val);
1398
1399 if (pte_size != HW_MMU_COARSE_PAGE_SIZE)
1400 goto skip_coarse_page;
1401
1402 /*
1403 * Get the L2 PA from the L1 PTE, and find
1404 * corresponding L2 VA
1405 */
1406 l2_base_pa = hw_mmu_pte_coarse_l1(pte_val);
1407 l2_base_va = l2_base_pa - pt->l2_base_pa + pt->l2_base_va;
1408 l2_page_num =
1409 (l2_base_pa - pt->l2_base_pa) / HW_MMU_COARSE_PAGE_SIZE;
1410 /*
1411 * Find the L2 PTE address from which we will start
1412 * clearing, the number of PTEs to be cleared on this
1413 * page, and the size of VA space that needs to be
1414 * cleared on this L2 page
1415 */
1416 pte_addr_l2 = hw_mmu_pte_addr_l2(l2_base_va, va_curr);
1417 pte_count = pte_addr_l2 & (HW_MMU_COARSE_PAGE_SIZE - 1);
1418 pte_count = (HW_MMU_COARSE_PAGE_SIZE - pte_count) / sizeof(u32);
1419 if (rem_bytes < (pte_count * PG_SIZE4K))
1420 pte_count = rem_bytes / PG_SIZE4K;
1421 rem_bytes_l2 = pte_count * PG_SIZE4K;
1422
1423 /*
1424 * Unmap the VA space on this L2 PT. A quicker way
1425 * would be to clear pte_count entries starting from
1426 * pte_addr_l2. However, below code checks that we don't
1427 * clear invalid entries or less than 64KB for a 64KB
1428 * entry. Similar checking is done for L1 PTEs too
1429 * below
1430 */
1431 while (rem_bytes_l2 && !status) {
1432 pte_val = *(u32 *) pte_addr_l2;
1433 pte_size = hw_mmu_pte_size_l2(pte_val);
1434 /* va_curr aligned to pte_size? */
1435 if (pte_size == 0 || rem_bytes_l2 < pte_size ||
1436 va_curr & (pte_size - 1)) {
1437 status = -EPERM;
1438 break;
1439 }
1440
1441 /* Collect Physical addresses from VA */
1442 paddr = (pte_val & ~(pte_size - 1));
1443 if (pte_size == HW_PAGE_SIZE64KB)
1444 numof4k_pages = 16;
1445 else
1446 numof4k_pages = 1;
1447 temp = 0;
1448 while (temp++ < numof4k_pages) {
1449 if (!pfn_valid(__phys_to_pfn(paddr))) {
1450 paddr += HW_PAGE_SIZE4KB;
1451 continue;
1452 }
1453 pg = PHYS_TO_PAGE(paddr);
1454 if (page_count(pg) < 1) {
1455 pr_info("DSPBRIDGE: UNMAP function: "
1456 "COUNT 0 FOR PA 0x%x, size = "
1457 "0x%x\n", paddr, ul_num_bytes);
1458 bad_page_dump(paddr, pg);
1459 } else {
1460 set_page_dirty(pg);
1461 page_cache_release(pg);
1462 }
1463 paddr += HW_PAGE_SIZE4KB;
1464 }
1465 if (hw_mmu_pte_clear(pte_addr_l2, va_curr, pte_size)) {
1466 status = -EPERM;
1467 goto EXIT_LOOP;
1468 }
1469
1470 status = 0;
1471 rem_bytes_l2 -= pte_size;
1472 va_curr += pte_size;
1473 pte_addr_l2 += (pte_size >> 12) * sizeof(u32);
1474 }
1475 spin_lock(&pt->pg_lock);
1476 if (rem_bytes_l2 == 0) {
1477 pt->pg_info[l2_page_num].num_entries -= pte_count;
1478 if (pt->pg_info[l2_page_num].num_entries == 0) {
1479 /*
1480 * Clear the L1 PTE pointing to the L2 PT
1481 */
1482 if (!hw_mmu_pte_clear(l1_base_va, va_curr_orig,
1483 HW_MMU_COARSE_PAGE_SIZE))
1484 status = 0;
1485 else {
1486 status = -EPERM;
1487 spin_unlock(&pt->pg_lock);
1488 goto EXIT_LOOP;
1489 }
1490 }
1491 rem_bytes -= pte_count * PG_SIZE4K;
1492 } else
1493 status = -EPERM;
1494
1495 spin_unlock(&pt->pg_lock);
1496 continue;
1497skip_coarse_page:
1498 /* va_curr aligned to pte_size? */
1499 /* pte_size = 1 MB or 16 MB */
1500 if (pte_size == 0 || rem_bytes < pte_size ||
1501 va_curr & (pte_size - 1)) {
1502 status = -EPERM;
1503 break;
1504 }
1505
1506 if (pte_size == HW_PAGE_SIZE1MB)
1507 numof4k_pages = 256;
1508 else
1509 numof4k_pages = 4096;
1510 temp = 0;
1511 /* Collect Physical addresses from VA */
1512 paddr = (pte_val & ~(pte_size - 1));
1513 while (temp++ < numof4k_pages) {
1514 if (pfn_valid(__phys_to_pfn(paddr))) {
1515 pg = PHYS_TO_PAGE(paddr);
1516 if (page_count(pg) < 1) {
1517 pr_info("DSPBRIDGE: UNMAP function: "
1518 "COUNT 0 FOR PA 0x%x, size = "
1519 "0x%x\n", paddr, ul_num_bytes);
1520 bad_page_dump(paddr, pg);
1521 } else {
1522 set_page_dirty(pg);
1523 page_cache_release(pg);
1524 }
1525 }
1526 paddr += HW_PAGE_SIZE4KB;
1527 }
1528 if (!hw_mmu_pte_clear(l1_base_va, va_curr, pte_size)) {
1529 status = 0;
1530 rem_bytes -= pte_size;
1531 va_curr += pte_size;
1532 } else {
1533 status = -EPERM;
1534 goto EXIT_LOOP;
1535 }
1536 }
1537 /*
1538 * It is better to flush the TLB here, so that any stale old entries
1539 * get flushed
1540 */
1541EXIT_LOOP:
1542 flush_all(dev_context);
1543 dev_dbg(bridge,
1544 "%s: va_curr %x, pte_addr_l1 %x pte_addr_l2 %x rem_bytes %x,"
1545 " rem_bytes_l2 %x status %x\n", __func__, va_curr, pte_addr_l1,
1546 pte_addr_l2, rem_bytes, rem_bytes_l2, status);
1547 return status;
1548}
1549
1550/*
1551 * ======== user_va2_pa ========
1552 * Purpose:
1553 * This function walks through the page tables to convert a userland
1554 * virtual address to physical address
1555 */
1556static u32 user_va2_pa(struct mm_struct *mm, u32 address)
1557{
1558 pgd_t *pgd;
1559 pmd_t *pmd;
1560 pte_t *ptep, pte;
1561
1562 pgd = pgd_offset(mm, address);
1563 if (!(pgd_none(*pgd) || pgd_bad(*pgd))) {
1564 pmd = pmd_offset(pgd, address);
1565 if (!(pmd_none(*pmd) || pmd_bad(*pmd))) {
1566 ptep = pte_offset_map(pmd, address);
1567 if (ptep) {
1568 pte = *ptep;
1569 if (pte_present(pte))
1570 return pte & PAGE_MASK;
1571 }
1572 }
1573 }
1574
1575 return 0;
1576}
1577
1578/*
1579 * ======== pte_update ========
1580 * This function calculates the optimum page-aligned addresses and sizes
1581 * Caller must pass page-aligned values
1582 */
1583static int pte_update(struct bridge_dev_context *dev_ctxt, u32 pa,
1584 u32 va, u32 size,
1585 struct hw_mmu_map_attrs_t *map_attrs)
1586{
1587 u32 i;
1588 u32 all_bits;
1589 u32 pa_curr = pa;
1590 u32 va_curr = va;
1591 u32 num_bytes = size;
1592 struct bridge_dev_context *dev_context = dev_ctxt;
1593 int status = 0;
1594 u32 page_size[] = { HW_PAGE_SIZE16MB, HW_PAGE_SIZE1MB,
1595 HW_PAGE_SIZE64KB, HW_PAGE_SIZE4KB
1596 };
1597
1598 while (num_bytes && !status) {
1599 /* To find the max. page size with which both PA & VA are
1600 * aligned */
1601 all_bits = pa_curr | va_curr;
1602
1603 for (i = 0; i < 4; i++) {
1604 if ((num_bytes >= page_size[i]) && ((all_bits &
1605 (page_size[i] -
1606 1)) == 0)) {
1607 status =
1608 pte_set(dev_context->pt_attrs, pa_curr,
1609 va_curr, page_size[i], map_attrs);
1610 pa_curr += page_size[i];
1611 va_curr += page_size[i];
1612 num_bytes -= page_size[i];
1613 /* Don't try smaller sizes. Hopefully we have
1614 * reached an address aligned to a bigger page
1615 * size */
1616 break;
1617 }
1618 }
1619 }
1620
1621 return status;
1622}
1623
1624/*
1625 * ======== pte_set ========
1626 * This function calculates PTE address (MPU virtual) to be updated
1627 * It also manages the L2 page tables
1628 */
1629static int pte_set(struct pg_table_attrs *pt, u32 pa, u32 va,
1630 u32 size, struct hw_mmu_map_attrs_t *attrs)
1631{
1632 u32 i;
1633 u32 pte_val;
1634 u32 pte_addr_l1;
1635 u32 pte_size;
1636 /* Base address of the PT that will be updated */
1637 u32 pg_tbl_va;
1638 u32 l1_base_va;
1639 /* Compiler warns that the next three variables might be used
1640 * uninitialized in this function. Doesn't seem so. Working around,
1641 * anyways. */
1642 u32 l2_base_va = 0;
1643 u32 l2_base_pa = 0;
1644 u32 l2_page_num = 0;
1645 int status = 0;
1646
1647 l1_base_va = pt->l1_base_va;
1648 pg_tbl_va = l1_base_va;
1649 if ((size == HW_PAGE_SIZE64KB) || (size == HW_PAGE_SIZE4KB)) {
1650 /* Find whether the L1 PTE points to a valid L2 PT */
1651 pte_addr_l1 = hw_mmu_pte_addr_l1(l1_base_va, va);
1652 if (pte_addr_l1 <= (pt->l1_base_va + pt->l1_size)) {
1653 pte_val = *(u32 *) pte_addr_l1;
1654 pte_size = hw_mmu_pte_size_l1(pte_val);
1655 } else {
1656 return -EPERM;
1657 }
1658 spin_lock(&pt->pg_lock);
1659 if (pte_size == HW_MMU_COARSE_PAGE_SIZE) {
1660 /* Get the L2 PA from the L1 PTE, and find
1661 * corresponding L2 VA */
1662 l2_base_pa = hw_mmu_pte_coarse_l1(pte_val);
1663 l2_base_va =
1664 l2_base_pa - pt->l2_base_pa + pt->l2_base_va;
1665 l2_page_num =
1666 (l2_base_pa -
1667 pt->l2_base_pa) / HW_MMU_COARSE_PAGE_SIZE;
1668 } else if (pte_size == 0) {
1669 /* L1 PTE is invalid. Allocate a L2 PT and
1670 * point the L1 PTE to it */
1671 /* Find a free L2 PT. */
1672 for (i = 0; (i < pt->l2_num_pages) &&
1673 (pt->pg_info[i].num_entries != 0); i++)
1674 ;;
1675 if (i < pt->l2_num_pages) {
1676 l2_page_num = i;
1677 l2_base_pa = pt->l2_base_pa + (l2_page_num *
1678 HW_MMU_COARSE_PAGE_SIZE);
1679 l2_base_va = pt->l2_base_va + (l2_page_num *
1680 HW_MMU_COARSE_PAGE_SIZE);
1681 /* Endianness attributes are ignored for
1682 * HW_MMU_COARSE_PAGE_SIZE */
1683 status =
1684 hw_mmu_pte_set(l1_base_va, l2_base_pa, va,
1685 HW_MMU_COARSE_PAGE_SIZE,
1686 attrs);
1687 } else {
1688 status = -ENOMEM;
1689 }
1690 } else {
1691 /* Found valid L1 PTE of another size.
1692 * Should not overwrite it. */
1693 status = -EPERM;
1694 }
1695 if (!status) {
1696 pg_tbl_va = l2_base_va;
1697 if (size == HW_PAGE_SIZE64KB)
1698 pt->pg_info[l2_page_num].num_entries += 16;
1699 else
1700 pt->pg_info[l2_page_num].num_entries++;
1701 dev_dbg(bridge, "PTE: L2 BaseVa %x, BasePa %x, PageNum "
1702 "%x, num_entries %x\n", l2_base_va,
1703 l2_base_pa, l2_page_num,
1704 pt->pg_info[l2_page_num].num_entries);
1705 }
1706 spin_unlock(&pt->pg_lock);
1707 }
1708 if (!status) {
1709 dev_dbg(bridge, "PTE: pg_tbl_va %x, pa %x, va %x, size %x\n",
1710 pg_tbl_va, pa, va, size);
1711 dev_dbg(bridge, "PTE: endianism %x, element_size %x, "
1712 "mixed_size %x\n", attrs->endianism,
1713 attrs->element_size, attrs->mixed_size);
1714 status = hw_mmu_pte_set(pg_tbl_va, pa, va, size, attrs);
1715 }
1716
1717 return status;
1718}
1719
1720/* Memory map kernel VA -- memory allocated with vmalloc */
1721static int mem_map_vmalloc(struct bridge_dev_context *dev_context,
1722 u32 ul_mpu_addr, u32 virt_addr,
1723 u32 ul_num_bytes,
1724 struct hw_mmu_map_attrs_t *hw_attrs)
1725{
1726 int status = 0;
1727 struct page *page[1];
1728 u32 i;
1729 u32 pa_curr;
1730 u32 pa_next;
1731 u32 va_curr;
1732 u32 size_curr;
1733 u32 num_pages;
1734 u32 pa;
1735 u32 num_of4k_pages;
1736 u32 temp = 0;
1737
1738 /*
1739 * Do Kernel va to pa translation.
1740 * Combine physically contiguous regions to reduce TLBs.
1741 * Pass the translated pa to pte_update.
1742 */
1743 num_pages = ul_num_bytes / PAGE_SIZE; /* PAGE_SIZE = OS page size */
1744 i = 0;
1745 va_curr = ul_mpu_addr;
1746 page[0] = vmalloc_to_page((void *)va_curr);
1747 pa_next = page_to_phys(page[0]);
1748 while (!status && (i < num_pages)) {
1749 /*
1750 * Reuse pa_next from the previous iteraion to avoid
1751 * an extra va2pa call
1752 */
1753 pa_curr = pa_next;
1754 size_curr = PAGE_SIZE;
1755 /*
1756 * If the next page is physically contiguous,
1757 * map it with the current one by increasing
1758 * the size of the region to be mapped
1759 */
1760 while (++i < num_pages) {
1761 page[0] =
1762 vmalloc_to_page((void *)(va_curr + size_curr));
1763 pa_next = page_to_phys(page[0]);
1764
1765 if (pa_next == (pa_curr + size_curr))
1766 size_curr += PAGE_SIZE;
1767 else
1768 break;
1769
1770 }
1771 if (pa_next == 0) {
1772 status = -ENOMEM;
1773 break;
1774 }
1775 pa = pa_curr;
1776 num_of4k_pages = size_curr / HW_PAGE_SIZE4KB;
1777 while (temp++ < num_of4k_pages) {
1778 get_page(PHYS_TO_PAGE(pa));
1779 pa += HW_PAGE_SIZE4KB;
1780 }
1781 status = pte_update(dev_context, pa_curr, virt_addr +
1782 (va_curr - ul_mpu_addr), size_curr,
1783 hw_attrs);
1784 va_curr += size_curr;
1785 }
1786 /*
1787 * In any case, flush the TLB
1788 * This is called from here instead from pte_update to avoid unnecessary
1789 * repetition while mapping non-contiguous physical regions of a virtual
1790 * region
1791 */
1792 flush_all(dev_context);
1793 dev_dbg(bridge, "%s status %x\n", __func__, status);
1794 return status;
1795}
1796
1797/*
931 * ======== wait_for_start ======== 1798 * ======== wait_for_start ========
932 * Wait for the singal from DSP that it has started, or time out. 1799 * Wait for the singal from DSP that it has started, or time out.
933 */ 1800 */
diff --git a/drivers/staging/tidspbridge/core/tiomap3430_pwr.c b/drivers/staging/tidspbridge/core/tiomap3430_pwr.c
index b57a9fd5e757..fb9026e1403c 100644
--- a/drivers/staging/tidspbridge/core/tiomap3430_pwr.c
+++ b/drivers/staging/tidspbridge/core/tiomap3430_pwr.c
@@ -31,6 +31,10 @@
31#include <dspbridge/dev.h> 31#include <dspbridge/dev.h>
32#include <dspbridge/iodefs.h> 32#include <dspbridge/iodefs.h>
33 33
34/* ------------------------------------ Hardware Abstraction Layer */
35#include <hw_defs.h>
36#include <hw_mmu.h>
37
34#include <dspbridge/pwr_sh.h> 38#include <dspbridge/pwr_sh.h>
35 39
36/* ----------------------------------- Bridge Driver */ 40/* ----------------------------------- Bridge Driver */
diff --git a/drivers/staging/tidspbridge/core/tiomap_io.c b/drivers/staging/tidspbridge/core/tiomap_io.c
index 66dbf02549e4..ba2961049dad 100644
--- a/drivers/staging/tidspbridge/core/tiomap_io.c
+++ b/drivers/staging/tidspbridge/core/tiomap_io.c
@@ -134,16 +134,17 @@ int read_ext_dsp_data(struct bridge_dev_context *dev_ctxt,
134 134
135 if (!status) { 135 if (!status) {
136 ul_tlb_base_virt = 136 ul_tlb_base_virt =
137 dev_context->sh_s.seg0_da * DSPWORDSIZE; 137 dev_context->atlb_entry[0].ul_dsp_va * DSPWORDSIZE;
138 DBC_ASSERT(ul_tlb_base_virt <= ul_shm_base_virt); 138 DBC_ASSERT(ul_tlb_base_virt <= ul_shm_base_virt);
139 dw_ext_prog_virt_mem = dev_context->sh_s.seg0_va; 139 dw_ext_prog_virt_mem =
140 dev_context->atlb_entry[0].ul_gpp_va;
140 141
141 if (!trace_read) { 142 if (!trace_read) {
142 ul_shm_offset_virt = 143 ul_shm_offset_virt =
143 ul_shm_base_virt - ul_tlb_base_virt; 144 ul_shm_base_virt - ul_tlb_base_virt;
144 ul_shm_offset_virt += 145 ul_shm_offset_virt +=
145 PG_ALIGN_HIGH(ul_ext_end - ul_dyn_ext_base + 146 PG_ALIGN_HIGH(ul_ext_end - ul_dyn_ext_base +
146 1, PAGE_SIZE * 16); 147 1, HW_PAGE_SIZE64KB);
147 dw_ext_prog_virt_mem -= ul_shm_offset_virt; 148 dw_ext_prog_virt_mem -= ul_shm_offset_virt;
148 dw_ext_prog_virt_mem += 149 dw_ext_prog_virt_mem +=
149 (ul_ext_base - ul_dyn_ext_base); 150 (ul_ext_base - ul_dyn_ext_base);
@@ -317,9 +318,8 @@ int write_ext_dsp_data(struct bridge_dev_context *dev_context,
317 ret = -EPERM; 318 ret = -EPERM;
318 319
319 if (!ret) { 320 if (!ret) {
320 ul_tlb_base_virt = dev_context->sh_s.seg0_da * 321 ul_tlb_base_virt =
321 DSPWORDSIZE; 322 dev_context->atlb_entry[0].ul_dsp_va * DSPWORDSIZE;
322
323 DBC_ASSERT(ul_tlb_base_virt <= ul_shm_base_virt); 323 DBC_ASSERT(ul_tlb_base_virt <= ul_shm_base_virt);
324 324
325 if (symbols_reloaded) { 325 if (symbols_reloaded) {
@@ -337,7 +337,7 @@ int write_ext_dsp_data(struct bridge_dev_context *dev_context,
337 ul_shm_base_virt - ul_tlb_base_virt; 337 ul_shm_base_virt - ul_tlb_base_virt;
338 if (trace_load) { 338 if (trace_load) {
339 dw_ext_prog_virt_mem = 339 dw_ext_prog_virt_mem =
340 dev_context->sh_s.seg0_va; 340 dev_context->atlb_entry[0].ul_gpp_va;
341 } else { 341 } else {
342 dw_ext_prog_virt_mem = host_res->dw_mem_base[1]; 342 dw_ext_prog_virt_mem = host_res->dw_mem_base[1];
343 dw_ext_prog_virt_mem += 343 dw_ext_prog_virt_mem +=
@@ -393,6 +393,7 @@ int sm_interrupt_dsp(struct bridge_dev_context *dev_context, u16 mb_val)
393 omap_dspbridge_dev->dev.platform_data; 393 omap_dspbridge_dev->dev.platform_data;
394 struct cfg_hostres *resources = dev_context->resources; 394 struct cfg_hostres *resources = dev_context->resources;
395 int status = 0; 395 int status = 0;
396 u32 temp;
396 397
397 if (!dev_context->mbox) 398 if (!dev_context->mbox)
398 return 0; 399 return 0;
@@ -436,7 +437,7 @@ int sm_interrupt_dsp(struct bridge_dev_context *dev_context, u16 mb_val)
436 omap_mbox_restore_ctx(dev_context->mbox); 437 omap_mbox_restore_ctx(dev_context->mbox);
437 438
438 /* Access MMU SYS CONFIG register to generate a short wakeup */ 439 /* Access MMU SYS CONFIG register to generate a short wakeup */
439 iommu_read_reg(dev_context->dsp_mmu, MMU_SYSCONFIG); 440 temp = readl(resources->dw_dmmu_base + 0x10);
440 441
441 dev_context->dw_brd_state = BRD_RUNNING; 442 dev_context->dw_brd_state = BRD_RUNNING;
442 } else if (dev_context->dw_brd_state == BRD_RETENTION) { 443 } else if (dev_context->dw_brd_state == BRD_RETENTION) {
diff --git a/drivers/staging/tidspbridge/core/ue_deh.c b/drivers/staging/tidspbridge/core/ue_deh.c
index e24ea0c73914..3430418190da 100644
--- a/drivers/staging/tidspbridge/core/ue_deh.c
+++ b/drivers/staging/tidspbridge/core/ue_deh.c
@@ -31,6 +31,57 @@
31#include <dspbridge/drv.h> 31#include <dspbridge/drv.h>
32#include <dspbridge/wdt.h> 32#include <dspbridge/wdt.h>
33 33
34static u32 fault_addr;
35
36static void mmu_fault_dpc(unsigned long data)
37{
38 struct deh_mgr *deh = (void *)data;
39
40 if (!deh)
41 return;
42
43 bridge_deh_notify(deh, DSP_MMUFAULT, 0);
44}
45
46static irqreturn_t mmu_fault_isr(int irq, void *data)
47{
48 struct deh_mgr *deh = data;
49 struct cfg_hostres *resources;
50 u32 event;
51
52 if (!deh)
53 return IRQ_HANDLED;
54
55 resources = deh->hbridge_context->resources;
56 if (!resources) {
57 dev_dbg(bridge, "%s: Failed to get Host Resources\n",
58 __func__);
59 return IRQ_HANDLED;
60 }
61
62 hw_mmu_event_status(resources->dw_dmmu_base, &event);
63 if (event == HW_MMU_TRANSLATION_FAULT) {
64 hw_mmu_fault_addr_read(resources->dw_dmmu_base, &fault_addr);
65 dev_dbg(bridge, "%s: event=0x%x, fault_addr=0x%x\n", __func__,
66 event, fault_addr);
67 /*
68 * Schedule a DPC directly. In the future, it may be
69 * necessary to check if DSP MMU fault is intended for
70 * Bridge.
71 */
72 tasklet_schedule(&deh->dpc_tasklet);
73
74 /* Disable the MMU events, else once we clear it will
75 * start to raise INTs again */
76 hw_mmu_event_disable(resources->dw_dmmu_base,
77 HW_MMU_TRANSLATION_FAULT);
78 } else {
79 hw_mmu_event_disable(resources->dw_dmmu_base,
80 HW_MMU_ALL_INTERRUPTS);
81 }
82 return IRQ_HANDLED;
83}
84
34int bridge_deh_create(struct deh_mgr **ret_deh, 85int bridge_deh_create(struct deh_mgr **ret_deh,
35 struct dev_object *hdev_obj) 86 struct dev_object *hdev_obj)
36{ 87{
@@ -58,9 +109,18 @@ int bridge_deh_create(struct deh_mgr **ret_deh,
58 } 109 }
59 ntfy_init(deh->ntfy_obj); 110 ntfy_init(deh->ntfy_obj);
60 111
112 /* Create a MMUfault DPC */
113 tasklet_init(&deh->dpc_tasklet, mmu_fault_dpc, (u32) deh);
114
61 /* Fill in context structure */ 115 /* Fill in context structure */
62 deh->hbridge_context = hbridge_context; 116 deh->hbridge_context = hbridge_context;
63 117
118 /* Install ISR function for DSP MMU fault */
119 status = request_irq(INT_DSP_MMU_IRQ, mmu_fault_isr, 0,
120 "DspBridge\tiommu fault", deh);
121 if (status < 0)
122 goto err;
123
64 *ret_deh = deh; 124 *ret_deh = deh;
65 return 0; 125 return 0;
66 126
@@ -80,6 +140,11 @@ int bridge_deh_destroy(struct deh_mgr *deh)
80 ntfy_delete(deh->ntfy_obj); 140 ntfy_delete(deh->ntfy_obj);
81 kfree(deh->ntfy_obj); 141 kfree(deh->ntfy_obj);
82 } 142 }
143 /* Disable DSP MMU fault */
144 free_irq(INT_DSP_MMU_IRQ, deh);
145
146 /* Free DPC object */
147 tasklet_kill(&deh->dpc_tasklet);
83 148
84 /* Deallocate the DEH manager object */ 149 /* Deallocate the DEH manager object */
85 kfree(deh); 150 kfree(deh);
@@ -101,6 +166,48 @@ int bridge_deh_register_notify(struct deh_mgr *deh, u32 event_mask,
101 return ntfy_unregister(deh->ntfy_obj, hnotification); 166 return ntfy_unregister(deh->ntfy_obj, hnotification);
102} 167}
103 168
169#ifdef CONFIG_TIDSPBRIDGE_BACKTRACE
170static void mmu_fault_print_stack(struct bridge_dev_context *dev_context)
171{
172 struct cfg_hostres *resources;
173 struct hw_mmu_map_attrs_t map_attrs = {
174 .endianism = HW_LITTLE_ENDIAN,
175 .element_size = HW_ELEM_SIZE16BIT,
176 .mixed_size = HW_MMU_CPUES,
177 };
178 void *dummy_va_addr;
179
180 resources = dev_context->resources;
181 dummy_va_addr = (void*)__get_free_page(GFP_ATOMIC);
182
183 /*
184 * Before acking the MMU fault, let's make sure MMU can only
185 * access entry #0. Then add a new entry so that the DSP OS
186 * can continue in order to dump the stack.
187 */
188 hw_mmu_twl_disable(resources->dw_dmmu_base);
189 hw_mmu_tlb_flush_all(resources->dw_dmmu_base);
190
191 hw_mmu_tlb_add(resources->dw_dmmu_base,
192 virt_to_phys(dummy_va_addr), fault_addr,
193 HW_PAGE_SIZE4KB, 1,
194 &map_attrs, HW_SET, HW_SET);
195
196 dsp_clk_enable(DSP_CLK_GPT8);
197
198 dsp_gpt_wait_overflow(DSP_CLK_GPT8, 0xfffffffe);
199
200 /* Clear MMU interrupt */
201 hw_mmu_event_ack(resources->dw_dmmu_base,
202 HW_MMU_TRANSLATION_FAULT);
203 dump_dsp_stack(dev_context);
204 dsp_clk_disable(DSP_CLK_GPT8);
205
206 hw_mmu_disable(resources->dw_dmmu_base);
207 free_page((unsigned long)dummy_va_addr);
208}
209#endif
210
104static inline const char *event_to_string(int event) 211static inline const char *event_to_string(int event)
105{ 212{
106 switch (event) { 213 switch (event) {
@@ -133,7 +240,13 @@ void bridge_deh_notify(struct deh_mgr *deh, int event, int info)
133#endif 240#endif
134 break; 241 break;
135 case DSP_MMUFAULT: 242 case DSP_MMUFAULT:
136 dev_err(bridge, "%s: %s, addr=0x%x", __func__, str, info); 243 dev_err(bridge, "%s: %s, addr=0x%x", __func__,
244 str, fault_addr);
245#ifdef CONFIG_TIDSPBRIDGE_BACKTRACE
246 print_dsp_trace_buffer(dev_context);
247 dump_dl_modules(dev_context);
248 mmu_fault_print_stack(dev_context);
249#endif
137 break; 250 break;
138 default: 251 default:
139 dev_err(bridge, "%s: %s", __func__, str); 252 dev_err(bridge, "%s: %s", __func__, str);
diff --git a/drivers/staging/tidspbridge/hw/EasiGlobal.h b/drivers/staging/tidspbridge/hw/EasiGlobal.h
new file mode 100644
index 000000000000..e48d7f67c60a
--- /dev/null
+++ b/drivers/staging/tidspbridge/hw/EasiGlobal.h
@@ -0,0 +1,41 @@
1/*
2 * EasiGlobal.h
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2007 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#ifndef _EASIGLOBAL_H
18#define _EASIGLOBAL_H
19#include <linux/types.h>
20
21/*
22 * DEFINE: READ_ONLY, WRITE_ONLY & READ_WRITE
23 *
24 * DESCRIPTION: Defines used to describe register types for EASI-checker tests.
25 */
26
27#define READ_ONLY 1
28#define WRITE_ONLY 2
29#define READ_WRITE 3
30
31/*
32 * MACRO: _DEBUG_LEVEL1_EASI
33 *
34 * DESCRIPTION: A MACRO which can be used to indicate that a particular beach
35 * register access function was called.
36 *
37 * NOTE: We currently dont use this functionality.
38 */
39#define _DEBUG_LEVEL1_EASI(easi_num) ((void)0)
40
41#endif /* _EASIGLOBAL_H */
diff --git a/drivers/staging/tidspbridge/hw/MMUAccInt.h b/drivers/staging/tidspbridge/hw/MMUAccInt.h
new file mode 100644
index 000000000000..1cefca321d71
--- /dev/null
+++ b/drivers/staging/tidspbridge/hw/MMUAccInt.h
@@ -0,0 +1,76 @@
1/*
2 * MMUAccInt.h
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2007 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#ifndef _MMU_ACC_INT_H
18#define _MMU_ACC_INT_H
19
20/* Mappings of level 1 EASI function numbers to function names */
21
22#define EASIL1_MMUMMU_SYSCONFIG_READ_REGISTER32 (MMU_BASE_EASIL1 + 3)
23#define EASIL1_MMUMMU_SYSCONFIG_IDLE_MODE_WRITE32 (MMU_BASE_EASIL1 + 17)
24#define EASIL1_MMUMMU_SYSCONFIG_AUTO_IDLE_WRITE32 (MMU_BASE_EASIL1 + 39)
25#define EASIL1_MMUMMU_IRQSTATUS_WRITE_REGISTER32 (MMU_BASE_EASIL1 + 51)
26#define EASIL1_MMUMMU_IRQENABLE_READ_REGISTER32 (MMU_BASE_EASIL1 + 102)
27#define EASIL1_MMUMMU_IRQENABLE_WRITE_REGISTER32 (MMU_BASE_EASIL1 + 103)
28#define EASIL1_MMUMMU_WALKING_STTWL_RUNNING_READ32 (MMU_BASE_EASIL1 + 156)
29#define EASIL1_MMUMMU_CNTLTWL_ENABLE_READ32 (MMU_BASE_EASIL1 + 174)
30#define EASIL1_MMUMMU_CNTLTWL_ENABLE_WRITE32 (MMU_BASE_EASIL1 + 180)
31#define EASIL1_MMUMMU_CNTLMMU_ENABLE_WRITE32 (MMU_BASE_EASIL1 + 190)
32#define EASIL1_MMUMMU_FAULT_AD_READ_REGISTER32 (MMU_BASE_EASIL1 + 194)
33#define EASIL1_MMUMMU_TTB_WRITE_REGISTER32 (MMU_BASE_EASIL1 + 198)
34#define EASIL1_MMUMMU_LOCK_READ_REGISTER32 (MMU_BASE_EASIL1 + 203)
35#define EASIL1_MMUMMU_LOCK_WRITE_REGISTER32 (MMU_BASE_EASIL1 + 204)
36#define EASIL1_MMUMMU_LOCK_BASE_VALUE_READ32 (MMU_BASE_EASIL1 + 205)
37#define EASIL1_MMUMMU_LOCK_CURRENT_VICTIM_READ32 (MMU_BASE_EASIL1 + 209)
38#define EASIL1_MMUMMU_LOCK_CURRENT_VICTIM_WRITE32 (MMU_BASE_EASIL1 + 211)
39#define EASIL1_MMUMMU_LOCK_CURRENT_VICTIM_SET32 (MMU_BASE_EASIL1 + 212)
40#define EASIL1_MMUMMU_LD_TLB_READ_REGISTER32 (MMU_BASE_EASIL1 + 213)
41#define EASIL1_MMUMMU_LD_TLB_WRITE_REGISTER32 (MMU_BASE_EASIL1 + 214)
42#define EASIL1_MMUMMU_CAM_WRITE_REGISTER32 (MMU_BASE_EASIL1 + 226)
43#define EASIL1_MMUMMU_RAM_WRITE_REGISTER32 (MMU_BASE_EASIL1 + 268)
44#define EASIL1_MMUMMU_FLUSH_ENTRY_WRITE_REGISTER32 (MMU_BASE_EASIL1 + 322)
45
46/* Register offset address definitions */
47#define MMU_MMU_SYSCONFIG_OFFSET 0x10
48#define MMU_MMU_IRQSTATUS_OFFSET 0x18
49#define MMU_MMU_IRQENABLE_OFFSET 0x1c
50#define MMU_MMU_WALKING_ST_OFFSET 0x40
51#define MMU_MMU_CNTL_OFFSET 0x44
52#define MMU_MMU_FAULT_AD_OFFSET 0x48
53#define MMU_MMU_TTB_OFFSET 0x4c
54#define MMU_MMU_LOCK_OFFSET 0x50
55#define MMU_MMU_LD_TLB_OFFSET 0x54
56#define MMU_MMU_CAM_OFFSET 0x58
57#define MMU_MMU_RAM_OFFSET 0x5c
58#define MMU_MMU_GFLUSH_OFFSET 0x60
59#define MMU_MMU_FLUSH_ENTRY_OFFSET 0x64
60/* Bitfield mask and offset declarations */
61#define MMU_MMU_SYSCONFIG_IDLE_MODE_MASK 0x18
62#define MMU_MMU_SYSCONFIG_IDLE_MODE_OFFSET 3
63#define MMU_MMU_SYSCONFIG_AUTO_IDLE_MASK 0x1
64#define MMU_MMU_SYSCONFIG_AUTO_IDLE_OFFSET 0
65#define MMU_MMU_WALKING_ST_TWL_RUNNING_MASK 0x1
66#define MMU_MMU_WALKING_ST_TWL_RUNNING_OFFSET 0
67#define MMU_MMU_CNTL_TWL_ENABLE_MASK 0x4
68#define MMU_MMU_CNTL_TWL_ENABLE_OFFSET 2
69#define MMU_MMU_CNTL_MMU_ENABLE_MASK 0x2
70#define MMU_MMU_CNTL_MMU_ENABLE_OFFSET 1
71#define MMU_MMU_LOCK_BASE_VALUE_MASK 0xfc00
72#define MMU_MMU_LOCK_BASE_VALUE_OFFSET 10
73#define MMU_MMU_LOCK_CURRENT_VICTIM_MASK 0x3f0
74#define MMU_MMU_LOCK_CURRENT_VICTIM_OFFSET 4
75
76#endif /* _MMU_ACC_INT_H */
diff --git a/drivers/staging/tidspbridge/hw/MMURegAcM.h b/drivers/staging/tidspbridge/hw/MMURegAcM.h
new file mode 100644
index 000000000000..ab1a16da731c
--- /dev/null
+++ b/drivers/staging/tidspbridge/hw/MMURegAcM.h
@@ -0,0 +1,225 @@
1/*
2 * MMURegAcM.h
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2007 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#ifndef _MMU_REG_ACM_H
18#define _MMU_REG_ACM_H
19
20#include <linux/io.h>
21#include <EasiGlobal.h>
22
23#include "MMUAccInt.h"
24
25#if defined(USE_LEVEL_1_MACROS)
26
27#define MMUMMU_SYSCONFIG_READ_REGISTER32(base_address)\
28 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_SYSCONFIG_READ_REGISTER32),\
29 __raw_readl((base_address)+MMU_MMU_SYSCONFIG_OFFSET))
30
31#define MMUMMU_SYSCONFIG_IDLE_MODE_WRITE32(base_address, value)\
32{\
33 const u32 offset = MMU_MMU_SYSCONFIG_OFFSET;\
34 register u32 data = __raw_readl((base_address)+offset);\
35 register u32 new_value = (value);\
36 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_SYSCONFIG_IDLE_MODE_WRITE32);\
37 data &= ~(MMU_MMU_SYSCONFIG_IDLE_MODE_MASK);\
38 new_value <<= MMU_MMU_SYSCONFIG_IDLE_MODE_OFFSET;\
39 new_value &= MMU_MMU_SYSCONFIG_IDLE_MODE_MASK;\
40 new_value |= data;\
41 __raw_writel(new_value, base_address+offset);\
42}
43
44#define MMUMMU_SYSCONFIG_AUTO_IDLE_WRITE32(base_address, value)\
45{\
46 const u32 offset = MMU_MMU_SYSCONFIG_OFFSET;\
47 register u32 data = __raw_readl((base_address)+offset);\
48 register u32 new_value = (value);\
49 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_SYSCONFIG_AUTO_IDLE_WRITE32);\
50 data &= ~(MMU_MMU_SYSCONFIG_AUTO_IDLE_MASK);\
51 new_value <<= MMU_MMU_SYSCONFIG_AUTO_IDLE_OFFSET;\
52 new_value &= MMU_MMU_SYSCONFIG_AUTO_IDLE_MASK;\
53 new_value |= data;\
54 __raw_writel(new_value, base_address+offset);\
55}
56
57#define MMUMMU_IRQSTATUS_READ_REGISTER32(base_address)\
58 (_DEBUG_LEVEL1_EASI(easil1_mmummu_irqstatus_read_register32),\
59 __raw_readl((base_address)+MMU_MMU_IRQSTATUS_OFFSET))
60
61#define MMUMMU_IRQSTATUS_WRITE_REGISTER32(base_address, value)\
62{\
63 const u32 offset = MMU_MMU_IRQSTATUS_OFFSET;\
64 register u32 new_value = (value);\
65 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_IRQSTATUS_WRITE_REGISTER32);\
66 __raw_writel(new_value, (base_address)+offset);\
67}
68
69#define MMUMMU_IRQENABLE_READ_REGISTER32(base_address)\
70 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_IRQENABLE_READ_REGISTER32),\
71 __raw_readl((base_address)+MMU_MMU_IRQENABLE_OFFSET))
72
73#define MMUMMU_IRQENABLE_WRITE_REGISTER32(base_address, value)\
74{\
75 const u32 offset = MMU_MMU_IRQENABLE_OFFSET;\
76 register u32 new_value = (value);\
77 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_IRQENABLE_WRITE_REGISTER32);\
78 __raw_writel(new_value, (base_address)+offset);\
79}
80
81#define MMUMMU_WALKING_STTWL_RUNNING_READ32(base_address)\
82 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_WALKING_STTWL_RUNNING_READ32),\
83 (((__raw_readl(((base_address)+(MMU_MMU_WALKING_ST_OFFSET))))\
84 & MMU_MMU_WALKING_ST_TWL_RUNNING_MASK) >>\
85 MMU_MMU_WALKING_ST_TWL_RUNNING_OFFSET))
86
87#define MMUMMU_CNTLTWL_ENABLE_READ32(base_address)\
88 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_CNTLTWL_ENABLE_READ32),\
89 (((__raw_readl(((base_address)+(MMU_MMU_CNTL_OFFSET)))) &\
90 MMU_MMU_CNTL_TWL_ENABLE_MASK) >>\
91 MMU_MMU_CNTL_TWL_ENABLE_OFFSET))
92
93#define MMUMMU_CNTLTWL_ENABLE_WRITE32(base_address, value)\
94{\
95 const u32 offset = MMU_MMU_CNTL_OFFSET;\
96 register u32 data = __raw_readl((base_address)+offset);\
97 register u32 new_value = (value);\
98 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_CNTLTWL_ENABLE_WRITE32);\
99 data &= ~(MMU_MMU_CNTL_TWL_ENABLE_MASK);\
100 new_value <<= MMU_MMU_CNTL_TWL_ENABLE_OFFSET;\
101 new_value &= MMU_MMU_CNTL_TWL_ENABLE_MASK;\
102 new_value |= data;\
103 __raw_writel(new_value, base_address+offset);\
104}
105
106#define MMUMMU_CNTLMMU_ENABLE_WRITE32(base_address, value)\
107{\
108 const u32 offset = MMU_MMU_CNTL_OFFSET;\
109 register u32 data = __raw_readl((base_address)+offset);\
110 register u32 new_value = (value);\
111 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_CNTLMMU_ENABLE_WRITE32);\
112 data &= ~(MMU_MMU_CNTL_MMU_ENABLE_MASK);\
113 new_value <<= MMU_MMU_CNTL_MMU_ENABLE_OFFSET;\
114 new_value &= MMU_MMU_CNTL_MMU_ENABLE_MASK;\
115 new_value |= data;\
116 __raw_writel(new_value, base_address+offset);\
117}
118
119#define MMUMMU_FAULT_AD_READ_REGISTER32(base_address)\
120 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_FAULT_AD_READ_REGISTER32),\
121 __raw_readl((base_address)+MMU_MMU_FAULT_AD_OFFSET))
122
123#define MMUMMU_TTB_WRITE_REGISTER32(base_address, value)\
124{\
125 const u32 offset = MMU_MMU_TTB_OFFSET;\
126 register u32 new_value = (value);\
127 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_TTB_WRITE_REGISTER32);\
128 __raw_writel(new_value, (base_address)+offset);\
129}
130
131#define MMUMMU_LOCK_READ_REGISTER32(base_address)\
132 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_LOCK_READ_REGISTER32),\
133 __raw_readl((base_address)+MMU_MMU_LOCK_OFFSET))
134
135#define MMUMMU_LOCK_WRITE_REGISTER32(base_address, value)\
136{\
137 const u32 offset = MMU_MMU_LOCK_OFFSET;\
138 register u32 new_value = (value);\
139 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_LOCK_WRITE_REGISTER32);\
140 __raw_writel(new_value, (base_address)+offset);\
141}
142
143#define MMUMMU_LOCK_BASE_VALUE_READ32(base_address)\
144 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_LOCK_BASE_VALUE_READ32),\
145 (((__raw_readl(((base_address)+(MMU_MMU_LOCK_OFFSET)))) &\
146 MMU_MMU_LOCK_BASE_VALUE_MASK) >>\
147 MMU_MMU_LOCK_BASE_VALUE_OFFSET))
148
149#define MMUMMU_LOCK_BASE_VALUE_WRITE32(base_address, value)\
150{\
151 const u32 offset = MMU_MMU_LOCK_OFFSET;\
152 register u32 data = __raw_readl((base_address)+offset);\
153 register u32 new_value = (value);\
154 _DEBUG_LEVEL1_EASI(easil1_mmummu_lock_base_value_write32);\
155 data &= ~(MMU_MMU_LOCK_BASE_VALUE_MASK);\
156 new_value <<= MMU_MMU_LOCK_BASE_VALUE_OFFSET;\
157 new_value &= MMU_MMU_LOCK_BASE_VALUE_MASK;\
158 new_value |= data;\
159 __raw_writel(new_value, base_address+offset);\
160}
161
162#define MMUMMU_LOCK_CURRENT_VICTIM_READ32(base_address)\
163 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_LOCK_CURRENT_VICTIM_READ32),\
164 (((__raw_readl(((base_address)+(MMU_MMU_LOCK_OFFSET)))) &\
165 MMU_MMU_LOCK_CURRENT_VICTIM_MASK) >>\
166 MMU_MMU_LOCK_CURRENT_VICTIM_OFFSET))
167
168#define MMUMMU_LOCK_CURRENT_VICTIM_WRITE32(base_address, value)\
169{\
170 const u32 offset = MMU_MMU_LOCK_OFFSET;\
171 register u32 data = __raw_readl((base_address)+offset);\
172 register u32 new_value = (value);\
173 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_LOCK_CURRENT_VICTIM_WRITE32);\
174 data &= ~(MMU_MMU_LOCK_CURRENT_VICTIM_MASK);\
175 new_value <<= MMU_MMU_LOCK_CURRENT_VICTIM_OFFSET;\
176 new_value &= MMU_MMU_LOCK_CURRENT_VICTIM_MASK;\
177 new_value |= data;\
178 __raw_writel(new_value, base_address+offset);\
179}
180
181#define MMUMMU_LOCK_CURRENT_VICTIM_SET32(var, value)\
182 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_LOCK_CURRENT_VICTIM_SET32),\
183 (((var) & ~(MMU_MMU_LOCK_CURRENT_VICTIM_MASK)) |\
184 (((value) << MMU_MMU_LOCK_CURRENT_VICTIM_OFFSET) &\
185 MMU_MMU_LOCK_CURRENT_VICTIM_MASK)))
186
187#define MMUMMU_LD_TLB_READ_REGISTER32(base_address)\
188 (_DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_LD_TLB_READ_REGISTER32),\
189 __raw_readl((base_address)+MMU_MMU_LD_TLB_OFFSET))
190
191#define MMUMMU_LD_TLB_WRITE_REGISTER32(base_address, value)\
192{\
193 const u32 offset = MMU_MMU_LD_TLB_OFFSET;\
194 register u32 new_value = (value);\
195 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_LD_TLB_WRITE_REGISTER32);\
196 __raw_writel(new_value, (base_address)+offset);\
197}
198
199#define MMUMMU_CAM_WRITE_REGISTER32(base_address, value)\
200{\
201 const u32 offset = MMU_MMU_CAM_OFFSET;\
202 register u32 new_value = (value);\
203 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_CAM_WRITE_REGISTER32);\
204 __raw_writel(new_value, (base_address)+offset);\
205}
206
207#define MMUMMU_RAM_WRITE_REGISTER32(base_address, value)\
208{\
209 const u32 offset = MMU_MMU_RAM_OFFSET;\
210 register u32 new_value = (value);\
211 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_RAM_WRITE_REGISTER32);\
212 __raw_writel(new_value, (base_address)+offset);\
213}
214
215#define MMUMMU_FLUSH_ENTRY_WRITE_REGISTER32(base_address, value)\
216{\
217 const u32 offset = MMU_MMU_FLUSH_ENTRY_OFFSET;\
218 register u32 new_value = (value);\
219 _DEBUG_LEVEL1_EASI(EASIL1_MMUMMU_FLUSH_ENTRY_WRITE_REGISTER32);\
220 __raw_writel(new_value, (base_address)+offset);\
221}
222
223#endif /* USE_LEVEL_1_MACROS */
224
225#endif /* _MMU_REG_ACM_H */
diff --git a/drivers/staging/tidspbridge/hw/hw_defs.h b/drivers/staging/tidspbridge/hw/hw_defs.h
new file mode 100644
index 000000000000..d5266d4c163f
--- /dev/null
+++ b/drivers/staging/tidspbridge/hw/hw_defs.h
@@ -0,0 +1,58 @@
1/*
2 * hw_defs.h
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * Global HW definitions
7 *
8 * Copyright (C) 2007 Texas Instruments, Inc.
9 *
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19#ifndef _HW_DEFS_H
20#define _HW_DEFS_H
21
22/* Page size */
23#define HW_PAGE_SIZE4KB 0x1000
24#define HW_PAGE_SIZE64KB 0x10000
25#define HW_PAGE_SIZE1MB 0x100000
26#define HW_PAGE_SIZE16MB 0x1000000
27
28/* hw_status: return type for HW API */
29typedef long hw_status;
30
31/* Macro used to set and clear any bit */
32#define HW_CLEAR 0
33#define HW_SET 1
34
35/* hw_endianism_t: Enumerated Type used to specify the endianism
36 * Do NOT change these values. They are used as bit fields. */
37enum hw_endianism_t {
38 HW_LITTLE_ENDIAN,
39 HW_BIG_ENDIAN
40};
41
42/* hw_element_size_t: Enumerated Type used to specify the element size
43 * Do NOT change these values. They are used as bit fields. */
44enum hw_element_size_t {
45 HW_ELEM_SIZE8BIT,
46 HW_ELEM_SIZE16BIT,
47 HW_ELEM_SIZE32BIT,
48 HW_ELEM_SIZE64BIT
49};
50
51/* hw_idle_mode_t: Enumerated Type used to specify Idle modes */
52enum hw_idle_mode_t {
53 HW_FORCE_IDLE,
54 HW_NO_IDLE,
55 HW_SMART_IDLE
56};
57
58#endif /* _HW_DEFS_H */
diff --git a/drivers/staging/tidspbridge/hw/hw_mmu.c b/drivers/staging/tidspbridge/hw/hw_mmu.c
new file mode 100644
index 000000000000..014f5d5293ae
--- /dev/null
+++ b/drivers/staging/tidspbridge/hw/hw_mmu.c
@@ -0,0 +1,562 @@
1/*
2 * hw_mmu.c
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * API definitions to setup MMU TLB and PTE
7 *
8 * Copyright (C) 2007 Texas Instruments, Inc.
9 *
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19#include <linux/io.h>
20#include "MMURegAcM.h"
21#include <hw_defs.h>
22#include <hw_mmu.h>
23#include <linux/types.h>
24#include <linux/err.h>
25
26#define MMU_BASE_VAL_MASK 0xFC00
27#define MMU_PAGE_MAX 3
28#define MMU_ELEMENTSIZE_MAX 3
29#define MMU_ADDR_MASK 0xFFFFF000
30#define MMU_TTB_MASK 0xFFFFC000
31#define MMU_SECTION_ADDR_MASK 0xFFF00000
32#define MMU_SSECTION_ADDR_MASK 0xFF000000
33#define MMU_PAGE_TABLE_MASK 0xFFFFFC00
34#define MMU_LARGE_PAGE_MASK 0xFFFF0000
35#define MMU_SMALL_PAGE_MASK 0xFFFFF000
36
37#define MMU_LOAD_TLB 0x00000001
38#define MMU_GFLUSH 0x60
39
40/*
41 * hw_mmu_page_size_t: Enumerated Type used to specify the MMU Page Size(SLSS)
42 */
43enum hw_mmu_page_size_t {
44 HW_MMU_SECTION,
45 HW_MMU_LARGE_PAGE,
46 HW_MMU_SMALL_PAGE,
47 HW_MMU_SUPERSECTION
48};
49
50/*
51 * FUNCTION : mmu_flush_entry
52 *
53 * INPUTS:
54 *
55 * Identifier : base_address
56 * Type : const u32
57 * Description : Base Address of instance of MMU module
58 *
59 * RETURNS:
60 *
61 * Type : hw_status
62 * Description : 0 -- No errors occured
63 * RET_BAD_NULL_PARAM -- A Pointer
64 * Paramater was set to NULL
65 *
66 * PURPOSE: : Flush the TLB entry pointed by the
67 * lock counter register
68 * even if this entry is set protected
69 *
70 * METHOD: : Check the Input parameter and Flush a
71 * single entry in the TLB.
72 */
73static hw_status mmu_flush_entry(const void __iomem *base_address);
74
75/*
76 * FUNCTION : mmu_set_cam_entry
77 *
78 * INPUTS:
79 *
80 * Identifier : base_address
81 * TypE : const u32
82 * Description : Base Address of instance of MMU module
83 *
84 * Identifier : page_sz
85 * TypE : const u32
86 * Description : It indicates the page size
87 *
88 * Identifier : preserved_bit
89 * Type : const u32
90 * Description : It indicates the TLB entry is preserved entry
91 * or not
92 *
93 * Identifier : valid_bit
94 * Type : const u32
95 * Description : It indicates the TLB entry is valid entry or not
96 *
97 *
98 * Identifier : virtual_addr_tag
99 * Type : const u32
100 * Description : virtual Address
101 *
102 * RETURNS:
103 *
104 * Type : hw_status
105 * Description : 0 -- No errors occured
106 * RET_BAD_NULL_PARAM -- A Pointer Paramater
107 * was set to NULL
108 * RET_PARAM_OUT_OF_RANGE -- Input Parameter out
109 * of Range
110 *
111 * PURPOSE: : Set MMU_CAM reg
112 *
113 * METHOD: : Check the Input parameters and set the CAM entry.
114 */
115static hw_status mmu_set_cam_entry(const void __iomem *base_address,
116 const u32 page_sz,
117 const u32 preserved_bit,
118 const u32 valid_bit,
119 const u32 virtual_addr_tag);
120
121/*
122 * FUNCTION : mmu_set_ram_entry
123 *
124 * INPUTS:
125 *
126 * Identifier : base_address
127 * Type : const u32
128 * Description : Base Address of instance of MMU module
129 *
130 * Identifier : physical_addr
131 * Type : const u32
132 * Description : Physical Address to which the corresponding
133 * virtual Address shouldpoint
134 *
135 * Identifier : endianism
136 * Type : hw_endianism_t
137 * Description : endianism for the given page
138 *
139 * Identifier : element_size
140 * Type : hw_element_size_t
141 * Description : The element size ( 8,16, 32 or 64 bit)
142 *
143 * Identifier : mixed_size
144 * Type : hw_mmu_mixed_size_t
145 * Description : Element Size to follow CPU or TLB
146 *
147 * RETURNS:
148 *
149 * Type : hw_status
150 * Description : 0 -- No errors occured
151 * RET_BAD_NULL_PARAM -- A Pointer Paramater
152 * was set to NULL
153 * RET_PARAM_OUT_OF_RANGE -- Input Parameter
154 * out of Range
155 *
156 * PURPOSE: : Set MMU_CAM reg
157 *
158 * METHOD: : Check the Input parameters and set the RAM entry.
159 */
160static hw_status mmu_set_ram_entry(const void __iomem *base_address,
161 const u32 physical_addr,
162 enum hw_endianism_t endianism,
163 enum hw_element_size_t element_size,
164 enum hw_mmu_mixed_size_t mixed_size);
165
166/* HW FUNCTIONS */
167
168hw_status hw_mmu_enable(const void __iomem *base_address)
169{
170 hw_status status = 0;
171
172 MMUMMU_CNTLMMU_ENABLE_WRITE32(base_address, HW_SET);
173
174 return status;
175}
176
177hw_status hw_mmu_disable(const void __iomem *base_address)
178{
179 hw_status status = 0;
180
181 MMUMMU_CNTLMMU_ENABLE_WRITE32(base_address, HW_CLEAR);
182
183 return status;
184}
185
186hw_status hw_mmu_num_locked_set(const void __iomem *base_address,
187 u32 num_locked_entries)
188{
189 hw_status status = 0;
190
191 MMUMMU_LOCK_BASE_VALUE_WRITE32(base_address, num_locked_entries);
192
193 return status;
194}
195
196hw_status hw_mmu_victim_num_set(const void __iomem *base_address,
197 u32 victim_entry_num)
198{
199 hw_status status = 0;
200
201 MMUMMU_LOCK_CURRENT_VICTIM_WRITE32(base_address, victim_entry_num);
202
203 return status;
204}
205
206hw_status hw_mmu_event_ack(const void __iomem *base_address, u32 irq_mask)
207{
208 hw_status status = 0;
209
210 MMUMMU_IRQSTATUS_WRITE_REGISTER32(base_address, irq_mask);
211
212 return status;
213}
214
215hw_status hw_mmu_event_disable(const void __iomem *base_address, u32 irq_mask)
216{
217 hw_status status = 0;
218 u32 irq_reg;
219
220 irq_reg = MMUMMU_IRQENABLE_READ_REGISTER32(base_address);
221
222 MMUMMU_IRQENABLE_WRITE_REGISTER32(base_address, irq_reg & ~irq_mask);
223
224 return status;
225}
226
227hw_status hw_mmu_event_enable(const void __iomem *base_address, u32 irq_mask)
228{
229 hw_status status = 0;
230 u32 irq_reg;
231
232 irq_reg = MMUMMU_IRQENABLE_READ_REGISTER32(base_address);
233
234 MMUMMU_IRQENABLE_WRITE_REGISTER32(base_address, irq_reg | irq_mask);
235
236 return status;
237}
238
239hw_status hw_mmu_event_status(const void __iomem *base_address, u32 *irq_mask)
240{
241 hw_status status = 0;
242
243 *irq_mask = MMUMMU_IRQSTATUS_READ_REGISTER32(base_address);
244
245 return status;
246}
247
248hw_status hw_mmu_fault_addr_read(const void __iomem *base_address, u32 *addr)
249{
250 hw_status status = 0;
251
252 /* read values from register */
253 *addr = MMUMMU_FAULT_AD_READ_REGISTER32(base_address);
254
255 return status;
256}
257
258hw_status hw_mmu_ttb_set(const void __iomem *base_address, u32 ttb_phys_addr)
259{
260 hw_status status = 0;
261 u32 load_ttb;
262
263 load_ttb = ttb_phys_addr & ~0x7FUL;
264 /* write values to register */
265 MMUMMU_TTB_WRITE_REGISTER32(base_address, load_ttb);
266
267 return status;
268}
269
270hw_status hw_mmu_twl_enable(const void __iomem *base_address)
271{
272 hw_status status = 0;
273
274 MMUMMU_CNTLTWL_ENABLE_WRITE32(base_address, HW_SET);
275
276 return status;
277}
278
279hw_status hw_mmu_twl_disable(const void __iomem *base_address)
280{
281 hw_status status = 0;
282
283 MMUMMU_CNTLTWL_ENABLE_WRITE32(base_address, HW_CLEAR);
284
285 return status;
286}
287
288hw_status hw_mmu_tlb_flush(const void __iomem *base_address, u32 virtual_addr,
289 u32 page_sz)
290{
291 hw_status status = 0;
292 u32 virtual_addr_tag;
293 enum hw_mmu_page_size_t pg_size_bits;
294
295 switch (page_sz) {
296 case HW_PAGE_SIZE4KB:
297 pg_size_bits = HW_MMU_SMALL_PAGE;
298 break;
299
300 case HW_PAGE_SIZE64KB:
301 pg_size_bits = HW_MMU_LARGE_PAGE;
302 break;
303
304 case HW_PAGE_SIZE1MB:
305 pg_size_bits = HW_MMU_SECTION;
306 break;
307
308 case HW_PAGE_SIZE16MB:
309 pg_size_bits = HW_MMU_SUPERSECTION;
310 break;
311
312 default:
313 return -EINVAL;
314 }
315
316 /* Generate the 20-bit tag from virtual address */
317 virtual_addr_tag = ((virtual_addr & MMU_ADDR_MASK) >> 12);
318
319 mmu_set_cam_entry(base_address, pg_size_bits, 0, 0, virtual_addr_tag);
320
321 mmu_flush_entry(base_address);
322
323 return status;
324}
325
326hw_status hw_mmu_tlb_add(const void __iomem *base_address,
327 u32 physical_addr,
328 u32 virtual_addr,
329 u32 page_sz,
330 u32 entry_num,
331 struct hw_mmu_map_attrs_t *map_attrs,
332 s8 preserved_bit, s8 valid_bit)
333{
334 hw_status status = 0;
335 u32 lock_reg;
336 u32 virtual_addr_tag;
337 enum hw_mmu_page_size_t mmu_pg_size;
338
339 /*Check the input Parameters */
340 switch (page_sz) {
341 case HW_PAGE_SIZE4KB:
342 mmu_pg_size = HW_MMU_SMALL_PAGE;
343 break;
344
345 case HW_PAGE_SIZE64KB:
346 mmu_pg_size = HW_MMU_LARGE_PAGE;
347 break;
348
349 case HW_PAGE_SIZE1MB:
350 mmu_pg_size = HW_MMU_SECTION;
351 break;
352
353 case HW_PAGE_SIZE16MB:
354 mmu_pg_size = HW_MMU_SUPERSECTION;
355 break;
356
357 default:
358 return -EINVAL;
359 }
360
361 lock_reg = MMUMMU_LOCK_READ_REGISTER32(base_address);
362
363 /* Generate the 20-bit tag from virtual address */
364 virtual_addr_tag = ((virtual_addr & MMU_ADDR_MASK) >> 12);
365
366 /* Write the fields in the CAM Entry Register */
367 mmu_set_cam_entry(base_address, mmu_pg_size, preserved_bit, valid_bit,
368 virtual_addr_tag);
369
370 /* Write the different fields of the RAM Entry Register */
371 /* endianism of the page,Element Size of the page (8, 16, 32, 64 bit) */
372 mmu_set_ram_entry(base_address, physical_addr, map_attrs->endianism,
373 map_attrs->element_size, map_attrs->mixed_size);
374
375 /* Update the MMU Lock Register */
376 /* currentVictim between lockedBaseValue and (MMU_Entries_Number - 1) */
377 MMUMMU_LOCK_CURRENT_VICTIM_WRITE32(base_address, entry_num);
378
379 /* Enable loading of an entry in TLB by writing 1
380 into LD_TLB_REG register */
381 MMUMMU_LD_TLB_WRITE_REGISTER32(base_address, MMU_LOAD_TLB);
382
383 MMUMMU_LOCK_WRITE_REGISTER32(base_address, lock_reg);
384
385 return status;
386}
387
388hw_status hw_mmu_pte_set(const u32 pg_tbl_va,
389 u32 physical_addr,
390 u32 virtual_addr,
391 u32 page_sz, struct hw_mmu_map_attrs_t *map_attrs)
392{
393 hw_status status = 0;
394 u32 pte_addr, pte_val;
395 s32 num_entries = 1;
396
397 switch (page_sz) {
398 case HW_PAGE_SIZE4KB:
399 pte_addr = hw_mmu_pte_addr_l2(pg_tbl_va,
400 virtual_addr &
401 MMU_SMALL_PAGE_MASK);
402 pte_val =
403 ((physical_addr & MMU_SMALL_PAGE_MASK) |
404 (map_attrs->endianism << 9) | (map_attrs->
405 element_size << 4) |
406 (map_attrs->mixed_size << 11) | 2);
407 break;
408
409 case HW_PAGE_SIZE64KB:
410 num_entries = 16;
411 pte_addr = hw_mmu_pte_addr_l2(pg_tbl_va,
412 virtual_addr &
413 MMU_LARGE_PAGE_MASK);
414 pte_val =
415 ((physical_addr & MMU_LARGE_PAGE_MASK) |
416 (map_attrs->endianism << 9) | (map_attrs->
417 element_size << 4) |
418 (map_attrs->mixed_size << 11) | 1);
419 break;
420
421 case HW_PAGE_SIZE1MB:
422 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
423 virtual_addr &
424 MMU_SECTION_ADDR_MASK);
425 pte_val =
426 ((((physical_addr & MMU_SECTION_ADDR_MASK) |
427 (map_attrs->endianism << 15) | (map_attrs->
428 element_size << 10) |
429 (map_attrs->mixed_size << 17)) & ~0x40000) | 0x2);
430 break;
431
432 case HW_PAGE_SIZE16MB:
433 num_entries = 16;
434 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
435 virtual_addr &
436 MMU_SSECTION_ADDR_MASK);
437 pte_val =
438 (((physical_addr & MMU_SSECTION_ADDR_MASK) |
439 (map_attrs->endianism << 15) | (map_attrs->
440 element_size << 10) |
441 (map_attrs->mixed_size << 17)
442 ) | 0x40000 | 0x2);
443 break;
444
445 case HW_MMU_COARSE_PAGE_SIZE:
446 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
447 virtual_addr &
448 MMU_SECTION_ADDR_MASK);
449 pte_val = (physical_addr & MMU_PAGE_TABLE_MASK) | 1;
450 break;
451
452 default:
453 return -EINVAL;
454 }
455
456 while (--num_entries >= 0)
457 ((u32 *) pte_addr)[num_entries] = pte_val;
458
459 return status;
460}
461
462hw_status hw_mmu_pte_clear(const u32 pg_tbl_va, u32 virtual_addr, u32 page_size)
463{
464 hw_status status = 0;
465 u32 pte_addr;
466 s32 num_entries = 1;
467
468 switch (page_size) {
469 case HW_PAGE_SIZE4KB:
470 pte_addr = hw_mmu_pte_addr_l2(pg_tbl_va,
471 virtual_addr &
472 MMU_SMALL_PAGE_MASK);
473 break;
474
475 case HW_PAGE_SIZE64KB:
476 num_entries = 16;
477 pte_addr = hw_mmu_pte_addr_l2(pg_tbl_va,
478 virtual_addr &
479 MMU_LARGE_PAGE_MASK);
480 break;
481
482 case HW_PAGE_SIZE1MB:
483 case HW_MMU_COARSE_PAGE_SIZE:
484 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
485 virtual_addr &
486 MMU_SECTION_ADDR_MASK);
487 break;
488
489 case HW_PAGE_SIZE16MB:
490 num_entries = 16;
491 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
492 virtual_addr &
493 MMU_SSECTION_ADDR_MASK);
494 break;
495
496 default:
497 return -EINVAL;
498 }
499
500 while (--num_entries >= 0)
501 ((u32 *) pte_addr)[num_entries] = 0;
502
503 return status;
504}
505
506/* mmu_flush_entry */
507static hw_status mmu_flush_entry(const void __iomem *base_address)
508{
509 hw_status status = 0;
510 u32 flush_entry_data = 0x1;
511
512 /* write values to register */
513 MMUMMU_FLUSH_ENTRY_WRITE_REGISTER32(base_address, flush_entry_data);
514
515 return status;
516}
517
518/* mmu_set_cam_entry */
519static hw_status mmu_set_cam_entry(const void __iomem *base_address,
520 const u32 page_sz,
521 const u32 preserved_bit,
522 const u32 valid_bit,
523 const u32 virtual_addr_tag)
524{
525 hw_status status = 0;
526 u32 mmu_cam_reg;
527
528 mmu_cam_reg = (virtual_addr_tag << 12);
529 mmu_cam_reg = (mmu_cam_reg) | (page_sz) | (valid_bit << 2) |
530 (preserved_bit << 3);
531
532 /* write values to register */
533 MMUMMU_CAM_WRITE_REGISTER32(base_address, mmu_cam_reg);
534
535 return status;
536}
537
538/* mmu_set_ram_entry */
539static hw_status mmu_set_ram_entry(const void __iomem *base_address,
540 const u32 physical_addr,
541 enum hw_endianism_t endianism,
542 enum hw_element_size_t element_size,
543 enum hw_mmu_mixed_size_t mixed_size)
544{
545 hw_status status = 0;
546 u32 mmu_ram_reg;
547
548 mmu_ram_reg = (physical_addr & MMU_ADDR_MASK);
549 mmu_ram_reg = (mmu_ram_reg) | ((endianism << 9) | (element_size << 7) |
550 (mixed_size << 6));
551
552 /* write values to register */
553 MMUMMU_RAM_WRITE_REGISTER32(base_address, mmu_ram_reg);
554
555 return status;
556
557}
558
559void hw_mmu_tlb_flush_all(const void __iomem *base)
560{
561 __raw_writeb(1, base + MMU_GFLUSH);
562}
diff --git a/drivers/staging/tidspbridge/hw/hw_mmu.h b/drivers/staging/tidspbridge/hw/hw_mmu.h
new file mode 100644
index 000000000000..1458a2c6027b
--- /dev/null
+++ b/drivers/staging/tidspbridge/hw/hw_mmu.h
@@ -0,0 +1,163 @@
1/*
2 * hw_mmu.h
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * MMU types and API declarations
7 *
8 * Copyright (C) 2007 Texas Instruments, Inc.
9 *
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19#ifndef _HW_MMU_H
20#define _HW_MMU_H
21
22#include <linux/types.h>
23
24/* Bitmasks for interrupt sources */
25#define HW_MMU_TRANSLATION_FAULT 0x2
26#define HW_MMU_ALL_INTERRUPTS 0x1F
27
28#define HW_MMU_COARSE_PAGE_SIZE 0x400
29
30/* hw_mmu_mixed_size_t: Enumerated Type used to specify whether to follow
31 CPU/TLB Element size */
32enum hw_mmu_mixed_size_t {
33 HW_MMU_TLBES,
34 HW_MMU_CPUES
35};
36
37/* hw_mmu_map_attrs_t: Struct containing MMU mapping attributes */
38struct hw_mmu_map_attrs_t {
39 enum hw_endianism_t endianism;
40 enum hw_element_size_t element_size;
41 enum hw_mmu_mixed_size_t mixed_size;
42 bool donotlockmpupage;
43};
44
45extern hw_status hw_mmu_enable(const void __iomem *base_address);
46
47extern hw_status hw_mmu_disable(const void __iomem *base_address);
48
49extern hw_status hw_mmu_num_locked_set(const void __iomem *base_address,
50 u32 num_locked_entries);
51
52extern hw_status hw_mmu_victim_num_set(const void __iomem *base_address,
53 u32 victim_entry_num);
54
55/* For MMU faults */
56extern hw_status hw_mmu_event_ack(const void __iomem *base_address,
57 u32 irq_mask);
58
59extern hw_status hw_mmu_event_disable(const void __iomem *base_address,
60 u32 irq_mask);
61
62extern hw_status hw_mmu_event_enable(const void __iomem *base_address,
63 u32 irq_mask);
64
65extern hw_status hw_mmu_event_status(const void __iomem *base_address,
66 u32 *irq_mask);
67
68extern hw_status hw_mmu_fault_addr_read(const void __iomem *base_address,
69 u32 *addr);
70
71/* Set the TT base address */
72extern hw_status hw_mmu_ttb_set(const void __iomem *base_address,
73 u32 ttb_phys_addr);
74
75extern hw_status hw_mmu_twl_enable(const void __iomem *base_address);
76
77extern hw_status hw_mmu_twl_disable(const void __iomem *base_address);
78
79extern hw_status hw_mmu_tlb_flush(const void __iomem *base_address,
80 u32 virtual_addr, u32 page_sz);
81
82extern hw_status hw_mmu_tlb_add(const void __iomem *base_address,
83 u32 physical_addr,
84 u32 virtual_addr,
85 u32 page_sz,
86 u32 entry_num,
87 struct hw_mmu_map_attrs_t *map_attrs,
88 s8 preserved_bit, s8 valid_bit);
89
90/* For PTEs */
91extern hw_status hw_mmu_pte_set(const u32 pg_tbl_va,
92 u32 physical_addr,
93 u32 virtual_addr,
94 u32 page_sz,
95 struct hw_mmu_map_attrs_t *map_attrs);
96
97extern hw_status hw_mmu_pte_clear(const u32 pg_tbl_va,
98 u32 virtual_addr, u32 page_size);
99
100void hw_mmu_tlb_flush_all(const void __iomem *base);
101
102static inline u32 hw_mmu_pte_addr_l1(u32 l1_base, u32 va)
103{
104 u32 pte_addr;
105 u32 va31_to20;
106
107 va31_to20 = va >> (20 - 2); /* Left-shift by 2 here itself */
108 va31_to20 &= 0xFFFFFFFCUL;
109 pte_addr = l1_base + va31_to20;
110
111 return pte_addr;
112}
113
114static inline u32 hw_mmu_pte_addr_l2(u32 l2_base, u32 va)
115{
116 u32 pte_addr;
117
118 pte_addr = (l2_base & 0xFFFFFC00) | ((va >> 10) & 0x3FC);
119
120 return pte_addr;
121}
122
123static inline u32 hw_mmu_pte_coarse_l1(u32 pte_val)
124{
125 u32 pte_coarse;
126
127 pte_coarse = pte_val & 0xFFFFFC00;
128
129 return pte_coarse;
130}
131
132static inline u32 hw_mmu_pte_size_l1(u32 pte_val)
133{
134 u32 pte_size = 0;
135
136 if ((pte_val & 0x3) == 0x1) {
137 /* Points to L2 PT */
138 pte_size = HW_MMU_COARSE_PAGE_SIZE;
139 }
140
141 if ((pte_val & 0x3) == 0x2) {
142 if (pte_val & (1 << 18))
143 pte_size = HW_PAGE_SIZE16MB;
144 else
145 pte_size = HW_PAGE_SIZE1MB;
146 }
147
148 return pte_size;
149}
150
151static inline u32 hw_mmu_pte_size_l2(u32 pte_val)
152{
153 u32 pte_size = 0;
154
155 if (pte_val & 0x2)
156 pte_size = HW_PAGE_SIZE4KB;
157 else if (pte_val & 0x1)
158 pte_size = HW_PAGE_SIZE64KB;
159
160 return pte_size;
161}
162
163#endif /* _HW_MMU_H */
diff --git a/drivers/staging/tidspbridge/include/dspbridge/cfgdefs.h b/drivers/staging/tidspbridge/include/dspbridge/cfgdefs.h
index dfb55cca34c7..38122dbf877a 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/cfgdefs.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/cfgdefs.h
@@ -68,6 +68,7 @@ struct cfg_hostres {
68 void __iomem *dw_per_base; 68 void __iomem *dw_per_base;
69 u32 dw_per_pm_base; 69 u32 dw_per_pm_base;
70 u32 dw_core_pm_base; 70 u32 dw_core_pm_base;
71 void __iomem *dw_dmmu_base;
71 void __iomem *dw_sys_ctrl_base; 72 void __iomem *dw_sys_ctrl_base;
72}; 73};
73 74
diff --git a/drivers/staging/tidspbridge/include/dspbridge/dev.h b/drivers/staging/tidspbridge/include/dspbridge/dev.h
index 9bdd48f57429..357458fadd2a 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/dev.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/dev.h
@@ -27,6 +27,7 @@
27#include <dspbridge/nodedefs.h> 27#include <dspbridge/nodedefs.h>
28#include <dspbridge/dispdefs.h> 28#include <dspbridge/dispdefs.h>
29#include <dspbridge/dspdefs.h> 29#include <dspbridge/dspdefs.h>
30#include <dspbridge/dmm.h>
30#include <dspbridge/host_os.h> 31#include <dspbridge/host_os.h>
31 32
32/* ----------------------------------- This */ 33/* ----------------------------------- This */
@@ -233,6 +234,29 @@ extern int dev_get_cmm_mgr(struct dev_object *hdev_obj,
233 struct cmm_object **mgr); 234 struct cmm_object **mgr);
234 235
235/* 236/*
237 * ======== dev_get_dmm_mgr ========
238 * Purpose:
239 * Retrieve the handle to the dynamic memory manager created for this
240 * device.
241 * Parameters:
242 * hdev_obj: Handle to device object created with
243 * dev_create_device().
244 * *mgr: Ptr to location to store handle.
245 * Returns:
246 * 0: Success.
247 * -EFAULT: Invalid hdev_obj.
248 * Requires:
249 * mgr != NULL.
250 * DEV Initialized.
251 * Ensures:
252 * 0: *mgr contains a handle to a channel manager object,
253 * or NULL.
254 * else: *mgr is NULL.
255 */
256extern int dev_get_dmm_mgr(struct dev_object *hdev_obj,
257 struct dmm_object **mgr);
258
259/*
236 * ======== dev_get_cod_mgr ======== 260 * ======== dev_get_cod_mgr ========
237 * Purpose: 261 * Purpose:
238 * Retrieve the COD manager create for this device. 262 * Retrieve the COD manager create for this device.
diff --git a/drivers/staging/tidspbridge/include/dspbridge/dmm.h b/drivers/staging/tidspbridge/include/dspbridge/dmm.h
new file mode 100644
index 000000000000..6c58335c5f60
--- /dev/null
+++ b/drivers/staging/tidspbridge/include/dspbridge/dmm.h
@@ -0,0 +1,75 @@
1/*
2 * dmm.h
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * The Dynamic Memory Mapping(DMM) module manages the DSP Virtual address
7 * space that can be directly mapped to any MPU buffer or memory region.
8 *
9 * Copyright (C) 2005-2006 Texas Instruments, Inc.
10 *
11 * This package is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20#ifndef DMM_
21#define DMM_
22
23#include <dspbridge/dbdefs.h>
24
25struct dmm_object;
26
27/* DMM attributes used in dmm_create() */
28struct dmm_mgrattrs {
29 u32 reserved;
30};
31
32#define DMMPOOLSIZE 0x4000000
33
34/*
35 * ======== dmm_get_handle ========
36 * Purpose:
37 * Return the dynamic memory manager object for this device.
38 * This is typically called from the client process.
39 */
40
41extern int dmm_get_handle(void *hprocessor,
42 struct dmm_object **dmm_manager);
43
44extern int dmm_reserve_memory(struct dmm_object *dmm_mgr,
45 u32 size, u32 *prsv_addr);
46
47extern int dmm_un_reserve_memory(struct dmm_object *dmm_mgr,
48 u32 rsv_addr);
49
50extern int dmm_map_memory(struct dmm_object *dmm_mgr, u32 addr,
51 u32 size);
52
53extern int dmm_un_map_memory(struct dmm_object *dmm_mgr,
54 u32 addr, u32 *psize);
55
56extern int dmm_destroy(struct dmm_object *dmm_mgr);
57
58extern int dmm_delete_tables(struct dmm_object *dmm_mgr);
59
60extern int dmm_create(struct dmm_object **dmm_manager,
61 struct dev_object *hdev_obj,
62 const struct dmm_mgrattrs *mgr_attrts);
63
64extern bool dmm_init(void);
65
66extern void dmm_exit(void);
67
68extern int dmm_create_tables(struct dmm_object *dmm_mgr,
69 u32 addr, u32 size);
70
71#ifdef DSP_DMM_DEBUG
72u32 dmm_mem_map_dump(struct dmm_object *dmm_mgr);
73#endif
74
75#endif /* DMM_ */
diff --git a/drivers/staging/tidspbridge/include/dspbridge/drv.h b/drivers/staging/tidspbridge/include/dspbridge/drv.h
index 75a2c9b5c6f2..c1f363ec9afa 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/drv.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/drv.h
@@ -108,6 +108,12 @@ struct dmm_map_object {
108 struct bridge_dma_map_info dma_info; 108 struct bridge_dma_map_info dma_info;
109}; 109};
110 110
111/* Used for DMM reserved memory accounting */
112struct dmm_rsv_object {
113 struct list_head link;
114 u32 dsp_reserved_addr;
115};
116
111/* New structure (member of process context) abstracts DMM resource info */ 117/* New structure (member of process context) abstracts DMM resource info */
112struct dspheap_res_object { 118struct dspheap_res_object {
113 s32 heap_allocated; /* DMM status */ 119 s32 heap_allocated; /* DMM status */
@@ -159,6 +165,10 @@ struct process_context {
159 struct list_head dmm_map_list; 165 struct list_head dmm_map_list;
160 spinlock_t dmm_map_lock; 166 spinlock_t dmm_map_lock;
161 167
168 /* DMM reserved memory resources */
169 struct list_head dmm_rsv_list;
170 spinlock_t dmm_rsv_lock;
171
162 /* DSP Heap resources */ 172 /* DSP Heap resources */
163 struct dspheap_res_object *pdspheap_list; 173 struct dspheap_res_object *pdspheap_list;
164 174
diff --git a/drivers/staging/tidspbridge/include/dspbridge/dsp-mmu.h b/drivers/staging/tidspbridge/include/dspbridge/dsp-mmu.h
deleted file mode 100644
index cb38d4cc0734..000000000000
--- a/drivers/staging/tidspbridge/include/dspbridge/dsp-mmu.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/*
2 * dsp-mmu.h
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * DSP iommu.
7 *
8 * Copyright (C) 2005-2010 Texas Instruments, Inc.
9 *
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19#ifndef _DSP_MMU_
20#define _DSP_MMU_
21
22#include <plat/iommu.h>
23#include <plat/iovmm.h>
24
25/**
26 * dsp_mmu_init() - initialize dsp_mmu module and returns a handle
27 *
28 * This function initialize dsp mmu module and returns a struct iommu
29 * handle to use it for dsp maps.
30 *
31 */
32struct iommu *dsp_mmu_init(void);
33
34/**
35 * dsp_mmu_exit() - destroy dsp mmu module
36 * @mmu: Pointer to iommu handle.
37 *
38 * This function destroys dsp mmu module.
39 *
40 */
41void dsp_mmu_exit(struct iommu *mmu);
42
43/**
44 * user_to_dsp_map() - maps user to dsp virtual address
45 * @mmu: Pointer to iommu handle.
46 * @uva: Virtual user space address.
47 * @da DSP address
48 * @size Buffer size to map.
49 * @usr_pgs struct page array pointer where the user pages will be stored
50 *
51 * This function maps a user space buffer into DSP virtual address.
52 *
53 */
54u32 user_to_dsp_map(struct iommu *mmu, u32 uva, u32 da, u32 size,
55 struct page **usr_pgs);
56
57/**
58 * user_to_dsp_unmap() - unmaps DSP virtual buffer.
59 * @mmu: Pointer to iommu handle.
60 * @da DSP address
61 *
62 * This function unmaps a user space buffer into DSP virtual address.
63 *
64 */
65int user_to_dsp_unmap(struct iommu *mmu, u32 da);
66
67#endif
diff --git a/drivers/staging/tidspbridge/include/dspbridge/dspdefs.h b/drivers/staging/tidspbridge/include/dspbridge/dspdefs.h
index 615363474810..0ae7d1646a1b 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/dspdefs.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/dspdefs.h
@@ -162,6 +162,48 @@ typedef int(*fxn_brd_memwrite) (struct bridge_dev_context
162 u32 mem_type); 162 u32 mem_type);
163 163
164/* 164/*
165 * ======== bridge_brd_mem_map ========
166 * Purpose:
167 * Map a MPU memory region to a DSP/IVA memory space
168 * Parameters:
169 * dev_ctxt: Handle to Bridge driver defined device info.
170 * ul_mpu_addr: MPU memory region start address.
171 * virt_addr: DSP/IVA memory region u8 address.
172 * ul_num_bytes: Number of bytes to map.
173 * map_attrs: Mapping attributes (e.g. endianness).
174 * Returns:
175 * 0: Success.
176 * -EPERM: Other, unspecified error.
177 * Requires:
178 * dev_ctxt != NULL;
179 * Ensures:
180 */
181typedef int(*fxn_brd_memmap) (struct bridge_dev_context
182 * dev_ctxt, u32 ul_mpu_addr,
183 u32 virt_addr, u32 ul_num_bytes,
184 u32 map_attr,
185 struct page **mapped_pages);
186
187/*
188 * ======== bridge_brd_mem_un_map ========
189 * Purpose:
190 * UnMap an MPU memory region from DSP/IVA memory space
191 * Parameters:
192 * dev_ctxt: Handle to Bridge driver defined device info.
193 * virt_addr: DSP/IVA memory region u8 address.
194 * ul_num_bytes: Number of bytes to unmap.
195 * Returns:
196 * 0: Success.
197 * -EPERM: Other, unspecified error.
198 * Requires:
199 * dev_ctxt != NULL;
200 * Ensures:
201 */
202typedef int(*fxn_brd_memunmap) (struct bridge_dev_context
203 * dev_ctxt,
204 u32 virt_addr, u32 ul_num_bytes);
205
206/*
165 * ======== bridge_brd_stop ======== 207 * ======== bridge_brd_stop ========
166 * Purpose: 208 * Purpose:
167 * Bring board to the BRD_STOPPED state. 209 * Bring board to the BRD_STOPPED state.
@@ -951,6 +993,8 @@ struct bridge_drv_interface {
951 fxn_brd_setstate pfn_brd_set_state; /* Sets the Board State */ 993 fxn_brd_setstate pfn_brd_set_state; /* Sets the Board State */
952 fxn_brd_memcopy pfn_brd_mem_copy; /* Copies DSP Memory */ 994 fxn_brd_memcopy pfn_brd_mem_copy; /* Copies DSP Memory */
953 fxn_brd_memwrite pfn_brd_mem_write; /* Write DSP Memory w/o halt */ 995 fxn_brd_memwrite pfn_brd_mem_write; /* Write DSP Memory w/o halt */
996 fxn_brd_memmap pfn_brd_mem_map; /* Maps MPU mem to DSP mem */
997 fxn_brd_memunmap pfn_brd_mem_un_map; /* Unmaps MPU mem to DSP mem */
954 fxn_chnl_create pfn_chnl_create; /* Create channel manager. */ 998 fxn_chnl_create pfn_chnl_create; /* Create channel manager. */
955 fxn_chnl_destroy pfn_chnl_destroy; /* Destroy channel manager. */ 999 fxn_chnl_destroy pfn_chnl_destroy; /* Destroy channel manager. */
956 fxn_chnl_open pfn_chnl_open; /* Create a new channel. */ 1000 fxn_chnl_open pfn_chnl_open; /* Create a new channel. */
diff --git a/drivers/staging/tidspbridge/include/dspbridge/dspioctl.h b/drivers/staging/tidspbridge/include/dspbridge/dspioctl.h
index bad180108ada..41e0594dff34 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/dspioctl.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/dspioctl.h
@@ -19,6 +19,10 @@
19#ifndef DSPIOCTL_ 19#ifndef DSPIOCTL_
20#define DSPIOCTL_ 20#define DSPIOCTL_
21 21
22/* ------------------------------------ Hardware Abstraction Layer */
23#include <hw_defs.h>
24#include <hw_mmu.h>
25
22/* 26/*
23 * Any IOCTLS at or above this value are reserved for standard Bridge driver 27 * Any IOCTLS at or above this value are reserved for standard Bridge driver
24 * interfaces. 28 * interfaces.
@@ -61,6 +65,9 @@ struct bridge_ioctl_extproc {
61 /* GPP virtual address. __va does not work for ioremapped addresses */ 65 /* GPP virtual address. __va does not work for ioremapped addresses */
62 u32 ul_gpp_va; 66 u32 ul_gpp_va;
63 u32 ul_size; /* Size of the mapped memory in bytes */ 67 u32 ul_size; /* Size of the mapped memory in bytes */
68 enum hw_endianism_t endianism;
69 enum hw_mmu_mixed_size_t mixed_mode;
70 enum hw_element_size_t elem_size;
64}; 71};
65 72
66#endif /* DSPIOCTL_ */ 73#endif /* DSPIOCTL_ */
diff --git a/drivers/staging/tidspbridge/include/dspbridge/proc.h b/drivers/staging/tidspbridge/include/dspbridge/proc.h
index 2d12aab6b5bf..5e09fd165d9d 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/proc.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/proc.h
@@ -551,6 +551,29 @@ extern int proc_map(void *hprocessor,
551 struct process_context *pr_ctxt); 551 struct process_context *pr_ctxt);
552 552
553/* 553/*
554 * ======== proc_reserve_memory ========
555 * Purpose:
556 * Reserve a virtually contiguous region of DSP address space.
557 * Parameters:
558 * hprocessor : The processor handle.
559 * ul_size : Size of the address space to reserve.
560 * pp_rsv_addr : Ptr to DSP side reserved u8 address.
561 * Returns:
562 * 0 : Success.
563 * -EFAULT : Invalid processor handle.
564 * -EPERM : General failure.
565 * -ENOMEM : Cannot reserve chunk of this size.
566 * Requires:
567 * pp_rsv_addr is not NULL
568 * PROC Initialized.
569 * Ensures:
570 * Details:
571 */
572extern int proc_reserve_memory(void *hprocessor,
573 u32 ul_size, void **pp_rsv_addr,
574 struct process_context *pr_ctxt);
575
576/*
554 * ======== proc_un_map ======== 577 * ======== proc_un_map ========
555 * Purpose: 578 * Purpose:
556 * Removes a MPU buffer mapping from the DSP address space. 579 * Removes a MPU buffer mapping from the DSP address space.
@@ -572,4 +595,27 @@ extern int proc_map(void *hprocessor,
572extern int proc_un_map(void *hprocessor, void *map_addr, 595extern int proc_un_map(void *hprocessor, void *map_addr,
573 struct process_context *pr_ctxt); 596 struct process_context *pr_ctxt);
574 597
598/*
599 * ======== proc_un_reserve_memory ========
600 * Purpose:
601 * Frees a previously reserved region of DSP address space.
602 * Parameters:
603 * hprocessor : The processor handle.
604 * prsv_addr : Ptr to DSP side reservedBYTE address.
605 * Returns:
606 * 0 : Success.
607 * -EFAULT : Invalid processor handle.
608 * -EPERM : General failure.
609 * -ENOENT : Cannot find a reserved region starting with this
610 * : address.
611 * Requires:
612 * prsv_addr is not NULL
613 * PROC Initialized.
614 * Ensures:
615 * Details:
616 */
617extern int proc_un_reserve_memory(void *hprocessor,
618 void *prsv_addr,
619 struct process_context *pr_ctxt);
620
575#endif /* PROC_ */ 621#endif /* PROC_ */
diff --git a/drivers/staging/tidspbridge/pmgr/dev.c b/drivers/staging/tidspbridge/pmgr/dev.c
index 7b30267ef0e2..132e960967b9 100644
--- a/drivers/staging/tidspbridge/pmgr/dev.c
+++ b/drivers/staging/tidspbridge/pmgr/dev.c
@@ -34,6 +34,7 @@
34#include <dspbridge/cod.h> 34#include <dspbridge/cod.h>
35#include <dspbridge/drv.h> 35#include <dspbridge/drv.h>
36#include <dspbridge/proc.h> 36#include <dspbridge/proc.h>
37#include <dspbridge/dmm.h>
37 38
38/* ----------------------------------- Resource Manager */ 39/* ----------------------------------- Resource Manager */
39#include <dspbridge/mgr.h> 40#include <dspbridge/mgr.h>
@@ -74,6 +75,7 @@ struct dev_object {
74 struct msg_mgr *hmsg_mgr; /* Message manager. */ 75 struct msg_mgr *hmsg_mgr; /* Message manager. */
75 struct io_mgr *hio_mgr; /* IO manager (CHNL, msg_ctrl) */ 76 struct io_mgr *hio_mgr; /* IO manager (CHNL, msg_ctrl) */
76 struct cmm_object *hcmm_mgr; /* SM memory manager. */ 77 struct cmm_object *hcmm_mgr; /* SM memory manager. */
78 struct dmm_object *dmm_mgr; /* Dynamic memory manager. */
77 struct ldr_module *module_obj; /* Bridge Module handle. */ 79 struct ldr_module *module_obj; /* Bridge Module handle. */
78 u32 word_size; /* DSP word size: quick access. */ 80 u32 word_size; /* DSP word size: quick access. */
79 struct drv_object *hdrv_obj; /* Driver Object */ 81 struct drv_object *hdrv_obj; /* Driver Object */
@@ -248,6 +250,9 @@ int dev_create_device(struct dev_object **device_obj,
248 /* Instantiate the DEH module */ 250 /* Instantiate the DEH module */
249 status = bridge_deh_create(&dev_obj->hdeh_mgr, dev_obj); 251 status = bridge_deh_create(&dev_obj->hdeh_mgr, dev_obj);
250 } 252 }
253 /* Create DMM mgr . */
254 status = dmm_create(&dev_obj->dmm_mgr,
255 (struct dev_object *)dev_obj, NULL);
251 } 256 }
252 /* Add the new DEV_Object to the global list: */ 257 /* Add the new DEV_Object to the global list: */
253 if (!status) { 258 if (!status) {
@@ -273,6 +278,8 @@ leave:
273 kfree(dev_obj->proc_list); 278 kfree(dev_obj->proc_list);
274 if (dev_obj->cod_mgr) 279 if (dev_obj->cod_mgr)
275 cod_delete(dev_obj->cod_mgr); 280 cod_delete(dev_obj->cod_mgr);
281 if (dev_obj->dmm_mgr)
282 dmm_destroy(dev_obj->dmm_mgr);
276 kfree(dev_obj); 283 kfree(dev_obj);
277 } 284 }
278 285
@@ -382,6 +389,11 @@ int dev_destroy_device(struct dev_object *hdev_obj)
382 dev_obj->hcmm_mgr = NULL; 389 dev_obj->hcmm_mgr = NULL;
383 } 390 }
384 391
392 if (dev_obj->dmm_mgr) {
393 dmm_destroy(dev_obj->dmm_mgr);
394 dev_obj->dmm_mgr = NULL;
395 }
396
385 /* Call the driver's bridge_dev_destroy() function: */ 397 /* Call the driver's bridge_dev_destroy() function: */
386 /* Require of DevDestroy */ 398 /* Require of DevDestroy */
387 if (dev_obj->hbridge_context) { 399 if (dev_obj->hbridge_context) {
@@ -462,6 +474,32 @@ int dev_get_cmm_mgr(struct dev_object *hdev_obj,
462} 474}
463 475
464/* 476/*
477 * ======== dev_get_dmm_mgr ========
478 * Purpose:
479 * Retrieve the handle to the dynamic memory manager created for this
480 * device.
481 */
482int dev_get_dmm_mgr(struct dev_object *hdev_obj,
483 struct dmm_object **mgr)
484{
485 int status = 0;
486 struct dev_object *dev_obj = hdev_obj;
487
488 DBC_REQUIRE(refs > 0);
489 DBC_REQUIRE(mgr != NULL);
490
491 if (hdev_obj) {
492 *mgr = dev_obj->dmm_mgr;
493 } else {
494 *mgr = NULL;
495 status = -EFAULT;
496 }
497
498 DBC_ENSURE(!status || (mgr != NULL && *mgr == NULL));
499 return status;
500}
501
502/*
465 * ======== dev_get_cod_mgr ======== 503 * ======== dev_get_cod_mgr ========
466 * Purpose: 504 * Purpose:
467 * Retrieve the COD manager create for this device. 505 * Retrieve the COD manager create for this device.
@@ -713,8 +751,10 @@ void dev_exit(void)
713 751
714 refs--; 752 refs--;
715 753
716 if (refs == 0) 754 if (refs == 0) {
717 cmm_exit(); 755 cmm_exit();
756 dmm_exit();
757 }
718 758
719 DBC_ENSURE(refs >= 0); 759 DBC_ENSURE(refs >= 0);
720} 760}
@@ -726,12 +766,25 @@ void dev_exit(void)
726 */ 766 */
727bool dev_init(void) 767bool dev_init(void)
728{ 768{
729 bool ret = true; 769 bool cmm_ret, dmm_ret, ret = true;
730 770
731 DBC_REQUIRE(refs >= 0); 771 DBC_REQUIRE(refs >= 0);
732 772
733 if (refs == 0) 773 if (refs == 0) {
734 ret = cmm_init(); 774 cmm_ret = cmm_init();
775 dmm_ret = dmm_init();
776
777 ret = cmm_ret && dmm_ret;
778
779 if (!ret) {
780 if (cmm_ret)
781 cmm_exit();
782
783 if (dmm_ret)
784 dmm_exit();
785
786 }
787 }
735 788
736 if (ret) 789 if (ret)
737 refs++; 790 refs++;
@@ -1065,6 +1118,8 @@ static void store_interface_fxns(struct bridge_drv_interface *drv_fxns,
1065 STORE_FXN(fxn_brd_setstate, pfn_brd_set_state); 1118 STORE_FXN(fxn_brd_setstate, pfn_brd_set_state);
1066 STORE_FXN(fxn_brd_memcopy, pfn_brd_mem_copy); 1119 STORE_FXN(fxn_brd_memcopy, pfn_brd_mem_copy);
1067 STORE_FXN(fxn_brd_memwrite, pfn_brd_mem_write); 1120 STORE_FXN(fxn_brd_memwrite, pfn_brd_mem_write);
1121 STORE_FXN(fxn_brd_memmap, pfn_brd_mem_map);
1122 STORE_FXN(fxn_brd_memunmap, pfn_brd_mem_un_map);
1068 STORE_FXN(fxn_chnl_create, pfn_chnl_create); 1123 STORE_FXN(fxn_chnl_create, pfn_chnl_create);
1069 STORE_FXN(fxn_chnl_destroy, pfn_chnl_destroy); 1124 STORE_FXN(fxn_chnl_destroy, pfn_chnl_destroy);
1070 STORE_FXN(fxn_chnl_open, pfn_chnl_open); 1125 STORE_FXN(fxn_chnl_open, pfn_chnl_open);
diff --git a/drivers/staging/tidspbridge/pmgr/dmm.c b/drivers/staging/tidspbridge/pmgr/dmm.c
new file mode 100644
index 000000000000..8685233d7627
--- /dev/null
+++ b/drivers/staging/tidspbridge/pmgr/dmm.c
@@ -0,0 +1,533 @@
1/*
2 * dmm.c
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * The Dynamic Memory Manager (DMM) module manages the DSP Virtual address
7 * space that can be directly mapped to any MPU buffer or memory region
8 *
9 * Notes:
10 * Region: Generic memory entitiy having a start address and a size
11 * Chunk: Reserved region
12 *
13 * Copyright (C) 2005-2006 Texas Instruments, Inc.
14 *
15 * This package is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License version 2 as
17 * published by the Free Software Foundation.
18 *
19 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
21 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23#include <linux/types.h>
24
25/* ----------------------------------- Host OS */
26#include <dspbridge/host_os.h>
27
28/* ----------------------------------- DSP/BIOS Bridge */
29#include <dspbridge/dbdefs.h>
30
31/* ----------------------------------- Trace & Debug */
32#include <dspbridge/dbc.h>
33
34/* ----------------------------------- OS Adaptation Layer */
35#include <dspbridge/sync.h>
36
37/* ----------------------------------- Platform Manager */
38#include <dspbridge/dev.h>
39#include <dspbridge/proc.h>
40
41/* ----------------------------------- This */
42#include <dspbridge/dmm.h>
43
44/* ----------------------------------- Defines, Data Structures, Typedefs */
45#define DMM_ADDR_VIRTUAL(a) \
46 (((struct map_page *)(a) - virtual_mapping_table) * PG_SIZE4K +\
47 dyn_mem_map_beg)
48#define DMM_ADDR_TO_INDEX(a) (((a) - dyn_mem_map_beg) / PG_SIZE4K)
49
50/* DMM Mgr */
51struct dmm_object {
52 /* Dmm Lock is used to serialize access mem manager for
53 * multi-threads. */
54 spinlock_t dmm_lock; /* Lock to access dmm mgr */
55};
56
57/* ----------------------------------- Globals */
58static u32 refs; /* module reference count */
59struct map_page {
60 u32 region_size:15;
61 u32 mapped_size:15;
62 u32 reserved:1;
63 u32 mapped:1;
64};
65
66/* Create the free list */
67static struct map_page *virtual_mapping_table;
68static u32 free_region; /* The index of free region */
69static u32 free_size;
70static u32 dyn_mem_map_beg; /* The Beginning of dynamic memory mapping */
71static u32 table_size; /* The size of virt and phys pages tables */
72
73/* ----------------------------------- Function Prototypes */
74static struct map_page *get_region(u32 addr);
75static struct map_page *get_free_region(u32 len);
76static struct map_page *get_mapped_region(u32 addrs);
77
78/* ======== dmm_create_tables ========
79 * Purpose:
80 * Create table to hold the information of physical address
81 * the buffer pages that is passed by the user, and the table
82 * to hold the information of the virtual memory that is reserved
83 * for DSP.
84 */
85int dmm_create_tables(struct dmm_object *dmm_mgr, u32 addr, u32 size)
86{
87 struct dmm_object *dmm_obj = (struct dmm_object *)dmm_mgr;
88 int status = 0;
89
90 status = dmm_delete_tables(dmm_obj);
91 if (!status) {
92 dyn_mem_map_beg = addr;
93 table_size = PG_ALIGN_HIGH(size, PG_SIZE4K) / PG_SIZE4K;
94 /* Create the free list */
95 virtual_mapping_table = __vmalloc(table_size *
96 sizeof(struct map_page), GFP_KERNEL |
97 __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
98 if (virtual_mapping_table == NULL)
99 status = -ENOMEM;
100 else {
101 /* On successful allocation,
102 * all entries are zero ('free') */
103 free_region = 0;
104 free_size = table_size * PG_SIZE4K;
105 virtual_mapping_table[0].region_size = table_size;
106 }
107 }
108
109 if (status)
110 pr_err("%s: failure, status 0x%x\n", __func__, status);
111
112 return status;
113}
114
115/*
116 * ======== dmm_create ========
117 * Purpose:
118 * Create a dynamic memory manager object.
119 */
120int dmm_create(struct dmm_object **dmm_manager,
121 struct dev_object *hdev_obj,
122 const struct dmm_mgrattrs *mgr_attrts)
123{
124 struct dmm_object *dmm_obj = NULL;
125 int status = 0;
126 DBC_REQUIRE(refs > 0);
127 DBC_REQUIRE(dmm_manager != NULL);
128
129 *dmm_manager = NULL;
130 /* create, zero, and tag a cmm mgr object */
131 dmm_obj = kzalloc(sizeof(struct dmm_object), GFP_KERNEL);
132 if (dmm_obj != NULL) {
133 spin_lock_init(&dmm_obj->dmm_lock);
134 *dmm_manager = dmm_obj;
135 } else {
136 status = -ENOMEM;
137 }
138
139 return status;
140}
141
142/*
143 * ======== dmm_destroy ========
144 * Purpose:
145 * Release the communication memory manager resources.
146 */
147int dmm_destroy(struct dmm_object *dmm_mgr)
148{
149 struct dmm_object *dmm_obj = (struct dmm_object *)dmm_mgr;
150 int status = 0;
151
152 DBC_REQUIRE(refs > 0);
153 if (dmm_mgr) {
154 status = dmm_delete_tables(dmm_obj);
155 if (!status)
156 kfree(dmm_obj);
157 } else
158 status = -EFAULT;
159
160 return status;
161}
162
163/*
164 * ======== dmm_delete_tables ========
165 * Purpose:
166 * Delete DMM Tables.
167 */
168int dmm_delete_tables(struct dmm_object *dmm_mgr)
169{
170 int status = 0;
171
172 DBC_REQUIRE(refs > 0);
173 /* Delete all DMM tables */
174 if (dmm_mgr)
175 vfree(virtual_mapping_table);
176 else
177 status = -EFAULT;
178 return status;
179}
180
181/*
182 * ======== dmm_exit ========
183 * Purpose:
184 * Discontinue usage of module; free resources when reference count
185 * reaches 0.
186 */
187void dmm_exit(void)
188{
189 DBC_REQUIRE(refs > 0);
190
191 refs--;
192}
193
194/*
195 * ======== dmm_get_handle ========
196 * Purpose:
197 * Return the dynamic memory manager object for this device.
198 * This is typically called from the client process.
199 */
200int dmm_get_handle(void *hprocessor, struct dmm_object **dmm_manager)
201{
202 int status = 0;
203 struct dev_object *hdev_obj;
204
205 DBC_REQUIRE(refs > 0);
206 DBC_REQUIRE(dmm_manager != NULL);
207 if (hprocessor != NULL)
208 status = proc_get_dev_object(hprocessor, &hdev_obj);
209 else
210 hdev_obj = dev_get_first(); /* default */
211
212 if (!status)
213 status = dev_get_dmm_mgr(hdev_obj, dmm_manager);
214
215 return status;
216}
217
218/*
219 * ======== dmm_init ========
220 * Purpose:
221 * Initializes private state of DMM module.
222 */
223bool dmm_init(void)
224{
225 bool ret = true;
226
227 DBC_REQUIRE(refs >= 0);
228
229 if (ret)
230 refs++;
231
232 DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0)));
233
234 virtual_mapping_table = NULL;
235 table_size = 0;
236
237 return ret;
238}
239
240/*
241 * ======== dmm_map_memory ========
242 * Purpose:
243 * Add a mapping block to the reserved chunk. DMM assumes that this block
244 * will be mapped in the DSP/IVA's address space. DMM returns an error if a
245 * mapping overlaps another one. This function stores the info that will be
246 * required later while unmapping the block.
247 */
248int dmm_map_memory(struct dmm_object *dmm_mgr, u32 addr, u32 size)
249{
250 struct dmm_object *dmm_obj = (struct dmm_object *)dmm_mgr;
251 struct map_page *chunk;
252 int status = 0;
253
254 spin_lock(&dmm_obj->dmm_lock);
255 /* Find the Reserved memory chunk containing the DSP block to
256 * be mapped */
257 chunk = (struct map_page *)get_region(addr);
258 if (chunk != NULL) {
259 /* Mark the region 'mapped', leave the 'reserved' info as-is */
260 chunk->mapped = true;
261 chunk->mapped_size = (size / PG_SIZE4K);
262 } else
263 status = -ENOENT;
264 spin_unlock(&dmm_obj->dmm_lock);
265
266 dev_dbg(bridge, "%s dmm_mgr %p, addr %x, size %x\n\tstatus %x, "
267 "chunk %p", __func__, dmm_mgr, addr, size, status, chunk);
268
269 return status;
270}
271
272/*
273 * ======== dmm_reserve_memory ========
274 * Purpose:
275 * Reserve a chunk of virtually contiguous DSP/IVA address space.
276 */
277int dmm_reserve_memory(struct dmm_object *dmm_mgr, u32 size,
278 u32 *prsv_addr)
279{
280 int status = 0;
281 struct dmm_object *dmm_obj = (struct dmm_object *)dmm_mgr;
282 struct map_page *node;
283 u32 rsv_addr = 0;
284 u32 rsv_size = 0;
285
286 spin_lock(&dmm_obj->dmm_lock);
287
288 /* Try to get a DSP chunk from the free list */
289 node = get_free_region(size);
290 if (node != NULL) {
291 /* DSP chunk of given size is available. */
292 rsv_addr = DMM_ADDR_VIRTUAL(node);
293 /* Calculate the number entries to use */
294 rsv_size = size / PG_SIZE4K;
295 if (rsv_size < node->region_size) {
296 /* Mark remainder of free region */
297 node[rsv_size].mapped = false;
298 node[rsv_size].reserved = false;
299 node[rsv_size].region_size =
300 node->region_size - rsv_size;
301 node[rsv_size].mapped_size = 0;
302 }
303 /* get_region will return first fit chunk. But we only use what
304 is requested. */
305 node->mapped = false;
306 node->reserved = true;
307 node->region_size = rsv_size;
308 node->mapped_size = 0;
309 /* Return the chunk's starting address */
310 *prsv_addr = rsv_addr;
311 } else
312 /*dSP chunk of given size is not available */
313 status = -ENOMEM;
314
315 spin_unlock(&dmm_obj->dmm_lock);
316
317 dev_dbg(bridge, "%s dmm_mgr %p, size %x, prsv_addr %p\n\tstatus %x, "
318 "rsv_addr %x, rsv_size %x\n", __func__, dmm_mgr, size,
319 prsv_addr, status, rsv_addr, rsv_size);
320
321 return status;
322}
323
324/*
325 * ======== dmm_un_map_memory ========
326 * Purpose:
327 * Remove the mapped block from the reserved chunk.
328 */
329int dmm_un_map_memory(struct dmm_object *dmm_mgr, u32 addr, u32 *psize)
330{
331 struct dmm_object *dmm_obj = (struct dmm_object *)dmm_mgr;
332 struct map_page *chunk;
333 int status = 0;
334
335 spin_lock(&dmm_obj->dmm_lock);
336 chunk = get_mapped_region(addr);
337 if (chunk == NULL)
338 status = -ENOENT;
339
340 if (!status) {
341 /* Unmap the region */
342 *psize = chunk->mapped_size * PG_SIZE4K;
343 chunk->mapped = false;
344 chunk->mapped_size = 0;
345 }
346 spin_unlock(&dmm_obj->dmm_lock);
347
348 dev_dbg(bridge, "%s: dmm_mgr %p, addr %x, psize %p\n\tstatus %x, "
349 "chunk %p\n", __func__, dmm_mgr, addr, psize, status, chunk);
350
351 return status;
352}
353
354/*
355 * ======== dmm_un_reserve_memory ========
356 * Purpose:
357 * Free a chunk of reserved DSP/IVA address space.
358 */
359int dmm_un_reserve_memory(struct dmm_object *dmm_mgr, u32 rsv_addr)
360{
361 struct dmm_object *dmm_obj = (struct dmm_object *)dmm_mgr;
362 struct map_page *chunk;
363 u32 i;
364 int status = 0;
365 u32 chunk_size;
366
367 spin_lock(&dmm_obj->dmm_lock);
368
369 /* Find the chunk containing the reserved address */
370 chunk = get_mapped_region(rsv_addr);
371 if (chunk == NULL)
372 status = -ENOENT;
373
374 if (!status) {
375 /* Free all the mapped pages for this reserved region */
376 i = 0;
377 while (i < chunk->region_size) {
378 if (chunk[i].mapped) {
379 /* Remove mapping from the page tables. */
380 chunk_size = chunk[i].mapped_size;
381 /* Clear the mapping flags */
382 chunk[i].mapped = false;
383 chunk[i].mapped_size = 0;
384 i += chunk_size;
385 } else
386 i++;
387 }
388 /* Clear the flags (mark the region 'free') */
389 chunk->reserved = false;
390 /* NOTE: We do NOT coalesce free regions here.
391 * Free regions are coalesced in get_region(), as it traverses
392 *the whole mapping table
393 */
394 }
395 spin_unlock(&dmm_obj->dmm_lock);
396
397 dev_dbg(bridge, "%s: dmm_mgr %p, rsv_addr %x\n\tstatus %x chunk %p",
398 __func__, dmm_mgr, rsv_addr, status, chunk);
399
400 return status;
401}
402
403/*
404 * ======== get_region ========
405 * Purpose:
406 * Returns a region containing the specified memory region
407 */
408static struct map_page *get_region(u32 addr)
409{
410 struct map_page *curr_region = NULL;
411 u32 i = 0;
412
413 if (virtual_mapping_table != NULL) {
414 /* find page mapped by this address */
415 i = DMM_ADDR_TO_INDEX(addr);
416 if (i < table_size)
417 curr_region = virtual_mapping_table + i;
418 }
419
420 dev_dbg(bridge, "%s: curr_region %p, free_region %d, free_size %d\n",
421 __func__, curr_region, free_region, free_size);
422 return curr_region;
423}
424
425/*
426 * ======== get_free_region ========
427 * Purpose:
428 * Returns the requested free region
429 */
430static struct map_page *get_free_region(u32 len)
431{
432 struct map_page *curr_region = NULL;
433 u32 i = 0;
434 u32 region_size = 0;
435 u32 next_i = 0;
436
437 if (virtual_mapping_table == NULL)
438 return curr_region;
439 if (len > free_size) {
440 /* Find the largest free region
441 * (coalesce during the traversal) */
442 while (i < table_size) {
443 region_size = virtual_mapping_table[i].region_size;
444 next_i = i + region_size;
445 if (virtual_mapping_table[i].reserved == false) {
446 /* Coalesce, if possible */
447 if (next_i < table_size &&
448 virtual_mapping_table[next_i].reserved
449 == false) {
450 virtual_mapping_table[i].region_size +=
451 virtual_mapping_table
452 [next_i].region_size;
453 continue;
454 }
455 region_size *= PG_SIZE4K;
456 if (region_size > free_size) {
457 free_region = i;
458 free_size = region_size;
459 }
460 }
461 i = next_i;
462 }
463 }
464 if (len <= free_size) {
465 curr_region = virtual_mapping_table + free_region;
466 free_region += (len / PG_SIZE4K);
467 free_size -= len;
468 }
469 return curr_region;
470}
471
472/*
473 * ======== get_mapped_region ========
474 * Purpose:
475 * Returns the requestedmapped region
476 */
477static struct map_page *get_mapped_region(u32 addrs)
478{
479 u32 i = 0;
480 struct map_page *curr_region = NULL;
481
482 if (virtual_mapping_table == NULL)
483 return curr_region;
484
485 i = DMM_ADDR_TO_INDEX(addrs);
486 if (i < table_size && (virtual_mapping_table[i].mapped ||
487 virtual_mapping_table[i].reserved))
488 curr_region = virtual_mapping_table + i;
489 return curr_region;
490}
491
492#ifdef DSP_DMM_DEBUG
493u32 dmm_mem_map_dump(struct dmm_object *dmm_mgr)
494{
495 struct map_page *curr_node = NULL;
496 u32 i;
497 u32 freemem = 0;
498 u32 bigsize = 0;
499
500 spin_lock(&dmm_mgr->dmm_lock);
501
502 if (virtual_mapping_table != NULL) {
503 for (i = 0; i < table_size; i +=
504 virtual_mapping_table[i].region_size) {
505 curr_node = virtual_mapping_table + i;
506 if (curr_node->reserved) {
507 /*printk("RESERVED size = 0x%x, "
508 "Map size = 0x%x\n",
509 (curr_node->region_size * PG_SIZE4K),
510 (curr_node->mapped == false) ? 0 :
511 (curr_node->mapped_size * PG_SIZE4K));
512 */
513 } else {
514/* printk("UNRESERVED size = 0x%x\n",
515 (curr_node->region_size * PG_SIZE4K));
516 */
517 freemem += (curr_node->region_size * PG_SIZE4K);
518 if (curr_node->region_size > bigsize)
519 bigsize = curr_node->region_size;
520 }
521 }
522 }
523 spin_unlock(&dmm_mgr->dmm_lock);
524 printk(KERN_INFO "Total DSP VA FREE memory = %d Mbytes\n",
525 freemem / (1024 * 1024));
526 printk(KERN_INFO "Total DSP VA USED memory= %d Mbytes \n",
527 (((table_size * PG_SIZE4K) - freemem)) / (1024 * 1024));
528 printk(KERN_INFO "DSP VA - Biggest FREE block = %d Mbytes \n\n",
529 (bigsize * PG_SIZE4K / (1024 * 1024)));
530
531 return 0;
532}
533#endif
diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index 981551ce4d78..86ca785f1913 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -993,10 +993,27 @@ u32 procwrap_register_notify(union trapped_args *args, void *pr_ctxt)
993/* 993/*
994 * ======== procwrap_reserve_memory ======== 994 * ======== procwrap_reserve_memory ========
995 */ 995 */
996u32 __deprecated procwrap_reserve_memory(union trapped_args *args, 996u32 procwrap_reserve_memory(union trapped_args *args, void *pr_ctxt)
997 void *pr_ctxt)
998{ 997{
999 return 0; 998 int status;
999 void *prsv_addr;
1000 void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
1001
1002 if ((args->args_proc_rsvmem.ul_size <= 0) ||
1003 (args->args_proc_rsvmem.ul_size & (PG_SIZE4K - 1)) != 0)
1004 return -EINVAL;
1005
1006 status = proc_reserve_memory(hprocessor,
1007 args->args_proc_rsvmem.ul_size, &prsv_addr,
1008 pr_ctxt);
1009 if (!status) {
1010 if (put_user(prsv_addr, args->args_proc_rsvmem.pp_rsv_addr)) {
1011 status = -EINVAL;
1012 proc_un_reserve_memory(args->args_proc_rsvmem.
1013 hprocessor, prsv_addr, pr_ctxt);
1014 }
1015 }
1016 return status;
1000} 1017}
1001 1018
1002/* 1019/*
@@ -1025,10 +1042,15 @@ u32 procwrap_un_map(union trapped_args *args, void *pr_ctxt)
1025/* 1042/*
1026 * ======== procwrap_un_reserve_memory ======== 1043 * ======== procwrap_un_reserve_memory ========
1027 */ 1044 */
1028u32 __deprecated procwrap_un_reserve_memory(union trapped_args *args, 1045u32 procwrap_un_reserve_memory(union trapped_args *args, void *pr_ctxt)
1029 void *pr_ctxt)
1030{ 1046{
1031 return 0; 1047 int status;
1048 void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
1049
1050 status = proc_un_reserve_memory(hprocessor,
1051 args->args_proc_unrsvmem.prsv_addr,
1052 pr_ctxt);
1053 return status;
1032} 1054}
1033 1055
1034/* 1056/*
diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
index 91cc168516e5..81b1b9013550 100644
--- a/drivers/staging/tidspbridge/rmgr/drv.c
+++ b/drivers/staging/tidspbridge/rmgr/drv.c
@@ -146,6 +146,7 @@ int drv_remove_all_dmm_res_elements(void *process_ctxt)
146 struct process_context *ctxt = (struct process_context *)process_ctxt; 146 struct process_context *ctxt = (struct process_context *)process_ctxt;
147 int status = 0; 147 int status = 0;
148 struct dmm_map_object *temp_map, *map_obj; 148 struct dmm_map_object *temp_map, *map_obj;
149 struct dmm_rsv_object *temp_rsv, *rsv_obj;
149 150
150 /* Free DMM mapped memory resources */ 151 /* Free DMM mapped memory resources */
151 list_for_each_entry_safe(map_obj, temp_map, &ctxt->dmm_map_list, link) { 152 list_for_each_entry_safe(map_obj, temp_map, &ctxt->dmm_map_list, link) {
@@ -155,6 +156,16 @@ int drv_remove_all_dmm_res_elements(void *process_ctxt)
155 pr_err("%s: proc_un_map failed!" 156 pr_err("%s: proc_un_map failed!"
156 " status = 0x%xn", __func__, status); 157 " status = 0x%xn", __func__, status);
157 } 158 }
159
160 /* Free DMM reserved memory resources */
161 list_for_each_entry_safe(rsv_obj, temp_rsv, &ctxt->dmm_rsv_list, link) {
162 status = proc_un_reserve_memory(ctxt->hprocessor, (void *)
163 rsv_obj->dsp_reserved_addr,
164 ctxt);
165 if (status)
166 pr_err("%s: proc_un_reserve_memory failed!"
167 " status = 0x%xn", __func__, status);
168 }
158 return status; 169 return status;
159} 170}
160 171
@@ -732,6 +743,7 @@ static int request_bridge_resources(struct cfg_hostres *res)
732 host_res->dw_sys_ctrl_base = ioremap(OMAP_SYSC_BASE, OMAP_SYSC_SIZE); 743 host_res->dw_sys_ctrl_base = ioremap(OMAP_SYSC_BASE, OMAP_SYSC_SIZE);
733 dev_dbg(bridge, "dw_mem_base[0] 0x%x\n", host_res->dw_mem_base[0]); 744 dev_dbg(bridge, "dw_mem_base[0] 0x%x\n", host_res->dw_mem_base[0]);
734 dev_dbg(bridge, "dw_mem_base[3] 0x%x\n", host_res->dw_mem_base[3]); 745 dev_dbg(bridge, "dw_mem_base[3] 0x%x\n", host_res->dw_mem_base[3]);
746 dev_dbg(bridge, "dw_dmmu_base %p\n", host_res->dw_dmmu_base);
735 747
736 /* for 24xx base port is not mapping the mamory for DSP 748 /* for 24xx base port is not mapping the mamory for DSP
737 * internal memory TODO Do a ioremap here */ 749 * internal memory TODO Do a ioremap here */
@@ -785,6 +797,8 @@ int drv_request_bridge_res_dsp(void **phost_resources)
785 OMAP_PER_PRM_SIZE); 797 OMAP_PER_PRM_SIZE);
786 host_res->dw_core_pm_base = (u32) ioremap(OMAP_CORE_PRM_BASE, 798 host_res->dw_core_pm_base = (u32) ioremap(OMAP_CORE_PRM_BASE,
787 OMAP_CORE_PRM_SIZE); 799 OMAP_CORE_PRM_SIZE);
800 host_res->dw_dmmu_base = ioremap(OMAP_DMMU_BASE,
801 OMAP_DMMU_SIZE);
788 802
789 dev_dbg(bridge, "dw_mem_base[0] 0x%x\n", 803 dev_dbg(bridge, "dw_mem_base[0] 0x%x\n",
790 host_res->dw_mem_base[0]); 804 host_res->dw_mem_base[0]);
@@ -796,6 +810,7 @@ int drv_request_bridge_res_dsp(void **phost_resources)
796 host_res->dw_mem_base[3]); 810 host_res->dw_mem_base[3]);
797 dev_dbg(bridge, "dw_mem_base[4] 0x%x\n", 811 dev_dbg(bridge, "dw_mem_base[4] 0x%x\n",
798 host_res->dw_mem_base[4]); 812 host_res->dw_mem_base[4]);
813 dev_dbg(bridge, "dw_dmmu_base %p\n", host_res->dw_dmmu_base);
799 814
800 shm_size = drv_datap->shm_size; 815 shm_size = drv_datap->shm_size;
801 if (shm_size >= 0x10000) { 816 if (shm_size >= 0x10000) {
diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c
index 34be43fec044..324fcdffb3b3 100644
--- a/drivers/staging/tidspbridge/rmgr/drv_interface.c
+++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c
@@ -509,6 +509,8 @@ static int bridge_open(struct inode *ip, struct file *filp)
509 pr_ctxt->res_state = PROC_RES_ALLOCATED; 509 pr_ctxt->res_state = PROC_RES_ALLOCATED;
510 spin_lock_init(&pr_ctxt->dmm_map_lock); 510 spin_lock_init(&pr_ctxt->dmm_map_lock);
511 INIT_LIST_HEAD(&pr_ctxt->dmm_map_list); 511 INIT_LIST_HEAD(&pr_ctxt->dmm_map_list);
512 spin_lock_init(&pr_ctxt->dmm_rsv_lock);
513 INIT_LIST_HEAD(&pr_ctxt->dmm_rsv_list);
512 514
513 pr_ctxt->node_id = kzalloc(sizeof(struct idr), GFP_KERNEL); 515 pr_ctxt->node_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
514 if (pr_ctxt->node_id) { 516 if (pr_ctxt->node_id) {
diff --git a/drivers/staging/tidspbridge/rmgr/node.c b/drivers/staging/tidspbridge/rmgr/node.c
index a660247f527a..1562f3c1281c 100644
--- a/drivers/staging/tidspbridge/rmgr/node.c
+++ b/drivers/staging/tidspbridge/rmgr/node.c
@@ -56,6 +56,7 @@
56/* ----------------------------------- This */ 56/* ----------------------------------- This */
57#include <dspbridge/nodepriv.h> 57#include <dspbridge/nodepriv.h>
58#include <dspbridge/node.h> 58#include <dspbridge/node.h>
59#include <dspbridge/dmm.h>
59 60
60/* Static/Dynamic Loader includes */ 61/* Static/Dynamic Loader includes */
61#include <dspbridge/dbll.h> 62#include <dspbridge/dbll.h>
@@ -316,6 +317,10 @@ int node_allocate(struct proc_object *hprocessor,
316 u32 mapped_addr = 0; 317 u32 mapped_addr = 0;
317 u32 map_attrs = 0x0; 318 u32 map_attrs = 0x0;
318 struct dsp_processorstate proc_state; 319 struct dsp_processorstate proc_state;
320#ifdef DSP_DMM_DEBUG
321 struct dmm_object *dmm_mgr;
322 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
323#endif
319 324
320 void *node_res; 325 void *node_res;
321 326
@@ -425,12 +430,34 @@ int node_allocate(struct proc_object *hprocessor,
425 if (status) 430 if (status)
426 goto func_cont; 431 goto func_cont;
427 432
433 status = proc_reserve_memory(hprocessor,
434 pnode->create_args.asa.task_arg_obj.
435 heap_size + PAGE_SIZE,
436 (void **)&(pnode->create_args.asa.
437 task_arg_obj.udsp_heap_res_addr),
438 pr_ctxt);
439 if (status) {
440 pr_err("%s: Failed to reserve memory for heap: 0x%x\n",
441 __func__, status);
442 goto func_cont;
443 }
444#ifdef DSP_DMM_DEBUG
445 status = dmm_get_handle(p_proc_object, &dmm_mgr);
446 if (!dmm_mgr) {
447 status = DSP_EHANDLE;
448 goto func_cont;
449 }
450
451 dmm_mem_map_dump(dmm_mgr);
452#endif
453
428 map_attrs |= DSP_MAPLITTLEENDIAN; 454 map_attrs |= DSP_MAPLITTLEENDIAN;
429 map_attrs |= DSP_MAPELEMSIZE32; 455 map_attrs |= DSP_MAPELEMSIZE32;
430 map_attrs |= DSP_MAPVIRTUALADDR; 456 map_attrs |= DSP_MAPVIRTUALADDR;
431 status = proc_map(hprocessor, (void *)attr_in->pgpp_virt_addr, 457 status = proc_map(hprocessor, (void *)attr_in->pgpp_virt_addr,
432 pnode->create_args.asa.task_arg_obj.heap_size, 458 pnode->create_args.asa.task_arg_obj.heap_size,
433 NULL, (void **)&mapped_addr, map_attrs, 459 (void *)pnode->create_args.asa.task_arg_obj.
460 udsp_heap_res_addr, (void **)&mapped_addr, map_attrs,
434 pr_ctxt); 461 pr_ctxt);
435 if (status) 462 if (status)
436 pr_err("%s: Failed to map memory for Heap: 0x%x\n", 463 pr_err("%s: Failed to map memory for Heap: 0x%x\n",
@@ -2484,7 +2511,11 @@ static void delete_node(struct node_object *hnode,
2484 struct stream_chnl stream; 2511 struct stream_chnl stream;
2485 struct node_msgargs node_msg_args; 2512 struct node_msgargs node_msg_args;
2486 struct node_taskargs task_arg_obj; 2513 struct node_taskargs task_arg_obj;
2487 2514#ifdef DSP_DMM_DEBUG
2515 struct dmm_object *dmm_mgr;
2516 struct proc_object *p_proc_object =
2517 (struct proc_object *)hnode->hprocessor;
2518#endif
2488 int status; 2519 int status;
2489 if (!hnode) 2520 if (!hnode)
2490 goto func_end; 2521 goto func_end;
@@ -2545,6 +2576,19 @@ static void delete_node(struct node_object *hnode,
2545 status = proc_un_map(hnode->hprocessor, (void *) 2576 status = proc_un_map(hnode->hprocessor, (void *)
2546 task_arg_obj.udsp_heap_addr, 2577 task_arg_obj.udsp_heap_addr,
2547 pr_ctxt); 2578 pr_ctxt);
2579
2580 status = proc_un_reserve_memory(hnode->hprocessor,
2581 (void *)
2582 task_arg_obj.
2583 udsp_heap_res_addr,
2584 pr_ctxt);
2585#ifdef DSP_DMM_DEBUG
2586 status = dmm_get_handle(p_proc_object, &dmm_mgr);
2587 if (dmm_mgr)
2588 dmm_mem_map_dump(dmm_mgr);
2589 else
2590 status = DSP_EHANDLE;
2591#endif
2548 } 2592 }
2549 } 2593 }
2550 if (node_type != NODE_MESSAGE) { 2594 if (node_type != NODE_MESSAGE) {
diff --git a/drivers/staging/tidspbridge/rmgr/proc.c b/drivers/staging/tidspbridge/rmgr/proc.c
index 7a15a02efedf..b47d7aa747b1 100644
--- a/drivers/staging/tidspbridge/rmgr/proc.c
+++ b/drivers/staging/tidspbridge/rmgr/proc.c
@@ -39,6 +39,7 @@
39#include <dspbridge/cod.h> 39#include <dspbridge/cod.h>
40#include <dspbridge/dev.h> 40#include <dspbridge/dev.h>
41#include <dspbridge/procpriv.h> 41#include <dspbridge/procpriv.h>
42#include <dspbridge/dmm.h>
42 43
43/* ----------------------------------- Resource Manager */ 44/* ----------------------------------- Resource Manager */
44#include <dspbridge/mgr.h> 45#include <dspbridge/mgr.h>
@@ -51,7 +52,6 @@
51#include <dspbridge/msg.h> 52#include <dspbridge/msg.h>
52#include <dspbridge/dspioctl.h> 53#include <dspbridge/dspioctl.h>
53#include <dspbridge/drv.h> 54#include <dspbridge/drv.h>
54#include <_tiomap.h>
55 55
56/* ----------------------------------- This */ 56/* ----------------------------------- This */
57#include <dspbridge/proc.h> 57#include <dspbridge/proc.h>
@@ -151,21 +151,34 @@ static struct dmm_map_object *add_mapping_info(struct process_context *pr_ctxt,
151 return map_obj; 151 return map_obj;
152} 152}
153 153
154static int match_exact_map_obj(struct dmm_map_object *map_obj,
155 u32 dsp_addr, u32 size)
156{
157 if (map_obj->dsp_addr == dsp_addr && map_obj->size != size)
158 pr_err("%s: addr match (0x%x), size don't (0x%x != 0x%x)\n",
159 __func__, dsp_addr, map_obj->size, size);
160
161 return map_obj->dsp_addr == dsp_addr &&
162 map_obj->size == size;
163}
164
154static void remove_mapping_information(struct process_context *pr_ctxt, 165static void remove_mapping_information(struct process_context *pr_ctxt,
155 u32 dsp_addr) 166 u32 dsp_addr, u32 size)
156{ 167{
157 struct dmm_map_object *map_obj; 168 struct dmm_map_object *map_obj;
158 169
159 pr_debug("%s: looking for virt 0x%x\n", __func__, dsp_addr); 170 pr_debug("%s: looking for virt 0x%x size 0x%x\n", __func__,
171 dsp_addr, size);
160 172
161 spin_lock(&pr_ctxt->dmm_map_lock); 173 spin_lock(&pr_ctxt->dmm_map_lock);
162 list_for_each_entry(map_obj, &pr_ctxt->dmm_map_list, link) { 174 list_for_each_entry(map_obj, &pr_ctxt->dmm_map_list, link) {
163 pr_debug("%s: candidate: mpu_addr 0x%x virt 0x%x\n", 175 pr_debug("%s: candidate: mpu_addr 0x%x virt 0x%x size 0x%x\n",
164 __func__, 176 __func__,
165 map_obj->mpu_addr, 177 map_obj->mpu_addr,
166 map_obj->dsp_addr); 178 map_obj->dsp_addr,
179 map_obj->size);
167 180
168 if (map_obj->dsp_addr == dsp_addr) { 181 if (match_exact_map_obj(map_obj, dsp_addr, size)) {
169 pr_debug("%s: match, deleting map info\n", __func__); 182 pr_debug("%s: match, deleting map info\n", __func__);
170 list_del(&map_obj->link); 183 list_del(&map_obj->link);
171 kfree(map_obj->dma_info.sg); 184 kfree(map_obj->dma_info.sg);
@@ -1077,6 +1090,7 @@ int proc_load(void *hprocessor, const s32 argc_index,
1077 s32 cnew_envp; /* " " in new_envp[] */ 1090 s32 cnew_envp; /* " " in new_envp[] */
1078 s32 nproc_id = 0; /* Anticipate MP version. */ 1091 s32 nproc_id = 0; /* Anticipate MP version. */
1079 struct dcd_manager *hdcd_handle; 1092 struct dcd_manager *hdcd_handle;
1093 struct dmm_object *dmm_mgr;
1080 u32 dw_ext_end; 1094 u32 dw_ext_end;
1081 u32 proc_id; 1095 u32 proc_id;
1082 int brd_state; 1096 int brd_state;
@@ -1267,6 +1281,25 @@ int proc_load(void *hprocessor, const s32 argc_index,
1267 if (!status) 1281 if (!status)
1268 status = cod_get_sym_value(cod_mgr, EXTEND, 1282 status = cod_get_sym_value(cod_mgr, EXTEND,
1269 &dw_ext_end); 1283 &dw_ext_end);
1284
1285 /* Reset DMM structs and add an initial free chunk */
1286 if (!status) {
1287 status =
1288 dev_get_dmm_mgr(p_proc_object->hdev_obj,
1289 &dmm_mgr);
1290 if (dmm_mgr) {
1291 /* Set dw_ext_end to DMM START u8
1292 * address */
1293 dw_ext_end =
1294 (dw_ext_end + 1) * DSPWORDSIZE;
1295 /* DMM memory is from EXT_END */
1296 status = dmm_create_tables(dmm_mgr,
1297 dw_ext_end,
1298 DMMPOOLSIZE);
1299 } else {
1300 status = -EFAULT;
1301 }
1302 }
1270 } 1303 }
1271 } 1304 }
1272 /* Restore the original argv[0] */ 1305 /* Restore the original argv[0] */
@@ -1319,10 +1352,12 @@ int proc_map(void *hprocessor, void *pmpu_addr, u32 ul_size,
1319{ 1352{
1320 u32 va_align; 1353 u32 va_align;
1321 u32 pa_align; 1354 u32 pa_align;
1355 struct dmm_object *dmm_mgr;
1322 u32 size_align; 1356 u32 size_align;
1323 int status = 0; 1357 int status = 0;
1324 struct proc_object *p_proc_object = (struct proc_object *)hprocessor; 1358 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1325 struct dmm_map_object *map_obj; 1359 struct dmm_map_object *map_obj;
1360 u32 tmp_addr = 0;
1326 1361
1327#ifdef CONFIG_TIDSPBRIDGE_CACHE_LINE_CHECK 1362#ifdef CONFIG_TIDSPBRIDGE_CACHE_LINE_CHECK
1328 if ((ul_map_attr & BUFMODE_MASK) != RBUF) { 1363 if ((ul_map_attr & BUFMODE_MASK) != RBUF) {
@@ -1347,30 +1382,33 @@ int proc_map(void *hprocessor, void *pmpu_addr, u32 ul_size,
1347 } 1382 }
1348 /* Critical section */ 1383 /* Critical section */
1349 mutex_lock(&proc_lock); 1384 mutex_lock(&proc_lock);
1385 dmm_get_handle(p_proc_object, &dmm_mgr);
1386 if (dmm_mgr)
1387 status = dmm_map_memory(dmm_mgr, va_align, size_align);
1388 else
1389 status = -EFAULT;
1350 1390
1351 /* Add mapping to the page tables. */ 1391 /* Add mapping to the page tables. */
1352 if (!status) { 1392 if (!status) {
1393
1394 /* Mapped address = MSB of VA | LSB of PA */
1395 tmp_addr = (va_align | ((u32) pmpu_addr & (PG_SIZE4K - 1)));
1353 /* mapped memory resource tracking */ 1396 /* mapped memory resource tracking */
1354 map_obj = add_mapping_info(pr_ctxt, pa_align, va_align, 1397 map_obj = add_mapping_info(pr_ctxt, pa_align, tmp_addr,
1355 size_align); 1398 size_align);
1356 if (!map_obj) { 1399 if (!map_obj)
1357 status = -ENOMEM; 1400 status = -ENOMEM;
1358 } else { 1401 else
1359 va_align = user_to_dsp_map( 1402 status = (*p_proc_object->intf_fxns->pfn_brd_mem_map)
1360 p_proc_object->hbridge_context->dsp_mmu, 1403 (p_proc_object->hbridge_context, pa_align, va_align,
1361 pa_align, va_align, size_align, 1404 size_align, ul_map_attr, map_obj->pages);
1362 map_obj->pages);
1363 if (IS_ERR_VALUE(va_align))
1364 status = (int)va_align;
1365 }
1366 } 1405 }
1367 if (!status) { 1406 if (!status) {
1368 /* Mapped address = MSB of VA | LSB of PA */ 1407 /* Mapped address = MSB of VA | LSB of PA */
1369 map_obj->dsp_addr = (va_align | 1408 *pp_map_addr = (void *) tmp_addr;
1370 ((u32)pmpu_addr & (PG_SIZE4K - 1)));
1371 *pp_map_addr = (void *)map_obj->dsp_addr;
1372 } else { 1409 } else {
1373 remove_mapping_information(pr_ctxt, va_align); 1410 remove_mapping_information(pr_ctxt, tmp_addr, size_align);
1411 dmm_un_map_memory(dmm_mgr, va_align, &size_align);
1374 } 1412 }
1375 mutex_unlock(&proc_lock); 1413 mutex_unlock(&proc_lock);
1376 1414
@@ -1463,6 +1501,55 @@ func_end:
1463} 1501}
1464 1502
1465/* 1503/*
1504 * ======== proc_reserve_memory ========
1505 * Purpose:
1506 * Reserve a virtually contiguous region of DSP address space.
1507 */
1508int proc_reserve_memory(void *hprocessor, u32 ul_size,
1509 void **pp_rsv_addr,
1510 struct process_context *pr_ctxt)
1511{
1512 struct dmm_object *dmm_mgr;
1513 int status = 0;
1514 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1515 struct dmm_rsv_object *rsv_obj;
1516
1517 if (!p_proc_object) {
1518 status = -EFAULT;
1519 goto func_end;
1520 }
1521
1522 status = dmm_get_handle(p_proc_object, &dmm_mgr);
1523 if (!dmm_mgr) {
1524 status = -EFAULT;
1525 goto func_end;
1526 }
1527
1528 status = dmm_reserve_memory(dmm_mgr, ul_size, (u32 *) pp_rsv_addr);
1529 if (status != 0)
1530 goto func_end;
1531
1532 /*
1533 * A successful reserve should be followed by insertion of rsv_obj
1534 * into dmm_rsv_list, so that reserved memory resource tracking
1535 * remains uptodate
1536 */
1537 rsv_obj = kmalloc(sizeof(struct dmm_rsv_object), GFP_KERNEL);
1538 if (rsv_obj) {
1539 rsv_obj->dsp_reserved_addr = (u32) *pp_rsv_addr;
1540 spin_lock(&pr_ctxt->dmm_rsv_lock);
1541 list_add(&rsv_obj->link, &pr_ctxt->dmm_rsv_list);
1542 spin_unlock(&pr_ctxt->dmm_rsv_lock);
1543 }
1544
1545func_end:
1546 dev_dbg(bridge, "%s: hprocessor: 0x%p ul_size: 0x%x pp_rsv_addr: 0x%p "
1547 "status 0x%x\n", __func__, hprocessor,
1548 ul_size, pp_rsv_addr, status);
1549 return status;
1550}
1551
1552/*
1466 * ======== proc_start ======== 1553 * ======== proc_start ========
1467 * Purpose: 1554 * Purpose:
1468 * Start a processor running. 1555 * Start a processor running.
@@ -1610,7 +1697,9 @@ int proc_un_map(void *hprocessor, void *map_addr,
1610{ 1697{
1611 int status = 0; 1698 int status = 0;
1612 struct proc_object *p_proc_object = (struct proc_object *)hprocessor; 1699 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1700 struct dmm_object *dmm_mgr;
1613 u32 va_align; 1701 u32 va_align;
1702 u32 size_align;
1614 1703
1615 va_align = PG_ALIGN_LOW((u32) map_addr, PG_SIZE4K); 1704 va_align = PG_ALIGN_LOW((u32) map_addr, PG_SIZE4K);
1616 if (!p_proc_object) { 1705 if (!p_proc_object) {
@@ -1618,11 +1707,24 @@ int proc_un_map(void *hprocessor, void *map_addr,
1618 goto func_end; 1707 goto func_end;
1619 } 1708 }
1620 1709
1710 status = dmm_get_handle(hprocessor, &dmm_mgr);
1711 if (!dmm_mgr) {
1712 status = -EFAULT;
1713 goto func_end;
1714 }
1715
1621 /* Critical section */ 1716 /* Critical section */
1622 mutex_lock(&proc_lock); 1717 mutex_lock(&proc_lock);
1718 /*
1719 * Update DMM structures. Get the size to unmap.
1720 * This function returns error if the VA is not mapped
1721 */
1722 status = dmm_un_map_memory(dmm_mgr, (u32) va_align, &size_align);
1623 /* Remove mapping from the page tables. */ 1723 /* Remove mapping from the page tables. */
1624 status = user_to_dsp_unmap(p_proc_object->hbridge_context->dsp_mmu, 1724 if (!status) {
1625 va_align); 1725 status = (*p_proc_object->intf_fxns->pfn_brd_mem_un_map)
1726 (p_proc_object->hbridge_context, va_align, size_align);
1727 }
1626 1728
1627 mutex_unlock(&proc_lock); 1729 mutex_unlock(&proc_lock);
1628 if (status) 1730 if (status)
@@ -1633,7 +1735,7 @@ int proc_un_map(void *hprocessor, void *map_addr,
1633 * from dmm_map_list, so that mapped memory resource tracking 1735 * from dmm_map_list, so that mapped memory resource tracking
1634 * remains uptodate 1736 * remains uptodate
1635 */ 1737 */
1636 remove_mapping_information(pr_ctxt, (u32) map_addr); 1738 remove_mapping_information(pr_ctxt, (u32) map_addr, size_align);
1637 1739
1638func_end: 1740func_end:
1639 dev_dbg(bridge, "%s: hprocessor: 0x%p map_addr: 0x%p status: 0x%x\n", 1741 dev_dbg(bridge, "%s: hprocessor: 0x%p map_addr: 0x%p status: 0x%x\n",
@@ -1642,6 +1744,55 @@ func_end:
1642} 1744}
1643 1745
1644/* 1746/*
1747 * ======== proc_un_reserve_memory ========
1748 * Purpose:
1749 * Frees a previously reserved region of DSP address space.
1750 */
1751int proc_un_reserve_memory(void *hprocessor, void *prsv_addr,
1752 struct process_context *pr_ctxt)
1753{
1754 struct dmm_object *dmm_mgr;
1755 int status = 0;
1756 struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
1757 struct dmm_rsv_object *rsv_obj;
1758
1759 if (!p_proc_object) {
1760 status = -EFAULT;
1761 goto func_end;
1762 }
1763
1764 status = dmm_get_handle(p_proc_object, &dmm_mgr);
1765 if (!dmm_mgr) {
1766 status = -EFAULT;
1767 goto func_end;
1768 }
1769
1770 status = dmm_un_reserve_memory(dmm_mgr, (u32) prsv_addr);
1771 if (status != 0)
1772 goto func_end;
1773
1774 /*
1775 * A successful unreserve should be followed by removal of rsv_obj
1776 * from dmm_rsv_list, so that reserved memory resource tracking
1777 * remains uptodate
1778 */
1779 spin_lock(&pr_ctxt->dmm_rsv_lock);
1780 list_for_each_entry(rsv_obj, &pr_ctxt->dmm_rsv_list, link) {
1781 if (rsv_obj->dsp_reserved_addr == (u32) prsv_addr) {
1782 list_del(&rsv_obj->link);
1783 kfree(rsv_obj);
1784 break;
1785 }
1786 }
1787 spin_unlock(&pr_ctxt->dmm_rsv_lock);
1788
1789func_end:
1790 dev_dbg(bridge, "%s: hprocessor: 0x%p prsv_addr: 0x%p status: 0x%x\n",
1791 __func__, hprocessor, prsv_addr, status);
1792 return status;
1793}
1794
1795/*
1645 * ======== = proc_monitor ======== == 1796 * ======== = proc_monitor ======== ==
1646 * Purpose: 1797 * Purpose:
1647 * Place the Processor in Monitor State. This is an internal 1798 * Place the Processor in Monitor State. This is an internal
diff --git a/drivers/staging/tm6000/tm6000-cards.c b/drivers/staging/tm6000/tm6000-cards.c
index 664e6038090d..b143258f094a 100644
--- a/drivers/staging/tm6000/tm6000-cards.c
+++ b/drivers/staging/tm6000/tm6000-cards.c
@@ -545,7 +545,7 @@ static void tm6000_config_tuner(struct tm6000_core *dev)
545 545
546 /* Load tuner module */ 546 /* Load tuner module */
547 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 547 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
548 NULL, "tuner", dev->tuner_addr, NULL); 548 "tuner", dev->tuner_addr, NULL);
549 549
550 memset(&tun_setup, 0, sizeof(tun_setup)); 550 memset(&tun_setup, 0, sizeof(tun_setup));
551 tun_setup.type = dev->tuner_type; 551 tun_setup.type = dev->tuner_type;
@@ -683,7 +683,7 @@ static int tm6000_init_dev(struct tm6000_core *dev)
683 683
684 if (dev->caps.has_tda9874) 684 if (dev->caps.has_tda9874)
685 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 685 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
686 NULL, "tvaudio", I2C_ADDR_TDA9874, NULL); 686 "tvaudio", I2C_ADDR_TDA9874, NULL);
687 687
688 /* register and initialize V4L2 */ 688 /* register and initialize V4L2 */
689 rc = tm6000_v4l2_register(dev); 689 rc = tm6000_v4l2_register(dev);
diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c
index 3e46866dd279..93f625fc852b 100644
--- a/drivers/staging/tm6000/tm6000-i2c.c
+++ b/drivers/staging/tm6000/tm6000-i2c.c
@@ -320,7 +320,6 @@ static struct i2c_algorithm tm6000_algo = {
320 320
321static struct i2c_adapter tm6000_adap_template = { 321static struct i2c_adapter tm6000_adap_template = {
322 .owner = THIS_MODULE, 322 .owner = THIS_MODULE,
323 .class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
324 .name = "tm6000", 323 .name = "tm6000",
325 .algo = &tm6000_algo, 324 .algo = &tm6000_algo,
326}; 325};
diff --git a/drivers/staging/tm6000/tm6000-video.c b/drivers/staging/tm6000/tm6000-video.c
index 9ec82796634e..c5690b2a8924 100644
--- a/drivers/staging/tm6000/tm6000-video.c
+++ b/drivers/staging/tm6000/tm6000-video.c
@@ -1032,6 +1032,7 @@ static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *norm)
1032 struct tm6000_fh *fh=priv; 1032 struct tm6000_fh *fh=priv;
1033 struct tm6000_core *dev = fh->dev; 1033 struct tm6000_core *dev = fh->dev;
1034 1034
1035 dev->norm = *norm;
1035 rc = tm6000_init_analog_mode(dev); 1036 rc = tm6000_init_analog_mode(dev);
1036 1037
1037 fh->width = dev->width; 1038 fh->width = dev->width;
diff --git a/drivers/staging/udlfb/udlfb.c b/drivers/staging/udlfb/udlfb.c
index 5969e848d297..b7ac16005265 100644
--- a/drivers/staging/udlfb/udlfb.c
+++ b/drivers/staging/udlfb/udlfb.c
@@ -887,7 +887,7 @@ static int dlfb_ops_open(struct fb_info *info, int user)
887 887
888 struct fb_deferred_io *fbdefio; 888 struct fb_deferred_io *fbdefio;
889 889
890 fbdefio = kmalloc(GFP_KERNEL, sizeof(struct fb_deferred_io)); 890 fbdefio = kmalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
891 891
892 if (fbdefio) { 892 if (fbdefio) {
893 fbdefio->delay = DL_DEFIO_WRITE_DELAY; 893 fbdefio->delay = DL_DEFIO_WRITE_DELAY;
@@ -1441,7 +1441,7 @@ static struct device_attribute fb_device_attrs[] = {
1441 __ATTR_RO(metrics_bytes_identical), 1441 __ATTR_RO(metrics_bytes_identical),
1442 __ATTR_RO(metrics_bytes_sent), 1442 __ATTR_RO(metrics_bytes_sent),
1443 __ATTR_RO(metrics_cpu_kcycles_used), 1443 __ATTR_RO(metrics_cpu_kcycles_used),
1444 __ATTR(metrics_reset, S_IWUGO, NULL, metrics_reset_store), 1444 __ATTR(metrics_reset, S_IWUSR, NULL, metrics_reset_store),
1445}; 1445};
1446 1446
1447/* 1447/*
diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
index e992d5d9e15b..7cc3d2407d1b 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -1675,13 +1675,14 @@ static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
1675 1675
1676 { 1676 {
1677 char essid[IW_ESSID_MAX_SIZE+1]; 1677 char essid[IW_ESSID_MAX_SIZE+1];
1678 if (wrq->u.essid.pointer) 1678 if (wrq->u.essid.pointer) {
1679 rc = iwctl_giwessid(dev, NULL, 1679 rc = iwctl_giwessid(dev, NULL,
1680 &(wrq->u.essid), essid); 1680 &(wrq->u.essid), essid);
1681 if (copy_to_user(wrq->u.essid.pointer, 1681 if (copy_to_user(wrq->u.essid.pointer,
1682 essid, 1682 essid,
1683 wrq->u.essid.length) ) 1683 wrq->u.essid.length) )
1684 rc = -EFAULT; 1684 rc = -EFAULT;
1685 }
1685 } 1686 }
1686 break; 1687 break;
1687 1688
diff --git a/drivers/staging/westbridge/astoria/api/src/cyasusb.c b/drivers/staging/westbridge/astoria/api/src/cyasusb.c
index 5a2197012065..7777d9a60a52 100644
--- a/drivers/staging/westbridge/astoria/api/src/cyasusb.c
+++ b/drivers/staging/westbridge/astoria/api/src/cyasusb.c
@@ -1417,7 +1417,6 @@ cy_as_usb_set_enum_config(cy_as_device_handle handle,
1417 */ 1417 */
1418 bus_mask = 0; 1418 bus_mask = 0;
1419 media_mask = 0; 1419 media_mask = 0;
1420 media_mask = 0;
1421 for (bus = 0; bus < CY_AS_MAX_BUSES; bus++) { 1420 for (bus = 0; bus < CY_AS_MAX_BUSES; bus++) {
1422 for (device = 0; device < CY_AS_MAX_STORAGE_DEVICES; device++) { 1421 for (device = 0; device < CY_AS_MAX_STORAGE_DEVICES; device++) {
1423 if (config_p->devices_to_enumerate[bus][device] == 1422 if (config_p->devices_to_enumerate[bus][device] ==
diff --git a/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c b/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c
index f428a7af357a..e1851f00be56 100644
--- a/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c
+++ b/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c
@@ -157,7 +157,7 @@ struct cyasblkdev_blk_data {
157/* pointer to west bridge block data device superstructure */ 157/* pointer to west bridge block data device superstructure */
158static struct cyasblkdev_blk_data *gl_bd; 158static struct cyasblkdev_blk_data *gl_bd;
159 159
160static DECLARE_MUTEX(open_lock); 160static DEFINE_SEMAPHORE(open_lock);
161 161
162/* local forwardd declarationss */ 162/* local forwardd declarationss */
163static cy_as_device_handle *cyas_dev_handle; 163static cy_as_device_handle *cyas_dev_handle;
diff --git a/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.c b/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.c
index 24e959eca412..0bbb8a3e191d 100644
--- a/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.c
+++ b/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.c
@@ -334,7 +334,7 @@ int cyasblkdev_init_queue(struct cyasblkdev_queue *bq, spinlock_t *lock)
334 334
335 init_completion(&bq->thread_complete); 335 init_completion(&bq->thread_complete);
336 init_waitqueue_head(&bq->thread_wq); 336 init_waitqueue_head(&bq->thread_wq);
337 init_MUTEX(&bq->thread_sem); 337 sema_init(&bq->thread_sem, 1);
338 338
339 ret = kernel_thread(cyasblkdev_queue_thread, bq, CLONE_KERNEL); 339 ret = kernel_thread(cyasblkdev_queue_thread, bq, CLONE_KERNEL);
340 if (ret >= 0) { 340 if (ret >= 0) {
diff --git a/drivers/staging/winbond/sysdef.h b/drivers/staging/winbond/sysdef.h
index 9195adf98e14..d0d71f69bc8c 100644
--- a/drivers/staging/winbond/sysdef.h
+++ b/drivers/staging/winbond/sysdef.h
@@ -2,6 +2,9 @@
2 2
3#ifndef SYS_DEF_H 3#ifndef SYS_DEF_H
4#define SYS_DEF_H 4#define SYS_DEF_H
5
6#include <linux/delay.h>
7
5#define WB_LINUX 8#define WB_LINUX
6#define WB_LINUX_WPA_PSK 9#define WB_LINUX_WPA_PSK
7 10
diff --git a/drivers/staging/wlan-ng/cfg80211.c b/drivers/staging/wlan-ng/cfg80211.c
index 4af83d5318f2..6a71f52c59b1 100644
--- a/drivers/staging/wlan-ng/cfg80211.c
+++ b/drivers/staging/wlan-ng/cfg80211.c
@@ -139,7 +139,7 @@ exit:
139} 139}
140 140
141int prism2_add_key(struct wiphy *wiphy, struct net_device *dev, 141int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
142 u8 key_index, const u8 *mac_addr, 142 u8 key_index, bool pairwise, const u8 *mac_addr,
143 struct key_params *params) 143 struct key_params *params)
144{ 144{
145 wlandevice_t *wlandev = dev->ml_priv; 145 wlandevice_t *wlandev = dev->ml_priv;
@@ -198,7 +198,7 @@ exit:
198} 198}
199 199
200int prism2_get_key(struct wiphy *wiphy, struct net_device *dev, 200int prism2_get_key(struct wiphy *wiphy, struct net_device *dev,
201 u8 key_index, const u8 *mac_addr, void *cookie, 201 u8 key_index, bool pairwise, const u8 *mac_addr, void *cookie,
202 void (*callback)(void *cookie, struct key_params*)) 202 void (*callback)(void *cookie, struct key_params*))
203{ 203{
204 wlandevice_t *wlandev = dev->ml_priv; 204 wlandevice_t *wlandev = dev->ml_priv;
@@ -227,7 +227,7 @@ int prism2_get_key(struct wiphy *wiphy, struct net_device *dev,
227} 227}
228 228
229int prism2_del_key(struct wiphy *wiphy, struct net_device *dev, 229int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
230 u8 key_index, const u8 *mac_addr) 230 u8 key_index, bool pairwise, const u8 *mac_addr)
231{ 231{
232 wlandevice_t *wlandev = dev->ml_priv; 232 wlandevice_t *wlandev = dev->ml_priv;
233 u32 did; 233 u32 did;
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index aa1792c8429e..b7b4a733b467 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -522,8 +522,8 @@ static int p80211netdev_ethtool(wlandevice_t *wlandev, void __user *useraddr)
522 if (copy_to_user(useraddr, &edata, sizeof(edata))) 522 if (copy_to_user(useraddr, &edata, sizeof(edata)))
523 return -EFAULT; 523 return -EFAULT;
524 return 0; 524 return 0;
525 }
526#endif 525#endif
526 }
527 527
528 return -EOPNOTSUPP; 528 return -EOPNOTSUPP;
529} 529}
diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c
index 6c574a994d11..6b3cf00b0ff4 100644
--- a/drivers/staging/zram/zram_sysfs.c
+++ b/drivers/staging/zram/zram_sysfs.c
@@ -189,10 +189,10 @@ static ssize_t mem_used_total_show(struct device *dev,
189 return sprintf(buf, "%llu\n", val); 189 return sprintf(buf, "%llu\n", val);
190} 190}
191 191
192static DEVICE_ATTR(disksize, S_IRUGO | S_IWUGO, 192static DEVICE_ATTR(disksize, S_IRUGO | S_IWUSR,
193 disksize_show, disksize_store); 193 disksize_show, disksize_store);
194static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL); 194static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
195static DEVICE_ATTR(reset, S_IWUGO, NULL, reset_store); 195static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
196static DEVICE_ATTR(num_reads, S_IRUGO, num_reads_show, NULL); 196static DEVICE_ATTR(num_reads, S_IRUGO, num_reads_show, NULL);
197static DEVICE_ATTR(num_writes, S_IRUGO, num_writes_show, NULL); 197static DEVICE_ATTR(num_writes, S_IRUGO, num_writes_show, NULL);
198static DEVICE_ATTR(invalid_io, S_IRUGO, invalid_io_show, NULL); 198static DEVICE_ATTR(invalid_io, S_IRUGO, invalid_io_show, NULL);
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
new file mode 100644
index 000000000000..c43ef48b1a0f
--- /dev/null
+++ b/drivers/tty/Makefile
@@ -0,0 +1,11 @@
1obj-y += tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o \
2 tty_buffer.o tty_port.o tty_mutex.o
3obj-$(CONFIG_LEGACY_PTYS) += pty.o
4obj-$(CONFIG_UNIX98_PTYS) += pty.o
5obj-$(CONFIG_AUDIT) += tty_audit.o
6obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
7obj-$(CONFIG_N_HDLC) += n_hdlc.o
8obj-$(CONFIG_N_GSM) += n_gsm.o
9obj-$(CONFIG_R3964) += n_r3964.o
10
11obj-y += vt/
diff --git a/drivers/char/n_gsm.c b/drivers/tty/n_gsm.c
index 04ef3ef0a422..c5f8e5bda2b2 100644
--- a/drivers/char/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -716,8 +716,8 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
716 if (msg->len < 128) 716 if (msg->len < 128)
717 *--dp = (msg->len << 1) | EA; 717 *--dp = (msg->len << 1) | EA;
718 else { 718 else {
719 *--dp = (msg->len >> 6) | EA; 719 *--dp = (msg->len >> 7); /* bits 7 - 15 */
720 *--dp = (msg->len & 127) << 1; 720 *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */
721 } 721 }
722 } 722 }
723 723
@@ -968,6 +968,8 @@ static void gsm_control_reply(struct gsm_mux *gsm, int cmd, u8 *data,
968{ 968{
969 struct gsm_msg *msg; 969 struct gsm_msg *msg;
970 msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype); 970 msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype);
971 if (msg == NULL)
972 return;
971 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ 973 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */
972 msg->data[1] = (dlen << 1) | EA; 974 msg->data[1] = (dlen << 1) | EA;
973 memcpy(msg->data + 2, data, dlen); 975 memcpy(msg->data + 2, data, dlen);
@@ -2375,6 +2377,7 @@ static int gsmld_config(struct tty_struct *tty, struct gsm_mux *gsm,
2375 gsm->mru = c->mru; 2377 gsm->mru = c->mru;
2376 gsm->encoding = c->encapsulation; 2378 gsm->encoding = c->encapsulation;
2377 gsm->adaption = c->adaption; 2379 gsm->adaption = c->adaption;
2380 gsm->n2 = c->n2;
2378 2381
2379 if (c->i == 1) 2382 if (c->i == 1)
2380 gsm->ftype = UIH; 2383 gsm->ftype = UIH;
diff --git a/drivers/char/n_hdlc.c b/drivers/tty/n_hdlc.c
index 47d32281032c..47d32281032c 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
diff --git a/drivers/char/n_r3964.c b/drivers/tty/n_r3964.c
index 88dda0c45ee0..88dda0c45ee0 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/tty/n_r3964.c
diff --git a/drivers/char/n_tty.c b/drivers/tty/n_tty.c
index 428f4fe0b5f7..428f4fe0b5f7 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/tty/n_tty.c
diff --git a/drivers/char/pty.c b/drivers/tty/pty.c
index 923a48585501..923a48585501 100644
--- a/drivers/char/pty.c
+++ b/drivers/tty/pty.c
diff --git a/drivers/char/sysrq.c b/drivers/tty/sysrq.c
index eaa5d3efa79d..c556ed9db13d 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -554,7 +554,7 @@ EXPORT_SYMBOL(handle_sysrq);
554#ifdef CONFIG_INPUT 554#ifdef CONFIG_INPUT
555 555
556/* Simple translation table for the SysRq keys */ 556/* Simple translation table for the SysRq keys */
557static const unsigned char sysrq_xlate[KEY_MAX + 1] = 557static const unsigned char sysrq_xlate[KEY_CNT] =
558 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */ 558 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
559 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */ 559 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
560 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */ 560 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
@@ -563,53 +563,129 @@ static const unsigned char sysrq_xlate[KEY_MAX + 1] =
563 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */ 563 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
564 "\r\000/"; /* 0x60 - 0x6f */ 564 "\r\000/"; /* 0x60 - 0x6f */
565 565
566static bool sysrq_down; 566struct sysrq_state {
567static int sysrq_alt_use; 567 struct input_handle handle;
568static int sysrq_alt; 568 struct work_struct reinject_work;
569static DEFINE_SPINLOCK(sysrq_event_lock); 569 unsigned long key_down[BITS_TO_LONGS(KEY_CNT)];
570 unsigned int alt;
571 unsigned int alt_use;
572 bool active;
573 bool need_reinject;
574};
575
576static void sysrq_reinject_alt_sysrq(struct work_struct *work)
577{
578 struct sysrq_state *sysrq =
579 container_of(work, struct sysrq_state, reinject_work);
580 struct input_handle *handle = &sysrq->handle;
581 unsigned int alt_code = sysrq->alt_use;
582
583 if (sysrq->need_reinject) {
584 /* Simulate press and release of Alt + SysRq */
585 input_inject_event(handle, EV_KEY, alt_code, 1);
586 input_inject_event(handle, EV_KEY, KEY_SYSRQ, 1);
587 input_inject_event(handle, EV_SYN, SYN_REPORT, 1);
588
589 input_inject_event(handle, EV_KEY, KEY_SYSRQ, 0);
590 input_inject_event(handle, EV_KEY, alt_code, 0);
591 input_inject_event(handle, EV_SYN, SYN_REPORT, 1);
592 }
593}
570 594
571static bool sysrq_filter(struct input_handle *handle, unsigned int type, 595static bool sysrq_filter(struct input_handle *handle,
572 unsigned int code, int value) 596 unsigned int type, unsigned int code, int value)
573{ 597{
598 struct sysrq_state *sysrq = handle->private;
599 bool was_active = sysrq->active;
574 bool suppress; 600 bool suppress;
575 601
576 /* We are called with interrupts disabled, just take the lock */ 602 switch (type) {
577 spin_lock(&sysrq_event_lock);
578 603
579 if (type != EV_KEY) 604 case EV_SYN:
580 goto out; 605 suppress = false;
606 break;
581 607
582 switch (code) { 608 case EV_KEY:
609 switch (code) {
583 610
584 case KEY_LEFTALT: 611 case KEY_LEFTALT:
585 case KEY_RIGHTALT: 612 case KEY_RIGHTALT:
586 if (value) 613 if (!value) {
587 sysrq_alt = code; 614 /* One of ALTs is being released */
588 else { 615 if (sysrq->active && code == sysrq->alt_use)
589 if (sysrq_down && code == sysrq_alt_use) 616 sysrq->active = false;
590 sysrq_down = false;
591 617
592 sysrq_alt = 0; 618 sysrq->alt = KEY_RESERVED;
619
620 } else if (value != 2) {
621 sysrq->alt = code;
622 sysrq->need_reinject = false;
623 }
624 break;
625
626 case KEY_SYSRQ:
627 if (value == 1 && sysrq->alt != KEY_RESERVED) {
628 sysrq->active = true;
629 sysrq->alt_use = sysrq->alt;
630 /*
631 * If nothing else will be pressed we'll need
632 * to * re-inject Alt-SysRq keysroke.
633 */
634 sysrq->need_reinject = true;
635 }
636
637 /*
638 * Pretend that sysrq was never pressed at all. This
639 * is needed to properly handle KGDB which will try
640 * to release all keys after exiting debugger. If we
641 * do not clear key bit it KGDB will end up sending
642 * release events for Alt and SysRq, potentially
643 * triggering print screen function.
644 */
645 if (sysrq->active)
646 clear_bit(KEY_SYSRQ, handle->dev->key);
647
648 break;
649
650 default:
651 if (sysrq->active && value && value != 2) {
652 sysrq->need_reinject = false;
653 __handle_sysrq(sysrq_xlate[code], true);
654 }
655 break;
593 } 656 }
594 break;
595 657
596 case KEY_SYSRQ: 658 suppress = sysrq->active;
597 if (value == 1 && sysrq_alt) { 659
598 sysrq_down = true; 660 if (!sysrq->active) {
599 sysrq_alt_use = sysrq_alt; 661 /*
662 * If we are not suppressing key presses keep track of
663 * keyboard state so we can release keys that have been
664 * pressed before entering SysRq mode.
665 */
666 if (value)
667 set_bit(code, sysrq->key_down);
668 else
669 clear_bit(code, sysrq->key_down);
670
671 if (was_active)
672 schedule_work(&sysrq->reinject_work);
673
674 } else if (value == 0 &&
675 test_and_clear_bit(code, sysrq->key_down)) {
676 /*
677 * Pass on release events for keys that was pressed before
678 * entering SysRq mode.
679 */
680 suppress = false;
600 } 681 }
601 break; 682 break;
602 683
603 default: 684 default:
604 if (sysrq_down && value && value != 2) 685 suppress = sysrq->active;
605 __handle_sysrq(sysrq_xlate[code], true);
606 break; 686 break;
607 } 687 }
608 688
609out:
610 suppress = sysrq_down;
611 spin_unlock(&sysrq_event_lock);
612
613 return suppress; 689 return suppress;
614} 690}
615 691
@@ -617,28 +693,28 @@ static int sysrq_connect(struct input_handler *handler,
617 struct input_dev *dev, 693 struct input_dev *dev,
618 const struct input_device_id *id) 694 const struct input_device_id *id)
619{ 695{
620 struct input_handle *handle; 696 struct sysrq_state *sysrq;
621 int error; 697 int error;
622 698
623 sysrq_down = false; 699 sysrq = kzalloc(sizeof(struct sysrq_state), GFP_KERNEL);
624 sysrq_alt = 0; 700 if (!sysrq)
625
626 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
627 if (!handle)
628 return -ENOMEM; 701 return -ENOMEM;
629 702
630 handle->dev = dev; 703 INIT_WORK(&sysrq->reinject_work, sysrq_reinject_alt_sysrq);
631 handle->handler = handler; 704
632 handle->name = "sysrq"; 705 sysrq->handle.dev = dev;
706 sysrq->handle.handler = handler;
707 sysrq->handle.name = "sysrq";
708 sysrq->handle.private = sysrq;
633 709
634 error = input_register_handle(handle); 710 error = input_register_handle(&sysrq->handle);
635 if (error) { 711 if (error) {
636 pr_err("Failed to register input sysrq handler, error %d\n", 712 pr_err("Failed to register input sysrq handler, error %d\n",
637 error); 713 error);
638 goto err_free; 714 goto err_free;
639 } 715 }
640 716
641 error = input_open_device(handle); 717 error = input_open_device(&sysrq->handle);
642 if (error) { 718 if (error) {
643 pr_err("Failed to open input device, error %d\n", error); 719 pr_err("Failed to open input device, error %d\n", error);
644 goto err_unregister; 720 goto err_unregister;
@@ -647,17 +723,20 @@ static int sysrq_connect(struct input_handler *handler,
647 return 0; 723 return 0;
648 724
649 err_unregister: 725 err_unregister:
650 input_unregister_handle(handle); 726 input_unregister_handle(&sysrq->handle);
651 err_free: 727 err_free:
652 kfree(handle); 728 kfree(sysrq);
653 return error; 729 return error;
654} 730}
655 731
656static void sysrq_disconnect(struct input_handle *handle) 732static void sysrq_disconnect(struct input_handle *handle)
657{ 733{
734 struct sysrq_state *sysrq = handle->private;
735
658 input_close_device(handle); 736 input_close_device(handle);
737 cancel_work_sync(&sysrq->reinject_work);
659 input_unregister_handle(handle); 738 input_unregister_handle(handle);
660 kfree(handle); 739 kfree(sysrq);
661} 740}
662 741
663/* 742/*
diff --git a/drivers/char/tty_audit.c b/drivers/tty/tty_audit.c
index f64582b0f623..f64582b0f623 100644
--- a/drivers/char/tty_audit.c
+++ b/drivers/tty/tty_audit.c
diff --git a/drivers/char/tty_buffer.c b/drivers/tty/tty_buffer.c
index cc1e9850d655..d8210ca00720 100644
--- a/drivers/char/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -413,7 +413,8 @@ static void flush_to_ldisc(struct work_struct *work)
413 spin_lock_irqsave(&tty->buf.lock, flags); 413 spin_lock_irqsave(&tty->buf.lock, flags);
414 414
415 if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) { 415 if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) {
416 struct tty_buffer *head; 416 struct tty_buffer *head, *tail = tty->buf.tail;
417 int seen_tail = 0;
417 while ((head = tty->buf.head) != NULL) { 418 while ((head = tty->buf.head) != NULL) {
418 int count; 419 int count;
419 char *char_buf; 420 char *char_buf;
@@ -423,6 +424,15 @@ static void flush_to_ldisc(struct work_struct *work)
423 if (!count) { 424 if (!count) {
424 if (head->next == NULL) 425 if (head->next == NULL)
425 break; 426 break;
427 /*
428 There's a possibility tty might get new buffer
429 added during the unlock window below. We could
430 end up spinning in here forever hogging the CPU
431 completely. To avoid this let's have a rest each
432 time we processed the tail buffer.
433 */
434 if (tail == head)
435 seen_tail = 1;
426 tty->buf.head = head->next; 436 tty->buf.head = head->next;
427 tty_buffer_free(tty, head); 437 tty_buffer_free(tty, head);
428 continue; 438 continue;
@@ -432,7 +442,7 @@ static void flush_to_ldisc(struct work_struct *work)
432 line discipline as we want to empty the queue */ 442 line discipline as we want to empty the queue */
433 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) 443 if (test_bit(TTY_FLUSHPENDING, &tty->flags))
434 break; 444 break;
435 if (!tty->receive_room) { 445 if (!tty->receive_room || seen_tail) {
436 schedule_delayed_work(&tty->buf.work, 1); 446 schedule_delayed_work(&tty->buf.work, 1);
437 break; 447 break;
438 } 448 }
diff --git a/drivers/char/tty_io.c b/drivers/tty/tty_io.c
index c05c5af5aa04..35480dd57a30 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -559,6 +559,9 @@ void __tty_hangup(struct tty_struct *tty)
559 559
560 tty_lock(); 560 tty_lock();
561 561
562 /* some functions below drop BTM, so we need this bit */
563 set_bit(TTY_HUPPING, &tty->flags);
564
562 /* inuse_filps is protected by the single tty lock, 565 /* inuse_filps is protected by the single tty lock,
563 this really needs to change if we want to flush the 566 this really needs to change if we want to flush the
564 workqueue with the lock held */ 567 workqueue with the lock held */
@@ -578,6 +581,10 @@ void __tty_hangup(struct tty_struct *tty)
578 } 581 }
579 spin_unlock(&tty_files_lock); 582 spin_unlock(&tty_files_lock);
580 583
584 /*
585 * it drops BTM and thus races with reopen
586 * we protect the race by TTY_HUPPING
587 */
581 tty_ldisc_hangup(tty); 588 tty_ldisc_hangup(tty);
582 589
583 read_lock(&tasklist_lock); 590 read_lock(&tasklist_lock);
@@ -615,7 +622,6 @@ void __tty_hangup(struct tty_struct *tty)
615 tty->session = NULL; 622 tty->session = NULL;
616 tty->pgrp = NULL; 623 tty->pgrp = NULL;
617 tty->ctrl_status = 0; 624 tty->ctrl_status = 0;
618 set_bit(TTY_HUPPED, &tty->flags);
619 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 625 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
620 626
621 /* Account for the p->signal references we killed */ 627 /* Account for the p->signal references we killed */
@@ -641,6 +647,7 @@ void __tty_hangup(struct tty_struct *tty)
641 * can't yet guarantee all that. 647 * can't yet guarantee all that.
642 */ 648 */
643 set_bit(TTY_HUPPED, &tty->flags); 649 set_bit(TTY_HUPPED, &tty->flags);
650 clear_bit(TTY_HUPPING, &tty->flags);
644 tty_ldisc_enable(tty); 651 tty_ldisc_enable(tty);
645 652
646 tty_unlock(); 653 tty_unlock();
@@ -1310,7 +1317,9 @@ static int tty_reopen(struct tty_struct *tty)
1310{ 1317{
1311 struct tty_driver *driver = tty->driver; 1318 struct tty_driver *driver = tty->driver;
1312 1319
1313 if (test_bit(TTY_CLOSING, &tty->flags)) 1320 if (test_bit(TTY_CLOSING, &tty->flags) ||
1321 test_bit(TTY_HUPPING, &tty->flags) ||
1322 test_bit(TTY_LDISC_CHANGING, &tty->flags))
1314 return -EIO; 1323 return -EIO;
1315 1324
1316 if (driver->type == TTY_DRIVER_TYPE_PTY && 1325 if (driver->type == TTY_DRIVER_TYPE_PTY &&
diff --git a/drivers/char/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 0c1889971459..0c1889971459 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
diff --git a/drivers/char/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 412f9775d19c..4214d58276f7 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -47,6 +47,7 @@
47 47
48static DEFINE_SPINLOCK(tty_ldisc_lock); 48static DEFINE_SPINLOCK(tty_ldisc_lock);
49static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); 49static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
50static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_idle);
50/* Line disc dispatch table */ 51/* Line disc dispatch table */
51static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; 52static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
52 53
@@ -83,6 +84,7 @@ static void put_ldisc(struct tty_ldisc *ld)
83 return; 84 return;
84 } 85 }
85 local_irq_restore(flags); 86 local_irq_restore(flags);
87 wake_up(&tty_ldisc_idle);
86} 88}
87 89
88/** 90/**
@@ -452,6 +454,8 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
452 /* BTM here locks versus a hangup event */ 454 /* BTM here locks versus a hangup event */
453 WARN_ON(!tty_locked()); 455 WARN_ON(!tty_locked());
454 ret = ld->ops->open(tty); 456 ret = ld->ops->open(tty);
457 if (ret)
458 clear_bit(TTY_LDISC_OPEN, &tty->flags);
455 return ret; 459 return ret;
456 } 460 }
457 return 0; 461 return 0;
@@ -531,6 +535,23 @@ static int tty_ldisc_halt(struct tty_struct *tty)
531} 535}
532 536
533/** 537/**
538 * tty_ldisc_wait_idle - wait for the ldisc to become idle
539 * @tty: tty to wait for
540 *
541 * Wait for the line discipline to become idle. The discipline must
542 * have been halted for this to guarantee it remains idle.
543 */
544static int tty_ldisc_wait_idle(struct tty_struct *tty)
545{
546 int ret;
547 ret = wait_event_interruptible_timeout(tty_ldisc_idle,
548 atomic_read(&tty->ldisc->users) == 1, 5 * HZ);
549 if (ret < 0)
550 return ret;
551 return ret > 0 ? 0 : -EBUSY;
552}
553
554/**
534 * tty_set_ldisc - set line discipline 555 * tty_set_ldisc - set line discipline
535 * @tty: the terminal to set 556 * @tty: the terminal to set
536 * @ldisc: the line discipline 557 * @ldisc: the line discipline
@@ -634,8 +655,17 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
634 655
635 flush_scheduled_work(); 656 flush_scheduled_work();
636 657
658 retval = tty_ldisc_wait_idle(tty);
659
637 tty_lock(); 660 tty_lock();
638 mutex_lock(&tty->ldisc_mutex); 661 mutex_lock(&tty->ldisc_mutex);
662
663 /* handle wait idle failure locked */
664 if (retval) {
665 tty_ldisc_put(new_ldisc);
666 goto enable;
667 }
668
639 if (test_bit(TTY_HUPPED, &tty->flags)) { 669 if (test_bit(TTY_HUPPED, &tty->flags)) {
640 /* We were raced by the hangup method. It will have stomped 670 /* We were raced by the hangup method. It will have stomped
641 the ldisc data and closed the ldisc down */ 671 the ldisc data and closed the ldisc down */
@@ -669,6 +699,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
669 699
670 tty_ldisc_put(o_ldisc); 700 tty_ldisc_put(o_ldisc);
671 701
702enable:
672 /* 703 /*
673 * Allow ldisc referencing to occur again 704 * Allow ldisc referencing to occur again
674 */ 705 */
@@ -714,9 +745,12 @@ static void tty_reset_termios(struct tty_struct *tty)
714 * state closed 745 * state closed
715 */ 746 */
716 747
717static void tty_ldisc_reinit(struct tty_struct *tty, int ldisc) 748static int tty_ldisc_reinit(struct tty_struct *tty, int ldisc)
718{ 749{
719 struct tty_ldisc *ld; 750 struct tty_ldisc *ld = tty_ldisc_get(ldisc);
751
752 if (IS_ERR(ld))
753 return -1;
720 754
721 tty_ldisc_close(tty, tty->ldisc); 755 tty_ldisc_close(tty, tty->ldisc);
722 tty_ldisc_put(tty->ldisc); 756 tty_ldisc_put(tty->ldisc);
@@ -724,10 +758,10 @@ static void tty_ldisc_reinit(struct tty_struct *tty, int ldisc)
724 /* 758 /*
725 * Switch the line discipline back 759 * Switch the line discipline back
726 */ 760 */
727 ld = tty_ldisc_get(ldisc);
728 BUG_ON(IS_ERR(ld));
729 tty_ldisc_assign(tty, ld); 761 tty_ldisc_assign(tty, ld);
730 tty_set_termios_ldisc(tty, ldisc); 762 tty_set_termios_ldisc(tty, ldisc);
763
764 return 0;
731} 765}
732 766
733/** 767/**
@@ -802,13 +836,16 @@ void tty_ldisc_hangup(struct tty_struct *tty)
802 a FIXME */ 836 a FIXME */
803 if (tty->ldisc) { /* Not yet closed */ 837 if (tty->ldisc) { /* Not yet closed */
804 if (reset == 0) { 838 if (reset == 0) {
805 tty_ldisc_reinit(tty, tty->termios->c_line); 839
806 err = tty_ldisc_open(tty, tty->ldisc); 840 if (!tty_ldisc_reinit(tty, tty->termios->c_line))
841 err = tty_ldisc_open(tty, tty->ldisc);
842 else
843 err = 1;
807 } 844 }
808 /* If the re-open fails or we reset then go to N_TTY. The 845 /* If the re-open fails or we reset then go to N_TTY. The
809 N_TTY open cannot fail */ 846 N_TTY open cannot fail */
810 if (reset || err) { 847 if (reset || err) {
811 tty_ldisc_reinit(tty, N_TTY); 848 BUG_ON(tty_ldisc_reinit(tty, N_TTY));
812 WARN_ON(tty_ldisc_open(tty, tty->ldisc)); 849 WARN_ON(tty_ldisc_open(tty, tty->ldisc));
813 } 850 }
814 tty_ldisc_enable(tty); 851 tty_ldisc_enable(tty);
diff --git a/drivers/char/tty_mutex.c b/drivers/tty/tty_mutex.c
index 133697540c73..133697540c73 100644
--- a/drivers/char/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
diff --git a/drivers/char/tty_port.c b/drivers/tty/tty_port.c
index 33d37d230f8f..33d37d230f8f 100644
--- a/drivers/char/tty_port.c
+++ b/drivers/tty/tty_port.c
diff --git a/drivers/char/.gitignore b/drivers/tty/vt/.gitignore
index 83683a2d8e6a..83683a2d8e6a 100644
--- a/drivers/char/.gitignore
+++ b/drivers/tty/vt/.gitignore
diff --git a/drivers/tty/vt/Makefile b/drivers/tty/vt/Makefile
new file mode 100644
index 000000000000..14a51c9960df
--- /dev/null
+++ b/drivers/tty/vt/Makefile
@@ -0,0 +1,34 @@
1#
2# This file contains the font map for the default (hardware) font
3#
4FONTMAPFILE = cp437.uni
5
6obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o \
7 selection.o keyboard.o
8obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o
9obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
10
11# Files generated that shall be removed upon make clean
12clean-files := consolemap_deftbl.c defkeymap.c
13
14quiet_cmd_conmk = CONMK $@
15 cmd_conmk = scripts/conmakehash $< > $@
16
17$(obj)/consolemap_deftbl.c: $(src)/$(FONTMAPFILE)
18 $(call cmd,conmk)
19
20$(obj)/defkeymap.o: $(obj)/defkeymap.c
21
22# Uncomment if you're changing the keymap and have an appropriate
23# loadkeys version for the map. By default, we'll use the shipped
24# versions.
25# GENERATE_KEYMAP := 1
26
27ifdef GENERATE_KEYMAP
28
29$(obj)/defkeymap.c: $(obj)/%.c: $(src)/%.map
30 loadkeys --mktable $< > $@.tmp
31 sed -e 's/^static *//' $@.tmp > $@
32 rm $@.tmp
33
34endif
diff --git a/drivers/char/consolemap.c b/drivers/tty/vt/consolemap.c
index 45d3e80156d4..45d3e80156d4 100644
--- a/drivers/char/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
diff --git a/drivers/char/cp437.uni b/drivers/tty/vt/cp437.uni
index bc6163484f62..bc6163484f62 100644
--- a/drivers/char/cp437.uni
+++ b/drivers/tty/vt/cp437.uni
diff --git a/drivers/char/defkeymap.c_shipped b/drivers/tty/vt/defkeymap.c_shipped
index d2208dfe3f67..d2208dfe3f67 100644
--- a/drivers/char/defkeymap.c_shipped
+++ b/drivers/tty/vt/defkeymap.c_shipped
diff --git a/drivers/char/defkeymap.map b/drivers/tty/vt/defkeymap.map
index 50b30cace261..50b30cace261 100644
--- a/drivers/char/defkeymap.map
+++ b/drivers/tty/vt/defkeymap.map
diff --git a/drivers/char/keyboard.c b/drivers/tty/vt/keyboard.c
index e95d7876ca6b..e95d7876ca6b 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
diff --git a/drivers/char/selection.c b/drivers/tty/vt/selection.c
index ebae344ce910..ebae344ce910 100644
--- a/drivers/char/selection.c
+++ b/drivers/tty/vt/selection.c
diff --git a/drivers/char/vc_screen.c b/drivers/tty/vt/vc_screen.c
index 273ab44cc91d..eab3a1ff99e4 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -553,12 +553,12 @@ static unsigned int
553vcs_poll(struct file *file, poll_table *wait) 553vcs_poll(struct file *file, poll_table *wait)
554{ 554{
555 struct vcs_poll_data *poll = vcs_poll_data_get(file); 555 struct vcs_poll_data *poll = vcs_poll_data_get(file);
556 int ret = 0; 556 int ret = DEFAULT_POLLMASK|POLLERR|POLLPRI;
557 557
558 if (poll) { 558 if (poll) {
559 poll_wait(file, &poll->waitq, wait); 559 poll_wait(file, &poll->waitq, wait);
560 if (!poll->seen_last_update) 560 if (poll->seen_last_update)
561 ret = POLLIN | POLLRDNORM; 561 ret = DEFAULT_POLLMASK;
562 } 562 }
563 return ret; 563 return ret;
564} 564}
diff --git a/drivers/char/vt.c b/drivers/tty/vt/vt.c
index a8ec48ed14d9..a8ec48ed14d9 100644
--- a/drivers/char/vt.c
+++ b/drivers/tty/vt/vt.c
diff --git a/drivers/char/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 6b68a0fb4611..6b68a0fb4611 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index a858d2b87b94..51fe1795d5a8 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de> 4 * Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de>
5 * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de> 5 * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
6 * Copyright(C) 2006, Hans J. Koch <hjk@linutronix.de> 6 * Copyright(C) 2006, Hans J. Koch <hjk@hansjkoch.de>
7 * Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com> 7 * Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com>
8 * 8 *
9 * Userspace IO 9 * Userspace IO
diff --git a/drivers/uio/uio_cif.c b/drivers/uio/uio_cif.c
index a8ea2f19a0cc..a84a451159ed 100644
--- a/drivers/uio/uio_cif.c
+++ b/drivers/uio/uio_cif.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * UIO Hilscher CIF card driver 2 * UIO Hilscher CIF card driver
3 * 3 *
4 * (C) 2007 Hans J. Koch <hjk@linutronix.de> 4 * (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
5 * Original code (C) 2005 Benedikt Spranger <b.spranger@linutronix.de> 5 * Original code (C) 2005 Benedikt Spranger <b.spranger@linutronix.de>
6 * 6 *
7 * Licensed under GPL version 2 only. 7 * Licensed under GPL version 2 only.
diff --git a/drivers/uio/uio_netx.c b/drivers/uio/uio_netx.c
index 5a18e9f7b836..5ffdb483b015 100644
--- a/drivers/uio/uio_netx.c
+++ b/drivers/uio/uio_netx.c
@@ -2,7 +2,7 @@
2 * UIO driver for Hilscher NetX based fieldbus cards (cifX, comX). 2 * UIO driver for Hilscher NetX based fieldbus cards (cifX, comX).
3 * See http://www.hilscher.com for details. 3 * See http://www.hilscher.com for details.
4 * 4 *
5 * (C) 2007 Hans J. Koch <hjk@linutronix.de> 5 * (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
6 * (C) 2008 Manuel Traut <manut@linutronix.de> 6 * (C) 2008 Manuel Traut <manut@linutronix.de>
7 * 7 *
8 * Licensed under GPL version 2 only. 8 * Licensed under GPL version 2 only.
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index ea071a5b6eee..44447f54942f 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -2301,7 +2301,7 @@ out:
2301 return ret; 2301 return ret;
2302} 2302}
2303 2303
2304static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot); 2304static DEVICE_ATTR(stat_status, S_IWUSR | S_IRUGO, read_status, reboot);
2305 2305
2306static ssize_t read_human_status(struct device *dev, 2306static ssize_t read_human_status(struct device *dev,
2307 struct device_attribute *attr, char *buf) 2307 struct device_attribute *attr, char *buf)
@@ -2364,8 +2364,7 @@ out:
2364 return ret; 2364 return ret;
2365} 2365}
2366 2366
2367static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, 2367static DEVICE_ATTR(stat_human_status, S_IRUGO, read_human_status, NULL);
2368 read_human_status, NULL);
2369 2368
2370static ssize_t read_delin(struct device *dev, struct device_attribute *attr, 2369static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2371 char *buf) 2370 char *buf)
@@ -2397,7 +2396,7 @@ out:
2397 return ret; 2396 return ret;
2398} 2397}
2399 2398
2400static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL); 2399static DEVICE_ATTR(stat_delin, S_IRUGO, read_delin, NULL);
2401 2400
2402#define UEA_ATTR(name, reset) \ 2401#define UEA_ATTR(name, reset) \
2403 \ 2402 \
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 05bf5a27b5b0..989e16e4ab5c 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -951,7 +951,9 @@ static int usbatm_atm_init(struct usbatm_data *instance)
951 * condition: callbacks we register can be executed at once, before we have 951 * condition: callbacks we register can be executed at once, before we have
952 * initialized the struct atm_dev. To protect against this, all callbacks 952 * initialized the struct atm_dev. To protect against this, all callbacks
953 * abort if atm_dev->dev_data is NULL. */ 953 * abort if atm_dev->dev_data is NULL. */
954 atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL); 954 atm_dev = atm_dev_register(instance->driver_name,
955 &instance->usb_intf->dev, &usbatm_atm_devops,
956 -1, NULL);
955 if (!atm_dev) { 957 if (!atm_dev) {
956 usb_err(instance, "%s: failed to register ATM device!\n", __func__); 958 usb_err(instance, "%s: failed to register ATM device!\n", __func__);
957 return -1; 959 return -1;
@@ -966,14 +968,6 @@ static int usbatm_atm_init(struct usbatm_data *instance)
966 /* temp init ATM device, set to 128kbit */ 968 /* temp init ATM device, set to 128kbit */
967 atm_dev->link_rate = 128 * 1000 / 424; 969 atm_dev->link_rate = 128 * 1000 / 424;
968 970
969 ret = sysfs_create_link(&atm_dev->class_dev.kobj,
970 &instance->usb_intf->dev.kobj, "device");
971 if (ret) {
972 atm_err(instance, "%s: sysfs_create_link failed: %d\n",
973 __func__, ret);
974 goto fail_sysfs;
975 }
976
977 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) { 971 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
978 atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret); 972 atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret);
979 goto fail; 973 goto fail;
@@ -992,8 +986,6 @@ static int usbatm_atm_init(struct usbatm_data *instance)
992 return 0; 986 return 0;
993 987
994 fail: 988 fail:
995 sysfs_remove_link(&atm_dev->class_dev.kobj, "device");
996 fail_sysfs:
997 instance->atm_dev = NULL; 989 instance->atm_dev = NULL;
998 atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */ 990 atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */
999 return ret; 991 return ret;
@@ -1329,7 +1321,6 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1329 1321
1330 /* ATM finalize */ 1322 /* ATM finalize */
1331 if (instance->atm_dev) { 1323 if (instance->atm_dev) {
1332 sysfs_remove_link(&instance->atm_dev->class_dev.kobj, "device");
1333 atm_dev_deregister(instance->atm_dev); 1324 atm_dev_deregister(instance->atm_dev);
1334 instance->atm_dev = NULL; 1325 instance->atm_dev = NULL;
1335 } 1326 }
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index 9eed5b52d9de..bcc24779ba0e 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -107,11 +107,19 @@ config USB_SUSPEND
107 If you are unsure about this, say N here. 107 If you are unsure about this, say N here.
108 108
109config USB_OTG 109config USB_OTG
110 bool 110 bool "OTG support"
111 depends on USB && EXPERIMENTAL 111 depends on USB && EXPERIMENTAL
112 depends on USB_SUSPEND 112 depends on USB_SUSPEND
113 default n 113 default n
114 114 help
115 The most notable feature of USB OTG is support for a
116 "Dual-Role" device, which can act as either a device
117 or a host. The initial role is decided by the type of
118 plug inserted and can be changed later when two dual
119 role devices talk to each other.
120
121 Select this only if your board has Mini-AB/Micro-AB
122 connector.
115 123
116config USB_OTG_WHITELIST 124config USB_OTG_WHITELIST
117 bool "Rely on OTG Targeted Peripherals List" 125 bool "Rely on OTG Targeted Peripherals List"
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index ddb4dc980923..a3d2e2399655 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -54,7 +54,6 @@
54#include <linux/gfp.h> 54#include <linux/gfp.h>
55#include <linux/poll.h> 55#include <linux/poll.h>
56#include <linux/usb.h> 56#include <linux/usb.h>
57#include <linux/smp_lock.h>
58#include <linux/usbdevice_fs.h> 57#include <linux/usbdevice_fs.h>
59#include <linux/usb/hcd.h> 58#include <linux/usb/hcd.h>
60#include <linux/mutex.h> 59#include <linux/mutex.h>
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index f1aaff6202a5..a7131ad630f9 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -37,7 +37,6 @@
37#include <linux/fs.h> 37#include <linux/fs.h>
38#include <linux/mm.h> 38#include <linux/mm.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/smp_lock.h>
41#include <linux/signal.h> 40#include <linux/signal.h>
42#include <linux/poll.h> 41#include <linux/poll.h>
43#include <linux/module.h> 42#include <linux/module.h>
@@ -965,10 +964,11 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg)
965 964
966static int proc_connectinfo(struct dev_state *ps, void __user *arg) 965static int proc_connectinfo(struct dev_state *ps, void __user *arg)
967{ 966{
968 struct usbdevfs_connectinfo ci; 967 struct usbdevfs_connectinfo ci = {
968 .devnum = ps->dev->devnum,
969 .slow = ps->dev->speed == USB_SPEED_LOW
970 };
969 971
970 ci.devnum = ps->dev->devnum;
971 ci.slow = ps->dev->speed == USB_SPEED_LOW;
972 if (copy_to_user(arg, &ci, sizeof(ci))) 972 if (copy_to_user(arg, &ci, sizeof(ci)))
973 return -EFAULT; 973 return -EFAULT;
974 return 0; 974 return 0;
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 9fe34fb78ef1..cf6a5423de09 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -19,7 +19,6 @@
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/rwsem.h> 20#include <linux/rwsem.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/smp_lock.h>
23#include <linux/usb.h> 22#include <linux/usb.h>
24 23
25#include "usb.h" 24#include "usb.h"
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 61800f77dac8..ced846ac4141 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1330,6 +1330,8 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1330 */ 1330 */
1331 1331
1332 if (usb_endpoint_xfer_control(&urb->ep->desc)) { 1332 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
1333 if (hcd->self.uses_pio_for_control)
1334 return ret;
1333 if (hcd->self.uses_dma) { 1335 if (hcd->self.uses_dma) {
1334 urb->setup_dma = dma_map_single( 1336 urb->setup_dma = dma_map_single(
1335 hcd->self.controller, 1337 hcd->self.controller,
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 9819a4cc3b26..b690aa35df9a 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -39,7 +39,6 @@
39#include <linux/parser.h> 39#include <linux/parser.h>
40#include <linux/notifier.h> 40#include <linux/notifier.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/smp_lock.h>
43#include <linux/usb/hcd.h> 42#include <linux/usb/hcd.h>
44#include <asm/byteorder.h> 43#include <asm/byteorder.h>
45#include "usb.h" 44#include "usb.h"
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index b739ca814651..607d0db4a988 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -158,7 +158,7 @@ config USB_GADGET_FSL_USB2
158 boolean "Freescale Highspeed USB DR Peripheral Controller" 158 boolean "Freescale Highspeed USB DR Peripheral Controller"
159 depends on FSL_SOC || ARCH_MXC 159 depends on FSL_SOC || ARCH_MXC
160 select USB_GADGET_DUALSPEED 160 select USB_GADGET_DUALSPEED
161 select USB_FSL_MPH_DR_OF 161 select USB_FSL_MPH_DR_OF if OF
162 help 162 help
163 Some of Freescale PowerPC processors have a High Speed 163 Some of Freescale PowerPC processors have a High Speed
164 Dual-Role(DR) USB controller, which supports device mode. 164 Dual-Role(DR) USB controller, which supports device mode.
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index b5e20e873cba..717ff653fa23 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -2017,7 +2017,7 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2017 } 2017 }
2018 } else { 2018 } else {
2019 /* gpio_request fail so use -EINVAL for gpio_is_valid */ 2019 /* gpio_request fail so use -EINVAL for gpio_is_valid */
2020 ubc->vbus_pin = -EINVAL; 2020 udc->vbus_pin = -EINVAL;
2021 } 2021 }
2022 } 2022 }
2023 2023
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 7b5cc16e4a0b..8572dad5ecbb 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1047,9 +1047,9 @@ composite_unbind(struct usb_gadget *gadget)
1047 kfree(cdev->req->buf); 1047 kfree(cdev->req->buf);
1048 usb_ep_free_request(gadget->ep0, cdev->req); 1048 usb_ep_free_request(gadget->ep0, cdev->req);
1049 } 1049 }
1050 device_remove_file(&gadget->dev, &dev_attr_suspended);
1050 kfree(cdev); 1051 kfree(cdev);
1051 set_gadget_data(gadget, NULL); 1052 set_gadget_data(gadget, NULL);
1052 device_remove_file(&gadget->dev, &dev_attr_suspended);
1053 composite = NULL; 1053 composite = NULL;
1054} 1054}
1055 1055
@@ -1107,14 +1107,6 @@ static int composite_bind(struct usb_gadget *gadget)
1107 */ 1107 */
1108 usb_ep_autoconfig_reset(cdev->gadget); 1108 usb_ep_autoconfig_reset(cdev->gadget);
1109 1109
1110 /* standardized runtime overrides for device ID data */
1111 if (idVendor)
1112 cdev->desc.idVendor = cpu_to_le16(idVendor);
1113 if (idProduct)
1114 cdev->desc.idProduct = cpu_to_le16(idProduct);
1115 if (bcdDevice)
1116 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1117
1118 /* composite gadget needs to assign strings for whole device (like 1110 /* composite gadget needs to assign strings for whole device (like
1119 * serial number), register function drivers, potentially update 1111 * serial number), register function drivers, potentially update
1120 * power state and consumption, etc 1112 * power state and consumption, etc
@@ -1126,6 +1118,14 @@ static int composite_bind(struct usb_gadget *gadget)
1126 cdev->desc = *composite->dev; 1118 cdev->desc = *composite->dev;
1127 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket; 1119 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1128 1120
1121 /* standardized runtime overrides for device ID data */
1122 if (idVendor)
1123 cdev->desc.idVendor = cpu_to_le16(idVendor);
1124 if (idProduct)
1125 cdev->desc.idProduct = cpu_to_le16(idProduct);
1126 if (bcdDevice)
1127 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1128
1129 /* stirng overrides */ 1129 /* stirng overrides */
1130 if (iManufacturer || !cdev->desc.iManufacturer) { 1130 if (iManufacturer || !cdev->desc.iManufacturer) {
1131 if (!iManufacturer && !composite->iManufacturer && 1131 if (!iManufacturer && !composite->iManufacturer &&
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 4a830df4fc31..484c5ba5450e 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -30,7 +30,6 @@
30#include <linux/blkdev.h> 30#include <linux/blkdev.h>
31#include <linux/pagemap.h> 31#include <linux/pagemap.h>
32#include <asm/unaligned.h> 32#include <asm/unaligned.h>
33#include <linux/smp_lock.h>
34 33
35#include <linux/usb/composite.h> 34#include <linux/usb/composite.h>
36#include <linux/usb/functionfs.h> 35#include <linux/usb/functionfs.h>
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c
index 4f891eddd060..598e7e2ab80c 100644
--- a/drivers/usb/gadget/f_hid.c
+++ b/drivers/usb/gadget/f_hid.c
@@ -25,7 +25,6 @@
25#include <linux/cdev.h> 25#include <linux/cdev.h>
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/poll.h> 27#include <linux/poll.h>
28#include <linux/smp_lock.h>
29#include <linux/uaccess.h> 28#include <linux/uaccess.h>
30#include <linux/wait.h> 29#include <linux/wait.h>
31#include <linux/usb/g_hid.h> 30#include <linux/usb/g_hid.h>
diff --git a/drivers/usb/gadget/goku_udc.h b/drivers/usb/gadget/goku_udc.h
index 566cb2319056..e7e0c69d3b1f 100644
--- a/drivers/usb/gadget/goku_udc.h
+++ b/drivers/usb/gadget/goku_udc.h
@@ -251,7 +251,8 @@ struct goku_udc {
251 got_region:1, 251 got_region:1,
252 req_config:1, 252 req_config:1,
253 configured:1, 253 configured:1,
254 enabled:1; 254 enabled:1,
255 registered:1;
255 256
256 /* pci state used to access those endpoints */ 257 /* pci state used to access those endpoints */
257 struct pci_dev *pdev; 258 struct pci_dev *pdev;
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index cb23355f52d3..fbe86ca95802 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -811,7 +811,6 @@ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
811 INFO(dev, "MAC %pM\n", net->dev_addr); 811 INFO(dev, "MAC %pM\n", net->dev_addr);
812 INFO(dev, "HOST MAC %pM\n", dev->host_mac); 812 INFO(dev, "HOST MAC %pM\n", dev->host_mac);
813 813
814 netif_stop_queue(net);
815 the_dev = dev; 814 the_dev = dev;
816 } 815 }
817 816
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 01e5354a4c20..40f7716b31fc 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -105,11 +105,15 @@ struct gs_port {
105 wait_queue_head_t close_wait; /* wait for last close */ 105 wait_queue_head_t close_wait; /* wait for last close */
106 106
107 struct list_head read_pool; 107 struct list_head read_pool;
108 int read_started;
109 int read_allocated;
108 struct list_head read_queue; 110 struct list_head read_queue;
109 unsigned n_read; 111 unsigned n_read;
110 struct tasklet_struct push; 112 struct tasklet_struct push;
111 113
112 struct list_head write_pool; 114 struct list_head write_pool;
115 int write_started;
116 int write_allocated;
113 struct gs_buf port_write_buf; 117 struct gs_buf port_write_buf;
114 wait_queue_head_t drain_wait; /* wait while writes drain */ 118 wait_queue_head_t drain_wait; /* wait while writes drain */
115 119
@@ -363,6 +367,9 @@ __acquires(&port->port_lock)
363 struct usb_request *req; 367 struct usb_request *req;
364 int len; 368 int len;
365 369
370 if (port->write_started >= QUEUE_SIZE)
371 break;
372
366 req = list_entry(pool->next, struct usb_request, list); 373 req = list_entry(pool->next, struct usb_request, list);
367 len = gs_send_packet(port, req->buf, in->maxpacket); 374 len = gs_send_packet(port, req->buf, in->maxpacket);
368 if (len == 0) { 375 if (len == 0) {
@@ -397,6 +404,8 @@ __acquires(&port->port_lock)
397 break; 404 break;
398 } 405 }
399 406
407 port->write_started++;
408
400 /* abort immediately after disconnect */ 409 /* abort immediately after disconnect */
401 if (!port->port_usb) 410 if (!port->port_usb)
402 break; 411 break;
@@ -418,7 +427,6 @@ __acquires(&port->port_lock)
418{ 427{
419 struct list_head *pool = &port->read_pool; 428 struct list_head *pool = &port->read_pool;
420 struct usb_ep *out = port->port_usb->out; 429 struct usb_ep *out = port->port_usb->out;
421 unsigned started = 0;
422 430
423 while (!list_empty(pool)) { 431 while (!list_empty(pool)) {
424 struct usb_request *req; 432 struct usb_request *req;
@@ -430,6 +438,9 @@ __acquires(&port->port_lock)
430 if (!tty) 438 if (!tty)
431 break; 439 break;
432 440
441 if (port->read_started >= QUEUE_SIZE)
442 break;
443
433 req = list_entry(pool->next, struct usb_request, list); 444 req = list_entry(pool->next, struct usb_request, list);
434 list_del(&req->list); 445 list_del(&req->list);
435 req->length = out->maxpacket; 446 req->length = out->maxpacket;
@@ -447,13 +458,13 @@ __acquires(&port->port_lock)
447 list_add(&req->list, pool); 458 list_add(&req->list, pool);
448 break; 459 break;
449 } 460 }
450 started++; 461 port->read_started++;
451 462
452 /* abort immediately after disconnect */ 463 /* abort immediately after disconnect */
453 if (!port->port_usb) 464 if (!port->port_usb)
454 break; 465 break;
455 } 466 }
456 return started; 467 return port->read_started;
457} 468}
458 469
459/* 470/*
@@ -535,6 +546,7 @@ static void gs_rx_push(unsigned long _port)
535 } 546 }
536recycle: 547recycle:
537 list_move(&req->list, &port->read_pool); 548 list_move(&req->list, &port->read_pool);
549 port->read_started--;
538 } 550 }
539 551
540 /* Push from tty to ldisc; without low_latency set this is handled by 552 /* Push from tty to ldisc; without low_latency set this is handled by
@@ -587,6 +599,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
587 599
588 spin_lock(&port->port_lock); 600 spin_lock(&port->port_lock);
589 list_add(&req->list, &port->write_pool); 601 list_add(&req->list, &port->write_pool);
602 port->write_started--;
590 603
591 switch (req->status) { 604 switch (req->status) {
592 default: 605 default:
@@ -608,7 +621,8 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
608 spin_unlock(&port->port_lock); 621 spin_unlock(&port->port_lock);
609} 622}
610 623
611static void gs_free_requests(struct usb_ep *ep, struct list_head *head) 624static void gs_free_requests(struct usb_ep *ep, struct list_head *head,
625 int *allocated)
612{ 626{
613 struct usb_request *req; 627 struct usb_request *req;
614 628
@@ -616,25 +630,31 @@ static void gs_free_requests(struct usb_ep *ep, struct list_head *head)
616 req = list_entry(head->next, struct usb_request, list); 630 req = list_entry(head->next, struct usb_request, list);
617 list_del(&req->list); 631 list_del(&req->list);
618 gs_free_req(ep, req); 632 gs_free_req(ep, req);
633 if (allocated)
634 (*allocated)--;
619 } 635 }
620} 636}
621 637
622static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head, 638static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
623 void (*fn)(struct usb_ep *, struct usb_request *)) 639 void (*fn)(struct usb_ep *, struct usb_request *),
640 int *allocated)
624{ 641{
625 int i; 642 int i;
626 struct usb_request *req; 643 struct usb_request *req;
644 int n = allocated ? QUEUE_SIZE - *allocated : QUEUE_SIZE;
627 645
628 /* Pre-allocate up to QUEUE_SIZE transfers, but if we can't 646 /* Pre-allocate up to QUEUE_SIZE transfers, but if we can't
629 * do quite that many this time, don't fail ... we just won't 647 * do quite that many this time, don't fail ... we just won't
630 * be as speedy as we might otherwise be. 648 * be as speedy as we might otherwise be.
631 */ 649 */
632 for (i = 0; i < QUEUE_SIZE; i++) { 650 for (i = 0; i < n; i++) {
633 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC); 651 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
634 if (!req) 652 if (!req)
635 return list_empty(head) ? -ENOMEM : 0; 653 return list_empty(head) ? -ENOMEM : 0;
636 req->complete = fn; 654 req->complete = fn;
637 list_add_tail(&req->list, head); 655 list_add_tail(&req->list, head);
656 if (allocated)
657 (*allocated)++;
638 } 658 }
639 return 0; 659 return 0;
640} 660}
@@ -661,14 +681,15 @@ static int gs_start_io(struct gs_port *port)
661 * configurations may use different endpoints with a given port; 681 * configurations may use different endpoints with a given port;
662 * and high speed vs full speed changes packet sizes too. 682 * and high speed vs full speed changes packet sizes too.
663 */ 683 */
664 status = gs_alloc_requests(ep, head, gs_read_complete); 684 status = gs_alloc_requests(ep, head, gs_read_complete,
685 &port->read_allocated);
665 if (status) 686 if (status)
666 return status; 687 return status;
667 688
668 status = gs_alloc_requests(port->port_usb->in, &port->write_pool, 689 status = gs_alloc_requests(port->port_usb->in, &port->write_pool,
669 gs_write_complete); 690 gs_write_complete, &port->write_allocated);
670 if (status) { 691 if (status) {
671 gs_free_requests(ep, head); 692 gs_free_requests(ep, head, &port->read_allocated);
672 return status; 693 return status;
673 } 694 }
674 695
@@ -680,8 +701,9 @@ static int gs_start_io(struct gs_port *port)
680 if (started) { 701 if (started) {
681 tty_wakeup(port->port_tty); 702 tty_wakeup(port->port_tty);
682 } else { 703 } else {
683 gs_free_requests(ep, head); 704 gs_free_requests(ep, head, &port->read_allocated);
684 gs_free_requests(port->port_usb->in, &port->write_pool); 705 gs_free_requests(port->port_usb->in, &port->write_pool,
706 &port->write_allocated);
685 status = -EIO; 707 status = -EIO;
686 } 708 }
687 709
@@ -1315,8 +1337,12 @@ void gserial_disconnect(struct gserial *gser)
1315 spin_lock_irqsave(&port->port_lock, flags); 1337 spin_lock_irqsave(&port->port_lock, flags);
1316 if (port->open_count == 0 && !port->openclose) 1338 if (port->open_count == 0 && !port->openclose)
1317 gs_buf_free(&port->port_write_buf); 1339 gs_buf_free(&port->port_write_buf);
1318 gs_free_requests(gser->out, &port->read_pool); 1340 gs_free_requests(gser->out, &port->read_pool, NULL);
1319 gs_free_requests(gser->out, &port->read_queue); 1341 gs_free_requests(gser->out, &port->read_queue, NULL);
1320 gs_free_requests(gser->in, &port->write_pool); 1342 gs_free_requests(gser->in, &port->write_pool, NULL);
1343
1344 port->read_allocated = port->read_started =
1345 port->write_allocated = port->write_started = 0;
1346
1321 spin_unlock_irqrestore(&port->port_lock, flags); 1347 spin_unlock_irqrestore(&port->port_lock, flags);
1322} 1348}
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2391c396ca32..6f4f8e6a40c7 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -122,7 +122,7 @@ config USB_EHCI_FSL
122 bool "Support for Freescale on-chip EHCI USB controller" 122 bool "Support for Freescale on-chip EHCI USB controller"
123 depends on USB_EHCI_HCD && FSL_SOC 123 depends on USB_EHCI_HCD && FSL_SOC
124 select USB_EHCI_ROOT_HUB_TT 124 select USB_EHCI_ROOT_HUB_TT
125 select USB_FSL_MPH_DR_OF 125 select USB_FSL_MPH_DR_OF if OF
126 ---help--- 126 ---help---
127 Variation of ARC USB block used in some Freescale chips. 127 Variation of ARC USB block used in some Freescale chips.
128 128
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 86afdc73322f..6e2599661b5b 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -1067,7 +1067,7 @@ static inline void create_debug_files (struct ehci_hcd *ehci)
1067 &debug_registers_fops)) 1067 &debug_registers_fops))
1068 goto file_error; 1068 goto file_error;
1069 1069
1070 if (!debugfs_create_file("lpm", S_IRUGO|S_IWUGO, ehci->debug_dir, bus, 1070 if (!debugfs_create_file("lpm", S_IRUGO|S_IWUSR, ehci->debug_dir, bus,
1071 &debug_lpm_fops)) 1071 &debug_lpm_fops))
1072 goto file_error; 1072 goto file_error;
1073 1073
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 502a7e6fef42..e9062806d4a2 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1063,10 +1063,11 @@ rescan:
1063 tmp && tmp != qh; 1063 tmp && tmp != qh;
1064 tmp = tmp->qh_next.qh) 1064 tmp = tmp->qh_next.qh)
1065 continue; 1065 continue;
1066 /* periodic qh self-unlinks on empty */ 1066 /* periodic qh self-unlinks on empty, and a COMPLETING qh
1067 if (!tmp) 1067 * may already be unlinked.
1068 goto nogood; 1068 */
1069 unlink_async (ehci, qh); 1069 if (tmp)
1070 unlink_async(ehci, qh);
1070 /* FALL THROUGH */ 1071 /* FALL THROUGH */
1071 case QH_STATE_UNLINK: /* wait for hw to finish? */ 1072 case QH_STATE_UNLINK: /* wait for hw to finish? */
1072 case QH_STATE_UNLINK_WAIT: 1073 case QH_STATE_UNLINK_WAIT:
@@ -1083,7 +1084,6 @@ idle_timeout:
1083 } 1084 }
1084 /* else FALL THROUGH */ 1085 /* else FALL THROUGH */
1085 default: 1086 default:
1086nogood:
1087 /* caller was supposed to have unlinked any requests; 1087 /* caller was supposed to have unlinked any requests;
1088 * that's not our job. just leak this memory. 1088 * that's not our job. just leak this memory.
1089 */ 1089 */
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index d36e4e75e08d..12f70c302b0b 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -141,6 +141,10 @@ static void ehci_mem_cleanup (struct ehci_hcd *ehci)
141 qh_put (ehci->async); 141 qh_put (ehci->async);
142 ehci->async = NULL; 142 ehci->async = NULL;
143 143
144 if (ehci->dummy)
145 qh_put(ehci->dummy);
146 ehci->dummy = NULL;
147
144 /* DMA consistent memory and pools */ 148 /* DMA consistent memory and pools */
145 if (ehci->qtd_pool) 149 if (ehci->qtd_pool)
146 dma_pool_destroy (ehci->qtd_pool); 150 dma_pool_destroy (ehci->qtd_pool);
@@ -227,8 +231,26 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
227 if (ehci->periodic == NULL) { 231 if (ehci->periodic == NULL) {
228 goto fail; 232 goto fail;
229 } 233 }
230 for (i = 0; i < ehci->periodic_size; i++) 234
231 ehci->periodic [i] = EHCI_LIST_END(ehci); 235 if (ehci->use_dummy_qh) {
236 struct ehci_qh_hw *hw;
237 ehci->dummy = ehci_qh_alloc(ehci, flags);
238 if (!ehci->dummy)
239 goto fail;
240
241 hw = ehci->dummy->hw;
242 hw->hw_next = EHCI_LIST_END(ehci);
243 hw->hw_qtd_next = EHCI_LIST_END(ehci);
244 hw->hw_alt_next = EHCI_LIST_END(ehci);
245 hw->hw_token &= ~QTD_STS_ACTIVE;
246 ehci->dummy->hw = hw;
247
248 for (i = 0; i < ehci->periodic_size; i++)
249 ehci->periodic[i] = ehci->dummy->qh_dma;
250 } else {
251 for (i = 0; i < ehci->periodic_size; i++)
252 ehci->periodic[i] = EHCI_LIST_END(ehci);
253 }
232 254
233 /* software shadow of hardware table */ 255 /* software shadow of hardware table */
234 ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags); 256 ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags);
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
index ac9c4d7c44af..bce85055019a 100644
--- a/drivers/usb/host/ehci-mxc.c
+++ b/drivers/usb/host/ehci-mxc.c
@@ -36,6 +36,8 @@ struct ehci_mxc_priv {
36static int ehci_mxc_setup(struct usb_hcd *hcd) 36static int ehci_mxc_setup(struct usb_hcd *hcd)
37{ 37{
38 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 38 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
39 struct device *dev = hcd->self.controller;
40 struct mxc_usbh_platform_data *pdata = dev_get_platdata(dev);
39 int retval; 41 int retval;
40 42
41 /* EHCI registers start at offset 0x100 */ 43 /* EHCI registers start at offset 0x100 */
@@ -63,6 +65,12 @@ static int ehci_mxc_setup(struct usb_hcd *hcd)
63 65
64 ehci_reset(ehci); 66 ehci_reset(ehci);
65 67
68 /* set up the PORTSCx register */
69 ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]);
70
71 /* is this really needed? */
72 msleep(10);
73
66 ehci_port_power(ehci, 0); 74 ehci_port_power(ehci, 0);
67 return 0; 75 return 0;
68} 76}
@@ -114,7 +122,7 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
114 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; 122 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
115 struct usb_hcd *hcd; 123 struct usb_hcd *hcd;
116 struct resource *res; 124 struct resource *res;
117 int irq, ret, temp; 125 int irq, ret;
118 struct ehci_mxc_priv *priv; 126 struct ehci_mxc_priv *priv;
119 struct device *dev = &pdev->dev; 127 struct device *dev = &pdev->dev;
120 128
@@ -188,10 +196,6 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
188 clk_enable(priv->ahbclk); 196 clk_enable(priv->ahbclk);
189 } 197 }
190 198
191 /* set up the PORTSCx register */
192 ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]);
193 mdelay(10);
194
195 /* setup specific usb hw */ 199 /* setup specific usb hw */
196 ret = mxc_initialize_usb_hw(pdev->id, pdata->flags); 200 ret = mxc_initialize_usb_hw(pdev->id, pdata->flags);
197 if (ret < 0) 201 if (ret < 0)
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index a1e8d273103f..655f3c9f88bf 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -103,6 +103,19 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
103 if (retval) 103 if (retval)
104 return retval; 104 return retval;
105 105
106 if ((pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x7808) ||
107 (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x4396)) {
108 /* EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
109 * read/write memory space which does not belong to it when
110 * there is NULL pointer with T-bit set to 1 in the frame list
111 * table. To avoid the issue, the frame list link pointer
112 * should always contain a valid pointer to a inactive qh.
113 */
114 ehci->use_dummy_qh = 1;
115 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI "
116 "dummy qh workaround\n");
117 }
118
106 /* data structure init */ 119 /* data structure init */
107 retval = ehci_init(hcd); 120 retval = ehci_init(hcd);
108 if (retval) 121 if (retval)
@@ -148,6 +161,18 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
148 if (pdev->revision < 0xa4) 161 if (pdev->revision < 0xa4)
149 ehci->no_selective_suspend = 1; 162 ehci->no_selective_suspend = 1;
150 break; 163 break;
164
165 /* MCP89 chips on the MacBookAir3,1 give EPROTO when
166 * fetching device descriptors unless LPM is disabled.
167 * There are also intermittent problems enumerating
168 * devices with PPCD enabled.
169 */
170 case 0x0d9d:
171 ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89");
172 ehci->has_lpm = 0;
173 ehci->has_ppcd = 0;
174 ehci->command &= ~CMD_PPCEE;
175 break;
151 } 176 }
152 break; 177 break;
153 case PCI_VENDOR_ID_VIA: 178 case PCI_VENDOR_ID_VIA:
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index a92526d6e5ae..d9f78eb26572 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -98,7 +98,14 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
98 */ 98 */
99 *prev_p = *periodic_next_shadow(ehci, &here, 99 *prev_p = *periodic_next_shadow(ehci, &here,
100 Q_NEXT_TYPE(ehci, *hw_p)); 100 Q_NEXT_TYPE(ehci, *hw_p));
101 *hw_p = *shadow_next_periodic(ehci, &here, Q_NEXT_TYPE(ehci, *hw_p)); 101
102 if (!ehci->use_dummy_qh ||
103 *shadow_next_periodic(ehci, &here, Q_NEXT_TYPE(ehci, *hw_p))
104 != EHCI_LIST_END(ehci))
105 *hw_p = *shadow_next_periodic(ehci, &here,
106 Q_NEXT_TYPE(ehci, *hw_p));
107 else
108 *hw_p = ehci->dummy->qh_dma;
102} 109}
103 110
104/* how many of the uframe's 125 usecs are allocated? */ 111/* how many of the uframe's 125 usecs are allocated? */
@@ -2335,7 +2342,11 @@ restart:
2335 * pointer for much longer, if at all. 2342 * pointer for much longer, if at all.
2336 */ 2343 */
2337 *q_p = q.itd->itd_next; 2344 *q_p = q.itd->itd_next;
2338 *hw_p = q.itd->hw_next; 2345 if (!ehci->use_dummy_qh ||
2346 q.itd->hw_next != EHCI_LIST_END(ehci))
2347 *hw_p = q.itd->hw_next;
2348 else
2349 *hw_p = ehci->dummy->qh_dma;
2339 type = Q_NEXT_TYPE(ehci, q.itd->hw_next); 2350 type = Q_NEXT_TYPE(ehci, q.itd->hw_next);
2340 wmb(); 2351 wmb();
2341 modified = itd_complete (ehci, q.itd); 2352 modified = itd_complete (ehci, q.itd);
@@ -2368,7 +2379,11 @@ restart:
2368 * URB completion. 2379 * URB completion.
2369 */ 2380 */
2370 *q_p = q.sitd->sitd_next; 2381 *q_p = q.sitd->sitd_next;
2371 *hw_p = q.sitd->hw_next; 2382 if (!ehci->use_dummy_qh ||
2383 q.sitd->hw_next != EHCI_LIST_END(ehci))
2384 *hw_p = q.sitd->hw_next;
2385 else
2386 *hw_p = ehci->dummy->qh_dma;
2372 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); 2387 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
2373 wmb(); 2388 wmb();
2374 modified = sitd_complete (ehci, q.sitd); 2389 modified = sitd_complete (ehci, q.sitd);
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index bde823f704e9..ba8eab366b82 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -73,6 +73,7 @@ struct ehci_hcd { /* one per controller */
73 73
74 /* async schedule support */ 74 /* async schedule support */
75 struct ehci_qh *async; 75 struct ehci_qh *async;
76 struct ehci_qh *dummy; /* For AMD quirk use */
76 struct ehci_qh *reclaim; 77 struct ehci_qh *reclaim;
77 unsigned scanning : 1; 78 unsigned scanning : 1;
78 79
@@ -131,6 +132,7 @@ struct ehci_hcd { /* one per controller */
131 unsigned need_io_watchdog:1; 132 unsigned need_io_watchdog:1;
132 unsigned broken_periodic:1; 133 unsigned broken_periodic:1;
133 unsigned fs_i_thresh:1; /* Intel iso scheduling */ 134 unsigned fs_i_thresh:1; /* Intel iso scheduling */
135 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
134 136
135 /* required for usb32 quirk */ 137 /* required for usb32 quirk */
136 #define OHCI_CTRL_HCFS (3 << 6) 138 #define OHCI_CTRL_HCFS (3 << 6)
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 8196fa11fec4..43a39eb56cc6 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -70,7 +70,6 @@
70#include <linux/ioport.h> 70#include <linux/ioport.h>
71#include <linux/sched.h> 71#include <linux/sched.h>
72#include <linux/slab.h> 72#include <linux/slab.h>
73#include <linux/smp_lock.h>
74#include <linux/errno.h> 73#include <linux/errno.h>
75#include <linux/init.h> 74#include <linux/init.h>
76#include <linux/list.h> 75#include <linux/list.h>
@@ -2684,7 +2683,7 @@ static int __devexit isp1362_remove(struct platform_device *pdev)
2684 return 0; 2683 return 0;
2685} 2684}
2686 2685
2687static int __init isp1362_probe(struct platform_device *pdev) 2686static int __devinit isp1362_probe(struct platform_device *pdev)
2688{ 2687{
2689 struct usb_hcd *hcd; 2688 struct usb_hcd *hcd;
2690 struct isp1362_hcd *isp1362_hcd; 2689 struct isp1362_hcd *isp1362_hcd;
diff --git a/drivers/usb/host/ohci-jz4740.c b/drivers/usb/host/ohci-jz4740.c
index 10e1872f3ab9..931d588c3fb5 100644
--- a/drivers/usb/host/ohci-jz4740.c
+++ b/drivers/usb/host/ohci-jz4740.c
@@ -273,4 +273,4 @@ static struct platform_driver ohci_hcd_jz4740_driver = {
273 }, 273 },
274}; 274};
275 275
276MODULE_ALIAS("platfrom:jz4740-ohci"); 276MODULE_ALIAS("platform:jz4740-ohci");
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 6e7fb5f38db6..ee60cd3ea642 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -12,7 +12,6 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/debugfs.h> 14#include <linux/debugfs.h>
15#include <linux/smp_lock.h>
16#include <asm/io.h> 15#include <asm/io.h>
17 16
18#include "uhci-hcd.h" 17#include "uhci-hcd.h"
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index fef5a1f9d483..5d963e350494 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -229,6 +229,13 @@ void xhci_ring_device(struct xhci_hcd *xhci, int slot_id)
229static void xhci_disable_port(struct xhci_hcd *xhci, u16 wIndex, 229static void xhci_disable_port(struct xhci_hcd *xhci, u16 wIndex,
230 u32 __iomem *addr, u32 port_status) 230 u32 __iomem *addr, u32 port_status)
231{ 231{
232 /* Don't allow the USB core to disable SuperSpeed ports. */
233 if (xhci->port_array[wIndex] == 0x03) {
234 xhci_dbg(xhci, "Ignoring request to disable "
235 "SuperSpeed port.\n");
236 return;
237 }
238
232 /* Write 1 to disable the port */ 239 /* Write 1 to disable the port */
233 xhci_writel(xhci, port_status | PORT_PE, addr); 240 xhci_writel(xhci, port_status | PORT_PE, addr);
234 port_status = xhci_readl(xhci, addr); 241 port_status = xhci_readl(xhci, addr);
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 202770676da3..1d0f45f0e7a6 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1045,7 +1045,7 @@ static inline u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci,
1045 if (udev->speed == USB_SPEED_SUPER) 1045 if (udev->speed == USB_SPEED_SUPER)
1046 return ep->ss_ep_comp.wBytesPerInterval; 1046 return ep->ss_ep_comp.wBytesPerInterval;
1047 1047
1048 max_packet = ep->desc.wMaxPacketSize & 0x3ff; 1048 max_packet = GET_MAX_PACKET(ep->desc.wMaxPacketSize);
1049 max_burst = (ep->desc.wMaxPacketSize & 0x1800) >> 11; 1049 max_burst = (ep->desc.wMaxPacketSize & 0x1800) >> 11;
1050 /* A 0 in max burst means 1 transfer per ESIT */ 1050 /* A 0 in max burst means 1 transfer per ESIT */
1051 return max_packet * (max_burst + 1); 1051 return max_packet * (max_burst + 1);
@@ -1135,7 +1135,7 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1135 /* Fall through */ 1135 /* Fall through */
1136 case USB_SPEED_FULL: 1136 case USB_SPEED_FULL:
1137 case USB_SPEED_LOW: 1137 case USB_SPEED_LOW:
1138 max_packet = ep->desc.wMaxPacketSize & 0x3ff; 1138 max_packet = GET_MAX_PACKET(ep->desc.wMaxPacketSize);
1139 ep_ctx->ep_info2 |= MAX_PACKET(max_packet); 1139 ep_ctx->ep_info2 |= MAX_PACKET(max_packet);
1140 break; 1140 break;
1141 default: 1141 default:
@@ -1443,6 +1443,13 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1443 xhci->dcbaa = NULL; 1443 xhci->dcbaa = NULL;
1444 1444
1445 scratchpad_free(xhci); 1445 scratchpad_free(xhci);
1446
1447 xhci->num_usb2_ports = 0;
1448 xhci->num_usb3_ports = 0;
1449 kfree(xhci->usb2_ports);
1450 kfree(xhci->usb3_ports);
1451 kfree(xhci->port_array);
1452
1446 xhci->page_size = 0; 1453 xhci->page_size = 0;
1447 xhci->page_shift = 0; 1454 xhci->page_shift = 0;
1448 xhci->bus_suspended = 0; 1455 xhci->bus_suspended = 0;
@@ -1627,6 +1634,166 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
1627 &xhci->ir_set->erst_dequeue); 1634 &xhci->ir_set->erst_dequeue);
1628} 1635}
1629 1636
1637static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
1638 u32 __iomem *addr, u8 major_revision)
1639{
1640 u32 temp, port_offset, port_count;
1641 int i;
1642
1643 if (major_revision > 0x03) {
1644 xhci_warn(xhci, "Ignoring unknown port speed, "
1645 "Ext Cap %p, revision = 0x%x\n",
1646 addr, major_revision);
1647 /* Ignoring port protocol we can't understand. FIXME */
1648 return;
1649 }
1650
1651 /* Port offset and count in the third dword, see section 7.2 */
1652 temp = xhci_readl(xhci, addr + 2);
1653 port_offset = XHCI_EXT_PORT_OFF(temp);
1654 port_count = XHCI_EXT_PORT_COUNT(temp);
1655 xhci_dbg(xhci, "Ext Cap %p, port offset = %u, "
1656 "count = %u, revision = 0x%x\n",
1657 addr, port_offset, port_count, major_revision);
1658 /* Port count includes the current port offset */
1659 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports)
1660 /* WTF? "Valid values are ‘1’ to MaxPorts" */
1661 return;
1662 port_offset--;
1663 for (i = port_offset; i < (port_offset + port_count); i++) {
1664 /* Duplicate entry. Ignore the port if the revisions differ. */
1665 if (xhci->port_array[i] != 0) {
1666 xhci_warn(xhci, "Duplicate port entry, Ext Cap %p,"
1667 " port %u\n", addr, i);
1668 xhci_warn(xhci, "Port was marked as USB %u, "
1669 "duplicated as USB %u\n",
1670 xhci->port_array[i], major_revision);
1671 /* Only adjust the roothub port counts if we haven't
1672 * found a similar duplicate.
1673 */
1674 if (xhci->port_array[i] != major_revision &&
1675 xhci->port_array[i] != (u8) -1) {
1676 if (xhci->port_array[i] == 0x03)
1677 xhci->num_usb3_ports--;
1678 else
1679 xhci->num_usb2_ports--;
1680 xhci->port_array[i] = (u8) -1;
1681 }
1682 /* FIXME: Should we disable the port? */
1683 continue;
1684 }
1685 xhci->port_array[i] = major_revision;
1686 if (major_revision == 0x03)
1687 xhci->num_usb3_ports++;
1688 else
1689 xhci->num_usb2_ports++;
1690 }
1691 /* FIXME: Should we disable ports not in the Extended Capabilities? */
1692}
1693
1694/*
1695 * Scan the Extended Capabilities for the "Supported Protocol Capabilities" that
1696 * specify what speeds each port is supposed to be. We can't count on the port
1697 * speed bits in the PORTSC register being correct until a device is connected,
1698 * but we need to set up the two fake roothubs with the correct number of USB
1699 * 3.0 and USB 2.0 ports at host controller initialization time.
1700 */
1701static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
1702{
1703 u32 __iomem *addr;
1704 u32 offset;
1705 unsigned int num_ports;
1706 int i, port_index;
1707
1708 addr = &xhci->cap_regs->hcc_params;
1709 offset = XHCI_HCC_EXT_CAPS(xhci_readl(xhci, addr));
1710 if (offset == 0) {
1711 xhci_err(xhci, "No Extended Capability registers, "
1712 "unable to set up roothub.\n");
1713 return -ENODEV;
1714 }
1715
1716 num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1717 xhci->port_array = kzalloc(sizeof(*xhci->port_array)*num_ports, flags);
1718 if (!xhci->port_array)
1719 return -ENOMEM;
1720
1721 /*
1722 * For whatever reason, the first capability offset is from the
1723 * capability register base, not from the HCCPARAMS register.
1724 * See section 5.3.6 for offset calculation.
1725 */
1726 addr = &xhci->cap_regs->hc_capbase + offset;
1727 while (1) {
1728 u32 cap_id;
1729
1730 cap_id = xhci_readl(xhci, addr);
1731 if (XHCI_EXT_CAPS_ID(cap_id) == XHCI_EXT_CAPS_PROTOCOL)
1732 xhci_add_in_port(xhci, num_ports, addr,
1733 (u8) XHCI_EXT_PORT_MAJOR(cap_id));
1734 offset = XHCI_EXT_CAPS_NEXT(cap_id);
1735 if (!offset || (xhci->num_usb2_ports + xhci->num_usb3_ports)
1736 == num_ports)
1737 break;
1738 /*
1739 * Once you're into the Extended Capabilities, the offset is
1740 * always relative to the register holding the offset.
1741 */
1742 addr += offset;
1743 }
1744
1745 if (xhci->num_usb2_ports == 0 && xhci->num_usb3_ports == 0) {
1746 xhci_warn(xhci, "No ports on the roothubs?\n");
1747 return -ENODEV;
1748 }
1749 xhci_dbg(xhci, "Found %u USB 2.0 ports and %u USB 3.0 ports.\n",
1750 xhci->num_usb2_ports, xhci->num_usb3_ports);
1751 /*
1752 * Note we could have all USB 3.0 ports, or all USB 2.0 ports.
1753 * Not sure how the USB core will handle a hub with no ports...
1754 */
1755 if (xhci->num_usb2_ports) {
1756 xhci->usb2_ports = kmalloc(sizeof(*xhci->usb2_ports)*
1757 xhci->num_usb2_ports, flags);
1758 if (!xhci->usb2_ports)
1759 return -ENOMEM;
1760
1761 port_index = 0;
1762 for (i = 0; i < num_ports; i++) {
1763 if (xhci->port_array[i] == 0x03 ||
1764 xhci->port_array[i] == 0 ||
1765 xhci->port_array[i] == -1)
1766 continue;
1767
1768 xhci->usb2_ports[port_index] =
1769 &xhci->op_regs->port_status_base +
1770 NUM_PORT_REGS*i;
1771 xhci_dbg(xhci, "USB 2.0 port at index %u, "
1772 "addr = %p\n", i,
1773 xhci->usb2_ports[port_index]);
1774 port_index++;
1775 }
1776 }
1777 if (xhci->num_usb3_ports) {
1778 xhci->usb3_ports = kmalloc(sizeof(*xhci->usb3_ports)*
1779 xhci->num_usb3_ports, flags);
1780 if (!xhci->usb3_ports)
1781 return -ENOMEM;
1782
1783 port_index = 0;
1784 for (i = 0; i < num_ports; i++)
1785 if (xhci->port_array[i] == 0x03) {
1786 xhci->usb3_ports[port_index] =
1787 &xhci->op_regs->port_status_base +
1788 NUM_PORT_REGS*i;
1789 xhci_dbg(xhci, "USB 3.0 port at index %u, "
1790 "addr = %p\n", i,
1791 xhci->usb3_ports[port_index]);
1792 port_index++;
1793 }
1794 }
1795 return 0;
1796}
1630 1797
1631int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) 1798int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1632{ 1799{
@@ -1809,6 +1976,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1809 1976
1810 if (scratchpad_alloc(xhci, flags)) 1977 if (scratchpad_alloc(xhci, flags))
1811 goto fail; 1978 goto fail;
1979 if (xhci_setup_port_arrays(xhci, flags))
1980 goto fail;
1812 1981
1813 return 0; 1982 return 0;
1814 1983
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 9f3115e729b1..df558f6f84e3 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2104,7 +2104,6 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
2104 2104
2105 if (!(status & STS_EINT)) { 2105 if (!(status & STS_EINT)) {
2106 spin_unlock(&xhci->lock); 2106 spin_unlock(&xhci->lock);
2107 xhci_warn(xhci, "Spurious interrupt.\n");
2108 return IRQ_NONE; 2107 return IRQ_NONE;
2109 } 2108 }
2110 xhci_dbg(xhci, "op reg status = %08x\n", status); 2109 xhci_dbg(xhci, "op reg status = %08x\n", status);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 5d7d4e951ea4..45e4a3108cc3 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -577,6 +577,65 @@ static void xhci_restore_registers(struct xhci_hcd *xhci)
577 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base); 577 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base);
578} 578}
579 579
580static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
581{
582 u64 val_64;
583
584 /* step 2: initialize command ring buffer */
585 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
586 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
587 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
588 xhci->cmd_ring->dequeue) &
589 (u64) ~CMD_RING_RSVD_BITS) |
590 xhci->cmd_ring->cycle_state;
591 xhci_dbg(xhci, "// Setting command ring address to 0x%llx\n",
592 (long unsigned long) val_64);
593 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
594}
595
596/*
597 * The whole command ring must be cleared to zero when we suspend the host.
598 *
599 * The host doesn't save the command ring pointer in the suspend well, so we
600 * need to re-program it on resume. Unfortunately, the pointer must be 64-byte
601 * aligned, because of the reserved bits in the command ring dequeue pointer
602 * register. Therefore, we can't just set the dequeue pointer back in the
603 * middle of the ring (TRBs are 16-byte aligned).
604 */
605static void xhci_clear_command_ring(struct xhci_hcd *xhci)
606{
607 struct xhci_ring *ring;
608 struct xhci_segment *seg;
609
610 ring = xhci->cmd_ring;
611 seg = ring->deq_seg;
612 do {
613 memset(seg->trbs, 0, SEGMENT_SIZE);
614 seg = seg->next;
615 } while (seg != ring->deq_seg);
616
617 /* Reset the software enqueue and dequeue pointers */
618 ring->deq_seg = ring->first_seg;
619 ring->dequeue = ring->first_seg->trbs;
620 ring->enq_seg = ring->deq_seg;
621 ring->enqueue = ring->dequeue;
622
623 /*
624 * Ring is now zeroed, so the HW should look for change of ownership
625 * when the cycle bit is set to 1.
626 */
627 ring->cycle_state = 1;
628
629 /*
630 * Reset the hardware dequeue pointer.
631 * Yes, this will need to be re-written after resume, but we're paranoid
632 * and want to make sure the hardware doesn't access bogus memory
633 * because, say, the BIOS or an SMI started the host without changing
634 * the command ring pointers.
635 */
636 xhci_set_cmd_ring_deq(xhci);
637}
638
580/* 639/*
581 * Stop HC (not bus-specific) 640 * Stop HC (not bus-specific)
582 * 641 *
@@ -604,6 +663,7 @@ int xhci_suspend(struct xhci_hcd *xhci)
604 spin_unlock_irq(&xhci->lock); 663 spin_unlock_irq(&xhci->lock);
605 return -ETIMEDOUT; 664 return -ETIMEDOUT;
606 } 665 }
666 xhci_clear_command_ring(xhci);
607 667
608 /* step 3: save registers */ 668 /* step 3: save registers */
609 xhci_save_registers(xhci); 669 xhci_save_registers(xhci);
@@ -635,7 +695,6 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
635 u32 command, temp = 0; 695 u32 command, temp = 0;
636 struct usb_hcd *hcd = xhci_to_hcd(xhci); 696 struct usb_hcd *hcd = xhci_to_hcd(xhci);
637 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 697 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
638 u64 val_64;
639 int old_state, retval; 698 int old_state, retval;
640 699
641 old_state = hcd->state; 700 old_state = hcd->state;
@@ -648,15 +707,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
648 /* step 1: restore register */ 707 /* step 1: restore register */
649 xhci_restore_registers(xhci); 708 xhci_restore_registers(xhci);
650 /* step 2: initialize command ring buffer */ 709 /* step 2: initialize command ring buffer */
651 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); 710 xhci_set_cmd_ring_deq(xhci);
652 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
653 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
654 xhci->cmd_ring->dequeue) &
655 (u64) ~CMD_RING_RSVD_BITS) |
656 xhci->cmd_ring->cycle_state;
657 xhci_dbg(xhci, "// Setting command ring address to 0x%llx\n",
658 (long unsigned long) val_64);
659 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
660 /* step 3: restore state and start state*/ 711 /* step 3: restore state and start state*/
661 /* step 3: set CRS flag */ 712 /* step 3: set CRS flag */
662 command = xhci_readl(xhci, &xhci->op_regs->command); 713 command = xhci_readl(xhci, &xhci->op_regs->command);
@@ -714,6 +765,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
714 return retval; 765 return retval;
715 } 766 }
716 767
768 spin_unlock_irq(&xhci->lock);
717 /* Re-setup MSI-X */ 769 /* Re-setup MSI-X */
718 if (hcd->irq) 770 if (hcd->irq)
719 free_irq(hcd->irq, hcd); 771 free_irq(hcd->irq, hcd);
@@ -736,6 +788,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
736 hcd->irq = pdev->irq; 788 hcd->irq = pdev->irq;
737 } 789 }
738 790
791 spin_lock_irq(&xhci->lock);
739 /* step 4: set Run/Stop bit */ 792 /* step 4: set Run/Stop bit */
740 command = xhci_readl(xhci, &xhci->op_regs->command); 793 command = xhci_readl(xhci, &xhci->op_regs->command);
741 command |= CMD_RUN; 794 command |= CMD_RUN;
@@ -1496,6 +1549,15 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1496 cmd_completion = command->completion; 1549 cmd_completion = command->completion;
1497 cmd_status = &command->status; 1550 cmd_status = &command->status;
1498 command->command_trb = xhci->cmd_ring->enqueue; 1551 command->command_trb = xhci->cmd_ring->enqueue;
1552
1553 /* Enqueue pointer can be left pointing to the link TRB,
1554 * we must handle that
1555 */
1556 if ((command->command_trb->link.control & TRB_TYPE_BITMASK)
1557 == TRB_TYPE(TRB_LINK))
1558 command->command_trb =
1559 xhci->cmd_ring->enq_seg->next->trbs;
1560
1499 list_add_tail(&command->cmd_list, &virt_dev->cmd_list); 1561 list_add_tail(&command->cmd_list, &virt_dev->cmd_list);
1500 } else { 1562 } else {
1501 in_ctx = virt_dev->in_ctx; 1563 in_ctx = virt_dev->in_ctx;
@@ -2219,6 +2281,15 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
2219 /* Attempt to submit the Reset Device command to the command ring */ 2281 /* Attempt to submit the Reset Device command to the command ring */
2220 spin_lock_irqsave(&xhci->lock, flags); 2282 spin_lock_irqsave(&xhci->lock, flags);
2221 reset_device_cmd->command_trb = xhci->cmd_ring->enqueue; 2283 reset_device_cmd->command_trb = xhci->cmd_ring->enqueue;
2284
2285 /* Enqueue pointer can be left pointing to the link TRB,
2286 * we must handle that
2287 */
2288 if ((reset_device_cmd->command_trb->link.control & TRB_TYPE_BITMASK)
2289 == TRB_TYPE(TRB_LINK))
2290 reset_device_cmd->command_trb =
2291 xhci->cmd_ring->enq_seg->next->trbs;
2292
2222 list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list); 2293 list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list);
2223 ret = xhci_queue_reset_device(xhci, slot_id); 2294 ret = xhci_queue_reset_device(xhci, slot_id);
2224 if (ret) { 2295 if (ret) {
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 93d3bf4d213c..170c367112d2 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -454,6 +454,24 @@ struct xhci_doorbell_array {
454 454
455 455
456/** 456/**
457 * struct xhci_protocol_caps
458 * @revision: major revision, minor revision, capability ID,
459 * and next capability pointer.
460 * @name_string: Four ASCII characters to say which spec this xHC
461 * follows, typically "USB ".
462 * @port_info: Port offset, count, and protocol-defined information.
463 */
464struct xhci_protocol_caps {
465 u32 revision;
466 u32 name_string;
467 u32 port_info;
468};
469
470#define XHCI_EXT_PORT_MAJOR(x) (((x) >> 24) & 0xff)
471#define XHCI_EXT_PORT_OFF(x) ((x) & 0xff)
472#define XHCI_EXT_PORT_COUNT(x) (((x) >> 8) & 0xff)
473
474/**
457 * struct xhci_container_ctx 475 * struct xhci_container_ctx
458 * @type: Type of context. Used to calculated offsets to contained contexts. 476 * @type: Type of context. Used to calculated offsets to contained contexts.
459 * @size: Size of the context data 477 * @size: Size of the context data
@@ -621,6 +639,11 @@ struct xhci_ep_ctx {
621#define MAX_PACKET_MASK (0xffff << 16) 639#define MAX_PACKET_MASK (0xffff << 16)
622#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff) 640#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
623 641
642/* Get max packet size from ep desc. Bit 10..0 specify the max packet size.
643 * USB2.0 spec 9.6.6.
644 */
645#define GET_MAX_PACKET(p) ((p) & 0x7ff)
646
624/* tx_info bitmasks */ 647/* tx_info bitmasks */
625#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff) 648#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff)
626#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16) 649#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16)
@@ -1235,6 +1258,14 @@ struct xhci_hcd {
1235 u32 suspended_ports[8]; /* which ports are 1258 u32 suspended_ports[8]; /* which ports are
1236 suspended */ 1259 suspended */
1237 unsigned long resume_done[MAX_HC_PORTS]; 1260 unsigned long resume_done[MAX_HC_PORTS];
1261 /* Is each xHCI roothub port a USB 3.0, USB 2.0, or USB 1.1 port? */
1262 u8 *port_array;
1263 /* Array of pointers to USB 3.0 PORTSC registers */
1264 u32 __iomem **usb3_ports;
1265 unsigned int num_usb3_ports;
1266 /* Array of pointers to USB 2.0 PORTSC registers */
1267 u32 __iomem **usb2_ports;
1268 unsigned int num_usb2_ports;
1238}; 1269};
1239 1270
1240/* For testing purposes */ 1271/* For testing purposes */
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 5a47805d9580..c90c89dc0003 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -364,7 +364,7 @@ static int mts_scsi_host_reset(struct scsi_cmnd *srb)
364} 364}
365 365
366static int 366static int
367mts_scsi_queuecommand(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback); 367mts_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *srb);
368 368
369static void mts_transfer_cleanup( struct urb *transfer ); 369static void mts_transfer_cleanup( struct urb *transfer );
370static void mts_do_sg(struct urb * transfer); 370static void mts_do_sg(struct urb * transfer);
@@ -573,7 +573,7 @@ mts_build_transfer_context(struct scsi_cmnd *srb, struct mts_desc* desc)
573 573
574 574
575static int 575static int
576mts_scsi_queuecommand(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback) 576mts_scsi_queuecommand_lck(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback)
577{ 577{
578 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); 578 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
579 int err = 0; 579 int err = 0;
@@ -626,6 +626,8 @@ out:
626 return err; 626 return err;
627} 627}
628 628
629static DEF_SCSI_QCMD(mts_scsi_queuecommand)
630
629static struct scsi_host_template mts_scsi_host_template = { 631static struct scsi_host_template mts_scsi_host_template = {
630 .module = THIS_MODULE, 632 .module = THIS_MODULE,
631 .name = "microtekX6", 633 .name = "microtekX6",
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c
index 2f43c57743c9..9251773ecef4 100644
--- a/drivers/usb/misc/cypress_cy7c63.c
+++ b/drivers/usb/misc/cypress_cy7c63.c
@@ -196,11 +196,9 @@ static ssize_t get_port1_handler(struct device *dev,
196 return read_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1); 196 return read_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1);
197} 197}
198 198
199static DEVICE_ATTR(port0, S_IWUGO | S_IRUGO, 199static DEVICE_ATTR(port0, S_IRUGO | S_IWUSR, get_port0_handler, set_port0_handler);
200 get_port0_handler, set_port0_handler);
201 200
202static DEVICE_ATTR(port1, S_IWUGO | S_IRUGO, 201static DEVICE_ATTR(port1, S_IRUGO | S_IWUSR, get_port1_handler, set_port1_handler);
203 get_port1_handler, set_port1_handler);
204 202
205 203
206static int cypress_probe(struct usb_interface *interface, 204static int cypress_probe(struct usb_interface *interface,
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 7a10e48b78f9..e573e4704015 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -553,6 +553,7 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd,
553 /* needed for power consumption */ 553 /* needed for power consumption */
554 struct usb_config_descriptor *cfg_descriptor = &dev->udev->actconfig->desc; 554 struct usb_config_descriptor *cfg_descriptor = &dev->udev->actconfig->desc;
555 555
556 memset(&info, 0, sizeof(info));
556 /* directly from the descriptor */ 557 /* directly from the descriptor */
557 info.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); 558 info.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
558 info.product = dev->product_id; 559 info.product = dev->product_id;
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 70d00e99a4b4..dd573abd2d1e 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3008,6 +3008,7 @@ sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3008#else 3008#else
3009 x.sisusb_conactive = 0; 3009 x.sisusb_conactive = 0;
3010#endif 3010#endif
3011 memset(x.sisusb_reserved, 0, sizeof(x.sisusb_reserved));
3011 3012
3012 if (copy_to_user((void __user *)arg, &x, sizeof(x))) 3013 if (copy_to_user((void __user *)arg, &x, sizeof(x)))
3013 retval = -EFAULT; 3014 retval = -EFAULT;
diff --git a/drivers/usb/misc/trancevibrator.c b/drivers/usb/misc/trancevibrator.c
index d77aba46ae85..f63776a48e2a 100644
--- a/drivers/usb/misc/trancevibrator.c
+++ b/drivers/usb/misc/trancevibrator.c
@@ -86,7 +86,7 @@ static ssize_t set_speed(struct device *dev, struct device_attribute *attr,
86 return count; 86 return count;
87} 87}
88 88
89static DEVICE_ATTR(speed, S_IWUGO | S_IRUGO, show_speed, set_speed); 89static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR, show_speed, set_speed);
90 90
91static int tv_probe(struct usb_interface *interface, 91static int tv_probe(struct usb_interface *interface,
92 const struct usb_device_id *id) 92 const struct usb_device_id *id)
diff --git a/drivers/usb/misc/usbled.c b/drivers/usb/misc/usbled.c
index 63da2c3c838f..c96f51de1696 100644
--- a/drivers/usb/misc/usbled.c
+++ b/drivers/usb/misc/usbled.c
@@ -94,7 +94,7 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
94 change_color(led); \ 94 change_color(led); \
95 return count; \ 95 return count; \
96} \ 96} \
97static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 97static DEVICE_ATTR(value, S_IRUGO | S_IWUSR, show_##value, set_##value);
98show_set(blue); 98show_set(blue);
99show_set(red); 99show_set(red);
100show_set(green); 100show_set(green);
diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c
index de8ef945b536..417b8f207e8b 100644
--- a/drivers/usb/misc/usbsevseg.c
+++ b/drivers/usb/misc/usbsevseg.c
@@ -192,7 +192,7 @@ static ssize_t set_attr_##name(struct device *dev, \
192 \ 192 \
193 return count; \ 193 return count; \
194} \ 194} \
195static DEVICE_ATTR(name, S_IWUGO | S_IRUGO, show_attr_##name, set_attr_##name); 195static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show_attr_##name, set_attr_##name);
196 196
197static ssize_t show_attr_text(struct device *dev, 197static ssize_t show_attr_text(struct device *dev,
198 struct device_attribute *attr, char *buf) 198 struct device_attribute *attr, char *buf)
@@ -223,7 +223,7 @@ static ssize_t set_attr_text(struct device *dev,
223 return count; 223 return count;
224} 224}
225 225
226static DEVICE_ATTR(text, S_IWUGO | S_IRUGO, show_attr_text, set_attr_text); 226static DEVICE_ATTR(text, S_IRUGO | S_IWUSR, show_attr_text, set_attr_text);
227 227
228static ssize_t show_attr_decimals(struct device *dev, 228static ssize_t show_attr_decimals(struct device *dev,
229 struct device_attribute *attr, char *buf) 229 struct device_attribute *attr, char *buf)
@@ -272,8 +272,7 @@ static ssize_t set_attr_decimals(struct device *dev,
272 return count; 272 return count;
273} 273}
274 274
275static DEVICE_ATTR(decimals, S_IWUGO | S_IRUGO, 275static DEVICE_ATTR(decimals, S_IRUGO | S_IWUSR, show_attr_decimals, set_attr_decimals);
276 show_attr_decimals, set_attr_decimals);
277 276
278static ssize_t show_attr_textmode(struct device *dev, 277static ssize_t show_attr_textmode(struct device *dev,
279 struct device_attribute *attr, char *buf) 278 struct device_attribute *attr, char *buf)
@@ -319,8 +318,7 @@ static ssize_t set_attr_textmode(struct device *dev,
319 return -EINVAL; 318 return -EINVAL;
320} 319}
321 320
322static DEVICE_ATTR(textmode, S_IWUGO | S_IRUGO, 321static DEVICE_ATTR(textmode, S_IRUGO | S_IWUSR, show_attr_textmode, set_attr_textmode);
323 show_attr_textmode, set_attr_textmode);
324 322
325 323
326MYDEV_ATTR_SIMPLE_UNSIGNED(powered, update_display_powered); 324MYDEV_ATTR_SIMPLE_UNSIGNED(powered, update_display_powered);
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index 796e2f68f749..4ff21587ab03 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -3,7 +3,7 @@
3/* 3/*
4 * uss720.c -- USS720 USB Parport Cable. 4 * uss720.c -- USS720 USB Parport Cable.
5 * 5 *
6 * Copyright (C) 1999, 2005 6 * Copyright (C) 1999, 2005, 2010
7 * Thomas Sailer (t.sailer@alumni.ethz.ch) 7 * Thomas Sailer (t.sailer@alumni.ethz.ch)
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
@@ -776,6 +776,8 @@ static const struct usb_device_id uss720_table[] = {
776 { USB_DEVICE(0x0557, 0x2001) }, 776 { USB_DEVICE(0x0557, 0x2001) },
777 { USB_DEVICE(0x0729, 0x1284) }, 777 { USB_DEVICE(0x0729, 0x1284) },
778 { USB_DEVICE(0x1293, 0x0002) }, 778 { USB_DEVICE(0x1293, 0x0002) },
779 { USB_DEVICE(0x1293, 0x0002) },
780 { USB_DEVICE(0x050d, 0x0002) },
779 { } /* Terminating entry */ 781 { } /* Terminating entry */
780}; 782};
781 783
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
index 719c6180b31f..ac5bfd619e62 100644
--- a/drivers/usb/misc/yurex.c
+++ b/drivers/usb/misc/yurex.c
@@ -536,6 +536,7 @@ static const struct file_operations yurex_fops = {
536 .open = yurex_open, 536 .open = yurex_open,
537 .release = yurex_release, 537 .release = yurex_release,
538 .fasync = yurex_fasync, 538 .fasync = yurex_fasync,
539 .llseek = default_llseek,
539}; 540};
540 541
541 542
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 44cb37b5a4dc..c436e1e2c3b6 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -15,7 +15,6 @@
15#include <linux/poll.h> 15#include <linux/poll.h>
16#include <linux/compat.h> 16#include <linux/compat.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/smp_lock.h>
19#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21 20
diff --git a/drivers/usb/mon/mon_stat.c b/drivers/usb/mon/mon_stat.c
index 8ec94f15a738..e5ce42bd316e 100644
--- a/drivers/usb/mon/mon_stat.c
+++ b/drivers/usb/mon/mon_stat.c
@@ -11,7 +11,6 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/usb.h> 12#include <linux/usb.h>
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/smp_lock.h>
15#include <asm/uaccess.h> 14#include <asm/uaccess.h>
16 15
17#include "usb_mon.h" 16#include "usb_mon.h"
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 611a9d274363..fcb5206a65bd 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -171,8 +171,9 @@ static irqreturn_t blackfin_interrupt(int irq, void *__hci)
171 } 171 }
172 172
173 /* Start sampling ID pin, when plug is removed from MUSB */ 173 /* Start sampling ID pin, when plug is removed from MUSB */
174 if (is_otg_enabled(musb) && (musb->xceiv->state == OTG_STATE_B_IDLE 174 if ((is_otg_enabled(musb) && (musb->xceiv->state == OTG_STATE_B_IDLE
175 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 175 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) ||
176 (musb->int_usb & MUSB_INTR_DISCONNECT && is_host_active(musb))) {
176 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 177 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
177 musb->a_wait_bcon = TIMER_DELAY; 178 musb->a_wait_bcon = TIMER_DELAY;
178 } 179 }
@@ -323,30 +324,8 @@ int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
323 return -EIO; 324 return -EIO;
324} 325}
325 326
326int __init musb_platform_init(struct musb *musb, void *board_data) 327static void musb_platform_reg_init(struct musb *musb)
327{ 328{
328
329 /*
330 * Rev 1.0 BF549 EZ-KITs require PE7 to be high for both DEVICE
331 * and OTG HOST modes, while rev 1.1 and greater require PE7 to
332 * be low for DEVICE mode and high for HOST mode. We set it high
333 * here because we are in host mode
334 */
335
336 if (gpio_request(musb->config->gpio_vrsel, "USB_VRSEL")) {
337 printk(KERN_ERR "Failed ro request USB_VRSEL GPIO_%d \n",
338 musb->config->gpio_vrsel);
339 return -ENODEV;
340 }
341 gpio_direction_output(musb->config->gpio_vrsel, 0);
342
343 usb_nop_xceiv_register();
344 musb->xceiv = otg_get_transceiver();
345 if (!musb->xceiv) {
346 gpio_free(musb->config->gpio_vrsel);
347 return -ENODEV;
348 }
349
350 if (ANOMALY_05000346) { 329 if (ANOMALY_05000346) {
351 bfin_write_USB_APHY_CALIB(ANOMALY_05000346_value); 330 bfin_write_USB_APHY_CALIB(ANOMALY_05000346_value);
352 SSYNC(); 331 SSYNC();
@@ -358,7 +337,8 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
358 } 337 }
359 338
360 /* Configure PLL oscillator register */ 339 /* Configure PLL oscillator register */
361 bfin_write_USB_PLLOSC_CTRL(0x30a8); 340 bfin_write_USB_PLLOSC_CTRL(0x3080 |
341 ((480/musb->config->clkin) << 1));
362 SSYNC(); 342 SSYNC();
363 343
364 bfin_write_USB_SRP_CLKDIV((get_sclk()/1000) / 32 - 1); 344 bfin_write_USB_SRP_CLKDIV((get_sclk()/1000) / 32 - 1);
@@ -380,6 +360,33 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
380 EP2_RX_ENA | EP3_RX_ENA | EP4_RX_ENA | 360 EP2_RX_ENA | EP3_RX_ENA | EP4_RX_ENA |
381 EP5_RX_ENA | EP6_RX_ENA | EP7_RX_ENA); 361 EP5_RX_ENA | EP6_RX_ENA | EP7_RX_ENA);
382 SSYNC(); 362 SSYNC();
363}
364
365int __init musb_platform_init(struct musb *musb, void *board_data)
366{
367
368 /*
369 * Rev 1.0 BF549 EZ-KITs require PE7 to be high for both DEVICE
370 * and OTG HOST modes, while rev 1.1 and greater require PE7 to
371 * be low for DEVICE mode and high for HOST mode. We set it high
372 * here because we are in host mode
373 */
374
375 if (gpio_request(musb->config->gpio_vrsel, "USB_VRSEL")) {
376 printk(KERN_ERR "Failed ro request USB_VRSEL GPIO_%d\n",
377 musb->config->gpio_vrsel);
378 return -ENODEV;
379 }
380 gpio_direction_output(musb->config->gpio_vrsel, 0);
381
382 usb_nop_xceiv_register();
383 musb->xceiv = otg_get_transceiver();
384 if (!musb->xceiv) {
385 gpio_free(musb->config->gpio_vrsel);
386 return -ENODEV;
387 }
388
389 musb_platform_reg_init(musb);
383 390
384 if (is_host_enabled(musb)) { 391 if (is_host_enabled(musb)) {
385 musb->board_set_vbus = bfin_set_vbus; 392 musb->board_set_vbus = bfin_set_vbus;
@@ -394,6 +401,27 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
394 return 0; 401 return 0;
395} 402}
396 403
404#ifdef CONFIG_PM
405void musb_platform_save_context(struct musb *musb,
406 struct musb_context_registers *musb_context)
407{
408 if (is_host_active(musb))
409 /*
410 * During hibernate gpio_vrsel will change from high to low
411 * low which will generate wakeup event resume the system
412 * immediately. Set it to 0 before hibernate to avoid this
413 * wakeup event.
414 */
415 gpio_set_value(musb->config->gpio_vrsel, 0);
416}
417
418void musb_platform_restore_context(struct musb *musb,
419 struct musb_context_registers *musb_context)
420{
421 musb_platform_reg_init(musb);
422}
423#endif
424
397int musb_platform_exit(struct musb *musb) 425int musb_platform_exit(struct musb *musb)
398{ 426{
399 gpio_free(musb->config->gpio_vrsel); 427 gpio_free(musb->config->gpio_vrsel);
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index c9f9024c5515..99beebce8550 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -552,7 +552,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
552 if (int_usb & MUSB_INTR_SESSREQ) { 552 if (int_usb & MUSB_INTR_SESSREQ) {
553 void __iomem *mbase = musb->mregs; 553 void __iomem *mbase = musb->mregs;
554 554
555 if (devctl & MUSB_DEVCTL_BDEVICE) { 555 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS
556 && (devctl & MUSB_DEVCTL_BDEVICE)) {
556 DBG(3, "SessReq while on B state\n"); 557 DBG(3, "SessReq while on B state\n");
557 return IRQ_HANDLED; 558 return IRQ_HANDLED;
558 } 559 }
@@ -1052,6 +1053,11 @@ static void musb_shutdown(struct platform_device *pdev)
1052 clk_put(musb->clock); 1053 clk_put(musb->clock);
1053 spin_unlock_irqrestore(&musb->lock, flags); 1054 spin_unlock_irqrestore(&musb->lock, flags);
1054 1055
1056 if (!is_otg_enabled(musb) && is_host_enabled(musb))
1057 usb_remove_hcd(musb_to_hcd(musb));
1058 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1059 musb_platform_exit(musb);
1060
1055 /* FIXME power down */ 1061 /* FIXME power down */
1056} 1062}
1057 1063
@@ -2110,12 +2116,15 @@ bad_config:
2110 * Otherwise, wait till the gadget driver hooks up. 2116 * Otherwise, wait till the gadget driver hooks up.
2111 */ 2117 */
2112 if (!is_otg_enabled(musb) && is_host_enabled(musb)) { 2118 if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
2119 struct usb_hcd *hcd = musb_to_hcd(musb);
2120
2113 MUSB_HST_MODE(musb); 2121 MUSB_HST_MODE(musb);
2114 musb->xceiv->default_a = 1; 2122 musb->xceiv->default_a = 1;
2115 musb->xceiv->state = OTG_STATE_A_IDLE; 2123 musb->xceiv->state = OTG_STATE_A_IDLE;
2116 2124
2117 status = usb_add_hcd(musb_to_hcd(musb), -1, 0); 2125 status = usb_add_hcd(musb_to_hcd(musb), -1, 0);
2118 2126
2127 hcd->self.uses_pio_for_control = 1;
2119 DBG(1, "%s mode, status %d, devctl %02x %c\n", 2128 DBG(1, "%s mode, status %d, devctl %02x %c\n",
2120 "HOST", status, 2129 "HOST", status,
2121 musb_readb(musb->mregs, MUSB_DEVCTL), 2130 musb_readb(musb->mregs, MUSB_DEVCTL),
@@ -2244,13 +2253,6 @@ static int __exit musb_remove(struct platform_device *pdev)
2244 */ 2253 */
2245 musb_exit_debugfs(musb); 2254 musb_exit_debugfs(musb);
2246 musb_shutdown(pdev); 2255 musb_shutdown(pdev);
2247#ifdef CONFIG_USB_MUSB_HDRC_HCD
2248 if (musb->board_mode == MUSB_HOST)
2249 usb_remove_hcd(musb_to_hcd(musb));
2250#endif
2251 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
2252 musb_platform_exit(musb);
2253 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
2254 2256
2255 musb_free(musb); 2257 musb_free(musb);
2256 iounmap(ctrl_base); 2258 iounmap(ctrl_base);
@@ -2411,9 +2413,6 @@ static int musb_suspend(struct device *dev)
2411 unsigned long flags; 2413 unsigned long flags;
2412 struct musb *musb = dev_to_musb(&pdev->dev); 2414 struct musb *musb = dev_to_musb(&pdev->dev);
2413 2415
2414 if (!musb->clock)
2415 return 0;
2416
2417 spin_lock_irqsave(&musb->lock, flags); 2416 spin_lock_irqsave(&musb->lock, flags);
2418 2417
2419 if (is_peripheral_active(musb)) { 2418 if (is_peripheral_active(musb)) {
@@ -2428,10 +2427,12 @@ static int musb_suspend(struct device *dev)
2428 2427
2429 musb_save_context(musb); 2428 musb_save_context(musb);
2430 2429
2431 if (musb->set_clock) 2430 if (musb->clock) {
2432 musb->set_clock(musb->clock, 0); 2431 if (musb->set_clock)
2433 else 2432 musb->set_clock(musb->clock, 0);
2434 clk_disable(musb->clock); 2433 else
2434 clk_disable(musb->clock);
2435 }
2435 spin_unlock_irqrestore(&musb->lock, flags); 2436 spin_unlock_irqrestore(&musb->lock, flags);
2436 return 0; 2437 return 0;
2437} 2438}
@@ -2441,13 +2442,12 @@ static int musb_resume_noirq(struct device *dev)
2441 struct platform_device *pdev = to_platform_device(dev); 2442 struct platform_device *pdev = to_platform_device(dev);
2442 struct musb *musb = dev_to_musb(&pdev->dev); 2443 struct musb *musb = dev_to_musb(&pdev->dev);
2443 2444
2444 if (!musb->clock) 2445 if (musb->clock) {
2445 return 0; 2446 if (musb->set_clock)
2446 2447 musb->set_clock(musb->clock, 1);
2447 if (musb->set_clock) 2448 else
2448 musb->set_clock(musb->clock, 1); 2449 clk_enable(musb->clock);
2449 else 2450 }
2450 clk_enable(musb->clock);
2451 2451
2452 musb_restore_context(musb); 2452 musb_restore_context(musb);
2453 2453
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 69797e5b46a7..febaabcc2b35 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -487,7 +487,7 @@ struct musb_context_registers {
487}; 487};
488 488
489#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \ 489#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
490 defined(CONFIG_ARCH_OMAP4) 490 defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_BLACKFIN)
491extern void musb_platform_save_context(struct musb *musb, 491extern void musb_platform_save_context(struct musb *musb,
492 struct musb_context_registers *musb_context); 492 struct musb_context_registers *musb_context);
493extern void musb_platform_restore_context(struct musb *musb, 493extern void musb_platform_restore_context(struct musb *musb,
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 1cbeaa17ffff..d5b9cfcc5977 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -92,6 +92,59 @@
92 92
93/* ----------------------------------------------------------------------- */ 93/* ----------------------------------------------------------------------- */
94 94
95/* Maps the buffer to dma */
96
97static inline void map_dma_buffer(struct musb_request *request,
98 struct musb *musb)
99{
100 if (request->request.dma == DMA_ADDR_INVALID) {
101 request->request.dma = dma_map_single(
102 musb->controller,
103 request->request.buf,
104 request->request.length,
105 request->tx
106 ? DMA_TO_DEVICE
107 : DMA_FROM_DEVICE);
108 request->mapped = 1;
109 } else {
110 dma_sync_single_for_device(musb->controller,
111 request->request.dma,
112 request->request.length,
113 request->tx
114 ? DMA_TO_DEVICE
115 : DMA_FROM_DEVICE);
116 request->mapped = 0;
117 }
118}
119
120/* Unmap the buffer from dma and maps it back to cpu */
121static inline void unmap_dma_buffer(struct musb_request *request,
122 struct musb *musb)
123{
124 if (request->request.dma == DMA_ADDR_INVALID) {
125 DBG(20, "not unmapping a never mapped buffer\n");
126 return;
127 }
128 if (request->mapped) {
129 dma_unmap_single(musb->controller,
130 request->request.dma,
131 request->request.length,
132 request->tx
133 ? DMA_TO_DEVICE
134 : DMA_FROM_DEVICE);
135 request->request.dma = DMA_ADDR_INVALID;
136 request->mapped = 0;
137 } else {
138 dma_sync_single_for_cpu(musb->controller,
139 request->request.dma,
140 request->request.length,
141 request->tx
142 ? DMA_TO_DEVICE
143 : DMA_FROM_DEVICE);
144
145 }
146}
147
95/* 148/*
96 * Immediately complete a request. 149 * Immediately complete a request.
97 * 150 *
@@ -119,24 +172,8 @@ __acquires(ep->musb->lock)
119 172
120 ep->busy = 1; 173 ep->busy = 1;
121 spin_unlock(&musb->lock); 174 spin_unlock(&musb->lock);
122 if (is_dma_capable()) { 175 if (is_dma_capable() && ep->dma)
123 if (req->mapped) { 176 unmap_dma_buffer(req, musb);
124 dma_unmap_single(musb->controller,
125 req->request.dma,
126 req->request.length,
127 req->tx
128 ? DMA_TO_DEVICE
129 : DMA_FROM_DEVICE);
130 req->request.dma = DMA_ADDR_INVALID;
131 req->mapped = 0;
132 } else if (req->request.dma != DMA_ADDR_INVALID)
133 dma_sync_single_for_cpu(musb->controller,
134 req->request.dma,
135 req->request.length,
136 req->tx
137 ? DMA_TO_DEVICE
138 : DMA_FROM_DEVICE);
139 }
140 if (request->status == 0) 177 if (request->status == 0)
141 DBG(5, "%s done request %p, %d/%d\n", 178 DBG(5, "%s done request %p, %d/%d\n",
142 ep->end_point.name, request, 179 ep->end_point.name, request,
@@ -395,6 +432,13 @@ static void txstate(struct musb *musb, struct musb_request *req)
395#endif 432#endif
396 433
397 if (!use_dma) { 434 if (!use_dma) {
435 /*
436 * Unmap the dma buffer back to cpu if dma channel
437 * programming fails
438 */
439 if (is_dma_capable() && musb_ep->dma)
440 unmap_dma_buffer(req, musb);
441
398 musb_write_fifo(musb_ep->hw_ep, fifo_count, 442 musb_write_fifo(musb_ep->hw_ep, fifo_count,
399 (u8 *) (request->buf + request->actual)); 443 (u8 *) (request->buf + request->actual));
400 request->actual += fifo_count; 444 request->actual += fifo_count;
@@ -644,10 +688,8 @@ static void rxstate(struct musb *musb, struct musb_request *req)
644 */ 688 */
645 689
646 csr |= MUSB_RXCSR_DMAENAB; 690 csr |= MUSB_RXCSR_DMAENAB;
647 if (!musb_ep->hb_mult &&
648 musb_ep->hw_ep->rx_double_buffered)
649 csr |= MUSB_RXCSR_AUTOCLEAR;
650#ifdef USE_MODE1 691#ifdef USE_MODE1
692 csr |= MUSB_RXCSR_AUTOCLEAR;
651 /* csr |= MUSB_RXCSR_DMAMODE; */ 693 /* csr |= MUSB_RXCSR_DMAMODE; */
652 694
653 /* this special sequence (enabling and then 695 /* this special sequence (enabling and then
@@ -656,6 +698,10 @@ static void rxstate(struct musb *musb, struct musb_request *req)
656 */ 698 */
657 musb_writew(epio, MUSB_RXCSR, 699 musb_writew(epio, MUSB_RXCSR,
658 csr | MUSB_RXCSR_DMAMODE); 700 csr | MUSB_RXCSR_DMAMODE);
701#else
702 if (!musb_ep->hb_mult &&
703 musb_ep->hw_ep->rx_double_buffered)
704 csr |= MUSB_RXCSR_AUTOCLEAR;
659#endif 705#endif
660 musb_writew(epio, MUSB_RXCSR, csr); 706 musb_writew(epio, MUSB_RXCSR, csr);
661 707
@@ -711,6 +757,21 @@ static void rxstate(struct musb *musb, struct musb_request *req)
711 return; 757 return;
712 } 758 }
713#endif 759#endif
760 /*
761 * Unmap the dma buffer back to cpu if dma channel
762 * programming fails. This buffer is mapped if the
763 * channel allocation is successful
764 */
765 if (is_dma_capable() && musb_ep->dma) {
766 unmap_dma_buffer(req, musb);
767
768 /*
769 * Clear DMAENAB and AUTOCLEAR for the
770 * PIO mode transfer
771 */
772 csr &= ~(MUSB_RXCSR_DMAENAB | MUSB_RXCSR_AUTOCLEAR);
773 musb_writew(epio, MUSB_RXCSR, csr);
774 }
714 775
715 musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *) 776 musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *)
716 (request->buf + request->actual)); 777 (request->buf + request->actual));
@@ -807,7 +868,7 @@ void musb_g_rx(struct musb *musb, u8 epnum)
807 868
808#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA) 869#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA)
809 /* Autoclear doesn't clear RxPktRdy for short packets */ 870 /* Autoclear doesn't clear RxPktRdy for short packets */
810 if ((dma->desired_mode == 0) 871 if ((dma->desired_mode == 0 && !hw_ep->rx_double_buffered)
811 || (dma->actual_len 872 || (dma->actual_len
812 & (musb_ep->packet_sz - 1))) { 873 & (musb_ep->packet_sz - 1))) {
813 /* ack the read! */ 874 /* ack the read! */
@@ -818,8 +879,16 @@ void musb_g_rx(struct musb *musb, u8 epnum)
818 /* incomplete, and not short? wait for next IN packet */ 879 /* incomplete, and not short? wait for next IN packet */
819 if ((request->actual < request->length) 880 if ((request->actual < request->length)
820 && (musb_ep->dma->actual_len 881 && (musb_ep->dma->actual_len
821 == musb_ep->packet_sz)) 882 == musb_ep->packet_sz)) {
883 /* In double buffer case, continue to unload fifo if
884 * there is Rx packet in FIFO.
885 **/
886 csr = musb_readw(epio, MUSB_RXCSR);
887 if ((csr & MUSB_RXCSR_RXPKTRDY) &&
888 hw_ep->rx_double_buffered)
889 goto exit;
822 return; 890 return;
891 }
823#endif 892#endif
824 musb_g_giveback(musb_ep, request, 0); 893 musb_g_giveback(musb_ep, request, 0);
825 894
@@ -827,7 +896,9 @@ void musb_g_rx(struct musb *musb, u8 epnum)
827 if (!request) 896 if (!request)
828 return; 897 return;
829 } 898 }
830 899#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA)
900exit:
901#endif
831 /* Analyze request */ 902 /* Analyze request */
832 rxstate(musb, to_musb_request(request)); 903 rxstate(musb, to_musb_request(request));
833} 904}
@@ -916,13 +987,9 @@ static int musb_gadget_enable(struct usb_ep *ep,
916 * likewise high bandwidth periodic tx 987 * likewise high bandwidth periodic tx
917 */ 988 */
918 /* Set TXMAXP with the FIFO size of the endpoint 989 /* Set TXMAXP with the FIFO size of the endpoint
919 * to disable double buffering mode. Currently, It seems that double 990 * to disable double buffering mode.
920 * buffering has problem if musb RTL revision number < 2.0.
921 */ 991 */
922 if (musb->hwvers < MUSB_HWVERS_2000) 992 musb_writew(regs, MUSB_TXMAXP, musb_ep->packet_sz | (musb_ep->hb_mult << 11));
923 musb_writew(regs, MUSB_TXMAXP, hw_ep->max_packet_sz_tx);
924 else
925 musb_writew(regs, MUSB_TXMAXP, musb_ep->packet_sz | (musb_ep->hb_mult << 11));
926 993
927 csr = MUSB_TXCSR_MODE | MUSB_TXCSR_CLRDATATOG; 994 csr = MUSB_TXCSR_MODE | MUSB_TXCSR_CLRDATATOG;
928 if (musb_readw(regs, MUSB_TXCSR) 995 if (musb_readw(regs, MUSB_TXCSR)
@@ -958,10 +1025,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
958 /* Set RXMAXP with the FIFO size of the endpoint 1025 /* Set RXMAXP with the FIFO size of the endpoint
959 * to disable double buffering mode. 1026 * to disable double buffering mode.
960 */ 1027 */
961 if (musb->hwvers < MUSB_HWVERS_2000) 1028 musb_writew(regs, MUSB_RXMAXP, musb_ep->packet_sz | (musb_ep->hb_mult << 11));
962 musb_writew(regs, MUSB_RXMAXP, hw_ep->max_packet_sz_rx);
963 else
964 musb_writew(regs, MUSB_RXMAXP, musb_ep->packet_sz | (musb_ep->hb_mult << 11));
965 1029
966 /* force shared fifo to OUT-only mode */ 1030 /* force shared fifo to OUT-only mode */
967 if (hw_ep->is_shared_fifo) { 1031 if (hw_ep->is_shared_fifo) {
@@ -1147,28 +1211,9 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1147 request->epnum = musb_ep->current_epnum; 1211 request->epnum = musb_ep->current_epnum;
1148 request->tx = musb_ep->is_in; 1212 request->tx = musb_ep->is_in;
1149 1213
1150 if (is_dma_capable() && musb_ep->dma) { 1214 if (is_dma_capable() && musb_ep->dma)
1151 if (request->request.dma == DMA_ADDR_INVALID) { 1215 map_dma_buffer(request, musb);
1152 request->request.dma = dma_map_single( 1216 else
1153 musb->controller,
1154 request->request.buf,
1155 request->request.length,
1156 request->tx
1157 ? DMA_TO_DEVICE
1158 : DMA_FROM_DEVICE);
1159 request->mapped = 1;
1160 } else {
1161 dma_sync_single_for_device(musb->controller,
1162 request->request.dma,
1163 request->request.length,
1164 request->tx
1165 ? DMA_TO_DEVICE
1166 : DMA_FROM_DEVICE);
1167 request->mapped = 0;
1168 }
1169 } else if (!req->buf) {
1170 return -ENODATA;
1171 } else
1172 request->mapped = 0; 1217 request->mapped = 0;
1173 1218
1174 spin_lock_irqsave(&musb->lock, lockflags); 1219 spin_lock_irqsave(&musb->lock, lockflags);
@@ -1695,8 +1740,10 @@ int __init musb_gadget_setup(struct musb *musb)
1695 musb_platform_try_idle(musb, 0); 1740 musb_platform_try_idle(musb, 0);
1696 1741
1697 status = device_register(&musb->g.dev); 1742 status = device_register(&musb->g.dev);
1698 if (status != 0) 1743 if (status != 0) {
1744 put_device(&musb->g.dev);
1699 the_gadget = NULL; 1745 the_gadget = NULL;
1746 }
1700 return status; 1747 return status;
1701} 1748}
1702 1749
@@ -1786,6 +1833,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1786 spin_unlock_irqrestore(&musb->lock, flags); 1833 spin_unlock_irqrestore(&musb->lock, flags);
1787 1834
1788 if (is_otg_enabled(musb)) { 1835 if (is_otg_enabled(musb)) {
1836 struct usb_hcd *hcd = musb_to_hcd(musb);
1837
1789 DBG(3, "OTG startup...\n"); 1838 DBG(3, "OTG startup...\n");
1790 1839
1791 /* REVISIT: funcall to other code, which also 1840 /* REVISIT: funcall to other code, which also
@@ -1800,6 +1849,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1800 musb->gadget_driver = NULL; 1849 musb->gadget_driver = NULL;
1801 musb->g.dev.driver = NULL; 1850 musb->g.dev.driver = NULL;
1802 spin_unlock_irqrestore(&musb->lock, flags); 1851 spin_unlock_irqrestore(&musb->lock, flags);
1852 } else {
1853 hcd->self.uses_pio_for_control = 1;
1803 } 1854 }
1804 } 1855 }
1805 } 1856 }
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index 244267527a60..5a727c5b8676 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -633,8 +633,9 @@ static inline u8 musb_read_txhubaddr(void __iomem *mbase, u8 epnum)
633 return 0; 633 return 0;
634} 634}
635 635
636static inline void musb_read_txhubport(void __iomem *mbase, u8 epnum) 636static inline u8 musb_read_txhubport(void __iomem *mbase, u8 epnum)
637{ 637{
638 return 0;
638} 639}
639 640
640#endif /* CONFIG_BLACKFIN */ 641#endif /* CONFIG_BLACKFIN */
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index 6f771af5cbdb..563114d613d6 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -158,6 +158,8 @@ static int dma_channel_program(struct dma_channel *channel,
158 dma_addr_t dma_addr, u32 len) 158 dma_addr_t dma_addr, u32 len)
159{ 159{
160 struct musb_dma_channel *musb_channel = channel->private_data; 160 struct musb_dma_channel *musb_channel = channel->private_data;
161 struct musb_dma_controller *controller = musb_channel->controller;
162 struct musb *musb = controller->private_data;
161 163
162 DBG(2, "ep%d-%s pkt_sz %d, dma_addr 0x%x length %d, mode %d\n", 164 DBG(2, "ep%d-%s pkt_sz %d, dma_addr 0x%x length %d, mode %d\n",
163 musb_channel->epnum, 165 musb_channel->epnum,
@@ -167,6 +169,18 @@ static int dma_channel_program(struct dma_channel *channel,
167 BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN || 169 BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN ||
168 channel->status == MUSB_DMA_STATUS_BUSY); 170 channel->status == MUSB_DMA_STATUS_BUSY);
169 171
172 /*
173 * The DMA engine in RTL1.8 and above cannot handle
174 * DMA addresses that are not aligned to a 4 byte boundary.
175 * It ends up masking the last two bits of the address
176 * programmed in DMA_ADDR.
177 *
178 * Fail such DMA transfers, so that the backup PIO mode
179 * can carry out the transfer
180 */
181 if ((musb->hwvers >= MUSB_HWVERS_1800) && (dma_addr % 4))
182 return false;
183
170 channel->actual_len = 0; 184 channel->actual_len = 0;
171 musb_channel->start_addr = dma_addr; 185 musb_channel->start_addr = dma_addr;
172 musb_channel->len = len; 186 musb_channel->len = len;
diff --git a/drivers/usb/otg/langwell_otg.c b/drivers/usb/otg/langwell_otg.c
index bdc3ea66be69..9fea48264fa2 100644
--- a/drivers/usb/otg/langwell_otg.c
+++ b/drivers/usb/otg/langwell_otg.c
@@ -1896,7 +1896,7 @@ set_a_bus_req(struct device *dev, struct device_attribute *attr,
1896 } 1896 }
1897 return count; 1897 return count;
1898} 1898}
1899static DEVICE_ATTR(a_bus_req, S_IRUGO | S_IWUGO, get_a_bus_req, set_a_bus_req); 1899static DEVICE_ATTR(a_bus_req, S_IRUGO | S_IWUSR, get_a_bus_req, set_a_bus_req);
1900 1900
1901static ssize_t 1901static ssize_t
1902get_a_bus_drop(struct device *dev, struct device_attribute *attr, char *buf) 1902get_a_bus_drop(struct device *dev, struct device_attribute *attr, char *buf)
@@ -1942,8 +1942,7 @@ set_a_bus_drop(struct device *dev, struct device_attribute *attr,
1942 } 1942 }
1943 return count; 1943 return count;
1944} 1944}
1945static DEVICE_ATTR(a_bus_drop, S_IRUGO | S_IWUGO, 1945static DEVICE_ATTR(a_bus_drop, S_IRUGO | S_IWUSR, get_a_bus_drop, set_a_bus_drop);
1946 get_a_bus_drop, set_a_bus_drop);
1947 1946
1948static ssize_t 1947static ssize_t
1949get_b_bus_req(struct device *dev, struct device_attribute *attr, char *buf) 1948get_b_bus_req(struct device *dev, struct device_attribute *attr, char *buf)
@@ -1988,7 +1987,7 @@ set_b_bus_req(struct device *dev, struct device_attribute *attr,
1988 } 1987 }
1989 return count; 1988 return count;
1990} 1989}
1991static DEVICE_ATTR(b_bus_req, S_IRUGO | S_IWUGO, get_b_bus_req, set_b_bus_req); 1990static DEVICE_ATTR(b_bus_req, S_IRUGO | S_IWUSR, get_b_bus_req, set_b_bus_req);
1992 1991
1993static ssize_t 1992static ssize_t
1994set_a_clr_err(struct device *dev, struct device_attribute *attr, 1993set_a_clr_err(struct device *dev, struct device_attribute *attr,
@@ -2012,7 +2011,7 @@ set_a_clr_err(struct device *dev, struct device_attribute *attr,
2012 } 2011 }
2013 return count; 2012 return count;
2014} 2013}
2015static DEVICE_ATTR(a_clr_err, S_IWUGO, NULL, set_a_clr_err); 2014static DEVICE_ATTR(a_clr_err, S_IWUSR, NULL, set_a_clr_err);
2016 2015
2017static struct attribute *inputs_attrs[] = { 2016static struct attribute *inputs_attrs[] = {
2018 &dev_attr_a_bus_req.attr, 2017 &dev_attr_a_bus_req.attr,
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 89a9a5847803..2dec50013528 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -201,6 +201,7 @@ static struct usb_device_id id_table_combined [] = {
201 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) }, 201 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
202 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) }, 202 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
203 { USB_DEVICE(FTDI_VID, FTDI_R2000KU_TRUE_RNG) }, 203 { USB_DEVICE(FTDI_VID, FTDI_R2000KU_TRUE_RNG) },
204 { USB_DEVICE(FTDI_VID, FTDI_VARDAAN_PID) },
204 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0100_PID) }, 205 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0100_PID) },
205 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0101_PID) }, 206 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0101_PID) },
206 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0102_PID) }, 207 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0102_PID) },
@@ -696,6 +697,7 @@ static struct usb_device_id id_table_combined [] = {
696 .driver_info = (kernel_ulong_t)&ftdi_NDI_device_quirk }, 697 .driver_info = (kernel_ulong_t)&ftdi_NDI_device_quirk },
697 { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) }, 698 { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) },
698 { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_SERIAL_VX7_PID) }, 699 { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_SERIAL_VX7_PID) },
700 { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_CT29B_PID) },
699 { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) }, 701 { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) },
700 { USB_DEVICE(FTDI_VID, FTDI_PHI_FISCO_PID) }, 702 { USB_DEVICE(FTDI_VID, FTDI_PHI_FISCO_PID) },
701 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) }, 703 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
@@ -794,6 +796,9 @@ static struct usb_device_id id_table_combined [] = {
794 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_LOGBOOKML_PID) }, 796 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_LOGBOOKML_PID) },
795 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_LS_LOGBOOK_PID) }, 797 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_LS_LOGBOOK_PID) },
796 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_HS_LOGBOOK_PID) }, 798 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_HS_LOGBOOK_PID) },
799 { USB_DEVICE(FTDI_VID, FTDI_DOTEC_PID) },
800 { USB_DEVICE(QIHARDWARE_VID, MILKYMISTONE_JTAGSERIAL_PID),
801 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
797 { }, /* Optional parameter entry */ 802 { }, /* Optional parameter entry */
798 { } /* Terminating entry */ 803 { } /* Terminating entry */
799}; 804};
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 7dfe02f1fb6a..bf0867285481 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -114,6 +114,9 @@
114/* Lenz LI-USB Computer Interface. */ 114/* Lenz LI-USB Computer Interface. */
115#define FTDI_LENZ_LIUSB_PID 0xD780 115#define FTDI_LENZ_LIUSB_PID 0xD780
116 116
117/* Vardaan Enterprises Serial Interface VEUSB422R3 */
118#define FTDI_VARDAAN_PID 0xF070
119
117/* 120/*
118 * Xsens Technologies BV products (http://www.xsens.com). 121 * Xsens Technologies BV products (http://www.xsens.com).
119 */ 122 */
@@ -721,6 +724,7 @@
721 */ 724 */
722#define RTSYSTEMS_VID 0x2100 /* Vendor ID */ 725#define RTSYSTEMS_VID 0x2100 /* Vendor ID */
723#define RTSYSTEMS_SERIAL_VX7_PID 0x9e52 /* Serial converter for VX-7 Radios using FT232RL */ 726#define RTSYSTEMS_SERIAL_VX7_PID 0x9e52 /* Serial converter for VX-7 Radios using FT232RL */
727#define RTSYSTEMS_CT29B_PID 0x9e54 /* CT29B Radio Cable */
724 728
725/* 729/*
726 * Bayer Ascensia Contour blood glucose meter USB-converter cable. 730 * Bayer Ascensia Contour blood glucose meter USB-converter cable.
@@ -1077,6 +1081,11 @@
1077#define MJSG_HD_RADIO_PID 0x937C 1081#define MJSG_HD_RADIO_PID 0x937C
1078 1082
1079/* 1083/*
1084 * D.O.Tec products (http://www.directout.eu)
1085 */
1086#define FTDI_DOTEC_PID 0x9868
1087
1088/*
1080 * Xverve Signalyzer tools (http://www.signalyzer.com/) 1089 * Xverve Signalyzer tools (http://www.signalyzer.com/)
1081 */ 1090 */
1082#define XVERVE_SIGNALYZER_ST_PID 0xBCA0 1091#define XVERVE_SIGNALYZER_ST_PID 0xBCA0
@@ -1100,3 +1109,10 @@
1100#define FTDI_SCIENCESCOPE_LOGBOOKML_PID 0xFF18 1109#define FTDI_SCIENCESCOPE_LOGBOOKML_PID 0xFF18
1101#define FTDI_SCIENCESCOPE_LS_LOGBOOK_PID 0xFF1C 1110#define FTDI_SCIENCESCOPE_LS_LOGBOOK_PID 0xFF1C
1102#define FTDI_SCIENCESCOPE_HS_LOGBOOK_PID 0xFF1D 1111#define FTDI_SCIENCESCOPE_HS_LOGBOOK_PID 0xFF1D
1112
1113/*
1114 * Milkymist One JTAG/Serial
1115 */
1116#define QIHARDWARE_VID 0x20B7
1117#define MILKYMISTONE_JTAGSERIAL_PID 0x0713
1118
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 2297fb1bcf65..ef2977d3a613 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -518,7 +518,7 @@ static const struct usb_device_id option_ids[] = {
518 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff) }, 518 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff) },
519 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff) }, 519 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff) },
520 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) }, 520 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) },
521 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC) }, 521 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC, 0xff, 0xff, 0xff) },
522 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, 522 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) },
523 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, 523 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) },
524 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) }, 524 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) },
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index e64da74bdcc5..6954de50c0ff 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -21,7 +21,6 @@
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/smp_lock.h>
25#include <linux/tty.h> 24#include <linux/tty.h>
26#include <linux/tty_driver.h> 25#include <linux/tty_driver.h>
27#include <linux/tty_flip.h> 26#include <linux/tty_flip.h>
@@ -52,6 +51,7 @@ static struct usb_driver usb_serial_driver = {
52 .suspend = usb_serial_suspend, 51 .suspend = usb_serial_suspend,
53 .resume = usb_serial_resume, 52 .resume = usb_serial_resume,
54 .no_dynamic_id = 1, 53 .no_dynamic_id = 1,
54 .supports_autosuspend = 1,
55}; 55};
56 56
57/* There is no MODULE_DEVICE_TABLE for usbserial.c. Instead 57/* There is no MODULE_DEVICE_TABLE for usbserial.c. Instead
@@ -1344,6 +1344,8 @@ int usb_serial_register(struct usb_serial_driver *driver)
1344 return -ENODEV; 1344 return -ENODEV;
1345 1345
1346 fixup_generic(driver); 1346 fixup_generic(driver);
1347 if (driver->usb_driver)
1348 driver->usb_driver->supports_autosuspend = 1;
1347 1349
1348 if (!driver->description) 1350 if (!driver->description)
1349 driver->description = driver->driver.name; 1351 driver->description = driver->driver.name;
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index a688b1e686ea..689ee1fb702a 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -285,7 +285,7 @@ static int slave_configure(struct scsi_device *sdev)
285 285
286/* queue a command */ 286/* queue a command */
287/* This is always called with scsi_lock(host) held */ 287/* This is always called with scsi_lock(host) held */
288static int queuecommand(struct scsi_cmnd *srb, 288static int queuecommand_lck(struct scsi_cmnd *srb,
289 void (*done)(struct scsi_cmnd *)) 289 void (*done)(struct scsi_cmnd *))
290{ 290{
291 struct us_data *us = host_to_us(srb->device->host); 291 struct us_data *us = host_to_us(srb->device->host);
@@ -315,6 +315,8 @@ static int queuecommand(struct scsi_cmnd *srb,
315 return 0; 315 return 0;
316} 316}
317 317
318static DEF_SCSI_QCMD(queuecommand)
319
318/*********************************************************************** 320/***********************************************************************
319 * Error handling functions 321 * Error handling functions
320 ***********************************************************************/ 322 ***********************************************************************/
diff --git a/drivers/usb/storage/sierra_ms.c b/drivers/usb/storage/sierra_ms.c
index 57fc2f532cab..ceba512f84d0 100644
--- a/drivers/usb/storage/sierra_ms.c
+++ b/drivers/usb/storage/sierra_ms.c
@@ -121,7 +121,7 @@ static ssize_t show_truinst(struct device *dev, struct device_attribute *attr,
121 } 121 }
122 return result; 122 return result;
123} 123}
124static DEVICE_ATTR(truinst, S_IWUGO | S_IRUGO, show_truinst, NULL); 124static DEVICE_ATTR(truinst, S_IRUGO, show_truinst, NULL);
125 125
126int sierra_ms_init(struct us_data *us) 126int sierra_ms_init(struct us_data *us)
127{ 127{
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 2054b1e25a65..339fac3949df 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -331,10 +331,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp,
331 331
332 iu->iu_id = IU_ID_COMMAND; 332 iu->iu_id = IU_ID_COMMAND;
333 iu->tag = cpu_to_be16(stream_id); 333 iu->tag = cpu_to_be16(stream_id);
334 if (sdev->ordered_tags && (cmnd->request->cmd_flags & REQ_HARDBARRIER)) 334 iu->prio_attr = UAS_SIMPLE_TAG;
335 iu->prio_attr = UAS_ORDERED_TAG;
336 else
337 iu->prio_attr = UAS_SIMPLE_TAG;
338 iu->len = len; 335 iu->len = len;
339 int_to_scsilun(sdev->lun, &iu->lun); 336 int_to_scsilun(sdev->lun, &iu->lun);
340 memcpy(iu->cdb, cmnd->cmnd, cmnd->cmd_len); 337 memcpy(iu->cdb, cmnd->cmnd, cmnd->cmd_len);
@@ -433,7 +430,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
433 return 0; 430 return 0;
434} 431}
435 432
436static int uas_queuecommand(struct scsi_cmnd *cmnd, 433static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
437 void (*done)(struct scsi_cmnd *)) 434 void (*done)(struct scsi_cmnd *))
438{ 435{
439 struct scsi_device *sdev = cmnd->device; 436 struct scsi_device *sdev = cmnd->device;
@@ -491,6 +488,8 @@ static int uas_queuecommand(struct scsi_cmnd *cmnd,
491 return 0; 488 return 0;
492} 489}
493 490
491static DEF_SCSI_QCMD(uas_queuecommand)
492
494static int uas_eh_abort_handler(struct scsi_cmnd *cmnd) 493static int uas_eh_abort_handler(struct scsi_cmnd *cmnd)
495{ 494{
496 struct scsi_device *sdev = cmnd->device; 495 struct scsi_device *sdev = cmnd->device;
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 6ccdd3dd5259..fcc1e32ce256 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -481,6 +481,13 @@ UNUSUAL_DEV( 0x04e8, 0x507c, 0x0220, 0x0220,
481 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 481 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
482 US_FL_MAX_SECTORS_64), 482 US_FL_MAX_SECTORS_64),
483 483
484/* Reported by Vitaly Kuznetsov <vitty@altlinux.ru> */
485UNUSUAL_DEV( 0x04e8, 0x5122, 0x0000, 0x9999,
486 "Samsung",
487 "YP-CP3",
488 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
489 US_FL_MAX_SECTORS_64 | US_FL_BULK_IGNORE_TAG),
490
484/* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>. 491/* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>.
485 * Device uses standards-violating 32-byte Bulk Command Block Wrappers and 492 * Device uses standards-violating 32-byte Bulk Command Block Wrappers and
486 * reports itself as "Proprietary SCSI Bulk." Cf. device entry 0x084d:0x0011. 493 * reports itself as "Proprietary SCSI Bulk." Cf. device entry 0x084d:0x0011.
diff --git a/drivers/uwb/allocator.c b/drivers/uwb/allocator.c
index 436e4f7110cb..e45e673b8770 100644
--- a/drivers/uwb/allocator.c
+++ b/drivers/uwb/allocator.c
@@ -326,7 +326,8 @@ int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv, struct uwb_mas_bm *availab
326 int bit_index; 326 int bit_index;
327 327
328 ai = kzalloc(sizeof(struct uwb_rsv_alloc_info), GFP_KERNEL); 328 ai = kzalloc(sizeof(struct uwb_rsv_alloc_info), GFP_KERNEL);
329 329 if (!ai)
330 return UWB_RSV_ALLOC_NOT_FOUND;
330 ai->min_mas = rsv->min_mas; 331 ai->min_mas = rsv->min_mas;
331 ai->max_mas = rsv->max_mas; 332 ai->max_mas = rsv->max_mas;
332 ai->max_interval = rsv->max_interval; 333 ai->max_interval = rsv->max_interval;
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 4b4da5b86ff9..f442668a1e52 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -129,8 +129,9 @@ static void handle_tx(struct vhost_net *net)
129 size_t hdr_size; 129 size_t hdr_size;
130 struct socket *sock; 130 struct socket *sock;
131 131
132 sock = rcu_dereference_check(vq->private_data, 132 /* TODO: check that we are running from vhost_worker?
133 lockdep_is_held(&vq->mutex)); 133 * Not sure it's worth it, it's straight-forward enough. */
134 sock = rcu_dereference_check(vq->private_data, 1);
134 if (!sock) 135 if (!sock)
135 return; 136 return;
136 137
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 94701ff3a23a..159c77a5746f 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -884,6 +884,7 @@ static int log_write(void __user *log_base,
884 int r; 884 int r;
885 if (!write_length) 885 if (!write_length)
886 return 0; 886 return 0;
887 write_length += write_address % VHOST_PAGE_SIZE;
887 write_address /= VHOST_PAGE_SIZE; 888 write_address /= VHOST_PAGE_SIZE;
888 for (;;) { 889 for (;;) {
889 u64 base = (u64)(unsigned long)log_base; 890 u64 base = (u64)(unsigned long)log_base;
@@ -897,7 +898,7 @@ static int log_write(void __user *log_base,
897 if (write_length <= VHOST_PAGE_SIZE) 898 if (write_length <= VHOST_PAGE_SIZE)
898 break; 899 break;
899 write_length -= VHOST_PAGE_SIZE; 900 write_length -= VHOST_PAGE_SIZE;
900 write_address += VHOST_PAGE_SIZE; 901 write_address += 1;
901 } 902 }
902 return r; 903 return r;
903} 904}
diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c
index 3ec24609151e..734c650a47c4 100644
--- a/drivers/video/backlight/adp8860_bl.c
+++ b/drivers/video/backlight/adp8860_bl.c
@@ -502,8 +502,10 @@ static ssize_t adp8860_bl_l1_daylight_max_store(struct device *dev,
502 struct device_attribute *attr, const char *buf, size_t count) 502 struct device_attribute *attr, const char *buf, size_t count)
503{ 503{
504 struct adp8860_bl *data = dev_get_drvdata(dev); 504 struct adp8860_bl *data = dev_get_drvdata(dev);
505 int ret = strict_strtoul(buf, 10, &data->cached_daylight_max);
506 if (ret)
507 return ret;
505 508
506 strict_strtoul(buf, 10, &data->cached_daylight_max);
507 return adp8860_store(dev, buf, count, ADP8860_BLMX1); 509 return adp8860_store(dev, buf, count, ADP8860_BLMX1);
508} 510}
509static DEVICE_ATTR(l1_daylight_max, 0664, adp8860_bl_l1_daylight_max_show, 511static DEVICE_ATTR(l1_daylight_max, 0664, adp8860_bl_l1_daylight_max_show,
@@ -614,7 +616,7 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev,
614 if (val == 0) { 616 if (val == 0) {
615 /* Enable automatic ambient light sensing */ 617 /* Enable automatic ambient light sensing */
616 adp8860_set_bits(data->client, ADP8860_MDCR, CMP_AUTOEN); 618 adp8860_set_bits(data->client, ADP8860_MDCR, CMP_AUTOEN);
617 } else if ((val > 0) && (val < 6)) { 619 } else if ((val > 0) && (val <= 3)) {
618 /* Disable automatic ambient light sensing */ 620 /* Disable automatic ambient light sensing */
619 adp8860_clr_bits(data->client, ADP8860_MDCR, CMP_AUTOEN); 621 adp8860_clr_bits(data->client, ADP8860_MDCR, CMP_AUTOEN);
620 622
@@ -622,7 +624,7 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev,
622 mutex_lock(&data->lock); 624 mutex_lock(&data->lock);
623 adp8860_read(data->client, ADP8860_CFGR, &reg_val); 625 adp8860_read(data->client, ADP8860_CFGR, &reg_val);
624 reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); 626 reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT);
625 reg_val |= val << CFGR_BLV_SHIFT; 627 reg_val |= (val - 1) << CFGR_BLV_SHIFT;
626 adp8860_write(data->client, ADP8860_CFGR, reg_val); 628 adp8860_write(data->client, ADP8860_CFGR, reg_val);
627 mutex_unlock(&data->lock); 629 mutex_unlock(&data->lock);
628 } 630 }
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index e207810bba3c..08703299ef61 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -197,12 +197,12 @@ static int backlight_suspend(struct device *dev, pm_message_t state)
197{ 197{
198 struct backlight_device *bd = to_backlight_device(dev); 198 struct backlight_device *bd = to_backlight_device(dev);
199 199
200 if (bd->ops->options & BL_CORE_SUSPENDRESUME) { 200 mutex_lock(&bd->ops_lock);
201 mutex_lock(&bd->ops_lock); 201 if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) {
202 bd->props.state |= BL_CORE_SUSPENDED; 202 bd->props.state |= BL_CORE_SUSPENDED;
203 backlight_update_status(bd); 203 backlight_update_status(bd);
204 mutex_unlock(&bd->ops_lock);
205 } 204 }
205 mutex_unlock(&bd->ops_lock);
206 206
207 return 0; 207 return 0;
208} 208}
@@ -211,12 +211,12 @@ static int backlight_resume(struct device *dev)
211{ 211{
212 struct backlight_device *bd = to_backlight_device(dev); 212 struct backlight_device *bd = to_backlight_device(dev);
213 213
214 if (bd->ops->options & BL_CORE_SUSPENDRESUME) { 214 mutex_lock(&bd->ops_lock);
215 mutex_lock(&bd->ops_lock); 215 if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) {
216 bd->props.state &= ~BL_CORE_SUSPENDED; 216 bd->props.state &= ~BL_CORE_SUSPENDED;
217 backlight_update_status(bd); 217 backlight_update_status(bd);
218 mutex_unlock(&bd->ops_lock);
219 } 218 }
219 mutex_unlock(&bd->ops_lock);
220 220
221 return 0; 221 return 0;
222} 222}
diff --git a/drivers/video/backlight/l4f00242t03.c b/drivers/video/backlight/l4f00242t03.c
index 9093ef0fa869..c67801e57aaf 100644
--- a/drivers/video/backlight/l4f00242t03.c
+++ b/drivers/video/backlight/l4f00242t03.c
@@ -78,7 +78,7 @@ static int l4f00242t03_lcd_power_set(struct lcd_device *ld, int power)
78 const u16 slpin = 0x10; 78 const u16 slpin = 0x10;
79 const u16 disoff = 0x28; 79 const u16 disoff = 0x28;
80 80
81 if (power) { 81 if (power <= FB_BLANK_NORMAL) {
82 if (priv->lcd_on) 82 if (priv->lcd_on)
83 return 0; 83 return 0;
84 84
diff --git a/drivers/video/backlight/lms283gf05.c b/drivers/video/backlight/lms283gf05.c
index abc43a0eb97d..5d3cf33953ac 100644
--- a/drivers/video/backlight/lms283gf05.c
+++ b/drivers/video/backlight/lms283gf05.c
@@ -129,7 +129,7 @@ static int lms283gf05_power_set(struct lcd_device *ld, int power)
129 struct spi_device *spi = st->spi; 129 struct spi_device *spi = st->spi;
130 struct lms283gf05_pdata *pdata = spi->dev.platform_data; 130 struct lms283gf05_pdata *pdata = spi->dev.platform_data;
131 131
132 if (power) { 132 if (power <= FB_BLANK_NORMAL) {
133 if (pdata) 133 if (pdata)
134 lms283gf05_reset(pdata->reset_gpio, 134 lms283gf05_reset(pdata->reset_gpio,
135 pdata->reset_inverted); 135 pdata->reset_inverted);
diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
index 9fb533f6373e..1485f7345f49 100644
--- a/drivers/video/backlight/mbp_nvidia_bl.c
+++ b/drivers/video/backlight/mbp_nvidia_bl.c
@@ -335,6 +335,24 @@ static const struct dmi_system_id __initdata mbp_device_table[] = {
335 }, 335 },
336 .driver_data = (void *)&nvidia_chipset_data, 336 .driver_data = (void *)&nvidia_chipset_data,
337 }, 337 },
338 {
339 .callback = mbp_dmi_match,
340 .ident = "MacBookAir 3,1",
341 .matches = {
342 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
343 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir3,1"),
344 },
345 .driver_data = (void *)&nvidia_chipset_data,
346 },
347 {
348 .callback = mbp_dmi_match,
349 .ident = "MacBookAir 3,2",
350 .matches = {
351 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
352 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir3,2"),
353 },
354 .driver_data = (void *)&nvidia_chipset_data,
355 },
338 { } 356 { }
339}; 357};
340 358
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 550443518891..21866ec69656 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -25,6 +25,7 @@ struct pwm_bl_data {
25 struct pwm_device *pwm; 25 struct pwm_device *pwm;
26 struct device *dev; 26 struct device *dev;
27 unsigned int period; 27 unsigned int period;
28 unsigned int lth_brightness;
28 int (*notify)(struct device *, 29 int (*notify)(struct device *,
29 int brightness); 30 int brightness);
30}; 31};
@@ -48,7 +49,9 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
48 pwm_config(pb->pwm, 0, pb->period); 49 pwm_config(pb->pwm, 0, pb->period);
49 pwm_disable(pb->pwm); 50 pwm_disable(pb->pwm);
50 } else { 51 } else {
51 pwm_config(pb->pwm, brightness * pb->period / max, pb->period); 52 brightness = pb->lth_brightness +
53 (brightness * (pb->period - pb->lth_brightness) / max);
54 pwm_config(pb->pwm, brightness, pb->period);
52 pwm_enable(pb->pwm); 55 pwm_enable(pb->pwm);
53 } 56 }
54 return 0; 57 return 0;
@@ -92,6 +95,8 @@ static int pwm_backlight_probe(struct platform_device *pdev)
92 95
93 pb->period = data->pwm_period_ns; 96 pb->period = data->pwm_period_ns;
94 pb->notify = data->notify; 97 pb->notify = data->notify;
98 pb->lth_brightness = data->lth_brightness *
99 (data->pwm_period_ns / data->max_brightness);
95 pb->dev = &pdev->dev; 100 pb->dev = &pdev->dev;
96 101
97 pb->pwm = pwm_request(data->pwm_id, "backlight"); 102 pb->pwm = pwm_request(data->pwm_id, "backlight");
diff --git a/drivers/video/backlight/s6e63m0.c b/drivers/video/backlight/s6e63m0.c
index a3128c9cb7ad..5927db0da999 100644
--- a/drivers/video/backlight/s6e63m0.c
+++ b/drivers/video/backlight/s6e63m0.c
@@ -729,10 +729,10 @@ static ssize_t s6e63m0_sysfs_show_gamma_table(struct device *dev,
729 729
730 return strlen(buf); 730 return strlen(buf);
731} 731}
732static DEVICE_ATTR(gamma_table, 0644, 732static DEVICE_ATTR(gamma_table, 0444,
733 s6e63m0_sysfs_show_gamma_table, NULL); 733 s6e63m0_sysfs_show_gamma_table, NULL);
734 734
735static int __init s6e63m0_probe(struct spi_device *spi) 735static int __devinit s6e63m0_probe(struct spi_device *spi)
736{ 736{
737 int ret = 0; 737 int ret = 0;
738 struct s6e63m0 *lcd = NULL; 738 struct s6e63m0 *lcd = NULL;
@@ -829,6 +829,9 @@ static int __devexit s6e63m0_remove(struct spi_device *spi)
829 struct s6e63m0 *lcd = dev_get_drvdata(&spi->dev); 829 struct s6e63m0 *lcd = dev_get_drvdata(&spi->dev);
830 830
831 s6e63m0_power(lcd, FB_BLANK_POWERDOWN); 831 s6e63m0_power(lcd, FB_BLANK_POWERDOWN);
832 device_remove_file(&spi->dev, &dev_attr_gamma_table);
833 device_remove_file(&spi->dev, &dev_attr_gamma_mode);
834 backlight_device_unregister(lcd->bd);
832 lcd_device_unregister(lcd->ld); 835 lcd_device_unregister(lcd->ld);
833 kfree(lcd); 836 kfree(lcd);
834 837
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 54e32c513610..915448ec75bf 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -47,7 +47,6 @@
47#include <linux/ioport.h> 47#include <linux/ioport.h>
48#include <linux/init.h> 48#include <linux/init.h>
49#include <linux/screen_info.h> 49#include <linux/screen_info.h>
50#include <linux/smp_lock.h>
51#include <video/vga.h> 50#include <video/vga.h>
52#include <asm/io.h> 51#include <asm/io.h>
53 52
diff --git a/drivers/video/da8xx-fb.c b/drivers/video/da8xx-fb.c
index cad7d45c8bac..c265aed09e04 100644
--- a/drivers/video/da8xx-fb.c
+++ b/drivers/video/da8xx-fb.c
@@ -1029,10 +1029,6 @@ static int __init fb_probe(struct platform_device *device)
1029 goto err_release_pl_mem; 1029 goto err_release_pl_mem;
1030 } 1030 }
1031 1031
1032 ret = request_irq(par->irq, lcdc_irq_handler, 0, DRIVER_NAME, par);
1033 if (ret)
1034 goto err_release_pl_mem;
1035
1036 /* Initialize par */ 1032 /* Initialize par */
1037 da8xx_fb_info->var.bits_per_pixel = lcd_cfg->bpp; 1033 da8xx_fb_info->var.bits_per_pixel = lcd_cfg->bpp;
1038 1034
@@ -1060,7 +1056,7 @@ static int __init fb_probe(struct platform_device *device)
1060 1056
1061 ret = fb_alloc_cmap(&da8xx_fb_info->cmap, PALETTE_SIZE, 0); 1057 ret = fb_alloc_cmap(&da8xx_fb_info->cmap, PALETTE_SIZE, 0);
1062 if (ret) 1058 if (ret)
1063 goto err_free_irq; 1059 goto err_release_pl_mem;
1064 da8xx_fb_info->cmap.len = par->palette_sz; 1060 da8xx_fb_info->cmap.len = par->palette_sz;
1065 1061
1066 /* initialize var_screeninfo */ 1062 /* initialize var_screeninfo */
@@ -1088,8 +1084,13 @@ static int __init fb_probe(struct platform_device *device)
1088 goto err_cpu_freq; 1084 goto err_cpu_freq;
1089 } 1085 }
1090#endif 1086#endif
1087
1088 ret = request_irq(par->irq, lcdc_irq_handler, 0, DRIVER_NAME, par);
1089 if (ret)
1090 goto irq_freq;
1091 return 0; 1091 return 0;
1092 1092
1093irq_freq:
1093#ifdef CONFIG_CPU_FREQ 1094#ifdef CONFIG_CPU_FREQ
1094err_cpu_freq: 1095err_cpu_freq:
1095 unregister_framebuffer(da8xx_fb_info); 1096 unregister_framebuffer(da8xx_fb_info);
@@ -1098,9 +1099,6 @@ err_cpu_freq:
1098err_dealloc_cmap: 1099err_dealloc_cmap:
1099 fb_dealloc_cmap(&da8xx_fb_info->cmap); 1100 fb_dealloc_cmap(&da8xx_fb_info->cmap);
1100 1101
1101err_free_irq:
1102 free_irq(par->irq, par);
1103
1104err_release_pl_mem: 1102err_release_pl_mem:
1105 dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base, 1103 dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base,
1106 par->p_palette_base); 1104 par->p_palette_base);
diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
index f53b9f1d6aba..5c3960da755a 100644
--- a/drivers/video/fbcmap.c
+++ b/drivers/video/fbcmap.c
@@ -80,6 +80,7 @@ static const struct fb_cmap default_16_colors = {
80 * @cmap: frame buffer colormap structure 80 * @cmap: frame buffer colormap structure
81 * @len: length of @cmap 81 * @len: length of @cmap
82 * @transp: boolean, 1 if there is transparency, 0 otherwise 82 * @transp: boolean, 1 if there is transparency, 0 otherwise
83 * @flags: flags for kmalloc memory allocation
83 * 84 *
84 * Allocates memory for a colormap @cmap. @len is the 85 * Allocates memory for a colormap @cmap. @len is the
85 * number of entries in the palette. 86 * number of entries in the palette.
@@ -88,34 +89,48 @@ static const struct fb_cmap default_16_colors = {
88 * 89 *
89 */ 90 */
90 91
91int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp) 92int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags)
92{ 93{
93 int size = len*sizeof(u16); 94 int size = len * sizeof(u16);
94 95 int ret = -ENOMEM;
95 if (cmap->len != len) { 96
96 fb_dealloc_cmap(cmap); 97 if (cmap->len != len) {
97 if (!len) 98 fb_dealloc_cmap(cmap);
98 return 0; 99 if (!len)
99 if (!(cmap->red = kmalloc(size, GFP_ATOMIC))) 100 return 0;
100 goto fail; 101
101 if (!(cmap->green = kmalloc(size, GFP_ATOMIC))) 102 cmap->red = kmalloc(size, flags);
102 goto fail; 103 if (!cmap->red)
103 if (!(cmap->blue = kmalloc(size, GFP_ATOMIC))) 104 goto fail;
104 goto fail; 105 cmap->green = kmalloc(size, flags);
105 if (transp) { 106 if (!cmap->green)
106 if (!(cmap->transp = kmalloc(size, GFP_ATOMIC))) 107 goto fail;
108 cmap->blue = kmalloc(size, flags);
109 if (!cmap->blue)
110 goto fail;
111 if (transp) {
112 cmap->transp = kmalloc(size, flags);
113 if (!cmap->transp)
114 goto fail;
115 } else {
116 cmap->transp = NULL;
117 }
118 }
119 cmap->start = 0;
120 cmap->len = len;
121 ret = fb_copy_cmap(fb_default_cmap(len), cmap);
122 if (ret)
107 goto fail; 123 goto fail;
108 } else 124 return 0;
109 cmap->transp = NULL;
110 }
111 cmap->start = 0;
112 cmap->len = len;
113 fb_copy_cmap(fb_default_cmap(len), cmap);
114 return 0;
115 125
116fail: 126fail:
117 fb_dealloc_cmap(cmap); 127 fb_dealloc_cmap(cmap);
118 return -ENOMEM; 128 return ret;
129}
130
131int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp)
132{
133 return fb_alloc_cmap_gfp(cmap, len, transp, GFP_ATOMIC);
119} 134}
120 135
121/** 136/**
@@ -250,8 +265,12 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
250 int rc, size = cmap->len * sizeof(u16); 265 int rc, size = cmap->len * sizeof(u16);
251 struct fb_cmap umap; 266 struct fb_cmap umap;
252 267
268 if (size < 0 || size < cmap->len)
269 return -E2BIG;
270
253 memset(&umap, 0, sizeof(struct fb_cmap)); 271 memset(&umap, 0, sizeof(struct fb_cmap));
254 rc = fb_alloc_cmap(&umap, cmap->len, cmap->transp != NULL); 272 rc = fb_alloc_cmap_gfp(&umap, cmap->len, cmap->transp != NULL,
273 GFP_KERNEL);
255 if (rc) 274 if (rc)
256 return rc; 275 return rc;
257 if (copy_from_user(umap.red, cmap->red, size) || 276 if (copy_from_user(umap.red, cmap->red, size) ||
diff --git a/drivers/video/geode/lxfb.h b/drivers/video/geode/lxfb.h
index e4c4d89b7860..be8ccb47ebe0 100644
--- a/drivers/video/geode/lxfb.h
+++ b/drivers/video/geode/lxfb.h
@@ -22,6 +22,7 @@
22#define DC_HFILT_COUNT 0x100 22#define DC_HFILT_COUNT 0x100
23#define DC_VFILT_COUNT 0x100 23#define DC_VFILT_COUNT 0x100
24#define VP_COEFF_SIZE 0x1000 24#define VP_COEFF_SIZE 0x1000
25#define VP_PAL_COUNT 0x100
25 26
26#define OUTPUT_CRT 0x01 27#define OUTPUT_CRT 0x01
27#define OUTPUT_PANEL 0x02 28#define OUTPUT_PANEL 0x02
@@ -48,7 +49,8 @@ struct lxfb_par {
48 uint64_t vp[VP_REG_COUNT]; 49 uint64_t vp[VP_REG_COUNT];
49 uint64_t fp[FP_REG_COUNT]; 50 uint64_t fp[FP_REG_COUNT];
50 51
51 uint32_t pal[DC_PAL_COUNT]; 52 uint32_t dc_pal[DC_PAL_COUNT];
53 uint32_t vp_pal[VP_PAL_COUNT];
52 uint32_t hcoeff[DC_HFILT_COUNT * 2]; 54 uint32_t hcoeff[DC_HFILT_COUNT * 2];
53 uint32_t vcoeff[DC_VFILT_COUNT]; 55 uint32_t vcoeff[DC_VFILT_COUNT];
54 uint32_t vp_coeff[VP_COEFF_SIZE / 4]; 56 uint32_t vp_coeff[VP_COEFF_SIZE / 4];
diff --git a/drivers/video/geode/lxfb_ops.c b/drivers/video/geode/lxfb_ops.c
index bc35a95e59d4..79e9abc72b83 100644
--- a/drivers/video/geode/lxfb_ops.c
+++ b/drivers/video/geode/lxfb_ops.c
@@ -276,10 +276,10 @@ static void lx_graphics_enable(struct fb_info *info)
276 write_fp(par, FP_PT1, 0); 276 write_fp(par, FP_PT1, 0);
277 temp = FP_PT2_SCRC; 277 temp = FP_PT2_SCRC;
278 278
279 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) 279 if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
280 temp |= FP_PT2_HSP; 280 temp |= FP_PT2_HSP;
281 281
282 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) 282 if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
283 temp |= FP_PT2_VSP; 283 temp |= FP_PT2_VSP;
284 284
285 write_fp(par, FP_PT2, temp); 285 write_fp(par, FP_PT2, temp);
@@ -610,10 +610,15 @@ static void lx_save_regs(struct lxfb_par *par)
610 memcpy(par->vp, par->vp_regs, sizeof(par->vp)); 610 memcpy(par->vp, par->vp_regs, sizeof(par->vp));
611 memcpy(par->fp, par->vp_regs + VP_FP_START, sizeof(par->fp)); 611 memcpy(par->fp, par->vp_regs + VP_FP_START, sizeof(par->fp));
612 612
613 /* save the palette */ 613 /* save the display controller palette */
614 write_dc(par, DC_PAL_ADDRESS, 0); 614 write_dc(par, DC_PAL_ADDRESS, 0);
615 for (i = 0; i < ARRAY_SIZE(par->pal); i++) 615 for (i = 0; i < ARRAY_SIZE(par->dc_pal); i++)
616 par->pal[i] = read_dc(par, DC_PAL_DATA); 616 par->dc_pal[i] = read_dc(par, DC_PAL_DATA);
617
618 /* save the video processor palette */
619 write_vp(par, VP_PAR, 0);
620 for (i = 0; i < ARRAY_SIZE(par->vp_pal); i++)
621 par->vp_pal[i] = read_vp(par, VP_PDR);
617 622
618 /* save the horizontal filter coefficients */ 623 /* save the horizontal filter coefficients */
619 filt = par->dc[DC_IRQ_FILT_CTL] | DC_IRQ_FILT_CTL_H_FILT_SEL; 624 filt = par->dc[DC_IRQ_FILT_CTL] | DC_IRQ_FILT_CTL_H_FILT_SEL;
@@ -706,8 +711,8 @@ static void lx_restore_display_ctlr(struct lxfb_par *par)
706 711
707 /* restore the palette */ 712 /* restore the palette */
708 write_dc(par, DC_PAL_ADDRESS, 0); 713 write_dc(par, DC_PAL_ADDRESS, 0);
709 for (i = 0; i < ARRAY_SIZE(par->pal); i++) 714 for (i = 0; i < ARRAY_SIZE(par->dc_pal); i++)
710 write_dc(par, DC_PAL_DATA, par->pal[i]); 715 write_dc(par, DC_PAL_DATA, par->dc_pal[i]);
711 716
712 /* restore the horizontal filter coefficients */ 717 /* restore the horizontal filter coefficients */
713 filt = par->dc[DC_IRQ_FILT_CTL] | DC_IRQ_FILT_CTL_H_FILT_SEL; 718 filt = par->dc[DC_IRQ_FILT_CTL] | DC_IRQ_FILT_CTL_H_FILT_SEL;
@@ -751,6 +756,11 @@ static void lx_restore_video_proc(struct lxfb_par *par)
751 } 756 }
752 } 757 }
753 758
759 /* restore video processor palette */
760 write_vp(par, VP_PAR, 0);
761 for (i = 0; i < ARRAY_SIZE(par->vp_pal); i++)
762 write_vp(par, VP_PDR, par->vp_pal[i]);
763
754 /* restore video coeff ram */ 764 /* restore video coeff ram */
755 memcpy(par->vp_regs + VP_VCR, par->vp_coeff, sizeof(par->vp_coeff)); 765 memcpy(par->vp_regs + VP_VCR, par->vp_coeff, sizeof(par->vp_coeff));
756} 766}
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 0a4dbdc1693a..de450c1fb869 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -855,6 +855,7 @@ const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
855 abs(cmode->yres - mode->yres); 855 abs(cmode->yres - mode->yres);
856 if (diff > d) { 856 if (diff > d) {
857 diff = d; 857 diff = d;
858 diff_refresh = abs(cmode->refresh - mode->refresh);
858 best = cmode; 859 best = cmode;
859 } else if (diff == d) { 860 } else if (diff == d) {
860 d = abs(cmode->refresh - mode->refresh); 861 d = abs(cmode->refresh - mode->refresh);
diff --git a/drivers/video/mx3fb.c b/drivers/video/mx3fb.c
index 7cfc170bce19..ca0f6be9d12e 100644
--- a/drivers/video/mx3fb.c
+++ b/drivers/video/mx3fb.c
@@ -27,6 +27,7 @@
27#include <linux/clk.h> 27#include <linux/clk.h>
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29 29
30#include <mach/dma.h>
30#include <mach/hardware.h> 31#include <mach/hardware.h>
31#include <mach/ipu.h> 32#include <mach/ipu.h>
32#include <mach/mx3fb.h> 33#include <mach/mx3fb.h>
@@ -1420,6 +1421,9 @@ static bool chan_filter(struct dma_chan *chan, void *arg)
1420 struct device *dev; 1421 struct device *dev;
1421 struct mx3fb_platform_data *mx3fb_pdata; 1422 struct mx3fb_platform_data *mx3fb_pdata;
1422 1423
1424 if (!imx_dma_is_ipu(chan))
1425 return false;
1426
1423 if (!rq) 1427 if (!rq)
1424 return false; 1428 return false;
1425 1429
diff --git a/drivers/video/omap/Kconfig b/drivers/video/omap/Kconfig
index 455c6055325d..083c8fe53e24 100644
--- a/drivers/video/omap/Kconfig
+++ b/drivers/video/omap/Kconfig
@@ -1,7 +1,7 @@
1config FB_OMAP 1config FB_OMAP
2 tristate "OMAP frame buffer support (EXPERIMENTAL)" 2 tristate "OMAP frame buffer support (EXPERIMENTAL)"
3 depends on FB && ARCH_OMAP && (OMAP2_DSS = "n") 3 depends on FB && (OMAP2_DSS = "n")
4 4 depends on ARCH_OMAP1 || ARCH_OMAP2 || ARCH_OMAP3
5 select FB_CFB_FILLRECT 5 select FB_CFB_FILLRECT
6 select FB_CFB_COPYAREA 6 select FB_CFB_COPYAREA
7 select FB_CFB_IMAGEBLIT 7 select FB_CFB_IMAGEBLIT
diff --git a/drivers/video/omap2/vram.c b/drivers/video/omap2/vram.c
index fed2a72bc6b6..9441e2eb3dee 100644
--- a/drivers/video/omap2/vram.c
+++ b/drivers/video/omap2/vram.c
@@ -551,12 +551,18 @@ void __init omap_vram_reserve_sdram_memblock(void)
551 if (!size) 551 if (!size)
552 return; 552 return;
553 553
554 size = PAGE_ALIGN(size); 554 size = ALIGN(size, SZ_2M);
555 555
556 if (paddr) { 556 if (paddr) {
557 if ((paddr & ~PAGE_MASK) || 557 if (paddr & ~PAGE_MASK) {
558 !memblock_is_region_memory(paddr, size)) { 558 pr_err("VRAM start address 0x%08x not page aligned\n",
559 pr_err("Illegal SDRAM region for VRAM\n"); 559 paddr);
560 return;
561 }
562
563 if (!memblock_is_region_memory(paddr, size)) {
564 pr_err("Illegal SDRAM region 0x%08x..0x%08x for VRAM\n",
565 paddr, paddr + size - 1);
560 return; 566 return;
561 } 567 }
562 568
@@ -570,9 +576,12 @@ void __init omap_vram_reserve_sdram_memblock(void)
570 return; 576 return;
571 } 577 }
572 } else { 578 } else {
573 paddr = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_REAL_LIMIT); 579 paddr = memblock_alloc(size, SZ_2M);
574 } 580 }
575 581
582 memblock_free(paddr, size);
583 memblock_remove(paddr, size);
584
576 omap_vram_add_region(paddr, size); 585 omap_vram_add_region(paddr, size);
577 586
578 pr_info("Reserving %u bytes SDRAM for VRAM\n", size); 587 pr_info("Reserving %u bytes SDRAM for VRAM\n", size);
diff --git a/drivers/video/riva/rivafb-i2c.c b/drivers/video/riva/rivafb-i2c.c
index a0e22ac483a3..167400e2a182 100644
--- a/drivers/video/riva/rivafb-i2c.c
+++ b/drivers/video/riva/rivafb-i2c.c
@@ -94,7 +94,6 @@ static int __devinit riva_setup_i2c_bus(struct riva_i2c_chan *chan,
94 94
95 strcpy(chan->adapter.name, name); 95 strcpy(chan->adapter.name, name);
96 chan->adapter.owner = THIS_MODULE; 96 chan->adapter.owner = THIS_MODULE;
97 chan->adapter.id = I2C_HW_B_RIVA;
98 chan->adapter.class = i2c_class; 97 chan->adapter.class = i2c_class;
99 chan->adapter.algo_data = &chan->algo; 98 chan->adapter.algo_data = &chan->algo;
100 chan->adapter.dev.parent = &chan->par->pdev->dev; 99 chan->adapter.dev.parent = &chan->par->pdev->dev;
diff --git a/drivers/video/sh_mobile_hdmi.c b/drivers/video/sh_mobile_hdmi.c
index 55b3077ff6ff..d7df10315d8d 100644
--- a/drivers/video/sh_mobile_hdmi.c
+++ b/drivers/video/sh_mobile_hdmi.c
@@ -1071,6 +1071,10 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
1071 if (!hdmi->info) 1071 if (!hdmi->info)
1072 goto out; 1072 goto out;
1073 1073
1074 hdmi->monspec.modedb_len = 0;
1075 fb_destroy_modedb(hdmi->monspec.modedb);
1076 hdmi->monspec.modedb = NULL;
1077
1074 acquire_console_sem(); 1078 acquire_console_sem();
1075 1079
1076 /* HDMI disconnect */ 1080 /* HDMI disconnect */
@@ -1078,7 +1082,6 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
1078 1082
1079 release_console_sem(); 1083 release_console_sem();
1080 pm_runtime_put(hdmi->dev); 1084 pm_runtime_put(hdmi->dev);
1081 fb_destroy_modedb(hdmi->monspec.modedb);
1082 } 1085 }
1083 1086
1084out: 1087out:
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index 50963739a409..b02d97a879d6 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -115,15 +115,16 @@ static const struct fb_videomode default_720p = {
115 .xres = 1280, 115 .xres = 1280,
116 .yres = 720, 116 .yres = 720,
117 117
118 .left_margin = 200, 118 .left_margin = 220,
119 .right_margin = 88, 119 .right_margin = 110,
120 .hsync_len = 48, 120 .hsync_len = 40,
121 121
122 .upper_margin = 20, 122 .upper_margin = 20,
123 .lower_margin = 5, 123 .lower_margin = 5,
124 .vsync_len = 5, 124 .vsync_len = 5,
125 125
126 .pixclock = 13468, 126 .pixclock = 13468,
127 .refresh = 60,
127 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT, 128 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
128}; 129};
129 130
@@ -859,7 +860,7 @@ static void sh_mobile_fb_reconfig(struct fb_info *info)
859 /* Couldn't reconfigure, hopefully, can continue as before */ 860 /* Couldn't reconfigure, hopefully, can continue as before */
860 return; 861 return;
861 862
862 info->fix.line_length = mode2.xres * (ch->cfg.bpp / 8); 863 info->fix.line_length = mode1.xres * (ch->cfg.bpp / 8);
863 864
864 /* 865 /*
865 * fb_set_var() calls the notifier change internally, only if 866 * fb_set_var() calls the notifier change internally, only if
@@ -867,7 +868,7 @@ static void sh_mobile_fb_reconfig(struct fb_info *info)
867 * user event, we have to call the chain ourselves. 868 * user event, we have to call the chain ourselves.
868 */ 869 */
869 event.info = info; 870 event.info = info;
870 event.data = &mode2; 871 event.data = &mode1;
871 fb_notifier_call_chain(evnt, &event); 872 fb_notifier_call_chain(evnt, &event);
872} 873}
873 874
@@ -1197,6 +1198,7 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1197 const struct fb_videomode *mode = cfg->lcd_cfg; 1198 const struct fb_videomode *mode = cfg->lcd_cfg;
1198 unsigned long max_size = 0; 1199 unsigned long max_size = 0;
1199 int k; 1200 int k;
1201 int num_cfg;
1200 1202
1201 ch->info = framebuffer_alloc(0, &pdev->dev); 1203 ch->info = framebuffer_alloc(0, &pdev->dev);
1202 if (!ch->info) { 1204 if (!ch->info) {
@@ -1232,8 +1234,14 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1232 info->fix = sh_mobile_lcdc_fix; 1234 info->fix = sh_mobile_lcdc_fix;
1233 info->fix.smem_len = max_size * (cfg->bpp / 8) * 2; 1235 info->fix.smem_len = max_size * (cfg->bpp / 8) * 2;
1234 1236
1235 if (!mode) 1237 if (!mode) {
1236 mode = &default_720p; 1238 mode = &default_720p;
1239 num_cfg = 1;
1240 } else {
1241 num_cfg = ch->cfg.num_cfg;
1242 }
1243
1244 fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
1237 1245
1238 fb_videomode_to_var(var, mode); 1246 fb_videomode_to_var(var, mode);
1239 /* Default Y virtual resolution is 2x panel size */ 1247 /* Default Y virtual resolution is 2x panel size */
@@ -1281,10 +1289,6 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1281 1289
1282 for (i = 0; i < j; i++) { 1290 for (i = 0; i < j; i++) {
1283 struct sh_mobile_lcdc_chan *ch = priv->ch + i; 1291 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1284 const struct fb_videomode *mode = ch->cfg.lcd_cfg;
1285
1286 if (!mode)
1287 mode = &default_720p;
1288 1292
1289 info = ch->info; 1293 info = ch->info;
1290 1294
@@ -1297,7 +1301,6 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1297 } 1301 }
1298 } 1302 }
1299 1303
1300 fb_videomode_to_modelist(mode, ch->cfg.num_cfg, &info->modelist);
1301 error = register_framebuffer(info); 1304 error = register_framebuffer(info);
1302 if (error < 0) 1305 if (error < 0)
1303 goto err1; 1306 goto err1;
diff --git a/drivers/video/sis/init.c b/drivers/video/sis/init.c
index c311ad3c3687..31137adc8fba 100644
--- a/drivers/video/sis/init.c
+++ b/drivers/video/sis/init.c
@@ -62,11 +62,11 @@
62 62
63#include "init.h" 63#include "init.h"
64 64
65#ifdef SIS300 65#ifdef CONFIG_FB_SIS_300
66#include "300vtbl.h" 66#include "300vtbl.h"
67#endif 67#endif
68 68
69#ifdef SIS315H 69#ifdef CONFIG_FB_SIS_315
70#include "310vtbl.h" 70#include "310vtbl.h"
71#endif 71#endif
72 72
@@ -78,7 +78,7 @@
78/* POINTER INITIALIZATION */ 78/* POINTER INITIALIZATION */
79/*********************************************/ 79/*********************************************/
80 80
81#if defined(SIS300) || defined(SIS315H) 81#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
82static void 82static void
83InitCommonPointer(struct SiS_Private *SiS_Pr) 83InitCommonPointer(struct SiS_Private *SiS_Pr)
84{ 84{
@@ -160,7 +160,7 @@ InitCommonPointer(struct SiS_Private *SiS_Pr)
160} 160}
161#endif 161#endif
162 162
163#ifdef SIS300 163#ifdef CONFIG_FB_SIS_300
164static void 164static void
165InitTo300Pointer(struct SiS_Private *SiS_Pr) 165InitTo300Pointer(struct SiS_Private *SiS_Pr)
166{ 166{
@@ -237,7 +237,7 @@ InitTo300Pointer(struct SiS_Private *SiS_Pr)
237} 237}
238#endif 238#endif
239 239
240#ifdef SIS315H 240#ifdef CONFIG_FB_SIS_315
241static void 241static void
242InitTo310Pointer(struct SiS_Private *SiS_Pr) 242InitTo310Pointer(struct SiS_Private *SiS_Pr)
243{ 243{
@@ -321,13 +321,13 @@ bool
321SiSInitPtr(struct SiS_Private *SiS_Pr) 321SiSInitPtr(struct SiS_Private *SiS_Pr)
322{ 322{
323 if(SiS_Pr->ChipType < SIS_315H) { 323 if(SiS_Pr->ChipType < SIS_315H) {
324#ifdef SIS300 324#ifdef CONFIG_FB_SIS_300
325 InitTo300Pointer(SiS_Pr); 325 InitTo300Pointer(SiS_Pr);
326#else 326#else
327 return false; 327 return false;
328#endif 328#endif
329 } else { 329 } else {
330#ifdef SIS315H 330#ifdef CONFIG_FB_SIS_315
331 InitTo310Pointer(SiS_Pr); 331 InitTo310Pointer(SiS_Pr);
332#else 332#else
333 return false; 333 return false;
@@ -340,9 +340,7 @@ SiSInitPtr(struct SiS_Private *SiS_Pr)
340/* HELPER: Get ModeID */ 340/* HELPER: Get ModeID */
341/*********************************************/ 341/*********************************************/
342 342
343#ifndef SIS_XORG_XF86
344static 343static
345#endif
346unsigned short 344unsigned short
347SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, 345SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
348 int Depth, bool FSTN, int LCDwidth, int LCDheight) 346 int Depth, bool FSTN, int LCDwidth, int LCDheight)
@@ -884,51 +882,51 @@ SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDispl
884void 882void
885SiS_SetReg(SISIOADDRESS port, unsigned short index, unsigned short data) 883SiS_SetReg(SISIOADDRESS port, unsigned short index, unsigned short data)
886{ 884{
887 OutPortByte(port, index); 885 outb((u8)index, port);
888 OutPortByte(port + 1, data); 886 outb((u8)data, port + 1);
889} 887}
890 888
891void 889void
892SiS_SetRegByte(SISIOADDRESS port, unsigned short data) 890SiS_SetRegByte(SISIOADDRESS port, unsigned short data)
893{ 891{
894 OutPortByte(port, data); 892 outb((u8)data, port);
895} 893}
896 894
897void 895void
898SiS_SetRegShort(SISIOADDRESS port, unsigned short data) 896SiS_SetRegShort(SISIOADDRESS port, unsigned short data)
899{ 897{
900 OutPortWord(port, data); 898 outw((u16)data, port);
901} 899}
902 900
903void 901void
904SiS_SetRegLong(SISIOADDRESS port, unsigned int data) 902SiS_SetRegLong(SISIOADDRESS port, unsigned int data)
905{ 903{
906 OutPortLong(port, data); 904 outl((u32)data, port);
907} 905}
908 906
909unsigned char 907unsigned char
910SiS_GetReg(SISIOADDRESS port, unsigned short index) 908SiS_GetReg(SISIOADDRESS port, unsigned short index)
911{ 909{
912 OutPortByte(port, index); 910 outb((u8)index, port);
913 return(InPortByte(port + 1)); 911 return inb(port + 1);
914} 912}
915 913
916unsigned char 914unsigned char
917SiS_GetRegByte(SISIOADDRESS port) 915SiS_GetRegByte(SISIOADDRESS port)
918{ 916{
919 return(InPortByte(port)); 917 return inb(port);
920} 918}
921 919
922unsigned short 920unsigned short
923SiS_GetRegShort(SISIOADDRESS port) 921SiS_GetRegShort(SISIOADDRESS port)
924{ 922{
925 return(InPortWord(port)); 923 return inw(port);
926} 924}
927 925
928unsigned int 926unsigned int
929SiS_GetRegLong(SISIOADDRESS port) 927SiS_GetRegLong(SISIOADDRESS port)
930{ 928{
931 return(InPortLong(port)); 929 return inl(port);
932} 930}
933 931
934void 932void
@@ -1089,7 +1087,7 @@ static void
1089SiSInitPCIetc(struct SiS_Private *SiS_Pr) 1087SiSInitPCIetc(struct SiS_Private *SiS_Pr)
1090{ 1088{
1091 switch(SiS_Pr->ChipType) { 1089 switch(SiS_Pr->ChipType) {
1092#ifdef SIS300 1090#ifdef CONFIG_FB_SIS_300
1093 case SIS_300: 1091 case SIS_300:
1094 case SIS_540: 1092 case SIS_540:
1095 case SIS_630: 1093 case SIS_630:
@@ -1108,7 +1106,7 @@ SiSInitPCIetc(struct SiS_Private *SiS_Pr)
1108 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A); 1106 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A);
1109 break; 1107 break;
1110#endif 1108#endif
1111#ifdef SIS315H 1109#ifdef CONFIG_FB_SIS_315
1112 case SIS_315H: 1110 case SIS_315H:
1113 case SIS_315: 1111 case SIS_315:
1114 case SIS_315PRO: 1112 case SIS_315PRO:
@@ -1152,9 +1150,7 @@ SiSInitPCIetc(struct SiS_Private *SiS_Pr)
1152/* HELPER: SetLVDSetc */ 1150/* HELPER: SetLVDSetc */
1153/*********************************************/ 1151/*********************************************/
1154 1152
1155#ifdef SIS_LINUX_KERNEL
1156static 1153static
1157#endif
1158void 1154void
1159SiSSetLVDSetc(struct SiS_Private *SiS_Pr) 1155SiSSetLVDSetc(struct SiS_Private *SiS_Pr)
1160{ 1156{
@@ -1174,7 +1170,7 @@ SiSSetLVDSetc(struct SiS_Private *SiS_Pr)
1174 if((temp == 1) || (temp == 2)) return; 1170 if((temp == 1) || (temp == 2)) return;
1175 1171
1176 switch(SiS_Pr->ChipType) { 1172 switch(SiS_Pr->ChipType) {
1177#ifdef SIS300 1173#ifdef CONFIG_FB_SIS_300
1178 case SIS_540: 1174 case SIS_540:
1179 case SIS_630: 1175 case SIS_630:
1180 case SIS_730: 1176 case SIS_730:
@@ -1188,7 +1184,7 @@ SiSSetLVDSetc(struct SiS_Private *SiS_Pr)
1188 } 1184 }
1189 break; 1185 break;
1190#endif 1186#endif
1191#ifdef SIS315H 1187#ifdef CONFIG_FB_SIS_315
1192 case SIS_550: 1188 case SIS_550:
1193 case SIS_650: 1189 case SIS_650:
1194 case SIS_740: 1190 case SIS_740:
@@ -1420,9 +1416,7 @@ SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr)
1420/* HELPER: GetVBType */ 1416/* HELPER: GetVBType */
1421/*********************************************/ 1417/*********************************************/
1422 1418
1423#ifdef SIS_LINUX_KERNEL
1424static 1419static
1425#endif
1426void 1420void
1427SiS_GetVBType(struct SiS_Private *SiS_Pr) 1421SiS_GetVBType(struct SiS_Private *SiS_Pr)
1428{ 1422{
@@ -1487,7 +1481,6 @@ SiS_GetVBType(struct SiS_Private *SiS_Pr)
1487/* HELPER: Check RAM size */ 1481/* HELPER: Check RAM size */
1488/*********************************************/ 1482/*********************************************/
1489 1483
1490#ifdef SIS_LINUX_KERNEL
1491static bool 1484static bool
1492SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1485SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1493 unsigned short ModeIdIndex) 1486 unsigned short ModeIdIndex)
@@ -1501,13 +1494,12 @@ SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1501 if(AdapterMemSize < memorysize) return false; 1494 if(AdapterMemSize < memorysize) return false;
1502 return true; 1495 return true;
1503} 1496}
1504#endif
1505 1497
1506/*********************************************/ 1498/*********************************************/
1507/* HELPER: Get DRAM type */ 1499/* HELPER: Get DRAM type */
1508/*********************************************/ 1500/*********************************************/
1509 1501
1510#ifdef SIS315H 1502#ifdef CONFIG_FB_SIS_315
1511static unsigned char 1503static unsigned char
1512SiS_Get310DRAMType(struct SiS_Private *SiS_Pr) 1504SiS_Get310DRAMType(struct SiS_Private *SiS_Pr)
1513{ 1505{
@@ -1574,7 +1566,6 @@ SiS_GetMCLK(struct SiS_Private *SiS_Pr)
1574/* HELPER: ClearBuffer */ 1566/* HELPER: ClearBuffer */
1575/*********************************************/ 1567/*********************************************/
1576 1568
1577#ifdef SIS_LINUX_KERNEL
1578static void 1569static void
1579SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo) 1570SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1580{ 1571{
@@ -1587,7 +1578,7 @@ SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1587 1578
1588 if(SiS_Pr->SiS_ModeType >= ModeEGA) { 1579 if(SiS_Pr->SiS_ModeType >= ModeEGA) {
1589 if(ModeNo > 0x13) { 1580 if(ModeNo > 0x13) {
1590 SiS_SetMemory(memaddr, memsize, 0); 1581 memset_io(memaddr, 0, memsize);
1591 } else { 1582 } else {
1592 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr; 1583 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
1593 for(i = 0; i < 0x4000; i++) writew(0x0000, &pBuffer[i]); 1584 for(i = 0; i < 0x4000; i++) writew(0x0000, &pBuffer[i]);
@@ -1596,10 +1587,9 @@ SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1596 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr; 1587 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
1597 for(i = 0; i < 0x4000; i++) writew(0x0720, &pBuffer[i]); 1588 for(i = 0; i < 0x4000; i++) writew(0x0720, &pBuffer[i]);
1598 } else { 1589 } else {
1599 SiS_SetMemory(memaddr, 0x8000, 0); 1590 memset_io(memaddr, 0, 0x8000);
1600 } 1591 }
1601} 1592}
1602#endif
1603 1593
1604/*********************************************/ 1594/*********************************************/
1605/* HELPER: SearchModeID */ 1595/* HELPER: SearchModeID */
@@ -2132,7 +2122,7 @@ SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2132 SiS_SetReg(SiS_Pr->SiS_P3d4,0x14,0x4F); 2122 SiS_SetReg(SiS_Pr->SiS_P3d4,0x14,0x4F);
2133 } 2123 }
2134 2124
2135#ifdef SIS315H 2125#ifdef CONFIG_FB_SIS_315
2136 if(SiS_Pr->ChipType == XGI_20) { 2126 if(SiS_Pr->ChipType == XGI_20) {
2137 SiS_SetReg(SiS_Pr->SiS_P3d4,0x04,crt1data[4] - 1); 2127 SiS_SetReg(SiS_Pr->SiS_P3d4,0x04,crt1data[4] - 1);
2138 if(!(temp = crt1data[5] & 0x1f)) { 2128 if(!(temp = crt1data[5] & 0x1f)) {
@@ -2215,7 +2205,7 @@ SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2215 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb); 2205 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
2216 2206
2217 if(SiS_Pr->ChipType >= SIS_315H) { 2207 if(SiS_Pr->ChipType >= SIS_315H) {
2218#ifdef SIS315H 2208#ifdef CONFIG_FB_SIS_315
2219 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x01); 2209 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x01);
2220 if(SiS_Pr->ChipType == XGI_20) { 2210 if(SiS_Pr->ChipType == XGI_20) {
2221 unsigned short mf = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex); 2211 unsigned short mf = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
@@ -2236,7 +2226,7 @@ SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2236/* FIFO */ 2226/* FIFO */
2237/*********************************************/ 2227/*********************************************/
2238 2228
2239#ifdef SIS300 2229#ifdef CONFIG_FB_SIS_300
2240void 2230void
2241SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1, 2231SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
2242 unsigned short *idx2) 2232 unsigned short *idx2)
@@ -2506,11 +2496,7 @@ SiS_SetCRT1FIFO_630(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2506 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data); 2496 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data);
2507 2497
2508 /* Write foreground and background queue */ 2498 /* Write foreground and background queue */
2509#ifdef SIS_LINUX_KERNEL
2510 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50); 2499 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
2511#else
2512 templ = pciReadLong(0x00000000, 0x50);
2513#endif
2514 2500
2515 if(SiS_Pr->ChipType == SIS_730) { 2501 if(SiS_Pr->ChipType == SIS_730) {
2516 2502
@@ -2530,13 +2516,8 @@ SiS_SetCRT1FIFO_630(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2530 2516
2531 } 2517 }
2532 2518
2533#ifdef SIS_LINUX_KERNEL
2534 sisfb_write_nbridge_pci_dword(SiS_Pr, 0x50, templ); 2519 sisfb_write_nbridge_pci_dword(SiS_Pr, 0x50, templ);
2535 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xA0); 2520 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xA0);
2536#else
2537 pciWriteLong(0x00000000, 0x50, templ);
2538 templ = pciReadLong(0x00000000, 0xA0);
2539#endif
2540 2521
2541 /* GUI grant timer (PCI config 0xA3) */ 2522 /* GUI grant timer (PCI config 0xA3) */
2542 if(SiS_Pr->ChipType == SIS_730) { 2523 if(SiS_Pr->ChipType == SIS_730) {
@@ -2552,15 +2533,11 @@ SiS_SetCRT1FIFO_630(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2552 2533
2553 } 2534 }
2554 2535
2555#ifdef SIS_LINUX_KERNEL
2556 sisfb_write_nbridge_pci_dword(SiS_Pr, 0xA0, templ); 2536 sisfb_write_nbridge_pci_dword(SiS_Pr, 0xA0, templ);
2557#else
2558 pciWriteLong(0x00000000, 0xA0, templ);
2559#endif
2560} 2537}
2561#endif /* SIS300 */ 2538#endif /* CONFIG_FB_SIS_300 */
2562 2539
2563#ifdef SIS315H 2540#ifdef CONFIG_FB_SIS_315
2564static void 2541static void
2565SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) 2542SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
2566{ 2543{
@@ -2612,7 +2589,7 @@ SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2612 } 2589 }
2613 2590
2614 if(SiS_Pr->ChipType < SIS_315H) { 2591 if(SiS_Pr->ChipType < SIS_315H) {
2615#ifdef SIS300 2592#ifdef CONFIG_FB_SIS_300
2616 if(VCLK > 150) data |= 0x80; 2593 if(VCLK > 150) data |= 0x80;
2617 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data); 2594 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data);
2618 2595
@@ -2621,7 +2598,7 @@ SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2621 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data); 2598 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data);
2622#endif 2599#endif
2623 } else if(SiS_Pr->ChipType < XGI_20) { 2600 } else if(SiS_Pr->ChipType < XGI_20) {
2624#ifdef SIS315H 2601#ifdef CONFIG_FB_SIS_315
2625 if(VCLK >= 166) data |= 0x0c; 2602 if(VCLK >= 166) data |= 0x0c;
2626 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data); 2603 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
2627 2604
@@ -2630,7 +2607,7 @@ SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2630 } 2607 }
2631#endif 2608#endif
2632 } else { 2609 } else {
2633#ifdef SIS315H 2610#ifdef CONFIG_FB_SIS_315
2634 if(VCLK >= 200) data |= 0x0c; 2611 if(VCLK >= 200) data |= 0x0c;
2635 if(SiS_Pr->ChipType == XGI_20) data &= ~0x04; 2612 if(SiS_Pr->ChipType == XGI_20) data &= ~0x04;
2636 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data); 2613 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
@@ -2675,7 +2652,7 @@ SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2675 unsigned short ModeIdIndex, unsigned short RRTI) 2652 unsigned short ModeIdIndex, unsigned short RRTI)
2676{ 2653{
2677 unsigned short data, infoflag = 0, modeflag, resindex; 2654 unsigned short data, infoflag = 0, modeflag, resindex;
2678#ifdef SIS315H 2655#ifdef CONFIG_FB_SIS_315
2679 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 2656 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
2680 unsigned short data2, data3; 2657 unsigned short data2, data3;
2681#endif 2658#endif
@@ -2736,7 +2713,7 @@ SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2736 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data); 2713 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data);
2737 } 2714 }
2738 2715
2739#ifdef SIS315H 2716#ifdef CONFIG_FB_SIS_315
2740 if(SiS_Pr->ChipType >= SIS_315H) { 2717 if(SiS_Pr->ChipType >= SIS_315H) {
2741 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb); 2718 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb);
2742 } 2719 }
@@ -2826,7 +2803,7 @@ SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2826 2803
2827 SiS_SetVCLKState(SiS_Pr, ModeNo, RRTI, ModeIdIndex); 2804 SiS_SetVCLKState(SiS_Pr, ModeNo, RRTI, ModeIdIndex);
2828 2805
2829#ifdef SIS315H 2806#ifdef CONFIG_FB_SIS_315
2830 if(((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) || 2807 if(((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) ||
2831 (SiS_Pr->ChipType == XGI_40)) { 2808 (SiS_Pr->ChipType == XGI_40)) {
2832 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) { 2809 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
@@ -2845,7 +2822,7 @@ SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2845#endif 2822#endif
2846} 2823}
2847 2824
2848#ifdef SIS315H 2825#ifdef CONFIG_FB_SIS_315
2849static void 2826static void
2850SiS_SetupDualChip(struct SiS_Private *SiS_Pr) 2827SiS_SetupDualChip(struct SiS_Private *SiS_Pr)
2851{ 2828{
@@ -2999,11 +2976,6 @@ SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sho
2999 SiS_Pr->SiS_SelectCRT2Rate = 0; 2976 SiS_Pr->SiS_SelectCRT2Rate = 0;
3000 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); 2977 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
3001 2978
3002#ifdef SIS_XORG_XF86
3003 xf86DrvMsgVerb(0, X_PROBED, 4, "(init: VBType=0x%04x, VBInfo=0x%04x)\n",
3004 SiS_Pr->SiS_VBType, SiS_Pr->SiS_VBInfo);
3005#endif
3006
3007 if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) { 2979 if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
3008 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { 2980 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
3009 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; 2981 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
@@ -3028,7 +3000,7 @@ SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sho
3028 } 3000 }
3029 3001
3030 switch(SiS_Pr->ChipType) { 3002 switch(SiS_Pr->ChipType) {
3031#ifdef SIS300 3003#ifdef CONFIG_FB_SIS_300
3032 case SIS_300: 3004 case SIS_300:
3033 SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo, RefreshRateTableIndex); 3005 SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo, RefreshRateTableIndex);
3034 break; 3006 break;
@@ -3039,7 +3011,7 @@ SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sho
3039 break; 3011 break;
3040#endif 3012#endif
3041 default: 3013 default:
3042#ifdef SIS315H 3014#ifdef CONFIG_FB_SIS_315
3043 if(SiS_Pr->ChipType == XGI_20) { 3015 if(SiS_Pr->ChipType == XGI_20) {
3044 unsigned char sr2b = 0, sr2c = 0; 3016 unsigned char sr2b = 0, sr2c = 0;
3045 switch(ModeNo) { 3017 switch(ModeNo) {
@@ -3062,7 +3034,7 @@ SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sho
3062 3034
3063 SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); 3035 SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3064 3036
3065#ifdef SIS315H 3037#ifdef CONFIG_FB_SIS_315
3066 if(SiS_Pr->ChipType == XGI_40) { 3038 if(SiS_Pr->ChipType == XGI_40) {
3067 SiS_SetupDualChip(SiS_Pr); 3039 SiS_SetupDualChip(SiS_Pr);
3068 } 3040 }
@@ -3070,11 +3042,9 @@ SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sho
3070 3042
3071 SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex); 3043 SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
3072 3044
3073#ifdef SIS_LINUX_KERNEL
3074 if(SiS_Pr->SiS_flag_clearbuffer) { 3045 if(SiS_Pr->SiS_flag_clearbuffer) {
3075 SiS_ClearBuffer(SiS_Pr, ModeNo); 3046 SiS_ClearBuffer(SiS_Pr, ModeNo);
3076 } 3047 }
3077#endif
3078 3048
3079 if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) { 3049 if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) {
3080 SiS_WaitRetrace1(SiS_Pr); 3050 SiS_WaitRetrace1(SiS_Pr);
@@ -3104,7 +3074,7 @@ SiS_InitVB(struct SiS_Private *SiS_Pr)
3104static void 3074static void
3105SiS_ResetVB(struct SiS_Private *SiS_Pr) 3075SiS_ResetVB(struct SiS_Private *SiS_Pr)
3106{ 3076{
3107#ifdef SIS315H 3077#ifdef CONFIG_FB_SIS_315
3108 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 3078 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
3109 unsigned short temp; 3079 unsigned short temp;
3110 3080
@@ -3139,7 +3109,7 @@ SiS_StrangeStuff(struct SiS_Private *SiS_Pr)
3139 * which locks CRT2 in some way to CRT1 timing. Disable 3109 * which locks CRT2 in some way to CRT1 timing. Disable
3140 * this here. 3110 * this here.
3141 */ 3111 */
3142#ifdef SIS315H 3112#ifdef CONFIG_FB_SIS_315
3143 if((IS_SIS651) || (IS_SISM650) || 3113 if((IS_SIS651) || (IS_SISM650) ||
3144 SiS_Pr->ChipType == SIS_340 || 3114 SiS_Pr->ChipType == SIS_340 ||
3145 SiS_Pr->ChipType == XGI_40) { 3115 SiS_Pr->ChipType == XGI_40) {
@@ -3160,7 +3130,7 @@ SiS_StrangeStuff(struct SiS_Private *SiS_Pr)
3160static void 3130static void
3161SiS_Handle760(struct SiS_Private *SiS_Pr) 3131SiS_Handle760(struct SiS_Private *SiS_Pr)
3162{ 3132{
3163#ifdef SIS315H 3133#ifdef CONFIG_FB_SIS_315
3164 unsigned int somebase; 3134 unsigned int somebase;
3165 unsigned char temp1, temp2, temp3; 3135 unsigned char temp1, temp2, temp3;
3166 3136
@@ -3170,11 +3140,7 @@ SiS_Handle760(struct SiS_Private *SiS_Pr)
3170 (!(SiS_Pr->SiS_SysFlags & SF_760UMA)) ) 3140 (!(SiS_Pr->SiS_SysFlags & SF_760UMA)) )
3171 return; 3141 return;
3172 3142
3173#ifdef SIS_LINUX_KERNEL
3174 somebase = sisfb_read_mio_pci_word(SiS_Pr, 0x74); 3143 somebase = sisfb_read_mio_pci_word(SiS_Pr, 0x74);
3175#else
3176 somebase = pciReadWord(0x00001000, 0x74);
3177#endif
3178 somebase &= 0xffff; 3144 somebase &= 0xffff;
3179 3145
3180 if(somebase == 0) return; 3146 if(somebase == 0) return;
@@ -3190,105 +3156,34 @@ SiS_Handle760(struct SiS_Private *SiS_Pr)
3190 temp2 = 0x0b; 3156 temp2 = 0x0b;
3191 } 3157 }
3192 3158
3193#ifdef SIS_LINUX_KERNEL
3194 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x7e, temp1); 3159 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x7e, temp1);
3195 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x8d, temp2); 3160 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x8d, temp2);
3196#else
3197 pciWriteByte(0x00000000, 0x7e, temp1);
3198 pciWriteByte(0x00000000, 0x8d, temp2);
3199#endif
3200 3161
3201 SiS_SetRegByte((somebase + 0x85), temp3); 3162 SiS_SetRegByte((somebase + 0x85), temp3);
3202#endif 3163#endif
3203} 3164}
3204 3165
3205/*********************************************/ 3166/*********************************************/
3206/* X.org/XFree86: SET SCREEN PITCH */
3207/*********************************************/
3208
3209#ifdef SIS_XORG_XF86
3210static void
3211SiS_SetPitchCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3212{
3213 SISPtr pSiS = SISPTR(pScrn);
3214 unsigned short HDisplay = pSiS->scrnPitch >> 3;
3215
3216 SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,(HDisplay & 0xFF));
3217 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,(HDisplay >> 8));
3218}
3219
3220static void
3221SiS_SetPitchCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3222{
3223 SISPtr pSiS = SISPTR(pScrn);
3224 unsigned short HDisplay = pSiS->scrnPitch2 >> 3;
3225
3226 /* Unlock CRT2 */
3227 if(pSiS->VGAEngine == SIS_315_VGA)
3228 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2F, 0x01);
3229 else
3230 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24, 0x01);
3231
3232 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(HDisplay & 0xFF));
3233 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0xF0,(HDisplay >> 8));
3234}
3235
3236static void
3237SiS_SetPitch(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3238{
3239 SISPtr pSiS = SISPTR(pScrn);
3240 bool isslavemode = false;
3241
3242 if( (pSiS->VBFlags2 & VB2_VIDEOBRIDGE) &&
3243 ( ((pSiS->VGAEngine == SIS_300_VGA) &&
3244 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0xa0) == 0x20) ||
3245 ((pSiS->VGAEngine == SIS_315_VGA) &&
3246 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x50) == 0x10) ) ) {
3247 isslavemode = true;
3248 }
3249
3250 /* We need to set pitch for CRT1 if bridge is in slave mode, too */
3251 if((pSiS->VBFlags & DISPTYPE_DISP1) || (isslavemode)) {
3252 SiS_SetPitchCRT1(SiS_Pr, pScrn);
3253 }
3254 /* We must not set the pitch for CRT2 if bridge is in slave mode */
3255 if((pSiS->VBFlags & DISPTYPE_DISP2) && (!isslavemode)) {
3256 SiS_SetPitchCRT2(SiS_Pr, pScrn);
3257 }
3258}
3259#endif
3260
3261/*********************************************/
3262/* SiSSetMode() */ 3167/* SiSSetMode() */
3263/*********************************************/ 3168/*********************************************/
3264 3169
3265#ifdef SIS_XORG_XF86
3266/* We need pScrn for setting the pitch correctly */
3267bool
3268SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo, bool dosetpitch)
3269#else
3270bool 3170bool
3271SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo) 3171SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3272#endif
3273{ 3172{
3274 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress; 3173 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3275 unsigned short RealModeNo, ModeIdIndex; 3174 unsigned short RealModeNo, ModeIdIndex;
3276 unsigned char backupreg = 0; 3175 unsigned char backupreg = 0;
3277#ifdef SIS_LINUX_KERNEL
3278 unsigned short KeepLockReg; 3176 unsigned short KeepLockReg;
3279 3177
3280 SiS_Pr->UseCustomMode = false; 3178 SiS_Pr->UseCustomMode = false;
3281 SiS_Pr->CRT1UsesCustomMode = false; 3179 SiS_Pr->CRT1UsesCustomMode = false;
3282#endif
3283 3180
3284 SiS_Pr->SiS_flag_clearbuffer = 0; 3181 SiS_Pr->SiS_flag_clearbuffer = 0;
3285 3182
3286 if(SiS_Pr->UseCustomMode) { 3183 if(SiS_Pr->UseCustomMode) {
3287 ModeNo = 0xfe; 3184 ModeNo = 0xfe;
3288 } else { 3185 } else {
3289#ifdef SIS_LINUX_KERNEL
3290 if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1; 3186 if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1;
3291#endif
3292 ModeNo &= 0x7f; 3187 ModeNo &= 0x7f;
3293 } 3188 }
3294 3189
@@ -3301,13 +3196,8 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3301 SiS_GetSysFlags(SiS_Pr); 3196 SiS_GetSysFlags(SiS_Pr);
3302 3197
3303 SiS_Pr->SiS_VGAINFO = 0x11; 3198 SiS_Pr->SiS_VGAINFO = 0x11;
3304#if defined(SIS_XORG_XF86) && (defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__))
3305 if(pScrn) SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3306#endif
3307 3199
3308#ifdef SIS_LINUX_KERNEL
3309 KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05); 3200 KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
3310#endif
3311 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86); 3201 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3312 3202
3313 SiSInitPCIetc(SiS_Pr); 3203 SiSInitPCIetc(SiS_Pr);
@@ -3344,12 +3234,10 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3344 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex); 3234 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3345 SiS_SetLowModeTest(SiS_Pr, ModeNo); 3235 SiS_SetLowModeTest(SiS_Pr, ModeNo);
3346 3236
3347#ifdef SIS_LINUX_KERNEL
3348 /* Check memory size (kernel framebuffer driver only) */ 3237 /* Check memory size (kernel framebuffer driver only) */
3349 if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) { 3238 if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) {
3350 return false; 3239 return false;
3351 } 3240 }
3352#endif
3353 3241
3354 SiS_OpenCRTC(SiS_Pr); 3242 SiS_OpenCRTC(SiS_Pr);
3355 3243
@@ -3384,7 +3272,7 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3384 SiS_DisplayOn(SiS_Pr); 3272 SiS_DisplayOn(SiS_Pr);
3385 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF); 3273 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3386 3274
3387#ifdef SIS315H 3275#ifdef CONFIG_FB_SIS_315
3388 if(SiS_Pr->ChipType >= SIS_315H) { 3276 if(SiS_Pr->ChipType >= SIS_315H) {
3389 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 3277 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
3390 if(!(SiS_IsDualEdge(SiS_Pr))) { 3278 if(!(SiS_IsDualEdge(SiS_Pr))) {
@@ -3396,7 +3284,7 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3396 3284
3397 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { 3285 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3398 if(SiS_Pr->ChipType >= SIS_315H) { 3286 if(SiS_Pr->ChipType >= SIS_315H) {
3399#ifdef SIS315H 3287#ifdef CONFIG_FB_SIS_315
3400 if(!SiS_Pr->SiS_ROMNew) { 3288 if(!SiS_Pr->SiS_ROMNew) {
3401 if(SiS_IsVAMode(SiS_Pr)) { 3289 if(SiS_IsVAMode(SiS_Pr)) {
3402 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01); 3290 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
@@ -3424,424 +3312,16 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3424 } 3312 }
3425 } 3313 }
3426 3314
3427#ifdef SIS_XORG_XF86
3428 if(pScrn) {
3429 /* SetPitch: Adapt to virtual size & position */
3430 if((ModeNo > 0x13) && (dosetpitch)) {
3431 SiS_SetPitch(SiS_Pr, pScrn);
3432 }
3433
3434 /* Backup/Set ModeNo in BIOS scratch area */
3435 SiS_GetSetModeID(pScrn, ModeNo);
3436 }
3437#endif
3438
3439 SiS_CloseCRTC(SiS_Pr); 3315 SiS_CloseCRTC(SiS_Pr);
3440 3316
3441 SiS_Handle760(SiS_Pr); 3317 SiS_Handle760(SiS_Pr);
3442 3318
3443#ifdef SIS_LINUX_KERNEL
3444 /* We never lock registers in XF86 */ 3319 /* We never lock registers in XF86 */
3445 if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00); 3320 if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00);
3446#endif
3447 3321
3448 return true; 3322 return true;
3449} 3323}
3450 3324
3451/*********************************************/
3452/* X.org/XFree86: SiSBIOSSetMode() */
3453/* for non-Dual-Head mode */
3454/*********************************************/
3455
3456#ifdef SIS_XORG_XF86
3457bool
3458SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3459 DisplayModePtr mode, bool IsCustom)
3460{
3461 SISPtr pSiS = SISPTR(pScrn);
3462 unsigned short ModeNo = 0;
3463
3464 SiS_Pr->UseCustomMode = false;
3465
3466 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3467
3468 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting custom mode %dx%d\n",
3469 SiS_Pr->CHDisplay,
3470 (mode->Flags & V_INTERLACE ? SiS_Pr->CVDisplay * 2 :
3471 (mode->Flags & V_DBLSCAN ? SiS_Pr->CVDisplay / 2 :
3472 SiS_Pr->CVDisplay)));
3473
3474 } else {
3475
3476 /* Don't need vbflags here; checks done earlier */
3477 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags);
3478 if(!ModeNo) return false;
3479
3480 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting standard mode 0x%x\n", ModeNo);
3481
3482 }
3483
3484 return(SiSSetMode(SiS_Pr, pScrn, ModeNo, true));
3485}
3486
3487/*********************************************/
3488/* X.org/XFree86: SiSBIOSSetModeCRT2() */
3489/* for Dual-Head modes */
3490/*********************************************/
3491
3492bool
3493SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3494 DisplayModePtr mode, bool IsCustom)
3495{
3496 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3497 SISPtr pSiS = SISPTR(pScrn);
3498#ifdef SISDUALHEAD
3499 SISEntPtr pSiSEnt = pSiS->entityPrivate;
3500#endif
3501 unsigned short ModeIdIndex;
3502 unsigned short ModeNo = 0;
3503 unsigned char backupreg = 0;
3504
3505 SiS_Pr->UseCustomMode = false;
3506
3507 /* Remember: Custom modes for CRT2 are ONLY supported
3508 * -) on the 30x/B/C, and
3509 * -) if CRT2 is LCD or VGA, or CRT1 is LCDA
3510 */
3511
3512 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3513
3514 ModeNo = 0xfe;
3515
3516 } else {
3517
3518 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags);
3519 if(!ModeNo) return false;
3520
3521 }
3522
3523 SiSRegInit(SiS_Pr, BaseAddr);
3524 SiSInitPtr(SiS_Pr);
3525 SiS_GetSysFlags(SiS_Pr);
3526#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__)
3527 SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3528#else
3529 SiS_Pr->SiS_VGAINFO = 0x11;
3530#endif
3531
3532 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3533
3534 SiSInitPCIetc(SiS_Pr);
3535 SiSSetLVDSetc(SiS_Pr);
3536 SiSDetermineROMUsage(SiS_Pr);
3537
3538 /* Save mode info so we can set it from within SetMode for CRT1 */
3539#ifdef SISDUALHEAD
3540 if(pSiS->DualHeadMode) {
3541 pSiSEnt->CRT2ModeNo = ModeNo;
3542 pSiSEnt->CRT2DMode = mode;
3543 pSiSEnt->CRT2IsCustom = IsCustom;
3544 pSiSEnt->CRT2CR30 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
3545 pSiSEnt->CRT2CR31 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
3546 pSiSEnt->CRT2CR35 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3547 pSiSEnt->CRT2CR38 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3548#if 0
3549 /* We can't set CRT2 mode before CRT1 mode is set - says who...? */
3550 if(pSiSEnt->CRT1ModeNo == -1) {
3551 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3552 "Setting CRT2 mode delayed until after setting CRT1 mode\n");
3553 return true;
3554 }
3555#endif
3556 pSiSEnt->CRT2ModeSet = true;
3557 }
3558#endif
3559
3560 if(SiS_Pr->UseCustomMode) {
3561
3562 unsigned short temptemp = SiS_Pr->CVDisplay;
3563
3564 if(SiS_Pr->CModeFlag & DoubleScanMode) temptemp >>= 1;
3565 else if(SiS_Pr->CInfoFlag & InterlaceMode) temptemp <<= 1;
3566
3567 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3568 "Setting custom mode %dx%d on CRT2\n",
3569 SiS_Pr->CHDisplay, temptemp);
3570
3571 } else {
3572
3573 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3574 "Setting standard mode 0x%x on CRT2\n", ModeNo);
3575
3576 }
3577
3578 SiS_UnLockCRT2(SiS_Pr);
3579
3580 if(!SiS_Pr->UseCustomMode) {
3581 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
3582 } else {
3583 ModeIdIndex = 0;
3584 }
3585
3586 SiS_GetVBType(SiS_Pr);
3587
3588 SiS_InitVB(SiS_Pr);
3589 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3590 if(SiS_Pr->ChipType >= SIS_315H) {
3591 SiS_ResetVB(SiS_Pr);
3592 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
3593 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
3594 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3595 } else {
3596 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3597 }
3598 }
3599
3600 /* Get VB information (connectors, connected devices) */
3601 if(!SiS_Pr->UseCustomMode) {
3602 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 1);
3603 } else {
3604 /* If this is a custom mode, we don't check the modeflag for CRT2Mode */
3605 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 0);
3606 }
3607 SiS_SetYPbPr(SiS_Pr);
3608 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3609 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3610 SiS_SetLowModeTest(SiS_Pr, ModeNo);
3611
3612 SiS_ResetSegmentRegisters(SiS_Pr);
3613
3614 /* Set mode on CRT2 */
3615 if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
3616 (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
3617 (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
3618 (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
3619 SiS_SetCRT2Group(SiS_Pr, ModeNo);
3620 }
3621
3622 SiS_StrangeStuff(SiS_Pr);
3623
3624 SiS_DisplayOn(SiS_Pr);
3625 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3626
3627 if(SiS_Pr->ChipType >= SIS_315H) {
3628 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
3629 if(!(SiS_IsDualEdge(SiS_Pr))) {
3630 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
3631 }
3632 }
3633 }
3634
3635 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3636 if(SiS_Pr->ChipType >= SIS_315H) {
3637 if(!SiS_Pr->SiS_ROMNew) {
3638 if(SiS_IsVAMode(SiS_Pr)) {
3639 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
3640 } else {
3641 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
3642 }
3643 }
3644
3645 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
3646
3647 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
3648 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
3649 }
3650 } else if((SiS_Pr->ChipType == SIS_630) ||
3651 (SiS_Pr->ChipType == SIS_730)) {
3652 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
3653 }
3654 }
3655
3656 /* SetPitch: Adapt to virtual size & position */
3657 SiS_SetPitchCRT2(SiS_Pr, pScrn);
3658
3659 SiS_Handle760(SiS_Pr);
3660
3661 return true;
3662}
3663
3664/*********************************************/
3665/* X.org/XFree86: SiSBIOSSetModeCRT1() */
3666/* for Dual-Head modes */
3667/*********************************************/
3668
3669bool
3670SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3671 DisplayModePtr mode, bool IsCustom)
3672{
3673 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3674 SISPtr pSiS = SISPTR(pScrn);
3675 unsigned short ModeIdIndex, ModeNo = 0;
3676 unsigned char backupreg = 0;
3677#ifdef SISDUALHEAD
3678 SISEntPtr pSiSEnt = pSiS->entityPrivate;
3679 unsigned char backupcr30, backupcr31, backupcr38, backupcr35, backupp40d=0;
3680 bool backupcustom;
3681#endif
3682
3683 SiS_Pr->UseCustomMode = false;
3684
3685 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3686
3687 unsigned short temptemp = SiS_Pr->CVDisplay;
3688
3689 if(SiS_Pr->CModeFlag & DoubleScanMode) temptemp >>= 1;
3690 else if(SiS_Pr->CInfoFlag & InterlaceMode) temptemp <<= 1;
3691
3692 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3693 "Setting custom mode %dx%d on CRT1\n",
3694 SiS_Pr->CHDisplay, temptemp);
3695 ModeNo = 0xfe;
3696
3697 } else {
3698
3699 ModeNo = SiS_GetModeNumber(pScrn, mode, 0); /* don't give VBFlags */
3700 if(!ModeNo) return false;
3701
3702 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3703 "Setting standard mode 0x%x on CRT1\n", ModeNo);
3704 }
3705
3706 SiSInitPtr(SiS_Pr);
3707 SiSRegInit(SiS_Pr, BaseAddr);
3708 SiS_GetSysFlags(SiS_Pr);
3709#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__)
3710 SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3711#else
3712 SiS_Pr->SiS_VGAINFO = 0x11;
3713#endif
3714
3715 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3716
3717 SiSInitPCIetc(SiS_Pr);
3718 SiSSetLVDSetc(SiS_Pr);
3719 SiSDetermineROMUsage(SiS_Pr);
3720
3721 SiS_UnLockCRT2(SiS_Pr);
3722
3723 if(!SiS_Pr->UseCustomMode) {
3724 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
3725 } else {
3726 ModeIdIndex = 0;
3727 }
3728
3729 /* Determine VBType */
3730 SiS_GetVBType(SiS_Pr);
3731
3732 SiS_InitVB(SiS_Pr);
3733 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3734 if(SiS_Pr->ChipType >= SIS_315H) {
3735 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3736 } else {
3737 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3738 }
3739 }
3740
3741 /* Get VB information (connectors, connected devices) */
3742 /* (We don't care if the current mode is a CRT2 mode) */
3743 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 0);
3744 SiS_SetYPbPr(SiS_Pr);
3745 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3746 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3747 SiS_SetLowModeTest(SiS_Pr, ModeNo);
3748
3749 SiS_OpenCRTC(SiS_Pr);
3750
3751 /* Set mode on CRT1 */
3752 SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
3753 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
3754 SiS_SetCRT2Group(SiS_Pr, ModeNo);
3755 }
3756
3757 /* SetPitch: Adapt to virtual size & position */
3758 SiS_SetPitchCRT1(SiS_Pr, pScrn);
3759
3760 SiS_HandleCRT1(SiS_Pr);
3761
3762 SiS_StrangeStuff(SiS_Pr);
3763
3764 SiS_CloseCRTC(SiS_Pr);
3765
3766#ifdef SISDUALHEAD
3767 if(pSiS->DualHeadMode) {
3768 pSiSEnt->CRT1ModeNo = ModeNo;
3769 pSiSEnt->CRT1DMode = mode;
3770 }
3771#endif
3772
3773 if(SiS_Pr->UseCustomMode) {
3774 SiS_Pr->CRT1UsesCustomMode = true;
3775 SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
3776 SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
3777 } else {
3778 SiS_Pr->CRT1UsesCustomMode = false;
3779 }
3780
3781 /* Reset CRT2 if changing mode on CRT1 */
3782#ifdef SISDUALHEAD
3783 if(pSiS->DualHeadMode) {
3784 if(pSiSEnt->CRT2ModeNo != -1) {
3785 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3786 "(Re-)Setting mode for CRT2\n");
3787 backupcustom = SiS_Pr->UseCustomMode;
3788 backupcr30 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
3789 backupcr31 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
3790 backupcr35 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3791 backupcr38 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3792 if(SiS_Pr->SiS_VBType & VB_SISVB) {
3793 /* Backup LUT-enable */
3794 if(pSiSEnt->CRT2ModeSet) {
3795 backupp40d = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x0d) & 0x08;
3796 }
3797 }
3798 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
3799 SiS_SetReg(SiS_Pr->SiS_P3d4,0x30,pSiSEnt->CRT2CR30);
3800 SiS_SetReg(SiS_Pr->SiS_P3d4,0x31,pSiSEnt->CRT2CR31);
3801 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,pSiSEnt->CRT2CR35);
3802 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,pSiSEnt->CRT2CR38);
3803 }
3804
3805 SiSBIOSSetModeCRT2(SiS_Pr, pSiSEnt->pScrn_1,
3806 pSiSEnt->CRT2DMode, pSiSEnt->CRT2IsCustom);
3807
3808 SiS_SetReg(SiS_Pr->SiS_P3d4,0x30,backupcr30);
3809 SiS_SetReg(SiS_Pr->SiS_P3d4,0x31,backupcr31);
3810 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupcr35);
3811 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupcr38);
3812 if(SiS_Pr->SiS_VBType & VB_SISVB) {
3813 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d, ~0x08, backupp40d);
3814 }
3815 SiS_Pr->UseCustomMode = backupcustom;
3816 }
3817 }
3818#endif
3819
3820 /* Warning: From here, the custom mode entries in SiS_Pr are
3821 * possibly overwritten
3822 */
3823
3824 SiS_DisplayOn(SiS_Pr);
3825 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3826
3827 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3828 if(SiS_Pr->ChipType >= SIS_315H) {
3829 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
3830 } else if((SiS_Pr->ChipType == SIS_630) ||
3831 (SiS_Pr->ChipType == SIS_730)) {
3832 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
3833 }
3834 }
3835
3836 SiS_Handle760(SiS_Pr);
3837
3838 /* Backup/Set ModeNo in BIOS scratch area */
3839 SiS_GetSetModeID(pScrn,ModeNo);
3840
3841 return true;
3842}
3843#endif /* Linux_XF86 */
3844
3845#ifndef GETBITSTR 3325#ifndef GETBITSTR
3846#define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l)) 3326#define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
3847#define GENMASK(mask) BITMASK(1?mask,0?mask) 3327#define GENMASK(mask) BITMASK(1?mask,0?mask)
@@ -3927,7 +3407,7 @@ SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
3927 SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE; 3407 SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE;
3928 3408
3929 if(SiS_Pr->ChipType < SIS_315H) { 3409 if(SiS_Pr->ChipType < SIS_315H) {
3930#ifdef SIS300 3410#ifdef CONFIG_FB_SIS_300
3931 tempbx = SiS_Pr->SiS_VGAHT; 3411 tempbx = SiS_Pr->SiS_VGAHT;
3932 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3412 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3933 tempbx = SiS_Pr->PanelHT; 3413 tempbx = SiS_Pr->PanelHT;
@@ -3936,7 +3416,7 @@ SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
3936 remaining = tempbx % 8; 3416 remaining = tempbx % 8;
3937#endif 3417#endif
3938 } else { 3418 } else {
3939#ifdef SIS315H 3419#ifdef CONFIG_FB_SIS_315
3940 /* OK for LCDA, LVDS */ 3420 /* OK for LCDA, LVDS */
3941 tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes; 3421 tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes;
3942 tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */ 3422 tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */
@@ -3950,7 +3430,7 @@ SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
3950 SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx; 3430 SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx;
3951 3431
3952 if(SiS_Pr->ChipType < SIS_315H) { 3432 if(SiS_Pr->ChipType < SIS_315H) {
3953#ifdef SIS300 3433#ifdef CONFIG_FB_SIS_300
3954 if(SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) { 3434 if(SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) {
3955 SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE + ((SiS_Pr->PanelHRS + 1) & ~1); 3435 SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE + ((SiS_Pr->PanelHRS + 1) & ~1);
3956 SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + SiS_Pr->PanelHRE; 3436 SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + SiS_Pr->PanelHRE;
@@ -3982,7 +3462,7 @@ SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
3982 } 3462 }
3983#endif 3463#endif
3984 } else { 3464 } else {
3985#ifdef SIS315H 3465#ifdef CONFIG_FB_SIS_315
3986 tempax = VGAHDE; 3466 tempax = VGAHDE;
3987 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3467 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3988 tempbx = SiS_Pr->PanelXRes; 3468 tempbx = SiS_Pr->PanelXRes;
@@ -4001,7 +3481,7 @@ SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
4001 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3481 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
4002 tempax = SiS_Pr->PanelYRes; 3482 tempax = SiS_Pr->PanelYRes;
4003 } else if(SiS_Pr->ChipType < SIS_315H) { 3483 } else if(SiS_Pr->ChipType < SIS_315H) {
4004#ifdef SIS300 3484#ifdef CONFIG_FB_SIS_300
4005 /* Stupid hack for 640x400/320x200 */ 3485 /* Stupid hack for 640x400/320x200 */
4006 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 3486 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
4007 if((tempax + tempbx) == 438) tempbx += 16; 3487 if((tempax + tempbx) == 438) tempbx += 16;
@@ -4054,36 +3534,12 @@ SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
4054 if(modeflag & DoubleScanMode) tempax |= 0x80; 3534 if(modeflag & DoubleScanMode) tempax |= 0x80;
4055 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax); 3535 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax);
4056 3536
4057#ifdef SIS_XORG_XF86
4058#ifdef TWDEBUG
4059 xf86DrvMsg(0, X_INFO, "%d %d %d %d %d %d %d %d (%d %d %d %d)\n",
4060 SiS_Pr->CHDisplay, SiS_Pr->CHSyncStart, SiS_Pr->CHSyncEnd, SiS_Pr->CHTotal,
4061 SiS_Pr->CVDisplay, SiS_Pr->CVSyncStart, SiS_Pr->CVSyncEnd, SiS_Pr->CVTotal,
4062 SiS_Pr->CHBlankStart, SiS_Pr->CHBlankEnd, SiS_Pr->CVBlankStart, SiS_Pr->CVBlankEnd);
4063 xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
4064 SiS_Pr->CCRT1CRTC[0], SiS_Pr->CCRT1CRTC[1],
4065 SiS_Pr->CCRT1CRTC[2], SiS_Pr->CCRT1CRTC[3],
4066 SiS_Pr->CCRT1CRTC[4], SiS_Pr->CCRT1CRTC[5],
4067 SiS_Pr->CCRT1CRTC[6], SiS_Pr->CCRT1CRTC[7]);
4068 xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
4069 SiS_Pr->CCRT1CRTC[8], SiS_Pr->CCRT1CRTC[9],
4070 SiS_Pr->CCRT1CRTC[10], SiS_Pr->CCRT1CRTC[11],
4071 SiS_Pr->CCRT1CRTC[12], SiS_Pr->CCRT1CRTC[13],
4072 SiS_Pr->CCRT1CRTC[14], SiS_Pr->CCRT1CRTC[15]);
4073 xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", SiS_Pr->CCRT1CRTC[16]);
4074#endif
4075#endif
4076} 3537}
4077 3538
4078void 3539void
4079SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, 3540SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
4080 int xres, int yres, 3541 int xres, int yres,
4081#ifdef SIS_XORG_XF86
4082 DisplayModePtr current
4083#endif
4084#ifdef SIS_LINUX_KERNEL
4085 struct fb_var_screeninfo *var, bool writeres 3542 struct fb_var_screeninfo *var, bool writeres
4086#endif
4087) 3543)
4088{ 3544{
4089 unsigned short HRE, HBE, HRS, HBS, HDE, HT; 3545 unsigned short HRE, HBE, HRS, HBS, HDE, HT;
@@ -4127,25 +3583,10 @@ SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
4127 3583
4128 D = B - F - C; 3584 D = B - F - C;
4129 3585
4130#ifdef SIS_XORG_XF86
4131 current->HDisplay = (E * 8);
4132 current->HSyncStart = (E * 8) + (F * 8);
4133 current->HSyncEnd = (E * 8) + (F * 8) + (C * 8);
4134 current->HTotal = (E * 8) + (F * 8) + (C * 8) + (D * 8);
4135#ifdef TWDEBUG
4136 xf86DrvMsg(0, X_INFO,
4137 "H: A %d B %d C %d D %d E %d F %d HT %d HDE %d HRS %d HBS %d HBE %d HRE %d\n",
4138 A, B, C, D, E, F, HT, HDE, HRS, HBS, HBE, HRE);
4139#else
4140 (void)VBS; (void)HBS; (void)A;
4141#endif
4142#endif
4143#ifdef SIS_LINUX_KERNEL
4144 if(writeres) var->xres = xres = E * 8; 3586 if(writeres) var->xres = xres = E * 8;
4145 var->left_margin = D * 8; 3587 var->left_margin = D * 8;
4146 var->right_margin = F * 8; 3588 var->right_margin = F * 8;
4147 var->hsync_len = C * 8; 3589 var->hsync_len = C * 8;
4148#endif
4149 3590
4150 /* Vertical */ 3591 /* Vertical */
4151 sr_data = crdata[13]; 3592 sr_data = crdata[13];
@@ -4192,30 +3633,10 @@ SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
4192 3633
4193 D = B - F - C; 3634 D = B - F - C;
4194 3635
4195#ifdef SIS_XORG_XF86
4196 current->VDisplay = VDE + 1;
4197 current->VSyncStart = VRS + 1;
4198 current->VSyncEnd = ((VRS & ~0x1f) | VRE) + 1;
4199 if(VRE <= (VRS & 0x1f)) current->VSyncEnd += 32;
4200 current->VTotal = E + D + C + F;
4201#if 0
4202 current->VDisplay = E;
4203 current->VSyncStart = E + D;
4204 current->VSyncEnd = E + D + C;
4205 current->VTotal = E + D + C + F;
4206#endif
4207#ifdef TWDEBUG
4208 xf86DrvMsg(0, X_INFO,
4209 "V: A %d B %d C %d D %d E %d F %d VT %d VDE %d VRS %d VBS %d VBE %d VRE %d\n",
4210 A, B, C, D, E, F, VT, VDE, VRS, VBS, VBE, VRE);
4211#endif
4212#endif
4213#ifdef SIS_LINUX_KERNEL
4214 if(writeres) var->yres = yres = E; 3636 if(writeres) var->yres = yres = E;
4215 var->upper_margin = D; 3637 var->upper_margin = D;
4216 var->lower_margin = F; 3638 var->lower_margin = F;
4217 var->vsync_len = C; 3639 var->vsync_len = C;
4218#endif
4219 3640
4220 if((xres == 320) && ((yres == 200) || (yres == 240))) { 3641 if((xres == 320) && ((yres == 200) || (yres == 240))) {
4221 /* Terrible hack, but correct CRTC data for 3642 /* Terrible hack, but correct CRTC data for
@@ -4224,17 +3645,9 @@ SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
4224 * a negative D. The CRT controller does not 3645 * a negative D. The CRT controller does not
4225 * seem to like correcting HRE to 50) 3646 * seem to like correcting HRE to 50)
4226 */ 3647 */
4227#ifdef SIS_XORG_XF86
4228 current->HDisplay = 320;
4229 current->HSyncStart = 328;
4230 current->HSyncEnd = 376;
4231 current->HTotal = 400;
4232#endif
4233#ifdef SIS_LINUX_KERNEL
4234 var->left_margin = (400 - 376); 3648 var->left_margin = (400 - 376);
4235 var->right_margin = (328 - 320); 3649 var->right_margin = (328 - 320);
4236 var->hsync_len = (376 - 328); 3650 var->hsync_len = (376 - 328);
4237#endif
4238 3651
4239 } 3652 }
4240 3653
diff --git a/drivers/video/sis/init.h b/drivers/video/sis/init.h
index b96005c39c67..ee8ed3c203da 100644
--- a/drivers/video/sis/init.h
+++ b/drivers/video/sis/init.h
@@ -53,21 +53,8 @@
53#ifndef _INIT_H_ 53#ifndef _INIT_H_
54#define _INIT_H_ 54#define _INIT_H_
55 55
56#include "osdef.h"
57#include "initdef.h" 56#include "initdef.h"
58 57
59#ifdef SIS_XORG_XF86
60#include "sis.h"
61#define SIS_NEED_inSISREG
62#define SIS_NEED_inSISREGW
63#define SIS_NEED_inSISREGL
64#define SIS_NEED_outSISREG
65#define SIS_NEED_outSISREGW
66#define SIS_NEED_outSISREGL
67#include "sis_regs.h"
68#endif
69
70#ifdef SIS_LINUX_KERNEL
71#include "vgatypes.h" 58#include "vgatypes.h"
72#include "vstruct.h" 59#include "vstruct.h"
73#ifdef SIS_CP 60#ifdef SIS_CP
@@ -78,7 +65,6 @@
78#include <linux/fb.h> 65#include <linux/fb.h>
79#include "sis.h" 66#include "sis.h"
80#include <video/sisfb.h> 67#include <video/sisfb.h>
81#endif
82 68
83/* Mode numbers */ 69/* Mode numbers */
84static const unsigned short ModeIndex_320x200[] = {0x59, 0x41, 0x00, 0x4f}; 70static const unsigned short ModeIndex_320x200[] = {0x59, 0x41, 0x00, 0x4f};
@@ -286,7 +272,7 @@ static const struct SiS_ModeResInfo_S SiS_ModeResInfo[] =
286 { 1280, 854, 8,16} /* 0x22 */ 272 { 1280, 854, 8,16} /* 0x22 */
287}; 273};
288 274
289#if defined(SIS300) || defined(SIS315H) 275#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
290static const struct SiS_StandTable_S SiS_StandTable[]= 276static const struct SiS_StandTable_S SiS_StandTable[]=
291{ 277{
292/* 0x00: MD_0_200 */ 278/* 0x00: MD_0_200 */
@@ -1521,10 +1507,6 @@ static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1640x480_1_H[] =
1521}; 1507};
1522 1508
1523bool SiSInitPtr(struct SiS_Private *SiS_Pr); 1509bool SiSInitPtr(struct SiS_Private *SiS_Pr);
1524#ifdef SIS_XORG_XF86
1525unsigned short SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
1526 int Depth, bool FSTN, int LCDwith, int LCDheight);
1527#endif
1528unsigned short SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, 1510unsigned short SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay,
1529 int VDisplay, int Depth, bool FSTN, 1511 int VDisplay, int Depth, bool FSTN,
1530 unsigned short CustomT, int LCDwith, int LCDheight, 1512 unsigned short CustomT, int LCDwith, int LCDheight,
@@ -1550,17 +1532,11 @@ void SiS_SetRegOR(SISIOADDRESS Port,unsigned short Index, unsigned short DataOR
1550void SiS_DisplayOn(struct SiS_Private *SiS_Pr); 1532void SiS_DisplayOn(struct SiS_Private *SiS_Pr);
1551void SiS_DisplayOff(struct SiS_Private *SiS_Pr); 1533void SiS_DisplayOff(struct SiS_Private *SiS_Pr);
1552void SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr); 1534void SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr);
1553#ifndef SIS_LINUX_KERNEL
1554void SiSSetLVDSetc(struct SiS_Private *SiS_Pr);
1555#endif
1556void SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable); 1535void SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable);
1557void SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable); 1536void SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable);
1558unsigned short SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1537unsigned short SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1559 unsigned short ModeIdIndex); 1538 unsigned short ModeIdIndex);
1560bool SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr); 1539bool SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr);
1561#ifndef SIS_LINUX_KERNEL
1562void SiS_GetVBType(struct SiS_Private *SiS_Pr);
1563#endif
1564 1540
1565bool SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo, 1541bool SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
1566 unsigned short *ModeIdIndex); 1542 unsigned short *ModeIdIndex);
@@ -1572,37 +1548,19 @@ unsigned short SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short Mode
1572 unsigned short ModeIdIndex); 1548 unsigned short ModeIdIndex);
1573unsigned short SiS_GetOffset(struct SiS_Private *SiS_Pr,unsigned short ModeNo, 1549unsigned short SiS_GetOffset(struct SiS_Private *SiS_Pr,unsigned short ModeNo,
1574 unsigned short ModeIdIndex, unsigned short RRTI); 1550 unsigned short ModeIdIndex, unsigned short RRTI);
1575#ifdef SIS300 1551#ifdef CONFIG_FB_SIS_300
1576void SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1, 1552void SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
1577 unsigned short *idx2); 1553 unsigned short *idx2);
1578unsigned short SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2); 1554unsigned short SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2);
1579unsigned short SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index); 1555unsigned short SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index);
1580#endif 1556#endif
1581void SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex); 1557void SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
1582#ifdef SIS_XORG_XF86
1583bool SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo,
1584 bool dosetpitch);
1585bool SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
1586 DisplayModePtr mode, bool IsCustom);
1587bool SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
1588 DisplayModePtr mode, bool IsCustom);
1589bool SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
1590 DisplayModePtr mode, bool IsCustom);
1591#endif
1592#ifdef SIS_LINUX_KERNEL
1593bool SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo); 1558bool SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
1594#endif
1595void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth); 1559void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth);
1596void SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1560void SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1597 unsigned short ModeIdIndex); 1561 unsigned short ModeIdIndex);
1598#ifdef SIS_XORG_XF86
1599void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres,
1600 int yres, DisplayModePtr current);
1601#endif
1602#ifdef SIS_LINUX_KERNEL
1603void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres, 1562void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres,
1604 int yres, struct fb_var_screeninfo *var, bool writeres); 1563 int yres, struct fb_var_screeninfo *var, bool writeres);
1605#endif
1606 1564
1607/* From init301.c: */ 1565/* From init301.c: */
1608extern void SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1566extern void SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
@@ -1626,29 +1584,16 @@ extern unsigned short SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short
1626extern bool SiS_IsVAMode(struct SiS_Private *); 1584extern bool SiS_IsVAMode(struct SiS_Private *);
1627extern bool SiS_IsDualEdge(struct SiS_Private *); 1585extern bool SiS_IsDualEdge(struct SiS_Private *);
1628 1586
1629#ifdef SIS_XORG_XF86 1587#ifdef CONFIG_FB_SIS_300
1630/* From other modules: */
1631extern unsigned short SiS_CheckBuildCustomMode(ScrnInfoPtr pScrn, DisplayModePtr mode,
1632 unsigned int VBFlags);
1633extern unsigned char SiS_GetSetBIOSScratch(ScrnInfoPtr pScrn, unsigned short offset,
1634 unsigned char value);
1635extern unsigned char SiS_GetSetModeID(ScrnInfoPtr pScrn, unsigned char id);
1636extern unsigned short SiS_GetModeNumber(ScrnInfoPtr pScrn, DisplayModePtr mode,
1637 unsigned int VBFlags);
1638#endif
1639
1640#ifdef SIS_LINUX_KERNEL
1641#ifdef SIS300
1642extern unsigned int sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg); 1588extern unsigned int sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg);
1643extern void sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg, 1589extern void sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg,
1644 unsigned int val); 1590 unsigned int val);
1645#endif 1591#endif
1646#ifdef SIS315H 1592#ifdef CONFIG_FB_SIS_315
1647extern void sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg, 1593extern void sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg,
1648 unsigned char val); 1594 unsigned char val);
1649extern unsigned int sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg); 1595extern unsigned int sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg);
1650#endif 1596#endif
1651#endif
1652 1597
1653#endif 1598#endif
1654 1599
diff --git a/drivers/video/sis/init301.c b/drivers/video/sis/init301.c
index da33d801c22e..9fa66fd4052a 100644
--- a/drivers/video/sis/init301.c
+++ b/drivers/video/sis/init301.c
@@ -75,11 +75,11 @@
75 75
76#include "init301.h" 76#include "init301.h"
77 77
78#ifdef SIS300 78#ifdef CONFIG_FB_SIS_300
79#include "oem300.h" 79#include "oem300.h"
80#endif 80#endif
81 81
82#ifdef SIS315H 82#ifdef CONFIG_FB_SIS_315
83#include "oem310.h" 83#include "oem310.h"
84#endif 84#endif
85 85
@@ -87,9 +87,7 @@
87#define SiS_I2CDELAYSHORT 150 87#define SiS_I2CDELAYSHORT 150
88 88
89static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr); 89static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr);
90#ifdef SIS_LINUX_KERNEL
91static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val); 90static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
92#endif
93 91
94/*********************************************/ 92/*********************************************/
95/* HELPER: Lock/Unlock CRT2 */ 93/* HELPER: Lock/Unlock CRT2 */
@@ -106,9 +104,7 @@ SiS_UnLockCRT2(struct SiS_Private *SiS_Pr)
106 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01); 104 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
107} 105}
108 106
109#ifdef SIS_LINUX_KERNEL
110static 107static
111#endif
112void 108void
113SiS_LockCRT2(struct SiS_Private *SiS_Pr) 109SiS_LockCRT2(struct SiS_Private *SiS_Pr)
114{ 110{
@@ -138,7 +134,7 @@ SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned
138/* HELPER: Get Pointer to LCD structure */ 134/* HELPER: Get Pointer to LCD structure */
139/*********************************************/ 135/*********************************************/
140 136
141#ifdef SIS315H 137#ifdef CONFIG_FB_SIS_315
142static unsigned char * 138static unsigned char *
143GetLCDStructPtr661(struct SiS_Private *SiS_Pr) 139GetLCDStructPtr661(struct SiS_Private *SiS_Pr)
144{ 140{
@@ -404,7 +400,7 @@ SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
404/* HELPER: GET SOME DATA FROM BIOS ROM */ 400/* HELPER: GET SOME DATA FROM BIOS ROM */
405/*********************************************/ 401/*********************************************/
406 402
407#ifdef SIS300 403#ifdef CONFIG_FB_SIS_300
408static bool 404static bool
409SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr) 405SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
410{ 406{
@@ -449,7 +445,7 @@ SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
449 SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05); 445 SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05);
450} 446}
451 447
452#if defined(SIS300) || defined(SIS315H) 448#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
453static void 449static void
454SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay) 450SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
455{ 451{
@@ -457,7 +453,7 @@ SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
457} 453}
458#endif 454#endif
459 455
460#ifdef SIS315H 456#ifdef CONFIG_FB_SIS_315
461static void 457static void
462SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay) 458SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
463{ 459{
@@ -467,7 +463,7 @@ SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
467} 463}
468#endif 464#endif
469 465
470#if defined(SIS300) || defined(SIS315H) 466#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
471static void 467static void
472SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay) 468SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
473{ 469{
@@ -480,14 +476,14 @@ SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
480static void 476static void
481SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime) 477SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
482{ 478{
483#if defined(SIS300) || defined(SIS315H) 479#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
484 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 480 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
485 unsigned short PanelID, DelayIndex, Delay=0; 481 unsigned short PanelID, DelayIndex, Delay=0;
486#endif 482#endif
487 483
488 if(SiS_Pr->ChipType < SIS_315H) { 484 if(SiS_Pr->ChipType < SIS_315H) {
489 485
490#ifdef SIS300 486#ifdef CONFIG_FB_SIS_300
491 487
492 PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36); 488 PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
493 if(SiS_Pr->SiS_VBType & VB_SISVB) { 489 if(SiS_Pr->SiS_VBType & VB_SISVB) {
@@ -513,11 +509,11 @@ SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
513 } 509 }
514 SiS_ShortDelay(SiS_Pr, Delay); 510 SiS_ShortDelay(SiS_Pr, Delay);
515 511
516#endif /* SIS300 */ 512#endif /* CONFIG_FB_SIS_300 */
517 513
518 } else { 514 } else {
519 515
520#ifdef SIS315H 516#ifdef CONFIG_FB_SIS_315
521 517
522 if((SiS_Pr->ChipType >= SIS_661) || 518 if((SiS_Pr->ChipType >= SIS_661) ||
523 (SiS_Pr->ChipType <= SIS_315PRO) || 519 (SiS_Pr->ChipType <= SIS_315PRO) ||
@@ -579,12 +575,12 @@ SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
579 575
580 } 576 }
581 577
582#endif /* SIS315H */ 578#endif /* CONFIG_FB_SIS_315 */
583 579
584 } 580 }
585} 581}
586 582
587#ifdef SIS315H 583#ifdef CONFIG_FB_SIS_315
588static void 584static void
589SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop) 585SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop)
590{ 586{
@@ -613,7 +609,7 @@ SiS_WaitRetrace1(struct SiS_Private *SiS_Pr)
613 while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog); 609 while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
614} 610}
615 611
616#if defined(SIS300) || defined(SIS315H) 612#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
617static void 613static void
618SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg) 614SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg)
619{ 615{
@@ -630,7 +626,7 @@ static void
630SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr) 626SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
631{ 627{
632 if(SiS_Pr->ChipType < SIS_315H) { 628 if(SiS_Pr->ChipType < SIS_315H) {
633#ifdef SIS300 629#ifdef CONFIG_FB_SIS_300
634 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { 630 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
635 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return; 631 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
636 } 632 }
@@ -641,7 +637,7 @@ SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
641 } 637 }
642#endif 638#endif
643 } else { 639 } else {
644#ifdef SIS315H 640#ifdef CONFIG_FB_SIS_315
645 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) { 641 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
646 SiS_WaitRetrace1(SiS_Pr); 642 SiS_WaitRetrace1(SiS_Pr);
647 } else { 643 } else {
@@ -686,7 +682,7 @@ SiS_VBLongWait(struct SiS_Private *SiS_Pr)
686/* HELPER: MISC */ 682/* HELPER: MISC */
687/*********************************************/ 683/*********************************************/
688 684
689#ifdef SIS300 685#ifdef CONFIG_FB_SIS_300
690static bool 686static bool
691SiS_Is301B(struct SiS_Private *SiS_Pr) 687SiS_Is301B(struct SiS_Private *SiS_Pr)
692{ 688{
@@ -708,7 +704,7 @@ SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
708bool 704bool
709SiS_IsDualEdge(struct SiS_Private *SiS_Pr) 705SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
710{ 706{
711#ifdef SIS315H 707#ifdef CONFIG_FB_SIS_315
712 if(SiS_Pr->ChipType >= SIS_315H) { 708 if(SiS_Pr->ChipType >= SIS_315H) {
713 if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) { 709 if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
714 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true; 710 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true;
@@ -721,7 +717,7 @@ SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
721bool 717bool
722SiS_IsVAMode(struct SiS_Private *SiS_Pr) 718SiS_IsVAMode(struct SiS_Private *SiS_Pr)
723{ 719{
724#ifdef SIS315H 720#ifdef CONFIG_FB_SIS_315
725 unsigned short flag; 721 unsigned short flag;
726 722
727 if(SiS_Pr->ChipType >= SIS_315H) { 723 if(SiS_Pr->ChipType >= SIS_315H) {
@@ -732,7 +728,7 @@ SiS_IsVAMode(struct SiS_Private *SiS_Pr)
732 return false; 728 return false;
733} 729}
734 730
735#ifdef SIS315H 731#ifdef CONFIG_FB_SIS_315
736static bool 732static bool
737SiS_IsVAorLCD(struct SiS_Private *SiS_Pr) 733SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
738{ 734{
@@ -745,7 +741,7 @@ SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
745static bool 741static bool
746SiS_IsDualLink(struct SiS_Private *SiS_Pr) 742SiS_IsDualLink(struct SiS_Private *SiS_Pr)
747{ 743{
748#ifdef SIS315H 744#ifdef CONFIG_FB_SIS_315
749 if(SiS_Pr->ChipType >= SIS_315H) { 745 if(SiS_Pr->ChipType >= SIS_315H) {
750 if((SiS_CRT2IsLCD(SiS_Pr)) || 746 if((SiS_CRT2IsLCD(SiS_Pr)) ||
751 (SiS_IsVAMode(SiS_Pr))) { 747 (SiS_IsVAMode(SiS_Pr))) {
@@ -756,7 +752,7 @@ SiS_IsDualLink(struct SiS_Private *SiS_Pr)
756 return false; 752 return false;
757} 753}
758 754
759#ifdef SIS315H 755#ifdef CONFIG_FB_SIS_315
760static bool 756static bool
761SiS_TVEnabled(struct SiS_Private *SiS_Pr) 757SiS_TVEnabled(struct SiS_Private *SiS_Pr)
762{ 758{
@@ -768,7 +764,7 @@ SiS_TVEnabled(struct SiS_Private *SiS_Pr)
768} 764}
769#endif 765#endif
770 766
771#ifdef SIS315H 767#ifdef CONFIG_FB_SIS_315
772static bool 768static bool
773SiS_LCDAEnabled(struct SiS_Private *SiS_Pr) 769SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
774{ 770{
@@ -777,7 +773,7 @@ SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
777} 773}
778#endif 774#endif
779 775
780#ifdef SIS315H 776#ifdef CONFIG_FB_SIS_315
781static bool 777static bool
782SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr) 778SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
783{ 779{
@@ -788,7 +784,7 @@ SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
788} 784}
789#endif 785#endif
790 786
791#ifdef SIS315H 787#ifdef CONFIG_FB_SIS_315
792static bool 788static bool
793SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr) 789SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
794{ 790{
@@ -804,7 +800,7 @@ SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
804} 800}
805#endif 801#endif
806 802
807#ifdef SIS315H 803#ifdef CONFIG_FB_SIS_315
808static bool 804static bool
809SiS_IsYPbPr(struct SiS_Private *SiS_Pr) 805SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
810{ 806{
@@ -816,7 +812,7 @@ SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
816} 812}
817#endif 813#endif
818 814
819#ifdef SIS315H 815#ifdef CONFIG_FB_SIS_315
820static bool 816static bool
821SiS_IsChScart(struct SiS_Private *SiS_Pr) 817SiS_IsChScart(struct SiS_Private *SiS_Pr)
822{ 818{
@@ -828,7 +824,7 @@ SiS_IsChScart(struct SiS_Private *SiS_Pr)
828} 824}
829#endif 825#endif
830 826
831#ifdef SIS315H 827#ifdef CONFIG_FB_SIS_315
832static bool 828static bool
833SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr) 829SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
834{ 830{
@@ -848,7 +844,7 @@ SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
848} 844}
849#endif 845#endif
850 846
851#ifdef SIS315H 847#ifdef CONFIG_FB_SIS_315
852static bool 848static bool
853SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr) 849SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
854{ 850{
@@ -914,7 +910,7 @@ SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
914/*********************************************/ 910/*********************************************/
915 911
916/* Setup general purpose IO for Chrontel communication */ 912/* Setup general purpose IO for Chrontel communication */
917#ifdef SIS300 913#ifdef CONFIG_FB_SIS_300
918void 914void
919SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo) 915SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
920{ 916{
@@ -923,11 +919,7 @@ SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
923 919
924 if(!(SiS_Pr->SiS_ChSW)) return; 920 if(!(SiS_Pr->SiS_ChSW)) return;
925 921
926#ifdef SIS_LINUX_KERNEL
927 acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74); 922 acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74);
928#else
929 acpibase = pciReadLong(0x00000800, 0x74);
930#endif
931 acpibase &= 0xFFFF; 923 acpibase &= 0xFFFF;
932 if(!acpibase) return; 924 if(!acpibase) return;
933 temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */ 925 temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
@@ -969,7 +961,7 @@ SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
969 tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV); 961 tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
970 tempbx |= tempax; 962 tempbx |= tempax;
971 963
972#ifdef SIS315H 964#ifdef CONFIG_FB_SIS_315
973 if(SiS_Pr->ChipType >= SIS_315H) { 965 if(SiS_Pr->ChipType >= SIS_315H) {
974 if(SiS_Pr->SiS_VBType & VB_SISLCDA) { 966 if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
975 if(ModeNo == 0x03) { 967 if(ModeNo == 0x03) {
@@ -1019,7 +1011,7 @@ SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1019 } 1011 }
1020 } 1012 }
1021 1013
1022#endif /* SIS315H */ 1014#endif /* CONFIG_FB_SIS_315 */
1023 1015
1024 if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) { 1016 if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) {
1025 tempbx &= ~(SetCRT2ToRAMDAC); 1017 tempbx &= ~(SetCRT2ToRAMDAC);
@@ -1154,24 +1146,16 @@ SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1154 1146
1155 SiS_Pr->SiS_VBInfo = tempbx; 1147 SiS_Pr->SiS_VBInfo = tempbx;
1156 1148
1157#ifdef SIS300 1149#ifdef CONFIG_FB_SIS_300
1158 if(SiS_Pr->ChipType == SIS_630) { 1150 if(SiS_Pr->ChipType == SIS_630) {
1159 SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo); 1151 SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
1160 } 1152 }
1161#endif 1153#endif
1162 1154
1163#ifdef SIS_LINUX_KERNEL
1164#if 0 1155#if 0
1165 printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n", 1156 printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n",
1166 SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag); 1157 SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
1167#endif 1158#endif
1168#endif
1169#ifdef SIS_XORG_XF86
1170#ifdef TWDEBUG
1171 xf86DrvMsg(0, X_PROBED, "(init301: VBInfo=0x%04x, SetFlag=0x%04x)\n",
1172 SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
1173#endif
1174#endif
1175} 1159}
1176 1160
1177/*********************************************/ 1161/*********************************************/
@@ -1415,12 +1399,6 @@ SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
1415 } 1399 }
1416 1400
1417 SiS_Pr->SiS_VBInfo &= ~SetPALTV; 1401 SiS_Pr->SiS_VBInfo &= ~SetPALTV;
1418
1419#ifdef SIS_XORG_XF86
1420#ifdef TWDEBUG
1421 xf86DrvMsg(0, X_INFO, "(init301: TVMode %x, VBInfo %x)\n", SiS_Pr->SiS_TVMode, SiS_Pr->SiS_VBInfo);
1422#endif
1423#endif
1424} 1402}
1425 1403
1426/*********************************************/ 1404/*********************************************/
@@ -1443,22 +1421,10 @@ SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr)
1443static void 1421static void
1444SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr) 1422SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
1445{ 1423{
1446#ifdef SIS315H 1424#ifdef CONFIG_FB_SIS_315
1447 unsigned char *ROMAddr; 1425 unsigned char *ROMAddr;
1448 unsigned short temp; 1426 unsigned short temp;
1449 1427
1450#ifdef SIS_XORG_XF86
1451#ifdef TWDEBUG
1452 xf86DrvMsg(0, X_INFO, "Paneldata driver: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
1453 SiS_Pr->PanelHT, SiS_Pr->PanelVT,
1454 SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
1455 SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
1456 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
1457 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
1458 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
1459#endif
1460#endif
1461
1462 if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) { 1428 if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
1463 if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) { 1429 if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
1464 SiS_Pr->SiS_NeedRomModeData = true; 1430 SiS_Pr->SiS_NeedRomModeData = true;
@@ -1480,18 +1446,6 @@ SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
1480 SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C = 1446 SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
1481 SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20]; 1447 SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
1482 1448
1483#ifdef SIS_XORG_XF86
1484#ifdef TWDEBUG
1485 xf86DrvMsg(0, X_INFO, "Paneldata BIOS: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
1486 SiS_Pr->PanelHT, SiS_Pr->PanelVT,
1487 SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
1488 SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
1489 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
1490 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
1491 SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
1492#endif
1493#endif
1494
1495 } 1449 }
1496#endif 1450#endif
1497} 1451}
@@ -1517,13 +1471,13 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
1517{ 1471{
1518 unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0; 1472 unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
1519 bool panelcanscale = false; 1473 bool panelcanscale = false;
1520#ifdef SIS300 1474#ifdef CONFIG_FB_SIS_300
1521 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 1475 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1522 static const unsigned char SiS300SeriesLCDRes[] = 1476 static const unsigned char SiS300SeriesLCDRes[] =
1523 { 0, 1, 2, 3, 7, 4, 5, 8, 1477 { 0, 1, 2, 3, 7, 4, 5, 8,
1524 0, 0, 10, 0, 0, 0, 0, 15 }; 1478 0, 0, 10, 0, 0, 0, 0, 15 };
1525#endif 1479#endif
1526#ifdef SIS315H 1480#ifdef CONFIG_FB_SIS_315
1527 unsigned char *myptr = NULL; 1481 unsigned char *myptr = NULL;
1528#endif 1482#endif
1529 1483
@@ -1562,7 +1516,7 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
1562 SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1; 1516 SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
1563 } 1517 }
1564 temp &= 0x0f; 1518 temp &= 0x0f;
1565#ifdef SIS300 1519#ifdef CONFIG_FB_SIS_300
1566 if(SiS_Pr->ChipType < SIS_315H) { 1520 if(SiS_Pr->ChipType < SIS_315H) {
1567 /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */ 1521 /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
1568 if(SiS_Pr->SiS_VBType & VB_SIS301) { 1522 if(SiS_Pr->SiS_VBType & VB_SIS301) {
@@ -1574,7 +1528,7 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
1574#endif 1528#endif
1575 1529
1576 /* Translate to our internal types */ 1530 /* Translate to our internal types */
1577#ifdef SIS315H 1531#ifdef CONFIG_FB_SIS_315
1578 if(SiS_Pr->ChipType == SIS_550) { 1532 if(SiS_Pr->ChipType == SIS_550) {
1579 if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */ 1533 if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */
1580 else if(temp == Panel310_320x240_2) temp = Panel_320x240_2; 1534 else if(temp == Panel310_320x240_2) temp = Panel_320x240_2;
@@ -1597,7 +1551,7 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
1597 1551
1598 SiS_Pr->SiS_LCDResInfo = temp; 1552 SiS_Pr->SiS_LCDResInfo = temp;
1599 1553
1600#ifdef SIS300 1554#ifdef CONFIG_FB_SIS_300
1601 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 1555 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
1602 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) { 1556 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
1603 SiS_Pr->SiS_LCDResInfo = Panel_Barco1366; 1557 SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
@@ -1639,7 +1593,7 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
1639 else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 1593 else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
1640 1594
1641 /* Dual link, Pass 1:1 BIOS default, etc. */ 1595 /* Dual link, Pass 1:1 BIOS default, etc. */
1642#ifdef SIS315H 1596#ifdef CONFIG_FB_SIS_315
1643 if(SiS_Pr->ChipType >= SIS_661) { 1597 if(SiS_Pr->ChipType >= SIS_661) {
1644 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 1598 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
1645 if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11; 1599 if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
@@ -2076,7 +2030,7 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
2076 } 2030 }
2077 } 2031 }
2078 2032
2079#ifdef SIS300 2033#ifdef CONFIG_FB_SIS_300
2080 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 2034 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
2081 if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) { 2035 if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
2082 SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */ 2036 SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
@@ -2186,17 +2140,10 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
2186 SiS_Pr->SiS_SetFlag |= LCDVESATiming; 2140 SiS_Pr->SiS_SetFlag |= LCDVESATiming;
2187 } 2141 }
2188 2142
2189#ifdef SIS_LINUX_KERNEL
2190#if 0 2143#if 0
2191 printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n", 2144 printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
2192 SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo); 2145 SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
2193#endif 2146#endif
2194#endif
2195#ifdef SIS_XORG_XF86
2196 xf86DrvMsgVerb(0, X_PROBED, 4,
2197 "(init301: LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x SetFlag=0x%04x)\n",
2198 SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo, SiS_Pr->SiS_SetFlag);
2199#endif
2200} 2147}
2201 2148
2202/*********************************************/ 2149/*********************************************/
@@ -2359,7 +2306,7 @@ SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned shor
2359 VCLKIndex = SiS_Pr->PanelVCLKIdx315; 2306 VCLKIndex = SiS_Pr->PanelVCLKIdx315;
2360 } 2307 }
2361 2308
2362#ifdef SIS300 2309#ifdef CONFIG_FB_SIS_300
2363 /* Special Timing: Barco iQ Pro R series */ 2310 /* Special Timing: Barco iQ Pro R series */
2364 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44; 2311 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
2365 2312
@@ -2410,12 +2357,6 @@ SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned shor
2410 2357
2411 } 2358 }
2412 2359
2413#ifdef SIS_XORG_XF86
2414#ifdef TWDEBUG
2415 xf86DrvMsg(0, X_INFO, "VCLKIndex %d (0x%x)\n", VCLKIndex, VCLKIndex);
2416#endif
2417#endif
2418
2419 return VCLKIndex; 2360 return VCLKIndex;
2420} 2361}
2421 2362
@@ -2428,10 +2369,10 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2428{ 2369{
2429 unsigned short i, j, modeflag, tempah=0; 2370 unsigned short i, j, modeflag, tempah=0;
2430 short tempcl; 2371 short tempcl;
2431#if defined(SIS300) || defined(SIS315H) 2372#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
2432 unsigned short tempbl; 2373 unsigned short tempbl;
2433#endif 2374#endif
2434#ifdef SIS315H 2375#ifdef CONFIG_FB_SIS_315
2435 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 2376 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
2436 unsigned short tempah2, tempbl2; 2377 unsigned short tempah2, tempbl2;
2437#endif 2378#endif
@@ -2454,7 +2395,7 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2454 2395
2455 if(SiS_Pr->ChipType < SIS_315H) { 2396 if(SiS_Pr->ChipType < SIS_315H) {
2456 2397
2457#ifdef SIS300 /* ---- 300 series ---- */ 2398#ifdef CONFIG_FB_SIS_300 /* ---- 300 series ---- */
2458 2399
2459 /* For 301BDH: (with LCD via LVDS) */ 2400 /* For 301BDH: (with LCD via LVDS) */
2460 if(SiS_Pr->SiS_VBType & VB_NoLCD) { 2401 if(SiS_Pr->SiS_VBType & VB_NoLCD) {
@@ -2477,11 +2418,11 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2477 2418
2478 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0; 2419 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
2479 2420
2480#endif /* SIS300 */ 2421#endif /* CONFIG_FB_SIS_300 */
2481 2422
2482 } else { 2423 } else {
2483 2424
2484#ifdef SIS315H /* ------- 315/330 series ------ */ 2425#ifdef CONFIG_FB_SIS_315 /* ------- 315/330 series ------ */
2485 2426
2486 if(ModeNo > 0x13) { 2427 if(ModeNo > 0x13) {
2487 tempcl -= ModeVGA; 2428 tempcl -= ModeVGA;
@@ -2494,7 +2435,7 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2494 2435
2495 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50; 2436 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
2496 2437
2497#endif /* SIS315H */ 2438#endif /* CONFIG_FB_SIS_315 */
2498 2439
2499 } 2440 }
2500 2441
@@ -2503,7 +2444,7 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2503 if(SiS_Pr->ChipType < SIS_315H) { 2444 if(SiS_Pr->ChipType < SIS_315H) {
2504 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah); 2445 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
2505 } else { 2446 } else {
2506#ifdef SIS315H 2447#ifdef CONFIG_FB_SIS_315
2507 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 2448 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
2508 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah); 2449 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
2509 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { 2450 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
@@ -2584,7 +2525,7 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2584 2525
2585 if(SiS_Pr->ChipType >= SIS_315H) { 2526 if(SiS_Pr->ChipType >= SIS_315H) {
2586 2527
2587#ifdef SIS315H 2528#ifdef CONFIG_FB_SIS_315
2588 /* LVDS can only be slave in 8bpp modes */ 2529 /* LVDS can only be slave in 8bpp modes */
2589 tempah = 0x80; 2530 tempah = 0x80;
2590 if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) { 2531 if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
@@ -2604,7 +2545,7 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2604 2545
2605 } else { 2546 } else {
2606 2547
2607#ifdef SIS300 2548#ifdef CONFIG_FB_SIS_300
2608 tempah = 0; 2549 tempah = 0;
2609 if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) { 2550 if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
2610 tempah |= 0x02; 2551 tempah |= 0x02;
@@ -2626,7 +2567,7 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2626 2567
2627 if(SiS_Pr->ChipType >= SIS_315H) { 2568 if(SiS_Pr->ChipType >= SIS_315H) {
2628 2569
2629#ifdef SIS315H 2570#ifdef CONFIG_FB_SIS_315
2630 /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */ 2571 /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */
2631 2572
2632 /* The following is nearly unpreditable and varies from machine 2573 /* The following is nearly unpreditable and varies from machine
@@ -2718,11 +2659,11 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2718 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah); 2659 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
2719 } 2660 }
2720 2661
2721#endif /* SIS315H */ 2662#endif /* CONFIG_FB_SIS_315 */
2722 2663
2723 } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { 2664 } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
2724 2665
2725#ifdef SIS300 2666#ifdef CONFIG_FB_SIS_300
2726 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f); 2667 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
2727 2668
2728 if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) || 2669 if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
@@ -2745,7 +2686,7 @@ SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
2745 2686
2746 } else { /* LVDS */ 2687 } else { /* LVDS */
2747 2688
2748#ifdef SIS315H 2689#ifdef CONFIG_FB_SIS_315
2749 if(SiS_Pr->ChipType >= SIS_315H) { 2690 if(SiS_Pr->ChipType >= SIS_315H) {
2750 2691
2751 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 2692 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
@@ -2931,7 +2872,7 @@ SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
2931 } 2872 }
2932 } 2873 }
2933 2874
2934#ifdef SIS315H 2875#ifdef CONFIG_FB_SIS_315
2935 if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) { 2876 if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
2936 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { 2877 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
2937 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { 2878 if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
@@ -3036,7 +2977,7 @@ SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
3036 case Panel_1280x1024: tempbx = 24; break; 2977 case Panel_1280x1024: tempbx = 24; break;
3037 case Panel_1400x1050: tempbx = 26; break; 2978 case Panel_1400x1050: tempbx = 26; break;
3038 case Panel_1600x1200: tempbx = 28; break; 2979 case Panel_1600x1200: tempbx = 28; break;
3039#ifdef SIS300 2980#ifdef CONFIG_FB_SIS_300
3040 case Panel_Barco1366: tempbx = 80; break; 2981 case Panel_Barco1366: tempbx = 80; break;
3041#endif 2982#endif
3042 } 2983 }
@@ -3053,7 +2994,7 @@ SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
3053 2994
3054 if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30; 2995 if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30;
3055 2996
3056#ifdef SIS300 2997#ifdef CONFIG_FB_SIS_300
3057 if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) { 2998 if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
3058 tempbx = 82; 2999 tempbx = 82;
3059 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; 3000 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
@@ -3189,7 +3130,7 @@ SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
3189 3130
3190 if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 3131 if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
3191 3132
3192#ifdef SIS315H 3133#ifdef CONFIG_FB_SIS_315
3193 SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); 3134 SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3194 SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex); 3135 SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
3195#endif 3136#endif
@@ -3214,7 +3155,7 @@ SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
3214 case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break; 3155 case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
3215 case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break; 3156 case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
3216 case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break; 3157 case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
3217#ifdef SIS300 3158#ifdef CONFIG_FB_SIS_300
3218 case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break; 3159 case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
3219 case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break; 3160 case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
3220 case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break; 3161 case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
@@ -3248,7 +3189,7 @@ SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
3248 (SiS_Pr->SiS_SetFlag & SetDOSMode) ) { 3189 (SiS_Pr->SiS_SetFlag & SetDOSMode) ) {
3249 SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes; 3190 SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
3250 SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes; 3191 SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
3251#ifdef SIS300 3192#ifdef CONFIG_FB_SIS_300
3252 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) { 3193 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
3253 if(ResIndex < 0x08) { 3194 if(ResIndex < 0x08) {
3254 SiS_Pr->SiS_HDE = 1280; 3195 SiS_Pr->SiS_HDE = 1280;
@@ -3270,7 +3211,7 @@ SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3270 unsigned short resinfo, CRT2Index, ResIndex; 3211 unsigned short resinfo, CRT2Index, ResIndex;
3271 const struct SiS_LCDData *LCDPtr = NULL; 3212 const struct SiS_LCDData *LCDPtr = NULL;
3272 const struct SiS_TVData *TVPtr = NULL; 3213 const struct SiS_TVData *TVPtr = NULL;
3273#ifdef SIS315H 3214#ifdef CONFIG_FB_SIS_315
3274 short resinfo661; 3215 short resinfo661;
3275#endif 3216#endif
3276 3217
@@ -3283,7 +3224,7 @@ SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3283 } else { 3224 } else {
3284 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 3225 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3285 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 3226 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3286#ifdef SIS315H 3227#ifdef CONFIG_FB_SIS_315
3287 resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661; 3228 resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
3288 if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && 3229 if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
3289 (SiS_Pr->SiS_SetFlag & LCDVESATiming) && 3230 (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
@@ -3460,7 +3401,7 @@ SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3460 3401
3461 } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) { 3402 } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
3462 3403
3463#ifdef SIS315H 3404#ifdef CONFIG_FB_SIS_315
3464 SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr]; 3405 SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
3465 SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1]; 3406 SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
3466 SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8); 3407 SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
@@ -3520,19 +3461,13 @@ SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3520 case Panel_1680x1050 : 3461 case Panel_1680x1050 :
3521 case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break; 3462 case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
3522 case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break; 3463 case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
3523#ifdef SIS315H 3464#ifdef CONFIG_FB_SIS_315
3524 case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break; 3465 case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
3525 case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break; 3466 case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
3526#endif 3467#endif
3527 default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break; 3468 default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
3528 } 3469 }
3529 3470
3530#ifdef SIS_XORG_XF86
3531#ifdef TWDEBUG
3532 xf86DrvMsg(0, X_INFO, "GetCRT2Data: Index %d ResIndex %d\n", CRT2Index, ResIndex);
3533#endif
3534#endif
3535
3536 SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX; 3471 SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
3537 SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT; 3472 SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
3538 SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT; 3473 SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
@@ -3624,7 +3559,7 @@ SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr)
3624{ 3559{
3625 const struct SiS_LVDSDes *PanelDesPtr = NULL; 3560 const struct SiS_LVDSDes *PanelDesPtr = NULL;
3626 3561
3627#ifdef SIS300 3562#ifdef CONFIG_FB_SIS_300
3628 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { 3563 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
3629 3564
3630 if(SiS_Pr->ChipType < SIS_315H) { 3565 if(SiS_Pr->ChipType < SIS_315H) {
@@ -3696,7 +3631,7 @@ SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3696 3631
3697 if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 3632 if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
3698 3633
3699#ifdef SIS315H 3634#ifdef CONFIG_FB_SIS_315
3700 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { 3635 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3701 /* non-pass 1:1 only, see above */ 3636 /* non-pass 1:1 only, see above */
3702 if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) { 3637 if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
@@ -3771,7 +3706,7 @@ SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3771 } else { 3706 } else {
3772 3707
3773 if(SiS_Pr->ChipType < SIS_315H) { 3708 if(SiS_Pr->ChipType < SIS_315H) {
3774#ifdef SIS300 3709#ifdef CONFIG_FB_SIS_300
3775 switch(SiS_Pr->SiS_LCDResInfo) { 3710 switch(SiS_Pr->SiS_LCDResInfo) {
3776 case Panel_800x600: 3711 case Panel_800x600:
3777 if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) { 3712 if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
@@ -3816,7 +3751,7 @@ SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3816 } 3751 }
3817#endif 3752#endif
3818 } else { 3753 } else {
3819#ifdef SIS315H 3754#ifdef CONFIG_FB_SIS_315
3820 switch(SiS_Pr->SiS_LCDResInfo) { 3755 switch(SiS_Pr->SiS_LCDResInfo) {
3821 case Panel_1024x768: 3756 case Panel_1024x768:
3822 case Panel_1280x1024: 3757 case Panel_1280x1024:
@@ -3844,7 +3779,7 @@ SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3844 if(SiS_Pr->ChipType < SIS_315H) { 3779 if(SiS_Pr->ChipType < SIS_315H) {
3845 if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320; 3780 if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
3846 } else { 3781 } else {
3847#ifdef SIS315H 3782#ifdef CONFIG_FB_SIS_315
3848 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480; 3783 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
3849 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804; 3784 if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
3850 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704; 3785 if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
@@ -3866,7 +3801,7 @@ SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3866/* DISABLE VIDEO BRIDGE */ 3801/* DISABLE VIDEO BRIDGE */
3867/*********************************************/ 3802/*********************************************/
3868 3803
3869#ifdef SIS315H 3804#ifdef CONFIG_FB_SIS_315
3870static int 3805static int
3871SiS_HandlePWD(struct SiS_Private *SiS_Pr) 3806SiS_HandlePWD(struct SiS_Private *SiS_Pr)
3872{ 3807{
@@ -3891,11 +3826,6 @@ SiS_HandlePWD(struct SiS_Private *SiS_Pr)
3891 ret = 1; 3826 ret = 1;
3892 } 3827 }
3893 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp); 3828 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp);
3894#ifdef SIS_XORG_XF86
3895#ifdef TWDEBUG
3896 xf86DrvMsg(0, 0, "Setting PWD %x\n", temp);
3897#endif
3898#endif
3899 } 3829 }
3900#endif 3830#endif
3901 return ret; 3831 return ret;
@@ -3909,7 +3839,7 @@ SiS_HandlePWD(struct SiS_Private *SiS_Pr)
3909void 3839void
3910SiS_DisableBridge(struct SiS_Private *SiS_Pr) 3840SiS_DisableBridge(struct SiS_Private *SiS_Pr)
3911{ 3841{
3912#ifdef SIS315H 3842#ifdef CONFIG_FB_SIS_315
3913 unsigned short tempah, pushax=0, modenum; 3843 unsigned short tempah, pushax=0, modenum;
3914#endif 3844#endif
3915 unsigned short temp=0; 3845 unsigned short temp=0;
@@ -3920,7 +3850,7 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
3920 3850
3921 if(SiS_Pr->ChipType < SIS_315H) { 3851 if(SiS_Pr->ChipType < SIS_315H) {
3922 3852
3923#ifdef SIS300 /* 300 series */ 3853#ifdef CONFIG_FB_SIS_300 /* 300 series */
3924 3854
3925 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { 3855 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
3926 if(SiS_Pr->SiS_VBType & VB_SISLVDS) { 3856 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
@@ -3953,11 +3883,11 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
3953 } 3883 }
3954 } 3884 }
3955 3885
3956#endif /* SIS300 */ 3886#endif /* CONFIG_FB_SIS_300 */
3957 3887
3958 } else { 3888 } else {
3959 3889
3960#ifdef SIS315H /* 315 series */ 3890#ifdef CONFIG_FB_SIS_315 /* 315 series */
3961 3891
3962 int didpwd = 0; 3892 int didpwd = 0;
3963 bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) || 3893 bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
@@ -4081,14 +4011,14 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
4081 4011
4082 } 4012 }
4083 4013
4084#endif /* SIS315H */ 4014#endif /* CONFIG_FB_SIS_315 */
4085 4015
4086 } 4016 }
4087 4017
4088 } else { /* ============ For 301 ================ */ 4018 } else { /* ============ For 301 ================ */
4089 4019
4090 if(SiS_Pr->ChipType < SIS_315H) { 4020 if(SiS_Pr->ChipType < SIS_315H) {
4091#ifdef SIS300 4021#ifdef CONFIG_FB_SIS_300
4092 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { 4022 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
4093 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08); 4023 SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
4094 SiS_PanelDelay(SiS_Pr, 3); 4024 SiS_PanelDelay(SiS_Pr, 3);
@@ -4111,7 +4041,7 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
4111 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); 4041 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
4112 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp); 4042 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
4113 } else { 4043 } else {
4114#ifdef SIS300 4044#ifdef CONFIG_FB_SIS_300
4115 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */ 4045 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
4116 if( (!(SiS_CRT2IsLCD(SiS_Pr))) || 4046 if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
4117 (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) { 4047 (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
@@ -4127,7 +4057,7 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
4127 4057
4128 if(SiS_Pr->ChipType < SIS_315H) { 4058 if(SiS_Pr->ChipType < SIS_315H) {
4129 4059
4130#ifdef SIS300 /* 300 series */ 4060#ifdef CONFIG_FB_SIS_300 /* 300 series */
4131 4061
4132 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { 4062 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
4133 SiS_SetCH700x(SiS_Pr,0x0E,0x09); 4063 SiS_SetCH700x(SiS_Pr,0x0E,0x09);
@@ -4171,11 +4101,11 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
4171 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04); 4101 SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
4172 } 4102 }
4173 4103
4174#endif /* SIS300 */ 4104#endif /* CONFIG_FB_SIS_300 */
4175 4105
4176 } else { 4106 } else {
4177 4107
4178#ifdef SIS315H /* 315 series */ 4108#ifdef CONFIG_FB_SIS_315 /* 315 series */
4179 4109
4180 if(!(SiS_IsNotM650orLater(SiS_Pr))) { 4110 if(!(SiS_IsNotM650orLater(SiS_Pr))) {
4181 /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */ 4111 /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */
@@ -4288,7 +4218,7 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
4288 } 4218 }
4289 } 4219 }
4290 4220
4291#endif /* SIS315H */ 4221#endif /* CONFIG_FB_SIS_315 */
4292 4222
4293 } /* 315 series */ 4223 } /* 315 series */
4294 4224
@@ -4304,14 +4234,12 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
4304 * from outside the context of a mode switch! 4234 * from outside the context of a mode switch!
4305 * MUST call getVBType before calling this 4235 * MUST call getVBType before calling this
4306 */ 4236 */
4307#ifdef SIS_LINUX_KERNEL
4308static 4237static
4309#endif
4310void 4238void
4311SiS_EnableBridge(struct SiS_Private *SiS_Pr) 4239SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4312{ 4240{
4313 unsigned short temp=0, tempah; 4241 unsigned short temp=0, tempah;
4314#ifdef SIS315H 4242#ifdef CONFIG_FB_SIS_315
4315 unsigned short temp1, pushax=0; 4243 unsigned short temp1, pushax=0;
4316 bool delaylong = false; 4244 bool delaylong = false;
4317#endif 4245#endif
@@ -4322,7 +4250,7 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4322 4250
4323 if(SiS_Pr->ChipType < SIS_315H) { 4251 if(SiS_Pr->ChipType < SIS_315H) {
4324 4252
4325#ifdef SIS300 /* 300 series */ 4253#ifdef CONFIG_FB_SIS_300 /* 300 series */
4326 4254
4327 if(SiS_CRT2IsLCD(SiS_Pr)) { 4255 if(SiS_CRT2IsLCD(SiS_Pr)) {
4328 if(SiS_Pr->SiS_VBType & VB_SISLVDS) { 4256 if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
@@ -4385,11 +4313,11 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4385 } 4313 }
4386 4314
4387 4315
4388#endif /* SIS300 */ 4316#endif /* CONFIG_FB_SIS_300 */
4389 4317
4390 } else { 4318 } else {
4391 4319
4392#ifdef SIS315H /* 315 series */ 4320#ifdef CONFIG_FB_SIS_315 /* 315 series */
4393 4321
4394#ifdef SET_EMI 4322#ifdef SET_EMI
4395 unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0; 4323 unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0;
@@ -4688,7 +4616,7 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4688 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); 4616 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
4689 } 4617 }
4690 4618
4691#endif /* SIS315H */ 4619#endif /* CONFIG_FB_SIS_315 */
4692 4620
4693 } 4621 }
4694 4622
@@ -4739,7 +4667,7 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4739 4667
4740 if(SiS_Pr->ChipType < SIS_315H) { 4668 if(SiS_Pr->ChipType < SIS_315H) {
4741 4669
4742#ifdef SIS300 /* 300 series */ 4670#ifdef CONFIG_FB_SIS_300 /* 300 series */
4743 4671
4744 if(SiS_CRT2IsLCD(SiS_Pr)) { 4672 if(SiS_CRT2IsLCD(SiS_Pr)) {
4745 if(SiS_Pr->ChipType == SIS_730) { 4673 if(SiS_Pr->ChipType == SIS_730) {
@@ -4783,11 +4711,11 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4783 } 4711 }
4784 } 4712 }
4785 4713
4786#endif /* SIS300 */ 4714#endif /* CONFIG_FB_SIS_300 */
4787 4715
4788 } else { 4716 } else {
4789 4717
4790#ifdef SIS315H /* 315 series */ 4718#ifdef CONFIG_FB_SIS_315 /* 315 series */
4791 4719
4792 if(!(SiS_IsNotM650orLater(SiS_Pr))) { 4720 if(!(SiS_IsNotM650orLater(SiS_Pr))) {
4793 /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */ 4721 /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */
@@ -4881,7 +4809,7 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4881 } 4809 }
4882 } 4810 }
4883 4811
4884#endif /* SIS315H */ 4812#endif /* CONFIG_FB_SIS_315 */
4885 4813
4886 } /* 310 series */ 4814 } /* 310 series */
4887 4815
@@ -4971,7 +4899,7 @@ SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned shor
4971 4899
4972 if(SiS_Pr->ChipType < SIS_315H) { 4900 if(SiS_Pr->ChipType < SIS_315H) {
4973 4901
4974#ifdef SIS300 /* ---- 300 series --- */ 4902#ifdef CONFIG_FB_SIS_300 /* ---- 300 series --- */
4975 4903
4976 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */ 4904 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */
4977 4905
@@ -5000,11 +4928,11 @@ SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned shor
5000 4928
5001 } 4929 }
5002 4930
5003#endif /* SIS300 */ 4931#endif /* CONFIG_FB_SIS_300 */
5004 4932
5005 } else { 4933 } else {
5006 4934
5007#ifdef SIS315H /* ------- 315 series ------ */ 4935#ifdef CONFIG_FB_SIS_315 /* ------- 315 series ------ */
5008 4936
5009 if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */ 4937 if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */
5010 4938
@@ -5076,13 +5004,13 @@ SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned shor
5076 } 5004 }
5077 5005
5078 } 5006 }
5079#endif /* SIS315H */ 5007#endif /* CONFIG_FB_SIS_315 */
5080 } 5008 }
5081 } 5009 }
5082} 5010}
5083 5011
5084/* Set CRT2 FIFO on 300/540/630/730 */ 5012/* Set CRT2 FIFO on 300/540/630/730 */
5085#ifdef SIS300 5013#ifdef CONFIG_FB_SIS_300
5086static void 5014static void
5087SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo) 5015SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
5088{ 5016{
@@ -5154,13 +5082,8 @@ SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
5154 5082
5155 } else { 5083 } else {
5156 5084
5157#ifdef SIS_LINUX_KERNEL
5158 pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50); 5085 pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
5159 pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0); 5086 pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0);
5160#else
5161 pci50 = pciReadLong(0x00000000, 0x50);
5162 pciA0 = pciReadLong(0x00000000, 0xA0);
5163#endif
5164 5087
5165 if(SiS_Pr->ChipType == SIS_730) { 5088 if(SiS_Pr->ChipType == SIS_730) {
5166 5089
@@ -5262,7 +5185,7 @@ SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
5262#endif 5185#endif
5263 5186
5264/* Set CRT2 FIFO on 315/330 series */ 5187/* Set CRT2 FIFO on 315/330 series */
5265#ifdef SIS315H 5188#ifdef CONFIG_FB_SIS_315
5266static void 5189static void
5267SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr) 5190SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr)
5268{ 5191{
@@ -5420,27 +5343,6 @@ SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned sho
5420 5343
5421 temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)); 5344 temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
5422 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */ 5345 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */
5423
5424#ifdef SIS_XORG_XF86
5425#ifdef TWDEBUG
5426 xf86DrvMsg(0, X_INFO, "%d %d %d %d %d %d %d %d (%d %d %d %d)\n",
5427 SiS_Pr->CHDisplay, SiS_Pr->CHSyncStart, SiS_Pr->CHSyncEnd, SiS_Pr->CHTotal,
5428 SiS_Pr->CVDisplay, SiS_Pr->CVSyncStart, SiS_Pr->CVSyncEnd, SiS_Pr->CVTotal,
5429 SiS_Pr->CHBlankStart, SiS_Pr->CHBlankEnd, SiS_Pr->CVBlankStart, SiS_Pr->CVBlankEnd);
5430
5431 xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
5432 SiS_Pr->CCRT1CRTC[0], SiS_Pr->CCRT1CRTC[1],
5433 SiS_Pr->CCRT1CRTC[2], SiS_Pr->CCRT1CRTC[3],
5434 SiS_Pr->CCRT1CRTC[4], SiS_Pr->CCRT1CRTC[5],
5435 SiS_Pr->CCRT1CRTC[6], SiS_Pr->CCRT1CRTC[7]);
5436 xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
5437 SiS_Pr->CCRT1CRTC[8], SiS_Pr->CCRT1CRTC[9],
5438 SiS_Pr->CCRT1CRTC[10], SiS_Pr->CCRT1CRTC[11],
5439 SiS_Pr->CCRT1CRTC[12], SiS_Pr->CCRT1CRTC[13],
5440 SiS_Pr->CCRT1CRTC[14], SiS_Pr->CCRT1CRTC[15]);
5441 xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", SiS_Pr->CCRT1CRTC[16]);
5442#endif
5443#endif
5444} 5346}
5445 5347
5446/* Setup panel link 5348/* Setup panel link
@@ -5455,17 +5357,17 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5455 unsigned short push2, tempax, tempbx, tempcx, temp; 5357 unsigned short push2, tempax, tempbx, tempcx, temp;
5456 unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0; 5358 unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
5457 bool islvds = false, issis = false, chkdclkfirst = false; 5359 bool islvds = false, issis = false, chkdclkfirst = false;
5458#ifdef SIS300 5360#ifdef CONFIG_FB_SIS_300
5459 unsigned short crt2crtc = 0; 5361 unsigned short crt2crtc = 0;
5460#endif 5362#endif
5461#ifdef SIS315H 5363#ifdef CONFIG_FB_SIS_315
5462 unsigned short pushcx; 5364 unsigned short pushcx;
5463#endif 5365#endif
5464 5366
5465 if(ModeNo <= 0x13) { 5367 if(ModeNo <= 0x13) {
5466 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 5368 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
5467 resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; 5369 resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
5468#ifdef SIS300 5370#ifdef CONFIG_FB_SIS_300
5469 crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; 5371 crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
5470#endif 5372#endif
5471 } else if(SiS_Pr->UseCustomMode) { 5373 } else if(SiS_Pr->UseCustomMode) {
@@ -5473,7 +5375,7 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5473 } else { 5375 } else {
5474 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 5376 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5475 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; 5377 resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
5476#ifdef SIS300 5378#ifdef CONFIG_FB_SIS_300
5477 crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; 5379 crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
5478#endif 5380#endif
5479 } 5381 }
@@ -5494,7 +5396,7 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5494 } 5396 }
5495 } 5397 }
5496 5398
5497#ifdef SIS315H 5399#ifdef CONFIG_FB_SIS_315
5498 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { 5400 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
5499 if(IS_SIS330) { 5401 if(IS_SIS330) {
5500 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10); 5402 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
@@ -5744,7 +5646,7 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5744 5646
5745 if(SiS_Pr->ChipType < SIS_315H) { 5647 if(SiS_Pr->ChipType < SIS_315H) {
5746 5648
5747#ifdef SIS300 /* 300 series */ 5649#ifdef CONFIG_FB_SIS_300 /* 300 series */
5748 tempeax = SiS_Pr->SiS_VGAVDE << 6; 5650 tempeax = SiS_Pr->SiS_VGAVDE << 6;
5749 temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE); 5651 temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE);
5750 tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE; 5652 tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE;
@@ -5755,11 +5657,11 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5755 temp = (unsigned short)(tempeax & 0x00FF); 5657 temp = (unsigned short)(tempeax & 0x00FF);
5756 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */ 5658 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
5757 tempvcfact = temp; 5659 tempvcfact = temp;
5758#endif /* SIS300 */ 5660#endif /* CONFIG_FB_SIS_300 */
5759 5661
5760 } else { 5662 } else {
5761 5663
5762#ifdef SIS315H /* 315 series */ 5664#ifdef CONFIG_FB_SIS_315 /* 315 series */
5763 tempeax = SiS_Pr->SiS_VGAVDE << 18; 5665 tempeax = SiS_Pr->SiS_VGAVDE << 18;
5764 tempebx = SiS_Pr->SiS_VDE; 5666 tempebx = SiS_Pr->SiS_VDE;
5765 temp = (tempeax % tempebx); 5667 temp = (tempeax % tempebx);
@@ -5845,7 +5747,7 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5845 temp = (unsigned short)(tempecx & 0x00FF); 5747 temp = (unsigned short)(tempecx & 0x00FF);
5846 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp); 5748 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
5847 5749
5848#ifdef SIS315H 5750#ifdef CONFIG_FB_SIS_315
5849 if(SiS_Pr->ChipType >= SIS_315H) { 5751 if(SiS_Pr->ChipType >= SIS_315H) {
5850 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 5752 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
5851 if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) { 5753 if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) {
@@ -5863,7 +5765,7 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5863 } 5765 }
5864#endif 5766#endif
5865 5767
5866#ifdef SIS300 5768#ifdef CONFIG_FB_SIS_300
5867 if(SiS_Pr->SiS_IF_DEF_TRUMPION) { 5769 if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
5868 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 5770 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
5869 unsigned char *trumpdata; 5771 unsigned char *trumpdata;
@@ -5899,7 +5801,7 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5899 } 5801 }
5900#endif 5802#endif
5901 5803
5902#ifdef SIS315H 5804#ifdef CONFIG_FB_SIS_315
5903 if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) { 5805 if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
5904 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00); 5806 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00);
5905 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00); 5807 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00);
@@ -5999,7 +5901,7 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5999 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a); 5901 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a);
6000 } 5902 }
6001 } 5903 }
6002#endif /* SIS315H */ 5904#endif /* CONFIG_FB_SIS_315 */
6003} 5905}
6004 5906
6005/* Set Part 1 */ 5907/* Set Part 1 */
@@ -6007,12 +5909,12 @@ static void
6007SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, 5909SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
6008 unsigned short RefreshRateTableIndex) 5910 unsigned short RefreshRateTableIndex)
6009{ 5911{
6010#if defined(SIS300) || defined(SIS315H) 5912#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
6011 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 5913 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
6012#endif 5914#endif
6013 unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0; 5915 unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
6014 unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0; 5916 unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0;
6015#ifdef SIS315H 5917#ifdef CONFIG_FB_SIS_315
6016 unsigned short tempbl=0; 5918 unsigned short tempbl=0;
6017#endif 5919#endif
6018 5920
@@ -6038,11 +5940,11 @@ SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6038 (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) { 5940 (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
6039 5941
6040 if(SiS_Pr->ChipType < SIS_315H ) { 5942 if(SiS_Pr->ChipType < SIS_315H ) {
6041#ifdef SIS300 5943#ifdef CONFIG_FB_SIS_300
6042 SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo); 5944 SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo);
6043#endif 5945#endif
6044 } else { 5946 } else {
6045#ifdef SIS315H 5947#ifdef CONFIG_FB_SIS_315
6046 SiS_SetCRT2FIFO_310(SiS_Pr); 5948 SiS_SetCRT2FIFO_310(SiS_Pr);
6047#endif 5949#endif
6048 } 5950 }
@@ -6051,7 +5953,7 @@ SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6051 5953
6052 if(SiS_Pr->ChipType < SIS_315H ) { 5954 if(SiS_Pr->ChipType < SIS_315H ) {
6053 5955
6054#ifdef SIS300 /* ------------- 300 series --------------*/ 5956#ifdef CONFIG_FB_SIS_300 /* ------------- 300 series --------------*/
6055 5957
6056 temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */ 5958 temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
6057 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */ 5959 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
@@ -6070,11 +5972,11 @@ SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6070 5972
6071 bridgeadd = 12; 5973 bridgeadd = 12;
6072 5974
6073#endif /* SIS300 */ 5975#endif /* CONFIG_FB_SIS_300 */
6074 5976
6075 } else { 5977 } else {
6076 5978
6077#ifdef SIS315H /* ------------------- 315/330 series --------------- */ 5979#ifdef CONFIG_FB_SIS_315 /* ------------------- 315/330 series --------------- */
6078 5980
6079 tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */ 5981 tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */
6080 if(modeflag & HalfDCLK) { 5982 if(modeflag & HalfDCLK) {
@@ -6125,7 +6027,7 @@ SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6125 } 6027 }
6126 } 6028 }
6127 6029
6128#endif /* SIS315H */ 6030#endif /* CONFIG_FB_SIS_315 */
6129 6031
6130 } /* 315/330 series */ 6032 } /* 315/330 series */
6131 6033
@@ -6256,7 +6158,7 @@ SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6256 6158
6257 if(SiS_Pr->ChipType < SIS_315H) { 6159 if(SiS_Pr->ChipType < SIS_315H) {
6258 6160
6259#ifdef SIS300 /* ---------- 300 series -------------- */ 6161#ifdef CONFIG_FB_SIS_300 /* ---------- 300 series -------------- */
6260 6162
6261 if(SiS_Pr->SiS_VBType & VB_SISVB) { 6163 if(SiS_Pr->SiS_VBType & VB_SISVB) {
6262 temp = 0x20; 6164 temp = 0x20;
@@ -6310,11 +6212,11 @@ SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6310 6212
6311 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */ 6213 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
6312 6214
6313#endif /* SIS300 */ 6215#endif /* CONFIG_FB_SIS_300 */
6314 6216
6315 } else { 6217 } else {
6316 6218
6317#ifdef SIS315H /* --------------- 315/330 series ---------------*/ 6219#ifdef CONFIG_FB_SIS_315 /* --------------- 315/330 series ---------------*/
6318 6220
6319 if(SiS_Pr->ChipType < SIS_661) { 6221 if(SiS_Pr->ChipType < SIS_661) {
6320 6222
@@ -6349,7 +6251,7 @@ SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6349 if(modeflag & HalfDCLK) tempax |= 0x40; 6251 if(modeflag & HalfDCLK) tempax |= 0x40;
6350 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax); 6252 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
6351 6253
6352#endif /* SIS315H */ 6254#endif /* CONFIG_FB_SIS_315 */
6353 6255
6354 } 6256 }
6355 6257
@@ -6381,7 +6283,7 @@ SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6381/* SET PART 2 REGISTER GROUP */ 6283/* SET PART 2 REGISTER GROUP */
6382/*********************************************/ 6284/*********************************************/
6383 6285
6384#ifdef SIS315H 6286#ifdef CONFIG_FB_SIS_315
6385static unsigned char * 6287static unsigned char *
6386SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype) 6288SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype)
6387{ 6289{
@@ -6478,7 +6380,7 @@ SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned sh
6478} 6380}
6479#endif 6381#endif
6480 6382
6481#ifdef SIS300 6383#ifdef CONFIG_FB_SIS_300
6482static void 6384static void
6483SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc) 6385SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc)
6484{ 6386{
@@ -6690,7 +6592,7 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6690 unsigned int longtemp, PhaseIndex; 6592 unsigned int longtemp, PhaseIndex;
6691 bool newtvphase; 6593 bool newtvphase;
6692 const unsigned char *TimingPoint; 6594 const unsigned char *TimingPoint;
6693#ifdef SIS315H 6595#ifdef CONFIG_FB_SIS_315
6694 unsigned short resindex, CRT2Index; 6596 unsigned short resindex, CRT2Index;
6695 const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL; 6597 const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
6696 6598
@@ -7069,7 +6971,7 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7069 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB); 6971 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
7070 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF); 6972 SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
7071 6973
7072#ifdef SIS315H 6974#ifdef CONFIG_FB_SIS_315
7073 if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, 6975 if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
7074 &CRT2Index, &resindex)) { 6976 &CRT2Index, &resindex)) {
7075 switch(CRT2Index) { 6977 switch(CRT2Index) {
@@ -7130,12 +7032,6 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7130 7032
7131 /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */ 7033 /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
7132 7034
7133#ifdef SIS_XORG_XF86
7134#ifdef TWDEBUG
7135 xf86DrvMsg(0, X_INFO, "lcdvdes 0x%x lcdvdee 0x%x\n", tempcx, tempbx);
7136#endif
7137#endif
7138
7139 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */ 7035 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
7140 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */ 7036 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
7141 7037
@@ -7184,12 +7080,6 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7184 tempbx = SiS_Pr->CVSyncStart; 7080 tempbx = SiS_Pr->CVSyncStart;
7185 } 7081 }
7186 7082
7187#ifdef SIS_XORG_XF86
7188#ifdef TWDEBUG
7189 xf86DrvMsg(0, X_INFO, "lcdvrs 0x%x\n", tempbx);
7190#endif
7191#endif
7192
7193 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */ 7083 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
7194 7084
7195 temp = (tempbx >> 4) & 0xF0; 7085 temp = (tempbx >> 4) & 0xF0;
@@ -7201,15 +7091,9 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7201 temp |= (SiS_Pr->CVSyncEnd & 0x0f); 7091 temp |= (SiS_Pr->CVSyncEnd & 0x0f);
7202 } 7092 }
7203 7093
7204#ifdef SIS_XORG_XF86
7205#ifdef TWDEBUG
7206 xf86DrvMsg(0, X_INFO, "lcdvre[3:0] 0x%x\n", (temp & 0x0f));
7207#endif
7208#endif
7209
7210 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp); 7094 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
7211 7095
7212#ifdef SIS300 7096#ifdef CONFIG_FB_SIS_300
7213 SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc); 7097 SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc);
7214#endif 7098#endif
7215 7099
@@ -7245,12 +7129,6 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7245 tempax >>= 1; 7129 tempax >>= 1;
7246 } 7130 }
7247 7131
7248#ifdef SIS_XORG_XF86
7249#ifdef TWDEBUG
7250 xf86DrvMsg(0, X_INFO, "lcdhdee 0x%x\n", tempbx);
7251#endif
7252#endif
7253
7254 tempbx += bridgeoffset; 7132 tempbx += bridgeoffset;
7255 7133
7256 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */ 7134 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */
@@ -7276,12 +7154,6 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7276 tempbx += bridgeoffset; 7154 tempbx += bridgeoffset;
7277 } 7155 }
7278 7156
7279#ifdef SIS_XORG_XF86
7280#ifdef TWDEBUG
7281 xf86DrvMsg(0, X_INFO, "lcdhrs 0x%x\n", tempbx);
7282#endif
7283#endif
7284
7285 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */ 7157 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
7286 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0)); 7158 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
7287 7159
@@ -7300,20 +7172,14 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7300 tempbx += bridgeoffset; 7172 tempbx += bridgeoffset;
7301 } 7173 }
7302 7174
7303#ifdef SIS_XORG_XF86
7304#ifdef TWDEBUG
7305 xf86DrvMsg(0, X_INFO, "lcdhre 0x%x\n", tempbx);
7306#endif
7307#endif
7308
7309 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */ 7175 SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
7310 7176
7311 SiS_SetGroup2_Tail(SiS_Pr, ModeNo); 7177 SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
7312 7178
7313#ifdef SIS300 7179#ifdef CONFIG_FB_SIS_300
7314 SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo); 7180 SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo);
7315#endif 7181#endif
7316#ifdef SIS315H 7182#ifdef CONFIG_FB_SIS_315
7317 } /* CRT2-LCD from table */ 7183 } /* CRT2-LCD from table */
7318#endif 7184#endif
7319} 7185}
@@ -7382,7 +7248,7 @@ SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7382/* SET PART 4 REGISTER GROUP */ 7248/* SET PART 4 REGISTER GROUP */
7383/*********************************************/ 7249/*********************************************/
7384 7250
7385#ifdef SIS315H 7251#ifdef CONFIG_FB_SIS_315
7386#if 0 7252#if 0
7387static void 7253static void
7388SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift) 7254SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift)
@@ -8011,7 +7877,7 @@ SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
8011 7877
8012 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { 7878 if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
8013 7879
8014#ifdef SIS300 7880#ifdef CONFIG_FB_SIS_300
8015 7881
8016 /* Chrontel 7005 - I assume that it does not come with a 315 series chip */ 7882 /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
8017 7883
@@ -8124,7 +7990,7 @@ SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
8124 7990
8125 /* Chrontel 7019 - assumed that it does not come with a 300 series chip */ 7991 /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
8126 7992
8127#ifdef SIS315H 7993#ifdef CONFIG_FB_SIS_315
8128 7994
8129 unsigned short temp; 7995 unsigned short temp;
8130 7996
@@ -8175,7 +8041,7 @@ SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
8175 8041
8176} 8042}
8177 8043
8178#ifdef SIS315H /* ----------- 315 series only ---------- */ 8044#ifdef CONFIG_FB_SIS_315 /* ----------- 315 series only ---------- */
8179 8045
8180void 8046void
8181SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr) 8047SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr)
@@ -8657,7 +8523,7 @@ SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
8657bool 8523bool
8658SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo) 8524SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8659{ 8525{
8660#ifdef SIS300 8526#ifdef CONFIG_FB_SIS_300
8661 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 8527 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
8662#endif 8528#endif
8663 unsigned short ModeIdIndex, RefreshRateTableIndex; 8529 unsigned short ModeIdIndex, RefreshRateTableIndex;
@@ -8703,16 +8569,6 @@ SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8703 SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); 8569 SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8704 } 8570 }
8705 8571
8706#ifdef SIS_XORG_XF86
8707#ifdef TWDEBUG
8708 xf86DrvMsg(0, X_INFO, "(init301: LCDHDES 0x%03x LCDVDES 0x%03x)\n", SiS_Pr->SiS_LCDHDES, SiS_Pr->SiS_LCDVDES);
8709 xf86DrvMsg(0, X_INFO, "(init301: HDE 0x%03x VDE 0x%03x)\n", SiS_Pr->SiS_HDE, SiS_Pr->SiS_VDE);
8710 xf86DrvMsg(0, X_INFO, "(init301: VGAHDE 0x%03x VGAVDE 0x%03x)\n", SiS_Pr->SiS_VGAHDE, SiS_Pr->SiS_VGAVDE);
8711 xf86DrvMsg(0, X_INFO, "(init301: HT 0x%03x VT 0x%03x)\n", SiS_Pr->SiS_HT, SiS_Pr->SiS_VT);
8712 xf86DrvMsg(0, X_INFO, "(init301: VGAHT 0x%03x VGAVT 0x%03x)\n", SiS_Pr->SiS_VGAHT, SiS_Pr->SiS_VGAVT);
8713#endif
8714#endif
8715
8716 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8572 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8717 SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); 8573 SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8718 } 8574 }
@@ -8722,12 +8578,12 @@ SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8722 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8578 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8723 8579
8724 SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); 8580 SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8725#ifdef SIS315H 8581#ifdef CONFIG_FB_SIS_315
8726 SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); 8582 SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8727#endif 8583#endif
8728 SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex); 8584 SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex);
8729 SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); 8585 SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
8730#ifdef SIS315H 8586#ifdef CONFIG_FB_SIS_315
8731 SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex); 8587 SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex);
8732#endif 8588#endif
8733 SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex); 8589 SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex);
@@ -8758,7 +8614,7 @@ SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8758 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { 8614 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
8759 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { 8615 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
8760 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { 8616 if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
8761#ifdef SIS315H 8617#ifdef CONFIG_FB_SIS_315
8762 SiS_SetCH701xForLCD(SiS_Pr); 8618 SiS_SetCH701xForLCD(SiS_Pr);
8763#endif 8619#endif
8764 } 8620 }
@@ -8771,7 +8627,7 @@ SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8771 8627
8772 } 8628 }
8773 8629
8774#ifdef SIS300 8630#ifdef CONFIG_FB_SIS_300
8775 if(SiS_Pr->ChipType < SIS_315H) { 8631 if(SiS_Pr->ChipType < SIS_315H) {
8776 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8632 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8777 if(SiS_Pr->SiS_UseOEM) { 8633 if(SiS_Pr->SiS_UseOEM) {
@@ -8794,7 +8650,7 @@ SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8794 } 8650 }
8795#endif 8651#endif
8796 8652
8797#ifdef SIS315H 8653#ifdef CONFIG_FB_SIS_315
8798 if(SiS_Pr->ChipType >= SIS_315H) { 8654 if(SiS_Pr->ChipType >= SIS_315H) {
8799 if(SiS_Pr->SiS_SetFlag & LowModeTests) { 8655 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
8800 if(SiS_Pr->ChipType < SIS_661) { 8656 if(SiS_Pr->ChipType < SIS_661) {
@@ -8873,7 +8729,7 @@ SiS_SetupDDCN(struct SiS_Private *SiS_Pr)
8873 } 8729 }
8874} 8730}
8875 8731
8876#ifdef SIS300 8732#ifdef CONFIG_FB_SIS_300
8877static unsigned char * 8733static unsigned char *
8878SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr) 8734SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
8879{ 8735{
@@ -8923,11 +8779,6 @@ SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
8923 dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr); 8779 dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
8924 if(!dataptr) return false; 8780 if(!dataptr) return false;
8925 } 8781 }
8926#ifdef SIS_XORG_XF86
8927#ifdef TWDEBUG
8928 xf86DrvMsg(0, X_INFO, "Trumpion block success\n");
8929#endif
8930#endif
8931 return true; 8782 return true;
8932} 8783}
8933#endif 8784#endif
@@ -9002,9 +8853,7 @@ SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
9002 SiS_SetChReg(SiS_Pr, reg, val, 0); 8853 SiS_SetChReg(SiS_Pr, reg, val, 0);
9003} 8854}
9004 8855
9005#ifdef SIS_LINUX_KERNEL
9006static 8856static
9007#endif
9008void 8857void
9009SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val) 8858SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
9010{ 8859{
@@ -9091,9 +8940,7 @@ SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
9091 8940
9092/* Read from Chrontel 70xx */ 8941/* Read from Chrontel 70xx */
9093/* Parameter is [Register no (S7-S0)] */ 8942/* Parameter is [Register no (S7-S0)] */
9094#ifdef SIS_LINUX_KERNEL
9095static 8943static
9096#endif
9097unsigned short 8944unsigned short
9098SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx) 8945SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx)
9099{ 8946{
@@ -9114,9 +8961,7 @@ SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
9114} 8961}
9115 8962
9116/* Our own DDC functions */ 8963/* Our own DDC functions */
9117#ifndef SIS_XORG_XF86
9118static 8964static
9119#endif
9120unsigned short 8965unsigned short
9121SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine, 8966SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
9122 unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32, 8967 unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32,
@@ -9224,12 +9069,6 @@ SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
9224 9069
9225 SiS_SetupDDCN(SiS_Pr); 9070 SiS_SetupDDCN(SiS_Pr);
9226 9071
9227#ifdef SIS_XORG_XF86
9228#ifdef TWDEBUG
9229 xf86DrvMsg(0, X_INFO, "DDC Port %x Index %x Shift %d\n",
9230 SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, temp);
9231#endif
9232#endif
9233 return 0; 9072 return 0;
9234} 9073}
9235 9074
@@ -9292,11 +9131,6 @@ SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
9292 SiS_SetSwitchDDC2(SiS_Pr); 9131 SiS_SetSwitchDDC2(SiS_Pr);
9293 if(SiS_PrepareDDC(SiS_Pr)) { 9132 if(SiS_PrepareDDC(SiS_Pr)) {
9294 SiS_SetStop(SiS_Pr); 9133 SiS_SetStop(SiS_Pr);
9295#ifdef SIS_XORG_XF86
9296#ifdef TWDEBUG
9297 xf86DrvMsg(0, X_INFO, "Probe: Prepare failed\n");
9298#endif
9299#endif
9300 return 0xFFFF; 9134 return 0xFFFF;
9301 } 9135 }
9302 mask = 0xf0; 9136 mask = 0xf0;
@@ -9310,11 +9144,6 @@ SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
9310 } else { 9144 } else {
9311 failed = true; 9145 failed = true;
9312 ret = 0xFFFF; 9146 ret = 0xFFFF;
9313#ifdef SIS_XORG_XF86
9314#ifdef TWDEBUG
9315 xf86DrvMsg(0, X_INFO, "Probe: Read 1 failed\n");
9316#endif
9317#endif
9318 } 9147 }
9319 } 9148 }
9320 if(!failed) { 9149 if(!failed) {
@@ -9324,11 +9153,6 @@ SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
9324 if(temp == value) ret = 0; 9153 if(temp == value) ret = 0;
9325 else { 9154 else {
9326 ret = 0xFFFF; 9155 ret = 0xFFFF;
9327#ifdef SIS_XORG_XF86
9328#ifdef TWDEBUG
9329 xf86DrvMsg(0, X_INFO, "Probe: Read 2 failed\n");
9330#endif
9331#endif
9332 if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { 9156 if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
9333 if(temp == 0x30) ret = 0; 9157 if(temp == 0x30) ret = 0;
9334 } 9158 }
@@ -9338,9 +9162,7 @@ SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
9338 return ret; 9162 return ret;
9339} 9163}
9340 9164
9341#ifndef SIS_XORG_XF86
9342static 9165static
9343#endif
9344unsigned short 9166unsigned short
9345SiS_ProbeDDC(struct SiS_Private *SiS_Pr) 9167SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
9346{ 9168{
@@ -9357,9 +9179,7 @@ SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
9357 return flag; 9179 return flag;
9358} 9180}
9359 9181
9360#ifndef SIS_XORG_XF86
9361static 9182static
9362#endif
9363unsigned short 9183unsigned short
9364SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer) 9184SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer)
9365{ 9185{
@@ -9606,11 +9426,6 @@ SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr)
9606 temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); 9426 temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
9607 } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog); 9427 } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
9608 if (!watchdog) { 9428 if (!watchdog) {
9609#ifdef SIS_XORG_XF86
9610#ifdef TWDEBUG
9611 xf86DrvMsg(0, X_INFO, "SetClkHigh failed\n");
9612#endif
9613#endif
9614 return 0xFFFF; 9429 return 0xFFFF;
9615 } 9430 }
9616 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); 9431 SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
@@ -9641,7 +9456,7 @@ SiS_CheckACK(struct SiS_Private *SiS_Pr)
9641 9456
9642/* =============== SiS 315/330 O.E.M. ================= */ 9457/* =============== SiS 315/330 O.E.M. ================= */
9643 9458
9644#ifdef SIS315H 9459#ifdef CONFIG_FB_SIS_315
9645 9460
9646static unsigned short 9461static unsigned short
9647GetRAMDACromptr(struct SiS_Private *SiS_Pr) 9462GetRAMDACromptr(struct SiS_Private *SiS_Pr)
@@ -10829,7 +10644,7 @@ SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned shor
10829 10644
10830/* ================= SiS 300 O.E.M. ================== */ 10645/* ================= SiS 300 O.E.M. ================== */
10831 10646
10832#ifdef SIS300 10647#ifdef CONFIG_FB_SIS_300
10833 10648
10834static void 10649static void
10835SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex, 10650SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
diff --git a/drivers/video/sis/init301.h b/drivers/video/sis/init301.h
index 51d99222375d..e1fd31d0fddf 100644
--- a/drivers/video/sis/init301.h
+++ b/drivers/video/sis/init301.h
@@ -53,15 +53,8 @@
53#ifndef _INIT301_H_ 53#ifndef _INIT301_H_
54#define _INIT301_H_ 54#define _INIT301_H_
55 55
56#include "osdef.h"
57#include "initdef.h" 56#include "initdef.h"
58 57
59#ifdef SIS_XORG_XF86
60#include "sis.h"
61#include "sis_regs.h"
62#endif
63
64#ifdef SIS_LINUX_KERNEL
65#include "vgatypes.h" 58#include "vgatypes.h"
66#include "vstruct.h" 59#include "vstruct.h"
67#ifdef SIS_CP 60#ifdef SIS_CP
@@ -72,7 +65,6 @@
72#include <linux/fb.h> 65#include <linux/fb.h>
73#include "sis.h" 66#include "sis.h"
74#include <video/sisfb.h> 67#include <video/sisfb.h>
75#endif
76 68
77static const unsigned char SiS_YPbPrTable[3][64] = { 69static const unsigned char SiS_YPbPrTable[3][64] = {
78 { 70 {
@@ -237,7 +229,7 @@ static const unsigned char SiS_Part2CLVX_6[] = { /* 1080i */
237 0xFF,0xFF, 229 0xFF,0xFF,
238}; 230};
239 231
240#ifdef SIS315H 232#ifdef CONFIG_FB_SIS_315
241/* 661 et al LCD data structure (2.03.00) */ 233/* 661 et al LCD data structure (2.03.00) */
242static const unsigned char SiS_LCDStruct661[] = { 234static const unsigned char SiS_LCDStruct661[] = {
243 /* 1024x768 */ 235 /* 1024x768 */
@@ -279,7 +271,7 @@ static const unsigned char SiS_LCDStruct661[] = {
279}; 271};
280#endif 272#endif
281 273
282#ifdef SIS300 274#ifdef CONFIG_FB_SIS_300
283static unsigned char SiS300_TrumpionData[14][80] = { 275static unsigned char SiS300_TrumpionData[14][80] = {
284 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02, 276 { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
285 0x20,0x03,0x0B,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x10,0x00,0x00,0x04,0x23, 277 0x20,0x03,0x0B,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x10,0x00,0x00,0x04,0x23,
@@ -356,9 +348,6 @@ static unsigned char SiS300_TrumpionData[14][80] = {
356#endif 348#endif
357 349
358void SiS_UnLockCRT2(struct SiS_Private *SiS_Pr); 350void SiS_UnLockCRT2(struct SiS_Private *SiS_Pr);
359#ifndef SIS_LINUX_KERNEL
360void SiS_LockCRT2(struct SiS_Private *SiS_Pr);
361#endif
362void SiS_EnableCRT2(struct SiS_Private *SiS_Pr); 351void SiS_EnableCRT2(struct SiS_Private *SiS_Pr);
363unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex); 352unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
364void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr); 353void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr);
@@ -375,9 +364,6 @@ unsigned short SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo
375 unsigned short RefreshRateTableIndex); 364 unsigned short RefreshRateTableIndex);
376unsigned short SiS_GetResInfo(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex); 365unsigned short SiS_GetResInfo(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex);
377void SiS_DisableBridge(struct SiS_Private *SiS_Pr); 366void SiS_DisableBridge(struct SiS_Private *SiS_Pr);
378#ifndef SIS_LINUX_KERNEL
379void SiS_EnableBridge(struct SiS_Private *SiS_Pr);
380#endif
381bool SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo); 367bool SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
382void SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr); 368void SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr);
383void SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr); 369void SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr);
@@ -386,13 +372,9 @@ void SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned cha
386unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempax); 372unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempax);
387void SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val); 373void SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
388unsigned short SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempax); 374unsigned short SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempax);
389#ifndef SIS_LINUX_KERNEL
390void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
391unsigned short SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempax);
392#endif
393void SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg, 375void SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
394 unsigned char orval,unsigned short andval); 376 unsigned char orval,unsigned short andval);
395#ifdef SIS315H 377#ifdef CONFIG_FB_SIS_315
396static void SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr); 378static void SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr);
397static void SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr); 379static void SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr);
398static void SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr); 380static void SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr);
@@ -401,7 +383,7 @@ void SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr);
401void SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr); 383void SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr);
402#endif /* 315 */ 384#endif /* 315 */
403 385
404#ifdef SIS300 386#ifdef CONFIG_FB_SIS_300
405static bool SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr); 387static bool SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr);
406void SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo); 388void SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo);
407#endif 389#endif
@@ -412,21 +394,12 @@ unsigned short SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, i
412 unsigned short adaptnum, unsigned short DDCdatatype, 394 unsigned short adaptnum, unsigned short DDCdatatype,
413 unsigned char *buffer, unsigned int VBFlags2); 395 unsigned char *buffer, unsigned int VBFlags2);
414 396
415#ifdef SIS_XORG_XF86
416unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags,
417 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype,
418 bool checkcr32, unsigned int VBFlags2);
419unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr);
420unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype,
421 unsigned char *buffer);
422#else
423static unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, 397static unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags,
424 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype, 398 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype,
425 bool checkcr32, unsigned int VBFlags2); 399 bool checkcr32, unsigned int VBFlags2);
426static unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr); 400static unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr);
427static unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, 401static unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype,
428 unsigned char *buffer); 402 unsigned char *buffer);
429#endif
430static void SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr); 403static void SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr);
431static unsigned short SiS_SetStart(struct SiS_Private *SiS_Pr); 404static unsigned short SiS_SetStart(struct SiS_Private *SiS_Pr);
432static unsigned short SiS_SetStop(struct SiS_Private *SiS_Pr); 405static unsigned short SiS_SetStop(struct SiS_Private *SiS_Pr);
@@ -441,13 +414,13 @@ static unsigned short SiS_PrepareDDC(struct SiS_Private *SiS_Pr);
441static void SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno); 414static void SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno);
442static unsigned short SiS_DoProbeDDC(struct SiS_Private *SiS_Pr); 415static unsigned short SiS_DoProbeDDC(struct SiS_Private *SiS_Pr);
443 416
444#ifdef SIS300 417#ifdef CONFIG_FB_SIS_300
445static void SiS_OEM300Setting(struct SiS_Private *SiS_Pr, 418static void SiS_OEM300Setting(struct SiS_Private *SiS_Pr,
446 unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefTabindex); 419 unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefTabindex);
447static void SetOEMLCDData2(struct SiS_Private *SiS_Pr, 420static void SetOEMLCDData2(struct SiS_Private *SiS_Pr,
448 unsigned short ModeNo, unsigned short ModeIdIndex,unsigned short RefTableIndex); 421 unsigned short ModeNo, unsigned short ModeIdIndex,unsigned short RefTableIndex);
449#endif 422#endif
450#ifdef SIS315H 423#ifdef CONFIG_FB_SIS_315
451static void SiS_OEM310Setting(struct SiS_Private *SiS_Pr, 424static void SiS_OEM310Setting(struct SiS_Private *SiS_Pr,
452 unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RRTI); 425 unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RRTI);
453static void SiS_OEM661Setting(struct SiS_Private *SiS_Pr, 426static void SiS_OEM661Setting(struct SiS_Private *SiS_Pr,
@@ -482,15 +455,13 @@ extern void SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short M
482extern void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth); 455extern void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth);
483extern unsigned short SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide); 456extern unsigned short SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide);
484extern unsigned short SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide); 457extern unsigned short SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide);
485#ifdef SIS300 458#ifdef CONFIG_FB_SIS_300
486extern void SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *tempbx, 459extern void SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *tempbx,
487 unsigned short *tempcl); 460 unsigned short *tempcl);
488extern unsigned short SiS_GetFIFOThresholdB300(unsigned short tempbx, unsigned short tempcl); 461extern unsigned short SiS_GetFIFOThresholdB300(unsigned short tempbx, unsigned short tempcl);
489extern unsigned short SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index); 462extern unsigned short SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index);
490#ifdef SIS_LINUX_KERNEL
491extern unsigned int sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg); 463extern unsigned int sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg);
492extern unsigned int sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg); 464extern unsigned int sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg);
493#endif 465#endif
494#endif
495 466
496#endif 467#endif
diff --git a/drivers/video/sis/initextlfb.c b/drivers/video/sis/initextlfb.c
index 99c04a4855d1..9dec64da4015 100644
--- a/drivers/video/sis/initextlfb.c
+++ b/drivers/video/sis/initextlfb.c
@@ -25,7 +25,6 @@
25 * Author: Thomas Winischhofer <thomas@winischhofer.net> 25 * Author: Thomas Winischhofer <thomas@winischhofer.net>
26 */ 26 */
27 27
28#include "osdef.h"
29#include "initdef.h" 28#include "initdef.h"
30#include "vgatypes.h" 29#include "vgatypes.h"
31#include "vstruct.h" 30#include "vstruct.h"
@@ -59,7 +58,7 @@ sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno,
59 58
60 if(rateindex > 0) rateindex--; 59 if(rateindex > 0) rateindex--;
61 60
62#ifdef SIS315H 61#ifdef CONFIG_FB_SIS_315
63 switch(ModeNo) { 62 switch(ModeNo) {
64 case 0x5a: ModeNo = 0x50; break; 63 case 0x5a: ModeNo = 0x50; break;
65 case 0x5b: ModeNo = 0x56; 64 case 0x5b: ModeNo = 0x56;
@@ -103,7 +102,7 @@ sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
103 102
104 if(rateindex > 0) rateindex--; 103 if(rateindex > 0) rateindex--;
105 104
106#ifdef SIS315H 105#ifdef CONFIG_FB_SIS_315
107 switch(ModeNo) { 106 switch(ModeNo) {
108 case 0x5a: ModeNo = 0x50; break; 107 case 0x5a: ModeNo = 0x50; break;
109 case 0x5b: ModeNo = 0x56; 108 case 0x5b: ModeNo = 0x56;
@@ -187,7 +186,7 @@ sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *ht
187 186
188 if(rateindex > 0) rateindex--; 187 if(rateindex > 0) rateindex--;
189 188
190#ifdef SIS315H 189#ifdef CONFIG_FB_SIS_315
191 switch(ModeNo) { 190 switch(ModeNo) {
192 case 0x5a: ModeNo = 0x50; break; 191 case 0x5a: ModeNo = 0x50; break;
193 case 0x5b: ModeNo = 0x56; 192 case 0x5b: ModeNo = 0x56;
diff --git a/drivers/video/sis/osdef.h b/drivers/video/sis/osdef.h
deleted file mode 100644
index 6ff8f988a1a7..000000000000
--- a/drivers/video/sis/osdef.h
+++ /dev/null
@@ -1,133 +0,0 @@
1/* $XFree86$ */
2/* $XdotOrg$ */
3/*
4 * OS depending defines
5 *
6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 *
8 * If distributed as part of the Linux kernel, the following license terms
9 * apply:
10 *
11 * * This program is free software; you can redistribute it and/or modify
12 * * it under the terms of the GNU General Public License as published by
13 * * the Free Software Foundation; either version 2 of the named License,
14 * * or any later version.
15 * *
16 * * This program is distributed in the hope that it will be useful,
17 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * * GNU General Public License for more details.
20 * *
21 * * You should have received a copy of the GNU General Public License
22 * * along with this program; if not, write to the Free Software
23 * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
24 *
25 * Otherwise, the following license terms apply:
26 *
27 * * Redistribution and use in source and binary forms, with or without
28 * * modification, are permitted provided that the following conditions
29 * * are met:
30 * * 1) Redistributions of source code must retain the above copyright
31 * * notice, this list of conditions and the following disclaimer.
32 * * 2) Redistributions in binary form must reproduce the above copyright
33 * * notice, this list of conditions and the following disclaimer in the
34 * * documentation and/or other materials provided with the distribution.
35 * * 3) The name of the author may not be used to endorse or promote products
36 * * derived from this software without specific prior written permission.
37 * *
38 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
41 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
42 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
47 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 * Author: Thomas Winischhofer <thomas@winischhofer.net>
50 * Silicon Integrated Systems, Inc. (used by permission)
51 *
52 */
53
54#ifndef _SIS_OSDEF_H_
55#define _SIS_OSDEF_H_
56
57/* The choices are: */
58#define SIS_LINUX_KERNEL /* Linux kernel framebuffer */
59#undef SIS_XORG_XF86 /* XFree86/X.org */
60
61#ifdef OutPortByte
62#undef OutPortByte
63#endif
64
65#ifdef OutPortWord
66#undef OutPortWord
67#endif
68
69#ifdef OutPortLong
70#undef OutPortLong
71#endif
72
73#ifdef InPortByte
74#undef InPortByte
75#endif
76
77#ifdef InPortWord
78#undef InPortWord
79#endif
80
81#ifdef InPortLong
82#undef InPortLong
83#endif
84
85/**********************************************************************/
86/* LINUX KERNEL */
87/**********************************************************************/
88
89#ifdef SIS_LINUX_KERNEL
90
91#ifdef CONFIG_FB_SIS_300
92#define SIS300
93#endif
94
95#ifdef CONFIG_FB_SIS_315
96#define SIS315H
97#endif
98
99#if !defined(SIS300) && !defined(SIS315H)
100#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set
101#warning sisfb will not work!
102#endif
103
104#define OutPortByte(p,v) outb((u8)(v),(SISIOADDRESS)(p))
105#define OutPortWord(p,v) outw((u16)(v),(SISIOADDRESS)(p))
106#define OutPortLong(p,v) outl((u32)(v),(SISIOADDRESS)(p))
107#define InPortByte(p) inb((SISIOADDRESS)(p))
108#define InPortWord(p) inw((SISIOADDRESS)(p))
109#define InPortLong(p) inl((SISIOADDRESS)(p))
110#define SiS_SetMemory(MemoryAddress,MemorySize,value) memset_io(MemoryAddress, value, MemorySize)
111
112#endif /* LINUX_KERNEL */
113
114/**********************************************************************/
115/* XFree86/X.org */
116/**********************************************************************/
117
118#ifdef SIS_XORG_XF86
119
120#define SIS300
121#define SIS315H
122
123#define OutPortByte(p,v) outSISREG((IOADDRESS)(p),(CARD8)(v))
124#define OutPortWord(p,v) outSISREGW((IOADDRESS)(p),(CARD16)(v))
125#define OutPortLong(p,v) outSISREGL((IOADDRESS)(p),(CARD32)(v))
126#define InPortByte(p) inSISREG((IOADDRESS)(p))
127#define InPortWord(p) inSISREGW((IOADDRESS)(p))
128#define InPortLong(p) inSISREGL((IOADDRESS)(p))
129#define SiS_SetMemory(MemoryAddress,MemorySize,value) memset(MemoryAddress, value, MemorySize)
130
131#endif /* XF86 */
132
133#endif /* _OSDEF_H_ */
diff --git a/drivers/video/sis/sis.h b/drivers/video/sis/sis.h
index 7c5710e3fb56..80d89d37c414 100644
--- a/drivers/video/sis/sis.h
+++ b/drivers/video/sis/sis.h
@@ -24,7 +24,6 @@
24#ifndef _SIS_H_ 24#ifndef _SIS_H_
25#define _SIS_H_ 25#define _SIS_H_
26 26
27#include "osdef.h"
28#include <video/sisfb.h> 27#include <video/sisfb.h>
29 28
30#include "vgatypes.h" 29#include "vgatypes.h"
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index b52f8e4ef1fd..7e3370f115b6 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -60,6 +60,11 @@
60#include "sis.h" 60#include "sis.h"
61#include "sis_main.h" 61#include "sis_main.h"
62 62
63#if !defined(CONFIG_FB_SIS_300) && !defined(CONFIG_FB_SIS_315)
64#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set
65#warning sisfb will not work!
66#endif
67
63static void sisfb_handle_command(struct sis_video_info *ivideo, 68static void sisfb_handle_command(struct sis_video_info *ivideo,
64 struct sisfb_cmd *sisfb_command); 69 struct sisfb_cmd *sisfb_command);
65 70
@@ -4114,14 +4119,6 @@ sisfb_find_rom(struct pci_dev *pdev)
4114 if(sisfb_check_rom(rom_base, ivideo)) { 4119 if(sisfb_check_rom(rom_base, ivideo)) {
4115 4120
4116 if((myrombase = vmalloc(65536))) { 4121 if((myrombase = vmalloc(65536))) {
4117
4118 /* Work around bug in pci/rom.c: Folks forgot to check
4119 * whether the size retrieved from the BIOS image eventually
4120 * is larger than the mapped size
4121 */
4122 if(pci_resource_len(pdev, PCI_ROM_RESOURCE) < romsize)
4123 romsize = pci_resource_len(pdev, PCI_ROM_RESOURCE);
4124
4125 memcpy_fromio(myrombase, rom_base, 4122 memcpy_fromio(myrombase, rom_base,
4126 (romsize > 65536) ? 65536 : romsize); 4123 (romsize > 65536) ? 65536 : romsize);
4127 } 4124 }
@@ -4155,23 +4152,6 @@ sisfb_find_rom(struct pci_dev *pdev)
4155 4152
4156 } 4153 }
4157 4154
4158#else
4159
4160 pci_read_config_dword(pdev, PCI_ROM_ADDRESS, &temp);
4161 pci_write_config_dword(pdev, PCI_ROM_ADDRESS,
4162 (ivideo->video_base & PCI_ROM_ADDRESS_MASK) | PCI_ROM_ADDRESS_ENABLE);
4163
4164 rom_base = ioremap(ivideo->video_base, 65536);
4165 if(rom_base) {
4166 if(sisfb_check_rom(rom_base, ivideo)) {
4167 if((myrombase = vmalloc(65536)))
4168 memcpy_fromio(myrombase, rom_base, 65536);
4169 }
4170 iounmap(rom_base);
4171 }
4172
4173 pci_write_config_dword(pdev, PCI_ROM_ADDRESS, temp);
4174
4175#endif 4155#endif
4176 4156
4177 return myrombase; 4157 return myrombase;
@@ -4181,6 +4161,9 @@ static void __devinit
4181sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize, 4161sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize,
4182 unsigned int min) 4162 unsigned int min)
4183{ 4163{
4164 if (*mapsize < (min << 20))
4165 return;
4166
4184 ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize)); 4167 ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize));
4185 4168
4186 if(!ivideo->video_vbase) { 4169 if(!ivideo->video_vbase) {
@@ -4514,7 +4497,7 @@ sisfb_post_sis300(struct pci_dev *pdev)
4514 } else { 4497 } else {
4515#endif 4498#endif
4516 /* Need to map max FB size for finding out about RAM size */ 4499 /* Need to map max FB size for finding out about RAM size */
4517 mapsize = 64 << 20; 4500 mapsize = ivideo->video_size;
4518 sisfb_post_map_vram(ivideo, &mapsize, 4); 4501 sisfb_post_map_vram(ivideo, &mapsize, 4);
4519 4502
4520 if(ivideo->video_vbase) { 4503 if(ivideo->video_vbase) {
@@ -4680,7 +4663,7 @@ sisfb_post_xgi_ramsize(struct sis_video_info *ivideo)
4680 orSISIDXREG(SISSR, 0x20, (0x80 | 0x04)); 4663 orSISIDXREG(SISSR, 0x20, (0x80 | 0x04));
4681 4664
4682 /* Need to map max FB size for finding out about RAM size */ 4665 /* Need to map max FB size for finding out about RAM size */
4683 mapsize = 256 << 20; 4666 mapsize = ivideo->video_size;
4684 sisfb_post_map_vram(ivideo, &mapsize, 32); 4667 sisfb_post_map_vram(ivideo, &mapsize, 32);
4685 4668
4686 if(!ivideo->video_vbase) { 4669 if(!ivideo->video_vbase) {
@@ -5936,6 +5919,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5936 } 5919 }
5937 5920
5938 ivideo->video_base = pci_resource_start(pdev, 0); 5921 ivideo->video_base = pci_resource_start(pdev, 0);
5922 ivideo->video_size = pci_resource_len(pdev, 0);
5939 ivideo->mmio_base = pci_resource_start(pdev, 1); 5923 ivideo->mmio_base = pci_resource_start(pdev, 1);
5940 ivideo->mmio_size = pci_resource_len(pdev, 1); 5924 ivideo->mmio_size = pci_resource_len(pdev, 1);
5941 ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30; 5925 ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30;
diff --git a/drivers/video/sis/vgatypes.h b/drivers/video/sis/vgatypes.h
index 81a22eaabfde..12c0dfaf2518 100644
--- a/drivers/video/sis/vgatypes.h
+++ b/drivers/video/sis/vgatypes.h
@@ -55,21 +55,10 @@
55 55
56#define SISIOMEMTYPE 56#define SISIOMEMTYPE
57 57
58#ifdef SIS_LINUX_KERNEL
59typedef unsigned long SISIOADDRESS; 58typedef unsigned long SISIOADDRESS;
60#include <linux/types.h> /* Need __iomem */ 59#include <linux/types.h> /* Need __iomem */
61#undef SISIOMEMTYPE 60#undef SISIOMEMTYPE
62#define SISIOMEMTYPE __iomem 61#define SISIOMEMTYPE __iomem
63#endif
64
65#ifdef SIS_XORG_XF86
66#if XF86_VERSION_CURRENT < XF86_VERSION_NUMERIC(4,2,0,0,0)
67typedef unsigned long IOADDRESS;
68typedef unsigned long SISIOADDRESS;
69#else
70typedef IOADDRESS SISIOADDRESS;
71#endif
72#endif
73 62
74typedef enum _SIS_CHIP_TYPE { 63typedef enum _SIS_CHIP_TYPE {
75 SIS_VGALegacy = 0, 64 SIS_VGALegacy = 0,
diff --git a/drivers/video/sis/vstruct.h b/drivers/video/sis/vstruct.h
index bef4aae388d0..ea94d214dcff 100644
--- a/drivers/video/sis/vstruct.h
+++ b/drivers/video/sis/vstruct.h
@@ -233,24 +233,15 @@ struct SiS_Private
233{ 233{
234 unsigned char ChipType; 234 unsigned char ChipType;
235 unsigned char ChipRevision; 235 unsigned char ChipRevision;
236#ifdef SIS_XORG_XF86
237 PCITAG PciTag;
238#endif
239#ifdef SIS_LINUX_KERNEL
240 void *ivideo; 236 void *ivideo;
241#endif
242 unsigned char *VirtualRomBase; 237 unsigned char *VirtualRomBase;
243 bool UseROM; 238 bool UseROM;
244#ifdef SIS_LINUX_KERNEL
245 unsigned char SISIOMEMTYPE *VideoMemoryAddress; 239 unsigned char SISIOMEMTYPE *VideoMemoryAddress;
246 unsigned int VideoMemorySize; 240 unsigned int VideoMemorySize;
247#endif
248 SISIOADDRESS IOAddress; 241 SISIOADDRESS IOAddress;
249 SISIOADDRESS IOAddress2; /* For dual chip XGI volari */ 242 SISIOADDRESS IOAddress2; /* For dual chip XGI volari */
250 243
251#ifdef SIS_LINUX_KERNEL
252 SISIOADDRESS RelIO; 244 SISIOADDRESS RelIO;
253#endif
254 SISIOADDRESS SiS_P3c4; 245 SISIOADDRESS SiS_P3c4;
255 SISIOADDRESS SiS_P3d4; 246 SISIOADDRESS SiS_P3d4;
256 SISIOADDRESS SiS_P3c0; 247 SISIOADDRESS SiS_P3c0;
@@ -280,9 +271,6 @@ struct SiS_Private
280 unsigned short SiS_IF_DEF_FSTN; 271 unsigned short SiS_IF_DEF_FSTN;
281 unsigned short SiS_SysFlags; 272 unsigned short SiS_SysFlags;
282 unsigned char SiS_VGAINFO; 273 unsigned char SiS_VGAINFO;
283#ifdef SIS_XORG_XF86
284 unsigned short SiS_CP1, SiS_CP2, SiS_CP3, SiS_CP4;
285#endif
286 bool SiS_UseROM; 274 bool SiS_UseROM;
287 bool SiS_ROMNew; 275 bool SiS_ROMNew;
288 bool SiS_XGIROM; 276 bool SiS_XGIROM;
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 3a43ebf83a49..efb35aa8309a 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -9,19 +9,19 @@ static ssize_t device_show(struct device *_d,
9 struct device_attribute *attr, char *buf) 9 struct device_attribute *attr, char *buf)
10{ 10{
11 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 11 struct virtio_device *dev = container_of(_d,struct virtio_device,dev);
12 return sprintf(buf, "%hu", dev->id.device); 12 return sprintf(buf, "0x%04x\n", dev->id.device);
13} 13}
14static ssize_t vendor_show(struct device *_d, 14static ssize_t vendor_show(struct device *_d,
15 struct device_attribute *attr, char *buf) 15 struct device_attribute *attr, char *buf)
16{ 16{
17 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 17 struct virtio_device *dev = container_of(_d,struct virtio_device,dev);
18 return sprintf(buf, "%hu", dev->id.vendor); 18 return sprintf(buf, "0x%04x\n", dev->id.vendor);
19} 19}
20static ssize_t status_show(struct device *_d, 20static ssize_t status_show(struct device *_d,
21 struct device_attribute *attr, char *buf) 21 struct device_attribute *attr, char *buf)
22{ 22{
23 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 23 struct virtio_device *dev = container_of(_d,struct virtio_device,dev);
24 return sprintf(buf, "0x%08x", dev->config->get_status(dev)); 24 return sprintf(buf, "0x%08x\n", dev->config->get_status(dev));
25} 25}
26static ssize_t modalias_show(struct device *_d, 26static ssize_t modalias_show(struct device *_d,
27 struct device_attribute *attr, char *buf) 27 struct device_attribute *attr, char *buf)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 1475ed6b575f..cc2f73e03475 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -230,9 +230,6 @@ add_head:
230 pr_debug("Added buffer head %i to %p\n", head, vq); 230 pr_debug("Added buffer head %i to %p\n", head, vq);
231 END_USE(vq); 231 END_USE(vq);
232 232
233 /* If we're indirect, we can fit many (assuming not OOM). */
234 if (vq->indirect)
235 return vq->num_free ? vq->vring.num : 0;
236 return vq->num_free; 233 return vq->num_free;
237} 234}
238EXPORT_SYMBOL_GPL(virtqueue_add_buf_gfp); 235EXPORT_SYMBOL_GPL(virtqueue_add_buf_gfp);
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 4a291045ebac..a5ad77ef4266 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -558,6 +558,9 @@ config IT8712F_WDT
558 This is the driver for the built-in watchdog timer on the IT8712F 558 This is the driver for the built-in watchdog timer on the IT8712F
559 Super I/0 chipset used on many motherboards. 559 Super I/0 chipset used on many motherboards.
560 560
561 If the driver does not work, then make sure that the game port in
562 the BIOS is enabled.
563
561 To compile this driver as a module, choose M here: the 564 To compile this driver as a module, choose M here: the
562 module will be called it8712f_wdt. 565 module will be called it8712f_wdt.
563 566
diff --git a/drivers/watchdog/bcm63xx_wdt.c b/drivers/watchdog/bcm63xx_wdt.c
index a1debc89356b..3c5045a206dd 100644
--- a/drivers/watchdog/bcm63xx_wdt.c
+++ b/drivers/watchdog/bcm63xx_wdt.c
@@ -18,7 +18,6 @@
18#include <linux/miscdevice.h> 18#include <linux/miscdevice.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/moduleparam.h> 20#include <linux/moduleparam.h>
21#include <linux/reboot.h>
22#include <linux/types.h> 21#include <linux/types.h>
23#include <linux/uaccess.h> 22#include <linux/uaccess.h>
24#include <linux/watchdog.h> 23#include <linux/watchdog.h>
@@ -220,14 +219,6 @@ static long bcm63xx_wdt_ioctl(struct file *file, unsigned int cmd,
220 } 219 }
221} 220}
222 221
223static int bcm63xx_wdt_notify_sys(struct notifier_block *this,
224 unsigned long code, void *unused)
225{
226 if (code == SYS_DOWN || code == SYS_HALT)
227 bcm63xx_wdt_pause();
228 return NOTIFY_DONE;
229}
230
231static const struct file_operations bcm63xx_wdt_fops = { 222static const struct file_operations bcm63xx_wdt_fops = {
232 .owner = THIS_MODULE, 223 .owner = THIS_MODULE,
233 .llseek = no_llseek, 224 .llseek = no_llseek,
@@ -243,12 +234,8 @@ static struct miscdevice bcm63xx_wdt_miscdev = {
243 .fops = &bcm63xx_wdt_fops, 234 .fops = &bcm63xx_wdt_fops,
244}; 235};
245 236
246static struct notifier_block bcm63xx_wdt_notifier = {
247 .notifier_call = bcm63xx_wdt_notify_sys,
248};
249 237
250 238static int __devinit bcm63xx_wdt_probe(struct platform_device *pdev)
251static int bcm63xx_wdt_probe(struct platform_device *pdev)
252{ 239{
253 int ret; 240 int ret;
254 struct resource *r; 241 struct resource *r;
@@ -280,16 +267,10 @@ static int bcm63xx_wdt_probe(struct platform_device *pdev)
280 wdt_time); 267 wdt_time);
281 } 268 }
282 269
283 ret = register_reboot_notifier(&bcm63xx_wdt_notifier);
284 if (ret) {
285 dev_err(&pdev->dev, "failed to register reboot_notifier\n");
286 goto unregister_timer;
287 }
288
289 ret = misc_register(&bcm63xx_wdt_miscdev); 270 ret = misc_register(&bcm63xx_wdt_miscdev);
290 if (ret < 0) { 271 if (ret < 0) {
291 dev_err(&pdev->dev, "failed to register watchdog device\n"); 272 dev_err(&pdev->dev, "failed to register watchdog device\n");
292 goto unregister_reboot_notifier; 273 goto unregister_timer;
293 } 274 }
294 275
295 dev_info(&pdev->dev, " started, timer margin: %d sec\n", 276 dev_info(&pdev->dev, " started, timer margin: %d sec\n",
@@ -297,8 +278,6 @@ static int bcm63xx_wdt_probe(struct platform_device *pdev)
297 278
298 return 0; 279 return 0;
299 280
300unregister_reboot_notifier:
301 unregister_reboot_notifier(&bcm63xx_wdt_notifier);
302unregister_timer: 281unregister_timer:
303 bcm63xx_timer_unregister(TIMER_WDT_ID); 282 bcm63xx_timer_unregister(TIMER_WDT_ID);
304unmap: 283unmap:
@@ -306,25 +285,28 @@ unmap:
306 return ret; 285 return ret;
307} 286}
308 287
309static int bcm63xx_wdt_remove(struct platform_device *pdev) 288static int __devexit bcm63xx_wdt_remove(struct platform_device *pdev)
310{ 289{
311 if (!nowayout) 290 if (!nowayout)
312 bcm63xx_wdt_pause(); 291 bcm63xx_wdt_pause();
313 292
314 misc_deregister(&bcm63xx_wdt_miscdev); 293 misc_deregister(&bcm63xx_wdt_miscdev);
315
316 iounmap(bcm63xx_wdt_device.regs);
317
318 unregister_reboot_notifier(&bcm63xx_wdt_notifier);
319 bcm63xx_timer_unregister(TIMER_WDT_ID); 294 bcm63xx_timer_unregister(TIMER_WDT_ID);
320 295 iounmap(bcm63xx_wdt_device.regs);
321 return 0; 296 return 0;
322} 297}
323 298
299static void bcm63xx_wdt_shutdown(struct platform_device *pdev)
300{
301 bcm63xx_wdt_pause();
302}
303
324static struct platform_driver bcm63xx_wdt = { 304static struct platform_driver bcm63xx_wdt = {
325 .probe = bcm63xx_wdt_probe, 305 .probe = bcm63xx_wdt_probe,
326 .remove = bcm63xx_wdt_remove, 306 .remove = __devexit_p(bcm63xx_wdt_remove),
307 .shutdown = bcm63xx_wdt_shutdown,
327 .driver = { 308 .driver = {
309 .owner = THIS_MODULE,
328 .name = "bcm63xx-wdt", 310 .name = "bcm63xx-wdt",
329 } 311 }
330}; 312};
diff --git a/drivers/watchdog/gef_wdt.c b/drivers/watchdog/gef_wdt.c
index 9c21d19043a6..f6bd6f10fcec 100644
--- a/drivers/watchdog/gef_wdt.c
+++ b/drivers/watchdog/gef_wdt.c
@@ -30,6 +30,7 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/miscdevice.h> 31#include <linux/miscdevice.h>
32#include <linux/watchdog.h> 32#include <linux/watchdog.h>
33#include <linux/fs.h>
33#include <linux/of.h> 34#include <linux/of.h>
34#include <linux/of_platform.h> 35#include <linux/of_platform.h>
35#include <linux/io.h> 36#include <linux/io.h>
diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
index f7e90fe47b71..b8838d2c67a6 100644
--- a/drivers/watchdog/iTCO_wdt.c
+++ b/drivers/watchdog/iTCO_wdt.c
@@ -32,6 +32,7 @@
32 * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH) 32 * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH)
33 * document number 320066-003, 320257-008: EP80597 (IICH) 33 * document number 320066-003, 320257-008: EP80597 (IICH)
34 * document number TBD : Cougar Point (CPT) 34 * document number TBD : Cougar Point (CPT)
35 * document number TBD : Patsburg (PBG)
35 */ 36 */
36 37
37/* 38/*
@@ -146,7 +147,8 @@ enum iTCO_chipsets {
146 TCO_CPT29, /* Cougar Point */ 147 TCO_CPT29, /* Cougar Point */
147 TCO_CPT30, /* Cougar Point */ 148 TCO_CPT30, /* Cougar Point */
148 TCO_CPT31, /* Cougar Point */ 149 TCO_CPT31, /* Cougar Point */
149 TCO_PBG, /* Patsburg */ 150 TCO_PBG1, /* Patsburg */
151 TCO_PBG2, /* Patsburg */
150}; 152};
151 153
152static struct { 154static struct {
@@ -235,6 +237,7 @@ static struct {
235 {"Cougar Point", 2}, 237 {"Cougar Point", 2},
236 {"Cougar Point", 2}, 238 {"Cougar Point", 2},
237 {"Patsburg", 2}, 239 {"Patsburg", 2},
240 {"Patsburg", 2},
238 {NULL, 0} 241 {NULL, 0}
239}; 242};
240 243
@@ -350,7 +353,8 @@ static struct pci_device_id iTCO_wdt_pci_tbl[] = {
350 { ITCO_PCI_DEVICE(0x1c5d, TCO_CPT29)}, 353 { ITCO_PCI_DEVICE(0x1c5d, TCO_CPT29)},
351 { ITCO_PCI_DEVICE(0x1c5e, TCO_CPT30)}, 354 { ITCO_PCI_DEVICE(0x1c5e, TCO_CPT30)},
352 { ITCO_PCI_DEVICE(0x1c5f, TCO_CPT31)}, 355 { ITCO_PCI_DEVICE(0x1c5f, TCO_CPT31)},
353 { ITCO_PCI_DEVICE(0x1d40, TCO_PBG)}, 356 { ITCO_PCI_DEVICE(0x1d40, TCO_PBG1)},
357 { ITCO_PCI_DEVICE(0x1d41, TCO_PBG2)},
354 { 0, }, /* End of list */ 358 { 0, }, /* End of list */
355}; 359};
356MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl); 360MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl);
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index eb8a78d77d9d..533a199e7a3f 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -8,9 +8,12 @@ obj-$(CONFIG_BLOCK) += biomerge.o
8obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o 8obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o
9obj-$(CONFIG_XEN_XENCOMM) += xencomm.o 9obj-$(CONFIG_XEN_XENCOMM) += xencomm.o
10obj-$(CONFIG_XEN_BALLOON) += balloon.o 10obj-$(CONFIG_XEN_BALLOON) += balloon.o
11obj-$(CONFIG_XEN_DEV_EVTCHN) += evtchn.o 11obj-$(CONFIG_XEN_DEV_EVTCHN) += xen-evtchn.o
12obj-$(CONFIG_XENFS) += xenfs/ 12obj-$(CONFIG_XENFS) += xenfs/
13obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o 13obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o
14obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o 14obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o
15obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o 15obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o
16obj-$(CONFIG_XEN_DOM0) += pci.o 16obj-$(CONFIG_XEN_DOM0) += pci.o
17
18xen-evtchn-y := evtchn.o
19
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 500290b150bb..43f9f02c7db0 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -50,6 +50,7 @@
50#include <asm/pgtable.h> 50#include <asm/pgtable.h>
51#include <asm/uaccess.h> 51#include <asm/uaccess.h>
52#include <asm/tlb.h> 52#include <asm/tlb.h>
53#include <asm/e820.h>
53 54
54#include <asm/xen/hypervisor.h> 55#include <asm/xen/hypervisor.h>
55#include <asm/xen/hypercall.h> 56#include <asm/xen/hypercall.h>
@@ -119,7 +120,7 @@ static void scrub_page(struct page *page)
119} 120}
120 121
121/* balloon_append: add the given page to the balloon. */ 122/* balloon_append: add the given page to the balloon. */
122static void balloon_append(struct page *page) 123static void __balloon_append(struct page *page)
123{ 124{
124 /* Lowmem is re-populated first, so highmem pages go at list tail. */ 125 /* Lowmem is re-populated first, so highmem pages go at list tail. */
125 if (PageHighMem(page)) { 126 if (PageHighMem(page)) {
@@ -130,7 +131,11 @@ static void balloon_append(struct page *page)
130 list_add(&page->lru, &ballooned_pages); 131 list_add(&page->lru, &ballooned_pages);
131 balloon_stats.balloon_low++; 132 balloon_stats.balloon_low++;
132 } 133 }
134}
133 135
136static void balloon_append(struct page *page)
137{
138 __balloon_append(page);
134 totalram_pages--; 139 totalram_pages--;
135} 140}
136 141
@@ -191,7 +196,7 @@ static unsigned long current_target(void)
191 196
192static int increase_reservation(unsigned long nr_pages) 197static int increase_reservation(unsigned long nr_pages)
193{ 198{
194 unsigned long pfn, i, flags; 199 unsigned long pfn, i;
195 struct page *page; 200 struct page *page;
196 long rc; 201 long rc;
197 struct xen_memory_reservation reservation = { 202 struct xen_memory_reservation reservation = {
@@ -203,8 +208,6 @@ static int increase_reservation(unsigned long nr_pages)
203 if (nr_pages > ARRAY_SIZE(frame_list)) 208 if (nr_pages > ARRAY_SIZE(frame_list))
204 nr_pages = ARRAY_SIZE(frame_list); 209 nr_pages = ARRAY_SIZE(frame_list);
205 210
206 spin_lock_irqsave(&xen_reservation_lock, flags);
207
208 page = balloon_first_page(); 211 page = balloon_first_page();
209 for (i = 0; i < nr_pages; i++) { 212 for (i = 0; i < nr_pages; i++) {
210 BUG_ON(page == NULL); 213 BUG_ON(page == NULL);
@@ -247,14 +250,12 @@ static int increase_reservation(unsigned long nr_pages)
247 balloon_stats.current_pages += rc; 250 balloon_stats.current_pages += rc;
248 251
249 out: 252 out:
250 spin_unlock_irqrestore(&xen_reservation_lock, flags);
251
252 return rc < 0 ? rc : rc != nr_pages; 253 return rc < 0 ? rc : rc != nr_pages;
253} 254}
254 255
255static int decrease_reservation(unsigned long nr_pages) 256static int decrease_reservation(unsigned long nr_pages)
256{ 257{
257 unsigned long pfn, i, flags; 258 unsigned long pfn, i;
258 struct page *page; 259 struct page *page;
259 int need_sleep = 0; 260 int need_sleep = 0;
260 int ret; 261 int ret;
@@ -292,8 +293,6 @@ static int decrease_reservation(unsigned long nr_pages)
292 kmap_flush_unused(); 293 kmap_flush_unused();
293 flush_tlb_all(); 294 flush_tlb_all();
294 295
295 spin_lock_irqsave(&xen_reservation_lock, flags);
296
297 /* No more mappings: invalidate P2M and add to balloon. */ 296 /* No more mappings: invalidate P2M and add to balloon. */
298 for (i = 0; i < nr_pages; i++) { 297 for (i = 0; i < nr_pages; i++) {
299 pfn = mfn_to_pfn(frame_list[i]); 298 pfn = mfn_to_pfn(frame_list[i]);
@@ -308,8 +307,6 @@ static int decrease_reservation(unsigned long nr_pages)
308 307
309 balloon_stats.current_pages -= nr_pages; 308 balloon_stats.current_pages -= nr_pages;
310 309
311 spin_unlock_irqrestore(&xen_reservation_lock, flags);
312
313 return need_sleep; 310 return need_sleep;
314} 311}
315 312
@@ -395,7 +392,7 @@ static struct notifier_block xenstore_notifier;
395 392
396static int __init balloon_init(void) 393static int __init balloon_init(void)
397{ 394{
398 unsigned long pfn; 395 unsigned long pfn, extra_pfn_end;
399 struct page *page; 396 struct page *page;
400 397
401 if (!xen_pv_domain()) 398 if (!xen_pv_domain())
@@ -415,11 +412,24 @@ static int __init balloon_init(void)
415 412
416 register_balloon(&balloon_sysdev); 413 register_balloon(&balloon_sysdev);
417 414
418 /* Initialise the balloon with excess memory space. */ 415 /*
419 for (pfn = xen_start_info->nr_pages; pfn < max_pfn; pfn++) { 416 * Initialise the balloon with excess memory space. We need
417 * to make sure we don't add memory which doesn't exist or
418 * logically exist. The E820 map can be trimmed to be smaller
419 * than the amount of physical memory due to the mem= command
420 * line parameter. And if this is a 32-bit non-HIGHMEM kernel
421 * on a system with memory which requires highmem to access,
422 * don't try to use it.
423 */
424 extra_pfn_end = min(min(max_pfn, e820_end_of_ram_pfn()),
425 (unsigned long)PFN_DOWN(xen_extra_mem_start + xen_extra_mem_size));
426 for (pfn = PFN_UP(xen_extra_mem_start);
427 pfn < extra_pfn_end;
428 pfn++) {
420 page = pfn_to_page(pfn); 429 page = pfn_to_page(pfn);
421 if (!PageReserved(page)) 430 /* totalram_pages doesn't include the boot-time
422 balloon_append(page); 431 balloon extension, so don't subtract from it. */
432 __balloon_append(page);
423 } 433 }
424 434
425 target_watch.callback = watch_target; 435 target_watch.callback = watch_target;
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index 97612f548a8e..31af0ac31a98 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -105,7 +105,6 @@ struct irq_info
105 105
106static struct irq_info *irq_info; 106static struct irq_info *irq_info;
107static int *pirq_to_irq; 107static int *pirq_to_irq;
108static int nr_pirqs;
109 108
110static int *evtchn_to_irq; 109static int *evtchn_to_irq;
111struct cpu_evtchn_s { 110struct cpu_evtchn_s {
@@ -278,17 +277,17 @@ static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu)
278 cpumask_copy(irq_to_desc(irq)->affinity, cpumask_of(cpu)); 277 cpumask_copy(irq_to_desc(irq)->affinity, cpumask_of(cpu));
279#endif 278#endif
280 279
281 __clear_bit(chn, cpu_evtchn_mask(cpu_from_irq(irq))); 280 clear_bit(chn, cpu_evtchn_mask(cpu_from_irq(irq)));
282 __set_bit(chn, cpu_evtchn_mask(cpu)); 281 set_bit(chn, cpu_evtchn_mask(cpu));
283 282
284 irq_info[irq].cpu = cpu; 283 irq_info[irq].cpu = cpu;
285} 284}
286 285
287static void init_evtchn_cpu_bindings(void) 286static void init_evtchn_cpu_bindings(void)
288{ 287{
288 int i;
289#ifdef CONFIG_SMP 289#ifdef CONFIG_SMP
290 struct irq_desc *desc; 290 struct irq_desc *desc;
291 int i;
292 291
293 /* By default all event channels notify CPU#0. */ 292 /* By default all event channels notify CPU#0. */
294 for_each_irq_desc(i, desc) { 293 for_each_irq_desc(i, desc) {
@@ -296,7 +295,10 @@ static void init_evtchn_cpu_bindings(void)
296 } 295 }
297#endif 296#endif
298 297
299 memset(cpu_evtchn_mask(0), ~0, sizeof(struct cpu_evtchn_s)); 298 for_each_possible_cpu(i)
299 memset(cpu_evtchn_mask(i),
300 (i == 0) ? ~0 : 0, sizeof(struct cpu_evtchn_s));
301
300} 302}
301 303
302static inline void clear_evtchn(int port) 304static inline void clear_evtchn(int port)
@@ -382,12 +384,17 @@ static int get_nr_hw_irqs(void)
382 return ret; 384 return ret;
383} 385}
384 386
385/* callers of this function should make sure that PHYSDEVOP_get_nr_pirqs 387static int find_unbound_pirq(int type)
386 * succeeded otherwise nr_pirqs won't hold the right value */
387static int find_unbound_pirq(void)
388{ 388{
389 int i; 389 int rc, i;
390 for (i = nr_pirqs-1; i >= 0; i--) { 390 struct physdev_get_free_pirq op_get_free_pirq;
391 op_get_free_pirq.type = type;
392
393 rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_free_pirq, &op_get_free_pirq);
394 if (!rc)
395 return op_get_free_pirq.pirq;
396
397 for (i = 0; i < nr_irqs; i++) {
391 if (pirq_to_irq[i] < 0) 398 if (pirq_to_irq[i] < 0)
392 return i; 399 return i;
393 } 400 }
@@ -420,7 +427,7 @@ static int find_unbound_irq(void)
420 if (irq == start) 427 if (irq == start)
421 goto no_irqs; 428 goto no_irqs;
422 429
423 res = irq_alloc_desc_at(irq, 0); 430 res = irq_alloc_desc_at(irq, -1);
424 431
425 if (WARN_ON(res != irq)) 432 if (WARN_ON(res != irq))
426 return -1; 433 return -1;
@@ -608,10 +615,10 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name)
608 615
609 spin_lock(&irq_mapping_update_lock); 616 spin_lock(&irq_mapping_update_lock);
610 617
611 if ((pirq > nr_pirqs) || (gsi > nr_irqs)) { 618 if ((pirq > nr_irqs) || (gsi > nr_irqs)) {
612 printk(KERN_WARNING "xen_map_pirq_gsi: %s %s is incorrect!\n", 619 printk(KERN_WARNING "xen_map_pirq_gsi: %s %s is incorrect!\n",
613 pirq > nr_pirqs ? "nr_pirqs" :"", 620 pirq > nr_irqs ? "pirq" :"",
614 gsi > nr_irqs ? "nr_irqs" : ""); 621 gsi > nr_irqs ? "gsi" : "");
615 goto out; 622 goto out;
616 } 623 }
617 624
@@ -627,7 +634,7 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name)
627 if (identity_mapped_irq(gsi) || (!xen_initial_domain() && 634 if (identity_mapped_irq(gsi) || (!xen_initial_domain() &&
628 xen_pv_domain())) { 635 xen_pv_domain())) {
629 irq = gsi; 636 irq = gsi;
630 irq_alloc_desc_at(irq, 0); 637 irq_alloc_desc_at(irq, -1);
631 } else 638 } else
632 irq = find_unbound_irq(); 639 irq = find_unbound_irq();
633 640
@@ -661,17 +668,21 @@ out:
661#include <linux/msi.h> 668#include <linux/msi.h>
662#include "../pci/msi.h" 669#include "../pci/msi.h"
663 670
664void xen_allocate_pirq_msi(char *name, int *irq, int *pirq) 671void xen_allocate_pirq_msi(char *name, int *irq, int *pirq, int alloc)
665{ 672{
666 spin_lock(&irq_mapping_update_lock); 673 spin_lock(&irq_mapping_update_lock);
667 674
668 *irq = find_unbound_irq(); 675 if (alloc & XEN_ALLOC_IRQ) {
669 if (*irq == -1) 676 *irq = find_unbound_irq();
670 goto out; 677 if (*irq == -1)
678 goto out;
679 }
671 680
672 *pirq = find_unbound_pirq(); 681 if (alloc & XEN_ALLOC_PIRQ) {
673 if (*pirq == -1) 682 *pirq = find_unbound_pirq(MAP_PIRQ_TYPE_MSI);
674 goto out; 683 if (*pirq == -1)
684 goto out;
685 }
675 686
676 set_irq_chip_and_handler_name(*irq, &xen_pirq_chip, 687 set_irq_chip_and_handler_name(*irq, &xen_pirq_chip,
677 handle_level_irq, name); 688 handle_level_irq, name);
@@ -752,13 +763,14 @@ int xen_destroy_irq(int irq)
752 goto out; 763 goto out;
753 764
754 if (xen_initial_domain()) { 765 if (xen_initial_domain()) {
755 unmap_irq.pirq = info->u.pirq.gsi; 766 unmap_irq.pirq = info->u.pirq.pirq;
756 unmap_irq.domid = DOMID_SELF; 767 unmap_irq.domid = DOMID_SELF;
757 rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq); 768 rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq);
758 if (rc) { 769 if (rc) {
759 printk(KERN_WARNING "unmap irq failed %d\n", rc); 770 printk(KERN_WARNING "unmap irq failed %d\n", rc);
760 goto out; 771 goto out;
761 } 772 }
773 pirq_to_irq[info->u.pirq.pirq] = -1;
762 } 774 }
763 irq_info[irq] = mk_unbound_info(); 775 irq_info[irq] = mk_unbound_info();
764 776
@@ -779,6 +791,11 @@ int xen_gsi_from_irq(unsigned irq)
779 return gsi_from_irq(irq); 791 return gsi_from_irq(irq);
780} 792}
781 793
794int xen_irq_from_pirq(unsigned pirq)
795{
796 return pirq_to_irq[pirq];
797}
798
782int bind_evtchn_to_irq(unsigned int evtchn) 799int bind_evtchn_to_irq(unsigned int evtchn)
783{ 800{
784 int irq; 801 int irq;
@@ -1276,6 +1293,42 @@ static int retrigger_dynirq(unsigned int irq)
1276 return ret; 1293 return ret;
1277} 1294}
1278 1295
1296static void restore_cpu_pirqs(void)
1297{
1298 int pirq, rc, irq, gsi;
1299 struct physdev_map_pirq map_irq;
1300
1301 for (pirq = 0; pirq < nr_irqs; pirq++) {
1302 irq = pirq_to_irq[pirq];
1303 if (irq == -1)
1304 continue;
1305
1306 /* save/restore of PT devices doesn't work, so at this point the
1307 * only devices present are GSI based emulated devices */
1308 gsi = gsi_from_irq(irq);
1309 if (!gsi)
1310 continue;
1311
1312 map_irq.domid = DOMID_SELF;
1313 map_irq.type = MAP_PIRQ_TYPE_GSI;
1314 map_irq.index = gsi;
1315 map_irq.pirq = pirq;
1316
1317 rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
1318 if (rc) {
1319 printk(KERN_WARNING "xen map irq failed gsi=%d irq=%d pirq=%d rc=%d\n",
1320 gsi, irq, pirq, rc);
1321 irq_info[irq] = mk_unbound_info();
1322 pirq_to_irq[pirq] = -1;
1323 continue;
1324 }
1325
1326 printk(KERN_DEBUG "xen: --> irq=%d, pirq=%d\n", irq, map_irq.pirq);
1327
1328 startup_pirq(irq);
1329 }
1330}
1331
1279static void restore_cpu_virqs(unsigned int cpu) 1332static void restore_cpu_virqs(unsigned int cpu)
1280{ 1333{
1281 struct evtchn_bind_virq bind_virq; 1334 struct evtchn_bind_virq bind_virq;
@@ -1299,9 +1352,6 @@ static void restore_cpu_virqs(unsigned int cpu)
1299 evtchn_to_irq[evtchn] = irq; 1352 evtchn_to_irq[evtchn] = irq;
1300 irq_info[irq] = mk_virq_info(evtchn, virq); 1353 irq_info[irq] = mk_virq_info(evtchn, virq);
1301 bind_evtchn_to_cpu(evtchn, cpu); 1354 bind_evtchn_to_cpu(evtchn, cpu);
1302
1303 /* Ready for use. */
1304 unmask_evtchn(evtchn);
1305 } 1355 }
1306} 1356}
1307 1357
@@ -1327,10 +1377,6 @@ static void restore_cpu_ipis(unsigned int cpu)
1327 evtchn_to_irq[evtchn] = irq; 1377 evtchn_to_irq[evtchn] = irq;
1328 irq_info[irq] = mk_ipi_info(evtchn, ipi); 1378 irq_info[irq] = mk_ipi_info(evtchn, ipi);
1329 bind_evtchn_to_cpu(evtchn, cpu); 1379 bind_evtchn_to_cpu(evtchn, cpu);
1330
1331 /* Ready for use. */
1332 unmask_evtchn(evtchn);
1333
1334 } 1380 }
1335} 1381}
1336 1382
@@ -1390,6 +1436,7 @@ void xen_poll_irq(int irq)
1390void xen_irq_resume(void) 1436void xen_irq_resume(void)
1391{ 1437{
1392 unsigned int cpu, irq, evtchn; 1438 unsigned int cpu, irq, evtchn;
1439 struct irq_desc *desc;
1393 1440
1394 init_evtchn_cpu_bindings(); 1441 init_evtchn_cpu_bindings();
1395 1442
@@ -1408,6 +1455,25 @@ void xen_irq_resume(void)
1408 restore_cpu_virqs(cpu); 1455 restore_cpu_virqs(cpu);
1409 restore_cpu_ipis(cpu); 1456 restore_cpu_ipis(cpu);
1410 } 1457 }
1458
1459 /*
1460 * Unmask any IRQF_NO_SUSPEND IRQs which are enabled. These
1461 * are not handled by the IRQ core.
1462 */
1463 for_each_irq_desc(irq, desc) {
1464 if (!desc->action || !(desc->action->flags & IRQF_NO_SUSPEND))
1465 continue;
1466 if (desc->status & IRQ_DISABLED)
1467 continue;
1468
1469 evtchn = evtchn_from_irq(irq);
1470 if (evtchn == -1)
1471 continue;
1472
1473 unmask_evtchn(evtchn);
1474 }
1475
1476 restore_cpu_pirqs();
1411} 1477}
1412 1478
1413static struct irq_chip xen_dynamic_chip __read_mostly = { 1479static struct irq_chip xen_dynamic_chip __read_mostly = {
@@ -1492,26 +1558,17 @@ void xen_callback_vector(void) {}
1492 1558
1493void __init xen_init_IRQ(void) 1559void __init xen_init_IRQ(void)
1494{ 1560{
1495 int i, rc; 1561 int i;
1496 struct physdev_nr_pirqs op_nr_pirqs;
1497 1562
1498 cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s), 1563 cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s),
1499 GFP_KERNEL); 1564 GFP_KERNEL);
1500 irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL); 1565 irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL);
1501 1566
1502 rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_nr_pirqs, &op_nr_pirqs); 1567 /* We are using nr_irqs as the maximum number of pirq available but
1503 if (rc < 0) { 1568 * that number is actually chosen by Xen and we don't know exactly
1504 nr_pirqs = nr_irqs; 1569 * what it is. Be careful choosing high pirq numbers. */
1505 if (rc != -ENOSYS) 1570 pirq_to_irq = kcalloc(nr_irqs, sizeof(*pirq_to_irq), GFP_KERNEL);
1506 printk(KERN_WARNING "PHYSDEVOP_get_nr_pirqs returned rc=%d\n", rc); 1571 for (i = 0; i < nr_irqs; i++)
1507 } else {
1508 if (xen_pv_domain() && !xen_initial_domain())
1509 nr_pirqs = max((int)op_nr_pirqs.nr_pirqs, nr_irqs);
1510 else
1511 nr_pirqs = op_nr_pirqs.nr_pirqs;
1512 }
1513 pirq_to_irq = kcalloc(nr_pirqs, sizeof(*pirq_to_irq), GFP_KERNEL);
1514 for (i = 0; i < nr_pirqs; i++)
1515 pirq_to_irq[i] = -1; 1572 pirq_to_irq[i] = -1;
1516 1573
1517 evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq), 1574 evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq),
diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c
index fec6ba3c08a8..ef11daf0cafe 100644
--- a/drivers/xen/evtchn.c
+++ b/drivers/xen/evtchn.c
@@ -69,20 +69,51 @@ struct per_user_data {
69 const char *name; 69 const char *name;
70}; 70};
71 71
72/* Who's bound to each port? */ 72/*
73static struct per_user_data *port_user[NR_EVENT_CHANNELS]; 73 * Who's bound to each port? This is logically an array of struct
74 * per_user_data *, but we encode the current enabled-state in bit 0.
75 */
76static unsigned long *port_user;
74static DEFINE_SPINLOCK(port_user_lock); /* protects port_user[] and ring_prod */ 77static DEFINE_SPINLOCK(port_user_lock); /* protects port_user[] and ring_prod */
75 78
76irqreturn_t evtchn_interrupt(int irq, void *data) 79static inline struct per_user_data *get_port_user(unsigned port)
80{
81 return (struct per_user_data *)(port_user[port] & ~1);
82}
83
84static inline void set_port_user(unsigned port, struct per_user_data *u)
85{
86 port_user[port] = (unsigned long)u;
87}
88
89static inline bool get_port_enabled(unsigned port)
90{
91 return port_user[port] & 1;
92}
93
94static inline void set_port_enabled(unsigned port, bool enabled)
95{
96 if (enabled)
97 port_user[port] |= 1;
98 else
99 port_user[port] &= ~1;
100}
101
102static irqreturn_t evtchn_interrupt(int irq, void *data)
77{ 103{
78 unsigned int port = (unsigned long)data; 104 unsigned int port = (unsigned long)data;
79 struct per_user_data *u; 105 struct per_user_data *u;
80 106
81 spin_lock(&port_user_lock); 107 spin_lock(&port_user_lock);
82 108
83 u = port_user[port]; 109 u = get_port_user(port);
110
111 WARN(!get_port_enabled(port),
112 "Interrupt for port %d, but apparently not enabled; per-user %p\n",
113 port, u);
84 114
85 disable_irq_nosync(irq); 115 disable_irq_nosync(irq);
116 set_port_enabled(port, false);
86 117
87 if ((u->ring_prod - u->ring_cons) < EVTCHN_RING_SIZE) { 118 if ((u->ring_prod - u->ring_cons) < EVTCHN_RING_SIZE) {
88 u->ring[EVTCHN_RING_MASK(u->ring_prod)] = port; 119 u->ring[EVTCHN_RING_MASK(u->ring_prod)] = port;
@@ -92,9 +123,8 @@ irqreturn_t evtchn_interrupt(int irq, void *data)
92 kill_fasync(&u->evtchn_async_queue, 123 kill_fasync(&u->evtchn_async_queue,
93 SIGIO, POLL_IN); 124 SIGIO, POLL_IN);
94 } 125 }
95 } else { 126 } else
96 u->ring_overflow = 1; 127 u->ring_overflow = 1;
97 }
98 128
99 spin_unlock(&port_user_lock); 129 spin_unlock(&port_user_lock);
100 130
@@ -198,9 +228,18 @@ static ssize_t evtchn_write(struct file *file, const char __user *buf,
198 goto out; 228 goto out;
199 229
200 spin_lock_irq(&port_user_lock); 230 spin_lock_irq(&port_user_lock);
201 for (i = 0; i < (count/sizeof(evtchn_port_t)); i++) 231
202 if ((kbuf[i] < NR_EVENT_CHANNELS) && (port_user[kbuf[i]] == u)) 232 for (i = 0; i < (count/sizeof(evtchn_port_t)); i++) {
203 enable_irq(irq_from_evtchn(kbuf[i])); 233 unsigned port = kbuf[i];
234
235 if (port < NR_EVENT_CHANNELS &&
236 get_port_user(port) == u &&
237 !get_port_enabled(port)) {
238 set_port_enabled(port, true);
239 enable_irq(irq_from_evtchn(port));
240 }
241 }
242
204 spin_unlock_irq(&port_user_lock); 243 spin_unlock_irq(&port_user_lock);
205 244
206 rc = count; 245 rc = count;
@@ -222,8 +261,9 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)
222 * interrupt handler yet, and our caller has already 261 * interrupt handler yet, and our caller has already
223 * serialized bind operations.) 262 * serialized bind operations.)
224 */ 263 */
225 BUG_ON(port_user[port] != NULL); 264 BUG_ON(get_port_user(port) != NULL);
226 port_user[port] = u; 265 set_port_user(port, u);
266 set_port_enabled(port, true); /* start enabled */
227 267
228 rc = bind_evtchn_to_irqhandler(port, evtchn_interrupt, IRQF_DISABLED, 268 rc = bind_evtchn_to_irqhandler(port, evtchn_interrupt, IRQF_DISABLED,
229 u->name, (void *)(unsigned long)port); 269 u->name, (void *)(unsigned long)port);
@@ -239,10 +279,7 @@ static void evtchn_unbind_from_user(struct per_user_data *u, int port)
239 279
240 unbind_from_irqhandler(irq, (void *)(unsigned long)port); 280 unbind_from_irqhandler(irq, (void *)(unsigned long)port);
241 281
242 /* make sure we unbind the irq handler before clearing the port */ 282 set_port_user(port, NULL);
243 barrier();
244
245 port_user[port] = NULL;
246} 283}
247 284
248static long evtchn_ioctl(struct file *file, 285static long evtchn_ioctl(struct file *file,
@@ -333,15 +370,17 @@ static long evtchn_ioctl(struct file *file,
333 spin_lock_irq(&port_user_lock); 370 spin_lock_irq(&port_user_lock);
334 371
335 rc = -ENOTCONN; 372 rc = -ENOTCONN;
336 if (port_user[unbind.port] != u) { 373 if (get_port_user(unbind.port) != u) {
337 spin_unlock_irq(&port_user_lock); 374 spin_unlock_irq(&port_user_lock);
338 break; 375 break;
339 } 376 }
340 377
341 evtchn_unbind_from_user(u, unbind.port); 378 disable_irq(irq_from_evtchn(unbind.port));
342 379
343 spin_unlock_irq(&port_user_lock); 380 spin_unlock_irq(&port_user_lock);
344 381
382 evtchn_unbind_from_user(u, unbind.port);
383
345 rc = 0; 384 rc = 0;
346 break; 385 break;
347 } 386 }
@@ -355,7 +394,7 @@ static long evtchn_ioctl(struct file *file,
355 394
356 if (notify.port >= NR_EVENT_CHANNELS) { 395 if (notify.port >= NR_EVENT_CHANNELS) {
357 rc = -EINVAL; 396 rc = -EINVAL;
358 } else if (port_user[notify.port] != u) { 397 } else if (get_port_user(notify.port) != u) {
359 rc = -ENOTCONN; 398 rc = -ENOTCONN;
360 } else { 399 } else {
361 notify_remote_via_evtchn(notify.port); 400 notify_remote_via_evtchn(notify.port);
@@ -431,7 +470,7 @@ static int evtchn_open(struct inode *inode, struct file *filp)
431 470
432 filp->private_data = u; 471 filp->private_data = u;
433 472
434 return 0; 473 return nonseekable_open(inode, filp);;
435} 474}
436 475
437static int evtchn_release(struct inode *inode, struct file *filp) 476static int evtchn_release(struct inode *inode, struct file *filp)
@@ -444,14 +483,21 @@ static int evtchn_release(struct inode *inode, struct file *filp)
444 free_page((unsigned long)u->ring); 483 free_page((unsigned long)u->ring);
445 484
446 for (i = 0; i < NR_EVENT_CHANNELS; i++) { 485 for (i = 0; i < NR_EVENT_CHANNELS; i++) {
447 if (port_user[i] != u) 486 if (get_port_user(i) != u)
448 continue; 487 continue;
449 488
450 evtchn_unbind_from_user(port_user[i], i); 489 disable_irq(irq_from_evtchn(i));
451 } 490 }
452 491
453 spin_unlock_irq(&port_user_lock); 492 spin_unlock_irq(&port_user_lock);
454 493
494 for (i = 0; i < NR_EVENT_CHANNELS; i++) {
495 if (get_port_user(i) != u)
496 continue;
497
498 evtchn_unbind_from_user(get_port_user(i), i);
499 }
500
455 kfree(u->name); 501 kfree(u->name);
456 kfree(u); 502 kfree(u);
457 503
@@ -467,12 +513,12 @@ static const struct file_operations evtchn_fops = {
467 .fasync = evtchn_fasync, 513 .fasync = evtchn_fasync,
468 .open = evtchn_open, 514 .open = evtchn_open,
469 .release = evtchn_release, 515 .release = evtchn_release,
470 .llseek = noop_llseek, 516 .llseek = no_llseek,
471}; 517};
472 518
473static struct miscdevice evtchn_miscdev = { 519static struct miscdevice evtchn_miscdev = {
474 .minor = MISC_DYNAMIC_MINOR, 520 .minor = MISC_DYNAMIC_MINOR,
475 .name = "evtchn", 521 .name = "xen/evtchn",
476 .fops = &evtchn_fops, 522 .fops = &evtchn_fops,
477}; 523};
478static int __init evtchn_init(void) 524static int __init evtchn_init(void)
@@ -482,8 +528,11 @@ static int __init evtchn_init(void)
482 if (!xen_domain()) 528 if (!xen_domain())
483 return -ENODEV; 529 return -ENODEV;
484 530
531 port_user = kcalloc(NR_EVENT_CHANNELS, sizeof(*port_user), GFP_KERNEL);
532 if (port_user == NULL)
533 return -ENOMEM;
534
485 spin_lock_init(&port_user_lock); 535 spin_lock_init(&port_user_lock);
486 memset(port_user, 0, sizeof(port_user));
487 536
488 /* Create '/dev/misc/evtchn'. */ 537 /* Create '/dev/misc/evtchn'. */
489 err = misc_register(&evtchn_miscdev); 538 err = misc_register(&evtchn_miscdev);
@@ -499,6 +548,9 @@ static int __init evtchn_init(void)
499 548
500static void __exit evtchn_cleanup(void) 549static void __exit evtchn_cleanup(void)
501{ 550{
551 kfree(port_user);
552 port_user = NULL;
553
502 misc_deregister(&evtchn_miscdev); 554 misc_deregister(&evtchn_miscdev);
503} 555}
504 556
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index ef9c7db52077..db8c4c4ac880 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -49,6 +49,7 @@ static int xen_hvm_suspend(void *data)
49 49
50 if (!*cancelled) { 50 if (!*cancelled) {
51 xen_irq_resume(); 51 xen_irq_resume();
52 xen_console_resume();
52 xen_timer_resume(); 53 xen_timer_resume();
53 } 54 }
54 55
diff --git a/drivers/xen/xenfs/privcmd.c b/drivers/xen/xenfs/privcmd.c
index f80be7f6eb95..dbd3b16fd131 100644
--- a/drivers/xen/xenfs/privcmd.c
+++ b/drivers/xen/xenfs/privcmd.c
@@ -15,7 +15,6 @@
15#include <linux/mman.h> 15#include <linux/mman.h>
16#include <linux/uaccess.h> 16#include <linux/uaccess.h>
17#include <linux/swap.h> 17#include <linux/swap.h>
18#include <linux/smp_lock.h>
19#include <linux/highmem.h> 18#include <linux/highmem.h>
20#include <linux/pagemap.h> 19#include <linux/pagemap.h>
21#include <linux/seq_file.h> 20#include <linux/seq_file.h>
@@ -266,9 +265,7 @@ static int mmap_return_errors(void *data, void *state)
266 xen_pfn_t *mfnp = data; 265 xen_pfn_t *mfnp = data;
267 struct mmap_batch_state *st = state; 266 struct mmap_batch_state *st = state;
268 267
269 put_user(*mfnp, st->user++); 268 return put_user(*mfnp, st->user++);
270
271 return 0;
272} 269}
273 270
274static struct vm_operations_struct privcmd_vm_ops; 271static struct vm_operations_struct privcmd_vm_ops;
@@ -323,10 +320,8 @@ static long privcmd_ioctl_mmap_batch(void __user *udata)
323 up_write(&mm->mmap_sem); 320 up_write(&mm->mmap_sem);
324 321
325 if (state.err > 0) { 322 if (state.err > 0) {
326 ret = 0;
327
328 state.user = m.arr; 323 state.user = m.arr;
329 traverse_pages(m.num, sizeof(xen_pfn_t), 324 ret = traverse_pages(m.num, sizeof(xen_pfn_t),
330 &pagelist, 325 &pagelist,
331 mmap_return_errors, &state); 326 mmap_return_errors, &state);
332 } 327 }
@@ -384,8 +379,9 @@ static int privcmd_mmap(struct file *file, struct vm_area_struct *vma)
384 if (xen_feature(XENFEAT_auto_translated_physmap)) 379 if (xen_feature(XENFEAT_auto_translated_physmap))
385 return -ENOSYS; 380 return -ENOSYS;
386 381
387 /* DONTCOPY is essential for Xen as copy_page_range is broken. */ 382 /* DONTCOPY is essential for Xen because copy_page_range doesn't know
388 vma->vm_flags |= VM_RESERVED | VM_IO | VM_DONTCOPY; 383 * how to recreate these mappings */
384 vma->vm_flags |= VM_RESERVED | VM_IO | VM_DONTCOPY | VM_PFNMAP;
389 vma->vm_ops = &privcmd_vm_ops; 385 vma->vm_ops = &privcmd_vm_ops;
390 vma->vm_private_data = NULL; 386 vma->vm_private_data = NULL;
391 387
diff --git a/drivers/xen/xenfs/super.c b/drivers/xen/xenfs/super.c
index f6339d11d59c..1aa389719846 100644
--- a/drivers/xen/xenfs/super.c
+++ b/drivers/xen/xenfs/super.c
@@ -12,8 +12,6 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/magic.h> 14#include <linux/magic.h>
15#include <linux/mm.h>
16#include <linux/backing-dev.h>
17 15
18#include <xen/xen.h> 16#include <xen/xen.h>
19 17
@@ -24,28 +22,12 @@
24MODULE_DESCRIPTION("Xen filesystem"); 22MODULE_DESCRIPTION("Xen filesystem");
25MODULE_LICENSE("GPL"); 23MODULE_LICENSE("GPL");
26 24
27static int xenfs_set_page_dirty(struct page *page)
28{
29 return !TestSetPageDirty(page);
30}
31
32static const struct address_space_operations xenfs_aops = {
33 .set_page_dirty = xenfs_set_page_dirty,
34};
35
36static struct backing_dev_info xenfs_backing_dev_info = {
37 .ra_pages = 0, /* No readahead */
38 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
39};
40
41static struct inode *xenfs_make_inode(struct super_block *sb, int mode) 25static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
42{ 26{
43 struct inode *ret = new_inode(sb); 27 struct inode *ret = new_inode(sb);
44 28
45 if (ret) { 29 if (ret) {
46 ret->i_mode = mode; 30 ret->i_mode = mode;
47 ret->i_mapping->a_ops = &xenfs_aops;
48 ret->i_mapping->backing_dev_info = &xenfs_backing_dev_info;
49 ret->i_uid = ret->i_gid = 0; 31 ret->i_uid = ret->i_gid = 0;
50 ret->i_blocks = 0; 32 ret->i_blocks = 0;
51 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME; 33 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
@@ -121,9 +103,9 @@ static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
121 return rc; 103 return rc;
122} 104}
123 105
124static int xenfs_mount(struct file_system_type *fs_type, 106static struct dentry *xenfs_mount(struct file_system_type *fs_type,
125 int flags, const char *dev_name, 107 int flags, const char *dev_name,
126 void *data) 108 void *data)
127{ 109{
128 return mount_single(fs_type, flags, data, xenfs_fill_super); 110 return mount_single(fs_type, flags, data, xenfs_fill_super);
129} 111}
@@ -137,25 +119,11 @@ static struct file_system_type xenfs_type = {
137 119
138static int __init xenfs_init(void) 120static int __init xenfs_init(void)
139{ 121{
140 int err; 122 if (xen_domain())
141 if (!xen_domain()) { 123 return register_filesystem(&xenfs_type);
142 printk(KERN_INFO "xenfs: not registering filesystem on non-xen platform\n");
143 return 0;
144 }
145
146 err = register_filesystem(&xenfs_type);
147 if (err) {
148 printk(KERN_ERR "xenfs: Unable to register filesystem!\n");
149 goto out;
150 }
151
152 err = bdi_init(&xenfs_backing_dev_info);
153 if (err)
154 unregister_filesystem(&xenfs_type);
155
156 out:
157 124
158 return err; 125 printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
126 return 0;
159} 127}
160 128
161static void __exit xenfs_exit(void) 129static void __exit xenfs_exit(void)
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c
index cafc50454292..e0c84725d3e9 100644
--- a/drivers/zorro/proc.c
+++ b/drivers/zorro/proc.c
@@ -13,7 +13,6 @@
13#include <linux/proc_fs.h> 13#include <linux/proc_fs.h>
14#include <linux/seq_file.h> 14#include <linux/seq_file.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/smp_lock.h>
17#include <asm/uaccess.h> 16#include <asm/uaccess.h>
18#include <asm/amigahw.h> 17#include <asm/amigahw.h>
19#include <asm/setup.h> 18#include <asm/setup.h>
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index d5c1401f0031..d34896cfb19f 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -980,19 +980,11 @@ static int autofs4_root_ioctl_unlocked(struct inode *inode, struct file *filp,
980 } 980 }
981} 981}
982 982
983static DEFINE_MUTEX(autofs4_ioctl_mutex);
984
985static long autofs4_root_ioctl(struct file *filp, 983static long autofs4_root_ioctl(struct file *filp,
986 unsigned int cmd, unsigned long arg) 984 unsigned int cmd, unsigned long arg)
987{ 985{
988 long ret;
989 struct inode *inode = filp->f_dentry->d_inode; 986 struct inode *inode = filp->f_dentry->d_inode;
990 987 return autofs4_root_ioctl_unlocked(inode, filp, cmd, arg);
991 mutex_lock(&autofs4_ioctl_mutex);
992 ret = autofs4_root_ioctl_unlocked(inode, filp, cmd, arg);
993 mutex_unlock(&autofs4_ioctl_mutex);
994
995 return ret;
996} 988}
997 989
998#ifdef CONFIG_COMPAT 990#ifdef CONFIG_COMPAT
@@ -1002,13 +994,11 @@ static long autofs4_root_compat_ioctl(struct file *filp,
1002 struct inode *inode = filp->f_path.dentry->d_inode; 994 struct inode *inode = filp->f_path.dentry->d_inode;
1003 int ret; 995 int ret;
1004 996
1005 mutex_lock(&autofs4_ioctl_mutex);
1006 if (cmd == AUTOFS_IOC_READY || cmd == AUTOFS_IOC_FAIL) 997 if (cmd == AUTOFS_IOC_READY || cmd == AUTOFS_IOC_FAIL)
1007 ret = autofs4_root_ioctl_unlocked(inode, filp, cmd, arg); 998 ret = autofs4_root_ioctl_unlocked(inode, filp, cmd, arg);
1008 else 999 else
1009 ret = autofs4_root_ioctl_unlocked(inode, filp, cmd, 1000 ret = autofs4_root_ioctl_unlocked(inode, filp, cmd,
1010 (unsigned long)compat_ptr(arg)); 1001 (unsigned long)compat_ptr(arg));
1011 mutex_unlock(&autofs4_ioctl_mutex);
1012 1002
1013 return ret; 1003 return ret;
1014} 1004}
diff --git a/fs/bio.c b/fs/bio.c
index 8abb2dfb2e7c..4bd454fa844e 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -370,6 +370,9 @@ struct bio *bio_kmalloc(gfp_t gfp_mask, int nr_iovecs)
370{ 370{
371 struct bio *bio; 371 struct bio *bio;
372 372
373 if (nr_iovecs > UIO_MAXIOV)
374 return NULL;
375
373 bio = kmalloc(sizeof(struct bio) + nr_iovecs * sizeof(struct bio_vec), 376 bio = kmalloc(sizeof(struct bio) + nr_iovecs * sizeof(struct bio_vec),
374 gfp_mask); 377 gfp_mask);
375 if (unlikely(!bio)) 378 if (unlikely(!bio))
@@ -697,8 +700,12 @@ static void bio_free_map_data(struct bio_map_data *bmd)
697static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count, 700static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count,
698 gfp_t gfp_mask) 701 gfp_t gfp_mask)
699{ 702{
700 struct bio_map_data *bmd = kmalloc(sizeof(*bmd), gfp_mask); 703 struct bio_map_data *bmd;
701 704
705 if (iov_count > UIO_MAXIOV)
706 return NULL;
707
708 bmd = kmalloc(sizeof(*bmd), gfp_mask);
702 if (!bmd) 709 if (!bmd)
703 return NULL; 710 return NULL;
704 711
@@ -827,6 +834,12 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
827 end = (uaddr + iov[i].iov_len + PAGE_SIZE - 1) >> PAGE_SHIFT; 834 end = (uaddr + iov[i].iov_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
828 start = uaddr >> PAGE_SHIFT; 835 start = uaddr >> PAGE_SHIFT;
829 836
837 /*
838 * Overflow, abort
839 */
840 if (end < start)
841 return ERR_PTR(-EINVAL);
842
830 nr_pages += end - start; 843 nr_pages += end - start;
831 len += iov[i].iov_len; 844 len += iov[i].iov_len;
832 } 845 }
@@ -955,6 +968,12 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
955 unsigned long end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; 968 unsigned long end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
956 unsigned long start = uaddr >> PAGE_SHIFT; 969 unsigned long start = uaddr >> PAGE_SHIFT;
957 970
971 /*
972 * Overflow, abort
973 */
974 if (end < start)
975 return ERR_PTR(-EINVAL);
976
958 nr_pages += end - start; 977 nr_pages += end - start;
959 /* 978 /*
960 * buffer must be aligned to at least hardsector size for now 979 * buffer must be aligned to at least hardsector size for now
@@ -982,7 +1001,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
982 unsigned long start = uaddr >> PAGE_SHIFT; 1001 unsigned long start = uaddr >> PAGE_SHIFT;
983 const int local_nr_pages = end - start; 1002 const int local_nr_pages = end - start;
984 const int page_limit = cur_page + local_nr_pages; 1003 const int page_limit = cur_page + local_nr_pages;
985 1004
986 ret = get_user_pages_fast(uaddr, local_nr_pages, 1005 ret = get_user_pages_fast(uaddr, local_nr_pages,
987 write_to_vm, &pages[cur_page]); 1006 write_to_vm, &pages[cur_page]);
988 if (ret < local_nr_pages) { 1007 if (ret < local_nr_pages) {
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 06e8ff12b97c..4230252fd689 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -11,7 +11,6 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/kmod.h> 12#include <linux/kmod.h>
13#include <linux/major.h> 13#include <linux/major.h>
14#include <linux/smp_lock.h>
15#include <linux/device_cgroup.h> 14#include <linux/device_cgroup.h>
16#include <linux/highmem.h> 15#include <linux/highmem.h>
17#include <linux/blkdev.h> 16#include <linux/blkdev.h>
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 7845d1f7d1d9..b50bc4bd5c56 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -91,23 +91,10 @@ static inline int compressed_bio_size(struct btrfs_root *root,
91static struct bio *compressed_bio_alloc(struct block_device *bdev, 91static struct bio *compressed_bio_alloc(struct block_device *bdev,
92 u64 first_byte, gfp_t gfp_flags) 92 u64 first_byte, gfp_t gfp_flags)
93{ 93{
94 struct bio *bio;
95 int nr_vecs; 94 int nr_vecs;
96 95
97 nr_vecs = bio_get_nr_vecs(bdev); 96 nr_vecs = bio_get_nr_vecs(bdev);
98 bio = bio_alloc(gfp_flags, nr_vecs); 97 return btrfs_bio_alloc(bdev, first_byte >> 9, nr_vecs, gfp_flags);
99
100 if (bio == NULL && (current->flags & PF_MEMALLOC)) {
101 while (!bio && (nr_vecs /= 2))
102 bio = bio_alloc(gfp_flags, nr_vecs);
103 }
104
105 if (bio) {
106 bio->bi_size = 0;
107 bio->bi_bdev = bdev;
108 bio->bi_sector = first_byte >> 9;
109 }
110 return bio;
111} 98}
112 99
113static int check_compressed_csum(struct inode *inode, 100static int check_compressed_csum(struct inode *inode,
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 8db9234f6b41..af52f6d7a4d8 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -808,9 +808,9 @@ struct btrfs_block_group_cache {
808 int extents_thresh; 808 int extents_thresh;
809 int free_extents; 809 int free_extents;
810 int total_bitmaps; 810 int total_bitmaps;
811 int ro:1; 811 unsigned int ro:1;
812 int dirty:1; 812 unsigned int dirty:1;
813 int iref:1; 813 unsigned int iref:1;
814 814
815 int disk_cache_state; 815 int disk_cache_state;
816 816
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index fb827d0d7181..51d2e4de34eb 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -28,6 +28,7 @@
28#include <linux/freezer.h> 28#include <linux/freezer.h>
29#include <linux/crc32c.h> 29#include <linux/crc32c.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/migrate.h>
31#include "compat.h" 32#include "compat.h"
32#include "ctree.h" 33#include "ctree.h"
33#include "disk-io.h" 34#include "disk-io.h"
@@ -355,6 +356,8 @@ static int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
355 ret = btree_read_extent_buffer_pages(root, eb, start + PAGE_CACHE_SIZE, 356 ret = btree_read_extent_buffer_pages(root, eb, start + PAGE_CACHE_SIZE,
356 btrfs_header_generation(eb)); 357 btrfs_header_generation(eb));
357 BUG_ON(ret); 358 BUG_ON(ret);
359 WARN_ON(!btrfs_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN));
360
358 found_start = btrfs_header_bytenr(eb); 361 found_start = btrfs_header_bytenr(eb);
359 if (found_start != start) { 362 if (found_start != start) {
360 WARN_ON(1); 363 WARN_ON(1);
@@ -693,6 +696,27 @@ static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
693 __btree_submit_bio_done); 696 __btree_submit_bio_done);
694} 697}
695 698
699#ifdef CONFIG_MIGRATION
700static int btree_migratepage(struct address_space *mapping,
701 struct page *newpage, struct page *page)
702{
703 /*
704 * we can't safely write a btree page from here,
705 * we haven't done the locking hook
706 */
707 if (PageDirty(page))
708 return -EAGAIN;
709 /*
710 * Buffers may be managed in a filesystem specific way.
711 * We must have no buffers or drop them.
712 */
713 if (page_has_private(page) &&
714 !try_to_release_page(page, GFP_KERNEL))
715 return -EAGAIN;
716 return migrate_page(mapping, newpage, page);
717}
718#endif
719
696static int btree_writepage(struct page *page, struct writeback_control *wbc) 720static int btree_writepage(struct page *page, struct writeback_control *wbc)
697{ 721{
698 struct extent_io_tree *tree; 722 struct extent_io_tree *tree;
@@ -707,8 +731,7 @@ static int btree_writepage(struct page *page, struct writeback_control *wbc)
707 } 731 }
708 732
709 redirty_page_for_writepage(wbc, page); 733 redirty_page_for_writepage(wbc, page);
710 eb = btrfs_find_tree_block(root, page_offset(page), 734 eb = btrfs_find_tree_block(root, page_offset(page), PAGE_CACHE_SIZE);
711 PAGE_CACHE_SIZE);
712 WARN_ON(!eb); 735 WARN_ON(!eb);
713 736
714 was_dirty = test_and_set_bit(EXTENT_BUFFER_DIRTY, &eb->bflags); 737 was_dirty = test_and_set_bit(EXTENT_BUFFER_DIRTY, &eb->bflags);
@@ -799,6 +822,9 @@ static const struct address_space_operations btree_aops = {
799 .releasepage = btree_releasepage, 822 .releasepage = btree_releasepage,
800 .invalidatepage = btree_invalidatepage, 823 .invalidatepage = btree_invalidatepage,
801 .sync_page = block_sync_page, 824 .sync_page = block_sync_page,
825#ifdef CONFIG_MIGRATION
826 .migratepage = btree_migratepage,
827#endif
802}; 828};
803 829
804int readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize, 830int readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize,
@@ -981,7 +1007,10 @@ static int find_and_setup_root(struct btrfs_root *tree_root,
981 blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item)); 1007 blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
982 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 1008 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
983 blocksize, generation); 1009 blocksize, generation);
984 BUG_ON(!root->node); 1010 if (!root->node || !btrfs_buffer_uptodate(root->node, generation)) {
1011 free_extent_buffer(root->node);
1012 return -EIO;
1013 }
985 root->commit_root = btrfs_root_node(root); 1014 root->commit_root = btrfs_root_node(root);
986 return 0; 1015 return 0;
987} 1016}
@@ -1538,10 +1567,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1538 GFP_NOFS); 1567 GFP_NOFS);
1539 struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), 1568 struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root),
1540 GFP_NOFS); 1569 GFP_NOFS);
1541 struct btrfs_root *tree_root = kzalloc(sizeof(struct btrfs_root), 1570 struct btrfs_root *tree_root = btrfs_sb(sb);
1542 GFP_NOFS); 1571 struct btrfs_fs_info *fs_info = tree_root->fs_info;
1543 struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info),
1544 GFP_NOFS);
1545 struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), 1572 struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root),
1546 GFP_NOFS); 1573 GFP_NOFS);
1547 struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), 1574 struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root),
diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index 951ef09b82f4..659f532d26a0 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -166,7 +166,7 @@ static struct dentry *btrfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
166static struct dentry *btrfs_get_parent(struct dentry *child) 166static struct dentry *btrfs_get_parent(struct dentry *child)
167{ 167{
168 struct inode *dir = child->d_inode; 168 struct inode *dir = child->d_inode;
169 static struct dentry *dentry; 169 struct dentry *dentry;
170 struct btrfs_root *root = BTRFS_I(dir)->root; 170 struct btrfs_root *root = BTRFS_I(dir)->root;
171 struct btrfs_path *path; 171 struct btrfs_path *path;
172 struct extent_buffer *leaf; 172 struct extent_buffer *leaf;
@@ -232,9 +232,85 @@ fail:
232 return ERR_PTR(ret); 232 return ERR_PTR(ret);
233} 233}
234 234
235static int btrfs_get_name(struct dentry *parent, char *name,
236 struct dentry *child)
237{
238 struct inode *inode = child->d_inode;
239 struct inode *dir = parent->d_inode;
240 struct btrfs_path *path;
241 struct btrfs_root *root = BTRFS_I(dir)->root;
242 struct btrfs_inode_ref *iref;
243 struct btrfs_root_ref *rref;
244 struct extent_buffer *leaf;
245 unsigned long name_ptr;
246 struct btrfs_key key;
247 int name_len;
248 int ret;
249
250 if (!dir || !inode)
251 return -EINVAL;
252
253 if (!S_ISDIR(dir->i_mode))
254 return -EINVAL;
255
256 path = btrfs_alloc_path();
257 if (!path)
258 return -ENOMEM;
259 path->leave_spinning = 1;
260
261 if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
262 key.objectid = BTRFS_I(inode)->root->root_key.objectid;
263 key.type = BTRFS_ROOT_BACKREF_KEY;
264 key.offset = (u64)-1;
265 root = root->fs_info->tree_root;
266 } else {
267 key.objectid = inode->i_ino;
268 key.offset = dir->i_ino;
269 key.type = BTRFS_INODE_REF_KEY;
270 }
271
272 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
273 if (ret < 0) {
274 btrfs_free_path(path);
275 return ret;
276 } else if (ret > 0) {
277 if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
278 path->slots[0]--;
279 } else {
280 btrfs_free_path(path);
281 return -ENOENT;
282 }
283 }
284 leaf = path->nodes[0];
285
286 if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
287 rref = btrfs_item_ptr(leaf, path->slots[0],
288 struct btrfs_root_ref);
289 name_ptr = (unsigned long)(rref + 1);
290 name_len = btrfs_root_ref_name_len(leaf, rref);
291 } else {
292 iref = btrfs_item_ptr(leaf, path->slots[0],
293 struct btrfs_inode_ref);
294 name_ptr = (unsigned long)(iref + 1);
295 name_len = btrfs_inode_ref_name_len(leaf, iref);
296 }
297
298 read_extent_buffer(leaf, name, name_ptr, name_len);
299 btrfs_free_path(path);
300
301 /*
302 * have to add the null termination to make sure that reconnect_path
303 * gets the right len for strlen
304 */
305 name[name_len] = '\0';
306
307 return 0;
308}
309
235const struct export_operations btrfs_export_ops = { 310const struct export_operations btrfs_export_ops = {
236 .encode_fh = btrfs_encode_fh, 311 .encode_fh = btrfs_encode_fh,
237 .fh_to_dentry = btrfs_fh_to_dentry, 312 .fh_to_dentry = btrfs_fh_to_dentry,
238 .fh_to_parent = btrfs_fh_to_parent, 313 .fh_to_parent = btrfs_fh_to_parent,
239 .get_parent = btrfs_get_parent, 314 .get_parent = btrfs_get_parent,
315 .get_name = btrfs_get_name,
240}; 316};
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 0c097f3aec41..227e5815d838 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -429,6 +429,7 @@ err:
429 429
430static int cache_block_group(struct btrfs_block_group_cache *cache, 430static int cache_block_group(struct btrfs_block_group_cache *cache,
431 struct btrfs_trans_handle *trans, 431 struct btrfs_trans_handle *trans,
432 struct btrfs_root *root,
432 int load_cache_only) 433 int load_cache_only)
433{ 434{
434 struct btrfs_fs_info *fs_info = cache->fs_info; 435 struct btrfs_fs_info *fs_info = cache->fs_info;
@@ -442,9 +443,12 @@ static int cache_block_group(struct btrfs_block_group_cache *cache,
442 443
443 /* 444 /*
444 * We can't do the read from on-disk cache during a commit since we need 445 * We can't do the read from on-disk cache during a commit since we need
445 * to have the normal tree locking. 446 * to have the normal tree locking. Also if we are currently trying to
447 * allocate blocks for the tree root we can't do the fast caching since
448 * we likely hold important locks.
446 */ 449 */
447 if (!trans->transaction->in_commit) { 450 if (!trans->transaction->in_commit &&
451 (root && root != root->fs_info->tree_root)) {
448 spin_lock(&cache->lock); 452 spin_lock(&cache->lock);
449 if (cache->cached != BTRFS_CACHE_NO) { 453 if (cache->cached != BTRFS_CACHE_NO) {
450 spin_unlock(&cache->lock); 454 spin_unlock(&cache->lock);
@@ -2741,6 +2745,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group,
2741 struct btrfs_root *root = block_group->fs_info->tree_root; 2745 struct btrfs_root *root = block_group->fs_info->tree_root;
2742 struct inode *inode = NULL; 2746 struct inode *inode = NULL;
2743 u64 alloc_hint = 0; 2747 u64 alloc_hint = 0;
2748 int dcs = BTRFS_DC_ERROR;
2744 int num_pages = 0; 2749 int num_pages = 0;
2745 int retries = 0; 2750 int retries = 0;
2746 int ret = 0; 2751 int ret = 0;
@@ -2795,6 +2800,8 @@ again:
2795 2800
2796 spin_lock(&block_group->lock); 2801 spin_lock(&block_group->lock);
2797 if (block_group->cached != BTRFS_CACHE_FINISHED) { 2802 if (block_group->cached != BTRFS_CACHE_FINISHED) {
2803 /* We're not cached, don't bother trying to write stuff out */
2804 dcs = BTRFS_DC_WRITTEN;
2798 spin_unlock(&block_group->lock); 2805 spin_unlock(&block_group->lock);
2799 goto out_put; 2806 goto out_put;
2800 } 2807 }
@@ -2821,6 +2828,8 @@ again:
2821 ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, num_pages, 2828 ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, num_pages,
2822 num_pages, num_pages, 2829 num_pages, num_pages,
2823 &alloc_hint); 2830 &alloc_hint);
2831 if (!ret)
2832 dcs = BTRFS_DC_SETUP;
2824 btrfs_free_reserved_data_space(inode, num_pages); 2833 btrfs_free_reserved_data_space(inode, num_pages);
2825out_put: 2834out_put:
2826 iput(inode); 2835 iput(inode);
@@ -2828,10 +2837,7 @@ out_free:
2828 btrfs_release_path(root, path); 2837 btrfs_release_path(root, path);
2829out: 2838out:
2830 spin_lock(&block_group->lock); 2839 spin_lock(&block_group->lock);
2831 if (ret) 2840 block_group->disk_cache_state = dcs;
2832 block_group->disk_cache_state = BTRFS_DC_ERROR;
2833 else
2834 block_group->disk_cache_state = BTRFS_DC_SETUP;
2835 spin_unlock(&block_group->lock); 2841 spin_unlock(&block_group->lock);
2836 2842
2837 return ret; 2843 return ret;
@@ -3037,7 +3043,13 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
3037 3043
3038u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags) 3044u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags)
3039{ 3045{
3040 u64 num_devices = root->fs_info->fs_devices->rw_devices; 3046 /*
3047 * we add in the count of missing devices because we want
3048 * to make sure that any RAID levels on a degraded FS
3049 * continue to be honored.
3050 */
3051 u64 num_devices = root->fs_info->fs_devices->rw_devices +
3052 root->fs_info->fs_devices->missing_devices;
3041 3053
3042 if (num_devices == 1) 3054 if (num_devices == 1)
3043 flags &= ~(BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID0); 3055 flags &= ~(BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID0);
@@ -3412,7 +3424,7 @@ again:
3412 * our reservation. 3424 * our reservation.
3413 */ 3425 */
3414 if (unused <= space_info->total_bytes) { 3426 if (unused <= space_info->total_bytes) {
3415 unused -= space_info->total_bytes; 3427 unused = space_info->total_bytes - unused;
3416 if (unused >= num_bytes) { 3428 if (unused >= num_bytes) {
3417 if (!reserved) 3429 if (!reserved)
3418 space_info->bytes_reserved += orig_bytes; 3430 space_info->bytes_reserved += orig_bytes;
@@ -4080,7 +4092,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
4080 * space back to the block group, otherwise we will leak space. 4092 * space back to the block group, otherwise we will leak space.
4081 */ 4093 */
4082 if (!alloc && cache->cached == BTRFS_CACHE_NO) 4094 if (!alloc && cache->cached == BTRFS_CACHE_NO)
4083 cache_block_group(cache, trans, 1); 4095 cache_block_group(cache, trans, NULL, 1);
4084 4096
4085 byte_in_group = bytenr - cache->key.objectid; 4097 byte_in_group = bytenr - cache->key.objectid;
4086 WARN_ON(byte_in_group > cache->key.offset); 4098 WARN_ON(byte_in_group > cache->key.offset);
@@ -4930,11 +4942,31 @@ search:
4930 btrfs_get_block_group(block_group); 4942 btrfs_get_block_group(block_group);
4931 search_start = block_group->key.objectid; 4943 search_start = block_group->key.objectid;
4932 4944
4945 /*
4946 * this can happen if we end up cycling through all the
4947 * raid types, but we want to make sure we only allocate
4948 * for the proper type.
4949 */
4950 if (!block_group_bits(block_group, data)) {
4951 u64 extra = BTRFS_BLOCK_GROUP_DUP |
4952 BTRFS_BLOCK_GROUP_RAID1 |
4953 BTRFS_BLOCK_GROUP_RAID10;
4954
4955 /*
4956 * if they asked for extra copies and this block group
4957 * doesn't provide them, bail. This does allow us to
4958 * fill raid0 from raid1.
4959 */
4960 if ((data & extra) && !(block_group->flags & extra))
4961 goto loop;
4962 }
4963
4933have_block_group: 4964have_block_group:
4934 if (unlikely(block_group->cached == BTRFS_CACHE_NO)) { 4965 if (unlikely(block_group->cached == BTRFS_CACHE_NO)) {
4935 u64 free_percent; 4966 u64 free_percent;
4936 4967
4937 ret = cache_block_group(block_group, trans, 1); 4968 ret = cache_block_group(block_group, trans,
4969 orig_root, 1);
4938 if (block_group->cached == BTRFS_CACHE_FINISHED) 4970 if (block_group->cached == BTRFS_CACHE_FINISHED)
4939 goto have_block_group; 4971 goto have_block_group;
4940 4972
@@ -4958,7 +4990,8 @@ have_block_group:
4958 if (loop > LOOP_CACHING_NOWAIT || 4990 if (loop > LOOP_CACHING_NOWAIT ||
4959 (loop > LOOP_FIND_IDEAL && 4991 (loop > LOOP_FIND_IDEAL &&
4960 atomic_read(&space_info->caching_threads) < 2)) { 4992 atomic_read(&space_info->caching_threads) < 2)) {
4961 ret = cache_block_group(block_group, trans, 0); 4993 ret = cache_block_group(block_group, trans,
4994 orig_root, 0);
4962 BUG_ON(ret); 4995 BUG_ON(ret);
4963 } 4996 }
4964 found_uncached_bg = true; 4997 found_uncached_bg = true;
@@ -5515,7 +5548,7 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
5515 u64 num_bytes = ins->offset; 5548 u64 num_bytes = ins->offset;
5516 5549
5517 block_group = btrfs_lookup_block_group(root->fs_info, ins->objectid); 5550 block_group = btrfs_lookup_block_group(root->fs_info, ins->objectid);
5518 cache_block_group(block_group, trans, 0); 5551 cache_block_group(block_group, trans, NULL, 0);
5519 caching_ctl = get_caching_control(block_group); 5552 caching_ctl = get_caching_control(block_group);
5520 5553
5521 if (!caching_ctl) { 5554 if (!caching_ctl) {
@@ -6300,9 +6333,13 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
6300 NULL, NULL); 6333 NULL, NULL);
6301 BUG_ON(ret < 0); 6334 BUG_ON(ret < 0);
6302 if (ret > 0) { 6335 if (ret > 0) {
6303 ret = btrfs_del_orphan_item(trans, tree_root, 6336 /* if we fail to delete the orphan item this time
6304 root->root_key.objectid); 6337 * around, it'll get picked up the next time.
6305 BUG_ON(ret); 6338 *
6339 * The most common failure here is just -ENOENT.
6340 */
6341 btrfs_del_orphan_item(trans, tree_root,
6342 root->root_key.objectid);
6306 } 6343 }
6307 } 6344 }
6308 6345
@@ -7878,7 +7915,14 @@ static u64 update_block_group_flags(struct btrfs_root *root, u64 flags)
7878 u64 stripped = BTRFS_BLOCK_GROUP_RAID0 | 7915 u64 stripped = BTRFS_BLOCK_GROUP_RAID0 |
7879 BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10; 7916 BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10;
7880 7917
7881 num_devices = root->fs_info->fs_devices->rw_devices; 7918 /*
7919 * we add in the count of missing devices because we want
7920 * to make sure that any RAID levels on a degraded FS
7921 * continue to be honored.
7922 */
7923 num_devices = root->fs_info->fs_devices->rw_devices +
7924 root->fs_info->fs_devices->missing_devices;
7925
7882 if (num_devices == 1) { 7926 if (num_devices == 1) {
7883 stripped |= BTRFS_BLOCK_GROUP_DUP; 7927 stripped |= BTRFS_BLOCK_GROUP_DUP;
7884 stripped = flags & ~stripped; 7928 stripped = flags & ~stripped;
@@ -8247,7 +8291,6 @@ int btrfs_read_block_groups(struct btrfs_root *root)
8247 break; 8291 break;
8248 if (ret != 0) 8292 if (ret != 0)
8249 goto error; 8293 goto error;
8250
8251 leaf = path->nodes[0]; 8294 leaf = path->nodes[0];
8252 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 8295 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
8253 cache = kzalloc(sizeof(*cache), GFP_NOFS); 8296 cache = kzalloc(sizeof(*cache), GFP_NOFS);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index eac10e3260a9..3e86b9f36507 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1828,9 +1828,9 @@ static void end_bio_extent_preparewrite(struct bio *bio, int err)
1828 bio_put(bio); 1828 bio_put(bio);
1829} 1829}
1830 1830
1831static struct bio * 1831struct bio *
1832extent_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, 1832btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs,
1833 gfp_t gfp_flags) 1833 gfp_t gfp_flags)
1834{ 1834{
1835 struct bio *bio; 1835 struct bio *bio;
1836 1836
@@ -1919,7 +1919,7 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,
1919 else 1919 else
1920 nr = bio_get_nr_vecs(bdev); 1920 nr = bio_get_nr_vecs(bdev);
1921 1921
1922 bio = extent_bio_alloc(bdev, sector, nr, GFP_NOFS | __GFP_HIGH); 1922 bio = btrfs_bio_alloc(bdev, sector, nr, GFP_NOFS | __GFP_HIGH);
1923 1923
1924 bio_add_page(bio, page, page_size, offset); 1924 bio_add_page(bio, page, page_size, offset);
1925 bio->bi_end_io = end_io_func; 1925 bio->bi_end_io = end_io_func;
@@ -2901,21 +2901,53 @@ out:
2901int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2901int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2902 __u64 start, __u64 len, get_extent_t *get_extent) 2902 __u64 start, __u64 len, get_extent_t *get_extent)
2903{ 2903{
2904 int ret; 2904 int ret = 0;
2905 u64 off = start; 2905 u64 off = start;
2906 u64 max = start + len; 2906 u64 max = start + len;
2907 u32 flags = 0; 2907 u32 flags = 0;
2908 u32 found_type;
2909 u64 last;
2908 u64 disko = 0; 2910 u64 disko = 0;
2911 struct btrfs_key found_key;
2909 struct extent_map *em = NULL; 2912 struct extent_map *em = NULL;
2910 struct extent_state *cached_state = NULL; 2913 struct extent_state *cached_state = NULL;
2914 struct btrfs_path *path;
2915 struct btrfs_file_extent_item *item;
2911 int end = 0; 2916 int end = 0;
2912 u64 em_start = 0, em_len = 0; 2917 u64 em_start = 0, em_len = 0;
2913 unsigned long emflags; 2918 unsigned long emflags;
2914 ret = 0; 2919 int hole = 0;
2915 2920
2916 if (len == 0) 2921 if (len == 0)
2917 return -EINVAL; 2922 return -EINVAL;
2918 2923
2924 path = btrfs_alloc_path();
2925 if (!path)
2926 return -ENOMEM;
2927 path->leave_spinning = 1;
2928
2929 ret = btrfs_lookup_file_extent(NULL, BTRFS_I(inode)->root,
2930 path, inode->i_ino, -1, 0);
2931 if (ret < 0) {
2932 btrfs_free_path(path);
2933 return ret;
2934 }
2935 WARN_ON(!ret);
2936 path->slots[0]--;
2937 item = btrfs_item_ptr(path->nodes[0], path->slots[0],
2938 struct btrfs_file_extent_item);
2939 btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);
2940 found_type = btrfs_key_type(&found_key);
2941
2942 /* No extents, just return */
2943 if (found_key.objectid != inode->i_ino ||
2944 found_type != BTRFS_EXTENT_DATA_KEY) {
2945 btrfs_free_path(path);
2946 return 0;
2947 }
2948 last = found_key.offset;
2949 btrfs_free_path(path);
2950
2919 lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + len, 0, 2951 lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + len, 0,
2920 &cached_state, GFP_NOFS); 2952 &cached_state, GFP_NOFS);
2921 em = get_extent(inode, NULL, 0, off, max - off, 0); 2953 em = get_extent(inode, NULL, 0, off, max - off, 0);
@@ -2925,11 +2957,18 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2925 ret = PTR_ERR(em); 2957 ret = PTR_ERR(em);
2926 goto out; 2958 goto out;
2927 } 2959 }
2960
2928 while (!end) { 2961 while (!end) {
2962 hole = 0;
2929 off = em->start + em->len; 2963 off = em->start + em->len;
2930 if (off >= max) 2964 if (off >= max)
2931 end = 1; 2965 end = 1;
2932 2966
2967 if (em->block_start == EXTENT_MAP_HOLE) {
2968 hole = 1;
2969 goto next;
2970 }
2971
2933 em_start = em->start; 2972 em_start = em->start;
2934 em_len = em->len; 2973 em_len = em->len;
2935 2974
@@ -2939,8 +2978,6 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2939 if (em->block_start == EXTENT_MAP_LAST_BYTE) { 2978 if (em->block_start == EXTENT_MAP_LAST_BYTE) {
2940 end = 1; 2979 end = 1;
2941 flags |= FIEMAP_EXTENT_LAST; 2980 flags |= FIEMAP_EXTENT_LAST;
2942 } else if (em->block_start == EXTENT_MAP_HOLE) {
2943 flags |= FIEMAP_EXTENT_UNWRITTEN;
2944 } else if (em->block_start == EXTENT_MAP_INLINE) { 2981 } else if (em->block_start == EXTENT_MAP_INLINE) {
2945 flags |= (FIEMAP_EXTENT_DATA_INLINE | 2982 flags |= (FIEMAP_EXTENT_DATA_INLINE |
2946 FIEMAP_EXTENT_NOT_ALIGNED); 2983 FIEMAP_EXTENT_NOT_ALIGNED);
@@ -2953,10 +2990,10 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2953 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) 2990 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags))
2954 flags |= FIEMAP_EXTENT_ENCODED; 2991 flags |= FIEMAP_EXTENT_ENCODED;
2955 2992
2993next:
2956 emflags = em->flags; 2994 emflags = em->flags;
2957 free_extent_map(em); 2995 free_extent_map(em);
2958 em = NULL; 2996 em = NULL;
2959
2960 if (!end) { 2997 if (!end) {
2961 em = get_extent(inode, NULL, 0, off, max - off, 0); 2998 em = get_extent(inode, NULL, 0, off, max - off, 0);
2962 if (!em) 2999 if (!em)
@@ -2967,15 +3004,23 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2967 } 3004 }
2968 emflags = em->flags; 3005 emflags = em->flags;
2969 } 3006 }
3007
2970 if (test_bit(EXTENT_FLAG_VACANCY, &emflags)) { 3008 if (test_bit(EXTENT_FLAG_VACANCY, &emflags)) {
2971 flags |= FIEMAP_EXTENT_LAST; 3009 flags |= FIEMAP_EXTENT_LAST;
2972 end = 1; 3010 end = 1;
2973 } 3011 }
2974 3012
2975 ret = fiemap_fill_next_extent(fieinfo, em_start, disko, 3013 if (em_start == last) {
2976 em_len, flags); 3014 flags |= FIEMAP_EXTENT_LAST;
2977 if (ret) 3015 end = 1;
2978 goto out_free; 3016 }
3017
3018 if (!hole) {
3019 ret = fiemap_fill_next_extent(fieinfo, em_start, disko,
3020 em_len, flags);
3021 if (ret)
3022 goto out_free;
3023 }
2979 } 3024 }
2980out_free: 3025out_free:
2981 free_extent_map(em); 3026 free_extent_map(em);
@@ -3836,8 +3881,10 @@ int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page)
3836 3881
3837 spin_lock(&tree->buffer_lock); 3882 spin_lock(&tree->buffer_lock);
3838 eb = radix_tree_lookup(&tree->buffer, start >> PAGE_CACHE_SHIFT); 3883 eb = radix_tree_lookup(&tree->buffer, start >> PAGE_CACHE_SHIFT);
3839 if (!eb) 3884 if (!eb) {
3840 goto out; 3885 spin_unlock(&tree->buffer_lock);
3886 return ret;
3887 }
3841 3888
3842 if (test_bit(EXTENT_BUFFER_DIRTY, &eb->bflags)) { 3889 if (test_bit(EXTENT_BUFFER_DIRTY, &eb->bflags)) {
3843 ret = 0; 3890 ret = 0;
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 1c6d4f342ef7..4183c8178f01 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -310,4 +310,7 @@ int extent_clear_unlock_delalloc(struct inode *inode,
310 struct extent_io_tree *tree, 310 struct extent_io_tree *tree,
311 u64 start, u64 end, struct page *locked_page, 311 u64 start, u64 end, struct page *locked_page,
312 unsigned long op); 312 unsigned long op);
313struct bio *
314btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs,
315 gfp_t gfp_flags);
313#endif 316#endif
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e354c33df082..66836d85763b 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -48,30 +48,34 @@ static noinline int btrfs_copy_from_user(loff_t pos, int num_pages,
48 struct page **prepared_pages, 48 struct page **prepared_pages,
49 struct iov_iter *i) 49 struct iov_iter *i)
50{ 50{
51 size_t copied; 51 size_t copied = 0;
52 int pg = 0; 52 int pg = 0;
53 int offset = pos & (PAGE_CACHE_SIZE - 1); 53 int offset = pos & (PAGE_CACHE_SIZE - 1);
54 int total_copied = 0;
54 55
55 while (write_bytes > 0) { 56 while (write_bytes > 0) {
56 size_t count = min_t(size_t, 57 size_t count = min_t(size_t,
57 PAGE_CACHE_SIZE - offset, write_bytes); 58 PAGE_CACHE_SIZE - offset, write_bytes);
58 struct page *page = prepared_pages[pg]; 59 struct page *page = prepared_pages[pg];
59again: 60 /*
60 if (unlikely(iov_iter_fault_in_readable(i, count))) 61 * Copy data from userspace to the current page
61 return -EFAULT; 62 *
62 63 * Disable pagefault to avoid recursive lock since
63 /* Copy data from userspace to the current page */ 64 * the pages are already locked
64 copied = iov_iter_copy_from_user(page, i, offset, count); 65 */
66 pagefault_disable();
67 copied = iov_iter_copy_from_user_atomic(page, i, offset, count);
68 pagefault_enable();
65 69
66 /* Flush processor's dcache for this page */ 70 /* Flush processor's dcache for this page */
67 flush_dcache_page(page); 71 flush_dcache_page(page);
68 iov_iter_advance(i, copied); 72 iov_iter_advance(i, copied);
69 write_bytes -= copied; 73 write_bytes -= copied;
74 total_copied += copied;
70 75
76 /* Return to btrfs_file_aio_write to fault page */
71 if (unlikely(copied == 0)) { 77 if (unlikely(copied == 0)) {
72 count = min_t(size_t, PAGE_CACHE_SIZE - offset, 78 break;
73 iov_iter_single_seg_count(i));
74 goto again;
75 } 79 }
76 80
77 if (unlikely(copied < PAGE_CACHE_SIZE - offset)) { 81 if (unlikely(copied < PAGE_CACHE_SIZE - offset)) {
@@ -81,7 +85,7 @@ again:
81 offset = 0; 85 offset = 0;
82 } 86 }
83 } 87 }
84 return 0; 88 return total_copied;
85} 89}
86 90
87/* 91/*
@@ -854,6 +858,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
854 unsigned long last_index; 858 unsigned long last_index;
855 int will_write; 859 int will_write;
856 int buffered = 0; 860 int buffered = 0;
861 int copied = 0;
862 int dirty_pages = 0;
857 863
858 will_write = ((file->f_flags & O_DSYNC) || IS_SYNC(inode) || 864 will_write = ((file->f_flags & O_DSYNC) || IS_SYNC(inode) ||
859 (file->f_flags & O_DIRECT)); 865 (file->f_flags & O_DIRECT));
@@ -970,7 +976,17 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
970 WARN_ON(num_pages > nrptrs); 976 WARN_ON(num_pages > nrptrs);
971 memset(pages, 0, sizeof(struct page *) * nrptrs); 977 memset(pages, 0, sizeof(struct page *) * nrptrs);
972 978
973 ret = btrfs_delalloc_reserve_space(inode, write_bytes); 979 /*
980 * Fault pages before locking them in prepare_pages
981 * to avoid recursive lock
982 */
983 if (unlikely(iov_iter_fault_in_readable(&i, write_bytes))) {
984 ret = -EFAULT;
985 goto out;
986 }
987
988 ret = btrfs_delalloc_reserve_space(inode,
989 num_pages << PAGE_CACHE_SHIFT);
974 if (ret) 990 if (ret)
975 goto out; 991 goto out;
976 992
@@ -978,37 +994,49 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
978 pos, first_index, last_index, 994 pos, first_index, last_index,
979 write_bytes); 995 write_bytes);
980 if (ret) { 996 if (ret) {
981 btrfs_delalloc_release_space(inode, write_bytes); 997 btrfs_delalloc_release_space(inode,
998 num_pages << PAGE_CACHE_SHIFT);
982 goto out; 999 goto out;
983 } 1000 }
984 1001
985 ret = btrfs_copy_from_user(pos, num_pages, 1002 copied = btrfs_copy_from_user(pos, num_pages,
986 write_bytes, pages, &i); 1003 write_bytes, pages, &i);
987 if (ret == 0) { 1004 dirty_pages = (copied + PAGE_CACHE_SIZE - 1) >>
1005 PAGE_CACHE_SHIFT;
1006
1007 if (num_pages > dirty_pages) {
1008 if (copied > 0)
1009 atomic_inc(
1010 &BTRFS_I(inode)->outstanding_extents);
1011 btrfs_delalloc_release_space(inode,
1012 (num_pages - dirty_pages) <<
1013 PAGE_CACHE_SHIFT);
1014 }
1015
1016 if (copied > 0) {
988 dirty_and_release_pages(NULL, root, file, pages, 1017 dirty_and_release_pages(NULL, root, file, pages,
989 num_pages, pos, write_bytes); 1018 dirty_pages, pos, copied);
990 } 1019 }
991 1020
992 btrfs_drop_pages(pages, num_pages); 1021 btrfs_drop_pages(pages, num_pages);
993 if (ret) {
994 btrfs_delalloc_release_space(inode, write_bytes);
995 goto out;
996 }
997 1022
998 if (will_write) { 1023 if (copied > 0) {
999 filemap_fdatawrite_range(inode->i_mapping, pos, 1024 if (will_write) {
1000 pos + write_bytes - 1); 1025 filemap_fdatawrite_range(inode->i_mapping, pos,
1001 } else { 1026 pos + copied - 1);
1002 balance_dirty_pages_ratelimited_nr(inode->i_mapping, 1027 } else {
1003 num_pages); 1028 balance_dirty_pages_ratelimited_nr(
1004 if (num_pages < 1029 inode->i_mapping,
1005 (root->leafsize >> PAGE_CACHE_SHIFT) + 1) 1030 dirty_pages);
1006 btrfs_btree_balance_dirty(root, 1); 1031 if (dirty_pages <
1007 btrfs_throttle(root); 1032 (root->leafsize >> PAGE_CACHE_SHIFT) + 1)
1033 btrfs_btree_balance_dirty(root, 1);
1034 btrfs_throttle(root);
1035 }
1008 } 1036 }
1009 1037
1010 pos += write_bytes; 1038 pos += copied;
1011 num_written += write_bytes; 1039 num_written += copied;
1012 1040
1013 cond_resched(); 1041 cond_resched();
1014 } 1042 }
@@ -1047,8 +1075,14 @@ out:
1047 1075
1048 if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) { 1076 if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) {
1049 trans = btrfs_start_transaction(root, 0); 1077 trans = btrfs_start_transaction(root, 0);
1078 if (IS_ERR(trans)) {
1079 num_written = PTR_ERR(trans);
1080 goto done;
1081 }
1082 mutex_lock(&inode->i_mutex);
1050 ret = btrfs_log_dentry_safe(trans, root, 1083 ret = btrfs_log_dentry_safe(trans, root,
1051 file->f_dentry); 1084 file->f_dentry);
1085 mutex_unlock(&inode->i_mutex);
1052 if (ret == 0) { 1086 if (ret == 0) {
1053 ret = btrfs_sync_log(trans, root); 1087 ret = btrfs_sync_log(trans, root);
1054 if (ret == 0) 1088 if (ret == 0)
@@ -1067,6 +1101,7 @@ out:
1067 (start_pos + num_written - 1) >> PAGE_CACHE_SHIFT); 1101 (start_pos + num_written - 1) >> PAGE_CACHE_SHIFT);
1068 } 1102 }
1069 } 1103 }
1104done:
1070 current->backing_dev_info = NULL; 1105 current->backing_dev_info = NULL;
1071 return num_written ? num_written : err; 1106 return num_written ? num_written : err;
1072} 1107}
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 22ee0dc2e6b8..60d684266959 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -290,7 +290,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
290 (unsigned long long)BTRFS_I(inode)->generation, 290 (unsigned long long)BTRFS_I(inode)->generation,
291 (unsigned long long)generation, 291 (unsigned long long)generation,
292 (unsigned long long)block_group->key.objectid); 292 (unsigned long long)block_group->key.objectid);
293 goto out; 293 goto free_cache;
294 } 294 }
295 295
296 if (!num_entries) 296 if (!num_entries)
@@ -524,6 +524,12 @@ int btrfs_write_out_cache(struct btrfs_root *root,
524 return 0; 524 return 0;
525 } 525 }
526 526
527 node = rb_first(&block_group->free_space_offset);
528 if (!node) {
529 iput(inode);
530 return 0;
531 }
532
527 last_index = (i_size_read(inode) - 1) >> PAGE_CACHE_SHIFT; 533 last_index = (i_size_read(inode) - 1) >> PAGE_CACHE_SHIFT;
528 filemap_write_and_wait(inode->i_mapping); 534 filemap_write_and_wait(inode->i_mapping);
529 btrfs_wait_ordered_range(inode, inode->i_size & 535 btrfs_wait_ordered_range(inode, inode->i_size &
@@ -543,10 +549,6 @@ int btrfs_write_out_cache(struct btrfs_root *root,
543 */ 549 */
544 first_page_offset = (sizeof(u32) * num_checksums) + sizeof(u64); 550 first_page_offset = (sizeof(u32) * num_checksums) + sizeof(u64);
545 551
546 node = rb_first(&block_group->free_space_offset);
547 if (!node)
548 goto out_free;
549
550 /* 552 /*
551 * Lock all pages first so we can lock the extent safely. 553 * Lock all pages first so we can lock the extent safely.
552 * 554 *
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 558cac2dfa54..72f31ecb5c90 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -495,7 +495,7 @@ again:
495 add_async_extent(async_cow, start, num_bytes, 495 add_async_extent(async_cow, start, num_bytes,
496 total_compressed, pages, nr_pages_ret); 496 total_compressed, pages, nr_pages_ret);
497 497
498 if (start + num_bytes < end && start + num_bytes < actual_end) { 498 if (start + num_bytes < end) {
499 start += num_bytes; 499 start += num_bytes;
500 pages = NULL; 500 pages = NULL;
501 cond_resched(); 501 cond_resched();
@@ -4501,6 +4501,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
4501 BTRFS_I(inode)->index_cnt = 2; 4501 BTRFS_I(inode)->index_cnt = 2;
4502 BTRFS_I(inode)->root = root; 4502 BTRFS_I(inode)->root = root;
4503 BTRFS_I(inode)->generation = trans->transid; 4503 BTRFS_I(inode)->generation = trans->transid;
4504 inode->i_generation = BTRFS_I(inode)->generation;
4504 btrfs_set_inode_space_info(root, inode); 4505 btrfs_set_inode_space_info(root, inode);
4505 4506
4506 if (mode & S_IFDIR) 4507 if (mode & S_IFDIR)
@@ -4622,12 +4623,12 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
4622} 4623}
4623 4624
4624static int btrfs_add_nondir(struct btrfs_trans_handle *trans, 4625static int btrfs_add_nondir(struct btrfs_trans_handle *trans,
4625 struct dentry *dentry, struct inode *inode, 4626 struct inode *dir, struct dentry *dentry,
4626 int backref, u64 index) 4627 struct inode *inode, int backref, u64 index)
4627{ 4628{
4628 int err = btrfs_add_link(trans, dentry->d_parent->d_inode, 4629 int err = btrfs_add_link(trans, dir, inode,
4629 inode, dentry->d_name.name, 4630 dentry->d_name.name, dentry->d_name.len,
4630 dentry->d_name.len, backref, index); 4631 backref, index);
4631 if (!err) { 4632 if (!err) {
4632 d_instantiate(dentry, inode); 4633 d_instantiate(dentry, inode);
4633 return 0; 4634 return 0;
@@ -4668,8 +4669,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
4668 btrfs_set_trans_block_group(trans, dir); 4669 btrfs_set_trans_block_group(trans, dir);
4669 4670
4670 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 4671 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name,
4671 dentry->d_name.len, 4672 dentry->d_name.len, dir->i_ino, objectid,
4672 dentry->d_parent->d_inode->i_ino, objectid,
4673 BTRFS_I(dir)->block_group, mode, &index); 4673 BTRFS_I(dir)->block_group, mode, &index);
4674 err = PTR_ERR(inode); 4674 err = PTR_ERR(inode);
4675 if (IS_ERR(inode)) 4675 if (IS_ERR(inode))
@@ -4682,7 +4682,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
4682 } 4682 }
4683 4683
4684 btrfs_set_trans_block_group(trans, inode); 4684 btrfs_set_trans_block_group(trans, inode);
4685 err = btrfs_add_nondir(trans, dentry, inode, 0, index); 4685 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
4686 if (err) 4686 if (err)
4687 drop_inode = 1; 4687 drop_inode = 1;
4688 else { 4688 else {
@@ -4730,10 +4730,8 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
4730 btrfs_set_trans_block_group(trans, dir); 4730 btrfs_set_trans_block_group(trans, dir);
4731 4731
4732 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 4732 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name,
4733 dentry->d_name.len, 4733 dentry->d_name.len, dir->i_ino, objectid,
4734 dentry->d_parent->d_inode->i_ino, 4734 BTRFS_I(dir)->block_group, mode, &index);
4735 objectid, BTRFS_I(dir)->block_group, mode,
4736 &index);
4737 err = PTR_ERR(inode); 4735 err = PTR_ERR(inode);
4738 if (IS_ERR(inode)) 4736 if (IS_ERR(inode))
4739 goto out_unlock; 4737 goto out_unlock;
@@ -4745,7 +4743,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
4745 } 4743 }
4746 4744
4747 btrfs_set_trans_block_group(trans, inode); 4745 btrfs_set_trans_block_group(trans, inode);
4748 err = btrfs_add_nondir(trans, dentry, inode, 0, index); 4746 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
4749 if (err) 4747 if (err)
4750 drop_inode = 1; 4748 drop_inode = 1;
4751 else { 4749 else {
@@ -4787,6 +4785,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
4787 return -EPERM; 4785 return -EPERM;
4788 4786
4789 btrfs_inc_nlink(inode); 4787 btrfs_inc_nlink(inode);
4788 inode->i_ctime = CURRENT_TIME;
4790 4789
4791 err = btrfs_set_inode_index(dir, &index); 4790 err = btrfs_set_inode_index(dir, &index);
4792 if (err) 4791 if (err)
@@ -4805,15 +4804,17 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
4805 btrfs_set_trans_block_group(trans, dir); 4804 btrfs_set_trans_block_group(trans, dir);
4806 ihold(inode); 4805 ihold(inode);
4807 4806
4808 err = btrfs_add_nondir(trans, dentry, inode, 1, index); 4807 err = btrfs_add_nondir(trans, dir, dentry, inode, 1, index);
4809 4808
4810 if (err) { 4809 if (err) {
4811 drop_inode = 1; 4810 drop_inode = 1;
4812 } else { 4811 } else {
4812 struct dentry *parent = dget_parent(dentry);
4813 btrfs_update_inode_block_group(trans, dir); 4813 btrfs_update_inode_block_group(trans, dir);
4814 err = btrfs_update_inode(trans, root, inode); 4814 err = btrfs_update_inode(trans, root, inode);
4815 BUG_ON(err); 4815 BUG_ON(err);
4816 btrfs_log_new_name(trans, inode, NULL, dentry->d_parent); 4816 btrfs_log_new_name(trans, inode, NULL, parent);
4817 dput(parent);
4817 } 4818 }
4818 4819
4819 nr = trans->blocks_used; 4820 nr = trans->blocks_used;
@@ -4853,8 +4854,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
4853 btrfs_set_trans_block_group(trans, dir); 4854 btrfs_set_trans_block_group(trans, dir);
4854 4855
4855 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 4856 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name,
4856 dentry->d_name.len, 4857 dentry->d_name.len, dir->i_ino, objectid,
4857 dentry->d_parent->d_inode->i_ino, objectid,
4858 BTRFS_I(dir)->block_group, S_IFDIR | mode, 4858 BTRFS_I(dir)->block_group, S_IFDIR | mode,
4859 &index); 4859 &index);
4860 if (IS_ERR(inode)) { 4860 if (IS_ERR(inode)) {
@@ -4877,9 +4877,8 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
4877 if (err) 4877 if (err)
4878 goto out_fail; 4878 goto out_fail;
4879 4879
4880 err = btrfs_add_link(trans, dentry->d_parent->d_inode, 4880 err = btrfs_add_link(trans, dir, inode, dentry->d_name.name,
4881 inode, dentry->d_name.name, 4881 dentry->d_name.len, 0, index);
4882 dentry->d_name.len, 0, index);
4883 if (err) 4882 if (err)
4884 goto out_fail; 4883 goto out_fail;
4885 4884
@@ -5535,13 +5534,21 @@ struct btrfs_dio_private {
5535 u64 bytes; 5534 u64 bytes;
5536 u32 *csums; 5535 u32 *csums;
5537 void *private; 5536 void *private;
5537
5538 /* number of bios pending for this dio */
5539 atomic_t pending_bios;
5540
5541 /* IO errors */
5542 int errors;
5543
5544 struct bio *orig_bio;
5538}; 5545};
5539 5546
5540static void btrfs_endio_direct_read(struct bio *bio, int err) 5547static void btrfs_endio_direct_read(struct bio *bio, int err)
5541{ 5548{
5549 struct btrfs_dio_private *dip = bio->bi_private;
5542 struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt - 1; 5550 struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt - 1;
5543 struct bio_vec *bvec = bio->bi_io_vec; 5551 struct bio_vec *bvec = bio->bi_io_vec;
5544 struct btrfs_dio_private *dip = bio->bi_private;
5545 struct inode *inode = dip->inode; 5552 struct inode *inode = dip->inode;
5546 struct btrfs_root *root = BTRFS_I(inode)->root; 5553 struct btrfs_root *root = BTRFS_I(inode)->root;
5547 u64 start; 5554 u64 start;
@@ -5595,15 +5602,18 @@ static void btrfs_endio_direct_write(struct bio *bio, int err)
5595 struct btrfs_trans_handle *trans; 5602 struct btrfs_trans_handle *trans;
5596 struct btrfs_ordered_extent *ordered = NULL; 5603 struct btrfs_ordered_extent *ordered = NULL;
5597 struct extent_state *cached_state = NULL; 5604 struct extent_state *cached_state = NULL;
5605 u64 ordered_offset = dip->logical_offset;
5606 u64 ordered_bytes = dip->bytes;
5598 int ret; 5607 int ret;
5599 5608
5600 if (err) 5609 if (err)
5601 goto out_done; 5610 goto out_done;
5602 5611again:
5603 ret = btrfs_dec_test_ordered_pending(inode, &ordered, 5612 ret = btrfs_dec_test_first_ordered_pending(inode, &ordered,
5604 dip->logical_offset, dip->bytes); 5613 &ordered_offset,
5614 ordered_bytes);
5605 if (!ret) 5615 if (!ret)
5606 goto out_done; 5616 goto out_test;
5607 5617
5608 BUG_ON(!ordered); 5618 BUG_ON(!ordered);
5609 5619
@@ -5663,8 +5673,20 @@ out_unlock:
5663out: 5673out:
5664 btrfs_delalloc_release_metadata(inode, ordered->len); 5674 btrfs_delalloc_release_metadata(inode, ordered->len);
5665 btrfs_end_transaction(trans, root); 5675 btrfs_end_transaction(trans, root);
5676 ordered_offset = ordered->file_offset + ordered->len;
5666 btrfs_put_ordered_extent(ordered); 5677 btrfs_put_ordered_extent(ordered);
5667 btrfs_put_ordered_extent(ordered); 5678 btrfs_put_ordered_extent(ordered);
5679
5680out_test:
5681 /*
5682 * our bio might span multiple ordered extents. If we haven't
5683 * completed the accounting for the whole dio, go back and try again
5684 */
5685 if (ordered_offset < dip->logical_offset + dip->bytes) {
5686 ordered_bytes = dip->logical_offset + dip->bytes -
5687 ordered_offset;
5688 goto again;
5689 }
5668out_done: 5690out_done:
5669 bio->bi_private = dip->private; 5691 bio->bi_private = dip->private;
5670 5692
@@ -5684,6 +5706,176 @@ static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw,
5684 return 0; 5706 return 0;
5685} 5707}
5686 5708
5709static void btrfs_end_dio_bio(struct bio *bio, int err)
5710{
5711 struct btrfs_dio_private *dip = bio->bi_private;
5712
5713 if (err) {
5714 printk(KERN_ERR "btrfs direct IO failed ino %lu rw %lu "
5715 "sector %#Lx len %u err no %d\n",
5716 dip->inode->i_ino, bio->bi_rw,
5717 (unsigned long long)bio->bi_sector, bio->bi_size, err);
5718 dip->errors = 1;
5719
5720 /*
5721 * before atomic variable goto zero, we must make sure
5722 * dip->errors is perceived to be set.
5723 */
5724 smp_mb__before_atomic_dec();
5725 }
5726
5727 /* if there are more bios still pending for this dio, just exit */
5728 if (!atomic_dec_and_test(&dip->pending_bios))
5729 goto out;
5730
5731 if (dip->errors)
5732 bio_io_error(dip->orig_bio);
5733 else {
5734 set_bit(BIO_UPTODATE, &dip->orig_bio->bi_flags);
5735 bio_endio(dip->orig_bio, 0);
5736 }
5737out:
5738 bio_put(bio);
5739}
5740
5741static struct bio *btrfs_dio_bio_alloc(struct block_device *bdev,
5742 u64 first_sector, gfp_t gfp_flags)
5743{
5744 int nr_vecs = bio_get_nr_vecs(bdev);
5745 return btrfs_bio_alloc(bdev, first_sector, nr_vecs, gfp_flags);
5746}
5747
5748static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode,
5749 int rw, u64 file_offset, int skip_sum,
5750 u32 *csums)
5751{
5752 int write = rw & REQ_WRITE;
5753 struct btrfs_root *root = BTRFS_I(inode)->root;
5754 int ret;
5755
5756 bio_get(bio);
5757 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0);
5758 if (ret)
5759 goto err;
5760
5761 if (write && !skip_sum) {
5762 ret = btrfs_wq_submit_bio(root->fs_info,
5763 inode, rw, bio, 0, 0,
5764 file_offset,
5765 __btrfs_submit_bio_start_direct_io,
5766 __btrfs_submit_bio_done);
5767 goto err;
5768 } else if (!skip_sum)
5769 btrfs_lookup_bio_sums_dio(root, inode, bio,
5770 file_offset, csums);
5771
5772 ret = btrfs_map_bio(root, rw, bio, 0, 1);
5773err:
5774 bio_put(bio);
5775 return ret;
5776}
5777
5778static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,
5779 int skip_sum)
5780{
5781 struct inode *inode = dip->inode;
5782 struct btrfs_root *root = BTRFS_I(inode)->root;
5783 struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree;
5784 struct bio *bio;
5785 struct bio *orig_bio = dip->orig_bio;
5786 struct bio_vec *bvec = orig_bio->bi_io_vec;
5787 u64 start_sector = orig_bio->bi_sector;
5788 u64 file_offset = dip->logical_offset;
5789 u64 submit_len = 0;
5790 u64 map_length;
5791 int nr_pages = 0;
5792 u32 *csums = dip->csums;
5793 int ret = 0;
5794
5795 bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS);
5796 if (!bio)
5797 return -ENOMEM;
5798 bio->bi_private = dip;
5799 bio->bi_end_io = btrfs_end_dio_bio;
5800 atomic_inc(&dip->pending_bios);
5801
5802 map_length = orig_bio->bi_size;
5803 ret = btrfs_map_block(map_tree, READ, start_sector << 9,
5804 &map_length, NULL, 0);
5805 if (ret) {
5806 bio_put(bio);
5807 return -EIO;
5808 }
5809
5810 while (bvec <= (orig_bio->bi_io_vec + orig_bio->bi_vcnt - 1)) {
5811 if (unlikely(map_length < submit_len + bvec->bv_len ||
5812 bio_add_page(bio, bvec->bv_page, bvec->bv_len,
5813 bvec->bv_offset) < bvec->bv_len)) {
5814 /*
5815 * inc the count before we submit the bio so
5816 * we know the end IO handler won't happen before
5817 * we inc the count. Otherwise, the dip might get freed
5818 * before we're done setting it up
5819 */
5820 atomic_inc(&dip->pending_bios);
5821 ret = __btrfs_submit_dio_bio(bio, inode, rw,
5822 file_offset, skip_sum,
5823 csums);
5824 if (ret) {
5825 bio_put(bio);
5826 atomic_dec(&dip->pending_bios);
5827 goto out_err;
5828 }
5829
5830 if (!skip_sum)
5831 csums = csums + nr_pages;
5832 start_sector += submit_len >> 9;
5833 file_offset += submit_len;
5834
5835 submit_len = 0;
5836 nr_pages = 0;
5837
5838 bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev,
5839 start_sector, GFP_NOFS);
5840 if (!bio)
5841 goto out_err;
5842 bio->bi_private = dip;
5843 bio->bi_end_io = btrfs_end_dio_bio;
5844
5845 map_length = orig_bio->bi_size;
5846 ret = btrfs_map_block(map_tree, READ, start_sector << 9,
5847 &map_length, NULL, 0);
5848 if (ret) {
5849 bio_put(bio);
5850 goto out_err;
5851 }
5852 } else {
5853 submit_len += bvec->bv_len;
5854 nr_pages ++;
5855 bvec++;
5856 }
5857 }
5858
5859 ret = __btrfs_submit_dio_bio(bio, inode, rw, file_offset, skip_sum,
5860 csums);
5861 if (!ret)
5862 return 0;
5863
5864 bio_put(bio);
5865out_err:
5866 dip->errors = 1;
5867 /*
5868 * before atomic variable goto zero, we must
5869 * make sure dip->errors is perceived to be set.
5870 */
5871 smp_mb__before_atomic_dec();
5872 if (atomic_dec_and_test(&dip->pending_bios))
5873 bio_io_error(dip->orig_bio);
5874
5875 /* bio_end_io() will handle error, so we needn't return it */
5876 return 0;
5877}
5878
5687static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode, 5879static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode,
5688 loff_t file_offset) 5880 loff_t file_offset)
5689{ 5881{
@@ -5723,36 +5915,18 @@ static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode,
5723 5915
5724 dip->disk_bytenr = (u64)bio->bi_sector << 9; 5916 dip->disk_bytenr = (u64)bio->bi_sector << 9;
5725 bio->bi_private = dip; 5917 bio->bi_private = dip;
5918 dip->errors = 0;
5919 dip->orig_bio = bio;
5920 atomic_set(&dip->pending_bios, 0);
5726 5921
5727 if (write) 5922 if (write)
5728 bio->bi_end_io = btrfs_endio_direct_write; 5923 bio->bi_end_io = btrfs_endio_direct_write;
5729 else 5924 else
5730 bio->bi_end_io = btrfs_endio_direct_read; 5925 bio->bi_end_io = btrfs_endio_direct_read;
5731 5926
5732 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 5927 ret = btrfs_submit_direct_hook(rw, dip, skip_sum);
5733 if (ret) 5928 if (!ret)
5734 goto out_err;
5735
5736 if (write && !skip_sum) {
5737 ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info,
5738 inode, rw, bio, 0, 0,
5739 dip->logical_offset,
5740 __btrfs_submit_bio_start_direct_io,
5741 __btrfs_submit_bio_done);
5742 if (ret)
5743 goto out_err;
5744 return; 5929 return;
5745 } else if (!skip_sum)
5746 btrfs_lookup_bio_sums_dio(root, inode, bio,
5747 dip->logical_offset, dip->csums);
5748
5749 ret = btrfs_map_bio(root, rw, bio, 0, 1);
5750 if (ret)
5751 goto out_err;
5752 return;
5753out_err:
5754 kfree(dip->csums);
5755 kfree(dip);
5756free_ordered: 5930free_ordered:
5757 /* 5931 /*
5758 * If this is a write, we need to clean up the reserved space and kill 5932 * If this is a write, we need to clean up the reserved space and kill
@@ -5760,8 +5934,7 @@ free_ordered:
5760 */ 5934 */
5761 if (write) { 5935 if (write) {
5762 struct btrfs_ordered_extent *ordered; 5936 struct btrfs_ordered_extent *ordered;
5763 ordered = btrfs_lookup_ordered_extent(inode, 5937 ordered = btrfs_lookup_ordered_extent(inode, file_offset);
5764 dip->logical_offset);
5765 if (!test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags) && 5938 if (!test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags) &&
5766 !test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) 5939 !test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags))
5767 btrfs_free_reserved_extent(root, ordered->start, 5940 btrfs_free_reserved_extent(root, ordered->start,
@@ -6607,8 +6780,9 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
6607 BUG_ON(ret); 6780 BUG_ON(ret);
6608 6781
6609 if (old_inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) { 6782 if (old_inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) {
6610 btrfs_log_new_name(trans, old_inode, old_dir, 6783 struct dentry *parent = dget_parent(new_dentry);
6611 new_dentry->d_parent); 6784 btrfs_log_new_name(trans, old_inode, old_dir, parent);
6785 dput(parent);
6612 btrfs_end_log_trans(root); 6786 btrfs_end_log_trans(root);
6613 } 6787 }
6614out_fail: 6788out_fail:
@@ -6758,8 +6932,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
6758 btrfs_set_trans_block_group(trans, dir); 6932 btrfs_set_trans_block_group(trans, dir);
6759 6933
6760 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 6934 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name,
6761 dentry->d_name.len, 6935 dentry->d_name.len, dir->i_ino, objectid,
6762 dentry->d_parent->d_inode->i_ino, objectid,
6763 BTRFS_I(dir)->block_group, S_IFLNK|S_IRWXUGO, 6936 BTRFS_I(dir)->block_group, S_IFLNK|S_IRWXUGO,
6764 &index); 6937 &index);
6765 err = PTR_ERR(inode); 6938 err = PTR_ERR(inode);
@@ -6773,7 +6946,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
6773 } 6946 }
6774 6947
6775 btrfs_set_trans_block_group(trans, inode); 6948 btrfs_set_trans_block_group(trans, inode);
6776 err = btrfs_add_nondir(trans, dentry, inode, 0, index); 6949 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
6777 if (err) 6950 if (err)
6778 drop_inode = 1; 6951 drop_inode = 1;
6779 else { 6952 else {
@@ -6844,6 +7017,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
6844 struct btrfs_root *root = BTRFS_I(inode)->root; 7017 struct btrfs_root *root = BTRFS_I(inode)->root;
6845 struct btrfs_key ins; 7018 struct btrfs_key ins;
6846 u64 cur_offset = start; 7019 u64 cur_offset = start;
7020 u64 i_size;
6847 int ret = 0; 7021 int ret = 0;
6848 bool own_trans = true; 7022 bool own_trans = true;
6849 7023
@@ -6885,11 +7059,11 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
6885 (actual_len > inode->i_size) && 7059 (actual_len > inode->i_size) &&
6886 (cur_offset > inode->i_size)) { 7060 (cur_offset > inode->i_size)) {
6887 if (cur_offset > actual_len) 7061 if (cur_offset > actual_len)
6888 i_size_write(inode, actual_len); 7062 i_size = actual_len;
6889 else 7063 else
6890 i_size_write(inode, cur_offset); 7064 i_size = cur_offset;
6891 i_size_write(inode, cur_offset); 7065 i_size_write(inode, i_size);
6892 btrfs_ordered_update_i_size(inode, cur_offset, NULL); 7066 btrfs_ordered_update_i_size(inode, i_size, NULL);
6893 } 7067 }
6894 7068
6895 ret = btrfs_update_inode(trans, root, inode); 7069 ret = btrfs_update_inode(trans, root, inode);
@@ -6943,6 +7117,10 @@ static long btrfs_fallocate(struct inode *inode, int mode,
6943 btrfs_wait_ordered_range(inode, alloc_start, alloc_end - alloc_start); 7117 btrfs_wait_ordered_range(inode, alloc_start, alloc_end - alloc_start);
6944 7118
6945 mutex_lock(&inode->i_mutex); 7119 mutex_lock(&inode->i_mutex);
7120 ret = inode_newsize_ok(inode, alloc_end);
7121 if (ret)
7122 goto out;
7123
6946 if (alloc_start > inode->i_size) { 7124 if (alloc_start > inode->i_size) {
6947 ret = btrfs_cont_expand(inode, alloc_start); 7125 ret = btrfs_cont_expand(inode, alloc_start);
6948 if (ret) 7126 if (ret)
@@ -7139,6 +7317,7 @@ static const struct inode_operations btrfs_symlink_inode_operations = {
7139 .readlink = generic_readlink, 7317 .readlink = generic_readlink,
7140 .follow_link = page_follow_link_light, 7318 .follow_link = page_follow_link_light,
7141 .put_link = page_put_link, 7319 .put_link = page_put_link,
7320 .getattr = btrfs_getattr,
7142 .permission = btrfs_permission, 7321 .permission = btrfs_permission,
7143 .setxattr = btrfs_setxattr, 7322 .setxattr = btrfs_setxattr,
7144 .getxattr = btrfs_getxattr, 7323 .getxattr = btrfs_getxattr,
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 463d91b4dd3a..f87552a1d7ea 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -233,7 +233,8 @@ static noinline int create_subvol(struct btrfs_root *root,
233 struct btrfs_inode_item *inode_item; 233 struct btrfs_inode_item *inode_item;
234 struct extent_buffer *leaf; 234 struct extent_buffer *leaf;
235 struct btrfs_root *new_root; 235 struct btrfs_root *new_root;
236 struct inode *dir = dentry->d_parent->d_inode; 236 struct dentry *parent = dget_parent(dentry);
237 struct inode *dir;
237 int ret; 238 int ret;
238 int err; 239 int err;
239 u64 objectid; 240 u64 objectid;
@@ -242,8 +243,13 @@ static noinline int create_subvol(struct btrfs_root *root,
242 243
243 ret = btrfs_find_free_objectid(NULL, root->fs_info->tree_root, 244 ret = btrfs_find_free_objectid(NULL, root->fs_info->tree_root,
244 0, &objectid); 245 0, &objectid);
245 if (ret) 246 if (ret) {
247 dput(parent);
246 return ret; 248 return ret;
249 }
250
251 dir = parent->d_inode;
252
247 /* 253 /*
248 * 1 - inode item 254 * 1 - inode item
249 * 2 - refs 255 * 2 - refs
@@ -251,8 +257,10 @@ static noinline int create_subvol(struct btrfs_root *root,
251 * 2 - dir items 257 * 2 - dir items
252 */ 258 */
253 trans = btrfs_start_transaction(root, 6); 259 trans = btrfs_start_transaction(root, 6);
254 if (IS_ERR(trans)) 260 if (IS_ERR(trans)) {
261 dput(parent);
255 return PTR_ERR(trans); 262 return PTR_ERR(trans);
263 }
256 264
257 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 265 leaf = btrfs_alloc_free_block(trans, root, root->leafsize,
258 0, objectid, NULL, 0, 0, 0); 266 0, objectid, NULL, 0, 0, 0);
@@ -339,6 +347,7 @@ static noinline int create_subvol(struct btrfs_root *root,
339 347
340 d_instantiate(dentry, btrfs_lookup_dentry(dir, dentry)); 348 d_instantiate(dentry, btrfs_lookup_dentry(dir, dentry));
341fail: 349fail:
350 dput(parent);
342 if (async_transid) { 351 if (async_transid) {
343 *async_transid = trans->transid; 352 *async_transid = trans->transid;
344 err = btrfs_commit_transaction_async(trans, root, 1); 353 err = btrfs_commit_transaction_async(trans, root, 1);
@@ -354,6 +363,7 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,
354 char *name, int namelen, u64 *async_transid) 363 char *name, int namelen, u64 *async_transid)
355{ 364{
356 struct inode *inode; 365 struct inode *inode;
366 struct dentry *parent;
357 struct btrfs_pending_snapshot *pending_snapshot; 367 struct btrfs_pending_snapshot *pending_snapshot;
358 struct btrfs_trans_handle *trans; 368 struct btrfs_trans_handle *trans;
359 int ret; 369 int ret;
@@ -396,7 +406,9 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,
396 406
397 btrfs_orphan_cleanup(pending_snapshot->snap); 407 btrfs_orphan_cleanup(pending_snapshot->snap);
398 408
399 inode = btrfs_lookup_dentry(dentry->d_parent->d_inode, dentry); 409 parent = dget_parent(dentry);
410 inode = btrfs_lookup_dentry(parent->d_inode, dentry);
411 dput(parent);
400 if (IS_ERR(inode)) { 412 if (IS_ERR(inode)) {
401 ret = PTR_ERR(inode); 413 ret = PTR_ERR(inode);
402 goto fail; 414 goto fail;
@@ -935,23 +947,42 @@ out:
935 947
936static noinline int btrfs_ioctl_snap_create(struct file *file, 948static noinline int btrfs_ioctl_snap_create(struct file *file,
937 void __user *arg, int subvol, 949 void __user *arg, int subvol,
938 int async) 950 int v2)
939{ 951{
940 struct btrfs_ioctl_vol_args *vol_args = NULL; 952 struct btrfs_ioctl_vol_args *vol_args = NULL;
941 struct btrfs_ioctl_async_vol_args *async_vol_args = NULL; 953 struct btrfs_ioctl_vol_args_v2 *vol_args_v2 = NULL;
942 char *name; 954 char *name;
943 u64 fd; 955 u64 fd;
944 u64 transid = 0;
945 int ret; 956 int ret;
946 957
947 if (async) { 958 if (v2) {
948 async_vol_args = memdup_user(arg, sizeof(*async_vol_args)); 959 u64 transid = 0;
949 if (IS_ERR(async_vol_args)) 960 u64 *ptr = NULL;
950 return PTR_ERR(async_vol_args); 961
962 vol_args_v2 = memdup_user(arg, sizeof(*vol_args_v2));
963 if (IS_ERR(vol_args_v2))
964 return PTR_ERR(vol_args_v2);
965
966 if (vol_args_v2->flags & ~BTRFS_SUBVOL_CREATE_ASYNC) {
967 ret = -EINVAL;
968 goto out;
969 }
970
971 name = vol_args_v2->name;
972 fd = vol_args_v2->fd;
973 vol_args_v2->name[BTRFS_SUBVOL_NAME_MAX] = '\0';
974
975 if (vol_args_v2->flags & BTRFS_SUBVOL_CREATE_ASYNC)
976 ptr = &transid;
977
978 ret = btrfs_ioctl_snap_create_transid(file, name, fd,
979 subvol, ptr);
951 980
952 name = async_vol_args->name; 981 if (ret == 0 && ptr &&
953 fd = async_vol_args->fd; 982 copy_to_user(arg +
954 async_vol_args->name[BTRFS_SNAPSHOT_NAME_MAX] = '\0'; 983 offsetof(struct btrfs_ioctl_vol_args_v2,
984 transid), ptr, sizeof(*ptr)))
985 ret = -EFAULT;
955 } else { 986 } else {
956 vol_args = memdup_user(arg, sizeof(*vol_args)); 987 vol_args = memdup_user(arg, sizeof(*vol_args));
957 if (IS_ERR(vol_args)) 988 if (IS_ERR(vol_args))
@@ -959,20 +990,13 @@ static noinline int btrfs_ioctl_snap_create(struct file *file,
959 name = vol_args->name; 990 name = vol_args->name;
960 fd = vol_args->fd; 991 fd = vol_args->fd;
961 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; 992 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
962 }
963
964 ret = btrfs_ioctl_snap_create_transid(file, name, fd,
965 subvol, &transid);
966 993
967 if (!ret && async) { 994 ret = btrfs_ioctl_snap_create_transid(file, name, fd,
968 if (copy_to_user(arg + 995 subvol, NULL);
969 offsetof(struct btrfs_ioctl_async_vol_args,
970 transid), &transid, sizeof(transid)))
971 return -EFAULT;
972 } 996 }
973 997out:
974 kfree(vol_args); 998 kfree(vol_args);
975 kfree(async_vol_args); 999 kfree(vol_args_v2);
976 1000
977 return ret; 1001 return ret;
978} 1002}
@@ -1669,12 +1693,11 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
1669 olen = len = src->i_size - off; 1693 olen = len = src->i_size - off;
1670 /* if we extend to eof, continue to block boundary */ 1694 /* if we extend to eof, continue to block boundary */
1671 if (off + len == src->i_size) 1695 if (off + len == src->i_size)
1672 len = ((src->i_size + bs-1) & ~(bs-1)) 1696 len = ALIGN(src->i_size, bs) - off;
1673 - off;
1674 1697
1675 /* verify the end result is block aligned */ 1698 /* verify the end result is block aligned */
1676 if ((off & (bs-1)) || 1699 if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs) ||
1677 ((off + len) & (bs-1))) 1700 !IS_ALIGNED(destoff, bs))
1678 goto out_unlock; 1701 goto out_unlock;
1679 1702
1680 /* do any pending delalloc/csum calc on src, one way or 1703 /* do any pending delalloc/csum calc on src, one way or
@@ -1874,8 +1897,8 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
1874 * but shouldn't round up the file size 1897 * but shouldn't round up the file size
1875 */ 1898 */
1876 endoff = new_key.offset + datal; 1899 endoff = new_key.offset + datal;
1877 if (endoff > off+olen) 1900 if (endoff > destoff+olen)
1878 endoff = off+olen; 1901 endoff = destoff+olen;
1879 if (endoff > inode->i_size) 1902 if (endoff > inode->i_size)
1880 btrfs_i_size_write(inode, endoff); 1903 btrfs_i_size_write(inode, endoff);
1881 1904
@@ -2235,7 +2258,7 @@ long btrfs_ioctl(struct file *file, unsigned int
2235 return btrfs_ioctl_getversion(file, argp); 2258 return btrfs_ioctl_getversion(file, argp);
2236 case BTRFS_IOC_SNAP_CREATE: 2259 case BTRFS_IOC_SNAP_CREATE:
2237 return btrfs_ioctl_snap_create(file, argp, 0, 0); 2260 return btrfs_ioctl_snap_create(file, argp, 0, 0);
2238 case BTRFS_IOC_SNAP_CREATE_ASYNC: 2261 case BTRFS_IOC_SNAP_CREATE_V2:
2239 return btrfs_ioctl_snap_create(file, argp, 0, 1); 2262 return btrfs_ioctl_snap_create(file, argp, 0, 1);
2240 case BTRFS_IOC_SUBVOL_CREATE: 2263 case BTRFS_IOC_SUBVOL_CREATE:
2241 return btrfs_ioctl_snap_create(file, argp, 1, 0); 2264 return btrfs_ioctl_snap_create(file, argp, 1, 0);
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 17c99ebdf960..c344d12c646b 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -30,11 +30,15 @@ struct btrfs_ioctl_vol_args {
30 char name[BTRFS_PATH_NAME_MAX + 1]; 30 char name[BTRFS_PATH_NAME_MAX + 1];
31}; 31};
32 32
33#define BTRFS_SNAPSHOT_NAME_MAX 4079 33#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
34struct btrfs_ioctl_async_vol_args { 34
35#define BTRFS_SUBVOL_NAME_MAX 4039
36struct btrfs_ioctl_vol_args_v2 {
35 __s64 fd; 37 __s64 fd;
36 __u64 transid; 38 __u64 transid;
37 char name[BTRFS_SNAPSHOT_NAME_MAX + 1]; 39 __u64 flags;
40 __u64 unused[4];
41 char name[BTRFS_SUBVOL_NAME_MAX + 1];
38}; 42};
39 43
40#define BTRFS_INO_LOOKUP_PATH_MAX 4080 44#define BTRFS_INO_LOOKUP_PATH_MAX 4080
@@ -187,6 +191,6 @@ struct btrfs_ioctl_space_args {
187 struct btrfs_ioctl_space_args) 191 struct btrfs_ioctl_space_args)
188#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64) 192#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
189#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64) 193#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
190#define BTRFS_IOC_SNAP_CREATE_ASYNC _IOW(BTRFS_IOCTL_MAGIC, 23, \ 194#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
191 struct btrfs_ioctl_async_vol_args) 195 struct btrfs_ioctl_vol_args_v2)
192#endif 196#endif
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index f4621f6deca1..ae7737e352c9 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -250,6 +250,73 @@ int btrfs_add_ordered_sum(struct inode *inode,
250 250
251/* 251/*
252 * this is used to account for finished IO across a given range 252 * this is used to account for finished IO across a given range
253 * of the file. The IO may span ordered extents. If
254 * a given ordered_extent is completely done, 1 is returned, otherwise
255 * 0.
256 *
257 * test_and_set_bit on a flag in the struct btrfs_ordered_extent is used
258 * to make sure this function only returns 1 once for a given ordered extent.
259 *
260 * file_offset is updated to one byte past the range that is recorded as
261 * complete. This allows you to walk forward in the file.
262 */
263int btrfs_dec_test_first_ordered_pending(struct inode *inode,
264 struct btrfs_ordered_extent **cached,
265 u64 *file_offset, u64 io_size)
266{
267 struct btrfs_ordered_inode_tree *tree;
268 struct rb_node *node;
269 struct btrfs_ordered_extent *entry = NULL;
270 int ret;
271 u64 dec_end;
272 u64 dec_start;
273 u64 to_dec;
274
275 tree = &BTRFS_I(inode)->ordered_tree;
276 spin_lock(&tree->lock);
277 node = tree_search(tree, *file_offset);
278 if (!node) {
279 ret = 1;
280 goto out;
281 }
282
283 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node);
284 if (!offset_in_entry(entry, *file_offset)) {
285 ret = 1;
286 goto out;
287 }
288
289 dec_start = max(*file_offset, entry->file_offset);
290 dec_end = min(*file_offset + io_size, entry->file_offset +
291 entry->len);
292 *file_offset = dec_end;
293 if (dec_start > dec_end) {
294 printk(KERN_CRIT "bad ordering dec_start %llu end %llu\n",
295 (unsigned long long)dec_start,
296 (unsigned long long)dec_end);
297 }
298 to_dec = dec_end - dec_start;
299 if (to_dec > entry->bytes_left) {
300 printk(KERN_CRIT "bad ordered accounting left %llu size %llu\n",
301 (unsigned long long)entry->bytes_left,
302 (unsigned long long)to_dec);
303 }
304 entry->bytes_left -= to_dec;
305 if (entry->bytes_left == 0)
306 ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags);
307 else
308 ret = 1;
309out:
310 if (!ret && cached && entry) {
311 *cached = entry;
312 atomic_inc(&entry->refs);
313 }
314 spin_unlock(&tree->lock);
315 return ret == 0;
316}
317
318/*
319 * this is used to account for finished IO across a given range
253 * of the file. The IO should not span ordered extents. If 320 * of the file. The IO should not span ordered extents. If
254 * a given ordered_extent is completely done, 1 is returned, otherwise 321 * a given ordered_extent is completely done, 1 is returned, otherwise
255 * 0. 322 * 0.
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 8ac365492a3f..61dca83119dd 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -141,6 +141,9 @@ int btrfs_remove_ordered_extent(struct inode *inode,
141int btrfs_dec_test_ordered_pending(struct inode *inode, 141int btrfs_dec_test_ordered_pending(struct inode *inode,
142 struct btrfs_ordered_extent **cached, 142 struct btrfs_ordered_extent **cached,
143 u64 file_offset, u64 io_size); 143 u64 file_offset, u64 io_size);
144int btrfs_dec_test_first_ordered_pending(struct inode *inode,
145 struct btrfs_ordered_extent **cached,
146 u64 *file_offset, u64 io_size);
144int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, 147int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
145 u64 start, u64 len, u64 disk_len, int type); 148 u64 start, u64 len, u64 disk_len, int type);
146int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset, 149int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset,
diff --git a/fs/btrfs/orphan.c b/fs/btrfs/orphan.c
index 79cba5fbc28e..f8be250963a0 100644
--- a/fs/btrfs/orphan.c
+++ b/fs/btrfs/orphan.c
@@ -56,8 +56,12 @@ int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
56 return -ENOMEM; 56 return -ENOMEM;
57 57
58 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 58 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
59 if (ret) 59 if (ret < 0)
60 goto out; 60 goto out;
61 if (ret) {
62 ret = -ENOENT;
63 goto out;
64 }
61 65
62 ret = btrfs_del_item(trans, root, path); 66 ret = btrfs_del_item(trans, root, path);
63 67
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 8299a25ffc8f..883c6fa1367e 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -244,6 +244,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
244 case Opt_space_cache: 244 case Opt_space_cache:
245 printk(KERN_INFO "btrfs: enabling disk space caching\n"); 245 printk(KERN_INFO "btrfs: enabling disk space caching\n");
246 btrfs_set_opt(info->mount_opt, SPACE_CACHE); 246 btrfs_set_opt(info->mount_opt, SPACE_CACHE);
247 break;
247 case Opt_clear_cache: 248 case Opt_clear_cache:
248 printk(KERN_INFO "btrfs: force clearing of disk cache\n"); 249 printk(KERN_INFO "btrfs: force clearing of disk cache\n");
249 btrfs_set_opt(info->mount_opt, CLEAR_CACHE); 250 btrfs_set_opt(info->mount_opt, CLEAR_CACHE);
@@ -562,12 +563,26 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
562 563
563static int btrfs_test_super(struct super_block *s, void *data) 564static int btrfs_test_super(struct super_block *s, void *data)
564{ 565{
565 struct btrfs_fs_devices *test_fs_devices = data; 566 struct btrfs_root *test_root = data;
566 struct btrfs_root *root = btrfs_sb(s); 567 struct btrfs_root *root = btrfs_sb(s);
567 568
568 return root->fs_info->fs_devices == test_fs_devices; 569 /*
570 * If this super block is going away, return false as it
571 * can't match as an existing super block.
572 */
573 if (!atomic_read(&s->s_active))
574 return 0;
575 return root->fs_info->fs_devices == test_root->fs_info->fs_devices;
576}
577
578static int btrfs_set_super(struct super_block *s, void *data)
579{
580 s->s_fs_info = data;
581
582 return set_anon_super(s, data);
569} 583}
570 584
585
571/* 586/*
572 * Find a superblock for the given device / mount point. 587 * Find a superblock for the given device / mount point.
573 * 588 *
@@ -581,6 +596,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
581 struct super_block *s; 596 struct super_block *s;
582 struct dentry *root; 597 struct dentry *root;
583 struct btrfs_fs_devices *fs_devices = NULL; 598 struct btrfs_fs_devices *fs_devices = NULL;
599 struct btrfs_root *tree_root = NULL;
600 struct btrfs_fs_info *fs_info = NULL;
584 fmode_t mode = FMODE_READ; 601 fmode_t mode = FMODE_READ;
585 char *subvol_name = NULL; 602 char *subvol_name = NULL;
586 u64 subvol_objectid = 0; 603 u64 subvol_objectid = 0;
@@ -608,8 +625,24 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
608 goto error_close_devices; 625 goto error_close_devices;
609 } 626 }
610 627
628 /*
629 * Setup a dummy root and fs_info for test/set super. This is because
630 * we don't actually fill this stuff out until open_ctree, but we need
631 * it for searching for existing supers, so this lets us do that and
632 * then open_ctree will properly initialize everything later.
633 */
634 fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS);
635 tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
636 if (!fs_info || !tree_root) {
637 error = -ENOMEM;
638 goto error_close_devices;
639 }
640 fs_info->tree_root = tree_root;
641 fs_info->fs_devices = fs_devices;
642 tree_root->fs_info = fs_info;
643
611 bdev = fs_devices->latest_bdev; 644 bdev = fs_devices->latest_bdev;
612 s = sget(fs_type, btrfs_test_super, set_anon_super, fs_devices); 645 s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root);
613 if (IS_ERR(s)) 646 if (IS_ERR(s))
614 goto error_s; 647 goto error_s;
615 648
@@ -652,9 +685,9 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
652 mutex_unlock(&root->d_inode->i_mutex); 685 mutex_unlock(&root->d_inode->i_mutex);
653 686
654 if (IS_ERR(new_root)) { 687 if (IS_ERR(new_root)) {
688 dput(root);
655 deactivate_locked_super(s); 689 deactivate_locked_super(s);
656 error = PTR_ERR(new_root); 690 error = PTR_ERR(new_root);
657 dput(root);
658 goto error_free_subvol_name; 691 goto error_free_subvol_name;
659 } 692 }
660 if (!new_root->d_inode) { 693 if (!new_root->d_inode) {
@@ -675,6 +708,8 @@ error_s:
675 error = PTR_ERR(s); 708 error = PTR_ERR(s);
676error_close_devices: 709error_close_devices:
677 btrfs_close_devices(fs_devices); 710 btrfs_close_devices(fs_devices);
711 kfree(fs_info);
712 kfree(tree_root);
678error_free_subvol_name: 713error_free_subvol_name:
679 kfree(subvol_name); 714 kfree(subvol_name);
680 return ERR_PTR(error); 715 return ERR_PTR(error);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 1fffbc017bdf..f50e931fc217 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -902,6 +902,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
902 struct btrfs_root *root = pending->root; 902 struct btrfs_root *root = pending->root;
903 struct btrfs_root *parent_root; 903 struct btrfs_root *parent_root;
904 struct inode *parent_inode; 904 struct inode *parent_inode;
905 struct dentry *parent;
905 struct dentry *dentry; 906 struct dentry *dentry;
906 struct extent_buffer *tmp; 907 struct extent_buffer *tmp;
907 struct extent_buffer *old; 908 struct extent_buffer *old;
@@ -941,7 +942,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
941 trans->block_rsv = &pending->block_rsv; 942 trans->block_rsv = &pending->block_rsv;
942 943
943 dentry = pending->dentry; 944 dentry = pending->dentry;
944 parent_inode = dentry->d_parent->d_inode; 945 parent = dget_parent(dentry);
946 parent_inode = parent->d_inode;
945 parent_root = BTRFS_I(parent_inode)->root; 947 parent_root = BTRFS_I(parent_inode)->root;
946 record_root_in_trans(trans, parent_root); 948 record_root_in_trans(trans, parent_root);
947 949
@@ -989,6 +991,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
989 parent_inode->i_ino, index, 991 parent_inode->i_ino, index,
990 dentry->d_name.name, dentry->d_name.len); 992 dentry->d_name.name, dentry->d_name.len);
991 BUG_ON(ret); 993 BUG_ON(ret);
994 dput(parent);
992 995
993 key.offset = (u64)-1; 996 key.offset = (u64)-1;
994 pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key); 997 pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index a29f19384a27..054744ac5719 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2869,6 +2869,7 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
2869{ 2869{
2870 int ret = 0; 2870 int ret = 0;
2871 struct btrfs_root *root; 2871 struct btrfs_root *root;
2872 struct dentry *old_parent = NULL;
2872 2873
2873 /* 2874 /*
2874 * for regular files, if its inode is already on disk, we don't 2875 * for regular files, if its inode is already on disk, we don't
@@ -2910,10 +2911,13 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
2910 if (IS_ROOT(parent)) 2911 if (IS_ROOT(parent))
2911 break; 2912 break;
2912 2913
2913 parent = parent->d_parent; 2914 parent = dget_parent(parent);
2915 dput(old_parent);
2916 old_parent = parent;
2914 inode = parent->d_inode; 2917 inode = parent->d_inode;
2915 2918
2916 } 2919 }
2920 dput(old_parent);
2917out: 2921out:
2918 return ret; 2922 return ret;
2919} 2923}
@@ -2945,6 +2949,7 @@ int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
2945{ 2949{
2946 int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL; 2950 int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL;
2947 struct super_block *sb; 2951 struct super_block *sb;
2952 struct dentry *old_parent = NULL;
2948 int ret = 0; 2953 int ret = 0;
2949 u64 last_committed = root->fs_info->last_trans_committed; 2954 u64 last_committed = root->fs_info->last_trans_committed;
2950 2955
@@ -3016,10 +3021,13 @@ int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
3016 if (IS_ROOT(parent)) 3021 if (IS_ROOT(parent))
3017 break; 3022 break;
3018 3023
3019 parent = parent->d_parent; 3024 parent = dget_parent(parent);
3025 dput(old_parent);
3026 old_parent = parent;
3020 } 3027 }
3021 ret = 0; 3028 ret = 0;
3022end_trans: 3029end_trans:
3030 dput(old_parent);
3023 if (ret < 0) { 3031 if (ret < 0) {
3024 BUG_ON(ret != -ENOSPC); 3032 BUG_ON(ret != -ENOSPC);
3025 root->fs_info->last_trans_log_full_commit = trans->transid; 3033 root->fs_info->last_trans_log_full_commit = trans->transid;
@@ -3039,8 +3047,13 @@ end_no_trans:
3039int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, 3047int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
3040 struct btrfs_root *root, struct dentry *dentry) 3048 struct btrfs_root *root, struct dentry *dentry)
3041{ 3049{
3042 return btrfs_log_inode_parent(trans, root, dentry->d_inode, 3050 struct dentry *parent = dget_parent(dentry);
3043 dentry->d_parent, 0); 3051 int ret;
3052
3053 ret = btrfs_log_inode_parent(trans, root, dentry->d_inode, parent, 0);
3054 dput(parent);
3055
3056 return ret;
3044} 3057}
3045 3058
3046/* 3059/*
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index cc04dc1445d6..6b9884507837 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -412,12 +412,16 @@ static noinline int device_list_add(const char *path,
412 412
413 device->fs_devices = fs_devices; 413 device->fs_devices = fs_devices;
414 fs_devices->num_devices++; 414 fs_devices->num_devices++;
415 } else if (strcmp(device->name, path)) { 415 } else if (!device->name || strcmp(device->name, path)) {
416 name = kstrdup(path, GFP_NOFS); 416 name = kstrdup(path, GFP_NOFS);
417 if (!name) 417 if (!name)
418 return -ENOMEM; 418 return -ENOMEM;
419 kfree(device->name); 419 kfree(device->name);
420 device->name = name; 420 device->name = name;
421 if (device->missing) {
422 fs_devices->missing_devices--;
423 device->missing = 0;
424 }
421 } 425 }
422 426
423 if (found_transid > fs_devices->latest_trans) { 427 if (found_transid > fs_devices->latest_trans) {
@@ -1236,6 +1240,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1236 1240
1237 device->fs_devices->num_devices--; 1241 device->fs_devices->num_devices--;
1238 1242
1243 if (device->missing)
1244 root->fs_info->fs_devices->missing_devices--;
1245
1239 next_device = list_entry(root->fs_info->fs_devices->devices.next, 1246 next_device = list_entry(root->fs_info->fs_devices->devices.next,
1240 struct btrfs_device, dev_list); 1247 struct btrfs_device, dev_list);
1241 if (device->bdev == root->fs_info->sb->s_bdev) 1248 if (device->bdev == root->fs_info->sb->s_bdev)
@@ -3080,7 +3087,9 @@ static struct btrfs_device *add_missing_dev(struct btrfs_root *root,
3080 device->devid = devid; 3087 device->devid = devid;
3081 device->work.func = pending_bios_fn; 3088 device->work.func = pending_bios_fn;
3082 device->fs_devices = fs_devices; 3089 device->fs_devices = fs_devices;
3090 device->missing = 1;
3083 fs_devices->num_devices++; 3091 fs_devices->num_devices++;
3092 fs_devices->missing_devices++;
3084 spin_lock_init(&device->io_lock); 3093 spin_lock_init(&device->io_lock);
3085 INIT_LIST_HEAD(&device->dev_alloc_list); 3094 INIT_LIST_HEAD(&device->dev_alloc_list);
3086 memcpy(device->uuid, dev_uuid, BTRFS_UUID_SIZE); 3095 memcpy(device->uuid, dev_uuid, BTRFS_UUID_SIZE);
@@ -3278,6 +3287,15 @@ static int read_one_dev(struct btrfs_root *root,
3278 device = add_missing_dev(root, devid, dev_uuid); 3287 device = add_missing_dev(root, devid, dev_uuid);
3279 if (!device) 3288 if (!device)
3280 return -ENOMEM; 3289 return -ENOMEM;
3290 } else if (!device->missing) {
3291 /*
3292 * this happens when a device that was properly setup
3293 * in the device info lists suddenly goes bad.
3294 * device->bdev is NULL, and so we have to set
3295 * device->missing to one here
3296 */
3297 root->fs_info->fs_devices->missing_devices++;
3298 device->missing = 1;
3281 } 3299 }
3282 } 3300 }
3283 3301
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2b638b6e4eea..2740db49eb04 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -44,6 +44,7 @@ struct btrfs_device {
44 44
45 int writeable; 45 int writeable;
46 int in_fs_metadata; 46 int in_fs_metadata;
47 int missing;
47 48
48 spinlock_t io_lock; 49 spinlock_t io_lock;
49 50
@@ -93,6 +94,7 @@ struct btrfs_fs_devices {
93 u64 num_devices; 94 u64 num_devices;
94 u64 open_devices; 95 u64 open_devices;
95 u64 rw_devices; 96 u64 rw_devices;
97 u64 missing_devices;
96 u64 total_rw_bytes; 98 u64 total_rw_bytes;
97 struct block_device *latest_bdev; 99 struct block_device *latest_bdev;
98 100
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index e9c874abc9e1..561438b6a50c 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -204,7 +204,7 @@ static int readpage_nounlock(struct file *filp, struct page *page)
204 err = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout, 204 err = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout,
205 page->index << PAGE_CACHE_SHIFT, &len, 205 page->index << PAGE_CACHE_SHIFT, &len,
206 ci->i_truncate_seq, ci->i_truncate_size, 206 ci->i_truncate_seq, ci->i_truncate_size,
207 &page, 1); 207 &page, 1, 0);
208 if (err == -ENOENT) 208 if (err == -ENOENT)
209 err = 0; 209 err = 0;
210 if (err < 0) { 210 if (err < 0) {
@@ -287,7 +287,7 @@ static int ceph_readpages(struct file *file, struct address_space *mapping,
287 rc = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout, 287 rc = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout,
288 offset, &len, 288 offset, &len,
289 ci->i_truncate_seq, ci->i_truncate_size, 289 ci->i_truncate_seq, ci->i_truncate_size,
290 pages, nr_pages); 290 pages, nr_pages, 0);
291 if (rc == -ENOENT) 291 if (rc == -ENOENT)
292 rc = 0; 292 rc = 0;
293 if (rc < 0) 293 if (rc < 0)
@@ -774,7 +774,7 @@ get_more_pages:
774 snapc, do_sync, 774 snapc, do_sync,
775 ci->i_truncate_seq, 775 ci->i_truncate_seq,
776 ci->i_truncate_size, 776 ci->i_truncate_size,
777 &inode->i_mtime, true, 1); 777 &inode->i_mtime, true, 1, 0);
778 max_pages = req->r_num_pages; 778 max_pages = req->r_num_pages;
779 779
780 alloc_page_vec(fsc, req); 780 alloc_page_vec(fsc, req);
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 98ab13e2b71d..60d27bc9eb83 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -1430,8 +1430,8 @@ static int try_nonblocking_invalidate(struct inode *inode)
1430 invalidating_gen == ci->i_rdcache_gen) { 1430 invalidating_gen == ci->i_rdcache_gen) {
1431 /* success. */ 1431 /* success. */
1432 dout("try_nonblocking_invalidate %p success\n", inode); 1432 dout("try_nonblocking_invalidate %p success\n", inode);
1433 ci->i_rdcache_gen = 0; 1433 /* save any racing async invalidate some trouble */
1434 ci->i_rdcache_revoking = 0; 1434 ci->i_rdcache_revoking = ci->i_rdcache_gen - 1;
1435 return 0; 1435 return 0;
1436 } 1436 }
1437 dout("try_nonblocking_invalidate %p failed\n", inode); 1437 dout("try_nonblocking_invalidate %p failed\n", inode);
@@ -2273,8 +2273,7 @@ static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
2273{ 2273{
2274 struct ceph_inode_info *ci = ceph_inode(inode); 2274 struct ceph_inode_info *ci = ceph_inode(inode);
2275 int mds = session->s_mds; 2275 int mds = session->s_mds;
2276 unsigned seq = le32_to_cpu(grant->seq); 2276 int seq = le32_to_cpu(grant->seq);
2277 unsigned issue_seq = le32_to_cpu(grant->issue_seq);
2278 int newcaps = le32_to_cpu(grant->caps); 2277 int newcaps = le32_to_cpu(grant->caps);
2279 int issued, implemented, used, wanted, dirty; 2278 int issued, implemented, used, wanted, dirty;
2280 u64 size = le64_to_cpu(grant->size); 2279 u64 size = le64_to_cpu(grant->size);
@@ -2286,8 +2285,8 @@ static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
2286 int revoked_rdcache = 0; 2285 int revoked_rdcache = 0;
2287 int queue_invalidate = 0; 2286 int queue_invalidate = 0;
2288 2287
2289 dout("handle_cap_grant inode %p cap %p mds%d seq %u/%u %s\n", 2288 dout("handle_cap_grant inode %p cap %p mds%d seq %d %s\n",
2290 inode, cap, mds, seq, issue_seq, ceph_cap_string(newcaps)); 2289 inode, cap, mds, seq, ceph_cap_string(newcaps));
2291 dout(" size %llu max_size %llu, i_size %llu\n", size, max_size, 2290 dout(" size %llu max_size %llu, i_size %llu\n", size, max_size,
2292 inode->i_size); 2291 inode->i_size);
2293 2292
@@ -2383,7 +2382,6 @@ static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
2383 } 2382 }
2384 2383
2385 cap->seq = seq; 2384 cap->seq = seq;
2386 cap->issue_seq = issue_seq;
2387 2385
2388 /* file layout may have changed */ 2386 /* file layout may have changed */
2389 ci->i_layout = grant->layout; 2387 ci->i_layout = grant->layout;
@@ -2691,6 +2689,11 @@ static void handle_cap_import(struct ceph_mds_client *mdsc,
2691 NULL /* no caps context */); 2689 NULL /* no caps context */);
2692 try_flush_caps(inode, session, NULL); 2690 try_flush_caps(inode, session, NULL);
2693 up_read(&mdsc->snap_rwsem); 2691 up_read(&mdsc->snap_rwsem);
2692
2693 /* make sure we re-request max_size, if necessary */
2694 spin_lock(&inode->i_lock);
2695 ci->i_requested_max_size = 0;
2696 spin_unlock(&inode->i_lock);
2694} 2697}
2695 2698
2696/* 2699/*
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index e0a2dc6fcafc..d902948a90d8 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -40,7 +40,8 @@ int ceph_init_dentry(struct dentry *dentry)
40 if (dentry->d_fsdata) 40 if (dentry->d_fsdata)
41 return 0; 41 return 0;
42 42
43 if (ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP) 43 if (dentry->d_parent == NULL || /* nfs fh_to_dentry */
44 ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP)
44 dentry->d_op = &ceph_dentry_ops; 45 dentry->d_op = &ceph_dentry_ops;
45 else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR) 46 else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR)
46 dentry->d_op = &ceph_snapdir_dentry_ops; 47 dentry->d_op = &ceph_snapdir_dentry_ops;
@@ -114,8 +115,8 @@ static int __dcache_readdir(struct file *filp,
114 spin_lock(&dcache_lock); 115 spin_lock(&dcache_lock);
115 116
116 /* start at beginning? */ 117 /* start at beginning? */
117 if (filp->f_pos == 2 || (last && 118 if (filp->f_pos == 2 || last == NULL ||
118 filp->f_pos < ceph_dentry(last)->offset)) { 119 filp->f_pos < ceph_dentry(last)->offset) {
119 if (list_empty(&parent->d_subdirs)) 120 if (list_empty(&parent->d_subdirs))
120 goto out_unlock; 121 goto out_unlock;
121 p = parent->d_subdirs.prev; 122 p = parent->d_subdirs.prev;
@@ -336,7 +337,10 @@ more:
336 if (req->r_reply_info.dir_end) { 337 if (req->r_reply_info.dir_end) {
337 kfree(fi->last_name); 338 kfree(fi->last_name);
338 fi->last_name = NULL; 339 fi->last_name = NULL;
339 fi->next_offset = 2; 340 if (ceph_frag_is_rightmost(frag))
341 fi->next_offset = 2;
342 else
343 fi->next_offset = 0;
340 } else { 344 } else {
341 rinfo = &req->r_reply_info; 345 rinfo = &req->r_reply_info;
342 err = note_last_dentry(fi, 346 err = note_last_dentry(fi,
@@ -355,18 +359,22 @@ more:
355 u64 pos = ceph_make_fpos(frag, off); 359 u64 pos = ceph_make_fpos(frag, off);
356 struct ceph_mds_reply_inode *in = 360 struct ceph_mds_reply_inode *in =
357 rinfo->dir_in[off - fi->offset].in; 361 rinfo->dir_in[off - fi->offset].in;
362 struct ceph_vino vino;
363 ino_t ino;
364
358 dout("readdir off %d (%d/%d) -> %lld '%.*s' %p\n", 365 dout("readdir off %d (%d/%d) -> %lld '%.*s' %p\n",
359 off, off - fi->offset, rinfo->dir_nr, pos, 366 off, off - fi->offset, rinfo->dir_nr, pos,
360 rinfo->dir_dname_len[off - fi->offset], 367 rinfo->dir_dname_len[off - fi->offset],
361 rinfo->dir_dname[off - fi->offset], in); 368 rinfo->dir_dname[off - fi->offset], in);
362 BUG_ON(!in); 369 BUG_ON(!in);
363 ftype = le32_to_cpu(in->mode) >> 12; 370 ftype = le32_to_cpu(in->mode) >> 12;
371 vino.ino = le64_to_cpu(in->ino);
372 vino.snap = le64_to_cpu(in->snapid);
373 ino = ceph_vino_to_ino(vino);
364 if (filldir(dirent, 374 if (filldir(dirent,
365 rinfo->dir_dname[off - fi->offset], 375 rinfo->dir_dname[off - fi->offset],
366 rinfo->dir_dname_len[off - fi->offset], 376 rinfo->dir_dname_len[off - fi->offset],
367 pos, 377 pos, ino, ftype) < 0) {
368 le64_to_cpu(in->ino),
369 ftype) < 0) {
370 dout("filldir stopping us...\n"); 378 dout("filldir stopping us...\n");
371 return 0; 379 return 0;
372 } 380 }
@@ -414,6 +422,7 @@ static void reset_readdir(struct ceph_file_info *fi)
414 fi->last_readdir = NULL; 422 fi->last_readdir = NULL;
415 } 423 }
416 kfree(fi->last_name); 424 kfree(fi->last_name);
425 fi->last_name = NULL;
417 fi->next_offset = 2; /* compensate for . and .. */ 426 fi->next_offset = 2; /* compensate for . and .. */
418 if (fi->dentry) { 427 if (fi->dentry) {
419 dput(fi->dentry); 428 dput(fi->dentry);
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index e77c28cf3690..7d0e4a82d898 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -154,11 +154,13 @@ int ceph_open(struct inode *inode, struct file *file)
154 } 154 }
155 155
156 /* 156 /*
157 * No need to block if we have any caps. Update wanted set 157 * No need to block if we have caps on the auth MDS (for
158 * write) or any MDS (for read). Update wanted set
158 * asynchronously. 159 * asynchronously.
159 */ 160 */
160 spin_lock(&inode->i_lock); 161 spin_lock(&inode->i_lock);
161 if (__ceph_is_any_real_caps(ci)) { 162 if (__ceph_is_any_real_caps(ci) &&
163 (((fmode & CEPH_FILE_MODE_WR) == 0) || ci->i_auth_cap)) {
162 int mds_wanted = __ceph_caps_mds_wanted(ci); 164 int mds_wanted = __ceph_caps_mds_wanted(ci);
163 int issued = __ceph_caps_issued(ci, NULL); 165 int issued = __ceph_caps_issued(ci, NULL);
164 166
@@ -280,11 +282,13 @@ int ceph_release(struct inode *inode, struct file *file)
280static int striped_read(struct inode *inode, 282static int striped_read(struct inode *inode,
281 u64 off, u64 len, 283 u64 off, u64 len,
282 struct page **pages, int num_pages, 284 struct page **pages, int num_pages,
283 int *checkeof) 285 int *checkeof, bool align_to_pages,
286 unsigned long buf_align)
284{ 287{
285 struct ceph_fs_client *fsc = ceph_inode_to_client(inode); 288 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
286 struct ceph_inode_info *ci = ceph_inode(inode); 289 struct ceph_inode_info *ci = ceph_inode(inode);
287 u64 pos, this_len; 290 u64 pos, this_len;
291 int io_align, page_align;
288 int page_off = off & ~PAGE_CACHE_MASK; /* first byte's offset in page */ 292 int page_off = off & ~PAGE_CACHE_MASK; /* first byte's offset in page */
289 int left, pages_left; 293 int left, pages_left;
290 int read; 294 int read;
@@ -300,14 +304,19 @@ static int striped_read(struct inode *inode,
300 page_pos = pages; 304 page_pos = pages;
301 pages_left = num_pages; 305 pages_left = num_pages;
302 read = 0; 306 read = 0;
307 io_align = off & ~PAGE_MASK;
303 308
304more: 309more:
310 if (align_to_pages)
311 page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
312 else
313 page_align = pos & ~PAGE_MASK;
305 this_len = left; 314 this_len = left;
306 ret = ceph_osdc_readpages(&fsc->client->osdc, ceph_vino(inode), 315 ret = ceph_osdc_readpages(&fsc->client->osdc, ceph_vino(inode),
307 &ci->i_layout, pos, &this_len, 316 &ci->i_layout, pos, &this_len,
308 ci->i_truncate_seq, 317 ci->i_truncate_seq,
309 ci->i_truncate_size, 318 ci->i_truncate_size,
310 page_pos, pages_left); 319 page_pos, pages_left, page_align);
311 hit_stripe = this_len < left; 320 hit_stripe = this_len < left;
312 was_short = ret >= 0 && ret < this_len; 321 was_short = ret >= 0 && ret < this_len;
313 if (ret == -ENOENT) 322 if (ret == -ENOENT)
@@ -368,32 +377,34 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
368 struct inode *inode = file->f_dentry->d_inode; 377 struct inode *inode = file->f_dentry->d_inode;
369 struct page **pages; 378 struct page **pages;
370 u64 off = *poff; 379 u64 off = *poff;
371 int num_pages = calc_pages_for(off, len); 380 int num_pages, ret;
372 int ret;
373 381
374 dout("sync_read on file %p %llu~%u %s\n", file, off, len, 382 dout("sync_read on file %p %llu~%u %s\n", file, off, len,
375 (file->f_flags & O_DIRECT) ? "O_DIRECT" : ""); 383 (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
376 384
377 if (file->f_flags & O_DIRECT) { 385 if (file->f_flags & O_DIRECT) {
378 pages = ceph_get_direct_page_vector(data, num_pages, off, len); 386 num_pages = calc_pages_for((unsigned long)data, len);
379 387 pages = ceph_get_direct_page_vector(data, num_pages, true);
380 /*
381 * flush any page cache pages in this range. this
382 * will make concurrent normal and O_DIRECT io slow,
383 * but it will at least behave sensibly when they are
384 * in sequence.
385 */
386 } else { 388 } else {
389 num_pages = calc_pages_for(off, len);
387 pages = ceph_alloc_page_vector(num_pages, GFP_NOFS); 390 pages = ceph_alloc_page_vector(num_pages, GFP_NOFS);
388 } 391 }
389 if (IS_ERR(pages)) 392 if (IS_ERR(pages))
390 return PTR_ERR(pages); 393 return PTR_ERR(pages);
391 394
395 /*
396 * flush any page cache pages in this range. this
397 * will make concurrent normal and sync io slow,
398 * but it will at least behave sensibly when they are
399 * in sequence.
400 */
392 ret = filemap_write_and_wait(inode->i_mapping); 401 ret = filemap_write_and_wait(inode->i_mapping);
393 if (ret < 0) 402 if (ret < 0)
394 goto done; 403 goto done;
395 404
396 ret = striped_read(inode, off, len, pages, num_pages, checkeof); 405 ret = striped_read(inode, off, len, pages, num_pages, checkeof,
406 file->f_flags & O_DIRECT,
407 (unsigned long)data & ~PAGE_MASK);
397 408
398 if (ret >= 0 && (file->f_flags & O_DIRECT) == 0) 409 if (ret >= 0 && (file->f_flags & O_DIRECT) == 0)
399 ret = ceph_copy_page_vector_to_user(pages, data, off, ret); 410 ret = ceph_copy_page_vector_to_user(pages, data, off, ret);
@@ -402,7 +413,7 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
402 413
403done: 414done:
404 if (file->f_flags & O_DIRECT) 415 if (file->f_flags & O_DIRECT)
405 ceph_put_page_vector(pages, num_pages); 416 ceph_put_page_vector(pages, num_pages, true);
406 else 417 else
407 ceph_release_page_vector(pages, num_pages); 418 ceph_release_page_vector(pages, num_pages);
408 dout("sync_read result %d\n", ret); 419 dout("sync_read result %d\n", ret);
@@ -448,6 +459,8 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
448 int flags; 459 int flags;
449 int do_sync = 0; 460 int do_sync = 0;
450 int check_caps = 0; 461 int check_caps = 0;
462 int page_align, io_align;
463 unsigned long buf_align;
451 int ret; 464 int ret;
452 struct timespec mtime = CURRENT_TIME; 465 struct timespec mtime = CURRENT_TIME;
453 466
@@ -462,6 +475,9 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
462 else 475 else
463 pos = *offset; 476 pos = *offset;
464 477
478 io_align = pos & ~PAGE_MASK;
479 buf_align = (unsigned long)data & ~PAGE_MASK;
480
465 ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + left); 481 ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + left);
466 if (ret < 0) 482 if (ret < 0)
467 return ret; 483 return ret;
@@ -486,20 +502,27 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
486 */ 502 */
487more: 503more:
488 len = left; 504 len = left;
505 if (file->f_flags & O_DIRECT) {
506 /* write from beginning of first page, regardless of
507 io alignment */
508 page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
509 num_pages = calc_pages_for((unsigned long)data, len);
510 } else {
511 page_align = pos & ~PAGE_MASK;
512 num_pages = calc_pages_for(pos, len);
513 }
489 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout, 514 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
490 ceph_vino(inode), pos, &len, 515 ceph_vino(inode), pos, &len,
491 CEPH_OSD_OP_WRITE, flags, 516 CEPH_OSD_OP_WRITE, flags,
492 ci->i_snap_realm->cached_context, 517 ci->i_snap_realm->cached_context,
493 do_sync, 518 do_sync,
494 ci->i_truncate_seq, ci->i_truncate_size, 519 ci->i_truncate_seq, ci->i_truncate_size,
495 &mtime, false, 2); 520 &mtime, false, 2, page_align);
496 if (!req) 521 if (!req)
497 return -ENOMEM; 522 return -ENOMEM;
498 523
499 num_pages = calc_pages_for(pos, len);
500
501 if (file->f_flags & O_DIRECT) { 524 if (file->f_flags & O_DIRECT) {
502 pages = ceph_get_direct_page_vector(data, num_pages, pos, len); 525 pages = ceph_get_direct_page_vector(data, num_pages, false);
503 if (IS_ERR(pages)) { 526 if (IS_ERR(pages)) {
504 ret = PTR_ERR(pages); 527 ret = PTR_ERR(pages);
505 goto out; 528 goto out;
@@ -549,7 +572,7 @@ more:
549 } 572 }
550 573
551 if (file->f_flags & O_DIRECT) 574 if (file->f_flags & O_DIRECT)
552 ceph_put_page_vector(pages, num_pages); 575 ceph_put_page_vector(pages, num_pages, false);
553 else if (file->f_flags & O_SYNC) 576 else if (file->f_flags & O_SYNC)
554 ceph_release_page_vector(pages, num_pages); 577 ceph_release_page_vector(pages, num_pages);
555 578
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 1d6a45b5a04c..bf1286588f26 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -2,7 +2,6 @@
2 2
3#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/fs.h> 4#include <linux/fs.h>
5#include <linux/smp_lock.h>
6#include <linux/slab.h> 5#include <linux/slab.h>
7#include <linux/string.h> 6#include <linux/string.h>
8#include <linux/uaccess.h> 7#include <linux/uaccess.h>
@@ -471,7 +470,9 @@ void ceph_fill_file_time(struct inode *inode, int issued,
471 470
472 if (issued & (CEPH_CAP_FILE_EXCL| 471 if (issued & (CEPH_CAP_FILE_EXCL|
473 CEPH_CAP_FILE_WR| 472 CEPH_CAP_FILE_WR|
474 CEPH_CAP_FILE_BUFFER)) { 473 CEPH_CAP_FILE_BUFFER|
474 CEPH_CAP_AUTH_EXCL|
475 CEPH_CAP_XATTR_EXCL)) {
475 if (timespec_compare(ctime, &inode->i_ctime) > 0) { 476 if (timespec_compare(ctime, &inode->i_ctime) > 0) {
476 dout("ctime %ld.%09ld -> %ld.%09ld inc w/ cap\n", 477 dout("ctime %ld.%09ld -> %ld.%09ld inc w/ cap\n",
477 inode->i_ctime.tv_sec, inode->i_ctime.tv_nsec, 478 inode->i_ctime.tv_sec, inode->i_ctime.tv_nsec,
@@ -511,7 +512,7 @@ void ceph_fill_file_time(struct inode *inode, int issued,
511 warn = 1; 512 warn = 1;
512 } 513 }
513 } else { 514 } else {
514 /* we have no write caps; whatever the MDS says is true */ 515 /* we have no write|excl caps; whatever the MDS says is true */
515 if (ceph_seq_cmp(time_warp_seq, ci->i_time_warp_seq) >= 0) { 516 if (ceph_seq_cmp(time_warp_seq, ci->i_time_warp_seq) >= 0) {
516 inode->i_ctime = *ctime; 517 inode->i_ctime = *ctime;
517 inode->i_mtime = *mtime; 518 inode->i_mtime = *mtime;
@@ -567,12 +568,17 @@ static int fill_inode(struct inode *inode,
567 568
568 /* 569 /*
569 * provided version will be odd if inode value is projected, 570 * provided version will be odd if inode value is projected,
570 * even if stable. skip the update if we have a newer info 571 * even if stable. skip the update if we have newer stable
571 * (e.g., due to inode info racing form multiple MDSs), or if 572 * info (ours>=theirs, e.g. due to racing mds replies), unless
572 * we are getting projected (unstable) inode info. 573 * we are getting projected (unstable) info (in which case the
574 * version is odd, and we want ours>theirs).
575 * us them
576 * 2 2 skip
577 * 3 2 skip
578 * 3 3 update
573 */ 579 */
574 if (le64_to_cpu(info->version) > 0 && 580 if (le64_to_cpu(info->version) > 0 &&
575 (ci->i_version & ~1) > le64_to_cpu(info->version)) 581 (ci->i_version & ~1) >= le64_to_cpu(info->version))
576 goto no_change; 582 goto no_change;
577 583
578 issued = __ceph_caps_issued(ci, &implemented); 584 issued = __ceph_caps_issued(ci, &implemented);
@@ -606,7 +612,14 @@ static int fill_inode(struct inode *inode,
606 le32_to_cpu(info->time_warp_seq), 612 le32_to_cpu(info->time_warp_seq),
607 &ctime, &mtime, &atime); 613 &ctime, &mtime, &atime);
608 614
609 ci->i_max_size = le64_to_cpu(info->max_size); 615 /* only update max_size on auth cap */
616 if ((info->cap.flags & CEPH_CAP_FLAG_AUTH) &&
617 ci->i_max_size != le64_to_cpu(info->max_size)) {
618 dout("max_size %lld -> %llu\n", ci->i_max_size,
619 le64_to_cpu(info->max_size));
620 ci->i_max_size = le64_to_cpu(info->max_size);
621 }
622
610 ci->i_layout = info->layout; 623 ci->i_layout = info->layout;
611 inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1; 624 inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
612 625
@@ -1055,7 +1068,8 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req,
1055 ininfo = rinfo->targeti.in; 1068 ininfo = rinfo->targeti.in;
1056 vino.ino = le64_to_cpu(ininfo->ino); 1069 vino.ino = le64_to_cpu(ininfo->ino);
1057 vino.snap = le64_to_cpu(ininfo->snapid); 1070 vino.snap = le64_to_cpu(ininfo->snapid);
1058 if (!dn->d_inode) { 1071 in = dn->d_inode;
1072 if (!in) {
1059 in = ceph_get_inode(sb, vino); 1073 in = ceph_get_inode(sb, vino);
1060 if (IS_ERR(in)) { 1074 if (IS_ERR(in)) {
1061 pr_err("fill_trace bad get_inode " 1075 pr_err("fill_trace bad get_inode "
@@ -1386,11 +1400,8 @@ static void ceph_invalidate_work(struct work_struct *work)
1386 spin_lock(&inode->i_lock); 1400 spin_lock(&inode->i_lock);
1387 dout("invalidate_pages %p gen %d revoking %d\n", inode, 1401 dout("invalidate_pages %p gen %d revoking %d\n", inode,
1388 ci->i_rdcache_gen, ci->i_rdcache_revoking); 1402 ci->i_rdcache_gen, ci->i_rdcache_revoking);
1389 if (ci->i_rdcache_gen == 0 || 1403 if (ci->i_rdcache_revoking != ci->i_rdcache_gen) {
1390 ci->i_rdcache_revoking != ci->i_rdcache_gen) {
1391 BUG_ON(ci->i_rdcache_revoking > ci->i_rdcache_gen);
1392 /* nevermind! */ 1404 /* nevermind! */
1393 ci->i_rdcache_revoking = 0;
1394 spin_unlock(&inode->i_lock); 1405 spin_unlock(&inode->i_lock);
1395 goto out; 1406 goto out;
1396 } 1407 }
@@ -1400,15 +1411,16 @@ static void ceph_invalidate_work(struct work_struct *work)
1400 ceph_invalidate_nondirty_pages(inode->i_mapping); 1411 ceph_invalidate_nondirty_pages(inode->i_mapping);
1401 1412
1402 spin_lock(&inode->i_lock); 1413 spin_lock(&inode->i_lock);
1403 if (orig_gen == ci->i_rdcache_gen) { 1414 if (orig_gen == ci->i_rdcache_gen &&
1415 orig_gen == ci->i_rdcache_revoking) {
1404 dout("invalidate_pages %p gen %d successful\n", inode, 1416 dout("invalidate_pages %p gen %d successful\n", inode,
1405 ci->i_rdcache_gen); 1417 ci->i_rdcache_gen);
1406 ci->i_rdcache_gen = 0; 1418 ci->i_rdcache_revoking--;
1407 ci->i_rdcache_revoking = 0;
1408 check = 1; 1419 check = 1;
1409 } else { 1420 } else {
1410 dout("invalidate_pages %p gen %d raced, gen now %d\n", 1421 dout("invalidate_pages %p gen %d raced, now %d revoking %d\n",
1411 inode, orig_gen, ci->i_rdcache_gen); 1422 inode, orig_gen, ci->i_rdcache_gen,
1423 ci->i_rdcache_revoking);
1412 } 1424 }
1413 spin_unlock(&inode->i_lock); 1425 spin_unlock(&inode->i_lock);
1414 1426
@@ -1739,7 +1751,7 @@ int ceph_do_getattr(struct inode *inode, int mask)
1739 return 0; 1751 return 0;
1740 } 1752 }
1741 1753
1742 dout("do_getattr inode %p mask %s\n", inode, ceph_cap_string(mask)); 1754 dout("do_getattr inode %p mask %s mode 0%o\n", inode, ceph_cap_string(mask), inode->i_mode);
1743 if (ceph_caps_issued_mask(ceph_inode(inode), mask, 1)) 1755 if (ceph_caps_issued_mask(ceph_inode(inode), mask, 1))
1744 return 0; 1756 return 0;
1745 1757
diff --git a/fs/ceph/ioctl.h b/fs/ceph/ioctl.h
index a6ce54e94eb5..52e8fd74d450 100644
--- a/fs/ceph/ioctl.h
+++ b/fs/ceph/ioctl.h
@@ -4,7 +4,7 @@
4#include <linux/ioctl.h> 4#include <linux/ioctl.h>
5#include <linux/types.h> 5#include <linux/types.h>
6 6
7#define CEPH_IOCTL_MAGIC 0x98 7#define CEPH_IOCTL_MAGIC 0x97
8 8
9/* just use u64 to align sanely on all archs */ 9/* just use u64 to align sanely on all archs */
10struct ceph_ioctl_layout { 10struct ceph_ioctl_layout {
diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index 40abde93c345..476b329867d4 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -11,40 +11,68 @@
11 * Implement fcntl and flock locking functions. 11 * Implement fcntl and flock locking functions.
12 */ 12 */
13static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file, 13static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
14 u64 pid, u64 pid_ns, 14 int cmd, u8 wait, struct file_lock *fl)
15 int cmd, u64 start, u64 length, u8 wait)
16{ 15{
17 struct inode *inode = file->f_dentry->d_inode; 16 struct inode *inode = file->f_dentry->d_inode;
18 struct ceph_mds_client *mdsc = 17 struct ceph_mds_client *mdsc =
19 ceph_sb_to_client(inode->i_sb)->mdsc; 18 ceph_sb_to_client(inode->i_sb)->mdsc;
20 struct ceph_mds_request *req; 19 struct ceph_mds_request *req;
21 int err; 20 int err;
21 u64 length = 0;
22 22
23 req = ceph_mdsc_create_request(mdsc, operation, USE_AUTH_MDS); 23 req = ceph_mdsc_create_request(mdsc, operation, USE_AUTH_MDS);
24 if (IS_ERR(req)) 24 if (IS_ERR(req))
25 return PTR_ERR(req); 25 return PTR_ERR(req);
26 req->r_inode = igrab(inode); 26 req->r_inode = igrab(inode);
27 27
28 /* mds requires start and length rather than start and end */
29 if (LLONG_MAX == fl->fl_end)
30 length = 0;
31 else
32 length = fl->fl_end - fl->fl_start + 1;
33
28 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 34 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, "
29 "length: %llu, wait: %d, type`: %d", (int)lock_type, 35 "length: %llu, wait: %d, type`: %d", (int)lock_type,
30 (int)operation, pid, start, length, wait, cmd); 36 (int)operation, (u64)fl->fl_pid, fl->fl_start,
37 length, wait, fl->fl_type);
38
31 39
32 req->r_args.filelock_change.rule = lock_type; 40 req->r_args.filelock_change.rule = lock_type;
33 req->r_args.filelock_change.type = cmd; 41 req->r_args.filelock_change.type = cmd;
34 req->r_args.filelock_change.pid = cpu_to_le64(pid); 42 req->r_args.filelock_change.pid = cpu_to_le64((u64)fl->fl_pid);
35 /* This should be adjusted, but I'm not sure if 43 /* This should be adjusted, but I'm not sure if
36 namespaces actually get id numbers*/ 44 namespaces actually get id numbers*/
37 req->r_args.filelock_change.pid_namespace = 45 req->r_args.filelock_change.pid_namespace =
38 cpu_to_le64((u64)pid_ns); 46 cpu_to_le64((u64)(unsigned long)fl->fl_nspid);
39 req->r_args.filelock_change.start = cpu_to_le64(start); 47 req->r_args.filelock_change.start = cpu_to_le64(fl->fl_start);
40 req->r_args.filelock_change.length = cpu_to_le64(length); 48 req->r_args.filelock_change.length = cpu_to_le64(length);
41 req->r_args.filelock_change.wait = wait; 49 req->r_args.filelock_change.wait = wait;
42 50
43 err = ceph_mdsc_do_request(mdsc, inode, req); 51 err = ceph_mdsc_do_request(mdsc, inode, req);
52
53 if ( operation == CEPH_MDS_OP_GETFILELOCK){
54 fl->fl_pid = le64_to_cpu(req->r_reply_info.filelock_reply->pid);
55 if (CEPH_LOCK_SHARED == req->r_reply_info.filelock_reply->type)
56 fl->fl_type = F_RDLCK;
57 else if (CEPH_LOCK_EXCL == req->r_reply_info.filelock_reply->type)
58 fl->fl_type = F_WRLCK;
59 else
60 fl->fl_type = F_UNLCK;
61
62 fl->fl_start = le64_to_cpu(req->r_reply_info.filelock_reply->start);
63 length = le64_to_cpu(req->r_reply_info.filelock_reply->start) +
64 le64_to_cpu(req->r_reply_info.filelock_reply->length);
65 if (length >= 1)
66 fl->fl_end = length -1;
67 else
68 fl->fl_end = 0;
69
70 }
44 ceph_mdsc_put_request(req); 71 ceph_mdsc_put_request(req);
45 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " 72 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, "
46 "length: %llu, wait: %d, type`: %d err code %d", (int)lock_type, 73 "length: %llu, wait: %d, type`: %d, err code %d", (int)lock_type,
47 (int)operation, pid, start, length, wait, cmd, err); 74 (int)operation, (u64)fl->fl_pid, fl->fl_start,
75 length, wait, fl->fl_type, err);
48 return err; 76 return err;
49} 77}
50 78
@@ -54,7 +82,6 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
54 */ 82 */
55int ceph_lock(struct file *file, int cmd, struct file_lock *fl) 83int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
56{ 84{
57 u64 length;
58 u8 lock_cmd; 85 u8 lock_cmd;
59 int err; 86 int err;
60 u8 wait = 0; 87 u8 wait = 0;
@@ -76,29 +103,20 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
76 else 103 else
77 lock_cmd = CEPH_LOCK_UNLOCK; 104 lock_cmd = CEPH_LOCK_UNLOCK;
78 105
79 if (LLONG_MAX == fl->fl_end) 106 err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, lock_cmd, wait, fl);
80 length = 0;
81 else
82 length = fl->fl_end - fl->fl_start + 1;
83
84 err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
85 (u64)fl->fl_pid,
86 (u64)(unsigned long)fl->fl_nspid,
87 lock_cmd, fl->fl_start,
88 length, wait);
89 if (!err) { 107 if (!err) {
90 dout("mds locked, locking locally"); 108 if ( op != CEPH_MDS_OP_GETFILELOCK ){
91 err = posix_lock_file(file, fl, NULL); 109 dout("mds locked, locking locally");
92 if (err && (CEPH_MDS_OP_SETFILELOCK == op)) { 110 err = posix_lock_file(file, fl, NULL);
93 /* undo! This should only happen if the kernel detects 111 if (err && (CEPH_MDS_OP_SETFILELOCK == op)) {
94 * local deadlock. */ 112 /* undo! This should only happen if the kernel detects
95 ceph_lock_message(CEPH_LOCK_FCNTL, op, file, 113 * local deadlock. */
96 (u64)fl->fl_pid, 114 ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
97 (u64)(unsigned long)fl->fl_nspid, 115 CEPH_LOCK_UNLOCK, 0, fl);
98 CEPH_LOCK_UNLOCK, fl->fl_start, 116 dout("got %d on posix_lock_file, undid lock", err);
99 length, 0); 117 }
100 dout("got %d on posix_lock_file, undid lock", err);
101 } 118 }
119
102 } else { 120 } else {
103 dout("mds returned error code %d", err); 121 dout("mds returned error code %d", err);
104 } 122 }
@@ -107,7 +125,6 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
107 125
108int ceph_flock(struct file *file, int cmd, struct file_lock *fl) 126int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
109{ 127{
110 u64 length;
111 u8 lock_cmd; 128 u8 lock_cmd;
112 int err; 129 int err;
113 u8 wait = 1; 130 u8 wait = 1;
@@ -127,26 +144,15 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
127 lock_cmd = CEPH_LOCK_EXCL; 144 lock_cmd = CEPH_LOCK_EXCL;
128 else 145 else
129 lock_cmd = CEPH_LOCK_UNLOCK; 146 lock_cmd = CEPH_LOCK_UNLOCK;
130 /* mds requires start and length rather than start and end */
131 if (LLONG_MAX == fl->fl_end)
132 length = 0;
133 else
134 length = fl->fl_end - fl->fl_start + 1;
135 147
136 err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, 148 err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK,
137 file, (u64)fl->fl_pid, 149 file, lock_cmd, wait, fl);
138 (u64)(unsigned long)fl->fl_nspid,
139 lock_cmd, fl->fl_start,
140 length, wait);
141 if (!err) { 150 if (!err) {
142 err = flock_lock_file_wait(file, fl); 151 err = flock_lock_file_wait(file, fl);
143 if (err) { 152 if (err) {
144 ceph_lock_message(CEPH_LOCK_FLOCK, 153 ceph_lock_message(CEPH_LOCK_FLOCK,
145 CEPH_MDS_OP_SETFILELOCK, 154 CEPH_MDS_OP_SETFILELOCK,
146 file, (u64)fl->fl_pid, 155 file, CEPH_LOCK_UNLOCK, 0, fl);
147 (u64)(unsigned long)fl->fl_nspid,
148 CEPH_LOCK_UNLOCK, fl->fl_start,
149 length, 0);
150 dout("got %d on flock_lock_file_wait, undid lock", err); 156 dout("got %d on flock_lock_file_wait, undid lock", err);
151 } 157 }
152 } else { 158 } else {
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 3142b15940c2..38800eaa81d0 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -6,7 +6,6 @@
6#include <linux/sched.h> 6#include <linux/sched.h>
7#include <linux/debugfs.h> 7#include <linux/debugfs.h>
8#include <linux/seq_file.h> 8#include <linux/seq_file.h>
9#include <linux/smp_lock.h>
10 9
11#include "super.h" 10#include "super.h"
12#include "mds_client.h" 11#include "mds_client.h"
@@ -203,6 +202,38 @@ out_bad:
203} 202}
204 203
205/* 204/*
205 * parse fcntl F_GETLK results
206 */
207static int parse_reply_info_filelock(void **p, void *end,
208 struct ceph_mds_reply_info_parsed *info)
209{
210 if (*p + sizeof(*info->filelock_reply) > end)
211 goto bad;
212
213 info->filelock_reply = *p;
214 *p += sizeof(*info->filelock_reply);
215
216 if (unlikely(*p != end))
217 goto bad;
218 return 0;
219
220bad:
221 return -EIO;
222}
223
224/*
225 * parse extra results
226 */
227static int parse_reply_info_extra(void **p, void *end,
228 struct ceph_mds_reply_info_parsed *info)
229{
230 if (info->head->op == CEPH_MDS_OP_GETFILELOCK)
231 return parse_reply_info_filelock(p, end, info);
232 else
233 return parse_reply_info_dir(p, end, info);
234}
235
236/*
206 * parse entire mds reply 237 * parse entire mds reply
207 */ 238 */
208static int parse_reply_info(struct ceph_msg *msg, 239static int parse_reply_info(struct ceph_msg *msg,
@@ -224,10 +255,10 @@ static int parse_reply_info(struct ceph_msg *msg,
224 goto out_bad; 255 goto out_bad;
225 } 256 }
226 257
227 /* dir content */ 258 /* extra */
228 ceph_decode_32_safe(&p, end, len, bad); 259 ceph_decode_32_safe(&p, end, len, bad);
229 if (len > 0) { 260 if (len > 0) {
230 err = parse_reply_info_dir(&p, p+len, info); 261 err = parse_reply_info_extra(&p, p+len, info);
231 if (err < 0) 262 if (err < 0)
232 goto out_bad; 263 goto out_bad;
233 } 264 }
@@ -529,6 +560,9 @@ static void __register_request(struct ceph_mds_client *mdsc,
529 ceph_mdsc_get_request(req); 560 ceph_mdsc_get_request(req);
530 __insert_request(mdsc, req); 561 __insert_request(mdsc, req);
531 562
563 req->r_uid = current_fsuid();
564 req->r_gid = current_fsgid();
565
532 if (dir) { 566 if (dir) {
533 struct ceph_inode_info *ci = ceph_inode(dir); 567 struct ceph_inode_info *ci = ceph_inode(dir);
534 568
@@ -1588,8 +1622,8 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
1588 1622
1589 head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch); 1623 head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch);
1590 head->op = cpu_to_le32(req->r_op); 1624 head->op = cpu_to_le32(req->r_op);
1591 head->caller_uid = cpu_to_le32(current_fsuid()); 1625 head->caller_uid = cpu_to_le32(req->r_uid);
1592 head->caller_gid = cpu_to_le32(current_fsgid()); 1626 head->caller_gid = cpu_to_le32(req->r_gid);
1593 head->args = req->r_args; 1627 head->args = req->r_args;
1594 1628
1595 ceph_encode_filepath(&p, end, ino1, path1); 1629 ceph_encode_filepath(&p, end, ino1, path1);
@@ -2072,7 +2106,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
2072 2106
2073 mutex_lock(&session->s_mutex); 2107 mutex_lock(&session->s_mutex);
2074 if (err < 0) { 2108 if (err < 0) {
2075 pr_err("mdsc_handle_reply got corrupt reply mds%d\n", mds); 2109 pr_err("mdsc_handle_reply got corrupt reply mds%d(tid:%lld)\n", mds, tid);
2076 ceph_msg_dump(msg); 2110 ceph_msg_dump(msg);
2077 goto out_err; 2111 goto out_err;
2078 } 2112 }
@@ -2092,7 +2126,8 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
2092 mutex_lock(&req->r_fill_mutex); 2126 mutex_lock(&req->r_fill_mutex);
2093 err = ceph_fill_trace(mdsc->fsc->sb, req, req->r_session); 2127 err = ceph_fill_trace(mdsc->fsc->sb, req, req->r_session);
2094 if (err == 0) { 2128 if (err == 0) {
2095 if (result == 0 && rinfo->dir_nr) 2129 if (result == 0 && req->r_op != CEPH_MDS_OP_GETFILELOCK &&
2130 rinfo->dir_nr)
2096 ceph_readdir_prepopulate(req, req->r_session); 2131 ceph_readdir_prepopulate(req, req->r_session);
2097 ceph_unreserve_caps(mdsc, &req->r_caps_reservation); 2132 ceph_unreserve_caps(mdsc, &req->r_caps_reservation);
2098 } 2133 }
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index d66d63c72355..aabe563b54db 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -42,26 +42,37 @@ struct ceph_mds_reply_info_in {
42}; 42};
43 43
44/* 44/*
45 * parsed info about an mds reply, including information about the 45 * parsed info about an mds reply, including information about
46 * target inode and/or its parent directory and dentry, and directory 46 * either: 1) the target inode and/or its parent directory and dentry,
47 * contents (for readdir results). 47 * and directory contents (for readdir results), or
48 * 2) the file range lock info (for fcntl F_GETLK results).
48 */ 49 */
49struct ceph_mds_reply_info_parsed { 50struct ceph_mds_reply_info_parsed {
50 struct ceph_mds_reply_head *head; 51 struct ceph_mds_reply_head *head;
51 52
53 /* trace */
52 struct ceph_mds_reply_info_in diri, targeti; 54 struct ceph_mds_reply_info_in diri, targeti;
53 struct ceph_mds_reply_dirfrag *dirfrag; 55 struct ceph_mds_reply_dirfrag *dirfrag;
54 char *dname; 56 char *dname;
55 u32 dname_len; 57 u32 dname_len;
56 struct ceph_mds_reply_lease *dlease; 58 struct ceph_mds_reply_lease *dlease;
57 59
58 struct ceph_mds_reply_dirfrag *dir_dir; 60 /* extra */
59 int dir_nr; 61 union {
60 char **dir_dname; 62 /* for fcntl F_GETLK results */
61 u32 *dir_dname_len; 63 struct ceph_filelock *filelock_reply;
62 struct ceph_mds_reply_lease **dir_dlease; 64
63 struct ceph_mds_reply_info_in *dir_in; 65 /* for readdir results */
64 u8 dir_complete, dir_end; 66 struct {
67 struct ceph_mds_reply_dirfrag *dir_dir;
68 int dir_nr;
69 char **dir_dname;
70 u32 *dir_dname_len;
71 struct ceph_mds_reply_lease **dir_dlease;
72 struct ceph_mds_reply_info_in *dir_in;
73 u8 dir_complete, dir_end;
74 };
75 };
65 76
66 /* encoded blob describing snapshot contexts for certain 77 /* encoded blob describing snapshot contexts for certain
67 operations (e.g., open) */ 78 operations (e.g., open) */
@@ -170,6 +181,8 @@ struct ceph_mds_request {
170 181
171 union ceph_mds_request_args r_args; 182 union ceph_mds_request_args r_args;
172 int r_fmode; /* file mode, if expecting cap */ 183 int r_fmode; /* file mode, if expecting cap */
184 uid_t r_uid;
185 gid_t r_gid;
173 186
174 /* for choosing which mds to send this request to */ 187 /* for choosing which mds to send this request to */
175 int r_direct_mode; 188 int r_direct_mode;
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 1886294e12f7..7f01728a4657 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -293,9 +293,7 @@ struct ceph_inode_info {
293 int i_rd_ref, i_rdcache_ref, i_wr_ref; 293 int i_rd_ref, i_rdcache_ref, i_wr_ref;
294 int i_wrbuffer_ref, i_wrbuffer_ref_head; 294 int i_wrbuffer_ref, i_wrbuffer_ref_head;
295 u32 i_shared_gen; /* increment each time we get FILE_SHARED */ 295 u32 i_shared_gen; /* increment each time we get FILE_SHARED */
296 u32 i_rdcache_gen; /* we increment this each time we get 296 u32 i_rdcache_gen; /* incremented each time we get FILE_CACHE. */
297 FILE_CACHE. If it's non-zero, we
298 _may_ have cached pages. */
299 u32 i_rdcache_revoking; /* RDCACHE gen to async invalidate, if any */ 297 u32 i_rdcache_revoking; /* RDCACHE gen to async invalidate, if any */
300 298
301 struct list_head i_unsafe_writes; /* uncommitted sync writes */ 299 struct list_head i_unsafe_writes; /* uncommitted sync writes */
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig
index 0ed213970ced..ee45648b0d1a 100644
--- a/fs/cifs/Kconfig
+++ b/fs/cifs/Kconfig
@@ -4,6 +4,7 @@ config CIFS
4 select NLS 4 select NLS
5 select CRYPTO 5 select CRYPTO
6 select CRYPTO_MD5 6 select CRYPTO_MD5
7 select CRYPTO_HMAC
7 select CRYPTO_ARC4 8 select CRYPTO_ARC4
8 help 9 help
9 This is the client VFS module for the Common Internet File System 10 This is the client VFS module for the Common Internet File System
@@ -143,6 +144,13 @@ config CIFS_FSCACHE
143 to be cached locally on disk through the general filesystem cache 144 to be cached locally on disk through the general filesystem cache
144 manager. If unsure, say N. 145 manager. If unsure, say N.
145 146
147config CIFS_ACL
148 bool "Provide CIFS ACL support (EXPERIMENTAL)"
149 depends on EXPERIMENTAL && CIFS_XATTR
150 help
151 Allows to fetch CIFS/NTFS ACL from the server. The DACL blob
152 is handed over to the application/caller.
153
146config CIFS_EXPERIMENTAL 154config CIFS_EXPERIMENTAL
147 bool "CIFS Experimental Features (EXPERIMENTAL)" 155 bool "CIFS Experimental Features (EXPERIMENTAL)"
148 depends on CIFS && EXPERIMENTAL 156 depends on CIFS && EXPERIMENTAL
diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile
index adefa60a9bdc..43b19dd39191 100644
--- a/fs/cifs/Makefile
+++ b/fs/cifs/Makefile
@@ -6,7 +6,9 @@ obj-$(CONFIG_CIFS) += cifs.o
6cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \ 6cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
7 link.o misc.o netmisc.o smbdes.o smbencrypt.o transport.o asn1.o \ 7 link.o misc.o netmisc.o smbdes.o smbencrypt.o transport.o asn1.o \
8 md4.o md5.o cifs_unicode.o nterr.o xattr.o cifsencrypt.o \ 8 md4.o md5.o cifs_unicode.o nterr.o xattr.o cifsencrypt.o \
9 readdir.o ioctl.o sess.o export.o cifsacl.o 9 readdir.o ioctl.o sess.o export.o
10
11cifs-$(CONFIG_CIFS_ACL) += cifsacl.o
10 12
11cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o 13cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o
12 14
diff --git a/fs/cifs/README b/fs/cifs/README
index ee68d1036544..46af99ab3614 100644
--- a/fs/cifs/README
+++ b/fs/cifs/README
@@ -337,6 +337,15 @@ A partial list of the supported mount options follows:
337 wsize default write size (default 57344) 337 wsize default write size (default 57344)
338 maximum wsize currently allowed by CIFS is 57344 (fourteen 338 maximum wsize currently allowed by CIFS is 57344 (fourteen
339 4096 byte pages) 339 4096 byte pages)
340 actimeo=n attribute cache timeout in seconds (default 1 second).
341 After this timeout, the cifs client requests fresh attribute
342 information from the server. This option allows to tune the
343 attribute cache timeout to suit the workload needs. Shorter
344 timeouts mean better the cache coherency, but increased number
345 of calls to the server. Longer timeouts mean reduced number
346 of calls to the server at the expense of less stricter cache
347 coherency checks (i.e. incorrect attribute cache for a short
348 period of time).
340 rw mount the network share read-write (note that the 349 rw mount the network share read-write (note that the
341 server may still consider the share read-only) 350 server may still consider the share read-only)
342 ro mount network share read-only 351 ro mount network share read-only
diff --git a/fs/cifs/TODO b/fs/cifs/TODO
index 5aff46c61e52..355abcdcda98 100644
--- a/fs/cifs/TODO
+++ b/fs/cifs/TODO
@@ -81,7 +81,7 @@ u) DOS attrs - returned as pseudo-xattr in Samba format (check VFAT and NTFS for
81 81
82v) mount check for unmatched uids 82v) mount check for unmatched uids
83 83
84w) Add support for new vfs entry points for setlease and fallocate 84w) Add support for new vfs entry point for fallocate
85 85
86x) Fix Samba 3 server to handle Linux kernel aio so dbench with lots of 86x) Fix Samba 3 server to handle Linux kernel aio so dbench with lots of
87processes can proceed better in parallel (on the server) 87processes can proceed better in parallel (on the server)
diff --git a/fs/cifs/cifs_fs_sb.h b/fs/cifs/cifs_fs_sb.h
index 525ba59a4105..7852cd677051 100644
--- a/fs/cifs/cifs_fs_sb.h
+++ b/fs/cifs/cifs_fs_sb.h
@@ -15,7 +15,7 @@
15 * the GNU Lesser General Public License for more details. 15 * the GNU Lesser General Public License for more details.
16 * 16 *
17 */ 17 */
18#include <linux/radix-tree.h> 18#include <linux/rbtree.h>
19 19
20#ifndef _CIFS_FS_SB_H 20#ifndef _CIFS_FS_SB_H
21#define _CIFS_FS_SB_H 21#define _CIFS_FS_SB_H
@@ -42,12 +42,13 @@
42#define CIFS_MOUNT_MULTIUSER 0x20000 /* multiuser mount */ 42#define CIFS_MOUNT_MULTIUSER 0x20000 /* multiuser mount */
43 43
44struct cifs_sb_info { 44struct cifs_sb_info {
45 struct radix_tree_root tlink_tree; 45 struct rb_root tlink_tree;
46#define CIFS_TLINK_MASTER_TAG 0 /* is "master" (mount) tcon */
47 spinlock_t tlink_tree_lock; 46 spinlock_t tlink_tree_lock;
47 struct tcon_link *master_tlink;
48 struct nls_table *local_nls; 48 struct nls_table *local_nls;
49 unsigned int rsize; 49 unsigned int rsize;
50 unsigned int wsize; 50 unsigned int wsize;
51 unsigned long actimeo; /* attribute cache timeout (jiffies) */
51 atomic_t active; 52 atomic_t active;
52 uid_t mnt_uid; 53 uid_t mnt_uid;
53 gid_t mnt_gid; 54 gid_t mnt_gid;
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index c9b4792ae825..a437ec391a01 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -30,8 +30,6 @@
30#include "cifs_debug.h" 30#include "cifs_debug.h"
31 31
32 32
33#ifdef CONFIG_CIFS_EXPERIMENTAL
34
35static struct cifs_wksid wksidarr[NUM_WK_SIDS] = { 33static struct cifs_wksid wksidarr[NUM_WK_SIDS] = {
36 {{1, 0, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0} }, "null user"}, 34 {{1, 0, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0} }, "null user"},
37 {{1, 1, {0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0} }, "nobody"}, 35 {{1, 1, {0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0} }, "nobody"},
@@ -560,7 +558,7 @@ static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
560 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); 558 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
561 559
562 if (IS_ERR(tlink)) 560 if (IS_ERR(tlink))
563 return NULL; 561 return ERR_CAST(tlink);
564 562
565 xid = GetXid(); 563 xid = GetXid();
566 rc = CIFSSMBGetCIFSACL(xid, tlink_tcon(tlink), fid, &pntsd, pacllen); 564 rc = CIFSSMBGetCIFSACL(xid, tlink_tcon(tlink), fid, &pntsd, pacllen);
@@ -568,7 +566,9 @@ static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
568 566
569 cifs_put_tlink(tlink); 567 cifs_put_tlink(tlink);
570 568
571 cFYI(1, "GetCIFSACL rc = %d ACL len %d", rc, *pacllen); 569 cFYI(1, "%s: rc = %d ACL len %d", __func__, rc, *pacllen);
570 if (rc)
571 return ERR_PTR(rc);
572 return pntsd; 572 return pntsd;
573} 573}
574 574
@@ -583,7 +583,7 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
583 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); 583 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
584 584
585 if (IS_ERR(tlink)) 585 if (IS_ERR(tlink))
586 return NULL; 586 return ERR_CAST(tlink);
587 587
588 tcon = tlink_tcon(tlink); 588 tcon = tlink_tcon(tlink);
589 xid = GetXid(); 589 xid = GetXid();
@@ -591,23 +591,22 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
591 rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, READ_CONTROL, 0, 591 rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, READ_CONTROL, 0,
592 &fid, &oplock, NULL, cifs_sb->local_nls, 592 &fid, &oplock, NULL, cifs_sb->local_nls,
593 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 593 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
594 if (rc) { 594 if (!rc) {
595 cERROR(1, "Unable to open file to get ACL"); 595 rc = CIFSSMBGetCIFSACL(xid, tcon, fid, &pntsd, pacllen);
596 goto out; 596 CIFSSMBClose(xid, tcon, fid);
597 } 597 }
598 598
599 rc = CIFSSMBGetCIFSACL(xid, tcon, fid, &pntsd, pacllen);
600 cFYI(1, "GetCIFSACL rc = %d ACL len %d", rc, *pacllen);
601
602 CIFSSMBClose(xid, tcon, fid);
603 out:
604 cifs_put_tlink(tlink); 599 cifs_put_tlink(tlink);
605 FreeXid(xid); 600 FreeXid(xid);
601
602 cFYI(1, "%s: rc = %d ACL len %d", __func__, rc, *pacllen);
603 if (rc)
604 return ERR_PTR(rc);
606 return pntsd; 605 return pntsd;
607} 606}
608 607
609/* Retrieve an ACL from the server */ 608/* Retrieve an ACL from the server */
610static struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb, 609struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb,
611 struct inode *inode, const char *path, 610 struct inode *inode, const char *path,
612 u32 *pacllen) 611 u32 *pacllen)
613{ 612{
@@ -695,7 +694,7 @@ static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
695} 694}
696 695
697/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ 696/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */
698void 697int
699cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, 698cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
700 struct inode *inode, const char *path, const __u16 *pfid) 699 struct inode *inode, const char *path, const __u16 *pfid)
701{ 700{
@@ -711,17 +710,21 @@ cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
711 pntsd = get_cifs_acl(cifs_sb, inode, path, &acllen); 710 pntsd = get_cifs_acl(cifs_sb, inode, path, &acllen);
712 711
713 /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ 712 /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */
714 if (pntsd) 713 if (IS_ERR(pntsd)) {
714 rc = PTR_ERR(pntsd);
715 cERROR(1, "%s: error %d getting sec desc", __func__, rc);
716 } else {
715 rc = parse_sec_desc(pntsd, acllen, fattr); 717 rc = parse_sec_desc(pntsd, acllen, fattr);
716 if (rc) 718 kfree(pntsd);
717 cFYI(1, "parse sec desc failed rc = %d", rc); 719 if (rc)
720 cERROR(1, "parse sec desc failed rc = %d", rc);
721 }
718 722
719 kfree(pntsd); 723 return rc;
720 return;
721} 724}
722 725
723/* Convert mode bits to an ACL so we can update the ACL on the server */ 726/* Convert mode bits to an ACL so we can update the ACL on the server */
724int mode_to_acl(struct inode *inode, const char *path, __u64 nmode) 727int mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode)
725{ 728{
726 int rc = 0; 729 int rc = 0;
727 __u32 secdesclen = 0; 730 __u32 secdesclen = 0;
@@ -736,7 +739,10 @@ int mode_to_acl(struct inode *inode, const char *path, __u64 nmode)
736 /* Add three ACEs for owner, group, everyone getting rid of 739 /* Add three ACEs for owner, group, everyone getting rid of
737 other ACEs as chmod disables ACEs and set the security descriptor */ 740 other ACEs as chmod disables ACEs and set the security descriptor */
738 741
739 if (pntsd) { 742 if (IS_ERR(pntsd)) {
743 rc = PTR_ERR(pntsd);
744 cERROR(1, "%s: error %d getting sec desc", __func__, rc);
745 } else {
740 /* allocate memory for the smb header, 746 /* allocate memory for the smb header,
741 set security descriptor request security descriptor 747 set security descriptor request security descriptor
742 parameters, and secuirty descriptor itself */ 748 parameters, and secuirty descriptor itself */
@@ -766,4 +772,3 @@ int mode_to_acl(struct inode *inode, const char *path, __u64 nmode)
766 772
767 return rc; 773 return rc;
768} 774}
769#endif /* CONFIG_CIFS_EXPERIMENTAL */
diff --git a/fs/cifs/cifsacl.h b/fs/cifs/cifsacl.h
index 6c8096cf5155..c4ae7d036563 100644
--- a/fs/cifs/cifsacl.h
+++ b/fs/cifs/cifsacl.h
@@ -74,11 +74,7 @@ struct cifs_wksid {
74 char sidname[SIDNAMELENGTH]; 74 char sidname[SIDNAMELENGTH];
75} __attribute__((packed)); 75} __attribute__((packed));
76 76
77#ifdef CONFIG_CIFS_EXPERIMENTAL
78
79extern int match_sid(struct cifs_sid *); 77extern int match_sid(struct cifs_sid *);
80extern int compare_sids(const struct cifs_sid *, const struct cifs_sid *); 78extern int compare_sids(const struct cifs_sid *, const struct cifs_sid *);
81 79
82#endif /* CONFIG_CIFS_EXPERIMENTAL */
83
84#endif /* _CIFSACL_H */ 80#endif /* _CIFSACL_H */
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 75c4eaa79588..3936aa7f2c22 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -116,7 +116,7 @@ cifs_read_super(struct super_block *sb, void *data,
116 return -ENOMEM; 116 return -ENOMEM;
117 117
118 spin_lock_init(&cifs_sb->tlink_tree_lock); 118 spin_lock_init(&cifs_sb->tlink_tree_lock);
119 INIT_RADIX_TREE(&cifs_sb->tlink_tree, GFP_KERNEL); 119 cifs_sb->tlink_tree = RB_ROOT;
120 120
121 rc = bdi_setup_and_register(&cifs_sb->bdi, "cifs", BDI_CAP_MAP_COPY); 121 rc = bdi_setup_and_register(&cifs_sb->bdi, "cifs", BDI_CAP_MAP_COPY);
122 if (rc) { 122 if (rc) {
@@ -321,8 +321,7 @@ cifs_alloc_inode(struct super_block *sb)
321 /* Until the file is open and we have gotten oplock 321 /* Until the file is open and we have gotten oplock
322 info back from the server, can not assume caching of 322 info back from the server, can not assume caching of
323 file data or metadata */ 323 file data or metadata */
324 cifs_inode->clientCanCacheRead = false; 324 cifs_set_oplock_level(cifs_inode, 0);
325 cifs_inode->clientCanCacheAll = false;
326 cifs_inode->delete_pending = false; 325 cifs_inode->delete_pending = false;
327 cifs_inode->invalid_mapping = false; 326 cifs_inode->invalid_mapping = false;
328 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ 327 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
@@ -459,9 +458,13 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
459 seq_printf(s, ",acl"); 458 seq_printf(s, ",acl");
460 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) 459 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
461 seq_printf(s, ",mfsymlinks"); 460 seq_printf(s, ",mfsymlinks");
461 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
462 seq_printf(s, ",fsc");
462 463
463 seq_printf(s, ",rsize=%d", cifs_sb->rsize); 464 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
464 seq_printf(s, ",wsize=%d", cifs_sb->wsize); 465 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
466 /* convert actimeo and display it in seconds */
467 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
465 468
466 return 0; 469 return 0;
467} 470}
@@ -934,7 +937,6 @@ init_cifs(void)
934 GlobalCurrentXid = 0; 937 GlobalCurrentXid = 0;
935 GlobalTotalActiveXid = 0; 938 GlobalTotalActiveXid = 0;
936 GlobalMaxActiveXid = 0; 939 GlobalMaxActiveXid = 0;
937 memset(Local_System_Name, 0, 15);
938 spin_lock_init(&cifs_tcp_ses_lock); 940 spin_lock_init(&cifs_tcp_ses_lock);
939 spin_lock_init(&cifs_file_list_lock); 941 spin_lock_init(&cifs_file_list_lock);
940 spin_lock_init(&GlobalMid_Lock); 942 spin_lock_init(&GlobalMid_Lock);
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index f259e4d7612d..7136c0c3e2f9 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -45,6 +45,16 @@
45#define CIFS_MIN_RCV_POOL 4 45#define CIFS_MIN_RCV_POOL 4
46 46
47/* 47/*
48 * default attribute cache timeout (jiffies)
49 */
50#define CIFS_DEF_ACTIMEO (1 * HZ)
51
52/*
53 * max attribute cache timeout (jiffies) - 2^30
54 */
55#define CIFS_MAX_ACTIMEO (1 << 30)
56
57/*
48 * MAX_REQ is the maximum number of requests that WE will send 58 * MAX_REQ is the maximum number of requests that WE will send
49 * on one socket concurrently. It also matches the most common 59 * on one socket concurrently. It also matches the most common
50 * value of max multiplex returned by servers. We may 60 * value of max multiplex returned by servers. We may
@@ -336,7 +346,8 @@ struct cifsTconInfo {
336 * "get" on the container. 346 * "get" on the container.
337 */ 347 */
338struct tcon_link { 348struct tcon_link {
339 unsigned long tl_index; 349 struct rb_node tl_rbnode;
350 uid_t tl_uid;
340 unsigned long tl_flags; 351 unsigned long tl_flags;
341#define TCON_LINK_MASTER 0 352#define TCON_LINK_MASTER 0
342#define TCON_LINK_PENDING 1 353#define TCON_LINK_PENDING 1
@@ -745,8 +756,6 @@ GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
745GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */ 756GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
746GLOBAL_EXTERN spinlock_t GlobalMid_Lock; /* protects above & list operations */ 757GLOBAL_EXTERN spinlock_t GlobalMid_Lock; /* protects above & list operations */
747 /* on midQ entries */ 758 /* on midQ entries */
748GLOBAL_EXTERN char Local_System_Name[15];
749
750/* 759/*
751 * Global counters, updated atomically 760 * Global counters, updated atomically
752 */ 761 */
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index edb6d90efdf2..e6d1481b16c1 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -54,7 +54,8 @@ do { \
54 __func__, curr_xid, (int)rc); \ 54 __func__, curr_xid, (int)rc); \
55} while (0) 55} while (0)
56extern char *build_path_from_dentry(struct dentry *); 56extern char *build_path_from_dentry(struct dentry *);
57extern char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb); 57extern char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb,
58 struct cifsTconInfo *tcon);
58extern char *build_wildcard_path_from_dentry(struct dentry *direntry); 59extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
59extern char *cifs_compose_mount_options(const char *sb_mountdata, 60extern char *cifs_compose_mount_options(const char *sb_mountdata,
60 const char *fullpath, const struct dfs_info3_param *ref, 61 const char *fullpath, const struct dfs_info3_param *ref,
@@ -79,9 +80,7 @@ extern bool is_valid_oplock_break(struct smb_hdr *smb,
79 struct TCP_Server_Info *); 80 struct TCP_Server_Info *);
80extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); 81extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof);
81extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); 82extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool);
82#ifdef CONFIG_CIFS_EXPERIMENTAL
83extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); 83extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool);
84#endif
85extern unsigned int smbCalcSize(struct smb_hdr *ptr); 84extern unsigned int smbCalcSize(struct smb_hdr *ptr);
86extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr); 85extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
87extern int decode_negTokenInit(unsigned char *security_blob, int length, 86extern int decode_negTokenInit(unsigned char *security_blob, int length,
@@ -104,6 +103,7 @@ extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601);
104extern u64 cifs_UnixTimeToNT(struct timespec); 103extern u64 cifs_UnixTimeToNT(struct timespec);
105extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, 104extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time,
106 int offset); 105 int offset);
106extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock);
107 107
108extern struct cifsFileInfo *cifs_new_fileinfo(__u16 fileHandle, 108extern struct cifsFileInfo *cifs_new_fileinfo(__u16 fileHandle,
109 struct file *file, struct tcon_link *tlink, 109 struct file *file, struct tcon_link *tlink,
@@ -129,10 +129,12 @@ extern int cifs_get_file_info_unix(struct file *filp);
129extern int cifs_get_inode_info_unix(struct inode **pinode, 129extern int cifs_get_inode_info_unix(struct inode **pinode,
130 const unsigned char *search_path, 130 const unsigned char *search_path,
131 struct super_block *sb, int xid); 131 struct super_block *sb, int xid);
132extern void cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, 132extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb,
133 struct cifs_fattr *fattr, struct inode *inode, 133 struct cifs_fattr *fattr, struct inode *inode,
134 const char *path, const __u16 *pfid); 134 const char *path, const __u16 *pfid);
135extern int mode_to_acl(struct inode *inode, const char *path, __u64); 135extern int mode_to_cifs_acl(struct inode *inode, const char *path, __u64);
136extern struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *, struct inode *,
137 const char *, u32 *);
136 138
137extern int cifs_mount(struct super_block *, struct cifs_sb_info *, char *, 139extern int cifs_mount(struct super_block *, struct cifs_sb_info *, char *,
138 const char *); 140 const char *);
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 2f2632b6df5a..67acfb3acad2 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -2478,95 +2478,6 @@ querySymLinkRetry:
2478} 2478}
2479 2479
2480#ifdef CONFIG_CIFS_EXPERIMENTAL 2480#ifdef CONFIG_CIFS_EXPERIMENTAL
2481/* Initialize NT TRANSACT SMB into small smb request buffer.
2482 This assumes that all NT TRANSACTS that we init here have
2483 total parm and data under about 400 bytes (to fit in small cifs
2484 buffer size), which is the case so far, it easily fits. NB:
2485 Setup words themselves and ByteCount
2486 MaxSetupCount (size of returned setup area) and
2487 MaxParameterCount (returned parms size) must be set by caller */
2488static int
2489smb_init_nttransact(const __u16 sub_command, const int setup_count,
2490 const int parm_len, struct cifsTconInfo *tcon,
2491 void **ret_buf)
2492{
2493 int rc;
2494 __u32 temp_offset;
2495 struct smb_com_ntransact_req *pSMB;
2496
2497 rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon,
2498 (void **)&pSMB);
2499 if (rc)
2500 return rc;
2501 *ret_buf = (void *)pSMB;
2502 pSMB->Reserved = 0;
2503 pSMB->TotalParameterCount = cpu_to_le32(parm_len);
2504 pSMB->TotalDataCount = 0;
2505 pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf -
2506 MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
2507 pSMB->ParameterCount = pSMB->TotalParameterCount;
2508 pSMB->DataCount = pSMB->TotalDataCount;
2509 temp_offset = offsetof(struct smb_com_ntransact_req, Parms) +
2510 (setup_count * 2) - 4 /* for rfc1001 length itself */;
2511 pSMB->ParameterOffset = cpu_to_le32(temp_offset);
2512 pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len);
2513 pSMB->SetupCount = setup_count; /* no need to le convert byte fields */
2514 pSMB->SubCommand = cpu_to_le16(sub_command);
2515 return 0;
2516}
2517
2518static int
2519validate_ntransact(char *buf, char **ppparm, char **ppdata,
2520 __u32 *pparmlen, __u32 *pdatalen)
2521{
2522 char *end_of_smb;
2523 __u32 data_count, data_offset, parm_count, parm_offset;
2524 struct smb_com_ntransact_rsp *pSMBr;
2525
2526 *pdatalen = 0;
2527 *pparmlen = 0;
2528
2529 if (buf == NULL)
2530 return -EINVAL;
2531
2532 pSMBr = (struct smb_com_ntransact_rsp *)buf;
2533
2534 /* ByteCount was converted from little endian in SendReceive */
2535 end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount +
2536 (char *)&pSMBr->ByteCount;
2537
2538 data_offset = le32_to_cpu(pSMBr->DataOffset);
2539 data_count = le32_to_cpu(pSMBr->DataCount);
2540 parm_offset = le32_to_cpu(pSMBr->ParameterOffset);
2541 parm_count = le32_to_cpu(pSMBr->ParameterCount);
2542
2543 *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset;
2544 *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset;
2545
2546 /* should we also check that parm and data areas do not overlap? */
2547 if (*ppparm > end_of_smb) {
2548 cFYI(1, "parms start after end of smb");
2549 return -EINVAL;
2550 } else if (parm_count + *ppparm > end_of_smb) {
2551 cFYI(1, "parm end after end of smb");
2552 return -EINVAL;
2553 } else if (*ppdata > end_of_smb) {
2554 cFYI(1, "data starts after end of smb");
2555 return -EINVAL;
2556 } else if (data_count + *ppdata > end_of_smb) {
2557 cFYI(1, "data %p + count %d (%p) past smb end %p start %p",
2558 *ppdata, data_count, (data_count + *ppdata),
2559 end_of_smb, pSMBr);
2560 return -EINVAL;
2561 } else if (parm_count + data_count > pSMBr->ByteCount) {
2562 cFYI(1, "parm count and data count larger than SMB");
2563 return -EINVAL;
2564 }
2565 *pdatalen = data_count;
2566 *pparmlen = parm_count;
2567 return 0;
2568}
2569
2570int 2481int
2571CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, 2482CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
2572 const unsigned char *searchName, 2483 const unsigned char *searchName,
@@ -3056,7 +2967,97 @@ GetExtAttrOut:
3056 2967
3057#endif /* CONFIG_POSIX */ 2968#endif /* CONFIG_POSIX */
3058 2969
3059#ifdef CONFIG_CIFS_EXPERIMENTAL 2970#ifdef CONFIG_CIFS_ACL
2971/*
2972 * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that
2973 * all NT TRANSACTS that we init here have total parm and data under about 400
2974 * bytes (to fit in small cifs buffer size), which is the case so far, it
2975 * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of
2976 * returned setup area) and MaxParameterCount (returned parms size) must be set
2977 * by caller
2978 */
2979static int
2980smb_init_nttransact(const __u16 sub_command, const int setup_count,
2981 const int parm_len, struct cifsTconInfo *tcon,
2982 void **ret_buf)
2983{
2984 int rc;
2985 __u32 temp_offset;
2986 struct smb_com_ntransact_req *pSMB;
2987
2988 rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon,
2989 (void **)&pSMB);
2990 if (rc)
2991 return rc;
2992 *ret_buf = (void *)pSMB;
2993 pSMB->Reserved = 0;
2994 pSMB->TotalParameterCount = cpu_to_le32(parm_len);
2995 pSMB->TotalDataCount = 0;
2996 pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf -
2997 MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
2998 pSMB->ParameterCount = pSMB->TotalParameterCount;
2999 pSMB->DataCount = pSMB->TotalDataCount;
3000 temp_offset = offsetof(struct smb_com_ntransact_req, Parms) +
3001 (setup_count * 2) - 4 /* for rfc1001 length itself */;
3002 pSMB->ParameterOffset = cpu_to_le32(temp_offset);
3003 pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len);
3004 pSMB->SetupCount = setup_count; /* no need to le convert byte fields */
3005 pSMB->SubCommand = cpu_to_le16(sub_command);
3006 return 0;
3007}
3008
3009static int
3010validate_ntransact(char *buf, char **ppparm, char **ppdata,
3011 __u32 *pparmlen, __u32 *pdatalen)
3012{
3013 char *end_of_smb;
3014 __u32 data_count, data_offset, parm_count, parm_offset;
3015 struct smb_com_ntransact_rsp *pSMBr;
3016
3017 *pdatalen = 0;
3018 *pparmlen = 0;
3019
3020 if (buf == NULL)
3021 return -EINVAL;
3022
3023 pSMBr = (struct smb_com_ntransact_rsp *)buf;
3024
3025 /* ByteCount was converted from little endian in SendReceive */
3026 end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount +
3027 (char *)&pSMBr->ByteCount;
3028
3029 data_offset = le32_to_cpu(pSMBr->DataOffset);
3030 data_count = le32_to_cpu(pSMBr->DataCount);
3031 parm_offset = le32_to_cpu(pSMBr->ParameterOffset);
3032 parm_count = le32_to_cpu(pSMBr->ParameterCount);
3033
3034 *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset;
3035 *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset;
3036
3037 /* should we also check that parm and data areas do not overlap? */
3038 if (*ppparm > end_of_smb) {
3039 cFYI(1, "parms start after end of smb");
3040 return -EINVAL;
3041 } else if (parm_count + *ppparm > end_of_smb) {
3042 cFYI(1, "parm end after end of smb");
3043 return -EINVAL;
3044 } else if (*ppdata > end_of_smb) {
3045 cFYI(1, "data starts after end of smb");
3046 return -EINVAL;
3047 } else if (data_count + *ppdata > end_of_smb) {
3048 cFYI(1, "data %p + count %d (%p) past smb end %p start %p",
3049 *ppdata, data_count, (data_count + *ppdata),
3050 end_of_smb, pSMBr);
3051 return -EINVAL;
3052 } else if (parm_count + data_count > pSMBr->ByteCount) {
3053 cFYI(1, "parm count and data count larger than SMB");
3054 return -EINVAL;
3055 }
3056 *pdatalen = data_count;
3057 *pparmlen = parm_count;
3058 return 0;
3059}
3060
3060/* Get Security Descriptor (by handle) from remote server for a file or dir */ 3061/* Get Security Descriptor (by handle) from remote server for a file or dir */
3061int 3062int
3062CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, 3063CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
@@ -3214,7 +3215,7 @@ setCifsAclRetry:
3214 return (rc); 3215 return (rc);
3215} 3216}
3216 3217
3217#endif /* CONFIG_CIFS_EXPERIMENTAL */ 3218#endif /* CONFIG_CIFS_ACL */
3218 3219
3219/* Legacy Query Path Information call for lookup to old servers such 3220/* Legacy Query Path Information call for lookup to old servers such
3220 as Win9x/WinME */ 3221 as Win9x/WinME */
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 9eb327defa1d..cc1a8604a790 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -105,6 +105,7 @@ struct smb_vol {
105 unsigned int wsize; 105 unsigned int wsize;
106 bool sockopt_tcp_nodelay:1; 106 bool sockopt_tcp_nodelay:1;
107 unsigned short int port; 107 unsigned short int port;
108 unsigned long actimeo; /* attribute cache timeout (jiffies) */
108 char *prepath; 109 char *prepath;
109 struct sockaddr_storage srcaddr; /* allow binding to a local IP */ 110 struct sockaddr_storage srcaddr; /* allow binding to a local IP */
110 struct nls_table *local_nls; 111 struct nls_table *local_nls;
@@ -116,6 +117,7 @@ struct smb_vol {
116 117
117static int ipv4_connect(struct TCP_Server_Info *server); 118static int ipv4_connect(struct TCP_Server_Info *server);
118static int ipv6_connect(struct TCP_Server_Info *server); 119static int ipv6_connect(struct TCP_Server_Info *server);
120static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
119static void cifs_prune_tlinks(struct work_struct *work); 121static void cifs_prune_tlinks(struct work_struct *work);
120 122
121/* 123/*
@@ -805,23 +807,20 @@ cifs_parse_mount_options(char *options, const char *devname,
805 short int override_gid = -1; 807 short int override_gid = -1;
806 bool uid_specified = false; 808 bool uid_specified = false;
807 bool gid_specified = false; 809 bool gid_specified = false;
810 char *nodename = utsname()->nodename;
808 811
809 separator[0] = ','; 812 separator[0] = ',';
810 separator[1] = 0; 813 separator[1] = 0;
811 814
812 if (Local_System_Name[0] != 0) 815 /*
813 memcpy(vol->source_rfc1001_name, Local_System_Name, 15); 816 * does not have to be perfect mapping since field is
814 else { 817 * informational, only used for servers that do not support
815 char *nodename = utsname()->nodename; 818 * port 445 and it can be overridden at mount time
816 int n = strnlen(nodename, 15); 819 */
817 memset(vol->source_rfc1001_name, 0x20, 15); 820 memset(vol->source_rfc1001_name, 0x20, 15);
818 for (i = 0; i < n; i++) { 821 for (i = 0; i < strnlen(nodename, 15); i++)
819 /* does not have to be perfect mapping since field is 822 vol->source_rfc1001_name[i] = toupper(nodename[i]);
820 informational, only used for servers that do not support 823
821 port 445 and it can be overridden at mount time */
822 vol->source_rfc1001_name[i] = toupper(nodename[i]);
823 }
824 }
825 vol->source_rfc1001_name[15] = 0; 824 vol->source_rfc1001_name[15] = 0;
826 /* null target name indicates to use *SMBSERVR default called name 825 /* null target name indicates to use *SMBSERVR default called name
827 if we end up sending RFC1001 session initialize */ 826 if we end up sending RFC1001 session initialize */
@@ -839,6 +838,8 @@ cifs_parse_mount_options(char *options, const char *devname,
839 /* default to using server inode numbers where available */ 838 /* default to using server inode numbers where available */
840 vol->server_ino = 1; 839 vol->server_ino = 1;
841 840
841 vol->actimeo = CIFS_DEF_ACTIMEO;
842
842 if (!options) 843 if (!options)
843 return 1; 844 return 1;
844 845
@@ -1213,6 +1214,16 @@ cifs_parse_mount_options(char *options, const char *devname,
1213 printk(KERN_WARNING "CIFS: server net" 1214 printk(KERN_WARNING "CIFS: server net"
1214 "biosname longer than 15 truncated.\n"); 1215 "biosname longer than 15 truncated.\n");
1215 } 1216 }
1217 } else if (strnicmp(data, "actimeo", 7) == 0) {
1218 if (value && *value) {
1219 vol->actimeo = HZ * simple_strtoul(value,
1220 &value, 0);
1221 if (vol->actimeo > CIFS_MAX_ACTIMEO) {
1222 cERROR(1, "CIFS: attribute cache"
1223 "timeout too large");
1224 return 1;
1225 }
1226 }
1216 } else if (strnicmp(data, "credentials", 4) == 0) { 1227 } else if (strnicmp(data, "credentials", 4) == 0) {
1217 /* ignore */ 1228 /* ignore */
1218 } else if (strnicmp(data, "version", 3) == 0) { 1229 } else if (strnicmp(data, "version", 3) == 0) {
@@ -1351,6 +1362,11 @@ cifs_parse_mount_options(char *options, const char *devname,
1351 "supported. Instead set " 1362 "supported. Instead set "
1352 "/proc/fs/cifs/LookupCacheEnabled to 0\n"); 1363 "/proc/fs/cifs/LookupCacheEnabled to 0\n");
1353 } else if (strnicmp(data, "fsc", 3) == 0) { 1364 } else if (strnicmp(data, "fsc", 3) == 0) {
1365#ifndef CONFIG_CIFS_FSCACHE
1366 cERROR(1, "FS-Cache support needs CONFIG_CIFS_FSCACHE"
1367 "kernel config option set");
1368 return 1;
1369#endif
1354 vol->fsc = true; 1370 vol->fsc = true;
1355 } else if (strnicmp(data, "mfsymlinks", 10) == 0) { 1371 } else if (strnicmp(data, "mfsymlinks", 10) == 0) {
1356 vol->mfsymlinks = true; 1372 vol->mfsymlinks = true;
@@ -2565,6 +2581,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
2565 cFYI(1, "file mode: 0x%x dir mode: 0x%x", 2581 cFYI(1, "file mode: 0x%x dir mode: 0x%x",
2566 cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode); 2582 cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode);
2567 2583
2584 cifs_sb->actimeo = pvolume_info->actimeo;
2585
2568 if (pvolume_info->noperm) 2586 if (pvolume_info->noperm)
2569 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM; 2587 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
2570 if (pvolume_info->setuids) 2588 if (pvolume_info->setuids)
@@ -2815,13 +2833,13 @@ remote_path_check:
2815 /* check if a whole path (including prepath) is not remote */ 2833 /* check if a whole path (including prepath) is not remote */
2816 if (!rc && cifs_sb->prepathlen && tcon) { 2834 if (!rc && cifs_sb->prepathlen && tcon) {
2817 /* build_path_to_root works only when we have a valid tcon */ 2835 /* build_path_to_root works only when we have a valid tcon */
2818 full_path = cifs_build_path_to_root(cifs_sb); 2836 full_path = cifs_build_path_to_root(cifs_sb, tcon);
2819 if (full_path == NULL) { 2837 if (full_path == NULL) {
2820 rc = -ENOMEM; 2838 rc = -ENOMEM;
2821 goto mount_fail_check; 2839 goto mount_fail_check;
2822 } 2840 }
2823 rc = is_path_accessible(xid, tcon, cifs_sb, full_path); 2841 rc = is_path_accessible(xid, tcon, cifs_sb, full_path);
2824 if (rc != -EREMOTE) { 2842 if (rc != 0 && rc != -EREMOTE) {
2825 kfree(full_path); 2843 kfree(full_path);
2826 goto mount_fail_check; 2844 goto mount_fail_check;
2827 } 2845 }
@@ -2900,24 +2918,16 @@ remote_path_check:
2900 goto mount_fail_check; 2918 goto mount_fail_check;
2901 } 2919 }
2902 2920
2903 tlink->tl_index = pSesInfo->linux_uid; 2921 tlink->tl_uid = pSesInfo->linux_uid;
2904 tlink->tl_tcon = tcon; 2922 tlink->tl_tcon = tcon;
2905 tlink->tl_time = jiffies; 2923 tlink->tl_time = jiffies;
2906 set_bit(TCON_LINK_MASTER, &tlink->tl_flags); 2924 set_bit(TCON_LINK_MASTER, &tlink->tl_flags);
2907 set_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); 2925 set_bit(TCON_LINK_IN_TREE, &tlink->tl_flags);
2908 2926
2909 rc = radix_tree_preload(GFP_KERNEL); 2927 cifs_sb->master_tlink = tlink;
2910 if (rc == -ENOMEM) {
2911 kfree(tlink);
2912 goto mount_fail_check;
2913 }
2914
2915 spin_lock(&cifs_sb->tlink_tree_lock); 2928 spin_lock(&cifs_sb->tlink_tree_lock);
2916 radix_tree_insert(&cifs_sb->tlink_tree, pSesInfo->linux_uid, tlink); 2929 tlink_rb_insert(&cifs_sb->tlink_tree, tlink);
2917 radix_tree_tag_set(&cifs_sb->tlink_tree, pSesInfo->linux_uid,
2918 CIFS_TLINK_MASTER_TAG);
2919 spin_unlock(&cifs_sb->tlink_tree_lock); 2930 spin_unlock(&cifs_sb->tlink_tree_lock);
2920 radix_tree_preload_end();
2921 2931
2922 queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks, 2932 queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
2923 TLINK_IDLE_EXPIRE); 2933 TLINK_IDLE_EXPIRE);
@@ -3107,32 +3117,25 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3107int 3117int
3108cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb) 3118cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
3109{ 3119{
3110 int i, ret; 3120 struct rb_root *root = &cifs_sb->tlink_tree;
3121 struct rb_node *node;
3122 struct tcon_link *tlink;
3111 char *tmp; 3123 char *tmp;
3112 struct tcon_link *tlink[8];
3113 unsigned long index = 0;
3114 3124
3115 cancel_delayed_work_sync(&cifs_sb->prune_tlinks); 3125 cancel_delayed_work_sync(&cifs_sb->prune_tlinks);
3116 3126
3117 do { 3127 spin_lock(&cifs_sb->tlink_tree_lock);
3118 spin_lock(&cifs_sb->tlink_tree_lock); 3128 while ((node = rb_first(root))) {
3119 ret = radix_tree_gang_lookup(&cifs_sb->tlink_tree, 3129 tlink = rb_entry(node, struct tcon_link, tl_rbnode);
3120 (void **)tlink, index, 3130 cifs_get_tlink(tlink);
3121 ARRAY_SIZE(tlink)); 3131 clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags);
3122 /* increment index for next pass */ 3132 rb_erase(node, root);
3123 if (ret > 0)
3124 index = tlink[ret - 1]->tl_index + 1;
3125 for (i = 0; i < ret; i++) {
3126 cifs_get_tlink(tlink[i]);
3127 clear_bit(TCON_LINK_IN_TREE, &tlink[i]->tl_flags);
3128 radix_tree_delete(&cifs_sb->tlink_tree,
3129 tlink[i]->tl_index);
3130 }
3131 spin_unlock(&cifs_sb->tlink_tree_lock);
3132 3133
3133 for (i = 0; i < ret; i++) 3134 spin_unlock(&cifs_sb->tlink_tree_lock);
3134 cifs_put_tlink(tlink[i]); 3135 cifs_put_tlink(tlink);
3135 } while (ret != 0); 3136 spin_lock(&cifs_sb->tlink_tree_lock);
3137 }
3138 spin_unlock(&cifs_sb->tlink_tree_lock);
3136 3139
3137 tmp = cifs_sb->prepath; 3140 tmp = cifs_sb->prepath;
3138 cifs_sb->prepathlen = 0; 3141 cifs_sb->prepathlen = 0;
@@ -3271,22 +3274,10 @@ out:
3271 return tcon; 3274 return tcon;
3272} 3275}
3273 3276
3274static struct tcon_link * 3277static inline struct tcon_link *
3275cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb) 3278cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb)
3276{ 3279{
3277 struct tcon_link *tlink; 3280 return cifs_sb->master_tlink;
3278 unsigned int ret;
3279
3280 spin_lock(&cifs_sb->tlink_tree_lock);
3281 ret = radix_tree_gang_lookup_tag(&cifs_sb->tlink_tree, (void **)&tlink,
3282 0, 1, CIFS_TLINK_MASTER_TAG);
3283 spin_unlock(&cifs_sb->tlink_tree_lock);
3284
3285 /* the master tcon should always be present */
3286 if (ret == 0)
3287 BUG();
3288
3289 return tlink;
3290} 3281}
3291 3282
3292struct cifsTconInfo * 3283struct cifsTconInfo *
@@ -3302,6 +3293,47 @@ cifs_sb_tcon_pending_wait(void *unused)
3302 return signal_pending(current) ? -ERESTARTSYS : 0; 3293 return signal_pending(current) ? -ERESTARTSYS : 0;
3303} 3294}
3304 3295
3296/* find and return a tlink with given uid */
3297static struct tcon_link *
3298tlink_rb_search(struct rb_root *root, uid_t uid)
3299{
3300 struct rb_node *node = root->rb_node;
3301 struct tcon_link *tlink;
3302
3303 while (node) {
3304 tlink = rb_entry(node, struct tcon_link, tl_rbnode);
3305
3306 if (tlink->tl_uid > uid)
3307 node = node->rb_left;
3308 else if (tlink->tl_uid < uid)
3309 node = node->rb_right;
3310 else
3311 return tlink;
3312 }
3313 return NULL;
3314}
3315
3316/* insert a tcon_link into the tree */
3317static void
3318tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink)
3319{
3320 struct rb_node **new = &(root->rb_node), *parent = NULL;
3321 struct tcon_link *tlink;
3322
3323 while (*new) {
3324 tlink = rb_entry(*new, struct tcon_link, tl_rbnode);
3325 parent = *new;
3326
3327 if (tlink->tl_uid > new_tlink->tl_uid)
3328 new = &((*new)->rb_left);
3329 else
3330 new = &((*new)->rb_right);
3331 }
3332
3333 rb_link_node(&new_tlink->tl_rbnode, parent, new);
3334 rb_insert_color(&new_tlink->tl_rbnode, root);
3335}
3336
3305/* 3337/*
3306 * Find or construct an appropriate tcon given a cifs_sb and the fsuid of the 3338 * Find or construct an appropriate tcon given a cifs_sb and the fsuid of the
3307 * current task. 3339 * current task.
@@ -3309,7 +3341,7 @@ cifs_sb_tcon_pending_wait(void *unused)
3309 * If the superblock doesn't refer to a multiuser mount, then just return 3341 * If the superblock doesn't refer to a multiuser mount, then just return
3310 * the master tcon for the mount. 3342 * the master tcon for the mount.
3311 * 3343 *
3312 * First, search the radix tree for an existing tcon for this fsuid. If one 3344 * First, search the rbtree for an existing tcon for this fsuid. If one
3313 * exists, then check to see if it's pending construction. If it is then wait 3345 * exists, then check to see if it's pending construction. If it is then wait
3314 * for construction to complete. Once it's no longer pending, check to see if 3346 * for construction to complete. Once it's no longer pending, check to see if
3315 * it failed and either return an error or retry construction, depending on 3347 * it failed and either return an error or retry construction, depending on
@@ -3322,14 +3354,14 @@ struct tcon_link *
3322cifs_sb_tlink(struct cifs_sb_info *cifs_sb) 3354cifs_sb_tlink(struct cifs_sb_info *cifs_sb)
3323{ 3355{
3324 int ret; 3356 int ret;
3325 unsigned long fsuid = (unsigned long) current_fsuid(); 3357 uid_t fsuid = current_fsuid();
3326 struct tcon_link *tlink, *newtlink; 3358 struct tcon_link *tlink, *newtlink;
3327 3359
3328 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) 3360 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER))
3329 return cifs_get_tlink(cifs_sb_master_tlink(cifs_sb)); 3361 return cifs_get_tlink(cifs_sb_master_tlink(cifs_sb));
3330 3362
3331 spin_lock(&cifs_sb->tlink_tree_lock); 3363 spin_lock(&cifs_sb->tlink_tree_lock);
3332 tlink = radix_tree_lookup(&cifs_sb->tlink_tree, fsuid); 3364 tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid);
3333 if (tlink) 3365 if (tlink)
3334 cifs_get_tlink(tlink); 3366 cifs_get_tlink(tlink);
3335 spin_unlock(&cifs_sb->tlink_tree_lock); 3367 spin_unlock(&cifs_sb->tlink_tree_lock);
@@ -3338,36 +3370,24 @@ cifs_sb_tlink(struct cifs_sb_info *cifs_sb)
3338 newtlink = kzalloc(sizeof(*tlink), GFP_KERNEL); 3370 newtlink = kzalloc(sizeof(*tlink), GFP_KERNEL);
3339 if (newtlink == NULL) 3371 if (newtlink == NULL)
3340 return ERR_PTR(-ENOMEM); 3372 return ERR_PTR(-ENOMEM);
3341 newtlink->tl_index = fsuid; 3373 newtlink->tl_uid = fsuid;
3342 newtlink->tl_tcon = ERR_PTR(-EACCES); 3374 newtlink->tl_tcon = ERR_PTR(-EACCES);
3343 set_bit(TCON_LINK_PENDING, &newtlink->tl_flags); 3375 set_bit(TCON_LINK_PENDING, &newtlink->tl_flags);
3344 set_bit(TCON_LINK_IN_TREE, &newtlink->tl_flags); 3376 set_bit(TCON_LINK_IN_TREE, &newtlink->tl_flags);
3345 cifs_get_tlink(newtlink); 3377 cifs_get_tlink(newtlink);
3346 3378
3347 ret = radix_tree_preload(GFP_KERNEL);
3348 if (ret != 0) {
3349 kfree(newtlink);
3350 return ERR_PTR(ret);
3351 }
3352
3353 spin_lock(&cifs_sb->tlink_tree_lock); 3379 spin_lock(&cifs_sb->tlink_tree_lock);
3354 /* was one inserted after previous search? */ 3380 /* was one inserted after previous search? */
3355 tlink = radix_tree_lookup(&cifs_sb->tlink_tree, fsuid); 3381 tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid);
3356 if (tlink) { 3382 if (tlink) {
3357 cifs_get_tlink(tlink); 3383 cifs_get_tlink(tlink);
3358 spin_unlock(&cifs_sb->tlink_tree_lock); 3384 spin_unlock(&cifs_sb->tlink_tree_lock);
3359 radix_tree_preload_end();
3360 kfree(newtlink); 3385 kfree(newtlink);
3361 goto wait_for_construction; 3386 goto wait_for_construction;
3362 } 3387 }
3363 ret = radix_tree_insert(&cifs_sb->tlink_tree, fsuid, newtlink);
3364 spin_unlock(&cifs_sb->tlink_tree_lock);
3365 radix_tree_preload_end();
3366 if (ret) {
3367 kfree(newtlink);
3368 return ERR_PTR(ret);
3369 }
3370 tlink = newtlink; 3388 tlink = newtlink;
3389 tlink_rb_insert(&cifs_sb->tlink_tree, tlink);
3390 spin_unlock(&cifs_sb->tlink_tree_lock);
3371 } else { 3391 } else {
3372wait_for_construction: 3392wait_for_construction:
3373 ret = wait_on_bit(&tlink->tl_flags, TCON_LINK_PENDING, 3393 ret = wait_on_bit(&tlink->tl_flags, TCON_LINK_PENDING,
@@ -3413,39 +3433,39 @@ cifs_prune_tlinks(struct work_struct *work)
3413{ 3433{
3414 struct cifs_sb_info *cifs_sb = container_of(work, struct cifs_sb_info, 3434 struct cifs_sb_info *cifs_sb = container_of(work, struct cifs_sb_info,
3415 prune_tlinks.work); 3435 prune_tlinks.work);
3416 struct tcon_link *tlink[8]; 3436 struct rb_root *root = &cifs_sb->tlink_tree;
3417 unsigned long now = jiffies; 3437 struct rb_node *node = rb_first(root);
3418 unsigned long index = 0; 3438 struct rb_node *tmp;
3419 int i, ret; 3439 struct tcon_link *tlink;
3420 3440
3421 do { 3441 /*
3422 spin_lock(&cifs_sb->tlink_tree_lock); 3442 * Because we drop the spinlock in the loop in order to put the tlink
3423 ret = radix_tree_gang_lookup(&cifs_sb->tlink_tree, 3443 * it's not guarded against removal of links from the tree. The only
3424 (void **)tlink, index, 3444 * places that remove entries from the tree are this function and
3425 ARRAY_SIZE(tlink)); 3445 * umounts. Because this function is non-reentrant and is canceled
3426 /* increment index for next pass */ 3446 * before umount can proceed, this is safe.
3427 if (ret > 0) 3447 */
3428 index = tlink[ret - 1]->tl_index + 1; 3448 spin_lock(&cifs_sb->tlink_tree_lock);
3429 for (i = 0; i < ret; i++) { 3449 node = rb_first(root);
3430 if (test_bit(TCON_LINK_MASTER, &tlink[i]->tl_flags) || 3450 while (node != NULL) {
3431 atomic_read(&tlink[i]->tl_count) != 0 || 3451 tmp = node;
3432 time_after(tlink[i]->tl_time + TLINK_IDLE_EXPIRE, 3452 node = rb_next(tmp);
3433 now)) { 3453 tlink = rb_entry(tmp, struct tcon_link, tl_rbnode);
3434 tlink[i] = NULL; 3454
3435 continue; 3455 if (test_bit(TCON_LINK_MASTER, &tlink->tl_flags) ||
3436 } 3456 atomic_read(&tlink->tl_count) != 0 ||
3437 cifs_get_tlink(tlink[i]); 3457 time_after(tlink->tl_time + TLINK_IDLE_EXPIRE, jiffies))
3438 clear_bit(TCON_LINK_IN_TREE, &tlink[i]->tl_flags); 3458 continue;
3439 radix_tree_delete(&cifs_sb->tlink_tree,
3440 tlink[i]->tl_index);
3441 }
3442 spin_unlock(&cifs_sb->tlink_tree_lock);
3443 3459
3444 for (i = 0; i < ret; i++) { 3460 cifs_get_tlink(tlink);
3445 if (tlink[i] != NULL) 3461 clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags);
3446 cifs_put_tlink(tlink[i]); 3462 rb_erase(tmp, root);
3447 } 3463
3448 } while (ret != 0); 3464 spin_unlock(&cifs_sb->tlink_tree_lock);
3465 cifs_put_tlink(tlink);
3466 spin_lock(&cifs_sb->tlink_tree_lock);
3467 }
3468 spin_unlock(&cifs_sb->tlink_tree_lock);
3449 3469
3450 queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks, 3470 queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
3451 TLINK_IDLE_EXPIRE); 3471 TLINK_IDLE_EXPIRE);
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c
index 0eb87026cad3..548f06230a6d 100644
--- a/fs/cifs/dns_resolve.c
+++ b/fs/cifs/dns_resolve.c
@@ -66,7 +66,7 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
66 /* Search for server name delimiter */ 66 /* Search for server name delimiter */
67 sep = memchr(hostname, '\\', len); 67 sep = memchr(hostname, '\\', len);
68 if (sep) 68 if (sep)
69 len = sep - unc; 69 len = sep - hostname;
70 else 70 else
71 cFYI(1, "%s: probably server name is whole unc: %s", 71 cFYI(1, "%s: probably server name is whole unc: %s",
72 __func__, unc); 72 __func__, unc);
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index ae82159cf7fa..5a28660ca2b5 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -146,12 +146,7 @@ client_can_cache:
146 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, 146 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
147 xid, NULL); 147 xid, NULL);
148 148
149 if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { 149 cifs_set_oplock_level(pCifsInode, oplock);
150 pCifsInode->clientCanCacheAll = true;
151 pCifsInode->clientCanCacheRead = true;
152 cFYI(1, "Exclusive Oplock granted on inode %p", inode);
153 } else if ((oplock & 0xF) == OPLOCK_READ)
154 pCifsInode->clientCanCacheRead = true;
155 150
156 return rc; 151 return rc;
157} 152}
@@ -253,12 +248,7 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file,
253 list_add_tail(&pCifsFile->flist, &pCifsInode->openFileList); 248 list_add_tail(&pCifsFile->flist, &pCifsInode->openFileList);
254 spin_unlock(&cifs_file_list_lock); 249 spin_unlock(&cifs_file_list_lock);
255 250
256 if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { 251 cifs_set_oplock_level(pCifsInode, oplock);
257 pCifsInode->clientCanCacheAll = true;
258 pCifsInode->clientCanCacheRead = true;
259 cFYI(1, "Exclusive Oplock inode %p", inode);
260 } else if ((oplock & 0xF) == OPLOCK_READ)
261 pCifsInode->clientCanCacheRead = true;
262 252
263 file->private_data = pCifsFile; 253 file->private_data = pCifsFile;
264 return pCifsFile; 254 return pCifsFile;
@@ -271,8 +261,9 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file,
271 */ 261 */
272void cifsFileInfo_put(struct cifsFileInfo *cifs_file) 262void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
273{ 263{
264 struct inode *inode = cifs_file->dentry->d_inode;
274 struct cifsTconInfo *tcon = tlink_tcon(cifs_file->tlink); 265 struct cifsTconInfo *tcon = tlink_tcon(cifs_file->tlink);
275 struct cifsInodeInfo *cifsi = CIFS_I(cifs_file->dentry->d_inode); 266 struct cifsInodeInfo *cifsi = CIFS_I(inode);
276 struct cifsLockInfo *li, *tmp; 267 struct cifsLockInfo *li, *tmp;
277 268
278 spin_lock(&cifs_file_list_lock); 269 spin_lock(&cifs_file_list_lock);
@@ -288,8 +279,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
288 if (list_empty(&cifsi->openFileList)) { 279 if (list_empty(&cifsi->openFileList)) {
289 cFYI(1, "closing last open instance for inode %p", 280 cFYI(1, "closing last open instance for inode %p",
290 cifs_file->dentry->d_inode); 281 cifs_file->dentry->d_inode);
291 cifsi->clientCanCacheRead = false; 282 cifs_set_oplock_level(cifsi, 0);
292 cifsi->clientCanCacheAll = false;
293 } 283 }
294 spin_unlock(&cifs_file_list_lock); 284 spin_unlock(&cifs_file_list_lock);
295 285
@@ -607,8 +597,6 @@ reopen_success:
607 rc = filemap_write_and_wait(inode->i_mapping); 597 rc = filemap_write_and_wait(inode->i_mapping);
608 mapping_set_error(inode->i_mapping, rc); 598 mapping_set_error(inode->i_mapping, rc);
609 599
610 pCifsInode->clientCanCacheAll = false;
611 pCifsInode->clientCanCacheRead = false;
612 if (tcon->unix_ext) 600 if (tcon->unix_ext)
613 rc = cifs_get_inode_info_unix(&inode, 601 rc = cifs_get_inode_info_unix(&inode,
614 full_path, inode->i_sb, xid); 602 full_path, inode->i_sb, xid);
@@ -622,18 +610,9 @@ reopen_success:
622 invalidate the current end of file on the server 610 invalidate the current end of file on the server
623 we can not go to the server to get the new inod 611 we can not go to the server to get the new inod
624 info */ 612 info */
625 if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { 613
626 pCifsInode->clientCanCacheAll = true; 614 cifs_set_oplock_level(pCifsInode, oplock);
627 pCifsInode->clientCanCacheRead = true; 615
628 cFYI(1, "Exclusive Oplock granted on inode %p",
629 pCifsFile->dentry->d_inode);
630 } else if ((oplock & 0xF) == OPLOCK_READ) {
631 pCifsInode->clientCanCacheRead = true;
632 pCifsInode->clientCanCacheAll = false;
633 } else {
634 pCifsInode->clientCanCacheRead = false;
635 pCifsInode->clientCanCacheAll = false;
636 }
637 cifs_relock_file(pCifsFile); 616 cifs_relock_file(pCifsFile);
638 617
639reopen_error_exit: 618reopen_error_exit:
@@ -775,12 +754,6 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
775 754
776 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 755 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
777 tcon = tlink_tcon(((struct cifsFileInfo *)file->private_data)->tlink); 756 tcon = tlink_tcon(((struct cifsFileInfo *)file->private_data)->tlink);
778
779 if (file->private_data == NULL) {
780 rc = -EBADF;
781 FreeXid(xid);
782 return rc;
783 }
784 netfid = ((struct cifsFileInfo *)file->private_data)->netfid; 757 netfid = ((struct cifsFileInfo *)file->private_data)->netfid;
785 758
786 if ((tcon->ses->capabilities & CAP_UNIX) && 759 if ((tcon->ses->capabilities & CAP_UNIX) &&
@@ -956,6 +929,7 @@ cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
956ssize_t cifs_user_write(struct file *file, const char __user *write_data, 929ssize_t cifs_user_write(struct file *file, const char __user *write_data,
957 size_t write_size, loff_t *poffset) 930 size_t write_size, loff_t *poffset)
958{ 931{
932 struct inode *inode = file->f_path.dentry->d_inode;
959 int rc = 0; 933 int rc = 0;
960 unsigned int bytes_written = 0; 934 unsigned int bytes_written = 0;
961 unsigned int total_written; 935 unsigned int total_written;
@@ -963,7 +937,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
963 struct cifsTconInfo *pTcon; 937 struct cifsTconInfo *pTcon;
964 int xid, long_op; 938 int xid, long_op;
965 struct cifsFileInfo *open_file; 939 struct cifsFileInfo *open_file;
966 struct cifsInodeInfo *cifsi = CIFS_I(file->f_path.dentry->d_inode); 940 struct cifsInodeInfo *cifsi = CIFS_I(inode);
967 941
968 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 942 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
969 943
@@ -1029,21 +1003,17 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
1029 1003
1030 cifs_stats_bytes_written(pTcon, total_written); 1004 cifs_stats_bytes_written(pTcon, total_written);
1031 1005
1032 /* since the write may have blocked check these pointers again */
1033 if ((file->f_path.dentry) && (file->f_path.dentry->d_inode)) {
1034 struct inode *inode = file->f_path.dentry->d_inode;
1035/* Do not update local mtime - server will set its actual value on write 1006/* Do not update local mtime - server will set its actual value on write
1036 * inode->i_ctime = inode->i_mtime = 1007 * inode->i_ctime = inode->i_mtime =
1037 * current_fs_time(inode->i_sb);*/ 1008 * current_fs_time(inode->i_sb);*/
1038 if (total_written > 0) { 1009 if (total_written > 0) {
1039 spin_lock(&inode->i_lock); 1010 spin_lock(&inode->i_lock);
1040 if (*poffset > file->f_path.dentry->d_inode->i_size) 1011 if (*poffset > inode->i_size)
1041 i_size_write(file->f_path.dentry->d_inode, 1012 i_size_write(inode, *poffset);
1042 *poffset); 1013 spin_unlock(&inode->i_lock);
1043 spin_unlock(&inode->i_lock);
1044 }
1045 mark_inode_dirty_sync(file->f_path.dentry->d_inode);
1046 } 1014 }
1015 mark_inode_dirty_sync(inode);
1016
1047 FreeXid(xid); 1017 FreeXid(xid);
1048 return total_written; 1018 return total_written;
1049} 1019}
@@ -1138,7 +1108,6 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file,
1138 return total_written; 1108 return total_written;
1139} 1109}
1140 1110
1141#ifdef CONFIG_CIFS_EXPERIMENTAL
1142struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode, 1111struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,
1143 bool fsuid_only) 1112 bool fsuid_only)
1144{ 1113{
@@ -1172,13 +1141,12 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,
1172 spin_unlock(&cifs_file_list_lock); 1141 spin_unlock(&cifs_file_list_lock);
1173 return NULL; 1142 return NULL;
1174} 1143}
1175#endif
1176 1144
1177struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, 1145struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode,
1178 bool fsuid_only) 1146 bool fsuid_only)
1179{ 1147{
1180 struct cifsFileInfo *open_file; 1148 struct cifsFileInfo *open_file;
1181 struct cifs_sb_info *cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); 1149 struct cifs_sb_info *cifs_sb;
1182 bool any_available = false; 1150 bool any_available = false;
1183 int rc; 1151 int rc;
1184 1152
@@ -1192,6 +1160,8 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode,
1192 return NULL; 1160 return NULL;
1193 } 1161 }
1194 1162
1163 cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb);
1164
1195 /* only filter by fsuid on multiuser mounts */ 1165 /* only filter by fsuid on multiuser mounts */
1196 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) 1166 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER))
1197 fsuid_only = false; 1167 fsuid_only = false;
@@ -2299,8 +2269,10 @@ void cifs_oplock_break_get(struct cifsFileInfo *cfile)
2299 2269
2300void cifs_oplock_break_put(struct cifsFileInfo *cfile) 2270void cifs_oplock_break_put(struct cifsFileInfo *cfile)
2301{ 2271{
2272 struct super_block *sb = cfile->dentry->d_sb;
2273
2302 cifsFileInfo_put(cfile); 2274 cifsFileInfo_put(cfile);
2303 cifs_sb_deactive(cfile->dentry->d_sb); 2275 cifs_sb_deactive(sb);
2304} 2276}
2305 2277
2306const struct address_space_operations cifs_addr_ops = { 2278const struct address_space_operations cifs_addr_ops = {
diff --git a/fs/cifs/fscache.c b/fs/cifs/fscache.c
index a2ad94efcfe6..297a43d0ff7f 100644
--- a/fs/cifs/fscache.c
+++ b/fs/cifs/fscache.c
@@ -2,7 +2,7 @@
2 * fs/cifs/fscache.c - CIFS filesystem cache interface 2 * fs/cifs/fscache.c - CIFS filesystem cache interface
3 * 3 *
4 * Copyright (c) 2010 Novell, Inc. 4 * Copyright (c) 2010 Novell, Inc.
5 * Author(s): Suresh Jayaraman (sjayaraman@suse.de> 5 * Author(s): Suresh Jayaraman <sjayaraman@suse.de>
6 * 6 *
7 * This library is free software; you can redistribute it and/or modify 7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published 8 * it under the terms of the GNU Lesser General Public License as published
@@ -67,10 +67,12 @@ static void cifs_fscache_enable_inode_cookie(struct inode *inode)
67 if (cifsi->fscache) 67 if (cifsi->fscache)
68 return; 68 return;
69 69
70 cifsi->fscache = fscache_acquire_cookie(tcon->fscache, 70 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) {
71 cifsi->fscache = fscache_acquire_cookie(tcon->fscache,
71 &cifs_fscache_inode_object_def, cifsi); 72 &cifs_fscache_inode_object_def, cifsi);
72 cFYI(1, "CIFS: got FH cookie (0x%p/0x%p)", tcon->fscache, 73 cFYI(1, "CIFS: got FH cookie (0x%p/0x%p)", tcon->fscache,
73 cifsi->fscache); 74 cifsi->fscache);
75 }
74} 76}
75 77
76void cifs_fscache_release_inode_cookie(struct inode *inode) 78void cifs_fscache_release_inode_cookie(struct inode *inode)
@@ -101,10 +103,8 @@ void cifs_fscache_set_inode_cookie(struct inode *inode, struct file *filp)
101{ 103{
102 if ((filp->f_flags & O_ACCMODE) != O_RDONLY) 104 if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
103 cifs_fscache_disable_inode_cookie(inode); 105 cifs_fscache_disable_inode_cookie(inode);
104 else { 106 else
105 cifs_fscache_enable_inode_cookie(inode); 107 cifs_fscache_enable_inode_cookie(inode);
106 cFYI(1, "CIFS: fscache inode cookie set");
107 }
108} 108}
109 109
110void cifs_fscache_reset_inode_cookie(struct inode *inode) 110void cifs_fscache_reset_inode_cookie(struct inode *inode)
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 39869c3c3efb..589f3e3f6e00 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -686,13 +686,18 @@ int cifs_get_inode_info(struct inode **pinode,
686 cFYI(1, "cifs_sfu_type failed: %d", tmprc); 686 cFYI(1, "cifs_sfu_type failed: %d", tmprc);
687 } 687 }
688 688
689#ifdef CONFIG_CIFS_EXPERIMENTAL 689#ifdef CONFIG_CIFS_ACL
690 /* fill in 0777 bits from ACL */ 690 /* fill in 0777 bits from ACL */
691 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) { 691 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
692 cFYI(1, "Getting mode bits from ACL"); 692 rc = cifs_acl_to_fattr(cifs_sb, &fattr, *pinode, full_path,
693 cifs_acl_to_fattr(cifs_sb, &fattr, *pinode, full_path, pfid); 693 pfid);
694 if (rc) {
695 cFYI(1, "%s: Getting ACL failed with error: %d",
696 __func__, rc);
697 goto cgii_exit;
698 }
694 } 699 }
695#endif 700#endif /* CONFIG_CIFS_ACL */
696 701
697 /* fill in remaining high mode bits e.g. SUID, VTX */ 702 /* fill in remaining high mode bits e.g. SUID, VTX */
698 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) 703 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
@@ -723,12 +728,12 @@ static const struct inode_operations cifs_ipc_inode_ops = {
723 .lookup = cifs_lookup, 728 .lookup = cifs_lookup,
724}; 729};
725 730
726char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb) 731char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb,
732 struct cifsTconInfo *tcon)
727{ 733{
728 int pplen = cifs_sb->prepathlen; 734 int pplen = cifs_sb->prepathlen;
729 int dfsplen; 735 int dfsplen;
730 char *full_path = NULL; 736 char *full_path = NULL;
731 struct cifsTconInfo *tcon = cifs_sb_master_tcon(cifs_sb);
732 737
733 /* if no prefix path, simply set path to the root of share to "" */ 738 /* if no prefix path, simply set path to the root of share to "" */
734 if (pplen == 0) { 739 if (pplen == 0) {
@@ -870,7 +875,7 @@ struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
870 char *full_path; 875 char *full_path;
871 struct cifsTconInfo *tcon = cifs_sb_master_tcon(cifs_sb); 876 struct cifsTconInfo *tcon = cifs_sb_master_tcon(cifs_sb);
872 877
873 full_path = cifs_build_path_to_root(cifs_sb); 878 full_path = cifs_build_path_to_root(cifs_sb, tcon);
874 if (full_path == NULL) 879 if (full_path == NULL)
875 return ERR_PTR(-ENOMEM); 880 return ERR_PTR(-ENOMEM);
876 881
@@ -881,8 +886,10 @@ struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
881 rc = cifs_get_inode_info(&inode, full_path, NULL, sb, 886 rc = cifs_get_inode_info(&inode, full_path, NULL, sb,
882 xid, NULL); 887 xid, NULL);
883 888
884 if (!inode) 889 if (!inode) {
885 return ERR_PTR(rc); 890 inode = ERR_PTR(rc);
891 goto out;
892 }
886 893
887#ifdef CONFIG_CIFS_FSCACHE 894#ifdef CONFIG_CIFS_FSCACHE
888 /* populate tcon->resource_id */ 895 /* populate tcon->resource_id */
@@ -898,13 +905,11 @@ struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
898 inode->i_uid = cifs_sb->mnt_uid; 905 inode->i_uid = cifs_sb->mnt_uid;
899 inode->i_gid = cifs_sb->mnt_gid; 906 inode->i_gid = cifs_sb->mnt_gid;
900 } else if (rc) { 907 } else if (rc) {
901 kfree(full_path);
902 _FreeXid(xid);
903 iget_failed(inode); 908 iget_failed(inode);
904 return ERR_PTR(rc); 909 inode = ERR_PTR(rc);
905 } 910 }
906 911
907 912out:
908 kfree(full_path); 913 kfree(full_path);
909 /* can not call macro FreeXid here since in a void func 914 /* can not call macro FreeXid here since in a void func
910 * TODO: This is no longer true 915 * TODO: This is no longer true
@@ -1648,6 +1653,7 @@ static bool
1648cifs_inode_needs_reval(struct inode *inode) 1653cifs_inode_needs_reval(struct inode *inode)
1649{ 1654{
1650 struct cifsInodeInfo *cifs_i = CIFS_I(inode); 1655 struct cifsInodeInfo *cifs_i = CIFS_I(inode);
1656 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1651 1657
1652 if (cifs_i->clientCanCacheRead) 1658 if (cifs_i->clientCanCacheRead)
1653 return false; 1659 return false;
@@ -1658,19 +1664,21 @@ cifs_inode_needs_reval(struct inode *inode)
1658 if (cifs_i->time == 0) 1664 if (cifs_i->time == 0)
1659 return true; 1665 return true;
1660 1666
1661 /* FIXME: the actimeo should be tunable */ 1667 if (!time_in_range(jiffies, cifs_i->time,
1662 if (time_after_eq(jiffies, cifs_i->time + HZ)) 1668 cifs_i->time + cifs_sb->actimeo))
1663 return true; 1669 return true;
1664 1670
1665 /* hardlinked files w/ noserverino get "special" treatment */ 1671 /* hardlinked files w/ noserverino get "special" treatment */
1666 if (!(CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) && 1672 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) &&
1667 S_ISREG(inode->i_mode) && inode->i_nlink != 1) 1673 S_ISREG(inode->i_mode) && inode->i_nlink != 1)
1668 return true; 1674 return true;
1669 1675
1670 return false; 1676 return false;
1671} 1677}
1672 1678
1673/* check invalid_mapping flag and zap the cache if it's set */ 1679/*
1680 * Zap the cache. Called when invalid_mapping flag is set.
1681 */
1674static void 1682static void
1675cifs_invalidate_mapping(struct inode *inode) 1683cifs_invalidate_mapping(struct inode *inode)
1676{ 1684{
@@ -2114,11 +2122,16 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2114 2122
2115 if (attrs->ia_valid & ATTR_MODE) { 2123 if (attrs->ia_valid & ATTR_MODE) {
2116 rc = 0; 2124 rc = 0;
2117#ifdef CONFIG_CIFS_EXPERIMENTAL 2125#ifdef CONFIG_CIFS_ACL
2118 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) 2126 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
2119 rc = mode_to_acl(inode, full_path, mode); 2127 rc = mode_to_cifs_acl(inode, full_path, mode);
2120 else 2128 if (rc) {
2121#endif 2129 cFYI(1, "%s: Setting ACL failed with error: %d",
2130 __func__, rc);
2131 goto cifs_setattr_exit;
2132 }
2133 } else
2134#endif /* CONFIG_CIFS_ACL */
2122 if (((mode & S_IWUGO) == 0) && 2135 if (((mode & S_IWUGO) == 0) &&
2123 (cifsInode->cifsAttrs & ATTR_READONLY) == 0) { 2136 (cifsInode->cifsAttrs & ATTR_READONLY) == 0) {
2124 2137
@@ -2177,7 +2190,6 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2177 2190
2178 setattr_copy(inode, attrs); 2191 setattr_copy(inode, attrs);
2179 mark_inode_dirty(inode); 2192 mark_inode_dirty(inode);
2180 return 0;
2181 2193
2182cifs_setattr_exit: 2194cifs_setattr_exit:
2183 kfree(full_path); 2195 kfree(full_path);
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c
index 077bf756f342..0c98672d0122 100644
--- a/fs/cifs/ioctl.c
+++ b/fs/cifs/ioctl.c
@@ -38,10 +38,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
38 struct cifs_sb_info *cifs_sb; 38 struct cifs_sb_info *cifs_sb;
39#ifdef CONFIG_CIFS_POSIX 39#ifdef CONFIG_CIFS_POSIX
40 struct cifsFileInfo *pSMBFile = filep->private_data; 40 struct cifsFileInfo *pSMBFile = filep->private_data;
41 struct cifsTconInfo *tcon = tlink_tcon(pSMBFile->tlink); 41 struct cifsTconInfo *tcon;
42 __u64 ExtAttrBits = 0; 42 __u64 ExtAttrBits = 0;
43 __u64 ExtAttrMask = 0; 43 __u64 ExtAttrMask = 0;
44 __u64 caps = le64_to_cpu(tcon->fsUnixInfo.Capability); 44 __u64 caps;
45#endif /* CONFIG_CIFS_POSIX */ 45#endif /* CONFIG_CIFS_POSIX */
46 46
47 xid = GetXid(); 47 xid = GetXid();
@@ -62,9 +62,11 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
62 break; 62 break;
63#ifdef CONFIG_CIFS_POSIX 63#ifdef CONFIG_CIFS_POSIX
64 case FS_IOC_GETFLAGS: 64 case FS_IOC_GETFLAGS:
65 if (pSMBFile == NULL)
66 break;
67 tcon = tlink_tcon(pSMBFile->tlink);
68 caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
65 if (CIFS_UNIX_EXTATTR_CAP & caps) { 69 if (CIFS_UNIX_EXTATTR_CAP & caps) {
66 if (pSMBFile == NULL)
67 break;
68 rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid, 70 rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid,
69 &ExtAttrBits, &ExtAttrMask); 71 &ExtAttrBits, &ExtAttrMask);
70 if (rc == 0) 72 if (rc == 0)
@@ -75,13 +77,15 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
75 break; 77 break;
76 78
77 case FS_IOC_SETFLAGS: 79 case FS_IOC_SETFLAGS:
80 if (pSMBFile == NULL)
81 break;
82 tcon = tlink_tcon(pSMBFile->tlink);
83 caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
78 if (CIFS_UNIX_EXTATTR_CAP & caps) { 84 if (CIFS_UNIX_EXTATTR_CAP & caps) {
79 if (get_user(ExtAttrBits, (int __user *)arg)) { 85 if (get_user(ExtAttrBits, (int __user *)arg)) {
80 rc = -EFAULT; 86 rc = -EFAULT;
81 break; 87 break;
82 } 88 }
83 if (pSMBFile == NULL)
84 break;
85 /* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid, 89 /* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid,
86 extAttrBits, &ExtAttrMask);*/ 90 extAttrBits, &ExtAttrMask);*/
87 } 91 }
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index c4e296fe3518..43f10281bc19 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -569,10 +569,9 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
569 569
570 cFYI(1, "file id match, oplock break"); 570 cFYI(1, "file id match, oplock break");
571 pCifsInode = CIFS_I(netfile->dentry->d_inode); 571 pCifsInode = CIFS_I(netfile->dentry->d_inode);
572 pCifsInode->clientCanCacheAll = false;
573 if (pSMB->OplockLevel == 0)
574 pCifsInode->clientCanCacheRead = false;
575 572
573 cifs_set_oplock_level(pCifsInode,
574 pSMB->OplockLevel);
576 /* 575 /*
577 * cifs_oplock_break_put() can't be called 576 * cifs_oplock_break_put() can't be called
578 * from here. Get reference after queueing 577 * from here. Get reference after queueing
@@ -722,3 +721,23 @@ cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb)
722 cifs_sb_master_tcon(cifs_sb)->treeName); 721 cifs_sb_master_tcon(cifs_sb)->treeName);
723 } 722 }
724} 723}
724
725void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock)
726{
727 oplock &= 0xF;
728
729 if (oplock == OPLOCK_EXCLUSIVE) {
730 cinode->clientCanCacheAll = true;
731 cinode->clientCanCacheRead = true;
732 cFYI(1, "Exclusive Oplock granted on inode %p",
733 &cinode->vfs_inode);
734 } else if (oplock == OPLOCK_READ) {
735 cinode->clientCanCacheAll = false;
736 cinode->clientCanCacheRead = true;
737 cFYI(1, "Level II Oplock granted on inode %p",
738 &cinode->vfs_inode);
739 } else {
740 cinode->clientCanCacheAll = false;
741 cinode->clientCanCacheRead = false;
742 }
743}
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index ef7bb7b50f58..a73eb9f4bdaf 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -226,26 +226,29 @@ static int initiate_cifs_search(const int xid, struct file *file)
226 char *full_path = NULL; 226 char *full_path = NULL;
227 struct cifsFileInfo *cifsFile; 227 struct cifsFileInfo *cifsFile;
228 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 228 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
229 struct tcon_link *tlink; 229 struct tcon_link *tlink = NULL;
230 struct cifsTconInfo *pTcon; 230 struct cifsTconInfo *pTcon;
231 231
232 tlink = cifs_sb_tlink(cifs_sb);
233 if (IS_ERR(tlink))
234 return PTR_ERR(tlink);
235 pTcon = tlink_tcon(tlink);
236
237 if (file->private_data == NULL)
238 file->private_data =
239 kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
240 if (file->private_data == NULL) { 232 if (file->private_data == NULL) {
241 rc = -ENOMEM; 233 tlink = cifs_sb_tlink(cifs_sb);
242 goto error_exit; 234 if (IS_ERR(tlink))
235 return PTR_ERR(tlink);
236
237 cifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
238 if (cifsFile == NULL) {
239 rc = -ENOMEM;
240 goto error_exit;
241 }
242 file->private_data = cifsFile;
243 cifsFile->tlink = cifs_get_tlink(tlink);
244 pTcon = tlink_tcon(tlink);
245 } else {
246 cifsFile = file->private_data;
247 pTcon = tlink_tcon(cifsFile->tlink);
243 } 248 }
244 249
245 cifsFile = file->private_data;
246 cifsFile->invalidHandle = true; 250 cifsFile->invalidHandle = true;
247 cifsFile->srch_inf.endOfSearch = false; 251 cifsFile->srch_inf.endOfSearch = false;
248 cifsFile->tlink = cifs_get_tlink(tlink);
249 252
250 full_path = build_path_from_dentry(file->f_path.dentry); 253 full_path = build_path_from_dentry(file->f_path.dentry);
251 if (full_path == NULL) { 254 if (full_path == NULL) {
@@ -756,18 +759,6 @@ static int cifs_filldir(char *pfindEntry, struct file *file, filldir_t filldir,
756 rc = filldir(direntry, qstring.name, qstring.len, file->f_pos, 759 rc = filldir(direntry, qstring.name, qstring.len, file->f_pos,
757 ino, fattr.cf_dtype); 760 ino, fattr.cf_dtype);
758 761
759 /*
760 * we can not return filldir errors to the caller since they are
761 * "normal" when the stat blocksize is too small - we return remapped
762 * error instead
763 *
764 * FIXME: This looks bogus. filldir returns -EOVERFLOW in the above
765 * case already. Why should we be clobbering other errors from it?
766 */
767 if (rc) {
768 cFYI(1, "filldir rc = %d", rc);
769 rc = -EOVERFLOW;
770 }
771 dput(tmp_dentry); 762 dput(tmp_dentry);
772 return rc; 763 return rc;
773} 764}
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c
index a264b744bb41..eae2a1491608 100644
--- a/fs/cifs/xattr.c
+++ b/fs/cifs/xattr.c
@@ -30,10 +30,11 @@
30 30
31#define MAX_EA_VALUE_SIZE 65535 31#define MAX_EA_VALUE_SIZE 65535
32#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib" 32#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
33#define CIFS_XATTR_CIFS_ACL "system.cifs_acl"
33#define CIFS_XATTR_USER_PREFIX "user." 34#define CIFS_XATTR_USER_PREFIX "user."
34#define CIFS_XATTR_SYSTEM_PREFIX "system." 35#define CIFS_XATTR_SYSTEM_PREFIX "system."
35#define CIFS_XATTR_OS2_PREFIX "os2." 36#define CIFS_XATTR_OS2_PREFIX "os2."
36#define CIFS_XATTR_SECURITY_PREFIX ".security" 37#define CIFS_XATTR_SECURITY_PREFIX "security."
37#define CIFS_XATTR_TRUSTED_PREFIX "trusted." 38#define CIFS_XATTR_TRUSTED_PREFIX "trusted."
38#define XATTR_TRUSTED_PREFIX_LEN 8 39#define XATTR_TRUSTED_PREFIX_LEN 8
39#define XATTR_SECURITY_PREFIX_LEN 9 40#define XATTR_SECURITY_PREFIX_LEN 9
@@ -277,29 +278,8 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
277 cifs_sb->local_nls, 278 cifs_sb->local_nls,
278 cifs_sb->mnt_cifs_flags & 279 cifs_sb->mnt_cifs_flags &
279 CIFS_MOUNT_MAP_SPECIAL_CHR); 280 CIFS_MOUNT_MAP_SPECIAL_CHR);
280#ifdef CONFIG_CIFS_EXPERIMENTAL
281 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
282 __u16 fid;
283 int oplock = 0;
284 struct cifs_ntsd *pacl = NULL;
285 __u32 buflen = 0;
286 if (experimEnabled)
287 rc = CIFSSMBOpen(xid, pTcon, full_path,
288 FILE_OPEN, GENERIC_READ, 0, &fid,
289 &oplock, NULL, cifs_sb->local_nls,
290 cifs_sb->mnt_cifs_flags &
291 CIFS_MOUNT_MAP_SPECIAL_CHR);
292 /* else rc is EOPNOTSUPP from above */
293
294 if (rc == 0) {
295 rc = CIFSSMBGetCIFSACL(xid, pTcon, fid, &pacl,
296 &buflen);
297 CIFSSMBClose(xid, pTcon, fid);
298 }
299 }
300#endif /* EXPERIMENTAL */
301#else 281#else
302 cFYI(1, "query POSIX ACL not supported yet"); 282 cFYI(1, "Query POSIX ACL not supported yet");
303#endif /* CONFIG_CIFS_POSIX */ 283#endif /* CONFIG_CIFS_POSIX */
304 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT, 284 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
305 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { 285 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
@@ -311,8 +291,33 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
311 cifs_sb->mnt_cifs_flags & 291 cifs_sb->mnt_cifs_flags &
312 CIFS_MOUNT_MAP_SPECIAL_CHR); 292 CIFS_MOUNT_MAP_SPECIAL_CHR);
313#else 293#else
314 cFYI(1, "query POSIX default ACL not supported yet"); 294 cFYI(1, "Query POSIX default ACL not supported yet");
315#endif 295#endif /* CONFIG_CIFS_POSIX */
296 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
297 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
298#ifdef CONFIG_CIFS_ACL
299 u32 acllen;
300 struct cifs_ntsd *pacl;
301
302 pacl = get_cifs_acl(cifs_sb, direntry->d_inode,
303 full_path, &acllen);
304 if (IS_ERR(pacl)) {
305 rc = PTR_ERR(pacl);
306 cERROR(1, "%s: error %zd getting sec desc",
307 __func__, rc);
308 } else {
309 if (ea_value) {
310 if (acllen > buf_size)
311 acllen = -ERANGE;
312 else
313 memcpy(ea_value, pacl, acllen);
314 }
315 rc = acllen;
316 kfree(pacl);
317 }
318#else
319 cFYI(1, "Query CIFS ACL not supported yet");
320#endif /* CONFIG_CIFS_ACL */
316 } else if (strncmp(ea_name, 321 } else if (strncmp(ea_name,
317 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) { 322 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
318 cFYI(1, "Trusted xattr namespace not supported yet"); 323 cFYI(1, "Trusted xattr namespace not supported yet");
diff --git a/fs/compat.c b/fs/compat.c
index c580c322fa6b..eb1740ac8c0a 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1350,6 +1350,10 @@ static int compat_count(compat_uptr_t __user *argv, int max)
1350 argv++; 1350 argv++;
1351 if (i++ >= max) 1351 if (i++ >= max)
1352 return -E2BIG; 1352 return -E2BIG;
1353
1354 if (fatal_signal_pending(current))
1355 return -ERESTARTNOHAND;
1356 cond_resched();
1353 } 1357 }
1354 } 1358 }
1355 return i; 1359 return i;
@@ -1391,6 +1395,12 @@ static int compat_copy_strings(int argc, compat_uptr_t __user *argv,
1391 while (len > 0) { 1395 while (len > 0) {
1392 int offset, bytes_to_copy; 1396 int offset, bytes_to_copy;
1393 1397
1398 if (fatal_signal_pending(current)) {
1399 ret = -ERESTARTNOHAND;
1400 goto out;
1401 }
1402 cond_resched();
1403
1394 offset = pos % PAGE_SIZE; 1404 offset = pos % PAGE_SIZE;
1395 if (offset == 0) 1405 if (offset == 0)
1396 offset = PAGE_SIZE; 1406 offset = PAGE_SIZE;
@@ -1407,18 +1417,8 @@ static int compat_copy_strings(int argc, compat_uptr_t __user *argv,
1407 if (!kmapped_page || kpos != (pos & PAGE_MASK)) { 1417 if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
1408 struct page *page; 1418 struct page *page;
1409 1419
1410#ifdef CONFIG_STACK_GROWSUP 1420 page = get_arg_page(bprm, pos, 1);
1411 ret = expand_stack_downwards(bprm->vma, pos); 1421 if (!page) {
1412 if (ret < 0) {
1413 /* We've exceed the stack rlimit. */
1414 ret = -E2BIG;
1415 goto out;
1416 }
1417#endif
1418 ret = get_user_pages(current, bprm->mm, pos,
1419 1, 1, 1, &page, NULL);
1420 if (ret <= 0) {
1421 /* We've exceed the stack rlimit. */
1422 ret = -E2BIG; 1422 ret = -E2BIG;
1423 goto out; 1423 goto out;
1424 } 1424 }
@@ -1539,8 +1539,10 @@ int compat_do_execve(char * filename,
1539 return retval; 1539 return retval;
1540 1540
1541out: 1541out:
1542 if (bprm->mm) 1542 if (bprm->mm) {
1543 acct_arg_size(bprm, 0);
1543 mmput(bprm->mm); 1544 mmput(bprm->mm);
1545 }
1544 1546
1545out_file: 1547out_file:
1546 if (bprm->file) { 1548 if (bprm->file) {
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 410ed188faa1..a60579b007b0 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -19,7 +19,6 @@
19#include <linux/compiler.h> 19#include <linux/compiler.h>
20#include <linux/sched.h> 20#include <linux/sched.h>
21#include <linux/smp.h> 21#include <linux/smp.h>
22#include <linux/smp_lock.h>
23#include <linux/ioctl.h> 22#include <linux/ioctl.h>
24#include <linux/if.h> 23#include <linux/if.h>
25#include <linux/if_bridge.h> 24#include <linux/if_bridge.h>
diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c
index 253732382d37..2720178b7718 100644
--- a/fs/ecryptfs/super.c
+++ b/fs/ecryptfs/super.c
@@ -28,7 +28,6 @@
28#include <linux/key.h> 28#include <linux/key.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <linux/smp_lock.h>
32#include <linux/file.h> 31#include <linux/file.h>
33#include <linux/crypto.h> 32#include <linux/crypto.h>
34#include "ecryptfs_kernel.h" 33#include "ecryptfs_kernel.h"
diff --git a/fs/exec.c b/fs/exec.c
index 99d33a1371e9..c62efcb959c7 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -164,7 +164,26 @@ out:
164 164
165#ifdef CONFIG_MMU 165#ifdef CONFIG_MMU
166 166
167static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos, 167void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
168{
169 struct mm_struct *mm = current->mm;
170 long diff = (long)(pages - bprm->vma_pages);
171
172 if (!mm || !diff)
173 return;
174
175 bprm->vma_pages = pages;
176
177#ifdef SPLIT_RSS_COUNTING
178 add_mm_counter(mm, MM_ANONPAGES, diff);
179#else
180 spin_lock(&mm->page_table_lock);
181 add_mm_counter(mm, MM_ANONPAGES, diff);
182 spin_unlock(&mm->page_table_lock);
183#endif
184}
185
186struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
168 int write) 187 int write)
169{ 188{
170 struct page *page; 189 struct page *page;
@@ -186,6 +205,8 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
186 unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start; 205 unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start;
187 struct rlimit *rlim; 206 struct rlimit *rlim;
188 207
208 acct_arg_size(bprm, size / PAGE_SIZE);
209
189 /* 210 /*
190 * We've historically supported up to 32 pages (ARG_MAX) 211 * We've historically supported up to 32 pages (ARG_MAX)
191 * of argument strings even with small stacks 212 * of argument strings even with small stacks
@@ -254,6 +275,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
254 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP; 275 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
255 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); 276 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
256 INIT_LIST_HEAD(&vma->anon_vma_chain); 277 INIT_LIST_HEAD(&vma->anon_vma_chain);
278
279 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
280 if (err)
281 goto err;
282
257 err = insert_vm_struct(mm, vma); 283 err = insert_vm_struct(mm, vma);
258 if (err) 284 if (err)
259 goto err; 285 goto err;
@@ -276,7 +302,11 @@ static bool valid_arg_len(struct linux_binprm *bprm, long len)
276 302
277#else 303#else
278 304
279static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos, 305void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
306{
307}
308
309struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
280 int write) 310 int write)
281{ 311{
282 struct page *page; 312 struct page *page;
@@ -1003,6 +1033,7 @@ int flush_old_exec(struct linux_binprm * bprm)
1003 /* 1033 /*
1004 * Release all of the old mmap stuff 1034 * Release all of the old mmap stuff
1005 */ 1035 */
1036 acct_arg_size(bprm, 0);
1006 retval = exec_mmap(bprm->mm); 1037 retval = exec_mmap(bprm->mm);
1007 if (retval) 1038 if (retval)
1008 goto out; 1039 goto out;
@@ -1426,8 +1457,10 @@ int do_execve(const char * filename,
1426 return retval; 1457 return retval;
1427 1458
1428out: 1459out:
1429 if (bprm->mm) 1460 if (bprm->mm) {
1430 mmput (bprm->mm); 1461 acct_arg_size(bprm, 0);
1462 mmput(bprm->mm);
1463 }
1431 1464
1432out_file: 1465out_file:
1433 if (bprm->file) { 1466 if (bprm->file) {
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 2fedaf8b5012..acf8695fa8f0 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -27,7 +27,6 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/blkdev.h> 28#include <linux/blkdev.h>
29#include <linux/parser.h> 29#include <linux/parser.h>
30#include <linux/smp_lock.h>
31#include <linux/buffer_head.h> 30#include <linux/buffer_head.h>
32#include <linux/exportfs.h> 31#include <linux/exportfs.h>
33#include <linux/vfs.h> 32#include <linux/vfs.h>
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 47162de0b957..1f253a9a141d 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -177,7 +177,7 @@ struct mpage_da_data {
177 177
178struct ext4_io_page { 178struct ext4_io_page {
179 struct page *p_page; 179 struct page *p_page;
180 int p_count; 180 atomic_t p_count;
181}; 181};
182 182
183#define MAX_IO_PAGES 128 183#define MAX_IO_PAGES 128
@@ -858,6 +858,7 @@ struct ext4_inode_info {
858 spinlock_t i_completed_io_lock; 858 spinlock_t i_completed_io_lock;
859 /* current io_end structure for async DIO write*/ 859 /* current io_end structure for async DIO write*/
860 ext4_io_end_t *cur_aio_dio; 860 ext4_io_end_t *cur_aio_dio;
861 atomic_t i_ioend_count; /* Number of outstanding io_end structs */
861 862
862 /* 863 /*
863 * Transactions that contain inode's metadata needed to complete 864 * Transactions that contain inode's metadata needed to complete
@@ -909,6 +910,7 @@ struct ext4_inode_info {
909#define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ 910#define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
910#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ 911#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
911#define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */ 912#define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */
913#define EXT4_MOUNT_MBLK_IO_SUBMIT 0x4000000 /* multi-block io submits */
912#define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ 914#define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
913#define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */ 915#define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
914#define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */ 916#define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */
@@ -2060,6 +2062,7 @@ extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
2060/* page-io.c */ 2062/* page-io.c */
2061extern int __init ext4_init_pageio(void); 2063extern int __init ext4_init_pageio(void);
2062extern void ext4_exit_pageio(void); 2064extern void ext4_exit_pageio(void);
2065extern void ext4_ioend_wait(struct inode *);
2063extern void ext4_free_io_end(ext4_io_end_t *io); 2066extern void ext4_free_io_end(ext4_io_end_t *io);
2064extern ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags); 2067extern ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags);
2065extern int ext4_end_io_nolock(ext4_io_end_t *io); 2068extern int ext4_end_io_nolock(ext4_io_end_t *io);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index b6a4b41d7e14..ef9d5be0b2a8 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -53,6 +53,7 @@
53static inline int ext4_begin_ordered_truncate(struct inode *inode, 53static inline int ext4_begin_ordered_truncate(struct inode *inode,
54 loff_t new_size) 54 loff_t new_size)
55{ 55{
56 trace_ext4_begin_ordered_truncate(inode, new_size);
56 return jbd2_journal_begin_ordered_truncate( 57 return jbd2_journal_begin_ordered_truncate(
57 EXT4_SB(inode->i_sb)->s_journal, 58 EXT4_SB(inode->i_sb)->s_journal,
58 &EXT4_I(inode)->jinode, 59 &EXT4_I(inode)->jinode,
@@ -178,6 +179,7 @@ void ext4_evict_inode(struct inode *inode)
178 handle_t *handle; 179 handle_t *handle;
179 int err; 180 int err;
180 181
182 trace_ext4_evict_inode(inode);
181 if (inode->i_nlink) { 183 if (inode->i_nlink) {
182 truncate_inode_pages(&inode->i_data, 0); 184 truncate_inode_pages(&inode->i_data, 0);
183 goto no_delete; 185 goto no_delete;
@@ -2123,9 +2125,12 @@ static int mpage_da_submit_io(struct mpage_da_data *mpd,
2123 */ 2125 */
2124 if (unlikely(journal_data && PageChecked(page))) 2126 if (unlikely(journal_data && PageChecked(page)))
2125 err = __ext4_journalled_writepage(page, len); 2127 err = __ext4_journalled_writepage(page, len);
2126 else 2128 else if (test_opt(inode->i_sb, MBLK_IO_SUBMIT))
2127 err = ext4_bio_write_page(&io_submit, page, 2129 err = ext4_bio_write_page(&io_submit, page,
2128 len, mpd->wbc); 2130 len, mpd->wbc);
2131 else
2132 err = block_write_full_page(page,
2133 noalloc_get_block_write, mpd->wbc);
2129 2134
2130 if (!err) 2135 if (!err)
2131 mpd->pages_written++; 2136 mpd->pages_written++;
@@ -5410,9 +5415,7 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
5410 * will return the blocks that include the delayed allocation 5415 * will return the blocks that include the delayed allocation
5411 * blocks for this file. 5416 * blocks for this file.
5412 */ 5417 */
5413 spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
5414 delalloc_blocks = EXT4_I(inode)->i_reserved_data_blocks; 5418 delalloc_blocks = EXT4_I(inode)->i_reserved_data_blocks;
5415 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
5416 5419
5417 stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9; 5420 stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9;
5418 return 0; 5421 return 0;
@@ -5649,6 +5652,7 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
5649 int err, ret; 5652 int err, ret;
5650 5653
5651 might_sleep(); 5654 might_sleep();
5655 trace_ext4_mark_inode_dirty(inode, _RET_IP_);
5652 err = ext4_reserve_inode_write(handle, inode, &iloc); 5656 err = ext4_reserve_inode_write(handle, inode, &iloc);
5653 if (ext4_handle_valid(handle) && 5657 if (ext4_handle_valid(handle) &&
5654 EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize && 5658 EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize &&
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index bf5ae883b1bd..eb3bc2fe647e 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -331,6 +331,30 @@ mext_out:
331 return err; 331 return err;
332 } 332 }
333 333
334 case FITRIM:
335 {
336 struct super_block *sb = inode->i_sb;
337 struct fstrim_range range;
338 int ret = 0;
339
340 if (!capable(CAP_SYS_ADMIN))
341 return -EPERM;
342
343 if (copy_from_user(&range, (struct fstrim_range *)arg,
344 sizeof(range)))
345 return -EFAULT;
346
347 ret = ext4_trim_fs(sb, &range);
348 if (ret < 0)
349 return ret;
350
351 if (copy_to_user((struct fstrim_range *)arg, &range,
352 sizeof(range)))
353 return -EFAULT;
354
355 return 0;
356 }
357
334 default: 358 default:
335 return -ENOTTY; 359 return -ENOTTY;
336 } 360 }
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index c58eba34724a..5b4d4e3a4d58 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4640,8 +4640,6 @@ do_more:
4640 * with group lock held. generate_buddy look at 4640 * with group lock held. generate_buddy look at
4641 * them with group lock_held 4641 * them with group lock_held
4642 */ 4642 */
4643 if (test_opt(sb, DISCARD))
4644 ext4_issue_discard(sb, block_group, bit, count);
4645 ext4_lock_group(sb, block_group); 4643 ext4_lock_group(sb, block_group);
4646 mb_clear_bits(bitmap_bh->b_data, bit, count); 4644 mb_clear_bits(bitmap_bh->b_data, bit, count);
4647 mb_free_blocks(inode, &e4b, bit, count); 4645 mb_free_blocks(inode, &e4b, bit, count);
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 92203b8a099f..dc40e75cba88 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -872,7 +872,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
872 if (namelen > EXT4_NAME_LEN) 872 if (namelen > EXT4_NAME_LEN)
873 return NULL; 873 return NULL;
874 if ((namelen <= 2) && (name[0] == '.') && 874 if ((namelen <= 2) && (name[0] == '.') &&
875 (name[1] == '.' || name[1] == '0')) { 875 (name[1] == '.' || name[1] == '\0')) {
876 /* 876 /*
877 * "." or ".." will only be in the first block 877 * "." or ".." will only be in the first block
878 * NFS may look up ".."; "." should be handled by the VFS 878 * NFS may look up ".."; "." should be handled by the VFS
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 46a7d6a9d976..beacce11ac50 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -32,8 +32,14 @@
32 32
33static struct kmem_cache *io_page_cachep, *io_end_cachep; 33static struct kmem_cache *io_page_cachep, *io_end_cachep;
34 34
35#define WQ_HASH_SZ 37
36#define to_ioend_wq(v) (&ioend_wq[((unsigned long)v) % WQ_HASH_SZ])
37static wait_queue_head_t ioend_wq[WQ_HASH_SZ];
38
35int __init ext4_init_pageio(void) 39int __init ext4_init_pageio(void)
36{ 40{
41 int i;
42
37 io_page_cachep = KMEM_CACHE(ext4_io_page, SLAB_RECLAIM_ACCOUNT); 43 io_page_cachep = KMEM_CACHE(ext4_io_page, SLAB_RECLAIM_ACCOUNT);
38 if (io_page_cachep == NULL) 44 if (io_page_cachep == NULL)
39 return -ENOMEM; 45 return -ENOMEM;
@@ -42,6 +48,8 @@ int __init ext4_init_pageio(void)
42 kmem_cache_destroy(io_page_cachep); 48 kmem_cache_destroy(io_page_cachep);
43 return -ENOMEM; 49 return -ENOMEM;
44 } 50 }
51 for (i = 0; i < WQ_HASH_SZ; i++)
52 init_waitqueue_head(&ioend_wq[i]);
45 53
46 return 0; 54 return 0;
47} 55}
@@ -52,24 +60,37 @@ void ext4_exit_pageio(void)
52 kmem_cache_destroy(io_page_cachep); 60 kmem_cache_destroy(io_page_cachep);
53} 61}
54 62
63void ext4_ioend_wait(struct inode *inode)
64{
65 wait_queue_head_t *wq = to_ioend_wq(inode);
66
67 wait_event(*wq, (atomic_read(&EXT4_I(inode)->i_ioend_count) == 0));
68}
69
70static void put_io_page(struct ext4_io_page *io_page)
71{
72 if (atomic_dec_and_test(&io_page->p_count)) {
73 end_page_writeback(io_page->p_page);
74 put_page(io_page->p_page);
75 kmem_cache_free(io_page_cachep, io_page);
76 }
77}
78
55void ext4_free_io_end(ext4_io_end_t *io) 79void ext4_free_io_end(ext4_io_end_t *io)
56{ 80{
57 int i; 81 int i;
82 wait_queue_head_t *wq;
58 83
59 BUG_ON(!io); 84 BUG_ON(!io);
60 if (io->page) 85 if (io->page)
61 put_page(io->page); 86 put_page(io->page);
62 for (i = 0; i < io->num_io_pages; i++) { 87 for (i = 0; i < io->num_io_pages; i++)
63 if (--io->pages[i]->p_count == 0) { 88 put_io_page(io->pages[i]);
64 struct page *page = io->pages[i]->p_page;
65
66 end_page_writeback(page);
67 put_page(page);
68 kmem_cache_free(io_page_cachep, io->pages[i]);
69 }
70 }
71 io->num_io_pages = 0; 89 io->num_io_pages = 0;
72 iput(io->inode); 90 wq = to_ioend_wq(io->inode);
91 if (atomic_dec_and_test(&EXT4_I(io->inode)->i_ioend_count) &&
92 waitqueue_active(wq))
93 wake_up_all(wq);
73 kmem_cache_free(io_end_cachep, io); 94 kmem_cache_free(io_end_cachep, io);
74} 95}
75 96
@@ -142,8 +163,8 @@ ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags)
142 io = kmem_cache_alloc(io_end_cachep, flags); 163 io = kmem_cache_alloc(io_end_cachep, flags);
143 if (io) { 164 if (io) {
144 memset(io, 0, sizeof(*io)); 165 memset(io, 0, sizeof(*io));
145 io->inode = igrab(inode); 166 atomic_inc(&EXT4_I(inode)->i_ioend_count);
146 BUG_ON(!io->inode); 167 io->inode = inode;
147 INIT_WORK(&io->work, ext4_end_io_work); 168 INIT_WORK(&io->work, ext4_end_io_work);
148 INIT_LIST_HEAD(&io->list); 169 INIT_LIST_HEAD(&io->list);
149 } 170 }
@@ -171,35 +192,15 @@ static void ext4_end_bio(struct bio *bio, int error)
171 struct workqueue_struct *wq; 192 struct workqueue_struct *wq;
172 struct inode *inode; 193 struct inode *inode;
173 unsigned long flags; 194 unsigned long flags;
174 ext4_fsblk_t err_block;
175 int i; 195 int i;
176 196
177 BUG_ON(!io_end); 197 BUG_ON(!io_end);
178 inode = io_end->inode;
179 bio->bi_private = NULL; 198 bio->bi_private = NULL;
180 bio->bi_end_io = NULL; 199 bio->bi_end_io = NULL;
181 if (test_bit(BIO_UPTODATE, &bio->bi_flags)) 200 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
182 error = 0; 201 error = 0;
183 err_block = bio->bi_sector >> (inode->i_blkbits - 9);
184 bio_put(bio); 202 bio_put(bio);
185 203
186 if (!(inode->i_sb->s_flags & MS_ACTIVE)) {
187 pr_err("sb umounted, discard end_io request for inode %lu\n",
188 io_end->inode->i_ino);
189 ext4_free_io_end(io_end);
190 return;
191 }
192
193 if (error) {
194 io_end->flag |= EXT4_IO_END_ERROR;
195 ext4_warning(inode->i_sb, "I/O error writing to inode %lu "
196 "(offset %llu size %ld starting block %llu)",
197 inode->i_ino,
198 (unsigned long long) io_end->offset,
199 (long) io_end->size,
200 (unsigned long long) err_block);
201 }
202
203 for (i = 0; i < io_end->num_io_pages; i++) { 204 for (i = 0; i < io_end->num_io_pages; i++) {
204 struct page *page = io_end->pages[i]->p_page; 205 struct page *page = io_end->pages[i]->p_page;
205 struct buffer_head *bh, *head; 206 struct buffer_head *bh, *head;
@@ -236,14 +237,6 @@ static void ext4_end_bio(struct bio *bio, int error)
236 } while (bh != head); 237 } while (bh != head);
237 } 238 }
238 239
239 if (--io_end->pages[i]->p_count == 0) {
240 struct page *page = io_end->pages[i]->p_page;
241
242 end_page_writeback(page);
243 put_page(page);
244 kmem_cache_free(io_page_cachep, io_end->pages[i]);
245 }
246
247 /* 240 /*
248 * If this is a partial write which happened to make 241 * If this is a partial write which happened to make
249 * all buffers uptodate then we can optimize away a 242 * all buffers uptodate then we can optimize away a
@@ -253,9 +246,22 @@ static void ext4_end_bio(struct bio *bio, int error)
253 */ 246 */
254 if (!partial_write) 247 if (!partial_write)
255 SetPageUptodate(page); 248 SetPageUptodate(page);
256 }
257 249
250 put_io_page(io_end->pages[i]);
251 }
258 io_end->num_io_pages = 0; 252 io_end->num_io_pages = 0;
253 inode = io_end->inode;
254
255 if (error) {
256 io_end->flag |= EXT4_IO_END_ERROR;
257 ext4_warning(inode->i_sb, "I/O error writing to inode %lu "
258 "(offset %llu size %ld starting block %llu)",
259 inode->i_ino,
260 (unsigned long long) io_end->offset,
261 (long) io_end->size,
262 (unsigned long long)
263 bio->bi_sector >> (inode->i_blkbits - 9));
264 }
259 265
260 /* Add the io_end to per-inode completed io list*/ 266 /* Add the io_end to per-inode completed io list*/
261 spin_lock_irqsave(&EXT4_I(inode)->i_completed_io_lock, flags); 267 spin_lock_irqsave(&EXT4_I(inode)->i_completed_io_lock, flags);
@@ -305,7 +311,6 @@ static int io_submit_init(struct ext4_io_submit *io,
305 bio->bi_private = io->io_end = io_end; 311 bio->bi_private = io->io_end = io_end;
306 bio->bi_end_io = ext4_end_bio; 312 bio->bi_end_io = ext4_end_bio;
307 313
308 io_end->inode = inode;
309 io_end->offset = (page->index << PAGE_CACHE_SHIFT) + bh_offset(bh); 314 io_end->offset = (page->index << PAGE_CACHE_SHIFT) + bh_offset(bh);
310 315
311 io->io_bio = bio; 316 io->io_bio = bio;
@@ -360,7 +365,7 @@ submit_and_retry:
360 if ((io_end->num_io_pages == 0) || 365 if ((io_end->num_io_pages == 0) ||
361 (io_end->pages[io_end->num_io_pages-1] != io_page)) { 366 (io_end->pages[io_end->num_io_pages-1] != io_page)) {
362 io_end->pages[io_end->num_io_pages++] = io_page; 367 io_end->pages[io_end->num_io_pages++] = io_page;
363 io_page->p_count++; 368 atomic_inc(&io_page->p_count);
364 } 369 }
365 return 0; 370 return 0;
366} 371}
@@ -389,7 +394,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
389 return -ENOMEM; 394 return -ENOMEM;
390 } 395 }
391 io_page->p_page = page; 396 io_page->p_page = page;
392 io_page->p_count = 0; 397 atomic_set(&io_page->p_count, 1);
393 get_page(page); 398 get_page(page);
394 399
395 for (bh = head = page_buffers(page), block_start = 0; 400 for (bh = head = page_buffers(page), block_start = 0;
@@ -421,10 +426,6 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
421 * PageWriteback bit from the page to prevent the system from 426 * PageWriteback bit from the page to prevent the system from
422 * wedging later on. 427 * wedging later on.
423 */ 428 */
424 if (io_page->p_count == 0) { 429 put_io_page(io_page);
425 put_page(page);
426 end_page_writeback(page);
427 kmem_cache_free(io_page_cachep, io_page);
428 }
429 return ret; 430 return ret;
430} 431}
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 40131b777af6..fb15c9c0be74 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -828,12 +828,22 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
828 ei->cur_aio_dio = NULL; 828 ei->cur_aio_dio = NULL;
829 ei->i_sync_tid = 0; 829 ei->i_sync_tid = 0;
830 ei->i_datasync_tid = 0; 830 ei->i_datasync_tid = 0;
831 atomic_set(&ei->i_ioend_count, 0);
831 832
832 return &ei->vfs_inode; 833 return &ei->vfs_inode;
833} 834}
834 835
836static int ext4_drop_inode(struct inode *inode)
837{
838 int drop = generic_drop_inode(inode);
839
840 trace_ext4_drop_inode(inode, drop);
841 return drop;
842}
843
835static void ext4_destroy_inode(struct inode *inode) 844static void ext4_destroy_inode(struct inode *inode)
836{ 845{
846 ext4_ioend_wait(inode);
837 if (!list_empty(&(EXT4_I(inode)->i_orphan))) { 847 if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
838 ext4_msg(inode->i_sb, KERN_ERR, 848 ext4_msg(inode->i_sb, KERN_ERR,
839 "Inode %lu (%p): orphan list check failed!", 849 "Inode %lu (%p): orphan list check failed!",
@@ -1016,6 +1026,8 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
1016 !(def_mount_opts & EXT4_DEFM_NODELALLOC)) 1026 !(def_mount_opts & EXT4_DEFM_NODELALLOC))
1017 seq_puts(seq, ",nodelalloc"); 1027 seq_puts(seq, ",nodelalloc");
1018 1028
1029 if (test_opt(sb, MBLK_IO_SUBMIT))
1030 seq_puts(seq, ",mblk_io_submit");
1019 if (sbi->s_stripe) 1031 if (sbi->s_stripe)
1020 seq_printf(seq, ",stripe=%lu", sbi->s_stripe); 1032 seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
1021 /* 1033 /*
@@ -1173,6 +1185,7 @@ static const struct super_operations ext4_sops = {
1173 .destroy_inode = ext4_destroy_inode, 1185 .destroy_inode = ext4_destroy_inode,
1174 .write_inode = ext4_write_inode, 1186 .write_inode = ext4_write_inode,
1175 .dirty_inode = ext4_dirty_inode, 1187 .dirty_inode = ext4_dirty_inode,
1188 .drop_inode = ext4_drop_inode,
1176 .evict_inode = ext4_evict_inode, 1189 .evict_inode = ext4_evict_inode,
1177 .put_super = ext4_put_super, 1190 .put_super = ext4_put_super,
1178 .sync_fs = ext4_sync_fs, 1191 .sync_fs = ext4_sync_fs,
@@ -1186,7 +1199,6 @@ static const struct super_operations ext4_sops = {
1186 .quota_write = ext4_quota_write, 1199 .quota_write = ext4_quota_write,
1187#endif 1200#endif
1188 .bdev_try_to_free_page = bdev_try_to_free_page, 1201 .bdev_try_to_free_page = bdev_try_to_free_page,
1189 .trim_fs = ext4_trim_fs
1190}; 1202};
1191 1203
1192static const struct super_operations ext4_nojournal_sops = { 1204static const struct super_operations ext4_nojournal_sops = {
@@ -1194,6 +1206,7 @@ static const struct super_operations ext4_nojournal_sops = {
1194 .destroy_inode = ext4_destroy_inode, 1206 .destroy_inode = ext4_destroy_inode,
1195 .write_inode = ext4_write_inode, 1207 .write_inode = ext4_write_inode,
1196 .dirty_inode = ext4_dirty_inode, 1208 .dirty_inode = ext4_dirty_inode,
1209 .drop_inode = ext4_drop_inode,
1197 .evict_inode = ext4_evict_inode, 1210 .evict_inode = ext4_evict_inode,
1198 .write_super = ext4_write_super, 1211 .write_super = ext4_write_super,
1199 .put_super = ext4_put_super, 1212 .put_super = ext4_put_super,
@@ -1228,8 +1241,8 @@ enum {
1228 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota, 1241 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
1229 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, 1242 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
1230 Opt_resize, Opt_usrquota, Opt_grpquota, Opt_i_version, 1243 Opt_resize, Opt_usrquota, Opt_grpquota, Opt_i_version,
1231 Opt_stripe, Opt_delalloc, Opt_nodelalloc, 1244 Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_mblk_io_submit,
1232 Opt_block_validity, Opt_noblock_validity, 1245 Opt_nomblk_io_submit, Opt_block_validity, Opt_noblock_validity,
1233 Opt_inode_readahead_blks, Opt_journal_ioprio, 1246 Opt_inode_readahead_blks, Opt_journal_ioprio,
1234 Opt_dioread_nolock, Opt_dioread_lock, 1247 Opt_dioread_nolock, Opt_dioread_lock,
1235 Opt_discard, Opt_nodiscard, 1248 Opt_discard, Opt_nodiscard,
@@ -1293,6 +1306,8 @@ static const match_table_t tokens = {
1293 {Opt_resize, "resize"}, 1306 {Opt_resize, "resize"},
1294 {Opt_delalloc, "delalloc"}, 1307 {Opt_delalloc, "delalloc"},
1295 {Opt_nodelalloc, "nodelalloc"}, 1308 {Opt_nodelalloc, "nodelalloc"},
1309 {Opt_mblk_io_submit, "mblk_io_submit"},
1310 {Opt_nomblk_io_submit, "nomblk_io_submit"},
1296 {Opt_block_validity, "block_validity"}, 1311 {Opt_block_validity, "block_validity"},
1297 {Opt_noblock_validity, "noblock_validity"}, 1312 {Opt_noblock_validity, "noblock_validity"},
1298 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, 1313 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
@@ -1714,6 +1729,12 @@ set_qf_format:
1714 case Opt_nodelalloc: 1729 case Opt_nodelalloc:
1715 clear_opt(sbi->s_mount_opt, DELALLOC); 1730 clear_opt(sbi->s_mount_opt, DELALLOC);
1716 break; 1731 break;
1732 case Opt_mblk_io_submit:
1733 set_opt(sbi->s_mount_opt, MBLK_IO_SUBMIT);
1734 break;
1735 case Opt_nomblk_io_submit:
1736 clear_opt(sbi->s_mount_opt, MBLK_IO_SUBMIT);
1737 break;
1717 case Opt_stripe: 1738 case Opt_stripe:
1718 if (match_int(&args[0], &option)) 1739 if (match_int(&args[0], &option))
1719 return 0; 1740 return 0;
@@ -2699,7 +2720,6 @@ static int ext4_lazyinit_thread(void *arg)
2699 struct ext4_li_request *elr; 2720 struct ext4_li_request *elr;
2700 unsigned long next_wakeup; 2721 unsigned long next_wakeup;
2701 DEFINE_WAIT(wait); 2722 DEFINE_WAIT(wait);
2702 int ret;
2703 2723
2704 BUG_ON(NULL == eli); 2724 BUG_ON(NULL == eli);
2705 2725
@@ -2723,13 +2743,12 @@ cont_thread:
2723 elr = list_entry(pos, struct ext4_li_request, 2743 elr = list_entry(pos, struct ext4_li_request,
2724 lr_request); 2744 lr_request);
2725 2745
2726 if (time_after_eq(jiffies, elr->lr_next_sched)) 2746 if (time_after_eq(jiffies, elr->lr_next_sched)) {
2727 ret = ext4_run_li_request(elr); 2747 if (ext4_run_li_request(elr) != 0) {
2728 2748 /* error, remove the lazy_init job */
2729 if (ret) { 2749 ext4_remove_li_request(elr);
2730 ret = 0; 2750 continue;
2731 ext4_remove_li_request(elr); 2751 }
2732 continue;
2733 } 2752 }
2734 2753
2735 if (time_before(elr->lr_next_sched, next_wakeup)) 2754 if (time_before(elr->lr_next_sched, next_wakeup))
@@ -2740,7 +2759,8 @@ cont_thread:
2740 if (freezing(current)) 2759 if (freezing(current))
2741 refrigerator(); 2760 refrigerator();
2742 2761
2743 if (time_after_eq(jiffies, next_wakeup)) { 2762 if ((time_after_eq(jiffies, next_wakeup)) ||
2763 (MAX_JIFFY_OFFSET == next_wakeup)) {
2744 cond_resched(); 2764 cond_resched();
2745 continue; 2765 continue;
2746 } 2766 }
@@ -2788,9 +2808,6 @@ static void ext4_clear_request_list(void)
2788 struct ext4_li_request *elr; 2808 struct ext4_li_request *elr;
2789 2809
2790 mutex_lock(&ext4_li_info->li_list_mtx); 2810 mutex_lock(&ext4_li_info->li_list_mtx);
2791 if (list_empty(&ext4_li_info->li_request_list))
2792 return;
2793
2794 list_for_each_safe(pos, n, &ext4_li_info->li_request_list) { 2811 list_for_each_safe(pos, n, &ext4_li_info->li_request_list) {
2795 elr = list_entry(pos, struct ext4_li_request, 2812 elr = list_entry(pos, struct ext4_li_request,
2796 lr_request); 2813 lr_request);
@@ -3257,13 +3274,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3257 * Test whether we have more sectors than will fit in sector_t, 3274 * Test whether we have more sectors than will fit in sector_t,
3258 * and whether the max offset is addressable by the page cache. 3275 * and whether the max offset is addressable by the page cache.
3259 */ 3276 */
3260 ret = generic_check_addressable(sb->s_blocksize_bits, 3277 err = generic_check_addressable(sb->s_blocksize_bits,
3261 ext4_blocks_count(es)); 3278 ext4_blocks_count(es));
3262 if (ret) { 3279 if (err) {
3263 ext4_msg(sb, KERN_ERR, "filesystem" 3280 ext4_msg(sb, KERN_ERR, "filesystem"
3264 " too large to mount safely on this system"); 3281 " too large to mount safely on this system");
3265 if (sizeof(sector_t) < 8) 3282 if (sizeof(sector_t) < 8)
3266 ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled"); 3283 ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled");
3284 ret = err;
3267 goto failed_mount; 3285 goto failed_mount;
3268 } 3286 }
3269 3287
@@ -3348,6 +3366,24 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3348 get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 3366 get_random_bytes(&sbi->s_next_generation, sizeof(u32));
3349 spin_lock_init(&sbi->s_next_gen_lock); 3367 spin_lock_init(&sbi->s_next_gen_lock);
3350 3368
3369 err = percpu_counter_init(&sbi->s_freeblocks_counter,
3370 ext4_count_free_blocks(sb));
3371 if (!err) {
3372 err = percpu_counter_init(&sbi->s_freeinodes_counter,
3373 ext4_count_free_inodes(sb));
3374 }
3375 if (!err) {
3376 err = percpu_counter_init(&sbi->s_dirs_counter,
3377 ext4_count_dirs(sb));
3378 }
3379 if (!err) {
3380 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
3381 }
3382 if (err) {
3383 ext4_msg(sb, KERN_ERR, "insufficient memory");
3384 goto failed_mount3;
3385 }
3386
3351 sbi->s_stripe = ext4_get_stripe_size(sbi); 3387 sbi->s_stripe = ext4_get_stripe_size(sbi);
3352 sbi->s_max_writeback_mb_bump = 128; 3388 sbi->s_max_writeback_mb_bump = 128;
3353 3389
@@ -3446,22 +3482,19 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3446 } 3482 }
3447 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); 3483 set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
3448 3484
3449no_journal: 3485 /*
3450 err = percpu_counter_init(&sbi->s_freeblocks_counter, 3486 * The journal may have updated the bg summary counts, so we
3451 ext4_count_free_blocks(sb)); 3487 * need to update the global counters.
3452 if (!err) 3488 */
3453 err = percpu_counter_init(&sbi->s_freeinodes_counter, 3489 percpu_counter_set(&sbi->s_freeblocks_counter,
3454 ext4_count_free_inodes(sb)); 3490 ext4_count_free_blocks(sb));
3455 if (!err) 3491 percpu_counter_set(&sbi->s_freeinodes_counter,
3456 err = percpu_counter_init(&sbi->s_dirs_counter, 3492 ext4_count_free_inodes(sb));
3457 ext4_count_dirs(sb)); 3493 percpu_counter_set(&sbi->s_dirs_counter,
3458 if (!err) 3494 ext4_count_dirs(sb));
3459 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0); 3495 percpu_counter_set(&sbi->s_dirtyblocks_counter, 0);
3460 if (err) {
3461 ext4_msg(sb, KERN_ERR, "insufficient memory");
3462 goto failed_mount_wq;
3463 }
3464 3496
3497no_journal:
3465 EXT4_SB(sb)->dio_unwritten_wq = create_workqueue("ext4-dio-unwritten"); 3498 EXT4_SB(sb)->dio_unwritten_wq = create_workqueue("ext4-dio-unwritten");
3466 if (!EXT4_SB(sb)->dio_unwritten_wq) { 3499 if (!EXT4_SB(sb)->dio_unwritten_wq) {
3467 printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n"); 3500 printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n");
@@ -3611,10 +3644,6 @@ failed_mount_wq:
3611 jbd2_journal_destroy(sbi->s_journal); 3644 jbd2_journal_destroy(sbi->s_journal);
3612 sbi->s_journal = NULL; 3645 sbi->s_journal = NULL;
3613 } 3646 }
3614 percpu_counter_destroy(&sbi->s_freeblocks_counter);
3615 percpu_counter_destroy(&sbi->s_freeinodes_counter);
3616 percpu_counter_destroy(&sbi->s_dirs_counter);
3617 percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
3618failed_mount3: 3647failed_mount3:
3619 if (sbi->s_flex_groups) { 3648 if (sbi->s_flex_groups) {
3620 if (is_vmalloc_addr(sbi->s_flex_groups)) 3649 if (is_vmalloc_addr(sbi->s_flex_groups))
@@ -3622,6 +3651,10 @@ failed_mount3:
3622 else 3651 else
3623 kfree(sbi->s_flex_groups); 3652 kfree(sbi->s_flex_groups);
3624 } 3653 }
3654 percpu_counter_destroy(&sbi->s_freeblocks_counter);
3655 percpu_counter_destroy(&sbi->s_freeinodes_counter);
3656 percpu_counter_destroy(&sbi->s_dirs_counter);
3657 percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
3625failed_mount2: 3658failed_mount2:
3626 for (i = 0; i < db_count; i++) 3659 for (i = 0; i < db_count; i++)
3627 brelse(sbi->s_group_desc[i]); 3660 brelse(sbi->s_group_desc[i]);
@@ -3949,13 +3982,11 @@ static int ext4_commit_super(struct super_block *sb, int sync)
3949 else 3982 else
3950 es->s_kbytes_written = 3983 es->s_kbytes_written =
3951 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written); 3984 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written);
3952 if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeblocks_counter)) 3985 ext4_free_blocks_count_set(es, percpu_counter_sum_positive(
3953 ext4_free_blocks_count_set(es, percpu_counter_sum_positive( 3986 &EXT4_SB(sb)->s_freeblocks_counter));
3954 &EXT4_SB(sb)->s_freeblocks_counter)); 3987 es->s_free_inodes_count =
3955 if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeinodes_counter)) 3988 cpu_to_le32(percpu_counter_sum_positive(
3956 es->s_free_inodes_count = 3989 &EXT4_SB(sb)->s_freeinodes_counter));
3957 cpu_to_le32(percpu_counter_sum_positive(
3958 &EXT4_SB(sb)->s_freeinodes_counter));
3959 sb->s_dirt = 0; 3990 sb->s_dirt = 0;
3960 BUFFER_TRACE(sbh, "marking dirty"); 3991 BUFFER_TRACE(sbh, "marking dirty");
3961 mark_buffer_dirty(sbh); 3992 mark_buffer_dirty(sbh);
@@ -4556,12 +4587,10 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
4556 4587
4557static int ext4_quota_off(struct super_block *sb, int type) 4588static int ext4_quota_off(struct super_block *sb, int type)
4558{ 4589{
4559 /* Force all delayed allocation blocks to be allocated */ 4590 /* Force all delayed allocation blocks to be allocated.
4560 if (test_opt(sb, DELALLOC)) { 4591 * Caller already holds s_umount sem */
4561 down_read(&sb->s_umount); 4592 if (test_opt(sb, DELALLOC))
4562 sync_filesystem(sb); 4593 sync_filesystem(sb);
4563 up_read(&sb->s_umount);
4564 }
4565 4594
4566 return dquot_quota_off(sb, type); 4595 return dquot_quota_off(sb, type);
4567} 4596}
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index c8224587123f..8b984a2cebbd 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -13,6 +13,7 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/compat.h>
16 17
17static const struct file_operations fuse_direct_io_file_operations; 18static const struct file_operations fuse_direct_io_file_operations;
18 19
@@ -134,6 +135,7 @@ EXPORT_SYMBOL_GPL(fuse_do_open);
134void fuse_finish_open(struct inode *inode, struct file *file) 135void fuse_finish_open(struct inode *inode, struct file *file)
135{ 136{
136 struct fuse_file *ff = file->private_data; 137 struct fuse_file *ff = file->private_data;
138 struct fuse_conn *fc = get_fuse_conn(inode);
137 139
138 if (ff->open_flags & FOPEN_DIRECT_IO) 140 if (ff->open_flags & FOPEN_DIRECT_IO)
139 file->f_op = &fuse_direct_io_file_operations; 141 file->f_op = &fuse_direct_io_file_operations;
@@ -141,6 +143,15 @@ void fuse_finish_open(struct inode *inode, struct file *file)
141 invalidate_inode_pages2(inode->i_mapping); 143 invalidate_inode_pages2(inode->i_mapping);
142 if (ff->open_flags & FOPEN_NONSEEKABLE) 144 if (ff->open_flags & FOPEN_NONSEEKABLE)
143 nonseekable_open(inode, file); 145 nonseekable_open(inode, file);
146 if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) {
147 struct fuse_inode *fi = get_fuse_inode(inode);
148
149 spin_lock(&fc->lock);
150 fi->attr_version = ++fc->attr_version;
151 i_size_write(inode, 0);
152 spin_unlock(&fc->lock);
153 fuse_invalidate_attr(inode);
154 }
144} 155}
145 156
146int fuse_open_common(struct inode *inode, struct file *file, bool isdir) 157int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
@@ -1618,6 +1629,58 @@ static int fuse_ioctl_copy_user(struct page **pages, struct iovec *iov,
1618} 1629}
1619 1630
1620/* 1631/*
1632 * CUSE servers compiled on 32bit broke on 64bit kernels because the
1633 * ABI was defined to be 'struct iovec' which is different on 32bit
1634 * and 64bit. Fortunately we can determine which structure the server
1635 * used from the size of the reply.
1636 */
1637static int fuse_copy_ioctl_iovec(struct iovec *dst, void *src,
1638 size_t transferred, unsigned count,
1639 bool is_compat)
1640{
1641#ifdef CONFIG_COMPAT
1642 if (count * sizeof(struct compat_iovec) == transferred) {
1643 struct compat_iovec *ciov = src;
1644 unsigned i;
1645
1646 /*
1647 * With this interface a 32bit server cannot support
1648 * non-compat (i.e. ones coming from 64bit apps) ioctl
1649 * requests
1650 */
1651 if (!is_compat)
1652 return -EINVAL;
1653
1654 for (i = 0; i < count; i++) {
1655 dst[i].iov_base = compat_ptr(ciov[i].iov_base);
1656 dst[i].iov_len = ciov[i].iov_len;
1657 }
1658 return 0;
1659 }
1660#endif
1661
1662 if (count * sizeof(struct iovec) != transferred)
1663 return -EIO;
1664
1665 memcpy(dst, src, transferred);
1666 return 0;
1667}
1668
1669/* Make sure iov_length() won't overflow */
1670static int fuse_verify_ioctl_iov(struct iovec *iov, size_t count)
1671{
1672 size_t n;
1673 u32 max = FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT;
1674
1675 for (n = 0; n < count; n++) {
1676 if (iov->iov_len > (size_t) max)
1677 return -ENOMEM;
1678 max -= iov->iov_len;
1679 }
1680 return 0;
1681}
1682
1683/*
1621 * For ioctls, there is no generic way to determine how much memory 1684 * For ioctls, there is no generic way to determine how much memory
1622 * needs to be read and/or written. Furthermore, ioctls are allowed 1685 * needs to be read and/or written. Furthermore, ioctls are allowed
1623 * to dereference the passed pointer, so the parameter requires deep 1686 * to dereference the passed pointer, so the parameter requires deep
@@ -1798,18 +1861,25 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1798 in_iovs + out_iovs > FUSE_IOCTL_MAX_IOV) 1861 in_iovs + out_iovs > FUSE_IOCTL_MAX_IOV)
1799 goto out; 1862 goto out;
1800 1863
1801 err = -EIO;
1802 if ((in_iovs + out_iovs) * sizeof(struct iovec) != transferred)
1803 goto out;
1804
1805 /* okay, copy in iovs and retry */
1806 vaddr = kmap_atomic(pages[0], KM_USER0); 1864 vaddr = kmap_atomic(pages[0], KM_USER0);
1807 memcpy(page_address(iov_page), vaddr, transferred); 1865 err = fuse_copy_ioctl_iovec(page_address(iov_page), vaddr,
1866 transferred, in_iovs + out_iovs,
1867 (flags & FUSE_IOCTL_COMPAT) != 0);
1808 kunmap_atomic(vaddr, KM_USER0); 1868 kunmap_atomic(vaddr, KM_USER0);
1869 if (err)
1870 goto out;
1809 1871
1810 in_iov = page_address(iov_page); 1872 in_iov = page_address(iov_page);
1811 out_iov = in_iov + in_iovs; 1873 out_iov = in_iov + in_iovs;
1812 1874
1875 err = fuse_verify_ioctl_iov(in_iov, in_iovs);
1876 if (err)
1877 goto out;
1878
1879 err = fuse_verify_ioctl_iov(out_iov, out_iovs);
1880 if (err)
1881 goto out;
1882
1813 goto retry; 1883 goto retry;
1814 } 1884 }
1815 1885
diff --git a/fs/gfs2/export.c b/fs/gfs2/export.c
index 06d582732d34..5ab3839dfcb9 100644
--- a/fs/gfs2/export.c
+++ b/fs/gfs2/export.c
@@ -138,10 +138,8 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
138 struct gfs2_inum_host *inum) 138 struct gfs2_inum_host *inum)
139{ 139{
140 struct gfs2_sbd *sdp = sb->s_fs_info; 140 struct gfs2_sbd *sdp = sb->s_fs_info;
141 struct gfs2_holder i_gh;
142 struct inode *inode; 141 struct inode *inode;
143 struct dentry *dentry; 142 struct dentry *dentry;
144 int error;
145 143
146 inode = gfs2_ilookup(sb, inum->no_addr); 144 inode = gfs2_ilookup(sb, inum->no_addr);
147 if (inode) { 145 if (inode) {
@@ -152,52 +150,16 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
152 goto out_inode; 150 goto out_inode;
153 } 151 }
154 152
155 error = gfs2_glock_nq_num(sdp, inum->no_addr, &gfs2_inode_glops, 153 inode = gfs2_lookup_by_inum(sdp, inum->no_addr, &inum->no_formal_ino,
156 LM_ST_SHARED, LM_FLAG_ANY, &i_gh); 154 GFS2_BLKST_DINODE);
157 if (error) 155 if (IS_ERR(inode))
158 return ERR_PTR(error); 156 return ERR_CAST(inode);
159
160 error = gfs2_check_blk_type(sdp, inum->no_addr, GFS2_BLKST_DINODE);
161 if (error)
162 goto fail;
163
164 inode = gfs2_inode_lookup(sb, DT_UNKNOWN, inum->no_addr, 0);
165 if (IS_ERR(inode)) {
166 error = PTR_ERR(inode);
167 goto fail;
168 }
169
170 error = gfs2_inode_refresh(GFS2_I(inode));
171 if (error) {
172 iput(inode);
173 goto fail;
174 }
175
176 /* Pick up the works we bypass in gfs2_inode_lookup */
177 if (inode->i_state & I_NEW)
178 gfs2_set_iop(inode);
179
180 if (GFS2_I(inode)->i_no_formal_ino != inum->no_formal_ino) {
181 iput(inode);
182 goto fail;
183 }
184
185 error = -EIO;
186 if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM) {
187 iput(inode);
188 goto fail;
189 }
190
191 gfs2_glock_dq_uninit(&i_gh);
192 157
193out_inode: 158out_inode:
194 dentry = d_obtain_alias(inode); 159 dentry = d_obtain_alias(inode);
195 if (!IS_ERR(dentry)) 160 if (!IS_ERR(dentry))
196 dentry->d_op = &gfs2_dops; 161 dentry->d_op = &gfs2_dops;
197 return dentry; 162 return dentry;
198fail:
199 gfs2_glock_dq_uninit(&i_gh);
200 return ERR_PTR(error);
201} 163}
202 164
203static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid, 165static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid,
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 87778857f099..f92c17704169 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -686,21 +686,20 @@ static void delete_work_func(struct work_struct *work)
686{ 686{
687 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete); 687 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete);
688 struct gfs2_sbd *sdp = gl->gl_sbd; 688 struct gfs2_sbd *sdp = gl->gl_sbd;
689 struct gfs2_inode *ip = NULL; 689 struct gfs2_inode *ip;
690 struct inode *inode; 690 struct inode *inode;
691 u64 no_addr = 0; 691 u64 no_addr = gl->gl_name.ln_number;
692
693 ip = gl->gl_object;
694 /* Note: Unsafe to dereference ip as we don't hold right refs/locks */
692 695
693 spin_lock(&gl->gl_spin);
694 ip = (struct gfs2_inode *)gl->gl_object;
695 if (ip) 696 if (ip)
696 no_addr = ip->i_no_addr;
697 spin_unlock(&gl->gl_spin);
698 if (ip) {
699 inode = gfs2_ilookup(sdp->sd_vfs, no_addr); 697 inode = gfs2_ilookup(sdp->sd_vfs, no_addr);
700 if (inode) { 698 else
701 d_prune_aliases(inode); 699 inode = gfs2_lookup_by_inum(sdp, no_addr, NULL, GFS2_BLKST_UNLINKED);
702 iput(inode); 700 if (inode && !IS_ERR(inode)) {
703 } 701 d_prune_aliases(inode);
702 iput(inode);
704 } 703 }
705 gfs2_glock_put(gl); 704 gfs2_glock_put(gl);
706} 705}
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 06370f8bd8cf..e1213f7f9217 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -73,49 +73,6 @@ static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr)
73 return iget5_locked(sb, hash, iget_test, iget_set, &no_addr); 73 return iget5_locked(sb, hash, iget_test, iget_set, &no_addr);
74} 74}
75 75
76struct gfs2_skip_data {
77 u64 no_addr;
78 int skipped;
79};
80
81static int iget_skip_test(struct inode *inode, void *opaque)
82{
83 struct gfs2_inode *ip = GFS2_I(inode);
84 struct gfs2_skip_data *data = opaque;
85
86 if (ip->i_no_addr == data->no_addr) {
87 if (inode->i_state & (I_FREEING|I_WILL_FREE)){
88 data->skipped = 1;
89 return 0;
90 }
91 return 1;
92 }
93 return 0;
94}
95
96static int iget_skip_set(struct inode *inode, void *opaque)
97{
98 struct gfs2_inode *ip = GFS2_I(inode);
99 struct gfs2_skip_data *data = opaque;
100
101 if (data->skipped)
102 return 1;
103 inode->i_ino = (unsigned long)(data->no_addr);
104 ip->i_no_addr = data->no_addr;
105 return 0;
106}
107
108static struct inode *gfs2_iget_skip(struct super_block *sb,
109 u64 no_addr)
110{
111 struct gfs2_skip_data data;
112 unsigned long hash = (unsigned long)no_addr;
113
114 data.no_addr = no_addr;
115 data.skipped = 0;
116 return iget5_locked(sb, hash, iget_skip_test, iget_skip_set, &data);
117}
118
119/** 76/**
120 * GFS2 lookup code fills in vfs inode contents based on info obtained 77 * GFS2 lookup code fills in vfs inode contents based on info obtained
121 * from directory entry inside gfs2_inode_lookup(). This has caused issues 78 * from directory entry inside gfs2_inode_lookup(). This has caused issues
@@ -243,93 +200,54 @@ fail:
243 return ERR_PTR(error); 200 return ERR_PTR(error);
244} 201}
245 202
246/** 203struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
247 * gfs2_process_unlinked_inode - Lookup an unlinked inode for reclamation 204 u64 *no_formal_ino, unsigned int blktype)
248 * and try to reclaim it by doing iput.
249 *
250 * This function assumes no rgrp locks are currently held.
251 *
252 * @sb: The super block
253 * no_addr: The inode number
254 *
255 */
256
257void gfs2_process_unlinked_inode(struct super_block *sb, u64 no_addr)
258{ 205{
259 struct gfs2_sbd *sdp; 206 struct super_block *sb = sdp->sd_vfs;
260 struct gfs2_inode *ip; 207 struct gfs2_holder i_gh;
261 struct gfs2_glock *io_gl = NULL;
262 int error;
263 struct gfs2_holder gh;
264 struct inode *inode; 208 struct inode *inode;
209 int error;
265 210
266 inode = gfs2_iget_skip(sb, no_addr); 211 error = gfs2_glock_nq_num(sdp, no_addr, &gfs2_inode_glops,
267 212 LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
268 if (!inode) 213 if (error)
269 return; 214 return ERR_PTR(error);
270
271 /* If it's not a new inode, someone's using it, so leave it alone. */
272 if (!(inode->i_state & I_NEW)) {
273 iput(inode);
274 return;
275 }
276
277 ip = GFS2_I(inode);
278 sdp = GFS2_SB(inode);
279 ip->i_no_formal_ino = -1;
280 215
281 error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); 216 error = gfs2_check_blk_type(sdp, no_addr, blktype);
282 if (unlikely(error)) 217 if (error)
283 goto fail; 218 goto fail;
284 ip->i_gl->gl_object = ip;
285 219
286 error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); 220 inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0);
287 if (unlikely(error)) 221 if (IS_ERR(inode))
288 goto fail_put; 222 goto fail;
289
290 set_bit(GIF_INVALID, &ip->i_flags);
291 error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, LM_FLAG_TRY | GL_EXACT,
292 &ip->i_iopen_gh);
293 if (unlikely(error))
294 goto fail_iopen;
295 223
296 ip->i_iopen_gh.gh_gl->gl_object = ip; 224 error = gfs2_inode_refresh(GFS2_I(inode));
297 gfs2_glock_put(io_gl); 225 if (error)
298 io_gl = NULL; 226 goto fail_iput;
299 227
300 inode->i_mode = DT2IF(DT_UNKNOWN); 228 /* Pick up the works we bypass in gfs2_inode_lookup */
229 if (inode->i_state & I_NEW)
230 gfs2_set_iop(inode);
301 231
302 /* 232 /* Two extra checks for NFS only */
303 * We must read the inode in order to work out its type in 233 if (no_formal_ino) {
304 * this case. Note that this doesn't happen often as we normally 234 error = -ESTALE;
305 * know the type beforehand. This code path only occurs during 235 if (GFS2_I(inode)->i_no_formal_ino != *no_formal_ino)
306 * unlinked inode recovery (where it is safe to do this glock, 236 goto fail_iput;
307 * which is not true in the general case).
308 */
309 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, LM_FLAG_TRY,
310 &gh);
311 if (unlikely(error))
312 goto fail_glock;
313 237
314 /* Inode is now uptodate */ 238 error = -EIO;
315 gfs2_glock_dq_uninit(&gh); 239 if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM)
316 gfs2_set_iop(inode); 240 goto fail_iput;
317 241
318 /* The iput will cause it to be deleted. */ 242 error = 0;
319 iput(inode); 243 }
320 return;
321 244
322fail_glock:
323 gfs2_glock_dq(&ip->i_iopen_gh);
324fail_iopen:
325 if (io_gl)
326 gfs2_glock_put(io_gl);
327fail_put:
328 ip->i_gl->gl_object = NULL;
329 gfs2_glock_put(ip->i_gl);
330fail: 245fail:
331 iget_failed(inode); 246 gfs2_glock_dq_uninit(&i_gh);
332 return; 247 return error ? ERR_PTR(error) : inode;
248fail_iput:
249 iput(inode);
250 goto fail;
333} 251}
334 252
335static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) 253static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index 6720d7d5fbc6..d8499fadcc53 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -99,7 +99,9 @@ err:
99extern void gfs2_set_iop(struct inode *inode); 99extern void gfs2_set_iop(struct inode *inode);
100extern struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type, 100extern struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type,
101 u64 no_addr, u64 no_formal_ino); 101 u64 no_addr, u64 no_formal_ino);
102extern void gfs2_process_unlinked_inode(struct super_block *sb, u64 no_addr); 102extern struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
103 u64 *no_formal_ino,
104 unsigned int blktype);
103extern struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr); 105extern struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr);
104 106
105extern int gfs2_inode_refresh(struct gfs2_inode *ip); 107extern int gfs2_inode_refresh(struct gfs2_inode *ip);
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 58a9b9998b42..f606baf9ba72 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -631,6 +631,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
631 struct fs_disk_quota *fdq) 631 struct fs_disk_quota *fdq)
632{ 632{
633 struct inode *inode = &ip->i_inode; 633 struct inode *inode = &ip->i_inode;
634 struct gfs2_sbd *sdp = GFS2_SB(inode);
634 struct address_space *mapping = inode->i_mapping; 635 struct address_space *mapping = inode->i_mapping;
635 unsigned long index = loc >> PAGE_CACHE_SHIFT; 636 unsigned long index = loc >> PAGE_CACHE_SHIFT;
636 unsigned offset = loc & (PAGE_CACHE_SIZE - 1); 637 unsigned offset = loc & (PAGE_CACHE_SIZE - 1);
@@ -658,11 +659,11 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
658 qd->qd_qb.qb_value = qp->qu_value; 659 qd->qd_qb.qb_value = qp->qu_value;
659 if (fdq) { 660 if (fdq) {
660 if (fdq->d_fieldmask & FS_DQ_BSOFT) { 661 if (fdq->d_fieldmask & FS_DQ_BSOFT) {
661 qp->qu_warn = cpu_to_be64(fdq->d_blk_softlimit); 662 qp->qu_warn = cpu_to_be64(fdq->d_blk_softlimit >> sdp->sd_fsb2bb_shift);
662 qd->qd_qb.qb_warn = qp->qu_warn; 663 qd->qd_qb.qb_warn = qp->qu_warn;
663 } 664 }
664 if (fdq->d_fieldmask & FS_DQ_BHARD) { 665 if (fdq->d_fieldmask & FS_DQ_BHARD) {
665 qp->qu_limit = cpu_to_be64(fdq->d_blk_hardlimit); 666 qp->qu_limit = cpu_to_be64(fdq->d_blk_hardlimit >> sdp->sd_fsb2bb_shift);
666 qd->qd_qb.qb_limit = qp->qu_limit; 667 qd->qd_qb.qb_limit = qp->qu_limit;
667 } 668 }
668 } 669 }
@@ -1497,9 +1498,9 @@ static int gfs2_get_dqblk(struct super_block *sb, int type, qid_t id,
1497 fdq->d_version = FS_DQUOT_VERSION; 1498 fdq->d_version = FS_DQUOT_VERSION;
1498 fdq->d_flags = (type == QUOTA_USER) ? FS_USER_QUOTA : FS_GROUP_QUOTA; 1499 fdq->d_flags = (type == QUOTA_USER) ? FS_USER_QUOTA : FS_GROUP_QUOTA;
1499 fdq->d_id = id; 1500 fdq->d_id = id;
1500 fdq->d_blk_hardlimit = be64_to_cpu(qlvb->qb_limit); 1501 fdq->d_blk_hardlimit = be64_to_cpu(qlvb->qb_limit) << sdp->sd_fsb2bb_shift;
1501 fdq->d_blk_softlimit = be64_to_cpu(qlvb->qb_warn); 1502 fdq->d_blk_softlimit = be64_to_cpu(qlvb->qb_warn) << sdp->sd_fsb2bb_shift;
1502 fdq->d_bcount = be64_to_cpu(qlvb->qb_value); 1503 fdq->d_bcount = be64_to_cpu(qlvb->qb_value) << sdp->sd_fsb2bb_shift;
1503 1504
1504 gfs2_glock_dq_uninit(&q_gh); 1505 gfs2_glock_dq_uninit(&q_gh);
1505out: 1506out:
@@ -1566,10 +1567,10 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
1566 1567
1567 /* If nothing has changed, this is a no-op */ 1568 /* If nothing has changed, this is a no-op */
1568 if ((fdq->d_fieldmask & FS_DQ_BSOFT) && 1569 if ((fdq->d_fieldmask & FS_DQ_BSOFT) &&
1569 (fdq->d_blk_softlimit == be64_to_cpu(qd->qd_qb.qb_warn))) 1570 ((fdq->d_blk_softlimit >> sdp->sd_fsb2bb_shift) == be64_to_cpu(qd->qd_qb.qb_warn)))
1570 fdq->d_fieldmask ^= FS_DQ_BSOFT; 1571 fdq->d_fieldmask ^= FS_DQ_BSOFT;
1571 if ((fdq->d_fieldmask & FS_DQ_BHARD) && 1572 if ((fdq->d_fieldmask & FS_DQ_BHARD) &&
1572 (fdq->d_blk_hardlimit == be64_to_cpu(qd->qd_qb.qb_limit))) 1573 ((fdq->d_blk_hardlimit >> sdp->sd_fsb2bb_shift) == be64_to_cpu(qd->qd_qb.qb_limit)))
1573 fdq->d_fieldmask ^= FS_DQ_BHARD; 1574 fdq->d_fieldmask ^= FS_DQ_BHARD;
1574 if (fdq->d_fieldmask == 0) 1575 if (fdq->d_fieldmask == 0)
1575 goto out_i; 1576 goto out_i;
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index bef3ab6cf5c1..33c8407b876f 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -963,17 +963,18 @@ static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_alloc *al)
963 * The inode, if one has been found, in inode. 963 * The inode, if one has been found, in inode.
964 */ 964 */
965 965
966static u64 try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, 966static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip)
967 u64 skip)
968{ 967{
969 u32 goal = 0, block; 968 u32 goal = 0, block;
970 u64 no_addr; 969 u64 no_addr;
971 struct gfs2_sbd *sdp = rgd->rd_sbd; 970 struct gfs2_sbd *sdp = rgd->rd_sbd;
972 unsigned int n; 971 unsigned int n;
972 struct gfs2_glock *gl;
973 struct gfs2_inode *ip;
974 int error;
975 int found = 0;
973 976
974 for(;;) { 977 while (goal < rgd->rd_data) {
975 if (goal >= rgd->rd_data)
976 break;
977 down_write(&sdp->sd_log_flush_lock); 978 down_write(&sdp->sd_log_flush_lock);
978 n = 1; 979 n = 1;
979 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, 980 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED,
@@ -990,11 +991,32 @@ static u64 try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked,
990 if (no_addr == skip) 991 if (no_addr == skip)
991 continue; 992 continue;
992 *last_unlinked = no_addr; 993 *last_unlinked = no_addr;
993 return no_addr; 994
995 error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &gl);
996 if (error)
997 continue;
998
999 /* If the inode is already in cache, we can ignore it here
1000 * because the existing inode disposal code will deal with
1001 * it when all refs have gone away. Accessing gl_object like
1002 * this is not safe in general. Here it is ok because we do
1003 * not dereference the pointer, and we only need an approx
1004 * answer to whether it is NULL or not.
1005 */
1006 ip = gl->gl_object;
1007
1008 if (ip || queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
1009 gfs2_glock_put(gl);
1010 else
1011 found++;
1012
1013 /* Limit reclaim to sensible number of tasks */
1014 if (found > 2*NR_CPUS)
1015 return;
994 } 1016 }
995 1017
996 rgd->rd_flags &= ~GFS2_RDF_CHECK; 1018 rgd->rd_flags &= ~GFS2_RDF_CHECK;
997 return 0; 1019 return;
998} 1020}
999 1021
1000/** 1022/**
@@ -1075,11 +1097,9 @@ static void forward_rgrp_set(struct gfs2_sbd *sdp, struct gfs2_rgrpd *rgd)
1075 * Try to acquire rgrp in way which avoids contending with others. 1097 * Try to acquire rgrp in way which avoids contending with others.
1076 * 1098 *
1077 * Returns: errno 1099 * Returns: errno
1078 * unlinked: the block address of an unlinked block to be reclaimed
1079 */ 1100 */
1080 1101
1081static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked, 1102static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1082 u64 *last_unlinked)
1083{ 1103{
1084 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1104 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1085 struct gfs2_rgrpd *rgd, *begin = NULL; 1105 struct gfs2_rgrpd *rgd, *begin = NULL;
@@ -1089,7 +1109,6 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked,
1089 int loops = 0; 1109 int loops = 0;
1090 int error, rg_locked; 1110 int error, rg_locked;
1091 1111
1092 *unlinked = 0;
1093 rgd = gfs2_blk2rgrpd(sdp, ip->i_goal); 1112 rgd = gfs2_blk2rgrpd(sdp, ip->i_goal);
1094 1113
1095 while (rgd) { 1114 while (rgd) {
@@ -1106,17 +1125,10 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked,
1106 case 0: 1125 case 0:
1107 if (try_rgrp_fit(rgd, al)) 1126 if (try_rgrp_fit(rgd, al))
1108 goto out; 1127 goto out;
1109 /* If the rg came in already locked, there's no 1128 if (rgd->rd_flags & GFS2_RDF_CHECK)
1110 way we can recover from a failed try_rgrp_unlink 1129 try_rgrp_unlink(rgd, last_unlinked, ip->i_no_addr);
1111 because that would require an iput which can only
1112 happen after the rgrp is unlocked. */
1113 if (!rg_locked && rgd->rd_flags & GFS2_RDF_CHECK)
1114 *unlinked = try_rgrp_unlink(rgd, last_unlinked,
1115 ip->i_no_addr);
1116 if (!rg_locked) 1130 if (!rg_locked)
1117 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1131 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1118 if (*unlinked)
1119 return -EAGAIN;
1120 /* fall through */ 1132 /* fall through */
1121 case GLR_TRYFAILED: 1133 case GLR_TRYFAILED:
1122 rgd = recent_rgrp_next(rgd); 1134 rgd = recent_rgrp_next(rgd);
@@ -1145,13 +1157,10 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked,
1145 case 0: 1157 case 0:
1146 if (try_rgrp_fit(rgd, al)) 1158 if (try_rgrp_fit(rgd, al))
1147 goto out; 1159 goto out;
1148 if (!rg_locked && rgd->rd_flags & GFS2_RDF_CHECK) 1160 if (rgd->rd_flags & GFS2_RDF_CHECK)
1149 *unlinked = try_rgrp_unlink(rgd, last_unlinked, 1161 try_rgrp_unlink(rgd, last_unlinked, ip->i_no_addr);
1150 ip->i_no_addr);
1151 if (!rg_locked) 1162 if (!rg_locked)
1152 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1163 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1153 if (*unlinked)
1154 return -EAGAIN;
1155 break; 1164 break;
1156 1165
1157 case GLR_TRYFAILED: 1166 case GLR_TRYFAILED:
@@ -1204,12 +1213,12 @@ int gfs2_inplace_reserve_i(struct gfs2_inode *ip, int hold_rindex,
1204 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1213 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1205 struct gfs2_alloc *al = ip->i_alloc; 1214 struct gfs2_alloc *al = ip->i_alloc;
1206 int error = 0; 1215 int error = 0;
1207 u64 last_unlinked = NO_BLOCK, unlinked; 1216 u64 last_unlinked = NO_BLOCK;
1217 int tries = 0;
1208 1218
1209 if (gfs2_assert_warn(sdp, al->al_requested)) 1219 if (gfs2_assert_warn(sdp, al->al_requested))
1210 return -EINVAL; 1220 return -EINVAL;
1211 1221
1212try_again:
1213 if (hold_rindex) { 1222 if (hold_rindex) {
1214 /* We need to hold the rindex unless the inode we're using is 1223 /* We need to hold the rindex unless the inode we're using is
1215 the rindex itself, in which case it's already held. */ 1224 the rindex itself, in which case it's already held. */
@@ -1218,31 +1227,23 @@ try_again:
1218 else if (!sdp->sd_rgrps) /* We may not have the rindex read 1227 else if (!sdp->sd_rgrps) /* We may not have the rindex read
1219 in, so: */ 1228 in, so: */
1220 error = gfs2_ri_update_special(ip); 1229 error = gfs2_ri_update_special(ip);
1230 if (error)
1231 return error;
1221 } 1232 }
1222 1233
1223 if (error) 1234 do {
1224 return error; 1235 error = get_local_rgrp(ip, &last_unlinked);
1236 /* If there is no space, flushing the log may release some */
1237 if (error)
1238 gfs2_log_flush(sdp, NULL);
1239 } while (error && tries++ < 3);
1225 1240
1226 /* Find an rgrp suitable for allocation. If it encounters any unlinked
1227 dinodes along the way, error will equal -EAGAIN and unlinked will
1228 contains it block address. We then need to look up that inode and
1229 try to free it, and try the allocation again. */
1230 error = get_local_rgrp(ip, &unlinked, &last_unlinked);
1231 if (error) { 1241 if (error) {
1232 if (hold_rindex && ip != GFS2_I(sdp->sd_rindex)) 1242 if (hold_rindex && ip != GFS2_I(sdp->sd_rindex))
1233 gfs2_glock_dq_uninit(&al->al_ri_gh); 1243 gfs2_glock_dq_uninit(&al->al_ri_gh);
1234 if (error != -EAGAIN) 1244 return error;
1235 return error;
1236
1237 gfs2_process_unlinked_inode(ip->i_inode.i_sb, unlinked);
1238 /* regardless of whether or not gfs2_process_unlinked_inode
1239 was successful, we don't want to repeat it again. */
1240 last_unlinked = unlinked;
1241 gfs2_log_flush(sdp, NULL);
1242 error = 0;
1243
1244 goto try_again;
1245 } 1245 }
1246
1246 /* no error, so we have the rgrp set in the inode's allocation. */ 1247 /* no error, so we have the rgrp set in the inode's allocation. */
1247 al->al_file = file; 1248 al->al_file = file;
1248 al->al_line = line; 1249 al->al_line = line;
diff --git a/fs/hpfs/buffer.c b/fs/hpfs/buffer.c
index eac5f96323e3..793cb9d943d2 100644
--- a/fs/hpfs/buffer.c
+++ b/fs/hpfs/buffer.c
@@ -14,7 +14,7 @@ void hpfs_lock_creation(struct super_block *s)
14#ifdef DEBUG_LOCKS 14#ifdef DEBUG_LOCKS
15 printk("lock creation\n"); 15 printk("lock creation\n");
16#endif 16#endif
17 down(&hpfs_sb(s)->hpfs_creation_de); 17 mutex_lock(&hpfs_sb(s)->hpfs_creation_de);
18} 18}
19 19
20void hpfs_unlock_creation(struct super_block *s) 20void hpfs_unlock_creation(struct super_block *s)
@@ -22,7 +22,7 @@ void hpfs_unlock_creation(struct super_block *s)
22#ifdef DEBUG_LOCKS 22#ifdef DEBUG_LOCKS
23 printk("unlock creation\n"); 23 printk("unlock creation\n");
24#endif 24#endif
25 up(&hpfs_sb(s)->hpfs_creation_de); 25 mutex_unlock(&hpfs_sb(s)->hpfs_creation_de);
26} 26}
27 27
28/* Map a sector into a buffer and return pointers to it and to the buffer. */ 28/* Map a sector into a buffer and return pointers to it and to the buffer. */
diff --git a/fs/hpfs/hpfs_fn.h b/fs/hpfs/hpfs_fn.h
index b59eac0232a0..2fee17d0d9ab 100644
--- a/fs/hpfs/hpfs_fn.h
+++ b/fs/hpfs/hpfs_fn.h
@@ -87,7 +87,7 @@ struct hpfs_sb_info {
87 unsigned *sb_bmp_dir; /* main bitmap directory */ 87 unsigned *sb_bmp_dir; /* main bitmap directory */
88 unsigned sb_c_bitmap; /* current bitmap */ 88 unsigned sb_c_bitmap; /* current bitmap */
89 unsigned sb_max_fwd_alloc; /* max forwad allocation */ 89 unsigned sb_max_fwd_alloc; /* max forwad allocation */
90 struct semaphore hpfs_creation_de; /* when creating dirents, nobody else 90 struct mutex hpfs_creation_de; /* when creating dirents, nobody else
91 can alloc blocks */ 91 can alloc blocks */
92 /*unsigned sb_mounting : 1;*/ 92 /*unsigned sb_mounting : 1;*/
93 int sb_timeshift; 93 int sb_timeshift;
diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
index bb69389972eb..6c5f01597c3a 100644
--- a/fs/hpfs/super.c
+++ b/fs/hpfs/super.c
@@ -491,7 +491,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
491 sbi->sb_bmp_dir = NULL; 491 sbi->sb_bmp_dir = NULL;
492 sbi->sb_cp_table = NULL; 492 sbi->sb_cp_table = NULL;
493 493
494 init_MUTEX(&sbi->hpfs_creation_de); 494 mutex_init(&sbi->hpfs_creation_de);
495 495
496 uid = current_uid(); 496 uid = current_uid();
497 gid = current_gid(); 497 gid = current_gid();
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index d6cfac1f0a40..a5fe68189eed 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -932,8 +932,7 @@ struct file *hugetlb_file_setup(const char *name, size_t size, int acctflag,
932 if (creat_flags == HUGETLB_SHMFS_INODE && !can_do_hugetlb_shm()) { 932 if (creat_flags == HUGETLB_SHMFS_INODE && !can_do_hugetlb_shm()) {
933 *user = current_user(); 933 *user = current_user();
934 if (user_shm_lock(size, *user)) { 934 if (user_shm_lock(size, *user)) {
935 WARN_ONCE(1, 935 printk_once(KERN_WARNING "Using mlock ulimits for SHM_HUGETLB is deprecated\n");
936 "Using mlock ulimits for SHM_HUGETLB deprecated\n");
937 } else { 936 } else {
938 *user = NULL; 937 *user = NULL;
939 return ERR_PTR(-EPERM); 938 return ERR_PTR(-EPERM);
diff --git a/fs/ioctl.c b/fs/ioctl.c
index e92fdbb3bc3a..d6cc16476620 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -6,7 +6,6 @@
6 6
7#include <linux/syscalls.h> 7#include <linux/syscalls.h>
8#include <linux/mm.h> 8#include <linux/mm.h>
9#include <linux/smp_lock.h>
10#include <linux/capability.h> 9#include <linux/capability.h>
11#include <linux/file.h> 10#include <linux/file.h>
12#include <linux/fs.h> 11#include <linux/fs.h>
@@ -530,41 +529,6 @@ static int ioctl_fsthaw(struct file *filp)
530 return thaw_super(sb); 529 return thaw_super(sb);
531} 530}
532 531
533static int ioctl_fstrim(struct file *filp, void __user *argp)
534{
535 struct super_block *sb = filp->f_path.dentry->d_inode->i_sb;
536 struct fstrim_range range;
537 int ret = 0;
538
539 if (!capable(CAP_SYS_ADMIN))
540 return -EPERM;
541
542 /* If filesystem doesn't support trim feature, return. */
543 if (sb->s_op->trim_fs == NULL)
544 return -EOPNOTSUPP;
545
546 /* If a blockdevice-backed filesystem isn't specified, return EINVAL. */
547 if (sb->s_bdev == NULL)
548 return -EINVAL;
549
550 if (argp == NULL) {
551 range.start = 0;
552 range.len = ULLONG_MAX;
553 range.minlen = 0;
554 } else if (copy_from_user(&range, argp, sizeof(range)))
555 return -EFAULT;
556
557 ret = sb->s_op->trim_fs(sb, &range);
558 if (ret < 0)
559 return ret;
560
561 if ((argp != NULL) &&
562 (copy_to_user(argp, &range, sizeof(range))))
563 return -EFAULT;
564
565 return 0;
566}
567
568/* 532/*
569 * When you add any new common ioctls to the switches above and below 533 * When you add any new common ioctls to the switches above and below
570 * please update compat_sys_ioctl() too. 534 * please update compat_sys_ioctl() too.
@@ -615,10 +579,6 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
615 error = ioctl_fsthaw(filp); 579 error = ioctl_fsthaw(filp);
616 break; 580 break;
617 581
618 case FITRIM:
619 error = ioctl_fstrim(filp, argp);
620 break;
621
622 case FS_IOC_FIEMAP: 582 case FS_IOC_FIEMAP:
623 return ioctl_fiemap(filp, arg); 583 return ioctl_fiemap(filp, arg);
624 584
diff --git a/fs/ioprio.c b/fs/ioprio.c
index 748cfb92dcc6..7da2a06508e5 100644
--- a/fs/ioprio.c
+++ b/fs/ioprio.c
@@ -103,12 +103,7 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
103 } 103 }
104 104
105 ret = -ESRCH; 105 ret = -ESRCH;
106 /* 106 rcu_read_lock();
107 * We want IOPRIO_WHO_PGRP/IOPRIO_WHO_USER to be "atomic",
108 * so we can't use rcu_read_lock(). See re-copy of ->ioprio
109 * in copy_process().
110 */
111 read_lock(&tasklist_lock);
112 switch (which) { 107 switch (which) {
113 case IOPRIO_WHO_PROCESS: 108 case IOPRIO_WHO_PROCESS:
114 if (!who) 109 if (!who)
@@ -153,7 +148,7 @@ free_uid:
153 ret = -EINVAL; 148 ret = -EINVAL;
154 } 149 }
155 150
156 read_unlock(&tasklist_lock); 151 rcu_read_unlock();
157 return ret; 152 return ret;
158} 153}
159 154
@@ -197,7 +192,7 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
197 int ret = -ESRCH; 192 int ret = -ESRCH;
198 int tmpio; 193 int tmpio;
199 194
200 read_lock(&tasklist_lock); 195 rcu_read_lock();
201 switch (which) { 196 switch (which) {
202 case IOPRIO_WHO_PROCESS: 197 case IOPRIO_WHO_PROCESS:
203 if (!who) 198 if (!who)
@@ -250,6 +245,6 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
250 ret = -EINVAL; 245 ret = -EINVAL;
251 } 246 }
252 247
253 read_unlock(&tasklist_lock); 248 rcu_read_unlock();
254 return ret; 249 return ret;
255} 250}
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 538417c1fdbb..f837ba953529 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -899,6 +899,14 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
899 899
900 /* journal descriptor can store up to n blocks -bzzz */ 900 /* journal descriptor can store up to n blocks -bzzz */
901 journal->j_blocksize = blocksize; 901 journal->j_blocksize = blocksize;
902 journal->j_dev = bdev;
903 journal->j_fs_dev = fs_dev;
904 journal->j_blk_offset = start;
905 journal->j_maxlen = len;
906 bdevname(journal->j_dev, journal->j_devname);
907 p = journal->j_devname;
908 while ((p = strchr(p, '/')))
909 *p = '!';
902 jbd2_stats_proc_init(journal); 910 jbd2_stats_proc_init(journal);
903 n = journal->j_blocksize / sizeof(journal_block_tag_t); 911 n = journal->j_blocksize / sizeof(journal_block_tag_t);
904 journal->j_wbufsize = n; 912 journal->j_wbufsize = n;
@@ -908,14 +916,6 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
908 __func__); 916 __func__);
909 goto out_err; 917 goto out_err;
910 } 918 }
911 journal->j_dev = bdev;
912 journal->j_fs_dev = fs_dev;
913 journal->j_blk_offset = start;
914 journal->j_maxlen = len;
915 bdevname(journal->j_dev, journal->j_devname);
916 p = journal->j_devname;
917 while ((p = strchr(p, '/')))
918 *p = '!';
919 919
920 bh = __getblk(journal->j_dev, start, journal->j_blocksize); 920 bh = __getblk(journal->j_dev, start, journal->j_blocksize);
921 if (!bh) { 921 if (!bh) {
@@ -1838,7 +1838,6 @@ size_t journal_tag_bytes(journal_t *journal)
1838 */ 1838 */
1839#define JBD2_MAX_SLABS 8 1839#define JBD2_MAX_SLABS 8
1840static struct kmem_cache *jbd2_slab[JBD2_MAX_SLABS]; 1840static struct kmem_cache *jbd2_slab[JBD2_MAX_SLABS];
1841static DECLARE_MUTEX(jbd2_slab_create_sem);
1842 1841
1843static const char *jbd2_slab_names[JBD2_MAX_SLABS] = { 1842static const char *jbd2_slab_names[JBD2_MAX_SLABS] = {
1844 "jbd2_1k", "jbd2_2k", "jbd2_4k", "jbd2_8k", 1843 "jbd2_1k", "jbd2_2k", "jbd2_4k", "jbd2_8k",
@@ -1859,6 +1858,7 @@ static void jbd2_journal_destroy_slabs(void)
1859 1858
1860static int jbd2_journal_create_slab(size_t size) 1859static int jbd2_journal_create_slab(size_t size)
1861{ 1860{
1861 static DEFINE_MUTEX(jbd2_slab_create_mutex);
1862 int i = order_base_2(size) - 10; 1862 int i = order_base_2(size) - 10;
1863 size_t slab_size; 1863 size_t slab_size;
1864 1864
@@ -1870,16 +1870,16 @@ static int jbd2_journal_create_slab(size_t size)
1870 1870
1871 if (unlikely(i < 0)) 1871 if (unlikely(i < 0))
1872 i = 0; 1872 i = 0;
1873 down(&jbd2_slab_create_sem); 1873 mutex_lock(&jbd2_slab_create_mutex);
1874 if (jbd2_slab[i]) { 1874 if (jbd2_slab[i]) {
1875 up(&jbd2_slab_create_sem); 1875 mutex_unlock(&jbd2_slab_create_mutex);
1876 return 0; /* Already created */ 1876 return 0; /* Already created */
1877 } 1877 }
1878 1878
1879 slab_size = 1 << (i+10); 1879 slab_size = 1 << (i+10);
1880 jbd2_slab[i] = kmem_cache_create(jbd2_slab_names[i], slab_size, 1880 jbd2_slab[i] = kmem_cache_create(jbd2_slab_names[i], slab_size,
1881 slab_size, 0, NULL); 1881 slab_size, 0, NULL);
1882 up(&jbd2_slab_create_sem); 1882 mutex_unlock(&jbd2_slab_create_mutex);
1883 if (!jbd2_slab[i]) { 1883 if (!jbd2_slab[i]) {
1884 printk(KERN_EMERG "JBD2: no memory for jbd2_slab cache\n"); 1884 printk(KERN_EMERG "JBD2: no memory for jbd2_slab cache\n");
1885 return -ENOMEM; 1885 return -ENOMEM;
diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c
index d5bb86866e6c..25509eb28fd7 100644
--- a/fs/lockd/clntlock.c
+++ b/fs/lockd/clntlock.c
@@ -14,7 +14,6 @@
14#include <linux/sunrpc/clnt.h> 14#include <linux/sunrpc/clnt.h>
15#include <linux/sunrpc/svc.h> 15#include <linux/sunrpc/svc.h>
16#include <linux/lockd/lockd.h> 16#include <linux/lockd/lockd.h>
17#include <linux/smp_lock.h>
18#include <linux/kthread.h> 17#include <linux/kthread.h>
19 18
20#define NLMDBG_FACILITY NLMDBG_CLIENT 19#define NLMDBG_FACILITY NLMDBG_CLIENT
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index 47ea1e1925b8..332c54cf75e0 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -7,7 +7,6 @@
7 */ 7 */
8 8
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/smp_lock.h>
11#include <linux/slab.h> 10#include <linux/slab.h>
12#include <linux/types.h> 11#include <linux/types.h>
13#include <linux/errno.h> 12#include <linux/errno.h>
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 25e21e4023b2..ed0c59fe23ce 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -124,7 +124,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
124 continue; 124 continue;
125 if (host->h_server != ni->server) 125 if (host->h_server != ni->server)
126 continue; 126 continue;
127 if (ni->server && 127 if (ni->server && ni->src_len != 0 &&
128 !rpc_cmp_addr(nlm_srcaddr(host), ni->src_sap)) 128 !rpc_cmp_addr(nlm_srcaddr(host), ni->src_sap))
129 continue; 129 continue;
130 130
@@ -167,6 +167,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
167 host->h_addrlen = ni->salen; 167 host->h_addrlen = ni->salen;
168 rpc_set_port(nlm_addr(host), 0); 168 rpc_set_port(nlm_addr(host), 0);
169 memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); 169 memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len);
170 host->h_srcaddrlen = ni->src_len;
170 host->h_version = ni->version; 171 host->h_version = ni->version;
171 host->h_proto = ni->protocol; 172 host->h_proto = ni->protocol;
172 host->h_rpcclnt = NULL; 173 host->h_rpcclnt = NULL;
@@ -238,9 +239,6 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
238 const char *hostname, 239 const char *hostname,
239 int noresvport) 240 int noresvport)
240{ 241{
241 const struct sockaddr source = {
242 .sa_family = AF_UNSPEC,
243 };
244 struct nlm_lookup_host_info ni = { 242 struct nlm_lookup_host_info ni = {
245 .server = 0, 243 .server = 0,
246 .sap = sap, 244 .sap = sap,
@@ -249,8 +247,6 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
249 .version = version, 247 .version = version,
250 .hostname = hostname, 248 .hostname = hostname,
251 .hostname_len = strlen(hostname), 249 .hostname_len = strlen(hostname),
252 .src_sap = &source,
253 .src_len = sizeof(source),
254 .noresvport = noresvport, 250 .noresvport = noresvport,
255 }; 251 };
256 252
@@ -357,7 +353,6 @@ nlm_bind_host(struct nlm_host *host)
357 .protocol = host->h_proto, 353 .protocol = host->h_proto,
358 .address = nlm_addr(host), 354 .address = nlm_addr(host),
359 .addrsize = host->h_addrlen, 355 .addrsize = host->h_addrlen,
360 .saddress = nlm_srcaddr(host),
361 .timeout = &timeparms, 356 .timeout = &timeparms,
362 .servername = host->h_name, 357 .servername = host->h_name,
363 .program = &nlm_program, 358 .program = &nlm_program,
@@ -376,6 +371,8 @@ nlm_bind_host(struct nlm_host *host)
376 args.flags |= RPC_CLNT_CREATE_HARDRTRY; 371 args.flags |= RPC_CLNT_CREATE_HARDRTRY;
377 if (host->h_noresvport) 372 if (host->h_noresvport)
378 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; 373 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
374 if (host->h_srcaddrlen)
375 args.saddress = nlm_srcaddr(host);
379 376
380 clnt = rpc_create(&args); 377 clnt = rpc_create(&args);
381 if (!IS_ERR(clnt)) 378 if (!IS_ERR(clnt))
diff --git a/fs/lockd/svc4proc.c b/fs/lockd/svc4proc.c
index a336e832475d..38d261192453 100644
--- a/fs/lockd/svc4proc.c
+++ b/fs/lockd/svc4proc.c
@@ -9,7 +9,6 @@
9 9
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/time.h> 11#include <linux/time.h>
12#include <linux/smp_lock.h>
13#include <linux/lockd/lockd.h> 12#include <linux/lockd/lockd.h>
14#include <linux/lockd/share.h> 13#include <linux/lockd/share.h>
15 14
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index c462d346acbd..ef5659b211e9 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -25,7 +25,6 @@
25#include <linux/errno.h> 25#include <linux/errno.h>
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/smp_lock.h>
29#include <linux/sunrpc/clnt.h> 28#include <linux/sunrpc/clnt.h>
30#include <linux/sunrpc/svc.h> 29#include <linux/sunrpc/svc.h>
31#include <linux/lockd/nlm.h> 30#include <linux/lockd/nlm.h>
diff --git a/fs/lockd/svcproc.c b/fs/lockd/svcproc.c
index c3069f38d602..0caea5310ac3 100644
--- a/fs/lockd/svcproc.c
+++ b/fs/lockd/svcproc.c
@@ -9,7 +9,6 @@
9 9
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/time.h> 11#include <linux/time.h>
12#include <linux/smp_lock.h>
13#include <linux/lockd/lockd.h> 12#include <linux/lockd/lockd.h>
14#include <linux/lockd/share.h> 13#include <linux/lockd/share.h>
15 14
diff --git a/fs/locks.c b/fs/locks.c
index 50ec15927aab..8729347bcd1a 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -122,7 +122,6 @@
122#include <linux/module.h> 122#include <linux/module.h>
123#include <linux/security.h> 123#include <linux/security.h>
124#include <linux/slab.h> 124#include <linux/slab.h>
125#include <linux/smp_lock.h>
126#include <linux/syscalls.h> 125#include <linux/syscalls.h>
127#include <linux/time.h> 126#include <linux/time.h>
128#include <linux/rcupdate.h> 127#include <linux/rcupdate.h>
@@ -186,7 +185,7 @@ void locks_release_private(struct file_lock *fl)
186EXPORT_SYMBOL_GPL(locks_release_private); 185EXPORT_SYMBOL_GPL(locks_release_private);
187 186
188/* Free a lock which is not in use. */ 187/* Free a lock which is not in use. */
189static void locks_free_lock(struct file_lock *fl) 188void locks_free_lock(struct file_lock *fl)
190{ 189{
191 BUG_ON(waitqueue_active(&fl->fl_wait)); 190 BUG_ON(waitqueue_active(&fl->fl_wait));
192 BUG_ON(!list_empty(&fl->fl_block)); 191 BUG_ON(!list_empty(&fl->fl_block));
@@ -195,6 +194,7 @@ static void locks_free_lock(struct file_lock *fl)
195 locks_release_private(fl); 194 locks_release_private(fl);
196 kmem_cache_free(filelock_cache, fl); 195 kmem_cache_free(filelock_cache, fl);
197} 196}
197EXPORT_SYMBOL(locks_free_lock);
198 198
199void locks_init_lock(struct file_lock *fl) 199void locks_init_lock(struct file_lock *fl)
200{ 200{
@@ -234,11 +234,8 @@ static void locks_copy_private(struct file_lock *new, struct file_lock *fl)
234 fl->fl_ops->fl_copy_lock(new, fl); 234 fl->fl_ops->fl_copy_lock(new, fl);
235 new->fl_ops = fl->fl_ops; 235 new->fl_ops = fl->fl_ops;
236 } 236 }
237 if (fl->fl_lmops) { 237 if (fl->fl_lmops)
238 if (fl->fl_lmops->fl_copy_lock)
239 fl->fl_lmops->fl_copy_lock(new, fl);
240 new->fl_lmops = fl->fl_lmops; 238 new->fl_lmops = fl->fl_lmops;
241 }
242} 239}
243 240
244/* 241/*
@@ -1371,20 +1368,22 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1371 struct inode *inode = dentry->d_inode; 1368 struct inode *inode = dentry->d_inode;
1372 int error, rdlease_count = 0, wrlease_count = 0; 1369 int error, rdlease_count = 0, wrlease_count = 0;
1373 1370
1371 lease = *flp;
1372
1373 error = -EACCES;
1374 if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE)) 1374 if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE))
1375 return -EACCES; 1375 goto out;
1376 error = -EINVAL;
1376 if (!S_ISREG(inode->i_mode)) 1377 if (!S_ISREG(inode->i_mode))
1377 return -EINVAL; 1378 goto out;
1378 error = security_file_lock(filp, arg); 1379 error = security_file_lock(filp, arg);
1379 if (error) 1380 if (error)
1380 return error; 1381 goto out;
1381 1382
1382 time_out_leases(inode); 1383 time_out_leases(inode);
1383 1384
1384 BUG_ON(!(*flp)->fl_lmops->fl_break); 1385 BUG_ON(!(*flp)->fl_lmops->fl_break);
1385 1386
1386 lease = *flp;
1387
1388 if (arg != F_UNLCK) { 1387 if (arg != F_UNLCK) {
1389 error = -EAGAIN; 1388 error = -EAGAIN;
1390 if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0)) 1389 if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0))
@@ -1425,8 +1424,9 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1425 goto out; 1424 goto out;
1426 1425
1427 if (my_before != NULL) { 1426 if (my_before != NULL) {
1428 *flp = *my_before;
1429 error = lease->fl_lmops->fl_change(my_before, arg); 1427 error = lease->fl_lmops->fl_change(my_before, arg);
1428 if (!error)
1429 *flp = *my_before;
1430 goto out; 1430 goto out;
1431 } 1431 }
1432 1432
@@ -1441,7 +1441,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1441 return 0; 1441 return 0;
1442 1442
1443out: 1443out:
1444 locks_free_lock(lease);
1445 return error; 1444 return error;
1446} 1445}
1447EXPORT_SYMBOL(generic_setlease); 1446EXPORT_SYMBOL(generic_setlease);
@@ -1493,21 +1492,19 @@ int vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
1493} 1492}
1494EXPORT_SYMBOL_GPL(vfs_setlease); 1493EXPORT_SYMBOL_GPL(vfs_setlease);
1495 1494
1496/** 1495static int do_fcntl_delete_lease(struct file *filp)
1497 * fcntl_setlease - sets a lease on an open file
1498 * @fd: open file descriptor
1499 * @filp: file pointer
1500 * @arg: type of lease to obtain
1501 *
1502 * Call this fcntl to establish a lease on the file.
1503 * Note that you also need to call %F_SETSIG to
1504 * receive a signal when the lease is broken.
1505 */
1506int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
1507{ 1496{
1508 struct file_lock *fl; 1497 struct file_lock fl, *flp = &fl;
1498
1499 lease_init(filp, F_UNLCK, flp);
1500
1501 return vfs_setlease(filp, F_UNLCK, &flp);
1502}
1503
1504static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
1505{
1506 struct file_lock *fl, *ret;
1509 struct fasync_struct *new; 1507 struct fasync_struct *new;
1510 struct inode *inode = filp->f_path.dentry->d_inode;
1511 int error; 1508 int error;
1512 1509
1513 fl = lease_alloc(filp, arg); 1510 fl = lease_alloc(filp, arg);
@@ -1519,10 +1516,16 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
1519 locks_free_lock(fl); 1516 locks_free_lock(fl);
1520 return -ENOMEM; 1517 return -ENOMEM;
1521 } 1518 }
1519 ret = fl;
1522 lock_flocks(); 1520 lock_flocks();
1523 error = __vfs_setlease(filp, arg, &fl); 1521 error = __vfs_setlease(filp, arg, &ret);
1524 if (error || arg == F_UNLCK) 1522 if (error) {
1525 goto out_unlock; 1523 unlock_flocks();
1524 locks_free_lock(fl);
1525 goto out_free_fasync;
1526 }
1527 if (ret != fl)
1528 locks_free_lock(fl);
1526 1529
1527 /* 1530 /*
1528 * fasync_insert_entry() returns the old entry if any. 1531 * fasync_insert_entry() returns the old entry if any.
@@ -1530,26 +1533,36 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
1530 * inserted it into the fasync list. Clear new so that 1533 * inserted it into the fasync list. Clear new so that
1531 * we don't release it here. 1534 * we don't release it here.
1532 */ 1535 */
1533 if (!fasync_insert_entry(fd, filp, &fl->fl_fasync, new)) 1536 if (!fasync_insert_entry(fd, filp, &ret->fl_fasync, new))
1534 new = NULL; 1537 new = NULL;
1535 1538
1536 if (error < 0) {
1537 /* remove lease just inserted by setlease */
1538 fl->fl_type = F_UNLCK | F_INPROGRESS;
1539 fl->fl_break_time = jiffies - 10;
1540 time_out_leases(inode);
1541 goto out_unlock;
1542 }
1543
1544 error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); 1539 error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
1545out_unlock:
1546 unlock_flocks(); 1540 unlock_flocks();
1541
1542out_free_fasync:
1547 if (new) 1543 if (new)
1548 fasync_free(new); 1544 fasync_free(new);
1549 return error; 1545 return error;
1550} 1546}
1551 1547
1552/** 1548/**
1549 * fcntl_setlease - sets a lease on an open file
1550 * @fd: open file descriptor
1551 * @filp: file pointer
1552 * @arg: type of lease to obtain
1553 *
1554 * Call this fcntl to establish a lease on the file.
1555 * Note that you also need to call %F_SETSIG to
1556 * receive a signal when the lease is broken.
1557 */
1558int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
1559{
1560 if (arg == F_UNLCK)
1561 return do_fcntl_delete_lease(filp);
1562 return do_fcntl_add_lease(fd, filp, arg);
1563}
1564
1565/**
1553 * flock_lock_file_wait - Apply a FLOCK-style lock to a file 1566 * flock_lock_file_wait - Apply a FLOCK-style lock to a file
1554 * @filp: The file to apply the lock to 1567 * @filp: The file to apply the lock to
1555 * @fl: The lock to be applied 1568 * @fl: The lock to be applied
diff --git a/fs/logfs/logfs.h b/fs/logfs/logfs.h
index cd51a36b37f0..57afd4a6fabb 100644
--- a/fs/logfs/logfs.h
+++ b/fs/logfs/logfs.h
@@ -486,7 +486,7 @@ static inline int logfs_get_sb_bdev(struct logfs_super *s,
486 486
487/* dev_mtd.c */ 487/* dev_mtd.c */
488#ifdef CONFIG_MTD 488#ifdef CONFIG_MTD
489int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr) 489int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr);
490#else 490#else
491static inline int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr) 491static inline int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr)
492{ 492{
diff --git a/fs/namei.c b/fs/namei.c
index 5362af9b7372..4ff7ca530533 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1748,6 +1748,9 @@ struct file *do_filp_open(int dfd, const char *pathname,
1748 if (!(open_flag & O_CREAT)) 1748 if (!(open_flag & O_CREAT))
1749 mode = 0; 1749 mode = 0;
1750 1750
1751 /* Must never be set by userspace */
1752 open_flag &= ~FMODE_NONOTIFY;
1753
1751 /* 1754 /*
1752 * O_SYNC is implemented as __O_SYNC|O_DSYNC. As many places only 1755 * O_SYNC is implemented as __O_SYNC|O_DSYNC. As many places only
1753 * check for O_DSYNC if the need any syncing at all we enforce it's 1756 * check for O_DSYNC if the need any syncing at all we enforce it's
diff --git a/fs/namespace.c b/fs/namespace.c
index 8a415c9c5e55..3dbfc072ec70 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -13,7 +13,6 @@
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <linux/spinlock.h> 14#include <linux/spinlock.h>
15#include <linux/percpu.h> 15#include <linux/percpu.h>
16#include <linux/smp_lock.h>
17#include <linux/init.h> 16#include <linux/init.h>
18#include <linux/kernel.h> 17#include <linux/kernel.h>
19#include <linux/acct.h> 18#include <linux/acct.h>
diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
index aac8832e919e..f22b12e7d337 100644
--- a/fs/ncpfs/dir.c
+++ b/fs/ncpfs/dir.c
@@ -19,7 +19,6 @@
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <asm/uaccess.h> 20#include <asm/uaccess.h>
21#include <asm/byteorder.h> 21#include <asm/byteorder.h>
22#include <linux/smp_lock.h>
23 22
24#include <linux/ncp_fs.h> 23#include <linux/ncp_fs.h>
25 24
diff --git a/fs/ncpfs/file.c b/fs/ncpfs/file.c
index 6c754f70c529..cb50aaf981df 100644
--- a/fs/ncpfs/file.c
+++ b/fs/ncpfs/file.c
@@ -17,7 +17,6 @@
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/smp_lock.h>
21 20
22#include <linux/ncp_fs.h> 21#include <linux/ncp_fs.h>
23#include "ncplib_kernel.h" 22#include "ncplib_kernel.h"
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index d290545aa0c4..8fb93b604e73 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.c
@@ -26,7 +26,6 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/smp_lock.h>
30#include <linux/vfs.h> 29#include <linux/vfs.h>
31#include <linux/mount.h> 30#include <linux/mount.h>
32#include <linux/seq_file.h> 31#include <linux/seq_file.h>
diff --git a/fs/ncpfs/ioctl.c b/fs/ncpfs/ioctl.c
index c2a1f9a155c3..d40a547e3377 100644
--- a/fs/ncpfs/ioctl.c
+++ b/fs/ncpfs/ioctl.c
@@ -17,7 +17,6 @@
17#include <linux/mount.h> 17#include <linux/mount.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/highuid.h> 19#include <linux/highuid.h>
20#include <linux/smp_lock.h>
21#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
22#include <linux/sched.h> 21#include <linux/sched.h>
23 22
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index aeec017fe814..93a8b3bd69e3 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -9,7 +9,6 @@
9#include <linux/completion.h> 9#include <linux/completion.h>
10#include <linux/ip.h> 10#include <linux/ip.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/smp_lock.h>
13#include <linux/sunrpc/svc.h> 12#include <linux/sunrpc/svc.h>
14#include <linux/sunrpc/svcsock.h> 13#include <linux/sunrpc/svcsock.h>
15#include <linux/nfs_fs.h> 14#include <linux/nfs_fs.h>
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 232a7eead33a..1fd62fc49be3 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -11,7 +11,6 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/smp_lock.h>
15#include <linux/spinlock.h> 14#include <linux/spinlock.h>
16 15
17#include <linux/nfs4.h> 16#include <linux/nfs4.h>
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 07ac3847e562..996dd8989a91 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -34,6 +34,7 @@
34#include <linux/mount.h> 34#include <linux/mount.h>
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
37#include <linux/kmemleak.h>
37 38
38#include "delegation.h" 39#include "delegation.h"
39#include "iostat.h" 40#include "iostat.h"
@@ -56,7 +57,7 @@ static int nfs_rename(struct inode *, struct dentry *,
56 struct inode *, struct dentry *); 57 struct inode *, struct dentry *);
57static int nfs_fsync_dir(struct file *, int); 58static int nfs_fsync_dir(struct file *, int);
58static loff_t nfs_llseek_dir(struct file *, loff_t, int); 59static loff_t nfs_llseek_dir(struct file *, loff_t, int);
59static int nfs_readdir_clear_array(struct page*, gfp_t); 60static void nfs_readdir_clear_array(struct page*);
60 61
61const struct file_operations nfs_dir_operations = { 62const struct file_operations nfs_dir_operations = {
62 .llseek = nfs_llseek_dir, 63 .llseek = nfs_llseek_dir,
@@ -82,8 +83,8 @@ const struct inode_operations nfs_dir_inode_operations = {
82 .setattr = nfs_setattr, 83 .setattr = nfs_setattr,
83}; 84};
84 85
85const struct address_space_operations nfs_dir_addr_space_ops = { 86const struct address_space_operations nfs_dir_aops = {
86 .releasepage = nfs_readdir_clear_array, 87 .freepage = nfs_readdir_clear_array,
87}; 88};
88 89
89#ifdef CONFIG_NFS_V3 90#ifdef CONFIG_NFS_V3
@@ -161,6 +162,7 @@ struct nfs_cache_array_entry {
161 u64 cookie; 162 u64 cookie;
162 u64 ino; 163 u64 ino;
163 struct qstr string; 164 struct qstr string;
165 unsigned char d_type;
164}; 166};
165 167
166struct nfs_cache_array { 168struct nfs_cache_array {
@@ -170,14 +172,13 @@ struct nfs_cache_array {
170 struct nfs_cache_array_entry array[0]; 172 struct nfs_cache_array_entry array[0];
171}; 173};
172 174
173#define MAX_READDIR_ARRAY ((PAGE_SIZE - sizeof(struct nfs_cache_array)) / sizeof(struct nfs_cache_array_entry))
174
175typedef __be32 * (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int); 175typedef __be32 * (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int);
176typedef struct { 176typedef struct {
177 struct file *file; 177 struct file *file;
178 struct page *page; 178 struct page *page;
179 unsigned long page_index; 179 unsigned long page_index;
180 u64 *dir_cookie; 180 u64 *dir_cookie;
181 u64 last_cookie;
181 loff_t current_index; 182 loff_t current_index;
182 decode_dirent_t decode; 183 decode_dirent_t decode;
183 184
@@ -194,9 +195,13 @@ typedef struct {
194static 195static
195struct nfs_cache_array *nfs_readdir_get_array(struct page *page) 196struct nfs_cache_array *nfs_readdir_get_array(struct page *page)
196{ 197{
198 void *ptr;
197 if (page == NULL) 199 if (page == NULL)
198 return ERR_PTR(-EIO); 200 return ERR_PTR(-EIO);
199 return (struct nfs_cache_array *)kmap(page); 201 ptr = kmap(page);
202 if (ptr == NULL)
203 return ERR_PTR(-ENOMEM);
204 return ptr;
200} 205}
201 206
202static 207static
@@ -209,14 +214,15 @@ void nfs_readdir_release_array(struct page *page)
209 * we are freeing strings created by nfs_add_to_readdir_array() 214 * we are freeing strings created by nfs_add_to_readdir_array()
210 */ 215 */
211static 216static
212int nfs_readdir_clear_array(struct page *page, gfp_t mask) 217void nfs_readdir_clear_array(struct page *page)
213{ 218{
214 struct nfs_cache_array *array = nfs_readdir_get_array(page); 219 struct nfs_cache_array *array;
215 int i; 220 int i;
221
222 array = kmap_atomic(page, KM_USER0);
216 for (i = 0; i < array->size; i++) 223 for (i = 0; i < array->size; i++)
217 kfree(array->array[i].string.name); 224 kfree(array->array[i].string.name);
218 nfs_readdir_release_array(page); 225 kunmap_atomic(array, KM_USER0);
219 return 0;
220} 226}
221 227
222/* 228/*
@@ -231,6 +237,11 @@ int nfs_readdir_make_qstr(struct qstr *string, const char *name, unsigned int le
231 string->name = kmemdup(name, len, GFP_KERNEL); 237 string->name = kmemdup(name, len, GFP_KERNEL);
232 if (string->name == NULL) 238 if (string->name == NULL)
233 return -ENOMEM; 239 return -ENOMEM;
240 /*
241 * Avoid a kmemleak false positive. The pointer to the name is stored
242 * in a page cache page which kmemleak does not scan.
243 */
244 kmemleak_not_leak(string->name);
234 string->hash = full_name_hash(name, len); 245 string->hash = full_name_hash(name, len);
235 return 0; 246 return 0;
236} 247}
@@ -244,20 +255,24 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
244 255
245 if (IS_ERR(array)) 256 if (IS_ERR(array))
246 return PTR_ERR(array); 257 return PTR_ERR(array);
247 ret = -EIO;
248 if (array->size >= MAX_READDIR_ARRAY)
249 goto out;
250 258
251 cache_entry = &array->array[array->size]; 259 cache_entry = &array->array[array->size];
260
261 /* Check that this entry lies within the page bounds */
262 ret = -ENOSPC;
263 if ((char *)&cache_entry[1] - (char *)page_address(page) > PAGE_SIZE)
264 goto out;
265
252 cache_entry->cookie = entry->prev_cookie; 266 cache_entry->cookie = entry->prev_cookie;
253 cache_entry->ino = entry->ino; 267 cache_entry->ino = entry->ino;
268 cache_entry->d_type = entry->d_type;
254 ret = nfs_readdir_make_qstr(&cache_entry->string, entry->name, entry->len); 269 ret = nfs_readdir_make_qstr(&cache_entry->string, entry->name, entry->len);
255 if (ret) 270 if (ret)
256 goto out; 271 goto out;
257 array->last_cookie = entry->cookie; 272 array->last_cookie = entry->cookie;
258 if (entry->eof == 1)
259 array->eof_index = array->size;
260 array->size++; 273 array->size++;
274 if (entry->eof != 0)
275 array->eof_index = array->size;
261out: 276out:
262 nfs_readdir_release_array(page); 277 nfs_readdir_release_array(page);
263 return ret; 278 return ret;
@@ -272,7 +287,7 @@ int nfs_readdir_search_for_pos(struct nfs_cache_array *array, nfs_readdir_descri
272 if (diff < 0) 287 if (diff < 0)
273 goto out_eof; 288 goto out_eof;
274 if (diff >= array->size) { 289 if (diff >= array->size) {
275 if (array->eof_index > 0) 290 if (array->eof_index >= 0)
276 goto out_eof; 291 goto out_eof;
277 desc->current_index += array->size; 292 desc->current_index += array->size;
278 return -EAGAIN; 293 return -EAGAIN;
@@ -281,8 +296,6 @@ int nfs_readdir_search_for_pos(struct nfs_cache_array *array, nfs_readdir_descri
281 index = (unsigned int)diff; 296 index = (unsigned int)diff;
282 *desc->dir_cookie = array->array[index].cookie; 297 *desc->dir_cookie = array->array[index].cookie;
283 desc->cache_entry_index = index; 298 desc->cache_entry_index = index;
284 if (index == array->eof_index)
285 desc->eof = 1;
286 return 0; 299 return 0;
287out_eof: 300out_eof:
288 desc->eof = 1; 301 desc->eof = 1;
@@ -296,17 +309,16 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des
296 int status = -EAGAIN; 309 int status = -EAGAIN;
297 310
298 for (i = 0; i < array->size; i++) { 311 for (i = 0; i < array->size; i++) {
299 if (i == array->eof_index) {
300 desc->eof = 1;
301 status = -EBADCOOKIE;
302 }
303 if (array->array[i].cookie == *desc->dir_cookie) { 312 if (array->array[i].cookie == *desc->dir_cookie) {
304 desc->cache_entry_index = i; 313 desc->cache_entry_index = i;
305 status = 0; 314 return 0;
306 break;
307 } 315 }
308 } 316 }
309 317 if (array->eof_index >= 0) {
318 status = -EBADCOOKIE;
319 if (*desc->dir_cookie == array->last_cookie)
320 desc->eof = 1;
321 }
310 return status; 322 return status;
311} 323}
312 324
@@ -314,10 +326,7 @@ static
314int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc) 326int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc)
315{ 327{
316 struct nfs_cache_array *array; 328 struct nfs_cache_array *array;
317 int status = -EBADCOOKIE; 329 int status;
318
319 if (desc->dir_cookie == NULL)
320 goto out;
321 330
322 array = nfs_readdir_get_array(desc->page); 331 array = nfs_readdir_get_array(desc->page);
323 if (IS_ERR(array)) { 332 if (IS_ERR(array)) {
@@ -330,6 +339,10 @@ int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc)
330 else 339 else
331 status = nfs_readdir_search_for_cookie(array, desc); 340 status = nfs_readdir_search_for_cookie(array, desc);
332 341
342 if (status == -EAGAIN) {
343 desc->last_cookie = array->last_cookie;
344 desc->page_index++;
345 }
333 nfs_readdir_release_array(desc->page); 346 nfs_readdir_release_array(desc->page);
334out: 347out:
335 return status; 348 return status;
@@ -381,13 +394,9 @@ int xdr_decode(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, struct x
381static 394static
382int nfs_same_file(struct dentry *dentry, struct nfs_entry *entry) 395int nfs_same_file(struct dentry *dentry, struct nfs_entry *entry)
383{ 396{
384 struct nfs_inode *node;
385 if (dentry->d_inode == NULL) 397 if (dentry->d_inode == NULL)
386 goto different; 398 goto different;
387 node = NFS_I(dentry->d_inode); 399 if (nfs_compare_fh(entry->fh, NFS_FH(dentry->d_inode)) != 0)
388 if (node->fh.size != entry->fh->size)
389 goto different;
390 if (strncmp(node->fh.data, entry->fh->data, node->fh.size) != 0)
391 goto different; 400 goto different;
392 return 1; 401 return 1;
393different: 402different:
@@ -449,14 +458,15 @@ out:
449 458
450/* Perform conversion from xdr to cache array */ 459/* Perform conversion from xdr to cache array */
451static 460static
452void nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, 461int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry,
453 void *xdr_page, struct page *page, unsigned int buflen) 462 void *xdr_page, struct page *page, unsigned int buflen)
454{ 463{
455 struct xdr_stream stream; 464 struct xdr_stream stream;
456 struct xdr_buf buf; 465 struct xdr_buf buf;
457 __be32 *ptr = xdr_page; 466 __be32 *ptr = xdr_page;
458 int status;
459 struct nfs_cache_array *array; 467 struct nfs_cache_array *array;
468 unsigned int count = 0;
469 int status;
460 470
461 buf.head->iov_base = xdr_page; 471 buf.head->iov_base = xdr_page;
462 buf.head->iov_len = buflen; 472 buf.head->iov_len = buflen;
@@ -471,21 +481,32 @@ void nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *e
471 481
472 do { 482 do {
473 status = xdr_decode(desc, entry, &stream); 483 status = xdr_decode(desc, entry, &stream);
474 if (status != 0) 484 if (status != 0) {
485 if (status == -EAGAIN)
486 status = 0;
475 break; 487 break;
488 }
476 489
477 if (nfs_readdir_add_to_array(entry, page) == -1) 490 count++;
478 break; 491
479 if (desc->plus == 1) 492 if (desc->plus != 0)
480 nfs_prime_dcache(desc->file->f_path.dentry, entry); 493 nfs_prime_dcache(desc->file->f_path.dentry, entry);
494
495 status = nfs_readdir_add_to_array(entry, page);
496 if (status != 0)
497 break;
481 } while (!entry->eof); 498 } while (!entry->eof);
482 499
483 if (status == -EBADCOOKIE && entry->eof) { 500 if (count == 0 || (status == -EBADCOOKIE && entry->eof != 0)) {
484 array = nfs_readdir_get_array(page); 501 array = nfs_readdir_get_array(page);
485 array->eof_index = array->size - 1; 502 if (!IS_ERR(array)) {
486 status = 0; 503 array->eof_index = array->size;
487 nfs_readdir_release_array(page); 504 status = 0;
505 nfs_readdir_release_array(page);
506 } else
507 status = PTR_ERR(array);
488 } 508 }
509 return status;
489} 510}
490 511
491static 512static
@@ -537,11 +558,11 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
537 struct nfs_entry entry; 558 struct nfs_entry entry;
538 struct file *file = desc->file; 559 struct file *file = desc->file;
539 struct nfs_cache_array *array; 560 struct nfs_cache_array *array;
540 int status = 0; 561 int status = -ENOMEM;
541 unsigned int array_size = ARRAY_SIZE(pages); 562 unsigned int array_size = ARRAY_SIZE(pages);
542 563
543 entry.prev_cookie = 0; 564 entry.prev_cookie = 0;
544 entry.cookie = *desc->dir_cookie; 565 entry.cookie = desc->last_cookie;
545 entry.eof = 0; 566 entry.eof = 0;
546 entry.fh = nfs_alloc_fhandle(); 567 entry.fh = nfs_alloc_fhandle();
547 entry.fattr = nfs_alloc_fattr(); 568 entry.fattr = nfs_alloc_fattr();
@@ -549,6 +570,10 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
549 goto out; 570 goto out;
550 571
551 array = nfs_readdir_get_array(page); 572 array = nfs_readdir_get_array(page);
573 if (IS_ERR(array)) {
574 status = PTR_ERR(array);
575 goto out;
576 }
552 memset(array, 0, sizeof(struct nfs_cache_array)); 577 memset(array, 0, sizeof(struct nfs_cache_array));
553 array->eof_index = -1; 578 array->eof_index = -1;
554 579
@@ -556,12 +581,19 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
556 if (!pages_ptr) 581 if (!pages_ptr)
557 goto out_release_array; 582 goto out_release_array;
558 do { 583 do {
584 unsigned int pglen;
559 status = nfs_readdir_xdr_filler(pages, desc, &entry, file, inode); 585 status = nfs_readdir_xdr_filler(pages, desc, &entry, file, inode);
560 586
561 if (status < 0) 587 if (status < 0)
562 break; 588 break;
563 nfs_readdir_page_filler(desc, &entry, pages_ptr, page, array_size * PAGE_SIZE); 589 pglen = status;
564 } while (array->eof_index < 0 && array->size < MAX_READDIR_ARRAY); 590 status = nfs_readdir_page_filler(desc, &entry, pages_ptr, page, pglen);
591 if (status < 0) {
592 if (status == -ENOSPC)
593 status = 0;
594 break;
595 }
596 } while (array->eof_index < 0);
565 597
566 nfs_readdir_free_large_page(pages_ptr, pages, array_size); 598 nfs_readdir_free_large_page(pages_ptr, pages, array_size);
567out_release_array: 599out_release_array:
@@ -582,8 +614,10 @@ static
582int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page) 614int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page)
583{ 615{
584 struct inode *inode = desc->file->f_path.dentry->d_inode; 616 struct inode *inode = desc->file->f_path.dentry->d_inode;
617 int ret;
585 618
586 if (nfs_readdir_xdr_to_array(desc, page, inode) < 0) 619 ret = nfs_readdir_xdr_to_array(desc, page, inode);
620 if (ret < 0)
587 goto error; 621 goto error;
588 SetPageUptodate(page); 622 SetPageUptodate(page);
589 623
@@ -595,12 +629,14 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page)
595 return 0; 629 return 0;
596 error: 630 error:
597 unlock_page(page); 631 unlock_page(page);
598 return -EIO; 632 return ret;
599} 633}
600 634
601static 635static
602void cache_page_release(nfs_readdir_descriptor_t *desc) 636void cache_page_release(nfs_readdir_descriptor_t *desc)
603{ 637{
638 if (!desc->page->mapping)
639 nfs_readdir_clear_array(desc->page);
604 page_cache_release(desc->page); 640 page_cache_release(desc->page);
605 desc->page = NULL; 641 desc->page = NULL;
606} 642}
@@ -608,12 +644,8 @@ void cache_page_release(nfs_readdir_descriptor_t *desc)
608static 644static
609struct page *get_cache_page(nfs_readdir_descriptor_t *desc) 645struct page *get_cache_page(nfs_readdir_descriptor_t *desc)
610{ 646{
611 struct page *page; 647 return read_cache_page(desc->file->f_path.dentry->d_inode->i_mapping,
612 page = read_cache_page(desc->file->f_path.dentry->d_inode->i_mapping,
613 desc->page_index, (filler_t *)nfs_readdir_filler, desc); 648 desc->page_index, (filler_t *)nfs_readdir_filler, desc);
614 if (IS_ERR(page))
615 desc->eof = 1;
616 return page;
617} 649}
618 650
619/* 651/*
@@ -629,9 +661,8 @@ int find_cache_page(nfs_readdir_descriptor_t *desc)
629 return PTR_ERR(desc->page); 661 return PTR_ERR(desc->page);
630 662
631 res = nfs_readdir_search_array(desc); 663 res = nfs_readdir_search_array(desc);
632 if (res == 0) 664 if (res != 0)
633 return 0; 665 cache_page_release(desc);
634 cache_page_release(desc);
635 return res; 666 return res;
636} 667}
637 668
@@ -639,22 +670,18 @@ int find_cache_page(nfs_readdir_descriptor_t *desc)
639static inline 670static inline
640int readdir_search_pagecache(nfs_readdir_descriptor_t *desc) 671int readdir_search_pagecache(nfs_readdir_descriptor_t *desc)
641{ 672{
642 int res = -EAGAIN; 673 int res;
643 674
644 while (1) { 675 if (desc->page_index == 0) {
645 res = find_cache_page(desc); 676 desc->current_index = 0;
646 if (res != -EAGAIN) 677 desc->last_cookie = 0;
647 break;
648 desc->page_index++;
649 } 678 }
679 do {
680 res = find_cache_page(desc);
681 } while (res == -EAGAIN);
650 return res; 682 return res;
651} 683}
652 684
653static inline unsigned int dt_type(struct inode *inode)
654{
655 return (inode->i_mode >> 12) & 15;
656}
657
658/* 685/*
659 * Once we've found the start of the dirent within a page: fill 'er up... 686 * Once we've found the start of the dirent within a page: fill 'er up...
660 */ 687 */
@@ -666,35 +693,35 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc, void *dirent,
666 int i = 0; 693 int i = 0;
667 int res = 0; 694 int res = 0;
668 struct nfs_cache_array *array = NULL; 695 struct nfs_cache_array *array = NULL;
669 unsigned int d_type = DT_UNKNOWN;
670 struct dentry *dentry = NULL;
671 696
672 array = nfs_readdir_get_array(desc->page); 697 array = nfs_readdir_get_array(desc->page);
698 if (IS_ERR(array)) {
699 res = PTR_ERR(array);
700 goto out;
701 }
673 702
674 for (i = desc->cache_entry_index; i < array->size; i++) { 703 for (i = desc->cache_entry_index; i < array->size; i++) {
675 d_type = DT_UNKNOWN; 704 struct nfs_cache_array_entry *ent;
676 705
677 res = filldir(dirent, array->array[i].string.name, 706 ent = &array->array[i];
678 array->array[i].string.len, file->f_pos, 707 if (filldir(dirent, ent->string.name, ent->string.len,
679 nfs_compat_user_ino64(array->array[i].ino), d_type); 708 file->f_pos, nfs_compat_user_ino64(ent->ino),
680 if (res < 0) 709 ent->d_type) < 0) {
710 desc->eof = 1;
681 break; 711 break;
712 }
682 file->f_pos++; 713 file->f_pos++;
683 desc->cache_entry_index = i;
684 if (i < (array->size-1)) 714 if (i < (array->size-1))
685 *desc->dir_cookie = array->array[i+1].cookie; 715 *desc->dir_cookie = array->array[i+1].cookie;
686 else 716 else
687 *desc->dir_cookie = array->last_cookie; 717 *desc->dir_cookie = array->last_cookie;
688 if (i == array->eof_index) {
689 desc->eof = 1;
690 break;
691 }
692 } 718 }
719 if (array->eof_index >= 0)
720 desc->eof = 1;
693 721
694 nfs_readdir_release_array(desc->page); 722 nfs_readdir_release_array(desc->page);
723out:
695 cache_page_release(desc); 724 cache_page_release(desc);
696 if (dentry != NULL)
697 dput(dentry);
698 dfprintk(DIRCACHE, "NFS: nfs_do_filldir() filling ended @ cookie %Lu; returning = %d\n", 725 dfprintk(DIRCACHE, "NFS: nfs_do_filldir() filling ended @ cookie %Lu; returning = %d\n",
699 (unsigned long long)*desc->dir_cookie, res); 726 (unsigned long long)*desc->dir_cookie, res);
700 return res; 727 return res;
@@ -729,13 +756,14 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent,
729 goto out; 756 goto out;
730 } 757 }
731 758
732 if (nfs_readdir_xdr_to_array(desc, page, inode) == -1) {
733 status = -EIO;
734 goto out_release;
735 }
736
737 desc->page_index = 0; 759 desc->page_index = 0;
760 desc->last_cookie = *desc->dir_cookie;
738 desc->page = page; 761 desc->page = page;
762
763 status = nfs_readdir_xdr_to_array(desc, page, inode);
764 if (status < 0)
765 goto out_release;
766
739 status = nfs_do_filldir(desc, dirent, filldir); 767 status = nfs_do_filldir(desc, dirent, filldir);
740 768
741 out: 769 out:
@@ -757,7 +785,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
757 struct inode *inode = dentry->d_inode; 785 struct inode *inode = dentry->d_inode;
758 nfs_readdir_descriptor_t my_desc, 786 nfs_readdir_descriptor_t my_desc,
759 *desc = &my_desc; 787 *desc = &my_desc;
760 int res = -ENOMEM; 788 int res;
761 789
762 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n", 790 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
763 dentry->d_parent->d_name.name, dentry->d_name.name, 791 dentry->d_parent->d_name.name, dentry->d_name.name,
@@ -782,18 +810,18 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
782 if (res < 0) 810 if (res < 0)
783 goto out; 811 goto out;
784 812
785 while (desc->eof != 1) { 813 do {
786 res = readdir_search_pagecache(desc); 814 res = readdir_search_pagecache(desc);
787 815
788 if (res == -EBADCOOKIE) { 816 if (res == -EBADCOOKIE) {
817 res = 0;
789 /* This means either end of directory */ 818 /* This means either end of directory */
790 if (*desc->dir_cookie && desc->eof == 0) { 819 if (*desc->dir_cookie && desc->eof == 0) {
791 /* Or that the server has 'lost' a cookie */ 820 /* Or that the server has 'lost' a cookie */
792 res = uncached_readdir(desc, dirent, filldir); 821 res = uncached_readdir(desc, dirent, filldir);
793 if (res >= 0) 822 if (res == 0)
794 continue; 823 continue;
795 } 824 }
796 res = 0;
797 break; 825 break;
798 } 826 }
799 if (res == -ETOOSMALL && desc->plus) { 827 if (res == -ETOOSMALL && desc->plus) {
@@ -808,11 +836,9 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
808 break; 836 break;
809 837
810 res = nfs_do_filldir(desc, dirent, filldir); 838 res = nfs_do_filldir(desc, dirent, filldir);
811 if (res < 0) { 839 if (res < 0)
812 res = 0;
813 break; 840 break;
814 } 841 } while (!desc->eof);
815 }
816out: 842out:
817 nfs_unblock_sillyrename(dentry); 843 nfs_unblock_sillyrename(dentry);
818 if (res > 0) 844 if (res > 0)
@@ -1345,12 +1371,12 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1345 res = NULL; 1371 res = NULL;
1346 goto out; 1372 goto out;
1347 /* This turned out not to be a regular file */ 1373 /* This turned out not to be a regular file */
1348 case -EISDIR:
1349 case -ENOTDIR: 1374 case -ENOTDIR:
1350 goto no_open; 1375 goto no_open;
1351 case -ELOOP: 1376 case -ELOOP:
1352 if (!(nd->intent.open.flags & O_NOFOLLOW)) 1377 if (!(nd->intent.open.flags & O_NOFOLLOW))
1353 goto no_open; 1378 goto no_open;
1379 /* case -EISDIR: */
1354 /* case -EINVAL: */ 1380 /* case -EINVAL: */
1355 default: 1381 default:
1356 res = ERR_CAST(inode); 1382 res = ERR_CAST(inode);
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 84d3c8b90206..e6ace0d93c71 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -867,7 +867,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
867 goto out; 867 goto out;
868 nfs_alloc_commit_data(dreq); 868 nfs_alloc_commit_data(dreq);
869 869
870 if (dreq->commit_data == NULL || count < wsize) 870 if (dreq->commit_data == NULL || count <= wsize)
871 sync = NFS_FILE_SYNC; 871 sync = NFS_FILE_SYNC;
872 872
873 dreq->inode = inode; 873 dreq->inode = inode;
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index e756075637b0..7bf029ef4084 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -693,6 +693,7 @@ do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
693{ 693{
694 struct inode *inode = filp->f_mapping->host; 694 struct inode *inode = filp->f_mapping->host;
695 int status = 0; 695 int status = 0;
696 unsigned int saved_type = fl->fl_type;
696 697
697 /* Try local locking first */ 698 /* Try local locking first */
698 posix_test_lock(filp, fl); 699 posix_test_lock(filp, fl);
@@ -700,6 +701,7 @@ do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
700 /* found a conflict */ 701 /* found a conflict */
701 goto out; 702 goto out;
702 } 703 }
704 fl->fl_type = saved_type;
703 705
704 if (nfs_have_delegation(inode, FMODE_READ)) 706 if (nfs_have_delegation(inode, FMODE_READ))
705 goto out_noconflict; 707 goto out_noconflict;
@@ -884,6 +886,5 @@ static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
884 dprintk("NFS: setlease(%s/%s, arg=%ld)\n", 886 dprintk("NFS: setlease(%s/%s, arg=%ld)\n",
885 file->f_path.dentry->d_parent->d_name.name, 887 file->f_path.dentry->d_parent->d_name.name,
886 file->f_path.dentry->d_name.name, arg); 888 file->f_path.dentry->d_name.name, arg);
887
888 return -EINVAL; 889 return -EINVAL;
889} 890}
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 314f57164602..e67e31c73416 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -289,6 +289,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
289 } else if (S_ISDIR(inode->i_mode)) { 289 } else if (S_ISDIR(inode->i_mode)) {
290 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops; 290 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
291 inode->i_fop = &nfs_dir_operations; 291 inode->i_fop = &nfs_dir_operations;
292 inode->i_data.a_ops = &nfs_dir_aops;
292 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS)) 293 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS))
293 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags); 294 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags);
294 /* Deal with crossing mountpoints */ 295 /* Deal with crossing mountpoints */
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index db08ff3ff454..e6356b750b77 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -362,6 +362,15 @@ unsigned int nfs_page_length(struct page *page)
362} 362}
363 363
364/* 364/*
365 * Convert a umode to a dirent->d_type
366 */
367static inline
368unsigned char nfs_umode_to_dtype(umode_t mode)
369{
370 return (mode >> 12) & 15;
371}
372
373/*
365 * Determine the number of pages in an array of length 'len' and 374 * Determine the number of pages in an array of length 'len' and
366 * with a base offset of 'base' 375 * with a base offset of 'base'
367 */ 376 */
diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c
index eceafe74f473..4f981f1f6689 100644
--- a/fs/nfs/mount_clnt.c
+++ b/fs/nfs/mount_clnt.c
@@ -505,13 +505,13 @@ static struct rpc_procinfo mnt3_procedures[] = {
505 505
506static struct rpc_version mnt_version1 = { 506static struct rpc_version mnt_version1 = {
507 .number = 1, 507 .number = 1,
508 .nrprocs = 2, 508 .nrprocs = ARRAY_SIZE(mnt_procedures),
509 .procs = mnt_procedures, 509 .procs = mnt_procedures,
510}; 510};
511 511
512static struct rpc_version mnt_version3 = { 512static struct rpc_version mnt_version3 = {
513 .number = 3, 513 .number = 3,
514 .nrprocs = 2, 514 .nrprocs = ARRAY_SIZE(mnt3_procedures),
515 .procs = mnt3_procedures, 515 .procs = mnt3_procedures,
516}; 516};
517 517
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index e6bf45710cc7..5914a1911c95 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -423,7 +423,7 @@ nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy)
423 struct page **page; 423 struct page **page;
424 size_t hdrlen; 424 size_t hdrlen;
425 unsigned int pglen, recvd; 425 unsigned int pglen, recvd;
426 int status, nr = 0; 426 int status;
427 427
428 if ((status = ntohl(*p++))) 428 if ((status = ntohl(*p++)))
429 return nfs_stat_to_errno(status); 429 return nfs_stat_to_errno(status);
@@ -443,7 +443,7 @@ nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy)
443 if (pglen > recvd) 443 if (pglen > recvd)
444 pglen = recvd; 444 pglen = recvd;
445 page = rcvbuf->pages; 445 page = rcvbuf->pages;
446 return nr; 446 return pglen;
447} 447}
448 448
449static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 449static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
@@ -485,6 +485,8 @@ nfs_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_se
485 entry->prev_cookie = entry->cookie; 485 entry->prev_cookie = entry->cookie;
486 entry->cookie = ntohl(*p++); 486 entry->cookie = ntohl(*p++);
487 487
488 entry->d_type = DT_UNKNOWN;
489
488 p = xdr_inline_peek(xdr, 8); 490 p = xdr_inline_peek(xdr, 8);
489 if (p != NULL) 491 if (p != NULL)
490 entry->eof = !p[0] && p[1]; 492 entry->eof = !p[0] && p[1];
@@ -495,7 +497,7 @@ nfs_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_se
495 497
496out_overflow: 498out_overflow:
497 print_overflow_msg(__func__, xdr); 499 print_overflow_msg(__func__, xdr);
498 return ERR_PTR(-EIO); 500 return ERR_PTR(-EAGAIN);
499} 501}
500 502
501/* 503/*
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index d9a5e832c257..f6cc60f06dac 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -555,7 +555,7 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
555 struct page **page; 555 struct page **page;
556 size_t hdrlen; 556 size_t hdrlen;
557 u32 recvd, pglen; 557 u32 recvd, pglen;
558 int status, nr = 0; 558 int status;
559 559
560 status = ntohl(*p++); 560 status = ntohl(*p++);
561 /* Decode post_op_attrs */ 561 /* Decode post_op_attrs */
@@ -586,7 +586,7 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
586 pglen = recvd; 586 pglen = recvd;
587 page = rcvbuf->pages; 587 page = rcvbuf->pages;
588 588
589 return nr; 589 return pglen;
590} 590}
591 591
592__be32 * 592__be32 *
@@ -622,11 +622,13 @@ nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_s
622 entry->prev_cookie = entry->cookie; 622 entry->prev_cookie = entry->cookie;
623 p = xdr_decode_hyper(p, &entry->cookie); 623 p = xdr_decode_hyper(p, &entry->cookie);
624 624
625 entry->d_type = DT_UNKNOWN;
625 if (plus) { 626 if (plus) {
626 entry->fattr->valid = 0; 627 entry->fattr->valid = 0;
627 p = xdr_decode_post_op_attr_stream(xdr, entry->fattr); 628 p = xdr_decode_post_op_attr_stream(xdr, entry->fattr);
628 if (IS_ERR(p)) 629 if (IS_ERR(p))
629 goto out_overflow_exit; 630 goto out_overflow_exit;
631 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
630 /* In fact, a post_op_fh3: */ 632 /* In fact, a post_op_fh3: */
631 p = xdr_inline_decode(xdr, 4); 633 p = xdr_inline_decode(xdr, 4);
632 if (unlikely(!p)) 634 if (unlikely(!p))
@@ -656,7 +658,7 @@ nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_s
656out_overflow: 658out_overflow:
657 print_overflow_msg(__func__, xdr); 659 print_overflow_msg(__func__, xdr);
658out_overflow_exit: 660out_overflow_exit:
659 return ERR_PTR(-EIO); 661 return ERR_PTR(-EAGAIN);
660} 662}
661 663
662/* 664/*
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 0f24cdf2cb13..4435e5e1f904 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2852,8 +2852,10 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2852 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); 2852 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2853 res.pgbase = args.pgbase; 2853 res.pgbase = args.pgbase;
2854 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); 2854 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0);
2855 if (status == 0) 2855 if (status >= 0) {
2856 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); 2856 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2857 status += args.pgbase;
2858 }
2857 2859
2858 nfs_invalidate_atime(dir); 2860 nfs_invalidate_atime(dir);
2859 2861
@@ -3359,6 +3361,8 @@ static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
3359 ret = nfs_revalidate_inode(server, inode); 3361 ret = nfs_revalidate_inode(server, inode);
3360 if (ret < 0) 3362 if (ret < 0)
3361 return ret; 3363 return ret;
3364 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
3365 nfs_zap_acl_cache(inode);
3362 ret = nfs4_read_cached_acl(inode, buf, buflen); 3366 ret = nfs4_read_cached_acl(inode, buf, buflen);
3363 if (ret != -ENOENT) 3367 if (ret != -ENOENT)
3364 return ret; 3368 return ret;
@@ -3387,6 +3391,13 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl
3387 nfs_inode_return_delegation(inode); 3391 nfs_inode_return_delegation(inode);
3388 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); 3392 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3389 ret = nfs4_call_sync(server, &msg, &arg, &res, 1); 3393 ret = nfs4_call_sync(server, &msg, &arg, &res, 1);
3394 /*
3395 * Acl update can result in inode attribute update.
3396 * so mark the attribute cache invalid.
3397 */
3398 spin_lock(&inode->i_lock);
3399 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
3400 spin_unlock(&inode->i_lock);
3390 nfs_access_zap_cache(inode); 3401 nfs_access_zap_cache(inode);
3391 nfs_zap_acl_cache(inode); 3402 nfs_zap_acl_cache(inode);
3392 return ret; 3403 return ret;
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index f313c4cce7e4..9f1826b012e6 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -4518,7 +4518,7 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
4518 xdr_read_pages(xdr, pglen); 4518 xdr_read_pages(xdr, pglen);
4519 4519
4520 4520
4521 return 0; 4521 return pglen;
4522} 4522}
4523 4523
4524static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 4524static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
@@ -6208,6 +6208,10 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6208 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 6208 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6209 entry->ino = entry->fattr->fileid; 6209 entry->ino = entry->fattr->fileid;
6210 6210
6211 entry->d_type = DT_UNKNOWN;
6212 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6213 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6214
6211 if (verify_attr_len(xdr, p, len) < 0) 6215 if (verify_attr_len(xdr, p, len) < 0)
6212 goto out_overflow; 6216 goto out_overflow;
6213 6217
@@ -6221,7 +6225,7 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6221 6225
6222out_overflow: 6226out_overflow:
6223 print_overflow_msg(__func__, xdr); 6227 print_overflow_msg(__func__, xdr);
6224 return ERR_PTR(-EIO); 6228 return ERR_PTR(-EAGAIN);
6225} 6229}
6226 6230
6227/* 6231/*
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 137b549e63db..b68536cc9046 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -115,7 +115,7 @@ int nfs_set_page_tag_locked(struct nfs_page *req)
115{ 115{
116 if (!nfs_lock_request_dontget(req)) 116 if (!nfs_lock_request_dontget(req))
117 return 0; 117 return 0;
118 if (req->wb_page != NULL) 118 if (test_bit(PG_MAPPED, &req->wb_flags))
119 radix_tree_tag_set(&NFS_I(req->wb_context->path.dentry->d_inode)->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED); 119 radix_tree_tag_set(&NFS_I(req->wb_context->path.dentry->d_inode)->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED);
120 return 1; 120 return 1;
121} 121}
@@ -125,7 +125,7 @@ int nfs_set_page_tag_locked(struct nfs_page *req)
125 */ 125 */
126void nfs_clear_page_tag_locked(struct nfs_page *req) 126void nfs_clear_page_tag_locked(struct nfs_page *req)
127{ 127{
128 if (req->wb_page != NULL) { 128 if (test_bit(PG_MAPPED, &req->wb_flags)) {
129 struct inode *inode = req->wb_context->path.dentry->d_inode; 129 struct inode *inode = req->wb_context->path.dentry->d_inode;
130 struct nfs_inode *nfsi = NFS_I(inode); 130 struct nfs_inode *nfsi = NFS_I(inode);
131 131
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index e4b62c6f5a6e..aedcaa7f291f 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -152,7 +152,6 @@ static void nfs_readpage_release(struct nfs_page *req)
152 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode), 152 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
153 req->wb_bytes, 153 req->wb_bytes,
154 (long long)req_offset(req)); 154 (long long)req_offset(req));
155 nfs_clear_request(req);
156 nfs_release_request(req); 155 nfs_release_request(req);
157} 156}
158 157
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 0a42e8f4adcb..4100630c9a5b 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -39,7 +39,6 @@
39#include <linux/nfs_mount.h> 39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h> 40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h> 41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h> 42#include <linux/seq_file.h>
44#include <linux/mount.h> 43#include <linux/mount.h>
45#include <linux/mnt_namespace.h> 44#include <linux/mnt_namespace.h>
@@ -67,6 +66,12 @@
67 66
68#define NFSDBG_FACILITY NFSDBG_VFS 67#define NFSDBG_FACILITY NFSDBG_VFS
69 68
69#ifdef CONFIG_NFS_V3
70#define NFS_DEFAULT_VERSION 3
71#else
72#define NFS_DEFAULT_VERSION 2
73#endif
74
70enum { 75enum {
71 /* Mount options that take no arguments */ 76 /* Mount options that take no arguments */
72 Opt_soft, Opt_hard, 77 Opt_soft, Opt_hard,
@@ -1064,12 +1069,10 @@ static int nfs_parse_mount_options(char *raw,
1064 mnt->flags |= NFS_MOUNT_VER3; 1069 mnt->flags |= NFS_MOUNT_VER3;
1065 mnt->version = 3; 1070 mnt->version = 3;
1066 break; 1071 break;
1067#ifdef CONFIG_NFS_V4
1068 case Opt_v4: 1072 case Opt_v4:
1069 mnt->flags &= ~NFS_MOUNT_VER3; 1073 mnt->flags &= ~NFS_MOUNT_VER3;
1070 mnt->version = 4; 1074 mnt->version = 4;
1071 break; 1075 break;
1072#endif
1073 case Opt_udp: 1076 case Opt_udp:
1074 mnt->flags &= ~NFS_MOUNT_TCP; 1077 mnt->flags &= ~NFS_MOUNT_TCP;
1075 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; 1078 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
@@ -1281,12 +1284,10 @@ static int nfs_parse_mount_options(char *raw,
1281 mnt->flags |= NFS_MOUNT_VER3; 1284 mnt->flags |= NFS_MOUNT_VER3;
1282 mnt->version = 3; 1285 mnt->version = 3;
1283 break; 1286 break;
1284#ifdef CONFIG_NFS_V4
1285 case NFS4_VERSION: 1287 case NFS4_VERSION:
1286 mnt->flags &= ~NFS_MOUNT_VER3; 1288 mnt->flags &= ~NFS_MOUNT_VER3;
1287 mnt->version = 4; 1289 mnt->version = 4;
1288 break; 1290 break;
1289#endif
1290 default: 1291 default:
1291 goto out_invalid_value; 1292 goto out_invalid_value;
1292 } 1293 }
@@ -2277,7 +2278,7 @@ static int nfs_get_sb(struct file_system_type *fs_type,
2277 }; 2278 };
2278 int error = -ENOMEM; 2279 int error = -ENOMEM;
2279 2280
2280 data = nfs_alloc_parsed_mount_data(3); 2281 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2281 mntfh = nfs_alloc_fhandle(); 2282 mntfh = nfs_alloc_fhandle();
2282 if (data == NULL || mntfh == NULL) 2283 if (data == NULL || mntfh == NULL)
2283 goto out_free_fh; 2284 goto out_free_fh;
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 4c14c17a5276..10d648ea128b 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -390,6 +390,7 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
390 if (nfs_have_delegation(inode, FMODE_WRITE)) 390 if (nfs_have_delegation(inode, FMODE_WRITE))
391 nfsi->change_attr++; 391 nfsi->change_attr++;
392 } 392 }
393 set_bit(PG_MAPPED, &req->wb_flags);
393 SetPagePrivate(req->wb_page); 394 SetPagePrivate(req->wb_page);
394 set_page_private(req->wb_page, (unsigned long)req); 395 set_page_private(req->wb_page, (unsigned long)req);
395 nfsi->npages++; 396 nfsi->npages++;
@@ -415,6 +416,7 @@ static void nfs_inode_remove_request(struct nfs_page *req)
415 spin_lock(&inode->i_lock); 416 spin_lock(&inode->i_lock);
416 set_page_private(req->wb_page, 0); 417 set_page_private(req->wb_page, 0);
417 ClearPagePrivate(req->wb_page); 418 ClearPagePrivate(req->wb_page);
419 clear_bit(PG_MAPPED, &req->wb_flags);
418 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index); 420 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
419 nfsi->npages--; 421 nfsi->npages--;
420 if (!nfsi->npages) { 422 if (!nfsi->npages) {
@@ -422,7 +424,6 @@ static void nfs_inode_remove_request(struct nfs_page *req)
422 iput(inode); 424 iput(inode);
423 } else 425 } else
424 spin_unlock(&inode->i_lock); 426 spin_unlock(&inode->i_lock);
425 nfs_clear_request(req);
426 nfs_release_request(req); 427 nfs_release_request(req);
427} 428}
428 429
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 2a533a0af2a9..7e84a852cdae 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -260,9 +260,11 @@ void fill_post_wcc(struct svc_fh *fhp)
260 err = vfs_getattr(fhp->fh_export->ex_path.mnt, fhp->fh_dentry, 260 err = vfs_getattr(fhp->fh_export->ex_path.mnt, fhp->fh_dentry,
261 &fhp->fh_post_attr); 261 &fhp->fh_post_attr);
262 fhp->fh_post_change = fhp->fh_dentry->d_inode->i_version; 262 fhp->fh_post_change = fhp->fh_dentry->d_inode->i_version;
263 if (err) 263 if (err) {
264 fhp->fh_post_saved = 0; 264 fhp->fh_post_saved = 0;
265 else 265 /* Grab the ctime anyway - set_change_info might use it */
266 fhp->fh_post_attr.ctime = fhp->fh_dentry->d_inode->i_ctime;
267 } else
266 fhp->fh_post_saved = 1; 268 fhp->fh_post_saved = 1;
267} 269}
268 270
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 56347e0ac88d..116cab970e0f 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -673,16 +673,17 @@ static void nfsd4_hash_conn(struct nfsd4_conn *conn, struct nfsd4_session *ses)
673 spin_unlock(&clp->cl_lock); 673 spin_unlock(&clp->cl_lock);
674} 674}
675 675
676static void nfsd4_register_conn(struct nfsd4_conn *conn) 676static int nfsd4_register_conn(struct nfsd4_conn *conn)
677{ 677{
678 conn->cn_xpt_user.callback = nfsd4_conn_lost; 678 conn->cn_xpt_user.callback = nfsd4_conn_lost;
679 register_xpt_user(conn->cn_xprt, &conn->cn_xpt_user); 679 return register_xpt_user(conn->cn_xprt, &conn->cn_xpt_user);
680} 680}
681 681
682static __be32 nfsd4_new_conn(struct svc_rqst *rqstp, struct nfsd4_session *ses) 682static __be32 nfsd4_new_conn(struct svc_rqst *rqstp, struct nfsd4_session *ses)
683{ 683{
684 struct nfsd4_conn *conn; 684 struct nfsd4_conn *conn;
685 u32 flags = NFS4_CDFC4_FORE; 685 u32 flags = NFS4_CDFC4_FORE;
686 int ret;
686 687
687 if (ses->se_flags & SESSION4_BACK_CHAN) 688 if (ses->se_flags & SESSION4_BACK_CHAN)
688 flags |= NFS4_CDFC4_BACK; 689 flags |= NFS4_CDFC4_BACK;
@@ -690,7 +691,10 @@ static __be32 nfsd4_new_conn(struct svc_rqst *rqstp, struct nfsd4_session *ses)
690 if (!conn) 691 if (!conn)
691 return nfserr_jukebox; 692 return nfserr_jukebox;
692 nfsd4_hash_conn(conn, ses); 693 nfsd4_hash_conn(conn, ses);
693 nfsd4_register_conn(conn); 694 ret = nfsd4_register_conn(conn);
695 if (ret)
696 /* oops; xprt is already down: */
697 nfsd4_conn_lost(&conn->cn_xpt_user);
694 return nfs_ok; 698 return nfs_ok;
695} 699}
696 700
@@ -1644,6 +1648,7 @@ static void nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_sessi
1644{ 1648{
1645 struct nfs4_client *clp = ses->se_client; 1649 struct nfs4_client *clp = ses->se_client;
1646 struct nfsd4_conn *c; 1650 struct nfsd4_conn *c;
1651 int ret;
1647 1652
1648 spin_lock(&clp->cl_lock); 1653 spin_lock(&clp->cl_lock);
1649 c = __nfsd4_find_conn(new->cn_xprt, ses); 1654 c = __nfsd4_find_conn(new->cn_xprt, ses);
@@ -1654,7 +1659,10 @@ static void nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_sessi
1654 } 1659 }
1655 __nfsd4_hash_conn(new, ses); 1660 __nfsd4_hash_conn(new, ses);
1656 spin_unlock(&clp->cl_lock); 1661 spin_unlock(&clp->cl_lock);
1657 nfsd4_register_conn(new); 1662 ret = nfsd4_register_conn(new);
1663 if (ret)
1664 /* oops; xprt is already down: */
1665 nfsd4_conn_lost(&new->cn_xpt_user);
1658 return; 1666 return;
1659} 1667}
1660 1668
@@ -2254,7 +2262,7 @@ nfs4_file_downgrade(struct nfs4_file *fp, unsigned int share_access)
2254 * Spawn a thread to perform a recall on the delegation represented 2262 * Spawn a thread to perform a recall on the delegation represented
2255 * by the lease (file_lock) 2263 * by the lease (file_lock)
2256 * 2264 *
2257 * Called from break_lease() with lock_kernel() held. 2265 * Called from break_lease() with lock_flocks() held.
2258 * Note: we assume break_lease will only call this *once* for any given 2266 * Note: we assume break_lease will only call this *once* for any given
2259 * lease. 2267 * lease.
2260 */ 2268 */
@@ -2278,7 +2286,7 @@ void nfsd_break_deleg_cb(struct file_lock *fl)
2278 list_add_tail(&dp->dl_recall_lru, &del_recall_lru); 2286 list_add_tail(&dp->dl_recall_lru, &del_recall_lru);
2279 spin_unlock(&recall_lock); 2287 spin_unlock(&recall_lock);
2280 2288
2281 /* only place dl_time is set. protected by lock_kernel*/ 2289 /* only place dl_time is set. protected by lock_flocks*/
2282 dp->dl_time = get_seconds(); 2290 dp->dl_time = get_seconds();
2283 2291
2284 /* 2292 /*
@@ -2295,7 +2303,7 @@ void nfsd_break_deleg_cb(struct file_lock *fl)
2295/* 2303/*
2296 * The file_lock is being reapd. 2304 * The file_lock is being reapd.
2297 * 2305 *
2298 * Called by locks_free_lock() with lock_kernel() held. 2306 * Called by locks_free_lock() with lock_flocks() held.
2299 */ 2307 */
2300static 2308static
2301void nfsd_release_deleg_cb(struct file_lock *fl) 2309void nfsd_release_deleg_cb(struct file_lock *fl)
@@ -2310,23 +2318,7 @@ void nfsd_release_deleg_cb(struct file_lock *fl)
2310} 2318}
2311 2319
2312/* 2320/*
2313 * Set the delegation file_lock back pointer. 2321 * Called from setlease() with lock_flocks() held
2314 *
2315 * Called from setlease() with lock_kernel() held.
2316 */
2317static
2318void nfsd_copy_lock_deleg_cb(struct file_lock *new, struct file_lock *fl)
2319{
2320 struct nfs4_delegation *dp = (struct nfs4_delegation *)new->fl_owner;
2321
2322 dprintk("NFSD: nfsd_copy_lock_deleg_cb: new fl %p dp %p\n", new, dp);
2323 if (!dp)
2324 return;
2325 dp->dl_flock = new;
2326}
2327
2328/*
2329 * Called from setlease() with lock_kernel() held
2330 */ 2322 */
2331static 2323static
2332int nfsd_same_client_deleg_cb(struct file_lock *onlist, struct file_lock *try) 2324int nfsd_same_client_deleg_cb(struct file_lock *onlist, struct file_lock *try)
@@ -2355,7 +2347,6 @@ int nfsd_change_deleg_cb(struct file_lock **onlist, int arg)
2355static const struct lock_manager_operations nfsd_lease_mng_ops = { 2347static const struct lock_manager_operations nfsd_lease_mng_ops = {
2356 .fl_break = nfsd_break_deleg_cb, 2348 .fl_break = nfsd_break_deleg_cb,
2357 .fl_release_private = nfsd_release_deleg_cb, 2349 .fl_release_private = nfsd_release_deleg_cb,
2358 .fl_copy_lock = nfsd_copy_lock_deleg_cb,
2359 .fl_mylease = nfsd_same_client_deleg_cb, 2350 .fl_mylease = nfsd_same_client_deleg_cb,
2360 .fl_change = nfsd_change_deleg_cb, 2351 .fl_change = nfsd_change_deleg_cb,
2361}; 2352};
@@ -2661,12 +2652,15 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
2661 fl->fl_file = find_readable_file(stp->st_file); 2652 fl->fl_file = find_readable_file(stp->st_file);
2662 BUG_ON(!fl->fl_file); 2653 BUG_ON(!fl->fl_file);
2663 fl->fl_pid = current->tgid; 2654 fl->fl_pid = current->tgid;
2655 dp->dl_flock = fl;
2664 2656
2665 /* vfs_setlease checks to see if delegation should be handed out. 2657 /* vfs_setlease checks to see if delegation should be handed out.
2666 * the lock_manager callbacks fl_mylease and fl_change are used 2658 * the lock_manager callbacks fl_mylease and fl_change are used
2667 */ 2659 */
2668 if ((status = vfs_setlease(fl->fl_file, fl->fl_type, &fl))) { 2660 if ((status = vfs_setlease(fl->fl_file, fl->fl_type, &fl))) {
2669 dprintk("NFSD: setlease failed [%d], no delegation\n", status); 2661 dprintk("NFSD: setlease failed [%d], no delegation\n", status);
2662 dp->dl_flock = NULL;
2663 locks_free_lock(fl);
2670 unhash_delegation(dp); 2664 unhash_delegation(dp);
2671 flag = NFS4_OPEN_DELEGATE_NONE; 2665 flag = NFS4_OPEN_DELEGATE_NONE;
2672 goto out; 2666 goto out;
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 4d476ff08ae6..60fce3dc5cb5 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -484,18 +484,17 @@ static inline bool nfsd4_not_cached(struct nfsd4_compoundres *resp)
484static inline void 484static inline void
485set_change_info(struct nfsd4_change_info *cinfo, struct svc_fh *fhp) 485set_change_info(struct nfsd4_change_info *cinfo, struct svc_fh *fhp)
486{ 486{
487 BUG_ON(!fhp->fh_pre_saved || !fhp->fh_post_saved); 487 BUG_ON(!fhp->fh_pre_saved);
488 cinfo->atomic = 1; 488 cinfo->atomic = fhp->fh_post_saved;
489 cinfo->change_supported = IS_I_VERSION(fhp->fh_dentry->d_inode); 489 cinfo->change_supported = IS_I_VERSION(fhp->fh_dentry->d_inode);
490 if (cinfo->change_supported) { 490
491 cinfo->before_change = fhp->fh_pre_change; 491 cinfo->before_change = fhp->fh_pre_change;
492 cinfo->after_change = fhp->fh_post_change; 492 cinfo->after_change = fhp->fh_post_change;
493 } else { 493 cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec;
494 cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec; 494 cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec;
495 cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec; 495 cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec;
496 cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec; 496 cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec;
497 cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec; 497
498 }
499} 498}
500 499
501int nfs4svc_encode_voidres(struct svc_rqst *, __be32 *, void *); 500int nfs4svc_encode_voidres(struct svc_rqst *, __be32 *, void *);
diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c
index 49c844dab33a..59e5fe742f7b 100644
--- a/fs/nilfs2/dat.c
+++ b/fs/nilfs2/dat.c
@@ -335,7 +335,7 @@ int nilfs_dat_move(struct inode *dat, __u64 vblocknr, sector_t blocknr)
335 * the device at this point. 335 * the device at this point.
336 * 336 *
337 * To prevent nilfs_dat_translate() from returning the 337 * To prevent nilfs_dat_translate() from returning the
338 * uncommited block number, this makes a copy of the entry 338 * uncommitted block number, this makes a copy of the entry
339 * buffer and redirects nilfs_dat_translate() to the copy. 339 * buffer and redirects nilfs_dat_translate() to the copy.
340 */ 340 */
341 if (!buffer_nilfs_redirected(entry_bh)) { 341 if (!buffer_nilfs_redirected(entry_bh)) {
diff --git a/fs/nilfs2/gcinode.c b/fs/nilfs2/gcinode.c
index 33ad25ddd5c4..caf9a6a3fb54 100644
--- a/fs/nilfs2/gcinode.c
+++ b/fs/nilfs2/gcinode.c
@@ -176,7 +176,6 @@ int nilfs_gccache_wait_and_mark_dirty(struct buffer_head *bh)
176int nilfs_init_gcinode(struct inode *inode) 176int nilfs_init_gcinode(struct inode *inode)
177{ 177{
178 struct nilfs_inode_info *ii = NILFS_I(inode); 178 struct nilfs_inode_info *ii = NILFS_I(inode);
179 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
180 179
181 inode->i_mode = S_IFREG; 180 inode->i_mode = S_IFREG;
182 mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); 181 mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
@@ -186,14 +185,6 @@ int nilfs_init_gcinode(struct inode *inode)
186 ii->i_flags = 0; 185 ii->i_flags = 0;
187 nilfs_bmap_init_gc(ii->i_bmap); 186 nilfs_bmap_init_gc(ii->i_bmap);
188 187
189 /*
190 * Add the inode to GC inode list. Garbage Collection
191 * is serialized and no two processes manipulate the
192 * list simultaneously.
193 */
194 igrab(inode);
195 list_add(&NILFS_I(inode)->i_dirty, &nilfs->ns_gc_inodes);
196
197 return 0; 188 return 0;
198} 189}
199 190
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index 3e90f86d5bfe..b185e937a335 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -337,6 +337,7 @@ static int nilfs_ioctl_move_blocks(struct super_block *sb,
337 struct nilfs_argv *argv, void *buf) 337 struct nilfs_argv *argv, void *buf)
338{ 338{
339 size_t nmembs = argv->v_nmembs; 339 size_t nmembs = argv->v_nmembs;
340 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
340 struct inode *inode; 341 struct inode *inode;
341 struct nilfs_vdesc *vdesc; 342 struct nilfs_vdesc *vdesc;
342 struct buffer_head *bh, *n; 343 struct buffer_head *bh, *n;
@@ -349,10 +350,21 @@ static int nilfs_ioctl_move_blocks(struct super_block *sb,
349 ino = vdesc->vd_ino; 350 ino = vdesc->vd_ino;
350 cno = vdesc->vd_cno; 351 cno = vdesc->vd_cno;
351 inode = nilfs_iget_for_gc(sb, ino, cno); 352 inode = nilfs_iget_for_gc(sb, ino, cno);
352 if (unlikely(inode == NULL)) { 353 if (IS_ERR(inode)) {
353 ret = -ENOMEM; 354 ret = PTR_ERR(inode);
354 goto failed; 355 goto failed;
355 } 356 }
357 if (list_empty(&NILFS_I(inode)->i_dirty)) {
358 /*
359 * Add the inode to GC inode list. Garbage Collection
360 * is serialized and no two processes manipulate the
361 * list simultaneously.
362 */
363 igrab(inode);
364 list_add(&NILFS_I(inode)->i_dirty,
365 &nilfs->ns_gc_inodes);
366 }
367
356 do { 368 do {
357 ret = nilfs_ioctl_move_inode_block(inode, vdesc, 369 ret = nilfs_ioctl_move_inode_block(inode, vdesc,
358 &buffers); 370 &buffers);
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index b04f88eed09e..f35794b97e8e 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -92,7 +92,11 @@ static int fanotify_get_response_from_access(struct fsnotify_group *group,
92 92
93 pr_debug("%s: group=%p event=%p\n", __func__, group, event); 93 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
94 94
95 wait_event(group->fanotify_data.access_waitq, event->response); 95 wait_event(group->fanotify_data.access_waitq, event->response ||
96 atomic_read(&group->fanotify_data.bypass_perm));
97
98 if (!event->response) /* bypass_perm set */
99 return 0;
96 100
97 /* userspace responded, convert to something usable */ 101 /* userspace responded, convert to something usable */
98 spin_lock(&event->lock); 102 spin_lock(&event->lock);
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 063224812b7e..8b61220cffc5 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -106,20 +106,29 @@ static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event)
106 return client_fd; 106 return client_fd;
107} 107}
108 108
109static ssize_t fill_event_metadata(struct fsnotify_group *group, 109static int fill_event_metadata(struct fsnotify_group *group,
110 struct fanotify_event_metadata *metadata, 110 struct fanotify_event_metadata *metadata,
111 struct fsnotify_event *event) 111 struct fsnotify_event *event)
112{ 112{
113 int ret = 0;
114
113 pr_debug("%s: group=%p metadata=%p event=%p\n", __func__, 115 pr_debug("%s: group=%p metadata=%p event=%p\n", __func__,
114 group, metadata, event); 116 group, metadata, event);
115 117
116 metadata->event_len = FAN_EVENT_METADATA_LEN; 118 metadata->event_len = FAN_EVENT_METADATA_LEN;
119 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
117 metadata->vers = FANOTIFY_METADATA_VERSION; 120 metadata->vers = FANOTIFY_METADATA_VERSION;
118 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS; 121 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
119 metadata->pid = pid_vnr(event->tgid); 122 metadata->pid = pid_vnr(event->tgid);
120 metadata->fd = create_fd(group, event); 123 if (unlikely(event->mask & FAN_Q_OVERFLOW))
124 metadata->fd = FAN_NOFD;
125 else {
126 metadata->fd = create_fd(group, event);
127 if (metadata->fd < 0)
128 ret = metadata->fd;
129 }
121 130
122 return metadata->fd; 131 return ret;
123} 132}
124 133
125#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS 134#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
@@ -200,7 +209,7 @@ static int prepare_for_access_response(struct fsnotify_group *group,
200 209
201 mutex_lock(&group->fanotify_data.access_mutex); 210 mutex_lock(&group->fanotify_data.access_mutex);
202 211
203 if (group->fanotify_data.bypass_perm) { 212 if (atomic_read(&group->fanotify_data.bypass_perm)) {
204 mutex_unlock(&group->fanotify_data.access_mutex); 213 mutex_unlock(&group->fanotify_data.access_mutex);
205 kmem_cache_free(fanotify_response_event_cache, re); 214 kmem_cache_free(fanotify_response_event_cache, re);
206 event->response = FAN_ALLOW; 215 event->response = FAN_ALLOW;
@@ -257,24 +266,34 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
257 266
258 pr_debug("%s: group=%p event=%p\n", __func__, group, event); 267 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
259 268
260 fd = fill_event_metadata(group, &fanotify_event_metadata, event); 269 ret = fill_event_metadata(group, &fanotify_event_metadata, event);
261 if (fd < 0) 270 if (ret < 0)
262 return fd; 271 goto out;
263 272
273 fd = fanotify_event_metadata.fd;
264 ret = prepare_for_access_response(group, event, fd); 274 ret = prepare_for_access_response(group, event, fd);
265 if (ret) 275 if (ret)
266 goto out_close_fd; 276 goto out_close_fd;
267 277
268 ret = -EFAULT; 278 ret = -EFAULT;
269 if (copy_to_user(buf, &fanotify_event_metadata, FAN_EVENT_METADATA_LEN)) 279 if (copy_to_user(buf, &fanotify_event_metadata,
280 fanotify_event_metadata.event_len))
270 goto out_kill_access_response; 281 goto out_kill_access_response;
271 282
272 return FAN_EVENT_METADATA_LEN; 283 return fanotify_event_metadata.event_len;
273 284
274out_kill_access_response: 285out_kill_access_response:
275 remove_access_response(group, event, fd); 286 remove_access_response(group, event, fd);
276out_close_fd: 287out_close_fd:
277 sys_close(fd); 288 if (fd != FAN_NOFD)
289 sys_close(fd);
290out:
291#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
292 if (event->mask & FAN_ALL_PERM_EVENTS) {
293 event->response = FAN_DENY;
294 wake_up(&group->fanotify_data.access_waitq);
295 }
296#endif
278 return ret; 297 return ret;
279} 298}
280 299
@@ -382,7 +401,7 @@ static int fanotify_release(struct inode *ignored, struct file *file)
382 401
383 mutex_lock(&group->fanotify_data.access_mutex); 402 mutex_lock(&group->fanotify_data.access_mutex);
384 403
385 group->fanotify_data.bypass_perm = true; 404 atomic_inc(&group->fanotify_data.bypass_perm);
386 405
387 list_for_each_entry_safe(re, lre, &group->fanotify_data.access_list, list) { 406 list_for_each_entry_safe(re, lre, &group->fanotify_data.access_list, list) {
388 pr_debug("%s: found group=%p re=%p event=%p\n", __func__, group, 407 pr_debug("%s: found group=%p re=%p event=%p\n", __func__, group,
@@ -586,11 +605,10 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
586{ 605{
587 struct fsnotify_mark *fsn_mark; 606 struct fsnotify_mark *fsn_mark;
588 __u32 added; 607 __u32 added;
608 int ret = 0;
589 609
590 fsn_mark = fsnotify_find_vfsmount_mark(group, mnt); 610 fsn_mark = fsnotify_find_vfsmount_mark(group, mnt);
591 if (!fsn_mark) { 611 if (!fsn_mark) {
592 int ret;
593
594 if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks) 612 if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks)
595 return -ENOSPC; 613 return -ENOSPC;
596 614
@@ -600,17 +618,16 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
600 618
601 fsnotify_init_mark(fsn_mark, fanotify_free_mark); 619 fsnotify_init_mark(fsn_mark, fanotify_free_mark);
602 ret = fsnotify_add_mark(fsn_mark, group, NULL, mnt, 0); 620 ret = fsnotify_add_mark(fsn_mark, group, NULL, mnt, 0);
603 if (ret) { 621 if (ret)
604 fanotify_free_mark(fsn_mark); 622 goto err;
605 return ret;
606 }
607 } 623 }
608 added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); 624 added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
609 fsnotify_put_mark(fsn_mark); 625
610 if (added & ~mnt->mnt_fsnotify_mask) 626 if (added & ~mnt->mnt_fsnotify_mask)
611 fsnotify_recalc_vfsmount_mask(mnt); 627 fsnotify_recalc_vfsmount_mask(mnt);
612 628err:
613 return 0; 629 fsnotify_put_mark(fsn_mark);
630 return ret;
614} 631}
615 632
616static int fanotify_add_inode_mark(struct fsnotify_group *group, 633static int fanotify_add_inode_mark(struct fsnotify_group *group,
@@ -619,6 +636,7 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
619{ 636{
620 struct fsnotify_mark *fsn_mark; 637 struct fsnotify_mark *fsn_mark;
621 __u32 added; 638 __u32 added;
639 int ret = 0;
622 640
623 pr_debug("%s: group=%p inode=%p\n", __func__, group, inode); 641 pr_debug("%s: group=%p inode=%p\n", __func__, group, inode);
624 642
@@ -634,8 +652,6 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
634 652
635 fsn_mark = fsnotify_find_inode_mark(group, inode); 653 fsn_mark = fsnotify_find_inode_mark(group, inode);
636 if (!fsn_mark) { 654 if (!fsn_mark) {
637 int ret;
638
639 if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks) 655 if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks)
640 return -ENOSPC; 656 return -ENOSPC;
641 657
@@ -645,16 +661,16 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
645 661
646 fsnotify_init_mark(fsn_mark, fanotify_free_mark); 662 fsnotify_init_mark(fsn_mark, fanotify_free_mark);
647 ret = fsnotify_add_mark(fsn_mark, group, inode, NULL, 0); 663 ret = fsnotify_add_mark(fsn_mark, group, inode, NULL, 0);
648 if (ret) { 664 if (ret)
649 fanotify_free_mark(fsn_mark); 665 goto err;
650 return ret;
651 }
652 } 666 }
653 added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); 667 added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
654 fsnotify_put_mark(fsn_mark); 668
655 if (added & ~inode->i_fsnotify_mask) 669 if (added & ~inode->i_fsnotify_mask)
656 fsnotify_recalc_inode_mask(inode); 670 fsnotify_recalc_inode_mask(inode);
657 return 0; 671err:
672 fsnotify_put_mark(fsn_mark);
673 return ret;
658} 674}
659 675
660/* fanotify syscalls */ 676/* fanotify syscalls */
@@ -687,8 +703,10 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
687 703
688 /* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */ 704 /* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */
689 group = fsnotify_alloc_group(&fanotify_fsnotify_ops); 705 group = fsnotify_alloc_group(&fanotify_fsnotify_ops);
690 if (IS_ERR(group)) 706 if (IS_ERR(group)) {
707 free_uid(user);
691 return PTR_ERR(group); 708 return PTR_ERR(group);
709 }
692 710
693 group->fanotify_data.user = user; 711 group->fanotify_data.user = user;
694 atomic_inc(&user->fanotify_listeners); 712 atomic_inc(&user->fanotify_listeners);
@@ -698,6 +716,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
698 mutex_init(&group->fanotify_data.access_mutex); 716 mutex_init(&group->fanotify_data.access_mutex);
699 init_waitqueue_head(&group->fanotify_data.access_waitq); 717 init_waitqueue_head(&group->fanotify_data.access_waitq);
700 INIT_LIST_HEAD(&group->fanotify_data.access_list); 718 INIT_LIST_HEAD(&group->fanotify_data.access_list);
719 atomic_set(&group->fanotify_data.bypass_perm, 0);
701#endif 720#endif
702 switch (flags & FAN_ALL_CLASS_BITS) { 721 switch (flags & FAN_ALL_CLASS_BITS) {
703 case FAN_CLASS_NOTIF: 722 case FAN_CLASS_NOTIF:
@@ -764,8 +783,10 @@ SYSCALL_DEFINE(fanotify_mark)(int fanotify_fd, unsigned int flags,
764 if (flags & ~FAN_ALL_MARK_FLAGS) 783 if (flags & ~FAN_ALL_MARK_FLAGS)
765 return -EINVAL; 784 return -EINVAL;
766 switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) { 785 switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) {
767 case FAN_MARK_ADD: 786 case FAN_MARK_ADD: /* fallthrough */
768 case FAN_MARK_REMOVE: 787 case FAN_MARK_REMOVE:
788 if (!mask)
789 return -EINVAL;
769 case FAN_MARK_FLUSH: 790 case FAN_MARK_FLUSH:
770 break; 791 break;
771 default: 792 default:
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index 444c305a468c..4cd5d5d78f9f 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -752,6 +752,7 @@ SYSCALL_DEFINE1(inotify_init1, int, flags)
752 if (ret >= 0) 752 if (ret >= 0)
753 return ret; 753 return ret;
754 754
755 fsnotify_put_group(group);
755 atomic_dec(&user->inotify_devs); 756 atomic_dec(&user->inotify_devs);
756out_free_uid: 757out_free_uid:
757 free_uid(user); 758 free_uid(user);
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 52c7557f3e25..9f26ac9be2a4 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1964,8 +1964,10 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
1964 if (reg == NULL) 1964 if (reg == NULL)
1965 return ERR_PTR(-ENOMEM); 1965 return ERR_PTR(-ENOMEM);
1966 1966
1967 if (strlen(name) > O2HB_MAX_REGION_NAME_LEN) 1967 if (strlen(name) > O2HB_MAX_REGION_NAME_LEN) {
1968 return ERR_PTR(-ENAMETOOLONG); 1968 ret = -ENAMETOOLONG;
1969 goto free;
1970 }
1969 1971
1970 spin_lock(&o2hb_live_lock); 1972 spin_lock(&o2hb_live_lock);
1971 reg->hr_region_num = 0; 1973 reg->hr_region_num = 0;
@@ -1974,7 +1976,8 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
1974 O2NM_MAX_REGIONS); 1976 O2NM_MAX_REGIONS);
1975 if (reg->hr_region_num >= O2NM_MAX_REGIONS) { 1977 if (reg->hr_region_num >= O2NM_MAX_REGIONS) {
1976 spin_unlock(&o2hb_live_lock); 1978 spin_unlock(&o2hb_live_lock);
1977 return ERR_PTR(-EFBIG); 1979 ret = -EFBIG;
1980 goto free;
1978 } 1981 }
1979 set_bit(reg->hr_region_num, o2hb_region_bitmap); 1982 set_bit(reg->hr_region_num, o2hb_region_bitmap);
1980 } 1983 }
@@ -1986,10 +1989,13 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
1986 ret = o2hb_debug_region_init(reg, o2hb_debug_dir); 1989 ret = o2hb_debug_region_init(reg, o2hb_debug_dir);
1987 if (ret) { 1990 if (ret) {
1988 config_item_put(&reg->hr_item); 1991 config_item_put(&reg->hr_item);
1989 return ERR_PTR(ret); 1992 goto free;
1990 } 1993 }
1991 1994
1992 return &reg->hr_item; 1995 return &reg->hr_item;
1996free:
1997 kfree(reg);
1998 return ERR_PTR(ret);
1993} 1999}
1994 2000
1995static void o2hb_heartbeat_group_drop_item(struct config_group *group, 2001static void o2hb_heartbeat_group_drop_item(struct config_group *group,
diff --git a/fs/ocfs2/dcache.c b/fs/ocfs2/dcache.c
index edaded48e7e9..895532ac4d98 100644
--- a/fs/ocfs2/dcache.c
+++ b/fs/ocfs2/dcache.c
@@ -476,7 +476,6 @@ static void ocfs2_dentry_iput(struct dentry *dentry, struct inode *inode)
476 476
477out: 477out:
478 iput(inode); 478 iput(inode);
479 ocfs2_dentry_attach_gen(dentry);
480} 479}
481 480
482/* 481/*
diff --git a/fs/ocfs2/dlm/dlmdomain.c b/fs/ocfs2/dlm/dlmdomain.c
index 58a93b953735..cc2aaa96cfe5 100644
--- a/fs/ocfs2/dlm/dlmdomain.c
+++ b/fs/ocfs2/dlm/dlmdomain.c
@@ -959,7 +959,7 @@ static int dlm_match_regions(struct dlm_ctxt *dlm,
959 r += O2HB_MAX_REGION_NAME_LEN; 959 r += O2HB_MAX_REGION_NAME_LEN;
960 } 960 }
961 961
962 local = kmalloc(sizeof(qr->qr_regions), GFP_KERNEL); 962 local = kmalloc(sizeof(qr->qr_regions), GFP_ATOMIC);
963 if (!local) { 963 if (!local) {
964 status = -ENOMEM; 964 status = -ENOMEM;
965 goto bail; 965 goto bail;
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
index d8408217e3bd..70dd3b1798f1 100644
--- a/fs/ocfs2/ocfs2.h
+++ b/fs/ocfs2/ocfs2.h
@@ -159,7 +159,9 @@ struct ocfs2_lock_res {
159 char l_name[OCFS2_LOCK_ID_MAX_LEN]; 159 char l_name[OCFS2_LOCK_ID_MAX_LEN];
160 unsigned int l_ro_holders; 160 unsigned int l_ro_holders;
161 unsigned int l_ex_holders; 161 unsigned int l_ex_holders;
162 unsigned char l_level; 162 signed char l_level;
163 signed char l_requested;
164 signed char l_blocking;
163 165
164 /* Data packed - type enum ocfs2_lock_type */ 166 /* Data packed - type enum ocfs2_lock_type */
165 unsigned char l_type; 167 unsigned char l_type;
@@ -169,8 +171,6 @@ struct ocfs2_lock_res {
169 unsigned char l_action; 171 unsigned char l_action;
170 /* Data packed - enum type ocfs2_unlock_action */ 172 /* Data packed - enum type ocfs2_unlock_action */
171 unsigned char l_unlock_action; 173 unsigned char l_unlock_action;
172 unsigned char l_requested;
173 unsigned char l_blocking;
174 unsigned int l_pending_gen; 174 unsigned int l_pending_gen;
175 175
176 spinlock_t l_lock; 176 spinlock_t l_lock;
diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c
index 252e7c82f929..a5ebe421195f 100644
--- a/fs/ocfs2/stack_user.c
+++ b/fs/ocfs2/stack_user.c
@@ -190,7 +190,7 @@ static struct ocfs2_live_connection *ocfs2_connection_find(const char *name)
190 return c; 190 return c;
191 } 191 }
192 192
193 return c; 193 return NULL;
194} 194}
195 195
196/* 196/*
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index f02c0ef31578..cfeab7ce3697 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -41,7 +41,6 @@
41#include <linux/mount.h> 41#include <linux/mount.h>
42#include <linux/seq_file.h> 42#include <linux/seq_file.h>
43#include <linux/quotaops.h> 43#include <linux/quotaops.h>
44#include <linux/smp_lock.h>
45 44
46#define MLOG_MASK_PREFIX ML_SUPER 45#define MLOG_MASK_PREFIX ML_SUPER
47#include <cluster/masklog.h> 46#include <cluster/masklog.h>
diff --git a/fs/openpromfs/inode.c b/fs/openpromfs/inode.c
index ddb1f41376e5..911e61f348fc 100644
--- a/fs/openpromfs/inode.c
+++ b/fs/openpromfs/inode.c
@@ -418,7 +418,7 @@ out_no_root:
418static struct dentry *openprom_mount(struct file_system_type *fs_type, 418static struct dentry *openprom_mount(struct file_system_type *fs_type,
419 int flags, const char *dev_name, void *data) 419 int flags, const char *dev_name, void *data)
420{ 420{
421 return mount_single(fs_type, flags, data, openprom_fill_super) 421 return mount_single(fs_type, flags, data, openprom_fill_super);
422} 422}
423 423
424static struct file_system_type openprom_fs_type = { 424static struct file_system_type openprom_fs_type = {
diff --git a/fs/pipe.c b/fs/pipe.c
index a8012a955720..04629f36e397 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1199,12 +1199,24 @@ int pipe_proc_fn(struct ctl_table *table, int write, void __user *buf,
1199 return ret; 1199 return ret;
1200} 1200}
1201 1201
1202/*
1203 * After the inode slimming patch, i_pipe/i_bdev/i_cdev share the same
1204 * location, so checking ->i_pipe is not enough to verify that this is a
1205 * pipe.
1206 */
1207struct pipe_inode_info *get_pipe_info(struct file *file)
1208{
1209 struct inode *i = file->f_path.dentry->d_inode;
1210
1211 return S_ISFIFO(i->i_mode) ? i->i_pipe : NULL;
1212}
1213
1202long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) 1214long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
1203{ 1215{
1204 struct pipe_inode_info *pipe; 1216 struct pipe_inode_info *pipe;
1205 long ret; 1217 long ret;
1206 1218
1207 pipe = file->f_path.dentry->d_inode->i_pipe; 1219 pipe = get_pipe_info(file);
1208 if (!pipe) 1220 if (!pipe)
1209 return -EBADF; 1221 return -EBADF;
1210 1222
diff --git a/fs/proc/base.c b/fs/proc/base.c
index f3d02ca461ec..182845147fe4 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1574,7 +1574,7 @@ static int do_proc_readlink(struct path *path, char __user *buffer, int buflen)
1574 if (!tmp) 1574 if (!tmp)
1575 return -ENOMEM; 1575 return -ENOMEM;
1576 1576
1577 pathname = d_path_with_unreachable(path, tmp, PAGE_SIZE); 1577 pathname = d_path(path, tmp, PAGE_SIZE);
1578 len = PTR_ERR(pathname); 1578 len = PTR_ERR(pathname);
1579 if (IS_ERR(pathname)) 1579 if (IS_ERR(pathname))
1580 goto out; 1580 goto out;
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 9c2b5f484879..3ddb6068177c 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -16,7 +16,6 @@
16#include <linux/limits.h> 16#include <linux/limits.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/smp_lock.h>
20#include <linux/sysctl.h> 19#include <linux/sysctl.h>
21#include <linux/slab.h> 20#include <linux/slab.h>
22 21
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index da6b01d70f01..c126c83b9a45 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -706,6 +706,7 @@ static int pagemap_hugetlb_range(pte_t *pte, unsigned long hmask,
706 * skip over unmapped regions. 706 * skip over unmapped regions.
707 */ 707 */
708#define PAGEMAP_WALK_SIZE (PMD_SIZE) 708#define PAGEMAP_WALK_SIZE (PMD_SIZE)
709#define PAGEMAP_WALK_MASK (PMD_MASK)
709static ssize_t pagemap_read(struct file *file, char __user *buf, 710static ssize_t pagemap_read(struct file *file, char __user *buf,
710 size_t count, loff_t *ppos) 711 size_t count, loff_t *ppos)
711{ 712{
@@ -776,7 +777,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
776 unsigned long end; 777 unsigned long end;
777 778
778 pm.pos = 0; 779 pm.pos = 0;
779 end = start_vaddr + PAGEMAP_WALK_SIZE; 780 end = (start_vaddr + PAGEMAP_WALK_SIZE) & PAGEMAP_WALK_MASK;
780 /* overflow ? */ 781 /* overflow ? */
781 if (end < start_vaddr || end > end_vaddr) 782 if (end < start_vaddr || end > end_vaddr)
782 end = end_vaddr; 783 end = end_vaddr;
diff --git a/fs/read_write.c b/fs/read_write.c
index 431a0ed610c8..5d431bacbea9 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -9,7 +9,6 @@
9#include <linux/fcntl.h> 9#include <linux/fcntl.h>
10#include <linux/file.h> 10#include <linux/file.h>
11#include <linux/uio.h> 11#include <linux/uio.h>
12#include <linux/smp_lock.h>
13#include <linux/fsnotify.h> 12#include <linux/fsnotify.h>
14#include <linux/security.h> 13#include <linux/security.h>
15#include <linux/module.h> 14#include <linux/module.h>
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 41656d40dc5c..0bae036831e2 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -8,7 +8,6 @@
8#include <linux/reiserfs_acl.h> 8#include <linux/reiserfs_acl.h>
9#include <linux/reiserfs_xattr.h> 9#include <linux/reiserfs_xattr.h>
10#include <linux/exportfs.h> 10#include <linux/exportfs.h>
11#include <linux/smp_lock.h>
12#include <linux/pagemap.h> 11#include <linux/pagemap.h>
13#include <linux/highmem.h> 12#include <linux/highmem.h>
14#include <linux/slab.h> 13#include <linux/slab.h>
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index adf22b485cea..79265fdc317a 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -9,7 +9,6 @@
9#include <linux/time.h> 9#include <linux/time.h>
10#include <asm/uaccess.h> 10#include <asm/uaccess.h>
11#include <linux/pagemap.h> 11#include <linux/pagemap.h>
12#include <linux/smp_lock.h>
13#include <linux/compat.h> 12#include <linux/compat.h>
14 13
15/* 14/*
@@ -184,12 +183,11 @@ int reiserfs_unpack(struct inode *inode, struct file *filp)
184 return 0; 183 return 0;
185 } 184 }
186 185
187 /* we need to make sure nobody is changing the file size beneath
188 ** us
189 */
190 reiserfs_mutex_lock_safe(&inode->i_mutex, inode->i_sb);
191 depth = reiserfs_write_lock_once(inode->i_sb); 186 depth = reiserfs_write_lock_once(inode->i_sb);
192 187
188 /* we need to make sure nobody is changing the file size beneath us */
189 reiserfs_mutex_lock_safe(&inode->i_mutex, inode->i_sb);
190
193 write_from = inode->i_size & (blocksize - 1); 191 write_from = inode->i_size & (blocksize - 1);
194 /* if we are on a block boundary, we are already unpacked. */ 192 /* if we are on a block boundary, we are already unpacked. */
195 if (write_from == 0) { 193 if (write_from == 0) {
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 076c8b194682..d31bce1a9f90 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -43,7 +43,6 @@
43#include <linux/fcntl.h> 43#include <linux/fcntl.h>
44#include <linux/stat.h> 44#include <linux/stat.h>
45#include <linux/string.h> 45#include <linux/string.h>
46#include <linux/smp_lock.h>
47#include <linux/buffer_head.h> 46#include <linux/buffer_head.h>
48#include <linux/workqueue.h> 47#include <linux/workqueue.h>
49#include <linux/writeback.h> 48#include <linux/writeback.h>
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 3bf7a6457f4d..b243117b8752 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -28,7 +28,6 @@
28#include <linux/mount.h> 28#include <linux/mount.h>
29#include <linux/namei.h> 29#include <linux/namei.h>
30#include <linux/crc32.h> 30#include <linux/crc32.h>
31#include <linux/smp_lock.h>
32 31
33struct file_system_type reiserfs_fs_type; 32struct file_system_type reiserfs_fs_type;
34 33
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index 536d697a8a28..90d2fcb67a31 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -472,7 +472,9 @@ int reiserfs_acl_chmod(struct inode *inode)
472 struct reiserfs_transaction_handle th; 472 struct reiserfs_transaction_handle th;
473 size_t size = reiserfs_xattr_nblocks(inode, 473 size_t size = reiserfs_xattr_nblocks(inode,
474 reiserfs_acl_size(clone->a_count)); 474 reiserfs_acl_size(clone->a_count));
475 reiserfs_write_lock(inode->i_sb); 475 int depth;
476
477 depth = reiserfs_write_lock_once(inode->i_sb);
476 error = journal_begin(&th, inode->i_sb, size * 2); 478 error = journal_begin(&th, inode->i_sb, size * 2);
477 if (!error) { 479 if (!error) {
478 int error2; 480 int error2;
@@ -482,7 +484,7 @@ int reiserfs_acl_chmod(struct inode *inode)
482 if (error2) 484 if (error2)
483 error = error2; 485 error = error2;
484 } 486 }
485 reiserfs_write_unlock(inode->i_sb); 487 reiserfs_write_unlock_once(inode->i_sb, depth);
486 } 488 }
487 posix_acl_release(clone); 489 posix_acl_release(clone);
488 return error; 490 return error;
diff --git a/fs/splice.c b/fs/splice.c
index 8f1dfaecc8f0..ce2f02579e35 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1311,18 +1311,6 @@ long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
1311static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe, 1311static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe,
1312 struct pipe_inode_info *opipe, 1312 struct pipe_inode_info *opipe,
1313 size_t len, unsigned int flags); 1313 size_t len, unsigned int flags);
1314/*
1315 * After the inode slimming patch, i_pipe/i_bdev/i_cdev share the same
1316 * location, so checking ->i_pipe is not enough to verify that this is a
1317 * pipe.
1318 */
1319static inline struct pipe_inode_info *pipe_info(struct inode *inode)
1320{
1321 if (S_ISFIFO(inode->i_mode))
1322 return inode->i_pipe;
1323
1324 return NULL;
1325}
1326 1314
1327/* 1315/*
1328 * Determine where to splice to/from. 1316 * Determine where to splice to/from.
@@ -1336,8 +1324,8 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1336 loff_t offset, *off; 1324 loff_t offset, *off;
1337 long ret; 1325 long ret;
1338 1326
1339 ipipe = pipe_info(in->f_path.dentry->d_inode); 1327 ipipe = get_pipe_info(in);
1340 opipe = pipe_info(out->f_path.dentry->d_inode); 1328 opipe = get_pipe_info(out);
1341 1329
1342 if (ipipe && opipe) { 1330 if (ipipe && opipe) {
1343 if (off_in || off_out) 1331 if (off_in || off_out)
@@ -1555,7 +1543,7 @@ static long vmsplice_to_user(struct file *file, const struct iovec __user *iov,
1555 int error; 1543 int error;
1556 long ret; 1544 long ret;
1557 1545
1558 pipe = pipe_info(file->f_path.dentry->d_inode); 1546 pipe = get_pipe_info(file);
1559 if (!pipe) 1547 if (!pipe)
1560 return -EBADF; 1548 return -EBADF;
1561 1549
@@ -1642,7 +1630,7 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
1642 }; 1630 };
1643 long ret; 1631 long ret;
1644 1632
1645 pipe = pipe_info(file->f_path.dentry->d_inode); 1633 pipe = get_pipe_info(file);
1646 if (!pipe) 1634 if (!pipe)
1647 return -EBADF; 1635 return -EBADF;
1648 1636
@@ -2022,8 +2010,8 @@ static int link_pipe(struct pipe_inode_info *ipipe,
2022static long do_tee(struct file *in, struct file *out, size_t len, 2010static long do_tee(struct file *in, struct file *out, size_t len,
2023 unsigned int flags) 2011 unsigned int flags)
2024{ 2012{
2025 struct pipe_inode_info *ipipe = pipe_info(in->f_path.dentry->d_inode); 2013 struct pipe_inode_info *ipipe = get_pipe_info(in);
2026 struct pipe_inode_info *opipe = pipe_info(out->f_path.dentry->d_inode); 2014 struct pipe_inode_info *opipe = get_pipe_info(out);
2027 int ret = -EINVAL; 2015 int ret = -EINVAL;
2028 2016
2029 /* 2017 /*
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c
index c9af48fffcd7..691f61223ed6 100644
--- a/fs/xfs/linux-2.6/xfs_aops.c
+++ b/fs/xfs/linux-2.6/xfs_aops.c
@@ -934,7 +934,6 @@ xfs_aops_discard_page(
934 struct xfs_inode *ip = XFS_I(inode); 934 struct xfs_inode *ip = XFS_I(inode);
935 struct buffer_head *bh, *head; 935 struct buffer_head *bh, *head;
936 loff_t offset = page_offset(page); 936 loff_t offset = page_offset(page);
937 ssize_t len = 1 << inode->i_blkbits;
938 937
939 if (!xfs_is_delayed_page(page, IO_DELAY)) 938 if (!xfs_is_delayed_page(page, IO_DELAY))
940 goto out_invalidate; 939 goto out_invalidate;
@@ -949,58 +948,14 @@ xfs_aops_discard_page(
949 xfs_ilock(ip, XFS_ILOCK_EXCL); 948 xfs_ilock(ip, XFS_ILOCK_EXCL);
950 bh = head = page_buffers(page); 949 bh = head = page_buffers(page);
951 do { 950 do {
952 int done;
953 xfs_fileoff_t offset_fsb;
954 xfs_bmbt_irec_t imap;
955 int nimaps = 1;
956 int error; 951 int error;
957 xfs_fsblock_t firstblock; 952 xfs_fileoff_t start_fsb;
958 xfs_bmap_free_t flist;
959 953
960 if (!buffer_delay(bh)) 954 if (!buffer_delay(bh))
961 goto next_buffer; 955 goto next_buffer;
962 956
963 offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); 957 start_fsb = XFS_B_TO_FSBT(ip->i_mount, offset);
964 958 error = xfs_bmap_punch_delalloc_range(ip, start_fsb, 1);
965 /*
966 * Map the range first and check that it is a delalloc extent
967 * before trying to unmap the range. Otherwise we will be
968 * trying to remove a real extent (which requires a
969 * transaction) or a hole, which is probably a bad idea...
970 */
971 error = xfs_bmapi(NULL, ip, offset_fsb, 1,
972 XFS_BMAPI_ENTIRE, NULL, 0, &imap,
973 &nimaps, NULL);
974
975 if (error) {
976 /* something screwed, just bail */
977 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
978 xfs_fs_cmn_err(CE_ALERT, ip->i_mount,
979 "page discard failed delalloc mapping lookup.");
980 }
981 break;
982 }
983 if (!nimaps) {
984 /* nothing there */
985 goto next_buffer;
986 }
987 if (imap.br_startblock != DELAYSTARTBLOCK) {
988 /* been converted, ignore */
989 goto next_buffer;
990 }
991 WARN_ON(imap.br_blockcount == 0);
992
993 /*
994 * Note: while we initialise the firstblock/flist pair, they
995 * should never be used because blocks should never be
996 * allocated or freed for a delalloc extent and hence we need
997 * don't cancel or finish them after the xfs_bunmapi() call.
998 */
999 xfs_bmap_init(&flist, &firstblock);
1000 error = xfs_bunmapi(NULL, ip, offset_fsb, 1, 0, 1, &firstblock,
1001 &flist, &done);
1002
1003 ASSERT(!flist.xbf_count && !flist.xbf_first);
1004 if (error) { 959 if (error) {
1005 /* something screwed, just bail */ 960 /* something screwed, just bail */
1006 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) { 961 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
@@ -1010,7 +965,7 @@ xfs_aops_discard_page(
1010 break; 965 break;
1011 } 966 }
1012next_buffer: 967next_buffer:
1013 offset += len; 968 offset += 1 << inode->i_blkbits;
1014 969
1015 } while ((bh = bh->b_this_page) != head); 970 } while ((bh = bh->b_this_page) != head);
1016 971
@@ -1111,11 +1066,12 @@ xfs_vm_writepage(
1111 uptodate = 0; 1066 uptodate = 0;
1112 1067
1113 /* 1068 /*
1114 * A hole may still be marked uptodate because discard_buffer 1069 * set_page_dirty dirties all buffers in a page, independent
1115 * leaves the flag set. 1070 * of their state. The dirty state however is entirely
1071 * meaningless for holes (!mapped && uptodate), so skip
1072 * buffers covering holes here.
1116 */ 1073 */
1117 if (!buffer_mapped(bh) && buffer_uptodate(bh)) { 1074 if (!buffer_mapped(bh) && buffer_uptodate(bh)) {
1118 ASSERT(!buffer_dirty(bh));
1119 imap_valid = 0; 1075 imap_valid = 0;
1120 continue; 1076 continue;
1121 } 1077 }
@@ -1504,11 +1460,42 @@ xfs_vm_write_failed(
1504 struct inode *inode = mapping->host; 1460 struct inode *inode = mapping->host;
1505 1461
1506 if (to > inode->i_size) { 1462 if (to > inode->i_size) {
1507 struct iattr ia = { 1463 /*
1508 .ia_valid = ATTR_SIZE | ATTR_FORCE, 1464 * punch out the delalloc blocks we have already allocated. We
1509 .ia_size = inode->i_size, 1465 * don't call xfs_setattr() to do this as we may be in the
1510 }; 1466 * middle of a multi-iovec write and so the vfs inode->i_size
1511 xfs_setattr(XFS_I(inode), &ia, XFS_ATTR_NOLOCK); 1467 * will not match the xfs ip->i_size and so it will zero too
1468 * much. Hence we jus truncate the page cache to zero what is
1469 * necessary and punch the delalloc blocks directly.
1470 */
1471 struct xfs_inode *ip = XFS_I(inode);
1472 xfs_fileoff_t start_fsb;
1473 xfs_fileoff_t end_fsb;
1474 int error;
1475
1476 truncate_pagecache(inode, to, inode->i_size);
1477
1478 /*
1479 * Check if there are any blocks that are outside of i_size
1480 * that need to be trimmed back.
1481 */
1482 start_fsb = XFS_B_TO_FSB(ip->i_mount, inode->i_size) + 1;
1483 end_fsb = XFS_B_TO_FSB(ip->i_mount, to);
1484 if (end_fsb <= start_fsb)
1485 return;
1486
1487 xfs_ilock(ip, XFS_ILOCK_EXCL);
1488 error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
1489 end_fsb - start_fsb);
1490 if (error) {
1491 /* something screwed, just bail */
1492 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
1493 xfs_fs_cmn_err(CE_ALERT, ip->i_mount,
1494 "xfs_vm_write_failed: unable to clean up ino %lld",
1495 ip->i_ino);
1496 }
1497 }
1498 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1512 } 1499 }
1513} 1500}
1514 1501
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index 63fd2c07cb57..4c5deb6e9e31 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -488,29 +488,16 @@ found:
488 spin_unlock(&pag->pag_buf_lock); 488 spin_unlock(&pag->pag_buf_lock);
489 xfs_perag_put(pag); 489 xfs_perag_put(pag);
490 490
491 /* Attempt to get the semaphore without sleeping, 491 if (xfs_buf_cond_lock(bp)) {
492 * if this does not work then we need to drop the 492 /* failed, so wait for the lock if requested. */
493 * spinlock and do a hard attempt on the semaphore.
494 */
495 if (down_trylock(&bp->b_sema)) {
496 if (!(flags & XBF_TRYLOCK)) { 493 if (!(flags & XBF_TRYLOCK)) {
497 /* wait for buffer ownership */
498 xfs_buf_lock(bp); 494 xfs_buf_lock(bp);
499 XFS_STATS_INC(xb_get_locked_waited); 495 XFS_STATS_INC(xb_get_locked_waited);
500 } else { 496 } else {
501 /* We asked for a trylock and failed, no need
502 * to look at file offset and length here, we
503 * know that this buffer at least overlaps our
504 * buffer and is locked, therefore our buffer
505 * either does not exist, or is this buffer.
506 */
507 xfs_buf_rele(bp); 497 xfs_buf_rele(bp);
508 XFS_STATS_INC(xb_busy_locked); 498 XFS_STATS_INC(xb_busy_locked);
509 return NULL; 499 return NULL;
510 } 500 }
511 } else {
512 /* trylock worked */
513 XB_SET_OWNER(bp);
514 } 501 }
515 502
516 if (bp->b_flags & XBF_STALE) { 503 if (bp->b_flags & XBF_STALE) {
@@ -876,10 +863,18 @@ xfs_buf_rele(
876 */ 863 */
877 864
878/* 865/*
879 * Locks a buffer object, if it is not already locked. 866 * Locks a buffer object, if it is not already locked. Note that this in
880 * Note that this in no way locks the underlying pages, so it is only 867 * no way locks the underlying pages, so it is only useful for
881 * useful for synchronizing concurrent use of buffer objects, not for 868 * synchronizing concurrent use of buffer objects, not for synchronizing
882 * synchronizing independent access to the underlying pages. 869 * independent access to the underlying pages.
870 *
871 * If we come across a stale, pinned, locked buffer, we know that we are
872 * being asked to lock a buffer that has been reallocated. Because it is
873 * pinned, we know that the log has not been pushed to disk and hence it
874 * will still be locked. Rather than continuing to have trylock attempts
875 * fail until someone else pushes the log, push it ourselves before
876 * returning. This means that the xfsaild will not get stuck trying
877 * to push on stale inode buffers.
883 */ 878 */
884int 879int
885xfs_buf_cond_lock( 880xfs_buf_cond_lock(
@@ -890,6 +885,8 @@ xfs_buf_cond_lock(
890 locked = down_trylock(&bp->b_sema) == 0; 885 locked = down_trylock(&bp->b_sema) == 0;
891 if (locked) 886 if (locked)
892 XB_SET_OWNER(bp); 887 XB_SET_OWNER(bp);
888 else if (atomic_read(&bp->b_pin_count) && (bp->b_flags & XBF_STALE))
889 xfs_log_force(bp->b_target->bt_mount, 0);
893 890
894 trace_xfs_buf_cond_lock(bp, _RET_IP_); 891 trace_xfs_buf_cond_lock(bp, _RET_IP_);
895 return locked ? 0 : -EBUSY; 892 return locked ? 0 : -EBUSY;
@@ -1781,7 +1778,6 @@ xfs_buf_delwri_split(
1781 INIT_LIST_HEAD(list); 1778 INIT_LIST_HEAD(list);
1782 spin_lock(dwlk); 1779 spin_lock(dwlk);
1783 list_for_each_entry_safe(bp, n, dwq, b_list) { 1780 list_for_each_entry_safe(bp, n, dwq, b_list) {
1784 trace_xfs_buf_delwri_split(bp, _RET_IP_);
1785 ASSERT(bp->b_flags & XBF_DELWRI); 1781 ASSERT(bp->b_flags & XBF_DELWRI);
1786 1782
1787 if (!XFS_BUF_ISPINNED(bp) && !xfs_buf_cond_lock(bp)) { 1783 if (!XFS_BUF_ISPINNED(bp) && !xfs_buf_cond_lock(bp)) {
@@ -1795,6 +1791,7 @@ xfs_buf_delwri_split(
1795 _XBF_RUN_QUEUES); 1791 _XBF_RUN_QUEUES);
1796 bp->b_flags |= XBF_WRITE; 1792 bp->b_flags |= XBF_WRITE;
1797 list_move_tail(&bp->b_list, list); 1793 list_move_tail(&bp->b_list, list);
1794 trace_xfs_buf_delwri_split(bp, _RET_IP_);
1798 } else 1795 } else
1799 skipped++; 1796 skipped++;
1800 } 1797 }
diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
index 2ea238f6d38e..ad442d9e392e 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
@@ -416,7 +416,7 @@ xfs_attrlist_by_handle(
416 if (IS_ERR(dentry)) 416 if (IS_ERR(dentry))
417 return PTR_ERR(dentry); 417 return PTR_ERR(dentry);
418 418
419 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL); 419 kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
420 if (!kbuf) 420 if (!kbuf)
421 goto out_dput; 421 goto out_dput;
422 422
diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
index 96107efc0c61..94d5fd6a2973 100644
--- a/fs/xfs/linux-2.6/xfs_iops.c
+++ b/fs/xfs/linux-2.6/xfs_iops.c
@@ -762,7 +762,8 @@ xfs_setup_inode(
762 inode->i_state = I_NEW; 762 inode->i_state = I_NEW;
763 763
764 inode_sb_list_add(inode); 764 inode_sb_list_add(inode);
765 insert_inode_hash(inode); 765 /* make the inode look hashed for the writeback code */
766 hlist_add_fake(&inode->i_hash);
766 767
767 inode->i_mode = ip->i_d.di_mode; 768 inode->i_mode = ip->i_d.di_mode;
768 inode->i_nlink = ip->i_d.di_nlink; 769 inode->i_nlink = ip->i_d.di_nlink;
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index 7465a7ffc4fd..c115dd5e95a8 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -353,9 +353,6 @@ xfs_parseargs(
353 mp->m_qflags &= ~XFS_OQUOTA_ENFD; 353 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
354 } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) { 354 } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
355 mp->m_flags |= XFS_MOUNT_DELAYLOG; 355 mp->m_flags |= XFS_MOUNT_DELAYLOG;
356 cmn_err(CE_WARN,
357 "Enabling EXPERIMENTAL delayed logging feature "
358 "- use at your own risk.\n");
359 } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) { 356 } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
360 mp->m_flags &= ~XFS_MOUNT_DELAYLOG; 357 mp->m_flags &= ~XFS_MOUNT_DELAYLOG;
361 } else if (!strcmp(this_char, "ihashsize")) { 358 } else if (!strcmp(this_char, "ihashsize")) {
diff --git a/fs/xfs/linux-2.6/xfs_sync.c b/fs/xfs/linux-2.6/xfs_sync.c
index 37d33254981d..afb0d7cfad1c 100644
--- a/fs/xfs/linux-2.6/xfs_sync.c
+++ b/fs/xfs/linux-2.6/xfs_sync.c
@@ -853,6 +853,7 @@ restart:
853 if (trylock) { 853 if (trylock) {
854 if (!mutex_trylock(&pag->pag_ici_reclaim_lock)) { 854 if (!mutex_trylock(&pag->pag_ici_reclaim_lock)) {
855 skipped++; 855 skipped++;
856 xfs_perag_put(pag);
856 continue; 857 continue;
857 } 858 }
858 first_index = pag->pag_ici_reclaim_cursor; 859 first_index = pag->pag_ici_reclaim_cursor;
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index 8abd12e32e13..4111cd3966c7 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -5471,8 +5471,13 @@ xfs_getbmap(
5471 if (error) 5471 if (error)
5472 goto out_unlock_iolock; 5472 goto out_unlock_iolock;
5473 } 5473 }
5474 5474 /*
5475 ASSERT(ip->i_delayed_blks == 0); 5475 * even after flushing the inode, there can still be delalloc
5476 * blocks on the inode beyond EOF due to speculative
5477 * preallocation. These are not removed until the release
5478 * function is called or the inode is inactivated. Hence we
5479 * cannot assert here that ip->i_delayed_blks == 0.
5480 */
5476 } 5481 }
5477 5482
5478 lock = xfs_ilock_map_shared(ip); 5483 lock = xfs_ilock_map_shared(ip);
@@ -6070,3 +6075,79 @@ xfs_bmap_disk_count_leaves(
6070 *count += xfs_bmbt_disk_get_blockcount(frp); 6075 *count += xfs_bmbt_disk_get_blockcount(frp);
6071 } 6076 }
6072} 6077}
6078
6079/*
6080 * dead simple method of punching delalyed allocation blocks from a range in
6081 * the inode. Walks a block at a time so will be slow, but is only executed in
6082 * rare error cases so the overhead is not critical. This will alays punch out
6083 * both the start and end blocks, even if the ranges only partially overlap
6084 * them, so it is up to the caller to ensure that partial blocks are not
6085 * passed in.
6086 */
6087int
6088xfs_bmap_punch_delalloc_range(
6089 struct xfs_inode *ip,
6090 xfs_fileoff_t start_fsb,
6091 xfs_fileoff_t length)
6092{
6093 xfs_fileoff_t remaining = length;
6094 int error = 0;
6095
6096 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
6097
6098 do {
6099 int done;
6100 xfs_bmbt_irec_t imap;
6101 int nimaps = 1;
6102 xfs_fsblock_t firstblock;
6103 xfs_bmap_free_t flist;
6104
6105 /*
6106 * Map the range first and check that it is a delalloc extent
6107 * before trying to unmap the range. Otherwise we will be
6108 * trying to remove a real extent (which requires a
6109 * transaction) or a hole, which is probably a bad idea...
6110 */
6111 error = xfs_bmapi(NULL, ip, start_fsb, 1,
6112 XFS_BMAPI_ENTIRE, NULL, 0, &imap,
6113 &nimaps, NULL);
6114
6115 if (error) {
6116 /* something screwed, just bail */
6117 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
6118 xfs_fs_cmn_err(CE_ALERT, ip->i_mount,
6119 "Failed delalloc mapping lookup ino %lld fsb %lld.",
6120 ip->i_ino, start_fsb);
6121 }
6122 break;
6123 }
6124 if (!nimaps) {
6125 /* nothing there */
6126 goto next_block;
6127 }
6128 if (imap.br_startblock != DELAYSTARTBLOCK) {
6129 /* been converted, ignore */
6130 goto next_block;
6131 }
6132 WARN_ON(imap.br_blockcount == 0);
6133
6134 /*
6135 * Note: while we initialise the firstblock/flist pair, they
6136 * should never be used because blocks should never be
6137 * allocated or freed for a delalloc extent and hence we need
6138 * don't cancel or finish them after the xfs_bunmapi() call.
6139 */
6140 xfs_bmap_init(&flist, &firstblock);
6141 error = xfs_bunmapi(NULL, ip, start_fsb, 1, 0, 1, &firstblock,
6142 &flist, &done);
6143 if (error)
6144 break;
6145
6146 ASSERT(!flist.xbf_count && !flist.xbf_first);
6147next_block:
6148 start_fsb++;
6149 remaining--;
6150 } while(remaining > 0);
6151
6152 return error;
6153}
diff --git a/fs/xfs/xfs_bmap.h b/fs/xfs/xfs_bmap.h
index 71ec9b6ecdfc..3651191daea1 100644
--- a/fs/xfs/xfs_bmap.h
+++ b/fs/xfs/xfs_bmap.h
@@ -394,6 +394,11 @@ xfs_bmap_count_blocks(
394 int whichfork, 394 int whichfork,
395 int *count); 395 int *count);
396 396
397int
398xfs_bmap_punch_delalloc_range(
399 struct xfs_inode *ip,
400 xfs_fileoff_t start_fsb,
401 xfs_fileoff_t length);
397#endif /* __KERNEL__ */ 402#endif /* __KERNEL__ */
398 403
399#endif /* __XFS_BMAP_H__ */ 404#endif /* __XFS_BMAP_H__ */
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c
index 3b9582c60a22..e60490bc00a6 100644
--- a/fs/xfs/xfs_dfrag.c
+++ b/fs/xfs/xfs_dfrag.c
@@ -377,6 +377,19 @@ xfs_swap_extents(
377 ip->i_d.di_format = tip->i_d.di_format; 377 ip->i_d.di_format = tip->i_d.di_format;
378 tip->i_d.di_format = tmp; 378 tip->i_d.di_format = tmp;
379 379
380 /*
381 * The extents in the source inode could still contain speculative
382 * preallocation beyond EOF (e.g. the file is open but not modified
383 * while defrag is in progress). In that case, we need to copy over the
384 * number of delalloc blocks the data fork in the source inode is
385 * tracking beyond EOF so that when the fork is truncated away when the
386 * temporary inode is unlinked we don't underrun the i_delayed_blks
387 * counter on that inode.
388 */
389 ASSERT(tip->i_delayed_blks == 0);
390 tip->i_delayed_blks = ip->i_delayed_blks;
391 ip->i_delayed_blks = 0;
392
380 ilf_fields = XFS_ILOG_CORE; 393 ilf_fields = XFS_ILOG_CORE;
381 394
382 switch(ip->i_d.di_format) { 395 switch(ip->i_d.di_format) {
diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c
index ed9990267661..c78cc6a3d87c 100644
--- a/fs/xfs/xfs_error.c
+++ b/fs/xfs/xfs_error.c
@@ -58,6 +58,7 @@ xfs_error_trap(int e)
58int xfs_etest[XFS_NUM_INJECT_ERROR]; 58int xfs_etest[XFS_NUM_INJECT_ERROR];
59int64_t xfs_etest_fsid[XFS_NUM_INJECT_ERROR]; 59int64_t xfs_etest_fsid[XFS_NUM_INJECT_ERROR];
60char * xfs_etest_fsname[XFS_NUM_INJECT_ERROR]; 60char * xfs_etest_fsname[XFS_NUM_INJECT_ERROR];
61int xfs_error_test_active;
61 62
62int 63int
63xfs_error_test(int error_tag, int *fsidp, char *expression, 64xfs_error_test(int error_tag, int *fsidp, char *expression,
@@ -108,6 +109,7 @@ xfs_errortag_add(int error_tag, xfs_mount_t *mp)
108 len = strlen(mp->m_fsname); 109 len = strlen(mp->m_fsname);
109 xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP); 110 xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP);
110 strcpy(xfs_etest_fsname[i], mp->m_fsname); 111 strcpy(xfs_etest_fsname[i], mp->m_fsname);
112 xfs_error_test_active++;
111 return 0; 113 return 0;
112 } 114 }
113 } 115 }
@@ -137,6 +139,7 @@ xfs_errortag_clearall(xfs_mount_t *mp, int loud)
137 xfs_etest_fsid[i] = 0LL; 139 xfs_etest_fsid[i] = 0LL;
138 kmem_free(xfs_etest_fsname[i]); 140 kmem_free(xfs_etest_fsname[i]);
139 xfs_etest_fsname[i] = NULL; 141 xfs_etest_fsname[i] = NULL;
142 xfs_error_test_active--;
140 } 143 }
141 } 144 }
142 145
diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h
index c2c1a072bb82..f338847f80b8 100644
--- a/fs/xfs/xfs_error.h
+++ b/fs/xfs/xfs_error.h
@@ -127,13 +127,14 @@ extern void xfs_corruption_error(const char *tag, int level,
127#define XFS_RANDOM_BMAPIFORMAT XFS_RANDOM_DEFAULT 127#define XFS_RANDOM_BMAPIFORMAT XFS_RANDOM_DEFAULT
128 128
129#ifdef DEBUG 129#ifdef DEBUG
130extern int xfs_error_test_active;
130extern int xfs_error_test(int, int *, char *, int, char *, unsigned long); 131extern int xfs_error_test(int, int *, char *, int, char *, unsigned long);
131 132
132#define XFS_NUM_INJECT_ERROR 10 133#define XFS_NUM_INJECT_ERROR 10
133#define XFS_TEST_ERROR(expr, mp, tag, rf) \ 134#define XFS_TEST_ERROR(expr, mp, tag, rf) \
134 ((expr) || \ 135 ((expr) || (xfs_error_test_active && \
135 xfs_error_test((tag), (mp)->m_fixedfsid, "expr", __LINE__, __FILE__, \ 136 xfs_error_test((tag), (mp)->m_fixedfsid, "expr", __LINE__, __FILE__, \
136 (rf))) 137 (rf))))
137 138
138extern int xfs_errortag_add(int error_tag, xfs_mount_t *mp); 139extern int xfs_errortag_add(int error_tag, xfs_mount_t *mp);
139extern int xfs_errortag_clearall(xfs_mount_t *mp, int loud); 140extern int xfs_errortag_clearall(xfs_mount_t *mp, int loud);
diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c
index 9b715dce5699..9124425b7f2f 100644
--- a/fs/xfs/xfs_filestream.c
+++ b/fs/xfs/xfs_filestream.c
@@ -744,9 +744,15 @@ xfs_filestream_new_ag(
744 * If the file's parent directory is known, take its iolock in exclusive 744 * If the file's parent directory is known, take its iolock in exclusive
745 * mode to prevent two sibling files from racing each other to migrate 745 * mode to prevent two sibling files from racing each other to migrate
746 * themselves and their parent to different AGs. 746 * themselves and their parent to different AGs.
747 *
748 * Note that we lock the parent directory iolock inside the child
749 * iolock here. That's fine as we never hold both parent and child
750 * iolock in any other place. This is different from the ilock,
751 * which requires locking of the child after the parent for namespace
752 * operations.
747 */ 753 */
748 if (pip) 754 if (pip)
749 xfs_ilock(pip, XFS_IOLOCK_EXCL); 755 xfs_ilock(pip, XFS_IOLOCK_EXCL | XFS_IOLOCK_PARENT);
750 756
751 /* 757 /*
752 * A new AG needs to be found for the file. If the file's parent 758 * A new AG needs to be found for the file. If the file's parent
diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
index c7ac020705df..7c8d30c453c3 100644
--- a/fs/xfs/xfs_inode_item.c
+++ b/fs/xfs/xfs_inode_item.c
@@ -657,18 +657,37 @@ xfs_inode_item_unlock(
657} 657}
658 658
659/* 659/*
660 * This is called to find out where the oldest active copy of the 660 * This is called to find out where the oldest active copy of the inode log
661 * inode log item in the on disk log resides now that the last log 661 * item in the on disk log resides now that the last log write of it completed
662 * write of it completed at the given lsn. Since we always re-log 662 * at the given lsn. Since we always re-log all dirty data in an inode, the
663 * all dirty data in an inode, the latest copy in the on disk log 663 * latest copy in the on disk log is the only one that matters. Therefore,
664 * is the only one that matters. Therefore, simply return the 664 * simply return the given lsn.
665 * given lsn. 665 *
666 * If the inode has been marked stale because the cluster is being freed, we
667 * don't want to (re-)insert this inode into the AIL. There is a race condition
668 * where the cluster buffer may be unpinned before the inode is inserted into
669 * the AIL during transaction committed processing. If the buffer is unpinned
670 * before the inode item has been committed and inserted, then it is possible
671 * for the buffer to be written and IO completions before the inode is inserted
672 * into the AIL. In that case, we'd be inserting a clean, stale inode into the
673 * AIL which will never get removed. It will, however, get reclaimed which
674 * triggers an assert in xfs_inode_free() complaining about freein an inode
675 * still in the AIL.
676 *
677 * To avoid this, return a lower LSN than the one passed in so that the
678 * transaction committed code will not move the inode forward in the AIL but
679 * will still unpin it properly.
666 */ 680 */
667STATIC xfs_lsn_t 681STATIC xfs_lsn_t
668xfs_inode_item_committed( 682xfs_inode_item_committed(
669 struct xfs_log_item *lip, 683 struct xfs_log_item *lip,
670 xfs_lsn_t lsn) 684 xfs_lsn_t lsn)
671{ 685{
686 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
687 struct xfs_inode *ip = iip->ili_inode;
688
689 if (xfs_iflags_test(ip, XFS_ISTALE))
690 return lsn - 1;
672 return lsn; 691 return lsn;
673} 692}
674 693
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index b1498ab5a399..19e9dfa1c254 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -275,6 +275,7 @@ xfs_free_perag(
275 pag = radix_tree_delete(&mp->m_perag_tree, agno); 275 pag = radix_tree_delete(&mp->m_perag_tree, agno);
276 spin_unlock(&mp->m_perag_lock); 276 spin_unlock(&mp->m_perag_lock);
277 ASSERT(pag); 277 ASSERT(pag);
278 ASSERT(atomic_read(&pag->pag_ref) == 0);
278 call_rcu(&pag->rcu_head, __xfs_free_perag); 279 call_rcu(&pag->rcu_head, __xfs_free_perag);
279 } 280 }
280} 281}
diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
index e0e64b113bd6..9bb6eda4cd21 100644
--- a/fs/xfs/xfs_quota.h
+++ b/fs/xfs/xfs_quota.h
@@ -346,8 +346,17 @@ xfs_qm_vop_dqalloc(struct xfs_inode *ip, uid_t uid, gid_t gid, prid_t prid,
346#define xfs_trans_mod_dquot_byino(tp, ip, fields, delta) 346#define xfs_trans_mod_dquot_byino(tp, ip, fields, delta)
347#define xfs_trans_apply_dquot_deltas(tp) 347#define xfs_trans_apply_dquot_deltas(tp)
348#define xfs_trans_unreserve_and_mod_dquots(tp) 348#define xfs_trans_unreserve_and_mod_dquots(tp)
349#define xfs_trans_reserve_quota_nblks(tp, ip, nblks, ninos, flags) (0) 349static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
350#define xfs_trans_reserve_quota_bydquots(tp, mp, u, g, nb, ni, fl) (0) 350 struct xfs_inode *ip, long nblks, long ninos, uint flags)
351{
352 return 0;
353}
354static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
355 struct xfs_mount *mp, struct xfs_dquot *udqp,
356 struct xfs_dquot *gdqp, long nblks, long nions, uint flags)
357{
358 return 0;
359}
351#define xfs_qm_vop_create_dqattach(tp, ip, u, g) 360#define xfs_qm_vop_create_dqattach(tp, ip, u, g)
352#define xfs_qm_vop_rename_dqattach(it) (0) 361#define xfs_qm_vop_rename_dqattach(it) (0)
353#define xfs_qm_vop_chown(tp, ip, old, new) (NULL) 362#define xfs_qm_vop_chown(tp, ip, old, new) (NULL)
@@ -357,11 +366,14 @@ xfs_qm_vop_dqalloc(struct xfs_inode *ip, uid_t uid, gid_t gid, prid_t prid,
357#define xfs_qm_dqdetach(ip) 366#define xfs_qm_dqdetach(ip)
358#define xfs_qm_dqrele(d) 367#define xfs_qm_dqrele(d)
359#define xfs_qm_statvfs(ip, s) 368#define xfs_qm_statvfs(ip, s)
360#define xfs_qm_sync(mp, fl) (0) 369static inline int xfs_qm_sync(struct xfs_mount *mp, int flags)
370{
371 return 0;
372}
361#define xfs_qm_newmount(mp, a, b) (0) 373#define xfs_qm_newmount(mp, a, b) (0)
362#define xfs_qm_mount_quotas(mp) 374#define xfs_qm_mount_quotas(mp)
363#define xfs_qm_unmount(mp) 375#define xfs_qm_unmount(mp)
364#define xfs_qm_unmount_quotas(mp) (0) 376#define xfs_qm_unmount_quotas(mp)
365#endif /* CONFIG_XFS_QUOTA */ 377#endif /* CONFIG_XFS_QUOTA */
366 378
367#define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \ 379#define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
diff --git a/fs/xfs/xfs_rename.c b/fs/xfs/xfs_rename.c
index d2af0a8381a6..77a59891734e 100644
--- a/fs/xfs/xfs_rename.c
+++ b/fs/xfs/xfs_rename.c
@@ -297,6 +297,7 @@ xfs_rename(
297 * it and some incremental backup programs won't work without it. 297 * it and some incremental backup programs won't work without it.
298 */ 298 */
299 xfs_trans_ichgtime(tp, src_ip, XFS_ICHGTIME_CHG); 299 xfs_trans_ichgtime(tp, src_ip, XFS_ICHGTIME_CHG);
300 xfs_trans_log_inode(tp, src_ip, XFS_ILOG_CORE);
300 301
301 /* 302 /*
302 * Adjust the link count on src_dp. This is necessary when 303 * Adjust the link count on src_dp. This is necessary when
diff --git a/include/acpi/video.h b/include/acpi/video.h
index 551793c9b6e8..0e98e679d3a7 100644
--- a/include/acpi/video.h
+++ b/include/acpi/video.h
@@ -1,6 +1,10 @@
1#ifndef __ACPI_VIDEO_H 1#ifndef __ACPI_VIDEO_H
2#define __ACPI_VIDEO_H 2#define __ACPI_VIDEO_H
3 3
4#include <linux/errno.h> /* for ENODEV */
5
6struct acpi_device;
7
4#define ACPI_VIDEO_DISPLAY_CRT 1 8#define ACPI_VIDEO_DISPLAY_CRT 1
5#define ACPI_VIDEO_DISPLAY_TV 2 9#define ACPI_VIDEO_DISPLAY_TV 2
6#define ACPI_VIDEO_DISPLAY_DVI 3 10#define ACPI_VIDEO_DISPLAY_DVI 3
@@ -26,4 +30,3 @@ static inline int acpi_video_get_edid(struct acpi_device *device, int type,
26#endif 30#endif
27 31
28#endif 32#endif
29
diff --git a/include/asm-generic/stat.h b/include/asm-generic/stat.h
index 47e64170305d..bd8cad21998e 100644
--- a/include/asm-generic/stat.h
+++ b/include/asm-generic/stat.h
@@ -33,18 +33,18 @@ struct stat {
33 int st_blksize; /* Optimal block size for I/O. */ 33 int st_blksize; /* Optimal block size for I/O. */
34 int __pad2; 34 int __pad2;
35 long st_blocks; /* Number 512-byte blocks allocated. */ 35 long st_blocks; /* Number 512-byte blocks allocated. */
36 int st_atime; /* Time of last access. */ 36 long st_atime; /* Time of last access. */
37 unsigned int st_atime_nsec; 37 unsigned long st_atime_nsec;
38 int st_mtime; /* Time of last modification. */ 38 long st_mtime; /* Time of last modification. */
39 unsigned int st_mtime_nsec; 39 unsigned long st_mtime_nsec;
40 int st_ctime; /* Time of last status change. */ 40 long st_ctime; /* Time of last status change. */
41 unsigned int st_ctime_nsec; 41 unsigned long st_ctime_nsec;
42 unsigned int __unused4; 42 unsigned int __unused4;
43 unsigned int __unused5; 43 unsigned int __unused5;
44}; 44};
45 45
46#if __BITS_PER_LONG != 64
47/* This matches struct stat64 in glibc2.1. Only used for 32 bit. */ 46/* This matches struct stat64 in glibc2.1. Only used for 32 bit. */
47#if __BITS_PER_LONG != 64 || defined(__ARCH_WANT_STAT64)
48struct stat64 { 48struct stat64 {
49 unsigned long long st_dev; /* Device. */ 49 unsigned long long st_dev; /* Device. */
50 unsigned long long st_ino; /* File serial number. */ 50 unsigned long long st_ino; /* File serial number. */
diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h
index 8c641bed9bbd..a2776e2807a4 100644
--- a/include/drm/i915_drm.h
+++ b/include/drm/i915_drm.h
@@ -287,6 +287,8 @@ typedef struct drm_i915_irq_wait {
287#define I915_PARAM_HAS_EXECBUF2 9 287#define I915_PARAM_HAS_EXECBUF2 9
288#define I915_PARAM_HAS_BSD 10 288#define I915_PARAM_HAS_BSD 10
289#define I915_PARAM_HAS_BLT 11 289#define I915_PARAM_HAS_BLT 11
290#define I915_PARAM_HAS_RELAXED_FENCING 12
291#define I915_PARAM_HAS_COHERENT_RINGS 13
290 292
291typedef struct drm_i915_getparam { 293typedef struct drm_i915_getparam {
292 int param; 294 int param;
diff --git a/include/drm/nouveau_drm.h b/include/drm/nouveau_drm.h
index 01a714119506..bc5590b1a1ac 100644
--- a/include/drm/nouveau_drm.h
+++ b/include/drm/nouveau_drm.h
@@ -80,6 +80,7 @@ struct drm_nouveau_gpuobj_free {
80#define NOUVEAU_GETPARAM_VM_VRAM_BASE 12 80#define NOUVEAU_GETPARAM_VM_VRAM_BASE 12
81#define NOUVEAU_GETPARAM_GRAPH_UNITS 13 81#define NOUVEAU_GETPARAM_GRAPH_UNITS 13
82#define NOUVEAU_GETPARAM_PTIMER_TIME 14 82#define NOUVEAU_GETPARAM_PTIMER_TIME 14
83#define NOUVEAU_GETPARAM_HAS_BO_USAGE 15
83struct drm_nouveau_getparam { 84struct drm_nouveau_getparam {
84 uint64_t param; 85 uint64_t param;
85 uint64_t value; 86 uint64_t value;
@@ -95,6 +96,12 @@ struct drm_nouveau_setparam {
95#define NOUVEAU_GEM_DOMAIN_GART (1 << 2) 96#define NOUVEAU_GEM_DOMAIN_GART (1 << 2)
96#define NOUVEAU_GEM_DOMAIN_MAPPABLE (1 << 3) 97#define NOUVEAU_GEM_DOMAIN_MAPPABLE (1 << 3)
97 98
99#define NOUVEAU_GEM_TILE_LAYOUT_MASK 0x0000ff00
100#define NOUVEAU_GEM_TILE_16BPP 0x00000001
101#define NOUVEAU_GEM_TILE_32BPP 0x00000002
102#define NOUVEAU_GEM_TILE_ZETA 0x00000004
103#define NOUVEAU_GEM_TILE_NONCONTIG 0x00000008
104
98struct drm_nouveau_gem_info { 105struct drm_nouveau_gem_info {
99 uint32_t handle; 106 uint32_t handle;
100 uint32_t domain; 107 uint32_t domain;
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 5afa5b52063e..beafc156a535 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -432,6 +432,10 @@ extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo);
432 * together with the @destroy function, 432 * together with the @destroy function,
433 * enables driver-specific objects derived from a ttm_buffer_object. 433 * enables driver-specific objects derived from a ttm_buffer_object.
434 * On successful return, the object kref and list_kref are set to 1. 434 * On successful return, the object kref and list_kref are set to 1.
435 * If a failure occurs, the function will call the @destroy function, or
436 * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
437 * illegal and will likely cause memory corruption.
438 *
435 * Returns 439 * Returns
436 * -ENOMEM: Out of memory. 440 * -ENOMEM: Out of memory.
437 * -EINVAL: Invalid placement flags. 441 * -EINVAL: Invalid placement flags.
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index d01b4ddbdc56..8e0c848326b6 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -206,14 +206,84 @@ struct ttm_tt {
206struct ttm_mem_type_manager; 206struct ttm_mem_type_manager;
207 207
208struct ttm_mem_type_manager_func { 208struct ttm_mem_type_manager_func {
209 /**
210 * struct ttm_mem_type_manager member init
211 *
212 * @man: Pointer to a memory type manager.
213 * @p_size: Implementation dependent, but typically the size of the
214 * range to be managed in pages.
215 *
216 * Called to initialize a private range manager. The function is
217 * expected to initialize the man::priv member.
218 * Returns 0 on success, negative error code on failure.
219 */
209 int (*init)(struct ttm_mem_type_manager *man, unsigned long p_size); 220 int (*init)(struct ttm_mem_type_manager *man, unsigned long p_size);
221
222 /**
223 * struct ttm_mem_type_manager member takedown
224 *
225 * @man: Pointer to a memory type manager.
226 *
227 * Called to undo the setup done in init. All allocated resources
228 * should be freed.
229 */
210 int (*takedown)(struct ttm_mem_type_manager *man); 230 int (*takedown)(struct ttm_mem_type_manager *man);
231
232 /**
233 * struct ttm_mem_type_manager member get_node
234 *
235 * @man: Pointer to a memory type manager.
236 * @bo: Pointer to the buffer object we're allocating space for.
237 * @placement: Placement details.
238 * @mem: Pointer to a struct ttm_mem_reg to be filled in.
239 *
240 * This function should allocate space in the memory type managed
241 * by @man. Placement details if
242 * applicable are given by @placement. If successful,
243 * @mem::mm_node should be set to a non-null value, and
244 * @mem::start should be set to a value identifying the beginning
245 * of the range allocated, and the function should return zero.
246 * If the memory region accomodate the buffer object, @mem::mm_node
247 * should be set to NULL, and the function should return 0.
248 * If a system error occured, preventing the request to be fulfilled,
249 * the function should return a negative error code.
250 *
251 * Note that @mem::mm_node will only be dereferenced by
252 * struct ttm_mem_type_manager functions and optionally by the driver,
253 * which has knowledge of the underlying type.
254 *
255 * This function may not be called from within atomic context, so
256 * an implementation can and must use either a mutex or a spinlock to
257 * protect any data structures managing the space.
258 */
211 int (*get_node)(struct ttm_mem_type_manager *man, 259 int (*get_node)(struct ttm_mem_type_manager *man,
212 struct ttm_buffer_object *bo, 260 struct ttm_buffer_object *bo,
213 struct ttm_placement *placement, 261 struct ttm_placement *placement,
214 struct ttm_mem_reg *mem); 262 struct ttm_mem_reg *mem);
263
264 /**
265 * struct ttm_mem_type_manager member put_node
266 *
267 * @man: Pointer to a memory type manager.
268 * @mem: Pointer to a struct ttm_mem_reg to be filled in.
269 *
270 * This function frees memory type resources previously allocated
271 * and that are identified by @mem::mm_node and @mem::start. May not
272 * be called from within atomic context.
273 */
215 void (*put_node)(struct ttm_mem_type_manager *man, 274 void (*put_node)(struct ttm_mem_type_manager *man,
216 struct ttm_mem_reg *mem); 275 struct ttm_mem_reg *mem);
276
277 /**
278 * struct ttm_mem_type_manager member debug
279 *
280 * @man: Pointer to a memory type manager.
281 * @prefix: Prefix to be used in printout to identify the caller.
282 *
283 * This function is called to print out the state of the memory
284 * type manager to aid debugging of out-of-memory conditions.
285 * It may not be called from within atomic context.
286 */
217 void (*debug)(struct ttm_mem_type_manager *man, const char *prefix); 287 void (*debug)(struct ttm_mem_type_manager *man, const char *prefix);
218}; 288};
219 289
@@ -231,14 +301,13 @@ struct ttm_mem_type_manager {
231 uint64_t size; 301 uint64_t size;
232 uint32_t available_caching; 302 uint32_t available_caching;
233 uint32_t default_caching; 303 uint32_t default_caching;
304 const struct ttm_mem_type_manager_func *func;
305 void *priv;
234 306
235 /* 307 /*
236 * Protected by the bdev->lru_lock. 308 * Protected by the global->lru_lock.
237 * TODO: Consider one lru_lock per ttm_mem_type_manager.
238 * Plays ill with list removal, though.
239 */ 309 */
240 const struct ttm_mem_type_manager_func *func; 310
241 void *priv;
242 struct list_head lru; 311 struct list_head lru;
243}; 312};
244 313
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 050a7bccb836..67c91b4418b0 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -219,7 +219,7 @@ static inline int acpi_video_display_switch_support(void)
219 219
220extern int acpi_blacklisted(void); 220extern int acpi_blacklisted(void);
221extern void acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d); 221extern void acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d);
222extern int acpi_osi_setup(char *str); 222extern void acpi_osi_setup(char *str);
223 223
224#ifdef CONFIG_ACPI_NUMA 224#ifdef CONFIG_ACPI_NUMA
225int acpi_get_pxm(acpi_handle handle); 225int acpi_get_pxm(acpi_handle handle);
diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
index a8e4e832cdbb..475f8c42c0e9 100644
--- a/include/linux/atmdev.h
+++ b/include/linux/atmdev.h
@@ -427,8 +427,10 @@ extern rwlock_t vcc_sklist_lock;
427 427
428#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb)) 428#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
429 429
430struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops, 430struct atm_dev *atm_dev_register(const char *type, struct device *parent,
431 int number,unsigned long *flags); /* number == -1: pick first available */ 431 const struct atmdev_ops *ops,
432 int number, /* -1 == pick first available */
433 unsigned long *flags);
432struct atm_dev *atm_dev_lookup(int number); 434struct atm_dev *atm_dev_lookup(int number);
433void atm_dev_deregister(struct atm_dev *dev); 435void atm_dev_deregister(struct atm_dev *dev);
434 436
diff --git a/include/linux/atomic.h b/include/linux/atomic.h
new file mode 100644
index 000000000000..96c038e43d66
--- /dev/null
+++ b/include/linux/atomic.h
@@ -0,0 +1,37 @@
1#ifndef _LINUX_ATOMIC_H
2#define _LINUX_ATOMIC_H
3#include <asm/atomic.h>
4
5/**
6 * atomic_inc_not_zero_hint - increment if not null
7 * @v: pointer of type atomic_t
8 * @hint: probable value of the atomic before the increment
9 *
10 * This version of atomic_inc_not_zero() gives a hint of probable
11 * value of the atomic. This helps processor to not read the memory
12 * before doing the atomic read/modify/write cycle, lowering
13 * number of bus transactions on some arches.
14 *
15 * Returns: 0 if increment was not done, 1 otherwise.
16 */
17#ifndef atomic_inc_not_zero_hint
18static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
19{
20 int val, c = hint;
21
22 /* sanity test, should be removed by compiler if hint is a constant */
23 if (!hint)
24 return atomic_inc_not_zero(v);
25
26 do {
27 val = atomic_cmpxchg(v, c, c + 1);
28 if (val == c)
29 return 1;
30 c = val;
31 } while (c);
32
33 return 0;
34}
35#endif
36
37#endif /* _LINUX_ATOMIC_H */
diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
index a065612fc928..64a7114a9394 100644
--- a/include/linux/binfmts.h
+++ b/include/linux/binfmts.h
@@ -29,6 +29,7 @@ struct linux_binprm{
29 char buf[BINPRM_BUF_SIZE]; 29 char buf[BINPRM_BUF_SIZE];
30#ifdef CONFIG_MMU 30#ifdef CONFIG_MMU
31 struct vm_area_struct *vma; 31 struct vm_area_struct *vma;
32 unsigned long vma_pages;
32#else 33#else
33# define MAX_ARG_PAGES 32 34# define MAX_ARG_PAGES 32
34 struct page *page[MAX_ARG_PAGES]; 35 struct page *page[MAX_ARG_PAGES];
@@ -59,6 +60,10 @@ struct linux_binprm{
59 unsigned long loader, exec; 60 unsigned long loader, exec;
60}; 61};
61 62
63extern void acct_arg_size(struct linux_binprm *bprm, unsigned long pages);
64extern struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
65 int write);
66
62#define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0 67#define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
63#define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT) 68#define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
64 69
diff --git a/include/linux/bio.h b/include/linux/bio.h
index ba679992d39b..35dcdb3589bc 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -66,10 +66,6 @@
66#define bio_offset(bio) bio_iovec((bio))->bv_offset 66#define bio_offset(bio) bio_iovec((bio))->bv_offset
67#define bio_segments(bio) ((bio)->bi_vcnt - (bio)->bi_idx) 67#define bio_segments(bio) ((bio)->bi_vcnt - (bio)->bi_idx)
68#define bio_sectors(bio) ((bio)->bi_size >> 9) 68#define bio_sectors(bio) ((bio)->bi_size >> 9)
69#define bio_empty_barrier(bio) \
70 ((bio->bi_rw & REQ_HARDBARRIER) && \
71 !bio_has_data(bio) && \
72 !(bio->bi_rw & REQ_DISCARD))
73 69
74static inline unsigned int bio_cur_bytes(struct bio *bio) 70static inline unsigned int bio_cur_bytes(struct bio *bio)
75{ 71{
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 0437ab6bb54c..46ad5197537a 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -122,7 +122,6 @@ enum rq_flag_bits {
122 __REQ_FAILFAST_TRANSPORT, /* no driver retries of transport errors */ 122 __REQ_FAILFAST_TRANSPORT, /* no driver retries of transport errors */
123 __REQ_FAILFAST_DRIVER, /* no driver retries of driver errors */ 123 __REQ_FAILFAST_DRIVER, /* no driver retries of driver errors */
124 124
125 __REQ_HARDBARRIER, /* may not be passed by drive either */
126 __REQ_SYNC, /* request is sync (sync write or read) */ 125 __REQ_SYNC, /* request is sync (sync write or read) */
127 __REQ_META, /* metadata io request */ 126 __REQ_META, /* metadata io request */
128 __REQ_DISCARD, /* request to discard sectors */ 127 __REQ_DISCARD, /* request to discard sectors */
@@ -159,7 +158,6 @@ enum rq_flag_bits {
159#define REQ_FAILFAST_DEV (1 << __REQ_FAILFAST_DEV) 158#define REQ_FAILFAST_DEV (1 << __REQ_FAILFAST_DEV)
160#define REQ_FAILFAST_TRANSPORT (1 << __REQ_FAILFAST_TRANSPORT) 159#define REQ_FAILFAST_TRANSPORT (1 << __REQ_FAILFAST_TRANSPORT)
161#define REQ_FAILFAST_DRIVER (1 << __REQ_FAILFAST_DRIVER) 160#define REQ_FAILFAST_DRIVER (1 << __REQ_FAILFAST_DRIVER)
162#define REQ_HARDBARRIER (1 << __REQ_HARDBARRIER)
163#define REQ_SYNC (1 << __REQ_SYNC) 161#define REQ_SYNC (1 << __REQ_SYNC)
164#define REQ_META (1 << __REQ_META) 162#define REQ_META (1 << __REQ_META)
165#define REQ_DISCARD (1 << __REQ_DISCARD) 163#define REQ_DISCARD (1 << __REQ_DISCARD)
@@ -168,8 +166,8 @@ enum rq_flag_bits {
168#define REQ_FAILFAST_MASK \ 166#define REQ_FAILFAST_MASK \
169 (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER) 167 (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)
170#define REQ_COMMON_MASK \ 168#define REQ_COMMON_MASK \
171 (REQ_WRITE | REQ_FAILFAST_MASK | REQ_HARDBARRIER | REQ_SYNC | \ 169 (REQ_WRITE | REQ_FAILFAST_MASK | REQ_SYNC | REQ_META | REQ_DISCARD | \
172 REQ_META | REQ_DISCARD | REQ_NOIDLE | REQ_FLUSH | REQ_FUA) 170 REQ_NOIDLE | REQ_FLUSH | REQ_FUA)
173#define REQ_CLONE_MASK REQ_COMMON_MASK 171#define REQ_CLONE_MASK REQ_COMMON_MASK
174 172
175#define REQ_UNPLUG (1 << __REQ_UNPLUG) 173#define REQ_UNPLUG (1 << __REQ_UNPLUG)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 5027a599077d..36ab42c9bb99 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -250,7 +250,7 @@ struct queue_limits {
250 250
251 unsigned char misaligned; 251 unsigned char misaligned;
252 unsigned char discard_misaligned; 252 unsigned char discard_misaligned;
253 unsigned char no_cluster; 253 unsigned char cluster;
254 signed char discard_zeroes_data; 254 signed char discard_zeroes_data;
255}; 255};
256 256
@@ -380,7 +380,6 @@ struct request_queue
380#endif 380#endif
381}; 381};
382 382
383#define QUEUE_FLAG_CLUSTER 0 /* cluster several segments into 1 */
384#define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */ 383#define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */
385#define QUEUE_FLAG_STOPPED 2 /* queue is stopped */ 384#define QUEUE_FLAG_STOPPED 2 /* queue is stopped */
386#define QUEUE_FLAG_SYNCFULL 3 /* read queue has been filled */ 385#define QUEUE_FLAG_SYNCFULL 3 /* read queue has been filled */
@@ -403,7 +402,6 @@ struct request_queue
403#define QUEUE_FLAG_SECDISCARD 19 /* supports SECDISCARD */ 402#define QUEUE_FLAG_SECDISCARD 19 /* supports SECDISCARD */
404 403
405#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ 404#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
406 (1 << QUEUE_FLAG_CLUSTER) | \
407 (1 << QUEUE_FLAG_STACKABLE) | \ 405 (1 << QUEUE_FLAG_STACKABLE) | \
408 (1 << QUEUE_FLAG_SAME_COMP) | \ 406 (1 << QUEUE_FLAG_SAME_COMP) | \
409 (1 << QUEUE_FLAG_ADD_RANDOM)) 407 (1 << QUEUE_FLAG_ADD_RANDOM))
@@ -510,6 +508,11 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
510 508
511#define rq_data_dir(rq) ((rq)->cmd_flags & 1) 509#define rq_data_dir(rq) ((rq)->cmd_flags & 1)
512 510
511static inline unsigned int blk_queue_cluster(struct request_queue *q)
512{
513 return q->limits.cluster;
514}
515
513/* 516/*
514 * We regard a request as sync, if either a read or a sync write 517 * We regard a request as sync, if either a read or a sync write
515 */ 518 */
@@ -552,8 +555,7 @@ static inline void blk_clear_queue_full(struct request_queue *q, int sync)
552 * it already be started by driver. 555 * it already be started by driver.
553 */ 556 */
554#define RQ_NOMERGE_FLAGS \ 557#define RQ_NOMERGE_FLAGS \
555 (REQ_NOMERGE | REQ_STARTED | REQ_HARDBARRIER | REQ_SOFTBARRIER | \ 558 (REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_FLUSH | REQ_FUA)
556 REQ_FLUSH | REQ_FUA)
557#define rq_mergeable(rq) \ 559#define rq_mergeable(rq) \
558 (!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \ 560 (!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
559 (((rq)->cmd_flags & REQ_DISCARD) || \ 561 (((rq)->cmd_flags & REQ_DISCARD) || \
@@ -806,6 +808,7 @@ extern struct request_queue *blk_init_allocated_queue(struct request_queue *,
806extern void blk_cleanup_queue(struct request_queue *); 808extern void blk_cleanup_queue(struct request_queue *);
807extern void blk_queue_make_request(struct request_queue *, make_request_fn *); 809extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
808extern void blk_queue_bounce_limit(struct request_queue *, u64); 810extern void blk_queue_bounce_limit(struct request_queue *, u64);
811extern void blk_limits_max_hw_sectors(struct queue_limits *, unsigned int);
809extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int); 812extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
810extern void blk_queue_max_segments(struct request_queue *, unsigned short); 813extern void blk_queue_max_segments(struct request_queue *, unsigned short);
811extern void blk_queue_max_segment_size(struct request_queue *, unsigned int); 814extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index 266ab9291232..499dfe982a0e 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -105,6 +105,8 @@ extern void *__alloc_bootmem_low_node(pg_data_t *pgdat,
105 105
106#define alloc_bootmem(x) \ 106#define alloc_bootmem(x) \
107 __alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS)) 107 __alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
108#define alloc_bootmem_align(x, align) \
109 __alloc_bootmem(x, align, __pa(MAX_DMA_ADDRESS))
108#define alloc_bootmem_nopanic(x) \ 110#define alloc_bootmem_nopanic(x) \
109 __alloc_bootmem_nopanic(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS)) 111 __alloc_bootmem_nopanic(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
110#define alloc_bootmem_pages(x) \ 112#define alloc_bootmem_pages(x) \
diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h
index f22b2e941686..72c72bfccb88 100644
--- a/include/linux/ceph/libceph.h
+++ b/include/linux/ceph/libceph.h
@@ -227,9 +227,10 @@ extern int ceph_open_session(struct ceph_client *client);
227extern void ceph_release_page_vector(struct page **pages, int num_pages); 227extern void ceph_release_page_vector(struct page **pages, int num_pages);
228 228
229extern struct page **ceph_get_direct_page_vector(const char __user *data, 229extern struct page **ceph_get_direct_page_vector(const char __user *data,
230 int num_pages, 230 int num_pages,
231 loff_t off, size_t len); 231 bool write_page);
232extern void ceph_put_page_vector(struct page **pages, int num_pages); 232extern void ceph_put_page_vector(struct page **pages, int num_pages,
233 bool dirty);
233extern void ceph_release_page_vector(struct page **pages, int num_pages); 234extern void ceph_release_page_vector(struct page **pages, int num_pages);
234extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags); 235extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
235extern int ceph_copy_user_to_page_vector(struct page **pages, 236extern int ceph_copy_user_to_page_vector(struct page **pages,
diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h
index 5956d62c3057..a108b425fee2 100644
--- a/include/linux/ceph/messenger.h
+++ b/include/linux/ceph/messenger.h
@@ -82,6 +82,7 @@ struct ceph_msg {
82 struct ceph_buffer *middle; 82 struct ceph_buffer *middle;
83 struct page **pages; /* data payload. NOT OWNER. */ 83 struct page **pages; /* data payload. NOT OWNER. */
84 unsigned nr_pages; /* size of page array */ 84 unsigned nr_pages; /* size of page array */
85 unsigned page_alignment; /* io offset in first page */
85 struct ceph_pagelist *pagelist; /* instead of pages */ 86 struct ceph_pagelist *pagelist; /* instead of pages */
86 struct list_head list_head; 87 struct list_head list_head;
87 struct kref kref; 88 struct kref kref;
diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index 6c91fb032c39..a1af29648fb5 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -79,6 +79,7 @@ struct ceph_osd_request {
79 struct ceph_file_layout r_file_layout; 79 struct ceph_file_layout r_file_layout;
80 struct ceph_snap_context *r_snapc; /* snap context for writes */ 80 struct ceph_snap_context *r_snapc; /* snap context for writes */
81 unsigned r_num_pages; /* size of page array (follows) */ 81 unsigned r_num_pages; /* size of page array (follows) */
82 unsigned r_page_alignment; /* io offset in first page */
82 struct page **r_pages; /* pages for data payload */ 83 struct page **r_pages; /* pages for data payload */
83 int r_pages_from_pool; 84 int r_pages_from_pool;
84 int r_own_pages; /* if true, i own page list */ 85 int r_own_pages; /* if true, i own page list */
@@ -194,7 +195,8 @@ extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
194 int do_sync, u32 truncate_seq, 195 int do_sync, u32 truncate_seq,
195 u64 truncate_size, 196 u64 truncate_size,
196 struct timespec *mtime, 197 struct timespec *mtime,
197 bool use_mempool, int num_reply); 198 bool use_mempool, int num_reply,
199 int page_align);
198 200
199static inline void ceph_osdc_get_request(struct ceph_osd_request *req) 201static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
200{ 202{
@@ -218,7 +220,8 @@ extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
218 struct ceph_file_layout *layout, 220 struct ceph_file_layout *layout,
219 u64 off, u64 *plen, 221 u64 off, u64 *plen,
220 u32 truncate_seq, u64 truncate_size, 222 u32 truncate_seq, u64 truncate_size,
221 struct page **pages, int nr_pages); 223 struct page **pages, int nr_pages,
224 int page_align);
222 225
223extern int ceph_osdc_writepages(struct ceph_osd_client *osdc, 226extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
224 struct ceph_vino vino, 227 struct ceph_vino vino,
diff --git a/include/linux/cnt32_to_63.h b/include/linux/cnt32_to_63.h
index 7605fdd1eb65..e3d8bf26e5eb 100644
--- a/include/linux/cnt32_to_63.h
+++ b/include/linux/cnt32_to_63.h
@@ -61,13 +61,31 @@ union cnt32_to_63 {
61 * 61 *
62 * 2) this code must not be preempted for a duration longer than the 62 * 2) this code must not be preempted for a duration longer than the
63 * 32-bit counter half period minus the longest period between two 63 * 32-bit counter half period minus the longest period between two
64 * calls to this code. 64 * calls to this code;
65 * 65 *
66 * Those requirements ensure proper update to the state bit in memory. 66 * Those requirements ensure proper update to the state bit in memory.
67 * This is usually not a problem in practice, but if it is then a kernel 67 * This is usually not a problem in practice, but if it is then a kernel
68 * timer should be scheduled to manage for this code to be executed often 68 * timer should be scheduled to manage for this code to be executed often
69 * enough. 69 * enough.
70 * 70 *
71 * And finally:
72 *
73 * 3) the cnt_lo argument must be seen as a globally incrementing value,
74 * meaning that it should be a direct reference to the counter data which
75 * can be evaluated according to a specific ordering within the macro,
76 * and not the result of a previous evaluation stored in a variable.
77 *
78 * For example, this is wrong:
79 *
80 * u32 partial = get_hw_count();
81 * u64 full = cnt32_to_63(partial);
82 * return full;
83 *
84 * This is fine:
85 *
86 * u64 full = cnt32_to_63(get_hw_count());
87 * return full;
88 *
71 * Note that the top bit (bit 63) in the returned value should be considered 89 * Note that the top bit (bit 63) in the returned value should be considered
72 * as garbage. It is not cleared here because callers are likely to use a 90 * as garbage. It is not cleared here because callers are likely to use a
73 * multiplier on the returned value which can get rid of the top bit 91 * multiplier on the returned value which can get rid of the top bit
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 4823af64e9db..5f09323ee880 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -10,11 +10,6 @@
10 * 10 *
11 * CPUs are exported via sysfs in the class/cpu/devices/ 11 * CPUs are exported via sysfs in the class/cpu/devices/
12 * directory. 12 * directory.
13 *
14 * Per-cpu interfaces can be implemented using a struct device_interface.
15 * See the following for how to do this:
16 * - drivers/base/intf.c
17 * - Documentation/driver-model/interface.txt
18 */ 13 */
19#ifndef _LINUX_CPU_H_ 14#ifndef _LINUX_CPU_H_
20#define _LINUX_CPU_H_ 15#define _LINUX_CPU_H_
diff --git a/include/linux/dmar.h b/include/linux/dmar.h
index a7d9dc21391d..7b776d71d36d 100644
--- a/include/linux/dmar.h
+++ b/include/linux/dmar.h
@@ -175,10 +175,21 @@ static inline int set_msi_sid(struct irte *irte, struct pci_dev *dev)
175 return 0; 175 return 0;
176} 176}
177 177
178#define enable_intr_remapping(mode) (-1)
179#define disable_intr_remapping() (0)
180#define reenable_intr_remapping(mode) (0)
181#define intr_remapping_enabled (0) 178#define intr_remapping_enabled (0)
179
180static inline int enable_intr_remapping(int eim)
181{
182 return -1;
183}
184
185static inline void disable_intr_remapping(void)
186{
187}
188
189static inline int reenable_intr_remapping(int eim)
190{
191 return 0;
192}
182#endif 193#endif
183 194
184/* Can't use the common MSI interrupt functions 195/* Can't use the common MSI interrupt functions
diff --git a/include/linux/drbd.h b/include/linux/drbd.h
index 9b2a0158f399..ef44c7a0638c 100644
--- a/include/linux/drbd.h
+++ b/include/linux/drbd.h
@@ -53,7 +53,7 @@
53 53
54 54
55extern const char *drbd_buildtag(void); 55extern const char *drbd_buildtag(void);
56#define REL_VERSION "8.3.9rc2" 56#define REL_VERSION "8.3.9"
57#define API_VERSION 88 57#define API_VERSION 88
58#define PRO_VERSION_MIN 86 58#define PRO_VERSION_MIN 86
59#define PRO_VERSION_MAX 95 59#define PRO_VERSION_MAX 95
diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h
index 0f0121467fc4..6c6133f76e16 100644
--- a/include/linux/fanotify.h
+++ b/include/linux/fanotify.h
@@ -83,11 +83,13 @@
83 FAN_ALL_PERM_EVENTS |\ 83 FAN_ALL_PERM_EVENTS |\
84 FAN_Q_OVERFLOW) 84 FAN_Q_OVERFLOW)
85 85
86#define FANOTIFY_METADATA_VERSION 2 86#define FANOTIFY_METADATA_VERSION 3
87 87
88struct fanotify_event_metadata { 88struct fanotify_event_metadata {
89 __u32 event_len; 89 __u32 event_len;
90 __u32 vers; 90 __u8 vers;
91 __u8 reserved;
92 __u16 metadata_len;
91 __aligned_u64 mask; 93 __aligned_u64 mask;
92 __s32 fd; 94 __s32 fd;
93 __s32 pid; 95 __s32 pid;
@@ -96,11 +98,13 @@ struct fanotify_event_metadata {
96struct fanotify_response { 98struct fanotify_response {
97 __s32 fd; 99 __s32 fd;
98 __u32 response; 100 __u32 response;
99} __attribute__ ((packed)); 101};
100 102
101/* Legit userspace responses to a _PERM event */ 103/* Legit userspace responses to a _PERM event */
102#define FAN_ALLOW 0x01 104#define FAN_ALLOW 0x01
103#define FAN_DENY 0x02 105#define FAN_DENY 0x02
106/* No fd set in event */
107#define FAN_NOFD -1
104 108
105/* Helper functions to deal with fanotify_event_metadata buffers */ 109/* Helper functions to deal with fanotify_event_metadata buffers */
106#define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) 110#define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 7fca3dc4e475..d1631d37e9e0 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -1122,6 +1122,7 @@ extern const struct fb_videomode *fb_find_best_display(const struct fb_monspecs
1122 1122
1123/* drivers/video/fbcmap.c */ 1123/* drivers/video/fbcmap.c */
1124extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp); 1124extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
1125extern int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags);
1125extern void fb_dealloc_cmap(struct fb_cmap *cmap); 1126extern void fb_dealloc_cmap(struct fb_cmap *cmap);
1126extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to); 1127extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to);
1127extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to); 1128extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 7b7b507ffa1c..090f0eacde29 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -34,9 +34,9 @@
34#define SEEK_MAX SEEK_END 34#define SEEK_MAX SEEK_END
35 35
36struct fstrim_range { 36struct fstrim_range {
37 uint64_t start; 37 __u64 start;
38 uint64_t len; 38 __u64 len;
39 uint64_t minlen; 39 __u64 minlen;
40}; 40};
41 41
42/* And dynamically-tunable limits and defaults: */ 42/* And dynamically-tunable limits and defaults: */
@@ -602,6 +602,7 @@ struct address_space_operations {
602 sector_t (*bmap)(struct address_space *, sector_t); 602 sector_t (*bmap)(struct address_space *, sector_t);
603 void (*invalidatepage) (struct page *, unsigned long); 603 void (*invalidatepage) (struct page *, unsigned long);
604 int (*releasepage) (struct page *, gfp_t); 604 int (*releasepage) (struct page *, gfp_t);
605 void (*freepage)(struct page *);
605 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, 606 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
606 loff_t offset, unsigned long nr_segs); 607 loff_t offset, unsigned long nr_segs);
607 int (*get_xip_mem)(struct address_space *, pgoff_t, int, 608 int (*get_xip_mem)(struct address_space *, pgoff_t, int,
@@ -1056,7 +1057,6 @@ struct lock_manager_operations {
1056 int (*fl_compare_owner)(struct file_lock *, struct file_lock *); 1057 int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
1057 void (*fl_notify)(struct file_lock *); /* unblock callback */ 1058 void (*fl_notify)(struct file_lock *); /* unblock callback */
1058 int (*fl_grant)(struct file_lock *, struct file_lock *, int); 1059 int (*fl_grant)(struct file_lock *, struct file_lock *, int);
1059 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
1060 void (*fl_release_private)(struct file_lock *); 1060 void (*fl_release_private)(struct file_lock *);
1061 void (*fl_break)(struct file_lock *); 1061 void (*fl_break)(struct file_lock *);
1062 int (*fl_mylease)(struct file_lock *, struct file_lock *); 1062 int (*fl_mylease)(struct file_lock *, struct file_lock *);
@@ -1129,6 +1129,7 @@ extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
1129extern int fcntl_getlease(struct file *filp); 1129extern int fcntl_getlease(struct file *filp);
1130 1130
1131/* fs/locks.c */ 1131/* fs/locks.c */
1132void locks_free_lock(struct file_lock *fl);
1132extern void locks_init_lock(struct file_lock *); 1133extern void locks_init_lock(struct file_lock *);
1133extern struct file_lock * locks_alloc_lock(void); 1134extern struct file_lock * locks_alloc_lock(void);
1134extern void locks_copy_lock(struct file_lock *, struct file_lock *); 1135extern void locks_copy_lock(struct file_lock *, struct file_lock *);
@@ -1612,7 +1613,6 @@ struct super_operations {
1612 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); 1613 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
1613#endif 1614#endif
1614 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t); 1615 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
1615 int (*trim_fs) (struct super_block *, struct fstrim_range *);
1616}; 1616};
1617 1617
1618/* 1618/*
diff --git a/include/linux/fsl-diu-fb.h b/include/linux/fsl-diu-fb.h
index fc295d7ea463..781d4671415f 100644
--- a/include/linux/fsl-diu-fb.h
+++ b/include/linux/fsl-diu-fb.h
@@ -54,7 +54,6 @@ struct aoi_display_offset {
54}; 54};
55 55
56#define MFB_SET_CHROMA_KEY _IOW('M', 1, struct mfb_chroma_key) 56#define MFB_SET_CHROMA_KEY _IOW('M', 1, struct mfb_chroma_key)
57#define MFB_WAIT_FOR_VSYNC _IOW('F', 0x20, u_int32_t)
58#define MFB_SET_BRIGHTNESS _IOW('M', 3, __u8) 57#define MFB_SET_BRIGHTNESS _IOW('M', 3, __u8)
59 58
60#define MFB_SET_ALPHA 0x80014d00 59#define MFB_SET_ALPHA 0x80014d00
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index 5c185fa27089..b10bcdeaef76 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -235,9 +235,6 @@ static inline void fsnotify_open(struct file *file)
235 if (S_ISDIR(inode->i_mode)) 235 if (S_ISDIR(inode->i_mode))
236 mask |= FS_ISDIR; 236 mask |= FS_ISDIR;
237 237
238 /* FMODE_NONOTIFY must never be set from user */
239 file->f_mode &= ~FMODE_NONOTIFY;
240
241 fsnotify_parent(path, NULL, mask); 238 fsnotify_parent(path, NULL, mask);
242 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); 239 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
243} 240}
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 0a68f924f06f..7380763595d3 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -166,7 +166,7 @@ struct fsnotify_group {
166 struct mutex access_mutex; 166 struct mutex access_mutex;
167 struct list_head access_list; 167 struct list_head access_list;
168 wait_queue_head_t access_waitq; 168 wait_queue_head_t access_waitq;
169 bool bypass_perm; /* protected by access_mutex */ 169 atomic_t bypass_perm;
170#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */ 170#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */
171 int f_flags; 171 int f_flags;
172 unsigned int max_marks; 172 unsigned int max_marks;
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index e8713d55360a..f54adfcbec9c 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -360,7 +360,7 @@ void drain_local_pages(void *dummy);
360 360
361extern gfp_t gfp_allowed_mask; 361extern gfp_t gfp_allowed_mask;
362 362
363extern void set_gfp_allowed_mask(gfp_t mask); 363extern void pm_restrict_gfp_mask(void);
364extern gfp_t clear_gfp_allowed_mask(gfp_t mask); 364extern void pm_restore_gfp_mask(void);
365 365
366#endif /* __LINUX_GFP_H */ 366#endif /* __LINUX_GFP_H */
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index ce73a30113b4..dd1a56fbe924 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -16,6 +16,8 @@ struct gpio_keys_button {
16struct gpio_keys_platform_data { 16struct gpio_keys_platform_data {
17 struct gpio_keys_button *buttons; 17 struct gpio_keys_button *buttons;
18 int nbuttons; 18 int nbuttons;
19 unsigned int poll_interval; /* polling interval in msecs -
20 for polling driver only */
19 unsigned int rep:1; /* enable input subsystem auto repeat */ 21 unsigned int rep:1; /* enable input subsystem auto repeat */
20 int (*enable)(struct device *dev); 22 int (*enable)(struct device *dev);
21 void (*disable)(struct device *dev); 23 void (*disable)(struct device *dev);
diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h
index 8a389b608ce3..32f9fd6619b4 100644
--- a/include/linux/hardirq.h
+++ b/include/linux/hardirq.h
@@ -2,9 +2,6 @@
2#define LINUX_HARDIRQ_H 2#define LINUX_HARDIRQ_H
3 3
4#include <linux/preempt.h> 4#include <linux/preempt.h>
5#ifdef CONFIG_PREEMPT
6#include <linux/smp_lock.h>
7#endif
8#include <linux/lockdep.h> 5#include <linux/lockdep.h>
9#include <linux/ftrace_irq.h> 6#include <linux/ftrace_irq.h>
10#include <asm/hardirq.h> 7#include <asm/hardirq.h>
@@ -96,11 +93,16 @@
96 */ 93 */
97#define in_nmi() (preempt_count() & NMI_MASK) 94#define in_nmi() (preempt_count() & NMI_MASK)
98 95
96#if defined(CONFIG_PREEMPT) && defined(CONFIG_BKL)
97# include <linux/sched.h>
98# define PREEMPT_INATOMIC_BASE (current->lock_depth >= 0)
99#else
100# define PREEMPT_INATOMIC_BASE 0
101#endif
102
99#if defined(CONFIG_PREEMPT) 103#if defined(CONFIG_PREEMPT)
100# define PREEMPT_INATOMIC_BASE kernel_locked()
101# define PREEMPT_CHECK_OFFSET 1 104# define PREEMPT_CHECK_OFFSET 1
102#else 105#else
103# define PREEMPT_INATOMIC_BASE 0
104# define PREEMPT_CHECK_OFFSET 0 106# define PREEMPT_CHECK_OFFSET 0
105#endif 107#endif
106 108
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index e9138198e823..b676c585574e 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -5,6 +5,7 @@
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/mm.h> 6#include <linux/mm.h>
7#include <linux/uaccess.h> 7#include <linux/uaccess.h>
8#include <linux/hardirq.h>
8 9
9#include <asm/cacheflush.h> 10#include <asm/cacheflush.h>
10 11
diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h
index a2d6ea49ec56..d1e55fed2c7d 100644
--- a/include/linux/hw_breakpoint.h
+++ b/include/linux/hw_breakpoint.h
@@ -33,6 +33,8 @@ enum bp_type_idx {
33 33
34#ifdef CONFIG_HAVE_HW_BREAKPOINT 34#ifdef CONFIG_HAVE_HW_BREAKPOINT
35 35
36extern int __init init_hw_breakpoint(void);
37
36static inline void hw_breakpoint_init(struct perf_event_attr *attr) 38static inline void hw_breakpoint_init(struct perf_event_attr *attr)
37{ 39{
38 memset(attr, 0, sizeof(*attr)); 40 memset(attr, 0, sizeof(*attr));
@@ -108,6 +110,8 @@ static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
108 110
109#else /* !CONFIG_HAVE_HW_BREAKPOINT */ 111#else /* !CONFIG_HAVE_HW_BREAKPOINT */
110 112
113static inline int __init init_hw_breakpoint(void) { return 0; }
114
111static inline struct perf_event * 115static inline struct perf_event *
112register_user_hw_breakpoint(struct perf_event_attr *attr, 116register_user_hw_breakpoint(struct perf_event_attr *attr,
113 perf_overflow_handler_t triggered, 117 perf_overflow_handler_t triggered,
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index e844a0b18695..4bef5c557160 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -32,28 +32,6 @@
32 */ 32 */
33 33
34/* --- Bit algorithm adapters */ 34/* --- Bit algorithm adapters */
35#define I2C_HW_B_BT848 0x010005 /* BT848 video boards */
36#define I2C_HW_B_RIVA 0x010010 /* Riva based graphics cards */
37#define I2C_HW_B_ZR36067 0x010019 /* Zoran-36057/36067 based boards */
38#define I2C_HW_B_CX2388x 0x01001b /* connexant 2388x based tv cards */ 35#define I2C_HW_B_CX2388x 0x01001b /* connexant 2388x based tv cards */
39#define I2C_HW_B_EM28XX 0x01001f /* em28xx video capture cards */
40#define I2C_HW_B_CX2341X 0x010020 /* Conexant CX2341X MPEG encoder cards */
41#define I2C_HW_B_CX23885 0x010022 /* conexant 23885 based tv cards (bus1) */
42#define I2C_HW_B_AU0828 0x010023 /* auvitek au0828 usb bridge */
43#define I2C_HW_B_CX231XX 0x010024 /* Conexant CX231XX USB based cards */
44#define I2C_HW_B_HDPVR 0x010025 /* Hauppauge HD PVR */
45
46/* --- SGI adapters */
47#define I2C_HW_SGI_VINO 0x160000
48
49/* --- SMBus only adapters */
50#define I2C_HW_SMBUS_W9968CF 0x04000d
51#define I2C_HW_SMBUS_OV511 0x04000e /* OV511(+) USB 1.1 webcam ICs */
52#define I2C_HW_SMBUS_OV518 0x04000f /* OV518(+) USB 1.1 webcam ICs */
53#define I2C_HW_SMBUS_CAFE 0x040012 /* Marvell 88ALP01 "CAFE" cam */
54
55/* --- Miscellaneous adapters */
56#define I2C_HW_SAA7146 0x060000 /* SAA7146 video decoder bus */
57#define I2C_HW_SAA7134 0x090000 /* SAA7134 video decoder bus */
58 36
59#endif /* LINUX_I2C_ID_H */ 37#endif /* LINUX_I2C_ID_H */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 1f66fa06a97c..56cfe23ffb39 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -353,7 +353,7 @@ struct i2c_algorithm {
353 */ 353 */
354struct i2c_adapter { 354struct i2c_adapter {
355 struct module *owner; 355 struct module *owner;
356 unsigned int id; 356 unsigned int id __deprecated;
357 unsigned int class; /* classes to allow probing for */ 357 unsigned int class; /* classes to allow probing for */
358 const struct i2c_algorithm *algo; /* the algorithm to access the bus */ 358 const struct i2c_algorithm *algo; /* the algorithm to access the bus */
359 void *algo_data; 359 void *algo_data;
@@ -407,8 +407,6 @@ void i2c_unlock_adapter(struct i2c_adapter *);
407 407
408/* i2c adapter classes (bitmask) */ 408/* i2c adapter classes (bitmask) */
409#define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */ 409#define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */
410#define I2C_CLASS_TV_ANALOG (1<<1) /* bttv + friends */
411#define I2C_CLASS_TV_DIGITAL (1<<2) /* dvb cards */
412#define I2C_CLASS_DDC (1<<3) /* DDC bus on graphics adapters */ 410#define I2C_CLASS_DDC (1<<3) /* DDC bus on graphics adapters */
413#define I2C_CLASS_SPD (1<<7) /* SPD EEPROMs and similar */ 411#define I2C_CLASS_SPD (1<<7) /* SPD EEPROMs and similar */
414 412
diff --git a/include/linux/i2c/adp5588.h b/include/linux/i2c/adp5588.h
index 3c5d6b6e765c..cec17cf6cac2 100644
--- a/include/linux/i2c/adp5588.h
+++ b/include/linux/i2c/adp5588.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Analog Devices ADP5588 I/O Expander and QWERTY Keypad Controller 2 * Analog Devices ADP5588 I/O Expander and QWERTY Keypad Controller
3 * 3 *
4 * Copyright 2009 Analog Devices Inc. 4 * Copyright 2009-2010 Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
@@ -77,13 +77,26 @@
77 /* Configuration Register1 */ 77 /* Configuration Register1 */
78#define ADP5588_AUTO_INC (1 << 7) 78#define ADP5588_AUTO_INC (1 << 7)
79#define ADP5588_GPIEM_CFG (1 << 6) 79#define ADP5588_GPIEM_CFG (1 << 6)
80#define ADP5588_OVR_FLOW_M (1 << 5)
80#define ADP5588_INT_CFG (1 << 4) 81#define ADP5588_INT_CFG (1 << 4)
82#define ADP5588_OVR_FLOW_IEN (1 << 3)
83#define ADP5588_K_LCK_IM (1 << 2)
81#define ADP5588_GPI_IEN (1 << 1) 84#define ADP5588_GPI_IEN (1 << 1)
85#define ADP5588_KE_IEN (1 << 0)
82 86
83/* Interrupt Status Register */ 87/* Interrupt Status Register */
88#define ADP5588_CMP2_INT (1 << 5)
89#define ADP5588_CMP1_INT (1 << 4)
90#define ADP5588_OVR_FLOW_INT (1 << 3)
91#define ADP5588_K_LCK_INT (1 << 2)
84#define ADP5588_GPI_INT (1 << 1) 92#define ADP5588_GPI_INT (1 << 1)
85#define ADP5588_KE_INT (1 << 0) 93#define ADP5588_KE_INT (1 << 0)
86 94
95/* Key Lock and Event Counter Register */
96#define ADP5588_K_LCK_EN (1 << 6)
97#define ADP5588_LCK21 0x30
98#define ADP5588_KEC 0xF
99
87#define ADP5588_MAXGPIO 18 100#define ADP5588_MAXGPIO 18
88#define ADP5588_BANK(offs) ((offs) >> 3) 101#define ADP5588_BANK(offs) ((offs) >> 3)
89#define ADP5588_BIT(offs) (1u << ((offs) & 0x7)) 102#define ADP5588_BIT(offs) (1u << ((offs) & 0x7))
diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
index c2f3a72712ce..635e1faec412 100644
--- a/include/linux/if_vlan.h
+++ b/include/linux/if_vlan.h
@@ -339,6 +339,31 @@ static inline int vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
339 } 339 }
340} 340}
341 341
342/**
343 * vlan_get_protocol - get protocol EtherType.
344 * @skb: skbuff to query
345 *
346 * Returns the EtherType of the packet, regardless of whether it is
347 * vlan encapsulated (normal or hardware accelerated) or not.
348 */
349static inline __be16 vlan_get_protocol(const struct sk_buff *skb)
350{
351 __be16 protocol = 0;
352
353 if (vlan_tx_tag_present(skb) ||
354 skb->protocol != cpu_to_be16(ETH_P_8021Q))
355 protocol = skb->protocol;
356 else {
357 __be16 proto, *protop;
358 protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr,
359 h_vlan_encapsulated_proto),
360 sizeof(proto), &proto);
361 if (likely(protop))
362 protocol = *protop;
363 }
364
365 return protocol;
366}
342#endif /* __KERNEL__ */ 367#endif /* __KERNEL__ */
343 368
344/* VLAN IOCTLs are found in sockios.h */ 369/* VLAN IOCTLs are found in sockios.h */
diff --git a/include/linux/input.h b/include/linux/input.h
index 51af441f3a21..9777668883be 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -47,6 +47,25 @@ struct input_id {
47 __u16 version; 47 __u16 version;
48}; 48};
49 49
50/**
51 * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
52 * @value: latest reported value for the axis.
53 * @minimum: specifies minimum value for the axis.
54 * @maximum: specifies maximum value for the axis.
55 * @fuzz: specifies fuzz value that is used to filter noise from
56 * the event stream.
57 * @flat: values that are within this value will be discarded by
58 * joydev interface and reported as 0 instead.
59 * @resolution: specifies resolution for the values reported for
60 * the axis.
61 *
62 * Note that input core does not clamp reported values to the
63 * [minimum, maximum] limits, such task is left to userspace.
64 *
65 * Resolution for main axes (ABS_X, ABS_Y, ABS_Z) is reported in
66 * units per millimeter (units/mm), resolution for rotational axes
67 * (ABS_RX, ABS_RY, ABS_RZ) is reported in units per radian.
68 */
50struct input_absinfo { 69struct input_absinfo {
51 __s32 value; 70 __s32 value;
52 __s32 minimum; 71 __s32 minimum;
@@ -85,8 +104,10 @@ struct input_keymap_entry {
85#define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */ 104#define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */
86#define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */ 105#define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */
87 106
88#define EVIOCGKEYCODE _IOR('E', 0x04, struct input_keymap_entry) /* get keycode */ 107#define EVIOCGKEYCODE _IOR('E', 0x04, unsigned int[2]) /* get keycode */
89#define EVIOCSKEYCODE _IOW('E', 0x04, struct input_keymap_entry) /* set keycode */ 108#define EVIOCGKEYCODE_V2 _IOR('E', 0x04, struct input_keymap_entry)
109#define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */
110#define EVIOCSKEYCODE_V2 _IOW('E', 0x04, struct input_keymap_entry)
90 111
91#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ 112#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */
92#define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */ 113#define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */
@@ -624,6 +645,10 @@ struct input_keymap_entry {
624#define KEY_CAMERA_FOCUS 0x210 645#define KEY_CAMERA_FOCUS 0x210
625#define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */ 646#define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */
626 647
648#define KEY_TOUCHPAD_TOGGLE 0x212 /* Request switch touchpad on or off */
649#define KEY_TOUCHPAD_ON 0x213
650#define KEY_TOUCHPAD_OFF 0x214
651
627#define BTN_TRIGGER_HAPPY 0x2c0 652#define BTN_TRIGGER_HAPPY 0x2c0
628#define BTN_TRIGGER_HAPPY1 0x2c0 653#define BTN_TRIGGER_HAPPY1 0x2c0
629#define BTN_TRIGGER_HAPPY2 0x2c1 654#define BTN_TRIGGER_HAPPY2 0x2c1
@@ -1130,7 +1155,7 @@ struct input_mt_slot {
1130 * of tracked contacts 1155 * of tracked contacts
1131 * @mtsize: number of MT slots the device uses 1156 * @mtsize: number of MT slots the device uses
1132 * @slot: MT slot currently being transmitted 1157 * @slot: MT slot currently being transmitted
1133 * @absinfo: array of &struct absinfo elements holding information 1158 * @absinfo: array of &struct input_absinfo elements holding information
1134 * about absolute axes (current value, min, max, flat, fuzz, 1159 * about absolute axes (current value, min, max, flat, fuzz,
1135 * resolution) 1160 * resolution)
1136 * @key: reflects current state of device's keys/buttons 1161 * @key: reflects current state of device's keys/buttons
@@ -1406,6 +1431,8 @@ static inline void input_set_drvdata(struct input_dev *dev, void *data)
1406int __must_check input_register_device(struct input_dev *); 1431int __must_check input_register_device(struct input_dev *);
1407void input_unregister_device(struct input_dev *); 1432void input_unregister_device(struct input_dev *);
1408 1433
1434void input_reset_device(struct input_dev *);
1435
1409int __must_check input_register_handler(struct input_handler *); 1436int __must_check input_register_handler(struct input_handler *);
1410void input_unregister_handler(struct input_handler *); 1437void input_unregister_handler(struct input_handler *);
1411 1438
@@ -1421,7 +1448,7 @@ void input_release_device(struct input_handle *);
1421int input_open_device(struct input_handle *); 1448int input_open_device(struct input_handle *);
1422void input_close_device(struct input_handle *); 1449void input_close_device(struct input_handle *);
1423 1450
1424int input_flush_device(struct input_handle* handle, struct file* file); 1451int input_flush_device(struct input_handle *handle, struct file *file);
1425 1452
1426void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value); 1453void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1427void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value); 1454void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
diff --git a/include/linux/iocontext.h b/include/linux/iocontext.h
index 3e70b21884a9..b2eee896dcbc 100644
--- a/include/linux/iocontext.h
+++ b/include/linux/iocontext.h
@@ -76,7 +76,6 @@ int put_io_context(struct io_context *ioc);
76void exit_io_context(struct task_struct *task); 76void exit_io_context(struct task_struct *task);
77struct io_context *get_io_context(gfp_t gfp_flags, int node); 77struct io_context *get_io_context(gfp_t gfp_flags, int node);
78struct io_context *alloc_io_context(gfp_t gfp_flags, int node); 78struct io_context *alloc_io_context(gfp_t gfp_flags, int node);
79void copy_io_context(struct io_context **pdst, struct io_context **psrc);
80#else 79#else
81static inline void exit_io_context(struct task_struct *task) 80static inline void exit_io_context(struct task_struct *task)
82{ 81{
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index d377ea815d45..e9bb22cba764 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -112,7 +112,6 @@ struct resource_list {
112/* PC/ISA/whatever - the normal PC address spaces: IO and memory */ 112/* PC/ISA/whatever - the normal PC address spaces: IO and memory */
113extern struct resource ioport_resource; 113extern struct resource ioport_resource;
114extern struct resource iomem_resource; 114extern struct resource iomem_resource;
115extern int resource_alloc_from_bottom;
116 115
117extern struct resource *request_resource_conflict(struct resource *root, struct resource *new); 116extern struct resource *request_resource_conflict(struct resource *root, struct resource *new);
118extern int request_resource(struct resource *root, struct resource *new); 117extern int request_resource(struct resource *root, struct resource *new);
@@ -124,6 +123,7 @@ extern void reserve_region_with_split(struct resource *root,
124extern struct resource *insert_resource_conflict(struct resource *parent, struct resource *new); 123extern struct resource *insert_resource_conflict(struct resource *parent, struct resource *new);
125extern int insert_resource(struct resource *parent, struct resource *new); 124extern int insert_resource(struct resource *parent, struct resource *new);
126extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new); 125extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new);
126extern void arch_remove_reservations(struct resource *avail);
127extern int allocate_resource(struct resource *root, struct resource *new, 127extern int allocate_resource(struct resource *root, struct resource *new,
128 resource_size_t size, resource_size_t min, 128 resource_size_t size, resource_size_t min,
129 resource_size_t max, resource_size_t align, 129 resource_size_t max, resource_size_t align,
diff --git a/include/linux/irq.h b/include/linux/irq.h
index e9639115dff1..abde2527c699 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -412,6 +412,11 @@ static inline void irq_free_desc(unsigned int irq)
412 irq_free_descs(irq, 1); 412 irq_free_descs(irq, 1);
413} 413}
414 414
415static inline int irq_reserve_irq(unsigned int irq)
416{
417 return irq_reserve_irqs(irq, 1);
418}
419
415#endif /* CONFIG_GENERIC_HARDIRQS */ 420#endif /* CONFIG_GENERIC_HARDIRQS */
416 421
417#endif /* !CONFIG_S390 */ 422#endif /* !CONFIG_S390 */
diff --git a/include/linux/irqnr.h b/include/linux/irqnr.h
index 05aa8c23483f..3bc4dcab6e82 100644
--- a/include/linux/irqnr.h
+++ b/include/linux/irqnr.h
@@ -43,7 +43,7 @@ unsigned int irq_get_next_irq(unsigned int offset);
43 else 43 else
44 44
45#ifdef CONFIG_SMP 45#ifdef CONFIG_SMP
46#define irq_node(irq) (irq_to_desc(irq)->node) 46#define irq_node(irq) (irq_get_irq_data(irq)->node)
47#else 47#else
48#define irq_node(irq) 0 48#define irq_node(irq) 0
49#endif 49#endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 450092c1e35f..b6de9a6f7018 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -17,13 +17,11 @@
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18#include <linux/log2.h> 18#include <linux/log2.h>
19#include <linux/typecheck.h> 19#include <linux/typecheck.h>
20#include <linux/printk.h>
20#include <linux/dynamic_debug.h> 21#include <linux/dynamic_debug.h>
21#include <asm/byteorder.h> 22#include <asm/byteorder.h>
22#include <asm/bug.h> 23#include <asm/bug.h>
23 24
24extern const char linux_banner[];
25extern const char linux_proc_banner[];
26
27#define USHRT_MAX ((u16)(~0U)) 25#define USHRT_MAX ((u16)(~0U))
28#define SHRT_MAX ((s16)(USHRT_MAX>>1)) 26#define SHRT_MAX ((s16)(USHRT_MAX>>1))
29#define SHRT_MIN ((s16)(-SHRT_MAX - 1)) 27#define SHRT_MIN ((s16)(-SHRT_MAX - 1))
@@ -60,7 +58,7 @@ extern const char linux_proc_banner[];
60#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 58#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
61#define roundup(x, y) ( \ 59#define roundup(x, y) ( \
62{ \ 60{ \
63 typeof(y) __y = y; \ 61 const typeof(y) __y = y; \
64 (((x) + (__y - 1)) / __y) * __y; \ 62 (((x) + (__y - 1)) / __y) * __y; \
65} \ 63} \
66) 64)
@@ -110,31 +108,6 @@ extern const char linux_proc_banner[];
110 */ 108 */
111#define lower_32_bits(n) ((u32)(n)) 109#define lower_32_bits(n) ((u32)(n))
112 110
113#define KERN_EMERG "<0>" /* system is unusable */
114#define KERN_ALERT "<1>" /* action must be taken immediately */
115#define KERN_CRIT "<2>" /* critical conditions */
116#define KERN_ERR "<3>" /* error conditions */
117#define KERN_WARNING "<4>" /* warning conditions */
118#define KERN_NOTICE "<5>" /* normal but significant condition */
119#define KERN_INFO "<6>" /* informational */
120#define KERN_DEBUG "<7>" /* debug-level messages */
121
122/* Use the default kernel loglevel */
123#define KERN_DEFAULT "<d>"
124/*
125 * Annotation for a "continued" line of log printout (only done after a
126 * line that had no enclosing \n). Only to be used by core/arch code
127 * during early bootup (a continued line is not SMP-safe otherwise).
128 */
129#define KERN_CONT "<c>"
130
131extern int console_printk[];
132
133#define console_loglevel (console_printk[0])
134#define default_message_loglevel (console_printk[1])
135#define minimum_console_loglevel (console_printk[2])
136#define default_console_loglevel (console_printk[3])
137
138struct completion; 111struct completion;
139struct pt_regs; 112struct pt_regs;
140struct user; 113struct user;
@@ -187,11 +160,6 @@ static inline void might_fault(void)
187} 160}
188#endif 161#endif
189 162
190struct va_format {
191 const char *fmt;
192 va_list *va;
193};
194
195extern struct atomic_notifier_head panic_notifier_list; 163extern struct atomic_notifier_head panic_notifier_list;
196extern long (*panic_blink)(int state); 164extern long (*panic_blink)(int state);
197NORET_TYPE void panic(const char * fmt, ...) 165NORET_TYPE void panic(const char * fmt, ...)
@@ -245,114 +213,8 @@ extern int func_ptr_is_kernel_text(void *ptr);
245struct pid; 213struct pid;
246extern struct pid *session_of_pgrp(struct pid *pgrp); 214extern struct pid *session_of_pgrp(struct pid *pgrp);
247 215
248/*
249 * FW_BUG
250 * Add this to a message where you are sure the firmware is buggy or behaves
251 * really stupid or out of spec. Be aware that the responsible BIOS developer
252 * should be able to fix this issue or at least get a concrete idea of the
253 * problem by reading your message without the need of looking at the kernel
254 * code.
255 *
256 * Use it for definite and high priority BIOS bugs.
257 *
258 * FW_WARN
259 * Use it for not that clear (e.g. could the kernel messed up things already?)
260 * and medium priority BIOS bugs.
261 *
262 * FW_INFO
263 * Use this one if you want to tell the user or vendor about something
264 * suspicious, but generally harmless related to the firmware.
265 *
266 * Use it for information or very low priority BIOS bugs.
267 */
268#define FW_BUG "[Firmware Bug]: "
269#define FW_WARN "[Firmware Warn]: "
270#define FW_INFO "[Firmware Info]: "
271
272/*
273 * HW_ERR
274 * Add this to a message for hardware errors, so that user can report
275 * it to hardware vendor instead of LKML or software vendor.
276 */
277#define HW_ERR "[Hardware Error]: "
278
279#ifdef CONFIG_PRINTK
280asmlinkage int vprintk(const char *fmt, va_list args)
281 __attribute__ ((format (printf, 1, 0)));
282asmlinkage int printk(const char * fmt, ...)
283 __attribute__ ((format (printf, 1, 2))) __cold;
284
285/*
286 * Please don't use printk_ratelimit(), because it shares ratelimiting state
287 * with all other unrelated printk_ratelimit() callsites. Instead use
288 * printk_ratelimited() or plain old __ratelimit().
289 */
290extern int __printk_ratelimit(const char *func);
291#define printk_ratelimit() __printk_ratelimit(__func__)
292extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
293 unsigned int interval_msec);
294
295extern int printk_delay_msec;
296
297/*
298 * Print a one-time message (analogous to WARN_ONCE() et al):
299 */
300#define printk_once(x...) ({ \
301 static bool __print_once; \
302 \
303 if (!__print_once) { \
304 __print_once = true; \
305 printk(x); \
306 } \
307})
308
309void log_buf_kexec_setup(void);
310#else
311static inline int vprintk(const char *s, va_list args)
312 __attribute__ ((format (printf, 1, 0)));
313static inline int vprintk(const char *s, va_list args) { return 0; }
314static inline int printk(const char *s, ...)
315 __attribute__ ((format (printf, 1, 2)));
316static inline int __cold printk(const char *s, ...) { return 0; }
317static inline int printk_ratelimit(void) { return 0; }
318static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
319 unsigned int interval_msec) \
320 { return false; }
321
322/* No effect, but we still get type checking even in the !PRINTK case: */
323#define printk_once(x...) printk(x)
324
325static inline void log_buf_kexec_setup(void)
326{
327}
328#endif
329
330/*
331 * Dummy printk for disabled debugging statements to use whilst maintaining
332 * gcc's format and side-effect checking.
333 */
334static inline __attribute__ ((format (printf, 1, 2)))
335int no_printk(const char *s, ...) { return 0; }
336
337extern int printk_needs_cpu(int cpu);
338extern void printk_tick(void);
339
340extern void asmlinkage __attribute__((format(printf, 1, 2)))
341 early_printk(const char *fmt, ...);
342
343unsigned long int_sqrt(unsigned long); 216unsigned long int_sqrt(unsigned long);
344 217
345static inline void console_silent(void)
346{
347 console_loglevel = 0;
348}
349
350static inline void console_verbose(void)
351{
352 if (console_loglevel)
353 console_loglevel = 15;
354}
355
356extern void bust_spinlocks(int yes); 218extern void bust_spinlocks(int yes);
357extern void wake_up_klogd(void); 219extern void wake_up_klogd(void);
358extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ 220extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
@@ -389,22 +251,6 @@ extern enum system_states {
389#define TAINT_CRAP 10 251#define TAINT_CRAP 10
390#define TAINT_FIRMWARE_WORKAROUND 11 252#define TAINT_FIRMWARE_WORKAROUND 11
391 253
392extern void dump_stack(void) __cold;
393
394enum {
395 DUMP_PREFIX_NONE,
396 DUMP_PREFIX_ADDRESS,
397 DUMP_PREFIX_OFFSET
398};
399extern void hex_dump_to_buffer(const void *buf, size_t len,
400 int rowsize, int groupsize,
401 char *linebuf, size_t linebuflen, bool ascii);
402extern void print_hex_dump(const char *level, const char *prefix_str,
403 int prefix_type, int rowsize, int groupsize,
404 const void *buf, size_t len, bool ascii);
405extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
406 const void *buf, size_t len);
407
408extern const char hex_asc[]; 254extern const char hex_asc[];
409#define hex_asc_lo(x) hex_asc[((x) & 0x0f)] 255#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
410#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] 256#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
@@ -418,94 +264,6 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
418 264
419extern int hex_to_bin(char ch); 265extern int hex_to_bin(char ch);
420 266
421#ifndef pr_fmt
422#define pr_fmt(fmt) fmt
423#endif
424
425#define pr_emerg(fmt, ...) \
426 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
427#define pr_alert(fmt, ...) \
428 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
429#define pr_crit(fmt, ...) \
430 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
431#define pr_err(fmt, ...) \
432 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
433#define pr_warning(fmt, ...) \
434 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
435#define pr_warn pr_warning
436#define pr_notice(fmt, ...) \
437 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
438#define pr_info(fmt, ...) \
439 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
440#define pr_cont(fmt, ...) \
441 printk(KERN_CONT fmt, ##__VA_ARGS__)
442
443/* pr_devel() should produce zero code unless DEBUG is defined */
444#ifdef DEBUG
445#define pr_devel(fmt, ...) \
446 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
447#else
448#define pr_devel(fmt, ...) \
449 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
450#endif
451
452/* If you are writing a driver, please use dev_dbg instead */
453#if defined(DEBUG)
454#define pr_debug(fmt, ...) \
455 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
456#elif defined(CONFIG_DYNAMIC_DEBUG)
457/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
458#define pr_debug(fmt, ...) \
459 dynamic_pr_debug(fmt, ##__VA_ARGS__)
460#else
461#define pr_debug(fmt, ...) \
462 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
463#endif
464
465/*
466 * ratelimited messages with local ratelimit_state,
467 * no local ratelimit_state used in the !PRINTK case
468 */
469#ifdef CONFIG_PRINTK
470#define printk_ratelimited(fmt, ...) ({ \
471 static DEFINE_RATELIMIT_STATE(_rs, \
472 DEFAULT_RATELIMIT_INTERVAL, \
473 DEFAULT_RATELIMIT_BURST); \
474 \
475 if (__ratelimit(&_rs)) \
476 printk(fmt, ##__VA_ARGS__); \
477})
478#else
479/* No effect, but we still get type checking even in the !PRINTK case: */
480#define printk_ratelimited printk
481#endif
482
483#define pr_emerg_ratelimited(fmt, ...) \
484 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
485#define pr_alert_ratelimited(fmt, ...) \
486 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
487#define pr_crit_ratelimited(fmt, ...) \
488 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
489#define pr_err_ratelimited(fmt, ...) \
490 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
491#define pr_warning_ratelimited(fmt, ...) \
492 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
493#define pr_warn_ratelimited pr_warning_ratelimited
494#define pr_notice_ratelimited(fmt, ...) \
495 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
496#define pr_info_ratelimited(fmt, ...) \
497 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
498/* no pr_cont_ratelimited, don't do that... */
499/* If you are writing a driver, please use dev_dbg instead */
500#if defined(DEBUG)
501#define pr_debug_ratelimited(fmt, ...) \
502 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
503#else
504#define pr_debug_ratelimited(fmt, ...) \
505 ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
506 ##__VA_ARGS__); 0; })
507#endif
508
509/* 267/*
510 * General tracing related utility functions - trace_printk(), 268 * General tracing related utility functions - trace_printk(),
511 * tracing_on/tracing_off and tracing_start()/tracing_stop 269 * tracing_on/tracing_off and tracing_start()/tracing_stop
diff --git a/include/linux/leds-lp5521.h b/include/linux/leds-lp5521.h
new file mode 100644
index 000000000000..38368d785f08
--- /dev/null
+++ b/include/linux/leds-lp5521.h
@@ -0,0 +1,47 @@
1/*
2 * LP5521 LED chip driver.
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#ifndef __LINUX_LP5521_H
24#define __LINUX_LP5521_H
25
26/* See Documentation/leds/leds-lp5521.txt */
27
28struct lp5521_led_config {
29 u8 chan_nr;
30 u8 led_current; /* mA x10, 0 if led is not connected */
31 u8 max_current;
32};
33
34#define LP5521_CLOCK_AUTO 0
35#define LP5521_CLOCK_INT 1
36#define LP5521_CLOCK_EXT 2
37
38struct lp5521_platform_data {
39 struct lp5521_led_config *led_config;
40 u8 num_channels;
41 u8 clock_mode;
42 int (*setup_resources)(void);
43 void (*release_resources)(void);
44 void (*enable)(bool state);
45};
46
47#endif /* __LINUX_LP5521_H */
diff --git a/include/linux/leds-lp5523.h b/include/linux/leds-lp5523.h
new file mode 100644
index 000000000000..796747637b80
--- /dev/null
+++ b/include/linux/leds-lp5523.h
@@ -0,0 +1,47 @@
1/*
2 * LP5523 LED Driver
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#ifndef __LINUX_LP5523_H
24#define __LINUX_LP5523_H
25
26/* See Documentation/leds/leds-lp5523.txt */
27
28struct lp5523_led_config {
29 u8 chan_nr;
30 u8 led_current; /* mA x10, 0 if led is not connected */
31 u8 max_current;
32};
33
34#define LP5523_CLOCK_AUTO 0
35#define LP5523_CLOCK_INT 1
36#define LP5523_CLOCK_EXT 2
37
38struct lp5523_platform_data {
39 struct lp5523_led_config *led_config;
40 u8 num_channels;
41 u8 clock_mode;
42 int (*setup_resources)(void);
43 void (*release_resources)(void);
44 void (*enable)(bool state);
45};
46
47#endif /* __LINUX_LP5523_H */
diff --git a/include/linux/leds.h b/include/linux/leds.h
index ba6986a11663..0f19df9e37b0 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -15,6 +15,7 @@
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/rwsem.h> 17#include <linux/rwsem.h>
18#include <linux/timer.h>
18 19
19struct device; 20struct device;
20/* 21/*
@@ -45,10 +46,14 @@ struct led_classdev {
45 /* Get LED brightness level */ 46 /* Get LED brightness level */
46 enum led_brightness (*brightness_get)(struct led_classdev *led_cdev); 47 enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
47 48
48 /* Activate hardware accelerated blink, delays are in 49 /*
49 * miliseconds and if none is provided then a sensible default 50 * Activate hardware accelerated blink, delays are in milliseconds
50 * should be chosen. The call can adjust the timings if it can't 51 * and if both are zero then a sensible default should be chosen.
51 * match the values specified exactly. */ 52 * The call should adjust the timings in that case and if it can't
53 * match the values specified exactly.
54 * Deactivate blinking again when the brightness is set to a fixed
55 * value via the brightness_set() callback.
56 */
52 int (*blink_set)(struct led_classdev *led_cdev, 57 int (*blink_set)(struct led_classdev *led_cdev,
53 unsigned long *delay_on, 58 unsigned long *delay_on,
54 unsigned long *delay_off); 59 unsigned long *delay_off);
@@ -57,6 +62,10 @@ struct led_classdev {
57 struct list_head node; /* LED Device list */ 62 struct list_head node; /* LED Device list */
58 const char *default_trigger; /* Trigger to use */ 63 const char *default_trigger; /* Trigger to use */
59 64
65 unsigned long blink_delay_on, blink_delay_off;
66 struct timer_list blink_timer;
67 int blink_brightness;
68
60#ifdef CONFIG_LEDS_TRIGGERS 69#ifdef CONFIG_LEDS_TRIGGERS
61 /* Protects the trigger data below */ 70 /* Protects the trigger data below */
62 struct rw_semaphore trigger_lock; 71 struct rw_semaphore trigger_lock;
@@ -73,6 +82,36 @@ extern void led_classdev_unregister(struct led_classdev *led_cdev);
73extern void led_classdev_suspend(struct led_classdev *led_cdev); 82extern void led_classdev_suspend(struct led_classdev *led_cdev);
74extern void led_classdev_resume(struct led_classdev *led_cdev); 83extern void led_classdev_resume(struct led_classdev *led_cdev);
75 84
85/**
86 * led_blink_set - set blinking with software fallback
87 * @led_cdev: the LED to start blinking
88 * @delay_on: the time it should be on (in ms)
89 * @delay_off: the time it should ble off (in ms)
90 *
91 * This function makes the LED blink, attempting to use the
92 * hardware acceleration if possible, but falling back to
93 * software blinking if there is no hardware blinking or if
94 * the LED refuses the passed values.
95 *
96 * Note that if software blinking is active, simply calling
97 * led_cdev->brightness_set() will not stop the blinking,
98 * use led_classdev_brightness_set() instead.
99 */
100extern void led_blink_set(struct led_classdev *led_cdev,
101 unsigned long *delay_on,
102 unsigned long *delay_off);
103/**
104 * led_brightness_set - set LED brightness
105 * @led_cdev: the LED to set
106 * @brightness: the brightness to set it to
107 *
108 * Set an LED's brightness, and, if necessary, cancel the
109 * software blink timer that implements blinking when the
110 * hardware doesn't.
111 */
112extern void led_brightness_set(struct led_classdev *led_cdev,
113 enum led_brightness brightness);
114
76/* 115/*
77 * LED Triggers 116 * LED Triggers
78 */ 117 */
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 15b77b8dc7e1..d947b1231662 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -986,7 +986,7 @@ extern void ata_host_init(struct ata_host *, struct device *,
986 unsigned long, struct ata_port_operations *); 986 unsigned long, struct ata_port_operations *);
987extern int ata_scsi_detect(struct scsi_host_template *sht); 987extern int ata_scsi_detect(struct scsi_host_template *sht);
988extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 988extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
989extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)); 989extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
990extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev, 990extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
991 int cmd, void __user *arg); 991 int cmd, void __user *arg);
992extern void ata_sas_port_destroy(struct ata_port *); 992extern void ata_sas_port_destroy(struct ata_port *);
diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h
index a34dea46b629..2dee05e5119a 100644
--- a/include/linux/lockd/lockd.h
+++ b/include/linux/lockd/lockd.h
@@ -43,6 +43,7 @@ struct nlm_host {
43 struct sockaddr_storage h_addr; /* peer address */ 43 struct sockaddr_storage h_addr; /* peer address */
44 size_t h_addrlen; 44 size_t h_addrlen;
45 struct sockaddr_storage h_srcaddr; /* our address (optional) */ 45 struct sockaddr_storage h_srcaddr; /* our address (optional) */
46 size_t h_srcaddrlen;
46 struct rpc_clnt *h_rpcclnt; /* RPC client to talk to peer */ 47 struct rpc_clnt *h_rpcclnt; /* RPC client to talk to peer */
47 char *h_name; /* remote hostname */ 48 char *h_name; /* remote hostname */
48 u32 h_version; /* interface version */ 49 u32 h_version; /* interface version */
diff --git a/include/linux/marvell_phy.h b/include/linux/marvell_phy.h
index d0f08018335d..dd3c34ebca9a 100644
--- a/include/linux/marvell_phy.h
+++ b/include/linux/marvell_phy.h
@@ -11,8 +11,9 @@
11#define MARVELL_PHY_ID_88E1118 0x01410e10 11#define MARVELL_PHY_ID_88E1118 0x01410e10
12#define MARVELL_PHY_ID_88E1121R 0x01410cb0 12#define MARVELL_PHY_ID_88E1121R 0x01410cb0
13#define MARVELL_PHY_ID_88E1145 0x01410cd0 13#define MARVELL_PHY_ID_88E1145 0x01410cd0
14#define MARVELL_PHY_ID_88E1149R 0x01410e50
14#define MARVELL_PHY_ID_88E1240 0x01410e30 15#define MARVELL_PHY_ID_88E1240 0x01410e30
15#define MARVELL_PHY_ID_88EC048 0x01410e90 16#define MARVELL_PHY_ID_88E1318S 0x01410e90
16 17
17/* struct phy_device dev_flags definitions */ 18/* struct phy_device dev_flags definitions */
18#define MARVELL_PHY_M1145_FLAGS_RESISTANCE 0x00000001 19#define MARVELL_PHY_M1145_FLAGS_RESISTANCE 0x00000001
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 4307231bd22f..31c237a00c48 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -161,6 +161,9 @@ extern void register_page_bootmem_info_node(struct pglist_data *pgdat);
161extern void put_page_bootmem(struct page *page); 161extern void put_page_bootmem(struct page *page);
162#endif 162#endif
163 163
164void lock_memory_hotplug(void);
165void unlock_memory_hotplug(void);
166
164#else /* ! CONFIG_MEMORY_HOTPLUG */ 167#else /* ! CONFIG_MEMORY_HOTPLUG */
165/* 168/*
166 * Stub functions for when hotplug is off 169 * Stub functions for when hotplug is off
@@ -192,6 +195,9 @@ static inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
192{ 195{
193} 196}
194 197
198static inline void lock_memory_hotplug(void) {}
199static inline void unlock_memory_hotplug(void) {}
200
195#endif /* ! CONFIG_MEMORY_HOTPLUG */ 201#endif /* ! CONFIG_MEMORY_HOTPLUG */
196 202
197#ifdef CONFIG_MEMORY_HOTREMOVE 203#ifdef CONFIG_MEMORY_HOTREMOVE
diff --git a/include/linux/mfd/wm8350/audio.h b/include/linux/mfd/wm8350/audio.h
index a95141eafce3..bd581c6fa085 100644
--- a/include/linux/mfd/wm8350/audio.h
+++ b/include/linux/mfd/wm8350/audio.h
@@ -522,9 +522,6 @@
522#define WM8350_MCLK_SEL_PLL_32K 3 522#define WM8350_MCLK_SEL_PLL_32K 3
523#define WM8350_MCLK_SEL_MCLK 5 523#define WM8350_MCLK_SEL_MCLK 5
524 524
525#define WM8350_MCLK_DIR_OUT 0
526#define WM8350_MCLK_DIR_IN 1
527
528/* clock divider id's */ 525/* clock divider id's */
529#define WM8350_ADC_CLKDIV 0 526#define WM8350_ADC_CLKDIV 0
530#define WM8350_DAC_CLKDIV 1 527#define WM8350_DAC_CLKDIV 1
diff --git a/include/linux/mfd/wm8994/pdata.h b/include/linux/mfd/wm8994/pdata.h
index 5c51f367c061..add8a1b8bcf0 100644
--- a/include/linux/mfd/wm8994/pdata.h
+++ b/include/linux/mfd/wm8994/pdata.h
@@ -29,7 +29,7 @@ struct wm8994_ldo_pdata {
29#define WM8994_CONFIGURE_GPIO 0x8000 29#define WM8994_CONFIGURE_GPIO 0x8000
30 30
31#define WM8994_DRC_REGS 5 31#define WM8994_DRC_REGS 5
32#define WM8994_EQ_REGS 19 32#define WM8994_EQ_REGS 20
33 33
34/** 34/**
35 * DRC configurations are specified with a label and a set of register 35 * DRC configurations are specified with a label and a set of register
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 6d87f68ce4b6..30f6fad99a58 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -168,6 +168,7 @@ struct mmc_host {
168 /* DDR mode at 1.8V */ 168 /* DDR mode at 1.8V */
169#define MMC_CAP_1_2V_DDR (1 << 12) /* can support */ 169#define MMC_CAP_1_2V_DDR (1 << 12) /* can support */
170 /* DDR mode at 1.2V */ 170 /* DDR mode at 1.2V */
171#define MMC_CAP_POWER_OFF_CARD (1 << 13) /* Can power off after boot */
171 172
172 mmc_pm_flag_t pm_caps; /* supported pm features */ 173 mmc_pm_flag_t pm_caps; /* supported pm features */
173 174
diff --git a/include/linux/mmc/sh_mmcif.h b/include/linux/mmc/sh_mmcif.h
index d19e2114fd86..5c99da1078aa 100644
--- a/include/linux/mmc/sh_mmcif.h
+++ b/include/linux/mmc/sh_mmcif.h
@@ -59,19 +59,19 @@ struct sh_mmcif_plat_data {
59#define MMCIF_CE_HOST_STS2 0x0000004C 59#define MMCIF_CE_HOST_STS2 0x0000004C
60#define MMCIF_CE_VERSION 0x0000007C 60#define MMCIF_CE_VERSION 0x0000007C
61 61
62extern inline u32 sh_mmcif_readl(void __iomem *addr, int reg) 62static inline u32 sh_mmcif_readl(void __iomem *addr, int reg)
63{ 63{
64 return readl(addr + reg); 64 return readl(addr + reg);
65} 65}
66 66
67extern inline void sh_mmcif_writel(void __iomem *addr, int reg, u32 val) 67static inline void sh_mmcif_writel(void __iomem *addr, int reg, u32 val)
68{ 68{
69 writel(val, addr + reg); 69 writel(val, addr + reg);
70} 70}
71 71
72#define SH_MMCIF_BBS 512 /* boot block size */ 72#define SH_MMCIF_BBS 512 /* boot block size */
73 73
74extern inline void sh_mmcif_boot_cmd_send(void __iomem *base, 74static inline void sh_mmcif_boot_cmd_send(void __iomem *base,
75 unsigned long cmd, unsigned long arg) 75 unsigned long cmd, unsigned long arg)
76{ 76{
77 sh_mmcif_writel(base, MMCIF_CE_INT, 0); 77 sh_mmcif_writel(base, MMCIF_CE_INT, 0);
@@ -79,7 +79,7 @@ extern inline void sh_mmcif_boot_cmd_send(void __iomem *base,
79 sh_mmcif_writel(base, MMCIF_CE_CMD_SET, cmd); 79 sh_mmcif_writel(base, MMCIF_CE_CMD_SET, cmd);
80} 80}
81 81
82extern inline int sh_mmcif_boot_cmd_poll(void __iomem *base, unsigned long mask) 82static inline int sh_mmcif_boot_cmd_poll(void __iomem *base, unsigned long mask)
83{ 83{
84 unsigned long tmp; 84 unsigned long tmp;
85 int cnt; 85 int cnt;
@@ -95,14 +95,14 @@ extern inline int sh_mmcif_boot_cmd_poll(void __iomem *base, unsigned long mask)
95 return -1; 95 return -1;
96} 96}
97 97
98extern inline int sh_mmcif_boot_cmd(void __iomem *base, 98static inline int sh_mmcif_boot_cmd(void __iomem *base,
99 unsigned long cmd, unsigned long arg) 99 unsigned long cmd, unsigned long arg)
100{ 100{
101 sh_mmcif_boot_cmd_send(base, cmd, arg); 101 sh_mmcif_boot_cmd_send(base, cmd, arg);
102 return sh_mmcif_boot_cmd_poll(base, 0x00010000); 102 return sh_mmcif_boot_cmd_poll(base, 0x00010000);
103} 103}
104 104
105extern inline int sh_mmcif_boot_do_read_single(void __iomem *base, 105static inline int sh_mmcif_boot_do_read_single(void __iomem *base,
106 unsigned int block_nr, 106 unsigned int block_nr,
107 unsigned long *buf) 107 unsigned long *buf)
108{ 108{
@@ -125,7 +125,7 @@ extern inline int sh_mmcif_boot_do_read_single(void __iomem *base,
125 return 0; 125 return 0;
126} 126}
127 127
128extern inline int sh_mmcif_boot_do_read(void __iomem *base, 128static inline int sh_mmcif_boot_do_read(void __iomem *base,
129 unsigned long first_block, 129 unsigned long first_block,
130 unsigned long nr_blocks, 130 unsigned long nr_blocks,
131 void *buf) 131 void *buf)
@@ -143,7 +143,7 @@ extern inline int sh_mmcif_boot_do_read(void __iomem *base,
143 return ret; 143 return ret;
144} 144}
145 145
146extern inline void sh_mmcif_boot_init(void __iomem *base) 146static inline void sh_mmcif_boot_init(void __iomem *base)
147{ 147{
148 unsigned long tmp; 148 unsigned long tmp;
149 149
@@ -177,7 +177,7 @@ extern inline void sh_mmcif_boot_init(void __iomem *base)
177 sh_mmcif_boot_cmd(base, 0x03400040, 0x00010000); 177 sh_mmcif_boot_cmd(base, 0x03400040, 0x00010000);
178} 178}
179 179
180extern inline void sh_mmcif_boot_slurp(void __iomem *base, 180static inline void sh_mmcif_boot_slurp(void __iomem *base,
181 unsigned char *buf, 181 unsigned char *buf,
182 unsigned long no_bytes) 182 unsigned long no_bytes)
183{ 183{
diff --git a/include/linux/module.h b/include/linux/module.h
index b29e7458b966..7575bbbdf2a2 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -517,7 +517,7 @@ static inline void __module_get(struct module *module)
517#define symbol_put_addr(p) do { } while(0) 517#define symbol_put_addr(p) do { } while(0)
518 518
519#endif /* CONFIG_MODULE_UNLOAD */ 519#endif /* CONFIG_MODULE_UNLOAD */
520int use_module(struct module *a, struct module *b); 520int ref_module(struct module *a, struct module *b);
521 521
522/* This is a #define so the string doesn't get put in every .o file */ 522/* This is a #define so the string doesn't get put in every .o file */
523#define module_name(mod) \ 523#define module_name(mod) \
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 072652d94d9f..d8fd2c23a1b9 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1554,6 +1554,11 @@ static inline void netif_tx_wake_all_queues(struct net_device *dev)
1554 1554
1555static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue) 1555static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
1556{ 1556{
1557 if (WARN_ON(!dev_queue)) {
1558 printk(KERN_INFO "netif_stop_queue() cannot be called before "
1559 "register_netdev()");
1560 return;
1561 }
1557 set_bit(__QUEUE_STATE_XOFF, &dev_queue->state); 1562 set_bit(__QUEUE_STATE_XOFF, &dev_queue->state);
1558} 1563}
1559 1564
diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index 89341c32631a..03317c8d4077 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -215,7 +215,7 @@ NF_HOOK_COND(uint8_t pf, unsigned int hook, struct sk_buff *skb,
215 int ret; 215 int ret;
216 216
217 if (!cond || 217 if (!cond ||
218 (ret = nf_hook_thresh(pf, hook, skb, in, out, okfn, INT_MIN) == 1)) 218 ((ret = nf_hook_thresh(pf, hook, skb, in, out, okfn, INT_MIN)) == 1))
219 ret = okfn(skb); 219 ret = okfn(skb);
220 return ret; 220 return ret;
221} 221}
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index bba26684acdc..29d504d5d1c3 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -401,6 +401,7 @@ extern const struct inode_operations nfs3_file_inode_operations;
401#endif /* CONFIG_NFS_V3 */ 401#endif /* CONFIG_NFS_V3 */
402extern const struct file_operations nfs_file_operations; 402extern const struct file_operations nfs_file_operations;
403extern const struct address_space_operations nfs_file_aops; 403extern const struct address_space_operations nfs_file_aops;
404extern const struct address_space_operations nfs_dir_aops;
404 405
405static inline struct nfs_open_context *nfs_file_open_context(struct file *filp) 406static inline struct nfs_open_context *nfs_file_open_context(struct file *filp)
406{ 407{
@@ -593,12 +594,6 @@ nfs_fileid_to_ino_t(u64 fileid)
593 return ino; 594 return ino;
594} 595}
595 596
596#define nfs_wait_event(clnt, wq, condition) \
597({ \
598 int __retval = wait_event_killable(wq, condition); \
599 __retval; \
600})
601
602#define NFS_JUKEBOX_RETRY_TIME (5 * HZ) 597#define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
603 598
604#endif /* __KERNEL__ */ 599#endif /* __KERNEL__ */
diff --git a/include/linux/nfs_page.h b/include/linux/nfs_page.h
index f8b60e7f4c44..d55cee73f634 100644
--- a/include/linux/nfs_page.h
+++ b/include/linux/nfs_page.h
@@ -29,6 +29,7 @@
29 */ 29 */
30enum { 30enum {
31 PG_BUSY = 0, 31 PG_BUSY = 0,
32 PG_MAPPED,
32 PG_CLEAN, 33 PG_CLEAN,
33 PG_NEED_COMMIT, 34 PG_NEED_COMMIT,
34 PG_NEED_RESCHED, 35 PG_NEED_RESCHED,
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index ba6cc8f223c9..80f07198a31a 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -483,6 +483,7 @@ struct nfs_entry {
483 int eof; 483 int eof;
484 struct nfs_fh * fh; 484 struct nfs_fh * fh;
485 struct nfs_fattr * fattr; 485 struct nfs_fattr * fattr;
486 unsigned char d_type;
486}; 487};
487 488
488/* 489/*
diff --git a/include/linux/node.h b/include/linux/node.h
index 06292dac3eab..1466945cc9ef 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -10,11 +10,6 @@
10 * 10 *
11 * Nodes are exported via driverfs in the class/node/devices/ 11 * Nodes are exported via driverfs in the class/node/devices/
12 * directory. 12 * directory.
13 *
14 * Per-node interfaces can be implemented using a struct device_interface.
15 * See the following for how to do this:
16 * - drivers/base/intf.c
17 * - Documentation/driver-model/interface.txt
18 */ 13 */
19#ifndef _LINUX_NODE_H_ 14#ifndef _LINUX_NODE_H_
20#define _LINUX_NODE_H_ 15#define _LINUX_NODE_H_
diff --git a/include/linux/page_cgroup.h b/include/linux/page_cgroup.h
index 5bb13b3db84d..b02195dfc1b0 100644
--- a/include/linux/page_cgroup.h
+++ b/include/linux/page_cgroup.h
@@ -59,8 +59,6 @@ static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
59static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \ 59static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
60 { return test_and_clear_bit(PCG_##lname, &pc->flags); } 60 { return test_and_clear_bit(PCG_##lname, &pc->flags); }
61 61
62TESTPCGFLAG(Locked, LOCK)
63
64/* Cache flag is set only once (at allocation) */ 62/* Cache flag is set only once (at allocation) */
65TESTPCGFLAG(Cache, CACHE) 63TESTPCGFLAG(Cache, CACHE)
66CLEARPCGFLAG(Cache, CACHE) 64CLEARPCGFLAG(Cache, CACHE)
@@ -104,6 +102,11 @@ static inline void unlock_page_cgroup(struct page_cgroup *pc)
104 bit_spin_unlock(PCG_LOCK, &pc->flags); 102 bit_spin_unlock(PCG_LOCK, &pc->flags);
105} 103}
106 104
105static inline int page_is_cgroup_locked(struct page_cgroup *pc)
106{
107 return bit_spin_is_locked(PCG_LOCK, &pc->flags);
108}
109
107#else /* CONFIG_CGROUP_MEM_RES_CTLR */ 110#else /* CONFIG_CGROUP_MEM_RES_CTLR */
108struct page_cgroup; 111struct page_cgroup;
109 112
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 87e2c2e7aed3..cb845c16ad7d 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2047,6 +2047,7 @@
2047#define PCI_DEVICE_ID_AFAVLAB_P030 0x2182 2047#define PCI_DEVICE_ID_AFAVLAB_P030 0x2182
2048#define PCI_SUBDEVICE_ID_AFAVLAB_P061 0x2150 2048#define PCI_SUBDEVICE_ID_AFAVLAB_P061 0x2150
2049 2049
2050#define PCI_VENDOR_ID_BCM_GVC 0x14a4
2050#define PCI_VENDOR_ID_BROADCOM 0x14e4 2051#define PCI_VENDOR_ID_BROADCOM 0x14e4
2051#define PCI_DEVICE_ID_TIGON3_5752 0x1600 2052#define PCI_DEVICE_ID_TIGON3_5752 0x1600
2052#define PCI_DEVICE_ID_TIGON3_5752M 0x1601 2053#define PCI_DEVICE_ID_TIGON3_5752M 0x1601
@@ -2441,6 +2442,7 @@
2441#define PCI_DEVICE_ID_INTEL_MFD_SDIO2 0x0822 2442#define PCI_DEVICE_ID_INTEL_MFD_SDIO2 0x0822
2442#define PCI_DEVICE_ID_INTEL_MFD_EMMC0 0x0823 2443#define PCI_DEVICE_ID_INTEL_MFD_EMMC0 0x0823
2443#define PCI_DEVICE_ID_INTEL_MFD_EMMC1 0x0824 2444#define PCI_DEVICE_ID_INTEL_MFD_EMMC1 0x0824
2445#define PCI_DEVICE_ID_INTEL_MRST_SD2 0x084F
2444#define PCI_DEVICE_ID_INTEL_I960 0x0960 2446#define PCI_DEVICE_ID_INTEL_I960 0x0960
2445#define PCI_DEVICE_ID_INTEL_I960RM 0x0962 2447#define PCI_DEVICE_ID_INTEL_I960RM 0x0962
2446#define PCI_DEVICE_ID_INTEL_8257X_SOL 0x1062 2448#define PCI_DEVICE_ID_INTEL_8257X_SOL 0x1062
@@ -2465,6 +2467,7 @@
2465#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22 2467#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
2466#define PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MIN 0x1c41 2468#define PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MIN 0x1c41
2467#define PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MAX 0x1c5f 2469#define PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MAX 0x1c5f
2470#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
2468#define PCI_DEVICE_ID_INTEL_PATSBURG_LPC 0x1d40 2471#define PCI_DEVICE_ID_INTEL_PATSBURG_LPC 0x1d40
2469#define PCI_DEVICE_ID_INTEL_82801AA_0 0x2410 2472#define PCI_DEVICE_ID_INTEL_82801AA_0 0x2410
2470#define PCI_DEVICE_ID_INTEL_82801AA_1 0x2411 2473#define PCI_DEVICE_ID_INTEL_82801AA_1 0x2411
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 057bf22a8323..4f1279e105ee 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -747,6 +747,16 @@ struct perf_event {
747 u64 tstamp_running; 747 u64 tstamp_running;
748 u64 tstamp_stopped; 748 u64 tstamp_stopped;
749 749
750 /*
751 * timestamp shadows the actual context timing but it can
752 * be safely used in NMI interrupt context. It reflects the
753 * context time as it was when the event was last scheduled in.
754 *
755 * ctx_time already accounts for ctx->timestamp. Therefore to
756 * compute ctx_time for a sample, simply add perf_clock().
757 */
758 u64 shadow_ctx_time;
759
750 struct perf_event_attr attr; 760 struct perf_event_attr attr;
751 struct hw_perf_event hw; 761 struct hw_perf_event hw;
752 762
@@ -840,6 +850,7 @@ struct perf_event_context {
840 int nr_active; 850 int nr_active;
841 int is_active; 851 int is_active;
842 int nr_stat; 852 int nr_stat;
853 int rotate_disable;
843 atomic_t refcount; 854 atomic_t refcount;
844 struct task_struct *task; 855 struct task_struct *task;
845 856
@@ -876,6 +887,7 @@ struct perf_cpu_context {
876 int exclusive; 887 int exclusive;
877 struct list_head rotation_list; 888 struct list_head rotation_list;
878 int jiffies_interval; 889 int jiffies_interval;
890 struct pmu *active_pmu;
879}; 891};
880 892
881struct perf_output_handle { 893struct perf_output_handle {
@@ -898,20 +910,6 @@ extern int perf_num_counters(void);
898extern const char *perf_pmu_name(void); 910extern const char *perf_pmu_name(void);
899extern void __perf_event_task_sched_in(struct task_struct *task); 911extern void __perf_event_task_sched_in(struct task_struct *task);
900extern void __perf_event_task_sched_out(struct task_struct *task, struct task_struct *next); 912extern void __perf_event_task_sched_out(struct task_struct *task, struct task_struct *next);
901
902extern atomic_t perf_task_events;
903
904static inline void perf_event_task_sched_in(struct task_struct *task)
905{
906 COND_STMT(&perf_task_events, __perf_event_task_sched_in(task));
907}
908
909static inline
910void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next)
911{
912 COND_STMT(&perf_task_events, __perf_event_task_sched_out(task, next));
913}
914
915extern int perf_event_init_task(struct task_struct *child); 913extern int perf_event_init_task(struct task_struct *child);
916extern void perf_event_exit_task(struct task_struct *child); 914extern void perf_event_exit_task(struct task_struct *child);
917extern void perf_event_free_task(struct task_struct *task); 915extern void perf_event_free_task(struct task_struct *task);
@@ -1020,6 +1018,21 @@ have_event:
1020 __perf_sw_event(event_id, nr, nmi, regs, addr); 1018 __perf_sw_event(event_id, nr, nmi, regs, addr);
1021} 1019}
1022 1020
1021extern atomic_t perf_task_events;
1022
1023static inline void perf_event_task_sched_in(struct task_struct *task)
1024{
1025 COND_STMT(&perf_task_events, __perf_event_task_sched_in(task));
1026}
1027
1028static inline
1029void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next)
1030{
1031 perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 1, NULL, 0);
1032
1033 COND_STMT(&perf_task_events, __perf_event_task_sched_out(task, next));
1034}
1035
1023extern void perf_event_mmap(struct vm_area_struct *vma); 1036extern void perf_event_mmap(struct vm_area_struct *vma);
1024extern struct perf_guest_info_callbacks *perf_guest_cbs; 1037extern struct perf_guest_info_callbacks *perf_guest_cbs;
1025extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); 1038extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
index 445796945ac9..bb27d7ec2fb9 100644
--- a/include/linux/pipe_fs_i.h
+++ b/include/linux/pipe_fs_i.h
@@ -160,5 +160,6 @@ void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *);
160 160
161/* for F_SETPIPE_SZ and F_GETPIPE_SZ */ 161/* for F_SETPIPE_SZ and F_GETPIPE_SZ */
162long pipe_fcntl(struct file *, unsigned int, unsigned long arg); 162long pipe_fcntl(struct file *, unsigned int, unsigned long arg);
163struct pipe_inode_info *get_pipe_info(struct file *file);
163 164
164#endif 165#endif
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 3ec2358f8692..d19f1cca7f74 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -77,7 +77,8 @@ static inline void device_set_run_wake(struct device *dev, bool enable)
77 77
78static inline bool pm_runtime_suspended(struct device *dev) 78static inline bool pm_runtime_suspended(struct device *dev)
79{ 79{
80 return dev->power.runtime_status == RPM_SUSPENDED; 80 return dev->power.runtime_status == RPM_SUSPENDED
81 && !dev->power.disable_depth;
81} 82}
82 83
83static inline void pm_runtime_mark_last_busy(struct device *dev) 84static inline void pm_runtime_mark_last_busy(struct device *dev)
diff --git a/include/linux/printk.h b/include/linux/printk.h
new file mode 100644
index 000000000000..b772ca5fbdf0
--- /dev/null
+++ b/include/linux/printk.h
@@ -0,0 +1,248 @@
1#ifndef __KERNEL_PRINTK__
2#define __KERNEL_PRINTK__
3
4extern const char linux_banner[];
5extern const char linux_proc_banner[];
6
7#define KERN_EMERG "<0>" /* system is unusable */
8#define KERN_ALERT "<1>" /* action must be taken immediately */
9#define KERN_CRIT "<2>" /* critical conditions */
10#define KERN_ERR "<3>" /* error conditions */
11#define KERN_WARNING "<4>" /* warning conditions */
12#define KERN_NOTICE "<5>" /* normal but significant condition */
13#define KERN_INFO "<6>" /* informational */
14#define KERN_DEBUG "<7>" /* debug-level messages */
15
16/* Use the default kernel loglevel */
17#define KERN_DEFAULT "<d>"
18/*
19 * Annotation for a "continued" line of log printout (only done after a
20 * line that had no enclosing \n). Only to be used by core/arch code
21 * during early bootup (a continued line is not SMP-safe otherwise).
22 */
23#define KERN_CONT "<c>"
24
25extern int console_printk[];
26
27#define console_loglevel (console_printk[0])
28#define default_message_loglevel (console_printk[1])
29#define minimum_console_loglevel (console_printk[2])
30#define default_console_loglevel (console_printk[3])
31
32struct va_format {
33 const char *fmt;
34 va_list *va;
35};
36
37/*
38 * FW_BUG
39 * Add this to a message where you are sure the firmware is buggy or behaves
40 * really stupid or out of spec. Be aware that the responsible BIOS developer
41 * should be able to fix this issue or at least get a concrete idea of the
42 * problem by reading your message without the need of looking at the kernel
43 * code.
44 *
45 * Use it for definite and high priority BIOS bugs.
46 *
47 * FW_WARN
48 * Use it for not that clear (e.g. could the kernel messed up things already?)
49 * and medium priority BIOS bugs.
50 *
51 * FW_INFO
52 * Use this one if you want to tell the user or vendor about something
53 * suspicious, but generally harmless related to the firmware.
54 *
55 * Use it for information or very low priority BIOS bugs.
56 */
57#define FW_BUG "[Firmware Bug]: "
58#define FW_WARN "[Firmware Warn]: "
59#define FW_INFO "[Firmware Info]: "
60
61/*
62 * HW_ERR
63 * Add this to a message for hardware errors, so that user can report
64 * it to hardware vendor instead of LKML or software vendor.
65 */
66#define HW_ERR "[Hardware Error]: "
67
68#ifdef CONFIG_PRINTK
69asmlinkage int vprintk(const char *fmt, va_list args)
70 __attribute__ ((format (printf, 1, 0)));
71asmlinkage int printk(const char * fmt, ...)
72 __attribute__ ((format (printf, 1, 2))) __cold;
73
74/*
75 * Please don't use printk_ratelimit(), because it shares ratelimiting state
76 * with all other unrelated printk_ratelimit() callsites. Instead use
77 * printk_ratelimited() or plain old __ratelimit().
78 */
79extern int __printk_ratelimit(const char *func);
80#define printk_ratelimit() __printk_ratelimit(__func__)
81extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
82 unsigned int interval_msec);
83
84extern int printk_delay_msec;
85extern int dmesg_restrict;
86
87/*
88 * Print a one-time message (analogous to WARN_ONCE() et al):
89 */
90#define printk_once(x...) ({ \
91 static bool __print_once; \
92 \
93 if (!__print_once) { \
94 __print_once = true; \
95 printk(x); \
96 } \
97})
98
99void log_buf_kexec_setup(void);
100#else
101static inline int vprintk(const char *s, va_list args)
102 __attribute__ ((format (printf, 1, 0)));
103static inline int vprintk(const char *s, va_list args) { return 0; }
104static inline int printk(const char *s, ...)
105 __attribute__ ((format (printf, 1, 2)));
106static inline int __cold printk(const char *s, ...) { return 0; }
107static inline int printk_ratelimit(void) { return 0; }
108static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
109 unsigned int interval_msec) \
110 { return false; }
111
112/* No effect, but we still get type checking even in the !PRINTK case: */
113#define printk_once(x...) printk(x)
114
115static inline void log_buf_kexec_setup(void)
116{
117}
118#endif
119
120/*
121 * Dummy printk for disabled debugging statements to use whilst maintaining
122 * gcc's format and side-effect checking.
123 */
124static inline __attribute__ ((format (printf, 1, 2)))
125int no_printk(const char *s, ...) { return 0; }
126
127extern int printk_needs_cpu(int cpu);
128extern void printk_tick(void);
129
130extern void asmlinkage __attribute__((format(printf, 1, 2)))
131 early_printk(const char *fmt, ...);
132
133static inline void console_silent(void)
134{
135 console_loglevel = 0;
136}
137
138static inline void console_verbose(void)
139{
140 if (console_loglevel)
141 console_loglevel = 15;
142}
143
144extern void dump_stack(void) __cold;
145
146enum {
147 DUMP_PREFIX_NONE,
148 DUMP_PREFIX_ADDRESS,
149 DUMP_PREFIX_OFFSET
150};
151extern void hex_dump_to_buffer(const void *buf, size_t len,
152 int rowsize, int groupsize,
153 char *linebuf, size_t linebuflen, bool ascii);
154extern void print_hex_dump(const char *level, const char *prefix_str,
155 int prefix_type, int rowsize, int groupsize,
156 const void *buf, size_t len, bool ascii);
157extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
158 const void *buf, size_t len);
159
160#ifndef pr_fmt
161#define pr_fmt(fmt) fmt
162#endif
163
164#define pr_emerg(fmt, ...) \
165 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
166#define pr_alert(fmt, ...) \
167 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
168#define pr_crit(fmt, ...) \
169 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
170#define pr_err(fmt, ...) \
171 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
172#define pr_warning(fmt, ...) \
173 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
174#define pr_warn pr_warning
175#define pr_notice(fmt, ...) \
176 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
177#define pr_info(fmt, ...) \
178 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
179#define pr_cont(fmt, ...) \
180 printk(KERN_CONT fmt, ##__VA_ARGS__)
181
182/* pr_devel() should produce zero code unless DEBUG is defined */
183#ifdef DEBUG
184#define pr_devel(fmt, ...) \
185 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
186#else
187#define pr_devel(fmt, ...) \
188 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
189#endif
190
191/* If you are writing a driver, please use dev_dbg instead */
192#if defined(DEBUG)
193#define pr_debug(fmt, ...) \
194 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
195#elif defined(CONFIG_DYNAMIC_DEBUG)
196/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
197#define pr_debug(fmt, ...) \
198 dynamic_pr_debug(fmt, ##__VA_ARGS__)
199#else
200#define pr_debug(fmt, ...) \
201 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
202#endif
203
204/*
205 * ratelimited messages with local ratelimit_state,
206 * no local ratelimit_state used in the !PRINTK case
207 */
208#ifdef CONFIG_PRINTK
209#define printk_ratelimited(fmt, ...) ({ \
210 static DEFINE_RATELIMIT_STATE(_rs, \
211 DEFAULT_RATELIMIT_INTERVAL, \
212 DEFAULT_RATELIMIT_BURST); \
213 \
214 if (__ratelimit(&_rs)) \
215 printk(fmt, ##__VA_ARGS__); \
216})
217#else
218/* No effect, but we still get type checking even in the !PRINTK case: */
219#define printk_ratelimited printk
220#endif
221
222#define pr_emerg_ratelimited(fmt, ...) \
223 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
224#define pr_alert_ratelimited(fmt, ...) \
225 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
226#define pr_crit_ratelimited(fmt, ...) \
227 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
228#define pr_err_ratelimited(fmt, ...) \
229 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
230#define pr_warning_ratelimited(fmt, ...) \
231 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
232#define pr_warn_ratelimited pr_warning_ratelimited
233#define pr_notice_ratelimited(fmt, ...) \
234 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
235#define pr_info_ratelimited(fmt, ...) \
236 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
237/* no pr_cont_ratelimited, don't do that... */
238/* If you are writing a driver, please use dev_dbg instead */
239#if defined(DEBUG)
240#define pr_debug_ratelimited(fmt, ...) \
241 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
242#else
243#define pr_debug_ratelimited(fmt, ...) \
244 ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
245 ##__VA_ARGS__); 0; })
246#endif
247
248#endif
diff --git a/include/linux/pwm_backlight.h b/include/linux/pwm_backlight.h
index 01b3d759f1fc..e031e1a486d9 100644
--- a/include/linux/pwm_backlight.h
+++ b/include/linux/pwm_backlight.h
@@ -8,6 +8,7 @@ struct platform_pwm_backlight_data {
8 int pwm_id; 8 int pwm_id;
9 unsigned int max_brightness; 9 unsigned int max_brightness;
10 unsigned int dft_brightness; 10 unsigned int dft_brightness;
11 unsigned int lth_brightness;
11 unsigned int pwm_period_ns; 12 unsigned int pwm_period_ns;
12 int (*init)(struct device *dev); 13 int (*init)(struct device *dev);
13 int (*notify)(struct device *dev, int brightness); 14 int (*notify)(struct device *dev, int brightness);
diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
index a39cbed9ee17..ab2baa5c4884 100644
--- a/include/linux/radix-tree.h
+++ b/include/linux/radix-tree.h
@@ -34,19 +34,13 @@
34 * needed for RCU lookups (because root->height is unreliable). The only 34 * needed for RCU lookups (because root->height is unreliable). The only
35 * time callers need worry about this is when doing a lookup_slot under 35 * time callers need worry about this is when doing a lookup_slot under
36 * RCU. 36 * RCU.
37 *
38 * Indirect pointer in fact is also used to tag the last pointer of a node
39 * when it is shrunk, before we rcu free the node. See shrink code for
40 * details.
37 */ 41 */
38#define RADIX_TREE_INDIRECT_PTR 1 42#define RADIX_TREE_INDIRECT_PTR 1
39#define RADIX_TREE_RETRY ((void *)-1UL)
40
41static inline void *radix_tree_ptr_to_indirect(void *ptr)
42{
43 return (void *)((unsigned long)ptr | RADIX_TREE_INDIRECT_PTR);
44}
45 43
46static inline void *radix_tree_indirect_to_ptr(void *ptr)
47{
48 return (void *)((unsigned long)ptr & ~RADIX_TREE_INDIRECT_PTR);
49}
50#define radix_tree_indirect_to_ptr(ptr) \ 44#define radix_tree_indirect_to_ptr(ptr) \
51 radix_tree_indirect_to_ptr((void __force *)(ptr)) 45 radix_tree_indirect_to_ptr((void __force *)(ptr))
52 46
@@ -140,16 +134,29 @@ do { \
140 * removed. 134 * removed.
141 * 135 *
142 * For use with radix_tree_lookup_slot(). Caller must hold tree at least read 136 * For use with radix_tree_lookup_slot(). Caller must hold tree at least read
143 * locked across slot lookup and dereference. More likely, will be used with 137 * locked across slot lookup and dereference. Not required if write lock is
144 * radix_tree_replace_slot(), as well, so caller will hold tree write locked. 138 * held (ie. items cannot be concurrently inserted).
139 *
140 * radix_tree_deref_retry must be used to confirm validity of the pointer if
141 * only the read lock is held.
145 */ 142 */
146static inline void *radix_tree_deref_slot(void **pslot) 143static inline void *radix_tree_deref_slot(void **pslot)
147{ 144{
148 void *ret = rcu_dereference(*pslot); 145 return rcu_dereference(*pslot);
149 if (unlikely(radix_tree_is_indirect_ptr(ret)))
150 ret = RADIX_TREE_RETRY;
151 return ret;
152} 146}
147
148/**
149 * radix_tree_deref_retry - check radix_tree_deref_slot
150 * @arg: pointer returned by radix_tree_deref_slot
151 * Returns: 0 if retry is not required, otherwise retry is required
152 *
153 * radix_tree_deref_retry must be used with radix_tree_deref_slot.
154 */
155static inline int radix_tree_deref_retry(void *arg)
156{
157 return unlikely((unsigned long)arg & RADIX_TREE_INDIRECT_PTR);
158}
159
153/** 160/**
154 * radix_tree_replace_slot - replace item in a slot 161 * radix_tree_replace_slot - replace item in a slot
155 * @pslot: pointer to slot, returned by radix_tree_lookup_slot 162 * @pslot: pointer to slot, returned by radix_tree_lookup_slot
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index 5ca47e59b727..c21072adbfad 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -22,7 +22,6 @@
22#include <asm/unaligned.h> 22#include <asm/unaligned.h>
23#include <linux/bitops.h> 23#include <linux/bitops.h>
24#include <linux/proc_fs.h> 24#include <linux/proc_fs.h>
25#include <linux/smp_lock.h>
26#include <linux/buffer_head.h> 25#include <linux/buffer_head.h>
27#include <linux/reiserfs_fs_i.h> 26#include <linux/reiserfs_fs_i.h>
28#include <linux/reiserfs_fs_sb.h> 27#include <linux/reiserfs_fs_sb.h>
diff --git a/include/linux/resource.h b/include/linux/resource.h
index 88d36f9145ba..d01c96c1966e 100644
--- a/include/linux/resource.h
+++ b/include/linux/resource.h
@@ -2,6 +2,7 @@
2#define _LINUX_RESOURCE_H 2#define _LINUX_RESOURCE_H
3 3
4#include <linux/time.h> 4#include <linux/time.h>
5#include <linux/types.h>
5 6
6/* 7/*
7 * Resource control/accounting header file for linux 8 * Resource control/accounting header file for linux
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index d42f274418b8..bbad657a3725 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -6,7 +6,6 @@
6#include <linux/if_link.h> 6#include <linux/if_link.h>
7#include <linux/if_addr.h> 7#include <linux/if_addr.h>
8#include <linux/neighbour.h> 8#include <linux/neighbour.h>
9#include <linux/netdevice.h>
10 9
11/* rtnetlink families. Values up to 127 are reserved for real address 10/* rtnetlink families. Values up to 127 are reserved for real address
12 * families, values above 128 may be used arbitrarily. 11 * families, values above 128 may be used arbitrarily.
@@ -606,6 +605,7 @@ struct tcamsg {
606#ifdef __KERNEL__ 605#ifdef __KERNEL__
607 606
608#include <linux/mutex.h> 607#include <linux/mutex.h>
608#include <linux/netdevice.h>
609 609
610static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str) 610static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str)
611{ 611{
diff --git a/include/linux/sched.h b/include/linux/sched.h
index d0036e52a24a..223874538b33 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -143,7 +143,7 @@ extern unsigned long nr_iowait_cpu(int cpu);
143extern unsigned long this_cpu_load(void); 143extern unsigned long this_cpu_load(void);
144 144
145 145
146extern void calc_global_load(void); 146extern void calc_global_load(unsigned long ticks);
147 147
148extern unsigned long get_parent_ip(unsigned long addr); 148extern unsigned long get_parent_ip(unsigned long addr);
149 149
@@ -862,6 +862,7 @@ struct sched_group {
862 * single CPU. 862 * single CPU.
863 */ 863 */
864 unsigned int cpu_power, cpu_power_orig; 864 unsigned int cpu_power, cpu_power_orig;
865 unsigned int group_weight;
865 866
866 /* 867 /*
867 * The CPUs this group covers. 868 * The CPUs this group covers.
diff --git a/include/linux/security.h b/include/linux/security.h
index b8246a8df7d2..fd4d55fb8845 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -77,7 +77,6 @@ extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
77extern int cap_task_setscheduler(struct task_struct *p); 77extern int cap_task_setscheduler(struct task_struct *p);
78extern int cap_task_setioprio(struct task_struct *p, int ioprio); 78extern int cap_task_setioprio(struct task_struct *p, int ioprio);
79extern int cap_task_setnice(struct task_struct *p, int nice); 79extern int cap_task_setnice(struct task_struct *p, int nice);
80extern int cap_syslog(int type, bool from_file);
81extern int cap_vm_enough_memory(struct mm_struct *mm, long pages); 80extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
82 81
83struct msghdr; 82struct msghdr;
@@ -1388,7 +1387,7 @@ struct security_operations {
1388 int (*sysctl) (struct ctl_table *table, int op); 1387 int (*sysctl) (struct ctl_table *table, int op);
1389 int (*quotactl) (int cmds, int type, int id, struct super_block *sb); 1388 int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
1390 int (*quota_on) (struct dentry *dentry); 1389 int (*quota_on) (struct dentry *dentry);
1391 int (*syslog) (int type, bool from_file); 1390 int (*syslog) (int type);
1392 int (*settime) (struct timespec *ts, struct timezone *tz); 1391 int (*settime) (struct timespec *ts, struct timezone *tz);
1393 int (*vm_enough_memory) (struct mm_struct *mm, long pages); 1392 int (*vm_enough_memory) (struct mm_struct *mm, long pages);
1394 1393
@@ -1671,7 +1670,7 @@ int security_real_capable_noaudit(struct task_struct *tsk, int cap);
1671int security_sysctl(struct ctl_table *table, int op); 1670int security_sysctl(struct ctl_table *table, int op);
1672int security_quotactl(int cmds, int type, int id, struct super_block *sb); 1671int security_quotactl(int cmds, int type, int id, struct super_block *sb);
1673int security_quota_on(struct dentry *dentry); 1672int security_quota_on(struct dentry *dentry);
1674int security_syslog(int type, bool from_file); 1673int security_syslog(int type);
1675int security_settime(struct timespec *ts, struct timezone *tz); 1674int security_settime(struct timespec *ts, struct timezone *tz);
1676int security_vm_enough_memory(long pages); 1675int security_vm_enough_memory(long pages);
1677int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); 1676int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
@@ -1901,9 +1900,9 @@ static inline int security_quota_on(struct dentry *dentry)
1901 return 0; 1900 return 0;
1902} 1901}
1903 1902
1904static inline int security_syslog(int type, bool from_file) 1903static inline int security_syslog(int type)
1905{ 1904{
1906 return cap_syslog(type, from_file); 1905 return 0;
1907} 1906}
1908 1907
1909static inline int security_settime(struct timespec *ts, struct timezone *tz) 1908static inline int security_settime(struct timespec *ts, struct timezone *tz)
diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
index 5310d27abd2a..39fa04966aa8 100644
--- a/include/linux/semaphore.h
+++ b/include/linux/semaphore.h
@@ -29,9 +29,6 @@ struct semaphore {
29#define DEFINE_SEMAPHORE(name) \ 29#define DEFINE_SEMAPHORE(name) \
30 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1) 30 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
31 31
32#define DECLARE_MUTEX(name) \
33 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
34
35static inline void sema_init(struct semaphore *sem, int val) 32static inline void sema_init(struct semaphore *sem, int val)
36{ 33{
37 static struct lock_class_key __key; 34 static struct lock_class_key __key;
@@ -39,9 +36,6 @@ static inline void sema_init(struct semaphore *sem, int val)
39 lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0); 36 lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
40} 37}
41 38
42#define init_MUTEX(sem) sema_init(sem, 1)
43#define init_MUTEX_LOCKED(sem) sema_init(sem, 0)
44
45extern void down(struct semaphore *sem); 39extern void down(struct semaphore *sem);
46extern int __must_check down_interruptible(struct semaphore *sem); 40extern int __must_check down_interruptible(struct semaphore *sem);
47extern int __must_check down_killable(struct semaphore *sem); 41extern int __must_check down_killable(struct semaphore *sem);
diff --git a/include/linux/sh_clk.h b/include/linux/sh_clk.h
index 4dca992f3093..9a52f72527dc 100644
--- a/include/linux/sh_clk.h
+++ b/include/linux/sh_clk.h
@@ -19,11 +19,13 @@ struct clk_mapping {
19}; 19};
20 20
21struct clk_ops { 21struct clk_ops {
22#ifdef CONFIG_SH_CLK_CPG_LEGACY
22 void (*init)(struct clk *clk); 23 void (*init)(struct clk *clk);
24#endif
23 int (*enable)(struct clk *clk); 25 int (*enable)(struct clk *clk);
24 void (*disable)(struct clk *clk); 26 void (*disable)(struct clk *clk);
25 unsigned long (*recalc)(struct clk *clk); 27 unsigned long (*recalc)(struct clk *clk);
26 int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id); 28 int (*set_rate)(struct clk *clk, unsigned long rate);
27 int (*set_parent)(struct clk *clk, struct clk *parent); 29 int (*set_parent)(struct clk *clk, struct clk *parent);
28 long (*round_rate)(struct clk *clk, unsigned long rate); 30 long (*round_rate)(struct clk *clk, unsigned long rate);
29}; 31};
@@ -67,36 +69,6 @@ int clk_register(struct clk *);
67void clk_unregister(struct clk *); 69void clk_unregister(struct clk *);
68void clk_enable_init_clocks(void); 70void clk_enable_init_clocks(void);
69 71
70/**
71 * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter
72 * @clk: clock source
73 * @rate: desired clock rate in Hz
74 * @algo_id: algorithm id to be passed down to ops->set_rate
75 *
76 * Returns success (0) or negative errno.
77 */
78int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id);
79
80enum clk_sh_algo_id {
81 NO_CHANGE = 0,
82
83 IUS_N1_N1,
84 IUS_322,
85 IUS_522,
86 IUS_N11,
87
88 SB_N1,
89
90 SB3_N1,
91 SB3_32,
92 SB3_43,
93 SB3_54,
94
95 BP_N1,
96
97 IP_N1,
98};
99
100struct clk_div_mult_table { 72struct clk_div_mult_table {
101 unsigned int *divisors; 73 unsigned int *divisors;
102 unsigned int nr_divisors; 74 unsigned int nr_divisors;
@@ -122,6 +94,10 @@ int clk_rate_table_find(struct clk *clk,
122long clk_rate_div_range_round(struct clk *clk, unsigned int div_min, 94long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
123 unsigned int div_max, unsigned long rate); 95 unsigned int div_max, unsigned long rate);
124 96
97long clk_round_parent(struct clk *clk, unsigned long target,
98 unsigned long *best_freq, unsigned long *parent_freq,
99 unsigned int div_min, unsigned int div_max);
100
125#define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \ 101#define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \
126{ \ 102{ \
127 .parent = _parent, \ 103 .parent = _parent, \
diff --git a/include/linux/sh_intc.h b/include/linux/sh_intc.h
index f656d1a43dc0..5812fefbcedf 100644
--- a/include/linux/sh_intc.h
+++ b/include/linux/sh_intc.h
@@ -79,7 +79,7 @@ struct intc_hw_desc {
79 unsigned int nr_subgroups; 79 unsigned int nr_subgroups;
80}; 80};
81 81
82#define _INTC_ARRAY(a) a, a == NULL ? 0 : sizeof(a)/sizeof(*a) 82#define _INTC_ARRAY(a) a, __same_type(a, NULL) ? 0 : sizeof(a)/sizeof(*a)
83 83
84#define INTC_HW_DESC(vectors, groups, mask_regs, \ 84#define INTC_HW_DESC(vectors, groups, mask_regs, \
85 prio_regs, sense_regs, ack_regs) \ 85 prio_regs, sense_regs, ack_regs) \
diff --git a/include/linux/sh_timer.h b/include/linux/sh_timer.h
index 864bd56bd3b0..4d9dcd138315 100644
--- a/include/linux/sh_timer.h
+++ b/include/linux/sh_timer.h
@@ -5,7 +5,6 @@ struct sh_timer_config {
5 char *name; 5 char *name;
6 long channel_offset; 6 long channel_offset;
7 int timer_bit; 7 int timer_bit;
8 char *clk;
9 unsigned long clockevent_rating; 8 unsigned long clockevent_rating;
10 unsigned long clocksource_rating; 9 unsigned long clocksource_rating;
11}; 10};
diff --git a/include/linux/smp_lock.h b/include/linux/smp_lock.h
index 291f721144c2..3a1988202731 100644
--- a/include/linux/smp_lock.h
+++ b/include/linux/smp_lock.h
@@ -4,8 +4,6 @@
4#ifdef CONFIG_LOCK_KERNEL 4#ifdef CONFIG_LOCK_KERNEL
5#include <linux/sched.h> 5#include <linux/sched.h>
6 6
7#define kernel_locked() (current->lock_depth >= 0)
8
9extern int __lockfunc __reacquire_kernel_lock(void); 7extern int __lockfunc __reacquire_kernel_lock(void);
10extern void __lockfunc __release_kernel_lock(void); 8extern void __lockfunc __release_kernel_lock(void);
11 9
@@ -58,7 +56,6 @@ static inline void cycle_kernel_lock(void)
58#define lock_kernel() 56#define lock_kernel()
59#define unlock_kernel() 57#define unlock_kernel()
60#define cycle_kernel_lock() do { } while(0) 58#define cycle_kernel_lock() do { } while(0)
61#define kernel_locked() 1
62#endif /* CONFIG_BKL */ 59#endif /* CONFIG_BKL */
63 60
64#define release_kernel_lock(task) do { } while(0) 61#define release_kernel_lock(task) do { } while(0)
diff --git a/include/linux/snmp.h b/include/linux/snmp.h
index ebb0c80ffd6e..12b2b18e50c1 100644
--- a/include/linux/snmp.h
+++ b/include/linux/snmp.h
@@ -230,6 +230,7 @@ enum
230 LINUX_MIB_TCPMINTTLDROP, /* RFC 5082 */ 230 LINUX_MIB_TCPMINTTLDROP, /* RFC 5082 */
231 LINUX_MIB_TCPDEFERACCEPTDROP, 231 LINUX_MIB_TCPDEFERACCEPTDROP,
232 LINUX_MIB_IPRPFILTER, /* IP Reverse Path Filter (rp_filter) */ 232 LINUX_MIB_IPRPFILTER, /* IP Reverse Path Filter (rp_filter) */
233 LINUX_MIB_TCPTIMEWAITOVERFLOW, /* TCPTimeWaitOverflow */
233 __LINUX_MIB_MAX 234 __LINUX_MIB_MAX
234}; 235};
235 236
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 92e52a1e6af3..b4d7710bc38d 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -204,6 +204,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
204/** 204/**
205 * struct spi_master - interface to SPI master controller 205 * struct spi_master - interface to SPI master controller
206 * @dev: device interface to this driver 206 * @dev: device interface to this driver
207 * @list: link with the global spi_master list
207 * @bus_num: board-specific (and often SOC-specific) identifier for a 208 * @bus_num: board-specific (and often SOC-specific) identifier for a
208 * given SPI controller. 209 * given SPI controller.
209 * @num_chipselect: chipselects are used to distinguish individual 210 * @num_chipselect: chipselects are used to distinguish individual
@@ -238,6 +239,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
238struct spi_master { 239struct spi_master {
239 struct device dev; 240 struct device dev;
240 241
242 struct list_head list;
243
241 /* other than negative (== assign one dynamically), bus_num is fully 244 /* other than negative (== assign one dynamically), bus_num is fully
242 * board-specific. usually that simplifies to being SOC-specific. 245 * board-specific. usually that simplifies to being SOC-specific.
243 * example: one SOC has three SPI controllers, numbered 0..2, 246 * example: one SOC has three SPI controllers, numbered 0..2,
diff --git a/include/linux/ssb/ssb_driver_gige.h b/include/linux/ssb/ssb_driver_gige.h
index 942e38736901..eba52a100533 100644
--- a/include/linux/ssb/ssb_driver_gige.h
+++ b/include/linux/ssb/ssb_driver_gige.h
@@ -96,16 +96,21 @@ static inline bool ssb_gige_must_flush_posted_writes(struct pci_dev *pdev)
96 return 0; 96 return 0;
97} 97}
98 98
99extern char * nvram_get(const char *name); 99#ifdef CONFIG_BCM47XX
100#include <asm/mach-bcm47xx/nvram.h>
100/* Get the device MAC address */ 101/* Get the device MAC address */
101static inline void ssb_gige_get_macaddr(struct pci_dev *pdev, u8 *macaddr) 102static inline void ssb_gige_get_macaddr(struct pci_dev *pdev, u8 *macaddr)
102{ 103{
103#ifdef CONFIG_BCM47XX 104 char buf[20];
104 char *res = nvram_get("et0macaddr"); 105 if (nvram_getenv("et0macaddr", buf, sizeof(buf)) < 0)
105 if (res) 106 return;
106 memcpy(macaddr, res, 6); 107 nvram_parse_macaddr(buf, macaddr);
107#endif
108} 108}
109#else
110static inline void ssb_gige_get_macaddr(struct pci_dev *pdev, u8 *macaddr)
111{
112}
113#endif
109 114
110extern int ssb_gige_pcibios_plat_dev_init(struct ssb_device *sdev, 115extern int ssb_gige_pcibios_plat_dev_init(struct ssb_device *sdev,
111 struct pci_dev *pdev); 116 struct pci_dev *pdev);
diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h
index bbdb680ffbe9..aea0d438e3c7 100644
--- a/include/linux/sunrpc/svc_xprt.h
+++ b/include/linux/sunrpc/svc_xprt.h
@@ -82,18 +82,28 @@ struct svc_xprt {
82 struct net *xpt_net; 82 struct net *xpt_net;
83}; 83};
84 84
85static inline void register_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u) 85static inline void unregister_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u)
86{ 86{
87 spin_lock(&xpt->xpt_lock); 87 spin_lock(&xpt->xpt_lock);
88 list_add(&u->list, &xpt->xpt_users); 88 list_del_init(&u->list);
89 spin_unlock(&xpt->xpt_lock); 89 spin_unlock(&xpt->xpt_lock);
90} 90}
91 91
92static inline void unregister_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u) 92static inline int register_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u)
93{ 93{
94 spin_lock(&xpt->xpt_lock); 94 spin_lock(&xpt->xpt_lock);
95 list_del_init(&u->list); 95 if (test_bit(XPT_CLOSE, &xpt->xpt_flags)) {
96 /*
97 * The connection is about to be deleted soon (or,
98 * worse, may already be deleted--in which case we've
99 * already notified the xpt_users).
100 */
101 spin_unlock(&xpt->xpt_lock);
102 return -ENOTCONN;
103 }
104 list_add(&u->list, &xpt->xpt_users);
96 spin_unlock(&xpt->xpt_lock); 105 spin_unlock(&xpt->xpt_lock);
106 return 0;
97} 107}
98 108
99int svc_reg_xprt_class(struct svc_xprt_class *); 109int svc_reg_xprt_class(struct svc_xprt_class *);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 2a754748dd5f..54e4eaaa0561 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -13,7 +13,6 @@
13#include <linux/tty_driver.h> 13#include <linux/tty_driver.h>
14#include <linux/tty_ldisc.h> 14#include <linux/tty_ldisc.h>
15#include <linux/mutex.h> 15#include <linux/mutex.h>
16#include <linux/smp_lock.h>
17 16
18#include <asm/system.h> 17#include <asm/system.h>
19 18
@@ -50,7 +49,7 @@
50#define N_V253 19 /* Codec control over voice modem */ 49#define N_V253 19 /* Codec control over voice modem */
51#define N_CAIF 20 /* CAIF protocol for talking to modems */ 50#define N_CAIF 20 /* CAIF protocol for talking to modems */
52#define N_GSM0710 21 /* GSM 0710 Mux */ 51#define N_GSM0710 21 /* GSM 0710 Mux */
53#define N_TI_WL 22 /* for TI's WL BT, FM, GPS combo chips */ 52#define N_TI_WL 22 /* for TI's WL BT, FM, GPS combo chips */
54 53
55/* 54/*
56 * This character is the same as _POSIX_VDISABLE: it cannot be used as 55 * This character is the same as _POSIX_VDISABLE: it cannot be used as
@@ -367,6 +366,7 @@ struct tty_file_private {
367#define TTY_HUPPED 18 /* Post driver->hangup() */ 366#define TTY_HUPPED 18 /* Post driver->hangup() */
368#define TTY_FLUSHING 19 /* Flushing to ldisc in progress */ 367#define TTY_FLUSHING 19 /* Flushing to ldisc in progress */
369#define TTY_FLUSHPENDING 20 /* Queued buffer flush pending */ 368#define TTY_FLUSHPENDING 20 /* Queued buffer flush pending */
369#define TTY_HUPPING 21 /* ->hangup() in progress */
370 370
371#define TTY_WRITE_FLUSH(tty) tty_write_flush((tty)) 371#define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
372 372
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index d6188e5a52df..665517c05eaf 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de> 4 * Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de>
5 * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de> 5 * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
6 * Copyright(C) 2006, Hans J. Koch <hjk@linutronix.de> 6 * Copyright(C) 2006, Hans J. Koch <hjk@hansjkoch.de>
7 * Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com> 7 * Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com>
8 * 8 *
9 * Userspace IO driver. 9 * Userspace IO driver.
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 35fe6ab222bb..a28eb2592577 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -313,6 +313,10 @@ struct usb_bus {
313 int busnum; /* Bus number (in order of reg) */ 313 int busnum; /* Bus number (in order of reg) */
314 const char *bus_name; /* stable id (PCI slot_name etc) */ 314 const char *bus_name; /* stable id (PCI slot_name etc) */
315 u8 uses_dma; /* Does the host controller use DMA? */ 315 u8 uses_dma; /* Does the host controller use DMA? */
316 u8 uses_pio_for_control; /*
317 * Does the host controller use PIO
318 * for control transfers?
319 */
316 u8 otg_port; /* 0, or number of OTG/HNP port */ 320 u8 otg_port; /* 0, or number of OTG/HNP port */
317 unsigned is_b_host:1; /* true during some HNP roleswitches */ 321 unsigned is_b_host:1; /* true during some HNP roleswitches */
318 unsigned b_hnp_enable:1; /* OTG: did A-Host enable HNP? */ 322 unsigned b_hnp_enable:1; /* OTG: did A-Host enable HNP? */
@@ -797,7 +801,7 @@ struct usbdrv_wrap {
797 * @disconnect: Called when the interface is no longer accessible, usually 801 * @disconnect: Called when the interface is no longer accessible, usually
798 * because its device has been (or is being) disconnected or the 802 * because its device has been (or is being) disconnected or the
799 * driver module is being unloaded. 803 * driver module is being unloaded.
800 * @ioctl: Used for drivers that want to talk to userspace through 804 * @unlocked_ioctl: Used for drivers that want to talk to userspace through
801 * the "usbfs" filesystem. This lets devices provide ways to 805 * the "usbfs" filesystem. This lets devices provide ways to
802 * expose information to user space regardless of where they 806 * expose information to user space regardless of where they
803 * do (or don't) show up otherwise in the filesystem. 807 * do (or don't) show up otherwise in the filesystem.
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h
index ee2dd1d506ed..2387f9fc8138 100644
--- a/include/linux/usb/musb.h
+++ b/include/linux/usb/musb.h
@@ -89,6 +89,8 @@ struct musb_hdrc_config {
89 /* A GPIO controlling VRSEL in Blackfin */ 89 /* A GPIO controlling VRSEL in Blackfin */
90 unsigned int gpio_vrsel; 90 unsigned int gpio_vrsel;
91 unsigned int gpio_vrsel_active; 91 unsigned int gpio_vrsel_active;
92 /* musb CLKIN in Blackfin in MHZ */
93 unsigned char clkin;
92#endif 94#endif
93 95
94}; 96};
diff --git a/include/linux/video_output.h b/include/linux/video_output.h
index 2fb46bc9340d..ed5cdeb3604d 100644
--- a/include/linux/video_output.h
+++ b/include/linux/video_output.h
@@ -23,6 +23,7 @@
23#ifndef _LINUX_VIDEO_OUTPUT_H 23#ifndef _LINUX_VIDEO_OUTPUT_H
24#define _LINUX_VIDEO_OUTPUT_H 24#define _LINUX_VIDEO_OUTPUT_H
25#include <linux/device.h> 25#include <linux/device.h>
26#include <linux/err.h>
26struct output_device; 27struct output_device;
27struct output_properties { 28struct output_properties {
28 int (*set_state)(struct output_device *); 29 int (*set_state)(struct output_device *);
@@ -34,9 +35,23 @@ struct output_device {
34 struct device dev; 35 struct device dev;
35}; 36};
36#define to_output_device(obj) container_of(obj, struct output_device, dev) 37#define to_output_device(obj) container_of(obj, struct output_device, dev)
38#if defined(CONFIG_VIDEO_OUTPUT_CONTROL) || defined(CONFIG_VIDEO_OUTPUT_CONTROL_MODULE)
37struct output_device *video_output_register(const char *name, 39struct output_device *video_output_register(const char *name,
38 struct device *dev, 40 struct device *dev,
39 void *devdata, 41 void *devdata,
40 struct output_properties *op); 42 struct output_properties *op);
41void video_output_unregister(struct output_device *dev); 43void video_output_unregister(struct output_device *dev);
44#else
45static struct output_device *video_output_register(const char *name,
46 struct device *dev,
47 void *devdata,
48 struct output_properties *op)
49{
50 return ERR_PTR(-ENODEV);
51}
52static void video_output_unregister(struct output_device *dev)
53{
54 return;
55}
56#endif
42#endif 57#endif
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index a03dcf62ca9d..44b54f619ac6 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -7,8 +7,6 @@
7 7
8struct vm_area_struct; /* vma defining user mapping in mm_types.h */ 8struct vm_area_struct; /* vma defining user mapping in mm_types.h */
9 9
10extern bool vmap_lazy_unmap;
11
12/* bits in flags of vmalloc's vm_struct below */ 10/* bits in flags of vmalloc's vm_struct below */
13#define VM_IOREMAP 0x00000001 /* ioremap() and friends */ 11#define VM_IOREMAP 0x00000001 /* ioremap() and friends */
14#define VM_ALLOC 0x00000002 /* vmalloc() */ 12#define VM_ALLOC 0x00000002 /* vmalloc() */
diff --git a/include/media/saa7146.h b/include/media/saa7146.h
index 7a9f76ecbbbd..ac7ce00f39cf 100644
--- a/include/media/saa7146.h
+++ b/include/media/saa7146.h
@@ -161,7 +161,7 @@ extern struct list_head saa7146_devices;
161extern struct mutex saa7146_devices_lock; 161extern struct mutex saa7146_devices_lock;
162int saa7146_register_extension(struct saa7146_extension*); 162int saa7146_register_extension(struct saa7146_extension*);
163int saa7146_unregister_extension(struct saa7146_extension*); 163int saa7146_unregister_extension(struct saa7146_extension*);
164struct saa7146_format* format_by_fourcc(struct saa7146_dev *dev, int fourcc); 164struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc);
165int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt); 165int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt);
166void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt); 166void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt);
167int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt, struct scatterlist *list, int length ); 167int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt, struct scatterlist *list, int length );
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 41dd480e45f1..239125af3ea3 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -137,31 +137,27 @@ struct v4l2_subdev_ops;
137 137
138 138
139/* Load an i2c module and return an initialized v4l2_subdev struct. 139/* Load an i2c module and return an initialized v4l2_subdev struct.
140 Only call request_module if module_name != NULL.
141 The client_type argument is the name of the chip that's on the adapter. */ 140 The client_type argument is the name of the chip that's on the adapter. */
142struct v4l2_subdev *v4l2_i2c_new_subdev_cfg(struct v4l2_device *v4l2_dev, 141struct v4l2_subdev *v4l2_i2c_new_subdev_cfg(struct v4l2_device *v4l2_dev,
143 struct i2c_adapter *adapter, 142 struct i2c_adapter *adapter, const char *client_type,
144 const char *module_name, const char *client_type,
145 int irq, void *platform_data, 143 int irq, void *platform_data,
146 u8 addr, const unsigned short *probe_addrs); 144 u8 addr, const unsigned short *probe_addrs);
147 145
148/* Load an i2c module and return an initialized v4l2_subdev struct. 146/* Load an i2c module and return an initialized v4l2_subdev struct.
149 Only call request_module if module_name != NULL.
150 The client_type argument is the name of the chip that's on the adapter. */ 147 The client_type argument is the name of the chip that's on the adapter. */
151static inline struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev, 148static inline struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
152 struct i2c_adapter *adapter, 149 struct i2c_adapter *adapter, const char *client_type,
153 const char *module_name, const char *client_type,
154 u8 addr, const unsigned short *probe_addrs) 150 u8 addr, const unsigned short *probe_addrs)
155{ 151{
156 return v4l2_i2c_new_subdev_cfg(v4l2_dev, adapter, module_name, 152 return v4l2_i2c_new_subdev_cfg(v4l2_dev, adapter, client_type, 0, NULL,
157 client_type, 0, NULL, addr, probe_addrs); 153 addr, probe_addrs);
158} 154}
159 155
160struct i2c_board_info; 156struct i2c_board_info;
161 157
162struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, 158struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
163 struct i2c_adapter *adapter, const char *module_name, 159 struct i2c_adapter *adapter, struct i2c_board_info *info,
164 struct i2c_board_info *info, const unsigned short *probe_addrs); 160 const unsigned short *probe_addrs);
165 161
166/* Initialize an v4l2_subdev with data from an i2c_client struct */ 162/* Initialize an v4l2_subdev with data from an i2c_client struct */
167void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, 163void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index 6648036b728d..b16f307d471a 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -51,6 +51,8 @@ struct v4l2_device {
51 unsigned int notification, void *arg); 51 unsigned int notification, void *arg);
52 /* The control handler. May be NULL. */ 52 /* The control handler. May be NULL. */
53 struct v4l2_ctrl_handler *ctrl_handler; 53 struct v4l2_ctrl_handler *ctrl_handler;
54 /* BKL replacement mutex. Temporary solution only. */
55 struct mutex ioctl_lock;
54}; 56};
55 57
56/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev. 58/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
diff --git a/include/net/af_unix.h b/include/net/af_unix.h
index 90c9e2872f27..18e5c3f67580 100644
--- a/include/net/af_unix.h
+++ b/include/net/af_unix.h
@@ -10,6 +10,7 @@ extern void unix_inflight(struct file *fp);
10extern void unix_notinflight(struct file *fp); 10extern void unix_notinflight(struct file *fp);
11extern void unix_gc(void); 11extern void unix_gc(void);
12extern void wait_for_unix_gc(void); 12extern void wait_for_unix_gc(void);
13extern struct sock *unix_get_socket(struct file *filp);
13 14
14#define UNIX_HASH_SIZE 256 15#define UNIX_HASH_SIZE 256
15 16
@@ -56,6 +57,7 @@ struct unix_sock {
56 spinlock_t lock; 57 spinlock_t lock;
57 unsigned int gc_candidate : 1; 58 unsigned int gc_candidate : 1;
58 unsigned int gc_maybe_cycle : 1; 59 unsigned int gc_maybe_cycle : 1;
60 unsigned char recursion_level;
59 struct socket_wq peer_wq; 61 struct socket_wq peer_wq;
60}; 62};
61#define unix_sk(__sk) ((struct unix_sock *)__sk) 63#define unix_sk(__sk) ((struct unix_sock *)__sk)
diff --git a/include/net/caif/caif_dev.h b/include/net/caif/caif_dev.h
index 6da573c75d54..8eff83b95366 100644
--- a/include/net/caif/caif_dev.h
+++ b/include/net/caif/caif_dev.h
@@ -28,7 +28,7 @@ struct caif_param {
28 * @sockaddr: Socket address to connect. 28 * @sockaddr: Socket address to connect.
29 * @priority: Priority of the connection. 29 * @priority: Priority of the connection.
30 * @link_selector: Link selector (high bandwidth or low latency) 30 * @link_selector: Link selector (high bandwidth or low latency)
31 * @link_name: Name of the CAIF Link Layer to use. 31 * @ifindex: kernel index of the interface.
32 * @param: Connect Request parameters (CAIF_SO_REQ_PARAM). 32 * @param: Connect Request parameters (CAIF_SO_REQ_PARAM).
33 * 33 *
34 * This struct is used when connecting a CAIF channel. 34 * This struct is used when connecting a CAIF channel.
@@ -39,7 +39,7 @@ struct caif_connect_request {
39 struct sockaddr_caif sockaddr; 39 struct sockaddr_caif sockaddr;
40 enum caif_channel_priority priority; 40 enum caif_channel_priority priority;
41 enum caif_link_selector link_selector; 41 enum caif_link_selector link_selector;
42 char link_name[16]; 42 int ifindex;
43 struct caif_param param; 43 struct caif_param param;
44}; 44};
45 45
diff --git a/include/net/caif/caif_spi.h b/include/net/caif/caif_spi.h
index ce4570dff020..87c3d11b8e55 100644
--- a/include/net/caif/caif_spi.h
+++ b/include/net/caif/caif_spi.h
@@ -121,6 +121,8 @@ struct cfspi {
121 wait_queue_head_t wait; 121 wait_queue_head_t wait;
122 spinlock_t lock; 122 spinlock_t lock;
123 bool flow_stop; 123 bool flow_stop;
124 bool slave;
125 bool slave_talked;
124#ifdef CONFIG_DEBUG_FS 126#ifdef CONFIG_DEBUG_FS
125 enum cfspi_state dbg_state; 127 enum cfspi_state dbg_state;
126 u16 pcmd; 128 u16 pcmd;
diff --git a/include/net/caif/cfcnfg.h b/include/net/caif/cfcnfg.h
index bd646faffa47..f688478bfb84 100644
--- a/include/net/caif/cfcnfg.h
+++ b/include/net/caif/cfcnfg.h
@@ -139,10 +139,10 @@ struct dev_info *cfcnfg_get_phyid(struct cfcnfg *cnfg,
139 enum cfcnfg_phy_preference phy_pref); 139 enum cfcnfg_phy_preference phy_pref);
140 140
141/** 141/**
142 * cfcnfg_get_named() - Get the Physical Identifier of CAIF Link Layer 142 * cfcnfg_get_id_from_ifi() - Get the Physical Identifier of ifindex,
143 * it matches caif physical id with the kernel interface id.
143 * @cnfg: Configuration object 144 * @cnfg: Configuration object
144 * @name: Name of the Physical Layer (Caif Link Layer) 145 * @ifi: ifindex obtained from socket.c bindtodevice.
145 */ 146 */
146int cfcnfg_get_named(struct cfcnfg *cnfg, char *name); 147int cfcnfg_get_id_from_ifi(struct cfcnfg *cnfg, int ifi);
147
148#endif /* CFCNFG_H_ */ 148#endif /* CFCNFG_H_ */
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 2a7936d7851d..97b8b7c9b63c 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1355,7 +1355,7 @@ enum wiphy_flags {
1355 WIPHY_FLAG_4ADDR_AP = BIT(5), 1355 WIPHY_FLAG_4ADDR_AP = BIT(5),
1356 WIPHY_FLAG_4ADDR_STATION = BIT(6), 1356 WIPHY_FLAG_4ADDR_STATION = BIT(6),
1357 WIPHY_FLAG_CONTROL_PORT_PROTOCOL = BIT(7), 1357 WIPHY_FLAG_CONTROL_PORT_PROTOCOL = BIT(7),
1358 WIPHY_FLAG_IBSS_RSN = BIT(7), 1358 WIPHY_FLAG_IBSS_RSN = BIT(8),
1359}; 1359};
1360 1360
1361struct mac_address { 1361struct mac_address {
diff --git a/include/net/dn.h b/include/net/dn.h
index e5469f7b67a3..a514a3cf4573 100644
--- a/include/net/dn.h
+++ b/include/net/dn.h
@@ -225,7 +225,7 @@ extern int decnet_di_count;
225extern int decnet_dr_count; 225extern int decnet_dr_count;
226extern int decnet_no_fc_max_cwnd; 226extern int decnet_no_fc_max_cwnd;
227 227
228extern int sysctl_decnet_mem[3]; 228extern long sysctl_decnet_mem[3];
229extern int sysctl_decnet_wmem[3]; 229extern int sysctl_decnet_wmem[3];
230extern int sysctl_decnet_rmem[3]; 230extern int sysctl_decnet_rmem[3];
231 231
diff --git a/include/net/dst_ops.h b/include/net/dst_ops.h
index 1fa5306e3e23..51665b3461b8 100644
--- a/include/net/dst_ops.h
+++ b/include/net/dst_ops.h
@@ -2,6 +2,7 @@
2#define _NET_DST_OPS_H 2#define _NET_DST_OPS_H
3#include <linux/types.h> 3#include <linux/types.h>
4#include <linux/percpu_counter.h> 4#include <linux/percpu_counter.h>
5#include <linux/cache.h>
5 6
6struct dst_entry; 7struct dst_entry;
7struct kmem_cachep; 8struct kmem_cachep;
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index 55590ab16b3e..6beb1ffc2b7f 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -303,7 +303,7 @@ static inline void neigh_confirm(struct neighbour *neigh)
303 303
304static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb) 304static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
305{ 305{
306 unsigned long now = ACCESS_ONCE(jiffies); 306 unsigned long now = jiffies;
307 307
308 if (neigh->used != now) 308 if (neigh->used != now)
309 neigh->used = now; 309 neigh->used = now;
diff --git a/include/net/netlink.h b/include/net/netlink.h
index f3b201d335b3..9801c55de5d6 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -384,7 +384,7 @@ static inline int nlmsg_parse(const struct nlmsghdr *nlh, int hdrlen,
384 * 384 *
385 * Returns the first attribute which matches the specified type. 385 * Returns the first attribute which matches the specified type.
386 */ 386 */
387static inline struct nlattr *nlmsg_find_attr(struct nlmsghdr *nlh, 387static inline struct nlattr *nlmsg_find_attr(const struct nlmsghdr *nlh,
388 int hdrlen, int attrtype) 388 int hdrlen, int attrtype)
389{ 389{
390 return nla_find(nlmsg_attrdata(nlh, hdrlen), 390 return nla_find(nlmsg_attrdata(nlh, hdrlen),
diff --git a/include/net/sock.h b/include/net/sock.h
index c7a736228ca2..659d968d95c5 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -762,7 +762,7 @@ struct proto {
762 762
763 /* Memory pressure */ 763 /* Memory pressure */
764 void (*enter_memory_pressure)(struct sock *sk); 764 void (*enter_memory_pressure)(struct sock *sk);
765 atomic_t *memory_allocated; /* Current allocated memory. */ 765 atomic_long_t *memory_allocated; /* Current allocated memory. */
766 struct percpu_counter *sockets_allocated; /* Current number of sockets. */ 766 struct percpu_counter *sockets_allocated; /* Current number of sockets. */
767 /* 767 /*
768 * Pressure flag: try to collapse. 768 * Pressure flag: try to collapse.
@@ -771,7 +771,7 @@ struct proto {
771 * is strict, actions are advisory and have some latency. 771 * is strict, actions are advisory and have some latency.
772 */ 772 */
773 int *memory_pressure; 773 int *memory_pressure;
774 int *sysctl_mem; 774 long *sysctl_mem;
775 int *sysctl_wmem; 775 int *sysctl_wmem;
776 int *sysctl_rmem; 776 int *sysctl_rmem;
777 int max_header; 777 int max_header;
@@ -1155,6 +1155,8 @@ extern void sk_common_release(struct sock *sk);
1155/* Initialise core socket variables */ 1155/* Initialise core socket variables */
1156extern void sock_init_data(struct socket *sock, struct sock *sk); 1156extern void sock_init_data(struct socket *sock, struct sock *sk);
1157 1157
1158extern void sk_filter_release_rcu(struct rcu_head *rcu);
1159
1158/** 1160/**
1159 * sk_filter_release - release a socket filter 1161 * sk_filter_release - release a socket filter
1160 * @fp: filter to remove 1162 * @fp: filter to remove
@@ -1165,7 +1167,7 @@ extern void sock_init_data(struct socket *sock, struct sock *sk);
1165static inline void sk_filter_release(struct sk_filter *fp) 1167static inline void sk_filter_release(struct sk_filter *fp)
1166{ 1168{
1167 if (atomic_dec_and_test(&fp->refcnt)) 1169 if (atomic_dec_and_test(&fp->refcnt))
1168 kfree(fp); 1170 call_rcu_bh(&fp->rcu, sk_filter_release_rcu);
1169} 1171}
1170 1172
1171static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp) 1173static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 4fee0424af7e..e36c874c7fb1 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -224,7 +224,7 @@ extern int sysctl_tcp_fack;
224extern int sysctl_tcp_reordering; 224extern int sysctl_tcp_reordering;
225extern int sysctl_tcp_ecn; 225extern int sysctl_tcp_ecn;
226extern int sysctl_tcp_dsack; 226extern int sysctl_tcp_dsack;
227extern int sysctl_tcp_mem[3]; 227extern long sysctl_tcp_mem[3];
228extern int sysctl_tcp_wmem[3]; 228extern int sysctl_tcp_wmem[3];
229extern int sysctl_tcp_rmem[3]; 229extern int sysctl_tcp_rmem[3];
230extern int sysctl_tcp_app_win; 230extern int sysctl_tcp_app_win;
@@ -247,7 +247,7 @@ extern int sysctl_tcp_cookie_size;
247extern int sysctl_tcp_thin_linear_timeouts; 247extern int sysctl_tcp_thin_linear_timeouts;
248extern int sysctl_tcp_thin_dupack; 248extern int sysctl_tcp_thin_dupack;
249 249
250extern atomic_t tcp_memory_allocated; 250extern atomic_long_t tcp_memory_allocated;
251extern struct percpu_counter tcp_sockets_allocated; 251extern struct percpu_counter tcp_sockets_allocated;
252extern int tcp_memory_pressure; 252extern int tcp_memory_pressure;
253 253
@@ -280,7 +280,7 @@ static inline bool tcp_too_many_orphans(struct sock *sk, int shift)
280 } 280 }
281 281
282 if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && 282 if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF &&
283 atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2]) 283 atomic_long_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])
284 return true; 284 return true;
285 return false; 285 return false;
286} 286}
diff --git a/include/net/udp.h b/include/net/udp.h
index 200b82848c9a..bb967dd59bf7 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -105,10 +105,10 @@ static inline struct udp_hslot *udp_hashslot2(struct udp_table *table,
105 105
106extern struct proto udp_prot; 106extern struct proto udp_prot;
107 107
108extern atomic_t udp_memory_allocated; 108extern atomic_long_t udp_memory_allocated;
109 109
110/* sysctl variables for udp */ 110/* sysctl variables for udp */
111extern int sysctl_udp_mem[3]; 111extern long sysctl_udp_mem[3];
112extern int sysctl_udp_rmem_min; 112extern int sysctl_udp_rmem_min;
113extern int sysctl_udp_wmem_min; 113extern int sysctl_udp_wmem_min;
114 114
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
index 14be49b44e84..5c4c1678f7be 100644
--- a/include/scsi/libfc.h
+++ b/include/scsi/libfc.h
@@ -721,7 +721,7 @@ struct libfc_function_template {
721 * struct fc_disc - Discovery context 721 * struct fc_disc - Discovery context
722 * @retry_count: Number of retries 722 * @retry_count: Number of retries
723 * @pending: 1 if discovery is pending, 0 if not 723 * @pending: 1 if discovery is pending, 0 if not
724 * @requesting: 1 if discovery has been requested, 0 if not 724 * @requested: 1 if discovery has been requested, 0 if not
725 * @seq_count: Number of sequences used for discovery 725 * @seq_count: Number of sequences used for discovery
726 * @buf_len: Length of the discovery buffer 726 * @buf_len: Length of the discovery buffer
727 * @disc_id: Discovery ID 727 * @disc_id: Discovery ID
@@ -1006,8 +1006,7 @@ void fc_fcp_destroy(struct fc_lport *);
1006/* 1006/*
1007 * SCSI INTERACTION LAYER 1007 * SCSI INTERACTION LAYER
1008 *****************************/ 1008 *****************************/
1009int fc_queuecommand(struct scsi_cmnd *, 1009int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
1010 void (*done)(struct scsi_cmnd *));
1011int fc_eh_abort(struct scsi_cmnd *); 1010int fc_eh_abort(struct scsi_cmnd *);
1012int fc_eh_device_reset(struct scsi_cmnd *); 1011int fc_eh_device_reset(struct scsi_cmnd *);
1013int fc_eh_host_reset(struct scsi_cmnd *); 1012int fc_eh_host_reset(struct scsi_cmnd *);
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index ae5196aae1a5..b81d969ddc67 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -341,8 +341,7 @@ extern int iscsi_eh_abort(struct scsi_cmnd *sc);
341extern int iscsi_eh_recover_target(struct scsi_cmnd *sc); 341extern int iscsi_eh_recover_target(struct scsi_cmnd *sc);
342extern int iscsi_eh_session_reset(struct scsi_cmnd *sc); 342extern int iscsi_eh_session_reset(struct scsi_cmnd *sc);
343extern int iscsi_eh_device_reset(struct scsi_cmnd *sc); 343extern int iscsi_eh_device_reset(struct scsi_cmnd *sc);
344extern int iscsi_queuecommand(struct scsi_cmnd *sc, 344extern int iscsi_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *sc);
345 void (*done)(struct scsi_cmnd *));
346 345
347/* 346/*
348 * iSCSI host helpers. 347 * iSCSI host helpers.
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index 3dec1949f69c..90ce527ecf3d 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -621,8 +621,7 @@ int sas_set_phy_speed(struct sas_phy *phy,
621int sas_phy_enable(struct sas_phy *phy, int enabled); 621int sas_phy_enable(struct sas_phy *phy, int enabled);
622int sas_phy_reset(struct sas_phy *phy, int hard_reset); 622int sas_phy_reset(struct sas_phy *phy, int hard_reset);
623int sas_queue_up(struct sas_task *task); 623int sas_queue_up(struct sas_task *task);
624extern int sas_queuecommand(struct scsi_cmnd *, 624extern int sas_queuecommand(struct Scsi_Host * ,struct scsi_cmnd *);
625 void (*scsi_done)(struct scsi_cmnd *));
626extern int sas_target_alloc(struct scsi_target *); 625extern int sas_target_alloc(struct scsi_target *);
627extern int sas_slave_alloc(struct scsi_device *); 626extern int sas_slave_alloc(struct scsi_device *);
628extern int sas_slave_configure(struct scsi_device *); 627extern int sas_slave_configure(struct scsi_device *);
diff --git a/include/scsi/osd_initiator.h b/include/scsi/osd_initiator.h
index a8f370126632..53a9e886612b 100644
--- a/include/scsi/osd_initiator.h
+++ b/include/scsi/osd_initiator.h
@@ -137,7 +137,7 @@ struct osd_request {
137 void *buff; 137 void *buff;
138 unsigned alloc_size; /* 0 here means: don't call kfree */ 138 unsigned alloc_size; /* 0 here means: don't call kfree */
139 unsigned total_bytes; 139 unsigned total_bytes;
140 } set_attr, enc_get_attr, get_attr; 140 } cdb_cont, set_attr, enc_get_attr, get_attr;
141 141
142 struct _osd_io_info { 142 struct _osd_io_info {
143 struct bio *bio; 143 struct bio *bio;
@@ -448,6 +448,20 @@ void osd_req_read(struct osd_request *or,
448int osd_req_read_kern(struct osd_request *or, 448int osd_req_read_kern(struct osd_request *or,
449 const struct osd_obj_id *obj, u64 offset, void *buff, u64 len); 449 const struct osd_obj_id *obj, u64 offset, void *buff, u64 len);
450 450
451/* Scatter/Gather write/read commands */
452int osd_req_write_sg(struct osd_request *or,
453 const struct osd_obj_id *obj, struct bio *bio,
454 const struct osd_sg_entry *sglist, unsigned numentries);
455int osd_req_read_sg(struct osd_request *or,
456 const struct osd_obj_id *obj, struct bio *bio,
457 const struct osd_sg_entry *sglist, unsigned numentries);
458int osd_req_write_sg_kern(struct osd_request *or,
459 const struct osd_obj_id *obj, void **buff,
460 const struct osd_sg_entry *sglist, unsigned numentries);
461int osd_req_read_sg_kern(struct osd_request *or,
462 const struct osd_obj_id *obj, void **buff,
463 const struct osd_sg_entry *sglist, unsigned numentries);
464
451/* 465/*
452 * Root/Partition/Collection/Object Attributes commands 466 * Root/Partition/Collection/Object Attributes commands
453 */ 467 */
diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h
index 685661283540..a6026da25f3e 100644
--- a/include/scsi/osd_protocol.h
+++ b/include/scsi/osd_protocol.h
@@ -631,4 +631,46 @@ static inline void osd_sec_set_caps(struct osd_capability_head *cap,
631 put_unaligned_le16(bit_mask, &cap->permissions_bit_mask); 631 put_unaligned_le16(bit_mask, &cap->permissions_bit_mask);
632} 632}
633 633
634/* osd2r05a sec 5.3: CDB continuation segment formats */
635enum osd_continuation_segment_format {
636 CDB_CONTINUATION_FORMAT_V2 = 0x01,
637};
638
639struct osd_continuation_segment_header {
640 u8 format;
641 u8 reserved1;
642 __be16 service_action;
643 __be32 reserved2;
644 u8 integrity_check[OSDv2_CRYPTO_KEYID_SIZE];
645} __packed;
646
647/* osd2r05a sec 5.4.1: CDB continuation descriptors */
648enum osd_continuation_descriptor_type {
649 NO_MORE_DESCRIPTORS = 0x0000,
650 SCATTER_GATHER_LIST = 0x0001,
651 QUERY_LIST = 0x0002,
652 USER_OBJECT = 0x0003,
653 COPY_USER_OBJECT_SOURCE = 0x0101,
654 EXTENSION_CAPABILITIES = 0xFFEE
655};
656
657struct osd_continuation_descriptor_header {
658 __be16 type;
659 u8 reserved;
660 u8 pad_length;
661 __be32 length;
662} __packed;
663
664
665/* osd2r05a sec 5.4.2: Scatter/gather list */
666struct osd_sg_list_entry {
667 __be64 offset;
668 __be64 len;
669};
670
671struct osd_sg_continuation_descriptor {
672 struct osd_continuation_descriptor_header hdr;
673 struct osd_sg_list_entry entries[];
674};
675
634#endif /* ndef __OSD_PROTOCOL_H__ */ 676#endif /* ndef __OSD_PROTOCOL_H__ */
diff --git a/include/scsi/osd_types.h b/include/scsi/osd_types.h
index 3f5e88cc75c0..bd0be7ed4bcf 100644
--- a/include/scsi/osd_types.h
+++ b/include/scsi/osd_types.h
@@ -37,4 +37,9 @@ struct osd_attr {
37 void *val_ptr; /* in network order */ 37 void *val_ptr; /* in network order */
38}; 38};
39 39
40struct osd_sg_entry {
41 u64 offset;
42 u64 len;
43};
44
40#endif /* ndef __OSD_TYPES_H__ */ 45#endif /* ndef __OSD_TYPES_H__ */
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index d0a6a845f204..e7e385842a38 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -127,8 +127,7 @@ struct scsi_host_template {
127 * 127 *
128 * STATUS: REQUIRED 128 * STATUS: REQUIRED
129 */ 129 */
130 int (* queuecommand)(struct scsi_cmnd *, 130 int (* queuecommand)(struct Scsi_Host *, struct scsi_cmnd *);
131 void (*done)(struct scsi_cmnd *));
132 131
133 /* 132 /*
134 * The transfer functions are used to queue a scsi command to 133 * The transfer functions are used to queue a scsi command to
@@ -505,6 +504,25 @@ struct scsi_host_template {
505}; 504};
506 505
507/* 506/*
507 * Temporary #define for host lock push down. Can be removed when all
508 * drivers have been updated to take advantage of unlocked
509 * queuecommand.
510 *
511 */
512#define DEF_SCSI_QCMD(func_name) \
513 int func_name(struct Scsi_Host *shost, struct scsi_cmnd *cmd) \
514 { \
515 unsigned long irq_flags; \
516 int rc; \
517 spin_lock_irqsave(shost->host_lock, irq_flags); \
518 scsi_cmd_get_serial(shost, cmd); \
519 rc = func_name##_lck (cmd, cmd->scsi_done); \
520 spin_unlock_irqrestore(shost->host_lock, irq_flags); \
521 return rc; \
522 }
523
524
525/*
508 * shost state: If you alter this, you also need to alter scsi_sysfs.c 526 * shost state: If you alter this, you also need to alter scsi_sysfs.c
509 * (for the ascii descriptions) and the state model enforcer: 527 * (for the ascii descriptions) and the state model enforcer:
510 * scsi_host_set_state() 528 * scsi_host_set_state()
@@ -752,6 +770,7 @@ extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
752extern void scsi_host_put(struct Scsi_Host *t); 770extern void scsi_host_put(struct Scsi_Host *t);
753extern struct Scsi_Host *scsi_host_lookup(unsigned short); 771extern struct Scsi_Host *scsi_host_lookup(unsigned short);
754extern const char *scsi_host_state_name(enum scsi_host_state); 772extern const char *scsi_host_state_name(enum scsi_host_state);
773extern void scsi_cmd_get_serial(struct Scsi_Host *, struct scsi_cmnd *);
755 774
756extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *); 775extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
757 776
diff --git a/include/sound/sh_fsi.h b/include/sound/sh_fsi.h
index fa60cbda90a4..d79894192ae3 100644
--- a/include/sound/sh_fsi.h
+++ b/include/sound/sh_fsi.h
@@ -85,7 +85,9 @@
85 * ACK_MD (FSI2) 85 * ACK_MD (FSI2)
86 * CKG1 (FSI) 86 * CKG1 (FSI)
87 * 87 *
88 * err: return value < 0 88 * err : return value < 0
89 * no change : return value == 0
90 * change xMD : return value > 0
89 * 91 *
90 * 0x-00000AB 92 * 0x-00000AB
91 * 93 *
@@ -111,7 +113,7 @@
111struct sh_fsi_platform_info { 113struct sh_fsi_platform_info {
112 unsigned long porta_flags; 114 unsigned long porta_flags;
113 unsigned long portb_flags; 115 unsigned long portb_flags;
114 int (*set_rate)(int is_porta, int rate); /* for master mode */ 116 int (*set_rate)(struct device *dev, int is_porta, int rate, int enable);
115}; 117};
116 118
117#endif /* __SOUND_FSI_H */ 119#endif /* __SOUND_FSI_H */
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index 289010d3270b..e5e345fb2a5c 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -98,6 +98,103 @@ TRACE_EVENT(ext4_allocate_inode,
98 (unsigned long) __entry->dir, __entry->mode) 98 (unsigned long) __entry->dir, __entry->mode)
99); 99);
100 100
101TRACE_EVENT(ext4_evict_inode,
102 TP_PROTO(struct inode *inode),
103
104 TP_ARGS(inode),
105
106 TP_STRUCT__entry(
107 __field( int, dev_major )
108 __field( int, dev_minor )
109 __field( ino_t, ino )
110 __field( int, nlink )
111 ),
112
113 TP_fast_assign(
114 __entry->dev_major = MAJOR(inode->i_sb->s_dev);
115 __entry->dev_minor = MINOR(inode->i_sb->s_dev);
116 __entry->ino = inode->i_ino;
117 __entry->nlink = inode->i_nlink;
118 ),
119
120 TP_printk("dev %d,%d ino %lu nlink %d",
121 __entry->dev_major, __entry->dev_minor,
122 (unsigned long) __entry->ino, __entry->nlink)
123);
124
125TRACE_EVENT(ext4_drop_inode,
126 TP_PROTO(struct inode *inode, int drop),
127
128 TP_ARGS(inode, drop),
129
130 TP_STRUCT__entry(
131 __field( int, dev_major )
132 __field( int, dev_minor )
133 __field( ino_t, ino )
134 __field( int, drop )
135 ),
136
137 TP_fast_assign(
138 __entry->dev_major = MAJOR(inode->i_sb->s_dev);
139 __entry->dev_minor = MINOR(inode->i_sb->s_dev);
140 __entry->ino = inode->i_ino;
141 __entry->drop = drop;
142 ),
143
144 TP_printk("dev %d,%d ino %lu drop %d",
145 __entry->dev_major, __entry->dev_minor,
146 (unsigned long) __entry->ino, __entry->drop)
147);
148
149TRACE_EVENT(ext4_mark_inode_dirty,
150 TP_PROTO(struct inode *inode, unsigned long IP),
151
152 TP_ARGS(inode, IP),
153
154 TP_STRUCT__entry(
155 __field( int, dev_major )
156 __field( int, dev_minor )
157 __field( ino_t, ino )
158 __field(unsigned long, ip )
159 ),
160
161 TP_fast_assign(
162 __entry->dev_major = MAJOR(inode->i_sb->s_dev);
163 __entry->dev_minor = MINOR(inode->i_sb->s_dev);
164 __entry->ino = inode->i_ino;
165 __entry->ip = IP;
166 ),
167
168 TP_printk("dev %d,%d ino %lu caller %pF",
169 __entry->dev_major, __entry->dev_minor,
170 (unsigned long) __entry->ino, (void *)__entry->ip)
171);
172
173TRACE_EVENT(ext4_begin_ordered_truncate,
174 TP_PROTO(struct inode *inode, loff_t new_size),
175
176 TP_ARGS(inode, new_size),
177
178 TP_STRUCT__entry(
179 __field( int, dev_major )
180 __field( int, dev_minor )
181 __field( ino_t, ino )
182 __field( loff_t, new_size )
183 ),
184
185 TP_fast_assign(
186 __entry->dev_major = MAJOR(inode->i_sb->s_dev);
187 __entry->dev_minor = MINOR(inode->i_sb->s_dev);
188 __entry->ino = inode->i_ino;
189 __entry->new_size = new_size;
190 ),
191
192 TP_printk("dev %d,%d ino %lu new_size %lld",
193 __entry->dev_major, __entry->dev_minor,
194 (unsigned long) __entry->ino,
195 (long long) __entry->new_size)
196);
197
101DECLARE_EVENT_CLASS(ext4__write_begin, 198DECLARE_EVENT_CLASS(ext4__write_begin,
102 199
103 TP_PROTO(struct inode *inode, loff_t pos, unsigned int len, 200 TP_PROTO(struct inode *inode, loff_t pos, unsigned int len,
diff --git a/include/video/da8xx-fb.h b/include/video/da8xx-fb.h
index 6316cdabf73f..89d43b3d4cb9 100644
--- a/include/video/da8xx-fb.h
+++ b/include/video/da8xx-fb.h
@@ -99,7 +99,6 @@ struct lcd_sync_arg {
99#define FBIPUT_COLOR _IOW('F', 6, int) 99#define FBIPUT_COLOR _IOW('F', 6, int)
100#define FBIPUT_HSYNC _IOW('F', 9, int) 100#define FBIPUT_HSYNC _IOW('F', 9, int)
101#define FBIPUT_VSYNC _IOW('F', 10, int) 101#define FBIPUT_VSYNC _IOW('F', 10, int)
102#define FBIO_WAITFORVSYNC _IOW('F', 0x20, u_int32_t)
103 102
104#endif /* ifndef DA8XX_FB_H */ 103#endif /* ifndef DA8XX_FB_H */
105 104
diff --git a/include/xen/events.h b/include/xen/events.h
index 646dd17d3aa4..00f53ddcc062 100644
--- a/include/xen/events.h
+++ b/include/xen/events.h
@@ -76,7 +76,9 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name);
76 76
77#ifdef CONFIG_PCI_MSI 77#ifdef CONFIG_PCI_MSI
78/* Allocate an irq and a pirq to be used with MSIs. */ 78/* Allocate an irq and a pirq to be used with MSIs. */
79void xen_allocate_pirq_msi(char *name, int *irq, int *pirq); 79#define XEN_ALLOC_PIRQ (1 << 0)
80#define XEN_ALLOC_IRQ (1 << 1)
81void xen_allocate_pirq_msi(char *name, int *irq, int *pirq, int alloc_mask);
80int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type); 82int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type);
81#endif 83#endif
82 84
@@ -89,4 +91,7 @@ int xen_vector_from_irq(unsigned pirq);
89/* Return gsi allocated to pirq */ 91/* Return gsi allocated to pirq */
90int xen_gsi_from_irq(unsigned pirq); 92int xen_gsi_from_irq(unsigned pirq);
91 93
94/* Return irq from pirq */
95int xen_irq_from_pirq(unsigned pirq);
96
92#endif /* _XEN_EVENTS_H */ 97#endif /* _XEN_EVENTS_H */
diff --git a/include/xen/interface/io/ring.h b/include/xen/interface/io/ring.h
index e8cbf431c8cc..75271b9a8f61 100644
--- a/include/xen/interface/io/ring.h
+++ b/include/xen/interface/io/ring.h
@@ -24,8 +24,15 @@ typedef unsigned int RING_IDX;
24 * A ring contains as many entries as will fit, rounded down to the nearest 24 * A ring contains as many entries as will fit, rounded down to the nearest
25 * power of two (so we can mask with (size-1) to loop around). 25 * power of two (so we can mask with (size-1) to loop around).
26 */ 26 */
27#define __RING_SIZE(_s, _sz) \ 27#define __CONST_RING_SIZE(_s, _sz) \
28 (__RD32(((_sz) - (long)&(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0]))) 28 (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
29 sizeof(((struct _s##_sring *)0)->ring[0])))
30
31/*
32 * The same for passing in an actual pointer instead of a name tag.
33 */
34#define __RING_SIZE(_s, _sz) \
35 (__RD32(((_sz) - (long)&(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
29 36
30/* 37/*
31 * Macros to make the correct C datatypes for a new kind of ring. 38 * Macros to make the correct C datatypes for a new kind of ring.
diff --git a/include/xen/interface/memory.h b/include/xen/interface/memory.h
index d7a6c13bde69..eac3ce153719 100644
--- a/include/xen/interface/memory.h
+++ b/include/xen/interface/memory.h
@@ -141,6 +141,19 @@ struct xen_machphys_mfn_list {
141DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list); 141DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list);
142 142
143/* 143/*
144 * Returns the location in virtual address space of the machine_to_phys
145 * mapping table. Architectures which do not have a m2p table, or which do not
146 * map it by default into guest address space, do not implement this command.
147 * arg == addr of xen_machphys_mapping_t.
148 */
149#define XENMEM_machphys_mapping 12
150struct xen_machphys_mapping {
151 unsigned long v_start, v_end; /* Start and end virtual addresses. */
152 unsigned long max_mfn; /* Maximum MFN that can be looked up. */
153};
154DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mapping_t);
155
156/*
144 * Sets the GPFN at which a particular page appears in the specified guest's 157 * Sets the GPFN at which a particular page appears in the specified guest's
145 * pseudophysical address space. 158 * pseudophysical address space.
146 * arg == addr of xen_add_to_physmap_t. 159 * arg == addr of xen_add_to_physmap_t.
diff --git a/include/xen/interface/physdev.h b/include/xen/interface/physdev.h
index 2b2c66c3df00..534cac89a77d 100644
--- a/include/xen/interface/physdev.h
+++ b/include/xen/interface/physdev.h
@@ -188,6 +188,16 @@ struct physdev_nr_pirqs {
188 uint32_t nr_pirqs; 188 uint32_t nr_pirqs;
189}; 189};
190 190
191/* type is MAP_PIRQ_TYPE_GSI or MAP_PIRQ_TYPE_MSI
192 * the hypercall returns a free pirq */
193#define PHYSDEVOP_get_free_pirq 23
194struct physdev_get_free_pirq {
195 /* IN */
196 int type;
197 /* OUT */
198 uint32_t pirq;
199};
200
191/* 201/*
192 * Notify that some PIRQ-bound event channels have been unmasked. 202 * Notify that some PIRQ-bound event channels have been unmasked.
193 * ** This command is obsolete since interface version 0x00030202 and is ** 203 * ** This command is obsolete since interface version 0x00030202 and is **
diff --git a/include/xen/page.h b/include/xen/page.h
index eaf85fab1263..0be36b976f4b 100644
--- a/include/xen/page.h
+++ b/include/xen/page.h
@@ -1 +1,8 @@
1#ifndef _XEN_PAGE_H
2#define _XEN_PAGE_H
3
1#include <asm/xen/page.h> 4#include <asm/xen/page.h>
5
6extern phys_addr_t xen_extra_mem_start, xen_extra_mem_size;
7
8#endif /* _XEN_PAGE_H */
diff --git a/include/xen/privcmd.h b/include/xen/privcmd.h
index b42cdfd92fee..17857fb4d550 100644
--- a/include/xen/privcmd.h
+++ b/include/xen/privcmd.h
@@ -34,13 +34,10 @@
34#define __LINUX_PUBLIC_PRIVCMD_H__ 34#define __LINUX_PUBLIC_PRIVCMD_H__
35 35
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/compiler.h>
37 38
38typedef unsigned long xen_pfn_t; 39typedef unsigned long xen_pfn_t;
39 40
40#ifndef __user
41#define __user
42#endif
43
44struct privcmd_hypercall { 41struct privcmd_hypercall {
45 __u64 op; 42 __u64 op;
46 __u64 arg[5]; 43 __u64 arg[5];
diff --git a/init/Kconfig b/init/Kconfig
index 88c10468db46..c9728992a776 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -613,6 +613,19 @@ config CGROUP_MEM_RES_CTLR_SWAP
613 if boot option "noswapaccount" is set, swap will not be accounted. 613 if boot option "noswapaccount" is set, swap will not be accounted.
614 Now, memory usage of swap_cgroup is 2 bytes per entry. If swap page 614 Now, memory usage of swap_cgroup is 2 bytes per entry. If swap page
615 size is 4096bytes, 512k per 1Gbytes of swap. 615 size is 4096bytes, 512k per 1Gbytes of swap.
616config CGROUP_MEM_RES_CTLR_SWAP_ENABLED
617 bool "Memory Resource Controller Swap Extension enabled by default"
618 depends on CGROUP_MEM_RES_CTLR_SWAP
619 default y
620 help
621 Memory Resource Controller Swap Extension comes with its price in
622 a bigger memory consumption. General purpose distribution kernels
623 which want to enable the feautre but keep it disabled by default
624 and let the user enable it by swapaccount boot command line
625 parameter should have this option unselected.
626 For those who want to have the feature enabled by default should
627 select this option (if, for some reason, they need to disable it
628 then noswapaccount does the trick).
616 629
617menuconfig CGROUP_SCHED 630menuconfig CGROUP_SCHED
618 bool "Group CPU scheduler" 631 bool "Group CPU scheduler"
diff --git a/init/main.c b/init/main.c
index e59af24a0b7c..8646401f7a0e 100644
--- a/init/main.c
+++ b/init/main.c
@@ -20,7 +20,6 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/ioport.h> 21#include <linux/ioport.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/smp_lock.h>
24#include <linux/initrd.h> 23#include <linux/initrd.h>
25#include <linux/bootmem.h> 24#include <linux/bootmem.h>
26#include <linux/acpi.h> 25#include <linux/acpi.h>
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 7242cc71bb7e..bd3e8e29caa3 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -82,7 +82,7 @@ static kdbtab_t kdb_base_commands[50];
82#define for_each_kdbcmd(cmd, num) \ 82#define for_each_kdbcmd(cmd, num) \
83 for ((cmd) = kdb_base_commands, (num) = 0; \ 83 for ((cmd) = kdb_base_commands, (num) = 0; \
84 num < kdb_max_commands; \ 84 num < kdb_max_commands; \
85 num == KDB_BASE_CMD_MAX ? cmd = kdb_commands : cmd++, num++) 85 num++, num == KDB_BASE_CMD_MAX ? cmd = kdb_commands : cmd++)
86 86
87typedef struct _kdbmsg { 87typedef struct _kdbmsg {
88 int km_diag; /* kdb diagnostic */ 88 int km_diag; /* kdb diagnostic */
@@ -646,7 +646,7 @@ static int kdb_defcmd2(const char *cmdstr, const char *argv0)
646 } 646 }
647 if (!s->usable) 647 if (!s->usable)
648 return KDB_NOTIMP; 648 return KDB_NOTIMP;
649 s->command = kmalloc((s->count + 1) * sizeof(*(s->command)), GFP_KDB); 649 s->command = kzalloc((s->count + 1) * sizeof(*(s->command)), GFP_KDB);
650 if (!s->command) { 650 if (!s->command) {
651 kdb_printf("Could not allocate new kdb_defcmd table for %s\n", 651 kdb_printf("Could not allocate new kdb_defcmd table for %s\n",
652 cmdstr); 652 cmdstr);
@@ -2361,7 +2361,7 @@ static int kdb_pid(int argc, const char **argv)
2361 */ 2361 */
2362static int kdb_ll(int argc, const char **argv) 2362static int kdb_ll(int argc, const char **argv)
2363{ 2363{
2364 int diag; 2364 int diag = 0;
2365 unsigned long addr; 2365 unsigned long addr;
2366 long offset = 0; 2366 long offset = 0;
2367 unsigned long va; 2367 unsigned long va;
@@ -2400,20 +2400,21 @@ static int kdb_ll(int argc, const char **argv)
2400 char buf[80]; 2400 char buf[80];
2401 2401
2402 if (KDB_FLAG(CMD_INTERRUPT)) 2402 if (KDB_FLAG(CMD_INTERRUPT))
2403 return 0; 2403 goto out;
2404 2404
2405 sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va); 2405 sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va);
2406 diag = kdb_parse(buf); 2406 diag = kdb_parse(buf);
2407 if (diag) 2407 if (diag)
2408 return diag; 2408 goto out;
2409 2409
2410 addr = va + linkoffset; 2410 addr = va + linkoffset;
2411 if (kdb_getword(&va, addr, sizeof(va))) 2411 if (kdb_getword(&va, addr, sizeof(va)))
2412 return 0; 2412 goto out;
2413 } 2413 }
2414 kfree(command);
2415 2414
2416 return 0; 2415out:
2416 kfree(command);
2417 return diag;
2417} 2418}
2418 2419
2419static int kdb_kgdb(int argc, const char **argv) 2420static int kdb_kgdb(int argc, const char **argv)
@@ -2739,13 +2740,13 @@ int kdb_register_repeat(char *cmd,
2739 } 2740 }
2740 if (kdb_commands) { 2741 if (kdb_commands) {
2741 memcpy(new, kdb_commands, 2742 memcpy(new, kdb_commands,
2742 kdb_max_commands * sizeof(*new)); 2743 (kdb_max_commands - KDB_BASE_CMD_MAX) * sizeof(*new));
2743 kfree(kdb_commands); 2744 kfree(kdb_commands);
2744 } 2745 }
2745 memset(new + kdb_max_commands, 0, 2746 memset(new + kdb_max_commands, 0,
2746 kdb_command_extend * sizeof(*new)); 2747 kdb_command_extend * sizeof(*new));
2747 kdb_commands = new; 2748 kdb_commands = new;
2748 kp = kdb_commands + kdb_max_commands; 2749 kp = kdb_commands + kdb_max_commands - KDB_BASE_CMD_MAX;
2749 kdb_max_commands += kdb_command_extend; 2750 kdb_max_commands += kdb_command_extend;
2750 } 2751 }
2751 2752
diff --git a/kernel/exit.c b/kernel/exit.c
index b194febf5799..676149a4ac5f 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -96,6 +96,14 @@ static void __exit_signal(struct task_struct *tsk)
96 sig->tty = NULL; 96 sig->tty = NULL;
97 } else { 97 } else {
98 /* 98 /*
99 * This can only happen if the caller is de_thread().
100 * FIXME: this is the temporary hack, we should teach
101 * posix-cpu-timers to handle this case correctly.
102 */
103 if (unlikely(has_group_leader_pid(tsk)))
104 posix_cpu_timers_exit_group(tsk);
105
106 /*
99 * If there is any task waiting for the group exit 107 * If there is any task waiting for the group exit
100 * then notify it: 108 * then notify it:
101 */ 109 */
@@ -906,6 +914,15 @@ NORET_TYPE void do_exit(long code)
906 if (unlikely(!tsk->pid)) 914 if (unlikely(!tsk->pid))
907 panic("Attempted to kill the idle task!"); 915 panic("Attempted to kill the idle task!");
908 916
917 /*
918 * If do_exit is called because this processes oopsed, it's possible
919 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
920 * continuing. Amongst other possible reasons, this is to prevent
921 * mm_release()->clear_child_tid() from writing to a user-controlled
922 * kernel address.
923 */
924 set_fs(USER_DS);
925
909 tracehook_report_exit(&code); 926 tracehook_report_exit(&code);
910 927
911 validate_creds_for_do_exit(tsk); 928 validate_creds_for_do_exit(tsk);
diff --git a/kernel/fork.c b/kernel/fork.c
index 3b159c5991b7..5447dc7defa9 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -273,6 +273,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
273 273
274 setup_thread_stack(tsk, orig); 274 setup_thread_stack(tsk, orig);
275 clear_user_return_notifier(tsk); 275 clear_user_return_notifier(tsk);
276 clear_tsk_need_resched(tsk);
276 stackend = end_of_stack(tsk); 277 stackend = end_of_stack(tsk);
277 *stackend = STACK_END_MAGIC; /* for overflow detection */ 278 *stackend = STACK_END_MAGIC; /* for overflow detection */
278 279
diff --git a/kernel/futex.c b/kernel/futex.c
index 6c683b37f2ce..40a8777a27d0 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2489,7 +2489,8 @@ void exit_robust_list(struct task_struct *curr)
2489{ 2489{
2490 struct robust_list_head __user *head = curr->robust_list; 2490 struct robust_list_head __user *head = curr->robust_list;
2491 struct robust_list __user *entry, *next_entry, *pending; 2491 struct robust_list __user *entry, *next_entry, *pending;
2492 unsigned int limit = ROBUST_LIST_LIMIT, pi, next_pi, pip; 2492 unsigned int limit = ROBUST_LIST_LIMIT, pi, pip;
2493 unsigned int uninitialized_var(next_pi);
2493 unsigned long futex_offset; 2494 unsigned long futex_offset;
2494 int rc; 2495 int rc;
2495 2496
diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
index 06da4dfc339b..a7934ac75e5b 100644
--- a/kernel/futex_compat.c
+++ b/kernel/futex_compat.c
@@ -49,7 +49,8 @@ void compat_exit_robust_list(struct task_struct *curr)
49{ 49{
50 struct compat_robust_list_head __user *head = curr->compat_robust_list; 50 struct compat_robust_list_head __user *head = curr->compat_robust_list;
51 struct robust_list __user *entry, *next_entry, *pending; 51 struct robust_list __user *entry, *next_entry, *pending;
52 unsigned int limit = ROBUST_LIST_LIMIT, pi, next_pi, pip; 52 unsigned int limit = ROBUST_LIST_LIMIT, pi, pip;
53 unsigned int uninitialized_var(next_pi);
53 compat_uptr_t uentry, next_uentry, upending; 54 compat_uptr_t uentry, next_uentry, upending;
54 compat_long_t futex_offset; 55 compat_long_t futex_offset;
55 int rc; 56 int rc;
diff --git a/kernel/hw_breakpoint.c b/kernel/hw_breakpoint.c
index 2c9120f0afca..e5325825aeb6 100644
--- a/kernel/hw_breakpoint.c
+++ b/kernel/hw_breakpoint.c
@@ -620,7 +620,7 @@ static struct pmu perf_breakpoint = {
620 .read = hw_breakpoint_pmu_read, 620 .read = hw_breakpoint_pmu_read,
621}; 621};
622 622
623static int __init init_hw_breakpoint(void) 623int __init init_hw_breakpoint(void)
624{ 624{
625 unsigned int **task_bp_pinned; 625 unsigned int **task_bp_pinned;
626 int cpu, err_cpu; 626 int cpu, err_cpu;
@@ -655,6 +655,5 @@ static int __init init_hw_breakpoint(void)
655 655
656 return -ENOMEM; 656 return -ENOMEM;
657} 657}
658core_initcall(init_hw_breakpoint);
659 658
660 659
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 644e8d5fa367..5f92acc5f952 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -324,6 +324,10 @@ void enable_irq(unsigned int irq)
324 if (!desc) 324 if (!desc)
325 return; 325 return;
326 326
327 if (WARN(!desc->irq_data.chip || !desc->irq_data.chip->irq_enable,
328 KERN_ERR "enable_irq before setup/request_irq: irq %u\n", irq))
329 return;
330
327 chip_bus_lock(desc); 331 chip_bus_lock(desc);
328 raw_spin_lock_irqsave(&desc->lock, flags); 332 raw_spin_lock_irqsave(&desc->lock, flags);
329 __enable_irq(desc, irq, false); 333 __enable_irq(desc, irq, false);
diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
index 01b1d3a88983..6c8a2a9f8a7b 100644
--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -214,7 +214,7 @@ static int irq_spurious_proc_show(struct seq_file *m, void *v)
214 214
215static int irq_spurious_proc_open(struct inode *inode, struct file *file) 215static int irq_spurious_proc_open(struct inode *inode, struct file *file)
216{ 216{
217 return single_open(file, irq_spurious_proc_show, NULL); 217 return single_open(file, irq_spurious_proc_show, PDE(inode)->data);
218} 218}
219 219
220static const struct file_operations irq_spurious_proc_fops = { 220static const struct file_operations irq_spurious_proc_fops = {
diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index f16763ff8481..90f881904bb1 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -145,7 +145,9 @@ void irq_work_run(void)
145 * Clear the BUSY bit and return to the free state if 145 * Clear the BUSY bit and return to the free state if
146 * no-one else claimed it meanwhile. 146 * no-one else claimed it meanwhile.
147 */ 147 */
148 cmpxchg(&entry->next, next_flags(NULL, IRQ_WORK_BUSY), NULL); 148 (void)cmpxchg(&entry->next,
149 next_flags(NULL, IRQ_WORK_BUSY),
150 NULL);
149 } 151 }
150} 152}
151EXPORT_SYMBOL_GPL(irq_work_run); 153EXPORT_SYMBOL_GPL(irq_work_run);
diff --git a/kernel/latencytop.c b/kernel/latencytop.c
index 877fb306d415..17110a4a4fc2 100644
--- a/kernel/latencytop.c
+++ b/kernel/latencytop.c
@@ -194,14 +194,7 @@ __account_scheduler_latency(struct task_struct *tsk, int usecs, int inter)
194 194
195 account_global_scheduler_latency(tsk, &lat); 195 account_global_scheduler_latency(tsk, &lat);
196 196
197 /* 197 for (i = 0; i < tsk->latency_record_count; i++) {
198 * short term hack; if we're > 32 we stop; future we recycle:
199 */
200 tsk->latency_record_count++;
201 if (tsk->latency_record_count >= LT_SAVECOUNT)
202 goto out_unlock;
203
204 for (i = 0; i < LT_SAVECOUNT; i++) {
205 struct latency_record *mylat; 198 struct latency_record *mylat;
206 int same = 1; 199 int same = 1;
207 200
@@ -227,8 +220,14 @@ __account_scheduler_latency(struct task_struct *tsk, int usecs, int inter)
227 } 220 }
228 } 221 }
229 222
223 /*
224 * short term hack; if we're > 32 we stop; future we recycle:
225 */
226 if (tsk->latency_record_count >= LT_SAVECOUNT)
227 goto out_unlock;
228
230 /* Allocated a new one: */ 229 /* Allocated a new one: */
231 i = tsk->latency_record_count; 230 i = tsk->latency_record_count++;
232 memcpy(&tsk->latency_record[i], &lat, sizeof(struct latency_record)); 231 memcpy(&tsk->latency_record[i], &lat, sizeof(struct latency_record));
233 232
234out_unlock: 233out_unlock:
diff --git a/kernel/module.c b/kernel/module.c
index 437a74a7524a..d190664f25ff 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2326,6 +2326,18 @@ static void find_module_sections(struct module *mod, struct load_info *info)
2326 kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) * 2326 kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) *
2327 mod->num_trace_events, GFP_KERNEL); 2327 mod->num_trace_events, GFP_KERNEL);
2328#endif 2328#endif
2329#ifdef CONFIG_TRACING
2330 mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt",
2331 sizeof(*mod->trace_bprintk_fmt_start),
2332 &mod->num_trace_bprintk_fmt);
2333 /*
2334 * This section contains pointers to allocated objects in the trace
2335 * code and not scanning it leads to false positives.
2336 */
2337 kmemleak_scan_area(mod->trace_bprintk_fmt_start,
2338 sizeof(*mod->trace_bprintk_fmt_start) *
2339 mod->num_trace_bprintk_fmt, GFP_KERNEL);
2340#endif
2329#ifdef CONFIG_FTRACE_MCOUNT_RECORD 2341#ifdef CONFIG_FTRACE_MCOUNT_RECORD
2330 /* sechdrs[0].sh_size is always zero */ 2342 /* sechdrs[0].sh_size is always zero */
2331 mod->ftrace_callsites = section_objs(info, "__mcount_loc", 2343 mod->ftrace_callsites = section_objs(info, "__mcount_loc",
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 06682e7b12e2..83d8fd991c86 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -31,6 +31,7 @@
31#include <linux/kernel_stat.h> 31#include <linux/kernel_stat.h>
32#include <linux/perf_event.h> 32#include <linux/perf_event.h>
33#include <linux/ftrace_event.h> 33#include <linux/ftrace_event.h>
34#include <linux/hw_breakpoint.h>
34 35
35#include <asm/irq_regs.h> 36#include <asm/irq_regs.h>
36 37
@@ -674,6 +675,8 @@ event_sched_in(struct perf_event *event,
674 675
675 event->tstamp_running += ctx->time - event->tstamp_stopped; 676 event->tstamp_running += ctx->time - event->tstamp_stopped;
676 677
678 event->shadow_ctx_time = ctx->time - ctx->timestamp;
679
677 if (!is_software_event(event)) 680 if (!is_software_event(event))
678 cpuctx->active_oncpu++; 681 cpuctx->active_oncpu++;
679 ctx->nr_active++; 682 ctx->nr_active++;
@@ -1284,8 +1287,6 @@ void __perf_event_task_sched_out(struct task_struct *task,
1284{ 1287{
1285 int ctxn; 1288 int ctxn;
1286 1289
1287 perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 1, NULL, 0);
1288
1289 for_each_task_context_nr(ctxn) 1290 for_each_task_context_nr(ctxn)
1290 perf_event_context_sched_out(task, ctxn, next); 1291 perf_event_context_sched_out(task, ctxn, next);
1291} 1292}
@@ -1619,8 +1620,12 @@ static void rotate_ctx(struct perf_event_context *ctx)
1619{ 1620{
1620 raw_spin_lock(&ctx->lock); 1621 raw_spin_lock(&ctx->lock);
1621 1622
1622 /* Rotate the first entry last of non-pinned groups */ 1623 /*
1623 list_rotate_left(&ctx->flexible_groups); 1624 * Rotate the first entry last of non-pinned groups. Rotation might be
1625 * disabled by the inheritance code.
1626 */
1627 if (!ctx->rotate_disable)
1628 list_rotate_left(&ctx->flexible_groups);
1624 1629
1625 raw_spin_unlock(&ctx->lock); 1630 raw_spin_unlock(&ctx->lock);
1626} 1631}
@@ -2232,11 +2237,6 @@ int perf_event_release_kernel(struct perf_event *event)
2232 raw_spin_unlock_irq(&ctx->lock); 2237 raw_spin_unlock_irq(&ctx->lock);
2233 mutex_unlock(&ctx->mutex); 2238 mutex_unlock(&ctx->mutex);
2234 2239
2235 mutex_lock(&event->owner->perf_event_mutex);
2236 list_del_init(&event->owner_entry);
2237 mutex_unlock(&event->owner->perf_event_mutex);
2238 put_task_struct(event->owner);
2239
2240 free_event(event); 2240 free_event(event);
2241 2241
2242 return 0; 2242 return 0;
@@ -2249,9 +2249,43 @@ EXPORT_SYMBOL_GPL(perf_event_release_kernel);
2249static int perf_release(struct inode *inode, struct file *file) 2249static int perf_release(struct inode *inode, struct file *file)
2250{ 2250{
2251 struct perf_event *event = file->private_data; 2251 struct perf_event *event = file->private_data;
2252 struct task_struct *owner;
2252 2253
2253 file->private_data = NULL; 2254 file->private_data = NULL;
2254 2255
2256 rcu_read_lock();
2257 owner = ACCESS_ONCE(event->owner);
2258 /*
2259 * Matches the smp_wmb() in perf_event_exit_task(). If we observe
2260 * !owner it means the list deletion is complete and we can indeed
2261 * free this event, otherwise we need to serialize on
2262 * owner->perf_event_mutex.
2263 */
2264 smp_read_barrier_depends();
2265 if (owner) {
2266 /*
2267 * Since delayed_put_task_struct() also drops the last
2268 * task reference we can safely take a new reference
2269 * while holding the rcu_read_lock().
2270 */
2271 get_task_struct(owner);
2272 }
2273 rcu_read_unlock();
2274
2275 if (owner) {
2276 mutex_lock(&owner->perf_event_mutex);
2277 /*
2278 * We have to re-check the event->owner field, if it is cleared
2279 * we raced with perf_event_exit_task(), acquiring the mutex
2280 * ensured they're done, and we can proceed with freeing the
2281 * event.
2282 */
2283 if (event->owner)
2284 list_del_init(&event->owner_entry);
2285 mutex_unlock(&owner->perf_event_mutex);
2286 put_task_struct(owner);
2287 }
2288
2255 return perf_event_release_kernel(event); 2289 return perf_event_release_kernel(event);
2256} 2290}
2257 2291
@@ -3396,7 +3430,8 @@ static u32 perf_event_tid(struct perf_event *event, struct task_struct *p)
3396} 3430}
3397 3431
3398static void perf_output_read_one(struct perf_output_handle *handle, 3432static void perf_output_read_one(struct perf_output_handle *handle,
3399 struct perf_event *event) 3433 struct perf_event *event,
3434 u64 enabled, u64 running)
3400{ 3435{
3401 u64 read_format = event->attr.read_format; 3436 u64 read_format = event->attr.read_format;
3402 u64 values[4]; 3437 u64 values[4];
@@ -3404,11 +3439,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
3404 3439
3405 values[n++] = perf_event_count(event); 3440 values[n++] = perf_event_count(event);
3406 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) { 3441 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
3407 values[n++] = event->total_time_enabled + 3442 values[n++] = enabled +
3408 atomic64_read(&event->child_total_time_enabled); 3443 atomic64_read(&event->child_total_time_enabled);
3409 } 3444 }
3410 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) { 3445 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
3411 values[n++] = event->total_time_running + 3446 values[n++] = running +
3412 atomic64_read(&event->child_total_time_running); 3447 atomic64_read(&event->child_total_time_running);
3413 } 3448 }
3414 if (read_format & PERF_FORMAT_ID) 3449 if (read_format & PERF_FORMAT_ID)
@@ -3421,7 +3456,8 @@ static void perf_output_read_one(struct perf_output_handle *handle,
3421 * XXX PERF_FORMAT_GROUP vs inherited events seems difficult. 3456 * XXX PERF_FORMAT_GROUP vs inherited events seems difficult.
3422 */ 3457 */
3423static void perf_output_read_group(struct perf_output_handle *handle, 3458static void perf_output_read_group(struct perf_output_handle *handle,
3424 struct perf_event *event) 3459 struct perf_event *event,
3460 u64 enabled, u64 running)
3425{ 3461{
3426 struct perf_event *leader = event->group_leader, *sub; 3462 struct perf_event *leader = event->group_leader, *sub;
3427 u64 read_format = event->attr.read_format; 3463 u64 read_format = event->attr.read_format;
@@ -3431,10 +3467,10 @@ static void perf_output_read_group(struct perf_output_handle *handle,
3431 values[n++] = 1 + leader->nr_siblings; 3467 values[n++] = 1 + leader->nr_siblings;
3432 3468
3433 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) 3469 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
3434 values[n++] = leader->total_time_enabled; 3470 values[n++] = enabled;
3435 3471
3436 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) 3472 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
3437 values[n++] = leader->total_time_running; 3473 values[n++] = running;
3438 3474
3439 if (leader != event) 3475 if (leader != event)
3440 leader->pmu->read(leader); 3476 leader->pmu->read(leader);
@@ -3459,13 +3495,35 @@ static void perf_output_read_group(struct perf_output_handle *handle,
3459 } 3495 }
3460} 3496}
3461 3497
3498#define PERF_FORMAT_TOTAL_TIMES (PERF_FORMAT_TOTAL_TIME_ENABLED|\
3499 PERF_FORMAT_TOTAL_TIME_RUNNING)
3500
3462static void perf_output_read(struct perf_output_handle *handle, 3501static void perf_output_read(struct perf_output_handle *handle,
3463 struct perf_event *event) 3502 struct perf_event *event)
3464{ 3503{
3504 u64 enabled = 0, running = 0, now, ctx_time;
3505 u64 read_format = event->attr.read_format;
3506
3507 /*
3508 * compute total_time_enabled, total_time_running
3509 * based on snapshot values taken when the event
3510 * was last scheduled in.
3511 *
3512 * we cannot simply called update_context_time()
3513 * because of locking issue as we are called in
3514 * NMI context
3515 */
3516 if (read_format & PERF_FORMAT_TOTAL_TIMES) {
3517 now = perf_clock();
3518 ctx_time = event->shadow_ctx_time + now;
3519 enabled = ctx_time - event->tstamp_enabled;
3520 running = ctx_time - event->tstamp_running;
3521 }
3522
3465 if (event->attr.read_format & PERF_FORMAT_GROUP) 3523 if (event->attr.read_format & PERF_FORMAT_GROUP)
3466 perf_output_read_group(handle, event); 3524 perf_output_read_group(handle, event, enabled, running);
3467 else 3525 else
3468 perf_output_read_one(handle, event); 3526 perf_output_read_one(handle, event, enabled, running);
3469} 3527}
3470 3528
3471void perf_output_sample(struct perf_output_handle *handle, 3529void perf_output_sample(struct perf_output_handle *handle,
@@ -3766,6 +3824,8 @@ static void perf_event_task_event(struct perf_task_event *task_event)
3766 rcu_read_lock(); 3824 rcu_read_lock();
3767 list_for_each_entry_rcu(pmu, &pmus, entry) { 3825 list_for_each_entry_rcu(pmu, &pmus, entry) {
3768 cpuctx = get_cpu_ptr(pmu->pmu_cpu_context); 3826 cpuctx = get_cpu_ptr(pmu->pmu_cpu_context);
3827 if (cpuctx->active_pmu != pmu)
3828 goto next;
3769 perf_event_task_ctx(&cpuctx->ctx, task_event); 3829 perf_event_task_ctx(&cpuctx->ctx, task_event);
3770 3830
3771 ctx = task_event->task_ctx; 3831 ctx = task_event->task_ctx;
@@ -3901,6 +3961,8 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event)
3901 rcu_read_lock(); 3961 rcu_read_lock();
3902 list_for_each_entry_rcu(pmu, &pmus, entry) { 3962 list_for_each_entry_rcu(pmu, &pmus, entry) {
3903 cpuctx = get_cpu_ptr(pmu->pmu_cpu_context); 3963 cpuctx = get_cpu_ptr(pmu->pmu_cpu_context);
3964 if (cpuctx->active_pmu != pmu)
3965 goto next;
3904 perf_event_comm_ctx(&cpuctx->ctx, comm_event); 3966 perf_event_comm_ctx(&cpuctx->ctx, comm_event);
3905 3967
3906 ctxn = pmu->task_ctx_nr; 3968 ctxn = pmu->task_ctx_nr;
@@ -4086,6 +4148,8 @@ got_name:
4086 rcu_read_lock(); 4148 rcu_read_lock();
4087 list_for_each_entry_rcu(pmu, &pmus, entry) { 4149 list_for_each_entry_rcu(pmu, &pmus, entry) {
4088 cpuctx = get_cpu_ptr(pmu->pmu_cpu_context); 4150 cpuctx = get_cpu_ptr(pmu->pmu_cpu_context);
4151 if (cpuctx->active_pmu != pmu)
4152 goto next;
4089 perf_event_mmap_ctx(&cpuctx->ctx, mmap_event, 4153 perf_event_mmap_ctx(&cpuctx->ctx, mmap_event,
4090 vma->vm_flags & VM_EXEC); 4154 vma->vm_flags & VM_EXEC);
4091 4155
@@ -4655,7 +4719,7 @@ static int perf_swevent_init(struct perf_event *event)
4655 break; 4719 break;
4656 } 4720 }
4657 4721
4658 if (event_id > PERF_COUNT_SW_MAX) 4722 if (event_id >= PERF_COUNT_SW_MAX)
4659 return -ENOENT; 4723 return -ENOENT;
4660 4724
4661 if (!event->parent) { 4725 if (!event->parent) {
@@ -5087,20 +5151,36 @@ static void *find_pmu_context(int ctxn)
5087 return NULL; 5151 return NULL;
5088} 5152}
5089 5153
5090static void free_pmu_context(void * __percpu cpu_context) 5154static void update_pmu_context(struct pmu *pmu, struct pmu *old_pmu)
5091{ 5155{
5092 struct pmu *pmu; 5156 int cpu;
5157
5158 for_each_possible_cpu(cpu) {
5159 struct perf_cpu_context *cpuctx;
5160
5161 cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu);
5162
5163 if (cpuctx->active_pmu == old_pmu)
5164 cpuctx->active_pmu = pmu;
5165 }
5166}
5167
5168static void free_pmu_context(struct pmu *pmu)
5169{
5170 struct pmu *i;
5093 5171
5094 mutex_lock(&pmus_lock); 5172 mutex_lock(&pmus_lock);
5095 /* 5173 /*
5096 * Like a real lame refcount. 5174 * Like a real lame refcount.
5097 */ 5175 */
5098 list_for_each_entry(pmu, &pmus, entry) { 5176 list_for_each_entry(i, &pmus, entry) {
5099 if (pmu->pmu_cpu_context == cpu_context) 5177 if (i->pmu_cpu_context == pmu->pmu_cpu_context) {
5178 update_pmu_context(i, pmu);
5100 goto out; 5179 goto out;
5180 }
5101 } 5181 }
5102 5182
5103 free_percpu(cpu_context); 5183 free_percpu(pmu->pmu_cpu_context);
5104out: 5184out:
5105 mutex_unlock(&pmus_lock); 5185 mutex_unlock(&pmus_lock);
5106} 5186}
@@ -5132,6 +5212,7 @@ int perf_pmu_register(struct pmu *pmu)
5132 cpuctx->ctx.pmu = pmu; 5212 cpuctx->ctx.pmu = pmu;
5133 cpuctx->jiffies_interval = 1; 5213 cpuctx->jiffies_interval = 1;
5134 INIT_LIST_HEAD(&cpuctx->rotation_list); 5214 INIT_LIST_HEAD(&cpuctx->rotation_list);
5215 cpuctx->active_pmu = pmu;
5135 } 5216 }
5136 5217
5137got_cpu_context: 5218got_cpu_context:
@@ -5183,7 +5264,7 @@ void perf_pmu_unregister(struct pmu *pmu)
5183 synchronize_rcu(); 5264 synchronize_rcu();
5184 5265
5185 free_percpu(pmu->pmu_disable_count); 5266 free_percpu(pmu->pmu_disable_count);
5186 free_pmu_context(pmu->pmu_cpu_context); 5267 free_pmu_context(pmu);
5187} 5268}
5188 5269
5189struct pmu *perf_init_event(struct perf_event *event) 5270struct pmu *perf_init_event(struct perf_event *event)
@@ -5651,7 +5732,7 @@ SYSCALL_DEFINE5(perf_event_open,
5651 mutex_unlock(&ctx->mutex); 5732 mutex_unlock(&ctx->mutex);
5652 5733
5653 event->owner = current; 5734 event->owner = current;
5654 get_task_struct(current); 5735
5655 mutex_lock(&current->perf_event_mutex); 5736 mutex_lock(&current->perf_event_mutex);
5656 list_add_tail(&event->owner_entry, &current->perf_event_list); 5737 list_add_tail(&event->owner_entry, &current->perf_event_list);
5657 mutex_unlock(&current->perf_event_mutex); 5738 mutex_unlock(&current->perf_event_mutex);
@@ -5719,12 +5800,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
5719 ++ctx->generation; 5800 ++ctx->generation;
5720 mutex_unlock(&ctx->mutex); 5801 mutex_unlock(&ctx->mutex);
5721 5802
5722 event->owner = current;
5723 get_task_struct(current);
5724 mutex_lock(&current->perf_event_mutex);
5725 list_add_tail(&event->owner_entry, &current->perf_event_list);
5726 mutex_unlock(&current->perf_event_mutex);
5727
5728 return event; 5803 return event;
5729 5804
5730err_free: 5805err_free:
@@ -5875,8 +5950,24 @@ again:
5875 */ 5950 */
5876void perf_event_exit_task(struct task_struct *child) 5951void perf_event_exit_task(struct task_struct *child)
5877{ 5952{
5953 struct perf_event *event, *tmp;
5878 int ctxn; 5954 int ctxn;
5879 5955
5956 mutex_lock(&child->perf_event_mutex);
5957 list_for_each_entry_safe(event, tmp, &child->perf_event_list,
5958 owner_entry) {
5959 list_del_init(&event->owner_entry);
5960
5961 /*
5962 * Ensure the list deletion is visible before we clear
5963 * the owner, closes a race against perf_release() where
5964 * we need to serialize on the owner->perf_event_mutex.
5965 */
5966 smp_wmb();
5967 event->owner = NULL;
5968 }
5969 mutex_unlock(&child->perf_event_mutex);
5970
5880 for_each_task_context_nr(ctxn) 5971 for_each_task_context_nr(ctxn)
5881 perf_event_exit_task_context(child, ctxn); 5972 perf_event_exit_task_context(child, ctxn);
5882} 5973}
@@ -6096,6 +6187,7 @@ int perf_event_init_context(struct task_struct *child, int ctxn)
6096 struct perf_event *event; 6187 struct perf_event *event;
6097 struct task_struct *parent = current; 6188 struct task_struct *parent = current;
6098 int inherited_all = 1; 6189 int inherited_all = 1;
6190 unsigned long flags;
6099 int ret = 0; 6191 int ret = 0;
6100 6192
6101 child->perf_event_ctxp[ctxn] = NULL; 6193 child->perf_event_ctxp[ctxn] = NULL;
@@ -6136,6 +6228,15 @@ int perf_event_init_context(struct task_struct *child, int ctxn)
6136 break; 6228 break;
6137 } 6229 }
6138 6230
6231 /*
6232 * We can't hold ctx->lock when iterating the ->flexible_group list due
6233 * to allocations, but we need to prevent rotation because
6234 * rotate_ctx() will change the list from interrupt context.
6235 */
6236 raw_spin_lock_irqsave(&parent_ctx->lock, flags);
6237 parent_ctx->rotate_disable = 1;
6238 raw_spin_unlock_irqrestore(&parent_ctx->lock, flags);
6239
6139 list_for_each_entry(event, &parent_ctx->flexible_groups, group_entry) { 6240 list_for_each_entry(event, &parent_ctx->flexible_groups, group_entry) {
6140 ret = inherit_task_group(event, parent, parent_ctx, 6241 ret = inherit_task_group(event, parent, parent_ctx,
6141 child, ctxn, &inherited_all); 6242 child, ctxn, &inherited_all);
@@ -6143,6 +6244,10 @@ int perf_event_init_context(struct task_struct *child, int ctxn)
6143 break; 6244 break;
6144 } 6245 }
6145 6246
6247 raw_spin_lock_irqsave(&parent_ctx->lock, flags);
6248 parent_ctx->rotate_disable = 0;
6249 raw_spin_unlock_irqrestore(&parent_ctx->lock, flags);
6250
6146 child_ctx = child->perf_event_ctxp[ctxn]; 6251 child_ctx = child->perf_event_ctxp[ctxn];
6147 6252
6148 if (child_ctx && inherited_all) { 6253 if (child_ctx && inherited_all) {
@@ -6295,6 +6400,8 @@ perf_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu)
6295 6400
6296void __init perf_event_init(void) 6401void __init perf_event_init(void)
6297{ 6402{
6403 int ret;
6404
6298 perf_event_init_all_cpus(); 6405 perf_event_init_all_cpus();
6299 init_srcu_struct(&pmus_srcu); 6406 init_srcu_struct(&pmus_srcu);
6300 perf_pmu_register(&perf_swevent); 6407 perf_pmu_register(&perf_swevent);
@@ -6302,4 +6409,7 @@ void __init perf_event_init(void)
6302 perf_pmu_register(&perf_task_clock); 6409 perf_pmu_register(&perf_task_clock);
6303 perf_tp_register(); 6410 perf_tp_register();
6304 perf_cpu_notifier(perf_cpu_notify); 6411 perf_cpu_notifier(perf_cpu_notify);
6412
6413 ret = init_hw_breakpoint();
6414 WARN(ret, "hw_breakpoint initialization failed with: %d", ret);
6305} 6415}
diff --git a/kernel/pm_qos_params.c b/kernel/pm_qos_params.c
index c7a8f453919e..aeaa7f846821 100644
--- a/kernel/pm_qos_params.c
+++ b/kernel/pm_qos_params.c
@@ -121,10 +121,10 @@ static inline int pm_qos_get_value(struct pm_qos_object *o)
121 121
122 switch (o->type) { 122 switch (o->type) {
123 case PM_QOS_MIN: 123 case PM_QOS_MIN:
124 return plist_last(&o->requests)->prio; 124 return plist_first(&o->requests)->prio;
125 125
126 case PM_QOS_MAX: 126 case PM_QOS_MAX:
127 return plist_first(&o->requests)->prio; 127 return plist_last(&o->requests)->prio;
128 128
129 default: 129 default:
130 /* runtime check for not using enum */ 130 /* runtime check for not using enum */
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 6842eeba5879..05bb7173850e 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -37,13 +37,13 @@ static int check_clock(const clockid_t which_clock)
37 if (pid == 0) 37 if (pid == 0)
38 return 0; 38 return 0;
39 39
40 read_lock(&tasklist_lock); 40 rcu_read_lock();
41 p = find_task_by_vpid(pid); 41 p = find_task_by_vpid(pid);
42 if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ? 42 if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
43 same_thread_group(p, current) : thread_group_leader(p))) { 43 same_thread_group(p, current) : has_group_leader_pid(p))) {
44 error = -EINVAL; 44 error = -EINVAL;
45 } 45 }
46 read_unlock(&tasklist_lock); 46 rcu_read_unlock();
47 47
48 return error; 48 return error;
49} 49}
@@ -390,7 +390,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
390 390
391 INIT_LIST_HEAD(&new_timer->it.cpu.entry); 391 INIT_LIST_HEAD(&new_timer->it.cpu.entry);
392 392
393 read_lock(&tasklist_lock); 393 rcu_read_lock();
394 if (CPUCLOCK_PERTHREAD(new_timer->it_clock)) { 394 if (CPUCLOCK_PERTHREAD(new_timer->it_clock)) {
395 if (pid == 0) { 395 if (pid == 0) {
396 p = current; 396 p = current;
@@ -404,7 +404,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
404 p = current->group_leader; 404 p = current->group_leader;
405 } else { 405 } else {
406 p = find_task_by_vpid(pid); 406 p = find_task_by_vpid(pid);
407 if (p && !thread_group_leader(p)) 407 if (p && !has_group_leader_pid(p))
408 p = NULL; 408 p = NULL;
409 } 409 }
410 } 410 }
@@ -414,7 +414,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
414 } else { 414 } else {
415 ret = -EINVAL; 415 ret = -EINVAL;
416 } 416 }
417 read_unlock(&tasklist_lock); 417 rcu_read_unlock();
418 418
419 return ret; 419 return ret;
420} 420}
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 29bff6117abc..a5aff3ebad38 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -246,9 +246,13 @@ config PM_OPS
246 depends on PM_SLEEP || PM_RUNTIME 246 depends on PM_SLEEP || PM_RUNTIME
247 default y 247 default y
248 248
249config ARCH_HAS_OPP
250 bool
251
249config PM_OPP 252config PM_OPP
250 bool "Operating Performance Point (OPP) Layer library" 253 bool "Operating Performance Point (OPP) Layer library"
251 depends on PM 254 depends on PM
255 depends on ARCH_HAS_OPP
252 ---help--- 256 ---help---
253 SOCs have a standard set of tuples consisting of frequency and 257 SOCs have a standard set of tuples consisting of frequency and
254 voltage pairs that the device will support per voltage domain. This 258 voltage pairs that the device will support per voltage domain. This
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 491b81a27111..b6279be691ac 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -327,7 +327,6 @@ static int create_image(int platform_mode)
327int hibernation_snapshot(int platform_mode) 327int hibernation_snapshot(int platform_mode)
328{ 328{
329 int error; 329 int error;
330 gfp_t saved_mask;
331 330
332 error = platform_begin(platform_mode); 331 error = platform_begin(platform_mode);
333 if (error) 332 if (error)
@@ -339,7 +338,7 @@ int hibernation_snapshot(int platform_mode)
339 goto Close; 338 goto Close;
340 339
341 suspend_console(); 340 suspend_console();
342 saved_mask = clear_gfp_allowed_mask(GFP_IOFS); 341 pm_restrict_gfp_mask();
343 error = dpm_suspend_start(PMSG_FREEZE); 342 error = dpm_suspend_start(PMSG_FREEZE);
344 if (error) 343 if (error)
345 goto Recover_platform; 344 goto Recover_platform;
@@ -348,7 +347,10 @@ int hibernation_snapshot(int platform_mode)
348 goto Recover_platform; 347 goto Recover_platform;
349 348
350 error = create_image(platform_mode); 349 error = create_image(platform_mode);
351 /* Control returns here after successful restore */ 350 /*
351 * Control returns here (1) after the image has been created or the
352 * image creation has failed and (2) after a successful restore.
353 */
352 354
353 Resume_devices: 355 Resume_devices:
354 /* We may need to release the preallocated image pages here. */ 356 /* We may need to release the preallocated image pages here. */
@@ -357,7 +359,10 @@ int hibernation_snapshot(int platform_mode)
357 359
358 dpm_resume_end(in_suspend ? 360 dpm_resume_end(in_suspend ?
359 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); 361 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
360 set_gfp_allowed_mask(saved_mask); 362
363 if (error || !in_suspend)
364 pm_restore_gfp_mask();
365
361 resume_console(); 366 resume_console();
362 Close: 367 Close:
363 platform_end(platform_mode); 368 platform_end(platform_mode);
@@ -452,17 +457,16 @@ static int resume_target_kernel(bool platform_mode)
452int hibernation_restore(int platform_mode) 457int hibernation_restore(int platform_mode)
453{ 458{
454 int error; 459 int error;
455 gfp_t saved_mask;
456 460
457 pm_prepare_console(); 461 pm_prepare_console();
458 suspend_console(); 462 suspend_console();
459 saved_mask = clear_gfp_allowed_mask(GFP_IOFS); 463 pm_restrict_gfp_mask();
460 error = dpm_suspend_start(PMSG_QUIESCE); 464 error = dpm_suspend_start(PMSG_QUIESCE);
461 if (!error) { 465 if (!error) {
462 error = resume_target_kernel(platform_mode); 466 error = resume_target_kernel(platform_mode);
463 dpm_resume_end(PMSG_RECOVER); 467 dpm_resume_end(PMSG_RECOVER);
464 } 468 }
465 set_gfp_allowed_mask(saved_mask); 469 pm_restore_gfp_mask();
466 resume_console(); 470 resume_console();
467 pm_restore_console(); 471 pm_restore_console();
468 return error; 472 return error;
@@ -476,7 +480,6 @@ int hibernation_restore(int platform_mode)
476int hibernation_platform_enter(void) 480int hibernation_platform_enter(void)
477{ 481{
478 int error; 482 int error;
479 gfp_t saved_mask;
480 483
481 if (!hibernation_ops) 484 if (!hibernation_ops)
482 return -ENOSYS; 485 return -ENOSYS;
@@ -492,7 +495,6 @@ int hibernation_platform_enter(void)
492 495
493 entering_platform_hibernation = true; 496 entering_platform_hibernation = true;
494 suspend_console(); 497 suspend_console();
495 saved_mask = clear_gfp_allowed_mask(GFP_IOFS);
496 error = dpm_suspend_start(PMSG_HIBERNATE); 498 error = dpm_suspend_start(PMSG_HIBERNATE);
497 if (error) { 499 if (error) {
498 if (hibernation_ops->recover) 500 if (hibernation_ops->recover)
@@ -536,7 +538,6 @@ int hibernation_platform_enter(void)
536 Resume_devices: 538 Resume_devices:
537 entering_platform_hibernation = false; 539 entering_platform_hibernation = false;
538 dpm_resume_end(PMSG_RESTORE); 540 dpm_resume_end(PMSG_RESTORE);
539 set_gfp_allowed_mask(saved_mask);
540 resume_console(); 541 resume_console();
541 542
542 Close: 543 Close:
@@ -646,6 +647,7 @@ int hibernate(void)
646 swsusp_free(); 647 swsusp_free();
647 if (!error) 648 if (!error)
648 power_down(); 649 power_down();
650 pm_restore_gfp_mask();
649 } else { 651 } else {
650 pr_debug("PM: Image restored successfully.\n"); 652 pr_debug("PM: Image restored successfully.\n");
651 } 653 }
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 80051bdde6f1..ea64ece26d97 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -197,7 +197,6 @@ static int suspend_enter(suspend_state_t state)
197int suspend_devices_and_enter(suspend_state_t state) 197int suspend_devices_and_enter(suspend_state_t state)
198{ 198{
199 int error; 199 int error;
200 gfp_t saved_mask;
201 200
202 if (!suspend_ops) 201 if (!suspend_ops)
203 return -ENOSYS; 202 return -ENOSYS;
@@ -208,7 +207,7 @@ int suspend_devices_and_enter(suspend_state_t state)
208 goto Close; 207 goto Close;
209 } 208 }
210 suspend_console(); 209 suspend_console();
211 saved_mask = clear_gfp_allowed_mask(GFP_IOFS); 210 pm_restrict_gfp_mask();
212 suspend_test_start(); 211 suspend_test_start();
213 error = dpm_suspend_start(PMSG_SUSPEND); 212 error = dpm_suspend_start(PMSG_SUSPEND);
214 if (error) { 213 if (error) {
@@ -225,7 +224,7 @@ int suspend_devices_and_enter(suspend_state_t state)
225 suspend_test_start(); 224 suspend_test_start();
226 dpm_resume_end(PMSG_RESUME); 225 dpm_resume_end(PMSG_RESUME);
227 suspend_test_finish("resume devices"); 226 suspend_test_finish("resume devices");
228 set_gfp_allowed_mask(saved_mask); 227 pm_restore_gfp_mask();
229 resume_console(); 228 resume_console();
230 Close: 229 Close:
231 if (suspend_ops->end) 230 if (suspend_ops->end)
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index cd09c22de03d..69425889bd40 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -6,6 +6,7 @@
6 * 6 *
7 * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz> 7 * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz>
8 * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> 8 * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
9 * Copyright (C) 2010 Bojan Smojver <bojan@rexursive.com>
9 * 10 *
10 * This file is released under the GPLv2. 11 * This file is released under the GPLv2.
11 * 12 *
@@ -29,7 +30,7 @@
29 30
30#include "power.h" 31#include "power.h"
31 32
32#define HIBERNATE_SIG "LINHIB0001" 33#define HIBERNATE_SIG "S1SUSPEND"
33 34
34/* 35/*
35 * The swap map is a data structure used for keeping track of each page 36 * The swap map is a data structure used for keeping track of each page
@@ -753,30 +754,43 @@ static int load_image_lzo(struct swap_map_handle *handle,
753{ 754{
754 unsigned int m; 755 unsigned int m;
755 int error = 0; 756 int error = 0;
757 struct bio *bio;
756 struct timeval start; 758 struct timeval start;
757 struct timeval stop; 759 struct timeval stop;
758 unsigned nr_pages; 760 unsigned nr_pages;
759 size_t off, unc_len, cmp_len; 761 size_t i, off, unc_len, cmp_len;
760 unsigned char *unc, *cmp, *page; 762 unsigned char *unc, *cmp, *page[LZO_CMP_PAGES];
761 763
762 page = (void *)__get_free_page(__GFP_WAIT | __GFP_HIGH); 764 for (i = 0; i < LZO_CMP_PAGES; i++) {
763 if (!page) { 765 page[i] = (void *)__get_free_page(__GFP_WAIT | __GFP_HIGH);
764 printk(KERN_ERR "PM: Failed to allocate LZO page\n"); 766 if (!page[i]) {
765 return -ENOMEM; 767 printk(KERN_ERR "PM: Failed to allocate LZO page\n");
768
769 while (i)
770 free_page((unsigned long)page[--i]);
771
772 return -ENOMEM;
773 }
766 } 774 }
767 775
768 unc = vmalloc(LZO_UNC_SIZE); 776 unc = vmalloc(LZO_UNC_SIZE);
769 if (!unc) { 777 if (!unc) {
770 printk(KERN_ERR "PM: Failed to allocate LZO uncompressed\n"); 778 printk(KERN_ERR "PM: Failed to allocate LZO uncompressed\n");
771 free_page((unsigned long)page); 779
780 for (i = 0; i < LZO_CMP_PAGES; i++)
781 free_page((unsigned long)page[i]);
782
772 return -ENOMEM; 783 return -ENOMEM;
773 } 784 }
774 785
775 cmp = vmalloc(LZO_CMP_SIZE); 786 cmp = vmalloc(LZO_CMP_SIZE);
776 if (!cmp) { 787 if (!cmp) {
777 printk(KERN_ERR "PM: Failed to allocate LZO compressed\n"); 788 printk(KERN_ERR "PM: Failed to allocate LZO compressed\n");
789
778 vfree(unc); 790 vfree(unc);
779 free_page((unsigned long)page); 791 for (i = 0; i < LZO_CMP_PAGES; i++)
792 free_page((unsigned long)page[i]);
793
780 return -ENOMEM; 794 return -ENOMEM;
781 } 795 }
782 796
@@ -787,6 +801,7 @@ static int load_image_lzo(struct swap_map_handle *handle,
787 if (!m) 801 if (!m)
788 m = 1; 802 m = 1;
789 nr_pages = 0; 803 nr_pages = 0;
804 bio = NULL;
790 do_gettimeofday(&start); 805 do_gettimeofday(&start);
791 806
792 error = snapshot_write_next(snapshot); 807 error = snapshot_write_next(snapshot);
@@ -794,11 +809,11 @@ static int load_image_lzo(struct swap_map_handle *handle,
794 goto out_finish; 809 goto out_finish;
795 810
796 for (;;) { 811 for (;;) {
797 error = swap_read_page(handle, page, NULL); /* sync */ 812 error = swap_read_page(handle, page[0], NULL); /* sync */
798 if (error) 813 if (error)
799 break; 814 break;
800 815
801 cmp_len = *(size_t *)page; 816 cmp_len = *(size_t *)page[0];
802 if (unlikely(!cmp_len || 817 if (unlikely(!cmp_len ||
803 cmp_len > lzo1x_worst_compress(LZO_UNC_SIZE))) { 818 cmp_len > lzo1x_worst_compress(LZO_UNC_SIZE))) {
804 printk(KERN_ERR "PM: Invalid LZO compressed length\n"); 819 printk(KERN_ERR "PM: Invalid LZO compressed length\n");
@@ -806,13 +821,20 @@ static int load_image_lzo(struct swap_map_handle *handle,
806 break; 821 break;
807 } 822 }
808 823
809 memcpy(cmp, page, PAGE_SIZE); 824 for (off = PAGE_SIZE, i = 1;
810 for (off = PAGE_SIZE; off < LZO_HEADER + cmp_len; off += PAGE_SIZE) { 825 off < LZO_HEADER + cmp_len; off += PAGE_SIZE, i++) {
811 error = swap_read_page(handle, page, NULL); /* sync */ 826 error = swap_read_page(handle, page[i], &bio);
812 if (error) 827 if (error)
813 goto out_finish; 828 goto out_finish;
829 }
814 830
815 memcpy(cmp + off, page, PAGE_SIZE); 831 error = hib_wait_on_bio_chain(&bio); /* need all data now */
832 if (error)
833 goto out_finish;
834
835 for (off = 0, i = 0;
836 off < LZO_HEADER + cmp_len; off += PAGE_SIZE, i++) {
837 memcpy(cmp + off, page[i], PAGE_SIZE);
816 } 838 }
817 839
818 unc_len = LZO_UNC_SIZE; 840 unc_len = LZO_UNC_SIZE;
@@ -857,7 +879,8 @@ out_finish:
857 879
858 vfree(cmp); 880 vfree(cmp);
859 vfree(unc); 881 vfree(unc);
860 free_page((unsigned long)page); 882 for (i = 0; i < LZO_CMP_PAGES; i++)
883 free_page((unsigned long)page[i]);
861 884
862 return error; 885 return error;
863} 886}
diff --git a/kernel/power/user.c b/kernel/power/user.c
index e819e17877ca..c36c3b9e8a84 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -137,7 +137,7 @@ static int snapshot_release(struct inode *inode, struct file *filp)
137 free_all_swap_pages(data->swap); 137 free_all_swap_pages(data->swap);
138 if (data->frozen) 138 if (data->frozen)
139 thaw_processes(); 139 thaw_processes();
140 pm_notifier_call_chain(data->mode == O_WRONLY ? 140 pm_notifier_call_chain(data->mode == O_RDONLY ?
141 PM_POST_HIBERNATION : PM_POST_RESTORE); 141 PM_POST_HIBERNATION : PM_POST_RESTORE);
142 atomic_inc(&snapshot_device_available); 142 atomic_inc(&snapshot_device_available);
143 143
@@ -263,6 +263,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
263 case SNAPSHOT_UNFREEZE: 263 case SNAPSHOT_UNFREEZE:
264 if (!data->frozen || data->ready) 264 if (!data->frozen || data->ready)
265 break; 265 break;
266 pm_restore_gfp_mask();
266 thaw_processes(); 267 thaw_processes();
267 usermodehelper_enable(); 268 usermodehelper_enable();
268 data->frozen = 0; 269 data->frozen = 0;
@@ -275,6 +276,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
275 error = -EPERM; 276 error = -EPERM;
276 break; 277 break;
277 } 278 }
279 pm_restore_gfp_mask();
278 error = hibernation_snapshot(data->platform_support); 280 error = hibernation_snapshot(data->platform_support);
279 if (!error) 281 if (!error)
280 error = put_user(in_suspend, (int __user *)arg); 282 error = put_user(in_suspend, (int __user *)arg);
diff --git a/kernel/printk.c b/kernel/printk.c
index b2ebaee8c377..a23315dc4498 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -261,6 +261,12 @@ static inline void boot_delay_msec(void)
261} 261}
262#endif 262#endif
263 263
264#ifdef CONFIG_SECURITY_DMESG_RESTRICT
265int dmesg_restrict = 1;
266#else
267int dmesg_restrict;
268#endif
269
264int do_syslog(int type, char __user *buf, int len, bool from_file) 270int do_syslog(int type, char __user *buf, int len, bool from_file)
265{ 271{
266 unsigned i, j, limit, count; 272 unsigned i, j, limit, count;
@@ -268,7 +274,20 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
268 char c; 274 char c;
269 int error = 0; 275 int error = 0;
270 276
271 error = security_syslog(type, from_file); 277 /*
278 * If this is from /proc/kmsg we only do the capabilities checks
279 * at open time.
280 */
281 if (type == SYSLOG_ACTION_OPEN || !from_file) {
282 if (dmesg_restrict && !capable(CAP_SYS_ADMIN))
283 return -EPERM;
284 if ((type != SYSLOG_ACTION_READ_ALL &&
285 type != SYSLOG_ACTION_SIZE_BUFFER) &&
286 !capable(CAP_SYS_ADMIN))
287 return -EPERM;
288 }
289
290 error = security_syslog(type);
272 if (error) 291 if (error)
273 return error; 292 return error;
274 293
@@ -1063,13 +1082,15 @@ void printk_tick(void)
1063 1082
1064int printk_needs_cpu(int cpu) 1083int printk_needs_cpu(int cpu)
1065{ 1084{
1085 if (unlikely(cpu_is_offline(cpu)))
1086 printk_tick();
1066 return per_cpu(printk_pending, cpu); 1087 return per_cpu(printk_pending, cpu);
1067} 1088}
1068 1089
1069void wake_up_klogd(void) 1090void wake_up_klogd(void)
1070{ 1091{
1071 if (waitqueue_active(&log_wait)) 1092 if (waitqueue_active(&log_wait))
1072 __raw_get_cpu_var(printk_pending) = 1; 1093 this_cpu_write(printk_pending, 1);
1073} 1094}
1074 1095
1075/** 1096/**
diff --git a/kernel/range.c b/kernel/range.c
index 471b66acabb5..37fa9b99ad58 100644
--- a/kernel/range.c
+++ b/kernel/range.c
@@ -119,7 +119,7 @@ static int cmp_range(const void *x1, const void *x2)
119 119
120int clean_sort_range(struct range *range, int az) 120int clean_sort_range(struct range *range, int az)
121{ 121{
122 int i, j, k = az - 1, nr_range = 0; 122 int i, j, k = az - 1, nr_range = az;
123 123
124 for (i = 0; i < k; i++) { 124 for (i = 0; i < k; i++) {
125 if (range[i].end) 125 if (range[i].end)
diff --git a/kernel/relay.c b/kernel/relay.c
index c7cf397fb929..859ea5a9605f 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -70,17 +70,10 @@ static const struct vm_operations_struct relay_file_mmap_ops = {
70 */ 70 */
71static struct page **relay_alloc_page_array(unsigned int n_pages) 71static struct page **relay_alloc_page_array(unsigned int n_pages)
72{ 72{
73 struct page **array; 73 const size_t pa_size = n_pages * sizeof(struct page *);
74 size_t pa_size = n_pages * sizeof(struct page *); 74 if (pa_size > PAGE_SIZE)
75 75 return vzalloc(pa_size);
76 if (pa_size > PAGE_SIZE) { 76 return kzalloc(pa_size, GFP_KERNEL);
77 array = vmalloc(pa_size);
78 if (array)
79 memset(array, 0, pa_size);
80 } else {
81 array = kzalloc(pa_size, GFP_KERNEL);
82 }
83 return array;
84} 77}
85 78
86/* 79/*
diff --git a/kernel/resource.c b/kernel/resource.c
index 9fad33efd0db..798e2fae2a06 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -40,23 +40,6 @@ EXPORT_SYMBOL(iomem_resource);
40 40
41static DEFINE_RWLOCK(resource_lock); 41static DEFINE_RWLOCK(resource_lock);
42 42
43/*
44 * By default, we allocate free space bottom-up. The architecture can request
45 * top-down by clearing this flag. The user can override the architecture's
46 * choice with the "resource_alloc_from_bottom" kernel boot option, but that
47 * should only be a debugging tool.
48 */
49int resource_alloc_from_bottom = 1;
50
51static __init int setup_alloc_from_bottom(char *s)
52{
53 printk(KERN_INFO
54 "resource: allocating from bottom-up; please report a bug\n");
55 resource_alloc_from_bottom = 1;
56 return 0;
57}
58early_param("resource_alloc_from_bottom", setup_alloc_from_bottom);
59
60static void *r_next(struct seq_file *m, void *v, loff_t *pos) 43static void *r_next(struct seq_file *m, void *v, loff_t *pos)
61{ 44{
62 struct resource *p = v; 45 struct resource *p = v;
@@ -374,6 +357,10 @@ int __weak page_is_ram(unsigned long pfn)
374 return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1; 357 return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1;
375} 358}
376 359
360void __weak arch_remove_reservations(struct resource *avail)
361{
362}
363
377static resource_size_t simple_align_resource(void *data, 364static resource_size_t simple_align_resource(void *data,
378 const struct resource *avail, 365 const struct resource *avail,
379 resource_size_t size, 366 resource_size_t size,
@@ -397,74 +384,7 @@ static bool resource_contains(struct resource *res1, struct resource *res2)
397} 384}
398 385
399/* 386/*
400 * Find the resource before "child" in the sibling list of "root" children.
401 */
402static struct resource *find_sibling_prev(struct resource *root, struct resource *child)
403{
404 struct resource *this;
405
406 for (this = root->child; this; this = this->sibling)
407 if (this->sibling == child)
408 return this;
409
410 return NULL;
411}
412
413/*
414 * Find empty slot in the resource tree given range and alignment. 387 * Find empty slot in the resource tree given range and alignment.
415 * This version allocates from the end of the root resource first.
416 */
417static int find_resource_from_top(struct resource *root, struct resource *new,
418 resource_size_t size, resource_size_t min,
419 resource_size_t max, resource_size_t align,
420 resource_size_t (*alignf)(void *,
421 const struct resource *,
422 resource_size_t,
423 resource_size_t),
424 void *alignf_data)
425{
426 struct resource *this;
427 struct resource tmp, avail, alloc;
428
429 tmp.start = root->end;
430 tmp.end = root->end;
431
432 this = find_sibling_prev(root, NULL);
433 for (;;) {
434 if (this) {
435 if (this->end < root->end)
436 tmp.start = this->end + 1;
437 } else
438 tmp.start = root->start;
439
440 resource_clip(&tmp, min, max);
441
442 /* Check for overflow after ALIGN() */
443 avail = *new;
444 avail.start = ALIGN(tmp.start, align);
445 avail.end = tmp.end;
446 if (avail.start >= tmp.start) {
447 alloc.start = alignf(alignf_data, &avail, size, align);
448 alloc.end = alloc.start + size - 1;
449 if (resource_contains(&avail, &alloc)) {
450 new->start = alloc.start;
451 new->end = alloc.end;
452 return 0;
453 }
454 }
455
456 if (!this || this->start == root->start)
457 break;
458
459 tmp.end = this->start - 1;
460 this = find_sibling_prev(root, this);
461 }
462 return -EBUSY;
463}
464
465/*
466 * Find empty slot in the resource tree given range and alignment.
467 * This version allocates from the beginning of the root resource first.
468 */ 388 */
469static int find_resource(struct resource *root, struct resource *new, 389static int find_resource(struct resource *root, struct resource *new,
470 resource_size_t size, resource_size_t min, 390 resource_size_t size, resource_size_t min,
@@ -478,23 +398,24 @@ static int find_resource(struct resource *root, struct resource *new,
478 struct resource *this = root->child; 398 struct resource *this = root->child;
479 struct resource tmp = *new, avail, alloc; 399 struct resource tmp = *new, avail, alloc;
480 400
401 tmp.flags = new->flags;
481 tmp.start = root->start; 402 tmp.start = root->start;
482 /* 403 /*
483 * Skip past an allocated resource that starts at 0, since the 404 * Skip past an allocated resource that starts at 0, since the assignment
484 * assignment of this->start - 1 to tmp->end below would cause an 405 * of this->start - 1 to tmp->end below would cause an underflow.
485 * underflow.
486 */ 406 */
487 if (this && this->start == 0) { 407 if (this && this->start == 0) {
488 tmp.start = this->end + 1; 408 tmp.start = this->end + 1;
489 this = this->sibling; 409 this = this->sibling;
490 } 410 }
491 for (;;) { 411 for(;;) {
492 if (this) 412 if (this)
493 tmp.end = this->start - 1; 413 tmp.end = this->start - 1;
494 else 414 else
495 tmp.end = root->end; 415 tmp.end = root->end;
496 416
497 resource_clip(&tmp, min, max); 417 resource_clip(&tmp, min, max);
418 arch_remove_reservations(&tmp);
498 419
499 /* Check for overflow after ALIGN() */ 420 /* Check for overflow after ALIGN() */
500 avail = *new; 421 avail = *new;
@@ -509,10 +430,8 @@ static int find_resource(struct resource *root, struct resource *new,
509 return 0; 430 return 0;
510 } 431 }
511 } 432 }
512
513 if (!this) 433 if (!this)
514 break; 434 break;
515
516 tmp.start = this->end + 1; 435 tmp.start = this->end + 1;
517 this = this->sibling; 436 this = this->sibling;
518 } 437 }
@@ -545,10 +464,7 @@ int allocate_resource(struct resource *root, struct resource *new,
545 alignf = simple_align_resource; 464 alignf = simple_align_resource;
546 465
547 write_lock(&resource_lock); 466 write_lock(&resource_lock);
548 if (resource_alloc_from_bottom) 467 err = find_resource(root, new, size, min, max, align, alignf, alignf_data);
549 err = find_resource(root, new, size, min, max, align, alignf, alignf_data);
550 else
551 err = find_resource_from_top(root, new, size, min, max, align, alignf, alignf_data);
552 if (err >= 0 && __request_resource(root, new)) 468 if (err >= 0 && __request_resource(root, new))
553 err = -EBUSY; 469 err = -EBUSY;
554 write_unlock(&resource_lock); 470 write_unlock(&resource_lock);
diff --git a/kernel/sched.c b/kernel/sched.c
index 554c0d6c489e..f89fb67818de 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -560,18 +560,8 @@ struct rq {
560 560
561static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); 561static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
562 562
563static inline
564void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
565{
566 rq->curr->sched_class->check_preempt_curr(rq, p, flags);
567 563
568 /* 564static void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags);
569 * A queue event has occurred, and we're going to schedule. In
570 * this case, we can save a useless back to back clock update.
571 */
572 if (test_tsk_need_resched(p))
573 rq->skip_clock_update = 1;
574}
575 565
576static inline int cpu_of(struct rq *rq) 566static inline int cpu_of(struct rq *rq)
577{ 567{
@@ -646,22 +636,18 @@ static inline struct task_group *task_group(struct task_struct *p)
646 636
647#endif /* CONFIG_CGROUP_SCHED */ 637#endif /* CONFIG_CGROUP_SCHED */
648 638
649static u64 irq_time_cpu(int cpu); 639static void update_rq_clock_task(struct rq *rq, s64 delta);
650static void sched_irq_time_avg_update(struct rq *rq, u64 irq_time);
651 640
652inline void update_rq_clock(struct rq *rq) 641static void update_rq_clock(struct rq *rq)
653{ 642{
654 if (!rq->skip_clock_update) { 643 s64 delta;
655 int cpu = cpu_of(rq);
656 u64 irq_time;
657 644
658 rq->clock = sched_clock_cpu(cpu); 645 if (rq->skip_clock_update)
659 irq_time = irq_time_cpu(cpu); 646 return;
660 if (rq->clock - irq_time > rq->clock_task)
661 rq->clock_task = rq->clock - irq_time;
662 647
663 sched_irq_time_avg_update(rq, irq_time); 648 delta = sched_clock_cpu(cpu_of(rq)) - rq->clock;
664 } 649 rq->clock += delta;
650 update_rq_clock_task(rq, delta);
665} 651}
666 652
667/* 653/*
@@ -1934,10 +1920,9 @@ static void deactivate_task(struct rq *rq, struct task_struct *p, int flags)
1934 * They are read and saved off onto struct rq in update_rq_clock(). 1920 * They are read and saved off onto struct rq in update_rq_clock().
1935 * This may result in other CPU reading this CPU's irq time and can 1921 * This may result in other CPU reading this CPU's irq time and can
1936 * race with irq/account_system_vtime on this CPU. We would either get old 1922 * race with irq/account_system_vtime on this CPU. We would either get old
1937 * or new value (or semi updated value on 32 bit) with a side effect of 1923 * or new value with a side effect of accounting a slice of irq time to wrong
1938 * accounting a slice of irq time to wrong task when irq is in progress 1924 * task when irq is in progress while we read rq->clock. That is a worthy
1939 * while we read rq->clock. That is a worthy compromise in place of having 1925 * compromise in place of having locks on each irq in account_system_time.
1940 * locks on each irq in account_system_time.
1941 */ 1926 */
1942static DEFINE_PER_CPU(u64, cpu_hardirq_time); 1927static DEFINE_PER_CPU(u64, cpu_hardirq_time);
1943static DEFINE_PER_CPU(u64, cpu_softirq_time); 1928static DEFINE_PER_CPU(u64, cpu_softirq_time);
@@ -1955,19 +1940,58 @@ void disable_sched_clock_irqtime(void)
1955 sched_clock_irqtime = 0; 1940 sched_clock_irqtime = 0;
1956} 1941}
1957 1942
1958static u64 irq_time_cpu(int cpu) 1943#ifndef CONFIG_64BIT
1944static DEFINE_PER_CPU(seqcount_t, irq_time_seq);
1945
1946static inline void irq_time_write_begin(void)
1959{ 1947{
1960 if (!sched_clock_irqtime) 1948 __this_cpu_inc(irq_time_seq.sequence);
1961 return 0; 1949 smp_wmb();
1950}
1962 1951
1952static inline void irq_time_write_end(void)
1953{
1954 smp_wmb();
1955 __this_cpu_inc(irq_time_seq.sequence);
1956}
1957
1958static inline u64 irq_time_read(int cpu)
1959{
1960 u64 irq_time;
1961 unsigned seq;
1962
1963 do {
1964 seq = read_seqcount_begin(&per_cpu(irq_time_seq, cpu));
1965 irq_time = per_cpu(cpu_softirq_time, cpu) +
1966 per_cpu(cpu_hardirq_time, cpu);
1967 } while (read_seqcount_retry(&per_cpu(irq_time_seq, cpu), seq));
1968
1969 return irq_time;
1970}
1971#else /* CONFIG_64BIT */
1972static inline void irq_time_write_begin(void)
1973{
1974}
1975
1976static inline void irq_time_write_end(void)
1977{
1978}
1979
1980static inline u64 irq_time_read(int cpu)
1981{
1963 return per_cpu(cpu_softirq_time, cpu) + per_cpu(cpu_hardirq_time, cpu); 1982 return per_cpu(cpu_softirq_time, cpu) + per_cpu(cpu_hardirq_time, cpu);
1964} 1983}
1984#endif /* CONFIG_64BIT */
1965 1985
1986/*
1987 * Called before incrementing preempt_count on {soft,}irq_enter
1988 * and before decrementing preempt_count on {soft,}irq_exit.
1989 */
1966void account_system_vtime(struct task_struct *curr) 1990void account_system_vtime(struct task_struct *curr)
1967{ 1991{
1968 unsigned long flags; 1992 unsigned long flags;
1993 s64 delta;
1969 int cpu; 1994 int cpu;
1970 u64 now, delta;
1971 1995
1972 if (!sched_clock_irqtime) 1996 if (!sched_clock_irqtime)
1973 return; 1997 return;
@@ -1975,9 +1999,10 @@ void account_system_vtime(struct task_struct *curr)
1975 local_irq_save(flags); 1999 local_irq_save(flags);
1976 2000
1977 cpu = smp_processor_id(); 2001 cpu = smp_processor_id();
1978 now = sched_clock_cpu(cpu); 2002 delta = sched_clock_cpu(cpu) - __this_cpu_read(irq_start_time);
1979 delta = now - per_cpu(irq_start_time, cpu); 2003 __this_cpu_add(irq_start_time, delta);
1980 per_cpu(irq_start_time, cpu) = now; 2004
2005 irq_time_write_begin();
1981 /* 2006 /*
1982 * We do not account for softirq time from ksoftirqd here. 2007 * We do not account for softirq time from ksoftirqd here.
1983 * We want to continue accounting softirq time to ksoftirqd thread 2008 * We want to continue accounting softirq time to ksoftirqd thread
@@ -1985,33 +2010,55 @@ void account_system_vtime(struct task_struct *curr)
1985 * that do not consume any time, but still wants to run. 2010 * that do not consume any time, but still wants to run.
1986 */ 2011 */
1987 if (hardirq_count()) 2012 if (hardirq_count())
1988 per_cpu(cpu_hardirq_time, cpu) += delta; 2013 __this_cpu_add(cpu_hardirq_time, delta);
1989 else if (in_serving_softirq() && !(curr->flags & PF_KSOFTIRQD)) 2014 else if (in_serving_softirq() && !(curr->flags & PF_KSOFTIRQD))
1990 per_cpu(cpu_softirq_time, cpu) += delta; 2015 __this_cpu_add(cpu_softirq_time, delta);
1991 2016
2017 irq_time_write_end();
1992 local_irq_restore(flags); 2018 local_irq_restore(flags);
1993} 2019}
1994EXPORT_SYMBOL_GPL(account_system_vtime); 2020EXPORT_SYMBOL_GPL(account_system_vtime);
1995 2021
1996static void sched_irq_time_avg_update(struct rq *rq, u64 curr_irq_time) 2022static void update_rq_clock_task(struct rq *rq, s64 delta)
1997{ 2023{
1998 if (sched_clock_irqtime && sched_feat(NONIRQ_POWER)) { 2024 s64 irq_delta;
1999 u64 delta_irq = curr_irq_time - rq->prev_irq_time; 2025
2000 rq->prev_irq_time = curr_irq_time; 2026 irq_delta = irq_time_read(cpu_of(rq)) - rq->prev_irq_time;
2001 sched_rt_avg_update(rq, delta_irq); 2027
2002 } 2028 /*
2029 * Since irq_time is only updated on {soft,}irq_exit, we might run into
2030 * this case when a previous update_rq_clock() happened inside a
2031 * {soft,}irq region.
2032 *
2033 * When this happens, we stop ->clock_task and only update the
2034 * prev_irq_time stamp to account for the part that fit, so that a next
2035 * update will consume the rest. This ensures ->clock_task is
2036 * monotonic.
2037 *
2038 * It does however cause some slight miss-attribution of {soft,}irq
2039 * time, a more accurate solution would be to update the irq_time using
2040 * the current rq->clock timestamp, except that would require using
2041 * atomic ops.
2042 */
2043 if (irq_delta > delta)
2044 irq_delta = delta;
2045
2046 rq->prev_irq_time += irq_delta;
2047 delta -= irq_delta;
2048 rq->clock_task += delta;
2049
2050 if (irq_delta && sched_feat(NONIRQ_POWER))
2051 sched_rt_avg_update(rq, irq_delta);
2003} 2052}
2004 2053
2005#else 2054#else /* CONFIG_IRQ_TIME_ACCOUNTING */
2006 2055
2007static u64 irq_time_cpu(int cpu) 2056static void update_rq_clock_task(struct rq *rq, s64 delta)
2008{ 2057{
2009 return 0; 2058 rq->clock_task += delta;
2010} 2059}
2011 2060
2012static void sched_irq_time_avg_update(struct rq *rq, u64 curr_irq_time) { } 2061#endif /* CONFIG_IRQ_TIME_ACCOUNTING */
2013
2014#endif
2015 2062
2016#include "sched_idletask.c" 2063#include "sched_idletask.c"
2017#include "sched_fair.c" 2064#include "sched_fair.c"
@@ -2118,6 +2165,31 @@ static inline void check_class_changed(struct rq *rq, struct task_struct *p,
2118 p->sched_class->prio_changed(rq, p, oldprio, running); 2165 p->sched_class->prio_changed(rq, p, oldprio, running);
2119} 2166}
2120 2167
2168static void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
2169{
2170 const struct sched_class *class;
2171
2172 if (p->sched_class == rq->curr->sched_class) {
2173 rq->curr->sched_class->check_preempt_curr(rq, p, flags);
2174 } else {
2175 for_each_class(class) {
2176 if (class == rq->curr->sched_class)
2177 break;
2178 if (class == p->sched_class) {
2179 resched_task(rq->curr);
2180 break;
2181 }
2182 }
2183 }
2184
2185 /*
2186 * A queue event has occurred, and we're going to schedule. In
2187 * this case, we can save a useless back to back clock update.
2188 */
2189 if (rq->curr->se.on_rq && test_tsk_need_resched(rq->curr))
2190 rq->skip_clock_update = 1;
2191}
2192
2121#ifdef CONFIG_SMP 2193#ifdef CONFIG_SMP
2122/* 2194/*
2123 * Is this task likely cache-hot: 2195 * Is this task likely cache-hot:
@@ -3104,6 +3176,15 @@ static long calc_load_fold_active(struct rq *this_rq)
3104 return delta; 3176 return delta;
3105} 3177}
3106 3178
3179static unsigned long
3180calc_load(unsigned long load, unsigned long exp, unsigned long active)
3181{
3182 load *= exp;
3183 load += active * (FIXED_1 - exp);
3184 load += 1UL << (FSHIFT - 1);
3185 return load >> FSHIFT;
3186}
3187
3107#ifdef CONFIG_NO_HZ 3188#ifdef CONFIG_NO_HZ
3108/* 3189/*
3109 * For NO_HZ we delay the active fold to the next LOAD_FREQ update. 3190 * For NO_HZ we delay the active fold to the next LOAD_FREQ update.
@@ -3133,6 +3214,128 @@ static long calc_load_fold_idle(void)
3133 3214
3134 return delta; 3215 return delta;
3135} 3216}
3217
3218/**
3219 * fixed_power_int - compute: x^n, in O(log n) time
3220 *
3221 * @x: base of the power
3222 * @frac_bits: fractional bits of @x
3223 * @n: power to raise @x to.
3224 *
3225 * By exploiting the relation between the definition of the natural power
3226 * function: x^n := x*x*...*x (x multiplied by itself for n times), and
3227 * the binary encoding of numbers used by computers: n := \Sum n_i * 2^i,
3228 * (where: n_i \elem {0, 1}, the binary vector representing n),
3229 * we find: x^n := x^(\Sum n_i * 2^i) := \Prod x^(n_i * 2^i), which is
3230 * of course trivially computable in O(log_2 n), the length of our binary
3231 * vector.
3232 */
3233static unsigned long
3234fixed_power_int(unsigned long x, unsigned int frac_bits, unsigned int n)
3235{
3236 unsigned long result = 1UL << frac_bits;
3237
3238 if (n) for (;;) {
3239 if (n & 1) {
3240 result *= x;
3241 result += 1UL << (frac_bits - 1);
3242 result >>= frac_bits;
3243 }
3244 n >>= 1;
3245 if (!n)
3246 break;
3247 x *= x;
3248 x += 1UL << (frac_bits - 1);
3249 x >>= frac_bits;
3250 }
3251
3252 return result;
3253}
3254
3255/*
3256 * a1 = a0 * e + a * (1 - e)
3257 *
3258 * a2 = a1 * e + a * (1 - e)
3259 * = (a0 * e + a * (1 - e)) * e + a * (1 - e)
3260 * = a0 * e^2 + a * (1 - e) * (1 + e)
3261 *
3262 * a3 = a2 * e + a * (1 - e)
3263 * = (a0 * e^2 + a * (1 - e) * (1 + e)) * e + a * (1 - e)
3264 * = a0 * e^3 + a * (1 - e) * (1 + e + e^2)
3265 *
3266 * ...
3267 *
3268 * an = a0 * e^n + a * (1 - e) * (1 + e + ... + e^n-1) [1]
3269 * = a0 * e^n + a * (1 - e) * (1 - e^n)/(1 - e)
3270 * = a0 * e^n + a * (1 - e^n)
3271 *
3272 * [1] application of the geometric series:
3273 *
3274 * n 1 - x^(n+1)
3275 * S_n := \Sum x^i = -------------
3276 * i=0 1 - x
3277 */
3278static unsigned long
3279calc_load_n(unsigned long load, unsigned long exp,
3280 unsigned long active, unsigned int n)
3281{
3282
3283 return calc_load(load, fixed_power_int(exp, FSHIFT, n), active);
3284}
3285
3286/*
3287 * NO_HZ can leave us missing all per-cpu ticks calling
3288 * calc_load_account_active(), but since an idle CPU folds its delta into
3289 * calc_load_tasks_idle per calc_load_account_idle(), all we need to do is fold
3290 * in the pending idle delta if our idle period crossed a load cycle boundary.
3291 *
3292 * Once we've updated the global active value, we need to apply the exponential
3293 * weights adjusted to the number of cycles missed.
3294 */
3295static void calc_global_nohz(unsigned long ticks)
3296{
3297 long delta, active, n;
3298
3299 if (time_before(jiffies, calc_load_update))
3300 return;
3301
3302 /*
3303 * If we crossed a calc_load_update boundary, make sure to fold
3304 * any pending idle changes, the respective CPUs might have
3305 * missed the tick driven calc_load_account_active() update
3306 * due to NO_HZ.
3307 */
3308 delta = calc_load_fold_idle();
3309 if (delta)
3310 atomic_long_add(delta, &calc_load_tasks);
3311
3312 /*
3313 * If we were idle for multiple load cycles, apply them.
3314 */
3315 if (ticks >= LOAD_FREQ) {
3316 n = ticks / LOAD_FREQ;
3317
3318 active = atomic_long_read(&calc_load_tasks);
3319 active = active > 0 ? active * FIXED_1 : 0;
3320
3321 avenrun[0] = calc_load_n(avenrun[0], EXP_1, active, n);
3322 avenrun[1] = calc_load_n(avenrun[1], EXP_5, active, n);
3323 avenrun[2] = calc_load_n(avenrun[2], EXP_15, active, n);
3324
3325 calc_load_update += n * LOAD_FREQ;
3326 }
3327
3328 /*
3329 * Its possible the remainder of the above division also crosses
3330 * a LOAD_FREQ period, the regular check in calc_global_load()
3331 * which comes after this will take care of that.
3332 *
3333 * Consider us being 11 ticks before a cycle completion, and us
3334 * sleeping for 4*LOAD_FREQ + 22 ticks, then the above code will
3335 * age us 4 cycles, and the test in calc_global_load() will
3336 * pick up the final one.
3337 */
3338}
3136#else 3339#else
3137static void calc_load_account_idle(struct rq *this_rq) 3340static void calc_load_account_idle(struct rq *this_rq)
3138{ 3341{
@@ -3142,6 +3345,10 @@ static inline long calc_load_fold_idle(void)
3142{ 3345{
3143 return 0; 3346 return 0;
3144} 3347}
3348
3349static void calc_global_nohz(unsigned long ticks)
3350{
3351}
3145#endif 3352#endif
3146 3353
3147/** 3354/**
@@ -3159,24 +3366,17 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
3159 loads[2] = (avenrun[2] + offset) << shift; 3366 loads[2] = (avenrun[2] + offset) << shift;
3160} 3367}
3161 3368
3162static unsigned long
3163calc_load(unsigned long load, unsigned long exp, unsigned long active)
3164{
3165 load *= exp;
3166 load += active * (FIXED_1 - exp);
3167 return load >> FSHIFT;
3168}
3169
3170/* 3369/*
3171 * calc_load - update the avenrun load estimates 10 ticks after the 3370 * calc_load - update the avenrun load estimates 10 ticks after the
3172 * CPUs have updated calc_load_tasks. 3371 * CPUs have updated calc_load_tasks.
3173 */ 3372 */
3174void calc_global_load(void) 3373void calc_global_load(unsigned long ticks)
3175{ 3374{
3176 unsigned long upd = calc_load_update + 10;
3177 long active; 3375 long active;
3178 3376
3179 if (time_before(jiffies, upd)) 3377 calc_global_nohz(ticks);
3378
3379 if (time_before(jiffies, calc_load_update + 10))
3180 return; 3380 return;
3181 3381
3182 active = atomic_long_read(&calc_load_tasks); 3382 active = atomic_long_read(&calc_load_tasks);
@@ -3830,7 +4030,6 @@ static void put_prev_task(struct rq *rq, struct task_struct *prev)
3830{ 4030{
3831 if (prev->se.on_rq) 4031 if (prev->se.on_rq)
3832 update_rq_clock(rq); 4032 update_rq_clock(rq);
3833 rq->skip_clock_update = 0;
3834 prev->sched_class->put_prev_task(rq, prev); 4033 prev->sched_class->put_prev_task(rq, prev);
3835} 4034}
3836 4035
@@ -3888,7 +4087,6 @@ need_resched_nonpreemptible:
3888 hrtick_clear(rq); 4087 hrtick_clear(rq);
3889 4088
3890 raw_spin_lock_irq(&rq->lock); 4089 raw_spin_lock_irq(&rq->lock);
3891 clear_tsk_need_resched(prev);
3892 4090
3893 switch_count = &prev->nivcsw; 4091 switch_count = &prev->nivcsw;
3894 if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) { 4092 if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
@@ -3920,6 +4118,8 @@ need_resched_nonpreemptible:
3920 4118
3921 put_prev_task(rq, prev); 4119 put_prev_task(rq, prev);
3922 next = pick_next_task(rq); 4120 next = pick_next_task(rq);
4121 clear_tsk_need_resched(prev);
4122 rq->skip_clock_update = 0;
3923 4123
3924 if (likely(prev != next)) { 4124 if (likely(prev != next)) {
3925 sched_info_switch(prev, next); 4125 sched_info_switch(prev, next);
@@ -6960,6 +7160,8 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
6960 if (cpu != group_first_cpu(sd->groups)) 7160 if (cpu != group_first_cpu(sd->groups))
6961 return; 7161 return;
6962 7162
7163 sd->groups->group_weight = cpumask_weight(sched_group_cpus(sd->groups));
7164
6963 child = sd->child; 7165 child = sd->child;
6964 7166
6965 sd->groups->cpu_power = 0; 7167 sd->groups->cpu_power = 0;
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index f4f6a8326dd0..00ebd7686676 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -1654,12 +1654,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
1654 struct cfs_rq *cfs_rq = task_cfs_rq(curr); 1654 struct cfs_rq *cfs_rq = task_cfs_rq(curr);
1655 int scale = cfs_rq->nr_running >= sched_nr_latency; 1655 int scale = cfs_rq->nr_running >= sched_nr_latency;
1656 1656
1657 if (unlikely(rt_prio(p->prio)))
1658 goto preempt;
1659
1660 if (unlikely(p->sched_class != &fair_sched_class))
1661 return;
1662
1663 if (unlikely(se == pse)) 1657 if (unlikely(se == pse))
1664 return; 1658 return;
1665 1659
@@ -1764,10 +1758,6 @@ static void pull_task(struct rq *src_rq, struct task_struct *p,
1764 set_task_cpu(p, this_cpu); 1758 set_task_cpu(p, this_cpu);
1765 activate_task(this_rq, p, 0); 1759 activate_task(this_rq, p, 0);
1766 check_preempt_curr(this_rq, p, 0); 1760 check_preempt_curr(this_rq, p, 0);
1767
1768 /* re-arm NEWIDLE balancing when moving tasks */
1769 src_rq->avg_idle = this_rq->avg_idle = 2*sysctl_sched_migration_cost;
1770 this_rq->idle_stamp = 0;
1771} 1761}
1772 1762
1773/* 1763/*
@@ -2035,13 +2025,16 @@ struct sd_lb_stats {
2035 unsigned long this_load_per_task; 2025 unsigned long this_load_per_task;
2036 unsigned long this_nr_running; 2026 unsigned long this_nr_running;
2037 unsigned long this_has_capacity; 2027 unsigned long this_has_capacity;
2028 unsigned int this_idle_cpus;
2038 2029
2039 /* Statistics of the busiest group */ 2030 /* Statistics of the busiest group */
2031 unsigned int busiest_idle_cpus;
2040 unsigned long max_load; 2032 unsigned long max_load;
2041 unsigned long busiest_load_per_task; 2033 unsigned long busiest_load_per_task;
2042 unsigned long busiest_nr_running; 2034 unsigned long busiest_nr_running;
2043 unsigned long busiest_group_capacity; 2035 unsigned long busiest_group_capacity;
2044 unsigned long busiest_has_capacity; 2036 unsigned long busiest_has_capacity;
2037 unsigned int busiest_group_weight;
2045 2038
2046 int group_imb; /* Is there imbalance in this sd */ 2039 int group_imb; /* Is there imbalance in this sd */
2047#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) 2040#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
@@ -2063,6 +2056,8 @@ struct sg_lb_stats {
2063 unsigned long sum_nr_running; /* Nr tasks running in the group */ 2056 unsigned long sum_nr_running; /* Nr tasks running in the group */
2064 unsigned long sum_weighted_load; /* Weighted load of group's tasks */ 2057 unsigned long sum_weighted_load; /* Weighted load of group's tasks */
2065 unsigned long group_capacity; 2058 unsigned long group_capacity;
2059 unsigned long idle_cpus;
2060 unsigned long group_weight;
2066 int group_imb; /* Is there an imbalance in the group ? */ 2061 int group_imb; /* Is there an imbalance in the group ? */
2067 int group_has_capacity; /* Is there extra capacity in the group? */ 2062 int group_has_capacity; /* Is there extra capacity in the group? */
2068}; 2063};
@@ -2431,7 +2426,8 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
2431 sgs->group_load += load; 2426 sgs->group_load += load;
2432 sgs->sum_nr_running += rq->nr_running; 2427 sgs->sum_nr_running += rq->nr_running;
2433 sgs->sum_weighted_load += weighted_cpuload(i); 2428 sgs->sum_weighted_load += weighted_cpuload(i);
2434 2429 if (idle_cpu(i))
2430 sgs->idle_cpus++;
2435 } 2431 }
2436 2432
2437 /* 2433 /*
@@ -2469,6 +2465,7 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
2469 sgs->group_capacity = DIV_ROUND_CLOSEST(group->cpu_power, SCHED_LOAD_SCALE); 2465 sgs->group_capacity = DIV_ROUND_CLOSEST(group->cpu_power, SCHED_LOAD_SCALE);
2470 if (!sgs->group_capacity) 2466 if (!sgs->group_capacity)
2471 sgs->group_capacity = fix_small_capacity(sd, group); 2467 sgs->group_capacity = fix_small_capacity(sd, group);
2468 sgs->group_weight = group->group_weight;
2472 2469
2473 if (sgs->group_capacity > sgs->sum_nr_running) 2470 if (sgs->group_capacity > sgs->sum_nr_running)
2474 sgs->group_has_capacity = 1; 2471 sgs->group_has_capacity = 1;
@@ -2576,13 +2573,16 @@ static inline void update_sd_lb_stats(struct sched_domain *sd, int this_cpu,
2576 sds->this_nr_running = sgs.sum_nr_running; 2573 sds->this_nr_running = sgs.sum_nr_running;
2577 sds->this_load_per_task = sgs.sum_weighted_load; 2574 sds->this_load_per_task = sgs.sum_weighted_load;
2578 sds->this_has_capacity = sgs.group_has_capacity; 2575 sds->this_has_capacity = sgs.group_has_capacity;
2576 sds->this_idle_cpus = sgs.idle_cpus;
2579 } else if (update_sd_pick_busiest(sd, sds, sg, &sgs, this_cpu)) { 2577 } else if (update_sd_pick_busiest(sd, sds, sg, &sgs, this_cpu)) {
2580 sds->max_load = sgs.avg_load; 2578 sds->max_load = sgs.avg_load;
2581 sds->busiest = sg; 2579 sds->busiest = sg;
2582 sds->busiest_nr_running = sgs.sum_nr_running; 2580 sds->busiest_nr_running = sgs.sum_nr_running;
2581 sds->busiest_idle_cpus = sgs.idle_cpus;
2583 sds->busiest_group_capacity = sgs.group_capacity; 2582 sds->busiest_group_capacity = sgs.group_capacity;
2584 sds->busiest_load_per_task = sgs.sum_weighted_load; 2583 sds->busiest_load_per_task = sgs.sum_weighted_load;
2585 sds->busiest_has_capacity = sgs.group_has_capacity; 2584 sds->busiest_has_capacity = sgs.group_has_capacity;
2585 sds->busiest_group_weight = sgs.group_weight;
2586 sds->group_imb = sgs.group_imb; 2586 sds->group_imb = sgs.group_imb;
2587 } 2587 }
2588 2588
@@ -2860,8 +2860,26 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
2860 if (sds.this_load >= sds.avg_load) 2860 if (sds.this_load >= sds.avg_load)
2861 goto out_balanced; 2861 goto out_balanced;
2862 2862
2863 if (100 * sds.max_load <= sd->imbalance_pct * sds.this_load) 2863 /*
2864 goto out_balanced; 2864 * In the CPU_NEWLY_IDLE, use imbalance_pct to be conservative.
2865 * And to check for busy balance use !idle_cpu instead of
2866 * CPU_NOT_IDLE. This is because HT siblings will use CPU_NOT_IDLE
2867 * even when they are idle.
2868 */
2869 if (idle == CPU_NEWLY_IDLE || !idle_cpu(this_cpu)) {
2870 if (100 * sds.max_load <= sd->imbalance_pct * sds.this_load)
2871 goto out_balanced;
2872 } else {
2873 /*
2874 * This cpu is idle. If the busiest group load doesn't
2875 * have more tasks than the number of available cpu's and
2876 * there is no imbalance between this and busiest group
2877 * wrt to idle cpu's, it is balanced.
2878 */
2879 if ((sds.this_idle_cpus <= sds.busiest_idle_cpus + 1) &&
2880 sds.busiest_nr_running <= sds.busiest_group_weight)
2881 goto out_balanced;
2882 }
2865 2883
2866force_balance: 2884force_balance:
2867 /* Looks like there is an imbalance. Compute it */ 2885 /* Looks like there is an imbalance. Compute it */
@@ -3197,8 +3215,10 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
3197 interval = msecs_to_jiffies(sd->balance_interval); 3215 interval = msecs_to_jiffies(sd->balance_interval);
3198 if (time_after(next_balance, sd->last_balance + interval)) 3216 if (time_after(next_balance, sd->last_balance + interval))
3199 next_balance = sd->last_balance + interval; 3217 next_balance = sd->last_balance + interval;
3200 if (pulled_task) 3218 if (pulled_task) {
3219 this_rq->idle_stamp = 0;
3201 break; 3220 break;
3221 }
3202 } 3222 }
3203 3223
3204 raw_spin_lock(&this_rq->lock); 3224 raw_spin_lock(&this_rq->lock);
diff --git a/kernel/sched_stoptask.c b/kernel/sched_stoptask.c
index 45bddc0c1048..2bf6b47058c1 100644
--- a/kernel/sched_stoptask.c
+++ b/kernel/sched_stoptask.c
@@ -19,14 +19,14 @@ select_task_rq_stop(struct rq *rq, struct task_struct *p,
19static void 19static void
20check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags) 20check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags)
21{ 21{
22 resched_task(rq->curr); /* we preempt everything */ 22 /* we're never preempted */
23} 23}
24 24
25static struct task_struct *pick_next_task_stop(struct rq *rq) 25static struct task_struct *pick_next_task_stop(struct rq *rq)
26{ 26{
27 struct task_struct *stop = rq->stop; 27 struct task_struct *stop = rq->stop;
28 28
29 if (stop && stop->state == TASK_RUNNING) 29 if (stop && stop->se.on_rq)
30 return stop; 30 return stop;
31 31
32 return NULL; 32 return NULL;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index c33a1edb799f..5abfa1518554 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -702,6 +702,15 @@ static struct ctl_table kern_table[] = {
702 .extra1 = &zero, 702 .extra1 = &zero,
703 .extra2 = &ten_thousand, 703 .extra2 = &ten_thousand,
704 }, 704 },
705 {
706 .procname = "dmesg_restrict",
707 .data = &dmesg_restrict,
708 .maxlen = sizeof(int),
709 .mode = 0644,
710 .proc_handler = proc_dointvec_minmax,
711 .extra1 = &zero,
712 .extra2 = &one,
713 },
705#endif 714#endif
706 { 715 {
707 .procname = "ngroups_max", 716 .procname = "ngroups_max",
diff --git a/kernel/timer.c b/kernel/timer.c
index 68a9ae7679b7..353b9227c2ec 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -1252,6 +1252,12 @@ unsigned long get_next_timer_interrupt(unsigned long now)
1252 struct tvec_base *base = __get_cpu_var(tvec_bases); 1252 struct tvec_base *base = __get_cpu_var(tvec_bases);
1253 unsigned long expires; 1253 unsigned long expires;
1254 1254
1255 /*
1256 * Pretend that there is no timer pending if the cpu is offline.
1257 * Possible pending timers will be migrated later to an active cpu.
1258 */
1259 if (cpu_is_offline(smp_processor_id()))
1260 return now + NEXT_TIMER_MAX_DELTA;
1255 spin_lock(&base->lock); 1261 spin_lock(&base->lock);
1256 if (time_before_eq(base->next_timer, base->timer_jiffies)) 1262 if (time_before_eq(base->next_timer, base->timer_jiffies))
1257 base->next_timer = __next_timer_interrupt(base); 1263 base->next_timer = __next_timer_interrupt(base);
@@ -1319,7 +1325,7 @@ void do_timer(unsigned long ticks)
1319{ 1325{
1320 jiffies_64 += ticks; 1326 jiffies_64 += ticks;
1321 update_wall_time(); 1327 update_wall_time();
1322 calc_global_load(); 1328 calc_global_load(ticks);
1323} 1329}
1324 1330
1325#ifdef __ARCH_WANT_SYS_ALARM 1331#ifdef __ARCH_WANT_SYS_ALARM
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index e04b8bcdef88..ea37e2ff4164 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -126,7 +126,7 @@ if FTRACE
126config FUNCTION_TRACER 126config FUNCTION_TRACER
127 bool "Kernel Function Tracer" 127 bool "Kernel Function Tracer"
128 depends on HAVE_FUNCTION_TRACER 128 depends on HAVE_FUNCTION_TRACER
129 select FRAME_POINTER if (!ARM_UNWIND) 129 select FRAME_POINTER if !ARM_UNWIND && !S390
130 select KALLSYMS 130 select KALLSYMS
131 select GENERIC_TRACER 131 select GENERIC_TRACER
132 select CONTEXT_SWITCH_TRACER 132 select CONTEXT_SWITCH_TRACER
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index bc251ed66724..7b8ec0281548 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -168,7 +168,6 @@ static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector,
168static const u32 ddir_act[2] = { BLK_TC_ACT(BLK_TC_READ), 168static const u32 ddir_act[2] = { BLK_TC_ACT(BLK_TC_READ),
169 BLK_TC_ACT(BLK_TC_WRITE) }; 169 BLK_TC_ACT(BLK_TC_WRITE) };
170 170
171#define BLK_TC_HARDBARRIER BLK_TC_BARRIER
172#define BLK_TC_RAHEAD BLK_TC_AHEAD 171#define BLK_TC_RAHEAD BLK_TC_AHEAD
173 172
174/* The ilog2() calls fall out because they're constant */ 173/* The ilog2() calls fall out because they're constant */
@@ -196,7 +195,6 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
196 return; 195 return;
197 196
198 what |= ddir_act[rw & WRITE]; 197 what |= ddir_act[rw & WRITE];
199 what |= MASK_TC_BIT(rw, HARDBARRIER);
200 what |= MASK_TC_BIT(rw, SYNC); 198 what |= MASK_TC_BIT(rw, SYNC);
201 what |= MASK_TC_BIT(rw, RAHEAD); 199 what |= MASK_TC_BIT(rw, RAHEAD);
202 what |= MASK_TC_BIT(rw, META); 200 what |= MASK_TC_BIT(rw, META);
@@ -1807,8 +1805,6 @@ void blk_fill_rwbs(char *rwbs, u32 rw, int bytes)
1807 1805
1808 if (rw & REQ_RAHEAD) 1806 if (rw & REQ_RAHEAD)
1809 rwbs[i++] = 'A'; 1807 rwbs[i++] = 'A';
1810 if (rw & REQ_HARDBARRIER)
1811 rwbs[i++] = 'B';
1812 if (rw & REQ_SYNC) 1808 if (rw & REQ_SYNC)
1813 rwbs[i++] = 'S'; 1809 rwbs[i++] = 'S';
1814 if (rw & REQ_META) 1810 if (rw & REQ_META)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 82d9b8106cd0..f8cf959bad45 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -17,7 +17,6 @@
17#include <linux/writeback.h> 17#include <linux/writeback.h>
18#include <linux/kallsyms.h> 18#include <linux/kallsyms.h>
19#include <linux/seq_file.h> 19#include <linux/seq_file.h>
20#include <linux/smp_lock.h>
21#include <linux/notifier.h> 20#include <linux/notifier.h>
22#include <linux/irqflags.h> 21#include <linux/irqflags.h>
23#include <linux/debugfs.h> 22#include <linux/debugfs.h>
@@ -1284,6 +1283,8 @@ void trace_dump_stack(void)
1284 __ftrace_trace_stack(global_trace.buffer, flags, 3, preempt_count()); 1283 __ftrace_trace_stack(global_trace.buffer, flags, 3, preempt_count());
1285} 1284}
1286 1285
1286static DEFINE_PER_CPU(int, user_stack_count);
1287
1287void 1288void
1288ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc) 1289ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
1289{ 1290{
@@ -1302,6 +1303,18 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
1302 if (unlikely(in_nmi())) 1303 if (unlikely(in_nmi()))
1303 return; 1304 return;
1304 1305
1306 /*
1307 * prevent recursion, since the user stack tracing may
1308 * trigger other kernel events.
1309 */
1310 preempt_disable();
1311 if (__this_cpu_read(user_stack_count))
1312 goto out;
1313
1314 __this_cpu_inc(user_stack_count);
1315
1316
1317
1305 event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, 1318 event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK,
1306 sizeof(*entry), flags, pc); 1319 sizeof(*entry), flags, pc);
1307 if (!event) 1320 if (!event)
@@ -1319,6 +1332,11 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
1319 save_stack_trace_user(&trace); 1332 save_stack_trace_user(&trace);
1320 if (!filter_check_discard(call, entry, buffer, event)) 1333 if (!filter_check_discard(call, entry, buffer, event))
1321 ring_buffer_unlock_commit(buffer, event); 1334 ring_buffer_unlock_commit(buffer, event);
1335
1336 __this_cpu_dec(user_stack_count);
1337
1338 out:
1339 preempt_enable();
1322} 1340}
1323 1341
1324#ifdef UNUSED 1342#ifdef UNUSED
@@ -2320,11 +2338,19 @@ tracing_write_stub(struct file *filp, const char __user *ubuf,
2320 return count; 2338 return count;
2321} 2339}
2322 2340
2341static loff_t tracing_seek(struct file *file, loff_t offset, int origin)
2342{
2343 if (file->f_mode & FMODE_READ)
2344 return seq_lseek(file, offset, origin);
2345 else
2346 return 0;
2347}
2348
2323static const struct file_operations tracing_fops = { 2349static const struct file_operations tracing_fops = {
2324 .open = tracing_open, 2350 .open = tracing_open,
2325 .read = seq_read, 2351 .read = seq_read,
2326 .write = tracing_write_stub, 2352 .write = tracing_write_stub,
2327 .llseek = seq_lseek, 2353 .llseek = tracing_seek,
2328 .release = tracing_release, 2354 .release = tracing_release,
2329}; 2355};
2330 2356
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index bafba687a6d8..6e3c41a4024c 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -43,7 +43,7 @@ static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts_saved);
43static DEFINE_PER_CPU(struct perf_event *, watchdog_ev); 43static DEFINE_PER_CPU(struct perf_event *, watchdog_ev);
44#endif 44#endif
45 45
46static int __initdata no_watchdog; 46static int no_watchdog;
47 47
48 48
49/* boot commands */ 49/* boot commands */
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 90db1bd1a978..e785b0f2aea5 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -661,7 +661,7 @@ void wq_worker_waking_up(struct task_struct *task, unsigned int cpu)
661{ 661{
662 struct worker *worker = kthread_data(task); 662 struct worker *worker = kthread_data(task);
663 663
664 if (likely(!(worker->flags & WORKER_NOT_RUNNING))) 664 if (!(worker->flags & WORKER_NOT_RUNNING))
665 atomic_inc(get_gcwq_nr_running(cpu)); 665 atomic_inc(get_gcwq_nr_running(cpu));
666} 666}
667 667
@@ -687,7 +687,7 @@ struct task_struct *wq_worker_sleeping(struct task_struct *task,
687 struct global_cwq *gcwq = get_gcwq(cpu); 687 struct global_cwq *gcwq = get_gcwq(cpu);
688 atomic_t *nr_running = get_gcwq_nr_running(cpu); 688 atomic_t *nr_running = get_gcwq_nr_running(cpu);
689 689
690 if (unlikely(worker->flags & WORKER_NOT_RUNNING)) 690 if (worker->flags & WORKER_NOT_RUNNING)
691 return NULL; 691 return NULL;
692 692
693 /* this can only happen on the local cpu */ 693 /* this can only happen on the local cpu */
@@ -3692,7 +3692,8 @@ static int __init init_workqueues(void)
3692 system_nrt_wq = alloc_workqueue("events_nrt", WQ_NON_REENTRANT, 0); 3692 system_nrt_wq = alloc_workqueue("events_nrt", WQ_NON_REENTRANT, 0);
3693 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, 3693 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND,
3694 WQ_UNBOUND_MAX_ACTIVE); 3694 WQ_UNBOUND_MAX_ACTIVE);
3695 BUG_ON(!system_wq || !system_long_wq || !system_nrt_wq); 3695 BUG_ON(!system_wq || !system_long_wq || !system_nrt_wq ||
3696 !system_unbound_wq);
3696 return 0; 3697 return 0;
3697} 3698}
3698early_initcall(init_workqueues); 3699early_initcall(init_workqueues);
diff --git a/lib/debug_locks.c b/lib/debug_locks.c
index 5bf0020b9248..b1c177307677 100644
--- a/lib/debug_locks.c
+++ b/lib/debug_locks.c
@@ -8,7 +8,6 @@
8 * 8 *
9 * Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> 9 * Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
10 */ 10 */
11#include <linux/kernel.h>
12#include <linux/rwsem.h> 11#include <linux/rwsem.h>
13#include <linux/mutex.h> 12#include <linux/mutex.h>
14#include <linux/module.h> 13#include <linux/module.h>
@@ -39,7 +38,6 @@ int debug_locks_off(void)
39{ 38{
40 if (__debug_locks_off()) { 39 if (__debug_locks_off()) {
41 if (!debug_locks_silent) { 40 if (!debug_locks_silent) {
42 oops_in_progress = 1;
43 console_verbose(); 41 console_verbose();
44 return 1; 42 return 1;
45 } 43 }
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 6f412ab4c24f..5086bb962b4d 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -82,6 +82,16 @@ struct radix_tree_preload {
82}; 82};
83static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, }; 83static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
84 84
85static inline void *ptr_to_indirect(void *ptr)
86{
87 return (void *)((unsigned long)ptr | RADIX_TREE_INDIRECT_PTR);
88}
89
90static inline void *indirect_to_ptr(void *ptr)
91{
92 return (void *)((unsigned long)ptr & ~RADIX_TREE_INDIRECT_PTR);
93}
94
85static inline gfp_t root_gfp_mask(struct radix_tree_root *root) 95static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
86{ 96{
87 return root->gfp_mask & __GFP_BITS_MASK; 97 return root->gfp_mask & __GFP_BITS_MASK;
@@ -265,7 +275,7 @@ static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
265 return -ENOMEM; 275 return -ENOMEM;
266 276
267 /* Increase the height. */ 277 /* Increase the height. */
268 node->slots[0] = radix_tree_indirect_to_ptr(root->rnode); 278 node->slots[0] = indirect_to_ptr(root->rnode);
269 279
270 /* Propagate the aggregated tag info into the new root */ 280 /* Propagate the aggregated tag info into the new root */
271 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) { 281 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) {
@@ -276,7 +286,7 @@ static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
276 newheight = root->height+1; 286 newheight = root->height+1;
277 node->height = newheight; 287 node->height = newheight;
278 node->count = 1; 288 node->count = 1;
279 node = radix_tree_ptr_to_indirect(node); 289 node = ptr_to_indirect(node);
280 rcu_assign_pointer(root->rnode, node); 290 rcu_assign_pointer(root->rnode, node);
281 root->height = newheight; 291 root->height = newheight;
282 } while (height > root->height); 292 } while (height > root->height);
@@ -309,7 +319,7 @@ int radix_tree_insert(struct radix_tree_root *root,
309 return error; 319 return error;
310 } 320 }
311 321
312 slot = radix_tree_indirect_to_ptr(root->rnode); 322 slot = indirect_to_ptr(root->rnode);
313 323
314 height = root->height; 324 height = root->height;
315 shift = (height-1) * RADIX_TREE_MAP_SHIFT; 325 shift = (height-1) * RADIX_TREE_MAP_SHIFT;
@@ -325,8 +335,7 @@ int radix_tree_insert(struct radix_tree_root *root,
325 rcu_assign_pointer(node->slots[offset], slot); 335 rcu_assign_pointer(node->slots[offset], slot);
326 node->count++; 336 node->count++;
327 } else 337 } else
328 rcu_assign_pointer(root->rnode, 338 rcu_assign_pointer(root->rnode, ptr_to_indirect(slot));
329 radix_tree_ptr_to_indirect(slot));
330 } 339 }
331 340
332 /* Go a level down */ 341 /* Go a level down */
@@ -374,7 +383,7 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root,
374 return NULL; 383 return NULL;
375 return is_slot ? (void *)&root->rnode : node; 384 return is_slot ? (void *)&root->rnode : node;
376 } 385 }
377 node = radix_tree_indirect_to_ptr(node); 386 node = indirect_to_ptr(node);
378 387
379 height = node->height; 388 height = node->height;
380 if (index > radix_tree_maxindex(height)) 389 if (index > radix_tree_maxindex(height))
@@ -393,7 +402,7 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root,
393 height--; 402 height--;
394 } while (height > 0); 403 } while (height > 0);
395 404
396 return is_slot ? (void *)slot:node; 405 return is_slot ? (void *)slot : indirect_to_ptr(node);
397} 406}
398 407
399/** 408/**
@@ -455,7 +464,7 @@ void *radix_tree_tag_set(struct radix_tree_root *root,
455 height = root->height; 464 height = root->height;
456 BUG_ON(index > radix_tree_maxindex(height)); 465 BUG_ON(index > radix_tree_maxindex(height));
457 466
458 slot = radix_tree_indirect_to_ptr(root->rnode); 467 slot = indirect_to_ptr(root->rnode);
459 shift = (height - 1) * RADIX_TREE_MAP_SHIFT; 468 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
460 469
461 while (height > 0) { 470 while (height > 0) {
@@ -509,7 +518,7 @@ void *radix_tree_tag_clear(struct radix_tree_root *root,
509 518
510 shift = (height - 1) * RADIX_TREE_MAP_SHIFT; 519 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
511 pathp->node = NULL; 520 pathp->node = NULL;
512 slot = radix_tree_indirect_to_ptr(root->rnode); 521 slot = indirect_to_ptr(root->rnode);
513 522
514 while (height > 0) { 523 while (height > 0) {
515 int offset; 524 int offset;
@@ -579,7 +588,7 @@ int radix_tree_tag_get(struct radix_tree_root *root,
579 588
580 if (!radix_tree_is_indirect_ptr(node)) 589 if (!radix_tree_is_indirect_ptr(node))
581 return (index == 0); 590 return (index == 0);
582 node = radix_tree_indirect_to_ptr(node); 591 node = indirect_to_ptr(node);
583 592
584 height = node->height; 593 height = node->height;
585 if (index > radix_tree_maxindex(height)) 594 if (index > radix_tree_maxindex(height))
@@ -666,7 +675,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
666 } 675 }
667 676
668 shift = (height - 1) * RADIX_TREE_MAP_SHIFT; 677 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
669 slot = radix_tree_indirect_to_ptr(root->rnode); 678 slot = indirect_to_ptr(root->rnode);
670 679
671 /* 680 /*
672 * we fill the path from (root->height - 2) to 0, leaving the index at 681 * we fill the path from (root->height - 2) to 0, leaving the index at
@@ -897,7 +906,7 @@ radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
897 results[0] = node; 906 results[0] = node;
898 return 1; 907 return 1;
899 } 908 }
900 node = radix_tree_indirect_to_ptr(node); 909 node = indirect_to_ptr(node);
901 910
902 max_index = radix_tree_maxindex(node->height); 911 max_index = radix_tree_maxindex(node->height);
903 912
@@ -916,7 +925,8 @@ radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
916 slot = *(((void ***)results)[ret + i]); 925 slot = *(((void ***)results)[ret + i]);
917 if (!slot) 926 if (!slot)
918 continue; 927 continue;
919 results[ret + nr_found] = rcu_dereference_raw(slot); 928 results[ret + nr_found] =
929 indirect_to_ptr(rcu_dereference_raw(slot));
920 nr_found++; 930 nr_found++;
921 } 931 }
922 ret += nr_found; 932 ret += nr_found;
@@ -965,7 +975,7 @@ radix_tree_gang_lookup_slot(struct radix_tree_root *root, void ***results,
965 results[0] = (void **)&root->rnode; 975 results[0] = (void **)&root->rnode;
966 return 1; 976 return 1;
967 } 977 }
968 node = radix_tree_indirect_to_ptr(node); 978 node = indirect_to_ptr(node);
969 979
970 max_index = radix_tree_maxindex(node->height); 980 max_index = radix_tree_maxindex(node->height);
971 981
@@ -1090,7 +1100,7 @@ radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
1090 results[0] = node; 1100 results[0] = node;
1091 return 1; 1101 return 1;
1092 } 1102 }
1093 node = radix_tree_indirect_to_ptr(node); 1103 node = indirect_to_ptr(node);
1094 1104
1095 max_index = radix_tree_maxindex(node->height); 1105 max_index = radix_tree_maxindex(node->height);
1096 1106
@@ -1109,7 +1119,8 @@ radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
1109 slot = *(((void ***)results)[ret + i]); 1119 slot = *(((void ***)results)[ret + i]);
1110 if (!slot) 1120 if (!slot)
1111 continue; 1121 continue;
1112 results[ret + nr_found] = rcu_dereference_raw(slot); 1122 results[ret + nr_found] =
1123 indirect_to_ptr(rcu_dereference_raw(slot));
1113 nr_found++; 1124 nr_found++;
1114 } 1125 }
1115 ret += nr_found; 1126 ret += nr_found;
@@ -1159,7 +1170,7 @@ radix_tree_gang_lookup_tag_slot(struct radix_tree_root *root, void ***results,
1159 results[0] = (void **)&root->rnode; 1170 results[0] = (void **)&root->rnode;
1160 return 1; 1171 return 1;
1161 } 1172 }
1162 node = radix_tree_indirect_to_ptr(node); 1173 node = indirect_to_ptr(node);
1163 1174
1164 max_index = radix_tree_maxindex(node->height); 1175 max_index = radix_tree_maxindex(node->height);
1165 1176
@@ -1195,7 +1206,7 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1195 void *newptr; 1206 void *newptr;
1196 1207
1197 BUG_ON(!radix_tree_is_indirect_ptr(to_free)); 1208 BUG_ON(!radix_tree_is_indirect_ptr(to_free));
1198 to_free = radix_tree_indirect_to_ptr(to_free); 1209 to_free = indirect_to_ptr(to_free);
1199 1210
1200 /* 1211 /*
1201 * The candidate node has more than one child, or its child 1212 * The candidate node has more than one child, or its child
@@ -1208,16 +1219,39 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1208 1219
1209 /* 1220 /*
1210 * We don't need rcu_assign_pointer(), since we are simply 1221 * We don't need rcu_assign_pointer(), since we are simply
1211 * moving the node from one part of the tree to another. If 1222 * moving the node from one part of the tree to another: if it
1212 * it was safe to dereference the old pointer to it 1223 * was safe to dereference the old pointer to it
1213 * (to_free->slots[0]), it will be safe to dereference the new 1224 * (to_free->slots[0]), it will be safe to dereference the new
1214 * one (root->rnode). 1225 * one (root->rnode) as far as dependent read barriers go.
1215 */ 1226 */
1216 newptr = to_free->slots[0]; 1227 newptr = to_free->slots[0];
1217 if (root->height > 1) 1228 if (root->height > 1)
1218 newptr = radix_tree_ptr_to_indirect(newptr); 1229 newptr = ptr_to_indirect(newptr);
1219 root->rnode = newptr; 1230 root->rnode = newptr;
1220 root->height--; 1231 root->height--;
1232
1233 /*
1234 * We have a dilemma here. The node's slot[0] must not be
1235 * NULLed in case there are concurrent lookups expecting to
1236 * find the item. However if this was a bottom-level node,
1237 * then it may be subject to the slot pointer being visible
1238 * to callers dereferencing it. If item corresponding to
1239 * slot[0] is subsequently deleted, these callers would expect
1240 * their slot to become empty sooner or later.
1241 *
1242 * For example, lockless pagecache will look up a slot, deref
1243 * the page pointer, and if the page is 0 refcount it means it
1244 * was concurrently deleted from pagecache so try the deref
1245 * again. Fortunately there is already a requirement for logic
1246 * to retry the entire slot lookup -- the indirect pointer
1247 * problem (replacing direct root node with an indirect pointer
1248 * also results in a stale slot). So tag the slot as indirect
1249 * to force callers to retry.
1250 */
1251 if (root->height == 0)
1252 *((unsigned long *)&to_free->slots[0]) |=
1253 RADIX_TREE_INDIRECT_PTR;
1254
1221 radix_tree_node_free(to_free); 1255 radix_tree_node_free(to_free);
1222 } 1256 }
1223} 1257}
@@ -1254,7 +1288,7 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1254 root->rnode = NULL; 1288 root->rnode = NULL;
1255 goto out; 1289 goto out;
1256 } 1290 }
1257 slot = radix_tree_indirect_to_ptr(slot); 1291 slot = indirect_to_ptr(slot);
1258 1292
1259 shift = (height - 1) * RADIX_TREE_MAP_SHIFT; 1293 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
1260 pathp->node = NULL; 1294 pathp->node = NULL;
@@ -1296,8 +1330,7 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1296 radix_tree_node_free(to_free); 1330 radix_tree_node_free(to_free);
1297 1331
1298 if (pathp->node->count) { 1332 if (pathp->node->count) {
1299 if (pathp->node == 1333 if (pathp->node == indirect_to_ptr(root->rnode))
1300 radix_tree_indirect_to_ptr(root->rnode))
1301 radix_tree_shrink(root); 1334 radix_tree_shrink(root);
1302 goto out; 1335 goto out;
1303 } 1336 }
diff --git a/mm/filemap.c b/mm/filemap.c
index 75572b5f2374..6b9aee20f242 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -143,13 +143,18 @@ void __remove_from_page_cache(struct page *page)
143void remove_from_page_cache(struct page *page) 143void remove_from_page_cache(struct page *page)
144{ 144{
145 struct address_space *mapping = page->mapping; 145 struct address_space *mapping = page->mapping;
146 void (*freepage)(struct page *);
146 147
147 BUG_ON(!PageLocked(page)); 148 BUG_ON(!PageLocked(page));
148 149
150 freepage = mapping->a_ops->freepage;
149 spin_lock_irq(&mapping->tree_lock); 151 spin_lock_irq(&mapping->tree_lock);
150 __remove_from_page_cache(page); 152 __remove_from_page_cache(page);
151 spin_unlock_irq(&mapping->tree_lock); 153 spin_unlock_irq(&mapping->tree_lock);
152 mem_cgroup_uncharge_cache_page(page); 154 mem_cgroup_uncharge_cache_page(page);
155
156 if (freepage)
157 freepage(page);
153} 158}
154EXPORT_SYMBOL(remove_from_page_cache); 159EXPORT_SYMBOL(remove_from_page_cache);
155 160
@@ -644,7 +649,9 @@ repeat:
644 pagep = radix_tree_lookup_slot(&mapping->page_tree, offset); 649 pagep = radix_tree_lookup_slot(&mapping->page_tree, offset);
645 if (pagep) { 650 if (pagep) {
646 page = radix_tree_deref_slot(pagep); 651 page = radix_tree_deref_slot(pagep);
647 if (unlikely(!page || page == RADIX_TREE_RETRY)) 652 if (unlikely(!page))
653 goto out;
654 if (radix_tree_deref_retry(page))
648 goto repeat; 655 goto repeat;
649 656
650 if (!page_cache_get_speculative(page)) 657 if (!page_cache_get_speculative(page))
@@ -660,6 +667,7 @@ repeat:
660 goto repeat; 667 goto repeat;
661 } 668 }
662 } 669 }
670out:
663 rcu_read_unlock(); 671 rcu_read_unlock();
664 672
665 return page; 673 return page;
@@ -777,12 +785,11 @@ repeat:
777 page = radix_tree_deref_slot((void **)pages[i]); 785 page = radix_tree_deref_slot((void **)pages[i]);
778 if (unlikely(!page)) 786 if (unlikely(!page))
779 continue; 787 continue;
780 /* 788 if (radix_tree_deref_retry(page)) {
781 * this can only trigger if nr_found == 1, making livelock 789 if (ret)
782 * a non issue. 790 start = pages[ret-1]->index;
783 */
784 if (unlikely(page == RADIX_TREE_RETRY))
785 goto restart; 791 goto restart;
792 }
786 793
787 if (!page_cache_get_speculative(page)) 794 if (!page_cache_get_speculative(page))
788 goto repeat; 795 goto repeat;
@@ -830,11 +837,7 @@ repeat:
830 page = radix_tree_deref_slot((void **)pages[i]); 837 page = radix_tree_deref_slot((void **)pages[i]);
831 if (unlikely(!page)) 838 if (unlikely(!page))
832 continue; 839 continue;
833 /* 840 if (radix_tree_deref_retry(page))
834 * this can only trigger if nr_found == 1, making livelock
835 * a non issue.
836 */
837 if (unlikely(page == RADIX_TREE_RETRY))
838 goto restart; 841 goto restart;
839 842
840 if (page->mapping == NULL || page->index != index) 843 if (page->mapping == NULL || page->index != index)
@@ -887,11 +890,7 @@ repeat:
887 page = radix_tree_deref_slot((void **)pages[i]); 890 page = radix_tree_deref_slot((void **)pages[i]);
888 if (unlikely(!page)) 891 if (unlikely(!page))
889 continue; 892 continue;
890 /* 893 if (radix_tree_deref_retry(page))
891 * this can only trigger if nr_found == 1, making livelock
892 * a non issue.
893 */
894 if (unlikely(page == RADIX_TREE_RETRY))
895 goto restart; 894 goto restart;
896 895
897 if (!page_cache_get_speculative(page)) 896 if (!page_cache_get_speculative(page))
@@ -1029,6 +1028,9 @@ find_page:
1029 goto page_not_up_to_date; 1028 goto page_not_up_to_date;
1030 if (!trylock_page(page)) 1029 if (!trylock_page(page))
1031 goto page_not_up_to_date; 1030 goto page_not_up_to_date;
1031 /* Did it get truncated before we got the lock? */
1032 if (!page->mapping)
1033 goto page_not_up_to_date_locked;
1032 if (!mapping->a_ops->is_partially_uptodate(page, 1034 if (!mapping->a_ops->is_partially_uptodate(page,
1033 desc, offset)) 1035 desc, offset))
1034 goto page_not_up_to_date_locked; 1036 goto page_not_up_to_date_locked;
@@ -1563,8 +1565,10 @@ retry_find:
1563 goto no_cached_page; 1565 goto no_cached_page;
1564 } 1566 }
1565 1567
1566 if (!lock_page_or_retry(page, vma->vm_mm, vmf->flags)) 1568 if (!lock_page_or_retry(page, vma->vm_mm, vmf->flags)) {
1569 page_cache_release(page);
1567 return ret | VM_FAULT_RETRY; 1570 return ret | VM_FAULT_RETRY;
1571 }
1568 1572
1569 /* Did it get truncated? */ 1573 /* Did it get truncated? */
1570 if (unlikely(page->mapping != mapping)) { 1574 if (unlikely(page->mapping != mapping)) {
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index c4a3558589ab..85855240933d 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2738,7 +2738,8 @@ out_page_table_lock:
2738 unlock_page(pagecache_page); 2738 unlock_page(pagecache_page);
2739 put_page(pagecache_page); 2739 put_page(pagecache_page);
2740 } 2740 }
2741 unlock_page(page); 2741 if (page != pagecache_page)
2742 unlock_page(page);
2742 2743
2743out_mutex: 2744out_mutex:
2744 mutex_unlock(&hugetlb_instantiation_mutex); 2745 mutex_unlock(&hugetlb_instantiation_mutex);
diff --git a/mm/ksm.c b/mm/ksm.c
index 65ab5c7067d9..43bc893470b4 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1724,8 +1724,13 @@ static int ksm_memory_callback(struct notifier_block *self,
1724 /* 1724 /*
1725 * Keep it very simple for now: just lock out ksmd and 1725 * Keep it very simple for now: just lock out ksmd and
1726 * MADV_UNMERGEABLE while any memory is going offline. 1726 * MADV_UNMERGEABLE while any memory is going offline.
1727 * mutex_lock_nested() is necessary because lockdep was alarmed
1728 * that here we take ksm_thread_mutex inside notifier chain
1729 * mutex, and later take notifier chain mutex inside
1730 * ksm_thread_mutex to unlock it. But that's safe because both
1731 * are inside mem_hotplug_mutex.
1727 */ 1732 */
1728 mutex_lock(&ksm_thread_mutex); 1733 mutex_lock_nested(&ksm_thread_mutex, SINGLE_DEPTH_NESTING);
1729 break; 1734 break;
1730 1735
1731 case MEM_OFFLINE: 1736 case MEM_OFFLINE:
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9a99cfaf0a19..7a22b4129211 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -61,7 +61,14 @@ struct mem_cgroup *root_mem_cgroup __read_mostly;
61#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP 61#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
62/* Turned on only when memory cgroup is enabled && really_do_swap_account = 1 */ 62/* Turned on only when memory cgroup is enabled && really_do_swap_account = 1 */
63int do_swap_account __read_mostly; 63int do_swap_account __read_mostly;
64static int really_do_swap_account __initdata = 1; /* for remember boot option*/ 64
65/* for remember boot option*/
66#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP_ENABLED
67static int really_do_swap_account __initdata = 1;
68#else
69static int really_do_swap_account __initdata = 0;
70#endif
71
65#else 72#else
66#define do_swap_account (0) 73#define do_swap_account (0)
67#endif 74#endif
@@ -278,13 +285,14 @@ enum move_type {
278 285
279/* "mc" and its members are protected by cgroup_mutex */ 286/* "mc" and its members are protected by cgroup_mutex */
280static struct move_charge_struct { 287static struct move_charge_struct {
281 spinlock_t lock; /* for from, to, moving_task */ 288 spinlock_t lock; /* for from, to */
282 struct mem_cgroup *from; 289 struct mem_cgroup *from;
283 struct mem_cgroup *to; 290 struct mem_cgroup *to;
284 unsigned long precharge; 291 unsigned long precharge;
285 unsigned long moved_charge; 292 unsigned long moved_charge;
286 unsigned long moved_swap; 293 unsigned long moved_swap;
287 struct task_struct *moving_task; /* a task moving charges */ 294 struct task_struct *moving_task; /* a task moving charges */
295 struct mm_struct *mm;
288 wait_queue_head_t waitq; /* a waitq for other context */ 296 wait_queue_head_t waitq; /* a waitq for other context */
289} mc = { 297} mc = {
290 .lock = __SPIN_LOCK_UNLOCKED(mc.lock), 298 .lock = __SPIN_LOCK_UNLOCKED(mc.lock),
@@ -2152,7 +2160,7 @@ static void __mem_cgroup_move_account(struct page_cgroup *pc,
2152{ 2160{
2153 VM_BUG_ON(from == to); 2161 VM_BUG_ON(from == to);
2154 VM_BUG_ON(PageLRU(pc->page)); 2162 VM_BUG_ON(PageLRU(pc->page));
2155 VM_BUG_ON(!PageCgroupLocked(pc)); 2163 VM_BUG_ON(!page_is_cgroup_locked(pc));
2156 VM_BUG_ON(!PageCgroupUsed(pc)); 2164 VM_BUG_ON(!PageCgroupUsed(pc));
2157 VM_BUG_ON(pc->mem_cgroup != from); 2165 VM_BUG_ON(pc->mem_cgroup != from);
2158 2166
@@ -4208,15 +4216,17 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
4208 4216
4209 memset(mem, 0, size); 4217 memset(mem, 0, size);
4210 mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu); 4218 mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu);
4211 if (!mem->stat) { 4219 if (!mem->stat)
4212 if (size < PAGE_SIZE) 4220 goto out_free;
4213 kfree(mem);
4214 else
4215 vfree(mem);
4216 mem = NULL;
4217 }
4218 spin_lock_init(&mem->pcp_counter_lock); 4221 spin_lock_init(&mem->pcp_counter_lock);
4219 return mem; 4222 return mem;
4223
4224out_free:
4225 if (size < PAGE_SIZE)
4226 kfree(mem);
4227 else
4228 vfree(mem);
4229 return NULL;
4220} 4230}
4221 4231
4222/* 4232/*
@@ -4629,7 +4639,7 @@ static unsigned long mem_cgroup_count_precharge(struct mm_struct *mm)
4629 unsigned long precharge; 4639 unsigned long precharge;
4630 struct vm_area_struct *vma; 4640 struct vm_area_struct *vma;
4631 4641
4632 down_read(&mm->mmap_sem); 4642 /* We've already held the mmap_sem */
4633 for (vma = mm->mmap; vma; vma = vma->vm_next) { 4643 for (vma = mm->mmap; vma; vma = vma->vm_next) {
4634 struct mm_walk mem_cgroup_count_precharge_walk = { 4644 struct mm_walk mem_cgroup_count_precharge_walk = {
4635 .pmd_entry = mem_cgroup_count_precharge_pte_range, 4645 .pmd_entry = mem_cgroup_count_precharge_pte_range,
@@ -4641,7 +4651,6 @@ static unsigned long mem_cgroup_count_precharge(struct mm_struct *mm)
4641 walk_page_range(vma->vm_start, vma->vm_end, 4651 walk_page_range(vma->vm_start, vma->vm_end,
4642 &mem_cgroup_count_precharge_walk); 4652 &mem_cgroup_count_precharge_walk);
4643 } 4653 }
4644 up_read(&mm->mmap_sem);
4645 4654
4646 precharge = mc.precharge; 4655 precharge = mc.precharge;
4647 mc.precharge = 0; 4656 mc.precharge = 0;
@@ -4692,11 +4701,16 @@ static void mem_cgroup_clear_mc(void)
4692 4701
4693 mc.moved_swap = 0; 4702 mc.moved_swap = 0;
4694 } 4703 }
4704 if (mc.mm) {
4705 up_read(&mc.mm->mmap_sem);
4706 mmput(mc.mm);
4707 }
4695 spin_lock(&mc.lock); 4708 spin_lock(&mc.lock);
4696 mc.from = NULL; 4709 mc.from = NULL;
4697 mc.to = NULL; 4710 mc.to = NULL;
4698 mc.moving_task = NULL;
4699 spin_unlock(&mc.lock); 4711 spin_unlock(&mc.lock);
4712 mc.moving_task = NULL;
4713 mc.mm = NULL;
4700 mem_cgroup_end_move(from); 4714 mem_cgroup_end_move(from);
4701 memcg_oom_recover(from); 4715 memcg_oom_recover(from);
4702 memcg_oom_recover(to); 4716 memcg_oom_recover(to);
@@ -4722,12 +4736,21 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss,
4722 return 0; 4736 return 0;
4723 /* We move charges only when we move a owner of the mm */ 4737 /* We move charges only when we move a owner of the mm */
4724 if (mm->owner == p) { 4738 if (mm->owner == p) {
4739 /*
4740 * We do all the move charge works under one mmap_sem to
4741 * avoid deadlock with down_write(&mmap_sem)
4742 * -> try_charge() -> if (mc.moving_task) -> sleep.
4743 */
4744 down_read(&mm->mmap_sem);
4745
4725 VM_BUG_ON(mc.from); 4746 VM_BUG_ON(mc.from);
4726 VM_BUG_ON(mc.to); 4747 VM_BUG_ON(mc.to);
4727 VM_BUG_ON(mc.precharge); 4748 VM_BUG_ON(mc.precharge);
4728 VM_BUG_ON(mc.moved_charge); 4749 VM_BUG_ON(mc.moved_charge);
4729 VM_BUG_ON(mc.moved_swap); 4750 VM_BUG_ON(mc.moved_swap);
4730 VM_BUG_ON(mc.moving_task); 4751 VM_BUG_ON(mc.moving_task);
4752 VM_BUG_ON(mc.mm);
4753
4731 mem_cgroup_start_move(from); 4754 mem_cgroup_start_move(from);
4732 spin_lock(&mc.lock); 4755 spin_lock(&mc.lock);
4733 mc.from = from; 4756 mc.from = from;
@@ -4735,14 +4758,16 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss,
4735 mc.precharge = 0; 4758 mc.precharge = 0;
4736 mc.moved_charge = 0; 4759 mc.moved_charge = 0;
4737 mc.moved_swap = 0; 4760 mc.moved_swap = 0;
4738 mc.moving_task = current;
4739 spin_unlock(&mc.lock); 4761 spin_unlock(&mc.lock);
4762 mc.moving_task = current;
4763 mc.mm = mm;
4740 4764
4741 ret = mem_cgroup_precharge_mc(mm); 4765 ret = mem_cgroup_precharge_mc(mm);
4742 if (ret) 4766 if (ret)
4743 mem_cgroup_clear_mc(); 4767 mem_cgroup_clear_mc();
4744 } 4768 /* We call up_read() and mmput() in clear_mc(). */
4745 mmput(mm); 4769 } else
4770 mmput(mm);
4746 } 4771 }
4747 return ret; 4772 return ret;
4748} 4773}
@@ -4830,7 +4855,7 @@ static void mem_cgroup_move_charge(struct mm_struct *mm)
4830 struct vm_area_struct *vma; 4855 struct vm_area_struct *vma;
4831 4856
4832 lru_add_drain_all(); 4857 lru_add_drain_all();
4833 down_read(&mm->mmap_sem); 4858 /* We've already held the mmap_sem */
4834 for (vma = mm->mmap; vma; vma = vma->vm_next) { 4859 for (vma = mm->mmap; vma; vma = vma->vm_next) {
4835 int ret; 4860 int ret;
4836 struct mm_walk mem_cgroup_move_charge_walk = { 4861 struct mm_walk mem_cgroup_move_charge_walk = {
@@ -4849,7 +4874,6 @@ static void mem_cgroup_move_charge(struct mm_struct *mm)
4849 */ 4874 */
4850 break; 4875 break;
4851 } 4876 }
4852 up_read(&mm->mmap_sem);
4853} 4877}
4854 4878
4855static void mem_cgroup_move_task(struct cgroup_subsys *ss, 4879static void mem_cgroup_move_task(struct cgroup_subsys *ss,
@@ -4858,17 +4882,11 @@ static void mem_cgroup_move_task(struct cgroup_subsys *ss,
4858 struct task_struct *p, 4882 struct task_struct *p,
4859 bool threadgroup) 4883 bool threadgroup)
4860{ 4884{
4861 struct mm_struct *mm; 4885 if (!mc.mm)
4862
4863 if (!mc.to)
4864 /* no need to move charge */ 4886 /* no need to move charge */
4865 return; 4887 return;
4866 4888
4867 mm = get_task_mm(p); 4889 mem_cgroup_move_charge(mc.mm);
4868 if (mm) {
4869 mem_cgroup_move_charge(mm);
4870 mmput(mm);
4871 }
4872 mem_cgroup_clear_mc(); 4890 mem_cgroup_clear_mc();
4873} 4891}
4874#else /* !CONFIG_MMU */ 4892#else /* !CONFIG_MMU */
@@ -4909,10 +4927,20 @@ struct cgroup_subsys mem_cgroup_subsys = {
4909}; 4927};
4910 4928
4911#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP 4929#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
4930static int __init enable_swap_account(char *s)
4931{
4932 /* consider enabled if no parameter or 1 is given */
4933 if (!s || !strcmp(s, "1"))
4934 really_do_swap_account = 1;
4935 else if (!strcmp(s, "0"))
4936 really_do_swap_account = 0;
4937 return 1;
4938}
4939__setup("swapaccount", enable_swap_account);
4912 4940
4913static int __init disable_swap_account(char *s) 4941static int __init disable_swap_account(char *s)
4914{ 4942{
4915 really_do_swap_account = 0; 4943 enable_swap_account("0");
4916 return 1; 4944 return 1;
4917} 4945}
4918__setup("noswapaccount", disable_swap_account); 4946__setup("noswapaccount", disable_swap_account);
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 124324134ff6..46ab2c044b0e 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -51,6 +51,7 @@
51#include <linux/slab.h> 51#include <linux/slab.h>
52#include <linux/swapops.h> 52#include <linux/swapops.h>
53#include <linux/hugetlb.h> 53#include <linux/hugetlb.h>
54#include <linux/memory_hotplug.h>
54#include "internal.h" 55#include "internal.h"
55 56
56int sysctl_memory_failure_early_kill __read_mostly = 0; 57int sysctl_memory_failure_early_kill __read_mostly = 0;
@@ -1230,11 +1231,10 @@ static int get_any_page(struct page *p, unsigned long pfn, int flags)
1230 return 1; 1231 return 1;
1231 1232
1232 /* 1233 /*
1233 * The lock_system_sleep prevents a race with memory hotplug, 1234 * The lock_memory_hotplug prevents a race with memory hotplug.
1234 * because the isolation assumes there's only a single user.
1235 * This is a big hammer, a better would be nicer. 1235 * This is a big hammer, a better would be nicer.
1236 */ 1236 */
1237 lock_system_sleep(); 1237 lock_memory_hotplug();
1238 1238
1239 /* 1239 /*
1240 * Isolate the page, so that it doesn't get reallocated if it 1240 * Isolate the page, so that it doesn't get reallocated if it
@@ -1264,7 +1264,7 @@ static int get_any_page(struct page *p, unsigned long pfn, int flags)
1264 ret = 1; 1264 ret = 1;
1265 } 1265 }
1266 unset_migratetype_isolate(p); 1266 unset_migratetype_isolate(p);
1267 unlock_system_sleep(); 1267 unlock_memory_hotplug();
1268 return ret; 1268 return ret;
1269} 1269}
1270 1270
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 9260314a221e..2c6523af5473 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -34,6 +34,23 @@
34 34
35#include "internal.h" 35#include "internal.h"
36 36
37DEFINE_MUTEX(mem_hotplug_mutex);
38
39void lock_memory_hotplug(void)
40{
41 mutex_lock(&mem_hotplug_mutex);
42
43 /* for exclusive hibernation if CONFIG_HIBERNATION=y */
44 lock_system_sleep();
45}
46
47void unlock_memory_hotplug(void)
48{
49 unlock_system_sleep();
50 mutex_unlock(&mem_hotplug_mutex);
51}
52
53
37/* add this memory to iomem resource */ 54/* add this memory to iomem resource */
38static struct resource *register_memory_resource(u64 start, u64 size) 55static struct resource *register_memory_resource(u64 start, u64 size)
39{ 56{
@@ -493,7 +510,7 @@ int mem_online_node(int nid)
493 pg_data_t *pgdat; 510 pg_data_t *pgdat;
494 int ret; 511 int ret;
495 512
496 lock_system_sleep(); 513 lock_memory_hotplug();
497 pgdat = hotadd_new_pgdat(nid, 0); 514 pgdat = hotadd_new_pgdat(nid, 0);
498 if (pgdat) { 515 if (pgdat) {
499 ret = -ENOMEM; 516 ret = -ENOMEM;
@@ -504,7 +521,7 @@ int mem_online_node(int nid)
504 BUG_ON(ret); 521 BUG_ON(ret);
505 522
506out: 523out:
507 unlock_system_sleep(); 524 unlock_memory_hotplug();
508 return ret; 525 return ret;
509} 526}
510 527
@@ -516,7 +533,7 @@ int __ref add_memory(int nid, u64 start, u64 size)
516 struct resource *res; 533 struct resource *res;
517 int ret; 534 int ret;
518 535
519 lock_system_sleep(); 536 lock_memory_hotplug();
520 537
521 res = register_memory_resource(start, size); 538 res = register_memory_resource(start, size);
522 ret = -EEXIST; 539 ret = -EEXIST;
@@ -563,7 +580,7 @@ error:
563 release_memory_resource(res); 580 release_memory_resource(res);
564 581
565out: 582out:
566 unlock_system_sleep(); 583 unlock_memory_hotplug();
567 return ret; 584 return ret;
568} 585}
569EXPORT_SYMBOL_GPL(add_memory); 586EXPORT_SYMBOL_GPL(add_memory);
@@ -791,7 +808,7 @@ static int offline_pages(unsigned long start_pfn,
791 if (!test_pages_in_a_zone(start_pfn, end_pfn)) 808 if (!test_pages_in_a_zone(start_pfn, end_pfn))
792 return -EINVAL; 809 return -EINVAL;
793 810
794 lock_system_sleep(); 811 lock_memory_hotplug();
795 812
796 zone = page_zone(pfn_to_page(start_pfn)); 813 zone = page_zone(pfn_to_page(start_pfn));
797 node = zone_to_nid(zone); 814 node = zone_to_nid(zone);
@@ -880,7 +897,7 @@ repeat:
880 writeback_set_ratelimit(); 897 writeback_set_ratelimit();
881 898
882 memory_notify(MEM_OFFLINE, &arg); 899 memory_notify(MEM_OFFLINE, &arg);
883 unlock_system_sleep(); 900 unlock_memory_hotplug();
884 return 0; 901 return 0;
885 902
886failed_removal: 903failed_removal:
@@ -891,7 +908,7 @@ failed_removal:
891 undo_isolate_page_range(start_pfn, end_pfn); 908 undo_isolate_page_range(start_pfn, end_pfn);
892 909
893out: 910out:
894 unlock_system_sleep(); 911 unlock_memory_hotplug();
895 return ret; 912 return ret;
896} 913}
897 914
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 4a57f135b76e..11ff260fb282 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1307,15 +1307,18 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
1307 goto out; 1307 goto out;
1308 1308
1309 /* Find the mm_struct */ 1309 /* Find the mm_struct */
1310 rcu_read_lock();
1310 read_lock(&tasklist_lock); 1311 read_lock(&tasklist_lock);
1311 task = pid ? find_task_by_vpid(pid) : current; 1312 task = pid ? find_task_by_vpid(pid) : current;
1312 if (!task) { 1313 if (!task) {
1313 read_unlock(&tasklist_lock); 1314 read_unlock(&tasklist_lock);
1315 rcu_read_unlock();
1314 err = -ESRCH; 1316 err = -ESRCH;
1315 goto out; 1317 goto out;
1316 } 1318 }
1317 mm = get_task_mm(task); 1319 mm = get_task_mm(task);
1318 read_unlock(&tasklist_lock); 1320 read_unlock(&tasklist_lock);
1321 rcu_read_unlock();
1319 1322
1320 err = -EINVAL; 1323 err = -EINVAL;
1321 if (!mm) 1324 if (!mm)
diff --git a/mm/mmap.c b/mm/mmap.c
index b179abb1474a..50a4aa0255a0 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2462,6 +2462,7 @@ int install_special_mapping(struct mm_struct *mm,
2462 unsigned long addr, unsigned long len, 2462 unsigned long addr, unsigned long len,
2463 unsigned long vm_flags, struct page **pages) 2463 unsigned long vm_flags, struct page **pages)
2464{ 2464{
2465 int ret;
2465 struct vm_area_struct *vma; 2466 struct vm_area_struct *vma;
2466 2467
2467 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); 2468 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
@@ -2479,16 +2480,23 @@ int install_special_mapping(struct mm_struct *mm,
2479 vma->vm_ops = &special_mapping_vmops; 2480 vma->vm_ops = &special_mapping_vmops;
2480 vma->vm_private_data = pages; 2481 vma->vm_private_data = pages;
2481 2482
2482 if (unlikely(insert_vm_struct(mm, vma))) { 2483 ret = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
2483 kmem_cache_free(vm_area_cachep, vma); 2484 if (ret)
2484 return -ENOMEM; 2485 goto out;
2485 } 2486
2487 ret = insert_vm_struct(mm, vma);
2488 if (ret)
2489 goto out;
2486 2490
2487 mm->total_vm += len >> PAGE_SHIFT; 2491 mm->total_vm += len >> PAGE_SHIFT;
2488 2492
2489 perf_event_mmap(vma); 2493 perf_event_mmap(vma);
2490 2494
2491 return 0; 2495 return 0;
2496
2497out:
2498 kmem_cache_free(vm_area_cachep, vma);
2499 return ret;
2492} 2500}
2493 2501
2494static DEFINE_MUTEX(mm_all_locks_mutex); 2502static DEFINE_MUTEX(mm_all_locks_mutex);
diff --git a/mm/mprotect.c b/mm/mprotect.c
index 2d1bf7cf8851..4c5133873097 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -211,6 +211,7 @@ success:
211 mmu_notifier_invalidate_range_end(mm, start, end); 211 mmu_notifier_invalidate_range_end(mm, start, end);
212 vm_stat_account(mm, oldflags, vma->vm_file, -nrpages); 212 vm_stat_account(mm, oldflags, vma->vm_file, -nrpages);
213 vm_stat_account(mm, newflags, vma->vm_file, nrpages); 213 vm_stat_account(mm, newflags, vma->vm_file, nrpages);
214 perf_event_mmap(vma);
214 return 0; 215 return 0;
215 216
216fail: 217fail:
@@ -299,7 +300,6 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
299 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); 300 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
300 if (error) 301 if (error)
301 goto out; 302 goto out;
302 perf_event_mmap(vma);
303 nstart = tmp; 303 nstart = tmp;
304 304
305 if (nstart < prev->vm_end) 305 if (nstart < prev->vm_end)
diff --git a/mm/nommu.c b/mm/nommu.c
index 3613517c7592..27a9ac588516 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1717,6 +1717,7 @@ void exit_mmap(struct mm_struct *mm)
1717 mm->mmap = vma->vm_next; 1717 mm->mmap = vma->vm_next;
1718 delete_vma_from_mm(vma); 1718 delete_vma_from_mm(vma);
1719 delete_vma(mm, vma); 1719 delete_vma(mm, vma);
1720 cond_resched();
1720 } 1721 }
1721 1722
1722 kleave(""); 1723 kleave("");
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index f823ee192e94..826ba6922e84 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -104,19 +104,24 @@ gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
104 * only be modified with pm_mutex held, unless the suspend/hibernate code is 104 * only be modified with pm_mutex held, unless the suspend/hibernate code is
105 * guaranteed not to run in parallel with that modification). 105 * guaranteed not to run in parallel with that modification).
106 */ 106 */
107void set_gfp_allowed_mask(gfp_t mask) 107
108static gfp_t saved_gfp_mask;
109
110void pm_restore_gfp_mask(void)
108{ 111{
109 WARN_ON(!mutex_is_locked(&pm_mutex)); 112 WARN_ON(!mutex_is_locked(&pm_mutex));
110 gfp_allowed_mask = mask; 113 if (saved_gfp_mask) {
114 gfp_allowed_mask = saved_gfp_mask;
115 saved_gfp_mask = 0;
116 }
111} 117}
112 118
113gfp_t clear_gfp_allowed_mask(gfp_t mask) 119void pm_restrict_gfp_mask(void)
114{ 120{
115 gfp_t ret = gfp_allowed_mask;
116
117 WARN_ON(!mutex_is_locked(&pm_mutex)); 121 WARN_ON(!mutex_is_locked(&pm_mutex));
118 gfp_allowed_mask &= ~mask; 122 WARN_ON(saved_gfp_mask);
119 return ret; 123 saved_gfp_mask = gfp_allowed_mask;
124 gfp_allowed_mask &= ~GFP_IOFS;
120} 125}
121#endif /* CONFIG_PM_SLEEP */ 126#endif /* CONFIG_PM_SLEEP */
122 127
@@ -3008,14 +3013,6 @@ static __init_refok int __build_all_zonelists(void *data)
3008 build_zonelist_cache(pgdat); 3013 build_zonelist_cache(pgdat);
3009 } 3014 }
3010 3015
3011#ifdef CONFIG_MEMORY_HOTPLUG
3012 /* Setup real pagesets for the new zone */
3013 if (data) {
3014 struct zone *zone = data;
3015 setup_zone_pageset(zone);
3016 }
3017#endif
3018
3019 /* 3016 /*
3020 * Initialize the boot_pagesets that are going to be used 3017 * Initialize the boot_pagesets that are going to be used
3021 * for bootstrapping processors. The real pagesets for 3018 * for bootstrapping processors. The real pagesets for
@@ -3064,7 +3061,11 @@ void build_all_zonelists(void *data)
3064 } else { 3061 } else {
3065 /* we have to stop all cpus to guarantee there is no user 3062 /* we have to stop all cpus to guarantee there is no user
3066 of zonelist */ 3063 of zonelist */
3067 stop_machine(__build_all_zonelists, data, NULL); 3064#ifdef CONFIG_MEMORY_HOTPLUG
3065 if (data)
3066 setup_zone_pageset((struct zone *)data);
3067#endif
3068 stop_machine(__build_all_zonelists, NULL, NULL);
3068 /* cpuset refresh routine should be here */ 3069 /* cpuset refresh routine should be here */
3069 } 3070 }
3070 vm_total_pages = nr_free_pagecache_pages(); 3071 vm_total_pages = nr_free_pagecache_pages();
diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index 8b1a2ce21ee5..38cc58b8b2b0 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -139,7 +139,6 @@ int walk_page_range(unsigned long addr, unsigned long end,
139 pgd_t *pgd; 139 pgd_t *pgd;
140 unsigned long next; 140 unsigned long next;
141 int err = 0; 141 int err = 0;
142 struct vm_area_struct *vma;
143 142
144 if (addr >= end) 143 if (addr >= end)
145 return err; 144 return err;
@@ -149,15 +148,17 @@ int walk_page_range(unsigned long addr, unsigned long end,
149 148
150 pgd = pgd_offset(walk->mm, addr); 149 pgd = pgd_offset(walk->mm, addr);
151 do { 150 do {
151 struct vm_area_struct *uninitialized_var(vma);
152
152 next = pgd_addr_end(addr, end); 153 next = pgd_addr_end(addr, end);
153 154
155#ifdef CONFIG_HUGETLB_PAGE
154 /* 156 /*
155 * handle hugetlb vma individually because pagetable walk for 157 * handle hugetlb vma individually because pagetable walk for
156 * the hugetlb page is dependent on the architecture and 158 * the hugetlb page is dependent on the architecture and
157 * we can't handled it in the same manner as non-huge pages. 159 * we can't handled it in the same manner as non-huge pages.
158 */ 160 */
159 vma = find_vma(walk->mm, addr); 161 vma = find_vma(walk->mm, addr);
160#ifdef CONFIG_HUGETLB_PAGE
161 if (vma && is_vm_hugetlb_page(vma)) { 162 if (vma && is_vm_hugetlb_page(vma)) {
162 if (vma->vm_end < next) 163 if (vma->vm_end < next)
163 next = vma->vm_end; 164 next = vma->vm_end;
diff --git a/mm/slub.c b/mm/slub.c
index 8fd5401bb071..bec0e355fbad 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3273,9 +3273,9 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
3273 kfree(n); 3273 kfree(n);
3274 kfree(s); 3274 kfree(s);
3275 } 3275 }
3276err:
3276 up_write(&slub_lock); 3277 up_write(&slub_lock);
3277 3278
3278err:
3279 if (flags & SLAB_PANIC) 3279 if (flags & SLAB_PANIC)
3280 panic("Cannot create slabcache %s\n", name); 3280 panic("Cannot create slabcache %s\n", name);
3281 else 3281 else
@@ -3401,13 +3401,13 @@ static int validate_slab(struct kmem_cache *s, struct page *page,
3401 3401
3402 for_each_free_object(p, s, page->freelist) { 3402 for_each_free_object(p, s, page->freelist) {
3403 set_bit(slab_index(p, s, addr), map); 3403 set_bit(slab_index(p, s, addr), map);
3404 if (!check_object(s, page, p, 0)) 3404 if (!check_object(s, page, p, SLUB_RED_INACTIVE))
3405 return 0; 3405 return 0;
3406 } 3406 }
3407 3407
3408 for_each_object(p, s, addr, page->objects) 3408 for_each_object(p, s, addr, page->objects)
3409 if (!test_bit(slab_index(p, s, addr), map)) 3409 if (!test_bit(slab_index(p, s, addr), map))
3410 if (!check_object(s, page, p, 1)) 3410 if (!check_object(s, page, p, SLUB_RED_ACTIVE))
3411 return 0; 3411 return 0;
3412 return 1; 3412 return 1;
3413} 3413}
@@ -3862,6 +3862,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
3862 x += sprintf(buf + x, " N%d=%lu", 3862 x += sprintf(buf + x, " N%d=%lu",
3863 node, nodes[node]); 3863 node, nodes[node]);
3864#endif 3864#endif
3865 up_read(&slub_lock);
3865 kfree(nodes); 3866 kfree(nodes);
3866 return x + sprintf(buf + x, "\n"); 3867 return x + sprintf(buf + x, "\n");
3867} 3868}
diff --git a/mm/truncate.c b/mm/truncate.c
index ba887bff48c5..3c2d5ddfa0d4 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -390,6 +390,10 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)
390 __remove_from_page_cache(page); 390 __remove_from_page_cache(page);
391 spin_unlock_irq(&mapping->tree_lock); 391 spin_unlock_irq(&mapping->tree_lock);
392 mem_cgroup_uncharge_cache_page(page); 392 mem_cgroup_uncharge_cache_page(page);
393
394 if (mapping->a_ops->freepage)
395 mapping->a_ops->freepage(page);
396
393 page_cache_release(page); /* pagecache ref */ 397 page_cache_release(page); /* pagecache ref */
394 return 1; 398 return 1;
395failed: 399failed:
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index a3d66b3dc5cb..eb5cc7d00c5a 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -31,8 +31,6 @@
31#include <asm/tlbflush.h> 31#include <asm/tlbflush.h>
32#include <asm/shmparam.h> 32#include <asm/shmparam.h>
33 33
34bool vmap_lazy_unmap __read_mostly = true;
35
36/*** Page table manipulation functions ***/ 34/*** Page table manipulation functions ***/
37 35
38static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end) 36static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
@@ -503,9 +501,6 @@ static unsigned long lazy_max_pages(void)
503{ 501{
504 unsigned int log; 502 unsigned int log;
505 503
506 if (!vmap_lazy_unmap)
507 return 0;
508
509 log = fls(num_online_cpus()); 504 log = fls(num_online_cpus());
510 505
511 return log * (32UL * 1024 * 1024 / PAGE_SIZE); 506 return log * (32UL * 1024 * 1024 / PAGE_SIZE);
@@ -566,7 +561,6 @@ static void __purge_vmap_area_lazy(unsigned long *start, unsigned long *end,
566 if (va->va_end > *end) 561 if (va->va_end > *end)
567 *end = va->va_end; 562 *end = va->va_end;
568 nr += (va->va_end - va->va_start) >> PAGE_SHIFT; 563 nr += (va->va_end - va->va_start) >> PAGE_SHIFT;
569 unmap_vmap_area(va);
570 list_add_tail(&va->purge_list, &valist); 564 list_add_tail(&va->purge_list, &valist);
571 va->flags |= VM_LAZY_FREEING; 565 va->flags |= VM_LAZY_FREEING;
572 va->flags &= ~VM_LAZY_FREE; 566 va->flags &= ~VM_LAZY_FREE;
@@ -611,10 +605,11 @@ static void purge_vmap_area_lazy(void)
611} 605}
612 606
613/* 607/*
614 * Free and unmap a vmap area, caller ensuring flush_cache_vunmap had been 608 * Free a vmap area, caller ensuring that the area has been unmapped
615 * called for the correct range previously. 609 * and flush_cache_vunmap had been called for the correct range
610 * previously.
616 */ 611 */
617static void free_unmap_vmap_area_noflush(struct vmap_area *va) 612static void free_vmap_area_noflush(struct vmap_area *va)
618{ 613{
619 va->flags |= VM_LAZY_FREE; 614 va->flags |= VM_LAZY_FREE;
620 atomic_add((va->va_end - va->va_start) >> PAGE_SHIFT, &vmap_lazy_nr); 615 atomic_add((va->va_end - va->va_start) >> PAGE_SHIFT, &vmap_lazy_nr);
@@ -623,6 +618,16 @@ static void free_unmap_vmap_area_noflush(struct vmap_area *va)
623} 618}
624 619
625/* 620/*
621 * Free and unmap a vmap area, caller ensuring flush_cache_vunmap had been
622 * called for the correct range previously.
623 */
624static void free_unmap_vmap_area_noflush(struct vmap_area *va)
625{
626 unmap_vmap_area(va);
627 free_vmap_area_noflush(va);
628}
629
630/*
626 * Free and unmap a vmap area 631 * Free and unmap a vmap area
627 */ 632 */
628static void free_unmap_vmap_area(struct vmap_area *va) 633static void free_unmap_vmap_area(struct vmap_area *va)
@@ -798,7 +803,7 @@ static void free_vmap_block(struct vmap_block *vb)
798 spin_unlock(&vmap_block_tree_lock); 803 spin_unlock(&vmap_block_tree_lock);
799 BUG_ON(tmp != vb); 804 BUG_ON(tmp != vb);
800 805
801 free_unmap_vmap_area_noflush(vb->va); 806 free_vmap_area_noflush(vb->va);
802 call_rcu(&vb->rcu_head, rcu_free_vb); 807 call_rcu(&vb->rcu_head, rcu_free_vb);
803} 808}
804 809
@@ -936,6 +941,8 @@ static void vb_free(const void *addr, unsigned long size)
936 rcu_read_unlock(); 941 rcu_read_unlock();
937 BUG_ON(!vb); 942 BUG_ON(!vb);
938 943
944 vunmap_page_range((unsigned long)addr, (unsigned long)addr + size);
945
939 spin_lock(&vb->lock); 946 spin_lock(&vb->lock);
940 BUG_ON(bitmap_allocate_region(vb->dirty_map, offset >> PAGE_SHIFT, order)); 947 BUG_ON(bitmap_allocate_region(vb->dirty_map, offset >> PAGE_SHIFT, order));
941 948
@@ -988,7 +995,6 @@ void vm_unmap_aliases(void)
988 995
989 s = vb->va->va_start + (i << PAGE_SHIFT); 996 s = vb->va->va_start + (i << PAGE_SHIFT);
990 e = vb->va->va_start + (j << PAGE_SHIFT); 997 e = vb->va->va_start + (j << PAGE_SHIFT);
991 vunmap_page_range(s, e);
992 flush = 1; 998 flush = 1;
993 999
994 if (s < start) 1000 if (s < start)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index b8a6fdc21312..9ca587c69274 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -494,9 +494,16 @@ static int __remove_mapping(struct address_space *mapping, struct page *page)
494 spin_unlock_irq(&mapping->tree_lock); 494 spin_unlock_irq(&mapping->tree_lock);
495 swapcache_free(swap, page); 495 swapcache_free(swap, page);
496 } else { 496 } else {
497 void (*freepage)(struct page *);
498
499 freepage = mapping->a_ops->freepage;
500
497 __remove_from_page_cache(page); 501 __remove_from_page_cache(page);
498 spin_unlock_irq(&mapping->tree_lock); 502 spin_unlock_irq(&mapping->tree_lock);
499 mem_cgroup_uncharge_cache_page(page); 503 mem_cgroup_uncharge_cache_page(page);
504
505 if (freepage != NULL)
506 freepage(page);
500 } 507 }
501 508
502 return 1; 509 return 1;
@@ -913,7 +920,7 @@ keep_lumpy:
913 * back off and wait for congestion to clear because further reclaim 920 * back off and wait for congestion to clear because further reclaim
914 * will encounter the same problem 921 * will encounter the same problem
915 */ 922 */
916 if (nr_dirty == nr_congested) 923 if (nr_dirty == nr_congested && nr_dirty != 0)
917 zone_set_flag(zone, ZONE_CONGESTED); 924 zone_set_flag(zone, ZONE_CONGESTED);
918 925
919 free_page_list(&free_pages); 926 free_page_list(&free_pages);
diff --git a/mm/vmstat.c b/mm/vmstat.c
index cd2e42be7b68..8f62f17ee1c7 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -750,8 +750,6 @@ static const char * const vmstat_text[] = {
750 "nr_shmem", 750 "nr_shmem",
751 "nr_dirtied", 751 "nr_dirtied",
752 "nr_written", 752 "nr_written",
753 "nr_dirty_threshold",
754 "nr_dirty_background_threshold",
755 753
756#ifdef CONFIG_NUMA 754#ifdef CONFIG_NUMA
757 "numa_hit", 755 "numa_hit",
@@ -761,6 +759,8 @@ static const char * const vmstat_text[] = {
761 "numa_local", 759 "numa_local",
762 "numa_other", 760 "numa_other",
763#endif 761#endif
762 "nr_dirty_threshold",
763 "nr_dirty_background_threshold",
764 764
765#ifdef CONFIG_VM_EVENT_COUNTERS 765#ifdef CONFIG_VM_EVENT_COUNTERS
766 "pgpgin", 766 "pgpgin",
@@ -949,7 +949,7 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
949 v[PGPGIN] /= 2; /* sectors -> kbytes */ 949 v[PGPGIN] /= 2; /* sectors -> kbytes */
950 v[PGPGOUT] /= 2; 950 v[PGPGOUT] /= 2;
951#endif 951#endif
952 return m->private + *pos; 952 return (unsigned long *)m->private + *pos;
953} 953}
954 954
955static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos) 955static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos)
diff --git a/net/atm/atm_sysfs.c b/net/atm/atm_sysfs.c
index 799c631f0fed..f7fa67c78766 100644
--- a/net/atm/atm_sysfs.c
+++ b/net/atm/atm_sysfs.c
@@ -143,12 +143,13 @@ static struct class atm_class = {
143 .dev_uevent = atm_uevent, 143 .dev_uevent = atm_uevent,
144}; 144};
145 145
146int atm_register_sysfs(struct atm_dev *adev) 146int atm_register_sysfs(struct atm_dev *adev, struct device *parent)
147{ 147{
148 struct device *cdev = &adev->class_dev; 148 struct device *cdev = &adev->class_dev;
149 int i, j, err; 149 int i, j, err;
150 150
151 cdev->class = &atm_class; 151 cdev->class = &atm_class;
152 cdev->parent = parent;
152 dev_set_drvdata(cdev, adev); 153 dev_set_drvdata(cdev, adev);
153 154
154 dev_set_name(cdev, "%s%d", adev->type, adev->number); 155 dev_set_name(cdev, "%s%d", adev->type, adev->number);
diff --git a/net/atm/resources.c b/net/atm/resources.c
index d29e58261511..23f45ce6f351 100644
--- a/net/atm/resources.c
+++ b/net/atm/resources.c
@@ -74,8 +74,9 @@ struct atm_dev *atm_dev_lookup(int number)
74} 74}
75EXPORT_SYMBOL(atm_dev_lookup); 75EXPORT_SYMBOL(atm_dev_lookup);
76 76
77struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops, 77struct atm_dev *atm_dev_register(const char *type, struct device *parent,
78 int number, unsigned long *flags) 78 const struct atmdev_ops *ops, int number,
79 unsigned long *flags)
79{ 80{
80 struct atm_dev *dev, *inuse; 81 struct atm_dev *dev, *inuse;
81 82
@@ -115,7 +116,7 @@ struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
115 goto out_fail; 116 goto out_fail;
116 } 117 }
117 118
118 if (atm_register_sysfs(dev) < 0) { 119 if (atm_register_sysfs(dev, parent) < 0) {
119 pr_err("atm_register_sysfs failed for dev %s\n", type); 120 pr_err("atm_register_sysfs failed for dev %s\n", type);
120 atm_proc_dev_deregister(dev); 121 atm_proc_dev_deregister(dev);
121 goto out_fail; 122 goto out_fail;
diff --git a/net/atm/resources.h b/net/atm/resources.h
index 126fb1840dfb..521431e30507 100644
--- a/net/atm/resources.h
+++ b/net/atm/resources.h
@@ -42,6 +42,6 @@ static inline void atm_proc_dev_deregister(struct atm_dev *dev)
42 42
43#endif /* CONFIG_PROC_FS */ 43#endif /* CONFIG_PROC_FS */
44 44
45int atm_register_sysfs(struct atm_dev *adev); 45int atm_register_sysfs(struct atm_dev *adev, struct device *parent);
46void atm_unregister_sysfs(struct atm_dev *adev); 46void atm_unregister_sysfs(struct atm_dev *adev);
47#endif 47#endif
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index 26eaebf4aaa9..bb86d2932394 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -1392,6 +1392,7 @@ static int ax25_getname(struct socket *sock, struct sockaddr *uaddr,
1392 ax25_cb *ax25; 1392 ax25_cb *ax25;
1393 int err = 0; 1393 int err = 0;
1394 1394
1395 memset(fsa, 0, sizeof(fsa));
1395 lock_sock(sk); 1396 lock_sock(sk);
1396 ax25 = ax25_sk(sk); 1397 ax25 = ax25_sk(sk);
1397 1398
@@ -1403,7 +1404,6 @@ static int ax25_getname(struct socket *sock, struct sockaddr *uaddr,
1403 1404
1404 fsa->fsa_ax25.sax25_family = AF_AX25; 1405 fsa->fsa_ax25.sax25_family = AF_AX25;
1405 fsa->fsa_ax25.sax25_call = ax25->dest_addr; 1406 fsa->fsa_ax25.sax25_call = ax25->dest_addr;
1406 fsa->fsa_ax25.sax25_ndigis = 0;
1407 1407
1408 if (ax25->digipeat != NULL) { 1408 if (ax25->digipeat != NULL) {
1409 ndigi = ax25->digipeat->ndigi; 1409 ndigi = ax25->digipeat->ndigi;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index bfef5bae0b3a..84093b0000b9 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1175,6 +1175,12 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff
1175 hci_send_cmd(hdev, 1175 hci_send_cmd(hdev,
1176 HCI_OP_READ_REMOTE_EXT_FEATURES, 1176 HCI_OP_READ_REMOTE_EXT_FEATURES,
1177 sizeof(cp), &cp); 1177 sizeof(cp), &cp);
1178 } else if (!ev->status && conn->out &&
1179 conn->sec_level == BT_SECURITY_HIGH) {
1180 struct hci_cp_auth_requested cp;
1181 cp.handle = ev->handle;
1182 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED,
1183 sizeof(cp), &cp);
1178 } else { 1184 } else {
1179 conn->state = BT_CONNECTED; 1185 conn->state = BT_CONNECTED;
1180 hci_proto_connect_cfm(conn, ev->status); 1186 hci_proto_connect_cfm(conn, ev->status);
diff --git a/net/bluetooth/hidp/Kconfig b/net/bluetooth/hidp/Kconfig
index 98fdfa1fbddd..86a91543172a 100644
--- a/net/bluetooth/hidp/Kconfig
+++ b/net/bluetooth/hidp/Kconfig
@@ -1,6 +1,6 @@
1config BT_HIDP 1config BT_HIDP
2 tristate "HIDP protocol support" 2 tristate "HIDP protocol support"
3 depends on BT && BT_L2CAP && INPUT 3 depends on BT && BT_L2CAP && INPUT && HID_SUPPORT
4 select HID 4 select HID
5 help 5 help
6 HIDP (Human Interface Device Protocol) is a transport layer 6 HIDP (Human Interface Device Protocol) is a transport layer
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index daa7a988d9a6..cd8f6ea03841 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -2421,11 +2421,11 @@ static inline int l2cap_get_conf_opt(void **ptr, int *type, int *olen, unsigned
2421 break; 2421 break;
2422 2422
2423 case 2: 2423 case 2:
2424 *val = __le16_to_cpu(*((__le16 *) opt->val)); 2424 *val = get_unaligned_le16(opt->val);
2425 break; 2425 break;
2426 2426
2427 case 4: 2427 case 4:
2428 *val = __le32_to_cpu(*((__le32 *) opt->val)); 2428 *val = get_unaligned_le32(opt->val);
2429 break; 2429 break;
2430 2430
2431 default: 2431 default:
@@ -2452,11 +2452,11 @@ static void l2cap_add_conf_opt(void **ptr, u8 type, u8 len, unsigned long val)
2452 break; 2452 break;
2453 2453
2454 case 2: 2454 case 2:
2455 *((__le16 *) opt->val) = cpu_to_le16(val); 2455 put_unaligned_le16(val, opt->val);
2456 break; 2456 break;
2457 2457
2458 case 4: 2458 case 4:
2459 *((__le32 *) opt->val) = cpu_to_le32(val); 2459 put_unaligned_le32(val, opt->val);
2460 break; 2460 break;
2461 2461
2462 default: 2462 default:
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 39a5d87e33b4..fa642aa652bd 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -79,7 +79,10 @@ static void rfcomm_make_uih(struct sk_buff *skb, u8 addr);
79 79
80static void rfcomm_process_connect(struct rfcomm_session *s); 80static void rfcomm_process_connect(struct rfcomm_session *s);
81 81
82static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, bdaddr_t *dst, int *err); 82static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src,
83 bdaddr_t *dst,
84 u8 sec_level,
85 int *err);
83static struct rfcomm_session *rfcomm_session_get(bdaddr_t *src, bdaddr_t *dst); 86static struct rfcomm_session *rfcomm_session_get(bdaddr_t *src, bdaddr_t *dst);
84static void rfcomm_session_del(struct rfcomm_session *s); 87static void rfcomm_session_del(struct rfcomm_session *s);
85 88
@@ -401,7 +404,7 @@ static int __rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst,
401 404
402 s = rfcomm_session_get(src, dst); 405 s = rfcomm_session_get(src, dst);
403 if (!s) { 406 if (!s) {
404 s = rfcomm_session_create(src, dst, &err); 407 s = rfcomm_session_create(src, dst, d->sec_level, &err);
405 if (!s) 408 if (!s)
406 return err; 409 return err;
407 } 410 }
@@ -679,7 +682,10 @@ static void rfcomm_session_close(struct rfcomm_session *s, int err)
679 rfcomm_session_put(s); 682 rfcomm_session_put(s);
680} 683}
681 684
682static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, bdaddr_t *dst, int *err) 685static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src,
686 bdaddr_t *dst,
687 u8 sec_level,
688 int *err)
683{ 689{
684 struct rfcomm_session *s = NULL; 690 struct rfcomm_session *s = NULL;
685 struct sockaddr_l2 addr; 691 struct sockaddr_l2 addr;
@@ -704,6 +710,7 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, bdaddr_t *dst
704 sk = sock->sk; 710 sk = sock->sk;
705 lock_sock(sk); 711 lock_sock(sk);
706 l2cap_pi(sk)->imtu = l2cap_mtu; 712 l2cap_pi(sk)->imtu = l2cap_mtu;
713 l2cap_pi(sk)->sec_level = sec_level;
707 if (l2cap_ertm) 714 if (l2cap_ertm)
708 l2cap_pi(sk)->mode = L2CAP_MODE_ERTM; 715 l2cap_pi(sk)->mode = L2CAP_MODE_ERTM;
709 release_sock(sk); 716 release_sock(sk);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index d0927d1fdada..66b9e5c0523a 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -882,7 +882,7 @@ static int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type)
882 int lm = 0; 882 int lm = 0;
883 883
884 if (type != SCO_LINK && type != ESCO_LINK) 884 if (type != SCO_LINK && type != ESCO_LINK)
885 return 0; 885 return -EINVAL;
886 886
887 BT_DBG("hdev %s, bdaddr %s", hdev->name, batostr(bdaddr)); 887 BT_DBG("hdev %s, bdaddr %s", hdev->name, batostr(bdaddr));
888 888
@@ -908,7 +908,7 @@ static int sco_connect_cfm(struct hci_conn *hcon, __u8 status)
908 BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status); 908 BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status);
909 909
910 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK) 910 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
911 return 0; 911 return -EINVAL;
912 912
913 if (!status) { 913 if (!status) {
914 struct sco_conn *conn; 914 struct sco_conn *conn;
@@ -927,7 +927,7 @@ static int sco_disconn_cfm(struct hci_conn *hcon, __u8 reason)
927 BT_DBG("hcon %p reason %d", hcon, reason); 927 BT_DBG("hcon %p reason %d", hcon, reason);
928 928
929 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK) 929 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
930 return 0; 930 return -EINVAL;
931 931
932 sco_conn_del(hcon, bt_err(reason)); 932 sco_conn_del(hcon, bt_err(reason));
933 933
diff --git a/net/caif/caif_config_util.c b/net/caif/caif_config_util.c
index 76ae68303d3a..d522d8c1703e 100644
--- a/net/caif/caif_config_util.c
+++ b/net/caif/caif_config_util.c
@@ -16,11 +16,18 @@ int connect_req_to_link_param(struct cfcnfg *cnfg,
16{ 16{
17 struct dev_info *dev_info; 17 struct dev_info *dev_info;
18 enum cfcnfg_phy_preference pref; 18 enum cfcnfg_phy_preference pref;
19 int res;
20
19 memset(l, 0, sizeof(*l)); 21 memset(l, 0, sizeof(*l));
20 l->priority = s->priority; 22 /* In caif protocol low value is high priority */
23 l->priority = CAIF_PRIO_MAX - s->priority + 1;
21 24
22 if (s->link_name[0] != '\0') 25 if (s->ifindex != 0){
23 l->phyid = cfcnfg_get_named(cnfg, s->link_name); 26 res = cfcnfg_get_id_from_ifi(cnfg, s->ifindex);
27 if (res < 0)
28 return res;
29 l->phyid = res;
30 }
24 else { 31 else {
25 switch (s->link_selector) { 32 switch (s->link_selector) {
26 case CAIF_LINK_HIGH_BANDW: 33 case CAIF_LINK_HIGH_BANDW:
diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
index b99369a055d1..a42a408306e4 100644
--- a/net/caif/caif_dev.c
+++ b/net/caif/caif_dev.c
@@ -307,6 +307,8 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what,
307 307
308 case NETDEV_UNREGISTER: 308 case NETDEV_UNREGISTER:
309 caifd = caif_get(dev); 309 caifd = caif_get(dev);
310 if (caifd == NULL)
311 break;
310 netdev_info(dev, "unregister\n"); 312 netdev_info(dev, "unregister\n");
311 atomic_set(&caifd->state, what); 313 atomic_set(&caifd->state, what);
312 caif_device_destroy(dev); 314 caif_device_destroy(dev);
diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
index 2eca2dd0000f..1bf0cf503796 100644
--- a/net/caif/caif_socket.c
+++ b/net/caif/caif_socket.c
@@ -716,8 +716,7 @@ static int setsockopt(struct socket *sock,
716{ 716{
717 struct sock *sk = sock->sk; 717 struct sock *sk = sock->sk;
718 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); 718 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk);
719 int prio, linksel; 719 int linksel;
720 struct ifreq ifreq;
721 720
722 if (cf_sk->sk.sk_socket->state != SS_UNCONNECTED) 721 if (cf_sk->sk.sk_socket->state != SS_UNCONNECTED)
723 return -ENOPROTOOPT; 722 return -ENOPROTOOPT;
@@ -735,33 +734,6 @@ static int setsockopt(struct socket *sock,
735 release_sock(&cf_sk->sk); 734 release_sock(&cf_sk->sk);
736 return 0; 735 return 0;
737 736
738 case SO_PRIORITY:
739 if (lvl != SOL_SOCKET)
740 goto bad_sol;
741 if (ol < sizeof(int))
742 return -EINVAL;
743 if (copy_from_user(&prio, ov, sizeof(int)))
744 return -EINVAL;
745 lock_sock(&(cf_sk->sk));
746 cf_sk->conn_req.priority = prio;
747 release_sock(&cf_sk->sk);
748 return 0;
749
750 case SO_BINDTODEVICE:
751 if (lvl != SOL_SOCKET)
752 goto bad_sol;
753 if (ol < sizeof(struct ifreq))
754 return -EINVAL;
755 if (copy_from_user(&ifreq, ov, sizeof(ifreq)))
756 return -EFAULT;
757 lock_sock(&(cf_sk->sk));
758 strncpy(cf_sk->conn_req.link_name, ifreq.ifr_name,
759 sizeof(cf_sk->conn_req.link_name));
760 cf_sk->conn_req.link_name
761 [sizeof(cf_sk->conn_req.link_name)-1] = 0;
762 release_sock(&cf_sk->sk);
763 return 0;
764
765 case CAIFSO_REQ_PARAM: 737 case CAIFSO_REQ_PARAM:
766 if (lvl != SOL_CAIF) 738 if (lvl != SOL_CAIF)
767 goto bad_sol; 739 goto bad_sol;
@@ -880,6 +852,18 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
880 sock->state = SS_CONNECTING; 852 sock->state = SS_CONNECTING;
881 sk->sk_state = CAIF_CONNECTING; 853 sk->sk_state = CAIF_CONNECTING;
882 854
855 /* Check priority value comming from socket */
856 /* if priority value is out of range it will be ajusted */
857 if (cf_sk->sk.sk_priority > CAIF_PRIO_MAX)
858 cf_sk->conn_req.priority = CAIF_PRIO_MAX;
859 else if (cf_sk->sk.sk_priority < CAIF_PRIO_MIN)
860 cf_sk->conn_req.priority = CAIF_PRIO_MIN;
861 else
862 cf_sk->conn_req.priority = cf_sk->sk.sk_priority;
863
864 /*ifindex = id of the interface.*/
865 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
866
883 dbfs_atomic_inc(&cnt.num_connect_req); 867 dbfs_atomic_inc(&cnt.num_connect_req);
884 cf_sk->layer.receive = caif_sktrecv_cb; 868 cf_sk->layer.receive = caif_sktrecv_cb;
885 err = caif_connect_client(&cf_sk->conn_req, 869 err = caif_connect_client(&cf_sk->conn_req,
@@ -905,6 +889,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
905 cf_sk->maxframe = mtu - (headroom + tailroom); 889 cf_sk->maxframe = mtu - (headroom + tailroom);
906 if (cf_sk->maxframe < 1) { 890 if (cf_sk->maxframe < 1) {
907 pr_warn("CAIF Interface MTU too small (%d)\n", dev->mtu); 891 pr_warn("CAIF Interface MTU too small (%d)\n", dev->mtu);
892 err = -ENODEV;
908 goto out; 893 goto out;
909 } 894 }
910 895
@@ -1142,7 +1127,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
1142 set_rx_flow_on(cf_sk); 1127 set_rx_flow_on(cf_sk);
1143 1128
1144 /* Set default options on configuration */ 1129 /* Set default options on configuration */
1145 cf_sk->conn_req.priority = CAIF_PRIO_NORMAL; 1130 cf_sk->sk.sk_priority= CAIF_PRIO_NORMAL;
1146 cf_sk->conn_req.link_selector = CAIF_LINK_LOW_LATENCY; 1131 cf_sk->conn_req.link_selector = CAIF_LINK_LOW_LATENCY;
1147 cf_sk->conn_req.protocol = protocol; 1132 cf_sk->conn_req.protocol = protocol;
1148 /* Increase the number of sockets created. */ 1133 /* Increase the number of sockets created. */
diff --git a/net/caif/cfcnfg.c b/net/caif/cfcnfg.c
index 41adafd18914..21ede141018a 100644
--- a/net/caif/cfcnfg.c
+++ b/net/caif/cfcnfg.c
@@ -173,18 +173,15 @@ static struct cfcnfg_phyinfo *cfcnfg_get_phyinfo(struct cfcnfg *cnfg,
173 return NULL; 173 return NULL;
174} 174}
175 175
176int cfcnfg_get_named(struct cfcnfg *cnfg, char *name) 176
177int cfcnfg_get_id_from_ifi(struct cfcnfg *cnfg, int ifi)
177{ 178{
178 int i; 179 int i;
179 180 for (i = 0; i < MAX_PHY_LAYERS; i++)
180 /* Try to match with specified name */ 181 if (cnfg->phy_layers[i].frm_layer != NULL &&
181 for (i = 0; i < MAX_PHY_LAYERS; i++) { 182 cnfg->phy_layers[i].ifindex == ifi)
182 if (cnfg->phy_layers[i].frm_layer != NULL 183 return i;
183 && strcmp(cnfg->phy_layers[i].phy_layer->name, 184 return -ENODEV;
184 name) == 0)
185 return cnfg->phy_layers[i].frm_layer->id;
186 }
187 return 0;
188} 185}
189 186
190int cfcnfg_disconn_adapt_layer(struct cfcnfg *cnfg, struct cflayer *adap_layer) 187int cfcnfg_disconn_adapt_layer(struct cfcnfg *cnfg, struct cflayer *adap_layer)
diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
index 08f267a109aa..3cd8f978e309 100644
--- a/net/caif/cfctrl.c
+++ b/net/caif/cfctrl.c
@@ -361,11 +361,10 @@ void cfctrl_cancel_req(struct cflayer *layr, struct cflayer *adap_layer)
361 struct cfctrl_request_info *p, *tmp; 361 struct cfctrl_request_info *p, *tmp;
362 struct cfctrl *ctrl = container_obj(layr); 362 struct cfctrl *ctrl = container_obj(layr);
363 spin_lock(&ctrl->info_list_lock); 363 spin_lock(&ctrl->info_list_lock);
364 pr_warn("enter\n");
365 364
366 list_for_each_entry_safe(p, tmp, &ctrl->list, list) { 365 list_for_each_entry_safe(p, tmp, &ctrl->list, list) {
367 if (p->client_layer == adap_layer) { 366 if (p->client_layer == adap_layer) {
368 pr_warn("cancel req :%d\n", p->sequence_no); 367 pr_debug("cancel req :%d\n", p->sequence_no);
369 list_del(&p->list); 368 list_del(&p->list);
370 kfree(p); 369 kfree(p);
371 } 370 }
diff --git a/net/caif/cfdbgl.c b/net/caif/cfdbgl.c
index 496fda9ac66f..11a2af4c162a 100644
--- a/net/caif/cfdbgl.c
+++ b/net/caif/cfdbgl.c
@@ -12,6 +12,8 @@
12#include <net/caif/cfsrvl.h> 12#include <net/caif/cfsrvl.h>
13#include <net/caif/cfpkt.h> 13#include <net/caif/cfpkt.h>
14 14
15#define container_obj(layr) ((struct cfsrvl *) layr)
16
15static int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt); 17static int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt);
16static int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt); 18static int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt);
17 19
@@ -38,5 +40,17 @@ static int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt)
38 40
39static int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt) 41static int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt)
40{ 42{
43 struct cfsrvl *service = container_obj(layr);
44 struct caif_payload_info *info;
45 int ret;
46
47 if (!cfsrvl_ready(service, &ret))
48 return ret;
49
50 /* Add info for MUX-layer to route the packet out */
51 info = cfpkt_info(pkt);
52 info->channel_id = service->layer.id;
53 info->dev_info = &service->dev_info;
54
41 return layr->dn->transmit(layr->dn, pkt); 55 return layr->dn->transmit(layr->dn, pkt);
42} 56}
diff --git a/net/caif/cfrfml.c b/net/caif/cfrfml.c
index bde8481e8d25..e2fb5fa75795 100644
--- a/net/caif/cfrfml.c
+++ b/net/caif/cfrfml.c
@@ -193,7 +193,7 @@ out:
193 193
194static int cfrfml_transmit_segment(struct cfrfml *rfml, struct cfpkt *pkt) 194static int cfrfml_transmit_segment(struct cfrfml *rfml, struct cfpkt *pkt)
195{ 195{
196 caif_assert(cfpkt_getlen(pkt) >= rfml->fragment_size); 196 caif_assert(cfpkt_getlen(pkt) < rfml->fragment_size);
197 197
198 /* Add info for MUX-layer to route the packet out. */ 198 /* Add info for MUX-layer to route the packet out. */
199 cfpkt_info(pkt)->channel_id = rfml->serv.layer.id; 199 cfpkt_info(pkt)->channel_id = rfml->serv.layer.id;
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 08ffe9e4be20..6faa8256e10c 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -125,7 +125,7 @@ struct bcm_sock {
125 struct list_head tx_ops; 125 struct list_head tx_ops;
126 unsigned long dropped_usr_msgs; 126 unsigned long dropped_usr_msgs;
127 struct proc_dir_entry *bcm_proc_read; 127 struct proc_dir_entry *bcm_proc_read;
128 char procname [9]; /* pointer printed in ASCII with \0 */ 128 char procname [20]; /* pointer printed in ASCII with \0 */
129}; 129};
130 130
131static inline struct bcm_sock *bcm_sk(const struct sock *sk) 131static inline struct bcm_sock *bcm_sk(const struct sock *sk)
diff --git a/net/ceph/Makefile b/net/ceph/Makefile
index aab1cabb8035..5f19415ec9c0 100644
--- a/net/ceph/Makefile
+++ b/net/ceph/Makefile
@@ -1,9 +1,6 @@
1# 1#
2# Makefile for CEPH filesystem. 2# Makefile for CEPH filesystem.
3# 3#
4
5ifneq ($(KERNELRELEASE),)
6
7obj-$(CONFIG_CEPH_LIB) += libceph.o 4obj-$(CONFIG_CEPH_LIB) += libceph.o
8 5
9libceph-objs := ceph_common.o messenger.o msgpool.o buffer.o pagelist.o \ 6libceph-objs := ceph_common.o messenger.o msgpool.o buffer.o pagelist.o \
@@ -16,22 +13,3 @@ libceph-objs := ceph_common.o messenger.o msgpool.o buffer.o pagelist.o \
16 ceph_fs.o ceph_strings.o ceph_hash.o \ 13 ceph_fs.o ceph_strings.o ceph_hash.o \
17 pagevec.o 14 pagevec.o
18 15
19else
20#Otherwise we were called directly from the command
21# line; invoke the kernel build system.
22
23KERNELDIR ?= /lib/modules/$(shell uname -r)/build
24PWD := $(shell pwd)
25
26default: all
27
28all:
29 $(MAKE) -C $(KERNELDIR) M=$(PWD) CONFIG_CEPH_LIB=m modules
30
31modules_install:
32 $(MAKE) -C $(KERNELDIR) M=$(PWD) CONFIG_CEPH_LIB=m modules_install
33
34clean:
35 $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
36
37endif
diff --git a/net/ceph/buffer.c b/net/ceph/buffer.c
index 53d8abfa25d5..bf3e6a13c215 100644
--- a/net/ceph/buffer.c
+++ b/net/ceph/buffer.c
@@ -19,7 +19,7 @@ struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp)
19 if (b->vec.iov_base) { 19 if (b->vec.iov_base) {
20 b->is_vmalloc = false; 20 b->is_vmalloc = false;
21 } else { 21 } else {
22 b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL); 22 b->vec.iov_base = __vmalloc(len, gfp | __GFP_HIGHMEM, PAGE_KERNEL);
23 if (!b->vec.iov_base) { 23 if (!b->vec.iov_base) {
24 kfree(b); 24 kfree(b);
25 return NULL; 25 return NULL;
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 0e8157ee5d43..b6ff4a1519ab 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -97,11 +97,9 @@ struct workqueue_struct *ceph_msgr_wq;
97int ceph_msgr_init(void) 97int ceph_msgr_init(void)
98{ 98{
99 ceph_msgr_wq = create_workqueue("ceph-msgr"); 99 ceph_msgr_wq = create_workqueue("ceph-msgr");
100 if (IS_ERR(ceph_msgr_wq)) { 100 if (!ceph_msgr_wq) {
101 int ret = PTR_ERR(ceph_msgr_wq); 101 pr_err("msgr_init failed to create workqueue\n");
102 pr_err("msgr_init failed to create workqueue: %d\n", ret); 102 return -ENOMEM;
103 ceph_msgr_wq = NULL;
104 return ret;
105 } 103 }
106 return 0; 104 return 0;
107} 105}
@@ -540,8 +538,7 @@ static void prepare_write_message(struct ceph_connection *con)
540 /* initialize page iterator */ 538 /* initialize page iterator */
541 con->out_msg_pos.page = 0; 539 con->out_msg_pos.page = 0;
542 if (m->pages) 540 if (m->pages)
543 con->out_msg_pos.page_pos = 541 con->out_msg_pos.page_pos = m->page_alignment;
544 le16_to_cpu(m->hdr.data_off) & ~PAGE_MASK;
545 else 542 else
546 con->out_msg_pos.page_pos = 0; 543 con->out_msg_pos.page_pos = 0;
547 con->out_msg_pos.data_pos = 0; 544 con->out_msg_pos.data_pos = 0;
@@ -1491,7 +1488,7 @@ static int read_partial_message(struct ceph_connection *con)
1491 struct ceph_msg *m = con->in_msg; 1488 struct ceph_msg *m = con->in_msg;
1492 int ret; 1489 int ret;
1493 int to, left; 1490 int to, left;
1494 unsigned front_len, middle_len, data_len, data_off; 1491 unsigned front_len, middle_len, data_len;
1495 int datacrc = con->msgr->nocrc; 1492 int datacrc = con->msgr->nocrc;
1496 int skip; 1493 int skip;
1497 u64 seq; 1494 u64 seq;
@@ -1527,19 +1524,17 @@ static int read_partial_message(struct ceph_connection *con)
1527 data_len = le32_to_cpu(con->in_hdr.data_len); 1524 data_len = le32_to_cpu(con->in_hdr.data_len);
1528 if (data_len > CEPH_MSG_MAX_DATA_LEN) 1525 if (data_len > CEPH_MSG_MAX_DATA_LEN)
1529 return -EIO; 1526 return -EIO;
1530 data_off = le16_to_cpu(con->in_hdr.data_off);
1531 1527
1532 /* verify seq# */ 1528 /* verify seq# */
1533 seq = le64_to_cpu(con->in_hdr.seq); 1529 seq = le64_to_cpu(con->in_hdr.seq);
1534 if ((s64)seq - (s64)con->in_seq < 1) { 1530 if ((s64)seq - (s64)con->in_seq < 1) {
1535 pr_info("skipping %s%lld %s seq %lld, expected %lld\n", 1531 pr_info("skipping %s%lld %s seq %lld expected %lld\n",
1536 ENTITY_NAME(con->peer_name), 1532 ENTITY_NAME(con->peer_name),
1537 ceph_pr_addr(&con->peer_addr.in_addr), 1533 ceph_pr_addr(&con->peer_addr.in_addr),
1538 seq, con->in_seq + 1); 1534 seq, con->in_seq + 1);
1539 con->in_base_pos = -front_len - middle_len - data_len - 1535 con->in_base_pos = -front_len - middle_len - data_len -
1540 sizeof(m->footer); 1536 sizeof(m->footer);
1541 con->in_tag = CEPH_MSGR_TAG_READY; 1537 con->in_tag = CEPH_MSGR_TAG_READY;
1542 con->in_seq++;
1543 return 0; 1538 return 0;
1544 } else if ((s64)seq - (s64)con->in_seq > 1) { 1539 } else if ((s64)seq - (s64)con->in_seq > 1) {
1545 pr_err("read_partial_message bad seq %lld expected %lld\n", 1540 pr_err("read_partial_message bad seq %lld expected %lld\n",
@@ -1576,7 +1571,7 @@ static int read_partial_message(struct ceph_connection *con)
1576 1571
1577 con->in_msg_pos.page = 0; 1572 con->in_msg_pos.page = 0;
1578 if (m->pages) 1573 if (m->pages)
1579 con->in_msg_pos.page_pos = data_off & ~PAGE_MASK; 1574 con->in_msg_pos.page_pos = m->page_alignment;
1580 else 1575 else
1581 con->in_msg_pos.page_pos = 0; 1576 con->in_msg_pos.page_pos = 0;
1582 con->in_msg_pos.data_pos = 0; 1577 con->in_msg_pos.data_pos = 0;
@@ -2301,6 +2296,7 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags)
2301 2296
2302 /* data */ 2297 /* data */
2303 m->nr_pages = 0; 2298 m->nr_pages = 0;
2299 m->page_alignment = 0;
2304 m->pages = NULL; 2300 m->pages = NULL;
2305 m->pagelist = NULL; 2301 m->pagelist = NULL;
2306 m->bio = NULL; 2302 m->bio = NULL;
@@ -2370,6 +2366,7 @@ static struct ceph_msg *ceph_alloc_msg(struct ceph_connection *con,
2370 type, front_len); 2366 type, front_len);
2371 return NULL; 2367 return NULL;
2372 } 2368 }
2369 msg->page_alignment = le16_to_cpu(hdr->data_off);
2373 } 2370 }
2374 memcpy(&msg->hdr, &con->in_hdr, sizeof(con->in_hdr)); 2371 memcpy(&msg->hdr, &con->in_hdr, sizeof(con->in_hdr));
2375 2372
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 79391994b3ed..3e20a122ffa2 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -71,6 +71,7 @@ void ceph_calc_raw_layout(struct ceph_osd_client *osdc,
71 op->extent.length = objlen; 71 op->extent.length = objlen;
72 } 72 }
73 req->r_num_pages = calc_pages_for(off, *plen); 73 req->r_num_pages = calc_pages_for(off, *plen);
74 req->r_page_alignment = off & ~PAGE_MASK;
74 if (op->op == CEPH_OSD_OP_WRITE) 75 if (op->op == CEPH_OSD_OP_WRITE)
75 op->payload_len = *plen; 76 op->payload_len = *plen;
76 77
@@ -390,6 +391,8 @@ void ceph_osdc_build_request(struct ceph_osd_request *req,
390 req->r_request->hdr.data_len = cpu_to_le32(data_len); 391 req->r_request->hdr.data_len = cpu_to_le32(data_len);
391 } 392 }
392 393
394 req->r_request->page_alignment = req->r_page_alignment;
395
393 BUG_ON(p > msg->front.iov_base + msg->front.iov_len); 396 BUG_ON(p > msg->front.iov_base + msg->front.iov_len);
394 msg_size = p - msg->front.iov_base; 397 msg_size = p - msg->front.iov_base;
395 msg->front.iov_len = msg_size; 398 msg->front.iov_len = msg_size;
@@ -419,7 +422,8 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
419 u32 truncate_seq, 422 u32 truncate_seq,
420 u64 truncate_size, 423 u64 truncate_size,
421 struct timespec *mtime, 424 struct timespec *mtime,
422 bool use_mempool, int num_reply) 425 bool use_mempool, int num_reply,
426 int page_align)
423{ 427{
424 struct ceph_osd_req_op ops[3]; 428 struct ceph_osd_req_op ops[3];
425 struct ceph_osd_request *req; 429 struct ceph_osd_request *req;
@@ -447,6 +451,10 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
447 calc_layout(osdc, vino, layout, off, plen, req, ops); 451 calc_layout(osdc, vino, layout, off, plen, req, ops);
448 req->r_file_layout = *layout; /* keep a copy */ 452 req->r_file_layout = *layout; /* keep a copy */
449 453
454 /* in case it differs from natural alignment that calc_layout
455 filled in for us */
456 req->r_page_alignment = page_align;
457
450 ceph_osdc_build_request(req, off, plen, ops, 458 ceph_osdc_build_request(req, off, plen, ops,
451 snapc, 459 snapc,
452 mtime, 460 mtime,
@@ -1489,7 +1497,7 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc,
1489 struct ceph_vino vino, struct ceph_file_layout *layout, 1497 struct ceph_vino vino, struct ceph_file_layout *layout,
1490 u64 off, u64 *plen, 1498 u64 off, u64 *plen,
1491 u32 truncate_seq, u64 truncate_size, 1499 u32 truncate_seq, u64 truncate_size,
1492 struct page **pages, int num_pages) 1500 struct page **pages, int num_pages, int page_align)
1493{ 1501{
1494 struct ceph_osd_request *req; 1502 struct ceph_osd_request *req;
1495 int rc = 0; 1503 int rc = 0;
@@ -1499,15 +1507,15 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc,
1499 req = ceph_osdc_new_request(osdc, layout, vino, off, plen, 1507 req = ceph_osdc_new_request(osdc, layout, vino, off, plen,
1500 CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ, 1508 CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
1501 NULL, 0, truncate_seq, truncate_size, NULL, 1509 NULL, 0, truncate_seq, truncate_size, NULL,
1502 false, 1); 1510 false, 1, page_align);
1503 if (!req) 1511 if (!req)
1504 return -ENOMEM; 1512 return -ENOMEM;
1505 1513
1506 /* it may be a short read due to an object boundary */ 1514 /* it may be a short read due to an object boundary */
1507 req->r_pages = pages; 1515 req->r_pages = pages;
1508 1516
1509 dout("readpages final extent is %llu~%llu (%d pages)\n", 1517 dout("readpages final extent is %llu~%llu (%d pages align %d)\n",
1510 off, *plen, req->r_num_pages); 1518 off, *plen, req->r_num_pages, page_align);
1511 1519
1512 rc = ceph_osdc_start_request(osdc, req, false); 1520 rc = ceph_osdc_start_request(osdc, req, false);
1513 if (!rc) 1521 if (!rc)
@@ -1533,6 +1541,7 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
1533{ 1541{
1534 struct ceph_osd_request *req; 1542 struct ceph_osd_request *req;
1535 int rc = 0; 1543 int rc = 0;
1544 int page_align = off & ~PAGE_MASK;
1536 1545
1537 BUG_ON(vino.snap != CEPH_NOSNAP); 1546 BUG_ON(vino.snap != CEPH_NOSNAP);
1538 req = ceph_osdc_new_request(osdc, layout, vino, off, &len, 1547 req = ceph_osdc_new_request(osdc, layout, vino, off, &len,
@@ -1541,7 +1550,7 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
1541 CEPH_OSD_FLAG_WRITE, 1550 CEPH_OSD_FLAG_WRITE,
1542 snapc, do_sync, 1551 snapc, do_sync,
1543 truncate_seq, truncate_size, mtime, 1552 truncate_seq, truncate_size, mtime,
1544 nofail, 1); 1553 nofail, 1, page_align);
1545 if (!req) 1554 if (!req)
1546 return -ENOMEM; 1555 return -ENOMEM;
1547 1556
@@ -1638,8 +1647,7 @@ static struct ceph_msg *get_reply(struct ceph_connection *con,
1638 m = ceph_msg_get(req->r_reply); 1647 m = ceph_msg_get(req->r_reply);
1639 1648
1640 if (data_len > 0) { 1649 if (data_len > 0) {
1641 unsigned data_off = le16_to_cpu(hdr->data_off); 1650 int want = calc_pages_for(req->r_page_alignment, data_len);
1642 int want = calc_pages_for(data_off & ~PAGE_MASK, data_len);
1643 1651
1644 if (unlikely(req->r_num_pages < want)) { 1652 if (unlikely(req->r_num_pages < want)) {
1645 pr_warning("tid %lld reply %d > expected %d pages\n", 1653 pr_warning("tid %lld reply %d > expected %d pages\n",
@@ -1651,6 +1659,7 @@ static struct ceph_msg *get_reply(struct ceph_connection *con,
1651 } 1659 }
1652 m->pages = req->r_pages; 1660 m->pages = req->r_pages;
1653 m->nr_pages = req->r_num_pages; 1661 m->nr_pages = req->r_num_pages;
1662 m->page_alignment = req->r_page_alignment;
1654#ifdef CONFIG_BLOCK 1663#ifdef CONFIG_BLOCK
1655 m->bio = req->r_bio; 1664 m->bio = req->r_bio;
1656#endif 1665#endif
diff --git a/net/ceph/pagevec.c b/net/ceph/pagevec.c
index 54caf0687155..1a040e64c69f 100644
--- a/net/ceph/pagevec.c
+++ b/net/ceph/pagevec.c
@@ -13,8 +13,7 @@
13 * build a vector of user pages 13 * build a vector of user pages
14 */ 14 */
15struct page **ceph_get_direct_page_vector(const char __user *data, 15struct page **ceph_get_direct_page_vector(const char __user *data,
16 int num_pages, 16 int num_pages, bool write_page)
17 loff_t off, size_t len)
18{ 17{
19 struct page **pages; 18 struct page **pages;
20 int rc; 19 int rc;
@@ -25,24 +24,27 @@ struct page **ceph_get_direct_page_vector(const char __user *data,
25 24
26 down_read(&current->mm->mmap_sem); 25 down_read(&current->mm->mmap_sem);
27 rc = get_user_pages(current, current->mm, (unsigned long)data, 26 rc = get_user_pages(current, current->mm, (unsigned long)data,
28 num_pages, 0, 0, pages, NULL); 27 num_pages, write_page, 0, pages, NULL);
29 up_read(&current->mm->mmap_sem); 28 up_read(&current->mm->mmap_sem);
30 if (rc < 0) 29 if (rc < num_pages)
31 goto fail; 30 goto fail;
32 return pages; 31 return pages;
33 32
34fail: 33fail:
35 kfree(pages); 34 ceph_put_page_vector(pages, rc > 0 ? rc : 0, false);
36 return ERR_PTR(rc); 35 return ERR_PTR(rc);
37} 36}
38EXPORT_SYMBOL(ceph_get_direct_page_vector); 37EXPORT_SYMBOL(ceph_get_direct_page_vector);
39 38
40void ceph_put_page_vector(struct page **pages, int num_pages) 39void ceph_put_page_vector(struct page **pages, int num_pages, bool dirty)
41{ 40{
42 int i; 41 int i;
43 42
44 for (i = 0; i < num_pages; i++) 43 for (i = 0; i < num_pages; i++) {
44 if (dirty)
45 set_page_dirty_lock(pages[i]);
45 put_page(pages[i]); 46 put_page(pages[i]);
47 }
46 kfree(pages); 48 kfree(pages);
47} 49}
48EXPORT_SYMBOL(ceph_put_page_vector); 50EXPORT_SYMBOL(ceph_put_page_vector);
diff --git a/net/core/dev.c b/net/core/dev.c
index 89204e8c0e14..126694116852 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2131,7 +2131,7 @@ static struct netdev_queue *dev_pick_tx(struct net_device *dev,
2131 } else { 2131 } else {
2132 struct sock *sk = skb->sk; 2132 struct sock *sk = skb->sk;
2133 queue_index = sk_tx_queue_get(sk); 2133 queue_index = sk_tx_queue_get(sk);
2134 if (queue_index < 0) { 2134 if (queue_index < 0 || queue_index >= dev->real_num_tx_queues) {
2135 2135
2136 queue_index = 0; 2136 queue_index = 0;
2137 if (dev->real_num_tx_queues > 1) 2137 if (dev->real_num_tx_queues > 1)
diff --git a/net/core/dst.c b/net/core/dst.c
index 8abe628b79f1..b99c7c7ffce2 100644
--- a/net/core/dst.c
+++ b/net/core/dst.c
@@ -370,6 +370,7 @@ static int dst_dev_event(struct notifier_block *this, unsigned long event,
370 370
371static struct notifier_block dst_dev_notifier = { 371static struct notifier_block dst_dev_notifier = {
372 .notifier_call = dst_dev_event, 372 .notifier_call = dst_dev_event,
373 .priority = -10, /* must be called after other network notifiers */
373}; 374};
374 375
375void __init dst_init(void) 376void __init dst_init(void)
diff --git a/net/core/filter.c b/net/core/filter.c
index 7beaec36b541..ae21a0d3c4a2 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -112,39 +112,41 @@ EXPORT_SYMBOL(sk_filter);
112 */ 112 */
113unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int flen) 113unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int flen)
114{ 114{
115 struct sock_filter *fentry; /* We walk down these */
116 void *ptr; 115 void *ptr;
117 u32 A = 0; /* Accumulator */ 116 u32 A = 0; /* Accumulator */
118 u32 X = 0; /* Index Register */ 117 u32 X = 0; /* Index Register */
119 u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */ 118 u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
119 unsigned long memvalid = 0;
120 u32 tmp; 120 u32 tmp;
121 int k; 121 int k;
122 int pc; 122 int pc;
123 123
124 BUILD_BUG_ON(BPF_MEMWORDS > BITS_PER_LONG);
124 /* 125 /*
125 * Process array of filter instructions. 126 * Process array of filter instructions.
126 */ 127 */
127 for (pc = 0; pc < flen; pc++) { 128 for (pc = 0; pc < flen; pc++) {
128 fentry = &filter[pc]; 129 const struct sock_filter *fentry = &filter[pc];
130 u32 f_k = fentry->k;
129 131
130 switch (fentry->code) { 132 switch (fentry->code) {
131 case BPF_S_ALU_ADD_X: 133 case BPF_S_ALU_ADD_X:
132 A += X; 134 A += X;
133 continue; 135 continue;
134 case BPF_S_ALU_ADD_K: 136 case BPF_S_ALU_ADD_K:
135 A += fentry->k; 137 A += f_k;
136 continue; 138 continue;
137 case BPF_S_ALU_SUB_X: 139 case BPF_S_ALU_SUB_X:
138 A -= X; 140 A -= X;
139 continue; 141 continue;
140 case BPF_S_ALU_SUB_K: 142 case BPF_S_ALU_SUB_K:
141 A -= fentry->k; 143 A -= f_k;
142 continue; 144 continue;
143 case BPF_S_ALU_MUL_X: 145 case BPF_S_ALU_MUL_X:
144 A *= X; 146 A *= X;
145 continue; 147 continue;
146 case BPF_S_ALU_MUL_K: 148 case BPF_S_ALU_MUL_K:
147 A *= fentry->k; 149 A *= f_k;
148 continue; 150 continue;
149 case BPF_S_ALU_DIV_X: 151 case BPF_S_ALU_DIV_X:
150 if (X == 0) 152 if (X == 0)
@@ -152,49 +154,49 @@ unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int
152 A /= X; 154 A /= X;
153 continue; 155 continue;
154 case BPF_S_ALU_DIV_K: 156 case BPF_S_ALU_DIV_K:
155 A /= fentry->k; 157 A /= f_k;
156 continue; 158 continue;
157 case BPF_S_ALU_AND_X: 159 case BPF_S_ALU_AND_X:
158 A &= X; 160 A &= X;
159 continue; 161 continue;
160 case BPF_S_ALU_AND_K: 162 case BPF_S_ALU_AND_K:
161 A &= fentry->k; 163 A &= f_k;
162 continue; 164 continue;
163 case BPF_S_ALU_OR_X: 165 case BPF_S_ALU_OR_X:
164 A |= X; 166 A |= X;
165 continue; 167 continue;
166 case BPF_S_ALU_OR_K: 168 case BPF_S_ALU_OR_K:
167 A |= fentry->k; 169 A |= f_k;
168 continue; 170 continue;
169 case BPF_S_ALU_LSH_X: 171 case BPF_S_ALU_LSH_X:
170 A <<= X; 172 A <<= X;
171 continue; 173 continue;
172 case BPF_S_ALU_LSH_K: 174 case BPF_S_ALU_LSH_K:
173 A <<= fentry->k; 175 A <<= f_k;
174 continue; 176 continue;
175 case BPF_S_ALU_RSH_X: 177 case BPF_S_ALU_RSH_X:
176 A >>= X; 178 A >>= X;
177 continue; 179 continue;
178 case BPF_S_ALU_RSH_K: 180 case BPF_S_ALU_RSH_K:
179 A >>= fentry->k; 181 A >>= f_k;
180 continue; 182 continue;
181 case BPF_S_ALU_NEG: 183 case BPF_S_ALU_NEG:
182 A = -A; 184 A = -A;
183 continue; 185 continue;
184 case BPF_S_JMP_JA: 186 case BPF_S_JMP_JA:
185 pc += fentry->k; 187 pc += f_k;
186 continue; 188 continue;
187 case BPF_S_JMP_JGT_K: 189 case BPF_S_JMP_JGT_K:
188 pc += (A > fentry->k) ? fentry->jt : fentry->jf; 190 pc += (A > f_k) ? fentry->jt : fentry->jf;
189 continue; 191 continue;
190 case BPF_S_JMP_JGE_K: 192 case BPF_S_JMP_JGE_K:
191 pc += (A >= fentry->k) ? fentry->jt : fentry->jf; 193 pc += (A >= f_k) ? fentry->jt : fentry->jf;
192 continue; 194 continue;
193 case BPF_S_JMP_JEQ_K: 195 case BPF_S_JMP_JEQ_K:
194 pc += (A == fentry->k) ? fentry->jt : fentry->jf; 196 pc += (A == f_k) ? fentry->jt : fentry->jf;
195 continue; 197 continue;
196 case BPF_S_JMP_JSET_K: 198 case BPF_S_JMP_JSET_K:
197 pc += (A & fentry->k) ? fentry->jt : fentry->jf; 199 pc += (A & f_k) ? fentry->jt : fentry->jf;
198 continue; 200 continue;
199 case BPF_S_JMP_JGT_X: 201 case BPF_S_JMP_JGT_X:
200 pc += (A > X) ? fentry->jt : fentry->jf; 202 pc += (A > X) ? fentry->jt : fentry->jf;
@@ -209,7 +211,7 @@ unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int
209 pc += (A & X) ? fentry->jt : fentry->jf; 211 pc += (A & X) ? fentry->jt : fentry->jf;
210 continue; 212 continue;
211 case BPF_S_LD_W_ABS: 213 case BPF_S_LD_W_ABS:
212 k = fentry->k; 214 k = f_k;
213load_w: 215load_w:
214 ptr = load_pointer(skb, k, 4, &tmp); 216 ptr = load_pointer(skb, k, 4, &tmp);
215 if (ptr != NULL) { 217 if (ptr != NULL) {
@@ -218,7 +220,7 @@ load_w:
218 } 220 }
219 break; 221 break;
220 case BPF_S_LD_H_ABS: 222 case BPF_S_LD_H_ABS:
221 k = fentry->k; 223 k = f_k;
222load_h: 224load_h:
223 ptr = load_pointer(skb, k, 2, &tmp); 225 ptr = load_pointer(skb, k, 2, &tmp);
224 if (ptr != NULL) { 226 if (ptr != NULL) {
@@ -227,7 +229,7 @@ load_h:
227 } 229 }
228 break; 230 break;
229 case BPF_S_LD_B_ABS: 231 case BPF_S_LD_B_ABS:
230 k = fentry->k; 232 k = f_k;
231load_b: 233load_b:
232 ptr = load_pointer(skb, k, 1, &tmp); 234 ptr = load_pointer(skb, k, 1, &tmp);
233 if (ptr != NULL) { 235 if (ptr != NULL) {
@@ -242,32 +244,34 @@ load_b:
242 X = skb->len; 244 X = skb->len;
243 continue; 245 continue;
244 case BPF_S_LD_W_IND: 246 case BPF_S_LD_W_IND:
245 k = X + fentry->k; 247 k = X + f_k;
246 goto load_w; 248 goto load_w;
247 case BPF_S_LD_H_IND: 249 case BPF_S_LD_H_IND:
248 k = X + fentry->k; 250 k = X + f_k;
249 goto load_h; 251 goto load_h;
250 case BPF_S_LD_B_IND: 252 case BPF_S_LD_B_IND:
251 k = X + fentry->k; 253 k = X + f_k;
252 goto load_b; 254 goto load_b;
253 case BPF_S_LDX_B_MSH: 255 case BPF_S_LDX_B_MSH:
254 ptr = load_pointer(skb, fentry->k, 1, &tmp); 256 ptr = load_pointer(skb, f_k, 1, &tmp);
255 if (ptr != NULL) { 257 if (ptr != NULL) {
256 X = (*(u8 *)ptr & 0xf) << 2; 258 X = (*(u8 *)ptr & 0xf) << 2;
257 continue; 259 continue;
258 } 260 }
259 return 0; 261 return 0;
260 case BPF_S_LD_IMM: 262 case BPF_S_LD_IMM:
261 A = fentry->k; 263 A = f_k;
262 continue; 264 continue;
263 case BPF_S_LDX_IMM: 265 case BPF_S_LDX_IMM:
264 X = fentry->k; 266 X = f_k;
265 continue; 267 continue;
266 case BPF_S_LD_MEM: 268 case BPF_S_LD_MEM:
267 A = mem[fentry->k]; 269 A = (memvalid & (1UL << f_k)) ?
270 mem[f_k] : 0;
268 continue; 271 continue;
269 case BPF_S_LDX_MEM: 272 case BPF_S_LDX_MEM:
270 X = mem[fentry->k]; 273 X = (memvalid & (1UL << f_k)) ?
274 mem[f_k] : 0;
271 continue; 275 continue;
272 case BPF_S_MISC_TAX: 276 case BPF_S_MISC_TAX:
273 X = A; 277 X = A;
@@ -276,14 +280,16 @@ load_b:
276 A = X; 280 A = X;
277 continue; 281 continue;
278 case BPF_S_RET_K: 282 case BPF_S_RET_K:
279 return fentry->k; 283 return f_k;
280 case BPF_S_RET_A: 284 case BPF_S_RET_A:
281 return A; 285 return A;
282 case BPF_S_ST: 286 case BPF_S_ST:
283 mem[fentry->k] = A; 287 memvalid |= 1UL << f_k;
288 mem[f_k] = A;
284 continue; 289 continue;
285 case BPF_S_STX: 290 case BPF_S_STX:
286 mem[fentry->k] = X; 291 memvalid |= 1UL << f_k;
292 mem[f_k] = X;
287 continue; 293 continue;
288 default: 294 default:
289 WARN_ON(1); 295 WARN_ON(1);
@@ -583,23 +589,16 @@ int sk_chk_filter(struct sock_filter *filter, int flen)
583EXPORT_SYMBOL(sk_chk_filter); 589EXPORT_SYMBOL(sk_chk_filter);
584 590
585/** 591/**
586 * sk_filter_rcu_release: Release a socket filter by rcu_head 592 * sk_filter_release_rcu - Release a socket filter by rcu_head
587 * @rcu: rcu_head that contains the sk_filter to free 593 * @rcu: rcu_head that contains the sk_filter to free
588 */ 594 */
589static void sk_filter_rcu_release(struct rcu_head *rcu) 595void sk_filter_release_rcu(struct rcu_head *rcu)
590{ 596{
591 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu); 597 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
592 598
593 sk_filter_release(fp); 599 kfree(fp);
594}
595
596static void sk_filter_delayed_uncharge(struct sock *sk, struct sk_filter *fp)
597{
598 unsigned int size = sk_filter_len(fp);
599
600 atomic_sub(size, &sk->sk_omem_alloc);
601 call_rcu_bh(&fp->rcu, sk_filter_rcu_release);
602} 600}
601EXPORT_SYMBOL(sk_filter_release_rcu);
603 602
604/** 603/**
605 * sk_attach_filter - attach a socket filter 604 * sk_attach_filter - attach a socket filter
@@ -643,7 +642,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
643 rcu_assign_pointer(sk->sk_filter, fp); 642 rcu_assign_pointer(sk->sk_filter, fp);
644 643
645 if (old_fp) 644 if (old_fp)
646 sk_filter_delayed_uncharge(sk, old_fp); 645 sk_filter_uncharge(sk, old_fp);
647 return 0; 646 return 0;
648} 647}
649EXPORT_SYMBOL_GPL(sk_attach_filter); 648EXPORT_SYMBOL_GPL(sk_attach_filter);
@@ -657,7 +656,7 @@ int sk_detach_filter(struct sock *sk)
657 sock_owned_by_user(sk)); 656 sock_owned_by_user(sk));
658 if (filter) { 657 if (filter) {
659 rcu_assign_pointer(sk->sk_filter, NULL); 658 rcu_assign_pointer(sk->sk_filter, NULL);
660 sk_filter_delayed_uncharge(sk, filter); 659 sk_filter_uncharge(sk, filter);
661 ret = 0; 660 ret = 0;
662 } 661 }
663 return ret; 662 return ret;
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index a5ff5a89f376..7f902cad10f8 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -712,15 +712,21 @@ static void rx_queue_release(struct kobject *kobj)
712 712
713 713
714 map = rcu_dereference_raw(queue->rps_map); 714 map = rcu_dereference_raw(queue->rps_map);
715 if (map) 715 if (map) {
716 RCU_INIT_POINTER(queue->rps_map, NULL);
716 call_rcu(&map->rcu, rps_map_release); 717 call_rcu(&map->rcu, rps_map_release);
718 }
717 719
718 flow_table = rcu_dereference_raw(queue->rps_flow_table); 720 flow_table = rcu_dereference_raw(queue->rps_flow_table);
719 if (flow_table) 721 if (flow_table) {
722 RCU_INIT_POINTER(queue->rps_flow_table, NULL);
720 call_rcu(&flow_table->rcu, rps_dev_flow_table_release); 723 call_rcu(&flow_table->rcu, rps_dev_flow_table_release);
724 }
721 725
722 if (atomic_dec_and_test(&first->count)) 726 if (atomic_dec_and_test(&first->count))
723 kfree(first); 727 kfree(first);
728 else
729 memset(kobj, 0, sizeof(*kobj));
724} 730}
725 731
726static struct kobj_type rx_queue_ktype = { 732static struct kobj_type rx_queue_ktype = {
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index fbce4b05a53e..33bc3823ac6f 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -887,7 +887,7 @@ static ssize_t pktgen_if_write(struct file *file,
887 i += len; 887 i += len;
888 888
889 if (debug) { 889 if (debug) {
890 size_t copy = min(count, 1023); 890 size_t copy = min_t(size_t, count, 1023);
891 char tb[copy + 1]; 891 char tb[copy + 1];
892 if (copy_from_user(tb, user_buffer, copy)) 892 if (copy_from_user(tb, user_buffer, copy))
893 return -EFAULT; 893 return -EFAULT;
@@ -2612,8 +2612,8 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
2612 /* Update any of the values, used when we're incrementing various 2612 /* Update any of the values, used when we're incrementing various
2613 * fields. 2613 * fields.
2614 */ 2614 */
2615 queue_map = pkt_dev->cur_queue_map;
2616 mod_cur_headers(pkt_dev); 2615 mod_cur_headers(pkt_dev);
2616 queue_map = pkt_dev->cur_queue_map;
2617 2617
2618 datalen = (odev->hard_header_len + 16) & ~0xf; 2618 datalen = (odev->hard_header_len + 16) & ~0xf;
2619 2619
@@ -2976,8 +2976,8 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2976 /* Update any of the values, used when we're incrementing various 2976 /* Update any of the values, used when we're incrementing various
2977 * fields. 2977 * fields.
2978 */ 2978 */
2979 queue_map = pkt_dev->cur_queue_map;
2980 mod_cur_headers(pkt_dev); 2979 mod_cur_headers(pkt_dev);
2980 queue_map = pkt_dev->cur_queue_map;
2981 2981
2982 skb = __netdev_alloc_skb(odev, 2982 skb = __netdev_alloc_skb(odev,
2983 pkt_dev->cur_pkt_size + 64 2983 pkt_dev->cur_pkt_size + 64
diff --git a/net/core/request_sock.c b/net/core/request_sock.c
index 7552495aff7a..fceeb37d7161 100644
--- a/net/core/request_sock.c
+++ b/net/core/request_sock.c
@@ -45,9 +45,7 @@ int reqsk_queue_alloc(struct request_sock_queue *queue,
45 nr_table_entries = roundup_pow_of_two(nr_table_entries + 1); 45 nr_table_entries = roundup_pow_of_two(nr_table_entries + 1);
46 lopt_size += nr_table_entries * sizeof(struct request_sock *); 46 lopt_size += nr_table_entries * sizeof(struct request_sock *);
47 if (lopt_size > PAGE_SIZE) 47 if (lopt_size > PAGE_SIZE)
48 lopt = __vmalloc(lopt_size, 48 lopt = vzalloc(lopt_size);
49 GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
50 PAGE_KERNEL);
51 else 49 else
52 lopt = kzalloc(lopt_size, GFP_KERNEL); 50 lopt = kzalloc(lopt_size, GFP_KERNEL);
53 if (lopt == NULL) 51 if (lopt == NULL)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 8121268ddbdd..841c287ef40a 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -347,16 +347,17 @@ static size_t rtnl_link_get_size(const struct net_device *dev)
347 if (!ops) 347 if (!ops)
348 return 0; 348 return 0;
349 349
350 size = nlmsg_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */ 350 size = nla_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */
351 nlmsg_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */ 351 nla_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */
352 352
353 if (ops->get_size) 353 if (ops->get_size)
354 /* IFLA_INFO_DATA + nested data */ 354 /* IFLA_INFO_DATA + nested data */
355 size += nlmsg_total_size(sizeof(struct nlattr)) + 355 size += nla_total_size(sizeof(struct nlattr)) +
356 ops->get_size(dev); 356 ops->get_size(dev);
357 357
358 if (ops->get_xstats_size) 358 if (ops->get_xstats_size)
359 size += ops->get_xstats_size(dev); /* IFLA_INFO_XSTATS */ 359 /* IFLA_INFO_XSTATS */
360 size += nla_total_size(ops->get_xstats_size(dev));
360 361
361 return size; 362 return size;
362} 363}
diff --git a/net/core/sock.c b/net/core/sock.c
index 3eed5424e659..fb6080111461 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1653,10 +1653,10 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)
1653{ 1653{
1654 struct proto *prot = sk->sk_prot; 1654 struct proto *prot = sk->sk_prot;
1655 int amt = sk_mem_pages(size); 1655 int amt = sk_mem_pages(size);
1656 int allocated; 1656 long allocated;
1657 1657
1658 sk->sk_forward_alloc += amt * SK_MEM_QUANTUM; 1658 sk->sk_forward_alloc += amt * SK_MEM_QUANTUM;
1659 allocated = atomic_add_return(amt, prot->memory_allocated); 1659 allocated = atomic_long_add_return(amt, prot->memory_allocated);
1660 1660
1661 /* Under limit. */ 1661 /* Under limit. */
1662 if (allocated <= prot->sysctl_mem[0]) { 1662 if (allocated <= prot->sysctl_mem[0]) {
@@ -1714,7 +1714,7 @@ suppress_allocation:
1714 1714
1715 /* Alas. Undo changes. */ 1715 /* Alas. Undo changes. */
1716 sk->sk_forward_alloc -= amt * SK_MEM_QUANTUM; 1716 sk->sk_forward_alloc -= amt * SK_MEM_QUANTUM;
1717 atomic_sub(amt, prot->memory_allocated); 1717 atomic_long_sub(amt, prot->memory_allocated);
1718 return 0; 1718 return 0;
1719} 1719}
1720EXPORT_SYMBOL(__sk_mem_schedule); 1720EXPORT_SYMBOL(__sk_mem_schedule);
@@ -1727,12 +1727,12 @@ void __sk_mem_reclaim(struct sock *sk)
1727{ 1727{
1728 struct proto *prot = sk->sk_prot; 1728 struct proto *prot = sk->sk_prot;
1729 1729
1730 atomic_sub(sk->sk_forward_alloc >> SK_MEM_QUANTUM_SHIFT, 1730 atomic_long_sub(sk->sk_forward_alloc >> SK_MEM_QUANTUM_SHIFT,
1731 prot->memory_allocated); 1731 prot->memory_allocated);
1732 sk->sk_forward_alloc &= SK_MEM_QUANTUM - 1; 1732 sk->sk_forward_alloc &= SK_MEM_QUANTUM - 1;
1733 1733
1734 if (prot->memory_pressure && *prot->memory_pressure && 1734 if (prot->memory_pressure && *prot->memory_pressure &&
1735 (atomic_read(prot->memory_allocated) < prot->sysctl_mem[0])) 1735 (atomic_long_read(prot->memory_allocated) < prot->sysctl_mem[0]))
1736 *prot->memory_pressure = 0; 1736 *prot->memory_pressure = 0;
1737} 1737}
1738EXPORT_SYMBOL(__sk_mem_reclaim); 1738EXPORT_SYMBOL(__sk_mem_reclaim);
@@ -2452,12 +2452,12 @@ static char proto_method_implemented(const void *method)
2452 2452
2453static void proto_seq_printf(struct seq_file *seq, struct proto *proto) 2453static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
2454{ 2454{
2455 seq_printf(seq, "%-9s %4u %6d %6d %-3s %6u %-3s %-10s " 2455 seq_printf(seq, "%-9s %4u %6d %6ld %-3s %6u %-3s %-10s "
2456 "%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n", 2456 "%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n",
2457 proto->name, 2457 proto->name,
2458 proto->obj_size, 2458 proto->obj_size,
2459 sock_prot_inuse_get(seq_file_net(seq), proto), 2459 sock_prot_inuse_get(seq_file_net(seq), proto),
2460 proto->memory_allocated != NULL ? atomic_read(proto->memory_allocated) : -1, 2460 proto->memory_allocated != NULL ? atomic_long_read(proto->memory_allocated) : -1L,
2461 proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI", 2461 proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI",
2462 proto->max_header, 2462 proto->max_header,
2463 proto->slab == NULL ? "no" : "yes", 2463 proto->slab == NULL ? "no" : "yes",
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index 0ae6c22da85b..c19bb4ee405e 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -96,11 +96,13 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
96 struct phy_device *phydev; 96 struct phy_device *phydev;
97 unsigned int type; 97 unsigned int type;
98 98
99 skb_push(skb, ETH_HLEN); 99 if (skb_headroom(skb) < ETH_HLEN)
100 return false;
101 __skb_push(skb, ETH_HLEN);
100 102
101 type = classify(skb); 103 type = classify(skb);
102 104
103 skb_pull(skb, ETH_HLEN); 105 __skb_pull(skb, ETH_HLEN);
104 106
105 switch (type) { 107 switch (type) {
106 case PTP_CLASS_V1_IPV4: 108 case PTP_CLASS_V1_IPV4:
diff --git a/net/dccp/input.c b/net/dccp/input.c
index 265985370fa1..e424a09e83f6 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -239,7 +239,8 @@ static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
239 dccp_update_gsr(sk, seqno); 239 dccp_update_gsr(sk, seqno);
240 240
241 if (dh->dccph_type != DCCP_PKT_SYNC && 241 if (dh->dccph_type != DCCP_PKT_SYNC &&
242 (ackno != DCCP_PKT_WITHOUT_ACK_SEQ)) 242 ackno != DCCP_PKT_WITHOUT_ACK_SEQ &&
243 after48(ackno, dp->dccps_gar))
243 dp->dccps_gar = ackno; 244 dp->dccps_gar = ackno;
244 } else { 245 } else {
245 unsigned long now = jiffies; 246 unsigned long now = jiffies;
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index d6b93d19790f..6f97268ed85f 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -155,7 +155,7 @@ static const struct proto_ops dn_proto_ops;
155static DEFINE_RWLOCK(dn_hash_lock); 155static DEFINE_RWLOCK(dn_hash_lock);
156static struct hlist_head dn_sk_hash[DN_SK_HASH_SIZE]; 156static struct hlist_head dn_sk_hash[DN_SK_HASH_SIZE];
157static struct hlist_head dn_wild_sk; 157static struct hlist_head dn_wild_sk;
158static atomic_t decnet_memory_allocated; 158static atomic_long_t decnet_memory_allocated;
159 159
160static int __dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen, int flags); 160static int __dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen, int flags);
161static int __dn_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen, int flags); 161static int __dn_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen, int flags);
@@ -1556,6 +1556,8 @@ static int __dn_getsockopt(struct socket *sock, int level,int optname, char __us
1556 if (r_len > sizeof(struct linkinfo_dn)) 1556 if (r_len > sizeof(struct linkinfo_dn))
1557 r_len = sizeof(struct linkinfo_dn); 1557 r_len = sizeof(struct linkinfo_dn);
1558 1558
1559 memset(&link, 0, sizeof(link));
1560
1559 switch(sock->state) { 1561 switch(sock->state) {
1560 case SS_CONNECTING: 1562 case SS_CONNECTING:
1561 link.idn_linkstate = LL_CONNECTING; 1563 link.idn_linkstate = LL_CONNECTING;
diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
index be3eb8e23288..28f8b5e5f73b 100644
--- a/net/decnet/sysctl_net_decnet.c
+++ b/net/decnet/sysctl_net_decnet.c
@@ -38,7 +38,7 @@ int decnet_log_martians = 1;
38int decnet_no_fc_max_cwnd = NSP_MIN_WINDOW; 38int decnet_no_fc_max_cwnd = NSP_MIN_WINDOW;
39 39
40/* Reasonable defaults, I hope, based on tcp's defaults */ 40/* Reasonable defaults, I hope, based on tcp's defaults */
41int sysctl_decnet_mem[3] = { 768 << 3, 1024 << 3, 1536 << 3 }; 41long sysctl_decnet_mem[3] = { 768 << 3, 1024 << 3, 1536 << 3 };
42int sysctl_decnet_wmem[3] = { 4 * 1024, 16 * 1024, 128 * 1024 }; 42int sysctl_decnet_wmem[3] = { 4 * 1024, 16 * 1024, 128 * 1024 };
43int sysctl_decnet_rmem[3] = { 4 * 1024, 87380, 87380 * 2 }; 43int sysctl_decnet_rmem[3] = { 4 * 1024, 87380, 87380 * 2 };
44 44
@@ -324,7 +324,7 @@ static ctl_table dn_table[] = {
324 .data = &sysctl_decnet_mem, 324 .data = &sysctl_decnet_mem,
325 .maxlen = sizeof(sysctl_decnet_mem), 325 .maxlen = sizeof(sysctl_decnet_mem),
326 .mode = 0644, 326 .mode = 0644,
327 .proc_handler = proc_dointvec, 327 .proc_handler = proc_doulongvec_minmax
328 }, 328 },
329 { 329 {
330 .procname = "decnet_rmem", 330 .procname = "decnet_rmem",
diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c
index f8c1ae4b41f0..15dcc1a586b4 100644
--- a/net/econet/af_econet.c
+++ b/net/econet/af_econet.c
@@ -31,6 +31,7 @@
31#include <linux/skbuff.h> 31#include <linux/skbuff.h>
32#include <linux/udp.h> 32#include <linux/udp.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/vmalloc.h>
34#include <net/sock.h> 35#include <net/sock.h>
35#include <net/inet_common.h> 36#include <net/inet_common.h>
36#include <linux/stat.h> 37#include <linux/stat.h>
@@ -276,12 +277,12 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
276#endif 277#endif
277#ifdef CONFIG_ECONET_AUNUDP 278#ifdef CONFIG_ECONET_AUNUDP
278 struct msghdr udpmsg; 279 struct msghdr udpmsg;
279 struct iovec iov[msg->msg_iovlen+1]; 280 struct iovec iov[2];
280 struct aunhdr ah; 281 struct aunhdr ah;
281 struct sockaddr_in udpdest; 282 struct sockaddr_in udpdest;
282 __kernel_size_t size; 283 __kernel_size_t size;
283 int i;
284 mm_segment_t oldfs; 284 mm_segment_t oldfs;
285 char *userbuf;
285#endif 286#endif
286 287
287 /* 288 /*
@@ -297,23 +298,14 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
297 298
298 mutex_lock(&econet_mutex); 299 mutex_lock(&econet_mutex);
299 300
300 if (saddr == NULL) { 301 if (saddr == NULL || msg->msg_namelen < sizeof(struct sockaddr_ec)) {
301 struct econet_sock *eo = ec_sk(sk); 302 mutex_unlock(&econet_mutex);
302 303 return -EINVAL;
303 addr.station = eo->station; 304 }
304 addr.net = eo->net; 305 addr.station = saddr->addr.station;
305 port = eo->port; 306 addr.net = saddr->addr.net;
306 cb = eo->cb; 307 port = saddr->port;
307 } else { 308 cb = saddr->cb;
308 if (msg->msg_namelen < sizeof(struct sockaddr_ec)) {
309 mutex_unlock(&econet_mutex);
310 return -EINVAL;
311 }
312 addr.station = saddr->addr.station;
313 addr.net = saddr->addr.net;
314 port = saddr->port;
315 cb = saddr->cb;
316 }
317 309
318 /* Look for a device with the right network number. */ 310 /* Look for a device with the right network number. */
319 dev = net2dev_map[addr.net]; 311 dev = net2dev_map[addr.net];
@@ -328,17 +320,17 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
328 } 320 }
329 } 321 }
330 322
331 if (len + 15 > dev->mtu) {
332 mutex_unlock(&econet_mutex);
333 return -EMSGSIZE;
334 }
335
336 if (dev->type == ARPHRD_ECONET) { 323 if (dev->type == ARPHRD_ECONET) {
337 /* Real hardware Econet. We're not worthy etc. */ 324 /* Real hardware Econet. We're not worthy etc. */
338#ifdef CONFIG_ECONET_NATIVE 325#ifdef CONFIG_ECONET_NATIVE
339 unsigned short proto = 0; 326 unsigned short proto = 0;
340 int res; 327 int res;
341 328
329 if (len + 15 > dev->mtu) {
330 mutex_unlock(&econet_mutex);
331 return -EMSGSIZE;
332 }
333
342 dev_hold(dev); 334 dev_hold(dev);
343 335
344 skb = sock_alloc_send_skb(sk, len+LL_ALLOCATED_SPACE(dev), 336 skb = sock_alloc_send_skb(sk, len+LL_ALLOCATED_SPACE(dev),
@@ -351,7 +343,6 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
351 343
352 eb = (struct ec_cb *)&skb->cb; 344 eb = (struct ec_cb *)&skb->cb;
353 345
354 /* BUG: saddr may be NULL */
355 eb->cookie = saddr->cookie; 346 eb->cookie = saddr->cookie;
356 eb->sec = *saddr; 347 eb->sec = *saddr;
357 eb->sent = ec_tx_done; 348 eb->sent = ec_tx_done;
@@ -415,6 +406,11 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
415 return -ENETDOWN; /* No socket - can't send */ 406 return -ENETDOWN; /* No socket - can't send */
416 } 407 }
417 408
409 if (len > 32768) {
410 err = -E2BIG;
411 goto error;
412 }
413
418 /* Make up a UDP datagram and hand it off to some higher intellect. */ 414 /* Make up a UDP datagram and hand it off to some higher intellect. */
419 415
420 memset(&udpdest, 0, sizeof(udpdest)); 416 memset(&udpdest, 0, sizeof(udpdest));
@@ -446,36 +442,26 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
446 442
447 /* tack our header on the front of the iovec */ 443 /* tack our header on the front of the iovec */
448 size = sizeof(struct aunhdr); 444 size = sizeof(struct aunhdr);
449 /*
450 * XXX: that is b0rken. We can't mix userland and kernel pointers
451 * in iovec, since on a lot of platforms copy_from_user() will
452 * *not* work with the kernel and userland ones at the same time,
453 * regardless of what we do with set_fs(). And we are talking about
454 * econet-over-ethernet here, so "it's only ARM anyway" doesn't
455 * apply. Any suggestions on fixing that code? -- AV
456 */
457 iov[0].iov_base = (void *)&ah; 445 iov[0].iov_base = (void *)&ah;
458 iov[0].iov_len = size; 446 iov[0].iov_len = size;
459 for (i = 0; i < msg->msg_iovlen; i++) { 447
460 void __user *base = msg->msg_iov[i].iov_base; 448 userbuf = vmalloc(len);
461 size_t iov_len = msg->msg_iov[i].iov_len; 449 if (userbuf == NULL) {
462 /* Check it now since we switch to KERNEL_DS later. */ 450 err = -ENOMEM;
463 if (!access_ok(VERIFY_READ, base, iov_len)) { 451 goto error;
464 mutex_unlock(&econet_mutex);
465 return -EFAULT;
466 }
467 iov[i+1].iov_base = base;
468 iov[i+1].iov_len = iov_len;
469 size += iov_len;
470 } 452 }
471 453
454 iov[1].iov_base = userbuf;
455 iov[1].iov_len = len;
456 err = memcpy_fromiovec(userbuf, msg->msg_iov, len);
457 if (err)
458 goto error_free_buf;
459
472 /* Get a skbuff (no data, just holds our cb information) */ 460 /* Get a skbuff (no data, just holds our cb information) */
473 if ((skb = sock_alloc_send_skb(sk, 0, 461 if ((skb = sock_alloc_send_skb(sk, 0,
474 msg->msg_flags & MSG_DONTWAIT, 462 msg->msg_flags & MSG_DONTWAIT,
475 &err)) == NULL) { 463 &err)) == NULL)
476 mutex_unlock(&econet_mutex); 464 goto error_free_buf;
477 return err;
478 }
479 465
480 eb = (struct ec_cb *)&skb->cb; 466 eb = (struct ec_cb *)&skb->cb;
481 467
@@ -491,7 +477,7 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
491 udpmsg.msg_name = (void *)&udpdest; 477 udpmsg.msg_name = (void *)&udpdest;
492 udpmsg.msg_namelen = sizeof(udpdest); 478 udpmsg.msg_namelen = sizeof(udpdest);
493 udpmsg.msg_iov = &iov[0]; 479 udpmsg.msg_iov = &iov[0];
494 udpmsg.msg_iovlen = msg->msg_iovlen + 1; 480 udpmsg.msg_iovlen = 2;
495 udpmsg.msg_control = NULL; 481 udpmsg.msg_control = NULL;
496 udpmsg.msg_controllen = 0; 482 udpmsg.msg_controllen = 0;
497 udpmsg.msg_flags=0; 483 udpmsg.msg_flags=0;
@@ -499,9 +485,13 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock,
499 oldfs = get_fs(); set_fs(KERNEL_DS); /* More privs :-) */ 485 oldfs = get_fs(); set_fs(KERNEL_DS); /* More privs :-) */
500 err = sock_sendmsg(udpsock, &udpmsg, size); 486 err = sock_sendmsg(udpsock, &udpmsg, size);
501 set_fs(oldfs); 487 set_fs(oldfs);
488
489error_free_buf:
490 vfree(userbuf);
502#else 491#else
503 err = -EPROTOTYPE; 492 err = -EPROTOTYPE;
504#endif 493#endif
494 error:
505 mutex_unlock(&econet_mutex); 495 mutex_unlock(&econet_mutex);
506 496
507 return err; 497 return err;
@@ -671,6 +661,11 @@ static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg)
671 err = 0; 661 err = 0;
672 switch (cmd) { 662 switch (cmd) {
673 case SIOCSIFADDR: 663 case SIOCSIFADDR:
664 if (!capable(CAP_NET_ADMIN)) {
665 err = -EPERM;
666 break;
667 }
668
674 edev = dev->ec_ptr; 669 edev = dev->ec_ptr;
675 if (edev == NULL) { 670 if (edev == NULL) {
676 /* Magic up a new one. */ 671 /* Magic up a new one. */
@@ -856,9 +851,13 @@ static void aun_incoming(struct sk_buff *skb, struct aunhdr *ah, size_t len)
856{ 851{
857 struct iphdr *ip = ip_hdr(skb); 852 struct iphdr *ip = ip_hdr(skb);
858 unsigned char stn = ntohl(ip->saddr) & 0xff; 853 unsigned char stn = ntohl(ip->saddr) & 0xff;
854 struct dst_entry *dst = skb_dst(skb);
855 struct ec_device *edev = NULL;
859 struct sock *sk = NULL; 856 struct sock *sk = NULL;
860 struct sk_buff *newskb; 857 struct sk_buff *newskb;
861 struct ec_device *edev = skb->dev->ec_ptr; 858
859 if (dst)
860 edev = dst->dev->ec_ptr;
862 861
863 if (! edev) 862 if (! edev)
864 goto bad; 863 goto bad;
diff --git a/net/ipv4/fib_lookup.h b/net/ipv4/fib_lookup.h
index a29edf2219c8..c079cc0ec651 100644
--- a/net/ipv4/fib_lookup.h
+++ b/net/ipv4/fib_lookup.h
@@ -47,11 +47,8 @@ extern int fib_detect_death(struct fib_info *fi, int order,
47static inline void fib_result_assign(struct fib_result *res, 47static inline void fib_result_assign(struct fib_result *res,
48 struct fib_info *fi) 48 struct fib_info *fi)
49{ 49{
50 if (res->fi != NULL) 50 /* we used to play games with refcounts, but we now use RCU */
51 fib_info_put(res->fi);
52 res->fi = fi; 51 res->fi = fi;
53 if (fi != NULL)
54 atomic_inc(&fi->fib_clntref);
55} 52}
56 53
57#endif /* _FIB_LOOKUP_H */ 54#endif /* _FIB_LOOKUP_H */
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 200eb538fbb3..0f280348e0fd 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -365,7 +365,7 @@ static struct tnode *tnode_alloc(size_t size)
365 if (size <= PAGE_SIZE) 365 if (size <= PAGE_SIZE)
366 return kzalloc(size, GFP_KERNEL); 366 return kzalloc(size, GFP_KERNEL);
367 else 367 else
368 return __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL); 368 return vzalloc(size);
369} 369}
370 370
371static void __tnode_vfree(struct work_struct *arg) 371static void __tnode_vfree(struct work_struct *arg)
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 96bc7f9475a3..e5d1a44bcbdf 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -569,6 +569,9 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
569 /* No need to clone since we're just using its address. */ 569 /* No need to clone since we're just using its address. */
570 rt2 = rt; 570 rt2 = rt;
571 571
572 if (!fl.nl_u.ip4_u.saddr)
573 fl.nl_u.ip4_u.saddr = rt->rt_src;
574
572 err = xfrm_lookup(net, (struct dst_entry **)&rt, &fl, NULL, 0); 575 err = xfrm_lookup(net, (struct dst_entry **)&rt, &fl, NULL, 0);
573 switch (err) { 576 switch (err) {
574 case 0: 577 case 0:
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index c8877c6c7216..3c53c2d89e3b 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -2306,10 +2306,8 @@ void ip_mc_drop_socket(struct sock *sk)
2306 2306
2307 in_dev = inetdev_by_index(net, iml->multi.imr_ifindex); 2307 in_dev = inetdev_by_index(net, iml->multi.imr_ifindex);
2308 (void) ip_mc_leave_src(sk, iml, in_dev); 2308 (void) ip_mc_leave_src(sk, iml, in_dev);
2309 if (in_dev != NULL) { 2309 if (in_dev != NULL)
2310 ip_mc_dec_group(in_dev, iml->multi.imr_multiaddr.s_addr); 2310 ip_mc_dec_group(in_dev, iml->multi.imr_multiaddr.s_addr);
2311 in_dev_put(in_dev);
2312 }
2313 /* decrease mem now to avoid the memleak warning */ 2311 /* decrease mem now to avoid the memleak warning */
2314 atomic_sub(sizeof(*iml), &sk->sk_omem_alloc); 2312 atomic_sub(sizeof(*iml), &sk->sk_omem_alloc);
2315 call_rcu(&iml->rcu, ip_mc_socklist_reclaim); 2313 call_rcu(&iml->rcu, ip_mc_socklist_reclaim);
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index ba8042665849..2ada17129fce 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -490,9 +490,11 @@ static int inet_csk_diag_dump(struct sock *sk,
490{ 490{
491 struct inet_diag_req *r = NLMSG_DATA(cb->nlh); 491 struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
492 492
493 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) { 493 if (nlmsg_attrlen(cb->nlh, sizeof(*r))) {
494 struct inet_diag_entry entry; 494 struct inet_diag_entry entry;
495 struct rtattr *bc = (struct rtattr *)(r + 1); 495 const struct nlattr *bc = nlmsg_find_attr(cb->nlh,
496 sizeof(*r),
497 INET_DIAG_REQ_BYTECODE);
496 struct inet_sock *inet = inet_sk(sk); 498 struct inet_sock *inet = inet_sk(sk);
497 499
498 entry.family = sk->sk_family; 500 entry.family = sk->sk_family;
@@ -512,7 +514,7 @@ static int inet_csk_diag_dump(struct sock *sk,
512 entry.dport = ntohs(inet->inet_dport); 514 entry.dport = ntohs(inet->inet_dport);
513 entry.userlocks = sk->sk_userlocks; 515 entry.userlocks = sk->sk_userlocks;
514 516
515 if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry)) 517 if (!inet_diag_bc_run(nla_data(bc), nla_len(bc), &entry))
516 return 0; 518 return 0;
517 } 519 }
518 520
@@ -527,9 +529,11 @@ static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
527{ 529{
528 struct inet_diag_req *r = NLMSG_DATA(cb->nlh); 530 struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
529 531
530 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) { 532 if (nlmsg_attrlen(cb->nlh, sizeof(*r))) {
531 struct inet_diag_entry entry; 533 struct inet_diag_entry entry;
532 struct rtattr *bc = (struct rtattr *)(r + 1); 534 const struct nlattr *bc = nlmsg_find_attr(cb->nlh,
535 sizeof(*r),
536 INET_DIAG_REQ_BYTECODE);
533 537
534 entry.family = tw->tw_family; 538 entry.family = tw->tw_family;
535#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) 539#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
@@ -548,7 +552,7 @@ static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
548 entry.dport = ntohs(tw->tw_dport); 552 entry.dport = ntohs(tw->tw_dport);
549 entry.userlocks = 0; 553 entry.userlocks = 0;
550 554
551 if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry)) 555 if (!inet_diag_bc_run(nla_data(bc), nla_len(bc), &entry))
552 return 0; 556 return 0;
553 } 557 }
554 558
@@ -618,7 +622,7 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
618 struct inet_diag_req *r = NLMSG_DATA(cb->nlh); 622 struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
619 struct inet_connection_sock *icsk = inet_csk(sk); 623 struct inet_connection_sock *icsk = inet_csk(sk);
620 struct listen_sock *lopt; 624 struct listen_sock *lopt;
621 struct rtattr *bc = NULL; 625 const struct nlattr *bc = NULL;
622 struct inet_sock *inet = inet_sk(sk); 626 struct inet_sock *inet = inet_sk(sk);
623 int j, s_j; 627 int j, s_j;
624 int reqnum, s_reqnum; 628 int reqnum, s_reqnum;
@@ -638,8 +642,9 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
638 if (!lopt || !lopt->qlen) 642 if (!lopt || !lopt->qlen)
639 goto out; 643 goto out;
640 644
641 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) { 645 if (nlmsg_attrlen(cb->nlh, sizeof(*r))) {
642 bc = (struct rtattr *)(r + 1); 646 bc = nlmsg_find_attr(cb->nlh, sizeof(*r),
647 INET_DIAG_REQ_BYTECODE);
643 entry.sport = inet->inet_num; 648 entry.sport = inet->inet_num;
644 entry.userlocks = sk->sk_userlocks; 649 entry.userlocks = sk->sk_userlocks;
645 } 650 }
@@ -672,8 +677,8 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
672 &ireq->rmt_addr; 677 &ireq->rmt_addr;
673 entry.dport = ntohs(ireq->rmt_port); 678 entry.dport = ntohs(ireq->rmt_port);
674 679
675 if (!inet_diag_bc_run(RTA_DATA(bc), 680 if (!inet_diag_bc_run(nla_data(bc),
676 RTA_PAYLOAD(bc), &entry)) 681 nla_len(bc), &entry))
677 continue; 682 continue;
678 } 683 }
679 684
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 1b344f30b463..3c0369a3a663 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -133,8 +133,7 @@ int __inet_inherit_port(struct sock *sk, struct sock *child)
133 } 133 }
134 } 134 }
135 } 135 }
136 sk_add_bind_node(child, &tb->owners); 136 inet_bind_hash(child, tb, port);
137 inet_csk(child)->icsk_bind_hash = tb;
138 spin_unlock(&head->lock); 137 spin_unlock(&head->lock);
139 138
140 return 0; 139 return 0;
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 01087e035b7d..70ff77f02eee 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -1325,7 +1325,6 @@ static void ipgre_fb_tunnel_init(struct net_device *dev)
1325{ 1325{
1326 struct ip_tunnel *tunnel = netdev_priv(dev); 1326 struct ip_tunnel *tunnel = netdev_priv(dev);
1327 struct iphdr *iph = &tunnel->parms.iph; 1327 struct iphdr *iph = &tunnel->parms.iph;
1328 struct ipgre_net *ign = net_generic(dev_net(dev), ipgre_net_id);
1329 1328
1330 tunnel->dev = dev; 1329 tunnel->dev = dev;
1331 strcpy(tunnel->parms.name, dev->name); 1330 strcpy(tunnel->parms.name, dev->name);
@@ -1336,7 +1335,6 @@ static void ipgre_fb_tunnel_init(struct net_device *dev)
1336 tunnel->hlen = sizeof(struct iphdr) + 4; 1335 tunnel->hlen = sizeof(struct iphdr) + 4;
1337 1336
1338 dev_hold(dev); 1337 dev_hold(dev);
1339 rcu_assign_pointer(ign->tunnels_wc[0], tunnel);
1340} 1338}
1341 1339
1342 1340
@@ -1383,10 +1381,12 @@ static int __net_init ipgre_init_net(struct net *net)
1383 if ((err = register_netdev(ign->fb_tunnel_dev))) 1381 if ((err = register_netdev(ign->fb_tunnel_dev)))
1384 goto err_reg_dev; 1382 goto err_reg_dev;
1385 1383
1384 rcu_assign_pointer(ign->tunnels_wc[0],
1385 netdev_priv(ign->fb_tunnel_dev));
1386 return 0; 1386 return 0;
1387 1387
1388err_reg_dev: 1388err_reg_dev:
1389 free_netdev(ign->fb_tunnel_dev); 1389 ipgre_dev_free(ign->fb_tunnel_dev);
1390err_alloc_dev: 1390err_alloc_dev:
1391 return err; 1391 return err;
1392} 1392}
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 3cad2591ace0..3fac340a28d5 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -927,6 +927,7 @@ static int get_info(struct net *net, void __user *user,
927 private = &tmp; 927 private = &tmp;
928 } 928 }
929#endif 929#endif
930 memset(&info, 0, sizeof(info));
930 info.valid_hooks = t->valid_hooks; 931 info.valid_hooks = t->valid_hooks;
931 memcpy(info.hook_entry, private->hook_entry, 932 memcpy(info.hook_entry, private->hook_entry,
932 sizeof(info.hook_entry)); 933 sizeof(info.hook_entry));
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index d31b007a6d80..a846d633b3b6 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -1124,6 +1124,7 @@ static int get_info(struct net *net, void __user *user,
1124 private = &tmp; 1124 private = &tmp;
1125 } 1125 }
1126#endif 1126#endif
1127 memset(&info, 0, sizeof(info));
1127 info.valid_hooks = t->valid_hooks; 1128 info.valid_hooks = t->valid_hooks;
1128 memcpy(info.hook_entry, private->hook_entry, 1129 memcpy(info.hook_entry, private->hook_entry,
1129 sizeof(info.hook_entry)); 1130 sizeof(info.hook_entry));
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
index 295c97431e43..c04787ce1a71 100644
--- a/net/ipv4/netfilter/nf_nat_core.c
+++ b/net/ipv4/netfilter/nf_nat_core.c
@@ -47,26 +47,6 @@ __nf_nat_proto_find(u_int8_t protonum)
47 return rcu_dereference(nf_nat_protos[protonum]); 47 return rcu_dereference(nf_nat_protos[protonum]);
48} 48}
49 49
50static const struct nf_nat_protocol *
51nf_nat_proto_find_get(u_int8_t protonum)
52{
53 const struct nf_nat_protocol *p;
54
55 rcu_read_lock();
56 p = __nf_nat_proto_find(protonum);
57 if (!try_module_get(p->me))
58 p = &nf_nat_unknown_protocol;
59 rcu_read_unlock();
60
61 return p;
62}
63
64static void
65nf_nat_proto_put(const struct nf_nat_protocol *p)
66{
67 module_put(p->me);
68}
69
70/* We keep an extra hash for each conntrack, for fast searching. */ 50/* We keep an extra hash for each conntrack, for fast searching. */
71static inline unsigned int 51static inline unsigned int
72hash_by_src(const struct net *net, u16 zone, 52hash_by_src(const struct net *net, u16 zone,
@@ -588,6 +568,26 @@ static struct nf_ct_ext_type nat_extend __read_mostly = {
588#include <linux/netfilter/nfnetlink.h> 568#include <linux/netfilter/nfnetlink.h>
589#include <linux/netfilter/nfnetlink_conntrack.h> 569#include <linux/netfilter/nfnetlink_conntrack.h>
590 570
571static const struct nf_nat_protocol *
572nf_nat_proto_find_get(u_int8_t protonum)
573{
574 const struct nf_nat_protocol *p;
575
576 rcu_read_lock();
577 p = __nf_nat_proto_find(protonum);
578 if (!try_module_get(p->me))
579 p = &nf_nat_unknown_protocol;
580 rcu_read_unlock();
581
582 return p;
583}
584
585static void
586nf_nat_proto_put(const struct nf_nat_protocol *p)
587{
588 module_put(p->me);
589}
590
591static const struct nla_policy protonat_nla_policy[CTA_PROTONAT_MAX+1] = { 591static const struct nla_policy protonat_nla_policy[CTA_PROTONAT_MAX+1] = {
592 [CTA_PROTONAT_PORT_MIN] = { .type = NLA_U16 }, 592 [CTA_PROTONAT_PORT_MIN] = { .type = NLA_U16 },
593 [CTA_PROTONAT_PORT_MAX] = { .type = NLA_U16 }, 593 [CTA_PROTONAT_PORT_MAX] = { .type = NLA_U16 },
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index 4ae1f203f7cb..b14ec7d03b6e 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -59,13 +59,13 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)
59 local_bh_enable(); 59 local_bh_enable();
60 60
61 socket_seq_show(seq); 61 socket_seq_show(seq);
62 seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n", 62 seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld\n",
63 sock_prot_inuse_get(net, &tcp_prot), orphans, 63 sock_prot_inuse_get(net, &tcp_prot), orphans,
64 tcp_death_row.tw_count, sockets, 64 tcp_death_row.tw_count, sockets,
65 atomic_read(&tcp_memory_allocated)); 65 atomic_long_read(&tcp_memory_allocated));
66 seq_printf(seq, "UDP: inuse %d mem %d\n", 66 seq_printf(seq, "UDP: inuse %d mem %ld\n",
67 sock_prot_inuse_get(net, &udp_prot), 67 sock_prot_inuse_get(net, &udp_prot),
68 atomic_read(&udp_memory_allocated)); 68 atomic_long_read(&udp_memory_allocated));
69 seq_printf(seq, "UDPLITE: inuse %d\n", 69 seq_printf(seq, "UDPLITE: inuse %d\n",
70 sock_prot_inuse_get(net, &udplite_prot)); 70 sock_prot_inuse_get(net, &udplite_prot));
71 seq_printf(seq, "RAW: inuse %d\n", 71 seq_printf(seq, "RAW: inuse %d\n",
@@ -253,6 +253,7 @@ static const struct snmp_mib snmp4_net_list[] = {
253 SNMP_MIB_ITEM("TCPMinTTLDrop", LINUX_MIB_TCPMINTTLDROP), 253 SNMP_MIB_ITEM("TCPMinTTLDrop", LINUX_MIB_TCPMINTTLDROP),
254 SNMP_MIB_ITEM("TCPDeferAcceptDrop", LINUX_MIB_TCPDEFERACCEPTDROP), 254 SNMP_MIB_ITEM("TCPDeferAcceptDrop", LINUX_MIB_TCPDEFERACCEPTDROP),
255 SNMP_MIB_ITEM("IPReversePathFilter", LINUX_MIB_IPRPFILTER), 255 SNMP_MIB_ITEM("IPReversePathFilter", LINUX_MIB_IPRPFILTER),
256 SNMP_MIB_ITEM("TCPTimeWaitOverflow", LINUX_MIB_TCPTIMEWAITOVERFLOW),
256 SNMP_MIB_SENTINEL 257 SNMP_MIB_SENTINEL
257}; 258};
258 259
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index d96c1da4b17c..1b4ec21497a4 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -26,6 +26,8 @@ static int zero;
26static int tcp_retr1_max = 255; 26static int tcp_retr1_max = 255;
27static int ip_local_port_range_min[] = { 1, 1 }; 27static int ip_local_port_range_min[] = { 1, 1 };
28static int ip_local_port_range_max[] = { 65535, 65535 }; 28static int ip_local_port_range_max[] = { 65535, 65535 };
29static int tcp_adv_win_scale_min = -31;
30static int tcp_adv_win_scale_max = 31;
29 31
30/* Update system visible IP port range */ 32/* Update system visible IP port range */
31static void set_local_port_range(int range[2]) 33static void set_local_port_range(int range[2])
@@ -398,7 +400,7 @@ static struct ctl_table ipv4_table[] = {
398 .data = &sysctl_tcp_mem, 400 .data = &sysctl_tcp_mem,
399 .maxlen = sizeof(sysctl_tcp_mem), 401 .maxlen = sizeof(sysctl_tcp_mem),
400 .mode = 0644, 402 .mode = 0644,
401 .proc_handler = proc_dointvec 403 .proc_handler = proc_doulongvec_minmax
402 }, 404 },
403 { 405 {
404 .procname = "tcp_wmem", 406 .procname = "tcp_wmem",
@@ -426,7 +428,9 @@ static struct ctl_table ipv4_table[] = {
426 .data = &sysctl_tcp_adv_win_scale, 428 .data = &sysctl_tcp_adv_win_scale,
427 .maxlen = sizeof(int), 429 .maxlen = sizeof(int),
428 .mode = 0644, 430 .mode = 0644,
429 .proc_handler = proc_dointvec 431 .proc_handler = proc_dointvec_minmax,
432 .extra1 = &tcp_adv_win_scale_min,
433 .extra2 = &tcp_adv_win_scale_max,
430 }, 434 },
431 { 435 {
432 .procname = "tcp_tw_reuse", 436 .procname = "tcp_tw_reuse",
@@ -602,8 +606,7 @@ static struct ctl_table ipv4_table[] = {
602 .data = &sysctl_udp_mem, 606 .data = &sysctl_udp_mem,
603 .maxlen = sizeof(sysctl_udp_mem), 607 .maxlen = sizeof(sysctl_udp_mem),
604 .mode = 0644, 608 .mode = 0644,
605 .proc_handler = proc_dointvec_minmax, 609 .proc_handler = proc_doulongvec_minmax,
606 .extra1 = &zero
607 }, 610 },
608 { 611 {
609 .procname = "udp_rmem_min", 612 .procname = "udp_rmem_min",
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 1664a0590bb8..f15c36a706ec 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -282,7 +282,7 @@ int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT;
282struct percpu_counter tcp_orphan_count; 282struct percpu_counter tcp_orphan_count;
283EXPORT_SYMBOL_GPL(tcp_orphan_count); 283EXPORT_SYMBOL_GPL(tcp_orphan_count);
284 284
285int sysctl_tcp_mem[3] __read_mostly; 285long sysctl_tcp_mem[3] __read_mostly;
286int sysctl_tcp_wmem[3] __read_mostly; 286int sysctl_tcp_wmem[3] __read_mostly;
287int sysctl_tcp_rmem[3] __read_mostly; 287int sysctl_tcp_rmem[3] __read_mostly;
288 288
@@ -290,7 +290,7 @@ EXPORT_SYMBOL(sysctl_tcp_mem);
290EXPORT_SYMBOL(sysctl_tcp_rmem); 290EXPORT_SYMBOL(sysctl_tcp_rmem);
291EXPORT_SYMBOL(sysctl_tcp_wmem); 291EXPORT_SYMBOL(sysctl_tcp_wmem);
292 292
293atomic_t tcp_memory_allocated; /* Current allocated memory. */ 293atomic_long_t tcp_memory_allocated; /* Current allocated memory. */
294EXPORT_SYMBOL(tcp_memory_allocated); 294EXPORT_SYMBOL(tcp_memory_allocated);
295 295
296/* 296/*
@@ -2246,7 +2246,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
2246 /* Values greater than interface MTU won't take effect. However 2246 /* Values greater than interface MTU won't take effect. However
2247 * at the point when this call is done we typically don't yet 2247 * at the point when this call is done we typically don't yet
2248 * know which interface is going to be used */ 2248 * know which interface is going to be used */
2249 if (val < 8 || val > MAX_TCP_WINDOW) { 2249 if (val < TCP_MIN_MSS || val > MAX_TCP_WINDOW) {
2250 err = -EINVAL; 2250 err = -EINVAL;
2251 break; 2251 break;
2252 } 2252 }
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 3357f69e353d..6d8ab1c4efc3 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -259,8 +259,11 @@ static void tcp_fixup_sndbuf(struct sock *sk)
259 int sndmem = tcp_sk(sk)->rx_opt.mss_clamp + MAX_TCP_HEADER + 16 + 259 int sndmem = tcp_sk(sk)->rx_opt.mss_clamp + MAX_TCP_HEADER + 16 +
260 sizeof(struct sk_buff); 260 sizeof(struct sk_buff);
261 261
262 if (sk->sk_sndbuf < 3 * sndmem) 262 if (sk->sk_sndbuf < 3 * sndmem) {
263 sk->sk_sndbuf = min(3 * sndmem, sysctl_tcp_wmem[2]); 263 sk->sk_sndbuf = 3 * sndmem;
264 if (sk->sk_sndbuf > sysctl_tcp_wmem[2])
265 sk->sk_sndbuf = sysctl_tcp_wmem[2];
266 }
264} 267}
265 268
266/* 2. Tuning advertised window (window_clamp, rcv_ssthresh) 269/* 2. Tuning advertised window (window_clamp, rcv_ssthresh)
@@ -396,7 +399,7 @@ static void tcp_clamp_window(struct sock *sk)
396 if (sk->sk_rcvbuf < sysctl_tcp_rmem[2] && 399 if (sk->sk_rcvbuf < sysctl_tcp_rmem[2] &&
397 !(sk->sk_userlocks & SOCK_RCVBUF_LOCK) && 400 !(sk->sk_userlocks & SOCK_RCVBUF_LOCK) &&
398 !tcp_memory_pressure && 401 !tcp_memory_pressure &&
399 atomic_read(&tcp_memory_allocated) < sysctl_tcp_mem[0]) { 402 atomic_long_read(&tcp_memory_allocated) < sysctl_tcp_mem[0]) {
400 sk->sk_rcvbuf = min(atomic_read(&sk->sk_rmem_alloc), 403 sk->sk_rcvbuf = min(atomic_read(&sk->sk_rmem_alloc),
401 sysctl_tcp_rmem[2]); 404 sysctl_tcp_rmem[2]);
402 } 405 }
@@ -4861,7 +4864,7 @@ static int tcp_should_expand_sndbuf(struct sock *sk)
4861 return 0; 4864 return 0;
4862 4865
4863 /* If we are under soft global TCP memory pressure, do not expand. */ 4866 /* If we are under soft global TCP memory pressure, do not expand. */
4864 if (atomic_read(&tcp_memory_allocated) >= sysctl_tcp_mem[0]) 4867 if (atomic_long_read(&tcp_memory_allocated) >= sysctl_tcp_mem[0])
4865 return 0; 4868 return 0;
4866 4869
4867 /* If we filled the congestion window, do not expand. */ 4870 /* If we filled the congestion window, do not expand. */
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 8f8527d41682..e13da6de1fc7 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -415,6 +415,9 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
415 !icsk->icsk_backoff) 415 !icsk->icsk_backoff)
416 break; 416 break;
417 417
418 if (sock_owned_by_user(sk))
419 break;
420
418 icsk->icsk_backoff--; 421 icsk->icsk_backoff--;
419 inet_csk(sk)->icsk_rto = __tcp_set_rto(tp) << 422 inet_csk(sk)->icsk_rto = __tcp_set_rto(tp) <<
420 icsk->icsk_backoff; 423 icsk->icsk_backoff;
@@ -429,11 +432,6 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
429 if (remaining) { 432 if (remaining) {
430 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, 433 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
431 remaining, TCP_RTO_MAX); 434 remaining, TCP_RTO_MAX);
432 } else if (sock_owned_by_user(sk)) {
433 /* RTO revert clocked out retransmission,
434 * but socket is locked. Will defer. */
435 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
436 HZ/20, TCP_RTO_MAX);
437 } else { 435 } else {
438 /* RTO revert clocked out retransmission. 436 /* RTO revert clocked out retransmission.
439 * Will retransmit now */ 437 * Will retransmit now */
@@ -2045,7 +2043,9 @@ get_req:
2045 } 2043 }
2046get_sk: 2044get_sk:
2047 sk_nulls_for_each_from(sk, node) { 2045 sk_nulls_for_each_from(sk, node) {
2048 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) { 2046 if (!net_eq(sock_net(sk), net))
2047 continue;
2048 if (sk->sk_family == st->family) {
2049 cur = sk; 2049 cur = sk;
2050 goto out; 2050 goto out;
2051 } 2051 }
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 43cf901d7659..a66735f75963 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -347,7 +347,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
347 * socket up. We've got bigger problems than 347 * socket up. We've got bigger problems than
348 * non-graceful socket closings. 348 * non-graceful socket closings.
349 */ 349 */
350 LIMIT_NETDEBUG(KERN_INFO "TCP: time wait bucket table overflow\n"); 350 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPTIMEWAITOVERFLOW);
351 } 351 }
352 352
353 tcp_update_metrics(sk); 353 tcp_update_metrics(sk);
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index e96152207164..8750d4050b48 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -231,11 +231,10 @@ void tcp_select_initial_window(int __space, __u32 mss,
231 /* when initializing use the value from init_rcv_wnd 231 /* when initializing use the value from init_rcv_wnd
232 * rather than the default from above 232 * rather than the default from above
233 */ 233 */
234 if (init_rcv_wnd && 234 if (init_rcv_wnd)
235 (*rcv_wnd > init_rcv_wnd * mss)) 235 *rcv_wnd = min(*rcv_wnd, init_rcv_wnd * mss);
236 *rcv_wnd = init_rcv_wnd * mss; 236 else
237 else if (*rcv_wnd > init_cwnd * mss) 237 *rcv_wnd = min(*rcv_wnd, init_cwnd * mss);
238 *rcv_wnd = init_cwnd * mss;
239 } 238 }
240 239
241 /* Set the clamp no higher than max representable value */ 240 /* Set the clamp no higher than max representable value */
@@ -386,27 +385,30 @@ struct tcp_out_options {
386 */ 385 */
387static u8 tcp_cookie_size_check(u8 desired) 386static u8 tcp_cookie_size_check(u8 desired)
388{ 387{
389 if (desired > 0) { 388 int cookie_size;
389
390 if (desired > 0)
390 /* previously specified */ 391 /* previously specified */
391 return desired; 392 return desired;
392 } 393
393 if (sysctl_tcp_cookie_size <= 0) { 394 cookie_size = ACCESS_ONCE(sysctl_tcp_cookie_size);
395 if (cookie_size <= 0)
394 /* no default specified */ 396 /* no default specified */
395 return 0; 397 return 0;
396 } 398
397 if (sysctl_tcp_cookie_size <= TCP_COOKIE_MIN) { 399 if (cookie_size <= TCP_COOKIE_MIN)
398 /* value too small, specify minimum */ 400 /* value too small, specify minimum */
399 return TCP_COOKIE_MIN; 401 return TCP_COOKIE_MIN;
400 } 402
401 if (sysctl_tcp_cookie_size >= TCP_COOKIE_MAX) { 403 if (cookie_size >= TCP_COOKIE_MAX)
402 /* value too large, specify maximum */ 404 /* value too large, specify maximum */
403 return TCP_COOKIE_MAX; 405 return TCP_COOKIE_MAX;
404 } 406
405 if (0x1 & sysctl_tcp_cookie_size) { 407 if (cookie_size & 1)
406 /* 8-bit multiple, illegal, fix it */ 408 /* 8-bit multiple, illegal, fix it */
407 return (u8)(sysctl_tcp_cookie_size + 0x1); 409 cookie_size++;
408 } 410
409 return (u8)sysctl_tcp_cookie_size; 411 return (u8)cookie_size;
410} 412}
411 413
412/* Write previously computed TCP options to the packet. 414/* Write previously computed TCP options to the packet.
@@ -1513,6 +1515,7 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
1513 struct tcp_sock *tp = tcp_sk(sk); 1515 struct tcp_sock *tp = tcp_sk(sk);
1514 const struct inet_connection_sock *icsk = inet_csk(sk); 1516 const struct inet_connection_sock *icsk = inet_csk(sk);
1515 u32 send_win, cong_win, limit, in_flight; 1517 u32 send_win, cong_win, limit, in_flight;
1518 int win_divisor;
1516 1519
1517 if (TCP_SKB_CB(skb)->flags & TCPHDR_FIN) 1520 if (TCP_SKB_CB(skb)->flags & TCPHDR_FIN)
1518 goto send_now; 1521 goto send_now;
@@ -1544,13 +1547,14 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
1544 if ((skb != tcp_write_queue_tail(sk)) && (limit >= skb->len)) 1547 if ((skb != tcp_write_queue_tail(sk)) && (limit >= skb->len))
1545 goto send_now; 1548 goto send_now;
1546 1549
1547 if (sysctl_tcp_tso_win_divisor) { 1550 win_divisor = ACCESS_ONCE(sysctl_tcp_tso_win_divisor);
1551 if (win_divisor) {
1548 u32 chunk = min(tp->snd_wnd, tp->snd_cwnd * tp->mss_cache); 1552 u32 chunk = min(tp->snd_wnd, tp->snd_cwnd * tp->mss_cache);
1549 1553
1550 /* If at least some fraction of a window is available, 1554 /* If at least some fraction of a window is available,
1551 * just use it. 1555 * just use it.
1552 */ 1556 */
1553 chunk /= sysctl_tcp_tso_win_divisor; 1557 chunk /= win_divisor;
1554 if (limit >= chunk) 1558 if (limit >= chunk)
1555 goto send_now; 1559 goto send_now;
1556 } else { 1560 } else {
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 28cb2d733a3c..5e0a3a582a59 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -110,7 +110,7 @@
110struct udp_table udp_table __read_mostly; 110struct udp_table udp_table __read_mostly;
111EXPORT_SYMBOL(udp_table); 111EXPORT_SYMBOL(udp_table);
112 112
113int sysctl_udp_mem[3] __read_mostly; 113long sysctl_udp_mem[3] __read_mostly;
114EXPORT_SYMBOL(sysctl_udp_mem); 114EXPORT_SYMBOL(sysctl_udp_mem);
115 115
116int sysctl_udp_rmem_min __read_mostly; 116int sysctl_udp_rmem_min __read_mostly;
@@ -119,7 +119,7 @@ EXPORT_SYMBOL(sysctl_udp_rmem_min);
119int sysctl_udp_wmem_min __read_mostly; 119int sysctl_udp_wmem_min __read_mostly;
120EXPORT_SYMBOL(sysctl_udp_wmem_min); 120EXPORT_SYMBOL(sysctl_udp_wmem_min);
121 121
122atomic_t udp_memory_allocated; 122atomic_long_t udp_memory_allocated;
123EXPORT_SYMBOL(udp_memory_allocated); 123EXPORT_SYMBOL(udp_memory_allocated);
124 124
125#define MAX_UDP_PORTS 65536 125#define MAX_UDP_PORTS 65536
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index e048ec62d109..93b7a933a775 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -98,7 +98,11 @@
98#endif 98#endif
99 99
100#define INFINITY_LIFE_TIME 0xFFFFFFFF 100#define INFINITY_LIFE_TIME 0xFFFFFFFF
101#define TIME_DELTA(a, b) ((unsigned long)((long)(a) - (long)(b))) 101
102static inline u32 cstamp_delta(unsigned long cstamp)
103{
104 return (cstamp - INITIAL_JIFFIES) * 100UL / HZ;
105}
102 106
103#define ADDRCONF_TIMER_FUZZ_MINUS (HZ > 50 ? HZ/50 : 1) 107#define ADDRCONF_TIMER_FUZZ_MINUS (HZ > 50 ? HZ/50 : 1)
104#define ADDRCONF_TIMER_FUZZ (HZ / 4) 108#define ADDRCONF_TIMER_FUZZ (HZ / 4)
@@ -2740,10 +2744,6 @@ static int addrconf_ifdown(struct net_device *dev, int how)
2740 /* Flag it for later restoration when link comes up */ 2744 /* Flag it for later restoration when link comes up */
2741 ifa->flags |= IFA_F_TENTATIVE; 2745 ifa->flags |= IFA_F_TENTATIVE;
2742 ifa->state = INET6_IFADDR_STATE_DAD; 2746 ifa->state = INET6_IFADDR_STATE_DAD;
2743
2744 write_unlock_bh(&idev->lock);
2745
2746 in6_ifa_hold(ifa);
2747 } else { 2747 } else {
2748 list_del(&ifa->if_list); 2748 list_del(&ifa->if_list);
2749 2749
@@ -2758,19 +2758,15 @@ static int addrconf_ifdown(struct net_device *dev, int how)
2758 ifa->state = INET6_IFADDR_STATE_DEAD; 2758 ifa->state = INET6_IFADDR_STATE_DEAD;
2759 spin_unlock_bh(&ifa->state_lock); 2759 spin_unlock_bh(&ifa->state_lock);
2760 2760
2761 if (state == INET6_IFADDR_STATE_DEAD) 2761 if (state != INET6_IFADDR_STATE_DEAD) {
2762 goto put_ifa; 2762 __ipv6_ifa_notify(RTM_DELADDR, ifa);
2763 } 2763 atomic_notifier_call_chain(&inet6addr_chain,
2764 2764 NETDEV_DOWN, ifa);
2765 __ipv6_ifa_notify(RTM_DELADDR, ifa); 2765 }
2766 if (ifa->state == INET6_IFADDR_STATE_DEAD)
2767 atomic_notifier_call_chain(&inet6addr_chain,
2768 NETDEV_DOWN, ifa);
2769
2770put_ifa:
2771 in6_ifa_put(ifa);
2772 2766
2773 write_lock_bh(&idev->lock); 2767 in6_ifa_put(ifa);
2768 write_lock_bh(&idev->lock);
2769 }
2774 } 2770 }
2775 2771
2776 list_splice(&keep_list, &idev->addr_list); 2772 list_splice(&keep_list, &idev->addr_list);
@@ -3452,10 +3448,8 @@ static int put_cacheinfo(struct sk_buff *skb, unsigned long cstamp,
3452{ 3448{
3453 struct ifa_cacheinfo ci; 3449 struct ifa_cacheinfo ci;
3454 3450
3455 ci.cstamp = (u32)(TIME_DELTA(cstamp, INITIAL_JIFFIES) / HZ * 100 3451 ci.cstamp = cstamp_delta(cstamp);
3456 + TIME_DELTA(cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ); 3452 ci.tstamp = cstamp_delta(tstamp);
3457 ci.tstamp = (u32)(TIME_DELTA(tstamp, INITIAL_JIFFIES) / HZ * 100
3458 + TIME_DELTA(tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3459 ci.ifa_prefered = preferred; 3453 ci.ifa_prefered = preferred;
3460 ci.ifa_valid = valid; 3454 ci.ifa_valid = valid;
3461 3455
@@ -3806,8 +3800,10 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
3806 array[DEVCONF_AUTOCONF] = cnf->autoconf; 3800 array[DEVCONF_AUTOCONF] = cnf->autoconf;
3807 array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits; 3801 array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits;
3808 array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits; 3802 array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits;
3809 array[DEVCONF_RTR_SOLICIT_INTERVAL] = cnf->rtr_solicit_interval; 3803 array[DEVCONF_RTR_SOLICIT_INTERVAL] =
3810 array[DEVCONF_RTR_SOLICIT_DELAY] = cnf->rtr_solicit_delay; 3804 jiffies_to_msecs(cnf->rtr_solicit_interval);
3805 array[DEVCONF_RTR_SOLICIT_DELAY] =
3806 jiffies_to_msecs(cnf->rtr_solicit_delay);
3811 array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version; 3807 array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version;
3812#ifdef CONFIG_IPV6_PRIVACY 3808#ifdef CONFIG_IPV6_PRIVACY
3813 array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr; 3809 array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr;
@@ -3821,7 +3817,8 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
3821 array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo; 3817 array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo;
3822#ifdef CONFIG_IPV6_ROUTER_PREF 3818#ifdef CONFIG_IPV6_ROUTER_PREF
3823 array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref; 3819 array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref;
3824 array[DEVCONF_RTR_PROBE_INTERVAL] = cnf->rtr_probe_interval; 3820 array[DEVCONF_RTR_PROBE_INTERVAL] =
3821 jiffies_to_msecs(cnf->rtr_probe_interval);
3825#ifdef CONFIG_IPV6_ROUTE_INFO 3822#ifdef CONFIG_IPV6_ROUTE_INFO
3826 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen; 3823 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen;
3827#endif 3824#endif
@@ -3937,10 +3934,9 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
3937 NLA_PUT_U32(skb, IFLA_INET6_FLAGS, idev->if_flags); 3934 NLA_PUT_U32(skb, IFLA_INET6_FLAGS, idev->if_flags);
3938 3935
3939 ci.max_reasm_len = IPV6_MAXPLEN; 3936 ci.max_reasm_len = IPV6_MAXPLEN;
3940 ci.tstamp = (__u32)(TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) / HZ * 100 3937 ci.tstamp = cstamp_delta(idev->tstamp);
3941 + TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ); 3938 ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time);
3942 ci.reachable_time = idev->nd_parms->reachable_time; 3939 ci.retrans_time = jiffies_to_msecs(idev->nd_parms->retrans_time);
3943 ci.retrans_time = idev->nd_parms->retrans_time;
3944 NLA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci); 3940 NLA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci);
3945 3941
3946 nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32)); 3942 nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32));
@@ -4025,11 +4021,11 @@ void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
4025 kfree_skb(skb); 4021 kfree_skb(skb);
4026 goto errout; 4022 goto errout;
4027 } 4023 }
4028 rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC); 4024 rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFINFO, NULL, GFP_ATOMIC);
4029 return; 4025 return;
4030errout: 4026errout:
4031 if (err < 0) 4027 if (err < 0)
4032 rtnl_set_sk_err(net, RTNLGRP_IPV6_IFADDR, err); 4028 rtnl_set_sk_err(net, RTNLGRP_IPV6_IFINFO, err);
4033} 4029}
4034 4030
4035static inline size_t inet6_prefix_nlmsg_size(void) 4031static inline size_t inet6_prefix_nlmsg_size(void)
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 2a59610c2a58..70e891a20fb9 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1175,6 +1175,8 @@ static void ip6_tnl_link_config(struct ip6_tnl *t)
1175 sizeof (struct ipv6hdr); 1175 sizeof (struct ipv6hdr);
1176 1176
1177 dev->mtu = rt->rt6i_dev->mtu - sizeof (struct ipv6hdr); 1177 dev->mtu = rt->rt6i_dev->mtu - sizeof (struct ipv6hdr);
1178 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1179 dev->mtu-=8;
1178 1180
1179 if (dev->mtu < IPV6_MIN_MTU) 1181 if (dev->mtu < IPV6_MIN_MTU)
1180 dev->mtu = IPV6_MIN_MTU; 1182 dev->mtu = IPV6_MIN_MTU;
@@ -1363,12 +1365,17 @@ static const struct net_device_ops ip6_tnl_netdev_ops = {
1363 1365
1364static void ip6_tnl_dev_setup(struct net_device *dev) 1366static void ip6_tnl_dev_setup(struct net_device *dev)
1365{ 1367{
1368 struct ip6_tnl *t;
1369
1366 dev->netdev_ops = &ip6_tnl_netdev_ops; 1370 dev->netdev_ops = &ip6_tnl_netdev_ops;
1367 dev->destructor = ip6_dev_free; 1371 dev->destructor = ip6_dev_free;
1368 1372
1369 dev->type = ARPHRD_TUNNEL6; 1373 dev->type = ARPHRD_TUNNEL6;
1370 dev->hard_header_len = LL_MAX_HEADER + sizeof (struct ipv6hdr); 1374 dev->hard_header_len = LL_MAX_HEADER + sizeof (struct ipv6hdr);
1371 dev->mtu = ETH_DATA_LEN - sizeof (struct ipv6hdr); 1375 dev->mtu = ETH_DATA_LEN - sizeof (struct ipv6hdr);
1376 t = netdev_priv(dev);
1377 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1378 dev->mtu-=8;
1372 dev->flags |= IFF_NOARP; 1379 dev->flags |= IFF_NOARP;
1373 dev->addr_len = sizeof(struct in6_addr); 1380 dev->addr_len = sizeof(struct in6_addr);
1374 dev->features |= NETIF_F_NETNS_LOCAL; 1381 dev->features |= NETIF_F_NETNS_LOCAL;
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 51df035897e7..455582384ece 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -1137,6 +1137,7 @@ static int get_info(struct net *net, void __user *user,
1137 private = &tmp; 1137 private = &tmp;
1138 } 1138 }
1139#endif 1139#endif
1140 memset(&info, 0, sizeof(info));
1140 info.valid_hooks = t->valid_hooks; 1141 info.valid_hooks = t->valid_hooks;
1141 memcpy(info.hook_entry, private->hook_entry, 1142 memcpy(info.hook_entry, private->hook_entry,
1142 sizeof(info.hook_entry)); 1143 sizeof(info.hook_entry));
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 3a3f129a44cb..79d43aa8fa8d 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -286,7 +286,7 @@ found:
286 286
287 /* Check for overlap with preceding fragment. */ 287 /* Check for overlap with preceding fragment. */
288 if (prev && 288 if (prev &&
289 (NFCT_FRAG6_CB(prev)->offset + prev->len) - offset > 0) 289 (NFCT_FRAG6_CB(prev)->offset + prev->len) > offset)
290 goto discard_fq; 290 goto discard_fq;
291 291
292 /* Look for overlap with succeeding segment. */ 292 /* Look for overlap with succeeding segment. */
diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
index d082eaeefa25..24b3558b8e67 100644
--- a/net/ipv6/proc.c
+++ b/net/ipv6/proc.c
@@ -126,6 +126,8 @@ static const struct snmp_mib snmp6_udp6_list[] = {
126 SNMP_MIB_ITEM("Udp6NoPorts", UDP_MIB_NOPORTS), 126 SNMP_MIB_ITEM("Udp6NoPorts", UDP_MIB_NOPORTS),
127 SNMP_MIB_ITEM("Udp6InErrors", UDP_MIB_INERRORS), 127 SNMP_MIB_ITEM("Udp6InErrors", UDP_MIB_INERRORS),
128 SNMP_MIB_ITEM("Udp6OutDatagrams", UDP_MIB_OUTDATAGRAMS), 128 SNMP_MIB_ITEM("Udp6OutDatagrams", UDP_MIB_OUTDATAGRAMS),
129 SNMP_MIB_ITEM("Udp6RcvbufErrors", UDP_MIB_RCVBUFERRORS),
130 SNMP_MIB_ITEM("Udp6SndbufErrors", UDP_MIB_SNDBUFERRORS),
129 SNMP_MIB_SENTINEL 131 SNMP_MIB_SENTINEL
130}; 132};
131 133
@@ -134,6 +136,8 @@ static const struct snmp_mib snmp6_udplite6_list[] = {
134 SNMP_MIB_ITEM("UdpLite6NoPorts", UDP_MIB_NOPORTS), 136 SNMP_MIB_ITEM("UdpLite6NoPorts", UDP_MIB_NOPORTS),
135 SNMP_MIB_ITEM("UdpLite6InErrors", UDP_MIB_INERRORS), 137 SNMP_MIB_ITEM("UdpLite6InErrors", UDP_MIB_INERRORS),
136 SNMP_MIB_ITEM("UdpLite6OutDatagrams", UDP_MIB_OUTDATAGRAMS), 138 SNMP_MIB_ITEM("UdpLite6OutDatagrams", UDP_MIB_OUTDATAGRAMS),
139 SNMP_MIB_ITEM("UdpLite6RcvbufErrors", UDP_MIB_RCVBUFERRORS),
140 SNMP_MIB_ITEM("UdpLite6SndbufErrors", UDP_MIB_SNDBUFERRORS),
137 SNMP_MIB_SENTINEL 141 SNMP_MIB_SENTINEL
138}; 142};
139 143
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index c7ba3149633f..0f2766453759 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -349,7 +349,7 @@ found:
349 349
350 /* Check for overlap with preceding fragment. */ 350 /* Check for overlap with preceding fragment. */
351 if (prev && 351 if (prev &&
352 (FRAG6_CB(prev)->offset + prev->len) - offset > 0) 352 (FRAG6_CB(prev)->offset + prev->len) > offset)
353 goto discard_fq; 353 goto discard_fq;
354 354
355 /* Look for overlap with succeeding segment. */ 355 /* Look for overlap with succeeding segment. */
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 25661f968f3f..96455ffb76fb 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1945,8 +1945,12 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
1945 struct rt6_info *rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops); 1945 struct rt6_info *rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops);
1946 struct neighbour *neigh; 1946 struct neighbour *neigh;
1947 1947
1948 if (rt == NULL) 1948 if (rt == NULL) {
1949 if (net_ratelimit())
1950 pr_warning("IPv6: Maximum number of routes reached,"
1951 " consider increasing route/max_size.\n");
1949 return ERR_PTR(-ENOMEM); 1952 return ERR_PTR(-ENOMEM);
1953 }
1950 1954
1951 dev_hold(net->loopback_dev); 1955 dev_hold(net->loopback_dev);
1952 in6_dev_hold(idev); 1956 in6_dev_hold(idev);
@@ -2741,6 +2745,7 @@ static void __net_exit ip6_route_net_exit(struct net *net)
2741 kfree(net->ipv6.ip6_prohibit_entry); 2745 kfree(net->ipv6.ip6_prohibit_entry);
2742 kfree(net->ipv6.ip6_blk_hole_entry); 2746 kfree(net->ipv6.ip6_blk_hole_entry);
2743#endif 2747#endif
2748 dst_entries_destroy(&net->ipv6.ip6_dst_ops);
2744} 2749}
2745 2750
2746static struct pernet_operations ip6_route_net_ops = { 2751static struct pernet_operations ip6_route_net_ops = {
@@ -2832,5 +2837,6 @@ void ip6_route_cleanup(void)
2832 xfrm6_fini(); 2837 xfrm6_fini();
2833 fib6_gc_cleanup(); 2838 fib6_gc_cleanup();
2834 unregister_pernet_subsys(&ip6_route_net_ops); 2839 unregister_pernet_subsys(&ip6_route_net_ops);
2840 dst_entries_destroy(&ip6_dst_blackhole_ops);
2835 kmem_cache_destroy(ip6_dst_ops_template.kmem_cachep); 2841 kmem_cache_destroy(ip6_dst_ops_template.kmem_cachep);
2836} 2842}
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index d6bfaec3bbbf..8c4d00c7cd2b 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -606,8 +606,9 @@ static int ipip6_rcv(struct sk_buff *skb)
606 return 0; 606 return 0;
607 } 607 }
608 608
609 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); 609 /* no tunnel matched, let upstream know, ipsec may handle it */
610 rcu_read_unlock(); 610 rcu_read_unlock();
611 return 1;
611out: 612out:
612 kfree_skb(skb); 613 kfree_skb(skb);
613 return 0; 614 return 0;
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index 7f097989cde2..a6de3059746d 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -45,7 +45,6 @@
45#include <linux/capability.h> 45#include <linux/capability.h>
46#include <linux/module.h> 46#include <linux/module.h>
47#include <linux/types.h> 47#include <linux/types.h>
48#include <linux/smp_lock.h>
49#include <linux/socket.h> 48#include <linux/socket.h>
50#include <linux/sockios.h> 49#include <linux/sockios.h>
51#include <linux/slab.h> 50#include <linux/slab.h>
diff --git a/net/irda/irnet/irnet_ppp.c b/net/irda/irnet/irnet_ppp.c
index 7fa86373de41..7c567b8aa89a 100644
--- a/net/irda/irnet/irnet_ppp.c
+++ b/net/irda/irnet/irnet_ppp.c
@@ -15,7 +15,6 @@
15 15
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/smp_lock.h>
19#include "irnet_ppp.h" /* Private header */ 18#include "irnet_ppp.h" /* Private header */
20/* Please put other headers in irnet.h - Thanks */ 19/* Please put other headers in irnet.h - Thanks */
21 20
diff --git a/net/irda/irttp.c b/net/irda/irttp.c
index 285761e77d90..f6054f9ccbe3 100644
--- a/net/irda/irttp.c
+++ b/net/irda/irttp.c
@@ -550,22 +550,30 @@ EXPORT_SYMBOL(irttp_close_tsap);
550 */ 550 */
551int irttp_udata_request(struct tsap_cb *self, struct sk_buff *skb) 551int irttp_udata_request(struct tsap_cb *self, struct sk_buff *skb)
552{ 552{
553 int ret;
554
553 IRDA_ASSERT(self != NULL, return -1;); 555 IRDA_ASSERT(self != NULL, return -1;);
554 IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;); 556 IRDA_ASSERT(self->magic == TTP_TSAP_MAGIC, return -1;);
555 IRDA_ASSERT(skb != NULL, return -1;); 557 IRDA_ASSERT(skb != NULL, return -1;);
556 558
557 IRDA_DEBUG(4, "%s()\n", __func__); 559 IRDA_DEBUG(4, "%s()\n", __func__);
558 560
561 /* Take shortcut on zero byte packets */
562 if (skb->len == 0) {
563 ret = 0;
564 goto err;
565 }
566
559 /* Check that nothing bad happens */ 567 /* Check that nothing bad happens */
560 if ((skb->len == 0) || (!self->connected)) { 568 if (!self->connected) {
561 IRDA_DEBUG(1, "%s(), No data, or not connected\n", 569 IRDA_WARNING("%s(), Not connected\n", __func__);
562 __func__); 570 ret = -ENOTCONN;
563 goto err; 571 goto err;
564 } 572 }
565 573
566 if (skb->len > self->max_seg_size) { 574 if (skb->len > self->max_seg_size) {
567 IRDA_DEBUG(1, "%s(), UData is too large for IrLAP!\n", 575 IRDA_ERROR("%s(), UData is too large for IrLAP!\n", __func__);
568 __func__); 576 ret = -EMSGSIZE;
569 goto err; 577 goto err;
570 } 578 }
571 579
@@ -576,7 +584,7 @@ int irttp_udata_request(struct tsap_cb *self, struct sk_buff *skb)
576 584
577err: 585err:
578 dev_kfree_skb(skb); 586 dev_kfree_skb(skb);
579 return -1; 587 return ret;
580} 588}
581EXPORT_SYMBOL(irttp_udata_request); 589EXPORT_SYMBOL(irttp_udata_request);
582 590
@@ -599,9 +607,15 @@ int irttp_data_request(struct tsap_cb *self, struct sk_buff *skb)
599 IRDA_DEBUG(2, "%s() : queue len = %d\n", __func__, 607 IRDA_DEBUG(2, "%s() : queue len = %d\n", __func__,
600 skb_queue_len(&self->tx_queue)); 608 skb_queue_len(&self->tx_queue));
601 609
610 /* Take shortcut on zero byte packets */
611 if (skb->len == 0) {
612 ret = 0;
613 goto err;
614 }
615
602 /* Check that nothing bad happens */ 616 /* Check that nothing bad happens */
603 if ((skb->len == 0) || (!self->connected)) { 617 if (!self->connected) {
604 IRDA_WARNING("%s: No data, or not connected\n", __func__); 618 IRDA_WARNING("%s: Not connected\n", __func__);
605 ret = -ENOTCONN; 619 ret = -ENOTCONN;
606 goto err; 620 goto err;
607 } 621 }
diff --git a/net/l2tp/l2tp_debugfs.c b/net/l2tp/l2tp_debugfs.c
index 104ec3b283d4..b8dbae82fab8 100644
--- a/net/l2tp/l2tp_debugfs.c
+++ b/net/l2tp/l2tp_debugfs.c
@@ -249,7 +249,7 @@ static int l2tp_dfs_seq_open(struct inode *inode, struct file *file)
249 struct seq_file *seq; 249 struct seq_file *seq;
250 int rc = -ENOMEM; 250 int rc = -ENOMEM;
251 251
252 pd = kzalloc(GFP_KERNEL, sizeof(*pd)); 252 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
253 if (pd == NULL) 253 if (pd == NULL)
254 goto out; 254 goto out;
255 255
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 0bf6a59545ab..522e219f3558 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -674,4 +674,8 @@ MODULE_LICENSE("GPL");
674MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); 674MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
675MODULE_DESCRIPTION("L2TP over IP"); 675MODULE_DESCRIPTION("L2TP over IP");
676MODULE_VERSION("1.0"); 676MODULE_VERSION("1.0");
677MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET, SOCK_DGRAM, IPPROTO_L2TP); 677
678/* Use the value of SOCK_DGRAM (2) directory, because __stringify does't like
679 * enums
680 */
681MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET, 2, IPPROTO_L2TP);
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 582612998211..e35dbe55f520 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -317,8 +317,9 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
317 goto out; 317 goto out;
318 rc = -ENODEV; 318 rc = -ENODEV;
319 rtnl_lock(); 319 rtnl_lock();
320 rcu_read_lock();
320 if (sk->sk_bound_dev_if) { 321 if (sk->sk_bound_dev_if) {
321 llc->dev = dev_get_by_index(&init_net, sk->sk_bound_dev_if); 322 llc->dev = dev_get_by_index_rcu(&init_net, sk->sk_bound_dev_if);
322 if (llc->dev) { 323 if (llc->dev) {
323 if (!addr->sllc_arphrd) 324 if (!addr->sllc_arphrd)
324 addr->sllc_arphrd = llc->dev->type; 325 addr->sllc_arphrd = llc->dev->type;
@@ -329,13 +330,13 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
329 !llc_mac_match(addr->sllc_mac, 330 !llc_mac_match(addr->sllc_mac,
330 llc->dev->dev_addr)) { 331 llc->dev->dev_addr)) {
331 rc = -EINVAL; 332 rc = -EINVAL;
332 dev_put(llc->dev);
333 llc->dev = NULL; 333 llc->dev = NULL;
334 } 334 }
335 } 335 }
336 } else 336 } else
337 llc->dev = dev_getbyhwaddr(&init_net, addr->sllc_arphrd, 337 llc->dev = dev_getbyhwaddr(&init_net, addr->sllc_arphrd,
338 addr->sllc_mac); 338 addr->sllc_mac);
339 rcu_read_unlock();
339 rtnl_unlock(); 340 rtnl_unlock();
340 if (!llc->dev) 341 if (!llc->dev)
341 goto out; 342 goto out;
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index 4d6f8653ec88..8e8ea9cb7093 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -92,7 +92,7 @@ config MAC80211_MESH
92config MAC80211_LEDS 92config MAC80211_LEDS
93 bool "Enable LED triggers" 93 bool "Enable LED triggers"
94 depends on MAC80211 94 depends on MAC80211
95 select NEW_LEDS 95 depends on LEDS_CLASS
96 select LEDS_TRIGGERS 96 select LEDS_TRIGGERS
97 ---help--- 97 ---help---
98 This option enables a few LED triggers for different 98 This option enables a few LED triggers for different
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index f9163b12c7f1..7aa85591dbe7 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -391,6 +391,9 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
391 u32 hw_reconf_flags = 0; 391 u32 hw_reconf_flags = 0;
392 int i; 392 int i;
393 393
394 if (local->scan_sdata == sdata)
395 ieee80211_scan_cancel(local);
396
394 clear_bit(SDATA_STATE_RUNNING, &sdata->state); 397 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
395 398
396 /* 399 /*
@@ -523,9 +526,6 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
523 synchronize_rcu(); 526 synchronize_rcu();
524 skb_queue_purge(&sdata->skb_queue); 527 skb_queue_purge(&sdata->skb_queue);
525 528
526 if (local->scan_sdata == sdata)
527 ieee80211_scan_cancel(local);
528
529 /* 529 /*
530 * Disable beaconing here for mesh only, AP and IBSS 530 * Disable beaconing here for mesh only, AP and IBSS
531 * are already taken care of. 531 * are already taken care of.
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 902b03ee8f60..54fb4a0e76f0 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2247,6 +2247,10 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
2247 break; 2247 break;
2248 case cpu_to_le16(IEEE80211_STYPE_DEAUTH): 2248 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2249 case cpu_to_le16(IEEE80211_STYPE_DISASSOC): 2249 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
2250 if (is_multicast_ether_addr(mgmt->da) &&
2251 !is_broadcast_ether_addr(mgmt->da))
2252 return RX_DROP_MONITOR;
2253
2250 /* process only for station */ 2254 /* process only for station */
2251 if (sdata->vif.type != NL80211_IFTYPE_STATION) 2255 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2252 return RX_DROP_MONITOR; 2256 return RX_DROP_MONITOR;
@@ -2741,6 +2745,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2741 2745
2742 if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) 2746 if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
2743 return; 2747 return;
2748 goto out;
2744 } 2749 }
2745 } 2750 }
2746 2751
@@ -2780,6 +2785,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2780 return; 2785 return;
2781 } 2786 }
2782 2787
2788 out:
2783 dev_kfree_skb(skb); 2789 dev_kfree_skb(skb);
2784} 2790}
2785 2791
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 96c594309506..7a637b80a62e 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1587,7 +1587,12 @@ static void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1587 list) { 1587 list) {
1588 if (!ieee80211_sdata_running(tmp_sdata)) 1588 if (!ieee80211_sdata_running(tmp_sdata))
1589 continue; 1589 continue;
1590 if (tmp_sdata->vif.type != NL80211_IFTYPE_AP) 1590 if (tmp_sdata->vif.type ==
1591 NL80211_IFTYPE_MONITOR ||
1592 tmp_sdata->vif.type ==
1593 NL80211_IFTYPE_AP_VLAN ||
1594 tmp_sdata->vif.type ==
1595 NL80211_IFTYPE_WDS)
1591 continue; 1596 continue;
1592 if (compare_ether_addr(tmp_sdata->vif.addr, 1597 if (compare_ether_addr(tmp_sdata->vif.addr,
1593 hdr->addr2) == 0) { 1598 hdr->addr2) == 0) {
@@ -1732,15 +1737,13 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1732 int nh_pos, h_pos; 1737 int nh_pos, h_pos;
1733 struct sta_info *sta = NULL; 1738 struct sta_info *sta = NULL;
1734 u32 sta_flags = 0; 1739 u32 sta_flags = 0;
1740 struct sk_buff *tmp_skb;
1735 1741
1736 if (unlikely(skb->len < ETH_HLEN)) { 1742 if (unlikely(skb->len < ETH_HLEN)) {
1737 ret = NETDEV_TX_OK; 1743 ret = NETDEV_TX_OK;
1738 goto fail; 1744 goto fail;
1739 } 1745 }
1740 1746
1741 nh_pos = skb_network_header(skb) - skb->data;
1742 h_pos = skb_transport_header(skb) - skb->data;
1743
1744 /* convert Ethernet header to proper 802.11 header (based on 1747 /* convert Ethernet header to proper 802.11 header (based on
1745 * operation mode) */ 1748 * operation mode) */
1746 ethertype = (skb->data[12] << 8) | skb->data[13]; 1749 ethertype = (skb->data[12] << 8) | skb->data[13];
@@ -1913,6 +1916,20 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1913 goto fail; 1916 goto fail;
1914 } 1917 }
1915 1918
1919 /*
1920 * If the skb is shared we need to obtain our own copy.
1921 */
1922 if (skb_shared(skb)) {
1923 tmp_skb = skb;
1924 skb = skb_copy(skb, GFP_ATOMIC);
1925 kfree_skb(tmp_skb);
1926
1927 if (!skb) {
1928 ret = NETDEV_TX_OK;
1929 goto fail;
1930 }
1931 }
1932
1916 hdr.frame_control = fc; 1933 hdr.frame_control = fc;
1917 hdr.duration_id = 0; 1934 hdr.duration_id = 0;
1918 hdr.seq_ctrl = 0; 1935 hdr.seq_ctrl = 0;
@@ -1931,6 +1948,9 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1931 encaps_len = 0; 1948 encaps_len = 0;
1932 } 1949 }
1933 1950
1951 nh_pos = skb_network_header(skb) - skb->data;
1952 h_pos = skb_transport_header(skb) - skb->data;
1953
1934 skb_pull(skb, skip_header_bytes); 1954 skb_pull(skb, skip_header_bytes);
1935 nh_pos -= skip_header_bytes; 1955 nh_pos -= skip_header_bytes;
1936 h_pos -= skip_header_bytes; 1956 h_pos -= skip_header_bytes;
diff --git a/net/netfilter/ipvs/Kconfig b/net/netfilter/ipvs/Kconfig
index a22dac227055..70bd1d0774c6 100644
--- a/net/netfilter/ipvs/Kconfig
+++ b/net/netfilter/ipvs/Kconfig
@@ -4,6 +4,7 @@
4menuconfig IP_VS 4menuconfig IP_VS
5 tristate "IP virtual server support" 5 tristate "IP virtual server support"
6 depends on NET && INET && NETFILTER 6 depends on NET && INET && NETFILTER
7 depends on (NF_CONNTRACK || NF_CONNTRACK=n)
7 ---help--- 8 ---help---
8 IP Virtual Server support will let you build a high-performance 9 IP Virtual Server support will let you build a high-performance
9 virtual server based on cluster of two or more real servers. This 10 virtual server based on cluster of two or more real servers. This
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 1eacf8d9966a..27a5ea6b6a0f 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1312,7 +1312,8 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced, int nulls)
1312 if (!hash) { 1312 if (!hash) {
1313 *vmalloced = 1; 1313 *vmalloced = 1;
1314 printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n"); 1314 printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n");
1315 hash = __vmalloc(sz, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL); 1315 hash = __vmalloc(sz, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
1316 PAGE_KERNEL);
1316 } 1317 }
1317 1318
1318 if (hash && nulls) 1319 if (hash && nulls)
diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
index ed6d92958023..dc7bb74110df 100644
--- a/net/netfilter/nf_conntrack_proto.c
+++ b/net/netfilter/nf_conntrack_proto.c
@@ -292,6 +292,12 @@ int nf_conntrack_l4proto_register(struct nf_conntrack_l4proto *l4proto)
292 292
293 for (i = 0; i < MAX_NF_CT_PROTO; i++) 293 for (i = 0; i < MAX_NF_CT_PROTO; i++)
294 proto_array[i] = &nf_conntrack_l4proto_generic; 294 proto_array[i] = &nf_conntrack_l4proto_generic;
295
296 /* Before making proto_array visible to lockless readers,
297 * we must make sure its content is committed to memory.
298 */
299 smp_wmb();
300
295 nf_ct_protos[l4proto->l3proto] = proto_array; 301 nf_ct_protos[l4proto->l3proto] = proto_array;
296 } else if (nf_ct_protos[l4proto->l3proto][l4proto->l4proto] != 302 } else if (nf_ct_protos[l4proto->l3proto][l4proto->l4proto] !=
297 &nf_conntrack_l4proto_generic) { 303 &nf_conntrack_l4proto_generic) {
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 3616f27b9d46..8298e676f5a0 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1610,9 +1610,11 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
1610 1610
1611 err = -EINVAL; 1611 err = -EINVAL;
1612 vnet_hdr_len = sizeof(vnet_hdr); 1612 vnet_hdr_len = sizeof(vnet_hdr);
1613 if ((len -= vnet_hdr_len) < 0) 1613 if (len < vnet_hdr_len)
1614 goto out_free; 1614 goto out_free;
1615 1615
1616 len -= vnet_hdr_len;
1617
1616 if (skb_is_gso(skb)) { 1618 if (skb_is_gso(skb)) {
1617 struct skb_shared_info *sinfo = skb_shinfo(skb); 1619 struct skb_shared_info *sinfo = skb_shinfo(skb);
1618 1620
@@ -1719,7 +1721,7 @@ static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
1719 rcu_read_lock(); 1721 rcu_read_lock();
1720 dev = dev_get_by_index_rcu(sock_net(sk), pkt_sk(sk)->ifindex); 1722 dev = dev_get_by_index_rcu(sock_net(sk), pkt_sk(sk)->ifindex);
1721 if (dev) 1723 if (dev)
1722 strlcpy(uaddr->sa_data, dev->name, 15); 1724 strncpy(uaddr->sa_data, dev->name, 14);
1723 else 1725 else
1724 memset(uaddr->sa_data, 0, 14); 1726 memset(uaddr->sa_data, 0, 14);
1725 rcu_read_unlock(); 1727 rcu_read_unlock();
@@ -1742,6 +1744,7 @@ static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
1742 sll->sll_family = AF_PACKET; 1744 sll->sll_family = AF_PACKET;
1743 sll->sll_ifindex = po->ifindex; 1745 sll->sll_ifindex = po->ifindex;
1744 sll->sll_protocol = po->num; 1746 sll->sll_protocol = po->num;
1747 sll->sll_pkttype = 0;
1745 rcu_read_lock(); 1748 rcu_read_lock();
1746 dev = dev_get_by_index_rcu(sock_net(sk), po->ifindex); 1749 dev = dev_get_by_index_rcu(sock_net(sk), po->ifindex);
1747 if (dev) { 1750 if (dev) {
diff --git a/net/rds/loop.c b/net/rds/loop.c
index c390156b426f..aeec1d483b17 100644
--- a/net/rds/loop.c
+++ b/net/rds/loop.c
@@ -134,8 +134,12 @@ static int rds_loop_conn_alloc(struct rds_connection *conn, gfp_t gfp)
134static void rds_loop_conn_free(void *arg) 134static void rds_loop_conn_free(void *arg)
135{ 135{
136 struct rds_loop_connection *lc = arg; 136 struct rds_loop_connection *lc = arg;
137 unsigned long flags;
138
137 rdsdebug("lc %p\n", lc); 139 rdsdebug("lc %p\n", lc);
140 spin_lock_irqsave(&loop_conns_lock, flags);
138 list_del(&lc->loop_node); 141 list_del(&lc->loop_node);
142 spin_unlock_irqrestore(&loop_conns_lock, flags);
139 kfree(lc); 143 kfree(lc);
140} 144}
141 145
diff --git a/net/rds/message.c b/net/rds/message.c
index a84545dae370..1fd3d29023d7 100644
--- a/net/rds/message.c
+++ b/net/rds/message.c
@@ -224,6 +224,9 @@ struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents)
224 WARN_ON(rm->m_used_sgs + nents > rm->m_total_sgs); 224 WARN_ON(rm->m_used_sgs + nents > rm->m_total_sgs);
225 WARN_ON(!nents); 225 WARN_ON(!nents);
226 226
227 if (rm->m_used_sgs + nents > rm->m_total_sgs)
228 return NULL;
229
227 sg_ret = &sg_first[rm->m_used_sgs]; 230 sg_ret = &sg_first[rm->m_used_sgs];
228 sg_init_table(sg_ret, nents); 231 sg_init_table(sg_ret, nents);
229 rm->m_used_sgs += nents; 232 rm->m_used_sgs += nents;
@@ -246,6 +249,10 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in
246 rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len); 249 rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len);
247 rm->data.op_nents = ceil(total_len, PAGE_SIZE); 250 rm->data.op_nents = ceil(total_len, PAGE_SIZE);
248 rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs); 251 rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs);
252 if (!rm->data.op_sg) {
253 rds_message_put(rm);
254 return ERR_PTR(-ENOMEM);
255 }
249 256
250 for (i = 0; i < rm->data.op_nents; ++i) { 257 for (i = 0; i < rm->data.op_nents; ++i) {
251 sg_set_page(&rm->data.op_sg[i], 258 sg_set_page(&rm->data.op_sg[i],
diff --git a/net/rds/rdma.c b/net/rds/rdma.c
index 1a41debca1ce..4e37c1cbe8b2 100644
--- a/net/rds/rdma.c
+++ b/net/rds/rdma.c
@@ -479,13 +479,38 @@ void rds_atomic_free_op(struct rm_atomic_op *ao)
479 479
480 480
481/* 481/*
482 * Count the number of pages needed to describe an incoming iovec. 482 * Count the number of pages needed to describe an incoming iovec array.
483 */ 483 */
484static int rds_rdma_pages(struct rds_rdma_args *args) 484static int rds_rdma_pages(struct rds_iovec iov[], int nr_iovecs)
485{
486 int tot_pages = 0;
487 unsigned int nr_pages;
488 unsigned int i;
489
490 /* figure out the number of pages in the vector */
491 for (i = 0; i < nr_iovecs; i++) {
492 nr_pages = rds_pages_in_vec(&iov[i]);
493 if (nr_pages == 0)
494 return -EINVAL;
495
496 tot_pages += nr_pages;
497
498 /*
499 * nr_pages for one entry is limited to (UINT_MAX>>PAGE_SHIFT)+1,
500 * so tot_pages cannot overflow without first going negative.
501 */
502 if (tot_pages < 0)
503 return -EINVAL;
504 }
505
506 return tot_pages;
507}
508
509int rds_rdma_extra_size(struct rds_rdma_args *args)
485{ 510{
486 struct rds_iovec vec; 511 struct rds_iovec vec;
487 struct rds_iovec __user *local_vec; 512 struct rds_iovec __user *local_vec;
488 unsigned int tot_pages = 0; 513 int tot_pages = 0;
489 unsigned int nr_pages; 514 unsigned int nr_pages;
490 unsigned int i; 515 unsigned int i;
491 516
@@ -502,14 +527,16 @@ static int rds_rdma_pages(struct rds_rdma_args *args)
502 return -EINVAL; 527 return -EINVAL;
503 528
504 tot_pages += nr_pages; 529 tot_pages += nr_pages;
505 }
506 530
507 return tot_pages; 531 /*
508} 532 * nr_pages for one entry is limited to (UINT_MAX>>PAGE_SHIFT)+1,
533 * so tot_pages cannot overflow without first going negative.
534 */
535 if (tot_pages < 0)
536 return -EINVAL;
537 }
509 538
510int rds_rdma_extra_size(struct rds_rdma_args *args) 539 return tot_pages * sizeof(struct scatterlist);
511{
512 return rds_rdma_pages(args) * sizeof(struct scatterlist);
513} 540}
514 541
515/* 542/*
@@ -520,13 +547,12 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
520 struct cmsghdr *cmsg) 547 struct cmsghdr *cmsg)
521{ 548{
522 struct rds_rdma_args *args; 549 struct rds_rdma_args *args;
523 struct rds_iovec vec;
524 struct rm_rdma_op *op = &rm->rdma; 550 struct rm_rdma_op *op = &rm->rdma;
525 int nr_pages; 551 int nr_pages;
526 unsigned int nr_bytes; 552 unsigned int nr_bytes;
527 struct page **pages = NULL; 553 struct page **pages = NULL;
528 struct rds_iovec __user *local_vec; 554 struct rds_iovec iovstack[UIO_FASTIOV], *iovs = iovstack;
529 unsigned int nr; 555 int iov_size;
530 unsigned int i, j; 556 unsigned int i, j;
531 int ret = 0; 557 int ret = 0;
532 558
@@ -541,14 +567,31 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
541 goto out; 567 goto out;
542 } 568 }
543 569
544 if (args->nr_local > (u64)UINT_MAX) { 570 if (args->nr_local > UIO_MAXIOV) {
545 ret = -EMSGSIZE; 571 ret = -EMSGSIZE;
546 goto out; 572 goto out;
547 } 573 }
548 574
549 nr_pages = rds_rdma_pages(args); 575 /* Check whether to allocate the iovec area */
550 if (nr_pages < 0) 576 iov_size = args->nr_local * sizeof(struct rds_iovec);
577 if (args->nr_local > UIO_FASTIOV) {
578 iovs = sock_kmalloc(rds_rs_to_sk(rs), iov_size, GFP_KERNEL);
579 if (!iovs) {
580 ret = -ENOMEM;
581 goto out;
582 }
583 }
584
585 if (copy_from_user(iovs, (struct rds_iovec __user *)(unsigned long) args->local_vec_addr, iov_size)) {
586 ret = -EFAULT;
587 goto out;
588 }
589
590 nr_pages = rds_rdma_pages(iovs, args->nr_local);
591 if (nr_pages < 0) {
592 ret = -EINVAL;
551 goto out; 593 goto out;
594 }
552 595
553 pages = kcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL); 596 pages = kcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL);
554 if (!pages) { 597 if (!pages) {
@@ -564,6 +607,10 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
564 op->op_recverr = rs->rs_recverr; 607 op->op_recverr = rs->rs_recverr;
565 WARN_ON(!nr_pages); 608 WARN_ON(!nr_pages);
566 op->op_sg = rds_message_alloc_sgs(rm, nr_pages); 609 op->op_sg = rds_message_alloc_sgs(rm, nr_pages);
610 if (!op->op_sg) {
611 ret = -ENOMEM;
612 goto out;
613 }
567 614
568 if (op->op_notify || op->op_recverr) { 615 if (op->op_notify || op->op_recverr) {
569 /* We allocate an uninitialized notifier here, because 616 /* We allocate an uninitialized notifier here, because
@@ -597,50 +644,40 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
597 (unsigned long long)args->remote_vec.addr, 644 (unsigned long long)args->remote_vec.addr,
598 op->op_rkey); 645 op->op_rkey);
599 646
600 local_vec = (struct rds_iovec __user *)(unsigned long) args->local_vec_addr;
601
602 for (i = 0; i < args->nr_local; i++) { 647 for (i = 0; i < args->nr_local; i++) {
603 if (copy_from_user(&vec, &local_vec[i], 648 struct rds_iovec *iov = &iovs[i];
604 sizeof(struct rds_iovec))) { 649 /* don't need to check, rds_rdma_pages() verified nr will be +nonzero */
605 ret = -EFAULT; 650 unsigned int nr = rds_pages_in_vec(iov);
606 goto out;
607 }
608
609 nr = rds_pages_in_vec(&vec);
610 if (nr == 0) {
611 ret = -EINVAL;
612 goto out;
613 }
614 651
615 rs->rs_user_addr = vec.addr; 652 rs->rs_user_addr = iov->addr;
616 rs->rs_user_bytes = vec.bytes; 653 rs->rs_user_bytes = iov->bytes;
617 654
618 /* If it's a WRITE operation, we want to pin the pages for reading. 655 /* If it's a WRITE operation, we want to pin the pages for reading.
619 * If it's a READ operation, we need to pin the pages for writing. 656 * If it's a READ operation, we need to pin the pages for writing.
620 */ 657 */
621 ret = rds_pin_pages(vec.addr, nr, pages, !op->op_write); 658 ret = rds_pin_pages(iov->addr, nr, pages, !op->op_write);
622 if (ret < 0) 659 if (ret < 0)
623 goto out; 660 goto out;
624 661
625 rdsdebug("RDS: nr_bytes %u nr %u vec.bytes %llu vec.addr %llx\n", 662 rdsdebug("RDS: nr_bytes %u nr %u iov->bytes %llu iov->addr %llx\n",
626 nr_bytes, nr, vec.bytes, vec.addr); 663 nr_bytes, nr, iov->bytes, iov->addr);
627 664
628 nr_bytes += vec.bytes; 665 nr_bytes += iov->bytes;
629 666
630 for (j = 0; j < nr; j++) { 667 for (j = 0; j < nr; j++) {
631 unsigned int offset = vec.addr & ~PAGE_MASK; 668 unsigned int offset = iov->addr & ~PAGE_MASK;
632 struct scatterlist *sg; 669 struct scatterlist *sg;
633 670
634 sg = &op->op_sg[op->op_nents + j]; 671 sg = &op->op_sg[op->op_nents + j];
635 sg_set_page(sg, pages[j], 672 sg_set_page(sg, pages[j],
636 min_t(unsigned int, vec.bytes, PAGE_SIZE - offset), 673 min_t(unsigned int, iov->bytes, PAGE_SIZE - offset),
637 offset); 674 offset);
638 675
639 rdsdebug("RDS: sg->offset %x sg->len %x vec.addr %llx vec.bytes %llu\n", 676 rdsdebug("RDS: sg->offset %x sg->len %x iov->addr %llx iov->bytes %llu\n",
640 sg->offset, sg->length, vec.addr, vec.bytes); 677 sg->offset, sg->length, iov->addr, iov->bytes);
641 678
642 vec.addr += sg->length; 679 iov->addr += sg->length;
643 vec.bytes -= sg->length; 680 iov->bytes -= sg->length;
644 } 681 }
645 682
646 op->op_nents += nr; 683 op->op_nents += nr;
@@ -655,13 +692,14 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
655 } 692 }
656 op->op_bytes = nr_bytes; 693 op->op_bytes = nr_bytes;
657 694
658 ret = 0;
659out: 695out:
696 if (iovs != iovstack)
697 sock_kfree_s(rds_rs_to_sk(rs), iovs, iov_size);
660 kfree(pages); 698 kfree(pages);
661 if (ret) 699 if (ret)
662 rds_rdma_free_op(op); 700 rds_rdma_free_op(op);
663 701 else
664 rds_stats_inc(s_send_rdma); 702 rds_stats_inc(s_send_rdma);
665 703
666 return ret; 704 return ret;
667} 705}
@@ -773,6 +811,10 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm,
773 rm->atomic.op_active = 1; 811 rm->atomic.op_active = 1;
774 rm->atomic.op_recverr = rs->rs_recverr; 812 rm->atomic.op_recverr = rs->rs_recverr;
775 rm->atomic.op_sg = rds_message_alloc_sgs(rm, 1); 813 rm->atomic.op_sg = rds_message_alloc_sgs(rm, 1);
814 if (!rm->atomic.op_sg) {
815 ret = -ENOMEM;
816 goto err;
817 }
776 818
777 /* verify 8 byte-aligned */ 819 /* verify 8 byte-aligned */
778 if (args->local_addr & 0x7) { 820 if (args->local_addr & 0x7) {
diff --git a/net/rds/send.c b/net/rds/send.c
index 0bc9db17a87d..35b9c2e9caf1 100644
--- a/net/rds/send.c
+++ b/net/rds/send.c
@@ -973,6 +973,10 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
973 /* Attach data to the rm */ 973 /* Attach data to the rm */
974 if (payload_len) { 974 if (payload_len) {
975 rm->data.op_sg = rds_message_alloc_sgs(rm, ceil(payload_len, PAGE_SIZE)); 975 rm->data.op_sg = rds_message_alloc_sgs(rm, ceil(payload_len, PAGE_SIZE));
976 if (!rm->data.op_sg) {
977 ret = -ENOMEM;
978 goto out;
979 }
976 ret = rds_message_copy_from_user(rm, msg->msg_iov, payload_len); 980 ret = rds_message_copy_from_user(rm, msg->msg_iov, payload_len);
977 if (ret) 981 if (ret)
978 goto out; 982 goto out;
diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index 08a8c6cf2d10..8e0a32001c90 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -221,7 +221,13 @@ static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
221static void rds_tcp_conn_free(void *arg) 221static void rds_tcp_conn_free(void *arg)
222{ 222{
223 struct rds_tcp_connection *tc = arg; 223 struct rds_tcp_connection *tc = arg;
224 unsigned long flags;
224 rdsdebug("freeing tc %p\n", tc); 225 rdsdebug("freeing tc %p\n", tc);
226
227 spin_lock_irqsave(&rds_tcp_conn_lock, flags);
228 list_del(&tc->t_tcp_node);
229 spin_unlock_irqrestore(&rds_tcp_conn_lock, flags);
230
225 kmem_cache_free(rds_tcp_conn_slab, tc); 231 kmem_cache_free(rds_tcp_conn_slab, tc);
226} 232}
227 233
diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c
index efd4f95fd050..f23d9155b1ef 100644
--- a/net/sched/cls_basic.c
+++ b/net/sched/cls_basic.c
@@ -268,6 +268,10 @@ static int basic_dump(struct tcf_proto *tp, unsigned long fh,
268 goto nla_put_failure; 268 goto nla_put_failure;
269 269
270 nla_nest_end(skb, nest); 270 nla_nest_end(skb, nest);
271
272 if (tcf_exts_dump_stats(skb, &f->exts, &basic_ext_map) < 0)
273 goto nla_put_failure;
274
271 return skb->len; 275 return skb->len;
272 276
273nla_put_failure: 277nla_put_failure:
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 37dff78e9cb1..d49c40fb7e09 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -34,8 +34,6 @@ struct cgroup_subsys net_cls_subsys = {
34 .populate = cgrp_populate, 34 .populate = cgrp_populate,
35#ifdef CONFIG_NET_CLS_CGROUP 35#ifdef CONFIG_NET_CLS_CGROUP
36 .subsys_id = net_cls_subsys_id, 36 .subsys_id = net_cls_subsys_id,
37#else
38#define net_cls_subsys_id net_cls_subsys.subsys_id
39#endif 37#endif
40 .module = THIS_MODULE, 38 .module = THIS_MODULE,
41}; 39};
diff --git a/net/sched/em_text.c b/net/sched/em_text.c
index 763253257411..ea8f566e720c 100644
--- a/net/sched/em_text.c
+++ b/net/sched/em_text.c
@@ -103,7 +103,8 @@ retry:
103 103
104static void em_text_destroy(struct tcf_proto *tp, struct tcf_ematch *m) 104static void em_text_destroy(struct tcf_proto *tp, struct tcf_ematch *m)
105{ 105{
106 textsearch_destroy(EM_TEXT_PRIV(m)->config); 106 if (EM_TEXT_PRIV(m) && EM_TEXT_PRIV(m)->config)
107 textsearch_destroy(EM_TEXT_PRIV(m)->config);
107} 108}
108 109
109static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m) 110static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m)
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 1ef29c74d85e..e58f9476f29c 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -92,7 +92,7 @@ static struct sctp_af *sctp_af_v6_specific;
92struct kmem_cache *sctp_chunk_cachep __read_mostly; 92struct kmem_cache *sctp_chunk_cachep __read_mostly;
93struct kmem_cache *sctp_bucket_cachep __read_mostly; 93struct kmem_cache *sctp_bucket_cachep __read_mostly;
94 94
95int sysctl_sctp_mem[3]; 95long sysctl_sctp_mem[3];
96int sysctl_sctp_rmem[3]; 96int sysctl_sctp_rmem[3];
97int sysctl_sctp_wmem[3]; 97int sysctl_sctp_wmem[3];
98 98
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index e34ca9cc1167..0b9ee34ad35c 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -111,12 +111,12 @@ static void sctp_sock_migrate(struct sock *, struct sock *,
111static char *sctp_hmac_alg = SCTP_COOKIE_HMAC_ALG; 111static char *sctp_hmac_alg = SCTP_COOKIE_HMAC_ALG;
112 112
113extern struct kmem_cache *sctp_bucket_cachep; 113extern struct kmem_cache *sctp_bucket_cachep;
114extern int sysctl_sctp_mem[3]; 114extern long sysctl_sctp_mem[3];
115extern int sysctl_sctp_rmem[3]; 115extern int sysctl_sctp_rmem[3];
116extern int sysctl_sctp_wmem[3]; 116extern int sysctl_sctp_wmem[3];
117 117
118static int sctp_memory_pressure; 118static int sctp_memory_pressure;
119static atomic_t sctp_memory_allocated; 119static atomic_long_t sctp_memory_allocated;
120struct percpu_counter sctp_sockets_allocated; 120struct percpu_counter sctp_sockets_allocated;
121 121
122static void sctp_enter_memory_pressure(struct sock *sk) 122static void sctp_enter_memory_pressure(struct sock *sk)
@@ -2932,6 +2932,7 @@ static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optva
2932 struct sctp_association *asoc = NULL; 2932 struct sctp_association *asoc = NULL;
2933 struct sctp_setpeerprim prim; 2933 struct sctp_setpeerprim prim;
2934 struct sctp_chunk *chunk; 2934 struct sctp_chunk *chunk;
2935 struct sctp_af *af;
2935 int err; 2936 int err;
2936 2937
2937 sp = sctp_sk(sk); 2938 sp = sctp_sk(sk);
@@ -2959,6 +2960,13 @@ static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optva
2959 if (!sctp_state(asoc, ESTABLISHED)) 2960 if (!sctp_state(asoc, ESTABLISHED))
2960 return -ENOTCONN; 2961 return -ENOTCONN;
2961 2962
2963 af = sctp_get_af_specific(prim.sspp_addr.ss_family);
2964 if (!af)
2965 return -EINVAL;
2966
2967 if (!af->addr_valid((union sctp_addr *)&prim.sspp_addr, sp, NULL))
2968 return -EADDRNOTAVAIL;
2969
2962 if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim.sspp_addr)) 2970 if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim.sspp_addr))
2963 return -EADDRNOTAVAIL; 2971 return -EADDRNOTAVAIL;
2964 2972
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 832590bbe0c0..50cb57f0919e 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -54,7 +54,7 @@ static int sack_timer_max = 500;
54static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */ 54static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */
55static int rwnd_scale_max = 16; 55static int rwnd_scale_max = 16;
56 56
57extern int sysctl_sctp_mem[3]; 57extern long sysctl_sctp_mem[3];
58extern int sysctl_sctp_rmem[3]; 58extern int sysctl_sctp_rmem[3];
59extern int sysctl_sctp_wmem[3]; 59extern int sysctl_sctp_wmem[3];
60 60
@@ -203,7 +203,7 @@ static ctl_table sctp_table[] = {
203 .data = &sysctl_sctp_mem, 203 .data = &sysctl_sctp_mem,
204 .maxlen = sizeof(sysctl_sctp_mem), 204 .maxlen = sizeof(sysctl_sctp_mem),
205 .mode = 0644, 205 .mode = 0644,
206 .proc_handler = proc_dointvec, 206 .proc_handler = proc_doulongvec_minmax
207 }, 207 },
208 { 208 {
209 .procname = "sctp_rmem", 209 .procname = "sctp_rmem",
diff --git a/net/socket.c b/net/socket.c
index 5247ae10f374..088fb3fd45e0 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -732,6 +732,21 @@ static int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg,
732 return ret; 732 return ret;
733} 733}
734 734
735/**
736 * kernel_recvmsg - Receive a message from a socket (kernel space)
737 * @sock: The socket to receive the message from
738 * @msg: Received message
739 * @vec: Input s/g array for message data
740 * @num: Size of input s/g array
741 * @size: Number of bytes to read
742 * @flags: Message flags (MSG_DONTWAIT, etc...)
743 *
744 * On return the msg structure contains the scatter/gather array passed in the
745 * vec argument. The array is modified so that it consists of the unfilled
746 * portion of the original array.
747 *
748 * The returned value is the total number of bytes received, or an error.
749 */
735int kernel_recvmsg(struct socket *sock, struct msghdr *msg, 750int kernel_recvmsg(struct socket *sock, struct msghdr *msg,
736 struct kvec *vec, size_t num, size_t size, int flags) 751 struct kvec *vec, size_t num, size_t size, int flags)
737{ 752{
@@ -1652,6 +1667,8 @@ SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
1652 struct iovec iov; 1667 struct iovec iov;
1653 int fput_needed; 1668 int fput_needed;
1654 1669
1670 if (len > INT_MAX)
1671 len = INT_MAX;
1655 sock = sockfd_lookup_light(fd, &err, &fput_needed); 1672 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1656 if (!sock) 1673 if (!sock)
1657 goto out; 1674 goto out;
@@ -1709,6 +1726,8 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
1709 int err, err2; 1726 int err, err2;
1710 int fput_needed; 1727 int fput_needed;
1711 1728
1729 if (size > INT_MAX)
1730 size = INT_MAX;
1712 sock = sockfd_lookup_light(fd, &err, &fput_needed); 1731 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1713 if (!sock) 1732 if (!sock)
1714 goto out; 1733 goto out;
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 9dab9573be41..92ce94f5146b 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -989,20 +989,26 @@ call_refreshresult(struct rpc_task *task)
989 dprint_status(task); 989 dprint_status(task);
990 990
991 task->tk_status = 0; 991 task->tk_status = 0;
992 task->tk_action = call_allocate; 992 task->tk_action = call_refresh;
993 if (status >= 0 && rpcauth_uptodatecred(task))
994 return;
995 switch (status) { 993 switch (status) {
996 case -EACCES: 994 case 0:
997 rpc_exit(task, -EACCES); 995 if (rpcauth_uptodatecred(task))
998 return; 996 task->tk_action = call_allocate;
999 case -ENOMEM:
1000 rpc_exit(task, -ENOMEM);
1001 return; 997 return;
1002 case -ETIMEDOUT: 998 case -ETIMEDOUT:
1003 rpc_delay(task, 3*HZ); 999 rpc_delay(task, 3*HZ);
1000 case -EAGAIN:
1001 status = -EACCES;
1002 if (!task->tk_cred_retry)
1003 break;
1004 task->tk_cred_retry--;
1005 dprintk("RPC: %5u %s: retry refresh creds\n",
1006 task->tk_pid, __func__);
1007 return;
1004 } 1008 }
1005 task->tk_action = call_refresh; 1009 dprintk("RPC: %5u %s: refresh creds failed with error %d\n",
1010 task->tk_pid, __func__, status);
1011 rpc_exit(task, status);
1006} 1012}
1007 1013
1008/* 1014/*
diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
index f71a73107ae9..80df89d957ba 100644
--- a/net/sunrpc/stats.c
+++ b/net/sunrpc/stats.c
@@ -115,9 +115,7 @@ EXPORT_SYMBOL_GPL(svc_seq_show);
115 */ 115 */
116struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt) 116struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt)
117{ 117{
118 struct rpc_iostats *new; 118 return kcalloc(clnt->cl_maxproc, sizeof(struct rpc_iostats), GFP_KERNEL);
119 new = kcalloc(clnt->cl_maxproc, sizeof(struct rpc_iostats), GFP_KERNEL);
120 return new;
121} 119}
122EXPORT_SYMBOL_GPL(rpc_alloc_iostats); 120EXPORT_SYMBOL_GPL(rpc_alloc_iostats);
123 121
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index c82fe739fbdc..3f2c5559ca1a 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -5,7 +5,6 @@
5 */ 5 */
6 6
7#include <linux/sched.h> 7#include <linux/sched.h>
8#include <linux/smp_lock.h>
9#include <linux/errno.h> 8#include <linux/errno.h>
10#include <linux/freezer.h> 9#include <linux/freezer.h>
11#include <linux/kthread.h> 10#include <linux/kthread.h>
@@ -213,6 +212,7 @@ int svc_create_xprt(struct svc_serv *serv, const char *xprt_name,
213 spin_lock(&svc_xprt_class_lock); 212 spin_lock(&svc_xprt_class_lock);
214 list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) { 213 list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) {
215 struct svc_xprt *newxprt; 214 struct svc_xprt *newxprt;
215 unsigned short newport;
216 216
217 if (strcmp(xprt_name, xcl->xcl_name)) 217 if (strcmp(xprt_name, xcl->xcl_name))
218 continue; 218 continue;
@@ -231,8 +231,9 @@ int svc_create_xprt(struct svc_serv *serv, const char *xprt_name,
231 spin_lock_bh(&serv->sv_lock); 231 spin_lock_bh(&serv->sv_lock);
232 list_add(&newxprt->xpt_list, &serv->sv_permsocks); 232 list_add(&newxprt->xpt_list, &serv->sv_permsocks);
233 spin_unlock_bh(&serv->sv_lock); 233 spin_unlock_bh(&serv->sv_lock);
234 newport = svc_xprt_local_port(newxprt);
234 clear_bit(XPT_BUSY, &newxprt->xpt_flags); 235 clear_bit(XPT_BUSY, &newxprt->xpt_flags);
235 return svc_xprt_local_port(newxprt); 236 return newport;
236 } 237 }
237 err: 238 err:
238 spin_unlock(&svc_xprt_class_lock); 239 spin_unlock(&svc_xprt_class_lock);
@@ -426,8 +427,13 @@ void svc_xprt_received(struct svc_xprt *xprt)
426{ 427{
427 BUG_ON(!test_bit(XPT_BUSY, &xprt->xpt_flags)); 428 BUG_ON(!test_bit(XPT_BUSY, &xprt->xpt_flags));
428 xprt->xpt_pool = NULL; 429 xprt->xpt_pool = NULL;
430 /* As soon as we clear busy, the xprt could be closed and
431 * 'put', so we need a reference to call svc_xprt_enqueue with:
432 */
433 svc_xprt_get(xprt);
429 clear_bit(XPT_BUSY, &xprt->xpt_flags); 434 clear_bit(XPT_BUSY, &xprt->xpt_flags);
430 svc_xprt_enqueue(xprt); 435 svc_xprt_enqueue(xprt);
436 svc_xprt_put(xprt);
431} 437}
432EXPORT_SYMBOL_GPL(svc_xprt_received); 438EXPORT_SYMBOL_GPL(svc_xprt_received);
433 439
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 33217fc3d697..e9f0d5004483 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -396,6 +396,7 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
396 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 396 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
397 struct tipc_sock *tsock = tipc_sk(sock->sk); 397 struct tipc_sock *tsock = tipc_sk(sock->sk);
398 398
399 memset(addr, 0, sizeof(*addr));
399 if (peer) { 400 if (peer) {
400 if ((sock->state != SS_CONNECTED) && 401 if ((sock->state != SS_CONNECTED) &&
401 ((peer != 2) || (sock->state != SS_DISCONNECTING))) 402 ((peer != 2) || (sock->state != SS_DISCONNECTING)))
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 3c95304a0817..2268e6798124 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1343,9 +1343,25 @@ static void unix_destruct_scm(struct sk_buff *skb)
1343 sock_wfree(skb); 1343 sock_wfree(skb);
1344} 1344}
1345 1345
1346#define MAX_RECURSION_LEVEL 4
1347
1346static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb) 1348static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1347{ 1349{
1348 int i; 1350 int i;
1351 unsigned char max_level = 0;
1352 int unix_sock_count = 0;
1353
1354 for (i = scm->fp->count - 1; i >= 0; i--) {
1355 struct sock *sk = unix_get_socket(scm->fp->fp[i]);
1356
1357 if (sk) {
1358 unix_sock_count++;
1359 max_level = max(max_level,
1360 unix_sk(sk)->recursion_level);
1361 }
1362 }
1363 if (unlikely(max_level > MAX_RECURSION_LEVEL))
1364 return -ETOOMANYREFS;
1349 1365
1350 /* 1366 /*
1351 * Need to duplicate file references for the sake of garbage 1367 * Need to duplicate file references for the sake of garbage
@@ -1356,9 +1372,11 @@ static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1356 if (!UNIXCB(skb).fp) 1372 if (!UNIXCB(skb).fp)
1357 return -ENOMEM; 1373 return -ENOMEM;
1358 1374
1359 for (i = scm->fp->count-1; i >= 0; i--) 1375 if (unix_sock_count) {
1360 unix_inflight(scm->fp->fp[i]); 1376 for (i = scm->fp->count - 1; i >= 0; i--)
1361 return 0; 1377 unix_inflight(scm->fp->fp[i]);
1378 }
1379 return max_level;
1362} 1380}
1363 1381
1364static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool send_fds) 1382static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool send_fds)
@@ -1393,6 +1411,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1393 struct sk_buff *skb; 1411 struct sk_buff *skb;
1394 long timeo; 1412 long timeo;
1395 struct scm_cookie tmp_scm; 1413 struct scm_cookie tmp_scm;
1414 int max_level;
1396 1415
1397 if (NULL == siocb->scm) 1416 if (NULL == siocb->scm)
1398 siocb->scm = &tmp_scm; 1417 siocb->scm = &tmp_scm;
@@ -1431,8 +1450,9 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1431 goto out; 1450 goto out;
1432 1451
1433 err = unix_scm_to_skb(siocb->scm, skb, true); 1452 err = unix_scm_to_skb(siocb->scm, skb, true);
1434 if (err) 1453 if (err < 0)
1435 goto out_free; 1454 goto out_free;
1455 max_level = err + 1;
1436 unix_get_secdata(siocb->scm, skb); 1456 unix_get_secdata(siocb->scm, skb);
1437 1457
1438 skb_reset_transport_header(skb); 1458 skb_reset_transport_header(skb);
@@ -1514,6 +1534,8 @@ restart:
1514 if (sock_flag(other, SOCK_RCVTSTAMP)) 1534 if (sock_flag(other, SOCK_RCVTSTAMP))
1515 __net_timestamp(skb); 1535 __net_timestamp(skb);
1516 skb_queue_tail(&other->sk_receive_queue, skb); 1536 skb_queue_tail(&other->sk_receive_queue, skb);
1537 if (max_level > unix_sk(other)->recursion_level)
1538 unix_sk(other)->recursion_level = max_level;
1517 unix_state_unlock(other); 1539 unix_state_unlock(other);
1518 other->sk_data_ready(other, len); 1540 other->sk_data_ready(other, len);
1519 sock_put(other); 1541 sock_put(other);
@@ -1544,6 +1566,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1544 int sent = 0; 1566 int sent = 0;
1545 struct scm_cookie tmp_scm; 1567 struct scm_cookie tmp_scm;
1546 bool fds_sent = false; 1568 bool fds_sent = false;
1569 int max_level;
1547 1570
1548 if (NULL == siocb->scm) 1571 if (NULL == siocb->scm)
1549 siocb->scm = &tmp_scm; 1572 siocb->scm = &tmp_scm;
@@ -1607,10 +1630,11 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1607 1630
1608 /* Only send the fds in the first buffer */ 1631 /* Only send the fds in the first buffer */
1609 err = unix_scm_to_skb(siocb->scm, skb, !fds_sent); 1632 err = unix_scm_to_skb(siocb->scm, skb, !fds_sent);
1610 if (err) { 1633 if (err < 0) {
1611 kfree_skb(skb); 1634 kfree_skb(skb);
1612 goto out_err; 1635 goto out_err;
1613 } 1636 }
1637 max_level = err + 1;
1614 fds_sent = true; 1638 fds_sent = true;
1615 1639
1616 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size); 1640 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
@@ -1626,6 +1650,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1626 goto pipe_err_free; 1650 goto pipe_err_free;
1627 1651
1628 skb_queue_tail(&other->sk_receive_queue, skb); 1652 skb_queue_tail(&other->sk_receive_queue, skb);
1653 if (max_level > unix_sk(other)->recursion_level)
1654 unix_sk(other)->recursion_level = max_level;
1629 unix_state_unlock(other); 1655 unix_state_unlock(other);
1630 other->sk_data_ready(other, size); 1656 other->sk_data_ready(other, size);
1631 sent += size; 1657 sent += size;
@@ -1845,6 +1871,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1845 unix_state_lock(sk); 1871 unix_state_lock(sk);
1846 skb = skb_dequeue(&sk->sk_receive_queue); 1872 skb = skb_dequeue(&sk->sk_receive_queue);
1847 if (skb == NULL) { 1873 if (skb == NULL) {
1874 unix_sk(sk)->recursion_level = 0;
1848 if (copied >= target) 1875 if (copied >= target)
1849 goto unlock; 1876 goto unlock;
1850 1877
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index c8df6fda0b1f..f89f83bf828e 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -96,7 +96,7 @@ static DECLARE_WAIT_QUEUE_HEAD(unix_gc_wait);
96unsigned int unix_tot_inflight; 96unsigned int unix_tot_inflight;
97 97
98 98
99static struct sock *unix_get_socket(struct file *filp) 99struct sock *unix_get_socket(struct file *filp)
100{ 100{
101 struct sock *u_sock = NULL; 101 struct sock *u_sock = NULL;
102 struct inode *inode = filp->f_path.dentry->d_inode; 102 struct inode *inode = filp->f_path.dentry->d_inode;
@@ -259,9 +259,16 @@ static void inc_inflight_move_tail(struct unix_sock *u)
259} 259}
260 260
261static bool gc_in_progress = false; 261static bool gc_in_progress = false;
262#define UNIX_INFLIGHT_TRIGGER_GC 16000
262 263
263void wait_for_unix_gc(void) 264void wait_for_unix_gc(void)
264{ 265{
266 /*
267 * If number of inflight sockets is insane,
268 * force a garbage collect right now.
269 */
270 if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress)
271 unix_gc();
265 wait_event(unix_gc_wait, gc_in_progress == false); 272 wait_event(unix_gc_wait, gc_in_progress == false);
266} 273}
267 274
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index d0c92dddb26b..17cd0c04d139 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -44,6 +44,38 @@ rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
44 return chan; 44 return chan;
45} 45}
46 46
47static bool can_beacon_sec_chan(struct wiphy *wiphy,
48 struct ieee80211_channel *chan,
49 enum nl80211_channel_type channel_type)
50{
51 struct ieee80211_channel *sec_chan;
52 int diff;
53
54 switch (channel_type) {
55 case NL80211_CHAN_HT40PLUS:
56 diff = 20;
57 break;
58 case NL80211_CHAN_HT40MINUS:
59 diff = -20;
60 break;
61 default:
62 return false;
63 }
64
65 sec_chan = ieee80211_get_channel(wiphy, chan->center_freq + diff);
66 if (!sec_chan)
67 return false;
68
69 /* we'll need a DFS capability later */
70 if (sec_chan->flags & (IEEE80211_CHAN_DISABLED |
71 IEEE80211_CHAN_PASSIVE_SCAN |
72 IEEE80211_CHAN_NO_IBSS |
73 IEEE80211_CHAN_RADAR))
74 return false;
75
76 return true;
77}
78
47int cfg80211_set_freq(struct cfg80211_registered_device *rdev, 79int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
48 struct wireless_dev *wdev, int freq, 80 struct wireless_dev *wdev, int freq,
49 enum nl80211_channel_type channel_type) 81 enum nl80211_channel_type channel_type)
@@ -68,6 +100,28 @@ int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
68 if (!chan) 100 if (!chan)
69 return -EINVAL; 101 return -EINVAL;
70 102
103 /* Both channels should be able to initiate communication */
104 if (wdev && (wdev->iftype == NL80211_IFTYPE_ADHOC ||
105 wdev->iftype == NL80211_IFTYPE_AP ||
106 wdev->iftype == NL80211_IFTYPE_AP_VLAN ||
107 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
108 wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
109 switch (channel_type) {
110 case NL80211_CHAN_HT40PLUS:
111 case NL80211_CHAN_HT40MINUS:
112 if (!can_beacon_sec_chan(&rdev->wiphy, chan,
113 channel_type)) {
114 printk(KERN_DEBUG
115 "cfg80211: Secondary channel not "
116 "allowed to initiate communication\n");
117 return -EINVAL;
118 }
119 break;
120 default:
121 break;
122 }
123 }
124
71 result = rdev->ops->set_channel(&rdev->wiphy, 125 result = rdev->ops->set_channel(&rdev->wiphy,
72 wdev ? wdev->netdev : NULL, 126 wdev ? wdev->netdev : NULL,
73 chan, channel_type); 127 chan, channel_type);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index c506241f8637..4e78e3f26798 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -224,8 +224,8 @@ static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
224 } 224 }
225 225
226 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); 226 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
227 if (IS_ERR(dev)) { 227 if (IS_ERR(*rdev)) {
228 err = PTR_ERR(dev); 228 err = PTR_ERR(*rdev);
229 goto out_rtnl; 229 goto out_rtnl;
230 } 230 }
231 231
diff --git a/net/x25/x25_facilities.c b/net/x25/x25_facilities.c
index 771bab00754b..55187c8f6420 100644
--- a/net/x25/x25_facilities.c
+++ b/net/x25/x25_facilities.c
@@ -61,6 +61,8 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
61 while (len > 0) { 61 while (len > 0) {
62 switch (*p & X25_FAC_CLASS_MASK) { 62 switch (*p & X25_FAC_CLASS_MASK) {
63 case X25_FAC_CLASS_A: 63 case X25_FAC_CLASS_A:
64 if (len < 2)
65 return 0;
64 switch (*p) { 66 switch (*p) {
65 case X25_FAC_REVERSE: 67 case X25_FAC_REVERSE:
66 if((p[1] & 0x81) == 0x81) { 68 if((p[1] & 0x81) == 0x81) {
@@ -104,6 +106,8 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
104 len -= 2; 106 len -= 2;
105 break; 107 break;
106 case X25_FAC_CLASS_B: 108 case X25_FAC_CLASS_B:
109 if (len < 3)
110 return 0;
107 switch (*p) { 111 switch (*p) {
108 case X25_FAC_PACKET_SIZE: 112 case X25_FAC_PACKET_SIZE:
109 facilities->pacsize_in = p[1]; 113 facilities->pacsize_in = p[1];
@@ -125,6 +129,8 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
125 len -= 3; 129 len -= 3;
126 break; 130 break;
127 case X25_FAC_CLASS_C: 131 case X25_FAC_CLASS_C:
132 if (len < 4)
133 return 0;
128 printk(KERN_DEBUG "X.25: unknown facility %02X, " 134 printk(KERN_DEBUG "X.25: unknown facility %02X, "
129 "values %02X, %02X, %02X\n", 135 "values %02X, %02X, %02X\n",
130 p[0], p[1], p[2], p[3]); 136 p[0], p[1], p[2], p[3]);
@@ -132,26 +138,26 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
132 len -= 4; 138 len -= 4;
133 break; 139 break;
134 case X25_FAC_CLASS_D: 140 case X25_FAC_CLASS_D:
141 if (len < p[1] + 2)
142 return 0;
135 switch (*p) { 143 switch (*p) {
136 case X25_FAC_CALLING_AE: 144 case X25_FAC_CALLING_AE:
137 if (p[1] > X25_MAX_DTE_FACIL_LEN) 145 if (p[1] > X25_MAX_DTE_FACIL_LEN || p[1] <= 1)
138 break; 146 return 0;
139 dte_facs->calling_len = p[2]; 147 dte_facs->calling_len = p[2];
140 memcpy(dte_facs->calling_ae, &p[3], p[1] - 1); 148 memcpy(dte_facs->calling_ae, &p[3], p[1] - 1);
141 *vc_fac_mask |= X25_MASK_CALLING_AE; 149 *vc_fac_mask |= X25_MASK_CALLING_AE;
142 break; 150 break;
143 case X25_FAC_CALLED_AE: 151 case X25_FAC_CALLED_AE:
144 if (p[1] > X25_MAX_DTE_FACIL_LEN) 152 if (p[1] > X25_MAX_DTE_FACIL_LEN || p[1] <= 1)
145 break; 153 return 0;
146 dte_facs->called_len = p[2]; 154 dte_facs->called_len = p[2];
147 memcpy(dte_facs->called_ae, &p[3], p[1] - 1); 155 memcpy(dte_facs->called_ae, &p[3], p[1] - 1);
148 *vc_fac_mask |= X25_MASK_CALLED_AE; 156 *vc_fac_mask |= X25_MASK_CALLED_AE;
149 break; 157 break;
150 default: 158 default:
151 printk(KERN_DEBUG "X.25: unknown facility %02X," 159 printk(KERN_DEBUG "X.25: unknown facility %02X,"
152 "length %d, values %02X, %02X, " 160 "length %d\n", p[0], p[1]);
153 "%02X, %02X\n",
154 p[0], p[1], p[2], p[3], p[4], p[5]);
155 break; 161 break;
156 } 162 }
157 len -= p[1] + 2; 163 len -= p[1] + 2;
diff --git a/net/x25/x25_in.c b/net/x25/x25_in.c
index 63178961efac..f729f022be69 100644
--- a/net/x25/x25_in.c
+++ b/net/x25/x25_in.c
@@ -119,6 +119,8 @@ static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametyp
119 &x25->vc_facil_mask); 119 &x25->vc_facil_mask);
120 if (len > 0) 120 if (len > 0)
121 skb_pull(skb, len); 121 skb_pull(skb, len);
122 else
123 return -1;
122 /* 124 /*
123 * Copy any Call User Data. 125 * Copy any Call User Data.
124 */ 126 */
diff --git a/net/x25/x25_link.c b/net/x25/x25_link.c
index 73e7b954ad28..b25c6463c3e9 100644
--- a/net/x25/x25_link.c
+++ b/net/x25/x25_link.c
@@ -394,6 +394,7 @@ void __exit x25_link_free(void)
394 list_for_each_safe(entry, tmp, &x25_neigh_list) { 394 list_for_each_safe(entry, tmp, &x25_neigh_list) {
395 nb = list_entry(entry, struct x25_neigh, node); 395 nb = list_entry(entry, struct x25_neigh, node);
396 __x25_remove_neigh(nb); 396 __x25_remove_neigh(nb);
397 dev_put(nb->dev);
397 } 398 }
398 write_unlock_bh(&x25_neigh_list_lock); 399 write_unlock_bh(&x25_neigh_list_lock);
399} 400}
diff --git a/net/xfrm/xfrm_hash.c b/net/xfrm/xfrm_hash.c
index a2023ec52329..1e98bc0fe0a5 100644
--- a/net/xfrm/xfrm_hash.c
+++ b/net/xfrm/xfrm_hash.c
@@ -19,7 +19,7 @@ struct hlist_head *xfrm_hash_alloc(unsigned int sz)
19 if (sz <= PAGE_SIZE) 19 if (sz <= PAGE_SIZE)
20 n = kzalloc(sz, GFP_KERNEL); 20 n = kzalloc(sz, GFP_KERNEL);
21 else if (hashdist) 21 else if (hashdist)
22 n = __vmalloc(sz, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL); 22 n = vzalloc(sz);
23 else 23 else
24 n = (struct hlist_head *) 24 n = (struct hlist_head *)
25 __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, 25 __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index eb96ce52f178..220ebc05c7af 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1268,7 +1268,7 @@ struct xfrm_state * xfrm_state_migrate(struct xfrm_state *x,
1268 1268
1269 return xc; 1269 return xc;
1270error: 1270error:
1271 kfree(xc); 1271 xfrm_state_put(xc);
1272 return NULL; 1272 return NULL;
1273} 1273}
1274EXPORT_SYMBOL(xfrm_state_migrate); 1274EXPORT_SYMBOL(xfrm_state_migrate);
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 90b54d4697fd..e3c7fc0dca38 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2794,12 +2794,8 @@ sub process {
2794 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); 2794 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
2795 } 2795 }
2796 2796
2797# check for semaphores used as mutexes 2797# check for semaphores initialized locked
2798 if ($line =~ /^.\s*(DECLARE_MUTEX|init_MUTEX)\s*\(/) { 2798 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
2799 WARN("mutexes are preferred for single holder semaphores\n" . $herecurr);
2800 }
2801# check for semaphores used as mutexes
2802 if ($line =~ /^.\s*init_MUTEX_LOCKED\s*\(/) {
2803 WARN("consider using a completion\n" . $herecurr); 2799 WARN("consider using a completion\n" . $herecurr);
2804 2800
2805 } 2801 }
diff --git a/scripts/gfp-translate b/scripts/gfp-translate
index d81b968d864e..c9230e158a8f 100644
--- a/scripts/gfp-translate
+++ b/scripts/gfp-translate
@@ -63,7 +63,12 @@ fi
63 63
64# Extract GFP flags from the kernel source 64# Extract GFP flags from the kernel source
65TMPFILE=`mktemp -t gfptranslate-XXXXXX` || exit 1 65TMPFILE=`mktemp -t gfptranslate-XXXXXX` || exit 1
66grep "^#define __GFP" $SOURCE/include/linux/gfp.h | sed -e 's/(__force gfp_t)//' | sed -e 's/u)/)/' | grep -v GFP_BITS | sed -e 's/)\//) \//' > $TMPFILE 66grep -q ___GFP $SOURCE/include/linux/gfp.h
67if [ $? -eq 0 ]; then
68 grep "^#define ___GFP" $SOURCE/include/linux/gfp.h | sed -e 's/u$//' | grep -v GFP_BITS > $TMPFILE
69else
70 grep "^#define __GFP" $SOURCE/include/linux/gfp.h | sed -e 's/(__force gfp_t)//' | sed -e 's/u)/)/' | grep -v GFP_BITS | sed -e 's/)\//) \//' > $TMPFILE
71fi
67 72
68# Parse the flags 73# Parse the flags
69IFS=" 74IFS="
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 184eb6a0b505..e57826ced380 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -164,6 +164,7 @@ struct menu {
164 struct menu *list; 164 struct menu *list;
165 struct symbol *sym; 165 struct symbol *sym;
166 struct property *prompt; 166 struct property *prompt;
167 struct expr *visibility;
167 struct expr *dep; 168 struct expr *dep;
168 unsigned int flags; 169 unsigned int flags;
169 char *help; 170 char *help;
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 753cdbd7b805..3f7240df0f3b 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -107,6 +107,7 @@ void menu_end_menu(void);
107void menu_add_entry(struct symbol *sym); 107void menu_add_entry(struct symbol *sym);
108void menu_end_entry(void); 108void menu_end_entry(void);
109void menu_add_dep(struct expr *dep); 109void menu_add_dep(struct expr *dep);
110void menu_add_visibility(struct expr *dep);
110struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep); 111struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep);
111struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep); 112struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
112void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); 113void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 7e83aef42c6d..b9d9aa18e6d6 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -152,6 +152,12 @@ struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr
152 return menu_add_prop(type, prompt, NULL, dep); 152 return menu_add_prop(type, prompt, NULL, dep);
153} 153}
154 154
155void menu_add_visibility(struct expr *expr)
156{
157 current_entry->visibility = expr_alloc_and(current_entry->visibility,
158 expr);
159}
160
155void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep) 161void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
156{ 162{
157 menu_add_prop(type, NULL, expr, dep); 163 menu_add_prop(type, NULL, expr, dep);
@@ -410,6 +416,11 @@ bool menu_is_visible(struct menu *menu)
410 if (!menu->prompt) 416 if (!menu->prompt)
411 return false; 417 return false;
412 418
419 if (menu->visibility) {
420 if (expr_calc_value(menu->visibility) == no)
421 return no;
422 }
423
413 sym = menu->sym; 424 sym = menu->sym;
414 if (sym) { 425 if (sym) {
415 sym_calc_value(sym); 426 sym_calc_value(sym);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index c0efe102d655..af6e9f3de950 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -875,7 +875,7 @@ const char *sym_expand_string_value(const char *in)
875 symval = sym_get_string_value(sym); 875 symval = sym_get_string_value(sym);
876 } 876 }
877 877
878 newlen = strlen(res) + strlen(symval) + strlen(src); 878 newlen = strlen(res) + strlen(symval) + strlen(src) + 1;
879 if (newlen > reslen) { 879 if (newlen > reslen) {
880 reslen = newlen; 880 reslen = newlen;
881 res = realloc(res, reslen); 881 res = realloc(res, reslen);
diff --git a/scripts/kconfig/zconf.gperf b/scripts/kconfig/zconf.gperf
index d8bc74249622..c9e690eb7545 100644
--- a/scripts/kconfig/zconf.gperf
+++ b/scripts/kconfig/zconf.gperf
@@ -38,6 +38,7 @@ hex, T_TYPE, TF_COMMAND, S_HEX
38string, T_TYPE, TF_COMMAND, S_STRING 38string, T_TYPE, TF_COMMAND, S_STRING
39select, T_SELECT, TF_COMMAND 39select, T_SELECT, TF_COMMAND
40range, T_RANGE, TF_COMMAND 40range, T_RANGE, TF_COMMAND
41visible, T_VISIBLE, TF_COMMAND
41option, T_OPTION, TF_COMMAND 42option, T_OPTION, TF_COMMAND
42on, T_ON, TF_PARAM 43on, T_ON, TF_PARAM
43modules, T_OPT_MODULES, TF_OPTION 44modules, T_OPT_MODULES, TF_OPTION
diff --git a/scripts/kconfig/zconf.hash.c_shipped b/scripts/kconfig/zconf.hash.c_shipped
index c1748faf4634..4055d5de1750 100644
--- a/scripts/kconfig/zconf.hash.c_shipped
+++ b/scripts/kconfig/zconf.hash.c_shipped
@@ -32,7 +32,7 @@
32struct kconf_id; 32struct kconf_id;
33 33
34static struct kconf_id *kconf_id_lookup(register const char *str, register unsigned int len); 34static struct kconf_id *kconf_id_lookup(register const char *str, register unsigned int len);
35/* maximum key range = 47, duplicates = 0 */ 35/* maximum key range = 50, duplicates = 0 */
36 36
37#ifdef __GNUC__ 37#ifdef __GNUC__
38__inline 38__inline
@@ -46,32 +46,32 @@ kconf_id_hash (register const char *str, register unsigned int len)
46{ 46{
47 static unsigned char asso_values[] = 47 static unsigned char asso_values[] =
48 { 48 {
49 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
50 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 50 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
51 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 51 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
52 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 52 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
53 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 53 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
54 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 54 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
55 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 55 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
56 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 56 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
57 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 57 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
58 49, 49, 49, 49, 49, 49, 49, 49, 11, 5, 58 52, 52, 52, 52, 52, 52, 52, 52, 40, 5,
59 0, 0, 5, 49, 5, 20, 49, 49, 5, 20, 59 0, 0, 5, 52, 0, 20, 52, 52, 10, 20,
60 5, 0, 30, 49, 0, 15, 0, 10, 0, 49, 60 5, 0, 35, 52, 0, 30, 0, 15, 0, 52,
61 25, 49, 49, 49, 49, 49, 49, 49, 49, 49, 61 15, 52, 52, 52, 52, 52, 52, 52, 52, 52,
62 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 62 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
63 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 63 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
64 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 64 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
65 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 65 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
66 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 66 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
67 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 67 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
68 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 68 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
69 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 69 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
70 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 70 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
71 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 71 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
72 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 72 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
73 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 73 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
74 49, 49, 49, 49, 49, 49 74 52, 52, 52, 52, 52, 52
75 }; 75 };
76 register int hval = len; 76 register int hval = len;
77 77
@@ -102,25 +102,26 @@ struct kconf_id_strings_t
102 char kconf_id_strings_str12[sizeof("default")]; 102 char kconf_id_strings_str12[sizeof("default")];
103 char kconf_id_strings_str13[sizeof("def_bool")]; 103 char kconf_id_strings_str13[sizeof("def_bool")];
104 char kconf_id_strings_str14[sizeof("help")]; 104 char kconf_id_strings_str14[sizeof("help")];
105 char kconf_id_strings_str15[sizeof("bool")];
106 char kconf_id_strings_str16[sizeof("config")]; 105 char kconf_id_strings_str16[sizeof("config")];
107 char kconf_id_strings_str17[sizeof("def_tristate")]; 106 char kconf_id_strings_str17[sizeof("def_tristate")];
108 char kconf_id_strings_str18[sizeof("boolean")]; 107 char kconf_id_strings_str18[sizeof("hex")];
109 char kconf_id_strings_str19[sizeof("defconfig_list")]; 108 char kconf_id_strings_str19[sizeof("defconfig_list")];
110 char kconf_id_strings_str21[sizeof("string")];
111 char kconf_id_strings_str22[sizeof("if")]; 109 char kconf_id_strings_str22[sizeof("if")];
112 char kconf_id_strings_str23[sizeof("int")]; 110 char kconf_id_strings_str23[sizeof("int")];
113 char kconf_id_strings_str26[sizeof("select")];
114 char kconf_id_strings_str27[sizeof("modules")]; 111 char kconf_id_strings_str27[sizeof("modules")];
115 char kconf_id_strings_str28[sizeof("tristate")]; 112 char kconf_id_strings_str28[sizeof("tristate")];
116 char kconf_id_strings_str29[sizeof("menu")]; 113 char kconf_id_strings_str29[sizeof("menu")];
117 char kconf_id_strings_str31[sizeof("source")];
118 char kconf_id_strings_str32[sizeof("comment")]; 114 char kconf_id_strings_str32[sizeof("comment")];
119 char kconf_id_strings_str33[sizeof("hex")];
120 char kconf_id_strings_str35[sizeof("menuconfig")]; 115 char kconf_id_strings_str35[sizeof("menuconfig")];
121 char kconf_id_strings_str36[sizeof("prompt")]; 116 char kconf_id_strings_str36[sizeof("string")];
122 char kconf_id_strings_str37[sizeof("depends")]; 117 char kconf_id_strings_str37[sizeof("visible")];
118 char kconf_id_strings_str41[sizeof("prompt")];
119 char kconf_id_strings_str42[sizeof("depends")];
120 char kconf_id_strings_str44[sizeof("bool")];
121 char kconf_id_strings_str46[sizeof("select")];
122 char kconf_id_strings_str47[sizeof("boolean")];
123 char kconf_id_strings_str48[sizeof("mainmenu")]; 123 char kconf_id_strings_str48[sizeof("mainmenu")];
124 char kconf_id_strings_str51[sizeof("source")];
124 }; 125 };
125static struct kconf_id_strings_t kconf_id_strings_contents = 126static struct kconf_id_strings_t kconf_id_strings_contents =
126 { 127 {
@@ -136,25 +137,26 @@ static struct kconf_id_strings_t kconf_id_strings_contents =
136 "default", 137 "default",
137 "def_bool", 138 "def_bool",
138 "help", 139 "help",
139 "bool",
140 "config", 140 "config",
141 "def_tristate", 141 "def_tristate",
142 "boolean", 142 "hex",
143 "defconfig_list", 143 "defconfig_list",
144 "string",
145 "if", 144 "if",
146 "int", 145 "int",
147 "select",
148 "modules", 146 "modules",
149 "tristate", 147 "tristate",
150 "menu", 148 "menu",
151 "source",
152 "comment", 149 "comment",
153 "hex",
154 "menuconfig", 150 "menuconfig",
151 "string",
152 "visible",
155 "prompt", 153 "prompt",
156 "depends", 154 "depends",
157 "mainmenu" 155 "bool",
156 "select",
157 "boolean",
158 "mainmenu",
159 "source"
158 }; 160 };
159#define kconf_id_strings ((const char *) &kconf_id_strings_contents) 161#define kconf_id_strings ((const char *) &kconf_id_strings_contents)
160#ifdef __GNUC__ 162#ifdef __GNUC__
@@ -168,11 +170,11 @@ kconf_id_lookup (register const char *str, register unsigned int len)
168{ 170{
169 enum 171 enum
170 { 172 {
171 TOTAL_KEYWORDS = 31, 173 TOTAL_KEYWORDS = 32,
172 MIN_WORD_LENGTH = 2, 174 MIN_WORD_LENGTH = 2,
173 MAX_WORD_LENGTH = 14, 175 MAX_WORD_LENGTH = 14,
174 MIN_HASH_VALUE = 2, 176 MIN_HASH_VALUE = 2,
175 MAX_HASH_VALUE = 48 177 MAX_HASH_VALUE = 51
176 }; 178 };
177 179
178 static struct kconf_id wordlist[] = 180 static struct kconf_id wordlist[] =
@@ -191,31 +193,35 @@ kconf_id_lookup (register const char *str, register unsigned int len)
191 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str12, T_DEFAULT, TF_COMMAND, S_UNKNOWN}, 193 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str12, T_DEFAULT, TF_COMMAND, S_UNKNOWN},
192 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str13, T_DEFAULT, TF_COMMAND, S_BOOLEAN}, 194 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str13, T_DEFAULT, TF_COMMAND, S_BOOLEAN},
193 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str14, T_HELP, TF_COMMAND}, 195 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str14, T_HELP, TF_COMMAND},
194 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str15, T_TYPE, TF_COMMAND, S_BOOLEAN}, 196 {-1},
195 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str16, T_CONFIG, TF_COMMAND}, 197 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str16, T_CONFIG, TF_COMMAND},
196 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str17, T_DEFAULT, TF_COMMAND, S_TRISTATE}, 198 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str17, T_DEFAULT, TF_COMMAND, S_TRISTATE},
197 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str18, T_TYPE, TF_COMMAND, S_BOOLEAN}, 199 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str18, T_TYPE, TF_COMMAND, S_HEX},
198 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str19, T_OPT_DEFCONFIG_LIST,TF_OPTION}, 200 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str19, T_OPT_DEFCONFIG_LIST,TF_OPTION},
199 {-1}, 201 {-1}, {-1},
200 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str21, T_TYPE, TF_COMMAND, S_STRING},
201 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str22, T_IF, TF_COMMAND|TF_PARAM}, 202 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str22, T_IF, TF_COMMAND|TF_PARAM},
202 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str23, T_TYPE, TF_COMMAND, S_INT}, 203 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str23, T_TYPE, TF_COMMAND, S_INT},
203 {-1}, {-1}, 204 {-1}, {-1}, {-1},
204 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str26, T_SELECT, TF_COMMAND},
205 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str27, T_OPT_MODULES, TF_OPTION}, 205 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str27, T_OPT_MODULES, TF_OPTION},
206 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str28, T_TYPE, TF_COMMAND, S_TRISTATE}, 206 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str28, T_TYPE, TF_COMMAND, S_TRISTATE},
207 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str29, T_MENU, TF_COMMAND}, 207 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str29, T_MENU, TF_COMMAND},
208 {-1}, 208 {-1}, {-1},
209 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str31, T_SOURCE, TF_COMMAND},
210 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str32, T_COMMENT, TF_COMMAND}, 209 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str32, T_COMMENT, TF_COMMAND},
211 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str33, T_TYPE, TF_COMMAND, S_HEX}, 210 {-1}, {-1},
212 {-1},
213 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str35, T_MENUCONFIG, TF_COMMAND}, 211 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str35, T_MENUCONFIG, TF_COMMAND},
214 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str36, T_PROMPT, TF_COMMAND}, 212 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str36, T_TYPE, TF_COMMAND, S_STRING},
215 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str37, T_DEPENDS, TF_COMMAND}, 213 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str37, T_VISIBLE, TF_COMMAND},
216 {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, 214 {-1}, {-1}, {-1},
215 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str41, T_PROMPT, TF_COMMAND},
216 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str42, T_DEPENDS, TF_COMMAND},
217 {-1}, 217 {-1},
218 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str48, T_MAINMENU, TF_COMMAND} 218 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str44, T_TYPE, TF_COMMAND, S_BOOLEAN},
219 {-1},
220 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str46, T_SELECT, TF_COMMAND},
221 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str47, T_TYPE, TF_COMMAND, S_BOOLEAN},
222 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str48, T_MAINMENU, TF_COMMAND},
223 {-1}, {-1},
224 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str51, T_SOURCE, TF_COMMAND}
219 }; 225 };
220 226
221 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) 227 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
diff --git a/scripts/kconfig/zconf.tab.c_shipped b/scripts/kconfig/zconf.tab.c_shipped
index 699d4b265186..4c5495ea205e 100644
--- a/scripts/kconfig/zconf.tab.c_shipped
+++ b/scripts/kconfig/zconf.tab.c_shipped
@@ -160,18 +160,19 @@ static struct menu *current_menu, *current_entry;
160 T_DEFAULT = 275, 160 T_DEFAULT = 275,
161 T_SELECT = 276, 161 T_SELECT = 276,
162 T_RANGE = 277, 162 T_RANGE = 277,
163 T_OPTION = 278, 163 T_VISIBLE = 278,
164 T_ON = 279, 164 T_OPTION = 279,
165 T_WORD = 280, 165 T_ON = 280,
166 T_WORD_QUOTE = 281, 166 T_WORD = 281,
167 T_UNEQUAL = 282, 167 T_WORD_QUOTE = 282,
168 T_CLOSE_PAREN = 283, 168 T_UNEQUAL = 283,
169 T_OPEN_PAREN = 284, 169 T_CLOSE_PAREN = 284,
170 T_EOL = 285, 170 T_OPEN_PAREN = 285,
171 T_OR = 286, 171 T_EOL = 286,
172 T_AND = 287, 172 T_OR = 287,
173 T_EQUAL = 288, 173 T_AND = 288,
174 T_NOT = 289 174 T_EQUAL = 289,
175 T_NOT = 290
175 }; 176 };
176#endif 177#endif
177 178
@@ -419,20 +420,20 @@ union yyalloc
419/* YYFINAL -- State number of the termination state. */ 420/* YYFINAL -- State number of the termination state. */
420#define YYFINAL 11 421#define YYFINAL 11
421/* YYLAST -- Last index in YYTABLE. */ 422/* YYLAST -- Last index in YYTABLE. */
422#define YYLAST 277 423#define YYLAST 290
423 424
424/* YYNTOKENS -- Number of terminals. */ 425/* YYNTOKENS -- Number of terminals. */
425#define YYNTOKENS 35 426#define YYNTOKENS 36
426/* YYNNTS -- Number of nonterminals. */ 427/* YYNNTS -- Number of nonterminals. */
427#define YYNNTS 48 428#define YYNNTS 50
428/* YYNRULES -- Number of rules. */ 429/* YYNRULES -- Number of rules. */
429#define YYNRULES 113 430#define YYNRULES 118
430/* YYNRULES -- Number of states. */ 431/* YYNRULES -- Number of states. */
431#define YYNSTATES 185 432#define YYNSTATES 191
432 433
433/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ 434/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
434#define YYUNDEFTOK 2 435#define YYUNDEFTOK 2
435#define YYMAXUTOK 289 436#define YYMAXUTOK 290
436 437
437#define YYTRANSLATE(YYX) \ 438#define YYTRANSLATE(YYX) \
438 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) 439 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@@ -468,7 +469,8 @@ static const yytype_uint8 yytranslate[] =
468 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 469 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
469 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 470 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
470 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 471 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
471 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 472 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
473 35
472}; 474};
473 475
474#if YYDEBUG 476#if YYDEBUG
@@ -478,72 +480,73 @@ static const yytype_uint16 yyprhs[] =
478{ 480{
479 0, 0, 3, 6, 8, 11, 13, 14, 17, 20, 481 0, 0, 3, 6, 8, 11, 13, 14, 17, 20,
480 23, 26, 31, 36, 40, 42, 44, 46, 48, 50, 482 23, 26, 31, 36, 40, 42, 44, 46, 48, 50,
481 52, 54, 56, 58, 60, 62, 64, 66, 70, 73, 483 52, 54, 56, 58, 60, 62, 64, 66, 68, 72,
482 77, 80, 84, 87, 88, 91, 94, 97, 100, 103, 484 75, 79, 82, 86, 89, 90, 93, 96, 99, 102,
483 106, 110, 115, 120, 125, 131, 135, 136, 140, 141, 485 105, 108, 112, 117, 122, 127, 133, 137, 138, 142,
484 144, 148, 151, 153, 157, 158, 161, 164, 167, 170, 486 143, 146, 150, 153, 155, 159, 160, 163, 166, 169,
485 173, 178, 182, 185, 190, 191, 194, 198, 200, 204, 487 172, 175, 180, 184, 187, 192, 193, 196, 200, 202,
486 205, 208, 211, 214, 218, 222, 225, 227, 231, 232, 488 206, 207, 210, 213, 216, 220, 224, 228, 230, 234,
487 235, 238, 241, 245, 249, 252, 255, 258, 259, 262, 489 235, 238, 241, 244, 248, 252, 255, 258, 261, 262,
488 265, 268, 273, 274, 277, 279, 281, 284, 287, 290, 490 265, 268, 271, 276, 277, 280, 283, 286, 287, 290,
489 292, 295, 296, 299, 301, 305, 309, 313, 316, 320, 491 292, 294, 297, 300, 303, 305, 308, 309, 312, 314,
490 324, 326, 328, 329 492 318, 322, 326, 329, 333, 337, 339, 341, 342
491}; 493};
492 494
493/* YYRHS -- A `-1'-separated list of the rules' RHS. */ 495/* YYRHS -- A `-1'-separated list of the rules' RHS. */
494static const yytype_int8 yyrhs[] = 496static const yytype_int8 yyrhs[] =
495{ 497{
496 36, 0, -1, 78, 37, -1, 37, -1, 62, 38, 498 37, 0, -1, 81, 38, -1, 38, -1, 63, 39,
497 -1, 38, -1, -1, 38, 40, -1, 38, 54, -1, 499 -1, 39, -1, -1, 39, 41, -1, 39, 55, -1,
498 38, 66, -1, 38, 77, -1, 38, 25, 1, 30, 500 39, 67, -1, 39, 80, -1, 39, 26, 1, 31,
499 -1, 38, 39, 1, 30, -1, 38, 1, 30, -1, 501 -1, 39, 40, 1, 31, -1, 39, 1, 31, -1,
500 16, -1, 18, -1, 19, -1, 21, -1, 17, -1, 502 16, -1, 18, -1, 19, -1, 21, -1, 17, -1,
501 22, -1, 20, -1, 30, -1, 60, -1, 70, -1, 503 22, -1, 20, -1, 23, -1, 31, -1, 61, -1,
502 43, -1, 45, -1, 68, -1, 25, 1, 30, -1, 504 71, -1, 44, -1, 46, -1, 69, -1, 26, 1,
503 1, 30, -1, 10, 25, 30, -1, 42, 46, -1, 505 31, -1, 1, 31, -1, 10, 26, 31, -1, 43,
504 11, 25, 30, -1, 44, 46, -1, -1, 46, 47, 506 47, -1, 11, 26, 31, -1, 45, 47, -1, -1,
505 -1, 46, 48, -1, 46, 74, -1, 46, 72, -1, 507 47, 48, -1, 47, 49, -1, 47, 75, -1, 47,
506 46, 41, -1, 46, 30, -1, 19, 75, 30, -1, 508 73, -1, 47, 42, -1, 47, 31, -1, 19, 78,
507 18, 76, 79, 30, -1, 20, 80, 79, 30, -1, 509 31, -1, 18, 79, 82, 31, -1, 20, 83, 82,
508 21, 25, 79, 30, -1, 22, 81, 81, 79, 30, 510 31, -1, 21, 26, 82, 31, -1, 22, 84, 84,
509 -1, 23, 49, 30, -1, -1, 49, 25, 50, -1, 511 82, 31, -1, 24, 50, 31, -1, -1, 50, 26,
510 -1, 33, 76, -1, 7, 82, 30, -1, 51, 55, 512 51, -1, -1, 34, 79, -1, 7, 85, 31, -1,
511 -1, 77, -1, 52, 57, 53, -1, -1, 55, 56, 513 52, 56, -1, 80, -1, 53, 58, 54, -1, -1,
512 -1, 55, 74, -1, 55, 72, -1, 55, 30, -1, 514 56, 57, -1, 56, 75, -1, 56, 73, -1, 56,
513 55, 41, -1, 18, 76, 79, 30, -1, 19, 75, 515 31, -1, 56, 42, -1, 18, 79, 82, 31, -1,
514 30, -1, 17, 30, -1, 20, 25, 79, 30, -1, 516 19, 78, 31, -1, 17, 31, -1, 20, 26, 82,
515 -1, 57, 40, -1, 14, 80, 78, -1, 77, -1, 517 31, -1, -1, 58, 41, -1, 14, 83, 81, -1,
516 58, 61, 59, -1, -1, 61, 40, -1, 61, 66, 518 80, -1, 59, 62, 60, -1, -1, 62, 41, -1,
517 -1, 61, 54, -1, 3, 76, 78, -1, 4, 76, 519 62, 67, -1, 62, 55, -1, 3, 79, 81, -1,
518 30, -1, 63, 73, -1, 77, -1, 64, 67, 65, 520 4, 79, 31, -1, 64, 76, 74, -1, 80, -1,
519 -1, -1, 67, 40, -1, 67, 66, -1, 67, 54, 521 65, 68, 66, -1, -1, 68, 41, -1, 68, 67,
520 -1, 6, 76, 30, -1, 9, 76, 30, -1, 69, 522 -1, 68, 55, -1, 6, 79, 31, -1, 9, 79,
521 73, -1, 12, 30, -1, 71, 13, -1, -1, 73, 523 31, -1, 70, 74, -1, 12, 31, -1, 72, 13,
522 74, -1, 73, 30, -1, 73, 41, -1, 16, 24, 524 -1, -1, 74, 75, -1, 74, 31, -1, 74, 42,
523 80, 30, -1, -1, 76, 79, -1, 25, -1, 26, 525 -1, 16, 25, 83, 31, -1, -1, 76, 77, -1,
524 -1, 5, 30, -1, 8, 30, -1, 15, 30, -1, 526 76, 31, -1, 23, 82, -1, -1, 79, 82, -1,
525 30, -1, 78, 30, -1, -1, 14, 80, -1, 81, 527 26, -1, 27, -1, 5, 31, -1, 8, 31, -1,
526 -1, 81, 33, 81, -1, 81, 27, 81, -1, 29, 528 15, 31, -1, 31, -1, 81, 31, -1, -1, 14,
527 80, 28, -1, 34, 80, -1, 80, 31, 80, -1, 529 83, -1, 84, -1, 84, 34, 84, -1, 84, 28,
528 80, 32, 80, -1, 25, -1, 26, -1, -1, 25, 530 84, -1, 30, 83, 29, -1, 35, 83, -1, 83,
529 -1 531 32, 83, -1, 83, 33, 83, -1, 26, -1, 27,
532 -1, -1, 26, -1
530}; 533};
531 534
532/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 535/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
533static const yytype_uint16 yyrline[] = 536static const yytype_uint16 yyrline[] =
534{ 537{
535 0, 107, 107, 107, 109, 109, 111, 113, 114, 115, 538 0, 108, 108, 108, 110, 110, 112, 114, 115, 116,
536 116, 117, 118, 122, 126, 126, 126, 126, 126, 126, 539 117, 118, 119, 123, 127, 127, 127, 127, 127, 127,
537 126, 130, 131, 132, 133, 134, 135, 139, 140, 146, 540 127, 127, 131, 132, 133, 134, 135, 136, 140, 141,
538 154, 160, 168, 178, 180, 181, 182, 183, 184, 185, 541 147, 155, 161, 169, 179, 181, 182, 183, 184, 185,
539 188, 196, 202, 212, 218, 224, 227, 229, 240, 241, 542 186, 189, 197, 203, 213, 219, 225, 228, 230, 241,
540 246, 255, 260, 268, 271, 273, 274, 275, 276, 277, 543 242, 247, 256, 261, 269, 272, 274, 275, 276, 277,
541 280, 286, 297, 303, 313, 315, 320, 328, 336, 339, 544 278, 281, 287, 298, 304, 314, 316, 321, 329, 337,
542 341, 342, 343, 348, 355, 362, 367, 375, 378, 380, 545 340, 342, 343, 344, 349, 356, 363, 368, 376, 379,
543 381, 382, 385, 393, 400, 407, 413, 420, 422, 423, 546 381, 382, 383, 386, 394, 401, 408, 414, 421, 423,
544 424, 427, 435, 437, 442, 443, 446, 447, 448, 452, 547 424, 425, 428, 436, 438, 439, 442, 449, 451, 456,
545 453, 456, 457, 460, 461, 462, 463, 464, 465, 466, 548 457, 460, 461, 462, 466, 467, 470, 471, 474, 475,
546 469, 470, 473, 474 549 476, 477, 478, 479, 480, 483, 484, 487, 488
547}; 550};
548#endif 551#endif
549 552
@@ -556,7 +559,7 @@ static const char *const yytname[] =
556 "T_SOURCE", "T_CHOICE", "T_ENDCHOICE", "T_COMMENT", "T_CONFIG", 559 "T_SOURCE", "T_CHOICE", "T_ENDCHOICE", "T_COMMENT", "T_CONFIG",
557 "T_MENUCONFIG", "T_HELP", "T_HELPTEXT", "T_IF", "T_ENDIF", "T_DEPENDS", 560 "T_MENUCONFIG", "T_HELP", "T_HELPTEXT", "T_IF", "T_ENDIF", "T_DEPENDS",
558 "T_OPTIONAL", "T_PROMPT", "T_TYPE", "T_DEFAULT", "T_SELECT", "T_RANGE", 561 "T_OPTIONAL", "T_PROMPT", "T_TYPE", "T_DEFAULT", "T_SELECT", "T_RANGE",
559 "T_OPTION", "T_ON", "T_WORD", "T_WORD_QUOTE", "T_UNEQUAL", 562 "T_VISIBLE", "T_OPTION", "T_ON", "T_WORD", "T_WORD_QUOTE", "T_UNEQUAL",
560 "T_CLOSE_PAREN", "T_OPEN_PAREN", "T_EOL", "T_OR", "T_AND", "T_EQUAL", 563 "T_CLOSE_PAREN", "T_OPEN_PAREN", "T_EOL", "T_OR", "T_AND", "T_EQUAL",
561 "T_NOT", "$accept", "input", "start", "stmt_list", "option_name", 564 "T_NOT", "$accept", "input", "start", "stmt_list", "option_name",
562 "common_stmt", "option_error", "config_entry_start", "config_stmt", 565 "common_stmt", "option_error", "config_entry_start", "config_stmt",
@@ -567,8 +570,8 @@ static const char *const yytname[] =
567 "if_entry", "if_end", "if_stmt", "if_block", "mainmenu_stmt", "menu", 570 "if_entry", "if_end", "if_stmt", "if_block", "mainmenu_stmt", "menu",
568 "menu_entry", "menu_end", "menu_stmt", "menu_block", "source_stmt", 571 "menu_entry", "menu_end", "menu_stmt", "menu_block", "source_stmt",
569 "comment", "comment_stmt", "help_start", "help", "depends_list", 572 "comment", "comment_stmt", "help_start", "help", "depends_list",
570 "depends", "prompt_stmt_opt", "prompt", "end", "nl", "if_expr", "expr", 573 "depends", "visibility_list", "visible", "prompt_stmt_opt", "prompt",
571 "symbol", "word_opt", 0 574 "end", "nl", "if_expr", "expr", "symbol", "word_opt", 0
572}; 575};
573#endif 576#endif
574 577
@@ -580,25 +583,25 @@ static const yytype_uint16 yytoknum[] =
580 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 583 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
581 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 584 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
582 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 585 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
583 285, 286, 287, 288, 289 586 285, 286, 287, 288, 289, 290
584}; 587};
585# endif 588# endif
586 589
587/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 590/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
588static const yytype_uint8 yyr1[] = 591static const yytype_uint8 yyr1[] =
589{ 592{
590 0, 35, 36, 36, 37, 37, 38, 38, 38, 38, 593 0, 36, 37, 37, 38, 38, 39, 39, 39, 39,
591 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 594 39, 39, 39, 39, 40, 40, 40, 40, 40, 40,
592 39, 40, 40, 40, 40, 40, 40, 41, 41, 42, 595 40, 40, 41, 41, 41, 41, 41, 41, 42, 42,
593 43, 44, 45, 46, 46, 46, 46, 46, 46, 46, 596 43, 44, 45, 46, 47, 47, 47, 47, 47, 47,
594 47, 47, 47, 47, 47, 48, 49, 49, 50, 50, 597 47, 48, 48, 48, 48, 48, 49, 50, 50, 51,
595 51, 52, 53, 54, 55, 55, 55, 55, 55, 55, 598 51, 52, 53, 54, 55, 56, 56, 56, 56, 56,
596 56, 56, 56, 56, 57, 57, 58, 59, 60, 61, 599 56, 57, 57, 57, 57, 58, 58, 59, 60, 61,
597 61, 61, 61, 62, 63, 64, 65, 66, 67, 67, 600 62, 62, 62, 62, 63, 64, 65, 66, 67, 68,
598 67, 67, 68, 69, 70, 71, 72, 73, 73, 73, 601 68, 68, 68, 69, 70, 71, 72, 73, 74, 74,
599 73, 74, 75, 75, 76, 76, 77, 77, 77, 78, 602 74, 74, 75, 76, 76, 76, 77, 78, 78, 79,
600 78, 79, 79, 80, 80, 80, 80, 80, 80, 80, 603 79, 80, 80, 80, 81, 81, 82, 82, 83, 83,
601 81, 81, 82, 82 604 83, 83, 83, 83, 83, 84, 84, 85, 85
602}; 605};
603 606
604/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ 607/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
@@ -606,16 +609,16 @@ static const yytype_uint8 yyr2[] =
606{ 609{
607 0, 2, 2, 1, 2, 1, 0, 2, 2, 2, 610 0, 2, 2, 1, 2, 1, 0, 2, 2, 2,
608 2, 4, 4, 3, 1, 1, 1, 1, 1, 1, 611 2, 4, 4, 3, 1, 1, 1, 1, 1, 1,
609 1, 1, 1, 1, 1, 1, 1, 3, 2, 3, 612 1, 1, 1, 1, 1, 1, 1, 1, 3, 2,
610 2, 3, 2, 0, 2, 2, 2, 2, 2, 2, 613 3, 2, 3, 2, 0, 2, 2, 2, 2, 2,
611 3, 4, 4, 4, 5, 3, 0, 3, 0, 2, 614 2, 3, 4, 4, 4, 5, 3, 0, 3, 0,
612 3, 2, 1, 3, 0, 2, 2, 2, 2, 2, 615 2, 3, 2, 1, 3, 0, 2, 2, 2, 2,
613 4, 3, 2, 4, 0, 2, 3, 1, 3, 0, 616 2, 4, 3, 2, 4, 0, 2, 3, 1, 3,
614 2, 2, 2, 3, 3, 2, 1, 3, 0, 2, 617 0, 2, 2, 2, 3, 3, 3, 1, 3, 0,
615 2, 2, 3, 3, 2, 2, 2, 0, 2, 2, 618 2, 2, 2, 3, 3, 2, 2, 2, 0, 2,
616 2, 4, 0, 2, 1, 1, 2, 2, 2, 1, 619 2, 2, 4, 0, 2, 2, 2, 0, 2, 1,
617 2, 0, 2, 1, 3, 3, 3, 2, 3, 3, 620 1, 2, 2, 2, 1, 2, 0, 2, 1, 3,
618 1, 1, 0, 1 621 3, 3, 2, 3, 3, 1, 1, 0, 1
619}; 622};
620 623
621/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state 624/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
@@ -623,165 +626,172 @@ static const yytype_uint8 yyr2[] =
623 means the default is an error. */ 626 means the default is an error. */
624static const yytype_uint8 yydefact[] = 627static const yytype_uint8 yydefact[] =
625{ 628{
626 6, 0, 99, 0, 3, 0, 6, 6, 94, 95, 629 6, 0, 104, 0, 3, 0, 6, 6, 99, 100,
627 0, 1, 0, 0, 0, 0, 112, 0, 0, 0, 630 0, 1, 0, 0, 0, 0, 117, 0, 0, 0,
628 0, 0, 0, 14, 18, 15, 16, 20, 17, 19, 631 0, 0, 0, 14, 18, 15, 16, 20, 17, 19,
629 0, 21, 0, 7, 33, 24, 33, 25, 54, 64, 632 21, 0, 22, 0, 7, 34, 25, 34, 26, 55,
630 8, 69, 22, 87, 78, 9, 26, 87, 23, 10, 633 65, 8, 70, 23, 93, 79, 9, 27, 88, 24,
631 0, 100, 2, 73, 13, 0, 96, 0, 113, 0, 634 10, 0, 105, 2, 74, 13, 0, 101, 0, 118,
632 97, 0, 0, 0, 110, 111, 0, 0, 0, 103, 635 0, 102, 0, 0, 0, 115, 116, 0, 0, 0,
633 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 636 108, 103, 0, 0, 0, 0, 0, 0, 0, 88,
634 0, 74, 82, 50, 83, 29, 31, 0, 107, 0, 637 0, 0, 75, 83, 51, 84, 30, 32, 0, 112,
635 0, 66, 0, 0, 11, 12, 0, 0, 0, 0, 638 0, 0, 67, 0, 0, 11, 12, 0, 0, 0,
636 92, 0, 0, 0, 46, 0, 39, 38, 34, 35, 639 0, 97, 0, 0, 0, 47, 0, 40, 39, 35,
637 0, 37, 36, 0, 0, 92, 0, 58, 59, 55, 640 36, 0, 38, 37, 0, 0, 97, 0, 59, 60,
638 57, 56, 65, 53, 52, 70, 72, 68, 71, 67, 641 56, 58, 57, 66, 54, 53, 71, 73, 69, 72,
639 89, 90, 88, 79, 81, 77, 80, 76, 106, 108, 642 68, 106, 95, 0, 94, 80, 82, 78, 81, 77,
640 109, 105, 104, 28, 85, 0, 101, 0, 101, 101, 643 90, 91, 89, 111, 113, 114, 110, 109, 29, 86,
641 101, 0, 0, 0, 86, 62, 101, 0, 101, 0, 644 0, 106, 0, 106, 106, 106, 0, 0, 0, 87,
642 0, 0, 40, 93, 0, 0, 101, 48, 45, 27, 645 63, 106, 0, 106, 0, 96, 0, 0, 41, 98,
643 0, 61, 0, 91, 102, 41, 42, 43, 0, 0, 646 0, 0, 106, 49, 46, 28, 0, 62, 0, 107,
644 47, 60, 63, 44, 49 647 92, 42, 43, 44, 0, 0, 48, 61, 64, 45,
648 50
645}; 649};
646 650
647/* YYDEFGOTO[NTERM-NUM]. */ 651/* YYDEFGOTO[NTERM-NUM]. */
648static const yytype_int16 yydefgoto[] = 652static const yytype_int16 yydefgoto[] =
649{ 653{
650 -1, 3, 4, 5, 32, 33, 107, 34, 35, 36, 654 -1, 3, 4, 5, 33, 34, 108, 35, 36, 37,
651 37, 73, 108, 109, 152, 180, 38, 39, 123, 40, 655 38, 74, 109, 110, 157, 186, 39, 40, 124, 41,
652 75, 119, 76, 41, 127, 42, 77, 6, 43, 44, 656 76, 120, 77, 42, 128, 43, 78, 6, 44, 45,
653 135, 45, 79, 46, 47, 48, 110, 111, 78, 112, 657 137, 46, 80, 47, 48, 49, 111, 112, 81, 113,
654 147, 148, 49, 7, 161, 68, 69, 59 658 79, 134, 152, 153, 50, 7, 165, 69, 70, 60
655}; 659};
656 660
657/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 661/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
658 STATE-NUM. */ 662 STATE-NUM. */
659#define YYPACT_NINF -89 663#define YYPACT_NINF -90
660static const yytype_int16 yypact[] = 664static const yytype_int16 yypact[] =
661{ 665{
662 3, 4, -89, 20, -89, 100, -89, 7, -89, -89, 666 4, 42, -90, 96, -90, 111, -90, 15, -90, -90,
663 -8, -89, 17, 4, 28, 4, 37, 36, 4, 68, 667 75, -90, 82, 42, 104, 42, 110, 107, 42, 115,
664 87, -18, 69, -89, -89, -89, -89, -89, -89, -89, 668 125, -4, 121, -90, -90, -90, -90, -90, -90, -90,
665 128, -89, 138, -89, -89, -89, -89, -89, -89, -89, 669 -90, 162, -90, 163, -90, -90, -90, -90, -90, -90,
666 -89, -89, -89, -89, -89, -89, -89, -89, -89, -89, 670 -90, -90, -90, -90, -90, -90, -90, -90, -90, -90,
667 127, -89, -89, 110, -89, 126, -89, 136, -89, 137, 671 -90, 139, -90, -90, 138, -90, 142, -90, 143, -90,
668 -89, 147, 150, 152, -89, -89, -18, -18, 171, -14, 672 152, -90, 164, 167, 168, -90, -90, -4, -4, 77,
669 -89, 153, 157, 34, 67, 180, 233, 220, 207, 220, 673 -18, -90, 177, 185, 33, 71, 195, 247, 236, -2,
670 154, -89, -89, -89, -89, -89, -89, 0, -89, -18, 674 236, 171, -90, -90, -90, -90, -90, -90, 41, -90,
671 -18, 110, 44, 44, -89, -89, 163, 174, 182, 4, 675 -4, -4, 138, 97, 97, -90, -90, 186, 187, 194,
672 4, -18, 194, 44, -89, 219, -89, -89, -89, -89, 676 42, 42, -4, 196, 97, -90, 219, -90, -90, -90,
673 223, -89, -89, 203, 4, 4, 215, -89, -89, -89, 677 -90, 210, -90, -90, 204, 42, 42, 199, -90, -90,
674 -89, -89, -89, -89, -89, -89, -89, -89, -89, -89, 678 -90, -90, -90, -90, -90, -90, -90, -90, -90, -90,
675 -89, -89, -89, -89, -89, -89, -89, -89, -89, 213, 679 -90, 222, -90, 223, -90, -90, -90, -90, -90, -90,
676 -89, -89, -89, -89, -89, -18, 232, 227, 232, -5, 680 -90, -90, -90, -90, 215, -90, -90, -90, -90, -90,
677 232, 44, 35, 234, -89, -89, 232, 235, 232, 224, 681 -4, 222, 228, 222, -5, 222, 97, 35, 229, -90,
678 -18, 236, -89, -89, 237, 238, 232, 216, -89, -89, 682 -90, 222, 232, 222, -4, -90, 135, 233, -90, -90,
679 240, -89, 241, -89, 71, -89, -89, -89, 242, 4, 683 234, 235, 222, 240, -90, -90, 237, -90, 239, -13,
680 -89, -89, -89, -89, -89 684 -90, -90, -90, -90, 244, 42, -90, -90, -90, -90,
685 -90
681}; 686};
682 687
683/* YYPGOTO[NTERM-NUM]. */ 688/* YYPGOTO[NTERM-NUM]. */
684static const yytype_int16 yypgoto[] = 689static const yytype_int16 yypgoto[] =
685{ 690{
686 -89, -89, 255, 267, -89, 47, -57, -89, -89, -89, 691 -90, -90, 269, 271, -90, 23, -70, -90, -90, -90,
687 -89, 239, -89, -89, -89, -89, -89, -89, -89, 130, 692 -90, 243, -90, -90, -90, -90, -90, -90, -90, -48,
688 -89, -89, -89, -89, -89, -89, -89, -89, -89, -89, 693 -90, -90, -90, -90, -90, -90, -90, -90, -90, -90,
689 -89, 181, -89, -89, -89, -89, -89, 199, 229, 16, 694 -90, -20, -90, -90, -90, -90, -90, 206, 205, -68,
690 162, -1, 74, -7, 103, -65, -88, -89 695 -90, -90, 169, -1, 27, -7, 118, -66, -89, -90
691}; 696};
692 697
693/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If 698/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
694 positive, shift that token. If negative, reduce the rule which 699 positive, shift that token. If negative, reduce the rule which
695 number is the opposite. If zero, do what YYDEFACT says. 700 number is the opposite. If zero, do what YYDEFACT says.
696 If YYTABLE_NINF, syntax error. */ 701 If YYTABLE_NINF, syntax error. */
697#define YYTABLE_NINF -85 702#define YYTABLE_NINF -86
698static const yytype_int16 yytable[] = 703static const yytype_int16 yytable[] =
699{ 704{
700 10, 87, 88, 53, 141, 142, 1, 64, 65, 160, 705 10, 88, 89, 54, 146, 147, 119, 1, 122, 164,
701 1, 66, 55, 92, 57, 151, 67, 61, 118, 93, 706 93, 141, 56, 142, 58, 156, 94, 62, 1, 90,
702 11, 131, 2, 131, 139, 140, 89, 90, 138, 8, 707 91, 131, 65, 66, 144, 145, 67, 90, 91, 132,
703 9, 89, 90, 2, -30, 96, 149, 51, -30, -30, 708 127, 68, 136, -31, 97, 2, 154, -31, -31, -31,
704 -30, -30, -30, -30, -30, -30, 97, 54, -30, -30, 709 -31, -31, -31, -31, -31, 98, 52, -31, -31, 99,
705 98, -30, 99, 100, 101, 102, 103, 104, 56, 105, 710 -31, 100, 101, 102, 103, 104, -31, 105, 129, 106,
706 167, 91, 58, 166, 106, 168, 60, -32, 96, 64, 711 138, 173, 92, 141, 107, 142, 174, 172, 8, 9,
707 65, -32, -32, -32, -32, -32, -32, -32, -32, 97, 712 143, -33, 97, 90, 91, -33, -33, -33, -33, -33,
708 159, -32, -32, 98, -32, 99, 100, 101, 102, 103, 713 -33, -33, -33, 98, 166, -33, -33, 99, -33, 100,
709 104, 121, 105, 62, 132, 174, 132, 106, 146, 70, 714 101, 102, 103, 104, -33, 105, 11, 106, 179, 151,
710 -5, 12, 89, 90, 13, 14, 15, 16, 17, 18, 715 123, 126, 107, 135, 125, 130, 2, 139, 2, 90,
711 19, 20, 63, 156, 21, 22, 23, 24, 25, 26, 716 91, -5, 12, 55, 161, 13, 14, 15, 16, 17,
712 27, 28, 29, 122, 125, 30, 133, -4, 12, 71, 717 18, 19, 20, 65, 66, 21, 22, 23, 24, 25,
713 31, 13, 14, 15, 16, 17, 18, 19, 20, 72, 718 26, 27, 28, 29, 30, 57, 59, 31, 61, -4,
714 51, 21, 22, 23, 24, 25, 26, 27, 28, 29, 719 12, 63, 32, 13, 14, 15, 16, 17, 18, 19,
715 124, 129, 30, 137, -84, 96, 81, 31, -84, -84, 720 20, 64, 71, 21, 22, 23, 24, 25, 26, 27,
716 -84, -84, -84, -84, -84, -84, 82, 83, -84, -84, 721 28, 29, 30, 72, 73, 31, 180, 90, 91, 52,
717 98, -84, -84, -84, -84, -84, -84, 84, 184, 105, 722 32, -85, 97, 82, 83, -85, -85, -85, -85, -85,
718 85, 96, 86, 94, 130, -51, -51, 95, -51, -51, 723 -85, -85, -85, 84, 190, -85, -85, 99, -85, -85,
719 -51, -51, 97, 143, -51, -51, 98, 113, 114, 115, 724 -85, -85, -85, -85, -85, 85, 97, 106, 86, 87,
720 116, 2, 89, 90, 144, 105, 145, 126, 96, 134, 725 -52, -52, 140, -52, -52, -52, -52, 98, 95, -52,
721 117, -75, -75, -75, -75, -75, -75, -75, -75, 150, 726 -52, 99, 114, 115, 116, 117, 96, 148, 149, 150,
722 153, -75, -75, 98, 13, 14, 15, 16, 17, 18, 727 158, 106, 155, 159, 97, 163, 118, -76, -76, -76,
723 19, 20, 105, 155, 21, 22, 154, 130, 14, 15, 728 -76, -76, -76, -76, -76, 160, 164, -76, -76, 99,
724 158, 17, 18, 19, 20, 90, 160, 21, 22, 179, 729 13, 14, 15, 16, 17, 18, 19, 20, 91, 106,
725 31, 163, 164, 165, 173, 89, 90, 162, 128, 170, 730 21, 22, 14, 15, 140, 17, 18, 19, 20, 168,
726 136, 172, 52, 31, 169, 171, 175, 176, 177, 178, 731 175, 21, 22, 177, 181, 182, 183, 32, 187, 167,
727 181, 182, 183, 50, 120, 74, 80, 157 732 188, 169, 170, 171, 185, 189, 53, 51, 32, 176,
733 75, 178, 121, 0, 133, 162, 0, 0, 0, 0,
734 184
728}; 735};
729 736
730static const yytype_uint8 yycheck[] = 737static const yytype_int16 yycheck[] =
731{ 738{
732 1, 66, 67, 10, 92, 93, 3, 25, 26, 14, 739 1, 67, 68, 10, 93, 94, 76, 3, 76, 14,
733 3, 29, 13, 27, 15, 103, 34, 18, 75, 33, 740 28, 81, 13, 81, 15, 104, 34, 18, 3, 32,
734 0, 78, 30, 80, 89, 90, 31, 32, 28, 25, 741 33, 23, 26, 27, 90, 91, 30, 32, 33, 31,
735 26, 31, 32, 30, 0, 1, 101, 30, 4, 5, 742 78, 35, 80, 0, 1, 31, 102, 4, 5, 6,
736 6, 7, 8, 9, 10, 11, 12, 30, 14, 15, 743 7, 8, 9, 10, 11, 12, 31, 14, 15, 16,
737 16, 17, 18, 19, 20, 21, 22, 23, 30, 25, 744 17, 18, 19, 20, 21, 22, 23, 24, 78, 26,
738 25, 68, 25, 151, 30, 30, 30, 0, 1, 25, 745 80, 26, 69, 133, 31, 133, 31, 156, 26, 27,
739 26, 4, 5, 6, 7, 8, 9, 10, 11, 12, 746 29, 0, 1, 32, 33, 4, 5, 6, 7, 8,
740 145, 14, 15, 16, 17, 18, 19, 20, 21, 22, 747 9, 10, 11, 12, 150, 14, 15, 16, 17, 18,
741 23, 75, 25, 25, 78, 160, 80, 30, 99, 30, 748 19, 20, 21, 22, 23, 24, 0, 26, 164, 100,
742 0, 1, 31, 32, 4, 5, 6, 7, 8, 9, 749 77, 78, 31, 80, 77, 78, 31, 80, 31, 32,
743 10, 11, 25, 114, 14, 15, 16, 17, 18, 19, 750 33, 0, 1, 31, 115, 4, 5, 6, 7, 8,
744 20, 21, 22, 76, 77, 25, 79, 0, 1, 1, 751 9, 10, 11, 26, 27, 14, 15, 16, 17, 18,
745 30, 4, 5, 6, 7, 8, 9, 10, 11, 1, 752 19, 20, 21, 22, 23, 31, 26, 26, 31, 0,
746 30, 14, 15, 16, 17, 18, 19, 20, 21, 22, 753 1, 26, 31, 4, 5, 6, 7, 8, 9, 10,
747 76, 77, 25, 79, 0, 1, 30, 30, 4, 5, 754 11, 26, 31, 14, 15, 16, 17, 18, 19, 20,
748 6, 7, 8, 9, 10, 11, 30, 30, 14, 15, 755 21, 22, 23, 1, 1, 26, 31, 32, 33, 31,
749 16, 17, 18, 19, 20, 21, 22, 30, 179, 25, 756 31, 0, 1, 31, 31, 4, 5, 6, 7, 8,
750 30, 1, 30, 30, 30, 5, 6, 30, 8, 9, 757 9, 10, 11, 31, 185, 14, 15, 16, 17, 18,
751 10, 11, 12, 30, 14, 15, 16, 17, 18, 19, 758 19, 20, 21, 22, 23, 31, 1, 26, 31, 31,
752 20, 30, 31, 32, 30, 25, 24, 77, 1, 79, 759 5, 6, 31, 8, 9, 10, 11, 12, 31, 14,
753 30, 4, 5, 6, 7, 8, 9, 10, 11, 25, 760 15, 16, 17, 18, 19, 20, 31, 31, 31, 25,
754 1, 14, 15, 16, 4, 5, 6, 7, 8, 9, 761 1, 26, 26, 13, 1, 26, 31, 4, 5, 6,
755 10, 11, 25, 30, 14, 15, 13, 30, 5, 6, 762 7, 8, 9, 10, 11, 31, 14, 14, 15, 16,
756 25, 8, 9, 10, 11, 32, 14, 14, 15, 33, 763 4, 5, 6, 7, 8, 9, 10, 11, 33, 26,
757 30, 148, 149, 150, 30, 31, 32, 30, 77, 156, 764 14, 15, 5, 6, 31, 8, 9, 10, 11, 31,
758 79, 158, 7, 30, 30, 30, 30, 30, 30, 166, 765 31, 14, 15, 31, 31, 31, 31, 31, 31, 151,
759 30, 30, 30, 6, 75, 36, 47, 115 766 31, 153, 154, 155, 34, 31, 7, 6, 31, 161,
767 37, 163, 76, -1, 79, 116, -1, -1, -1, -1,
768 172
760}; 769};
761 770
762/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 771/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
763 symbol of state STATE-NUM. */ 772 symbol of state STATE-NUM. */
764static const yytype_uint8 yystos[] = 773static const yytype_uint8 yystos[] =
765{ 774{
766 0, 3, 30, 36, 37, 38, 62, 78, 25, 26, 775 0, 3, 31, 37, 38, 39, 63, 81, 26, 27,
767 76, 0, 1, 4, 5, 6, 7, 8, 9, 10, 776 79, 0, 1, 4, 5, 6, 7, 8, 9, 10,
768 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 777 11, 14, 15, 16, 17, 18, 19, 20, 21, 22,
769 25, 30, 39, 40, 42, 43, 44, 45, 51, 52, 778 23, 26, 31, 40, 41, 43, 44, 45, 46, 52,
770 54, 58, 60, 63, 64, 66, 68, 69, 70, 77, 779 53, 55, 59, 61, 64, 65, 67, 69, 70, 71,
771 38, 30, 37, 78, 30, 76, 30, 76, 25, 82, 780 80, 39, 31, 38, 81, 31, 79, 31, 79, 26,
772 30, 76, 25, 25, 25, 26, 29, 34, 80, 81, 781 85, 31, 79, 26, 26, 26, 27, 30, 35, 83,
773 30, 1, 1, 46, 46, 55, 57, 61, 73, 67, 782 84, 31, 1, 1, 47, 47, 56, 58, 62, 76,
774 73, 30, 30, 30, 30, 30, 30, 80, 80, 31, 783 68, 74, 31, 31, 31, 31, 31, 31, 83, 83,
775 32, 78, 27, 33, 30, 30, 1, 12, 16, 18, 784 32, 33, 81, 28, 34, 31, 31, 1, 12, 16,
776 19, 20, 21, 22, 23, 25, 30, 41, 47, 48, 785 18, 19, 20, 21, 22, 24, 26, 31, 42, 48,
777 71, 72, 74, 17, 18, 19, 20, 30, 41, 56, 786 49, 72, 73, 75, 17, 18, 19, 20, 31, 42,
778 72, 74, 40, 53, 77, 40, 54, 59, 66, 77, 787 57, 73, 75, 41, 54, 80, 41, 55, 60, 67,
779 30, 41, 74, 40, 54, 65, 66, 77, 28, 80, 788 80, 23, 31, 74, 77, 41, 55, 66, 67, 80,
780 80, 81, 81, 30, 30, 24, 76, 75, 76, 80, 789 31, 42, 75, 29, 83, 83, 84, 84, 31, 31,
781 25, 81, 49, 1, 13, 30, 76, 75, 25, 80, 790 25, 79, 78, 79, 83, 26, 84, 50, 1, 13,
782 14, 79, 30, 79, 79, 79, 81, 25, 30, 30, 791 31, 79, 78, 26, 14, 82, 83, 82, 31, 82,
783 79, 30, 79, 30, 80, 30, 30, 30, 79, 33, 792 82, 82, 84, 26, 31, 31, 82, 31, 82, 83,
784 50, 30, 30, 30, 76 793 31, 31, 31, 31, 82, 34, 51, 31, 31, 31,
794 79
785}; 795};
786 796
787#define yyerrok (yyerrstatus = 0) 797#define yyerrok (yyerrstatus = 0)
@@ -1292,7 +1302,7 @@ yydestruct (yymsg, yytype, yyvaluep)
1292 1302
1293 switch (yytype) 1303 switch (yytype)
1294 { 1304 {
1295 case 52: /* "choice_entry" */ 1305 case 53: /* "choice_entry" */
1296 1306
1297 { 1307 {
1298 fprintf(stderr, "%s:%d: missing end statement for this entry\n", 1308 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
@@ -1302,7 +1312,7 @@ yydestruct (yymsg, yytype, yyvaluep)
1302}; 1312};
1303 1313
1304 break; 1314 break;
1305 case 58: /* "if_entry" */ 1315 case 59: /* "if_entry" */
1306 1316
1307 { 1317 {
1308 fprintf(stderr, "%s:%d: missing end statement for this entry\n", 1318 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
@@ -1312,7 +1322,7 @@ yydestruct (yymsg, yytype, yyvaluep)
1312}; 1322};
1313 1323
1314 break; 1324 break;
1315 case 64: /* "menu_entry" */ 1325 case 65: /* "menu_entry" */
1316 1326
1317 { 1327 {
1318 fprintf(stderr, "%s:%d: missing end statement for this entry\n", 1328 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
@@ -1644,17 +1654,17 @@ yyreduce:
1644 { zconf_error("invalid statement"); ;} 1654 { zconf_error("invalid statement"); ;}
1645 break; 1655 break;
1646 1656
1647 case 27: 1657 case 28:
1648 1658
1649 { zconf_error("unknown option \"%s\"", (yyvsp[(1) - (3)].string)); ;} 1659 { zconf_error("unknown option \"%s\"", (yyvsp[(1) - (3)].string)); ;}
1650 break; 1660 break;
1651 1661
1652 case 28: 1662 case 29:
1653 1663
1654 { zconf_error("invalid option"); ;} 1664 { zconf_error("invalid option"); ;}
1655 break; 1665 break;
1656 1666
1657 case 29: 1667 case 30:
1658 1668
1659 { 1669 {
1660 struct symbol *sym = sym_lookup((yyvsp[(2) - (3)].string), 0); 1670 struct symbol *sym = sym_lookup((yyvsp[(2) - (3)].string), 0);
@@ -1664,7 +1674,7 @@ yyreduce:
1664;} 1674;}
1665 break; 1675 break;
1666 1676
1667 case 30: 1677 case 31:
1668 1678
1669 { 1679 {
1670 menu_end_entry(); 1680 menu_end_entry();
@@ -1672,7 +1682,7 @@ yyreduce:
1672;} 1682;}
1673 break; 1683 break;
1674 1684
1675 case 31: 1685 case 32:
1676 1686
1677 { 1687 {
1678 struct symbol *sym = sym_lookup((yyvsp[(2) - (3)].string), 0); 1688 struct symbol *sym = sym_lookup((yyvsp[(2) - (3)].string), 0);
@@ -1682,7 +1692,7 @@ yyreduce:
1682;} 1692;}
1683 break; 1693 break;
1684 1694
1685 case 32: 1695 case 33:
1686 1696
1687 { 1697 {
1688 if (current_entry->prompt) 1698 if (current_entry->prompt)
@@ -1694,7 +1704,7 @@ yyreduce:
1694;} 1704;}
1695 break; 1705 break;
1696 1706
1697 case 40: 1707 case 41:
1698 1708
1699 { 1709 {
1700 menu_set_type((yyvsp[(1) - (3)].id)->stype); 1710 menu_set_type((yyvsp[(1) - (3)].id)->stype);
@@ -1704,7 +1714,7 @@ yyreduce:
1704;} 1714;}
1705 break; 1715 break;
1706 1716
1707 case 41: 1717 case 42:
1708 1718
1709 { 1719 {
1710 menu_add_prompt(P_PROMPT, (yyvsp[(2) - (4)].string), (yyvsp[(3) - (4)].expr)); 1720 menu_add_prompt(P_PROMPT, (yyvsp[(2) - (4)].string), (yyvsp[(3) - (4)].expr));
@@ -1712,7 +1722,7 @@ yyreduce:
1712;} 1722;}
1713 break; 1723 break;
1714 1724
1715 case 42: 1725 case 43:
1716 1726
1717 { 1727 {
1718 menu_add_expr(P_DEFAULT, (yyvsp[(2) - (4)].expr), (yyvsp[(3) - (4)].expr)); 1728 menu_add_expr(P_DEFAULT, (yyvsp[(2) - (4)].expr), (yyvsp[(3) - (4)].expr));
@@ -1724,7 +1734,7 @@ yyreduce:
1724;} 1734;}
1725 break; 1735 break;
1726 1736
1727 case 43: 1737 case 44:
1728 1738
1729 { 1739 {
1730 menu_add_symbol(P_SELECT, sym_lookup((yyvsp[(2) - (4)].string), 0), (yyvsp[(3) - (4)].expr)); 1740 menu_add_symbol(P_SELECT, sym_lookup((yyvsp[(2) - (4)].string), 0), (yyvsp[(3) - (4)].expr));
@@ -1732,7 +1742,7 @@ yyreduce:
1732;} 1742;}
1733 break; 1743 break;
1734 1744
1735 case 44: 1745 case 45:
1736 1746
1737 { 1747 {
1738 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,(yyvsp[(2) - (5)].symbol), (yyvsp[(3) - (5)].symbol)), (yyvsp[(4) - (5)].expr)); 1748 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,(yyvsp[(2) - (5)].symbol), (yyvsp[(3) - (5)].symbol)), (yyvsp[(4) - (5)].expr));
@@ -1740,7 +1750,7 @@ yyreduce:
1740;} 1750;}
1741 break; 1751 break;
1742 1752
1743 case 47: 1753 case 48:
1744 1754
1745 { 1755 {
1746 struct kconf_id *id = kconf_id_lookup((yyvsp[(2) - (3)].string), strlen((yyvsp[(2) - (3)].string))); 1756 struct kconf_id *id = kconf_id_lookup((yyvsp[(2) - (3)].string), strlen((yyvsp[(2) - (3)].string)));
@@ -1752,17 +1762,17 @@ yyreduce:
1752;} 1762;}
1753 break; 1763 break;
1754 1764
1755 case 48: 1765 case 49:
1756 1766
1757 { (yyval.string) = NULL; ;} 1767 { (yyval.string) = NULL; ;}
1758 break; 1768 break;
1759 1769
1760 case 49: 1770 case 50:
1761 1771
1762 { (yyval.string) = (yyvsp[(2) - (2)].string); ;} 1772 { (yyval.string) = (yyvsp[(2) - (2)].string); ;}
1763 break; 1773 break;
1764 1774
1765 case 50: 1775 case 51:
1766 1776
1767 { 1777 {
1768 struct symbol *sym = sym_lookup((yyvsp[(2) - (3)].string), SYMBOL_CHOICE); 1778 struct symbol *sym = sym_lookup((yyvsp[(2) - (3)].string), SYMBOL_CHOICE);
@@ -1773,14 +1783,14 @@ yyreduce:
1773;} 1783;}
1774 break; 1784 break;
1775 1785
1776 case 51: 1786 case 52:
1777 1787
1778 { 1788 {
1779 (yyval.menu) = menu_add_menu(); 1789 (yyval.menu) = menu_add_menu();
1780;} 1790;}
1781 break; 1791 break;
1782 1792
1783 case 52: 1793 case 53:
1784 1794
1785 { 1795 {
1786 if (zconf_endtoken((yyvsp[(1) - (1)].id), T_CHOICE, T_ENDCHOICE)) { 1796 if (zconf_endtoken((yyvsp[(1) - (1)].id), T_CHOICE, T_ENDCHOICE)) {
@@ -1790,7 +1800,7 @@ yyreduce:
1790;} 1800;}
1791 break; 1801 break;
1792 1802
1793 case 60: 1803 case 61:
1794 1804
1795 { 1805 {
1796 menu_add_prompt(P_PROMPT, (yyvsp[(2) - (4)].string), (yyvsp[(3) - (4)].expr)); 1806 menu_add_prompt(P_PROMPT, (yyvsp[(2) - (4)].string), (yyvsp[(3) - (4)].expr));
@@ -1798,7 +1808,7 @@ yyreduce:
1798;} 1808;}
1799 break; 1809 break;
1800 1810
1801 case 61: 1811 case 62:
1802 1812
1803 { 1813 {
1804 if ((yyvsp[(1) - (3)].id)->stype == S_BOOLEAN || (yyvsp[(1) - (3)].id)->stype == S_TRISTATE) { 1814 if ((yyvsp[(1) - (3)].id)->stype == S_BOOLEAN || (yyvsp[(1) - (3)].id)->stype == S_TRISTATE) {
@@ -1811,7 +1821,7 @@ yyreduce:
1811;} 1821;}
1812 break; 1822 break;
1813 1823
1814 case 62: 1824 case 63:
1815 1825
1816 { 1826 {
1817 current_entry->sym->flags |= SYMBOL_OPTIONAL; 1827 current_entry->sym->flags |= SYMBOL_OPTIONAL;
@@ -1819,7 +1829,7 @@ yyreduce:
1819;} 1829;}
1820 break; 1830 break;
1821 1831
1822 case 63: 1832 case 64:
1823 1833
1824 { 1834 {
1825 if ((yyvsp[(1) - (4)].id)->stype == S_UNKNOWN) { 1835 if ((yyvsp[(1) - (4)].id)->stype == S_UNKNOWN) {
@@ -1831,7 +1841,7 @@ yyreduce:
1831;} 1841;}
1832 break; 1842 break;
1833 1843
1834 case 66: 1844 case 67:
1835 1845
1836 { 1846 {
1837 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno()); 1847 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
@@ -1841,7 +1851,7 @@ yyreduce:
1841;} 1851;}
1842 break; 1852 break;
1843 1853
1844 case 67: 1854 case 68:
1845 1855
1846 { 1856 {
1847 if (zconf_endtoken((yyvsp[(1) - (1)].id), T_IF, T_ENDIF)) { 1857 if (zconf_endtoken((yyvsp[(1) - (1)].id), T_IF, T_ENDIF)) {
@@ -1851,14 +1861,14 @@ yyreduce:
1851;} 1861;}
1852 break; 1862 break;
1853 1863
1854 case 73: 1864 case 74:
1855 1865
1856 { 1866 {
1857 menu_add_prompt(P_MENU, (yyvsp[(2) - (3)].string), NULL); 1867 menu_add_prompt(P_MENU, (yyvsp[(2) - (3)].string), NULL);
1858;} 1868;}
1859 break; 1869 break;
1860 1870
1861 case 74: 1871 case 75:
1862 1872
1863 { 1873 {
1864 menu_add_entry(NULL); 1874 menu_add_entry(NULL);
@@ -1867,14 +1877,14 @@ yyreduce:
1867;} 1877;}
1868 break; 1878 break;
1869 1879
1870 case 75: 1880 case 76:
1871 1881
1872 { 1882 {
1873 (yyval.menu) = menu_add_menu(); 1883 (yyval.menu) = menu_add_menu();
1874;} 1884;}
1875 break; 1885 break;
1876 1886
1877 case 76: 1887 case 77:
1878 1888
1879 { 1889 {
1880 if (zconf_endtoken((yyvsp[(1) - (1)].id), T_MENU, T_ENDMENU)) { 1890 if (zconf_endtoken((yyvsp[(1) - (1)].id), T_MENU, T_ENDMENU)) {
@@ -1884,7 +1894,7 @@ yyreduce:
1884;} 1894;}
1885 break; 1895 break;
1886 1896
1887 case 82: 1897 case 83:
1888 1898
1889 { 1899 {
1890 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), (yyvsp[(2) - (3)].string)); 1900 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), (yyvsp[(2) - (3)].string));
@@ -1892,7 +1902,7 @@ yyreduce:
1892;} 1902;}
1893 break; 1903 break;
1894 1904
1895 case 83: 1905 case 84:
1896 1906
1897 { 1907 {
1898 menu_add_entry(NULL); 1908 menu_add_entry(NULL);
@@ -1901,14 +1911,14 @@ yyreduce:
1901;} 1911;}
1902 break; 1912 break;
1903 1913
1904 case 84: 1914 case 85:
1905 1915
1906 { 1916 {
1907 menu_end_entry(); 1917 menu_end_entry();
1908;} 1918;}
1909 break; 1919 break;
1910 1920
1911 case 85: 1921 case 86:
1912 1922
1913 { 1923 {
1914 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno()); 1924 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
@@ -1916,14 +1926,14 @@ yyreduce:
1916;} 1926;}
1917 break; 1927 break;
1918 1928
1919 case 86: 1929 case 87:
1920 1930
1921 { 1931 {
1922 current_entry->help = (yyvsp[(2) - (2)].string); 1932 current_entry->help = (yyvsp[(2) - (2)].string);
1923;} 1933;}
1924 break; 1934 break;
1925 1935
1926 case 91: 1936 case 92:
1927 1937
1928 { 1938 {
1929 menu_add_dep((yyvsp[(3) - (4)].expr)); 1939 menu_add_dep((yyvsp[(3) - (4)].expr));
@@ -1931,84 +1941,91 @@ yyreduce:
1931;} 1941;}
1932 break; 1942 break;
1933 1943
1934 case 93: 1944 case 96:
1945
1946 {
1947 menu_add_visibility((yyvsp[(2) - (2)].expr));
1948;}
1949 break;
1950
1951 case 98:
1935 1952
1936 { 1953 {
1937 menu_add_prompt(P_PROMPT, (yyvsp[(1) - (2)].string), (yyvsp[(2) - (2)].expr)); 1954 menu_add_prompt(P_PROMPT, (yyvsp[(1) - (2)].string), (yyvsp[(2) - (2)].expr));
1938;} 1955;}
1939 break; 1956 break;
1940 1957
1941 case 96: 1958 case 101:
1942 1959
1943 { (yyval.id) = (yyvsp[(1) - (2)].id); ;} 1960 { (yyval.id) = (yyvsp[(1) - (2)].id); ;}
1944 break; 1961 break;
1945 1962
1946 case 97: 1963 case 102:
1947 1964
1948 { (yyval.id) = (yyvsp[(1) - (2)].id); ;} 1965 { (yyval.id) = (yyvsp[(1) - (2)].id); ;}
1949 break; 1966 break;
1950 1967
1951 case 98: 1968 case 103:
1952 1969
1953 { (yyval.id) = (yyvsp[(1) - (2)].id); ;} 1970 { (yyval.id) = (yyvsp[(1) - (2)].id); ;}
1954 break; 1971 break;
1955 1972
1956 case 101: 1973 case 106:
1957 1974
1958 { (yyval.expr) = NULL; ;} 1975 { (yyval.expr) = NULL; ;}
1959 break; 1976 break;
1960 1977
1961 case 102: 1978 case 107:
1962 1979
1963 { (yyval.expr) = (yyvsp[(2) - (2)].expr); ;} 1980 { (yyval.expr) = (yyvsp[(2) - (2)].expr); ;}
1964 break; 1981 break;
1965 1982
1966 case 103: 1983 case 108:
1967 1984
1968 { (yyval.expr) = expr_alloc_symbol((yyvsp[(1) - (1)].symbol)); ;} 1985 { (yyval.expr) = expr_alloc_symbol((yyvsp[(1) - (1)].symbol)); ;}
1969 break; 1986 break;
1970 1987
1971 case 104: 1988 case 109:
1972 1989
1973 { (yyval.expr) = expr_alloc_comp(E_EQUAL, (yyvsp[(1) - (3)].symbol), (yyvsp[(3) - (3)].symbol)); ;} 1990 { (yyval.expr) = expr_alloc_comp(E_EQUAL, (yyvsp[(1) - (3)].symbol), (yyvsp[(3) - (3)].symbol)); ;}
1974 break; 1991 break;
1975 1992
1976 case 105: 1993 case 110:
1977 1994
1978 { (yyval.expr) = expr_alloc_comp(E_UNEQUAL, (yyvsp[(1) - (3)].symbol), (yyvsp[(3) - (3)].symbol)); ;} 1995 { (yyval.expr) = expr_alloc_comp(E_UNEQUAL, (yyvsp[(1) - (3)].symbol), (yyvsp[(3) - (3)].symbol)); ;}
1979 break; 1996 break;
1980 1997
1981 case 106: 1998 case 111:
1982 1999
1983 { (yyval.expr) = (yyvsp[(2) - (3)].expr); ;} 2000 { (yyval.expr) = (yyvsp[(2) - (3)].expr); ;}
1984 break; 2001 break;
1985 2002
1986 case 107: 2003 case 112:
1987 2004
1988 { (yyval.expr) = expr_alloc_one(E_NOT, (yyvsp[(2) - (2)].expr)); ;} 2005 { (yyval.expr) = expr_alloc_one(E_NOT, (yyvsp[(2) - (2)].expr)); ;}
1989 break; 2006 break;
1990 2007
1991 case 108: 2008 case 113:
1992 2009
1993 { (yyval.expr) = expr_alloc_two(E_OR, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;} 2010 { (yyval.expr) = expr_alloc_two(E_OR, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
1994 break; 2011 break;
1995 2012
1996 case 109: 2013 case 114:
1997 2014
1998 { (yyval.expr) = expr_alloc_two(E_AND, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;} 2015 { (yyval.expr) = expr_alloc_two(E_AND, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
1999 break; 2016 break;
2000 2017
2001 case 110: 2018 case 115:
2002 2019
2003 { (yyval.symbol) = sym_lookup((yyvsp[(1) - (1)].string), 0); free((yyvsp[(1) - (1)].string)); ;} 2020 { (yyval.symbol) = sym_lookup((yyvsp[(1) - (1)].string), 0); free((yyvsp[(1) - (1)].string)); ;}
2004 break; 2021 break;
2005 2022
2006 case 111: 2023 case 116:
2007 2024
2008 { (yyval.symbol) = sym_lookup((yyvsp[(1) - (1)].string), SYMBOL_CONST); free((yyvsp[(1) - (1)].string)); ;} 2025 { (yyval.symbol) = sym_lookup((yyvsp[(1) - (1)].string), SYMBOL_CONST); free((yyvsp[(1) - (1)].string)); ;}
2009 break; 2026 break;
2010 2027
2011 case 112: 2028 case 117:
2012 2029
2013 { (yyval.string) = NULL; ;} 2030 { (yyval.string) = NULL; ;}
2014 break; 2031 break;
@@ -2278,6 +2295,7 @@ static const char *zconf_tokenname(int token)
2278 case T_IF: return "if"; 2295 case T_IF: return "if";
2279 case T_ENDIF: return "endif"; 2296 case T_ENDIF: return "endif";
2280 case T_DEPENDS: return "depends"; 2297 case T_DEPENDS: return "depends";
2298 case T_VISIBLE: return "visible";
2281 } 2299 }
2282 return "<token>"; 2300 return "<token>";
2283} 2301}
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 2abd3c7ff15d..49fb4ab664c3 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -36,7 +36,7 @@ static struct menu *current_menu, *current_entry;
36#define YYERROR_VERBOSE 36#define YYERROR_VERBOSE
37#endif 37#endif
38%} 38%}
39%expect 28 39%expect 30
40 40
41%union 41%union
42{ 42{
@@ -68,6 +68,7 @@ static struct menu *current_menu, *current_entry;
68%token <id>T_DEFAULT 68%token <id>T_DEFAULT
69%token <id>T_SELECT 69%token <id>T_SELECT
70%token <id>T_RANGE 70%token <id>T_RANGE
71%token <id>T_VISIBLE
71%token <id>T_OPTION 72%token <id>T_OPTION
72%token <id>T_ON 73%token <id>T_ON
73%token <string> T_WORD 74%token <string> T_WORD
@@ -123,7 +124,7 @@ stmt_list:
123; 124;
124 125
125option_name: 126option_name:
126 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT 127 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
127; 128;
128 129
129common_stmt: 130common_stmt:
@@ -359,7 +360,7 @@ menu: T_MENU prompt T_EOL
359 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno()); 360 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
360}; 361};
361 362
362menu_entry: menu depends_list 363menu_entry: menu visibility_list depends_list
363{ 364{
364 $$ = menu_add_menu(); 365 $$ = menu_add_menu();
365}; 366};
@@ -430,6 +431,19 @@ depends: T_DEPENDS T_ON expr T_EOL
430 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno()); 431 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
431}; 432};
432 433
434/* visibility option */
435
436visibility_list:
437 /* empty */
438 | visibility_list visible
439 | visibility_list T_EOL
440;
441
442visible: T_VISIBLE if_expr
443{
444 menu_add_visibility($2);
445};
446
433/* prompt statement */ 447/* prompt statement */
434 448
435prompt_stmt_opt: 449prompt_stmt_opt:
@@ -526,6 +540,7 @@ static const char *zconf_tokenname(int token)
526 case T_IF: return "if"; 540 case T_IF: return "if";
527 case T_ENDIF: return "endif"; 541 case T_ENDIF: return "endif";
528 case T_DEPENDS: return "depends"; 542 case T_DEPENDS: return "depends";
543 case T_VISIBLE: return "visible";
529 } 544 }
530 return "<token>"; 545 return "<token>";
531} 546}
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index cdb6dc1f6458..39580a5dc5df 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -5,7 +5,7 @@ use strict;
5## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 5## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
7## Copyright (C) 2001 Simon Huggins ## 7## Copyright (C) 2001 Simon Huggins ##
8## Copyright (C) 2005-2009 Randy Dunlap ## 8## Copyright (C) 2005-2010 Randy Dunlap ##
9## ## 9## ##
10## #define enhancements by Armin Kuster <akuster@mvista.com> ## 10## #define enhancements by Armin Kuster <akuster@mvista.com> ##
11## Copyright (c) 2000 MontaVista Software, Inc. ## 11## Copyright (c) 2000 MontaVista Software, Inc. ##
@@ -453,7 +453,7 @@ sub output_highlight {
453 if ($output_mode eq "html" || $output_mode eq "xml") { 453 if ($output_mode eq "html" || $output_mode eq "xml") {
454 $contents = local_unescape($contents); 454 $contents = local_unescape($contents);
455 # convert data read & converted thru xml_escape() into &xyz; format: 455 # convert data read & converted thru xml_escape() into &xyz; format:
456 $contents =~ s/\\\\\\/&/g; 456 $contents =~ s/\\\\\\/\&/g;
457 } 457 }
458# print STDERR "contents b4:$contents\n"; 458# print STDERR "contents b4:$contents\n";
459 eval $dohighlight; 459 eval $dohighlight;
@@ -770,7 +770,11 @@ sub output_struct_xml(%) {
770 print $args{'type'} . " " . $args{'struct'} . " {\n"; 770 print $args{'type'} . " " . $args{'struct'} . " {\n";
771 foreach $parameter (@{$args{'parameterlist'}}) { 771 foreach $parameter (@{$args{'parameterlist'}}) {
772 if ($parameter =~ /^#/) { 772 if ($parameter =~ /^#/) {
773 print "$parameter\n"; 773 my $prm = $parameter;
774 # convert data read & converted thru xml_escape() into &xyz; format:
775 # This allows us to have #define macros interspersed in a struct.
776 $prm =~ s/\\\\\\/\&/g;
777 print "$prm\n";
774 next; 778 next;
775 } 779 }
776 780
@@ -1701,6 +1705,8 @@ sub push_parameter($$$) {
1701 } 1705 }
1702 } 1706 }
1703 1707
1708 $param = xml_escape($param);
1709
1704 # strip spaces from $param so that it is one continous string 1710 # strip spaces from $param so that it is one continous string
1705 # on @parameterlist; 1711 # on @parameterlist;
1706 # this fixes a problem where check_sections() cannot find 1712 # this fixes a problem where check_sections() cannot find
diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h
index 58e933a20544..39667174971d 100644
--- a/scripts/recordmcount.h
+++ b/scripts/recordmcount.h
@@ -119,7 +119,7 @@ static uint_t (*Elf_r_sym)(Elf_Rel const *rp) = fn_ELF_R_SYM;
119 119
120static void fn_ELF_R_INFO(Elf_Rel *const rp, unsigned sym, unsigned type) 120static void fn_ELF_R_INFO(Elf_Rel *const rp, unsigned sym, unsigned type)
121{ 121{
122 rp->r_info = ELF_R_INFO(sym, type); 122 rp->r_info = _w(ELF_R_INFO(sym, type));
123} 123}
124static void (*Elf_r_info)(Elf_Rel *const rp, unsigned sym, unsigned type) = fn_ELF_R_INFO; 124static void (*Elf_r_info)(Elf_Rel *const rp, unsigned sym, unsigned type) = fn_ELF_R_INFO;
125 125
diff --git a/scripts/tags.sh b/scripts/tags.sh
index 8509bb512935..bbbe584d4494 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -125,7 +125,9 @@ exuberant()
125 -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \ 125 -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
126 --extra=+f --c-kinds=-px \ 126 --extra=+f --c-kinds=-px \
127 --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' \ 127 --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' \
128 --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' 128 --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' \
129 --regex-c++='/^TRACE_EVENT\(([^,)]*).*/trace_\1/' \
130 --regex-c++='/^DEFINE_EVENT\(([^,)]*).*/trace_\1/'
129 131
130 all_kconfigs | xargs $1 -a \ 132 all_kconfigs | xargs $1 -a \
131 --langdef=kconfig --language-force=kconfig \ 133 --langdef=kconfig --language-force=kconfig \
diff --git a/security/Kconfig b/security/Kconfig
index bd72ae623494..e80da955e687 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -39,6 +39,18 @@ config KEYS_DEBUG_PROC_KEYS
39 39
40 If you are unsure as to whether this is required, answer N. 40 If you are unsure as to whether this is required, answer N.
41 41
42config SECURITY_DMESG_RESTRICT
43 bool "Restrict unprivileged access to the kernel syslog"
44 default n
45 help
46 This enforces restrictions on unprivileged users reading the kernel
47 syslog via dmesg(8).
48
49 If this option is not selected, no restrictions will be enforced
50 unless the dmesg_restrict sysctl is explicitly set to (1).
51
52 If you are unsure how to answer this question, answer N.
53
42config SECURITY 54config SECURITY
43 bool "Enable different security models" 55 bool "Enable different security models"
44 depends on SYSFS 56 depends on SYSFS
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index cf1de4462ccd..b7106f192b75 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -922,7 +922,7 @@ static int __init apparmor_init(void)
922 error = register_security(&apparmor_ops); 922 error = register_security(&apparmor_ops);
923 if (error) { 923 if (error) {
924 AA_ERROR("Unable to register AppArmor\n"); 924 AA_ERROR("Unable to register AppArmor\n");
925 goto register_security_out; 925 goto set_init_cxt_out;
926 } 926 }
927 927
928 /* Report that AppArmor successfully initialized */ 928 /* Report that AppArmor successfully initialized */
@@ -936,6 +936,9 @@ static int __init apparmor_init(void)
936 936
937 return error; 937 return error;
938 938
939set_init_cxt_out:
940 aa_free_task_context(current->real_cred->security);
941
939register_security_out: 942register_security_out:
940 aa_free_root_ns(); 943 aa_free_root_ns();
941 944
@@ -944,7 +947,6 @@ alloc_out:
944 947
945 apparmor_enabled = 0; 948 apparmor_enabled = 0;
946 return error; 949 return error;
947
948} 950}
949 951
950security_initcall(apparmor_init); 952security_initcall(apparmor_init);
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 52cc865f1464..4f0eadee78b8 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -306,7 +306,7 @@ static struct aa_namespace *alloc_namespace(const char *prefix,
306 return ns; 306 return ns;
307 307
308fail_unconfined: 308fail_unconfined:
309 kzfree(ns->base.name); 309 kzfree(ns->base.hname);
310fail_ns: 310fail_ns:
311 kzfree(ns); 311 kzfree(ns);
312 return NULL; 312 return NULL;
diff --git a/security/capability.c b/security/capability.c
index 30ae00fbecd5..c773635ca3a0 100644
--- a/security/capability.c
+++ b/security/capability.c
@@ -17,6 +17,11 @@ static int cap_sysctl(ctl_table *table, int op)
17 return 0; 17 return 0;
18} 18}
19 19
20static int cap_syslog(int type)
21{
22 return 0;
23}
24
20static int cap_quotactl(int cmds, int type, int id, struct super_block *sb) 25static int cap_quotactl(int cmds, int type, int id, struct super_block *sb)
21{ 26{
22 return 0; 27 return 0;
diff --git a/security/commoncap.c b/security/commoncap.c
index 5e632b4857e4..64c2ed9c9015 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -27,7 +27,6 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/prctl.h> 28#include <linux/prctl.h>
29#include <linux/securebits.h> 29#include <linux/securebits.h>
30#include <linux/syslog.h>
31 30
32/* 31/*
33 * If a non-root user executes a setuid-root binary in 32 * If a non-root user executes a setuid-root binary in
@@ -884,24 +883,6 @@ error:
884} 883}
885 884
886/** 885/**
887 * cap_syslog - Determine whether syslog function is permitted
888 * @type: Function requested
889 * @from_file: Whether this request came from an open file (i.e. /proc)
890 *
891 * Determine whether the current process is permitted to use a particular
892 * syslog function, returning 0 if permission is granted, -ve if not.
893 */
894int cap_syslog(int type, bool from_file)
895{
896 if (type != SYSLOG_ACTION_OPEN && from_file)
897 return 0;
898 if ((type != SYSLOG_ACTION_READ_ALL &&
899 type != SYSLOG_ACTION_SIZE_BUFFER) && !capable(CAP_SYS_ADMIN))
900 return -EPERM;
901 return 0;
902}
903
904/**
905 * cap_vm_enough_memory - Determine whether a new virtual mapping is permitted 886 * cap_vm_enough_memory - Determine whether a new virtual mapping is permitted
906 * @mm: The VM space in which the new mapping is to be made 887 * @mm: The VM space in which the new mapping is to be made
907 * @pages: The size of the mapping 888 * @pages: The size of the mapping
diff --git a/security/security.c b/security/security.c
index 3ef5e2a7a741..1b798d3df710 100644
--- a/security/security.c
+++ b/security/security.c
@@ -197,9 +197,9 @@ int security_quota_on(struct dentry *dentry)
197 return security_ops->quota_on(dentry); 197 return security_ops->quota_on(dentry);
198} 198}
199 199
200int security_syslog(int type, bool from_file) 200int security_syslog(int type)
201{ 201{
202 return security_ops->syslog(type, from_file); 202 return security_ops->syslog(type);
203} 203}
204 204
205int security_settime(struct timespec *ts, struct timezone *tz) 205int security_settime(struct timespec *ts, struct timezone *tz)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index d9154cf90ae1..65fa8bf596f5 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1973,14 +1973,10 @@ static int selinux_quota_on(struct dentry *dentry)
1973 return dentry_has_perm(cred, NULL, dentry, FILE__QUOTAON); 1973 return dentry_has_perm(cred, NULL, dentry, FILE__QUOTAON);
1974} 1974}
1975 1975
1976static int selinux_syslog(int type, bool from_file) 1976static int selinux_syslog(int type)
1977{ 1977{
1978 int rc; 1978 int rc;
1979 1979
1980 rc = cap_syslog(type, from_file);
1981 if (rc)
1982 return rc;
1983
1984 switch (type) { 1980 switch (type) {
1985 case SYSLOG_ACTION_READ_ALL: /* Read last kernel messages */ 1981 case SYSLOG_ACTION_READ_ALL: /* Read last kernel messages */
1986 case SYSLOG_ACTION_SIZE_BUFFER: /* Return size of the log buffer */ 1982 case SYSLOG_ACTION_SIZE_BUFFER: /* Return size of the log buffer */
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index bc39f4067af6..489a85afa477 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -157,15 +157,11 @@ static int smack_ptrace_traceme(struct task_struct *ptp)
157 * 157 *
158 * Returns 0 on success, error code otherwise. 158 * Returns 0 on success, error code otherwise.
159 */ 159 */
160static int smack_syslog(int type, bool from_file) 160static int smack_syslog(int typefrom_file)
161{ 161{
162 int rc; 162 int rc = 0;
163 char *sp = current_security(); 163 char *sp = current_security();
164 164
165 rc = cap_syslog(type, from_file);
166 if (rc != 0)
167 return rc;
168
169 if (capable(CAP_MAC_OVERRIDE)) 165 if (capable(CAP_MAC_OVERRIDE))
170 return 0; 166 return 0;
171 167
diff --git a/sound/atmel/abdac.c b/sound/atmel/abdac.c
index f2f41c854221..6e2409181895 100644
--- a/sound/atmel/abdac.c
+++ b/sound/atmel/abdac.c
@@ -420,9 +420,9 @@ static int __devinit atmel_abdac_probe(struct platform_device *pdev)
420 return PTR_ERR(pclk); 420 return PTR_ERR(pclk);
421 } 421 }
422 sample_clk = clk_get(&pdev->dev, "sample_clk"); 422 sample_clk = clk_get(&pdev->dev, "sample_clk");
423 if (IS_ERR(pclk)) { 423 if (IS_ERR(sample_clk)) {
424 dev_dbg(&pdev->dev, "no sample clock\n"); 424 dev_dbg(&pdev->dev, "no sample clock\n");
425 retval = PTR_ERR(pclk); 425 retval = PTR_ERR(sample_clk);
426 goto out_put_pclk; 426 goto out_put_pclk;
427 } 427 }
428 clk_enable(pclk); 428 clk_enable(pclk);
diff --git a/sound/core/info.c b/sound/core/info.c
index b70564ed8b37..7077f601da5a 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -23,7 +23,6 @@
23#include <linux/time.h> 23#include <linux/time.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/smp_lock.h>
27#include <linux/string.h> 26#include <linux/string.h>
28#include <sound/core.h> 27#include <sound/core.h>
29#include <sound/minors.h> 28#include <sound/minors.h>
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 5c8c7dff8ede..b753ec661fcf 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -1510,16 +1510,19 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
1510static int snd_pcm_oss_reset(struct snd_pcm_oss_file *pcm_oss_file) 1510static int snd_pcm_oss_reset(struct snd_pcm_oss_file *pcm_oss_file)
1511{ 1511{
1512 struct snd_pcm_substream *substream; 1512 struct snd_pcm_substream *substream;
1513 struct snd_pcm_runtime *runtime;
1514 int i;
1513 1515
1514 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK]; 1516 for (i = 0; i < 2; i++) {
1515 if (substream != NULL) { 1517 substream = pcm_oss_file->streams[i];
1516 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 1518 if (!substream)
1517 substream->runtime->oss.prepare = 1; 1519 continue;
1518 } 1520 runtime = substream->runtime;
1519 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
1520 if (substream != NULL) {
1521 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 1521 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
1522 substream->runtime->oss.prepare = 1; 1522 runtime->oss.prepare = 1;
1523 runtime->oss.buffer_used = 0;
1524 runtime->oss.prev_hw_ptr_period = 0;
1525 runtime->oss.period_ptr = 0;
1523 } 1526 }
1524 return 0; 1527 return 0;
1525} 1528}
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index a1707cca9c66..b75db8e9cc0f 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -223,7 +223,7 @@ static void xrun_log(struct snd_pcm_substream *substream,
223 entry->jiffies = jiffies; 223 entry->jiffies = jiffies;
224 entry->pos = pos; 224 entry->pos = pos;
225 entry->period_size = runtime->period_size; 225 entry->period_size = runtime->period_size;
226 entry->buffer_size = runtime->buffer_size;; 226 entry->buffer_size = runtime->buffer_size;
227 entry->old_hw_ptr = runtime->status->hw_ptr; 227 entry->old_hw_ptr = runtime->status->hw_ptr;
228 entry->hw_ptr_base = runtime->hw_ptr_base; 228 entry->hw_ptr_base = runtime->hw_ptr_base;
229 log->idx = (log->idx + 1) % XRUN_LOG_CNT; 229 log->idx = (log->idx + 1) % XRUN_LOG_CNT;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 8e022fc70f55..c0ebb5162e95 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -22,7 +22,6 @@
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/file.h> 23#include <linux/file.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/smp_lock.h>
26#include <linux/time.h> 25#include <linux/time.h>
27#include <linux/pm_qos_params.h> 26#include <linux/pm_qos_params.h>
28#include <linux/uio.h> 27#include <linux/uio.h>
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 62a093efb453..66691fe437e6 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -21,7 +21,6 @@
21 21
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/smp_lock.h>
25#include <linux/time.h> 24#include <linux/time.h>
26#include <linux/device.h> 25#include <linux/device.h>
27#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
diff --git a/sound/oss/dev_table.c b/sound/oss/dev_table.c
index 727bdb9ba2dc..d8cf3e58dc76 100644
--- a/sound/oss/dev_table.c
+++ b/sound/oss/dev_table.c
@@ -71,7 +71,7 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
71 if (sound_nblocks >= MAX_MEM_BLOCKS) 71 if (sound_nblocks >= MAX_MEM_BLOCKS)
72 sound_nblocks = MAX_MEM_BLOCKS - 1; 72 sound_nblocks = MAX_MEM_BLOCKS - 1;
73 73
74 op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_operations))); 74 op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vzalloc(sizeof(struct audio_operations)));
75 sound_nblocks++; 75 sound_nblocks++;
76 if (sound_nblocks >= MAX_MEM_BLOCKS) 76 if (sound_nblocks >= MAX_MEM_BLOCKS)
77 sound_nblocks = MAX_MEM_BLOCKS - 1; 77 sound_nblocks = MAX_MEM_BLOCKS - 1;
@@ -81,7 +81,6 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
81 sound_unload_audiodev(num); 81 sound_unload_audiodev(num);
82 return -(ENOMEM); 82 return -(ENOMEM);
83 } 83 }
84 memset((char *) op, 0, sizeof(struct audio_operations));
85 init_waitqueue_head(&op->in_sleeper); 84 init_waitqueue_head(&op->in_sleeper);
86 init_waitqueue_head(&op->out_sleeper); 85 init_waitqueue_head(&op->out_sleeper);
87 init_waitqueue_head(&op->poll_sleeper); 86 init_waitqueue_head(&op->poll_sleeper);
@@ -128,7 +127,7 @@ int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
128 /* FIXME: This leaks a mixer_operations struct every time its called 127 /* FIXME: This leaks a mixer_operations struct every time its called
129 until you unload sound! */ 128 until you unload sound! */
130 129
131 op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct mixer_operations))); 130 op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vzalloc(sizeof(struct mixer_operations)));
132 sound_nblocks++; 131 sound_nblocks++;
133 if (sound_nblocks >= MAX_MEM_BLOCKS) 132 if (sound_nblocks >= MAX_MEM_BLOCKS)
134 sound_nblocks = MAX_MEM_BLOCKS - 1; 133 sound_nblocks = MAX_MEM_BLOCKS - 1;
@@ -137,7 +136,6 @@ int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
137 printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name); 136 printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name);
138 return -ENOMEM; 137 return -ENOMEM;
139 } 138 }
140 memset((char *) op, 0, sizeof(struct mixer_operations));
141 memcpy((char *) op, (char *) driver, driver_size); 139 memcpy((char *) op, (char *) driver, driver_size);
142 140
143 strlcpy(op->name, name, sizeof(op->name)); 141 strlcpy(op->name, name, sizeof(op->name));
diff --git a/sound/oss/midibuf.c b/sound/oss/midibuf.c
index 782b3b84dac6..ceedb1eff203 100644
--- a/sound/oss/midibuf.c
+++ b/sound/oss/midibuf.c
@@ -178,7 +178,7 @@ int MIDIbuf_open(int dev, struct file *file)
178 return err; 178 return err;
179 179
180 parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT; 180 parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT;
181 midi_in_buf[dev] = (struct midi_buf *) vmalloc(sizeof(struct midi_buf)); 181 midi_in_buf[dev] = vmalloc(sizeof(struct midi_buf));
182 182
183 if (midi_in_buf[dev] == NULL) 183 if (midi_in_buf[dev] == NULL)
184 { 184 {
@@ -188,7 +188,7 @@ int MIDIbuf_open(int dev, struct file *file)
188 } 188 }
189 midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0; 189 midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0;
190 190
191 midi_out_buf[dev] = (struct midi_buf *) vmalloc(sizeof(struct midi_buf)); 191 midi_out_buf[dev] = vmalloc(sizeof(struct midi_buf));
192 192
193 if (midi_out_buf[dev] == NULL) 193 if (midi_out_buf[dev] == NULL)
194 { 194 {
diff --git a/sound/oss/pss.c b/sound/oss/pss.c
index e19dd5dcc2de..9b800ce5100e 100644
--- a/sound/oss/pss.c
+++ b/sound/oss/pss.c
@@ -859,7 +859,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg,
859 return 0; 859 return 0;
860 860
861 case SNDCTL_COPR_LOAD: 861 case SNDCTL_COPR_LOAD:
862 buf = (copr_buffer *) vmalloc(sizeof(copr_buffer)); 862 buf = vmalloc(sizeof(copr_buffer));
863 if (buf == NULL) 863 if (buf == NULL)
864 return -ENOSPC; 864 return -ENOSPC;
865 if (copy_from_user(buf, arg, sizeof(copr_buffer))) { 865 if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
@@ -871,7 +871,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg,
871 return err; 871 return err;
872 872
873 case SNDCTL_COPR_SENDMSG: 873 case SNDCTL_COPR_SENDMSG:
874 mbuf = (copr_msg *)vmalloc(sizeof(copr_msg)); 874 mbuf = vmalloc(sizeof(copr_msg));
875 if (mbuf == NULL) 875 if (mbuf == NULL)
876 return -ENOSPC; 876 return -ENOSPC;
877 if (copy_from_user(mbuf, arg, sizeof(copr_msg))) { 877 if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
@@ -895,7 +895,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg,
895 895
896 case SNDCTL_COPR_RCVMSG: 896 case SNDCTL_COPR_RCVMSG:
897 err = 0; 897 err = 0;
898 mbuf = (copr_msg *)vmalloc(sizeof(copr_msg)); 898 mbuf = vmalloc(sizeof(copr_msg));
899 if (mbuf == NULL) 899 if (mbuf == NULL)
900 return -ENOSPC; 900 return -ENOSPC;
901 data = (unsigned short *)mbuf->data; 901 data = (unsigned short *)mbuf->data;
diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c
index e85789e53816..5ea1098ac427 100644
--- a/sound/oss/sequencer.c
+++ b/sound/oss/sequencer.c
@@ -1646,13 +1646,13 @@ void sequencer_init(void)
1646{ 1646{
1647 if (sequencer_ok) 1647 if (sequencer_ok)
1648 return; 1648 return;
1649 queue = (unsigned char *)vmalloc(SEQ_MAX_QUEUE * EV_SZ); 1649 queue = vmalloc(SEQ_MAX_QUEUE * EV_SZ);
1650 if (queue == NULL) 1650 if (queue == NULL)
1651 { 1651 {
1652 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer output queue\n"); 1652 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer output queue\n");
1653 return; 1653 return;
1654 } 1654 }
1655 iqueue = (unsigned char *)vmalloc(SEQ_MAX_QUEUE * IEV_SZ); 1655 iqueue = vmalloc(SEQ_MAX_QUEUE * IEV_SZ);
1656 if (iqueue == NULL) 1656 if (iqueue == NULL)
1657 { 1657 {
1658 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer input queue\n"); 1658 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer input queue\n");
diff --git a/sound/pci/asihpi/hpi6000.c b/sound/pci/asihpi/hpi6000.c
index f7e374ec4414..1b9bf9395cfe 100644
--- a/sound/pci/asihpi/hpi6000.c
+++ b/sound/pci/asihpi/hpi6000.c
@@ -625,6 +625,8 @@ static short create_adapter_obj(struct hpi_adapter_obj *pao,
625 control_cache_size, (struct hpi_control_cache_info *) 625 control_cache_size, (struct hpi_control_cache_info *)
626 &phw->control_cache[0] 626 &phw->control_cache[0]
627 ); 627 );
628 if (!phw->p_cache)
629 pao->has_control_cache = 0;
628 } else 630 } else
629 pao->has_control_cache = 0; 631 pao->has_control_cache = 0;
630 632
diff --git a/sound/pci/asihpi/hpi6205.c b/sound/pci/asihpi/hpi6205.c
index 22c5fc625533..2672f6591ceb 100644
--- a/sound/pci/asihpi/hpi6205.c
+++ b/sound/pci/asihpi/hpi6205.c
@@ -644,6 +644,8 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
644 interface->control_cache.size_in_bytes, 644 interface->control_cache.size_in_bytes,
645 (struct hpi_control_cache_info *) 645 (struct hpi_control_cache_info *)
646 p_control_cache_virtual); 646 p_control_cache_virtual);
647 if (!phw->p_cache)
648 err = HPI_ERROR_MEMORY_ALLOC;
647 } 649 }
648 if (!err) { 650 if (!err) {
649 err = hpios_locked_mem_get_phys_addr(&phw-> 651 err = hpios_locked_mem_get_phys_addr(&phw->
diff --git a/sound/pci/asihpi/hpicmn.c b/sound/pci/asihpi/hpicmn.c
index dda4f1c6f658..d67f4d3db911 100644
--- a/sound/pci/asihpi/hpicmn.c
+++ b/sound/pci/asihpi/hpicmn.c
@@ -571,14 +571,20 @@ struct hpi_control_cache *hpi_alloc_control_cache(const u32
571{ 571{
572 struct hpi_control_cache *p_cache = 572 struct hpi_control_cache *p_cache =
573 kmalloc(sizeof(*p_cache), GFP_KERNEL); 573 kmalloc(sizeof(*p_cache), GFP_KERNEL);
574 if (!p_cache)
575 return NULL;
576 p_cache->p_info =
577 kmalloc(sizeof(*p_cache->p_info) * number_of_controls,
578 GFP_KERNEL);
579 if (!p_cache->p_info) {
580 kfree(p_cache);
581 return NULL;
582 }
574 p_cache->cache_size_in_bytes = size_in_bytes; 583 p_cache->cache_size_in_bytes = size_in_bytes;
575 p_cache->control_count = number_of_controls; 584 p_cache->control_count = number_of_controls;
576 p_cache->p_cache = 585 p_cache->p_cache =
577 (struct hpi_control_cache_single *)pDSP_control_buffer; 586 (struct hpi_control_cache_single *)pDSP_control_buffer;
578 p_cache->init = 0; 587 p_cache->init = 0;
579 p_cache->p_info =
580 kmalloc(sizeof(*p_cache->p_info) * p_cache->control_count,
581 GFP_KERNEL);
582 return p_cache; 588 return p_cache;
583} 589}
584 590
diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
index 62895a719fcb..22dbd91811a4 100644
--- a/sound/pci/asihpi/hpioctl.c
+++ b/sound/pci/asihpi/hpioctl.c
@@ -435,7 +435,7 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
435 struct hpi_message hm; 435 struct hpi_message hm;
436 struct hpi_response hr; 436 struct hpi_response hr;
437 struct hpi_adapter *pa; 437 struct hpi_adapter *pa;
438 pa = (struct hpi_adapter *)pci_get_drvdata(pci_dev); 438 pa = pci_get_drvdata(pci_dev);
439 439
440 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, 440 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
441 HPI_SUBSYS_DELETE_ADAPTER); 441 HPI_SUBSYS_DELETE_ADAPTER);
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 4679ed83a43b..2f3cacbd5528 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -1129,10 +1129,11 @@ snd_azf3328_codec_setdmaa(struct snd_azf3328 *chip,
1129 1129
1130 count_areas = size/2; 1130 count_areas = size/2;
1131 addr_area2 = addr+count_areas; 1131 addr_area2 = addr+count_areas;
1132 count_areas--; /* max. index */
1133 snd_azf3328_dbgcodec("setdma: buffers %08lx[%u] / %08lx[%u]\n", 1132 snd_azf3328_dbgcodec("setdma: buffers %08lx[%u] / %08lx[%u]\n",
1134 addr, count_areas, addr_area2, count_areas); 1133 addr, count_areas, addr_area2, count_areas);
1135 1134
1135 count_areas--; /* max. index */
1136
1136 /* build combined I/O buffer length word */ 1137 /* build combined I/O buffer length word */
1137 lengths = (count_areas << 16) | (count_areas); 1138 lengths = (count_areas << 16) | (count_areas);
1138 spin_lock_irqsave(&chip->reg_lock, flags); 1139 spin_lock_irqsave(&chip->reg_lock, flags);
@@ -1740,11 +1741,15 @@ static const struct snd_pcm_hardware snd_azf3328_hardware =
1740 .rate_max = AZF_FREQ_66200, 1741 .rate_max = AZF_FREQ_66200,
1741 .channels_min = 1, 1742 .channels_min = 1,
1742 .channels_max = 2, 1743 .channels_max = 2,
1743 .buffer_bytes_max = 65536, 1744 .buffer_bytes_max = (64*1024),
1744 .period_bytes_min = 64, 1745 .period_bytes_min = 1024,
1745 .period_bytes_max = 65536, 1746 .period_bytes_max = (32*1024),
1746 .periods_min = 1, 1747 /* We simply have two DMA areas (instead of a list of descriptors
1747 .periods_max = 1024, 1748 such as other cards); I believe that this is a fixed hardware
1749 attribute and there isn't much driver magic to be done to expand it.
1750 Thus indicate that we have at least and at most 2 periods. */
1751 .periods_min = 2,
1752 .periods_max = 2,
1748 /* FIXME: maybe that card actually has a FIFO? 1753 /* FIXME: maybe that card actually has a FIFO?
1749 * Hmm, it seems newer revisions do have one, but we still don't know 1754 * Hmm, it seems newer revisions do have one, but we still don't know
1750 * its size... */ 1755 * its size... */
@@ -1980,8 +1985,13 @@ snd_azf3328_timer_stop(struct snd_timer *timer)
1980 chip = snd_timer_chip(timer); 1985 chip = snd_timer_chip(timer);
1981 spin_lock_irqsave(&chip->reg_lock, flags); 1986 spin_lock_irqsave(&chip->reg_lock, flags);
1982 /* disable timer countdown and interrupt */ 1987 /* disable timer countdown and interrupt */
1983 /* FIXME: should we write TIMER_IRQ_ACK here? */ 1988 /* Hmm, should we write TIMER_IRQ_ACK here?
1984 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0); 1989 YES indeed, otherwise a rogue timer operation - which prompts
1990 ALSA(?) to call repeated stop() in vain, but NOT start() -
1991 will never end (value 0x03 is kept shown in control byte).
1992 Simply manually poking 0x04 _once_ immediately successfully stops
1993 the hardware/ALSA interrupt activity. */
1994 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x04);
1985 spin_unlock_irqrestore(&chip->reg_lock, flags); 1995 spin_unlock_irqrestore(&chip->reg_lock, flags);
1986 snd_azf3328_dbgcallleave(); 1996 snd_azf3328_dbgcallleave();
1987 return 0; 1997 return 0;
diff --git a/sound/pci/cs46xx/dsp_spos.c b/sound/pci/cs46xx/dsp_spos.c
index 3e5ca8fb519f..e377287192aa 100644
--- a/sound/pci/cs46xx/dsp_spos.c
+++ b/sound/pci/cs46xx/dsp_spos.c
@@ -225,39 +225,25 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
225{ 225{
226 struct dsp_spos_instance * ins = kzalloc(sizeof(struct dsp_spos_instance), GFP_KERNEL); 226 struct dsp_spos_instance * ins = kzalloc(sizeof(struct dsp_spos_instance), GFP_KERNEL);
227 227
228 if (ins == NULL) 228 if (ins == NULL)
229 return NULL; 229 return NULL;
230 230
231 /* better to use vmalloc for this big table */ 231 /* better to use vmalloc for this big table */
232 ins->symbol_table.nsymbols = 0;
233 ins->symbol_table.symbols = vmalloc(sizeof(struct dsp_symbol_entry) * 232 ins->symbol_table.symbols = vmalloc(sizeof(struct dsp_symbol_entry) *
234 DSP_MAX_SYMBOLS); 233 DSP_MAX_SYMBOLS);
235 ins->symbol_table.highest_frag_index = 0; 234 ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
236 235 ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL);
237 if (ins->symbol_table.symbols == NULL) { 236 if (!ins->symbol_table.symbols || !ins->code.data || !ins->modules) {
238 cs46xx_dsp_spos_destroy(chip); 237 cs46xx_dsp_spos_destroy(chip);
239 goto error; 238 goto error;
240 } 239 }
241 240 ins->symbol_table.nsymbols = 0;
241 ins->symbol_table.highest_frag_index = 0;
242 ins->code.offset = 0; 242 ins->code.offset = 0;
243 ins->code.size = 0; 243 ins->code.size = 0;
244 ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
245
246 if (ins->code.data == NULL) {
247 cs46xx_dsp_spos_destroy(chip);
248 goto error;
249 }
250
251 ins->nscb = 0; 244 ins->nscb = 0;
252 ins->ntask = 0; 245 ins->ntask = 0;
253
254 ins->nmodules = 0; 246 ins->nmodules = 0;
255 ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL);
256
257 if (ins->modules == NULL) {
258 cs46xx_dsp_spos_destroy(chip);
259 goto error;
260 }
261 247
262 /* default SPDIF input sample rate 248 /* default SPDIF input sample rate
263 to 48000 khz */ 249 to 48000 khz */
@@ -271,8 +257,8 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
271 257
272 /* set left and right validity bits and 258 /* set left and right validity bits and
273 default channel status */ 259 default channel status */
274 ins->spdif_csuv_default = 260 ins->spdif_csuv_default =
275 ins->spdif_csuv_stream = 261 ins->spdif_csuv_stream =
276 /* byte 0 */ ((unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF & 0xff)) << 24) | 262 /* byte 0 */ ((unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF & 0xff)) << 24) |
277 /* byte 1 */ ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff)) << 16) | 263 /* byte 1 */ ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff)) << 16) |
278 /* byte 3 */ (unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) | 264 /* byte 3 */ (unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) |
@@ -281,6 +267,9 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
281 return ins; 267 return ins;
282 268
283error: 269error:
270 kfree(ins->modules);
271 kfree(ins->code.data);
272 vfree(ins->symbol_table.symbols);
284 kfree(ins); 273 kfree(ins);
285 return NULL; 274 return NULL;
286} 275}
diff --git a/sound/pci/ctxfi/ctpcm.c b/sound/pci/ctxfi/ctpcm.c
index 85ab43e89212..457d21189b0d 100644
--- a/sound/pci/ctxfi/ctpcm.c
+++ b/sound/pci/ctxfi/ctpcm.c
@@ -129,8 +129,6 @@ static int ct_pcm_playback_open(struct snd_pcm_substream *substream)
129 129
130 apcm->substream = substream; 130 apcm->substream = substream;
131 apcm->interrupt = ct_atc_pcm_interrupt; 131 apcm->interrupt = ct_atc_pcm_interrupt;
132 runtime->private_data = apcm;
133 runtime->private_free = ct_atc_pcm_free_substream;
134 if (IEC958 == substream->pcm->device) { 132 if (IEC958 == substream->pcm->device) {
135 runtime->hw = ct_spdif_passthru_playback_hw; 133 runtime->hw = ct_spdif_passthru_playback_hw;
136 atc->spdif_out_passthru(atc, 1); 134 atc->spdif_out_passthru(atc, 1);
@@ -155,8 +153,12 @@ static int ct_pcm_playback_open(struct snd_pcm_substream *substream)
155 } 153 }
156 154
157 apcm->timer = ct_timer_instance_new(atc->timer, apcm); 155 apcm->timer = ct_timer_instance_new(atc->timer, apcm);
158 if (!apcm->timer) 156 if (!apcm->timer) {
157 kfree(apcm);
159 return -ENOMEM; 158 return -ENOMEM;
159 }
160 runtime->private_data = apcm;
161 runtime->private_free = ct_atc_pcm_free_substream;
160 162
161 return 0; 163 return 0;
162} 164}
@@ -278,8 +280,6 @@ static int ct_pcm_capture_open(struct snd_pcm_substream *substream)
278 apcm->started = 0; 280 apcm->started = 0;
279 apcm->substream = substream; 281 apcm->substream = substream;
280 apcm->interrupt = ct_atc_pcm_interrupt; 282 apcm->interrupt = ct_atc_pcm_interrupt;
281 runtime->private_data = apcm;
282 runtime->private_free = ct_atc_pcm_free_substream;
283 runtime->hw = ct_pcm_capture_hw; 283 runtime->hw = ct_pcm_capture_hw;
284 runtime->hw.rate_max = atc->rsr * atc->msr; 284 runtime->hw.rate_max = atc->rsr * atc->msr;
285 285
@@ -298,8 +298,12 @@ static int ct_pcm_capture_open(struct snd_pcm_substream *substream)
298 } 298 }
299 299
300 apcm->timer = ct_timer_instance_new(atc->timer, apcm); 300 apcm->timer = ct_timer_instance_new(atc->timer, apcm);
301 if (!apcm->timer) 301 if (!apcm->timer) {
302 kfree(apcm);
302 return -ENOMEM; 303 return -ENOMEM;
304 }
305 runtime->private_data = apcm;
306 runtime->private_free = ct_atc_pcm_free_substream;
303 307
304 return 0; 308 return 0;
305} 309}
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index cb0c23a6b473..4a663471dadc 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -189,6 +189,9 @@ static void hdmi_update_short_audio_desc(struct cea_sad *a,
189 a->channels = GRAB_BITS(buf, 0, 0, 3); 189 a->channels = GRAB_BITS(buf, 0, 0, 3);
190 a->channels++; 190 a->channels++;
191 191
192 a->sample_bits = 0;
193 a->max_bitrate = 0;
194
192 a->format = GRAB_BITS(buf, 0, 3, 4); 195 a->format = GRAB_BITS(buf, 0, 3, 4);
193 switch (a->format) { 196 switch (a->format) {
194 case AUDIO_CODING_TYPE_REF_STREAM_HEADER: 197 case AUDIO_CODING_TYPE_REF_STREAM_HEADER:
@@ -198,7 +201,6 @@ static void hdmi_update_short_audio_desc(struct cea_sad *a,
198 201
199 case AUDIO_CODING_TYPE_LPCM: 202 case AUDIO_CODING_TYPE_LPCM:
200 val = GRAB_BITS(buf, 2, 0, 3); 203 val = GRAB_BITS(buf, 2, 0, 3);
201 a->sample_bits = 0;
202 for (i = 0; i < 3; i++) 204 for (i = 0; i < 3; i++)
203 if (val & (1 << i)) 205 if (val & (1 << i))
204 a->sample_bits |= cea_sample_sizes[i + 1]; 206 a->sample_bits |= cea_sample_sizes[i + 1];
@@ -598,24 +600,19 @@ void hdmi_eld_update_pcm_info(struct hdmi_eld *eld, struct hda_pcm_stream *pcm,
598{ 600{
599 int i; 601 int i;
600 602
601 pcm->rates = 0; 603 /* assume basic audio support (the basic audio flag is not in ELD;
602 pcm->formats = 0; 604 * however, all audio capable sinks are required to support basic
603 pcm->maxbps = 0; 605 * audio) */
604 pcm->channels_min = -1; 606 pcm->rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
605 pcm->channels_max = 0; 607 pcm->formats = SNDRV_PCM_FMTBIT_S16_LE;
608 pcm->maxbps = 16;
609 pcm->channels_max = 2;
606 for (i = 0; i < eld->sad_count; i++) { 610 for (i = 0; i < eld->sad_count; i++) {
607 struct cea_sad *a = &eld->sad[i]; 611 struct cea_sad *a = &eld->sad[i];
608 pcm->rates |= a->rates; 612 pcm->rates |= a->rates;
609 if (a->channels < pcm->channels_min)
610 pcm->channels_min = a->channels;
611 if (a->channels > pcm->channels_max) 613 if (a->channels > pcm->channels_max)
612 pcm->channels_max = a->channels; 614 pcm->channels_max = a->channels;
613 if (a->format == AUDIO_CODING_TYPE_LPCM) { 615 if (a->format == AUDIO_CODING_TYPE_LPCM) {
614 if (a->sample_bits & AC_SUPPCM_BITS_16) {
615 pcm->formats |= SNDRV_PCM_FMTBIT_S16_LE;
616 if (pcm->maxbps < 16)
617 pcm->maxbps = 16;
618 }
619 if (a->sample_bits & AC_SUPPCM_BITS_20) { 616 if (a->sample_bits & AC_SUPPCM_BITS_20) {
620 pcm->formats |= SNDRV_PCM_FMTBIT_S32_LE; 617 pcm->formats |= SNDRV_PCM_FMTBIT_S32_LE;
621 if (pcm->maxbps < 20) 618 if (pcm->maxbps < 20)
@@ -635,7 +632,6 @@ void hdmi_eld_update_pcm_info(struct hdmi_eld *eld, struct hda_pcm_stream *pcm,
635 /* restrict the parameters by the values the codec provides */ 632 /* restrict the parameters by the values the codec provides */
636 pcm->rates &= codec_pars->rates; 633 pcm->rates &= codec_pars->rates;
637 pcm->formats &= codec_pars->formats; 634 pcm->formats &= codec_pars->formats;
638 pcm->channels_min = max(pcm->channels_min, codec_pars->channels_min);
639 pcm->channels_max = min(pcm->channels_max, codec_pars->channels_max); 635 pcm->channels_max = min(pcm->channels_max, codec_pars->channels_max);
640 pcm->maxbps = min(pcm->maxbps, codec_pars->maxbps); 636 pcm->maxbps = min(pcm->maxbps, codec_pars->maxbps);
641} 637}
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 21aa9b0e28f6..b030c8eba21f 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -2296,6 +2296,7 @@ static int azx_dev_free(struct snd_device *device)
2296 */ 2296 */
2297static struct snd_pci_quirk position_fix_list[] __devinitdata = { 2297static struct snd_pci_quirk position_fix_list[] __devinitdata = {
2298 SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB), 2298 SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB),
2299 SND_PCI_QUIRK(0x1025, 0x026f, "Acer Aspire 5538", POS_FIX_LPIB),
2299 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB), 2300 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
2300 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB), 2301 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
2301 SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB), 2302 SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB),
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 460fb2ef7e39..18af38ebf757 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -1166,6 +1166,7 @@ static const char *cs420x_models[CS420X_MODELS] = {
1166 1166
1167static struct snd_pci_quirk cs420x_cfg_tbl[] = { 1167static struct snd_pci_quirk cs420x_cfg_tbl[] = {
1168 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53), 1168 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53),
1169 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55),
1169 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55), 1170 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
1170 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55), 1171 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55),
1171 SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27), 1172 SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 6361f752b5f3..76bd58a0e2b6 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -2116,8 +2116,8 @@ static void cxt5066_update_speaker(struct hda_codec *codec)
2116 struct conexant_spec *spec = codec->spec; 2116 struct conexant_spec *spec = codec->spec;
2117 unsigned int pinctl; 2117 unsigned int pinctl;
2118 2118
2119 snd_printdd("CXT5066: update speaker, hp_present=%d\n", 2119 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2120 spec->hp_present); 2120 spec->hp_present, spec->cur_eapd);
2121 2121
2122 /* Port A (HP) */ 2122 /* Port A (HP) */
2123 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0; 2123 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
@@ -2125,11 +2125,20 @@ static void cxt5066_update_speaker(struct hda_codec *codec)
2125 pinctl); 2125 pinctl);
2126 2126
2127 /* Port D (HP/LO) */ 2127 /* Port D (HP/LO) */
2128 pinctl = ((spec->hp_present & 2) && spec->cur_eapd) 2128 if (spec->dell_automute) {
2129 ? spec->port_d_mode : 0; 2129 /* DELL AIO Port Rule: PortA> PortD> IntSpk */
2130 /* Mute if Port A is connected on Thinkpad */ 2130 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2131 if (spec->thinkpad && (spec->hp_present & 1)) 2131 ? PIN_OUT : 0;
2132 pinctl = 0; 2132 } else if (spec->thinkpad) {
2133 if (spec->cur_eapd)
2134 pinctl = spec->port_d_mode;
2135 /* Mute dock line-out if Port A (laptop HP) is present */
2136 if (spec->hp_present& 1)
2137 pinctl = 0;
2138 } else {
2139 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2140 ? spec->port_d_mode : 0;
2141 }
2133 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2142 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2134 pinctl); 2143 pinctl);
2135 2144
@@ -2137,14 +2146,6 @@ static void cxt5066_update_speaker(struct hda_codec *codec)
2137 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 2146 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2138 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2147 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2139 pinctl); 2148 pinctl);
2140
2141 if (spec->dell_automute) {
2142 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
2143 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2144 ? PIN_OUT : 0;
2145 snd_hda_codec_write(codec, 0x1c, 0,
2146 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
2147 }
2148} 2149}
2149 2150
2150/* turn on/off EAPD (+ mute HP) as a master switch */ 2151/* turn on/off EAPD (+ mute HP) as a master switch */
@@ -3095,11 +3096,11 @@ static const char *cxt5066_models[CXT5066_MODELS] = {
3095static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 3096static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3096 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 3097 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
3097 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 3098 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
3098 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 3099 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3099 CXT5066_DELL_LAPTOP),
3100 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3100 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3101 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3101 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3102 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3102 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3103 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_HP_LAPTOP),
3103 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3104 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3104 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 3105 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
3105 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5), 3106 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
@@ -3108,8 +3109,10 @@ static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3108 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 3109 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3109 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3110 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3110 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD), 3111 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
3112 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
3111 SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD), 3113 SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
3112 SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD), 3114 SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
3115 SND_PCI_QUIRK(0x17aa, 0x21c8, "Thinkpad Edge 11", CXT5066_IDEAPAD),
3113 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 3116 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3114 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD), 3117 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD),
3115 SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD), 3118 SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD),
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index d3e49aa5b9ec..31df7747990d 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -834,7 +834,6 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
834 return -ENODEV; 834 return -ENODEV;
835 } else { 835 } else {
836 /* fallback to the codec default */ 836 /* fallback to the codec default */
837 hinfo->channels_min = codec_pars->channels_min;
838 hinfo->channels_max = codec_pars->channels_max; 837 hinfo->channels_max = codec_pars->channels_max;
839 hinfo->rates = codec_pars->rates; 838 hinfo->rates = codec_pars->rates;
840 hinfo->formats = codec_pars->formats; 839 hinfo->formats = codec_pars->formats;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 5f00589cb791..427da45d7906 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -1614,6 +1614,7 @@ do_sku:
1614 spec->init_amp = ALC_INIT_GPIO3; 1614 spec->init_amp = ALC_INIT_GPIO3;
1615 break; 1615 break;
1616 case 5: 1616 case 5:
1617 default:
1617 spec->init_amp = ALC_INIT_DEFAULT; 1618 spec->init_amp = ALC_INIT_DEFAULT;
1618 break; 1619 break;
1619 } 1620 }
@@ -2014,6 +2015,36 @@ static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
2014}; 2015};
2015 2016
2016/* 2017/*
2018 *ALC888 Acer Aspire 7730G model
2019 */
2020
2021static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
2022/* Bias voltage on for external mic port */
2023 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2024/* Front Mic: set to PIN_IN (empty by default) */
2025 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2026/* Unselect Front Mic by default in input mixer 3 */
2027 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2028/* Enable unsolicited event for HP jack */
2029 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2030/* Enable speaker output */
2031 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2032 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2033 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2034/* Enable headphone output */
2035 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2036 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2037 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2038 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2039/*Enable internal subwoofer */
2040 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2041 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2042 {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
2043 {0x17, AC_VERB_SET_EAPD_BTLENABLE, 2},
2044 { }
2045};
2046
2047/*
2017 * ALC889 Acer Aspire 8930G model 2048 * ALC889 Acer Aspire 8930G model
2018 */ 2049 */
2019 2050
@@ -2200,6 +2231,16 @@ static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
2200 spec->autocfg.speaker_pins[2] = 0x17; 2231 spec->autocfg.speaker_pins[2] = 0x17;
2201} 2232}
2202 2233
2234static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
2235{
2236 struct alc_spec *spec = codec->spec;
2237
2238 spec->autocfg.hp_pins[0] = 0x15;
2239 spec->autocfg.speaker_pins[0] = 0x14;
2240 spec->autocfg.speaker_pins[1] = 0x16;
2241 spec->autocfg.speaker_pins[2] = 0x17;
2242}
2243
2203static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec) 2244static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
2204{ 2245{
2205 struct alc_spec *spec = codec->spec; 2246 struct alc_spec *spec = codec->spec;
@@ -4554,6 +4595,7 @@ static struct snd_pci_quirk alc880_cfg_tbl[] = {
4554 SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU), 4595 SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
4555 SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW), 4596 SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
4556 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG), 4597 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
4598 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_LG),
4557 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG), 4599 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
4558 SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW), 4600 SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
4559 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700), 4601 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
@@ -9524,13 +9566,6 @@ static struct hda_verb alc883_acer_eapd_verbs[] = {
9524 { } 9566 { }
9525}; 9567};
9526 9568
9527static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
9528 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9529 {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
9530 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9531 { } /* end */
9532};
9533
9534static void alc888_6st_dell_setup(struct hda_codec *codec) 9569static void alc888_6st_dell_setup(struct hda_codec *codec)
9535{ 9570{
9536 struct alc_spec *spec = codec->spec; 9571 struct alc_spec *spec = codec->spec;
@@ -9831,7 +9866,6 @@ static struct snd_pci_quirk alc882_cfg_tbl[] = {
9831 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763), 9866 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9832 SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763), 9867 SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9833 SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY), 9868 SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
9834 SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
9835 SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG), 9869 SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
9836 SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG), 9870 SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
9837 SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66), 9871 SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
@@ -10328,7 +10362,7 @@ static struct alc_config_preset alc882_presets[] = {
10328 .const_channel_count = 6, 10362 .const_channel_count = 6,
10329 .input_mux = &alc883_capture_source, 10363 .input_mux = &alc883_capture_source,
10330 .unsol_event = alc_automute_amp_unsol_event, 10364 .unsol_event = alc_automute_amp_unsol_event,
10331 .setup = alc888_acer_aspire_6530g_setup, 10365 .setup = alc888_acer_aspire_7730g_setup,
10332 .init_hook = alc_automute_amp, 10366 .init_hook = alc_automute_amp,
10333 }, 10367 },
10334 [ALC883_MEDION] = { 10368 [ALC883_MEDION] = {
@@ -10796,7 +10830,8 @@ static int alc_auto_add_mic_boost(struct hda_codec *codec)
10796{ 10830{
10797 struct alc_spec *spec = codec->spec; 10831 struct alc_spec *spec = codec->spec;
10798 struct auto_pin_cfg *cfg = &spec->autocfg; 10832 struct auto_pin_cfg *cfg = &spec->autocfg;
10799 int i, err; 10833 int i, err, type;
10834 int type_idx = 0;
10800 hda_nid_t nid; 10835 hda_nid_t nid;
10801 10836
10802 for (i = 0; i < cfg->num_inputs; i++) { 10837 for (i = 0; i < cfg->num_inputs; i++) {
@@ -10805,9 +10840,15 @@ static int alc_auto_add_mic_boost(struct hda_codec *codec)
10805 nid = cfg->inputs[i].pin; 10840 nid = cfg->inputs[i].pin;
10806 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { 10841 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
10807 char label[32]; 10842 char label[32];
10843 type = cfg->inputs[i].type;
10844 if (i > 0 && type == cfg->inputs[i - 1].type)
10845 type_idx++;
10846 else
10847 type_idx = 0;
10808 snprintf(label, sizeof(label), "%s Boost", 10848 snprintf(label, sizeof(label), "%s Boost",
10809 hda_get_autocfg_input_label(codec, cfg, i)); 10849 hda_get_autocfg_input_label(codec, cfg, i));
10810 err = add_control(spec, ALC_CTL_WIDGET_VOL, label, 0, 10850 err = add_control(spec, ALC_CTL_WIDGET_VOL, label,
10851 type_idx,
10811 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); 10852 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10812 if (err < 0) 10853 if (err < 0)
10813 return err; 10854 return err;
@@ -14623,7 +14664,10 @@ static int alc275_setup_dual_adc(struct hda_codec *codec)
14623/* different alc269-variants */ 14664/* different alc269-variants */
14624enum { 14665enum {
14625 ALC269_TYPE_NORMAL, 14666 ALC269_TYPE_NORMAL,
14667 ALC269_TYPE_ALC258,
14626 ALC269_TYPE_ALC259, 14668 ALC269_TYPE_ALC259,
14669 ALC269_TYPE_ALC269VB,
14670 ALC269_TYPE_ALC270,
14627 ALC269_TYPE_ALC271X, 14671 ALC269_TYPE_ALC271X,
14628}; 14672};
14629 14673
@@ -14763,6 +14807,8 @@ static int alc269_resume(struct hda_codec *codec)
14763enum { 14807enum {
14764 ALC269_FIXUP_SONY_VAIO, 14808 ALC269_FIXUP_SONY_VAIO,
14765 ALC269_FIXUP_DELL_M101Z, 14809 ALC269_FIXUP_DELL_M101Z,
14810 ALC269_FIXUP_LENOVO_EDGE14,
14811 ALC269_FIXUP_ASUS_G73JW,
14766}; 14812};
14767 14813
14768static const struct alc_fixup alc269_fixups[] = { 14814static const struct alc_fixup alc269_fixups[] = {
@@ -14780,11 +14826,22 @@ static const struct alc_fixup alc269_fixups[] = {
14780 {} 14826 {}
14781 } 14827 }
14782 }, 14828 },
14829 [ALC269_FIXUP_LENOVO_EDGE14] = {
14830 .sku = ALC_FIXUP_SKU_IGNORE,
14831 },
14832 [ALC269_FIXUP_ASUS_G73JW] = {
14833 .pins = (const struct alc_pincfg[]) {
14834 { 0x17, 0x99130111 }, /* subwoofer */
14835 { }
14836 }
14837 },
14783}; 14838};
14784 14839
14785static struct snd_pci_quirk alc269_fixup_tbl[] = { 14840static struct snd_pci_quirk alc269_fixup_tbl[] = {
14786 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), 14841 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
14787 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), 14842 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
14843 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_LENOVO_EDGE14),
14844 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
14788 {} 14845 {}
14789}; 14846};
14790 14847
@@ -15023,7 +15080,7 @@ static int alc269_fill_coef(struct hda_codec *codec)
15023static int patch_alc269(struct hda_codec *codec) 15080static int patch_alc269(struct hda_codec *codec)
15024{ 15081{
15025 struct alc_spec *spec; 15082 struct alc_spec *spec;
15026 int board_config; 15083 int board_config, coef;
15027 int err; 15084 int err;
15028 15085
15029 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 15086 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -15034,14 +15091,23 @@ static int patch_alc269(struct hda_codec *codec)
15034 15091
15035 alc_auto_parse_customize_define(codec); 15092 alc_auto_parse_customize_define(codec);
15036 15093
15037 if ((alc_read_coef_idx(codec, 0) & 0x00f0) == 0x0010){ 15094 coef = alc_read_coef_idx(codec, 0);
15095 if ((coef & 0x00f0) == 0x0010) {
15038 if (codec->bus->pci->subsystem_vendor == 0x1025 && 15096 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
15039 spec->cdefine.platform_type == 1) { 15097 spec->cdefine.platform_type == 1) {
15040 alc_codec_rename(codec, "ALC271X"); 15098 alc_codec_rename(codec, "ALC271X");
15041 spec->codec_variant = ALC269_TYPE_ALC271X; 15099 spec->codec_variant = ALC269_TYPE_ALC271X;
15042 } else { 15100 } else if ((coef & 0xf000) == 0x1000) {
15101 spec->codec_variant = ALC269_TYPE_ALC270;
15102 } else if ((coef & 0xf000) == 0x2000) {
15043 alc_codec_rename(codec, "ALC259"); 15103 alc_codec_rename(codec, "ALC259");
15044 spec->codec_variant = ALC269_TYPE_ALC259; 15104 spec->codec_variant = ALC269_TYPE_ALC259;
15105 } else if ((coef & 0xf000) == 0x3000) {
15106 alc_codec_rename(codec, "ALC258");
15107 spec->codec_variant = ALC269_TYPE_ALC258;
15108 } else {
15109 alc_codec_rename(codec, "ALC269VB");
15110 spec->codec_variant = ALC269_TYPE_ALC269VB;
15045 } 15111 }
15046 } else 15112 } else
15047 alc_fix_pll_init(codec, 0x20, 0x04, 15); 15113 alc_fix_pll_init(codec, 0x20, 0x04, 15);
@@ -15104,7 +15170,7 @@ static int patch_alc269(struct hda_codec *codec)
15104 spec->stream_digital_capture = &alc269_pcm_digital_capture; 15170 spec->stream_digital_capture = &alc269_pcm_digital_capture;
15105 15171
15106 if (!spec->adc_nids) { /* wasn't filled automatically? use default */ 15172 if (!spec->adc_nids) { /* wasn't filled automatically? use default */
15107 if (spec->codec_variant != ALC269_TYPE_NORMAL) { 15173 if (spec->codec_variant == ALC269_TYPE_NORMAL) {
15108 spec->adc_nids = alc269_adc_nids; 15174 spec->adc_nids = alc269_adc_nids;
15109 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids); 15175 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
15110 spec->capsrc_nids = alc269_capsrc_nids; 15176 spec->capsrc_nids = alc269_capsrc_nids;
@@ -16898,7 +16964,7 @@ static struct alc_config_preset alc861vd_presets[] = {
16898static int alc861vd_auto_create_input_ctls(struct hda_codec *codec, 16964static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
16899 const struct auto_pin_cfg *cfg) 16965 const struct auto_pin_cfg *cfg)
16900{ 16966{
16901 return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0); 16967 return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x22, 0);
16902} 16968}
16903 16969
16904 16970
@@ -18952,6 +19018,8 @@ static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
18952 return 0x02; 19018 return 0x02;
18953 else if (nid >= 0x0c && nid <= 0x0e) 19019 else if (nid >= 0x0c && nid <= 0x0e)
18954 return nid - 0x0c + 0x02; 19020 return nid - 0x0c + 0x02;
19021 else if (nid == 0x26) /* ALC887-VD has this DAC too */
19022 return 0x25;
18955 else 19023 else
18956 return 0; 19024 return 0;
18957} 19025}
@@ -18960,7 +19028,7 @@ static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
18960static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin, 19028static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
18961 hda_nid_t dac) 19029 hda_nid_t dac)
18962{ 19030{
18963 hda_nid_t mix[4]; 19031 hda_nid_t mix[5];
18964 int i, num; 19032 int i, num;
18965 19033
18966 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); 19034 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
@@ -19298,6 +19366,7 @@ static const struct alc_fixup alc662_fixups[] = {
19298 19366
19299static struct snd_pci_quirk alc662_fixup_tbl[] = { 19367static struct snd_pci_quirk alc662_fixup_tbl[] = {
19300 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), 19368 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
19369 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
19301 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), 19370 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
19302 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), 19371 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
19303 {} 19372 {}
@@ -19419,7 +19488,10 @@ static int patch_alc888(struct hda_codec *codec)
19419{ 19488{
19420 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){ 19489 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
19421 kfree(codec->chip_name); 19490 kfree(codec->chip_name);
19422 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL); 19491 if (codec->vendor_id == 0x10ec0887)
19492 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
19493 else
19494 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
19423 if (!codec->chip_name) { 19495 if (!codec->chip_name) {
19424 alc_free(codec); 19496 alc_free(codec);
19425 return -ENOMEM; 19497 return -ENOMEM;
@@ -19909,7 +19981,7 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
19909 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", 19981 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
19910 .patch = patch_alc882 }, 19982 .patch = patch_alc882 },
19911 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, 19983 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
19912 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, 19984 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
19913 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", 19985 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
19914 .patch = patch_alc882 }, 19986 .patch = patch_alc882 },
19915 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 }, 19987 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 93fa59cc60ef..efa4225f5fd6 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -389,6 +389,11 @@ static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
389 0x11, 0x20, 0 389 0x11, 0x20, 0
390}; 390};
391 391
392#define STAC92HD87B_NUM_DMICS 1
393static hda_nid_t stac92hd87b_dmic_nids[STAC92HD87B_NUM_DMICS + 1] = {
394 0x11, 0
395};
396
392#define STAC92HD83XXX_NUM_CAPS 2 397#define STAC92HD83XXX_NUM_CAPS 2
393static unsigned long stac92hd83xxx_capvols[] = { 398static unsigned long stac92hd83xxx_capvols[] = {
394 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT), 399 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
@@ -1622,6 +1627,8 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1622static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = { 1627static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1, 1628 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1624 "Alienware M17x", STAC_ALIENWARE_M17X), 1629 "Alienware M17x", STAC_ALIENWARE_M17X),
1630 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1631 "Alienware M17x", STAC_ALIENWARE_M17X),
1625 {} /* terminator */ 1632 {} /* terminator */
1626}; 1633};
1627 1634
@@ -3486,10 +3493,8 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3486 return err; 3493 return err;
3487 } 3494 }
3488 3495
3489 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) { 3496 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3490 snd_hda_add_imux_item(imux, label, index, NULL); 3497 snd_hda_add_imux_item(imux, label, index, NULL);
3491 spec->num_analog_muxes++;
3492 }
3493 } 3498 }
3494 3499
3495 return 0; 3500 return 0;
@@ -5452,12 +5457,17 @@ again:
5452 stac92hd83xxx_brd_tbl[spec->board_config]); 5457 stac92hd83xxx_brd_tbl[spec->board_config]);
5453 5458
5454 switch (codec->vendor_id) { 5459 switch (codec->vendor_id) {
5460 case 0x111d76d1:
5461 case 0x111d76d9:
5462 spec->dmic_nids = stac92hd87b_dmic_nids;
5463 spec->num_dmics = stac92xx_connected_ports(codec,
5464 stac92hd87b_dmic_nids,
5465 STAC92HD87B_NUM_DMICS);
5466 /* Fall through */
5455 case 0x111d7666: 5467 case 0x111d7666:
5456 case 0x111d7667: 5468 case 0x111d7667:
5457 case 0x111d7668: 5469 case 0x111d7668:
5458 case 0x111d7669: 5470 case 0x111d7669:
5459 case 0x111d76d1:
5460 case 0x111d76d9:
5461 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids); 5471 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5462 spec->pin_nids = stac92hd88xxx_pin_nids; 5472 spec->pin_nids = stac92hd88xxx_pin_nids;
5463 spec->mono_nid = 0; 5473 spec->mono_nid = 0;
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 400f9ebd243e..629a5494347a 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -1866,6 +1866,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1866 }, 1866 },
1867 { 1867 {
1868 .subvendor = 0x1028, 1868 .subvendor = 0x1028,
1869 .subdevice = 0x0182,
1870 .name = "Dell Latitude D610", /* STAC9750/51 */
1871 .type = AC97_TUNE_HP_ONLY
1872 },
1873 {
1874 .subvendor = 0x1028,
1869 .subdevice = 0x0186, 1875 .subdevice = 0x0186,
1870 .name = "Dell Latitude D810", /* cf. Malone #41015 */ 1876 .name = "Dell Latitude D810", /* cf. Malone #41015 */
1871 .type = AC97_TUNE_HP_MUTE_LED 1877 .type = AC97_TUNE_HP_MUTE_LED
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c
index ef9af3f4ace2..1bd7a540fd49 100644
--- a/sound/pci/lx6464es/lx6464es.c
+++ b/sound/pci/lx6464es/lx6464es.c
@@ -425,7 +425,7 @@ exit:
425static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream) 425static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
426{ 426{
427 struct snd_pcm_substream *substream = lx_stream->stream; 427 struct snd_pcm_substream *substream = lx_stream->stream;
428 const int is_capture = lx_stream->is_capture; 428 const unsigned int is_capture = lx_stream->is_capture;
429 429
430 int err; 430 int err;
431 431
@@ -473,7 +473,7 @@ static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
473 473
474static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream) 474static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream)
475{ 475{
476 const int is_capture = lx_stream->is_capture; 476 const unsigned int is_capture = lx_stream->is_capture;
477 int err; 477 int err;
478 478
479 snd_printd(LXP "stopping: stopping stream\n"); 479 snd_printd(LXP "stopping: stopping stream\n");
diff --git a/sound/pci/lx6464es/lx6464es.h b/sound/pci/lx6464es/lx6464es.h
index 51afc048961d..aea621eafbb5 100644
--- a/sound/pci/lx6464es/lx6464es.h
+++ b/sound/pci/lx6464es/lx6464es.h
@@ -60,7 +60,7 @@ struct lx_stream {
60 snd_pcm_uframes_t frame_pos; 60 snd_pcm_uframes_t frame_pos;
61 enum lx_stream_status status; /* free, open, running, draining 61 enum lx_stream_status status; /* free, open, running, draining
62 * pause */ 62 * pause */
63 int is_capture:1; 63 unsigned int is_capture:1;
64}; 64};
65 65
66 66
diff --git a/sound/pci/lx6464es/lx_core.c b/sound/pci/lx6464es/lx_core.c
index 3086b751da4a..617f98b0cbae 100644
--- a/sound/pci/lx6464es/lx_core.c
+++ b/sound/pci/lx6464es/lx_core.c
@@ -1152,7 +1152,7 @@ static int lx_interrupt_request_new_buffer(struct lx6464es *chip,
1152 struct lx_stream *lx_stream) 1152 struct lx_stream *lx_stream)
1153{ 1153{
1154 struct snd_pcm_substream *substream = lx_stream->stream; 1154 struct snd_pcm_substream *substream = lx_stream->stream;
1155 int is_capture = lx_stream->is_capture; 1155 const unsigned int is_capture = lx_stream->is_capture;
1156 int err; 1156 int err;
1157 unsigned long flags; 1157 unsigned long flags;
1158 1158
diff --git a/sound/pci/mixart/mixart_hwdep.h b/sound/pci/mixart/mixart_hwdep.h
index a46f5083db99..812e288ef2e7 100644
--- a/sound/pci/mixart/mixart_hwdep.h
+++ b/sound/pci/mixart/mixart_hwdep.h
@@ -25,11 +25,21 @@
25 25
26#include <sound/hwdep.h> 26#include <sound/hwdep.h>
27 27
28#ifndef readl_be
28#define readl_be(x) be32_to_cpu(__raw_readl(x)) 29#define readl_be(x) be32_to_cpu(__raw_readl(x))
30#endif
31
32#ifndef writel_be
29#define writel_be(data,addr) __raw_writel(cpu_to_be32(data),addr) 33#define writel_be(data,addr) __raw_writel(cpu_to_be32(data),addr)
34#endif
30 35
36#ifndef readl_le
31#define readl_le(x) le32_to_cpu(__raw_readl(x)) 37#define readl_le(x) le32_to_cpu(__raw_readl(x))
38#endif
39
40#ifndef writel_le
32#define writel_le(data,addr) __raw_writel(cpu_to_le32(data),addr) 41#define writel_le(data,addr) __raw_writel(cpu_to_le32(data),addr)
42#endif
33 43
34#define MIXART_MEM(mgr,x) ((mgr)->mem[0].virt + (x)) 44#define MIXART_MEM(mgr,x) ((mgr)->mem[0].virt + (x))
35#define MIXART_REG(mgr,x) ((mgr)->mem[1].virt + (x)) 45#define MIXART_REG(mgr,x) ((mgr)->mem[1].virt + (x))
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 85081172403f..b47cfd45b3b9 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -1228,10 +1228,8 @@ int __devinit snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return)
1228 chip->rsrc[i].start + 1, 1228 chip->rsrc[i].start + 1,
1229 rnames[i]) == NULL) { 1229 rnames[i]) == NULL) {
1230 printk(KERN_ERR "snd: can't request rsrc " 1230 printk(KERN_ERR "snd: can't request rsrc "
1231 " %d (%s: 0x%016llx:%016llx)\n", 1231 " %d (%s: %pR)\n",
1232 i, rnames[i], 1232 i, rnames[i], &chip->rsrc[i]);
1233 (unsigned long long)chip->rsrc[i].start,
1234 (unsigned long long)chip->rsrc[i].end);
1235 err = -ENODEV; 1233 err = -ENODEV;
1236 goto __error; 1234 goto __error;
1237 } 1235 }
@@ -1256,10 +1254,8 @@ int __devinit snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return)
1256 chip->rsrc[i].start + 1, 1254 chip->rsrc[i].start + 1,
1257 rnames[i]) == NULL) { 1255 rnames[i]) == NULL) {
1258 printk(KERN_ERR "snd: can't request rsrc " 1256 printk(KERN_ERR "snd: can't request rsrc "
1259 " %d (%s: 0x%016llx:%016llx)\n", 1257 " %d (%s: %pR)\n",
1260 i, rnames[i], 1258 i, rnames[i], &chip->rsrc[i]);
1261 (unsigned long long)chip->rsrc[i].start,
1262 (unsigned long long)chip->rsrc[i].end);
1263 err = -ENODEV; 1259 err = -ENODEV;
1264 goto __error; 1260 goto __error;
1265 } 1261 }
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index e720d5e6f04c..bee3c94f58b0 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -16,7 +16,8 @@ config SND_ATMEL_SOC_SSC
16 16
17config SND_AT91_SOC_SAM9G20_WM8731 17config SND_AT91_SOC_SAM9G20_WM8731
18 tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board" 18 tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board"
19 depends on ATMEL_SSC && ARCH_AT91SAM9G20 && SND_ATMEL_SOC 19 depends on ATMEL_SSC && ARCH_AT91SAM9G20 && SND_ATMEL_SOC && \
20 AT91_PROGRAMMABLE_CLOCKS
20 select SND_ATMEL_SOC_SSC 21 select SND_ATMEL_SOC_SSC
21 select SND_SOC_WM8731 22 select SND_SOC_WM8731
22 help 23 help
@@ -25,7 +26,7 @@ config SND_AT91_SOC_SAM9G20_WM8731
25 26
26config SND_AT32_SOC_PLAYPAQ 27config SND_AT32_SOC_PLAYPAQ
27 tristate "SoC Audio support for PlayPaq with WM8510" 28 tristate "SoC Audio support for PlayPaq with WM8510"
28 depends on SND_ATMEL_SOC && BOARD_PLAYPAQ 29 depends on SND_ATMEL_SOC && BOARD_PLAYPAQ && AT91_PROGRAMMABLE_CLOCKS
29 select SND_ATMEL_SOC_SSC 30 select SND_ATMEL_SOC_SSC
30 select SND_SOC_WM8510 31 select SND_SOC_WM8510
31 help 32 help
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index 293569dfd0ed..e521ada80542 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -222,9 +222,9 @@ static int __init at91sam9g20ek_init(void)
222 } 222 }
223 223
224 pllb = clk_get(NULL, "pllb"); 224 pllb = clk_get(NULL, "pllb");
225 if (IS_ERR(mclk)) { 225 if (IS_ERR(pllb)) {
226 printk(KERN_ERR "ASoC: Failed to get PLLB\n"); 226 printk(KERN_ERR "ASoC: Failed to get PLLB\n");
227 ret = PTR_ERR(mclk); 227 ret = PTR_ERR(pllb);
228 goto err_mclk; 228 goto err_mclk;
229 } 229 }
230 ret = clk_set_parent(mclk, pllb); 230 ret = clk_set_parent(mclk, pllb);
@@ -240,6 +240,7 @@ static int __init at91sam9g20ek_init(void)
240 if (!at91sam9g20ek_snd_device) { 240 if (!at91sam9g20ek_snd_device) {
241 printk(KERN_ERR "ASoC: Platform device allocation failed\n"); 241 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
242 ret = -ENOMEM; 242 ret = -ENOMEM;
243 goto err_mclk;
243 } 244 }
244 245
245 platform_set_drvdata(at91sam9g20ek_snd_device, 246 platform_set_drvdata(at91sam9g20ek_snd_device,
@@ -248,11 +249,13 @@ static int __init at91sam9g20ek_init(void)
248 ret = platform_device_add(at91sam9g20ek_snd_device); 249 ret = platform_device_add(at91sam9g20ek_snd_device);
249 if (ret) { 250 if (ret) {
250 printk(KERN_ERR "ASoC: Platform device allocation failed\n"); 251 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
251 platform_device_put(at91sam9g20ek_snd_device); 252 goto err_device_add;
252 } 253 }
253 254
254 return ret; 255 return ret;
255 256
257err_device_add:
258 platform_device_put(at91sam9g20ek_snd_device);
256err_mclk: 259err_mclk:
257 clk_put(mclk); 260 clk_put(mclk);
258 mclk = NULL; 261 mclk = NULL;
diff --git a/sound/soc/atmel/snd-soc-afeb9260.c b/sound/soc/atmel/snd-soc-afeb9260.c
index e3d283561c19..86e0f8586dc3 100644
--- a/sound/soc/atmel/snd-soc-afeb9260.c
+++ b/sound/soc/atmel/snd-soc-afeb9260.c
@@ -167,7 +167,6 @@ static int __init afeb9260_soc_init(void)
167 167
168 return 0; 168 return 0;
169err1: 169err1:
170 platform_device_del(afeb9260_snd_device);
171 platform_device_put(afeb9260_snd_device); 170 platform_device_put(afeb9260_snd_device);
172 return err; 171 return err;
173} 172}
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 94a9d06b9027..3b5690d28b8b 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -25,8 +25,9 @@ config SND_SOC_ALL_CODECS
25 select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC 25 select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC
26 select SND_SOC_CS42L51 if I2C 26 select SND_SOC_CS42L51 if I2C
27 select SND_SOC_CS4270 if I2C 27 select SND_SOC_CS4270 if I2C
28 select SND_SOC_CX20442
28 select SND_SOC_DA7210 if I2C 29 select SND_SOC_DA7210 if I2C
29 select SND_SOC_JZ4740 if SOC_JZ4740 30 select SND_SOC_JZ4740_CODEC if SOC_JZ4740
30 select SND_SOC_MAX98088 if I2C 31 select SND_SOC_MAX98088 if I2C
31 select SND_SOC_MAX9877 if I2C 32 select SND_SOC_MAX9877 if I2C
32 select SND_SOC_PCM3008 33 select SND_SOC_PCM3008
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 43316a70be05..5182e76e7eb3 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -28,6 +28,11 @@
28#include <sound/max98088.h> 28#include <sound/max98088.h>
29#include "max98088.h" 29#include "max98088.h"
30 30
31enum max98088_type {
32 MAX98088,
33 MAX98089,
34};
35
31struct max98088_cdata { 36struct max98088_cdata {
32 unsigned int rate; 37 unsigned int rate;
33 unsigned int fmt; 38 unsigned int fmt;
@@ -36,6 +41,7 @@ struct max98088_cdata {
36 41
37struct max98088_priv { 42struct max98088_priv {
38 u8 reg_cache[M98088_REG_CNT]; 43 u8 reg_cache[M98088_REG_CNT];
44 enum max98088_type devtype;
39 void *control_data; 45 void *control_data;
40 struct max98088_pdata *pdata; 46 struct max98088_pdata *pdata;
41 unsigned int sysclk; 47 unsigned int sysclk;
@@ -2013,7 +2019,10 @@ err_access:
2013 2019
2014static int max98088_remove(struct snd_soc_codec *codec) 2020static int max98088_remove(struct snd_soc_codec *codec)
2015{ 2021{
2022 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
2023
2016 max98088_set_bias_level(codec, SND_SOC_BIAS_OFF); 2024 max98088_set_bias_level(codec, SND_SOC_BIAS_OFF);
2025 kfree(max98088->eq_texts);
2017 2026
2018 return 0; 2027 return 0;
2019} 2028}
@@ -2040,6 +2049,8 @@ static int max98088_i2c_probe(struct i2c_client *i2c,
2040 if (max98088 == NULL) 2049 if (max98088 == NULL)
2041 return -ENOMEM; 2050 return -ENOMEM;
2042 2051
2052 max98088->devtype = id->driver_data;
2053
2043 i2c_set_clientdata(i2c, max98088); 2054 i2c_set_clientdata(i2c, max98088);
2044 max98088->control_data = i2c; 2055 max98088->control_data = i2c;
2045 max98088->pdata = i2c->dev.platform_data; 2056 max98088->pdata = i2c->dev.platform_data;
@@ -2059,7 +2070,8 @@ static int __devexit max98088_i2c_remove(struct i2c_client *client)
2059} 2070}
2060 2071
2061static const struct i2c_device_id max98088_i2c_id[] = { 2072static const struct i2c_device_id max98088_i2c_id[] = {
2062 { "max98088", 0 }, 2073 { "max98088", MAX98088 },
2074 { "max98089", MAX98089 },
2063 { } 2075 { }
2064}; 2076};
2065MODULE_DEVICE_TABLE(i2c, max98088_i2c_id); 2077MODULE_DEVICE_TABLE(i2c, max98088_i2c_id);
diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c
index 00d67cc8e206..061f9e5a497b 100644
--- a/sound/soc/codecs/stac9766.c
+++ b/sound/soc/codecs/stac9766.c
@@ -383,6 +383,7 @@ static struct snd_soc_codec_driver soc_codec_dev_stac9766 = {
383 .reg_cache_size = sizeof(stac9766_reg), 383 .reg_cache_size = sizeof(stac9766_reg),
384 .reg_word_size = sizeof(u16), 384 .reg_word_size = sizeof(u16),
385 .reg_cache_step = 2, 385 .reg_cache_step = 2,
386 .reg_cache_default = stac9766_reg,
386}; 387};
387 388
388static __devinit int stac9766_probe(struct platform_device *pdev) 389static __devinit int stac9766_probe(struct platform_device *pdev)
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index fc687790188b..77b8f9ae29be 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -1176,7 +1176,7 @@ EXPORT_SYMBOL_GPL(aic3x_set_gpio);
1176int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio) 1176int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio)
1177{ 1177{
1178 u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG; 1178 u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
1179 u8 val, bit = gpio ? 2: 1; 1179 u8 val = 0, bit = gpio ? 2 : 1;
1180 1180
1181 aic3x_read(codec, reg, &val); 1181 aic3x_read(codec, reg, &val);
1182 return (val >> bit) & 1; 1182 return (val >> bit) & 1;
@@ -1204,7 +1204,7 @@ EXPORT_SYMBOL_GPL(aic3x_set_headset_detection);
1204 1204
1205int aic3x_headset_detected(struct snd_soc_codec *codec) 1205int aic3x_headset_detected(struct snd_soc_codec *codec)
1206{ 1206{
1207 u8 val; 1207 u8 val = 0;
1208 aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val); 1208 aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val);
1209 return (val >> 4) & 1; 1209 return (val >> 4) & 1;
1210} 1210}
@@ -1212,7 +1212,7 @@ EXPORT_SYMBOL_GPL(aic3x_headset_detected);
1212 1212
1213int aic3x_button_pressed(struct snd_soc_codec *codec) 1213int aic3x_button_pressed(struct snd_soc_codec *codec)
1214{ 1214{
1215 u8 val; 1215 u8 val = 0;
1216 aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val); 1216 aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val);
1217 return (val >> 5) & 1; 1217 return (val >> 5) & 1;
1218} 1218}
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index d251ff54a2d3..c5ab8c805771 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -58,7 +58,7 @@
58 (1000000000 / ((rate * 1000) / samples)) 58 (1000000000 / ((rate * 1000) / samples))
59 59
60#define US_TO_SAMPLES(rate, us) \ 60#define US_TO_SAMPLES(rate, us) \
61 (rate / (1000000 / us)) 61 (rate / (1000000 / (us < 1000000 ? us : 1000000)))
62 62
63#define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \ 63#define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \
64 ((samples * 5000) / ((burstrate * 5000) / (burstrate - playrate))) 64 ((samples * 5000) / ((burstrate * 5000) / (burstrate - playrate)))
@@ -200,7 +200,7 @@ static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
200 u8 *value) 200 u8 *value)
201{ 201{
202 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 202 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
203 int val; 203 int val, ret = 0;
204 204
205 *value = reg & 0xff; 205 *value = reg & 0xff;
206 206
@@ -210,6 +210,7 @@ static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
210 if (val < 0) { 210 if (val < 0) {
211 dev_err(codec->dev, "Read failed (%d)\n", val); 211 dev_err(codec->dev, "Read failed (%d)\n", val);
212 value[0] = dac33_read_reg_cache(codec, reg); 212 value[0] = dac33_read_reg_cache(codec, reg);
213 ret = val;
213 } else { 214 } else {
214 value[0] = val; 215 value[0] = val;
215 dac33_write_reg_cache(codec, reg, val); 216 dac33_write_reg_cache(codec, reg, val);
@@ -218,7 +219,7 @@ static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
218 value[0] = dac33_read_reg_cache(codec, reg); 219 value[0] = dac33_read_reg_cache(codec, reg);
219 } 220 }
220 221
221 return 0; 222 return ret;
222} 223}
223 224
224static int dac33_write(struct snd_soc_codec *codec, unsigned int reg, 225static int dac33_write(struct snd_soc_codec *codec, unsigned int reg,
@@ -329,13 +330,18 @@ static void dac33_init_chip(struct snd_soc_codec *codec)
329 dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL)); 330 dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL));
330} 331}
331 332
332static inline void dac33_read_id(struct snd_soc_codec *codec) 333static inline int dac33_read_id(struct snd_soc_codec *codec)
333{ 334{
335 int i, ret = 0;
334 u8 reg; 336 u8 reg;
335 337
336 dac33_read(codec, DAC33_DEVICE_ID_MSB, &reg); 338 for (i = 0; i < 3; i++) {
337 dac33_read(codec, DAC33_DEVICE_ID_LSB, &reg); 339 ret = dac33_read(codec, DAC33_DEVICE_ID_MSB + i, &reg);
338 dac33_read(codec, DAC33_DEVICE_REV_ID, &reg); 340 if (ret < 0)
341 break;
342 }
343
344 return ret;
339} 345}
340 346
341static inline void dac33_soft_power(struct snd_soc_codec *codec, int power) 347static inline void dac33_soft_power(struct snd_soc_codec *codec, int power)
@@ -1076,6 +1082,9 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
1076 /* Number of samples under i2c latency */ 1082 /* Number of samples under i2c latency */
1077 dac33->alarm_threshold = US_TO_SAMPLES(rate, 1083 dac33->alarm_threshold = US_TO_SAMPLES(rate,
1078 dac33->mode1_latency); 1084 dac33->mode1_latency);
1085 nsample_limit = DAC33_BUFFER_SIZE_SAMPLES -
1086 dac33->alarm_threshold;
1087
1079 if (dac33->auto_fifo_config) { 1088 if (dac33->auto_fifo_config) {
1080 if (period_size <= dac33->alarm_threshold) 1089 if (period_size <= dac33->alarm_threshold)
1081 /* 1090 /*
@@ -1086,6 +1095,8 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
1086 ((dac33->alarm_threshold / period_size) + 1095 ((dac33->alarm_threshold / period_size) +
1087 (dac33->alarm_threshold % period_size ? 1096 (dac33->alarm_threshold % period_size ?
1088 1 : 0)); 1097 1 : 0));
1098 else if (period_size > nsample_limit)
1099 dac33->nsample = nsample_limit;
1089 else 1100 else
1090 dac33->nsample = period_size; 1101 dac33->nsample = period_size;
1091 } else { 1102 } else {
@@ -1097,8 +1108,7 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
1097 */ 1108 */
1098 dac33->nsample_max = substream->runtime->buffer_size - 1109 dac33->nsample_max = substream->runtime->buffer_size -
1099 period_size; 1110 period_size;
1100 nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - 1111
1101 dac33->alarm_threshold;
1102 if (dac33->nsample_max > nsample_limit) 1112 if (dac33->nsample_max > nsample_limit)
1103 dac33->nsample_max = nsample_limit; 1113 dac33->nsample_max = nsample_limit;
1104 1114
@@ -1414,9 +1424,15 @@ static int dac33_soc_probe(struct snd_soc_codec *codec)
1414 dev_err(codec->dev, "Failed to power up codec: %d\n", ret); 1424 dev_err(codec->dev, "Failed to power up codec: %d\n", ret);
1415 goto err_power; 1425 goto err_power;
1416 } 1426 }
1417 dac33_read_id(codec); 1427 ret = dac33_read_id(codec);
1418 dac33_hard_power(codec, 0); 1428 dac33_hard_power(codec, 0);
1419 1429
1430 if (ret < 0) {
1431 dev_err(codec->dev, "Failed to read chip ID: %d\n", ret);
1432 ret = -ENODEV;
1433 goto err_power;
1434 }
1435
1420 /* Check if the IRQ number is valid and request it */ 1436 /* Check if the IRQ number is valid and request it */
1421 if (dac33->irq >= 0) { 1437 if (dac33->irq >= 0) {
1422 ret = request_irq(dac33->irq, dac33_interrupt_handler, 1438 ret = request_irq(dac33->irq, dac33_interrupt_handler,
diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index 329acc1a2074..d2c243095673 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -78,8 +78,10 @@ static int tpa6130a2_i2c_write(int reg, u8 value)
78 78
79 if (data->power_state) { 79 if (data->power_state) {
80 val = i2c_smbus_write_byte_data(tpa6130a2_client, reg, value); 80 val = i2c_smbus_write_byte_data(tpa6130a2_client, reg, value);
81 if (val < 0) 81 if (val < 0) {
82 dev_err(&tpa6130a2_client->dev, "Write failed\n"); 82 dev_err(&tpa6130a2_client->dev, "Write failed\n");
83 return val;
84 }
83 } 85 }
84 86
85 /* Either powered on or off, we save the context */ 87 /* Either powered on or off, we save the context */
@@ -119,13 +121,13 @@ static int tpa6130a2_power(int power)
119{ 121{
120 struct tpa6130a2_data *data; 122 struct tpa6130a2_data *data;
121 u8 val; 123 u8 val;
122 int ret; 124 int ret = 0;
123 125
124 BUG_ON(tpa6130a2_client == NULL); 126 BUG_ON(tpa6130a2_client == NULL);
125 data = i2c_get_clientdata(tpa6130a2_client); 127 data = i2c_get_clientdata(tpa6130a2_client);
126 128
127 mutex_lock(&data->mutex); 129 mutex_lock(&data->mutex);
128 if (power) { 130 if (power && !data->power_state) {
129 /* Power on */ 131 /* Power on */
130 if (data->power_gpio >= 0) 132 if (data->power_gpio >= 0)
131 gpio_set_value(data->power_gpio, 1); 133 gpio_set_value(data->power_gpio, 1);
@@ -153,7 +155,7 @@ static int tpa6130a2_power(int power)
153 val = tpa6130a2_read(TPA6130A2_REG_CONTROL); 155 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
154 val &= ~TPA6130A2_SWS; 156 val &= ~TPA6130A2_SWS;
155 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val); 157 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
156 } else { 158 } else if (!power && data->power_state) {
157 /* set SWS */ 159 /* set SWS */
158 val = tpa6130a2_read(TPA6130A2_REG_CONTROL); 160 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
159 val |= TPA6130A2_SWS; 161 val |= TPA6130A2_SWS;
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index 7540a509a6f5..464f0cfa4c7a 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -597,6 +597,7 @@ static struct snd_soc_codec_driver soc_codec_dev_uda134x = {
597 .resume = uda134x_soc_resume, 597 .resume = uda134x_soc_resume,
598 .reg_cache_size = sizeof(uda134x_reg), 598 .reg_cache_size = sizeof(uda134x_reg),
599 .reg_word_size = sizeof(u8), 599 .reg_word_size = sizeof(u8),
600 .reg_cache_default = uda134x_reg,
600 .reg_cache_step = 1, 601 .reg_cache_step = 1,
601 .read = uda134x_read_reg_cache, 602 .read = uda134x_read_reg_cache,
602 .write = uda134x_write, 603 .write = uda134x_write,
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index f4f1fba38eb9..7611add7f8c3 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -831,7 +831,7 @@ static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai,
831 } 831 }
832 832
833 /* MCLK direction */ 833 /* MCLK direction */
834 if (dir == WM8350_MCLK_DIR_OUT) 834 if (dir == SND_SOC_CLOCK_OUT)
835 wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_2, 835 wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_2,
836 WM8350_MCLK_DIR); 836 WM8350_MCLK_DIR);
837 else 837 else
@@ -1586,6 +1586,13 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec)
1586 wm8350_set_bits(wm8350, WM8350_ROUT2_VOLUME, 1586 wm8350_set_bits(wm8350, WM8350_ROUT2_VOLUME,
1587 WM8350_OUT2_VU | WM8350_OUT2R_MUTE); 1587 WM8350_OUT2_VU | WM8350_OUT2R_MUTE);
1588 1588
1589 /* Make sure AIF tristating is disabled by default */
1590 wm8350_clear_bits(wm8350, WM8350_AI_FORMATING, WM8350_AIF_TRI);
1591
1592 /* Make sure we've got a sane companding setup too */
1593 wm8350_clear_bits(wm8350, WM8350_ADC_DAC_COMP,
1594 WM8350_DAC_COMP | WM8350_LOOPBACK);
1595
1589 /* Make sure jack detect is disabled to start off with */ 1596 /* Make sure jack detect is disabled to start off with */
1590 wm8350_clear_bits(wm8350, WM8350_JACK_DETECT, 1597 wm8350_clear_bits(wm8350, WM8350_JACK_DETECT,
1591 WM8350_JDL_ENA | WM8350_JDR_ENA); 1598 WM8350_JDL_ENA | WM8350_JDR_ENA);
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c
index 712ef7c76f90..9a433a5396cb 100644
--- a/sound/soc/codecs/wm8523.c
+++ b/sound/soc/codecs/wm8523.c
@@ -146,7 +146,6 @@ static int wm8523_startup(struct snd_pcm_substream *substream,
146 return -EINVAL; 146 return -EINVAL;
147 } 147 }
148 148
149 return 0;
150 snd_pcm_hw_constraint_list(substream->runtime, 0, 149 snd_pcm_hw_constraint_list(substream->runtime, 0,
151 SNDRV_PCM_HW_PARAM_RATE, 150 SNDRV_PCM_HW_PARAM_RATE,
152 &wm8523->rate_constraint); 151 &wm8523->rate_constraint);
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index a2e0ed59b376..8725d4e75431 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -161,7 +161,7 @@
161static const u16 wm8580_reg[] = { 161static const u16 wm8580_reg[] = {
162 0x0121, 0x017e, 0x007d, 0x0014, /*R3*/ 162 0x0121, 0x017e, 0x007d, 0x0014, /*R3*/
163 0x0121, 0x017e, 0x007d, 0x0194, /*R7*/ 163 0x0121, 0x017e, 0x007d, 0x0194, /*R7*/
164 0x001c, 0x0002, 0x0002, 0x00c2, /*R11*/ 164 0x0010, 0x0002, 0x0002, 0x00c2, /*R11*/
165 0x0182, 0x0082, 0x000a, 0x0024, /*R15*/ 165 0x0182, 0x0082, 0x000a, 0x0024, /*R15*/
166 0x0009, 0x0000, 0x00ff, 0x0000, /*R19*/ 166 0x0009, 0x0000, 0x00ff, 0x0000, /*R19*/
167 0x00ff, 0x00ff, 0x00ff, 0x00ff, /*R23*/ 167 0x00ff, 0x00ff, 0x00ff, 0x00ff, /*R23*/
@@ -491,16 +491,16 @@ static int wm8580_paif_hw_params(struct snd_pcm_substream *substream,
491 paifa |= 0x8; 491 paifa |= 0x8;
492 break; 492 break;
493 case SNDRV_PCM_FORMAT_S20_3LE: 493 case SNDRV_PCM_FORMAT_S20_3LE:
494 paifa |= 0x10; 494 paifa |= 0x0;
495 paifb |= WM8580_AIF_LENGTH_20; 495 paifb |= WM8580_AIF_LENGTH_20;
496 break; 496 break;
497 case SNDRV_PCM_FORMAT_S24_LE: 497 case SNDRV_PCM_FORMAT_S24_LE:
498 paifa |= 0x10; 498 paifa |= 0x0;
499 paifb |= WM8580_AIF_LENGTH_24; 499 paifb |= WM8580_AIF_LENGTH_24;
500 break; 500 break;
501 case SNDRV_PCM_FORMAT_S32_LE: 501 case SNDRV_PCM_FORMAT_S32_LE:
502 paifa |= 0x10; 502 paifa |= 0x0;
503 paifb |= WM8580_AIF_LENGTH_24; 503 paifb |= WM8580_AIF_LENGTH_32;
504 break; 504 break;
505 default: 505 default:
506 return -EINVAL; 506 return -EINVAL;
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 631385802eb4..e725c09a3e79 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -526,7 +526,7 @@ static int wm8731_probe(struct snd_soc_codec *codec)
526 snd_soc_update_bits(codec, WM8731_RINVOL, 0x100, 0); 526 snd_soc_update_bits(codec, WM8731_RINVOL, 0x100, 0);
527 527
528 /* Disable bypass path by default */ 528 /* Disable bypass path by default */
529 snd_soc_update_bits(codec, WM8731_APANA, 0x4, 0); 529 snd_soc_update_bits(codec, WM8731_APANA, 0x8, 0);
530 530
531 snd_soc_add_controls(codec, wm8731_snd_controls, 531 snd_soc_add_controls(codec, wm8731_snd_controls,
532 ARRAY_SIZE(wm8731_snd_controls)); 532 ARRAY_SIZE(wm8731_snd_controls));
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index 04182c464e35..0132a27140ae 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -34,7 +34,6 @@
34/* codec private data */ 34/* codec private data */
35struct wm8776_priv { 35struct wm8776_priv {
36 enum snd_soc_control_type control_type; 36 enum snd_soc_control_type control_type;
37 u16 reg_cache[WM8776_CACHEREGNUM];
38 int sysclk[2]; 37 int sysclk[2];
39}; 38};
40 39
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index b4f11724a63f..aca4b1ea10bb 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -186,7 +186,6 @@ static int wm8900_volatile_register(unsigned int reg)
186{ 186{
187 switch (reg) { 187 switch (reg) {
188 case WM8900_REG_ID: 188 case WM8900_REG_ID:
189 case WM8900_REG_POWER1:
190 return 1; 189 return 1;
191 default: 190 default:
192 return 0; 191 return 0;
@@ -1200,11 +1199,6 @@ static int wm8900_probe(struct snd_soc_codec *codec)
1200 return -ENODEV; 1199 return -ENODEV;
1201 } 1200 }
1202 1201
1203 /* Read back from the chip */
1204 reg = snd_soc_read(codec, WM8900_REG_POWER1);
1205 reg = (reg >> 12) & 0xf;
1206 dev_info(codec->dev, "WM8900 revision %d\n", reg);
1207
1208 wm8900_reset(codec); 1202 wm8900_reset(codec);
1209 1203
1210 /* Turn the chip on */ 1204 /* Turn the chip on */
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 33be84e506ea..9001cc48ba13 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -818,7 +818,8 @@ static int wm8904_get_deemph(struct snd_kcontrol *kcontrol,
818 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 818 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
819 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); 819 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
820 820
821 return wm8904->deemph; 821 ucontrol->value.enumerated.item[0] = wm8904->deemph;
822 return 0;
822} 823}
823 824
824static int wm8904_put_deemph(struct snd_kcontrol *kcontrol, 825static int wm8904_put_deemph(struct snd_kcontrol *kcontrol,
@@ -2498,6 +2499,8 @@ static int wm8904_remove(struct snd_soc_codec *codec)
2498 2499
2499 wm8904_set_bias_level(codec, SND_SOC_BIAS_OFF); 2500 wm8904_set_bias_level(codec, SND_SOC_BIAS_OFF);
2500 regulator_bulk_free(ARRAY_SIZE(wm8904->supplies), wm8904->supplies); 2501 regulator_bulk_free(ARRAY_SIZE(wm8904->supplies), wm8904->supplies);
2502 kfree(wm8904->retune_mobile_texts);
2503 kfree(wm8904->drc_texts);
2501 2504
2502 return 0; 2505 return 0;
2503} 2506}
diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c
index f89ad6c9a80b..9cbab8e1de01 100644
--- a/sound/soc/codecs/wm8955.c
+++ b/sound/soc/codecs/wm8955.c
@@ -380,7 +380,8 @@ static int wm8955_get_deemph(struct snd_kcontrol *kcontrol,
380 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 380 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
381 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec); 381 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
382 382
383 return wm8955->deemph; 383 ucontrol->value.enumerated.item[0] = wm8955->deemph;
384 return 0;
384} 385}
385 386
386static int wm8955_put_deemph(struct snd_kcontrol *kcontrol, 387static int wm8955_put_deemph(struct snd_kcontrol *kcontrol,
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index 8d5efb333c33..21986c42272f 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -138,7 +138,8 @@ static int wm8960_get_deemph(struct snd_kcontrol *kcontrol,
138 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 138 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
139 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 139 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
140 140
141 return wm8960->deemph; 141 ucontrol->value.enumerated.item[0] = wm8960->deemph;
142 return 0;
142} 143}
143 144
144static int wm8960_put_deemph(struct snd_kcontrol *kcontrol, 145static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,
diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c
index 4f326f604104..8340485c9851 100644
--- a/sound/soc/codecs/wm8961.c
+++ b/sound/soc/codecs/wm8961.c
@@ -711,7 +711,7 @@ static int wm8961_hw_params(struct snd_pcm_substream *substream,
711 if (fs <= 24000) 711 if (fs <= 24000)
712 reg |= WM8961_DACSLOPE; 712 reg |= WM8961_DACSLOPE;
713 else 713 else
714 reg &= WM8961_DACSLOPE; 714 reg &= ~WM8961_DACSLOPE;
715 snd_soc_write(codec, WM8961_ADC_DAC_CONTROL_2, reg); 715 snd_soc_write(codec, WM8961_ADC_DAC_CONTROL_2, reg);
716 716
717 return 0; 717 return 0;
@@ -736,7 +736,7 @@ static int wm8961_set_sysclk(struct snd_soc_dai *dai, int clk_id,
736 freq /= 2; 736 freq /= 2;
737 } else { 737 } else {
738 dev_dbg(codec->dev, "Using MCLK/1 for %dHz MCLK\n", freq); 738 dev_dbg(codec->dev, "Using MCLK/1 for %dHz MCLK\n", freq);
739 reg &= WM8961_MCLKDIV; 739 reg &= ~WM8961_MCLKDIV;
740 } 740 }
741 741
742 snd_soc_write(codec, WM8961_CLOCKING1, reg); 742 snd_soc_write(codec, WM8961_CLOCKING1, reg);
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 894d0cd3aa9b..1304ca91a11c 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -3339,7 +3339,7 @@ static irqreturn_t wm8962_irq(int irq, void *data)
3339 int mask; 3339 int mask;
3340 int active; 3340 int active;
3341 3341
3342 mask = snd_soc_read(codec, WM8962_INTERRUPT_STATUS_2); 3342 mask = snd_soc_read(codec, WM8962_INTERRUPT_STATUS_2_MASK);
3343 3343
3344 active = snd_soc_read(codec, WM8962_INTERRUPT_STATUS_2); 3344 active = snd_soc_read(codec, WM8962_INTERRUPT_STATUS_2);
3345 active &= ~mask; 3345 active &= ~mask;
@@ -3500,8 +3500,11 @@ static ssize_t wm8962_beep_set(struct device *dev,
3500{ 3500{
3501 struct wm8962_priv *wm8962 = dev_get_drvdata(dev); 3501 struct wm8962_priv *wm8962 = dev_get_drvdata(dev);
3502 long int time; 3502 long int time;
3503 int ret;
3503 3504
3504 strict_strtol(buf, 10, &time); 3505 ret = strict_strtol(buf, 10, &time);
3506 if (ret != 0)
3507 return ret;
3505 3508
3506 input_event(wm8962->beep, EV_SND, SND_TONE, time); 3509 input_event(wm8962->beep, EV_SND, SND_TONE, time);
3507 3510
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 0db59c3aa5d4..4d3e6f1ac584 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -3903,6 +3903,8 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
3903 return -ENOMEM; 3903 return -ENOMEM;
3904 snd_soc_codec_set_drvdata(codec, wm8994); 3904 snd_soc_codec_set_drvdata(codec, wm8994);
3905 3905
3906 codec->reg_cache = &wm8994->reg_cache;
3907
3906 wm8994->pdata = dev_get_platdata(codec->dev->parent); 3908 wm8994->pdata = dev_get_platdata(codec->dev->parent);
3907 wm8994->codec = codec; 3909 wm8994->codec = codec;
3908 3910
@@ -4059,6 +4061,8 @@ static int wm8994_codec_remove(struct snd_soc_codec *codec)
4059 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994); 4061 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994);
4060 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994); 4062 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994);
4061 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET, wm8994); 4063 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET, wm8994);
4064 kfree(wm8994->retune_mobile_texts);
4065 kfree(wm8994->drc_texts);
4062 kfree(wm8994); 4066 kfree(wm8994);
4063 4067
4064 return 0; 4068 return 0;
@@ -4071,6 +4075,8 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
4071 .resume = wm8994_resume, 4075 .resume = wm8994_resume,
4072 .read = wm8994_read, 4076 .read = wm8994_read,
4073 .write = wm8994_write, 4077 .write = wm8994_write,
4078 .readable_register = wm8994_readable,
4079 .volatile_register = wm8994_volatile,
4074 .set_bias_level = wm8994_set_bias_level, 4080 .set_bias_level = wm8994_set_bias_level,
4075}; 4081};
4076 4082
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index 2cb81538cd91..0e24092722c3 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -123,7 +123,7 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
123 reg_r = reg & WM8993_DCS_DAC_WR_VAL_0_MASK; 123 reg_r = reg & WM8993_DCS_DAC_WR_VAL_0_MASK;
124 break; 124 break;
125 default: 125 default:
126 WARN(1, "Unknown DCS readback method"); 126 WARN(1, "Unknown DCS readback method\n");
127 break; 127 break;
128 } 128 }
129 129
@@ -293,7 +293,7 @@ SOC_DOUBLE_R("Speaker Switch",
293SOC_DOUBLE_R("Speaker ZC Switch", 293SOC_DOUBLE_R("Speaker ZC Switch",
294 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT, 294 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
295 7, 1, 0), 295 7, 1, 0),
296SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 0, 3, 7, 0, 296SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 3, 0, 7, 0,
297 spkboost_tlv), 297 spkboost_tlv),
298SOC_ENUM("Speaker Reference", speaker_ref), 298SOC_ENUM("Speaker Reference", speaker_ref),
299SOC_ENUM("Speaker Mode", speaker_mode), 299SOC_ENUM("Speaker Mode", speaker_mode),
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index 2b07b17a6b2d..bc9e6b0b3f6f 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -157,12 +157,23 @@ static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
157} 157}
158 158
159/* davinci-evm digital audio interface glue - connects codec <--> CPU */ 159/* davinci-evm digital audio interface glue - connects codec <--> CPU */
160static struct snd_soc_dai_link evm_dai = { 160static struct snd_soc_dai_link dm6446_evm_dai = {
161 .name = "TLV320AIC3X", 161 .name = "TLV320AIC3X",
162 .stream_name = "AIC3X", 162 .stream_name = "AIC3X",
163 .cpu_dai_name = "davinci-mcasp.0", 163 .cpu_dai_name = "davinci-mcbsp",
164 .codec_dai_name = "tlv320aic3x-hifi", 164 .codec_dai_name = "tlv320aic3x-hifi",
165 .codec_name = "tlv320aic3x-codec.0-001a", 165 .codec_name = "tlv320aic3x-codec.1-001b",
166 .platform_name = "davinci-pcm-audio",
167 .init = evm_aic3x_init,
168 .ops = &evm_ops,
169};
170
171static struct snd_soc_dai_link dm355_evm_dai = {
172 .name = "TLV320AIC3X",
173 .stream_name = "AIC3X",
174 .cpu_dai_name = "davinci-mcbsp.1",
175 .codec_dai_name = "tlv320aic3x-hifi",
176 .codec_name = "tlv320aic3x-codec.1-001b",
166 .platform_name = "davinci-pcm-audio", 177 .platform_name = "davinci-pcm-audio",
167 .init = evm_aic3x_init, 178 .init = evm_aic3x_init,
168 .ops = &evm_ops, 179 .ops = &evm_ops,
@@ -172,10 +183,10 @@ static struct snd_soc_dai_link dm365_evm_dai = {
172#ifdef CONFIG_SND_DM365_AIC3X_CODEC 183#ifdef CONFIG_SND_DM365_AIC3X_CODEC
173 .name = "TLV320AIC3X", 184 .name = "TLV320AIC3X",
174 .stream_name = "AIC3X", 185 .stream_name = "AIC3X",
175 .cpu_dai_name = "davinci-i2s", 186 .cpu_dai_name = "davinci-mcbsp",
176 .codec_dai_name = "tlv320aic3x-hifi", 187 .codec_dai_name = "tlv320aic3x-hifi",
177 .init = evm_aic3x_init, 188 .init = evm_aic3x_init,
178 .codec_name = "tlv320aic3x-codec.0-001a", 189 .codec_name = "tlv320aic3x-codec.1-0018",
179 .ops = &evm_ops, 190 .ops = &evm_ops,
180#elif defined(CONFIG_SND_DM365_VOICE_CODEC) 191#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
181 .name = "Voice Codec - CQ93VC", 192 .name = "Voice Codec - CQ93VC",
@@ -219,10 +230,17 @@ static struct snd_soc_dai_link da8xx_evm_dai = {
219 .ops = &evm_ops, 230 .ops = &evm_ops,
220}; 231};
221 232
222/* davinci dm6446, dm355 evm audio machine driver */ 233/* davinci dm6446 evm audio machine driver */
223static struct snd_soc_card snd_soc_card_evm = { 234static struct snd_soc_card dm6446_snd_soc_card_evm = {
224 .name = "DaVinci EVM", 235 .name = "DaVinci DM6446 EVM",
225 .dai_link = &evm_dai, 236 .dai_link = &dm6446_evm_dai,
237 .num_links = 1,
238};
239
240/* davinci dm355 evm audio machine driver */
241static struct snd_soc_card dm355_snd_soc_card_evm = {
242 .name = "DaVinci DM355 EVM",
243 .dai_link = &dm355_evm_dai,
226 .num_links = 1, 244 .num_links = 1,
227}; 245};
228 246
@@ -261,10 +279,10 @@ static int __init evm_init(void)
261 int ret; 279 int ret;
262 280
263 if (machine_is_davinci_evm()) { 281 if (machine_is_davinci_evm()) {
264 evm_snd_dev_data = &snd_soc_card_evm; 282 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
265 index = 0; 283 index = 0;
266 } else if (machine_is_davinci_dm355_evm()) { 284 } else if (machine_is_davinci_dm355_evm()) {
267 evm_snd_dev_data = &snd_soc_card_evm; 285 evm_snd_dev_data = &dm355_snd_soc_card_evm;
268 index = 1; 286 index = 1;
269 } else if (machine_is_davinci_dm365_evm()) { 287 } else if (machine_is_davinci_dm365_evm()) {
270 evm_snd_dev_data = &dm365_snd_soc_card_evm; 288 evm_snd_dev_data = &dm365_snd_soc_card_evm;
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
index d46b545d41f4..9e0e565e6ed9 100644
--- a/sound/soc/davinci/davinci-i2s.c
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -426,9 +426,6 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
426 snd_pcm_format_t fmt; 426 snd_pcm_format_t fmt;
427 unsigned element_cnt = 1; 427 unsigned element_cnt = 1;
428 428
429 dai->capture_dma_data = dev->dma_params;
430 dai->playback_dma_data = dev->dma_params;
431
432 /* general line settings */ 429 /* general line settings */
433 spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); 430 spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
434 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { 431 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
@@ -601,6 +598,15 @@ static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
601 return ret; 598 return ret;
602} 599}
603 600
601static int davinci_i2s_startup(struct snd_pcm_substream *substream,
602 struct snd_soc_dai *dai)
603{
604 struct davinci_mcbsp_dev *dev = snd_soc_dai_get_drvdata(dai);
605
606 snd_soc_dai_set_dma_data(dai, substream, dev->dma_params);
607 return 0;
608}
609
604static void davinci_i2s_shutdown(struct snd_pcm_substream *substream, 610static void davinci_i2s_shutdown(struct snd_pcm_substream *substream,
605 struct snd_soc_dai *dai) 611 struct snd_soc_dai *dai)
606{ 612{
@@ -612,6 +618,7 @@ static void davinci_i2s_shutdown(struct snd_pcm_substream *substream,
612#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000 618#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000
613 619
614static struct snd_soc_dai_ops davinci_i2s_dai_ops = { 620static struct snd_soc_dai_ops davinci_i2s_dai_ops = {
621 .startup = davinci_i2s_startup,
615 .shutdown = davinci_i2s_shutdown, 622 .shutdown = davinci_i2s_shutdown,
616 .prepare = davinci_i2s_prepare, 623 .prepare = davinci_i2s_prepare,
617 .trigger = davinci_i2s_trigger, 624 .trigger = davinci_i2s_trigger,
@@ -749,7 +756,7 @@ static struct platform_driver davinci_mcbsp_driver = {
749 .probe = davinci_i2s_probe, 756 .probe = davinci_i2s_probe,
750 .remove = davinci_i2s_remove, 757 .remove = davinci_i2s_remove,
751 .driver = { 758 .driver = {
752 .name = "davinci-i2s", 759 .name = "davinci-mcbsp",
753 .owner = THIS_MODULE, 760 .owner = THIS_MODULE,
754 }, 761 },
755}; 762};
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 86918ee12419..fb55d2c5d704 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -715,9 +715,6 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
715 int word_length; 715 int word_length;
716 u8 fifo_level; 716 u8 fifo_level;
717 717
718 cpu_dai->capture_dma_data = dev->dma_params;
719 cpu_dai->playback_dma_data = dev->dma_params;
720
721 davinci_hw_common_param(dev, substream->stream); 718 davinci_hw_common_param(dev, substream->stream);
722 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 719 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
723 fifo_level = dev->txnumevt; 720 fifo_level = dev->txnumevt;
@@ -799,7 +796,17 @@ static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
799 return ret; 796 return ret;
800} 797}
801 798
799static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
800 struct snd_soc_dai *dai)
801{
802 struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai);
803
804 snd_soc_dai_set_dma_data(dai, substream, dev->dma_params);
805 return 0;
806}
807
802static struct snd_soc_dai_ops davinci_mcasp_dai_ops = { 808static struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
809 .startup = davinci_mcasp_startup,
803 .trigger = davinci_mcasp_trigger, 810 .trigger = davinci_mcasp_trigger,
804 .hw_params = davinci_mcasp_hw_params, 811 .hw_params = davinci_mcasp_hw_params,
805 .set_fmt = davinci_mcasp_set_dai_fmt, 812 .set_fmt = davinci_mcasp_set_dai_fmt,
diff --git a/sound/soc/davinci/davinci-sffsdr.c b/sound/soc/davinci/davinci-sffsdr.c
index 009b6521a1bf..6c6666a1f942 100644
--- a/sound/soc/davinci/davinci-sffsdr.c
+++ b/sound/soc/davinci/davinci-sffsdr.c
@@ -84,7 +84,7 @@ static struct snd_soc_ops sffsdr_ops = {
84static struct snd_soc_dai_link sffsdr_dai = { 84static struct snd_soc_dai_link sffsdr_dai = {
85 .name = "PCM3008", /* Codec name */ 85 .name = "PCM3008", /* Codec name */
86 .stream_name = "PCM3008 HiFi", 86 .stream_name = "PCM3008 HiFi",
87 .cpu_dai_name = "davinci-asp.0", 87 .cpu_dai_name = "davinci-mcbsp",
88 .codec_dai_name = "pcm3008-hifi", 88 .codec_dai_name = "pcm3008-hifi",
89 .codec_name = "pcm3008-codec", 89 .codec_name = "pcm3008-codec",
90 .platform_name = "davinci-pcm-audio", 90 .platform_name = "davinci-pcm-audio",
diff --git a/sound/soc/davinci/davinci-vcif.c b/sound/soc/davinci/davinci-vcif.c
index ea232f6a2c21..9d2afccc3a2d 100644
--- a/sound/soc/davinci/davinci-vcif.c
+++ b/sound/soc/davinci/davinci-vcif.c
@@ -97,9 +97,6 @@ static int davinci_vcif_hw_params(struct snd_pcm_substream *substream,
97 &davinci_vcif_dev->dma_params[substream->stream]; 97 &davinci_vcif_dev->dma_params[substream->stream];
98 u32 w; 98 u32 w;
99 99
100 dai->capture_dma_data = davinci_vcif_dev->dma_params;
101 dai->playback_dma_data = davinci_vcif_dev->dma_params;
102
103 /* Restart the codec before setup */ 100 /* Restart the codec before setup */
104 davinci_vcif_stop(substream); 101 davinci_vcif_stop(substream);
105 davinci_vcif_start(substream); 102 davinci_vcif_start(substream);
@@ -174,9 +171,19 @@ static int davinci_vcif_trigger(struct snd_pcm_substream *substream, int cmd,
174 return ret; 171 return ret;
175} 172}
176 173
174static int davinci_vcif_startup(struct snd_pcm_substream *substream,
175 struct snd_soc_dai *dai)
176{
177 struct davinci_vcif_dev *dev = snd_soc_dai_get_drvdata(dai);
178
179 snd_soc_dai_set_dma_data(dai, substream, dev->dma_params);
180 return 0;
181}
182
177#define DAVINCI_VCIF_RATES SNDRV_PCM_RATE_8000_48000 183#define DAVINCI_VCIF_RATES SNDRV_PCM_RATE_8000_48000
178 184
179static struct snd_soc_dai_ops davinci_vcif_dai_ops = { 185static struct snd_soc_dai_ops davinci_vcif_dai_ops = {
186 .startup = davinci_vcif_startup,
180 .trigger = davinci_vcif_trigger, 187 .trigger = davinci_vcif_trigger,
181 .hw_params = davinci_vcif_hw_params, 188 .hw_params = davinci_vcif_hw_params,
182}; 189};
@@ -240,7 +247,10 @@ fail:
240 247
241static int davinci_vcif_remove(struct platform_device *pdev) 248static int davinci_vcif_remove(struct platform_device *pdev)
242{ 249{
250 struct davinci_vcif_dev *davinci_vcif_dev = dev_get_drvdata(&pdev->dev);
251
243 snd_soc_unregister_dai(&pdev->dev); 252 snd_soc_unregister_dai(&pdev->dev);
253 kfree(davinci_vcif_dev);
244 254
245 return 0; 255 return 0;
246} 256}
diff --git a/sound/soc/ep93xx/simone.c b/sound/soc/ep93xx/simone.c
index 4b0d19913728..286817946c56 100644
--- a/sound/soc/ep93xx/simone.c
+++ b/sound/soc/ep93xx/simone.c
@@ -54,24 +54,26 @@ static int __init simone_init(void)
54 54
55 ret = platform_device_add(simone_snd_ac97_device); 55 ret = platform_device_add(simone_snd_ac97_device);
56 if (ret) 56 if (ret)
57 goto fail; 57 goto fail1;
58 58
59 simone_snd_device = platform_device_alloc("soc-audio", -1); 59 simone_snd_device = platform_device_alloc("soc-audio", -1);
60 if (!simone_snd_device) { 60 if (!simone_snd_device) {
61 ret = -ENOMEM; 61 ret = -ENOMEM;
62 goto fail; 62 goto fail2;
63 } 63 }
64 64
65 platform_set_drvdata(simone_snd_device, &snd_soc_simone); 65 platform_set_drvdata(simone_snd_device, &snd_soc_simone);
66 ret = platform_device_add(simone_snd_device); 66 ret = platform_device_add(simone_snd_device);
67 if (ret) { 67 if (ret)
68 platform_device_put(simone_snd_device); 68 goto fail3;
69 goto fail;
70 }
71 69
72 return ret; 70 return 0;
73 71
74fail: 72fail3:
73 platform_device_put(simone_snd_device);
74fail2:
75 platform_device_del(simone_snd_ac97_device);
76fail1:
75 platform_device_put(simone_snd_ac97_device); 77 platform_device_put(simone_snd_ac97_device);
76 return ret; 78 return ret;
77} 79}
diff --git a/sound/soc/fsl/efika-audio-fabric.c b/sound/soc/fsl/efika-audio-fabric.c
index 53251e6b5bd5..108b5d8bd0e9 100644
--- a/sound/soc/fsl/efika-audio-fabric.c
+++ b/sound/soc/fsl/efika-audio-fabric.c
@@ -76,6 +76,7 @@ static __init int efika_fabric_init(void)
76 rc = platform_device_add(pdev); 76 rc = platform_device_add(pdev);
77 if (rc) { 77 if (rc) {
78 pr_err("efika_fabric_init: platform_device_add() failed\n"); 78 pr_err("efika_fabric_init: platform_device_add() failed\n");
79 platform_device_put(pdev);
79 return -ENODEV; 80 return -ENODEV;
80 } 81 }
81 return 0; 82 return 0;
diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
index dce6b551cd78..f92dca07cd35 100644
--- a/sound/soc/fsl/mpc5200_dma.c
+++ b/sound/soc/fsl/mpc5200_dma.c
@@ -9,7 +9,6 @@
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/of_device.h> 10#include <linux/of_device.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/of_device.h>
13#include <linux/of_platform.h> 12#include <linux/of_platform.h>
14 13
15#include <sound/soc.h> 14#include <sound/soc.h>
diff --git a/sound/soc/fsl/mpc5200_psc_i2s.c b/sound/soc/fsl/mpc5200_psc_i2s.c
index 74ffed41340f..9018fa5bf0db 100644
--- a/sound/soc/fsl/mpc5200_psc_i2s.c
+++ b/sound/soc/fsl/mpc5200_psc_i2s.c
@@ -160,7 +160,7 @@ static int __devinit psc_i2s_of_probe(struct platform_device *op,
160 rc = snd_soc_register_dais(&op->dev, psc_i2s_dai, ARRAY_SIZE(psc_i2s_dai)); 160 rc = snd_soc_register_dais(&op->dev, psc_i2s_dai, ARRAY_SIZE(psc_i2s_dai));
161 if (rc != 0) { 161 if (rc != 0) {
162 pr_err("Failed to register DAI\n"); 162 pr_err("Failed to register DAI\n");
163 return 0; 163 return rc;
164 } 164 }
165 165
166 psc_dma = dev_get_drvdata(&op->dev); 166 psc_dma = dev_get_drvdata(&op->dev);
diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c
index 0d7dcf1e4863..7d7847a1e66b 100644
--- a/sound/soc/fsl/mpc8610_hpcd.c
+++ b/sound/soc/fsl/mpc8610_hpcd.c
@@ -498,6 +498,7 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev)
498 dev_err(&pdev->dev, "platform device add failed\n"); 498 dev_err(&pdev->dev, "platform device add failed\n");
499 goto error; 499 goto error;
500 } 500 }
501 dev_set_drvdata(&pdev->dev, sound_device);
501 502
502 of_node_put(codec_np); 503 of_node_put(codec_np);
503 504
diff --git a/sound/soc/fsl/p1022_ds.c b/sound/soc/fsl/p1022_ds.c
index 63b9eaa1ebc2..026b756961e0 100644
--- a/sound/soc/fsl/p1022_ds.c
+++ b/sound/soc/fsl/p1022_ds.c
@@ -498,6 +498,7 @@ static int p1022_ds_probe(struct platform_device *pdev)
498 dev_err(&pdev->dev, "platform device add failed\n"); 498 dev_err(&pdev->dev, "platform device add failed\n");
499 goto error; 499 goto error;
500 } 500 }
501 dev_set_drvdata(&pdev->dev, sound_device);
501 502
502 of_node_put(codec_np); 503 of_node_put(codec_np);
503 504
diff --git a/sound/soc/fsl/pcm030-audio-fabric.c b/sound/soc/fsl/pcm030-audio-fabric.c
index 25f27ec1dd6e..ba4d85e317ed 100644
--- a/sound/soc/fsl/pcm030-audio-fabric.c
+++ b/sound/soc/fsl/pcm030-audio-fabric.c
@@ -76,6 +76,7 @@ static __init int pcm030_fabric_init(void)
76 rc = platform_device_add(pdev); 76 rc = platform_device_add(pdev);
77 if (rc) { 77 if (rc) {
78 pr_err("pcm030_fabric_init: platform_device_add() failed\n"); 78 pr_err("pcm030_fabric_init: platform_device_add() failed\n");
79 platform_device_put(pdev);
79 return -ENODEV; 80 return -ENODEV;
80 } 81 }
81 return 0; 82 return 0;
diff --git a/sound/soc/imx/eukrea-tlv320.c b/sound/soc/imx/eukrea-tlv320.c
index b59675257ce5..dd4fffdbd177 100644
--- a/sound/soc/imx/eukrea-tlv320.c
+++ b/sound/soc/imx/eukrea-tlv320.c
@@ -34,8 +34,8 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
34 struct snd_pcm_hw_params *params) 34 struct snd_pcm_hw_params *params)
35{ 35{
36 struct snd_soc_pcm_runtime *rtd = substream->private_data; 36 struct snd_soc_pcm_runtime *rtd = substream->private_data;
37 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 37 struct snd_soc_dai *codec_dai = rtd->codec_dai;
38 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; 38 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
39 int ret; 39 int ret;
40 40
41 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | 41 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
@@ -79,10 +79,10 @@ static struct snd_soc_ops eukrea_tlv320_snd_ops = {
79static struct snd_soc_dai_link eukrea_tlv320_dai = { 79static struct snd_soc_dai_link eukrea_tlv320_dai = {
80 .name = "tlv320aic23", 80 .name = "tlv320aic23",
81 .stream_name = "TLV320AIC23", 81 .stream_name = "TLV320AIC23",
82 .codec_dai = "tlv320aic23-hifi", 82 .codec_dai_name = "tlv320aic23-hifi",
83 .platform_name = "imx-pcm-audio.0", 83 .platform_name = "imx-pcm-audio.0",
84 .codec_name = "tlv320aic23-codec.0-001a", 84 .codec_name = "tlv320aic23-codec.0-001a",
85 .cpu_dai = "imx-ssi.0", 85 .cpu_dai_name = "imx-ssi.0",
86 .ops = &eukrea_tlv320_snd_ops, 86 .ops = &eukrea_tlv320_snd_ops,
87}; 87};
88 88
diff --git a/sound/soc/imx/imx-pcm-dma-mx2.c b/sound/soc/imx/imx-pcm-dma-mx2.c
index fd493ee1428e..671ef8dd524c 100644
--- a/sound/soc/imx/imx-pcm-dma-mx2.c
+++ b/sound/soc/imx/imx-pcm-dma-mx2.c
@@ -20,6 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/dmaengine.h>
23 24
24#include <sound/core.h> 25#include <sound/core.h>
25#include <sound/initval.h> 26#include <sound/initval.h>
@@ -27,165 +28,146 @@
27#include <sound/pcm_params.h> 28#include <sound/pcm_params.h>
28#include <sound/soc.h> 29#include <sound/soc.h>
29 30
30#include <mach/dma-mx1-mx2.h> 31#include <mach/dma.h>
31 32
32#include "imx-ssi.h" 33#include "imx-ssi.h"
33 34
34struct imx_pcm_runtime_data { 35struct imx_pcm_runtime_data {
35 int sg_count; 36 int period_bytes;
36 struct scatterlist *sg_list;
37 int period;
38 int periods; 37 int periods;
39 unsigned long dma_addr;
40 int dma; 38 int dma;
41 struct snd_pcm_substream *substream;
42 unsigned long offset; 39 unsigned long offset;
43 unsigned long size; 40 unsigned long size;
44 unsigned long period_cnt;
45 void *buf; 41 void *buf;
46 int period_time; 42 int period_time;
43 struct dma_async_tx_descriptor *desc;
44 struct dma_chan *dma_chan;
45 struct imx_dma_data dma_data;
47}; 46};
48 47
49/* Called by the DMA framework when a period has elapsed */ 48static void audio_dma_irq(void *data)
50static void imx_ssi_dma_progression(int channel, void *data,
51 struct scatterlist *sg)
52{ 49{
53 struct snd_pcm_substream *substream = data; 50 struct snd_pcm_substream *substream = (struct snd_pcm_substream *)data;
54 struct snd_pcm_runtime *runtime = substream->runtime; 51 struct snd_pcm_runtime *runtime = substream->runtime;
55 struct imx_pcm_runtime_data *iprtd = runtime->private_data; 52 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
56 53
57 if (!sg) 54 iprtd->offset += iprtd->period_bytes;
58 return; 55 iprtd->offset %= iprtd->period_bytes * iprtd->periods;
59
60 runtime = iprtd->substream->runtime;
61 56
62 iprtd->offset = sg->dma_address - runtime->dma_addr; 57 snd_pcm_period_elapsed(substream);
63
64 snd_pcm_period_elapsed(iprtd->substream);
65} 58}
66 59
67static void imx_ssi_dma_callback(int channel, void *data) 60static bool filter(struct dma_chan *chan, void *param)
68{ 61{
69 pr_err("%s shouldn't be called\n", __func__); 62 struct imx_pcm_runtime_data *iprtd = param;
70}
71 63
72static void snd_imx_dma_err_callback(int channel, void *data, int err) 64 if (!imx_dma_is_general_purpose(chan))
73{ 65 return false;
74 struct snd_pcm_substream *substream = data;
75 struct snd_soc_pcm_runtime *rtd = substream->private_data;
76 struct imx_pcm_dma_params *dma_params =
77 snd_soc_dai_get_dma_data(rtd->dai->cpu_dai, substream);
78 struct snd_pcm_runtime *runtime = substream->runtime;
79 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
80 int ret;
81 66
82 pr_err("DMA timeout on channel %d -%s%s%s%s\n", 67 chan->private = &iprtd->dma_data;
83 channel,
84 err & IMX_DMA_ERR_BURST ? " burst" : "",
85 err & IMX_DMA_ERR_REQUEST ? " request" : "",
86 err & IMX_DMA_ERR_TRANSFER ? " transfer" : "",
87 err & IMX_DMA_ERR_BUFFER ? " buffer" : "");
88 68
89 imx_dma_disable(iprtd->dma); 69 return true;
90 ret = imx_dma_setup_sg(iprtd->dma, iprtd->sg_list, iprtd->sg_count,
91 IMX_DMA_LENGTH_LOOP, dma_params->dma_addr,
92 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
93 DMA_MODE_WRITE : DMA_MODE_READ);
94 if (!ret)
95 imx_dma_enable(iprtd->dma);
96} 70}
97 71
98static int imx_ssi_dma_alloc(struct snd_pcm_substream *substream) 72static int imx_ssi_dma_alloc(struct snd_pcm_substream *substream,
73 struct snd_pcm_hw_params *params)
99{ 74{
100 struct snd_soc_pcm_runtime *rtd = substream->private_data; 75 struct snd_soc_pcm_runtime *rtd = substream->private_data;
101 struct imx_pcm_dma_params *dma_params; 76 struct imx_pcm_dma_params *dma_params;
102 struct snd_pcm_runtime *runtime = substream->runtime; 77 struct snd_pcm_runtime *runtime = substream->runtime;
103 struct imx_pcm_runtime_data *iprtd = runtime->private_data; 78 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
79 struct dma_slave_config slave_config;
80 dma_cap_mask_t mask;
81 enum dma_slave_buswidth buswidth;
104 int ret; 82 int ret;
105 83
106 dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); 84 dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
107 85
108 iprtd->dma = imx_dma_request_by_prio(DRV_NAME, DMA_PRIO_HIGH); 86 iprtd->dma_data.peripheral_type = IMX_DMATYPE_SSI;
109 if (iprtd->dma < 0) { 87 iprtd->dma_data.priority = DMA_PRIO_HIGH;
110 pr_err("Failed to claim the audio DMA\n"); 88 iprtd->dma_data.dma_request = dma_params->dma;
111 return -ENODEV;
112 }
113 89
114 ret = imx_dma_setup_handlers(iprtd->dma, 90 /* Try to grab a DMA channel */
115 imx_ssi_dma_callback, 91 dma_cap_zero(mask);
116 snd_imx_dma_err_callback, substream); 92 dma_cap_set(DMA_SLAVE, mask);
117 if (ret) 93 iprtd->dma_chan = dma_request_channel(mask, filter, iprtd);
118 goto out; 94 if (!iprtd->dma_chan)
95 return -EINVAL;
119 96
120 ret = imx_dma_setup_progression_handler(iprtd->dma, 97 switch (params_format(params)) {
121 imx_ssi_dma_progression); 98 case SNDRV_PCM_FORMAT_S16_LE:
122 if (ret) { 99 buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
123 pr_err("Failed to setup the DMA handler\n"); 100 break;
124 goto out; 101 case SNDRV_PCM_FORMAT_S20_3LE:
102 case SNDRV_PCM_FORMAT_S24_LE:
103 buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
104 break;
105 default:
106 return 0;
125 } 107 }
126 108
127 ret = imx_dma_config_channel(iprtd->dma, 109 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
128 IMX_DMA_MEMSIZE_16 | IMX_DMA_TYPE_FIFO, 110 slave_config.direction = DMA_TO_DEVICE;
129 IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR, 111 slave_config.dst_addr = dma_params->dma_addr;
130 dma_params->dma, 1); 112 slave_config.dst_addr_width = buswidth;
131 if (ret < 0) { 113 slave_config.dst_maxburst = dma_params->burstsize;
132 pr_err("Cannot configure DMA channel: %d\n", ret); 114 } else {
133 goto out; 115 slave_config.direction = DMA_FROM_DEVICE;
116 slave_config.src_addr = dma_params->dma_addr;
117 slave_config.src_addr_width = buswidth;
118 slave_config.src_maxburst = dma_params->burstsize;
134 } 119 }
135 120
136 imx_dma_config_burstlen(iprtd->dma, dma_params->burstsize * 2); 121 ret = dmaengine_slave_config(iprtd->dma_chan, &slave_config);
122 if (ret)
123 return ret;
137 124
138 return 0; 125 return 0;
139out:
140 imx_dma_free(iprtd->dma);
141 return ret;
142} 126}
143 127
144static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream, 128static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,
145 struct snd_pcm_hw_params *params) 129 struct snd_pcm_hw_params *params)
146{ 130{
131 struct snd_soc_pcm_runtime *rtd = substream->private_data;
147 struct snd_pcm_runtime *runtime = substream->runtime; 132 struct snd_pcm_runtime *runtime = substream->runtime;
148 struct imx_pcm_runtime_data *iprtd = runtime->private_data; 133 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
149 int i;
150 unsigned long dma_addr; 134 unsigned long dma_addr;
135 struct dma_chan *chan;
136 struct imx_pcm_dma_params *dma_params;
137 int ret;
151 138
152 imx_ssi_dma_alloc(substream); 139 dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
140 ret = imx_ssi_dma_alloc(substream, params);
141 if (ret)
142 return ret;
143 chan = iprtd->dma_chan;
153 144
154 iprtd->size = params_buffer_bytes(params); 145 iprtd->size = params_buffer_bytes(params);
155 iprtd->periods = params_periods(params); 146 iprtd->periods = params_periods(params);
156 iprtd->period = params_period_bytes(params); 147 iprtd->period_bytes = params_period_bytes(params);
157 iprtd->offset = 0; 148 iprtd->offset = 0;
158 iprtd->period_time = HZ / (params_rate(params) / 149 iprtd->period_time = HZ / (params_rate(params) /
159 params_period_size(params)); 150 params_period_size(params));
160 151
161 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); 152 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
162 153
163 if (iprtd->sg_count != iprtd->periods) {
164 kfree(iprtd->sg_list);
165
166 iprtd->sg_list = kcalloc(iprtd->periods + 1,
167 sizeof(struct scatterlist), GFP_KERNEL);
168 if (!iprtd->sg_list)
169 return -ENOMEM;
170 iprtd->sg_count = iprtd->periods + 1;
171 }
172
173 sg_init_table(iprtd->sg_list, iprtd->sg_count);
174 dma_addr = runtime->dma_addr; 154 dma_addr = runtime->dma_addr;
175 155
176 for (i = 0; i < iprtd->periods; i++) { 156 iprtd->buf = (unsigned int *)substream->dma_buffer.area;
177 iprtd->sg_list[i].page_link = 0; 157
178 iprtd->sg_list[i].offset = 0; 158 iprtd->desc = chan->device->device_prep_dma_cyclic(chan, dma_addr,
179 iprtd->sg_list[i].dma_address = dma_addr; 159 iprtd->period_bytes * iprtd->periods,
180 iprtd->sg_list[i].length = iprtd->period; 160 iprtd->period_bytes,
181 dma_addr += iprtd->period; 161 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
162 DMA_TO_DEVICE : DMA_FROM_DEVICE);
163 if (!iprtd->desc) {
164 dev_err(&chan->dev->device, "cannot prepare slave dma\n");
165 return -EINVAL;
182 } 166 }
183 167
184 /* close the loop */ 168 iprtd->desc->callback = audio_dma_irq;
185 iprtd->sg_list[iprtd->sg_count - 1].offset = 0; 169 iprtd->desc->callback_param = substream;
186 iprtd->sg_list[iprtd->sg_count - 1].length = 0; 170
187 iprtd->sg_list[iprtd->sg_count - 1].page_link =
188 ((unsigned long) iprtd->sg_list | 0x01) & ~0x02;
189 return 0; 171 return 0;
190} 172}
191 173
@@ -194,41 +176,21 @@ static int snd_imx_pcm_hw_free(struct snd_pcm_substream *substream)
194 struct snd_pcm_runtime *runtime = substream->runtime; 176 struct snd_pcm_runtime *runtime = substream->runtime;
195 struct imx_pcm_runtime_data *iprtd = runtime->private_data; 177 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
196 178
197 if (iprtd->dma >= 0) { 179 if (iprtd->dma_chan) {
198 imx_dma_free(iprtd->dma); 180 dma_release_channel(iprtd->dma_chan);
199 iprtd->dma = -EINVAL; 181 iprtd->dma_chan = NULL;
200 } 182 }
201 183
202 kfree(iprtd->sg_list);
203 iprtd->sg_list = NULL;
204
205 return 0; 184 return 0;
206} 185}
207 186
208static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream) 187static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream)
209{ 188{
210 struct snd_pcm_runtime *runtime = substream->runtime;
211 struct snd_soc_pcm_runtime *rtd = substream->private_data; 189 struct snd_soc_pcm_runtime *rtd = substream->private_data;
212 struct imx_pcm_dma_params *dma_params; 190 struct imx_pcm_dma_params *dma_params;
213 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
214 int err;
215 191
216 dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); 192 dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
217 193
218 iprtd->substream = substream;
219 iprtd->buf = (unsigned int *)substream->dma_buffer.area;
220 iprtd->period_cnt = 0;
221
222 pr_debug("%s: buf: %p period: %d periods: %d\n",
223 __func__, iprtd->buf, iprtd->period, iprtd->periods);
224
225 err = imx_dma_setup_sg(iprtd->dma, iprtd->sg_list, iprtd->sg_count,
226 IMX_DMA_LENGTH_LOOP, dma_params->dma_addr,
227 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
228 DMA_MODE_WRITE : DMA_MODE_READ);
229 if (err)
230 return err;
231
232 return 0; 194 return 0;
233} 195}
234 196
@@ -241,14 +203,14 @@ static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
241 case SNDRV_PCM_TRIGGER_START: 203 case SNDRV_PCM_TRIGGER_START:
242 case SNDRV_PCM_TRIGGER_RESUME: 204 case SNDRV_PCM_TRIGGER_RESUME:
243 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 205 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
244 imx_dma_enable(iprtd->dma); 206 dmaengine_submit(iprtd->desc);
245 207
246 break; 208 break;
247 209
248 case SNDRV_PCM_TRIGGER_STOP: 210 case SNDRV_PCM_TRIGGER_STOP:
249 case SNDRV_PCM_TRIGGER_SUSPEND: 211 case SNDRV_PCM_TRIGGER_SUSPEND:
250 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 212 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
251 imx_dma_disable(iprtd->dma); 213 dmaengine_terminate_all(iprtd->dma_chan);
252 214
253 break; 215 break;
254 default: 216 default:
@@ -263,6 +225,9 @@ static snd_pcm_uframes_t snd_imx_pcm_pointer(struct snd_pcm_substream *substream
263 struct snd_pcm_runtime *runtime = substream->runtime; 225 struct snd_pcm_runtime *runtime = substream->runtime;
264 struct imx_pcm_runtime_data *iprtd = runtime->private_data; 226 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
265 227
228 pr_debug("%s: %ld %ld\n", __func__, iprtd->offset,
229 bytes_to_frames(substream->runtime, iprtd->offset));
230
266 return bytes_to_frames(substream->runtime, iprtd->offset); 231 return bytes_to_frames(substream->runtime, iprtd->offset);
267} 232}
268 233
@@ -279,7 +244,7 @@ static struct snd_pcm_hardware snd_imx_hardware = {
279 .channels_max = 2, 244 .channels_max = 2,
280 .buffer_bytes_max = IMX_SSI_DMABUF_SIZE, 245 .buffer_bytes_max = IMX_SSI_DMABUF_SIZE,
281 .period_bytes_min = 128, 246 .period_bytes_min = 128,
282 .period_bytes_max = 16 * 1024, 247 .period_bytes_max = 65535, /* Limited by SDMA engine */
283 .periods_min = 2, 248 .periods_min = 2,
284 .periods_max = 255, 249 .periods_max = 255,
285 .fifo_size = 0, 250 .fifo_size = 0,
@@ -304,11 +269,23 @@ static int snd_imx_open(struct snd_pcm_substream *substream)
304 } 269 }
305 270
306 snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware); 271 snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
272
273 return 0;
274}
275
276static int snd_imx_close(struct snd_pcm_substream *substream)
277{
278 struct snd_pcm_runtime *runtime = substream->runtime;
279 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
280
281 kfree(iprtd);
282
307 return 0; 283 return 0;
308} 284}
309 285
310static struct snd_pcm_ops imx_pcm_ops = { 286static struct snd_pcm_ops imx_pcm_ops = {
311 .open = snd_imx_open, 287 .open = snd_imx_open,
288 .close = snd_imx_close,
312 .ioctl = snd_pcm_lib_ioctl, 289 .ioctl = snd_pcm_lib_ioctl,
313 .hw_params = snd_imx_pcm_hw_params, 290 .hw_params = snd_imx_pcm_hw_params,
314 .hw_free = snd_imx_pcm_hw_free, 291 .hw_free = snd_imx_pcm_hw_free,
@@ -340,7 +317,6 @@ static struct platform_driver imx_pcm_driver = {
340 .name = "imx-pcm-audio", 317 .name = "imx-pcm-audio",
341 .owner = THIS_MODULE, 318 .owner = THIS_MODULE,
342 }, 319 },
343
344 .probe = imx_soc_platform_probe, 320 .probe = imx_soc_platform_probe,
345 .remove = __devexit_p(imx_soc_platform_remove), 321 .remove = __devexit_p(imx_soc_platform_remove),
346}; 322};
@@ -356,4 +332,3 @@ static void __exit snd_imx_pcm_exit(void)
356 platform_driver_unregister(&imx_pcm_driver); 332 platform_driver_unregister(&imx_pcm_driver);
357} 333}
358module_exit(snd_imx_pcm_exit); 334module_exit(snd_imx_pcm_exit);
359
diff --git a/sound/soc/imx/imx-ssi.c b/sound/soc/imx/imx-ssi.c
index d4bd345b0a8d..390b6ffc2658 100644
--- a/sound/soc/imx/imx-ssi.c
+++ b/sound/soc/imx/imx-ssi.c
@@ -439,7 +439,22 @@ void imx_pcm_free(struct snd_pcm *pcm)
439} 439}
440EXPORT_SYMBOL_GPL(imx_pcm_free); 440EXPORT_SYMBOL_GPL(imx_pcm_free);
441 441
442static int imx_ssi_dai_probe(struct snd_soc_dai *dai)
443{
444 struct imx_ssi *ssi = dev_get_drvdata(dai->dev);
445 uint32_t val;
446
447 snd_soc_dai_set_drvdata(dai, ssi);
448
449 val = SSI_SFCSR_TFWM0(ssi->dma_params_tx.burstsize) |
450 SSI_SFCSR_RFWM0(ssi->dma_params_rx.burstsize);
451 writel(val, ssi->base + SSI_SFCSR);
452
453 return 0;
454}
455
442static struct snd_soc_dai_driver imx_ssi_dai = { 456static struct snd_soc_dai_driver imx_ssi_dai = {
457 .probe = imx_ssi_dai_probe,
443 .playback = { 458 .playback = {
444 .channels_min = 2, 459 .channels_min = 2,
445 .channels_max = 2, 460 .channels_max = 2,
@@ -455,20 +470,6 @@ static struct snd_soc_dai_driver imx_ssi_dai = {
455 .ops = &imx_ssi_pcm_dai_ops, 470 .ops = &imx_ssi_pcm_dai_ops,
456}; 471};
457 472
458static int imx_ssi_dai_probe(struct snd_soc_dai *dai)
459{
460 struct imx_ssi *ssi = dev_get_drvdata(dai->dev);
461 uint32_t val;
462
463 snd_soc_dai_set_drvdata(dai, ssi);
464
465 val = SSI_SFCSR_TFWM0(ssi->dma_params_tx.burstsize) |
466 SSI_SFCSR_RFWM0(ssi->dma_params_rx.burstsize);
467 writel(val, ssi->base + SSI_SFCSR);
468
469 return 0;
470}
471
472static struct snd_soc_dai_driver imx_ac97_dai = { 473static struct snd_soc_dai_driver imx_ac97_dai = {
473 .probe = imx_ssi_dai_probe, 474 .probe = imx_ssi_dai_probe,
474 .ac97_control = 1, 475 .ac97_control = 1,
@@ -677,9 +678,25 @@ static int imx_ssi_probe(struct platform_device *pdev)
677 goto failed_register; 678 goto failed_register;
678 } 679 }
679 680
680 ssi->soc_platform_pdev = platform_device_alloc("imx-fiq-pcm-audio", pdev->id); 681 ssi->soc_platform_pdev_fiq = platform_device_alloc("imx-fiq-pcm-audio", pdev->id);
681 if (!ssi->soc_platform_pdev) 682 if (!ssi->soc_platform_pdev_fiq) {
683 ret = -ENOMEM;
684 goto failed_pdev_fiq_alloc;
685 }
686
687 platform_set_drvdata(ssi->soc_platform_pdev_fiq, ssi);
688 ret = platform_device_add(ssi->soc_platform_pdev_fiq);
689 if (ret) {
690 dev_err(&pdev->dev, "failed to add platform device\n");
691 goto failed_pdev_fiq_add;
692 }
693
694 ssi->soc_platform_pdev = platform_device_alloc("imx-pcm-audio", pdev->id);
695 if (!ssi->soc_platform_pdev) {
696 ret = -ENOMEM;
682 goto failed_pdev_alloc; 697 goto failed_pdev_alloc;
698 }
699
683 platform_set_drvdata(ssi->soc_platform_pdev, ssi); 700 platform_set_drvdata(ssi->soc_platform_pdev, ssi);
684 ret = platform_device_add(ssi->soc_platform_pdev); 701 ret = platform_device_add(ssi->soc_platform_pdev);
685 if (ret) { 702 if (ret) {
@@ -692,6 +709,10 @@ static int imx_ssi_probe(struct platform_device *pdev)
692failed_pdev_add: 709failed_pdev_add:
693 platform_device_put(ssi->soc_platform_pdev); 710 platform_device_put(ssi->soc_platform_pdev);
694failed_pdev_alloc: 711failed_pdev_alloc:
712 platform_device_del(ssi->soc_platform_pdev_fiq);
713failed_pdev_fiq_add:
714 platform_device_put(ssi->soc_platform_pdev_fiq);
715failed_pdev_fiq_alloc:
695 snd_soc_unregister_dai(&pdev->dev); 716 snd_soc_unregister_dai(&pdev->dev);
696failed_register: 717failed_register:
697failed_ac97: 718failed_ac97:
@@ -712,8 +733,8 @@ static int __devexit imx_ssi_remove(struct platform_device *pdev)
712 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 733 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
713 struct imx_ssi *ssi = platform_get_drvdata(pdev); 734 struct imx_ssi *ssi = platform_get_drvdata(pdev);
714 735
715 platform_device_del(ssi->soc_platform_pdev); 736 platform_device_unregister(ssi->soc_platform_pdev);
716 platform_device_put(ssi->soc_platform_pdev); 737 platform_device_unregister(ssi->soc_platform_pdev_fiq);
717 738
718 snd_soc_unregister_dai(&pdev->dev); 739 snd_soc_unregister_dai(&pdev->dev);
719 740
diff --git a/sound/soc/imx/imx-ssi.h b/sound/soc/imx/imx-ssi.h
index 53b780d9b2b0..a4406a134892 100644
--- a/sound/soc/imx/imx-ssi.h
+++ b/sound/soc/imx/imx-ssi.h
@@ -185,6 +185,9 @@
185 185
186#define DRV_NAME "imx-ssi" 186#define DRV_NAME "imx-ssi"
187 187
188#include <linux/dmaengine.h>
189#include <mach/dma.h>
190
188struct imx_pcm_dma_params { 191struct imx_pcm_dma_params {
189 int dma; 192 int dma;
190 unsigned long dma_addr; 193 unsigned long dma_addr;
@@ -212,6 +215,7 @@ struct imx_ssi {
212 int enabled; 215 int enabled;
213 216
214 struct platform_device *soc_platform_pdev; 217 struct platform_device *soc_platform_pdev;
218 struct platform_device *soc_platform_pdev_fiq;
215}; 219};
216 220
217struct snd_soc_platform *imx_ssi_fiq_init(struct platform_device *pdev, 221struct snd_soc_platform *imx_ssi_fiq_init(struct platform_device *pdev,
diff --git a/sound/soc/imx/phycore-ac97.c b/sound/soc/imx/phycore-ac97.c
index 6a65dd705519..9eabc28667e6 100644
--- a/sound/soc/imx/phycore-ac97.c
+++ b/sound/soc/imx/phycore-ac97.c
@@ -20,9 +20,6 @@
20#include <sound/soc-dapm.h> 20#include <sound/soc-dapm.h>
21#include <asm/mach-types.h> 21#include <asm/mach-types.h>
22 22
23#include "../codecs/wm9712.h"
24#include "imx-ssi.h"
25
26static struct snd_soc_card imx_phycore; 23static struct snd_soc_card imx_phycore;
27 24
28static struct snd_soc_ops imx_phycore_hifi_ops = { 25static struct snd_soc_ops imx_phycore_hifi_ops = {
@@ -41,11 +38,12 @@ static struct snd_soc_dai_link imx_phycore_dai_ac97[] = {
41}; 38};
42 39
43static struct snd_soc_card imx_phycore = { 40static struct snd_soc_card imx_phycore = {
44 .name = "PhyCORE-audio", 41 .name = "PhyCORE-ac97-audio",
45 .dai_link = imx_phycore_dai_ac97, 42 .dai_link = imx_phycore_dai_ac97,
46 .num_links = ARRAY_SIZE(imx_phycore_dai_ac97), 43 .num_links = ARRAY_SIZE(imx_phycore_dai_ac97),
47}; 44};
48 45
46static struct platform_device *imx_phycore_snd_ac97_device;
49static struct platform_device *imx_phycore_snd_device; 47static struct platform_device *imx_phycore_snd_device;
50 48
51static int __init imx_phycore_init(void) 49static int __init imx_phycore_init(void)
@@ -56,29 +54,42 @@ static int __init imx_phycore_init(void)
56 /* return happy. We might run on a totally different machine */ 54 /* return happy. We might run on a totally different machine */
57 return 0; 55 return 0;
58 56
59 imx_phycore_snd_device = platform_device_alloc("soc-audio", -1); 57 imx_phycore_snd_ac97_device = platform_device_alloc("soc-audio", -1);
60 if (!imx_phycore_snd_device) 58 if (!imx_phycore_snd_ac97_device)
61 return -ENOMEM; 59 return -ENOMEM;
62 60
63 platform_set_drvdata(imx_phycore_snd_device, &imx_phycore); 61 platform_set_drvdata(imx_phycore_snd_ac97_device, &imx_phycore);
64 ret = platform_device_add(imx_phycore_snd_device); 62 ret = platform_device_add(imx_phycore_snd_ac97_device);
63 if (ret)
64 goto fail1;
65 65
66 imx_phycore_snd_device = platform_device_alloc("wm9712-codec", -1); 66 imx_phycore_snd_device = platform_device_alloc("wm9712-codec", -1);
67 if (!imx_phycore_snd_device) 67 if (!imx_phycore_snd_device) {
68 return -ENOMEM; 68 ret = -ENOMEM;
69 goto fail2;
70 }
69 ret = platform_device_add(imx_phycore_snd_device); 71 ret = platform_device_add(imx_phycore_snd_device);
70 72
71 if (ret) { 73 if (ret) {
72 printk(KERN_ERR "ASoC: Platform device allocation failed\n"); 74 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
73 platform_device_put(imx_phycore_snd_device); 75 goto fail3;
74 } 76 }
75 77
78 return 0;
79
80fail3:
81 platform_device_put(imx_phycore_snd_device);
82fail2:
83 platform_device_del(imx_phycore_snd_ac97_device);
84fail1:
85 platform_device_put(imx_phycore_snd_ac97_device);
76 return ret; 86 return ret;
77} 87}
78 88
79static void __exit imx_phycore_exit(void) 89static void __exit imx_phycore_exit(void)
80{ 90{
81 platform_device_unregister(imx_phycore_snd_device); 91 platform_device_unregister(imx_phycore_snd_device);
92 platform_device_unregister(imx_phycore_snd_ac97_device);
82} 93}
83 94
84late_initcall(imx_phycore_init); 95late_initcall(imx_phycore_init);
diff --git a/sound/soc/nuc900/nuc900-ac97.c b/sound/soc/nuc900/nuc900-ac97.c
index 293dc748797c..dac6732da969 100644
--- a/sound/soc/nuc900/nuc900-ac97.c
+++ b/sound/soc/nuc900/nuc900-ac97.c
@@ -49,7 +49,7 @@ static unsigned short nuc900_ac97_read(struct snd_ac97 *ac97,
49 mutex_lock(&ac97_mutex); 49 mutex_lock(&ac97_mutex);
50 50
51 val = nuc900_checkready(); 51 val = nuc900_checkready();
52 if (!!val) { 52 if (val) {
53 dev_err(nuc900_audio->dev, "AC97 codec is not ready\n"); 53 dev_err(nuc900_audio->dev, "AC97 codec is not ready\n");
54 goto out; 54 goto out;
55 } 55 }
@@ -102,7 +102,7 @@ static void nuc900_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
102 mutex_lock(&ac97_mutex); 102 mutex_lock(&ac97_mutex);
103 103
104 tmp = nuc900_checkready(); 104 tmp = nuc900_checkready();
105 if (!!tmp) 105 if (tmp)
106 dev_err(nuc900_audio->dev, "AC97 codec is not ready\n"); 106 dev_err(nuc900_audio->dev, "AC97 codec is not ready\n");
107 107
108 /* clear the R_WB bit and write register index */ 108 /* clear the R_WB bit and write register index */
@@ -149,7 +149,7 @@ static void nuc900_ac97_warm_reset(struct snd_ac97 *ac97)
149 udelay(100); 149 udelay(100);
150 150
151 val = nuc900_checkready(); 151 val = nuc900_checkready();
152 if (!!val) 152 if (val)
153 dev_err(nuc900_audio->dev, "AC97 codec is not ready\n"); 153 dev_err(nuc900_audio->dev, "AC97 codec is not ready\n");
154 154
155 mutex_unlock(&ac97_mutex); 155 mutex_unlock(&ac97_mutex);
@@ -263,8 +263,7 @@ static int nuc900_ac97_trigger(struct snd_pcm_substream *substream,
263 return ret; 263 return ret;
264} 264}
265 265
266static int nuc900_ac97_probe(struct platform_device *pdev, 266static int nuc900_ac97_probe(struct snd_soc_dai *dai)
267 struct snd_soc_dai *dai)
268{ 267{
269 struct nuc900_audio *nuc900_audio = nuc900_ac97_data; 268 struct nuc900_audio *nuc900_audio = nuc900_ac97_data;
270 unsigned long val; 269 unsigned long val;
@@ -284,12 +283,12 @@ static int nuc900_ac97_probe(struct platform_device *pdev,
284 return 0; 283 return 0;
285} 284}
286 285
287static void nuc900_ac97_remove(struct platform_device *pdev, 286static int nuc900_ac97_remove(struct snd_soc_dai *dai)
288 struct snd_soc_dai *dai)
289{ 287{
290 struct nuc900_audio *nuc900_audio = nuc900_ac97_data; 288 struct nuc900_audio *nuc900_audio = nuc900_ac97_data;
291 289
292 clk_disable(nuc900_audio->clk); 290 clk_disable(nuc900_audio->clk);
291 return 0;
293} 292}
294 293
295static struct snd_soc_dai_ops nuc900_ac97_dai_ops = { 294static struct snd_soc_dai_ops nuc900_ac97_dai_ops = {
@@ -313,7 +312,7 @@ static struct snd_soc_dai_driver nuc900_ac97_dai = {
313 .channels_max = 2, 312 .channels_max = 2,
314 }, 313 },
315 .ops = &nuc900_ac97_dai_ops, 314 .ops = &nuc900_ac97_dai_ops,
316} 315};
317 316
318static int __devinit nuc900_ac97_drvprobe(struct platform_device *pdev) 317static int __devinit nuc900_ac97_drvprobe(struct platform_device *pdev)
319{ 318{
@@ -384,7 +383,6 @@ out0:
384 383
385static int __devexit nuc900_ac97_drvremove(struct platform_device *pdev) 384static int __devexit nuc900_ac97_drvremove(struct platform_device *pdev)
386{ 385{
387
388 snd_soc_unregister_dai(&pdev->dev); 386 snd_soc_unregister_dai(&pdev->dev);
389 387
390 clk_put(nuc900_ac97_data->clk); 388 clk_put(nuc900_ac97_data->clk);
@@ -392,6 +390,7 @@ static int __devexit nuc900_ac97_drvremove(struct platform_device *pdev)
392 release_mem_region(nuc900_ac97_data->res->start, 390 release_mem_region(nuc900_ac97_data->res->start,
393 resource_size(nuc900_ac97_data->res)); 391 resource_size(nuc900_ac97_data->res));
394 392
393 kfree(nuc900_ac97_data);
395 nuc900_ac97_data = NULL; 394 nuc900_ac97_data = NULL;
396 395
397 return 0; 396 return 0;
diff --git a/sound/soc/nuc900/nuc900-audio.h b/sound/soc/nuc900/nuc900-audio.h
index aeed8ead2b2b..59f7e8ed1a68 100644
--- a/sound/soc/nuc900/nuc900-audio.h
+++ b/sound/soc/nuc900/nuc900-audio.h
@@ -110,4 +110,6 @@ struct nuc900_audio {
110 110
111}; 111};
112 112
113extern struct nuc900_audio *nuc900_ac97_data;
114
113#endif /*end _NUC900_AUDIO_H */ 115#endif /*end _NUC900_AUDIO_H */
diff --git a/sound/soc/nuc900/nuc900-pcm.c b/sound/soc/nuc900/nuc900-pcm.c
index 195d1ac94771..8263f56dc665 100644
--- a/sound/soc/nuc900/nuc900-pcm.c
+++ b/sound/soc/nuc900/nuc900-pcm.c
@@ -50,12 +50,12 @@ static int nuc900_dma_hw_params(struct snd_pcm_substream *substream,
50 unsigned long flags; 50 unsigned long flags;
51 int ret = 0; 51 int ret = 0;
52 52
53 spin_lock_irqsave(&nuc900_audio->lock, flags);
54
55 ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); 53 ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
56 if (ret < 0) 54 if (ret < 0)
57 return ret; 55 return ret;
58 56
57 spin_lock_irqsave(&nuc900_audio->lock, flags);
58
59 nuc900_audio->substream = substream; 59 nuc900_audio->substream = substream;
60 nuc900_audio->dma_addr[substream->stream] = runtime->dma_addr; 60 nuc900_audio->dma_addr[substream->stream] = runtime->dma_addr;
61 nuc900_audio->buffersize[substream->stream] = 61 nuc900_audio->buffersize[substream->stream] =
@@ -169,6 +169,7 @@ static int nuc900_dma_prepare(struct snd_pcm_substream *substream)
169 struct snd_pcm_runtime *runtime = substream->runtime; 169 struct snd_pcm_runtime *runtime = substream->runtime;
170 struct nuc900_audio *nuc900_audio = runtime->private_data; 170 struct nuc900_audio *nuc900_audio = runtime->private_data;
171 unsigned long flags, val; 171 unsigned long flags, val;
172 int ret = 0;
172 173
173 spin_lock_irqsave(&nuc900_audio->lock, flags); 174 spin_lock_irqsave(&nuc900_audio->lock, flags);
174 175
@@ -197,10 +198,10 @@ static int nuc900_dma_prepare(struct snd_pcm_substream *substream)
197 AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); 198 AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val);
198 break; 199 break;
199 default: 200 default:
200 return -EINVAL; 201 ret = -EINVAL;
201 } 202 }
202 spin_unlock_irqrestore(&nuc900_audio->lock, flags); 203 spin_unlock_irqrestore(&nuc900_audio->lock, flags);
203 return 0; 204 return ret;
204} 205}
205 206
206static int nuc900_dma_trigger(struct snd_pcm_substream *substream, int cmd) 207static int nuc900_dma_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -332,7 +333,7 @@ static struct snd_soc_platform_driver nuc900_soc_platform = {
332 .ops = &nuc900_dma_ops, 333 .ops = &nuc900_dma_ops,
333 .pcm_new = nuc900_dma_new, 334 .pcm_new = nuc900_dma_new,
334 .pcm_free = nuc900_dma_free_dma_buffers, 335 .pcm_free = nuc900_dma_free_dma_buffers,
335} 336};
336 337
337static int __devinit nuc900_soc_platform_probe(struct platform_device *pdev) 338static int __devinit nuc900_soc_platform_probe(struct platform_device *pdev)
338{ 339{
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index d542ea2ff6be..a088db6d5091 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -12,8 +12,8 @@ config SND_OMAP_SOC_MCPDM
12config SND_OMAP_SOC_N810 12config SND_OMAP_SOC_N810
13 tristate "SoC Audio support for Nokia N810" 13 tristate "SoC Audio support for Nokia N810"
14 depends on SND_OMAP_SOC && MACH_NOKIA_N810 && I2C 14 depends on SND_OMAP_SOC && MACH_NOKIA_N810 && I2C
15 depends on OMAP_MUX
15 select SND_OMAP_SOC_MCBSP 16 select SND_OMAP_SOC_MCBSP
16 select OMAP_MUX
17 select SND_SOC_TLV320AIC3X 17 select SND_SOC_TLV320AIC3X
18 help 18 help
19 Say Y if you want to add support for SoC audio on Nokia N810. 19 Say Y if you want to add support for SoC audio on Nokia N810.
diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c
index d211c9fa5a91..7e84f24b9a88 100644
--- a/sound/soc/omap/omap-mcbsp.c
+++ b/sound/soc/omap/omap-mcbsp.c
@@ -644,15 +644,23 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
644 644
645 645
646 case OMAP_MCBSP_CLKR_SRC_CLKR: 646 case OMAP_MCBSP_CLKR_SRC_CLKR:
647 if (cpu_class_is_omap1())
648 break;
647 omap2_mcbsp1_mux_clkr_src(CLKR_SRC_CLKR); 649 omap2_mcbsp1_mux_clkr_src(CLKR_SRC_CLKR);
648 break; 650 break;
649 case OMAP_MCBSP_CLKR_SRC_CLKX: 651 case OMAP_MCBSP_CLKR_SRC_CLKX:
652 if (cpu_class_is_omap1())
653 break;
650 omap2_mcbsp1_mux_clkr_src(CLKR_SRC_CLKX); 654 omap2_mcbsp1_mux_clkr_src(CLKR_SRC_CLKX);
651 break; 655 break;
652 case OMAP_MCBSP_FSR_SRC_FSR: 656 case OMAP_MCBSP_FSR_SRC_FSR:
657 if (cpu_class_is_omap1())
658 break;
653 omap2_mcbsp1_mux_fsr_src(FSR_SRC_FSR); 659 omap2_mcbsp1_mux_fsr_src(FSR_SRC_FSR);
654 break; 660 break;
655 case OMAP_MCBSP_FSR_SRC_FSX: 661 case OMAP_MCBSP_FSR_SRC_FSX:
662 if (cpu_class_is_omap1())
663 break;
656 omap2_mcbsp1_mux_fsr_src(FSR_SRC_FSX); 664 omap2_mcbsp1_mux_fsr_src(FSR_SRC_FSX);
657 break; 665 break;
658 default: 666 default:
diff --git a/sound/soc/omap/omap3pandora.c b/sound/soc/omap/omap3pandora.c
index dbd9d96b5f92..4ee33ce2cb98 100644
--- a/sound/soc/omap/omap3pandora.c
+++ b/sound/soc/omap/omap3pandora.c
@@ -306,6 +306,7 @@ static int __init omap3pandora_soc_init(void)
306 pr_err(PREFIX "Failed to get DAC regulator from %s: %ld\n", 306 pr_err(PREFIX "Failed to get DAC regulator from %s: %ld\n",
307 dev_name(&omap3pandora_snd_device->dev), 307 dev_name(&omap3pandora_snd_device->dev),
308 PTR_ERR(omap3pandora_dac_reg)); 308 PTR_ERR(omap3pandora_dac_reg));
309 ret = PTR_ERR(omap3pandora_dac_reg);
309 goto fail3; 310 goto fail3;
310 } 311 }
311 312
diff --git a/sound/soc/omap/osk5912.c b/sound/soc/omap/osk5912.c
index f0e662556428..65ae00e976ef 100644
--- a/sound/soc/omap/osk5912.c
+++ b/sound/soc/omap/osk5912.c
@@ -177,7 +177,8 @@ static int __init osk_soc_init(void)
177 tlv320aic23_mclk = clk_get(dev, "mclk"); 177 tlv320aic23_mclk = clk_get(dev, "mclk");
178 if (IS_ERR(tlv320aic23_mclk)) { 178 if (IS_ERR(tlv320aic23_mclk)) {
179 printk(KERN_ERR "Could not get mclk clock\n"); 179 printk(KERN_ERR "Could not get mclk clock\n");
180 return -ENODEV; 180 err = PTR_ERR(tlv320aic23_mclk);
181 goto err2;
181 } 182 }
182 183
183 /* 184 /*
@@ -188,7 +189,7 @@ static int __init osk_soc_init(void)
188 if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) { 189 if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) {
189 printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n"); 190 printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n");
190 err = -ECANCELED; 191 err = -ECANCELED;
191 goto err1; 192 goto err3;
192 } 193 }
193 } 194 }
194 195
@@ -196,9 +197,12 @@ static int __init osk_soc_init(void)
196 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK); 197 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
197 198
198 return 0; 199 return 0;
199err1: 200
201err3:
200 clk_put(tlv320aic23_mclk); 202 clk_put(tlv320aic23_mclk);
203err2:
201 platform_device_del(osk_snd_device); 204 platform_device_del(osk_snd_device);
205err1:
202 platform_device_put(osk_snd_device); 206 platform_device_put(osk_snd_device);
203 207
204 return err; 208 return err;
@@ -207,6 +211,7 @@ err1:
207 211
208static void __exit osk_soc_exit(void) 212static void __exit osk_soc_exit(void)
209{ 213{
214 clk_put(tlv320aic23_mclk);
210 platform_device_unregister(osk_snd_device); 215 platform_device_unregister(osk_snd_device);
211} 216}
212 217
diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig
index 37f191bbfdd9..580f48571303 100644
--- a/sound/soc/pxa/Kconfig
+++ b/sound/soc/pxa/Kconfig
@@ -1,6 +1,7 @@
1config SND_PXA2XX_SOC 1config SND_PXA2XX_SOC
2 tristate "SoC Audio for the Intel PXA2xx chip" 2 tristate "SoC Audio for the Intel PXA2xx chip"
3 depends on ARCH_PXA 3 depends on ARCH_PXA
4 select SND_ARM
4 select SND_PXA2XX_LIB 5 select SND_PXA2XX_LIB
5 help 6 help
6 Say Y or M if you want to add support for codecs attached to 7 Say Y or M if you want to add support for codecs attached to
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index 97e9423615c9..f451acd4935b 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -100,8 +100,13 @@ static int corgi_startup(struct snd_pcm_substream *substream)
100 struct snd_soc_pcm_runtime *rtd = substream->private_data; 100 struct snd_soc_pcm_runtime *rtd = substream->private_data;
101 struct snd_soc_codec *codec = rtd->codec; 101 struct snd_soc_codec *codec = rtd->codec;
102 102
103 mutex_lock(&codec->mutex);
104
103 /* check the jack status at stream startup */ 105 /* check the jack status at stream startup */
104 corgi_ext_control(codec); 106 corgi_ext_control(codec);
107
108 mutex_unlock(&codec->mutex);
109
105 return 0; 110 return 0;
106} 111}
107 112
diff --git a/sound/soc/pxa/magician.c b/sound/soc/pxa/magician.c
index b8207ced4072..5ef0526924b9 100644
--- a/sound/soc/pxa/magician.c
+++ b/sound/soc/pxa/magician.c
@@ -72,9 +72,13 @@ static int magician_startup(struct snd_pcm_substream *substream)
72 struct snd_soc_pcm_runtime *rtd = substream->private_data; 72 struct snd_soc_pcm_runtime *rtd = substream->private_data;
73 struct snd_soc_codec *codec = rtd->codec; 73 struct snd_soc_codec *codec = rtd->codec;
74 74
75 mutex_lock(&codec->mutex);
76
75 /* check the jack status at stream startup */ 77 /* check the jack status at stream startup */
76 magician_ext_control(codec); 78 magician_ext_control(codec);
77 79
80 mutex_unlock(&codec->mutex);
81
78 return 0; 82 return 0;
79} 83}
80 84
diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c
index af84ee9c5e11..84edd0385a21 100644
--- a/sound/soc/pxa/poodle.c
+++ b/sound/soc/pxa/poodle.c
@@ -77,8 +77,13 @@ static int poodle_startup(struct snd_pcm_substream *substream)
77 struct snd_soc_pcm_runtime *rtd = substream->private_data; 77 struct snd_soc_pcm_runtime *rtd = substream->private_data;
78 struct snd_soc_codec *codec = rtd->codec; 78 struct snd_soc_codec *codec = rtd->codec;
79 79
80 mutex_lock(&codec->mutex);
81
80 /* check the jack status at stream startup */ 82 /* check the jack status at stream startup */
81 poodle_ext_control(codec); 83 poodle_ext_control(codec);
84
85 mutex_unlock(&codec->mutex);
86
82 return 0; 87 return 0;
83} 88}
84 89
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index f470f360f4dd..0b30d7de24ec 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -108,8 +108,13 @@ static int spitz_startup(struct snd_pcm_substream *substream)
108 struct snd_soc_pcm_runtime *rtd = substream->private_data; 108 struct snd_soc_pcm_runtime *rtd = substream->private_data;
109 struct snd_soc_codec *codec = rtd->codec; 109 struct snd_soc_codec *codec = rtd->codec;
110 110
111 mutex_lock(&codec->mutex);
112
111 /* check the jack status at stream startup */ 113 /* check the jack status at stream startup */
112 spitz_ext_control(codec); 114 spitz_ext_control(codec);
115
116 mutex_unlock(&codec->mutex);
117
113 return 0; 118 return 0;
114} 119}
115 120
diff --git a/sound/soc/pxa/tosa.c b/sound/soc/pxa/tosa.c
index a3bfb2e8b70f..7b983f935454 100644
--- a/sound/soc/pxa/tosa.c
+++ b/sound/soc/pxa/tosa.c
@@ -79,10 +79,15 @@ static void tosa_ext_control(struct snd_soc_codec *codec)
79static int tosa_startup(struct snd_pcm_substream *substream) 79static int tosa_startup(struct snd_pcm_substream *substream)
80{ 80{
81 struct snd_soc_pcm_runtime *rtd = substream->private_data; 81 struct snd_soc_pcm_runtime *rtd = substream->private_data;
82 struct snd_soc_codec *codec = rtd->card->codec; 82 struct snd_soc_codec *codec = rtd->codec;
83
84 mutex_lock(&codec->mutex);
83 85
84 /* check the jack status at stream startup */ 86 /* check the jack status at stream startup */
85 tosa_ext_control(codec); 87 tosa_ext_control(codec);
88
89 mutex_unlock(&codec->mutex);
90
86 return 0; 91 return 0;
87} 92}
88 93
diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig
index 8a6b53ccd203..d85bf8a0abb2 100644
--- a/sound/soc/s3c24xx/Kconfig
+++ b/sound/soc/s3c24xx/Kconfig
@@ -2,6 +2,7 @@ config SND_S3C24XX_SOC
2 tristate "SoC Audio for the Samsung S3CXXXX chips" 2 tristate "SoC Audio for the Samsung S3CXXXX chips"
3 depends on ARCH_S3C2410 || ARCH_S3C64XX || ARCH_S5PC100 || ARCH_S5PV210 3 depends on ARCH_S3C2410 || ARCH_S3C64XX || ARCH_S5PC100 || ARCH_S5PV210
4 select S3C64XX_DMA if ARCH_S3C64XX 4 select S3C64XX_DMA if ARCH_S3C64XX
5 select S3C2410_DMA if ARCH_S3C2410
5 help 6 help
6 Say Y or M if you want to add support for codecs attached to 7 Say Y or M if you want to add support for codecs attached to
7 the S3C24XX AC97 or I2S interfaces. You will also need to 8 the S3C24XX AC97 or I2S interfaces. You will also need to
diff --git a/sound/soc/s3c24xx/rx1950_uda1380.c b/sound/soc/s3c24xx/rx1950_uda1380.c
index ffd5cf2fb0a9..468cc11fdf47 100644
--- a/sound/soc/s3c24xx/rx1950_uda1380.c
+++ b/sound/soc/s3c24xx/rx1950_uda1380.c
@@ -50,7 +50,6 @@ static unsigned int rates[] = {
50 16000, 50 16000,
51 44100, 51 44100,
52 48000, 52 48000,
53 88200,
54}; 53};
55 54
56static struct snd_pcm_hw_constraint_list hw_rates = { 55static struct snd_pcm_hw_constraint_list hw_rates = {
@@ -130,7 +129,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
130}; 129};
131 130
132static struct platform_device *s3c24xx_snd_device; 131static struct platform_device *s3c24xx_snd_device;
133static struct clk *xtal;
134 132
135static int rx1950_startup(struct snd_pcm_substream *substream) 133static int rx1950_startup(struct snd_pcm_substream *substream)
136{ 134{
@@ -179,10 +177,8 @@ static int rx1950_hw_params(struct snd_pcm_substream *substream,
179 case 44100: 177 case 44100:
180 case 88200: 178 case 88200:
181 clk_source = S3C24XX_CLKSRC_MPLL; 179 clk_source = S3C24XX_CLKSRC_MPLL;
182 fs_mode = S3C2410_IISMOD_256FS; 180 fs_mode = S3C2410_IISMOD_384FS;
183 div = clk_get_rate(xtal) / (256 * rate); 181 div = 1;
184 if (clk_get_rate(xtal) % (256 * rate) > (128 * rate))
185 div++;
186 break; 182 break;
187 default: 183 default:
188 printk(KERN_ERR "%s: rate %d is not supported\n", 184 printk(KERN_ERR "%s: rate %d is not supported\n",
@@ -210,7 +206,7 @@ static int rx1950_hw_params(struct snd_pcm_substream *substream,
210 206
211 /* set MCLK division for sample rate */ 207 /* set MCLK division for sample rate */
212 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK, 208 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
213 S3C2410_IISMOD_384FS); 209 fs_mode);
214 if (ret < 0) 210 if (ret < 0)
215 return ret; 211 return ret;
216 212
@@ -295,17 +291,8 @@ static int __init rx1950_init(void)
295 goto err_plat_add; 291 goto err_plat_add;
296 } 292 }
297 293
298 xtal = clk_get(&s3c24xx_snd_device->dev, "xtal");
299
300 if (IS_ERR(xtal)) {
301 ret = PTR_ERR(xtal);
302 platform_device_unregister(s3c24xx_snd_device);
303 goto err_clk;
304 }
305
306 return 0; 294 return 0;
307 295
308err_clk:
309err_plat_add: 296err_plat_add:
310err_plat_alloc: 297err_plat_alloc:
311err_gpio_conf: 298err_gpio_conf:
@@ -320,7 +307,6 @@ static void __exit rx1950_exit(void)
320 platform_device_unregister(s3c24xx_snd_device); 307 platform_device_unregister(s3c24xx_snd_device);
321 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios), 308 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
322 hp_jack_gpios); 309 hp_jack_gpios);
323 clk_put(xtal);
324 gpio_free(S3C2410_GPA(1)); 310 gpio_free(S3C2410_GPA(1));
325} 311}
326 312
diff --git a/sound/soc/s3c24xx/smdk_spdif.c b/sound/soc/s3c24xx/smdk_spdif.c
index 11c88b13dd2e..761e02b4a6e0 100644
--- a/sound/soc/s3c24xx/smdk_spdif.c
+++ b/sound/soc/s3c24xx/smdk_spdif.c
@@ -38,7 +38,7 @@ static int set_audio_clock_heirachy(struct platform_device *pdev)
38 } 38 }
39 39
40 mout_epll = clk_get(NULL, "mout_epll"); 40 mout_epll = clk_get(NULL, "mout_epll");
41 if (IS_ERR(fout_epll)) { 41 if (IS_ERR(mout_epll)) {
42 printk(KERN_WARNING "%s: Cannot find mout_epll.\n", 42 printk(KERN_WARNING "%s: Cannot find mout_epll.\n",
43 __func__); 43 __func__);
44 ret = -EINVAL; 44 ret = -EINVAL;
@@ -54,7 +54,7 @@ static int set_audio_clock_heirachy(struct platform_device *pdev)
54 } 54 }
55 55
56 sclk_spdif = clk_get(NULL, "sclk_spdif"); 56 sclk_spdif = clk_get(NULL, "sclk_spdif");
57 if (IS_ERR(fout_epll)) { 57 if (IS_ERR(sclk_spdif)) {
58 printk(KERN_WARNING "%s: Cannot find sclk_spdif.\n", 58 printk(KERN_WARNING "%s: Cannot find sclk_spdif.\n",
59 __func__); 59 __func__);
60 ret = -EINVAL; 60 ret = -EINVAL;
diff --git a/sound/soc/s6000/s6000-i2s.c b/sound/soc/s6000/s6000-i2s.c
index 8778faa174a6..3052f64b2403 100644
--- a/sound/soc/s6000/s6000-i2s.c
+++ b/sound/soc/s6000/s6000-i2s.c
@@ -434,7 +434,7 @@ static struct snd_soc_dai_driver s6000_i2s_dai = {
434 .rate_max = 1562500, 434 .rate_max = 1562500,
435 }, 435 },
436 .ops = &s6000_i2s_dai_ops, 436 .ops = &s6000_i2s_dai_ops,
437} 437};
438 438
439static int __devinit s6000_i2s_probe(struct platform_device *pdev) 439static int __devinit s6000_i2s_probe(struct platform_device *pdev)
440{ 440{
diff --git a/sound/soc/s6000/s6000-pcm.c b/sound/soc/s6000/s6000-pcm.c
index 271fd222bf19..ab3ccaec72d2 100644
--- a/sound/soc/s6000/s6000-pcm.c
+++ b/sound/soc/s6000/s6000-pcm.c
@@ -473,7 +473,7 @@ static int s6000_pcm_new(struct snd_card *card,
473 } 473 }
474 474
475 res = request_irq(params->irq, s6000_pcm_irq, IRQF_SHARED, 475 res = request_irq(params->irq, s6000_pcm_irq, IRQF_SHARED,
476 s6000_soc_platform.name, pcm); 476 "s6000-audio", pcm);
477 if (res) { 477 if (res) {
478 printk(KERN_ERR "s6000-pcm couldn't get IRQ\n"); 478 printk(KERN_ERR "s6000-pcm couldn't get IRQ\n");
479 return res; 479 return res;
diff --git a/sound/soc/s6000/s6105-ipcam.c b/sound/soc/s6000/s6105-ipcam.c
index 96c05e137538..c1244c5bc730 100644
--- a/sound/soc/s6000/s6105-ipcam.c
+++ b/sound/soc/s6000/s6105-ipcam.c
@@ -167,7 +167,7 @@ static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd)
167 167
168 snd_soc_dapm_sync(codec); 168 snd_soc_dapm_sync(codec);
169 169
170 snd_ctl_add(codec->snd_card, snd_ctl_new1(&audio_out_mux, codec)); 170 snd_ctl_add(codec->card->snd_card, snd_ctl_new1(&audio_out_mux, codec));
171 171
172 return 0; 172 return 0;
173} 173}
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 507e709f2807..4c2404b1b862 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -132,6 +132,8 @@ struct fsi_priv {
132 struct fsi_stream playback; 132 struct fsi_stream playback;
133 struct fsi_stream capture; 133 struct fsi_stream capture;
134 134
135 long rate;
136
135 u32 mst_ctrl; 137 u32 mst_ctrl;
136}; 138};
137 139
@@ -854,10 +856,17 @@ static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
854{ 856{
855 struct fsi_priv *fsi = fsi_get_priv(substream); 857 struct fsi_priv *fsi = fsi_get_priv(substream);
856 int is_play = fsi_is_play(substream); 858 int is_play = fsi_is_play(substream);
859 struct fsi_master *master = fsi_get_master(fsi);
860 int (*set_rate)(struct device *dev, int is_porta, int rate, int enable);
857 861
858 fsi_irq_disable(fsi, is_play); 862 fsi_irq_disable(fsi, is_play);
859 fsi_clk_ctrl(fsi, 0); 863 fsi_clk_ctrl(fsi, 0);
860 864
865 set_rate = master->info->set_rate;
866 if (set_rate && fsi->rate)
867 set_rate(dai->dev, fsi_is_port_a(fsi), fsi->rate, 0);
868 fsi->rate = 0;
869
861 pm_runtime_put_sync(dai->dev); 870 pm_runtime_put_sync(dai->dev);
862} 871}
863 872
@@ -891,20 +900,20 @@ static int fsi_dai_hw_params(struct snd_pcm_substream *substream,
891{ 900{
892 struct fsi_priv *fsi = fsi_get_priv(substream); 901 struct fsi_priv *fsi = fsi_get_priv(substream);
893 struct fsi_master *master = fsi_get_master(fsi); 902 struct fsi_master *master = fsi_get_master(fsi);
894 int (*set_rate)(int is_porta, int rate) = master->info->set_rate; 903 int (*set_rate)(struct device *dev, int is_porta, int rate, int enable);
895 int fsi_ver = master->core->ver; 904 int fsi_ver = master->core->ver;
896 int is_play = fsi_is_play(substream); 905 long rate = params_rate(params);
897 int ret; 906 int ret;
898 907
899 /* if slave mode, set_rate is not needed */ 908 set_rate = master->info->set_rate;
900 if (!fsi_is_master_mode(fsi, is_play)) 909 if (!set_rate)
901 return 0; 910 return 0;
902 911
903 /* it is error if no set_rate */ 912 ret = set_rate(dai->dev, fsi_is_port_a(fsi), rate, 1);
904 if (!set_rate) 913 if (ret < 0) /* error */
905 return -EIO; 914 return ret;
906 915
907 ret = set_rate(fsi_is_port_a(fsi), params_rate(params)); 916 fsi->rate = rate;
908 if (ret > 0) { 917 if (ret > 0) {
909 u32 data = 0; 918 u32 data = 0;
910 919
diff --git a/sound/soc/sh/ssi.c b/sound/soc/sh/ssi.c
index 40bbdf1591dc..05192d97b377 100644
--- a/sound/soc/sh/ssi.c
+++ b/sound/soc/sh/ssi.c
@@ -387,7 +387,7 @@ static int __devinit sh4_soc_dai_probe(struct platform_device *pdev)
387 387
388static int __devexit sh4_soc_dai_remove(struct platform_device *pdev) 388static int __devexit sh4_soc_dai_remove(struct platform_device *pdev)
389{ 389{
390 snd_soc_unregister_dai(&pdev->dev, ARRAY_SIZE(sh4_ssi_dai)); 390 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(sh4_ssi_dai));
391 return 0; 391 return 0;
392} 392}
393 393
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 1c8f3f507f54..85b7d548f167 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -165,8 +165,11 @@ static ssize_t pmdown_time_set(struct device *dev,
165{ 165{
166 struct snd_soc_pcm_runtime *rtd = 166 struct snd_soc_pcm_runtime *rtd =
167 container_of(dev, struct snd_soc_pcm_runtime, dev); 167 container_of(dev, struct snd_soc_pcm_runtime, dev);
168 int ret;
168 169
169 strict_strtol(buf, 10, &rtd->pmdown_time); 170 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
171 if (ret)
172 return ret;
170 173
171 return count; 174 return count;
172} 175}
@@ -1616,12 +1619,14 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1616#ifdef CONFIG_SND_SOC_AC97_BUS 1619#ifdef CONFIG_SND_SOC_AC97_BUS
1617 /* register any AC97 codecs */ 1620 /* register any AC97 codecs */
1618 for (i = 0; i < card->num_rtd; i++) { 1621 for (i = 0; i < card->num_rtd; i++) {
1619 ret = soc_register_ac97_dai_link(&card->rtd[i]); 1622 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1620 if (ret < 0) { 1623 if (ret < 0) {
1621 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name); 1624 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1622 goto probe_dai_err; 1625 while (--i >= 0)
1623 } 1626 soc_unregister_ac97_dai_link(&card->rtd[i]);
1627 goto probe_dai_err;
1624 } 1628 }
1629 }
1625#endif 1630#endif
1626 1631
1627 card->instantiated = 1; 1632 card->instantiated = 1;
@@ -3040,8 +3045,10 @@ int snd_soc_register_dais(struct device *dev,
3040 for (i = 0; i < count; i++) { 3045 for (i = 0; i < count; i++) {
3041 3046
3042 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 3047 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3043 if (dai == NULL) 3048 if (dai == NULL) {
3044 return -ENOMEM; 3049 ret = -ENOMEM;
3050 goto err;
3051 }
3045 3052
3046 /* create DAI component name */ 3053 /* create DAI component name */
3047 dai->name = fmt_multiple_name(dev, &dai_drv[i]); 3054 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
@@ -3067,7 +3074,9 @@ int snd_soc_register_dais(struct device *dev,
3067 pr_debug("Registered DAI '%s'\n", dai->name); 3074 pr_debug("Registered DAI '%s'\n", dai->name);
3068 } 3075 }
3069 3076
3077 mutex_lock(&client_mutex);
3070 snd_soc_instantiate_cards(); 3078 snd_soc_instantiate_cards();
3079 mutex_unlock(&client_mutex);
3071 return 0; 3080 return 0;
3072 3081
3073err: 3082err:
@@ -3260,9 +3269,6 @@ int snd_soc_register_codec(struct device *dev,
3260 return 0; 3269 return 0;
3261 3270
3262error: 3271error:
3263 for (i--; i >= 0; i--)
3264 snd_soc_unregister_dai(dev);
3265
3266 if (codec->reg_cache) 3272 if (codec->reg_cache)
3267 kfree(codec->reg_cache); 3273 kfree(codec->reg_cache);
3268 kfree(codec->name); 3274 kfree(codec->name);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 7d85c6496afa..c721502833bc 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -683,12 +683,12 @@ static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
683 struct snd_soc_dapm_widget *b, 683 struct snd_soc_dapm_widget *b,
684 int sort[]) 684 int sort[])
685{ 685{
686 if (a->codec != b->codec)
687 return (unsigned long)a - (unsigned long)b;
688 if (sort[a->id] != sort[b->id]) 686 if (sort[a->id] != sort[b->id])
689 return sort[a->id] - sort[b->id]; 687 return sort[a->id] - sort[b->id];
690 if (a->reg != b->reg) 688 if (a->reg != b->reg)
691 return a->reg - b->reg; 689 return a->reg - b->reg;
690 if (a->codec != b->codec)
691 return (unsigned long)a->codec - (unsigned long)b->codec;
692 692
693 return 0; 693 return 0;
694} 694}
@@ -944,6 +944,9 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
944 case SND_SOC_DAPM_STREAM_RESUME: 944 case SND_SOC_DAPM_STREAM_RESUME:
945 sys_power = 1; 945 sys_power = 1;
946 break; 946 break;
947 case SND_SOC_DAPM_STREAM_STOP:
948 sys_power = !!codec->active;
949 break;
947 case SND_SOC_DAPM_STREAM_SUSPEND: 950 case SND_SOC_DAPM_STREAM_SUSPEND:
948 sys_power = 0; 951 sys_power = 0;
949 break; 952 break;
diff --git a/sound/sound_core.c b/sound/sound_core.c
index c03bbaefdbc3..5580aced8730 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -104,7 +104,6 @@ module_exit(cleanup_soundcore);
104 104
105#include <linux/init.h> 105#include <linux/init.h>
106#include <linux/slab.h> 106#include <linux/slab.h>
107#include <linux/smp_lock.h>
108#include <linux/types.h> 107#include <linux/types.h>
109#include <linux/kernel.h> 108#include <linux/kernel.h>
110#include <linux/sound.h> 109#include <linux/sound.h>
diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 1bc56b2b94e2..337a00241a1f 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -155,7 +155,7 @@ static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
155 if (max_tries < 1) 155 if (max_tries < 1)
156 max_tries = 1; 156 max_tries = 1;
157 157
158 /* ssc_div must be a power of 2. */ 158 /* ssc_div must be even. */
159 ssc_div = (ssc_div + 1) & ~1UL; 159 ssc_div = (ssc_div + 1) & ~1UL;
160 160
161 if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN) { 161 if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN) {
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 7dae05d8783e..782f741cd00a 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -60,7 +60,7 @@ static const struct rc_config {
60 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ 60 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
61 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ 61 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
62 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ 62 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
63 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi */ 63 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
64 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ 64 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
65}; 65};
66 66
@@ -183,7 +183,13 @@ static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
183 if (value > 1) 183 if (value > 1)
184 return -EINVAL; 184 return -EINVAL;
185 changed = value != mixer->audigy2nx_leds[index]; 185 changed = value != mixer->audigy2nx_leds[index];
186 err = snd_usb_ctl_msg(mixer->chip->dev, 186 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
187 err = snd_usb_ctl_msg(mixer->chip->dev,
188 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
189 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
190 !value, 0, NULL, 0, 100);
191 else
192 err = snd_usb_ctl_msg(mixer->chip->dev,
187 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 193 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
188 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 194 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
189 value, index + 2, NULL, 0, 100); 195 value, index + 2, NULL, 0, 100);
@@ -225,8 +231,12 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
225 int i, err; 231 int i, err;
226 232
227 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { 233 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
234 /* USB X-Fi S51 doesn't have a CMSS LED */
235 if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
236 continue;
228 if (i > 1 && /* Live24ext has 2 LEDs only */ 237 if (i > 1 && /* Live24ext has 2 LEDs only */
229 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 238 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
239 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
230 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) 240 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
231 break; 241 break;
232 err = snd_ctl_add(mixer->chip->card, 242 err = snd_ctl_add(mixer->chip->card,
@@ -365,6 +375,7 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
365 375
366 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) || 376 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
367 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 377 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
378 mixer->chip->usb_id == USB_ID(0x041e, 0x3042) ||
368 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) { 379 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) {
369 if ((err = snd_audigy2nx_controls_create(mixer)) < 0) 380 if ((err = snd_audigy2nx_controls_create(mixer)) < 0)
370 return err; 381 return err;
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index cff3a3c465d7..4132522ac90f 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -676,8 +676,10 @@ static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
676 if (!needs_knot) 676 if (!needs_knot)
677 return 0; 677 return 0;
678 678
679 subs->rate_list.count = count;
680 subs->rate_list.list = kmalloc(sizeof(int) * count, GFP_KERNEL); 679 subs->rate_list.list = kmalloc(sizeof(int) * count, GFP_KERNEL);
680 if (!subs->rate_list.list)
681 return -ENOMEM;
682 subs->rate_list.count = count;
681 subs->rate_list.mask = 0; 683 subs->rate_list.mask = 0;
682 count = 0; 684 count = 0;
683 list_for_each_entry(fp, &subs->fmt_list, list) { 685 list_for_each_entry(fp, &subs->fmt_list, list) {
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt
index 122ec9dc4853..26aff6bf9e50 100644
--- a/tools/perf/Documentation/perf-trace.txt
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -8,7 +8,11 @@ perf-trace - Read perf.data (created by perf record) and display trace output
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf trace' {record <script> | report <script> [args] } 11'perf trace' [<options>]
12'perf trace' [<options>] record <script> [<record-options>] <command>
13'perf trace' [<options>] report <script> [script-args]
14'perf trace' [<options>] <script> <required-script-args> [<record-options>] <command>
15'perf trace' [<options>] <top-script> [script-args]
12 16
13DESCRIPTION 17DESCRIPTION
14----------- 18-----------
@@ -24,23 +28,53 @@ There are several variants of perf trace:
24 available via 'perf trace -l'). The following variants allow you to 28 available via 'perf trace -l'). The following variants allow you to
25 record and run those scripts: 29 record and run those scripts:
26 30
27 'perf trace record <script>' to record the events required for 'perf 31 'perf trace record <script> <command>' to record the events required
28 trace report'. <script> is the name displayed in the output of 32 for 'perf trace report'. <script> is the name displayed in the
29 'perf trace --list' i.e. the actual script name minus any language 33 output of 'perf trace --list' i.e. the actual script name minus any
30 extension. 34 language extension. If <command> is not specified, the events are
35 recorded using the -a (system-wide) 'perf record' option.
31 36
32 'perf trace report <script>' to run and display the results of 37 'perf trace report <script> [args]' to run and display the results
33 <script>. <script> is the name displayed in the output of 'perf 38 of <script>. <script> is the name displayed in the output of 'perf
34 trace --list' i.e. the actual script name minus any language 39 trace --list' i.e. the actual script name minus any language
35 extension. The perf.data output from a previous run of 'perf trace 40 extension. The perf.data output from a previous run of 'perf trace
36 record <script>' is used and should be present for this command to 41 record <script>' is used and should be present for this command to
37 succeed. 42 succeed. [args] refers to the (mainly optional) args expected by
43 the script.
44
45 'perf trace <script> <required-script-args> <command>' to both
46 record the events required for <script> and to run the <script>
47 using 'live-mode' i.e. without writing anything to disk. <script>
48 is the name displayed in the output of 'perf trace --list' i.e. the
49 actual script name minus any language extension. If <command> is
50 not specified, the events are recorded using the -a (system-wide)
51 'perf record' option. If <script> has any required args, they
52 should be specified before <command>. This mode doesn't allow for
53 optional script args to be specified; if optional script args are
54 desired, they can be specified using separate 'perf trace record'
55 and 'perf trace report' commands, with the stdout of the record step
56 piped to the stdin of the report script, using the '-o -' and '-i -'
57 options of the corresponding commands.
58
59 'perf trace <top-script>' to both record the events required for
60 <top-script> and to run the <top-script> using 'live-mode'
61 i.e. without writing anything to disk. <top-script> is the name
62 displayed in the output of 'perf trace --list' i.e. the actual
63 script name minus any language extension; a <top-script> is defined
64 as any script name ending with the string 'top'.
65
66 [<record-options>] can be passed to the record steps of 'perf trace
67 record' and 'live-mode' variants; this isn't possible however for
68 <top-script> 'live-mode' or 'perf trace report' variants.
38 69
39 See the 'SEE ALSO' section for links to language-specific 70 See the 'SEE ALSO' section for links to language-specific
40 information on how to write and run your own trace scripts. 71 information on how to write and run your own trace scripts.
41 72
42OPTIONS 73OPTIONS
43------- 74-------
75<command>...::
76 Any command you can specify in a shell.
77
44-D:: 78-D::
45--dump-raw-trace=:: 79--dump-raw-trace=::
46 Display verbose dump of the trace data. 80 Display verbose dump of the trace data.
@@ -64,6 +98,13 @@ OPTIONS
64 Generate perf-trace.[ext] starter script for given language, 98 Generate perf-trace.[ext] starter script for given language,
65 using current perf.data. 99 using current perf.data.
66 100
101-a::
102 Force system-wide collection. Scripts run without a <command>
103 normally use -a by default, while scripts run with a <command>
104 normally don't - this option allows the latter to be run in
105 system-wide mode.
106
107
67SEE ALSO 108SEE ALSO
68-------- 109--------
69linkperf:perf-record[1], linkperf:perf-trace-perl[1], 110linkperf:perf-record[1], linkperf:perf-trace-perl[1],
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4e75583ddd6d..564491fa18b2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -197,7 +197,7 @@ static void sig_atexit(void)
197 if (child_pid > 0) 197 if (child_pid > 0)
198 kill(child_pid, SIGTERM); 198 kill(child_pid, SIGTERM);
199 199
200 if (signr == -1) 200 if (signr == -1 || signr == SIGUSR1)
201 return; 201 return;
202 202
203 signal(signr, SIG_DFL); 203 signal(signr, SIG_DFL);
@@ -515,6 +515,7 @@ static int __cmd_record(int argc, const char **argv)
515 atexit(sig_atexit); 515 atexit(sig_atexit);
516 signal(SIGCHLD, sig_handler); 516 signal(SIGCHLD, sig_handler);
517 signal(SIGINT, sig_handler); 517 signal(SIGINT, sig_handler);
518 signal(SIGUSR1, sig_handler);
518 519
519 if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) { 520 if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
520 perror("failed to create pipes"); 521 perror("failed to create pipes");
@@ -606,6 +607,7 @@ static int __cmd_record(int argc, const char **argv)
606 execvp(argv[0], (char **)argv); 607 execvp(argv[0], (char **)argv);
607 608
608 perror(argv[0]); 609 perror(argv[0]);
610 kill(getppid(), SIGUSR1);
609 exit(-1); 611 exit(-1);
610 } 612 }
611 613
@@ -697,17 +699,18 @@ static int __cmd_record(int argc, const char **argv)
697 if (err < 0) 699 if (err < 0)
698 err = event__synthesize_kernel_mmap(process_synthesized_event, 700 err = event__synthesize_kernel_mmap(process_synthesized_event,
699 session, machine, "_stext"); 701 session, machine, "_stext");
700 if (err < 0) { 702 if (err < 0)
701 pr_err("Couldn't record kernel reference relocation symbol.\n"); 703 pr_err("Couldn't record kernel reference relocation symbol\n"
702 return err; 704 "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
703 } 705 "Check /proc/kallsyms permission or run as root.\n");
704 706
705 err = event__synthesize_modules(process_synthesized_event, 707 err = event__synthesize_modules(process_synthesized_event,
706 session, machine); 708 session, machine);
707 if (err < 0) { 709 if (err < 0)
708 pr_err("Couldn't record kernel reference relocation symbol.\n"); 710 pr_err("Couldn't record kernel module information.\n"
709 return err; 711 "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
710 } 712 "Check /proc/modules permission or run as root.\n");
713
711 if (perf_guest) 714 if (perf_guest)
712 perf_session__process_machines(session, event__synthesize_guest_os); 715 perf_session__process_machines(session, event__synthesize_guest_os);
713 716
@@ -761,7 +764,7 @@ static int __cmd_record(int argc, const char **argv)
761 } 764 }
762 } 765 }
763 766
764 if (quiet) 767 if (quiet || signr == SIGUSR1)
765 return 0; 768 return 0;
766 769
767 fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); 770 fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking);
@@ -790,7 +793,7 @@ static const char * const record_usage[] = {
790 793
791static bool force, append_file; 794static bool force, append_file;
792 795
793static const struct option options[] = { 796const struct option record_options[] = {
794 OPT_CALLBACK('e', "event", NULL, "event", 797 OPT_CALLBACK('e', "event", NULL, "event",
795 "event selector. use 'perf list' to list available events", 798 "event selector. use 'perf list' to list available events",
796 parse_events), 799 parse_events),
@@ -839,16 +842,16 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
839{ 842{
840 int i, j, err = -ENOMEM; 843 int i, j, err = -ENOMEM;
841 844
842 argc = parse_options(argc, argv, options, record_usage, 845 argc = parse_options(argc, argv, record_options, record_usage,
843 PARSE_OPT_STOP_AT_NON_OPTION); 846 PARSE_OPT_STOP_AT_NON_OPTION);
844 if (!argc && target_pid == -1 && target_tid == -1 && 847 if (!argc && target_pid == -1 && target_tid == -1 &&
845 !system_wide && !cpu_list) 848 !system_wide && !cpu_list)
846 usage_with_options(record_usage, options); 849 usage_with_options(record_usage, record_options);
847 850
848 if (force && append_file) { 851 if (force && append_file) {
849 fprintf(stderr, "Can't overwrite and append at the same time." 852 fprintf(stderr, "Can't overwrite and append at the same time."
850 " You need to choose between -f and -A"); 853 " You need to choose between -f and -A");
851 usage_with_options(record_usage, options); 854 usage_with_options(record_usage, record_options);
852 } else if (append_file) { 855 } else if (append_file) {
853 write_mode = WRITE_APPEND; 856 write_mode = WRITE_APPEND;
854 } else { 857 } else {
@@ -871,7 +874,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
871 if (thread_num <= 0) { 874 if (thread_num <= 0) {
872 fprintf(stderr, "Can't find all threads of pid %d\n", 875 fprintf(stderr, "Can't find all threads of pid %d\n",
873 target_pid); 876 target_pid);
874 usage_with_options(record_usage, options); 877 usage_with_options(record_usage, record_options);
875 } 878 }
876 } else { 879 } else {
877 all_tids=malloc(sizeof(pid_t)); 880 all_tids=malloc(sizeof(pid_t));
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index b513e40974f4..dd625808c2a5 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -69,7 +69,6 @@ static int target_tid = -1;
69static pid_t *all_tids = NULL; 69static pid_t *all_tids = NULL;
70static int thread_num = 0; 70static int thread_num = 0;
71static bool inherit = false; 71static bool inherit = false;
72static int profile_cpu = -1;
73static int nr_cpus = 0; 72static int nr_cpus = 0;
74static int realtime_prio = 0; 73static int realtime_prio = 0;
75static bool group = false; 74static bool group = false;
@@ -558,13 +557,13 @@ static void print_sym_table(void)
558 else 557 else
559 printf(" (all"); 558 printf(" (all");
560 559
561 if (profile_cpu != -1) 560 if (cpu_list)
562 printf(", cpu: %d)\n", profile_cpu); 561 printf(", CPU%s: %s)\n", nr_cpus > 1 ? "s" : "", cpu_list);
563 else { 562 else {
564 if (target_tid != -1) 563 if (target_tid != -1)
565 printf(")\n"); 564 printf(")\n");
566 else 565 else
567 printf(", %d CPUs)\n", nr_cpus); 566 printf(", %d CPU%s)\n", nr_cpus, nr_cpus > 1 ? "s" : "");
568 } 567 }
569 568
570 printf("%-*.*s\n", win_width, win_width, graph_dotted_line); 569 printf("%-*.*s\n", win_width, win_width, graph_dotted_line);
@@ -1187,11 +1186,10 @@ int group_fd;
1187static void start_counter(int i, int counter) 1186static void start_counter(int i, int counter)
1188{ 1187{
1189 struct perf_event_attr *attr; 1188 struct perf_event_attr *attr;
1190 int cpu; 1189 int cpu = -1;
1191 int thread_index; 1190 int thread_index;
1192 1191
1193 cpu = profile_cpu; 1192 if (target_tid == -1)
1194 if (target_tid == -1 && profile_cpu == -1)
1195 cpu = cpumap[i]; 1193 cpu = cpumap[i];
1196 1194
1197 attr = attrs + counter; 1195 attr = attrs + counter;
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 2f8df45c4dcb..86cfe3800e6b 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -10,6 +10,7 @@
10#include "util/symbol.h" 10#include "util/symbol.h"
11#include "util/thread.h" 11#include "util/thread.h"
12#include "util/trace-event.h" 12#include "util/trace-event.h"
13#include "util/parse-options.h"
13#include "util/util.h" 14#include "util/util.h"
14 15
15static char const *script_name; 16static char const *script_name;
@@ -17,6 +18,7 @@ static char const *generate_script_lang;
17static bool debug_mode; 18static bool debug_mode;
18static u64 last_timestamp; 19static u64 last_timestamp;
19static u64 nr_unordered; 20static u64 nr_unordered;
21extern const struct option record_options[];
20 22
21static int default_start_script(const char *script __unused, 23static int default_start_script(const char *script __unused,
22 int argc __unused, 24 int argc __unused,
@@ -328,7 +330,7 @@ static struct script_desc *script_desc__new(const char *name)
328{ 330{
329 struct script_desc *s = zalloc(sizeof(*s)); 331 struct script_desc *s = zalloc(sizeof(*s));
330 332
331 if (s != NULL) 333 if (s != NULL && name)
332 s->name = strdup(name); 334 s->name = strdup(name);
333 335
334 return s; 336 return s;
@@ -337,6 +339,8 @@ static struct script_desc *script_desc__new(const char *name)
337static void script_desc__delete(struct script_desc *s) 339static void script_desc__delete(struct script_desc *s)
338{ 340{
339 free(s->name); 341 free(s->name);
342 free(s->half_liner);
343 free(s->args);
340 free(s); 344 free(s);
341} 345}
342 346
@@ -537,8 +541,40 @@ static char *get_script_path(const char *script_root, const char *suffix)
537 return path; 541 return path;
538} 542}
539 543
544static bool is_top_script(const char *script_path)
545{
546 return ends_with((char *)script_path, "top") == NULL ? false : true;
547}
548
549static int has_required_arg(char *script_path)
550{
551 struct script_desc *desc;
552 int n_args = 0;
553 char *p;
554
555 desc = script_desc__new(NULL);
556
557 if (read_script_info(desc, script_path))
558 goto out;
559
560 if (!desc->args)
561 goto out;
562
563 for (p = desc->args; *p; p++)
564 if (*p == '<')
565 n_args++;
566out:
567 script_desc__delete(desc);
568
569 return n_args;
570}
571
540static const char * const trace_usage[] = { 572static const char * const trace_usage[] = {
541 "perf trace [<options>] <command>", 573 "perf trace [<options>]",
574 "perf trace [<options>] record <script> [<record-options>] <command>",
575 "perf trace [<options>] report <script> [script-args]",
576 "perf trace [<options>] <script> [<record-options>] <command>",
577 "perf trace [<options>] <top-script> [script-args]",
542 NULL 578 NULL
543}; 579};
544 580
@@ -564,50 +600,81 @@ static const struct option options[] = {
564 OPT_END() 600 OPT_END()
565}; 601};
566 602
603static bool have_cmd(int argc, const char **argv)
604{
605 char **__argv = malloc(sizeof(const char *) * argc);
606
607 if (!__argv)
608 die("malloc");
609 memcpy(__argv, argv, sizeof(const char *) * argc);
610 argc = parse_options(argc, (const char **)__argv, record_options,
611 NULL, PARSE_OPT_STOP_AT_NON_OPTION);
612 free(__argv);
613
614 return argc != 0;
615}
616
567int cmd_trace(int argc, const char **argv, const char *prefix __used) 617int cmd_trace(int argc, const char **argv, const char *prefix __used)
568{ 618{
619 char *rec_script_path = NULL;
620 char *rep_script_path = NULL;
569 struct perf_session *session; 621 struct perf_session *session;
570 const char *suffix = NULL; 622 char *script_path = NULL;
571 const char **__argv; 623 const char **__argv;
572 char *script_path; 624 bool system_wide;
573 int i, err; 625 int i, j, err;
574 626
575 if (argc >= 2 && strncmp(argv[1], "rec", strlen("rec")) == 0) { 627 setup_scripting();
576 if (argc < 3) { 628
577 fprintf(stderr, 629 argc = parse_options(argc, argv, options, trace_usage,
578 "Please specify a record script\n"); 630 PARSE_OPT_STOP_AT_NON_OPTION);
579 return -1; 631
580 } 632 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
581 suffix = RECORD_SUFFIX; 633 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
634 if (!rec_script_path)
635 return cmd_record(argc, argv, NULL);
582 } 636 }
583 637
584 if (argc >= 2 && strncmp(argv[1], "rep", strlen("rep")) == 0) { 638 if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) {
585 if (argc < 3) { 639 rep_script_path = get_script_path(argv[1], REPORT_SUFFIX);
640 if (!rep_script_path) {
586 fprintf(stderr, 641 fprintf(stderr,
587 "Please specify a report script\n"); 642 "Please specify a valid report script"
643 "(see 'perf trace -l' for listing)\n");
588 return -1; 644 return -1;
589 } 645 }
590 suffix = REPORT_SUFFIX;
591 } 646 }
592 647
593 /* make sure PERF_EXEC_PATH is set for scripts */ 648 /* make sure PERF_EXEC_PATH is set for scripts */
594 perf_set_argv_exec_path(perf_exec_path()); 649 perf_set_argv_exec_path(perf_exec_path());
595 650
596 if (!suffix && argc >= 2 && strncmp(argv[1], "-", strlen("-")) != 0) { 651 if (argc && !script_name && !rec_script_path && !rep_script_path) {
597 char *record_script_path, *report_script_path;
598 int live_pipe[2]; 652 int live_pipe[2];
653 int rep_args;
599 pid_t pid; 654 pid_t pid;
600 655
601 record_script_path = get_script_path(argv[1], RECORD_SUFFIX); 656 rec_script_path = get_script_path(argv[0], RECORD_SUFFIX);
602 if (!record_script_path) { 657 rep_script_path = get_script_path(argv[0], REPORT_SUFFIX);
603 fprintf(stderr, "record script not found\n"); 658
604 return -1; 659 if (!rec_script_path && !rep_script_path) {
660 fprintf(stderr, " Couldn't find script %s\n\n See perf"
661 " trace -l for available scripts.\n", argv[0]);
662 usage_with_options(trace_usage, options);
605 } 663 }
606 664
607 report_script_path = get_script_path(argv[1], REPORT_SUFFIX); 665 if (is_top_script(argv[0])) {
608 if (!report_script_path) { 666 rep_args = argc - 1;
609 fprintf(stderr, "report script not found\n"); 667 } else {
610 return -1; 668 int rec_args;
669
670 rep_args = has_required_arg(rep_script_path);
671 rec_args = (argc - 1) - rep_args;
672 if (rec_args < 0) {
673 fprintf(stderr, " %s script requires options."
674 "\n\n See perf trace -l for available "
675 "scripts and options.\n", argv[0]);
676 usage_with_options(trace_usage, options);
677 }
611 } 678 }
612 679
613 if (pipe(live_pipe) < 0) { 680 if (pipe(live_pipe) < 0) {
@@ -622,60 +689,84 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
622 } 689 }
623 690
624 if (!pid) { 691 if (!pid) {
692 system_wide = true;
693 j = 0;
694
625 dup2(live_pipe[1], 1); 695 dup2(live_pipe[1], 1);
626 close(live_pipe[0]); 696 close(live_pipe[0]);
627 697
628 __argv = malloc(6 * sizeof(const char *)); 698 if (!is_top_script(argv[0]))
629 __argv[0] = "/bin/sh"; 699 system_wide = !have_cmd(argc - rep_args,
630 __argv[1] = record_script_path; 700 &argv[rep_args]);
631 __argv[2] = "-q"; 701
632 __argv[3] = "-o"; 702 __argv = malloc((argc + 6) * sizeof(const char *));
633 __argv[4] = "-"; 703 if (!__argv)
634 __argv[5] = NULL; 704 die("malloc");
705
706 __argv[j++] = "/bin/sh";
707 __argv[j++] = rec_script_path;
708 if (system_wide)
709 __argv[j++] = "-a";
710 __argv[j++] = "-q";
711 __argv[j++] = "-o";
712 __argv[j++] = "-";
713 for (i = rep_args + 1; i < argc; i++)
714 __argv[j++] = argv[i];
715 __argv[j++] = NULL;
635 716
636 execvp("/bin/sh", (char **)__argv); 717 execvp("/bin/sh", (char **)__argv);
718 free(__argv);
637 exit(-1); 719 exit(-1);
638 } 720 }
639 721
640 dup2(live_pipe[0], 0); 722 dup2(live_pipe[0], 0);
641 close(live_pipe[1]); 723 close(live_pipe[1]);
642 724
643 __argv = malloc((argc + 3) * sizeof(const char *)); 725 __argv = malloc((argc + 4) * sizeof(const char *));
644 __argv[0] = "/bin/sh"; 726 if (!__argv)
645 __argv[1] = report_script_path; 727 die("malloc");
646 for (i = 2; i < argc; i++) 728 j = 0;
647 __argv[i] = argv[i]; 729 __argv[j++] = "/bin/sh";
648 __argv[i++] = "-i"; 730 __argv[j++] = rep_script_path;
649 __argv[i++] = "-"; 731 for (i = 1; i < rep_args + 1; i++)
650 __argv[i++] = NULL; 732 __argv[j++] = argv[i];
733 __argv[j++] = "-i";
734 __argv[j++] = "-";
735 __argv[j++] = NULL;
651 736
652 execvp("/bin/sh", (char **)__argv); 737 execvp("/bin/sh", (char **)__argv);
738 free(__argv);
653 exit(-1); 739 exit(-1);
654 } 740 }
655 741
656 if (suffix) { 742 if (rec_script_path)
657 script_path = get_script_path(argv[2], suffix); 743 script_path = rec_script_path;
658 if (!script_path) { 744 if (rep_script_path)
659 fprintf(stderr, "script not found\n"); 745 script_path = rep_script_path;
660 return -1; 746
661 } 747 if (script_path) {
662 748 system_wide = false;
663 __argv = malloc((argc + 1) * sizeof(const char *)); 749 j = 0;
664 __argv[0] = "/bin/sh"; 750
665 __argv[1] = script_path; 751 if (rec_script_path)
666 for (i = 3; i < argc; i++) 752 system_wide = !have_cmd(argc - 1, &argv[1]);
667 __argv[i - 1] = argv[i]; 753
668 __argv[argc - 1] = NULL; 754 __argv = malloc((argc + 2) * sizeof(const char *));
755 if (!__argv)
756 die("malloc");
757 __argv[j++] = "/bin/sh";
758 __argv[j++] = script_path;
759 if (system_wide)
760 __argv[j++] = "-a";
761 for (i = 2; i < argc; i++)
762 __argv[j++] = argv[i];
763 __argv[j++] = NULL;
669 764
670 execvp("/bin/sh", (char **)__argv); 765 execvp("/bin/sh", (char **)__argv);
766 free(__argv);
671 exit(-1); 767 exit(-1);
672 } 768 }
673 769
674 setup_scripting();
675
676 argc = parse_options(argc, argv, options, trace_usage,
677 PARSE_OPT_STOP_AT_NON_OPTION);
678
679 if (symbol__init() < 0) 770 if (symbol__init() < 0)
680 return -1; 771 return -1;
681 if (!script_name) 772 if (!script_name)
diff --git a/tools/perf/scripts/perl/bin/failed-syscalls-record b/tools/perf/scripts/perl/bin/failed-syscalls-record
index eb5846bcb565..8104895a7b67 100644
--- a/tools/perf/scripts/perl/bin/failed-syscalls-record
+++ b/tools/perf/scripts/perl/bin/failed-syscalls-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e raw_syscalls:sys_exit $@ 2perf record -e raw_syscalls:sys_exit $@
diff --git a/tools/perf/scripts/perl/bin/rw-by-file-record b/tools/perf/scripts/perl/bin/rw-by-file-record
index 5bfaae5a6cba..33efc8673aae 100644
--- a/tools/perf/scripts/perl/bin/rw-by-file-record
+++ b/tools/perf/scripts/perl/bin/rw-by-file-record
@@ -1,3 +1,3 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e syscalls:sys_enter_read -e syscalls:sys_enter_write $@ 2perf record -e syscalls:sys_enter_read -e syscalls:sys_enter_write $@
3 3
diff --git a/tools/perf/scripts/perl/bin/rw-by-pid-record b/tools/perf/scripts/perl/bin/rw-by-pid-record
index 6e0b2f7755ac..7cb9db230448 100644
--- a/tools/perf/scripts/perl/bin/rw-by-pid-record
+++ b/tools/perf/scripts/perl/bin/rw-by-pid-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@ 2perf record -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
diff --git a/tools/perf/scripts/perl/bin/rwtop-record b/tools/perf/scripts/perl/bin/rwtop-record
index 6e0b2f7755ac..7cb9db230448 100644
--- a/tools/perf/scripts/perl/bin/rwtop-record
+++ b/tools/perf/scripts/perl/bin/rwtop-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@ 2perf record -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
diff --git a/tools/perf/scripts/perl/bin/wakeup-latency-record b/tools/perf/scripts/perl/bin/wakeup-latency-record
index 9f2acaaae9f0..464251a1bd7e 100644
--- a/tools/perf/scripts/perl/bin/wakeup-latency-record
+++ b/tools/perf/scripts/perl/bin/wakeup-latency-record
@@ -1,5 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e sched:sched_switch -e sched:sched_wakeup $@ 2perf record -e sched:sched_switch -e sched:sched_wakeup $@
3 3
4 4
5 5
diff --git a/tools/perf/scripts/perl/bin/workqueue-stats-record b/tools/perf/scripts/perl/bin/workqueue-stats-record
index 85301f2471ff..8edda9078d5d 100644
--- a/tools/perf/scripts/perl/bin/workqueue-stats-record
+++ b/tools/perf/scripts/perl/bin/workqueue-stats-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion $@ 2perf record -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion $@
diff --git a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record
index eb5846bcb565..8104895a7b67 100644
--- a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record
+++ b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e raw_syscalls:sys_exit $@ 2perf record -e raw_syscalls:sys_exit $@
diff --git a/tools/perf/scripts/python/bin/futex-contention-record b/tools/perf/scripts/python/bin/futex-contention-record
index 5ecbb433caf4..b1495c9a9b20 100644
--- a/tools/perf/scripts/python/bin/futex-contention-record
+++ b/tools/perf/scripts/python/bin/futex-contention-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e syscalls:sys_enter_futex -e syscalls:sys_exit_futex $@ 2perf record -e syscalls:sys_enter_futex -e syscalls:sys_exit_futex $@
diff --git a/tools/perf/scripts/python/bin/netdev-times-record b/tools/perf/scripts/python/bin/netdev-times-record
index d931a828126b..558754b840a9 100644
--- a/tools/perf/scripts/python/bin/netdev-times-record
+++ b/tools/perf/scripts/python/bin/netdev-times-record
@@ -1,5 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e net:net_dev_xmit -e net:net_dev_queue \ 2perf record -e net:net_dev_xmit -e net:net_dev_queue \
3 -e net:netif_receive_skb -e net:netif_rx \ 3 -e net:netif_receive_skb -e net:netif_rx \
4 -e skb:consume_skb -e skb:kfree_skb \ 4 -e skb:consume_skb -e skb:kfree_skb \
5 -e skb:skb_copy_datagram_iovec -e napi:napi_poll \ 5 -e skb:skb_copy_datagram_iovec -e napi:napi_poll \
diff --git a/tools/perf/scripts/python/bin/sched-migration-record b/tools/perf/scripts/python/bin/sched-migration-record
index 17a3e9bd9e8f..7493fddbe995 100644
--- a/tools/perf/scripts/python/bin/sched-migration-record
+++ b/tools/perf/scripts/python/bin/sched-migration-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -m 16384 -a -e sched:sched_wakeup -e sched:sched_wakeup_new -e sched:sched_switch -e sched:sched_migrate_task $@ 2perf record -m 16384 -e sched:sched_wakeup -e sched:sched_wakeup_new -e sched:sched_switch -e sched:sched_migrate_task $@
diff --git a/tools/perf/scripts/python/bin/sctop-record b/tools/perf/scripts/python/bin/sctop-record
index 1fc5998b721d..4efbfaa7f6a5 100644
--- a/tools/perf/scripts/python/bin/sctop-record
+++ b/tools/perf/scripts/python/bin/sctop-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e raw_syscalls:sys_enter $@ 2perf record -e raw_syscalls:sys_enter $@
diff --git a/tools/perf/scripts/python/bin/syscall-counts-by-pid-record b/tools/perf/scripts/python/bin/syscall-counts-by-pid-record
index 1fc5998b721d..4efbfaa7f6a5 100644
--- a/tools/perf/scripts/python/bin/syscall-counts-by-pid-record
+++ b/tools/perf/scripts/python/bin/syscall-counts-by-pid-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e raw_syscalls:sys_enter $@ 2perf record -e raw_syscalls:sys_enter $@
diff --git a/tools/perf/scripts/python/bin/syscall-counts-record b/tools/perf/scripts/python/bin/syscall-counts-record
index 1fc5998b721d..4efbfaa7f6a5 100644
--- a/tools/perf/scripts/python/bin/syscall-counts-record
+++ b/tools/perf/scripts/python/bin/syscall-counts-record
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2perf record -a -e raw_syscalls:sys_enter $@ 2perf record -e raw_syscalls:sys_enter $@
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index d7e67b167ea3..64a85bafde63 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -946,11 +946,16 @@ perf_header__find_attr(u64 id, struct perf_header *header)
946 946
947 /* 947 /*
948 * We set id to -1 if the data file doesn't contain sample 948 * We set id to -1 if the data file doesn't contain sample
949 * ids. Check for this and avoid walking through the entire 949 * ids. This can happen when the data file contains one type
950 * list of ids which may be large. 950 * of event and in that case, the header can still store the
951 * event attribute information. Check for this and avoid
952 * walking through the entire list of ids which may be large.
951 */ 953 */
952 if (id == -1ULL) 954 if (id == -1ULL) {
955 if (header->attrs > 0)
956 return &header->attr[0]->attr;
953 return NULL; 957 return NULL;
958 }
954 959
955 for (i = 0; i < header->attrs; i++) { 960 for (i = 0; i < header->attrs; i++) {
956 struct perf_header_attr *attr = header->attr[i]; 961 struct perf_header_attr *attr = header->attr[i];
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b39f499e575a..d628c8d1cf5e 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -295,7 +295,9 @@ static void symbols__insert_by_name(struct rb_root *self, struct symbol *sym)
295{ 295{
296 struct rb_node **p = &self->rb_node; 296 struct rb_node **p = &self->rb_node;
297 struct rb_node *parent = NULL; 297 struct rb_node *parent = NULL;
298 struct symbol_name_rb_node *symn = ((void *)sym) - sizeof(*parent), *s; 298 struct symbol_name_rb_node *symn, *s;
299
300 symn = container_of(sym, struct symbol_name_rb_node, sym);
299 301
300 while (*p != NULL) { 302 while (*p != NULL) {
301 parent = *p; 303 parent = *p;
@@ -530,7 +532,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
530 struct machine *machine = kmaps->machine; 532 struct machine *machine = kmaps->machine;
531 struct map *curr_map = map; 533 struct map *curr_map = map;
532 struct symbol *pos; 534 struct symbol *pos;
533 int count = 0; 535 int count = 0, moved = 0;
534 struct rb_root *root = &self->symbols[map->type]; 536 struct rb_root *root = &self->symbols[map->type];
535 struct rb_node *next = rb_first(root); 537 struct rb_node *next = rb_first(root);
536 int kernel_range = 0; 538 int kernel_range = 0;
@@ -588,6 +590,11 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
588 char dso_name[PATH_MAX]; 590 char dso_name[PATH_MAX];
589 struct dso *dso; 591 struct dso *dso;
590 592
593 if (count == 0) {
594 curr_map = map;
595 goto filter_symbol;
596 }
597
591 if (self->kernel == DSO_TYPE_GUEST_KERNEL) 598 if (self->kernel == DSO_TYPE_GUEST_KERNEL)
592 snprintf(dso_name, sizeof(dso_name), 599 snprintf(dso_name, sizeof(dso_name),
593 "[guest.kernel].%d", 600 "[guest.kernel].%d",
@@ -613,7 +620,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
613 map_groups__insert(kmaps, curr_map); 620 map_groups__insert(kmaps, curr_map);
614 ++kernel_range; 621 ++kernel_range;
615 } 622 }
616 623filter_symbol:
617 if (filter && filter(curr_map, pos)) { 624 if (filter && filter(curr_map, pos)) {
618discard_symbol: rb_erase(&pos->rb_node, root); 625discard_symbol: rb_erase(&pos->rb_node, root);
619 symbol__delete(pos); 626 symbol__delete(pos);
@@ -621,8 +628,9 @@ discard_symbol: rb_erase(&pos->rb_node, root);
621 if (curr_map != map) { 628 if (curr_map != map) {
622 rb_erase(&pos->rb_node, root); 629 rb_erase(&pos->rb_node, root);
623 symbols__insert(&curr_map->dso->symbols[curr_map->type], pos); 630 symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
624 } 631 ++moved;
625 count++; 632 } else
633 ++count;
626 } 634 }
627 } 635 }
628 636
@@ -632,7 +640,7 @@ discard_symbol: rb_erase(&pos->rb_node, root);
632 dso__set_loaded(curr_map->dso, curr_map->type); 640 dso__set_loaded(curr_map->dso, curr_map->type);
633 } 641 }
634 642
635 return count; 643 return count + moved;
636} 644}
637 645
638int dso__load_kallsyms(struct dso *self, const char *filename, 646int dso__load_kallsyms(struct dso *self, const char *filename,
@@ -2123,14 +2131,55 @@ static struct dso *machine__create_kernel(struct machine *self)
2123 return kernel; 2131 return kernel;
2124} 2132}
2125 2133
2134struct process_args {
2135 u64 start;
2136};
2137
2138static int symbol__in_kernel(void *arg, const char *name,
2139 char type __used, u64 start)
2140{
2141 struct process_args *args = arg;
2142
2143 if (strchr(name, '['))
2144 return 0;
2145
2146 args->start = start;
2147 return 1;
2148}
2149
2150/* Figure out the start address of kernel map from /proc/kallsyms */
2151static u64 machine__get_kernel_start_addr(struct machine *machine)
2152{
2153 const char *filename;
2154 char path[PATH_MAX];
2155 struct process_args args;
2156
2157 if (machine__is_host(machine)) {
2158 filename = "/proc/kallsyms";
2159 } else {
2160 if (machine__is_default_guest(machine))
2161 filename = (char *)symbol_conf.default_guest_kallsyms;
2162 else {
2163 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
2164 filename = path;
2165 }
2166 }
2167
2168 if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
2169 return 0;
2170
2171 return args.start;
2172}
2173
2126int __machine__create_kernel_maps(struct machine *self, struct dso *kernel) 2174int __machine__create_kernel_maps(struct machine *self, struct dso *kernel)
2127{ 2175{
2128 enum map_type type; 2176 enum map_type type;
2177 u64 start = machine__get_kernel_start_addr(self);
2129 2178
2130 for (type = 0; type < MAP__NR_TYPES; ++type) { 2179 for (type = 0; type < MAP__NR_TYPES; ++type) {
2131 struct kmap *kmap; 2180 struct kmap *kmap;
2132 2181
2133 self->vmlinux_maps[type] = map__new2(0, kernel, type); 2182 self->vmlinux_maps[type] = map__new2(start, kernel, type);
2134 if (self->vmlinux_maps[type] == NULL) 2183 if (self->vmlinux_maps[type] == NULL)
2135 return -1; 2184 return -1;
2136 2185
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c
index 9706d9d40279..056c69521a38 100644
--- a/tools/perf/util/ui/util.c
+++ b/tools/perf/util/ui/util.c
@@ -104,9 +104,10 @@ out_destroy_form:
104 return rc; 104 return rc;
105} 105}
106 106
107static const char yes[] = "Yes", no[] = "No";
108
107bool ui__dialog_yesno(const char *msg) 109bool ui__dialog_yesno(const char *msg)
108{ 110{
109 /* newtWinChoice should really be accepting const char pointers... */ 111 /* newtWinChoice should really be accepting const char pointers... */
110 char yes[] = "Yes", no[] = "No"; 112 return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1;
111 return newtWinChoice(NULL, yes, no, (char *)msg) == 1;
112} 113}
diff --git a/usr/initramfs_data.S b/usr/initramfs_data.S
index b9efed5e35cc..c14322d1c0cf 100644
--- a/usr/initramfs_data.S
+++ b/usr/initramfs_data.S
@@ -22,16 +22,17 @@
22*/ 22*/
23 23
24#include <linux/stringify.h> 24#include <linux/stringify.h>
25#include <asm-generic/vmlinux.lds.h>
25 26
26.section .init.ramfs,"a" 27.section .init.ramfs,"a"
27__irf_start: 28__irf_start:
28.incbin __stringify(INITRAMFS_IMAGE) 29.incbin __stringify(INITRAMFS_IMAGE)
29__irf_end: 30__irf_end:
30.section .init.ramfs.info,"a" 31.section .init.ramfs.info,"a"
31.globl __initramfs_size 32.globl VMLINUX_SYMBOL(__initramfs_size)
32__initramfs_size: 33VMLINUX_SYMBOL(__initramfs_size):
33#ifdef CONFIG_32BIT 34#ifdef CONFIG_64BIT
34 .long __irf_end - __irf_start
35#else
36 .quad __irf_end - __irf_start 35 .quad __irf_end - __irf_start
36#else
37 .long __irf_end - __irf_start
37#endif 38#endif