aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-class-regulator21
-rw-r--r--Documentation/ABI/testing/sysfs-driver-wacom13
-rw-r--r--Documentation/RCU/checklist.txt6
-rw-r--r--Documentation/RCU/stallwarn.txt16
-rw-r--r--Documentation/RCU/trace.txt43
-rw-r--r--Documentation/RCU/whatisRCU.txt9
-rw-r--r--Documentation/accounting/getdelays.c5
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.txt5
-rw-r--r--Documentation/devicetree/bindings/regulator/tps65217.txt31
-rw-r--r--Documentation/devicetree/bindings/regulator/tps6586x.txt73
-rw-r--r--Documentation/dontdiff1
-rw-r--r--Documentation/i2c/busses/i2c-i8011
-rw-r--r--Documentation/ia64/aliasing-test.c1
-rw-r--r--Documentation/kernel-parameters.txt11
-rw-r--r--Documentation/power/swsusp.txt2
-rw-r--r--Documentation/trace/kprobetrace.txt2
-rw-r--r--Documentation/vfio.txt2
-rw-r--r--MAINTAINERS22
-rw-r--r--Makefile4
-rw-r--r--arch/Kconfig10
-rw-r--r--arch/alpha/kernel/process.c6
-rw-r--r--arch/alpha/kernel/smp.c1
-rw-r--r--arch/arm/Kconfig.debug6
-rw-r--r--arch/arm/Makefile4
-rw-r--r--arch/arm/boot/compressed/head.S5
-rw-r--r--arch/arm/boot/dts/at91sam9260.dtsi3
-rw-r--r--arch/arm/boot/dts/at91sam9263.dtsi5
-rw-r--r--arch/arm/boot/dts/at91sam9g45.dtsi5
-rw-r--r--arch/arm/boot/dts/at91sam9n12.dtsi4
-rw-r--r--arch/arm/boot/dts/at91sam9x5.dtsi4
-rw-r--r--arch/arm/include/asm/assembler.h8
-rw-r--r--arch/arm/include/asm/memory.h3
-rw-r--r--arch/arm/include/asm/tlb.h4
-rw-r--r--arch/arm/include/asm/uaccess.h58
-rw-r--r--arch/arm/include/asm/unistd.h2
-rw-r--r--arch/arm/kernel/calls.S1
-rw-r--r--arch/arm/kernel/hw_breakpoint.c62
-rw-r--r--arch/arm/kernel/smp_twd.c48
-rw-r--r--arch/arm/kernel/traps.c11
-rw-r--r--arch/arm/lib/delay.c1
-rw-r--r--arch/arm/lib/getuser.S23
-rw-r--r--arch/arm/lib/putuser.S6
-rw-r--r--arch/arm/mach-imx/clk-imx25.c8
-rw-r--r--arch/arm/mach-imx/clk-imx35.c6
-rw-r--r--arch/arm/mach-imx/mach-armadillo5x0.c3
-rw-r--r--arch/arm/mach-mxs/mach-mxs.c2
-rw-r--r--arch/arm/mach-omap2/Kconfig3
-rw-r--r--arch/arm/mach-omap2/Makefile2
-rw-r--r--arch/arm/mach-omap2/clock33xx_data.c14
-rw-r--r--arch/arm/mach-omap2/clockdomain2xxx_3xxx.c50
-rw-r--r--arch/arm/mach-omap2/cm-regbits-34xx.h1
-rw-r--r--arch/arm/mach-omap2/omap-wakeupgen.c2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod.c1
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_3xxx_data.c15
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_44xx_data.c12
-rw-r--r--arch/arm/mach-omap2/timer.c7
-rw-r--r--arch/arm/mach-orion5x/common.c7
-rw-r--r--arch/arm/mach-shmobile/board-kzm9g.c4
-rw-r--r--arch/arm/mach-tegra/board-harmony-power.c12
-rw-r--r--arch/arm/mm/context.c7
-rw-r--r--arch/arm/mm/dma-mapping.c4
-rw-r--r--arch/arm/mm/mm.h3
-rw-r--r--arch/arm/mm/mmu.c8
-rw-r--r--arch/arm/plat-mxc/include/mach/mx25.h1
-rw-r--r--arch/arm/plat-omap/sram.c11
-rw-r--r--arch/arm/plat-samsung/clock.c10
-rw-r--r--arch/blackfin/Kconfig1
-rw-r--r--arch/blackfin/Makefile1
-rw-r--r--arch/blackfin/include/asm/smp.h2
-rw-r--r--arch/blackfin/mach-common/smp.c223
-rw-r--r--arch/c6x/include/asm/Kbuild1
-rw-r--r--arch/c6x/include/asm/barrier.h27
-rw-r--r--arch/cris/kernel/process.c3
-rw-r--r--arch/frv/kernel/process.c3
-rw-r--r--arch/h8300/kernel/process.c3
-rw-r--r--arch/ia64/kernel/process.c3
-rw-r--r--arch/m32r/kernel/process.c3
-rw-r--r--arch/m68k/kernel/process.c3
-rw-r--r--arch/m68k/platform/coldfire/clk.c6
-rw-r--r--arch/mips/kernel/smp-cmp.c2
-rw-r--r--arch/mips/mm/gup.c2
-rw-r--r--arch/mips/mti-malta/malta-int.c9
-rw-r--r--arch/mips/mti-malta/malta-platform.c5
-rw-r--r--arch/mn10300/kernel/process.c3
-rw-r--r--arch/parisc/kernel/process.c3
-rw-r--r--arch/powerpc/boot/.gitignore4
-rw-r--r--arch/s390/include/asm/hugetlb.h24
-rw-r--r--arch/s390/include/asm/tlbflush.h2
-rw-r--r--arch/s390/kernel/setup.c2
-rw-r--r--arch/s390/lib/uaccess_pt.c142
-rw-r--r--arch/score/kernel/process.c4
-rw-r--r--arch/sh/kernel/cpu/sh5/entry.S2
-rw-r--r--arch/sh/kernel/entry-common.S2
-rw-r--r--arch/sparc/kernel/module.c13
-rw-r--r--arch/tile/include/gxio/iorpc_trio.h24
-rw-r--r--arch/um/drivers/mconsole_kern.c1
-rw-r--r--arch/um/include/asm/processor-generic.h9
-rw-r--r--arch/um/include/shared/common-offsets.h10
-rw-r--r--arch/um/include/shared/user.h11
-rw-r--r--arch/um/kernel/exec.c25
-rw-r--r--arch/um/kernel/process.c8
-rw-r--r--arch/um/kernel/signal.c6
-rw-r--r--arch/um/kernel/syscall.c24
-rw-r--r--arch/um/scripts/Makefile.rules2
-rw-r--r--arch/x86/Kconfig9
-rw-r--r--arch/x86/Makefile2
-rw-r--r--arch/x86/include/asm/hpet.h2
-rw-r--r--arch/x86/include/asm/rcu.h32
-rw-r--r--arch/x86/include/asm/thread_info.h10
-rw-r--r--arch/x86/include/asm/xen/page.h3
-rw-r--r--arch/x86/kernel/cpu/perf_event.h2
-rw-r--r--arch/x86/kernel/cpu/perf_event_amd_ibs.c12
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel.c25
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_ds.c14
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_lbr.c3
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore.c6
-rw-r--r--arch/x86/kernel/cpuid.c5
-rw-r--r--arch/x86/kernel/entry_64.S9
-rw-r--r--arch/x86/kernel/msr.c5
-rw-r--r--arch/x86/kernel/ptrace.c5
-rw-r--r--arch/x86/kernel/signal.c4
-rw-r--r--arch/x86/kernel/traps.c109
-rw-r--r--arch/x86/kvm/i8259.c2
-rw-r--r--arch/x86/kvm/vmx.c23
-rw-r--r--arch/x86/kvm/x86.c13
-rw-r--r--arch/x86/mm/fault.c13
-rw-r--r--arch/x86/mm/init.c2
-rw-r--r--arch/x86/um/Kconfig1
-rw-r--r--arch/x86/um/shared/sysdep/kernel-offsets.h3
-rw-r--r--arch/x86/um/shared/sysdep/syscalls.h2
-rw-r--r--arch/x86/um/signal.c6
-rw-r--r--arch/x86/um/sys_call_table_32.c2
-rw-r--r--arch/x86/um/syscalls_32.c27
-rw-r--r--arch/x86/um/syscalls_64.c23
-rw-r--r--arch/x86/xen/enlighten.c4
-rw-r--r--arch/x86/xen/p2m.c27
-rw-r--r--arch/x86/xen/setup.c4
-rw-r--r--arch/xtensa/kernel/process.c3
-rw-r--r--block/blk-core.c8
-rw-r--r--block/ioctl.c2
-rw-r--r--crypto/authenc.c4
-rw-r--r--drivers/acpi/bus.c10
-rw-r--r--drivers/acpi/power.c36
-rw-r--r--drivers/ata/ahci.c10
-rw-r--r--drivers/base/regmap/regmap-irq.c92
-rw-r--r--drivers/base/regmap/regmap.c13
-rw-r--r--drivers/block/aoe/aoecmd.c1
-rw-r--r--drivers/block/cciss_scsi.c1
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c38
-rw-r--r--drivers/block/mtip32xx/mtip32xx.h10
-rw-r--r--drivers/block/nbd.c9
-rw-r--r--drivers/block/nvme.c153
-rw-r--r--drivers/block/rbd.c7
-rw-r--r--drivers/block/xen-blkback/blkback.c2
-rw-r--r--drivers/bluetooth/ath3k.c2
-rw-r--r--drivers/bluetooth/btusb.c12
-rw-r--r--drivers/clk/Makefile1
-rw-r--r--drivers/clk/clk-devres.c55
-rw-r--r--drivers/clk/clkdev.c45
-rw-r--r--drivers/cpufreq/powernow-k8.c63
-rw-r--r--drivers/crypto/caam/key_gen.c1
-rw-r--r--drivers/dma/at_hdmac.c21
-rw-r--r--drivers/dma/ep93xx_dma.c2
-rw-r--r--drivers/dma/fsldma.c2
-rw-r--r--drivers/dma/imx-dma.c4
-rw-r--r--drivers/dma/intel_mid_dma.c2
-rw-r--r--drivers/dma/intel_mid_dma_regs.h6
-rw-r--r--drivers/dma/ioat/hw.h4
-rw-r--r--drivers/dma/pl330.c23
-rw-r--r--drivers/dma/ppc4xx/adma.c2
-rw-r--r--drivers/dma/ste_dma40_ll.h2
-rw-r--r--drivers/edac/edac_mc.c57
-rw-r--r--drivers/edac/i3200_edac.c2
-rw-r--r--drivers/edac/i5000_edac.c4
-rw-r--r--drivers/edac/sb_edac.c7
-rw-r--r--drivers/extcon/extcon-arizona.c5
-rw-r--r--drivers/extcon/extcon-max77693.c19
-rw-r--r--drivers/gpio/gpio-lpc32xx.c5
-rw-r--r--drivers/gpu/drm/ast/ast_drv.c3
-rw-r--r--drivers/gpu/drm/ast/ast_mode.c2
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_drv.c3
-rw-r--r--drivers/gpu/drm/exynos/Kconfig2
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_dmabuf.c7
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.c5
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fimd.c5
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_g2d.c52
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_gem.c4
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_hdmi.c3
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_plane.c1
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_vidi.c4
-rw-r--r--drivers/gpu/drm/exynos/exynos_hdmi.c11
-rw-r--r--drivers/gpu/drm/exynos/exynos_mixer.c6
-rw-r--r--drivers/gpu/drm/gma500/oaktrail_device.c2
-rw-r--r--drivers/gpu/drm/i810/i810_dma.c3
-rw-r--r--drivers/gpu/drm/i810/i810_drv.c3
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c1
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c3
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c3
-rw-r--r--drivers/gpu/drm/i915/intel_display.c18
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c11
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c2
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c31
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c3
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c15
-rw-r--r--drivers/gpu/drm/mgag200/mgag200_drv.c3
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_abi16.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_display.c2
-rw-r--r--drivers/gpu/drm/nouveau/nv50_gpio.c16
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_fb.c1
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_fifo.c3
-rw-r--r--drivers/gpu/drm/nouveau/nvd0_display.c4
-rw-r--r--drivers/gpu/drm/nouveau/nve0_fifo.c3
-rw-r--r--drivers/gpu/drm/radeon/r100.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_fence.c8
-rw-r--r--drivers/gpu/drm/savage/savage_drv.c3
-rw-r--r--drivers/gpu/drm/sis/sis_drv.c3
-rw-r--r--drivers/gpu/drm/tdfx/tdfx_drv.c3
-rw-r--r--drivers/gpu/drm/udl/udl_connector.c7
-rw-r--r--drivers/gpu/drm/udl/udl_drv.c3
-rw-r--r--drivers/gpu/drm/via/via_drv.c3
-rw-r--r--drivers/gpu/drm/vmwgfx/Kconfig8
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c8
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h10
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_fence.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c73
-rw-r--r--drivers/hid/Kconfig22
-rw-r--r--drivers/hid/Makefile21
-rw-r--r--drivers/hid/hid-a4tech.c1
-rw-r--r--drivers/hid/hid-apple.c1
-rw-r--r--drivers/hid/hid-aureal.c1
-rw-r--r--drivers/hid/hid-belkin.c1
-rw-r--r--drivers/hid/hid-cherry.c1
-rw-r--r--drivers/hid/hid-core.c38
-rw-r--r--drivers/hid/hid-cypress.c1
-rw-r--r--drivers/hid/hid-debug.c12
-rw-r--r--drivers/hid/hid-ezkey.c1
-rw-r--r--drivers/hid/hid-gyration.c1
-rw-r--r--drivers/hid/hid-holtekff.c3
-rw-r--r--drivers/hid/hid-ids.h16
-rw-r--r--drivers/hid/hid-input.c11
-rw-r--r--drivers/hid/hid-lcpower.c2
-rw-r--r--drivers/hid/hid-lenovo-tpkbd.c149
-rw-r--r--drivers/hid/hid-lg.c20
-rw-r--r--drivers/hid/hid-lg.h4
-rw-r--r--drivers/hid/hid-lg4ff.c198
-rw-r--r--drivers/hid/hid-logitech-dj.c45
-rw-r--r--drivers/hid/hid-logitech-dj.h1
-rw-r--r--drivers/hid/hid-magicmouse.c2
-rw-r--r--drivers/hid/hid-microsoft.c1
-rw-r--r--drivers/hid/hid-monterey.c1
-rw-r--r--drivers/hid/hid-multitouch.c252
-rw-r--r--drivers/hid/hid-ntrig.c8
-rw-r--r--drivers/hid/hid-petalynx.c1
-rw-r--r--drivers/hid/hid-picolcd.c2748
-rw-r--r--drivers/hid/hid-picolcd.h309
-rw-r--r--drivers/hid/hid-picolcd_backlight.c122
-rw-r--r--drivers/hid/hid-picolcd_cir.c152
-rw-r--r--drivers/hid/hid-picolcd_core.c689
-rw-r--r--drivers/hid/hid-picolcd_debugfs.c899
-rw-r--r--drivers/hid/hid-picolcd_fb.c615
-rw-r--r--drivers/hid/hid-picolcd_lcd.c107
-rw-r--r--drivers/hid/hid-picolcd_leds.c175
-rw-r--r--drivers/hid/hid-primax.c25
-rw-r--r--drivers/hid/hid-prodikeys.c18
-rw-r--r--drivers/hid/hid-ps3remote.c215
-rw-r--r--drivers/hid/hid-samsung.c1
-rw-r--r--drivers/hid/hid-sony.c1
-rw-r--r--drivers/hid/hid-sunplus.c1
-rw-r--r--drivers/hid/hid-uclogic.c98
-rw-r--r--drivers/hid/hid-wacom.c170
-rw-r--r--drivers/hid/hid-waltop.c29
-rw-r--r--drivers/hid/hid-wiimote-ext.c97
-rw-r--r--drivers/hid/hidraw.c84
-rw-r--r--drivers/hid/usbhid/hid-core.c6
-rw-r--r--drivers/hid/usbhid/hid-quirks.c3
-rw-r--r--drivers/hwmon/ad7314.c8
-rw-r--r--drivers/hwmon/ads7871.c9
-rw-r--r--drivers/hwmon/applesmc.c4
-rw-r--r--drivers/hwmon/coretemp.c5
-rw-r--r--drivers/hwmon/fam15h_power.c15
-rw-r--r--drivers/hwmon/ina2xx.c30
-rw-r--r--drivers/hwmon/twl4030-madc-hwmon.c9
-rw-r--r--drivers/hwmon/via-cputemp.c5
-rw-r--r--drivers/hwspinlock/hwspinlock_core.c3
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c6
-rw-r--r--drivers/i2c/busses/Kconfig6
-rw-r--r--drivers/i2c/busses/Makefile5
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c11
-rw-r--r--drivers/i2c/busses/i2c-i801.c3
-rw-r--r--drivers/i2c/busses/i2c-mxs.c13
-rw-r--r--drivers/i2c/busses/i2c-pnx.c53
-rw-r--r--drivers/i2c/i2c-core.c22
-rw-r--r--drivers/iio/adc/at91_adc.c2
-rw-r--r--drivers/infiniband/hw/cxgb4/cm.c2
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.c250
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.h6
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_verbs.c8
-rw-r--r--drivers/infiniband/hw/qib/qib_mad.c3
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h5
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c93
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c2
-rw-r--r--drivers/input/evdev.c78
-rw-r--r--drivers/input/input-mt.c305
-rw-r--r--drivers/input/input.c254
-rw-r--r--drivers/input/keyboard/imx_keypad.c4
-rw-r--r--drivers/input/misc/ab8500-ponkey.c4
-rw-r--r--drivers/input/misc/uinput.c2
-rw-r--r--drivers/input/mouse/alps.c2
-rw-r--r--drivers/input/mouse/bcm5974.c348
-rw-r--r--drivers/input/mouse/elantech.c4
-rw-r--r--drivers/input/mouse/sentelic.c13
-rw-r--r--drivers/input/mouse/synaptics.c4
-rw-r--r--drivers/input/serio/ambakmi.c6
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h6
-rw-r--r--drivers/input/tablet/wacom_wac.c6
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c2
-rw-r--r--drivers/input/touchscreen/cyttsp_core.c2
-rw-r--r--drivers/input/touchscreen/edt-ft5x06.c11
-rw-r--r--drivers/input/touchscreen/egalax_ts.c2
-rw-r--r--drivers/input/touchscreen/ili210x.c2
-rw-r--r--drivers/input/touchscreen/mms114.c2
-rw-r--r--drivers/input/touchscreen/penmount.c2
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c40
-rw-r--r--drivers/input/touchscreen/wacom_w8001.c2
-rw-r--r--drivers/iommu/amd_iommu.c6
-rw-r--r--drivers/isdn/hardware/mISDN/avmfritz.c3
-rw-r--r--drivers/isdn/hardware/mISDN/hfcmulti.c2
-rw-r--r--drivers/isdn/hardware/mISDN/mISDNipac.c3
-rw-r--r--drivers/isdn/hardware/mISDN/mISDNisar.c3
-rw-r--r--drivers/isdn/hardware/mISDN/netjet.c3
-rw-r--r--drivers/isdn/hardware/mISDN/w6692.c3
-rw-r--r--drivers/isdn/mISDN/hwchannel.c9
-rw-r--r--drivers/md/dm-mpath.c11
-rw-r--r--drivers/md/dm-table.c61
-rw-r--r--drivers/md/dm-thin.c135
-rw-r--r--drivers/md/dm-verity.c8
-rw-r--r--drivers/md/dm.c71
-rw-r--r--drivers/md/dm.h1
-rw-r--r--drivers/md/md.c6
-rw-r--r--drivers/md/raid10.c8
-rw-r--r--drivers/md/raid5.c7
-rw-r--r--drivers/mfd/88pm800.c5
-rw-r--r--drivers/mfd/88pm805.c3
-rw-r--r--drivers/mfd/88pm860x-core.c21
-rw-r--r--drivers/mfd/aat2870-core.c2
-rw-r--r--drivers/mfd/ab3100-core.c2
-rw-r--r--drivers/mfd/ab8500-core.c10
-rw-r--r--drivers/mfd/ab8500-gpadc.c2
-rw-r--r--drivers/mfd/arizona-core.c6
-rw-r--r--drivers/mfd/asic3.c6
-rw-r--r--drivers/mfd/cs5535-mfd.c2
-rw-r--r--drivers/mfd/da9052-core.c2
-rw-r--r--drivers/mfd/davinci_voicecodec.c2
-rw-r--r--drivers/mfd/db8500-prcmu.c2
-rw-r--r--drivers/mfd/htc-pasic3.c5
-rw-r--r--drivers/mfd/intel_msic.c4
-rw-r--r--drivers/mfd/janz-cmodio.c2
-rw-r--r--drivers/mfd/jz4740-adc.c3
-rw-r--r--drivers/mfd/lm3533-core.c7
-rw-r--r--drivers/mfd/lpc_ich.c24
-rw-r--r--drivers/mfd/lpc_sch.c6
-rw-r--r--drivers/mfd/max77686.c2
-rw-r--r--drivers/mfd/max77693-irq.c36
-rw-r--r--drivers/mfd/max77693.c16
-rw-r--r--drivers/mfd/max8925-core.c12
-rw-r--r--drivers/mfd/max8997.c2
-rw-r--r--drivers/mfd/max8998.c8
-rw-r--r--drivers/mfd/mc13xxx-core.c2
-rw-r--r--drivers/mfd/mfd-core.c12
-rw-r--r--drivers/mfd/palmas.c3
-rw-r--r--drivers/mfd/rc5t583.c4
-rw-r--r--drivers/mfd/rdc321x-southbridge.c5
-rw-r--r--drivers/mfd/sec-core.c8
-rw-r--r--drivers/mfd/sta2x11-mfd.c4
-rw-r--r--drivers/mfd/stmpe.c2
-rw-r--r--drivers/mfd/t7l66xb.c2
-rw-r--r--drivers/mfd/tc3589x.c8
-rw-r--r--drivers/mfd/tc6387xb.c2
-rw-r--r--drivers/mfd/tc6393xb.c4
-rw-r--r--drivers/mfd/ti-ssp.c2
-rw-r--r--drivers/mfd/timberdale.c12
-rw-r--r--drivers/mfd/tps6105x.c2
-rw-r--r--drivers/mfd/tps6507x.c2
-rw-r--r--drivers/mfd/tps65090.c2
-rw-r--r--drivers/mfd/tps65217.c130
-rw-r--r--drivers/mfd/tps6586x.c16
-rw-r--r--drivers/mfd/tps65910.c2
-rw-r--r--drivers/mfd/tps65911-comparator.c2
-rw-r--r--drivers/mfd/tps65912-core.c2
-rw-r--r--drivers/mfd/twl4030-audio.c2
-rw-r--r--drivers/mfd/twl6040-core.c2
-rw-r--r--drivers/mfd/vx855.c2
-rw-r--r--drivers/mfd/wl1273-core.c2
-rw-r--r--drivers/mfd/wm831x-core.c16
-rw-r--r--drivers/mfd/wm8400-core.c2
-rw-r--r--drivers/mfd/wm8994-core.c4
-rw-r--r--drivers/mfd/wm8994-irq.c1
-rw-r--r--drivers/mmc/core/sdio.c2
-rw-r--r--drivers/mmc/host/at91_mci.c2
-rw-r--r--drivers/mmc/host/atmel-mci.c2
-rw-r--r--drivers/mmc/host/omap_hsmmc.c2
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c2
-rw-r--r--drivers/mmc/host/vub300.c2
-rw-r--r--drivers/mtd/mtdchar.c48
-rw-r--r--drivers/net/can/janz-ican3.c4
-rw-r--r--drivers/net/can/mcp251x.c11
-rw-r--r--drivers/net/can/ti_hecc.c2
-rw-r--r--drivers/net/ethernet/3com/typhoon.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x.h2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c12
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h11
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_dump.h25
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c8
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c18
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c32
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c15
-rw-r--r--drivers/net/ethernet/cadence/at91_ether.c2
-rw-r--r--drivers/net/ethernet/freescale/gianfar_ethtool.c1
-rw-r--r--drivers/net/ethernet/freescale/gianfar_ptp.c4
-rw-r--r--drivers/net/ethernet/i825xx/znet.c13
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.c26
-rw-r--r--drivers/net/ethernet/intel/e1000/e1000_main.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/icm.c30
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/icm.h10
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/main.c16
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mcg.c106
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4.h76
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/resource_tracker.c116
-rw-r--r--drivers/net/ethernet/octeon/octeon_mgmt.c4
-rw-r--r--drivers/net/ethernet/pasemi/pasemi_mac.c4
-rw-r--r--drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c4
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c4
-rw-r--r--drivers/net/ethernet/seeq/sgiseeq.c1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c10
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_timer.c8
-rw-r--r--drivers/net/irda/sh_sir.c2
-rw-r--r--drivers/net/phy/bcm87xx.c2
-rw-r--r--drivers/net/phy/micrel.c45
-rw-r--r--drivers/net/phy/smsc.c28
-rw-r--r--drivers/net/ppp/pppoe.c2
-rw-r--r--drivers/net/team/team.c44
-rw-r--r--drivers/net/usb/asix_devices.c4
-rw-r--r--drivers/net/usb/qmi_wwan.c20
-rw-r--r--drivers/net/usb/sierra_net.c2
-rw-r--r--drivers/net/usb/smsc75xx.c1
-rw-r--r--drivers/net/usb/usbnet.c16
-rw-r--r--drivers/net/wan/ixp4xx_hss.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_paprd.c105
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.h4
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/gpio.c3
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c11
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h4
-rw-r--r--drivers/net/wireless/ath/ath9k/link.c20
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c3
-rw-r--r--drivers/net/wireless/b43/Kconfig4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c26
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb.c30
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c21
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/channel.c2
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c1
-rw-r--r--drivers/net/wireless/libertas/if_sdio.c5
-rw-r--r--drivers/net/wireless/mwifiex/cmdevt.c15
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c9
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.h1
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c9
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c11
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.h17
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt2800pci.c9
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c22
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c9
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.h1
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c9
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.h3
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c6
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/def.h1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/hw.c12
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/sw.c6
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/fw.c6
-rw-r--r--drivers/pci/.gitignore4
-rw-r--r--drivers/platform/x86/acer-wmi.c2
-rw-r--r--drivers/platform/x86/apple-gmux.c24
-rw-r--r--drivers/platform/x86/asus-laptop.c10
-rw-r--r--drivers/platform/x86/asus-wmi.c4
-rw-r--r--drivers/platform/x86/eeepc-laptop.c10
-rw-r--r--drivers/platform/x86/samsung-laptop.c4
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c13
-rw-r--r--drivers/pwm/pwm-tiecap.c7
-rw-r--r--drivers/pwm/pwm-tiehrpwm.c29
-rw-r--r--drivers/regulator/Kconfig38
-rw-r--r--drivers/regulator/Makefile2
-rw-r--r--drivers/regulator/aat2870-regulator.c2
-rw-r--r--drivers/regulator/ab3100.c6
-rw-r--r--drivers/regulator/ab8500.c36
-rw-r--r--drivers/regulator/arizona-ldo1.c6
-rw-r--r--drivers/regulator/arizona-micsupp.c5
-rw-r--r--drivers/regulator/core.c153
-rw-r--r--drivers/regulator/da9052-regulator.c4
-rw-r--r--drivers/regulator/dummy.c2
-rw-r--r--drivers/regulator/fan53555.c322
-rw-r--r--drivers/regulator/isl6271a-regulator.c6
-rw-r--r--drivers/regulator/lp872x.c88
-rw-r--r--drivers/regulator/lp8788-buck.c80
-rw-r--r--drivers/regulator/lp8788-ldo.c8
-rw-r--r--drivers/regulator/max77686.c30
-rw-r--r--drivers/regulator/max8907-regulator.c408
-rw-r--r--drivers/regulator/mc13783-regulator.c89
-rw-r--r--drivers/regulator/mc13892-regulator.c77
-rw-r--r--drivers/regulator/mc13xxx-regulator-core.c17
-rw-r--r--drivers/regulator/mc13xxx.h1
-rw-r--r--drivers/regulator/of_regulator.c25
-rw-r--r--drivers/regulator/palmas-regulator.c45
-rw-r--r--drivers/regulator/s2mps11.c27
-rw-r--r--drivers/regulator/tps65217-regulator.c124
-rw-r--r--drivers/regulator/tps6524x-regulator.c10
-rw-r--r--drivers/regulator/tps6586x-regulator.c96
-rw-r--r--drivers/regulator/twl-regulator.c110
-rw-r--r--drivers/regulator/wm831x-dcdc.c11
-rw-r--r--drivers/regulator/wm831x-ldo.c12
-rw-r--r--drivers/regulator/wm8400-regulator.c7
-rw-r--r--drivers/rpmsg/virtio_rpmsg_bus.c6
-rw-r--r--drivers/rtc/rtc-twl.c5
-rw-r--r--drivers/s390/block/dasd.c17
-rw-r--r--drivers/s390/block/dasd_alias.c27
-rw-r--r--drivers/s390/block/dasd_eckd.c32
-rw-r--r--drivers/s390/cio/device.c7
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_core.c2
-rw-r--r--drivers/scsi/bfa/bfa_ioc.c2
-rw-r--r--drivers/scsi/bfa/bfa_ioc.h2
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_fcoe.c4
-rw-r--r--drivers/scsi/bnx2i/bnx2i_hwi.c3
-rw-r--r--drivers/scsi/gdth.h9
-rw-r--r--drivers/scsi/hpsa.c3
-rw-r--r--drivers/scsi/ipr.c66
-rw-r--r--drivers/scsi/isci/host.c2
-rw-r--r--drivers/scsi/isci/init.c2
-rw-r--r--drivers/scsi/isci/port.c2
-rw-r--r--drivers/scsi/isci/request.c2
-rw-r--r--drivers/scsi/isci/task.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c4
-rw-r--r--drivers/scsi/megaraid.c5
-rw-r--r--drivers/scsi/megaraid.h35
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c3
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.c20
-rw-r--r--drivers/scsi/mvumi.c6
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c6
-rw-r--r--drivers/scsi/scsi_error.c10
-rw-r--r--drivers/scsi/scsi_lib.c5
-rw-r--r--drivers/scsi/scsi_scan.c10
-rw-r--r--drivers/scsi/virtio_scsi.c2
-rw-r--r--drivers/scsi/vmw_pvscsi.c4
-rw-r--r--drivers/sh/intc/core.c2
-rw-r--r--drivers/sh/pfc/pinctrl.c5
-rw-r--r--drivers/spi/spi-au1550.c2
-rw-r--r--drivers/spi/spi-bfin-sport.c2
-rw-r--r--drivers/spi/spi-oc-tiny.c2
-rw-r--r--drivers/spi/spi-ppc4xx.c4
-rw-r--r--drivers/spi/spi-topcliff-pch.c2
-rw-r--r--drivers/staging/android/android_alarm.h4
-rw-r--r--drivers/staging/comedi/drivers/amplc_dio200.c7
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc236.c7
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc263.c7
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci224.c7
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci230.c7
-rw-r--r--drivers/staging/comedi/drivers/das08.c11
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_ring.c4
-rw-r--r--drivers/staging/iio/adc/ad7192.c2
-rw-r--r--drivers/staging/iio/gyro/adis16260_core.c2
-rw-r--r--drivers/staging/iio/imu/adis16400_core.c2
-rw-r--r--drivers/staging/iio/meter/ade7753.c2
-rw-r--r--drivers/staging/iio/meter/ade7754.c2
-rw-r--r--drivers/staging/iio/meter/ade7759.c2
-rw-r--r--drivers/staging/nvec/nvec.c2
-rw-r--r--drivers/staging/omapdrm/omap_connector.c41
-rw-r--r--drivers/staging/ozwpan/ozcdev.c3
-rw-r--r--drivers/staging/rtl8712/recv_linux.c7
-rw-r--r--drivers/staging/vt6656/dpc.c2
-rw-r--r--drivers/staging/vt6656/rxtx.c38
-rw-r--r--drivers/staging/wlan-ng/cfg80211.c4
-rw-r--r--drivers/staging/zcache/zcache-main.c7
-rw-r--r--drivers/target/iscsi/iscsi_target_login.c11
-rw-r--r--drivers/target/iscsi/iscsi_target_parameters.c4
-rw-r--r--drivers/target/target_core_alua.c7
-rw-r--r--drivers/target/target_core_device.c7
-rw-r--r--drivers/target/target_core_iblock.c17
-rw-r--r--drivers/target/target_core_pr.c8
-rw-r--r--drivers/target/target_core_pscsi.c29
-rw-r--r--drivers/target/target_core_spc.c35
-rw-r--r--drivers/target/target_core_transport.c148
-rw-r--r--drivers/tty/serial/imx.c30
-rw-r--r--drivers/usb/chipidea/udc.c59
-rw-r--r--drivers/usb/class/cdc-wdm.c12
-rw-r--r--drivers/usb/core/devices.c2
-rw-r--r--drivers/usb/core/hcd.c6
-rw-r--r--drivers/usb/core/quirks.c4
-rw-r--r--drivers/usb/dwc3/core.c9
-rw-r--r--drivers/usb/dwc3/ep0.c1
-rw-r--r--drivers/usb/dwc3/gadget.c19
-rw-r--r--drivers/usb/gadget/at91_udc.c6
-rw-r--r--drivers/usb/gadget/dummy_hcd.c41
-rw-r--r--drivers/usb/gadget/f_fs.c4
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c3
-rw-r--r--drivers/usb/gadget/u_serial.c4
-rw-r--r--drivers/usb/host/ehci-q.c12
-rw-r--r--drivers/usb/host/ohci-at91.c13
-rw-r--r--drivers/usb/host/pci-quirks.c42
-rw-r--r--drivers/usb/host/pci-quirks.h1
-rw-r--r--drivers/usb/host/xhci-hub.c42
-rw-r--r--drivers/usb/host/xhci-plat.c2
-rw-r--r--drivers/usb/host/xhci.c123
-rw-r--r--drivers/usb/host/xhci.h6
-rw-r--r--drivers/usb/musb/musb_host.c2
-rw-r--r--drivers/usb/musb/musbhsdma.c2
-rw-r--r--drivers/usb/musb/tusb6010.c2
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c4
-rw-r--r--drivers/usb/serial/ftdi_sio.c22
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h29
-rw-r--r--drivers/usb/serial/option.c6
-rw-r--r--drivers/vfio/pci/vfio_pci_intrs.c76
-rw-r--r--drivers/video/backlight/88pm860x_bl.c1
-rw-r--r--drivers/video/exynos/exynos_mipi_dsi.c2
-rw-r--r--drivers/video/tmiofb.c4
-rw-r--r--drivers/w1/masters/ds1wm.c2
-rw-r--r--drivers/watchdog/hpwdt.c3
-rw-r--r--drivers/watchdog/watchdog_core.c3
-rw-r--r--drivers/xen/gntdev.c5
-rw-r--r--drivers/xen/grant-table.c6
-rw-r--r--fs/btrfs/ctree.h2
-rw-r--r--fs/btrfs/delayed-ref.h2
-rw-r--r--fs/btrfs/inode.c4
-rw-r--r--fs/btrfs/qgroup.c8
-rw-r--r--fs/cifs/cifs_unicode.c2
-rw-r--r--fs/cifs/file.c2
-rw-r--r--fs/cifs/smb2pdu.h4
-rw-r--r--fs/dcache.c12
-rw-r--r--fs/debugfs/file.c76
-rw-r--r--fs/ecryptfs/file.c10
-rw-r--r--fs/ecryptfs/inode.c5
-rw-r--r--fs/ecryptfs/main.c1
-rw-r--r--fs/ext2/balloc.c2
-rw-r--r--fs/ext3/balloc.c2
-rw-r--r--fs/ext3/inode.c19
-rw-r--r--fs/ext4/inode.c14
-rw-r--r--fs/ext4/mballoc.c2
-rw-r--r--fs/fs-writeback.c4
-rw-r--r--fs/fuse/control.c4
-rw-r--r--fs/fuse/cuse.c4
-rw-r--r--fs/fuse/dev.c1
-rw-r--r--fs/fuse/inode.c12
-rw-r--r--fs/gfs2/aops.c11
-rw-r--r--fs/gfs2/bmap.c2
-rw-r--r--fs/gfs2/file.c35
-rw-r--r--fs/gfs2/glock.c60
-rw-r--r--fs/gfs2/glops.c1
-rw-r--r--fs/gfs2/incore.h30
-rw-r--r--fs/gfs2/inode.c28
-rw-r--r--fs/gfs2/ops_fstype.c8
-rw-r--r--fs/gfs2/quota.c11
-rw-r--r--fs/gfs2/rgrp.c1221
-rw-r--r--fs/gfs2/rgrp.h28
-rw-r--r--fs/gfs2/super.c9
-rw-r--r--fs/gfs2/trace_gfs2.h20
-rw-r--r--fs/gfs2/trans.h7
-rw-r--r--fs/gfs2/xattr.c96
-rw-r--r--fs/libfs.c2
-rw-r--r--fs/lockd/svclock.c3
-rw-r--r--fs/namespace.c10
-rw-r--r--fs/nfs/file.c4
-rw-r--r--fs/nfs/inode.c2
-rw-r--r--fs/nfs/nfs3proc.c2
-rw-r--r--fs/nfs/nfs4file.c4
-rw-r--r--fs/nfs/nfs4proc.c55
-rw-r--r--fs/nfs/nfs4xdr.c17
-rw-r--r--fs/nfs/super.c4
-rw-r--r--fs/proc/proc_sysctl.c5
-rw-r--r--fs/stat.c2
-rw-r--r--fs/udf/file.c35
-rw-r--r--fs/xfs/xfs_buf.c5
-rw-r--r--fs/xfs/xfs_buf.h41
-rw-r--r--fs/xfs/xfs_super.c1
-rw-r--r--include/asm-generic/unistd.h4
-rw-r--r--include/drm/drm_fourcc.h6
-rw-r--r--include/linux/atmel-ssc.h1
-rw-r--r--include/linux/compiler-gcc4.h7
-rw-r--r--include/linux/compiler.h4
-rw-r--r--include/linux/dcache.h2
-rw-r--r--include/linux/hid.h5
-rw-r--r--include/linux/i2c-pnx.h1
-rw-r--r--include/linux/input.h35
-rw-r--r--include/linux/input/mt.h57
-rw-r--r--include/linux/interrupt.h2
-rw-r--r--include/linux/iommu.h42
-rw-r--r--include/linux/irqdesc.h2
-rw-r--r--include/linux/kernel.h2
-rw-r--r--include/linux/kobject.h2
-rw-r--r--include/linux/kthread.h11
-rw-r--r--include/linux/mISDNhw.h2
-rw-r--r--include/linux/memory.h2
-rw-r--r--include/linux/mfd/core.h4
-rw-r--r--include/linux/mfd/max77686.h1
-rw-r--r--include/linux/mfd/max8998.h2
-rw-r--r--include/linux/mfd/tps65217.h12
-rw-r--r--include/linux/mfd/tps6586x.h1
-rw-r--r--include/linux/micrel_phy.h19
-rw-r--r--include/linux/mlx4/device.h13
-rw-r--r--include/linux/nfs_fs.h5
-rw-r--r--include/linux/nfs_xdr.h2
-rw-r--r--include/linux/nvme.h2
-rw-r--r--include/linux/perf_event.h6
-rw-r--r--include/linux/rcupdate.h21
-rw-r--r--include/linux/regmap.h3
-rw-r--r--include/linux/regulator/consumer.h15
-rw-r--r--include/linux/regulator/driver.h18
-rw-r--r--include/linux/regulator/fan53555.h60
-rw-r--r--include/linux/regulator/machine.h2
-rw-r--r--include/linux/sched.h9
-rw-r--r--include/linux/security.h1
-rw-r--r--include/linux/smpboot.h43
-rw-r--r--include/linux/sunrpc/xprt.h3
-rw-r--r--include/linux/task_work.h3
-rw-r--r--include/linux/xfrm.h2
-rw-r--r--include/net/bluetooth/smp.h2
-rw-r--r--include/net/ip6_fib.h5
-rw-r--r--include/net/net_namespace.h10
-rw-r--r--include/net/netns/ipv4.h1
-rw-r--r--include/net/route.h2
-rw-r--r--include/net/sock.h2
-rw-r--r--include/net/xfrm.h3
-rw-r--r--include/target/target_core_backend.h4
-rw-r--r--include/target/target_core_base.h1
-rw-r--r--include/trace/define_trace.h2
-rw-r--r--include/trace/events/kmem.h4
-rw-r--r--include/xen/grant_table.h3
-rw-r--r--init/Kconfig18
-rw-r--r--kernel/Kconfig.locks103
-rw-r--r--kernel/Makefile3
-rw-r--r--kernel/cpu.c10
-rw-r--r--kernel/events/core.c64
-rw-r--r--kernel/events/hw_breakpoint.c11
-rw-r--r--kernel/irq/chip.c1
-rw-r--r--kernel/irq/dummychip.c2
-rw-r--r--kernel/kthread.c185
-rw-r--r--kernel/lockdep.c39
-rw-r--r--kernel/pid_namespace.c6
-rw-r--r--kernel/rcupdate.c4
-rw-r--r--kernel/rcutiny.c33
-rw-r--r--kernel/rcutiny_plugin.h10
-rw-r--r--kernel/rcutorture.c159
-rw-r--r--kernel/rcutree.c916
-rw-r--r--kernel/rcutree.h50
-rw-r--r--kernel/rcutree_plugin.h597
-rw-r--r--kernel/rcutree_trace.c22
-rw-r--r--kernel/sched/core.c92
-rw-r--r--kernel/sched/fair.c37
-rw-r--r--kernel/sched/rt.c1
-rw-r--r--kernel/sched/sched.h1
-rw-r--r--kernel/signal.c18
-rw-r--r--kernel/smpboot.c233
-rw-r--r--kernel/smpboot.h4
-rw-r--r--kernel/softirq.c111
-rw-r--r--kernel/task_work.c111
-rw-r--r--kernel/time/tick-sched.c4
-rw-r--r--kernel/time/timekeeping.c19
-rw-r--r--kernel/watchdog.c263
-rw-r--r--kernel/workqueue.c147
-rw-r--r--lib/Kconfig.debug14
-rw-r--r--lib/digsig.c6
-rw-r--r--lib/flex_proportions.c2
-rw-r--r--mm/bootmem.c2
-rw-r--r--mm/huge_memory.c1
-rw-r--r--mm/kmemleak.c6
-rw-r--r--mm/memblock.c2
-rw-r--r--mm/memory_hotplug.c16
-rw-r--r--mm/page_alloc.c2
-rw-r--r--mm/slab.c6
-rw-r--r--mm/slub.c15
-rw-r--r--mm/vmscan.c1
-rw-r--r--net/8021q/vlanproc.c2
-rw-r--r--net/batman-adv/bat_iv_ogm.c13
-rw-r--r--net/batman-adv/bitarray.h6
-rw-r--r--net/batman-adv/soft-interface.c7
-rw-r--r--net/bluetooth/bnep/sock.c4
-rw-r--r--net/bluetooth/cmtp/sock.c4
-rw-r--r--net/bluetooth/hci_conn.c4
-rw-r--r--net/bluetooth/hci_core.c2
-rw-r--r--net/bluetooth/hci_sock.c16
-rw-r--r--net/bluetooth/hidp/sock.c4
-rw-r--r--net/bluetooth/l2cap_core.c13
-rw-r--r--net/bluetooth/l2cap_sock.c2
-rw-r--r--net/bluetooth/mgmt.c16
-rw-r--r--net/bluetooth/smp.c10
-rw-r--r--net/bridge/netfilter/ebt_log.c2
-rw-r--r--net/caif/cfsrvl.c5
-rw-r--r--net/ceph/messenger.c5
-rw-r--r--net/core/dev.c16
-rw-r--r--net/core/pktgen.c2
-rw-r--r--net/core/skbuff.c4
-rw-r--r--net/core/sock.c12
-rw-r--r--net/ipv4/arp.c2
-rw-r--r--net/ipv4/devinet.c10
-rw-r--r--net/ipv4/fib_frontend.c20
-rw-r--r--net/ipv4/fib_rules.c2
-rw-r--r--net/ipv4/fib_trie.c6
-rw-r--r--net/ipv4/inetpeer.c5
-rw-r--r--net/ipv4/raw.c14
-rw-r--r--net/ipv4/route.c43
-rw-r--r--net/ipv4/tcp.c23
-rw-r--r--net/ipv4/tcp_input.c5
-rw-r--r--net/ipv4/udp.c5
-rw-r--r--net/ipv6/inet6_connection_sock.c23
-rw-r--r--net/ipv6/ip6_fib.c4
-rw-r--r--net/ipv6/mip6.c20
-rw-r--r--net/ipv6/raw.c21
-rw-r--r--net/ipv6/route.c19
-rw-r--r--net/ipv6/tcp_ipv6.c5
-rw-r--r--net/ipv6/udp.c11
-rw-r--r--net/l2tp/l2tp_core.c4
-rw-r--r--net/l2tp/l2tp_eth.c2
-rw-r--r--net/l2tp/l2tp_netlink.c12
-rw-r--r--net/mac80211/cfg.c9
-rw-r--r--net/mac80211/mlme.c4
-rw-r--r--net/netfilter/nf_conntrack_proto_tcp.c29
-rw-r--r--net/netfilter/nfnetlink_log.c14
-rw-r--r--net/netfilter/xt_LOG.c37
-rw-r--r--net/netfilter/xt_limit.c8
-rw-r--r--net/netrom/af_netrom.c9
-rw-r--r--net/openvswitch/actions.c2
-rw-r--r--net/openvswitch/datapath.c6
-rw-r--r--net/openvswitch/flow.h8
-rw-r--r--net/sched/sch_cbq.c5
-rw-r--r--net/sched/sch_fq_codel.c2
-rw-r--r--net/sched/sch_gred.c38
-rw-r--r--net/sched/sch_qfq.c5
-rw-r--r--net/sctp/output.c21
-rw-r--r--net/sunrpc/xprt.c34
-rw-r--r--net/sunrpc/xprtrdma/transport.c1
-rw-r--r--net/sunrpc/xprtsock.c3
-rw-r--r--net/wireless/nl80211.c4
-rw-r--r--net/wireless/reg.c12
-rw-r--r--net/xfrm/xfrm_input.c2
-rw-r--r--net/xfrm/xfrm_policy.c3
-rw-r--r--net/xfrm/xfrm_replay.c15
-rw-r--r--net/xfrm/xfrm_user.c57
-rw-r--r--scripts/Makefile.fwinst4
-rwxr-xr-xscripts/checksyscalls.sh2
-rw-r--r--scripts/coccinelle/api/memdup_user.cocci4
-rw-r--r--scripts/kconfig/streamline_config.pl50
-rw-r--r--scripts/link-vmlinux.sh7
-rw-r--r--security/apparmor/.gitignore1
-rw-r--r--security/keys/keyctl.c2
-rw-r--r--security/selinux/include/xfrm.h1
-rw-r--r--sound/core/compress_offload.c8
-rw-r--r--sound/oss/.gitignore1
-rw-r--r--sound/pci/hda/hda_codec.c2
-rw-r--r--sound/pci/hda/hda_intel.c2
-rw-r--r--sound/pci/hda/patch_sigmatel.c2
-rw-r--r--sound/pci/ice1712/prodigy_hifi.c3
-rw-r--r--sound/soc/codecs/arizona.c2
-rw-r--r--sound/soc/codecs/mc13783.c8
-rw-r--r--sound/soc/codecs/wm2000.c2
-rw-r--r--sound/soc/codecs/wm8904.c2
-rw-r--r--sound/soc/fsl/imx-sgtl5000.c2
-rw-r--r--sound/soc/omap/am3517evm.c2
-rw-r--r--sound/soc/samsung/dma.c8
-rw-r--r--sound/soc/soc-dapm.c5
-rw-r--r--sound/soc/spear/spear_pcm.c2
-rw-r--r--sound/soc/tegra/tegra_alc5632.c1
-rw-r--r--sound/soc/tegra/tegra_pcm.c4
-rw-r--r--sound/soc/ux500/ux500_msp_i2s.c25
-rw-r--r--sound/usb/endpoint.c8
-rw-r--r--sound/usb/pcm.c6
-rw-r--r--tools/perf/util/callchain.h2
-rw-r--r--tools/perf/util/parse-events-test.c2
-rw-r--r--tools/perf/util/python-ext-sources2
-rw-r--r--tools/testing/ktest/examples/include/defaults.conf2
-rw-r--r--tools/testing/ktest/examples/include/tests.conf2
-rwxr-xr-xtools/testing/ktest/ktest.pl4
-rw-r--r--tools/testing/selftests/vm/run_vmtests6
885 files changed, 14473 insertions, 9491 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-regulator b/Documentation/ABI/testing/sysfs-class-regulator
index e091fa873792..bc578bc60628 100644
--- a/Documentation/ABI/testing/sysfs-class-regulator
+++ b/Documentation/ABI/testing/sysfs-class-regulator
@@ -349,3 +349,24 @@ Description:
349 349
350 This will be one of the same strings reported by 350 This will be one of the same strings reported by
351 the "state" attribute. 351 the "state" attribute.
352
353What: /sys/class/regulator/.../bypass
354Date: September 2012
355KernelVersion: 3.7
356Contact: Mark Brown <broonie@opensource.wolfsonmicro.com>
357Description:
358 Some regulator directories will contain a field called
359 bypass. This indicates if the device is in bypass mode.
360
361 This will be one of the following strings:
362
363 'enabled'
364 'disabled'
365 'unknown'
366
367 'enabled' means the regulator is in bypass mode.
368
369 'disabled' means that the regulator is regulating.
370
371 'unknown' means software cannot determine the state, or
372 the reported state is invalid.
diff --git a/Documentation/ABI/testing/sysfs-driver-wacom b/Documentation/ABI/testing/sysfs-driver-wacom
index 8d55a83d6921..7fc781048b79 100644
--- a/Documentation/ABI/testing/sysfs-driver-wacom
+++ b/Documentation/ABI/testing/sysfs-driver-wacom
@@ -1,3 +1,16 @@
1WWhat: /sys/class/hidraw/hidraw*/device/oled*_img
2Date: June 2012
3Contact: linux-bluetooth@vger.kernel.org
4Description:
5 The /sys/class/hidraw/hidraw*/device/oled*_img files control
6 OLED mocro displays on Intuos4 Wireless tablet. Accepted image
7 has to contain 256 bytes (64x32 px 1 bit colour). The format
8 is the same as PBM image 62x32px without header (64 bits per
9 horizontal line, 32 lines). An example of setting OLED No. 0:
10 dd bs=256 count=1 if=img_file of=[path to oled0_img]/oled0_img
11 The attribute is read only and no local copy of the image is
12 stored.
13
1What: /sys/class/hidraw/hidraw*/device/speed 14What: /sys/class/hidraw/hidraw*/device/speed
2Date: April 2010 15Date: April 2010
3Kernel Version: 2.6.35 16Kernel Version: 2.6.35
diff --git a/Documentation/RCU/checklist.txt b/Documentation/RCU/checklist.txt
index fc103d7a0474..cdb20d41a44a 100644
--- a/Documentation/RCU/checklist.txt
+++ b/Documentation/RCU/checklist.txt
@@ -310,6 +310,12 @@ over a rather long period of time, but improvements are always welcome!
310 code under the influence of preempt_disable(), you instead 310 code under the influence of preempt_disable(), you instead
311 need to use synchronize_irq() or synchronize_sched(). 311 need to use synchronize_irq() or synchronize_sched().
312 312
313 This same limitation also applies to synchronize_rcu_bh()
314 and synchronize_srcu(), as well as to the asynchronous and
315 expedited forms of the three primitives, namely call_rcu(),
316 call_rcu_bh(), call_srcu(), synchronize_rcu_expedited(),
317 synchronize_rcu_bh_expedited(), and synchronize_srcu_expedited().
318
31312. Any lock acquired by an RCU callback must be acquired elsewhere 31912. Any lock acquired by an RCU callback must be acquired elsewhere
314 with softirq disabled, e.g., via spin_lock_irqsave(), 320 with softirq disabled, e.g., via spin_lock_irqsave(),
315 spin_lock_bh(), etc. Failing to disable irq on a given 321 spin_lock_bh(), etc. Failing to disable irq on a given
diff --git a/Documentation/RCU/stallwarn.txt b/Documentation/RCU/stallwarn.txt
index 523364e4e1f1..1927151b386b 100644
--- a/Documentation/RCU/stallwarn.txt
+++ b/Documentation/RCU/stallwarn.txt
@@ -99,7 +99,7 @@ In kernels with CONFIG_RCU_FAST_NO_HZ, even more information is
99printed: 99printed:
100 100
101 INFO: rcu_preempt detected stall on CPU 101 INFO: rcu_preempt detected stall on CPU
102 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 drain=0 . timer=-1 102 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 drain=0 . timer not pending
103 (t=65000 jiffies) 103 (t=65000 jiffies)
104 104
105The "(64628 ticks this GP)" indicates that this CPU has taken more 105The "(64628 ticks this GP)" indicates that this CPU has taken more
@@ -116,13 +116,13 @@ number between the two "/"s is the value of the nesting, which will
116be a small positive number if in the idle loop and a very large positive 116be a small positive number if in the idle loop and a very large positive
117number (as shown above) otherwise. 117number (as shown above) otherwise.
118 118
119For CONFIG_RCU_FAST_NO_HZ kernels, the "drain=0" indicates that the 119For CONFIG_RCU_FAST_NO_HZ kernels, the "drain=0" indicates that the CPU is
120CPU is not in the process of trying to force itself into dyntick-idle 120not in the process of trying to force itself into dyntick-idle state, the
121state, the "." indicates that the CPU has not given up forcing RCU 121"." indicates that the CPU has not given up forcing RCU into dyntick-idle
122into dyntick-idle mode (it would be "H" otherwise), and the "timer=-1" 122mode (it would be "H" otherwise), and the "timer not pending" indicates
123indicates that the CPU has not recented forced RCU into dyntick-idle 123that the CPU has not recently forced RCU into dyntick-idle mode (it
124mode (it would otherwise indicate the number of microseconds remaining 124would otherwise indicate the number of microseconds remaining in this
125in this forced state). 125forced state).
126 126
127 127
128Multiple Warnings From One Stall 128Multiple Warnings From One Stall
diff --git a/Documentation/RCU/trace.txt b/Documentation/RCU/trace.txt
index f6f15ce39903..672d19083252 100644
--- a/Documentation/RCU/trace.txt
+++ b/Documentation/RCU/trace.txt
@@ -333,23 +333,23 @@ o Each element of the form "1/1 0:127 ^0" represents one struct
333The output of "cat rcu/rcu_pending" looks as follows: 333The output of "cat rcu/rcu_pending" looks as follows:
334 334
335rcu_sched: 335rcu_sched:
336 0 np=255892 qsp=53936 rpq=85 cbr=0 cng=14417 gpc=10033 gps=24320 nf=6445 nn=146741 336 0 np=255892 qsp=53936 rpq=85 cbr=0 cng=14417 gpc=10033 gps=24320 nn=146741
337 1 np=261224 qsp=54638 rpq=33 cbr=0 cng=25723 gpc=16310 gps=2849 nf=5912 nn=155792 337 1 np=261224 qsp=54638 rpq=33 cbr=0 cng=25723 gpc=16310 gps=2849 nn=155792
338 2 np=237496 qsp=49664 rpq=23 cbr=0 cng=2762 gpc=45478 gps=1762 nf=1201 nn=136629 338 2 np=237496 qsp=49664 rpq=23 cbr=0 cng=2762 gpc=45478 gps=1762 nn=136629
339 3 np=236249 qsp=48766 rpq=98 cbr=0 cng=286 gpc=48049 gps=1218 nf=207 nn=137723 339 3 np=236249 qsp=48766 rpq=98 cbr=0 cng=286 gpc=48049 gps=1218 nn=137723
340 4 np=221310 qsp=46850 rpq=7 cbr=0 cng=26 gpc=43161 gps=4634 nf=3529 nn=123110 340 4 np=221310 qsp=46850 rpq=7 cbr=0 cng=26 gpc=43161 gps=4634 nn=123110
341 5 np=237332 qsp=48449 rpq=9 cbr=0 cng=54 gpc=47920 gps=3252 nf=201 nn=137456 341 5 np=237332 qsp=48449 rpq=9 cbr=0 cng=54 gpc=47920 gps=3252 nn=137456
342 6 np=219995 qsp=46718 rpq=12 cbr=0 cng=50 gpc=42098 gps=6093 nf=4202 nn=120834 342 6 np=219995 qsp=46718 rpq=12 cbr=0 cng=50 gpc=42098 gps=6093 nn=120834
343 7 np=249893 qsp=49390 rpq=42 cbr=0 cng=72 gpc=38400 gps=17102 nf=41 nn=144888 343 7 np=249893 qsp=49390 rpq=42 cbr=0 cng=72 gpc=38400 gps=17102 nn=144888
344rcu_bh: 344rcu_bh:
345 0 np=146741 qsp=1419 rpq=6 cbr=0 cng=6 gpc=0 gps=0 nf=2 nn=145314 345 0 np=146741 qsp=1419 rpq=6 cbr=0 cng=6 gpc=0 gps=0 nn=145314
346 1 np=155792 qsp=12597 rpq=3 cbr=0 cng=0 gpc=4 gps=8 nf=3 nn=143180 346 1 np=155792 qsp=12597 rpq=3 cbr=0 cng=0 gpc=4 gps=8 nn=143180
347 2 np=136629 qsp=18680 rpq=1 cbr=0 cng=0 gpc=7 gps=6 nf=0 nn=117936 347 2 np=136629 qsp=18680 rpq=1 cbr=0 cng=0 gpc=7 gps=6 nn=117936
348 3 np=137723 qsp=2843 rpq=0 cbr=0 cng=0 gpc=10 gps=7 nf=0 nn=134863 348 3 np=137723 qsp=2843 rpq=0 cbr=0 cng=0 gpc=10 gps=7 nn=134863
349 4 np=123110 qsp=12433 rpq=0 cbr=0 cng=0 gpc=4 gps=2 nf=0 nn=110671 349 4 np=123110 qsp=12433 rpq=0 cbr=0 cng=0 gpc=4 gps=2 nn=110671
350 5 np=137456 qsp=4210 rpq=1 cbr=0 cng=0 gpc=6 gps=5 nf=0 nn=133235 350 5 np=137456 qsp=4210 rpq=1 cbr=0 cng=0 gpc=6 gps=5 nn=133235
351 6 np=120834 qsp=9902 rpq=2 cbr=0 cng=0 gpc=6 gps=3 nf=2 nn=110921 351 6 np=120834 qsp=9902 rpq=2 cbr=0 cng=0 gpc=6 gps=3 nn=110921
352 7 np=144888 qsp=26336 rpq=0 cbr=0 cng=0 gpc=8 gps=2 nf=0 nn=118542 352 7 np=144888 qsp=26336 rpq=0 cbr=0 cng=0 gpc=8 gps=2 nn=118542
353 353
354As always, this is once again split into "rcu_sched" and "rcu_bh" 354As always, this is once again split into "rcu_sched" and "rcu_bh"
355portions, with CONFIG_TREE_PREEMPT_RCU kernels having an additional 355portions, with CONFIG_TREE_PREEMPT_RCU kernels having an additional
@@ -377,17 +377,6 @@ o "gpc" is the number of times that an old grace period had
377o "gps" is the number of times that a new grace period had started, 377o "gps" is the number of times that a new grace period had started,
378 but this CPU was not yet aware of it. 378 but this CPU was not yet aware of it.
379 379
380o "nf" is the number of times that this CPU suspected that the
381 current grace period had run for too long, and thus needed to
382 be forced.
383
384 Please note that "forcing" consists of sending resched IPIs
385 to holdout CPUs. If that CPU really still is in an old RCU
386 read-side critical section, then we really do have to wait for it.
387 The assumption behing "forcing" is that the CPU is not still in
388 an old RCU read-side critical section, but has not yet responded
389 for some other reason.
390
391o "nn" is the number of times that this CPU needed nothing. Alert 380o "nn" is the number of times that this CPU needed nothing. Alert
392 readers will note that the rcu "nn" number for a given CPU very 381 readers will note that the rcu "nn" number for a given CPU very
393 closely matches the rcu_bh "np" number for that same CPU. This 382 closely matches the rcu_bh "np" number for that same CPU. This
diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
index 69ee188515e7..bf0f6de2aa00 100644
--- a/Documentation/RCU/whatisRCU.txt
+++ b/Documentation/RCU/whatisRCU.txt
@@ -873,7 +873,7 @@ d. Do you need to treat NMI handlers, hardirq handlers,
873 and code segments with preemption disabled (whether 873 and code segments with preemption disabled (whether
874 via preempt_disable(), local_irq_save(), local_bh_disable(), 874 via preempt_disable(), local_irq_save(), local_bh_disable(),
875 or some other mechanism) as if they were explicit RCU readers? 875 or some other mechanism) as if they were explicit RCU readers?
876 If so, you need RCU-sched. 876 If so, RCU-sched is the only choice that will work for you.
877 877
878e. Do you need RCU grace periods to complete even in the face 878e. Do you need RCU grace periods to complete even in the face
879 of softirq monopolization of one or more of the CPUs? For 879 of softirq monopolization of one or more of the CPUs? For
@@ -884,7 +884,12 @@ f. Is your workload too update-intensive for normal use of
884 RCU, but inappropriate for other synchronization mechanisms? 884 RCU, but inappropriate for other synchronization mechanisms?
885 If so, consider SLAB_DESTROY_BY_RCU. But please be careful! 885 If so, consider SLAB_DESTROY_BY_RCU. But please be careful!
886 886
887g. Otherwise, use RCU. 887g. Do you need read-side critical sections that are respected
888 even though they are in the middle of the idle loop, during
889 user-mode execution, or on an offlined CPU? If so, SRCU is the
890 only choice that will work for you.
891
892h. Otherwise, use RCU.
888 893
889Of course, this all assumes that you have determined that RCU is in fact 894Of course, this all assumes that you have determined that RCU is in fact
890the right tool for your job. 895the right tool for your job.
diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index f6318f6d7baf..6f706aca2049 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -98,10 +98,9 @@ static int create_nl_socket(int protocol)
98 if (rcvbufsz) 98 if (rcvbufsz)
99 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, 99 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
100 &rcvbufsz, sizeof(rcvbufsz)) < 0) { 100 &rcvbufsz, sizeof(rcvbufsz)) < 0) {
101 fprintf(stderr, "Unable to set socket rcv buf size " 101 fprintf(stderr, "Unable to set socket rcv buf size to %d\n",
102 "to %d\n",
103 rcvbufsz); 102 rcvbufsz);
104 return -1; 103 goto error;
105 } 104 }
106 105
107 memset(&local, 0, sizeof(local)); 106 memset(&local, 0, sizeof(local));
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index 66ece3f87bbc..ecfc6ccd67ef 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -11,10 +11,13 @@ Optional properties:
11- regulator-boot-on: bootloader/firmware enabled regulator 11- regulator-boot-on: bootloader/firmware enabled regulator
12- <name>-supply: phandle to the parent supply/regulator node 12- <name>-supply: phandle to the parent supply/regulator node
13- regulator-ramp-delay: ramp delay for regulator(in uV/uS) 13- regulator-ramp-delay: ramp delay for regulator(in uV/uS)
14
15Deprecated properties:
14- regulator-compatible: If a regulator chip contains multiple 16- regulator-compatible: If a regulator chip contains multiple
15 regulators, and if the chip's binding contains a child node that 17 regulators, and if the chip's binding contains a child node that
16 describes each regulator, then this property indicates which regulator 18 describes each regulator, then this property indicates which regulator
17 this child node is intended to configure. 19 this child node is intended to configure. If this property is missing,
20 the node's name will be used instead.
18 21
19Example: 22Example:
20 23
diff --git a/Documentation/devicetree/bindings/regulator/tps65217.txt b/Documentation/devicetree/bindings/regulator/tps65217.txt
index 0487e9675ba0..d316fb895daf 100644
--- a/Documentation/devicetree/bindings/regulator/tps65217.txt
+++ b/Documentation/devicetree/bindings/regulator/tps65217.txt
@@ -22,66 +22,49 @@ Example:
22 compatible = "ti,tps65217"; 22 compatible = "ti,tps65217";
23 23
24 regulators { 24 regulators {
25 #address-cells = <1>; 25 dcdc1_reg: dcdc1 {
26 #size-cells = <0>;
27
28 dcdc1_reg: regulator@0 {
29 reg = <0>;
30 regulator-compatible = "dcdc1";
31 regulator-min-microvolt = <900000>; 26 regulator-min-microvolt = <900000>;
32 regulator-max-microvolt = <1800000>; 27 regulator-max-microvolt = <1800000>;
33 regulator-boot-on; 28 regulator-boot-on;
34 regulator-always-on; 29 regulator-always-on;
35 }; 30 };
36 31
37 dcdc2_reg: regulator@1 { 32 dcdc2_reg: dcdc2 {
38 reg = <1>;
39 regulator-compatible = "dcdc2";
40 regulator-min-microvolt = <900000>; 33 regulator-min-microvolt = <900000>;
41 regulator-max-microvolt = <3300000>; 34 regulator-max-microvolt = <3300000>;
42 regulator-boot-on; 35 regulator-boot-on;
43 regulator-always-on; 36 regulator-always-on;
44 }; 37 };
45 38
46 dcdc3_reg: regulator@2 { 39 dcdc3_reg: dcc3 {
47 reg = <2>;
48 regulator-compatible = "dcdc3";
49 regulator-min-microvolt = <900000>; 40 regulator-min-microvolt = <900000>;
50 regulator-max-microvolt = <1500000>; 41 regulator-max-microvolt = <1500000>;
51 regulator-boot-on; 42 regulator-boot-on;
52 regulator-always-on; 43 regulator-always-on;
53 }; 44 };
54 45
55 ldo1_reg: regulator@3 { 46 ldo1_reg: ldo1 {
56 reg = <3>;
57 regulator-compatible = "ldo1";
58 regulator-min-microvolt = <1000000>; 47 regulator-min-microvolt = <1000000>;
59 regulator-max-microvolt = <3300000>; 48 regulator-max-microvolt = <3300000>;
60 regulator-boot-on; 49 regulator-boot-on;
61 regulator-always-on; 50 regulator-always-on;
62 }; 51 };
63 52
64 ldo2_reg: regulator@4 { 53 ldo2_reg: ldo2 {
65 reg = <4>;
66 regulator-compatible = "ldo2";
67 regulator-min-microvolt = <900000>; 54 regulator-min-microvolt = <900000>;
68 regulator-max-microvolt = <3300000>; 55 regulator-max-microvolt = <3300000>;
69 regulator-boot-on; 56 regulator-boot-on;
70 regulator-always-on; 57 regulator-always-on;
71 }; 58 };
72 59
73 ldo3_reg: regulator@5 { 60 ldo3_reg: ldo3 {
74 reg = <5>;
75 regulator-compatible = "ldo3";
76 regulator-min-microvolt = <1800000>; 61 regulator-min-microvolt = <1800000>;
77 regulator-max-microvolt = <3300000>; 62 regulator-max-microvolt = <3300000>;
78 regulator-boot-on; 63 regulator-boot-on;
79 regulator-always-on; 64 regulator-always-on;
80 }; 65 };
81 66
82 ldo4_reg: regulator@6 { 67 ldo4_reg: ldo4 {
83 reg = <6>;
84 regulator-compatible = "ldo4";
85 regulator-min-microvolt = <1800000>; 68 regulator-min-microvolt = <1800000>;
86 regulator-max-microvolt = <3300000>; 69 regulator-max-microvolt = <3300000>;
87 regulator-boot-on; 70 regulator-boot-on;
diff --git a/Documentation/devicetree/bindings/regulator/tps6586x.txt b/Documentation/devicetree/bindings/regulator/tps6586x.txt
index da80c2ae0915..07b9ef6e49d5 100644
--- a/Documentation/devicetree/bindings/regulator/tps6586x.txt
+++ b/Documentation/devicetree/bindings/regulator/tps6586x.txt
@@ -6,9 +6,13 @@ Required properties:
6- interrupts: the interrupt outputs of the controller 6- interrupts: the interrupt outputs of the controller
7- #gpio-cells: number of cells to describe a GPIO 7- #gpio-cells: number of cells to describe a GPIO
8- gpio-controller: mark the device as a GPIO controller 8- gpio-controller: mark the device as a GPIO controller
9- regulators: list of regulators provided by this controller, must have 9- regulators: A node that houses a sub-node for each regulator within the
10 property "regulator-compatible" to match their hardware counterparts: 10 device. Each sub-node is identified using the node's name (or the deprecated
11 sm[0-2], ldo[0-9] and ldo_rtc 11 regulator-compatible property if present), with valid values listed below.
12 The content of each sub-node is defined by the standard binding for
13 regulators; see regulator.txt.
14 sys, sm[0-2], ldo[0-9] and ldo_rtc
15- sys-supply: The input supply for SYS.
12- vin-sm0-supply: The input supply for the SM0. 16- vin-sm0-supply: The input supply for the SM0.
13- vin-sm1-supply: The input supply for the SM1. 17- vin-sm1-supply: The input supply for the SM1.
14- vin-sm2-supply: The input supply for the SM2. 18- vin-sm2-supply: The input supply for the SM2.
@@ -20,6 +24,9 @@ Required properties:
20 24
21Each regulator is defined using the standard binding for regulators. 25Each regulator is defined using the standard binding for regulators.
22 26
27Note: LDO5 and LDO_RTC is supplied by SYS regulator internally and driver
28 take care of making proper parent child relationship.
29
23Example: 30Example:
24 31
25 pmu: tps6586x@34 { 32 pmu: tps6586x@34 {
@@ -30,6 +37,7 @@ Example:
30 #gpio-cells = <2>; 37 #gpio-cells = <2>;
31 gpio-controller; 38 gpio-controller;
32 39
40 sys-supply = <&some_reg>;
33 vin-sm0-supply = <&some_reg>; 41 vin-sm0-supply = <&some_reg>;
34 vin-sm1-supply = <&some_reg>; 42 vin-sm1-supply = <&some_reg>;
35 vin-sm2-supply = <&some_reg>; 43 vin-sm2-supply = <&some_reg>;
@@ -40,103 +48,80 @@ Example:
40 vinldo9-supply = <...>; 48 vinldo9-supply = <...>;
41 49
42 regulators { 50 regulators {
43 #address-cells = <1>; 51 sys_reg: sys {
44 #size-cells = <0>; 52 regulator-name = "vdd_sys";
53 regulator-boot-on;
54 regulator-always-on;
55 };
45 56
46 sm0_reg: regulator@0 { 57 sm0_reg: sm0 {
47 reg = <0>;
48 regulator-compatible = "sm0";
49 regulator-min-microvolt = < 725000>; 58 regulator-min-microvolt = < 725000>;
50 regulator-max-microvolt = <1500000>; 59 regulator-max-microvolt = <1500000>;
51 regulator-boot-on; 60 regulator-boot-on;
52 regulator-always-on; 61 regulator-always-on;
53 }; 62 };
54 63
55 sm1_reg: regulator@1 { 64 sm1_reg: sm1 {
56 reg = <1>;
57 regulator-compatible = "sm1";
58 regulator-min-microvolt = < 725000>; 65 regulator-min-microvolt = < 725000>;
59 regulator-max-microvolt = <1500000>; 66 regulator-max-microvolt = <1500000>;
60 regulator-boot-on; 67 regulator-boot-on;
61 regulator-always-on; 68 regulator-always-on;
62 }; 69 };
63 70
64 sm2_reg: regulator@2 { 71 sm2_reg: sm2 {
65 reg = <2>;
66 regulator-compatible = "sm2";
67 regulator-min-microvolt = <3000000>; 72 regulator-min-microvolt = <3000000>;
68 regulator-max-microvolt = <4550000>; 73 regulator-max-microvolt = <4550000>;
69 regulator-boot-on; 74 regulator-boot-on;
70 regulator-always-on; 75 regulator-always-on;
71 }; 76 };
72 77
73 ldo0_reg: regulator@3 { 78 ldo0_reg: ldo0 {
74 reg = <3>;
75 regulator-compatible = "ldo0";
76 regulator-name = "PCIE CLK"; 79 regulator-name = "PCIE CLK";
77 regulator-min-microvolt = <3300000>; 80 regulator-min-microvolt = <3300000>;
78 regulator-max-microvolt = <3300000>; 81 regulator-max-microvolt = <3300000>;
79 }; 82 };
80 83
81 ldo1_reg: regulator@4 { 84 ldo1_reg: ldo1 {
82 reg = <4>;
83 regulator-compatible = "ldo1";
84 regulator-min-microvolt = < 725000>; 85 regulator-min-microvolt = < 725000>;
85 regulator-max-microvolt = <1500000>; 86 regulator-max-microvolt = <1500000>;
86 }; 87 };
87 88
88 ldo2_reg: regulator@5 { 89 ldo2_reg: ldo2 {
89 reg = <5>;
90 regulator-compatible = "ldo2";
91 regulator-min-microvolt = < 725000>; 90 regulator-min-microvolt = < 725000>;
92 regulator-max-microvolt = <1500000>; 91 regulator-max-microvolt = <1500000>;
93 }; 92 };
94 93
95 ldo3_reg: regulator@6 { 94 ldo3_reg: ldo3 {
96 reg = <6>;
97 regulator-compatible = "ldo3";
98 regulator-min-microvolt = <1250000>; 95 regulator-min-microvolt = <1250000>;
99 regulator-max-microvolt = <3300000>; 96 regulator-max-microvolt = <3300000>;
100 }; 97 };
101 98
102 ldo4_reg: regulator@7 { 99 ldo4_reg: ldo4 {
103 reg = <7>;
104 regulator-compatible = "ldo4";
105 regulator-min-microvolt = <1700000>; 100 regulator-min-microvolt = <1700000>;
106 regulator-max-microvolt = <2475000>; 101 regulator-max-microvolt = <2475000>;
107 }; 102 };
108 103
109 ldo5_reg: regulator@8 { 104 ldo5_reg: ldo5 {
110 reg = <8>;
111 regulator-compatible = "ldo5";
112 regulator-min-microvolt = <1250000>; 105 regulator-min-microvolt = <1250000>;
113 regulator-max-microvolt = <3300000>; 106 regulator-max-microvolt = <3300000>;
114 }; 107 };
115 108
116 ldo6_reg: regulator@9 { 109 ldo6_reg: ldo6 {
117 reg = <9>;
118 regulator-compatible = "ldo6";
119 regulator-min-microvolt = <1250000>; 110 regulator-min-microvolt = <1250000>;
120 regulator-max-microvolt = <3300000>; 111 regulator-max-microvolt = <3300000>;
121 }; 112 };
122 113
123 ldo7_reg: regulator@10 { 114 ldo7_reg: ldo7 {
124 reg = <10>;
125 regulator-compatible = "ldo7";
126 regulator-min-microvolt = <1250000>; 115 regulator-min-microvolt = <1250000>;
127 regulator-max-microvolt = <3300000>; 116 regulator-max-microvolt = <3300000>;
128 }; 117 };
129 118
130 ldo8_reg: regulator@11 { 119 ldo8_reg: ldo8 {
131 reg = <11>;
132 regulator-compatible = "ldo8";
133 regulator-min-microvolt = <1250000>; 120 regulator-min-microvolt = <1250000>;
134 regulator-max-microvolt = <3300000>; 121 regulator-max-microvolt = <3300000>;
135 }; 122 };
136 123
137 ldo9_reg: regulator@12 { 124 ldo9_reg: ldo9 {
138 reg = <12>;
139 regulator-compatible = "ldo9";
140 regulator-min-microvolt = <1250000>; 125 regulator-min-microvolt = <1250000>;
141 regulator-max-microvolt = <3300000>; 126 regulator-max-microvolt = <3300000>;
142 }; 127 };
diff --git a/Documentation/dontdiff b/Documentation/dontdiff
index 39462cf35cd4..74c25c8d8884 100644
--- a/Documentation/dontdiff
+++ b/Documentation/dontdiff
@@ -162,7 +162,6 @@ mach-types.h
162machtypes.h 162machtypes.h
163map 163map
164map_hugetlb 164map_hugetlb
165maui_boot.h
166media 165media
167mconf 166mconf
168miboot* 167miboot*
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index 615142da4ef6..157416e78cc4 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -21,6 +21,7 @@ Supported adapters:
21 * Intel DH89xxCC (PCH) 21 * Intel DH89xxCC (PCH)
22 * Intel Panther Point (PCH) 22 * Intel Panther Point (PCH)
23 * Intel Lynx Point (PCH) 23 * Intel Lynx Point (PCH)
24 * Intel Lynx Point-LP (PCH)
24 Datasheets: Publicly available at the Intel website 25 Datasheets: Publicly available at the Intel website
25 26
26On Intel Patsburg and later chipsets, both the normal host SMBus controller 27On Intel Patsburg and later chipsets, both the normal host SMBus controller
diff --git a/Documentation/ia64/aliasing-test.c b/Documentation/ia64/aliasing-test.c
index 5caa2af33207..62a190d45f38 100644
--- a/Documentation/ia64/aliasing-test.c
+++ b/Documentation/ia64/aliasing-test.c
@@ -132,6 +132,7 @@ static int read_rom(char *path)
132 132
133 rc = write(fd, "1", 2); 133 rc = write(fd, "1", 2);
134 if (rc <= 0) { 134 if (rc <= 0) {
135 close(fd);
135 perror("write"); 136 perror("write");
136 return -1; 137 return -1;
137 } 138 }
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index ad7e2e5088c1..55ada0471f93 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2385,6 +2385,17 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
2385 rcutree.rcu_cpu_stall_timeout= [KNL,BOOT] 2385 rcutree.rcu_cpu_stall_timeout= [KNL,BOOT]
2386 Set timeout for RCU CPU stall warning messages. 2386 Set timeout for RCU CPU stall warning messages.
2387 2387
2388 rcutree.jiffies_till_first_fqs= [KNL,BOOT]
2389 Set delay from grace-period initialization to
2390 first attempt to force quiescent states.
2391 Units are jiffies, minimum value is zero,
2392 and maximum value is HZ.
2393
2394 rcutree.jiffies_till_next_fqs= [KNL,BOOT]
2395 Set delay between subsequent attempts to force
2396 quiescent states. Units are jiffies, minimum
2397 value is one, and maximum value is HZ.
2398
2388 rcutorture.fqs_duration= [KNL,BOOT] 2399 rcutorture.fqs_duration= [KNL,BOOT]
2389 Set duration of force_quiescent_state bursts. 2400 Set duration of force_quiescent_state bursts.
2390 2401
diff --git a/Documentation/power/swsusp.txt b/Documentation/power/swsusp.txt
index 92341b84250d..0b4b63e7e9b6 100644
--- a/Documentation/power/swsusp.txt
+++ b/Documentation/power/swsusp.txt
@@ -53,7 +53,7 @@ before suspend (it is limited to 500 MB by default).
53 53
54Article about goals and implementation of Software Suspend for Linux 54Article about goals and implementation of Software Suspend for Linux
55~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56Author: G‚ábor Kuti 56Author: Gábor Kuti
57Last revised: 2003-10-20 by Pavel Machek 57Last revised: 2003-10-20 by Pavel Machek
58 58
59Idea and goals to achieve 59Idea and goals to achieve
diff --git a/Documentation/trace/kprobetrace.txt b/Documentation/trace/kprobetrace.txt
index d0d0bb9e3e25..d68ea5fc812b 100644
--- a/Documentation/trace/kprobetrace.txt
+++ b/Documentation/trace/kprobetrace.txt
@@ -12,7 +12,7 @@ kprobes can probe (this means, all functions body except for __kprobes
12functions). Unlike the Tracepoint based event, this can be added and removed 12functions). Unlike the Tracepoint based event, this can be added and removed
13dynamically, on the fly. 13dynamically, on the fly.
14 14
15To enable this feature, build your kernel with CONFIG_KPROBE_TRACING=y. 15To enable this feature, build your kernel with CONFIG_KPROBE_EVENT=y.
16 16
17Similar to the events tracer, this doesn't need to be activated via 17Similar to the events tracer, this doesn't need to be activated via
18current_tracer. Instead of that, add probe points via 18current_tracer. Instead of that, add probe points via
diff --git a/Documentation/vfio.txt b/Documentation/vfio.txt
index 0cb6685c8029..8eda3635a17d 100644
--- a/Documentation/vfio.txt
+++ b/Documentation/vfio.txt
@@ -133,7 +133,7 @@ character devices for this group:
133$ lspci -n -s 0000:06:0d.0 133$ lspci -n -s 0000:06:0d.0
13406:0d.0 0401: 1102:0002 (rev 08) 13406:0d.0 0401: 1102:0002 (rev 08)
135# echo 0000:06:0d.0 > /sys/bus/pci/devices/0000:06:0d.0/driver/unbind 135# echo 0000:06:0d.0 > /sys/bus/pci/devices/0000:06:0d.0/driver/unbind
136# echo 1102 0002 > /sys/bus/pci/drivers/vfio/new_id 136# echo 1102 0002 > /sys/bus/pci/drivers/vfio-pci/new_id
137 137
138Now we need to look at what other devices are in the group to free 138Now we need to look at what other devices are in the group to free
139it for use by VFIO: 139it for use by VFIO:
diff --git a/MAINTAINERS b/MAINTAINERS
index fdc0119963e7..9362f54bccb8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3388,7 +3388,7 @@ M: "Wolfram Sang (embedded platforms)" <w.sang@pengutronix.de>
3388L: linux-i2c@vger.kernel.org 3388L: linux-i2c@vger.kernel.org
3389W: http://i2c.wiki.kernel.org/ 3389W: http://i2c.wiki.kernel.org/
3390T: quilt kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-i2c/ 3390T: quilt kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-i2c/
3391T: git git://git.fluff.org/bjdooks/linux.git 3391T: git git://git.pengutronix.de/git/wsa/linux.git
3392S: Maintained 3392S: Maintained
3393F: Documentation/i2c/ 3393F: Documentation/i2c/
3394F: drivers/i2c/ 3394F: drivers/i2c/
@@ -3552,11 +3552,12 @@ K: \b(ABS|SYN)_MT_
3552 3552
3553INTEL C600 SERIES SAS CONTROLLER DRIVER 3553INTEL C600 SERIES SAS CONTROLLER DRIVER
3554M: Intel SCU Linux support <intel-linux-scu@intel.com> 3554M: Intel SCU Linux support <intel-linux-scu@intel.com>
3555M: Lukasz Dorau <lukasz.dorau@intel.com>
3556M: Maciej Patelczyk <maciej.patelczyk@intel.com>
3555M: Dave Jiang <dave.jiang@intel.com> 3557M: Dave Jiang <dave.jiang@intel.com>
3556M: Ed Nadolski <edmund.nadolski@intel.com>
3557L: linux-scsi@vger.kernel.org 3558L: linux-scsi@vger.kernel.org
3558T: git git://git.kernel.org/pub/scm/linux/kernel/git/djbw/isci.git 3559T: git git://git.code.sf.net/p/intel-sas/isci
3559S: Maintained 3560S: Supported
3560F: drivers/scsi/isci/ 3561F: drivers/scsi/isci/
3561F: firmware/isci/ 3562F: firmware/isci/
3562 3563
@@ -3666,11 +3667,12 @@ F: Documentation/networking/README.ipw2200
3666F: drivers/net/wireless/ipw2x00/ 3667F: drivers/net/wireless/ipw2x00/
3667 3668
3668INTEL(R) TRUSTED EXECUTION TECHNOLOGY (TXT) 3669INTEL(R) TRUSTED EXECUTION TECHNOLOGY (TXT)
3669M: Joseph Cihula <joseph.cihula@intel.com> 3670M: Richard L Maliszewski <richard.l.maliszewski@intel.com>
3671M: Gang Wei <gang.wei@intel.com>
3670M: Shane Wang <shane.wang@intel.com> 3672M: Shane Wang <shane.wang@intel.com>
3671L: tboot-devel@lists.sourceforge.net 3673L: tboot-devel@lists.sourceforge.net
3672W: http://tboot.sourceforge.net 3674W: http://tboot.sourceforge.net
3673T: Mercurial http://www.bughost.org/repos.hg/tboot.hg 3675T: hg http://tboot.hg.sourceforge.net:8000/hgroot/tboot/tboot
3674S: Supported 3676S: Supported
3675F: Documentation/intel_txt.txt 3677F: Documentation/intel_txt.txt
3676F: include/linux/tboot.h 3678F: include/linux/tboot.h
@@ -5320,6 +5322,12 @@ L: linux-mtd@lists.infradead.org
5320S: Maintained 5322S: Maintained
5321F: drivers/mtd/devices/phram.c 5323F: drivers/mtd/devices/phram.c
5322 5324
5325PICOLCD HID DRIVER
5326M: Bruno Prémont <bonbons@linux-vserver.org>
5327L: linux-input@vger.kernel.org
5328S: Maintained
5329F: drivers/hid/hid-picolcd*
5330
5323PICOXCELL SUPPORT 5331PICOXCELL SUPPORT
5324M: Jamie Iles <jamie@jamieiles.com> 5332M: Jamie Iles <jamie@jamieiles.com>
5325L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 5333L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
@@ -5543,6 +5551,8 @@ F: Documentation/devicetree/bindings/pwm/
5543F: include/linux/pwm.h 5551F: include/linux/pwm.h
5544F: include/linux/of_pwm.h 5552F: include/linux/of_pwm.h
5545F: drivers/pwm/ 5553F: drivers/pwm/
5554F: drivers/video/backlight/pwm_bl.c
5555F: include/linux/pwm_backlight.h
5546 5556
5547PXA2xx/PXA3xx SUPPORT 5557PXA2xx/PXA3xx SUPPORT
5548M: Eric Miao <eric.y.miao@gmail.com> 5558M: Eric Miao <eric.y.miao@gmail.com>
diff --git a/Makefile b/Makefile
index 843f2f6c28a7..846dd7607854 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 6 2PATCHLEVEL = 6
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc5 4EXTRAVERSION =
5NAME = Saber-toothed Squirrel 5NAME = Terrified Chipmunk
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
8# To see a list of typical targets execute "make help" 8# To see a list of typical targets execute "make help"
diff --git a/arch/Kconfig b/arch/Kconfig
index 2a83a3f6a615..1a7b468abf4a 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -294,4 +294,14 @@ config SECCOMP_FILTER
294 294
295 See Documentation/prctl/seccomp_filter.txt for details. 295 See Documentation/prctl/seccomp_filter.txt for details.
296 296
297config HAVE_RCU_USER_QS
298 bool
299 help
300 Provide kernel entry/exit hooks necessary for userspace
301 RCU extended quiescent state. Syscalls need to be wrapped inside
302 rcu_user_exit()-rcu_user_enter() through the slow path using
303 TIF_NOHZ flag. Exceptions handlers must be wrapped as well. Irqs
304 are already protected inside rcu_irq_enter/rcu_irq_exit() but
305 preemption or signal handling on irq exit still need to be protected.
306
297source "kernel/gcov/Kconfig" 307source "kernel/gcov/Kconfig"
diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c
index d6fde98b74b3..83638aa096d5 100644
--- a/arch/alpha/kernel/process.c
+++ b/arch/alpha/kernel/process.c
@@ -28,6 +28,7 @@
28#include <linux/tty.h> 28#include <linux/tty.h>
29#include <linux/console.h> 29#include <linux/console.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/rcupdate.h>
31 32
32#include <asm/reg.h> 33#include <asm/reg.h>
33#include <asm/uaccess.h> 34#include <asm/uaccess.h>
@@ -54,9 +55,12 @@ cpu_idle(void)
54 /* FIXME -- EV6 and LCA45 know how to power down 55 /* FIXME -- EV6 and LCA45 know how to power down
55 the CPU. */ 56 the CPU. */
56 57
58 rcu_idle_enter();
57 while (!need_resched()) 59 while (!need_resched())
58 cpu_relax(); 60 cpu_relax();
59 schedule(); 61
62 rcu_idle_exit();
63 schedule_preempt_disabled();
60 } 64 }
61} 65}
62 66
diff --git a/arch/alpha/kernel/smp.c b/arch/alpha/kernel/smp.c
index 35ddc02bfa4a..a41ad90a97a6 100644
--- a/arch/alpha/kernel/smp.c
+++ b/arch/alpha/kernel/smp.c
@@ -166,6 +166,7 @@ smp_callin(void)
166 DBGS(("smp_callin: commencing CPU %d current %p active_mm %p\n", 166 DBGS(("smp_callin: commencing CPU %d current %p active_mm %p\n",
167 cpuid, current, current->active_mm)); 167 cpuid, current, current->active_mm));
168 168
169 preempt_disable();
169 /* Do nothing. */ 170 /* Do nothing. */
170 cpu_idle(); 171 cpu_idle();
171} 172}
diff --git a/arch/arm/Kconfig.debug b/arch/arm/Kconfig.debug
index f15f82bf3a50..e968a52e4881 100644
--- a/arch/arm/Kconfig.debug
+++ b/arch/arm/Kconfig.debug
@@ -356,15 +356,15 @@ choice
356 is nothing connected to read from the DCC. 356 is nothing connected to read from the DCC.
357 357
358 config DEBUG_SEMIHOSTING 358 config DEBUG_SEMIHOSTING
359 bool "Kernel low-level debug output via semihosting I" 359 bool "Kernel low-level debug output via semihosting I/O"
360 help 360 help
361 Semihosting enables code running on an ARM target to use 361 Semihosting enables code running on an ARM target to use
362 the I/O facilities on a host debugger/emulator through a 362 the I/O facilities on a host debugger/emulator through a
363 simple SVC calls. The host debugger or emulator must have 363 simple SVC call. The host debugger or emulator must have
364 semihosting enabled for the special svc call to be trapped 364 semihosting enabled for the special svc call to be trapped
365 otherwise the kernel will crash. 365 otherwise the kernel will crash.
366 366
367 This is known to work with OpenOCD, as wellas 367 This is known to work with OpenOCD, as well as
368 ARM's Fast Models, or any other controlling environment 368 ARM's Fast Models, or any other controlling environment
369 that implements semihosting. 369 that implements semihosting.
370 370
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 30eae87ead6d..a051dfbdd7db 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -284,10 +284,10 @@ zImage Image xipImage bootpImage uImage: vmlinux
284zinstall uinstall install: vmlinux 284zinstall uinstall install: vmlinux
285 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $@ 285 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $@
286 286
287%.dtb: 287%.dtb: scripts
288 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ 288 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@
289 289
290dtbs: 290dtbs: scripts
291 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ 291 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@
292 292
293# We use MRPROPER_FILES and CLEAN_FILES now 293# We use MRPROPER_FILES and CLEAN_FILES now
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index b8c64b80bafc..bc67cbff3944 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -653,16 +653,21 @@ __armv7_mmu_cache_on:
653 mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs 653 mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
654#endif 654#endif
655 mrc p15, 0, r0, c1, c0, 0 @ read control reg 655 mrc p15, 0, r0, c1, c0, 0 @ read control reg
656 bic r0, r0, #1 << 28 @ clear SCTLR.TRE
656 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement 657 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
657 orr r0, r0, #0x003c @ write buffer 658 orr r0, r0, #0x003c @ write buffer
658#ifdef CONFIG_MMU 659#ifdef CONFIG_MMU
659#ifdef CONFIG_CPU_ENDIAN_BE8 660#ifdef CONFIG_CPU_ENDIAN_BE8
660 orr r0, r0, #1 << 25 @ big-endian page tables 661 orr r0, r0, #1 << 25 @ big-endian page tables
661#endif 662#endif
663 mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
662 orrne r0, r0, #1 @ MMU enabled 664 orrne r0, r0, #1 @ MMU enabled
663 movne r1, #0xfffffffd @ domain 0 = client 665 movne r1, #0xfffffffd @ domain 0 = client
666 bic r6, r6, #1 << 31 @ 32-bit translation system
667 bic r6, r6, #3 << 0 @ use only ttbr0
664 mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer 668 mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
665 mcrne p15, 0, r1, c3, c0, 0 @ load domain access control 669 mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
670 mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
666#endif 671#endif
667 mcr p15, 0, r0, c7, c5, 4 @ ISB 672 mcr p15, 0, r0, c7, c5, 4 @ ISB
668 mcr p15, 0, r0, c1, c0, 0 @ load control register 673 mcr p15, 0, r0, c1, c0, 0 @ load control register
diff --git a/arch/arm/boot/dts/at91sam9260.dtsi b/arch/arm/boot/dts/at91sam9260.dtsi
index 66389c1c6f62..7c95f76398de 100644
--- a/arch/arm/boot/dts/at91sam9260.dtsi
+++ b/arch/arm/boot/dts/at91sam9260.dtsi
@@ -104,6 +104,7 @@
104 #gpio-cells = <2>; 104 #gpio-cells = <2>;
105 gpio-controller; 105 gpio-controller;
106 interrupt-controller; 106 interrupt-controller;
107 #interrupt-cells = <2>;
107 }; 108 };
108 109
109 pioB: gpio@fffff600 { 110 pioB: gpio@fffff600 {
@@ -113,6 +114,7 @@
113 #gpio-cells = <2>; 114 #gpio-cells = <2>;
114 gpio-controller; 115 gpio-controller;
115 interrupt-controller; 116 interrupt-controller;
117 #interrupt-cells = <2>;
116 }; 118 };
117 119
118 pioC: gpio@fffff800 { 120 pioC: gpio@fffff800 {
@@ -122,6 +124,7 @@
122 #gpio-cells = <2>; 124 #gpio-cells = <2>;
123 gpio-controller; 125 gpio-controller;
124 interrupt-controller; 126 interrupt-controller;
127 #interrupt-cells = <2>;
125 }; 128 };
126 129
127 dbgu: serial@fffff200 { 130 dbgu: serial@fffff200 {
diff --git a/arch/arm/boot/dts/at91sam9263.dtsi b/arch/arm/boot/dts/at91sam9263.dtsi
index b460d6ce9eb5..195019b7ca0e 100644
--- a/arch/arm/boot/dts/at91sam9263.dtsi
+++ b/arch/arm/boot/dts/at91sam9263.dtsi
@@ -95,6 +95,7 @@
95 #gpio-cells = <2>; 95 #gpio-cells = <2>;
96 gpio-controller; 96 gpio-controller;
97 interrupt-controller; 97 interrupt-controller;
98 #interrupt-cells = <2>;
98 }; 99 };
99 100
100 pioB: gpio@fffff400 { 101 pioB: gpio@fffff400 {
@@ -104,6 +105,7 @@
104 #gpio-cells = <2>; 105 #gpio-cells = <2>;
105 gpio-controller; 106 gpio-controller;
106 interrupt-controller; 107 interrupt-controller;
108 #interrupt-cells = <2>;
107 }; 109 };
108 110
109 pioC: gpio@fffff600 { 111 pioC: gpio@fffff600 {
@@ -113,6 +115,7 @@
113 #gpio-cells = <2>; 115 #gpio-cells = <2>;
114 gpio-controller; 116 gpio-controller;
115 interrupt-controller; 117 interrupt-controller;
118 #interrupt-cells = <2>;
116 }; 119 };
117 120
118 pioD: gpio@fffff800 { 121 pioD: gpio@fffff800 {
@@ -122,6 +125,7 @@
122 #gpio-cells = <2>; 125 #gpio-cells = <2>;
123 gpio-controller; 126 gpio-controller;
124 interrupt-controller; 127 interrupt-controller;
128 #interrupt-cells = <2>;
125 }; 129 };
126 130
127 pioE: gpio@fffffa00 { 131 pioE: gpio@fffffa00 {
@@ -131,6 +135,7 @@
131 #gpio-cells = <2>; 135 #gpio-cells = <2>;
132 gpio-controller; 136 gpio-controller;
133 interrupt-controller; 137 interrupt-controller;
138 #interrupt-cells = <2>;
134 }; 139 };
135 140
136 dbgu: serial@ffffee00 { 141 dbgu: serial@ffffee00 {
diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi b/arch/arm/boot/dts/at91sam9g45.dtsi
index bafa8806fc17..63751b1e744b 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -113,6 +113,7 @@
113 #gpio-cells = <2>; 113 #gpio-cells = <2>;
114 gpio-controller; 114 gpio-controller;
115 interrupt-controller; 115 interrupt-controller;
116 #interrupt-cells = <2>;
116 }; 117 };
117 118
118 pioB: gpio@fffff400 { 119 pioB: gpio@fffff400 {
@@ -122,6 +123,7 @@
122 #gpio-cells = <2>; 123 #gpio-cells = <2>;
123 gpio-controller; 124 gpio-controller;
124 interrupt-controller; 125 interrupt-controller;
126 #interrupt-cells = <2>;
125 }; 127 };
126 128
127 pioC: gpio@fffff600 { 129 pioC: gpio@fffff600 {
@@ -131,6 +133,7 @@
131 #gpio-cells = <2>; 133 #gpio-cells = <2>;
132 gpio-controller; 134 gpio-controller;
133 interrupt-controller; 135 interrupt-controller;
136 #interrupt-cells = <2>;
134 }; 137 };
135 138
136 pioD: gpio@fffff800 { 139 pioD: gpio@fffff800 {
@@ -140,6 +143,7 @@
140 #gpio-cells = <2>; 143 #gpio-cells = <2>;
141 gpio-controller; 144 gpio-controller;
142 interrupt-controller; 145 interrupt-controller;
146 #interrupt-cells = <2>;
143 }; 147 };
144 148
145 pioE: gpio@fffffa00 { 149 pioE: gpio@fffffa00 {
@@ -149,6 +153,7 @@
149 #gpio-cells = <2>; 153 #gpio-cells = <2>;
150 gpio-controller; 154 gpio-controller;
151 interrupt-controller; 155 interrupt-controller;
156 #interrupt-cells = <2>;
152 }; 157 };
153 158
154 dbgu: serial@ffffee00 { 159 dbgu: serial@ffffee00 {
diff --git a/arch/arm/boot/dts/at91sam9n12.dtsi b/arch/arm/boot/dts/at91sam9n12.dtsi
index bfac0dfc332c..ef9336ae9614 100644
--- a/arch/arm/boot/dts/at91sam9n12.dtsi
+++ b/arch/arm/boot/dts/at91sam9n12.dtsi
@@ -107,6 +107,7 @@
107 #gpio-cells = <2>; 107 #gpio-cells = <2>;
108 gpio-controller; 108 gpio-controller;
109 interrupt-controller; 109 interrupt-controller;
110 #interrupt-cells = <2>;
110 }; 111 };
111 112
112 pioB: gpio@fffff600 { 113 pioB: gpio@fffff600 {
@@ -116,6 +117,7 @@
116 #gpio-cells = <2>; 117 #gpio-cells = <2>;
117 gpio-controller; 118 gpio-controller;
118 interrupt-controller; 119 interrupt-controller;
120 #interrupt-cells = <2>;
119 }; 121 };
120 122
121 pioC: gpio@fffff800 { 123 pioC: gpio@fffff800 {
@@ -125,6 +127,7 @@
125 #gpio-cells = <2>; 127 #gpio-cells = <2>;
126 gpio-controller; 128 gpio-controller;
127 interrupt-controller; 129 interrupt-controller;
130 #interrupt-cells = <2>;
128 }; 131 };
129 132
130 pioD: gpio@fffffa00 { 133 pioD: gpio@fffffa00 {
@@ -134,6 +137,7 @@
134 #gpio-cells = <2>; 137 #gpio-cells = <2>;
135 gpio-controller; 138 gpio-controller;
136 interrupt-controller; 139 interrupt-controller;
140 #interrupt-cells = <2>;
137 }; 141 };
138 142
139 dbgu: serial@fffff200 { 143 dbgu: serial@fffff200 {
diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi b/arch/arm/boot/dts/at91sam9x5.dtsi
index 4a18c393b136..8a387a8d61b7 100644
--- a/arch/arm/boot/dts/at91sam9x5.dtsi
+++ b/arch/arm/boot/dts/at91sam9x5.dtsi
@@ -115,6 +115,7 @@
115 #gpio-cells = <2>; 115 #gpio-cells = <2>;
116 gpio-controller; 116 gpio-controller;
117 interrupt-controller; 117 interrupt-controller;
118 #interrupt-cells = <2>;
118 }; 119 };
119 120
120 pioB: gpio@fffff600 { 121 pioB: gpio@fffff600 {
@@ -124,6 +125,7 @@
124 #gpio-cells = <2>; 125 #gpio-cells = <2>;
125 gpio-controller; 126 gpio-controller;
126 interrupt-controller; 127 interrupt-controller;
128 #interrupt-cells = <2>;
127 }; 129 };
128 130
129 pioC: gpio@fffff800 { 131 pioC: gpio@fffff800 {
@@ -133,6 +135,7 @@
133 #gpio-cells = <2>; 135 #gpio-cells = <2>;
134 gpio-controller; 136 gpio-controller;
135 interrupt-controller; 137 interrupt-controller;
138 #interrupt-cells = <2>;
136 }; 139 };
137 140
138 pioD: gpio@fffffa00 { 141 pioD: gpio@fffffa00 {
@@ -142,6 +145,7 @@
142 #gpio-cells = <2>; 145 #gpio-cells = <2>;
143 gpio-controller; 146 gpio-controller;
144 interrupt-controller; 147 interrupt-controller;
148 #interrupt-cells = <2>;
145 }; 149 };
146 150
147 dbgu: serial@fffff200 { 151 dbgu: serial@fffff200 {
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 03fb93621d0d..5c8b3bf4d825 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -320,4 +320,12 @@
320 .size \name , . - \name 320 .size \name , . - \name
321 .endm 321 .endm
322 322
323 .macro check_uaccess, addr:req, size:req, limit:req, tmp:req, bad:req
324#ifndef CONFIG_CPU_USE_DOMAINS
325 adds \tmp, \addr, #\size - 1
326 sbcccs \tmp, \tmp, \limit
327 bcs \bad
328#endif
329 .endm
330
323#endif /* __ASM_ASSEMBLER_H__ */ 331#endif /* __ASM_ASSEMBLER_H__ */
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index e965f1b560f1..5f6ddcc56452 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -187,6 +187,7 @@ static inline unsigned long __phys_to_virt(unsigned long x)
187#define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET) 187#define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET)
188#endif 188#endif
189#endif 189#endif
190#endif /* __ASSEMBLY__ */
190 191
191#ifndef PHYS_OFFSET 192#ifndef PHYS_OFFSET
192#ifdef PLAT_PHYS_OFFSET 193#ifdef PLAT_PHYS_OFFSET
@@ -196,6 +197,8 @@ static inline unsigned long __phys_to_virt(unsigned long x)
196#endif 197#endif
197#endif 198#endif
198 199
200#ifndef __ASSEMBLY__
201
199/* 202/*
200 * PFNs are used to describe any physical page; this means 203 * PFNs are used to describe any physical page; this means
201 * PFN 0 == physical address 0. 204 * PFN 0 == physical address 0.
diff --git a/arch/arm/include/asm/tlb.h b/arch/arm/include/asm/tlb.h
index 314d4664eae7..99a19512ee26 100644
--- a/arch/arm/include/asm/tlb.h
+++ b/arch/arm/include/asm/tlb.h
@@ -199,6 +199,9 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
199{ 199{
200 pgtable_page_dtor(pte); 200 pgtable_page_dtor(pte);
201 201
202#ifdef CONFIG_ARM_LPAE
203 tlb_add_flush(tlb, addr);
204#else
202 /* 205 /*
203 * With the classic ARM MMU, a pte page has two corresponding pmd 206 * With the classic ARM MMU, a pte page has two corresponding pmd
204 * entries, each covering 1MB. 207 * entries, each covering 1MB.
@@ -206,6 +209,7 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
206 addr &= PMD_MASK; 209 addr &= PMD_MASK;
207 tlb_add_flush(tlb, addr + SZ_1M - PAGE_SIZE); 210 tlb_add_flush(tlb, addr + SZ_1M - PAGE_SIZE);
208 tlb_add_flush(tlb, addr + SZ_1M); 211 tlb_add_flush(tlb, addr + SZ_1M);
212#endif
209 213
210 tlb_remove_page(tlb, pte); 214 tlb_remove_page(tlb, pte);
211} 215}
diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
index 479a6352e0b5..77bd79f2ffdb 100644
--- a/arch/arm/include/asm/uaccess.h
+++ b/arch/arm/include/asm/uaccess.h
@@ -101,28 +101,39 @@ extern int __get_user_1(void *);
101extern int __get_user_2(void *); 101extern int __get_user_2(void *);
102extern int __get_user_4(void *); 102extern int __get_user_4(void *);
103 103
104#define __get_user_x(__r2,__p,__e,__s,__i...) \ 104#define __GUP_CLOBBER_1 "lr", "cc"
105#ifdef CONFIG_CPU_USE_DOMAINS
106#define __GUP_CLOBBER_2 "ip", "lr", "cc"
107#else
108#define __GUP_CLOBBER_2 "lr", "cc"
109#endif
110#define __GUP_CLOBBER_4 "lr", "cc"
111
112#define __get_user_x(__r2,__p,__e,__l,__s) \
105 __asm__ __volatile__ ( \ 113 __asm__ __volatile__ ( \
106 __asmeq("%0", "r0") __asmeq("%1", "r2") \ 114 __asmeq("%0", "r0") __asmeq("%1", "r2") \
115 __asmeq("%3", "r1") \
107 "bl __get_user_" #__s \ 116 "bl __get_user_" #__s \
108 : "=&r" (__e), "=r" (__r2) \ 117 : "=&r" (__e), "=r" (__r2) \
109 : "0" (__p) \ 118 : "0" (__p), "r" (__l) \
110 : __i, "cc") 119 : __GUP_CLOBBER_##__s)
111 120
112#define get_user(x,p) \ 121#define __get_user_check(x,p) \
113 ({ \ 122 ({ \
123 unsigned long __limit = current_thread_info()->addr_limit - 1; \
114 register const typeof(*(p)) __user *__p asm("r0") = (p);\ 124 register const typeof(*(p)) __user *__p asm("r0") = (p);\
115 register unsigned long __r2 asm("r2"); \ 125 register unsigned long __r2 asm("r2"); \
126 register unsigned long __l asm("r1") = __limit; \
116 register int __e asm("r0"); \ 127 register int __e asm("r0"); \
117 switch (sizeof(*(__p))) { \ 128 switch (sizeof(*(__p))) { \
118 case 1: \ 129 case 1: \
119 __get_user_x(__r2, __p, __e, 1, "lr"); \ 130 __get_user_x(__r2, __p, __e, __l, 1); \
120 break; \ 131 break; \
121 case 2: \ 132 case 2: \
122 __get_user_x(__r2, __p, __e, 2, "r3", "lr"); \ 133 __get_user_x(__r2, __p, __e, __l, 2); \
123 break; \ 134 break; \
124 case 4: \ 135 case 4: \
125 __get_user_x(__r2, __p, __e, 4, "lr"); \ 136 __get_user_x(__r2, __p, __e, __l, 4); \
126 break; \ 137 break; \
127 default: __e = __get_user_bad(); break; \ 138 default: __e = __get_user_bad(); break; \
128 } \ 139 } \
@@ -130,42 +141,57 @@ extern int __get_user_4(void *);
130 __e; \ 141 __e; \
131 }) 142 })
132 143
144#define get_user(x,p) \
145 ({ \
146 might_fault(); \
147 __get_user_check(x,p); \
148 })
149
133extern int __put_user_1(void *, unsigned int); 150extern int __put_user_1(void *, unsigned int);
134extern int __put_user_2(void *, unsigned int); 151extern int __put_user_2(void *, unsigned int);
135extern int __put_user_4(void *, unsigned int); 152extern int __put_user_4(void *, unsigned int);
136extern int __put_user_8(void *, unsigned long long); 153extern int __put_user_8(void *, unsigned long long);
137 154
138#define __put_user_x(__r2,__p,__e,__s) \ 155#define __put_user_x(__r2,__p,__e,__l,__s) \
139 __asm__ __volatile__ ( \ 156 __asm__ __volatile__ ( \
140 __asmeq("%0", "r0") __asmeq("%2", "r2") \ 157 __asmeq("%0", "r0") __asmeq("%2", "r2") \
158 __asmeq("%3", "r1") \
141 "bl __put_user_" #__s \ 159 "bl __put_user_" #__s \
142 : "=&r" (__e) \ 160 : "=&r" (__e) \
143 : "0" (__p), "r" (__r2) \ 161 : "0" (__p), "r" (__r2), "r" (__l) \
144 : "ip", "lr", "cc") 162 : "ip", "lr", "cc")
145 163
146#define put_user(x,p) \ 164#define __put_user_check(x,p) \
147 ({ \ 165 ({ \
166 unsigned long __limit = current_thread_info()->addr_limit - 1; \
148 register const typeof(*(p)) __r2 asm("r2") = (x); \ 167 register const typeof(*(p)) __r2 asm("r2") = (x); \
149 register const typeof(*(p)) __user *__p asm("r0") = (p);\ 168 register const typeof(*(p)) __user *__p asm("r0") = (p);\
169 register unsigned long __l asm("r1") = __limit; \
150 register int __e asm("r0"); \ 170 register int __e asm("r0"); \
151 switch (sizeof(*(__p))) { \ 171 switch (sizeof(*(__p))) { \
152 case 1: \ 172 case 1: \
153 __put_user_x(__r2, __p, __e, 1); \ 173 __put_user_x(__r2, __p, __e, __l, 1); \
154 break; \ 174 break; \
155 case 2: \ 175 case 2: \
156 __put_user_x(__r2, __p, __e, 2); \ 176 __put_user_x(__r2, __p, __e, __l, 2); \
157 break; \ 177 break; \
158 case 4: \ 178 case 4: \
159 __put_user_x(__r2, __p, __e, 4); \ 179 __put_user_x(__r2, __p, __e, __l, 4); \
160 break; \ 180 break; \
161 case 8: \ 181 case 8: \
162 __put_user_x(__r2, __p, __e, 8); \ 182 __put_user_x(__r2, __p, __e, __l, 8); \
163 break; \ 183 break; \
164 default: __e = __put_user_bad(); break; \ 184 default: __e = __put_user_bad(); break; \
165 } \ 185 } \
166 __e; \ 186 __e; \
167 }) 187 })
168 188
189#define put_user(x,p) \
190 ({ \
191 might_fault(); \
192 __put_user_check(x,p); \
193 })
194
169#else /* CONFIG_MMU */ 195#else /* CONFIG_MMU */
170 196
171/* 197/*
@@ -219,6 +245,7 @@ do { \
219 unsigned long __gu_addr = (unsigned long)(ptr); \ 245 unsigned long __gu_addr = (unsigned long)(ptr); \
220 unsigned long __gu_val; \ 246 unsigned long __gu_val; \
221 __chk_user_ptr(ptr); \ 247 __chk_user_ptr(ptr); \
248 might_fault(); \
222 switch (sizeof(*(ptr))) { \ 249 switch (sizeof(*(ptr))) { \
223 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \ 250 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
224 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \ 251 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
@@ -300,6 +327,7 @@ do { \
300 unsigned long __pu_addr = (unsigned long)(ptr); \ 327 unsigned long __pu_addr = (unsigned long)(ptr); \
301 __typeof__(*(ptr)) __pu_val = (x); \ 328 __typeof__(*(ptr)) __pu_val = (x); \
302 __chk_user_ptr(ptr); \ 329 __chk_user_ptr(ptr); \
330 might_fault(); \
303 switch (sizeof(*(ptr))) { \ 331 switch (sizeof(*(ptr))) { \
304 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \ 332 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
305 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \ 333 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h
index 0cab47d4a83f..2fde5fd1acce 100644
--- a/arch/arm/include/asm/unistd.h
+++ b/arch/arm/include/asm/unistd.h
@@ -404,6 +404,7 @@
404#define __NR_setns (__NR_SYSCALL_BASE+375) 404#define __NR_setns (__NR_SYSCALL_BASE+375)
405#define __NR_process_vm_readv (__NR_SYSCALL_BASE+376) 405#define __NR_process_vm_readv (__NR_SYSCALL_BASE+376)
406#define __NR_process_vm_writev (__NR_SYSCALL_BASE+377) 406#define __NR_process_vm_writev (__NR_SYSCALL_BASE+377)
407 /* 378 for kcmp */
407 408
408/* 409/*
409 * The following SWIs are ARM private. 410 * The following SWIs are ARM private.
@@ -483,6 +484,7 @@
483 */ 484 */
484#define __IGNORE_fadvise64_64 485#define __IGNORE_fadvise64_64
485#define __IGNORE_migrate_pages 486#define __IGNORE_migrate_pages
487#define __IGNORE_kcmp
486 488
487#endif /* __KERNEL__ */ 489#endif /* __KERNEL__ */
488#endif /* __ASM_ARM_UNISTD_H */ 490#endif /* __ASM_ARM_UNISTD_H */
diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S
index 463ff4a0ec8a..e337879595e5 100644
--- a/arch/arm/kernel/calls.S
+++ b/arch/arm/kernel/calls.S
@@ -387,6 +387,7 @@
387/* 375 */ CALL(sys_setns) 387/* 375 */ CALL(sys_setns)
388 CALL(sys_process_vm_readv) 388 CALL(sys_process_vm_readv)
389 CALL(sys_process_vm_writev) 389 CALL(sys_process_vm_writev)
390 CALL(sys_ni_syscall) /* reserved for sys_kcmp */
390#ifndef syscalls_counted 391#ifndef syscalls_counted
391.equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls 392.equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
392#define syscalls_counted 393#define syscalls_counted
diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
index ba386bd94107..281bf3301241 100644
--- a/arch/arm/kernel/hw_breakpoint.c
+++ b/arch/arm/kernel/hw_breakpoint.c
@@ -159,6 +159,12 @@ static int debug_arch_supported(void)
159 arch >= ARM_DEBUG_ARCH_V7_1; 159 arch >= ARM_DEBUG_ARCH_V7_1;
160} 160}
161 161
162/* Can we determine the watchpoint access type from the fsr? */
163static int debug_exception_updates_fsr(void)
164{
165 return 0;
166}
167
162/* Determine number of WRP registers available. */ 168/* Determine number of WRP registers available. */
163static int get_num_wrp_resources(void) 169static int get_num_wrp_resources(void)
164{ 170{
@@ -604,13 +610,14 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp)
604 /* Aligned */ 610 /* Aligned */
605 break; 611 break;
606 case 1: 612 case 1:
607 /* Allow single byte watchpoint. */
608 if (info->ctrl.len == ARM_BREAKPOINT_LEN_1)
609 break;
610 case 2: 613 case 2:
611 /* Allow halfword watchpoints and breakpoints. */ 614 /* Allow halfword watchpoints and breakpoints. */
612 if (info->ctrl.len == ARM_BREAKPOINT_LEN_2) 615 if (info->ctrl.len == ARM_BREAKPOINT_LEN_2)
613 break; 616 break;
617 case 3:
618 /* Allow single byte watchpoint. */
619 if (info->ctrl.len == ARM_BREAKPOINT_LEN_1)
620 break;
614 default: 621 default:
615 ret = -EINVAL; 622 ret = -EINVAL;
616 goto out; 623 goto out;
@@ -619,18 +626,35 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp)
619 info->address &= ~alignment_mask; 626 info->address &= ~alignment_mask;
620 info->ctrl.len <<= offset; 627 info->ctrl.len <<= offset;
621 628
622 /* 629 if (!bp->overflow_handler) {
623 * Currently we rely on an overflow handler to take 630 /*
624 * care of single-stepping the breakpoint when it fires. 631 * Mismatch breakpoints are required for single-stepping
625 * In the case of userspace breakpoints on a core with V7 debug, 632 * breakpoints.
626 * we can use the mismatch feature as a poor-man's hardware 633 */
627 * single-step, but this only works for per-task breakpoints. 634 if (!core_has_mismatch_brps())
628 */ 635 return -EINVAL;
629 if (!bp->overflow_handler && (arch_check_bp_in_kernelspace(bp) || 636
630 !core_has_mismatch_brps() || !bp->hw.bp_target)) { 637 /* We don't allow mismatch breakpoints in kernel space. */
631 pr_warning("overflow handler required but none found\n"); 638 if (arch_check_bp_in_kernelspace(bp))
632 ret = -EINVAL; 639 return -EPERM;
640
641 /*
642 * Per-cpu breakpoints are not supported by our stepping
643 * mechanism.
644 */
645 if (!bp->hw.bp_target)
646 return -EINVAL;
647
648 /*
649 * We only support specific access types if the fsr
650 * reports them.
651 */
652 if (!debug_exception_updates_fsr() &&
653 (info->ctrl.type == ARM_BREAKPOINT_LOAD ||
654 info->ctrl.type == ARM_BREAKPOINT_STORE))
655 return -EINVAL;
633 } 656 }
657
634out: 658out:
635 return ret; 659 return ret;
636} 660}
@@ -706,10 +730,12 @@ static void watchpoint_handler(unsigned long addr, unsigned int fsr,
706 goto unlock; 730 goto unlock;
707 731
708 /* Check that the access type matches. */ 732 /* Check that the access type matches. */
709 access = (fsr & ARM_FSR_ACCESS_MASK) ? HW_BREAKPOINT_W : 733 if (debug_exception_updates_fsr()) {
710 HW_BREAKPOINT_R; 734 access = (fsr & ARM_FSR_ACCESS_MASK) ?
711 if (!(access & hw_breakpoint_type(wp))) 735 HW_BREAKPOINT_W : HW_BREAKPOINT_R;
712 goto unlock; 736 if (!(access & hw_breakpoint_type(wp)))
737 goto unlock;
738 }
713 739
714 /* We have a winner. */ 740 /* We have a winner. */
715 info->trigger = addr; 741 info->trigger = addr;
diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
index fef42b21cecb..e1f906989bb8 100644
--- a/arch/arm/kernel/smp_twd.c
+++ b/arch/arm/kernel/smp_twd.c
@@ -11,7 +11,6 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/clk.h> 13#include <linux/clk.h>
14#include <linux/cpufreq.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/device.h> 15#include <linux/device.h>
17#include <linux/err.h> 16#include <linux/err.h>
@@ -96,7 +95,52 @@ static void twd_timer_stop(struct clock_event_device *clk)
96 disable_percpu_irq(clk->irq); 95 disable_percpu_irq(clk->irq);
97} 96}
98 97
99#ifdef CONFIG_CPU_FREQ 98#ifdef CONFIG_COMMON_CLK
99
100/*
101 * Updates clockevent frequency when the cpu frequency changes.
102 * Called on the cpu that is changing frequency with interrupts disabled.
103 */
104static void twd_update_frequency(void *new_rate)
105{
106 twd_timer_rate = *((unsigned long *) new_rate);
107
108 clockevents_update_freq(*__this_cpu_ptr(twd_evt), twd_timer_rate);
109}
110
111static int twd_rate_change(struct notifier_block *nb,
112 unsigned long flags, void *data)
113{
114 struct clk_notifier_data *cnd = data;
115
116 /*
117 * The twd clock events must be reprogrammed to account for the new
118 * frequency. The timer is local to a cpu, so cross-call to the
119 * changing cpu.
120 */
121 if (flags == POST_RATE_CHANGE)
122 smp_call_function(twd_update_frequency,
123 (void *)&cnd->new_rate, 1);
124
125 return NOTIFY_OK;
126}
127
128static struct notifier_block twd_clk_nb = {
129 .notifier_call = twd_rate_change,
130};
131
132static int twd_clk_init(void)
133{
134 if (twd_evt && *__this_cpu_ptr(twd_evt) && !IS_ERR(twd_clk))
135 return clk_notifier_register(twd_clk, &twd_clk_nb);
136
137 return 0;
138}
139core_initcall(twd_clk_init);
140
141#elif defined (CONFIG_CPU_FREQ)
142
143#include <linux/cpufreq.h>
100 144
101/* 145/*
102 * Updates clockevent frequency when the cpu frequency changes. 146 * Updates clockevent frequency when the cpu frequency changes.
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index f7945218b8c6..b0179b89a04c 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -420,20 +420,23 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
420#endif 420#endif
421 instr = *(u32 *) pc; 421 instr = *(u32 *) pc;
422 } else if (thumb_mode(regs)) { 422 } else if (thumb_mode(regs)) {
423 get_user(instr, (u16 __user *)pc); 423 if (get_user(instr, (u16 __user *)pc))
424 goto die_sig;
424 if (is_wide_instruction(instr)) { 425 if (is_wide_instruction(instr)) {
425 unsigned int instr2; 426 unsigned int instr2;
426 get_user(instr2, (u16 __user *)pc+1); 427 if (get_user(instr2, (u16 __user *)pc+1))
428 goto die_sig;
427 instr <<= 16; 429 instr <<= 16;
428 instr |= instr2; 430 instr |= instr2;
429 } 431 }
430 } else { 432 } else if (get_user(instr, (u32 __user *)pc)) {
431 get_user(instr, (u32 __user *)pc); 433 goto die_sig;
432 } 434 }
433 435
434 if (call_undef_hook(regs, instr) == 0) 436 if (call_undef_hook(regs, instr) == 0)
435 return; 437 return;
436 438
439die_sig:
437#ifdef CONFIG_DEBUG_USER 440#ifdef CONFIG_DEBUG_USER
438 if (user_debug & UDBG_UNDEFINED) { 441 if (user_debug & UDBG_UNDEFINED) {
439 printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n", 442 printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n",
diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
index d6dacc69254e..395d5fbb8fa2 100644
--- a/arch/arm/lib/delay.c
+++ b/arch/arm/lib/delay.c
@@ -59,6 +59,7 @@ void __init init_current_timer_delay(unsigned long freq)
59{ 59{
60 pr_info("Switching to timer-based delay loop\n"); 60 pr_info("Switching to timer-based delay loop\n");
61 lpj_fine = freq / HZ; 61 lpj_fine = freq / HZ;
62 loops_per_jiffy = lpj_fine;
62 arm_delay_ops.delay = __timer_delay; 63 arm_delay_ops.delay = __timer_delay;
63 arm_delay_ops.const_udelay = __timer_const_udelay; 64 arm_delay_ops.const_udelay = __timer_const_udelay;
64 arm_delay_ops.udelay = __timer_udelay; 65 arm_delay_ops.udelay = __timer_udelay;
diff --git a/arch/arm/lib/getuser.S b/arch/arm/lib/getuser.S
index 11093a7c3e32..9b06bb41fca6 100644
--- a/arch/arm/lib/getuser.S
+++ b/arch/arm/lib/getuser.S
@@ -16,8 +16,9 @@
16 * __get_user_X 16 * __get_user_X
17 * 17 *
18 * Inputs: r0 contains the address 18 * Inputs: r0 contains the address
19 * r1 contains the address limit, which must be preserved
19 * Outputs: r0 is the error code 20 * Outputs: r0 is the error code
20 * r2, r3 contains the zero-extended value 21 * r2 contains the zero-extended value
21 * lr corrupted 22 * lr corrupted
22 * 23 *
23 * No other registers must be altered. (see <asm/uaccess.h> 24 * No other registers must be altered. (see <asm/uaccess.h>
@@ -27,33 +28,39 @@
27 * Note also that it is intended that __get_user_bad is not global. 28 * Note also that it is intended that __get_user_bad is not global.
28 */ 29 */
29#include <linux/linkage.h> 30#include <linux/linkage.h>
31#include <asm/assembler.h>
30#include <asm/errno.h> 32#include <asm/errno.h>
31#include <asm/domain.h> 33#include <asm/domain.h>
32 34
33ENTRY(__get_user_1) 35ENTRY(__get_user_1)
36 check_uaccess r0, 1, r1, r2, __get_user_bad
341: TUSER(ldrb) r2, [r0] 371: TUSER(ldrb) r2, [r0]
35 mov r0, #0 38 mov r0, #0
36 mov pc, lr 39 mov pc, lr
37ENDPROC(__get_user_1) 40ENDPROC(__get_user_1)
38 41
39ENTRY(__get_user_2) 42ENTRY(__get_user_2)
40#ifdef CONFIG_THUMB2_KERNEL 43 check_uaccess r0, 2, r1, r2, __get_user_bad
412: TUSER(ldrb) r2, [r0] 44#ifdef CONFIG_CPU_USE_DOMAINS
423: TUSER(ldrb) r3, [r0, #1] 45rb .req ip
462: ldrbt r2, [r0], #1
473: ldrbt rb, [r0], #0
43#else 48#else
442: TUSER(ldrb) r2, [r0], #1 49rb .req r0
453: TUSER(ldrb) r3, [r0] 502: ldrb r2, [r0]
513: ldrb rb, [r0, #1]
46#endif 52#endif
47#ifndef __ARMEB__ 53#ifndef __ARMEB__
48 orr r2, r2, r3, lsl #8 54 orr r2, r2, rb, lsl #8
49#else 55#else
50 orr r2, r3, r2, lsl #8 56 orr r2, rb, r2, lsl #8
51#endif 57#endif
52 mov r0, #0 58 mov r0, #0
53 mov pc, lr 59 mov pc, lr
54ENDPROC(__get_user_2) 60ENDPROC(__get_user_2)
55 61
56ENTRY(__get_user_4) 62ENTRY(__get_user_4)
63 check_uaccess r0, 4, r1, r2, __get_user_bad
574: TUSER(ldr) r2, [r0] 644: TUSER(ldr) r2, [r0]
58 mov r0, #0 65 mov r0, #0
59 mov pc, lr 66 mov pc, lr
diff --git a/arch/arm/lib/putuser.S b/arch/arm/lib/putuser.S
index 7db25990c589..3d73dcb959b0 100644
--- a/arch/arm/lib/putuser.S
+++ b/arch/arm/lib/putuser.S
@@ -16,6 +16,7 @@
16 * __put_user_X 16 * __put_user_X
17 * 17 *
18 * Inputs: r0 contains the address 18 * Inputs: r0 contains the address
19 * r1 contains the address limit, which must be preserved
19 * r2, r3 contains the value 20 * r2, r3 contains the value
20 * Outputs: r0 is the error code 21 * Outputs: r0 is the error code
21 * lr corrupted 22 * lr corrupted
@@ -27,16 +28,19 @@
27 * Note also that it is intended that __put_user_bad is not global. 28 * Note also that it is intended that __put_user_bad is not global.
28 */ 29 */
29#include <linux/linkage.h> 30#include <linux/linkage.h>
31#include <asm/assembler.h>
30#include <asm/errno.h> 32#include <asm/errno.h>
31#include <asm/domain.h> 33#include <asm/domain.h>
32 34
33ENTRY(__put_user_1) 35ENTRY(__put_user_1)
36 check_uaccess r0, 1, r1, ip, __put_user_bad
341: TUSER(strb) r2, [r0] 371: TUSER(strb) r2, [r0]
35 mov r0, #0 38 mov r0, #0
36 mov pc, lr 39 mov pc, lr
37ENDPROC(__put_user_1) 40ENDPROC(__put_user_1)
38 41
39ENTRY(__put_user_2) 42ENTRY(__put_user_2)
43 check_uaccess r0, 2, r1, ip, __put_user_bad
40 mov ip, r2, lsr #8 44 mov ip, r2, lsr #8
41#ifdef CONFIG_THUMB2_KERNEL 45#ifdef CONFIG_THUMB2_KERNEL
42#ifndef __ARMEB__ 46#ifndef __ARMEB__
@@ -60,12 +64,14 @@ ENTRY(__put_user_2)
60ENDPROC(__put_user_2) 64ENDPROC(__put_user_2)
61 65
62ENTRY(__put_user_4) 66ENTRY(__put_user_4)
67 check_uaccess r0, 4, r1, ip, __put_user_bad
634: TUSER(str) r2, [r0] 684: TUSER(str) r2, [r0]
64 mov r0, #0 69 mov r0, #0
65 mov pc, lr 70 mov pc, lr
66ENDPROC(__put_user_4) 71ENDPROC(__put_user_4)
67 72
68ENTRY(__put_user_8) 73ENTRY(__put_user_8)
74 check_uaccess r0, 8, r1, ip, __put_user_bad
69#ifdef CONFIG_THUMB2_KERNEL 75#ifdef CONFIG_THUMB2_KERNEL
705: TUSER(str) r2, [r0] 765: TUSER(str) r2, [r0]
716: TUSER(str) r3, [r0, #4] 776: TUSER(str) r3, [r0, #4]
diff --git a/arch/arm/mach-imx/clk-imx25.c b/arch/arm/mach-imx/clk-imx25.c
index fdd8cc87c9fe..d20d4795f4ea 100644
--- a/arch/arm/mach-imx/clk-imx25.c
+++ b/arch/arm/mach-imx/clk-imx25.c
@@ -222,10 +222,8 @@ int __init mx25_clocks_init(void)
222 clk_register_clkdev(clk[lcdc_ipg], "ipg", "imx-fb.0"); 222 clk_register_clkdev(clk[lcdc_ipg], "ipg", "imx-fb.0");
223 clk_register_clkdev(clk[lcdc_ahb], "ahb", "imx-fb.0"); 223 clk_register_clkdev(clk[lcdc_ahb], "ahb", "imx-fb.0");
224 clk_register_clkdev(clk[wdt_ipg], NULL, "imx2-wdt.0"); 224 clk_register_clkdev(clk[wdt_ipg], NULL, "imx2-wdt.0");
225 clk_register_clkdev(clk[ssi1_ipg_per], "per", "imx-ssi.0"); 225 clk_register_clkdev(clk[ssi1_ipg], NULL, "imx-ssi.0");
226 clk_register_clkdev(clk[ssi1_ipg], "ipg", "imx-ssi.0"); 226 clk_register_clkdev(clk[ssi2_ipg], NULL, "imx-ssi.1");
227 clk_register_clkdev(clk[ssi2_ipg_per], "per", "imx-ssi.1");
228 clk_register_clkdev(clk[ssi2_ipg], "ipg", "imx-ssi.1");
229 clk_register_clkdev(clk[esdhc1_ipg_per], "per", "sdhci-esdhc-imx25.0"); 227 clk_register_clkdev(clk[esdhc1_ipg_per], "per", "sdhci-esdhc-imx25.0");
230 clk_register_clkdev(clk[esdhc1_ipg], "ipg", "sdhci-esdhc-imx25.0"); 228 clk_register_clkdev(clk[esdhc1_ipg], "ipg", "sdhci-esdhc-imx25.0");
231 clk_register_clkdev(clk[esdhc1_ahb], "ahb", "sdhci-esdhc-imx25.0"); 229 clk_register_clkdev(clk[esdhc1_ahb], "ahb", "sdhci-esdhc-imx25.0");
@@ -243,6 +241,6 @@ int __init mx25_clocks_init(void)
243 clk_register_clkdev(clk[sdma_ahb], "ahb", "imx35-sdma"); 241 clk_register_clkdev(clk[sdma_ahb], "ahb", "imx35-sdma");
244 clk_register_clkdev(clk[iim_ipg], "iim", NULL); 242 clk_register_clkdev(clk[iim_ipg], "iim", NULL);
245 243
246 mxc_timer_init(MX25_IO_ADDRESS(MX25_GPT1_BASE_ADDR), 54); 244 mxc_timer_init(MX25_IO_ADDRESS(MX25_GPT1_BASE_ADDR), MX25_INT_GPT1);
247 return 0; 245 return 0;
248} 246}
diff --git a/arch/arm/mach-imx/clk-imx35.c b/arch/arm/mach-imx/clk-imx35.c
index c6422fb10bae..65fb8bcd86cb 100644
--- a/arch/arm/mach-imx/clk-imx35.c
+++ b/arch/arm/mach-imx/clk-imx35.c
@@ -230,10 +230,8 @@ int __init mx35_clocks_init()
230 clk_register_clkdev(clk[ipu_gate], NULL, "mx3_sdc_fb"); 230 clk_register_clkdev(clk[ipu_gate], NULL, "mx3_sdc_fb");
231 clk_register_clkdev(clk[owire_gate], NULL, "mxc_w1"); 231 clk_register_clkdev(clk[owire_gate], NULL, "mxc_w1");
232 clk_register_clkdev(clk[sdma_gate], NULL, "imx35-sdma"); 232 clk_register_clkdev(clk[sdma_gate], NULL, "imx35-sdma");
233 clk_register_clkdev(clk[ipg], "ipg", "imx-ssi.0"); 233 clk_register_clkdev(clk[ssi1_gate], NULL, "imx-ssi.0");
234 clk_register_clkdev(clk[ssi1_div_post], "per", "imx-ssi.0"); 234 clk_register_clkdev(clk[ssi2_gate], NULL, "imx-ssi.1");
235 clk_register_clkdev(clk[ipg], "ipg", "imx-ssi.1");
236 clk_register_clkdev(clk[ssi2_div_post], "per", "imx-ssi.1");
237 /* i.mx35 has the i.mx21 type uart */ 235 /* i.mx35 has the i.mx21 type uart */
238 clk_register_clkdev(clk[uart1_gate], "per", "imx21-uart.0"); 236 clk_register_clkdev(clk[uart1_gate], "per", "imx21-uart.0");
239 clk_register_clkdev(clk[ipg], "ipg", "imx21-uart.0"); 237 clk_register_clkdev(clk[ipg], "ipg", "imx21-uart.0");
diff --git a/arch/arm/mach-imx/mach-armadillo5x0.c b/arch/arm/mach-imx/mach-armadillo5x0.c
index 2c6ab3273f9e..5985ed1b8c98 100644
--- a/arch/arm/mach-imx/mach-armadillo5x0.c
+++ b/arch/arm/mach-imx/mach-armadillo5x0.c
@@ -526,7 +526,8 @@ static void __init armadillo5x0_init(void)
526 imx31_add_mxc_nand(&armadillo5x0_nand_board_info); 526 imx31_add_mxc_nand(&armadillo5x0_nand_board_info);
527 527
528 /* set NAND page size to 2k if not configured via boot mode pins */ 528 /* set NAND page size to 2k if not configured via boot mode pins */
529 __raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR); 529 __raw_writel(__raw_readl(mx3_ccm_base + MXC_CCM_RCSR) |
530 (1 << 30), mx3_ccm_base + MXC_CCM_RCSR);
530 531
531 /* RTC */ 532 /* RTC */
532 /* Get RTC IRQ and register the chip */ 533 /* Get RTC IRQ and register the chip */
diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index 8dabfe81d07c..ff886e01a0b0 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -261,7 +261,7 @@ static void __init apx4devkit_init(void)
261 enable_clk_enet_out(); 261 enable_clk_enet_out();
262 262
263 if (IS_BUILTIN(CONFIG_PHYLIB)) 263 if (IS_BUILTIN(CONFIG_PHYLIB))
264 phy_register_fixup_for_uid(PHY_ID_KS8051, MICREL_PHY_ID_MASK, 264 phy_register_fixup_for_uid(PHY_ID_KSZ8051, MICREL_PHY_ID_MASK,
265 apx4devkit_phy_fixup); 265 apx4devkit_phy_fixup);
266 266
267 mxsfb_pdata.mode_list = apx4devkit_video_modes; 267 mxsfb_pdata.mode_list = apx4devkit_video_modes;
diff --git a/arch/arm/mach-omap2/Kconfig b/arch/arm/mach-omap2/Kconfig
index fcd4e85c4ddc..346fd26f3aa6 100644
--- a/arch/arm/mach-omap2/Kconfig
+++ b/arch/arm/mach-omap2/Kconfig
@@ -232,10 +232,11 @@ config MACH_OMAP3_PANDORA
232 select OMAP_PACKAGE_CBB 232 select OMAP_PACKAGE_CBB
233 select REGULATOR_FIXED_VOLTAGE if REGULATOR 233 select REGULATOR_FIXED_VOLTAGE if REGULATOR
234 234
235config MACH_OMAP3_TOUCHBOOK 235config MACH_TOUCHBOOK
236 bool "OMAP3 Touch Book" 236 bool "OMAP3 Touch Book"
237 depends on ARCH_OMAP3 237 depends on ARCH_OMAP3
238 default y 238 default y
239 select OMAP_PACKAGE_CBB
239 240
240config MACH_OMAP_3430SDP 241config MACH_OMAP_3430SDP
241 bool "OMAP 3430 SDP board" 242 bool "OMAP 3430 SDP board"
diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index f6a24b3f9c4f..34c2c7f59f0a 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -255,7 +255,7 @@ obj-$(CONFIG_MACH_OMAP_3630SDP) += board-zoom-display.o
255obj-$(CONFIG_MACH_CM_T35) += board-cm-t35.o 255obj-$(CONFIG_MACH_CM_T35) += board-cm-t35.o
256obj-$(CONFIG_MACH_CM_T3517) += board-cm-t3517.o 256obj-$(CONFIG_MACH_CM_T3517) += board-cm-t3517.o
257obj-$(CONFIG_MACH_IGEP0020) += board-igep0020.o 257obj-$(CONFIG_MACH_IGEP0020) += board-igep0020.o
258obj-$(CONFIG_MACH_OMAP3_TOUCHBOOK) += board-omap3touchbook.o 258obj-$(CONFIG_MACH_TOUCHBOOK) += board-omap3touchbook.o
259obj-$(CONFIG_MACH_OMAP_4430SDP) += board-4430sdp.o 259obj-$(CONFIG_MACH_OMAP_4430SDP) += board-4430sdp.o
260obj-$(CONFIG_MACH_OMAP4_PANDA) += board-omap4panda.o 260obj-$(CONFIG_MACH_OMAP4_PANDA) += board-omap4panda.o
261 261
diff --git a/arch/arm/mach-omap2/clock33xx_data.c b/arch/arm/mach-omap2/clock33xx_data.c
index 25bbcc7ca4dc..ae27de8899a6 100644
--- a/arch/arm/mach-omap2/clock33xx_data.c
+++ b/arch/arm/mach-omap2/clock33xx_data.c
@@ -1036,13 +1036,13 @@ static struct omap_clk am33xx_clks[] = {
1036 CLK(NULL, "mmu_fck", &mmu_fck, CK_AM33XX), 1036 CLK(NULL, "mmu_fck", &mmu_fck, CK_AM33XX),
1037 CLK(NULL, "smartreflex0_fck", &smartreflex0_fck, CK_AM33XX), 1037 CLK(NULL, "smartreflex0_fck", &smartreflex0_fck, CK_AM33XX),
1038 CLK(NULL, "smartreflex1_fck", &smartreflex1_fck, CK_AM33XX), 1038 CLK(NULL, "smartreflex1_fck", &smartreflex1_fck, CK_AM33XX),
1039 CLK(NULL, "gpt1_fck", &timer1_fck, CK_AM33XX), 1039 CLK(NULL, "timer1_fck", &timer1_fck, CK_AM33XX),
1040 CLK(NULL, "gpt2_fck", &timer2_fck, CK_AM33XX), 1040 CLK(NULL, "timer2_fck", &timer2_fck, CK_AM33XX),
1041 CLK(NULL, "gpt3_fck", &timer3_fck, CK_AM33XX), 1041 CLK(NULL, "timer3_fck", &timer3_fck, CK_AM33XX),
1042 CLK(NULL, "gpt4_fck", &timer4_fck, CK_AM33XX), 1042 CLK(NULL, "timer4_fck", &timer4_fck, CK_AM33XX),
1043 CLK(NULL, "gpt5_fck", &timer5_fck, CK_AM33XX), 1043 CLK(NULL, "timer5_fck", &timer5_fck, CK_AM33XX),
1044 CLK(NULL, "gpt6_fck", &timer6_fck, CK_AM33XX), 1044 CLK(NULL, "timer6_fck", &timer6_fck, CK_AM33XX),
1045 CLK(NULL, "gpt7_fck", &timer7_fck, CK_AM33XX), 1045 CLK(NULL, "timer7_fck", &timer7_fck, CK_AM33XX),
1046 CLK(NULL, "usbotg_fck", &usbotg_fck, CK_AM33XX), 1046 CLK(NULL, "usbotg_fck", &usbotg_fck, CK_AM33XX),
1047 CLK(NULL, "ieee5000_fck", &ieee5000_fck, CK_AM33XX), 1047 CLK(NULL, "ieee5000_fck", &ieee5000_fck, CK_AM33XX),
1048 CLK(NULL, "wdt1_fck", &wdt1_fck, CK_AM33XX), 1048 CLK(NULL, "wdt1_fck", &wdt1_fck, CK_AM33XX),
diff --git a/arch/arm/mach-omap2/clockdomain2xxx_3xxx.c b/arch/arm/mach-omap2/clockdomain2xxx_3xxx.c
index a0d68dbecfa3..f99e65cfb862 100644
--- a/arch/arm/mach-omap2/clockdomain2xxx_3xxx.c
+++ b/arch/arm/mach-omap2/clockdomain2xxx_3xxx.c
@@ -241,6 +241,52 @@ static void omap3_clkdm_deny_idle(struct clockdomain *clkdm)
241 _clkdm_del_autodeps(clkdm); 241 _clkdm_del_autodeps(clkdm);
242} 242}
243 243
244static int omap3xxx_clkdm_clk_enable(struct clockdomain *clkdm)
245{
246 bool hwsup = false;
247
248 if (!clkdm->clktrctrl_mask)
249 return 0;
250
251 hwsup = omap2_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
252 clkdm->clktrctrl_mask);
253
254 if (hwsup) {
255 /* Disable HW transitions when we are changing deps */
256 _disable_hwsup(clkdm);
257 _clkdm_add_autodeps(clkdm);
258 _enable_hwsup(clkdm);
259 } else {
260 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
261 omap3_clkdm_wakeup(clkdm);
262 }
263
264 return 0;
265}
266
267static int omap3xxx_clkdm_clk_disable(struct clockdomain *clkdm)
268{
269 bool hwsup = false;
270
271 if (!clkdm->clktrctrl_mask)
272 return 0;
273
274 hwsup = omap2_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
275 clkdm->clktrctrl_mask);
276
277 if (hwsup) {
278 /* Disable HW transitions when we are changing deps */
279 _disable_hwsup(clkdm);
280 _clkdm_del_autodeps(clkdm);
281 _enable_hwsup(clkdm);
282 } else {
283 if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP)
284 omap3_clkdm_sleep(clkdm);
285 }
286
287 return 0;
288}
289
244struct clkdm_ops omap2_clkdm_operations = { 290struct clkdm_ops omap2_clkdm_operations = {
245 .clkdm_add_wkdep = omap2_clkdm_add_wkdep, 291 .clkdm_add_wkdep = omap2_clkdm_add_wkdep,
246 .clkdm_del_wkdep = omap2_clkdm_del_wkdep, 292 .clkdm_del_wkdep = omap2_clkdm_del_wkdep,
@@ -267,6 +313,6 @@ struct clkdm_ops omap3_clkdm_operations = {
267 .clkdm_wakeup = omap3_clkdm_wakeup, 313 .clkdm_wakeup = omap3_clkdm_wakeup,
268 .clkdm_allow_idle = omap3_clkdm_allow_idle, 314 .clkdm_allow_idle = omap3_clkdm_allow_idle,
269 .clkdm_deny_idle = omap3_clkdm_deny_idle, 315 .clkdm_deny_idle = omap3_clkdm_deny_idle,
270 .clkdm_clk_enable = omap2_clkdm_clk_enable, 316 .clkdm_clk_enable = omap3xxx_clkdm_clk_enable,
271 .clkdm_clk_disable = omap2_clkdm_clk_disable, 317 .clkdm_clk_disable = omap3xxx_clkdm_clk_disable,
272}; 318};
diff --git a/arch/arm/mach-omap2/cm-regbits-34xx.h b/arch/arm/mach-omap2/cm-regbits-34xx.h
index 766338fe4d34..975f6bda0e0b 100644
--- a/arch/arm/mach-omap2/cm-regbits-34xx.h
+++ b/arch/arm/mach-omap2/cm-regbits-34xx.h
@@ -67,6 +67,7 @@
67#define OMAP3430_EN_IVA2_DPLL_MASK (0x7 << 0) 67#define OMAP3430_EN_IVA2_DPLL_MASK (0x7 << 0)
68 68
69/* CM_IDLEST_IVA2 */ 69/* CM_IDLEST_IVA2 */
70#define OMAP3430_ST_IVA2_SHIFT 0
70#define OMAP3430_ST_IVA2_MASK (1 << 0) 71#define OMAP3430_ST_IVA2_MASK (1 << 0)
71 72
72/* CM_IDLEST_PLL_IVA2 */ 73/* CM_IDLEST_PLL_IVA2 */
diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
index 05fdebfaa195..330d4c6e746b 100644
--- a/arch/arm/mach-omap2/omap-wakeupgen.c
+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
@@ -46,7 +46,7 @@
46static void __iomem *wakeupgen_base; 46static void __iomem *wakeupgen_base;
47static void __iomem *sar_base; 47static void __iomem *sar_base;
48static DEFINE_SPINLOCK(wakeupgen_lock); 48static DEFINE_SPINLOCK(wakeupgen_lock);
49static unsigned int irq_target_cpu[NR_IRQS]; 49static unsigned int irq_target_cpu[MAX_IRQS];
50static unsigned int irq_banks = MAX_NR_REG_BANKS; 50static unsigned int irq_banks = MAX_NR_REG_BANKS;
51static unsigned int max_irqs = MAX_IRQS; 51static unsigned int max_irqs = MAX_IRQS;
52static unsigned int omap_secure_apis; 52static unsigned int omap_secure_apis;
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index 6ca8e519968d..37afbd173c2c 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -1889,6 +1889,7 @@ static int _enable(struct omap_hwmod *oh)
1889 _enable_sysc(oh); 1889 _enable_sysc(oh);
1890 } 1890 }
1891 } else { 1891 } else {
1892 _omap4_disable_module(oh);
1892 _disable_clocks(oh); 1893 _disable_clocks(oh);
1893 pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n", 1894 pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
1894 oh->name, r); 1895 oh->name, r);
diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
index c9e38200216b..ce7e6068768f 100644
--- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
@@ -100,9 +100,9 @@ static struct omap_hwmod omap3xxx_mpu_hwmod = {
100 100
101/* IVA2 (IVA2) */ 101/* IVA2 (IVA2) */
102static struct omap_hwmod_rst_info omap3xxx_iva_resets[] = { 102static struct omap_hwmod_rst_info omap3xxx_iva_resets[] = {
103 { .name = "logic", .rst_shift = 0 }, 103 { .name = "logic", .rst_shift = 0, .st_shift = 8 },
104 { .name = "seq0", .rst_shift = 1 }, 104 { .name = "seq0", .rst_shift = 1, .st_shift = 9 },
105 { .name = "seq1", .rst_shift = 2 }, 105 { .name = "seq1", .rst_shift = 2, .st_shift = 10 },
106}; 106};
107 107
108static struct omap_hwmod omap3xxx_iva_hwmod = { 108static struct omap_hwmod omap3xxx_iva_hwmod = {
@@ -112,6 +112,15 @@ static struct omap_hwmod omap3xxx_iva_hwmod = {
112 .rst_lines = omap3xxx_iva_resets, 112 .rst_lines = omap3xxx_iva_resets,
113 .rst_lines_cnt = ARRAY_SIZE(omap3xxx_iva_resets), 113 .rst_lines_cnt = ARRAY_SIZE(omap3xxx_iva_resets),
114 .main_clk = "iva2_ck", 114 .main_clk = "iva2_ck",
115 .prcm = {
116 .omap2 = {
117 .module_offs = OMAP3430_IVA2_MOD,
118 .prcm_reg_id = 1,
119 .module_bit = OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_SHIFT,
120 .idlest_reg_id = 1,
121 .idlest_idle_bit = OMAP3430_ST_IVA2_SHIFT,
122 }
123 },
115}; 124};
116 125
117/* timer class */ 126/* timer class */
diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index 242aee498ceb..afb60917a948 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -4210,7 +4210,7 @@ static struct omap_hwmod_ocp_if omap44xx_dsp__iva = {
4210}; 4210};
4211 4211
4212/* dsp -> sl2if */ 4212/* dsp -> sl2if */
4213static struct omap_hwmod_ocp_if omap44xx_dsp__sl2if = { 4213static struct omap_hwmod_ocp_if __maybe_unused omap44xx_dsp__sl2if = {
4214 .master = &omap44xx_dsp_hwmod, 4214 .master = &omap44xx_dsp_hwmod,
4215 .slave = &omap44xx_sl2if_hwmod, 4215 .slave = &omap44xx_sl2if_hwmod,
4216 .clk = "dpll_iva_m5x2_ck", 4216 .clk = "dpll_iva_m5x2_ck",
@@ -4828,7 +4828,7 @@ static struct omap_hwmod_ocp_if omap44xx_l3_main_2__iss = {
4828}; 4828};
4829 4829
4830/* iva -> sl2if */ 4830/* iva -> sl2if */
4831static struct omap_hwmod_ocp_if omap44xx_iva__sl2if = { 4831static struct omap_hwmod_ocp_if __maybe_unused omap44xx_iva__sl2if = {
4832 .master = &omap44xx_iva_hwmod, 4832 .master = &omap44xx_iva_hwmod,
4833 .slave = &omap44xx_sl2if_hwmod, 4833 .slave = &omap44xx_sl2if_hwmod,
4834 .clk = "dpll_iva_m5x2_ck", 4834 .clk = "dpll_iva_m5x2_ck",
@@ -5362,7 +5362,7 @@ static struct omap_hwmod_ocp_if omap44xx_l4_wkup__scrm = {
5362}; 5362};
5363 5363
5364/* l3_main_2 -> sl2if */ 5364/* l3_main_2 -> sl2if */
5365static struct omap_hwmod_ocp_if omap44xx_l3_main_2__sl2if = { 5365static struct omap_hwmod_ocp_if __maybe_unused omap44xx_l3_main_2__sl2if = {
5366 .master = &omap44xx_l3_main_2_hwmod, 5366 .master = &omap44xx_l3_main_2_hwmod,
5367 .slave = &omap44xx_sl2if_hwmod, 5367 .slave = &omap44xx_sl2if_hwmod,
5368 .clk = "l3_div_ck", 5368 .clk = "l3_div_ck",
@@ -6032,7 +6032,7 @@ static struct omap_hwmod_ocp_if *omap44xx_hwmod_ocp_ifs[] __initdata = {
6032 &omap44xx_l4_abe__dmic, 6032 &omap44xx_l4_abe__dmic,
6033 &omap44xx_l4_abe__dmic_dma, 6033 &omap44xx_l4_abe__dmic_dma,
6034 &omap44xx_dsp__iva, 6034 &omap44xx_dsp__iva,
6035 &omap44xx_dsp__sl2if, 6035 /* &omap44xx_dsp__sl2if, */
6036 &omap44xx_l4_cfg__dsp, 6036 &omap44xx_l4_cfg__dsp,
6037 &omap44xx_l3_main_2__dss, 6037 &omap44xx_l3_main_2__dss,
6038 &omap44xx_l4_per__dss, 6038 &omap44xx_l4_per__dss,
@@ -6068,7 +6068,7 @@ static struct omap_hwmod_ocp_if *omap44xx_hwmod_ocp_ifs[] __initdata = {
6068 &omap44xx_l4_per__i2c4, 6068 &omap44xx_l4_per__i2c4,
6069 &omap44xx_l3_main_2__ipu, 6069 &omap44xx_l3_main_2__ipu,
6070 &omap44xx_l3_main_2__iss, 6070 &omap44xx_l3_main_2__iss,
6071 &omap44xx_iva__sl2if, 6071 /* &omap44xx_iva__sl2if, */
6072 &omap44xx_l3_main_2__iva, 6072 &omap44xx_l3_main_2__iva,
6073 &omap44xx_l4_wkup__kbd, 6073 &omap44xx_l4_wkup__kbd,
6074 &omap44xx_l4_cfg__mailbox, 6074 &omap44xx_l4_cfg__mailbox,
@@ -6099,7 +6099,7 @@ static struct omap_hwmod_ocp_if *omap44xx_hwmod_ocp_ifs[] __initdata = {
6099 &omap44xx_l4_cfg__cm_core, 6099 &omap44xx_l4_cfg__cm_core,
6100 &omap44xx_l4_wkup__prm, 6100 &omap44xx_l4_wkup__prm,
6101 &omap44xx_l4_wkup__scrm, 6101 &omap44xx_l4_wkup__scrm,
6102 &omap44xx_l3_main_2__sl2if, 6102 /* &omap44xx_l3_main_2__sl2if, */
6103 &omap44xx_l4_abe__slimbus1, 6103 &omap44xx_l4_abe__slimbus1,
6104 &omap44xx_l4_abe__slimbus1_dma, 6104 &omap44xx_l4_abe__slimbus1_dma,
6105 &omap44xx_l4_per__slimbus2, 6105 &omap44xx_l4_per__slimbus2,
diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c
index 2ff6d41ec6c6..2ba4f57dda86 100644
--- a/arch/arm/mach-omap2/timer.c
+++ b/arch/arm/mach-omap2/timer.c
@@ -260,6 +260,7 @@ static u32 notrace dmtimer_read_sched_clock(void)
260 return 0; 260 return 0;
261} 261}
262 262
263#ifdef CONFIG_OMAP_32K_TIMER
263/* Setup free-running counter for clocksource */ 264/* Setup free-running counter for clocksource */
264static int __init omap2_sync32k_clocksource_init(void) 265static int __init omap2_sync32k_clocksource_init(void)
265{ 266{
@@ -299,6 +300,12 @@ static int __init omap2_sync32k_clocksource_init(void)
299 300
300 return ret; 301 return ret;
301} 302}
303#else
304static inline int omap2_sync32k_clocksource_init(void)
305{
306 return -ENODEV;
307}
308#endif
302 309
303static void __init omap2_gptimer_clocksource_init(int gptimer_id, 310static void __init omap2_gptimer_clocksource_init(int gptimer_id,
304 const char *fck_source) 311 const char *fck_source)
diff --git a/arch/arm/mach-orion5x/common.c b/arch/arm/mach-orion5x/common.c
index 410291c67666..a6cd14ab1e4e 100644
--- a/arch/arm/mach-orion5x/common.c
+++ b/arch/arm/mach-orion5x/common.c
@@ -204,6 +204,13 @@ void __init orion5x_wdt_init(void)
204void __init orion5x_init_early(void) 204void __init orion5x_init_early(void)
205{ 205{
206 orion_time_set_base(TIMER_VIRT_BASE); 206 orion_time_set_base(TIMER_VIRT_BASE);
207
208 /*
209 * Some Orion5x devices allocate their coherent buffers from atomic
210 * context. Increase size of atomic coherent pool to make sure such
211 * the allocations won't fail.
212 */
213 init_dma_coherent_pool_size(SZ_1M);
207} 214}
208 215
209int orion5x_tclk; 216int orion5x_tclk;
diff --git a/arch/arm/mach-shmobile/board-kzm9g.c b/arch/arm/mach-shmobile/board-kzm9g.c
index 53b7ea92c32c..3b8a0171c3cb 100644
--- a/arch/arm/mach-shmobile/board-kzm9g.c
+++ b/arch/arm/mach-shmobile/board-kzm9g.c
@@ -346,11 +346,11 @@ static struct resource sh_mmcif_resources[] = {
346 .flags = IORESOURCE_MEM, 346 .flags = IORESOURCE_MEM,
347 }, 347 },
348 [1] = { 348 [1] = {
349 .start = gic_spi(141), 349 .start = gic_spi(140),
350 .flags = IORESOURCE_IRQ, 350 .flags = IORESOURCE_IRQ,
351 }, 351 },
352 [2] = { 352 [2] = {
353 .start = gic_spi(140), 353 .start = gic_spi(141),
354 .flags = IORESOURCE_IRQ, 354 .flags = IORESOURCE_IRQ,
355 }, 355 },
356}; 356};
diff --git a/arch/arm/mach-tegra/board-harmony-power.c b/arch/arm/mach-tegra/board-harmony-power.c
index b7344beec102..94486e7e9dfd 100644
--- a/arch/arm/mach-tegra/board-harmony-power.c
+++ b/arch/arm/mach-tegra/board-harmony-power.c
@@ -67,6 +67,13 @@ static struct regulator_init_data ldo0_data = {
67 }, \ 67 }, \
68 } 68 }
69 69
70static struct regulator_init_data sys_data = {
71 .supply_regulator = "vdd_5v0",
72 .constraints = {
73 .name = "vdd_sys",
74 },
75};
76
70HARMONY_REGULATOR_INIT(sm0, "vdd_sm0", "vdd_sys", 725, 1500, 1); 77HARMONY_REGULATOR_INIT(sm0, "vdd_sm0", "vdd_sys", 725, 1500, 1);
71HARMONY_REGULATOR_INIT(sm1, "vdd_sm1", "vdd_sys", 725, 1500, 1); 78HARMONY_REGULATOR_INIT(sm1, "vdd_sm1", "vdd_sys", 725, 1500, 1);
72HARMONY_REGULATOR_INIT(sm2, "vdd_sm2", "vdd_sys", 3000, 4550, 1); 79HARMONY_REGULATOR_INIT(sm2, "vdd_sm2", "vdd_sys", 3000, 4550, 1);
@@ -74,7 +81,7 @@ HARMONY_REGULATOR_INIT(ldo1, "vdd_ldo1", "vdd_sm2", 725, 1500, 1);
74HARMONY_REGULATOR_INIT(ldo2, "vdd_ldo2", "vdd_sm2", 725, 1500, 0); 81HARMONY_REGULATOR_INIT(ldo2, "vdd_ldo2", "vdd_sm2", 725, 1500, 0);
75HARMONY_REGULATOR_INIT(ldo3, "vdd_ldo3", "vdd_sm2", 1250, 3300, 1); 82HARMONY_REGULATOR_INIT(ldo3, "vdd_ldo3", "vdd_sm2", 1250, 3300, 1);
76HARMONY_REGULATOR_INIT(ldo4, "vdd_ldo4", "vdd_sm2", 1700, 2475, 1); 83HARMONY_REGULATOR_INIT(ldo4, "vdd_ldo4", "vdd_sm2", 1700, 2475, 1);
77HARMONY_REGULATOR_INIT(ldo5, "vdd_ldo5", NULL, 1250, 3300, 1); 84HARMONY_REGULATOR_INIT(ldo5, "vdd_ldo5", "vdd_sys", 1250, 3300, 1);
78HARMONY_REGULATOR_INIT(ldo6, "vdd_ldo6", "vdd_sm2", 1250, 3300, 0); 85HARMONY_REGULATOR_INIT(ldo6, "vdd_ldo6", "vdd_sm2", 1250, 3300, 0);
79HARMONY_REGULATOR_INIT(ldo7, "vdd_ldo7", "vdd_sm2", 1250, 3300, 0); 86HARMONY_REGULATOR_INIT(ldo7, "vdd_ldo7", "vdd_sm2", 1250, 3300, 0);
80HARMONY_REGULATOR_INIT(ldo8, "vdd_ldo8", "vdd_sm2", 1250, 3300, 0); 87HARMONY_REGULATOR_INIT(ldo8, "vdd_ldo8", "vdd_sm2", 1250, 3300, 0);
@@ -88,6 +95,7 @@ HARMONY_REGULATOR_INIT(ldo9, "vdd_ldo9", "vdd_sm2", 1250, 3300, 1);
88 } 95 }
89 96
90static struct tps6586x_subdev_info tps_devs[] = { 97static struct tps6586x_subdev_info tps_devs[] = {
98 TPS_REG(SYS, &sys_data),
91 TPS_REG(SM_0, &sm0_data), 99 TPS_REG(SM_0, &sm0_data),
92 TPS_REG(SM_1, &sm1_data), 100 TPS_REG(SM_1, &sm1_data),
93 TPS_REG(SM_2, &sm2_data), 101 TPS_REG(SM_2, &sm2_data),
@@ -120,7 +128,7 @@ static struct i2c_board_info __initdata harmony_regulators[] = {
120 128
121int __init harmony_regulator_init(void) 129int __init harmony_regulator_init(void)
122{ 130{
123 regulator_register_always_on(0, "vdd_sys", 131 regulator_register_always_on(0, "vdd_5v0",
124 NULL, 0, 5000000); 132 NULL, 0, 5000000);
125 133
126 if (machine_is_harmony()) { 134 if (machine_is_harmony()) {
diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
index 119bc52ab93e..4e07eec1270d 100644
--- a/arch/arm/mm/context.c
+++ b/arch/arm/mm/context.c
@@ -63,10 +63,11 @@ static int contextidr_notifier(struct notifier_block *unused, unsigned long cmd,
63 pid = task_pid_nr(thread->task) << ASID_BITS; 63 pid = task_pid_nr(thread->task) << ASID_BITS;
64 asm volatile( 64 asm volatile(
65 " mrc p15, 0, %0, c13, c0, 1\n" 65 " mrc p15, 0, %0, c13, c0, 1\n"
66 " bfi %1, %0, #0, %2\n" 66 " and %0, %0, %2\n"
67 " mcr p15, 0, %1, c13, c0, 1\n" 67 " orr %0, %0, %1\n"
68 " mcr p15, 0, %0, c13, c0, 1\n"
68 : "=r" (contextidr), "+r" (pid) 69 : "=r" (contextidr), "+r" (pid)
69 : "I" (ASID_BITS)); 70 : "I" (~ASID_MASK));
70 isb(); 71 isb();
71 72
72 return NOTIFY_OK; 73 return NOTIFY_OK;
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 051204fc4617..13f555d62491 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -346,6 +346,8 @@ static int __init atomic_pool_init(void)
346 (unsigned)pool->size / 1024); 346 (unsigned)pool->size / 1024);
347 return 0; 347 return 0;
348 } 348 }
349
350 kfree(pages);
349no_pages: 351no_pages:
350 kfree(bitmap); 352 kfree(bitmap);
351no_bitmap: 353no_bitmap:
@@ -489,7 +491,7 @@ static bool __in_atomic_pool(void *start, size_t size)
489 void *pool_start = pool->vaddr; 491 void *pool_start = pool->vaddr;
490 void *pool_end = pool->vaddr + pool->size; 492 void *pool_end = pool->vaddr + pool->size;
491 493
492 if (start < pool_start || start > pool_end) 494 if (start < pool_start || start >= pool_end)
493 return false; 495 return false;
494 496
495 if (end <= pool_end) 497 if (end <= pool_end)
diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h
index 6776160618ef..a8ee92da3544 100644
--- a/arch/arm/mm/mm.h
+++ b/arch/arm/mm/mm.h
@@ -55,6 +55,9 @@ extern void __flush_dcache_page(struct address_space *mapping, struct page *page
55/* permanent static mappings from iotable_init() */ 55/* permanent static mappings from iotable_init() */
56#define VM_ARM_STATIC_MAPPING 0x40000000 56#define VM_ARM_STATIC_MAPPING 0x40000000
57 57
58/* empty mapping */
59#define VM_ARM_EMPTY_MAPPING 0x20000000
60
58/* mapping type (attributes) for permanent static mappings */ 61/* mapping type (attributes) for permanent static mappings */
59#define VM_ARM_MTYPE(mt) ((mt) << 20) 62#define VM_ARM_MTYPE(mt) ((mt) << 20)
60#define VM_ARM_MTYPE_MASK (0x1f << 20) 63#define VM_ARM_MTYPE_MASK (0x1f << 20)
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 4c2d0451e84a..c2fa21d0103e 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -807,7 +807,7 @@ static void __init pmd_empty_section_gap(unsigned long addr)
807 vm = early_alloc_aligned(sizeof(*vm), __alignof__(*vm)); 807 vm = early_alloc_aligned(sizeof(*vm), __alignof__(*vm));
808 vm->addr = (void *)addr; 808 vm->addr = (void *)addr;
809 vm->size = SECTION_SIZE; 809 vm->size = SECTION_SIZE;
810 vm->flags = VM_IOREMAP | VM_ARM_STATIC_MAPPING; 810 vm->flags = VM_IOREMAP | VM_ARM_EMPTY_MAPPING;
811 vm->caller = pmd_empty_section_gap; 811 vm->caller = pmd_empty_section_gap;
812 vm_area_add_early(vm); 812 vm_area_add_early(vm);
813} 813}
@@ -820,7 +820,7 @@ static void __init fill_pmd_gaps(void)
820 820
821 /* we're still single threaded hence no lock needed here */ 821 /* we're still single threaded hence no lock needed here */
822 for (vm = vmlist; vm; vm = vm->next) { 822 for (vm = vmlist; vm; vm = vm->next) {
823 if (!(vm->flags & VM_ARM_STATIC_MAPPING)) 823 if (!(vm->flags & (VM_ARM_STATIC_MAPPING | VM_ARM_EMPTY_MAPPING)))
824 continue; 824 continue;
825 addr = (unsigned long)vm->addr; 825 addr = (unsigned long)vm->addr;
826 if (addr < next) 826 if (addr < next)
@@ -961,8 +961,8 @@ void __init sanity_check_meminfo(void)
961 * Check whether this memory bank would partially overlap 961 * Check whether this memory bank would partially overlap
962 * the vmalloc area. 962 * the vmalloc area.
963 */ 963 */
964 if (__va(bank->start + bank->size) > vmalloc_min || 964 if (__va(bank->start + bank->size - 1) >= vmalloc_min ||
965 __va(bank->start + bank->size) < __va(bank->start)) { 965 __va(bank->start + bank->size - 1) <= __va(bank->start)) {
966 unsigned long newsize = vmalloc_min - __va(bank->start); 966 unsigned long newsize = vmalloc_min - __va(bank->start);
967 printk(KERN_NOTICE "Truncating RAM at %.8llx-%.8llx " 967 printk(KERN_NOTICE "Truncating RAM at %.8llx-%.8llx "
968 "to -%.8llx (vmalloc region overlap).\n", 968 "to -%.8llx (vmalloc region overlap).\n",
diff --git a/arch/arm/plat-mxc/include/mach/mx25.h b/arch/arm/plat-mxc/include/mach/mx25.h
index 627d94f1b010..ec466400a200 100644
--- a/arch/arm/plat-mxc/include/mach/mx25.h
+++ b/arch/arm/plat-mxc/include/mach/mx25.h
@@ -98,6 +98,7 @@
98#define MX25_INT_UART1 (NR_IRQS_LEGACY + 45) 98#define MX25_INT_UART1 (NR_IRQS_LEGACY + 45)
99#define MX25_INT_GPIO2 (NR_IRQS_LEGACY + 51) 99#define MX25_INT_GPIO2 (NR_IRQS_LEGACY + 51)
100#define MX25_INT_GPIO1 (NR_IRQS_LEGACY + 52) 100#define MX25_INT_GPIO1 (NR_IRQS_LEGACY + 52)
101#define MX25_INT_GPT1 (NR_IRQS_LEGACY + 54)
101#define MX25_INT_FEC (NR_IRQS_LEGACY + 57) 102#define MX25_INT_FEC (NR_IRQS_LEGACY + 57)
102 103
103#define MX25_DMA_REQ_SSI2_RX1 22 104#define MX25_DMA_REQ_SSI2_RX1 22
diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
index 766181cb5c95..024f3b08db29 100644
--- a/arch/arm/plat-omap/sram.c
+++ b/arch/arm/plat-omap/sram.c
@@ -68,6 +68,7 @@
68 68
69static unsigned long omap_sram_start; 69static unsigned long omap_sram_start;
70static void __iomem *omap_sram_base; 70static void __iomem *omap_sram_base;
71static unsigned long omap_sram_skip;
71static unsigned long omap_sram_size; 72static unsigned long omap_sram_size;
72static void __iomem *omap_sram_ceil; 73static void __iomem *omap_sram_ceil;
73 74
@@ -106,6 +107,7 @@ static int is_sram_locked(void)
106 */ 107 */
107static void __init omap_detect_sram(void) 108static void __init omap_detect_sram(void)
108{ 109{
110 omap_sram_skip = SRAM_BOOTLOADER_SZ;
109 if (cpu_class_is_omap2()) { 111 if (cpu_class_is_omap2()) {
110 if (is_sram_locked()) { 112 if (is_sram_locked()) {
111 if (cpu_is_omap34xx()) { 113 if (cpu_is_omap34xx()) {
@@ -113,6 +115,7 @@ static void __init omap_detect_sram(void)
113 if ((omap_type() == OMAP2_DEVICE_TYPE_EMU) || 115 if ((omap_type() == OMAP2_DEVICE_TYPE_EMU) ||
114 (omap_type() == OMAP2_DEVICE_TYPE_SEC)) { 116 (omap_type() == OMAP2_DEVICE_TYPE_SEC)) {
115 omap_sram_size = 0x7000; /* 28K */ 117 omap_sram_size = 0x7000; /* 28K */
118 omap_sram_skip += SZ_16K;
116 } else { 119 } else {
117 omap_sram_size = 0x8000; /* 32K */ 120 omap_sram_size = 0x8000; /* 32K */
118 } 121 }
@@ -175,8 +178,10 @@ static void __init omap_map_sram(void)
175 return; 178 return;
176 179
177#ifdef CONFIG_OMAP4_ERRATA_I688 180#ifdef CONFIG_OMAP4_ERRATA_I688
181 if (cpu_is_omap44xx()) {
178 omap_sram_start += PAGE_SIZE; 182 omap_sram_start += PAGE_SIZE;
179 omap_sram_size -= SZ_16K; 183 omap_sram_size -= SZ_16K;
184 }
180#endif 185#endif
181 if (cpu_is_omap34xx()) { 186 if (cpu_is_omap34xx()) {
182 /* 187 /*
@@ -203,8 +208,8 @@ static void __init omap_map_sram(void)
203 * Looks like we need to preserve some bootloader code at the 208 * Looks like we need to preserve some bootloader code at the
204 * beginning of SRAM for jumping to flash for reboot to work... 209 * beginning of SRAM for jumping to flash for reboot to work...
205 */ 210 */
206 memset_io(omap_sram_base + SRAM_BOOTLOADER_SZ, 0, 211 memset_io(omap_sram_base + omap_sram_skip, 0,
207 omap_sram_size - SRAM_BOOTLOADER_SZ); 212 omap_sram_size - omap_sram_skip);
208} 213}
209 214
210/* 215/*
@@ -218,7 +223,7 @@ void *omap_sram_push_address(unsigned long size)
218{ 223{
219 unsigned long available, new_ceil = (unsigned long)omap_sram_ceil; 224 unsigned long available, new_ceil = (unsigned long)omap_sram_ceil;
220 225
221 available = omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ); 226 available = omap_sram_ceil - (omap_sram_base + omap_sram_skip);
222 227
223 if (size > available) { 228 if (size > available) {
224 pr_err("Not enough space in SRAM\n"); 229 pr_err("Not enough space in SRAM\n");
diff --git a/arch/arm/plat-samsung/clock.c b/arch/arm/plat-samsung/clock.c
index 65c5eca475e7..d1116e2dfbea 100644
--- a/arch/arm/plat-samsung/clock.c
+++ b/arch/arm/plat-samsung/clock.c
@@ -144,6 +144,7 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
144 144
145int clk_set_rate(struct clk *clk, unsigned long rate) 145int clk_set_rate(struct clk *clk, unsigned long rate)
146{ 146{
147 unsigned long flags;
147 int ret; 148 int ret;
148 149
149 if (IS_ERR(clk)) 150 if (IS_ERR(clk))
@@ -159,9 +160,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
159 if (clk->ops == NULL || clk->ops->set_rate == NULL) 160 if (clk->ops == NULL || clk->ops->set_rate == NULL)
160 return -EINVAL; 161 return -EINVAL;
161 162
162 spin_lock(&clocks_lock); 163 spin_lock_irqsave(&clocks_lock, flags);
163 ret = (clk->ops->set_rate)(clk, rate); 164 ret = (clk->ops->set_rate)(clk, rate);
164 spin_unlock(&clocks_lock); 165 spin_unlock_irqrestore(&clocks_lock, flags);
165 166
166 return ret; 167 return ret;
167} 168}
@@ -173,17 +174,18 @@ struct clk *clk_get_parent(struct clk *clk)
173 174
174int clk_set_parent(struct clk *clk, struct clk *parent) 175int clk_set_parent(struct clk *clk, struct clk *parent)
175{ 176{
177 unsigned long flags;
176 int ret = 0; 178 int ret = 0;
177 179
178 if (IS_ERR(clk)) 180 if (IS_ERR(clk))
179 return -EINVAL; 181 return -EINVAL;
180 182
181 spin_lock(&clocks_lock); 183 spin_lock_irqsave(&clocks_lock, flags);
182 184
183 if (clk->ops && clk->ops->set_parent) 185 if (clk->ops && clk->ops->set_parent)
184 ret = (clk->ops->set_parent)(clk, parent); 186 ret = (clk->ops->set_parent)(clk, parent);
185 187
186 spin_unlock(&clocks_lock); 188 spin_unlock_irqrestore(&clocks_lock, flags);
187 189
188 return ret; 190 return ret;
189} 191}
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index f34861920634..c7092e6057c5 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -38,6 +38,7 @@ config BLACKFIN
38 select GENERIC_ATOMIC64 38 select GENERIC_ATOMIC64
39 select GENERIC_IRQ_PROBE 39 select GENERIC_IRQ_PROBE
40 select IRQ_PER_CPU if SMP 40 select IRQ_PER_CPU if SMP
41 select USE_GENERIC_SMP_HELPERS if SMP
41 select HAVE_NMI_WATCHDOG if NMI_WATCHDOG 42 select HAVE_NMI_WATCHDOG if NMI_WATCHDOG
42 select GENERIC_SMP_IDLE_THREAD 43 select GENERIC_SMP_IDLE_THREAD
43 select ARCH_USES_GETTIMEOFFSET if !GENERIC_CLOCKEVENTS 44 select ARCH_USES_GETTIMEOFFSET if !GENERIC_CLOCKEVENTS
diff --git a/arch/blackfin/Makefile b/arch/blackfin/Makefile
index d3d7e64ca96d..66cf00095b84 100644
--- a/arch/blackfin/Makefile
+++ b/arch/blackfin/Makefile
@@ -20,7 +20,6 @@ endif
20KBUILD_AFLAGS += $(call cc-option,-mno-fdpic) 20KBUILD_AFLAGS += $(call cc-option,-mno-fdpic)
21KBUILD_CFLAGS_MODULE += -mlong-calls 21KBUILD_CFLAGS_MODULE += -mlong-calls
22LDFLAGS += -m elf32bfin 22LDFLAGS += -m elf32bfin
23KALLSYMS += --symbol-prefix=_
24 23
25KBUILD_DEFCONFIG := BF537-STAMP_defconfig 24KBUILD_DEFCONFIG := BF537-STAMP_defconfig
26 25
diff --git a/arch/blackfin/include/asm/smp.h b/arch/blackfin/include/asm/smp.h
index dc3d144b4bb5..9631598dcc5d 100644
--- a/arch/blackfin/include/asm/smp.h
+++ b/arch/blackfin/include/asm/smp.h
@@ -18,6 +18,8 @@
18#define raw_smp_processor_id() blackfin_core_id() 18#define raw_smp_processor_id() blackfin_core_id()
19 19
20extern void bfin_relocate_coreb_l1_mem(void); 20extern void bfin_relocate_coreb_l1_mem(void);
21extern void arch_send_call_function_single_ipi(int cpu);
22extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
21 23
22#if defined(CONFIG_SMP) && defined(CONFIG_ICACHE_FLUSH_L1) 24#if defined(CONFIG_SMP) && defined(CONFIG_ICACHE_FLUSH_L1)
23asmlinkage void blackfin_icache_flush_range_l1(unsigned long *ptr); 25asmlinkage void blackfin_icache_flush_range_l1(unsigned long *ptr);
diff --git a/arch/blackfin/mach-common/smp.c b/arch/blackfin/mach-common/smp.c
index 00bbe672b3b3..a40151306b77 100644
--- a/arch/blackfin/mach-common/smp.c
+++ b/arch/blackfin/mach-common/smp.c
@@ -48,10 +48,13 @@ unsigned long blackfin_iflush_l1_entry[NR_CPUS];
48 48
49struct blackfin_initial_pda __cpuinitdata initial_pda_coreb; 49struct blackfin_initial_pda __cpuinitdata initial_pda_coreb;
50 50
51#define BFIN_IPI_TIMER 0 51enum ipi_message_type {
52#define BFIN_IPI_RESCHEDULE 1 52 BFIN_IPI_TIMER,
53#define BFIN_IPI_CALL_FUNC 2 53 BFIN_IPI_RESCHEDULE,
54#define BFIN_IPI_CPU_STOP 3 54 BFIN_IPI_CALL_FUNC,
55 BFIN_IPI_CALL_FUNC_SINGLE,
56 BFIN_IPI_CPU_STOP,
57};
55 58
56struct blackfin_flush_data { 59struct blackfin_flush_data {
57 unsigned long start; 60 unsigned long start;
@@ -60,35 +63,20 @@ struct blackfin_flush_data {
60 63
61void *secondary_stack; 64void *secondary_stack;
62 65
63
64struct smp_call_struct {
65 void (*func)(void *info);
66 void *info;
67 int wait;
68 cpumask_t *waitmask;
69};
70
71static struct blackfin_flush_data smp_flush_data; 66static struct blackfin_flush_data smp_flush_data;
72 67
73static DEFINE_SPINLOCK(stop_lock); 68static DEFINE_SPINLOCK(stop_lock);
74 69
75struct ipi_message {
76 unsigned long type;
77 struct smp_call_struct call_struct;
78};
79
80/* A magic number - stress test shows this is safe for common cases */ 70/* A magic number - stress test shows this is safe for common cases */
81#define BFIN_IPI_MSGQ_LEN 5 71#define BFIN_IPI_MSGQ_LEN 5
82 72
83/* Simple FIFO buffer, overflow leads to panic */ 73/* Simple FIFO buffer, overflow leads to panic */
84struct ipi_message_queue { 74struct ipi_data {
85 spinlock_t lock;
86 unsigned long count; 75 unsigned long count;
87 unsigned long head; /* head of the queue */ 76 unsigned long bits;
88 struct ipi_message ipi_message[BFIN_IPI_MSGQ_LEN];
89}; 77};
90 78
91static DEFINE_PER_CPU(struct ipi_message_queue, ipi_msg_queue); 79static DEFINE_PER_CPU(struct ipi_data, bfin_ipi);
92 80
93static void ipi_cpu_stop(unsigned int cpu) 81static void ipi_cpu_stop(unsigned int cpu)
94{ 82{
@@ -129,28 +117,6 @@ static void ipi_flush_icache(void *info)
129 blackfin_icache_flush_range(fdata->start, fdata->end); 117 blackfin_icache_flush_range(fdata->start, fdata->end);
130} 118}
131 119
132static void ipi_call_function(unsigned int cpu, struct ipi_message *msg)
133{
134 int wait;
135 void (*func)(void *info);
136 void *info;
137 func = msg->call_struct.func;
138 info = msg->call_struct.info;
139 wait = msg->call_struct.wait;
140 func(info);
141 if (wait) {
142#ifdef __ARCH_SYNC_CORE_DCACHE
143 /*
144 * 'wait' usually means synchronization between CPUs.
145 * Invalidate D cache in case shared data was changed
146 * by func() to ensure cache coherence.
147 */
148 resync_core_dcache();
149#endif
150 cpumask_clear_cpu(cpu, msg->call_struct.waitmask);
151 }
152}
153
154/* Use IRQ_SUPPLE_0 to request reschedule. 120/* Use IRQ_SUPPLE_0 to request reschedule.
155 * When returning from interrupt to user space, 121 * When returning from interrupt to user space,
156 * there is chance to reschedule */ 122 * there is chance to reschedule */
@@ -172,152 +138,95 @@ void ipi_timer(void)
172 138
173static irqreturn_t ipi_handler_int1(int irq, void *dev_instance) 139static irqreturn_t ipi_handler_int1(int irq, void *dev_instance)
174{ 140{
175 struct ipi_message *msg; 141 struct ipi_data *bfin_ipi_data;
176 struct ipi_message_queue *msg_queue;
177 unsigned int cpu = smp_processor_id(); 142 unsigned int cpu = smp_processor_id();
178 unsigned long flags; 143 unsigned long pending;
144 unsigned long msg;
179 145
180 platform_clear_ipi(cpu, IRQ_SUPPLE_1); 146 platform_clear_ipi(cpu, IRQ_SUPPLE_1);
181 147
182 msg_queue = &__get_cpu_var(ipi_msg_queue); 148 bfin_ipi_data = &__get_cpu_var(bfin_ipi);
183 149
184 spin_lock_irqsave(&msg_queue->lock, flags); 150 while ((pending = xchg(&bfin_ipi_data->bits, 0)) != 0) {
185 151 msg = 0;
186 while (msg_queue->count) { 152 do {
187 msg = &msg_queue->ipi_message[msg_queue->head]; 153 msg = find_next_bit(&pending, BITS_PER_LONG, msg + 1);
188 switch (msg->type) { 154 switch (msg) {
189 case BFIN_IPI_TIMER: 155 case BFIN_IPI_TIMER:
190 ipi_timer(); 156 ipi_timer();
191 break; 157 break;
192 case BFIN_IPI_RESCHEDULE: 158 case BFIN_IPI_RESCHEDULE:
193 scheduler_ipi(); 159 scheduler_ipi();
194 break; 160 break;
195 case BFIN_IPI_CALL_FUNC: 161 case BFIN_IPI_CALL_FUNC:
196 ipi_call_function(cpu, msg); 162 generic_smp_call_function_interrupt();
197 break; 163 break;
198 case BFIN_IPI_CPU_STOP: 164
199 ipi_cpu_stop(cpu); 165 case BFIN_IPI_CALL_FUNC_SINGLE:
200 break; 166 generic_smp_call_function_single_interrupt();
201 default: 167 break;
202 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%lx\n", 168
203 cpu, msg->type); 169 case BFIN_IPI_CPU_STOP:
204 break; 170 ipi_cpu_stop(cpu);
205 } 171 break;
206 msg_queue->head++; 172 }
207 msg_queue->head %= BFIN_IPI_MSGQ_LEN; 173 } while (msg < BITS_PER_LONG);
208 msg_queue->count--; 174
175 smp_mb();
209 } 176 }
210 spin_unlock_irqrestore(&msg_queue->lock, flags);
211 return IRQ_HANDLED; 177 return IRQ_HANDLED;
212} 178}
213 179
214static void ipi_queue_init(void) 180static void bfin_ipi_init(void)
215{ 181{
216 unsigned int cpu; 182 unsigned int cpu;
217 struct ipi_message_queue *msg_queue; 183 struct ipi_data *bfin_ipi_data;
218 for_each_possible_cpu(cpu) { 184 for_each_possible_cpu(cpu) {
219 msg_queue = &per_cpu(ipi_msg_queue, cpu); 185 bfin_ipi_data = &per_cpu(bfin_ipi, cpu);
220 spin_lock_init(&msg_queue->lock); 186 bfin_ipi_data->bits = 0;
221 msg_queue->count = 0; 187 bfin_ipi_data->count = 0;
222 msg_queue->head = 0;
223 } 188 }
224} 189}
225 190
226static inline void smp_send_message(cpumask_t callmap, unsigned long type, 191void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
227 void (*func) (void *info), void *info, int wait)
228{ 192{
229 unsigned int cpu; 193 unsigned int cpu;
230 struct ipi_message_queue *msg_queue; 194 struct ipi_data *bfin_ipi_data;
231 struct ipi_message *msg; 195 unsigned long flags;
232 unsigned long flags, next_msg; 196
233 cpumask_t waitmask; /* waitmask is shared by all cpus */ 197 local_irq_save(flags);
234 198
235 cpumask_copy(&waitmask, &callmap); 199 for_each_cpu(cpu, cpumask) {
236 for_each_cpu(cpu, &callmap) { 200 bfin_ipi_data = &per_cpu(bfin_ipi, cpu);
237 msg_queue = &per_cpu(ipi_msg_queue, cpu); 201 smp_mb();
238 spin_lock_irqsave(&msg_queue->lock, flags); 202 set_bit(msg, &bfin_ipi_data->bits);
239 if (msg_queue->count < BFIN_IPI_MSGQ_LEN) { 203 bfin_ipi_data->count++;
240 next_msg = (msg_queue->head + msg_queue->count)
241 % BFIN_IPI_MSGQ_LEN;
242 msg = &msg_queue->ipi_message[next_msg];
243 msg->type = type;
244 if (type == BFIN_IPI_CALL_FUNC) {
245 msg->call_struct.func = func;
246 msg->call_struct.info = info;
247 msg->call_struct.wait = wait;
248 msg->call_struct.waitmask = &waitmask;
249 }
250 msg_queue->count++;
251 } else
252 panic("IPI message queue overflow\n");
253 spin_unlock_irqrestore(&msg_queue->lock, flags);
254 platform_send_ipi_cpu(cpu, IRQ_SUPPLE_1); 204 platform_send_ipi_cpu(cpu, IRQ_SUPPLE_1);
255 } 205 }
256 206
257 if (wait) { 207 local_irq_restore(flags);
258 while (!cpumask_empty(&waitmask))
259 blackfin_dcache_invalidate_range(
260 (unsigned long)(&waitmask),
261 (unsigned long)(&waitmask));
262#ifdef __ARCH_SYNC_CORE_DCACHE
263 /*
264 * Invalidate D cache in case shared data was changed by
265 * other processors to ensure cache coherence.
266 */
267 resync_core_dcache();
268#endif
269 }
270} 208}
271 209
272int smp_call_function(void (*func)(void *info), void *info, int wait) 210void arch_send_call_function_single_ipi(int cpu)
273{ 211{
274 cpumask_t callmap; 212 send_ipi(cpumask_of(cpu), BFIN_IPI_CALL_FUNC_SINGLE);
275
276 preempt_disable();
277 cpumask_copy(&callmap, cpu_online_mask);
278 cpumask_clear_cpu(smp_processor_id(), &callmap);
279 if (!cpumask_empty(&callmap))
280 smp_send_message(callmap, BFIN_IPI_CALL_FUNC, func, info, wait);
281
282 preempt_enable();
283
284 return 0;
285} 213}
286EXPORT_SYMBOL_GPL(smp_call_function);
287 214
288int smp_call_function_single(int cpuid, void (*func) (void *info), void *info, 215void arch_send_call_function_ipi_mask(const struct cpumask *mask)
289 int wait)
290{ 216{
291 unsigned int cpu = cpuid; 217 send_ipi(mask, BFIN_IPI_CALL_FUNC);
292 cpumask_t callmap;
293
294 if (cpu_is_offline(cpu))
295 return 0;
296 cpumask_clear(&callmap);
297 cpumask_set_cpu(cpu, &callmap);
298
299 smp_send_message(callmap, BFIN_IPI_CALL_FUNC, func, info, wait);
300
301 return 0;
302} 218}
303EXPORT_SYMBOL_GPL(smp_call_function_single);
304 219
305void smp_send_reschedule(int cpu) 220void smp_send_reschedule(int cpu)
306{ 221{
307 cpumask_t callmap; 222 send_ipi(cpumask_of(cpu), BFIN_IPI_RESCHEDULE);
308 /* simply trigger an ipi */
309
310 cpumask_clear(&callmap);
311 cpumask_set_cpu(cpu, &callmap);
312
313 smp_send_message(callmap, BFIN_IPI_RESCHEDULE, NULL, NULL, 0);
314 223
315 return; 224 return;
316} 225}
317 226
318void smp_send_msg(const struct cpumask *mask, unsigned long type) 227void smp_send_msg(const struct cpumask *mask, unsigned long type)
319{ 228{
320 smp_send_message(*mask, type, NULL, NULL, 0); 229 send_ipi(mask, type);
321} 230}
322 231
323void smp_timer_broadcast(const struct cpumask *mask) 232void smp_timer_broadcast(const struct cpumask *mask)
@@ -333,7 +242,7 @@ void smp_send_stop(void)
333 cpumask_copy(&callmap, cpu_online_mask); 242 cpumask_copy(&callmap, cpu_online_mask);
334 cpumask_clear_cpu(smp_processor_id(), &callmap); 243 cpumask_clear_cpu(smp_processor_id(), &callmap);
335 if (!cpumask_empty(&callmap)) 244 if (!cpumask_empty(&callmap))
336 smp_send_message(callmap, BFIN_IPI_CPU_STOP, NULL, NULL, 0); 245 send_ipi(&callmap, BFIN_IPI_CPU_STOP);
337 246
338 preempt_enable(); 247 preempt_enable();
339 248
@@ -436,7 +345,7 @@ void __init smp_prepare_boot_cpu(void)
436void __init smp_prepare_cpus(unsigned int max_cpus) 345void __init smp_prepare_cpus(unsigned int max_cpus)
437{ 346{
438 platform_prepare_cpus(max_cpus); 347 platform_prepare_cpus(max_cpus);
439 ipi_queue_init(); 348 bfin_ipi_init();
440 platform_request_ipi(IRQ_SUPPLE_0, ipi_handler_int0); 349 platform_request_ipi(IRQ_SUPPLE_0, ipi_handler_int0);
441 platform_request_ipi(IRQ_SUPPLE_1, ipi_handler_int1); 350 platform_request_ipi(IRQ_SUPPLE_1, ipi_handler_int1);
442} 351}
diff --git a/arch/c6x/include/asm/Kbuild b/arch/c6x/include/asm/Kbuild
index 3af601e31e66..f08e89183cda 100644
--- a/arch/c6x/include/asm/Kbuild
+++ b/arch/c6x/include/asm/Kbuild
@@ -2,6 +2,7 @@ include include/asm-generic/Kbuild.asm
2 2
3generic-y += atomic.h 3generic-y += atomic.h
4generic-y += auxvec.h 4generic-y += auxvec.h
5generic-y += barrier.h
5generic-y += bitsperlong.h 6generic-y += bitsperlong.h
6generic-y += bugs.h 7generic-y += bugs.h
7generic-y += cputime.h 8generic-y += cputime.h
diff --git a/arch/c6x/include/asm/barrier.h b/arch/c6x/include/asm/barrier.h
deleted file mode 100644
index 538240e85909..000000000000
--- a/arch/c6x/include/asm/barrier.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/*
2 * Port on Texas Instruments TMS320C6x architecture
3 *
4 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
6 *
7 * 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 * published by the Free Software Foundation.
10 */
11#ifndef _ASM_C6X_BARRIER_H
12#define _ASM_C6X_BARRIER_H
13
14#define nop() asm("NOP\n");
15
16#define mb() barrier()
17#define rmb() barrier()
18#define wmb() barrier()
19#define set_mb(var, value) do { var = value; mb(); } while (0)
20#define set_wmb(var, value) do { var = value; wmb(); } while (0)
21
22#define smp_mb() barrier()
23#define smp_rmb() barrier()
24#define smp_wmb() barrier()
25#define smp_read_barrier_depends() do { } while (0)
26
27#endif /* _ASM_C6X_BARRIER_H */
diff --git a/arch/cris/kernel/process.c b/arch/cris/kernel/process.c
index 66fd01728790..7f65be6f7f17 100644
--- a/arch/cris/kernel/process.c
+++ b/arch/cris/kernel/process.c
@@ -25,6 +25,7 @@
25#include <linux/elfcore.h> 25#include <linux/elfcore.h>
26#include <linux/mqueue.h> 26#include <linux/mqueue.h>
27#include <linux/reboot.h> 27#include <linux/reboot.h>
28#include <linux/rcupdate.h>
28 29
29//#define DEBUG 30//#define DEBUG
30 31
@@ -74,6 +75,7 @@ void cpu_idle (void)
74{ 75{
75 /* endless idle loop with no priority at all */ 76 /* endless idle loop with no priority at all */
76 while (1) { 77 while (1) {
78 rcu_idle_enter();
77 while (!need_resched()) { 79 while (!need_resched()) {
78 void (*idle)(void); 80 void (*idle)(void);
79 /* 81 /*
@@ -86,6 +88,7 @@ void cpu_idle (void)
86 idle = default_idle; 88 idle = default_idle;
87 idle(); 89 idle();
88 } 90 }
91 rcu_idle_exit();
89 schedule_preempt_disabled(); 92 schedule_preempt_disabled();
90 } 93 }
91} 94}
diff --git a/arch/frv/kernel/process.c b/arch/frv/kernel/process.c
index ff95f50efea5..2eb7fa5bf9d8 100644
--- a/arch/frv/kernel/process.c
+++ b/arch/frv/kernel/process.c
@@ -25,6 +25,7 @@
25#include <linux/reboot.h> 25#include <linux/reboot.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/pagemap.h> 27#include <linux/pagemap.h>
28#include <linux/rcupdate.h>
28 29
29#include <asm/asm-offsets.h> 30#include <asm/asm-offsets.h>
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
@@ -69,12 +70,14 @@ void cpu_idle(void)
69{ 70{
70 /* endless idle loop with no priority at all */ 71 /* endless idle loop with no priority at all */
71 while (1) { 72 while (1) {
73 rcu_idle_enter();
72 while (!need_resched()) { 74 while (!need_resched()) {
73 check_pgt_cache(); 75 check_pgt_cache();
74 76
75 if (!frv_dma_inprogress && idle) 77 if (!frv_dma_inprogress && idle)
76 idle(); 78 idle();
77 } 79 }
80 rcu_idle_exit();
78 81
79 schedule_preempt_disabled(); 82 schedule_preempt_disabled();
80 } 83 }
diff --git a/arch/h8300/kernel/process.c b/arch/h8300/kernel/process.c
index 0e9c315be104..f153ed1a4c08 100644
--- a/arch/h8300/kernel/process.c
+++ b/arch/h8300/kernel/process.c
@@ -36,6 +36,7 @@
36#include <linux/reboot.h> 36#include <linux/reboot.h>
37#include <linux/fs.h> 37#include <linux/fs.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/rcupdate.h>
39 40
40#include <asm/uaccess.h> 41#include <asm/uaccess.h>
41#include <asm/traps.h> 42#include <asm/traps.h>
@@ -78,8 +79,10 @@ void (*idle)(void) = default_idle;
78void cpu_idle(void) 79void cpu_idle(void)
79{ 80{
80 while (1) { 81 while (1) {
82 rcu_idle_enter();
81 while (!need_resched()) 83 while (!need_resched())
82 idle(); 84 idle();
85 rcu_idle_exit();
83 schedule_preempt_disabled(); 86 schedule_preempt_disabled();
84 } 87 }
85} 88}
diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index dd6fc1449741..3e316ec0b835 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -29,6 +29,7 @@
29#include <linux/kdebug.h> 29#include <linux/kdebug.h>
30#include <linux/utsname.h> 30#include <linux/utsname.h>
31#include <linux/tracehook.h> 31#include <linux/tracehook.h>
32#include <linux/rcupdate.h>
32 33
33#include <asm/cpu.h> 34#include <asm/cpu.h>
34#include <asm/delay.h> 35#include <asm/delay.h>
@@ -279,6 +280,7 @@ cpu_idle (void)
279 280
280 /* endless idle loop with no priority at all */ 281 /* endless idle loop with no priority at all */
281 while (1) { 282 while (1) {
283 rcu_idle_enter();
282 if (can_do_pal_halt) { 284 if (can_do_pal_halt) {
283 current_thread_info()->status &= ~TS_POLLING; 285 current_thread_info()->status &= ~TS_POLLING;
284 /* 286 /*
@@ -309,6 +311,7 @@ cpu_idle (void)
309 normal_xtp(); 311 normal_xtp();
310#endif 312#endif
311 } 313 }
314 rcu_idle_exit();
312 schedule_preempt_disabled(); 315 schedule_preempt_disabled();
313 check_pgt_cache(); 316 check_pgt_cache();
314 if (cpu_is_offline(cpu)) 317 if (cpu_is_offline(cpu))
diff --git a/arch/m32r/kernel/process.c b/arch/m32r/kernel/process.c
index 3a4a32b27208..384e63f3a4c4 100644
--- a/arch/m32r/kernel/process.c
+++ b/arch/m32r/kernel/process.c
@@ -26,6 +26,7 @@
26#include <linux/ptrace.h> 26#include <linux/ptrace.h>
27#include <linux/unistd.h> 27#include <linux/unistd.h>
28#include <linux/hardirq.h> 28#include <linux/hardirq.h>
29#include <linux/rcupdate.h>
29 30
30#include <asm/io.h> 31#include <asm/io.h>
31#include <asm/uaccess.h> 32#include <asm/uaccess.h>
@@ -82,6 +83,7 @@ void cpu_idle (void)
82{ 83{
83 /* endless idle loop with no priority at all */ 84 /* endless idle loop with no priority at all */
84 while (1) { 85 while (1) {
86 rcu_idle_enter();
85 while (!need_resched()) { 87 while (!need_resched()) {
86 void (*idle)(void) = pm_idle; 88 void (*idle)(void) = pm_idle;
87 89
@@ -90,6 +92,7 @@ void cpu_idle (void)
90 92
91 idle(); 93 idle();
92 } 94 }
95 rcu_idle_exit();
93 schedule_preempt_disabled(); 96 schedule_preempt_disabled();
94 } 97 }
95} 98}
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index c488e3cfab53..ac2892e49c7c 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -25,6 +25,7 @@
25#include <linux/reboot.h> 25#include <linux/reboot.h>
26#include <linux/init_task.h> 26#include <linux/init_task.h>
27#include <linux/mqueue.h> 27#include <linux/mqueue.h>
28#include <linux/rcupdate.h>
28 29
29#include <asm/uaccess.h> 30#include <asm/uaccess.h>
30#include <asm/traps.h> 31#include <asm/traps.h>
@@ -75,8 +76,10 @@ void cpu_idle(void)
75{ 76{
76 /* endless idle loop with no priority at all */ 77 /* endless idle loop with no priority at all */
77 while (1) { 78 while (1) {
79 rcu_idle_enter();
78 while (!need_resched()) 80 while (!need_resched())
79 idle(); 81 idle();
82 rcu_idle_exit();
80 schedule_preempt_disabled(); 83 schedule_preempt_disabled();
81 } 84 }
82} 85}
diff --git a/arch/m68k/platform/coldfire/clk.c b/arch/m68k/platform/coldfire/clk.c
index 75f9ee967ea7..9cd13b4ce42b 100644
--- a/arch/m68k/platform/coldfire/clk.c
+++ b/arch/m68k/platform/coldfire/clk.c
@@ -146,9 +146,3 @@ struct clk_ops clk_ops1 = {
146}; 146};
147#endif /* MCFPM_PPMCR1 */ 147#endif /* MCFPM_PPMCR1 */
148#endif /* MCFPM_PPMCR0 */ 148#endif /* MCFPM_PPMCR0 */
149
150struct clk *devm_clk_get(struct device *dev, const char *id)
151{
152 return NULL;
153}
154EXPORT_SYMBOL(devm_clk_get);
diff --git a/arch/mips/kernel/smp-cmp.c b/arch/mips/kernel/smp-cmp.c
index e7e03ecf5495..afc379ca3753 100644
--- a/arch/mips/kernel/smp-cmp.c
+++ b/arch/mips/kernel/smp-cmp.c
@@ -102,7 +102,7 @@ static void cmp_init_secondary(void)
102 c->vpe_id = (read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) & TCBIND_CURVPE; 102 c->vpe_id = (read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) & TCBIND_CURVPE;
103#endif 103#endif
104#ifdef CONFIG_MIPS_MT_SMTC 104#ifdef CONFIG_MIPS_MT_SMTC
105 c->tc_id = (read_c0_tcbind() >> TCBIND_CURTC_SHIFT) & TCBIND_CURTC; 105 c->tc_id = (read_c0_tcbind() & TCBIND_CURTC) >> TCBIND_CURTC_SHIFT;
106#endif 106#endif
107} 107}
108 108
diff --git a/arch/mips/mm/gup.c b/arch/mips/mm/gup.c
index 33aadbcf170b..dcfd573871c1 100644
--- a/arch/mips/mm/gup.c
+++ b/arch/mips/mm/gup.c
@@ -152,6 +152,8 @@ static int gup_huge_pud(pud_t pud, unsigned long addr, unsigned long end,
152 do { 152 do {
153 VM_BUG_ON(compound_head(page) != head); 153 VM_BUG_ON(compound_head(page) != head);
154 pages[*nr] = page; 154 pages[*nr] = page;
155 if (PageTail(page))
156 get_huge_page_tail(page);
155 (*nr)++; 157 (*nr)++;
156 page++; 158 page++;
157 refs++; 159 refs++;
diff --git a/arch/mips/mti-malta/malta-int.c b/arch/mips/mti-malta/malta-int.c
index 7b13a4caeea4..fea823f18479 100644
--- a/arch/mips/mti-malta/malta-int.c
+++ b/arch/mips/mti-malta/malta-int.c
@@ -273,16 +273,19 @@ asmlinkage void plat_irq_dispatch(void)
273 unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM; 273 unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
274 int irq; 274 int irq;
275 275
276 if (unlikely(!pending)) {
277 spurious_interrupt();
278 return;
279 }
280
276 irq = irq_ffs(pending); 281 irq = irq_ffs(pending);
277 282
278 if (irq == MIPSCPU_INT_I8259A) 283 if (irq == MIPSCPU_INT_I8259A)
279 malta_hw0_irqdispatch(); 284 malta_hw0_irqdispatch();
280 else if (gic_present && ((1 << irq) & ipi_map[smp_processor_id()])) 285 else if (gic_present && ((1 << irq) & ipi_map[smp_processor_id()]))
281 malta_ipi_irqdispatch(); 286 malta_ipi_irqdispatch();
282 else if (irq >= 0)
283 do_IRQ(MIPS_CPU_IRQ_BASE + irq);
284 else 287 else
285 spurious_interrupt(); 288 do_IRQ(MIPS_CPU_IRQ_BASE + irq);
286} 289}
287 290
288#ifdef CONFIG_MIPS_MT_SMP 291#ifdef CONFIG_MIPS_MT_SMP
diff --git a/arch/mips/mti-malta/malta-platform.c b/arch/mips/mti-malta/malta-platform.c
index 4c35301720e7..80562b81f0f2 100644
--- a/arch/mips/mti-malta/malta-platform.c
+++ b/arch/mips/mti-malta/malta-platform.c
@@ -138,11 +138,6 @@ static int __init malta_add_devices(void)
138 if (err) 138 if (err)
139 return err; 139 return err;
140 140
141 /*
142 * Set RTC to BCD mode to support current alarm code.
143 */
144 CMOS_WRITE(CMOS_READ(RTC_CONTROL) & ~RTC_DM_BINARY, RTC_CONTROL);
145
146 return 0; 141 return 0;
147} 142}
148 143
diff --git a/arch/mn10300/kernel/process.c b/arch/mn10300/kernel/process.c
index 7dab0cd36466..e9cceba193b6 100644
--- a/arch/mn10300/kernel/process.c
+++ b/arch/mn10300/kernel/process.c
@@ -25,6 +25,7 @@
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/fs.h> 26#include <linux/fs.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/rcupdate.h>
28#include <asm/uaccess.h> 29#include <asm/uaccess.h>
29#include <asm/pgtable.h> 30#include <asm/pgtable.h>
30#include <asm/io.h> 31#include <asm/io.h>
@@ -107,6 +108,7 @@ void cpu_idle(void)
107{ 108{
108 /* endless idle loop with no priority at all */ 109 /* endless idle loop with no priority at all */
109 for (;;) { 110 for (;;) {
111 rcu_idle_enter();
110 while (!need_resched()) { 112 while (!need_resched()) {
111 void (*idle)(void); 113 void (*idle)(void);
112 114
@@ -121,6 +123,7 @@ void cpu_idle(void)
121 } 123 }
122 idle(); 124 idle();
123 } 125 }
126 rcu_idle_exit();
124 127
125 schedule_preempt_disabled(); 128 schedule_preempt_disabled();
126 } 129 }
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index 2c05a9292a81..8c6b6b6561f0 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -48,6 +48,7 @@
48#include <linux/unistd.h> 48#include <linux/unistd.h>
49#include <linux/kallsyms.h> 49#include <linux/kallsyms.h>
50#include <linux/uaccess.h> 50#include <linux/uaccess.h>
51#include <linux/rcupdate.h>
51 52
52#include <asm/io.h> 53#include <asm/io.h>
53#include <asm/asm-offsets.h> 54#include <asm/asm-offsets.h>
@@ -69,8 +70,10 @@ void cpu_idle(void)
69 70
70 /* endless idle loop with no priority at all */ 71 /* endless idle loop with no priority at all */
71 while (1) { 72 while (1) {
73 rcu_idle_enter();
72 while (!need_resched()) 74 while (!need_resched())
73 barrier(); 75 barrier();
76 rcu_idle_exit();
74 schedule_preempt_disabled(); 77 schedule_preempt_disabled();
75 check_pgt_cache(); 78 check_pgt_cache();
76 } 79 }
diff --git a/arch/powerpc/boot/.gitignore b/arch/powerpc/boot/.gitignore
index 1c1aadc8c48f..c32ae5ce9fff 100644
--- a/arch/powerpc/boot/.gitignore
+++ b/arch/powerpc/boot/.gitignore
@@ -1,10 +1,6 @@
1addnote 1addnote
2empty.c 2empty.c
3hack-coff 3hack-coff
4infblock.c
5infblock.h
6infcodes.c
7infcodes.h
8inffast.c 4inffast.c
9inffast.h 5inffast.h
10inffixed.h 6inffixed.h
diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h
index 799ed0f1643d..2d6e6e380564 100644
--- a/arch/s390/include/asm/hugetlb.h
+++ b/arch/s390/include/asm/hugetlb.h
@@ -66,16 +66,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)
66 return pte; 66 return pte;
67} 67}
68 68
69static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
70 unsigned long addr, pte_t *ptep)
71{
72 pte_t pte = huge_ptep_get(ptep);
73
74 mm->context.flush_mm = 1;
75 pmd_clear((pmd_t *) ptep);
76 return pte;
77}
78
79static inline void __pmd_csp(pmd_t *pmdp) 69static inline void __pmd_csp(pmd_t *pmdp)
80{ 70{
81 register unsigned long reg2 asm("2") = pmd_val(*pmdp); 71 register unsigned long reg2 asm("2") = pmd_val(*pmdp);
@@ -117,6 +107,15 @@ static inline void huge_ptep_invalidate(struct mm_struct *mm,
117 __pmd_csp(pmdp); 107 __pmd_csp(pmdp);
118} 108}
119 109
110static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
111 unsigned long addr, pte_t *ptep)
112{
113 pte_t pte = huge_ptep_get(ptep);
114
115 huge_ptep_invalidate(mm, addr, ptep);
116 return pte;
117}
118
120#define huge_ptep_set_access_flags(__vma, __addr, __ptep, __entry, __dirty) \ 119#define huge_ptep_set_access_flags(__vma, __addr, __ptep, __entry, __dirty) \
121({ \ 120({ \
122 int __changed = !pte_same(huge_ptep_get(__ptep), __entry); \ 121 int __changed = !pte_same(huge_ptep_get(__ptep), __entry); \
@@ -131,10 +130,7 @@ static inline void huge_ptep_invalidate(struct mm_struct *mm,
131({ \ 130({ \
132 pte_t __pte = huge_ptep_get(__ptep); \ 131 pte_t __pte = huge_ptep_get(__ptep); \
133 if (pte_write(__pte)) { \ 132 if (pte_write(__pte)) { \
134 (__mm)->context.flush_mm = 1; \ 133 huge_ptep_invalidate(__mm, __addr, __ptep); \
135 if (atomic_read(&(__mm)->context.attach_count) > 1 || \
136 (__mm) != current->active_mm) \
137 huge_ptep_invalidate(__mm, __addr, __ptep); \
138 set_huge_pte_at(__mm, __addr, __ptep, \ 134 set_huge_pte_at(__mm, __addr, __ptep, \
139 huge_pte_wrprotect(__pte)); \ 135 huge_pte_wrprotect(__pte)); \
140 } \ 136 } \
diff --git a/arch/s390/include/asm/tlbflush.h b/arch/s390/include/asm/tlbflush.h
index 9fde315f3a7c..1d8fe2b17ef6 100644
--- a/arch/s390/include/asm/tlbflush.h
+++ b/arch/s390/include/asm/tlbflush.h
@@ -90,12 +90,10 @@ static inline void __tlb_flush_mm(struct mm_struct * mm)
90 90
91static inline void __tlb_flush_mm_cond(struct mm_struct * mm) 91static inline void __tlb_flush_mm_cond(struct mm_struct * mm)
92{ 92{
93 spin_lock(&mm->page_table_lock);
94 if (mm->context.flush_mm) { 93 if (mm->context.flush_mm) {
95 __tlb_flush_mm(mm); 94 __tlb_flush_mm(mm);
96 mm->context.flush_mm = 0; 95 mm->context.flush_mm = 0;
97 } 96 }
98 spin_unlock(&mm->page_table_lock);
99} 97}
100 98
101/* 99/*
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index f86c81e13c37..40b57693de38 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -974,11 +974,13 @@ static void __init setup_hwcaps(void)
974 if (MACHINE_HAS_HPAGE) 974 if (MACHINE_HAS_HPAGE)
975 elf_hwcap |= HWCAP_S390_HPAGE; 975 elf_hwcap |= HWCAP_S390_HPAGE;
976 976
977#if defined(CONFIG_64BIT)
977 /* 978 /*
978 * 64-bit register support for 31-bit processes 979 * 64-bit register support for 31-bit processes
979 * HWCAP_S390_HIGH_GPRS is bit 9. 980 * HWCAP_S390_HIGH_GPRS is bit 9.
980 */ 981 */
981 elf_hwcap |= HWCAP_S390_HIGH_GPRS; 982 elf_hwcap |= HWCAP_S390_HIGH_GPRS;
983#endif
982 984
983 get_cpu_id(&cpu_id); 985 get_cpu_id(&cpu_id);
984 switch (cpu_id.machine) { 986 switch (cpu_id.machine) {
diff --git a/arch/s390/lib/uaccess_pt.c b/arch/s390/lib/uaccess_pt.c
index 60ee2b883797..2d37bb861faf 100644
--- a/arch/s390/lib/uaccess_pt.c
+++ b/arch/s390/lib/uaccess_pt.c
@@ -2,69 +2,82 @@
2 * User access functions based on page table walks for enhanced 2 * User access functions based on page table walks for enhanced
3 * system layout without hardware support. 3 * system layout without hardware support.
4 * 4 *
5 * Copyright IBM Corp. 2006 5 * Copyright IBM Corp. 2006, 2012
6 * Author(s): Gerald Schaefer (gerald.schaefer@de.ibm.com) 6 * Author(s): Gerald Schaefer (gerald.schaefer@de.ibm.com)
7 */ 7 */
8 8
9#include <linux/errno.h> 9#include <linux/errno.h>
10#include <linux/hardirq.h> 10#include <linux/hardirq.h>
11#include <linux/mm.h> 11#include <linux/mm.h>
12#include <linux/hugetlb.h>
12#include <asm/uaccess.h> 13#include <asm/uaccess.h>
13#include <asm/futex.h> 14#include <asm/futex.h>
14#include "uaccess.h" 15#include "uaccess.h"
15 16
16static inline pte_t *follow_table(struct mm_struct *mm, unsigned long addr) 17
18/*
19 * Returns kernel address for user virtual address. If the returned address is
20 * >= -4095 (IS_ERR_VALUE(x) returns true), a fault has occured and the address
21 * contains the (negative) exception code.
22 */
23static __always_inline unsigned long follow_table(struct mm_struct *mm,
24 unsigned long addr, int write)
17{ 25{
18 pgd_t *pgd; 26 pgd_t *pgd;
19 pud_t *pud; 27 pud_t *pud;
20 pmd_t *pmd; 28 pmd_t *pmd;
29 pte_t *ptep;
21 30
22 pgd = pgd_offset(mm, addr); 31 pgd = pgd_offset(mm, addr);
23 if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd))) 32 if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
24 return (pte_t *) 0x3a; 33 return -0x3aUL;
25 34
26 pud = pud_offset(pgd, addr); 35 pud = pud_offset(pgd, addr);
27 if (pud_none(*pud) || unlikely(pud_bad(*pud))) 36 if (pud_none(*pud) || unlikely(pud_bad(*pud)))
28 return (pte_t *) 0x3b; 37 return -0x3bUL;
29 38
30 pmd = pmd_offset(pud, addr); 39 pmd = pmd_offset(pud, addr);
31 if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd))) 40 if (pmd_none(*pmd))
32 return (pte_t *) 0x10; 41 return -0x10UL;
42 if (pmd_huge(*pmd)) {
43 if (write && (pmd_val(*pmd) & _SEGMENT_ENTRY_RO))
44 return -0x04UL;
45 return (pmd_val(*pmd) & HPAGE_MASK) + (addr & ~HPAGE_MASK);
46 }
47 if (unlikely(pmd_bad(*pmd)))
48 return -0x10UL;
49
50 ptep = pte_offset_map(pmd, addr);
51 if (!pte_present(*ptep))
52 return -0x11UL;
53 if (write && !pte_write(*ptep))
54 return -0x04UL;
33 55
34 return pte_offset_map(pmd, addr); 56 return (pte_val(*ptep) & PAGE_MASK) + (addr & ~PAGE_MASK);
35} 57}
36 58
37static __always_inline size_t __user_copy_pt(unsigned long uaddr, void *kptr, 59static __always_inline size_t __user_copy_pt(unsigned long uaddr, void *kptr,
38 size_t n, int write_user) 60 size_t n, int write_user)
39{ 61{
40 struct mm_struct *mm = current->mm; 62 struct mm_struct *mm = current->mm;
41 unsigned long offset, pfn, done, size; 63 unsigned long offset, done, size, kaddr;
42 pte_t *pte;
43 void *from, *to; 64 void *from, *to;
44 65
45 done = 0; 66 done = 0;
46retry: 67retry:
47 spin_lock(&mm->page_table_lock); 68 spin_lock(&mm->page_table_lock);
48 do { 69 do {
49 pte = follow_table(mm, uaddr); 70 kaddr = follow_table(mm, uaddr, write_user);
50 if ((unsigned long) pte < 0x1000) 71 if (IS_ERR_VALUE(kaddr))
51 goto fault; 72 goto fault;
52 if (!pte_present(*pte)) {
53 pte = (pte_t *) 0x11;
54 goto fault;
55 } else if (write_user && !pte_write(*pte)) {
56 pte = (pte_t *) 0x04;
57 goto fault;
58 }
59 73
60 pfn = pte_pfn(*pte); 74 offset = uaddr & ~PAGE_MASK;
61 offset = uaddr & (PAGE_SIZE - 1);
62 size = min(n - done, PAGE_SIZE - offset); 75 size = min(n - done, PAGE_SIZE - offset);
63 if (write_user) { 76 if (write_user) {
64 to = (void *)((pfn << PAGE_SHIFT) + offset); 77 to = (void *) kaddr;
65 from = kptr + done; 78 from = kptr + done;
66 } else { 79 } else {
67 from = (void *)((pfn << PAGE_SHIFT) + offset); 80 from = (void *) kaddr;
68 to = kptr + done; 81 to = kptr + done;
69 } 82 }
70 memcpy(to, from, size); 83 memcpy(to, from, size);
@@ -75,7 +88,7 @@ retry:
75 return n - done; 88 return n - done;
76fault: 89fault:
77 spin_unlock(&mm->page_table_lock); 90 spin_unlock(&mm->page_table_lock);
78 if (__handle_fault(uaddr, (unsigned long) pte, write_user)) 91 if (__handle_fault(uaddr, -kaddr, write_user))
79 return n - done; 92 return n - done;
80 goto retry; 93 goto retry;
81} 94}
@@ -84,27 +97,22 @@ fault:
84 * Do DAT for user address by page table walk, return kernel address. 97 * Do DAT for user address by page table walk, return kernel address.
85 * This function needs to be called with current->mm->page_table_lock held. 98 * This function needs to be called with current->mm->page_table_lock held.
86 */ 99 */
87static __always_inline unsigned long __dat_user_addr(unsigned long uaddr) 100static __always_inline unsigned long __dat_user_addr(unsigned long uaddr,
101 int write)
88{ 102{
89 struct mm_struct *mm = current->mm; 103 struct mm_struct *mm = current->mm;
90 unsigned long pfn; 104 unsigned long kaddr;
91 pte_t *pte;
92 int rc; 105 int rc;
93 106
94retry: 107retry:
95 pte = follow_table(mm, uaddr); 108 kaddr = follow_table(mm, uaddr, write);
96 if ((unsigned long) pte < 0x1000) 109 if (IS_ERR_VALUE(kaddr))
97 goto fault;
98 if (!pte_present(*pte)) {
99 pte = (pte_t *) 0x11;
100 goto fault; 110 goto fault;
101 }
102 111
103 pfn = pte_pfn(*pte); 112 return kaddr;
104 return (pfn << PAGE_SHIFT) + (uaddr & (PAGE_SIZE - 1));
105fault: 113fault:
106 spin_unlock(&mm->page_table_lock); 114 spin_unlock(&mm->page_table_lock);
107 rc = __handle_fault(uaddr, (unsigned long) pte, 0); 115 rc = __handle_fault(uaddr, -kaddr, write);
108 spin_lock(&mm->page_table_lock); 116 spin_lock(&mm->page_table_lock);
109 if (!rc) 117 if (!rc)
110 goto retry; 118 goto retry;
@@ -159,11 +167,9 @@ static size_t clear_user_pt(size_t n, void __user *to)
159 167
160static size_t strnlen_user_pt(size_t count, const char __user *src) 168static size_t strnlen_user_pt(size_t count, const char __user *src)
161{ 169{
162 char *addr;
163 unsigned long uaddr = (unsigned long) src; 170 unsigned long uaddr = (unsigned long) src;
164 struct mm_struct *mm = current->mm; 171 struct mm_struct *mm = current->mm;
165 unsigned long offset, pfn, done, len; 172 unsigned long offset, done, len, kaddr;
166 pte_t *pte;
167 size_t len_str; 173 size_t len_str;
168 174
169 if (segment_eq(get_fs(), KERNEL_DS)) 175 if (segment_eq(get_fs(), KERNEL_DS))
@@ -172,19 +178,13 @@ static size_t strnlen_user_pt(size_t count, const char __user *src)
172retry: 178retry:
173 spin_lock(&mm->page_table_lock); 179 spin_lock(&mm->page_table_lock);
174 do { 180 do {
175 pte = follow_table(mm, uaddr); 181 kaddr = follow_table(mm, uaddr, 0);
176 if ((unsigned long) pte < 0x1000) 182 if (IS_ERR_VALUE(kaddr))
177 goto fault;
178 if (!pte_present(*pte)) {
179 pte = (pte_t *) 0x11;
180 goto fault; 183 goto fault;
181 }
182 184
183 pfn = pte_pfn(*pte); 185 offset = uaddr & ~PAGE_MASK;
184 offset = uaddr & (PAGE_SIZE-1);
185 addr = (char *)(pfn << PAGE_SHIFT) + offset;
186 len = min(count - done, PAGE_SIZE - offset); 186 len = min(count - done, PAGE_SIZE - offset);
187 len_str = strnlen(addr, len); 187 len_str = strnlen((char *) kaddr, len);
188 done += len_str; 188 done += len_str;
189 uaddr += len_str; 189 uaddr += len_str;
190 } while ((len_str == len) && (done < count)); 190 } while ((len_str == len) && (done < count));
@@ -192,7 +192,7 @@ retry:
192 return done + 1; 192 return done + 1;
193fault: 193fault:
194 spin_unlock(&mm->page_table_lock); 194 spin_unlock(&mm->page_table_lock);
195 if (__handle_fault(uaddr, (unsigned long) pte, 0)) 195 if (__handle_fault(uaddr, -kaddr, 0))
196 return 0; 196 return 0;
197 goto retry; 197 goto retry;
198} 198}
@@ -225,11 +225,10 @@ static size_t copy_in_user_pt(size_t n, void __user *to,
225 const void __user *from) 225 const void __user *from)
226{ 226{
227 struct mm_struct *mm = current->mm; 227 struct mm_struct *mm = current->mm;
228 unsigned long offset_from, offset_to, offset_max, pfn_from, pfn_to, 228 unsigned long offset_max, uaddr, done, size, error_code;
229 uaddr, done, size, error_code;
230 unsigned long uaddr_from = (unsigned long) from; 229 unsigned long uaddr_from = (unsigned long) from;
231 unsigned long uaddr_to = (unsigned long) to; 230 unsigned long uaddr_to = (unsigned long) to;
232 pte_t *pte_from, *pte_to; 231 unsigned long kaddr_to, kaddr_from;
233 int write_user; 232 int write_user;
234 233
235 if (segment_eq(get_fs(), KERNEL_DS)) { 234 if (segment_eq(get_fs(), KERNEL_DS)) {
@@ -242,38 +241,23 @@ retry:
242 do { 241 do {
243 write_user = 0; 242 write_user = 0;
244 uaddr = uaddr_from; 243 uaddr = uaddr_from;
245 pte_from = follow_table(mm, uaddr_from); 244 kaddr_from = follow_table(mm, uaddr_from, 0);
246 error_code = (unsigned long) pte_from; 245 error_code = kaddr_from;
247 if (error_code < 0x1000) 246 if (IS_ERR_VALUE(error_code))
248 goto fault;
249 if (!pte_present(*pte_from)) {
250 error_code = 0x11;
251 goto fault; 247 goto fault;
252 }
253 248
254 write_user = 1; 249 write_user = 1;
255 uaddr = uaddr_to; 250 uaddr = uaddr_to;
256 pte_to = follow_table(mm, uaddr_to); 251 kaddr_to = follow_table(mm, uaddr_to, 1);
257 error_code = (unsigned long) pte_to; 252 error_code = (unsigned long) kaddr_to;
258 if (error_code < 0x1000) 253 if (IS_ERR_VALUE(error_code))
259 goto fault;
260 if (!pte_present(*pte_to)) {
261 error_code = 0x11;
262 goto fault; 254 goto fault;
263 } else if (!pte_write(*pte_to)) {
264 error_code = 0x04;
265 goto fault;
266 }
267 255
268 pfn_from = pte_pfn(*pte_from); 256 offset_max = max(uaddr_from & ~PAGE_MASK,
269 pfn_to = pte_pfn(*pte_to); 257 uaddr_to & ~PAGE_MASK);
270 offset_from = uaddr_from & (PAGE_SIZE-1);
271 offset_to = uaddr_from & (PAGE_SIZE-1);
272 offset_max = max(offset_from, offset_to);
273 size = min(n - done, PAGE_SIZE - offset_max); 258 size = min(n - done, PAGE_SIZE - offset_max);
274 259
275 memcpy((void *)(pfn_to << PAGE_SHIFT) + offset_to, 260 memcpy((void *) kaddr_to, (void *) kaddr_from, size);
276 (void *)(pfn_from << PAGE_SHIFT) + offset_from, size);
277 done += size; 261 done += size;
278 uaddr_from += size; 262 uaddr_from += size;
279 uaddr_to += size; 263 uaddr_to += size;
@@ -282,7 +266,7 @@ retry:
282 return n - done; 266 return n - done;
283fault: 267fault:
284 spin_unlock(&mm->page_table_lock); 268 spin_unlock(&mm->page_table_lock);
285 if (__handle_fault(uaddr, error_code, write_user)) 269 if (__handle_fault(uaddr, -error_code, write_user))
286 return n - done; 270 return n - done;
287 goto retry; 271 goto retry;
288} 272}
@@ -341,7 +325,7 @@ int futex_atomic_op_pt(int op, u32 __user *uaddr, int oparg, int *old)
341 return __futex_atomic_op_pt(op, uaddr, oparg, old); 325 return __futex_atomic_op_pt(op, uaddr, oparg, old);
342 spin_lock(&current->mm->page_table_lock); 326 spin_lock(&current->mm->page_table_lock);
343 uaddr = (u32 __force __user *) 327 uaddr = (u32 __force __user *)
344 __dat_user_addr((__force unsigned long) uaddr); 328 __dat_user_addr((__force unsigned long) uaddr, 1);
345 if (!uaddr) { 329 if (!uaddr) {
346 spin_unlock(&current->mm->page_table_lock); 330 spin_unlock(&current->mm->page_table_lock);
347 return -EFAULT; 331 return -EFAULT;
@@ -378,7 +362,7 @@ int futex_atomic_cmpxchg_pt(u32 *uval, u32 __user *uaddr,
378 return __futex_atomic_cmpxchg_pt(uval, uaddr, oldval, newval); 362 return __futex_atomic_cmpxchg_pt(uval, uaddr, oldval, newval);
379 spin_lock(&current->mm->page_table_lock); 363 spin_lock(&current->mm->page_table_lock);
380 uaddr = (u32 __force __user *) 364 uaddr = (u32 __force __user *)
381 __dat_user_addr((__force unsigned long) uaddr); 365 __dat_user_addr((__force unsigned long) uaddr, 1);
382 if (!uaddr) { 366 if (!uaddr) {
383 spin_unlock(&current->mm->page_table_lock); 367 spin_unlock(&current->mm->page_table_lock);
384 return -EFAULT; 368 return -EFAULT;
diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
index 2707023c7563..637970cfd3f4 100644
--- a/arch/score/kernel/process.c
+++ b/arch/score/kernel/process.c
@@ -27,6 +27,7 @@
27#include <linux/reboot.h> 27#include <linux/reboot.h>
28#include <linux/elfcore.h> 28#include <linux/elfcore.h>
29#include <linux/pm.h> 29#include <linux/pm.h>
30#include <linux/rcupdate.h>
30 31
31void (*pm_power_off)(void); 32void (*pm_power_off)(void);
32EXPORT_SYMBOL(pm_power_off); 33EXPORT_SYMBOL(pm_power_off);
@@ -50,9 +51,10 @@ void __noreturn cpu_idle(void)
50{ 51{
51 /* endless idle loop with no priority at all */ 52 /* endless idle loop with no priority at all */
52 while (1) { 53 while (1) {
54 rcu_idle_enter();
53 while (!need_resched()) 55 while (!need_resched())
54 barrier(); 56 barrier();
55 57 rcu_idle_exit();
56 schedule_preempt_disabled(); 58 schedule_preempt_disabled();
57 } 59 }
58} 60}
diff --git a/arch/sh/kernel/cpu/sh5/entry.S b/arch/sh/kernel/cpu/sh5/entry.S
index b7cf6a547f11..7e605b95592a 100644
--- a/arch/sh/kernel/cpu/sh5/entry.S
+++ b/arch/sh/kernel/cpu/sh5/entry.S
@@ -933,7 +933,7 @@ ret_with_reschedule:
933 933
934 pta restore_all, tr1 934 pta restore_all, tr1
935 935
936 movi _TIF_SIGPENDING, r8 936 movi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), r8
937 and r8, r7, r8 937 and r8, r7, r8
938 pta work_notifysig, tr0 938 pta work_notifysig, tr0
939 bne r8, ZERO, tr0 939 bne r8, ZERO, tr0
diff --git a/arch/sh/kernel/entry-common.S b/arch/sh/kernel/entry-common.S
index f67601cb3f1f..b96489d8b27d 100644
--- a/arch/sh/kernel/entry-common.S
+++ b/arch/sh/kernel/entry-common.S
@@ -139,7 +139,7 @@ work_pending:
139 ! r8: current_thread_info 139 ! r8: current_thread_info
140 ! t: result of "tst #_TIF_NEED_RESCHED, r0" 140 ! t: result of "tst #_TIF_NEED_RESCHED, r0"
141 bf/s work_resched 141 bf/s work_resched
142 tst #_TIF_SIGPENDING, r0 142 tst #(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME), r0
143work_notifysig: 143work_notifysig:
144 bt/s __restore_all 144 bt/s __restore_all
145 mov r15, r4 145 mov r15, r4
diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c
index 15e0a1693976..f1ddc0d23679 100644
--- a/arch/sparc/kernel/module.c
+++ b/arch/sparc/kernel/module.c
@@ -48,9 +48,7 @@ void *module_alloc(unsigned long size)
48 return NULL; 48 return NULL;
49 49
50 ret = module_map(size); 50 ret = module_map(size);
51 if (!ret) 51 if (ret)
52 ret = ERR_PTR(-ENOMEM);
53 else
54 memset(ret, 0, size); 52 memset(ret, 0, size);
55 53
56 return ret; 54 return ret;
@@ -116,6 +114,10 @@ int apply_relocate_add(Elf_Shdr *sechdrs,
116 v = sym->st_value + rel[i].r_addend; 114 v = sym->st_value + rel[i].r_addend;
117 115
118 switch (ELF_R_TYPE(rel[i].r_info) & 0xff) { 116 switch (ELF_R_TYPE(rel[i].r_info) & 0xff) {
117 case R_SPARC_DISP32:
118 v -= (Elf_Addr) location;
119 *loc32 = v;
120 break;
119#ifdef CONFIG_SPARC64 121#ifdef CONFIG_SPARC64
120 case R_SPARC_64: 122 case R_SPARC_64:
121 location[0] = v >> 56; 123 location[0] = v >> 56;
@@ -128,11 +130,6 @@ int apply_relocate_add(Elf_Shdr *sechdrs,
128 location[7] = v >> 0; 130 location[7] = v >> 0;
129 break; 131 break;
130 132
131 case R_SPARC_DISP32:
132 v -= (Elf_Addr) location;
133 *loc32 = v;
134 break;
135
136 case R_SPARC_WDISP19: 133 case R_SPARC_WDISP19:
137 v -= (Elf_Addr) location; 134 v -= (Elf_Addr) location;
138 *loc32 = (*loc32 & ~0x7ffff) | 135 *loc32 = (*loc32 & ~0x7ffff) |
diff --git a/arch/tile/include/gxio/iorpc_trio.h b/arch/tile/include/gxio/iorpc_trio.h
index 15fb77992083..58105c31228b 100644
--- a/arch/tile/include/gxio/iorpc_trio.h
+++ b/arch/tile/include/gxio/iorpc_trio.h
@@ -25,21 +25,23 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <asm/pgtable.h> 26#include <asm/pgtable.h>
27 27
28#define GXIO_TRIO_OP_ALLOC_ASIDS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1400) 28#define GXIO_TRIO_OP_DEALLOC_ASID IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1400)
29#define GXIO_TRIO_OP_ALLOC_ASIDS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1401)
29 30
30#define GXIO_TRIO_OP_ALLOC_MEMORY_MAPS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1402) 31#define GXIO_TRIO_OP_ALLOC_MEMORY_MAPS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1404)
31 32
32#define GXIO_TRIO_OP_ALLOC_PIO_REGIONS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x140e) 33#define GXIO_TRIO_OP_ALLOC_PIO_REGIONS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1412)
33#define GXIO_TRIO_OP_INIT_PIO_REGION_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x140f)
34 34
35#define GXIO_TRIO_OP_INIT_MEMORY_MAP_MMU_AUX IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1417) 35#define GXIO_TRIO_OP_INIT_PIO_REGION_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1414)
36#define GXIO_TRIO_OP_GET_PORT_PROPERTY IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1418)
37#define GXIO_TRIO_OP_CONFIG_LEGACY_INTR IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1419)
38#define GXIO_TRIO_OP_CONFIG_MSI_INTR IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x141a)
39 36
40#define GXIO_TRIO_OP_SET_MPS_MRS IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x141c) 37#define GXIO_TRIO_OP_INIT_MEMORY_MAP_MMU_AUX IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x141e)
41#define GXIO_TRIO_OP_FORCE_RC_LINK_UP IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x141d) 38#define GXIO_TRIO_OP_GET_PORT_PROPERTY IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x141f)
42#define GXIO_TRIO_OP_FORCE_EP_LINK_UP IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x141e) 39#define GXIO_TRIO_OP_CONFIG_LEGACY_INTR IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1420)
40#define GXIO_TRIO_OP_CONFIG_MSI_INTR IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1421)
41
42#define GXIO_TRIO_OP_SET_MPS_MRS IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1423)
43#define GXIO_TRIO_OP_FORCE_RC_LINK_UP IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1424)
44#define GXIO_TRIO_OP_FORCE_EP_LINK_UP IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1425)
43#define GXIO_TRIO_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000) 45#define GXIO_TRIO_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
44#define GXIO_TRIO_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001) 46#define GXIO_TRIO_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
45 47
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index 664a60e8dfb4..c17de0db6736 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -705,6 +705,7 @@ static void stack_proc(void *arg)
705 struct task_struct *from = current, *to = arg; 705 struct task_struct *from = current, *to = arg;
706 706
707 to->thread.saved_task = from; 707 to->thread.saved_task = from;
708 rcu_switch(from, to);
708 switch_to(from, to, from); 709 switch_to(from, to, from);
709} 710}
710 711
diff --git a/arch/um/include/asm/processor-generic.h b/arch/um/include/asm/processor-generic.h
index 69f1c57a8d0d..33a6a2423bd2 100644
--- a/arch/um/include/asm/processor-generic.h
+++ b/arch/um/include/asm/processor-generic.h
@@ -20,14 +20,6 @@ struct mm_struct;
20 20
21struct thread_struct { 21struct thread_struct {
22 struct task_struct *saved_task; 22 struct task_struct *saved_task;
23 /*
24 * This flag is set to 1 before calling do_fork (and analyzed in
25 * copy_thread) to mark that we are begin called from userspace (fork /
26 * vfork / clone), and reset to 0 after. It is left to 0 when called
27 * from kernelspace (i.e. kernel_thread() or fork_idle(),
28 * as of 2.6.11).
29 */
30 int forking;
31 struct pt_regs regs; 23 struct pt_regs regs;
32 int singlestep_syscall; 24 int singlestep_syscall;
33 void *fault_addr; 25 void *fault_addr;
@@ -58,7 +50,6 @@ struct thread_struct {
58 50
59#define INIT_THREAD \ 51#define INIT_THREAD \
60{ \ 52{ \
61 .forking = 0, \
62 .regs = EMPTY_REGS, \ 53 .regs = EMPTY_REGS, \
63 .fault_addr = NULL, \ 54 .fault_addr = NULL, \
64 .prev_sched = NULL, \ 55 .prev_sched = NULL, \
diff --git a/arch/um/include/shared/common-offsets.h b/arch/um/include/shared/common-offsets.h
index 40db8f71deae..2df313b6a586 100644
--- a/arch/um/include/shared/common-offsets.h
+++ b/arch/um/include/shared/common-offsets.h
@@ -7,16 +7,6 @@ DEFINE(UM_KERN_PAGE_MASK, PAGE_MASK);
7DEFINE(UM_KERN_PAGE_SHIFT, PAGE_SHIFT); 7DEFINE(UM_KERN_PAGE_SHIFT, PAGE_SHIFT);
8DEFINE(UM_NSEC_PER_SEC, NSEC_PER_SEC); 8DEFINE(UM_NSEC_PER_SEC, NSEC_PER_SEC);
9 9
10DEFINE_STR(UM_KERN_EMERG, KERN_EMERG);
11DEFINE_STR(UM_KERN_ALERT, KERN_ALERT);
12DEFINE_STR(UM_KERN_CRIT, KERN_CRIT);
13DEFINE_STR(UM_KERN_ERR, KERN_ERR);
14DEFINE_STR(UM_KERN_WARNING, KERN_WARNING);
15DEFINE_STR(UM_KERN_NOTICE, KERN_NOTICE);
16DEFINE_STR(UM_KERN_INFO, KERN_INFO);
17DEFINE_STR(UM_KERN_DEBUG, KERN_DEBUG);
18DEFINE_STR(UM_KERN_CONT, KERN_CONT);
19
20DEFINE(UM_ELF_CLASS, ELF_CLASS); 10DEFINE(UM_ELF_CLASS, ELF_CLASS);
21DEFINE(UM_ELFCLASS32, ELFCLASS32); 11DEFINE(UM_ELFCLASS32, ELFCLASS32);
22DEFINE(UM_ELFCLASS64, ELFCLASS64); 12DEFINE(UM_ELFCLASS64, ELFCLASS64);
diff --git a/arch/um/include/shared/user.h b/arch/um/include/shared/user.h
index 4fa82c055aab..cef068563336 100644
--- a/arch/um/include/shared/user.h
+++ b/arch/um/include/shared/user.h
@@ -26,6 +26,17 @@
26extern void panic(const char *fmt, ...) 26extern void panic(const char *fmt, ...)
27 __attribute__ ((format (printf, 1, 2))); 27 __attribute__ ((format (printf, 1, 2)));
28 28
29/* Requires preincluding include/linux/kern_levels.h */
30#define UM_KERN_EMERG KERN_EMERG
31#define UM_KERN_ALERT KERN_ALERT
32#define UM_KERN_CRIT KERN_CRIT
33#define UM_KERN_ERR KERN_ERR
34#define UM_KERN_WARNING KERN_WARNING
35#define UM_KERN_NOTICE KERN_NOTICE
36#define UM_KERN_INFO KERN_INFO
37#define UM_KERN_DEBUG KERN_DEBUG
38#define UM_KERN_CONT KERN_CONT
39
29#ifdef UML_CONFIG_PRINTK 40#ifdef UML_CONFIG_PRINTK
30extern int printk(const char *fmt, ...) 41extern int printk(const char *fmt, ...)
31 __attribute__ ((format (printf, 1, 2))); 42 __attribute__ ((format (printf, 1, 2)));
diff --git a/arch/um/kernel/exec.c b/arch/um/kernel/exec.c
index 6cade9366364..8c82786da823 100644
--- a/arch/um/kernel/exec.c
+++ b/arch/um/kernel/exec.c
@@ -39,34 +39,21 @@ void flush_thread(void)
39 39
40void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp) 40void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
41{ 41{
42 get_safe_registers(regs->regs.gp, regs->regs.fp);
42 PT_REGS_IP(regs) = eip; 43 PT_REGS_IP(regs) = eip;
43 PT_REGS_SP(regs) = esp; 44 PT_REGS_SP(regs) = esp;
44} 45 current->ptrace &= ~PT_DTRACE;
45EXPORT_SYMBOL(start_thread);
46
47static long execve1(const char *file,
48 const char __user *const __user *argv,
49 const char __user *const __user *env)
50{
51 long error;
52
53 error = do_execve(file, argv, env, &current->thread.regs);
54 if (error == 0) {
55 task_lock(current);
56 current->ptrace &= ~PT_DTRACE;
57#ifdef SUBARCH_EXECVE1 46#ifdef SUBARCH_EXECVE1
58 SUBARCH_EXECVE1(&current->thread.regs.regs); 47 SUBARCH_EXECVE1(regs->regs);
59#endif 48#endif
60 task_unlock(current);
61 }
62 return error;
63} 49}
50EXPORT_SYMBOL(start_thread);
64 51
65long um_execve(const char *file, const char __user *const __user *argv, const char __user *const __user *env) 52long um_execve(const char *file, const char __user *const __user *argv, const char __user *const __user *env)
66{ 53{
67 long err; 54 long err;
68 55
69 err = execve1(file, argv, env); 56 err = do_execve(file, argv, env, &current->thread.regs);
70 if (!err) 57 if (!err)
71 UML_LONGJMP(current->thread.exec_buf, 1); 58 UML_LONGJMP(current->thread.exec_buf, 1);
72 return err; 59 return err;
@@ -81,7 +68,7 @@ long sys_execve(const char __user *file, const char __user *const __user *argv,
81 filename = getname(file); 68 filename = getname(file);
82 error = PTR_ERR(filename); 69 error = PTR_ERR(filename);
83 if (IS_ERR(filename)) goto out; 70 if (IS_ERR(filename)) goto out;
84 error = execve1(filename, argv, env); 71 error = do_execve(filename, argv, env, &current->thread.regs);
85 putname(filename); 72 putname(filename);
86 out: 73 out:
87 return error; 74 return error;
diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
index 57fc7028714a..c5f5afa50745 100644
--- a/arch/um/kernel/process.c
+++ b/arch/um/kernel/process.c
@@ -181,11 +181,12 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
181 struct pt_regs *regs) 181 struct pt_regs *regs)
182{ 182{
183 void (*handler)(void); 183 void (*handler)(void);
184 int kthread = current->flags & PF_KTHREAD;
184 int ret = 0; 185 int ret = 0;
185 186
186 p->thread = (struct thread_struct) INIT_THREAD; 187 p->thread = (struct thread_struct) INIT_THREAD;
187 188
188 if (current->thread.forking) { 189 if (!kthread) {
189 memcpy(&p->thread.regs.regs, &regs->regs, 190 memcpy(&p->thread.regs.regs, &regs->regs,
190 sizeof(p->thread.regs.regs)); 191 sizeof(p->thread.regs.regs));
191 PT_REGS_SET_SYSCALL_RETURN(&p->thread.regs, 0); 192 PT_REGS_SET_SYSCALL_RETURN(&p->thread.regs, 0);
@@ -195,8 +196,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
195 handler = fork_handler; 196 handler = fork_handler;
196 197
197 arch_copy_thread(&current->thread.arch, &p->thread.arch); 198 arch_copy_thread(&current->thread.arch, &p->thread.arch);
198 } 199 } else {
199 else {
200 get_safe_registers(p->thread.regs.regs.gp, p->thread.regs.regs.fp); 200 get_safe_registers(p->thread.regs.regs.gp, p->thread.regs.regs.fp);
201 p->thread.request.u.thread = current->thread.request.u.thread; 201 p->thread.request.u.thread = current->thread.request.u.thread;
202 handler = new_thread_handler; 202 handler = new_thread_handler;
@@ -204,7 +204,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
204 204
205 new_thread(task_stack_page(p), &p->thread.switch_buf, handler); 205 new_thread(task_stack_page(p), &p->thread.switch_buf, handler);
206 206
207 if (current->thread.forking) { 207 if (!kthread) {
208 clear_flushed_tls(p); 208 clear_flushed_tls(p);
209 209
210 /* 210 /*
diff --git a/arch/um/kernel/signal.c b/arch/um/kernel/signal.c
index 7362d58efc29..cc9c2350e417 100644
--- a/arch/um/kernel/signal.c
+++ b/arch/um/kernel/signal.c
@@ -22,9 +22,13 @@ static void handle_signal(struct pt_regs *regs, unsigned long signr,
22 struct k_sigaction *ka, siginfo_t *info) 22 struct k_sigaction *ka, siginfo_t *info)
23{ 23{
24 sigset_t *oldset = sigmask_to_save(); 24 sigset_t *oldset = sigmask_to_save();
25 int singlestep = 0;
25 unsigned long sp; 26 unsigned long sp;
26 int err; 27 int err;
27 28
29 if ((current->ptrace & PT_DTRACE) && (current->ptrace & PT_PTRACED))
30 singlestep = 1;
31
28 /* Did we come from a system call? */ 32 /* Did we come from a system call? */
29 if (PT_REGS_SYSCALL_NR(regs) >= 0) { 33 if (PT_REGS_SYSCALL_NR(regs) >= 0) {
30 /* If so, check system call restarting.. */ 34 /* If so, check system call restarting.. */
@@ -61,7 +65,7 @@ static void handle_signal(struct pt_regs *regs, unsigned long signr,
61 if (err) 65 if (err)
62 force_sigsegv(signr, current); 66 force_sigsegv(signr, current);
63 else 67 else
64 signal_delivered(signr, info, ka, regs, 0); 68 signal_delivered(signr, info, ka, regs, singlestep);
65} 69}
66 70
67static int kern_do_signal(struct pt_regs *regs) 71static int kern_do_signal(struct pt_regs *regs)
diff --git a/arch/um/kernel/syscall.c b/arch/um/kernel/syscall.c
index f958cb876ee3..a4c6d8eee74c 100644
--- a/arch/um/kernel/syscall.c
+++ b/arch/um/kernel/syscall.c
@@ -17,25 +17,25 @@
17 17
18long sys_fork(void) 18long sys_fork(void)
19{ 19{
20 long ret; 20 return do_fork(SIGCHLD, UPT_SP(&current->thread.regs.regs),
21
22 current->thread.forking = 1;
23 ret = do_fork(SIGCHLD, UPT_SP(&current->thread.regs.regs),
24 &current->thread.regs, 0, NULL, NULL); 21 &current->thread.regs, 0, NULL, NULL);
25 current->thread.forking = 0;
26 return ret;
27} 22}
28 23
29long sys_vfork(void) 24long sys_vfork(void)
30{ 25{
31 long ret; 26 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
32
33 current->thread.forking = 1;
34 ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
35 UPT_SP(&current->thread.regs.regs), 27 UPT_SP(&current->thread.regs.regs),
36 &current->thread.regs, 0, NULL, NULL); 28 &current->thread.regs, 0, NULL, NULL);
37 current->thread.forking = 0; 29}
38 return ret; 30
31long sys_clone(unsigned long clone_flags, unsigned long newsp,
32 void __user *parent_tid, void __user *child_tid)
33{
34 if (!newsp)
35 newsp = UPT_SP(&current->thread.regs.regs);
36
37 return do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
38 child_tid);
39} 39}
40 40
41long old_mmap(unsigned long addr, unsigned long len, 41long old_mmap(unsigned long addr, unsigned long len,
diff --git a/arch/um/scripts/Makefile.rules b/arch/um/scripts/Makefile.rules
index d50270d26b42..15889df9b466 100644
--- a/arch/um/scripts/Makefile.rules
+++ b/arch/um/scripts/Makefile.rules
@@ -8,7 +8,7 @@ USER_OBJS += $(filter %_user.o,$(obj-y) $(obj-m) $(USER_SINGLE_OBJS))
8USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file)) 8USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
9 9
10$(USER_OBJS:.o=.%): \ 10$(USER_OBJS:.o=.%): \
11 c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) -include user.h $(CFLAGS_$(basetarget).o) 11 c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) -include $(srctree)/include/linux/kern_levels.h -include user.h $(CFLAGS_$(basetarget).o)
12 12
13# These are like USER_OBJS but filter USER_CFLAGS through unprofile instead of 13# These are like USER_OBJS but filter USER_CFLAGS through unprofile instead of
14# using it directly. 14# using it directly.
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 28dd891a0a16..8ff1f56a0188 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -100,6 +100,7 @@ config X86
100 select KTIME_SCALAR if X86_32 100 select KTIME_SCALAR if X86_32
101 select GENERIC_STRNCPY_FROM_USER 101 select GENERIC_STRNCPY_FROM_USER
102 select GENERIC_STRNLEN_USER 102 select GENERIC_STRNLEN_USER
103 select HAVE_RCU_USER_QS if X86_64
103 104
104config INSTRUCTION_DECODER 105config INSTRUCTION_DECODER
105 def_bool (KPROBES || PERF_EVENTS || UPROBES) 106 def_bool (KPROBES || PERF_EVENTS || UPROBES)
@@ -749,10 +750,10 @@ config SWIOTLB
749 def_bool y if X86_64 750 def_bool y if X86_64
750 ---help--- 751 ---help---
751 Support for software bounce buffers used on x86-64 systems 752 Support for software bounce buffers used on x86-64 systems
752 which don't have a hardware IOMMU (e.g. the current generation 753 which don't have a hardware IOMMU. Using this PCI devices
753 of Intel's x86-64 CPUs). Using this PCI devices which can only 754 which can only access 32-bits of memory can be used on systems
754 access 32-bits of memory can be used on systems with more than 755 with more than 3 GB of memory.
755 3 GB of memory. If unsure, say Y. 756 If unsure, say Y.
756 757
757config IOMMU_HELPER 758config IOMMU_HELPER
758 def_bool (CALGARY_IOMMU || GART_IOMMU || SWIOTLB || AMD_IOMMU) 759 def_bool (CALGARY_IOMMU || GART_IOMMU || SWIOTLB || AMD_IOMMU)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 682e9c210baa..474ca35b1bce 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -142,7 +142,7 @@ KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
142KBUILD_CFLAGS += $(mflags-y) 142KBUILD_CFLAGS += $(mflags-y)
143KBUILD_AFLAGS += $(mflags-y) 143KBUILD_AFLAGS += $(mflags-y)
144 144
145archscripts: 145archscripts: scripts_basic
146 $(Q)$(MAKE) $(build)=arch/x86/tools relocs 146 $(Q)$(MAKE) $(build)=arch/x86/tools relocs
147 147
148### 148###
diff --git a/arch/x86/include/asm/hpet.h b/arch/x86/include/asm/hpet.h
index 2c392d663dce..434e2106cc87 100644
--- a/arch/x86/include/asm/hpet.h
+++ b/arch/x86/include/asm/hpet.h
@@ -35,8 +35,6 @@
35#define HPET_ID_NUMBER_SHIFT 8 35#define HPET_ID_NUMBER_SHIFT 8
36#define HPET_ID_VENDOR_SHIFT 16 36#define HPET_ID_VENDOR_SHIFT 16
37 37
38#define HPET_ID_VENDOR_8086 0x8086
39
40#define HPET_CFG_ENABLE 0x001 38#define HPET_CFG_ENABLE 0x001
41#define HPET_CFG_LEGACY 0x002 39#define HPET_CFG_LEGACY 0x002
42#define HPET_LEGACY_8254 2 40#define HPET_LEGACY_8254 2
diff --git a/arch/x86/include/asm/rcu.h b/arch/x86/include/asm/rcu.h
new file mode 100644
index 000000000000..d1ac07a23979
--- /dev/null
+++ b/arch/x86/include/asm/rcu.h
@@ -0,0 +1,32 @@
1#ifndef _ASM_X86_RCU_H
2#define _ASM_X86_RCU_H
3
4#ifndef __ASSEMBLY__
5
6#include <linux/rcupdate.h>
7#include <asm/ptrace.h>
8
9static inline void exception_enter(struct pt_regs *regs)
10{
11 rcu_user_exit();
12}
13
14static inline void exception_exit(struct pt_regs *regs)
15{
16#ifdef CONFIG_RCU_USER_QS
17 if (user_mode(regs))
18 rcu_user_enter();
19#endif
20}
21
22#else /* __ASSEMBLY__ */
23
24#ifdef CONFIG_RCU_USER_QS
25# define SCHEDULE_USER call schedule_user
26#else
27# define SCHEDULE_USER call schedule
28#endif
29
30#endif /* !__ASSEMBLY__ */
31
32#endif
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 89f794f007ec..c535d847e3b5 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -89,6 +89,7 @@ struct thread_info {
89#define TIF_NOTSC 16 /* TSC is not accessible in userland */ 89#define TIF_NOTSC 16 /* TSC is not accessible in userland */
90#define TIF_IA32 17 /* IA32 compatibility process */ 90#define TIF_IA32 17 /* IA32 compatibility process */
91#define TIF_FORK 18 /* ret_from_fork */ 91#define TIF_FORK 18 /* ret_from_fork */
92#define TIF_NOHZ 19 /* in adaptive nohz mode */
92#define TIF_MEMDIE 20 /* is terminating due to OOM killer */ 93#define TIF_MEMDIE 20 /* is terminating due to OOM killer */
93#define TIF_DEBUG 21 /* uses debug registers */ 94#define TIF_DEBUG 21 /* uses debug registers */
94#define TIF_IO_BITMAP 22 /* uses I/O bitmap */ 95#define TIF_IO_BITMAP 22 /* uses I/O bitmap */
@@ -114,6 +115,7 @@ struct thread_info {
114#define _TIF_NOTSC (1 << TIF_NOTSC) 115#define _TIF_NOTSC (1 << TIF_NOTSC)
115#define _TIF_IA32 (1 << TIF_IA32) 116#define _TIF_IA32 (1 << TIF_IA32)
116#define _TIF_FORK (1 << TIF_FORK) 117#define _TIF_FORK (1 << TIF_FORK)
118#define _TIF_NOHZ (1 << TIF_NOHZ)
117#define _TIF_DEBUG (1 << TIF_DEBUG) 119#define _TIF_DEBUG (1 << TIF_DEBUG)
118#define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP) 120#define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP)
119#define _TIF_FORCED_TF (1 << TIF_FORCED_TF) 121#define _TIF_FORCED_TF (1 << TIF_FORCED_TF)
@@ -126,12 +128,13 @@ struct thread_info {
126/* work to do in syscall_trace_enter() */ 128/* work to do in syscall_trace_enter() */
127#define _TIF_WORK_SYSCALL_ENTRY \ 129#define _TIF_WORK_SYSCALL_ENTRY \
128 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \ 130 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
129 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT) 131 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
132 _TIF_NOHZ)
130 133
131/* work to do in syscall_trace_leave() */ 134/* work to do in syscall_trace_leave() */
132#define _TIF_WORK_SYSCALL_EXIT \ 135#define _TIF_WORK_SYSCALL_EXIT \
133 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \ 136 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
134 _TIF_SYSCALL_TRACEPOINT) 137 _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
135 138
136/* work to do on interrupt/exception return */ 139/* work to do on interrupt/exception return */
137#define _TIF_WORK_MASK \ 140#define _TIF_WORK_MASK \
@@ -141,7 +144,8 @@ struct thread_info {
141 144
142/* work to do on any return to user space */ 145/* work to do on any return to user space */
143#define _TIF_ALLWORK_MASK \ 146#define _TIF_ALLWORK_MASK \
144 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT) 147 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
148 _TIF_NOHZ)
145 149
146/* Only used for 64 bit */ 150/* Only used for 64 bit */
147#define _TIF_DO_NOTIFY_MASK \ 151#define _TIF_DO_NOTIFY_MASK \
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 93971e841dd5..472b9b783019 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -51,7 +51,8 @@ extern unsigned long set_phys_range_identity(unsigned long pfn_s,
51 51
52extern int m2p_add_override(unsigned long mfn, struct page *page, 52extern int m2p_add_override(unsigned long mfn, struct page *page,
53 struct gnttab_map_grant_ref *kmap_op); 53 struct gnttab_map_grant_ref *kmap_op);
54extern int m2p_remove_override(struct page *page, bool clear_pte); 54extern int m2p_remove_override(struct page *page,
55 struct gnttab_map_grant_ref *kmap_op);
55extern struct page *m2p_find_override(unsigned long mfn); 56extern struct page *m2p_find_override(unsigned long mfn);
56extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn); 57extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
57 58
diff --git a/arch/x86/kernel/cpu/perf_event.h b/arch/x86/kernel/cpu/perf_event.h
index 6605a81ba339..8b6defe7eefc 100644
--- a/arch/x86/kernel/cpu/perf_event.h
+++ b/arch/x86/kernel/cpu/perf_event.h
@@ -586,6 +586,8 @@ extern struct event_constraint intel_westmere_pebs_event_constraints[];
586 586
587extern struct event_constraint intel_snb_pebs_event_constraints[]; 587extern struct event_constraint intel_snb_pebs_event_constraints[];
588 588
589extern struct event_constraint intel_ivb_pebs_event_constraints[];
590
589struct event_constraint *intel_pebs_constraints(struct perf_event *event); 591struct event_constraint *intel_pebs_constraints(struct perf_event *event);
590 592
591void intel_pmu_pebs_enable(struct perf_event *event); 593void intel_pmu_pebs_enable(struct perf_event *event);
diff --git a/arch/x86/kernel/cpu/perf_event_amd_ibs.c b/arch/x86/kernel/cpu/perf_event_amd_ibs.c
index 7bfb5bec8630..eebd5ffe1bba 100644
--- a/arch/x86/kernel/cpu/perf_event_amd_ibs.c
+++ b/arch/x86/kernel/cpu/perf_event_amd_ibs.c
@@ -209,6 +209,15 @@ static int perf_ibs_precise_event(struct perf_event *event, u64 *config)
209 return -EOPNOTSUPP; 209 return -EOPNOTSUPP;
210} 210}
211 211
212static const struct perf_event_attr ibs_notsupp = {
213 .exclude_user = 1,
214 .exclude_kernel = 1,
215 .exclude_hv = 1,
216 .exclude_idle = 1,
217 .exclude_host = 1,
218 .exclude_guest = 1,
219};
220
212static int perf_ibs_init(struct perf_event *event) 221static int perf_ibs_init(struct perf_event *event)
213{ 222{
214 struct hw_perf_event *hwc = &event->hw; 223 struct hw_perf_event *hwc = &event->hw;
@@ -229,6 +238,9 @@ static int perf_ibs_init(struct perf_event *event)
229 if (event->pmu != &perf_ibs->pmu) 238 if (event->pmu != &perf_ibs->pmu)
230 return -ENOENT; 239 return -ENOENT;
231 240
241 if (perf_flags(&event->attr) & perf_flags(&ibs_notsupp))
242 return -EINVAL;
243
232 if (config & ~perf_ibs->config_mask) 244 if (config & ~perf_ibs->config_mask)
233 return -EINVAL; 245 return -EINVAL;
234 246
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 7f2739e03e79..6bca492b8547 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -2008,6 +2008,7 @@ __init int intel_pmu_init(void)
2008 break; 2008 break;
2009 2009
2010 case 28: /* Atom */ 2010 case 28: /* Atom */
2011 case 54: /* Cedariew */
2011 memcpy(hw_cache_event_ids, atom_hw_cache_event_ids, 2012 memcpy(hw_cache_event_ids, atom_hw_cache_event_ids,
2012 sizeof(hw_cache_event_ids)); 2013 sizeof(hw_cache_event_ids));
2013 2014
@@ -2047,7 +2048,6 @@ __init int intel_pmu_init(void)
2047 case 42: /* SandyBridge */ 2048 case 42: /* SandyBridge */
2048 case 45: /* SandyBridge, "Romely-EP" */ 2049 case 45: /* SandyBridge, "Romely-EP" */
2049 x86_add_quirk(intel_sandybridge_quirk); 2050 x86_add_quirk(intel_sandybridge_quirk);
2050 case 58: /* IvyBridge */
2051 memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, 2051 memcpy(hw_cache_event_ids, snb_hw_cache_event_ids,
2052 sizeof(hw_cache_event_ids)); 2052 sizeof(hw_cache_event_ids));
2053 memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs, 2053 memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs,
@@ -2072,6 +2072,29 @@ __init int intel_pmu_init(void)
2072 2072
2073 pr_cont("SandyBridge events, "); 2073 pr_cont("SandyBridge events, ");
2074 break; 2074 break;
2075 case 58: /* IvyBridge */
2076 memcpy(hw_cache_event_ids, snb_hw_cache_event_ids,
2077 sizeof(hw_cache_event_ids));
2078 memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs,
2079 sizeof(hw_cache_extra_regs));
2080
2081 intel_pmu_lbr_init_snb();
2082
2083 x86_pmu.event_constraints = intel_snb_event_constraints;
2084 x86_pmu.pebs_constraints = intel_ivb_pebs_event_constraints;
2085 x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
2086 x86_pmu.extra_regs = intel_snb_extra_regs;
2087 /* all extra regs are per-cpu when HT is on */
2088 x86_pmu.er_flags |= ERF_HAS_RSP_1;
2089 x86_pmu.er_flags |= ERF_NO_HT_SHARING;
2090
2091 /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
2092 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
2093 X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
2094
2095 pr_cont("IvyBridge events, ");
2096 break;
2097
2075 2098
2076 default: 2099 default:
2077 switch (x86_pmu.version) { 2100 switch (x86_pmu.version) {
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
index e38d97bf4259..826054a4f2ee 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -407,6 +407,20 @@ struct event_constraint intel_snb_pebs_event_constraints[] = {
407 EVENT_CONSTRAINT_END 407 EVENT_CONSTRAINT_END
408}; 408};
409 409
410struct event_constraint intel_ivb_pebs_event_constraints[] = {
411 INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PRECDIST */
412 INTEL_UEVENT_CONSTRAINT(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
413 INTEL_UEVENT_CONSTRAINT(0x02c2, 0xf), /* UOPS_RETIRED.RETIRE_SLOTS */
414 INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
415 INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */
416 INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.* */
417 INTEL_EVENT_CONSTRAINT(0xd0, 0xf), /* MEM_UOP_RETIRED.* */
418 INTEL_EVENT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
419 INTEL_EVENT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
420 INTEL_EVENT_CONSTRAINT(0xd3, 0xf), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */
421 EVENT_CONSTRAINT_END
422};
423
410struct event_constraint *intel_pebs_constraints(struct perf_event *event) 424struct event_constraint *intel_pebs_constraints(struct perf_event *event)
411{ 425{
412 struct event_constraint *c; 426 struct event_constraint *c;
diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index 520b4265fcd2..da02e9cc3754 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -686,7 +686,8 @@ void intel_pmu_lbr_init_atom(void)
686 * to have an operational LBR which can freeze 686 * to have an operational LBR which can freeze
687 * on PMU interrupt 687 * on PMU interrupt
688 */ 688 */
689 if (boot_cpu_data.x86_mask < 10) { 689 if (boot_cpu_data.x86_model == 28
690 && boot_cpu_data.x86_mask < 10) {
690 pr_cont("LBR disabled due to erratum"); 691 pr_cont("LBR disabled due to erratum");
691 return; 692 return;
692 } 693 }
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
index 62ec3e6af7ea..db917ec89040 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
@@ -661,6 +661,11 @@ static void snb_uncore_msr_init_box(struct intel_uncore_box *box)
661 } 661 }
662} 662}
663 663
664static struct uncore_event_desc snb_uncore_events[] = {
665 INTEL_UNCORE_EVENT_DESC(clockticks, "event=0xff,umask=0x00"),
666 { /* end: all zeroes */ },
667};
668
664static struct attribute *snb_uncore_formats_attr[] = { 669static struct attribute *snb_uncore_formats_attr[] = {
665 &format_attr_event.attr, 670 &format_attr_event.attr,
666 &format_attr_umask.attr, 671 &format_attr_umask.attr,
@@ -704,6 +709,7 @@ static struct intel_uncore_type snb_uncore_cbox = {
704 .constraints = snb_uncore_cbox_constraints, 709 .constraints = snb_uncore_cbox_constraints,
705 .ops = &snb_uncore_msr_ops, 710 .ops = &snb_uncore_msr_ops,
706 .format_group = &snb_uncore_format_group, 711 .format_group = &snb_uncore_format_group,
712 .event_descs = snb_uncore_events,
707}; 713};
708 714
709static struct intel_uncore_type *snb_msr_uncores[] = { 715static struct intel_uncore_type *snb_msr_uncores[] = {
diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index 39472dd2323f..60c78917190c 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -199,12 +199,14 @@ static int __init cpuid_init(void)
199 goto out_chrdev; 199 goto out_chrdev;
200 } 200 }
201 cpuid_class->devnode = cpuid_devnode; 201 cpuid_class->devnode = cpuid_devnode;
202 get_online_cpus();
202 for_each_online_cpu(i) { 203 for_each_online_cpu(i) {
203 err = cpuid_device_create(i); 204 err = cpuid_device_create(i);
204 if (err != 0) 205 if (err != 0)
205 goto out_class; 206 goto out_class;
206 } 207 }
207 register_hotcpu_notifier(&cpuid_class_cpu_notifier); 208 register_hotcpu_notifier(&cpuid_class_cpu_notifier);
209 put_online_cpus();
208 210
209 err = 0; 211 err = 0;
210 goto out; 212 goto out;
@@ -214,6 +216,7 @@ out_class:
214 for_each_online_cpu(i) { 216 for_each_online_cpu(i) {
215 cpuid_device_destroy(i); 217 cpuid_device_destroy(i);
216 } 218 }
219 put_online_cpus();
217 class_destroy(cpuid_class); 220 class_destroy(cpuid_class);
218out_chrdev: 221out_chrdev:
219 __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid"); 222 __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid");
@@ -225,11 +228,13 @@ static void __exit cpuid_exit(void)
225{ 228{
226 int cpu = 0; 229 int cpu = 0;
227 230
231 get_online_cpus();
228 for_each_online_cpu(cpu) 232 for_each_online_cpu(cpu)
229 cpuid_device_destroy(cpu); 233 cpuid_device_destroy(cpu);
230 class_destroy(cpuid_class); 234 class_destroy(cpuid_class);
231 __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid"); 235 __unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid");
232 unregister_hotcpu_notifier(&cpuid_class_cpu_notifier); 236 unregister_hotcpu_notifier(&cpuid_class_cpu_notifier);
237 put_online_cpus();
233} 238}
234 239
235module_init(cpuid_init); 240module_init(cpuid_init);
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index e9cc2b32bdf4..4f0322e4ecee 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -56,6 +56,7 @@
56#include <asm/ftrace.h> 56#include <asm/ftrace.h>
57#include <asm/percpu.h> 57#include <asm/percpu.h>
58#include <asm/asm.h> 58#include <asm/asm.h>
59#include <asm/rcu.h>
59#include <linux/err.h> 60#include <linux/err.h>
60 61
61/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ 62/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
@@ -667,7 +668,7 @@ sysret_careful:
667 TRACE_IRQS_ON 668 TRACE_IRQS_ON
668 ENABLE_INTERRUPTS(CLBR_NONE) 669 ENABLE_INTERRUPTS(CLBR_NONE)
669 pushq_cfi %rdi 670 pushq_cfi %rdi
670 call schedule 671 SCHEDULE_USER
671 popq_cfi %rdi 672 popq_cfi %rdi
672 jmp sysret_check 673 jmp sysret_check
673 674
@@ -780,7 +781,7 @@ int_careful:
780 TRACE_IRQS_ON 781 TRACE_IRQS_ON
781 ENABLE_INTERRUPTS(CLBR_NONE) 782 ENABLE_INTERRUPTS(CLBR_NONE)
782 pushq_cfi %rdi 783 pushq_cfi %rdi
783 call schedule 784 SCHEDULE_USER
784 popq_cfi %rdi 785 popq_cfi %rdi
785 DISABLE_INTERRUPTS(CLBR_NONE) 786 DISABLE_INTERRUPTS(CLBR_NONE)
786 TRACE_IRQS_OFF 787 TRACE_IRQS_OFF
@@ -1076,7 +1077,7 @@ retint_careful:
1076 TRACE_IRQS_ON 1077 TRACE_IRQS_ON
1077 ENABLE_INTERRUPTS(CLBR_NONE) 1078 ENABLE_INTERRUPTS(CLBR_NONE)
1078 pushq_cfi %rdi 1079 pushq_cfi %rdi
1079 call schedule 1080 SCHEDULE_USER
1080 popq_cfi %rdi 1081 popq_cfi %rdi
1081 GET_THREAD_INFO(%rcx) 1082 GET_THREAD_INFO(%rcx)
1082 DISABLE_INTERRUPTS(CLBR_NONE) 1083 DISABLE_INTERRUPTS(CLBR_NONE)
@@ -1551,7 +1552,7 @@ paranoid_userspace:
1551paranoid_schedule: 1552paranoid_schedule:
1552 TRACE_IRQS_ON 1553 TRACE_IRQS_ON
1553 ENABLE_INTERRUPTS(CLBR_ANY) 1554 ENABLE_INTERRUPTS(CLBR_ANY)
1554 call schedule 1555 SCHEDULE_USER
1555 DISABLE_INTERRUPTS(CLBR_ANY) 1556 DISABLE_INTERRUPTS(CLBR_ANY)
1556 TRACE_IRQS_OFF 1557 TRACE_IRQS_OFF
1557 jmp paranoid_userspace 1558 jmp paranoid_userspace
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index eb113693f043..a7c5661f8496 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -257,12 +257,14 @@ static int __init msr_init(void)
257 goto out_chrdev; 257 goto out_chrdev;
258 } 258 }
259 msr_class->devnode = msr_devnode; 259 msr_class->devnode = msr_devnode;
260 get_online_cpus();
260 for_each_online_cpu(i) { 261 for_each_online_cpu(i) {
261 err = msr_device_create(i); 262 err = msr_device_create(i);
262 if (err != 0) 263 if (err != 0)
263 goto out_class; 264 goto out_class;
264 } 265 }
265 register_hotcpu_notifier(&msr_class_cpu_notifier); 266 register_hotcpu_notifier(&msr_class_cpu_notifier);
267 put_online_cpus();
266 268
267 err = 0; 269 err = 0;
268 goto out; 270 goto out;
@@ -271,6 +273,7 @@ out_class:
271 i = 0; 273 i = 0;
272 for_each_online_cpu(i) 274 for_each_online_cpu(i)
273 msr_device_destroy(i); 275 msr_device_destroy(i);
276 put_online_cpus();
274 class_destroy(msr_class); 277 class_destroy(msr_class);
275out_chrdev: 278out_chrdev:
276 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); 279 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
@@ -281,11 +284,13 @@ out:
281static void __exit msr_exit(void) 284static void __exit msr_exit(void)
282{ 285{
283 int cpu = 0; 286 int cpu = 0;
287 get_online_cpus();
284 for_each_online_cpu(cpu) 288 for_each_online_cpu(cpu)
285 msr_device_destroy(cpu); 289 msr_device_destroy(cpu);
286 class_destroy(msr_class); 290 class_destroy(msr_class);
287 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); 291 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
288 unregister_hotcpu_notifier(&msr_class_cpu_notifier); 292 unregister_hotcpu_notifier(&msr_class_cpu_notifier);
293 put_online_cpus();
289} 294}
290 295
291module_init(msr_init); 296module_init(msr_init);
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index c4c6a5c2bf0f..9f94f8ec26e4 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -21,6 +21,7 @@
21#include <linux/signal.h> 21#include <linux/signal.h>
22#include <linux/perf_event.h> 22#include <linux/perf_event.h>
23#include <linux/hw_breakpoint.h> 23#include <linux/hw_breakpoint.h>
24#include <linux/rcupdate.h>
24 25
25#include <asm/uaccess.h> 26#include <asm/uaccess.h>
26#include <asm/pgtable.h> 27#include <asm/pgtable.h>
@@ -1463,6 +1464,8 @@ long syscall_trace_enter(struct pt_regs *regs)
1463{ 1464{
1464 long ret = 0; 1465 long ret = 0;
1465 1466
1467 rcu_user_exit();
1468
1466 /* 1469 /*
1467 * If we stepped into a sysenter/syscall insn, it trapped in 1470 * If we stepped into a sysenter/syscall insn, it trapped in
1468 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP. 1471 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
@@ -1526,4 +1529,6 @@ void syscall_trace_leave(struct pt_regs *regs)
1526 !test_thread_flag(TIF_SYSCALL_EMU); 1529 !test_thread_flag(TIF_SYSCALL_EMU);
1527 if (step || test_thread_flag(TIF_SYSCALL_TRACE)) 1530 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
1528 tracehook_report_syscall_exit(regs, step); 1531 tracehook_report_syscall_exit(regs, step);
1532
1533 rcu_user_enter();
1529} 1534}
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index b280908a376e..bca0ab903e57 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -779,6 +779,8 @@ static void do_signal(struct pt_regs *regs)
779void 779void
780do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) 780do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
781{ 781{
782 rcu_user_exit();
783
782#ifdef CONFIG_X86_MCE 784#ifdef CONFIG_X86_MCE
783 /* notify userspace of pending MCEs */ 785 /* notify userspace of pending MCEs */
784 if (thread_info_flags & _TIF_MCE_NOTIFY) 786 if (thread_info_flags & _TIF_MCE_NOTIFY)
@@ -804,6 +806,8 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
804#ifdef CONFIG_X86_32 806#ifdef CONFIG_X86_32
805 clear_thread_flag(TIF_IRET); 807 clear_thread_flag(TIF_IRET);
806#endif /* CONFIG_X86_32 */ 808#endif /* CONFIG_X86_32 */
809
810 rcu_user_enter();
807} 811}
808 812
809void signal_fault(struct pt_regs *regs, void __user *frame, char *where) 813void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index b481341c9369..378967578f22 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -55,6 +55,7 @@
55#include <asm/i387.h> 55#include <asm/i387.h>
56#include <asm/fpu-internal.h> 56#include <asm/fpu-internal.h>
57#include <asm/mce.h> 57#include <asm/mce.h>
58#include <asm/rcu.h>
58 59
59#include <asm/mach_traps.h> 60#include <asm/mach_traps.h>
60 61
@@ -180,11 +181,15 @@ vm86_trap:
180#define DO_ERROR(trapnr, signr, str, name) \ 181#define DO_ERROR(trapnr, signr, str, name) \
181dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \ 182dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
182{ \ 183{ \
183 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ 184 exception_enter(regs); \
184 == NOTIFY_STOP) \ 185 if (notify_die(DIE_TRAP, str, regs, error_code, \
186 trapnr, signr) == NOTIFY_STOP) { \
187 exception_exit(regs); \
185 return; \ 188 return; \
189 } \
186 conditional_sti(regs); \ 190 conditional_sti(regs); \
187 do_trap(trapnr, signr, str, regs, error_code, NULL); \ 191 do_trap(trapnr, signr, str, regs, error_code, NULL); \
192 exception_exit(regs); \
188} 193}
189 194
190#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ 195#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
@@ -195,11 +200,15 @@ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
195 info.si_errno = 0; \ 200 info.si_errno = 0; \
196 info.si_code = sicode; \ 201 info.si_code = sicode; \
197 info.si_addr = (void __user *)siaddr; \ 202 info.si_addr = (void __user *)siaddr; \
198 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ 203 exception_enter(regs); \
199 == NOTIFY_STOP) \ 204 if (notify_die(DIE_TRAP, str, regs, error_code, \
205 trapnr, signr) == NOTIFY_STOP) { \
206 exception_exit(regs); \
200 return; \ 207 return; \
208 } \
201 conditional_sti(regs); \ 209 conditional_sti(regs); \
202 do_trap(trapnr, signr, str, regs, error_code, &info); \ 210 do_trap(trapnr, signr, str, regs, error_code, &info); \
211 exception_exit(regs); \
203} 212}
204 213
205DO_ERROR_INFO(X86_TRAP_DE, SIGFPE, "divide error", divide_error, FPE_INTDIV, 214DO_ERROR_INFO(X86_TRAP_DE, SIGFPE, "divide error", divide_error, FPE_INTDIV,
@@ -222,12 +231,14 @@ DO_ERROR_INFO(X86_TRAP_AC, SIGBUS, "alignment check", alignment_check,
222/* Runs on IST stack */ 231/* Runs on IST stack */
223dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code) 232dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code)
224{ 233{
234 exception_enter(regs);
225 if (notify_die(DIE_TRAP, "stack segment", regs, error_code, 235 if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
226 X86_TRAP_SS, SIGBUS) == NOTIFY_STOP) 236 X86_TRAP_SS, SIGBUS) != NOTIFY_STOP) {
227 return; 237 preempt_conditional_sti(regs);
228 preempt_conditional_sti(regs); 238 do_trap(X86_TRAP_SS, SIGBUS, "stack segment", regs, error_code, NULL);
229 do_trap(X86_TRAP_SS, SIGBUS, "stack segment", regs, error_code, NULL); 239 preempt_conditional_cli(regs);
230 preempt_conditional_cli(regs); 240 }
241 exception_exit(regs);
231} 242}
232 243
233dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code) 244dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
@@ -235,6 +246,7 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
235 static const char str[] = "double fault"; 246 static const char str[] = "double fault";
236 struct task_struct *tsk = current; 247 struct task_struct *tsk = current;
237 248
249 exception_enter(regs);
238 /* Return not checked because double check cannot be ignored */ 250 /* Return not checked because double check cannot be ignored */
239 notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV); 251 notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV);
240 252
@@ -255,16 +267,29 @@ do_general_protection(struct pt_regs *regs, long error_code)
255{ 267{
256 struct task_struct *tsk; 268 struct task_struct *tsk;
257 269
270 exception_enter(regs);
258 conditional_sti(regs); 271 conditional_sti(regs);
259 272
260#ifdef CONFIG_X86_32 273#ifdef CONFIG_X86_32
261 if (regs->flags & X86_VM_MASK) 274 if (regs->flags & X86_VM_MASK) {
262 goto gp_in_vm86; 275 local_irq_enable();
276 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
277 goto exit;
278 }
263#endif 279#endif
264 280
265 tsk = current; 281 tsk = current;
266 if (!user_mode(regs)) 282 if (!user_mode(regs)) {
267 goto gp_in_kernel; 283 if (fixup_exception(regs))
284 goto exit;
285
286 tsk->thread.error_code = error_code;
287 tsk->thread.trap_nr = X86_TRAP_GP;
288 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
289 X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
290 die("general protection fault", regs, error_code);
291 goto exit;
292 }
268 293
269 tsk->thread.error_code = error_code; 294 tsk->thread.error_code = error_code;
270 tsk->thread.trap_nr = X86_TRAP_GP; 295 tsk->thread.trap_nr = X86_TRAP_GP;
@@ -279,25 +304,8 @@ do_general_protection(struct pt_regs *regs, long error_code)
279 } 304 }
280 305
281 force_sig(SIGSEGV, tsk); 306 force_sig(SIGSEGV, tsk);
282 return; 307exit:
283 308 exception_exit(regs);
284#ifdef CONFIG_X86_32
285gp_in_vm86:
286 local_irq_enable();
287 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
288 return;
289#endif
290
291gp_in_kernel:
292 if (fixup_exception(regs))
293 return;
294
295 tsk->thread.error_code = error_code;
296 tsk->thread.trap_nr = X86_TRAP_GP;
297 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
298 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
299 return;
300 die("general protection fault", regs, error_code);
301} 309}
302 310
303/* May run on IST stack. */ 311/* May run on IST stack. */
@@ -312,15 +320,16 @@ dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_co
312 ftrace_int3_handler(regs)) 320 ftrace_int3_handler(regs))
313 return; 321 return;
314#endif 322#endif
323 exception_enter(regs);
315#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP 324#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
316 if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP, 325 if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
317 SIGTRAP) == NOTIFY_STOP) 326 SIGTRAP) == NOTIFY_STOP)
318 return; 327 goto exit;
319#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ 328#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
320 329
321 if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP, 330 if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
322 SIGTRAP) == NOTIFY_STOP) 331 SIGTRAP) == NOTIFY_STOP)
323 return; 332 goto exit;
324 333
325 /* 334 /*
326 * Let others (NMI) know that the debug stack is in use 335 * Let others (NMI) know that the debug stack is in use
@@ -331,6 +340,8 @@ dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_co
331 do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL); 340 do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
332 preempt_conditional_cli(regs); 341 preempt_conditional_cli(regs);
333 debug_stack_usage_dec(); 342 debug_stack_usage_dec();
343exit:
344 exception_exit(regs);
334} 345}
335 346
336#ifdef CONFIG_X86_64 347#ifdef CONFIG_X86_64
@@ -391,6 +402,8 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
391 unsigned long dr6; 402 unsigned long dr6;
392 int si_code; 403 int si_code;
393 404
405 exception_enter(regs);
406
394 get_debugreg(dr6, 6); 407 get_debugreg(dr6, 6);
395 408
396 /* Filter out all the reserved bits which are preset to 1 */ 409 /* Filter out all the reserved bits which are preset to 1 */
@@ -406,7 +419,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
406 419
407 /* Catch kmemcheck conditions first of all! */ 420 /* Catch kmemcheck conditions first of all! */
408 if ((dr6 & DR_STEP) && kmemcheck_trap(regs)) 421 if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
409 return; 422 goto exit;
410 423
411 /* DR6 may or may not be cleared by the CPU */ 424 /* DR6 may or may not be cleared by the CPU */
412 set_debugreg(0, 6); 425 set_debugreg(0, 6);
@@ -421,7 +434,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
421 434
422 if (notify_die(DIE_DEBUG, "debug", regs, PTR_ERR(&dr6), error_code, 435 if (notify_die(DIE_DEBUG, "debug", regs, PTR_ERR(&dr6), error_code,
423 SIGTRAP) == NOTIFY_STOP) 436 SIGTRAP) == NOTIFY_STOP)
424 return; 437 goto exit;
425 438
426 /* 439 /*
427 * Let others (NMI) know that the debug stack is in use 440 * Let others (NMI) know that the debug stack is in use
@@ -437,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
437 X86_TRAP_DB); 450 X86_TRAP_DB);
438 preempt_conditional_cli(regs); 451 preempt_conditional_cli(regs);
439 debug_stack_usage_dec(); 452 debug_stack_usage_dec();
440 return; 453 goto exit;
441 } 454 }
442 455
443 /* 456 /*
@@ -458,7 +471,8 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
458 preempt_conditional_cli(regs); 471 preempt_conditional_cli(regs);
459 debug_stack_usage_dec(); 472 debug_stack_usage_dec();
460 473
461 return; 474exit:
475 exception_exit(regs);
462} 476}
463 477
464/* 478/*
@@ -555,14 +569,17 @@ dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code)
555#ifdef CONFIG_X86_32 569#ifdef CONFIG_X86_32
556 ignore_fpu_irq = 1; 570 ignore_fpu_irq = 1;
557#endif 571#endif
558 572 exception_enter(regs);
559 math_error(regs, error_code, X86_TRAP_MF); 573 math_error(regs, error_code, X86_TRAP_MF);
574 exception_exit(regs);
560} 575}
561 576
562dotraplinkage void 577dotraplinkage void
563do_simd_coprocessor_error(struct pt_regs *regs, long error_code) 578do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
564{ 579{
580 exception_enter(regs);
565 math_error(regs, error_code, X86_TRAP_XF); 581 math_error(regs, error_code, X86_TRAP_XF);
582 exception_exit(regs);
566} 583}
567 584
568dotraplinkage void 585dotraplinkage void
@@ -629,6 +646,7 @@ EXPORT_SYMBOL_GPL(math_state_restore);
629dotraplinkage void __kprobes 646dotraplinkage void __kprobes
630do_device_not_available(struct pt_regs *regs, long error_code) 647do_device_not_available(struct pt_regs *regs, long error_code)
631{ 648{
649 exception_enter(regs);
632#ifdef CONFIG_MATH_EMULATION 650#ifdef CONFIG_MATH_EMULATION
633 if (read_cr0() & X86_CR0_EM) { 651 if (read_cr0() & X86_CR0_EM) {
634 struct math_emu_info info = { }; 652 struct math_emu_info info = { };
@@ -637,6 +655,7 @@ do_device_not_available(struct pt_regs *regs, long error_code)
637 655
638 info.regs = regs; 656 info.regs = regs;
639 math_emulate(&info); 657 math_emulate(&info);
658 exception_exit(regs);
640 return; 659 return;
641 } 660 }
642#endif 661#endif
@@ -644,12 +663,15 @@ do_device_not_available(struct pt_regs *regs, long error_code)
644#ifdef CONFIG_X86_32 663#ifdef CONFIG_X86_32
645 conditional_sti(regs); 664 conditional_sti(regs);
646#endif 665#endif
666 exception_exit(regs);
647} 667}
648 668
649#ifdef CONFIG_X86_32 669#ifdef CONFIG_X86_32
650dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) 670dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
651{ 671{
652 siginfo_t info; 672 siginfo_t info;
673
674 exception_enter(regs);
653 local_irq_enable(); 675 local_irq_enable();
654 676
655 info.si_signo = SIGILL; 677 info.si_signo = SIGILL;
@@ -657,10 +679,11 @@ dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
657 info.si_code = ILL_BADSTK; 679 info.si_code = ILL_BADSTK;
658 info.si_addr = NULL; 680 info.si_addr = NULL;
659 if (notify_die(DIE_TRAP, "iret exception", regs, error_code, 681 if (notify_die(DIE_TRAP, "iret exception", regs, error_code,
660 X86_TRAP_IRET, SIGILL) == NOTIFY_STOP) 682 X86_TRAP_IRET, SIGILL) != NOTIFY_STOP) {
661 return; 683 do_trap(X86_TRAP_IRET, SIGILL, "iret exception", regs, error_code,
662 do_trap(X86_TRAP_IRET, SIGILL, "iret exception", regs, error_code, 684 &info);
663 &info); 685 }
686 exception_exit(regs);
664} 687}
665#endif 688#endif
666 689
diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index e498b18f010c..9fc9aa7ac703 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -318,7 +318,7 @@ static void pic_ioport_write(void *opaque, u32 addr, u32 val)
318 if (val & 0x10) { 318 if (val & 0x10) {
319 u8 edge_irr = s->irr & ~s->elcr; 319 u8 edge_irr = s->irr & ~s->elcr;
320 int i; 320 int i;
321 bool found; 321 bool found = false;
322 struct kvm_vcpu *vcpu; 322 struct kvm_vcpu *vcpu;
323 323
324 s->init4 = val & 1; 324 s->init4 = val & 1;
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index c00f03de1b79..b1eb202ee76a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3619,6 +3619,7 @@ static void seg_setup(int seg)
3619 3619
3620static int alloc_apic_access_page(struct kvm *kvm) 3620static int alloc_apic_access_page(struct kvm *kvm)
3621{ 3621{
3622 struct page *page;
3622 struct kvm_userspace_memory_region kvm_userspace_mem; 3623 struct kvm_userspace_memory_region kvm_userspace_mem;
3623 int r = 0; 3624 int r = 0;
3624 3625
@@ -3633,7 +3634,13 @@ static int alloc_apic_access_page(struct kvm *kvm)
3633 if (r) 3634 if (r)
3634 goto out; 3635 goto out;
3635 3636
3636 kvm->arch.apic_access_page = gfn_to_page(kvm, 0xfee00); 3637 page = gfn_to_page(kvm, 0xfee00);
3638 if (is_error_page(page)) {
3639 r = -EFAULT;
3640 goto out;
3641 }
3642
3643 kvm->arch.apic_access_page = page;
3637out: 3644out:
3638 mutex_unlock(&kvm->slots_lock); 3645 mutex_unlock(&kvm->slots_lock);
3639 return r; 3646 return r;
@@ -3641,6 +3648,7 @@ out:
3641 3648
3642static int alloc_identity_pagetable(struct kvm *kvm) 3649static int alloc_identity_pagetable(struct kvm *kvm)
3643{ 3650{
3651 struct page *page;
3644 struct kvm_userspace_memory_region kvm_userspace_mem; 3652 struct kvm_userspace_memory_region kvm_userspace_mem;
3645 int r = 0; 3653 int r = 0;
3646 3654
@@ -3656,8 +3664,13 @@ static int alloc_identity_pagetable(struct kvm *kvm)
3656 if (r) 3664 if (r)
3657 goto out; 3665 goto out;
3658 3666
3659 kvm->arch.ept_identity_pagetable = gfn_to_page(kvm, 3667 page = gfn_to_page(kvm, kvm->arch.ept_identity_map_addr >> PAGE_SHIFT);
3660 kvm->arch.ept_identity_map_addr >> PAGE_SHIFT); 3668 if (is_error_page(page)) {
3669 r = -EFAULT;
3670 goto out;
3671 }
3672
3673 kvm->arch.ept_identity_pagetable = page;
3661out: 3674out:
3662 mutex_unlock(&kvm->slots_lock); 3675 mutex_unlock(&kvm->slots_lock);
3663 return r; 3676 return r;
@@ -6575,7 +6588,7 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
6575 /* Exposing INVPCID only when PCID is exposed */ 6588 /* Exposing INVPCID only when PCID is exposed */
6576 best = kvm_find_cpuid_entry(vcpu, 0x7, 0); 6589 best = kvm_find_cpuid_entry(vcpu, 0x7, 0);
6577 if (vmx_invpcid_supported() && 6590 if (vmx_invpcid_supported() &&
6578 best && (best->ecx & bit(X86_FEATURE_INVPCID)) && 6591 best && (best->ebx & bit(X86_FEATURE_INVPCID)) &&
6579 guest_cpuid_has_pcid(vcpu)) { 6592 guest_cpuid_has_pcid(vcpu)) {
6580 exec_control |= SECONDARY_EXEC_ENABLE_INVPCID; 6593 exec_control |= SECONDARY_EXEC_ENABLE_INVPCID;
6581 vmcs_write32(SECONDARY_VM_EXEC_CONTROL, 6594 vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
@@ -6585,7 +6598,7 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
6585 vmcs_write32(SECONDARY_VM_EXEC_CONTROL, 6598 vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
6586 exec_control); 6599 exec_control);
6587 if (best) 6600 if (best)
6588 best->ecx &= ~bit(X86_FEATURE_INVPCID); 6601 best->ebx &= ~bit(X86_FEATURE_INVPCID);
6589 } 6602 }
6590} 6603}
6591 6604
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 148ed666e311..2966c847d489 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5113,17 +5113,20 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu)
5113 !kvm_event_needs_reinjection(vcpu); 5113 !kvm_event_needs_reinjection(vcpu);
5114} 5114}
5115 5115
5116static void vapic_enter(struct kvm_vcpu *vcpu) 5116static int vapic_enter(struct kvm_vcpu *vcpu)
5117{ 5117{
5118 struct kvm_lapic *apic = vcpu->arch.apic; 5118 struct kvm_lapic *apic = vcpu->arch.apic;
5119 struct page *page; 5119 struct page *page;
5120 5120
5121 if (!apic || !apic->vapic_addr) 5121 if (!apic || !apic->vapic_addr)
5122 return; 5122 return 0;
5123 5123
5124 page = gfn_to_page(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT); 5124 page = gfn_to_page(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT);
5125 if (is_error_page(page))
5126 return -EFAULT;
5125 5127
5126 vcpu->arch.apic->vapic_page = page; 5128 vcpu->arch.apic->vapic_page = page;
5129 return 0;
5127} 5130}
5128 5131
5129static void vapic_exit(struct kvm_vcpu *vcpu) 5132static void vapic_exit(struct kvm_vcpu *vcpu)
@@ -5430,7 +5433,11 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
5430 } 5433 }
5431 5434
5432 vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); 5435 vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
5433 vapic_enter(vcpu); 5436 r = vapic_enter(vcpu);
5437 if (r) {
5438 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
5439 return r;
5440 }
5434 5441
5435 r = 1; 5442 r = 1;
5436 while (r > 0) { 5443 while (r > 0) {
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 76dcd9d8e0bc..7dde46d68a25 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -18,6 +18,7 @@
18#include <asm/pgalloc.h> /* pgd_*(), ... */ 18#include <asm/pgalloc.h> /* pgd_*(), ... */
19#include <asm/kmemcheck.h> /* kmemcheck_*(), ... */ 19#include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
20#include <asm/fixmap.h> /* VSYSCALL_START */ 20#include <asm/fixmap.h> /* VSYSCALL_START */
21#include <asm/rcu.h> /* exception_enter(), ... */
21 22
22/* 23/*
23 * Page fault error code bits: 24 * Page fault error code bits:
@@ -1000,8 +1001,8 @@ static int fault_in_kernel_space(unsigned long address)
1000 * and the problem, and then passes it off to one of the appropriate 1001 * and the problem, and then passes it off to one of the appropriate
1001 * routines. 1002 * routines.
1002 */ 1003 */
1003dotraplinkage void __kprobes 1004static void __kprobes
1004do_page_fault(struct pt_regs *regs, unsigned long error_code) 1005__do_page_fault(struct pt_regs *regs, unsigned long error_code)
1005{ 1006{
1006 struct vm_area_struct *vma; 1007 struct vm_area_struct *vma;
1007 struct task_struct *tsk; 1008 struct task_struct *tsk;
@@ -1209,3 +1210,11 @@ good_area:
1209 1210
1210 up_read(&mm->mmap_sem); 1211 up_read(&mm->mmap_sem);
1211} 1212}
1213
1214dotraplinkage void __kprobes
1215do_page_fault(struct pt_regs *regs, unsigned long error_code)
1216{
1217 exception_enter(regs);
1218 __do_page_fault(regs, error_code);
1219 exception_exit(regs);
1220}
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index e0e6990723e9..ab1f6a93b527 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -319,7 +319,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
319 */ 319 */
320int devmem_is_allowed(unsigned long pagenr) 320int devmem_is_allowed(unsigned long pagenr)
321{ 321{
322 if (pagenr <= 256) 322 if (pagenr < 256)
323 return 1; 323 return 1;
324 if (iomem_is_exclusive(pagenr << PAGE_SHIFT)) 324 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
325 return 0; 325 return 0;
diff --git a/arch/x86/um/Kconfig b/arch/x86/um/Kconfig
index 9926e11a772d..aeaff8bef2f1 100644
--- a/arch/x86/um/Kconfig
+++ b/arch/x86/um/Kconfig
@@ -21,6 +21,7 @@ config 64BIT
21config X86_32 21config X86_32
22 def_bool !64BIT 22 def_bool !64BIT
23 select HAVE_AOUT 23 select HAVE_AOUT
24 select ARCH_WANT_IPC_PARSE_VERSION
24 25
25config X86_64 26config X86_64
26 def_bool 64BIT 27 def_bool 64BIT
diff --git a/arch/x86/um/shared/sysdep/kernel-offsets.h b/arch/x86/um/shared/sysdep/kernel-offsets.h
index 5868526b5eef..46a9df99f3c5 100644
--- a/arch/x86/um/shared/sysdep/kernel-offsets.h
+++ b/arch/x86/um/shared/sysdep/kernel-offsets.h
@@ -7,9 +7,6 @@
7#define DEFINE(sym, val) \ 7#define DEFINE(sym, val) \
8 asm volatile("\n->" #sym " %0 " #val : : "i" (val)) 8 asm volatile("\n->" #sym " %0 " #val : : "i" (val))
9 9
10#define STR(x) #x
11#define DEFINE_STR(sym, val) asm volatile("\n->" #sym " " STR(val) " " #val: : )
12
13#define BLANK() asm volatile("\n->" : : ) 10#define BLANK() asm volatile("\n->" : : )
14 11
15#define OFFSET(sym, str, mem) \ 12#define OFFSET(sym, str, mem) \
diff --git a/arch/x86/um/shared/sysdep/syscalls.h b/arch/x86/um/shared/sysdep/syscalls.h
index bd9a89b67e41..ca255a805ed9 100644
--- a/arch/x86/um/shared/sysdep/syscalls.h
+++ b/arch/x86/um/shared/sysdep/syscalls.h
@@ -1,3 +1,5 @@
1extern long sys_clone(unsigned long clone_flags, unsigned long newsp,
2 void __user *parent_tid, void __user *child_tid);
1#ifdef __i386__ 3#ifdef __i386__
2#include "syscalls_32.h" 4#include "syscalls_32.h"
3#else 5#else
diff --git a/arch/x86/um/signal.c b/arch/x86/um/signal.c
index a508cea13503..ba7363ecf896 100644
--- a/arch/x86/um/signal.c
+++ b/arch/x86/um/signal.c
@@ -416,9 +416,6 @@ int setup_signal_stack_sc(unsigned long stack_top, int sig,
416 PT_REGS_AX(regs) = (unsigned long) sig; 416 PT_REGS_AX(regs) = (unsigned long) sig;
417 PT_REGS_DX(regs) = (unsigned long) 0; 417 PT_REGS_DX(regs) = (unsigned long) 0;
418 PT_REGS_CX(regs) = (unsigned long) 0; 418 PT_REGS_CX(regs) = (unsigned long) 0;
419
420 if ((current->ptrace & PT_DTRACE) && (current->ptrace & PT_PTRACED))
421 ptrace_notify(SIGTRAP);
422 return 0; 419 return 0;
423} 420}
424 421
@@ -466,9 +463,6 @@ int setup_signal_stack_si(unsigned long stack_top, int sig,
466 PT_REGS_AX(regs) = (unsigned long) sig; 463 PT_REGS_AX(regs) = (unsigned long) sig;
467 PT_REGS_DX(regs) = (unsigned long) &frame->info; 464 PT_REGS_DX(regs) = (unsigned long) &frame->info;
468 PT_REGS_CX(regs) = (unsigned long) &frame->uc; 465 PT_REGS_CX(regs) = (unsigned long) &frame->uc;
469
470 if ((current->ptrace & PT_DTRACE) && (current->ptrace & PT_PTRACED))
471 ptrace_notify(SIGTRAP);
472 return 0; 466 return 0;
473} 467}
474 468
diff --git a/arch/x86/um/sys_call_table_32.c b/arch/x86/um/sys_call_table_32.c
index 68d1dc91b37b..b5408cecac6c 100644
--- a/arch/x86/um/sys_call_table_32.c
+++ b/arch/x86/um/sys_call_table_32.c
@@ -28,7 +28,7 @@
28#define ptregs_execve sys_execve 28#define ptregs_execve sys_execve
29#define ptregs_iopl sys_iopl 29#define ptregs_iopl sys_iopl
30#define ptregs_vm86old sys_vm86old 30#define ptregs_vm86old sys_vm86old
31#define ptregs_clone sys_clone 31#define ptregs_clone i386_clone
32#define ptregs_vm86 sys_vm86 32#define ptregs_vm86 sys_vm86
33#define ptregs_sigaltstack sys_sigaltstack 33#define ptregs_sigaltstack sys_sigaltstack
34#define ptregs_vfork sys_vfork 34#define ptregs_vfork sys_vfork
diff --git a/arch/x86/um/syscalls_32.c b/arch/x86/um/syscalls_32.c
index b853e8600b9d..db444c7218fe 100644
--- a/arch/x86/um/syscalls_32.c
+++ b/arch/x86/um/syscalls_32.c
@@ -3,37 +3,24 @@
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include "linux/sched.h" 6#include <linux/syscalls.h>
7#include "linux/shm.h" 7#include <sysdep/syscalls.h>
8#include "linux/ipc.h"
9#include "linux/syscalls.h"
10#include "asm/mman.h"
11#include "asm/uaccess.h"
12#include "asm/unistd.h"
13 8
14/* 9/*
15 * The prototype on i386 is: 10 * The prototype on i386 is:
16 * 11 *
17 * int clone(int flags, void * child_stack, int * parent_tidptr, struct user_desc * newtls, int * child_tidptr) 12 * int clone(int flags, void * child_stack, int * parent_tidptr, struct user_desc * newtls
18 * 13 *
19 * and the "newtls" arg. on i386 is read by copy_thread directly from the 14 * and the "newtls" arg. on i386 is read by copy_thread directly from the
20 * register saved on the stack. 15 * register saved on the stack.
21 */ 16 */
22long sys_clone(unsigned long clone_flags, unsigned long newsp, 17long i386_clone(unsigned long clone_flags, unsigned long newsp,
23 int __user *parent_tid, void *newtls, int __user *child_tid) 18 int __user *parent_tid, void *newtls, int __user *child_tid)
24{ 19{
25 long ret; 20 return sys_clone(clone_flags, newsp, parent_tid, child_tid);
26
27 if (!newsp)
28 newsp = UPT_SP(&current->thread.regs.regs);
29
30 current->thread.forking = 1;
31 ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
32 child_tid);
33 current->thread.forking = 0;
34 return ret;
35} 21}
36 22
23
37long sys_sigaction(int sig, const struct old_sigaction __user *act, 24long sys_sigaction(int sig, const struct old_sigaction __user *act,
38 struct old_sigaction __user *oact) 25 struct old_sigaction __user *oact)
39{ 26{
diff --git a/arch/x86/um/syscalls_64.c b/arch/x86/um/syscalls_64.c
index f3d82bb6e15a..adb08eb5c22a 100644
--- a/arch/x86/um/syscalls_64.c
+++ b/arch/x86/um/syscalls_64.c
@@ -5,12 +5,9 @@
5 * Licensed under the GPL 5 * Licensed under the GPL
6 */ 6 */
7 7
8#include "linux/linkage.h" 8#include <linux/sched.h>
9#include "linux/personality.h" 9#include <asm/prctl.h> /* XXX This should get the constants from libc */
10#include "linux/utsname.h" 10#include <os.h>
11#include "asm/prctl.h" /* XXX This should get the constants from libc */
12#include "asm/uaccess.h"
13#include "os.h"
14 11
15long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr) 12long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr)
16{ 13{
@@ -79,20 +76,6 @@ long sys_arch_prctl(int code, unsigned long addr)
79 return arch_prctl(current, code, (unsigned long __user *) addr); 76 return arch_prctl(current, code, (unsigned long __user *) addr);
80} 77}
81 78
82long sys_clone(unsigned long clone_flags, unsigned long newsp,
83 void __user *parent_tid, void __user *child_tid)
84{
85 long ret;
86
87 if (!newsp)
88 newsp = UPT_SP(&current->thread.regs.regs);
89 current->thread.forking = 1;
90 ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
91 child_tid);
92 current->thread.forking = 0;
93 return ret;
94}
95
96void arch_switch_to(struct task_struct *to) 79void arch_switch_to(struct task_struct *to)
97{ 80{
98 if ((to->thread.arch.fs == 0) || (to->mm == NULL)) 81 if ((to->thread.arch.fs == 0) || (to->mm == NULL))
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 9642d4a38602..1fbe75a95f15 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1452,6 +1452,10 @@ asmlinkage void __init xen_start_kernel(void)
1452 pci_request_acs(); 1452 pci_request_acs();
1453 1453
1454 xen_acpi_sleep_register(); 1454 xen_acpi_sleep_register();
1455
1456 /* Avoid searching for BIOS MP tables */
1457 x86_init.mpparse.find_smp_config = x86_init_noop;
1458 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
1455 } 1459 }
1456#ifdef CONFIG_PCI 1460#ifdef CONFIG_PCI
1457 /* PCI BIOS service won't work from a PV guest. */ 1461 /* PCI BIOS service won't work from a PV guest. */
diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c
index 76ba0e97e530..72213da605f5 100644
--- a/arch/x86/xen/p2m.c
+++ b/arch/x86/xen/p2m.c
@@ -828,9 +828,6 @@ int m2p_add_override(unsigned long mfn, struct page *page,
828 828
829 xen_mc_issue(PARAVIRT_LAZY_MMU); 829 xen_mc_issue(PARAVIRT_LAZY_MMU);
830 } 830 }
831 /* let's use dev_bus_addr to record the old mfn instead */
832 kmap_op->dev_bus_addr = page->index;
833 page->index = (unsigned long) kmap_op;
834 } 831 }
835 spin_lock_irqsave(&m2p_override_lock, flags); 832 spin_lock_irqsave(&m2p_override_lock, flags);
836 list_add(&page->lru, &m2p_overrides[mfn_hash(mfn)]); 833 list_add(&page->lru, &m2p_overrides[mfn_hash(mfn)]);
@@ -857,7 +854,8 @@ int m2p_add_override(unsigned long mfn, struct page *page,
857 return 0; 854 return 0;
858} 855}
859EXPORT_SYMBOL_GPL(m2p_add_override); 856EXPORT_SYMBOL_GPL(m2p_add_override);
860int m2p_remove_override(struct page *page, bool clear_pte) 857int m2p_remove_override(struct page *page,
858 struct gnttab_map_grant_ref *kmap_op)
861{ 859{
862 unsigned long flags; 860 unsigned long flags;
863 unsigned long mfn; 861 unsigned long mfn;
@@ -887,10 +885,8 @@ int m2p_remove_override(struct page *page, bool clear_pte)
887 WARN_ON(!PagePrivate(page)); 885 WARN_ON(!PagePrivate(page));
888 ClearPagePrivate(page); 886 ClearPagePrivate(page);
889 887
890 if (clear_pte) { 888 set_phys_to_machine(pfn, page->index);
891 struct gnttab_map_grant_ref *map_op = 889 if (kmap_op != NULL) {
892 (struct gnttab_map_grant_ref *) page->index;
893 set_phys_to_machine(pfn, map_op->dev_bus_addr);
894 if (!PageHighMem(page)) { 890 if (!PageHighMem(page)) {
895 struct multicall_space mcs; 891 struct multicall_space mcs;
896 struct gnttab_unmap_grant_ref *unmap_op; 892 struct gnttab_unmap_grant_ref *unmap_op;
@@ -902,13 +898,13 @@ int m2p_remove_override(struct page *page, bool clear_pte)
902 * issued. In this case handle is going to -1 because 898 * issued. In this case handle is going to -1 because
903 * it hasn't been modified yet. 899 * it hasn't been modified yet.
904 */ 900 */
905 if (map_op->handle == -1) 901 if (kmap_op->handle == -1)
906 xen_mc_flush(); 902 xen_mc_flush();
907 /* 903 /*
908 * Now if map_op->handle is negative it means that the 904 * Now if kmap_op->handle is negative it means that the
909 * hypercall actually returned an error. 905 * hypercall actually returned an error.
910 */ 906 */
911 if (map_op->handle == GNTST_general_error) { 907 if (kmap_op->handle == GNTST_general_error) {
912 printk(KERN_WARNING "m2p_remove_override: " 908 printk(KERN_WARNING "m2p_remove_override: "
913 "pfn %lx mfn %lx, failed to modify kernel mappings", 909 "pfn %lx mfn %lx, failed to modify kernel mappings",
914 pfn, mfn); 910 pfn, mfn);
@@ -918,8 +914,8 @@ int m2p_remove_override(struct page *page, bool clear_pte)
918 mcs = xen_mc_entry( 914 mcs = xen_mc_entry(
919 sizeof(struct gnttab_unmap_grant_ref)); 915 sizeof(struct gnttab_unmap_grant_ref));
920 unmap_op = mcs.args; 916 unmap_op = mcs.args;
921 unmap_op->host_addr = map_op->host_addr; 917 unmap_op->host_addr = kmap_op->host_addr;
922 unmap_op->handle = map_op->handle; 918 unmap_op->handle = kmap_op->handle;
923 unmap_op->dev_bus_addr = 0; 919 unmap_op->dev_bus_addr = 0;
924 920
925 MULTI_grant_table_op(mcs.mc, 921 MULTI_grant_table_op(mcs.mc,
@@ -930,10 +926,9 @@ int m2p_remove_override(struct page *page, bool clear_pte)
930 set_pte_at(&init_mm, address, ptep, 926 set_pte_at(&init_mm, address, ptep,
931 pfn_pte(pfn, PAGE_KERNEL)); 927 pfn_pte(pfn, PAGE_KERNEL));
932 __flush_tlb_single(address); 928 __flush_tlb_single(address);
933 map_op->host_addr = 0; 929 kmap_op->host_addr = 0;
934 } 930 }
935 } else 931 }
936 set_phys_to_machine(pfn, page->index);
937 932
938 /* p2m(m2p(mfn)) == FOREIGN_FRAME(mfn): the mfn is already present 933 /* p2m(m2p(mfn)) == FOREIGN_FRAME(mfn): the mfn is already present
939 * somewhere in this domain, even before being added to the 934 * somewhere in this domain, even before being added to the
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index d11ca11d14fc..e2d62d697b5d 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -17,6 +17,7 @@
17#include <asm/e820.h> 17#include <asm/e820.h>
18#include <asm/setup.h> 18#include <asm/setup.h>
19#include <asm/acpi.h> 19#include <asm/acpi.h>
20#include <asm/numa.h>
20#include <asm/xen/hypervisor.h> 21#include <asm/xen/hypervisor.h>
21#include <asm/xen/hypercall.h> 22#include <asm/xen/hypercall.h>
22 23
@@ -544,4 +545,7 @@ void __init xen_arch_setup(void)
544 disable_cpufreq(); 545 disable_cpufreq();
545 WARN_ON(set_pm_idle_to_default()); 546 WARN_ON(set_pm_idle_to_default());
546 fiddle_vdso(); 547 fiddle_vdso();
548#ifdef CONFIG_NUMA
549 numa_off = 1;
550#endif
547} 551}
diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c
index 2c8d6a3d250a..bc44311aa18c 100644
--- a/arch/xtensa/kernel/process.c
+++ b/arch/xtensa/kernel/process.c
@@ -31,6 +31,7 @@
31#include <linux/mqueue.h> 31#include <linux/mqueue.h>
32#include <linux/fs.h> 32#include <linux/fs.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/rcupdate.h>
34 35
35#include <asm/pgtable.h> 36#include <asm/pgtable.h>
36#include <asm/uaccess.h> 37#include <asm/uaccess.h>
@@ -110,8 +111,10 @@ void cpu_idle(void)
110 111
111 /* endless idle loop with no priority at all */ 112 /* endless idle loop with no priority at all */
112 while (1) { 113 while (1) {
114 rcu_idle_enter();
113 while (!need_resched()) 115 while (!need_resched())
114 platform_idle(); 116 platform_idle();
117 rcu_idle_exit();
115 schedule_preempt_disabled(); 118 schedule_preempt_disabled();
116 } 119 }
117} 120}
diff --git a/block/blk-core.c b/block/blk-core.c
index 4b4dbdfbca89..ee3cb3a5e278 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -2254,9 +2254,11 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
2254 error_type = "I/O"; 2254 error_type = "I/O";
2255 break; 2255 break;
2256 } 2256 }
2257 printk(KERN_ERR "end_request: %s error, dev %s, sector %llu\n", 2257 printk_ratelimited(KERN_ERR "end_request: %s error, dev %s, sector %llu\n",
2258 error_type, req->rq_disk ? req->rq_disk->disk_name : "?", 2258 error_type, req->rq_disk ?
2259 (unsigned long long)blk_rq_pos(req)); 2259 req->rq_disk->disk_name : "?",
2260 (unsigned long long)blk_rq_pos(req));
2261
2260 } 2262 }
2261 2263
2262 blk_account_io_completion(req, nr_bytes); 2264 blk_account_io_completion(req, nr_bytes);
diff --git a/block/ioctl.c b/block/ioctl.c
index 4476e0e85d16..4a85096f5410 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -41,7 +41,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
41 sizeof(long long) > sizeof(long)) { 41 sizeof(long long) > sizeof(long)) {
42 long pstart = start, plength = length; 42 long pstart = start, plength = length;
43 if (pstart != start || plength != length 43 if (pstart != start || plength != length
44 || pstart < 0 || plength < 0) 44 || pstart < 0 || plength < 0 || partno > 65535)
45 return -EINVAL; 45 return -EINVAL;
46 } 46 }
47 47
diff --git a/crypto/authenc.c b/crypto/authenc.c
index 5ef7ba6b6a76..d0583a4489e6 100644
--- a/crypto/authenc.c
+++ b/crypto/authenc.c
@@ -336,7 +336,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
336 cryptlen += ivsize; 336 cryptlen += ivsize;
337 } 337 }
338 338
339 if (sg_is_last(assoc)) { 339 if (req->assoclen && sg_is_last(assoc)) {
340 authenc_ahash_fn = crypto_authenc_ahash; 340 authenc_ahash_fn = crypto_authenc_ahash;
341 sg_init_table(asg, 2); 341 sg_init_table(asg, 2);
342 sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset); 342 sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset);
@@ -490,7 +490,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
490 cryptlen += ivsize; 490 cryptlen += ivsize;
491 } 491 }
492 492
493 if (sg_is_last(assoc)) { 493 if (req->assoclen && sg_is_last(assoc)) {
494 authenc_ahash_fn = crypto_authenc_ahash; 494 authenc_ahash_fn = crypto_authenc_ahash;
495 sg_init_table(asg, 2); 495 sg_init_table(asg, 2);
496 sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset); 496 sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset);
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 9628652e080c..e0596954290b 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -237,6 +237,16 @@ static int __acpi_bus_get_power(struct acpi_device *device, int *state)
237 } else if (result == ACPI_STATE_D3_HOT) { 237 } else if (result == ACPI_STATE_D3_HOT) {
238 result = ACPI_STATE_D3; 238 result = ACPI_STATE_D3;
239 } 239 }
240
241 /*
242 * If we were unsure about the device parent's power state up to this
243 * point, the fact that the device is in D0 implies that the parent has
244 * to be in D0 too.
245 */
246 if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN
247 && result == ACPI_STATE_D0)
248 device->parent->power.state = ACPI_STATE_D0;
249
240 *state = result; 250 *state = result;
241 251
242 out: 252 out:
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index fc1803414629..40e38a06ba85 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -107,6 +107,7 @@ struct acpi_power_resource {
107 107
108 /* List of devices relying on this power resource */ 108 /* List of devices relying on this power resource */
109 struct acpi_power_resource_device *devices; 109 struct acpi_power_resource_device *devices;
110 struct mutex devices_lock;
110}; 111};
111 112
112static struct list_head acpi_power_resource_list; 113static struct list_head acpi_power_resource_list;
@@ -225,7 +226,6 @@ static void acpi_power_on_device(struct acpi_power_managed_device *device)
225 226
226static int __acpi_power_on(struct acpi_power_resource *resource) 227static int __acpi_power_on(struct acpi_power_resource *resource)
227{ 228{
228 struct acpi_power_resource_device *device_list = resource->devices;
229 acpi_status status = AE_OK; 229 acpi_status status = AE_OK;
230 230
231 status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL); 231 status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
@@ -238,19 +238,15 @@ static int __acpi_power_on(struct acpi_power_resource *resource)
238 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n", 238 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
239 resource->name)); 239 resource->name));
240 240
241 while (device_list) {
242 acpi_power_on_device(device_list->device);
243
244 device_list = device_list->next;
245 }
246
247 return 0; 241 return 0;
248} 242}
249 243
250static int acpi_power_on(acpi_handle handle) 244static int acpi_power_on(acpi_handle handle)
251{ 245{
252 int result = 0; 246 int result = 0;
247 bool resume_device = false;
253 struct acpi_power_resource *resource = NULL; 248 struct acpi_power_resource *resource = NULL;
249 struct acpi_power_resource_device *device_list;
254 250
255 result = acpi_power_get_context(handle, &resource); 251 result = acpi_power_get_context(handle, &resource);
256 if (result) 252 if (result)
@@ -266,10 +262,25 @@ static int acpi_power_on(acpi_handle handle)
266 result = __acpi_power_on(resource); 262 result = __acpi_power_on(resource);
267 if (result) 263 if (result)
268 resource->ref_count--; 264 resource->ref_count--;
265 else
266 resume_device = true;
269 } 267 }
270 268
271 mutex_unlock(&resource->resource_lock); 269 mutex_unlock(&resource->resource_lock);
272 270
271 if (!resume_device)
272 return result;
273
274 mutex_lock(&resource->devices_lock);
275
276 device_list = resource->devices;
277 while (device_list) {
278 acpi_power_on_device(device_list->device);
279 device_list = device_list->next;
280 }
281
282 mutex_unlock(&resource->devices_lock);
283
273 return result; 284 return result;
274} 285}
275 286
@@ -355,7 +366,7 @@ static void __acpi_power_resource_unregister_device(struct device *dev,
355 if (acpi_power_get_context(res_handle, &resource)) 366 if (acpi_power_get_context(res_handle, &resource))
356 return; 367 return;
357 368
358 mutex_lock(&resource->resource_lock); 369 mutex_lock(&resource->devices_lock);
359 prev = NULL; 370 prev = NULL;
360 curr = resource->devices; 371 curr = resource->devices;
361 while (curr) { 372 while (curr) {
@@ -372,7 +383,7 @@ static void __acpi_power_resource_unregister_device(struct device *dev,
372 prev = curr; 383 prev = curr;
373 curr = curr->next; 384 curr = curr->next;
374 } 385 }
375 mutex_unlock(&resource->resource_lock); 386 mutex_unlock(&resource->devices_lock);
376} 387}
377 388
378/* Unlink dev from all power resources in _PR0 */ 389/* Unlink dev from all power resources in _PR0 */
@@ -414,10 +425,10 @@ static int __acpi_power_resource_register_device(
414 425
415 power_resource_device->device = powered_device; 426 power_resource_device->device = powered_device;
416 427
417 mutex_lock(&resource->resource_lock); 428 mutex_lock(&resource->devices_lock);
418 power_resource_device->next = resource->devices; 429 power_resource_device->next = resource->devices;
419 resource->devices = power_resource_device; 430 resource->devices = power_resource_device;
420 mutex_unlock(&resource->resource_lock); 431 mutex_unlock(&resource->devices_lock);
421 432
422 return 0; 433 return 0;
423} 434}
@@ -462,7 +473,7 @@ int acpi_power_resource_register_device(struct device *dev, acpi_handle handle)
462 return ret; 473 return ret;
463 474
464no_power_resource: 475no_power_resource:
465 printk(KERN_WARNING PREFIX "Invalid Power Resource to register!"); 476 printk(KERN_DEBUG PREFIX "Invalid Power Resource to register!");
466 return -ENODEV; 477 return -ENODEV;
467} 478}
468EXPORT_SYMBOL_GPL(acpi_power_resource_register_device); 479EXPORT_SYMBOL_GPL(acpi_power_resource_register_device);
@@ -721,6 +732,7 @@ static int acpi_power_add(struct acpi_device *device)
721 732
722 resource->device = device; 733 resource->device = device;
723 mutex_init(&resource->resource_lock); 734 mutex_init(&resource->resource_lock);
735 mutex_init(&resource->devices_lock);
724 strcpy(resource->name, device->pnp.bus_id); 736 strcpy(resource->name, device->pnp.bus_id);
725 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 737 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
726 strcpy(acpi_device_class(device), ACPI_POWER_CLASS); 738 strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 50d5dea0ff59..7862d17976b7 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -268,6 +268,9 @@ static const struct pci_device_id ahci_pci_tbl[] = {
268 /* JMicron 360/1/3/5/6, match class to avoid IDE function */ 268 /* JMicron 360/1/3/5/6, match class to avoid IDE function */
269 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 269 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
270 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr }, 270 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr },
271 /* JMicron 362B and 362C have an AHCI function with IDE class code */
272 { PCI_VDEVICE(JMICRON, 0x2362), board_ahci_ign_iferr },
273 { PCI_VDEVICE(JMICRON, 0x236f), board_ahci_ign_iferr },
271 274
272 /* ATI */ 275 /* ATI */
273 { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */ 276 { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */
@@ -393,6 +396,8 @@ static const struct pci_device_id ahci_pci_tbl[] = {
393 .driver_data = board_ahci_yes_fbs }, /* 88se9125 */ 396 .driver_data = board_ahci_yes_fbs }, /* 88se9125 */
394 { PCI_DEVICE(0x1b4b, 0x917a), 397 { PCI_DEVICE(0x1b4b, 0x917a),
395 .driver_data = board_ahci_yes_fbs }, /* 88se9172 */ 398 .driver_data = board_ahci_yes_fbs }, /* 88se9172 */
399 { PCI_DEVICE(0x1b4b, 0x9192),
400 .driver_data = board_ahci_yes_fbs }, /* 88se9172 on some Gigabyte */
396 { PCI_DEVICE(0x1b4b, 0x91a3), 401 { PCI_DEVICE(0x1b4b, 0x91a3),
397 .driver_data = board_ahci_yes_fbs }, 402 .driver_data = board_ahci_yes_fbs },
398 403
@@ -400,7 +405,10 @@ static const struct pci_device_id ahci_pci_tbl[] = {
400 { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */ 405 { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */
401 406
402 /* Asmedia */ 407 /* Asmedia */
403 { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1061 */ 408 { PCI_VDEVICE(ASMEDIA, 0x0601), board_ahci }, /* ASM1060 */
409 { PCI_VDEVICE(ASMEDIA, 0x0602), board_ahci }, /* ASM1060 */
410 { PCI_VDEVICE(ASMEDIA, 0x0611), board_ahci }, /* ASM1061 */
411 { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1062 */
404 412
405 /* Generic, PCI class code for AHCI */ 413 /* Generic, PCI class code for AHCI */
406 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 414 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index a89734621e51..5b6b1d8e6cc0 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -16,12 +16,14 @@
16#include <linux/irq.h> 16#include <linux/irq.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/irqdomain.h> 18#include <linux/irqdomain.h>
19#include <linux/pm_runtime.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20 21
21#include "internal.h" 22#include "internal.h"
22 23
23struct regmap_irq_chip_data { 24struct regmap_irq_chip_data {
24 struct mutex lock; 25 struct mutex lock;
26 struct irq_chip irq_chip;
25 27
26 struct regmap *map; 28 struct regmap *map;
27 const struct regmap_irq_chip *chip; 29 const struct regmap_irq_chip *chip;
@@ -59,6 +61,14 @@ static void regmap_irq_sync_unlock(struct irq_data *data)
59 struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data); 61 struct regmap_irq_chip_data *d = irq_data_get_irq_chip_data(data);
60 struct regmap *map = d->map; 62 struct regmap *map = d->map;
61 int i, ret; 63 int i, ret;
64 u32 reg;
65
66 if (d->chip->runtime_pm) {
67 ret = pm_runtime_get_sync(map->dev);
68 if (ret < 0)
69 dev_err(map->dev, "IRQ sync failed to resume: %d\n",
70 ret);
71 }
62 72
63 /* 73 /*
64 * If there's been a change in the mask write it back to the 74 * If there's been a change in the mask write it back to the
@@ -66,15 +76,22 @@ static void regmap_irq_sync_unlock(struct irq_data *data)
66 * suppress pointless writes. 76 * suppress pointless writes.
67 */ 77 */
68 for (i = 0; i < d->chip->num_regs; i++) { 78 for (i = 0; i < d->chip->num_regs; i++) {
69 ret = regmap_update_bits(d->map, d->chip->mask_base + 79 reg = d->chip->mask_base +
70 (i * map->reg_stride * 80 (i * map->reg_stride * d->irq_reg_stride);
71 d->irq_reg_stride), 81 if (d->chip->mask_invert)
82 ret = regmap_update_bits(d->map, reg,
83 d->mask_buf_def[i], ~d->mask_buf[i]);
84 else
85 ret = regmap_update_bits(d->map, reg,
72 d->mask_buf_def[i], d->mask_buf[i]); 86 d->mask_buf_def[i], d->mask_buf[i]);
73 if (ret != 0) 87 if (ret != 0)
74 dev_err(d->map->dev, "Failed to sync masks in %x\n", 88 dev_err(d->map->dev, "Failed to sync masks in %x\n",
75 d->chip->mask_base + (i * map->reg_stride)); 89 reg);
76 } 90 }
77 91
92 if (d->chip->runtime_pm)
93 pm_runtime_put(map->dev);
94
78 /* If we've changed our wakeup count propagate it to the parent */ 95 /* If we've changed our wakeup count propagate it to the parent */
79 if (d->wake_count < 0) 96 if (d->wake_count < 0)
80 for (i = d->wake_count; i < 0; i++) 97 for (i = d->wake_count; i < 0; i++)
@@ -128,8 +145,7 @@ static int regmap_irq_set_wake(struct irq_data *data, unsigned int on)
128 return 0; 145 return 0;
129} 146}
130 147
131static struct irq_chip regmap_irq_chip = { 148static const struct irq_chip regmap_irq_chip = {
132 .name = "regmap",
133 .irq_bus_lock = regmap_irq_lock, 149 .irq_bus_lock = regmap_irq_lock,
134 .irq_bus_sync_unlock = regmap_irq_sync_unlock, 150 .irq_bus_sync_unlock = regmap_irq_sync_unlock,
135 .irq_disable = regmap_irq_disable, 151 .irq_disable = regmap_irq_disable,
@@ -144,6 +160,16 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
144 struct regmap *map = data->map; 160 struct regmap *map = data->map;
145 int ret, i; 161 int ret, i;
146 bool handled = false; 162 bool handled = false;
163 u32 reg;
164
165 if (chip->runtime_pm) {
166 ret = pm_runtime_get_sync(map->dev);
167 if (ret < 0) {
168 dev_err(map->dev, "IRQ thread failed to resume: %d\n",
169 ret);
170 return IRQ_NONE;
171 }
172 }
147 173
148 /* 174 /*
149 * Ignore masked IRQs and ack if we need to; we ack early so 175 * Ignore masked IRQs and ack if we need to; we ack early so
@@ -160,20 +186,20 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
160 if (ret != 0) { 186 if (ret != 0) {
161 dev_err(map->dev, "Failed to read IRQ status: %d\n", 187 dev_err(map->dev, "Failed to read IRQ status: %d\n",
162 ret); 188 ret);
189 if (chip->runtime_pm)
190 pm_runtime_put(map->dev);
163 return IRQ_NONE; 191 return IRQ_NONE;
164 } 192 }
165 193
166 data->status_buf[i] &= ~data->mask_buf[i]; 194 data->status_buf[i] &= ~data->mask_buf[i];
167 195
168 if (data->status_buf[i] && chip->ack_base) { 196 if (data->status_buf[i] && chip->ack_base) {
169 ret = regmap_write(map, chip->ack_base + 197 reg = chip->ack_base +
170 (i * map->reg_stride * 198 (i * map->reg_stride * data->irq_reg_stride);
171 data->irq_reg_stride), 199 ret = regmap_write(map, reg, data->status_buf[i]);
172 data->status_buf[i]);
173 if (ret != 0) 200 if (ret != 0)
174 dev_err(map->dev, "Failed to ack 0x%x: %d\n", 201 dev_err(map->dev, "Failed to ack 0x%x: %d\n",
175 chip->ack_base + (i * map->reg_stride), 202 reg, ret);
176 ret);
177 } 203 }
178 } 204 }
179 205
@@ -185,6 +211,9 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
185 } 211 }
186 } 212 }
187 213
214 if (chip->runtime_pm)
215 pm_runtime_put(map->dev);
216
188 if (handled) 217 if (handled)
189 return IRQ_HANDLED; 218 return IRQ_HANDLED;
190 else 219 else
@@ -197,7 +226,7 @@ static int regmap_irq_map(struct irq_domain *h, unsigned int virq,
197 struct regmap_irq_chip_data *data = h->host_data; 226 struct regmap_irq_chip_data *data = h->host_data;
198 227
199 irq_set_chip_data(virq, data); 228 irq_set_chip_data(virq, data);
200 irq_set_chip_and_handler(virq, &regmap_irq_chip, handle_edge_irq); 229 irq_set_chip(virq, &data->irq_chip);
201 irq_set_nested_thread(virq, 1); 230 irq_set_nested_thread(virq, 1);
202 231
203 /* ARM needs us to explicitly flag the IRQ as valid 232 /* ARM needs us to explicitly flag the IRQ as valid
@@ -238,6 +267,7 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
238 struct regmap_irq_chip_data *d; 267 struct regmap_irq_chip_data *d;
239 int i; 268 int i;
240 int ret = -ENOMEM; 269 int ret = -ENOMEM;
270 u32 reg;
241 271
242 for (i = 0; i < chip->num_irqs; i++) { 272 for (i = 0; i < chip->num_irqs; i++) {
243 if (chip->irqs[i].reg_offset % map->reg_stride) 273 if (chip->irqs[i].reg_offset % map->reg_stride)
@@ -284,6 +314,13 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
284 goto err_alloc; 314 goto err_alloc;
285 } 315 }
286 316
317 d->irq_chip = regmap_irq_chip;
318 d->irq_chip.name = chip->name;
319 if (!chip->wake_base) {
320 d->irq_chip.irq_set_wake = NULL;
321 d->irq_chip.flags |= IRQCHIP_MASK_ON_SUSPEND |
322 IRQCHIP_SKIP_SET_WAKE;
323 }
287 d->irq = irq; 324 d->irq = irq;
288 d->map = map; 325 d->map = map;
289 d->chip = chip; 326 d->chip = chip;
@@ -303,16 +340,37 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
303 /* Mask all the interrupts by default */ 340 /* Mask all the interrupts by default */
304 for (i = 0; i < chip->num_regs; i++) { 341 for (i = 0; i < chip->num_regs; i++) {
305 d->mask_buf[i] = d->mask_buf_def[i]; 342 d->mask_buf[i] = d->mask_buf_def[i];
306 ret = regmap_write(map, chip->mask_base + (i * map->reg_stride 343 reg = chip->mask_base +
307 * d->irq_reg_stride), 344 (i * map->reg_stride * d->irq_reg_stride);
308 d->mask_buf[i]); 345 if (chip->mask_invert)
346 ret = regmap_update_bits(map, reg,
347 d->mask_buf[i], ~d->mask_buf[i]);
348 else
349 ret = regmap_update_bits(map, reg,
350 d->mask_buf[i], d->mask_buf[i]);
309 if (ret != 0) { 351 if (ret != 0) {
310 dev_err(map->dev, "Failed to set masks in 0x%x: %d\n", 352 dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
311 chip->mask_base + (i * map->reg_stride), ret); 353 reg, ret);
312 goto err_alloc; 354 goto err_alloc;
313 } 355 }
314 } 356 }
315 357
358 /* Wake is disabled by default */
359 if (d->wake_buf) {
360 for (i = 0; i < chip->num_regs; i++) {
361 d->wake_buf[i] = d->mask_buf_def[i];
362 reg = chip->wake_base +
363 (i * map->reg_stride * d->irq_reg_stride);
364 ret = regmap_update_bits(map, reg, d->wake_buf[i],
365 d->wake_buf[i]);
366 if (ret != 0) {
367 dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
368 reg, ret);
369 goto err_alloc;
370 }
371 }
372 }
373
316 if (irq_base) 374 if (irq_base)
317 d->domain = irq_domain_add_legacy(map->dev->of_node, 375 d->domain = irq_domain_add_legacy(map->dev->of_node,
318 chip->num_irqs, irq_base, 0, 376 chip->num_irqs, irq_base, 0,
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index c241ae2f2f10..52069d29ff12 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -659,13 +659,12 @@ EXPORT_SYMBOL_GPL(devm_regmap_init);
659 * new cache. This can be used to restore the cache to defaults or to 659 * new cache. This can be used to restore the cache to defaults or to
660 * update the cache configuration to reflect runtime discovery of the 660 * update the cache configuration to reflect runtime discovery of the
661 * hardware. 661 * hardware.
662 *
663 * No explicit locking is done here, the user needs to ensure that
664 * this function will not race with other calls to regmap.
662 */ 665 */
663int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) 666int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
664{ 667{
665 int ret;
666
667 map->lock(map);
668
669 regcache_exit(map); 668 regcache_exit(map);
670 regmap_debugfs_exit(map); 669 regmap_debugfs_exit(map);
671 670
@@ -681,11 +680,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
681 map->cache_bypass = false; 680 map->cache_bypass = false;
682 map->cache_only = false; 681 map->cache_only = false;
683 682
684 ret = regcache_init(map, config); 683 return regcache_init(map, config);
685
686 map->unlock(map);
687
688 return ret;
689} 684}
690EXPORT_SYMBOL_GPL(regmap_reinit_cache); 685EXPORT_SYMBOL_GPL(regmap_reinit_cache);
691 686
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index de0435e63b02..887f68f6d79a 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -35,6 +35,7 @@ new_skb(ulong len)
35 skb_reset_mac_header(skb); 35 skb_reset_mac_header(skb);
36 skb_reset_network_header(skb); 36 skb_reset_network_header(skb);
37 skb->protocol = __constant_htons(ETH_P_AOE); 37 skb->protocol = __constant_htons(ETH_P_AOE);
38 skb_checksum_none_assert(skb);
38 } 39 }
39 return skb; 40 return skb;
40} 41}
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 38aa6dda6b81..da3311129a0c 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -795,6 +795,7 @@ static void complete_scsi_command(CommandList_struct *c, int timeout,
795 } 795 }
796 break; 796 break;
797 case CMD_PROTOCOL_ERR: 797 case CMD_PROTOCOL_ERR:
798 cmd->result = DID_ERROR << 16;
798 dev_warn(&h->pdev->dev, 799 dev_warn(&h->pdev->dev,
799 "%p has protocol error\n", c); 800 "%p has protocol error\n", c);
800 break; 801 break;
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index a8fddeb3d638..f946d31d6917 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -1148,11 +1148,15 @@ static bool mtip_pause_ncq(struct mtip_port *port,
1148 reply = port->rxfis + RX_FIS_D2H_REG; 1148 reply = port->rxfis + RX_FIS_D2H_REG;
1149 task_file_data = readl(port->mmio+PORT_TFDATA); 1149 task_file_data = readl(port->mmio+PORT_TFDATA);
1150 1150
1151 if ((task_file_data & 1) || (fis->command == ATA_CMD_SEC_ERASE_UNIT)) 1151 if (fis->command == ATA_CMD_SEC_ERASE_UNIT)
1152 clear_bit(MTIP_DDF_SEC_LOCK_BIT, &port->dd->dd_flag);
1153
1154 if ((task_file_data & 1))
1152 return false; 1155 return false;
1153 1156
1154 if (fis->command == ATA_CMD_SEC_ERASE_PREP) { 1157 if (fis->command == ATA_CMD_SEC_ERASE_PREP) {
1155 set_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags); 1158 set_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags);
1159 set_bit(MTIP_DDF_SEC_LOCK_BIT, &port->dd->dd_flag);
1156 port->ic_pause_timer = jiffies; 1160 port->ic_pause_timer = jiffies;
1157 return true; 1161 return true;
1158 } else if ((fis->command == ATA_CMD_DOWNLOAD_MICRO) && 1162 } else if ((fis->command == ATA_CMD_DOWNLOAD_MICRO) &&
@@ -1900,7 +1904,7 @@ static int exec_drive_command(struct mtip_port *port, u8 *command,
1900 int rv = 0, xfer_sz = command[3]; 1904 int rv = 0, xfer_sz = command[3];
1901 1905
1902 if (xfer_sz) { 1906 if (xfer_sz) {
1903 if (user_buffer) 1907 if (!user_buffer)
1904 return -EFAULT; 1908 return -EFAULT;
1905 1909
1906 buf = dmam_alloc_coherent(&port->dd->pdev->dev, 1910 buf = dmam_alloc_coherent(&port->dd->pdev->dev,
@@ -2043,7 +2047,7 @@ static void mtip_set_timeout(struct host_to_dev_fis *fis, unsigned int *timeout)
2043 *timeout = 240000; /* 4 minutes */ 2047 *timeout = 240000; /* 4 minutes */
2044 break; 2048 break;
2045 case ATA_CMD_STANDBYNOW1: 2049 case ATA_CMD_STANDBYNOW1:
2046 *timeout = 10000; /* 10 seconds */ 2050 *timeout = 120000; /* 2 minutes */
2047 break; 2051 break;
2048 case 0xF7: 2052 case 0xF7:
2049 case 0xFA: 2053 case 0xFA:
@@ -2588,9 +2592,6 @@ static ssize_t mtip_hw_read_registers(struct file *f, char __user *ubuf,
2588 if (!len || size) 2592 if (!len || size)
2589 return 0; 2593 return 0;
2590 2594
2591 if (size < 0)
2592 return -EINVAL;
2593
2594 size += sprintf(&buf[size], "H/ S ACTive : [ 0x"); 2595 size += sprintf(&buf[size], "H/ S ACTive : [ 0x");
2595 2596
2596 for (n = dd->slot_groups-1; n >= 0; n--) 2597 for (n = dd->slot_groups-1; n >= 0; n--)
@@ -2660,9 +2661,6 @@ static ssize_t mtip_hw_read_flags(struct file *f, char __user *ubuf,
2660 if (!len || size) 2661 if (!len || size)
2661 return 0; 2662 return 0;
2662 2663
2663 if (size < 0)
2664 return -EINVAL;
2665
2666 size += sprintf(&buf[size], "Flag-port : [ %08lX ]\n", 2664 size += sprintf(&buf[size], "Flag-port : [ %08lX ]\n",
2667 dd->port->flags); 2665 dd->port->flags);
2668 size += sprintf(&buf[size], "Flag-dd : [ %08lX ]\n", 2666 size += sprintf(&buf[size], "Flag-dd : [ %08lX ]\n",
@@ -3214,8 +3212,8 @@ static int mtip_hw_init(struct driver_data *dd)
3214 "Unable to check write protect progress\n"); 3212 "Unable to check write protect progress\n");
3215 else 3213 else
3216 dev_info(&dd->pdev->dev, 3214 dev_info(&dd->pdev->dev,
3217 "Write protect progress: %d%% (%d blocks)\n", 3215 "Write protect progress: %u%% (%u blocks)\n",
3218 attr242.cur, attr242.data); 3216 attr242.cur, le32_to_cpu(attr242.data));
3219 return rv; 3217 return rv;
3220 3218
3221out3: 3219out3:
@@ -3619,6 +3617,10 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio)
3619 bio_endio(bio, -ENODATA); 3617 bio_endio(bio, -ENODATA);
3620 return; 3618 return;
3621 } 3619 }
3620 if (unlikely(test_bit(MTIP_DDF_SEC_LOCK_BIT, &dd->dd_flag))) {
3621 bio_endio(bio, -ENODATA);
3622 return;
3623 }
3622 } 3624 }
3623 3625
3624 if (unlikely(!bio_has_data(bio))) { 3626 if (unlikely(!bio_has_data(bio))) {
@@ -4168,7 +4170,13 @@ static void mtip_pci_shutdown(struct pci_dev *pdev)
4168 4170
4169/* Table of device ids supported by this driver. */ 4171/* Table of device ids supported by this driver. */
4170static DEFINE_PCI_DEVICE_TABLE(mtip_pci_tbl) = { 4172static DEFINE_PCI_DEVICE_TABLE(mtip_pci_tbl) = {
4171 { PCI_DEVICE(PCI_VENDOR_ID_MICRON, P320_DEVICE_ID) }, 4173 { PCI_DEVICE(PCI_VENDOR_ID_MICRON, P320H_DEVICE_ID) },
4174 { PCI_DEVICE(PCI_VENDOR_ID_MICRON, P320M_DEVICE_ID) },
4175 { PCI_DEVICE(PCI_VENDOR_ID_MICRON, P320S_DEVICE_ID) },
4176 { PCI_DEVICE(PCI_VENDOR_ID_MICRON, P325M_DEVICE_ID) },
4177 { PCI_DEVICE(PCI_VENDOR_ID_MICRON, P420H_DEVICE_ID) },
4178 { PCI_DEVICE(PCI_VENDOR_ID_MICRON, P420M_DEVICE_ID) },
4179 { PCI_DEVICE(PCI_VENDOR_ID_MICRON, P425M_DEVICE_ID) },
4172 { 0 } 4180 { 0 }
4173}; 4181};
4174 4182
@@ -4199,12 +4207,12 @@ static int __init mtip_init(void)
4199{ 4207{
4200 int error; 4208 int error;
4201 4209
4202 printk(KERN_INFO MTIP_DRV_NAME " Version " MTIP_DRV_VERSION "\n"); 4210 pr_info(MTIP_DRV_NAME " Version " MTIP_DRV_VERSION "\n");
4203 4211
4204 /* Allocate a major block device number to use with this driver. */ 4212 /* Allocate a major block device number to use with this driver. */
4205 error = register_blkdev(0, MTIP_DRV_NAME); 4213 error = register_blkdev(0, MTIP_DRV_NAME);
4206 if (error <= 0) { 4214 if (error <= 0) {
4207 printk(KERN_ERR "Unable to register block device (%d)\n", 4215 pr_err("Unable to register block device (%d)\n",
4208 error); 4216 error);
4209 return -EBUSY; 4217 return -EBUSY;
4210 } 4218 }
@@ -4213,7 +4221,7 @@ static int __init mtip_init(void)
4213 if (!dfs_parent) { 4221 if (!dfs_parent) {
4214 dfs_parent = debugfs_create_dir("rssd", NULL); 4222 dfs_parent = debugfs_create_dir("rssd", NULL);
4215 if (IS_ERR_OR_NULL(dfs_parent)) { 4223 if (IS_ERR_OR_NULL(dfs_parent)) {
4216 printk(KERN_WARNING "Error creating debugfs parent\n"); 4224 pr_warn("Error creating debugfs parent\n");
4217 dfs_parent = NULL; 4225 dfs_parent = NULL;
4218 } 4226 }
4219 } 4227 }
diff --git a/drivers/block/mtip32xx/mtip32xx.h b/drivers/block/mtip32xx/mtip32xx.h
index f51fc23d17bb..18627a1d04c5 100644
--- a/drivers/block/mtip32xx/mtip32xx.h
+++ b/drivers/block/mtip32xx/mtip32xx.h
@@ -76,7 +76,13 @@
76 76
77/* Micron Vendor ID & P320x SSD Device ID */ 77/* Micron Vendor ID & P320x SSD Device ID */
78#define PCI_VENDOR_ID_MICRON 0x1344 78#define PCI_VENDOR_ID_MICRON 0x1344
79#define P320_DEVICE_ID 0x5150 79#define P320H_DEVICE_ID 0x5150
80#define P320M_DEVICE_ID 0x5151
81#define P320S_DEVICE_ID 0x5152
82#define P325M_DEVICE_ID 0x5153
83#define P420H_DEVICE_ID 0x5160
84#define P420M_DEVICE_ID 0x5161
85#define P425M_DEVICE_ID 0x5163
80 86
81/* Driver name and version strings */ 87/* Driver name and version strings */
82#define MTIP_DRV_NAME "mtip32xx" 88#define MTIP_DRV_NAME "mtip32xx"
@@ -131,10 +137,12 @@ enum {
131 MTIP_PF_SVC_THD_STOP_BIT = 8, 137 MTIP_PF_SVC_THD_STOP_BIT = 8,
132 138
133 /* below are bit numbers in 'dd_flag' defined in driver_data */ 139 /* below are bit numbers in 'dd_flag' defined in driver_data */
140 MTIP_DDF_SEC_LOCK_BIT = 0,
134 MTIP_DDF_REMOVE_PENDING_BIT = 1, 141 MTIP_DDF_REMOVE_PENDING_BIT = 1,
135 MTIP_DDF_OVER_TEMP_BIT = 2, 142 MTIP_DDF_OVER_TEMP_BIT = 2,
136 MTIP_DDF_WRITE_PROTECT_BIT = 3, 143 MTIP_DDF_WRITE_PROTECT_BIT = 3,
137 MTIP_DDF_STOP_IO = ((1 << MTIP_DDF_REMOVE_PENDING_BIT) | \ 144 MTIP_DDF_STOP_IO = ((1 << MTIP_DDF_REMOVE_PENDING_BIT) | \
145 (1 << MTIP_DDF_SEC_LOCK_BIT) | \
138 (1 << MTIP_DDF_OVER_TEMP_BIT) | \ 146 (1 << MTIP_DDF_OVER_TEMP_BIT) | \
139 (1 << MTIP_DDF_WRITE_PROTECT_BIT)), 147 (1 << MTIP_DDF_WRITE_PROTECT_BIT)),
140 148
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index d07c9f7fded6..0c03411c59eb 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -449,6 +449,14 @@ static void nbd_clear_que(struct nbd_device *nbd)
449 req->errors++; 449 req->errors++;
450 nbd_end_request(req); 450 nbd_end_request(req);
451 } 451 }
452
453 while (!list_empty(&nbd->waiting_queue)) {
454 req = list_entry(nbd->waiting_queue.next, struct request,
455 queuelist);
456 list_del_init(&req->queuelist);
457 req->errors++;
458 nbd_end_request(req);
459 }
452} 460}
453 461
454 462
@@ -598,6 +606,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
598 nbd->file = NULL; 606 nbd->file = NULL;
599 nbd_clear_que(nbd); 607 nbd_clear_que(nbd);
600 BUG_ON(!list_empty(&nbd->queue_head)); 608 BUG_ON(!list_empty(&nbd->queue_head));
609 BUG_ON(!list_empty(&nbd->waiting_queue));
601 if (file) 610 if (file)
602 fput(file); 611 fput(file);
603 return 0; 612 return 0;
diff --git a/drivers/block/nvme.c b/drivers/block/nvme.c
index 38a2d0631882..ad16c68c8645 100644
--- a/drivers/block/nvme.c
+++ b/drivers/block/nvme.c
@@ -79,6 +79,7 @@ struct nvme_dev {
79 char serial[20]; 79 char serial[20];
80 char model[40]; 80 char model[40];
81 char firmware_rev[8]; 81 char firmware_rev[8];
82 u32 max_hw_sectors;
82}; 83};
83 84
84/* 85/*
@@ -835,15 +836,15 @@ static int nvme_identify(struct nvme_dev *dev, unsigned nsid, unsigned cns,
835} 836}
836 837
837static int nvme_get_features(struct nvme_dev *dev, unsigned fid, 838static int nvme_get_features(struct nvme_dev *dev, unsigned fid,
838 unsigned dword11, dma_addr_t dma_addr) 839 unsigned nsid, dma_addr_t dma_addr)
839{ 840{
840 struct nvme_command c; 841 struct nvme_command c;
841 842
842 memset(&c, 0, sizeof(c)); 843 memset(&c, 0, sizeof(c));
843 c.features.opcode = nvme_admin_get_features; 844 c.features.opcode = nvme_admin_get_features;
845 c.features.nsid = cpu_to_le32(nsid);
844 c.features.prp1 = cpu_to_le64(dma_addr); 846 c.features.prp1 = cpu_to_le64(dma_addr);
845 c.features.fid = cpu_to_le32(fid); 847 c.features.fid = cpu_to_le32(fid);
846 c.features.dword11 = cpu_to_le32(dword11);
847 848
848 return nvme_submit_admin_cmd(dev, &c, NULL); 849 return nvme_submit_admin_cmd(dev, &c, NULL);
849} 850}
@@ -862,11 +863,51 @@ static int nvme_set_features(struct nvme_dev *dev, unsigned fid,
862 return nvme_submit_admin_cmd(dev, &c, result); 863 return nvme_submit_admin_cmd(dev, &c, result);
863} 864}
864 865
866/**
867 * nvme_cancel_ios - Cancel outstanding I/Os
868 * @queue: The queue to cancel I/Os on
869 * @timeout: True to only cancel I/Os which have timed out
870 */
871static void nvme_cancel_ios(struct nvme_queue *nvmeq, bool timeout)
872{
873 int depth = nvmeq->q_depth - 1;
874 struct nvme_cmd_info *info = nvme_cmd_info(nvmeq);
875 unsigned long now = jiffies;
876 int cmdid;
877
878 for_each_set_bit(cmdid, nvmeq->cmdid_data, depth) {
879 void *ctx;
880 nvme_completion_fn fn;
881 static struct nvme_completion cqe = {
882 .status = cpu_to_le16(NVME_SC_ABORT_REQ) << 1,
883 };
884
885 if (timeout && !time_after(now, info[cmdid].timeout))
886 continue;
887 dev_warn(nvmeq->q_dmadev, "Cancelling I/O %d\n", cmdid);
888 ctx = cancel_cmdid(nvmeq, cmdid, &fn);
889 fn(nvmeq->dev, ctx, &cqe);
890 }
891}
892
893static void nvme_free_queue_mem(struct nvme_queue *nvmeq)
894{
895 dma_free_coherent(nvmeq->q_dmadev, CQ_SIZE(nvmeq->q_depth),
896 (void *)nvmeq->cqes, nvmeq->cq_dma_addr);
897 dma_free_coherent(nvmeq->q_dmadev, SQ_SIZE(nvmeq->q_depth),
898 nvmeq->sq_cmds, nvmeq->sq_dma_addr);
899 kfree(nvmeq);
900}
901
865static void nvme_free_queue(struct nvme_dev *dev, int qid) 902static void nvme_free_queue(struct nvme_dev *dev, int qid)
866{ 903{
867 struct nvme_queue *nvmeq = dev->queues[qid]; 904 struct nvme_queue *nvmeq = dev->queues[qid];
868 int vector = dev->entry[nvmeq->cq_vector].vector; 905 int vector = dev->entry[nvmeq->cq_vector].vector;
869 906
907 spin_lock_irq(&nvmeq->q_lock);
908 nvme_cancel_ios(nvmeq, false);
909 spin_unlock_irq(&nvmeq->q_lock);
910
870 irq_set_affinity_hint(vector, NULL); 911 irq_set_affinity_hint(vector, NULL);
871 free_irq(vector, nvmeq); 912 free_irq(vector, nvmeq);
872 913
@@ -876,18 +917,15 @@ static void nvme_free_queue(struct nvme_dev *dev, int qid)
876 adapter_delete_cq(dev, qid); 917 adapter_delete_cq(dev, qid);
877 } 918 }
878 919
879 dma_free_coherent(nvmeq->q_dmadev, CQ_SIZE(nvmeq->q_depth), 920 nvme_free_queue_mem(nvmeq);
880 (void *)nvmeq->cqes, nvmeq->cq_dma_addr);
881 dma_free_coherent(nvmeq->q_dmadev, SQ_SIZE(nvmeq->q_depth),
882 nvmeq->sq_cmds, nvmeq->sq_dma_addr);
883 kfree(nvmeq);
884} 921}
885 922
886static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid, 923static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
887 int depth, int vector) 924 int depth, int vector)
888{ 925{
889 struct device *dmadev = &dev->pci_dev->dev; 926 struct device *dmadev = &dev->pci_dev->dev;
890 unsigned extra = (depth / 8) + (depth * sizeof(struct nvme_cmd_info)); 927 unsigned extra = DIV_ROUND_UP(depth, 8) + (depth *
928 sizeof(struct nvme_cmd_info));
891 struct nvme_queue *nvmeq = kzalloc(sizeof(*nvmeq) + extra, GFP_KERNEL); 929 struct nvme_queue *nvmeq = kzalloc(sizeof(*nvmeq) + extra, GFP_KERNEL);
892 if (!nvmeq) 930 if (!nvmeq)
893 return NULL; 931 return NULL;
@@ -975,7 +1013,7 @@ static __devinit struct nvme_queue *nvme_create_queue(struct nvme_dev *dev,
975 1013
976static int __devinit nvme_configure_admin_queue(struct nvme_dev *dev) 1014static int __devinit nvme_configure_admin_queue(struct nvme_dev *dev)
977{ 1015{
978 int result; 1016 int result = 0;
979 u32 aqa; 1017 u32 aqa;
980 u64 cap; 1018 u64 cap;
981 unsigned long timeout; 1019 unsigned long timeout;
@@ -1005,17 +1043,22 @@ static int __devinit nvme_configure_admin_queue(struct nvme_dev *dev)
1005 timeout = ((NVME_CAP_TIMEOUT(cap) + 1) * HZ / 2) + jiffies; 1043 timeout = ((NVME_CAP_TIMEOUT(cap) + 1) * HZ / 2) + jiffies;
1006 dev->db_stride = NVME_CAP_STRIDE(cap); 1044 dev->db_stride = NVME_CAP_STRIDE(cap);
1007 1045
1008 while (!(readl(&dev->bar->csts) & NVME_CSTS_RDY)) { 1046 while (!result && !(readl(&dev->bar->csts) & NVME_CSTS_RDY)) {
1009 msleep(100); 1047 msleep(100);
1010 if (fatal_signal_pending(current)) 1048 if (fatal_signal_pending(current))
1011 return -EINTR; 1049 result = -EINTR;
1012 if (time_after(jiffies, timeout)) { 1050 if (time_after(jiffies, timeout)) {
1013 dev_err(&dev->pci_dev->dev, 1051 dev_err(&dev->pci_dev->dev,
1014 "Device not ready; aborting initialisation\n"); 1052 "Device not ready; aborting initialisation\n");
1015 return -ENODEV; 1053 result = -ENODEV;
1016 } 1054 }
1017 } 1055 }
1018 1056
1057 if (result) {
1058 nvme_free_queue_mem(nvmeq);
1059 return result;
1060 }
1061
1019 result = queue_request_irq(dev, nvmeq, "nvme admin"); 1062 result = queue_request_irq(dev, nvmeq, "nvme admin");
1020 dev->queues[0] = nvmeq; 1063 dev->queues[0] = nvmeq;
1021 return result; 1064 return result;
@@ -1037,6 +1080,8 @@ static struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write,
1037 offset = offset_in_page(addr); 1080 offset = offset_in_page(addr);
1038 count = DIV_ROUND_UP(offset + length, PAGE_SIZE); 1081 count = DIV_ROUND_UP(offset + length, PAGE_SIZE);
1039 pages = kcalloc(count, sizeof(*pages), GFP_KERNEL); 1082 pages = kcalloc(count, sizeof(*pages), GFP_KERNEL);
1083 if (!pages)
1084 return ERR_PTR(-ENOMEM);
1040 1085
1041 err = get_user_pages_fast(addr, count, 1, pages); 1086 err = get_user_pages_fast(addr, count, 1, pages);
1042 if (err < count) { 1087 if (err < count) {
@@ -1146,14 +1191,13 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
1146 return status; 1191 return status;
1147} 1192}
1148 1193
1149static int nvme_user_admin_cmd(struct nvme_ns *ns, 1194static int nvme_user_admin_cmd(struct nvme_dev *dev,
1150 struct nvme_admin_cmd __user *ucmd) 1195 struct nvme_admin_cmd __user *ucmd)
1151{ 1196{
1152 struct nvme_dev *dev = ns->dev;
1153 struct nvme_admin_cmd cmd; 1197 struct nvme_admin_cmd cmd;
1154 struct nvme_command c; 1198 struct nvme_command c;
1155 int status, length; 1199 int status, length;
1156 struct nvme_iod *iod; 1200 struct nvme_iod *uninitialized_var(iod);
1157 1201
1158 if (!capable(CAP_SYS_ADMIN)) 1202 if (!capable(CAP_SYS_ADMIN))
1159 return -EACCES; 1203 return -EACCES;
@@ -1204,7 +1248,7 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
1204 case NVME_IOCTL_ID: 1248 case NVME_IOCTL_ID:
1205 return ns->ns_id; 1249 return ns->ns_id;
1206 case NVME_IOCTL_ADMIN_CMD: 1250 case NVME_IOCTL_ADMIN_CMD:
1207 return nvme_user_admin_cmd(ns, (void __user *)arg); 1251 return nvme_user_admin_cmd(ns->dev, (void __user *)arg);
1208 case NVME_IOCTL_SUBMIT_IO: 1252 case NVME_IOCTL_SUBMIT_IO:
1209 return nvme_submit_io(ns, (void __user *)arg); 1253 return nvme_submit_io(ns, (void __user *)arg);
1210 default: 1254 default:
@@ -1218,26 +1262,6 @@ static const struct block_device_operations nvme_fops = {
1218 .compat_ioctl = nvme_ioctl, 1262 .compat_ioctl = nvme_ioctl,
1219}; 1263};
1220 1264
1221static void nvme_timeout_ios(struct nvme_queue *nvmeq)
1222{
1223 int depth = nvmeq->q_depth - 1;
1224 struct nvme_cmd_info *info = nvme_cmd_info(nvmeq);
1225 unsigned long now = jiffies;
1226 int cmdid;
1227
1228 for_each_set_bit(cmdid, nvmeq->cmdid_data, depth) {
1229 void *ctx;
1230 nvme_completion_fn fn;
1231 static struct nvme_completion cqe = { .status = cpu_to_le16(NVME_SC_ABORT_REQ) << 1, };
1232
1233 if (!time_after(now, info[cmdid].timeout))
1234 continue;
1235 dev_warn(nvmeq->q_dmadev, "Timing out I/O %d\n", cmdid);
1236 ctx = cancel_cmdid(nvmeq, cmdid, &fn);
1237 fn(nvmeq->dev, ctx, &cqe);
1238 }
1239}
1240
1241static void nvme_resubmit_bios(struct nvme_queue *nvmeq) 1265static void nvme_resubmit_bios(struct nvme_queue *nvmeq)
1242{ 1266{
1243 while (bio_list_peek(&nvmeq->sq_cong)) { 1267 while (bio_list_peek(&nvmeq->sq_cong)) {
@@ -1269,7 +1293,7 @@ static int nvme_kthread(void *data)
1269 spin_lock_irq(&nvmeq->q_lock); 1293 spin_lock_irq(&nvmeq->q_lock);
1270 if (nvme_process_cq(nvmeq)) 1294 if (nvme_process_cq(nvmeq))
1271 printk("process_cq did something\n"); 1295 printk("process_cq did something\n");
1272 nvme_timeout_ios(nvmeq); 1296 nvme_cancel_ios(nvmeq, true);
1273 nvme_resubmit_bios(nvmeq); 1297 nvme_resubmit_bios(nvmeq);
1274 spin_unlock_irq(&nvmeq->q_lock); 1298 spin_unlock_irq(&nvmeq->q_lock);
1275 } 1299 }
@@ -1339,6 +1363,9 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, int nsid,
1339 ns->disk = disk; 1363 ns->disk = disk;
1340 lbaf = id->flbas & 0xf; 1364 lbaf = id->flbas & 0xf;
1341 ns->lba_shift = id->lbaf[lbaf].ds; 1365 ns->lba_shift = id->lbaf[lbaf].ds;
1366 blk_queue_logical_block_size(ns->queue, 1 << ns->lba_shift);
1367 if (dev->max_hw_sectors)
1368 blk_queue_max_hw_sectors(ns->queue, dev->max_hw_sectors);
1342 1369
1343 disk->major = nvme_major; 1370 disk->major = nvme_major;
1344 disk->minors = NVME_MINORS; 1371 disk->minors = NVME_MINORS;
@@ -1383,7 +1410,7 @@ static int set_queue_count(struct nvme_dev *dev, int count)
1383 1410
1384static int __devinit nvme_setup_io_queues(struct nvme_dev *dev) 1411static int __devinit nvme_setup_io_queues(struct nvme_dev *dev)
1385{ 1412{
1386 int result, cpu, i, nr_io_queues, db_bar_size; 1413 int result, cpu, i, nr_io_queues, db_bar_size, q_depth;
1387 1414
1388 nr_io_queues = num_online_cpus(); 1415 nr_io_queues = num_online_cpus();
1389 result = set_queue_count(dev, nr_io_queues); 1416 result = set_queue_count(dev, nr_io_queues);
@@ -1429,9 +1456,10 @@ static int __devinit nvme_setup_io_queues(struct nvme_dev *dev)
1429 cpu = cpumask_next(cpu, cpu_online_mask); 1456 cpu = cpumask_next(cpu, cpu_online_mask);
1430 } 1457 }
1431 1458
1459 q_depth = min_t(int, NVME_CAP_MQES(readq(&dev->bar->cap)) + 1,
1460 NVME_Q_DEPTH);
1432 for (i = 0; i < nr_io_queues; i++) { 1461 for (i = 0; i < nr_io_queues; i++) {
1433 dev->queues[i + 1] = nvme_create_queue(dev, i + 1, 1462 dev->queues[i + 1] = nvme_create_queue(dev, i + 1, q_depth, i);
1434 NVME_Q_DEPTH, i);
1435 if (IS_ERR(dev->queues[i + 1])) 1463 if (IS_ERR(dev->queues[i + 1]))
1436 return PTR_ERR(dev->queues[i + 1]); 1464 return PTR_ERR(dev->queues[i + 1]);
1437 dev->queue_count++; 1465 dev->queue_count++;
@@ -1480,6 +1508,10 @@ static int __devinit nvme_dev_add(struct nvme_dev *dev)
1480 memcpy(dev->serial, ctrl->sn, sizeof(ctrl->sn)); 1508 memcpy(dev->serial, ctrl->sn, sizeof(ctrl->sn));
1481 memcpy(dev->model, ctrl->mn, sizeof(ctrl->mn)); 1509 memcpy(dev->model, ctrl->mn, sizeof(ctrl->mn));
1482 memcpy(dev->firmware_rev, ctrl->fr, sizeof(ctrl->fr)); 1510 memcpy(dev->firmware_rev, ctrl->fr, sizeof(ctrl->fr));
1511 if (ctrl->mdts) {
1512 int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12;
1513 dev->max_hw_sectors = 1 << (ctrl->mdts + shift - 9);
1514 }
1483 1515
1484 id_ns = mem; 1516 id_ns = mem;
1485 for (i = 1; i <= nn; i++) { 1517 for (i = 1; i <= nn; i++) {
@@ -1523,8 +1555,6 @@ static int nvme_dev_remove(struct nvme_dev *dev)
1523 list_del(&dev->node); 1555 list_del(&dev->node);
1524 spin_unlock(&dev_list_lock); 1556 spin_unlock(&dev_list_lock);
1525 1557
1526 /* TODO: wait all I/O finished or cancel them */
1527
1528 list_for_each_entry_safe(ns, next, &dev->namespaces, list) { 1558 list_for_each_entry_safe(ns, next, &dev->namespaces, list) {
1529 list_del(&ns->list); 1559 list_del(&ns->list);
1530 del_gendisk(ns->disk); 1560 del_gendisk(ns->disk);
@@ -1560,15 +1590,33 @@ static void nvme_release_prp_pools(struct nvme_dev *dev)
1560 dma_pool_destroy(dev->prp_small_pool); 1590 dma_pool_destroy(dev->prp_small_pool);
1561} 1591}
1562 1592
1563/* XXX: Use an ida or something to let remove / add work correctly */ 1593static DEFINE_IDA(nvme_instance_ida);
1564static void nvme_set_instance(struct nvme_dev *dev) 1594
1595static int nvme_set_instance(struct nvme_dev *dev)
1565{ 1596{
1566 static int instance; 1597 int instance, error;
1567 dev->instance = instance++; 1598
1599 do {
1600 if (!ida_pre_get(&nvme_instance_ida, GFP_KERNEL))
1601 return -ENODEV;
1602
1603 spin_lock(&dev_list_lock);
1604 error = ida_get_new(&nvme_instance_ida, &instance);
1605 spin_unlock(&dev_list_lock);
1606 } while (error == -EAGAIN);
1607
1608 if (error)
1609 return -ENODEV;
1610
1611 dev->instance = instance;
1612 return 0;
1568} 1613}
1569 1614
1570static void nvme_release_instance(struct nvme_dev *dev) 1615static void nvme_release_instance(struct nvme_dev *dev)
1571{ 1616{
1617 spin_lock(&dev_list_lock);
1618 ida_remove(&nvme_instance_ida, dev->instance);
1619 spin_unlock(&dev_list_lock);
1572} 1620}
1573 1621
1574static int __devinit nvme_probe(struct pci_dev *pdev, 1622static int __devinit nvme_probe(struct pci_dev *pdev,
@@ -1601,7 +1649,10 @@ static int __devinit nvme_probe(struct pci_dev *pdev,
1601 pci_set_drvdata(pdev, dev); 1649 pci_set_drvdata(pdev, dev);
1602 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); 1650 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
1603 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); 1651 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
1604 nvme_set_instance(dev); 1652 result = nvme_set_instance(dev);
1653 if (result)
1654 goto disable;
1655
1605 dev->entry[0].vector = pdev->irq; 1656 dev->entry[0].vector = pdev->irq;
1606 1657
1607 result = nvme_setup_prp_pools(dev); 1658 result = nvme_setup_prp_pools(dev);
@@ -1704,15 +1755,17 @@ static struct pci_driver nvme_driver = {
1704 1755
1705static int __init nvme_init(void) 1756static int __init nvme_init(void)
1706{ 1757{
1707 int result = -EBUSY; 1758 int result;
1708 1759
1709 nvme_thread = kthread_run(nvme_kthread, NULL, "nvme"); 1760 nvme_thread = kthread_run(nvme_kthread, NULL, "nvme");
1710 if (IS_ERR(nvme_thread)) 1761 if (IS_ERR(nvme_thread))
1711 return PTR_ERR(nvme_thread); 1762 return PTR_ERR(nvme_thread);
1712 1763
1713 nvme_major = register_blkdev(nvme_major, "nvme"); 1764 result = register_blkdev(nvme_major, "nvme");
1714 if (nvme_major <= 0) 1765 if (result < 0)
1715 goto kill_kthread; 1766 goto kill_kthread;
1767 else if (result > 0)
1768 nvme_major = result;
1716 1769
1717 result = pci_register_driver(&nvme_driver); 1770 result = pci_register_driver(&nvme_driver);
1718 if (result) 1771 if (result)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 9917943a3572..54a55f03115d 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -246,13 +246,12 @@ static int rbd_open(struct block_device *bdev, fmode_t mode)
246{ 246{
247 struct rbd_device *rbd_dev = bdev->bd_disk->private_data; 247 struct rbd_device *rbd_dev = bdev->bd_disk->private_data;
248 248
249 rbd_get_dev(rbd_dev);
250
251 set_device_ro(bdev, rbd_dev->read_only);
252
253 if ((mode & FMODE_WRITE) && rbd_dev->read_only) 249 if ((mode & FMODE_WRITE) && rbd_dev->read_only)
254 return -EROFS; 250 return -EROFS;
255 251
252 rbd_get_dev(rbd_dev);
253 set_device_ro(bdev, rbd_dev->read_only);
254
256 return 0; 255 return 0;
257} 256}
258 257
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index 73f196ca713f..c6decb901e5e 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -337,7 +337,7 @@ static void xen_blkbk_unmap(struct pending_req *req)
337 invcount++; 337 invcount++;
338 } 338 }
339 339
340 ret = gnttab_unmap_refs(unmap, pages, invcount, false); 340 ret = gnttab_unmap_refs(unmap, NULL, pages, invcount);
341 BUG_ON(ret); 341 BUG_ON(ret);
342} 342}
343 343
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 11f36e502136..fc2de5528dcc 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -86,6 +86,7 @@ static struct usb_device_id ath3k_table[] = {
86 86
87 /* Atheros AR5BBU22 with sflash firmware */ 87 /* Atheros AR5BBU22 with sflash firmware */
88 { USB_DEVICE(0x0489, 0xE03C) }, 88 { USB_DEVICE(0x0489, 0xE03C) },
89 { USB_DEVICE(0x0489, 0xE036) },
89 90
90 { } /* Terminating entry */ 91 { } /* Terminating entry */
91}; 92};
@@ -109,6 +110,7 @@ static struct usb_device_id ath3k_blist_tbl[] = {
109 110
110 /* Atheros AR5BBU22 with sflash firmware */ 111 /* Atheros AR5BBU22 with sflash firmware */
111 { USB_DEVICE(0x0489, 0xE03C), .driver_info = BTUSB_ATH3012 }, 112 { USB_DEVICE(0x0489, 0xE03C), .driver_info = BTUSB_ATH3012 },
113 { USB_DEVICE(0x0489, 0xE036), .driver_info = BTUSB_ATH3012 },
112 114
113 { } /* Terminating entry */ 115 { } /* Terminating entry */
114}; 116};
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index cef3bac1a543..654e248763ef 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -52,6 +52,9 @@ static struct usb_device_id btusb_table[] = {
52 /* Generic Bluetooth USB device */ 52 /* Generic Bluetooth USB device */
53 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, 53 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
54 54
55 /* Apple-specific (Broadcom) devices */
56 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01) },
57
55 /* Broadcom SoftSailing reporting vendor specific */ 58 /* Broadcom SoftSailing reporting vendor specific */
56 { USB_DEVICE(0x0a5c, 0x21e1) }, 59 { USB_DEVICE(0x0a5c, 0x21e1) },
57 60
@@ -94,16 +97,14 @@ static struct usb_device_id btusb_table[] = {
94 97
95 /* Broadcom BCM20702A0 */ 98 /* Broadcom BCM20702A0 */
96 { USB_DEVICE(0x0489, 0xe042) }, 99 { USB_DEVICE(0x0489, 0xe042) },
97 { USB_DEVICE(0x0a5c, 0x21e3) },
98 { USB_DEVICE(0x0a5c, 0x21e6) },
99 { USB_DEVICE(0x0a5c, 0x21e8) },
100 { USB_DEVICE(0x0a5c, 0x21f3) },
101 { USB_DEVICE(0x0a5c, 0x21f4) },
102 { USB_DEVICE(0x413c, 0x8197) }, 100 { USB_DEVICE(0x413c, 0x8197) },
103 101
104 /* Foxconn - Hon Hai */ 102 /* Foxconn - Hon Hai */
105 { USB_DEVICE(0x0489, 0xe033) }, 103 { USB_DEVICE(0x0489, 0xe033) },
106 104
105 /*Broadcom devices with vendor specific id */
106 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01) },
107
107 { } /* Terminating entry */ 108 { } /* Terminating entry */
108}; 109};
109 110
@@ -141,6 +142,7 @@ static struct usb_device_id blacklist_table[] = {
141 142
142 /* Atheros AR5BBU12 with sflash firmware */ 143 /* Atheros AR5BBU12 with sflash firmware */
143 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, 144 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
145 { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 },
144 146
145 /* Broadcom BCM2035 */ 147 /* Broadcom BCM2035 */
146 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, 148 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 5869ea387054..72ce247a0e8d 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -1,4 +1,5 @@
1# common clock types 1# common clock types
2obj-$(CONFIG_HAVE_CLK) += clk-devres.o
2obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o 3obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o
3obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed-rate.o clk-gate.o \ 4obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed-rate.o clk-gate.o \
4 clk-mux.o clk-divider.o clk-fixed-factor.o 5 clk-mux.o clk-divider.o clk-fixed-factor.o
diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
new file mode 100644
index 000000000000..8f571548870f
--- /dev/null
+++ b/drivers/clk/clk-devres.c
@@ -0,0 +1,55 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 */
6
7#include <linux/clk.h>
8#include <linux/device.h>
9#include <linux/export.h>
10#include <linux/gfp.h>
11
12static void devm_clk_release(struct device *dev, void *res)
13{
14 clk_put(*(struct clk **)res);
15}
16
17struct clk *devm_clk_get(struct device *dev, const char *id)
18{
19 struct clk **ptr, *clk;
20
21 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
22 if (!ptr)
23 return ERR_PTR(-ENOMEM);
24
25 clk = clk_get(dev, id);
26 if (!IS_ERR(clk)) {
27 *ptr = clk;
28 devres_add(dev, ptr);
29 } else {
30 devres_free(ptr);
31 }
32
33 return clk;
34}
35EXPORT_SYMBOL(devm_clk_get);
36
37static int devm_clk_match(struct device *dev, void *res, void *data)
38{
39 struct clk **c = res;
40 if (!c || !*c) {
41 WARN_ON(!c || !*c);
42 return 0;
43 }
44 return *c == data;
45}
46
47void devm_clk_put(struct device *dev, struct clk *clk)
48{
49 int ret;
50
51 ret = devres_release(dev, devm_clk_release, devm_clk_match, clk);
52
53 WARN_ON(ret);
54}
55EXPORT_SYMBOL(devm_clk_put);
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index d423c9bdd71a..442a31363873 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -171,51 +171,6 @@ void clk_put(struct clk *clk)
171} 171}
172EXPORT_SYMBOL(clk_put); 172EXPORT_SYMBOL(clk_put);
173 173
174static void devm_clk_release(struct device *dev, void *res)
175{
176 clk_put(*(struct clk **)res);
177}
178
179struct clk *devm_clk_get(struct device *dev, const char *id)
180{
181 struct clk **ptr, *clk;
182
183 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
184 if (!ptr)
185 return ERR_PTR(-ENOMEM);
186
187 clk = clk_get(dev, id);
188 if (!IS_ERR(clk)) {
189 *ptr = clk;
190 devres_add(dev, ptr);
191 } else {
192 devres_free(ptr);
193 }
194
195 return clk;
196}
197EXPORT_SYMBOL(devm_clk_get);
198
199static int devm_clk_match(struct device *dev, void *res, void *data)
200{
201 struct clk **c = res;
202 if (!c || !*c) {
203 WARN_ON(!c || !*c);
204 return 0;
205 }
206 return *c == data;
207}
208
209void devm_clk_put(struct device *dev, struct clk *clk)
210{
211 int ret;
212
213 ret = devres_destroy(dev, devm_clk_release, devm_clk_match, clk);
214
215 WARN_ON(ret);
216}
217EXPORT_SYMBOL(devm_clk_put);
218
219void clkdev_add(struct clk_lookup *cl) 174void clkdev_add(struct clk_lookup *cl)
220{ 175{
221 mutex_lock(&clocks_mutex); 176 mutex_lock(&clocks_mutex);
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index c0e816468e30..1a40935c85fd 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -35,7 +35,6 @@
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/string.h> 36#include <linux/string.h>
37#include <linux/cpumask.h> 37#include <linux/cpumask.h>
38#include <linux/sched.h> /* for current / set_cpus_allowed() */
39#include <linux/io.h> 38#include <linux/io.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
41 40
@@ -1139,16 +1138,23 @@ static int transition_frequency_pstate(struct powernow_k8_data *data,
1139 return res; 1138 return res;
1140} 1139}
1141 1140
1142/* Driver entry point to switch to the target frequency */ 1141struct powernowk8_target_arg {
1143static int powernowk8_target(struct cpufreq_policy *pol, 1142 struct cpufreq_policy *pol;
1144 unsigned targfreq, unsigned relation) 1143 unsigned targfreq;
1144 unsigned relation;
1145};
1146
1147static long powernowk8_target_fn(void *arg)
1145{ 1148{
1146 cpumask_var_t oldmask; 1149 struct powernowk8_target_arg *pta = arg;
1150 struct cpufreq_policy *pol = pta->pol;
1151 unsigned targfreq = pta->targfreq;
1152 unsigned relation = pta->relation;
1147 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); 1153 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
1148 u32 checkfid; 1154 u32 checkfid;
1149 u32 checkvid; 1155 u32 checkvid;
1150 unsigned int newstate; 1156 unsigned int newstate;
1151 int ret = -EIO; 1157 int ret;
1152 1158
1153 if (!data) 1159 if (!data)
1154 return -EINVAL; 1160 return -EINVAL;
@@ -1156,29 +1162,16 @@ static int powernowk8_target(struct cpufreq_policy *pol,
1156 checkfid = data->currfid; 1162 checkfid = data->currfid;
1157 checkvid = data->currvid; 1163 checkvid = data->currvid;
1158 1164
1159 /* only run on specific CPU from here on. */
1160 /* This is poor form: use a workqueue or smp_call_function_single */
1161 if (!alloc_cpumask_var(&oldmask, GFP_KERNEL))
1162 return -ENOMEM;
1163
1164 cpumask_copy(oldmask, tsk_cpus_allowed(current));
1165 set_cpus_allowed_ptr(current, cpumask_of(pol->cpu));
1166
1167 if (smp_processor_id() != pol->cpu) {
1168 printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu);
1169 goto err_out;
1170 }
1171
1172 if (pending_bit_stuck()) { 1165 if (pending_bit_stuck()) {
1173 printk(KERN_ERR PFX "failing targ, change pending bit set\n"); 1166 printk(KERN_ERR PFX "failing targ, change pending bit set\n");
1174 goto err_out; 1167 return -EIO;
1175 } 1168 }
1176 1169
1177 pr_debug("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n", 1170 pr_debug("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n",
1178 pol->cpu, targfreq, pol->min, pol->max, relation); 1171 pol->cpu, targfreq, pol->min, pol->max, relation);
1179 1172
1180 if (query_current_values_with_pending_wait(data)) 1173 if (query_current_values_with_pending_wait(data))
1181 goto err_out; 1174 return -EIO;
1182 1175
1183 if (cpu_family != CPU_HW_PSTATE) { 1176 if (cpu_family != CPU_HW_PSTATE) {
1184 pr_debug("targ: curr fid 0x%x, vid 0x%x\n", 1177 pr_debug("targ: curr fid 0x%x, vid 0x%x\n",
@@ -1196,7 +1189,7 @@ static int powernowk8_target(struct cpufreq_policy *pol,
1196 1189
1197 if (cpufreq_frequency_table_target(pol, data->powernow_table, 1190 if (cpufreq_frequency_table_target(pol, data->powernow_table,
1198 targfreq, relation, &newstate)) 1191 targfreq, relation, &newstate))
1199 goto err_out; 1192 return -EIO;
1200 1193
1201 mutex_lock(&fidvid_mutex); 1194 mutex_lock(&fidvid_mutex);
1202 1195
@@ -1209,9 +1202,8 @@ static int powernowk8_target(struct cpufreq_policy *pol,
1209 ret = transition_frequency_fidvid(data, newstate); 1202 ret = transition_frequency_fidvid(data, newstate);
1210 if (ret) { 1203 if (ret) {
1211 printk(KERN_ERR PFX "transition frequency failed\n"); 1204 printk(KERN_ERR PFX "transition frequency failed\n");
1212 ret = 1;
1213 mutex_unlock(&fidvid_mutex); 1205 mutex_unlock(&fidvid_mutex);
1214 goto err_out; 1206 return 1;
1215 } 1207 }
1216 mutex_unlock(&fidvid_mutex); 1208 mutex_unlock(&fidvid_mutex);
1217 1209
@@ -1220,12 +1212,25 @@ static int powernowk8_target(struct cpufreq_policy *pol,
1220 data->powernow_table[newstate].index); 1212 data->powernow_table[newstate].index);
1221 else 1213 else
1222 pol->cur = find_khz_freq_from_fid(data->currfid); 1214 pol->cur = find_khz_freq_from_fid(data->currfid);
1223 ret = 0;
1224 1215
1225err_out: 1216 return 0;
1226 set_cpus_allowed_ptr(current, oldmask); 1217}
1227 free_cpumask_var(oldmask); 1218
1228 return ret; 1219/* Driver entry point to switch to the target frequency */
1220static int powernowk8_target(struct cpufreq_policy *pol,
1221 unsigned targfreq, unsigned relation)
1222{
1223 struct powernowk8_target_arg pta = { .pol = pol, .targfreq = targfreq,
1224 .relation = relation };
1225
1226 /*
1227 * Must run on @pol->cpu. cpufreq core is responsible for ensuring
1228 * that we're bound to the current CPU and pol->cpu stays online.
1229 */
1230 if (smp_processor_id() == pol->cpu)
1231 return powernowk8_target_fn(&pta);
1232 else
1233 return work_on_cpu(pol->cpu, powernowk8_target_fn, &pta);
1229} 1234}
1230 1235
1231/* Driver entry point to verify the policy and range of frequencies */ 1236/* Driver entry point to verify the policy and range of frequencies */
diff --git a/drivers/crypto/caam/key_gen.c b/drivers/crypto/caam/key_gen.c
index 002888185f17..d216cd3cc569 100644
--- a/drivers/crypto/caam/key_gen.c
+++ b/drivers/crypto/caam/key_gen.c
@@ -120,3 +120,4 @@ u32 gen_split_key(struct device *jrdev, u8 *key_out, int split_key_len,
120 120
121 return ret; 121 return ret;
122} 122}
123EXPORT_SYMBOL(gen_split_key);
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 3934fcc4e00b..17d6958342e7 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -168,9 +168,9 @@ static void atc_desc_put(struct at_dma_chan *atchan, struct at_desc *desc)
168} 168}
169 169
170/** 170/**
171 * atc_desc_chain - build chain adding a descripor 171 * atc_desc_chain - build chain adding a descriptor
172 * @first: address of first descripor of the chain 172 * @first: address of first descriptor of the chain
173 * @prev: address of previous descripor of the chain 173 * @prev: address of previous descriptor of the chain
174 * @desc: descriptor to queue 174 * @desc: descriptor to queue
175 * 175 *
176 * Called from prep_* functions 176 * Called from prep_* functions
@@ -661,7 +661,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
661 flags); 661 flags);
662 662
663 if (unlikely(!atslave || !sg_len)) { 663 if (unlikely(!atslave || !sg_len)) {
664 dev_dbg(chan2dev(chan), "prep_dma_memcpy: length is zero!\n"); 664 dev_dbg(chan2dev(chan), "prep_slave_sg: sg length is zero!\n");
665 return NULL; 665 return NULL;
666 } 666 }
667 667
@@ -689,6 +689,11 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
689 689
690 mem = sg_dma_address(sg); 690 mem = sg_dma_address(sg);
691 len = sg_dma_len(sg); 691 len = sg_dma_len(sg);
692 if (unlikely(!len)) {
693 dev_dbg(chan2dev(chan),
694 "prep_slave_sg: sg(%d) data length is zero\n", i);
695 goto err;
696 }
692 mem_width = 2; 697 mem_width = 2;
693 if (unlikely(mem & 3 || len & 3)) 698 if (unlikely(mem & 3 || len & 3))
694 mem_width = 0; 699 mem_width = 0;
@@ -724,6 +729,11 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
724 729
725 mem = sg_dma_address(sg); 730 mem = sg_dma_address(sg);
726 len = sg_dma_len(sg); 731 len = sg_dma_len(sg);
732 if (unlikely(!len)) {
733 dev_dbg(chan2dev(chan),
734 "prep_slave_sg: sg(%d) data length is zero\n", i);
735 goto err;
736 }
727 mem_width = 2; 737 mem_width = 2;
728 if (unlikely(mem & 3 || len & 3)) 738 if (unlikely(mem & 3 || len & 3))
729 mem_width = 0; 739 mem_width = 0;
@@ -757,6 +767,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
757 767
758err_desc_get: 768err_desc_get:
759 dev_err(chan2dev(chan), "not enough descriptors available\n"); 769 dev_err(chan2dev(chan), "not enough descriptors available\n");
770err:
760 atc_desc_put(atchan, first); 771 atc_desc_put(atchan, first);
761 return NULL; 772 return NULL;
762} 773}
@@ -785,7 +796,7 @@ err_out:
785} 796}
786 797
787/** 798/**
788 * atc_dma_cyclic_fill_desc - Fill one period decriptor 799 * atc_dma_cyclic_fill_desc - Fill one period descriptor
789 */ 800 */
790static int 801static int
791atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc, 802atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc,
diff --git a/drivers/dma/ep93xx_dma.c b/drivers/dma/ep93xx_dma.c
index c64917ec313d..bb02fd981afb 100644
--- a/drivers/dma/ep93xx_dma.c
+++ b/drivers/dma/ep93xx_dma.c
@@ -1118,7 +1118,7 @@ fail:
1118 * @chan: channel 1118 * @chan: channel
1119 * @dma_addr: DMA mapped address of the buffer 1119 * @dma_addr: DMA mapped address of the buffer
1120 * @buf_len: length of the buffer (in bytes) 1120 * @buf_len: length of the buffer (in bytes)
1121 * @period_len: lenght of a single period 1121 * @period_len: length of a single period
1122 * @dir: direction of the operation 1122 * @dir: direction of the operation
1123 * @context: operation context (ignored) 1123 * @context: operation context (ignored)
1124 * 1124 *
diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c
index 8f84761f98ba..094437b9d823 100644
--- a/drivers/dma/fsldma.c
+++ b/drivers/dma/fsldma.c
@@ -1015,7 +1015,7 @@ static irqreturn_t fsldma_chan_irq(int irq, void *data)
1015 /* 1015 /*
1016 * Programming Error 1016 * Programming Error
1017 * The DMA_INTERRUPT async_tx is a NULL transfer, which will 1017 * The DMA_INTERRUPT async_tx is a NULL transfer, which will
1018 * triger a PE interrupt. 1018 * trigger a PE interrupt.
1019 */ 1019 */
1020 if (stat & FSL_DMA_SR_PE) { 1020 if (stat & FSL_DMA_SR_PE) {
1021 chan_dbg(chan, "irq: Programming Error INT\n"); 1021 chan_dbg(chan, "irq: Programming Error INT\n");
diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c
index 5084975d793c..54f580bb993c 100644
--- a/drivers/dma/imx-dma.c
+++ b/drivers/dma/imx-dma.c
@@ -572,8 +572,8 @@ static void imxdma_tasklet(unsigned long data)
572 if (desc->desc.callback) 572 if (desc->desc.callback)
573 desc->desc.callback(desc->desc.callback_param); 573 desc->desc.callback(desc->desc.callback_param);
574 574
575 /* If we are dealing with a cyclic descriptor keep it on ld_active 575 /* If we are dealing with a cyclic descriptor, keep it on ld_active
576 * and dont mark the descripor as complete. 576 * and dont mark the descriptor as complete.
577 * Only in non-cyclic cases it would be marked as complete 577 * Only in non-cyclic cases it would be marked as complete
578 */ 578 */
579 if (imxdma_chan_is_doing_cyclic(imxdmac)) 579 if (imxdma_chan_is_doing_cyclic(imxdmac))
diff --git a/drivers/dma/intel_mid_dma.c b/drivers/dma/intel_mid_dma.c
index 222e907bfaaa..02b21d7d38e5 100644
--- a/drivers/dma/intel_mid_dma.c
+++ b/drivers/dma/intel_mid_dma.c
@@ -427,7 +427,7 @@ DMA engine callback Functions*/
427 * intel_mid_dma_tx_submit - callback to submit DMA transaction 427 * intel_mid_dma_tx_submit - callback to submit DMA transaction
428 * @tx: dma engine descriptor 428 * @tx: dma engine descriptor
429 * 429 *
430 * Submit the DMA trasaction for this descriptor, start if ch idle 430 * Submit the DMA transaction for this descriptor, start if ch idle
431 */ 431 */
432static dma_cookie_t intel_mid_dma_tx_submit(struct dma_async_tx_descriptor *tx) 432static dma_cookie_t intel_mid_dma_tx_submit(struct dma_async_tx_descriptor *tx)
433{ 433{
diff --git a/drivers/dma/intel_mid_dma_regs.h b/drivers/dma/intel_mid_dma_regs.h
index 1bfa9268feaf..17b42192ea58 100644
--- a/drivers/dma/intel_mid_dma_regs.h
+++ b/drivers/dma/intel_mid_dma_regs.h
@@ -168,9 +168,9 @@ union intel_mid_dma_cfg_hi {
168 * @active_list: current active descriptors 168 * @active_list: current active descriptors
169 * @queue: current queued up descriptors 169 * @queue: current queued up descriptors
170 * @free_list: current free descriptors 170 * @free_list: current free descriptors
171 * @slave: dma slave struture 171 * @slave: dma slave structure
172 * @descs_allocated: total number of decsiptors allocated 172 * @descs_allocated: total number of descriptors allocated
173 * @dma: dma device struture pointer 173 * @dma: dma device structure pointer
174 * @busy: bool representing if ch is busy (active txn) or not 174 * @busy: bool representing if ch is busy (active txn) or not
175 * @in_use: bool representing if ch is in use or not 175 * @in_use: bool representing if ch is in use or not
176 * @raw_tfr: raw trf interrupt received 176 * @raw_tfr: raw trf interrupt received
diff --git a/drivers/dma/ioat/hw.h b/drivers/dma/ioat/hw.h
index 60e675455b6a..d2ff3fda0b18 100644
--- a/drivers/dma/ioat/hw.h
+++ b/drivers/dma/ioat/hw.h
@@ -22,7 +22,6 @@
22#define _IOAT_HW_H_ 22#define _IOAT_HW_H_
23 23
24/* PCI Configuration Space Values */ 24/* PCI Configuration Space Values */
25#define IOAT_PCI_VID 0x8086
26#define IOAT_MMIO_BAR 0 25#define IOAT_MMIO_BAR 0
27 26
28/* CB device ID's */ 27/* CB device ID's */
@@ -31,9 +30,6 @@
31#define IOAT_PCI_DID_SCNB 0x65FF 30#define IOAT_PCI_DID_SCNB 0x65FF
32#define IOAT_PCI_DID_SNB 0x402F 31#define IOAT_PCI_DID_SNB 0x402F
33 32
34#define IOAT_PCI_RID 0x00
35#define IOAT_PCI_SVID 0x8086
36#define IOAT_PCI_SID 0x8086
37#define IOAT_VER_1_2 0x12 /* Version 1.2 */ 33#define IOAT_VER_1_2 0x12 /* Version 1.2 */
38#define IOAT_VER_2_0 0x20 /* Version 2.0 */ 34#define IOAT_VER_2_0 0x20 /* Version 2.0 */
39#define IOAT_VER_3_0 0x30 /* Version 3.0 */ 35#define IOAT_VER_3_0 0x30 /* Version 3.0 */
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index e4feba6b03c0..5d3bbcd279b4 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -522,7 +522,7 @@ enum desc_status {
522 /* In the DMAC pool */ 522 /* In the DMAC pool */
523 FREE, 523 FREE,
524 /* 524 /*
525 * Allocted to some channel during prep_xxx 525 * Allocated to some channel during prep_xxx
526 * Also may be sitting on the work_list. 526 * Also may be sitting on the work_list.
527 */ 527 */
528 PREP, 528 PREP,
@@ -1567,17 +1567,19 @@ static int pl330_submit_req(void *ch_id, struct pl330_req *r)
1567 goto xfer_exit; 1567 goto xfer_exit;
1568 } 1568 }
1569 1569
1570 /* Prefer Secure Channel */
1571 if (!_manager_ns(thrd))
1572 r->cfg->nonsecure = 0;
1573 else
1574 r->cfg->nonsecure = 1;
1575 1570
1576 /* Use last settings, if not provided */ 1571 /* Use last settings, if not provided */
1577 if (r->cfg) 1572 if (r->cfg) {
1573 /* Prefer Secure Channel */
1574 if (!_manager_ns(thrd))
1575 r->cfg->nonsecure = 0;
1576 else
1577 r->cfg->nonsecure = 1;
1578
1578 ccr = _prepare_ccr(r->cfg); 1579 ccr = _prepare_ccr(r->cfg);
1579 else 1580 } else {
1580 ccr = readl(regs + CC(thrd->id)); 1581 ccr = readl(regs + CC(thrd->id));
1582 }
1581 1583
1582 /* If this req doesn't have valid xfer settings */ 1584 /* If this req doesn't have valid xfer settings */
1583 if (!_is_valid(ccr)) { 1585 if (!_is_valid(ccr)) {
@@ -2928,6 +2930,11 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
2928 num_chan = max_t(int, pi->pcfg.num_peri, pi->pcfg.num_chan); 2930 num_chan = max_t(int, pi->pcfg.num_peri, pi->pcfg.num_chan);
2929 2931
2930 pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL); 2932 pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
2933 if (!pdmac->peripherals) {
2934 ret = -ENOMEM;
2935 dev_err(&adev->dev, "unable to allocate pdmac->peripherals\n");
2936 goto probe_err5;
2937 }
2931 2938
2932 for (i = 0; i < num_chan; i++) { 2939 for (i = 0; i < num_chan; i++) {
2933 pch = &pdmac->peripherals[i]; 2940 pch = &pdmac->peripherals[i];
diff --git a/drivers/dma/ppc4xx/adma.c b/drivers/dma/ppc4xx/adma.c
index ced98826684a..f72348d0bc41 100644
--- a/drivers/dma/ppc4xx/adma.c
+++ b/drivers/dma/ppc4xx/adma.c
@@ -4446,7 +4446,7 @@ static int __devinit ppc440spe_adma_probe(struct platform_device *ofdev)
4446 ret = -ENOMEM; 4446 ret = -ENOMEM;
4447 goto err_dma_alloc; 4447 goto err_dma_alloc;
4448 } 4448 }
4449 dev_dbg(&ofdev->dev, "allocted descriptor pool virt 0x%p phys 0x%llx\n", 4449 dev_dbg(&ofdev->dev, "allocated descriptor pool virt 0x%p phys 0x%llx\n",
4450 adev->dma_desc_pool_virt, (u64)adev->dma_desc_pool); 4450 adev->dma_desc_pool_virt, (u64)adev->dma_desc_pool);
4451 4451
4452 regs = ioremap(res.start, resource_size(&res)); 4452 regs = ioremap(res.start, resource_size(&res));
diff --git a/drivers/dma/ste_dma40_ll.h b/drivers/dma/ste_dma40_ll.h
index 51e8e5396e9b..6d47373f3f58 100644
--- a/drivers/dma/ste_dma40_ll.h
+++ b/drivers/dma/ste_dma40_ll.h
@@ -202,7 +202,7 @@
202/* LLI related structures */ 202/* LLI related structures */
203 203
204/** 204/**
205 * struct d40_phy_lli - The basic configration register for each physical 205 * struct d40_phy_lli - The basic configuration register for each physical
206 * channel. 206 * channel.
207 * 207 *
208 * @reg_cfg: The configuration register. 208 * @reg_cfg: The configuration register.
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 616d90bcb3a4..d5dc9da7f99f 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -199,6 +199,36 @@ void *edac_align_ptr(void **p, unsigned size, int n_elems)
199 return (void *)(((unsigned long)ptr) + align - r); 199 return (void *)(((unsigned long)ptr) + align - r);
200} 200}
201 201
202static void _edac_mc_free(struct mem_ctl_info *mci)
203{
204 int i, chn, row;
205 struct csrow_info *csr;
206 const unsigned int tot_dimms = mci->tot_dimms;
207 const unsigned int tot_channels = mci->num_cschannel;
208 const unsigned int tot_csrows = mci->nr_csrows;
209
210 if (mci->dimms) {
211 for (i = 0; i < tot_dimms; i++)
212 kfree(mci->dimms[i]);
213 kfree(mci->dimms);
214 }
215 if (mci->csrows) {
216 for (row = 0; row < tot_csrows; row++) {
217 csr = mci->csrows[row];
218 if (csr) {
219 if (csr->channels) {
220 for (chn = 0; chn < tot_channels; chn++)
221 kfree(csr->channels[chn]);
222 kfree(csr->channels);
223 }
224 kfree(csr);
225 }
226 }
227 kfree(mci->csrows);
228 }
229 kfree(mci);
230}
231
202/** 232/**
203 * edac_mc_alloc: Allocate and partially fill a struct mem_ctl_info structure 233 * edac_mc_alloc: Allocate and partially fill a struct mem_ctl_info structure
204 * @mc_num: Memory controller number 234 * @mc_num: Memory controller number
@@ -413,24 +443,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
413 return mci; 443 return mci;
414 444
415error: 445error:
416 if (mci->dimms) { 446 _edac_mc_free(mci);
417 for (i = 0; i < tot_dimms; i++)
418 kfree(mci->dimms[i]);
419 kfree(mci->dimms);
420 }
421 if (mci->csrows) {
422 for (chn = 0; chn < tot_channels; chn++) {
423 csr = mci->csrows[chn];
424 if (csr) {
425 for (chn = 0; chn < tot_channels; chn++)
426 kfree(csr->channels[chn]);
427 kfree(csr);
428 }
429 kfree(mci->csrows[i]);
430 }
431 kfree(mci->csrows);
432 }
433 kfree(mci);
434 447
435 return NULL; 448 return NULL;
436} 449}
@@ -445,6 +458,14 @@ void edac_mc_free(struct mem_ctl_info *mci)
445{ 458{
446 edac_dbg(1, "\n"); 459 edac_dbg(1, "\n");
447 460
461 /* If we're not yet registered with sysfs free only what was allocated
462 * in edac_mc_alloc().
463 */
464 if (!device_is_registered(&mci->dev)) {
465 _edac_mc_free(mci);
466 return;
467 }
468
448 /* the mci instance is freed here, when the sysfs object is dropped */ 469 /* the mci instance is freed here, when the sysfs object is dropped */
449 edac_unregister_sysfs(mci); 470 edac_unregister_sysfs(mci);
450} 471}
diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
index 47180a08edad..b6653a6fc5d5 100644
--- a/drivers/edac/i3200_edac.c
+++ b/drivers/edac/i3200_edac.c
@@ -391,7 +391,7 @@ static int i3200_probe1(struct pci_dev *pdev, int dev_idx)
391 for (j = 0; j < nr_channels; j++) { 391 for (j = 0; j < nr_channels; j++) {
392 struct dimm_info *dimm = csrow->channels[j]->dimm; 392 struct dimm_info *dimm = csrow->channels[j]->dimm;
393 393
394 dimm->nr_pages = nr_pages / nr_channels; 394 dimm->nr_pages = nr_pages;
395 dimm->grain = nr_pages << PAGE_SHIFT; 395 dimm->grain = nr_pages << PAGE_SHIFT;
396 dimm->mtype = MEM_DDR2; 396 dimm->mtype = MEM_DDR2;
397 dimm->dtype = DEV_UNKNOWN; 397 dimm->dtype = DEV_UNKNOWN;
diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index 39c63757c2a1..6a49dd00b81b 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -1012,6 +1012,10 @@ static void handle_channel(struct i5000_pvt *pvt, int slot, int channel,
1012 /* add the number of COLUMN bits */ 1012 /* add the number of COLUMN bits */
1013 addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr); 1013 addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
1014 1014
1015 /* Dual-rank memories have twice the size */
1016 if (dinfo->dual_rank)
1017 addrBits++;
1018
1015 addrBits += 6; /* add 64 bits per DIMM */ 1019 addrBits += 6; /* add 64 bits per DIMM */
1016 addrBits -= 20; /* divide by 2^^20 */ 1020 addrBits -= 20; /* divide by 2^^20 */
1017 addrBits -= 3; /* 8 bits per bytes */ 1021 addrBits -= 3; /* 8 bits per bytes */
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index f3b1f9fafa4b..5715b7c2c517 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -513,7 +513,8 @@ static int get_dimm_config(struct mem_ctl_info *mci)
513{ 513{
514 struct sbridge_pvt *pvt = mci->pvt_info; 514 struct sbridge_pvt *pvt = mci->pvt_info;
515 struct dimm_info *dimm; 515 struct dimm_info *dimm;
516 int i, j, banks, ranks, rows, cols, size, npages; 516 unsigned i, j, banks, ranks, rows, cols, npages;
517 u64 size;
517 u32 reg; 518 u32 reg;
518 enum edac_type mode; 519 enum edac_type mode;
519 enum mem_type mtype; 520 enum mem_type mtype;
@@ -585,10 +586,10 @@ static int get_dimm_config(struct mem_ctl_info *mci)
585 cols = numcol(mtr); 586 cols = numcol(mtr);
586 587
587 /* DDR3 has 8 I/O banks */ 588 /* DDR3 has 8 I/O banks */
588 size = (rows * cols * banks * ranks) >> (20 - 3); 589 size = ((u64)rows * cols * banks * ranks) >> (20 - 3);
589 npages = MiB_TO_PAGES(size); 590 npages = MiB_TO_PAGES(size);
590 591
591 edac_dbg(0, "mc#%d: channel %d, dimm %d, %d Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n", 592 edac_dbg(0, "mc#%d: channel %d, dimm %d, %Ld Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n",
592 pvt->sbridge_dev->mc, i, j, 593 pvt->sbridge_dev->mc, i, j,
593 size, npages, 594 size, npages,
594 banks, ranks, rows, cols); 595 banks, ranks, rows, cols);
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index 427a289f32a5..6c19833ed2d0 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -434,6 +434,11 @@ static int __devinit arizona_extcon_probe(struct platform_device *pdev)
434 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, 434 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
435 ARIZONA_JD1_ENA, ARIZONA_JD1_ENA); 435 ARIZONA_JD1_ENA, ARIZONA_JD1_ENA);
436 436
437 ret = regulator_allow_bypass(info->micvdd, true);
438 if (ret != 0)
439 dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n",
440 ret);
441
437 pm_runtime_put(&pdev->dev); 442 pm_runtime_put(&pdev->dev);
438 443
439 return 0; 444 return 0;
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index 920a609b2c35..38f9e52f358b 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -669,13 +669,18 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
669 } 669 }
670 info->dev = &pdev->dev; 670 info->dev = &pdev->dev;
671 info->max77693 = max77693; 671 info->max77693 = max77693;
672 info->max77693->regmap_muic = regmap_init_i2c(info->max77693->muic, 672 if (info->max77693->regmap_muic)
673 &max77693_muic_regmap_config); 673 dev_dbg(&pdev->dev, "allocate register map\n");
674 if (IS_ERR(info->max77693->regmap_muic)) { 674 else {
675 ret = PTR_ERR(info->max77693->regmap_muic); 675 info->max77693->regmap_muic = devm_regmap_init_i2c(
676 dev_err(max77693->dev, 676 info->max77693->muic,
677 "failed to allocate register map: %d\n", ret); 677 &max77693_muic_regmap_config);
678 goto err_regmap; 678 if (IS_ERR(info->max77693->regmap_muic)) {
679 ret = PTR_ERR(info->max77693->regmap_muic);
680 dev_err(max77693->dev,
681 "failed to allocate register map: %d\n", ret);
682 goto err_regmap;
683 }
679 } 684 }
680 platform_set_drvdata(pdev, info); 685 platform_set_drvdata(pdev, info);
681 mutex_init(&info->mutex); 686 mutex_init(&info->mutex);
diff --git a/drivers/gpio/gpio-lpc32xx.c b/drivers/gpio/gpio-lpc32xx.c
index 8a420f13905e..ed94b4ea72e9 100644
--- a/drivers/gpio/gpio-lpc32xx.c
+++ b/drivers/gpio/gpio-lpc32xx.c
@@ -308,6 +308,7 @@ static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin,
308{ 308{
309 struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 309 struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
310 310
311 __set_gpio_level_p012(group, pin, value);
311 __set_gpio_dir_p012(group, pin, 0); 312 __set_gpio_dir_p012(group, pin, 0);
312 313
313 return 0; 314 return 0;
@@ -318,6 +319,7 @@ static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin,
318{ 319{
319 struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 320 struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
320 321
322 __set_gpio_level_p3(group, pin, value);
321 __set_gpio_dir_p3(group, pin, 0); 323 __set_gpio_dir_p3(group, pin, 0);
322 324
323 return 0; 325 return 0;
@@ -326,6 +328,9 @@ static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin,
326static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin, 328static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin,
327 int value) 329 int value)
328{ 330{
331 struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
332
333 __set_gpo_level_p3(group, pin, value);
329 return 0; 334 return 0;
330} 335}
331 336
diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index d0c4574ef49c..36164806b9d4 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -193,6 +193,9 @@ static const struct file_operations ast_fops = {
193 .mmap = ast_mmap, 193 .mmap = ast_mmap,
194 .poll = drm_poll, 194 .poll = drm_poll,
195 .fasync = drm_fasync, 195 .fasync = drm_fasync,
196#ifdef CONFIG_COMPAT
197 .compat_ioctl = drm_compat_ioctl,
198#endif
196 .read = drm_read, 199 .read = drm_read,
197}; 200};
198 201
diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 7282c081fb53..a712cafcfa1d 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -841,7 +841,7 @@ int ast_cursor_init(struct drm_device *dev)
841 841
842 ast->cursor_cache = obj; 842 ast->cursor_cache = obj;
843 ast->cursor_cache_gpu_addr = gpu_addr; 843 ast->cursor_cache_gpu_addr = gpu_addr;
844 DRM_ERROR("pinned cursor cache at %llx\n", ast->cursor_cache_gpu_addr); 844 DRM_DEBUG_KMS("pinned cursor cache at %llx\n", ast->cursor_cache_gpu_addr);
845 return 0; 845 return 0;
846fail: 846fail:
847 return ret; 847 return ret;
diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.c b/drivers/gpu/drm/cirrus/cirrus_drv.c
index 7053140c6596..b83a2d7ddd1a 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.c
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.c
@@ -74,6 +74,9 @@ static const struct file_operations cirrus_driver_fops = {
74 .unlocked_ioctl = drm_ioctl, 74 .unlocked_ioctl = drm_ioctl,
75 .mmap = cirrus_mmap, 75 .mmap = cirrus_mmap,
76 .poll = drm_poll, 76 .poll = drm_poll,
77#ifdef CONFIG_COMPAT
78 .compat_ioctl = drm_compat_ioctl,
79#endif
77 .fasync = drm_fasync, 80 .fasync = drm_fasync,
78}; 81};
79static struct drm_driver driver = { 82static struct drm_driver driver = {
diff --git a/drivers/gpu/drm/exynos/Kconfig b/drivers/gpu/drm/exynos/Kconfig
index 7f5096763b7d..59a26e577b57 100644
--- a/drivers/gpu/drm/exynos/Kconfig
+++ b/drivers/gpu/drm/exynos/Kconfig
@@ -36,6 +36,6 @@ config DRM_EXYNOS_VIDI
36 36
37config DRM_EXYNOS_G2D 37config DRM_EXYNOS_G2D
38 bool "Exynos DRM G2D" 38 bool "Exynos DRM G2D"
39 depends on DRM_EXYNOS 39 depends on DRM_EXYNOS && !VIDEO_SAMSUNG_S5P_G2D
40 help 40 help
41 Choose this option if you want to use Exynos G2D for DRM. 41 Choose this option if you want to use Exynos G2D for DRM.
diff --git a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
index 613bf8a5d9b2..ae13febe0eaa 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
@@ -163,6 +163,12 @@ static void exynos_gem_dmabuf_kunmap(struct dma_buf *dma_buf,
163 /* TODO */ 163 /* TODO */
164} 164}
165 165
166static int exynos_gem_dmabuf_mmap(struct dma_buf *dma_buf,
167 struct vm_area_struct *vma)
168{
169 return -ENOTTY;
170}
171
166static struct dma_buf_ops exynos_dmabuf_ops = { 172static struct dma_buf_ops exynos_dmabuf_ops = {
167 .map_dma_buf = exynos_gem_map_dma_buf, 173 .map_dma_buf = exynos_gem_map_dma_buf,
168 .unmap_dma_buf = exynos_gem_unmap_dma_buf, 174 .unmap_dma_buf = exynos_gem_unmap_dma_buf,
@@ -170,6 +176,7 @@ static struct dma_buf_ops exynos_dmabuf_ops = {
170 .kmap_atomic = exynos_gem_dmabuf_kmap_atomic, 176 .kmap_atomic = exynos_gem_dmabuf_kmap_atomic,
171 .kunmap = exynos_gem_dmabuf_kunmap, 177 .kunmap = exynos_gem_dmabuf_kunmap,
172 .kunmap_atomic = exynos_gem_dmabuf_kunmap_atomic, 178 .kunmap_atomic = exynos_gem_dmabuf_kunmap_atomic,
179 .mmap = exynos_gem_dmabuf_mmap,
173 .release = exynos_dmabuf_release, 180 .release = exynos_dmabuf_release,
174}; 181};
175 182
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index ebacec6f1e48..d07071937453 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -160,7 +160,6 @@ static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
160 if (!file_priv) 160 if (!file_priv)
161 return -ENOMEM; 161 return -ENOMEM;
162 162
163 drm_prime_init_file_private(&file->prime);
164 file->driver_priv = file_priv; 163 file->driver_priv = file_priv;
165 164
166 return exynos_drm_subdrv_open(dev, file); 165 return exynos_drm_subdrv_open(dev, file);
@@ -184,7 +183,6 @@ static void exynos_drm_preclose(struct drm_device *dev,
184 e->base.destroy(&e->base); 183 e->base.destroy(&e->base);
185 } 184 }
186 } 185 }
187 drm_prime_destroy_file_private(&file->prime);
188 spin_unlock_irqrestore(&dev->event_lock, flags); 186 spin_unlock_irqrestore(&dev->event_lock, flags);
189 187
190 exynos_drm_subdrv_close(dev, file); 188 exynos_drm_subdrv_close(dev, file);
@@ -241,6 +239,9 @@ static const struct file_operations exynos_drm_driver_fops = {
241 .poll = drm_poll, 239 .poll = drm_poll,
242 .read = drm_read, 240 .read = drm_read,
243 .unlocked_ioctl = drm_ioctl, 241 .unlocked_ioctl = drm_ioctl,
242#ifdef CONFIG_COMPAT
243 .compat_ioctl = drm_compat_ioctl,
244#endif
244 .release = drm_release, 245 .release = drm_release,
245}; 246};
246 247
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
index a68d2b313f03..b19cd93e7047 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
@@ -831,11 +831,6 @@ static int __devinit fimd_probe(struct platform_device *pdev)
831 } 831 }
832 832
833 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 833 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
834 if (!res) {
835 dev_err(dev, "failed to find registers\n");
836 ret = -ENOENT;
837 goto err_clk;
838 }
839 834
840 ctx->regs = devm_request_and_ioremap(&pdev->dev, res); 835 ctx->regs = devm_request_and_ioremap(&pdev->dev, res);
841 if (!ctx->regs) { 836 if (!ctx->regs) {
diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index d2d88f22a037..1065e90d0919 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -129,7 +129,6 @@ struct g2d_runqueue_node {
129struct g2d_data { 129struct g2d_data {
130 struct device *dev; 130 struct device *dev;
131 struct clk *gate_clk; 131 struct clk *gate_clk;
132 struct resource *regs_res;
133 void __iomem *regs; 132 void __iomem *regs;
134 int irq; 133 int irq;
135 struct workqueue_struct *g2d_workq; 134 struct workqueue_struct *g2d_workq;
@@ -751,7 +750,7 @@ static int __devinit g2d_probe(struct platform_device *pdev)
751 struct exynos_drm_subdrv *subdrv; 750 struct exynos_drm_subdrv *subdrv;
752 int ret; 751 int ret;
753 752
754 g2d = kzalloc(sizeof(*g2d), GFP_KERNEL); 753 g2d = devm_kzalloc(&pdev->dev, sizeof(*g2d), GFP_KERNEL);
755 if (!g2d) { 754 if (!g2d) {
756 dev_err(dev, "failed to allocate driver data\n"); 755 dev_err(dev, "failed to allocate driver data\n");
757 return -ENOMEM; 756 return -ENOMEM;
@@ -759,10 +758,8 @@ static int __devinit g2d_probe(struct platform_device *pdev)
759 758
760 g2d->runqueue_slab = kmem_cache_create("g2d_runqueue_slab", 759 g2d->runqueue_slab = kmem_cache_create("g2d_runqueue_slab",
761 sizeof(struct g2d_runqueue_node), 0, 0, NULL); 760 sizeof(struct g2d_runqueue_node), 0, 0, NULL);
762 if (!g2d->runqueue_slab) { 761 if (!g2d->runqueue_slab)
763 ret = -ENOMEM; 762 return -ENOMEM;
764 goto err_free_mem;
765 }
766 763
767 g2d->dev = dev; 764 g2d->dev = dev;
768 765
@@ -794,38 +791,26 @@ static int __devinit g2d_probe(struct platform_device *pdev)
794 pm_runtime_enable(dev); 791 pm_runtime_enable(dev);
795 792
796 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 793 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
797 if (!res) {
798 dev_err(dev, "failed to get I/O memory\n");
799 ret = -ENOENT;
800 goto err_put_clk;
801 }
802 794
803 g2d->regs_res = request_mem_region(res->start, resource_size(res), 795 g2d->regs = devm_request_and_ioremap(&pdev->dev, res);
804 dev_name(dev));
805 if (!g2d->regs_res) {
806 dev_err(dev, "failed to request I/O memory\n");
807 ret = -ENOENT;
808 goto err_put_clk;
809 }
810
811 g2d->regs = ioremap(res->start, resource_size(res));
812 if (!g2d->regs) { 796 if (!g2d->regs) {
813 dev_err(dev, "failed to remap I/O memory\n"); 797 dev_err(dev, "failed to remap I/O memory\n");
814 ret = -ENXIO; 798 ret = -ENXIO;
815 goto err_release_res; 799 goto err_put_clk;
816 } 800 }
817 801
818 g2d->irq = platform_get_irq(pdev, 0); 802 g2d->irq = platform_get_irq(pdev, 0);
819 if (g2d->irq < 0) { 803 if (g2d->irq < 0) {
820 dev_err(dev, "failed to get irq\n"); 804 dev_err(dev, "failed to get irq\n");
821 ret = g2d->irq; 805 ret = g2d->irq;
822 goto err_unmap_base; 806 goto err_put_clk;
823 } 807 }
824 808
825 ret = request_irq(g2d->irq, g2d_irq_handler, 0, "drm_g2d", g2d); 809 ret = devm_request_irq(&pdev->dev, g2d->irq, g2d_irq_handler, 0,
810 "drm_g2d", g2d);
826 if (ret < 0) { 811 if (ret < 0) {
827 dev_err(dev, "irq request failed\n"); 812 dev_err(dev, "irq request failed\n");
828 goto err_unmap_base; 813 goto err_put_clk;
829 } 814 }
830 815
831 platform_set_drvdata(pdev, g2d); 816 platform_set_drvdata(pdev, g2d);
@@ -838,7 +823,7 @@ static int __devinit g2d_probe(struct platform_device *pdev)
838 ret = exynos_drm_subdrv_register(subdrv); 823 ret = exynos_drm_subdrv_register(subdrv);
839 if (ret < 0) { 824 if (ret < 0) {
840 dev_err(dev, "failed to register drm g2d device\n"); 825 dev_err(dev, "failed to register drm g2d device\n");
841 goto err_free_irq; 826 goto err_put_clk;
842 } 827 }
843 828
844 dev_info(dev, "The exynos g2d(ver %d.%d) successfully probed\n", 829 dev_info(dev, "The exynos g2d(ver %d.%d) successfully probed\n",
@@ -846,13 +831,6 @@ static int __devinit g2d_probe(struct platform_device *pdev)
846 831
847 return 0; 832 return 0;
848 833
849err_free_irq:
850 free_irq(g2d->irq, g2d);
851err_unmap_base:
852 iounmap(g2d->regs);
853err_release_res:
854 release_resource(g2d->regs_res);
855 kfree(g2d->regs_res);
856err_put_clk: 834err_put_clk:
857 pm_runtime_disable(dev); 835 pm_runtime_disable(dev);
858 clk_put(g2d->gate_clk); 836 clk_put(g2d->gate_clk);
@@ -862,8 +840,6 @@ err_destroy_workqueue:
862 destroy_workqueue(g2d->g2d_workq); 840 destroy_workqueue(g2d->g2d_workq);
863err_destroy_slab: 841err_destroy_slab:
864 kmem_cache_destroy(g2d->runqueue_slab); 842 kmem_cache_destroy(g2d->runqueue_slab);
865err_free_mem:
866 kfree(g2d);
867 return ret; 843 return ret;
868} 844}
869 845
@@ -873,24 +849,18 @@ static int __devexit g2d_remove(struct platform_device *pdev)
873 849
874 cancel_work_sync(&g2d->runqueue_work); 850 cancel_work_sync(&g2d->runqueue_work);
875 exynos_drm_subdrv_unregister(&g2d->subdrv); 851 exynos_drm_subdrv_unregister(&g2d->subdrv);
876 free_irq(g2d->irq, g2d);
877 852
878 while (g2d->runqueue_node) { 853 while (g2d->runqueue_node) {
879 g2d_free_runqueue_node(g2d, g2d->runqueue_node); 854 g2d_free_runqueue_node(g2d, g2d->runqueue_node);
880 g2d->runqueue_node = g2d_get_runqueue_node(g2d); 855 g2d->runqueue_node = g2d_get_runqueue_node(g2d);
881 } 856 }
882 857
883 iounmap(g2d->regs);
884 release_resource(g2d->regs_res);
885 kfree(g2d->regs_res);
886
887 pm_runtime_disable(&pdev->dev); 858 pm_runtime_disable(&pdev->dev);
888 clk_put(g2d->gate_clk); 859 clk_put(g2d->gate_clk);
889 860
890 g2d_fini_cmdlist(g2d); 861 g2d_fini_cmdlist(g2d);
891 destroy_workqueue(g2d->g2d_workq); 862 destroy_workqueue(g2d->g2d_workq);
892 kmem_cache_destroy(g2d->runqueue_slab); 863 kmem_cache_destroy(g2d->runqueue_slab);
893 kfree(g2d);
894 864
895 return 0; 865 return 0;
896} 866}
@@ -924,7 +894,7 @@ static int g2d_resume(struct device *dev)
924} 894}
925#endif 895#endif
926 896
927SIMPLE_DEV_PM_OPS(g2d_pm_ops, g2d_suspend, g2d_resume); 897static SIMPLE_DEV_PM_OPS(g2d_pm_ops, g2d_suspend, g2d_resume);
928 898
929struct platform_driver g2d_driver = { 899struct platform_driver g2d_driver = {
930 .probe = g2d_probe, 900 .probe = g2d_probe,
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index f9efde40c097..a38051c95ec4 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -122,7 +122,7 @@ fail:
122 __free_page(pages[i]); 122 __free_page(pages[i]);
123 123
124 drm_free_large(pages); 124 drm_free_large(pages);
125 return ERR_PTR(PTR_ERR(p)); 125 return ERR_CAST(p);
126} 126}
127 127
128static void exynos_gem_put_pages(struct drm_gem_object *obj, 128static void exynos_gem_put_pages(struct drm_gem_object *obj,
@@ -662,7 +662,7 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
662 */ 662 */
663 663
664 args->pitch = args->width * ((args->bpp + 7) / 8); 664 args->pitch = args->width * ((args->bpp + 7) / 8);
665 args->size = PAGE_ALIGN(args->pitch * args->height); 665 args->size = args->pitch * args->height;
666 666
667 exynos_gem_obj = exynos_drm_gem_create(dev, args->flags, args->size); 667 exynos_gem_obj = exynos_drm_gem_create(dev, args->flags, args->size);
668 if (IS_ERR(exynos_gem_obj)) 668 if (IS_ERR(exynos_gem_obj))
diff --git a/drivers/gpu/drm/exynos/exynos_drm_hdmi.c b/drivers/gpu/drm/exynos/exynos_drm_hdmi.c
index 8ffcdf8b9e22..3fdf0b65f47e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_hdmi.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_hdmi.c
@@ -345,7 +345,7 @@ static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev)
345 345
346 DRM_DEBUG_KMS("%s\n", __FILE__); 346 DRM_DEBUG_KMS("%s\n", __FILE__);
347 347
348 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 348 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
349 if (!ctx) { 349 if (!ctx) {
350 DRM_LOG_KMS("failed to alloc common hdmi context.\n"); 350 DRM_LOG_KMS("failed to alloc common hdmi context.\n");
351 return -ENOMEM; 351 return -ENOMEM;
@@ -371,7 +371,6 @@ static int __devexit exynos_drm_hdmi_remove(struct platform_device *pdev)
371 DRM_DEBUG_KMS("%s\n", __FILE__); 371 DRM_DEBUG_KMS("%s\n", __FILE__);
372 372
373 exynos_drm_subdrv_unregister(&ctx->subdrv); 373 exynos_drm_subdrv_unregister(&ctx->subdrv);
374 kfree(ctx);
375 374
376 return 0; 375 return 0;
377} 376}
diff --git a/drivers/gpu/drm/exynos/exynos_drm_plane.c b/drivers/gpu/drm/exynos/exynos_drm_plane.c
index b89829e5043a..e1f94b746bd7 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_plane.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_plane.c
@@ -29,7 +29,6 @@ static const uint32_t formats[] = {
29 DRM_FORMAT_XRGB8888, 29 DRM_FORMAT_XRGB8888,
30 DRM_FORMAT_ARGB8888, 30 DRM_FORMAT_ARGB8888,
31 DRM_FORMAT_NV12, 31 DRM_FORMAT_NV12,
32 DRM_FORMAT_NV12M,
33 DRM_FORMAT_NV12MT, 32 DRM_FORMAT_NV12MT,
34}; 33};
35 34
diff --git a/drivers/gpu/drm/exynos/exynos_drm_vidi.c b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
index bb1550c4dd57..537027a74fd5 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_vidi.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
@@ -633,7 +633,7 @@ static int __devinit vidi_probe(struct platform_device *pdev)
633 633
634 DRM_DEBUG_KMS("%s\n", __FILE__); 634 DRM_DEBUG_KMS("%s\n", __FILE__);
635 635
636 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 636 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
637 if (!ctx) 637 if (!ctx)
638 return -ENOMEM; 638 return -ENOMEM;
639 639
@@ -673,8 +673,6 @@ static int __devexit vidi_remove(struct platform_device *pdev)
673 ctx->raw_edid = NULL; 673 ctx->raw_edid = NULL;
674 } 674 }
675 675
676 kfree(ctx);
677
678 return 0; 676 return 0;
679} 677}
680 678
diff --git a/drivers/gpu/drm/exynos/exynos_hdmi.c b/drivers/gpu/drm/exynos/exynos_hdmi.c
index 409e2ec1207c..a6aea6f3ea1a 100644
--- a/drivers/gpu/drm/exynos/exynos_hdmi.c
+++ b/drivers/gpu/drm/exynos/exynos_hdmi.c
@@ -2172,7 +2172,7 @@ static int __devinit hdmi_resources_init(struct hdmi_context *hdata)
2172 2172
2173 DRM_DEBUG_KMS("HDMI resource init\n"); 2173 DRM_DEBUG_KMS("HDMI resource init\n");
2174 2174
2175 memset(res, 0, sizeof *res); 2175 memset(res, 0, sizeof(*res));
2176 2176
2177 /* get clocks, power */ 2177 /* get clocks, power */
2178 res->hdmi = clk_get(dev, "hdmi"); 2178 res->hdmi = clk_get(dev, "hdmi");
@@ -2204,7 +2204,7 @@ static int __devinit hdmi_resources_init(struct hdmi_context *hdata)
2204 clk_set_parent(res->sclk_hdmi, res->sclk_pixel); 2204 clk_set_parent(res->sclk_hdmi, res->sclk_pixel);
2205 2205
2206 res->regul_bulk = kzalloc(ARRAY_SIZE(supply) * 2206 res->regul_bulk = kzalloc(ARRAY_SIZE(supply) *
2207 sizeof res->regul_bulk[0], GFP_KERNEL); 2207 sizeof(res->regul_bulk[0]), GFP_KERNEL);
2208 if (!res->regul_bulk) { 2208 if (!res->regul_bulk) {
2209 DRM_ERROR("failed to get memory for regulators\n"); 2209 DRM_ERROR("failed to get memory for regulators\n");
2210 goto fail; 2210 goto fail;
@@ -2243,7 +2243,7 @@ static int hdmi_resources_cleanup(struct hdmi_context *hdata)
2243 clk_put(res->sclk_hdmi); 2243 clk_put(res->sclk_hdmi);
2244 if (!IS_ERR_OR_NULL(res->hdmi)) 2244 if (!IS_ERR_OR_NULL(res->hdmi))
2245 clk_put(res->hdmi); 2245 clk_put(res->hdmi);
2246 memset(res, 0, sizeof *res); 2246 memset(res, 0, sizeof(*res));
2247 2247
2248 return 0; 2248 return 0;
2249} 2249}
@@ -2312,11 +2312,6 @@ static int __devinit hdmi_probe(struct platform_device *pdev)
2312 } 2312 }
2313 2313
2314 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2314 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2315 if (!res) {
2316 DRM_ERROR("failed to find registers\n");
2317 ret = -ENOENT;
2318 goto err_resource;
2319 }
2320 2315
2321 hdata->regs = devm_request_and_ioremap(&pdev->dev, res); 2316 hdata->regs = devm_request_and_ioremap(&pdev->dev, res);
2322 if (!hdata->regs) { 2317 if (!hdata->regs) {
diff --git a/drivers/gpu/drm/exynos/exynos_mixer.c b/drivers/gpu/drm/exynos/exynos_mixer.c
index 30fcc12f81dd..25b97d5e5fcb 100644
--- a/drivers/gpu/drm/exynos/exynos_mixer.c
+++ b/drivers/gpu/drm/exynos/exynos_mixer.c
@@ -236,11 +236,11 @@ static inline void vp_filter_set(struct mixer_resources *res,
236static void vp_default_filter(struct mixer_resources *res) 236static void vp_default_filter(struct mixer_resources *res)
237{ 237{
238 vp_filter_set(res, VP_POLY8_Y0_LL, 238 vp_filter_set(res, VP_POLY8_Y0_LL,
239 filter_y_horiz_tap8, sizeof filter_y_horiz_tap8); 239 filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
240 vp_filter_set(res, VP_POLY4_Y0_LL, 240 vp_filter_set(res, VP_POLY4_Y0_LL,
241 filter_y_vert_tap4, sizeof filter_y_vert_tap4); 241 filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
242 vp_filter_set(res, VP_POLY4_C0_LL, 242 vp_filter_set(res, VP_POLY4_C0_LL,
243 filter_cr_horiz_tap4, sizeof filter_cr_horiz_tap4); 243 filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
244} 244}
245 245
246static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable) 246static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable)
diff --git a/drivers/gpu/drm/gma500/oaktrail_device.c b/drivers/gpu/drm/gma500/oaktrail_device.c
index 0f9b7db80f6b..cf49ba5a54bf 100644
--- a/drivers/gpu/drm/gma500/oaktrail_device.c
+++ b/drivers/gpu/drm/gma500/oaktrail_device.c
@@ -476,6 +476,7 @@ static const struct psb_offset oaktrail_regmap[2] = {
476 .pos = DSPAPOS, 476 .pos = DSPAPOS,
477 .surf = DSPASURF, 477 .surf = DSPASURF,
478 .addr = MRST_DSPABASE, 478 .addr = MRST_DSPABASE,
479 .base = MRST_DSPABASE,
479 .status = PIPEASTAT, 480 .status = PIPEASTAT,
480 .linoff = DSPALINOFF, 481 .linoff = DSPALINOFF,
481 .tileoff = DSPATILEOFF, 482 .tileoff = DSPATILEOFF,
@@ -499,6 +500,7 @@ static const struct psb_offset oaktrail_regmap[2] = {
499 .pos = DSPBPOS, 500 .pos = DSPBPOS,
500 .surf = DSPBSURF, 501 .surf = DSPBSURF,
501 .addr = DSPBBASE, 502 .addr = DSPBBASE,
503 .base = DSPBBASE,
502 .status = PIPEBSTAT, 504 .status = PIPEBSTAT,
503 .linoff = DSPBLINOFF, 505 .linoff = DSPBLINOFF,
504 .tileoff = DSPBTILEOFF, 506 .tileoff = DSPBTILEOFF,
diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
index 57d892eaaa6e..463ec6871fe9 100644
--- a/drivers/gpu/drm/i810/i810_dma.c
+++ b/drivers/gpu/drm/i810/i810_dma.c
@@ -115,6 +115,9 @@ static const struct file_operations i810_buffer_fops = {
115 .unlocked_ioctl = drm_ioctl, 115 .unlocked_ioctl = drm_ioctl,
116 .mmap = i810_mmap_buffers, 116 .mmap = i810_mmap_buffers,
117 .fasync = drm_fasync, 117 .fasync = drm_fasync,
118#ifdef CONFIG_COMPAT
119 .compat_ioctl = drm_compat_ioctl,
120#endif
118 .llseek = noop_llseek, 121 .llseek = noop_llseek,
119}; 122};
120 123
diff --git a/drivers/gpu/drm/i810/i810_drv.c b/drivers/gpu/drm/i810/i810_drv.c
index f9924ad04d09..48cfcca2b350 100644
--- a/drivers/gpu/drm/i810/i810_drv.c
+++ b/drivers/gpu/drm/i810/i810_drv.c
@@ -51,6 +51,9 @@ static const struct file_operations i810_driver_fops = {
51 .mmap = drm_mmap, 51 .mmap = drm_mmap,
52 .poll = drm_poll, 52 .poll = drm_poll,
53 .fasync = drm_fasync, 53 .fasync = drm_fasync,
54#ifdef CONFIG_COMPAT
55 .compat_ioctl = drm_compat_ioctl,
56#endif
54 .llseek = noop_llseek, 57 .llseek = noop_llseek,
55}; 58};
56 59
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 9cf7dfe022b9..914c0dfabe60 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1587,6 +1587,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1587 spin_lock_init(&dev_priv->irq_lock); 1587 spin_lock_init(&dev_priv->irq_lock);
1588 spin_lock_init(&dev_priv->error_lock); 1588 spin_lock_init(&dev_priv->error_lock);
1589 spin_lock_init(&dev_priv->rps_lock); 1589 spin_lock_init(&dev_priv->rps_lock);
1590 spin_lock_init(&dev_priv->dpio_lock);
1590 1591
1591 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) 1592 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
1592 dev_priv->num_pipe = 3; 1593 dev_priv->num_pipe = 3;
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 489e2b162b27..274d25de521e 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3242,7 +3242,8 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
3242{ 3242{
3243 int ret; 3243 int ret;
3244 3244
3245 BUG_ON(obj->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT); 3245 if (WARN_ON(obj->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT))
3246 return -EBUSY;
3246 3247
3247 if (obj->gtt_space != NULL) { 3248 if (obj->gtt_space != NULL) {
3248 if ((alignment && obj->gtt_offset & (alignment - 1)) || 3249 if ((alignment && obj->gtt_offset & (alignment - 1)) ||
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 8a3828528b9d..5249640cce13 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -2700,9 +2700,6 @@ void intel_irq_init(struct drm_device *dev)
2700 dev->driver->irq_handler = i8xx_irq_handler; 2700 dev->driver->irq_handler = i8xx_irq_handler;
2701 dev->driver->irq_uninstall = i8xx_irq_uninstall; 2701 dev->driver->irq_uninstall = i8xx_irq_uninstall;
2702 } else if (INTEL_INFO(dev)->gen == 3) { 2702 } else if (INTEL_INFO(dev)->gen == 3) {
2703 /* IIR "flip pending" means done if this bit is set */
2704 I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
2705
2706 dev->driver->irq_preinstall = i915_irq_preinstall; 2703 dev->driver->irq_preinstall = i915_irq_preinstall;
2707 dev->driver->irq_postinstall = i915_irq_postinstall; 2704 dev->driver->irq_postinstall = i915_irq_postinstall;
2708 dev->driver->irq_uninstall = i915_irq_uninstall; 2705 dev->driver->irq_uninstall = i915_irq_uninstall;
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 2dfa6cf4886b..c040aee1341c 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -1376,7 +1376,8 @@ static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1376 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", 1376 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1377 reg, pipe_name(pipe)); 1377 reg, pipe_name(pipe));
1378 1378
1379 WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_PIPE_B_SELECT), 1379 WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
1380 && (val & DP_PIPEB_SELECT),
1380 "IBX PCH dp port still using transcoder B\n"); 1381 "IBX PCH dp port still using transcoder B\n");
1381} 1382}
1382 1383
@@ -1388,7 +1389,8 @@ static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1388 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", 1389 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1389 reg, pipe_name(pipe)); 1390 reg, pipe_name(pipe));
1390 1391
1391 WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_PIPE_B_SELECT), 1392 WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0
1393 && (val & SDVO_PIPE_B_SELECT),
1392 "IBX PCH hdmi port still using transcoder B\n"); 1394 "IBX PCH hdmi port still using transcoder B\n");
1393} 1395}
1394 1396
@@ -4189,12 +4191,6 @@ static void i8xx_update_pll(struct drm_crtc *crtc,
4189 POSTING_READ(DPLL(pipe)); 4191 POSTING_READ(DPLL(pipe));
4190 udelay(150); 4192 udelay(150);
4191 4193
4192 I915_WRITE(DPLL(pipe), dpll);
4193
4194 /* Wait for the clocks to stabilize. */
4195 POSTING_READ(DPLL(pipe));
4196 udelay(150);
4197
4198 /* The LVDS pin pair needs to be on before the DPLLs are enabled. 4194 /* The LVDS pin pair needs to be on before the DPLLs are enabled.
4199 * This is an exception to the general rule that mode_set doesn't turn 4195 * This is an exception to the general rule that mode_set doesn't turn
4200 * things on. 4196 * things on.
@@ -4202,6 +4198,12 @@ static void i8xx_update_pll(struct drm_crtc *crtc,
4202 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 4198 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
4203 intel_update_lvds(crtc, clock, adjusted_mode); 4199 intel_update_lvds(crtc, clock, adjusted_mode);
4204 4200
4201 I915_WRITE(DPLL(pipe), dpll);
4202
4203 /* Wait for the clocks to stabilize. */
4204 POSTING_READ(DPLL(pipe));
4205 udelay(150);
4206
4205 /* The pixel multiplier can only be updated once the 4207 /* The pixel multiplier can only be updated once the
4206 * DPLL is enabled and the clocks are stable. 4208 * DPLL is enabled and the clocks are stable.
4207 * 4209 *
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index a6c426afaa7a..ace757af9133 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -2533,14 +2533,10 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2533 break; 2533 break;
2534 } 2534 }
2535 2535
2536 intel_dp_i2c_init(intel_dp, intel_connector, name);
2537
2538 /* Cache some DPCD data in the eDP case */ 2536 /* Cache some DPCD data in the eDP case */
2539 if (is_edp(intel_dp)) { 2537 if (is_edp(intel_dp)) {
2540 bool ret;
2541 struct edp_power_seq cur, vbt; 2538 struct edp_power_seq cur, vbt;
2542 u32 pp_on, pp_off, pp_div; 2539 u32 pp_on, pp_off, pp_div;
2543 struct edid *edid;
2544 2540
2545 pp_on = I915_READ(PCH_PP_ON_DELAYS); 2541 pp_on = I915_READ(PCH_PP_ON_DELAYS);
2546 pp_off = I915_READ(PCH_PP_OFF_DELAYS); 2542 pp_off = I915_READ(PCH_PP_OFF_DELAYS);
@@ -2591,6 +2587,13 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2591 2587
2592 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", 2588 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2593 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); 2589 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
2590 }
2591
2592 intel_dp_i2c_init(intel_dp, intel_connector, name);
2593
2594 if (is_edp(intel_dp)) {
2595 bool ret;
2596 struct edid *edid;
2594 2597
2595 ironlake_edp_panel_vdd_on(intel_dp); 2598 ironlake_edp_panel_vdd_on(intel_dp);
2596 ret = intel_dp_get_dpcd(intel_dp); 2599 ret = intel_dp_get_dpcd(intel_dp);
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 98f602427eb8..12dc3308ab8c 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -609,7 +609,7 @@ static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
609 u32 temp; 609 u32 temp;
610 u32 enable_bits = SDVO_ENABLE; 610 u32 enable_bits = SDVO_ENABLE;
611 611
612 if (intel_hdmi->has_audio) 612 if (intel_hdmi->has_audio || mode != DRM_MODE_DPMS_ON)
613 enable_bits |= SDVO_AUDIO_ENABLE; 613 enable_bits |= SDVO_AUDIO_ENABLE;
614 614
615 temp = I915_READ(intel_hdmi->sdvox_reg); 615 temp = I915_READ(intel_hdmi->sdvox_reg);
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index 3df4f5fa892a..e019b2369861 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -162,19 +162,12 @@ static u32 i915_read_blc_pwm_ctl(struct drm_i915_private *dev_priv)
162 return val; 162 return val;
163} 163}
164 164
165u32 intel_panel_get_max_backlight(struct drm_device *dev) 165static u32 _intel_panel_get_max_backlight(struct drm_device *dev)
166{ 166{
167 struct drm_i915_private *dev_priv = dev->dev_private; 167 struct drm_i915_private *dev_priv = dev->dev_private;
168 u32 max; 168 u32 max;
169 169
170 max = i915_read_blc_pwm_ctl(dev_priv); 170 max = i915_read_blc_pwm_ctl(dev_priv);
171 if (max == 0) {
172 /* XXX add code here to query mode clock or hardware clock
173 * and program max PWM appropriately.
174 */
175 pr_warn_once("fixme: max PWM is zero\n");
176 return 1;
177 }
178 171
179 if (HAS_PCH_SPLIT(dev)) { 172 if (HAS_PCH_SPLIT(dev)) {
180 max >>= 16; 173 max >>= 16;
@@ -188,6 +181,22 @@ u32 intel_panel_get_max_backlight(struct drm_device *dev)
188 max *= 0xff; 181 max *= 0xff;
189 } 182 }
190 183
184 return max;
185}
186
187u32 intel_panel_get_max_backlight(struct drm_device *dev)
188{
189 u32 max;
190
191 max = _intel_panel_get_max_backlight(dev);
192 if (max == 0) {
193 /* XXX add code here to query mode clock or hardware clock
194 * and program max PWM appropriately.
195 */
196 pr_warn_once("fixme: max PWM is zero\n");
197 return 1;
198 }
199
191 DRM_DEBUG_DRIVER("max backlight PWM = %d\n", max); 200 DRM_DEBUG_DRIVER("max backlight PWM = %d\n", max);
192 return max; 201 return max;
193} 202}
@@ -424,7 +433,11 @@ int intel_panel_setup_backlight(struct drm_device *dev)
424 433
425 memset(&props, 0, sizeof(props)); 434 memset(&props, 0, sizeof(props));
426 props.type = BACKLIGHT_RAW; 435 props.type = BACKLIGHT_RAW;
427 props.max_brightness = intel_panel_get_max_backlight(dev); 436 props.max_brightness = _intel_panel_get_max_backlight(dev);
437 if (props.max_brightness == 0) {
438 DRM_ERROR("Failed to get maximum backlight value\n");
439 return -ENODEV;
440 }
428 dev_priv->backlight = 441 dev_priv->backlight =
429 backlight_device_register("intel_backlight", 442 backlight_device_register("intel_backlight",
430 &connector->kdev, dev, 443 &connector->kdev, dev,
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index 1881c8c83f0e..ba8a27b1757a 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -3672,6 +3672,9 @@ static void gen3_init_clock_gating(struct drm_device *dev)
3672 3672
3673 if (IS_PINEVIEW(dev)) 3673 if (IS_PINEVIEW(dev))
3674 I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); 3674 I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY));
3675
3676 /* IIR "flip pending" means done if this bit is set */
3677 I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
3675} 3678}
3676 3679
3677static void i85x_init_clock_gating(struct drm_device *dev) 3680static void i85x_init_clock_gating(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index d81bb0bf2885..123afd357611 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -2573,7 +2573,6 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
2573 hotplug_mask = intel_sdvo->is_sdvob ? 2573 hotplug_mask = intel_sdvo->is_sdvob ?
2574 SDVOB_HOTPLUG_INT_STATUS_I915 : SDVOC_HOTPLUG_INT_STATUS_I915; 2574 SDVOB_HOTPLUG_INT_STATUS_I915 : SDVOC_HOTPLUG_INT_STATUS_I915;
2575 } 2575 }
2576 dev_priv->hotplug_supported_mask |= hotplug_mask;
2577 2576
2578 drm_encoder_helper_add(&intel_encoder->base, &intel_sdvo_helper_funcs); 2577 drm_encoder_helper_add(&intel_encoder->base, &intel_sdvo_helper_funcs);
2579 2578
@@ -2581,14 +2580,6 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
2581 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps)) 2580 if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
2582 goto err; 2581 goto err;
2583 2582
2584 /* Set up hotplug command - note paranoia about contents of reply.
2585 * We assume that the hardware is in a sane state, and only touch
2586 * the bits we think we understand.
2587 */
2588 intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG,
2589 &intel_sdvo->hotplug_active, 2);
2590 intel_sdvo->hotplug_active[0] &= ~0x3;
2591
2592 if (intel_sdvo_output_setup(intel_sdvo, 2583 if (intel_sdvo_output_setup(intel_sdvo,
2593 intel_sdvo->caps.output_flags) != true) { 2584 intel_sdvo->caps.output_flags) != true) {
2594 DRM_DEBUG_KMS("SDVO output failed to setup on %s\n", 2585 DRM_DEBUG_KMS("SDVO output failed to setup on %s\n",
@@ -2596,6 +2587,12 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
2596 goto err; 2587 goto err;
2597 } 2588 }
2598 2589
2590 /* Only enable the hotplug irq if we need it, to work around noisy
2591 * hotplug lines.
2592 */
2593 if (intel_sdvo->hotplug_active[0])
2594 dev_priv->hotplug_supported_mask |= hotplug_mask;
2595
2599 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg); 2596 intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg);
2600 2597
2601 /* Set the input timing to the screen. Assume always input 0. */ 2598 /* Set the input timing to the screen. Assume always input 0. */
diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag200/mgag200_drv.c
index ea1024d79974..e5f145d2cb3b 100644
--- a/drivers/gpu/drm/mgag200/mgag200_drv.c
+++ b/drivers/gpu/drm/mgag200/mgag200_drv.c
@@ -84,6 +84,9 @@ static const struct file_operations mgag200_driver_fops = {
84 .mmap = mgag200_mmap, 84 .mmap = mgag200_mmap,
85 .poll = drm_poll, 85 .poll = drm_poll,
86 .fasync = drm_fasync, 86 .fasync = drm_fasync,
87#ifdef CONFIG_COMPAT
88 .compat_ioctl = drm_compat_ioctl,
89#endif
87 .read = drm_read, 90 .read = drm_read,
88}; 91};
89 92
diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c b/drivers/gpu/drm/nouveau/nouveau_abi16.c
index ff23d88880e5..3ca240b4413d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_abi16.c
+++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c
@@ -179,7 +179,7 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
179 return 0; 179 return 0;
180 } else 180 } else
181 if (init->class == 0x906e) { 181 if (init->class == 0x906e) {
182 NV_ERROR(dev, "906e not supported yet\n"); 182 NV_DEBUG(dev, "906e not supported yet\n");
183 return -EINVAL; 183 return -EINVAL;
184 } 184 }
185 185
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c
index 69688ef5cf46..7e16dc5e6467 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -598,7 +598,7 @@ nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
598 args->size = args->pitch * args->height; 598 args->size = args->pitch * args->height;
599 args->size = roundup(args->size, PAGE_SIZE); 599 args->size = roundup(args->size, PAGE_SIZE);
600 600
601 ret = nouveau_gem_new(dev, args->size, 0, TTM_PL_FLAG_VRAM, 0, 0, &bo); 601 ret = nouveau_gem_new(dev, args->size, 0, NOUVEAU_GEM_DOMAIN_VRAM, 0, 0, &bo);
602 if (ret) 602 if (ret)
603 return ret; 603 return ret;
604 604
diff --git a/drivers/gpu/drm/nouveau/nv50_gpio.c b/drivers/gpu/drm/nouveau/nv50_gpio.c
index f429e6a8ca7a..c399d510b27a 100644
--- a/drivers/gpu/drm/nouveau/nv50_gpio.c
+++ b/drivers/gpu/drm/nouveau/nv50_gpio.c
@@ -22,6 +22,7 @@
22 * Authors: Ben Skeggs 22 * Authors: Ben Skeggs
23 */ 23 */
24 24
25#include <linux/dmi.h>
25#include "drmP.h" 26#include "drmP.h"
26#include "nouveau_drv.h" 27#include "nouveau_drv.h"
27#include "nouveau_hw.h" 28#include "nouveau_hw.h"
@@ -110,11 +111,26 @@ nv50_gpio_isr(struct drm_device *dev)
110 nv_wr32(dev, 0xe074, intr1); 111 nv_wr32(dev, 0xe074, intr1);
111} 112}
112 113
114static struct dmi_system_id gpio_reset_ids[] = {
115 {
116 .ident = "Apple Macbook 10,1",
117 .matches = {
118 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
119 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro10,1"),
120 }
121 },
122 { }
123};
124
113int 125int
114nv50_gpio_init(struct drm_device *dev) 126nv50_gpio_init(struct drm_device *dev)
115{ 127{
116 struct drm_nouveau_private *dev_priv = dev->dev_private; 128 struct drm_nouveau_private *dev_priv = dev->dev_private;
117 129
130 /* initialise gpios and routing to vbios defaults */
131 if (dmi_check_system(gpio_reset_ids))
132 nouveau_gpio_reset(dev);
133
118 /* disable, and ack any pending gpio interrupts */ 134 /* disable, and ack any pending gpio interrupts */
119 nv_wr32(dev, 0xe050, 0x00000000); 135 nv_wr32(dev, 0xe050, 0x00000000);
120 nv_wr32(dev, 0xe054, 0xffffffff); 136 nv_wr32(dev, 0xe054, 0xffffffff);
diff --git a/drivers/gpu/drm/nouveau/nvc0_fb.c b/drivers/gpu/drm/nouveau/nvc0_fb.c
index f704e942372e..f376c39310df 100644
--- a/drivers/gpu/drm/nouveau/nvc0_fb.c
+++ b/drivers/gpu/drm/nouveau/nvc0_fb.c
@@ -124,6 +124,7 @@ nvc0_fb_init(struct drm_device *dev)
124 priv = dev_priv->engine.fb.priv; 124 priv = dev_priv->engine.fb.priv;
125 125
126 nv_wr32(dev, 0x100c10, priv->r100c10 >> 8); 126 nv_wr32(dev, 0x100c10, priv->r100c10 >> 8);
127 nv_mask(dev, 0x17e820, 0x00100000, 0x00000000); /* NV_PLTCG_INTR_EN */
127 return 0; 128 return 0;
128} 129}
129 130
diff --git a/drivers/gpu/drm/nouveau/nvc0_fifo.c b/drivers/gpu/drm/nouveau/nvc0_fifo.c
index 7d85553d518c..cd39eb99f5b1 100644
--- a/drivers/gpu/drm/nouveau/nvc0_fifo.c
+++ b/drivers/gpu/drm/nouveau/nvc0_fifo.c
@@ -373,7 +373,8 @@ nvc0_fifo_isr_subfifo_intr(struct drm_device *dev, int unit)
373static void 373static void
374nvc0_fifo_isr(struct drm_device *dev) 374nvc0_fifo_isr(struct drm_device *dev)
375{ 375{
376 u32 stat = nv_rd32(dev, 0x002100); 376 u32 mask = nv_rd32(dev, 0x002140);
377 u32 stat = nv_rd32(dev, 0x002100) & mask;
377 378
378 if (stat & 0x00000100) { 379 if (stat & 0x00000100) {
379 NV_INFO(dev, "PFIFO: unknown status 0x00000100\n"); 380 NV_INFO(dev, "PFIFO: unknown status 0x00000100\n");
diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
index dac525b2994e..8a2fc89b7763 100644
--- a/drivers/gpu/drm/nouveau/nvd0_display.c
+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
@@ -1510,10 +1510,10 @@ nvd0_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
1510 case OUTPUT_DP: 1510 case OUTPUT_DP:
1511 if (nv_connector->base.display_info.bpc == 6) { 1511 if (nv_connector->base.display_info.bpc == 6) {
1512 nv_encoder->dp.datarate = mode->clock * 18 / 8; 1512 nv_encoder->dp.datarate = mode->clock * 18 / 8;
1513 syncs |= 0x00000140; 1513 syncs |= 0x00000002 << 6;
1514 } else { 1514 } else {
1515 nv_encoder->dp.datarate = mode->clock * 24 / 8; 1515 nv_encoder->dp.datarate = mode->clock * 24 / 8;
1516 syncs |= 0x00000180; 1516 syncs |= 0x00000005 << 6;
1517 } 1517 }
1518 1518
1519 if (nv_encoder->dcb->sorconf.link & 1) 1519 if (nv_encoder->dcb->sorconf.link & 1)
diff --git a/drivers/gpu/drm/nouveau/nve0_fifo.c b/drivers/gpu/drm/nouveau/nve0_fifo.c
index e98d144e6eb9..281bece751b6 100644
--- a/drivers/gpu/drm/nouveau/nve0_fifo.c
+++ b/drivers/gpu/drm/nouveau/nve0_fifo.c
@@ -345,7 +345,8 @@ nve0_fifo_isr_subfifo_intr(struct drm_device *dev, int unit)
345static void 345static void
346nve0_fifo_isr(struct drm_device *dev) 346nve0_fifo_isr(struct drm_device *dev)
347{ 347{
348 u32 stat = nv_rd32(dev, 0x002100); 348 u32 mask = nv_rd32(dev, 0x002140);
349 u32 stat = nv_rd32(dev, 0x002100) & mask;
349 350
350 if (stat & 0x00000100) { 351 if (stat & 0x00000100) {
351 NV_INFO(dev, "PFIFO: unknown status 0x00000100\n"); 352 NV_INFO(dev, "PFIFO: unknown status 0x00000100\n");
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 8acb34fd3fd5..8d7e33a0b243 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -1182,7 +1182,8 @@ int r100_cp_init(struct radeon_device *rdev, unsigned ring_size)
1182 ring->ready = true; 1182 ring->ready = true;
1183 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size); 1183 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
1184 1184
1185 if (radeon_ring_supports_scratch_reg(rdev, ring)) { 1185 if (!ring->rptr_save_reg /* not resuming from suspend */
1186 && radeon_ring_supports_scratch_reg(rdev, ring)) {
1186 r = radeon_scratch_get(rdev, &ring->rptr_save_reg); 1187 r = radeon_scratch_get(rdev, &ring->rptr_save_reg);
1187 if (r) { 1188 if (r) {
1188 DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r); 1189 DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r);
diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
index 7b737b9339ad..2a59375dbe52 100644
--- a/drivers/gpu/drm/radeon/radeon_fence.c
+++ b/drivers/gpu/drm/radeon/radeon_fence.c
@@ -131,7 +131,7 @@ int radeon_fence_emit(struct radeon_device *rdev,
131 */ 131 */
132void radeon_fence_process(struct radeon_device *rdev, int ring) 132void radeon_fence_process(struct radeon_device *rdev, int ring)
133{ 133{
134 uint64_t seq, last_seq; 134 uint64_t seq, last_seq, last_emitted;
135 unsigned count_loop = 0; 135 unsigned count_loop = 0;
136 bool wake = false; 136 bool wake = false;
137 137
@@ -158,13 +158,15 @@ void radeon_fence_process(struct radeon_device *rdev, int ring)
158 */ 158 */
159 last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq); 159 last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq);
160 do { 160 do {
161 last_emitted = rdev->fence_drv[ring].sync_seq[ring];
161 seq = radeon_fence_read(rdev, ring); 162 seq = radeon_fence_read(rdev, ring);
162 seq |= last_seq & 0xffffffff00000000LL; 163 seq |= last_seq & 0xffffffff00000000LL;
163 if (seq < last_seq) { 164 if (seq < last_seq) {
164 seq += 0x100000000LL; 165 seq &= 0xffffffff;
166 seq |= last_emitted & 0xffffffff00000000LL;
165 } 167 }
166 168
167 if (seq == last_seq) { 169 if (seq <= last_seq || seq > last_emitted) {
168 break; 170 break;
169 } 171 }
170 /* If we loop over we don't want to return without 172 /* If we loop over we don't want to return without
diff --git a/drivers/gpu/drm/savage/savage_drv.c b/drivers/gpu/drm/savage/savage_drv.c
index d31d4cca9a4c..c5a164337bd5 100644
--- a/drivers/gpu/drm/savage/savage_drv.c
+++ b/drivers/gpu/drm/savage/savage_drv.c
@@ -43,6 +43,9 @@ static const struct file_operations savage_driver_fops = {
43 .mmap = drm_mmap, 43 .mmap = drm_mmap,
44 .poll = drm_poll, 44 .poll = drm_poll,
45 .fasync = drm_fasync, 45 .fasync = drm_fasync,
46#ifdef CONFIG_COMPAT
47 .compat_ioctl = drm_compat_ioctl,
48#endif
46 .llseek = noop_llseek, 49 .llseek = noop_llseek,
47}; 50};
48 51
diff --git a/drivers/gpu/drm/sis/sis_drv.c b/drivers/gpu/drm/sis/sis_drv.c
index 7f119870147c..867dc03000e6 100644
--- a/drivers/gpu/drm/sis/sis_drv.c
+++ b/drivers/gpu/drm/sis/sis_drv.c
@@ -74,6 +74,9 @@ static const struct file_operations sis_driver_fops = {
74 .mmap = drm_mmap, 74 .mmap = drm_mmap,
75 .poll = drm_poll, 75 .poll = drm_poll,
76 .fasync = drm_fasync, 76 .fasync = drm_fasync,
77#ifdef CONFIG_COMPAT
78 .compat_ioctl = drm_compat_ioctl,
79#endif
77 .llseek = noop_llseek, 80 .llseek = noop_llseek,
78}; 81};
79 82
diff --git a/drivers/gpu/drm/tdfx/tdfx_drv.c b/drivers/gpu/drm/tdfx/tdfx_drv.c
index 90f6b13acfac..a7f4d6bd1330 100644
--- a/drivers/gpu/drm/tdfx/tdfx_drv.c
+++ b/drivers/gpu/drm/tdfx/tdfx_drv.c
@@ -49,6 +49,9 @@ static const struct file_operations tdfx_driver_fops = {
49 .mmap = drm_mmap, 49 .mmap = drm_mmap,
50 .poll = drm_poll, 50 .poll = drm_poll,
51 .fasync = drm_fasync, 51 .fasync = drm_fasync,
52#ifdef CONFIG_COMPAT
53 .compat_ioctl = drm_compat_ioctl,
54#endif
52 .llseek = noop_llseek, 55 .llseek = noop_llseek,
53}; 56};
54 57
diff --git a/drivers/gpu/drm/udl/udl_connector.c b/drivers/gpu/drm/udl/udl_connector.c
index ba055e9ca007..8d9dc44f1f94 100644
--- a/drivers/gpu/drm/udl/udl_connector.c
+++ b/drivers/gpu/drm/udl/udl_connector.c
@@ -69,6 +69,13 @@ static int udl_get_modes(struct drm_connector *connector)
69static int udl_mode_valid(struct drm_connector *connector, 69static int udl_mode_valid(struct drm_connector *connector,
70 struct drm_display_mode *mode) 70 struct drm_display_mode *mode)
71{ 71{
72 struct udl_device *udl = connector->dev->dev_private;
73 if (!udl->sku_pixel_limit)
74 return 0;
75
76 if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit)
77 return MODE_VIRTUAL_Y;
78
72 return 0; 79 return 0;
73} 80}
74 81
diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
index 6e52069894b3..9f84128505bb 100644
--- a/drivers/gpu/drm/udl/udl_drv.c
+++ b/drivers/gpu/drm/udl/udl_drv.c
@@ -66,6 +66,9 @@ static const struct file_operations udl_driver_fops = {
66 .unlocked_ioctl = drm_ioctl, 66 .unlocked_ioctl = drm_ioctl,
67 .release = drm_release, 67 .release = drm_release,
68 .fasync = drm_fasync, 68 .fasync = drm_fasync,
69#ifdef CONFIG_COMPAT
70 .compat_ioctl = drm_compat_ioctl,
71#endif
69 .llseek = noop_llseek, 72 .llseek = noop_llseek,
70}; 73};
71 74
diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
index e927b4c052f5..af1b914b17e3 100644
--- a/drivers/gpu/drm/via/via_drv.c
+++ b/drivers/gpu/drm/via/via_drv.c
@@ -65,6 +65,9 @@ static const struct file_operations via_driver_fops = {
65 .mmap = drm_mmap, 65 .mmap = drm_mmap,
66 .poll = drm_poll, 66 .poll = drm_poll,
67 .fasync = drm_fasync, 67 .fasync = drm_fasync,
68#ifdef CONFIG_COMPAT
69 .compat_ioctl = drm_compat_ioctl,
70#endif
68 .llseek = noop_llseek, 71 .llseek = noop_llseek,
69}; 72};
70 73
diff --git a/drivers/gpu/drm/vmwgfx/Kconfig b/drivers/gpu/drm/vmwgfx/Kconfig
index 794ff67c5701..b71bcd0bfbbf 100644
--- a/drivers/gpu/drm/vmwgfx/Kconfig
+++ b/drivers/gpu/drm/vmwgfx/Kconfig
@@ -12,3 +12,11 @@ config DRM_VMWGFX
12 This is a KMS enabled DRM driver for the VMware SVGA2 12 This is a KMS enabled DRM driver for the VMware SVGA2
13 virtual hardware. 13 virtual hardware.
14 The compiled module will be called "vmwgfx.ko". 14 The compiled module will be called "vmwgfx.ko".
15
16config DRM_VMWGFX_FBCON
17 depends on DRM_VMWGFX
18 bool "Enable framebuffer console under vmwgfx by default"
19 help
20 Choose this option if you are shipping a new vmwgfx
21 userspace driver that supports using the kernel driver.
22
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 4d9edead01ac..ba2c35dbf10e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -182,8 +182,9 @@ static struct pci_device_id vmw_pci_id_list[] = {
182 {0x15ad, 0x0405, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VMWGFX_CHIP_SVGAII}, 182 {0x15ad, 0x0405, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VMWGFX_CHIP_SVGAII},
183 {0, 0, 0} 183 {0, 0, 0}
184}; 184};
185MODULE_DEVICE_TABLE(pci, vmw_pci_id_list);
185 186
186static int enable_fbdev; 187static int enable_fbdev = IS_ENABLED(CONFIG_DRM_VMWGFX_FBCON);
187 188
188static int vmw_probe(struct pci_dev *, const struct pci_device_id *); 189static int vmw_probe(struct pci_dev *, const struct pci_device_id *);
189static void vmw_master_init(struct vmw_master *); 190static void vmw_master_init(struct vmw_master *);
@@ -1154,6 +1155,11 @@ static struct drm_driver driver = {
1154 .open = vmw_driver_open, 1155 .open = vmw_driver_open,
1155 .preclose = vmw_preclose, 1156 .preclose = vmw_preclose,
1156 .postclose = vmw_postclose, 1157 .postclose = vmw_postclose,
1158
1159 .dumb_create = vmw_dumb_create,
1160 .dumb_map_offset = vmw_dumb_map_offset,
1161 .dumb_destroy = vmw_dumb_destroy,
1162
1157 .fops = &vmwgfx_driver_fops, 1163 .fops = &vmwgfx_driver_fops,
1158 .name = VMWGFX_DRIVER_NAME, 1164 .name = VMWGFX_DRIVER_NAME,
1159 .desc = VMWGFX_DRIVER_DESC, 1165 .desc = VMWGFX_DRIVER_DESC,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index d0f2c079ee27..29c984ff7f23 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -645,6 +645,16 @@ int vmw_kms_readback(struct vmw_private *dev_priv,
645int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, 645int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
646 struct drm_file *file_priv); 646 struct drm_file *file_priv);
647 647
648int vmw_dumb_create(struct drm_file *file_priv,
649 struct drm_device *dev,
650 struct drm_mode_create_dumb *args);
651
652int vmw_dumb_map_offset(struct drm_file *file_priv,
653 struct drm_device *dev, uint32_t handle,
654 uint64_t *offset);
655int vmw_dumb_destroy(struct drm_file *file_priv,
656 struct drm_device *dev,
657 uint32_t handle);
648/** 658/**
649 * Overlay control - vmwgfx_overlay.c 659 * Overlay control - vmwgfx_overlay.c
650 */ 660 */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
index f2fb8f15e2f1..7e0743358dff 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
@@ -1018,7 +1018,7 @@ int vmw_event_fence_action_create(struct drm_file *file_priv,
1018 } 1018 }
1019 1019
1020 1020
1021 event = kzalloc(sizeof(event->event), GFP_KERNEL); 1021 event = kzalloc(sizeof(*event), GFP_KERNEL);
1022 if (unlikely(event == NULL)) { 1022 if (unlikely(event == NULL)) {
1023 DRM_ERROR("Failed to allocate an event.\n"); 1023 DRM_ERROR("Failed to allocate an event.\n");
1024 ret = -ENOMEM; 1024 ret = -ENOMEM;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 22bf9a21ec71..2c6ffe0e2c07 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -1917,3 +1917,76 @@ err_ref:
1917 vmw_resource_unreference(&res); 1917 vmw_resource_unreference(&res);
1918 return ret; 1918 return ret;
1919} 1919}
1920
1921
1922int vmw_dumb_create(struct drm_file *file_priv,
1923 struct drm_device *dev,
1924 struct drm_mode_create_dumb *args)
1925{
1926 struct vmw_private *dev_priv = vmw_priv(dev);
1927 struct vmw_master *vmaster = vmw_master(file_priv->master);
1928 struct vmw_user_dma_buffer *vmw_user_bo;
1929 struct ttm_buffer_object *tmp;
1930 int ret;
1931
1932 args->pitch = args->width * ((args->bpp + 7) / 8);
1933 args->size = args->pitch * args->height;
1934
1935 vmw_user_bo = kzalloc(sizeof(*vmw_user_bo), GFP_KERNEL);
1936 if (vmw_user_bo == NULL)
1937 return -ENOMEM;
1938
1939 ret = ttm_read_lock(&vmaster->lock, true);
1940 if (ret != 0) {
1941 kfree(vmw_user_bo);
1942 return ret;
1943 }
1944
1945 ret = vmw_dmabuf_init(dev_priv, &vmw_user_bo->dma, args->size,
1946 &vmw_vram_sys_placement, true,
1947 &vmw_user_dmabuf_destroy);
1948 if (ret != 0)
1949 goto out_no_dmabuf;
1950
1951 tmp = ttm_bo_reference(&vmw_user_bo->dma.base);
1952 ret = ttm_base_object_init(vmw_fpriv(file_priv)->tfile,
1953 &vmw_user_bo->base,
1954 false,
1955 ttm_buffer_type,
1956 &vmw_user_dmabuf_release, NULL);
1957 if (unlikely(ret != 0))
1958 goto out_no_base_object;
1959
1960 args->handle = vmw_user_bo->base.hash.key;
1961
1962out_no_base_object:
1963 ttm_bo_unref(&tmp);
1964out_no_dmabuf:
1965 ttm_read_unlock(&vmaster->lock);
1966 return ret;
1967}
1968
1969int vmw_dumb_map_offset(struct drm_file *file_priv,
1970 struct drm_device *dev, uint32_t handle,
1971 uint64_t *offset)
1972{
1973 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
1974 struct vmw_dma_buffer *out_buf;
1975 int ret;
1976
1977 ret = vmw_user_dmabuf_lookup(tfile, handle, &out_buf);
1978 if (ret != 0)
1979 return -EINVAL;
1980
1981 *offset = out_buf->base.addr_space_offset;
1982 vmw_dmabuf_unreference(&out_buf);
1983 return 0;
1984}
1985
1986int vmw_dumb_destroy(struct drm_file *file_priv,
1987 struct drm_device *dev,
1988 uint32_t handle)
1989{
1990 return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile,
1991 handle, TTM_REF_USAGE);
1992}
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index fbf49503508d..2af774ad1060 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -307,7 +307,6 @@ config HID_LOGITECH
307config HID_LOGITECH_DJ 307config HID_LOGITECH_DJ
308 tristate "Logitech Unifying receivers full support" 308 tristate "Logitech Unifying receivers full support"
309 depends on HID_LOGITECH 309 depends on HID_LOGITECH
310 default m
311 ---help--- 310 ---help---
312 Say Y if you want support for Logitech Unifying receivers and devices. 311 Say Y if you want support for Logitech Unifying receivers and devices.
313 Unifying receivers are capable of pairing up to 6 Logitech compliant 312 Unifying receivers are capable of pairing up to 6 Logitech compliant
@@ -527,6 +526,14 @@ config HID_PICOLCD_LEDS
527 ---help--- 526 ---help---
528 Provide access to PicoLCD's GPO pins via leds class. 527 Provide access to PicoLCD's GPO pins via leds class.
529 528
529config HID_PICOLCD_CIR
530 bool "CIR via RC class" if EXPERT
531 default !EXPERT
532 depends on HID_PICOLCD
533 depends on HID_PICOLCD=RC_CORE || RC_CORE=y
534 ---help---
535 Provide access to PicoLCD's CIR interface via remote control (LIRC).
536
530config HID_PRIMAX 537config HID_PRIMAX
531 tristate "Primax non-fully HID-compliant devices" 538 tristate "Primax non-fully HID-compliant devices"
532 depends on USB_HID 539 depends on USB_HID
@@ -534,6 +541,15 @@ config HID_PRIMAX
534 Support for Primax devices that are not fully compliant with the 541 Support for Primax devices that are not fully compliant with the
535 HID standard. 542 HID standard.
536 543
544config HID_PS3REMOTE
545 tristate "Sony PS3 BD Remote Control"
546 depends on BT_HIDP
547 ---help---
548 Support for the Sony PS3 Blue-ray Disk Remote Control and Logitech
549 Harmony Adapter for PS3, which connect over Bluetooth.
550
551 Support for the 6-axis controllers is provided by HID_SONY.
552
537config HID_ROCCAT 553config HID_ROCCAT
538 tristate "Roccat device support" 554 tristate "Roccat device support"
539 depends on USB_HID 555 depends on USB_HID
@@ -561,7 +577,9 @@ config HID_SONY
561 tristate "Sony PS3 controller" 577 tristate "Sony PS3 controller"
562 depends on USB_HID 578 depends on USB_HID
563 ---help--- 579 ---help---
564 Support for Sony PS3 controller. 580 Support for Sony PS3 6-axis controllers.
581
582 Support for the Sony PS3 BD Remote is provided by HID_PS3REMOTE.
565 583
566config HID_SPEEDLINK 584config HID_SPEEDLINK
567 tristate "Speedlink VAD Cezanne mouse support" 585 tristate "Speedlink VAD Cezanne mouse support"
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index f975485f88b2..5a3690ff9bf2 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -69,7 +69,28 @@ obj-$(CONFIG_HID_PRODIKEYS) += hid-prodikeys.o
69obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o 69obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o
70obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o 70obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o
71obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o 71obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o
72hid-picolcd-y += hid-picolcd_core.o
73ifdef CONFIG_HID_PICOLCD_FB
74hid-picolcd-y += hid-picolcd_fb.o
75endif
76ifdef CONFIG_HID_PICOLCD_BACKLIGHT
77hid-picolcd-y += hid-picolcd_backlight.o
78endif
79ifdef CONFIG_HID_PICOLCD_LCD
80hid-picolcd-y += hid-picolcd_lcd.o
81endif
82ifdef CONFIG_HID_PICOLCD_LEDS
83hid-picolcd-y += hid-picolcd_leds.o
84endif
85ifdef CONFIG_HID_PICOLCD_CIR
86hid-picolcd-y += hid-picolcd_cir.o
87endif
88ifdef CONFIG_DEBUG_FS
89hid-picolcd-y += hid-picolcd_debugfs.o
90endif
91
72obj-$(CONFIG_HID_PRIMAX) += hid-primax.o 92obj-$(CONFIG_HID_PRIMAX) += hid-primax.o
93obj-$(CONFIG_HID_PS3REMOTE) += hid-ps3remote.o
73obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o hid-roccat-common.o \ 94obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o hid-roccat-common.o \
74 hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \ 95 hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
75 hid-roccat-koneplus.o hid-roccat-kovaplus.o hid-roccat-pyra.o \ 96 hid-roccat-koneplus.o hid-roccat-kovaplus.o hid-roccat-pyra.o \
diff --git a/drivers/hid/hid-a4tech.c b/drivers/hid/hid-a4tech.c
index 902d1dfeb1b5..0a239885e67c 100644
--- a/drivers/hid/hid-a4tech.c
+++ b/drivers/hid/hid-a4tech.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 585344b6d338..06ebdbb6ea02 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com> 8 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-aureal.c b/drivers/hid/hid-aureal.c
index ba64b041b8bf..7968187ddf7b 100644
--- a/drivers/hid/hid-aureal.c
+++ b/drivers/hid/hid-aureal.c
@@ -9,7 +9,6 @@
9 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 9 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
10 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 10 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
11 * Copyright (c) 2006-2007 Jiri Kosina 11 * Copyright (c) 2006-2007 Jiri Kosina
12 * Copyright (c) 2007 Paul Walmsley
13 * Copyright (c) 2008 Jiri Slaby 12 * Copyright (c) 2008 Jiri Slaby
14 */ 13 */
15#include <linux/device.h> 14#include <linux/device.h>
diff --git a/drivers/hid/hid-belkin.c b/drivers/hid/hid-belkin.c
index a1a765a5b08a..a1a5a12c3a6b 100644
--- a/drivers/hid/hid-belkin.c
+++ b/drivers/hid/hid-belkin.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-cherry.c b/drivers/hid/hid-cherry.c
index 888ece68a47c..af034d3d9256 100644
--- a/drivers/hid/hid-cherry.c
+++ b/drivers/hid/hid-cherry.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 8bcd168fffae..2cd6880b6b17 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -126,7 +126,7 @@ static int open_collection(struct hid_parser *parser, unsigned type)
126 126
127 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { 127 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
128 hid_err(parser->device, "collection stack overflow\n"); 128 hid_err(parser->device, "collection stack overflow\n");
129 return -1; 129 return -EINVAL;
130 } 130 }
131 131
132 if (parser->device->maxcollection == parser->device->collection_size) { 132 if (parser->device->maxcollection == parser->device->collection_size) {
@@ -134,7 +134,7 @@ static int open_collection(struct hid_parser *parser, unsigned type)
134 parser->device->collection_size * 2, GFP_KERNEL); 134 parser->device->collection_size * 2, GFP_KERNEL);
135 if (collection == NULL) { 135 if (collection == NULL) {
136 hid_err(parser->device, "failed to reallocate collection array\n"); 136 hid_err(parser->device, "failed to reallocate collection array\n");
137 return -1; 137 return -ENOMEM;
138 } 138 }
139 memcpy(collection, parser->device->collection, 139 memcpy(collection, parser->device->collection,
140 sizeof(struct hid_collection) * 140 sizeof(struct hid_collection) *
@@ -170,7 +170,7 @@ static int close_collection(struct hid_parser *parser)
170{ 170{
171 if (!parser->collection_stack_ptr) { 171 if (!parser->collection_stack_ptr) {
172 hid_err(parser->device, "collection stack underflow\n"); 172 hid_err(parser->device, "collection stack underflow\n");
173 return -1; 173 return -EINVAL;
174 } 174 }
175 parser->collection_stack_ptr--; 175 parser->collection_stack_ptr--;
176 return 0; 176 return 0;
@@ -374,7 +374,7 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
374 374
375 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: 375 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
376 parser->global.report_size = item_udata(item); 376 parser->global.report_size = item_udata(item);
377 if (parser->global.report_size > 96) { 377 if (parser->global.report_size > 128) {
378 hid_err(parser->device, "invalid report_size %d\n", 378 hid_err(parser->device, "invalid report_size %d\n",
379 parser->global.report_size); 379 parser->global.report_size);
380 return -1; 380 return -1;
@@ -757,6 +757,7 @@ int hid_open_report(struct hid_device *device)
757 struct hid_item item; 757 struct hid_item item;
758 unsigned int size; 758 unsigned int size;
759 __u8 *start; 759 __u8 *start;
760 __u8 *buf;
760 __u8 *end; 761 __u8 *end;
761 int ret; 762 int ret;
762 static int (*dispatch_type[])(struct hid_parser *parser, 763 static int (*dispatch_type[])(struct hid_parser *parser,
@@ -775,12 +776,21 @@ int hid_open_report(struct hid_device *device)
775 return -ENODEV; 776 return -ENODEV;
776 size = device->dev_rsize; 777 size = device->dev_rsize;
777 778
779 buf = kmemdup(start, size, GFP_KERNEL);
780 if (buf == NULL)
781 return -ENOMEM;
782
778 if (device->driver->report_fixup) 783 if (device->driver->report_fixup)
779 start = device->driver->report_fixup(device, start, &size); 784 start = device->driver->report_fixup(device, buf, &size);
785 else
786 start = buf;
780 787
781 device->rdesc = kmemdup(start, size, GFP_KERNEL); 788 start = kmemdup(start, size, GFP_KERNEL);
782 if (device->rdesc == NULL) 789 kfree(buf);
790 if (start == NULL)
783 return -ENOMEM; 791 return -ENOMEM;
792
793 device->rdesc = start;
784 device->rsize = size; 794 device->rsize = size;
785 795
786 parser = vzalloc(sizeof(struct hid_parser)); 796 parser = vzalloc(sizeof(struct hid_parser));
@@ -1448,7 +1458,14 @@ void hid_disconnect(struct hid_device *hdev)
1448} 1458}
1449EXPORT_SYMBOL_GPL(hid_disconnect); 1459EXPORT_SYMBOL_GPL(hid_disconnect);
1450 1460
1451/* a list of devices for which there is a specialized driver on HID bus */ 1461/*
1462 * A list of devices for which there is a specialized driver on HID bus.
1463 *
1464 * Please note that for multitouch devices (driven by hid-multitouch driver),
1465 * there is a proper autodetection and autoloading in place (based on presence
1466 * of HID_DG_CONTACTID), so those devices don't need to be added to this list,
1467 * as we are doing the right thing in hid_scan_usage().
1468 */
1452static const struct hid_device_id hid_have_special_driver[] = { 1469static const struct hid_device_id hid_have_special_driver[] = {
1453 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, 1470 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1454 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, 1471 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
@@ -1566,6 +1583,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1566 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, 1583 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1567 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, 1584 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
1568 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) }, 1585 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
1586 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
1569 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) }, 1587 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
1570 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) }, 1588 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
1571 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) }, 1589 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
@@ -1627,6 +1645,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1627 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) }, 1645 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
1628 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, 1646 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1629 { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) }, 1647 { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
1648#if IS_ENABLED(CONFIG_HID_ROCCAT)
1630 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) }, 1649 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1631 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) }, 1650 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
1632 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) }, 1651 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
@@ -1635,10 +1654,12 @@ static const struct hid_device_id hid_have_special_driver[] = {
1635 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) }, 1654 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
1636 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) }, 1655 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
1637 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) }, 1656 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
1657#endif
1638 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) }, 1658 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
1639 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, 1659 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1640 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) }, 1660 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1641 { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) }, 1661 { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
1662 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
1642 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1663 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1643 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) }, 1664 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
1644 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1665 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
@@ -1663,6 +1684,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1663 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) }, 1684 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
1664 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) }, 1685 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
1665 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) }, 1686 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
1687 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
1666 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) }, 1688 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
1667 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) }, 1689 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
1668 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) }, 1690 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
diff --git a/drivers/hid/hid-cypress.c b/drivers/hid/hid-cypress.c
index 9e43aaca9774..3e159a50dac7 100644
--- a/drivers/hid/hid-cypress.c
+++ b/drivers/hid/hid-cypress.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 01dd9a7daf7a..933fff0fff1f 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -911,15 +911,21 @@ static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
911 911
912} 912}
913 913
914
915static int hid_debug_rdesc_show(struct seq_file *f, void *p) 914static int hid_debug_rdesc_show(struct seq_file *f, void *p)
916{ 915{
917 struct hid_device *hdev = f->private; 916 struct hid_device *hdev = f->private;
917 const __u8 *rdesc = hdev->rdesc;
918 unsigned rsize = hdev->rsize;
918 int i; 919 int i;
919 920
921 if (!rdesc) {
922 rdesc = hdev->dev_rdesc;
923 rsize = hdev->dev_rsize;
924 }
925
920 /* dump HID report descriptor */ 926 /* dump HID report descriptor */
921 for (i = 0; i < hdev->rsize; i++) 927 for (i = 0; i < rsize; i++)
922 seq_printf(f, "%02x ", hdev->rdesc[i]); 928 seq_printf(f, "%02x ", rdesc[i]);
923 seq_printf(f, "\n\n"); 929 seq_printf(f, "\n\n");
924 930
925 /* dump parsed data and input mappings */ 931 /* dump parsed data and input mappings */
diff --git a/drivers/hid/hid-ezkey.c b/drivers/hid/hid-ezkey.c
index ca1163e9d42d..6540af2871a7 100644
--- a/drivers/hid/hid-ezkey.c
+++ b/drivers/hid/hid-ezkey.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-gyration.c b/drivers/hid/hid-gyration.c
index e88b951cd10d..4442c30ef531 100644
--- a/drivers/hid/hid-gyration.c
+++ b/drivers/hid/hid-gyration.c
@@ -4,7 +4,6 @@
4 * Copyright (c) 1999 Andreas Gal 4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2007 Paul Walmsley
8 * Copyright (c) 2008 Jiri Slaby 7 * Copyright (c) 2008 Jiri Slaby
9 * Copyright (c) 2006-2008 Jiri Kosina 8 * Copyright (c) 2006-2008 Jiri Kosina
10 */ 9 */
diff --git a/drivers/hid/hid-holtekff.c b/drivers/hid/hid-holtekff.c
index 4e7542151e22..ff295e60059b 100644
--- a/drivers/hid/hid-holtekff.c
+++ b/drivers/hid/hid-holtekff.c
@@ -100,8 +100,7 @@ static void holtekff_send(struct holtekff_device *holtekff,
100 holtekff->field->value[i] = data[i]; 100 holtekff->field->value[i] = data[i];
101 } 101 }
102 102
103 dbg_hid("sending %02x %02x %02x %02x %02x %02x %02x\n", data[0], 103 dbg_hid("sending %*ph\n", 7, data);
104 data[1], data[2], data[3], data[4], data[5], data[6]);
105 104
106 usbhid_submit_report(hid, holtekff->field->report, USB_DIR_OUT); 105 usbhid_submit_report(hid, holtekff->field->report, USB_DIR_OUT);
107} 106}
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 1dcb76ff51e3..ca4d83e6e387 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 */ 8 */
10 9
11/* 10/*
@@ -269,7 +268,11 @@
269#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA 0x72fa 268#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA 0x72fa
270#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302 0x7302 269#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302 0x7302
271#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349 0x7349 270#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349 0x7349
271#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7 0x73f7
272#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001 0xa001 272#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001 0xa001
273#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224 0x7224
274#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0 0x72d0
275#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4 0x72c4
273 276
274#define USB_VENDOR_ID_ELECOM 0x056e 277#define USB_VENDOR_ID_ELECOM 0x056e
275#define USB_DEVICE_ID_ELECOM_BM084 0x0061 278#define USB_DEVICE_ID_ELECOM_BM084 0x0061
@@ -283,6 +286,9 @@
283#define USB_VENDOR_ID_EMS 0x2006 286#define USB_VENDOR_ID_EMS 0x2006
284#define USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II 0x0118 287#define USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II 0x0118
285 288
289#define USB_VENDOR_ID_FLATFROG 0x25b5
290#define USB_DEVICE_ID_MULTITOUCH_3200 0x0002
291
286#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f 292#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f
287#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100 293#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100
288 294
@@ -296,6 +302,9 @@
296#define USB_VENDOR_ID_EZKEY 0x0518 302#define USB_VENDOR_ID_EZKEY 0x0518
297#define USB_DEVICE_ID_BTC_8193 0x0002 303#define USB_DEVICE_ID_BTC_8193 0x0002
298 304
305#define USB_VENDOR_ID_FREESCALE 0x15A2
306#define USB_DEVICE_ID_FREESCALE_MX28 0x004F
307
299#define USB_VENDOR_ID_FRUCTEL 0x25B6 308#define USB_VENDOR_ID_FRUCTEL 0x25B6
300#define USB_DEVICE_ID_GAMETEL_MT_MODE 0x0002 309#define USB_DEVICE_ID_GAMETEL_MT_MODE 0x0002
301 310
@@ -305,6 +314,7 @@
305 314
306#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc 315#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc
307#define USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS 0x0003 316#define USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS 0x0003
317#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS 0x0100
308 318
309#define USB_VENDOR_ID_GLAB 0x06c2 319#define USB_VENDOR_ID_GLAB 0x06c2
310#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038 320#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
@@ -496,6 +506,7 @@
496#define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101 506#define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101
497#define USB_DEVICE_ID_LOGITECH_HARMONY_FIRST 0xc110 507#define USB_DEVICE_ID_LOGITECH_HARMONY_FIRST 0xc110
498#define USB_DEVICE_ID_LOGITECH_HARMONY_LAST 0xc14f 508#define USB_DEVICE_ID_LOGITECH_HARMONY_LAST 0xc14f
509#define USB_DEVICE_ID_LOGITECH_HARMONY_PS3 0x0306
499#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD 0xc20a 510#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD 0xc20a
500#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD 0xc211 511#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD 0xc211
501#define USB_DEVICE_ID_LOGITECH_EXTREME_3D 0xc215 512#define USB_DEVICE_ID_LOGITECH_EXTREME_3D 0xc215
@@ -652,7 +663,6 @@
652#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH 0x3000 663#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH 0x3000
653#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001 0x3001 664#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001 0x3001
654#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008 0x3008 665#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008 0x3008
655#define USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN 0x3001
656 666
657#define USB_VENDOR_ID_ROCCAT 0x1e7d 667#define USB_VENDOR_ID_ROCCAT 0x1e7d
658#define USB_DEVICE_ID_ROCCAT_ARVO 0x30d4 668#define USB_DEVICE_ID_ROCCAT_ARVO 0x30d4
@@ -683,6 +693,7 @@
683 693
684#define USB_VENDOR_ID_SONY 0x054c 694#define USB_VENDOR_ID_SONY 0x054c
685#define USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE 0x024b 695#define USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE 0x024b
696#define USB_DEVICE_ID_SONY_PS3_BDREMOTE 0x0306
686#define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268 697#define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268
687#define USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER 0x042f 698#define USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER 0x042f
688 699
@@ -758,6 +769,7 @@
758#define USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U 0x0005 769#define USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U 0x0005
759#define USB_DEVICE_ID_UCLOGIC_TABLET_WP1062 0x0064 770#define USB_DEVICE_ID_UCLOGIC_TABLET_WP1062 0x0064
760#define USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850 0x0522 771#define USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850 0x0522
772#define USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60 0x0781
761 773
762#define USB_VENDOR_ID_UNITEC 0x227d 774#define USB_VENDOR_ID_UNITEC 0x227d
763#define USB_DEVICE_ID_UNITEC_USB_TOUCH_0709 0x0709 775#define USB_DEVICE_ID_UNITEC_USB_TOUCH_0709 0x0709
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 811bfad64609..d917c0d53685 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1154,6 +1154,7 @@ static void report_features(struct hid_device *hid)
1154 1154
1155int hidinput_connect(struct hid_device *hid, unsigned int force) 1155int hidinput_connect(struct hid_device *hid, unsigned int force)
1156{ 1156{
1157 struct hid_driver *drv = hid->driver;
1157 struct hid_report *report; 1158 struct hid_report *report;
1158 struct hid_input *hidinput = NULL; 1159 struct hid_input *hidinput = NULL;
1159 struct input_dev *input_dev; 1160 struct input_dev *input_dev;
@@ -1228,6 +1229,8 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
1228 * UGCI) cram a lot of unrelated inputs into the 1229 * UGCI) cram a lot of unrelated inputs into the
1229 * same interface. */ 1230 * same interface. */
1230 hidinput->report = report; 1231 hidinput->report = report;
1232 if (drv->input_configured)
1233 drv->input_configured(hid, hidinput);
1231 if (input_register_device(hidinput->input)) 1234 if (input_register_device(hidinput->input))
1232 goto out_cleanup; 1235 goto out_cleanup;
1233 hidinput = NULL; 1236 hidinput = NULL;
@@ -1235,8 +1238,12 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
1235 } 1238 }
1236 } 1239 }
1237 1240
1238 if (hidinput && input_register_device(hidinput->input)) 1241 if (hidinput) {
1239 goto out_cleanup; 1242 if (drv->input_configured)
1243 drv->input_configured(hid, hidinput);
1244 if (input_register_device(hidinput->input))
1245 goto out_cleanup;
1246 }
1240 1247
1241 return 0; 1248 return 0;
1242 1249
diff --git a/drivers/hid/hid-lcpower.c b/drivers/hid/hid-lcpower.c
index c4fe9bd095b7..22bc14abdfa3 100644
--- a/drivers/hid/hid-lcpower.c
+++ b/drivers/hid/hid-lcpower.c
@@ -24,7 +24,7 @@ static int ts_input_mapping(struct hid_device *hdev, struct hid_input *hi,
24 struct hid_field *field, struct hid_usage *usage, 24 struct hid_field *field, struct hid_usage *usage,
25 unsigned long **bit, int *max) 25 unsigned long **bit, int *max)
26{ 26{
27 if ((usage->hid & HID_USAGE_PAGE) != 0x0ffbc0000) 27 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
28 return 0; 28 return 0;
29 29
30 switch (usage->hid & HID_USAGE) { 30 switch (usage->hid & HID_USAGE) {
diff --git a/drivers/hid/hid-lenovo-tpkbd.c b/drivers/hid/hid-lenovo-tpkbd.c
index 77d2df04c97b..cea016e94f43 100644
--- a/drivers/hid/hid-lenovo-tpkbd.c
+++ b/drivers/hid/hid-lenovo-tpkbd.c
@@ -56,9 +56,8 @@ static int tpkbd_input_mapping(struct hid_device *hdev,
56static int tpkbd_features_set(struct hid_device *hdev) 56static int tpkbd_features_set(struct hid_device *hdev)
57{ 57{
58 struct hid_report *report; 58 struct hid_report *report;
59 struct tpkbd_data_pointer *data_pointer; 59 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
60 60
61 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
62 report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[4]; 61 report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[4];
63 62
64 report->field[0]->value[0] = data_pointer->press_to_select ? 0x01 : 0x02; 63 report->field[0]->value[0] = data_pointer->press_to_select ? 0x01 : 0x02;
@@ -77,14 +76,8 @@ static ssize_t pointer_press_to_select_show(struct device *dev,
77 struct device_attribute *attr, 76 struct device_attribute *attr,
78 char *buf) 77 char *buf)
79{ 78{
80 struct hid_device *hdev; 79 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
81 struct tpkbd_data_pointer *data_pointer; 80 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
82
83 hdev = container_of(dev, struct hid_device, dev);
84 if (hdev == NULL)
85 return -ENODEV;
86
87 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
88 81
89 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select); 82 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select);
90} 83}
@@ -94,16 +87,10 @@ static ssize_t pointer_press_to_select_store(struct device *dev,
94 const char *buf, 87 const char *buf,
95 size_t count) 88 size_t count)
96{ 89{
97 struct hid_device *hdev; 90 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
98 struct tpkbd_data_pointer *data_pointer; 91 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
99 int value; 92 int value;
100 93
101 hdev = container_of(dev, struct hid_device, dev);
102 if (hdev == NULL)
103 return -ENODEV;
104
105 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
106
107 if (kstrtoint(buf, 10, &value)) 94 if (kstrtoint(buf, 10, &value))
108 return -EINVAL; 95 return -EINVAL;
109 if (value < 0 || value > 1) 96 if (value < 0 || value > 1)
@@ -119,14 +106,8 @@ static ssize_t pointer_dragging_show(struct device *dev,
119 struct device_attribute *attr, 106 struct device_attribute *attr,
120 char *buf) 107 char *buf)
121{ 108{
122 struct hid_device *hdev; 109 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
123 struct tpkbd_data_pointer *data_pointer; 110 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
124
125 hdev = container_of(dev, struct hid_device, dev);
126 if (hdev == NULL)
127 return -ENODEV;
128
129 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
130 111
131 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging); 112 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging);
132} 113}
@@ -136,16 +117,10 @@ static ssize_t pointer_dragging_store(struct device *dev,
136 const char *buf, 117 const char *buf,
137 size_t count) 118 size_t count)
138{ 119{
139 struct hid_device *hdev; 120 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
140 struct tpkbd_data_pointer *data_pointer; 121 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
141 int value; 122 int value;
142 123
143 hdev = container_of(dev, struct hid_device, dev);
144 if (hdev == NULL)
145 return -ENODEV;
146
147 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
148
149 if (kstrtoint(buf, 10, &value)) 124 if (kstrtoint(buf, 10, &value))
150 return -EINVAL; 125 return -EINVAL;
151 if (value < 0 || value > 1) 126 if (value < 0 || value > 1)
@@ -161,14 +136,8 @@ static ssize_t pointer_release_to_select_show(struct device *dev,
161 struct device_attribute *attr, 136 struct device_attribute *attr,
162 char *buf) 137 char *buf)
163{ 138{
164 struct hid_device *hdev; 139 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
165 struct tpkbd_data_pointer *data_pointer; 140 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
166
167 hdev = container_of(dev, struct hid_device, dev);
168 if (hdev == NULL)
169 return -ENODEV;
170
171 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
172 141
173 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select); 142 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select);
174} 143}
@@ -178,16 +147,10 @@ static ssize_t pointer_release_to_select_store(struct device *dev,
178 const char *buf, 147 const char *buf,
179 size_t count) 148 size_t count)
180{ 149{
181 struct hid_device *hdev; 150 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
182 struct tpkbd_data_pointer *data_pointer; 151 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
183 int value; 152 int value;
184 153
185 hdev = container_of(dev, struct hid_device, dev);
186 if (hdev == NULL)
187 return -ENODEV;
188
189 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
190
191 if (kstrtoint(buf, 10, &value)) 154 if (kstrtoint(buf, 10, &value))
192 return -EINVAL; 155 return -EINVAL;
193 if (value < 0 || value > 1) 156 if (value < 0 || value > 1)
@@ -203,14 +166,8 @@ static ssize_t pointer_select_right_show(struct device *dev,
203 struct device_attribute *attr, 166 struct device_attribute *attr,
204 char *buf) 167 char *buf)
205{ 168{
206 struct hid_device *hdev; 169 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
207 struct tpkbd_data_pointer *data_pointer; 170 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
208
209 hdev = container_of(dev, struct hid_device, dev);
210 if (hdev == NULL)
211 return -ENODEV;
212
213 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
214 171
215 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right); 172 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right);
216} 173}
@@ -220,16 +177,10 @@ static ssize_t pointer_select_right_store(struct device *dev,
220 const char *buf, 177 const char *buf,
221 size_t count) 178 size_t count)
222{ 179{
223 struct hid_device *hdev; 180 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
224 struct tpkbd_data_pointer *data_pointer; 181 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
225 int value; 182 int value;
226 183
227 hdev = container_of(dev, struct hid_device, dev);
228 if (hdev == NULL)
229 return -ENODEV;
230
231 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
232
233 if (kstrtoint(buf, 10, &value)) 184 if (kstrtoint(buf, 10, &value))
234 return -EINVAL; 185 return -EINVAL;
235 if (value < 0 || value > 1) 186 if (value < 0 || value > 1)
@@ -245,14 +196,8 @@ static ssize_t pointer_sensitivity_show(struct device *dev,
245 struct device_attribute *attr, 196 struct device_attribute *attr,
246 char *buf) 197 char *buf)
247{ 198{
248 struct hid_device *hdev; 199 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
249 struct tpkbd_data_pointer *data_pointer; 200 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
250
251 hdev = container_of(dev, struct hid_device, dev);
252 if (hdev == NULL)
253 return -ENODEV;
254
255 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
256 201
257 return snprintf(buf, PAGE_SIZE, "%u\n", 202 return snprintf(buf, PAGE_SIZE, "%u\n",
258 data_pointer->sensitivity); 203 data_pointer->sensitivity);
@@ -263,16 +208,10 @@ static ssize_t pointer_sensitivity_store(struct device *dev,
263 const char *buf, 208 const char *buf,
264 size_t count) 209 size_t count)
265{ 210{
266 struct hid_device *hdev; 211 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
267 struct tpkbd_data_pointer *data_pointer; 212 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
268 int value; 213 int value;
269 214
270 hdev = container_of(dev, struct hid_device, dev);
271 if (hdev == NULL)
272 return -ENODEV;
273
274 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
275
276 if (kstrtoint(buf, 10, &value) || value < 1 || value > 255) 215 if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
277 return -EINVAL; 216 return -EINVAL;
278 217
@@ -286,14 +225,10 @@ static ssize_t pointer_press_speed_show(struct device *dev,
286 struct device_attribute *attr, 225 struct device_attribute *attr,
287 char *buf) 226 char *buf)
288{ 227{
289 struct hid_device *hdev; 228 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
290 struct tpkbd_data_pointer *data_pointer; 229 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
291 230
292 hdev = container_of(dev, struct hid_device, dev); 231 data_pointer = hid_get_drvdata(hdev);
293 if (hdev == NULL)
294 return -ENODEV;
295
296 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
297 232
298 return snprintf(buf, PAGE_SIZE, "%u\n", 233 return snprintf(buf, PAGE_SIZE, "%u\n",
299 data_pointer->press_speed); 234 data_pointer->press_speed);
@@ -304,16 +239,10 @@ static ssize_t pointer_press_speed_store(struct device *dev,
304 const char *buf, 239 const char *buf,
305 size_t count) 240 size_t count)
306{ 241{
307 struct hid_device *hdev; 242 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
308 struct tpkbd_data_pointer *data_pointer; 243 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
309 int value; 244 int value;
310 245
311 hdev = container_of(dev, struct hid_device, dev);
312 if (hdev == NULL)
313 return -ENODEV;
314
315 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
316
317 if (kstrtoint(buf, 10, &value) || value < 1 || value > 255) 246 if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
318 return -EINVAL; 247 return -EINVAL;
319 248
@@ -370,15 +299,11 @@ static const struct attribute_group tpkbd_attr_group_pointer = {
370static enum led_brightness tpkbd_led_brightness_get( 299static enum led_brightness tpkbd_led_brightness_get(
371 struct led_classdev *led_cdev) 300 struct led_classdev *led_cdev)
372{ 301{
373 struct device *dev; 302 struct device *dev = led_cdev->dev->parent;
374 struct hid_device *hdev; 303 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
375 struct tpkbd_data_pointer *data_pointer; 304 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
376 int led_nr = 0; 305 int led_nr = 0;
377 306
378 dev = led_cdev->dev->parent;
379 hdev = container_of(dev, struct hid_device, dev);
380 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
381
382 if (led_cdev == &data_pointer->led_micmute) 307 if (led_cdev == &data_pointer->led_micmute)
383 led_nr = 1; 308 led_nr = 1;
384 309
@@ -390,16 +315,12 @@ static enum led_brightness tpkbd_led_brightness_get(
390static void tpkbd_led_brightness_set(struct led_classdev *led_cdev, 315static void tpkbd_led_brightness_set(struct led_classdev *led_cdev,
391 enum led_brightness value) 316 enum led_brightness value)
392{ 317{
393 struct device *dev; 318 struct device *dev = led_cdev->dev->parent;
394 struct hid_device *hdev; 319 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
320 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
395 struct hid_report *report; 321 struct hid_report *report;
396 struct tpkbd_data_pointer *data_pointer;
397 int led_nr = 0; 322 int led_nr = 0;
398 323
399 dev = led_cdev->dev->parent;
400 hdev = container_of(dev, struct hid_device, dev);
401 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
402
403 if (led_cdev == &data_pointer->led_micmute) 324 if (led_cdev == &data_pointer->led_micmute)
404 led_nr = 1; 325 led_nr = 1;
405 326
@@ -508,17 +429,17 @@ err_free:
508 429
509static void tpkbd_remove_tp(struct hid_device *hdev) 430static void tpkbd_remove_tp(struct hid_device *hdev)
510{ 431{
511 struct tpkbd_data_pointer *data_pointer; 432 struct tpkbd_data_pointer *data_pointer = hid_get_drvdata(hdev);
512 433
513 sysfs_remove_group(&hdev->dev.kobj, 434 sysfs_remove_group(&hdev->dev.kobj,
514 &tpkbd_attr_group_pointer); 435 &tpkbd_attr_group_pointer);
515 436
516 data_pointer = (struct tpkbd_data_pointer *) hid_get_drvdata(hdev);
517
518 led_classdev_unregister(&data_pointer->led_micmute); 437 led_classdev_unregister(&data_pointer->led_micmute);
519 led_classdev_unregister(&data_pointer->led_mute); 438 led_classdev_unregister(&data_pointer->led_mute);
520 439
521 hid_set_drvdata(hdev, NULL); 440 hid_set_drvdata(hdev, NULL);
441 kfree(data_pointer->led_micmute.name);
442 kfree(data_pointer->led_mute.name);
522 kfree(data_pointer); 443 kfree(data_pointer);
523} 444}
524 445
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
index fc37ed6b108c..a2f8e88b9fa2 100644
--- a/drivers/hid/hid-lg.c
+++ b/drivers/hid/hid-lg.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 * Copyright (c) 2010 Hendrik Iben 9 * Copyright (c) 2010 Hendrik Iben
11 */ 10 */
@@ -109,7 +108,7 @@ static __u8 dfp_rdesc_fixed[] = {
109static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc, 108static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
110 unsigned int *rsize) 109 unsigned int *rsize)
111{ 110{
112 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); 111 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
113 112
114 if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 && 113 if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
115 rdesc[84] == 0x8c && rdesc[85] == 0x02) { 114 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
@@ -278,7 +277,7 @@ static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi,
278 0, 0, 0, 0, 0,183,184,185,186,187, 277 0, 0, 0, 0, 0,183,184,185,186,187,
279 188,189,190,191,192,193,194, 0, 0, 0 278 188,189,190,191,192,193,194, 0, 0, 0
280 }; 279 };
281 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); 280 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
282 unsigned int hid = usage->hid; 281 unsigned int hid = usage->hid;
283 282
284 if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER && 283 if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER &&
@@ -319,7 +318,7 @@ static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
319 struct hid_field *field, struct hid_usage *usage, 318 struct hid_field *field, struct hid_usage *usage,
320 unsigned long **bit, int *max) 319 unsigned long **bit, int *max)
321{ 320{
322 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); 321 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
323 322
324 if ((drv_data->quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY && 323 if ((drv_data->quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY &&
325 (field->flags & HID_MAIN_ITEM_RELATIVE)) 324 (field->flags & HID_MAIN_ITEM_RELATIVE))
@@ -335,13 +334,16 @@ static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
335static int lg_event(struct hid_device *hdev, struct hid_field *field, 334static int lg_event(struct hid_device *hdev, struct hid_field *field,
336 struct hid_usage *usage, __s32 value) 335 struct hid_usage *usage, __s32 value)
337{ 336{
338 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); 337 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
339 338
340 if ((drv_data->quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) { 339 if ((drv_data->quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) {
341 input_event(field->hidinput->input, usage->type, usage->code, 340 input_event(field->hidinput->input, usage->type, usage->code,
342 -value); 341 -value);
343 return 1; 342 return 1;
344 } 343 }
344 if (drv_data->quirks & LG_FF4) {
345 return lg4ff_adjust_input_event(hdev, field, usage, value, drv_data);
346 }
345 347
346 return 0; 348 return 0;
347} 349}
@@ -358,7 +360,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
358 return -ENOMEM; 360 return -ENOMEM;
359 } 361 }
360 drv_data->quirks = id->driver_data; 362 drv_data->quirks = id->driver_data;
361 363
362 hid_set_drvdata(hdev, (void *)drv_data); 364 hid_set_drvdata(hdev, (void *)drv_data);
363 365
364 if (drv_data->quirks & LG_NOGET) 366 if (drv_data->quirks & LG_NOGET)
@@ -380,7 +382,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
380 } 382 }
381 383
382 /* Setup wireless link with Logitech Wii wheel */ 384 /* Setup wireless link with Logitech Wii wheel */
383 if(hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) { 385 if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) {
384 unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 386 unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
385 387
386 ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); 388 ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
@@ -416,7 +418,7 @@ err_free:
416 418
417static void lg_remove(struct hid_device *hdev) 419static void lg_remove(struct hid_device *hdev)
418{ 420{
419 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); 421 struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
420 if (drv_data->quirks & LG_FF4) 422 if (drv_data->quirks & LG_FF4)
421 lg4ff_deinit(hdev); 423 lg4ff_deinit(hdev);
422 424
@@ -476,7 +478,7 @@ static const struct hid_device_id lg_devices[] = {
476 .driver_data = LG_NOGET | LG_FF4 }, 478 .driver_data = LG_NOGET | LG_FF4 },
477 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL), 479 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL),
478 .driver_data = LG_FF4 }, 480 .driver_data = LG_FF4 },
479 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ), 481 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG),
480 .driver_data = LG_FF }, 482 .driver_data = LG_FF },
481 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2), 483 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2),
482 .driver_data = LG_FF2 }, 484 .driver_data = LG_FF2 },
diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h
index d64cf8d2751e..142ce3f5f055 100644
--- a/drivers/hid/hid-lg.h
+++ b/drivers/hid/hid-lg.h
@@ -25,9 +25,13 @@ static inline int lg3ff_init(struct hid_device *hdev) { return -1; }
25#endif 25#endif
26 26
27#ifdef CONFIG_LOGIWHEELS_FF 27#ifdef CONFIG_LOGIWHEELS_FF
28int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field,
29 struct hid_usage *usage, __s32 value, struct lg_drv_data *drv_data);
28int lg4ff_init(struct hid_device *hdev); 30int lg4ff_init(struct hid_device *hdev);
29int lg4ff_deinit(struct hid_device *hdev); 31int lg4ff_deinit(struct hid_device *hdev);
30#else 32#else
33static inline int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field,
34 struct hid_usage *usage, __s32 value, struct lg_drv_data *drv_data) { return 0; }
31static inline int lg4ff_init(struct hid_device *hdev) { return -1; } 35static inline int lg4ff_init(struct hid_device *hdev) { return -1; }
32static inline int lg4ff_deinit(struct hid_device *hdev) { return -1; } 36static inline int lg4ff_deinit(struct hid_device *hdev) { return -1; }
33#endif 37#endif
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
index f3390ee6105c..d7947c701f30 100644
--- a/drivers/hid/hid-lg4ff.c
+++ b/drivers/hid/hid-lg4ff.c
@@ -43,6 +43,11 @@
43#define G27_REV_MAJ 0x12 43#define G27_REV_MAJ 0x12
44#define G27_REV_MIN 0x38 44#define G27_REV_MIN 0x38
45 45
46#define DFP_X_MIN 0
47#define DFP_X_MAX 16383
48#define DFP_PEDAL_MIN 0
49#define DFP_PEDAL_MAX 255
50
46#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) 51#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev)
47 52
48static void hid_lg4ff_set_range_dfp(struct hid_device *hid, u16 range); 53static void hid_lg4ff_set_range_dfp(struct hid_device *hid, u16 range);
@@ -53,6 +58,7 @@ static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *at
53static DEVICE_ATTR(range, S_IRWXU | S_IRWXG | S_IRWXO, lg4ff_range_show, lg4ff_range_store); 58static DEVICE_ATTR(range, S_IRWXU | S_IRWXG | S_IRWXO, lg4ff_range_show, lg4ff_range_store);
54 59
55struct lg4ff_device_entry { 60struct lg4ff_device_entry {
61 __u32 product_id;
56 __u16 range; 62 __u16 range;
57 __u16 min_range; 63 __u16 min_range;
58 __u16 max_range; 64 __u16 max_range;
@@ -129,26 +135,77 @@ static const struct lg4ff_usb_revision lg4ff_revs[] = {
129 {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */ 135 {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */
130}; 136};
131 137
138/* Recalculates X axis value accordingly to currently selected range */
139static __s32 lg4ff_adjust_dfp_x_axis(__s32 value, __u16 range)
140{
141 __u16 max_range;
142 __s32 new_value;
143
144 if (range == 900)
145 return value;
146 else if (range == 200)
147 return value;
148 else if (range < 200)
149 max_range = 200;
150 else
151 max_range = 900;
152
153 new_value = 8192 + mult_frac(value - 8192, max_range, range);
154 if (new_value < 0)
155 return 0;
156 else if (new_value > 16383)
157 return 16383;
158 else
159 return new_value;
160}
161
162int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field,
163 struct hid_usage *usage, __s32 value, struct lg_drv_data *drv_data)
164{
165 struct lg4ff_device_entry *entry = drv_data->device_props;
166 __s32 new_value = 0;
167
168 if (!entry) {
169 hid_err(hid, "Device properties not found");
170 return 0;
171 }
172
173 switch (entry->product_id) {
174 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
175 switch (usage->code) {
176 case ABS_X:
177 new_value = lg4ff_adjust_dfp_x_axis(value, entry->range);
178 input_event(field->hidinput->input, usage->type, usage->code, new_value);
179 return 1;
180 default:
181 return 0;
182 }
183 default:
184 return 0;
185 }
186}
187
132static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 188static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
133{ 189{
134 struct hid_device *hid = input_get_drvdata(dev); 190 struct hid_device *hid = input_get_drvdata(dev);
135 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 191 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
136 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 192 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
193 __s32 *value = report->field[0]->value;
137 int x; 194 int x;
138 195
139#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff 196#define CLAMP(x) do { if (x < 0) x = 0; else if (x > 0xff) x = 0xff; } while (0)
140 197
141 switch (effect->type) { 198 switch (effect->type) {
142 case FF_CONSTANT: 199 case FF_CONSTANT:
143 x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */ 200 x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */
144 CLAMP(x); 201 CLAMP(x);
145 report->field[0]->value[0] = 0x11; /* Slot 1 */ 202 value[0] = 0x11; /* Slot 1 */
146 report->field[0]->value[1] = 0x08; 203 value[1] = 0x08;
147 report->field[0]->value[2] = x; 204 value[2] = x;
148 report->field[0]->value[3] = 0x80; 205 value[3] = 0x80;
149 report->field[0]->value[4] = 0x00; 206 value[4] = 0x00;
150 report->field[0]->value[5] = 0x00; 207 value[5] = 0x00;
151 report->field[0]->value[6] = 0x00; 208 value[6] = 0x00;
152 209
153 usbhid_submit_report(hid, report, USB_DIR_OUT); 210 usbhid_submit_report(hid, report, USB_DIR_OUT);
154 break; 211 break;
@@ -163,14 +220,15 @@ static void hid_lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitud
163 struct hid_device *hid = input_get_drvdata(dev); 220 struct hid_device *hid = input_get_drvdata(dev);
164 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 221 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
165 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 222 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
223 __s32 *value = report->field[0]->value;
166 224
167 report->field[0]->value[0] = 0xfe; 225 value[0] = 0xfe;
168 report->field[0]->value[1] = 0x0d; 226 value[1] = 0x0d;
169 report->field[0]->value[2] = magnitude >> 13; 227 value[2] = magnitude >> 13;
170 report->field[0]->value[3] = magnitude >> 13; 228 value[3] = magnitude >> 13;
171 report->field[0]->value[4] = magnitude >> 8; 229 value[4] = magnitude >> 8;
172 report->field[0]->value[5] = 0x00; 230 value[5] = 0x00;
173 report->field[0]->value[6] = 0x00; 231 value[6] = 0x00;
174 232
175 usbhid_submit_report(hid, report, USB_DIR_OUT); 233 usbhid_submit_report(hid, report, USB_DIR_OUT);
176} 234}
@@ -181,16 +239,16 @@ static void hid_lg4ff_set_autocenter_ffex(struct input_dev *dev, u16 magnitude)
181 struct hid_device *hid = input_get_drvdata(dev); 239 struct hid_device *hid = input_get_drvdata(dev);
182 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 240 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
183 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 241 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
242 __s32 *value = report->field[0]->value;
184 magnitude = magnitude * 90 / 65535; 243 magnitude = magnitude * 90 / 65535;
185
186 244
187 report->field[0]->value[0] = 0xfe; 245 value[0] = 0xfe;
188 report->field[0]->value[1] = 0x03; 246 value[1] = 0x03;
189 report->field[0]->value[2] = magnitude >> 14; 247 value[2] = magnitude >> 14;
190 report->field[0]->value[3] = magnitude >> 14; 248 value[3] = magnitude >> 14;
191 report->field[0]->value[4] = magnitude; 249 value[4] = magnitude;
192 report->field[0]->value[5] = 0x00; 250 value[5] = 0x00;
193 report->field[0]->value[6] = 0x00; 251 value[6] = 0x00;
194 252
195 usbhid_submit_report(hid, report, USB_DIR_OUT); 253 usbhid_submit_report(hid, report, USB_DIR_OUT);
196} 254}
@@ -200,15 +258,17 @@ static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range)
200{ 258{
201 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 259 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
202 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 260 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
261 __s32 *value = report->field[0]->value;
262
203 dbg_hid("G25/G27/DFGT: setting range to %u\n", range); 263 dbg_hid("G25/G27/DFGT: setting range to %u\n", range);
204 264
205 report->field[0]->value[0] = 0xf8; 265 value[0] = 0xf8;
206 report->field[0]->value[1] = 0x81; 266 value[1] = 0x81;
207 report->field[0]->value[2] = range & 0x00ff; 267 value[2] = range & 0x00ff;
208 report->field[0]->value[3] = (range & 0xff00) >> 8; 268 value[3] = (range & 0xff00) >> 8;
209 report->field[0]->value[4] = 0x00; 269 value[4] = 0x00;
210 report->field[0]->value[5] = 0x00; 270 value[5] = 0x00;
211 report->field[0]->value[6] = 0x00; 271 value[6] = 0x00;
212 272
213 usbhid_submit_report(hid, report, USB_DIR_OUT); 273 usbhid_submit_report(hid, report, USB_DIR_OUT);
214} 274}
@@ -219,16 +279,18 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
219 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 279 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
220 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 280 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
221 int start_left, start_right, full_range; 281 int start_left, start_right, full_range;
282 __s32 *value = report->field[0]->value;
283
222 dbg_hid("Driving Force Pro: setting range to %u\n", range); 284 dbg_hid("Driving Force Pro: setting range to %u\n", range);
223 285
224 /* Prepare "coarse" limit command */ 286 /* Prepare "coarse" limit command */
225 report->field[0]->value[0] = 0xf8; 287 value[0] = 0xf8;
226 report->field[0]->value[1] = 0x00; /* Set later */ 288 value[1] = 0x00; /* Set later */
227 report->field[0]->value[2] = 0x00; 289 value[2] = 0x00;
228 report->field[0]->value[3] = 0x00; 290 value[3] = 0x00;
229 report->field[0]->value[4] = 0x00; 291 value[4] = 0x00;
230 report->field[0]->value[5] = 0x00; 292 value[5] = 0x00;
231 report->field[0]->value[6] = 0x00; 293 value[6] = 0x00;
232 294
233 if (range > 200) { 295 if (range > 200) {
234 report->field[0]->value[1] = 0x03; 296 report->field[0]->value[1] = 0x03;
@@ -240,13 +302,13 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
240 usbhid_submit_report(hid, report, USB_DIR_OUT); 302 usbhid_submit_report(hid, report, USB_DIR_OUT);
241 303
242 /* Prepare "fine" limit command */ 304 /* Prepare "fine" limit command */
243 report->field[0]->value[0] = 0x81; 305 value[0] = 0x81;
244 report->field[0]->value[1] = 0x0b; 306 value[1] = 0x0b;
245 report->field[0]->value[2] = 0x00; 307 value[2] = 0x00;
246 report->field[0]->value[3] = 0x00; 308 value[3] = 0x00;
247 report->field[0]->value[4] = 0x00; 309 value[4] = 0x00;
248 report->field[0]->value[5] = 0x00; 310 value[5] = 0x00;
249 report->field[0]->value[6] = 0x00; 311 value[6] = 0x00;
250 312
251 if (range == 200 || range == 900) { /* Do not apply any fine limit */ 313 if (range == 200 || range == 900) { /* Do not apply any fine limit */
252 usbhid_submit_report(hid, report, USB_DIR_OUT); 314 usbhid_submit_report(hid, report, USB_DIR_OUT);
@@ -257,11 +319,11 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
257 start_left = (((full_range - range + 1) * 2047) / full_range); 319 start_left = (((full_range - range + 1) * 2047) / full_range);
258 start_right = 0xfff - start_left; 320 start_right = 0xfff - start_left;
259 321
260 report->field[0]->value[2] = start_left >> 4; 322 value[2] = start_left >> 4;
261 report->field[0]->value[3] = start_right >> 4; 323 value[3] = start_right >> 4;
262 report->field[0]->value[4] = 0xff; 324 value[4] = 0xff;
263 report->field[0]->value[5] = (start_right & 0xe) << 4 | (start_left & 0xe); 325 value[5] = (start_right & 0xe) << 4 | (start_left & 0xe);
264 report->field[0]->value[6] = 0xff; 326 value[6] = 0xff;
265 327
266 usbhid_submit_report(hid, report, USB_DIR_OUT); 328 usbhid_submit_report(hid, report, USB_DIR_OUT);
267} 329}
@@ -344,14 +406,15 @@ static void lg4ff_set_leds(struct hid_device *hid, __u8 leds)
344{ 406{
345 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 407 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
346 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 408 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
347 409 __s32 *value = report->field[0]->value;
348 report->field[0]->value[0] = 0xf8; 410
349 report->field[0]->value[1] = 0x12; 411 value[0] = 0xf8;
350 report->field[0]->value[2] = leds; 412 value[1] = 0x12;
351 report->field[0]->value[3] = 0x00; 413 value[2] = leds;
352 report->field[0]->value[4] = 0x00; 414 value[3] = 0x00;
353 report->field[0]->value[5] = 0x00; 415 value[4] = 0x00;
354 report->field[0]->value[6] = 0x00; 416 value[5] = 0x00;
417 value[6] = 0x00;
355 usbhid_submit_report(hid, report, USB_DIR_OUT); 418 usbhid_submit_report(hid, report, USB_DIR_OUT);
356} 419}
357 420
@@ -360,7 +423,7 @@ static void lg4ff_led_set_brightness(struct led_classdev *led_cdev,
360{ 423{
361 struct device *dev = led_cdev->dev->parent; 424 struct device *dev = led_cdev->dev->parent;
362 struct hid_device *hid = container_of(dev, struct hid_device, dev); 425 struct hid_device *hid = container_of(dev, struct hid_device, dev);
363 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hid); 426 struct lg_drv_data *drv_data = hid_get_drvdata(hid);
364 struct lg4ff_device_entry *entry; 427 struct lg4ff_device_entry *entry;
365 int i, state = 0; 428 int i, state = 0;
366 429
@@ -395,7 +458,7 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
395{ 458{
396 struct device *dev = led_cdev->dev->parent; 459 struct device *dev = led_cdev->dev->parent;
397 struct hid_device *hid = container_of(dev, struct hid_device, dev); 460 struct hid_device *hid = container_of(dev, struct hid_device, dev);
398 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hid); 461 struct lg_drv_data *drv_data = hid_get_drvdata(hid);
399 struct lg4ff_device_entry *entry; 462 struct lg4ff_device_entry *entry;
400 int i, value = 0; 463 int i, value = 0;
401 464
@@ -501,7 +564,7 @@ int lg4ff_init(struct hid_device *hid)
501 /* Check if autocentering is available and 564 /* Check if autocentering is available and
502 * set the centering force to zero by default */ 565 * set the centering force to zero by default */
503 if (test_bit(FF_AUTOCENTER, dev->ffbit)) { 566 if (test_bit(FF_AUTOCENTER, dev->ffbit)) {
504 if(rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */ 567 if (rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */
505 dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex; 568 dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex;
506 else 569 else
507 dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default; 570 dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default;
@@ -524,6 +587,7 @@ int lg4ff_init(struct hid_device *hid)
524 } 587 }
525 drv_data->device_props = entry; 588 drv_data->device_props = entry;
526 589
590 entry->product_id = lg4ff_devices[i].product_id;
527 entry->min_range = lg4ff_devices[i].min_range; 591 entry->min_range = lg4ff_devices[i].min_range;
528 entry->max_range = lg4ff_devices[i].max_range; 592 entry->max_range = lg4ff_devices[i].max_range;
529 entry->set_range = lg4ff_devices[i].set_range; 593 entry->set_range = lg4ff_devices[i].set_range;
@@ -534,6 +598,18 @@ int lg4ff_init(struct hid_device *hid)
534 return error; 598 return error;
535 dbg_hid("sysfs interface created\n"); 599 dbg_hid("sysfs interface created\n");
536 600
601 /* Set default axes parameters */
602 switch (lg4ff_devices[i].product_id) {
603 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
604 dbg_hid("Setting axes parameters for Driving Force Pro\n");
605 input_set_abs_params(dev, ABS_X, DFP_X_MIN, DFP_X_MAX, 0, 0);
606 input_set_abs_params(dev, ABS_Y, DFP_PEDAL_MIN, DFP_PEDAL_MAX, 0, 0);
607 input_set_abs_params(dev, ABS_RZ, DFP_PEDAL_MIN, DFP_PEDAL_MAX, 0, 0);
608 break;
609 default:
610 break;
611 }
612
537 /* Set the maximum range to start with */ 613 /* Set the maximum range to start with */
538 entry->range = entry->max_range; 614 entry->range = entry->max_range;
539 if (entry->set_range != NULL) 615 if (entry->set_range != NULL)
@@ -594,6 +670,8 @@ out:
594 return 0; 670 return 0;
595} 671}
596 672
673
674
597int lg4ff_deinit(struct hid_device *hid) 675int lg4ff_deinit(struct hid_device *hid)
598{ 676{
599 struct lg4ff_device_entry *entry; 677 struct lg4ff_device_entry *entry;
diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
index 4d524b5f52f5..9500f2f3f8fe 100644
--- a/drivers/hid/hid-logitech-dj.c
+++ b/drivers/hid/hid-logitech-dj.c
@@ -193,6 +193,7 @@ static struct hid_ll_driver logi_dj_ll_driver;
193static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, 193static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf,
194 size_t count, 194 size_t count,
195 unsigned char report_type); 195 unsigned char report_type);
196static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev);
196 197
197static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, 198static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev,
198 struct dj_report *dj_report) 199 struct dj_report *dj_report)
@@ -233,6 +234,7 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
233 if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] & 234 if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] &
234 SPFUNCTION_DEVICE_LIST_EMPTY) { 235 SPFUNCTION_DEVICE_LIST_EMPTY) {
235 dbg_hid("%s: device list is empty\n", __func__); 236 dbg_hid("%s: device list is empty\n", __func__);
237 djrcv_dev->querying_devices = false;
236 return; 238 return;
237 } 239 }
238 240
@@ -243,6 +245,12 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
243 return; 245 return;
244 } 246 }
245 247
248 if (djrcv_dev->paired_dj_devices[dj_report->device_index]) {
249 /* The device is already known. No need to reallocate it. */
250 dbg_hid("%s: device is already known\n", __func__);
251 return;
252 }
253
246 dj_hiddev = hid_allocate_device(); 254 dj_hiddev = hid_allocate_device();
247 if (IS_ERR(dj_hiddev)) { 255 if (IS_ERR(dj_hiddev)) {
248 dev_err(&djrcv_hdev->dev, "%s: hid_allocate_device failed\n", 256 dev_err(&djrcv_hdev->dev, "%s: hid_allocate_device failed\n",
@@ -306,6 +314,7 @@ static void delayedwork_callback(struct work_struct *work)
306 struct dj_report dj_report; 314 struct dj_report dj_report;
307 unsigned long flags; 315 unsigned long flags;
308 int count; 316 int count;
317 int retval;
309 318
310 dbg_hid("%s\n", __func__); 319 dbg_hid("%s\n", __func__);
311 320
@@ -338,6 +347,25 @@ static void delayedwork_callback(struct work_struct *work)
338 logi_dj_recv_destroy_djhid_device(djrcv_dev, &dj_report); 347 logi_dj_recv_destroy_djhid_device(djrcv_dev, &dj_report);
339 break; 348 break;
340 default: 349 default:
350 /* A normal report (i. e. not belonging to a pair/unpair notification)
351 * arriving here, means that the report arrived but we did not have a
352 * paired dj_device associated to the report's device_index, this
353 * means that the original "device paired" notification corresponding
354 * to this dj_device never arrived to this driver. The reason is that
355 * hid-core discards all packets coming from a device while probe() is
356 * executing. */
357 if (!djrcv_dev->paired_dj_devices[dj_report.device_index]) {
358 /* ok, we don't know the device, just re-ask the
359 * receiver for the list of connected devices. */
360 retval = logi_dj_recv_query_paired_devices(djrcv_dev);
361 if (!retval) {
362 /* everything went fine, so just leave */
363 break;
364 }
365 dev_err(&djrcv_dev->hdev->dev,
366 "%s:logi_dj_recv_query_paired_devices "
367 "error:%d\n", __func__, retval);
368 }
341 dbg_hid("%s: unexpected report type\n", __func__); 369 dbg_hid("%s: unexpected report type\n", __func__);
342 } 370 }
343} 371}
@@ -368,6 +396,12 @@ static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,
368 if (!djdev) { 396 if (!djdev) {
369 dbg_hid("djrcv_dev->paired_dj_devices[dj_report->device_index]" 397 dbg_hid("djrcv_dev->paired_dj_devices[dj_report->device_index]"
370 " is NULL, index %d\n", dj_report->device_index); 398 " is NULL, index %d\n", dj_report->device_index);
399 kfifo_in(&djrcv_dev->notif_fifo, dj_report, sizeof(struct dj_report));
400
401 if (schedule_work(&djrcv_dev->work) == 0) {
402 dbg_hid("%s: did not schedule the work item, was already "
403 "queued\n", __func__);
404 }
371 return; 405 return;
372 } 406 }
373 407
@@ -398,6 +432,12 @@ static void logi_dj_recv_forward_report(struct dj_receiver_dev *djrcv_dev,
398 if (dj_device == NULL) { 432 if (dj_device == NULL) {
399 dbg_hid("djrcv_dev->paired_dj_devices[dj_report->device_index]" 433 dbg_hid("djrcv_dev->paired_dj_devices[dj_report->device_index]"
400 " is NULL, index %d\n", dj_report->device_index); 434 " is NULL, index %d\n", dj_report->device_index);
435 kfifo_in(&djrcv_dev->notif_fifo, dj_report, sizeof(struct dj_report));
436
437 if (schedule_work(&djrcv_dev->work) == 0) {
438 dbg_hid("%s: did not schedule the work item, was already "
439 "queued\n", __func__);
440 }
401 return; 441 return;
402 } 442 }
403 443
@@ -439,6 +479,10 @@ static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)
439 struct dj_report *dj_report; 479 struct dj_report *dj_report;
440 int retval; 480 int retval;
441 481
482 /* no need to protect djrcv_dev->querying_devices */
483 if (djrcv_dev->querying_devices)
484 return 0;
485
442 dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL); 486 dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
443 if (!dj_report) 487 if (!dj_report)
444 return -ENOMEM; 488 return -ENOMEM;
@@ -450,6 +494,7 @@ static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)
450 return retval; 494 return retval;
451} 495}
452 496
497
453static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev, 498static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
454 unsigned timeout) 499 unsigned timeout)
455{ 500{
diff --git a/drivers/hid/hid-logitech-dj.h b/drivers/hid/hid-logitech-dj.h
index fd28a5e0ca3b..4a4000340ce1 100644
--- a/drivers/hid/hid-logitech-dj.h
+++ b/drivers/hid/hid-logitech-dj.h
@@ -101,6 +101,7 @@ struct dj_receiver_dev {
101 struct work_struct work; 101 struct work_struct work;
102 struct kfifo notif_fifo; 102 struct kfifo notif_fifo;
103 spinlock_t lock; 103 spinlock_t lock;
104 bool querying_devices;
104}; 105};
105 106
106struct dj_device { 107struct dj_device {
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 73647266daad..25ddf3e3aec6 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -392,7 +392,7 @@ static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hd
392 392
393 __set_bit(EV_ABS, input->evbit); 393 __set_bit(EV_ABS, input->evbit);
394 394
395 error = input_mt_init_slots(input, 16); 395 error = input_mt_init_slots(input, 16, 0);
396 if (error) 396 if (error)
397 return error; 397 return error;
398 input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255 << 2, 398 input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255 << 2,
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index e5c699b6c6f3..3acdcfcc17df 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-monterey.c b/drivers/hid/hid-monterey.c
index dedf757781ae..cd3643e06fa6 100644
--- a/drivers/hid/hid-monterey.c
+++ b/drivers/hid/hid-monterey.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 59c8b5c1d2de..3eb02b94fc87 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -51,12 +51,12 @@ MODULE_LICENSE("GPL");
51#define MT_QUIRK_VALID_IS_INRANGE (1 << 5) 51#define MT_QUIRK_VALID_IS_INRANGE (1 << 5)
52#define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6) 52#define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6)
53#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8) 53#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
54#define MT_QUIRK_NO_AREA (1 << 9)
54 55
55struct mt_slot { 56struct mt_slot {
56 __s32 x, y, p, w, h; 57 __s32 x, y, p, w, h;
57 __s32 contactid; /* the device ContactID assigned to this slot */ 58 __s32 contactid; /* the device ContactID assigned to this slot */
58 bool touch_state; /* is the touch valid? */ 59 bool touch_state; /* is the touch valid? */
59 bool seen_in_this_frame;/* has this slot been updated */
60}; 60};
61 61
62struct mt_class { 62struct mt_class {
@@ -92,8 +92,9 @@ struct mt_device {
92 __u8 touches_by_report; /* how many touches are present in one report: 92 __u8 touches_by_report; /* how many touches are present in one report:
93 * 1 means we should use a serial protocol 93 * 1 means we should use a serial protocol
94 * > 1 means hybrid (multitouch) protocol */ 94 * > 1 means hybrid (multitouch) protocol */
95 bool serial_maybe; /* need to check for serial protocol */
95 bool curvalid; /* is the current contact valid? */ 96 bool curvalid; /* is the current contact valid? */
96 struct mt_slot *slots; 97 unsigned mt_flags; /* flags to pass to input-mt */
97}; 98};
98 99
99/* classes of device behavior */ 100/* classes of device behavior */
@@ -115,6 +116,9 @@ struct mt_device {
115#define MT_CLS_EGALAX_SERIAL 0x0104 116#define MT_CLS_EGALAX_SERIAL 0x0104
116#define MT_CLS_TOPSEED 0x0105 117#define MT_CLS_TOPSEED 0x0105
117#define MT_CLS_PANASONIC 0x0106 118#define MT_CLS_PANASONIC 0x0106
119#define MT_CLS_FLATFROG 0x0107
120#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
121#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
118 122
119#define MT_DEFAULT_MAXCONTACT 10 123#define MT_DEFAULT_MAXCONTACT 10
120 124
@@ -134,25 +138,6 @@ static int cypress_compute_slot(struct mt_device *td)
134 return -1; 138 return -1;
135} 139}
136 140
137static int find_slot_from_contactid(struct mt_device *td)
138{
139 int i;
140 for (i = 0; i < td->maxcontacts; ++i) {
141 if (td->slots[i].contactid == td->curdata.contactid &&
142 td->slots[i].touch_state)
143 return i;
144 }
145 for (i = 0; i < td->maxcontacts; ++i) {
146 if (!td->slots[i].seen_in_this_frame &&
147 !td->slots[i].touch_state)
148 return i;
149 }
150 /* should not occurs. If this happens that means
151 * that the device sent more touches that it says
152 * in the report descriptor. It is ignored then. */
153 return -1;
154}
155
156static struct mt_class mt_classes[] = { 141static struct mt_class mt_classes[] = {
157 { .name = MT_CLS_DEFAULT, 142 { .name = MT_CLS_DEFAULT,
158 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP }, 143 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
@@ -190,7 +175,9 @@ static struct mt_class mt_classes[] = {
190 MT_QUIRK_SLOT_IS_CONTACTID, 175 MT_QUIRK_SLOT_IS_CONTACTID,
191 .sn_move = 2048, 176 .sn_move = 2048,
192 .sn_width = 128, 177 .sn_width = 128,
193 .sn_height = 128 }, 178 .sn_height = 128,
179 .maxcontacts = 60,
180 },
194 { .name = MT_CLS_CYPRESS, 181 { .name = MT_CLS_CYPRESS,
195 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | 182 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
196 MT_QUIRK_CYPRESS, 183 MT_QUIRK_CYPRESS,
@@ -215,7 +202,24 @@ static struct mt_class mt_classes[] = {
215 { .name = MT_CLS_PANASONIC, 202 { .name = MT_CLS_PANASONIC,
216 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP, 203 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
217 .maxcontacts = 4 }, 204 .maxcontacts = 4 },
205 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
206 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
207 MT_QUIRK_VALID_IS_INRANGE |
208 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
209 .maxcontacts = 2
210 },
211 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
212 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
213 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
214 .maxcontacts = 10
215 },
218 216
217 { .name = MT_CLS_FLATFROG,
218 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
219 MT_QUIRK_NO_AREA,
220 .sn_move = 2048,
221 .maxcontacts = 40,
222 },
219 { } 223 { }
220}; 224};
221 225
@@ -319,24 +323,16 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
319 * We need to ignore fields that belong to other collections 323 * We need to ignore fields that belong to other collections
320 * such as Mouse that might have the same GenericDesktop usages. */ 324 * such as Mouse that might have the same GenericDesktop usages. */
321 if (field->application == HID_DG_TOUCHSCREEN) 325 if (field->application == HID_DG_TOUCHSCREEN)
322 set_bit(INPUT_PROP_DIRECT, hi->input->propbit); 326 td->mt_flags |= INPUT_MT_DIRECT;
323 else if (field->application != HID_DG_TOUCHPAD) 327 else if (field->application != HID_DG_TOUCHPAD)
324 return 0; 328 return 0;
325 329
326 /* In case of an indirect device (touchpad), we need to add 330 /*
327 * specific BTN_TOOL_* to be handled by the synaptics xorg 331 * Model touchscreens providing buttons as touchpads.
328 * driver.
329 * We also consider that touchscreens providing buttons are touchpads.
330 */ 332 */
331 if (field->application == HID_DG_TOUCHPAD || 333 if (field->application == HID_DG_TOUCHPAD ||
332 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON || 334 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
333 cls->is_indirect) { 335 td->mt_flags |= INPUT_MT_POINTER;
334 set_bit(INPUT_PROP_POINTER, hi->input->propbit);
335 set_bit(BTN_TOOL_FINGER, hi->input->keybit);
336 set_bit(BTN_TOOL_DOUBLETAP, hi->input->keybit);
337 set_bit(BTN_TOOL_TRIPLETAP, hi->input->keybit);
338 set_bit(BTN_TOOL_QUADTAP, hi->input->keybit);
339 }
340 336
341 /* eGalax devices provide a Digitizer.Stylus input which overrides 337 /* eGalax devices provide a Digitizer.Stylus input which overrides
342 * the correct Digitizers.Finger X/Y ranges. 338 * the correct Digitizers.Finger X/Y ranges.
@@ -353,8 +349,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
353 EV_ABS, ABS_MT_POSITION_X); 349 EV_ABS, ABS_MT_POSITION_X);
354 set_abs(hi->input, ABS_MT_POSITION_X, field, 350 set_abs(hi->input, ABS_MT_POSITION_X, field,
355 cls->sn_move); 351 cls->sn_move);
356 /* touchscreen emulation */
357 set_abs(hi->input, ABS_X, field, cls->sn_move);
358 mt_store_field(usage, td, hi); 352 mt_store_field(usage, td, hi);
359 td->last_field_index = field->index; 353 td->last_field_index = field->index;
360 return 1; 354 return 1;
@@ -363,8 +357,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
363 EV_ABS, ABS_MT_POSITION_Y); 357 EV_ABS, ABS_MT_POSITION_Y);
364 set_abs(hi->input, ABS_MT_POSITION_Y, field, 358 set_abs(hi->input, ABS_MT_POSITION_Y, field,
365 cls->sn_move); 359 cls->sn_move);
366 /* touchscreen emulation */
367 set_abs(hi->input, ABS_Y, field, cls->sn_move);
368 mt_store_field(usage, td, hi); 360 mt_store_field(usage, td, hi);
369 td->last_field_index = field->index; 361 td->last_field_index = field->index;
370 return 1; 362 return 1;
@@ -388,9 +380,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
388 td->last_field_index = field->index; 380 td->last_field_index = field->index;
389 return 1; 381 return 1;
390 case HID_DG_CONTACTID: 382 case HID_DG_CONTACTID:
391 if (!td->maxcontacts)
392 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
393 input_mt_init_slots(hi->input, td->maxcontacts);
394 mt_store_field(usage, td, hi); 383 mt_store_field(usage, td, hi);
395 td->last_field_index = field->index; 384 td->last_field_index = field->index;
396 td->touches_by_report++; 385 td->touches_by_report++;
@@ -398,18 +387,21 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
398 case HID_DG_WIDTH: 387 case HID_DG_WIDTH:
399 hid_map_usage(hi, usage, bit, max, 388 hid_map_usage(hi, usage, bit, max,
400 EV_ABS, ABS_MT_TOUCH_MAJOR); 389 EV_ABS, ABS_MT_TOUCH_MAJOR);
401 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, 390 if (!(cls->quirks & MT_QUIRK_NO_AREA))
402 cls->sn_width); 391 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
392 cls->sn_width);
403 mt_store_field(usage, td, hi); 393 mt_store_field(usage, td, hi);
404 td->last_field_index = field->index; 394 td->last_field_index = field->index;
405 return 1; 395 return 1;
406 case HID_DG_HEIGHT: 396 case HID_DG_HEIGHT:
407 hid_map_usage(hi, usage, bit, max, 397 hid_map_usage(hi, usage, bit, max,
408 EV_ABS, ABS_MT_TOUCH_MINOR); 398 EV_ABS, ABS_MT_TOUCH_MINOR);
409 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, 399 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
410 cls->sn_height); 400 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
411 input_set_abs_params(hi->input, 401 cls->sn_height);
402 input_set_abs_params(hi->input,
412 ABS_MT_ORIENTATION, 0, 1, 0, 0); 403 ABS_MT_ORIENTATION, 0, 1, 0, 0);
404 }
413 mt_store_field(usage, td, hi); 405 mt_store_field(usage, td, hi);
414 td->last_field_index = field->index; 406 td->last_field_index = field->index;
415 return 1; 407 return 1;
@@ -418,9 +410,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
418 EV_ABS, ABS_MT_PRESSURE); 410 EV_ABS, ABS_MT_PRESSURE);
419 set_abs(hi->input, ABS_MT_PRESSURE, field, 411 set_abs(hi->input, ABS_MT_PRESSURE, field,
420 cls->sn_pressure); 412 cls->sn_pressure);
421 /* touchscreen emulation */
422 set_abs(hi->input, ABS_PRESSURE, field,
423 cls->sn_pressure);
424 mt_store_field(usage, td, hi); 413 mt_store_field(usage, td, hi);
425 td->last_field_index = field->index; 414 td->last_field_index = field->index;
426 return 1; 415 return 1;
@@ -464,7 +453,7 @@ static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
464 return -1; 453 return -1;
465} 454}
466 455
467static int mt_compute_slot(struct mt_device *td) 456static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
468{ 457{
469 __s32 quirks = td->mtclass.quirks; 458 __s32 quirks = td->mtclass.quirks;
470 459
@@ -480,42 +469,23 @@ static int mt_compute_slot(struct mt_device *td)
480 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE) 469 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
481 return td->curdata.contactid - 1; 470 return td->curdata.contactid - 1;
482 471
483 return find_slot_from_contactid(td); 472 return input_mt_get_slot_by_key(input, td->curdata.contactid);
484} 473}
485 474
486/* 475/*
487 * this function is called when a whole contact has been processed, 476 * this function is called when a whole contact has been processed,
488 * so that it can assign it to a slot and store the data there 477 * so that it can assign it to a slot and store the data there
489 */ 478 */
490static void mt_complete_slot(struct mt_device *td) 479static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
491{ 480{
492 td->curdata.seen_in_this_frame = true;
493 if (td->curvalid) { 481 if (td->curvalid) {
494 int slotnum = mt_compute_slot(td); 482 int slotnum = mt_compute_slot(td, input);
495 483 struct mt_slot *s = &td->curdata;
496 if (slotnum >= 0 && slotnum < td->maxcontacts)
497 td->slots[slotnum] = td->curdata;
498 }
499 td->num_received++;
500}
501 484
485 if (slotnum < 0 || slotnum >= td->maxcontacts)
486 return;
502 487
503/* 488 input_mt_slot(input, slotnum);
504 * this function is called when a whole packet has been received and processed,
505 * so that it can decide what to send to the input layer.
506 */
507static void mt_emit_event(struct mt_device *td, struct input_dev *input)
508{
509 int i;
510
511 for (i = 0; i < td->maxcontacts; ++i) {
512 struct mt_slot *s = &(td->slots[i]);
513 if ((td->mtclass.quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
514 !s->seen_in_this_frame) {
515 s->touch_state = false;
516 }
517
518 input_mt_slot(input, i);
519 input_mt_report_slot_state(input, MT_TOOL_FINGER, 489 input_mt_report_slot_state(input, MT_TOOL_FINGER,
520 s->touch_state); 490 s->touch_state);
521 if (s->touch_state) { 491 if (s->touch_state) {
@@ -532,24 +502,29 @@ static void mt_emit_event(struct mt_device *td, struct input_dev *input)
532 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); 502 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
533 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); 503 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
534 } 504 }
535 s->seen_in_this_frame = false;
536
537 } 505 }
538 506
539 input_mt_report_pointer_emulation(input, true); 507 td->num_received++;
508}
509
510/*
511 * this function is called when a whole packet has been received and processed,
512 * so that it can decide what to send to the input layer.
513 */
514static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
515{
516 input_mt_sync_frame(input);
540 input_sync(input); 517 input_sync(input);
541 td->num_received = 0; 518 td->num_received = 0;
542} 519}
543 520
544
545
546static int mt_event(struct hid_device *hid, struct hid_field *field, 521static int mt_event(struct hid_device *hid, struct hid_field *field,
547 struct hid_usage *usage, __s32 value) 522 struct hid_usage *usage, __s32 value)
548{ 523{
549 struct mt_device *td = hid_get_drvdata(hid); 524 struct mt_device *td = hid_get_drvdata(hid);
550 __s32 quirks = td->mtclass.quirks; 525 __s32 quirks = td->mtclass.quirks;
551 526
552 if (hid->claimed & HID_CLAIMED_INPUT && td->slots) { 527 if (hid->claimed & HID_CLAIMED_INPUT) {
553 switch (usage->hid) { 528 switch (usage->hid) {
554 case HID_DG_INRANGE: 529 case HID_DG_INRANGE:
555 if (quirks & MT_QUIRK_ALWAYS_VALID) 530 if (quirks & MT_QUIRK_ALWAYS_VALID)
@@ -602,11 +577,11 @@ static int mt_event(struct hid_device *hid, struct hid_field *field,
602 } 577 }
603 578
604 if (usage->hid == td->last_slot_field) 579 if (usage->hid == td->last_slot_field)
605 mt_complete_slot(td); 580 mt_complete_slot(td, field->hidinput->input);
606 581
607 if (field->index == td->last_field_index 582 if (field->index == td->last_field_index
608 && td->num_received >= td->num_expected) 583 && td->num_received >= td->num_expected)
609 mt_emit_event(td, field->hidinput->input); 584 mt_sync_frame(td, field->hidinput->input);
610 585
611 } 586 }
612 587
@@ -685,18 +660,45 @@ static void mt_post_parse(struct mt_device *td)
685 } 660 }
686} 661}
687 662
663static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
664
665{
666 struct mt_device *td = hid_get_drvdata(hdev);
667 struct mt_class *cls = &td->mtclass;
668 struct input_dev *input = hi->input;
669
670 /* Only initialize slots for MT input devices */
671 if (!test_bit(ABS_MT_POSITION_X, input->absbit))
672 return;
673
674 if (!td->maxcontacts)
675 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
676
677 mt_post_parse(td);
678 if (td->serial_maybe)
679 mt_post_parse_default_settings(td);
680
681 if (cls->is_indirect)
682 td->mt_flags |= INPUT_MT_POINTER;
683
684 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
685 td->mt_flags |= INPUT_MT_DROP_UNUSED;
686
687 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
688
689 td->mt_flags = 0;
690}
691
688static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) 692static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
689{ 693{
690 int ret, i; 694 int ret, i;
691 struct mt_device *td; 695 struct mt_device *td;
692 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ 696 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
693 697
694 if (id) { 698 for (i = 0; mt_classes[i].name ; i++) {
695 for (i = 0; mt_classes[i].name ; i++) { 699 if (id->driver_data == mt_classes[i].name) {
696 if (id->driver_data == mt_classes[i].name) { 700 mtclass = &(mt_classes[i]);
697 mtclass = &(mt_classes[i]); 701 break;
698 break;
699 }
700 } 702 }
701 } 703 }
702 704
@@ -722,6 +724,9 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
722 goto fail; 724 goto fail;
723 } 725 }
724 726
727 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
728 td->serial_maybe = true;
729
725 ret = hid_parse(hdev); 730 ret = hid_parse(hdev);
726 if (ret != 0) 731 if (ret != 0)
727 goto fail; 732 goto fail;
@@ -730,20 +735,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
730 if (ret) 735 if (ret)
731 goto fail; 736 goto fail;
732 737
733 mt_post_parse(td);
734
735 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
736 mt_post_parse_default_settings(td);
737
738 td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot),
739 GFP_KERNEL);
740 if (!td->slots) {
741 dev_err(&hdev->dev, "cannot allocate multitouch slots\n");
742 hid_hw_stop(hdev);
743 ret = -ENOMEM;
744 goto fail;
745 }
746
747 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group); 738 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
748 739
749 mt_set_maxcontacts(hdev); 740 mt_set_maxcontacts(hdev);
@@ -767,6 +758,32 @@ static int mt_reset_resume(struct hid_device *hdev)
767 mt_set_input_mode(hdev); 758 mt_set_input_mode(hdev);
768 return 0; 759 return 0;
769} 760}
761
762static int mt_resume(struct hid_device *hdev)
763{
764 struct usb_interface *intf;
765 struct usb_host_interface *interface;
766 struct usb_device *dev;
767
768 if (hdev->bus != BUS_USB)
769 return 0;
770
771 intf = to_usb_interface(hdev->dev.parent);
772 interface = intf->cur_altsetting;
773 dev = hid_to_usb_dev(hdev);
774
775 /* Some Elan legacy devices require SET_IDLE to be set on resume.
776 * It should be safe to send it to other devices too.
777 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
778
779 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
780 HID_REQ_SET_IDLE,
781 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
782 0, interface->desc.bInterfaceNumber,
783 NULL, 0, USB_CTRL_SET_TIMEOUT);
784
785 return 0;
786}
770#endif 787#endif
771 788
772static void mt_remove(struct hid_device *hdev) 789static void mt_remove(struct hid_device *hdev)
@@ -774,7 +791,6 @@ static void mt_remove(struct hid_device *hdev)
774 struct mt_device *td = hid_get_drvdata(hdev); 791 struct mt_device *td = hid_get_drvdata(hdev);
775 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); 792 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
776 hid_hw_stop(hdev); 793 hid_hw_stop(hdev);
777 kfree(td->slots);
778 kfree(td); 794 kfree(td);
779 hid_set_drvdata(hdev, NULL); 795 hid_set_drvdata(hdev, NULL);
780} 796}
@@ -885,17 +901,37 @@ static const struct hid_device_id mt_devices[] = {
885 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) }, 901 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
886 { .driver_data = MT_CLS_EGALAX_SERIAL, 902 { .driver_data = MT_CLS_EGALAX_SERIAL,
887 MT_USB_DEVICE(USB_VENDOR_ID_DWAV, 903 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
904 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
905 { .driver_data = MT_CLS_EGALAX_SERIAL,
906 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
888 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) }, 907 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
908 { .driver_data = MT_CLS_EGALAX,
909 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
910 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
911 { .driver_data = MT_CLS_EGALAX,
912 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
913 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
914 { .driver_data = MT_CLS_EGALAX,
915 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
916 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
889 917
890 /* Elo TouchSystems IntelliTouch Plus panel */ 918 /* Elo TouchSystems IntelliTouch Plus panel */
891 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID, 919 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
892 MT_USB_DEVICE(USB_VENDOR_ID_ELO, 920 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
893 USB_DEVICE_ID_ELO_TS2515) }, 921 USB_DEVICE_ID_ELO_TS2515) },
894 922
923 /* Flatfrog Panels */
924 { .driver_data = MT_CLS_FLATFROG,
925 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
926 USB_DEVICE_ID_MULTITOUCH_3200) },
927
895 /* GeneralTouch panel */ 928 /* GeneralTouch panel */
896 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, 929 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
897 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 930 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
898 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) }, 931 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
932 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
933 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
934 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
899 935
900 /* Gametel game controller */ 936 /* Gametel game controller */
901 { .driver_data = MT_CLS_DEFAULT, 937 { .driver_data = MT_CLS_DEFAULT,
@@ -1087,11 +1123,13 @@ static struct hid_driver mt_driver = {
1087 .remove = mt_remove, 1123 .remove = mt_remove,
1088 .input_mapping = mt_input_mapping, 1124 .input_mapping = mt_input_mapping,
1089 .input_mapped = mt_input_mapped, 1125 .input_mapped = mt_input_mapped,
1126 .input_configured = mt_input_configured,
1090 .feature_mapping = mt_feature_mapping, 1127 .feature_mapping = mt_feature_mapping,
1091 .usage_table = mt_grabbed_usages, 1128 .usage_table = mt_grabbed_usages,
1092 .event = mt_event, 1129 .event = mt_event,
1093#ifdef CONFIG_PM 1130#ifdef CONFIG_PM
1094 .reset_resume = mt_reset_resume, 1131 .reset_resume = mt_reset_resume,
1132 .resume = mt_resume,
1095#endif 1133#endif
1096}; 1134};
1097 1135
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 9fae2ebdd758..86a969f63292 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -882,10 +882,10 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
882 nd->activate_slack = activate_slack; 882 nd->activate_slack = activate_slack;
883 nd->act_state = activate_slack; 883 nd->act_state = activate_slack;
884 nd->deactivate_slack = -deactivate_slack; 884 nd->deactivate_slack = -deactivate_slack;
885 nd->sensor_logical_width = 0; 885 nd->sensor_logical_width = 1;
886 nd->sensor_logical_height = 0; 886 nd->sensor_logical_height = 1;
887 nd->sensor_physical_width = 0; 887 nd->sensor_physical_width = 1;
888 nd->sensor_physical_height = 0; 888 nd->sensor_physical_height = 1;
889 889
890 hid_set_drvdata(hdev, nd); 890 hid_set_drvdata(hdev, nd);
891 891
diff --git a/drivers/hid/hid-petalynx.c b/drivers/hid/hid-petalynx.c
index f1ea3ff8a98d..4c521de4e7e6 100644
--- a/drivers/hid/hid-petalynx.c
+++ b/drivers/hid/hid-petalynx.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-picolcd.c b/drivers/hid/hid-picolcd.c
deleted file mode 100644
index 27c8ebdfad01..000000000000
--- a/drivers/hid/hid-picolcd.c
+++ /dev/null
@@ -1,2748 +0,0 @@
1/***************************************************************************
2 * Copyright (C) 2010 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include <linux/hid-debug.h>
22#include <linux/input.h>
23#include "hid-ids.h"
24#include "usbhid/usbhid.h"
25#include <linux/usb.h>
26
27#include <linux/fb.h>
28#include <linux/vmalloc.h>
29#include <linux/backlight.h>
30#include <linux/lcd.h>
31
32#include <linux/leds.h>
33
34#include <linux/seq_file.h>
35#include <linux/debugfs.h>
36
37#include <linux/completion.h>
38#include <linux/uaccess.h>
39#include <linux/module.h>
40
41#define PICOLCD_NAME "PicoLCD (graphic)"
42
43/* Report numbers */
44#define REPORT_ERROR_CODE 0x10 /* LCD: IN[16] */
45#define ERR_SUCCESS 0x00
46#define ERR_PARAMETER_MISSING 0x01
47#define ERR_DATA_MISSING 0x02
48#define ERR_BLOCK_READ_ONLY 0x03
49#define ERR_BLOCK_NOT_ERASABLE 0x04
50#define ERR_BLOCK_TOO_BIG 0x05
51#define ERR_SECTION_OVERFLOW 0x06
52#define ERR_INVALID_CMD_LEN 0x07
53#define ERR_INVALID_DATA_LEN 0x08
54#define REPORT_KEY_STATE 0x11 /* LCD: IN[2] */
55#define REPORT_IR_DATA 0x21 /* LCD: IN[63] */
56#define REPORT_EE_DATA 0x32 /* LCD: IN[63] */
57#define REPORT_MEMORY 0x41 /* LCD: IN[63] */
58#define REPORT_LED_STATE 0x81 /* LCD: OUT[1] */
59#define REPORT_BRIGHTNESS 0x91 /* LCD: OUT[1] */
60#define REPORT_CONTRAST 0x92 /* LCD: OUT[1] */
61#define REPORT_RESET 0x93 /* LCD: OUT[2] */
62#define REPORT_LCD_CMD 0x94 /* LCD: OUT[63] */
63#define REPORT_LCD_DATA 0x95 /* LCD: OUT[63] */
64#define REPORT_LCD_CMD_DATA 0x96 /* LCD: OUT[63] */
65#define REPORT_EE_READ 0xa3 /* LCD: OUT[63] */
66#define REPORT_EE_WRITE 0xa4 /* LCD: OUT[63] */
67#define REPORT_ERASE_MEMORY 0xb2 /* LCD: OUT[2] */
68#define REPORT_READ_MEMORY 0xb3 /* LCD: OUT[3] */
69#define REPORT_WRITE_MEMORY 0xb4 /* LCD: OUT[63] */
70#define REPORT_SPLASH_RESTART 0xc1 /* LCD: OUT[1] */
71#define REPORT_EXIT_KEYBOARD 0xef /* LCD: OUT[2] */
72#define REPORT_VERSION 0xf1 /* LCD: IN[2],OUT[1] Bootloader: IN[2],OUT[1] */
73#define REPORT_BL_ERASE_MEMORY 0xf2 /* Bootloader: IN[36],OUT[4] */
74#define REPORT_BL_READ_MEMORY 0xf3 /* Bootloader: IN[36],OUT[4] */
75#define REPORT_BL_WRITE_MEMORY 0xf4 /* Bootloader: IN[36],OUT[36] */
76#define REPORT_DEVID 0xf5 /* LCD: IN[5], OUT[1] Bootloader: IN[5],OUT[1] */
77#define REPORT_SPLASH_SIZE 0xf6 /* LCD: IN[4], OUT[1] */
78#define REPORT_HOOK_VERSION 0xf7 /* LCD: IN[2], OUT[1] */
79#define REPORT_EXIT_FLASHER 0xff /* Bootloader: OUT[2] */
80
81#ifdef CONFIG_HID_PICOLCD_FB
82/* Framebuffer
83 *
84 * The PicoLCD use a Topway LCD module of 256x64 pixel
85 * This display area is tiled over 4 controllers with 8 tiles
86 * each. Each tile has 8x64 pixel, each data byte representing
87 * a 1-bit wide vertical line of the tile.
88 *
89 * The display can be updated at a tile granularity.
90 *
91 * Chip 1 Chip 2 Chip 3 Chip 4
92 * +----------------+----------------+----------------+----------------+
93 * | Tile 1 | Tile 1 | Tile 1 | Tile 1 |
94 * +----------------+----------------+----------------+----------------+
95 * | Tile 2 | Tile 2 | Tile 2 | Tile 2 |
96 * +----------------+----------------+----------------+----------------+
97 * ...
98 * +----------------+----------------+----------------+----------------+
99 * | Tile 8 | Tile 8 | Tile 8 | Tile 8 |
100 * +----------------+----------------+----------------+----------------+
101 */
102#define PICOLCDFB_NAME "picolcdfb"
103#define PICOLCDFB_WIDTH (256)
104#define PICOLCDFB_HEIGHT (64)
105#define PICOLCDFB_SIZE (PICOLCDFB_WIDTH * PICOLCDFB_HEIGHT / 8)
106
107#define PICOLCDFB_UPDATE_RATE_LIMIT 10
108#define PICOLCDFB_UPDATE_RATE_DEFAULT 2
109
110/* Framebuffer visual structures */
111static const struct fb_fix_screeninfo picolcdfb_fix = {
112 .id = PICOLCDFB_NAME,
113 .type = FB_TYPE_PACKED_PIXELS,
114 .visual = FB_VISUAL_MONO01,
115 .xpanstep = 0,
116 .ypanstep = 0,
117 .ywrapstep = 0,
118 .line_length = PICOLCDFB_WIDTH / 8,
119 .accel = FB_ACCEL_NONE,
120};
121
122static const struct fb_var_screeninfo picolcdfb_var = {
123 .xres = PICOLCDFB_WIDTH,
124 .yres = PICOLCDFB_HEIGHT,
125 .xres_virtual = PICOLCDFB_WIDTH,
126 .yres_virtual = PICOLCDFB_HEIGHT,
127 .width = 103,
128 .height = 26,
129 .bits_per_pixel = 1,
130 .grayscale = 1,
131 .red = {
132 .offset = 0,
133 .length = 1,
134 .msb_right = 0,
135 },
136 .green = {
137 .offset = 0,
138 .length = 1,
139 .msb_right = 0,
140 },
141 .blue = {
142 .offset = 0,
143 .length = 1,
144 .msb_right = 0,
145 },
146 .transp = {
147 .offset = 0,
148 .length = 0,
149 .msb_right = 0,
150 },
151};
152#endif /* CONFIG_HID_PICOLCD_FB */
153
154/* Input device
155 *
156 * The PicoLCD has an IR receiver header, a built-in keypad with 5 keys
157 * and header for 4x4 key matrix. The built-in keys are part of the matrix.
158 */
159static const unsigned short def_keymap[] = {
160 KEY_RESERVED, /* none */
161 KEY_BACK, /* col 4 + row 1 */
162 KEY_HOMEPAGE, /* col 3 + row 1 */
163 KEY_RESERVED, /* col 2 + row 1 */
164 KEY_RESERVED, /* col 1 + row 1 */
165 KEY_SCROLLUP, /* col 4 + row 2 */
166 KEY_OK, /* col 3 + row 2 */
167 KEY_SCROLLDOWN, /* col 2 + row 2 */
168 KEY_RESERVED, /* col 1 + row 2 */
169 KEY_RESERVED, /* col 4 + row 3 */
170 KEY_RESERVED, /* col 3 + row 3 */
171 KEY_RESERVED, /* col 2 + row 3 */
172 KEY_RESERVED, /* col 1 + row 3 */
173 KEY_RESERVED, /* col 4 + row 4 */
174 KEY_RESERVED, /* col 3 + row 4 */
175 KEY_RESERVED, /* col 2 + row 4 */
176 KEY_RESERVED, /* col 1 + row 4 */
177};
178#define PICOLCD_KEYS ARRAY_SIZE(def_keymap)
179
180/* Description of in-progress IO operation, used for operations
181 * that trigger response from device */
182struct picolcd_pending {
183 struct hid_report *out_report;
184 struct hid_report *in_report;
185 struct completion ready;
186 int raw_size;
187 u8 raw_data[64];
188};
189
190/* Per device data structure */
191struct picolcd_data {
192 struct hid_device *hdev;
193#ifdef CONFIG_DEBUG_FS
194 struct dentry *debug_reset;
195 struct dentry *debug_eeprom;
196 struct dentry *debug_flash;
197 struct mutex mutex_flash;
198 int addr_sz;
199#endif
200 u8 version[2];
201 unsigned short opmode_delay;
202 /* input stuff */
203 u8 pressed_keys[2];
204 struct input_dev *input_keys;
205 struct input_dev *input_cir;
206 unsigned short keycode[PICOLCD_KEYS];
207
208#ifdef CONFIG_HID_PICOLCD_FB
209 /* Framebuffer stuff */
210 u8 fb_update_rate;
211 u8 fb_bpp;
212 u8 fb_force;
213 u8 *fb_vbitmap; /* local copy of what was sent to PicoLCD */
214 u8 *fb_bitmap; /* framebuffer */
215 struct fb_info *fb_info;
216 struct fb_deferred_io fb_defio;
217#endif /* CONFIG_HID_PICOLCD_FB */
218#ifdef CONFIG_HID_PICOLCD_LCD
219 struct lcd_device *lcd;
220 u8 lcd_contrast;
221#endif /* CONFIG_HID_PICOLCD_LCD */
222#ifdef CONFIG_HID_PICOLCD_BACKLIGHT
223 struct backlight_device *backlight;
224 u8 lcd_brightness;
225 u8 lcd_power;
226#endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
227#ifdef CONFIG_HID_PICOLCD_LEDS
228 /* LED stuff */
229 u8 led_state;
230 struct led_classdev *led[8];
231#endif /* CONFIG_HID_PICOLCD_LEDS */
232
233 /* Housekeeping stuff */
234 spinlock_t lock;
235 struct mutex mutex;
236 struct picolcd_pending *pending;
237 int status;
238#define PICOLCD_BOOTLOADER 1
239#define PICOLCD_FAILED 2
240#define PICOLCD_READY_FB 4
241};
242
243
244/* Find a given report */
245#define picolcd_in_report(id, dev) picolcd_report(id, dev, HID_INPUT_REPORT)
246#define picolcd_out_report(id, dev) picolcd_report(id, dev, HID_OUTPUT_REPORT)
247
248static struct hid_report *picolcd_report(int id, struct hid_device *hdev, int dir)
249{
250 struct list_head *feature_report_list = &hdev->report_enum[dir].report_list;
251 struct hid_report *report = NULL;
252
253 list_for_each_entry(report, feature_report_list, list) {
254 if (report->id == id)
255 return report;
256 }
257 hid_warn(hdev, "No report with id 0x%x found\n", id);
258 return NULL;
259}
260
261#ifdef CONFIG_DEBUG_FS
262static void picolcd_debug_out_report(struct picolcd_data *data,
263 struct hid_device *hdev, struct hid_report *report);
264#define usbhid_submit_report(a, b, c) \
265 do { \
266 picolcd_debug_out_report(hid_get_drvdata(a), a, b); \
267 usbhid_submit_report(a, b, c); \
268 } while (0)
269#endif
270
271/* Submit a report and wait for a reply from device - if device fades away
272 * or does not respond in time, return NULL */
273static struct picolcd_pending *picolcd_send_and_wait(struct hid_device *hdev,
274 int report_id, const u8 *raw_data, int size)
275{
276 struct picolcd_data *data = hid_get_drvdata(hdev);
277 struct picolcd_pending *work;
278 struct hid_report *report = picolcd_out_report(report_id, hdev);
279 unsigned long flags;
280 int i, j, k;
281
282 if (!report || !data)
283 return NULL;
284 if (data->status & PICOLCD_FAILED)
285 return NULL;
286 work = kzalloc(sizeof(*work), GFP_KERNEL);
287 if (!work)
288 return NULL;
289
290 init_completion(&work->ready);
291 work->out_report = report;
292 work->in_report = NULL;
293 work->raw_size = 0;
294
295 mutex_lock(&data->mutex);
296 spin_lock_irqsave(&data->lock, flags);
297 for (i = k = 0; i < report->maxfield; i++)
298 for (j = 0; j < report->field[i]->report_count; j++) {
299 hid_set_field(report->field[i], j, k < size ? raw_data[k] : 0);
300 k++;
301 }
302 data->pending = work;
303 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
304 spin_unlock_irqrestore(&data->lock, flags);
305 wait_for_completion_interruptible_timeout(&work->ready, HZ*2);
306 spin_lock_irqsave(&data->lock, flags);
307 data->pending = NULL;
308 spin_unlock_irqrestore(&data->lock, flags);
309 mutex_unlock(&data->mutex);
310 return work;
311}
312
313#ifdef CONFIG_HID_PICOLCD_FB
314/* Send a given tile to PicoLCD */
315static int picolcd_fb_send_tile(struct hid_device *hdev, int chip, int tile)
316{
317 struct picolcd_data *data = hid_get_drvdata(hdev);
318 struct hid_report *report1 = picolcd_out_report(REPORT_LCD_CMD_DATA, hdev);
319 struct hid_report *report2 = picolcd_out_report(REPORT_LCD_DATA, hdev);
320 unsigned long flags;
321 u8 *tdata;
322 int i;
323
324 if (!report1 || report1->maxfield != 1 || !report2 || report2->maxfield != 1)
325 return -ENODEV;
326
327 spin_lock_irqsave(&data->lock, flags);
328 hid_set_field(report1->field[0], 0, chip << 2);
329 hid_set_field(report1->field[0], 1, 0x02);
330 hid_set_field(report1->field[0], 2, 0x00);
331 hid_set_field(report1->field[0], 3, 0x00);
332 hid_set_field(report1->field[0], 4, 0xb8 | tile);
333 hid_set_field(report1->field[0], 5, 0x00);
334 hid_set_field(report1->field[0], 6, 0x00);
335 hid_set_field(report1->field[0], 7, 0x40);
336 hid_set_field(report1->field[0], 8, 0x00);
337 hid_set_field(report1->field[0], 9, 0x00);
338 hid_set_field(report1->field[0], 10, 32);
339
340 hid_set_field(report2->field[0], 0, (chip << 2) | 0x01);
341 hid_set_field(report2->field[0], 1, 0x00);
342 hid_set_field(report2->field[0], 2, 0x00);
343 hid_set_field(report2->field[0], 3, 32);
344
345 tdata = data->fb_vbitmap + (tile * 4 + chip) * 64;
346 for (i = 0; i < 64; i++)
347 if (i < 32)
348 hid_set_field(report1->field[0], 11 + i, tdata[i]);
349 else
350 hid_set_field(report2->field[0], 4 + i - 32, tdata[i]);
351
352 usbhid_submit_report(data->hdev, report1, USB_DIR_OUT);
353 usbhid_submit_report(data->hdev, report2, USB_DIR_OUT);
354 spin_unlock_irqrestore(&data->lock, flags);
355 return 0;
356}
357
358/* Translate a single tile*/
359static int picolcd_fb_update_tile(u8 *vbitmap, const u8 *bitmap, int bpp,
360 int chip, int tile)
361{
362 int i, b, changed = 0;
363 u8 tdata[64];
364 u8 *vdata = vbitmap + (tile * 4 + chip) * 64;
365
366 if (bpp == 1) {
367 for (b = 7; b >= 0; b--) {
368 const u8 *bdata = bitmap + tile * 256 + chip * 8 + b * 32;
369 for (i = 0; i < 64; i++) {
370 tdata[i] <<= 1;
371 tdata[i] |= (bdata[i/8] >> (i % 8)) & 0x01;
372 }
373 }
374 } else if (bpp == 8) {
375 for (b = 7; b >= 0; b--) {
376 const u8 *bdata = bitmap + (tile * 256 + chip * 8 + b * 32) * 8;
377 for (i = 0; i < 64; i++) {
378 tdata[i] <<= 1;
379 tdata[i] |= (bdata[i] & 0x80) ? 0x01 : 0x00;
380 }
381 }
382 } else {
383 /* Oops, we should never get here! */
384 WARN_ON(1);
385 return 0;
386 }
387
388 for (i = 0; i < 64; i++)
389 if (tdata[i] != vdata[i]) {
390 changed = 1;
391 vdata[i] = tdata[i];
392 }
393 return changed;
394}
395
396/* Reconfigure LCD display */
397static int picolcd_fb_reset(struct picolcd_data *data, int clear)
398{
399 struct hid_report *report = picolcd_out_report(REPORT_LCD_CMD, data->hdev);
400 int i, j;
401 unsigned long flags;
402 static const u8 mapcmd[8] = { 0x00, 0x02, 0x00, 0x64, 0x3f, 0x00, 0x64, 0xc0 };
403
404 if (!report || report->maxfield != 1)
405 return -ENODEV;
406
407 spin_lock_irqsave(&data->lock, flags);
408 for (i = 0; i < 4; i++) {
409 for (j = 0; j < report->field[0]->maxusage; j++)
410 if (j == 0)
411 hid_set_field(report->field[0], j, i << 2);
412 else if (j < sizeof(mapcmd))
413 hid_set_field(report->field[0], j, mapcmd[j]);
414 else
415 hid_set_field(report->field[0], j, 0);
416 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
417 }
418
419 data->status |= PICOLCD_READY_FB;
420 spin_unlock_irqrestore(&data->lock, flags);
421
422 if (data->fb_bitmap) {
423 if (clear) {
424 memset(data->fb_vbitmap, 0, PICOLCDFB_SIZE);
425 memset(data->fb_bitmap, 0, PICOLCDFB_SIZE*data->fb_bpp);
426 }
427 data->fb_force = 1;
428 }
429
430 /* schedule first output of framebuffer */
431 if (data->fb_info)
432 schedule_delayed_work(&data->fb_info->deferred_work, 0);
433
434 return 0;
435}
436
437/* Update fb_vbitmap from the screen_base and send changed tiles to device */
438static void picolcd_fb_update(struct picolcd_data *data)
439{
440 int chip, tile, n;
441 unsigned long flags;
442
443 if (!data)
444 return;
445
446 spin_lock_irqsave(&data->lock, flags);
447 if (!(data->status & PICOLCD_READY_FB)) {
448 spin_unlock_irqrestore(&data->lock, flags);
449 picolcd_fb_reset(data, 0);
450 } else {
451 spin_unlock_irqrestore(&data->lock, flags);
452 }
453
454 /*
455 * Translate the framebuffer into the format needed by the PicoLCD.
456 * See display layout above.
457 * Do this one tile after the other and push those tiles that changed.
458 *
459 * Wait for our IO to complete as otherwise we might flood the queue!
460 */
461 n = 0;
462 for (chip = 0; chip < 4; chip++)
463 for (tile = 0; tile < 8; tile++)
464 if (picolcd_fb_update_tile(data->fb_vbitmap,
465 data->fb_bitmap, data->fb_bpp, chip, tile) ||
466 data->fb_force) {
467 n += 2;
468 if (!data->fb_info->par)
469 return; /* device lost! */
470 if (n >= HID_OUTPUT_FIFO_SIZE / 2) {
471 usbhid_wait_io(data->hdev);
472 n = 0;
473 }
474 picolcd_fb_send_tile(data->hdev, chip, tile);
475 }
476 data->fb_force = false;
477 if (n)
478 usbhid_wait_io(data->hdev);
479}
480
481/* Stub to call the system default and update the image on the picoLCD */
482static void picolcd_fb_fillrect(struct fb_info *info,
483 const struct fb_fillrect *rect)
484{
485 if (!info->par)
486 return;
487 sys_fillrect(info, rect);
488
489 schedule_delayed_work(&info->deferred_work, 0);
490}
491
492/* Stub to call the system default and update the image on the picoLCD */
493static void picolcd_fb_copyarea(struct fb_info *info,
494 const struct fb_copyarea *area)
495{
496 if (!info->par)
497 return;
498 sys_copyarea(info, area);
499
500 schedule_delayed_work(&info->deferred_work, 0);
501}
502
503/* Stub to call the system default and update the image on the picoLCD */
504static void picolcd_fb_imageblit(struct fb_info *info, const struct fb_image *image)
505{
506 if (!info->par)
507 return;
508 sys_imageblit(info, image);
509
510 schedule_delayed_work(&info->deferred_work, 0);
511}
512
513/*
514 * this is the slow path from userspace. they can seek and write to
515 * the fb. it's inefficient to do anything less than a full screen draw
516 */
517static ssize_t picolcd_fb_write(struct fb_info *info, const char __user *buf,
518 size_t count, loff_t *ppos)
519{
520 ssize_t ret;
521 if (!info->par)
522 return -ENODEV;
523 ret = fb_sys_write(info, buf, count, ppos);
524 if (ret >= 0)
525 schedule_delayed_work(&info->deferred_work, 0);
526 return ret;
527}
528
529static int picolcd_fb_blank(int blank, struct fb_info *info)
530{
531 if (!info->par)
532 return -ENODEV;
533 /* We let fb notification do this for us via lcd/backlight device */
534 return 0;
535}
536
537static void picolcd_fb_destroy(struct fb_info *info)
538{
539 struct picolcd_data *data = info->par;
540 u32 *ref_cnt = info->pseudo_palette;
541 int may_release;
542
543 info->par = NULL;
544 if (data)
545 data->fb_info = NULL;
546 fb_deferred_io_cleanup(info);
547
548 ref_cnt--;
549 mutex_lock(&info->lock);
550 (*ref_cnt)--;
551 may_release = !*ref_cnt;
552 mutex_unlock(&info->lock);
553 if (may_release) {
554 vfree((u8 *)info->fix.smem_start);
555 framebuffer_release(info);
556 }
557}
558
559static int picolcd_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
560{
561 __u32 bpp = var->bits_per_pixel;
562 __u32 activate = var->activate;
563
564 /* only allow 1/8 bit depth (8-bit is grayscale) */
565 *var = picolcdfb_var;
566 var->activate = activate;
567 if (bpp >= 8) {
568 var->bits_per_pixel = 8;
569 var->red.length = 8;
570 var->green.length = 8;
571 var->blue.length = 8;
572 } else {
573 var->bits_per_pixel = 1;
574 var->red.length = 1;
575 var->green.length = 1;
576 var->blue.length = 1;
577 }
578 return 0;
579}
580
581static int picolcd_set_par(struct fb_info *info)
582{
583 struct picolcd_data *data = info->par;
584 u8 *tmp_fb, *o_fb;
585 if (!data)
586 return -ENODEV;
587 if (info->var.bits_per_pixel == data->fb_bpp)
588 return 0;
589 /* switch between 1/8 bit depths */
590 if (info->var.bits_per_pixel != 1 && info->var.bits_per_pixel != 8)
591 return -EINVAL;
592
593 o_fb = data->fb_bitmap;
594 tmp_fb = kmalloc(PICOLCDFB_SIZE*info->var.bits_per_pixel, GFP_KERNEL);
595 if (!tmp_fb)
596 return -ENOMEM;
597
598 /* translate FB content to new bits-per-pixel */
599 if (info->var.bits_per_pixel == 1) {
600 int i, b;
601 for (i = 0; i < PICOLCDFB_SIZE; i++) {
602 u8 p = 0;
603 for (b = 0; b < 8; b++) {
604 p <<= 1;
605 p |= o_fb[i*8+b] ? 0x01 : 0x00;
606 }
607 tmp_fb[i] = p;
608 }
609 memcpy(o_fb, tmp_fb, PICOLCDFB_SIZE);
610 info->fix.visual = FB_VISUAL_MONO01;
611 info->fix.line_length = PICOLCDFB_WIDTH / 8;
612 } else {
613 int i;
614 memcpy(tmp_fb, o_fb, PICOLCDFB_SIZE);
615 for (i = 0; i < PICOLCDFB_SIZE * 8; i++)
616 o_fb[i] = tmp_fb[i/8] & (0x01 << (7 - i % 8)) ? 0xff : 0x00;
617 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
618 info->fix.line_length = PICOLCDFB_WIDTH;
619 }
620
621 kfree(tmp_fb);
622 data->fb_bpp = info->var.bits_per_pixel;
623 return 0;
624}
625
626/* Do refcounting on our FB and cleanup per worker if FB is
627 * closed after unplug of our device
628 * (fb_release holds info->lock and still touches info after
629 * we return so we can't release it immediately.
630 */
631struct picolcd_fb_cleanup_item {
632 struct fb_info *info;
633 struct picolcd_fb_cleanup_item *next;
634};
635static struct picolcd_fb_cleanup_item *fb_pending;
636static DEFINE_SPINLOCK(fb_pending_lock);
637
638static void picolcd_fb_do_cleanup(struct work_struct *data)
639{
640 struct picolcd_fb_cleanup_item *item;
641 unsigned long flags;
642
643 do {
644 spin_lock_irqsave(&fb_pending_lock, flags);
645 item = fb_pending;
646 fb_pending = item ? item->next : NULL;
647 spin_unlock_irqrestore(&fb_pending_lock, flags);
648
649 if (item) {
650 u8 *fb = (u8 *)item->info->fix.smem_start;
651 /* make sure we do not race against fb core when
652 * releasing */
653 mutex_lock(&item->info->lock);
654 mutex_unlock(&item->info->lock);
655 framebuffer_release(item->info);
656 vfree(fb);
657 }
658 } while (item);
659}
660
661static DECLARE_WORK(picolcd_fb_cleanup, picolcd_fb_do_cleanup);
662
663static int picolcd_fb_open(struct fb_info *info, int u)
664{
665 u32 *ref_cnt = info->pseudo_palette;
666 ref_cnt--;
667
668 (*ref_cnt)++;
669 return 0;
670}
671
672static int picolcd_fb_release(struct fb_info *info, int u)
673{
674 u32 *ref_cnt = info->pseudo_palette;
675 ref_cnt--;
676
677 (*ref_cnt)++;
678 if (!*ref_cnt) {
679 unsigned long flags;
680 struct picolcd_fb_cleanup_item *item = (struct picolcd_fb_cleanup_item *)ref_cnt;
681 item--;
682 spin_lock_irqsave(&fb_pending_lock, flags);
683 item->next = fb_pending;
684 fb_pending = item;
685 spin_unlock_irqrestore(&fb_pending_lock, flags);
686 schedule_work(&picolcd_fb_cleanup);
687 }
688 return 0;
689}
690
691/* Note this can't be const because of struct fb_info definition */
692static struct fb_ops picolcdfb_ops = {
693 .owner = THIS_MODULE,
694 .fb_destroy = picolcd_fb_destroy,
695 .fb_open = picolcd_fb_open,
696 .fb_release = picolcd_fb_release,
697 .fb_read = fb_sys_read,
698 .fb_write = picolcd_fb_write,
699 .fb_blank = picolcd_fb_blank,
700 .fb_fillrect = picolcd_fb_fillrect,
701 .fb_copyarea = picolcd_fb_copyarea,
702 .fb_imageblit = picolcd_fb_imageblit,
703 .fb_check_var = picolcd_fb_check_var,
704 .fb_set_par = picolcd_set_par,
705};
706
707
708/* Callback from deferred IO workqueue */
709static void picolcd_fb_deferred_io(struct fb_info *info, struct list_head *pagelist)
710{
711 picolcd_fb_update(info->par);
712}
713
714static const struct fb_deferred_io picolcd_fb_defio = {
715 .delay = HZ / PICOLCDFB_UPDATE_RATE_DEFAULT,
716 .deferred_io = picolcd_fb_deferred_io,
717};
718
719
720/*
721 * The "fb_update_rate" sysfs attribute
722 */
723static ssize_t picolcd_fb_update_rate_show(struct device *dev,
724 struct device_attribute *attr, char *buf)
725{
726 struct picolcd_data *data = dev_get_drvdata(dev);
727 unsigned i, fb_update_rate = data->fb_update_rate;
728 size_t ret = 0;
729
730 for (i = 1; i <= PICOLCDFB_UPDATE_RATE_LIMIT; i++)
731 if (ret >= PAGE_SIZE)
732 break;
733 else if (i == fb_update_rate)
734 ret += snprintf(buf+ret, PAGE_SIZE-ret, "[%u] ", i);
735 else
736 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%u ", i);
737 if (ret > 0)
738 buf[min(ret, (size_t)PAGE_SIZE)-1] = '\n';
739 return ret;
740}
741
742static ssize_t picolcd_fb_update_rate_store(struct device *dev,
743 struct device_attribute *attr, const char *buf, size_t count)
744{
745 struct picolcd_data *data = dev_get_drvdata(dev);
746 int i;
747 unsigned u;
748
749 if (count < 1 || count > 10)
750 return -EINVAL;
751
752 i = sscanf(buf, "%u", &u);
753 if (i != 1)
754 return -EINVAL;
755
756 if (u > PICOLCDFB_UPDATE_RATE_LIMIT)
757 return -ERANGE;
758 else if (u == 0)
759 u = PICOLCDFB_UPDATE_RATE_DEFAULT;
760
761 data->fb_update_rate = u;
762 data->fb_defio.delay = HZ / data->fb_update_rate;
763 return count;
764}
765
766static DEVICE_ATTR(fb_update_rate, 0666, picolcd_fb_update_rate_show,
767 picolcd_fb_update_rate_store);
768
769/* initialize Framebuffer device */
770static int picolcd_init_framebuffer(struct picolcd_data *data)
771{
772 struct device *dev = &data->hdev->dev;
773 struct fb_info *info = NULL;
774 int i, error = -ENOMEM;
775 u8 *fb_vbitmap = NULL;
776 u8 *fb_bitmap = NULL;
777 u32 *palette;
778
779 fb_bitmap = vmalloc(PICOLCDFB_SIZE*8);
780 if (fb_bitmap == NULL) {
781 dev_err(dev, "can't get a free page for framebuffer\n");
782 goto err_nomem;
783 }
784
785 fb_vbitmap = kmalloc(PICOLCDFB_SIZE, GFP_KERNEL);
786 if (fb_vbitmap == NULL) {
787 dev_err(dev, "can't alloc vbitmap image buffer\n");
788 goto err_nomem;
789 }
790
791 data->fb_update_rate = PICOLCDFB_UPDATE_RATE_DEFAULT;
792 data->fb_defio = picolcd_fb_defio;
793 /* The extra memory is:
794 * - struct picolcd_fb_cleanup_item
795 * - u32 for ref_count
796 * - 256*u32 for pseudo_palette
797 */
798 info = framebuffer_alloc(257 * sizeof(u32) + sizeof(struct picolcd_fb_cleanup_item), dev);
799 if (info == NULL) {
800 dev_err(dev, "failed to allocate a framebuffer\n");
801 goto err_nomem;
802 }
803
804 palette = info->par + sizeof(struct picolcd_fb_cleanup_item);
805 *palette = 1;
806 palette++;
807 for (i = 0; i < 256; i++)
808 palette[i] = i > 0 && i < 16 ? 0xff : 0;
809 info->pseudo_palette = palette;
810 info->fbdefio = &data->fb_defio;
811 info->screen_base = (char __force __iomem *)fb_bitmap;
812 info->fbops = &picolcdfb_ops;
813 info->var = picolcdfb_var;
814 info->fix = picolcdfb_fix;
815 info->fix.smem_len = PICOLCDFB_SIZE*8;
816 info->fix.smem_start = (unsigned long)fb_bitmap;
817 info->par = data;
818 info->flags = FBINFO_FLAG_DEFAULT;
819
820 data->fb_vbitmap = fb_vbitmap;
821 data->fb_bitmap = fb_bitmap;
822 data->fb_bpp = picolcdfb_var.bits_per_pixel;
823 error = picolcd_fb_reset(data, 1);
824 if (error) {
825 dev_err(dev, "failed to configure display\n");
826 goto err_cleanup;
827 }
828 error = device_create_file(dev, &dev_attr_fb_update_rate);
829 if (error) {
830 dev_err(dev, "failed to create sysfs attributes\n");
831 goto err_cleanup;
832 }
833 fb_deferred_io_init(info);
834 data->fb_info = info;
835 error = register_framebuffer(info);
836 if (error) {
837 dev_err(dev, "failed to register framebuffer\n");
838 goto err_sysfs;
839 }
840 /* schedule first output of framebuffer */
841 data->fb_force = 1;
842 schedule_delayed_work(&info->deferred_work, 0);
843 return 0;
844
845err_sysfs:
846 fb_deferred_io_cleanup(info);
847 device_remove_file(dev, &dev_attr_fb_update_rate);
848err_cleanup:
849 data->fb_vbitmap = NULL;
850 data->fb_bitmap = NULL;
851 data->fb_bpp = 0;
852 data->fb_info = NULL;
853
854err_nomem:
855 framebuffer_release(info);
856 vfree(fb_bitmap);
857 kfree(fb_vbitmap);
858 return error;
859}
860
861static void picolcd_exit_framebuffer(struct picolcd_data *data)
862{
863 struct fb_info *info = data->fb_info;
864 u8 *fb_vbitmap = data->fb_vbitmap;
865
866 if (!info)
867 return;
868
869 info->par = NULL;
870 device_remove_file(&data->hdev->dev, &dev_attr_fb_update_rate);
871 unregister_framebuffer(info);
872 data->fb_vbitmap = NULL;
873 data->fb_bitmap = NULL;
874 data->fb_bpp = 0;
875 data->fb_info = NULL;
876 kfree(fb_vbitmap);
877}
878
879#define picolcd_fbinfo(d) ((d)->fb_info)
880#else
881static inline int picolcd_fb_reset(struct picolcd_data *data, int clear)
882{
883 return 0;
884}
885static inline int picolcd_init_framebuffer(struct picolcd_data *data)
886{
887 return 0;
888}
889static inline void picolcd_exit_framebuffer(struct picolcd_data *data)
890{
891}
892#define picolcd_fbinfo(d) NULL
893#endif /* CONFIG_HID_PICOLCD_FB */
894
895#ifdef CONFIG_HID_PICOLCD_BACKLIGHT
896/*
897 * backlight class device
898 */
899static int picolcd_get_brightness(struct backlight_device *bdev)
900{
901 struct picolcd_data *data = bl_get_data(bdev);
902 return data->lcd_brightness;
903}
904
905static int picolcd_set_brightness(struct backlight_device *bdev)
906{
907 struct picolcd_data *data = bl_get_data(bdev);
908 struct hid_report *report = picolcd_out_report(REPORT_BRIGHTNESS, data->hdev);
909 unsigned long flags;
910
911 if (!report || report->maxfield != 1 || report->field[0]->report_count != 1)
912 return -ENODEV;
913
914 data->lcd_brightness = bdev->props.brightness & 0x0ff;
915 data->lcd_power = bdev->props.power;
916 spin_lock_irqsave(&data->lock, flags);
917 hid_set_field(report->field[0], 0, data->lcd_power == FB_BLANK_UNBLANK ? data->lcd_brightness : 0);
918 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
919 spin_unlock_irqrestore(&data->lock, flags);
920 return 0;
921}
922
923static int picolcd_check_bl_fb(struct backlight_device *bdev, struct fb_info *fb)
924{
925 return fb && fb == picolcd_fbinfo((struct picolcd_data *)bl_get_data(bdev));
926}
927
928static const struct backlight_ops picolcd_blops = {
929 .update_status = picolcd_set_brightness,
930 .get_brightness = picolcd_get_brightness,
931 .check_fb = picolcd_check_bl_fb,
932};
933
934static int picolcd_init_backlight(struct picolcd_data *data, struct hid_report *report)
935{
936 struct device *dev = &data->hdev->dev;
937 struct backlight_device *bdev;
938 struct backlight_properties props;
939 if (!report)
940 return -ENODEV;
941 if (report->maxfield != 1 || report->field[0]->report_count != 1 ||
942 report->field[0]->report_size != 8) {
943 dev_err(dev, "unsupported BRIGHTNESS report");
944 return -EINVAL;
945 }
946
947 memset(&props, 0, sizeof(props));
948 props.type = BACKLIGHT_RAW;
949 props.max_brightness = 0xff;
950 bdev = backlight_device_register(dev_name(dev), dev, data,
951 &picolcd_blops, &props);
952 if (IS_ERR(bdev)) {
953 dev_err(dev, "failed to register backlight\n");
954 return PTR_ERR(bdev);
955 }
956 bdev->props.brightness = 0xff;
957 data->lcd_brightness = 0xff;
958 data->backlight = bdev;
959 picolcd_set_brightness(bdev);
960 return 0;
961}
962
963static void picolcd_exit_backlight(struct picolcd_data *data)
964{
965 struct backlight_device *bdev = data->backlight;
966
967 data->backlight = NULL;
968 if (bdev)
969 backlight_device_unregister(bdev);
970}
971
972static inline int picolcd_resume_backlight(struct picolcd_data *data)
973{
974 if (!data->backlight)
975 return 0;
976 return picolcd_set_brightness(data->backlight);
977}
978
979#ifdef CONFIG_PM
980static void picolcd_suspend_backlight(struct picolcd_data *data)
981{
982 int bl_power = data->lcd_power;
983 if (!data->backlight)
984 return;
985
986 data->backlight->props.power = FB_BLANK_POWERDOWN;
987 picolcd_set_brightness(data->backlight);
988 data->lcd_power = data->backlight->props.power = bl_power;
989}
990#endif /* CONFIG_PM */
991#else
992static inline int picolcd_init_backlight(struct picolcd_data *data,
993 struct hid_report *report)
994{
995 return 0;
996}
997static inline void picolcd_exit_backlight(struct picolcd_data *data)
998{
999}
1000static inline int picolcd_resume_backlight(struct picolcd_data *data)
1001{
1002 return 0;
1003}
1004static inline void picolcd_suspend_backlight(struct picolcd_data *data)
1005{
1006}
1007#endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
1008
1009#ifdef CONFIG_HID_PICOLCD_LCD
1010/*
1011 * lcd class device
1012 */
1013static int picolcd_get_contrast(struct lcd_device *ldev)
1014{
1015 struct picolcd_data *data = lcd_get_data(ldev);
1016 return data->lcd_contrast;
1017}
1018
1019static int picolcd_set_contrast(struct lcd_device *ldev, int contrast)
1020{
1021 struct picolcd_data *data = lcd_get_data(ldev);
1022 struct hid_report *report = picolcd_out_report(REPORT_CONTRAST, data->hdev);
1023 unsigned long flags;
1024
1025 if (!report || report->maxfield != 1 || report->field[0]->report_count != 1)
1026 return -ENODEV;
1027
1028 data->lcd_contrast = contrast & 0x0ff;
1029 spin_lock_irqsave(&data->lock, flags);
1030 hid_set_field(report->field[0], 0, data->lcd_contrast);
1031 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
1032 spin_unlock_irqrestore(&data->lock, flags);
1033 return 0;
1034}
1035
1036static int picolcd_check_lcd_fb(struct lcd_device *ldev, struct fb_info *fb)
1037{
1038 return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev));
1039}
1040
1041static struct lcd_ops picolcd_lcdops = {
1042 .get_contrast = picolcd_get_contrast,
1043 .set_contrast = picolcd_set_contrast,
1044 .check_fb = picolcd_check_lcd_fb,
1045};
1046
1047static int picolcd_init_lcd(struct picolcd_data *data, struct hid_report *report)
1048{
1049 struct device *dev = &data->hdev->dev;
1050 struct lcd_device *ldev;
1051
1052 if (!report)
1053 return -ENODEV;
1054 if (report->maxfield != 1 || report->field[0]->report_count != 1 ||
1055 report->field[0]->report_size != 8) {
1056 dev_err(dev, "unsupported CONTRAST report");
1057 return -EINVAL;
1058 }
1059
1060 ldev = lcd_device_register(dev_name(dev), dev, data, &picolcd_lcdops);
1061 if (IS_ERR(ldev)) {
1062 dev_err(dev, "failed to register LCD\n");
1063 return PTR_ERR(ldev);
1064 }
1065 ldev->props.max_contrast = 0x0ff;
1066 data->lcd_contrast = 0xe5;
1067 data->lcd = ldev;
1068 picolcd_set_contrast(ldev, 0xe5);
1069 return 0;
1070}
1071
1072static void picolcd_exit_lcd(struct picolcd_data *data)
1073{
1074 struct lcd_device *ldev = data->lcd;
1075
1076 data->lcd = NULL;
1077 if (ldev)
1078 lcd_device_unregister(ldev);
1079}
1080
1081static inline int picolcd_resume_lcd(struct picolcd_data *data)
1082{
1083 if (!data->lcd)
1084 return 0;
1085 return picolcd_set_contrast(data->lcd, data->lcd_contrast);
1086}
1087#else
1088static inline int picolcd_init_lcd(struct picolcd_data *data,
1089 struct hid_report *report)
1090{
1091 return 0;
1092}
1093static inline void picolcd_exit_lcd(struct picolcd_data *data)
1094{
1095}
1096static inline int picolcd_resume_lcd(struct picolcd_data *data)
1097{
1098 return 0;
1099}
1100#endif /* CONFIG_HID_PICOLCD_LCD */
1101
1102#ifdef CONFIG_HID_PICOLCD_LEDS
1103/**
1104 * LED class device
1105 */
1106static void picolcd_leds_set(struct picolcd_data *data)
1107{
1108 struct hid_report *report;
1109 unsigned long flags;
1110
1111 if (!data->led[0])
1112 return;
1113 report = picolcd_out_report(REPORT_LED_STATE, data->hdev);
1114 if (!report || report->maxfield != 1 || report->field[0]->report_count != 1)
1115 return;
1116
1117 spin_lock_irqsave(&data->lock, flags);
1118 hid_set_field(report->field[0], 0, data->led_state);
1119 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
1120 spin_unlock_irqrestore(&data->lock, flags);
1121}
1122
1123static void picolcd_led_set_brightness(struct led_classdev *led_cdev,
1124 enum led_brightness value)
1125{
1126 struct device *dev;
1127 struct hid_device *hdev;
1128 struct picolcd_data *data;
1129 int i, state = 0;
1130
1131 dev = led_cdev->dev->parent;
1132 hdev = container_of(dev, struct hid_device, dev);
1133 data = hid_get_drvdata(hdev);
1134 for (i = 0; i < 8; i++) {
1135 if (led_cdev != data->led[i])
1136 continue;
1137 state = (data->led_state >> i) & 1;
1138 if (value == LED_OFF && state) {
1139 data->led_state &= ~(1 << i);
1140 picolcd_leds_set(data);
1141 } else if (value != LED_OFF && !state) {
1142 data->led_state |= 1 << i;
1143 picolcd_leds_set(data);
1144 }
1145 break;
1146 }
1147}
1148
1149static enum led_brightness picolcd_led_get_brightness(struct led_classdev *led_cdev)
1150{
1151 struct device *dev;
1152 struct hid_device *hdev;
1153 struct picolcd_data *data;
1154 int i, value = 0;
1155
1156 dev = led_cdev->dev->parent;
1157 hdev = container_of(dev, struct hid_device, dev);
1158 data = hid_get_drvdata(hdev);
1159 for (i = 0; i < 8; i++)
1160 if (led_cdev == data->led[i]) {
1161 value = (data->led_state >> i) & 1;
1162 break;
1163 }
1164 return value ? LED_FULL : LED_OFF;
1165}
1166
1167static int picolcd_init_leds(struct picolcd_data *data, struct hid_report *report)
1168{
1169 struct device *dev = &data->hdev->dev;
1170 struct led_classdev *led;
1171 size_t name_sz = strlen(dev_name(dev)) + 8;
1172 char *name;
1173 int i, ret = 0;
1174
1175 if (!report)
1176 return -ENODEV;
1177 if (report->maxfield != 1 || report->field[0]->report_count != 1 ||
1178 report->field[0]->report_size != 8) {
1179 dev_err(dev, "unsupported LED_STATE report");
1180 return -EINVAL;
1181 }
1182
1183 for (i = 0; i < 8; i++) {
1184 led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL);
1185 if (!led) {
1186 dev_err(dev, "can't allocate memory for LED %d\n", i);
1187 ret = -ENOMEM;
1188 goto err;
1189 }
1190 name = (void *)(&led[1]);
1191 snprintf(name, name_sz, "%s::GPO%d", dev_name(dev), i);
1192 led->name = name;
1193 led->brightness = 0;
1194 led->max_brightness = 1;
1195 led->brightness_get = picolcd_led_get_brightness;
1196 led->brightness_set = picolcd_led_set_brightness;
1197
1198 data->led[i] = led;
1199 ret = led_classdev_register(dev, data->led[i]);
1200 if (ret) {
1201 data->led[i] = NULL;
1202 kfree(led);
1203 dev_err(dev, "can't register LED %d\n", i);
1204 goto err;
1205 }
1206 }
1207 return 0;
1208err:
1209 for (i = 0; i < 8; i++)
1210 if (data->led[i]) {
1211 led = data->led[i];
1212 data->led[i] = NULL;
1213 led_classdev_unregister(led);
1214 kfree(led);
1215 }
1216 return ret;
1217}
1218
1219static void picolcd_exit_leds(struct picolcd_data *data)
1220{
1221 struct led_classdev *led;
1222 int i;
1223
1224 for (i = 0; i < 8; i++) {
1225 led = data->led[i];
1226 data->led[i] = NULL;
1227 if (!led)
1228 continue;
1229 led_classdev_unregister(led);
1230 kfree(led);
1231 }
1232}
1233
1234#else
1235static inline int picolcd_init_leds(struct picolcd_data *data,
1236 struct hid_report *report)
1237{
1238 return 0;
1239}
1240static inline void picolcd_exit_leds(struct picolcd_data *data)
1241{
1242}
1243static inline int picolcd_leds_set(struct picolcd_data *data)
1244{
1245 return 0;
1246}
1247#endif /* CONFIG_HID_PICOLCD_LEDS */
1248
1249/*
1250 * input class device
1251 */
1252static int picolcd_raw_keypad(struct picolcd_data *data,
1253 struct hid_report *report, u8 *raw_data, int size)
1254{
1255 /*
1256 * Keypad event
1257 * First and second data bytes list currently pressed keys,
1258 * 0x00 means no key and at most 2 keys may be pressed at same time
1259 */
1260 int i, j;
1261
1262 /* determine newly pressed keys */
1263 for (i = 0; i < size; i++) {
1264 unsigned int key_code;
1265 if (raw_data[i] == 0)
1266 continue;
1267 for (j = 0; j < sizeof(data->pressed_keys); j++)
1268 if (data->pressed_keys[j] == raw_data[i])
1269 goto key_already_down;
1270 for (j = 0; j < sizeof(data->pressed_keys); j++)
1271 if (data->pressed_keys[j] == 0) {
1272 data->pressed_keys[j] = raw_data[i];
1273 break;
1274 }
1275 input_event(data->input_keys, EV_MSC, MSC_SCAN, raw_data[i]);
1276 if (raw_data[i] < PICOLCD_KEYS)
1277 key_code = data->keycode[raw_data[i]];
1278 else
1279 key_code = KEY_UNKNOWN;
1280 if (key_code != KEY_UNKNOWN) {
1281 dbg_hid(PICOLCD_NAME " got key press for %u:%d",
1282 raw_data[i], key_code);
1283 input_report_key(data->input_keys, key_code, 1);
1284 }
1285 input_sync(data->input_keys);
1286key_already_down:
1287 continue;
1288 }
1289
1290 /* determine newly released keys */
1291 for (j = 0; j < sizeof(data->pressed_keys); j++) {
1292 unsigned int key_code;
1293 if (data->pressed_keys[j] == 0)
1294 continue;
1295 for (i = 0; i < size; i++)
1296 if (data->pressed_keys[j] == raw_data[i])
1297 goto key_still_down;
1298 input_event(data->input_keys, EV_MSC, MSC_SCAN, data->pressed_keys[j]);
1299 if (data->pressed_keys[j] < PICOLCD_KEYS)
1300 key_code = data->keycode[data->pressed_keys[j]];
1301 else
1302 key_code = KEY_UNKNOWN;
1303 if (key_code != KEY_UNKNOWN) {
1304 dbg_hid(PICOLCD_NAME " got key release for %u:%d",
1305 data->pressed_keys[j], key_code);
1306 input_report_key(data->input_keys, key_code, 0);
1307 }
1308 input_sync(data->input_keys);
1309 data->pressed_keys[j] = 0;
1310key_still_down:
1311 continue;
1312 }
1313 return 1;
1314}
1315
1316static int picolcd_raw_cir(struct picolcd_data *data,
1317 struct hid_report *report, u8 *raw_data, int size)
1318{
1319 /* Need understanding of CIR data format to implement ... */
1320 return 1;
1321}
1322
1323static int picolcd_check_version(struct hid_device *hdev)
1324{
1325 struct picolcd_data *data = hid_get_drvdata(hdev);
1326 struct picolcd_pending *verinfo;
1327 int ret = 0;
1328
1329 if (!data)
1330 return -ENODEV;
1331
1332 verinfo = picolcd_send_and_wait(hdev, REPORT_VERSION, NULL, 0);
1333 if (!verinfo) {
1334 hid_err(hdev, "no version response from PicoLCD\n");
1335 return -ENODEV;
1336 }
1337
1338 if (verinfo->raw_size == 2) {
1339 data->version[0] = verinfo->raw_data[1];
1340 data->version[1] = verinfo->raw_data[0];
1341 if (data->status & PICOLCD_BOOTLOADER) {
1342 hid_info(hdev, "PicoLCD, bootloader version %d.%d\n",
1343 verinfo->raw_data[1], verinfo->raw_data[0]);
1344 } else {
1345 hid_info(hdev, "PicoLCD, firmware version %d.%d\n",
1346 verinfo->raw_data[1], verinfo->raw_data[0]);
1347 }
1348 } else {
1349 hid_err(hdev, "confused, got unexpected version response from PicoLCD\n");
1350 ret = -EINVAL;
1351 }
1352 kfree(verinfo);
1353 return ret;
1354}
1355
1356/*
1357 * Reset our device and wait for answer to VERSION request
1358 */
1359static int picolcd_reset(struct hid_device *hdev)
1360{
1361 struct picolcd_data *data = hid_get_drvdata(hdev);
1362 struct hid_report *report = picolcd_out_report(REPORT_RESET, hdev);
1363 unsigned long flags;
1364 int error;
1365
1366 if (!data || !report || report->maxfield != 1)
1367 return -ENODEV;
1368
1369 spin_lock_irqsave(&data->lock, flags);
1370 if (hdev->product == USB_DEVICE_ID_PICOLCD_BOOTLOADER)
1371 data->status |= PICOLCD_BOOTLOADER;
1372
1373 /* perform the reset */
1374 hid_set_field(report->field[0], 0, 1);
1375 usbhid_submit_report(hdev, report, USB_DIR_OUT);
1376 spin_unlock_irqrestore(&data->lock, flags);
1377
1378 error = picolcd_check_version(hdev);
1379 if (error)
1380 return error;
1381
1382 picolcd_resume_lcd(data);
1383 picolcd_resume_backlight(data);
1384#ifdef CONFIG_HID_PICOLCD_FB
1385 if (data->fb_info)
1386 schedule_delayed_work(&data->fb_info->deferred_work, 0);
1387#endif /* CONFIG_HID_PICOLCD_FB */
1388
1389 picolcd_leds_set(data);
1390 return 0;
1391}
1392
1393/*
1394 * The "operation_mode" sysfs attribute
1395 */
1396static ssize_t picolcd_operation_mode_show(struct device *dev,
1397 struct device_attribute *attr, char *buf)
1398{
1399 struct picolcd_data *data = dev_get_drvdata(dev);
1400
1401 if (data->status & PICOLCD_BOOTLOADER)
1402 return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n");
1403 else
1404 return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n");
1405}
1406
1407static ssize_t picolcd_operation_mode_store(struct device *dev,
1408 struct device_attribute *attr, const char *buf, size_t count)
1409{
1410 struct picolcd_data *data = dev_get_drvdata(dev);
1411 struct hid_report *report = NULL;
1412 size_t cnt = count;
1413 int timeout = data->opmode_delay;
1414 unsigned long flags;
1415
1416 if (cnt >= 3 && strncmp("lcd", buf, 3) == 0) {
1417 if (data->status & PICOLCD_BOOTLOADER)
1418 report = picolcd_out_report(REPORT_EXIT_FLASHER, data->hdev);
1419 buf += 3;
1420 cnt -= 3;
1421 } else if (cnt >= 10 && strncmp("bootloader", buf, 10) == 0) {
1422 if (!(data->status & PICOLCD_BOOTLOADER))
1423 report = picolcd_out_report(REPORT_EXIT_KEYBOARD, data->hdev);
1424 buf += 10;
1425 cnt -= 10;
1426 }
1427 if (!report)
1428 return -EINVAL;
1429
1430 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
1431 cnt--;
1432 if (cnt != 0)
1433 return -EINVAL;
1434
1435 spin_lock_irqsave(&data->lock, flags);
1436 hid_set_field(report->field[0], 0, timeout & 0xff);
1437 hid_set_field(report->field[0], 1, (timeout >> 8) & 0xff);
1438 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
1439 spin_unlock_irqrestore(&data->lock, flags);
1440 return count;
1441}
1442
1443static DEVICE_ATTR(operation_mode, 0644, picolcd_operation_mode_show,
1444 picolcd_operation_mode_store);
1445
1446/*
1447 * The "operation_mode_delay" sysfs attribute
1448 */
1449static ssize_t picolcd_operation_mode_delay_show(struct device *dev,
1450 struct device_attribute *attr, char *buf)
1451{
1452 struct picolcd_data *data = dev_get_drvdata(dev);
1453
1454 return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay);
1455}
1456
1457static ssize_t picolcd_operation_mode_delay_store(struct device *dev,
1458 struct device_attribute *attr, const char *buf, size_t count)
1459{
1460 struct picolcd_data *data = dev_get_drvdata(dev);
1461 unsigned u;
1462 if (sscanf(buf, "%u", &u) != 1)
1463 return -EINVAL;
1464 if (u > 30000)
1465 return -EINVAL;
1466 else
1467 data->opmode_delay = u;
1468 return count;
1469}
1470
1471static DEVICE_ATTR(operation_mode_delay, 0644, picolcd_operation_mode_delay_show,
1472 picolcd_operation_mode_delay_store);
1473
1474
1475#ifdef CONFIG_DEBUG_FS
1476/*
1477 * The "reset" file
1478 */
1479static int picolcd_debug_reset_show(struct seq_file *f, void *p)
1480{
1481 if (picolcd_fbinfo((struct picolcd_data *)f->private))
1482 seq_printf(f, "all fb\n");
1483 else
1484 seq_printf(f, "all\n");
1485 return 0;
1486}
1487
1488static int picolcd_debug_reset_open(struct inode *inode, struct file *f)
1489{
1490 return single_open(f, picolcd_debug_reset_show, inode->i_private);
1491}
1492
1493static ssize_t picolcd_debug_reset_write(struct file *f, const char __user *user_buf,
1494 size_t count, loff_t *ppos)
1495{
1496 struct picolcd_data *data = ((struct seq_file *)f->private_data)->private;
1497 char buf[32];
1498 size_t cnt = min(count, sizeof(buf)-1);
1499 if (copy_from_user(buf, user_buf, cnt))
1500 return -EFAULT;
1501
1502 while (cnt > 0 && (buf[cnt-1] == ' ' || buf[cnt-1] == '\n'))
1503 cnt--;
1504 buf[cnt] = '\0';
1505 if (strcmp(buf, "all") == 0) {
1506 picolcd_reset(data->hdev);
1507 picolcd_fb_reset(data, 1);
1508 } else if (strcmp(buf, "fb") == 0) {
1509 picolcd_fb_reset(data, 1);
1510 } else {
1511 return -EINVAL;
1512 }
1513 return count;
1514}
1515
1516static const struct file_operations picolcd_debug_reset_fops = {
1517 .owner = THIS_MODULE,
1518 .open = picolcd_debug_reset_open,
1519 .read = seq_read,
1520 .llseek = seq_lseek,
1521 .write = picolcd_debug_reset_write,
1522 .release = single_release,
1523};
1524
1525/*
1526 * The "eeprom" file
1527 */
1528static ssize_t picolcd_debug_eeprom_read(struct file *f, char __user *u,
1529 size_t s, loff_t *off)
1530{
1531 struct picolcd_data *data = f->private_data;
1532 struct picolcd_pending *resp;
1533 u8 raw_data[3];
1534 ssize_t ret = -EIO;
1535
1536 if (s == 0)
1537 return -EINVAL;
1538 if (*off > 0x0ff)
1539 return 0;
1540
1541 /* prepare buffer with info about what we want to read (addr & len) */
1542 raw_data[0] = *off & 0xff;
1543 raw_data[1] = (*off >> 8) & 0xff;
1544 raw_data[2] = s < 20 ? s : 20;
1545 if (*off + raw_data[2] > 0xff)
1546 raw_data[2] = 0x100 - *off;
1547 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_READ, raw_data,
1548 sizeof(raw_data));
1549 if (!resp)
1550 return -EIO;
1551
1552 if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) {
1553 /* successful read :) */
1554 ret = resp->raw_data[2];
1555 if (ret > s)
1556 ret = s;
1557 if (copy_to_user(u, resp->raw_data+3, ret))
1558 ret = -EFAULT;
1559 else
1560 *off += ret;
1561 } /* anything else is some kind of IO error */
1562
1563 kfree(resp);
1564 return ret;
1565}
1566
1567static ssize_t picolcd_debug_eeprom_write(struct file *f, const char __user *u,
1568 size_t s, loff_t *off)
1569{
1570 struct picolcd_data *data = f->private_data;
1571 struct picolcd_pending *resp;
1572 ssize_t ret = -EIO;
1573 u8 raw_data[23];
1574
1575 if (s == 0)
1576 return -EINVAL;
1577 if (*off > 0x0ff)
1578 return -ENOSPC;
1579
1580 memset(raw_data, 0, sizeof(raw_data));
1581 raw_data[0] = *off & 0xff;
1582 raw_data[1] = (*off >> 8) & 0xff;
1583 raw_data[2] = min((size_t)20, s);
1584 if (*off + raw_data[2] > 0xff)
1585 raw_data[2] = 0x100 - *off;
1586
1587 if (copy_from_user(raw_data+3, u, min((u8)20, raw_data[2])))
1588 return -EFAULT;
1589 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_WRITE, raw_data,
1590 sizeof(raw_data));
1591
1592 if (!resp)
1593 return -EIO;
1594
1595 if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) {
1596 /* check if written data matches */
1597 if (memcmp(raw_data, resp->raw_data, 3+raw_data[2]) == 0) {
1598 *off += raw_data[2];
1599 ret = raw_data[2];
1600 }
1601 }
1602 kfree(resp);
1603 return ret;
1604}
1605
1606/*
1607 * Notes:
1608 * - read/write happens in chunks of at most 20 bytes, it's up to userspace
1609 * to loop in order to get more data.
1610 * - on write errors on otherwise correct write request the bytes
1611 * that should have been written are in undefined state.
1612 */
1613static const struct file_operations picolcd_debug_eeprom_fops = {
1614 .owner = THIS_MODULE,
1615 .open = simple_open,
1616 .read = picolcd_debug_eeprom_read,
1617 .write = picolcd_debug_eeprom_write,
1618 .llseek = generic_file_llseek,
1619};
1620
1621/*
1622 * The "flash" file
1623 */
1624/* record a flash address to buf (bounds check to be done by caller) */
1625static int _picolcd_flash_setaddr(struct picolcd_data *data, u8 *buf, long off)
1626{
1627 buf[0] = off & 0xff;
1628 buf[1] = (off >> 8) & 0xff;
1629 if (data->addr_sz == 3)
1630 buf[2] = (off >> 16) & 0xff;
1631 return data->addr_sz == 2 ? 2 : 3;
1632}
1633
1634/* read a given size of data (bounds check to be done by caller) */
1635static ssize_t _picolcd_flash_read(struct picolcd_data *data, int report_id,
1636 char __user *u, size_t s, loff_t *off)
1637{
1638 struct picolcd_pending *resp;
1639 u8 raw_data[4];
1640 ssize_t ret = 0;
1641 int len_off, err = -EIO;
1642
1643 while (s > 0) {
1644 err = -EIO;
1645 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
1646 raw_data[len_off] = s > 32 ? 32 : s;
1647 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, len_off+1);
1648 if (!resp || !resp->in_report)
1649 goto skip;
1650 if (resp->in_report->id == REPORT_MEMORY ||
1651 resp->in_report->id == REPORT_BL_READ_MEMORY) {
1652 if (memcmp(raw_data, resp->raw_data, len_off+1) != 0)
1653 goto skip;
1654 if (copy_to_user(u+ret, resp->raw_data+len_off+1, raw_data[len_off])) {
1655 err = -EFAULT;
1656 goto skip;
1657 }
1658 *off += raw_data[len_off];
1659 s -= raw_data[len_off];
1660 ret += raw_data[len_off];
1661 err = 0;
1662 }
1663skip:
1664 kfree(resp);
1665 if (err)
1666 return ret > 0 ? ret : err;
1667 }
1668 return ret;
1669}
1670
1671static ssize_t picolcd_debug_flash_read(struct file *f, char __user *u,
1672 size_t s, loff_t *off)
1673{
1674 struct picolcd_data *data = f->private_data;
1675
1676 if (s == 0)
1677 return -EINVAL;
1678 if (*off > 0x05fff)
1679 return 0;
1680 if (*off + s > 0x05fff)
1681 s = 0x06000 - *off;
1682
1683 if (data->status & PICOLCD_BOOTLOADER)
1684 return _picolcd_flash_read(data, REPORT_BL_READ_MEMORY, u, s, off);
1685 else
1686 return _picolcd_flash_read(data, REPORT_READ_MEMORY, u, s, off);
1687}
1688
1689/* erase block aligned to 64bytes boundary */
1690static ssize_t _picolcd_flash_erase64(struct picolcd_data *data, int report_id,
1691 loff_t *off)
1692{
1693 struct picolcd_pending *resp;
1694 u8 raw_data[3];
1695 int len_off;
1696 ssize_t ret = -EIO;
1697
1698 if (*off & 0x3f)
1699 return -EINVAL;
1700
1701 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
1702 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, len_off);
1703 if (!resp || !resp->in_report)
1704 goto skip;
1705 if (resp->in_report->id == REPORT_MEMORY ||
1706 resp->in_report->id == REPORT_BL_ERASE_MEMORY) {
1707 if (memcmp(raw_data, resp->raw_data, len_off) != 0)
1708 goto skip;
1709 ret = 0;
1710 }
1711skip:
1712 kfree(resp);
1713 return ret;
1714}
1715
1716/* write a given size of data (bounds check to be done by caller) */
1717static ssize_t _picolcd_flash_write(struct picolcd_data *data, int report_id,
1718 const char __user *u, size_t s, loff_t *off)
1719{
1720 struct picolcd_pending *resp;
1721 u8 raw_data[36];
1722 ssize_t ret = 0;
1723 int len_off, err = -EIO;
1724
1725 while (s > 0) {
1726 err = -EIO;
1727 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
1728 raw_data[len_off] = s > 32 ? 32 : s;
1729 if (copy_from_user(raw_data+len_off+1, u, raw_data[len_off])) {
1730 err = -EFAULT;
1731 break;
1732 }
1733 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data,
1734 len_off+1+raw_data[len_off]);
1735 if (!resp || !resp->in_report)
1736 goto skip;
1737 if (resp->in_report->id == REPORT_MEMORY ||
1738 resp->in_report->id == REPORT_BL_WRITE_MEMORY) {
1739 if (memcmp(raw_data, resp->raw_data, len_off+1+raw_data[len_off]) != 0)
1740 goto skip;
1741 *off += raw_data[len_off];
1742 s -= raw_data[len_off];
1743 ret += raw_data[len_off];
1744 err = 0;
1745 }
1746skip:
1747 kfree(resp);
1748 if (err)
1749 break;
1750 }
1751 return ret > 0 ? ret : err;
1752}
1753
1754static ssize_t picolcd_debug_flash_write(struct file *f, const char __user *u,
1755 size_t s, loff_t *off)
1756{
1757 struct picolcd_data *data = f->private_data;
1758 ssize_t err, ret = 0;
1759 int report_erase, report_write;
1760
1761 if (s == 0)
1762 return -EINVAL;
1763 if (*off > 0x5fff)
1764 return -ENOSPC;
1765 if (s & 0x3f)
1766 return -EINVAL;
1767 if (*off & 0x3f)
1768 return -EINVAL;
1769
1770 if (data->status & PICOLCD_BOOTLOADER) {
1771 report_erase = REPORT_BL_ERASE_MEMORY;
1772 report_write = REPORT_BL_WRITE_MEMORY;
1773 } else {
1774 report_erase = REPORT_ERASE_MEMORY;
1775 report_write = REPORT_WRITE_MEMORY;
1776 }
1777 mutex_lock(&data->mutex_flash);
1778 while (s > 0) {
1779 err = _picolcd_flash_erase64(data, report_erase, off);
1780 if (err)
1781 break;
1782 err = _picolcd_flash_write(data, report_write, u, 64, off);
1783 if (err < 0)
1784 break;
1785 ret += err;
1786 *off += err;
1787 s -= err;
1788 if (err != 64)
1789 break;
1790 }
1791 mutex_unlock(&data->mutex_flash);
1792 return ret > 0 ? ret : err;
1793}
1794
1795/*
1796 * Notes:
1797 * - concurrent writing is prevented by mutex and all writes must be
1798 * n*64 bytes and 64-byte aligned, each write being preceded by an
1799 * ERASE which erases a 64byte block.
1800 * If less than requested was written or an error is returned for an
1801 * otherwise correct write request the next 64-byte block which should
1802 * have been written is in undefined state (mostly: original, erased,
1803 * (half-)written with write error)
1804 * - reading can happen without special restriction
1805 */
1806static const struct file_operations picolcd_debug_flash_fops = {
1807 .owner = THIS_MODULE,
1808 .open = simple_open,
1809 .read = picolcd_debug_flash_read,
1810 .write = picolcd_debug_flash_write,
1811 .llseek = generic_file_llseek,
1812};
1813
1814
1815/*
1816 * Helper code for HID report level dumping/debugging
1817 */
1818static const char *error_codes[] = {
1819 "success", "parameter missing", "data_missing", "block readonly",
1820 "block not erasable", "block too big", "section overflow",
1821 "invalid command length", "invalid data length",
1822};
1823
1824static void dump_buff_as_hex(char *dst, size_t dst_sz, const u8 *data,
1825 const size_t data_len)
1826{
1827 int i, j;
1828 for (i = j = 0; i < data_len && j + 3 < dst_sz; i++) {
1829 dst[j++] = hex_asc[(data[i] >> 4) & 0x0f];
1830 dst[j++] = hex_asc[data[i] & 0x0f];
1831 dst[j++] = ' ';
1832 }
1833 if (j < dst_sz) {
1834 dst[j--] = '\0';
1835 dst[j] = '\n';
1836 } else
1837 dst[j] = '\0';
1838}
1839
1840static void picolcd_debug_out_report(struct picolcd_data *data,
1841 struct hid_device *hdev, struct hid_report *report)
1842{
1843 u8 raw_data[70];
1844 int raw_size = (report->size >> 3) + 1;
1845 char *buff;
1846#define BUFF_SZ 256
1847
1848 /* Avoid unnecessary overhead if debugfs is disabled */
1849 if (list_empty(&hdev->debug_list))
1850 return;
1851
1852 buff = kmalloc(BUFF_SZ, GFP_ATOMIC);
1853 if (!buff)
1854 return;
1855
1856 snprintf(buff, BUFF_SZ, "\nout report %d (size %d) = ",
1857 report->id, raw_size);
1858 hid_debug_event(hdev, buff);
1859 if (raw_size + 5 > sizeof(raw_data)) {
1860 kfree(buff);
1861 hid_debug_event(hdev, " TOO BIG\n");
1862 return;
1863 } else {
1864 raw_data[0] = report->id;
1865 hid_output_report(report, raw_data);
1866 dump_buff_as_hex(buff, BUFF_SZ, raw_data, raw_size);
1867 hid_debug_event(hdev, buff);
1868 }
1869
1870 switch (report->id) {
1871 case REPORT_LED_STATE:
1872 /* 1 data byte with GPO state */
1873 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1874 "REPORT_LED_STATE", report->id, raw_size-1);
1875 hid_debug_event(hdev, buff);
1876 snprintf(buff, BUFF_SZ, "\tGPO state: 0x%02x\n", raw_data[1]);
1877 hid_debug_event(hdev, buff);
1878 break;
1879 case REPORT_BRIGHTNESS:
1880 /* 1 data byte with brightness */
1881 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1882 "REPORT_BRIGHTNESS", report->id, raw_size-1);
1883 hid_debug_event(hdev, buff);
1884 snprintf(buff, BUFF_SZ, "\tBrightness: 0x%02x\n", raw_data[1]);
1885 hid_debug_event(hdev, buff);
1886 break;
1887 case REPORT_CONTRAST:
1888 /* 1 data byte with contrast */
1889 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1890 "REPORT_CONTRAST", report->id, raw_size-1);
1891 hid_debug_event(hdev, buff);
1892 snprintf(buff, BUFF_SZ, "\tContrast: 0x%02x\n", raw_data[1]);
1893 hid_debug_event(hdev, buff);
1894 break;
1895 case REPORT_RESET:
1896 /* 2 data bytes with reset duration in ms */
1897 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1898 "REPORT_RESET", report->id, raw_size-1);
1899 hid_debug_event(hdev, buff);
1900 snprintf(buff, BUFF_SZ, "\tDuration: 0x%02x%02x (%dms)\n",
1901 raw_data[2], raw_data[1], raw_data[2] << 8 | raw_data[1]);
1902 hid_debug_event(hdev, buff);
1903 break;
1904 case REPORT_LCD_CMD:
1905 /* 63 data bytes with LCD commands */
1906 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1907 "REPORT_LCD_CMD", report->id, raw_size-1);
1908 hid_debug_event(hdev, buff);
1909 /* TODO: format decoding */
1910 break;
1911 case REPORT_LCD_DATA:
1912 /* 63 data bytes with LCD data */
1913 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1914 "REPORT_LCD_CMD", report->id, raw_size-1);
1915 /* TODO: format decoding */
1916 hid_debug_event(hdev, buff);
1917 break;
1918 case REPORT_LCD_CMD_DATA:
1919 /* 63 data bytes with LCD commands and data */
1920 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1921 "REPORT_LCD_CMD", report->id, raw_size-1);
1922 /* TODO: format decoding */
1923 hid_debug_event(hdev, buff);
1924 break;
1925 case REPORT_EE_READ:
1926 /* 3 data bytes with read area description */
1927 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1928 "REPORT_EE_READ", report->id, raw_size-1);
1929 hid_debug_event(hdev, buff);
1930 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
1931 raw_data[2], raw_data[1]);
1932 hid_debug_event(hdev, buff);
1933 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
1934 hid_debug_event(hdev, buff);
1935 break;
1936 case REPORT_EE_WRITE:
1937 /* 3+1..20 data bytes with write area description */
1938 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1939 "REPORT_EE_WRITE", report->id, raw_size-1);
1940 hid_debug_event(hdev, buff);
1941 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
1942 raw_data[2], raw_data[1]);
1943 hid_debug_event(hdev, buff);
1944 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
1945 hid_debug_event(hdev, buff);
1946 if (raw_data[3] == 0) {
1947 snprintf(buff, BUFF_SZ, "\tNo data\n");
1948 } else if (raw_data[3] + 4 <= raw_size) {
1949 snprintf(buff, BUFF_SZ, "\tData: ");
1950 hid_debug_event(hdev, buff);
1951 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
1952 } else {
1953 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
1954 }
1955 hid_debug_event(hdev, buff);
1956 break;
1957 case REPORT_ERASE_MEMORY:
1958 case REPORT_BL_ERASE_MEMORY:
1959 /* 3 data bytes with pointer inside erase block */
1960 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1961 "REPORT_ERASE_MEMORY", report->id, raw_size-1);
1962 hid_debug_event(hdev, buff);
1963 switch (data->addr_sz) {
1964 case 2:
1965 snprintf(buff, BUFF_SZ, "\tAddress inside 64 byte block: 0x%02x%02x\n",
1966 raw_data[2], raw_data[1]);
1967 break;
1968 case 3:
1969 snprintf(buff, BUFF_SZ, "\tAddress inside 64 byte block: 0x%02x%02x%02x\n",
1970 raw_data[3], raw_data[2], raw_data[1]);
1971 break;
1972 default:
1973 snprintf(buff, BUFF_SZ, "\tNot supported\n");
1974 }
1975 hid_debug_event(hdev, buff);
1976 break;
1977 case REPORT_READ_MEMORY:
1978 case REPORT_BL_READ_MEMORY:
1979 /* 4 data bytes with read area description */
1980 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
1981 "REPORT_READ_MEMORY", report->id, raw_size-1);
1982 hid_debug_event(hdev, buff);
1983 switch (data->addr_sz) {
1984 case 2:
1985 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
1986 raw_data[2], raw_data[1]);
1987 hid_debug_event(hdev, buff);
1988 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
1989 break;
1990 case 3:
1991 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
1992 raw_data[3], raw_data[2], raw_data[1]);
1993 hid_debug_event(hdev, buff);
1994 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
1995 break;
1996 default:
1997 snprintf(buff, BUFF_SZ, "\tNot supported\n");
1998 }
1999 hid_debug_event(hdev, buff);
2000 break;
2001 case REPORT_WRITE_MEMORY:
2002 case REPORT_BL_WRITE_MEMORY:
2003 /* 4+1..32 data bytes with write adrea description */
2004 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
2005 "REPORT_WRITE_MEMORY", report->id, raw_size-1);
2006 hid_debug_event(hdev, buff);
2007 switch (data->addr_sz) {
2008 case 2:
2009 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
2010 raw_data[2], raw_data[1]);
2011 hid_debug_event(hdev, buff);
2012 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
2013 hid_debug_event(hdev, buff);
2014 if (raw_data[3] == 0) {
2015 snprintf(buff, BUFF_SZ, "\tNo data\n");
2016 } else if (raw_data[3] + 4 <= raw_size) {
2017 snprintf(buff, BUFF_SZ, "\tData: ");
2018 hid_debug_event(hdev, buff);
2019 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
2020 } else {
2021 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
2022 }
2023 break;
2024 case 3:
2025 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
2026 raw_data[3], raw_data[2], raw_data[1]);
2027 hid_debug_event(hdev, buff);
2028 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
2029 hid_debug_event(hdev, buff);
2030 if (raw_data[4] == 0) {
2031 snprintf(buff, BUFF_SZ, "\tNo data\n");
2032 } else if (raw_data[4] + 5 <= raw_size) {
2033 snprintf(buff, BUFF_SZ, "\tData: ");
2034 hid_debug_event(hdev, buff);
2035 dump_buff_as_hex(buff, BUFF_SZ, raw_data+5, raw_data[4]);
2036 } else {
2037 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
2038 }
2039 break;
2040 default:
2041 snprintf(buff, BUFF_SZ, "\tNot supported\n");
2042 }
2043 hid_debug_event(hdev, buff);
2044 break;
2045 case REPORT_SPLASH_RESTART:
2046 /* TODO */
2047 break;
2048 case REPORT_EXIT_KEYBOARD:
2049 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
2050 "REPORT_EXIT_KEYBOARD", report->id, raw_size-1);
2051 hid_debug_event(hdev, buff);
2052 snprintf(buff, BUFF_SZ, "\tRestart delay: %dms (0x%02x%02x)\n",
2053 raw_data[1] | (raw_data[2] << 8),
2054 raw_data[2], raw_data[1]);
2055 hid_debug_event(hdev, buff);
2056 break;
2057 case REPORT_VERSION:
2058 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
2059 "REPORT_VERSION", report->id, raw_size-1);
2060 hid_debug_event(hdev, buff);
2061 break;
2062 case REPORT_DEVID:
2063 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
2064 "REPORT_DEVID", report->id, raw_size-1);
2065 hid_debug_event(hdev, buff);
2066 break;
2067 case REPORT_SPLASH_SIZE:
2068 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
2069 "REPORT_SPLASH_SIZE", report->id, raw_size-1);
2070 hid_debug_event(hdev, buff);
2071 break;
2072 case REPORT_HOOK_VERSION:
2073 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
2074 "REPORT_HOOK_VERSION", report->id, raw_size-1);
2075 hid_debug_event(hdev, buff);
2076 break;
2077 case REPORT_EXIT_FLASHER:
2078 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
2079 "REPORT_VERSION", report->id, raw_size-1);
2080 hid_debug_event(hdev, buff);
2081 snprintf(buff, BUFF_SZ, "\tRestart delay: %dms (0x%02x%02x)\n",
2082 raw_data[1] | (raw_data[2] << 8),
2083 raw_data[2], raw_data[1]);
2084 hid_debug_event(hdev, buff);
2085 break;
2086 default:
2087 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
2088 "<unknown>", report->id, raw_size-1);
2089 hid_debug_event(hdev, buff);
2090 break;
2091 }
2092 wake_up_interruptible(&hdev->debug_wait);
2093 kfree(buff);
2094}
2095
2096static void picolcd_debug_raw_event(struct picolcd_data *data,
2097 struct hid_device *hdev, struct hid_report *report,
2098 u8 *raw_data, int size)
2099{
2100 char *buff;
2101
2102#define BUFF_SZ 256
2103 /* Avoid unnecessary overhead if debugfs is disabled */
2104 if (!hdev->debug_events)
2105 return;
2106
2107 buff = kmalloc(BUFF_SZ, GFP_ATOMIC);
2108 if (!buff)
2109 return;
2110
2111 switch (report->id) {
2112 case REPORT_ERROR_CODE:
2113 /* 2 data bytes with affected report and error code */
2114 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2115 "REPORT_ERROR_CODE", report->id, size-1);
2116 hid_debug_event(hdev, buff);
2117 if (raw_data[2] < ARRAY_SIZE(error_codes))
2118 snprintf(buff, BUFF_SZ, "\tError code 0x%02x (%s) in reply to report 0x%02x\n",
2119 raw_data[2], error_codes[raw_data[2]], raw_data[1]);
2120 else
2121 snprintf(buff, BUFF_SZ, "\tError code 0x%02x in reply to report 0x%02x\n",
2122 raw_data[2], raw_data[1]);
2123 hid_debug_event(hdev, buff);
2124 break;
2125 case REPORT_KEY_STATE:
2126 /* 2 data bytes with key state */
2127 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2128 "REPORT_KEY_STATE", report->id, size-1);
2129 hid_debug_event(hdev, buff);
2130 if (raw_data[1] == 0)
2131 snprintf(buff, BUFF_SZ, "\tNo key pressed\n");
2132 else if (raw_data[2] == 0)
2133 snprintf(buff, BUFF_SZ, "\tOne key pressed: 0x%02x (%d)\n",
2134 raw_data[1], raw_data[1]);
2135 else
2136 snprintf(buff, BUFF_SZ, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n",
2137 raw_data[1], raw_data[1], raw_data[2], raw_data[2]);
2138 hid_debug_event(hdev, buff);
2139 break;
2140 case REPORT_IR_DATA:
2141 /* Up to 20 byes of IR scancode data */
2142 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2143 "REPORT_IR_DATA", report->id, size-1);
2144 hid_debug_event(hdev, buff);
2145 if (raw_data[1] == 0) {
2146 snprintf(buff, BUFF_SZ, "\tUnexpectedly 0 data length\n");
2147 hid_debug_event(hdev, buff);
2148 } else if (raw_data[1] + 1 <= size) {
2149 snprintf(buff, BUFF_SZ, "\tData length: %d\n\tIR Data: ",
2150 raw_data[1]-1);
2151 hid_debug_event(hdev, buff);
2152 dump_buff_as_hex(buff, BUFF_SZ, raw_data+2, raw_data[1]-1);
2153 hid_debug_event(hdev, buff);
2154 } else {
2155 snprintf(buff, BUFF_SZ, "\tOverflowing data length: %d\n",
2156 raw_data[1]-1);
2157 hid_debug_event(hdev, buff);
2158 }
2159 break;
2160 case REPORT_EE_DATA:
2161 /* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */
2162 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2163 "REPORT_EE_DATA", report->id, size-1);
2164 hid_debug_event(hdev, buff);
2165 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
2166 raw_data[2], raw_data[1]);
2167 hid_debug_event(hdev, buff);
2168 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
2169 hid_debug_event(hdev, buff);
2170 if (raw_data[3] == 0) {
2171 snprintf(buff, BUFF_SZ, "\tNo data\n");
2172 hid_debug_event(hdev, buff);
2173 } else if (raw_data[3] + 4 <= size) {
2174 snprintf(buff, BUFF_SZ, "\tData: ");
2175 hid_debug_event(hdev, buff);
2176 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
2177 hid_debug_event(hdev, buff);
2178 } else {
2179 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
2180 hid_debug_event(hdev, buff);
2181 }
2182 break;
2183 case REPORT_MEMORY:
2184 /* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRTIE_MEMORY */
2185 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2186 "REPORT_MEMORY", report->id, size-1);
2187 hid_debug_event(hdev, buff);
2188 switch (data->addr_sz) {
2189 case 2:
2190 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
2191 raw_data[2], raw_data[1]);
2192 hid_debug_event(hdev, buff);
2193 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
2194 hid_debug_event(hdev, buff);
2195 if (raw_data[3] == 0) {
2196 snprintf(buff, BUFF_SZ, "\tNo data\n");
2197 } else if (raw_data[3] + 4 <= size) {
2198 snprintf(buff, BUFF_SZ, "\tData: ");
2199 hid_debug_event(hdev, buff);
2200 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
2201 } else {
2202 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
2203 }
2204 break;
2205 case 3:
2206 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
2207 raw_data[3], raw_data[2], raw_data[1]);
2208 hid_debug_event(hdev, buff);
2209 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
2210 hid_debug_event(hdev, buff);
2211 if (raw_data[4] == 0) {
2212 snprintf(buff, BUFF_SZ, "\tNo data\n");
2213 } else if (raw_data[4] + 5 <= size) {
2214 snprintf(buff, BUFF_SZ, "\tData: ");
2215 hid_debug_event(hdev, buff);
2216 dump_buff_as_hex(buff, BUFF_SZ, raw_data+5, raw_data[4]);
2217 } else {
2218 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
2219 }
2220 break;
2221 default:
2222 snprintf(buff, BUFF_SZ, "\tNot supported\n");
2223 }
2224 hid_debug_event(hdev, buff);
2225 break;
2226 case REPORT_VERSION:
2227 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2228 "REPORT_VERSION", report->id, size-1);
2229 hid_debug_event(hdev, buff);
2230 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n",
2231 raw_data[2], raw_data[1]);
2232 hid_debug_event(hdev, buff);
2233 break;
2234 case REPORT_BL_ERASE_MEMORY:
2235 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2236 "REPORT_BL_ERASE_MEMORY", report->id, size-1);
2237 hid_debug_event(hdev, buff);
2238 /* TODO */
2239 break;
2240 case REPORT_BL_READ_MEMORY:
2241 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2242 "REPORT_BL_READ_MEMORY", report->id, size-1);
2243 hid_debug_event(hdev, buff);
2244 /* TODO */
2245 break;
2246 case REPORT_BL_WRITE_MEMORY:
2247 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2248 "REPORT_BL_WRITE_MEMORY", report->id, size-1);
2249 hid_debug_event(hdev, buff);
2250 /* TODO */
2251 break;
2252 case REPORT_DEVID:
2253 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2254 "REPORT_DEVID", report->id, size-1);
2255 hid_debug_event(hdev, buff);
2256 snprintf(buff, BUFF_SZ, "\tSerial: 0x%02x%02x%02x%02x\n",
2257 raw_data[1], raw_data[2], raw_data[3], raw_data[4]);
2258 hid_debug_event(hdev, buff);
2259 snprintf(buff, BUFF_SZ, "\tType: 0x%02x\n",
2260 raw_data[5]);
2261 hid_debug_event(hdev, buff);
2262 break;
2263 case REPORT_SPLASH_SIZE:
2264 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2265 "REPORT_SPLASH_SIZE", report->id, size-1);
2266 hid_debug_event(hdev, buff);
2267 snprintf(buff, BUFF_SZ, "\tTotal splash space: %d\n",
2268 (raw_data[2] << 8) | raw_data[1]);
2269 hid_debug_event(hdev, buff);
2270 snprintf(buff, BUFF_SZ, "\tUsed splash space: %d\n",
2271 (raw_data[4] << 8) | raw_data[3]);
2272 hid_debug_event(hdev, buff);
2273 break;
2274 case REPORT_HOOK_VERSION:
2275 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2276 "REPORT_HOOK_VERSION", report->id, size-1);
2277 hid_debug_event(hdev, buff);
2278 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n",
2279 raw_data[1], raw_data[2]);
2280 hid_debug_event(hdev, buff);
2281 break;
2282 default:
2283 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
2284 "<unknown>", report->id, size-1);
2285 hid_debug_event(hdev, buff);
2286 break;
2287 }
2288 wake_up_interruptible(&hdev->debug_wait);
2289 kfree(buff);
2290}
2291
2292static void picolcd_init_devfs(struct picolcd_data *data,
2293 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
2294 struct hid_report *flash_r, struct hid_report *flash_w,
2295 struct hid_report *reset)
2296{
2297 struct hid_device *hdev = data->hdev;
2298
2299 mutex_init(&data->mutex_flash);
2300
2301 /* reset */
2302 if (reset)
2303 data->debug_reset = debugfs_create_file("reset", 0600,
2304 hdev->debug_dir, data, &picolcd_debug_reset_fops);
2305
2306 /* eeprom */
2307 if (eeprom_r || eeprom_w)
2308 data->debug_eeprom = debugfs_create_file("eeprom",
2309 (eeprom_w ? S_IWUSR : 0) | (eeprom_r ? S_IRUSR : 0),
2310 hdev->debug_dir, data, &picolcd_debug_eeprom_fops);
2311
2312 /* flash */
2313 if (flash_r && flash_r->maxfield == 1 && flash_r->field[0]->report_size == 8)
2314 data->addr_sz = flash_r->field[0]->report_count - 1;
2315 else
2316 data->addr_sz = -1;
2317 if (data->addr_sz == 2 || data->addr_sz == 3) {
2318 data->debug_flash = debugfs_create_file("flash",
2319 (flash_w ? S_IWUSR : 0) | (flash_r ? S_IRUSR : 0),
2320 hdev->debug_dir, data, &picolcd_debug_flash_fops);
2321 } else if (flash_r || flash_w)
2322 hid_warn(hdev, "Unexpected FLASH access reports, please submit rdesc for review\n");
2323}
2324
2325static void picolcd_exit_devfs(struct picolcd_data *data)
2326{
2327 struct dentry *dent;
2328
2329 dent = data->debug_reset;
2330 data->debug_reset = NULL;
2331 if (dent)
2332 debugfs_remove(dent);
2333 dent = data->debug_eeprom;
2334 data->debug_eeprom = NULL;
2335 if (dent)
2336 debugfs_remove(dent);
2337 dent = data->debug_flash;
2338 data->debug_flash = NULL;
2339 if (dent)
2340 debugfs_remove(dent);
2341 mutex_destroy(&data->mutex_flash);
2342}
2343#else
2344static inline void picolcd_debug_raw_event(struct picolcd_data *data,
2345 struct hid_device *hdev, struct hid_report *report,
2346 u8 *raw_data, int size)
2347{
2348}
2349static inline void picolcd_init_devfs(struct picolcd_data *data,
2350 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
2351 struct hid_report *flash_r, struct hid_report *flash_w,
2352 struct hid_report *reset)
2353{
2354}
2355static inline void picolcd_exit_devfs(struct picolcd_data *data)
2356{
2357}
2358#endif /* CONFIG_DEBUG_FS */
2359
2360/*
2361 * Handle raw report as sent by device
2362 */
2363static int picolcd_raw_event(struct hid_device *hdev,
2364 struct hid_report *report, u8 *raw_data, int size)
2365{
2366 struct picolcd_data *data = hid_get_drvdata(hdev);
2367 unsigned long flags;
2368 int ret = 0;
2369
2370 if (!data)
2371 return 1;
2372
2373 if (report->id == REPORT_KEY_STATE) {
2374 if (data->input_keys)
2375 ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
2376 } else if (report->id == REPORT_IR_DATA) {
2377 if (data->input_cir)
2378 ret = picolcd_raw_cir(data, report, raw_data+1, size-1);
2379 } else {
2380 spin_lock_irqsave(&data->lock, flags);
2381 /*
2382 * We let the caller of picolcd_send_and_wait() check if the
2383 * report we got is one of the expected ones or not.
2384 */
2385 if (data->pending) {
2386 memcpy(data->pending->raw_data, raw_data+1, size-1);
2387 data->pending->raw_size = size-1;
2388 data->pending->in_report = report;
2389 complete(&data->pending->ready);
2390 }
2391 spin_unlock_irqrestore(&data->lock, flags);
2392 }
2393
2394 picolcd_debug_raw_event(data, hdev, report, raw_data, size);
2395 return 1;
2396}
2397
2398#ifdef CONFIG_PM
2399static int picolcd_suspend(struct hid_device *hdev, pm_message_t message)
2400{
2401 if (PMSG_IS_AUTO(message))
2402 return 0;
2403
2404 picolcd_suspend_backlight(hid_get_drvdata(hdev));
2405 dbg_hid(PICOLCD_NAME " device ready for suspend\n");
2406 return 0;
2407}
2408
2409static int picolcd_resume(struct hid_device *hdev)
2410{
2411 int ret;
2412 ret = picolcd_resume_backlight(hid_get_drvdata(hdev));
2413 if (ret)
2414 dbg_hid(PICOLCD_NAME " restoring backlight failed: %d\n", ret);
2415 return 0;
2416}
2417
2418static int picolcd_reset_resume(struct hid_device *hdev)
2419{
2420 int ret;
2421 ret = picolcd_reset(hdev);
2422 if (ret)
2423 dbg_hid(PICOLCD_NAME " resetting our device failed: %d\n", ret);
2424 ret = picolcd_fb_reset(hid_get_drvdata(hdev), 0);
2425 if (ret)
2426 dbg_hid(PICOLCD_NAME " restoring framebuffer content failed: %d\n", ret);
2427 ret = picolcd_resume_lcd(hid_get_drvdata(hdev));
2428 if (ret)
2429 dbg_hid(PICOLCD_NAME " restoring lcd failed: %d\n", ret);
2430 ret = picolcd_resume_backlight(hid_get_drvdata(hdev));
2431 if (ret)
2432 dbg_hid(PICOLCD_NAME " restoring backlight failed: %d\n", ret);
2433 picolcd_leds_set(hid_get_drvdata(hdev));
2434 return 0;
2435}
2436#endif
2437
2438/* initialize keypad input device */
2439static int picolcd_init_keys(struct picolcd_data *data,
2440 struct hid_report *report)
2441{
2442 struct hid_device *hdev = data->hdev;
2443 struct input_dev *idev;
2444 int error, i;
2445
2446 if (!report)
2447 return -ENODEV;
2448 if (report->maxfield != 1 || report->field[0]->report_count != 2 ||
2449 report->field[0]->report_size != 8) {
2450 hid_err(hdev, "unsupported KEY_STATE report\n");
2451 return -EINVAL;
2452 }
2453
2454 idev = input_allocate_device();
2455 if (idev == NULL) {
2456 hid_err(hdev, "failed to allocate input device\n");
2457 return -ENOMEM;
2458 }
2459 input_set_drvdata(idev, hdev);
2460 memcpy(data->keycode, def_keymap, sizeof(def_keymap));
2461 idev->name = hdev->name;
2462 idev->phys = hdev->phys;
2463 idev->uniq = hdev->uniq;
2464 idev->id.bustype = hdev->bus;
2465 idev->id.vendor = hdev->vendor;
2466 idev->id.product = hdev->product;
2467 idev->id.version = hdev->version;
2468 idev->dev.parent = hdev->dev.parent;
2469 idev->keycode = &data->keycode;
2470 idev->keycodemax = PICOLCD_KEYS;
2471 idev->keycodesize = sizeof(data->keycode[0]);
2472 input_set_capability(idev, EV_MSC, MSC_SCAN);
2473 set_bit(EV_REP, idev->evbit);
2474 for (i = 0; i < PICOLCD_KEYS; i++)
2475 input_set_capability(idev, EV_KEY, data->keycode[i]);
2476 error = input_register_device(idev);
2477 if (error) {
2478 hid_err(hdev, "error registering the input device\n");
2479 input_free_device(idev);
2480 return error;
2481 }
2482 data->input_keys = idev;
2483 return 0;
2484}
2485
2486static void picolcd_exit_keys(struct picolcd_data *data)
2487{
2488 struct input_dev *idev = data->input_keys;
2489
2490 data->input_keys = NULL;
2491 if (idev)
2492 input_unregister_device(idev);
2493}
2494
2495/* initialize CIR input device */
2496static inline int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report)
2497{
2498 /* support not implemented yet */
2499 return 0;
2500}
2501
2502static inline void picolcd_exit_cir(struct picolcd_data *data)
2503{
2504}
2505
2506static int picolcd_probe_lcd(struct hid_device *hdev, struct picolcd_data *data)
2507{
2508 int error;
2509
2510 error = picolcd_check_version(hdev);
2511 if (error)
2512 return error;
2513
2514 if (data->version[0] != 0 && data->version[1] != 3)
2515 hid_info(hdev, "Device with untested firmware revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2516 dev_name(&hdev->dev));
2517
2518 /* Setup keypad input device */
2519 error = picolcd_init_keys(data, picolcd_in_report(REPORT_KEY_STATE, hdev));
2520 if (error)
2521 goto err;
2522
2523 /* Setup CIR input device */
2524 error = picolcd_init_cir(data, picolcd_in_report(REPORT_IR_DATA, hdev));
2525 if (error)
2526 goto err;
2527
2528 /* Set up the framebuffer device */
2529 error = picolcd_init_framebuffer(data);
2530 if (error)
2531 goto err;
2532
2533 /* Setup lcd class device */
2534 error = picolcd_init_lcd(data, picolcd_out_report(REPORT_CONTRAST, hdev));
2535 if (error)
2536 goto err;
2537
2538 /* Setup backlight class device */
2539 error = picolcd_init_backlight(data, picolcd_out_report(REPORT_BRIGHTNESS, hdev));
2540 if (error)
2541 goto err;
2542
2543 /* Setup the LED class devices */
2544 error = picolcd_init_leds(data, picolcd_out_report(REPORT_LED_STATE, hdev));
2545 if (error)
2546 goto err;
2547
2548 picolcd_init_devfs(data, picolcd_out_report(REPORT_EE_READ, hdev),
2549 picolcd_out_report(REPORT_EE_WRITE, hdev),
2550 picolcd_out_report(REPORT_READ_MEMORY, hdev),
2551 picolcd_out_report(REPORT_WRITE_MEMORY, hdev),
2552 picolcd_out_report(REPORT_RESET, hdev));
2553 return 0;
2554err:
2555 picolcd_exit_leds(data);
2556 picolcd_exit_backlight(data);
2557 picolcd_exit_lcd(data);
2558 picolcd_exit_framebuffer(data);
2559 picolcd_exit_cir(data);
2560 picolcd_exit_keys(data);
2561 return error;
2562}
2563
2564static int picolcd_probe_bootloader(struct hid_device *hdev, struct picolcd_data *data)
2565{
2566 int error;
2567
2568 error = picolcd_check_version(hdev);
2569 if (error)
2570 return error;
2571
2572 if (data->version[0] != 1 && data->version[1] != 0)
2573 hid_info(hdev, "Device with untested bootloader revision, please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n",
2574 dev_name(&hdev->dev));
2575
2576 picolcd_init_devfs(data, NULL, NULL,
2577 picolcd_out_report(REPORT_BL_READ_MEMORY, hdev),
2578 picolcd_out_report(REPORT_BL_WRITE_MEMORY, hdev), NULL);
2579 return 0;
2580}
2581
2582static int picolcd_probe(struct hid_device *hdev,
2583 const struct hid_device_id *id)
2584{
2585 struct picolcd_data *data;
2586 int error = -ENOMEM;
2587
2588 dbg_hid(PICOLCD_NAME " hardware probe...\n");
2589
2590 /*
2591 * Let's allocate the picolcd data structure, set some reasonable
2592 * defaults, and associate it with the device
2593 */
2594 data = kzalloc(sizeof(struct picolcd_data), GFP_KERNEL);
2595 if (data == NULL) {
2596 hid_err(hdev, "can't allocate space for Minibox PicoLCD device data\n");
2597 error = -ENOMEM;
2598 goto err_no_cleanup;
2599 }
2600
2601 spin_lock_init(&data->lock);
2602 mutex_init(&data->mutex);
2603 data->hdev = hdev;
2604 data->opmode_delay = 5000;
2605 if (hdev->product == USB_DEVICE_ID_PICOLCD_BOOTLOADER)
2606 data->status |= PICOLCD_BOOTLOADER;
2607 hid_set_drvdata(hdev, data);
2608
2609 /* Parse the device reports and start it up */
2610 error = hid_parse(hdev);
2611 if (error) {
2612 hid_err(hdev, "device report parse failed\n");
2613 goto err_cleanup_data;
2614 }
2615
2616 error = hid_hw_start(hdev, 0);
2617 if (error) {
2618 hid_err(hdev, "hardware start failed\n");
2619 goto err_cleanup_data;
2620 }
2621
2622 error = hid_hw_open(hdev);
2623 if (error) {
2624 hid_err(hdev, "failed to open input interrupt pipe for key and IR events\n");
2625 goto err_cleanup_hid_hw;
2626 }
2627
2628 error = device_create_file(&hdev->dev, &dev_attr_operation_mode_delay);
2629 if (error) {
2630 hid_err(hdev, "failed to create sysfs attributes\n");
2631 goto err_cleanup_hid_ll;
2632 }
2633
2634 error = device_create_file(&hdev->dev, &dev_attr_operation_mode);
2635 if (error) {
2636 hid_err(hdev, "failed to create sysfs attributes\n");
2637 goto err_cleanup_sysfs1;
2638 }
2639
2640 if (data->status & PICOLCD_BOOTLOADER)
2641 error = picolcd_probe_bootloader(hdev, data);
2642 else
2643 error = picolcd_probe_lcd(hdev, data);
2644 if (error)
2645 goto err_cleanup_sysfs2;
2646
2647 dbg_hid(PICOLCD_NAME " activated and initialized\n");
2648 return 0;
2649
2650err_cleanup_sysfs2:
2651 device_remove_file(&hdev->dev, &dev_attr_operation_mode);
2652err_cleanup_sysfs1:
2653 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay);
2654err_cleanup_hid_ll:
2655 hid_hw_close(hdev);
2656err_cleanup_hid_hw:
2657 hid_hw_stop(hdev);
2658err_cleanup_data:
2659 kfree(data);
2660err_no_cleanup:
2661 hid_set_drvdata(hdev, NULL);
2662
2663 return error;
2664}
2665
2666static void picolcd_remove(struct hid_device *hdev)
2667{
2668 struct picolcd_data *data = hid_get_drvdata(hdev);
2669 unsigned long flags;
2670
2671 dbg_hid(PICOLCD_NAME " hardware remove...\n");
2672 spin_lock_irqsave(&data->lock, flags);
2673 data->status |= PICOLCD_FAILED;
2674 spin_unlock_irqrestore(&data->lock, flags);
2675#ifdef CONFIG_HID_PICOLCD_FB
2676 /* short-circuit FB as early as possible in order to
2677 * avoid long delays if we host console.
2678 */
2679 if (data->fb_info)
2680 data->fb_info->par = NULL;
2681#endif
2682
2683 picolcd_exit_devfs(data);
2684 device_remove_file(&hdev->dev, &dev_attr_operation_mode);
2685 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay);
2686 hid_hw_close(hdev);
2687 hid_hw_stop(hdev);
2688 hid_set_drvdata(hdev, NULL);
2689
2690 /* Shortcut potential pending reply that will never arrive */
2691 spin_lock_irqsave(&data->lock, flags);
2692 if (data->pending)
2693 complete(&data->pending->ready);
2694 spin_unlock_irqrestore(&data->lock, flags);
2695
2696 /* Cleanup LED */
2697 picolcd_exit_leds(data);
2698 /* Clean up the framebuffer */
2699 picolcd_exit_backlight(data);
2700 picolcd_exit_lcd(data);
2701 picolcd_exit_framebuffer(data);
2702 /* Cleanup input */
2703 picolcd_exit_cir(data);
2704 picolcd_exit_keys(data);
2705
2706 mutex_destroy(&data->mutex);
2707 /* Finally, clean up the picolcd data itself */
2708 kfree(data);
2709}
2710
2711static const struct hid_device_id picolcd_devices[] = {
2712 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
2713 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
2714 { }
2715};
2716MODULE_DEVICE_TABLE(hid, picolcd_devices);
2717
2718static struct hid_driver picolcd_driver = {
2719 .name = "hid-picolcd",
2720 .id_table = picolcd_devices,
2721 .probe = picolcd_probe,
2722 .remove = picolcd_remove,
2723 .raw_event = picolcd_raw_event,
2724#ifdef CONFIG_PM
2725 .suspend = picolcd_suspend,
2726 .resume = picolcd_resume,
2727 .reset_resume = picolcd_reset_resume,
2728#endif
2729};
2730
2731static int __init picolcd_init(void)
2732{
2733 return hid_register_driver(&picolcd_driver);
2734}
2735
2736static void __exit picolcd_exit(void)
2737{
2738 hid_unregister_driver(&picolcd_driver);
2739#ifdef CONFIG_HID_PICOLCD_FB
2740 flush_work_sync(&picolcd_fb_cleanup);
2741 WARN_ON(fb_pending);
2742#endif
2743}
2744
2745module_init(picolcd_init);
2746module_exit(picolcd_exit);
2747MODULE_DESCRIPTION("Minibox graphics PicoLCD Driver");
2748MODULE_LICENSE("GPL v2");
diff --git a/drivers/hid/hid-picolcd.h b/drivers/hid/hid-picolcd.h
new file mode 100644
index 000000000000..020cef69f6a1
--- /dev/null
+++ b/drivers/hid/hid-picolcd.h
@@ -0,0 +1,309 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#define PICOLCD_NAME "PicoLCD (graphic)"
21
22/* Report numbers */
23#define REPORT_ERROR_CODE 0x10 /* LCD: IN[16] */
24#define ERR_SUCCESS 0x00
25#define ERR_PARAMETER_MISSING 0x01
26#define ERR_DATA_MISSING 0x02
27#define ERR_BLOCK_READ_ONLY 0x03
28#define ERR_BLOCK_NOT_ERASABLE 0x04
29#define ERR_BLOCK_TOO_BIG 0x05
30#define ERR_SECTION_OVERFLOW 0x06
31#define ERR_INVALID_CMD_LEN 0x07
32#define ERR_INVALID_DATA_LEN 0x08
33#define REPORT_KEY_STATE 0x11 /* LCD: IN[2] */
34#define REPORT_IR_DATA 0x21 /* LCD: IN[63] */
35#define REPORT_EE_DATA 0x32 /* LCD: IN[63] */
36#define REPORT_MEMORY 0x41 /* LCD: IN[63] */
37#define REPORT_LED_STATE 0x81 /* LCD: OUT[1] */
38#define REPORT_BRIGHTNESS 0x91 /* LCD: OUT[1] */
39#define REPORT_CONTRAST 0x92 /* LCD: OUT[1] */
40#define REPORT_RESET 0x93 /* LCD: OUT[2] */
41#define REPORT_LCD_CMD 0x94 /* LCD: OUT[63] */
42#define REPORT_LCD_DATA 0x95 /* LCD: OUT[63] */
43#define REPORT_LCD_CMD_DATA 0x96 /* LCD: OUT[63] */
44#define REPORT_EE_READ 0xa3 /* LCD: OUT[63] */
45#define REPORT_EE_WRITE 0xa4 /* LCD: OUT[63] */
46#define REPORT_ERASE_MEMORY 0xb2 /* LCD: OUT[2] */
47#define REPORT_READ_MEMORY 0xb3 /* LCD: OUT[3] */
48#define REPORT_WRITE_MEMORY 0xb4 /* LCD: OUT[63] */
49#define REPORT_SPLASH_RESTART 0xc1 /* LCD: OUT[1] */
50#define REPORT_EXIT_KEYBOARD 0xef /* LCD: OUT[2] */
51#define REPORT_VERSION 0xf1 /* LCD: IN[2],OUT[1] Bootloader: IN[2],OUT[1] */
52#define REPORT_BL_ERASE_MEMORY 0xf2 /* Bootloader: IN[36],OUT[4] */
53#define REPORT_BL_READ_MEMORY 0xf3 /* Bootloader: IN[36],OUT[4] */
54#define REPORT_BL_WRITE_MEMORY 0xf4 /* Bootloader: IN[36],OUT[36] */
55#define REPORT_DEVID 0xf5 /* LCD: IN[5], OUT[1] Bootloader: IN[5],OUT[1] */
56#define REPORT_SPLASH_SIZE 0xf6 /* LCD: IN[4], OUT[1] */
57#define REPORT_HOOK_VERSION 0xf7 /* LCD: IN[2], OUT[1] */
58#define REPORT_EXIT_FLASHER 0xff /* Bootloader: OUT[2] */
59
60/* Description of in-progress IO operation, used for operations
61 * that trigger response from device */
62struct picolcd_pending {
63 struct hid_report *out_report;
64 struct hid_report *in_report;
65 struct completion ready;
66 int raw_size;
67 u8 raw_data[64];
68};
69
70
71#define PICOLCD_KEYS 17
72
73/* Per device data structure */
74struct picolcd_data {
75 struct hid_device *hdev;
76#ifdef CONFIG_DEBUG_FS
77 struct dentry *debug_reset;
78 struct dentry *debug_eeprom;
79 struct dentry *debug_flash;
80 struct mutex mutex_flash;
81 int addr_sz;
82#endif
83 u8 version[2];
84 unsigned short opmode_delay;
85 /* input stuff */
86 u8 pressed_keys[2];
87 struct input_dev *input_keys;
88#ifdef CONFIG_HID_PICOLCD_CIR
89 struct rc_dev *rc_dev;
90#endif
91 unsigned short keycode[PICOLCD_KEYS];
92
93#ifdef CONFIG_HID_PICOLCD_FB
94 /* Framebuffer stuff */
95 struct fb_info *fb_info;
96#endif /* CONFIG_HID_PICOLCD_FB */
97#ifdef CONFIG_HID_PICOLCD_LCD
98 struct lcd_device *lcd;
99 u8 lcd_contrast;
100#endif /* CONFIG_HID_PICOLCD_LCD */
101#ifdef CONFIG_HID_PICOLCD_BACKLIGHT
102 struct backlight_device *backlight;
103 u8 lcd_brightness;
104 u8 lcd_power;
105#endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
106#ifdef CONFIG_HID_PICOLCD_LEDS
107 /* LED stuff */
108 u8 led_state;
109 struct led_classdev *led[8];
110#endif /* CONFIG_HID_PICOLCD_LEDS */
111
112 /* Housekeeping stuff */
113 spinlock_t lock;
114 struct mutex mutex;
115 struct picolcd_pending *pending;
116 int status;
117#define PICOLCD_BOOTLOADER 1
118#define PICOLCD_FAILED 2
119#define PICOLCD_CIR_SHUN 4
120};
121
122#ifdef CONFIG_HID_PICOLCD_FB
123struct picolcd_fb_data {
124 /* Framebuffer stuff */
125 spinlock_t lock;
126 struct picolcd_data *picolcd;
127 u8 update_rate;
128 u8 bpp;
129 u8 force;
130 u8 ready;
131 u8 *vbitmap; /* local copy of what was sent to PicoLCD */
132 u8 *bitmap; /* framebuffer */
133};
134#endif /* CONFIG_HID_PICOLCD_FB */
135
136/* Find a given report */
137#define picolcd_in_report(id, dev) picolcd_report(id, dev, HID_INPUT_REPORT)
138#define picolcd_out_report(id, dev) picolcd_report(id, dev, HID_OUTPUT_REPORT)
139
140struct hid_report *picolcd_report(int id, struct hid_device *hdev, int dir);
141
142#ifdef CONFIG_DEBUG_FS
143void picolcd_debug_out_report(struct picolcd_data *data,
144 struct hid_device *hdev, struct hid_report *report);
145#define usbhid_submit_report(a, b, c) \
146 do { \
147 picolcd_debug_out_report(hid_get_drvdata(a), a, b); \
148 usbhid_submit_report(a, b, c); \
149 } while (0)
150
151void picolcd_debug_raw_event(struct picolcd_data *data,
152 struct hid_device *hdev, struct hid_report *report,
153 u8 *raw_data, int size);
154
155void picolcd_init_devfs(struct picolcd_data *data,
156 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
157 struct hid_report *flash_r, struct hid_report *flash_w,
158 struct hid_report *reset);
159
160void picolcd_exit_devfs(struct picolcd_data *data);
161#else
162static inline void picolcd_debug_out_report(struct picolcd_data *data,
163 struct hid_device *hdev, struct hid_report *report)
164{
165}
166static inline void picolcd_debug_raw_event(struct picolcd_data *data,
167 struct hid_device *hdev, struct hid_report *report,
168 u8 *raw_data, int size)
169{
170}
171static inline void picolcd_init_devfs(struct picolcd_data *data,
172 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
173 struct hid_report *flash_r, struct hid_report *flash_w,
174 struct hid_report *reset)
175{
176}
177static inline void picolcd_exit_devfs(struct picolcd_data *data)
178{
179}
180#endif /* CONFIG_DEBUG_FS */
181
182
183#ifdef CONFIG_HID_PICOLCD_FB
184int picolcd_fb_reset(struct picolcd_data *data, int clear);
185
186int picolcd_init_framebuffer(struct picolcd_data *data);
187
188void picolcd_exit_framebuffer(struct picolcd_data *data);
189
190void picolcd_fb_refresh(struct picolcd_data *data);
191#define picolcd_fbinfo(d) ((d)->fb_info)
192#else
193static inline int picolcd_fb_reset(struct picolcd_data *data, int clear)
194{
195 return 0;
196}
197static inline int picolcd_init_framebuffer(struct picolcd_data *data)
198{
199 return 0;
200}
201static inline void picolcd_exit_framebuffer(struct picolcd_data *data)
202{
203}
204static inline void picolcd_fb_refresh(struct picolcd_data *data)
205{
206}
207#define picolcd_fbinfo(d) NULL
208#endif /* CONFIG_HID_PICOLCD_FB */
209
210
211#ifdef CONFIG_HID_PICOLCD_BACKLIGHT
212int picolcd_init_backlight(struct picolcd_data *data,
213 struct hid_report *report);
214
215void picolcd_exit_backlight(struct picolcd_data *data);
216
217int picolcd_resume_backlight(struct picolcd_data *data);
218
219void picolcd_suspend_backlight(struct picolcd_data *data);
220#else
221static inline int picolcd_init_backlight(struct picolcd_data *data,
222 struct hid_report *report)
223{
224 return 0;
225}
226static inline void picolcd_exit_backlight(struct picolcd_data *data)
227{
228}
229static inline int picolcd_resume_backlight(struct picolcd_data *data)
230{
231 return 0;
232}
233static inline void picolcd_suspend_backlight(struct picolcd_data *data)
234{
235}
236
237#endif /* CONFIG_HID_PICOLCD_BACKLIGHT */
238
239
240#ifdef CONFIG_HID_PICOLCD_LCD
241int picolcd_init_lcd(struct picolcd_data *data,
242 struct hid_report *report);
243
244void picolcd_exit_lcd(struct picolcd_data *data);
245
246int picolcd_resume_lcd(struct picolcd_data *data);
247#else
248static inline int picolcd_init_lcd(struct picolcd_data *data,
249 struct hid_report *report)
250{
251 return 0;
252}
253static inline void picolcd_exit_lcd(struct picolcd_data *data)
254{
255}
256static inline int picolcd_resume_lcd(struct picolcd_data *data)
257{
258 return 0;
259}
260#endif /* CONFIG_HID_PICOLCD_LCD */
261
262
263#ifdef CONFIG_HID_PICOLCD_LEDS
264int picolcd_init_leds(struct picolcd_data *data,
265 struct hid_report *report);
266
267void picolcd_exit_leds(struct picolcd_data *data);
268
269void picolcd_leds_set(struct picolcd_data *data);
270#else
271static inline int picolcd_init_leds(struct picolcd_data *data,
272 struct hid_report *report)
273{
274 return 0;
275}
276static inline void picolcd_exit_leds(struct picolcd_data *data)
277{
278}
279static inline void picolcd_leds_set(struct picolcd_data *data)
280{
281}
282#endif /* CONFIG_HID_PICOLCD_LEDS */
283
284
285#ifdef CONFIG_HID_PICOLCD_CIR
286int picolcd_raw_cir(struct picolcd_data *data,
287 struct hid_report *report, u8 *raw_data, int size);
288
289int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report);
290
291void picolcd_exit_cir(struct picolcd_data *data);
292#else
293static inline int picolcd_raw_cir(struct picolcd_data *data,
294 struct hid_report *report, u8 *raw_data, int size)
295{
296 return 1;
297}
298static inline int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report)
299{
300 return 0;
301}
302static inline void picolcd_exit_cir(struct picolcd_data *data)
303{
304}
305#endif /* CONFIG_HID_PICOLCD_LIRC */
306
307int picolcd_reset(struct hid_device *hdev);
308struct picolcd_pending *picolcd_send_and_wait(struct hid_device *hdev,
309 int report_id, const u8 *raw_data, int size);
diff --git a/drivers/hid/hid-picolcd_backlight.c b/drivers/hid/hid-picolcd_backlight.c
new file mode 100644
index 000000000000..b91f30945f9c
--- /dev/null
+++ b/drivers/hid/hid-picolcd_backlight.c
@@ -0,0 +1,122 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include "usbhid/usbhid.h"
22#include <linux/usb.h>
23
24#include <linux/fb.h>
25#include <linux/backlight.h>
26
27#include "hid-picolcd.h"
28
29static int picolcd_get_brightness(struct backlight_device *bdev)
30{
31 struct picolcd_data *data = bl_get_data(bdev);
32 return data->lcd_brightness;
33}
34
35static int picolcd_set_brightness(struct backlight_device *bdev)
36{
37 struct picolcd_data *data = bl_get_data(bdev);
38 struct hid_report *report = picolcd_out_report(REPORT_BRIGHTNESS, data->hdev);
39 unsigned long flags;
40
41 if (!report || report->maxfield != 1 || report->field[0]->report_count != 1)
42 return -ENODEV;
43
44 data->lcd_brightness = bdev->props.brightness & 0x0ff;
45 data->lcd_power = bdev->props.power;
46 spin_lock_irqsave(&data->lock, flags);
47 hid_set_field(report->field[0], 0, data->lcd_power == FB_BLANK_UNBLANK ? data->lcd_brightness : 0);
48 if (!(data->status & PICOLCD_FAILED))
49 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
50 spin_unlock_irqrestore(&data->lock, flags);
51 return 0;
52}
53
54static int picolcd_check_bl_fb(struct backlight_device *bdev, struct fb_info *fb)
55{
56 return fb && fb == picolcd_fbinfo((struct picolcd_data *)bl_get_data(bdev));
57}
58
59static const struct backlight_ops picolcd_blops = {
60 .update_status = picolcd_set_brightness,
61 .get_brightness = picolcd_get_brightness,
62 .check_fb = picolcd_check_bl_fb,
63};
64
65int picolcd_init_backlight(struct picolcd_data *data, struct hid_report *report)
66{
67 struct device *dev = &data->hdev->dev;
68 struct backlight_device *bdev;
69 struct backlight_properties props;
70 if (!report)
71 return -ENODEV;
72 if (report->maxfield != 1 || report->field[0]->report_count != 1 ||
73 report->field[0]->report_size != 8) {
74 dev_err(dev, "unsupported BRIGHTNESS report");
75 return -EINVAL;
76 }
77
78 memset(&props, 0, sizeof(props));
79 props.type = BACKLIGHT_RAW;
80 props.max_brightness = 0xff;
81 bdev = backlight_device_register(dev_name(dev), dev, data,
82 &picolcd_blops, &props);
83 if (IS_ERR(bdev)) {
84 dev_err(dev, "failed to register backlight\n");
85 return PTR_ERR(bdev);
86 }
87 bdev->props.brightness = 0xff;
88 data->lcd_brightness = 0xff;
89 data->backlight = bdev;
90 picolcd_set_brightness(bdev);
91 return 0;
92}
93
94void picolcd_exit_backlight(struct picolcd_data *data)
95{
96 struct backlight_device *bdev = data->backlight;
97
98 data->backlight = NULL;
99 if (bdev)
100 backlight_device_unregister(bdev);
101}
102
103int picolcd_resume_backlight(struct picolcd_data *data)
104{
105 if (!data->backlight)
106 return 0;
107 return picolcd_set_brightness(data->backlight);
108}
109
110#ifdef CONFIG_PM
111void picolcd_suspend_backlight(struct picolcd_data *data)
112{
113 int bl_power = data->lcd_power;
114 if (!data->backlight)
115 return;
116
117 data->backlight->props.power = FB_BLANK_POWERDOWN;
118 picolcd_set_brightness(data->backlight);
119 data->lcd_power = data->backlight->props.power = bl_power;
120}
121#endif /* CONFIG_PM */
122
diff --git a/drivers/hid/hid-picolcd_cir.c b/drivers/hid/hid-picolcd_cir.c
new file mode 100644
index 000000000000..13ca9191b630
--- /dev/null
+++ b/drivers/hid/hid-picolcd_cir.c
@@ -0,0 +1,152 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include <linux/hid-debug.h>
22#include <linux/input.h>
23#include "hid-ids.h"
24#include "usbhid/usbhid.h"
25#include <linux/usb.h>
26
27#include <linux/fb.h>
28#include <linux/vmalloc.h>
29#include <linux/backlight.h>
30#include <linux/lcd.h>
31
32#include <linux/leds.h>
33
34#include <linux/seq_file.h>
35#include <linux/debugfs.h>
36
37#include <linux/completion.h>
38#include <linux/uaccess.h>
39#include <linux/module.h>
40#include <media/rc-core.h>
41
42#include "hid-picolcd.h"
43
44
45int picolcd_raw_cir(struct picolcd_data *data,
46 struct hid_report *report, u8 *raw_data, int size)
47{
48 unsigned long flags;
49 int i, w, sz;
50 DEFINE_IR_RAW_EVENT(rawir);
51
52 /* ignore if rc_dev is NULL or status is shunned */
53 spin_lock_irqsave(&data->lock, flags);
54 if (!data->rc_dev || (data->status & PICOLCD_CIR_SHUN)) {
55 spin_unlock_irqrestore(&data->lock, flags);
56 return 1;
57 }
58 spin_unlock_irqrestore(&data->lock, flags);
59
60 /* PicoLCD USB packets contain 16-bit intervals in network order,
61 * with value negated for pulse. Intervals are in microseconds.
62 *
63 * Note: some userspace LIRC code for PicoLCD says negated values
64 * for space - is it a matter of IR chip? (pulse for my TSOP2236)
65 *
66 * In addition, the first interval seems to be around 15000 + base
67 * interval for non-first report of IR data - thus the quirk below
68 * to get RC_CODE to understand Sony and JVC remotes I have at hand
69 */
70 sz = size > 0 ? min((int)raw_data[0], size-1) : 0;
71 for (i = 0; i+1 < sz; i += 2) {
72 init_ir_raw_event(&rawir);
73 w = (raw_data[i] << 8) | (raw_data[i+1]);
74 rawir.pulse = !!(w & 0x8000);
75 rawir.duration = US_TO_NS(rawir.pulse ? (65536 - w) : w);
76 /* Quirk!! - see above */
77 if (i == 0 && rawir.duration > 15000000)
78 rawir.duration -= 15000000;
79 ir_raw_event_store(data->rc_dev, &rawir);
80 }
81 ir_raw_event_handle(data->rc_dev);
82
83 return 1;
84}
85
86static int picolcd_cir_open(struct rc_dev *dev)
87{
88 struct picolcd_data *data = dev->priv;
89 unsigned long flags;
90
91 spin_lock_irqsave(&data->lock, flags);
92 data->status &= ~PICOLCD_CIR_SHUN;
93 spin_unlock_irqrestore(&data->lock, flags);
94 return 0;
95}
96
97static void picolcd_cir_close(struct rc_dev *dev)
98{
99 struct picolcd_data *data = dev->priv;
100 unsigned long flags;
101
102 spin_lock_irqsave(&data->lock, flags);
103 data->status |= PICOLCD_CIR_SHUN;
104 spin_unlock_irqrestore(&data->lock, flags);
105}
106
107/* initialize CIR input device */
108int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report)
109{
110 struct rc_dev *rdev;
111 int ret = 0;
112
113 rdev = rc_allocate_device();
114 if (!rdev)
115 return -ENOMEM;
116
117 rdev->priv = data;
118 rdev->driver_type = RC_DRIVER_IR_RAW;
119 rdev->allowed_protos = RC_TYPE_ALL;
120 rdev->open = picolcd_cir_open;
121 rdev->close = picolcd_cir_close;
122 rdev->input_name = data->hdev->name;
123 rdev->input_phys = data->hdev->phys;
124 rdev->input_id.bustype = data->hdev->bus;
125 rdev->input_id.vendor = data->hdev->vendor;
126 rdev->input_id.product = data->hdev->product;
127 rdev->input_id.version = data->hdev->version;
128 rdev->dev.parent = &data->hdev->dev;
129 rdev->driver_name = PICOLCD_NAME;
130 rdev->map_name = RC_MAP_RC6_MCE;
131 rdev->timeout = MS_TO_NS(100);
132 rdev->rx_resolution = US_TO_NS(1);
133
134 ret = rc_register_device(rdev);
135 if (ret)
136 goto err;
137 data->rc_dev = rdev;
138 return 0;
139
140err:
141 rc_free_device(rdev);
142 return ret;
143}
144
145void picolcd_exit_cir(struct picolcd_data *data)
146{
147 struct rc_dev *rdev = data->rc_dev;
148
149 data->rc_dev = NULL;
150 rc_unregister_device(rdev);
151}
152
diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
new file mode 100644
index 000000000000..86df26e58aba
--- /dev/null
+++ b/drivers/hid/hid-picolcd_core.c
@@ -0,0 +1,689 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include <linux/hid-debug.h>
22#include <linux/input.h>
23#include "hid-ids.h"
24#include "usbhid/usbhid.h"
25#include <linux/usb.h>
26
27#include <linux/fb.h>
28#include <linux/vmalloc.h>
29
30#include <linux/completion.h>
31#include <linux/uaccess.h>
32#include <linux/module.h>
33
34#include "hid-picolcd.h"
35
36
37/* Input device
38 *
39 * The PicoLCD has an IR receiver header, a built-in keypad with 5 keys
40 * and header for 4x4 key matrix. The built-in keys are part of the matrix.
41 */
42static const unsigned short def_keymap[PICOLCD_KEYS] = {
43 KEY_RESERVED, /* none */
44 KEY_BACK, /* col 4 + row 1 */
45 KEY_HOMEPAGE, /* col 3 + row 1 */
46 KEY_RESERVED, /* col 2 + row 1 */
47 KEY_RESERVED, /* col 1 + row 1 */
48 KEY_SCROLLUP, /* col 4 + row 2 */
49 KEY_OK, /* col 3 + row 2 */
50 KEY_SCROLLDOWN, /* col 2 + row 2 */
51 KEY_RESERVED, /* col 1 + row 2 */
52 KEY_RESERVED, /* col 4 + row 3 */
53 KEY_RESERVED, /* col 3 + row 3 */
54 KEY_RESERVED, /* col 2 + row 3 */
55 KEY_RESERVED, /* col 1 + row 3 */
56 KEY_RESERVED, /* col 4 + row 4 */
57 KEY_RESERVED, /* col 3 + row 4 */
58 KEY_RESERVED, /* col 2 + row 4 */
59 KEY_RESERVED, /* col 1 + row 4 */
60};
61
62
63/* Find a given report */
64struct hid_report *picolcd_report(int id, struct hid_device *hdev, int dir)
65{
66 struct list_head *feature_report_list = &hdev->report_enum[dir].report_list;
67 struct hid_report *report = NULL;
68
69 list_for_each_entry(report, feature_report_list, list) {
70 if (report->id == id)
71 return report;
72 }
73 hid_warn(hdev, "No report with id 0x%x found\n", id);
74 return NULL;
75}
76
77/* Submit a report and wait for a reply from device - if device fades away
78 * or does not respond in time, return NULL */
79struct picolcd_pending *picolcd_send_and_wait(struct hid_device *hdev,
80 int report_id, const u8 *raw_data, int size)
81{
82 struct picolcd_data *data = hid_get_drvdata(hdev);
83 struct picolcd_pending *work;
84 struct hid_report *report = picolcd_out_report(report_id, hdev);
85 unsigned long flags;
86 int i, j, k;
87
88 if (!report || !data)
89 return NULL;
90 if (data->status & PICOLCD_FAILED)
91 return NULL;
92 work = kzalloc(sizeof(*work), GFP_KERNEL);
93 if (!work)
94 return NULL;
95
96 init_completion(&work->ready);
97 work->out_report = report;
98 work->in_report = NULL;
99 work->raw_size = 0;
100
101 mutex_lock(&data->mutex);
102 spin_lock_irqsave(&data->lock, flags);
103 for (i = k = 0; i < report->maxfield; i++)
104 for (j = 0; j < report->field[i]->report_count; j++) {
105 hid_set_field(report->field[i], j, k < size ? raw_data[k] : 0);
106 k++;
107 }
108 if (data->status & PICOLCD_FAILED) {
109 kfree(work);
110 work = NULL;
111 } else {
112 data->pending = work;
113 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
114 spin_unlock_irqrestore(&data->lock, flags);
115 wait_for_completion_interruptible_timeout(&work->ready, HZ*2);
116 spin_lock_irqsave(&data->lock, flags);
117 data->pending = NULL;
118 }
119 spin_unlock_irqrestore(&data->lock, flags);
120 mutex_unlock(&data->mutex);
121 return work;
122}
123
124/*
125 * input class device
126 */
127static int picolcd_raw_keypad(struct picolcd_data *data,
128 struct hid_report *report, u8 *raw_data, int size)
129{
130 /*
131 * Keypad event
132 * First and second data bytes list currently pressed keys,
133 * 0x00 means no key and at most 2 keys may be pressed at same time
134 */
135 int i, j;
136
137 /* determine newly pressed keys */
138 for (i = 0; i < size; i++) {
139 unsigned int key_code;
140 if (raw_data[i] == 0)
141 continue;
142 for (j = 0; j < sizeof(data->pressed_keys); j++)
143 if (data->pressed_keys[j] == raw_data[i])
144 goto key_already_down;
145 for (j = 0; j < sizeof(data->pressed_keys); j++)
146 if (data->pressed_keys[j] == 0) {
147 data->pressed_keys[j] = raw_data[i];
148 break;
149 }
150 input_event(data->input_keys, EV_MSC, MSC_SCAN, raw_data[i]);
151 if (raw_data[i] < PICOLCD_KEYS)
152 key_code = data->keycode[raw_data[i]];
153 else
154 key_code = KEY_UNKNOWN;
155 if (key_code != KEY_UNKNOWN) {
156 dbg_hid(PICOLCD_NAME " got key press for %u:%d",
157 raw_data[i], key_code);
158 input_report_key(data->input_keys, key_code, 1);
159 }
160 input_sync(data->input_keys);
161key_already_down:
162 continue;
163 }
164
165 /* determine newly released keys */
166 for (j = 0; j < sizeof(data->pressed_keys); j++) {
167 unsigned int key_code;
168 if (data->pressed_keys[j] == 0)
169 continue;
170 for (i = 0; i < size; i++)
171 if (data->pressed_keys[j] == raw_data[i])
172 goto key_still_down;
173 input_event(data->input_keys, EV_MSC, MSC_SCAN, data->pressed_keys[j]);
174 if (data->pressed_keys[j] < PICOLCD_KEYS)
175 key_code = data->keycode[data->pressed_keys[j]];
176 else
177 key_code = KEY_UNKNOWN;
178 if (key_code != KEY_UNKNOWN) {
179 dbg_hid(PICOLCD_NAME " got key release for %u:%d",
180 data->pressed_keys[j], key_code);
181 input_report_key(data->input_keys, key_code, 0);
182 }
183 input_sync(data->input_keys);
184 data->pressed_keys[j] = 0;
185key_still_down:
186 continue;
187 }
188 return 1;
189}
190
191static int picolcd_check_version(struct hid_device *hdev)
192{
193 struct picolcd_data *data = hid_get_drvdata(hdev);
194 struct picolcd_pending *verinfo;
195 int ret = 0;
196
197 if (!data)
198 return -ENODEV;
199
200 verinfo = picolcd_send_and_wait(hdev, REPORT_VERSION, NULL, 0);
201 if (!verinfo) {
202 hid_err(hdev, "no version response from PicoLCD\n");
203 return -ENODEV;
204 }
205
206 if (verinfo->raw_size == 2) {
207 data->version[0] = verinfo->raw_data[1];
208 data->version[1] = verinfo->raw_data[0];
209 if (data->status & PICOLCD_BOOTLOADER) {
210 hid_info(hdev, "PicoLCD, bootloader version %d.%d\n",
211 verinfo->raw_data[1], verinfo->raw_data[0]);
212 } else {
213 hid_info(hdev, "PicoLCD, firmware version %d.%d\n",
214 verinfo->raw_data[1], verinfo->raw_data[0]);
215 }
216 } else {
217 hid_err(hdev, "confused, got unexpected version response from PicoLCD\n");
218 ret = -EINVAL;
219 }
220 kfree(verinfo);
221 return ret;
222}
223
224/*
225 * Reset our device and wait for answer to VERSION request
226 */
227int picolcd_reset(struct hid_device *hdev)
228{
229 struct picolcd_data *data = hid_get_drvdata(hdev);
230 struct hid_report *report = picolcd_out_report(REPORT_RESET, hdev);
231 unsigned long flags;
232 int error;
233
234 if (!data || !report || report->maxfield != 1)
235 return -ENODEV;
236
237 spin_lock_irqsave(&data->lock, flags);
238 if (hdev->product == USB_DEVICE_ID_PICOLCD_BOOTLOADER)
239 data->status |= PICOLCD_BOOTLOADER;
240
241 /* perform the reset */
242 hid_set_field(report->field[0], 0, 1);
243 if (data->status & PICOLCD_FAILED) {
244 spin_unlock_irqrestore(&data->lock, flags);
245 return -ENODEV;
246 }
247 usbhid_submit_report(hdev, report, USB_DIR_OUT);
248 spin_unlock_irqrestore(&data->lock, flags);
249
250 error = picolcd_check_version(hdev);
251 if (error)
252 return error;
253
254 picolcd_resume_lcd(data);
255 picolcd_resume_backlight(data);
256 picolcd_fb_refresh(data);
257 picolcd_leds_set(data);
258 return 0;
259}
260
261/*
262 * The "operation_mode" sysfs attribute
263 */
264static ssize_t picolcd_operation_mode_show(struct device *dev,
265 struct device_attribute *attr, char *buf)
266{
267 struct picolcd_data *data = dev_get_drvdata(dev);
268
269 if (data->status & PICOLCD_BOOTLOADER)
270 return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n");
271 else
272 return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n");
273}
274
275static ssize_t picolcd_operation_mode_store(struct device *dev,
276 struct device_attribute *attr, const char *buf, size_t count)
277{
278 struct picolcd_data *data = dev_get_drvdata(dev);
279 struct hid_report *report = NULL;
280 size_t cnt = count;
281 int timeout = data->opmode_delay;
282 unsigned long flags;
283
284 if (cnt >= 3 && strncmp("lcd", buf, 3) == 0) {
285 if (data->status & PICOLCD_BOOTLOADER)
286 report = picolcd_out_report(REPORT_EXIT_FLASHER, data->hdev);
287 buf += 3;
288 cnt -= 3;
289 } else if (cnt >= 10 && strncmp("bootloader", buf, 10) == 0) {
290 if (!(data->status & PICOLCD_BOOTLOADER))
291 report = picolcd_out_report(REPORT_EXIT_KEYBOARD, data->hdev);
292 buf += 10;
293 cnt -= 10;
294 }
295 if (!report)
296 return -EINVAL;
297
298 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
299 cnt--;
300 if (cnt != 0)
301 return -EINVAL;
302
303 spin_lock_irqsave(&data->lock, flags);
304 hid_set_field(report->field[0], 0, timeout & 0xff);
305 hid_set_field(report->field[0], 1, (timeout >> 8) & 0xff);
306 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
307 spin_unlock_irqrestore(&data->lock, flags);
308 return count;
309}
310
311static DEVICE_ATTR(operation_mode, 0644, picolcd_operation_mode_show,
312 picolcd_operation_mode_store);
313
314/*
315 * The "operation_mode_delay" sysfs attribute
316 */
317static ssize_t picolcd_operation_mode_delay_show(struct device *dev,
318 struct device_attribute *attr, char *buf)
319{
320 struct picolcd_data *data = dev_get_drvdata(dev);
321
322 return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay);
323}
324
325static ssize_t picolcd_operation_mode_delay_store(struct device *dev,
326 struct device_attribute *attr, const char *buf, size_t count)
327{
328 struct picolcd_data *data = dev_get_drvdata(dev);
329 unsigned u;
330 if (sscanf(buf, "%u", &u) != 1)
331 return -EINVAL;
332 if (u > 30000)
333 return -EINVAL;
334 else
335 data->opmode_delay = u;
336 return count;
337}
338
339static DEVICE_ATTR(operation_mode_delay, 0644, picolcd_operation_mode_delay_show,
340 picolcd_operation_mode_delay_store);
341
342/*
343 * Handle raw report as sent by device
344 */
345static int picolcd_raw_event(struct hid_device *hdev,
346 struct hid_report *report, u8 *raw_data, int size)
347{
348 struct picolcd_data *data = hid_get_drvdata(hdev);
349 unsigned long flags;
350 int ret = 0;
351
352 if (!data)
353 return 1;
354
355 if (report->id == REPORT_KEY_STATE) {
356 if (data->input_keys)
357 ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
358 } else if (report->id == REPORT_IR_DATA) {
359 ret = picolcd_raw_cir(data, report, raw_data+1, size-1);
360 } else {
361 spin_lock_irqsave(&data->lock, flags);
362 /*
363 * We let the caller of picolcd_send_and_wait() check if the
364 * report we got is one of the expected ones or not.
365 */
366 if (data->pending) {
367 memcpy(data->pending->raw_data, raw_data+1, size-1);
368 data->pending->raw_size = size-1;
369 data->pending->in_report = report;
370 complete(&data->pending->ready);
371 }
372 spin_unlock_irqrestore(&data->lock, flags);
373 }
374
375 picolcd_debug_raw_event(data, hdev, report, raw_data, size);
376 return 1;
377}
378
379#ifdef CONFIG_PM
380static int picolcd_suspend(struct hid_device *hdev, pm_message_t message)
381{
382 if (PMSG_IS_AUTO(message))
383 return 0;
384
385 picolcd_suspend_backlight(hid_get_drvdata(hdev));
386 dbg_hid(PICOLCD_NAME " device ready for suspend\n");
387 return 0;
388}
389
390static int picolcd_resume(struct hid_device *hdev)
391{
392 int ret;
393 ret = picolcd_resume_backlight(hid_get_drvdata(hdev));
394 if (ret)
395 dbg_hid(PICOLCD_NAME " restoring backlight failed: %d\n", ret);
396 return 0;
397}
398
399static int picolcd_reset_resume(struct hid_device *hdev)
400{
401 int ret;
402 ret = picolcd_reset(hdev);
403 if (ret)
404 dbg_hid(PICOLCD_NAME " resetting our device failed: %d\n", ret);
405 ret = picolcd_fb_reset(hid_get_drvdata(hdev), 0);
406 if (ret)
407 dbg_hid(PICOLCD_NAME " restoring framebuffer content failed: %d\n", ret);
408 ret = picolcd_resume_lcd(hid_get_drvdata(hdev));
409 if (ret)
410 dbg_hid(PICOLCD_NAME " restoring lcd failed: %d\n", ret);
411 ret = picolcd_resume_backlight(hid_get_drvdata(hdev));
412 if (ret)
413 dbg_hid(PICOLCD_NAME " restoring backlight failed: %d\n", ret);
414 picolcd_leds_set(hid_get_drvdata(hdev));
415 return 0;
416}
417#endif
418
419/* initialize keypad input device */
420static int picolcd_init_keys(struct picolcd_data *data,
421 struct hid_report *report)
422{
423 struct hid_device *hdev = data->hdev;
424 struct input_dev *idev;
425 int error, i;
426
427 if (!report)
428 return -ENODEV;
429 if (report->maxfield != 1 || report->field[0]->report_count != 2 ||
430 report->field[0]->report_size != 8) {
431 hid_err(hdev, "unsupported KEY_STATE report\n");
432 return -EINVAL;
433 }
434
435 idev = input_allocate_device();
436 if (idev == NULL) {
437 hid_err(hdev, "failed to allocate input device\n");
438 return -ENOMEM;
439 }
440 input_set_drvdata(idev, hdev);
441 memcpy(data->keycode, def_keymap, sizeof(def_keymap));
442 idev->name = hdev->name;
443 idev->phys = hdev->phys;
444 idev->uniq = hdev->uniq;
445 idev->id.bustype = hdev->bus;
446 idev->id.vendor = hdev->vendor;
447 idev->id.product = hdev->product;
448 idev->id.version = hdev->version;
449 idev->dev.parent = &hdev->dev;
450 idev->keycode = &data->keycode;
451 idev->keycodemax = PICOLCD_KEYS;
452 idev->keycodesize = sizeof(data->keycode[0]);
453 input_set_capability(idev, EV_MSC, MSC_SCAN);
454 set_bit(EV_REP, idev->evbit);
455 for (i = 0; i < PICOLCD_KEYS; i++)
456 input_set_capability(idev, EV_KEY, data->keycode[i]);
457 error = input_register_device(idev);
458 if (error) {
459 hid_err(hdev, "error registering the input device\n");
460 input_free_device(idev);
461 return error;
462 }
463 data->input_keys = idev;
464 return 0;
465}
466
467static void picolcd_exit_keys(struct picolcd_data *data)
468{
469 struct input_dev *idev = data->input_keys;
470
471 data->input_keys = NULL;
472 if (idev)
473 input_unregister_device(idev);
474}
475
476static int picolcd_probe_lcd(struct hid_device *hdev, struct picolcd_data *data)
477{
478 int error;
479
480 /* Setup keypad input device */
481 error = picolcd_init_keys(data, picolcd_in_report(REPORT_KEY_STATE, hdev));
482 if (error)
483 goto err;
484
485 /* Setup CIR input device */
486 error = picolcd_init_cir(data, picolcd_in_report(REPORT_IR_DATA, hdev));
487 if (error)
488 goto err;
489
490 /* Set up the framebuffer device */
491 error = picolcd_init_framebuffer(data);
492 if (error)
493 goto err;
494
495 /* Setup lcd class device */
496 error = picolcd_init_lcd(data, picolcd_out_report(REPORT_CONTRAST, hdev));
497 if (error)
498 goto err;
499
500 /* Setup backlight class device */
501 error = picolcd_init_backlight(data, picolcd_out_report(REPORT_BRIGHTNESS, hdev));
502 if (error)
503 goto err;
504
505 /* Setup the LED class devices */
506 error = picolcd_init_leds(data, picolcd_out_report(REPORT_LED_STATE, hdev));
507 if (error)
508 goto err;
509
510 picolcd_init_devfs(data, picolcd_out_report(REPORT_EE_READ, hdev),
511 picolcd_out_report(REPORT_EE_WRITE, hdev),
512 picolcd_out_report(REPORT_READ_MEMORY, hdev),
513 picolcd_out_report(REPORT_WRITE_MEMORY, hdev),
514 picolcd_out_report(REPORT_RESET, hdev));
515 return 0;
516err:
517 picolcd_exit_leds(data);
518 picolcd_exit_backlight(data);
519 picolcd_exit_lcd(data);
520 picolcd_exit_framebuffer(data);
521 picolcd_exit_cir(data);
522 picolcd_exit_keys(data);
523 return error;
524}
525
526static int picolcd_probe_bootloader(struct hid_device *hdev, struct picolcd_data *data)
527{
528 picolcd_init_devfs(data, NULL, NULL,
529 picolcd_out_report(REPORT_BL_READ_MEMORY, hdev),
530 picolcd_out_report(REPORT_BL_WRITE_MEMORY, hdev), NULL);
531 return 0;
532}
533
534static int picolcd_probe(struct hid_device *hdev,
535 const struct hid_device_id *id)
536{
537 struct picolcd_data *data;
538 int error = -ENOMEM;
539
540 dbg_hid(PICOLCD_NAME " hardware probe...\n");
541
542 /*
543 * Let's allocate the picolcd data structure, set some reasonable
544 * defaults, and associate it with the device
545 */
546 data = kzalloc(sizeof(struct picolcd_data), GFP_KERNEL);
547 if (data == NULL) {
548 hid_err(hdev, "can't allocate space for Minibox PicoLCD device data\n");
549 error = -ENOMEM;
550 goto err_no_cleanup;
551 }
552
553 spin_lock_init(&data->lock);
554 mutex_init(&data->mutex);
555 data->hdev = hdev;
556 data->opmode_delay = 5000;
557 if (hdev->product == USB_DEVICE_ID_PICOLCD_BOOTLOADER)
558 data->status |= PICOLCD_BOOTLOADER;
559 hid_set_drvdata(hdev, data);
560
561 /* Parse the device reports and start it up */
562 error = hid_parse(hdev);
563 if (error) {
564 hid_err(hdev, "device report parse failed\n");
565 goto err_cleanup_data;
566 }
567
568 error = hid_hw_start(hdev, 0);
569 if (error) {
570 hid_err(hdev, "hardware start failed\n");
571 goto err_cleanup_data;
572 }
573
574 error = hid_hw_open(hdev);
575 if (error) {
576 hid_err(hdev, "failed to open input interrupt pipe for key and IR events\n");
577 goto err_cleanup_hid_hw;
578 }
579
580 error = device_create_file(&hdev->dev, &dev_attr_operation_mode_delay);
581 if (error) {
582 hid_err(hdev, "failed to create sysfs attributes\n");
583 goto err_cleanup_hid_ll;
584 }
585
586 error = device_create_file(&hdev->dev, &dev_attr_operation_mode);
587 if (error) {
588 hid_err(hdev, "failed to create sysfs attributes\n");
589 goto err_cleanup_sysfs1;
590 }
591
592 if (data->status & PICOLCD_BOOTLOADER)
593 error = picolcd_probe_bootloader(hdev, data);
594 else
595 error = picolcd_probe_lcd(hdev, data);
596 if (error)
597 goto err_cleanup_sysfs2;
598
599 dbg_hid(PICOLCD_NAME " activated and initialized\n");
600 return 0;
601
602err_cleanup_sysfs2:
603 device_remove_file(&hdev->dev, &dev_attr_operation_mode);
604err_cleanup_sysfs1:
605 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay);
606err_cleanup_hid_ll:
607 hid_hw_close(hdev);
608err_cleanup_hid_hw:
609 hid_hw_stop(hdev);
610err_cleanup_data:
611 kfree(data);
612err_no_cleanup:
613 hid_set_drvdata(hdev, NULL);
614
615 return error;
616}
617
618static void picolcd_remove(struct hid_device *hdev)
619{
620 struct picolcd_data *data = hid_get_drvdata(hdev);
621 unsigned long flags;
622
623 dbg_hid(PICOLCD_NAME " hardware remove...\n");
624 spin_lock_irqsave(&data->lock, flags);
625 data->status |= PICOLCD_FAILED;
626 spin_unlock_irqrestore(&data->lock, flags);
627
628 picolcd_exit_devfs(data);
629 device_remove_file(&hdev->dev, &dev_attr_operation_mode);
630 device_remove_file(&hdev->dev, &dev_attr_operation_mode_delay);
631 hid_hw_close(hdev);
632 hid_hw_stop(hdev);
633
634 /* Shortcut potential pending reply that will never arrive */
635 spin_lock_irqsave(&data->lock, flags);
636 if (data->pending)
637 complete(&data->pending->ready);
638 spin_unlock_irqrestore(&data->lock, flags);
639
640 /* Cleanup LED */
641 picolcd_exit_leds(data);
642 /* Clean up the framebuffer */
643 picolcd_exit_backlight(data);
644 picolcd_exit_lcd(data);
645 picolcd_exit_framebuffer(data);
646 /* Cleanup input */
647 picolcd_exit_cir(data);
648 picolcd_exit_keys(data);
649
650 hid_set_drvdata(hdev, NULL);
651 mutex_destroy(&data->mutex);
652 /* Finally, clean up the picolcd data itself */
653 kfree(data);
654}
655
656static const struct hid_device_id picolcd_devices[] = {
657 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
658 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
659 { }
660};
661MODULE_DEVICE_TABLE(hid, picolcd_devices);
662
663static struct hid_driver picolcd_driver = {
664 .name = "hid-picolcd",
665 .id_table = picolcd_devices,
666 .probe = picolcd_probe,
667 .remove = picolcd_remove,
668 .raw_event = picolcd_raw_event,
669#ifdef CONFIG_PM
670 .suspend = picolcd_suspend,
671 .resume = picolcd_resume,
672 .reset_resume = picolcd_reset_resume,
673#endif
674};
675
676static int __init picolcd_init(void)
677{
678 return hid_register_driver(&picolcd_driver);
679}
680
681static void __exit picolcd_exit(void)
682{
683 hid_unregister_driver(&picolcd_driver);
684}
685
686module_init(picolcd_init);
687module_exit(picolcd_exit);
688MODULE_DESCRIPTION("Minibox graphics PicoLCD Driver");
689MODULE_LICENSE("GPL v2");
diff --git a/drivers/hid/hid-picolcd_debugfs.c b/drivers/hid/hid-picolcd_debugfs.c
new file mode 100644
index 000000000000..4809aa1bdb9c
--- /dev/null
+++ b/drivers/hid/hid-picolcd_debugfs.c
@@ -0,0 +1,899 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include <linux/hid-debug.h>
22#include "usbhid/usbhid.h"
23#include <linux/usb.h>
24
25#include <linux/fb.h>
26#include <linux/seq_file.h>
27#include <linux/debugfs.h>
28
29#include <linux/module.h>
30#include <linux/uaccess.h>
31
32#include "hid-picolcd.h"
33
34
35static int picolcd_debug_reset_show(struct seq_file *f, void *p)
36{
37 if (picolcd_fbinfo((struct picolcd_data *)f->private))
38 seq_printf(f, "all fb\n");
39 else
40 seq_printf(f, "all\n");
41 return 0;
42}
43
44static int picolcd_debug_reset_open(struct inode *inode, struct file *f)
45{
46 return single_open(f, picolcd_debug_reset_show, inode->i_private);
47}
48
49static ssize_t picolcd_debug_reset_write(struct file *f, const char __user *user_buf,
50 size_t count, loff_t *ppos)
51{
52 struct picolcd_data *data = ((struct seq_file *)f->private_data)->private;
53 char buf[32];
54 size_t cnt = min(count, sizeof(buf)-1);
55 if (copy_from_user(buf, user_buf, cnt))
56 return -EFAULT;
57
58 while (cnt > 0 && (buf[cnt-1] == ' ' || buf[cnt-1] == '\n'))
59 cnt--;
60 buf[cnt] = '\0';
61 if (strcmp(buf, "all") == 0) {
62 picolcd_reset(data->hdev);
63 picolcd_fb_reset(data, 1);
64 } else if (strcmp(buf, "fb") == 0) {
65 picolcd_fb_reset(data, 1);
66 } else {
67 return -EINVAL;
68 }
69 return count;
70}
71
72static const struct file_operations picolcd_debug_reset_fops = {
73 .owner = THIS_MODULE,
74 .open = picolcd_debug_reset_open,
75 .read = seq_read,
76 .llseek = seq_lseek,
77 .write = picolcd_debug_reset_write,
78 .release = single_release,
79};
80
81/*
82 * The "eeprom" file
83 */
84static ssize_t picolcd_debug_eeprom_read(struct file *f, char __user *u,
85 size_t s, loff_t *off)
86{
87 struct picolcd_data *data = f->private_data;
88 struct picolcd_pending *resp;
89 u8 raw_data[3];
90 ssize_t ret = -EIO;
91
92 if (s == 0)
93 return -EINVAL;
94 if (*off > 0x0ff)
95 return 0;
96
97 /* prepare buffer with info about what we want to read (addr & len) */
98 raw_data[0] = *off & 0xff;
99 raw_data[1] = (*off >> 8) & 0xff;
100 raw_data[2] = s < 20 ? s : 20;
101 if (*off + raw_data[2] > 0xff)
102 raw_data[2] = 0x100 - *off;
103 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_READ, raw_data,
104 sizeof(raw_data));
105 if (!resp)
106 return -EIO;
107
108 if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) {
109 /* successful read :) */
110 ret = resp->raw_data[2];
111 if (ret > s)
112 ret = s;
113 if (copy_to_user(u, resp->raw_data+3, ret))
114 ret = -EFAULT;
115 else
116 *off += ret;
117 } /* anything else is some kind of IO error */
118
119 kfree(resp);
120 return ret;
121}
122
123static ssize_t picolcd_debug_eeprom_write(struct file *f, const char __user *u,
124 size_t s, loff_t *off)
125{
126 struct picolcd_data *data = f->private_data;
127 struct picolcd_pending *resp;
128 ssize_t ret = -EIO;
129 u8 raw_data[23];
130
131 if (s == 0)
132 return -EINVAL;
133 if (*off > 0x0ff)
134 return -ENOSPC;
135
136 memset(raw_data, 0, sizeof(raw_data));
137 raw_data[0] = *off & 0xff;
138 raw_data[1] = (*off >> 8) & 0xff;
139 raw_data[2] = min_t(size_t, 20, s);
140 if (*off + raw_data[2] > 0xff)
141 raw_data[2] = 0x100 - *off;
142
143 if (copy_from_user(raw_data+3, u, min((u8)20, raw_data[2])))
144 return -EFAULT;
145 resp = picolcd_send_and_wait(data->hdev, REPORT_EE_WRITE, raw_data,
146 sizeof(raw_data));
147
148 if (!resp)
149 return -EIO;
150
151 if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) {
152 /* check if written data matches */
153 if (memcmp(raw_data, resp->raw_data, 3+raw_data[2]) == 0) {
154 *off += raw_data[2];
155 ret = raw_data[2];
156 }
157 }
158 kfree(resp);
159 return ret;
160}
161
162/*
163 * Notes:
164 * - read/write happens in chunks of at most 20 bytes, it's up to userspace
165 * to loop in order to get more data.
166 * - on write errors on otherwise correct write request the bytes
167 * that should have been written are in undefined state.
168 */
169static const struct file_operations picolcd_debug_eeprom_fops = {
170 .owner = THIS_MODULE,
171 .open = simple_open,
172 .read = picolcd_debug_eeprom_read,
173 .write = picolcd_debug_eeprom_write,
174 .llseek = generic_file_llseek,
175};
176
177/*
178 * The "flash" file
179 */
180/* record a flash address to buf (bounds check to be done by caller) */
181static int _picolcd_flash_setaddr(struct picolcd_data *data, u8 *buf, long off)
182{
183 buf[0] = off & 0xff;
184 buf[1] = (off >> 8) & 0xff;
185 if (data->addr_sz == 3)
186 buf[2] = (off >> 16) & 0xff;
187 return data->addr_sz == 2 ? 2 : 3;
188}
189
190/* read a given size of data (bounds check to be done by caller) */
191static ssize_t _picolcd_flash_read(struct picolcd_data *data, int report_id,
192 char __user *u, size_t s, loff_t *off)
193{
194 struct picolcd_pending *resp;
195 u8 raw_data[4];
196 ssize_t ret = 0;
197 int len_off, err = -EIO;
198
199 while (s > 0) {
200 err = -EIO;
201 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
202 raw_data[len_off] = s > 32 ? 32 : s;
203 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, len_off+1);
204 if (!resp || !resp->in_report)
205 goto skip;
206 if (resp->in_report->id == REPORT_MEMORY ||
207 resp->in_report->id == REPORT_BL_READ_MEMORY) {
208 if (memcmp(raw_data, resp->raw_data, len_off+1) != 0)
209 goto skip;
210 if (copy_to_user(u+ret, resp->raw_data+len_off+1, raw_data[len_off])) {
211 err = -EFAULT;
212 goto skip;
213 }
214 *off += raw_data[len_off];
215 s -= raw_data[len_off];
216 ret += raw_data[len_off];
217 err = 0;
218 }
219skip:
220 kfree(resp);
221 if (err)
222 return ret > 0 ? ret : err;
223 }
224 return ret;
225}
226
227static ssize_t picolcd_debug_flash_read(struct file *f, char __user *u,
228 size_t s, loff_t *off)
229{
230 struct picolcd_data *data = f->private_data;
231
232 if (s == 0)
233 return -EINVAL;
234 if (*off > 0x05fff)
235 return 0;
236 if (*off + s > 0x05fff)
237 s = 0x06000 - *off;
238
239 if (data->status & PICOLCD_BOOTLOADER)
240 return _picolcd_flash_read(data, REPORT_BL_READ_MEMORY, u, s, off);
241 else
242 return _picolcd_flash_read(data, REPORT_READ_MEMORY, u, s, off);
243}
244
245/* erase block aligned to 64bytes boundary */
246static ssize_t _picolcd_flash_erase64(struct picolcd_data *data, int report_id,
247 loff_t *off)
248{
249 struct picolcd_pending *resp;
250 u8 raw_data[3];
251 int len_off;
252 ssize_t ret = -EIO;
253
254 if (*off & 0x3f)
255 return -EINVAL;
256
257 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
258 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data, len_off);
259 if (!resp || !resp->in_report)
260 goto skip;
261 if (resp->in_report->id == REPORT_MEMORY ||
262 resp->in_report->id == REPORT_BL_ERASE_MEMORY) {
263 if (memcmp(raw_data, resp->raw_data, len_off) != 0)
264 goto skip;
265 ret = 0;
266 }
267skip:
268 kfree(resp);
269 return ret;
270}
271
272/* write a given size of data (bounds check to be done by caller) */
273static ssize_t _picolcd_flash_write(struct picolcd_data *data, int report_id,
274 const char __user *u, size_t s, loff_t *off)
275{
276 struct picolcd_pending *resp;
277 u8 raw_data[36];
278 ssize_t ret = 0;
279 int len_off, err = -EIO;
280
281 while (s > 0) {
282 err = -EIO;
283 len_off = _picolcd_flash_setaddr(data, raw_data, *off);
284 raw_data[len_off] = s > 32 ? 32 : s;
285 if (copy_from_user(raw_data+len_off+1, u, raw_data[len_off])) {
286 err = -EFAULT;
287 break;
288 }
289 resp = picolcd_send_and_wait(data->hdev, report_id, raw_data,
290 len_off+1+raw_data[len_off]);
291 if (!resp || !resp->in_report)
292 goto skip;
293 if (resp->in_report->id == REPORT_MEMORY ||
294 resp->in_report->id == REPORT_BL_WRITE_MEMORY) {
295 if (memcmp(raw_data, resp->raw_data, len_off+1+raw_data[len_off]) != 0)
296 goto skip;
297 *off += raw_data[len_off];
298 s -= raw_data[len_off];
299 ret += raw_data[len_off];
300 err = 0;
301 }
302skip:
303 kfree(resp);
304 if (err)
305 break;
306 }
307 return ret > 0 ? ret : err;
308}
309
310static ssize_t picolcd_debug_flash_write(struct file *f, const char __user *u,
311 size_t s, loff_t *off)
312{
313 struct picolcd_data *data = f->private_data;
314 ssize_t err, ret = 0;
315 int report_erase, report_write;
316
317 if (s == 0)
318 return -EINVAL;
319 if (*off > 0x5fff)
320 return -ENOSPC;
321 if (s & 0x3f)
322 return -EINVAL;
323 if (*off & 0x3f)
324 return -EINVAL;
325
326 if (data->status & PICOLCD_BOOTLOADER) {
327 report_erase = REPORT_BL_ERASE_MEMORY;
328 report_write = REPORT_BL_WRITE_MEMORY;
329 } else {
330 report_erase = REPORT_ERASE_MEMORY;
331 report_write = REPORT_WRITE_MEMORY;
332 }
333 mutex_lock(&data->mutex_flash);
334 while (s > 0) {
335 err = _picolcd_flash_erase64(data, report_erase, off);
336 if (err)
337 break;
338 err = _picolcd_flash_write(data, report_write, u, 64, off);
339 if (err < 0)
340 break;
341 ret += err;
342 *off += err;
343 s -= err;
344 if (err != 64)
345 break;
346 }
347 mutex_unlock(&data->mutex_flash);
348 return ret > 0 ? ret : err;
349}
350
351/*
352 * Notes:
353 * - concurrent writing is prevented by mutex and all writes must be
354 * n*64 bytes and 64-byte aligned, each write being preceded by an
355 * ERASE which erases a 64byte block.
356 * If less than requested was written or an error is returned for an
357 * otherwise correct write request the next 64-byte block which should
358 * have been written is in undefined state (mostly: original, erased,
359 * (half-)written with write error)
360 * - reading can happen without special restriction
361 */
362static const struct file_operations picolcd_debug_flash_fops = {
363 .owner = THIS_MODULE,
364 .open = simple_open,
365 .read = picolcd_debug_flash_read,
366 .write = picolcd_debug_flash_write,
367 .llseek = generic_file_llseek,
368};
369
370
371/*
372 * Helper code for HID report level dumping/debugging
373 */
374static const char * const error_codes[] = {
375 "success", "parameter missing", "data_missing", "block readonly",
376 "block not erasable", "block too big", "section overflow",
377 "invalid command length", "invalid data length",
378};
379
380static void dump_buff_as_hex(char *dst, size_t dst_sz, const u8 *data,
381 const size_t data_len)
382{
383 int i, j;
384 for (i = j = 0; i < data_len && j + 4 < dst_sz; i++) {
385 dst[j++] = hex_asc[(data[i] >> 4) & 0x0f];
386 dst[j++] = hex_asc[data[i] & 0x0f];
387 dst[j++] = ' ';
388 }
389 dst[j] = '\0';
390 if (j > 0)
391 dst[j-1] = '\n';
392 if (i < data_len && j > 2)
393 dst[j-2] = dst[j-3] = '.';
394}
395
396void picolcd_debug_out_report(struct picolcd_data *data,
397 struct hid_device *hdev, struct hid_report *report)
398{
399 u8 raw_data[70];
400 int raw_size = (report->size >> 3) + 1;
401 char *buff;
402#define BUFF_SZ 256
403
404 /* Avoid unnecessary overhead if debugfs is disabled */
405 if (list_empty(&hdev->debug_list))
406 return;
407
408 buff = kmalloc(BUFF_SZ, GFP_ATOMIC);
409 if (!buff)
410 return;
411
412 snprintf(buff, BUFF_SZ, "\nout report %d (size %d) = ",
413 report->id, raw_size);
414 hid_debug_event(hdev, buff);
415 if (raw_size + 5 > sizeof(raw_data)) {
416 kfree(buff);
417 hid_debug_event(hdev, " TOO BIG\n");
418 return;
419 } else {
420 raw_data[0] = report->id;
421 hid_output_report(report, raw_data);
422 dump_buff_as_hex(buff, BUFF_SZ, raw_data, raw_size);
423 hid_debug_event(hdev, buff);
424 }
425
426 switch (report->id) {
427 case REPORT_LED_STATE:
428 /* 1 data byte with GPO state */
429 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
430 "REPORT_LED_STATE", report->id, raw_size-1);
431 hid_debug_event(hdev, buff);
432 snprintf(buff, BUFF_SZ, "\tGPO state: 0x%02x\n", raw_data[1]);
433 hid_debug_event(hdev, buff);
434 break;
435 case REPORT_BRIGHTNESS:
436 /* 1 data byte with brightness */
437 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
438 "REPORT_BRIGHTNESS", report->id, raw_size-1);
439 hid_debug_event(hdev, buff);
440 snprintf(buff, BUFF_SZ, "\tBrightness: 0x%02x\n", raw_data[1]);
441 hid_debug_event(hdev, buff);
442 break;
443 case REPORT_CONTRAST:
444 /* 1 data byte with contrast */
445 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
446 "REPORT_CONTRAST", report->id, raw_size-1);
447 hid_debug_event(hdev, buff);
448 snprintf(buff, BUFF_SZ, "\tContrast: 0x%02x\n", raw_data[1]);
449 hid_debug_event(hdev, buff);
450 break;
451 case REPORT_RESET:
452 /* 2 data bytes with reset duration in ms */
453 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
454 "REPORT_RESET", report->id, raw_size-1);
455 hid_debug_event(hdev, buff);
456 snprintf(buff, BUFF_SZ, "\tDuration: 0x%02x%02x (%dms)\n",
457 raw_data[2], raw_data[1], raw_data[2] << 8 | raw_data[1]);
458 hid_debug_event(hdev, buff);
459 break;
460 case REPORT_LCD_CMD:
461 /* 63 data bytes with LCD commands */
462 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
463 "REPORT_LCD_CMD", report->id, raw_size-1);
464 hid_debug_event(hdev, buff);
465 /* TODO: format decoding */
466 break;
467 case REPORT_LCD_DATA:
468 /* 63 data bytes with LCD data */
469 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
470 "REPORT_LCD_CMD", report->id, raw_size-1);
471 /* TODO: format decoding */
472 hid_debug_event(hdev, buff);
473 break;
474 case REPORT_LCD_CMD_DATA:
475 /* 63 data bytes with LCD commands and data */
476 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
477 "REPORT_LCD_CMD", report->id, raw_size-1);
478 /* TODO: format decoding */
479 hid_debug_event(hdev, buff);
480 break;
481 case REPORT_EE_READ:
482 /* 3 data bytes with read area description */
483 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
484 "REPORT_EE_READ", report->id, raw_size-1);
485 hid_debug_event(hdev, buff);
486 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
487 raw_data[2], raw_data[1]);
488 hid_debug_event(hdev, buff);
489 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
490 hid_debug_event(hdev, buff);
491 break;
492 case REPORT_EE_WRITE:
493 /* 3+1..20 data bytes with write area description */
494 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
495 "REPORT_EE_WRITE", report->id, raw_size-1);
496 hid_debug_event(hdev, buff);
497 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
498 raw_data[2], raw_data[1]);
499 hid_debug_event(hdev, buff);
500 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
501 hid_debug_event(hdev, buff);
502 if (raw_data[3] == 0) {
503 snprintf(buff, BUFF_SZ, "\tNo data\n");
504 } else if (raw_data[3] + 4 <= raw_size) {
505 snprintf(buff, BUFF_SZ, "\tData: ");
506 hid_debug_event(hdev, buff);
507 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
508 } else {
509 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
510 }
511 hid_debug_event(hdev, buff);
512 break;
513 case REPORT_ERASE_MEMORY:
514 case REPORT_BL_ERASE_MEMORY:
515 /* 3 data bytes with pointer inside erase block */
516 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
517 "REPORT_ERASE_MEMORY", report->id, raw_size-1);
518 hid_debug_event(hdev, buff);
519 switch (data->addr_sz) {
520 case 2:
521 snprintf(buff, BUFF_SZ, "\tAddress inside 64 byte block: 0x%02x%02x\n",
522 raw_data[2], raw_data[1]);
523 break;
524 case 3:
525 snprintf(buff, BUFF_SZ, "\tAddress inside 64 byte block: 0x%02x%02x%02x\n",
526 raw_data[3], raw_data[2], raw_data[1]);
527 break;
528 default:
529 snprintf(buff, BUFF_SZ, "\tNot supported\n");
530 }
531 hid_debug_event(hdev, buff);
532 break;
533 case REPORT_READ_MEMORY:
534 case REPORT_BL_READ_MEMORY:
535 /* 4 data bytes with read area description */
536 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
537 "REPORT_READ_MEMORY", report->id, raw_size-1);
538 hid_debug_event(hdev, buff);
539 switch (data->addr_sz) {
540 case 2:
541 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
542 raw_data[2], raw_data[1]);
543 hid_debug_event(hdev, buff);
544 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
545 break;
546 case 3:
547 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
548 raw_data[3], raw_data[2], raw_data[1]);
549 hid_debug_event(hdev, buff);
550 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
551 break;
552 default:
553 snprintf(buff, BUFF_SZ, "\tNot supported\n");
554 }
555 hid_debug_event(hdev, buff);
556 break;
557 case REPORT_WRITE_MEMORY:
558 case REPORT_BL_WRITE_MEMORY:
559 /* 4+1..32 data bytes with write adrea description */
560 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
561 "REPORT_WRITE_MEMORY", report->id, raw_size-1);
562 hid_debug_event(hdev, buff);
563 switch (data->addr_sz) {
564 case 2:
565 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
566 raw_data[2], raw_data[1]);
567 hid_debug_event(hdev, buff);
568 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
569 hid_debug_event(hdev, buff);
570 if (raw_data[3] == 0) {
571 snprintf(buff, BUFF_SZ, "\tNo data\n");
572 } else if (raw_data[3] + 4 <= raw_size) {
573 snprintf(buff, BUFF_SZ, "\tData: ");
574 hid_debug_event(hdev, buff);
575 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
576 } else {
577 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
578 }
579 break;
580 case 3:
581 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
582 raw_data[3], raw_data[2], raw_data[1]);
583 hid_debug_event(hdev, buff);
584 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
585 hid_debug_event(hdev, buff);
586 if (raw_data[4] == 0) {
587 snprintf(buff, BUFF_SZ, "\tNo data\n");
588 } else if (raw_data[4] + 5 <= raw_size) {
589 snprintf(buff, BUFF_SZ, "\tData: ");
590 hid_debug_event(hdev, buff);
591 dump_buff_as_hex(buff, BUFF_SZ, raw_data+5, raw_data[4]);
592 } else {
593 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
594 }
595 break;
596 default:
597 snprintf(buff, BUFF_SZ, "\tNot supported\n");
598 }
599 hid_debug_event(hdev, buff);
600 break;
601 case REPORT_SPLASH_RESTART:
602 /* TODO */
603 break;
604 case REPORT_EXIT_KEYBOARD:
605 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
606 "REPORT_EXIT_KEYBOARD", report->id, raw_size-1);
607 hid_debug_event(hdev, buff);
608 snprintf(buff, BUFF_SZ, "\tRestart delay: %dms (0x%02x%02x)\n",
609 raw_data[1] | (raw_data[2] << 8),
610 raw_data[2], raw_data[1]);
611 hid_debug_event(hdev, buff);
612 break;
613 case REPORT_VERSION:
614 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
615 "REPORT_VERSION", report->id, raw_size-1);
616 hid_debug_event(hdev, buff);
617 break;
618 case REPORT_DEVID:
619 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
620 "REPORT_DEVID", report->id, raw_size-1);
621 hid_debug_event(hdev, buff);
622 break;
623 case REPORT_SPLASH_SIZE:
624 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
625 "REPORT_SPLASH_SIZE", report->id, raw_size-1);
626 hid_debug_event(hdev, buff);
627 break;
628 case REPORT_HOOK_VERSION:
629 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
630 "REPORT_HOOK_VERSION", report->id, raw_size-1);
631 hid_debug_event(hdev, buff);
632 break;
633 case REPORT_EXIT_FLASHER:
634 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
635 "REPORT_VERSION", report->id, raw_size-1);
636 hid_debug_event(hdev, buff);
637 snprintf(buff, BUFF_SZ, "\tRestart delay: %dms (0x%02x%02x)\n",
638 raw_data[1] | (raw_data[2] << 8),
639 raw_data[2], raw_data[1]);
640 hid_debug_event(hdev, buff);
641 break;
642 default:
643 snprintf(buff, BUFF_SZ, "out report %s (%d, size=%d)\n",
644 "<unknown>", report->id, raw_size-1);
645 hid_debug_event(hdev, buff);
646 break;
647 }
648 wake_up_interruptible(&hdev->debug_wait);
649 kfree(buff);
650}
651
652void picolcd_debug_raw_event(struct picolcd_data *data,
653 struct hid_device *hdev, struct hid_report *report,
654 u8 *raw_data, int size)
655{
656 char *buff;
657
658#define BUFF_SZ 256
659 /* Avoid unnecessary overhead if debugfs is disabled */
660 if (list_empty(&hdev->debug_list))
661 return;
662
663 buff = kmalloc(BUFF_SZ, GFP_ATOMIC);
664 if (!buff)
665 return;
666
667 switch (report->id) {
668 case REPORT_ERROR_CODE:
669 /* 2 data bytes with affected report and error code */
670 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
671 "REPORT_ERROR_CODE", report->id, size-1);
672 hid_debug_event(hdev, buff);
673 if (raw_data[2] < ARRAY_SIZE(error_codes))
674 snprintf(buff, BUFF_SZ, "\tError code 0x%02x (%s) in reply to report 0x%02x\n",
675 raw_data[2], error_codes[raw_data[2]], raw_data[1]);
676 else
677 snprintf(buff, BUFF_SZ, "\tError code 0x%02x in reply to report 0x%02x\n",
678 raw_data[2], raw_data[1]);
679 hid_debug_event(hdev, buff);
680 break;
681 case REPORT_KEY_STATE:
682 /* 2 data bytes with key state */
683 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
684 "REPORT_KEY_STATE", report->id, size-1);
685 hid_debug_event(hdev, buff);
686 if (raw_data[1] == 0)
687 snprintf(buff, BUFF_SZ, "\tNo key pressed\n");
688 else if (raw_data[2] == 0)
689 snprintf(buff, BUFF_SZ, "\tOne key pressed: 0x%02x (%d)\n",
690 raw_data[1], raw_data[1]);
691 else
692 snprintf(buff, BUFF_SZ, "\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n",
693 raw_data[1], raw_data[1], raw_data[2], raw_data[2]);
694 hid_debug_event(hdev, buff);
695 break;
696 case REPORT_IR_DATA:
697 /* Up to 20 byes of IR scancode data */
698 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
699 "REPORT_IR_DATA", report->id, size-1);
700 hid_debug_event(hdev, buff);
701 if (raw_data[1] == 0) {
702 snprintf(buff, BUFF_SZ, "\tUnexpectedly 0 data length\n");
703 hid_debug_event(hdev, buff);
704 } else if (raw_data[1] + 1 <= size) {
705 snprintf(buff, BUFF_SZ, "\tData length: %d\n\tIR Data: ",
706 raw_data[1]);
707 hid_debug_event(hdev, buff);
708 dump_buff_as_hex(buff, BUFF_SZ, raw_data+2, raw_data[1]);
709 hid_debug_event(hdev, buff);
710 } else {
711 snprintf(buff, BUFF_SZ, "\tOverflowing data length: %d\n",
712 raw_data[1]-1);
713 hid_debug_event(hdev, buff);
714 }
715 break;
716 case REPORT_EE_DATA:
717 /* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */
718 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
719 "REPORT_EE_DATA", report->id, size-1);
720 hid_debug_event(hdev, buff);
721 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
722 raw_data[2], raw_data[1]);
723 hid_debug_event(hdev, buff);
724 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
725 hid_debug_event(hdev, buff);
726 if (raw_data[3] == 0) {
727 snprintf(buff, BUFF_SZ, "\tNo data\n");
728 hid_debug_event(hdev, buff);
729 } else if (raw_data[3] + 4 <= size) {
730 snprintf(buff, BUFF_SZ, "\tData: ");
731 hid_debug_event(hdev, buff);
732 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
733 hid_debug_event(hdev, buff);
734 } else {
735 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
736 hid_debug_event(hdev, buff);
737 }
738 break;
739 case REPORT_MEMORY:
740 /* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRTIE_MEMORY */
741 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
742 "REPORT_MEMORY", report->id, size-1);
743 hid_debug_event(hdev, buff);
744 switch (data->addr_sz) {
745 case 2:
746 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x\n",
747 raw_data[2], raw_data[1]);
748 hid_debug_event(hdev, buff);
749 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[3]);
750 hid_debug_event(hdev, buff);
751 if (raw_data[3] == 0) {
752 snprintf(buff, BUFF_SZ, "\tNo data\n");
753 } else if (raw_data[3] + 4 <= size) {
754 snprintf(buff, BUFF_SZ, "\tData: ");
755 hid_debug_event(hdev, buff);
756 dump_buff_as_hex(buff, BUFF_SZ, raw_data+4, raw_data[3]);
757 } else {
758 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
759 }
760 break;
761 case 3:
762 snprintf(buff, BUFF_SZ, "\tData address: 0x%02x%02x%02x\n",
763 raw_data[3], raw_data[2], raw_data[1]);
764 hid_debug_event(hdev, buff);
765 snprintf(buff, BUFF_SZ, "\tData length: %d\n", raw_data[4]);
766 hid_debug_event(hdev, buff);
767 if (raw_data[4] == 0) {
768 snprintf(buff, BUFF_SZ, "\tNo data\n");
769 } else if (raw_data[4] + 5 <= size) {
770 snprintf(buff, BUFF_SZ, "\tData: ");
771 hid_debug_event(hdev, buff);
772 dump_buff_as_hex(buff, BUFF_SZ, raw_data+5, raw_data[4]);
773 } else {
774 snprintf(buff, BUFF_SZ, "\tData overflowed\n");
775 }
776 break;
777 default:
778 snprintf(buff, BUFF_SZ, "\tNot supported\n");
779 }
780 hid_debug_event(hdev, buff);
781 break;
782 case REPORT_VERSION:
783 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
784 "REPORT_VERSION", report->id, size-1);
785 hid_debug_event(hdev, buff);
786 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n",
787 raw_data[2], raw_data[1]);
788 hid_debug_event(hdev, buff);
789 break;
790 case REPORT_BL_ERASE_MEMORY:
791 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
792 "REPORT_BL_ERASE_MEMORY", report->id, size-1);
793 hid_debug_event(hdev, buff);
794 /* TODO */
795 break;
796 case REPORT_BL_READ_MEMORY:
797 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
798 "REPORT_BL_READ_MEMORY", report->id, size-1);
799 hid_debug_event(hdev, buff);
800 /* TODO */
801 break;
802 case REPORT_BL_WRITE_MEMORY:
803 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
804 "REPORT_BL_WRITE_MEMORY", report->id, size-1);
805 hid_debug_event(hdev, buff);
806 /* TODO */
807 break;
808 case REPORT_DEVID:
809 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
810 "REPORT_DEVID", report->id, size-1);
811 hid_debug_event(hdev, buff);
812 snprintf(buff, BUFF_SZ, "\tSerial: 0x%02x%02x%02x%02x\n",
813 raw_data[1], raw_data[2], raw_data[3], raw_data[4]);
814 hid_debug_event(hdev, buff);
815 snprintf(buff, BUFF_SZ, "\tType: 0x%02x\n",
816 raw_data[5]);
817 hid_debug_event(hdev, buff);
818 break;
819 case REPORT_SPLASH_SIZE:
820 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
821 "REPORT_SPLASH_SIZE", report->id, size-1);
822 hid_debug_event(hdev, buff);
823 snprintf(buff, BUFF_SZ, "\tTotal splash space: %d\n",
824 (raw_data[2] << 8) | raw_data[1]);
825 hid_debug_event(hdev, buff);
826 snprintf(buff, BUFF_SZ, "\tUsed splash space: %d\n",
827 (raw_data[4] << 8) | raw_data[3]);
828 hid_debug_event(hdev, buff);
829 break;
830 case REPORT_HOOK_VERSION:
831 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
832 "REPORT_HOOK_VERSION", report->id, size-1);
833 hid_debug_event(hdev, buff);
834 snprintf(buff, BUFF_SZ, "\tFirmware version: %d.%d\n",
835 raw_data[1], raw_data[2]);
836 hid_debug_event(hdev, buff);
837 break;
838 default:
839 snprintf(buff, BUFF_SZ, "report %s (%d, size=%d)\n",
840 "<unknown>", report->id, size-1);
841 hid_debug_event(hdev, buff);
842 break;
843 }
844 wake_up_interruptible(&hdev->debug_wait);
845 kfree(buff);
846}
847
848void picolcd_init_devfs(struct picolcd_data *data,
849 struct hid_report *eeprom_r, struct hid_report *eeprom_w,
850 struct hid_report *flash_r, struct hid_report *flash_w,
851 struct hid_report *reset)
852{
853 struct hid_device *hdev = data->hdev;
854
855 mutex_init(&data->mutex_flash);
856
857 /* reset */
858 if (reset)
859 data->debug_reset = debugfs_create_file("reset", 0600,
860 hdev->debug_dir, data, &picolcd_debug_reset_fops);
861
862 /* eeprom */
863 if (eeprom_r || eeprom_w)
864 data->debug_eeprom = debugfs_create_file("eeprom",
865 (eeprom_w ? S_IWUSR : 0) | (eeprom_r ? S_IRUSR : 0),
866 hdev->debug_dir, data, &picolcd_debug_eeprom_fops);
867
868 /* flash */
869 if (flash_r && flash_r->maxfield == 1 && flash_r->field[0]->report_size == 8)
870 data->addr_sz = flash_r->field[0]->report_count - 1;
871 else
872 data->addr_sz = -1;
873 if (data->addr_sz == 2 || data->addr_sz == 3) {
874 data->debug_flash = debugfs_create_file("flash",
875 (flash_w ? S_IWUSR : 0) | (flash_r ? S_IRUSR : 0),
876 hdev->debug_dir, data, &picolcd_debug_flash_fops);
877 } else if (flash_r || flash_w)
878 hid_warn(hdev, "Unexpected FLASH access reports, please submit rdesc for review\n");
879}
880
881void picolcd_exit_devfs(struct picolcd_data *data)
882{
883 struct dentry *dent;
884
885 dent = data->debug_reset;
886 data->debug_reset = NULL;
887 if (dent)
888 debugfs_remove(dent);
889 dent = data->debug_eeprom;
890 data->debug_eeprom = NULL;
891 if (dent)
892 debugfs_remove(dent);
893 dent = data->debug_flash;
894 data->debug_flash = NULL;
895 if (dent)
896 debugfs_remove(dent);
897 mutex_destroy(&data->mutex_flash);
898}
899
diff --git a/drivers/hid/hid-picolcd_fb.c b/drivers/hid/hid-picolcd_fb.c
new file mode 100644
index 000000000000..0008a512211d
--- /dev/null
+++ b/drivers/hid/hid-picolcd_fb.c
@@ -0,0 +1,615 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include <linux/vmalloc.h>
22#include "usbhid/usbhid.h"
23#include <linux/usb.h>
24
25#include <linux/fb.h>
26#include <linux/module.h>
27
28#include "hid-picolcd.h"
29
30/* Framebuffer
31 *
32 * The PicoLCD use a Topway LCD module of 256x64 pixel
33 * This display area is tiled over 4 controllers with 8 tiles
34 * each. Each tile has 8x64 pixel, each data byte representing
35 * a 1-bit wide vertical line of the tile.
36 *
37 * The display can be updated at a tile granularity.
38 *
39 * Chip 1 Chip 2 Chip 3 Chip 4
40 * +----------------+----------------+----------------+----------------+
41 * | Tile 1 | Tile 1 | Tile 1 | Tile 1 |
42 * +----------------+----------------+----------------+----------------+
43 * | Tile 2 | Tile 2 | Tile 2 | Tile 2 |
44 * +----------------+----------------+----------------+----------------+
45 * ...
46 * +----------------+----------------+----------------+----------------+
47 * | Tile 8 | Tile 8 | Tile 8 | Tile 8 |
48 * +----------------+----------------+----------------+----------------+
49 */
50#define PICOLCDFB_NAME "picolcdfb"
51#define PICOLCDFB_WIDTH (256)
52#define PICOLCDFB_HEIGHT (64)
53#define PICOLCDFB_SIZE (PICOLCDFB_WIDTH * PICOLCDFB_HEIGHT / 8)
54
55#define PICOLCDFB_UPDATE_RATE_LIMIT 10
56#define PICOLCDFB_UPDATE_RATE_DEFAULT 2
57
58/* Framebuffer visual structures */
59static const struct fb_fix_screeninfo picolcdfb_fix = {
60 .id = PICOLCDFB_NAME,
61 .type = FB_TYPE_PACKED_PIXELS,
62 .visual = FB_VISUAL_MONO01,
63 .xpanstep = 0,
64 .ypanstep = 0,
65 .ywrapstep = 0,
66 .line_length = PICOLCDFB_WIDTH / 8,
67 .accel = FB_ACCEL_NONE,
68};
69
70static const struct fb_var_screeninfo picolcdfb_var = {
71 .xres = PICOLCDFB_WIDTH,
72 .yres = PICOLCDFB_HEIGHT,
73 .xres_virtual = PICOLCDFB_WIDTH,
74 .yres_virtual = PICOLCDFB_HEIGHT,
75 .width = 103,
76 .height = 26,
77 .bits_per_pixel = 1,
78 .grayscale = 1,
79 .red = {
80 .offset = 0,
81 .length = 1,
82 .msb_right = 0,
83 },
84 .green = {
85 .offset = 0,
86 .length = 1,
87 .msb_right = 0,
88 },
89 .blue = {
90 .offset = 0,
91 .length = 1,
92 .msb_right = 0,
93 },
94 .transp = {
95 .offset = 0,
96 .length = 0,
97 .msb_right = 0,
98 },
99};
100
101/* Send a given tile to PicoLCD */
102static int picolcd_fb_send_tile(struct picolcd_data *data, u8 *vbitmap,
103 int chip, int tile)
104{
105 struct hid_report *report1, *report2;
106 unsigned long flags;
107 u8 *tdata;
108 int i;
109
110 report1 = picolcd_out_report(REPORT_LCD_CMD_DATA, data->hdev);
111 if (!report1 || report1->maxfield != 1)
112 return -ENODEV;
113 report2 = picolcd_out_report(REPORT_LCD_DATA, data->hdev);
114 if (!report2 || report2->maxfield != 1)
115 return -ENODEV;
116
117 spin_lock_irqsave(&data->lock, flags);
118 if ((data->status & PICOLCD_FAILED)) {
119 spin_unlock_irqrestore(&data->lock, flags);
120 return -ENODEV;
121 }
122 hid_set_field(report1->field[0], 0, chip << 2);
123 hid_set_field(report1->field[0], 1, 0x02);
124 hid_set_field(report1->field[0], 2, 0x00);
125 hid_set_field(report1->field[0], 3, 0x00);
126 hid_set_field(report1->field[0], 4, 0xb8 | tile);
127 hid_set_field(report1->field[0], 5, 0x00);
128 hid_set_field(report1->field[0], 6, 0x00);
129 hid_set_field(report1->field[0], 7, 0x40);
130 hid_set_field(report1->field[0], 8, 0x00);
131 hid_set_field(report1->field[0], 9, 0x00);
132 hid_set_field(report1->field[0], 10, 32);
133
134 hid_set_field(report2->field[0], 0, (chip << 2) | 0x01);
135 hid_set_field(report2->field[0], 1, 0x00);
136 hid_set_field(report2->field[0], 2, 0x00);
137 hid_set_field(report2->field[0], 3, 32);
138
139 tdata = vbitmap + (tile * 4 + chip) * 64;
140 for (i = 0; i < 64; i++)
141 if (i < 32)
142 hid_set_field(report1->field[0], 11 + i, tdata[i]);
143 else
144 hid_set_field(report2->field[0], 4 + i - 32, tdata[i]);
145
146 usbhid_submit_report(data->hdev, report1, USB_DIR_OUT);
147 usbhid_submit_report(data->hdev, report2, USB_DIR_OUT);
148 spin_unlock_irqrestore(&data->lock, flags);
149 return 0;
150}
151
152/* Translate a single tile*/
153static int picolcd_fb_update_tile(u8 *vbitmap, const u8 *bitmap, int bpp,
154 int chip, int tile)
155{
156 int i, b, changed = 0;
157 u8 tdata[64];
158 u8 *vdata = vbitmap + (tile * 4 + chip) * 64;
159
160 if (bpp == 1) {
161 for (b = 7; b >= 0; b--) {
162 const u8 *bdata = bitmap + tile * 256 + chip * 8 + b * 32;
163 for (i = 0; i < 64; i++) {
164 tdata[i] <<= 1;
165 tdata[i] |= (bdata[i/8] >> (i % 8)) & 0x01;
166 }
167 }
168 } else if (bpp == 8) {
169 for (b = 7; b >= 0; b--) {
170 const u8 *bdata = bitmap + (tile * 256 + chip * 8 + b * 32) * 8;
171 for (i = 0; i < 64; i++) {
172 tdata[i] <<= 1;
173 tdata[i] |= (bdata[i] & 0x80) ? 0x01 : 0x00;
174 }
175 }
176 } else {
177 /* Oops, we should never get here! */
178 WARN_ON(1);
179 return 0;
180 }
181
182 for (i = 0; i < 64; i++)
183 if (tdata[i] != vdata[i]) {
184 changed = 1;
185 vdata[i] = tdata[i];
186 }
187 return changed;
188}
189
190void picolcd_fb_refresh(struct picolcd_data *data)
191{
192 if (data->fb_info)
193 schedule_delayed_work(&data->fb_info->deferred_work, 0);
194}
195
196/* Reconfigure LCD display */
197int picolcd_fb_reset(struct picolcd_data *data, int clear)
198{
199 struct hid_report *report = picolcd_out_report(REPORT_LCD_CMD, data->hdev);
200 struct picolcd_fb_data *fbdata = data->fb_info->par;
201 int i, j;
202 unsigned long flags;
203 static const u8 mapcmd[8] = { 0x00, 0x02, 0x00, 0x64, 0x3f, 0x00, 0x64, 0xc0 };
204
205 if (!report || report->maxfield != 1)
206 return -ENODEV;
207
208 spin_lock_irqsave(&data->lock, flags);
209 for (i = 0; i < 4; i++) {
210 for (j = 0; j < report->field[0]->maxusage; j++)
211 if (j == 0)
212 hid_set_field(report->field[0], j, i << 2);
213 else if (j < sizeof(mapcmd))
214 hid_set_field(report->field[0], j, mapcmd[j]);
215 else
216 hid_set_field(report->field[0], j, 0);
217 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
218 }
219 spin_unlock_irqrestore(&data->lock, flags);
220
221 if (clear) {
222 memset(fbdata->vbitmap, 0, PICOLCDFB_SIZE);
223 memset(fbdata->bitmap, 0, PICOLCDFB_SIZE*fbdata->bpp);
224 }
225 fbdata->force = 1;
226
227 /* schedule first output of framebuffer */
228 if (fbdata->ready)
229 schedule_delayed_work(&data->fb_info->deferred_work, 0);
230 else
231 fbdata->ready = 1;
232
233 return 0;
234}
235
236/* Update fb_vbitmap from the screen_base and send changed tiles to device */
237static void picolcd_fb_update(struct fb_info *info)
238{
239 int chip, tile, n;
240 unsigned long flags;
241 struct picolcd_fb_data *fbdata = info->par;
242 struct picolcd_data *data;
243
244 mutex_lock(&info->lock);
245
246 spin_lock_irqsave(&fbdata->lock, flags);
247 if (!fbdata->ready && fbdata->picolcd)
248 picolcd_fb_reset(fbdata->picolcd, 0);
249 spin_unlock_irqrestore(&fbdata->lock, flags);
250
251 /*
252 * Translate the framebuffer into the format needed by the PicoLCD.
253 * See display layout above.
254 * Do this one tile after the other and push those tiles that changed.
255 *
256 * Wait for our IO to complete as otherwise we might flood the queue!
257 */
258 n = 0;
259 for (chip = 0; chip < 4; chip++)
260 for (tile = 0; tile < 8; tile++) {
261 if (!fbdata->force && !picolcd_fb_update_tile(
262 fbdata->vbitmap, fbdata->bitmap,
263 fbdata->bpp, chip, tile))
264 continue;
265 n += 2;
266 if (n >= HID_OUTPUT_FIFO_SIZE / 2) {
267 spin_lock_irqsave(&fbdata->lock, flags);
268 data = fbdata->picolcd;
269 spin_unlock_irqrestore(&fbdata->lock, flags);
270 mutex_unlock(&info->lock);
271 if (!data)
272 return;
273 usbhid_wait_io(data->hdev);
274 mutex_lock(&info->lock);
275 n = 0;
276 }
277 spin_lock_irqsave(&fbdata->lock, flags);
278 data = fbdata->picolcd;
279 spin_unlock_irqrestore(&fbdata->lock, flags);
280 if (!data || picolcd_fb_send_tile(data,
281 fbdata->vbitmap, chip, tile))
282 goto out;
283 }
284 fbdata->force = false;
285 if (n) {
286 spin_lock_irqsave(&fbdata->lock, flags);
287 data = fbdata->picolcd;
288 spin_unlock_irqrestore(&fbdata->lock, flags);
289 mutex_unlock(&info->lock);
290 if (data)
291 usbhid_wait_io(data->hdev);
292 return;
293 }
294out:
295 mutex_unlock(&info->lock);
296}
297
298/* Stub to call the system default and update the image on the picoLCD */
299static void picolcd_fb_fillrect(struct fb_info *info,
300 const struct fb_fillrect *rect)
301{
302 if (!info->par)
303 return;
304 sys_fillrect(info, rect);
305
306 schedule_delayed_work(&info->deferred_work, 0);
307}
308
309/* Stub to call the system default and update the image on the picoLCD */
310static void picolcd_fb_copyarea(struct fb_info *info,
311 const struct fb_copyarea *area)
312{
313 if (!info->par)
314 return;
315 sys_copyarea(info, area);
316
317 schedule_delayed_work(&info->deferred_work, 0);
318}
319
320/* Stub to call the system default and update the image on the picoLCD */
321static void picolcd_fb_imageblit(struct fb_info *info, const struct fb_image *image)
322{
323 if (!info->par)
324 return;
325 sys_imageblit(info, image);
326
327 schedule_delayed_work(&info->deferred_work, 0);
328}
329
330/*
331 * this is the slow path from userspace. they can seek and write to
332 * the fb. it's inefficient to do anything less than a full screen draw
333 */
334static ssize_t picolcd_fb_write(struct fb_info *info, const char __user *buf,
335 size_t count, loff_t *ppos)
336{
337 ssize_t ret;
338 if (!info->par)
339 return -ENODEV;
340 ret = fb_sys_write(info, buf, count, ppos);
341 if (ret >= 0)
342 schedule_delayed_work(&info->deferred_work, 0);
343 return ret;
344}
345
346static int picolcd_fb_blank(int blank, struct fb_info *info)
347{
348 /* We let fb notification do this for us via lcd/backlight device */
349 return 0;
350}
351
352static void picolcd_fb_destroy(struct fb_info *info)
353{
354 struct picolcd_fb_data *fbdata = info->par;
355
356 /* make sure no work is deferred */
357 fb_deferred_io_cleanup(info);
358
359 /* No thridparty should ever unregister our framebuffer! */
360 WARN_ON(fbdata->picolcd != NULL);
361
362 vfree((u8 *)info->fix.smem_start);
363 framebuffer_release(info);
364}
365
366static int picolcd_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
367{
368 __u32 bpp = var->bits_per_pixel;
369 __u32 activate = var->activate;
370
371 /* only allow 1/8 bit depth (8-bit is grayscale) */
372 *var = picolcdfb_var;
373 var->activate = activate;
374 if (bpp >= 8) {
375 var->bits_per_pixel = 8;
376 var->red.length = 8;
377 var->green.length = 8;
378 var->blue.length = 8;
379 } else {
380 var->bits_per_pixel = 1;
381 var->red.length = 1;
382 var->green.length = 1;
383 var->blue.length = 1;
384 }
385 return 0;
386}
387
388static int picolcd_set_par(struct fb_info *info)
389{
390 struct picolcd_fb_data *fbdata = info->par;
391 u8 *tmp_fb, *o_fb;
392 if (info->var.bits_per_pixel == fbdata->bpp)
393 return 0;
394 /* switch between 1/8 bit depths */
395 if (info->var.bits_per_pixel != 1 && info->var.bits_per_pixel != 8)
396 return -EINVAL;
397
398 o_fb = fbdata->bitmap;
399 tmp_fb = kmalloc(PICOLCDFB_SIZE*info->var.bits_per_pixel, GFP_KERNEL);
400 if (!tmp_fb)
401 return -ENOMEM;
402
403 /* translate FB content to new bits-per-pixel */
404 if (info->var.bits_per_pixel == 1) {
405 int i, b;
406 for (i = 0; i < PICOLCDFB_SIZE; i++) {
407 u8 p = 0;
408 for (b = 0; b < 8; b++) {
409 p <<= 1;
410 p |= o_fb[i*8+b] ? 0x01 : 0x00;
411 }
412 tmp_fb[i] = p;
413 }
414 memcpy(o_fb, tmp_fb, PICOLCDFB_SIZE);
415 info->fix.visual = FB_VISUAL_MONO01;
416 info->fix.line_length = PICOLCDFB_WIDTH / 8;
417 } else {
418 int i;
419 memcpy(tmp_fb, o_fb, PICOLCDFB_SIZE);
420 for (i = 0; i < PICOLCDFB_SIZE * 8; i++)
421 o_fb[i] = tmp_fb[i/8] & (0x01 << (7 - i % 8)) ? 0xff : 0x00;
422 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
423 info->fix.line_length = PICOLCDFB_WIDTH;
424 }
425
426 kfree(tmp_fb);
427 fbdata->bpp = info->var.bits_per_pixel;
428 return 0;
429}
430
431/* Note this can't be const because of struct fb_info definition */
432static struct fb_ops picolcdfb_ops = {
433 .owner = THIS_MODULE,
434 .fb_destroy = picolcd_fb_destroy,
435 .fb_read = fb_sys_read,
436 .fb_write = picolcd_fb_write,
437 .fb_blank = picolcd_fb_blank,
438 .fb_fillrect = picolcd_fb_fillrect,
439 .fb_copyarea = picolcd_fb_copyarea,
440 .fb_imageblit = picolcd_fb_imageblit,
441 .fb_check_var = picolcd_fb_check_var,
442 .fb_set_par = picolcd_set_par,
443};
444
445
446/* Callback from deferred IO workqueue */
447static void picolcd_fb_deferred_io(struct fb_info *info, struct list_head *pagelist)
448{
449 picolcd_fb_update(info);
450}
451
452static const struct fb_deferred_io picolcd_fb_defio = {
453 .delay = HZ / PICOLCDFB_UPDATE_RATE_DEFAULT,
454 .deferred_io = picolcd_fb_deferred_io,
455};
456
457
458/*
459 * The "fb_update_rate" sysfs attribute
460 */
461static ssize_t picolcd_fb_update_rate_show(struct device *dev,
462 struct device_attribute *attr, char *buf)
463{
464 struct picolcd_data *data = dev_get_drvdata(dev);
465 struct picolcd_fb_data *fbdata = data->fb_info->par;
466 unsigned i, fb_update_rate = fbdata->update_rate;
467 size_t ret = 0;
468
469 for (i = 1; i <= PICOLCDFB_UPDATE_RATE_LIMIT; i++)
470 if (ret >= PAGE_SIZE)
471 break;
472 else if (i == fb_update_rate)
473 ret += snprintf(buf+ret, PAGE_SIZE-ret, "[%u] ", i);
474 else
475 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%u ", i);
476 if (ret > 0)
477 buf[min(ret, (size_t)PAGE_SIZE)-1] = '\n';
478 return ret;
479}
480
481static ssize_t picolcd_fb_update_rate_store(struct device *dev,
482 struct device_attribute *attr, const char *buf, size_t count)
483{
484 struct picolcd_data *data = dev_get_drvdata(dev);
485 struct picolcd_fb_data *fbdata = data->fb_info->par;
486 int i;
487 unsigned u;
488
489 if (count < 1 || count > 10)
490 return -EINVAL;
491
492 i = sscanf(buf, "%u", &u);
493 if (i != 1)
494 return -EINVAL;
495
496 if (u > PICOLCDFB_UPDATE_RATE_LIMIT)
497 return -ERANGE;
498 else if (u == 0)
499 u = PICOLCDFB_UPDATE_RATE_DEFAULT;
500
501 fbdata->update_rate = u;
502 data->fb_info->fbdefio->delay = HZ / fbdata->update_rate;
503 return count;
504}
505
506static DEVICE_ATTR(fb_update_rate, 0666, picolcd_fb_update_rate_show,
507 picolcd_fb_update_rate_store);
508
509/* initialize Framebuffer device */
510int picolcd_init_framebuffer(struct picolcd_data *data)
511{
512 struct device *dev = &data->hdev->dev;
513 struct fb_info *info = NULL;
514 struct picolcd_fb_data *fbdata = NULL;
515 int i, error = -ENOMEM;
516 u32 *palette;
517
518 /* The extra memory is:
519 * - 256*u32 for pseudo_palette
520 * - struct fb_deferred_io
521 */
522 info = framebuffer_alloc(256 * sizeof(u32) +
523 sizeof(struct fb_deferred_io) +
524 sizeof(struct picolcd_fb_data) +
525 PICOLCDFB_SIZE, dev);
526 if (info == NULL) {
527 dev_err(dev, "failed to allocate a framebuffer\n");
528 goto err_nomem;
529 }
530
531 info->fbdefio = info->par;
532 *info->fbdefio = picolcd_fb_defio;
533 info->par += sizeof(struct fb_deferred_io);
534 palette = info->par;
535 info->par += 256 * sizeof(u32);
536 for (i = 0; i < 256; i++)
537 palette[i] = i > 0 && i < 16 ? 0xff : 0;
538 info->pseudo_palette = palette;
539 info->fbops = &picolcdfb_ops;
540 info->var = picolcdfb_var;
541 info->fix = picolcdfb_fix;
542 info->fix.smem_len = PICOLCDFB_SIZE*8;
543 info->flags = FBINFO_FLAG_DEFAULT;
544
545 fbdata = info->par;
546 spin_lock_init(&fbdata->lock);
547 fbdata->picolcd = data;
548 fbdata->update_rate = PICOLCDFB_UPDATE_RATE_DEFAULT;
549 fbdata->bpp = picolcdfb_var.bits_per_pixel;
550 fbdata->force = 1;
551 fbdata->vbitmap = info->par + sizeof(struct picolcd_fb_data);
552 fbdata->bitmap = vmalloc(PICOLCDFB_SIZE*8);
553 if (fbdata->bitmap == NULL) {
554 dev_err(dev, "can't get a free page for framebuffer\n");
555 goto err_nomem;
556 }
557 info->screen_base = (char __force __iomem *)fbdata->bitmap;
558 info->fix.smem_start = (unsigned long)fbdata->bitmap;
559 memset(fbdata->vbitmap, 0xff, PICOLCDFB_SIZE);
560 data->fb_info = info;
561
562 error = picolcd_fb_reset(data, 1);
563 if (error) {
564 dev_err(dev, "failed to configure display\n");
565 goto err_cleanup;
566 }
567
568 error = device_create_file(dev, &dev_attr_fb_update_rate);
569 if (error) {
570 dev_err(dev, "failed to create sysfs attributes\n");
571 goto err_cleanup;
572 }
573
574 fb_deferred_io_init(info);
575 error = register_framebuffer(info);
576 if (error) {
577 dev_err(dev, "failed to register framebuffer\n");
578 goto err_sysfs;
579 }
580 return 0;
581
582err_sysfs:
583 device_remove_file(dev, &dev_attr_fb_update_rate);
584 fb_deferred_io_cleanup(info);
585err_cleanup:
586 data->fb_info = NULL;
587
588err_nomem:
589 if (fbdata)
590 vfree(fbdata->bitmap);
591 framebuffer_release(info);
592 return error;
593}
594
595void picolcd_exit_framebuffer(struct picolcd_data *data)
596{
597 struct fb_info *info = data->fb_info;
598 struct picolcd_fb_data *fbdata = info->par;
599 unsigned long flags;
600
601 device_remove_file(&data->hdev->dev, &dev_attr_fb_update_rate);
602
603 /* disconnect framebuffer from HID dev */
604 spin_lock_irqsave(&fbdata->lock, flags);
605 fbdata->picolcd = NULL;
606 spin_unlock_irqrestore(&fbdata->lock, flags);
607
608 /* make sure there is no running update - thus that fbdata->picolcd
609 * once obtained under lock is guaranteed not to get free() under
610 * the feet of the deferred work */
611 flush_delayed_work_sync(&info->deferred_work);
612
613 data->fb_info = NULL;
614 unregister_framebuffer(info);
615}
diff --git a/drivers/hid/hid-picolcd_lcd.c b/drivers/hid/hid-picolcd_lcd.c
new file mode 100644
index 000000000000..2d0ddc5ac65f
--- /dev/null
+++ b/drivers/hid/hid-picolcd_lcd.c
@@ -0,0 +1,107 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include "usbhid/usbhid.h"
22#include <linux/usb.h>
23
24#include <linux/fb.h>
25#include <linux/lcd.h>
26
27#include "hid-picolcd.h"
28
29/*
30 * lcd class device
31 */
32static int picolcd_get_contrast(struct lcd_device *ldev)
33{
34 struct picolcd_data *data = lcd_get_data(ldev);
35 return data->lcd_contrast;
36}
37
38static int picolcd_set_contrast(struct lcd_device *ldev, int contrast)
39{
40 struct picolcd_data *data = lcd_get_data(ldev);
41 struct hid_report *report = picolcd_out_report(REPORT_CONTRAST, data->hdev);
42 unsigned long flags;
43
44 if (!report || report->maxfield != 1 || report->field[0]->report_count != 1)
45 return -ENODEV;
46
47 data->lcd_contrast = contrast & 0x0ff;
48 spin_lock_irqsave(&data->lock, flags);
49 hid_set_field(report->field[0], 0, data->lcd_contrast);
50 if (!(data->status & PICOLCD_FAILED))
51 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
52 spin_unlock_irqrestore(&data->lock, flags);
53 return 0;
54}
55
56static int picolcd_check_lcd_fb(struct lcd_device *ldev, struct fb_info *fb)
57{
58 return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev));
59}
60
61static struct lcd_ops picolcd_lcdops = {
62 .get_contrast = picolcd_get_contrast,
63 .set_contrast = picolcd_set_contrast,
64 .check_fb = picolcd_check_lcd_fb,
65};
66
67int picolcd_init_lcd(struct picolcd_data *data, struct hid_report *report)
68{
69 struct device *dev = &data->hdev->dev;
70 struct lcd_device *ldev;
71
72 if (!report)
73 return -ENODEV;
74 if (report->maxfield != 1 || report->field[0]->report_count != 1 ||
75 report->field[0]->report_size != 8) {
76 dev_err(dev, "unsupported CONTRAST report");
77 return -EINVAL;
78 }
79
80 ldev = lcd_device_register(dev_name(dev), dev, data, &picolcd_lcdops);
81 if (IS_ERR(ldev)) {
82 dev_err(dev, "failed to register LCD\n");
83 return PTR_ERR(ldev);
84 }
85 ldev->props.max_contrast = 0x0ff;
86 data->lcd_contrast = 0xe5;
87 data->lcd = ldev;
88 picolcd_set_contrast(ldev, 0xe5);
89 return 0;
90}
91
92void picolcd_exit_lcd(struct picolcd_data *data)
93{
94 struct lcd_device *ldev = data->lcd;
95
96 data->lcd = NULL;
97 if (ldev)
98 lcd_device_unregister(ldev);
99}
100
101int picolcd_resume_lcd(struct picolcd_data *data)
102{
103 if (!data->lcd)
104 return 0;
105 return picolcd_set_contrast(data->lcd, data->lcd_contrast);
106}
107
diff --git a/drivers/hid/hid-picolcd_leds.c b/drivers/hid/hid-picolcd_leds.c
new file mode 100644
index 000000000000..28cb6a4f9634
--- /dev/null
+++ b/drivers/hid/hid-picolcd_leds.c
@@ -0,0 +1,175 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * 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 *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include <linux/hid-debug.h>
22#include <linux/input.h>
23#include "hid-ids.h"
24#include "usbhid/usbhid.h"
25#include <linux/usb.h>
26
27#include <linux/fb.h>
28#include <linux/vmalloc.h>
29#include <linux/backlight.h>
30#include <linux/lcd.h>
31
32#include <linux/leds.h>
33
34#include <linux/seq_file.h>
35#include <linux/debugfs.h>
36
37#include <linux/completion.h>
38#include <linux/uaccess.h>
39#include <linux/module.h>
40
41#include "hid-picolcd.h"
42
43
44void picolcd_leds_set(struct picolcd_data *data)
45{
46 struct hid_report *report;
47 unsigned long flags;
48
49 if (!data->led[0])
50 return;
51 report = picolcd_out_report(REPORT_LED_STATE, data->hdev);
52 if (!report || report->maxfield != 1 || report->field[0]->report_count != 1)
53 return;
54
55 spin_lock_irqsave(&data->lock, flags);
56 hid_set_field(report->field[0], 0, data->led_state);
57 if (!(data->status & PICOLCD_FAILED))
58 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
59 spin_unlock_irqrestore(&data->lock, flags);
60}
61
62static void picolcd_led_set_brightness(struct led_classdev *led_cdev,
63 enum led_brightness value)
64{
65 struct device *dev;
66 struct hid_device *hdev;
67 struct picolcd_data *data;
68 int i, state = 0;
69
70 dev = led_cdev->dev->parent;
71 hdev = container_of(dev, struct hid_device, dev);
72 data = hid_get_drvdata(hdev);
73 if (!data)
74 return;
75 for (i = 0; i < 8; i++) {
76 if (led_cdev != data->led[i])
77 continue;
78 state = (data->led_state >> i) & 1;
79 if (value == LED_OFF && state) {
80 data->led_state &= ~(1 << i);
81 picolcd_leds_set(data);
82 } else if (value != LED_OFF && !state) {
83 data->led_state |= 1 << i;
84 picolcd_leds_set(data);
85 }
86 break;
87 }
88}
89
90static enum led_brightness picolcd_led_get_brightness(struct led_classdev *led_cdev)
91{
92 struct device *dev;
93 struct hid_device *hdev;
94 struct picolcd_data *data;
95 int i, value = 0;
96
97 dev = led_cdev->dev->parent;
98 hdev = container_of(dev, struct hid_device, dev);
99 data = hid_get_drvdata(hdev);
100 for (i = 0; i < 8; i++)
101 if (led_cdev == data->led[i]) {
102 value = (data->led_state >> i) & 1;
103 break;
104 }
105 return value ? LED_FULL : LED_OFF;
106}
107
108int picolcd_init_leds(struct picolcd_data *data, struct hid_report *report)
109{
110 struct device *dev = &data->hdev->dev;
111 struct led_classdev *led;
112 size_t name_sz = strlen(dev_name(dev)) + 8;
113 char *name;
114 int i, ret = 0;
115
116 if (!report)
117 return -ENODEV;
118 if (report->maxfield != 1 || report->field[0]->report_count != 1 ||
119 report->field[0]->report_size != 8) {
120 dev_err(dev, "unsupported LED_STATE report");
121 return -EINVAL;
122 }
123
124 for (i = 0; i < 8; i++) {
125 led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL);
126 if (!led) {
127 dev_err(dev, "can't allocate memory for LED %d\n", i);
128 ret = -ENOMEM;
129 goto err;
130 }
131 name = (void *)(&led[1]);
132 snprintf(name, name_sz, "%s::GPO%d", dev_name(dev), i);
133 led->name = name;
134 led->brightness = 0;
135 led->max_brightness = 1;
136 led->brightness_get = picolcd_led_get_brightness;
137 led->brightness_set = picolcd_led_set_brightness;
138
139 data->led[i] = led;
140 ret = led_classdev_register(dev, data->led[i]);
141 if (ret) {
142 data->led[i] = NULL;
143 kfree(led);
144 dev_err(dev, "can't register LED %d\n", i);
145 goto err;
146 }
147 }
148 return 0;
149err:
150 for (i = 0; i < 8; i++)
151 if (data->led[i]) {
152 led = data->led[i];
153 data->led[i] = NULL;
154 led_classdev_unregister(led);
155 kfree(led);
156 }
157 return ret;
158}
159
160void picolcd_exit_leds(struct picolcd_data *data)
161{
162 struct led_classdev *led;
163 int i;
164
165 for (i = 0; i < 8; i++) {
166 led = data->led[i];
167 data->led[i] = NULL;
168 if (!led)
169 continue;
170 led_classdev_unregister(led);
171 kfree(led);
172 }
173}
174
175
diff --git a/drivers/hid/hid-primax.c b/drivers/hid/hid-primax.c
index 4d3c60d88318..c15adb0c98a1 100644
--- a/drivers/hid/hid-primax.c
+++ b/drivers/hid/hid-primax.c
@@ -64,29 +64,6 @@ static int px_raw_event(struct hid_device *hid, struct hid_report *report,
64 return 0; 64 return 0;
65} 65}
66 66
67static int px_probe(struct hid_device *hid, const struct hid_device_id *id)
68{
69 int ret;
70
71 ret = hid_parse(hid);
72 if (ret) {
73 hid_err(hid, "parse failed\n");
74 goto fail;
75 }
76
77 ret = hid_hw_start(hid, HID_CONNECT_DEFAULT);
78 if (ret)
79 hid_err(hid, "hw start failed\n");
80
81fail:
82 return ret;
83}
84
85static void px_remove(struct hid_device *hid)
86{
87 hid_hw_stop(hid);
88}
89
90static const struct hid_device_id px_devices[] = { 67static const struct hid_device_id px_devices[] = {
91 { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) }, 68 { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
92 { } 69 { }
@@ -97,8 +74,6 @@ static struct hid_driver px_driver = {
97 .name = "primax", 74 .name = "primax",
98 .id_table = px_devices, 75 .id_table = px_devices,
99 .raw_event = px_raw_event, 76 .raw_event = px_raw_event,
100 .probe = px_probe,
101 .remove = px_remove,
102}; 77};
103 78
104static int __init px_init(void) 79static int __init px_init(void)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index b71b77ab0dc7..ec8ca3336315 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -105,7 +105,7 @@ static ssize_t show_channel(struct device *dev,
105 struct device_attribute *attr, char *buf) 105 struct device_attribute *attr, char *buf)
106{ 106{
107 struct hid_device *hdev = container_of(dev, struct hid_device, dev); 107 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
108 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 108 struct pk_device *pk = hid_get_drvdata(hdev);
109 109
110 dbg_hid("pcmidi sysfs read channel=%u\n", pk->pm->midi_channel); 110 dbg_hid("pcmidi sysfs read channel=%u\n", pk->pm->midi_channel);
111 111
@@ -118,7 +118,7 @@ static ssize_t store_channel(struct device *dev,
118 struct device_attribute *attr, const char *buf, size_t count) 118 struct device_attribute *attr, const char *buf, size_t count)
119{ 119{
120 struct hid_device *hdev = container_of(dev, struct hid_device, dev); 120 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
121 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 121 struct pk_device *pk = hid_get_drvdata(hdev);
122 122
123 unsigned channel = 0; 123 unsigned channel = 0;
124 124
@@ -142,7 +142,7 @@ static ssize_t show_sustain(struct device *dev,
142 struct device_attribute *attr, char *buf) 142 struct device_attribute *attr, char *buf)
143{ 143{
144 struct hid_device *hdev = container_of(dev, struct hid_device, dev); 144 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
145 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 145 struct pk_device *pk = hid_get_drvdata(hdev);
146 146
147 dbg_hid("pcmidi sysfs read sustain=%u\n", pk->pm->midi_sustain); 147 dbg_hid("pcmidi sysfs read sustain=%u\n", pk->pm->midi_sustain);
148 148
@@ -155,7 +155,7 @@ static ssize_t store_sustain(struct device *dev,
155 struct device_attribute *attr, const char *buf, size_t count) 155 struct device_attribute *attr, const char *buf, size_t count)
156{ 156{
157 struct hid_device *hdev = container_of(dev, struct hid_device, dev); 157 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
158 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 158 struct pk_device *pk = hid_get_drvdata(hdev);
159 159
160 unsigned sustain = 0; 160 unsigned sustain = 0;
161 161
@@ -181,7 +181,7 @@ static ssize_t show_octave(struct device *dev,
181 struct device_attribute *attr, char *buf) 181 struct device_attribute *attr, char *buf)
182{ 182{
183 struct hid_device *hdev = container_of(dev, struct hid_device, dev); 183 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
184 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 184 struct pk_device *pk = hid_get_drvdata(hdev);
185 185
186 dbg_hid("pcmidi sysfs read octave=%d\n", pk->pm->midi_octave); 186 dbg_hid("pcmidi sysfs read octave=%d\n", pk->pm->midi_octave);
187 187
@@ -194,7 +194,7 @@ static ssize_t store_octave(struct device *dev,
194 struct device_attribute *attr, const char *buf, size_t count) 194 struct device_attribute *attr, const char *buf, size_t count)
195{ 195{
196 struct hid_device *hdev = container_of(dev, struct hid_device, dev); 196 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
197 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 197 struct pk_device *pk = hid_get_drvdata(hdev);
198 198
199 int octave = 0; 199 int octave = 0;
200 200
@@ -759,7 +759,7 @@ static int pk_input_mapping(struct hid_device *hdev, struct hid_input *hi,
759 struct hid_field *field, struct hid_usage *usage, 759 struct hid_field *field, struct hid_usage *usage,
760 unsigned long **bit, int *max) 760 unsigned long **bit, int *max)
761{ 761{
762 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 762 struct pk_device *pk = hid_get_drvdata(hdev);
763 struct pcmidi_snd *pm; 763 struct pcmidi_snd *pm;
764 764
765 pm = pk->pm; 765 pm = pk->pm;
@@ -777,7 +777,7 @@ static int pk_input_mapping(struct hid_device *hdev, struct hid_input *hi,
777static int pk_raw_event(struct hid_device *hdev, struct hid_report *report, 777static int pk_raw_event(struct hid_device *hdev, struct hid_report *report,
778 u8 *data, int size) 778 u8 *data, int size)
779{ 779{
780 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 780 struct pk_device *pk = hid_get_drvdata(hdev);
781 int ret = 0; 781 int ret = 0;
782 782
783 if (1 == pk->pm->ifnum) { 783 if (1 == pk->pm->ifnum) {
@@ -858,7 +858,7 @@ err_free_pk:
858 858
859static void pk_remove(struct hid_device *hdev) 859static void pk_remove(struct hid_device *hdev)
860{ 860{
861 struct pk_device *pk = (struct pk_device *)hid_get_drvdata(hdev); 861 struct pk_device *pk = hid_get_drvdata(hdev);
862 struct pcmidi_snd *pm; 862 struct pcmidi_snd *pm;
863 863
864 pm = pk->pm; 864 pm = pk->pm;
diff --git a/drivers/hid/hid-ps3remote.c b/drivers/hid/hid-ps3remote.c
new file mode 100644
index 000000000000..03811e539d71
--- /dev/null
+++ b/drivers/hid/hid-ps3remote.c
@@ -0,0 +1,215 @@
1/*
2 * HID driver for Sony PS3 BD Remote Control
3 *
4 * Copyright (c) 2012 David Dillow <dave@thedillows.org>
5 * Based on a blend of the bluez fakehid user-space code by Marcel Holtmann
6 * and other kernel HID drivers.
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 */
15
16/* NOTE: in order for the Sony PS3 BD Remote Control to be found by
17 * a Bluetooth host, the key combination Start+Enter has to be kept pressed
18 * for about 7 seconds with the Bluetooth Host Controller in discovering mode.
19 *
20 * There will be no PIN request from the device.
21 */
22
23#include <linux/device.h>
24#include <linux/hid.h>
25#include <linux/module.h>
26
27#include "hid-ids.h"
28
29static __u8 ps3remote_rdesc[] = {
30 0x05, 0x01, /* GUsagePage Generic Desktop */
31 0x09, 0x05, /* LUsage 0x05 [Game Pad] */
32 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */
33
34 /* Use collection 1 for joypad buttons */
35 0xA1, 0x02, /* MCollection Logical (interrelated data) */
36
37 /* Ignore the 1st byte, maybe it is used for a controller
38 * number but it's not needed for correct operation */
39 0x75, 0x08, /* GReportSize 0x08 [8] */
40 0x95, 0x01, /* GReportCount 0x01 [1] */
41 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
42
43 /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these
44 * buttons multiple keypresses are allowed */
45 0x05, 0x09, /* GUsagePage Button */
46 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */
47 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */
48 0x14, /* GLogicalMinimum [0] */
49 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */
50 0x75, 0x01, /* GReportSize 0x01 [1] */
51 0x95, 0x18, /* GReportCount 0x18 [24] */
52 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
53
54 0xC0, /* MEndCollection */
55
56 /* Use collection 2 for remote control buttons */
57 0xA1, 0x02, /* MCollection Logical (interrelated data) */
58
59 /* 5th byte is used for remote control buttons */
60 0x05, 0x09, /* GUsagePage Button */
61 0x18, /* LUsageMinimum [No button pressed] */
62 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */
63 0x14, /* GLogicalMinimum [0] */
64 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */
65 0x75, 0x08, /* GReportSize 0x08 [8] */
66 0x95, 0x01, /* GReportCount 0x01 [1] */
67 0x80, /* MInput */
68
69 /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at
70 * 0xff and 11th is for press indication */
71 0x75, 0x08, /* GReportSize 0x08 [8] */
72 0x95, 0x06, /* GReportCount 0x06 [6] */
73 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
74
75 /* 12th byte is for battery strength */
76 0x05, 0x06, /* GUsagePage Generic Device Controls */
77 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */
78 0x14, /* GLogicalMinimum [0] */
79 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */
80 0x75, 0x08, /* GReportSize 0x08 [8] */
81 0x95, 0x01, /* GReportCount 0x01 [1] */
82 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
83
84 0xC0, /* MEndCollection */
85
86 0xC0 /* MEndCollection [Game Pad] */
87};
88
89static const unsigned int ps3remote_keymap_joypad_buttons[] = {
90 [0x01] = KEY_SELECT,
91 [0x02] = BTN_THUMBL, /* L3 */
92 [0x03] = BTN_THUMBR, /* R3 */
93 [0x04] = BTN_START,
94 [0x05] = KEY_UP,
95 [0x06] = KEY_RIGHT,
96 [0x07] = KEY_DOWN,
97 [0x08] = KEY_LEFT,
98 [0x09] = BTN_TL2, /* L2 */
99 [0x0a] = BTN_TR2, /* R2 */
100 [0x0b] = BTN_TL, /* L1 */
101 [0x0c] = BTN_TR, /* R1 */
102 [0x0d] = KEY_OPTION, /* options/triangle */
103 [0x0e] = KEY_BACK, /* back/circle */
104 [0x0f] = BTN_0, /* cross */
105 [0x10] = KEY_SCREEN, /* view/square */
106 [0x11] = KEY_HOMEPAGE, /* PS button */
107 [0x14] = KEY_ENTER,
108};
109static const unsigned int ps3remote_keymap_remote_buttons[] = {
110 [0x00] = KEY_1,
111 [0x01] = KEY_2,
112 [0x02] = KEY_3,
113 [0x03] = KEY_4,
114 [0x04] = KEY_5,
115 [0x05] = KEY_6,
116 [0x06] = KEY_7,
117 [0x07] = KEY_8,
118 [0x08] = KEY_9,
119 [0x09] = KEY_0,
120 [0x0e] = KEY_ESC, /* return */
121 [0x0f] = KEY_CLEAR,
122 [0x16] = KEY_EJECTCD,
123 [0x1a] = KEY_MENU, /* top menu */
124 [0x28] = KEY_TIME,
125 [0x30] = KEY_PREVIOUS,
126 [0x31] = KEY_NEXT,
127 [0x32] = KEY_PLAY,
128 [0x33] = KEY_REWIND, /* scan back */
129 [0x34] = KEY_FORWARD, /* scan forward */
130 [0x38] = KEY_STOP,
131 [0x39] = KEY_PAUSE,
132 [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */
133 [0x60] = KEY_FRAMEBACK, /* slow/step back */
134 [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */
135 [0x63] = KEY_SUBTITLE,
136 [0x64] = KEY_AUDIO,
137 [0x65] = KEY_ANGLE,
138 [0x70] = KEY_INFO, /* display */
139 [0x80] = KEY_BLUE,
140 [0x81] = KEY_RED,
141 [0x82] = KEY_GREEN,
142 [0x83] = KEY_YELLOW,
143};
144
145static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc,
146 unsigned int *rsize)
147{
148 *rsize = sizeof(ps3remote_rdesc);
149 return ps3remote_rdesc;
150}
151
152static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi,
153 struct hid_field *field, struct hid_usage *usage,
154 unsigned long **bit, int *max)
155{
156 unsigned int key = usage->hid & HID_USAGE;
157
158 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
159 return -1;
160
161 switch (usage->collection_index) {
162 case 1:
163 if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons))
164 return -1;
165
166 key = ps3remote_keymap_joypad_buttons[key];
167 if (!key)
168 return -1;
169 break;
170 case 2:
171 if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons))
172 return -1;
173
174 key = ps3remote_keymap_remote_buttons[key];
175 if (!key)
176 return -1;
177 break;
178 default:
179 return -1;
180 }
181
182 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
183 return 1;
184}
185
186static const struct hid_device_id ps3remote_devices[] = {
187 /* PS3 BD Remote Control */
188 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
189 /* Logitech Harmony Adapter for PS3 */
190 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
191 { }
192};
193MODULE_DEVICE_TABLE(hid, ps3remote_devices);
194
195static struct hid_driver ps3remote_driver = {
196 .name = "ps3_remote",
197 .id_table = ps3remote_devices,
198 .report_fixup = ps3remote_fixup,
199 .input_mapping = ps3remote_mapping,
200};
201
202static int __init ps3remote_init(void)
203{
204 return hid_register_driver(&ps3remote_driver);
205}
206
207static void __exit ps3remote_exit(void)
208{
209 hid_unregister_driver(&ps3remote_driver);
210}
211
212module_init(ps3remote_init);
213module_exit(ps3remote_exit);
214MODULE_LICENSE("GPL");
215MODULE_AUTHOR("David Dillow <dave@thedillows.org>, Antonio Ospite <ospite@studenti.unina.it>");
diff --git a/drivers/hid/hid-samsung.c b/drivers/hid/hid-samsung.c
index 3c1fd8af5e0c..a5821d317229 100644
--- a/drivers/hid/hid-samsung.c
+++ b/drivers/hid/hid-samsung.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 * Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk> 9 * Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk>
11 * 10 *
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 5cd25bd907f8..7f33ebf299c2 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -4,7 +4,6 @@
4 * Copyright (c) 1999 Andreas Gal 4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2007 Paul Walmsley
8 * Copyright (c) 2008 Jiri Slaby 7 * Copyright (c) 2008 Jiri Slaby
9 * Copyright (c) 2006-2008 Jiri Kosina 8 * Copyright (c) 2006-2008 Jiri Kosina
10 */ 9 */
diff --git a/drivers/hid/hid-sunplus.c b/drivers/hid/hid-sunplus.c
index d484a0043dd4..45b4b066a262 100644
--- a/drivers/hid/hid-sunplus.c
+++ b/drivers/hid/hid-sunplus.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby 8 * Copyright (c) 2008 Jiri Slaby
10 */ 9 */
11 10
diff --git a/drivers/hid/hid-uclogic.c b/drivers/hid/hid-uclogic.c
index 3aba02be1f26..2e56a1fd2375 100644
--- a/drivers/hid/hid-uclogic.c
+++ b/drivers/hid/hid-uclogic.c
@@ -466,6 +466,86 @@ static __u8 twhl850_rdesc_fixed2[] = {
466 0xC0 /* End Collection */ 466 0xC0 /* End Collection */
467}; 467};
468 468
469/*
470 * See TWHA60 description, device and HID report descriptors at
471 * http://sf.net/apps/mediawiki/digimend/?title=UC-Logic_Tablet_TWHA60
472 */
473
474/* Size of the original descriptors of TWHA60 tablet */
475#define TWHA60_RDESC_ORIG_SIZE0 254
476#define TWHA60_RDESC_ORIG_SIZE1 139
477
478/* Fixed TWHA60 report descriptor, interface 0 (stylus) */
479static __u8 twha60_rdesc_fixed0[] = {
480 0x05, 0x0D, /* Usage Page (Digitizer), */
481 0x09, 0x02, /* Usage (Pen), */
482 0xA1, 0x01, /* Collection (Application), */
483 0x85, 0x09, /* Report ID (9), */
484 0x09, 0x20, /* Usage (Stylus), */
485 0xA0, /* Collection (Physical), */
486 0x75, 0x01, /* Report Size (1), */
487 0x09, 0x42, /* Usage (Tip Switch), */
488 0x09, 0x44, /* Usage (Barrel Switch), */
489 0x09, 0x46, /* Usage (Tablet Pick), */
490 0x14, /* Logical Minimum (0), */
491 0x25, 0x01, /* Logical Maximum (1), */
492 0x95, 0x03, /* Report Count (3), */
493 0x81, 0x02, /* Input (Variable), */
494 0x95, 0x04, /* Report Count (4), */
495 0x81, 0x01, /* Input (Constant), */
496 0x09, 0x32, /* Usage (In Range), */
497 0x95, 0x01, /* Report Count (1), */
498 0x81, 0x02, /* Input (Variable), */
499 0x75, 0x10, /* Report Size (16), */
500 0x95, 0x01, /* Report Count (1), */
501 0x14, /* Logical Minimum (0), */
502 0xA4, /* Push, */
503 0x05, 0x01, /* Usage Page (Desktop), */
504 0x55, 0xFD, /* Unit Exponent (-3), */
505 0x65, 0x13, /* Unit (Inch), */
506 0x34, /* Physical Minimum (0), */
507 0x09, 0x30, /* Usage (X), */
508 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
509 0x27, 0x3F, 0x9C,
510 0x00, 0x00, /* Logical Maximum (39999), */
511 0x81, 0x02, /* Input (Variable), */
512 0x09, 0x31, /* Usage (Y), */
513 0x46, 0x6A, 0x18, /* Physical Maximum (6250), */
514 0x26, 0xA7, 0x61, /* Logical Maximum (24999), */
515 0x81, 0x02, /* Input (Variable), */
516 0xB4, /* Pop, */
517 0x09, 0x30, /* Usage (Tip Pressure), */
518 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
519 0x81, 0x02, /* Input (Variable), */
520 0xC0, /* End Collection, */
521 0xC0 /* End Collection */
522};
523
524/* Fixed TWHA60 report descriptor, interface 1 (frame buttons) */
525static __u8 twha60_rdesc_fixed1[] = {
526 0x05, 0x01, /* Usage Page (Desktop), */
527 0x09, 0x06, /* Usage (Keyboard), */
528 0xA1, 0x01, /* Collection (Application), */
529 0x85, 0x05, /* Report ID (5), */
530 0x05, 0x07, /* Usage Page (Keyboard), */
531 0x14, /* Logical Minimum (0), */
532 0x25, 0x01, /* Logical Maximum (1), */
533 0x75, 0x01, /* Report Size (1), */
534 0x95, 0x08, /* Report Count (8), */
535 0x81, 0x01, /* Input (Constant), */
536 0x95, 0x0C, /* Report Count (12), */
537 0x19, 0x3A, /* Usage Minimum (KB F1), */
538 0x29, 0x45, /* Usage Maximum (KB F12), */
539 0x81, 0x02, /* Input (Variable), */
540 0x95, 0x0C, /* Report Count (12), */
541 0x19, 0x68, /* Usage Minimum (KB F13), */
542 0x29, 0x73, /* Usage Maximum (KB F24), */
543 0x81, 0x02, /* Input (Variable), */
544 0x95, 0x08, /* Report Count (8), */
545 0x81, 0x01, /* Input (Constant), */
546 0xC0 /* End Collection */
547};
548
469static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc, 549static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
470 unsigned int *rsize) 550 unsigned int *rsize)
471{ 551{
@@ -525,6 +605,22 @@ static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
525 break; 605 break;
526 } 606 }
527 break; 607 break;
608 case USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60:
609 switch (iface_num) {
610 case 0:
611 if (*rsize == TWHA60_RDESC_ORIG_SIZE0) {
612 rdesc = twha60_rdesc_fixed0;
613 *rsize = sizeof(twha60_rdesc_fixed0);
614 }
615 break;
616 case 1:
617 if (*rsize == TWHA60_RDESC_ORIG_SIZE1) {
618 rdesc = twha60_rdesc_fixed1;
619 *rsize = sizeof(twha60_rdesc_fixed1);
620 }
621 break;
622 }
623 break;
528 } 624 }
529 625
530 return rdesc; 626 return rdesc;
@@ -543,6 +639,8 @@ static const struct hid_device_id uclogic_devices[] = {
543 USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) }, 639 USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
544 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, 640 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
545 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) }, 641 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
642 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
643 USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
546 { } 644 { }
547}; 645};
548MODULE_DEVICE_TABLE(hid, uclogic_devices); 646MODULE_DEVICE_TABLE(hid, uclogic_devices);
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c
index fe23a1eb586b..2f60da9ed066 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -5,7 +5,6 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com> 8 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
10 * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru> 9 * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru>
11 * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net> 10 * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net>
@@ -33,6 +32,8 @@
33#define PAD_DEVICE_ID 0x0F 32#define PAD_DEVICE_ID 0x0F
34 33
35#define WAC_CMD_LED_CONTROL 0x20 34#define WAC_CMD_LED_CONTROL 0x20
35#define WAC_CMD_ICON_START_STOP 0x21
36#define WAC_CMD_ICON_TRANSFER 0x26
36 37
37struct wacom_data { 38struct wacom_data {
38 __u16 tool; 39 __u16 tool;
@@ -69,6 +70,91 @@ static enum power_supply_property wacom_ac_props[] = {
69 POWER_SUPPLY_PROP_SCOPE, 70 POWER_SUPPLY_PROP_SCOPE,
70}; 71};
71 72
73static void wacom_scramble(__u8 *image)
74{
75 __u16 mask;
76 __u16 s1;
77 __u16 s2;
78 __u16 r1 ;
79 __u16 r2 ;
80 __u16 r;
81 __u8 buf[256];
82 int i, w, x, y, z;
83
84 for (x = 0; x < 32; x++) {
85 for (y = 0; y < 8; y++)
86 buf[(8 * x) + (7 - y)] = image[(8 * x) + y];
87 }
88
89 /* Change 76543210 into GECA6420 as required by Intuos4 WL
90 * HGFEDCBA HFDB7531
91 */
92 for (x = 0; x < 4; x++) {
93 for (y = 0; y < 4; y++) {
94 for (z = 0; z < 8; z++) {
95 mask = 0x0001;
96 r1 = 0;
97 r2 = 0;
98 i = (x << 6) + (y << 4) + z;
99 s1 = buf[i];
100 s2 = buf[i+8];
101 for (w = 0; w < 8; w++) {
102 r1 |= (s1 & mask);
103 r2 |= (s2 & mask);
104 s1 <<= 1;
105 s2 <<= 1;
106 mask <<= 2;
107 }
108 r = r1 | (r2 << 1);
109 i = (x << 6) + (y << 4) + (z << 1);
110 image[i] = 0xFF & r;
111 image[i+1] = (0xFF00 & r) >> 8;
112 }
113 }
114 }
115}
116
117static void wacom_set_image(struct hid_device *hdev, const char *image,
118 __u8 icon_no)
119{
120 __u8 rep_data[68];
121 __u8 p[256];
122 int ret, i, j;
123
124 for (i = 0; i < 256; i++)
125 p[i] = image[i];
126
127 rep_data[0] = WAC_CMD_ICON_START_STOP;
128 rep_data[1] = 0;
129 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
130 HID_FEATURE_REPORT);
131 if (ret < 0)
132 goto err;
133
134 rep_data[0] = WAC_CMD_ICON_TRANSFER;
135 rep_data[1] = icon_no & 0x07;
136
137 wacom_scramble(p);
138
139 for (i = 0; i < 4; i++) {
140 for (j = 0; j < 64; j++)
141 rep_data[j + 3] = p[(i << 6) + j];
142
143 rep_data[2] = i;
144 ret = hdev->hid_output_raw_report(hdev, rep_data, 67,
145 HID_FEATURE_REPORT);
146 }
147
148 rep_data[0] = WAC_CMD_ICON_START_STOP;
149 rep_data[1] = 0;
150
151 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
152 HID_FEATURE_REPORT);
153
154err:
155 return;
156}
157
72static void wacom_leds_set_brightness(struct led_classdev *led_dev, 158static void wacom_leds_set_brightness(struct led_classdev *led_dev,
73 enum led_brightness value) 159 enum led_brightness value)
74{ 160{
@@ -91,7 +177,10 @@ static void wacom_leds_set_brightness(struct led_classdev *led_dev,
91 if (buf) { 177 if (buf) {
92 buf[0] = WAC_CMD_LED_CONTROL; 178 buf[0] = WAC_CMD_LED_CONTROL;
93 buf[1] = led; 179 buf[1] = led;
94 buf[2] = value; 180 buf[2] = value >> 2;
181 buf[3] = value;
182 /* use fixed brightness for OLEDs */
183 buf[4] = 0x08;
95 hdev->hid_output_raw_report(hdev, buf, 9, HID_FEATURE_REPORT); 184 hdev->hid_output_raw_report(hdev, buf, 9, HID_FEATURE_REPORT);
96 kfree(buf); 185 kfree(buf);
97 } 186 }
@@ -317,6 +406,34 @@ static ssize_t wacom_store_speed(struct device *dev,
317static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP, 406static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
318 wacom_show_speed, wacom_store_speed); 407 wacom_show_speed, wacom_store_speed);
319 408
409#define WACOM_STORE(OLED_ID) \
410static ssize_t wacom_oled##OLED_ID##_store(struct device *dev, \
411 struct device_attribute *attr, \
412 const char *buf, size_t count) \
413{ \
414 struct hid_device *hdev = container_of(dev, struct hid_device, \
415 dev); \
416 \
417 if (count != 256) \
418 return -EINVAL; \
419 \
420 wacom_set_image(hdev, buf, OLED_ID); \
421 \
422 return count; \
423} \
424 \
425static DEVICE_ATTR(oled##OLED_ID##_img, S_IWUSR | S_IWGRP, NULL, \
426 wacom_oled##OLED_ID##_store)
427
428WACOM_STORE(0);
429WACOM_STORE(1);
430WACOM_STORE(2);
431WACOM_STORE(3);
432WACOM_STORE(4);
433WACOM_STORE(5);
434WACOM_STORE(6);
435WACOM_STORE(7);
436
320static int wacom_gr_parse_report(struct hid_device *hdev, 437static int wacom_gr_parse_report(struct hid_device *hdev,
321 struct wacom_data *wdata, 438 struct wacom_data *wdata,
322 struct input_dev *input, unsigned char *data) 439 struct input_dev *input, unsigned char *data)
@@ -717,17 +834,33 @@ static int wacom_probe(struct hid_device *hdev,
717 hid_warn(hdev, 834 hid_warn(hdev,
718 "can't create sysfs speed attribute err: %d\n", ret); 835 "can't create sysfs speed attribute err: %d\n", ret);
719 836
837#define OLED_INIT(OLED_ID) \
838 do { \
839 ret = device_create_file(&hdev->dev, \
840 &dev_attr_oled##OLED_ID##_img); \
841 if (ret) \
842 hid_warn(hdev, \
843 "can't create sysfs oled attribute, err: %d\n", ret);\
844 } while (0)
845
846OLED_INIT(0);
847OLED_INIT(1);
848OLED_INIT(2);
849OLED_INIT(3);
850OLED_INIT(4);
851OLED_INIT(5);
852OLED_INIT(6);
853OLED_INIT(7);
854
720 wdata->features = 0; 855 wdata->features = 0;
721 wacom_set_features(hdev, 1); 856 wacom_set_features(hdev, 1);
722 857
723 if (hdev->product == USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) { 858 if (hdev->product == USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) {
724 sprintf(hdev->name, "%s", "Wacom Intuos4 WL"); 859 sprintf(hdev->name, "%s", "Wacom Intuos4 WL");
725 ret = wacom_initialize_leds(hdev); 860 ret = wacom_initialize_leds(hdev);
726 if (ret) { 861 if (ret)
727 hid_warn(hdev, 862 hid_warn(hdev,
728 "can't create led attribute, err: %d\n", ret); 863 "can't create led attribute, err: %d\n", ret);
729 goto destroy_leds;
730 }
731 } 864 }
732 865
733 wdata->battery.properties = wacom_battery_props; 866 wdata->battery.properties = wacom_battery_props;
@@ -740,8 +873,8 @@ static int wacom_probe(struct hid_device *hdev,
740 873
741 ret = power_supply_register(&hdev->dev, &wdata->battery); 874 ret = power_supply_register(&hdev->dev, &wdata->battery);
742 if (ret) { 875 if (ret) {
743 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n", 876 hid_err(hdev, "can't create sysfs battery attribute, err: %d\n",
744 ret); 877 ret);
745 goto err_battery; 878 goto err_battery;
746 } 879 }
747 880
@@ -756,8 +889,8 @@ static int wacom_probe(struct hid_device *hdev,
756 889
757 ret = power_supply_register(&hdev->dev, &wdata->ac); 890 ret = power_supply_register(&hdev->dev, &wdata->ac);
758 if (ret) { 891 if (ret) {
759 hid_warn(hdev, 892 hid_err(hdev,
760 "can't create ac battery attribute, err: %d\n", ret); 893 "can't create ac battery attribute, err: %d\n", ret);
761 goto err_ac; 894 goto err_ac;
762 } 895 }
763 896
@@ -767,10 +900,17 @@ static int wacom_probe(struct hid_device *hdev,
767err_ac: 900err_ac:
768 power_supply_unregister(&wdata->battery); 901 power_supply_unregister(&wdata->battery);
769err_battery: 902err_battery:
903 wacom_destroy_leds(hdev);
904 device_remove_file(&hdev->dev, &dev_attr_oled0_img);
905 device_remove_file(&hdev->dev, &dev_attr_oled1_img);
906 device_remove_file(&hdev->dev, &dev_attr_oled2_img);
907 device_remove_file(&hdev->dev, &dev_attr_oled3_img);
908 device_remove_file(&hdev->dev, &dev_attr_oled4_img);
909 device_remove_file(&hdev->dev, &dev_attr_oled5_img);
910 device_remove_file(&hdev->dev, &dev_attr_oled6_img);
911 device_remove_file(&hdev->dev, &dev_attr_oled7_img);
770 device_remove_file(&hdev->dev, &dev_attr_speed); 912 device_remove_file(&hdev->dev, &dev_attr_speed);
771 hid_hw_stop(hdev); 913 hid_hw_stop(hdev);
772destroy_leds:
773 wacom_destroy_leds(hdev);
774err_free: 914err_free:
775 kfree(wdata); 915 kfree(wdata);
776 return ret; 916 return ret;
@@ -781,6 +921,14 @@ static void wacom_remove(struct hid_device *hdev)
781 struct wacom_data *wdata = hid_get_drvdata(hdev); 921 struct wacom_data *wdata = hid_get_drvdata(hdev);
782 922
783 wacom_destroy_leds(hdev); 923 wacom_destroy_leds(hdev);
924 device_remove_file(&hdev->dev, &dev_attr_oled0_img);
925 device_remove_file(&hdev->dev, &dev_attr_oled1_img);
926 device_remove_file(&hdev->dev, &dev_attr_oled2_img);
927 device_remove_file(&hdev->dev, &dev_attr_oled3_img);
928 device_remove_file(&hdev->dev, &dev_attr_oled4_img);
929 device_remove_file(&hdev->dev, &dev_attr_oled5_img);
930 device_remove_file(&hdev->dev, &dev_attr_oled6_img);
931 device_remove_file(&hdev->dev, &dev_attr_oled7_img);
784 device_remove_file(&hdev->dev, &dev_attr_speed); 932 device_remove_file(&hdev->dev, &dev_attr_speed);
785 hid_hw_stop(hdev); 933 hid_hw_stop(hdev);
786 934
diff --git a/drivers/hid/hid-waltop.c b/drivers/hid/hid-waltop.c
index 745e4e9a8cf2..bb536ab5941e 100644
--- a/drivers/hid/hid-waltop.c
+++ b/drivers/hid/hid-waltop.c
@@ -638,28 +638,6 @@ static __u8 sirius_battery_free_tablet_rdesc_fixed[] = {
638 0xC0 /* End Collection */ 638 0xC0 /* End Collection */
639}; 639};
640 640
641static int waltop_probe(struct hid_device *hdev,
642 const struct hid_device_id *id)
643{
644 int ret;
645
646 ret = hid_parse(hdev);
647 if (ret) {
648 hid_err(hdev, "parse failed\n");
649 goto err;
650 }
651
652 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
653 if (ret) {
654 hid_err(hdev, "hw start failed\n");
655 goto err;
656 }
657
658 return 0;
659err:
660 return ret;
661}
662
663static __u8 *waltop_report_fixup(struct hid_device *hdev, __u8 *rdesc, 641static __u8 *waltop_report_fixup(struct hid_device *hdev, __u8 *rdesc,
664 unsigned int *rsize) 642 unsigned int *rsize)
665{ 643{
@@ -776,11 +754,6 @@ static int waltop_raw_event(struct hid_device *hdev, struct hid_report *report,
776 return 0; 754 return 0;
777} 755}
778 756
779static void waltop_remove(struct hid_device *hdev)
780{
781 hid_hw_stop(hdev);
782}
783
784static const struct hid_device_id waltop_devices[] = { 757static const struct hid_device_id waltop_devices[] = {
785 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, 758 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
786 USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) }, 759 USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
@@ -803,10 +776,8 @@ MODULE_DEVICE_TABLE(hid, waltop_devices);
803static struct hid_driver waltop_driver = { 776static struct hid_driver waltop_driver = {
804 .name = "waltop", 777 .name = "waltop",
805 .id_table = waltop_devices, 778 .id_table = waltop_devices,
806 .probe = waltop_probe,
807 .report_fixup = waltop_report_fixup, 779 .report_fixup = waltop_report_fixup,
808 .raw_event = waltop_raw_event, 780 .raw_event = waltop_raw_event,
809 .remove = waltop_remove,
810}; 781};
811 782
812static int __init waltop_init(void) 783static int __init waltop_init(void)
diff --git a/drivers/hid/hid-wiimote-ext.c b/drivers/hid/hid-wiimote-ext.c
index 0a1805c9b0e5..bc85bf29062e 100644
--- a/drivers/hid/hid-wiimote-ext.c
+++ b/drivers/hid/hid-wiimote-ext.c
@@ -28,12 +28,14 @@ struct wiimote_ext {
28 bool mp_plugged; 28 bool mp_plugged;
29 bool motionp; 29 bool motionp;
30 __u8 ext_type; 30 __u8 ext_type;
31 __u16 calib[4][3];
31}; 32};
32 33
33enum wiiext_type { 34enum wiiext_type {
34 WIIEXT_NONE, /* placeholder */ 35 WIIEXT_NONE, /* placeholder */
35 WIIEXT_CLASSIC, /* Nintendo classic controller */ 36 WIIEXT_CLASSIC, /* Nintendo classic controller */
36 WIIEXT_NUNCHUCK, /* Nintendo nunchuck controller */ 37 WIIEXT_NUNCHUCK, /* Nintendo nunchuck controller */
38 WIIEXT_BALANCE_BOARD, /* Nintendo balance board controller */
37}; 39};
38 40
39enum wiiext_keys { 41enum wiiext_keys {
@@ -126,6 +128,7 @@ error:
126static __u8 ext_read(struct wiimote_ext *ext) 128static __u8 ext_read(struct wiimote_ext *ext)
127{ 129{
128 ssize_t ret; 130 ssize_t ret;
131 __u8 buf[24], i, j, offs = 0;
129 __u8 rmem[2], wmem; 132 __u8 rmem[2], wmem;
130 __u8 type = WIIEXT_NONE; 133 __u8 type = WIIEXT_NONE;
131 134
@@ -151,6 +154,28 @@ static __u8 ext_read(struct wiimote_ext *ext)
151 type = WIIEXT_NUNCHUCK; 154 type = WIIEXT_NUNCHUCK;
152 else if (rmem[0] == 0x01 && rmem[1] == 0x01) 155 else if (rmem[0] == 0x01 && rmem[1] == 0x01)
153 type = WIIEXT_CLASSIC; 156 type = WIIEXT_CLASSIC;
157 else if (rmem[0] == 0x04 && rmem[1] == 0x02)
158 type = WIIEXT_BALANCE_BOARD;
159 }
160
161 /* get balance board calibration data */
162 if (type == WIIEXT_BALANCE_BOARD) {
163 ret = wiimote_cmd_read(ext->wdata, 0xa40024, buf, 12);
164 ret += wiimote_cmd_read(ext->wdata, 0xa40024 + 12,
165 buf + 12, 12);
166
167 if (ret != 24) {
168 type = WIIEXT_NONE;
169 } else {
170 for (i = 0; i < 3; i++) {
171 for (j = 0; j < 4; j++) {
172 ext->calib[j][i] = buf[offs];
173 ext->calib[j][i] <<= 8;
174 ext->calib[j][i] |= buf[offs + 1];
175 offs += 2;
176 }
177 }
178 }
154 } 179 }
155 180
156 wiimote_cmd_release(ext->wdata); 181 wiimote_cmd_release(ext->wdata);
@@ -509,6 +534,71 @@ static void handler_classic(struct wiimote_ext *ext, const __u8 *payload)
509 input_sync(ext->input); 534 input_sync(ext->input);
510} 535}
511 536
537static void handler_balance_board(struct wiimote_ext *ext, const __u8 *payload)
538{
539 __s32 val[4], tmp;
540 unsigned int i;
541
542 /* Byte | 8 7 6 5 4 3 2 1 |
543 * -----+--------------------------+
544 * 1 | Top Right <15:8> |
545 * 2 | Top Right <7:0> |
546 * -----+--------------------------+
547 * 3 | Bottom Right <15:8> |
548 * 4 | Bottom Right <7:0> |
549 * -----+--------------------------+
550 * 5 | Top Left <15:8> |
551 * 6 | Top Left <7:0> |
552 * -----+--------------------------+
553 * 7 | Bottom Left <15:8> |
554 * 8 | Bottom Left <7:0> |
555 * -----+--------------------------+
556 *
557 * These values represent the weight-measurements of the Wii-balance
558 * board with 16bit precision.
559 *
560 * The balance-board is never reported interleaved with motionp.
561 */
562
563 val[0] = payload[0];
564 val[0] <<= 8;
565 val[0] |= payload[1];
566
567 val[1] = payload[2];
568 val[1] <<= 8;
569 val[1] |= payload[3];
570
571 val[2] = payload[4];
572 val[2] <<= 8;
573 val[2] |= payload[5];
574
575 val[3] = payload[6];
576 val[3] <<= 8;
577 val[3] |= payload[7];
578
579 /* apply calibration data */
580 for (i = 0; i < 4; i++) {
581 if (val[i] < ext->calib[i][1]) {
582 tmp = val[i] - ext->calib[i][0];
583 tmp *= 1700;
584 tmp /= ext->calib[i][1] - ext->calib[i][0];
585 } else {
586 tmp = val[i] - ext->calib[i][1];
587 tmp *= 1700;
588 tmp /= ext->calib[i][2] - ext->calib[i][1];
589 tmp += 1700;
590 }
591 val[i] = tmp;
592 }
593
594 input_report_abs(ext->input, ABS_HAT0X, val[0]);
595 input_report_abs(ext->input, ABS_HAT0Y, val[1]);
596 input_report_abs(ext->input, ABS_HAT1X, val[2]);
597 input_report_abs(ext->input, ABS_HAT1Y, val[3]);
598
599 input_sync(ext->input);
600}
601
512/* call this with state.lock spinlock held */ 602/* call this with state.lock spinlock held */
513void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload) 603void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload)
514{ 604{
@@ -523,6 +613,8 @@ void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload)
523 handler_nunchuck(ext, payload); 613 handler_nunchuck(ext, payload);
524 } else if (ext->ext_type == WIIEXT_CLASSIC) { 614 } else if (ext->ext_type == WIIEXT_CLASSIC) {
525 handler_classic(ext, payload); 615 handler_classic(ext, payload);
616 } else if (ext->ext_type == WIIEXT_BALANCE_BOARD) {
617 handler_balance_board(ext, payload);
526 } 618 }
527} 619}
528 620
@@ -551,6 +643,11 @@ static ssize_t wiiext_show(struct device *dev, struct device_attribute *attr,
551 return sprintf(buf, "motionp+classic\n"); 643 return sprintf(buf, "motionp+classic\n");
552 else 644 else
553 return sprintf(buf, "classic\n"); 645 return sprintf(buf, "classic\n");
646 } else if (type == WIIEXT_BALANCE_BOARD) {
647 if (motionp)
648 return sprintf(buf, "motionp+balanceboard\n");
649 else
650 return sprintf(buf, "balanceboard\n");
554 } else { 651 } else {
555 if (motionp) 652 if (motionp)
556 return sprintf(buf, "motionp\n"); 653 return sprintf(buf, "motionp\n");
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 3b6f7bf5a77e..17d15bb610d1 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -42,6 +42,7 @@ static struct cdev hidraw_cdev;
42static struct class *hidraw_class; 42static struct class *hidraw_class;
43static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES]; 43static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES];
44static DEFINE_MUTEX(minors_lock); 44static DEFINE_MUTEX(minors_lock);
45static void drop_ref(struct hidraw *hid, int exists_bit);
45 46
46static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 47static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
47{ 48{
@@ -113,7 +114,7 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer,
113 __u8 *buf; 114 __u8 *buf;
114 int ret = 0; 115 int ret = 0;
115 116
116 if (!hidraw_table[minor]) { 117 if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
117 ret = -ENODEV; 118 ret = -ENODEV;
118 goto out; 119 goto out;
119 } 120 }
@@ -261,7 +262,7 @@ static int hidraw_open(struct inode *inode, struct file *file)
261 } 262 }
262 263
263 mutex_lock(&minors_lock); 264 mutex_lock(&minors_lock);
264 if (!hidraw_table[minor]) { 265 if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
265 err = -ENODEV; 266 err = -ENODEV;
266 goto out_unlock; 267 goto out_unlock;
267 } 268 }
@@ -298,36 +299,12 @@ out:
298static int hidraw_release(struct inode * inode, struct file * file) 299static int hidraw_release(struct inode * inode, struct file * file)
299{ 300{
300 unsigned int minor = iminor(inode); 301 unsigned int minor = iminor(inode);
301 struct hidraw *dev;
302 struct hidraw_list *list = file->private_data; 302 struct hidraw_list *list = file->private_data;
303 int ret;
304 int i;
305
306 mutex_lock(&minors_lock);
307 if (!hidraw_table[minor]) {
308 ret = -ENODEV;
309 goto unlock;
310 }
311 303
304 drop_ref(hidraw_table[minor], 0);
312 list_del(&list->node); 305 list_del(&list->node);
313 dev = hidraw_table[minor];
314 if (!--dev->open) {
315 if (list->hidraw->exist) {
316 hid_hw_power(dev->hid, PM_HINT_NORMAL);
317 hid_hw_close(dev->hid);
318 } else {
319 kfree(list->hidraw);
320 }
321 }
322
323 for (i = 0; i < HIDRAW_BUFFER_SIZE; ++i)
324 kfree(list->buffer[i].value);
325 kfree(list); 306 kfree(list);
326 ret = 0; 307 return 0;
327unlock:
328 mutex_unlock(&minors_lock);
329
330 return ret;
331} 308}
332 309
333static long hidraw_ioctl(struct file *file, unsigned int cmd, 310static long hidraw_ioctl(struct file *file, unsigned int cmd,
@@ -529,21 +506,7 @@ EXPORT_SYMBOL_GPL(hidraw_connect);
529void hidraw_disconnect(struct hid_device *hid) 506void hidraw_disconnect(struct hid_device *hid)
530{ 507{
531 struct hidraw *hidraw = hid->hidraw; 508 struct hidraw *hidraw = hid->hidraw;
532 509 drop_ref(hidraw, 1);
533 mutex_lock(&minors_lock);
534 hidraw->exist = 0;
535
536 device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
537
538 hidraw_table[hidraw->minor] = NULL;
539
540 if (hidraw->open) {
541 hid_hw_close(hid);
542 wake_up_interruptible(&hidraw->wait);
543 } else {
544 kfree(hidraw);
545 }
546 mutex_unlock(&minors_lock);
547} 510}
548EXPORT_SYMBOL_GPL(hidraw_disconnect); 511EXPORT_SYMBOL_GPL(hidraw_disconnect);
549 512
@@ -559,21 +522,28 @@ int __init hidraw_init(void)
559 522
560 if (result < 0) { 523 if (result < 0) {
561 pr_warn("can't get major number\n"); 524 pr_warn("can't get major number\n");
562 result = 0;
563 goto out; 525 goto out;
564 } 526 }
565 527
566 hidraw_class = class_create(THIS_MODULE, "hidraw"); 528 hidraw_class = class_create(THIS_MODULE, "hidraw");
567 if (IS_ERR(hidraw_class)) { 529 if (IS_ERR(hidraw_class)) {
568 result = PTR_ERR(hidraw_class); 530 result = PTR_ERR(hidraw_class);
569 unregister_chrdev(hidraw_major, "hidraw"); 531 goto error_cdev;
570 goto out;
571 } 532 }
572 533
573 cdev_init(&hidraw_cdev, &hidraw_ops); 534 cdev_init(&hidraw_cdev, &hidraw_ops);
574 cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES); 535 result = cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES);
536 if (result < 0)
537 goto error_class;
538
575out: 539out:
576 return result; 540 return result;
541
542error_class:
543 class_destroy(hidraw_class);
544error_cdev:
545 unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
546 goto out;
577} 547}
578 548
579void hidraw_exit(void) 549void hidraw_exit(void)
@@ -585,3 +555,23 @@ void hidraw_exit(void)
585 unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES); 555 unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
586 556
587} 557}
558
559static void drop_ref(struct hidraw *hidraw, int exists_bit)
560{
561 mutex_lock(&minors_lock);
562 if (exists_bit) {
563 hid_hw_close(hidraw->hid);
564 hidraw->exist = 0;
565 if (hidraw->open)
566 wake_up_interruptible(&hidraw->wait);
567 } else {
568 --hidraw->open;
569 }
570
571 if (!hidraw->open && !hidraw->exist) {
572 device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
573 hidraw_table[hidraw->minor] = NULL;
574 kfree(hidraw);
575 }
576 mutex_unlock(&minors_lock);
577}
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index dedd8e4e5c6d..8e0c4bf94ebc 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1415,20 +1415,20 @@ static int hid_post_reset(struct usb_interface *intf)
1415 * configuration descriptors passed, we already know that 1415 * configuration descriptors passed, we already know that
1416 * the size of the HID report descriptor has not changed. 1416 * the size of the HID report descriptor has not changed.
1417 */ 1417 */
1418 rdesc = kmalloc(hid->rsize, GFP_KERNEL); 1418 rdesc = kmalloc(hid->dev_rsize, GFP_KERNEL);
1419 if (!rdesc) { 1419 if (!rdesc) {
1420 dbg_hid("couldn't allocate rdesc memory (post_reset)\n"); 1420 dbg_hid("couldn't allocate rdesc memory (post_reset)\n");
1421 return 1; 1421 return 1;
1422 } 1422 }
1423 status = hid_get_class_descriptor(dev, 1423 status = hid_get_class_descriptor(dev,
1424 interface->desc.bInterfaceNumber, 1424 interface->desc.bInterfaceNumber,
1425 HID_DT_REPORT, rdesc, hid->rsize); 1425 HID_DT_REPORT, rdesc, hid->dev_rsize);
1426 if (status < 0) { 1426 if (status < 0) {
1427 dbg_hid("reading report descriptor failed (post_reset)\n"); 1427 dbg_hid("reading report descriptor failed (post_reset)\n");
1428 kfree(rdesc); 1428 kfree(rdesc);
1429 return 1; 1429 return 1;
1430 } 1430 }
1431 status = memcmp(rdesc, hid->rdesc, hid->rsize); 1431 status = memcmp(rdesc, hid->dev_rdesc, hid->dev_rsize);
1432 kfree(rdesc); 1432 kfree(rdesc);
1433 if (status != 0) { 1433 if (status != 0) {
1434 dbg_hid("report descriptor changed\n"); 1434 dbg_hid("report descriptor changed\n");
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 991e85c7325c..11c7932dc7e6 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -70,12 +70,13 @@ static const struct hid_blacklist {
70 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_AXIS_295, HID_QUIRK_NOGET }, 70 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_AXIS_295, HID_QUIRK_NOGET },
71 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, 71 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET },
72 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, 72 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
73 { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET },
73 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET }, 74 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET },
74 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS }, 75 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS },
75 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS }, 76 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS },
76 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2, HID_QUIRK_NO_INIT_REPORTS }, 77 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2, HID_QUIRK_NO_INIT_REPORTS },
77 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET }, 78 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET },
78 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NOGET }, 79 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001, HID_QUIRK_NOGET },
79 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008, HID_QUIRK_NOGET }, 80 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008, HID_QUIRK_NOGET },
80 { USB_VENDOR_ID_SENNHEISER, USB_DEVICE_ID_SENNHEISER_BTD500USB, HID_QUIRK_NOGET }, 81 { USB_VENDOR_ID_SENNHEISER, USB_DEVICE_ID_SENNHEISER_BTD500USB, HID_QUIRK_NOGET },
81 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, 82 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
index cfec802cf9ca..f915eb1c29f7 100644
--- a/drivers/hwmon/ad7314.c
+++ b/drivers/hwmon/ad7314.c
@@ -87,10 +87,18 @@ static ssize_t ad7314_show_temperature(struct device *dev,
87 } 87 }
88} 88}
89 89
90static ssize_t ad7314_show_name(struct device *dev,
91 struct device_attribute *devattr, char *buf)
92{
93 return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
94}
95
96static DEVICE_ATTR(name, S_IRUGO, ad7314_show_name, NULL);
90static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, 97static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
91 ad7314_show_temperature, NULL, 0); 98 ad7314_show_temperature, NULL, 0);
92 99
93static struct attribute *ad7314_attributes[] = { 100static struct attribute *ad7314_attributes[] = {
101 &dev_attr_name.attr,
94 &sensor_dev_attr_temp1_input.dev_attr.attr, 102 &sensor_dev_attr_temp1_input.dev_attr.attr,
95 NULL, 103 NULL,
96}; 104};
diff --git a/drivers/hwmon/ads7871.c b/drivers/hwmon/ads7871.c
index e65c6e45d36b..7bf4ce3d405e 100644
--- a/drivers/hwmon/ads7871.c
+++ b/drivers/hwmon/ads7871.c
@@ -139,6 +139,12 @@ static ssize_t show_voltage(struct device *dev,
139 } 139 }
140} 140}
141 141
142static ssize_t ads7871_show_name(struct device *dev,
143 struct device_attribute *devattr, char *buf)
144{
145 return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
146}
147
142static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL, 0); 148static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL, 0);
143static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 1); 149static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 1);
144static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 2); 150static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 2);
@@ -148,6 +154,8 @@ static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 5);
148static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 6); 154static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 6);
149static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 7); 155static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 7);
150 156
157static DEVICE_ATTR(name, S_IRUGO, ads7871_show_name, NULL);
158
151static struct attribute *ads7871_attributes[] = { 159static struct attribute *ads7871_attributes[] = {
152 &sensor_dev_attr_in0_input.dev_attr.attr, 160 &sensor_dev_attr_in0_input.dev_attr.attr,
153 &sensor_dev_attr_in1_input.dev_attr.attr, 161 &sensor_dev_attr_in1_input.dev_attr.attr,
@@ -157,6 +165,7 @@ static struct attribute *ads7871_attributes[] = {
157 &sensor_dev_attr_in5_input.dev_attr.attr, 165 &sensor_dev_attr_in5_input.dev_attr.attr,
158 &sensor_dev_attr_in6_input.dev_attr.attr, 166 &sensor_dev_attr_in6_input.dev_attr.attr,
159 &sensor_dev_attr_in7_input.dev_attr.attr, 167 &sensor_dev_attr_in7_input.dev_attr.attr,
168 &dev_attr_name.attr,
160 NULL 169 NULL
161}; 170};
162 171
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index 282708860517..8f3f6f2c45fd 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -53,10 +53,10 @@
53 53
54#define APPLESMC_MAX_DATA_LENGTH 32 54#define APPLESMC_MAX_DATA_LENGTH 32
55 55
56/* wait up to 32 ms for a status change. */ 56/* wait up to 128 ms for a status change. */
57#define APPLESMC_MIN_WAIT 0x0010 57#define APPLESMC_MIN_WAIT 0x0010
58#define APPLESMC_RETRY_WAIT 0x0100 58#define APPLESMC_RETRY_WAIT 0x0100
59#define APPLESMC_MAX_WAIT 0x8000 59#define APPLESMC_MAX_WAIT 0x20000
60 60
61#define APPLESMC_READ_CMD 0x10 61#define APPLESMC_READ_CMD 0x10
62#define APPLESMC_WRITE_CMD 0x11 62#define APPLESMC_WRITE_CMD 0x11
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 0fa356fe82cc..984a3f13923b 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -815,17 +815,20 @@ static int __init coretemp_init(void)
815 if (err) 815 if (err)
816 goto exit; 816 goto exit;
817 817
818 get_online_cpus();
818 for_each_online_cpu(i) 819 for_each_online_cpu(i)
819 get_core_online(i); 820 get_core_online(i);
820 821
821#ifndef CONFIG_HOTPLUG_CPU 822#ifndef CONFIG_HOTPLUG_CPU
822 if (list_empty(&pdev_list)) { 823 if (list_empty(&pdev_list)) {
824 put_online_cpus();
823 err = -ENODEV; 825 err = -ENODEV;
824 goto exit_driver_unreg; 826 goto exit_driver_unreg;
825 } 827 }
826#endif 828#endif
827 829
828 register_hotcpu_notifier(&coretemp_cpu_notifier); 830 register_hotcpu_notifier(&coretemp_cpu_notifier);
831 put_online_cpus();
829 return 0; 832 return 0;
830 833
831#ifndef CONFIG_HOTPLUG_CPU 834#ifndef CONFIG_HOTPLUG_CPU
@@ -840,6 +843,7 @@ static void __exit coretemp_exit(void)
840{ 843{
841 struct pdev_entry *p, *n; 844 struct pdev_entry *p, *n;
842 845
846 get_online_cpus();
843 unregister_hotcpu_notifier(&coretemp_cpu_notifier); 847 unregister_hotcpu_notifier(&coretemp_cpu_notifier);
844 mutex_lock(&pdev_list_mutex); 848 mutex_lock(&pdev_list_mutex);
845 list_for_each_entry_safe(p, n, &pdev_list, list) { 849 list_for_each_entry_safe(p, n, &pdev_list, list) {
@@ -848,6 +852,7 @@ static void __exit coretemp_exit(void)
848 kfree(p); 852 kfree(p);
849 } 853 }
850 mutex_unlock(&pdev_list_mutex); 854 mutex_unlock(&pdev_list_mutex);
855 put_online_cpus();
851 platform_driver_unregister(&coretemp_driver); 856 platform_driver_unregister(&coretemp_driver);
852} 857}
853 858
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 2764b78a784b..af69073b3fe8 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -129,12 +129,12 @@ static bool __devinit fam15h_power_is_internal_node0(struct pci_dev *f4)
129 * counter saturations resulting in bogus power readings. 129 * counter saturations resulting in bogus power readings.
130 * We correct this value ourselves to cope with older BIOSes. 130 * We correct this value ourselves to cope with older BIOSes.
131 */ 131 */
132static DEFINE_PCI_DEVICE_TABLE(affected_device) = { 132static const struct pci_device_id affected_device[] = {
133 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) }, 133 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) },
134 { 0 } 134 { 0 }
135}; 135};
136 136
137static void __devinit tweak_runavg_range(struct pci_dev *pdev) 137static void tweak_runavg_range(struct pci_dev *pdev)
138{ 138{
139 u32 val; 139 u32 val;
140 140
@@ -158,6 +158,16 @@ static void __devinit tweak_runavg_range(struct pci_dev *pdev)
158 REG_TDP_RUNNING_AVERAGE, val); 158 REG_TDP_RUNNING_AVERAGE, val);
159} 159}
160 160
161#ifdef CONFIG_PM
162static int fam15h_power_resume(struct pci_dev *pdev)
163{
164 tweak_runavg_range(pdev);
165 return 0;
166}
167#else
168#define fam15h_power_resume NULL
169#endif
170
161static void __devinit fam15h_power_init_data(struct pci_dev *f4, 171static void __devinit fam15h_power_init_data(struct pci_dev *f4,
162 struct fam15h_power_data *data) 172 struct fam15h_power_data *data)
163{ 173{
@@ -256,6 +266,7 @@ static struct pci_driver fam15h_power_driver = {
256 .id_table = fam15h_power_id_table, 266 .id_table = fam15h_power_id_table,
257 .probe = fam15h_power_probe, 267 .probe = fam15h_power_probe,
258 .remove = __devexit_p(fam15h_power_remove), 268 .remove = __devexit_p(fam15h_power_remove),
269 .resume = fam15h_power_resume,
259}; 270};
260 271
261module_pci_driver(fam15h_power_driver); 272module_pci_driver(fam15h_power_driver);
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index 7f3f4a385729..602148299f68 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -69,22 +69,6 @@ struct ina2xx_data {
69 u16 regs[INA2XX_MAX_REGISTERS]; 69 u16 regs[INA2XX_MAX_REGISTERS];
70}; 70};
71 71
72int ina2xx_read_word(struct i2c_client *client, int reg)
73{
74 int val = i2c_smbus_read_word_data(client, reg);
75 if (unlikely(val < 0)) {
76 dev_dbg(&client->dev,
77 "Failed to read register: %d\n", reg);
78 return val;
79 }
80 return be16_to_cpu(val);
81}
82
83void ina2xx_write_word(struct i2c_client *client, int reg, int data)
84{
85 i2c_smbus_write_word_data(client, reg, cpu_to_be16(data));
86}
87
88static struct ina2xx_data *ina2xx_update_device(struct device *dev) 72static struct ina2xx_data *ina2xx_update_device(struct device *dev)
89{ 73{
90 struct i2c_client *client = to_i2c_client(dev); 74 struct i2c_client *client = to_i2c_client(dev);
@@ -102,7 +86,7 @@ static struct ina2xx_data *ina2xx_update_device(struct device *dev)
102 86
103 /* Read all registers */ 87 /* Read all registers */
104 for (i = 0; i < data->registers; i++) { 88 for (i = 0; i < data->registers; i++) {
105 int rv = ina2xx_read_word(client, i); 89 int rv = i2c_smbus_read_word_swapped(client, i);
106 if (rv < 0) { 90 if (rv < 0) {
107 ret = ERR_PTR(rv); 91 ret = ERR_PTR(rv);
108 goto abort; 92 goto abort;
@@ -279,22 +263,26 @@ static int ina2xx_probe(struct i2c_client *client,
279 switch (data->kind) { 263 switch (data->kind) {
280 case ina219: 264 case ina219:
281 /* device configuration */ 265 /* device configuration */
282 ina2xx_write_word(client, INA2XX_CONFIG, INA219_CONFIG_DEFAULT); 266 i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
267 INA219_CONFIG_DEFAULT);
283 268
284 /* set current LSB to 1mA, shunt is in uOhms */ 269 /* set current LSB to 1mA, shunt is in uOhms */
285 /* (equation 13 in datasheet) */ 270 /* (equation 13 in datasheet) */
286 ina2xx_write_word(client, INA2XX_CALIBRATION, 40960000 / shunt); 271 i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
272 40960000 / shunt);
287 dev_info(&client->dev, 273 dev_info(&client->dev,
288 "power monitor INA219 (Rshunt = %li uOhm)\n", shunt); 274 "power monitor INA219 (Rshunt = %li uOhm)\n", shunt);
289 data->registers = INA219_REGISTERS; 275 data->registers = INA219_REGISTERS;
290 break; 276 break;
291 case ina226: 277 case ina226:
292 /* device configuration */ 278 /* device configuration */
293 ina2xx_write_word(client, INA2XX_CONFIG, INA226_CONFIG_DEFAULT); 279 i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
280 INA226_CONFIG_DEFAULT);
294 281
295 /* set current LSB to 1mA, shunt is in uOhms */ 282 /* set current LSB to 1mA, shunt is in uOhms */
296 /* (equation 1 in datasheet)*/ 283 /* (equation 1 in datasheet)*/
297 ina2xx_write_word(client, INA2XX_CALIBRATION, 5120000 / shunt); 284 i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
285 5120000 / shunt);
298 dev_info(&client->dev, 286 dev_info(&client->dev,
299 "power monitor INA226 (Rshunt = %li uOhm)\n", shunt); 287 "power monitor INA226 (Rshunt = %li uOhm)\n", shunt);
300 data->registers = INA226_REGISTERS; 288 data->registers = INA226_REGISTERS;
diff --git a/drivers/hwmon/twl4030-madc-hwmon.c b/drivers/hwmon/twl4030-madc-hwmon.c
index 0018c7dd0097..1a174f0a3cde 100644
--- a/drivers/hwmon/twl4030-madc-hwmon.c
+++ b/drivers/hwmon/twl4030-madc-hwmon.c
@@ -44,12 +44,13 @@ static ssize_t madc_read(struct device *dev,
44 struct device_attribute *devattr, char *buf) 44 struct device_attribute *devattr, char *buf)
45{ 45{
46 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 46 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
47 struct twl4030_madc_request req; 47 struct twl4030_madc_request req = {
48 .channels = 1 << attr->index,
49 .method = TWL4030_MADC_SW2,
50 .type = TWL4030_MADC_WAIT,
51 };
48 long val; 52 long val;
49 53
50 req.channels = (1 << attr->index);
51 req.method = TWL4030_MADC_SW2;
52 req.func_cb = NULL;
53 val = twl4030_madc_conversion(&req); 54 val = twl4030_madc_conversion(&req);
54 if (val < 0) 55 if (val < 0)
55 return val; 56 return val;
diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
index ee4ebc198a94..2e56c6ce9fb6 100644
--- a/drivers/hwmon/via-cputemp.c
+++ b/drivers/hwmon/via-cputemp.c
@@ -328,6 +328,7 @@ static int __init via_cputemp_init(void)
328 if (err) 328 if (err)
329 goto exit; 329 goto exit;
330 330
331 get_online_cpus();
331 for_each_online_cpu(i) { 332 for_each_online_cpu(i) {
332 struct cpuinfo_x86 *c = &cpu_data(i); 333 struct cpuinfo_x86 *c = &cpu_data(i);
333 334
@@ -347,12 +348,14 @@ static int __init via_cputemp_init(void)
347 348
348#ifndef CONFIG_HOTPLUG_CPU 349#ifndef CONFIG_HOTPLUG_CPU
349 if (list_empty(&pdev_list)) { 350 if (list_empty(&pdev_list)) {
351 put_online_cpus();
350 err = -ENODEV; 352 err = -ENODEV;
351 goto exit_driver_unreg; 353 goto exit_driver_unreg;
352 } 354 }
353#endif 355#endif
354 356
355 register_hotcpu_notifier(&via_cputemp_cpu_notifier); 357 register_hotcpu_notifier(&via_cputemp_cpu_notifier);
358 put_online_cpus();
356 return 0; 359 return 0;
357 360
358#ifndef CONFIG_HOTPLUG_CPU 361#ifndef CONFIG_HOTPLUG_CPU
@@ -367,6 +370,7 @@ static void __exit via_cputemp_exit(void)
367{ 370{
368 struct pdev_entry *p, *n; 371 struct pdev_entry *p, *n;
369 372
373 get_online_cpus();
370 unregister_hotcpu_notifier(&via_cputemp_cpu_notifier); 374 unregister_hotcpu_notifier(&via_cputemp_cpu_notifier);
371 mutex_lock(&pdev_list_mutex); 375 mutex_lock(&pdev_list_mutex);
372 list_for_each_entry_safe(p, n, &pdev_list, list) { 376 list_for_each_entry_safe(p, n, &pdev_list, list) {
@@ -375,6 +379,7 @@ static void __exit via_cputemp_exit(void)
375 kfree(p); 379 kfree(p);
376 } 380 }
377 mutex_unlock(&pdev_list_mutex); 381 mutex_unlock(&pdev_list_mutex);
382 put_online_cpus();
378 platform_driver_unregister(&via_cputemp_driver); 383 platform_driver_unregister(&via_cputemp_driver);
379} 384}
380 385
diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c
index 1201a15784c3..db713c0dfba4 100644
--- a/drivers/hwspinlock/hwspinlock_core.c
+++ b/drivers/hwspinlock/hwspinlock_core.c
@@ -552,7 +552,7 @@ EXPORT_SYMBOL_GPL(hwspin_lock_request_specific);
552 */ 552 */
553int hwspin_lock_free(struct hwspinlock *hwlock) 553int hwspin_lock_free(struct hwspinlock *hwlock)
554{ 554{
555 struct device *dev = hwlock->bank->dev; 555 struct device *dev;
556 struct hwspinlock *tmp; 556 struct hwspinlock *tmp;
557 int ret; 557 int ret;
558 558
@@ -561,6 +561,7 @@ int hwspin_lock_free(struct hwspinlock *hwlock)
561 return -EINVAL; 561 return -EINVAL;
562 } 562 }
563 563
564 dev = hwlock->bank->dev;
564 mutex_lock(&hwspinlock_tree_lock); 565 mutex_lock(&hwspinlock_tree_lock);
565 566
566 /* make sure the hwspinlock is used */ 567 /* make sure the hwspinlock is used */
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index 73133b1063f0..6f5f98d69af7 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -476,17 +476,17 @@ static int pca_init(struct i2c_adapter *adap)
476 /* To avoid integer overflow, use clock/100 for calculations */ 476 /* To avoid integer overflow, use clock/100 for calculations */
477 clock = pca_clock(pca_data) / 100; 477 clock = pca_clock(pca_data) / 100;
478 478
479 if (pca_data->i2c_clock > 10000) { 479 if (pca_data->i2c_clock > 1000000) {
480 mode = I2C_PCA_MODE_TURBO; 480 mode = I2C_PCA_MODE_TURBO;
481 min_tlow = 14; 481 min_tlow = 14;
482 min_thi = 5; 482 min_thi = 5;
483 raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */ 483 raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
484 } else if (pca_data->i2c_clock > 4000) { 484 } else if (pca_data->i2c_clock > 400000) {
485 mode = I2C_PCA_MODE_FASTP; 485 mode = I2C_PCA_MODE_FASTP;
486 min_tlow = 17; 486 min_tlow = 17;
487 min_thi = 9; 487 min_thi = 9;
488 raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */ 488 raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
489 } else if (pca_data->i2c_clock > 1000) { 489 } else if (pca_data->i2c_clock > 100000) {
490 mode = I2C_PCA_MODE_FAST; 490 mode = I2C_PCA_MODE_FAST;
491 min_tlow = 44; 491 min_tlow = 44;
492 min_thi = 20; 492 min_thi = 20;
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index b4aaa1bd6728..970a1612e795 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -104,6 +104,7 @@ config I2C_I801
104 DH89xxCC (PCH) 104 DH89xxCC (PCH)
105 Panther Point (PCH) 105 Panther Point (PCH)
106 Lynx Point (PCH) 106 Lynx Point (PCH)
107 Lynx Point-LP (PCH)
107 108
108 This driver can also be built as a module. If so, the module 109 This driver can also be built as a module. If so, the module
109 will be called i2c-i801. 110 will be called i2c-i801.
@@ -354,9 +355,13 @@ config I2C_DAVINCI
354 devices such as DaVinci NIC. 355 devices such as DaVinci NIC.
355 For details please see http://www.ti.com/davinci 356 For details please see http://www.ti.com/davinci
356 357
358config I2C_DESIGNWARE_CORE
359 tristate
360
357config I2C_DESIGNWARE_PLATFORM 361config I2C_DESIGNWARE_PLATFORM
358 tristate "Synopsys DesignWare Platform" 362 tristate "Synopsys DesignWare Platform"
359 depends on HAVE_CLK 363 depends on HAVE_CLK
364 select I2C_DESIGNWARE_CORE
360 help 365 help
361 If you say yes to this option, support will be included for the 366 If you say yes to this option, support will be included for the
362 Synopsys DesignWare I2C adapter. Only master mode is supported. 367 Synopsys DesignWare I2C adapter. Only master mode is supported.
@@ -367,6 +372,7 @@ config I2C_DESIGNWARE_PLATFORM
367config I2C_DESIGNWARE_PCI 372config I2C_DESIGNWARE_PCI
368 tristate "Synopsys DesignWare PCI" 373 tristate "Synopsys DesignWare PCI"
369 depends on PCI 374 depends on PCI
375 select I2C_DESIGNWARE_CORE
370 help 376 help
371 If you say yes to this option, support will be included for the 377 If you say yes to this option, support will be included for the
372 Synopsys DesignWare I2C adapter. Only master mode is supported. 378 Synopsys DesignWare I2C adapter. Only master mode is supported.
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ce3c2be7fb40..37c4182cc98b 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -33,10 +33,11 @@ obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
33obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o 33obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
34obj-$(CONFIG_I2C_CPM) += i2c-cpm.o 34obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
35obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o 35obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o
36obj-$(CONFIG_I2C_DESIGNWARE_CORE) += i2c-designware-core.o
36obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o 37obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o
37i2c-designware-platform-objs := i2c-designware-platdrv.o i2c-designware-core.o 38i2c-designware-platform-objs := i2c-designware-platdrv.o
38obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o 39obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o
39i2c-designware-pci-objs := i2c-designware-pcidrv.o i2c-designware-core.o 40i2c-designware-pci-objs := i2c-designware-pcidrv.o
40obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o 41obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o
41obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o 42obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
42obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o 43obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 1e48bec80edf..7b8ebbefb581 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -25,6 +25,7 @@
25 * ---------------------------------------------------------------------------- 25 * ----------------------------------------------------------------------------
26 * 26 *
27 */ 27 */
28#include <linux/export.h>
28#include <linux/clk.h> 29#include <linux/clk.h>
29#include <linux/errno.h> 30#include <linux/errno.h>
30#include <linux/err.h> 31#include <linux/err.h>
@@ -316,6 +317,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
316 dw_writel(dev, dev->master_cfg , DW_IC_CON); 317 dw_writel(dev, dev->master_cfg , DW_IC_CON);
317 return 0; 318 return 0;
318} 319}
320EXPORT_SYMBOL_GPL(i2c_dw_init);
319 321
320/* 322/*
321 * Waiting for bus not busy 323 * Waiting for bus not busy
@@ -568,12 +570,14 @@ done:
568 570
569 return ret; 571 return ret;
570} 572}
573EXPORT_SYMBOL_GPL(i2c_dw_xfer);
571 574
572u32 i2c_dw_func(struct i2c_adapter *adap) 575u32 i2c_dw_func(struct i2c_adapter *adap)
573{ 576{
574 struct dw_i2c_dev *dev = i2c_get_adapdata(adap); 577 struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
575 return dev->functionality; 578 return dev->functionality;
576} 579}
580EXPORT_SYMBOL_GPL(i2c_dw_func);
577 581
578static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) 582static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
579{ 583{
@@ -678,17 +682,20 @@ tx_aborted:
678 682
679 return IRQ_HANDLED; 683 return IRQ_HANDLED;
680} 684}
685EXPORT_SYMBOL_GPL(i2c_dw_isr);
681 686
682void i2c_dw_enable(struct dw_i2c_dev *dev) 687void i2c_dw_enable(struct dw_i2c_dev *dev)
683{ 688{
684 /* Enable the adapter */ 689 /* Enable the adapter */
685 dw_writel(dev, 1, DW_IC_ENABLE); 690 dw_writel(dev, 1, DW_IC_ENABLE);
686} 691}
692EXPORT_SYMBOL_GPL(i2c_dw_enable);
687 693
688u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev) 694u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev)
689{ 695{
690 return dw_readl(dev, DW_IC_ENABLE); 696 return dw_readl(dev, DW_IC_ENABLE);
691} 697}
698EXPORT_SYMBOL_GPL(i2c_dw_is_enabled);
692 699
693void i2c_dw_disable(struct dw_i2c_dev *dev) 700void i2c_dw_disable(struct dw_i2c_dev *dev)
694{ 701{
@@ -699,18 +706,22 @@ void i2c_dw_disable(struct dw_i2c_dev *dev)
699 dw_writel(dev, 0, DW_IC_INTR_MASK); 706 dw_writel(dev, 0, DW_IC_INTR_MASK);
700 dw_readl(dev, DW_IC_CLR_INTR); 707 dw_readl(dev, DW_IC_CLR_INTR);
701} 708}
709EXPORT_SYMBOL_GPL(i2c_dw_disable);
702 710
703void i2c_dw_clear_int(struct dw_i2c_dev *dev) 711void i2c_dw_clear_int(struct dw_i2c_dev *dev)
704{ 712{
705 dw_readl(dev, DW_IC_CLR_INTR); 713 dw_readl(dev, DW_IC_CLR_INTR);
706} 714}
715EXPORT_SYMBOL_GPL(i2c_dw_clear_int);
707 716
708void i2c_dw_disable_int(struct dw_i2c_dev *dev) 717void i2c_dw_disable_int(struct dw_i2c_dev *dev)
709{ 718{
710 dw_writel(dev, 0, DW_IC_INTR_MASK); 719 dw_writel(dev, 0, DW_IC_INTR_MASK);
711} 720}
721EXPORT_SYMBOL_GPL(i2c_dw_disable_int);
712 722
713u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev) 723u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev)
714{ 724{
715 return dw_readl(dev, DW_IC_COMP_PARAM_1); 725 return dw_readl(dev, DW_IC_COMP_PARAM_1);
716} 726}
727EXPORT_SYMBOL_GPL(i2c_dw_read_comp_param);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 898dcf9c7ade..33e9b0c09af2 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -52,6 +52,7 @@
52 DH89xxCC (PCH) 0x2330 32 hard yes yes yes 52 DH89xxCC (PCH) 0x2330 32 hard yes yes yes
53 Panther Point (PCH) 0x1e22 32 hard yes yes yes 53 Panther Point (PCH) 0x1e22 32 hard yes yes yes
54 Lynx Point (PCH) 0x8c22 32 hard yes yes yes 54 Lynx Point (PCH) 0x8c22 32 hard yes yes yes
55 Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes
55 56
56 Features supported by this driver: 57 Features supported by this driver:
57 Software PEC no 58 Software PEC no
@@ -155,6 +156,7 @@
155#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330 156#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
156#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30 157#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
157#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22 158#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
159#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
158 160
159struct i801_priv { 161struct i801_priv {
160 struct i2c_adapter adapter; 162 struct i2c_adapter adapter;
@@ -771,6 +773,7 @@ static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
771 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) }, 773 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
772 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) }, 774 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
773 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) }, 775 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) },
776 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) },
774 { 0, } 777 { 0, }
775}; 778};
776 779
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 088c5c1ed17d..51f05b8520ed 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -365,10 +365,6 @@ static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
365 struct device_node *node = dev->of_node; 365 struct device_node *node = dev->of_node;
366 int ret; 366 int ret;
367 367
368 if (!node)
369 return -EINVAL;
370
371 i2c->speed = &mxs_i2c_95kHz_config;
372 ret = of_property_read_u32(node, "clock-frequency", &speed); 368 ret = of_property_read_u32(node, "clock-frequency", &speed);
373 if (ret) 369 if (ret)
374 dev_warn(dev, "No I2C speed selected, using 100kHz\n"); 370 dev_warn(dev, "No I2C speed selected, using 100kHz\n");
@@ -419,10 +415,13 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)
419 return err; 415 return err;
420 416
421 i2c->dev = dev; 417 i2c->dev = dev;
418 i2c->speed = &mxs_i2c_95kHz_config;
422 419
423 err = mxs_i2c_get_ofdata(i2c); 420 if (dev->of_node) {
424 if (err) 421 err = mxs_i2c_get_ofdata(i2c);
425 return err; 422 if (err)
423 return err;
424 }
426 425
427 platform_set_drvdata(pdev, i2c); 426 platform_set_drvdata(pdev, i2c);
428 427
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 5d54416770b0..8488bddfe465 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -48,8 +48,9 @@ enum {
48 mcntrl_afie = 0x00000002, 48 mcntrl_afie = 0x00000002,
49 mcntrl_naie = 0x00000004, 49 mcntrl_naie = 0x00000004,
50 mcntrl_drmie = 0x00000008, 50 mcntrl_drmie = 0x00000008,
51 mcntrl_daie = 0x00000020, 51 mcntrl_drsie = 0x00000010,
52 mcntrl_rffie = 0x00000040, 52 mcntrl_rffie = 0x00000020,
53 mcntrl_daie = 0x00000040,
53 mcntrl_tffie = 0x00000080, 54 mcntrl_tffie = 0x00000080,
54 mcntrl_reset = 0x00000100, 55 mcntrl_reset = 0x00000100,
55 mcntrl_cdbmode = 0x00000400, 56 mcntrl_cdbmode = 0x00000400,
@@ -290,31 +291,37 @@ static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data)
290 * or we didn't 'ask' for it yet. 291 * or we didn't 'ask' for it yet.
291 */ 292 */
292 if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) { 293 if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) {
293 dev_dbg(&alg_data->adapter.dev, 294 /* 'Asking' is done asynchronously, e.g. dummy TX of several
294 "%s(): Write dummy data to fill Rx-fifo...\n", 295 * bytes is done before the first actual RX arrives in FIFO.
295 __func__); 296 * Therefore, ordered bytes (via TX) are counted separately.
297 */
298 if (alg_data->mif.order) {
299 dev_dbg(&alg_data->adapter.dev,
300 "%s(): Write dummy data to fill Rx-fifo...\n",
301 __func__);
296 302
297 if (alg_data->mif.len == 1) { 303 if (alg_data->mif.order == 1) {
298 /* Last byte, do not acknowledge next rcv. */ 304 /* Last byte, do not acknowledge next rcv. */
299 val |= stop_bit; 305 val |= stop_bit;
306
307 /*
308 * Enable interrupt RFDAIE (data in Rx fifo),
309 * and disable DRMIE (need data for Tx)
310 */
311 ctl = ioread32(I2C_REG_CTL(alg_data));
312 ctl |= mcntrl_rffie | mcntrl_daie;
313 ctl &= ~mcntrl_drmie;
314 iowrite32(ctl, I2C_REG_CTL(alg_data));
315 }
300 316
301 /* 317 /*
302 * Enable interrupt RFDAIE (data in Rx fifo), 318 * Now we'll 'ask' for data:
303 * and disable DRMIE (need data for Tx) 319 * For each byte we want to receive, we must
320 * write a (dummy) byte to the Tx-FIFO.
304 */ 321 */
305 ctl = ioread32(I2C_REG_CTL(alg_data)); 322 iowrite32(val, I2C_REG_TX(alg_data));
306 ctl |= mcntrl_rffie | mcntrl_daie; 323 alg_data->mif.order--;
307 ctl &= ~mcntrl_drmie;
308 iowrite32(ctl, I2C_REG_CTL(alg_data));
309 } 324 }
310
311 /*
312 * Now we'll 'ask' for data:
313 * For each byte we want to receive, we must
314 * write a (dummy) byte to the Tx-FIFO.
315 */
316 iowrite32(val, I2C_REG_TX(alg_data));
317
318 return 0; 325 return 0;
319 } 326 }
320 327
@@ -514,6 +521,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
514 521
515 alg_data->mif.buf = pmsg->buf; 522 alg_data->mif.buf = pmsg->buf;
516 alg_data->mif.len = pmsg->len; 523 alg_data->mif.len = pmsg->len;
524 alg_data->mif.order = pmsg->len;
517 alg_data->mif.mode = (pmsg->flags & I2C_M_RD) ? 525 alg_data->mif.mode = (pmsg->flags & I2C_M_RD) ?
518 I2C_SMBUS_READ : I2C_SMBUS_WRITE; 526 I2C_SMBUS_READ : I2C_SMBUS_WRITE;
519 alg_data->mif.ret = 0; 527 alg_data->mif.ret = 0;
@@ -566,6 +574,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
566 /* Cleanup to be sure... */ 574 /* Cleanup to be sure... */
567 alg_data->mif.buf = NULL; 575 alg_data->mif.buf = NULL;
568 alg_data->mif.len = 0; 576 alg_data->mif.len = 0;
577 alg_data->mif.order = 0;
569 578
570 dev_dbg(&alg_data->adapter.dev, "%s(): exiting, stat = %x\n", 579 dev_dbg(&alg_data->adapter.dev, "%s(): exiting, stat = %x\n",
571 __func__, ioread32(I2C_REG_STS(alg_data))); 580 __func__, ioread32(I2C_REG_STS(alg_data)));
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 2efa56c5ff2c..2091ae8f539a 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -637,6 +637,22 @@ static void i2c_adapter_dev_release(struct device *dev)
637} 637}
638 638
639/* 639/*
640 * This function is only needed for mutex_lock_nested, so it is never
641 * called unless locking correctness checking is enabled. Thus we
642 * make it inline to avoid a compiler warning. That's what gcc ends up
643 * doing anyway.
644 */
645static inline unsigned int i2c_adapter_depth(struct i2c_adapter *adapter)
646{
647 unsigned int depth = 0;
648
649 while ((adapter = i2c_parent_is_i2c_adapter(adapter)))
650 depth++;
651
652 return depth;
653}
654
655/*
640 * Let users instantiate I2C devices through sysfs. This can be used when 656 * Let users instantiate I2C devices through sysfs. This can be used when
641 * platform initialization code doesn't contain the proper data for 657 * platform initialization code doesn't contain the proper data for
642 * whatever reason. Also useful for drivers that do device detection and 658 * whatever reason. Also useful for drivers that do device detection and
@@ -726,7 +742,8 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
726 742
727 /* Make sure the device was added through sysfs */ 743 /* Make sure the device was added through sysfs */
728 res = -ENOENT; 744 res = -ENOENT;
729 mutex_lock(&adap->userspace_clients_lock); 745 mutex_lock_nested(&adap->userspace_clients_lock,
746 i2c_adapter_depth(adap));
730 list_for_each_entry_safe(client, next, &adap->userspace_clients, 747 list_for_each_entry_safe(client, next, &adap->userspace_clients,
731 detected) { 748 detected) {
732 if (client->addr == addr) { 749 if (client->addr == addr) {
@@ -1073,7 +1090,8 @@ int i2c_del_adapter(struct i2c_adapter *adap)
1073 return res; 1090 return res;
1074 1091
1075 /* Remove devices instantiated from sysfs */ 1092 /* Remove devices instantiated from sysfs */
1076 mutex_lock(&adap->userspace_clients_lock); 1093 mutex_lock_nested(&adap->userspace_clients_lock,
1094 i2c_adapter_depth(adap));
1077 list_for_each_entry_safe(client, next, &adap->userspace_clients, 1095 list_for_each_entry_safe(client, next, &adap->userspace_clients,
1078 detected) { 1096 detected) {
1079 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, 1097 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index f61780a02374..3bd5540238a7 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -617,7 +617,7 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
617 st->adc_clk = clk_get(&pdev->dev, "adc_op_clk"); 617 st->adc_clk = clk_get(&pdev->dev, "adc_op_clk");
618 if (IS_ERR(st->adc_clk)) { 618 if (IS_ERR(st->adc_clk)) {
619 dev_err(&pdev->dev, "Failed to get the ADC clock.\n"); 619 dev_err(&pdev->dev, "Failed to get the ADC clock.\n");
620 ret = PTR_ERR(st->clk); 620 ret = PTR_ERR(st->adc_clk);
621 goto error_disable_clk; 621 goto error_disable_clk;
622 } 622 }
623 623
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 51f42061dae9..6cfd4d8fd0bd 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -1361,11 +1361,11 @@ static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1361 struct tid_info *t = dev->rdev.lldi.tids; 1361 struct tid_info *t = dev->rdev.lldi.tids;
1362 1362
1363 ep = lookup_tid(t, tid); 1363 ep = lookup_tid(t, tid);
1364 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1365 if (!ep) { 1364 if (!ep) {
1366 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n"); 1365 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1367 return 0; 1366 return 0;
1368 } 1367 }
1368 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1369 mutex_lock(&ep->com.mutex); 1369 mutex_lock(&ep->com.mutex);
1370 switch (ep->com.state) { 1370 switch (ep->com.state) {
1371 case ABORTING: 1371 case ABORTING:
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.c b/drivers/infiniband/hw/ehca/ehca_irq.c
index 53589000fd07..8615d7cf7e01 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.c
+++ b/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -42,6 +42,7 @@
42 */ 42 */
43 43
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/smpboot.h>
45 46
46#include "ehca_classes.h" 47#include "ehca_classes.h"
47#include "ehca_irq.h" 48#include "ehca_irq.h"
@@ -652,7 +653,7 @@ void ehca_tasklet_eq(unsigned long data)
652 ehca_process_eq((struct ehca_shca*)data, 1); 653 ehca_process_eq((struct ehca_shca*)data, 1);
653} 654}
654 655
655static inline int find_next_online_cpu(struct ehca_comp_pool *pool) 656static int find_next_online_cpu(struct ehca_comp_pool *pool)
656{ 657{
657 int cpu; 658 int cpu;
658 unsigned long flags; 659 unsigned long flags;
@@ -662,17 +663,20 @@ static inline int find_next_online_cpu(struct ehca_comp_pool *pool)
662 ehca_dmp(cpu_online_mask, cpumask_size(), ""); 663 ehca_dmp(cpu_online_mask, cpumask_size(), "");
663 664
664 spin_lock_irqsave(&pool->last_cpu_lock, flags); 665 spin_lock_irqsave(&pool->last_cpu_lock, flags);
665 cpu = cpumask_next(pool->last_cpu, cpu_online_mask); 666 do {
666 if (cpu >= nr_cpu_ids) 667 cpu = cpumask_next(pool->last_cpu, cpu_online_mask);
667 cpu = cpumask_first(cpu_online_mask); 668 if (cpu >= nr_cpu_ids)
668 pool->last_cpu = cpu; 669 cpu = cpumask_first(cpu_online_mask);
670 pool->last_cpu = cpu;
671 } while (!per_cpu_ptr(pool->cpu_comp_tasks, cpu)->active);
669 spin_unlock_irqrestore(&pool->last_cpu_lock, flags); 672 spin_unlock_irqrestore(&pool->last_cpu_lock, flags);
670 673
671 return cpu; 674 return cpu;
672} 675}
673 676
674static void __queue_comp_task(struct ehca_cq *__cq, 677static void __queue_comp_task(struct ehca_cq *__cq,
675 struct ehca_cpu_comp_task *cct) 678 struct ehca_cpu_comp_task *cct,
679 struct task_struct *thread)
676{ 680{
677 unsigned long flags; 681 unsigned long flags;
678 682
@@ -683,7 +687,7 @@ static void __queue_comp_task(struct ehca_cq *__cq,
683 __cq->nr_callbacks++; 687 __cq->nr_callbacks++;
684 list_add_tail(&__cq->entry, &cct->cq_list); 688 list_add_tail(&__cq->entry, &cct->cq_list);
685 cct->cq_jobs++; 689 cct->cq_jobs++;
686 wake_up(&cct->wait_queue); 690 wake_up_process(thread);
687 } else 691 } else
688 __cq->nr_callbacks++; 692 __cq->nr_callbacks++;
689 693
@@ -695,6 +699,7 @@ static void queue_comp_task(struct ehca_cq *__cq)
695{ 699{
696 int cpu_id; 700 int cpu_id;
697 struct ehca_cpu_comp_task *cct; 701 struct ehca_cpu_comp_task *cct;
702 struct task_struct *thread;
698 int cq_jobs; 703 int cq_jobs;
699 unsigned long flags; 704 unsigned long flags;
700 705
@@ -702,7 +707,8 @@ static void queue_comp_task(struct ehca_cq *__cq)
702 BUG_ON(!cpu_online(cpu_id)); 707 BUG_ON(!cpu_online(cpu_id));
703 708
704 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); 709 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
705 BUG_ON(!cct); 710 thread = *per_cpu_ptr(pool->cpu_comp_threads, cpu_id);
711 BUG_ON(!cct || !thread);
706 712
707 spin_lock_irqsave(&cct->task_lock, flags); 713 spin_lock_irqsave(&cct->task_lock, flags);
708 cq_jobs = cct->cq_jobs; 714 cq_jobs = cct->cq_jobs;
@@ -710,28 +716,25 @@ static void queue_comp_task(struct ehca_cq *__cq)
710 if (cq_jobs > 0) { 716 if (cq_jobs > 0) {
711 cpu_id = find_next_online_cpu(pool); 717 cpu_id = find_next_online_cpu(pool);
712 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); 718 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
713 BUG_ON(!cct); 719 thread = *per_cpu_ptr(pool->cpu_comp_threads, cpu_id);
720 BUG_ON(!cct || !thread);
714 } 721 }
715 722 __queue_comp_task(__cq, cct, thread);
716 __queue_comp_task(__cq, cct);
717} 723}
718 724
719static void run_comp_task(struct ehca_cpu_comp_task *cct) 725static void run_comp_task(struct ehca_cpu_comp_task *cct)
720{ 726{
721 struct ehca_cq *cq; 727 struct ehca_cq *cq;
722 unsigned long flags;
723
724 spin_lock_irqsave(&cct->task_lock, flags);
725 728
726 while (!list_empty(&cct->cq_list)) { 729 while (!list_empty(&cct->cq_list)) {
727 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); 730 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
728 spin_unlock_irqrestore(&cct->task_lock, flags); 731 spin_unlock_irq(&cct->task_lock);
729 732
730 comp_event_callback(cq); 733 comp_event_callback(cq);
731 if (atomic_dec_and_test(&cq->nr_events)) 734 if (atomic_dec_and_test(&cq->nr_events))
732 wake_up(&cq->wait_completion); 735 wake_up(&cq->wait_completion);
733 736
734 spin_lock_irqsave(&cct->task_lock, flags); 737 spin_lock_irq(&cct->task_lock);
735 spin_lock(&cq->task_lock); 738 spin_lock(&cq->task_lock);
736 cq->nr_callbacks--; 739 cq->nr_callbacks--;
737 if (!cq->nr_callbacks) { 740 if (!cq->nr_callbacks) {
@@ -740,159 +743,76 @@ static void run_comp_task(struct ehca_cpu_comp_task *cct)
740 } 743 }
741 spin_unlock(&cq->task_lock); 744 spin_unlock(&cq->task_lock);
742 } 745 }
743
744 spin_unlock_irqrestore(&cct->task_lock, flags);
745} 746}
746 747
747static int comp_task(void *__cct) 748static void comp_task_park(unsigned int cpu)
748{ 749{
749 struct ehca_cpu_comp_task *cct = __cct; 750 struct ehca_cpu_comp_task *cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
750 int cql_empty; 751 struct ehca_cpu_comp_task *target;
751 DECLARE_WAITQUEUE(wait, current); 752 struct task_struct *thread;
752 753 struct ehca_cq *cq, *tmp;
753 set_current_state(TASK_INTERRUPTIBLE); 754 LIST_HEAD(list);
754 while (!kthread_should_stop()) {
755 add_wait_queue(&cct->wait_queue, &wait);
756
757 spin_lock_irq(&cct->task_lock);
758 cql_empty = list_empty(&cct->cq_list);
759 spin_unlock_irq(&cct->task_lock);
760 if (cql_empty)
761 schedule();
762 else
763 __set_current_state(TASK_RUNNING);
764
765 remove_wait_queue(&cct->wait_queue, &wait);
766 755
767 spin_lock_irq(&cct->task_lock); 756 spin_lock_irq(&cct->task_lock);
768 cql_empty = list_empty(&cct->cq_list); 757 cct->cq_jobs = 0;
769 spin_unlock_irq(&cct->task_lock); 758 cct->active = 0;
770 if (!cql_empty) 759 list_splice_init(&cct->cq_list, &list);
771 run_comp_task(__cct); 760 spin_unlock_irq(&cct->task_lock);
772 761
773 set_current_state(TASK_INTERRUPTIBLE); 762 cpu = find_next_online_cpu(pool);
763 target = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
764 thread = *per_cpu_ptr(pool->cpu_comp_threads, cpu);
765 spin_lock_irq(&target->task_lock);
766 list_for_each_entry_safe(cq, tmp, &list, entry) {
767 list_del(&cq->entry);
768 __queue_comp_task(cq, target, thread);
774 } 769 }
775 __set_current_state(TASK_RUNNING); 770 spin_unlock_irq(&target->task_lock);
776
777 return 0;
778}
779
780static struct task_struct *create_comp_task(struct ehca_comp_pool *pool,
781 int cpu)
782{
783 struct ehca_cpu_comp_task *cct;
784
785 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
786 spin_lock_init(&cct->task_lock);
787 INIT_LIST_HEAD(&cct->cq_list);
788 init_waitqueue_head(&cct->wait_queue);
789 cct->task = kthread_create_on_node(comp_task, cct, cpu_to_node(cpu),
790 "ehca_comp/%d", cpu);
791
792 return cct->task;
793} 771}
794 772
795static void destroy_comp_task(struct ehca_comp_pool *pool, 773static void comp_task_stop(unsigned int cpu, bool online)
796 int cpu)
797{ 774{
798 struct ehca_cpu_comp_task *cct; 775 struct ehca_cpu_comp_task *cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
799 struct task_struct *task;
800 unsigned long flags_cct;
801
802 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
803
804 spin_lock_irqsave(&cct->task_lock, flags_cct);
805 776
806 task = cct->task; 777 spin_lock_irq(&cct->task_lock);
807 cct->task = NULL;
808 cct->cq_jobs = 0; 778 cct->cq_jobs = 0;
809 779 cct->active = 0;
810 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 780 WARN_ON(!list_empty(&cct->cq_list));
811 781 spin_unlock_irq(&cct->task_lock);
812 if (task)
813 kthread_stop(task);
814} 782}
815 783
816static void __cpuinit take_over_work(struct ehca_comp_pool *pool, int cpu) 784static int comp_task_should_run(unsigned int cpu)
817{ 785{
818 struct ehca_cpu_comp_task *cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu); 786 struct ehca_cpu_comp_task *cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
819 LIST_HEAD(list);
820 struct ehca_cq *cq;
821 unsigned long flags_cct;
822
823 spin_lock_irqsave(&cct->task_lock, flags_cct);
824
825 list_splice_init(&cct->cq_list, &list);
826
827 while (!list_empty(&list)) {
828 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
829
830 list_del(&cq->entry);
831 __queue_comp_task(cq, this_cpu_ptr(pool->cpu_comp_tasks));
832 }
833
834 spin_unlock_irqrestore(&cct->task_lock, flags_cct);
835 787
788 return cct->cq_jobs;
836} 789}
837 790
838static int __cpuinit comp_pool_callback(struct notifier_block *nfb, 791static void comp_task(unsigned int cpu)
839 unsigned long action,
840 void *hcpu)
841{ 792{
842 unsigned int cpu = (unsigned long)hcpu; 793 struct ehca_cpu_comp_task *cct = this_cpu_ptr(pool->cpu_comp_tasks);
843 struct ehca_cpu_comp_task *cct; 794 int cql_empty;
844 795
845 switch (action) { 796 spin_lock_irq(&cct->task_lock);
846 case CPU_UP_PREPARE: 797 cql_empty = list_empty(&cct->cq_list);
847 case CPU_UP_PREPARE_FROZEN: 798 if (!cql_empty) {
848 ehca_gen_dbg("CPU: %x (CPU_PREPARE)", cpu); 799 __set_current_state(TASK_RUNNING);
849 if (!create_comp_task(pool, cpu)) { 800 run_comp_task(cct);
850 ehca_gen_err("Can't create comp_task for cpu: %x", cpu);
851 return notifier_from_errno(-ENOMEM);
852 }
853 break;
854 case CPU_UP_CANCELED:
855 case CPU_UP_CANCELED_FROZEN:
856 ehca_gen_dbg("CPU: %x (CPU_CANCELED)", cpu);
857 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
858 kthread_bind(cct->task, cpumask_any(cpu_online_mask));
859 destroy_comp_task(pool, cpu);
860 break;
861 case CPU_ONLINE:
862 case CPU_ONLINE_FROZEN:
863 ehca_gen_dbg("CPU: %x (CPU_ONLINE)", cpu);
864 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
865 kthread_bind(cct->task, cpu);
866 wake_up_process(cct->task);
867 break;
868 case CPU_DOWN_PREPARE:
869 case CPU_DOWN_PREPARE_FROZEN:
870 ehca_gen_dbg("CPU: %x (CPU_DOWN_PREPARE)", cpu);
871 break;
872 case CPU_DOWN_FAILED:
873 case CPU_DOWN_FAILED_FROZEN:
874 ehca_gen_dbg("CPU: %x (CPU_DOWN_FAILED)", cpu);
875 break;
876 case CPU_DEAD:
877 case CPU_DEAD_FROZEN:
878 ehca_gen_dbg("CPU: %x (CPU_DEAD)", cpu);
879 destroy_comp_task(pool, cpu);
880 take_over_work(pool, cpu);
881 break;
882 } 801 }
883 802 spin_unlock_irq(&cct->task_lock);
884 return NOTIFY_OK;
885} 803}
886 804
887static struct notifier_block comp_pool_callback_nb __cpuinitdata = { 805static struct smp_hotplug_thread comp_pool_threads = {
888 .notifier_call = comp_pool_callback, 806 .thread_should_run = comp_task_should_run,
889 .priority = 0, 807 .thread_fn = comp_task,
808 .thread_comm = "ehca_comp/%u",
809 .cleanup = comp_task_stop,
810 .park = comp_task_park,
890}; 811};
891 812
892int ehca_create_comp_pool(void) 813int ehca_create_comp_pool(void)
893{ 814{
894 int cpu; 815 int cpu, ret = -ENOMEM;
895 struct task_struct *task;
896 816
897 if (!ehca_scaling_code) 817 if (!ehca_scaling_code)
898 return 0; 818 return 0;
@@ -905,38 +825,46 @@ int ehca_create_comp_pool(void)
905 pool->last_cpu = cpumask_any(cpu_online_mask); 825 pool->last_cpu = cpumask_any(cpu_online_mask);
906 826
907 pool->cpu_comp_tasks = alloc_percpu(struct ehca_cpu_comp_task); 827 pool->cpu_comp_tasks = alloc_percpu(struct ehca_cpu_comp_task);
908 if (pool->cpu_comp_tasks == NULL) { 828 if (!pool->cpu_comp_tasks)
909 kfree(pool); 829 goto out_pool;
910 return -EINVAL;
911 }
912 830
913 for_each_online_cpu(cpu) { 831 pool->cpu_comp_threads = alloc_percpu(struct task_struct *);
914 task = create_comp_task(pool, cpu); 832 if (!pool->cpu_comp_threads)
915 if (task) { 833 goto out_tasks;
916 kthread_bind(task, cpu); 834
917 wake_up_process(task); 835 for_each_present_cpu(cpu) {
918 } 836 struct ehca_cpu_comp_task *cct;
837
838 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
839 spin_lock_init(&cct->task_lock);
840 INIT_LIST_HEAD(&cct->cq_list);
919 } 841 }
920 842
921 register_hotcpu_notifier(&comp_pool_callback_nb); 843 comp_pool_threads.store = pool->cpu_comp_threads;
844 ret = smpboot_register_percpu_thread(&comp_pool_threads);
845 if (ret)
846 goto out_threads;
922 847
923 printk(KERN_INFO "eHCA scaling code enabled\n"); 848 pr_info("eHCA scaling code enabled\n");
849 return ret;
924 850
925 return 0; 851out_threads:
852 free_percpu(pool->cpu_comp_threads);
853out_tasks:
854 free_percpu(pool->cpu_comp_tasks);
855out_pool:
856 kfree(pool);
857 return ret;
926} 858}
927 859
928void ehca_destroy_comp_pool(void) 860void ehca_destroy_comp_pool(void)
929{ 861{
930 int i;
931
932 if (!ehca_scaling_code) 862 if (!ehca_scaling_code)
933 return; 863 return;
934 864
935 unregister_hotcpu_notifier(&comp_pool_callback_nb); 865 smpboot_unregister_percpu_thread(&comp_pool_threads);
936
937 for_each_online_cpu(i)
938 destroy_comp_task(pool, i);
939 866
867 free_percpu(pool->cpu_comp_threads);
940 free_percpu(pool->cpu_comp_tasks); 868 free_percpu(pool->cpu_comp_tasks);
941 kfree(pool); 869 kfree(pool);
942} 870}
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.h b/drivers/infiniband/hw/ehca/ehca_irq.h
index 3346cb06cea6..5370199f08c7 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.h
+++ b/drivers/infiniband/hw/ehca/ehca_irq.h
@@ -58,15 +58,15 @@ void ehca_tasklet_eq(unsigned long data);
58void ehca_process_eq(struct ehca_shca *shca, int is_irq); 58void ehca_process_eq(struct ehca_shca *shca, int is_irq);
59 59
60struct ehca_cpu_comp_task { 60struct ehca_cpu_comp_task {
61 wait_queue_head_t wait_queue;
62 struct list_head cq_list; 61 struct list_head cq_list;
63 struct task_struct *task;
64 spinlock_t task_lock; 62 spinlock_t task_lock;
65 int cq_jobs; 63 int cq_jobs;
64 int active;
66}; 65};
67 66
68struct ehca_comp_pool { 67struct ehca_comp_pool {
69 struct ehca_cpu_comp_task *cpu_comp_tasks; 68 struct ehca_cpu_comp_task __percpu *cpu_comp_tasks;
69 struct task_struct * __percpu *cpu_comp_threads;
70 int last_cpu; 70 int last_cpu;
71 spinlock_t last_cpu_lock; 71 spinlock_t last_cpu_lock;
72}; 72};
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index cb5b7f7d4d38..b29a4246ef41 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -2219,7 +2219,6 @@ static bool ocrdma_poll_success_scqe(struct ocrdma_qp *qp,
2219 u32 wqe_idx; 2219 u32 wqe_idx;
2220 2220
2221 if (!qp->wqe_wr_id_tbl[tail].signaled) { 2221 if (!qp->wqe_wr_id_tbl[tail].signaled) {
2222 expand = true; /* CQE cannot be consumed yet */
2223 *polled = false; /* WC cannot be consumed yet */ 2222 *polled = false; /* WC cannot be consumed yet */
2224 } else { 2223 } else {
2225 ibwc->status = IB_WC_SUCCESS; 2224 ibwc->status = IB_WC_SUCCESS;
@@ -2227,10 +2226,11 @@ static bool ocrdma_poll_success_scqe(struct ocrdma_qp *qp,
2227 ibwc->qp = &qp->ibqp; 2226 ibwc->qp = &qp->ibqp;
2228 ocrdma_update_wc(qp, ibwc, tail); 2227 ocrdma_update_wc(qp, ibwc, tail);
2229 *polled = true; 2228 *polled = true;
2230 wqe_idx = le32_to_cpu(cqe->wq.wqeidx) & OCRDMA_CQE_WQEIDX_MASK;
2231 if (tail != wqe_idx)
2232 expand = true; /* Coalesced CQE can't be consumed yet */
2233 } 2229 }
2230 wqe_idx = le32_to_cpu(cqe->wq.wqeidx) & OCRDMA_CQE_WQEIDX_MASK;
2231 if (tail != wqe_idx)
2232 expand = true; /* Coalesced CQE can't be consumed yet */
2233
2234 ocrdma_hwq_inc_tail(&qp->sq); 2234 ocrdma_hwq_inc_tail(&qp->sq);
2235 return expand; 2235 return expand;
2236} 2236}
diff --git a/drivers/infiniband/hw/qib/qib_mad.c b/drivers/infiniband/hw/qib/qib_mad.c
index 19f1e6c45fb6..ccb119143d20 100644
--- a/drivers/infiniband/hw/qib/qib_mad.c
+++ b/drivers/infiniband/hw/qib/qib_mad.c
@@ -471,9 +471,10 @@ static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
471 if (port_num != port) { 471 if (port_num != port) {
472 ibp = to_iport(ibdev, port_num); 472 ibp = to_iport(ibdev, port_num);
473 ret = check_mkey(ibp, smp, 0); 473 ret = check_mkey(ibp, smp, 0);
474 if (ret) 474 if (ret) {
475 ret = IB_MAD_RESULT_FAILURE; 475 ret = IB_MAD_RESULT_FAILURE;
476 goto bail; 476 goto bail;
477 }
477 } 478 }
478 } 479 }
479 480
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index ca43901ed861..0af216d21f87 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -262,7 +262,10 @@ struct ipoib_ethtool_st {
262 u16 max_coalesced_frames; 262 u16 max_coalesced_frames;
263}; 263};
264 264
265struct ipoib_neigh_table;
266
265struct ipoib_neigh_hash { 267struct ipoib_neigh_hash {
268 struct ipoib_neigh_table *ntbl;
266 struct ipoib_neigh __rcu **buckets; 269 struct ipoib_neigh __rcu **buckets;
267 struct rcu_head rcu; 270 struct rcu_head rcu;
268 u32 mask; 271 u32 mask;
@@ -271,9 +274,9 @@ struct ipoib_neigh_hash {
271 274
272struct ipoib_neigh_table { 275struct ipoib_neigh_table {
273 struct ipoib_neigh_hash __rcu *htbl; 276 struct ipoib_neigh_hash __rcu *htbl;
274 rwlock_t rwlock;
275 atomic_t entries; 277 atomic_t entries;
276 struct completion flushed; 278 struct completion flushed;
279 struct completion deleted;
277}; 280};
278 281
279/* 282/*
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 3e2085a3ee47..1e19b5ae7c47 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -546,15 +546,15 @@ static void neigh_add_path(struct sk_buff *skb, u8 *daddr,
546 struct ipoib_neigh *neigh; 546 struct ipoib_neigh *neigh;
547 unsigned long flags; 547 unsigned long flags;
548 548
549 spin_lock_irqsave(&priv->lock, flags);
549 neigh = ipoib_neigh_alloc(daddr, dev); 550 neigh = ipoib_neigh_alloc(daddr, dev);
550 if (!neigh) { 551 if (!neigh) {
552 spin_unlock_irqrestore(&priv->lock, flags);
551 ++dev->stats.tx_dropped; 553 ++dev->stats.tx_dropped;
552 dev_kfree_skb_any(skb); 554 dev_kfree_skb_any(skb);
553 return; 555 return;
554 } 556 }
555 557
556 spin_lock_irqsave(&priv->lock, flags);
557
558 path = __path_find(dev, daddr + 4); 558 path = __path_find(dev, daddr + 4);
559 if (!path) { 559 if (!path) {
560 path = path_rec_create(dev, daddr + 4); 560 path = path_rec_create(dev, daddr + 4);
@@ -863,10 +863,10 @@ static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv)
863 if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) 863 if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags))
864 return; 864 return;
865 865
866 write_lock_bh(&ntbl->rwlock); 866 spin_lock_irqsave(&priv->lock, flags);
867 867
868 htbl = rcu_dereference_protected(ntbl->htbl, 868 htbl = rcu_dereference_protected(ntbl->htbl,
869 lockdep_is_held(&ntbl->rwlock)); 869 lockdep_is_held(&priv->lock));
870 870
871 if (!htbl) 871 if (!htbl)
872 goto out_unlock; 872 goto out_unlock;
@@ -883,16 +883,14 @@ static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv)
883 struct ipoib_neigh __rcu **np = &htbl->buckets[i]; 883 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
884 884
885 while ((neigh = rcu_dereference_protected(*np, 885 while ((neigh = rcu_dereference_protected(*np,
886 lockdep_is_held(&ntbl->rwlock))) != NULL) { 886 lockdep_is_held(&priv->lock))) != NULL) {
887 /* was the neigh idle for two GC periods */ 887 /* was the neigh idle for two GC periods */
888 if (time_after(neigh_obsolete, neigh->alive)) { 888 if (time_after(neigh_obsolete, neigh->alive)) {
889 rcu_assign_pointer(*np, 889 rcu_assign_pointer(*np,
890 rcu_dereference_protected(neigh->hnext, 890 rcu_dereference_protected(neigh->hnext,
891 lockdep_is_held(&ntbl->rwlock))); 891 lockdep_is_held(&priv->lock)));
892 /* remove from path/mc list */ 892 /* remove from path/mc list */
893 spin_lock_irqsave(&priv->lock, flags);
894 list_del(&neigh->list); 893 list_del(&neigh->list);
895 spin_unlock_irqrestore(&priv->lock, flags);
896 call_rcu(&neigh->rcu, ipoib_neigh_reclaim); 894 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
897 } else { 895 } else {
898 np = &neigh->hnext; 896 np = &neigh->hnext;
@@ -902,7 +900,7 @@ static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv)
902 } 900 }
903 901
904out_unlock: 902out_unlock:
905 write_unlock_bh(&ntbl->rwlock); 903 spin_unlock_irqrestore(&priv->lock, flags);
906} 904}
907 905
908static void ipoib_reap_neigh(struct work_struct *work) 906static void ipoib_reap_neigh(struct work_struct *work)
@@ -947,10 +945,8 @@ struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
947 struct ipoib_neigh *neigh; 945 struct ipoib_neigh *neigh;
948 u32 hash_val; 946 u32 hash_val;
949 947
950 write_lock_bh(&ntbl->rwlock);
951
952 htbl = rcu_dereference_protected(ntbl->htbl, 948 htbl = rcu_dereference_protected(ntbl->htbl,
953 lockdep_is_held(&ntbl->rwlock)); 949 lockdep_is_held(&priv->lock));
954 if (!htbl) { 950 if (!htbl) {
955 neigh = NULL; 951 neigh = NULL;
956 goto out_unlock; 952 goto out_unlock;
@@ -961,10 +957,10 @@ struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
961 */ 957 */
962 hash_val = ipoib_addr_hash(htbl, daddr); 958 hash_val = ipoib_addr_hash(htbl, daddr);
963 for (neigh = rcu_dereference_protected(htbl->buckets[hash_val], 959 for (neigh = rcu_dereference_protected(htbl->buckets[hash_val],
964 lockdep_is_held(&ntbl->rwlock)); 960 lockdep_is_held(&priv->lock));
965 neigh != NULL; 961 neigh != NULL;
966 neigh = rcu_dereference_protected(neigh->hnext, 962 neigh = rcu_dereference_protected(neigh->hnext,
967 lockdep_is_held(&ntbl->rwlock))) { 963 lockdep_is_held(&priv->lock))) {
968 if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) { 964 if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) {
969 /* found, take one ref on behalf of the caller */ 965 /* found, take one ref on behalf of the caller */
970 if (!atomic_inc_not_zero(&neigh->refcnt)) { 966 if (!atomic_inc_not_zero(&neigh->refcnt)) {
@@ -987,12 +983,11 @@ struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
987 /* put in hash */ 983 /* put in hash */
988 rcu_assign_pointer(neigh->hnext, 984 rcu_assign_pointer(neigh->hnext,
989 rcu_dereference_protected(htbl->buckets[hash_val], 985 rcu_dereference_protected(htbl->buckets[hash_val],
990 lockdep_is_held(&ntbl->rwlock))); 986 lockdep_is_held(&priv->lock)));
991 rcu_assign_pointer(htbl->buckets[hash_val], neigh); 987 rcu_assign_pointer(htbl->buckets[hash_val], neigh);
992 atomic_inc(&ntbl->entries); 988 atomic_inc(&ntbl->entries);
993 989
994out_unlock: 990out_unlock:
995 write_unlock_bh(&ntbl->rwlock);
996 991
997 return neigh; 992 return neigh;
998} 993}
@@ -1040,35 +1035,29 @@ void ipoib_neigh_free(struct ipoib_neigh *neigh)
1040 struct ipoib_neigh *n; 1035 struct ipoib_neigh *n;
1041 u32 hash_val; 1036 u32 hash_val;
1042 1037
1043 write_lock_bh(&ntbl->rwlock);
1044
1045 htbl = rcu_dereference_protected(ntbl->htbl, 1038 htbl = rcu_dereference_protected(ntbl->htbl,
1046 lockdep_is_held(&ntbl->rwlock)); 1039 lockdep_is_held(&priv->lock));
1047 if (!htbl) 1040 if (!htbl)
1048 goto out_unlock; 1041 return;
1049 1042
1050 hash_val = ipoib_addr_hash(htbl, neigh->daddr); 1043 hash_val = ipoib_addr_hash(htbl, neigh->daddr);
1051 np = &htbl->buckets[hash_val]; 1044 np = &htbl->buckets[hash_val];
1052 for (n = rcu_dereference_protected(*np, 1045 for (n = rcu_dereference_protected(*np,
1053 lockdep_is_held(&ntbl->rwlock)); 1046 lockdep_is_held(&priv->lock));
1054 n != NULL; 1047 n != NULL;
1055 n = rcu_dereference_protected(*np, 1048 n = rcu_dereference_protected(*np,
1056 lockdep_is_held(&ntbl->rwlock))) { 1049 lockdep_is_held(&priv->lock))) {
1057 if (n == neigh) { 1050 if (n == neigh) {
1058 /* found */ 1051 /* found */
1059 rcu_assign_pointer(*np, 1052 rcu_assign_pointer(*np,
1060 rcu_dereference_protected(neigh->hnext, 1053 rcu_dereference_protected(neigh->hnext,
1061 lockdep_is_held(&ntbl->rwlock))); 1054 lockdep_is_held(&priv->lock)));
1062 call_rcu(&neigh->rcu, ipoib_neigh_reclaim); 1055 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1063 goto out_unlock; 1056 return;
1064 } else { 1057 } else {
1065 np = &n->hnext; 1058 np = &n->hnext;
1066 } 1059 }
1067 } 1060 }
1068
1069out_unlock:
1070 write_unlock_bh(&ntbl->rwlock);
1071
1072} 1061}
1073 1062
1074static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv) 1063static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)
@@ -1080,7 +1069,6 @@ static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)
1080 1069
1081 clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags); 1070 clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
1082 ntbl->htbl = NULL; 1071 ntbl->htbl = NULL;
1083 rwlock_init(&ntbl->rwlock);
1084 htbl = kzalloc(sizeof(*htbl), GFP_KERNEL); 1072 htbl = kzalloc(sizeof(*htbl), GFP_KERNEL);
1085 if (!htbl) 1073 if (!htbl)
1086 return -ENOMEM; 1074 return -ENOMEM;
@@ -1095,6 +1083,7 @@ static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)
1095 htbl->mask = (size - 1); 1083 htbl->mask = (size - 1);
1096 htbl->buckets = buckets; 1084 htbl->buckets = buckets;
1097 ntbl->htbl = htbl; 1085 ntbl->htbl = htbl;
1086 htbl->ntbl = ntbl;
1098 atomic_set(&ntbl->entries, 0); 1087 atomic_set(&ntbl->entries, 0);
1099 1088
1100 /* start garbage collection */ 1089 /* start garbage collection */
@@ -1111,9 +1100,11 @@ static void neigh_hash_free_rcu(struct rcu_head *head)
1111 struct ipoib_neigh_hash, 1100 struct ipoib_neigh_hash,
1112 rcu); 1101 rcu);
1113 struct ipoib_neigh __rcu **buckets = htbl->buckets; 1102 struct ipoib_neigh __rcu **buckets = htbl->buckets;
1103 struct ipoib_neigh_table *ntbl = htbl->ntbl;
1114 1104
1115 kfree(buckets); 1105 kfree(buckets);
1116 kfree(htbl); 1106 kfree(htbl);
1107 complete(&ntbl->deleted);
1117} 1108}
1118 1109
1119void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid) 1110void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid)
@@ -1125,10 +1116,10 @@ void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid)
1125 int i; 1116 int i;
1126 1117
1127 /* remove all neigh connected to a given path or mcast */ 1118 /* remove all neigh connected to a given path or mcast */
1128 write_lock_bh(&ntbl->rwlock); 1119 spin_lock_irqsave(&priv->lock, flags);
1129 1120
1130 htbl = rcu_dereference_protected(ntbl->htbl, 1121 htbl = rcu_dereference_protected(ntbl->htbl,
1131 lockdep_is_held(&ntbl->rwlock)); 1122 lockdep_is_held(&priv->lock));
1132 1123
1133 if (!htbl) 1124 if (!htbl)
1134 goto out_unlock; 1125 goto out_unlock;
@@ -1138,16 +1129,14 @@ void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid)
1138 struct ipoib_neigh __rcu **np = &htbl->buckets[i]; 1129 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1139 1130
1140 while ((neigh = rcu_dereference_protected(*np, 1131 while ((neigh = rcu_dereference_protected(*np,
1141 lockdep_is_held(&ntbl->rwlock))) != NULL) { 1132 lockdep_is_held(&priv->lock))) != NULL) {
1142 /* delete neighs belong to this parent */ 1133 /* delete neighs belong to this parent */
1143 if (!memcmp(gid, neigh->daddr + 4, sizeof (union ib_gid))) { 1134 if (!memcmp(gid, neigh->daddr + 4, sizeof (union ib_gid))) {
1144 rcu_assign_pointer(*np, 1135 rcu_assign_pointer(*np,
1145 rcu_dereference_protected(neigh->hnext, 1136 rcu_dereference_protected(neigh->hnext,
1146 lockdep_is_held(&ntbl->rwlock))); 1137 lockdep_is_held(&priv->lock)));
1147 /* remove from parent list */ 1138 /* remove from parent list */
1148 spin_lock_irqsave(&priv->lock, flags);
1149 list_del(&neigh->list); 1139 list_del(&neigh->list);
1150 spin_unlock_irqrestore(&priv->lock, flags);
1151 call_rcu(&neigh->rcu, ipoib_neigh_reclaim); 1140 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1152 } else { 1141 } else {
1153 np = &neigh->hnext; 1142 np = &neigh->hnext;
@@ -1156,7 +1145,7 @@ void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid)
1156 } 1145 }
1157 } 1146 }
1158out_unlock: 1147out_unlock:
1159 write_unlock_bh(&ntbl->rwlock); 1148 spin_unlock_irqrestore(&priv->lock, flags);
1160} 1149}
1161 1150
1162static void ipoib_flush_neighs(struct ipoib_dev_priv *priv) 1151static void ipoib_flush_neighs(struct ipoib_dev_priv *priv)
@@ -1164,37 +1153,44 @@ static void ipoib_flush_neighs(struct ipoib_dev_priv *priv)
1164 struct ipoib_neigh_table *ntbl = &priv->ntbl; 1153 struct ipoib_neigh_table *ntbl = &priv->ntbl;
1165 struct ipoib_neigh_hash *htbl; 1154 struct ipoib_neigh_hash *htbl;
1166 unsigned long flags; 1155 unsigned long flags;
1167 int i; 1156 int i, wait_flushed = 0;
1168 1157
1169 write_lock_bh(&ntbl->rwlock); 1158 init_completion(&priv->ntbl.flushed);
1159
1160 spin_lock_irqsave(&priv->lock, flags);
1170 1161
1171 htbl = rcu_dereference_protected(ntbl->htbl, 1162 htbl = rcu_dereference_protected(ntbl->htbl,
1172 lockdep_is_held(&ntbl->rwlock)); 1163 lockdep_is_held(&priv->lock));
1173 if (!htbl) 1164 if (!htbl)
1174 goto out_unlock; 1165 goto out_unlock;
1175 1166
1167 wait_flushed = atomic_read(&priv->ntbl.entries);
1168 if (!wait_flushed)
1169 goto free_htbl;
1170
1176 for (i = 0; i < htbl->size; i++) { 1171 for (i = 0; i < htbl->size; i++) {
1177 struct ipoib_neigh *neigh; 1172 struct ipoib_neigh *neigh;
1178 struct ipoib_neigh __rcu **np = &htbl->buckets[i]; 1173 struct ipoib_neigh __rcu **np = &htbl->buckets[i];
1179 1174
1180 while ((neigh = rcu_dereference_protected(*np, 1175 while ((neigh = rcu_dereference_protected(*np,
1181 lockdep_is_held(&ntbl->rwlock))) != NULL) { 1176 lockdep_is_held(&priv->lock))) != NULL) {
1182 rcu_assign_pointer(*np, 1177 rcu_assign_pointer(*np,
1183 rcu_dereference_protected(neigh->hnext, 1178 rcu_dereference_protected(neigh->hnext,
1184 lockdep_is_held(&ntbl->rwlock))); 1179 lockdep_is_held(&priv->lock)));
1185 /* remove from path/mc list */ 1180 /* remove from path/mc list */
1186 spin_lock_irqsave(&priv->lock, flags);
1187 list_del(&neigh->list); 1181 list_del(&neigh->list);
1188 spin_unlock_irqrestore(&priv->lock, flags);
1189 call_rcu(&neigh->rcu, ipoib_neigh_reclaim); 1182 call_rcu(&neigh->rcu, ipoib_neigh_reclaim);
1190 } 1183 }
1191 } 1184 }
1192 1185
1186free_htbl:
1193 rcu_assign_pointer(ntbl->htbl, NULL); 1187 rcu_assign_pointer(ntbl->htbl, NULL);
1194 call_rcu(&htbl->rcu, neigh_hash_free_rcu); 1188 call_rcu(&htbl->rcu, neigh_hash_free_rcu);
1195 1189
1196out_unlock: 1190out_unlock:
1197 write_unlock_bh(&ntbl->rwlock); 1191 spin_unlock_irqrestore(&priv->lock, flags);
1192 if (wait_flushed)
1193 wait_for_completion(&priv->ntbl.flushed);
1198} 1194}
1199 1195
1200static void ipoib_neigh_hash_uninit(struct net_device *dev) 1196static void ipoib_neigh_hash_uninit(struct net_device *dev)
@@ -1203,7 +1199,7 @@ static void ipoib_neigh_hash_uninit(struct net_device *dev)
1203 int stopped; 1199 int stopped;
1204 1200
1205 ipoib_dbg(priv, "ipoib_neigh_hash_uninit\n"); 1201 ipoib_dbg(priv, "ipoib_neigh_hash_uninit\n");
1206 init_completion(&priv->ntbl.flushed); 1202 init_completion(&priv->ntbl.deleted);
1207 set_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags); 1203 set_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags);
1208 1204
1209 /* Stop GC if called at init fail need to cancel work */ 1205 /* Stop GC if called at init fail need to cancel work */
@@ -1211,10 +1207,9 @@ static void ipoib_neigh_hash_uninit(struct net_device *dev)
1211 if (!stopped) 1207 if (!stopped)
1212 cancel_delayed_work(&priv->neigh_reap_task); 1208 cancel_delayed_work(&priv->neigh_reap_task);
1213 1209
1214 if (atomic_read(&priv->ntbl.entries)) { 1210 ipoib_flush_neighs(priv);
1215 ipoib_flush_neighs(priv); 1211
1216 wait_for_completion(&priv->ntbl.flushed); 1212 wait_for_completion(&priv->ntbl.deleted);
1217 }
1218} 1213}
1219 1214
1220 1215
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index 13f4aa7593c8..75367249f447 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -707,9 +707,7 @@ out:
707 neigh = ipoib_neigh_get(dev, daddr); 707 neigh = ipoib_neigh_get(dev, daddr);
708 spin_lock_irqsave(&priv->lock, flags); 708 spin_lock_irqsave(&priv->lock, flags);
709 if (!neigh) { 709 if (!neigh) {
710 spin_unlock_irqrestore(&priv->lock, flags);
711 neigh = ipoib_neigh_alloc(daddr, dev); 710 neigh = ipoib_neigh_alloc(daddr, dev);
712 spin_lock_irqsave(&priv->lock, flags);
713 if (neigh) { 711 if (neigh) {
714 kref_get(&mcast->ah->ref); 712 kref_get(&mcast->ah->ref);
715 neigh->ah = mcast->ah; 713 neigh->ah = mcast->ah;
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 6c58bfff01a3..118d0300f1fb 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -54,16 +54,9 @@ struct evdev_client {
54static struct evdev *evdev_table[EVDEV_MINORS]; 54static struct evdev *evdev_table[EVDEV_MINORS];
55static DEFINE_MUTEX(evdev_table_mutex); 55static DEFINE_MUTEX(evdev_table_mutex);
56 56
57static void evdev_pass_event(struct evdev_client *client, 57static void __pass_event(struct evdev_client *client,
58 struct input_event *event, 58 const struct input_event *event)
59 ktime_t mono, ktime_t real)
60{ 59{
61 event->time = ktime_to_timeval(client->clkid == CLOCK_MONOTONIC ?
62 mono : real);
63
64 /* Interrupts are disabled, just acquire the lock. */
65 spin_lock(&client->buffer_lock);
66
67 client->buffer[client->head++] = *event; 60 client->buffer[client->head++] = *event;
68 client->head &= client->bufsize - 1; 61 client->head &= client->bufsize - 1;
69 62
@@ -86,42 +79,74 @@ static void evdev_pass_event(struct evdev_client *client,
86 client->packet_head = client->head; 79 client->packet_head = client->head;
87 kill_fasync(&client->fasync, SIGIO, POLL_IN); 80 kill_fasync(&client->fasync, SIGIO, POLL_IN);
88 } 81 }
82}
83
84static void evdev_pass_values(struct evdev_client *client,
85 const struct input_value *vals, unsigned int count,
86 ktime_t mono, ktime_t real)
87{
88 struct evdev *evdev = client->evdev;
89 const struct input_value *v;
90 struct input_event event;
91 bool wakeup = false;
92
93 event.time = ktime_to_timeval(client->clkid == CLOCK_MONOTONIC ?
94 mono : real);
95
96 /* Interrupts are disabled, just acquire the lock. */
97 spin_lock(&client->buffer_lock);
98
99 for (v = vals; v != vals + count; v++) {
100 event.type = v->type;
101 event.code = v->code;
102 event.value = v->value;
103 __pass_event(client, &event);
104 if (v->type == EV_SYN && v->code == SYN_REPORT)
105 wakeup = true;
106 }
89 107
90 spin_unlock(&client->buffer_lock); 108 spin_unlock(&client->buffer_lock);
109
110 if (wakeup)
111 wake_up_interruptible(&evdev->wait);
91} 112}
92 113
93/* 114/*
94 * Pass incoming event to all connected clients. 115 * Pass incoming events to all connected clients.
95 */ 116 */
96static void evdev_event(struct input_handle *handle, 117static void evdev_events(struct input_handle *handle,
97 unsigned int type, unsigned int code, int value) 118 const struct input_value *vals, unsigned int count)
98{ 119{
99 struct evdev *evdev = handle->private; 120 struct evdev *evdev = handle->private;
100 struct evdev_client *client; 121 struct evdev_client *client;
101 struct input_event event;
102 ktime_t time_mono, time_real; 122 ktime_t time_mono, time_real;
103 123
104 time_mono = ktime_get(); 124 time_mono = ktime_get();
105 time_real = ktime_sub(time_mono, ktime_get_monotonic_offset()); 125 time_real = ktime_sub(time_mono, ktime_get_monotonic_offset());
106 126
107 event.type = type;
108 event.code = code;
109 event.value = value;
110
111 rcu_read_lock(); 127 rcu_read_lock();
112 128
113 client = rcu_dereference(evdev->grab); 129 client = rcu_dereference(evdev->grab);
114 130
115 if (client) 131 if (client)
116 evdev_pass_event(client, &event, time_mono, time_real); 132 evdev_pass_values(client, vals, count, time_mono, time_real);
117 else 133 else
118 list_for_each_entry_rcu(client, &evdev->client_list, node) 134 list_for_each_entry_rcu(client, &evdev->client_list, node)
119 evdev_pass_event(client, &event, time_mono, time_real); 135 evdev_pass_values(client, vals, count,
136 time_mono, time_real);
120 137
121 rcu_read_unlock(); 138 rcu_read_unlock();
139}
122 140
123 if (type == EV_SYN && code == SYN_REPORT) 141/*
124 wake_up_interruptible(&evdev->wait); 142 * Pass incoming event to all connected clients.
143 */
144static void evdev_event(struct input_handle *handle,
145 unsigned int type, unsigned int code, int value)
146{
147 struct input_value vals[] = { { type, code, value } };
148
149 evdev_events(handle, vals, 1);
125} 150}
126 151
127static int evdev_fasync(int fd, struct file *file, int on) 152static int evdev_fasync(int fd, struct file *file, int on)
@@ -653,20 +678,22 @@ static int evdev_handle_mt_request(struct input_dev *dev,
653 unsigned int size, 678 unsigned int size,
654 int __user *ip) 679 int __user *ip)
655{ 680{
656 const struct input_mt_slot *mt = dev->mt; 681 const struct input_mt *mt = dev->mt;
657 unsigned int code; 682 unsigned int code;
658 int max_slots; 683 int max_slots;
659 int i; 684 int i;
660 685
661 if (get_user(code, &ip[0])) 686 if (get_user(code, &ip[0]))
662 return -EFAULT; 687 return -EFAULT;
663 if (!input_is_mt_value(code)) 688 if (!mt || !input_is_mt_value(code))
664 return -EINVAL; 689 return -EINVAL;
665 690
666 max_slots = (size - sizeof(__u32)) / sizeof(__s32); 691 max_slots = (size - sizeof(__u32)) / sizeof(__s32);
667 for (i = 0; i < dev->mtsize && i < max_slots; i++) 692 for (i = 0; i < mt->num_slots && i < max_slots; i++) {
668 if (put_user(input_mt_get_value(&mt[i], code), &ip[1 + i])) 693 int value = input_mt_get_value(&mt->slots[i], code);
694 if (put_user(value, &ip[1 + i]))
669 return -EFAULT; 695 return -EFAULT;
696 }
670 697
671 return 0; 698 return 0;
672} 699}
@@ -1048,6 +1075,7 @@ MODULE_DEVICE_TABLE(input, evdev_ids);
1048 1075
1049static struct input_handler evdev_handler = { 1076static struct input_handler evdev_handler = {
1050 .event = evdev_event, 1077 .event = evdev_event,
1078 .events = evdev_events,
1051 .connect = evdev_connect, 1079 .connect = evdev_connect,
1052 .disconnect = evdev_disconnect, 1080 .disconnect = evdev_disconnect,
1053 .fops = &evdev_fops, 1081 .fops = &evdev_fops,
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index 70a16c7da8cc..c0ec7d42c3be 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -14,6 +14,14 @@
14 14
15#define TRKID_SGN ((TRKID_MAX + 1) >> 1) 15#define TRKID_SGN ((TRKID_MAX + 1) >> 1)
16 16
17static void copy_abs(struct input_dev *dev, unsigned int dst, unsigned int src)
18{
19 if (dev->absinfo && test_bit(src, dev->absbit)) {
20 dev->absinfo[dst] = dev->absinfo[src];
21 dev->absbit[BIT_WORD(dst)] |= BIT_MASK(dst);
22 }
23}
24
17/** 25/**
18 * input_mt_init_slots() - initialize MT input slots 26 * input_mt_init_slots() - initialize MT input slots
19 * @dev: input device supporting MT events and finger tracking 27 * @dev: input device supporting MT events and finger tracking
@@ -25,29 +33,63 @@
25 * May be called repeatedly. Returns -EINVAL if attempting to 33 * May be called repeatedly. Returns -EINVAL if attempting to
26 * reinitialize with a different number of slots. 34 * reinitialize with a different number of slots.
27 */ 35 */
28int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots) 36int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
37 unsigned int flags)
29{ 38{
39 struct input_mt *mt = dev->mt;
30 int i; 40 int i;
31 41
32 if (!num_slots) 42 if (!num_slots)
33 return 0; 43 return 0;
34 if (dev->mt) 44 if (mt)
35 return dev->mtsize != num_slots ? -EINVAL : 0; 45 return mt->num_slots != num_slots ? -EINVAL : 0;
36 46
37 dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL); 47 mt = kzalloc(sizeof(*mt) + num_slots * sizeof(*mt->slots), GFP_KERNEL);
38 if (!dev->mt) 48 if (!mt)
39 return -ENOMEM; 49 goto err_mem;
40 50
41 dev->mtsize = num_slots; 51 mt->num_slots = num_slots;
52 mt->flags = flags;
42 input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0); 53 input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0);
43 input_set_abs_params(dev, ABS_MT_TRACKING_ID, 0, TRKID_MAX, 0, 0); 54 input_set_abs_params(dev, ABS_MT_TRACKING_ID, 0, TRKID_MAX, 0, 0);
44 input_set_events_per_packet(dev, 6 * num_slots); 55
56 if (flags & (INPUT_MT_POINTER | INPUT_MT_DIRECT)) {
57 __set_bit(EV_KEY, dev->evbit);
58 __set_bit(BTN_TOUCH, dev->keybit);
59
60 copy_abs(dev, ABS_X, ABS_MT_POSITION_X);
61 copy_abs(dev, ABS_Y, ABS_MT_POSITION_Y);
62 copy_abs(dev, ABS_PRESSURE, ABS_MT_PRESSURE);
63 }
64 if (flags & INPUT_MT_POINTER) {
65 __set_bit(BTN_TOOL_FINGER, dev->keybit);
66 __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
67 if (num_slots >= 3)
68 __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
69 if (num_slots >= 4)
70 __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
71 if (num_slots >= 5)
72 __set_bit(BTN_TOOL_QUINTTAP, dev->keybit);
73 __set_bit(INPUT_PROP_POINTER, dev->propbit);
74 }
75 if (flags & INPUT_MT_DIRECT)
76 __set_bit(INPUT_PROP_DIRECT, dev->propbit);
77 if (flags & INPUT_MT_TRACK) {
78 unsigned int n2 = num_slots * num_slots;
79 mt->red = kcalloc(n2, sizeof(*mt->red), GFP_KERNEL);
80 if (!mt->red)
81 goto err_mem;
82 }
45 83
46 /* Mark slots as 'unused' */ 84 /* Mark slots as 'unused' */
47 for (i = 0; i < num_slots; i++) 85 for (i = 0; i < num_slots; i++)
48 input_mt_set_value(&dev->mt[i], ABS_MT_TRACKING_ID, -1); 86 input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1);
49 87
88 dev->mt = mt;
50 return 0; 89 return 0;
90err_mem:
91 kfree(mt);
92 return -ENOMEM;
51} 93}
52EXPORT_SYMBOL(input_mt_init_slots); 94EXPORT_SYMBOL(input_mt_init_slots);
53 95
@@ -60,11 +102,11 @@ EXPORT_SYMBOL(input_mt_init_slots);
60 */ 102 */
61void input_mt_destroy_slots(struct input_dev *dev) 103void input_mt_destroy_slots(struct input_dev *dev)
62{ 104{
63 kfree(dev->mt); 105 if (dev->mt) {
106 kfree(dev->mt->red);
107 kfree(dev->mt);
108 }
64 dev->mt = NULL; 109 dev->mt = NULL;
65 dev->mtsize = 0;
66 dev->slot = 0;
67 dev->trkid = 0;
68} 110}
69EXPORT_SYMBOL(input_mt_destroy_slots); 111EXPORT_SYMBOL(input_mt_destroy_slots);
70 112
@@ -83,18 +125,24 @@ EXPORT_SYMBOL(input_mt_destroy_slots);
83void input_mt_report_slot_state(struct input_dev *dev, 125void input_mt_report_slot_state(struct input_dev *dev,
84 unsigned int tool_type, bool active) 126 unsigned int tool_type, bool active)
85{ 127{
86 struct input_mt_slot *mt; 128 struct input_mt *mt = dev->mt;
129 struct input_mt_slot *slot;
87 int id; 130 int id;
88 131
89 if (!dev->mt || !active) { 132 if (!mt)
133 return;
134
135 slot = &mt->slots[mt->slot];
136 slot->frame = mt->frame;
137
138 if (!active) {
90 input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); 139 input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
91 return; 140 return;
92 } 141 }
93 142
94 mt = &dev->mt[dev->slot]; 143 id = input_mt_get_value(slot, ABS_MT_TRACKING_ID);
95 id = input_mt_get_value(mt, ABS_MT_TRACKING_ID); 144 if (id < 0 || input_mt_get_value(slot, ABS_MT_TOOL_TYPE) != tool_type)
96 if (id < 0 || input_mt_get_value(mt, ABS_MT_TOOL_TYPE) != tool_type) 145 id = input_mt_new_trkid(mt);
97 id = input_mt_new_trkid(dev);
98 146
99 input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, id); 147 input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, id);
100 input_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, tool_type); 148 input_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, tool_type);
@@ -135,13 +183,19 @@ EXPORT_SYMBOL(input_mt_report_finger_count);
135 */ 183 */
136void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count) 184void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count)
137{ 185{
138 struct input_mt_slot *oldest = NULL; 186 struct input_mt *mt = dev->mt;
139 int oldid = dev->trkid; 187 struct input_mt_slot *oldest;
140 int count = 0; 188 int oldid, count, i;
141 int i; 189
190 if (!mt)
191 return;
192
193 oldest = 0;
194 oldid = mt->trkid;
195 count = 0;
142 196
143 for (i = 0; i < dev->mtsize; ++i) { 197 for (i = 0; i < mt->num_slots; ++i) {
144 struct input_mt_slot *ps = &dev->mt[i]; 198 struct input_mt_slot *ps = &mt->slots[i];
145 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID); 199 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
146 200
147 if (id < 0) 201 if (id < 0)
@@ -160,13 +214,208 @@ void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count)
160 if (oldest) { 214 if (oldest) {
161 int x = input_mt_get_value(oldest, ABS_MT_POSITION_X); 215 int x = input_mt_get_value(oldest, ABS_MT_POSITION_X);
162 int y = input_mt_get_value(oldest, ABS_MT_POSITION_Y); 216 int y = input_mt_get_value(oldest, ABS_MT_POSITION_Y);
163 int p = input_mt_get_value(oldest, ABS_MT_PRESSURE);
164 217
165 input_event(dev, EV_ABS, ABS_X, x); 218 input_event(dev, EV_ABS, ABS_X, x);
166 input_event(dev, EV_ABS, ABS_Y, y); 219 input_event(dev, EV_ABS, ABS_Y, y);
167 input_event(dev, EV_ABS, ABS_PRESSURE, p); 220
221 if (test_bit(ABS_MT_PRESSURE, dev->absbit)) {
222 int p = input_mt_get_value(oldest, ABS_MT_PRESSURE);
223 input_event(dev, EV_ABS, ABS_PRESSURE, p);
224 }
168 } else { 225 } else {
169 input_event(dev, EV_ABS, ABS_PRESSURE, 0); 226 if (test_bit(ABS_MT_PRESSURE, dev->absbit))
227 input_event(dev, EV_ABS, ABS_PRESSURE, 0);
170 } 228 }
171} 229}
172EXPORT_SYMBOL(input_mt_report_pointer_emulation); 230EXPORT_SYMBOL(input_mt_report_pointer_emulation);
231
232/**
233 * input_mt_sync_frame() - synchronize mt frame
234 * @dev: input device with allocated MT slots
235 *
236 * Close the frame and prepare the internal state for a new one.
237 * Depending on the flags, marks unused slots as inactive and performs
238 * pointer emulation.
239 */
240void input_mt_sync_frame(struct input_dev *dev)
241{
242 struct input_mt *mt = dev->mt;
243 struct input_mt_slot *s;
244
245 if (!mt)
246 return;
247
248 if (mt->flags & INPUT_MT_DROP_UNUSED) {
249 for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
250 if (s->frame == mt->frame)
251 continue;
252 input_mt_slot(dev, s - mt->slots);
253 input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
254 }
255 }
256
257 input_mt_report_pointer_emulation(dev, (mt->flags & INPUT_MT_POINTER));
258
259 mt->frame++;
260}
261EXPORT_SYMBOL(input_mt_sync_frame);
262
263static int adjust_dual(int *begin, int step, int *end, int eq)
264{
265 int f, *p, s, c;
266
267 if (begin == end)
268 return 0;
269
270 f = *begin;
271 p = begin + step;
272 s = p == end ? f + 1 : *p;
273
274 for (; p != end; p += step)
275 if (*p < f)
276 s = f, f = *p;
277 else if (*p < s)
278 s = *p;
279
280 c = (f + s + 1) / 2;
281 if (c == 0 || (c > 0 && !eq))
282 return 0;
283 if (s < 0)
284 c *= 2;
285
286 for (p = begin; p != end; p += step)
287 *p -= c;
288
289 return (c < s && s <= 0) || (f >= 0 && f < c);
290}
291
292static void find_reduced_matrix(int *w, int nr, int nc, int nrc)
293{
294 int i, k, sum;
295
296 for (k = 0; k < nrc; k++) {
297 for (i = 0; i < nr; i++)
298 adjust_dual(w + i, nr, w + i + nrc, nr <= nc);
299 sum = 0;
300 for (i = 0; i < nrc; i += nr)
301 sum += adjust_dual(w + i, 1, w + i + nr, nc <= nr);
302 if (!sum)
303 break;
304 }
305}
306
307static int input_mt_set_matrix(struct input_mt *mt,
308 const struct input_mt_pos *pos, int num_pos)
309{
310 const struct input_mt_pos *p;
311 struct input_mt_slot *s;
312 int *w = mt->red;
313 int x, y;
314
315 for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
316 if (!input_mt_is_active(s))
317 continue;
318 x = input_mt_get_value(s, ABS_MT_POSITION_X);
319 y = input_mt_get_value(s, ABS_MT_POSITION_Y);
320 for (p = pos; p != pos + num_pos; p++) {
321 int dx = x - p->x, dy = y - p->y;
322 *w++ = dx * dx + dy * dy;
323 }
324 }
325
326 return w - mt->red;
327}
328
329static void input_mt_set_slots(struct input_mt *mt,
330 int *slots, int num_pos)
331{
332 struct input_mt_slot *s;
333 int *w = mt->red, *p;
334
335 for (p = slots; p != slots + num_pos; p++)
336 *p = -1;
337
338 for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
339 if (!input_mt_is_active(s))
340 continue;
341 for (p = slots; p != slots + num_pos; p++)
342 if (*w++ < 0)
343 *p = s - mt->slots;
344 }
345
346 for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
347 if (input_mt_is_active(s))
348 continue;
349 for (p = slots; p != slots + num_pos; p++)
350 if (*p < 0) {
351 *p = s - mt->slots;
352 break;
353 }
354 }
355}
356
357/**
358 * input_mt_assign_slots() - perform a best-match assignment
359 * @dev: input device with allocated MT slots
360 * @slots: the slot assignment to be filled
361 * @pos: the position array to match
362 * @num_pos: number of positions
363 *
364 * Performs a best match against the current contacts and returns
365 * the slot assignment list. New contacts are assigned to unused
366 * slots.
367 *
368 * Returns zero on success, or negative error in case of failure.
369 */
370int input_mt_assign_slots(struct input_dev *dev, int *slots,
371 const struct input_mt_pos *pos, int num_pos)
372{
373 struct input_mt *mt = dev->mt;
374 int nrc;
375
376 if (!mt || !mt->red)
377 return -ENXIO;
378 if (num_pos > mt->num_slots)
379 return -EINVAL;
380 if (num_pos < 1)
381 return 0;
382
383 nrc = input_mt_set_matrix(mt, pos, num_pos);
384 find_reduced_matrix(mt->red, num_pos, nrc / num_pos, nrc);
385 input_mt_set_slots(mt, slots, num_pos);
386
387 return 0;
388}
389EXPORT_SYMBOL(input_mt_assign_slots);
390
391/**
392 * input_mt_get_slot_by_key() - return slot matching key
393 * @dev: input device with allocated MT slots
394 * @key: the key of the sought slot
395 *
396 * Returns the slot of the given key, if it exists, otherwise
397 * set the key on the first unused slot and return.
398 *
399 * If no available slot can be found, -1 is returned.
400 */
401int input_mt_get_slot_by_key(struct input_dev *dev, int key)
402{
403 struct input_mt *mt = dev->mt;
404 struct input_mt_slot *s;
405
406 if (!mt)
407 return -1;
408
409 for (s = mt->slots; s != mt->slots + mt->num_slots; s++)
410 if (input_mt_is_active(s) && s->key == key)
411 return s - mt->slots;
412
413 for (s = mt->slots; s != mt->slots + mt->num_slots; s++)
414 if (!input_mt_is_active(s)) {
415 s->key = key;
416 return s - mt->slots;
417 }
418
419 return -1;
420}
421EXPORT_SYMBOL(input_mt_get_slot_by_key);
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 8921c6180c51..5244f3d05b12 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -47,6 +47,8 @@ static DEFINE_MUTEX(input_mutex);
47 47
48static struct input_handler *input_table[8]; 48static struct input_handler *input_table[8];
49 49
50static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };
51
50static inline int is_event_supported(unsigned int code, 52static inline int is_event_supported(unsigned int code,
51 unsigned long *bm, unsigned int max) 53 unsigned long *bm, unsigned int max)
52{ 54{
@@ -69,42 +71,102 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz)
69 return value; 71 return value;
70} 72}
71 73
74static void input_start_autorepeat(struct input_dev *dev, int code)
75{
76 if (test_bit(EV_REP, dev->evbit) &&
77 dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] &&
78 dev->timer.data) {
79 dev->repeat_key = code;
80 mod_timer(&dev->timer,
81 jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
82 }
83}
84
85static void input_stop_autorepeat(struct input_dev *dev)
86{
87 del_timer(&dev->timer);
88}
89
72/* 90/*
73 * Pass event first through all filters and then, if event has not been 91 * Pass event first through all filters and then, if event has not been
74 * filtered out, through all open handles. This function is called with 92 * filtered out, through all open handles. This function is called with
75 * dev->event_lock held and interrupts disabled. 93 * dev->event_lock held and interrupts disabled.
76 */ 94 */
77static void input_pass_event(struct input_dev *dev, 95static unsigned int input_to_handler(struct input_handle *handle,
78 unsigned int type, unsigned int code, int value) 96 struct input_value *vals, unsigned int count)
97{
98 struct input_handler *handler = handle->handler;
99 struct input_value *end = vals;
100 struct input_value *v;
101
102 for (v = vals; v != vals + count; v++) {
103 if (handler->filter &&
104 handler->filter(handle, v->type, v->code, v->value))
105 continue;
106 if (end != v)
107 *end = *v;
108 end++;
109 }
110
111 count = end - vals;
112 if (!count)
113 return 0;
114
115 if (handler->events)
116 handler->events(handle, vals, count);
117 else if (handler->event)
118 for (v = vals; v != end; v++)
119 handler->event(handle, v->type, v->code, v->value);
120
121 return count;
122}
123
124/*
125 * Pass values first through all filters and then, if event has not been
126 * filtered out, through all open handles. This function is called with
127 * dev->event_lock held and interrupts disabled.
128 */
129static void input_pass_values(struct input_dev *dev,
130 struct input_value *vals, unsigned int count)
79{ 131{
80 struct input_handler *handler;
81 struct input_handle *handle; 132 struct input_handle *handle;
133 struct input_value *v;
134
135 if (!count)
136 return;
82 137
83 rcu_read_lock(); 138 rcu_read_lock();
84 139
85 handle = rcu_dereference(dev->grab); 140 handle = rcu_dereference(dev->grab);
86 if (handle) 141 if (handle) {
87 handle->handler->event(handle, type, code, value); 142 count = input_to_handler(handle, vals, count);
88 else { 143 } else {
89 bool filtered = false; 144 list_for_each_entry_rcu(handle, &dev->h_list, d_node)
90 145 if (handle->open)
91 list_for_each_entry_rcu(handle, &dev->h_list, d_node) { 146 count = input_to_handler(handle, vals, count);
92 if (!handle->open) 147 }
93 continue;
94 148
95 handler = handle->handler; 149 rcu_read_unlock();
96 if (!handler->filter) {
97 if (filtered)
98 break;
99 150
100 handler->event(handle, type, code, value); 151 add_input_randomness(vals->type, vals->code, vals->value);
101 152
102 } else if (handler->filter(handle, type, code, value)) 153 /* trigger auto repeat for key events */
103 filtered = true; 154 for (v = vals; v != vals + count; v++) {
155 if (v->type == EV_KEY && v->value != 2) {
156 if (v->value)
157 input_start_autorepeat(dev, v->code);
158 else
159 input_stop_autorepeat(dev);
104 } 160 }
105 } 161 }
162}
106 163
107 rcu_read_unlock(); 164static void input_pass_event(struct input_dev *dev,
165 unsigned int type, unsigned int code, int value)
166{
167 struct input_value vals[] = { { type, code, value } };
168
169 input_pass_values(dev, vals, ARRAY_SIZE(vals));
108} 170}
109 171
110/* 172/*
@@ -121,18 +183,12 @@ static void input_repeat_key(unsigned long data)
121 183
122 if (test_bit(dev->repeat_key, dev->key) && 184 if (test_bit(dev->repeat_key, dev->key) &&
123 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 185 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
186 struct input_value vals[] = {
187 { EV_KEY, dev->repeat_key, 2 },
188 input_value_sync
189 };
124 190
125 input_pass_event(dev, EV_KEY, dev->repeat_key, 2); 191 input_pass_values(dev, vals, ARRAY_SIZE(vals));
126
127 if (dev->sync) {
128 /*
129 * Only send SYN_REPORT if we are not in a middle
130 * of driver parsing a new hardware packet.
131 * Otherwise assume that the driver will send
132 * SYN_REPORT once it's done.
133 */
134 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
135 }
136 192
137 if (dev->rep[REP_PERIOD]) 193 if (dev->rep[REP_PERIOD])
138 mod_timer(&dev->timer, jiffies + 194 mod_timer(&dev->timer, jiffies +
@@ -142,30 +198,17 @@ static void input_repeat_key(unsigned long data)
142 spin_unlock_irqrestore(&dev->event_lock, flags); 198 spin_unlock_irqrestore(&dev->event_lock, flags);
143} 199}
144 200
145static void input_start_autorepeat(struct input_dev *dev, int code)
146{
147 if (test_bit(EV_REP, dev->evbit) &&
148 dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] &&
149 dev->timer.data) {
150 dev->repeat_key = code;
151 mod_timer(&dev->timer,
152 jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
153 }
154}
155
156static void input_stop_autorepeat(struct input_dev *dev)
157{
158 del_timer(&dev->timer);
159}
160
161#define INPUT_IGNORE_EVENT 0 201#define INPUT_IGNORE_EVENT 0
162#define INPUT_PASS_TO_HANDLERS 1 202#define INPUT_PASS_TO_HANDLERS 1
163#define INPUT_PASS_TO_DEVICE 2 203#define INPUT_PASS_TO_DEVICE 2
204#define INPUT_SLOT 4
205#define INPUT_FLUSH 8
164#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 206#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
165 207
166static int input_handle_abs_event(struct input_dev *dev, 208static int input_handle_abs_event(struct input_dev *dev,
167 unsigned int code, int *pval) 209 unsigned int code, int *pval)
168{ 210{
211 struct input_mt *mt = dev->mt;
169 bool is_mt_event; 212 bool is_mt_event;
170 int *pold; 213 int *pold;
171 214
@@ -174,8 +217,8 @@ static int input_handle_abs_event(struct input_dev *dev,
174 * "Stage" the event; we'll flush it later, when we 217 * "Stage" the event; we'll flush it later, when we
175 * get actual touch data. 218 * get actual touch data.
176 */ 219 */
177 if (*pval >= 0 && *pval < dev->mtsize) 220 if (mt && *pval >= 0 && *pval < mt->num_slots)
178 dev->slot = *pval; 221 mt->slot = *pval;
179 222
180 return INPUT_IGNORE_EVENT; 223 return INPUT_IGNORE_EVENT;
181 } 224 }
@@ -184,9 +227,8 @@ static int input_handle_abs_event(struct input_dev *dev,
184 227
185 if (!is_mt_event) { 228 if (!is_mt_event) {
186 pold = &dev->absinfo[code].value; 229 pold = &dev->absinfo[code].value;
187 } else if (dev->mt) { 230 } else if (mt) {
188 struct input_mt_slot *mtslot = &dev->mt[dev->slot]; 231 pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST];
189 pold = &mtslot->abs[code - ABS_MT_FIRST];
190 } else { 232 } else {
191 /* 233 /*
192 * Bypass filtering for multi-touch events when 234 * Bypass filtering for multi-touch events when
@@ -205,16 +247,16 @@ static int input_handle_abs_event(struct input_dev *dev,
205 } 247 }
206 248
207 /* Flush pending "slot" event */ 249 /* Flush pending "slot" event */
208 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { 250 if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
209 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot); 251 input_abs_set_val(dev, ABS_MT_SLOT, mt->slot);
210 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot); 252 return INPUT_PASS_TO_HANDLERS | INPUT_SLOT;
211 } 253 }
212 254
213 return INPUT_PASS_TO_HANDLERS; 255 return INPUT_PASS_TO_HANDLERS;
214} 256}
215 257
216static void input_handle_event(struct input_dev *dev, 258static int input_get_disposition(struct input_dev *dev,
217 unsigned int type, unsigned int code, int value) 259 unsigned int type, unsigned int code, int value)
218{ 260{
219 int disposition = INPUT_IGNORE_EVENT; 261 int disposition = INPUT_IGNORE_EVENT;
220 262
@@ -227,37 +269,34 @@ static void input_handle_event(struct input_dev *dev,
227 break; 269 break;
228 270
229 case SYN_REPORT: 271 case SYN_REPORT:
230 if (!dev->sync) { 272 disposition = INPUT_PASS_TO_HANDLERS | INPUT_FLUSH;
231 dev->sync = true;
232 disposition = INPUT_PASS_TO_HANDLERS;
233 }
234 break; 273 break;
235 case SYN_MT_REPORT: 274 case SYN_MT_REPORT:
236 dev->sync = false;
237 disposition = INPUT_PASS_TO_HANDLERS; 275 disposition = INPUT_PASS_TO_HANDLERS;
238 break; 276 break;
239 } 277 }
240 break; 278 break;
241 279
242 case EV_KEY: 280 case EV_KEY:
243 if (is_event_supported(code, dev->keybit, KEY_MAX) && 281 if (is_event_supported(code, dev->keybit, KEY_MAX)) {
244 !!test_bit(code, dev->key) != value) {
245 282
246 if (value != 2) { 283 /* auto-repeat bypasses state updates */
247 __change_bit(code, dev->key); 284 if (value == 2) {
248 if (value) 285 disposition = INPUT_PASS_TO_HANDLERS;
249 input_start_autorepeat(dev, code); 286 break;
250 else
251 input_stop_autorepeat(dev);
252 } 287 }
253 288
254 disposition = INPUT_PASS_TO_HANDLERS; 289 if (!!test_bit(code, dev->key) != !!value) {
290
291 __change_bit(code, dev->key);
292 disposition = INPUT_PASS_TO_HANDLERS;
293 }
255 } 294 }
256 break; 295 break;
257 296
258 case EV_SW: 297 case EV_SW:
259 if (is_event_supported(code, dev->swbit, SW_MAX) && 298 if (is_event_supported(code, dev->swbit, SW_MAX) &&
260 !!test_bit(code, dev->sw) != value) { 299 !!test_bit(code, dev->sw) != !!value) {
261 300
262 __change_bit(code, dev->sw); 301 __change_bit(code, dev->sw);
263 disposition = INPUT_PASS_TO_HANDLERS; 302 disposition = INPUT_PASS_TO_HANDLERS;
@@ -284,7 +323,7 @@ static void input_handle_event(struct input_dev *dev,
284 323
285 case EV_LED: 324 case EV_LED:
286 if (is_event_supported(code, dev->ledbit, LED_MAX) && 325 if (is_event_supported(code, dev->ledbit, LED_MAX) &&
287 !!test_bit(code, dev->led) != value) { 326 !!test_bit(code, dev->led) != !!value) {
288 327
289 __change_bit(code, dev->led); 328 __change_bit(code, dev->led);
290 disposition = INPUT_PASS_TO_ALL; 329 disposition = INPUT_PASS_TO_ALL;
@@ -317,14 +356,48 @@ static void input_handle_event(struct input_dev *dev,
317 break; 356 break;
318 } 357 }
319 358
320 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) 359 return disposition;
321 dev->sync = false; 360}
361
362static void input_handle_event(struct input_dev *dev,
363 unsigned int type, unsigned int code, int value)
364{
365 int disposition;
366
367 disposition = input_get_disposition(dev, type, code, value);
322 368
323 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 369 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
324 dev->event(dev, type, code, value); 370 dev->event(dev, type, code, value);
325 371
326 if (disposition & INPUT_PASS_TO_HANDLERS) 372 if (!dev->vals)
327 input_pass_event(dev, type, code, value); 373 return;
374
375 if (disposition & INPUT_PASS_TO_HANDLERS) {
376 struct input_value *v;
377
378 if (disposition & INPUT_SLOT) {
379 v = &dev->vals[dev->num_vals++];
380 v->type = EV_ABS;
381 v->code = ABS_MT_SLOT;
382 v->value = dev->mt->slot;
383 }
384
385 v = &dev->vals[dev->num_vals++];
386 v->type = type;
387 v->code = code;
388 v->value = value;
389 }
390
391 if (disposition & INPUT_FLUSH) {
392 if (dev->num_vals >= 2)
393 input_pass_values(dev, dev->vals, dev->num_vals);
394 dev->num_vals = 0;
395 } else if (dev->num_vals >= dev->max_vals - 2) {
396 dev->vals[dev->num_vals++] = input_value_sync;
397 input_pass_values(dev, dev->vals, dev->num_vals);
398 dev->num_vals = 0;
399 }
400
328} 401}
329 402
330/** 403/**
@@ -352,7 +425,6 @@ void input_event(struct input_dev *dev,
352 if (is_event_supported(type, dev->evbit, EV_MAX)) { 425 if (is_event_supported(type, dev->evbit, EV_MAX)) {
353 426
354 spin_lock_irqsave(&dev->event_lock, flags); 427 spin_lock_irqsave(&dev->event_lock, flags);
355 add_input_randomness(type, code, value);
356 input_handle_event(dev, type, code, value); 428 input_handle_event(dev, type, code, value);
357 spin_unlock_irqrestore(&dev->event_lock, flags); 429 spin_unlock_irqrestore(&dev->event_lock, flags);
358 } 430 }
@@ -831,10 +903,12 @@ int input_set_keycode(struct input_dev *dev,
831 if (test_bit(EV_KEY, dev->evbit) && 903 if (test_bit(EV_KEY, dev->evbit) &&
832 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && 904 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
833 __test_and_clear_bit(old_keycode, dev->key)) { 905 __test_and_clear_bit(old_keycode, dev->key)) {
906 struct input_value vals[] = {
907 { EV_KEY, old_keycode, 0 },
908 input_value_sync
909 };
834 910
835 input_pass_event(dev, EV_KEY, old_keycode, 0); 911 input_pass_values(dev, vals, ARRAY_SIZE(vals));
836 if (dev->sync)
837 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
838 } 912 }
839 913
840 out: 914 out:
@@ -1416,6 +1490,7 @@ static void input_dev_release(struct device *device)
1416 input_ff_destroy(dev); 1490 input_ff_destroy(dev);
1417 input_mt_destroy_slots(dev); 1491 input_mt_destroy_slots(dev);
1418 kfree(dev->absinfo); 1492 kfree(dev->absinfo);
1493 kfree(dev->vals);
1419 kfree(dev); 1494 kfree(dev);
1420 1495
1421 module_put(THIS_MODULE); 1496 module_put(THIS_MODULE);
@@ -1751,8 +1826,8 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev)
1751 int i; 1826 int i;
1752 unsigned int events; 1827 unsigned int events;
1753 1828
1754 if (dev->mtsize) { 1829 if (dev->mt) {
1755 mt_slots = dev->mtsize; 1830 mt_slots = dev->mt->num_slots;
1756 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { 1831 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) {
1757 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - 1832 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum -
1758 dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1, 1833 dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1,
@@ -1778,6 +1853,9 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev)
1778 if (test_bit(i, dev->relbit)) 1853 if (test_bit(i, dev->relbit))
1779 events++; 1854 events++;
1780 1855
1856 /* Make room for KEY and MSC events */
1857 events += 7;
1858
1781 return events; 1859 return events;
1782} 1860}
1783 1861
@@ -1816,6 +1894,7 @@ int input_register_device(struct input_dev *dev)
1816{ 1894{
1817 static atomic_t input_no = ATOMIC_INIT(0); 1895 static atomic_t input_no = ATOMIC_INIT(0);
1818 struct input_handler *handler; 1896 struct input_handler *handler;
1897 unsigned int packet_size;
1819 const char *path; 1898 const char *path;
1820 int error; 1899 int error;
1821 1900
@@ -1828,9 +1907,14 @@ int input_register_device(struct input_dev *dev)
1828 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ 1907 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */
1829 input_cleanse_bitmasks(dev); 1908 input_cleanse_bitmasks(dev);
1830 1909
1831 if (!dev->hint_events_per_packet) 1910 packet_size = input_estimate_events_per_packet(dev);
1832 dev->hint_events_per_packet = 1911 if (dev->hint_events_per_packet < packet_size)
1833 input_estimate_events_per_packet(dev); 1912 dev->hint_events_per_packet = packet_size;
1913
1914 dev->max_vals = max(dev->hint_events_per_packet, packet_size) + 2;
1915 dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL);
1916 if (!dev->vals)
1917 return -ENOMEM;
1834 1918
1835 /* 1919 /*
1836 * If delay and period are pre-set by the driver, then autorepeating 1920 * If delay and period are pre-set by the driver, then autorepeating
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index ce68e361558c..cdc252612c0b 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -516,9 +516,9 @@ static int __devinit imx_keypad_probe(struct platform_device *pdev)
516 input_set_drvdata(input_dev, keypad); 516 input_set_drvdata(input_dev, keypad);
517 517
518 /* Ensure that the keypad will stay dormant until opened */ 518 /* Ensure that the keypad will stay dormant until opened */
519 clk_enable(keypad->clk); 519 clk_prepare_enable(keypad->clk);
520 imx_keypad_inhibit(keypad); 520 imx_keypad_inhibit(keypad);
521 clk_disable(keypad->clk); 521 clk_disable_unprepare(keypad->clk);
522 522
523 error = request_irq(irq, imx_keypad_irq_handler, 0, 523 error = request_irq(irq, imx_keypad_irq_handler, 0,
524 pdev->name, keypad); 524 pdev->name, keypad);
diff --git a/drivers/input/misc/ab8500-ponkey.c b/drivers/input/misc/ab8500-ponkey.c
index f06231b7cab1..84ec691c05aa 100644
--- a/drivers/input/misc/ab8500-ponkey.c
+++ b/drivers/input/misc/ab8500-ponkey.c
@@ -74,8 +74,8 @@ static int __devinit ab8500_ponkey_probe(struct platform_device *pdev)
74 74
75 ponkey->idev = input; 75 ponkey->idev = input;
76 ponkey->ab8500 = ab8500; 76 ponkey->ab8500 = ab8500;
77 ponkey->irq_dbf = ab8500_irq_get_virq(ab8500, irq_dbf); 77 ponkey->irq_dbf = irq_dbf;
78 ponkey->irq_dbr = ab8500_irq_get_virq(ab8500, irq_dbr); 78 ponkey->irq_dbr = irq_dbr;
79 79
80 input->name = "AB8500 POn(PowerOn) Key"; 80 input->name = "AB8500 POn(PowerOn) Key";
81 input->dev.parent = &pdev->dev; 81 input->dev.parent = &pdev->dev;
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 736056897e50..6b1797503e34 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -405,7 +405,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
405 goto exit; 405 goto exit;
406 if (test_bit(ABS_MT_SLOT, dev->absbit)) { 406 if (test_bit(ABS_MT_SLOT, dev->absbit)) {
407 int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1; 407 int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
408 input_mt_init_slots(dev, nslot); 408 input_mt_init_slots(dev, nslot, 0);
409 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { 409 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
410 input_set_events_per_packet(dev, 60); 410 input_set_events_per_packet(dev, 60);
411 } 411 }
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 4a1347e91bdc..cf5af1f495ec 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -1620,7 +1620,7 @@ int alps_init(struct psmouse *psmouse)
1620 case ALPS_PROTO_V3: 1620 case ALPS_PROTO_V3:
1621 case ALPS_PROTO_V4: 1621 case ALPS_PROTO_V4:
1622 set_bit(INPUT_PROP_SEMI_MT, dev1->propbit); 1622 set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
1623 input_mt_init_slots(dev1, 2); 1623 input_mt_init_slots(dev1, 2, 0);
1624 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0); 1624 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0);
1625 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0); 1625 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0);
1626 1626
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index d528c23e194f..3a78f235fa3e 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -40,6 +40,7 @@
40#include <linux/usb/input.h> 40#include <linux/usb/input.h>
41#include <linux/hid.h> 41#include <linux/hid.h>
42#include <linux/mutex.h> 42#include <linux/mutex.h>
43#include <linux/input/mt.h>
43 44
44#define USB_VENDOR_ID_APPLE 0x05ac 45#define USB_VENDOR_ID_APPLE 0x05ac
45 46
@@ -183,26 +184,26 @@ struct tp_finger {
183 __le16 abs_y; /* absolute y coodinate */ 184 __le16 abs_y; /* absolute y coodinate */
184 __le16 rel_x; /* relative x coodinate */ 185 __le16 rel_x; /* relative x coodinate */
185 __le16 rel_y; /* relative y coodinate */ 186 __le16 rel_y; /* relative y coodinate */
186 __le16 size_major; /* finger size, major axis? */ 187 __le16 tool_major; /* tool area, major axis */
187 __le16 size_minor; /* finger size, minor axis? */ 188 __le16 tool_minor; /* tool area, minor axis */
188 __le16 orientation; /* 16384 when point, else 15 bit angle */ 189 __le16 orientation; /* 16384 when point, else 15 bit angle */
189 __le16 force_major; /* trackpad force, major axis? */ 190 __le16 touch_major; /* touch area, major axis */
190 __le16 force_minor; /* trackpad force, minor axis? */ 191 __le16 touch_minor; /* touch area, minor axis */
191 __le16 unused[3]; /* zeros */ 192 __le16 unused[3]; /* zeros */
192 __le16 multi; /* one finger: varies, more fingers: constant */ 193 __le16 multi; /* one finger: varies, more fingers: constant */
193} __attribute__((packed,aligned(2))); 194} __attribute__((packed,aligned(2)));
194 195
195/* trackpad finger data size, empirically at least ten fingers */ 196/* trackpad finger data size, empirically at least ten fingers */
197#define MAX_FINGERS 16
196#define SIZEOF_FINGER sizeof(struct tp_finger) 198#define SIZEOF_FINGER sizeof(struct tp_finger)
197#define SIZEOF_ALL_FINGERS (16 * SIZEOF_FINGER) 199#define SIZEOF_ALL_FINGERS (MAX_FINGERS * SIZEOF_FINGER)
198#define MAX_FINGER_ORIENTATION 16384 200#define MAX_FINGER_ORIENTATION 16384
199 201
200/* device-specific parameters */ 202/* device-specific parameters */
201struct bcm5974_param { 203struct bcm5974_param {
202 int dim; /* logical dimension */ 204 int snratio; /* signal-to-noise ratio */
203 int fuzz; /* logical noise value */ 205 int min; /* device minimum reading */
204 int devmin; /* device minimum reading */ 206 int max; /* device maximum reading */
205 int devmax; /* device maximum reading */
206}; 207};
207 208
208/* device-specific configuration */ 209/* device-specific configuration */
@@ -219,6 +220,7 @@ struct bcm5974_config {
219 struct bcm5974_param w; /* finger width limits */ 220 struct bcm5974_param w; /* finger width limits */
220 struct bcm5974_param x; /* horizontal limits */ 221 struct bcm5974_param x; /* horizontal limits */
221 struct bcm5974_param y; /* vertical limits */ 222 struct bcm5974_param y; /* vertical limits */
223 struct bcm5974_param o; /* orientation limits */
222}; 224};
223 225
224/* logical device structure */ 226/* logical device structure */
@@ -234,23 +236,16 @@ struct bcm5974 {
234 struct bt_data *bt_data; /* button transferred data */ 236 struct bt_data *bt_data; /* button transferred data */
235 struct urb *tp_urb; /* trackpad usb request block */ 237 struct urb *tp_urb; /* trackpad usb request block */
236 u8 *tp_data; /* trackpad transferred data */ 238 u8 *tp_data; /* trackpad transferred data */
237 int fingers; /* number of fingers on trackpad */ 239 const struct tp_finger *index[MAX_FINGERS]; /* finger index data */
240 struct input_mt_pos pos[MAX_FINGERS]; /* position array */
241 int slots[MAX_FINGERS]; /* slot assignments */
238}; 242};
239 243
240/* logical dimensions */
241#define DIM_PRESSURE 256 /* maximum finger pressure */
242#define DIM_WIDTH 16 /* maximum finger width */
243#define DIM_X 1280 /* maximum trackpad x value */
244#define DIM_Y 800 /* maximum trackpad y value */
245
246/* logical signal quality */ 244/* logical signal quality */
247#define SN_PRESSURE 45 /* pressure signal-to-noise ratio */ 245#define SN_PRESSURE 45 /* pressure signal-to-noise ratio */
248#define SN_WIDTH 100 /* width signal-to-noise ratio */ 246#define SN_WIDTH 25 /* width signal-to-noise ratio */
249#define SN_COORD 250 /* coordinate signal-to-noise ratio */ 247#define SN_COORD 250 /* coordinate signal-to-noise ratio */
250 248#define SN_ORIENT 10 /* orientation signal-to-noise ratio */
251/* pressure thresholds */
252#define PRESSURE_LOW (2 * DIM_PRESSURE / SN_PRESSURE)
253#define PRESSURE_HIGH (3 * PRESSURE_LOW)
254 249
255/* device constants */ 250/* device constants */
256static const struct bcm5974_config bcm5974_config_table[] = { 251static const struct bcm5974_config bcm5974_config_table[] = {
@@ -261,10 +256,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
261 0, 256 0,
262 0x84, sizeof(struct bt_data), 257 0x84, sizeof(struct bt_data),
263 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS, 258 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS,
264 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 256 }, 259 { SN_PRESSURE, 0, 256 },
265 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 260 { SN_WIDTH, 0, 2048 },
266 { DIM_X, DIM_X / SN_COORD, -4824, 5342 }, 261 { SN_COORD, -4824, 5342 },
267 { DIM_Y, DIM_Y / SN_COORD, -172, 5820 } 262 { SN_COORD, -172, 5820 },
263 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
268 }, 264 },
269 { 265 {
270 USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI, 266 USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI,
@@ -273,10 +269,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
273 0, 269 0,
274 0x84, sizeof(struct bt_data), 270 0x84, sizeof(struct bt_data),
275 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS, 271 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS,
276 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 256 }, 272 { SN_PRESSURE, 0, 256 },
277 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 273 { SN_WIDTH, 0, 2048 },
278 { DIM_X, DIM_X / SN_COORD, -4824, 4824 }, 274 { SN_COORD, -4824, 4824 },
279 { DIM_Y, DIM_Y / SN_COORD, -172, 4290 } 275 { SN_COORD, -172, 4290 },
276 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
280 }, 277 },
281 { 278 {
282 USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI, 279 USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI,
@@ -285,10 +282,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
285 HAS_INTEGRATED_BUTTON, 282 HAS_INTEGRATED_BUTTON,
286 0x84, sizeof(struct bt_data), 283 0x84, sizeof(struct bt_data),
287 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 284 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
288 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 285 { SN_PRESSURE, 0, 300 },
289 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 286 { SN_WIDTH, 0, 2048 },
290 { DIM_X, DIM_X / SN_COORD, -4460, 5166 }, 287 { SN_COORD, -4460, 5166 },
291 { DIM_Y, DIM_Y / SN_COORD, -75, 6700 } 288 { SN_COORD, -75, 6700 },
289 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
292 }, 290 },
293 { 291 {
294 USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI, 292 USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI,
@@ -297,10 +295,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
297 HAS_INTEGRATED_BUTTON, 295 HAS_INTEGRATED_BUTTON,
298 0x84, sizeof(struct bt_data), 296 0x84, sizeof(struct bt_data),
299 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 297 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
300 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 298 { SN_PRESSURE, 0, 300 },
301 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 299 { SN_WIDTH, 0, 2048 },
302 { DIM_X, DIM_X / SN_COORD, -4620, 5140 }, 300 { SN_COORD, -4620, 5140 },
303 { DIM_Y, DIM_Y / SN_COORD, -150, 6600 } 301 { SN_COORD, -150, 6600 },
302 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
304 }, 303 },
305 { 304 {
306 USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI, 305 USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI,
@@ -309,10 +308,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
309 HAS_INTEGRATED_BUTTON, 308 HAS_INTEGRATED_BUTTON,
310 0x84, sizeof(struct bt_data), 309 0x84, sizeof(struct bt_data),
311 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 310 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
312 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 311 { SN_PRESSURE, 0, 300 },
313 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 312 { SN_WIDTH, 0, 2048 },
314 { DIM_X, DIM_X / SN_COORD, -4616, 5112 }, 313 { SN_COORD, -4616, 5112 },
315 { DIM_Y, DIM_Y / SN_COORD, -142, 5234 } 314 { SN_COORD, -142, 5234 },
315 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
316 }, 316 },
317 { 317 {
318 USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI, 318 USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI,
@@ -321,10 +321,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
321 HAS_INTEGRATED_BUTTON, 321 HAS_INTEGRATED_BUTTON,
322 0x84, sizeof(struct bt_data), 322 0x84, sizeof(struct bt_data),
323 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 323 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
324 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 324 { SN_PRESSURE, 0, 300 },
325 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 325 { SN_WIDTH, 0, 2048 },
326 { DIM_X, DIM_X / SN_COORD, -4415, 5050 }, 326 { SN_COORD, -4415, 5050 },
327 { DIM_Y, DIM_Y / SN_COORD, -55, 6680 } 327 { SN_COORD, -55, 6680 },
328 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
328 }, 329 },
329 { 330 {
330 USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI, 331 USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI,
@@ -333,10 +334,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
333 HAS_INTEGRATED_BUTTON, 334 HAS_INTEGRATED_BUTTON,
334 0x84, sizeof(struct bt_data), 335 0x84, sizeof(struct bt_data),
335 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 336 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
336 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 337 { SN_PRESSURE, 0, 300 },
337 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 338 { SN_WIDTH, 0, 2048 },
338 { DIM_X, DIM_X / SN_COORD, -4620, 5140 }, 339 { SN_COORD, -4620, 5140 },
339 { DIM_Y, DIM_Y / SN_COORD, -150, 6600 } 340 { SN_COORD, -150, 6600 },
341 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
340 }, 342 },
341 { 343 {
342 USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI, 344 USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI,
@@ -345,10 +347,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
345 HAS_INTEGRATED_BUTTON, 347 HAS_INTEGRATED_BUTTON,
346 0x84, sizeof(struct bt_data), 348 0x84, sizeof(struct bt_data),
347 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 349 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
348 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 350 { SN_PRESSURE, 0, 300 },
349 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 351 { SN_WIDTH, 0, 2048 },
350 { DIM_X, DIM_X / SN_COORD, -4750, 5280 }, 352 { SN_COORD, -4750, 5280 },
351 { DIM_Y, DIM_Y / SN_COORD, -150, 6730 } 353 { SN_COORD, -150, 6730 },
354 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
352 }, 355 },
353 { 356 {
354 USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI, 357 USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI,
@@ -357,10 +360,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
357 HAS_INTEGRATED_BUTTON, 360 HAS_INTEGRATED_BUTTON,
358 0x84, sizeof(struct bt_data), 361 0x84, sizeof(struct bt_data),
359 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 362 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
360 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 363 { SN_PRESSURE, 0, 300 },
361 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 364 { SN_WIDTH, 0, 2048 },
362 { DIM_X, DIM_X / SN_COORD, -4620, 5140 }, 365 { SN_COORD, -4620, 5140 },
363 { DIM_Y, DIM_Y / SN_COORD, -150, 6600 } 366 { SN_COORD, -150, 6600 },
367 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
364 }, 368 },
365 { 369 {
366 USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI, 370 USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI,
@@ -369,10 +373,11 @@ static const struct bcm5974_config bcm5974_config_table[] = {
369 HAS_INTEGRATED_BUTTON, 373 HAS_INTEGRATED_BUTTON,
370 0x84, sizeof(struct bt_data), 374 0x84, sizeof(struct bt_data),
371 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, 375 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
372 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 }, 376 { SN_PRESSURE, 0, 300 },
373 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 }, 377 { SN_WIDTH, 0, 2048 },
374 { DIM_X, DIM_X / SN_COORD, -4750, 5280 }, 378 { SN_COORD, -4750, 5280 },
375 { DIM_Y, DIM_Y / SN_COORD, -150, 6730 } 379 { SN_COORD, -150, 6730 },
380 { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
376 }, 381 },
377 {} 382 {}
378}; 383};
@@ -396,18 +401,11 @@ static inline int raw2int(__le16 x)
396 return (signed short)le16_to_cpu(x); 401 return (signed short)le16_to_cpu(x);
397} 402}
398 403
399/* scale device data to logical dimensions (asserts devmin < devmax) */ 404static void set_abs(struct input_dev *input, unsigned int code,
400static inline int int2scale(const struct bcm5974_param *p, int x) 405 const struct bcm5974_param *p)
401{
402 return x * p->dim / (p->devmax - p->devmin);
403}
404
405/* all logical value ranges are [0,dim). */
406static inline int int2bound(const struct bcm5974_param *p, int x)
407{ 406{
408 int s = int2scale(p, x); 407 int fuzz = p->snratio ? (p->max - p->min) / p->snratio : 0;
409 408 input_set_abs_params(input, code, p->min, p->max, fuzz, 0);
410 return clamp_val(s, 0, p->dim - 1);
411} 409}
412 410
413/* setup which logical events to report */ 411/* setup which logical events to report */
@@ -416,48 +414,30 @@ static void setup_events_to_report(struct input_dev *input_dev,
416{ 414{
417 __set_bit(EV_ABS, input_dev->evbit); 415 __set_bit(EV_ABS, input_dev->evbit);
418 416
419 input_set_abs_params(input_dev, ABS_PRESSURE, 417 /* for synaptics only */
420 0, cfg->p.dim, cfg->p.fuzz, 0); 418 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 256, 5, 0);
421 input_set_abs_params(input_dev, ABS_TOOL_WIDTH, 419 input_set_abs_params(input_dev, ABS_TOOL_WIDTH, 0, 16, 0, 0);
422 0, cfg->w.dim, cfg->w.fuzz, 0);
423 input_set_abs_params(input_dev, ABS_X,
424 0, cfg->x.dim, cfg->x.fuzz, 0);
425 input_set_abs_params(input_dev, ABS_Y,
426 0, cfg->y.dim, cfg->y.fuzz, 0);
427 420
428 /* finger touch area */ 421 /* finger touch area */
429 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 422 set_abs(input_dev, ABS_MT_TOUCH_MAJOR, &cfg->w);
430 cfg->w.devmin, cfg->w.devmax, 0, 0); 423 set_abs(input_dev, ABS_MT_TOUCH_MINOR, &cfg->w);
431 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
432 cfg->w.devmin, cfg->w.devmax, 0, 0);
433 /* finger approach area */ 424 /* finger approach area */
434 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 425 set_abs(input_dev, ABS_MT_WIDTH_MAJOR, &cfg->w);
435 cfg->w.devmin, cfg->w.devmax, 0, 0); 426 set_abs(input_dev, ABS_MT_WIDTH_MINOR, &cfg->w);
436 input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR,
437 cfg->w.devmin, cfg->w.devmax, 0, 0);
438 /* finger orientation */ 427 /* finger orientation */
439 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 428 set_abs(input_dev, ABS_MT_ORIENTATION, &cfg->o);
440 -MAX_FINGER_ORIENTATION,
441 MAX_FINGER_ORIENTATION, 0, 0);
442 /* finger position */ 429 /* finger position */
443 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 430 set_abs(input_dev, ABS_MT_POSITION_X, &cfg->x);
444 cfg->x.devmin, cfg->x.devmax, 0, 0); 431 set_abs(input_dev, ABS_MT_POSITION_Y, &cfg->y);
445 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
446 cfg->y.devmin, cfg->y.devmax, 0, 0);
447 432
448 __set_bit(EV_KEY, input_dev->evbit); 433 __set_bit(EV_KEY, input_dev->evbit);
449 __set_bit(BTN_TOUCH, input_dev->keybit);
450 __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
451 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
452 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
453 __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit);
454 __set_bit(BTN_LEFT, input_dev->keybit); 434 __set_bit(BTN_LEFT, input_dev->keybit);
455 435
456 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
457 if (cfg->caps & HAS_INTEGRATED_BUTTON) 436 if (cfg->caps & HAS_INTEGRATED_BUTTON)
458 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); 437 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
459 438
460 input_set_events_per_packet(input_dev, 60); 439 input_mt_init_slots(input_dev, MAX_FINGERS,
440 INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED | INPUT_MT_TRACK);
461} 441}
462 442
463/* report button data as logical button state */ 443/* report button data as logical button state */
@@ -477,24 +457,44 @@ static int report_bt_state(struct bcm5974 *dev, int size)
477 return 0; 457 return 0;
478} 458}
479 459
480static void report_finger_data(struct input_dev *input, 460static void report_finger_data(struct input_dev *input, int slot,
481 const struct bcm5974_config *cfg, 461 const struct input_mt_pos *pos,
482 const struct tp_finger *f) 462 const struct tp_finger *f)
483{ 463{
464 input_mt_slot(input, slot);
465 input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
466
484 input_report_abs(input, ABS_MT_TOUCH_MAJOR, 467 input_report_abs(input, ABS_MT_TOUCH_MAJOR,
485 raw2int(f->force_major) << 1); 468 raw2int(f->touch_major) << 1);
486 input_report_abs(input, ABS_MT_TOUCH_MINOR, 469 input_report_abs(input, ABS_MT_TOUCH_MINOR,
487 raw2int(f->force_minor) << 1); 470 raw2int(f->touch_minor) << 1);
488 input_report_abs(input, ABS_MT_WIDTH_MAJOR, 471 input_report_abs(input, ABS_MT_WIDTH_MAJOR,
489 raw2int(f->size_major) << 1); 472 raw2int(f->tool_major) << 1);
490 input_report_abs(input, ABS_MT_WIDTH_MINOR, 473 input_report_abs(input, ABS_MT_WIDTH_MINOR,
491 raw2int(f->size_minor) << 1); 474 raw2int(f->tool_minor) << 1);
492 input_report_abs(input, ABS_MT_ORIENTATION, 475 input_report_abs(input, ABS_MT_ORIENTATION,
493 MAX_FINGER_ORIENTATION - raw2int(f->orientation)); 476 MAX_FINGER_ORIENTATION - raw2int(f->orientation));
494 input_report_abs(input, ABS_MT_POSITION_X, raw2int(f->abs_x)); 477 input_report_abs(input, ABS_MT_POSITION_X, pos->x);
495 input_report_abs(input, ABS_MT_POSITION_Y, 478 input_report_abs(input, ABS_MT_POSITION_Y, pos->y);
496 cfg->y.devmin + cfg->y.devmax - raw2int(f->abs_y)); 479}
497 input_mt_sync(input); 480
481static void report_synaptics_data(struct input_dev *input,
482 const struct bcm5974_config *cfg,
483 const struct tp_finger *f, int raw_n)
484{
485 int abs_p = 0, abs_w = 0;
486
487 if (raw_n) {
488 int p = raw2int(f->touch_major);
489 int w = raw2int(f->tool_major);
490 if (p > 0 && raw2int(f->origin)) {
491 abs_p = clamp_val(256 * p / cfg->p.max, 0, 255);
492 abs_w = clamp_val(16 * w / cfg->w.max, 0, 15);
493 }
494 }
495
496 input_report_abs(input, ABS_PRESSURE, abs_p);
497 input_report_abs(input, ABS_TOOL_WIDTH, abs_w);
498} 498}
499 499
500/* report trackpad data as logical trackpad state */ 500/* report trackpad data as logical trackpad state */
@@ -503,9 +503,7 @@ static int report_tp_state(struct bcm5974 *dev, int size)
503 const struct bcm5974_config *c = &dev->cfg; 503 const struct bcm5974_config *c = &dev->cfg;
504 const struct tp_finger *f; 504 const struct tp_finger *f;
505 struct input_dev *input = dev->input; 505 struct input_dev *input = dev->input;
506 int raw_p, raw_w, raw_x, raw_y, raw_n, i; 506 int raw_n, i, n = 0;
507 int ptest, origin, ibt = 0, nmin = 0, nmax = 0;
508 int abs_p = 0, abs_w = 0, abs_x = 0, abs_y = 0;
509 507
510 if (size < c->tp_offset || (size - c->tp_offset) % SIZEOF_FINGER != 0) 508 if (size < c->tp_offset || (size - c->tp_offset) % SIZEOF_FINGER != 0)
511 return -EIO; 509 return -EIO;
@@ -514,76 +512,29 @@ static int report_tp_state(struct bcm5974 *dev, int size)
514 f = (const struct tp_finger *)(dev->tp_data + c->tp_offset); 512 f = (const struct tp_finger *)(dev->tp_data + c->tp_offset);
515 raw_n = (size - c->tp_offset) / SIZEOF_FINGER; 513 raw_n = (size - c->tp_offset) / SIZEOF_FINGER;
516 514
517 /* always track the first finger; when detached, start over */ 515 for (i = 0; i < raw_n; i++) {
518 if (raw_n) { 516 if (raw2int(f[i].touch_major) == 0)
519 517 continue;
520 /* report raw trackpad data */ 518 dev->pos[n].x = raw2int(f[i].abs_x);
521 for (i = 0; i < raw_n; i++) 519 dev->pos[n].y = c->y.min + c->y.max - raw2int(f[i].abs_y);
522 report_finger_data(input, c, &f[i]); 520 dev->index[n++] = &f[i];
523
524 raw_p = raw2int(f->force_major);
525 raw_w = raw2int(f->size_major);
526 raw_x = raw2int(f->abs_x);
527 raw_y = raw2int(f->abs_y);
528
529 dprintk(9,
530 "bcm5974: "
531 "raw: p: %+05d w: %+05d x: %+05d y: %+05d n: %d\n",
532 raw_p, raw_w, raw_x, raw_y, raw_n);
533
534 ptest = int2bound(&c->p, raw_p);
535 origin = raw2int(f->origin);
536
537 /* while tracking finger still valid, count all fingers */
538 if (ptest > PRESSURE_LOW && origin) {
539 abs_p = ptest;
540 abs_w = int2bound(&c->w, raw_w);
541 abs_x = int2bound(&c->x, raw_x - c->x.devmin);
542 abs_y = int2bound(&c->y, c->y.devmax - raw_y);
543 while (raw_n--) {
544 ptest = int2bound(&c->p,
545 raw2int(f->force_major));
546 if (ptest > PRESSURE_LOW)
547 nmax++;
548 if (ptest > PRESSURE_HIGH)
549 nmin++;
550 f++;
551 }
552 }
553 } 521 }
554 522
555 /* set the integrated button if applicable */ 523 input_mt_assign_slots(input, dev->slots, dev->pos, n);
556 if (c->tp_type == TYPE2)
557 ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
558
559 if (dev->fingers < nmin)
560 dev->fingers = nmin;
561 if (dev->fingers > nmax)
562 dev->fingers = nmax;
563
564 input_report_key(input, BTN_TOUCH, dev->fingers > 0);
565 input_report_key(input, BTN_TOOL_FINGER, dev->fingers == 1);
566 input_report_key(input, BTN_TOOL_DOUBLETAP, dev->fingers == 2);
567 input_report_key(input, BTN_TOOL_TRIPLETAP, dev->fingers == 3);
568 input_report_key(input, BTN_TOOL_QUADTAP, dev->fingers > 3);
569
570 input_report_abs(input, ABS_PRESSURE, abs_p);
571 input_report_abs(input, ABS_TOOL_WIDTH, abs_w);
572 524
573 if (abs_p) { 525 for (i = 0; i < n; i++)
574 input_report_abs(input, ABS_X, abs_x); 526 report_finger_data(input, dev->slots[i],
575 input_report_abs(input, ABS_Y, abs_y); 527 &dev->pos[i], dev->index[i]);
576 528
577 dprintk(8, 529 input_mt_sync_frame(input);
578 "bcm5974: abs: p: %+05d w: %+05d x: %+05d y: %+05d "
579 "nmin: %d nmax: %d n: %d ibt: %d\n", abs_p, abs_w,
580 abs_x, abs_y, nmin, nmax, dev->fingers, ibt);
581 530
582 } 531 report_synaptics_data(input, c, f, raw_n);
583 532
584 /* type 2 reports button events via ibt only */ 533 /* type 2 reports button events via ibt only */
585 if (c->tp_type == TYPE2) 534 if (c->tp_type == TYPE2) {
535 int ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
586 input_report_key(input, BTN_LEFT, ibt); 536 input_report_key(input, BTN_LEFT, ibt);
537 }
587 538
588 input_sync(input); 539 input_sync(input);
589 540
@@ -742,9 +693,11 @@ static int bcm5974_start_traffic(struct bcm5974 *dev)
742 goto err_out; 693 goto err_out;
743 } 694 }
744 695
745 error = usb_submit_urb(dev->bt_urb, GFP_KERNEL); 696 if (dev->bt_urb) {
746 if (error) 697 error = usb_submit_urb(dev->bt_urb, GFP_KERNEL);
747 goto err_reset_mode; 698 if (error)
699 goto err_reset_mode;
700 }
748 701
749 error = usb_submit_urb(dev->tp_urb, GFP_KERNEL); 702 error = usb_submit_urb(dev->tp_urb, GFP_KERNEL);
750 if (error) 703 if (error)
@@ -868,19 +821,23 @@ static int bcm5974_probe(struct usb_interface *iface,
868 mutex_init(&dev->pm_mutex); 821 mutex_init(&dev->pm_mutex);
869 822
870 /* setup urbs */ 823 /* setup urbs */
871 dev->bt_urb = usb_alloc_urb(0, GFP_KERNEL); 824 if (cfg->tp_type == TYPE1) {
872 if (!dev->bt_urb) 825 dev->bt_urb = usb_alloc_urb(0, GFP_KERNEL);
873 goto err_free_devs; 826 if (!dev->bt_urb)
827 goto err_free_devs;
828 }
874 829
875 dev->tp_urb = usb_alloc_urb(0, GFP_KERNEL); 830 dev->tp_urb = usb_alloc_urb(0, GFP_KERNEL);
876 if (!dev->tp_urb) 831 if (!dev->tp_urb)
877 goto err_free_bt_urb; 832 goto err_free_bt_urb;
878 833
879 dev->bt_data = usb_alloc_coherent(dev->udev, 834 if (dev->bt_urb) {
835 dev->bt_data = usb_alloc_coherent(dev->udev,
880 dev->cfg.bt_datalen, GFP_KERNEL, 836 dev->cfg.bt_datalen, GFP_KERNEL,
881 &dev->bt_urb->transfer_dma); 837 &dev->bt_urb->transfer_dma);
882 if (!dev->bt_data) 838 if (!dev->bt_data)
883 goto err_free_urb; 839 goto err_free_urb;
840 }
884 841
885 dev->tp_data = usb_alloc_coherent(dev->udev, 842 dev->tp_data = usb_alloc_coherent(dev->udev,
886 dev->cfg.tp_datalen, GFP_KERNEL, 843 dev->cfg.tp_datalen, GFP_KERNEL,
@@ -888,10 +845,11 @@ static int bcm5974_probe(struct usb_interface *iface,
888 if (!dev->tp_data) 845 if (!dev->tp_data)
889 goto err_free_bt_buffer; 846 goto err_free_bt_buffer;
890 847
891 usb_fill_int_urb(dev->bt_urb, udev, 848 if (dev->bt_urb)
892 usb_rcvintpipe(udev, cfg->bt_ep), 849 usb_fill_int_urb(dev->bt_urb, udev,
893 dev->bt_data, dev->cfg.bt_datalen, 850 usb_rcvintpipe(udev, cfg->bt_ep),
894 bcm5974_irq_button, dev, 1); 851 dev->bt_data, dev->cfg.bt_datalen,
852 bcm5974_irq_button, dev, 1);
895 853
896 usb_fill_int_urb(dev->tp_urb, udev, 854 usb_fill_int_urb(dev->tp_urb, udev,
897 usb_rcvintpipe(udev, cfg->tp_ep), 855 usb_rcvintpipe(udev, cfg->tp_ep),
@@ -929,8 +887,9 @@ err_free_buffer:
929 usb_free_coherent(dev->udev, dev->cfg.tp_datalen, 887 usb_free_coherent(dev->udev, dev->cfg.tp_datalen,
930 dev->tp_data, dev->tp_urb->transfer_dma); 888 dev->tp_data, dev->tp_urb->transfer_dma);
931err_free_bt_buffer: 889err_free_bt_buffer:
932 usb_free_coherent(dev->udev, dev->cfg.bt_datalen, 890 if (dev->bt_urb)
933 dev->bt_data, dev->bt_urb->transfer_dma); 891 usb_free_coherent(dev->udev, dev->cfg.bt_datalen,
892 dev->bt_data, dev->bt_urb->transfer_dma);
934err_free_urb: 893err_free_urb:
935 usb_free_urb(dev->tp_urb); 894 usb_free_urb(dev->tp_urb);
936err_free_bt_urb: 895err_free_bt_urb:
@@ -951,8 +910,9 @@ static void bcm5974_disconnect(struct usb_interface *iface)
951 input_unregister_device(dev->input); 910 input_unregister_device(dev->input);
952 usb_free_coherent(dev->udev, dev->cfg.tp_datalen, 911 usb_free_coherent(dev->udev, dev->cfg.tp_datalen,
953 dev->tp_data, dev->tp_urb->transfer_dma); 912 dev->tp_data, dev->tp_urb->transfer_dma);
954 usb_free_coherent(dev->udev, dev->cfg.bt_datalen, 913 if (dev->bt_urb)
955 dev->bt_data, dev->bt_urb->transfer_dma); 914 usb_free_coherent(dev->udev, dev->cfg.bt_datalen,
915 dev->bt_data, dev->bt_urb->transfer_dma);
956 usb_free_urb(dev->tp_urb); 916 usb_free_urb(dev->tp_urb);
957 usb_free_urb(dev->bt_urb); 917 usb_free_urb(dev->bt_urb);
958 kfree(dev); 918 kfree(dev);
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 479011004a11..1e8e42fb03a4 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -1004,7 +1004,7 @@ static int elantech_set_input_params(struct psmouse *psmouse)
1004 input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2, 1004 input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2,
1005 ETP_WMAX_V2, 0, 0); 1005 ETP_WMAX_V2, 0, 0);
1006 } 1006 }
1007 input_mt_init_slots(dev, 2); 1007 input_mt_init_slots(dev, 2, 0);
1008 input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0); 1008 input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0);
1009 input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0); 1009 input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0);
1010 break; 1010 break;
@@ -1035,7 +1035,7 @@ static int elantech_set_input_params(struct psmouse *psmouse)
1035 input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2, 1035 input_set_abs_params(dev, ABS_TOOL_WIDTH, ETP_WMIN_V2,
1036 ETP_WMAX_V2, 0, 0); 1036 ETP_WMAX_V2, 0, 0);
1037 /* Multitouch capable pad, up to 5 fingers. */ 1037 /* Multitouch capable pad, up to 5 fingers. */
1038 input_mt_init_slots(dev, ETP_MAX_FINGERS); 1038 input_mt_init_slots(dev, ETP_MAX_FINGERS, 0);
1039 input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0); 1039 input_set_abs_params(dev, ABS_MT_POSITION_X, x_min, x_max, 0, 0);
1040 input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0); 1040 input_set_abs_params(dev, ABS_MT_POSITION_Y, y_min, y_max, 0, 0);
1041 input_abs_set_res(dev, ABS_MT_POSITION_X, x_res); 1041 input_abs_set_res(dev, ABS_MT_POSITION_X, x_res);
diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c
index 3f5649f19082..e582922bacf7 100644
--- a/drivers/input/mouse/sentelic.c
+++ b/drivers/input/mouse/sentelic.c
@@ -721,6 +721,17 @@ static psmouse_ret_t fsp_process_byte(struct psmouse *psmouse)
721 721
722 switch (psmouse->packet[0] >> FSP_PKT_TYPE_SHIFT) { 722 switch (psmouse->packet[0] >> FSP_PKT_TYPE_SHIFT) {
723 case FSP_PKT_TYPE_ABS: 723 case FSP_PKT_TYPE_ABS:
724
725 if ((packet[0] == 0x48 || packet[0] == 0x49) &&
726 packet[1] == 0 && packet[2] == 0) {
727 /*
728 * Ignore coordinate noise when finger leaving the
729 * surface, otherwise cursor may jump to upper-left
730 * corner.
731 */
732 packet[3] &= 0xf0;
733 }
734
724 abs_x = GET_ABS_X(packet); 735 abs_x = GET_ABS_X(packet);
725 abs_y = GET_ABS_Y(packet); 736 abs_y = GET_ABS_Y(packet);
726 737
@@ -960,7 +971,7 @@ static int fsp_set_input_params(struct psmouse *psmouse)
960 971
961 input_set_abs_params(dev, ABS_X, 0, abs_x, 0, 0); 972 input_set_abs_params(dev, ABS_X, 0, abs_x, 0, 0);
962 input_set_abs_params(dev, ABS_Y, 0, abs_y, 0, 0); 973 input_set_abs_params(dev, ABS_Y, 0, abs_y, 0, 0);
963 input_mt_init_slots(dev, 2); 974 input_mt_init_slots(dev, 2, 0);
964 input_set_abs_params(dev, ABS_MT_POSITION_X, 0, abs_x, 0, 0); 975 input_set_abs_params(dev, ABS_MT_POSITION_X, 0, abs_x, 0, 0);
965 input_set_abs_params(dev, ABS_MT_POSITION_Y, 0, abs_y, 0, 0); 976 input_set_abs_params(dev, ABS_MT_POSITION_Y, 0, abs_y, 0, 0);
966 } 977 }
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 14eaecea2b70..37033ade79d3 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -1232,7 +1232,7 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
1232 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); 1232 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
1233 1233
1234 if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) { 1234 if (SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) {
1235 input_mt_init_slots(dev, 2); 1235 input_mt_init_slots(dev, 2, 0);
1236 set_abs_position_params(dev, priv, ABS_MT_POSITION_X, 1236 set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
1237 ABS_MT_POSITION_Y); 1237 ABS_MT_POSITION_Y);
1238 /* Image sensors can report per-contact pressure */ 1238 /* Image sensors can report per-contact pressure */
@@ -1244,7 +1244,7 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
1244 } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) { 1244 } else if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c)) {
1245 /* Non-image sensors with AGM use semi-mt */ 1245 /* Non-image sensors with AGM use semi-mt */
1246 __set_bit(INPUT_PROP_SEMI_MT, dev->propbit); 1246 __set_bit(INPUT_PROP_SEMI_MT, dev->propbit);
1247 input_mt_init_slots(dev, 2); 1247 input_mt_init_slots(dev, 2, 0);
1248 set_abs_position_params(dev, priv, ABS_MT_POSITION_X, 1248 set_abs_position_params(dev, priv, ABS_MT_POSITION_X,
1249 ABS_MT_POSITION_Y); 1249 ABS_MT_POSITION_Y);
1250 } 1250 }
diff --git a/drivers/input/serio/ambakmi.c b/drivers/input/serio/ambakmi.c
index 2ffd110bd5bc..2e77246c2e5a 100644
--- a/drivers/input/serio/ambakmi.c
+++ b/drivers/input/serio/ambakmi.c
@@ -72,7 +72,7 @@ static int amba_kmi_open(struct serio *io)
72 unsigned int divisor; 72 unsigned int divisor;
73 int ret; 73 int ret;
74 74
75 ret = clk_enable(kmi->clk); 75 ret = clk_prepare_enable(kmi->clk);
76 if (ret) 76 if (ret)
77 goto out; 77 goto out;
78 78
@@ -92,7 +92,7 @@ static int amba_kmi_open(struct serio *io)
92 return 0; 92 return 0;
93 93
94 clk_disable: 94 clk_disable:
95 clk_disable(kmi->clk); 95 clk_disable_unprepare(kmi->clk);
96 out: 96 out:
97 return ret; 97 return ret;
98} 98}
@@ -104,7 +104,7 @@ static void amba_kmi_close(struct serio *io)
104 writeb(0, KMICR); 104 writeb(0, KMICR);
105 105
106 free_irq(kmi->irq, kmi); 106 free_irq(kmi->irq, kmi);
107 clk_disable(kmi->clk); 107 clk_disable_unprepare(kmi->clk);
108} 108}
109 109
110static int __devinit amba_kmi_probe(struct amba_device *dev, 110static int __devinit amba_kmi_probe(struct amba_device *dev,
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 6918773ce024..d6cc77a53c7e 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -335,6 +335,12 @@ static const struct dmi_system_id __initconst i8042_dmi_nomux_table[] = {
335 }, 335 },
336 { 336 {
337 .matches = { 337 .matches = {
338 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
339 DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE C850D"),
340 },
341 },
342 {
343 .matches = {
338 DMI_MATCH(DMI_SYS_VENDOR, "ALIENWARE"), 344 DMI_MATCH(DMI_SYS_VENDOR, "ALIENWARE"),
339 DMI_MATCH(DMI_PRODUCT_NAME, "Sentia"), 345 DMI_MATCH(DMI_PRODUCT_NAME, "Sentia"),
340 }, 346 },
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 532d067a9e07..2a81ce375f75 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -1530,7 +1530,7 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
1530 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); 1530 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
1531 __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit); 1531 __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit);
1532 1532
1533 input_mt_init_slots(input_dev, features->touch_max); 1533 input_mt_init_slots(input_dev, features->touch_max, 0);
1534 1534
1535 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 1535 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1536 0, 255, 0, 0); 1536 0, 255, 0, 0);
@@ -1575,7 +1575,7 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
1575 1575
1576 case TABLETPC2FG: 1576 case TABLETPC2FG:
1577 if (features->device_type == BTN_TOOL_FINGER) { 1577 if (features->device_type == BTN_TOOL_FINGER) {
1578 input_mt_init_slots(input_dev, features->touch_max); 1578 input_mt_init_slots(input_dev, features->touch_max, 0);
1579 input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE, 1579 input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE,
1580 0, MT_TOOL_MAX, 0, 0); 1580 0, MT_TOOL_MAX, 0, 0);
1581 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 1581 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
@@ -1631,7 +1631,7 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
1631 1631
1632 __set_bit(BTN_TOOL_FINGER, input_dev->keybit); 1632 __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
1633 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); 1633 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
1634 input_mt_init_slots(input_dev, features->touch_max); 1634 input_mt_init_slots(input_dev, features->touch_max, 0);
1635 1635
1636 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) { 1636 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
1637 __set_bit(BTN_TOOL_TRIPLETAP, 1637 __set_bit(BTN_TOOL_TRIPLETAP,
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 4623cc69fc60..e92615d0b1b0 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1152,7 +1152,7 @@ static int __devinit mxt_probe(struct i2c_client *client,
1152 1152
1153 /* For multi touch */ 1153 /* For multi touch */
1154 num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1; 1154 num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
1155 error = input_mt_init_slots(input_dev, num_mt_slots); 1155 error = input_mt_init_slots(input_dev, num_mt_slots, 0);
1156 if (error) 1156 if (error)
1157 goto err_free_object; 1157 goto err_free_object;
1158 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 1158 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
diff --git a/drivers/input/touchscreen/cyttsp_core.c b/drivers/input/touchscreen/cyttsp_core.c
index f030d9ec795d..8e60437ac85b 100644
--- a/drivers/input/touchscreen/cyttsp_core.c
+++ b/drivers/input/touchscreen/cyttsp_core.c
@@ -571,7 +571,7 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
571 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 571 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
572 0, CY_MAXZ, 0, 0); 572 0, CY_MAXZ, 0, 0);
573 573
574 input_mt_init_slots(input_dev, CY_MAX_ID); 574 input_mt_init_slots(input_dev, CY_MAX_ID, 0);
575 575
576 error = request_threaded_irq(ts->irq, NULL, cyttsp_irq, 576 error = request_threaded_irq(ts->irq, NULL, cyttsp_irq,
577 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 577 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index b06a5e3a665e..099d144ab7c9 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -566,9 +566,12 @@ static ssize_t edt_ft5x06_debugfs_raw_data_read(struct file *file,
566 } 566 }
567 567
568 read = min_t(size_t, count, tsdata->raw_bufsize - *off); 568 read = min_t(size_t, count, tsdata->raw_bufsize - *off);
569 error = copy_to_user(buf, tsdata->raw_buffer + *off, read); 569 if (copy_to_user(buf, tsdata->raw_buffer + *off, read)) {
570 if (!error) 570 error = -EFAULT;
571 *off += read; 571 goto out;
572 }
573
574 *off += read;
572out: 575out:
573 mutex_unlock(&tsdata->mutex); 576 mutex_unlock(&tsdata->mutex);
574 return error ?: read; 577 return error ?: read;
@@ -779,7 +782,7 @@ static int __devinit edt_ft5x06_ts_probe(struct i2c_client *client,
779 0, tsdata->num_x * 64 - 1, 0, 0); 782 0, tsdata->num_x * 64 - 1, 0, 0);
780 input_set_abs_params(input, ABS_MT_POSITION_Y, 783 input_set_abs_params(input, ABS_MT_POSITION_Y,
781 0, tsdata->num_y * 64 - 1, 0, 0); 784 0, tsdata->num_y * 64 - 1, 0, 0);
782 error = input_mt_init_slots(input, MAX_SUPPORT_POINTS); 785 error = input_mt_init_slots(input, MAX_SUPPORT_POINTS, 0);
783 if (error) { 786 if (error) {
784 dev_err(&client->dev, "Unable to init MT slots.\n"); 787 dev_err(&client->dev, "Unable to init MT slots.\n");
785 goto err_free_mem; 788 goto err_free_mem;
diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c
index 70524dd34f42..c1e3460f1195 100644
--- a/drivers/input/touchscreen/egalax_ts.c
+++ b/drivers/input/touchscreen/egalax_ts.c
@@ -204,7 +204,7 @@ static int __devinit egalax_ts_probe(struct i2c_client *client,
204 ABS_MT_POSITION_X, 0, EGALAX_MAX_X, 0, 0); 204 ABS_MT_POSITION_X, 0, EGALAX_MAX_X, 0, 0);
205 input_set_abs_params(input_dev, 205 input_set_abs_params(input_dev,
206 ABS_MT_POSITION_X, 0, EGALAX_MAX_Y, 0, 0); 206 ABS_MT_POSITION_X, 0, EGALAX_MAX_Y, 0, 0);
207 input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS); 207 input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS, 0);
208 208
209 input_set_drvdata(input_dev, ts); 209 input_set_drvdata(input_dev, ts);
210 210
diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
index c0044175a921..4ac69760ec08 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -252,7 +252,7 @@ static int __devinit ili210x_i2c_probe(struct i2c_client *client,
252 input_set_abs_params(input, ABS_Y, 0, ymax, 0, 0); 252 input_set_abs_params(input, ABS_Y, 0, ymax, 0, 0);
253 253
254 /* Multi touch */ 254 /* Multi touch */
255 input_mt_init_slots(input, MAX_TOUCHES); 255 input_mt_init_slots(input, MAX_TOUCHES, 0);
256 input_set_abs_params(input, ABS_MT_POSITION_X, 0, xmax, 0, 0); 256 input_set_abs_params(input, ABS_MT_POSITION_X, 0, xmax, 0, 0);
257 input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ymax, 0, 0); 257 input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ymax, 0, 0);
258 258
diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c
index 49c44bbf548d..560cf09d1c5a 100644
--- a/drivers/input/touchscreen/mms114.c
+++ b/drivers/input/touchscreen/mms114.c
@@ -404,7 +404,7 @@ static int __devinit mms114_probe(struct i2c_client *client,
404 input_set_abs_params(input_dev, ABS_Y, 0, data->pdata->y_size, 0, 0); 404 input_set_abs_params(input_dev, ABS_Y, 0, data->pdata->y_size, 0, 0);
405 405
406 /* For multi touch */ 406 /* For multi touch */
407 input_mt_init_slots(input_dev, MMS114_MAX_TOUCH); 407 input_mt_init_slots(input_dev, MMS114_MAX_TOUCH, 0);
408 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 408 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
409 0, MMS114_MAX_AREA, 0, 0); 409 0, MMS114_MAX_AREA, 0, 0);
410 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 410 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
diff --git a/drivers/input/touchscreen/penmount.c b/drivers/input/touchscreen/penmount.c
index 4ccde45b9da2..b49f0b836925 100644
--- a/drivers/input/touchscreen/penmount.c
+++ b/drivers/input/touchscreen/penmount.c
@@ -264,7 +264,7 @@ static int pm_connect(struct serio *serio, struct serio_driver *drv)
264 input_set_abs_params(pm->dev, ABS_Y, 0, max_y, 0, 0); 264 input_set_abs_params(pm->dev, ABS_Y, 0, max_y, 0, 0);
265 265
266 if (pm->maxcontacts > 1) { 266 if (pm->maxcontacts > 1) {
267 input_mt_init_slots(pm->dev, pm->maxcontacts); 267 input_mt_init_slots(pm->dev, pm->maxcontacts, 0);
268 input_set_abs_params(pm->dev, 268 input_set_abs_params(pm->dev,
269 ABS_MT_POSITION_X, 0, max_x, 0, 0); 269 ABS_MT_POSITION_X, 0, max_x, 0, 0);
270 input_set_abs_params(pm->dev, 270 input_set_abs_params(pm->dev,
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index e32709e0dd65..721fdb3597ca 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -304,6 +304,45 @@ static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
304#define EGALAX_PKT_TYPE_REPT 0x80 304#define EGALAX_PKT_TYPE_REPT 0x80
305#define EGALAX_PKT_TYPE_DIAG 0x0A 305#define EGALAX_PKT_TYPE_DIAG 0x0A
306 306
307static int egalax_init(struct usbtouch_usb *usbtouch)
308{
309 int ret, i;
310 unsigned char *buf;
311 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
312
313 /*
314 * An eGalax diagnostic packet kicks the device into using the right
315 * protocol. We send a "check active" packet. The response will be
316 * read later and ignored.
317 */
318
319 buf = kmalloc(3, GFP_KERNEL);
320 if (!buf)
321 return -ENOMEM;
322
323 buf[0] = EGALAX_PKT_TYPE_DIAG;
324 buf[1] = 1; /* length */
325 buf[2] = 'A'; /* command - check active */
326
327 for (i = 0; i < 3; i++) {
328 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
329 0,
330 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
331 0, 0, buf, 3,
332 USB_CTRL_SET_TIMEOUT);
333 if (ret >= 0) {
334 ret = 0;
335 break;
336 }
337 if (ret != -EPIPE)
338 break;
339 }
340
341 kfree(buf);
342
343 return ret;
344}
345
307static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt) 346static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
308{ 347{
309 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT) 348 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
@@ -1056,6 +1095,7 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
1056 .process_pkt = usbtouch_process_multi, 1095 .process_pkt = usbtouch_process_multi,
1057 .get_pkt_len = egalax_get_pkt_len, 1096 .get_pkt_len = egalax_get_pkt_len,
1058 .read_data = egalax_read_data, 1097 .read_data = egalax_read_data,
1098 .init = egalax_init,
1059 }, 1099 },
1060#endif 1100#endif
1061 1101
diff --git a/drivers/input/touchscreen/wacom_w8001.c b/drivers/input/touchscreen/wacom_w8001.c
index 8f9ad2f893b8..9a83be6b6584 100644
--- a/drivers/input/touchscreen/wacom_w8001.c
+++ b/drivers/input/touchscreen/wacom_w8001.c
@@ -471,7 +471,7 @@ static int w8001_setup(struct w8001 *w8001)
471 case 5: 471 case 5:
472 w8001->pktlen = W8001_PKTLEN_TOUCH2FG; 472 w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
473 473
474 input_mt_init_slots(dev, 2); 474 input_mt_init_slots(dev, 2, 0);
475 input_set_abs_params(dev, ABS_MT_POSITION_X, 475 input_set_abs_params(dev, ABS_MT_POSITION_X,
476 0, touch.x, 0, 0); 476 0, touch.x, 0, 0);
477 input_set_abs_params(dev, ABS_MT_POSITION_Y, 477 input_set_abs_params(dev, ABS_MT_POSITION_Y,
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b64502dfa9f4..e89daf1b21b4 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -266,7 +266,7 @@ static void swap_pci_ref(struct pci_dev **from, struct pci_dev *to)
266 266
267static int iommu_init_device(struct device *dev) 267static int iommu_init_device(struct device *dev)
268{ 268{
269 struct pci_dev *dma_pdev, *pdev = to_pci_dev(dev); 269 struct pci_dev *dma_pdev = NULL, *pdev = to_pci_dev(dev);
270 struct iommu_dev_data *dev_data; 270 struct iommu_dev_data *dev_data;
271 struct iommu_group *group; 271 struct iommu_group *group;
272 u16 alias; 272 u16 alias;
@@ -293,7 +293,9 @@ static int iommu_init_device(struct device *dev)
293 dev_data->alias_data = alias_data; 293 dev_data->alias_data = alias_data;
294 294
295 dma_pdev = pci_get_bus_and_slot(alias >> 8, alias & 0xff); 295 dma_pdev = pci_get_bus_and_slot(alias >> 8, alias & 0xff);
296 } else 296 }
297
298 if (dma_pdev == NULL)
297 dma_pdev = pci_dev_get(pdev); 299 dma_pdev = pci_dev_get(pdev);
298 300
299 /* Account for quirked devices */ 301 /* Account for quirked devices */
diff --git a/drivers/isdn/hardware/mISDN/avmfritz.c b/drivers/isdn/hardware/mISDN/avmfritz.c
index fa6ca4733725..dceaec821b0e 100644
--- a/drivers/isdn/hardware/mISDN/avmfritz.c
+++ b/drivers/isdn/hardware/mISDN/avmfritz.c
@@ -857,8 +857,9 @@ avm_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
857 switch (cmd) { 857 switch (cmd) {
858 case CLOSE_CHANNEL: 858 case CLOSE_CHANNEL:
859 test_and_clear_bit(FLG_OPEN, &bch->Flags); 859 test_and_clear_bit(FLG_OPEN, &bch->Flags);
860 cancel_work_sync(&bch->workq);
860 spin_lock_irqsave(&fc->lock, flags); 861 spin_lock_irqsave(&fc->lock, flags);
861 mISDN_freebchannel(bch); 862 mISDN_clear_bchannel(bch);
862 modehdlc(bch, ISDN_P_NONE); 863 modehdlc(bch, ISDN_P_NONE);
863 spin_unlock_irqrestore(&fc->lock, flags); 864 spin_unlock_irqrestore(&fc->lock, flags);
864 ch->protocol = ISDN_P_NONE; 865 ch->protocol = ISDN_P_NONE;
diff --git a/drivers/isdn/hardware/mISDN/hfcmulti.c b/drivers/isdn/hardware/mISDN/hfcmulti.c
index 5e402cf2e795..f02794203bb1 100644
--- a/drivers/isdn/hardware/mISDN/hfcmulti.c
+++ b/drivers/isdn/hardware/mISDN/hfcmulti.c
@@ -5059,6 +5059,7 @@ hfcmulti_init(struct hm_map *m, struct pci_dev *pdev,
5059 printk(KERN_INFO 5059 printk(KERN_INFO
5060 "HFC-E1 #%d has overlapping B-channels on fragment #%d\n", 5060 "HFC-E1 #%d has overlapping B-channels on fragment #%d\n",
5061 E1_cnt + 1, pt); 5061 E1_cnt + 1, pt);
5062 kfree(hc);
5062 return -EINVAL; 5063 return -EINVAL;
5063 } 5064 }
5064 maskcheck |= hc->bmask[pt]; 5065 maskcheck |= hc->bmask[pt];
@@ -5086,6 +5087,7 @@ hfcmulti_init(struct hm_map *m, struct pci_dev *pdev,
5086 if ((poll >> 1) > sizeof(hc->silence_data)) { 5087 if ((poll >> 1) > sizeof(hc->silence_data)) {
5087 printk(KERN_ERR "HFCMULTI error: silence_data too small, " 5088 printk(KERN_ERR "HFCMULTI error: silence_data too small, "
5088 "please fix\n"); 5089 "please fix\n");
5090 kfree(hc);
5089 return -EINVAL; 5091 return -EINVAL;
5090 } 5092 }
5091 for (i = 0; i < (poll >> 1); i++) 5093 for (i = 0; i < (poll >> 1); i++)
diff --git a/drivers/isdn/hardware/mISDN/mISDNipac.c b/drivers/isdn/hardware/mISDN/mISDNipac.c
index 752e0825591f..ccd7d851be26 100644
--- a/drivers/isdn/hardware/mISDN/mISDNipac.c
+++ b/drivers/isdn/hardware/mISDN/mISDNipac.c
@@ -1406,8 +1406,9 @@ hscx_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
1406 switch (cmd) { 1406 switch (cmd) {
1407 case CLOSE_CHANNEL: 1407 case CLOSE_CHANNEL:
1408 test_and_clear_bit(FLG_OPEN, &bch->Flags); 1408 test_and_clear_bit(FLG_OPEN, &bch->Flags);
1409 cancel_work_sync(&bch->workq);
1409 spin_lock_irqsave(hx->ip->hwlock, flags); 1410 spin_lock_irqsave(hx->ip->hwlock, flags);
1410 mISDN_freebchannel(bch); 1411 mISDN_clear_bchannel(bch);
1411 hscx_mode(hx, ISDN_P_NONE); 1412 hscx_mode(hx, ISDN_P_NONE);
1412 spin_unlock_irqrestore(hx->ip->hwlock, flags); 1413 spin_unlock_irqrestore(hx->ip->hwlock, flags);
1413 ch->protocol = ISDN_P_NONE; 1414 ch->protocol = ISDN_P_NONE;
diff --git a/drivers/isdn/hardware/mISDN/mISDNisar.c b/drivers/isdn/hardware/mISDN/mISDNisar.c
index be5973ded6d6..182ecf0626c2 100644
--- a/drivers/isdn/hardware/mISDN/mISDNisar.c
+++ b/drivers/isdn/hardware/mISDN/mISDNisar.c
@@ -1588,8 +1588,9 @@ isar_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
1588 switch (cmd) { 1588 switch (cmd) {
1589 case CLOSE_CHANNEL: 1589 case CLOSE_CHANNEL:
1590 test_and_clear_bit(FLG_OPEN, &bch->Flags); 1590 test_and_clear_bit(FLG_OPEN, &bch->Flags);
1591 cancel_work_sync(&bch->workq);
1591 spin_lock_irqsave(ich->is->hwlock, flags); 1592 spin_lock_irqsave(ich->is->hwlock, flags);
1592 mISDN_freebchannel(bch); 1593 mISDN_clear_bchannel(bch);
1593 modeisar(ich, ISDN_P_NONE); 1594 modeisar(ich, ISDN_P_NONE);
1594 spin_unlock_irqrestore(ich->is->hwlock, flags); 1595 spin_unlock_irqrestore(ich->is->hwlock, flags);
1595 ch->protocol = ISDN_P_NONE; 1596 ch->protocol = ISDN_P_NONE;
diff --git a/drivers/isdn/hardware/mISDN/netjet.c b/drivers/isdn/hardware/mISDN/netjet.c
index c3e3e7686273..9bcade59eb73 100644
--- a/drivers/isdn/hardware/mISDN/netjet.c
+++ b/drivers/isdn/hardware/mISDN/netjet.c
@@ -812,8 +812,9 @@ nj_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
812 switch (cmd) { 812 switch (cmd) {
813 case CLOSE_CHANNEL: 813 case CLOSE_CHANNEL:
814 test_and_clear_bit(FLG_OPEN, &bch->Flags); 814 test_and_clear_bit(FLG_OPEN, &bch->Flags);
815 cancel_work_sync(&bch->workq);
815 spin_lock_irqsave(&card->lock, flags); 816 spin_lock_irqsave(&card->lock, flags);
816 mISDN_freebchannel(bch); 817 mISDN_clear_bchannel(bch);
817 mode_tiger(bc, ISDN_P_NONE); 818 mode_tiger(bc, ISDN_P_NONE);
818 spin_unlock_irqrestore(&card->lock, flags); 819 spin_unlock_irqrestore(&card->lock, flags);
819 ch->protocol = ISDN_P_NONE; 820 ch->protocol = ISDN_P_NONE;
diff --git a/drivers/isdn/hardware/mISDN/w6692.c b/drivers/isdn/hardware/mISDN/w6692.c
index 26a86b846099..335fe6455002 100644
--- a/drivers/isdn/hardware/mISDN/w6692.c
+++ b/drivers/isdn/hardware/mISDN/w6692.c
@@ -1054,8 +1054,9 @@ w6692_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
1054 switch (cmd) { 1054 switch (cmd) {
1055 case CLOSE_CHANNEL: 1055 case CLOSE_CHANNEL:
1056 test_and_clear_bit(FLG_OPEN, &bch->Flags); 1056 test_and_clear_bit(FLG_OPEN, &bch->Flags);
1057 cancel_work_sync(&bch->workq);
1057 spin_lock_irqsave(&card->lock, flags); 1058 spin_lock_irqsave(&card->lock, flags);
1058 mISDN_freebchannel(bch); 1059 mISDN_clear_bchannel(bch);
1059 w6692_mode(bc, ISDN_P_NONE); 1060 w6692_mode(bc, ISDN_P_NONE);
1060 spin_unlock_irqrestore(&card->lock, flags); 1061 spin_unlock_irqrestore(&card->lock, flags);
1061 ch->protocol = ISDN_P_NONE; 1062 ch->protocol = ISDN_P_NONE;
diff --git a/drivers/isdn/mISDN/hwchannel.c b/drivers/isdn/mISDN/hwchannel.c
index ef34fd40867c..2602be23f341 100644
--- a/drivers/isdn/mISDN/hwchannel.c
+++ b/drivers/isdn/mISDN/hwchannel.c
@@ -148,17 +148,16 @@ mISDN_clear_bchannel(struct bchannel *ch)
148 ch->next_minlen = ch->init_minlen; 148 ch->next_minlen = ch->init_minlen;
149 ch->maxlen = ch->init_maxlen; 149 ch->maxlen = ch->init_maxlen;
150 ch->next_maxlen = ch->init_maxlen; 150 ch->next_maxlen = ch->init_maxlen;
151 skb_queue_purge(&ch->rqueue);
152 ch->rcount = 0;
151} 153}
152EXPORT_SYMBOL(mISDN_clear_bchannel); 154EXPORT_SYMBOL(mISDN_clear_bchannel);
153 155
154int 156void
155mISDN_freebchannel(struct bchannel *ch) 157mISDN_freebchannel(struct bchannel *ch)
156{ 158{
159 cancel_work_sync(&ch->workq);
157 mISDN_clear_bchannel(ch); 160 mISDN_clear_bchannel(ch);
158 skb_queue_purge(&ch->rqueue);
159 ch->rcount = 0;
160 flush_work_sync(&ch->workq);
161 return 0;
162} 161}
163EXPORT_SYMBOL(mISDN_freebchannel); 162EXPORT_SYMBOL(mISDN_freebchannel);
164 163
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index d8abb90a6c2f..034233eefc82 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1555,6 +1555,7 @@ static int multipath_ioctl(struct dm_target *ti, unsigned int cmd,
1555 unsigned long arg) 1555 unsigned long arg)
1556{ 1556{
1557 struct multipath *m = ti->private; 1557 struct multipath *m = ti->private;
1558 struct pgpath *pgpath;
1558 struct block_device *bdev; 1559 struct block_device *bdev;
1559 fmode_t mode; 1560 fmode_t mode;
1560 unsigned long flags; 1561 unsigned long flags;
@@ -1570,12 +1571,14 @@ again:
1570 if (!m->current_pgpath) 1571 if (!m->current_pgpath)
1571 __choose_pgpath(m, 0); 1572 __choose_pgpath(m, 0);
1572 1573
1573 if (m->current_pgpath) { 1574 pgpath = m->current_pgpath;
1574 bdev = m->current_pgpath->path.dev->bdev; 1575
1575 mode = m->current_pgpath->path.dev->mode; 1576 if (pgpath) {
1577 bdev = pgpath->path.dev->bdev;
1578 mode = pgpath->path.dev->mode;
1576 } 1579 }
1577 1580
1578 if (m->queue_io) 1581 if ((pgpath && m->queue_io) || (!pgpath && m->queue_if_no_path))
1579 r = -EAGAIN; 1582 r = -EAGAIN;
1580 else if (!bdev) 1583 else if (!bdev)
1581 r = -EIO; 1584 r = -EIO;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index f90069029aae..100368eb7991 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1212,6 +1212,41 @@ struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector)
1212 return &t->targets[(KEYS_PER_NODE * n) + k]; 1212 return &t->targets[(KEYS_PER_NODE * n) + k];
1213} 1213}
1214 1214
1215static int count_device(struct dm_target *ti, struct dm_dev *dev,
1216 sector_t start, sector_t len, void *data)
1217{
1218 unsigned *num_devices = data;
1219
1220 (*num_devices)++;
1221
1222 return 0;
1223}
1224
1225/*
1226 * Check whether a table has no data devices attached using each
1227 * target's iterate_devices method.
1228 * Returns false if the result is unknown because a target doesn't
1229 * support iterate_devices.
1230 */
1231bool dm_table_has_no_data_devices(struct dm_table *table)
1232{
1233 struct dm_target *uninitialized_var(ti);
1234 unsigned i = 0, num_devices = 0;
1235
1236 while (i < dm_table_get_num_targets(table)) {
1237 ti = dm_table_get_target(table, i++);
1238
1239 if (!ti->type->iterate_devices)
1240 return false;
1241
1242 ti->type->iterate_devices(ti, count_device, &num_devices);
1243 if (num_devices)
1244 return false;
1245 }
1246
1247 return true;
1248}
1249
1215/* 1250/*
1216 * Establish the new table's queue_limits and validate them. 1251 * Establish the new table's queue_limits and validate them.
1217 */ 1252 */
@@ -1354,17 +1389,25 @@ static int device_is_nonrot(struct dm_target *ti, struct dm_dev *dev,
1354 return q && blk_queue_nonrot(q); 1389 return q && blk_queue_nonrot(q);
1355} 1390}
1356 1391
1357static bool dm_table_is_nonrot(struct dm_table *t) 1392static int device_is_not_random(struct dm_target *ti, struct dm_dev *dev,
1393 sector_t start, sector_t len, void *data)
1394{
1395 struct request_queue *q = bdev_get_queue(dev->bdev);
1396
1397 return q && !blk_queue_add_random(q);
1398}
1399
1400static bool dm_table_all_devices_attribute(struct dm_table *t,
1401 iterate_devices_callout_fn func)
1358{ 1402{
1359 struct dm_target *ti; 1403 struct dm_target *ti;
1360 unsigned i = 0; 1404 unsigned i = 0;
1361 1405
1362 /* Ensure that all underlying device are non-rotational. */
1363 while (i < dm_table_get_num_targets(t)) { 1406 while (i < dm_table_get_num_targets(t)) {
1364 ti = dm_table_get_target(t, i++); 1407 ti = dm_table_get_target(t, i++);
1365 1408
1366 if (!ti->type->iterate_devices || 1409 if (!ti->type->iterate_devices ||
1367 !ti->type->iterate_devices(ti, device_is_nonrot, NULL)) 1410 !ti->type->iterate_devices(ti, func, NULL))
1368 return 0; 1411 return 0;
1369 } 1412 }
1370 1413
@@ -1396,7 +1439,8 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
1396 if (!dm_table_discard_zeroes_data(t)) 1439 if (!dm_table_discard_zeroes_data(t))
1397 q->limits.discard_zeroes_data = 0; 1440 q->limits.discard_zeroes_data = 0;
1398 1441
1399 if (dm_table_is_nonrot(t)) 1442 /* Ensure that all underlying devices are non-rotational. */
1443 if (dm_table_all_devices_attribute(t, device_is_nonrot))
1400 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q); 1444 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
1401 else 1445 else
1402 queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q); 1446 queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q);
@@ -1404,6 +1448,15 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
1404 dm_table_set_integrity(t); 1448 dm_table_set_integrity(t);
1405 1449
1406 /* 1450 /*
1451 * Determine whether or not this queue's I/O timings contribute
1452 * to the entropy pool, Only request-based targets use this.
1453 * Clear QUEUE_FLAG_ADD_RANDOM if any underlying device does not
1454 * have it set.
1455 */
1456 if (blk_queue_add_random(q) && dm_table_all_devices_attribute(t, device_is_not_random))
1457 queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, q);
1458
1459 /*
1407 * QUEUE_FLAG_STACKABLE must be set after all queue settings are 1460 * QUEUE_FLAG_STACKABLE must be set after all queue settings are
1408 * visible to other CPUs because, once the flag is set, incoming bios 1461 * visible to other CPUs because, once the flag is set, incoming bios
1409 * are processed by request-based dm, which refers to the queue 1462 * are processed by request-based dm, which refers to the queue
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index af1fc3b2c2ad..c29410af1e22 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -509,9 +509,9 @@ enum pool_mode {
509struct pool_features { 509struct pool_features {
510 enum pool_mode mode; 510 enum pool_mode mode;
511 511
512 unsigned zero_new_blocks:1; 512 bool zero_new_blocks:1;
513 unsigned discard_enabled:1; 513 bool discard_enabled:1;
514 unsigned discard_passdown:1; 514 bool discard_passdown:1;
515}; 515};
516 516
517struct thin_c; 517struct thin_c;
@@ -580,7 +580,8 @@ struct pool_c {
580 struct dm_target_callbacks callbacks; 580 struct dm_target_callbacks callbacks;
581 581
582 dm_block_t low_water_blocks; 582 dm_block_t low_water_blocks;
583 struct pool_features pf; 583 struct pool_features requested_pf; /* Features requested during table load */
584 struct pool_features adjusted_pf; /* Features used after adjusting for constituent devices */
584}; 585};
585 586
586/* 587/*
@@ -1839,6 +1840,47 @@ static void __requeue_bios(struct pool *pool)
1839/*---------------------------------------------------------------- 1840/*----------------------------------------------------------------
1840 * Binding of control targets to a pool object 1841 * Binding of control targets to a pool object
1841 *--------------------------------------------------------------*/ 1842 *--------------------------------------------------------------*/
1843static bool data_dev_supports_discard(struct pool_c *pt)
1844{
1845 struct request_queue *q = bdev_get_queue(pt->data_dev->bdev);
1846
1847 return q && blk_queue_discard(q);
1848}
1849
1850/*
1851 * If discard_passdown was enabled verify that the data device
1852 * supports discards. Disable discard_passdown if not.
1853 */
1854static void disable_passdown_if_not_supported(struct pool_c *pt)
1855{
1856 struct pool *pool = pt->pool;
1857 struct block_device *data_bdev = pt->data_dev->bdev;
1858 struct queue_limits *data_limits = &bdev_get_queue(data_bdev)->limits;
1859 sector_t block_size = pool->sectors_per_block << SECTOR_SHIFT;
1860 const char *reason = NULL;
1861 char buf[BDEVNAME_SIZE];
1862
1863 if (!pt->adjusted_pf.discard_passdown)
1864 return;
1865
1866 if (!data_dev_supports_discard(pt))
1867 reason = "discard unsupported";
1868
1869 else if (data_limits->max_discard_sectors < pool->sectors_per_block)
1870 reason = "max discard sectors smaller than a block";
1871
1872 else if (data_limits->discard_granularity > block_size)
1873 reason = "discard granularity larger than a block";
1874
1875 else if (block_size & (data_limits->discard_granularity - 1))
1876 reason = "discard granularity not a factor of block size";
1877
1878 if (reason) {
1879 DMWARN("Data device (%s) %s: Disabling discard passdown.", bdevname(data_bdev, buf), reason);
1880 pt->adjusted_pf.discard_passdown = false;
1881 }
1882}
1883
1842static int bind_control_target(struct pool *pool, struct dm_target *ti) 1884static int bind_control_target(struct pool *pool, struct dm_target *ti)
1843{ 1885{
1844 struct pool_c *pt = ti->private; 1886 struct pool_c *pt = ti->private;
@@ -1847,31 +1889,16 @@ static int bind_control_target(struct pool *pool, struct dm_target *ti)
1847 * We want to make sure that degraded pools are never upgraded. 1889 * We want to make sure that degraded pools are never upgraded.
1848 */ 1890 */
1849 enum pool_mode old_mode = pool->pf.mode; 1891 enum pool_mode old_mode = pool->pf.mode;
1850 enum pool_mode new_mode = pt->pf.mode; 1892 enum pool_mode new_mode = pt->adjusted_pf.mode;
1851 1893
1852 if (old_mode > new_mode) 1894 if (old_mode > new_mode)
1853 new_mode = old_mode; 1895 new_mode = old_mode;
1854 1896
1855 pool->ti = ti; 1897 pool->ti = ti;
1856 pool->low_water_blocks = pt->low_water_blocks; 1898 pool->low_water_blocks = pt->low_water_blocks;
1857 pool->pf = pt->pf; 1899 pool->pf = pt->adjusted_pf;
1858 set_pool_mode(pool, new_mode);
1859 1900
1860 /* 1901 set_pool_mode(pool, new_mode);
1861 * If discard_passdown was enabled verify that the data device
1862 * supports discards. Disable discard_passdown if not; otherwise
1863 * -EOPNOTSUPP will be returned.
1864 */
1865 /* FIXME: pull this out into a sep fn. */
1866 if (pt->pf.discard_passdown) {
1867 struct request_queue *q = bdev_get_queue(pt->data_dev->bdev);
1868 if (!q || !blk_queue_discard(q)) {
1869 char buf[BDEVNAME_SIZE];
1870 DMWARN("Discard unsupported by data device (%s): Disabling discard passdown.",
1871 bdevname(pt->data_dev->bdev, buf));
1872 pool->pf.discard_passdown = 0;
1873 }
1874 }
1875 1902
1876 return 0; 1903 return 0;
1877} 1904}
@@ -1889,9 +1916,9 @@ static void unbind_control_target(struct pool *pool, struct dm_target *ti)
1889static void pool_features_init(struct pool_features *pf) 1916static void pool_features_init(struct pool_features *pf)
1890{ 1917{
1891 pf->mode = PM_WRITE; 1918 pf->mode = PM_WRITE;
1892 pf->zero_new_blocks = 1; 1919 pf->zero_new_blocks = true;
1893 pf->discard_enabled = 1; 1920 pf->discard_enabled = true;
1894 pf->discard_passdown = 1; 1921 pf->discard_passdown = true;
1895} 1922}
1896 1923
1897static void __pool_destroy(struct pool *pool) 1924static void __pool_destroy(struct pool *pool)
@@ -2119,13 +2146,13 @@ static int parse_pool_features(struct dm_arg_set *as, struct pool_features *pf,
2119 argc--; 2146 argc--;
2120 2147
2121 if (!strcasecmp(arg_name, "skip_block_zeroing")) 2148 if (!strcasecmp(arg_name, "skip_block_zeroing"))
2122 pf->zero_new_blocks = 0; 2149 pf->zero_new_blocks = false;
2123 2150
2124 else if (!strcasecmp(arg_name, "ignore_discard")) 2151 else if (!strcasecmp(arg_name, "ignore_discard"))
2125 pf->discard_enabled = 0; 2152 pf->discard_enabled = false;
2126 2153
2127 else if (!strcasecmp(arg_name, "no_discard_passdown")) 2154 else if (!strcasecmp(arg_name, "no_discard_passdown"))
2128 pf->discard_passdown = 0; 2155 pf->discard_passdown = false;
2129 2156
2130 else if (!strcasecmp(arg_name, "read_only")) 2157 else if (!strcasecmp(arg_name, "read_only"))
2131 pf->mode = PM_READ_ONLY; 2158 pf->mode = PM_READ_ONLY;
@@ -2259,8 +2286,9 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
2259 pt->metadata_dev = metadata_dev; 2286 pt->metadata_dev = metadata_dev;
2260 pt->data_dev = data_dev; 2287 pt->data_dev = data_dev;
2261 pt->low_water_blocks = low_water_blocks; 2288 pt->low_water_blocks = low_water_blocks;
2262 pt->pf = pf; 2289 pt->adjusted_pf = pt->requested_pf = pf;
2263 ti->num_flush_requests = 1; 2290 ti->num_flush_requests = 1;
2291
2264 /* 2292 /*
2265 * Only need to enable discards if the pool should pass 2293 * Only need to enable discards if the pool should pass
2266 * them down to the data device. The thin device's discard 2294 * them down to the data device. The thin device's discard
@@ -2268,12 +2296,14 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
2268 */ 2296 */
2269 if (pf.discard_enabled && pf.discard_passdown) { 2297 if (pf.discard_enabled && pf.discard_passdown) {
2270 ti->num_discard_requests = 1; 2298 ti->num_discard_requests = 1;
2299
2271 /* 2300 /*
2272 * Setting 'discards_supported' circumvents the normal 2301 * Setting 'discards_supported' circumvents the normal
2273 * stacking of discard limits (this keeps the pool and 2302 * stacking of discard limits (this keeps the pool and
2274 * thin devices' discard limits consistent). 2303 * thin devices' discard limits consistent).
2275 */ 2304 */
2276 ti->discards_supported = true; 2305 ti->discards_supported = true;
2306 ti->discard_zeroes_data_unsupported = true;
2277 } 2307 }
2278 ti->private = pt; 2308 ti->private = pt;
2279 2309
@@ -2703,7 +2733,7 @@ static int pool_status(struct dm_target *ti, status_type_t type,
2703 format_dev_t(buf2, pt->data_dev->bdev->bd_dev), 2733 format_dev_t(buf2, pt->data_dev->bdev->bd_dev),
2704 (unsigned long)pool->sectors_per_block, 2734 (unsigned long)pool->sectors_per_block,
2705 (unsigned long long)pt->low_water_blocks); 2735 (unsigned long long)pt->low_water_blocks);
2706 emit_flags(&pt->pf, result, sz, maxlen); 2736 emit_flags(&pt->requested_pf, result, sz, maxlen);
2707 break; 2737 break;
2708 } 2738 }
2709 2739
@@ -2732,20 +2762,21 @@ static int pool_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
2732 return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 2762 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
2733} 2763}
2734 2764
2735static void set_discard_limits(struct pool *pool, struct queue_limits *limits) 2765static void set_discard_limits(struct pool_c *pt, struct queue_limits *limits)
2736{ 2766{
2737 /* 2767 struct pool *pool = pt->pool;
2738 * FIXME: these limits may be incompatible with the pool's data device 2768 struct queue_limits *data_limits;
2739 */ 2769
2740 limits->max_discard_sectors = pool->sectors_per_block; 2770 limits->max_discard_sectors = pool->sectors_per_block;
2741 2771
2742 /* 2772 /*
2743 * This is just a hint, and not enforced. We have to cope with 2773 * discard_granularity is just a hint, and not enforced.
2744 * bios that cover a block partially. A discard that spans a block
2745 * boundary is not sent to this target.
2746 */ 2774 */
2747 limits->discard_granularity = pool->sectors_per_block << SECTOR_SHIFT; 2775 if (pt->adjusted_pf.discard_passdown) {
2748 limits->discard_zeroes_data = pool->pf.zero_new_blocks; 2776 data_limits = &bdev_get_queue(pt->data_dev->bdev)->limits;
2777 limits->discard_granularity = data_limits->discard_granularity;
2778 } else
2779 limits->discard_granularity = pool->sectors_per_block << SECTOR_SHIFT;
2749} 2780}
2750 2781
2751static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits) 2782static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits)
@@ -2755,15 +2786,25 @@ static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits)
2755 2786
2756 blk_limits_io_min(limits, 0); 2787 blk_limits_io_min(limits, 0);
2757 blk_limits_io_opt(limits, pool->sectors_per_block << SECTOR_SHIFT); 2788 blk_limits_io_opt(limits, pool->sectors_per_block << SECTOR_SHIFT);
2758 if (pool->pf.discard_enabled) 2789
2759 set_discard_limits(pool, limits); 2790 /*
2791 * pt->adjusted_pf is a staging area for the actual features to use.
2792 * They get transferred to the live pool in bind_control_target()
2793 * called from pool_preresume().
2794 */
2795 if (!pt->adjusted_pf.discard_enabled)
2796 return;
2797
2798 disable_passdown_if_not_supported(pt);
2799
2800 set_discard_limits(pt, limits);
2760} 2801}
2761 2802
2762static struct target_type pool_target = { 2803static struct target_type pool_target = {
2763 .name = "thin-pool", 2804 .name = "thin-pool",
2764 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE | 2805 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE |
2765 DM_TARGET_IMMUTABLE, 2806 DM_TARGET_IMMUTABLE,
2766 .version = {1, 3, 0}, 2807 .version = {1, 4, 0},
2767 .module = THIS_MODULE, 2808 .module = THIS_MODULE,
2768 .ctr = pool_ctr, 2809 .ctr = pool_ctr,
2769 .dtr = pool_dtr, 2810 .dtr = pool_dtr,
@@ -3042,19 +3083,19 @@ static int thin_iterate_devices(struct dm_target *ti,
3042 return 0; 3083 return 0;
3043} 3084}
3044 3085
3086/*
3087 * A thin device always inherits its queue limits from its pool.
3088 */
3045static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits) 3089static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits)
3046{ 3090{
3047 struct thin_c *tc = ti->private; 3091 struct thin_c *tc = ti->private;
3048 struct pool *pool = tc->pool;
3049 3092
3050 blk_limits_io_min(limits, 0); 3093 *limits = bdev_get_queue(tc->pool_dev->bdev)->limits;
3051 blk_limits_io_opt(limits, pool->sectors_per_block << SECTOR_SHIFT);
3052 set_discard_limits(pool, limits);
3053} 3094}
3054 3095
3055static struct target_type thin_target = { 3096static struct target_type thin_target = {
3056 .name = "thin", 3097 .name = "thin",
3057 .version = {1, 3, 0}, 3098 .version = {1, 4, 0},
3058 .module = THIS_MODULE, 3099 .module = THIS_MODULE,
3059 .ctr = thin_ctr, 3100 .ctr = thin_ctr,
3060 .dtr = thin_dtr, 3101 .dtr = thin_dtr,
diff --git a/drivers/md/dm-verity.c b/drivers/md/dm-verity.c
index 254d19268ad2..892ae2766aa6 100644
--- a/drivers/md/dm-verity.c
+++ b/drivers/md/dm-verity.c
@@ -718,8 +718,8 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
718 v->hash_dev_block_bits = ffs(num) - 1; 718 v->hash_dev_block_bits = ffs(num) - 1;
719 719
720 if (sscanf(argv[5], "%llu%c", &num_ll, &dummy) != 1 || 720 if (sscanf(argv[5], "%llu%c", &num_ll, &dummy) != 1 ||
721 num_ll << (v->data_dev_block_bits - SECTOR_SHIFT) != 721 (sector_t)(num_ll << (v->data_dev_block_bits - SECTOR_SHIFT))
722 (sector_t)num_ll << (v->data_dev_block_bits - SECTOR_SHIFT)) { 722 >> (v->data_dev_block_bits - SECTOR_SHIFT) != num_ll) {
723 ti->error = "Invalid data blocks"; 723 ti->error = "Invalid data blocks";
724 r = -EINVAL; 724 r = -EINVAL;
725 goto bad; 725 goto bad;
@@ -733,8 +733,8 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
733 } 733 }
734 734
735 if (sscanf(argv[6], "%llu%c", &num_ll, &dummy) != 1 || 735 if (sscanf(argv[6], "%llu%c", &num_ll, &dummy) != 1 ||
736 num_ll << (v->hash_dev_block_bits - SECTOR_SHIFT) != 736 (sector_t)(num_ll << (v->hash_dev_block_bits - SECTOR_SHIFT))
737 (sector_t)num_ll << (v->hash_dev_block_bits - SECTOR_SHIFT)) { 737 >> (v->hash_dev_block_bits - SECTOR_SHIFT) != num_ll) {
738 ti->error = "Invalid hash start"; 738 ti->error = "Invalid hash start";
739 r = -EINVAL; 739 r = -EINVAL;
740 goto bad; 740 goto bad;
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 4e09b6ff5b49..67ffa391edcf 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -865,10 +865,14 @@ static void dm_done(struct request *clone, int error, bool mapped)
865{ 865{
866 int r = error; 866 int r = error;
867 struct dm_rq_target_io *tio = clone->end_io_data; 867 struct dm_rq_target_io *tio = clone->end_io_data;
868 dm_request_endio_fn rq_end_io = tio->ti->type->rq_end_io; 868 dm_request_endio_fn rq_end_io = NULL;
869 869
870 if (mapped && rq_end_io) 870 if (tio->ti) {
871 r = rq_end_io(tio->ti, clone, error, &tio->info); 871 rq_end_io = tio->ti->type->rq_end_io;
872
873 if (mapped && rq_end_io)
874 r = rq_end_io(tio->ti, clone, error, &tio->info);
875 }
872 876
873 if (r <= 0) 877 if (r <= 0)
874 /* The target wants to complete the I/O */ 878 /* The target wants to complete the I/O */
@@ -1588,15 +1592,6 @@ static int map_request(struct dm_target *ti, struct request *clone,
1588 int r, requeued = 0; 1592 int r, requeued = 0;
1589 struct dm_rq_target_io *tio = clone->end_io_data; 1593 struct dm_rq_target_io *tio = clone->end_io_data;
1590 1594
1591 /*
1592 * Hold the md reference here for the in-flight I/O.
1593 * We can't rely on the reference count by device opener,
1594 * because the device may be closed during the request completion
1595 * when all bios are completed.
1596 * See the comment in rq_completed() too.
1597 */
1598 dm_get(md);
1599
1600 tio->ti = ti; 1595 tio->ti = ti;
1601 r = ti->type->map_rq(ti, clone, &tio->info); 1596 r = ti->type->map_rq(ti, clone, &tio->info);
1602 switch (r) { 1597 switch (r) {
@@ -1628,6 +1623,26 @@ static int map_request(struct dm_target *ti, struct request *clone,
1628 return requeued; 1623 return requeued;
1629} 1624}
1630 1625
1626static struct request *dm_start_request(struct mapped_device *md, struct request *orig)
1627{
1628 struct request *clone;
1629
1630 blk_start_request(orig);
1631 clone = orig->special;
1632 atomic_inc(&md->pending[rq_data_dir(clone)]);
1633
1634 /*
1635 * Hold the md reference here for the in-flight I/O.
1636 * We can't rely on the reference count by device opener,
1637 * because the device may be closed during the request completion
1638 * when all bios are completed.
1639 * See the comment in rq_completed() too.
1640 */
1641 dm_get(md);
1642
1643 return clone;
1644}
1645
1631/* 1646/*
1632 * q->request_fn for request-based dm. 1647 * q->request_fn for request-based dm.
1633 * Called with the queue lock held. 1648 * Called with the queue lock held.
@@ -1657,14 +1672,21 @@ static void dm_request_fn(struct request_queue *q)
1657 pos = blk_rq_pos(rq); 1672 pos = blk_rq_pos(rq);
1658 1673
1659 ti = dm_table_find_target(map, pos); 1674 ti = dm_table_find_target(map, pos);
1660 BUG_ON(!dm_target_is_valid(ti)); 1675 if (!dm_target_is_valid(ti)) {
1676 /*
1677 * Must perform setup, that dm_done() requires,
1678 * before calling dm_kill_unmapped_request
1679 */
1680 DMERR_LIMIT("request attempted access beyond the end of device");
1681 clone = dm_start_request(md, rq);
1682 dm_kill_unmapped_request(clone, -EIO);
1683 continue;
1684 }
1661 1685
1662 if (ti->type->busy && ti->type->busy(ti)) 1686 if (ti->type->busy && ti->type->busy(ti))
1663 goto delay_and_out; 1687 goto delay_and_out;
1664 1688
1665 blk_start_request(rq); 1689 clone = dm_start_request(md, rq);
1666 clone = rq->special;
1667 atomic_inc(&md->pending[rq_data_dir(clone)]);
1668 1690
1669 spin_unlock(q->queue_lock); 1691 spin_unlock(q->queue_lock);
1670 if (map_request(ti, clone, md)) 1692 if (map_request(ti, clone, md))
@@ -1684,8 +1706,6 @@ delay_and_out:
1684 blk_delay_queue(q, HZ / 10); 1706 blk_delay_queue(q, HZ / 10);
1685out: 1707out:
1686 dm_table_put(map); 1708 dm_table_put(map);
1687
1688 return;
1689} 1709}
1690 1710
1691int dm_underlying_device_busy(struct request_queue *q) 1711int dm_underlying_device_busy(struct request_queue *q)
@@ -2409,7 +2429,7 @@ static void dm_queue_flush(struct mapped_device *md)
2409 */ 2429 */
2410struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table) 2430struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table)
2411{ 2431{
2412 struct dm_table *map = ERR_PTR(-EINVAL); 2432 struct dm_table *live_map, *map = ERR_PTR(-EINVAL);
2413 struct queue_limits limits; 2433 struct queue_limits limits;
2414 int r; 2434 int r;
2415 2435
@@ -2419,6 +2439,19 @@ struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table)
2419 if (!dm_suspended_md(md)) 2439 if (!dm_suspended_md(md))
2420 goto out; 2440 goto out;
2421 2441
2442 /*
2443 * If the new table has no data devices, retain the existing limits.
2444 * This helps multipath with queue_if_no_path if all paths disappear,
2445 * then new I/O is queued based on these limits, and then some paths
2446 * reappear.
2447 */
2448 if (dm_table_has_no_data_devices(table)) {
2449 live_map = dm_get_live_table(md);
2450 if (live_map)
2451 limits = md->queue->limits;
2452 dm_table_put(live_map);
2453 }
2454
2422 r = dm_calculate_queue_limits(table, &limits); 2455 r = dm_calculate_queue_limits(table, &limits);
2423 if (r) { 2456 if (r) {
2424 map = ERR_PTR(r); 2457 map = ERR_PTR(r);
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 52eef493d266..6a99fefaa743 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -54,6 +54,7 @@ void dm_table_event_callback(struct dm_table *t,
54 void (*fn)(void *), void *context); 54 void (*fn)(void *), void *context);
55struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index); 55struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index);
56struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector); 56struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector);
57bool dm_table_has_no_data_devices(struct dm_table *table);
57int dm_calculate_queue_limits(struct dm_table *table, 58int dm_calculate_queue_limits(struct dm_table *table,
58 struct queue_limits *limits); 59 struct queue_limits *limits);
59void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, 60void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 3f6203a4c7ea..308e87b417e0 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7619,6 +7619,8 @@ static int remove_and_add_spares(struct mddev *mddev)
7619 } 7619 }
7620 } 7620 }
7621 } 7621 }
7622 if (removed)
7623 set_bit(MD_CHANGE_DEVS, &mddev->flags);
7622 return spares; 7624 return spares;
7623} 7625}
7624 7626
@@ -7632,9 +7634,11 @@ static void reap_sync_thread(struct mddev *mddev)
7632 !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { 7634 !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
7633 /* success...*/ 7635 /* success...*/
7634 /* activate any spares */ 7636 /* activate any spares */
7635 if (mddev->pers->spare_active(mddev)) 7637 if (mddev->pers->spare_active(mddev)) {
7636 sysfs_notify(&mddev->kobj, NULL, 7638 sysfs_notify(&mddev->kobj, NULL,
7637 "degraded"); 7639 "degraded");
7640 set_bit(MD_CHANGE_DEVS, &mddev->flags);
7641 }
7638 } 7642 }
7639 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && 7643 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
7640 mddev->pers->finish_reshape) 7644 mddev->pers->finish_reshape)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 1c2eb38f3c51..0138a727c1f3 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1512,14 +1512,16 @@ static int _enough(struct r10conf *conf, struct geom *geo, int ignore)
1512 do { 1512 do {
1513 int n = conf->copies; 1513 int n = conf->copies;
1514 int cnt = 0; 1514 int cnt = 0;
1515 int this = first;
1515 while (n--) { 1516 while (n--) {
1516 if (conf->mirrors[first].rdev && 1517 if (conf->mirrors[this].rdev &&
1517 first != ignore) 1518 this != ignore)
1518 cnt++; 1519 cnt++;
1519 first = (first+1) % geo->raid_disks; 1520 this = (this+1) % geo->raid_disks;
1520 } 1521 }
1521 if (cnt == 0) 1522 if (cnt == 0)
1522 return 0; 1523 return 0;
1524 first = (first + geo->near_copies) % geo->raid_disks;
1523 } while (first != 0); 1525 } while (first != 0);
1524 return 1; 1526 return 1;
1525} 1527}
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index adda94df5eb2..0689173fd9f5 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -393,6 +393,8 @@ static int calc_degraded(struct r5conf *conf)
393 degraded = 0; 393 degraded = 0;
394 for (i = 0; i < conf->previous_raid_disks; i++) { 394 for (i = 0; i < conf->previous_raid_disks; i++) {
395 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); 395 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev);
396 if (rdev && test_bit(Faulty, &rdev->flags))
397 rdev = rcu_dereference(conf->disks[i].replacement);
396 if (!rdev || test_bit(Faulty, &rdev->flags)) 398 if (!rdev || test_bit(Faulty, &rdev->flags))
397 degraded++; 399 degraded++;
398 else if (test_bit(In_sync, &rdev->flags)) 400 else if (test_bit(In_sync, &rdev->flags))
@@ -417,6 +419,8 @@ static int calc_degraded(struct r5conf *conf)
417 degraded2 = 0; 419 degraded2 = 0;
418 for (i = 0; i < conf->raid_disks; i++) { 420 for (i = 0; i < conf->raid_disks; i++) {
419 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); 421 struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev);
422 if (rdev && test_bit(Faulty, &rdev->flags))
423 rdev = rcu_dereference(conf->disks[i].replacement);
420 if (!rdev || test_bit(Faulty, &rdev->flags)) 424 if (!rdev || test_bit(Faulty, &rdev->flags))
421 degraded2++; 425 degraded2++;
422 else if (test_bit(In_sync, &rdev->flags)) 426 else if (test_bit(In_sync, &rdev->flags))
@@ -1587,6 +1591,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
1587 #ifdef CONFIG_MULTICORE_RAID456 1591 #ifdef CONFIG_MULTICORE_RAID456
1588 init_waitqueue_head(&nsh->ops.wait_for_ops); 1592 init_waitqueue_head(&nsh->ops.wait_for_ops);
1589 #endif 1593 #endif
1594 spin_lock_init(&nsh->stripe_lock);
1590 1595
1591 list_add(&nsh->lru, &newstripes); 1596 list_add(&nsh->lru, &newstripes);
1592 } 1597 }
@@ -4192,7 +4197,7 @@ static void make_request(struct mddev *mddev, struct bio * bi)
4192 finish_wait(&conf->wait_for_overlap, &w); 4197 finish_wait(&conf->wait_for_overlap, &w);
4193 set_bit(STRIPE_HANDLE, &sh->state); 4198 set_bit(STRIPE_HANDLE, &sh->state);
4194 clear_bit(STRIPE_DELAYED, &sh->state); 4199 clear_bit(STRIPE_DELAYED, &sh->state);
4195 if ((bi->bi_rw & REQ_NOIDLE) && 4200 if ((bi->bi_rw & REQ_SYNC) &&
4196 !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) 4201 !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state))
4197 atomic_inc(&conf->preread_active_stripes); 4202 atomic_inc(&conf->preread_active_stripes);
4198 release_stripe_plug(mddev, sh); 4203 release_stripe_plug(mddev, sh);
diff --git a/drivers/mfd/88pm800.c b/drivers/mfd/88pm800.c
index b67a3018b136..ce229ea933d1 100644
--- a/drivers/mfd/88pm800.c
+++ b/drivers/mfd/88pm800.c
@@ -470,7 +470,8 @@ static int __devinit device_800_init(struct pm80x_chip *chip,
470 470
471 ret = 471 ret =
472 mfd_add_devices(chip->dev, 0, &onkey_devs[0], 472 mfd_add_devices(chip->dev, 0, &onkey_devs[0],
473 ARRAY_SIZE(onkey_devs), &onkey_resources[0], 0); 473 ARRAY_SIZE(onkey_devs), &onkey_resources[0], 0,
474 NULL);
474 if (ret < 0) { 475 if (ret < 0) {
475 dev_err(chip->dev, "Failed to add onkey subdev\n"); 476 dev_err(chip->dev, "Failed to add onkey subdev\n");
476 goto out_dev; 477 goto out_dev;
@@ -481,7 +482,7 @@ static int __devinit device_800_init(struct pm80x_chip *chip,
481 rtc_devs[0].platform_data = pdata->rtc; 482 rtc_devs[0].platform_data = pdata->rtc;
482 rtc_devs[0].pdata_size = sizeof(struct pm80x_rtc_pdata); 483 rtc_devs[0].pdata_size = sizeof(struct pm80x_rtc_pdata);
483 ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], 484 ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
484 ARRAY_SIZE(rtc_devs), NULL, 0); 485 ARRAY_SIZE(rtc_devs), NULL, 0, NULL);
485 if (ret < 0) { 486 if (ret < 0) {
486 dev_err(chip->dev, "Failed to add rtc subdev\n"); 487 dev_err(chip->dev, "Failed to add rtc subdev\n");
487 goto out_dev; 488 goto out_dev;
diff --git a/drivers/mfd/88pm805.c b/drivers/mfd/88pm805.c
index 6146583589f6..c20a31136f04 100644
--- a/drivers/mfd/88pm805.c
+++ b/drivers/mfd/88pm805.c
@@ -216,7 +216,8 @@ static int __devinit device_805_init(struct pm80x_chip *chip)
216 } 216 }
217 217
218 ret = mfd_add_devices(chip->dev, 0, &codec_devs[0], 218 ret = mfd_add_devices(chip->dev, 0, &codec_devs[0],
219 ARRAY_SIZE(codec_devs), &codec_resources[0], 0); 219 ARRAY_SIZE(codec_devs), &codec_resources[0], 0,
220 NULL);
220 if (ret < 0) { 221 if (ret < 0) {
221 dev_err(chip->dev, "Failed to add codec subdev\n"); 222 dev_err(chip->dev, "Failed to add codec subdev\n");
222 goto out_codec; 223 goto out_codec;
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index d09918cf1b15..b73f033b2c60 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -637,7 +637,7 @@ static void __devinit device_bk_init(struct pm860x_chip *chip,
637 bk_devs[i].resources = &bk_resources[j]; 637 bk_devs[i].resources = &bk_resources[j];
638 ret = mfd_add_devices(chip->dev, 0, 638 ret = mfd_add_devices(chip->dev, 0,
639 &bk_devs[i], 1, 639 &bk_devs[i], 1,
640 &bk_resources[j], 0); 640 &bk_resources[j], 0, NULL);
641 if (ret < 0) { 641 if (ret < 0) {
642 dev_err(chip->dev, "Failed to add " 642 dev_err(chip->dev, "Failed to add "
643 "backlight subdev\n"); 643 "backlight subdev\n");
@@ -672,7 +672,7 @@ static void __devinit device_led_init(struct pm860x_chip *chip,
672 led_devs[i].resources = &led_resources[j], 672 led_devs[i].resources = &led_resources[j],
673 ret = mfd_add_devices(chip->dev, 0, 673 ret = mfd_add_devices(chip->dev, 0,
674 &led_devs[i], 1, 674 &led_devs[i], 1,
675 &led_resources[j], 0); 675 &led_resources[j], 0, NULL);
676 if (ret < 0) { 676 if (ret < 0) {
677 dev_err(chip->dev, "Failed to add " 677 dev_err(chip->dev, "Failed to add "
678 "led subdev\n"); 678 "led subdev\n");
@@ -709,7 +709,7 @@ static void __devinit device_regulator_init(struct pm860x_chip *chip,
709 regulator_devs[i].resources = &regulator_resources[seq]; 709 regulator_devs[i].resources = &regulator_resources[seq];
710 710
711 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[i], 1, 711 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[i], 1,
712 &regulator_resources[seq], 0); 712 &regulator_resources[seq], 0, NULL);
713 if (ret < 0) { 713 if (ret < 0) {
714 dev_err(chip->dev, "Failed to add regulator subdev\n"); 714 dev_err(chip->dev, "Failed to add regulator subdev\n");
715 goto out; 715 goto out;
@@ -733,7 +733,7 @@ static void __devinit device_rtc_init(struct pm860x_chip *chip,
733 rtc_devs[0].resources = &rtc_resources[0]; 733 rtc_devs[0].resources = &rtc_resources[0];
734 ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], 734 ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
735 ARRAY_SIZE(rtc_devs), &rtc_resources[0], 735 ARRAY_SIZE(rtc_devs), &rtc_resources[0],
736 chip->irq_base); 736 chip->irq_base, NULL);
737 if (ret < 0) 737 if (ret < 0)
738 dev_err(chip->dev, "Failed to add rtc subdev\n"); 738 dev_err(chip->dev, "Failed to add rtc subdev\n");
739} 739}
@@ -752,7 +752,7 @@ static void __devinit device_touch_init(struct pm860x_chip *chip,
752 touch_devs[0].resources = &touch_resources[0]; 752 touch_devs[0].resources = &touch_resources[0];
753 ret = mfd_add_devices(chip->dev, 0, &touch_devs[0], 753 ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
754 ARRAY_SIZE(touch_devs), &touch_resources[0], 754 ARRAY_SIZE(touch_devs), &touch_resources[0],
755 chip->irq_base); 755 chip->irq_base, NULL);
756 if (ret < 0) 756 if (ret < 0)
757 dev_err(chip->dev, "Failed to add touch subdev\n"); 757 dev_err(chip->dev, "Failed to add touch subdev\n");
758} 758}
@@ -770,7 +770,7 @@ static void __devinit device_power_init(struct pm860x_chip *chip,
770 power_devs[0].num_resources = ARRAY_SIZE(battery_resources); 770 power_devs[0].num_resources = ARRAY_SIZE(battery_resources);
771 power_devs[0].resources = &battery_resources[0], 771 power_devs[0].resources = &battery_resources[0],
772 ret = mfd_add_devices(chip->dev, 0, &power_devs[0], 1, 772 ret = mfd_add_devices(chip->dev, 0, &power_devs[0], 1,
773 &battery_resources[0], chip->irq_base); 773 &battery_resources[0], chip->irq_base, NULL);
774 if (ret < 0) 774 if (ret < 0)
775 dev_err(chip->dev, "Failed to add battery subdev\n"); 775 dev_err(chip->dev, "Failed to add battery subdev\n");
776 776
@@ -779,7 +779,7 @@ static void __devinit device_power_init(struct pm860x_chip *chip,
779 power_devs[1].num_resources = ARRAY_SIZE(charger_resources); 779 power_devs[1].num_resources = ARRAY_SIZE(charger_resources);
780 power_devs[1].resources = &charger_resources[0], 780 power_devs[1].resources = &charger_resources[0],
781 ret = mfd_add_devices(chip->dev, 0, &power_devs[1], 1, 781 ret = mfd_add_devices(chip->dev, 0, &power_devs[1], 1,
782 &charger_resources[0], chip->irq_base); 782 &charger_resources[0], chip->irq_base, NULL);
783 if (ret < 0) 783 if (ret < 0)
784 dev_err(chip->dev, "Failed to add charger subdev\n"); 784 dev_err(chip->dev, "Failed to add charger subdev\n");
785 785
@@ -788,7 +788,7 @@ static void __devinit device_power_init(struct pm860x_chip *chip,
788 power_devs[2].num_resources = ARRAY_SIZE(preg_resources); 788 power_devs[2].num_resources = ARRAY_SIZE(preg_resources);
789 power_devs[2].resources = &preg_resources[0], 789 power_devs[2].resources = &preg_resources[0],
790 ret = mfd_add_devices(chip->dev, 0, &power_devs[2], 1, 790 ret = mfd_add_devices(chip->dev, 0, &power_devs[2], 1,
791 &preg_resources[0], chip->irq_base); 791 &preg_resources[0], chip->irq_base, NULL);
792 if (ret < 0) 792 if (ret < 0)
793 dev_err(chip->dev, "Failed to add preg subdev\n"); 793 dev_err(chip->dev, "Failed to add preg subdev\n");
794} 794}
@@ -802,7 +802,7 @@ static void __devinit device_onkey_init(struct pm860x_chip *chip,
802 onkey_devs[0].resources = &onkey_resources[0], 802 onkey_devs[0].resources = &onkey_resources[0],
803 ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0], 803 ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
804 ARRAY_SIZE(onkey_devs), &onkey_resources[0], 804 ARRAY_SIZE(onkey_devs), &onkey_resources[0],
805 chip->irq_base); 805 chip->irq_base, NULL);
806 if (ret < 0) 806 if (ret < 0)
807 dev_err(chip->dev, "Failed to add onkey subdev\n"); 807 dev_err(chip->dev, "Failed to add onkey subdev\n");
808} 808}
@@ -815,7 +815,8 @@ static void __devinit device_codec_init(struct pm860x_chip *chip,
815 codec_devs[0].num_resources = ARRAY_SIZE(codec_resources); 815 codec_devs[0].num_resources = ARRAY_SIZE(codec_resources);
816 codec_devs[0].resources = &codec_resources[0], 816 codec_devs[0].resources = &codec_resources[0],
817 ret = mfd_add_devices(chip->dev, 0, &codec_devs[0], 817 ret = mfd_add_devices(chip->dev, 0, &codec_devs[0],
818 ARRAY_SIZE(codec_devs), &codec_resources[0], 0); 818 ARRAY_SIZE(codec_devs), &codec_resources[0], 0,
819 NULL);
819 if (ret < 0) 820 if (ret < 0)
820 dev_err(chip->dev, "Failed to add codec subdev\n"); 821 dev_err(chip->dev, "Failed to add codec subdev\n");
821} 822}
diff --git a/drivers/mfd/aat2870-core.c b/drivers/mfd/aat2870-core.c
index 44a3fdbadef4..f1beb4971f87 100644
--- a/drivers/mfd/aat2870-core.c
+++ b/drivers/mfd/aat2870-core.c
@@ -424,7 +424,7 @@ static int aat2870_i2c_probe(struct i2c_client *client,
424 } 424 }
425 425
426 ret = mfd_add_devices(aat2870->dev, 0, aat2870_devs, 426 ret = mfd_add_devices(aat2870->dev, 0, aat2870_devs,
427 ARRAY_SIZE(aat2870_devs), NULL, 0); 427 ARRAY_SIZE(aat2870_devs), NULL, 0, NULL);
428 if (ret != 0) { 428 if (ret != 0) {
429 dev_err(aat2870->dev, "Failed to add subdev: %d\n", ret); 429 dev_err(aat2870->dev, "Failed to add subdev: %d\n", ret);
430 goto out_disable; 430 goto out_disable;
diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
index 78fca2902c8d..01781ae5d0d7 100644
--- a/drivers/mfd/ab3100-core.c
+++ b/drivers/mfd/ab3100-core.c
@@ -946,7 +946,7 @@ static int __devinit ab3100_probe(struct i2c_client *client,
946 } 946 }
947 947
948 err = mfd_add_devices(&client->dev, 0, ab3100_devs, 948 err = mfd_add_devices(&client->dev, 0, ab3100_devs,
949 ARRAY_SIZE(ab3100_devs), NULL, 0); 949 ARRAY_SIZE(ab3100_devs), NULL, 0, NULL);
950 950
951 ab3100_setup_debugfs(ab3100); 951 ab3100_setup_debugfs(ab3100);
952 952
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 626b4ecaf647..47adf800024e 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -1418,25 +1418,25 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1418 1418
1419 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs, 1419 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs,
1420 ARRAY_SIZE(abx500_common_devs), NULL, 1420 ARRAY_SIZE(abx500_common_devs), NULL,
1421 ab8500->irq_base); 1421 ab8500->irq_base, ab8500->domain);
1422 if (ret) 1422 if (ret)
1423 goto out_freeirq; 1423 goto out_freeirq;
1424 1424
1425 if (is_ab9540(ab8500)) 1425 if (is_ab9540(ab8500))
1426 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, 1426 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
1427 ARRAY_SIZE(ab9540_devs), NULL, 1427 ARRAY_SIZE(ab9540_devs), NULL,
1428 ab8500->irq_base); 1428 ab8500->irq_base, ab8500->domain);
1429 else 1429 else
1430 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, 1430 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
1431 ARRAY_SIZE(ab8500_devs), NULL, 1431 ARRAY_SIZE(ab8500_devs), NULL,
1432 ab8500->irq_base); 1432 ab8500->irq_base, ab8500->domain);
1433 if (ret) 1433 if (ret)
1434 goto out_freeirq; 1434 goto out_freeirq;
1435 1435
1436 if (is_ab9540(ab8500) || is_ab8505(ab8500)) 1436 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1437 ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs, 1437 ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs,
1438 ARRAY_SIZE(ab9540_ab8505_devs), NULL, 1438 ARRAY_SIZE(ab9540_ab8505_devs), NULL,
1439 ab8500->irq_base); 1439 ab8500->irq_base, ab8500->domain);
1440 if (ret) 1440 if (ret)
1441 goto out_freeirq; 1441 goto out_freeirq;
1442 1442
@@ -1444,7 +1444,7 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1444 /* Add battery management devices */ 1444 /* Add battery management devices */
1445 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs, 1445 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
1446 ARRAY_SIZE(ab8500_bm_devs), NULL, 1446 ARRAY_SIZE(ab8500_bm_devs), NULL,
1447 ab8500->irq_base); 1447 ab8500->irq_base, ab8500->domain);
1448 if (ret) 1448 if (ret)
1449 dev_err(ab8500->dev, "error adding bm devices\n"); 1449 dev_err(ab8500->dev, "error adding bm devices\n");
1450 } 1450 }
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index 866f95960b4b..29d72a259c85 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -342,7 +342,7 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
342 342
343 /* 343 /*
344 * Delay might be needed for ABB8500 cut 3.0, if not, remove 344 * Delay might be needed for ABB8500 cut 3.0, if not, remove
345 * when hardware will be availible 345 * when hardware will be available
346 */ 346 */
347 msleep(1); 347 msleep(1);
348 break; 348 break;
diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index c7983e862549..1b48f2094806 100644
--- a/drivers/mfd/arizona-core.c
+++ b/drivers/mfd/arizona-core.c
@@ -316,7 +316,7 @@ int __devinit arizona_dev_init(struct arizona *arizona)
316 } 316 }
317 317
318 ret = mfd_add_devices(arizona->dev, -1, early_devs, 318 ret = mfd_add_devices(arizona->dev, -1, early_devs,
319 ARRAY_SIZE(early_devs), NULL, 0); 319 ARRAY_SIZE(early_devs), NULL, 0, NULL);
320 if (ret != 0) { 320 if (ret != 0) {
321 dev_err(dev, "Failed to add early children: %d\n", ret); 321 dev_err(dev, "Failed to add early children: %d\n", ret);
322 return ret; 322 return ret;
@@ -516,11 +516,11 @@ int __devinit arizona_dev_init(struct arizona *arizona)
516 switch (arizona->type) { 516 switch (arizona->type) {
517 case WM5102: 517 case WM5102:
518 ret = mfd_add_devices(arizona->dev, -1, wm5102_devs, 518 ret = mfd_add_devices(arizona->dev, -1, wm5102_devs,
519 ARRAY_SIZE(wm5102_devs), NULL, 0); 519 ARRAY_SIZE(wm5102_devs), NULL, 0, NULL);
520 break; 520 break;
521 case WM5110: 521 case WM5110:
522 ret = mfd_add_devices(arizona->dev, -1, wm5110_devs, 522 ret = mfd_add_devices(arizona->dev, -1, wm5110_devs,
523 ARRAY_SIZE(wm5102_devs), NULL, 0); 523 ARRAY_SIZE(wm5102_devs), NULL, 0, NULL);
524 break; 524 break;
525 } 525 }
526 526
diff --git a/drivers/mfd/asic3.c b/drivers/mfd/asic3.c
index 683e18a23329..62f0883a7630 100644
--- a/drivers/mfd/asic3.c
+++ b/drivers/mfd/asic3.c
@@ -913,14 +913,14 @@ static int __init asic3_mfd_probe(struct platform_device *pdev,
913 if (pdata->clock_rate) { 913 if (pdata->clock_rate) {
914 ds1wm_pdata.clock_rate = pdata->clock_rate; 914 ds1wm_pdata.clock_rate = pdata->clock_rate;
915 ret = mfd_add_devices(&pdev->dev, pdev->id, 915 ret = mfd_add_devices(&pdev->dev, pdev->id,
916 &asic3_cell_ds1wm, 1, mem, asic->irq_base); 916 &asic3_cell_ds1wm, 1, mem, asic->irq_base, NULL);
917 if (ret < 0) 917 if (ret < 0)
918 goto out; 918 goto out;
919 } 919 }
920 920
921 if (mem_sdio && (irq >= 0)) { 921 if (mem_sdio && (irq >= 0)) {
922 ret = mfd_add_devices(&pdev->dev, pdev->id, 922 ret = mfd_add_devices(&pdev->dev, pdev->id,
923 &asic3_cell_mmc, 1, mem_sdio, irq); 923 &asic3_cell_mmc, 1, mem_sdio, irq, NULL);
924 if (ret < 0) 924 if (ret < 0)
925 goto out; 925 goto out;
926 } 926 }
@@ -934,7 +934,7 @@ static int __init asic3_mfd_probe(struct platform_device *pdev,
934 asic3_cell_leds[i].pdata_size = sizeof(pdata->leds[i]); 934 asic3_cell_leds[i].pdata_size = sizeof(pdata->leds[i]);
935 } 935 }
936 ret = mfd_add_devices(&pdev->dev, 0, 936 ret = mfd_add_devices(&pdev->dev, 0,
937 asic3_cell_leds, ASIC3_NUM_LEDS, NULL, 0); 937 asic3_cell_leds, ASIC3_NUM_LEDS, NULL, 0, NULL);
938 } 938 }
939 939
940 out: 940 out:
diff --git a/drivers/mfd/cs5535-mfd.c b/drivers/mfd/cs5535-mfd.c
index 3419e726de47..2b282133c725 100644
--- a/drivers/mfd/cs5535-mfd.c
+++ b/drivers/mfd/cs5535-mfd.c
@@ -149,7 +149,7 @@ static int __devinit cs5535_mfd_probe(struct pci_dev *pdev,
149 } 149 }
150 150
151 err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells, 151 err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells,
152 ARRAY_SIZE(cs5535_mfd_cells), NULL, 0); 152 ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL);
153 if (err) { 153 if (err) {
154 dev_err(&pdev->dev, "MFD add devices failed: %d\n", err); 154 dev_err(&pdev->dev, "MFD add devices failed: %d\n", err);
155 goto err_disable; 155 goto err_disable;
diff --git a/drivers/mfd/da9052-core.c b/drivers/mfd/da9052-core.c
index 2544910e1fd6..a0a62b24621b 100644
--- a/drivers/mfd/da9052-core.c
+++ b/drivers/mfd/da9052-core.c
@@ -803,7 +803,7 @@ int __devinit da9052_device_init(struct da9052 *da9052, u8 chip_id)
803 dev_err(da9052->dev, "DA9052 ADC IRQ failed ret=%d\n", ret); 803 dev_err(da9052->dev, "DA9052 ADC IRQ failed ret=%d\n", ret);
804 804
805 ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info, 805 ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info,
806 ARRAY_SIZE(da9052_subdev_info), NULL, 0); 806 ARRAY_SIZE(da9052_subdev_info), NULL, 0, NULL);
807 if (ret) 807 if (ret)
808 goto err; 808 goto err;
809 809
diff --git a/drivers/mfd/davinci_voicecodec.c b/drivers/mfd/davinci_voicecodec.c
index 4e2af2cb2d26..45e83a68641b 100644
--- a/drivers/mfd/davinci_voicecodec.c
+++ b/drivers/mfd/davinci_voicecodec.c
@@ -129,7 +129,7 @@ static int __init davinci_vc_probe(struct platform_device *pdev)
129 cell->pdata_size = sizeof(*davinci_vc); 129 cell->pdata_size = sizeof(*davinci_vc);
130 130
131 ret = mfd_add_devices(&pdev->dev, pdev->id, davinci_vc->cells, 131 ret = mfd_add_devices(&pdev->dev, pdev->id, davinci_vc->cells,
132 DAVINCI_VC_CELLS, NULL, 0); 132 DAVINCI_VC_CELLS, NULL, 0, NULL);
133 if (ret != 0) { 133 if (ret != 0) {
134 dev_err(&pdev->dev, "fail to register client devices\n"); 134 dev_err(&pdev->dev, "fail to register client devices\n");
135 goto fail4; 135 goto fail4;
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index 7040a0081130..0e63cdd9b52a 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -3010,7 +3010,7 @@ static int __devinit db8500_prcmu_probe(struct platform_device *pdev)
3010 prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET); 3010 prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET);
3011 3011
3012 err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs, 3012 err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs,
3013 ARRAY_SIZE(db8500_prcmu_devs), NULL, 0); 3013 ARRAY_SIZE(db8500_prcmu_devs), NULL, 0, NULL);
3014 if (err) { 3014 if (err) {
3015 pr_err("prcmu: Failed to add subdevices\n"); 3015 pr_err("prcmu: Failed to add subdevices\n");
3016 return err; 3016 return err;
diff --git a/drivers/mfd/htc-pasic3.c b/drivers/mfd/htc-pasic3.c
index 04c7093d6499..9e5453d21a68 100644
--- a/drivers/mfd/htc-pasic3.c
+++ b/drivers/mfd/htc-pasic3.c
@@ -168,7 +168,7 @@ static int __init pasic3_probe(struct platform_device *pdev)
168 /* the first 5 PASIC3 registers control the DS1WM */ 168 /* the first 5 PASIC3 registers control the DS1WM */
169 ds1wm_resources[0].end = (5 << asic->bus_shift) - 1; 169 ds1wm_resources[0].end = (5 << asic->bus_shift) - 1;
170 ret = mfd_add_devices(&pdev->dev, pdev->id, 170 ret = mfd_add_devices(&pdev->dev, pdev->id,
171 &ds1wm_cell, 1, r, irq); 171 &ds1wm_cell, 1, r, irq, NULL);
172 if (ret < 0) 172 if (ret < 0)
173 dev_warn(dev, "failed to register DS1WM\n"); 173 dev_warn(dev, "failed to register DS1WM\n");
174 } 174 }
@@ -176,7 +176,8 @@ static int __init pasic3_probe(struct platform_device *pdev)
176 if (pdata && pdata->led_pdata) { 176 if (pdata && pdata->led_pdata) {
177 led_cell.platform_data = pdata->led_pdata; 177 led_cell.platform_data = pdata->led_pdata;
178 led_cell.pdata_size = sizeof(struct pasic3_leds_machinfo); 178 led_cell.pdata_size = sizeof(struct pasic3_leds_machinfo);
179 ret = mfd_add_devices(&pdev->dev, pdev->id, &led_cell, 1, r, 0); 179 ret = mfd_add_devices(&pdev->dev, pdev->id, &led_cell, 1, r,
180 0, NULL);
180 if (ret < 0) 181 if (ret < 0)
181 dev_warn(dev, "failed to register LED device\n"); 182 dev_warn(dev, "failed to register LED device\n");
182 } 183 }
diff --git a/drivers/mfd/intel_msic.c b/drivers/mfd/intel_msic.c
index 59df5584cb58..266bdc5bd96d 100644
--- a/drivers/mfd/intel_msic.c
+++ b/drivers/mfd/intel_msic.c
@@ -344,13 +344,13 @@ static int __devinit intel_msic_init_devices(struct intel_msic *msic)
344 continue; 344 continue;
345 345
346 ret = mfd_add_devices(&pdev->dev, -1, &msic_devs[i], 1, NULL, 346 ret = mfd_add_devices(&pdev->dev, -1, &msic_devs[i], 1, NULL,
347 pdata->irq[i]); 347 pdata->irq[i], NULL);
348 if (ret) 348 if (ret)
349 goto fail; 349 goto fail;
350 } 350 }
351 351
352 ret = mfd_add_devices(&pdev->dev, 0, msic_other_devs, 352 ret = mfd_add_devices(&pdev->dev, 0, msic_other_devs,
353 ARRAY_SIZE(msic_other_devs), NULL, 0); 353 ARRAY_SIZE(msic_other_devs), NULL, 0, NULL);
354 if (ret) 354 if (ret)
355 goto fail; 355 goto fail;
356 356
diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
index 2ea99989551a..965c4801df8a 100644
--- a/drivers/mfd/janz-cmodio.c
+++ b/drivers/mfd/janz-cmodio.c
@@ -147,7 +147,7 @@ static int __devinit cmodio_probe_submodules(struct cmodio_device *priv)
147 } 147 }
148 148
149 return mfd_add_devices(&pdev->dev, 0, priv->cells, 149 return mfd_add_devices(&pdev->dev, 0, priv->cells,
150 num_probed, NULL, pdev->irq); 150 num_probed, NULL, pdev->irq, NULL);
151} 151}
152 152
153/* 153/*
diff --git a/drivers/mfd/jz4740-adc.c b/drivers/mfd/jz4740-adc.c
index 87662a17dec6..c6b6d7dda517 100644
--- a/drivers/mfd/jz4740-adc.c
+++ b/drivers/mfd/jz4740-adc.c
@@ -287,7 +287,8 @@ static int __devinit jz4740_adc_probe(struct platform_device *pdev)
287 writeb(0xff, adc->base + JZ_REG_ADC_CTRL); 287 writeb(0xff, adc->base + JZ_REG_ADC_CTRL);
288 288
289 ret = mfd_add_devices(&pdev->dev, 0, jz4740_adc_cells, 289 ret = mfd_add_devices(&pdev->dev, 0, jz4740_adc_cells,
290 ARRAY_SIZE(jz4740_adc_cells), mem_base, irq_base); 290 ARRAY_SIZE(jz4740_adc_cells), mem_base,
291 irq_base, NULL);
291 if (ret < 0) 292 if (ret < 0)
292 goto err_clk_put; 293 goto err_clk_put;
293 294
diff --git a/drivers/mfd/lm3533-core.c b/drivers/mfd/lm3533-core.c
index 0b2879b87fd9..24212f45b201 100644
--- a/drivers/mfd/lm3533-core.c
+++ b/drivers/mfd/lm3533-core.c
@@ -393,7 +393,8 @@ static int __devinit lm3533_device_als_init(struct lm3533 *lm3533)
393 lm3533_als_devs[0].platform_data = pdata->als; 393 lm3533_als_devs[0].platform_data = pdata->als;
394 lm3533_als_devs[0].pdata_size = sizeof(*pdata->als); 394 lm3533_als_devs[0].pdata_size = sizeof(*pdata->als);
395 395
396 ret = mfd_add_devices(lm3533->dev, 0, lm3533_als_devs, 1, NULL, 0); 396 ret = mfd_add_devices(lm3533->dev, 0, lm3533_als_devs, 1, NULL,
397 0, NULL);
397 if (ret) { 398 if (ret) {
398 dev_err(lm3533->dev, "failed to add ALS device\n"); 399 dev_err(lm3533->dev, "failed to add ALS device\n");
399 return ret; 400 return ret;
@@ -422,7 +423,7 @@ static int __devinit lm3533_device_bl_init(struct lm3533 *lm3533)
422 } 423 }
423 424
424 ret = mfd_add_devices(lm3533->dev, 0, lm3533_bl_devs, 425 ret = mfd_add_devices(lm3533->dev, 0, lm3533_bl_devs,
425 pdata->num_backlights, NULL, 0); 426 pdata->num_backlights, NULL, 0, NULL);
426 if (ret) { 427 if (ret) {
427 dev_err(lm3533->dev, "failed to add backlight devices\n"); 428 dev_err(lm3533->dev, "failed to add backlight devices\n");
428 return ret; 429 return ret;
@@ -451,7 +452,7 @@ static int __devinit lm3533_device_led_init(struct lm3533 *lm3533)
451 } 452 }
452 453
453 ret = mfd_add_devices(lm3533->dev, 0, lm3533_led_devs, 454 ret = mfd_add_devices(lm3533->dev, 0, lm3533_led_devs,
454 pdata->num_leds, NULL, 0); 455 pdata->num_leds, NULL, 0, NULL);
455 if (ret) { 456 if (ret) {
456 dev_err(lm3533->dev, "failed to add LED devices\n"); 457 dev_err(lm3533->dev, "failed to add LED devices\n");
457 return ret; 458 return ret;
diff --git a/drivers/mfd/lpc_ich.c b/drivers/mfd/lpc_ich.c
index 027cc8f86132..092ad4b44b6d 100644
--- a/drivers/mfd/lpc_ich.c
+++ b/drivers/mfd/lpc_ich.c
@@ -750,7 +750,7 @@ gpe0_done:
750 750
751 lpc_ich_finalize_cell(&lpc_ich_cells[LPC_GPIO], id); 751 lpc_ich_finalize_cell(&lpc_ich_cells[LPC_GPIO], id);
752 ret = mfd_add_devices(&dev->dev, -1, &lpc_ich_cells[LPC_GPIO], 752 ret = mfd_add_devices(&dev->dev, -1, &lpc_ich_cells[LPC_GPIO],
753 1, NULL, 0); 753 1, NULL, 0, NULL);
754 754
755gpio_done: 755gpio_done:
756 if (acpi_conflict) 756 if (acpi_conflict)
@@ -765,7 +765,6 @@ static int __devinit lpc_ich_init_wdt(struct pci_dev *dev,
765 u32 base_addr_cfg; 765 u32 base_addr_cfg;
766 u32 base_addr; 766 u32 base_addr;
767 int ret; 767 int ret;
768 bool acpi_conflict = false;
769 struct resource *res; 768 struct resource *res;
770 769
771 /* Setup power management base register */ 770 /* Setup power management base register */
@@ -780,20 +779,11 @@ static int __devinit lpc_ich_init_wdt(struct pci_dev *dev,
780 res = wdt_io_res(ICH_RES_IO_TCO); 779 res = wdt_io_res(ICH_RES_IO_TCO);
781 res->start = base_addr + ACPIBASE_TCO_OFF; 780 res->start = base_addr + ACPIBASE_TCO_OFF;
782 res->end = base_addr + ACPIBASE_TCO_END; 781 res->end = base_addr + ACPIBASE_TCO_END;
783 ret = acpi_check_resource_conflict(res);
784 if (ret) {
785 acpi_conflict = true;
786 goto wdt_done;
787 }
788 782
789 res = wdt_io_res(ICH_RES_IO_SMI); 783 res = wdt_io_res(ICH_RES_IO_SMI);
790 res->start = base_addr + ACPIBASE_SMI_OFF; 784 res->start = base_addr + ACPIBASE_SMI_OFF;
791 res->end = base_addr + ACPIBASE_SMI_END; 785 res->end = base_addr + ACPIBASE_SMI_END;
792 ret = acpi_check_resource_conflict(res); 786
793 if (ret) {
794 acpi_conflict = true;
795 goto wdt_done;
796 }
797 lpc_ich_enable_acpi_space(dev); 787 lpc_ich_enable_acpi_space(dev);
798 788
799 /* 789 /*
@@ -813,21 +803,13 @@ static int __devinit lpc_ich_init_wdt(struct pci_dev *dev,
813 res = wdt_mem_res(ICH_RES_MEM_GCS); 803 res = wdt_mem_res(ICH_RES_MEM_GCS);
814 res->start = base_addr + ACPIBASE_GCS_OFF; 804 res->start = base_addr + ACPIBASE_GCS_OFF;
815 res->end = base_addr + ACPIBASE_GCS_END; 805 res->end = base_addr + ACPIBASE_GCS_END;
816 ret = acpi_check_resource_conflict(res);
817 if (ret) {
818 acpi_conflict = true;
819 goto wdt_done;
820 }
821 } 806 }
822 807
823 lpc_ich_finalize_cell(&lpc_ich_cells[LPC_WDT], id); 808 lpc_ich_finalize_cell(&lpc_ich_cells[LPC_WDT], id);
824 ret = mfd_add_devices(&dev->dev, -1, &lpc_ich_cells[LPC_WDT], 809 ret = mfd_add_devices(&dev->dev, -1, &lpc_ich_cells[LPC_WDT],
825 1, NULL, 0); 810 1, NULL, 0, NULL);
826 811
827wdt_done: 812wdt_done:
828 if (acpi_conflict)
829 pr_warn("Resource conflict(s) found affecting %s\n",
830 lpc_ich_cells[LPC_WDT].name);
831 return ret; 813 return ret;
832} 814}
833 815
diff --git a/drivers/mfd/lpc_sch.c b/drivers/mfd/lpc_sch.c
index 9f20abc5e393..f6b9c5c96b24 100644
--- a/drivers/mfd/lpc_sch.c
+++ b/drivers/mfd/lpc_sch.c
@@ -127,7 +127,8 @@ static int __devinit lpc_sch_probe(struct pci_dev *dev,
127 lpc_sch_cells[i].id = id->device; 127 lpc_sch_cells[i].id = id->device;
128 128
129 ret = mfd_add_devices(&dev->dev, 0, 129 ret = mfd_add_devices(&dev->dev, 0,
130 lpc_sch_cells, ARRAY_SIZE(lpc_sch_cells), NULL, 0); 130 lpc_sch_cells, ARRAY_SIZE(lpc_sch_cells), NULL,
131 0, NULL);
131 if (ret) 132 if (ret)
132 goto out_dev; 133 goto out_dev;
133 134
@@ -153,7 +154,8 @@ static int __devinit lpc_sch_probe(struct pci_dev *dev,
153 tunnelcreek_cells[i].id = id->device; 154 tunnelcreek_cells[i].id = id->device;
154 155
155 ret = mfd_add_devices(&dev->dev, 0, tunnelcreek_cells, 156 ret = mfd_add_devices(&dev->dev, 0, tunnelcreek_cells,
156 ARRAY_SIZE(tunnelcreek_cells), NULL, 0); 157 ARRAY_SIZE(tunnelcreek_cells), NULL,
158 0, NULL);
157 } 159 }
158 160
159 return ret; 161 return ret;
diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index c03e12b51924..d9e24c849a00 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -126,7 +126,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
126 max77686_irq_init(max77686); 126 max77686_irq_init(max77686);
127 127
128 ret = mfd_add_devices(max77686->dev, -1, max77686_devs, 128 ret = mfd_add_devices(max77686->dev, -1, max77686_devs,
129 ARRAY_SIZE(max77686_devs), NULL, 0); 129 ARRAY_SIZE(max77686_devs), NULL, 0, NULL);
130 130
131 if (ret < 0) 131 if (ret < 0)
132 goto err_mfd; 132 goto err_mfd;
diff --git a/drivers/mfd/max77693-irq.c b/drivers/mfd/max77693-irq.c
index 2b403569e0a6..1029d018c739 100644
--- a/drivers/mfd/max77693-irq.c
+++ b/drivers/mfd/max77693-irq.c
@@ -137,6 +137,9 @@ static void max77693_irq_mask(struct irq_data *data)
137 const struct max77693_irq_data *irq_data = 137 const struct max77693_irq_data *irq_data =
138 irq_to_max77693_irq(max77693, data->irq); 138 irq_to_max77693_irq(max77693, data->irq);
139 139
140 if (irq_data->group >= MAX77693_IRQ_GROUP_NR)
141 return;
142
140 if (irq_data->group >= MUIC_INT1 && irq_data->group <= MUIC_INT3) 143 if (irq_data->group >= MUIC_INT1 && irq_data->group <= MUIC_INT3)
141 max77693->irq_masks_cur[irq_data->group] &= ~irq_data->mask; 144 max77693->irq_masks_cur[irq_data->group] &= ~irq_data->mask;
142 else 145 else
@@ -149,6 +152,9 @@ static void max77693_irq_unmask(struct irq_data *data)
149 const struct max77693_irq_data *irq_data = 152 const struct max77693_irq_data *irq_data =
150 irq_to_max77693_irq(max77693, data->irq); 153 irq_to_max77693_irq(max77693, data->irq);
151 154
155 if (irq_data->group >= MAX77693_IRQ_GROUP_NR)
156 return;
157
152 if (irq_data->group >= MUIC_INT1 && irq_data->group <= MUIC_INT3) 158 if (irq_data->group >= MUIC_INT1 && irq_data->group <= MUIC_INT3)
153 max77693->irq_masks_cur[irq_data->group] |= irq_data->mask; 159 max77693->irq_masks_cur[irq_data->group] |= irq_data->mask;
154 else 160 else
@@ -200,7 +206,7 @@ static irqreturn_t max77693_irq_thread(int irq, void *data)
200 206
201 if (irq_src & MAX77693_IRQSRC_MUIC) 207 if (irq_src & MAX77693_IRQSRC_MUIC)
202 /* MUIC INT1 ~ INT3 */ 208 /* MUIC INT1 ~ INT3 */
203 max77693_bulk_read(max77693->regmap, MAX77693_MUIC_REG_INT1, 209 max77693_bulk_read(max77693->regmap_muic, MAX77693_MUIC_REG_INT1,
204 MAX77693_NUM_IRQ_MUIC_REGS, &irq_reg[MUIC_INT1]); 210 MAX77693_NUM_IRQ_MUIC_REGS, &irq_reg[MUIC_INT1]);
205 211
206 /* Apply masking */ 212 /* Apply masking */
@@ -255,7 +261,8 @@ int max77693_irq_init(struct max77693_dev *max77693)
255{ 261{
256 struct irq_domain *domain; 262 struct irq_domain *domain;
257 int i; 263 int i;
258 int ret; 264 int ret = 0;
265 u8 intsrc_mask;
259 266
260 mutex_init(&max77693->irqlock); 267 mutex_init(&max77693->irqlock);
261 268
@@ -287,19 +294,38 @@ int max77693_irq_init(struct max77693_dev *max77693)
287 &max77693_irq_domain_ops, max77693); 294 &max77693_irq_domain_ops, max77693);
288 if (!domain) { 295 if (!domain) {
289 dev_err(max77693->dev, "could not create irq domain\n"); 296 dev_err(max77693->dev, "could not create irq domain\n");
290 return -ENODEV; 297 ret = -ENODEV;
298 goto err_irq;
291 } 299 }
292 max77693->irq_domain = domain; 300 max77693->irq_domain = domain;
293 301
302 /* Unmask max77693 interrupt */
303 ret = max77693_read_reg(max77693->regmap,
304 MAX77693_PMIC_REG_INTSRC_MASK, &intsrc_mask);
305 if (ret < 0) {
306 dev_err(max77693->dev, "fail to read PMIC register\n");
307 goto err_irq;
308 }
309
310 intsrc_mask &= ~(MAX77693_IRQSRC_CHG);
311 intsrc_mask &= ~(MAX77693_IRQSRC_FLASH);
312 intsrc_mask &= ~(MAX77693_IRQSRC_MUIC);
313 ret = max77693_write_reg(max77693->regmap,
314 MAX77693_PMIC_REG_INTSRC_MASK, intsrc_mask);
315 if (ret < 0) {
316 dev_err(max77693->dev, "fail to write PMIC register\n");
317 goto err_irq;
318 }
319
294 ret = request_threaded_irq(max77693->irq, NULL, max77693_irq_thread, 320 ret = request_threaded_irq(max77693->irq, NULL, max77693_irq_thread,
295 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 321 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
296 "max77693-irq", max77693); 322 "max77693-irq", max77693);
297
298 if (ret) 323 if (ret)
299 dev_err(max77693->dev, "Failed to request IRQ %d: %d\n", 324 dev_err(max77693->dev, "Failed to request IRQ %d: %d\n",
300 max77693->irq, ret); 325 max77693->irq, ret);
301 326
302 return 0; 327err_irq:
328 return ret;
303} 329}
304 330
305void max77693_irq_exit(struct max77693_dev *max77693) 331void max77693_irq_exit(struct max77693_dev *max77693)
diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c
index a1811cb50ec7..cc5155e20494 100644
--- a/drivers/mfd/max77693.c
+++ b/drivers/mfd/max77693.c
@@ -152,6 +152,20 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
152 max77693->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); 152 max77693->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC);
153 i2c_set_clientdata(max77693->haptic, max77693); 153 i2c_set_clientdata(max77693->haptic, max77693);
154 154
155 /*
156 * Initialize register map for MUIC device because use regmap-muic
157 * instance of MUIC device when irq of max77693 is initialized
158 * before call max77693-muic probe() function.
159 */
160 max77693->regmap_muic = devm_regmap_init_i2c(max77693->muic,
161 &max77693_regmap_config);
162 if (IS_ERR(max77693->regmap_muic)) {
163 ret = PTR_ERR(max77693->regmap_muic);
164 dev_err(max77693->dev,
165 "failed to allocate register map: %d\n", ret);
166 goto err_regmap;
167 }
168
155 ret = max77693_irq_init(max77693); 169 ret = max77693_irq_init(max77693);
156 if (ret < 0) 170 if (ret < 0)
157 goto err_irq; 171 goto err_irq;
@@ -159,7 +173,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
159 pm_runtime_set_active(max77693->dev); 173 pm_runtime_set_active(max77693->dev);
160 174
161 ret = mfd_add_devices(max77693->dev, -1, max77693_devs, 175 ret = mfd_add_devices(max77693->dev, -1, max77693_devs,
162 ARRAY_SIZE(max77693_devs), NULL, 0); 176 ARRAY_SIZE(max77693_devs), NULL, 0, NULL);
163 if (ret < 0) 177 if (ret < 0)
164 goto err_mfd; 178 goto err_mfd;
165 179
diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c
index 825a7f06d9ba..ee53757beca7 100644
--- a/drivers/mfd/max8925-core.c
+++ b/drivers/mfd/max8925-core.c
@@ -598,7 +598,7 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
598 598
599 ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], 599 ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
600 ARRAY_SIZE(rtc_devs), 600 ARRAY_SIZE(rtc_devs),
601 &rtc_resources[0], chip->irq_base); 601 &rtc_resources[0], chip->irq_base, NULL);
602 if (ret < 0) { 602 if (ret < 0) {
603 dev_err(chip->dev, "Failed to add rtc subdev\n"); 603 dev_err(chip->dev, "Failed to add rtc subdev\n");
604 goto out; 604 goto out;
@@ -606,7 +606,7 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
606 606
607 ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0], 607 ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
608 ARRAY_SIZE(onkey_devs), 608 ARRAY_SIZE(onkey_devs),
609 &onkey_resources[0], 0); 609 &onkey_resources[0], 0, NULL);
610 if (ret < 0) { 610 if (ret < 0) {
611 dev_err(chip->dev, "Failed to add onkey subdev\n"); 611 dev_err(chip->dev, "Failed to add onkey subdev\n");
612 goto out_dev; 612 goto out_dev;
@@ -615,7 +615,7 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
615 if (pdata) { 615 if (pdata) {
616 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0], 616 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
617 ARRAY_SIZE(regulator_devs), 617 ARRAY_SIZE(regulator_devs),
618 &regulator_resources[0], 0); 618 &regulator_resources[0], 0, NULL);
619 if (ret < 0) { 619 if (ret < 0) {
620 dev_err(chip->dev, "Failed to add regulator subdev\n"); 620 dev_err(chip->dev, "Failed to add regulator subdev\n");
621 goto out_dev; 621 goto out_dev;
@@ -625,7 +625,7 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
625 if (pdata && pdata->backlight) { 625 if (pdata && pdata->backlight) {
626 ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0], 626 ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
627 ARRAY_SIZE(backlight_devs), 627 ARRAY_SIZE(backlight_devs),
628 &backlight_resources[0], 0); 628 &backlight_resources[0], 0, NULL);
629 if (ret < 0) { 629 if (ret < 0) {
630 dev_err(chip->dev, "Failed to add backlight subdev\n"); 630 dev_err(chip->dev, "Failed to add backlight subdev\n");
631 goto out_dev; 631 goto out_dev;
@@ -635,7 +635,7 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
635 if (pdata && pdata->power) { 635 if (pdata && pdata->power) {
636 ret = mfd_add_devices(chip->dev, 0, &power_devs[0], 636 ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
637 ARRAY_SIZE(power_devs), 637 ARRAY_SIZE(power_devs),
638 &power_supply_resources[0], 0); 638 &power_supply_resources[0], 0, NULL);
639 if (ret < 0) { 639 if (ret < 0) {
640 dev_err(chip->dev, "Failed to add power supply " 640 dev_err(chip->dev, "Failed to add power supply "
641 "subdev\n"); 641 "subdev\n");
@@ -646,7 +646,7 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
646 if (pdata && pdata->touch) { 646 if (pdata && pdata->touch) {
647 ret = mfd_add_devices(chip->dev, 0, &touch_devs[0], 647 ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
648 ARRAY_SIZE(touch_devs), 648 ARRAY_SIZE(touch_devs),
649 &touch_resources[0], 0); 649 &touch_resources[0], 0, NULL);
650 if (ret < 0) { 650 if (ret < 0) {
651 dev_err(chip->dev, "Failed to add touch subdev\n"); 651 dev_err(chip->dev, "Failed to add touch subdev\n");
652 goto out_dev; 652 goto out_dev;
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
index 10b629c245b6..f123517065ec 100644
--- a/drivers/mfd/max8997.c
+++ b/drivers/mfd/max8997.c
@@ -160,7 +160,7 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
160 160
161 mfd_add_devices(max8997->dev, -1, max8997_devs, 161 mfd_add_devices(max8997->dev, -1, max8997_devs,
162 ARRAY_SIZE(max8997_devs), 162 ARRAY_SIZE(max8997_devs),
163 NULL, 0); 163 NULL, 0, NULL);
164 164
165 /* 165 /*
166 * TODO: enable others (flash, muic, rtc, battery, ...) and 166 * TODO: enable others (flash, muic, rtc, battery, ...) and
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c
index 6ef56d28c056..d7218cc90945 100644
--- a/drivers/mfd/max8998.c
+++ b/drivers/mfd/max8998.c
@@ -161,13 +161,13 @@ static int max8998_i2c_probe(struct i2c_client *i2c,
161 switch (id->driver_data) { 161 switch (id->driver_data) {
162 case TYPE_LP3974: 162 case TYPE_LP3974:
163 ret = mfd_add_devices(max8998->dev, -1, 163 ret = mfd_add_devices(max8998->dev, -1,
164 lp3974_devs, ARRAY_SIZE(lp3974_devs), 164 lp3974_devs, ARRAY_SIZE(lp3974_devs),
165 NULL, 0); 165 NULL, 0, NULL);
166 break; 166 break;
167 case TYPE_MAX8998: 167 case TYPE_MAX8998:
168 ret = mfd_add_devices(max8998->dev, -1, 168 ret = mfd_add_devices(max8998->dev, -1,
169 max8998_devs, ARRAY_SIZE(max8998_devs), 169 max8998_devs, ARRAY_SIZE(max8998_devs),
170 NULL, 0); 170 NULL, 0, NULL);
171 break; 171 break;
172 default: 172 default:
173 ret = -EINVAL; 173 ret = -EINVAL;
diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index b801dc72f041..1ec79b54bd2f 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -612,7 +612,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
612 if (!cell.name) 612 if (!cell.name)
613 return -ENOMEM; 613 return -ENOMEM;
614 614
615 return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0); 615 return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0, NULL);
616} 616}
617 617
618static int mc13xxx_add_subdevice(struct mc13xxx *mc13xxx, const char *format) 618static int mc13xxx_add_subdevice(struct mc13xxx *mc13xxx, const char *format)
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 0c3a01cde2f7..f8b77711ad2d 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -74,12 +74,11 @@ static int mfd_platform_add_cell(struct platform_device *pdev,
74static int mfd_add_device(struct device *parent, int id, 74static int mfd_add_device(struct device *parent, int id,
75 const struct mfd_cell *cell, 75 const struct mfd_cell *cell,
76 struct resource *mem_base, 76 struct resource *mem_base,
77 int irq_base) 77 int irq_base, struct irq_domain *domain)
78{ 78{
79 struct resource *res; 79 struct resource *res;
80 struct platform_device *pdev; 80 struct platform_device *pdev;
81 struct device_node *np = NULL; 81 struct device_node *np = NULL;
82 struct irq_domain *domain = NULL;
83 int ret = -ENOMEM; 82 int ret = -ENOMEM;
84 int r; 83 int r;
85 84
@@ -97,7 +96,6 @@ static int mfd_add_device(struct device *parent, int id,
97 for_each_child_of_node(parent->of_node, np) { 96 for_each_child_of_node(parent->of_node, np) {
98 if (of_device_is_compatible(np, cell->of_compatible)) { 97 if (of_device_is_compatible(np, cell->of_compatible)) {
99 pdev->dev.of_node = np; 98 pdev->dev.of_node = np;
100 domain = irq_find_host(parent->of_node);
101 break; 99 break;
102 } 100 }
103 } 101 }
@@ -177,7 +175,7 @@ fail_alloc:
177int mfd_add_devices(struct device *parent, int id, 175int mfd_add_devices(struct device *parent, int id,
178 struct mfd_cell *cells, int n_devs, 176 struct mfd_cell *cells, int n_devs,
179 struct resource *mem_base, 177 struct resource *mem_base,
180 int irq_base) 178 int irq_base, struct irq_domain *domain)
181{ 179{
182 int i; 180 int i;
183 int ret = 0; 181 int ret = 0;
@@ -191,7 +189,8 @@ int mfd_add_devices(struct device *parent, int id,
191 for (i = 0; i < n_devs; i++) { 189 for (i = 0; i < n_devs; i++) {
192 atomic_set(&cnts[i], 0); 190 atomic_set(&cnts[i], 0);
193 cells[i].usage_count = &cnts[i]; 191 cells[i].usage_count = &cnts[i];
194 ret = mfd_add_device(parent, id, cells + i, mem_base, irq_base); 192 ret = mfd_add_device(parent, id, cells + i, mem_base,
193 irq_base, domain);
195 if (ret) 194 if (ret)
196 break; 195 break;
197 } 196 }
@@ -247,7 +246,8 @@ int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones)
247 for (i = 0; i < n_clones; i++) { 246 for (i = 0; i < n_clones; i++) {
248 cell_entry.name = clones[i]; 247 cell_entry.name = clones[i];
249 /* don't give up if a single call fails; just report error */ 248 /* don't give up if a single call fails; just report error */
250 if (mfd_add_device(pdev->dev.parent, -1, &cell_entry, NULL, 0)) 249 if (mfd_add_device(pdev->dev.parent, -1, &cell_entry, NULL, 0,
250 NULL))
251 dev_err(dev, "failed to create platform device '%s'\n", 251 dev_err(dev, "failed to create platform device '%s'\n",
252 clones[i]); 252 clones[i]);
253 } 253 }
diff --git a/drivers/mfd/palmas.c b/drivers/mfd/palmas.c
index c4a69f193a1d..a345f9bb7b47 100644
--- a/drivers/mfd/palmas.c
+++ b/drivers/mfd/palmas.c
@@ -453,7 +453,8 @@ static int __devinit palmas_i2c_probe(struct i2c_client *i2c,
453 453
454 ret = mfd_add_devices(palmas->dev, -1, 454 ret = mfd_add_devices(palmas->dev, -1,
455 children, ARRAY_SIZE(palmas_children), 455 children, ARRAY_SIZE(palmas_children),
456 NULL, regmap_irq_chip_get_base(palmas->irq_data)); 456 NULL, regmap_irq_chip_get_base(palmas->irq_data),
457 NULL);
457 kfree(children); 458 kfree(children);
458 459
459 if (ret < 0) 460 if (ret < 0)
diff --git a/drivers/mfd/rc5t583.c b/drivers/mfd/rc5t583.c
index cdc1df7fa0e9..ff61efc76ce2 100644
--- a/drivers/mfd/rc5t583.c
+++ b/drivers/mfd/rc5t583.c
@@ -281,7 +281,7 @@ static int __devinit rc5t583_i2c_probe(struct i2c_client *i2c,
281 281
282 if (i2c->irq) { 282 if (i2c->irq) {
283 ret = rc5t583_irq_init(rc5t583, i2c->irq, pdata->irq_base); 283 ret = rc5t583_irq_init(rc5t583, i2c->irq, pdata->irq_base);
284 /* Still continue with waring if irq init fails */ 284 /* Still continue with warning, if irq init fails */
285 if (ret) 285 if (ret)
286 dev_warn(&i2c->dev, "IRQ init failed: %d\n", ret); 286 dev_warn(&i2c->dev, "IRQ init failed: %d\n", ret);
287 else 287 else
@@ -289,7 +289,7 @@ static int __devinit rc5t583_i2c_probe(struct i2c_client *i2c,
289 } 289 }
290 290
291 ret = mfd_add_devices(rc5t583->dev, -1, rc5t583_subdevs, 291 ret = mfd_add_devices(rc5t583->dev, -1, rc5t583_subdevs,
292 ARRAY_SIZE(rc5t583_subdevs), NULL, 0); 292 ARRAY_SIZE(rc5t583_subdevs), NULL, 0, NULL);
293 if (ret) { 293 if (ret) {
294 dev_err(&i2c->dev, "add mfd devices failed: %d\n", ret); 294 dev_err(&i2c->dev, "add mfd devices failed: %d\n", ret);
295 goto err_add_devs; 295 goto err_add_devs;
diff --git a/drivers/mfd/rdc321x-southbridge.c b/drivers/mfd/rdc321x-southbridge.c
index 685d61e431ad..fbabc3cbe350 100644
--- a/drivers/mfd/rdc321x-southbridge.c
+++ b/drivers/mfd/rdc321x-southbridge.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * RDC321x MFD southbrige driver 2 * RDC321x MFD southbridge driver
3 * 3 *
4 * Copyright (C) 2007-2010 Florian Fainelli <florian@openwrt.org> 4 * Copyright (C) 2007-2010 Florian Fainelli <florian@openwrt.org>
5 * Copyright (C) 2010 Bernhard Loos <bernhardloos@googlemail.com> 5 * Copyright (C) 2010 Bernhard Loos <bernhardloos@googlemail.com>
@@ -87,7 +87,8 @@ static int __devinit rdc321x_sb_probe(struct pci_dev *pdev,
87 rdc321x_wdt_pdata.sb_pdev = pdev; 87 rdc321x_wdt_pdata.sb_pdev = pdev;
88 88
89 return mfd_add_devices(&pdev->dev, -1, 89 return mfd_add_devices(&pdev->dev, -1,
90 rdc321x_sb_cells, ARRAY_SIZE(rdc321x_sb_cells), NULL, 0); 90 rdc321x_sb_cells, ARRAY_SIZE(rdc321x_sb_cells),
91 NULL, 0, NULL);
91} 92}
92 93
93static void __devexit rdc321x_sb_remove(struct pci_dev *pdev) 94static void __devexit rdc321x_sb_remove(struct pci_dev *pdev)
diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
index 2988efde11eb..49d361a618d0 100644
--- a/drivers/mfd/sec-core.c
+++ b/drivers/mfd/sec-core.c
@@ -141,19 +141,19 @@ static int sec_pmic_probe(struct i2c_client *i2c,
141 switch (sec_pmic->device_type) { 141 switch (sec_pmic->device_type) {
142 case S5M8751X: 142 case S5M8751X:
143 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8751_devs, 143 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8751_devs,
144 ARRAY_SIZE(s5m8751_devs), NULL, 0); 144 ARRAY_SIZE(s5m8751_devs), NULL, 0, NULL);
145 break; 145 break;
146 case S5M8763X: 146 case S5M8763X:
147 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8763_devs, 147 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8763_devs,
148 ARRAY_SIZE(s5m8763_devs), NULL, 0); 148 ARRAY_SIZE(s5m8763_devs), NULL, 0, NULL);
149 break; 149 break;
150 case S5M8767X: 150 case S5M8767X:
151 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8767_devs, 151 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8767_devs,
152 ARRAY_SIZE(s5m8767_devs), NULL, 0); 152 ARRAY_SIZE(s5m8767_devs), NULL, 0, NULL);
153 break; 153 break;
154 case S2MPS11X: 154 case S2MPS11X:
155 ret = mfd_add_devices(sec_pmic->dev, -1, s2mps11_devs, 155 ret = mfd_add_devices(sec_pmic->dev, -1, s2mps11_devs,
156 ARRAY_SIZE(s2mps11_devs), NULL, 0); 156 ARRAY_SIZE(s2mps11_devs), NULL, 0, NULL);
157 break; 157 break;
158 default: 158 default:
159 /* If this happens the probe function is problem */ 159 /* If this happens the probe function is problem */
diff --git a/drivers/mfd/sta2x11-mfd.c b/drivers/mfd/sta2x11-mfd.c
index d31fed07aefb..d35da6820bea 100644
--- a/drivers/mfd/sta2x11-mfd.c
+++ b/drivers/mfd/sta2x11-mfd.c
@@ -407,7 +407,7 @@ static int __devinit sta2x11_mfd_probe(struct pci_dev *pdev,
407 sta2x11_mfd_bar0, 407 sta2x11_mfd_bar0,
408 ARRAY_SIZE(sta2x11_mfd_bar0), 408 ARRAY_SIZE(sta2x11_mfd_bar0),
409 &pdev->resource[0], 409 &pdev->resource[0],
410 0); 410 0, NULL);
411 if (err) { 411 if (err) {
412 dev_err(&pdev->dev, "mfd_add_devices[0] failed: %d\n", err); 412 dev_err(&pdev->dev, "mfd_add_devices[0] failed: %d\n", err);
413 goto err_disable; 413 goto err_disable;
@@ -417,7 +417,7 @@ static int __devinit sta2x11_mfd_probe(struct pci_dev *pdev,
417 sta2x11_mfd_bar1, 417 sta2x11_mfd_bar1,
418 ARRAY_SIZE(sta2x11_mfd_bar1), 418 ARRAY_SIZE(sta2x11_mfd_bar1),
419 &pdev->resource[1], 419 &pdev->resource[1],
420 0); 420 0, NULL);
421 if (err) { 421 if (err) {
422 dev_err(&pdev->dev, "mfd_add_devices[1] failed: %d\n", err); 422 dev_err(&pdev->dev, "mfd_add_devices[1] failed: %d\n", err);
423 goto err_disable; 423 goto err_disable;
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index 2dd8d49cb30b..c94f521f392c 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -962,7 +962,7 @@ static int __devinit stmpe_add_device(struct stmpe *stmpe,
962 struct mfd_cell *cell, int irq) 962 struct mfd_cell *cell, int irq)
963{ 963{
964 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, 964 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1,
965 NULL, stmpe->irq_base + irq); 965 NULL, stmpe->irq_base + irq, NULL);
966} 966}
967 967
968static int __devinit stmpe_devices_init(struct stmpe *stmpe) 968static int __devinit stmpe_devices_init(struct stmpe *stmpe)
diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c
index 2d9e8799e733..b32940ec9034 100644
--- a/drivers/mfd/t7l66xb.c
+++ b/drivers/mfd/t7l66xb.c
@@ -388,7 +388,7 @@ static int t7l66xb_probe(struct platform_device *dev)
388 388
389 ret = mfd_add_devices(&dev->dev, dev->id, 389 ret = mfd_add_devices(&dev->dev, dev->id,
390 t7l66xb_cells, ARRAY_SIZE(t7l66xb_cells), 390 t7l66xb_cells, ARRAY_SIZE(t7l66xb_cells),
391 iomem, t7l66xb->irq_base); 391 iomem, t7l66xb->irq_base, NULL);
392 392
393 if (!ret) 393 if (!ret)
394 return 0; 394 return 0;
diff --git a/drivers/mfd/tc3589x.c b/drivers/mfd/tc3589x.c
index 048bf0532a09..b56ba6b43294 100644
--- a/drivers/mfd/tc3589x.c
+++ b/drivers/mfd/tc3589x.c
@@ -262,8 +262,8 @@ static int __devinit tc3589x_device_init(struct tc3589x *tc3589x)
262 262
263 if (blocks & TC3589x_BLOCK_GPIO) { 263 if (blocks & TC3589x_BLOCK_GPIO) {
264 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio, 264 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio,
265 ARRAY_SIZE(tc3589x_dev_gpio), NULL, 265 ARRAY_SIZE(tc3589x_dev_gpio), NULL,
266 tc3589x->irq_base); 266 tc3589x->irq_base, NULL);
267 if (ret) { 267 if (ret) {
268 dev_err(tc3589x->dev, "failed to add gpio child\n"); 268 dev_err(tc3589x->dev, "failed to add gpio child\n");
269 return ret; 269 return ret;
@@ -273,8 +273,8 @@ static int __devinit tc3589x_device_init(struct tc3589x *tc3589x)
273 273
274 if (blocks & TC3589x_BLOCK_KEYPAD) { 274 if (blocks & TC3589x_BLOCK_KEYPAD) {
275 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_keypad, 275 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_keypad,
276 ARRAY_SIZE(tc3589x_dev_keypad), NULL, 276 ARRAY_SIZE(tc3589x_dev_keypad), NULL,
277 tc3589x->irq_base); 277 tc3589x->irq_base, NULL);
278 if (ret) { 278 if (ret) {
279 dev_err(tc3589x->dev, "failed to keypad child\n"); 279 dev_err(tc3589x->dev, "failed to keypad child\n");
280 return ret; 280 return ret;
diff --git a/drivers/mfd/tc6387xb.c b/drivers/mfd/tc6387xb.c
index d20a284ad4ba..413c891102f8 100644
--- a/drivers/mfd/tc6387xb.c
+++ b/drivers/mfd/tc6387xb.c
@@ -192,7 +192,7 @@ static int __devinit tc6387xb_probe(struct platform_device *dev)
192 printk(KERN_INFO "Toshiba tc6387xb initialised\n"); 192 printk(KERN_INFO "Toshiba tc6387xb initialised\n");
193 193
194 ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells, 194 ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
195 ARRAY_SIZE(tc6387xb_cells), iomem, irq); 195 ARRAY_SIZE(tc6387xb_cells), iomem, irq, NULL);
196 196
197 if (!ret) 197 if (!ret)
198 return 0; 198 return 0;
diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
index 9612264f0e6d..dcab026fcbb2 100644
--- a/drivers/mfd/tc6393xb.c
+++ b/drivers/mfd/tc6393xb.c
@@ -700,8 +700,8 @@ static int __devinit tc6393xb_probe(struct platform_device *dev)
700 tc6393xb_cells[TC6393XB_CELL_FB].pdata_size = sizeof(*tcpd->fb_data); 700 tc6393xb_cells[TC6393XB_CELL_FB].pdata_size = sizeof(*tcpd->fb_data);
701 701
702 ret = mfd_add_devices(&dev->dev, dev->id, 702 ret = mfd_add_devices(&dev->dev, dev->id,
703 tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells), 703 tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells),
704 iomem, tcpd->irq_base); 704 iomem, tcpd->irq_base, NULL);
705 705
706 if (!ret) 706 if (!ret)
707 return 0; 707 return 0;
diff --git a/drivers/mfd/ti-ssp.c b/drivers/mfd/ti-ssp.c
index 4fb0e6c8e8fe..7c3675a74f93 100644
--- a/drivers/mfd/ti-ssp.c
+++ b/drivers/mfd/ti-ssp.c
@@ -412,7 +412,7 @@ static int __devinit ti_ssp_probe(struct platform_device *pdev)
412 cells[id].data_size = data->pdata_size; 412 cells[id].data_size = data->pdata_size;
413 } 413 }
414 414
415 error = mfd_add_devices(dev, 0, cells, 2, NULL, 0); 415 error = mfd_add_devices(dev, 0, cells, 2, NULL, 0, NULL);
416 if (error < 0) { 416 if (error < 0) {
417 dev_err(dev, "cannot add mfd cells\n"); 417 dev_err(dev, "cannot add mfd cells\n");
418 goto error_enable; 418 goto error_enable;
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c
index a447f4ec11fb..cccc626c83c8 100644
--- a/drivers/mfd/timberdale.c
+++ b/drivers/mfd/timberdale.c
@@ -757,25 +757,25 @@ static int __devinit timb_probe(struct pci_dev *dev,
757 err = mfd_add_devices(&dev->dev, -1, 757 err = mfd_add_devices(&dev->dev, -1,
758 timberdale_cells_bar0_cfg0, 758 timberdale_cells_bar0_cfg0,
759 ARRAY_SIZE(timberdale_cells_bar0_cfg0), 759 ARRAY_SIZE(timberdale_cells_bar0_cfg0),
760 &dev->resource[0], msix_entries[0].vector); 760 &dev->resource[0], msix_entries[0].vector, NULL);
761 break; 761 break;
762 case TIMB_HW_VER1: 762 case TIMB_HW_VER1:
763 err = mfd_add_devices(&dev->dev, -1, 763 err = mfd_add_devices(&dev->dev, -1,
764 timberdale_cells_bar0_cfg1, 764 timberdale_cells_bar0_cfg1,
765 ARRAY_SIZE(timberdale_cells_bar0_cfg1), 765 ARRAY_SIZE(timberdale_cells_bar0_cfg1),
766 &dev->resource[0], msix_entries[0].vector); 766 &dev->resource[0], msix_entries[0].vector, NULL);
767 break; 767 break;
768 case TIMB_HW_VER2: 768 case TIMB_HW_VER2:
769 err = mfd_add_devices(&dev->dev, -1, 769 err = mfd_add_devices(&dev->dev, -1,
770 timberdale_cells_bar0_cfg2, 770 timberdale_cells_bar0_cfg2,
771 ARRAY_SIZE(timberdale_cells_bar0_cfg2), 771 ARRAY_SIZE(timberdale_cells_bar0_cfg2),
772 &dev->resource[0], msix_entries[0].vector); 772 &dev->resource[0], msix_entries[0].vector, NULL);
773 break; 773 break;
774 case TIMB_HW_VER3: 774 case TIMB_HW_VER3:
775 err = mfd_add_devices(&dev->dev, -1, 775 err = mfd_add_devices(&dev->dev, -1,
776 timberdale_cells_bar0_cfg3, 776 timberdale_cells_bar0_cfg3,
777 ARRAY_SIZE(timberdale_cells_bar0_cfg3), 777 ARRAY_SIZE(timberdale_cells_bar0_cfg3),
778 &dev->resource[0], msix_entries[0].vector); 778 &dev->resource[0], msix_entries[0].vector, NULL);
779 break; 779 break;
780 default: 780 default:
781 dev_err(&dev->dev, "Uknown IP setup: %d.%d.%d\n", 781 dev_err(&dev->dev, "Uknown IP setup: %d.%d.%d\n",
@@ -792,7 +792,7 @@ static int __devinit timb_probe(struct pci_dev *dev,
792 792
793 err = mfd_add_devices(&dev->dev, 0, 793 err = mfd_add_devices(&dev->dev, 0,
794 timberdale_cells_bar1, ARRAY_SIZE(timberdale_cells_bar1), 794 timberdale_cells_bar1, ARRAY_SIZE(timberdale_cells_bar1),
795 &dev->resource[1], msix_entries[0].vector); 795 &dev->resource[1], msix_entries[0].vector, NULL);
796 if (err) { 796 if (err) {
797 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err); 797 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
798 goto err_mfd2; 798 goto err_mfd2;
@@ -803,7 +803,7 @@ static int __devinit timb_probe(struct pci_dev *dev,
803 ((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER3)) { 803 ((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER3)) {
804 err = mfd_add_devices(&dev->dev, 1, timberdale_cells_bar2, 804 err = mfd_add_devices(&dev->dev, 1, timberdale_cells_bar2,
805 ARRAY_SIZE(timberdale_cells_bar2), 805 ARRAY_SIZE(timberdale_cells_bar2),
806 &dev->resource[2], msix_entries[0].vector); 806 &dev->resource[2], msix_entries[0].vector, NULL);
807 if (err) { 807 if (err) {
808 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err); 808 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
809 goto err_mfd2; 809 goto err_mfd2;
diff --git a/drivers/mfd/tps6105x.c b/drivers/mfd/tps6105x.c
index a293b978e27c..14051bdc714b 100644
--- a/drivers/mfd/tps6105x.c
+++ b/drivers/mfd/tps6105x.c
@@ -188,7 +188,7 @@ static int __devinit tps6105x_probe(struct i2c_client *client,
188 } 188 }
189 189
190 ret = mfd_add_devices(&client->dev, 0, tps6105x_cells, 190 ret = mfd_add_devices(&client->dev, 0, tps6105x_cells,
191 ARRAY_SIZE(tps6105x_cells), NULL, 0); 191 ARRAY_SIZE(tps6105x_cells), NULL, 0, NULL);
192 if (ret) 192 if (ret)
193 goto fail; 193 goto fail;
194 194
diff --git a/drivers/mfd/tps6507x.c b/drivers/mfd/tps6507x.c
index 33ba7723c967..1b203499c744 100644
--- a/drivers/mfd/tps6507x.c
+++ b/drivers/mfd/tps6507x.c
@@ -100,7 +100,7 @@ static int tps6507x_i2c_probe(struct i2c_client *i2c,
100 100
101 ret = mfd_add_devices(tps6507x->dev, -1, 101 ret = mfd_add_devices(tps6507x->dev, -1,
102 tps6507x_devs, ARRAY_SIZE(tps6507x_devs), 102 tps6507x_devs, ARRAY_SIZE(tps6507x_devs),
103 NULL, 0); 103 NULL, 0, NULL);
104 104
105 if (ret < 0) 105 if (ret < 0)
106 goto err; 106 goto err;
diff --git a/drivers/mfd/tps65090.c b/drivers/mfd/tps65090.c
index 80e24f4b47bf..50fd87c87a1c 100644
--- a/drivers/mfd/tps65090.c
+++ b/drivers/mfd/tps65090.c
@@ -292,7 +292,7 @@ static int __devinit tps65090_i2c_probe(struct i2c_client *client,
292 } 292 }
293 293
294 ret = mfd_add_devices(tps65090->dev, -1, tps65090s, 294 ret = mfd_add_devices(tps65090->dev, -1, tps65090s,
295 ARRAY_SIZE(tps65090s), NULL, 0); 295 ARRAY_SIZE(tps65090s), NULL, 0, NULL);
296 if (ret) { 296 if (ret) {
297 dev_err(&client->dev, "add mfd devices failed with err: %d\n", 297 dev_err(&client->dev, "add mfd devices failed with err: %d\n",
298 ret); 298 ret);
diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c
index 61c097a98f5d..a95e9421b735 100644
--- a/drivers/mfd/tps65217.c
+++ b/drivers/mfd/tps65217.c
@@ -24,11 +24,18 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/regmap.h> 25#include <linux/regmap.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/regulator/of_regulator.h> 27#include <linux/of.h>
28#include <linux/of_device.h>
28 29
29#include <linux/mfd/core.h> 30#include <linux/mfd/core.h>
30#include <linux/mfd/tps65217.h> 31#include <linux/mfd/tps65217.h>
31 32
33static struct mfd_cell tps65217s[] = {
34 {
35 .name = "tps65217-pmic",
36 },
37};
38
32/** 39/**
33 * tps65217_reg_read: Read a single tps65217 register. 40 * tps65217_reg_read: Read a single tps65217 register.
34 * 41 *
@@ -133,83 +140,48 @@ int tps65217_clear_bits(struct tps65217 *tps, unsigned int reg,
133} 140}
134EXPORT_SYMBOL_GPL(tps65217_clear_bits); 141EXPORT_SYMBOL_GPL(tps65217_clear_bits);
135 142
136#ifdef CONFIG_OF
137static struct of_regulator_match reg_matches[] = {
138 { .name = "dcdc1", .driver_data = (void *)TPS65217_DCDC_1 },
139 { .name = "dcdc2", .driver_data = (void *)TPS65217_DCDC_2 },
140 { .name = "dcdc3", .driver_data = (void *)TPS65217_DCDC_3 },
141 { .name = "ldo1", .driver_data = (void *)TPS65217_LDO_1 },
142 { .name = "ldo2", .driver_data = (void *)TPS65217_LDO_2 },
143 { .name = "ldo3", .driver_data = (void *)TPS65217_LDO_3 },
144 { .name = "ldo4", .driver_data = (void *)TPS65217_LDO_4 },
145};
146
147static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client)
148{
149 struct device_node *node = client->dev.of_node;
150 struct tps65217_board *pdata;
151 struct device_node *regs;
152 int count = ARRAY_SIZE(reg_matches);
153 int ret, i;
154
155 regs = of_find_node_by_name(node, "regulators");
156 if (!regs)
157 return NULL;
158
159 ret = of_regulator_match(&client->dev, regs, reg_matches, count);
160 of_node_put(regs);
161 if ((ret < 0) || (ret > count))
162 return NULL;
163
164 count = ret;
165 pdata = devm_kzalloc(&client->dev, count * sizeof(*pdata), GFP_KERNEL);
166 if (!pdata)
167 return NULL;
168
169 for (i = 0; i < count; i++) {
170 if (!reg_matches[i].init_data || !reg_matches[i].of_node)
171 continue;
172
173 pdata->tps65217_init_data[i] = reg_matches[i].init_data;
174 pdata->of_node[i] = reg_matches[i].of_node;
175 }
176
177 return pdata;
178}
179
180static struct of_device_id tps65217_of_match[] = {
181 { .compatible = "ti,tps65217", },
182 { },
183};
184#else
185static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client)
186{
187 return NULL;
188}
189#endif
190
191static struct regmap_config tps65217_regmap_config = { 143static struct regmap_config tps65217_regmap_config = {
192 .reg_bits = 8, 144 .reg_bits = 8,
193 .val_bits = 8, 145 .val_bits = 8,
194}; 146};
195 147
148static const struct of_device_id tps65217_of_match[] = {
149 { .compatible = "ti,tps65217", .data = (void *)TPS65217 },
150 { /* sentinel */ },
151};
152
196static int __devinit tps65217_probe(struct i2c_client *client, 153static int __devinit tps65217_probe(struct i2c_client *client,
197 const struct i2c_device_id *ids) 154 const struct i2c_device_id *ids)
198{ 155{
199 struct tps65217 *tps; 156 struct tps65217 *tps;
200 struct regulator_init_data *reg_data;
201 struct tps65217_board *pdata = client->dev.platform_data;
202 int i, ret;
203 unsigned int version; 157 unsigned int version;
158 unsigned int chip_id = ids->driver_data;
159 const struct of_device_id *match;
160 int ret;
204 161
205 if (!pdata && client->dev.of_node) 162 if (client->dev.of_node) {
206 pdata = tps65217_parse_dt(client); 163 match = of_match_device(tps65217_of_match, &client->dev);
164 if (!match) {
165 dev_err(&client->dev,
166 "Failed to find matching dt id\n");
167 return -EINVAL;
168 }
169 chip_id = (unsigned int)match->data;
170 }
171
172 if (!chip_id) {
173 dev_err(&client->dev, "id is null.\n");
174 return -ENODEV;
175 }
207 176
208 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 177 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
209 if (!tps) 178 if (!tps)
210 return -ENOMEM; 179 return -ENOMEM;
211 180
212 tps->pdata = pdata; 181 i2c_set_clientdata(client, tps);
182 tps->dev = &client->dev;
183 tps->id = chip_id;
184
213 tps->regmap = devm_regmap_init_i2c(client, &tps65217_regmap_config); 185 tps->regmap = devm_regmap_init_i2c(client, &tps65217_regmap_config);
214 if (IS_ERR(tps->regmap)) { 186 if (IS_ERR(tps->regmap)) {
215 ret = PTR_ERR(tps->regmap); 187 ret = PTR_ERR(tps->regmap);
@@ -218,8 +190,12 @@ static int __devinit tps65217_probe(struct i2c_client *client,
218 return ret; 190 return ret;
219 } 191 }
220 192
221 i2c_set_clientdata(client, tps); 193 ret = mfd_add_devices(tps->dev, -1, tps65217s,
222 tps->dev = &client->dev; 194 ARRAY_SIZE(tps65217s), NULL, 0, NULL);
195 if (ret < 0) {
196 dev_err(tps->dev, "mfd_add_devices failed: %d\n", ret);
197 return ret;
198 }
223 199
224 ret = tps65217_reg_read(tps, TPS65217_REG_CHIPID, &version); 200 ret = tps65217_reg_read(tps, TPS65217_REG_CHIPID, &version);
225 if (ret < 0) { 201 if (ret < 0) {
@@ -232,41 +208,21 @@ static int __devinit tps65217_probe(struct i2c_client *client,
232 (version & TPS65217_CHIPID_CHIP_MASK) >> 4, 208 (version & TPS65217_CHIPID_CHIP_MASK) >> 4,
233 version & TPS65217_CHIPID_REV_MASK); 209 version & TPS65217_CHIPID_REV_MASK);
234 210
235 for (i = 0; i < TPS65217_NUM_REGULATOR; i++) {
236 struct platform_device *pdev;
237
238 pdev = platform_device_alloc("tps65217-pmic", i);
239 if (!pdev) {
240 dev_err(tps->dev, "Cannot create regulator %d\n", i);
241 continue;
242 }
243
244 pdev->dev.parent = tps->dev;
245 pdev->dev.of_node = pdata->of_node[i];
246 reg_data = pdata->tps65217_init_data[i];
247 platform_device_add_data(pdev, reg_data, sizeof(*reg_data));
248 tps->regulator_pdev[i] = pdev;
249
250 platform_device_add(pdev);
251 }
252
253 return 0; 211 return 0;
254} 212}
255 213
256static int __devexit tps65217_remove(struct i2c_client *client) 214static int __devexit tps65217_remove(struct i2c_client *client)
257{ 215{
258 struct tps65217 *tps = i2c_get_clientdata(client); 216 struct tps65217 *tps = i2c_get_clientdata(client);
259 int i;
260 217
261 for (i = 0; i < TPS65217_NUM_REGULATOR; i++) 218 mfd_remove_devices(tps->dev);
262 platform_device_unregister(tps->regulator_pdev[i]);
263 219
264 return 0; 220 return 0;
265} 221}
266 222
267static const struct i2c_device_id tps65217_id_table[] = { 223static const struct i2c_device_id tps65217_id_table[] = {
268 {"tps65217", 0xF0}, 224 {"tps65217", TPS65217},
269 {/* end of list */} 225 { /* sentinel */ }
270}; 226};
271MODULE_DEVICE_TABLE(i2c, tps65217_id_table); 227MODULE_DEVICE_TABLE(i2c, tps65217_id_table);
272 228
diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c
index 353c34812120..345960ca2fd8 100644
--- a/drivers/mfd/tps6586x.c
+++ b/drivers/mfd/tps6586x.c
@@ -25,6 +25,7 @@
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/regmap.h> 26#include <linux/regmap.h>
27#include <linux/regulator/of_regulator.h> 27#include <linux/regulator/of_regulator.h>
28#include <linux/regulator/machine.h>
28 29
29#include <linux/mfd/core.h> 30#include <linux/mfd/core.h>
30#include <linux/mfd/tps6586x.h> 31#include <linux/mfd/tps6586x.h>
@@ -346,6 +347,7 @@ failed:
346 347
347#ifdef CONFIG_OF 348#ifdef CONFIG_OF
348static struct of_regulator_match tps6586x_matches[] = { 349static struct of_regulator_match tps6586x_matches[] = {
350 { .name = "sys", .driver_data = (void *)TPS6586X_ID_SYS },
349 { .name = "sm0", .driver_data = (void *)TPS6586X_ID_SM_0 }, 351 { .name = "sm0", .driver_data = (void *)TPS6586X_ID_SM_0 },
350 { .name = "sm1", .driver_data = (void *)TPS6586X_ID_SM_1 }, 352 { .name = "sm1", .driver_data = (void *)TPS6586X_ID_SM_1 },
351 { .name = "sm2", .driver_data = (void *)TPS6586X_ID_SM_2 }, 353 { .name = "sm2", .driver_data = (void *)TPS6586X_ID_SM_2 },
@@ -369,6 +371,7 @@ static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *clien
369 struct tps6586x_platform_data *pdata; 371 struct tps6586x_platform_data *pdata;
370 struct tps6586x_subdev_info *devs; 372 struct tps6586x_subdev_info *devs;
371 struct device_node *regs; 373 struct device_node *regs;
374 const char *sys_rail_name = NULL;
372 unsigned int count; 375 unsigned int count;
373 unsigned int i, j; 376 unsigned int i, j;
374 int err; 377 int err;
@@ -391,12 +394,22 @@ static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *clien
391 return NULL; 394 return NULL;
392 395
393 for (i = 0, j = 0; i < num && j < count; i++) { 396 for (i = 0, j = 0; i < num && j < count; i++) {
397 struct regulator_init_data *reg_idata;
398
394 if (!tps6586x_matches[i].init_data) 399 if (!tps6586x_matches[i].init_data)
395 continue; 400 continue;
396 401
402 reg_idata = tps6586x_matches[i].init_data;
397 devs[j].name = "tps6586x-regulator"; 403 devs[j].name = "tps6586x-regulator";
398 devs[j].platform_data = tps6586x_matches[i].init_data; 404 devs[j].platform_data = tps6586x_matches[i].init_data;
399 devs[j].id = (int)tps6586x_matches[i].driver_data; 405 devs[j].id = (int)tps6586x_matches[i].driver_data;
406 if (devs[j].id == TPS6586X_ID_SYS)
407 sys_rail_name = reg_idata->constraints.name;
408
409 if ((devs[j].id == TPS6586X_ID_LDO_5) ||
410 (devs[j].id == TPS6586X_ID_LDO_RTC))
411 reg_idata->supply_regulator = sys_rail_name;
412
400 devs[j].of_node = tps6586x_matches[i].of_node; 413 devs[j].of_node = tps6586x_matches[i].of_node;
401 j++; 414 j++;
402 } 415 }
@@ -493,7 +506,8 @@ static int __devinit tps6586x_i2c_probe(struct i2c_client *client,
493 } 506 }
494 507
495 ret = mfd_add_devices(tps6586x->dev, -1, 508 ret = mfd_add_devices(tps6586x->dev, -1,
496 tps6586x_cell, ARRAY_SIZE(tps6586x_cell), NULL, 0); 509 tps6586x_cell, ARRAY_SIZE(tps6586x_cell),
510 NULL, 0, NULL);
497 if (ret < 0) { 511 if (ret < 0) {
498 dev_err(&client->dev, "mfd_add_devices failed: %d\n", ret); 512 dev_err(&client->dev, "mfd_add_devices failed: %d\n", ret);
499 goto err_mfd_add; 513 goto err_mfd_add;
diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index 1c563792c777..d3ce4d569deb 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -254,7 +254,7 @@ static __devinit int tps65910_i2c_probe(struct i2c_client *i2c,
254 254
255 ret = mfd_add_devices(tps65910->dev, -1, 255 ret = mfd_add_devices(tps65910->dev, -1,
256 tps65910s, ARRAY_SIZE(tps65910s), 256 tps65910s, ARRAY_SIZE(tps65910s),
257 NULL, 0); 257 NULL, 0, NULL);
258 if (ret < 0) { 258 if (ret < 0) {
259 dev_err(&i2c->dev, "mfd_add_devices failed: %d\n", ret); 259 dev_err(&i2c->dev, "mfd_add_devices failed: %d\n", ret);
260 return ret; 260 return ret;
diff --git a/drivers/mfd/tps65911-comparator.c b/drivers/mfd/tps65911-comparator.c
index 5a62e6bf89ae..0b6e361432c4 100644
--- a/drivers/mfd/tps65911-comparator.c
+++ b/drivers/mfd/tps65911-comparator.c
@@ -136,7 +136,7 @@ static __devinit int tps65911_comparator_probe(struct platform_device *pdev)
136 136
137 ret = comp_threshold_set(tps65910, COMP2, pdata->vmbch2_threshold); 137 ret = comp_threshold_set(tps65910, COMP2, pdata->vmbch2_threshold);
138 if (ret < 0) { 138 if (ret < 0) {
139 dev_err(&pdev->dev, "cannot set COMP2 theshold\n"); 139 dev_err(&pdev->dev, "cannot set COMP2 threshold\n");
140 return ret; 140 return ret;
141 } 141 }
142 142
diff --git a/drivers/mfd/tps65912-core.c b/drivers/mfd/tps65912-core.c
index 74fd8cb5f372..4658b5bdcd84 100644
--- a/drivers/mfd/tps65912-core.c
+++ b/drivers/mfd/tps65912-core.c
@@ -146,7 +146,7 @@ int tps65912_device_init(struct tps65912 *tps65912)
146 146
147 ret = mfd_add_devices(tps65912->dev, -1, 147 ret = mfd_add_devices(tps65912->dev, -1,
148 tps65912s, ARRAY_SIZE(tps65912s), 148 tps65912s, ARRAY_SIZE(tps65912s),
149 NULL, 0); 149 NULL, 0, NULL);
150 if (ret < 0) 150 if (ret < 0)
151 goto err; 151 goto err;
152 152
diff --git a/drivers/mfd/twl4030-audio.c b/drivers/mfd/twl4030-audio.c
index 838ce4eb444e..77c9acb14583 100644
--- a/drivers/mfd/twl4030-audio.c
+++ b/drivers/mfd/twl4030-audio.c
@@ -223,7 +223,7 @@ static int __devinit twl4030_audio_probe(struct platform_device *pdev)
223 223
224 if (childs) 224 if (childs)
225 ret = mfd_add_devices(&pdev->dev, pdev->id, audio->cells, 225 ret = mfd_add_devices(&pdev->dev, pdev->id, audio->cells,
226 childs, NULL, 0); 226 childs, NULL, 0, NULL);
227 else { 227 else {
228 dev_err(&pdev->dev, "No platform data found for childs\n"); 228 dev_err(&pdev->dev, "No platform data found for childs\n");
229 ret = -ENODEV; 229 ret = -ENODEV;
diff --git a/drivers/mfd/twl6040-core.c b/drivers/mfd/twl6040-core.c
index b0fad0ffca56..3dca5c195a20 100644
--- a/drivers/mfd/twl6040-core.c
+++ b/drivers/mfd/twl6040-core.c
@@ -632,7 +632,7 @@ static int __devinit twl6040_probe(struct i2c_client *client,
632 } 632 }
633 633
634 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children, 634 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children,
635 NULL, 0); 635 NULL, 0, NULL);
636 if (ret) 636 if (ret)
637 goto mfd_err; 637 goto mfd_err;
638 638
diff --git a/drivers/mfd/vx855.c b/drivers/mfd/vx855.c
index 872aff21e4be..b9a636d44c7f 100644
--- a/drivers/mfd/vx855.c
+++ b/drivers/mfd/vx855.c
@@ -102,7 +102,7 @@ static __devinit int vx855_probe(struct pci_dev *pdev,
102 vx855_gpio_resources[1].end = vx855_gpio_resources[1].start + 3; 102 vx855_gpio_resources[1].end = vx855_gpio_resources[1].start + 3;
103 103
104 ret = mfd_add_devices(&pdev->dev, -1, vx855_cells, ARRAY_SIZE(vx855_cells), 104 ret = mfd_add_devices(&pdev->dev, -1, vx855_cells, ARRAY_SIZE(vx855_cells),
105 NULL, 0); 105 NULL, 0, NULL);
106 106
107 /* we always return -ENODEV here in order to enable other 107 /* we always return -ENODEV here in order to enable other
108 * drivers like old, not-yet-platform_device ported i2c-viapro */ 108 * drivers like old, not-yet-platform_device ported i2c-viapro */
diff --git a/drivers/mfd/wl1273-core.c b/drivers/mfd/wl1273-core.c
index f39b756df561..86e0e4309fc2 100644
--- a/drivers/mfd/wl1273-core.c
+++ b/drivers/mfd/wl1273-core.c
@@ -241,7 +241,7 @@ static int __devinit wl1273_core_probe(struct i2c_client *client,
241 __func__, children); 241 __func__, children);
242 242
243 r = mfd_add_devices(&client->dev, -1, core->cells, 243 r = mfd_add_devices(&client->dev, -1, core->cells,
244 children, NULL, 0); 244 children, NULL, 0, NULL);
245 if (r) 245 if (r)
246 goto err; 246 goto err;
247 247
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index 946698fd2dc6..301731035940 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -1813,27 +1813,27 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1813 case WM8310: 1813 case WM8310:
1814 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1814 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1815 wm8310_devs, ARRAY_SIZE(wm8310_devs), 1815 wm8310_devs, ARRAY_SIZE(wm8310_devs),
1816 NULL, 0); 1816 NULL, 0, NULL);
1817 break; 1817 break;
1818 1818
1819 case WM8311: 1819 case WM8311:
1820 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1820 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1821 wm8311_devs, ARRAY_SIZE(wm8311_devs), 1821 wm8311_devs, ARRAY_SIZE(wm8311_devs),
1822 NULL, 0); 1822 NULL, 0, NULL);
1823 if (!pdata || !pdata->disable_touch) 1823 if (!pdata || !pdata->disable_touch)
1824 mfd_add_devices(wm831x->dev, wm831x_num, 1824 mfd_add_devices(wm831x->dev, wm831x_num,
1825 touch_devs, ARRAY_SIZE(touch_devs), 1825 touch_devs, ARRAY_SIZE(touch_devs),
1826 NULL, 0); 1826 NULL, 0, NULL);
1827 break; 1827 break;
1828 1828
1829 case WM8312: 1829 case WM8312:
1830 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1830 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1831 wm8312_devs, ARRAY_SIZE(wm8312_devs), 1831 wm8312_devs, ARRAY_SIZE(wm8312_devs),
1832 NULL, 0); 1832 NULL, 0, NULL);
1833 if (!pdata || !pdata->disable_touch) 1833 if (!pdata || !pdata->disable_touch)
1834 mfd_add_devices(wm831x->dev, wm831x_num, 1834 mfd_add_devices(wm831x->dev, wm831x_num,
1835 touch_devs, ARRAY_SIZE(touch_devs), 1835 touch_devs, ARRAY_SIZE(touch_devs),
1836 NULL, 0); 1836 NULL, 0, NULL);
1837 break; 1837 break;
1838 1838
1839 case WM8320: 1839 case WM8320:
@@ -1842,7 +1842,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1842 case WM8326: 1842 case WM8326:
1843 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1843 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1844 wm8320_devs, ARRAY_SIZE(wm8320_devs), 1844 wm8320_devs, ARRAY_SIZE(wm8320_devs),
1845 NULL, 0); 1845 NULL, 0, NULL);
1846 break; 1846 break;
1847 1847
1848 default: 1848 default:
@@ -1867,7 +1867,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1867 if (ret & WM831X_XTAL_ENA) { 1867 if (ret & WM831X_XTAL_ENA) {
1868 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1868 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1869 rtc_devs, ARRAY_SIZE(rtc_devs), 1869 rtc_devs, ARRAY_SIZE(rtc_devs),
1870 NULL, 0); 1870 NULL, 0, NULL);
1871 if (ret != 0) { 1871 if (ret != 0) {
1872 dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret); 1872 dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret);
1873 goto err_irq; 1873 goto err_irq;
@@ -1880,7 +1880,7 @@ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1880 /* Treat errors as non-critical */ 1880 /* Treat errors as non-critical */
1881 ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs, 1881 ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs,
1882 ARRAY_SIZE(backlight_devs), NULL, 1882 ARRAY_SIZE(backlight_devs), NULL,
1883 0); 1883 0, NULL);
1884 if (ret < 0) 1884 if (ret < 0)
1885 dev_err(wm831x->dev, "Failed to add backlight: %d\n", 1885 dev_err(wm831x->dev, "Failed to add backlight: %d\n",
1886 ret); 1886 ret);
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c
index 4b7d378551d5..639ca359242f 100644
--- a/drivers/mfd/wm8400-core.c
+++ b/drivers/mfd/wm8400-core.c
@@ -70,7 +70,7 @@ static int wm8400_register_codec(struct wm8400 *wm8400)
70 .pdata_size = sizeof(*wm8400), 70 .pdata_size = sizeof(*wm8400),
71 }; 71 };
72 72
73 return mfd_add_devices(wm8400->dev, -1, &cell, 1, NULL, 0); 73 return mfd_add_devices(wm8400->dev, -1, &cell, 1, NULL, 0, NULL);
74} 74}
75 75
76/* 76/*
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index eec74aa55fdf..2febf88cfce8 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -414,7 +414,7 @@ static __devinit int wm8994_device_init(struct wm8994 *wm8994, int irq)
414 ret = mfd_add_devices(wm8994->dev, -1, 414 ret = mfd_add_devices(wm8994->dev, -1,
415 wm8994_regulator_devs, 415 wm8994_regulator_devs,
416 ARRAY_SIZE(wm8994_regulator_devs), 416 ARRAY_SIZE(wm8994_regulator_devs),
417 NULL, 0); 417 NULL, 0, NULL);
418 if (ret != 0) { 418 if (ret != 0) {
419 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); 419 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
420 goto err; 420 goto err;
@@ -648,7 +648,7 @@ static __devinit int wm8994_device_init(struct wm8994 *wm8994, int irq)
648 648
649 ret = mfd_add_devices(wm8994->dev, -1, 649 ret = mfd_add_devices(wm8994->dev, -1,
650 wm8994_devs, ARRAY_SIZE(wm8994_devs), 650 wm8994_devs, ARRAY_SIZE(wm8994_devs),
651 NULL, 0); 651 NULL, 0, NULL);
652 if (ret != 0) { 652 if (ret != 0) {
653 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); 653 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
654 goto err_irq; 654 goto err_irq;
diff --git a/drivers/mfd/wm8994-irq.c b/drivers/mfd/wm8994-irq.c
index 0aac4aff17a5..a050e56a9bbd 100644
--- a/drivers/mfd/wm8994-irq.c
+++ b/drivers/mfd/wm8994-irq.c
@@ -135,6 +135,7 @@ static struct regmap_irq_chip wm8994_irq_chip = {
135 .status_base = WM8994_INTERRUPT_STATUS_1, 135 .status_base = WM8994_INTERRUPT_STATUS_1,
136 .mask_base = WM8994_INTERRUPT_STATUS_1_MASK, 136 .mask_base = WM8994_INTERRUPT_STATUS_1_MASK,
137 .ack_base = WM8994_INTERRUPT_STATUS_1, 137 .ack_base = WM8994_INTERRUPT_STATUS_1,
138 .runtime_pm = true,
138}; 139};
139 140
140int wm8994_irq_init(struct wm8994 *wm8994) 141int wm8994_irq_init(struct wm8994 *wm8994)
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index d4619e2ec030..2273ce6b6c1a 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -641,7 +641,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
641 /* 641 /*
642 * If the host and card support UHS-I mode request the card 642 * If the host and card support UHS-I mode request the card
643 * to switch to 1.8V signaling level. No 1.8v signalling if 643 * to switch to 1.8V signaling level. No 1.8v signalling if
644 * UHS mode is not enabled to maintain compatibilty and some 644 * UHS mode is not enabled to maintain compatibility and some
645 * systems that claim 1.8v signalling in fact do not support 645 * systems that claim 1.8v signalling in fact do not support
646 * it. 646 * it.
647 */ 647 */
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index efdb81d21c44..74bed0fc23e7 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -356,7 +356,7 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
356} 356}
357 357
358/* 358/*
359 * Update bytes tranfered count during a write operation 359 * Update bytes transfered count during a write operation
360 */ 360 */
361static void at91_mci_update_bytes_xfered(struct at91mci_host *host) 361static void at91_mci_update_bytes_xfered(struct at91mci_host *host)
362{ 362{
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index a53c7c478e05..852d5fbda630 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -1022,7 +1022,7 @@ static void atmci_stop_transfer(struct atmel_mci *host)
1022} 1022}
1023 1023
1024/* 1024/*
1025 * Stop data transfer because error(s) occured. 1025 * Stop data transfer because error(s) occurred.
1026 */ 1026 */
1027static void atmci_stop_transfer_pdc(struct atmel_mci *host) 1027static void atmci_stop_transfer_pdc(struct atmel_mci *host)
1028{ 1028{
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 3a09f93cc3b6..686e256764c8 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -447,7 +447,7 @@ static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host)
447 OMAP_HSMMC_WRITE(host->base, SYSCTL, 447 OMAP_HSMMC_WRITE(host->base, SYSCTL,
448 OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN); 448 OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
449 if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0) 449 if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0)
450 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n"); 450 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stopped\n");
451} 451}
452 452
453static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host, 453static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host,
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index e23f8134591c..32f4a070551f 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -315,7 +315,7 @@ static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
315 new_val = val & (SDHCI_CTRL_LED | \ 315 new_val = val & (SDHCI_CTRL_LED | \
316 SDHCI_CTRL_4BITBUS | \ 316 SDHCI_CTRL_4BITBUS | \
317 SDHCI_CTRL_D3CD); 317 SDHCI_CTRL_D3CD);
318 /* ensure the endianess */ 318 /* ensure the endianness */
319 new_val |= ESDHC_HOST_CONTROL_LE; 319 new_val |= ESDHC_HOST_CONTROL_LE;
320 /* bits 8&9 are reserved on mx25 */ 320 /* bits 8&9 are reserved on mx25 */
321 if (!is_imx25_esdhc(imx_data)) { 321 if (!is_imx25_esdhc(imx_data)) {
diff --git a/drivers/mmc/host/vub300.c b/drivers/mmc/host/vub300.c
index 3135a1a5d75d..58eab9ac1d01 100644
--- a/drivers/mmc/host/vub300.c
+++ b/drivers/mmc/host/vub300.c
@@ -806,7 +806,7 @@ static void command_res_completed(struct urb *urb)
806 * we suspect a buggy USB host controller 806 * we suspect a buggy USB host controller
807 */ 807 */
808 } else if (!vub300->data) { 808 } else if (!vub300->data) {
809 /* this means that the command (typically CMD52) suceeded */ 809 /* this means that the command (typically CMD52) succeeded */
810 } else if (vub300->resp.common.header_type != 0x02) { 810 } else if (vub300->resp.common.header_type != 0x02) {
811 /* 811 /*
812 * this is an error response from the VUB300 chip 812 * this is an error response from the VUB300 chip
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index f2f482bec573..a6e74514e662 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1123,6 +1123,33 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file,
1123} 1123}
1124#endif 1124#endif
1125 1125
1126static inline unsigned long get_vm_size(struct vm_area_struct *vma)
1127{
1128 return vma->vm_end - vma->vm_start;
1129}
1130
1131static inline resource_size_t get_vm_offset(struct vm_area_struct *vma)
1132{
1133 return (resource_size_t) vma->vm_pgoff << PAGE_SHIFT;
1134}
1135
1136/*
1137 * Set a new vm offset.
1138 *
1139 * Verify that the incoming offset really works as a page offset,
1140 * and that the offset and size fit in a resource_size_t.
1141 */
1142static inline int set_vm_offset(struct vm_area_struct *vma, resource_size_t off)
1143{
1144 pgoff_t pgoff = off >> PAGE_SHIFT;
1145 if (off != (resource_size_t) pgoff << PAGE_SHIFT)
1146 return -EINVAL;
1147 if (off + get_vm_size(vma) - 1 < off)
1148 return -EINVAL;
1149 vma->vm_pgoff = pgoff;
1150 return 0;
1151}
1152
1126/* 1153/*
1127 * set up a mapping for shared memory segments 1154 * set up a mapping for shared memory segments
1128 */ 1155 */
@@ -1132,20 +1159,29 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
1132 struct mtd_file_info *mfi = file->private_data; 1159 struct mtd_file_info *mfi = file->private_data;
1133 struct mtd_info *mtd = mfi->mtd; 1160 struct mtd_info *mtd = mfi->mtd;
1134 struct map_info *map = mtd->priv; 1161 struct map_info *map = mtd->priv;
1135 unsigned long start; 1162 resource_size_t start, off;
1136 unsigned long off; 1163 unsigned long len, vma_len;
1137 u32 len;
1138 1164
1139 if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) { 1165 if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) {
1140 off = vma->vm_pgoff << PAGE_SHIFT; 1166 off = get_vm_offset(vma);
1141 start = map->phys; 1167 start = map->phys;
1142 len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size); 1168 len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
1143 start &= PAGE_MASK; 1169 start &= PAGE_MASK;
1144 if ((vma->vm_end - vma->vm_start + off) > len) 1170 vma_len = get_vm_size(vma);
1171
1172 /* Overflow in off+len? */
1173 if (vma_len + off < off)
1174 return -EINVAL;
1175 /* Does it fit in the mapping? */
1176 if (vma_len + off > len)
1145 return -EINVAL; 1177 return -EINVAL;
1146 1178
1147 off += start; 1179 off += start;
1148 vma->vm_pgoff = off >> PAGE_SHIFT; 1180 /* Did that overflow? */
1181 if (off < start)
1182 return -EINVAL;
1183 if (set_vm_offset(vma, off) < 0)
1184 return -EINVAL;
1149 vma->vm_flags |= VM_IO | VM_RESERVED; 1185 vma->vm_flags |= VM_IO | VM_RESERVED;
1150 1186
1151#ifdef pgprot_noncached 1187#ifdef pgprot_noncached
diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c
index 98ee43819911..7edadee487ba 100644
--- a/drivers/net/can/janz-ican3.c
+++ b/drivers/net/can/janz-ican3.c
@@ -1391,7 +1391,6 @@ static irqreturn_t ican3_irq(int irq, void *dev_id)
1391 */ 1391 */
1392static int ican3_reset_module(struct ican3_dev *mod) 1392static int ican3_reset_module(struct ican3_dev *mod)
1393{ 1393{
1394 u8 val = 1 << mod->num;
1395 unsigned long start; 1394 unsigned long start;
1396 u8 runold, runnew; 1395 u8 runold, runnew;
1397 1396
@@ -1405,8 +1404,7 @@ static int ican3_reset_module(struct ican3_dev *mod)
1405 runold = ioread8(mod->dpm + TARGET_RUNNING); 1404 runold = ioread8(mod->dpm + TARGET_RUNNING);
1406 1405
1407 /* reset the module */ 1406 /* reset the module */
1408 iowrite8(val, &mod->ctrl->reset_assert); 1407 iowrite8(0x00, &mod->dpmctrl->hwreset);
1409 iowrite8(val, &mod->ctrl->reset_deassert);
1410 1408
1411 /* wait until the module has finished resetting and is running */ 1409 /* wait until the module has finished resetting and is running */
1412 start = jiffies; 1410 start = jiffies;
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index a580db29e503..26e7129332ab 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -83,6 +83,11 @@
83#define INSTRUCTION_LOAD_TXB(n) (0x40 + 2 * (n)) 83#define INSTRUCTION_LOAD_TXB(n) (0x40 + 2 * (n))
84#define INSTRUCTION_READ_RXB(n) (((n) == 0) ? 0x90 : 0x94) 84#define INSTRUCTION_READ_RXB(n) (((n) == 0) ? 0x90 : 0x94)
85#define INSTRUCTION_RESET 0xC0 85#define INSTRUCTION_RESET 0xC0
86#define RTS_TXB0 0x01
87#define RTS_TXB1 0x02
88#define RTS_TXB2 0x04
89#define INSTRUCTION_RTS(n) (0x80 | ((n) & 0x07))
90
86 91
87/* MPC251x registers */ 92/* MPC251x registers */
88#define CANSTAT 0x0e 93#define CANSTAT 0x0e
@@ -397,6 +402,7 @@ static void mcp251x_hw_tx_frame(struct spi_device *spi, u8 *buf,
397static void mcp251x_hw_tx(struct spi_device *spi, struct can_frame *frame, 402static void mcp251x_hw_tx(struct spi_device *spi, struct can_frame *frame,
398 int tx_buf_idx) 403 int tx_buf_idx)
399{ 404{
405 struct mcp251x_priv *priv = dev_get_drvdata(&spi->dev);
400 u32 sid, eid, exide, rtr; 406 u32 sid, eid, exide, rtr;
401 u8 buf[SPI_TRANSFER_BUF_LEN]; 407 u8 buf[SPI_TRANSFER_BUF_LEN];
402 408
@@ -418,7 +424,10 @@ static void mcp251x_hw_tx(struct spi_device *spi, struct can_frame *frame,
418 buf[TXBDLC_OFF] = (rtr << DLC_RTR_SHIFT) | frame->can_dlc; 424 buf[TXBDLC_OFF] = (rtr << DLC_RTR_SHIFT) | frame->can_dlc;
419 memcpy(buf + TXBDAT_OFF, frame->data, frame->can_dlc); 425 memcpy(buf + TXBDAT_OFF, frame->data, frame->can_dlc);
420 mcp251x_hw_tx_frame(spi, buf, frame->can_dlc, tx_buf_idx); 426 mcp251x_hw_tx_frame(spi, buf, frame->can_dlc, tx_buf_idx);
421 mcp251x_write_reg(spi, TXBCTRL(tx_buf_idx), TXBCTRL_TXREQ); 427
428 /* use INSTRUCTION_RTS, to avoid "repeated frame problem" */
429 priv->spi_tx_buf[0] = INSTRUCTION_RTS(1 << tx_buf_idx);
430 mcp251x_spi_trans(priv->spi, 1);
422} 431}
423 432
424static void mcp251x_hw_rx_frame(struct spi_device *spi, u8 *buf, 433static void mcp251x_hw_rx_frame(struct spi_device *spi, u8 *buf,
diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c
index 527dbcf95335..9ded21e79db5 100644
--- a/drivers/net/can/ti_hecc.c
+++ b/drivers/net/can/ti_hecc.c
@@ -984,12 +984,12 @@ static int __devexit ti_hecc_remove(struct platform_device *pdev)
984 struct net_device *ndev = platform_get_drvdata(pdev); 984 struct net_device *ndev = platform_get_drvdata(pdev);
985 struct ti_hecc_priv *priv = netdev_priv(ndev); 985 struct ti_hecc_priv *priv = netdev_priv(ndev);
986 986
987 unregister_candev(ndev);
987 clk_disable(priv->clk); 988 clk_disable(priv->clk);
988 clk_put(priv->clk); 989 clk_put(priv->clk);
989 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 990 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
990 iounmap(priv->base); 991 iounmap(priv->base);
991 release_mem_region(res->start, resource_size(res)); 992 release_mem_region(res->start, resource_size(res));
992 unregister_candev(ndev);
993 free_candev(ndev); 993 free_candev(ndev);
994 platform_set_drvdata(pdev, NULL); 994 platform_set_drvdata(pdev, NULL);
995 995
diff --git a/drivers/net/ethernet/3com/typhoon.c b/drivers/net/ethernet/3com/typhoon.c
index b15366635147..bb9670f29b59 100644
--- a/drivers/net/ethernet/3com/typhoon.c
+++ b/drivers/net/ethernet/3com/typhoon.c
@@ -364,7 +364,7 @@ typhoon_inc_rxfree_index(u32 *index, const int count)
364static inline void 364static inline void
365typhoon_inc_tx_index(u32 *index, const int count) 365typhoon_inc_tx_index(u32 *index, const int count)
366{ 366{
367 /* if we start using the Hi Tx ring, this needs updateing */ 367 /* if we start using the Hi Tx ring, this needs updating */
368 typhoon_inc_index(index, count, TXLO_ENTRIES); 368 typhoon_inc_index(index, count, TXLO_ENTRIES);
369} 369}
370 370
diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c
index 79cebd8525ce..e48312f2305d 100644
--- a/drivers/net/ethernet/broadcom/bnx2.c
+++ b/drivers/net/ethernet/broadcom/bnx2.c
@@ -8564,7 +8564,7 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8564 return 0; 8564 return 0;
8565 8565
8566error: 8566error:
8567 iounmap(bp->regview); 8567 pci_iounmap(pdev, bp->regview);
8568 pci_release_regions(pdev); 8568 pci_release_regions(pdev);
8569 pci_disable_device(pdev); 8569 pci_disable_device(pdev);
8570 pci_set_drvdata(pdev, NULL); 8570 pci_set_drvdata(pdev, NULL);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
index 6d1a24acb77e..eac25236856c 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
@@ -1458,7 +1458,7 @@ struct bnx2x {
1458 int fw_stats_req_sz; 1458 int fw_stats_req_sz;
1459 1459
1460 /* 1460 /*
1461 * FW statistics data shortcut (points at the begining of 1461 * FW statistics data shortcut (points at the beginning of
1462 * fw_stats buffer + fw_stats_req_sz). 1462 * fw_stats buffer + fw_stats_req_sz).
1463 */ 1463 */
1464 struct bnx2x_fw_stats_data *fw_stats_data; 1464 struct bnx2x_fw_stats_data *fw_stats_data;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index af20c6ee2cd9..e8e97a7d1d06 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -662,14 +662,16 @@ void bnx2x_csum_validate(struct sk_buff *skb, union eth_rx_cqe *cqe,
662 struct bnx2x_fastpath *fp, 662 struct bnx2x_fastpath *fp,
663 struct bnx2x_eth_q_stats *qstats) 663 struct bnx2x_eth_q_stats *qstats)
664{ 664{
665 /* Do nothing if no IP/L4 csum validation was done */ 665 /* Do nothing if no L4 csum validation was done.
666 666 * We do not check whether IP csum was validated. For IPv4 we assume
667 * that if the card got as far as validating the L4 csum, it also
668 * validated the IP csum. IPv6 has no IP csum.
669 */
667 if (cqe->fast_path_cqe.status_flags & 670 if (cqe->fast_path_cqe.status_flags &
668 (ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG | 671 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG)
669 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG))
670 return; 672 return;
671 673
672 /* If both IP/L4 validation were done, check if an error was found. */ 674 /* If L4 validation was done, check if an error was found. */
673 675
674 if (cqe->fast_path_cqe.type_error_flags & 676 if (cqe->fast_path_cqe.type_error_flags &
675 (ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG | 677 (ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG |
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
index 21b553229ea4..dfd86a55f1dc 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
@@ -710,17 +710,15 @@ static inline u16 bnx2x_tx_avail(struct bnx2x *bp,
710 prod = txdata->tx_bd_prod; 710 prod = txdata->tx_bd_prod;
711 cons = txdata->tx_bd_cons; 711 cons = txdata->tx_bd_cons;
712 712
713 /* NUM_TX_RINGS = number of "next-page" entries 713 used = SUB_S16(prod, cons);
714 It will be used as a threshold */
715 used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
716 714
717#ifdef BNX2X_STOP_ON_ERROR 715#ifdef BNX2X_STOP_ON_ERROR
718 WARN_ON(used < 0); 716 WARN_ON(used < 0);
719 WARN_ON(used > bp->tx_ring_size); 717 WARN_ON(used > txdata->tx_ring_size);
720 WARN_ON((bp->tx_ring_size - used) > MAX_TX_AVAIL); 718 WARN_ON((txdata->tx_ring_size - used) > MAX_TX_AVAIL);
721#endif 719#endif
722 720
723 return (s16)(bp->tx_ring_size) - used; 721 return (s16)(txdata->tx_ring_size) - used;
724} 722}
725 723
726static inline int bnx2x_tx_queue_has_work(struct bnx2x_fp_txdata *txdata) 724static inline int bnx2x_tx_queue_has_work(struct bnx2x_fp_txdata *txdata)
@@ -1088,6 +1086,7 @@ static inline void bnx2x_init_txdata(struct bnx2x *bp,
1088 txdata->txq_index = txq_index; 1086 txdata->txq_index = txq_index;
1089 txdata->tx_cons_sb = tx_cons_sb; 1087 txdata->tx_cons_sb = tx_cons_sb;
1090 txdata->parent_fp = fp; 1088 txdata->parent_fp = fp;
1089 txdata->tx_ring_size = IS_FCOE_FP(fp) ? MAX_TX_AVAIL : bp->tx_ring_size;
1091 1090
1092 DP(NETIF_MSG_IFUP, "created tx data cid %d, txq %d\n", 1091 DP(NETIF_MSG_IFUP, "created tx data cid %d, txq %d\n",
1093 txdata->cid, txdata->txq_index); 1092 txdata->cid, txdata->txq_index);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dump.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dump.h
index 3e4cff9b1ebe..b926f58e983b 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dump.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dump.h
@@ -401,11 +401,11 @@ static const struct reg_addr reg_addrs[] = {
401 { 0x70000, 8, RI_ALL_ONLINE }, 401 { 0x70000, 8, RI_ALL_ONLINE },
402 { 0x70020, 8184, RI_ALL_OFFLINE }, 402 { 0x70020, 8184, RI_ALL_OFFLINE },
403 { 0x78000, 8192, RI_E3E3B0_OFFLINE }, 403 { 0x78000, 8192, RI_E3E3B0_OFFLINE },
404 { 0x85000, 3, RI_ALL_ONLINE }, 404 { 0x85000, 3, RI_ALL_OFFLINE },
405 { 0x8501c, 7, RI_ALL_ONLINE }, 405 { 0x8501c, 7, RI_ALL_OFFLINE },
406 { 0x85048, 1, RI_ALL_ONLINE }, 406 { 0x85048, 1, RI_ALL_OFFLINE },
407 { 0x85200, 32, RI_ALL_ONLINE }, 407 { 0x85200, 32, RI_ALL_OFFLINE },
408 { 0xb0000, 16384, RI_E1H_ONLINE }, 408 { 0xb0000, 16384, RI_E1H_OFFLINE },
409 { 0xc1000, 7, RI_ALL_ONLINE }, 409 { 0xc1000, 7, RI_ALL_ONLINE },
410 { 0xc103c, 2, RI_E2E3E3B0_ONLINE }, 410 { 0xc103c, 2, RI_E2E3E3B0_ONLINE },
411 { 0xc1800, 2, RI_ALL_ONLINE }, 411 { 0xc1800, 2, RI_ALL_ONLINE },
@@ -581,17 +581,12 @@ static const struct reg_addr reg_addrs[] = {
581 { 0x140188, 3, RI_E1E1HE2E3_ONLINE }, 581 { 0x140188, 3, RI_E1E1HE2E3_ONLINE },
582 { 0x140194, 13, RI_ALL_ONLINE }, 582 { 0x140194, 13, RI_ALL_ONLINE },
583 { 0x140200, 6, RI_E1E1HE2E3_ONLINE }, 583 { 0x140200, 6, RI_E1E1HE2E3_ONLINE },
584 { 0x140220, 4, RI_E2E3_ONLINE },
585 { 0x140240, 4, RI_E2E3_ONLINE },
586 { 0x140260, 4, RI_E2E3_ONLINE }, 584 { 0x140260, 4, RI_E2E3_ONLINE },
587 { 0x140280, 4, RI_E2E3_ONLINE }, 585 { 0x140280, 4, RI_E2E3_ONLINE },
588 { 0x1402a0, 4, RI_E2E3_ONLINE },
589 { 0x1402c0, 4, RI_E2E3_ONLINE },
590 { 0x1402e0, 2, RI_E2E3_ONLINE }, 586 { 0x1402e0, 2, RI_E2E3_ONLINE },
591 { 0x1402e8, 2, RI_E2E3E3B0_ONLINE }, 587 { 0x1402e8, 2, RI_E2E3E3B0_ONLINE },
592 { 0x1402f0, 9, RI_E2E3_ONLINE }, 588 { 0x1402f0, 9, RI_E2E3_ONLINE },
593 { 0x140314, 44, RI_E3B0_ONLINE }, 589 { 0x140314, 44, RI_E3B0_ONLINE },
594 { 0x1403d0, 70, RI_E3B0_ONLINE },
595 { 0x144000, 4, RI_E1E1H_ONLINE }, 590 { 0x144000, 4, RI_E1E1H_ONLINE },
596 { 0x148000, 4, RI_E1E1H_ONLINE }, 591 { 0x148000, 4, RI_E1E1H_ONLINE },
597 { 0x14c000, 4, RI_E1E1H_ONLINE }, 592 { 0x14c000, 4, RI_E1E1H_ONLINE },
@@ -704,7 +699,6 @@ static const struct reg_addr reg_addrs[] = {
704 { 0x180398, 1, RI_E2E3E3B0_ONLINE }, 699 { 0x180398, 1, RI_E2E3E3B0_ONLINE },
705 { 0x1803a0, 5, RI_E2E3E3B0_ONLINE }, 700 { 0x1803a0, 5, RI_E2E3E3B0_ONLINE },
706 { 0x1803b4, 2, RI_E3E3B0_ONLINE }, 701 { 0x1803b4, 2, RI_E3E3B0_ONLINE },
707 { 0x180400, 1, RI_ALL_ONLINE },
708 { 0x180404, 255, RI_E1E1H_OFFLINE }, 702 { 0x180404, 255, RI_E1E1H_OFFLINE },
709 { 0x181000, 4, RI_ALL_ONLINE }, 703 { 0x181000, 4, RI_ALL_ONLINE },
710 { 0x181010, 1020, RI_ALL_OFFLINE }, 704 { 0x181010, 1020, RI_ALL_OFFLINE },
@@ -800,9 +794,9 @@ static const struct reg_addr reg_addrs[] = {
800 { 0x1b905c, 1, RI_E3E3B0_ONLINE }, 794 { 0x1b905c, 1, RI_E3E3B0_ONLINE },
801 { 0x1b9064, 1, RI_E3B0_ONLINE }, 795 { 0x1b9064, 1, RI_E3B0_ONLINE },
802 { 0x1b9080, 10, RI_E3B0_ONLINE }, 796 { 0x1b9080, 10, RI_E3B0_ONLINE },
803 { 0x1b9400, 14, RI_E2E3E3B0_ONLINE }, 797 { 0x1b9400, 14, RI_E2E3E3B0_OFFLINE },
804 { 0x1b943c, 19, RI_E2E3E3B0_ONLINE }, 798 { 0x1b943c, 19, RI_E2E3E3B0_OFFLINE },
805 { 0x1b9490, 10, RI_E2E3E3B0_ONLINE }, 799 { 0x1b9490, 10, RI_E2E3E3B0_OFFLINE },
806 { 0x1c0000, 2, RI_ALL_ONLINE }, 800 { 0x1c0000, 2, RI_ALL_ONLINE },
807 { 0x200000, 65, RI_ALL_ONLINE }, 801 { 0x200000, 65, RI_ALL_ONLINE },
808 { 0x20014c, 2, RI_E1HE2E3E3B0_ONLINE }, 802 { 0x20014c, 2, RI_E1HE2E3E3B0_ONLINE },
@@ -814,7 +808,6 @@ static const struct reg_addr reg_addrs[] = {
814 { 0x200398, 1, RI_E2E3E3B0_ONLINE }, 808 { 0x200398, 1, RI_E2E3E3B0_ONLINE },
815 { 0x2003a0, 1, RI_E2E3E3B0_ONLINE }, 809 { 0x2003a0, 1, RI_E2E3E3B0_ONLINE },
816 { 0x2003a8, 2, RI_E2E3E3B0_ONLINE }, 810 { 0x2003a8, 2, RI_E2E3E3B0_ONLINE },
817 { 0x200400, 1, RI_ALL_ONLINE },
818 { 0x200404, 255, RI_E1E1H_OFFLINE }, 811 { 0x200404, 255, RI_E1E1H_OFFLINE },
819 { 0x202000, 4, RI_ALL_ONLINE }, 812 { 0x202000, 4, RI_ALL_ONLINE },
820 { 0x202010, 2044, RI_ALL_OFFLINE }, 813 { 0x202010, 2044, RI_ALL_OFFLINE },
@@ -921,7 +914,6 @@ static const struct reg_addr reg_addrs[] = {
921 { 0x280398, 1, RI_E2E3E3B0_ONLINE }, 914 { 0x280398, 1, RI_E2E3E3B0_ONLINE },
922 { 0x2803a0, 1, RI_E2E3E3B0_ONLINE }, 915 { 0x2803a0, 1, RI_E2E3E3B0_ONLINE },
923 { 0x2803a8, 2, RI_E2E3E3B0_ONLINE }, 916 { 0x2803a8, 2, RI_E2E3E3B0_ONLINE },
924 { 0x280400, 1, RI_ALL_ONLINE },
925 { 0x280404, 255, RI_E1E1H_OFFLINE }, 917 { 0x280404, 255, RI_E1E1H_OFFLINE },
926 { 0x282000, 4, RI_ALL_ONLINE }, 918 { 0x282000, 4, RI_ALL_ONLINE },
927 { 0x282010, 2044, RI_ALL_OFFLINE }, 919 { 0x282010, 2044, RI_ALL_OFFLINE },
@@ -1031,7 +1023,6 @@ static const struct reg_addr reg_addrs[] = {
1031 { 0x300398, 1, RI_E2E3E3B0_ONLINE }, 1023 { 0x300398, 1, RI_E2E3E3B0_ONLINE },
1032 { 0x3003a0, 1, RI_E2E3E3B0_ONLINE }, 1024 { 0x3003a0, 1, RI_E2E3E3B0_ONLINE },
1033 { 0x3003a8, 2, RI_E2E3E3B0_ONLINE }, 1025 { 0x3003a8, 2, RI_E2E3E3B0_ONLINE },
1034 { 0x300400, 1, RI_ALL_ONLINE },
1035 { 0x300404, 255, RI_E1E1H_OFFLINE }, 1026 { 0x300404, 255, RI_E1E1H_OFFLINE },
1036 { 0x302000, 4, RI_ALL_ONLINE }, 1027 { 0x302000, 4, RI_ALL_ONLINE },
1037 { 0x302010, 2044, RI_ALL_OFFLINE }, 1028 { 0x302010, 2044, RI_ALL_OFFLINE },
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
index c37a68d68090..ebf40cd7aa10 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
@@ -775,7 +775,7 @@ static void bnx2x_get_regs(struct net_device *dev,
775 struct bnx2x *bp = netdev_priv(dev); 775 struct bnx2x *bp = netdev_priv(dev);
776 struct dump_hdr dump_hdr = {0}; 776 struct dump_hdr dump_hdr = {0};
777 777
778 regs->version = 0; 778 regs->version = 1;
779 memset(p, 0, regs->len); 779 memset(p, 0, regs->len);
780 780
781 if (!netif_running(bp->dev)) 781 if (!netif_running(bp->dev))
@@ -1587,6 +1587,12 @@ static int bnx2x_set_pauseparam(struct net_device *dev,
1587 bp->link_params.req_flow_ctrl[cfg_idx] = 1587 bp->link_params.req_flow_ctrl[cfg_idx] =
1588 BNX2X_FLOW_CTRL_AUTO; 1588 BNX2X_FLOW_CTRL_AUTO;
1589 } 1589 }
1590 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_NONE;
1591 if (epause->rx_pause)
1592 bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_RX;
1593
1594 if (epause->tx_pause)
1595 bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_TX;
1590 } 1596 }
1591 1597
1592 DP(BNX2X_MSG_ETHTOOL, 1598 DP(BNX2X_MSG_ETHTOOL,
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
index f4beb46c4709..b046beb435b2 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
@@ -2667,9 +2667,11 @@ int bnx2x_update_pfc(struct link_params *params,
2667 return bnx2x_status; 2667 return bnx2x_status;
2668 2668
2669 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n"); 2669 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
2670 if (CHIP_IS_E3(bp)) 2670
2671 bnx2x_update_pfc_xmac(params, vars, 0); 2671 if (CHIP_IS_E3(bp)) {
2672 else { 2672 if (vars->mac_type == MAC_TYPE_XMAC)
2673 bnx2x_update_pfc_xmac(params, vars, 0);
2674 } else {
2673 val = REG_RD(bp, MISC_REG_RESET_REG_2); 2675 val = REG_RD(bp, MISC_REG_RESET_REG_2);
2674 if ((val & 2676 if ((val &
2675 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port)) 2677 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
@@ -5432,7 +5434,7 @@ static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
5432 switch (speed_mask) { 5434 switch (speed_mask) {
5433 case GP_STATUS_10M: 5435 case GP_STATUS_10M:
5434 vars->line_speed = SPEED_10; 5436 vars->line_speed = SPEED_10;
5435 if (vars->duplex == DUPLEX_FULL) 5437 if (is_duplex == DUPLEX_FULL)
5436 vars->link_status |= LINK_10TFD; 5438 vars->link_status |= LINK_10TFD;
5437 else 5439 else
5438 vars->link_status |= LINK_10THD; 5440 vars->link_status |= LINK_10THD;
@@ -5440,7 +5442,7 @@ static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
5440 5442
5441 case GP_STATUS_100M: 5443 case GP_STATUS_100M:
5442 vars->line_speed = SPEED_100; 5444 vars->line_speed = SPEED_100;
5443 if (vars->duplex == DUPLEX_FULL) 5445 if (is_duplex == DUPLEX_FULL)
5444 vars->link_status |= LINK_100TXFD; 5446 vars->link_status |= LINK_100TXFD;
5445 else 5447 else
5446 vars->link_status |= LINK_100TXHD; 5448 vars->link_status |= LINK_100TXHD;
@@ -5449,7 +5451,7 @@ static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
5449 case GP_STATUS_1G: 5451 case GP_STATUS_1G:
5450 case GP_STATUS_1G_KX: 5452 case GP_STATUS_1G_KX:
5451 vars->line_speed = SPEED_1000; 5453 vars->line_speed = SPEED_1000;
5452 if (vars->duplex == DUPLEX_FULL) 5454 if (is_duplex == DUPLEX_FULL)
5453 vars->link_status |= LINK_1000TFD; 5455 vars->link_status |= LINK_1000TFD;
5454 else 5456 else
5455 vars->link_status |= LINK_1000THD; 5457 vars->link_status |= LINK_1000THD;
@@ -5457,7 +5459,7 @@ static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
5457 5459
5458 case GP_STATUS_2_5G: 5460 case GP_STATUS_2_5G:
5459 vars->line_speed = SPEED_2500; 5461 vars->line_speed = SPEED_2500;
5460 if (vars->duplex == DUPLEX_FULL) 5462 if (is_duplex == DUPLEX_FULL)
5461 vars->link_status |= LINK_2500TFD; 5463 vars->link_status |= LINK_2500TFD;
5462 else 5464 else
5463 vars->link_status |= LINK_2500THD; 5465 vars->link_status |= LINK_2500THD;
@@ -5531,6 +5533,7 @@ static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
5531 5533
5532 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) { 5534 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
5533 if (SINGLE_MEDIA_DIRECT(params)) { 5535 if (SINGLE_MEDIA_DIRECT(params)) {
5536 vars->duplex = duplex;
5534 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status); 5537 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
5535 if (phy->req_line_speed == SPEED_AUTO_NEG) 5538 if (phy->req_line_speed == SPEED_AUTO_NEG)
5536 bnx2x_xgxs_an_resolve(phy, params, vars, 5539 bnx2x_xgxs_an_resolve(phy, params, vars,
@@ -5625,6 +5628,7 @@ static int bnx2x_warpcore_read_status(struct bnx2x_phy *phy,
5625 LINK_STATUS_PARALLEL_DETECTION_USED; 5628 LINK_STATUS_PARALLEL_DETECTION_USED;
5626 } 5629 }
5627 bnx2x_ext_phy_resolve_fc(phy, params, vars); 5630 bnx2x_ext_phy_resolve_fc(phy, params, vars);
5631 vars->duplex = duplex;
5628 } 5632 }
5629 } 5633 }
5630 5634
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 21054987257a..0875ecfe3372 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -7561,8 +7561,14 @@ int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7561 } 7561 }
7562 7562
7563 rc = bnx2x_config_vlan_mac(bp, &ramrod_param); 7563 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
7564 if (rc < 0) 7564
7565 if (rc == -EEXIST) {
7566 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
7567 /* do not treat adding same MAC as error */
7568 rc = 0;
7569 } else if (rc < 0)
7565 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del")); 7570 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
7571
7566 return rc; 7572 return rc;
7567} 7573}
7568 7574
@@ -9825,12 +9831,13 @@ static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
9825 } 9831 }
9826 9832
9827#ifdef CONFIG_PCI_MSI 9833#ifdef CONFIG_PCI_MSI
9828 /* 9834 /* Due to new PF resource allocation by MFW T7.4 and above, it's
9829 * It's expected that number of CAM entries for this functions is equal 9835 * optional that number of CAM entries will not be equal to the value
9830 * to the number evaluated based on the MSI-X table size. We want a 9836 * advertised in PCI.
9831 * harsh warning if these values are different! 9837 * Driver should use the minimal value of both as the actual status
9838 * block count
9832 */ 9839 */
9833 WARN_ON(bp->igu_sb_cnt != igu_sb_cnt); 9840 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
9834#endif 9841#endif
9835 9842
9836 if (igu_sb_cnt == 0) 9843 if (igu_sb_cnt == 0)
@@ -10294,13 +10301,11 @@ static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
10294 dev_info.port_hw_config[port]. 10301 dev_info.port_hw_config[port].
10295 fcoe_wwn_node_name_lower); 10302 fcoe_wwn_node_name_lower);
10296 } else if (!IS_MF_SD(bp)) { 10303 } else if (!IS_MF_SD(bp)) {
10297 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
10298
10299 /* 10304 /*
10300 * Read the WWN info only if the FCoE feature is enabled for 10305 * Read the WWN info only if the FCoE feature is enabled for
10301 * this function. 10306 * this function.
10302 */ 10307 */
10303 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) 10308 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
10304 bnx2x_get_ext_wwn_info(bp, func); 10309 bnx2x_get_ext_wwn_info(bp, func);
10305 10310
10306 } else if (IS_MF_FCOE_SD(bp)) 10311 } else if (IS_MF_FCOE_SD(bp))
@@ -11073,7 +11078,14 @@ static int bnx2x_set_uc_list(struct bnx2x *bp)
11073 netdev_for_each_uc_addr(ha, dev) { 11078 netdev_for_each_uc_addr(ha, dev) {
11074 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true, 11079 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11075 BNX2X_UC_LIST_MAC, &ramrod_flags); 11080 BNX2X_UC_LIST_MAC, &ramrod_flags);
11076 if (rc < 0) { 11081 if (rc == -EEXIST) {
11082 DP(BNX2X_MSG_SP,
11083 "Failed to schedule ADD operations: %d\n", rc);
11084 /* do not treat adding same MAC as error */
11085 rc = 0;
11086
11087 } else if (rc < 0) {
11088
11077 BNX2X_ERR("Failed to schedule ADD operations: %d\n", 11089 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11078 rc); 11090 rc);
11079 return rc; 11091 return rc;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
index f83e033da6da..acf2fe4ca608 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
@@ -1321,7 +1321,7 @@ void bnx2x_init_mcast_obj(struct bnx2x *bp,
1321 * the current command will be enqueued to the tail of the 1321 * the current command will be enqueued to the tail of the
1322 * pending commands list. 1322 * pending commands list.
1323 * 1323 *
1324 * Return: 0 is operation was sucessfull and there are no pending completions, 1324 * Return: 0 is operation was successfull and there are no pending completions,
1325 * negative if there were errors, positive if there are pending 1325 * negative if there were errors, positive if there are pending
1326 * completions. 1326 * completions.
1327 */ 1327 */
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
index 332db64dd5be..a1d0446b39b3 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
@@ -101,6 +101,11 @@ static void bnx2x_hw_stats_post(struct bnx2x *bp)
101 if (CHIP_REV_IS_SLOW(bp)) 101 if (CHIP_REV_IS_SLOW(bp))
102 return; 102 return;
103 103
104 /* Update MCP's statistics if possible */
105 if (bp->func_stx)
106 memcpy(bnx2x_sp(bp, func_stats), &bp->func_stats,
107 sizeof(bp->func_stats));
108
104 /* loader */ 109 /* loader */
105 if (bp->executer_idx) { 110 if (bp->executer_idx) {
106 int loader_idx = PMF_DMAE_C(bp); 111 int loader_idx = PMF_DMAE_C(bp);
@@ -128,8 +133,6 @@ static void bnx2x_hw_stats_post(struct bnx2x *bp)
128 133
129 } else if (bp->func_stx) { 134 } else if (bp->func_stx) {
130 *stats_comp = 0; 135 *stats_comp = 0;
131 memcpy(bnx2x_sp(bp, func_stats), &bp->func_stats,
132 sizeof(bp->func_stats));
133 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); 136 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
134 } 137 }
135} 138}
@@ -1151,9 +1154,11 @@ static void bnx2x_stats_update(struct bnx2x *bp)
1151 if (bp->port.pmf) 1154 if (bp->port.pmf)
1152 bnx2x_hw_stats_update(bp); 1155 bnx2x_hw_stats_update(bp);
1153 1156
1154 if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) { 1157 if (bnx2x_storm_stats_update(bp)) {
1155 BNX2X_ERR("storm stats were not updated for 3 times\n"); 1158 if (bp->stats_pending++ == 3) {
1156 bnx2x_panic(); 1159 BNX2X_ERR("storm stats were not updated for 3 times\n");
1160 bnx2x_panic();
1161 }
1157 return; 1162 return;
1158 } 1163 }
1159 1164
diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index 77884191a8c6..4e980a7886fb 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -1086,7 +1086,7 @@ static int __init at91ether_probe(struct platform_device *pdev)
1086 /* Clock */ 1086 /* Clock */
1087 lp->ether_clk = clk_get(&pdev->dev, "ether_clk"); 1087 lp->ether_clk = clk_get(&pdev->dev, "ether_clk");
1088 if (IS_ERR(lp->ether_clk)) { 1088 if (IS_ERR(lp->ether_clk)) {
1089 res = -ENODEV; 1089 res = PTR_ERR(lp->ether_clk);
1090 goto err_ioumap; 1090 goto err_ioumap;
1091 } 1091 }
1092 clk_enable(lp->ether_clk); 1092 clk_enable(lp->ether_clk);
diff --git a/drivers/net/ethernet/freescale/gianfar_ethtool.c b/drivers/net/ethernet/freescale/gianfar_ethtool.c
index 8971921cc1c8..ab6762caa957 100644
--- a/drivers/net/ethernet/freescale/gianfar_ethtool.c
+++ b/drivers/net/ethernet/freescale/gianfar_ethtool.c
@@ -1773,6 +1773,7 @@ static int gfar_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
1773} 1773}
1774 1774
1775int gfar_phc_index = -1; 1775int gfar_phc_index = -1;
1776EXPORT_SYMBOL(gfar_phc_index);
1776 1777
1777static int gfar_get_ts_info(struct net_device *dev, 1778static int gfar_get_ts_info(struct net_device *dev,
1778 struct ethtool_ts_info *info) 1779 struct ethtool_ts_info *info)
diff --git a/drivers/net/ethernet/freescale/gianfar_ptp.c b/drivers/net/ethernet/freescale/gianfar_ptp.c
index c08e5d40fecb..0daa66b8eca0 100644
--- a/drivers/net/ethernet/freescale/gianfar_ptp.c
+++ b/drivers/net/ethernet/freescale/gianfar_ptp.c
@@ -515,7 +515,7 @@ static int gianfar_ptp_probe(struct platform_device *dev)
515 err = PTR_ERR(etsects->clock); 515 err = PTR_ERR(etsects->clock);
516 goto no_clock; 516 goto no_clock;
517 } 517 }
518 gfar_phc_clock = ptp_clock_index(etsects->clock); 518 gfar_phc_index = ptp_clock_index(etsects->clock);
519 519
520 dev_set_drvdata(&dev->dev, etsects); 520 dev_set_drvdata(&dev->dev, etsects);
521 521
@@ -539,7 +539,7 @@ static int gianfar_ptp_remove(struct platform_device *dev)
539 gfar_write(&etsects->regs->tmr_temask, 0); 539 gfar_write(&etsects->regs->tmr_temask, 0);
540 gfar_write(&etsects->regs->tmr_ctrl, 0); 540 gfar_write(&etsects->regs->tmr_ctrl, 0);
541 541
542 gfar_phc_clock = -1; 542 gfar_phc_index = -1;
543 ptp_clock_unregister(etsects->clock); 543 ptp_clock_unregister(etsects->clock);
544 iounmap(etsects->regs); 544 iounmap(etsects->regs);
545 release_resource(etsects->rsrc); 545 release_resource(etsects->rsrc);
diff --git a/drivers/net/ethernet/i825xx/znet.c b/drivers/net/ethernet/i825xx/znet.c
index bd1f1ef91e19..ba4e0cea3506 100644
--- a/drivers/net/ethernet/i825xx/znet.c
+++ b/drivers/net/ethernet/i825xx/znet.c
@@ -139,8 +139,11 @@ struct znet_private {
139/* Only one can be built-in;-> */ 139/* Only one can be built-in;-> */
140static struct net_device *znet_dev; 140static struct net_device *znet_dev;
141 141
142#define NETIDBLK_MAGIC "NETIDBLK"
143#define NETIDBLK_MAGIC_SIZE 8
144
142struct netidblk { 145struct netidblk {
143 char magic[8]; /* The magic number (string) "NETIDBLK" */ 146 char magic[NETIDBLK_MAGIC_SIZE]; /* The magic number (string) "NETIDBLK" */
144 unsigned char netid[8]; /* The physical station address */ 147 unsigned char netid[8]; /* The physical station address */
145 char nettype, globalopt; 148 char nettype, globalopt;
146 char vendor[8]; /* The machine vendor and product name. */ 149 char vendor[8]; /* The machine vendor and product name. */
@@ -373,14 +376,16 @@ static int __init znet_probe (void)
373 struct znet_private *znet; 376 struct znet_private *znet;
374 struct net_device *dev; 377 struct net_device *dev;
375 char *p; 378 char *p;
379 char *plast = phys_to_virt(0x100000 - NETIDBLK_MAGIC_SIZE);
376 int err = -ENOMEM; 380 int err = -ENOMEM;
377 381
378 /* This code scans the region 0xf0000 to 0xfffff for a "NETIDBLK". */ 382 /* This code scans the region 0xf0000 to 0xfffff for a "NETIDBLK". */
379 for(p = (char *)phys_to_virt(0xf0000); p < (char *)phys_to_virt(0x100000); p++) 383 for(p = (char *)phys_to_virt(0xf0000); p <= plast; p++)
380 if (*p == 'N' && strncmp(p, "NETIDBLK", 8) == 0) 384 if (*p == 'N' &&
385 strncmp(p, NETIDBLK_MAGIC, NETIDBLK_MAGIC_SIZE) == 0)
381 break; 386 break;
382 387
383 if (p >= (char *)phys_to_virt(0x100000)) { 388 if (p > plast) {
384 if (znet_debug > 1) 389 if (znet_debug > 1)
385 printk(KERN_INFO "No Z-Note ethernet adaptor found.\n"); 390 printk(KERN_INFO "No Z-Note ethernet adaptor found.\n");
386 return -ENODEV; 391 return -ENODEV;
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index 9010cea68bc3..b68d28a130e6 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -472,14 +472,9 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
472 } 472 }
473 473
474 if (adapter->rx_queue.queue_addr != NULL) { 474 if (adapter->rx_queue.queue_addr != NULL) {
475 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) { 475 dma_free_coherent(dev, adapter->rx_queue.queue_len,
476 dma_unmap_single(dev, 476 adapter->rx_queue.queue_addr,
477 adapter->rx_queue.queue_dma, 477 adapter->rx_queue.queue_dma);
478 adapter->rx_queue.queue_len,
479 DMA_BIDIRECTIONAL);
480 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
481 }
482 kfree(adapter->rx_queue.queue_addr);
483 adapter->rx_queue.queue_addr = NULL; 478 adapter->rx_queue.queue_addr = NULL;
484 } 479 }
485 480
@@ -556,10 +551,13 @@ static int ibmveth_open(struct net_device *netdev)
556 goto err_out; 551 goto err_out;
557 } 552 }
558 553
554 dev = &adapter->vdev->dev;
555
559 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * 556 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) *
560 rxq_entries; 557 rxq_entries;
561 adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, 558 adapter->rx_queue.queue_addr =
562 GFP_KERNEL); 559 dma_alloc_coherent(dev, adapter->rx_queue.queue_len,
560 &adapter->rx_queue.queue_dma, GFP_KERNEL);
563 561
564 if (!adapter->rx_queue.queue_addr) { 562 if (!adapter->rx_queue.queue_addr) {
565 netdev_err(netdev, "unable to allocate rx queue pages\n"); 563 netdev_err(netdev, "unable to allocate rx queue pages\n");
@@ -567,19 +565,13 @@ static int ibmveth_open(struct net_device *netdev)
567 goto err_out; 565 goto err_out;
568 } 566 }
569 567
570 dev = &adapter->vdev->dev;
571
572 adapter->buffer_list_dma = dma_map_single(dev, 568 adapter->buffer_list_dma = dma_map_single(dev,
573 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL); 569 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
574 adapter->filter_list_dma = dma_map_single(dev, 570 adapter->filter_list_dma = dma_map_single(dev,
575 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL); 571 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
576 adapter->rx_queue.queue_dma = dma_map_single(dev,
577 adapter->rx_queue.queue_addr,
578 adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL);
579 572
580 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) || 573 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
581 (dma_mapping_error(dev, adapter->filter_list_dma)) || 574 (dma_mapping_error(dev, adapter->filter_list_dma))) {
582 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) {
583 netdev_err(netdev, "unable to map filter or buffer list " 575 netdev_err(netdev, "unable to map filter or buffer list "
584 "pages\n"); 576 "pages\n");
585 rc = -ENOMEM; 577 rc = -ENOMEM;
diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c
index 3bfbb8df8989..bde337ee1a34 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_main.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_main.c
@@ -3149,6 +3149,17 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
3149 return NETDEV_TX_OK; 3149 return NETDEV_TX_OK;
3150 } 3150 }
3151 3151
3152 /* On PCI/PCI-X HW, if packet size is less than ETH_ZLEN,
3153 * packets may get corrupted during padding by HW.
3154 * To WA this issue, pad all small packets manually.
3155 */
3156 if (skb->len < ETH_ZLEN) {
3157 if (skb_pad(skb, ETH_ZLEN - skb->len))
3158 return NETDEV_TX_OK;
3159 skb->len = ETH_ZLEN;
3160 skb_set_tail_pointer(skb, ETH_ZLEN);
3161 }
3162
3152 mss = skb_shinfo(skb)->gso_size; 3163 mss = skb_shinfo(skb)->gso_size;
3153 /* The controller does a simple calculation to 3164 /* The controller does a simple calculation to
3154 * make sure there is enough room in the FIFO before 3165 * make sure there is enough room in the FIFO before
diff --git a/drivers/net/ethernet/mellanox/mlx4/icm.c b/drivers/net/ethernet/mellanox/mlx4/icm.c
index daf417923661..31d02649be41 100644
--- a/drivers/net/ethernet/mellanox/mlx4/icm.c
+++ b/drivers/net/ethernet/mellanox/mlx4/icm.c
@@ -227,9 +227,10 @@ int mlx4_UNMAP_ICM_AUX(struct mlx4_dev *dev)
227 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 227 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
228} 228}
229 229
230int mlx4_table_get(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj) 230int mlx4_table_get(struct mlx4_dev *dev, struct mlx4_icm_table *table, u32 obj)
231{ 231{
232 int i = (obj & (table->num_obj - 1)) / (MLX4_TABLE_CHUNK_SIZE / table->obj_size); 232 u32 i = (obj & (table->num_obj - 1)) /
233 (MLX4_TABLE_CHUNK_SIZE / table->obj_size);
233 int ret = 0; 234 int ret = 0;
234 235
235 mutex_lock(&table->mutex); 236 mutex_lock(&table->mutex);
@@ -262,16 +263,18 @@ out:
262 return ret; 263 return ret;
263} 264}
264 265
265void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj) 266void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, u32 obj)
266{ 267{
267 int i; 268 u32 i;
269 u64 offset;
268 270
269 i = (obj & (table->num_obj - 1)) / (MLX4_TABLE_CHUNK_SIZE / table->obj_size); 271 i = (obj & (table->num_obj - 1)) / (MLX4_TABLE_CHUNK_SIZE / table->obj_size);
270 272
271 mutex_lock(&table->mutex); 273 mutex_lock(&table->mutex);
272 274
273 if (--table->icm[i]->refcount == 0) { 275 if (--table->icm[i]->refcount == 0) {
274 mlx4_UNMAP_ICM(dev, table->virt + i * MLX4_TABLE_CHUNK_SIZE, 276 offset = (u64) i * MLX4_TABLE_CHUNK_SIZE;
277 mlx4_UNMAP_ICM(dev, table->virt + offset,
275 MLX4_TABLE_CHUNK_SIZE / MLX4_ICM_PAGE_SIZE); 278 MLX4_TABLE_CHUNK_SIZE / MLX4_ICM_PAGE_SIZE);
276 mlx4_free_icm(dev, table->icm[i], table->coherent); 279 mlx4_free_icm(dev, table->icm[i], table->coherent);
277 table->icm[i] = NULL; 280 table->icm[i] = NULL;
@@ -280,9 +283,11 @@ void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj)
280 mutex_unlock(&table->mutex); 283 mutex_unlock(&table->mutex);
281} 284}
282 285
283void *mlx4_table_find(struct mlx4_icm_table *table, int obj, dma_addr_t *dma_handle) 286void *mlx4_table_find(struct mlx4_icm_table *table, u32 obj,
287 dma_addr_t *dma_handle)
284{ 288{
285 int idx, offset, dma_offset, i; 289 int offset, dma_offset, i;
290 u64 idx;
286 struct mlx4_icm_chunk *chunk; 291 struct mlx4_icm_chunk *chunk;
287 struct mlx4_icm *icm; 292 struct mlx4_icm *icm;
288 struct page *page = NULL; 293 struct page *page = NULL;
@@ -292,7 +297,7 @@ void *mlx4_table_find(struct mlx4_icm_table *table, int obj, dma_addr_t *dma_han
292 297
293 mutex_lock(&table->mutex); 298 mutex_lock(&table->mutex);
294 299
295 idx = (obj & (table->num_obj - 1)) * table->obj_size; 300 idx = (u64) (obj & (table->num_obj - 1)) * table->obj_size;
296 icm = table->icm[idx / MLX4_TABLE_CHUNK_SIZE]; 301 icm = table->icm[idx / MLX4_TABLE_CHUNK_SIZE];
297 dma_offset = offset = idx % MLX4_TABLE_CHUNK_SIZE; 302 dma_offset = offset = idx % MLX4_TABLE_CHUNK_SIZE;
298 303
@@ -326,10 +331,11 @@ out:
326} 331}
327 332
328int mlx4_table_get_range(struct mlx4_dev *dev, struct mlx4_icm_table *table, 333int mlx4_table_get_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
329 int start, int end) 334 u32 start, u32 end)
330{ 335{
331 int inc = MLX4_TABLE_CHUNK_SIZE / table->obj_size; 336 int inc = MLX4_TABLE_CHUNK_SIZE / table->obj_size;
332 int i, err; 337 int err;
338 u32 i;
333 339
334 for (i = start; i <= end; i += inc) { 340 for (i = start; i <= end; i += inc) {
335 err = mlx4_table_get(dev, table, i); 341 err = mlx4_table_get(dev, table, i);
@@ -349,9 +355,9 @@ fail:
349} 355}
350 356
351void mlx4_table_put_range(struct mlx4_dev *dev, struct mlx4_icm_table *table, 357void mlx4_table_put_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
352 int start, int end) 358 u32 start, u32 end)
353{ 359{
354 int i; 360 u32 i;
355 361
356 for (i = start; i <= end; i += MLX4_TABLE_CHUNK_SIZE / table->obj_size) 362 for (i = start; i <= end; i += MLX4_TABLE_CHUNK_SIZE / table->obj_size)
357 mlx4_table_put(dev, table, i); 363 mlx4_table_put(dev, table, i);
diff --git a/drivers/net/ethernet/mellanox/mlx4/icm.h b/drivers/net/ethernet/mellanox/mlx4/icm.h
index a67744f53506..dee67fa39107 100644
--- a/drivers/net/ethernet/mellanox/mlx4/icm.h
+++ b/drivers/net/ethernet/mellanox/mlx4/icm.h
@@ -71,17 +71,17 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,
71 gfp_t gfp_mask, int coherent); 71 gfp_t gfp_mask, int coherent);
72void mlx4_free_icm(struct mlx4_dev *dev, struct mlx4_icm *icm, int coherent); 72void mlx4_free_icm(struct mlx4_dev *dev, struct mlx4_icm *icm, int coherent);
73 73
74int mlx4_table_get(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj); 74int mlx4_table_get(struct mlx4_dev *dev, struct mlx4_icm_table *table, u32 obj);
75void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj); 75void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, u32 obj);
76int mlx4_table_get_range(struct mlx4_dev *dev, struct mlx4_icm_table *table, 76int mlx4_table_get_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
77 int start, int end); 77 u32 start, u32 end);
78void mlx4_table_put_range(struct mlx4_dev *dev, struct mlx4_icm_table *table, 78void mlx4_table_put_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
79 int start, int end); 79 u32 start, u32 end);
80int mlx4_init_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table, 80int mlx4_init_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table,
81 u64 virt, int obj_size, u32 nobj, int reserved, 81 u64 virt, int obj_size, u32 nobj, int reserved,
82 int use_lowmem, int use_coherent); 82 int use_lowmem, int use_coherent);
83void mlx4_cleanup_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table); 83void mlx4_cleanup_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table);
84void *mlx4_table_find(struct mlx4_icm_table *table, int obj, dma_addr_t *dma_handle); 84void *mlx4_table_find(struct mlx4_icm_table *table, u32 obj, dma_addr_t *dma_handle);
85 85
86static inline void mlx4_icm_first(struct mlx4_icm *icm, 86static inline void mlx4_icm_first(struct mlx4_icm *icm,
87 struct mlx4_icm_iter *iter) 87 struct mlx4_icm_iter *iter)
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 827b72dfce99..2f816c6aed72 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -1234,13 +1234,13 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
1234 mlx4_info(dev, "non-primary physical function, skipping.\n"); 1234 mlx4_info(dev, "non-primary physical function, skipping.\n");
1235 else 1235 else
1236 mlx4_err(dev, "QUERY_FW command failed, aborting.\n"); 1236 mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
1237 goto unmap_bf; 1237 return err;
1238 } 1238 }
1239 1239
1240 err = mlx4_load_fw(dev); 1240 err = mlx4_load_fw(dev);
1241 if (err) { 1241 if (err) {
1242 mlx4_err(dev, "Failed to start FW, aborting.\n"); 1242 mlx4_err(dev, "Failed to start FW, aborting.\n");
1243 goto unmap_bf; 1243 return err;
1244 } 1244 }
1245 1245
1246 mlx4_cfg.log_pg_sz_m = 1; 1246 mlx4_cfg.log_pg_sz_m = 1;
@@ -1304,7 +1304,7 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
1304 err = mlx4_init_slave(dev); 1304 err = mlx4_init_slave(dev);
1305 if (err) { 1305 if (err) {
1306 mlx4_err(dev, "Failed to initialize slave\n"); 1306 mlx4_err(dev, "Failed to initialize slave\n");
1307 goto unmap_bf; 1307 return err;
1308 } 1308 }
1309 1309
1310 err = mlx4_slave_cap(dev); 1310 err = mlx4_slave_cap(dev);
@@ -1324,7 +1324,7 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
1324 err = mlx4_QUERY_ADAPTER(dev, &adapter); 1324 err = mlx4_QUERY_ADAPTER(dev, &adapter);
1325 if (err) { 1325 if (err) {
1326 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n"); 1326 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
1327 goto err_close; 1327 goto unmap_bf;
1328 } 1328 }
1329 1329
1330 priv->eq_table.inta_pin = adapter.inta_pin; 1330 priv->eq_table.inta_pin = adapter.inta_pin;
@@ -1332,6 +1332,9 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
1332 1332
1333 return 0; 1333 return 0;
1334 1334
1335unmap_bf:
1336 unmap_bf_area(dev);
1337
1335err_close: 1338err_close:
1336 mlx4_close_hca(dev); 1339 mlx4_close_hca(dev);
1337 1340
@@ -1344,8 +1347,6 @@ err_stop_fw:
1344 mlx4_UNMAP_FA(dev); 1347 mlx4_UNMAP_FA(dev);
1345 mlx4_free_icm(dev, priv->fw.fw_icm, 0); 1348 mlx4_free_icm(dev, priv->fw.fw_icm, 0);
1346 } 1349 }
1347unmap_bf:
1348 unmap_bf_area(dev);
1349 return err; 1350 return err;
1350} 1351}
1351 1352
@@ -1996,7 +1997,8 @@ static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
1996 } 1997 }
1997 1998
1998slave_start: 1999slave_start:
1999 if (mlx4_cmd_init(dev)) { 2000 err = mlx4_cmd_init(dev);
2001 if (err) {
2000 mlx4_err(dev, "Failed to init command interface, aborting.\n"); 2002 mlx4_err(dev, "Failed to init command interface, aborting.\n");
2001 goto err_sriov; 2003 goto err_sriov;
2002 } 2004 }
diff --git a/drivers/net/ethernet/mellanox/mlx4/mcg.c b/drivers/net/ethernet/mellanox/mlx4/mcg.c
index a018ea2a43de..e151c21baf2b 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mcg.c
+++ b/drivers/net/ethernet/mellanox/mlx4/mcg.c
@@ -137,11 +137,11 @@ static int mlx4_GID_HASH(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
137 return err; 137 return err;
138} 138}
139 139
140static struct mlx4_promisc_qp *get_promisc_qp(struct mlx4_dev *dev, u8 pf_num, 140static struct mlx4_promisc_qp *get_promisc_qp(struct mlx4_dev *dev, u8 port,
141 enum mlx4_steer_type steer, 141 enum mlx4_steer_type steer,
142 u32 qpn) 142 u32 qpn)
143{ 143{
144 struct mlx4_steer *s_steer = &mlx4_priv(dev)->steer[pf_num]; 144 struct mlx4_steer *s_steer = &mlx4_priv(dev)->steer[port - 1];
145 struct mlx4_promisc_qp *pqp; 145 struct mlx4_promisc_qp *pqp;
146 146
147 list_for_each_entry(pqp, &s_steer->promisc_qps[steer], list) { 147 list_for_each_entry(pqp, &s_steer->promisc_qps[steer], list) {
@@ -182,7 +182,7 @@ static int new_steering_entry(struct mlx4_dev *dev, u8 port,
182 /* If the given qpn is also a promisc qp, 182 /* If the given qpn is also a promisc qp,
183 * it should be inserted to duplicates list 183 * it should be inserted to duplicates list
184 */ 184 */
185 pqp = get_promisc_qp(dev, 0, steer, qpn); 185 pqp = get_promisc_qp(dev, port, steer, qpn);
186 if (pqp) { 186 if (pqp) {
187 dqp = kmalloc(sizeof *dqp, GFP_KERNEL); 187 dqp = kmalloc(sizeof *dqp, GFP_KERNEL);
188 if (!dqp) { 188 if (!dqp) {
@@ -256,7 +256,7 @@ static int existing_steering_entry(struct mlx4_dev *dev, u8 port,
256 256
257 s_steer = &mlx4_priv(dev)->steer[port - 1]; 257 s_steer = &mlx4_priv(dev)->steer[port - 1];
258 258
259 pqp = get_promisc_qp(dev, 0, steer, qpn); 259 pqp = get_promisc_qp(dev, port, steer, qpn);
260 if (!pqp) 260 if (!pqp)
261 return 0; /* nothing to do */ 261 return 0; /* nothing to do */
262 262
@@ -302,7 +302,7 @@ static bool check_duplicate_entry(struct mlx4_dev *dev, u8 port,
302 s_steer = &mlx4_priv(dev)->steer[port - 1]; 302 s_steer = &mlx4_priv(dev)->steer[port - 1];
303 303
304 /* if qp is not promisc, it cannot be duplicated */ 304 /* if qp is not promisc, it cannot be duplicated */
305 if (!get_promisc_qp(dev, 0, steer, qpn)) 305 if (!get_promisc_qp(dev, port, steer, qpn))
306 return false; 306 return false;
307 307
308 /* The qp is promisc qp so it is a duplicate on this index 308 /* The qp is promisc qp so it is a duplicate on this index
@@ -352,7 +352,7 @@ static bool can_remove_steering_entry(struct mlx4_dev *dev, u8 port,
352 members_count = be32_to_cpu(mgm->members_count) & 0xffffff; 352 members_count = be32_to_cpu(mgm->members_count) & 0xffffff;
353 for (i = 0; i < members_count; i++) { 353 for (i = 0; i < members_count; i++) {
354 qpn = be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK; 354 qpn = be32_to_cpu(mgm->qp[i]) & MGM_QPN_MASK;
355 if (!get_promisc_qp(dev, 0, steer, qpn) && qpn != tqpn) { 355 if (!get_promisc_qp(dev, port, steer, qpn) && qpn != tqpn) {
356 /* the qp is not promisc, the entry can't be removed */ 356 /* the qp is not promisc, the entry can't be removed */
357 goto out; 357 goto out;
358 } 358 }
@@ -398,7 +398,7 @@ static int add_promisc_qp(struct mlx4_dev *dev, u8 port,
398 398
399 mutex_lock(&priv->mcg_table.mutex); 399 mutex_lock(&priv->mcg_table.mutex);
400 400
401 if (get_promisc_qp(dev, 0, steer, qpn)) { 401 if (get_promisc_qp(dev, port, steer, qpn)) {
402 err = 0; /* Noting to do, already exists */ 402 err = 0; /* Noting to do, already exists */
403 goto out_mutex; 403 goto out_mutex;
404 } 404 }
@@ -503,7 +503,7 @@ static int remove_promisc_qp(struct mlx4_dev *dev, u8 port,
503 s_steer = &mlx4_priv(dev)->steer[port - 1]; 503 s_steer = &mlx4_priv(dev)->steer[port - 1];
504 mutex_lock(&priv->mcg_table.mutex); 504 mutex_lock(&priv->mcg_table.mutex);
505 505
506 pqp = get_promisc_qp(dev, 0, steer, qpn); 506 pqp = get_promisc_qp(dev, port, steer, qpn);
507 if (unlikely(!pqp)) { 507 if (unlikely(!pqp)) {
508 mlx4_warn(dev, "QP %x is not promiscuous QP\n", qpn); 508 mlx4_warn(dev, "QP %x is not promiscuous QP\n", qpn);
509 /* nothing to do */ 509 /* nothing to do */
@@ -650,13 +650,6 @@ static int find_entry(struct mlx4_dev *dev, u8 port,
650 return err; 650 return err;
651} 651}
652 652
653struct mlx4_net_trans_rule_hw_ctrl {
654 __be32 ctrl;
655 __be32 vf_vep_port;
656 __be32 qpn;
657 __be32 reserved;
658};
659
660static void trans_rule_ctrl_to_hw(struct mlx4_net_trans_rule *ctrl, 653static void trans_rule_ctrl_to_hw(struct mlx4_net_trans_rule *ctrl,
661 struct mlx4_net_trans_rule_hw_ctrl *hw) 654 struct mlx4_net_trans_rule_hw_ctrl *hw)
662{ 655{
@@ -680,87 +673,18 @@ static void trans_rule_ctrl_to_hw(struct mlx4_net_trans_rule *ctrl,
680 hw->qpn = cpu_to_be32(ctrl->qpn); 673 hw->qpn = cpu_to_be32(ctrl->qpn);
681} 674}
682 675
683struct mlx4_net_trans_rule_hw_ib { 676const u16 __sw_id_hw[] = {
684 u8 size; 677 [MLX4_NET_TRANS_RULE_ID_ETH] = 0xE001,
685 u8 rsvd1; 678 [MLX4_NET_TRANS_RULE_ID_IB] = 0xE005,
686 __be16 id; 679 [MLX4_NET_TRANS_RULE_ID_IPV6] = 0xE003,
687 u32 rsvd2; 680 [MLX4_NET_TRANS_RULE_ID_IPV4] = 0xE002,
688 __be32 qpn; 681 [MLX4_NET_TRANS_RULE_ID_TCP] = 0xE004,
689 __be32 qpn_mask; 682 [MLX4_NET_TRANS_RULE_ID_UDP] = 0xE006
690 u8 dst_gid[16];
691 u8 dst_gid_msk[16];
692} __packed;
693
694struct mlx4_net_trans_rule_hw_eth {
695 u8 size;
696 u8 rsvd;
697 __be16 id;
698 u8 rsvd1[6];
699 u8 dst_mac[6];
700 u16 rsvd2;
701 u8 dst_mac_msk[6];
702 u16 rsvd3;
703 u8 src_mac[6];
704 u16 rsvd4;
705 u8 src_mac_msk[6];
706 u8 rsvd5;
707 u8 ether_type_enable;
708 __be16 ether_type;
709 __be16 vlan_id_msk;
710 __be16 vlan_id;
711} __packed;
712
713struct mlx4_net_trans_rule_hw_tcp_udp {
714 u8 size;
715 u8 rsvd;
716 __be16 id;
717 __be16 rsvd1[3];
718 __be16 dst_port;
719 __be16 rsvd2;
720 __be16 dst_port_msk;
721 __be16 rsvd3;
722 __be16 src_port;
723 __be16 rsvd4;
724 __be16 src_port_msk;
725} __packed;
726
727struct mlx4_net_trans_rule_hw_ipv4 {
728 u8 size;
729 u8 rsvd;
730 __be16 id;
731 __be32 rsvd1;
732 __be32 dst_ip;
733 __be32 dst_ip_msk;
734 __be32 src_ip;
735 __be32 src_ip_msk;
736} __packed;
737
738struct _rule_hw {
739 union {
740 struct {
741 u8 size;
742 u8 rsvd;
743 __be16 id;
744 };
745 struct mlx4_net_trans_rule_hw_eth eth;
746 struct mlx4_net_trans_rule_hw_ib ib;
747 struct mlx4_net_trans_rule_hw_ipv4 ipv4;
748 struct mlx4_net_trans_rule_hw_tcp_udp tcp_udp;
749 };
750}; 683};
751 684
752static int parse_trans_rule(struct mlx4_dev *dev, struct mlx4_spec_list *spec, 685static int parse_trans_rule(struct mlx4_dev *dev, struct mlx4_spec_list *spec,
753 struct _rule_hw *rule_hw) 686 struct _rule_hw *rule_hw)
754{ 687{
755 static const u16 __sw_id_hw[] = {
756 [MLX4_NET_TRANS_RULE_ID_ETH] = 0xE001,
757 [MLX4_NET_TRANS_RULE_ID_IB] = 0xE005,
758 [MLX4_NET_TRANS_RULE_ID_IPV6] = 0xE003,
759 [MLX4_NET_TRANS_RULE_ID_IPV4] = 0xE002,
760 [MLX4_NET_TRANS_RULE_ID_TCP] = 0xE004,
761 [MLX4_NET_TRANS_RULE_ID_UDP] = 0xE006
762 };
763
764 static const size_t __rule_hw_sz[] = { 688 static const size_t __rule_hw_sz[] = {
765 [MLX4_NET_TRANS_RULE_ID_ETH] = 689 [MLX4_NET_TRANS_RULE_ID_ETH] =
766 sizeof(struct mlx4_net_trans_rule_hw_eth), 690 sizeof(struct mlx4_net_trans_rule_hw_eth),
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
index 4d9df8f2a126..dba69d98734a 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
@@ -690,6 +690,82 @@ struct mlx4_steer {
690 struct list_head steer_entries[MLX4_NUM_STEERS]; 690 struct list_head steer_entries[MLX4_NUM_STEERS];
691}; 691};
692 692
693struct mlx4_net_trans_rule_hw_ctrl {
694 __be32 ctrl;
695 __be32 vf_vep_port;
696 __be32 qpn;
697 __be32 reserved;
698};
699
700struct mlx4_net_trans_rule_hw_ib {
701 u8 size;
702 u8 rsvd1;
703 __be16 id;
704 u32 rsvd2;
705 __be32 qpn;
706 __be32 qpn_mask;
707 u8 dst_gid[16];
708 u8 dst_gid_msk[16];
709} __packed;
710
711struct mlx4_net_trans_rule_hw_eth {
712 u8 size;
713 u8 rsvd;
714 __be16 id;
715 u8 rsvd1[6];
716 u8 dst_mac[6];
717 u16 rsvd2;
718 u8 dst_mac_msk[6];
719 u16 rsvd3;
720 u8 src_mac[6];
721 u16 rsvd4;
722 u8 src_mac_msk[6];
723 u8 rsvd5;
724 u8 ether_type_enable;
725 __be16 ether_type;
726 __be16 vlan_id_msk;
727 __be16 vlan_id;
728} __packed;
729
730struct mlx4_net_trans_rule_hw_tcp_udp {
731 u8 size;
732 u8 rsvd;
733 __be16 id;
734 __be16 rsvd1[3];
735 __be16 dst_port;
736 __be16 rsvd2;
737 __be16 dst_port_msk;
738 __be16 rsvd3;
739 __be16 src_port;
740 __be16 rsvd4;
741 __be16 src_port_msk;
742} __packed;
743
744struct mlx4_net_trans_rule_hw_ipv4 {
745 u8 size;
746 u8 rsvd;
747 __be16 id;
748 __be32 rsvd1;
749 __be32 dst_ip;
750 __be32 dst_ip_msk;
751 __be32 src_ip;
752 __be32 src_ip_msk;
753} __packed;
754
755struct _rule_hw {
756 union {
757 struct {
758 u8 size;
759 u8 rsvd;
760 __be16 id;
761 };
762 struct mlx4_net_trans_rule_hw_eth eth;
763 struct mlx4_net_trans_rule_hw_ib ib;
764 struct mlx4_net_trans_rule_hw_ipv4 ipv4;
765 struct mlx4_net_trans_rule_hw_tcp_udp tcp_udp;
766 };
767};
768
693struct mlx4_priv { 769struct mlx4_priv {
694 struct mlx4_dev dev; 770 struct mlx4_dev dev;
695 771
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index 94ceddd17ab2..293c9e820c49 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -42,6 +42,7 @@
42#include <linux/mlx4/cmd.h> 42#include <linux/mlx4/cmd.h>
43#include <linux/mlx4/qp.h> 43#include <linux/mlx4/qp.h>
44#include <linux/if_ether.h> 44#include <linux/if_ether.h>
45#include <linux/etherdevice.h>
45 46
46#include "mlx4.h" 47#include "mlx4.h"
47#include "fw.h" 48#include "fw.h"
@@ -2776,18 +2777,133 @@ ex_put:
2776 return err; 2777 return err;
2777} 2778}
2778 2779
2780/*
2781 * MAC validation for Flow Steering rules.
2782 * VF can attach rules only with a mac address which is assigned to it.
2783 */
2784static int validate_eth_header_mac(int slave, struct _rule_hw *eth_header,
2785 struct list_head *rlist)
2786{
2787 struct mac_res *res, *tmp;
2788 __be64 be_mac;
2789
2790 /* make sure it isn't multicast or broadcast mac*/
2791 if (!is_multicast_ether_addr(eth_header->eth.dst_mac) &&
2792 !is_broadcast_ether_addr(eth_header->eth.dst_mac)) {
2793 list_for_each_entry_safe(res, tmp, rlist, list) {
2794 be_mac = cpu_to_be64(res->mac << 16);
2795 if (!memcmp(&be_mac, eth_header->eth.dst_mac, ETH_ALEN))
2796 return 0;
2797 }
2798 pr_err("MAC %pM doesn't belong to VF %d, Steering rule rejected\n",
2799 eth_header->eth.dst_mac, slave);
2800 return -EINVAL;
2801 }
2802 return 0;
2803}
2804
2805/*
2806 * In case of missing eth header, append eth header with a MAC address
2807 * assigned to the VF.
2808 */
2809static int add_eth_header(struct mlx4_dev *dev, int slave,
2810 struct mlx4_cmd_mailbox *inbox,
2811 struct list_head *rlist, int header_id)
2812{
2813 struct mac_res *res, *tmp;
2814 u8 port;
2815 struct mlx4_net_trans_rule_hw_ctrl *ctrl;
2816 struct mlx4_net_trans_rule_hw_eth *eth_header;
2817 struct mlx4_net_trans_rule_hw_ipv4 *ip_header;
2818 struct mlx4_net_trans_rule_hw_tcp_udp *l4_header;
2819 __be64 be_mac = 0;
2820 __be64 mac_msk = cpu_to_be64(MLX4_MAC_MASK << 16);
2821
2822 ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)inbox->buf;
2823 port = be32_to_cpu(ctrl->vf_vep_port) & 0xff;
2824 eth_header = (struct mlx4_net_trans_rule_hw_eth *)(ctrl + 1);
2825
2826 /* Clear a space in the inbox for eth header */
2827 switch (header_id) {
2828 case MLX4_NET_TRANS_RULE_ID_IPV4:
2829 ip_header =
2830 (struct mlx4_net_trans_rule_hw_ipv4 *)(eth_header + 1);
2831 memmove(ip_header, eth_header,
2832 sizeof(*ip_header) + sizeof(*l4_header));
2833 break;
2834 case MLX4_NET_TRANS_RULE_ID_TCP:
2835 case MLX4_NET_TRANS_RULE_ID_UDP:
2836 l4_header = (struct mlx4_net_trans_rule_hw_tcp_udp *)
2837 (eth_header + 1);
2838 memmove(l4_header, eth_header, sizeof(*l4_header));
2839 break;
2840 default:
2841 return -EINVAL;
2842 }
2843 list_for_each_entry_safe(res, tmp, rlist, list) {
2844 if (port == res->port) {
2845 be_mac = cpu_to_be64(res->mac << 16);
2846 break;
2847 }
2848 }
2849 if (!be_mac) {
2850 pr_err("Failed adding eth header to FS rule, Can't find matching MAC for port %d .\n",
2851 port);
2852 return -EINVAL;
2853 }
2854
2855 memset(eth_header, 0, sizeof(*eth_header));
2856 eth_header->size = sizeof(*eth_header) >> 2;
2857 eth_header->id = cpu_to_be16(__sw_id_hw[MLX4_NET_TRANS_RULE_ID_ETH]);
2858 memcpy(eth_header->dst_mac, &be_mac, ETH_ALEN);
2859 memcpy(eth_header->dst_mac_msk, &mac_msk, ETH_ALEN);
2860
2861 return 0;
2862
2863}
2864
2779int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave, 2865int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
2780 struct mlx4_vhcr *vhcr, 2866 struct mlx4_vhcr *vhcr,
2781 struct mlx4_cmd_mailbox *inbox, 2867 struct mlx4_cmd_mailbox *inbox,
2782 struct mlx4_cmd_mailbox *outbox, 2868 struct mlx4_cmd_mailbox *outbox,
2783 struct mlx4_cmd_info *cmd) 2869 struct mlx4_cmd_info *cmd)
2784{ 2870{
2871
2872 struct mlx4_priv *priv = mlx4_priv(dev);
2873 struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
2874 struct list_head *rlist = &tracker->slave_list[slave].res_list[RES_MAC];
2785 int err; 2875 int err;
2876 struct mlx4_net_trans_rule_hw_ctrl *ctrl;
2877 struct _rule_hw *rule_header;
2878 int header_id;
2786 2879
2787 if (dev->caps.steering_mode != 2880 if (dev->caps.steering_mode !=
2788 MLX4_STEERING_MODE_DEVICE_MANAGED) 2881 MLX4_STEERING_MODE_DEVICE_MANAGED)
2789 return -EOPNOTSUPP; 2882 return -EOPNOTSUPP;
2790 2883
2884 ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)inbox->buf;
2885 rule_header = (struct _rule_hw *)(ctrl + 1);
2886 header_id = map_hw_to_sw_id(be16_to_cpu(rule_header->id));
2887
2888 switch (header_id) {
2889 case MLX4_NET_TRANS_RULE_ID_ETH:
2890 if (validate_eth_header_mac(slave, rule_header, rlist))
2891 return -EINVAL;
2892 break;
2893 case MLX4_NET_TRANS_RULE_ID_IPV4:
2894 case MLX4_NET_TRANS_RULE_ID_TCP:
2895 case MLX4_NET_TRANS_RULE_ID_UDP:
2896 pr_warn("Can't attach FS rule without L2 headers, adding L2 header.\n");
2897 if (add_eth_header(dev, slave, inbox, rlist, header_id))
2898 return -EINVAL;
2899 vhcr->in_modifier +=
2900 sizeof(struct mlx4_net_trans_rule_hw_eth) >> 2;
2901 break;
2902 default:
2903 pr_err("Corrupted mailbox.\n");
2904 return -EINVAL;
2905 }
2906
2791 err = mlx4_cmd_imm(dev, inbox->dma, &vhcr->out_param, 2907 err = mlx4_cmd_imm(dev, inbox->dma, &vhcr->out_param,
2792 vhcr->in_modifier, 0, 2908 vhcr->in_modifier, 0,
2793 MLX4_QP_FLOW_STEERING_ATTACH, MLX4_CMD_TIME_CLASS_A, 2909 MLX4_QP_FLOW_STEERING_ATTACH, MLX4_CMD_TIME_CLASS_A,
diff --git a/drivers/net/ethernet/octeon/octeon_mgmt.c b/drivers/net/ethernet/octeon/octeon_mgmt.c
index c42bbb16cdae..a688a2ddcfd6 100644
--- a/drivers/net/ethernet/octeon/octeon_mgmt.c
+++ b/drivers/net/ethernet/octeon/octeon_mgmt.c
@@ -722,10 +722,8 @@ static int octeon_mgmt_init_phy(struct net_device *netdev)
722 octeon_mgmt_adjust_link, 0, 722 octeon_mgmt_adjust_link, 0,
723 PHY_INTERFACE_MODE_MII); 723 PHY_INTERFACE_MODE_MII);
724 724
725 if (IS_ERR(p->phydev)) { 725 if (!p->phydev)
726 p->phydev = NULL;
727 return -1; 726 return -1;
728 }
729 727
730 phy_start_aneg(p->phydev); 728 phy_start_aneg(p->phydev);
731 729
diff --git a/drivers/net/ethernet/pasemi/pasemi_mac.c b/drivers/net/ethernet/pasemi/pasemi_mac.c
index e559dfa06d6a..6fa74d530e44 100644
--- a/drivers/net/ethernet/pasemi/pasemi_mac.c
+++ b/drivers/net/ethernet/pasemi/pasemi_mac.c
@@ -1101,9 +1101,9 @@ static int pasemi_mac_phy_init(struct net_device *dev)
1101 phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0, 1101 phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0,
1102 PHY_INTERFACE_MODE_SGMII); 1102 PHY_INTERFACE_MODE_SGMII);
1103 1103
1104 if (IS_ERR(phydev)) { 1104 if (!phydev) {
1105 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name); 1105 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
1106 return PTR_ERR(phydev); 1106 return -ENODEV;
1107 } 1107 }
1108 1108
1109 mac->phydev = phydev; 1109 mac->phydev = phydev;
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
index 342b3a79bd0f..a77c558d8f40 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
@@ -1378,6 +1378,10 @@ static void netxen_mask_aer_correctable(struct netxen_adapter *adapter)
1378 struct pci_dev *root = pdev->bus->self; 1378 struct pci_dev *root = pdev->bus->self;
1379 u32 aer_pos; 1379 u32 aer_pos;
1380 1380
1381 /* root bus? */
1382 if (!root)
1383 return;
1384
1381 if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM && 1385 if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM &&
1382 adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP) 1386 adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP)
1383 return; 1387 return;
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
index b8ead696141e..2a179d087207 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
@@ -15,7 +15,7 @@ qlcnic_poll_rsp(struct qlcnic_adapter *adapter)
15 15
16 do { 16 do {
17 /* give atleast 1ms for firmware to respond */ 17 /* give atleast 1ms for firmware to respond */
18 msleep(1); 18 mdelay(1);
19 19
20 if (++timeout > QLCNIC_OS_CRB_RETRY_COUNT) 20 if (++timeout > QLCNIC_OS_CRB_RETRY_COUNT)
21 return QLCNIC_CDRP_RSP_TIMEOUT; 21 return QLCNIC_CDRP_RSP_TIMEOUT;
@@ -601,7 +601,7 @@ void qlcnic_fw_destroy_ctx(struct qlcnic_adapter *adapter)
601 qlcnic_fw_cmd_destroy_tx_ctx(adapter); 601 qlcnic_fw_cmd_destroy_tx_ctx(adapter);
602 602
603 /* Allow dma queues to drain after context reset */ 603 /* Allow dma queues to drain after context reset */
604 msleep(20); 604 mdelay(20);
605 } 605 }
606} 606}
607 607
diff --git a/drivers/net/ethernet/seeq/sgiseeq.c b/drivers/net/ethernet/seeq/sgiseeq.c
index bb8c8222122b..4d15bf413bdc 100644
--- a/drivers/net/ethernet/seeq/sgiseeq.c
+++ b/drivers/net/ethernet/seeq/sgiseeq.c
@@ -751,6 +751,7 @@ static int __devinit sgiseeq_probe(struct platform_device *pdev)
751 sp->srings = sr; 751 sp->srings = sr;
752 sp->rx_desc = sp->srings->rxvector; 752 sp->rx_desc = sp->srings->rxvector;
753 sp->tx_desc = sp->srings->txvector; 753 sp->tx_desc = sp->srings->txvector;
754 spin_lock_init(&sp->tx_lock);
754 755
755 /* A couple calculations now, saves many cycles later. */ 756 /* A couple calculations now, saves many cycles later. */
756 setup_rx_ring(dev, sp->rx_desc, SEEQ_RX_BUFFERS); 757 setup_rx_ring(dev, sp->rx_desc, SEEQ_RX_BUFFERS);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c136162e6473..3be88331d17a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1066,7 +1066,7 @@ static int stmmac_open(struct net_device *dev)
1066 } else 1066 } else
1067 priv->tm->enable = 1; 1067 priv->tm->enable = 1;
1068#endif 1068#endif
1069 clk_enable(priv->stmmac_clk); 1069 clk_prepare_enable(priv->stmmac_clk);
1070 1070
1071 stmmac_check_ether_addr(priv); 1071 stmmac_check_ether_addr(priv);
1072 1072
@@ -1188,7 +1188,7 @@ open_error:
1188 if (priv->phydev) 1188 if (priv->phydev)
1189 phy_disconnect(priv->phydev); 1189 phy_disconnect(priv->phydev);
1190 1190
1191 clk_disable(priv->stmmac_clk); 1191 clk_disable_unprepare(priv->stmmac_clk);
1192 1192
1193 return ret; 1193 return ret;
1194} 1194}
@@ -1246,7 +1246,7 @@ static int stmmac_release(struct net_device *dev)
1246#ifdef CONFIG_STMMAC_DEBUG_FS 1246#ifdef CONFIG_STMMAC_DEBUG_FS
1247 stmmac_exit_fs(); 1247 stmmac_exit_fs();
1248#endif 1248#endif
1249 clk_disable(priv->stmmac_clk); 1249 clk_disable_unprepare(priv->stmmac_clk);
1250 1250
1251 return 0; 1251 return 0;
1252} 1252}
@@ -2178,7 +2178,7 @@ int stmmac_suspend(struct net_device *ndev)
2178 else { 2178 else {
2179 stmmac_set_mac(priv->ioaddr, false); 2179 stmmac_set_mac(priv->ioaddr, false);
2180 /* Disable clock in case of PWM is off */ 2180 /* Disable clock in case of PWM is off */
2181 clk_disable(priv->stmmac_clk); 2181 clk_disable_unprepare(priv->stmmac_clk);
2182 } 2182 }
2183 spin_unlock_irqrestore(&priv->lock, flags); 2183 spin_unlock_irqrestore(&priv->lock, flags);
2184 return 0; 2184 return 0;
@@ -2203,7 +2203,7 @@ int stmmac_resume(struct net_device *ndev)
2203 priv->hw->mac->pmt(priv->ioaddr, 0); 2203 priv->hw->mac->pmt(priv->ioaddr, 0);
2204 else 2204 else
2205 /* enable the clk prevously disabled */ 2205 /* enable the clk prevously disabled */
2206 clk_enable(priv->stmmac_clk); 2206 clk_prepare_enable(priv->stmmac_clk);
2207 2207
2208 netif_device_attach(ndev); 2208 netif_device_attach(ndev);
2209 2209
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_timer.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_timer.c
index 2a0e1abde7e7..4ccd4e2977b7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_timer.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_timer.c
@@ -97,19 +97,19 @@ static struct clk *timer_clock;
97static void stmmac_tmu_start(unsigned int new_freq) 97static void stmmac_tmu_start(unsigned int new_freq)
98{ 98{
99 clk_set_rate(timer_clock, new_freq); 99 clk_set_rate(timer_clock, new_freq);
100 clk_enable(timer_clock); 100 clk_prepare_enable(timer_clock);
101} 101}
102 102
103static void stmmac_tmu_stop(void) 103static void stmmac_tmu_stop(void)
104{ 104{
105 clk_disable(timer_clock); 105 clk_disable_unprepare(timer_clock);
106} 106}
107 107
108int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm) 108int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm)
109{ 109{
110 timer_clock = clk_get(NULL, TMU_CHANNEL); 110 timer_clock = clk_get(NULL, TMU_CHANNEL);
111 111
112 if (timer_clock == NULL) 112 if (IS_ERR(timer_clock))
113 return -1; 113 return -1;
114 114
115 if (tmu2_register_user(stmmac_timer_handler, (void *)dev) < 0) { 115 if (tmu2_register_user(stmmac_timer_handler, (void *)dev) < 0) {
@@ -126,7 +126,7 @@ int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm)
126 126
127int stmmac_close_ext_timer(void) 127int stmmac_close_ext_timer(void)
128{ 128{
129 clk_disable(timer_clock); 129 clk_disable_unprepare(timer_clock);
130 tmu2_unregister_user(); 130 tmu2_unregister_user();
131 clk_put(timer_clock); 131 clk_put(timer_clock);
132 return 0; 132 return 0;
diff --git a/drivers/net/irda/sh_sir.c b/drivers/net/irda/sh_sir.c
index 256eddf1f75a..795109425568 100644
--- a/drivers/net/irda/sh_sir.c
+++ b/drivers/net/irda/sh_sir.c
@@ -280,7 +280,7 @@ static int sh_sir_set_baudrate(struct sh_sir_self *self, u32 baudrate)
280 } 280 }
281 281
282 clk = clk_get(NULL, "irda_clk"); 282 clk = clk_get(NULL, "irda_clk");
283 if (!clk) { 283 if (IS_ERR(clk)) {
284 dev_err(dev, "can not get irda_clk\n"); 284 dev_err(dev, "can not get irda_clk\n");
285 return -EIO; 285 return -EIO;
286 } 286 }
diff --git a/drivers/net/phy/bcm87xx.c b/drivers/net/phy/bcm87xx.c
index 2346b38b9837..799789518e87 100644
--- a/drivers/net/phy/bcm87xx.c
+++ b/drivers/net/phy/bcm87xx.c
@@ -229,3 +229,5 @@ static void __exit bcm87xx_exit(void)
229 ARRAY_SIZE(bcm87xx_driver)); 229 ARRAY_SIZE(bcm87xx_driver));
230} 230}
231module_exit(bcm87xx_exit); 231module_exit(bcm87xx_exit);
232
233MODULE_LICENSE("GPL");
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index cf287e0eb408..2165d5fdb8c0 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -21,6 +21,12 @@
21#include <linux/phy.h> 21#include <linux/phy.h>
22#include <linux/micrel_phy.h> 22#include <linux/micrel_phy.h>
23 23
24/* Operation Mode Strap Override */
25#define MII_KSZPHY_OMSO 0x16
26#define KSZPHY_OMSO_B_CAST_OFF (1 << 9)
27#define KSZPHY_OMSO_RMII_OVERRIDE (1 << 1)
28#define KSZPHY_OMSO_MII_OVERRIDE (1 << 0)
29
24/* general Interrupt control/status reg in vendor specific block. */ 30/* general Interrupt control/status reg in vendor specific block. */
25#define MII_KSZPHY_INTCS 0x1B 31#define MII_KSZPHY_INTCS 0x1B
26#define KSZPHY_INTCS_JABBER (1 << 15) 32#define KSZPHY_INTCS_JABBER (1 << 15)
@@ -101,6 +107,13 @@ static int kszphy_config_init(struct phy_device *phydev)
101 return 0; 107 return 0;
102} 108}
103 109
110static int ksz8021_config_init(struct phy_device *phydev)
111{
112 const u16 val = KSZPHY_OMSO_B_CAST_OFF | KSZPHY_OMSO_RMII_OVERRIDE;
113 phy_write(phydev, MII_KSZPHY_OMSO, val);
114 return 0;
115}
116
104static int ks8051_config_init(struct phy_device *phydev) 117static int ks8051_config_init(struct phy_device *phydev)
105{ 118{
106 int regval; 119 int regval;
@@ -128,9 +141,22 @@ static struct phy_driver ksphy_driver[] = {
128 .config_intr = ks8737_config_intr, 141 .config_intr = ks8737_config_intr,
129 .driver = { .owner = THIS_MODULE,}, 142 .driver = { .owner = THIS_MODULE,},
130}, { 143}, {
131 .phy_id = PHY_ID_KS8041, 144 .phy_id = PHY_ID_KSZ8021,
145 .phy_id_mask = 0x00ffffff,
146 .name = "Micrel KSZ8021",
147 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
148 SUPPORTED_Asym_Pause),
149 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
150 .config_init = ksz8021_config_init,
151 .config_aneg = genphy_config_aneg,
152 .read_status = genphy_read_status,
153 .ack_interrupt = kszphy_ack_interrupt,
154 .config_intr = kszphy_config_intr,
155 .driver = { .owner = THIS_MODULE,},
156}, {
157 .phy_id = PHY_ID_KSZ8041,
132 .phy_id_mask = 0x00fffff0, 158 .phy_id_mask = 0x00fffff0,
133 .name = "Micrel KS8041", 159 .name = "Micrel KSZ8041",
134 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 160 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
135 | SUPPORTED_Asym_Pause), 161 | SUPPORTED_Asym_Pause),
136 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 162 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
@@ -141,9 +167,9 @@ static struct phy_driver ksphy_driver[] = {
141 .config_intr = kszphy_config_intr, 167 .config_intr = kszphy_config_intr,
142 .driver = { .owner = THIS_MODULE,}, 168 .driver = { .owner = THIS_MODULE,},
143}, { 169}, {
144 .phy_id = PHY_ID_KS8051, 170 .phy_id = PHY_ID_KSZ8051,
145 .phy_id_mask = 0x00fffff0, 171 .phy_id_mask = 0x00fffff0,
146 .name = "Micrel KS8051", 172 .name = "Micrel KSZ8051",
147 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 173 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
148 | SUPPORTED_Asym_Pause), 174 | SUPPORTED_Asym_Pause),
149 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 175 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
@@ -154,8 +180,8 @@ static struct phy_driver ksphy_driver[] = {
154 .config_intr = kszphy_config_intr, 180 .config_intr = kszphy_config_intr,
155 .driver = { .owner = THIS_MODULE,}, 181 .driver = { .owner = THIS_MODULE,},
156}, { 182}, {
157 .phy_id = PHY_ID_KS8001, 183 .phy_id = PHY_ID_KSZ8001,
158 .name = "Micrel KS8001 or KS8721", 184 .name = "Micrel KSZ8001 or KS8721",
159 .phy_id_mask = 0x00ffffff, 185 .phy_id_mask = 0x00ffffff,
160 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 186 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
161 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 187 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
@@ -201,10 +227,11 @@ MODULE_LICENSE("GPL");
201 227
202static struct mdio_device_id __maybe_unused micrel_tbl[] = { 228static struct mdio_device_id __maybe_unused micrel_tbl[] = {
203 { PHY_ID_KSZ9021, 0x000ffffe }, 229 { PHY_ID_KSZ9021, 0x000ffffe },
204 { PHY_ID_KS8001, 0x00ffffff }, 230 { PHY_ID_KSZ8001, 0x00ffffff },
205 { PHY_ID_KS8737, 0x00fffff0 }, 231 { PHY_ID_KS8737, 0x00fffff0 },
206 { PHY_ID_KS8041, 0x00fffff0 }, 232 { PHY_ID_KSZ8021, 0x00ffffff },
207 { PHY_ID_KS8051, 0x00fffff0 }, 233 { PHY_ID_KSZ8041, 0x00fffff0 },
234 { PHY_ID_KSZ8051, 0x00fffff0 },
208 { } 235 { }
209}; 236};
210 237
diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index 6d6192316b30..88e3991464e7 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -56,6 +56,32 @@ static int smsc_phy_config_init(struct phy_device *phydev)
56 return smsc_phy_ack_interrupt (phydev); 56 return smsc_phy_ack_interrupt (phydev);
57} 57}
58 58
59static int lan87xx_config_init(struct phy_device *phydev)
60{
61 /*
62 * Make sure the EDPWRDOWN bit is NOT set. Setting this bit on
63 * LAN8710/LAN8720 PHY causes the PHY to misbehave, likely due
64 * to a bug on the chip.
65 *
66 * When the system is powered on with the network cable being
67 * disconnected all the way until after ifconfig ethX up is
68 * issued for the LAN port with this PHY, connecting the cable
69 * afterwards does not cause LINK change detection, while the
70 * expected behavior is the Link UP being detected.
71 */
72 int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
73 if (rc < 0)
74 return rc;
75
76 rc &= ~MII_LAN83C185_EDPWRDOWN;
77
78 rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS, rc);
79 if (rc < 0)
80 return rc;
81
82 return smsc_phy_ack_interrupt(phydev);
83}
84
59static int lan911x_config_init(struct phy_device *phydev) 85static int lan911x_config_init(struct phy_device *phydev)
60{ 86{
61 return smsc_phy_ack_interrupt(phydev); 87 return smsc_phy_ack_interrupt(phydev);
@@ -162,7 +188,7 @@ static struct phy_driver smsc_phy_driver[] = {
162 /* basic functions */ 188 /* basic functions */
163 .config_aneg = genphy_config_aneg, 189 .config_aneg = genphy_config_aneg,
164 .read_status = genphy_read_status, 190 .read_status = genphy_read_status,
165 .config_init = smsc_phy_config_init, 191 .config_init = lan87xx_config_init,
166 192
167 /* IRQ related */ 193 /* IRQ related */
168 .ack_interrupt = smsc_phy_ack_interrupt, 194 .ack_interrupt = smsc_phy_ack_interrupt,
diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
index cbf7047decc0..20f31d0d1536 100644
--- a/drivers/net/ppp/pppoe.c
+++ b/drivers/net/ppp/pppoe.c
@@ -570,7 +570,7 @@ static int pppoe_release(struct socket *sock)
570 570
571 po = pppox_sk(sk); 571 po = pppox_sk(sk);
572 572
573 if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) { 573 if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND | PPPOX_ZOMBIE)) {
574 dev_put(po->pppoe_dev); 574 dev_put(po->pppoe_dev);
575 po->pppoe_dev = NULL; 575 po->pppoe_dev = NULL;
576 } 576 }
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 341b65dbbcd3..f8cd61f449a4 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -848,7 +848,7 @@ static struct netpoll_info *team_netpoll_info(struct team *team)
848} 848}
849#endif 849#endif
850 850
851static void __team_port_change_check(struct team_port *port, bool linkup); 851static void __team_port_change_port_added(struct team_port *port, bool linkup);
852 852
853static int team_port_add(struct team *team, struct net_device *port_dev) 853static int team_port_add(struct team *team, struct net_device *port_dev)
854{ 854{
@@ -948,7 +948,7 @@ static int team_port_add(struct team *team, struct net_device *port_dev)
948 team_port_enable(team, port); 948 team_port_enable(team, port);
949 list_add_tail_rcu(&port->list, &team->port_list); 949 list_add_tail_rcu(&port->list, &team->port_list);
950 __team_compute_features(team); 950 __team_compute_features(team);
951 __team_port_change_check(port, !!netif_carrier_ok(port_dev)); 951 __team_port_change_port_added(port, !!netif_carrier_ok(port_dev));
952 __team_options_change_check(team); 952 __team_options_change_check(team);
953 953
954 netdev_info(dev, "Port device %s added\n", portname); 954 netdev_info(dev, "Port device %s added\n", portname);
@@ -983,6 +983,8 @@ err_set_mtu:
983 return err; 983 return err;
984} 984}
985 985
986static void __team_port_change_port_removed(struct team_port *port);
987
986static int team_port_del(struct team *team, struct net_device *port_dev) 988static int team_port_del(struct team *team, struct net_device *port_dev)
987{ 989{
988 struct net_device *dev = team->dev; 990 struct net_device *dev = team->dev;
@@ -999,8 +1001,7 @@ static int team_port_del(struct team *team, struct net_device *port_dev)
999 __team_option_inst_mark_removed_port(team, port); 1001 __team_option_inst_mark_removed_port(team, port);
1000 __team_options_change_check(team); 1002 __team_options_change_check(team);
1001 __team_option_inst_del_port(team, port); 1003 __team_option_inst_del_port(team, port);
1002 port->removed = true; 1004 __team_port_change_port_removed(port);
1003 __team_port_change_check(port, false);
1004 team_port_disable(team, port); 1005 team_port_disable(team, port);
1005 list_del_rcu(&port->list); 1006 list_del_rcu(&port->list);
1006 netdev_rx_handler_unregister(port_dev); 1007 netdev_rx_handler_unregister(port_dev);
@@ -1652,8 +1653,8 @@ static int team_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
1652 1653
1653 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq, 1654 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
1654 &team_nl_family, 0, TEAM_CMD_NOOP); 1655 &team_nl_family, 0, TEAM_CMD_NOOP);
1655 if (IS_ERR(hdr)) { 1656 if (!hdr) {
1656 err = PTR_ERR(hdr); 1657 err = -EMSGSIZE;
1657 goto err_msg_put; 1658 goto err_msg_put;
1658 } 1659 }
1659 1660
@@ -1847,8 +1848,8 @@ start_again:
1847 1848
1848 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags | NLM_F_MULTI, 1849 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags | NLM_F_MULTI,
1849 TEAM_CMD_OPTIONS_GET); 1850 TEAM_CMD_OPTIONS_GET);
1850 if (IS_ERR(hdr)) 1851 if (!hdr)
1851 return PTR_ERR(hdr); 1852 return -EMSGSIZE;
1852 1853
1853 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex)) 1854 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
1854 goto nla_put_failure; 1855 goto nla_put_failure;
@@ -2067,8 +2068,8 @@ static int team_nl_fill_port_list_get(struct sk_buff *skb,
2067 2068
2068 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags, 2069 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
2069 TEAM_CMD_PORT_LIST_GET); 2070 TEAM_CMD_PORT_LIST_GET);
2070 if (IS_ERR(hdr)) 2071 if (!hdr)
2071 return PTR_ERR(hdr); 2072 return -EMSGSIZE;
2072 2073
2073 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex)) 2074 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
2074 goto nla_put_failure; 2075 goto nla_put_failure;
@@ -2251,13 +2252,11 @@ static void __team_options_change_check(struct team *team)
2251} 2252}
2252 2253
2253/* rtnl lock is held */ 2254/* rtnl lock is held */
2254static void __team_port_change_check(struct team_port *port, bool linkup) 2255
2256static void __team_port_change_send(struct team_port *port, bool linkup)
2255{ 2257{
2256 int err; 2258 int err;
2257 2259
2258 if (!port->removed && port->state.linkup == linkup)
2259 return;
2260
2261 port->changed = true; 2260 port->changed = true;
2262 port->state.linkup = linkup; 2261 port->state.linkup = linkup;
2263 team_refresh_port_linkup(port); 2262 team_refresh_port_linkup(port);
@@ -2282,6 +2281,23 @@ send_event:
2282 2281
2283} 2282}
2284 2283
2284static void __team_port_change_check(struct team_port *port, bool linkup)
2285{
2286 if (port->state.linkup != linkup)
2287 __team_port_change_send(port, linkup);
2288}
2289
2290static void __team_port_change_port_added(struct team_port *port, bool linkup)
2291{
2292 __team_port_change_send(port, linkup);
2293}
2294
2295static void __team_port_change_port_removed(struct team_port *port)
2296{
2297 port->removed = true;
2298 __team_port_change_send(port, false);
2299}
2300
2285static void team_port_change_check(struct team_port *port, bool linkup) 2301static void team_port_change_check(struct team_port *port, bool linkup)
2286{ 2302{
2287 struct team *team = port->team; 2303 struct team *team = port->team;
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 4fd48df6b989..32e31c5c5dc6 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -962,6 +962,10 @@ static const struct usb_device_id products [] = {
962 USB_DEVICE (0x2001, 0x3c05), 962 USB_DEVICE (0x2001, 0x3c05),
963 .driver_info = (unsigned long) &ax88772_info, 963 .driver_info = (unsigned long) &ax88772_info,
964}, { 964}, {
965 // DLink DUB-E100 H/W Ver C1
966 USB_DEVICE (0x2001, 0x1a02),
967 .driver_info = (unsigned long) &ax88772_info,
968}, {
965 // Linksys USB1000 969 // Linksys USB1000
966 USB_DEVICE (0x1737, 0x0039), 970 USB_DEVICE (0x1737, 0x0039),
967 .driver_info = (unsigned long) &ax88178_info, 971 .driver_info = (unsigned long) &ax88178_info,
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index adfab3fc5478..3543c9e57824 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -297,7 +297,7 @@ static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message)
297 if (ret < 0) 297 if (ret < 0)
298 goto err; 298 goto err;
299 299
300 if (info->subdriver && info->subdriver->suspend) 300 if (intf == info->control && info->subdriver && info->subdriver->suspend)
301 ret = info->subdriver->suspend(intf, message); 301 ret = info->subdriver->suspend(intf, message);
302 if (ret < 0) 302 if (ret < 0)
303 usbnet_resume(intf); 303 usbnet_resume(intf);
@@ -310,13 +310,14 @@ static int qmi_wwan_resume(struct usb_interface *intf)
310 struct usbnet *dev = usb_get_intfdata(intf); 310 struct usbnet *dev = usb_get_intfdata(intf);
311 struct qmi_wwan_state *info = (void *)&dev->data; 311 struct qmi_wwan_state *info = (void *)&dev->data;
312 int ret = 0; 312 int ret = 0;
313 bool callsub = (intf == info->control && info->subdriver && info->subdriver->resume);
313 314
314 if (info->subdriver && info->subdriver->resume) 315 if (callsub)
315 ret = info->subdriver->resume(intf); 316 ret = info->subdriver->resume(intf);
316 if (ret < 0) 317 if (ret < 0)
317 goto err; 318 goto err;
318 ret = usbnet_resume(intf); 319 ret = usbnet_resume(intf);
319 if (ret < 0 && info->subdriver && info->subdriver->resume && info->subdriver->suspend) 320 if (ret < 0 && callsub && info->subdriver->suspend)
320 info->subdriver->suspend(intf, PMSG_SUSPEND); 321 info->subdriver->suspend(intf, PMSG_SUSPEND);
321err: 322err:
322 return ret; 323 return ret;
@@ -365,16 +366,20 @@ static const struct usb_device_id products[] = {
365 }, 366 },
366 367
367 /* 2. Combined interface devices matching on class+protocol */ 368 /* 2. Combined interface devices matching on class+protocol */
369 { /* Huawei E367 and possibly others in "Windows mode" */
370 USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 1, 7),
371 .driver_info = (unsigned long)&qmi_wwan_info,
372 },
368 { /* Huawei E392, E398 and possibly others in "Windows mode" */ 373 { /* Huawei E392, E398 and possibly others in "Windows mode" */
369 USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 1, 17), 374 USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 1, 17),
370 .driver_info = (unsigned long)&qmi_wwan_shared, 375 .driver_info = (unsigned long)&qmi_wwan_shared,
371 }, 376 },
372 { /* Pantech UML290 */ 377 { /* Pantech UML290, P4200 and more */
373 USB_DEVICE_AND_INTERFACE_INFO(0x106c, 0x3718, USB_CLASS_VENDOR_SPEC, 0xf0, 0xff), 378 USB_VENDOR_AND_INTERFACE_INFO(0x106c, USB_CLASS_VENDOR_SPEC, 0xf0, 0xff),
374 .driver_info = (unsigned long)&qmi_wwan_shared, 379 .driver_info = (unsigned long)&qmi_wwan_shared,
375 }, 380 },
376 { /* Pantech UML290 - newer firmware */ 381 { /* Pantech UML290 - newer firmware */
377 USB_DEVICE_AND_INTERFACE_INFO(0x106c, 0x3718, USB_CLASS_VENDOR_SPEC, 0xf1, 0xff), 382 USB_VENDOR_AND_INTERFACE_INFO(0x106c, USB_CLASS_VENDOR_SPEC, 0xf1, 0xff),
378 .driver_info = (unsigned long)&qmi_wwan_shared, 383 .driver_info = (unsigned long)&qmi_wwan_shared,
379 }, 384 },
380 385
@@ -382,6 +387,7 @@ static const struct usb_device_id products[] = {
382 {QMI_FIXED_INTF(0x19d2, 0x0055, 1)}, /* ZTE (Vodafone) K3520-Z */ 387 {QMI_FIXED_INTF(0x19d2, 0x0055, 1)}, /* ZTE (Vodafone) K3520-Z */
383 {QMI_FIXED_INTF(0x19d2, 0x0063, 4)}, /* ZTE (Vodafone) K3565-Z */ 388 {QMI_FIXED_INTF(0x19d2, 0x0063, 4)}, /* ZTE (Vodafone) K3565-Z */
384 {QMI_FIXED_INTF(0x19d2, 0x0104, 4)}, /* ZTE (Vodafone) K4505-Z */ 389 {QMI_FIXED_INTF(0x19d2, 0x0104, 4)}, /* ZTE (Vodafone) K4505-Z */
390 {QMI_FIXED_INTF(0x19d2, 0x0157, 5)}, /* ZTE MF683 */
385 {QMI_FIXED_INTF(0x19d2, 0x0167, 4)}, /* ZTE MF820D */ 391 {QMI_FIXED_INTF(0x19d2, 0x0167, 4)}, /* ZTE MF820D */
386 {QMI_FIXED_INTF(0x19d2, 0x0326, 4)}, /* ZTE MF821D */ 392 {QMI_FIXED_INTF(0x19d2, 0x0326, 4)}, /* ZTE MF821D */
387 {QMI_FIXED_INTF(0x19d2, 0x1008, 4)}, /* ZTE (Vodafone) K3570-Z */ 393 {QMI_FIXED_INTF(0x19d2, 0x1008, 4)}, /* ZTE (Vodafone) K3570-Z */
@@ -398,7 +404,6 @@ static const struct usb_device_id products[] = {
398 /* 4. Gobi 1000 devices */ 404 /* 4. Gobi 1000 devices */
399 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ 405 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
400 {QMI_GOBI1K_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */ 406 {QMI_GOBI1K_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */
401 {QMI_GOBI1K_DEVICE(0x03f0, 0x371d)}, /* HP un2430 Mobile Broadband Module */
402 {QMI_GOBI1K_DEVICE(0x04da, 0x250d)}, /* Panasonic Gobi Modem device */ 407 {QMI_GOBI1K_DEVICE(0x04da, 0x250d)}, /* Panasonic Gobi Modem device */
403 {QMI_GOBI1K_DEVICE(0x413c, 0x8172)}, /* Dell Gobi Modem device */ 408 {QMI_GOBI1K_DEVICE(0x413c, 0x8172)}, /* Dell Gobi Modem device */
404 {QMI_GOBI1K_DEVICE(0x1410, 0xa001)}, /* Novatel Gobi Modem device */ 409 {QMI_GOBI1K_DEVICE(0x1410, 0xa001)}, /* Novatel Gobi Modem device */
@@ -440,6 +445,7 @@ static const struct usb_device_id products[] = {
440 {QMI_GOBI_DEVICE(0x16d8, 0x8002)}, /* CMDTech Gobi 2000 Modem device (VU922) */ 445 {QMI_GOBI_DEVICE(0x16d8, 0x8002)}, /* CMDTech Gobi 2000 Modem device (VU922) */
441 {QMI_GOBI_DEVICE(0x05c6, 0x9205)}, /* Gobi 2000 Modem device */ 446 {QMI_GOBI_DEVICE(0x05c6, 0x9205)}, /* Gobi 2000 Modem device */
442 {QMI_GOBI_DEVICE(0x1199, 0x9013)}, /* Sierra Wireless Gobi 3000 Modem device (MC8355) */ 447 {QMI_GOBI_DEVICE(0x1199, 0x9013)}, /* Sierra Wireless Gobi 3000 Modem device (MC8355) */
448 {QMI_GOBI_DEVICE(0x03f0, 0x371d)}, /* HP un2430 Mobile Broadband Module */
443 {QMI_GOBI_DEVICE(0x1199, 0x9015)}, /* Sierra Wireless Gobi 3000 Modem device */ 449 {QMI_GOBI_DEVICE(0x1199, 0x9015)}, /* Sierra Wireless Gobi 3000 Modem device */
444 {QMI_GOBI_DEVICE(0x1199, 0x9019)}, /* Sierra Wireless Gobi 3000 Modem device */ 450 {QMI_GOBI_DEVICE(0x1199, 0x9019)}, /* Sierra Wireless Gobi 3000 Modem device */
445 {QMI_GOBI_DEVICE(0x1199, 0x901b)}, /* Sierra Wireless MC7770 */ 451 {QMI_GOBI_DEVICE(0x1199, 0x901b)}, /* Sierra Wireless MC7770 */
diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
index 7be49ea60b6d..8e22417fa6c1 100644
--- a/drivers/net/usb/sierra_net.c
+++ b/drivers/net/usb/sierra_net.c
@@ -656,7 +656,7 @@ static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap)
656 return -EIO; 656 return -EIO;
657 } 657 }
658 658
659 *datap = *attrdata; 659 *datap = le16_to_cpu(*attrdata);
660 660
661 kfree(attrdata); 661 kfree(attrdata);
662 return result; 662 return result;
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index f5ab6e613ec8..376143e8a1aa 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -1253,6 +1253,7 @@ static struct usb_driver smsc75xx_driver = {
1253 .probe = usbnet_probe, 1253 .probe = usbnet_probe,
1254 .suspend = usbnet_suspend, 1254 .suspend = usbnet_suspend,
1255 .resume = usbnet_resume, 1255 .resume = usbnet_resume,
1256 .reset_resume = usbnet_resume,
1256 .disconnect = usbnet_disconnect, 1257 .disconnect = usbnet_disconnect,
1257 .disable_hub_initiated_lpm = 1, 1258 .disable_hub_initiated_lpm = 1,
1258}; 1259};
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index fd4b26d46fd5..fc9f578a1e25 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1201,19 +1201,26 @@ deferred:
1201} 1201}
1202EXPORT_SYMBOL_GPL(usbnet_start_xmit); 1202EXPORT_SYMBOL_GPL(usbnet_start_xmit);
1203 1203
1204static void rx_alloc_submit(struct usbnet *dev, gfp_t flags) 1204static int rx_alloc_submit(struct usbnet *dev, gfp_t flags)
1205{ 1205{
1206 struct urb *urb; 1206 struct urb *urb;
1207 int i; 1207 int i;
1208 int ret = 0;
1208 1209
1209 /* don't refill the queue all at once */ 1210 /* don't refill the queue all at once */
1210 for (i = 0; i < 10 && dev->rxq.qlen < RX_QLEN(dev); i++) { 1211 for (i = 0; i < 10 && dev->rxq.qlen < RX_QLEN(dev); i++) {
1211 urb = usb_alloc_urb(0, flags); 1212 urb = usb_alloc_urb(0, flags);
1212 if (urb != NULL) { 1213 if (urb != NULL) {
1213 if (rx_submit(dev, urb, flags) == -ENOLINK) 1214 ret = rx_submit(dev, urb, flags);
1214 return; 1215 if (ret)
1216 goto err;
1217 } else {
1218 ret = -ENOMEM;
1219 goto err;
1215 } 1220 }
1216 } 1221 }
1222err:
1223 return ret;
1217} 1224}
1218 1225
1219/*-------------------------------------------------------------------------*/ 1226/*-------------------------------------------------------------------------*/
@@ -1257,7 +1264,8 @@ static void usbnet_bh (unsigned long param)
1257 int temp = dev->rxq.qlen; 1264 int temp = dev->rxq.qlen;
1258 1265
1259 if (temp < RX_QLEN(dev)) { 1266 if (temp < RX_QLEN(dev)) {
1260 rx_alloc_submit(dev, GFP_ATOMIC); 1267 if (rx_alloc_submit(dev, GFP_ATOMIC) == -ENOLINK)
1268 return;
1261 if (temp != dev->rxq.qlen) 1269 if (temp != dev->rxq.qlen)
1262 netif_dbg(dev, link, dev->net, 1270 netif_dbg(dev, link, dev->net,
1263 "rxqlen %d --> %d\n", 1271 "rxqlen %d --> %d\n",
diff --git a/drivers/net/wan/ixp4xx_hss.c b/drivers/net/wan/ixp4xx_hss.c
index aaaca9aa2293..3f575afd8cfc 100644
--- a/drivers/net/wan/ixp4xx_hss.c
+++ b/drivers/net/wan/ixp4xx_hss.c
@@ -10,6 +10,7 @@
10 10
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 12
13#include <linux/module.h>
13#include <linux/bitops.h> 14#include <linux/bitops.h>
14#include <linux/cdev.h> 15#include <linux/cdev.h>
15#include <linux/dma-mapping.h> 16#include <linux/dma-mapping.h>
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index 2588848f4a82..d066f2516e47 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -2982,6 +2982,10 @@ static u32 ath9k_hw_ar9300_get_eeprom(struct ath_hw *ah,
2982 case EEP_RX_MASK: 2982 case EEP_RX_MASK:
2983 return pBase->txrxMask & 0xf; 2983 return pBase->txrxMask & 0xf;
2984 case EEP_PAPRD: 2984 case EEP_PAPRD:
2985 if (AR_SREV_9462(ah))
2986 return false;
2987 if (!ah->config.enable_paprd);
2988 return false;
2985 return !!(pBase->featureEnable & BIT(5)); 2989 return !!(pBase->featureEnable & BIT(5));
2986 case EEP_CHAIN_MASK_REDUCE: 2990 case EEP_CHAIN_MASK_REDUCE:
2987 return (pBase->miscConfiguration >> 0x3) & 0x1; 2991 return (pBase->miscConfiguration >> 0x3) & 0x1;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
index 2c9f7d7ed4cc..0ed3846f9cbb 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
@@ -142,6 +142,7 @@ static int ar9003_paprd_setup_single_table(struct ath_hw *ah)
142 }; 142 };
143 int training_power; 143 int training_power;
144 int i, val; 144 int i, val;
145 u32 am2pm_mask = ah->paprd_ratemask;
145 146
146 if (IS_CHAN_2GHZ(ah->curchan)) 147 if (IS_CHAN_2GHZ(ah->curchan))
147 training_power = ar9003_get_training_power_2g(ah); 148 training_power = ar9003_get_training_power_2g(ah);
@@ -158,10 +159,13 @@ static int ar9003_paprd_setup_single_table(struct ath_hw *ah)
158 } 159 }
159 ah->paprd_training_power = training_power; 160 ah->paprd_training_power = training_power;
160 161
162 if (AR_SREV_9330(ah))
163 am2pm_mask = 0;
164
161 REG_RMW_FIELD(ah, AR_PHY_PAPRD_AM2AM, AR_PHY_PAPRD_AM2AM_MASK, 165 REG_RMW_FIELD(ah, AR_PHY_PAPRD_AM2AM, AR_PHY_PAPRD_AM2AM_MASK,
162 ah->paprd_ratemask); 166 ah->paprd_ratemask);
163 REG_RMW_FIELD(ah, AR_PHY_PAPRD_AM2PM, AR_PHY_PAPRD_AM2PM_MASK, 167 REG_RMW_FIELD(ah, AR_PHY_PAPRD_AM2PM, AR_PHY_PAPRD_AM2PM_MASK,
164 ah->paprd_ratemask); 168 am2pm_mask);
165 REG_RMW_FIELD(ah, AR_PHY_PAPRD_HT40, AR_PHY_PAPRD_HT40_MASK, 169 REG_RMW_FIELD(ah, AR_PHY_PAPRD_HT40, AR_PHY_PAPRD_HT40_MASK,
166 ah->paprd_ratemask_ht40); 170 ah->paprd_ratemask_ht40);
167 171
@@ -782,6 +786,102 @@ int ar9003_paprd_setup_gain_table(struct ath_hw *ah, int chain)
782} 786}
783EXPORT_SYMBOL(ar9003_paprd_setup_gain_table); 787EXPORT_SYMBOL(ar9003_paprd_setup_gain_table);
784 788
789static bool ar9003_paprd_retrain_pa_in(struct ath_hw *ah,
790 struct ath9k_hw_cal_data *caldata,
791 int chain)
792{
793 u32 *pa_in = caldata->pa_table[chain];
794 int capdiv_offset, quick_drop_offset;
795 int capdiv2g, quick_drop;
796 int count = 0;
797 int i;
798
799 if (!AR_SREV_9485(ah) && !AR_SREV_9330(ah))
800 return false;
801
802 capdiv2g = REG_READ_FIELD(ah, AR_PHY_65NM_CH0_TXRF3,
803 AR_PHY_65NM_CH0_TXRF3_CAPDIV2G);
804
805 quick_drop = REG_READ_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
806 AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_QUICK_DROP);
807
808 if (quick_drop)
809 quick_drop -= 0x40;
810
811 for (i = 0; i < NUM_BIN + 1; i++) {
812 if (pa_in[i] == 1400)
813 count++;
814 }
815
816 if (AR_SREV_9485(ah)) {
817 if (pa_in[23] < 800) {
818 capdiv_offset = (int)((1000 - pa_in[23] + 75) / 150);
819 capdiv2g += capdiv_offset;
820 if (capdiv2g > 7) {
821 capdiv2g = 7;
822 if (pa_in[23] < 600) {
823 quick_drop++;
824 if (quick_drop > 0)
825 quick_drop = 0;
826 }
827 }
828 } else if (pa_in[23] == 1400) {
829 quick_drop_offset = min_t(int, count / 3, 2);
830 quick_drop += quick_drop_offset;
831 capdiv2g += quick_drop_offset / 2;
832
833 if (capdiv2g > 7)
834 capdiv2g = 7;
835
836 if (quick_drop > 0) {
837 quick_drop = 0;
838 capdiv2g -= quick_drop_offset;
839 if (capdiv2g < 0)
840 capdiv2g = 0;
841 }
842 } else {
843 return false;
844 }
845 } else if (AR_SREV_9330(ah)) {
846 if (pa_in[23] < 1000) {
847 capdiv_offset = (1000 - pa_in[23]) / 100;
848 capdiv2g += capdiv_offset;
849 if (capdiv_offset > 3) {
850 capdiv_offset = 1;
851 quick_drop--;
852 }
853
854 capdiv2g += capdiv_offset;
855 if (capdiv2g > 6)
856 capdiv2g = 6;
857 if (quick_drop < -4)
858 quick_drop = -4;
859 } else if (pa_in[23] == 1400) {
860 if (count > 3) {
861 quick_drop++;
862 capdiv2g -= count / 4;
863 if (quick_drop > -2)
864 quick_drop = -2;
865 } else {
866 capdiv2g--;
867 }
868
869 if (capdiv2g < 0)
870 capdiv2g = 0;
871 } else {
872 return false;
873 }
874 }
875
876 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_TXRF3,
877 AR_PHY_65NM_CH0_TXRF3_CAPDIV2G, capdiv2g);
878 REG_RMW_FIELD(ah, AR_PHY_PAPRD_TRAINER_CNTL3,
879 AR_PHY_PAPRD_TRAINER_CNTL3_CF_PAPRD_QUICK_DROP,
880 quick_drop);
881
882 return true;
883}
884
785int ar9003_paprd_create_curve(struct ath_hw *ah, 885int ar9003_paprd_create_curve(struct ath_hw *ah,
786 struct ath9k_hw_cal_data *caldata, int chain) 886 struct ath9k_hw_cal_data *caldata, int chain)
787{ 887{
@@ -817,6 +917,9 @@ int ar9003_paprd_create_curve(struct ath_hw *ah,
817 if (!create_pa_curve(data_L, data_U, pa_table, small_signal_gain)) 917 if (!create_pa_curve(data_L, data_U, pa_table, small_signal_gain))
818 status = -2; 918 status = -2;
819 919
920 if (ar9003_paprd_retrain_pa_in(ah, caldata, chain))
921 status = -EINPROGRESS;
922
820 REG_CLR_BIT(ah, AR_PHY_PAPRD_TRAINER_STAT1, 923 REG_CLR_BIT(ah, AR_PHY_PAPRD_TRAINER_STAT1,
821 AR_PHY_PAPRD_TRAINER_STAT1_PAPRD_TRAIN_DONE); 924 AR_PHY_PAPRD_TRAINER_STAT1_PAPRD_TRAIN_DONE);
822 925
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.h b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
index 7bfbaf065a43..84d3d4956861 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
@@ -625,6 +625,10 @@
625#define AR_PHY_AIC_CTRL_4_B0 (AR_SM_BASE + 0x4c0) 625#define AR_PHY_AIC_CTRL_4_B0 (AR_SM_BASE + 0x4c0)
626#define AR_PHY_AIC_STAT_2_B0 (AR_SM_BASE + 0x4cc) 626#define AR_PHY_AIC_STAT_2_B0 (AR_SM_BASE + 0x4cc)
627 627
628#define AR_PHY_65NM_CH0_TXRF3 0x16048
629#define AR_PHY_65NM_CH0_TXRF3_CAPDIV2G 0x0000001e
630#define AR_PHY_65NM_CH0_TXRF3_CAPDIV2G_S 1
631
628#define AR_PHY_65NM_CH0_SYNTH4 0x1608c 632#define AR_PHY_65NM_CH0_SYNTH4 0x1608c
629#define AR_PHY_SYNTH4_LONG_SHIFT_SELECT (AR_SREV_9462(ah) ? 0x00000001 : 0x00000002) 633#define AR_PHY_SYNTH4_LONG_SHIFT_SELECT (AR_SREV_9462(ah) ? 0x00000001 : 0x00000002)
630#define AR_PHY_SYNTH4_LONG_SHIFT_SELECT_S (AR_SREV_9462(ah) ? 0 : 1) 634#define AR_PHY_SYNTH4_LONG_SHIFT_SELECT_S (AR_SREV_9462(ah) ? 0 : 1)
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index 68b643c8943c..c8ef30127adb 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -1577,6 +1577,8 @@ int ath9k_init_debug(struct ath_hw *ah)
1577 sc->debug.debugfs_phy, sc, &fops_tx_chainmask); 1577 sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
1578 debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR, 1578 debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR,
1579 sc->debug.debugfs_phy, sc, &fops_disable_ani); 1579 sc->debug.debugfs_phy, sc, &fops_disable_ani);
1580 debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1581 &sc->sc_ah->config.enable_paprd);
1580 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1582 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1581 sc, &fops_regidx); 1583 sc, &fops_regidx);
1582 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1584 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
diff --git a/drivers/net/wireless/ath/ath9k/gpio.c b/drivers/net/wireless/ath/ath9k/gpio.c
index bacdb8fb4ef4..9f83f71742a5 100644
--- a/drivers/net/wireless/ath/ath9k/gpio.c
+++ b/drivers/net/wireless/ath/ath9k/gpio.c
@@ -341,7 +341,8 @@ void ath9k_btcoex_stop_gen_timer(struct ath_softc *sc)
341{ 341{
342 struct ath_btcoex *btcoex = &sc->btcoex; 342 struct ath_btcoex *btcoex = &sc->btcoex;
343 343
344 ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer); 344 if (btcoex->hw_timer_enabled)
345 ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
345} 346}
346 347
347u16 ath9k_btcoex_aggr_limit(struct ath_softc *sc, u32 max_4ms_framelen) 348u16 ath9k_btcoex_aggr_limit(struct ath_softc *sc, u32 max_4ms_framelen)
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 60b6a9daff7e..4faf0a395876 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -463,9 +463,6 @@ static void ath9k_hw_init_config(struct ath_hw *ah)
463 ah->config.spurchans[i][1] = AR_NO_SPUR; 463 ah->config.spurchans[i][1] = AR_NO_SPUR;
464 } 464 }
465 465
466 /* PAPRD needs some more work to be enabled */
467 ah->config.paprd_disable = 1;
468
469 ah->config.rx_intr_mitigation = true; 466 ah->config.rx_intr_mitigation = true;
470 ah->config.pcieSerDesWrite = true; 467 ah->config.pcieSerDesWrite = true;
471 468
@@ -978,9 +975,6 @@ static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
978 else 975 else
979 imr_reg |= AR_IMR_TXOK; 976 imr_reg |= AR_IMR_TXOK;
980 977
981 if (opmode == NL80211_IFTYPE_AP)
982 imr_reg |= AR_IMR_MIB;
983
984 ENABLE_REGWRITE_BUFFER(ah); 978 ENABLE_REGWRITE_BUFFER(ah);
985 979
986 REG_WRITE(ah, AR_IMR, imr_reg); 980 REG_WRITE(ah, AR_IMR, imr_reg);
@@ -1778,6 +1772,8 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1778 /* Operating channel changed, reset channel calibration data */ 1772 /* Operating channel changed, reset channel calibration data */
1779 memset(caldata, 0, sizeof(*caldata)); 1773 memset(caldata, 0, sizeof(*caldata));
1780 ath9k_init_nfcal_hist_buffer(ah, chan); 1774 ath9k_init_nfcal_hist_buffer(ah, chan);
1775 } else if (caldata) {
1776 caldata->paprd_packet_sent = false;
1781 } 1777 }
1782 ah->noise = ath9k_hw_getchan_noise(ah, chan); 1778 ah->noise = ath9k_hw_getchan_noise(ah, chan);
1783 1779
@@ -2501,9 +2497,6 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
2501 pCap->rx_status_len = sizeof(struct ar9003_rxs); 2497 pCap->rx_status_len = sizeof(struct ar9003_rxs);
2502 pCap->tx_desc_len = sizeof(struct ar9003_txc); 2498 pCap->tx_desc_len = sizeof(struct ar9003_txc);
2503 pCap->txs_len = sizeof(struct ar9003_txs); 2499 pCap->txs_len = sizeof(struct ar9003_txs);
2504 if (!ah->config.paprd_disable &&
2505 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
2506 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
2507 } else { 2500 } else {
2508 pCap->tx_desc_len = sizeof(struct ath_desc); 2501 pCap->tx_desc_len = sizeof(struct ath_desc);
2509 if (AR_SREV_9280_20(ah)) 2502 if (AR_SREV_9280_20(ah))
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index ce7332c64efb..de6968fc64f4 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -236,7 +236,6 @@ enum ath9k_hw_caps {
236 ATH9K_HW_CAP_LDPC = BIT(6), 236 ATH9K_HW_CAP_LDPC = BIT(6),
237 ATH9K_HW_CAP_FASTCLOCK = BIT(7), 237 ATH9K_HW_CAP_FASTCLOCK = BIT(7),
238 ATH9K_HW_CAP_SGI_20 = BIT(8), 238 ATH9K_HW_CAP_SGI_20 = BIT(8),
239 ATH9K_HW_CAP_PAPRD = BIT(9),
240 ATH9K_HW_CAP_ANT_DIV_COMB = BIT(10), 239 ATH9K_HW_CAP_ANT_DIV_COMB = BIT(10),
241 ATH9K_HW_CAP_2GHZ = BIT(11), 240 ATH9K_HW_CAP_2GHZ = BIT(11),
242 ATH9K_HW_CAP_5GHZ = BIT(12), 241 ATH9K_HW_CAP_5GHZ = BIT(12),
@@ -287,12 +286,12 @@ struct ath9k_ops_config {
287 u8 pcie_clock_req; 286 u8 pcie_clock_req;
288 u32 pcie_waen; 287 u32 pcie_waen;
289 u8 analog_shiftreg; 288 u8 analog_shiftreg;
290 u8 paprd_disable;
291 u32 ofdm_trig_low; 289 u32 ofdm_trig_low;
292 u32 ofdm_trig_high; 290 u32 ofdm_trig_high;
293 u32 cck_trig_high; 291 u32 cck_trig_high;
294 u32 cck_trig_low; 292 u32 cck_trig_low;
295 u32 enable_ani; 293 u32 enable_ani;
294 u32 enable_paprd;
296 int serialize_regmode; 295 int serialize_regmode;
297 bool rx_intr_mitigation; 296 bool rx_intr_mitigation;
298 bool tx_intr_mitigation; 297 bool tx_intr_mitigation;
@@ -405,6 +404,7 @@ struct ath9k_hw_cal_data {
405 int8_t iCoff; 404 int8_t iCoff;
406 int8_t qCoff; 405 int8_t qCoff;
407 bool rtt_done; 406 bool rtt_done;
407 bool paprd_packet_sent;
408 bool paprd_done; 408 bool paprd_done;
409 bool nfcal_pending; 409 bool nfcal_pending;
410 bool nfcal_interference; 410 bool nfcal_interference;
diff --git a/drivers/net/wireless/ath/ath9k/link.c b/drivers/net/wireless/ath/ath9k/link.c
index d4549e9aac5c..7b88b9c39ccd 100644
--- a/drivers/net/wireless/ath/ath9k/link.c
+++ b/drivers/net/wireless/ath/ath9k/link.c
@@ -254,8 +254,9 @@ void ath_paprd_calibrate(struct work_struct *work)
254 int chain_ok = 0; 254 int chain_ok = 0;
255 int chain; 255 int chain;
256 int len = 1800; 256 int len = 1800;
257 int ret;
257 258
258 if (!caldata) 259 if (!caldata || !caldata->paprd_packet_sent || caldata->paprd_done)
259 return; 260 return;
260 261
261 ath9k_ps_wakeup(sc); 262 ath9k_ps_wakeup(sc);
@@ -282,13 +283,6 @@ void ath_paprd_calibrate(struct work_struct *work)
282 continue; 283 continue;
283 284
284 chain_ok = 0; 285 chain_ok = 0;
285
286 ath_dbg(common, CALIBRATE,
287 "Sending PAPRD frame for thermal measurement on chain %d\n",
288 chain);
289 if (!ath_paprd_send_frame(sc, skb, chain))
290 goto fail_paprd;
291
292 ar9003_paprd_setup_gain_table(ah, chain); 286 ar9003_paprd_setup_gain_table(ah, chain);
293 287
294 ath_dbg(common, CALIBRATE, 288 ath_dbg(common, CALIBRATE,
@@ -302,7 +296,13 @@ void ath_paprd_calibrate(struct work_struct *work)
302 break; 296 break;
303 } 297 }
304 298
305 if (ar9003_paprd_create_curve(ah, caldata, chain)) { 299 ret = ar9003_paprd_create_curve(ah, caldata, chain);
300 if (ret == -EINPROGRESS) {
301 ath_dbg(common, CALIBRATE,
302 "PAPRD curve on chain %d needs to be re-trained\n",
303 chain);
304 break;
305 } else if (ret) {
306 ath_dbg(common, CALIBRATE, 306 ath_dbg(common, CALIBRATE,
307 "PAPRD create curve failed on chain %d\n", 307 "PAPRD create curve failed on chain %d\n",
308 chain); 308 chain);
@@ -423,7 +423,7 @@ set_timer:
423 cal_interval = min(cal_interval, (u32)short_cal_interval); 423 cal_interval = min(cal_interval, (u32)short_cal_interval);
424 424
425 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval)); 425 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
426 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) { 426 if (ah->eep_ops->get_eeprom(ah, EEP_PAPRD) && ah->caldata) {
427 if (!ah->caldata->paprd_done) 427 if (!ah->caldata->paprd_done)
428 ieee80211_queue_work(sc->hw, &sc->paprd_work); 428 ieee80211_queue_work(sc->hw, &sc->paprd_work);
429 else if (!ah->paprd_table_write_done) 429 else if (!ah->paprd_table_write_done)
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 2c9da6b2ecb1..0d4155aec48d 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -2018,6 +2018,9 @@ static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
2018 2018
2019 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb); 2019 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb);
2020 2020
2021 if (sc->sc_ah->caldata)
2022 sc->sc_ah->caldata->paprd_packet_sent = true;
2023
2021 if (!(tx_flags & ATH_TX_ERROR)) 2024 if (!(tx_flags & ATH_TX_ERROR))
2022 /* Frame was ACKed */ 2025 /* Frame was ACKed */
2023 tx_info->flags |= IEEE80211_TX_STAT_ACK; 2026 tx_info->flags |= IEEE80211_TX_STAT_ACK;
diff --git a/drivers/net/wireless/b43/Kconfig b/drivers/net/wireless/b43/Kconfig
index 3876c7ea54f4..7a28d21ac389 100644
--- a/drivers/net/wireless/b43/Kconfig
+++ b/drivers/net/wireless/b43/Kconfig
@@ -34,8 +34,8 @@ config B43_BCMA
34config B43_BCMA_EXTRA 34config B43_BCMA_EXTRA
35 bool "Hardware support that overlaps with the brcmsmac driver" 35 bool "Hardware support that overlaps with the brcmsmac driver"
36 depends on B43_BCMA 36 depends on B43_BCMA
37 default n if BRCMSMAC || BRCMSMAC_MODULE 37 default n if BRCMSMAC
38 default y 38 default y
39 39
40config B43_SSB 40config B43_SSB
41 bool 41 bool
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
index 49765d34b4e0..7c4ee72f9d56 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh_sdmmc.c
@@ -638,6 +638,8 @@ static int brcmf_sdio_pd_probe(struct platform_device *pdev)
638 638
639 oobirq_entry = kzalloc(sizeof(struct brcmf_sdio_oobirq), 639 oobirq_entry = kzalloc(sizeof(struct brcmf_sdio_oobirq),
640 GFP_KERNEL); 640 GFP_KERNEL);
641 if (!oobirq_entry)
642 return -ENOMEM;
641 oobirq_entry->irq = res->start; 643 oobirq_entry->irq = res->start;
642 oobirq_entry->flags = res->flags & IRQF_TRIGGER_MASK; 644 oobirq_entry->flags = res->flags & IRQF_TRIGGER_MASK;
643 list_add_tail(&oobirq_entry->list, &oobirq_lh); 645 list_add_tail(&oobirq_entry->list, &oobirq_lh);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c
index 2621dd3d7dcd..6f70953f0bad 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c
@@ -764,8 +764,11 @@ static void brcmf_c_arp_offload_set(struct brcmf_pub *drvr, int arp_mode)
764{ 764{
765 char iovbuf[32]; 765 char iovbuf[32];
766 int retcode; 766 int retcode;
767 __le32 arp_mode_le;
767 768
768 brcmf_c_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf)); 769 arp_mode_le = cpu_to_le32(arp_mode);
770 brcmf_c_mkiovar("arp_ol", (char *)&arp_mode_le, 4, iovbuf,
771 sizeof(iovbuf));
769 retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, 772 retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR,
770 iovbuf, sizeof(iovbuf)); 773 iovbuf, sizeof(iovbuf));
771 retcode = retcode >= 0 ? 0 : retcode; 774 retcode = retcode >= 0 ? 0 : retcode;
@@ -781,8 +784,11 @@ static void brcmf_c_arp_offload_enable(struct brcmf_pub *drvr, int arp_enable)
781{ 784{
782 char iovbuf[32]; 785 char iovbuf[32];
783 int retcode; 786 int retcode;
787 __le32 arp_enable_le;
784 788
785 brcmf_c_mkiovar("arpoe", (char *)&arp_enable, 4, 789 arp_enable_le = cpu_to_le32(arp_enable);
790
791 brcmf_c_mkiovar("arpoe", (char *)&arp_enable_le, 4,
786 iovbuf, sizeof(iovbuf)); 792 iovbuf, sizeof(iovbuf));
787 retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, 793 retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR,
788 iovbuf, sizeof(iovbuf)); 794 iovbuf, sizeof(iovbuf));
@@ -800,10 +806,10 @@ int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr)
800 char iovbuf[BRCMF_EVENTING_MASK_LEN + 12]; /* Room for 806 char iovbuf[BRCMF_EVENTING_MASK_LEN + 12]; /* Room for
801 "event_msgs" + '\0' + bitvec */ 807 "event_msgs" + '\0' + bitvec */
802 char buf[128], *ptr; 808 char buf[128], *ptr;
803 u32 roaming = 1; 809 __le32 roaming_le = cpu_to_le32(1);
804 uint bcn_timeout = 3; 810 __le32 bcn_timeout_le = cpu_to_le32(3);
805 int scan_assoc_time = 40; 811 __le32 scan_assoc_time_le = cpu_to_le32(40);
806 int scan_unassoc_time = 40; 812 __le32 scan_unassoc_time_le = cpu_to_le32(40);
807 int i; 813 int i;
808 struct brcmf_bus_dcmd *cmdlst; 814 struct brcmf_bus_dcmd *cmdlst;
809 struct list_head *cur, *q; 815 struct list_head *cur, *q;
@@ -829,14 +835,14 @@ int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr)
829 835
830 /* Setup timeout if Beacons are lost and roam is off to report 836 /* Setup timeout if Beacons are lost and roam is off to report
831 link down */ 837 link down */
832 brcmf_c_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf, 838 brcmf_c_mkiovar("bcn_timeout", (char *)&bcn_timeout_le, 4, iovbuf,
833 sizeof(iovbuf)); 839 sizeof(iovbuf));
834 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, 840 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
835 sizeof(iovbuf)); 841 sizeof(iovbuf));
836 842
837 /* Enable/Disable build-in roaming to allowed ext supplicant to take 843 /* Enable/Disable build-in roaming to allowed ext supplicant to take
838 of romaing */ 844 of romaing */
839 brcmf_c_mkiovar("roam_off", (char *)&roaming, 4, 845 brcmf_c_mkiovar("roam_off", (char *)&roaming_le, 4,
840 iovbuf, sizeof(iovbuf)); 846 iovbuf, sizeof(iovbuf));
841 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, 847 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
842 sizeof(iovbuf)); 848 sizeof(iovbuf));
@@ -848,9 +854,9 @@ int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr)
848 sizeof(iovbuf)); 854 sizeof(iovbuf));
849 855
850 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_CHANNEL_TIME, 856 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_CHANNEL_TIME,
851 (char *)&scan_assoc_time, sizeof(scan_assoc_time)); 857 (char *)&scan_assoc_time_le, sizeof(scan_assoc_time_le));
852 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_UNASSOC_TIME, 858 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_UNASSOC_TIME,
853 (char *)&scan_unassoc_time, sizeof(scan_unassoc_time)); 859 (char *)&scan_unassoc_time_le, sizeof(scan_unassoc_time_le));
854 860
855 /* Set and enable ARP offload feature */ 861 /* Set and enable ARP offload feature */
856 brcmf_c_arp_offload_set(drvr, BRCMF_ARPOL_MODE); 862 brcmf_c_arp_offload_set(drvr, BRCMF_ARPOL_MODE);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index a299d42da8e7..58f89fa9c9f8 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -519,7 +519,7 @@ static void brcmf_usb_tx_complete(struct urb *urb)
519 else 519 else
520 devinfo->bus_pub.bus->dstats.tx_errors++; 520 devinfo->bus_pub.bus->dstats.tx_errors++;
521 521
522 dev_kfree_skb(req->skb); 522 brcmu_pkt_buf_free_skb(req->skb);
523 req->skb = NULL; 523 req->skb = NULL;
524 brcmf_usb_enq(devinfo, &devinfo->tx_freeq, req); 524 brcmf_usb_enq(devinfo, &devinfo->tx_freeq, req);
525 525
@@ -540,7 +540,7 @@ static void brcmf_usb_rx_complete(struct urb *urb)
540 devinfo->bus_pub.bus->dstats.rx_packets++; 540 devinfo->bus_pub.bus->dstats.rx_packets++;
541 } else { 541 } else {
542 devinfo->bus_pub.bus->dstats.rx_errors++; 542 devinfo->bus_pub.bus->dstats.rx_errors++;
543 dev_kfree_skb(skb); 543 brcmu_pkt_buf_free_skb(skb);
544 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req); 544 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req);
545 return; 545 return;
546 } 546 }
@@ -550,13 +550,15 @@ static void brcmf_usb_rx_complete(struct urb *urb)
550 if (brcmf_proto_hdrpull(devinfo->dev, &ifidx, skb) != 0) { 550 if (brcmf_proto_hdrpull(devinfo->dev, &ifidx, skb) != 0) {
551 brcmf_dbg(ERROR, "rx protocol error\n"); 551 brcmf_dbg(ERROR, "rx protocol error\n");
552 brcmu_pkt_buf_free_skb(skb); 552 brcmu_pkt_buf_free_skb(skb);
553 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req);
553 devinfo->bus_pub.bus->dstats.rx_errors++; 554 devinfo->bus_pub.bus->dstats.rx_errors++;
554 } else { 555 } else {
555 brcmf_rx_packet(devinfo->dev, ifidx, skb); 556 brcmf_rx_packet(devinfo->dev, ifidx, skb);
556 brcmf_usb_rx_refill(devinfo, req); 557 brcmf_usb_rx_refill(devinfo, req);
557 } 558 }
558 } else { 559 } else {
559 dev_kfree_skb(skb); 560 brcmu_pkt_buf_free_skb(skb);
561 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req);
560 } 562 }
561 return; 563 return;
562 564
@@ -581,14 +583,13 @@ static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo,
581 usb_fill_bulk_urb(req->urb, devinfo->usbdev, devinfo->rx_pipe, 583 usb_fill_bulk_urb(req->urb, devinfo->usbdev, devinfo->rx_pipe,
582 skb->data, skb_tailroom(skb), brcmf_usb_rx_complete, 584 skb->data, skb_tailroom(skb), brcmf_usb_rx_complete,
583 req); 585 req);
584 req->urb->transfer_flags |= URB_ZERO_PACKET;
585 req->devinfo = devinfo; 586 req->devinfo = devinfo;
587 brcmf_usb_enq(devinfo, &devinfo->rx_postq, req);
586 588
587 ret = usb_submit_urb(req->urb, GFP_ATOMIC); 589 ret = usb_submit_urb(req->urb, GFP_ATOMIC);
588 if (ret == 0) { 590 if (ret) {
589 brcmf_usb_enq(devinfo, &devinfo->rx_postq, req); 591 brcmf_usb_del_fromq(devinfo, req);
590 } else { 592 brcmu_pkt_buf_free_skb(req->skb);
591 dev_kfree_skb(req->skb);
592 req->skb = NULL; 593 req->skb = NULL;
593 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req); 594 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req);
594 } 595 }
@@ -683,23 +684,22 @@ static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb)
683 684
684 req = brcmf_usb_deq(devinfo, &devinfo->tx_freeq); 685 req = brcmf_usb_deq(devinfo, &devinfo->tx_freeq);
685 if (!req) { 686 if (!req) {
687 brcmu_pkt_buf_free_skb(skb);
686 brcmf_dbg(ERROR, "no req to send\n"); 688 brcmf_dbg(ERROR, "no req to send\n");
687 return -ENOMEM; 689 return -ENOMEM;
688 } 690 }
689 if (!req->urb) {
690 brcmf_dbg(ERROR, "no urb for req %p\n", req);
691 return -ENOBUFS;
692 }
693 691
694 req->skb = skb; 692 req->skb = skb;
695 req->devinfo = devinfo; 693 req->devinfo = devinfo;
696 usb_fill_bulk_urb(req->urb, devinfo->usbdev, devinfo->tx_pipe, 694 usb_fill_bulk_urb(req->urb, devinfo->usbdev, devinfo->tx_pipe,
697 skb->data, skb->len, brcmf_usb_tx_complete, req); 695 skb->data, skb->len, brcmf_usb_tx_complete, req);
698 req->urb->transfer_flags |= URB_ZERO_PACKET; 696 req->urb->transfer_flags |= URB_ZERO_PACKET;
697 brcmf_usb_enq(devinfo, &devinfo->tx_postq, req);
699 ret = usb_submit_urb(req->urb, GFP_ATOMIC); 698 ret = usb_submit_urb(req->urb, GFP_ATOMIC);
700 if (!ret) { 699 if (ret) {
701 brcmf_usb_enq(devinfo, &devinfo->tx_postq, req); 700 brcmf_dbg(ERROR, "brcmf_usb_tx usb_submit_urb FAILED\n");
702 } else { 701 brcmf_usb_del_fromq(devinfo, req);
702 brcmu_pkt_buf_free_skb(req->skb);
703 req->skb = NULL; 703 req->skb = NULL;
704 brcmf_usb_enq(devinfo, &devinfo->tx_freeq, req); 704 brcmf_usb_enq(devinfo, &devinfo->tx_freeq, req);
705 } 705 }
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
index 28c5fbb4af26..50b5553b6964 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
@@ -500,8 +500,10 @@ static void wl_iscan_prep(struct brcmf_scan_params_le *params_le,
500 params_le->active_time = cpu_to_le32(-1); 500 params_le->active_time = cpu_to_le32(-1);
501 params_le->passive_time = cpu_to_le32(-1); 501 params_le->passive_time = cpu_to_le32(-1);
502 params_le->home_time = cpu_to_le32(-1); 502 params_le->home_time = cpu_to_le32(-1);
503 if (ssid && ssid->SSID_len) 503 if (ssid && ssid->SSID_len) {
504 memcpy(&params_le->ssid_le, ssid, sizeof(struct brcmf_ssid)); 504 params_le->ssid_le.SSID_len = cpu_to_le32(ssid->SSID_len);
505 memcpy(&params_le->ssid_le.SSID, ssid->SSID, ssid->SSID_len);
506 }
505} 507}
506 508
507static s32 509static s32
@@ -1876,16 +1878,17 @@ brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
1876 } 1878 }
1877 1879
1878 if (test_bit(WL_STATUS_CONNECTED, &cfg_priv->status)) { 1880 if (test_bit(WL_STATUS_CONNECTED, &cfg_priv->status)) {
1879 scb_val.val = cpu_to_le32(0); 1881 memset(&scb_val, 0, sizeof(scb_val));
1880 err = brcmf_exec_dcmd(ndev, BRCMF_C_GET_RSSI, &scb_val, 1882 err = brcmf_exec_dcmd(ndev, BRCMF_C_GET_RSSI, &scb_val,
1881 sizeof(struct brcmf_scb_val_le)); 1883 sizeof(struct brcmf_scb_val_le));
1882 if (err) 1884 if (err) {
1883 WL_ERR("Could not get rssi (%d)\n", err); 1885 WL_ERR("Could not get rssi (%d)\n", err);
1884 1886 } else {
1885 rssi = le32_to_cpu(scb_val.val); 1887 rssi = le32_to_cpu(scb_val.val);
1886 sinfo->filled |= STATION_INFO_SIGNAL; 1888 sinfo->filled |= STATION_INFO_SIGNAL;
1887 sinfo->signal = rssi; 1889 sinfo->signal = rssi;
1888 WL_CONN("RSSI %d dBm\n", rssi); 1890 WL_CONN("RSSI %d dBm\n", rssi);
1891 }
1889 } 1892 }
1890 1893
1891done: 1894done:
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/channel.c b/drivers/net/wireless/brcm80211/brcmsmac/channel.c
index 7ed7d7577024..64a48f06d68b 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/channel.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/channel.c
@@ -77,7 +77,7 @@
77 NL80211_RRF_NO_IBSS) 77 NL80211_RRF_NO_IBSS)
78 78
79static const struct ieee80211_regdomain brcms_regdom_x2 = { 79static const struct ieee80211_regdomain brcms_regdom_x2 = {
80 .n_reg_rules = 7, 80 .n_reg_rules = 6,
81 .alpha2 = "X2", 81 .alpha2 = "X2",
82 .reg_rules = { 82 .reg_rules = {
83 BRCM_2GHZ_2412_2462, 83 BRCM_2GHZ_2412_2462,
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index 1e86ea2266d4..dbeebef562d5 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -1442,6 +1442,7 @@ static int iwl_trans_pcie_start_hw(struct iwl_trans *trans)
1442 return err; 1442 return err;
1443 1443
1444err_free_irq: 1444err_free_irq:
1445 trans_pcie->irq_requested = false;
1445 free_irq(trans_pcie->irq, trans); 1446 free_irq(trans_pcie->irq, trans);
1446error: 1447error:
1447 iwl_free_isr_ict(trans); 1448 iwl_free_isr_ict(trans);
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c
index e970897f6ab5..4cb234349fbf 100644
--- a/drivers/net/wireless/libertas/if_sdio.c
+++ b/drivers/net/wireless/libertas/if_sdio.c
@@ -1326,6 +1326,11 @@ static int if_sdio_suspend(struct device *dev)
1326 1326
1327 mmc_pm_flag_t flags = sdio_get_host_pm_caps(func); 1327 mmc_pm_flag_t flags = sdio_get_host_pm_caps(func);
1328 1328
1329 /* If we're powered off anyway, just let the mmc layer remove the
1330 * card. */
1331 if (!lbs_iface_active(card->priv))
1332 return -ENOSYS;
1333
1329 dev_info(dev, "%s: suspend: PM flags = 0x%x\n", 1334 dev_info(dev, "%s: suspend: PM flags = 0x%x\n",
1330 sdio_func_id(func), flags); 1335 sdio_func_id(func), flags);
1331 1336
diff --git a/drivers/net/wireless/mwifiex/cmdevt.c b/drivers/net/wireless/mwifiex/cmdevt.c
index c68adec3cc8b..565527aee0ea 100644
--- a/drivers/net/wireless/mwifiex/cmdevt.c
+++ b/drivers/net/wireless/mwifiex/cmdevt.c
@@ -170,7 +170,20 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
170 cmd_code = le16_to_cpu(host_cmd->command); 170 cmd_code = le16_to_cpu(host_cmd->command);
171 cmd_size = le16_to_cpu(host_cmd->size); 171 cmd_size = le16_to_cpu(host_cmd->size);
172 172
173 skb_trim(cmd_node->cmd_skb, cmd_size); 173 /* Adjust skb length */
174 if (cmd_node->cmd_skb->len > cmd_size)
175 /*
176 * cmd_size is less than sizeof(struct host_cmd_ds_command).
177 * Trim off the unused portion.
178 */
179 skb_trim(cmd_node->cmd_skb, cmd_size);
180 else if (cmd_node->cmd_skb->len < cmd_size)
181 /*
182 * cmd_size is larger than sizeof(struct host_cmd_ds_command)
183 * because we have appended custom IE TLV. Increase skb length
184 * accordingly.
185 */
186 skb_put(cmd_node->cmd_skb, cmd_size - cmd_node->cmd_skb->len);
174 187
175 do_gettimeofday(&tstamp); 188 do_gettimeofday(&tstamp);
176 dev_dbg(adapter->dev, "cmd: DNLD_CMD: (%lu.%lu): %#x, act %#x, len %d," 189 dev_dbg(adapter->dev, "cmd: DNLD_CMD: (%lu.%lu): %#x, act %#x, len %d,"
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index 8b9dbd76a252..64328af496f5 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -1611,6 +1611,7 @@ static int rt2400pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1611static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev) 1611static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1612{ 1612{
1613 int retval; 1613 int retval;
1614 u32 reg;
1614 1615
1615 /* 1616 /*
1616 * Allocate eeprom data. 1617 * Allocate eeprom data.
@@ -1624,6 +1625,14 @@ static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1624 return retval; 1625 return retval;
1625 1626
1626 /* 1627 /*
1628 * Enable rfkill polling by setting GPIO direction of the
1629 * rfkill switch GPIO pin correctly.
1630 */
1631 rt2x00pci_register_read(rt2x00dev, GPIOCSR, &reg);
1632 rt2x00_set_field32(&reg, GPIOCSR_BIT8, 1);
1633 rt2x00pci_register_write(rt2x00dev, GPIOCSR, reg);
1634
1635 /*
1627 * Initialize hw specifications. 1636 * Initialize hw specifications.
1628 */ 1637 */
1629 retval = rt2400pci_probe_hw_mode(rt2x00dev); 1638 retval = rt2400pci_probe_hw_mode(rt2x00dev);
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.h b/drivers/net/wireless/rt2x00/rt2400pci.h
index d3a4a68cc439..7564ae992b73 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.h
+++ b/drivers/net/wireless/rt2x00/rt2400pci.h
@@ -670,6 +670,7 @@
670#define GPIOCSR_BIT5 FIELD32(0x00000020) 670#define GPIOCSR_BIT5 FIELD32(0x00000020)
671#define GPIOCSR_BIT6 FIELD32(0x00000040) 671#define GPIOCSR_BIT6 FIELD32(0x00000040)
672#define GPIOCSR_BIT7 FIELD32(0x00000080) 672#define GPIOCSR_BIT7 FIELD32(0x00000080)
673#define GPIOCSR_BIT8 FIELD32(0x00000100)
673 674
674/* 675/*
675 * BBPPCSR: BBP Pin control register. 676 * BBPPCSR: BBP Pin control register.
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index d2cf8a4bc8b5..3de0406735f6 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -1929,6 +1929,7 @@ static int rt2500pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1929static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev) 1929static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1930{ 1930{
1931 int retval; 1931 int retval;
1932 u32 reg;
1932 1933
1933 /* 1934 /*
1934 * Allocate eeprom data. 1935 * Allocate eeprom data.
@@ -1942,6 +1943,14 @@ static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1942 return retval; 1943 return retval;
1943 1944
1944 /* 1945 /*
1946 * Enable rfkill polling by setting GPIO direction of the
1947 * rfkill switch GPIO pin correctly.
1948 */
1949 rt2x00pci_register_read(rt2x00dev, GPIOCSR, &reg);
1950 rt2x00_set_field32(&reg, GPIOCSR_DIR0, 1);
1951 rt2x00pci_register_write(rt2x00dev, GPIOCSR, reg);
1952
1953 /*
1945 * Initialize hw specifications. 1954 * Initialize hw specifications.
1946 */ 1955 */
1947 retval = rt2500pci_probe_hw_mode(rt2x00dev); 1956 retval = rt2500pci_probe_hw_mode(rt2x00dev);
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index 3aae36bb0a9e..89fee311d8fd 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -283,7 +283,7 @@ static int rt2500usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
283 u16 reg; 283 u16 reg;
284 284
285 rt2500usb_register_read(rt2x00dev, MAC_CSR19, &reg); 285 rt2500usb_register_read(rt2x00dev, MAC_CSR19, &reg);
286 return rt2x00_get_field32(reg, MAC_CSR19_BIT7); 286 return rt2x00_get_field16(reg, MAC_CSR19_BIT7);
287} 287}
288 288
289#ifdef CONFIG_RT2X00_LIB_LEDS 289#ifdef CONFIG_RT2X00_LIB_LEDS
@@ -1768,6 +1768,7 @@ static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1768static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev) 1768static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1769{ 1769{
1770 int retval; 1770 int retval;
1771 u16 reg;
1771 1772
1772 /* 1773 /*
1773 * Allocate eeprom data. 1774 * Allocate eeprom data.
@@ -1781,6 +1782,14 @@ static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1781 return retval; 1782 return retval;
1782 1783
1783 /* 1784 /*
1785 * Enable rfkill polling by setting GPIO direction of the
1786 * rfkill switch GPIO pin correctly.
1787 */
1788 rt2500usb_register_read(rt2x00dev, MAC_CSR19, &reg);
1789 rt2x00_set_field16(&reg, MAC_CSR19_BIT8, 0);
1790 rt2500usb_register_write(rt2x00dev, MAC_CSR19, reg);
1791
1792 /*
1784 * Initialize hw specifications. 1793 * Initialize hw specifications.
1785 */ 1794 */
1786 retval = rt2500usb_probe_hw_mode(rt2x00dev); 1795 retval = rt2500usb_probe_hw_mode(rt2x00dev);
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.h b/drivers/net/wireless/rt2x00/rt2500usb.h
index b493306a7eed..196bd5103e4f 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.h
+++ b/drivers/net/wireless/rt2x00/rt2500usb.h
@@ -189,14 +189,15 @@
189 * MAC_CSR19: GPIO control register. 189 * MAC_CSR19: GPIO control register.
190 */ 190 */
191#define MAC_CSR19 0x0426 191#define MAC_CSR19 0x0426
192#define MAC_CSR19_BIT0 FIELD32(0x0001) 192#define MAC_CSR19_BIT0 FIELD16(0x0001)
193#define MAC_CSR19_BIT1 FIELD32(0x0002) 193#define MAC_CSR19_BIT1 FIELD16(0x0002)
194#define MAC_CSR19_BIT2 FIELD32(0x0004) 194#define MAC_CSR19_BIT2 FIELD16(0x0004)
195#define MAC_CSR19_BIT3 FIELD32(0x0008) 195#define MAC_CSR19_BIT3 FIELD16(0x0008)
196#define MAC_CSR19_BIT4 FIELD32(0x0010) 196#define MAC_CSR19_BIT4 FIELD16(0x0010)
197#define MAC_CSR19_BIT5 FIELD32(0x0020) 197#define MAC_CSR19_BIT5 FIELD16(0x0020)
198#define MAC_CSR19_BIT6 FIELD32(0x0040) 198#define MAC_CSR19_BIT6 FIELD16(0x0040)
199#define MAC_CSR19_BIT7 FIELD32(0x0080) 199#define MAC_CSR19_BIT7 FIELD16(0x0080)
200#define MAC_CSR19_BIT8 FIELD16(0x0100)
200 201
201/* 202/*
202 * MAC_CSR20: LED control register. 203 * MAC_CSR20: LED control register.
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index cb8c2aca54e4..b93516d832fb 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -4089,6 +4089,7 @@ static int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
4089 rt2800_register_write(rt2x00dev, LDO_CFG0, reg); 4089 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
4090 msleep(1); 4090 msleep(1);
4091 rt2800_register_read(rt2x00dev, LDO_CFG0, &reg); 4091 rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
4092 rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 0);
4092 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1); 4093 rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
4093 rt2800_register_write(rt2x00dev, LDO_CFG0, reg); 4094 rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
4094 } 4095 }
diff --git a/drivers/net/wireless/rt2x00/rt2800pci.c b/drivers/net/wireless/rt2x00/rt2800pci.c
index 98aa426a3564..4765bbd654cd 100644
--- a/drivers/net/wireless/rt2x00/rt2800pci.c
+++ b/drivers/net/wireless/rt2x00/rt2800pci.c
@@ -983,6 +983,7 @@ static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
983static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev) 983static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
984{ 984{
985 int retval; 985 int retval;
986 u32 reg;
986 987
987 /* 988 /*
988 * Allocate eeprom data. 989 * Allocate eeprom data.
@@ -996,6 +997,14 @@ static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
996 return retval; 997 return retval;
997 998
998 /* 999 /*
1000 * Enable rfkill polling by setting GPIO direction of the
1001 * rfkill switch GPIO pin correctly.
1002 */
1003 rt2x00pci_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
1004 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_GPIOD_BIT2, 1);
1005 rt2x00pci_register_write(rt2x00dev, GPIO_CTRL_CFG, reg);
1006
1007 /*
999 * Initialize hw specifications. 1008 * Initialize hw specifications.
1000 */ 1009 */
1001 retval = rt2800_probe_hw_mode(rt2x00dev); 1010 retval = rt2800_probe_hw_mode(rt2x00dev);
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index 6cf336595e25..6b4226b71618 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -667,8 +667,16 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry,
667 skb_pull(entry->skb, RXINFO_DESC_SIZE); 667 skb_pull(entry->skb, RXINFO_DESC_SIZE);
668 668
669 /* 669 /*
670 * FIXME: we need to check for rx_pkt_len validity 670 * Check for rx_pkt_len validity. Return if invalid, leaving
671 * rxdesc->size zeroed out by the upper level.
671 */ 672 */
673 if (unlikely(rx_pkt_len == 0 ||
674 rx_pkt_len > entry->queue->data_size)) {
675 ERROR(entry->queue->rt2x00dev,
676 "Bad frame size %d, forcing to 0\n", rx_pkt_len);
677 return;
678 }
679
672 rxd = (__le32 *)(entry->skb->data + rx_pkt_len); 680 rxd = (__le32 *)(entry->skb->data + rx_pkt_len);
673 681
674 /* 682 /*
@@ -736,6 +744,7 @@ static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
736static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev) 744static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
737{ 745{
738 int retval; 746 int retval;
747 u32 reg;
739 748
740 /* 749 /*
741 * Allocate eeprom data. 750 * Allocate eeprom data.
@@ -749,6 +758,14 @@ static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
749 return retval; 758 return retval;
750 759
751 /* 760 /*
761 * Enable rfkill polling by setting GPIO direction of the
762 * rfkill switch GPIO pin correctly.
763 */
764 rt2x00usb_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
765 rt2x00_set_field32(&reg, GPIO_CTRL_CFG_GPIOD_BIT2, 1);
766 rt2x00usb_register_write(rt2x00dev, GPIO_CTRL_CFG, reg);
767
768 /*
752 * Initialize hw specifications. 769 * Initialize hw specifications.
753 */ 770 */
754 retval = rt2800_probe_hw_mode(rt2x00dev); 771 retval = rt2800_probe_hw_mode(rt2x00dev);
@@ -1157,6 +1174,8 @@ static struct usb_device_id rt2800usb_device_table[] = {
1157 { USB_DEVICE(0x1690, 0x0744) }, 1174 { USB_DEVICE(0x1690, 0x0744) },
1158 { USB_DEVICE(0x1690, 0x0761) }, 1175 { USB_DEVICE(0x1690, 0x0761) },
1159 { USB_DEVICE(0x1690, 0x0764) }, 1176 { USB_DEVICE(0x1690, 0x0764) },
1177 /* ASUS */
1178 { USB_DEVICE(0x0b05, 0x179d) },
1160 /* Cisco */ 1179 /* Cisco */
1161 { USB_DEVICE(0x167b, 0x4001) }, 1180 { USB_DEVICE(0x167b, 0x4001) },
1162 /* EnGenius */ 1181 /* EnGenius */
@@ -1222,7 +1241,6 @@ static struct usb_device_id rt2800usb_device_table[] = {
1222 { USB_DEVICE(0x0b05, 0x1760) }, 1241 { USB_DEVICE(0x0b05, 0x1760) },
1223 { USB_DEVICE(0x0b05, 0x1761) }, 1242 { USB_DEVICE(0x0b05, 0x1761) },
1224 { USB_DEVICE(0x0b05, 0x1790) }, 1243 { USB_DEVICE(0x0b05, 0x1790) },
1225 { USB_DEVICE(0x0b05, 0x179d) },
1226 /* AzureWave */ 1244 /* AzureWave */
1227 { USB_DEVICE(0x13d3, 0x3262) }, 1245 { USB_DEVICE(0x13d3, 0x3262) },
1228 { USB_DEVICE(0x13d3, 0x3284) }, 1246 { USB_DEVICE(0x13d3, 0x3284) },
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index a6b88bd4a1a5..3f07e36f462b 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -629,7 +629,7 @@ void rt2x00lib_rxdone(struct queue_entry *entry, gfp_t gfp)
629 */ 629 */
630 if (unlikely(rxdesc.size == 0 || 630 if (unlikely(rxdesc.size == 0 ||
631 rxdesc.size > entry->queue->data_size)) { 631 rxdesc.size > entry->queue->data_size)) {
632 WARNING(rt2x00dev, "Wrong frame size %d max %d.\n", 632 ERROR(rt2x00dev, "Wrong frame size %d max %d.\n",
633 rxdesc.size, entry->queue->data_size); 633 rxdesc.size, entry->queue->data_size);
634 dev_kfree_skb(entry->skb); 634 dev_kfree_skb(entry->skb);
635 goto renew_skb; 635 goto renew_skb;
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 3f7bc5cadf9a..b8ec96163922 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -2832,6 +2832,7 @@ static int rt61pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2832static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev) 2832static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev)
2833{ 2833{
2834 int retval; 2834 int retval;
2835 u32 reg;
2835 2836
2836 /* 2837 /*
2837 * Disable power saving. 2838 * Disable power saving.
@@ -2850,6 +2851,14 @@ static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev)
2850 return retval; 2851 return retval;
2851 2852
2852 /* 2853 /*
2854 * Enable rfkill polling by setting GPIO direction of the
2855 * rfkill switch GPIO pin correctly.
2856 */
2857 rt2x00pci_register_read(rt2x00dev, MAC_CSR13, &reg);
2858 rt2x00_set_field32(&reg, MAC_CSR13_BIT13, 1);
2859 rt2x00pci_register_write(rt2x00dev, MAC_CSR13, reg);
2860
2861 /*
2853 * Initialize hw specifications. 2862 * Initialize hw specifications.
2854 */ 2863 */
2855 retval = rt61pci_probe_hw_mode(rt2x00dev); 2864 retval = rt61pci_probe_hw_mode(rt2x00dev);
diff --git a/drivers/net/wireless/rt2x00/rt61pci.h b/drivers/net/wireless/rt2x00/rt61pci.h
index e3cd6db76b0e..8f3da5a56766 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.h
+++ b/drivers/net/wireless/rt2x00/rt61pci.h
@@ -372,6 +372,7 @@ struct hw_pairwise_ta_entry {
372#define MAC_CSR13_BIT10 FIELD32(0x00000400) 372#define MAC_CSR13_BIT10 FIELD32(0x00000400)
373#define MAC_CSR13_BIT11 FIELD32(0x00000800) 373#define MAC_CSR13_BIT11 FIELD32(0x00000800)
374#define MAC_CSR13_BIT12 FIELD32(0x00001000) 374#define MAC_CSR13_BIT12 FIELD32(0x00001000)
375#define MAC_CSR13_BIT13 FIELD32(0x00002000)
375 376
376/* 377/*
377 * MAC_CSR14: LED control register. 378 * MAC_CSR14: LED control register.
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index ba6e434b859d..248436c13ce0 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -2177,6 +2177,7 @@ static int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2177static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev) 2177static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
2178{ 2178{
2179 int retval; 2179 int retval;
2180 u32 reg;
2180 2181
2181 /* 2182 /*
2182 * Allocate eeprom data. 2183 * Allocate eeprom data.
@@ -2190,6 +2191,14 @@ static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
2190 return retval; 2191 return retval;
2191 2192
2192 /* 2193 /*
2194 * Enable rfkill polling by setting GPIO direction of the
2195 * rfkill switch GPIO pin correctly.
2196 */
2197 rt2x00usb_register_read(rt2x00dev, MAC_CSR13, &reg);
2198 rt2x00_set_field32(&reg, MAC_CSR13_BIT15, 0);
2199 rt2x00usb_register_write(rt2x00dev, MAC_CSR13, reg);
2200
2201 /*
2193 * Initialize hw specifications. 2202 * Initialize hw specifications.
2194 */ 2203 */
2195 retval = rt73usb_probe_hw_mode(rt2x00dev); 2204 retval = rt73usb_probe_hw_mode(rt2x00dev);
diff --git a/drivers/net/wireless/rt2x00/rt73usb.h b/drivers/net/wireless/rt2x00/rt73usb.h
index 9f6b470414d3..df1cc116b83b 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.h
+++ b/drivers/net/wireless/rt2x00/rt73usb.h
@@ -282,6 +282,9 @@ struct hw_pairwise_ta_entry {
282#define MAC_CSR13_BIT10 FIELD32(0x00000400) 282#define MAC_CSR13_BIT10 FIELD32(0x00000400)
283#define MAC_CSR13_BIT11 FIELD32(0x00000800) 283#define MAC_CSR13_BIT11 FIELD32(0x00000800)
284#define MAC_CSR13_BIT12 FIELD32(0x00001000) 284#define MAC_CSR13_BIT12 FIELD32(0x00001000)
285#define MAC_CSR13_BIT13 FIELD32(0x00002000)
286#define MAC_CSR13_BIT14 FIELD32(0x00004000)
287#define MAC_CSR13_BIT15 FIELD32(0x00008000)
285 288
286/* 289/*
287 * MAC_CSR14: LED control register. 290 * MAC_CSR14: LED control register.
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
index 44febfde9493..8a7b864faca3 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
@@ -315,7 +315,7 @@ static void _rtl92c_fill_h2c_command(struct ieee80211_hw *hw,
315 u16 box_reg = 0, box_extreg = 0; 315 u16 box_reg = 0, box_extreg = 0;
316 u8 u1b_tmp; 316 u8 u1b_tmp;
317 bool isfw_read = false; 317 bool isfw_read = false;
318 bool bwrite_sucess = false; 318 bool bwrite_success = false;
319 u8 wait_h2c_limmit = 100; 319 u8 wait_h2c_limmit = 100;
320 u8 wait_writeh2c_limmit = 100; 320 u8 wait_writeh2c_limmit = 100;
321 u8 boxcontent[4], boxextcontent[2]; 321 u8 boxcontent[4], boxextcontent[2];
@@ -354,7 +354,7 @@ static void _rtl92c_fill_h2c_command(struct ieee80211_hw *hw,
354 } 354 }
355 } 355 }
356 356
357 while (!bwrite_sucess) { 357 while (!bwrite_success) {
358 wait_writeh2c_limmit--; 358 wait_writeh2c_limmit--;
359 if (wait_writeh2c_limmit == 0) { 359 if (wait_writeh2c_limmit == 0) {
360 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 360 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
@@ -491,7 +491,7 @@ static void _rtl92c_fill_h2c_command(struct ieee80211_hw *hw,
491 break; 491 break;
492 } 492 }
493 493
494 bwrite_sucess = true; 494 bwrite_success = true;
495 495
496 rtlhal->last_hmeboxnum = boxnum + 1; 496 rtlhal->last_hmeboxnum = boxnum + 1;
497 if (rtlhal->last_hmeboxnum == 4) 497 if (rtlhal->last_hmeboxnum == 4)
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/def.h b/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
index 04c3aef8a4f6..2925094b2d91 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
@@ -117,6 +117,7 @@
117 117
118#define CHIP_VER_B BIT(4) 118#define CHIP_VER_B BIT(4)
119#define CHIP_92C_BITMASK BIT(0) 119#define CHIP_92C_BITMASK BIT(0)
120#define CHIP_UNKNOWN BIT(7)
120#define CHIP_92C_1T2R 0x03 121#define CHIP_92C_1T2R 0x03
121#define CHIP_92C 0x01 122#define CHIP_92C 0x01
122#define CHIP_88C 0x00 123#define CHIP_88C 0x00
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
index bd0da7ef290b..dd4bb0950a57 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
@@ -994,8 +994,16 @@ static enum version_8192c _rtl92ce_read_chip_version(struct ieee80211_hw *hw)
994 version = (value32 & TYPE_ID) ? VERSION_A_CHIP_92C : 994 version = (value32 & TYPE_ID) ? VERSION_A_CHIP_92C :
995 VERSION_A_CHIP_88C; 995 VERSION_A_CHIP_88C;
996 } else { 996 } else {
997 version = (value32 & TYPE_ID) ? VERSION_B_CHIP_92C : 997 version = (enum version_8192c) (CHIP_VER_B |
998 VERSION_B_CHIP_88C; 998 ((value32 & TYPE_ID) ? CHIP_92C_BITMASK : 0) |
999 ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0));
1000 if ((!IS_CHIP_VENDOR_UMC(version)) && (value32 &
1001 CHIP_VER_RTL_MASK)) {
1002 version = (enum version_8192c)(version |
1003 ((((value32 & CHIP_VER_RTL_MASK) == BIT(12))
1004 ? CHIP_VENDOR_UMC_B_CUT : CHIP_UNKNOWN) |
1005 CHIP_VENDOR_UMC));
1006 }
999 } 1007 }
1000 1008
1001 switch (version) { 1009 switch (version) {
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
index 3aa927f8b9b9..7d8f96405f42 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
@@ -162,10 +162,12 @@ int rtl92c_init_sw_vars(struct ieee80211_hw *hw)
162 162
163 /* request fw */ 163 /* request fw */
164 if (IS_VENDOR_UMC_A_CUT(rtlhal->version) && 164 if (IS_VENDOR_UMC_A_CUT(rtlhal->version) &&
165 !IS_92C_SERIAL(rtlhal->version)) 165 !IS_92C_SERIAL(rtlhal->version)) {
166 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cfwU.bin"; 166 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cfwU.bin";
167 else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version)) 167 } else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version)) {
168 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cfwU_B.bin"; 168 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cfwU_B.bin";
169 pr_info("****** This B_CUT device may not work with kernels 3.6 and earlier\n");
170 }
169 171
170 rtlpriv->max_fw_size = 0x4000; 172 rtlpriv->max_fw_size = 0x4000;
171 pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name); 173 pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/fw.c b/drivers/net/wireless/rtlwifi/rtl8192de/fw.c
index 895ae6c1f354..eb22dccc418b 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/fw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/fw.c
@@ -365,7 +365,7 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
365 u8 u1b_tmp; 365 u8 u1b_tmp;
366 bool isfw_read = false; 366 bool isfw_read = false;
367 u8 buf_index = 0; 367 u8 buf_index = 0;
368 bool bwrite_sucess = false; 368 bool bwrite_success = false;
369 u8 wait_h2c_limmit = 100; 369 u8 wait_h2c_limmit = 100;
370 u8 wait_writeh2c_limmit = 100; 370 u8 wait_writeh2c_limmit = 100;
371 u8 boxcontent[4], boxextcontent[2]; 371 u8 boxcontent[4], boxextcontent[2];
@@ -408,7 +408,7 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
408 break; 408 break;
409 } 409 }
410 } 410 }
411 while (!bwrite_sucess) { 411 while (!bwrite_success) {
412 wait_writeh2c_limmit--; 412 wait_writeh2c_limmit--;
413 if (wait_writeh2c_limmit == 0) { 413 if (wait_writeh2c_limmit == 0) {
414 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 414 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
@@ -515,7 +515,7 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
515 "switch case not processed\n"); 515 "switch case not processed\n");
516 break; 516 break;
517 } 517 }
518 bwrite_sucess = true; 518 bwrite_success = true;
519 rtlhal->last_hmeboxnum = boxnum + 1; 519 rtlhal->last_hmeboxnum = boxnum + 1;
520 if (rtlhal->last_hmeboxnum == 4) 520 if (rtlhal->last_hmeboxnum == 4)
521 rtlhal->last_hmeboxnum = 0; 521 rtlhal->last_hmeboxnum = 0;
diff --git a/drivers/pci/.gitignore b/drivers/pci/.gitignore
deleted file mode 100644
index f297ca8d313e..000000000000
--- a/drivers/pci/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
1classlist.h
2devlist.h
3gen-devlist
4
diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index 3782e1cd3697..934d861a3235 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -2196,10 +2196,8 @@ static int __init acer_wmi_init(void)
2196 interface->capability &= ~ACER_CAP_BRIGHTNESS; 2196 interface->capability &= ~ACER_CAP_BRIGHTNESS;
2197 pr_info("Brightness must be controlled by acpi video driver\n"); 2197 pr_info("Brightness must be controlled by acpi video driver\n");
2198 } else { 2198 } else {
2199#ifdef CONFIG_ACPI_VIDEO
2200 pr_info("Disabling ACPI video driver\n"); 2199 pr_info("Disabling ACPI video driver\n");
2201 acpi_video_unregister(); 2200 acpi_video_unregister();
2202#endif
2203 } 2201 }
2204 2202
2205 if (wmi_has_guid(WMID_GUID3)) { 2203 if (wmi_has_guid(WMID_GUID3)) {
diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
index dfb1a92ce949..db8f63841b42 100644
--- a/drivers/platform/x86/apple-gmux.c
+++ b/drivers/platform/x86/apple-gmux.c
@@ -101,7 +101,7 @@ static void gmux_pio_write32(struct apple_gmux_data *gmux_data, int port,
101 101
102 for (i = 0; i < 4; i++) { 102 for (i = 0; i < 4; i++) {
103 tmpval = (val >> (i * 8)) & 0xff; 103 tmpval = (val >> (i * 8)) & 0xff;
104 outb(tmpval, port + i); 104 outb(tmpval, gmux_data->iostart + port + i);
105 } 105 }
106} 106}
107 107
@@ -142,8 +142,9 @@ static u8 gmux_index_read8(struct apple_gmux_data *gmux_data, int port)
142 u8 val; 142 u8 val;
143 143
144 mutex_lock(&gmux_data->index_lock); 144 mutex_lock(&gmux_data->index_lock);
145 outb((port & 0xff), gmux_data->iostart + GMUX_PORT_READ);
146 gmux_index_wait_ready(gmux_data); 145 gmux_index_wait_ready(gmux_data);
146 outb((port & 0xff), gmux_data->iostart + GMUX_PORT_READ);
147 gmux_index_wait_complete(gmux_data);
147 val = inb(gmux_data->iostart + GMUX_PORT_VALUE); 148 val = inb(gmux_data->iostart + GMUX_PORT_VALUE);
148 mutex_unlock(&gmux_data->index_lock); 149 mutex_unlock(&gmux_data->index_lock);
149 150
@@ -166,8 +167,9 @@ static u32 gmux_index_read32(struct apple_gmux_data *gmux_data, int port)
166 u32 val; 167 u32 val;
167 168
168 mutex_lock(&gmux_data->index_lock); 169 mutex_lock(&gmux_data->index_lock);
169 outb((port & 0xff), gmux_data->iostart + GMUX_PORT_READ);
170 gmux_index_wait_ready(gmux_data); 170 gmux_index_wait_ready(gmux_data);
171 outb((port & 0xff), gmux_data->iostart + GMUX_PORT_READ);
172 gmux_index_wait_complete(gmux_data);
171 val = inl(gmux_data->iostart + GMUX_PORT_VALUE); 173 val = inl(gmux_data->iostart + GMUX_PORT_VALUE);
172 mutex_unlock(&gmux_data->index_lock); 174 mutex_unlock(&gmux_data->index_lock);
173 175
@@ -461,18 +463,22 @@ static int __devinit gmux_probe(struct pnp_dev *pnp,
461 ver_release = gmux_read8(gmux_data, GMUX_PORT_VERSION_RELEASE); 463 ver_release = gmux_read8(gmux_data, GMUX_PORT_VERSION_RELEASE);
462 if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) { 464 if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) {
463 if (gmux_is_indexed(gmux_data)) { 465 if (gmux_is_indexed(gmux_data)) {
466 u32 version;
464 mutex_init(&gmux_data->index_lock); 467 mutex_init(&gmux_data->index_lock);
465 gmux_data->indexed = true; 468 gmux_data->indexed = true;
469 version = gmux_read32(gmux_data,
470 GMUX_PORT_VERSION_MAJOR);
471 ver_major = (version >> 24) & 0xff;
472 ver_minor = (version >> 16) & 0xff;
473 ver_release = (version >> 8) & 0xff;
466 } else { 474 } else {
467 pr_info("gmux device not present\n"); 475 pr_info("gmux device not present\n");
468 ret = -ENODEV; 476 ret = -ENODEV;
469 goto err_release; 477 goto err_release;
470 } 478 }
471 pr_info("Found indexed gmux\n");
472 } else {
473 pr_info("Found gmux version %d.%d.%d\n", ver_major, ver_minor,
474 ver_release);
475 } 479 }
480 pr_info("Found gmux version %d.%d.%d [%s]\n", ver_major, ver_minor,
481 ver_release, (gmux_data->indexed ? "indexed" : "classic"));
476 482
477 memset(&props, 0, sizeof(props)); 483 memset(&props, 0, sizeof(props));
478 props.type = BACKLIGHT_PLATFORM; 484 props.type = BACKLIGHT_PLATFORM;
@@ -505,9 +511,7 @@ static int __devinit gmux_probe(struct pnp_dev *pnp,
505 * Disable the other backlight choices. 511 * Disable the other backlight choices.
506 */ 512 */
507 acpi_video_dmi_promote_vendor(); 513 acpi_video_dmi_promote_vendor();
508#if defined (CONFIG_ACPI_VIDEO) || defined (CONFIG_ACPI_VIDEO_MODULE)
509 acpi_video_unregister(); 514 acpi_video_unregister();
510#endif
511 apple_bl_unregister(); 515 apple_bl_unregister();
512 516
513 gmux_data->power_state = VGA_SWITCHEROO_ON; 517 gmux_data->power_state = VGA_SWITCHEROO_ON;
@@ -593,9 +597,7 @@ static void __devexit gmux_remove(struct pnp_dev *pnp)
593 kfree(gmux_data); 597 kfree(gmux_data);
594 598
595 acpi_video_dmi_demote_vendor(); 599 acpi_video_dmi_demote_vendor();
596#if defined (CONFIG_ACPI_VIDEO) || defined (CONFIG_ACPI_VIDEO_MODULE)
597 acpi_video_register(); 600 acpi_video_register();
598#endif
599 apple_bl_register(); 601 apple_bl_register();
600} 602}
601 603
diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
index e38f91be0b10..4b568df56643 100644
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -85,7 +85,7 @@ static char *wled_type = "unknown";
85static char *bled_type = "unknown"; 85static char *bled_type = "unknown";
86 86
87module_param(wled_type, charp, 0444); 87module_param(wled_type, charp, 0444);
88MODULE_PARM_DESC(wlan_status, "Set the wled type on boot " 88MODULE_PARM_DESC(wled_type, "Set the wled type on boot "
89 "(unknown, led or rfkill). " 89 "(unknown, led or rfkill). "
90 "default is unknown"); 90 "default is unknown");
91 91
@@ -863,9 +863,9 @@ static ssize_t show_infos(struct device *dev,
863 * The significance of others is yet to be found. 863 * The significance of others is yet to be found.
864 * If we don't find the method, we assume the device are present. 864 * If we don't find the method, we assume the device are present.
865 */ 865 */
866 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp); 866 rv = acpi_evaluate_integer(asus->handle, "HWRS", NULL, &temp);
867 if (!ACPI_FAILURE(rv)) 867 if (!ACPI_FAILURE(rv))
868 len += sprintf(page + len, "HRWS value : %#x\n", 868 len += sprintf(page + len, "HWRS value : %#x\n",
869 (uint) temp); 869 (uint) temp);
870 /* 870 /*
871 * Another value for userspace: the ASYM method returns 0x02 for 871 * Another value for userspace: the ASYM method returns 0x02 for
@@ -1751,9 +1751,9 @@ static int asus_laptop_get_info(struct asus_laptop *asus)
1751 * The significance of others is yet to be found. 1751 * The significance of others is yet to be found.
1752 */ 1752 */
1753 status = 1753 status =
1754 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result); 1754 acpi_evaluate_integer(asus->handle, "HWRS", NULL, &hwrs_result);
1755 if (!ACPI_FAILURE(status)) 1755 if (!ACPI_FAILURE(status))
1756 pr_notice(" HRWS returned %x", (int)hwrs_result); 1756 pr_notice(" HWRS returned %x", (int)hwrs_result);
1757 1757
1758 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL)) 1758 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
1759 asus->have_rsts = true; 1759 asus->have_rsts = true;
diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 2eb9fe8e8efd..c0e9ff489b24 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -47,9 +47,7 @@
47#include <linux/thermal.h> 47#include <linux/thermal.h>
48#include <acpi/acpi_bus.h> 48#include <acpi/acpi_bus.h>
49#include <acpi/acpi_drivers.h> 49#include <acpi/acpi_drivers.h>
50#ifdef CONFIG_ACPI_VIDEO
51#include <acpi/video.h> 50#include <acpi/video.h>
52#endif
53 51
54#include "asus-wmi.h" 52#include "asus-wmi.h"
55 53
@@ -1704,10 +1702,8 @@ static int asus_wmi_add(struct platform_device *pdev)
1704 if (asus->driver->quirks->wmi_backlight_power) 1702 if (asus->driver->quirks->wmi_backlight_power)
1705 acpi_video_dmi_promote_vendor(); 1703 acpi_video_dmi_promote_vendor();
1706 if (!acpi_video_backlight_support()) { 1704 if (!acpi_video_backlight_support()) {
1707#ifdef CONFIG_ACPI_VIDEO
1708 pr_info("Disabling ACPI video driver\n"); 1705 pr_info("Disabling ACPI video driver\n");
1709 acpi_video_unregister(); 1706 acpi_video_unregister();
1710#endif
1711 err = asus_wmi_backlight_init(asus); 1707 err = asus_wmi_backlight_init(asus);
1712 if (err && err != -ENODEV) 1708 if (err && err != -ENODEV)
1713 goto fail_backlight; 1709 goto fail_backlight;
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index dab91b48d22c..5ca264179f4e 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -610,12 +610,12 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
610 610
611 if (!bus) { 611 if (!bus) {
612 pr_warn("Unable to find PCI bus 1?\n"); 612 pr_warn("Unable to find PCI bus 1?\n");
613 goto out_unlock; 613 goto out_put_dev;
614 } 614 }
615 615
616 if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) { 616 if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
617 pr_err("Unable to read PCI config space?\n"); 617 pr_err("Unable to read PCI config space?\n");
618 goto out_unlock; 618 goto out_put_dev;
619 } 619 }
620 620
621 absent = (l == 0xffffffff); 621 absent = (l == 0xffffffff);
@@ -627,7 +627,7 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
627 absent ? "absent" : "present"); 627 absent ? "absent" : "present");
628 pr_warn("skipped wireless hotplug as probably " 628 pr_warn("skipped wireless hotplug as probably "
629 "inappropriate for this model\n"); 629 "inappropriate for this model\n");
630 goto out_unlock; 630 goto out_put_dev;
631 } 631 }
632 632
633 if (!blocked) { 633 if (!blocked) {
@@ -635,7 +635,7 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
635 if (dev) { 635 if (dev) {
636 /* Device already present */ 636 /* Device already present */
637 pci_dev_put(dev); 637 pci_dev_put(dev);
638 goto out_unlock; 638 goto out_put_dev;
639 } 639 }
640 dev = pci_scan_single_device(bus, 0); 640 dev = pci_scan_single_device(bus, 0);
641 if (dev) { 641 if (dev) {
@@ -650,6 +650,8 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
650 pci_dev_put(dev); 650 pci_dev_put(dev);
651 } 651 }
652 } 652 }
653out_put_dev:
654 pci_dev_put(port);
653 } 655 }
654 656
655out_unlock: 657out_unlock:
diff --git a/drivers/platform/x86/samsung-laptop.c b/drivers/platform/x86/samsung-laptop.c
index c1ca7bcebb66..dd90d15f5210 100644
--- a/drivers/platform/x86/samsung-laptop.c
+++ b/drivers/platform/x86/samsung-laptop.c
@@ -26,9 +26,7 @@
26#include <linux/seq_file.h> 26#include <linux/seq_file.h>
27#include <linux/debugfs.h> 27#include <linux/debugfs.h>
28#include <linux/ctype.h> 28#include <linux/ctype.h>
29#ifdef CONFIG_ACPI_VIDEO
30#include <acpi/video.h> 29#include <acpi/video.h>
31#endif
32 30
33/* 31/*
34 * This driver is needed because a number of Samsung laptops do not hook 32 * This driver is needed because a number of Samsung laptops do not hook
@@ -1558,9 +1556,7 @@ static int __init samsung_init(void)
1558 samsung->handle_backlight = false; 1556 samsung->handle_backlight = false;
1559 } else if (samsung->quirks->broken_acpi_video) { 1557 } else if (samsung->quirks->broken_acpi_video) {
1560 pr_info("Disabling ACPI video driver\n"); 1558 pr_info("Disabling ACPI video driver\n");
1561#ifdef CONFIG_ACPI_VIDEO
1562 acpi_video_unregister(); 1559 acpi_video_unregister();
1563#endif
1564 } 1560 }
1565#endif 1561#endif
1566 1562
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 80e377949314..52daaa816e53 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -545,7 +545,7 @@ TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
545 */ 545 */
546 546
547static int acpi_evalf(acpi_handle handle, 547static int acpi_evalf(acpi_handle handle,
548 void *res, char *method, char *fmt, ...) 548 int *res, char *method, char *fmt, ...)
549{ 549{
550 char *fmt0 = fmt; 550 char *fmt0 = fmt;
551 struct acpi_object_list params; 551 struct acpi_object_list params;
@@ -606,7 +606,7 @@ static int acpi_evalf(acpi_handle handle,
606 success = (status == AE_OK && 606 success = (status == AE_OK &&
607 out_obj.type == ACPI_TYPE_INTEGER); 607 out_obj.type == ACPI_TYPE_INTEGER);
608 if (success && res) 608 if (success && res)
609 *(int *)res = out_obj.integer.value; 609 *res = out_obj.integer.value;
610 break; 610 break;
611 case 'v': /* void */ 611 case 'v': /* void */
612 success = status == AE_OK; 612 success = status == AE_OK;
@@ -7386,17 +7386,18 @@ static int fan_get_status(u8 *status)
7386 * Add TPACPI_FAN_RD_ACPI_FANS ? */ 7386 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7387 7387
7388 switch (fan_status_access_mode) { 7388 switch (fan_status_access_mode) {
7389 case TPACPI_FAN_RD_ACPI_GFAN: 7389 case TPACPI_FAN_RD_ACPI_GFAN: {
7390 /* 570, 600e/x, 770e, 770x */ 7390 /* 570, 600e/x, 770e, 770x */
7391 int res;
7391 7392
7392 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) 7393 if (unlikely(!acpi_evalf(gfan_handle, &res, NULL, "d")))
7393 return -EIO; 7394 return -EIO;
7394 7395
7395 if (likely(status)) 7396 if (likely(status))
7396 *status = s & 0x07; 7397 *status = res & 0x07;
7397 7398
7398 break; 7399 break;
7399 7400 }
7400 case TPACPI_FAN_RD_TPEC: 7401 case TPACPI_FAN_RD_TPEC:
7401 /* all except 570, 600e/x, 770e, 770x */ 7402 /* all except 570, 600e/x, 770e, 770x */
7402 if (unlikely(!acpi_ec_read(fan_status_offset, &s))) 7403 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
diff --git a/drivers/pwm/pwm-tiecap.c b/drivers/pwm/pwm-tiecap.c
index 0b66d0f25922..4b6688909fee 100644
--- a/drivers/pwm/pwm-tiecap.c
+++ b/drivers/pwm/pwm-tiecap.c
@@ -100,6 +100,13 @@ static int ecap_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
100 writel(period_cycles, pc->mmio_base + CAP3); 100 writel(period_cycles, pc->mmio_base + CAP3);
101 } 101 }
102 102
103 if (!test_bit(PWMF_ENABLED, &pwm->flags)) {
104 reg_val = readw(pc->mmio_base + ECCTL2);
105 /* Disable APWM mode to put APWM output Low */
106 reg_val &= ~ECCTL2_APWM_MODE;
107 writew(reg_val, pc->mmio_base + ECCTL2);
108 }
109
103 pm_runtime_put_sync(pc->chip.dev); 110 pm_runtime_put_sync(pc->chip.dev);
104 return 0; 111 return 0;
105} 112}
diff --git a/drivers/pwm/pwm-tiehrpwm.c b/drivers/pwm/pwm-tiehrpwm.c
index c3756d1be194..b1996bcd5b78 100644
--- a/drivers/pwm/pwm-tiehrpwm.c
+++ b/drivers/pwm/pwm-tiehrpwm.c
@@ -104,6 +104,7 @@ struct ehrpwm_pwm_chip {
104 struct pwm_chip chip; 104 struct pwm_chip chip;
105 unsigned int clk_rate; 105 unsigned int clk_rate;
106 void __iomem *mmio_base; 106 void __iomem *mmio_base;
107 unsigned long period_cycles[NUM_PWM_CHANNEL];
107}; 108};
108 109
109static inline struct ehrpwm_pwm_chip *to_ehrpwm_pwm_chip(struct pwm_chip *chip) 110static inline struct ehrpwm_pwm_chip *to_ehrpwm_pwm_chip(struct pwm_chip *chip)
@@ -210,6 +211,7 @@ static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
210 unsigned long long c; 211 unsigned long long c;
211 unsigned long period_cycles, duty_cycles; 212 unsigned long period_cycles, duty_cycles;
212 unsigned short ps_divval, tb_divval; 213 unsigned short ps_divval, tb_divval;
214 int i;
213 215
214 if (period_ns < 0 || duty_ns < 0 || period_ns > NSEC_PER_SEC) 216 if (period_ns < 0 || duty_ns < 0 || period_ns > NSEC_PER_SEC)
215 return -ERANGE; 217 return -ERANGE;
@@ -229,6 +231,28 @@ static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
229 duty_cycles = (unsigned long)c; 231 duty_cycles = (unsigned long)c;
230 } 232 }
231 233
234 /*
235 * Period values should be same for multiple PWM channels as IP uses
236 * same period register for multiple channels.
237 */
238 for (i = 0; i < NUM_PWM_CHANNEL; i++) {
239 if (pc->period_cycles[i] &&
240 (pc->period_cycles[i] != period_cycles)) {
241 /*
242 * Allow channel to reconfigure period if no other
243 * channels being configured.
244 */
245 if (i == pwm->hwpwm)
246 continue;
247
248 dev_err(chip->dev, "Period value conflicts with channel %d\n",
249 i);
250 return -EINVAL;
251 }
252 }
253
254 pc->period_cycles[pwm->hwpwm] = period_cycles;
255
232 /* Configure clock prescaler to support Low frequency PWM wave */ 256 /* Configure clock prescaler to support Low frequency PWM wave */
233 if (set_prescale_div(period_cycles/PERIOD_MAX, &ps_divval, 257 if (set_prescale_div(period_cycles/PERIOD_MAX, &ps_divval,
234 &tb_divval)) { 258 &tb_divval)) {
@@ -320,10 +344,15 @@ static void ehrpwm_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
320 344
321static void ehrpwm_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 345static void ehrpwm_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
322{ 346{
347 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
348
323 if (test_bit(PWMF_ENABLED, &pwm->flags)) { 349 if (test_bit(PWMF_ENABLED, &pwm->flags)) {
324 dev_warn(chip->dev, "Removing PWM device without disabling\n"); 350 dev_warn(chip->dev, "Removing PWM device without disabling\n");
325 pm_runtime_put_sync(chip->dev); 351 pm_runtime_put_sync(chip->dev);
326 } 352 }
353
354 /* set period value to zero on free */
355 pc->period_cycles[pwm->hwpwm] = 0;
327} 356}
328 357
329static const struct pwm_ops ehrpwm_pwm_ops = { 358static const struct pwm_ops ehrpwm_pwm_ops = {
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 4e932cc695e9..e98a5e7827df 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -33,9 +33,8 @@ config REGULATOR_DUMMY
33 help 33 help
34 If this option is enabled then when a regulator lookup fails 34 If this option is enabled then when a regulator lookup fails
35 and the board has not specified that it has provided full 35 and the board has not specified that it has provided full
36 constraints then the regulator core will provide an always 36 constraints the regulator core will provide an always
37 enabled dummy regulator will be provided, allowing consumer 37 enabled dummy regulator, allowing consumer drivers to continue.
38 drivers to continue.
39 38
40 A warning will be generated when this substitution is done. 39 A warning will be generated when this substitution is done.
41 40
@@ -50,11 +49,11 @@ config REGULATOR_VIRTUAL_CONSUMER
50 tristate "Virtual regulator consumer support" 49 tristate "Virtual regulator consumer support"
51 help 50 help
52 This driver provides a virtual consumer for the voltage and 51 This driver provides a virtual consumer for the voltage and
53 current regulator API which provides sysfs controls for 52 current regulator API which provides sysfs controls for
54 configuring the supplies requested. This is mainly useful 53 configuring the supplies requested. This is mainly useful
55 for test purposes. 54 for test purposes.
56 55
57 If unsure, say no. 56 If unsure, say no.
58 57
59config REGULATOR_USERSPACE_CONSUMER 58config REGULATOR_USERSPACE_CONSUMER
60 tristate "Userspace regulator consumer support" 59 tristate "Userspace regulator consumer support"
@@ -63,7 +62,7 @@ config REGULATOR_USERSPACE_CONSUMER
63 from user space. Userspace consumer driver provides ability to 62 from user space. Userspace consumer driver provides ability to
64 control power supplies for such devices. 63 control power supplies for such devices.
65 64
66 If unsure, say no. 65 If unsure, say no.
67 66
68config REGULATOR_GPIO 67config REGULATOR_GPIO
69 tristate "GPIO regulator support" 68 tristate "GPIO regulator support"
@@ -110,6 +109,17 @@ config REGULATOR_DA9052
110 This driver supports the voltage regulators of DA9052-BC and 109 This driver supports the voltage regulators of DA9052-BC and
111 DA9053-AA/Bx PMIC. 110 DA9053-AA/Bx PMIC.
112 111
112config REGULATOR_FAN53555
113 tristate "Fairchild FAN53555 Regulator"
114 depends on I2C
115 select REGMAP_I2C
116 help
117 This driver supports Fairchild FAN53555 Digitally Programmable
118 TinyBuck Regulator. The FAN53555 is a step-down switching voltage
119 regulator that delivers a digitally programmable output from an
120 input voltage supply of 2.5V to 5.5V. The output voltage is
121 programmed through an I2C interface.
122
113config REGULATOR_ANATOP 123config REGULATOR_ANATOP
114 tristate "Freescale i.MX on-chip ANATOP LDO regulators" 124 tristate "Freescale i.MX on-chip ANATOP LDO regulators"
115 depends on MFD_ANATOP 125 depends on MFD_ANATOP
@@ -172,6 +182,14 @@ config REGULATOR_MAX8660
172 This driver controls a Maxim 8660/8661 voltage output 182 This driver controls a Maxim 8660/8661 voltage output
173 regulator via I2C bus. 183 regulator via I2C bus.
174 184
185config REGULATOR_MAX8907
186 tristate "Maxim 8907 voltage regulator"
187 depends on MFD_MAX8907
188 help
189 This driver controls a Maxim 8907 voltage output regulator
190 via I2C bus. The provided regulator is suitable for Tegra
191 chip to control Step-Down DC-DC and LDOs.
192
175config REGULATOR_MAX8925 193config REGULATOR_MAX8925
176 tristate "Maxim MAX8925 Power Management IC" 194 tristate "Maxim MAX8925 Power Management IC"
177 depends on MFD_MAX8925 195 depends on MFD_MAX8925
@@ -247,7 +265,7 @@ config REGULATOR_LP8788
247 265
248config REGULATOR_PCF50633 266config REGULATOR_PCF50633
249 tristate "NXP PCF50633 regulator driver" 267 tristate "NXP PCF50633 regulator driver"
250 depends on MFD_PCF50633 268 depends on MFD_PCF50633
251 help 269 help
252 Say Y here to support the voltage regulators and convertors 270 Say Y here to support the voltage regulators and convertors
253 on PCF50633 271 on PCF50633
@@ -416,7 +434,7 @@ config REGULATOR_WM8350
416 depends on MFD_WM8350 434 depends on MFD_WM8350
417 help 435 help
418 This driver provides support for the voltage and current regulators 436 This driver provides support for the voltage and current regulators
419 of the WM8350 AudioPlus PMIC. 437 of the WM8350 AudioPlus PMIC.
420 438
421config REGULATOR_WM8400 439config REGULATOR_WM8400
422 tristate "Wolfson Microelectronics WM8400 AudioPlus PMIC" 440 tristate "Wolfson Microelectronics WM8400 AudioPlus PMIC"
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 3342615cf25e..e431eed8a878 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
20obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 20obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
21obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 21obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
22obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 22obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
23obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o
23obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o 24obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
24obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o 25obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
25obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 26obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
@@ -30,6 +31,7 @@ obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o
30obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 31obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
31obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 32obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
32obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 33obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o
34obj-$(CONFIG_REGULATOR_MAX8907) += max8907-regulator.o
33obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o 35obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o
34obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o 36obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o
35obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o 37obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c
index 6f45bfd22e83..167c93f21981 100644
--- a/drivers/regulator/aat2870-regulator.c
+++ b/drivers/regulator/aat2870-regulator.c
@@ -162,7 +162,7 @@ static struct aat2870_regulator *aat2870_get_regulator(int id)
162static int aat2870_regulator_probe(struct platform_device *pdev) 162static int aat2870_regulator_probe(struct platform_device *pdev)
163{ 163{
164 struct aat2870_regulator *ri; 164 struct aat2870_regulator *ri;
165 struct regulator_config config = { 0 }; 165 struct regulator_config config = { };
166 struct regulator_dev *rdev; 166 struct regulator_dev *rdev;
167 167
168 ri = aat2870_get_regulator(pdev->id); 168 ri = aat2870_get_regulator(pdev->id);
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index c151fd5d8c97..65ad2b36ce36 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -347,17 +347,11 @@ static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg)
347 return abreg->plfdata->external_voltage; 347 return abreg->plfdata->external_voltage;
348} 348}
349 349
350static int ab3100_get_fixed_voltage_regulator(struct regulator_dev *reg)
351{
352 return reg->desc->min_uV;
353}
354
355static struct regulator_ops regulator_ops_fixed = { 350static struct regulator_ops regulator_ops_fixed = {
356 .list_voltage = regulator_list_voltage_linear, 351 .list_voltage = regulator_list_voltage_linear,
357 .enable = ab3100_enable_regulator, 352 .enable = ab3100_enable_regulator,
358 .disable = ab3100_disable_regulator, 353 .disable = ab3100_disable_regulator,
359 .is_enabled = ab3100_is_enabled_regulator, 354 .is_enabled = ab3100_is_enabled_regulator,
360 .get_voltage = ab3100_get_fixed_voltage_regulator,
361}; 355};
362 356
363static struct regulator_ops regulator_ops_variable = { 357static struct regulator_ops regulator_ops_variable = {
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index 10f2f4d4d190..e3d1d063025a 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -37,6 +37,7 @@
37 * @voltage_bank: bank to control regulator voltage 37 * @voltage_bank: bank to control regulator voltage
38 * @voltage_reg: register to control regulator voltage 38 * @voltage_reg: register to control regulator voltage
39 * @voltage_mask: mask to control regulator voltage 39 * @voltage_mask: mask to control regulator voltage
40 * @voltage_shift: shift to control regulator voltage
40 * @delay: startup/set voltage delay in us 41 * @delay: startup/set voltage delay in us
41 */ 42 */
42struct ab8500_regulator_info { 43struct ab8500_regulator_info {
@@ -50,6 +51,7 @@ struct ab8500_regulator_info {
50 u8 voltage_bank; 51 u8 voltage_bank;
51 u8 voltage_reg; 52 u8 voltage_reg;
52 u8 voltage_mask; 53 u8 voltage_mask;
54 u8 voltage_shift;
53 unsigned int delay; 55 unsigned int delay;
54}; 56};
55 57
@@ -195,17 +197,14 @@ static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
195 } 197 }
196 198
197 dev_vdbg(rdev_get_dev(rdev), 199 dev_vdbg(rdev_get_dev(rdev),
198 "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," 200 "%s-get_voltage (bank, reg, mask, shift, value): "
199 " 0x%x\n", 201 "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
200 info->desc.name, info->voltage_bank, info->voltage_reg, 202 info->desc.name, info->voltage_bank,
201 info->voltage_mask, regval); 203 info->voltage_reg, info->voltage_mask,
204 info->voltage_shift, regval);
202 205
203 /* vintcore has a different layout */
204 val = regval & info->voltage_mask; 206 val = regval & info->voltage_mask;
205 if (info->desc.id == AB8500_LDO_INTCORE) 207 return val >> info->voltage_shift;
206 return val >> 0x3;
207 else
208 return val;
209} 208}
210 209
211static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev, 210static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
@@ -221,7 +220,7 @@ static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
221 } 220 }
222 221
223 /* set the registers for the request */ 222 /* set the registers for the request */
224 regval = (u8)selector; 223 regval = (u8)selector << info->voltage_shift;
225 ret = abx500_mask_and_set_register_interruptible(info->dev, 224 ret = abx500_mask_and_set_register_interruptible(info->dev,
226 info->voltage_bank, info->voltage_reg, 225 info->voltage_bank, info->voltage_reg,
227 info->voltage_mask, regval); 226 info->voltage_mask, regval);
@@ -238,13 +237,6 @@ static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
238 return ret; 237 return ret;
239} 238}
240 239
241static int ab8500_regulator_enable_time(struct regulator_dev *rdev)
242{
243 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
244
245 return info->delay;
246}
247
248static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev, 240static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
249 unsigned int old_sel, 241 unsigned int old_sel,
250 unsigned int new_sel) 242 unsigned int new_sel)
@@ -261,22 +253,14 @@ static struct regulator_ops ab8500_regulator_ops = {
261 .get_voltage_sel = ab8500_regulator_get_voltage_sel, 253 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
262 .set_voltage_sel = ab8500_regulator_set_voltage_sel, 254 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
263 .list_voltage = regulator_list_voltage_table, 255 .list_voltage = regulator_list_voltage_table,
264 .enable_time = ab8500_regulator_enable_time,
265 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, 256 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
266}; 257};
267 258
268static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
269{
270 return rdev->desc->min_uV;
271}
272
273static struct regulator_ops ab8500_regulator_fixed_ops = { 259static struct regulator_ops ab8500_regulator_fixed_ops = {
274 .enable = ab8500_regulator_enable, 260 .enable = ab8500_regulator_enable,
275 .disable = ab8500_regulator_disable, 261 .disable = ab8500_regulator_disable,
276 .is_enabled = ab8500_regulator_is_enabled, 262 .is_enabled = ab8500_regulator_is_enabled,
277 .get_voltage = ab8500_fixed_get_voltage,
278 .list_voltage = regulator_list_voltage_linear, 263 .list_voltage = regulator_list_voltage_linear,
279 .enable_time = ab8500_regulator_enable_time,
280}; 264};
281 265
282static struct ab8500_regulator_info 266static struct ab8500_regulator_info
@@ -358,6 +342,7 @@ static struct ab8500_regulator_info
358 .voltage_bank = 0x03, 342 .voltage_bank = 0x03,
359 .voltage_reg = 0x80, 343 .voltage_reg = 0x80,
360 .voltage_mask = 0x38, 344 .voltage_mask = 0x38,
345 .voltage_shift = 3,
361 }, 346 },
362 347
363 /* 348 /*
@@ -374,6 +359,7 @@ static struct ab8500_regulator_info
374 .owner = THIS_MODULE, 359 .owner = THIS_MODULE,
375 .n_voltages = 1, 360 .n_voltages = 1,
376 .min_uV = 2000000, 361 .min_uV = 2000000,
362 .enable_time = 10000,
377 }, 363 },
378 .delay = 10000, 364 .delay = 10000,
379 .update_bank = 0x03, 365 .update_bank = 0x03,
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index c8f95c07adb6..d184aa35abcb 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -39,6 +39,8 @@ static struct regulator_ops arizona_ldo1_ops = {
39 .map_voltage = regulator_map_voltage_linear, 39 .map_voltage = regulator_map_voltage_linear,
40 .get_voltage_sel = regulator_get_voltage_sel_regmap, 40 .get_voltage_sel = regulator_get_voltage_sel_regmap,
41 .set_voltage_sel = regulator_set_voltage_sel_regmap, 41 .set_voltage_sel = regulator_set_voltage_sel_regmap,
42 .get_bypass = regulator_get_bypass_regmap,
43 .set_bypass = regulator_set_bypass_regmap,
42}; 44};
43 45
44static const struct regulator_desc arizona_ldo1 = { 46static const struct regulator_desc arizona_ldo1 = {
@@ -49,9 +51,11 @@ static const struct regulator_desc arizona_ldo1 = {
49 51
50 .vsel_reg = ARIZONA_LDO1_CONTROL_1, 52 .vsel_reg = ARIZONA_LDO1_CONTROL_1,
51 .vsel_mask = ARIZONA_LDO1_VSEL_MASK, 53 .vsel_mask = ARIZONA_LDO1_VSEL_MASK,
54 .bypass_reg = ARIZONA_LDO1_CONTROL_1,
55 .bypass_mask = ARIZONA_LDO1_BYPASS,
52 .min_uV = 900000, 56 .min_uV = 900000,
53 .uV_step = 50000, 57 .uV_step = 50000,
54 .n_voltages = 7, 58 .n_voltages = 6,
55 59
56 .owner = THIS_MODULE, 60 .owner = THIS_MODULE,
57}; 61};
diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
index 450a069aa9b6..d9b1f82cc5bd 100644
--- a/drivers/regulator/arizona-micsupp.c
+++ b/drivers/regulator/arizona-micsupp.c
@@ -82,6 +82,9 @@ static struct regulator_ops arizona_micsupp_ops = {
82 82
83 .get_voltage_sel = regulator_get_voltage_sel_regmap, 83 .get_voltage_sel = regulator_get_voltage_sel_regmap,
84 .set_voltage_sel = regulator_set_voltage_sel_regmap, 84 .set_voltage_sel = regulator_set_voltage_sel_regmap,
85
86 .get_bypass = regulator_get_bypass_regmap,
87 .set_bypass = regulator_set_bypass_regmap,
85}; 88};
86 89
87static const struct regulator_desc arizona_micsupp = { 90static const struct regulator_desc arizona_micsupp = {
@@ -95,6 +98,8 @@ static const struct regulator_desc arizona_micsupp = {
95 .vsel_mask = ARIZONA_LDO2_VSEL_MASK, 98 .vsel_mask = ARIZONA_LDO2_VSEL_MASK,
96 .enable_reg = ARIZONA_MIC_CHARGE_PUMP_1, 99 .enable_reg = ARIZONA_MIC_CHARGE_PUMP_1,
97 .enable_mask = ARIZONA_CPMIC_ENA, 100 .enable_mask = ARIZONA_CPMIC_ENA,
101 .bypass_reg = ARIZONA_MIC_CHARGE_PUMP_1,
102 .bypass_mask = ARIZONA_CPMIC_BYPASS,
98 103
99 .owner = THIS_MODULE, 104 .owner = THIS_MODULE,
100}; 105};
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 48385318175a..2e0352dc26bd 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -77,6 +77,7 @@ struct regulator {
77 struct device *dev; 77 struct device *dev;
78 struct list_head list; 78 struct list_head list;
79 unsigned int always_on:1; 79 unsigned int always_on:1;
80 unsigned int bypass:1;
80 int uA_load; 81 int uA_load;
81 int min_uV; 82 int min_uV;
82 int max_uV; 83 int max_uV;
@@ -394,6 +395,9 @@ static ssize_t regulator_status_show(struct device *dev,
394 case REGULATOR_STATUS_STANDBY: 395 case REGULATOR_STATUS_STANDBY:
395 label = "standby"; 396 label = "standby";
396 break; 397 break;
398 case REGULATOR_STATUS_BYPASS:
399 label = "bypass";
400 break;
397 case REGULATOR_STATUS_UNDEFINED: 401 case REGULATOR_STATUS_UNDEFINED:
398 label = "undefined"; 402 label = "undefined";
399 break; 403 break;
@@ -585,6 +589,27 @@ static ssize_t regulator_suspend_standby_state_show(struct device *dev,
585static DEVICE_ATTR(suspend_standby_state, 0444, 589static DEVICE_ATTR(suspend_standby_state, 0444,
586 regulator_suspend_standby_state_show, NULL); 590 regulator_suspend_standby_state_show, NULL);
587 591
592static ssize_t regulator_bypass_show(struct device *dev,
593 struct device_attribute *attr, char *buf)
594{
595 struct regulator_dev *rdev = dev_get_drvdata(dev);
596 const char *report;
597 bool bypass;
598 int ret;
599
600 ret = rdev->desc->ops->get_bypass(rdev, &bypass);
601
602 if (ret != 0)
603 report = "unknown";
604 else if (bypass)
605 report = "enabled";
606 else
607 report = "disabled";
608
609 return sprintf(buf, "%s\n", report);
610}
611static DEVICE_ATTR(bypass, 0444,
612 regulator_bypass_show, NULL);
588 613
589/* 614/*
590 * These are the only attributes are present for all regulators. 615 * These are the only attributes are present for all regulators.
@@ -778,6 +803,9 @@ static void print_constraints(struct regulator_dev *rdev)
778 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) 803 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
779 count += sprintf(buf + count, "standby"); 804 count += sprintf(buf + count, "standby");
780 805
806 if (!count)
807 sprintf(buf, "no parameters");
808
781 rdev_info(rdev, "%s\n", buf); 809 rdev_info(rdev, "%s\n", buf);
782 810
783 if ((constraints->min_uV != constraints->max_uV) && 811 if ((constraints->min_uV != constraints->max_uV) &&
@@ -974,6 +1002,7 @@ static int set_supply(struct regulator_dev *rdev,
974 err = -ENOMEM; 1002 err = -ENOMEM;
975 return err; 1003 return err;
976 } 1004 }
1005 supply_rdev->open_count++;
977 1006
978 return 0; 1007 return 0;
979} 1008}
@@ -1720,6 +1749,9 @@ int regulator_disable_deferred(struct regulator *regulator, int ms)
1720 if (regulator->always_on) 1749 if (regulator->always_on)
1721 return 0; 1750 return 0;
1722 1751
1752 if (!ms)
1753 return regulator_disable(regulator);
1754
1723 mutex_lock(&rdev->mutex); 1755 mutex_lock(&rdev->mutex);
1724 rdev->deferred_disables++; 1756 rdev->deferred_disables++;
1725 mutex_unlock(&rdev->mutex); 1757 mutex_unlock(&rdev->mutex);
@@ -2178,9 +2210,12 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2178 } 2210 }
2179 } 2211 }
2180 2212
2181 if (ret == 0 && best_val >= 0) 2213 if (ret == 0 && best_val >= 0) {
2214 unsigned long data = best_val;
2215
2182 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, 2216 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE,
2183 (void *)best_val); 2217 (void *)data);
2218 }
2184 2219
2185 trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val); 2220 trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val);
2186 2221
@@ -2291,8 +2326,8 @@ int regulator_set_voltage_time(struct regulator *regulator,
2291EXPORT_SYMBOL_GPL(regulator_set_voltage_time); 2326EXPORT_SYMBOL_GPL(regulator_set_voltage_time);
2292 2327
2293/** 2328/**
2294 *regulator_set_voltage_time_sel - get raise/fall time 2329 * regulator_set_voltage_time_sel - get raise/fall time
2295 * @regulator: regulator source 2330 * @rdev: regulator source device
2296 * @old_selector: selector for starting voltage 2331 * @old_selector: selector for starting voltage
2297 * @new_selector: selector for target voltage 2332 * @new_selector: selector for target voltage
2298 * 2333 *
@@ -2388,6 +2423,8 @@ static int _regulator_get_voltage(struct regulator_dev *rdev)
2388 ret = rdev->desc->ops->list_voltage(rdev, sel); 2423 ret = rdev->desc->ops->list_voltage(rdev, sel);
2389 } else if (rdev->desc->ops->get_voltage) { 2424 } else if (rdev->desc->ops->get_voltage) {
2390 ret = rdev->desc->ops->get_voltage(rdev); 2425 ret = rdev->desc->ops->get_voltage(rdev);
2426 } else if (rdev->desc->ops->list_voltage) {
2427 ret = rdev->desc->ops->list_voltage(rdev, 0);
2391 } else { 2428 } else {
2392 return -EINVAL; 2429 return -EINVAL;
2393 } 2430 }
@@ -2674,6 +2711,100 @@ out:
2674EXPORT_SYMBOL_GPL(regulator_set_optimum_mode); 2711EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
2675 2712
2676/** 2713/**
2714 * regulator_set_bypass_regmap - Default set_bypass() using regmap
2715 *
2716 * @rdev: device to operate on.
2717 * @enable: state to set.
2718 */
2719int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable)
2720{
2721 unsigned int val;
2722
2723 if (enable)
2724 val = rdev->desc->bypass_mask;
2725 else
2726 val = 0;
2727
2728 return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg,
2729 rdev->desc->bypass_mask, val);
2730}
2731EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap);
2732
2733/**
2734 * regulator_get_bypass_regmap - Default get_bypass() using regmap
2735 *
2736 * @rdev: device to operate on.
2737 * @enable: current state.
2738 */
2739int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable)
2740{
2741 unsigned int val;
2742 int ret;
2743
2744 ret = regmap_read(rdev->regmap, rdev->desc->bypass_reg, &val);
2745 if (ret != 0)
2746 return ret;
2747
2748 *enable = val & rdev->desc->bypass_mask;
2749
2750 return 0;
2751}
2752EXPORT_SYMBOL_GPL(regulator_get_bypass_regmap);
2753
2754/**
2755 * regulator_allow_bypass - allow the regulator to go into bypass mode
2756 *
2757 * @regulator: Regulator to configure
2758 * @allow: enable or disable bypass mode
2759 *
2760 * Allow the regulator to go into bypass mode if all other consumers
2761 * for the regulator also enable bypass mode and the machine
2762 * constraints allow this. Bypass mode means that the regulator is
2763 * simply passing the input directly to the output with no regulation.
2764 */
2765int regulator_allow_bypass(struct regulator *regulator, bool enable)
2766{
2767 struct regulator_dev *rdev = regulator->rdev;
2768 int ret = 0;
2769
2770 if (!rdev->desc->ops->set_bypass)
2771 return 0;
2772
2773 if (rdev->constraints &&
2774 !(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_BYPASS))
2775 return 0;
2776
2777 mutex_lock(&rdev->mutex);
2778
2779 if (enable && !regulator->bypass) {
2780 rdev->bypass_count++;
2781
2782 if (rdev->bypass_count == rdev->open_count) {
2783 ret = rdev->desc->ops->set_bypass(rdev, enable);
2784 if (ret != 0)
2785 rdev->bypass_count--;
2786 }
2787
2788 } else if (!enable && regulator->bypass) {
2789 rdev->bypass_count--;
2790
2791 if (rdev->bypass_count != rdev->open_count) {
2792 ret = rdev->desc->ops->set_bypass(rdev, enable);
2793 if (ret != 0)
2794 rdev->bypass_count++;
2795 }
2796 }
2797
2798 if (ret == 0)
2799 regulator->bypass = enable;
2800
2801 mutex_unlock(&rdev->mutex);
2802
2803 return ret;
2804}
2805EXPORT_SYMBOL_GPL(regulator_allow_bypass);
2806
2807/**
2677 * regulator_register_notifier - register regulator event notifier 2808 * regulator_register_notifier - register regulator event notifier
2678 * @regulator: regulator source 2809 * @regulator: regulator source
2679 * @nb: notifier block 2810 * @nb: notifier block
@@ -3011,7 +3142,8 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
3011 3142
3012 /* some attributes need specific methods to be displayed */ 3143 /* some attributes need specific methods to be displayed */
3013 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || 3144 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) ||
3014 (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0)) { 3145 (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) ||
3146 (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0)) {
3015 status = device_create_file(dev, &dev_attr_microvolts); 3147 status = device_create_file(dev, &dev_attr_microvolts);
3016 if (status < 0) 3148 if (status < 0)
3017 return status; 3149 return status;
@@ -3036,6 +3168,11 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
3036 if (status < 0) 3168 if (status < 0)
3037 return status; 3169 return status;
3038 } 3170 }
3171 if (ops->get_bypass) {
3172 status = device_create_file(dev, &dev_attr_bypass);
3173 if (status < 0)
3174 return status;
3175 }
3039 3176
3040 /* some attributes are type-specific */ 3177 /* some attributes are type-specific */
3041 if (rdev->desc->type == REGULATOR_CURRENT) { 3178 if (rdev->desc->type == REGULATOR_CURRENT) {
@@ -3124,6 +3261,8 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
3124 &rdev->use_count); 3261 &rdev->use_count);
3125 debugfs_create_u32("open_count", 0444, rdev->debugfs, 3262 debugfs_create_u32("open_count", 0444, rdev->debugfs,
3126 &rdev->open_count); 3263 &rdev->open_count);
3264 debugfs_create_u32("bypass_count", 0444, rdev->debugfs,
3265 &rdev->bypass_count);
3127} 3266}
3128 3267
3129/** 3268/**
@@ -3189,8 +3328,10 @@ regulator_register(const struct regulator_desc *regulator_desc,
3189 rdev->desc = regulator_desc; 3328 rdev->desc = regulator_desc;
3190 if (config->regmap) 3329 if (config->regmap)
3191 rdev->regmap = config->regmap; 3330 rdev->regmap = config->regmap;
3192 else 3331 else if (dev_get_regmap(dev, NULL))
3193 rdev->regmap = dev_get_regmap(dev, NULL); 3332 rdev->regmap = dev_get_regmap(dev, NULL);
3333 else if (dev->parent)
3334 rdev->regmap = dev_get_regmap(dev->parent, NULL);
3194 INIT_LIST_HEAD(&rdev->consumer_list); 3335 INIT_LIST_HEAD(&rdev->consumer_list);
3195 INIT_LIST_HEAD(&rdev->list); 3336 INIT_LIST_HEAD(&rdev->list);
3196 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); 3337 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c
index 903299cf15cf..27355b1199e5 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -133,8 +133,8 @@ static int da9052_dcdc_set_current_limit(struct regulator_dev *rdev, int min_uA,
133 max_uA < da9052_current_limits[row][DA9052_MIN_UA]) 133 max_uA < da9052_current_limits[row][DA9052_MIN_UA])
134 return -EINVAL; 134 return -EINVAL;
135 135
136 for (i = 0; i < DA9052_CURRENT_RANGE; i++) { 136 for (i = DA9052_CURRENT_RANGE - 1; i >= 0; i--) {
137 if (min_uA <= da9052_current_limits[row][i]) { 137 if (da9052_current_limits[row][i] <= max_uA) {
138 reg_val = i; 138 reg_val = i;
139 break; 139 break;
140 } 140 }
diff --git a/drivers/regulator/dummy.c b/drivers/regulator/dummy.c
index 86f655c7f7a1..03a1d7c11ef2 100644
--- a/drivers/regulator/dummy.c
+++ b/drivers/regulator/dummy.c
@@ -30,7 +30,7 @@ static struct regulator_init_data dummy_initdata;
30static struct regulator_ops dummy_ops; 30static struct regulator_ops dummy_ops;
31 31
32static struct regulator_desc dummy_desc = { 32static struct regulator_desc dummy_desc = {
33 .name = "dummy", 33 .name = "regulator-dummy",
34 .id = -1, 34 .id = -1,
35 .type = REGULATOR_VOLTAGE, 35 .type = REGULATOR_VOLTAGE,
36 .owner = THIS_MODULE, 36 .owner = THIS_MODULE,
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
new file mode 100644
index 000000000000..339f4d732e97
--- /dev/null
+++ b/drivers/regulator/fan53555.c
@@ -0,0 +1,322 @@
1/*
2 * FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver.
3 *
4 * Supported Part Numbers:
5 * FAN53555UC00X/01X/03X/04X/05X
6 *
7 * Copyright (c) 2012 Marvell Technology Ltd.
8 * Yunfan Zhang <yfzhang@marvell.com>
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 */
15#include <linux/module.h>
16#include <linux/param.h>
17#include <linux/err.h>
18#include <linux/platform_device.h>
19#include <linux/regulator/driver.h>
20#include <linux/regulator/machine.h>
21#include <linux/i2c.h>
22#include <linux/slab.h>
23#include <linux/regmap.h>
24#include <linux/regulator/fan53555.h>
25
26/* Voltage setting */
27#define FAN53555_VSEL0 0x00
28#define FAN53555_VSEL1 0x01
29/* Control register */
30#define FAN53555_CONTROL 0x02
31/* IC Type */
32#define FAN53555_ID1 0x03
33/* IC mask version */
34#define FAN53555_ID2 0x04
35/* Monitor register */
36#define FAN53555_MONITOR 0x05
37
38/* VSEL bit definitions */
39#define VSEL_BUCK_EN (1 << 7)
40#define VSEL_MODE (1 << 6)
41#define VSEL_NSEL_MASK 0x3F
42/* Chip ID and Verison */
43#define DIE_ID 0x0F /* ID1 */
44#define DIE_REV 0x0F /* ID2 */
45/* Control bit definitions */
46#define CTL_OUTPUT_DISCHG (1 << 7)
47#define CTL_SLEW_MASK (0x7 << 4)
48#define CTL_SLEW_SHIFT 4
49#define CTL_RESET (1 << 2)
50
51#define FAN53555_NVOLTAGES 64 /* Numbers of voltages */
52
53/* IC Type */
54enum {
55 FAN53555_CHIP_ID_00 = 0,
56 FAN53555_CHIP_ID_01,
57 FAN53555_CHIP_ID_02,
58 FAN53555_CHIP_ID_03,
59 FAN53555_CHIP_ID_04,
60 FAN53555_CHIP_ID_05,
61};
62
63struct fan53555_device_info {
64 struct regmap *regmap;
65 struct device *dev;
66 struct regulator_desc desc;
67 struct regulator_dev *rdev;
68 struct regulator_init_data *regulator;
69 /* IC Type and Rev */
70 int chip_id;
71 int chip_rev;
72 /* Voltage setting register */
73 unsigned int vol_reg;
74 unsigned int sleep_reg;
75 /* Voltage range and step(linear) */
76 unsigned int vsel_min;
77 unsigned int vsel_step;
78 /* Voltage slew rate limiting */
79 unsigned int slew_rate;
80 /* Sleep voltage cache */
81 unsigned int sleep_vol_cache;
82};
83
84static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV)
85{
86 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
87 int ret;
88
89 if (di->sleep_vol_cache == uV)
90 return 0;
91 ret = regulator_map_voltage_linear(rdev, uV, uV);
92 if (ret < 0)
93 return -EINVAL;
94 ret = regmap_update_bits(di->regmap, di->sleep_reg,
95 VSEL_NSEL_MASK, ret);
96 if (ret < 0)
97 return -EINVAL;
98 /* Cache the sleep voltage setting.
99 * Might not be the real voltage which is rounded */
100 di->sleep_vol_cache = uV;
101
102 return 0;
103}
104
105static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode)
106{
107 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
108
109 switch (mode) {
110 case REGULATOR_MODE_FAST:
111 regmap_update_bits(di->regmap, di->vol_reg,
112 VSEL_MODE, VSEL_MODE);
113 break;
114 case REGULATOR_MODE_NORMAL:
115 regmap_update_bits(di->regmap, di->vol_reg, VSEL_MODE, 0);
116 break;
117 default:
118 return -EINVAL;
119 }
120 return 0;
121}
122
123static unsigned int fan53555_get_mode(struct regulator_dev *rdev)
124{
125 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
126 unsigned int val;
127 int ret = 0;
128
129 ret = regmap_read(di->regmap, di->vol_reg, &val);
130 if (ret < 0)
131 return ret;
132 if (val & VSEL_MODE)
133 return REGULATOR_MODE_FAST;
134 else
135 return REGULATOR_MODE_NORMAL;
136}
137
138static struct regulator_ops fan53555_regulator_ops = {
139 .set_voltage_sel = regulator_set_voltage_sel_regmap,
140 .get_voltage_sel = regulator_get_voltage_sel_regmap,
141 .map_voltage = regulator_map_voltage_linear,
142 .list_voltage = regulator_list_voltage_linear,
143 .set_suspend_voltage = fan53555_set_suspend_voltage,
144 .enable = regulator_enable_regmap,
145 .disable = regulator_disable_regmap,
146 .is_enabled = regulator_is_enabled_regmap,
147 .set_mode = fan53555_set_mode,
148 .get_mode = fan53555_get_mode,
149};
150
151/* For 00,01,03,05 options:
152 * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V.
153 * For 04 option:
154 * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V.
155 * */
156static int fan53555_device_setup(struct fan53555_device_info *di,
157 struct fan53555_platform_data *pdata)
158{
159 unsigned int reg, data, mask;
160
161 /* Setup voltage control register */
162 switch (pdata->sleep_vsel_id) {
163 case FAN53555_VSEL_ID_0:
164 di->sleep_reg = FAN53555_VSEL0;
165 di->vol_reg = FAN53555_VSEL1;
166 break;
167 case FAN53555_VSEL_ID_1:
168 di->sleep_reg = FAN53555_VSEL1;
169 di->vol_reg = FAN53555_VSEL0;
170 break;
171 default:
172 dev_err(di->dev, "Invalid VSEL ID!\n");
173 return -EINVAL;
174 }
175 /* Init voltage range and step */
176 switch (di->chip_id) {
177 case FAN53555_CHIP_ID_00:
178 case FAN53555_CHIP_ID_01:
179 case FAN53555_CHIP_ID_03:
180 case FAN53555_CHIP_ID_05:
181 di->vsel_min = 600000;
182 di->vsel_step = 10000;
183 break;
184 case FAN53555_CHIP_ID_04:
185 di->vsel_min = 603000;
186 di->vsel_step = 12826;
187 break;
188 default:
189 dev_err(di->dev,
190 "Chip ID[%d]\n not supported!\n", di->chip_id);
191 return -EINVAL;
192 }
193 /* Init slew rate */
194 if (pdata->slew_rate & 0x7)
195 di->slew_rate = pdata->slew_rate;
196 else
197 di->slew_rate = FAN53555_SLEW_RATE_64MV;
198 reg = FAN53555_CONTROL;
199 data = di->slew_rate << CTL_SLEW_SHIFT;
200 mask = CTL_SLEW_MASK;
201 return regmap_update_bits(di->regmap, reg, mask, data);
202}
203
204static int fan53555_regulator_register(struct fan53555_device_info *di,
205 struct regulator_config *config)
206{
207 struct regulator_desc *rdesc = &di->desc;
208
209 rdesc->name = "fan53555-reg";
210 rdesc->ops = &fan53555_regulator_ops;
211 rdesc->type = REGULATOR_VOLTAGE;
212 rdesc->n_voltages = FAN53555_NVOLTAGES;
213 rdesc->enable_reg = di->vol_reg;
214 rdesc->enable_mask = VSEL_BUCK_EN;
215 rdesc->min_uV = di->vsel_min;
216 rdesc->uV_step = di->vsel_step;
217 rdesc->vsel_reg = di->vol_reg;
218 rdesc->vsel_mask = VSEL_NSEL_MASK;
219 rdesc->owner = THIS_MODULE;
220
221 di->rdev = regulator_register(&di->desc, config);
222 if (IS_ERR(di->rdev))
223 return PTR_ERR(di->rdev);
224 return 0;
225
226}
227
228static struct regmap_config fan53555_regmap_config = {
229 .reg_bits = 8,
230 .val_bits = 8,
231};
232
233static int __devinit fan53555_regulator_probe(struct i2c_client *client,
234 const struct i2c_device_id *id)
235{
236 struct fan53555_device_info *di;
237 struct fan53555_platform_data *pdata;
238 struct regulator_config config = { };
239 unsigned int val;
240 int ret;
241
242 pdata = client->dev.platform_data;
243 if (!pdata || !pdata->regulator) {
244 dev_err(&client->dev, "Platform data not found!\n");
245 return -ENODEV;
246 }
247
248 di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info),
249 GFP_KERNEL);
250 if (!di) {
251 dev_err(&client->dev, "Failed to allocate device info data!\n");
252 return -ENOMEM;
253 }
254 di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
255 if (IS_ERR(di->regmap)) {
256 dev_err(&client->dev, "Failed to allocate regmap!\n");
257 return PTR_ERR(di->regmap);
258 }
259 di->dev = &client->dev;
260 di->regulator = pdata->regulator;
261 i2c_set_clientdata(client, di);
262 /* Get chip ID */
263 ret = regmap_read(di->regmap, FAN53555_ID1, &val);
264 if (ret < 0) {
265 dev_err(&client->dev, "Failed to get chip ID!\n");
266 return -ENODEV;
267 }
268 di->chip_id = val & DIE_ID;
269 /* Get chip revision */
270 ret = regmap_read(di->regmap, FAN53555_ID2, &val);
271 if (ret < 0) {
272 dev_err(&client->dev, "Failed to get chip Rev!\n");
273 return -ENODEV;
274 }
275 di->chip_rev = val & DIE_REV;
276 dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n",
277 di->chip_id, di->chip_rev);
278 /* Device init */
279 ret = fan53555_device_setup(di, pdata);
280 if (ret < 0) {
281 dev_err(&client->dev, "Failed to setup device!\n");
282 return ret;
283 }
284 /* Register regulator */
285 config.dev = di->dev;
286 config.init_data = di->regulator;
287 config.regmap = di->regmap;
288 config.driver_data = di;
289 ret = fan53555_regulator_register(di, &config);
290 if (ret < 0)
291 dev_err(&client->dev, "Failed to register regulator!\n");
292 return ret;
293
294}
295
296static int __devexit fan53555_regulator_remove(struct i2c_client *client)
297{
298 struct fan53555_device_info *di = i2c_get_clientdata(client);
299
300 regulator_unregister(di->rdev);
301 return 0;
302}
303
304static const struct i2c_device_id fan53555_id[] = {
305 {"fan53555", -1},
306 { },
307};
308
309static struct i2c_driver fan53555_regulator_driver = {
310 .driver = {
311 .name = "fan53555-regulator",
312 },
313 .probe = fan53555_regulator_probe,
314 .remove = __devexit_p(fan53555_regulator_remove),
315 .id_table = fan53555_id,
316};
317
318module_i2c_driver(fan53555_regulator_driver);
319
320MODULE_AUTHOR("Yunfan Zhang <yfzhang@marvell.com>");
321MODULE_DESCRIPTION("FAN53555 regulator driver");
322MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index 1d145a07ada9..d8ecf49a5777 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -73,13 +73,7 @@ static struct regulator_ops isl_core_ops = {
73 .map_voltage = regulator_map_voltage_linear, 73 .map_voltage = regulator_map_voltage_linear,
74}; 74};
75 75
76static int isl6271a_get_fixed_voltage(struct regulator_dev *dev)
77{
78 return dev->desc->min_uV;
79}
80
81static struct regulator_ops isl_fixed_ops = { 76static struct regulator_ops isl_fixed_ops = {
82 .get_voltage = isl6271a_get_fixed_voltage,
83 .list_voltage = regulator_list_voltage_linear, 77 .list_voltage = regulator_list_voltage_linear,
84}; 78};
85 79
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
index 212c38eaba70..708f4b6a17dc 100644
--- a/drivers/regulator/lp872x.c
+++ b/drivers/regulator/lp872x.c
@@ -86,6 +86,10 @@
86#define EXTERN_DVS_USED 0 86#define EXTERN_DVS_USED 0
87#define MAX_DELAY 6 87#define MAX_DELAY 6
88 88
89/* Default DVS Mode */
90#define LP8720_DEFAULT_DVS 0
91#define LP8725_DEFAULT_DVS BIT(2)
92
89/* dump registers in regmap-debugfs */ 93/* dump registers in regmap-debugfs */
90#define MAX_REGISTERS 0x0F 94#define MAX_REGISTERS 0x0F
91 95
@@ -269,9 +273,9 @@ static int lp872x_regulator_enable_time(struct regulator_dev *rdev)
269 return val > MAX_DELAY ? 0 : val * time_step_us; 273 return val > MAX_DELAY ? 0 : val * time_step_us;
270} 274}
271 275
272static void lp872x_set_dvs(struct lp872x *lp, int gpio) 276static void lp872x_set_dvs(struct lp872x *lp, enum lp872x_dvs_sel dvs_sel,
277 int gpio)
273{ 278{
274 enum lp872x_dvs_sel dvs_sel = lp->pdata->dvs->vsel;
275 enum lp872x_dvs_state state; 279 enum lp872x_dvs_state state;
276 280
277 state = dvs_sel == SEL_V1 ? DVS_HIGH : DVS_LOW; 281 state = dvs_sel == SEL_V1 ? DVS_HIGH : DVS_LOW;
@@ -339,10 +343,10 @@ static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev,
339 struct lp872x *lp = rdev_get_drvdata(rdev); 343 struct lp872x *lp = rdev_get_drvdata(rdev);
340 enum lp872x_regulator_id buck = rdev_get_id(rdev); 344 enum lp872x_regulator_id buck = rdev_get_id(rdev);
341 u8 addr, mask = LP872X_VOUT_M; 345 u8 addr, mask = LP872X_VOUT_M;
342 struct lp872x_dvs *dvs = lp->pdata->dvs; 346 struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL;
343 347
344 if (dvs && gpio_is_valid(dvs->gpio)) 348 if (dvs && gpio_is_valid(dvs->gpio))
345 lp872x_set_dvs(lp, dvs->gpio); 349 lp872x_set_dvs(lp, dvs->vsel, dvs->gpio);
346 350
347 addr = lp872x_select_buck_vout_addr(lp, buck); 351 addr = lp872x_select_buck_vout_addr(lp, buck);
348 if (!lp872x_is_valid_buck_addr(addr)) 352 if (!lp872x_is_valid_buck_addr(addr))
@@ -374,8 +378,8 @@ static int lp8725_buck_set_current_limit(struct regulator_dev *rdev,
374{ 378{
375 struct lp872x *lp = rdev_get_drvdata(rdev); 379 struct lp872x *lp = rdev_get_drvdata(rdev);
376 enum lp872x_regulator_id buck = rdev_get_id(rdev); 380 enum lp872x_regulator_id buck = rdev_get_id(rdev);
377 int i, max = ARRAY_SIZE(lp8725_buck_uA); 381 int i;
378 u8 addr, val; 382 u8 addr;
379 383
380 switch (buck) { 384 switch (buck) {
381 case LP8725_ID_BUCK1: 385 case LP8725_ID_BUCK1:
@@ -388,17 +392,15 @@ static int lp8725_buck_set_current_limit(struct regulator_dev *rdev,
388 return -EINVAL; 392 return -EINVAL;
389 } 393 }
390 394
391 for (i = 0 ; i < max ; i++) 395 for (i = ARRAY_SIZE(lp8725_buck_uA) - 1 ; i >= 0; i--) {
392 if (lp8725_buck_uA[i] >= min_uA && 396 if (lp8725_buck_uA[i] >= min_uA &&
393 lp8725_buck_uA[i] <= max_uA) 397 lp8725_buck_uA[i] <= max_uA)
394 break; 398 return lp872x_update_bits(lp, addr,
395 399 LP8725_BUCK_CL_M,
396 if (i == max) 400 i << LP8725_BUCK_CL_S);
397 return -EINVAL; 401 }
398
399 val = i << LP8725_BUCK_CL_S;
400 402
401 return lp872x_update_bits(lp, addr, LP8725_BUCK_CL_M, val); 403 return -EINVAL;
402} 404}
403 405
404static int lp8725_buck_get_current_limit(struct regulator_dev *rdev) 406static int lp8725_buck_get_current_limit(struct regulator_dev *rdev)
@@ -727,39 +729,16 @@ static struct regulator_desc lp8725_regulator_desc[] = {
727 }, 729 },
728}; 730};
729 731
730static int lp872x_check_dvs_validity(struct lp872x *lp)
731{
732 struct lp872x_dvs *dvs = lp->pdata->dvs;
733 u8 val = 0;
734 int ret;
735
736 ret = lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val);
737 if (ret)
738 return ret;
739
740 ret = 0;
741 if (lp->chipid == LP8720) {
742 if (val & LP8720_EXT_DVS_M)
743 ret = dvs ? 0 : -EINVAL;
744 } else {
745 if ((val & LP8725_DVS1_M) == EXTERN_DVS_USED)
746 ret = dvs ? 0 : -EINVAL;
747 }
748
749 return ret;
750}
751
752static int lp872x_init_dvs(struct lp872x *lp) 732static int lp872x_init_dvs(struct lp872x *lp)
753{ 733{
754 int ret, gpio; 734 int ret, gpio;
755 struct lp872x_dvs *dvs = lp->pdata->dvs; 735 struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL;
756 enum lp872x_dvs_state pinstate; 736 enum lp872x_dvs_state pinstate;
737 u8 mask[] = { LP8720_EXT_DVS_M, LP8725_DVS1_M | LP8725_DVS2_M };
738 u8 default_dvs_mode[] = { LP8720_DEFAULT_DVS, LP8725_DEFAULT_DVS };
757 739
758 ret = lp872x_check_dvs_validity(lp); 740 if (!dvs)
759 if (ret) { 741 goto set_default_dvs_mode;
760 dev_warn(lp->dev, "invalid dvs data: %d\n", ret);
761 return ret;
762 }
763 742
764 gpio = dvs->gpio; 743 gpio = dvs->gpio;
765 if (!gpio_is_valid(gpio)) { 744 if (!gpio_is_valid(gpio)) {
@@ -778,6 +757,10 @@ static int lp872x_init_dvs(struct lp872x *lp)
778 lp->dvs_gpio = gpio; 757 lp->dvs_gpio = gpio;
779 758
780 return 0; 759 return 0;
760
761set_default_dvs_mode:
762 return lp872x_update_bits(lp, LP872X_GENERAL_CFG, mask[lp->chipid],
763 default_dvs_mode[lp->chipid]);
781} 764}
782 765
783static int lp872x_config(struct lp872x *lp) 766static int lp872x_config(struct lp872x *lp)
@@ -785,24 +768,29 @@ static int lp872x_config(struct lp872x *lp)
785 struct lp872x_platform_data *pdata = lp->pdata; 768 struct lp872x_platform_data *pdata = lp->pdata;
786 int ret; 769 int ret;
787 770
788 if (!pdata->update_config) 771 if (!pdata || !pdata->update_config)
789 return 0; 772 goto init_dvs;
790 773
791 ret = lp872x_write_byte(lp, LP872X_GENERAL_CFG, pdata->general_config); 774 ret = lp872x_write_byte(lp, LP872X_GENERAL_CFG, pdata->general_config);
792 if (ret) 775 if (ret)
793 return ret; 776 return ret;
794 777
778init_dvs:
795 return lp872x_init_dvs(lp); 779 return lp872x_init_dvs(lp);
796} 780}
797 781
798static struct regulator_init_data 782static struct regulator_init_data
799*lp872x_find_regulator_init_data(int id, struct lp872x *lp) 783*lp872x_find_regulator_init_data(int id, struct lp872x *lp)
800{ 784{
785 struct lp872x_platform_data *pdata = lp->pdata;
801 int i; 786 int i;
802 787
788 if (!pdata)
789 return NULL;
790
803 for (i = 0; i < lp->num_regulators; i++) { 791 for (i = 0; i < lp->num_regulators; i++) {
804 if (lp->pdata->regulator_data[i].id == id) 792 if (pdata->regulator_data[i].id == id)
805 return lp->pdata->regulator_data[i].init_data; 793 return pdata->regulator_data[i].init_data;
806 } 794 }
807 795
808 return NULL; 796 return NULL;
@@ -863,18 +851,12 @@ static const struct regmap_config lp872x_regmap_config = {
863static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id) 851static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
864{ 852{
865 struct lp872x *lp; 853 struct lp872x *lp;
866 struct lp872x_platform_data *pdata = cl->dev.platform_data;
867 int ret, size, num_regulators; 854 int ret, size, num_regulators;
868 const int lp872x_num_regulators[] = { 855 const int lp872x_num_regulators[] = {
869 [LP8720] = LP8720_NUM_REGULATORS, 856 [LP8720] = LP8720_NUM_REGULATORS,
870 [LP8725] = LP8725_NUM_REGULATORS, 857 [LP8725] = LP8725_NUM_REGULATORS,
871 }; 858 };
872 859
873 if (!pdata) {
874 dev_err(&cl->dev, "no platform data\n");
875 return -EINVAL;
876 }
877
878 lp = devm_kzalloc(&cl->dev, sizeof(struct lp872x), GFP_KERNEL); 860 lp = devm_kzalloc(&cl->dev, sizeof(struct lp872x), GFP_KERNEL);
879 if (!lp) 861 if (!lp)
880 goto err_mem; 862 goto err_mem;
@@ -894,7 +876,7 @@ static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
894 } 876 }
895 877
896 lp->dev = &cl->dev; 878 lp->dev = &cl->dev;
897 lp->pdata = pdata; 879 lp->pdata = cl->dev.platform_data;
898 lp->chipid = id->driver_data; 880 lp->chipid = id->driver_data;
899 lp->num_regulators = num_regulators; 881 lp->num_regulators = num_regulators;
900 i2c_set_clientdata(cl, lp); 882 i2c_set_clientdata(cl, lp);
diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c
index 6356e821400f..ba3e0aa402de 100644
--- a/drivers/regulator/lp8788-buck.c
+++ b/drivers/regulator/lp8788-buck.c
@@ -69,6 +69,9 @@
69#define PIN_HIGH 1 69#define PIN_HIGH 1
70#define ENABLE_TIME_USEC 32 70#define ENABLE_TIME_USEC 32
71 71
72#define BUCK_FPWM_MASK(x) (1 << (x))
73#define BUCK_FPWM_SHIFT(x) (x)
74
72enum lp8788_dvs_state { 75enum lp8788_dvs_state {
73 DVS_LOW = GPIOF_OUT_INIT_LOW, 76 DVS_LOW = GPIOF_OUT_INIT_LOW,
74 DVS_HIGH = GPIOF_OUT_INIT_HIGH, 77 DVS_HIGH = GPIOF_OUT_INIT_HIGH,
@@ -86,15 +89,9 @@ enum lp8788_buck_id {
86 BUCK4, 89 BUCK4,
87}; 90};
88 91
89struct lp8788_pwm_map {
90 u8 mask;
91 u8 shift;
92};
93
94struct lp8788_buck { 92struct lp8788_buck {
95 struct lp8788 *lp; 93 struct lp8788 *lp;
96 struct regulator_dev *regulator; 94 struct regulator_dev *regulator;
97 struct lp8788_pwm_map *pmap;
98 void *dvs; 95 void *dvs;
99}; 96};
100 97
@@ -106,29 +103,6 @@ static const int lp8788_buck_vtbl[] = {
106 1950000, 2000000, 103 1950000, 2000000,
107}; 104};
108 105
109/* buck pwm mode selection : used for set/get_mode in regulator ops
110 * @forced pwm : fast mode
111 * @auto pwm : normal mode
112 */
113static struct lp8788_pwm_map buck_pmap[] = {
114 [BUCK1] = {
115 .mask = LP8788_FPWM_BUCK1_M,
116 .shift = LP8788_FPWM_BUCK1_S,
117 },
118 [BUCK2] = {
119 .mask = LP8788_FPWM_BUCK2_M,
120 .shift = LP8788_FPWM_BUCK2_S,
121 },
122 [BUCK3] = {
123 .mask = LP8788_FPWM_BUCK3_M,
124 .shift = LP8788_FPWM_BUCK3_S,
125 },
126 [BUCK4] = {
127 .mask = LP8788_FPWM_BUCK4_M,
128 .shift = LP8788_FPWM_BUCK4_S,
129 },
130};
131
132static const u8 buck1_vout_addr[] = { 106static const u8 buck1_vout_addr[] = {
133 LP8788_BUCK1_VOUT0, LP8788_BUCK1_VOUT1, 107 LP8788_BUCK1_VOUT0, LP8788_BUCK1_VOUT1,
134 LP8788_BUCK1_VOUT2, LP8788_BUCK1_VOUT3, 108 LP8788_BUCK1_VOUT2, LP8788_BUCK1_VOUT3,
@@ -347,41 +321,37 @@ static int lp8788_buck_enable_time(struct regulator_dev *rdev)
347static int lp8788_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) 321static int lp8788_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
348{ 322{
349 struct lp8788_buck *buck = rdev_get_drvdata(rdev); 323 struct lp8788_buck *buck = rdev_get_drvdata(rdev);
350 struct lp8788_pwm_map *pmap = buck->pmap; 324 enum lp8788_buck_id id = rdev_get_id(rdev);
351 u8 val; 325 u8 mask, val;
352
353 if (!pmap)
354 return -EINVAL;
355 326
327 mask = BUCK_FPWM_MASK(id);
356 switch (mode) { 328 switch (mode) {
357 case REGULATOR_MODE_FAST: 329 case REGULATOR_MODE_FAST:
358 val = LP8788_FORCE_PWM << pmap->shift; 330 val = LP8788_FORCE_PWM << BUCK_FPWM_SHIFT(id);
359 break; 331 break;
360 case REGULATOR_MODE_NORMAL: 332 case REGULATOR_MODE_NORMAL:
361 val = LP8788_AUTO_PWM << pmap->shift; 333 val = LP8788_AUTO_PWM << BUCK_FPWM_SHIFT(id);
362 break; 334 break;
363 default: 335 default:
364 return -EINVAL; 336 return -EINVAL;
365 } 337 }
366 338
367 return lp8788_update_bits(buck->lp, LP8788_BUCK_PWM, pmap->mask, val); 339 return lp8788_update_bits(buck->lp, LP8788_BUCK_PWM, mask, val);
368} 340}
369 341
370static unsigned int lp8788_buck_get_mode(struct regulator_dev *rdev) 342static unsigned int lp8788_buck_get_mode(struct regulator_dev *rdev)
371{ 343{
372 struct lp8788_buck *buck = rdev_get_drvdata(rdev); 344 struct lp8788_buck *buck = rdev_get_drvdata(rdev);
373 struct lp8788_pwm_map *pmap = buck->pmap; 345 enum lp8788_buck_id id = rdev_get_id(rdev);
374 u8 val; 346 u8 val;
375 int ret; 347 int ret;
376 348
377 if (!pmap)
378 return -EINVAL;
379
380 ret = lp8788_read_byte(buck->lp, LP8788_BUCK_PWM, &val); 349 ret = lp8788_read_byte(buck->lp, LP8788_BUCK_PWM, &val);
381 if (ret) 350 if (ret)
382 return ret; 351 return ret;
383 352
384 return val & pmap->mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; 353 return val & BUCK_FPWM_MASK(id) ?
354 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
385} 355}
386 356
387static struct regulator_ops lp8788_buck12_ops = { 357static struct regulator_ops lp8788_buck12_ops = {
@@ -459,27 +429,6 @@ static struct regulator_desc lp8788_buck_desc[] = {
459 }, 429 },
460}; 430};
461 431
462static int lp8788_set_default_dvs_ctrl_mode(struct lp8788 *lp,
463 enum lp8788_buck_id id)
464{
465 u8 mask, val;
466
467 switch (id) {
468 case BUCK1:
469 mask = LP8788_BUCK1_DVS_SEL_M;
470 val = LP8788_BUCK1_DVS_I2C;
471 break;
472 case BUCK2:
473 mask = LP8788_BUCK2_DVS_SEL_M;
474 val = LP8788_BUCK2_DVS_I2C;
475 break;
476 default:
477 return 0;
478 }
479
480 return lp8788_update_bits(lp, LP8788_BUCK_DVS_SEL, mask, val);
481}
482
483static int _gpio_request(struct lp8788_buck *buck, int gpio, char *name) 432static int _gpio_request(struct lp8788_buck *buck, int gpio, char *name)
484{ 433{
485 struct device *dev = buck->lp->dev; 434 struct device *dev = buck->lp->dev;
@@ -530,6 +479,7 @@ static int lp8788_init_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id)
530 struct lp8788_platform_data *pdata = buck->lp->pdata; 479 struct lp8788_platform_data *pdata = buck->lp->pdata;
531 u8 mask[] = { LP8788_BUCK1_DVS_SEL_M, LP8788_BUCK2_DVS_SEL_M }; 480 u8 mask[] = { LP8788_BUCK1_DVS_SEL_M, LP8788_BUCK2_DVS_SEL_M };
532 u8 val[] = { LP8788_BUCK1_DVS_PIN, LP8788_BUCK2_DVS_PIN }; 481 u8 val[] = { LP8788_BUCK1_DVS_PIN, LP8788_BUCK2_DVS_PIN };
482 u8 default_dvs_mode[] = { LP8788_BUCK1_DVS_I2C, LP8788_BUCK2_DVS_I2C };
533 483
534 /* no dvs for buck3, 4 */ 484 /* no dvs for buck3, 4 */
535 if (id == BUCK3 || id == BUCK4) 485 if (id == BUCK3 || id == BUCK4)
@@ -550,7 +500,8 @@ static int lp8788_init_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id)
550 val[id]); 500 val[id]);
551 501
552set_default_dvs_mode: 502set_default_dvs_mode:
553 return lp8788_set_default_dvs_ctrl_mode(buck->lp, id); 503 return lp8788_update_bits(buck->lp, LP8788_BUCK_DVS_SEL, mask[id],
504 default_dvs_mode[id]);
554} 505}
555 506
556static __devinit int lp8788_buck_probe(struct platform_device *pdev) 507static __devinit int lp8788_buck_probe(struct platform_device *pdev)
@@ -567,7 +518,6 @@ static __devinit int lp8788_buck_probe(struct platform_device *pdev)
567 return -ENOMEM; 518 return -ENOMEM;
568 519
569 buck->lp = lp; 520 buck->lp = lp;
570 buck->pmap = &buck_pmap[id];
571 521
572 ret = lp8788_init_dvs(buck, id); 522 ret = lp8788_init_dvs(buck, id);
573 if (ret) 523 if (ret)
diff --git a/drivers/regulator/lp8788-ldo.c b/drivers/regulator/lp8788-ldo.c
index d2122e41a96d..6796eeb47dc6 100644
--- a/drivers/regulator/lp8788-ldo.c
+++ b/drivers/regulator/lp8788-ldo.c
@@ -496,6 +496,7 @@ static struct regulator_desc lp8788_dldo_desc[] = {
496 .name = "dldo12", 496 .name = "dldo12",
497 .id = DLDO12, 497 .id = DLDO12,
498 .ops = &lp8788_ldo_voltage_fixed_ops, 498 .ops = &lp8788_ldo_voltage_fixed_ops,
499 .n_voltages = 1,
499 .type = REGULATOR_VOLTAGE, 500 .type = REGULATOR_VOLTAGE,
500 .owner = THIS_MODULE, 501 .owner = THIS_MODULE,
501 .enable_reg = LP8788_EN_LDO_B, 502 .enable_reg = LP8788_EN_LDO_B,
@@ -521,6 +522,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
521 .name = "aldo2", 522 .name = "aldo2",
522 .id = ALDO2, 523 .id = ALDO2,
523 .ops = &lp8788_ldo_voltage_fixed_ops, 524 .ops = &lp8788_ldo_voltage_fixed_ops,
525 .n_voltages = 1,
524 .type = REGULATOR_VOLTAGE, 526 .type = REGULATOR_VOLTAGE,
525 .owner = THIS_MODULE, 527 .owner = THIS_MODULE,
526 .enable_reg = LP8788_EN_LDO_B, 528 .enable_reg = LP8788_EN_LDO_B,
@@ -530,6 +532,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
530 .name = "aldo3", 532 .name = "aldo3",
531 .id = ALDO3, 533 .id = ALDO3,
532 .ops = &lp8788_ldo_voltage_fixed_ops, 534 .ops = &lp8788_ldo_voltage_fixed_ops,
535 .n_voltages = 1,
533 .type = REGULATOR_VOLTAGE, 536 .type = REGULATOR_VOLTAGE,
534 .owner = THIS_MODULE, 537 .owner = THIS_MODULE,
535 .enable_reg = LP8788_EN_LDO_B, 538 .enable_reg = LP8788_EN_LDO_B,
@@ -539,6 +542,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
539 .name = "aldo4", 542 .name = "aldo4",
540 .id = ALDO4, 543 .id = ALDO4,
541 .ops = &lp8788_ldo_voltage_fixed_ops, 544 .ops = &lp8788_ldo_voltage_fixed_ops,
545 .n_voltages = 1,
542 .type = REGULATOR_VOLTAGE, 546 .type = REGULATOR_VOLTAGE,
543 .owner = THIS_MODULE, 547 .owner = THIS_MODULE,
544 .enable_reg = LP8788_EN_LDO_B, 548 .enable_reg = LP8788_EN_LDO_B,
@@ -548,6 +552,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
548 .name = "aldo5", 552 .name = "aldo5",
549 .id = ALDO5, 553 .id = ALDO5,
550 .ops = &lp8788_ldo_voltage_fixed_ops, 554 .ops = &lp8788_ldo_voltage_fixed_ops,
555 .n_voltages = 1,
551 .type = REGULATOR_VOLTAGE, 556 .type = REGULATOR_VOLTAGE,
552 .owner = THIS_MODULE, 557 .owner = THIS_MODULE,
553 .enable_reg = LP8788_EN_LDO_C, 558 .enable_reg = LP8788_EN_LDO_C,
@@ -583,6 +588,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
583 .name = "aldo8", 588 .name = "aldo8",
584 .id = ALDO8, 589 .id = ALDO8,
585 .ops = &lp8788_ldo_voltage_fixed_ops, 590 .ops = &lp8788_ldo_voltage_fixed_ops,
591 .n_voltages = 1,
586 .type = REGULATOR_VOLTAGE, 592 .type = REGULATOR_VOLTAGE,
587 .owner = THIS_MODULE, 593 .owner = THIS_MODULE,
588 .enable_reg = LP8788_EN_LDO_C, 594 .enable_reg = LP8788_EN_LDO_C,
@@ -592,6 +598,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
592 .name = "aldo9", 598 .name = "aldo9",
593 .id = ALDO9, 599 .id = ALDO9,
594 .ops = &lp8788_ldo_voltage_fixed_ops, 600 .ops = &lp8788_ldo_voltage_fixed_ops,
601 .n_voltages = 1,
595 .type = REGULATOR_VOLTAGE, 602 .type = REGULATOR_VOLTAGE,
596 .owner = THIS_MODULE, 603 .owner = THIS_MODULE,
597 .enable_reg = LP8788_EN_LDO_C, 604 .enable_reg = LP8788_EN_LDO_C,
@@ -601,6 +608,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
601 .name = "aldo10", 608 .name = "aldo10",
602 .id = ALDO10, 609 .id = ALDO10,
603 .ops = &lp8788_ldo_voltage_fixed_ops, 610 .ops = &lp8788_ldo_voltage_fixed_ops,
611 .n_voltages = 1,
604 .type = REGULATOR_VOLTAGE, 612 .type = REGULATOR_VOLTAGE,
605 .owner = THIS_MODULE, 613 .owner = THIS_MODULE,
606 .enable_reg = LP8788_EN_LDO_C, 614 .enable_reg = LP8788_EN_LDO_C,
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index c564af6f05a3..2a67d08658ad 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -66,7 +66,7 @@ enum max77686_ramp_rate {
66}; 66};
67 67
68struct max77686_data { 68struct max77686_data {
69 struct regulator_dev **rdev; 69 struct regulator_dev *rdev[MAX77686_REGULATORS];
70}; 70};
71 71
72static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) 72static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
@@ -265,6 +265,7 @@ static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
265 rmatch.of_node = NULL; 265 rmatch.of_node = NULL;
266 of_regulator_match(iodev->dev, regulators_np, &rmatch, 1); 266 of_regulator_match(iodev->dev, regulators_np, &rmatch, 1);
267 rdata[i].initdata = rmatch.init_data; 267 rdata[i].initdata = rmatch.init_data;
268 rdata[i].of_node = rmatch.of_node;
268 } 269 }
269 270
270 pdata->regulators = rdata; 271 pdata->regulators = rdata;
@@ -283,10 +284,8 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
283{ 284{
284 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 285 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
285 struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev); 286 struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev);
286 struct regulator_dev **rdev;
287 struct max77686_data *max77686; 287 struct max77686_data *max77686;
288 int i, size; 288 int i, ret = 0;
289 int ret = 0;
290 struct regulator_config config = { }; 289 struct regulator_config config = { };
291 290
292 dev_dbg(&pdev->dev, "%s\n", __func__); 291 dev_dbg(&pdev->dev, "%s\n", __func__);
@@ -313,45 +312,38 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
313 if (!max77686) 312 if (!max77686)
314 return -ENOMEM; 313 return -ENOMEM;
315 314
316 size = sizeof(struct regulator_dev *) * MAX77686_REGULATORS;
317 max77686->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
318 if (!max77686->rdev)
319 return -ENOMEM;
320
321 rdev = max77686->rdev;
322 config.dev = &pdev->dev; 315 config.dev = &pdev->dev;
323 config.regmap = iodev->regmap; 316 config.regmap = iodev->regmap;
324 platform_set_drvdata(pdev, max77686); 317 platform_set_drvdata(pdev, max77686);
325 318
326 for (i = 0; i < MAX77686_REGULATORS; i++) { 319 for (i = 0; i < MAX77686_REGULATORS; i++) {
327 config.init_data = pdata->regulators[i].initdata; 320 config.init_data = pdata->regulators[i].initdata;
321 config.of_node = pdata->regulators[i].of_node;
328 322
329 rdev[i] = regulator_register(&regulators[i], &config); 323 max77686->rdev[i] = regulator_register(&regulators[i], &config);
330 if (IS_ERR(rdev[i])) { 324 if (IS_ERR(max77686->rdev[i])) {
331 ret = PTR_ERR(rdev[i]); 325 ret = PTR_ERR(max77686->rdev[i]);
332 dev_err(&pdev->dev, 326 dev_err(&pdev->dev,
333 "regulator init failed for %d\n", i); 327 "regulator init failed for %d\n", i);
334 rdev[i] = NULL; 328 max77686->rdev[i] = NULL;
335 goto err; 329 goto err;
336 } 330 }
337 } 331 }
338 332
339 return 0; 333 return 0;
340err: 334err:
341 while (--i >= 0) 335 while (--i >= 0)
342 regulator_unregister(rdev[i]); 336 regulator_unregister(max77686->rdev[i]);
343 return ret; 337 return ret;
344} 338}
345 339
346static int __devexit max77686_pmic_remove(struct platform_device *pdev) 340static int __devexit max77686_pmic_remove(struct platform_device *pdev)
347{ 341{
348 struct max77686_data *max77686 = platform_get_drvdata(pdev); 342 struct max77686_data *max77686 = platform_get_drvdata(pdev);
349 struct regulator_dev **rdev = max77686->rdev;
350 int i; 343 int i;
351 344
352 for (i = 0; i < MAX77686_REGULATORS; i++) 345 for (i = 0; i < MAX77686_REGULATORS; i++)
353 if (rdev[i]) 346 regulator_unregister(max77686->rdev[i]);
354 regulator_unregister(rdev[i]);
355 347
356 return 0; 348 return 0;
357} 349}
diff --git a/drivers/regulator/max8907-regulator.c b/drivers/regulator/max8907-regulator.c
new file mode 100644
index 000000000000..af7607515ab9
--- /dev/null
+++ b/drivers/regulator/max8907-regulator.c
@@ -0,0 +1,408 @@
1/*
2 * max8907-regulator.c -- support regulators in max8907
3 *
4 * Copyright (C) 2010 Gyungoh Yoo <jack.yoo@maxim-ic.com>
5 * Copyright (C) 2010-2012, NVIDIA CORPORATION. All rights reserved.
6 *
7 * Portions based on drivers/regulator/tps65910-regulator.c,
8 * Copyright 2010 Texas Instruments Inc.
9 * Author: Graeme Gregory <gg@slimlogic.co.uk>
10 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#include <linux/err.h>
18#include <linux/init.h>
19#include <linux/mfd/core.h>
20#include <linux/mfd/max8907.h>
21#include <linux/module.h>
22#include <linux/of.h>
23#include <linux/platform_device.h>
24#include <linux/regulator/driver.h>
25#include <linux/regulator/machine.h>
26#include <linux/regulator/of_regulator.h>
27#include <linux/regmap.h>
28#include <linux/slab.h>
29
30#define MAX8907_II2RR_VERSION_MASK 0xF0
31#define MAX8907_II2RR_VERSION_REV_A 0x00
32#define MAX8907_II2RR_VERSION_REV_B 0x10
33#define MAX8907_II2RR_VERSION_REV_C 0x30
34
35struct max8907_regulator {
36 struct regulator_desc desc[MAX8907_NUM_REGULATORS];
37 struct regulator_dev *rdev[MAX8907_NUM_REGULATORS];
38};
39
40#define REG_MBATT() \
41 [MAX8907_MBATT] = { \
42 .name = "MBATT", \
43 .supply_name = "mbatt", \
44 .id = MAX8907_MBATT, \
45 .ops = &max8907_mbatt_ops, \
46 .type = REGULATOR_VOLTAGE, \
47 .owner = THIS_MODULE, \
48 }
49
50#define REG_LDO(ids, supply, base, min, max, step) \
51 [MAX8907_##ids] = { \
52 .name = #ids, \
53 .supply_name = supply, \
54 .id = MAX8907_##ids, \
55 .n_voltages = ((max) - (min)) / (step) + 1, \
56 .ops = &max8907_ldo_ops, \
57 .type = REGULATOR_VOLTAGE, \
58 .owner = THIS_MODULE, \
59 .min_uV = (min), \
60 .uV_step = (step), \
61 .vsel_reg = (base) + MAX8907_VOUT, \
62 .vsel_mask = 0x3f, \
63 .enable_reg = (base) + MAX8907_CTL, \
64 .enable_mask = MAX8907_MASK_LDO_EN, \
65 }
66
67#define REG_FIXED(ids, supply, voltage) \
68 [MAX8907_##ids] = { \
69 .name = #ids, \
70 .supply_name = supply, \
71 .id = MAX8907_##ids, \
72 .n_voltages = 1, \
73 .ops = &max8907_fixed_ops, \
74 .type = REGULATOR_VOLTAGE, \
75 .owner = THIS_MODULE, \
76 .min_uV = (voltage), \
77 }
78
79#define REG_OUT5V(ids, supply, base, voltage) \
80 [MAX8907_##ids] = { \
81 .name = #ids, \
82 .supply_name = supply, \
83 .id = MAX8907_##ids, \
84 .n_voltages = 1, \
85 .ops = &max8907_out5v_ops, \
86 .type = REGULATOR_VOLTAGE, \
87 .owner = THIS_MODULE, \
88 .min_uV = (voltage), \
89 .enable_reg = (base), \
90 .enable_mask = MAX8907_MASK_OUT5V_EN, \
91 }
92
93#define REG_BBAT(ids, supply, base, min, max, step) \
94 [MAX8907_##ids] = { \
95 .name = #ids, \
96 .supply_name = supply, \
97 .id = MAX8907_##ids, \
98 .n_voltages = ((max) - (min)) / (step) + 1, \
99 .ops = &max8907_bbat_ops, \
100 .type = REGULATOR_VOLTAGE, \
101 .owner = THIS_MODULE, \
102 .min_uV = (min), \
103 .uV_step = (step), \
104 .vsel_reg = (base), \
105 .vsel_mask = MAX8907_MASK_VBBATTCV, \
106 }
107
108#define LDO_750_50(id, supply, base) REG_LDO(id, supply, (base), \
109 750000, 3900000, 50000)
110#define LDO_650_25(id, supply, base) REG_LDO(id, supply, (base), \
111 650000, 2225000, 25000)
112
113static struct regulator_ops max8907_mbatt_ops = {
114};
115
116static struct regulator_ops max8907_ldo_ops = {
117 .list_voltage = regulator_list_voltage_linear,
118 .set_voltage_sel = regulator_set_voltage_sel_regmap,
119 .get_voltage_sel = regulator_get_voltage_sel_regmap,
120 .enable = regulator_enable_regmap,
121 .disable = regulator_disable_regmap,
122 .is_enabled = regulator_is_enabled_regmap,
123};
124
125static struct regulator_ops max8907_ldo_hwctl_ops = {
126 .list_voltage = regulator_list_voltage_linear,
127 .set_voltage_sel = regulator_set_voltage_sel_regmap,
128 .get_voltage_sel = regulator_get_voltage_sel_regmap,
129};
130
131static struct regulator_ops max8907_fixed_ops = {
132 .list_voltage = regulator_list_voltage_linear,
133};
134
135static struct regulator_ops max8907_out5v_ops = {
136 .list_voltage = regulator_list_voltage_linear,
137 .enable = regulator_enable_regmap,
138 .disable = regulator_disable_regmap,
139 .is_enabled = regulator_is_enabled_regmap,
140};
141
142static struct regulator_ops max8907_out5v_hwctl_ops = {
143 .list_voltage = regulator_list_voltage_linear,
144};
145
146static struct regulator_ops max8907_bbat_ops = {
147 .list_voltage = regulator_list_voltage_linear,
148 .set_voltage_sel = regulator_set_voltage_sel_regmap,
149 .get_voltage_sel = regulator_get_voltage_sel_regmap,
150};
151
152static struct regulator_desc max8907_regulators[] = {
153 REG_MBATT(),
154 REG_LDO(SD1, "in-v1", MAX8907_REG_SDCTL1, 650000, 2225000, 25000),
155 REG_LDO(SD2, "in-v2", MAX8907_REG_SDCTL2, 637500, 1425000, 12500),
156 REG_LDO(SD3, "in-v3", MAX8907_REG_SDCTL3, 750000, 3900000, 50000),
157 LDO_750_50(LDO1, "in1", MAX8907_REG_LDOCTL1),
158 LDO_650_25(LDO2, "in2", MAX8907_REG_LDOCTL2),
159 LDO_650_25(LDO3, "in3", MAX8907_REG_LDOCTL3),
160 LDO_750_50(LDO4, "in4", MAX8907_REG_LDOCTL4),
161 LDO_750_50(LDO5, "in5", MAX8907_REG_LDOCTL5),
162 LDO_750_50(LDO6, "in6", MAX8907_REG_LDOCTL6),
163 LDO_750_50(LDO7, "in7", MAX8907_REG_LDOCTL7),
164 LDO_750_50(LDO8, "in8", MAX8907_REG_LDOCTL8),
165 LDO_750_50(LDO9, "in9", MAX8907_REG_LDOCTL9),
166 LDO_750_50(LDO10, "in10", MAX8907_REG_LDOCTL10),
167 LDO_750_50(LDO11, "in11", MAX8907_REG_LDOCTL11),
168 LDO_750_50(LDO12, "in12", MAX8907_REG_LDOCTL12),
169 LDO_750_50(LDO13, "in13", MAX8907_REG_LDOCTL13),
170 LDO_750_50(LDO14, "in14", MAX8907_REG_LDOCTL14),
171 LDO_750_50(LDO15, "in15", MAX8907_REG_LDOCTL15),
172 LDO_750_50(LDO16, "in16", MAX8907_REG_LDOCTL16),
173 LDO_650_25(LDO17, "in17", MAX8907_REG_LDOCTL17),
174 LDO_650_25(LDO18, "in18", MAX8907_REG_LDOCTL18),
175 LDO_750_50(LDO19, "in19", MAX8907_REG_LDOCTL19),
176 LDO_750_50(LDO20, "in20", MAX8907_REG_LDOCTL20),
177 REG_OUT5V(OUT5V, "mbatt", MAX8907_REG_OUT5VEN, 5000000),
178 REG_OUT5V(OUT33V, "mbatt", MAX8907_REG_OUT33VEN, 3300000),
179 REG_BBAT(BBAT, "MBATT", MAX8907_REG_BBAT_CNFG,
180 2400000, 3000000, 200000),
181 REG_FIXED(SDBY, "MBATT", 1200000),
182 REG_FIXED(VRTC, "MBATT", 3300000),
183};
184
185#ifdef CONFIG_OF
186
187#define MATCH(_name, _id) \
188 [MAX8907_##_id] = { \
189 .name = #_name, \
190 .driver_data = (void *)&max8907_regulators[MAX8907_##_id], \
191 }
192
193static struct of_regulator_match max8907_matches[] = {
194 MATCH(mbatt, MBATT),
195 MATCH(sd1, SD1),
196 MATCH(sd2, SD2),
197 MATCH(sd3, SD3),
198 MATCH(ldo1, LDO1),
199 MATCH(ldo2, LDO2),
200 MATCH(ldo3, LDO3),
201 MATCH(ldo4, LDO4),
202 MATCH(ldo5, LDO5),
203 MATCH(ldo6, LDO6),
204 MATCH(ldo7, LDO7),
205 MATCH(ldo8, LDO8),
206 MATCH(ldo9, LDO9),
207 MATCH(ldo10, LDO10),
208 MATCH(ldo11, LDO11),
209 MATCH(ldo12, LDO12),
210 MATCH(ldo13, LDO13),
211 MATCH(ldo14, LDO14),
212 MATCH(ldo15, LDO15),
213 MATCH(ldo16, LDO16),
214 MATCH(ldo17, LDO17),
215 MATCH(ldo18, LDO18),
216 MATCH(ldo19, LDO19),
217 MATCH(ldo20, LDO20),
218 MATCH(out5v, OUT5V),
219 MATCH(out33v, OUT33V),
220 MATCH(bbat, BBAT),
221 MATCH(sdby, SDBY),
222 MATCH(vrtc, VRTC),
223};
224
225static int max8907_regulator_parse_dt(struct platform_device *pdev)
226{
227 struct device_node *np = pdev->dev.parent->of_node;
228 struct device_node *regulators;
229 int ret;
230
231 if (!pdev->dev.parent->of_node)
232 return 0;
233
234 regulators = of_find_node_by_name(np, "regulators");
235 if (!regulators) {
236 dev_err(&pdev->dev, "regulators node not found\n");
237 return -EINVAL;
238 }
239
240 ret = of_regulator_match(pdev->dev.parent, regulators,
241 max8907_matches,
242 ARRAY_SIZE(max8907_matches));
243 if (ret < 0) {
244 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
245 ret);
246 return ret;
247 }
248
249 return 0;
250}
251
252static inline struct regulator_init_data *match_init_data(int index)
253{
254 return max8907_matches[index].init_data;
255}
256
257static inline struct device_node *match_of_node(int index)
258{
259 return max8907_matches[index].of_node;
260}
261#else
262static int max8907_regulator_parse_dt(struct platform_device *pdev)
263{
264 return 0;
265}
266
267static inline struct regulator_init_data *match_init_data(int index)
268{
269 return NULL;
270}
271
272static inline struct device_node *match_of_node(int index)
273{
274 return NULL;
275}
276#endif
277
278static __devinit int max8907_regulator_probe(struct platform_device *pdev)
279{
280 struct max8907 *max8907 = dev_get_drvdata(pdev->dev.parent);
281 struct max8907_platform_data *pdata = dev_get_platdata(max8907->dev);
282 int ret;
283 struct max8907_regulator *pmic;
284 unsigned int val;
285 int i;
286 struct regulator_config config = {};
287 struct regulator_init_data *idata;
288 const char *mbatt_rail_name = NULL;
289
290 ret = max8907_regulator_parse_dt(pdev);
291 if (ret)
292 return ret;
293
294 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
295 if (!pmic) {
296 dev_err(&pdev->dev, "Failed to alloc pmic\n");
297 return -ENOMEM;
298 }
299 platform_set_drvdata(pdev, pmic);
300
301 memcpy(pmic->desc, max8907_regulators, sizeof(pmic->desc));
302
303 /* Backwards compatibility with MAX8907B; SD1 uses different voltages */
304 regmap_read(max8907->regmap_gen, MAX8907_REG_II2RR, &val);
305 if ((val & MAX8907_II2RR_VERSION_MASK) ==
306 MAX8907_II2RR_VERSION_REV_B) {
307 pmic->desc[MAX8907_SD1].min_uV = 637500;
308 pmic->desc[MAX8907_SD1].uV_step = 12500;
309 pmic->desc[MAX8907_SD1].n_voltages =
310 (1425000 - 637500) / 12500 + 1;
311 }
312
313 for (i = 0; i < MAX8907_NUM_REGULATORS; i++) {
314 config.dev = pdev->dev.parent;
315 if (pdata)
316 idata = pdata->init_data[i];
317 else
318 idata = match_init_data(i);
319 config.init_data = idata;
320 config.driver_data = pmic;
321 config.regmap = max8907->regmap_gen;
322 config.of_node = match_of_node(i);
323
324 switch (pmic->desc[i].id) {
325 case MAX8907_MBATT:
326 if (idata && idata->constraints.name)
327 mbatt_rail_name = idata->constraints.name;
328 else
329 mbatt_rail_name = pmic->desc[i].name;
330 break;
331 case MAX8907_BBAT:
332 case MAX8907_SDBY:
333 case MAX8907_VRTC:
334 idata->supply_regulator = mbatt_rail_name;
335 break;
336 }
337
338 if (pmic->desc[i].ops == &max8907_ldo_ops) {
339 regmap_read(config.regmap, pmic->desc[i].enable_reg,
340 &val);
341 if ((val & MAX8907_MASK_LDO_SEQ) !=
342 MAX8907_MASK_LDO_SEQ)
343 pmic->desc[i].ops = &max8907_ldo_hwctl_ops;
344 } else if (pmic->desc[i].ops == &max8907_out5v_ops) {
345 regmap_read(config.regmap, pmic->desc[i].enable_reg,
346 &val);
347 if ((val & (MAX8907_MASK_OUT5V_VINEN |
348 MAX8907_MASK_OUT5V_ENSRC)) !=
349 MAX8907_MASK_OUT5V_ENSRC)
350 pmic->desc[i].ops = &max8907_out5v_hwctl_ops;
351 }
352
353 pmic->rdev[i] = regulator_register(&pmic->desc[i], &config);
354 if (IS_ERR(pmic->rdev[i])) {
355 dev_err(&pdev->dev,
356 "failed to register %s regulator\n",
357 pmic->desc[i].name);
358 ret = PTR_ERR(pmic->rdev[i]);
359 goto err_unregister_regulator;
360 }
361 }
362
363 return 0;
364
365err_unregister_regulator:
366 while (--i >= 0)
367 regulator_unregister(pmic->rdev[i]);
368 return ret;
369}
370
371static __devexit int max8907_regulator_remove(struct platform_device *pdev)
372{
373 struct max8907_regulator *pmic = platform_get_drvdata(pdev);
374 int i;
375
376 for (i = 0; i < MAX8907_NUM_REGULATORS; i++)
377 regulator_unregister(pmic->rdev[i]);
378
379 return 0;
380}
381
382static struct platform_driver max8907_regulator_driver = {
383 .driver = {
384 .name = "max8907-regulator",
385 .owner = THIS_MODULE,
386 },
387 .probe = max8907_regulator_probe,
388 .remove = __devexit_p(max8907_regulator_remove),
389};
390
391static int __init max8907_regulator_init(void)
392{
393 return platform_driver_register(&max8907_regulator_driver);
394}
395
396subsys_initcall(max8907_regulator_init);
397
398static void __exit max8907_reg_exit(void)
399{
400 platform_driver_unregister(&max8907_regulator_driver);
401}
402
403module_exit(max8907_reg_exit);
404
405MODULE_DESCRIPTION("MAX8907 regulator driver");
406MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@maxim-ic.com>");
407MODULE_LICENSE("GPL v2");
408MODULE_ALIAS("platform:max8907-regulator");
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index 4932e3449fe1..0801a6d0c122 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -21,6 +21,30 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include "mc13xxx.h" 22#include "mc13xxx.h"
23 23
24#define MC13783_REG_SWITCHERS0 24
25/* Enable does not exist for SW1A */
26#define MC13783_REG_SWITCHERS0_SW1AEN 0
27#define MC13783_REG_SWITCHERS0_SW1AVSEL 0
28#define MC13783_REG_SWITCHERS0_SW1AVSEL_M (63 << 0)
29
30#define MC13783_REG_SWITCHERS1 25
31/* Enable does not exist for SW1B */
32#define MC13783_REG_SWITCHERS1_SW1BEN 0
33#define MC13783_REG_SWITCHERS1_SW1BVSEL 0
34#define MC13783_REG_SWITCHERS1_SW1BVSEL_M (63 << 0)
35
36#define MC13783_REG_SWITCHERS2 26
37/* Enable does not exist for SW2A */
38#define MC13783_REG_SWITCHERS2_SW2AEN 0
39#define MC13783_REG_SWITCHERS2_SW2AVSEL 0
40#define MC13783_REG_SWITCHERS2_SW2AVSEL_M (63 << 0)
41
42#define MC13783_REG_SWITCHERS3 27
43/* Enable does not exist for SW2B */
44#define MC13783_REG_SWITCHERS3_SW2BEN 0
45#define MC13783_REG_SWITCHERS3_SW2BVSEL 0
46#define MC13783_REG_SWITCHERS3_SW2BVSEL_M (63 << 0)
47
24#define MC13783_REG_SWITCHERS5 29 48#define MC13783_REG_SWITCHERS5 29
25#define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) 49#define MC13783_REG_SWITCHERS5_SW3EN (1 << 20)
26#define MC13783_REG_SWITCHERS5_SW3VSEL 18 50#define MC13783_REG_SWITCHERS5_SW3VSEL 18
@@ -93,6 +117,44 @@
93 117
94 118
95/* Voltage Values */ 119/* Voltage Values */
120static const int mc13783_sw1x_val[] = {
121 900000, 925000, 950000, 975000,
122 1000000, 1025000, 1050000, 1075000,
123 1100000, 1125000, 1150000, 1175000,
124 1200000, 1225000, 1250000, 1275000,
125 1300000, 1325000, 1350000, 1375000,
126 1400000, 1425000, 1450000, 1475000,
127 1500000, 1525000, 1550000, 1575000,
128 1600000, 1625000, 1650000, 1675000,
129 1700000, 1700000, 1700000, 1700000,
130 1800000, 1800000, 1800000, 1800000,
131 1850000, 1850000, 1850000, 1850000,
132 2000000, 2000000, 2000000, 2000000,
133 2100000, 2100000, 2100000, 2100000,
134 2200000, 2200000, 2200000, 2200000,
135 2200000, 2200000, 2200000, 2200000,
136 2200000, 2200000, 2200000, 2200000,
137};
138
139static const int mc13783_sw2x_val[] = {
140 900000, 925000, 950000, 975000,
141 1000000, 1025000, 1050000, 1075000,
142 1100000, 1125000, 1150000, 1175000,
143 1200000, 1225000, 1250000, 1275000,
144 1300000, 1325000, 1350000, 1375000,
145 1400000, 1425000, 1450000, 1475000,
146 1500000, 1525000, 1550000, 1575000,
147 1600000, 1625000, 1650000, 1675000,
148 1700000, 1700000, 1700000, 1700000,
149 1800000, 1800000, 1800000, 1800000,
150 1900000, 1900000, 1900000, 1900000,
151 2000000, 2000000, 2000000, 2000000,
152 2100000, 2100000, 2100000, 2100000,
153 2200000, 2200000, 2200000, 2200000,
154 2200000, 2200000, 2200000, 2200000,
155 2200000, 2200000, 2200000, 2200000,
156};
157
96static const unsigned int mc13783_sw3_val[] = { 158static const unsigned int mc13783_sw3_val[] = {
97 5000000, 5000000, 5000000, 5500000, 159 5000000, 5000000, 5000000, 5500000,
98}; 160};
@@ -188,6 +250,10 @@ static struct regulator_ops mc13783_gpo_regulator_ops;
188 MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages) 250 MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages)
189 251
190static struct mc13xxx_regulator mc13783_regulators[] = { 252static struct mc13xxx_regulator mc13783_regulators[] = {
253 MC13783_DEFINE_SW(SW1A, SWITCHERS0, SWITCHERS0, mc13783_sw1x_val),
254 MC13783_DEFINE_SW(SW1B, SWITCHERS1, SWITCHERS1, mc13783_sw1x_val),
255 MC13783_DEFINE_SW(SW2A, SWITCHERS2, SWITCHERS2, mc13783_sw2x_val),
256 MC13783_DEFINE_SW(SW2B, SWITCHERS3, SWITCHERS3, mc13783_sw2x_val),
191 MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val), 257 MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val),
192 258
193 MC13783_FIXED_DEFINE(REG, VAUDIO, REGULATORMODE0, mc13783_vaudio_val), 259 MC13783_FIXED_DEFINE(REG, VAUDIO, REGULATORMODE0, mc13783_vaudio_val),
@@ -238,9 +304,10 @@ static int mc13783_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask,
238 304
239 BUG_ON(val & ~mask); 305 BUG_ON(val & ~mask);
240 306
307 mc13xxx_lock(priv->mc13xxx);
241 ret = mc13xxx_reg_read(mc13783, MC13783_REG_POWERMISC, &valread); 308 ret = mc13xxx_reg_read(mc13783, MC13783_REG_POWERMISC, &valread);
242 if (ret) 309 if (ret)
243 return ret; 310 goto out;
244 311
245 /* Update the stored state for Power Gates. */ 312 /* Update the stored state for Power Gates. */
246 priv->powermisc_pwgt_state = 313 priv->powermisc_pwgt_state =
@@ -253,7 +320,10 @@ static int mc13783_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask,
253 valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) | 320 valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) |
254 priv->powermisc_pwgt_state; 321 priv->powermisc_pwgt_state;
255 322
256 return mc13xxx_reg_write(mc13783, MC13783_REG_POWERMISC, valread); 323 ret = mc13xxx_reg_write(mc13783, MC13783_REG_POWERMISC, valread);
324out:
325 mc13xxx_unlock(priv->mc13xxx);
326 return ret;
257} 327}
258 328
259static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev) 329static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev)
@@ -261,7 +331,6 @@ static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev)
261 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 331 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
262 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; 332 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
263 int id = rdev_get_id(rdev); 333 int id = rdev_get_id(rdev);
264 int ret;
265 u32 en_val = mc13xxx_regulators[id].enable_bit; 334 u32 en_val = mc13xxx_regulators[id].enable_bit;
266 335
267 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 336 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
@@ -271,12 +340,8 @@ static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev)
271 id == MC13783_REG_PWGT2SPI) 340 id == MC13783_REG_PWGT2SPI)
272 en_val = 0; 341 en_val = 0;
273 342
274 mc13xxx_lock(priv->mc13xxx); 343 return mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit,
275 ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit,
276 en_val); 344 en_val);
277 mc13xxx_unlock(priv->mc13xxx);
278
279 return ret;
280} 345}
281 346
282static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev) 347static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev)
@@ -284,7 +349,6 @@ static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev)
284 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 349 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
285 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; 350 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
286 int id = rdev_get_id(rdev); 351 int id = rdev_get_id(rdev);
287 int ret;
288 u32 dis_val = 0; 352 u32 dis_val = 0;
289 353
290 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 354 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
@@ -294,12 +358,8 @@ static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev)
294 id == MC13783_REG_PWGT2SPI) 358 id == MC13783_REG_PWGT2SPI)
295 dis_val = mc13xxx_regulators[id].enable_bit; 359 dis_val = mc13xxx_regulators[id].enable_bit;
296 360
297 mc13xxx_lock(priv->mc13xxx); 361 return mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit,
298 ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit,
299 dis_val); 362 dis_val);
300 mc13xxx_unlock(priv->mc13xxx);
301
302 return ret;
303} 363}
304 364
305static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev) 365static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev)
@@ -330,7 +390,6 @@ static struct regulator_ops mc13783_gpo_regulator_ops = {
330 .is_enabled = mc13783_gpo_regulator_is_enabled, 390 .is_enabled = mc13783_gpo_regulator_is_enabled,
331 .list_voltage = regulator_list_voltage_table, 391 .list_voltage = regulator_list_voltage_table,
332 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 392 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
333 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
334}; 393};
335 394
336static int __devinit mc13783_regulator_probe(struct platform_device *pdev) 395static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index b388b746452e..1fa63812f7ac 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -305,9 +305,10 @@ static int mc13892_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask,
305 305
306 BUG_ON(val & ~mask); 306 BUG_ON(val & ~mask);
307 307
308 mc13xxx_lock(priv->mc13xxx);
308 ret = mc13xxx_reg_read(mc13892, MC13892_POWERMISC, &valread); 309 ret = mc13xxx_reg_read(mc13892, MC13892_POWERMISC, &valread);
309 if (ret) 310 if (ret)
310 return ret; 311 goto out;
311 312
312 /* Update the stored state for Power Gates. */ 313 /* Update the stored state for Power Gates. */
313 priv->powermisc_pwgt_state = 314 priv->powermisc_pwgt_state =
@@ -320,14 +321,16 @@ static int mc13892_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask,
320 valread = (valread & ~MC13892_POWERMISC_PWGTSPI_M) | 321 valread = (valread & ~MC13892_POWERMISC_PWGTSPI_M) |
321 priv->powermisc_pwgt_state; 322 priv->powermisc_pwgt_state;
322 323
323 return mc13xxx_reg_write(mc13892, MC13892_POWERMISC, valread); 324 ret = mc13xxx_reg_write(mc13892, MC13892_POWERMISC, valread);
325out:
326 mc13xxx_unlock(priv->mc13xxx);
327 return ret;
324} 328}
325 329
326static int mc13892_gpo_regulator_enable(struct regulator_dev *rdev) 330static int mc13892_gpo_regulator_enable(struct regulator_dev *rdev)
327{ 331{
328 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 332 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
329 int id = rdev_get_id(rdev); 333 int id = rdev_get_id(rdev);
330 int ret;
331 u32 en_val = mc13892_regulators[id].enable_bit; 334 u32 en_val = mc13892_regulators[id].enable_bit;
332 u32 mask = mc13892_regulators[id].enable_bit; 335 u32 mask = mc13892_regulators[id].enable_bit;
333 336
@@ -340,18 +343,13 @@ static int mc13892_gpo_regulator_enable(struct regulator_dev *rdev)
340 if (id == MC13892_GPO4) 343 if (id == MC13892_GPO4)
341 mask |= MC13892_POWERMISC_GPO4ADINEN; 344 mask |= MC13892_POWERMISC_GPO4ADINEN;
342 345
343 mc13xxx_lock(priv->mc13xxx); 346 return mc13892_powermisc_rmw(priv, mask, en_val);
344 ret = mc13892_powermisc_rmw(priv, mask, en_val);
345 mc13xxx_unlock(priv->mc13xxx);
346
347 return ret;
348} 347}
349 348
350static int mc13892_gpo_regulator_disable(struct regulator_dev *rdev) 349static int mc13892_gpo_regulator_disable(struct regulator_dev *rdev)
351{ 350{
352 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 351 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
353 int id = rdev_get_id(rdev); 352 int id = rdev_get_id(rdev);
354 int ret;
355 u32 dis_val = 0; 353 u32 dis_val = 0;
356 354
357 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 355 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
@@ -360,12 +358,8 @@ static int mc13892_gpo_regulator_disable(struct regulator_dev *rdev)
360 if (id == MC13892_PWGT1SPI || id == MC13892_PWGT2SPI) 358 if (id == MC13892_PWGT1SPI || id == MC13892_PWGT2SPI)
361 dis_val = mc13892_regulators[id].enable_bit; 359 dis_val = mc13892_regulators[id].enable_bit;
362 360
363 mc13xxx_lock(priv->mc13xxx); 361 return mc13892_powermisc_rmw(priv, mc13892_regulators[id].enable_bit,
364 ret = mc13892_powermisc_rmw(priv, mc13892_regulators[id].enable_bit,
365 dis_val); 362 dis_val);
366 mc13xxx_unlock(priv->mc13xxx);
367
368 return ret;
369} 363}
370 364
371static int mc13892_gpo_regulator_is_enabled(struct regulator_dev *rdev) 365static int mc13892_gpo_regulator_is_enabled(struct regulator_dev *rdev)
@@ -396,14 +390,13 @@ static struct regulator_ops mc13892_gpo_regulator_ops = {
396 .is_enabled = mc13892_gpo_regulator_is_enabled, 390 .is_enabled = mc13892_gpo_regulator_is_enabled,
397 .list_voltage = regulator_list_voltage_table, 391 .list_voltage = regulator_list_voltage_table,
398 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 392 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
399 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
400}; 393};
401 394
402static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev) 395static int mc13892_sw_regulator_get_voltage_sel(struct regulator_dev *rdev)
403{ 396{
404 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 397 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
405 int ret, id = rdev_get_id(rdev); 398 int ret, id = rdev_get_id(rdev);
406 unsigned int val, hi; 399 unsigned int val;
407 400
408 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 401 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
409 402
@@ -414,17 +407,11 @@ static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev)
414 if (ret) 407 if (ret)
415 return ret; 408 return ret;
416 409
417 hi = val & MC13892_SWITCHERS0_SWxHI;
418 val = (val & mc13892_regulators[id].vsel_mask) 410 val = (val & mc13892_regulators[id].vsel_mask)
419 >> mc13892_regulators[id].vsel_shift; 411 >> mc13892_regulators[id].vsel_shift;
420 412
421 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val); 413 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
422 414
423 if (hi)
424 val = (25000 * val) + 1100000;
425 else
426 val = (25000 * val) + 600000;
427
428 return val; 415 return val;
429} 416}
430 417
@@ -432,37 +419,25 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
432 unsigned selector) 419 unsigned selector)
433{ 420{
434 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 421 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
435 int hi, value, mask, id = rdev_get_id(rdev); 422 int volt, mask, id = rdev_get_id(rdev);
436 u32 valread; 423 u32 reg_value;
437 int ret; 424 int ret;
438 425
439 value = rdev->desc->volt_table[selector]; 426 volt = rdev->desc->volt_table[selector];
427 mask = mc13892_regulators[id].vsel_mask;
428 reg_value = selector << mc13892_regulators[id].vsel_shift;
429
430 if (volt > 1375000) {
431 mask |= MC13892_SWITCHERS0_SWxHI;
432 reg_value |= MC13892_SWITCHERS0_SWxHI;
433 } else if (volt < 1100000) {
434 mask |= MC13892_SWITCHERS0_SWxHI;
435 reg_value &= ~MC13892_SWITCHERS0_SWxHI;
436 }
440 437
441 mc13xxx_lock(priv->mc13xxx); 438 mc13xxx_lock(priv->mc13xxx);
442 ret = mc13xxx_reg_read(priv->mc13xxx, 439 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg, mask,
443 mc13892_regulators[id].vsel_reg, &valread); 440 reg_value);
444 if (ret)
445 goto err;
446
447 if (value > 1375000)
448 hi = 1;
449 else if (value < 1100000)
450 hi = 0;
451 else
452 hi = valread & MC13892_SWITCHERS0_SWxHI;
453
454 if (hi) {
455 value = (value - 1100000) / 25000;
456 value |= MC13892_SWITCHERS0_SWxHI;
457 } else
458 value = (value - 600000) / 25000;
459
460 mask = mc13892_regulators[id].vsel_mask | MC13892_SWITCHERS0_SWxHI;
461 valread = (valread & ~mask) |
462 (value << mc13892_regulators[id].vsel_shift);
463 ret = mc13xxx_reg_write(priv->mc13xxx, mc13892_regulators[id].vsel_reg,
464 valread);
465err:
466 mc13xxx_unlock(priv->mc13xxx); 441 mc13xxx_unlock(priv->mc13xxx);
467 442
468 return ret; 443 return ret;
@@ -471,7 +446,7 @@ err:
471static struct regulator_ops mc13892_sw_regulator_ops = { 446static struct regulator_ops mc13892_sw_regulator_ops = {
472 .list_voltage = regulator_list_voltage_table, 447 .list_voltage = regulator_list_voltage_table,
473 .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel, 448 .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel,
474 .get_voltage = mc13892_sw_regulator_get_voltage, 449 .get_voltage_sel = mc13892_sw_regulator_get_voltage_sel,
475}; 450};
476 451
477static int mc13892_vcam_set_mode(struct regulator_dev *rdev, unsigned int mode) 452static int mc13892_vcam_set_mode(struct regulator_dev *rdev, unsigned int mode)
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
index d6eda28ca5d0..88cbb832d555 100644
--- a/drivers/regulator/mc13xxx-regulator-core.c
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -143,30 +143,21 @@ int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
143 __func__, id, min_uV, max_uV); 143 __func__, id, min_uV, max_uV);
144 144
145 if (min_uV <= rdev->desc->volt_table[0] && 145 if (min_uV <= rdev->desc->volt_table[0] &&
146 rdev->desc->volt_table[0] <= max_uV) 146 rdev->desc->volt_table[0] <= max_uV) {
147 *selector = 0;
147 return 0; 148 return 0;
148 else 149 } else {
149 return -EINVAL; 150 return -EINVAL;
151 }
150} 152}
151EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage); 153EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage);
152 154
153int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev)
154{
155 int id = rdev_get_id(rdev);
156
157 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
158
159 return rdev->desc->volt_table[0];
160}
161EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_get_voltage);
162
163struct regulator_ops mc13xxx_fixed_regulator_ops = { 155struct regulator_ops mc13xxx_fixed_regulator_ops = {
164 .enable = mc13xxx_regulator_enable, 156 .enable = mc13xxx_regulator_enable,
165 .disable = mc13xxx_regulator_disable, 157 .disable = mc13xxx_regulator_disable,
166 .is_enabled = mc13xxx_regulator_is_enabled, 158 .is_enabled = mc13xxx_regulator_is_enabled,
167 .list_voltage = regulator_list_voltage_table, 159 .list_voltage = regulator_list_voltage_table,
168 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 160 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
169 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
170}; 161};
171EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops); 162EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops);
172 163
diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h
index eaff5510b6df..06c8903f182a 100644
--- a/drivers/regulator/mc13xxx.h
+++ b/drivers/regulator/mc13xxx.h
@@ -34,7 +34,6 @@ struct mc13xxx_regulator_priv {
34 34
35extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, 35extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
36 int min_uV, int max_uV, unsigned *selector); 36 int min_uV, int max_uV, unsigned *selector);
37extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev);
38 37
39#ifdef CONFIG_OF 38#ifdef CONFIG_OF
40extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev); 39extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 3e4106f2bda9..6f684916fd79 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -92,16 +92,18 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
92EXPORT_SYMBOL_GPL(of_get_regulator_init_data); 92EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
93 93
94/** 94/**
95 * of_regulator_match - extract regulator init data when node 95 * of_regulator_match - extract multiple regulator init data from device tree.
96 * property "regulator-compatible" matches with the regulator name.
97 * @dev: device requesting the data 96 * @dev: device requesting the data
98 * @node: parent device node of the regulators 97 * @node: parent device node of the regulators
99 * @matches: match table for the regulators 98 * @matches: match table for the regulators
100 * @num_matches: number of entries in match table 99 * @num_matches: number of entries in match table
101 * 100 *
102 * This function uses a match table specified by the regulator driver and 101 * This function uses a match table specified by the regulator driver to
103 * looks up the corresponding init data in the device tree if 102 * parse regulator init data from the device tree. @node is expected to
104 * regulator-compatible matches. Note that the match table is modified 103 * contain a set of child nodes, each providing the init data for one
104 * regulator. The data parsed from a child node will be matched to a regulator
105 * based on either the deprecated property regulator-compatible if present,
106 * or otherwise the child node's name. Note that the match table is modified
105 * in place. 107 * in place.
106 * 108 *
107 * Returns the number of matches found or a negative error code on failure. 109 * Returns the number of matches found or a negative error code on failure.
@@ -112,26 +114,23 @@ int of_regulator_match(struct device *dev, struct device_node *node,
112{ 114{
113 unsigned int count = 0; 115 unsigned int count = 0;
114 unsigned int i; 116 unsigned int i;
115 const char *regulator_comp; 117 const char *name;
116 struct device_node *child; 118 struct device_node *child;
117 119
118 if (!dev || !node) 120 if (!dev || !node)
119 return -EINVAL; 121 return -EINVAL;
120 122
121 for_each_child_of_node(node, child) { 123 for_each_child_of_node(node, child) {
122 regulator_comp = of_get_property(child, 124 name = of_get_property(child,
123 "regulator-compatible", NULL); 125 "regulator-compatible", NULL);
124 if (!regulator_comp) { 126 if (!name)
125 dev_err(dev, "regulator-compatible is missing for node %s\n", 127 name = child->name;
126 child->name);
127 continue;
128 }
129 for (i = 0; i < num_matches; i++) { 128 for (i = 0; i < num_matches; i++) {
130 struct of_regulator_match *match = &matches[i]; 129 struct of_regulator_match *match = &matches[i];
131 if (match->of_node) 130 if (match->of_node)
132 continue; 131 continue;
133 132
134 if (strcmp(match->name, regulator_comp)) 133 if (strcmp(match->name, name))
135 continue; 134 continue;
136 135
137 match->init_data = 136 match->init_data =
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 46c7e88f8381..2ba7502fa3b2 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -443,44 +443,6 @@ static int palmas_list_voltage_ldo(struct regulator_dev *dev,
443 return 850000 + (selector * 50000); 443 return 850000 + (selector * 50000);
444} 444}
445 445
446static int palmas_get_voltage_ldo_sel(struct regulator_dev *dev)
447{
448 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
449 int id = rdev_get_id(dev);
450 int selector;
451 unsigned int reg;
452 unsigned int addr;
453
454 addr = palmas_regs_info[id].vsel_addr;
455
456 palmas_ldo_read(pmic->palmas, addr, &reg);
457
458 selector = reg & PALMAS_LDO1_VOLTAGE_VSEL_MASK;
459
460 /* Adjust selector to match list_voltage ranges */
461 if (selector > 49)
462 selector = 49;
463
464 return selector;
465}
466
467static int palmas_set_voltage_ldo_sel(struct regulator_dev *dev,
468 unsigned selector)
469{
470 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
471 int id = rdev_get_id(dev);
472 unsigned int reg = 0;
473 unsigned int addr;
474
475 addr = palmas_regs_info[id].vsel_addr;
476
477 reg = selector;
478
479 palmas_ldo_write(pmic->palmas, addr, reg);
480
481 return 0;
482}
483
484static int palmas_map_voltage_ldo(struct regulator_dev *rdev, 446static int palmas_map_voltage_ldo(struct regulator_dev *rdev,
485 int min_uV, int max_uV) 447 int min_uV, int max_uV)
486{ 448{
@@ -505,8 +467,8 @@ static struct regulator_ops palmas_ops_ldo = {
505 .is_enabled = palmas_is_enabled_ldo, 467 .is_enabled = palmas_is_enabled_ldo,
506 .enable = regulator_enable_regmap, 468 .enable = regulator_enable_regmap,
507 .disable = regulator_disable_regmap, 469 .disable = regulator_disable_regmap,
508 .get_voltage_sel = palmas_get_voltage_ldo_sel, 470 .get_voltage_sel = regulator_get_voltage_sel_regmap,
509 .set_voltage_sel = palmas_set_voltage_ldo_sel, 471 .set_voltage_sel = regulator_set_voltage_sel_regmap,
510 .list_voltage = palmas_list_voltage_ldo, 472 .list_voltage = palmas_list_voltage_ldo,
511 .map_voltage = palmas_map_voltage_ldo, 473 .map_voltage = palmas_map_voltage_ldo,
512}; 474};
@@ -757,6 +719,9 @@ static __devinit int palmas_probe(struct platform_device *pdev)
757 719
758 pmic->desc[id].type = REGULATOR_VOLTAGE; 720 pmic->desc[id].type = REGULATOR_VOLTAGE;
759 pmic->desc[id].owner = THIS_MODULE; 721 pmic->desc[id].owner = THIS_MODULE;
722 pmic->desc[id].vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
723 palmas_regs_info[id].vsel_addr);
724 pmic->desc[id].vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK;
760 pmic->desc[id].enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, 725 pmic->desc[id].enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
761 palmas_regs_info[id].ctrl_addr); 726 palmas_regs_info[id].ctrl_addr);
762 pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE; 727 pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 4669dc9ac74a..926f9c8f2fac 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -24,7 +24,7 @@
24#include <linux/mfd/samsung/s2mps11.h> 24#include <linux/mfd/samsung/s2mps11.h>
25 25
26struct s2mps11_info { 26struct s2mps11_info {
27 struct regulator_dev **rdev; 27 struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX];
28 28
29 int ramp_delay2; 29 int ramp_delay2;
30 int ramp_delay34; 30 int ramp_delay34;
@@ -236,9 +236,8 @@ static __devinit int s2mps11_pmic_probe(struct platform_device *pdev)
236 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); 236 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
237 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); 237 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);
238 struct regulator_config config = { }; 238 struct regulator_config config = { };
239 struct regulator_dev **rdev;
240 struct s2mps11_info *s2mps11; 239 struct s2mps11_info *s2mps11;
241 int i, ret, size; 240 int i, ret;
242 unsigned char ramp_enable, ramp_reg = 0; 241 unsigned char ramp_enable, ramp_reg = 0;
243 242
244 if (!pdata) { 243 if (!pdata) {
@@ -251,13 +250,6 @@ static __devinit int s2mps11_pmic_probe(struct platform_device *pdev)
251 if (!s2mps11) 250 if (!s2mps11)
252 return -ENOMEM; 251 return -ENOMEM;
253 252
254 size = sizeof(struct regulator_dev *) * S2MPS11_REGULATOR_MAX;
255 s2mps11->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
256 if (!s2mps11->rdev) {
257 return -ENOMEM;
258 }
259
260 rdev = s2mps11->rdev;
261 platform_set_drvdata(pdev, s2mps11); 253 platform_set_drvdata(pdev, s2mps11);
262 254
263 s2mps11->ramp_delay2 = pdata->buck2_ramp_delay; 255 s2mps11->ramp_delay2 = pdata->buck2_ramp_delay;
@@ -297,12 +289,12 @@ static __devinit int s2mps11_pmic_probe(struct platform_device *pdev)
297 config.init_data = pdata->regulators[i].initdata; 289 config.init_data = pdata->regulators[i].initdata;
298 config.driver_data = s2mps11; 290 config.driver_data = s2mps11;
299 291
300 rdev[i] = regulator_register(&regulators[i], &config); 292 s2mps11->rdev[i] = regulator_register(&regulators[i], &config);
301 if (IS_ERR(rdev[i])) { 293 if (IS_ERR(s2mps11->rdev[i])) {
302 ret = PTR_ERR(rdev[i]); 294 ret = PTR_ERR(s2mps11->rdev[i]);
303 dev_err(&pdev->dev, "regulator init failed for %d\n", 295 dev_err(&pdev->dev, "regulator init failed for %d\n",
304 i); 296 i);
305 rdev[i] = NULL; 297 s2mps11->rdev[i] = NULL;
306 goto err; 298 goto err;
307 } 299 }
308 } 300 }
@@ -310,8 +302,7 @@ static __devinit int s2mps11_pmic_probe(struct platform_device *pdev)
310 return 0; 302 return 0;
311err: 303err:
312 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) 304 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
313 if (rdev[i]) 305 regulator_unregister(s2mps11->rdev[i]);
314 regulator_unregister(rdev[i]);
315 306
316 return ret; 307 return ret;
317} 308}
@@ -319,12 +310,10 @@ err:
319static int __devexit s2mps11_pmic_remove(struct platform_device *pdev) 310static int __devexit s2mps11_pmic_remove(struct platform_device *pdev)
320{ 311{
321 struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev); 312 struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev);
322 struct regulator_dev **rdev = s2mps11->rdev;
323 int i; 313 int i;
324 314
325 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) 315 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
326 if (rdev[i]) 316 regulator_unregister(s2mps11->rdev[i]);
327 regulator_unregister(rdev[i]);
328 317
329 return 0; 318 return 0;
330} 319}
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c
index 6caa222af77a..ab00cab905b7 100644
--- a/drivers/regulator/tps65217-regulator.c
+++ b/drivers/regulator/tps65217-regulator.c
@@ -22,6 +22,7 @@
22#include <linux/err.h> 22#include <linux/err.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24 24
25#include <linux/regulator/of_regulator.h>
25#include <linux/regulator/driver.h> 26#include <linux/regulator/driver.h>
26#include <linux/regulator/machine.h> 27#include <linux/regulator/machine.h>
27#include <linux/mfd/tps65217.h> 28#include <linux/mfd/tps65217.h>
@@ -281,37 +282,130 @@ static const struct regulator_desc regulators[] = {
281 NULL), 282 NULL),
282}; 283};
283 284
285#ifdef CONFIG_OF
286static struct of_regulator_match reg_matches[] = {
287 { .name = "dcdc1", .driver_data = (void *)TPS65217_DCDC_1 },
288 { .name = "dcdc2", .driver_data = (void *)TPS65217_DCDC_2 },
289 { .name = "dcdc3", .driver_data = (void *)TPS65217_DCDC_3 },
290 { .name = "ldo1", .driver_data = (void *)TPS65217_LDO_1 },
291 { .name = "ldo2", .driver_data = (void *)TPS65217_LDO_2 },
292 { .name = "ldo3", .driver_data = (void *)TPS65217_LDO_3 },
293 { .name = "ldo4", .driver_data = (void *)TPS65217_LDO_4 },
294};
295
296static struct tps65217_board *tps65217_parse_dt(struct platform_device *pdev)
297{
298 struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
299 struct device_node *node = tps->dev->of_node;
300 struct tps65217_board *pdata;
301 struct device_node *regs;
302 int i, count;
303
304 regs = of_find_node_by_name(node, "regulators");
305 if (!regs)
306 return NULL;
307
308 count = of_regulator_match(pdev->dev.parent, regs,
309 reg_matches, TPS65217_NUM_REGULATOR);
310 of_node_put(regs);
311 if ((count < 0) || (count > TPS65217_NUM_REGULATOR))
312 return NULL;
313
314 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
315 if (!pdata)
316 return NULL;
317
318 for (i = 0; i < count; i++) {
319 if (!reg_matches[i].init_data || !reg_matches[i].of_node)
320 continue;
321
322 pdata->tps65217_init_data[i] = reg_matches[i].init_data;
323 pdata->of_node[i] = reg_matches[i].of_node;
324 }
325
326 return pdata;
327}
328#else
329static struct tps65217_board *tps65217_parse_dt(struct platform_device *pdev)
330{
331 return NULL;
332}
333#endif
334
284static int __devinit tps65217_regulator_probe(struct platform_device *pdev) 335static int __devinit tps65217_regulator_probe(struct platform_device *pdev)
285{ 336{
337 struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
338 struct tps65217_board *pdata = dev_get_platdata(tps->dev);
339 struct regulator_init_data *reg_data;
286 struct regulator_dev *rdev; 340 struct regulator_dev *rdev;
287 struct tps65217 *tps;
288 struct tps_info *info = &tps65217_pmic_regs[pdev->id];
289 struct regulator_config config = { }; 341 struct regulator_config config = { };
342 int i, ret;
290 343
291 /* Already set by core driver */ 344 if (tps->dev->of_node)
292 tps = dev_to_tps65217(pdev->dev.parent); 345 pdata = tps65217_parse_dt(pdev);
293 tps->info[pdev->id] = info;
294 346
295 config.dev = &pdev->dev; 347 if (!pdata) {
296 config.of_node = pdev->dev.of_node; 348 dev_err(&pdev->dev, "Platform data not found\n");
297 config.init_data = pdev->dev.platform_data; 349 return -EINVAL;
298 config.driver_data = tps; 350 }
299 351
300 rdev = regulator_register(&regulators[pdev->id], &config); 352 if (tps65217_chip_id(tps) != TPS65217) {
301 if (IS_ERR(rdev)) 353 dev_err(&pdev->dev, "Invalid tps chip version\n");
302 return PTR_ERR(rdev); 354 return -ENODEV;
355 }
303 356
304 platform_set_drvdata(pdev, rdev); 357 platform_set_drvdata(pdev, tps);
305 358
359 for (i = 0; i < TPS65217_NUM_REGULATOR; i++) {
360
361 reg_data = pdata->tps65217_init_data[i];
362
363 /*
364 * Regulator API handles empty constraints but not NULL
365 * constraints
366 */
367 if (!reg_data)
368 continue;
369
370 /* Register the regulators */
371 tps->info[i] = &tps65217_pmic_regs[i];
372
373 config.dev = tps->dev;
374 config.init_data = reg_data;
375 config.driver_data = tps;
376 config.regmap = tps->regmap;
377 if (tps->dev->of_node)
378 config.of_node = pdata->of_node[i];
379
380 rdev = regulator_register(&regulators[i], &config);
381 if (IS_ERR(rdev)) {
382 dev_err(tps->dev, "failed to register %s regulator\n",
383 pdev->name);
384 ret = PTR_ERR(rdev);
385 goto err_unregister_regulator;
386 }
387
388 /* Save regulator for cleanup */
389 tps->rdev[i] = rdev;
390 }
306 return 0; 391 return 0;
392
393err_unregister_regulator:
394 while (--i >= 0)
395 regulator_unregister(tps->rdev[i]);
396
397 return ret;
307} 398}
308 399
309static int __devexit tps65217_regulator_remove(struct platform_device *pdev) 400static int __devexit tps65217_regulator_remove(struct platform_device *pdev)
310{ 401{
311 struct regulator_dev *rdev = platform_get_drvdata(pdev); 402 struct tps65217 *tps = platform_get_drvdata(pdev);
403 unsigned int i;
404
405 for (i = 0; i < TPS65217_NUM_REGULATOR; i++)
406 regulator_unregister(tps->rdev[i]);
312 407
313 platform_set_drvdata(pdev, NULL); 408 platform_set_drvdata(pdev, NULL);
314 regulator_unregister(rdev);
315 409
316 return 0; 410 return 0;
317} 411}
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c
index 947ece933d90..058d2f2675e9 100644
--- a/drivers/regulator/tps6524x-regulator.c
+++ b/drivers/regulator/tps6524x-regulator.c
@@ -502,15 +502,13 @@ static int set_current_limit(struct regulator_dev *rdev, int min_uA,
502 if (info->n_ilimsels == 1) 502 if (info->n_ilimsels == 1)
503 return -EINVAL; 503 return -EINVAL;
504 504
505 for (i = 0; i < info->n_ilimsels; i++) 505 for (i = info->n_ilimsels - 1; i >= 0; i--) {
506 if (min_uA <= info->ilimsels[i] && 506 if (min_uA <= info->ilimsels[i] &&
507 max_uA >= info->ilimsels[i]) 507 max_uA >= info->ilimsels[i])
508 break; 508 return write_field(hw, &info->ilimsel, i);
509 509 }
510 if (i >= info->n_ilimsels)
511 return -EINVAL;
512 510
513 return write_field(hw, &info->ilimsel, i); 511 return -EINVAL;
514} 512}
515 513
516static int get_current_limit(struct regulator_dev *rdev) 514static int get_current_limit(struct regulator_dev *rdev)
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 19241fc30050..ce1e7cb8d513 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -57,9 +57,6 @@
57struct tps6586x_regulator { 57struct tps6586x_regulator {
58 struct regulator_desc desc; 58 struct regulator_desc desc;
59 59
60 int volt_reg;
61 int volt_shift;
62 int volt_nbits;
63 int enable_bit[2]; 60 int enable_bit[2];
64 int enable_reg[2]; 61 int enable_reg[2];
65 62
@@ -81,10 +78,10 @@ static int tps6586x_set_voltage_sel(struct regulator_dev *rdev,
81 int ret, val, rid = rdev_get_id(rdev); 78 int ret, val, rid = rdev_get_id(rdev);
82 uint8_t mask; 79 uint8_t mask;
83 80
84 val = selector << ri->volt_shift; 81 val = selector << (ffs(rdev->desc->vsel_mask) - 1);
85 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; 82 mask = rdev->desc->vsel_mask;
86 83
87 ret = tps6586x_update(parent, ri->volt_reg, val, mask); 84 ret = tps6586x_update(parent, rdev->desc->vsel_reg, val, mask);
88 if (ret) 85 if (ret)
89 return ret; 86 return ret;
90 87
@@ -100,66 +97,17 @@ static int tps6586x_set_voltage_sel(struct regulator_dev *rdev,
100 return ret; 97 return ret;
101} 98}
102 99
103static int tps6586x_get_voltage_sel(struct regulator_dev *rdev)
104{
105 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
106 struct device *parent = to_tps6586x_dev(rdev);
107 uint8_t val, mask;
108 int ret;
109
110 ret = tps6586x_read(parent, ri->volt_reg, &val);
111 if (ret)
112 return ret;
113
114 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
115 val = (val & mask) >> ri->volt_shift;
116
117 if (val >= ri->desc.n_voltages)
118 BUG();
119
120 return val;
121}
122
123static int tps6586x_regulator_enable(struct regulator_dev *rdev)
124{
125 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
126 struct device *parent = to_tps6586x_dev(rdev);
127
128 return tps6586x_set_bits(parent, ri->enable_reg[0],
129 1 << ri->enable_bit[0]);
130}
131
132static int tps6586x_regulator_disable(struct regulator_dev *rdev)
133{
134 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
135 struct device *parent = to_tps6586x_dev(rdev);
136
137 return tps6586x_clr_bits(parent, ri->enable_reg[0],
138 1 << ri->enable_bit[0]);
139}
140
141static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev)
142{
143 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
144 struct device *parent = to_tps6586x_dev(rdev);
145 uint8_t reg_val;
146 int ret;
147
148 ret = tps6586x_read(parent, ri->enable_reg[0], &reg_val);
149 if (ret)
150 return ret;
151
152 return !!(reg_val & (1 << ri->enable_bit[0]));
153}
154
155static struct regulator_ops tps6586x_regulator_ops = { 100static struct regulator_ops tps6586x_regulator_ops = {
156 .list_voltage = regulator_list_voltage_table, 101 .list_voltage = regulator_list_voltage_table,
157 .get_voltage_sel = tps6586x_get_voltage_sel, 102 .get_voltage_sel = regulator_get_voltage_sel_regmap,
158 .set_voltage_sel = tps6586x_set_voltage_sel, 103 .set_voltage_sel = tps6586x_set_voltage_sel,
159 104
160 .is_enabled = tps6586x_regulator_is_enabled, 105 .is_enabled = regulator_is_enabled_regmap,
161 .enable = tps6586x_regulator_enable, 106 .enable = regulator_enable_regmap,
162 .disable = tps6586x_regulator_disable, 107 .disable = regulator_disable_regmap,
108};
109
110static struct regulator_ops tps6586x_sys_regulator_ops = {
163}; 111};
164 112
165static const unsigned int tps6586x_ldo0_voltages[] = { 113static const unsigned int tps6586x_ldo0_voltages[] = {
@@ -202,10 +150,11 @@ static const unsigned int tps6586x_dvm_voltages[] = {
202 .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ 150 .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \
203 .volt_table = tps6586x_##vdata##_voltages, \ 151 .volt_table = tps6586x_##vdata##_voltages, \
204 .owner = THIS_MODULE, \ 152 .owner = THIS_MODULE, \
153 .enable_reg = TPS6586X_SUPPLY##ereg0, \
154 .enable_mask = 1 << (ebit0), \
155 .vsel_reg = TPS6586X_##vreg, \
156 .vsel_mask = ((1 << (nbits)) - 1) << (shift), \
205 }, \ 157 }, \
206 .volt_reg = TPS6586X_##vreg, \
207 .volt_shift = (shift), \
208 .volt_nbits = (nbits), \
209 .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \ 158 .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \
210 .enable_bit[0] = (ebit0), \ 159 .enable_bit[0] = (ebit0), \
211 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \ 160 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \
@@ -230,15 +179,28 @@ static const unsigned int tps6586x_dvm_voltages[] = {
230 TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ 179 TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \
231} 180}
232 181
182#define TPS6586X_SYS_REGULATOR() \
183{ \
184 .desc = { \
185 .supply_name = "sys", \
186 .name = "REG-SYS", \
187 .ops = &tps6586x_sys_regulator_ops, \
188 .type = REGULATOR_VOLTAGE, \
189 .id = TPS6586X_ID_SYS, \
190 .owner = THIS_MODULE, \
191 }, \
192}
193
233static struct tps6586x_regulator tps6586x_regulator[] = { 194static struct tps6586x_regulator tps6586x_regulator[] = {
195 TPS6586X_SYS_REGULATOR(),
234 TPS6586X_LDO(LDO_0, "vinldo01", ldo0, SUPPLYV1, 5, 3, ENC, 0, END, 0), 196 TPS6586X_LDO(LDO_0, "vinldo01", ldo0, SUPPLYV1, 5, 3, ENC, 0, END, 0),
235 TPS6586X_LDO(LDO_3, "vinldo23", ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2), 197 TPS6586X_LDO(LDO_3, "vinldo23", ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2),
236 TPS6586X_LDO(LDO_5, NULL, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6), 198 TPS6586X_LDO(LDO_5, "REG-SYS", ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6),
237 TPS6586X_LDO(LDO_6, "vinldo678", ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4), 199 TPS6586X_LDO(LDO_6, "vinldo678", ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4),
238 TPS6586X_LDO(LDO_7, "vinldo678", ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5), 200 TPS6586X_LDO(LDO_7, "vinldo678", ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5),
239 TPS6586X_LDO(LDO_8, "vinldo678", ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6), 201 TPS6586X_LDO(LDO_8, "vinldo678", ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6),
240 TPS6586X_LDO(LDO_9, "vinldo9", ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7), 202 TPS6586X_LDO(LDO_9, "vinldo9", ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7),
241 TPS6586X_LDO(LDO_RTC, NULL, ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7), 203 TPS6586X_LDO(LDO_RTC, "REG-SYS", ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7),
242 TPS6586X_LDO(LDO_1, "vinldo01", dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1), 204 TPS6586X_LDO(LDO_1, "vinldo01", dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1),
243 TPS6586X_LDO(SM_2, "vin-sm2", sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7), 205 TPS6586X_LDO(SM_2, "vin-sm2", sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7),
244 206
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 77a71a5c17c3..7eb986a40746 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -10,6 +10,8 @@
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/string.h>
14#include <linux/slab.h>
13#include <linux/init.h> 15#include <linux/init.h>
14#include <linux/err.h> 16#include <linux/err.h>
15#include <linux/platform_device.h> 17#include <linux/platform_device.h>
@@ -624,18 +626,9 @@ static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
624 return info->min_mV * 1000; 626 return info->min_mV * 1000;
625} 627}
626 628
627static int twlfixed_get_voltage(struct regulator_dev *rdev)
628{
629 struct twlreg_info *info = rdev_get_drvdata(rdev);
630
631 return info->min_mV * 1000;
632}
633
634static struct regulator_ops twl4030fixed_ops = { 629static struct regulator_ops twl4030fixed_ops = {
635 .list_voltage = twlfixed_list_voltage, 630 .list_voltage = twlfixed_list_voltage,
636 631
637 .get_voltage = twlfixed_get_voltage,
638
639 .enable = twl4030reg_enable, 632 .enable = twl4030reg_enable,
640 .disable = twl4030reg_disable, 633 .disable = twl4030reg_disable,
641 .is_enabled = twl4030reg_is_enabled, 634 .is_enabled = twl4030reg_is_enabled,
@@ -648,8 +641,6 @@ static struct regulator_ops twl4030fixed_ops = {
648static struct regulator_ops twl6030fixed_ops = { 641static struct regulator_ops twl6030fixed_ops = {
649 .list_voltage = twlfixed_list_voltage, 642 .list_voltage = twlfixed_list_voltage,
650 643
651 .get_voltage = twlfixed_get_voltage,
652
653 .enable = twl6030reg_enable, 644 .enable = twl6030reg_enable,
654 .disable = twl6030reg_disable, 645 .disable = twl6030reg_disable,
655 .is_enabled = twl6030reg_is_enabled, 646 .is_enabled = twl6030reg_is_enabled,
@@ -659,13 +650,6 @@ static struct regulator_ops twl6030fixed_ops = {
659 .get_status = twl6030reg_get_status, 650 .get_status = twl6030reg_get_status,
660}; 651};
661 652
662static struct regulator_ops twl6030_fixed_resource = {
663 .enable = twl6030reg_enable,
664 .disable = twl6030reg_disable,
665 .is_enabled = twl6030reg_is_enabled,
666 .get_status = twl6030reg_get_status,
667};
668
669/* 653/*
670 * SMPS status and control 654 * SMPS status and control
671 */ 655 */
@@ -757,37 +741,32 @@ static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
757 return voltage; 741 return voltage;
758} 742}
759 743
760static int 744static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV,
761twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, 745 int max_uV)
762 unsigned int *selector)
763{ 746{
764 struct twlreg_info *info = rdev_get_drvdata(rdev); 747 struct twlreg_info *info = rdev_get_drvdata(rdev);
765 int vsel = 0; 748 int vsel = 0;
766 749
767 switch (info->flags) { 750 switch (info->flags) {
768 case 0: 751 case 0:
769 if (min_uV == 0) 752 if (min_uV == 0)
770 vsel = 0; 753 vsel = 0;
771 else if ((min_uV >= 600000) && (min_uV <= 1300000)) { 754 else if ((min_uV >= 600000) && (min_uV <= 1300000)) {
772 int calc_uV;
773 vsel = DIV_ROUND_UP(min_uV - 600000, 12500); 755 vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
774 vsel++; 756 vsel++;
775 calc_uV = twl6030smps_list_voltage(rdev, vsel);
776 if (calc_uV > max_uV)
777 return -EINVAL;
778 } 757 }
779 /* Values 1..57 for vsel are linear and can be calculated 758 /* Values 1..57 for vsel are linear and can be calculated
780 * values 58..62 are non linear. 759 * values 58..62 are non linear.
781 */ 760 */
782 else if ((min_uV > 1900000) && (max_uV >= 2100000)) 761 else if ((min_uV > 1900000) && (min_uV <= 2100000))
783 vsel = 62; 762 vsel = 62;
784 else if ((min_uV > 1800000) && (max_uV >= 1900000)) 763 else if ((min_uV > 1800000) && (min_uV <= 1900000))
785 vsel = 61; 764 vsel = 61;
786 else if ((min_uV > 1500000) && (max_uV >= 1800000)) 765 else if ((min_uV > 1500000) && (min_uV <= 1800000))
787 vsel = 60; 766 vsel = 60;
788 else if ((min_uV > 1350000) && (max_uV >= 1500000)) 767 else if ((min_uV > 1350000) && (min_uV <= 1500000))
789 vsel = 59; 768 vsel = 59;
790 else if ((min_uV > 1300000) && (max_uV >= 1350000)) 769 else if ((min_uV > 1300000) && (min_uV <= 1350000))
791 vsel = 58; 770 vsel = 58;
792 else 771 else
793 return -EINVAL; 772 return -EINVAL;
@@ -796,25 +775,21 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
796 if (min_uV == 0) 775 if (min_uV == 0)
797 vsel = 0; 776 vsel = 0;
798 else if ((min_uV >= 700000) && (min_uV <= 1420000)) { 777 else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
799 int calc_uV;
800 vsel = DIV_ROUND_UP(min_uV - 700000, 12500); 778 vsel = DIV_ROUND_UP(min_uV - 700000, 12500);
801 vsel++; 779 vsel++;
802 calc_uV = twl6030smps_list_voltage(rdev, vsel);
803 if (calc_uV > max_uV)
804 return -EINVAL;
805 } 780 }
806 /* Values 1..57 for vsel are linear and can be calculated 781 /* Values 1..57 for vsel are linear and can be calculated
807 * values 58..62 are non linear. 782 * values 58..62 are non linear.
808 */ 783 */
809 else if ((min_uV > 1900000) && (max_uV >= 2100000)) 784 else if ((min_uV > 1900000) && (min_uV <= 2100000))
810 vsel = 62; 785 vsel = 62;
811 else if ((min_uV > 1800000) && (max_uV >= 1900000)) 786 else if ((min_uV > 1800000) && (min_uV <= 1900000))
812 vsel = 61; 787 vsel = 61;
813 else if ((min_uV > 1350000) && (max_uV >= 1800000)) 788 else if ((min_uV > 1350000) && (min_uV <= 1800000))
814 vsel = 60; 789 vsel = 60;
815 else if ((min_uV > 1350000) && (max_uV >= 1500000)) 790 else if ((min_uV > 1350000) && (min_uV <= 1500000))
816 vsel = 59; 791 vsel = 59;
817 else if ((min_uV > 1300000) && (max_uV >= 1350000)) 792 else if ((min_uV > 1300000) && (min_uV <= 1350000))
818 vsel = 58; 793 vsel = 58;
819 else 794 else
820 return -EINVAL; 795 return -EINVAL;
@@ -830,17 +805,23 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
830 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: 805 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
831 if (min_uV == 0) { 806 if (min_uV == 0) {
832 vsel = 0; 807 vsel = 0;
833 } else if ((min_uV >= 2161000) && (max_uV <= 4321000)) { 808 } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) {
834 vsel = DIV_ROUND_UP(min_uV - 2161000, 38600); 809 vsel = DIV_ROUND_UP(min_uV - 2161000, 38600);
835 vsel++; 810 vsel++;
836 } 811 }
837 break; 812 break;
838 } 813 }
839 814
840 *selector = vsel; 815 return vsel;
816}
817
818static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev,
819 unsigned int selector)
820{
821 struct twlreg_info *info = rdev_get_drvdata(rdev);
841 822
842 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS, 823 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
843 vsel); 824 selector);
844} 825}
845 826
846static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev) 827static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
@@ -852,8 +833,9 @@ static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
852 833
853static struct regulator_ops twlsmps_ops = { 834static struct regulator_ops twlsmps_ops = {
854 .list_voltage = twl6030smps_list_voltage, 835 .list_voltage = twl6030smps_list_voltage,
836 .map_voltage = twl6030smps_map_voltage,
855 837
856 .set_voltage = twl6030smps_set_voltage, 838 .set_voltage_sel = twl6030smps_set_voltage_sel,
857 .get_voltage_sel = twl6030smps_get_voltage_sel, 839 .get_voltage_sel = twl6030smps_get_voltage_sel,
858 840
859 .enable = twl6030reg_enable, 841 .enable = twl6030reg_enable,
@@ -876,7 +858,7 @@ static struct regulator_ops twlsmps_ops = {
876 0x0, TWL6030, twl6030fixed_ops) 858 0x0, TWL6030, twl6030fixed_ops)
877 859
878#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ 860#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
879static struct twlreg_info TWL4030_INFO_##label = { \ 861static const struct twlreg_info TWL4030_INFO_##label = { \
880 .base = offset, \ 862 .base = offset, \
881 .id = num, \ 863 .id = num, \
882 .table_len = ARRAY_SIZE(label##_VSEL_table), \ 864 .table_len = ARRAY_SIZE(label##_VSEL_table), \
@@ -894,7 +876,7 @@ static struct twlreg_info TWL4030_INFO_##label = { \
894 } 876 }
895 877
896#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \ 878#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
897static struct twlreg_info TWL4030_INFO_##label = { \ 879static const struct twlreg_info TWL4030_INFO_##label = { \
898 .base = offset, \ 880 .base = offset, \
899 .id = num, \ 881 .id = num, \
900 .remap = remap_conf, \ 882 .remap = remap_conf, \
@@ -909,7 +891,7 @@ static struct twlreg_info TWL4030_INFO_##label = { \
909 } 891 }
910 892
911#define TWL6030_ADJUSTABLE_SMPS(label) \ 893#define TWL6030_ADJUSTABLE_SMPS(label) \
912static struct twlreg_info TWL6030_INFO_##label = { \ 894static const struct twlreg_info TWL6030_INFO_##label = { \
913 .desc = { \ 895 .desc = { \
914 .name = #label, \ 896 .name = #label, \
915 .id = TWL6030_REG_##label, \ 897 .id = TWL6030_REG_##label, \
@@ -920,7 +902,7 @@ static struct twlreg_info TWL6030_INFO_##label = { \
920 } 902 }
921 903
922#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 904#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
923static struct twlreg_info TWL6030_INFO_##label = { \ 905static const struct twlreg_info TWL6030_INFO_##label = { \
924 .base = offset, \ 906 .base = offset, \
925 .min_mV = min_mVolts, \ 907 .min_mV = min_mVolts, \
926 .max_mV = max_mVolts, \ 908 .max_mV = max_mVolts, \
@@ -935,7 +917,7 @@ static struct twlreg_info TWL6030_INFO_##label = { \
935 } 917 }
936 918
937#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 919#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
938static struct twlreg_info TWL6025_INFO_##label = { \ 920static const struct twlreg_info TWL6025_INFO_##label = { \
939 .base = offset, \ 921 .base = offset, \
940 .min_mV = min_mVolts, \ 922 .min_mV = min_mVolts, \
941 .max_mV = max_mVolts, \ 923 .max_mV = max_mVolts, \
@@ -951,7 +933,7 @@ static struct twlreg_info TWL6025_INFO_##label = { \
951 933
952#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ 934#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
953 family, operations) \ 935 family, operations) \
954static struct twlreg_info TWLFIXED_INFO_##label = { \ 936static const struct twlreg_info TWLFIXED_INFO_##label = { \
955 .base = offset, \ 937 .base = offset, \
956 .id = num, \ 938 .id = num, \
957 .min_mV = mVolts, \ 939 .min_mV = mVolts, \
@@ -981,7 +963,7 @@ static struct twlreg_info TWLRES_INFO_##label = { \
981 } 963 }
982 964
983#define TWL6025_ADJUSTABLE_SMPS(label, offset) \ 965#define TWL6025_ADJUSTABLE_SMPS(label, offset) \
984static struct twlreg_info TWLSMPS_INFO_##label = { \ 966static const struct twlreg_info TWLSMPS_INFO_##label = { \
985 .base = offset, \ 967 .base = offset, \
986 .min_mV = 600, \ 968 .min_mV = 600, \
987 .max_mV = 2100, \ 969 .max_mV = 2100, \
@@ -1138,6 +1120,7 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1138{ 1120{
1139 int i, id; 1121 int i, id;
1140 struct twlreg_info *info; 1122 struct twlreg_info *info;
1123 const struct twlreg_info *template;
1141 struct regulator_init_data *initdata; 1124 struct regulator_init_data *initdata;
1142 struct regulation_constraints *c; 1125 struct regulation_constraints *c;
1143 struct regulator_dev *rdev; 1126 struct regulator_dev *rdev;
@@ -1147,17 +1130,17 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1147 1130
1148 match = of_match_device(twl_of_match, &pdev->dev); 1131 match = of_match_device(twl_of_match, &pdev->dev);
1149 if (match) { 1132 if (match) {
1150 info = match->data; 1133 template = match->data;
1151 id = info->desc.id; 1134 id = template->desc.id;
1152 initdata = of_get_regulator_init_data(&pdev->dev, 1135 initdata = of_get_regulator_init_data(&pdev->dev,
1153 pdev->dev.of_node); 1136 pdev->dev.of_node);
1154 drvdata = NULL; 1137 drvdata = NULL;
1155 } else { 1138 } else {
1156 id = pdev->id; 1139 id = pdev->id;
1157 initdata = pdev->dev.platform_data; 1140 initdata = pdev->dev.platform_data;
1158 for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) { 1141 for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) {
1159 info = twl_of_match[i].data; 1142 template = twl_of_match[i].data;
1160 if (info && info->desc.id == id) 1143 if (template && template->desc.id == id)
1161 break; 1144 break;
1162 } 1145 }
1163 if (i == ARRAY_SIZE(twl_of_match)) 1146 if (i == ARRAY_SIZE(twl_of_match))
@@ -1168,12 +1151,16 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1168 return -EINVAL; 1151 return -EINVAL;
1169 } 1152 }
1170 1153
1171 if (!info) 1154 if (!template)
1172 return -ENODEV; 1155 return -ENODEV;
1173 1156
1174 if (!initdata) 1157 if (!initdata)
1175 return -EINVAL; 1158 return -EINVAL;
1176 1159
1160 info = kmemdup(template, sizeof (*info), GFP_KERNEL);
1161 if (!info)
1162 return -ENOMEM;
1163
1177 if (drvdata) { 1164 if (drvdata) {
1178 /* copy the driver data into regulator data */ 1165 /* copy the driver data into regulator data */
1179 info->features = drvdata->features; 1166 info->features = drvdata->features;
@@ -1234,6 +1221,7 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1234 if (IS_ERR(rdev)) { 1221 if (IS_ERR(rdev)) {
1235 dev_err(&pdev->dev, "can't register %s, %ld\n", 1222 dev_err(&pdev->dev, "can't register %s, %ld\n",
1236 info->desc.name, PTR_ERR(rdev)); 1223 info->desc.name, PTR_ERR(rdev));
1224 kfree(info);
1237 return PTR_ERR(rdev); 1225 return PTR_ERR(rdev);
1238 } 1226 }
1239 platform_set_drvdata(pdev, rdev); 1227 platform_set_drvdata(pdev, rdev);
@@ -1255,7 +1243,11 @@ static int __devinit twlreg_probe(struct platform_device *pdev)
1255 1243
1256static int __devexit twlreg_remove(struct platform_device *pdev) 1244static int __devexit twlreg_remove(struct platform_device *pdev)
1257{ 1245{
1258 regulator_unregister(platform_get_drvdata(pdev)); 1246 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1247 struct twlreg_info *info = rdev->reg_data;
1248
1249 regulator_unregister(rdev);
1250 kfree(info);
1259 return 0; 1251 return 0;
1260} 1252}
1261 1253
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 7413885be01b..90cbcc683704 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -339,16 +339,15 @@ static int wm831x_buckv_set_current_limit(struct regulator_dev *rdev,
339 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2; 339 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
340 int i; 340 int i;
341 341
342 for (i = 0; i < ARRAY_SIZE(wm831x_dcdc_ilim); i++) { 342 for (i = ARRAY_SIZE(wm831x_dcdc_ilim) - 1; i >= 0; i--) {
343 if ((min_uA <= wm831x_dcdc_ilim[i]) && 343 if ((min_uA <= wm831x_dcdc_ilim[i]) &&
344 (wm831x_dcdc_ilim[i] <= max_uA)) 344 (wm831x_dcdc_ilim[i] <= max_uA))
345 break; 345 return wm831x_set_bits(wm831x, reg,
346 WM831X_DC1_HC_THR_MASK,
347 i << WM831X_DC1_HC_THR_SHIFT);
346 } 348 }
347 if (i == ARRAY_SIZE(wm831x_dcdc_ilim))
348 return -EINVAL;
349 349
350 return wm831x_set_bits(wm831x, reg, WM831X_DC1_HC_THR_MASK, 350 return -EINVAL;
351 i << WM831X_DC1_HC_THR_SHIFT);
352} 351}
353 352
354static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev) 353static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index 5cb70ca1e98d..9af512672be1 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -205,6 +205,8 @@ static int wm831x_gp_ldo_get_status(struct regulator_dev *rdev)
205 205
206 /* Is it reporting under voltage? */ 206 /* Is it reporting under voltage? */
207 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); 207 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
208 if (ret < 0)
209 return ret;
208 if (ret & mask) 210 if (ret & mask)
209 return REGULATOR_STATUS_ERROR; 211 return REGULATOR_STATUS_ERROR;
210 212
@@ -237,6 +239,8 @@ static struct regulator_ops wm831x_gp_ldo_ops = {
237 .set_mode = wm831x_gp_ldo_set_mode, 239 .set_mode = wm831x_gp_ldo_set_mode,
238 .get_status = wm831x_gp_ldo_get_status, 240 .get_status = wm831x_gp_ldo_get_status,
239 .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode, 241 .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode,
242 .get_bypass = regulator_get_bypass_regmap,
243 .set_bypass = regulator_set_bypass_regmap,
240 244
241 .is_enabled = regulator_is_enabled_regmap, 245 .is_enabled = regulator_is_enabled_regmap,
242 .enable = regulator_enable_regmap, 246 .enable = regulator_enable_regmap,
@@ -293,6 +297,8 @@ static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev)
293 ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK; 297 ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK;
294 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 298 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
295 ldo->desc.enable_mask = 1 << id; 299 ldo->desc.enable_mask = 1 << id;
300 ldo->desc.bypass_reg = ldo->base;
301 ldo->desc.bypass_mask = WM831X_LDO1_SWI;
296 302
297 config.dev = pdev->dev.parent; 303 config.dev = pdev->dev.parent;
298 if (pdata) 304 if (pdata)
@@ -469,6 +475,8 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev)
469 475
470 /* Is it reporting under voltage? */ 476 /* Is it reporting under voltage? */
471 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); 477 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
478 if (ret < 0)
479 return ret;
472 if (ret & mask) 480 if (ret & mask)
473 return REGULATOR_STATUS_ERROR; 481 return REGULATOR_STATUS_ERROR;
474 482
@@ -488,6 +496,8 @@ static struct regulator_ops wm831x_aldo_ops = {
488 .get_mode = wm831x_aldo_get_mode, 496 .get_mode = wm831x_aldo_get_mode,
489 .set_mode = wm831x_aldo_set_mode, 497 .set_mode = wm831x_aldo_set_mode,
490 .get_status = wm831x_aldo_get_status, 498 .get_status = wm831x_aldo_get_status,
499 .set_bypass = regulator_set_bypass_regmap,
500 .get_bypass = regulator_get_bypass_regmap,
491 501
492 .is_enabled = regulator_is_enabled_regmap, 502 .is_enabled = regulator_is_enabled_regmap,
493 .enable = regulator_enable_regmap, 503 .enable = regulator_enable_regmap,
@@ -544,6 +554,8 @@ static __devinit int wm831x_aldo_probe(struct platform_device *pdev)
544 ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK; 554 ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK;
545 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 555 ldo->desc.enable_reg = WM831X_LDO_ENABLE;
546 ldo->desc.enable_mask = 1 << id; 556 ldo->desc.enable_mask = 1 << id;
557 ldo->desc.bypass_reg = ldo->base;
558 ldo->desc.bypass_mask = WM831X_LDO7_SWI;
547 559
548 config.dev = pdev->dev.parent; 560 config.dev = pdev->dev.parent;
549 if (pdata) 561 if (pdata)
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 9035dd053611..27c746ef0636 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -120,13 +120,8 @@ static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
120 120
121 case REGULATOR_MODE_IDLE: 121 case REGULATOR_MODE_IDLE:
122 /* Datasheet: standby */ 122 /* Datasheet: standby */
123 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
124 WM8400_DC1_ACTIVE, 0);
125 if (ret != 0)
126 return ret;
127 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 123 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
128 WM8400_DC1_SLEEP, 0); 124 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, 0);
129
130 default: 125 default:
131 return -EINVAL; 126 return -EINVAL;
132 } 127 }
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 590cfafc7c17..1859f71372e2 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -1008,8 +1008,8 @@ static int rpmsg_probe(struct virtio_device *vdev)
1008 return 0; 1008 return 0;
1009 1009
1010free_coherent: 1010free_coherent:
1011 dma_free_coherent(vdev->dev.parent, RPMSG_TOTAL_BUF_SPACE, bufs_va, 1011 dma_free_coherent(vdev->dev.parent->parent, RPMSG_TOTAL_BUF_SPACE,
1012 vrp->bufs_dma); 1012 bufs_va, vrp->bufs_dma);
1013vqs_del: 1013vqs_del:
1014 vdev->config->del_vqs(vrp->vdev); 1014 vdev->config->del_vqs(vrp->vdev);
1015free_vrp: 1015free_vrp:
@@ -1043,7 +1043,7 @@ static void __devexit rpmsg_remove(struct virtio_device *vdev)
1043 1043
1044 vdev->config->del_vqs(vrp->vdev); 1044 vdev->config->del_vqs(vrp->vdev);
1045 1045
1046 dma_free_coherent(vdev->dev.parent, RPMSG_TOTAL_BUF_SPACE, 1046 dma_free_coherent(vdev->dev.parent->parent, RPMSG_TOTAL_BUF_SPACE,
1047 vrp->rbufs, vrp->bufs_dma); 1047 vrp->rbufs, vrp->bufs_dma);
1048 1048
1049 kfree(vrp); 1049 kfree(vrp);
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index c5d06fe83bba..9277d945bf48 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -495,6 +495,11 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev)
495 if (ret < 0) 495 if (ret < 0)
496 goto out1; 496 goto out1;
497 497
498 /* ensure interrupts are disabled, bootloaders can be strange */
499 ret = twl_rtc_write_u8(0, REG_RTC_INTERRUPTS_REG);
500 if (ret < 0)
501 dev_warn(&pdev->dev, "unable to disable interrupt\n");
502
498 /* init cached IRQ enable bits */ 503 /* init cached IRQ enable bits */
499 ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG); 504 ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
500 if (ret < 0) 505 if (ret < 0)
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 15370a2c5ff0..0595c763dafd 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -534,11 +534,11 @@ static void dasd_change_state(struct dasd_device *device)
534 if (rc) 534 if (rc)
535 device->target = device->state; 535 device->target = device->state;
536 536
537 if (device->state == device->target)
538 wake_up(&dasd_init_waitq);
539
540 /* let user-space know that the device status changed */ 537 /* let user-space know that the device status changed */
541 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE); 538 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
539
540 if (device->state == device->target)
541 wake_up(&dasd_init_waitq);
542} 542}
543 543
544/* 544/*
@@ -2157,6 +2157,7 @@ static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2157 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && 2157 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2158 (!dasd_eer_enabled(device))) { 2158 (!dasd_eer_enabled(device))) {
2159 cqr->status = DASD_CQR_FAILED; 2159 cqr->status = DASD_CQR_FAILED;
2160 cqr->intrc = -EAGAIN;
2160 continue; 2161 continue;
2161 } 2162 }
2162 /* Don't try to start requests if device is stopped */ 2163 /* Don't try to start requests if device is stopped */
@@ -3270,6 +3271,16 @@ void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3270 dasd_schedule_device_bh(device); 3271 dasd_schedule_device_bh(device);
3271 } 3272 }
3272 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) { 3273 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3274 if (!(device->path_data.opm & eventlpm) &&
3275 !(device->path_data.tbvpm & eventlpm)) {
3276 /*
3277 * we can not establish a pathgroup on an
3278 * unavailable path, so trigger a path
3279 * verification first
3280 */
3281 device->path_data.tbvpm |= eventlpm;
3282 dasd_schedule_device_bh(device);
3283 }
3273 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 3284 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3274 "Pathgroup re-established\n"); 3285 "Pathgroup re-established\n");
3275 if (device->discipline->kick_validate) 3286 if (device->discipline->kick_validate)
diff --git a/drivers/s390/block/dasd_alias.c b/drivers/s390/block/dasd_alias.c
index 157defe5e069..6b556995bb33 100644
--- a/drivers/s390/block/dasd_alias.c
+++ b/drivers/s390/block/dasd_alias.c
@@ -384,6 +384,29 @@ static void _remove_device_from_lcu(struct alias_lcu *lcu,
384 group->next = NULL; 384 group->next = NULL;
385}; 385};
386 386
387static int
388suborder_not_supported(struct dasd_ccw_req *cqr)
389{
390 char *sense;
391 char reason;
392 char msg_format;
393 char msg_no;
394
395 sense = dasd_get_sense(&cqr->irb);
396 if (!sense)
397 return 0;
398
399 reason = sense[0];
400 msg_format = (sense[7] & 0xF0);
401 msg_no = (sense[7] & 0x0F);
402
403 /* command reject, Format 0 MSG 4 - invalid parameter */
404 if ((reason == 0x80) && (msg_format == 0x00) && (msg_no == 0x04))
405 return 1;
406
407 return 0;
408}
409
387static int read_unit_address_configuration(struct dasd_device *device, 410static int read_unit_address_configuration(struct dasd_device *device,
388 struct alias_lcu *lcu) 411 struct alias_lcu *lcu)
389{ 412{
@@ -435,6 +458,8 @@ static int read_unit_address_configuration(struct dasd_device *device,
435 458
436 do { 459 do {
437 rc = dasd_sleep_on(cqr); 460 rc = dasd_sleep_on(cqr);
461 if (rc && suborder_not_supported(cqr))
462 return -EOPNOTSUPP;
438 } while (rc && (cqr->retries > 0)); 463 } while (rc && (cqr->retries > 0));
439 if (rc) { 464 if (rc) {
440 spin_lock_irqsave(&lcu->lock, flags); 465 spin_lock_irqsave(&lcu->lock, flags);
@@ -521,7 +546,7 @@ static void lcu_update_work(struct work_struct *work)
521 * processing the data 546 * processing the data
522 */ 547 */
523 spin_lock_irqsave(&lcu->lock, flags); 548 spin_lock_irqsave(&lcu->lock, flags);
524 if (rc || (lcu->flags & NEED_UAC_UPDATE)) { 549 if ((rc && (rc != -EOPNOTSUPP)) || (lcu->flags & NEED_UAC_UPDATE)) {
525 DBF_DEV_EVENT(DBF_WARNING, device, "could not update" 550 DBF_DEV_EVENT(DBF_WARNING, device, "could not update"
526 " alias data in lcu (rc = %d), retry later", rc); 551 " alias data in lcu (rc = %d), retry later", rc);
527 schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ); 552 schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ);
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index 2fb2b9ea97ec..c48c72abbefc 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -1507,7 +1507,8 @@ static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1507 * call might change behaviour of DASD devices. 1507 * call might change behaviour of DASD devices.
1508 */ 1508 */
1509static int 1509static int
1510dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav) 1510dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav,
1511 unsigned long flags)
1511{ 1512{
1512 struct dasd_ccw_req *cqr; 1513 struct dasd_ccw_req *cqr;
1513 int rc; 1514 int rc;
@@ -1516,10 +1517,19 @@ dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
1516 if (IS_ERR(cqr)) 1517 if (IS_ERR(cqr))
1517 return PTR_ERR(cqr); 1518 return PTR_ERR(cqr);
1518 1519
1520 /*
1521 * set flags e.g. turn on failfast, to prevent blocking
1522 * the calling function should handle failed requests
1523 */
1524 cqr->flags |= flags;
1525
1519 rc = dasd_sleep_on(cqr); 1526 rc = dasd_sleep_on(cqr);
1520 if (!rc) 1527 if (!rc)
1521 /* trigger CIO to reprobe devices */ 1528 /* trigger CIO to reprobe devices */
1522 css_schedule_reprobe(); 1529 css_schedule_reprobe();
1530 else if (cqr->intrc == -EAGAIN)
1531 rc = -EAGAIN;
1532
1523 dasd_sfree_request(cqr, cqr->memdev); 1533 dasd_sfree_request(cqr, cqr->memdev);
1524 return rc; 1534 return rc;
1525} 1535}
@@ -1527,7 +1537,8 @@ dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
1527/* 1537/*
1528 * Valide storage server of current device. 1538 * Valide storage server of current device.
1529 */ 1539 */
1530static void dasd_eckd_validate_server(struct dasd_device *device) 1540static int dasd_eckd_validate_server(struct dasd_device *device,
1541 unsigned long flags)
1531{ 1542{
1532 int rc; 1543 int rc;
1533 struct dasd_eckd_private *private; 1544 struct dasd_eckd_private *private;
@@ -1536,17 +1547,18 @@ static void dasd_eckd_validate_server(struct dasd_device *device)
1536 private = (struct dasd_eckd_private *) device->private; 1547 private = (struct dasd_eckd_private *) device->private;
1537 if (private->uid.type == UA_BASE_PAV_ALIAS || 1548 if (private->uid.type == UA_BASE_PAV_ALIAS ||
1538 private->uid.type == UA_HYPER_PAV_ALIAS) 1549 private->uid.type == UA_HYPER_PAV_ALIAS)
1539 return; 1550 return 0;
1540 if (dasd_nopav || MACHINE_IS_VM) 1551 if (dasd_nopav || MACHINE_IS_VM)
1541 enable_pav = 0; 1552 enable_pav = 0;
1542 else 1553 else
1543 enable_pav = 1; 1554 enable_pav = 1;
1544 rc = dasd_eckd_psf_ssc(device, enable_pav); 1555 rc = dasd_eckd_psf_ssc(device, enable_pav, flags);
1545 1556
1546 /* may be requested feature is not available on server, 1557 /* may be requested feature is not available on server,
1547 * therefore just report error and go ahead */ 1558 * therefore just report error and go ahead */
1548 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x " 1559 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1549 "returned rc=%d", private->uid.ssid, rc); 1560 "returned rc=%d", private->uid.ssid, rc);
1561 return rc;
1550} 1562}
1551 1563
1552/* 1564/*
@@ -1556,7 +1568,13 @@ static void dasd_eckd_do_validate_server(struct work_struct *work)
1556{ 1568{
1557 struct dasd_device *device = container_of(work, struct dasd_device, 1569 struct dasd_device *device = container_of(work, struct dasd_device,
1558 kick_validate); 1570 kick_validate);
1559 dasd_eckd_validate_server(device); 1571 if (dasd_eckd_validate_server(device, DASD_CQR_FLAGS_FAILFAST)
1572 == -EAGAIN) {
1573 /* schedule worker again if failed */
1574 schedule_work(&device->kick_validate);
1575 return;
1576 }
1577
1560 dasd_put_device(device); 1578 dasd_put_device(device);
1561} 1579}
1562 1580
@@ -1685,7 +1703,7 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
1685 if (rc) 1703 if (rc)
1686 goto out_err2; 1704 goto out_err2;
1687 1705
1688 dasd_eckd_validate_server(device); 1706 dasd_eckd_validate_server(device, 0);
1689 1707
1690 /* device may report different configuration data after LCU setup */ 1708 /* device may report different configuration data after LCU setup */
1691 rc = dasd_eckd_read_conf(device); 1709 rc = dasd_eckd_read_conf(device);
@@ -4153,7 +4171,7 @@ static int dasd_eckd_restore_device(struct dasd_device *device)
4153 rc = dasd_alias_make_device_known_to_lcu(device); 4171 rc = dasd_alias_make_device_known_to_lcu(device);
4154 if (rc) 4172 if (rc)
4155 return rc; 4173 return rc;
4156 dasd_eckd_validate_server(device); 4174 dasd_eckd_validate_server(device, DASD_CQR_FLAGS_FAILFAST);
4157 4175
4158 /* RE-Read Configuration Data */ 4176 /* RE-Read Configuration Data */
4159 rc = dasd_eckd_read_conf(device); 4177 rc = dasd_eckd_read_conf(device);
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index ed25c8740a9c..fc916f5d7314 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1426,6 +1426,8 @@ static enum io_sch_action sch_get_action(struct subchannel *sch)
1426 return IO_SCH_REPROBE; 1426 return IO_SCH_REPROBE;
1427 if (cdev->online) 1427 if (cdev->online)
1428 return IO_SCH_VERIFY; 1428 return IO_SCH_VERIFY;
1429 if (cdev->private->state == DEV_STATE_NOT_OPER)
1430 return IO_SCH_UNREG_ATTACH;
1429 return IO_SCH_NOP; 1431 return IO_SCH_NOP;
1430} 1432}
1431 1433
@@ -1519,11 +1521,14 @@ static int io_subchannel_sch_event(struct subchannel *sch, int process)
1519 goto out; 1521 goto out;
1520 break; 1522 break;
1521 case IO_SCH_UNREG_ATTACH: 1523 case IO_SCH_UNREG_ATTACH:
1524 spin_lock_irqsave(sch->lock, flags);
1522 if (cdev->private->flags.resuming) { 1525 if (cdev->private->flags.resuming) {
1523 /* Device will be handled later. */ 1526 /* Device will be handled later. */
1524 rc = 0; 1527 rc = 0;
1525 goto out; 1528 goto out_unlock;
1526 } 1529 }
1530 sch_set_cdev(sch, NULL);
1531 spin_unlock_irqrestore(sch->lock, flags);
1527 /* Unregister ccw device. */ 1532 /* Unregister ccw device. */
1528 ccw_device_unregister(cdev); 1533 ccw_device_unregister(cdev);
1529 break; 1534 break;
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
index 25417d0e7acb..0bcacf71aef8 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -2888,7 +2888,7 @@ ahd_handle_lqiphase_error(struct ahd_softc *ahd, u_int lqistat1)
2888 ahd_outb(ahd, CLRINT, CLRSCSIINT); 2888 ahd_outb(ahd, CLRINT, CLRSCSIINT);
2889 ahd_unpause(ahd); 2889 ahd_unpause(ahd);
2890 } else { 2890 } else {
2891 printk("Reseting Channel for LQI Phase error\n"); 2891 printk("Resetting Channel for LQI Phase error\n");
2892 ahd_dump_card_state(ahd); 2892 ahd_dump_card_state(ahd);
2893 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE); 2893 ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
2894 } 2894 }
diff --git a/drivers/scsi/bfa/bfa_ioc.c b/drivers/scsi/bfa/bfa_ioc.c
index 8cdb79c2fcdf..21ad2902e5ce 100644
--- a/drivers/scsi/bfa/bfa_ioc.c
+++ b/drivers/scsi/bfa/bfa_ioc.c
@@ -5587,7 +5587,7 @@ static bfa_status_t bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf);
5587static void bfa_dconf_init_cb(void *arg, bfa_status_t status); 5587static void bfa_dconf_init_cb(void *arg, bfa_status_t status);
5588 5588
5589/* 5589/*
5590 * Begining state of dconf module. Waiting for an event to start. 5590 * Beginning state of dconf module. Waiting for an event to start.
5591 */ 5591 */
5592static void 5592static void
5593bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event) 5593bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
index 1a99d4b5b50f..7b916e04ca56 100644
--- a/drivers/scsi/bfa/bfa_ioc.h
+++ b/drivers/scsi/bfa/bfa_ioc.h
@@ -530,7 +530,7 @@ struct bfa_diag_results_fwping {
530 530
531struct bfa_diag_qtest_result_s { 531struct bfa_diag_qtest_result_s {
532 u32 status; 532 u32 status;
533 u16 count; /* sucessful queue test count */ 533 u16 count; /* successful queue test count */
534 u8 queue; 534 u8 queue;
535 u8 rsvd; /* 64-bit align */ 535 u8 rsvd; /* 64-bit align */
536}; 536};
diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index ae1cb7639d99..e0558656c646 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -908,7 +908,7 @@ static void bnx2fc_indicate_netevent(void *context, unsigned long event,
908 return; 908 return;
909 909
910 default: 910 default:
911 printk(KERN_ERR PFX "Unkonwn netevent %ld", event); 911 printk(KERN_ERR PFX "Unknown netevent %ld", event);
912 return; 912 return;
913 } 913 }
914 914
@@ -1738,7 +1738,7 @@ static int bnx2fc_ulp_get_stats(void *handle)
1738/** 1738/**
1739 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance 1739 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1740 * 1740 *
1741 * @handle: transport handle pointing to adapter struture 1741 * @handle: transport handle pointing to adapter structure
1742 * 1742 *
1743 * This function maps adapter structure to pcidev structure and initiates 1743 * This function maps adapter structure to pcidev structure and initiates
1744 * firmware handshake to enable/initialize on-chip FCoE components. 1744 * firmware handshake to enable/initialize on-chip FCoE components.
diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index 33d6630529de..91eec60252ee 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -1264,6 +1264,9 @@ int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1264 int rc = 0; 1264 int rc = 0;
1265 u64 mask64; 1265 u64 mask64;
1266 1266
1267 memset(&iscsi_init, 0x00, sizeof(struct iscsi_kwqe_init1));
1268 memset(&iscsi_init2, 0x00, sizeof(struct iscsi_kwqe_init2));
1269
1267 bnx2i_adjust_qp_size(hba); 1270 bnx2i_adjust_qp_size(hba);
1268 1271
1269 iscsi_init.flags = 1272 iscsi_init.flags =
diff --git a/drivers/scsi/gdth.h b/drivers/scsi/gdth.h
index d3e4d7c6f577..fbf6f0f4b0dd 100644
--- a/drivers/scsi/gdth.h
+++ b/drivers/scsi/gdth.h
@@ -49,15 +49,6 @@
49/* GDT_ISA */ 49/* GDT_ISA */
50#define GDT2_ID 0x0120941c /* GDT2000/2020 */ 50#define GDT2_ID 0x0120941c /* GDT2000/2020 */
51 51
52/* vendor ID, device IDs (PCI) */
53/* these defines should already exist in <linux/pci.h> */
54#ifndef PCI_VENDOR_ID_VORTEX
55#define PCI_VENDOR_ID_VORTEX 0x1119 /* PCI controller vendor ID */
56#endif
57#ifndef PCI_VENDOR_ID_INTEL
58#define PCI_VENDOR_ID_INTEL 0x8086
59#endif
60
61#ifndef PCI_DEVICE_ID_VORTEX_GDT60x0 52#ifndef PCI_DEVICE_ID_VORTEX_GDT60x0
62/* GDT_PCI */ 53/* GDT_PCI */
63#define PCI_DEVICE_ID_VORTEX_GDT60x0 0 /* GDT6000/6020/6050 */ 54#define PCI_DEVICE_ID_VORTEX_GDT60x0 0 /* GDT6000/6020/6050 */
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 796482badf13..2b4261cb7742 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -1315,8 +1315,9 @@ static void complete_scsi_command(struct CommandList *cp)
1315 } 1315 }
1316 break; 1316 break;
1317 case CMD_PROTOCOL_ERR: 1317 case CMD_PROTOCOL_ERR:
1318 cmd->result = DID_ERROR << 16;
1318 dev_warn(&h->pdev->dev, "cp %p has " 1319 dev_warn(&h->pdev->dev, "cp %p has "
1319 "protocol error \n", cp); 1320 "protocol error\n", cp);
1320 break; 1321 break;
1321 case CMD_HARDWARE_ERR: 1322 case CMD_HARDWARE_ERR:
1322 cmd->result = DID_ERROR << 16; 1323 cmd->result = DID_ERROR << 16;
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 467dc38246f9..1059c99690e6 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -192,7 +192,7 @@ static const struct ipr_chip_t ipr_chip[] = {
192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] } 192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
193}; 193};
194 194
195static int ipr_max_bus_speeds [] = { 195static int ipr_max_bus_speeds[] = {
196 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE 196 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
197}; 197};
198 198
@@ -562,7 +562,7 @@ static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
562 trace_entry->u.add_data = add_data; 562 trace_entry->u.add_data = add_data;
563} 563}
564#else 564#else
565#define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0) 565#define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
566#endif 566#endif
567 567
568/** 568/**
@@ -1002,7 +1002,7 @@ static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1002 **/ 1002 **/
1003static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto) 1003static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
1004{ 1004{
1005 switch(proto) { 1005 switch (proto) {
1006 case IPR_PROTO_SATA: 1006 case IPR_PROTO_SATA:
1007 case IPR_PROTO_SAS_STP: 1007 case IPR_PROTO_SAS_STP:
1008 res->ata_class = ATA_DEV_ATA; 1008 res->ata_class = ATA_DEV_ATA;
@@ -3043,7 +3043,7 @@ static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
3043} 3043}
3044 3044
3045#else 3045#else
3046#define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0) 3046#define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
3047#endif 3047#endif
3048 3048
3049/** 3049/**
@@ -3055,7 +3055,7 @@ static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
3055 **/ 3055 **/
3056static void ipr_release_dump(struct kref *kref) 3056static void ipr_release_dump(struct kref *kref)
3057{ 3057{
3058 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref); 3058 struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
3059 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg; 3059 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3060 unsigned long lock_flags = 0; 3060 unsigned long lock_flags = 0;
3061 int i; 3061 int i;
@@ -3142,7 +3142,7 @@ restart:
3142 break; 3142 break;
3143 } 3143 }
3144 } 3144 }
3145 } while(did_work); 3145 } while (did_work);
3146 3146
3147 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) { 3147 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3148 if (res->add_to_ml) { 3148 if (res->add_to_ml) {
@@ -3268,7 +3268,7 @@ static ssize_t ipr_show_log_level(struct device *dev,
3268 * number of bytes printed to buffer 3268 * number of bytes printed to buffer
3269 **/ 3269 **/
3270static ssize_t ipr_store_log_level(struct device *dev, 3270static ssize_t ipr_store_log_level(struct device *dev,
3271 struct device_attribute *attr, 3271 struct device_attribute *attr,
3272 const char *buf, size_t count) 3272 const char *buf, size_t count)
3273{ 3273{
3274 struct Scsi_Host *shost = class_to_shost(dev); 3274 struct Scsi_Host *shost = class_to_shost(dev);
@@ -3315,7 +3315,7 @@ static ssize_t ipr_store_diagnostics(struct device *dev,
3315 return -EACCES; 3315 return -EACCES;
3316 3316
3317 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3317 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3318 while(ioa_cfg->in_reset_reload) { 3318 while (ioa_cfg->in_reset_reload) {
3319 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3319 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3320 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 3320 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3321 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3321 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
@@ -3682,7 +3682,7 @@ static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3682 unsigned long lock_flags; 3682 unsigned long lock_flags;
3683 3683
3684 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3684 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3685 while(ioa_cfg->in_reset_reload) { 3685 while (ioa_cfg->in_reset_reload) {
3686 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3686 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3687 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 3687 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3688 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3688 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
@@ -3746,7 +3746,7 @@ static ssize_t ipr_store_update_fw(struct device *dev,
3746 len = snprintf(fname, 99, "%s", buf); 3746 len = snprintf(fname, 99, "%s", buf);
3747 fname[len-1] = '\0'; 3747 fname[len-1] = '\0';
3748 3748
3749 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) { 3749 if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3750 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname); 3750 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3751 return -EIO; 3751 return -EIO;
3752 } 3752 }
@@ -4612,7 +4612,7 @@ static int ipr_slave_alloc(struct scsi_device *sdev)
4612 * Return value: 4612 * Return value:
4613 * SUCCESS / FAILED 4613 * SUCCESS / FAILED
4614 **/ 4614 **/
4615static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd) 4615static int __ipr_eh_host_reset(struct scsi_cmnd *scsi_cmd)
4616{ 4616{
4617 struct ipr_ioa_cfg *ioa_cfg; 4617 struct ipr_ioa_cfg *ioa_cfg;
4618 int rc; 4618 int rc;
@@ -4634,7 +4634,7 @@ static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
4634 return rc; 4634 return rc;
4635} 4635}
4636 4636
4637static int ipr_eh_host_reset(struct scsi_cmnd * cmd) 4637static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
4638{ 4638{
4639 int rc; 4639 int rc;
4640 4640
@@ -4701,7 +4701,7 @@ static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4701 } 4701 }
4702 4702
4703 LEAVE; 4703 LEAVE;
4704 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0); 4704 return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
4705} 4705}
4706 4706
4707/** 4707/**
@@ -4725,7 +4725,7 @@ static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
4725 4725
4726 ENTER; 4726 ENTER;
4727 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 4727 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4728 while(ioa_cfg->in_reset_reload) { 4728 while (ioa_cfg->in_reset_reload) {
4729 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 4729 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4730 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 4730 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4731 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 4731 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
@@ -4753,7 +4753,7 @@ static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
4753 * Return value: 4753 * Return value:
4754 * SUCCESS / FAILED 4754 * SUCCESS / FAILED
4755 **/ 4755 **/
4756static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd) 4756static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
4757{ 4757{
4758 struct ipr_cmnd *ipr_cmd; 4758 struct ipr_cmnd *ipr_cmd;
4759 struct ipr_ioa_cfg *ioa_cfg; 4759 struct ipr_ioa_cfg *ioa_cfg;
@@ -4811,10 +4811,10 @@ static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
4811 res->resetting_device = 0; 4811 res->resetting_device = 0;
4812 4812
4813 LEAVE; 4813 LEAVE;
4814 return (rc ? FAILED : SUCCESS); 4814 return rc ? FAILED : SUCCESS;
4815} 4815}
4816 4816
4817static int ipr_eh_dev_reset(struct scsi_cmnd * cmd) 4817static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
4818{ 4818{
4819 int rc; 4819 int rc;
4820 4820
@@ -4910,7 +4910,7 @@ static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
4910 * Return value: 4910 * Return value:
4911 * SUCCESS / FAILED 4911 * SUCCESS / FAILED
4912 **/ 4912 **/
4913static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd) 4913static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
4914{ 4914{
4915 struct ipr_cmnd *ipr_cmd; 4915 struct ipr_cmnd *ipr_cmd;
4916 struct ipr_ioa_cfg *ioa_cfg; 4916 struct ipr_ioa_cfg *ioa_cfg;
@@ -4979,7 +4979,7 @@ static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
4979 res->needs_sync_complete = 1; 4979 res->needs_sync_complete = 1;
4980 4980
4981 LEAVE; 4981 LEAVE;
4982 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS); 4982 return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
4983} 4983}
4984 4984
4985/** 4985/**
@@ -4989,7 +4989,7 @@ static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
4989 * Return value: 4989 * Return value:
4990 * SUCCESS / FAILED 4990 * SUCCESS / FAILED
4991 **/ 4991 **/
4992static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd) 4992static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
4993{ 4993{
4994 unsigned long flags; 4994 unsigned long flags;
4995 int rc; 4995 int rc;
@@ -5907,7 +5907,7 @@ static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
5907 * Return value: 5907 * Return value:
5908 * pointer to buffer with description string 5908 * pointer to buffer with description string
5909 **/ 5909 **/
5910static const char * ipr_ioa_info(struct Scsi_Host *host) 5910static const char *ipr_ioa_info(struct Scsi_Host *host)
5911{ 5911{
5912 static char buffer[512]; 5912 static char buffer[512];
5913 struct ipr_ioa_cfg *ioa_cfg; 5913 struct ipr_ioa_cfg *ioa_cfg;
@@ -5965,7 +5965,7 @@ static void ipr_ata_phy_reset(struct ata_port *ap)
5965 5965
5966 ENTER; 5966 ENTER;
5967 spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 5967 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5968 while(ioa_cfg->in_reset_reload) { 5968 while (ioa_cfg->in_reset_reload) {
5969 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags); 5969 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5970 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 5970 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5971 spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 5971 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
@@ -6005,7 +6005,7 @@ static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6005 unsigned long flags; 6005 unsigned long flags;
6006 6006
6007 spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 6007 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6008 while(ioa_cfg->in_reset_reload) { 6008 while (ioa_cfg->in_reset_reload) {
6009 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags); 6009 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6010 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 6010 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6011 spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 6011 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
@@ -6330,7 +6330,7 @@ static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6330 int i; 6330 int i;
6331 6331
6332 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) { 6332 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
6333 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){ 6333 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
6334 if (__is_processor(ipr_blocked_processors[i])) 6334 if (__is_processor(ipr_blocked_processors[i]))
6335 return 1; 6335 return 1;
6336 } 6336 }
@@ -6608,7 +6608,7 @@ static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
6608 * none 6608 * none
6609 **/ 6609 **/
6610static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg, 6610static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
6611 struct ipr_mode_pages *mode_pages) 6611 struct ipr_mode_pages *mode_pages)
6612{ 6612{
6613 int i, entry_length; 6613 int i, entry_length;
6614 struct ipr_dev_bus_entry *bus; 6614 struct ipr_dev_bus_entry *bus;
@@ -8022,7 +8022,7 @@ static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8022 ipr_reinit_ipr_cmnd(ipr_cmd); 8022 ipr_reinit_ipr_cmnd(ipr_cmd);
8023 ipr_cmd->job_step_failed = ipr_reset_cmd_failed; 8023 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
8024 rc = ipr_cmd->job_step(ipr_cmd); 8024 rc = ipr_cmd->job_step(ipr_cmd);
8025 } while(rc == IPR_RC_JOB_CONTINUE); 8025 } while (rc == IPR_RC_JOB_CONTINUE);
8026} 8026}
8027 8027
8028/** 8028/**
@@ -8283,7 +8283,7 @@ static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8283 } 8283 }
8284 8284
8285 if (ioa_cfg->ipr_cmd_pool) 8285 if (ioa_cfg->ipr_cmd_pool)
8286 pci_pool_destroy (ioa_cfg->ipr_cmd_pool); 8286 pci_pool_destroy(ioa_cfg->ipr_cmd_pool);
8287 8287
8288 kfree(ioa_cfg->ipr_cmnd_list); 8288 kfree(ioa_cfg->ipr_cmnd_list);
8289 kfree(ioa_cfg->ipr_cmnd_list_dma); 8289 kfree(ioa_cfg->ipr_cmnd_list_dma);
@@ -8363,8 +8363,8 @@ static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8363 dma_addr_t dma_addr; 8363 dma_addr_t dma_addr;
8364 int i; 8364 int i;
8365 8365
8366 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev, 8366 ioa_cfg->ipr_cmd_pool = pci_pool_create(IPR_NAME, ioa_cfg->pdev,
8367 sizeof(struct ipr_cmnd), 512, 0); 8367 sizeof(struct ipr_cmnd), 512, 0);
8368 8368
8369 if (!ioa_cfg->ipr_cmd_pool) 8369 if (!ioa_cfg->ipr_cmd_pool)
8370 return -ENOMEM; 8370 return -ENOMEM;
@@ -8378,7 +8378,7 @@ static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8378 } 8378 }
8379 8379
8380 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) { 8380 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8381 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr); 8381 ipr_cmd = pci_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
8382 8382
8383 if (!ipr_cmd) { 8383 if (!ipr_cmd) {
8384 ipr_free_cmd_blks(ioa_cfg); 8384 ipr_free_cmd_blks(ioa_cfg);
@@ -8964,7 +8964,7 @@ static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
8964 int target, lun; 8964 int target, lun;
8965 8965
8966 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++) 8966 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
8967 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ ) 8967 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++)
8968 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun); 8968 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
8969} 8969}
8970 8970
@@ -9010,7 +9010,7 @@ static void __ipr_remove(struct pci_dev *pdev)
9010 ENTER; 9010 ENTER;
9011 9011
9012 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags); 9012 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9013 while(ioa_cfg->in_reset_reload) { 9013 while (ioa_cfg->in_reset_reload) {
9014 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags); 9014 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9015 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 9015 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9016 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags); 9016 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
@@ -9139,7 +9139,7 @@ static void ipr_shutdown(struct pci_dev *pdev)
9139 unsigned long lock_flags = 0; 9139 unsigned long lock_flags = 0;
9140 9140
9141 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 9141 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9142 while(ioa_cfg->in_reset_reload) { 9142 while (ioa_cfg->in_reset_reload) {
9143 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 9143 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9144 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 9144 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9145 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 9145 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
diff --git a/drivers/scsi/isci/host.c b/drivers/scsi/isci/host.c
index 45385f531649..b334fdc1726a 100644
--- a/drivers/scsi/isci/host.c
+++ b/drivers/scsi/isci/host.c
@@ -492,7 +492,7 @@ static void sci_controller_process_completions(struct isci_host *ihost)
492 u32 event_cycle; 492 u32 event_cycle;
493 493
494 dev_dbg(&ihost->pdev->dev, 494 dev_dbg(&ihost->pdev->dev,
495 "%s: completion queue begining get:0x%08x\n", 495 "%s: completion queue beginning get:0x%08x\n",
496 __func__, 496 __func__,
497 ihost->completion_queue_get); 497 ihost->completion_queue_get);
498 498
diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index 92c1d86d1fc6..9be45a2b2232 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -222,7 +222,7 @@ static struct sas_domain_function_template isci_transport_ops = {
222 * @isci_host: This parameter specifies the lldd specific wrapper for the 222 * @isci_host: This parameter specifies the lldd specific wrapper for the
223 * libsas sas_ha struct. 223 * libsas sas_ha struct.
224 * 224 *
225 * This method returns an error code indicating sucess or failure. The user 225 * This method returns an error code indicating success or failure. The user
226 * should check for possible memory allocation error return otherwise, a zero 226 * should check for possible memory allocation error return otherwise, a zero
227 * indicates success. 227 * indicates success.
228 */ 228 */
diff --git a/drivers/scsi/isci/port.c b/drivers/scsi/isci/port.c
index 2fb85bf75449..13098b09a824 100644
--- a/drivers/scsi/isci/port.c
+++ b/drivers/scsi/isci/port.c
@@ -212,7 +212,7 @@ static void isci_port_link_up(struct isci_host *isci_host,
212 memcpy(iphy->sas_phy.attached_sas_addr, 212 memcpy(iphy->sas_phy.attached_sas_addr,
213 iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE); 213 iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
214 } else { 214 } else {
215 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__); 215 dev_err(&isci_host->pdev->dev, "%s: unknown target\n", __func__);
216 success = false; 216 success = false;
217 } 217 }
218 218
diff --git a/drivers/scsi/isci/request.c b/drivers/scsi/isci/request.c
index 7a0431c73493..c1bafc3f3fb1 100644
--- a/drivers/scsi/isci/request.c
+++ b/drivers/scsi/isci/request.c
@@ -2240,7 +2240,7 @@ static enum sci_status atapi_data_tc_completion_handler(struct isci_request *ire
2240 status = ireq->sci_status; 2240 status = ireq->sci_status;
2241 sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR); 2241 sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR);
2242 } else { 2242 } else {
2243 /* If receiving any non-sucess TC status, no UF 2243 /* If receiving any non-success TC status, no UF
2244 * received yet, then an UF for the status fis 2244 * received yet, then an UF for the status fis
2245 * is coming after (XXX: suspect this is 2245 * is coming after (XXX: suspect this is
2246 * actually a protocol error or a bug like the 2246 * actually a protocol error or a bug like the
diff --git a/drivers/scsi/isci/task.c b/drivers/scsi/isci/task.c
index 6bc74eb012c9..b6f19a1db780 100644
--- a/drivers/scsi/isci/task.c
+++ b/drivers/scsi/isci/task.c
@@ -532,7 +532,7 @@ int isci_task_abort_task(struct sas_task *task)
532 /* The request has already completed and there 532 /* The request has already completed and there
533 * is nothing to do here other than to set the task 533 * is nothing to do here other than to set the task
534 * done bit, and indicate that the task abort function 534 * done bit, and indicate that the task abort function
535 * was sucessful. 535 * was successful.
536 */ 536 */
537 spin_lock_irqsave(&task->task_state_lock, flags); 537 spin_lock_irqsave(&task->task_state_lock, flags);
538 task->task_state_flags |= SAS_TASK_STATE_DONE; 538 task->task_state_flags |= SAS_TASK_STATE_DONE;
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 45c15208be9f..29937b606c84 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -6607,7 +6607,7 @@ out_error:
6607 * we just use some constant number as place holder. 6607 * we just use some constant number as place holder.
6608 * 6608 *
6609 * Return codes 6609 * Return codes
6610 * 0 - sucessful 6610 * 0 - successful
6611 * -ENOMEM - No availble memory 6611 * -ENOMEM - No availble memory
6612 * -EIO - The mailbox failed to complete successfully. 6612 * -EIO - The mailbox failed to complete successfully.
6613 **/ 6613 **/
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 9cbd20b1328b..0e7e144507b2 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -4739,7 +4739,7 @@ lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
4739 * is attached to. 4739 * is attached to.
4740 * 4740 *
4741 * Return codes 4741 * Return codes
4742 * 0 - sucessful 4742 * 0 - successful
4743 * otherwise - failed to retrieve physical port name 4743 * otherwise - failed to retrieve physical port name
4744 **/ 4744 **/
4745static int 4745static int
@@ -15209,7 +15209,7 @@ lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
15209 /* 15209 /*
15210 * if next_fcf_pri was not set above and the list is not empty then 15210 * if next_fcf_pri was not set above and the list is not empty then
15211 * we have failed flogis on all of them. So reset flogi failed 15211 * we have failed flogis on all of them. So reset flogi failed
15212 * and start at the begining. 15212 * and start at the beginning.
15213 */ 15213 */
15214 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { 15214 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
15215 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { 15215 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 97825f116954..76ad72d32c3f 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -305,12 +305,11 @@ mega_query_adapter(adapter_t *adapter)
305 305
306 adapter->host->sg_tablesize = adapter->sglen; 306 adapter->host->sg_tablesize = adapter->sglen;
307 307
308
309 /* use HP firmware and bios version encoding 308 /* use HP firmware and bios version encoding
310 Note: fw_version[0|1] and bios_version[0|1] were originally shifted 309 Note: fw_version[0|1] and bios_version[0|1] were originally shifted
311 right 8 bits making them zero. This 0 value was hardcoded to fix 310 right 8 bits making them zero. This 0 value was hardcoded to fix
312 sparse warnings. */ 311 sparse warnings. */
313 if (adapter->product_info.subsysvid == HP_SUBSYS_VID) { 312 if (adapter->product_info.subsysvid == PCI_VENDOR_ID_HP) {
314 sprintf (adapter->fw_version, "%c%d%d.%d%d", 313 sprintf (adapter->fw_version, "%c%d%d.%d%d",
315 adapter->product_info.fw_version[2], 314 adapter->product_info.fw_version[2],
316 0, 315 0,
@@ -4716,7 +4715,7 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4716 * support, since this firmware cannot handle 64 bit 4715 * support, since this firmware cannot handle 64 bit
4717 * addressing 4716 * addressing
4718 */ 4717 */
4719 if ((subsysvid == HP_SUBSYS_VID) && 4718 if ((subsysvid == PCI_VENDOR_ID_HP) &&
4720 ((subsysid == 0x60E7) || (subsysid == 0x60E8))) { 4719 ((subsysid == 0x60E7) || (subsysid == 0x60E8))) {
4721 /* 4720 /*
4722 * which firmware 4721 * which firmware
diff --git a/drivers/scsi/megaraid.h b/drivers/scsi/megaraid.h
index 9a7897f8ca43..4fb2adf6b80d 100644
--- a/drivers/scsi/megaraid.h
+++ b/drivers/scsi/megaraid.h
@@ -45,45 +45,10 @@
45 45
46#define MAX_DEV_TYPE 32 46#define MAX_DEV_TYPE 32
47 47
48#ifndef PCI_VENDOR_ID_LSI_LOGIC
49#define PCI_VENDOR_ID_LSI_LOGIC 0x1000
50#endif
51
52#ifndef PCI_VENDOR_ID_AMI
53#define PCI_VENDOR_ID_AMI 0x101E
54#endif
55
56#ifndef PCI_VENDOR_ID_DELL
57#define PCI_VENDOR_ID_DELL 0x1028
58#endif
59
60#ifndef PCI_VENDOR_ID_INTEL
61#define PCI_VENDOR_ID_INTEL 0x8086
62#endif
63
64#ifndef PCI_DEVICE_ID_AMI_MEGARAID
65#define PCI_DEVICE_ID_AMI_MEGARAID 0x9010
66#endif
67
68#ifndef PCI_DEVICE_ID_AMI_MEGARAID2
69#define PCI_DEVICE_ID_AMI_MEGARAID2 0x9060
70#endif
71
72#ifndef PCI_DEVICE_ID_AMI_MEGARAID3
73#define PCI_DEVICE_ID_AMI_MEGARAID3 0x1960
74#endif
75
76#define PCI_DEVICE_ID_DISCOVERY 0x000E 48#define PCI_DEVICE_ID_DISCOVERY 0x000E
77#define PCI_DEVICE_ID_PERC4_DI 0x000F 49#define PCI_DEVICE_ID_PERC4_DI 0x000F
78#define PCI_DEVICE_ID_PERC4_QC_VERDE 0x0407 50#define PCI_DEVICE_ID_PERC4_QC_VERDE 0x0407
79 51
80/* Sub-System Vendor IDs */
81#define AMI_SUBSYS_VID 0x101E
82#define DELL_SUBSYS_VID 0x1028
83#define HP_SUBSYS_VID 0x103C
84#define LSI_SUBSYS_VID 0x1000
85#define INTEL_SUBSYS_VID 0x8086
86
87#define HBA_SIGNATURE 0x3344 52#define HBA_SIGNATURE 0x3344
88#define HBA_SIGNATURE_471 0xCCCC 53#define HBA_SIGNATURE_471 0xCCCC
89#define HBA_SIGNATURE_64BIT 0x0299 54#define HBA_SIGNATURE_64BIT 0x0299
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index dc27598785e5..ed38454228c6 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -4066,7 +4066,6 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4066 spin_lock_init(&instance->cmd_pool_lock); 4066 spin_lock_init(&instance->cmd_pool_lock);
4067 spin_lock_init(&instance->hba_lock); 4067 spin_lock_init(&instance->hba_lock);
4068 spin_lock_init(&instance->completion_lock); 4068 spin_lock_init(&instance->completion_lock);
4069 spin_lock_init(&poll_aen_lock);
4070 4069
4071 mutex_init(&instance->aen_mutex); 4070 mutex_init(&instance->aen_mutex);
4072 mutex_init(&instance->reset_mutex); 4071 mutex_init(&instance->reset_mutex);
@@ -5392,6 +5391,8 @@ static int __init megasas_init(void)
5392 printk(KERN_INFO "megasas: %s %s\n", MEGASAS_VERSION, 5391 printk(KERN_INFO "megasas: %s %s\n", MEGASAS_VERSION,
5393 MEGASAS_EXT_VERSION); 5392 MEGASAS_EXT_VERSION);
5394 5393
5394 spin_lock_init(&poll_aen_lock);
5395
5395 support_poll_for_event = 2; 5396 support_poll_for_event = 2;
5396 support_device_change = 1; 5397 support_device_change = 1;
5397 5398
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c b/drivers/scsi/mpt2sas/mpt2sas_base.c
index 9d46fcbe7755..9d5a56c4b332 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
@@ -1209,6 +1209,13 @@ _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1209 u16 message_control; 1209 u16 message_control;
1210 1210
1211 1211
1212 /* Check whether controller SAS2008 B0 controller,
1213 if it is SAS2008 B0 controller use IO-APIC instead of MSIX */
1214 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 &&
1215 ioc->pdev->revision == 0x01) {
1216 return -EINVAL;
1217 }
1218
1212 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX); 1219 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
1213 if (!base) { 1220 if (!base) {
1214 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not " 1221 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
@@ -2424,10 +2431,13 @@ _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2424 } 2431 }
2425 2432
2426 /* command line tunables for max controller queue depth */ 2433 /* command line tunables for max controller queue depth */
2427 if (max_queue_depth != -1) 2434 if (max_queue_depth != -1 && max_queue_depth != 0) {
2428 max_request_credit = (max_queue_depth < facts->RequestCredit) 2435 max_request_credit = min_t(u16, max_queue_depth +
2429 ? max_queue_depth : facts->RequestCredit; 2436 ioc->hi_priority_depth + ioc->internal_depth,
2430 else 2437 facts->RequestCredit);
2438 if (max_request_credit > MAX_HBA_QUEUE_DEPTH)
2439 max_request_credit = MAX_HBA_QUEUE_DEPTH;
2440 } else
2431 max_request_credit = min_t(u16, facts->RequestCredit, 2441 max_request_credit = min_t(u16, facts->RequestCredit,
2432 MAX_HBA_QUEUE_DEPTH); 2442 MAX_HBA_QUEUE_DEPTH);
2433 2443
@@ -2502,7 +2512,7 @@ _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2502 /* set the scsi host can_queue depth 2512 /* set the scsi host can_queue depth
2503 * with some internal commands that could be outstanding 2513 * with some internal commands that could be outstanding
2504 */ 2514 */
2505 ioc->shost->can_queue = ioc->scsiio_depth - (2); 2515 ioc->shost->can_queue = ioc->scsiio_depth;
2506 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: " 2516 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
2507 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue)); 2517 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
2508 2518
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 88cf1db21a79..783edc7c6b98 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -122,7 +122,7 @@ static struct mvumi_res *mvumi_alloc_mem_resource(struct mvumi_hba *mhba,
122 122
123 if (!res) { 123 if (!res) {
124 dev_err(&mhba->pdev->dev, 124 dev_err(&mhba->pdev->dev,
125 "Failed to allocate memory for resouce manager.\n"); 125 "Failed to allocate memory for resource manager.\n");
126 return NULL; 126 return NULL;
127 } 127 }
128 128
@@ -1007,13 +1007,13 @@ static int mvumi_handshake(struct mvumi_hba *mhba)
1007 tmp |= INT_MAP_COMAOUT | INT_MAP_COMAERR; 1007 tmp |= INT_MAP_COMAOUT | INT_MAP_COMAERR;
1008 iowrite32(tmp, regs + CPU_ENPOINTA_MASK_REG); 1008 iowrite32(tmp, regs + CPU_ENPOINTA_MASK_REG);
1009 iowrite32(mhba->list_num_io, mhba->ib_shadow); 1009 iowrite32(mhba->list_num_io, mhba->ib_shadow);
1010 /* Set InBound List Avaliable count shadow */ 1010 /* Set InBound List Available count shadow */
1011 iowrite32(lower_32_bits(mhba->ib_shadow_phys), 1011 iowrite32(lower_32_bits(mhba->ib_shadow_phys),
1012 regs + CLA_INB_AVAL_COUNT_BASEL); 1012 regs + CLA_INB_AVAL_COUNT_BASEL);
1013 iowrite32(upper_32_bits(mhba->ib_shadow_phys), 1013 iowrite32(upper_32_bits(mhba->ib_shadow_phys),
1014 regs + CLA_INB_AVAL_COUNT_BASEH); 1014 regs + CLA_INB_AVAL_COUNT_BASEH);
1015 1015
1016 /* Set OutBound List Avaliable count shadow */ 1016 /* Set OutBound List Available count shadow */
1017 iowrite32((mhba->list_num_io-1) | CL_POINTER_TOGGLE, 1017 iowrite32((mhba->list_num_io-1) | CL_POINTER_TOGGLE,
1018 mhba->ob_shadow); 1018 mhba->ob_shadow);
1019 iowrite32(lower_32_bits(mhba->ob_shadow_phys), regs + 0x5B0); 1019 iowrite32(lower_32_bits(mhba->ob_shadow_phys), regs + 0x5B0);
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 9da426628b97..487e3c8411c9 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -803,7 +803,7 @@ static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
803 iscsi_stats_dma); 803 iscsi_stats_dma);
804 if (ret != QLA_SUCCESS) { 804 if (ret != QLA_SUCCESS) {
805 ql4_printk(KERN_ERR, ha, 805 ql4_printk(KERN_ERR, ha,
806 "Unable to retreive iscsi stats\n"); 806 "Unable to retrieve iscsi stats\n");
807 goto free_stats; 807 goto free_stats;
808 } 808 }
809 809
@@ -4338,7 +4338,7 @@ static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
4338 return QLA_ERROR; 4338 return QLA_ERROR;
4339 4339
4340 /* For multi sessions, driver generates the ISID, so do not compare 4340 /* For multi sessions, driver generates the ISID, so do not compare
4341 * ISID in reset path since it would be a comparision between the 4341 * ISID in reset path since it would be a comparison between the
4342 * driver generated ISID and firmware generated ISID. This could 4342 * driver generated ISID and firmware generated ISID. This could
4343 * lead to adding duplicated DDBs in the list as driver generated 4343 * lead to adding duplicated DDBs in the list as driver generated
4344 * ISID would not match firmware generated ISID. 4344 * ISID would not match firmware generated ISID.
@@ -5326,7 +5326,7 @@ static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
5326 } 5326 }
5327} 5327}
5328/** 5328/**
5329 * qla4xxx_remove_adapter - calback function to remove adapter. 5329 * qla4xxx_remove_adapter - callback function to remove adapter.
5330 * @pci_dev: PCI device pointer 5330 * @pci_dev: PCI device pointer
5331 **/ 5331 **/
5332static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev) 5332static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 4a6381c87253..de2337f255a7 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -42,6 +42,8 @@
42 42
43#include <trace/events/scsi.h> 43#include <trace/events/scsi.h>
44 44
45static void scsi_eh_done(struct scsi_cmnd *scmd);
46
45#define SENSE_TIMEOUT (10*HZ) 47#define SENSE_TIMEOUT (10*HZ)
46 48
47/* 49/*
@@ -241,6 +243,14 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
241 if (! scsi_command_normalize_sense(scmd, &sshdr)) 243 if (! scsi_command_normalize_sense(scmd, &sshdr))
242 return FAILED; /* no valid sense data */ 244 return FAILED; /* no valid sense data */
243 245
246 if (scmd->cmnd[0] == TEST_UNIT_READY && scmd->scsi_done != scsi_eh_done)
247 /*
248 * nasty: for mid-layer issued TURs, we need to return the
249 * actual sense data without any recovery attempt. For eh
250 * issued ones, we need to try to recover and interpret
251 */
252 return SUCCESS;
253
244 if (scsi_sense_is_deferred(&sshdr)) 254 if (scsi_sense_is_deferred(&sshdr))
245 return NEEDS_RETRY; 255 return NEEDS_RETRY;
246 256
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ffd77739ae3e..faa790fba134 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -776,7 +776,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
776 } 776 }
777 777
778 if (req->cmd_type == REQ_TYPE_BLOCK_PC) { /* SG_IO ioctl from block level */ 778 if (req->cmd_type == REQ_TYPE_BLOCK_PC) { /* SG_IO ioctl from block level */
779 req->errors = result;
780 if (result) { 779 if (result) {
781 if (sense_valid && req->sense) { 780 if (sense_valid && req->sense) {
782 /* 781 /*
@@ -792,6 +791,10 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
792 if (!sense_deferred) 791 if (!sense_deferred)
793 error = __scsi_error_from_host_byte(cmd, result); 792 error = __scsi_error_from_host_byte(cmd, result);
794 } 793 }
794 /*
795 * __scsi_error_from_host_byte may have reset the host_byte
796 */
797 req->errors = cmd->result;
795 798
796 req->resid_len = scsi_get_resid(cmd); 799 req->resid_len = scsi_get_resid(cmd);
797 800
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 56a93794c470..d947ffc20ceb 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -764,6 +764,16 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
764 sdev->model = (char *) (sdev->inquiry + 16); 764 sdev->model = (char *) (sdev->inquiry + 16);
765 sdev->rev = (char *) (sdev->inquiry + 32); 765 sdev->rev = (char *) (sdev->inquiry + 32);
766 766
767 if (strncmp(sdev->vendor, "ATA ", 8) == 0) {
768 /*
769 * sata emulation layer device. This is a hack to work around
770 * the SATL power management specifications which state that
771 * when the SATL detects the device has gone into standby
772 * mode, it shall respond with NOT READY.
773 */
774 sdev->allow_restart = 1;
775 }
776
767 if (*bflags & BLIST_ISROM) { 777 if (*bflags & BLIST_ISROM) {
768 sdev->type = TYPE_ROM; 778 sdev->type = TYPE_ROM;
769 sdev->removable = 1; 779 sdev->removable = 1;
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index c7030fbee79c..3e79a2f00042 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -331,7 +331,7 @@ static void virtscsi_map_sgl(struct scatterlist *sg, unsigned int *p_idx,
331 int i; 331 int i;
332 332
333 for_each_sg(table->sgl, sg_elem, table->nents, i) 333 for_each_sg(table->sgl, sg_elem, table->nents, i)
334 sg_set_buf(&sg[idx++], sg_virt(sg_elem), sg_elem->length); 334 sg[idx++] = *sg_elem;
335 335
336 *p_idx = idx; 336 *p_idx = idx;
337} 337}
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 4411d4224401..20b3a483c2cc 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -295,7 +295,7 @@ static void ll_adapter_reset(const struct pvscsi_adapter *adapter)
295 295
296static void ll_bus_reset(const struct pvscsi_adapter *adapter) 296static void ll_bus_reset(const struct pvscsi_adapter *adapter)
297{ 297{
298 dev_dbg(pvscsi_dev(adapter), "Reseting bus on %p\n", adapter); 298 dev_dbg(pvscsi_dev(adapter), "Resetting bus on %p\n", adapter);
299 299
300 pvscsi_write_cmd_desc(adapter, PVSCSI_CMD_RESET_BUS, NULL, 0); 300 pvscsi_write_cmd_desc(adapter, PVSCSI_CMD_RESET_BUS, NULL, 0);
301} 301}
@@ -304,7 +304,7 @@ static void ll_device_reset(const struct pvscsi_adapter *adapter, u32 target)
304{ 304{
305 struct PVSCSICmdDescResetDevice cmd = { 0 }; 305 struct PVSCSICmdDescResetDevice cmd = { 0 };
306 306
307 dev_dbg(pvscsi_dev(adapter), "Reseting device: target=%u\n", target); 307 dev_dbg(pvscsi_dev(adapter), "Resetting device: target=%u\n", target);
308 308
309 cmd.target = target; 309 cmd.target = target;
310 310
diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c
index 32c26d795ed0..8f32a1323a79 100644
--- a/drivers/sh/intc/core.c
+++ b/drivers/sh/intc/core.c
@@ -355,7 +355,7 @@ int __init register_intc_controller(struct intc_desc *desc)
355 if (unlikely(res)) { 355 if (unlikely(res)) {
356 if (res == -EEXIST) { 356 if (res == -EEXIST) {
357 res = irq_domain_associate(d->domain, 357 res = irq_domain_associate(d->domain,
358 irq, irq); 358 irq2, irq2);
359 if (unlikely(res)) { 359 if (unlikely(res)) {
360 pr_err("domain association " 360 pr_err("domain association "
361 "failure\n"); 361 "failure\n");
diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c
index 2804eaae804e..0646bf6e7889 100644
--- a/drivers/sh/pfc/pinctrl.c
+++ b/drivers/sh/pfc/pinctrl.c
@@ -208,10 +208,13 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
208 208
209 break; 209 break;
210 case PINMUX_TYPE_GPIO: 210 case PINMUX_TYPE_GPIO:
211 case PINMUX_TYPE_INPUT:
212 case PINMUX_TYPE_OUTPUT:
211 break; 213 break;
212 default: 214 default:
213 pr_err("Unsupported mux type (%d), bailing...\n", pinmux_type); 215 pr_err("Unsupported mux type (%d), bailing...\n", pinmux_type);
214 return -ENOTSUPP; 216 ret = -ENOTSUPP;
217 goto err;
215 } 218 }
216 219
217 ret = 0; 220 ret = 0;
diff --git a/drivers/spi/spi-au1550.c b/drivers/spi/spi-au1550.c
index 5784c8799616..4de66d1cfe51 100644
--- a/drivers/spi/spi-au1550.c
+++ b/drivers/spi/spi-au1550.c
@@ -475,7 +475,7 @@ static irqreturn_t au1550_spi_dma_irq_callback(struct au1550_spi *hw)
475 /* 475 /*
476 * due to an spi error we consider transfer as done, 476 * due to an spi error we consider transfer as done,
477 * so mask all events until before next transfer start 477 * so mask all events until before next transfer start
478 * and stop the possibly running dma immediatelly 478 * and stop the possibly running dma immediately
479 */ 479 */
480 au1550_spi_mask_ack_all(hw); 480 au1550_spi_mask_ack_all(hw);
481 au1xxx_dbdma_stop(hw->dma_rx_ch); 481 au1xxx_dbdma_stop(hw->dma_rx_ch);
diff --git a/drivers/spi/spi-bfin-sport.c b/drivers/spi/spi-bfin-sport.c
index 1fe51198a622..6555ecd07302 100644
--- a/drivers/spi/spi-bfin-sport.c
+++ b/drivers/spi/spi-bfin-sport.c
@@ -467,7 +467,7 @@ bfin_sport_spi_pump_transfers(unsigned long data)
467 dev_dbg(drv_data->dev, "IO write error!\n"); 467 dev_dbg(drv_data->dev, "IO write error!\n");
468 drv_data->state = ERROR_STATE; 468 drv_data->state = ERROR_STATE;
469 } else { 469 } else {
470 /* Update total byte transfered */ 470 /* Update total byte transferred */
471 message->actual_length += transfer->len; 471 message->actual_length += transfer->len;
472 /* Move to next transfer of this msg */ 472 /* Move to next transfer of this msg */
473 drv_data->state = bfin_sport_spi_next_transfer(drv_data); 473 drv_data->state = bfin_sport_spi_next_transfer(drv_data);
diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c
index 698018fd992b..9d9071b730be 100644
--- a/drivers/spi/spi-oc-tiny.c
+++ b/drivers/spi/spi-oc-tiny.c
@@ -129,7 +129,7 @@ static int tiny_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
129 unsigned int i; 129 unsigned int i;
130 130
131 if (hw->irq >= 0) { 131 if (hw->irq >= 0) {
132 /* use intrrupt driven data transfer */ 132 /* use interrupt driven data transfer */
133 hw->len = t->len; 133 hw->len = t->len;
134 hw->txp = t->tx_buf; 134 hw->txp = t->tx_buf;
135 hw->rxp = t->rx_buf; 135 hw->rxp = t->rx_buf;
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c
index 75ac9d48ef46..7a85f22b6474 100644
--- a/drivers/spi/spi-ppc4xx.c
+++ b/drivers/spi/spi-ppc4xx.c
@@ -101,7 +101,7 @@ struct spi_ppc4xx_regs {
101 u8 dummy; 101 u8 dummy;
102 /* 102 /*
103 * Clock divisor modulus register 103 * Clock divisor modulus register
104 * This uses the follwing formula: 104 * This uses the following formula:
105 * SCPClkOut = OPBCLK/(4(CDM + 1)) 105 * SCPClkOut = OPBCLK/(4(CDM + 1))
106 * or 106 * or
107 * CDM = (OPBCLK/4*SCPClkOut) - 1 107 * CDM = (OPBCLK/4*SCPClkOut) - 1
@@ -201,7 +201,7 @@ static int spi_ppc4xx_setupxfer(struct spi_device *spi, struct spi_transfer *t)
201 return -EINVAL; 201 return -EINVAL;
202 } 202 }
203 203
204 /* Write new configration */ 204 /* Write new configuration */
205 out_8(&hw->regs->mode, cs->mode); 205 out_8(&hw->regs->mode, cs->mode);
206 206
207 /* Set the clock */ 207 /* Set the clock */
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index cd56dcf46320..1284c9b74653 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -505,7 +505,7 @@ static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg)
505 } 505 }
506 506
507 if (unlikely(pspi->max_speed_hz == 0)) { 507 if (unlikely(pspi->max_speed_hz == 0)) {
508 dev_err(&pspi->dev, "%s pch_spi_tranfer maxspeed=%d\n", 508 dev_err(&pspi->dev, "%s pch_spi_transfer maxspeed=%d\n",
509 __func__, pspi->max_speed_hz); 509 __func__, pspi->max_speed_hz);
510 retval = -EINVAL; 510 retval = -EINVAL;
511 goto err_out; 511 goto err_out;
diff --git a/drivers/staging/android/android_alarm.h b/drivers/staging/android/android_alarm.h
index d0cafd637199..f2ffd963f1c3 100644
--- a/drivers/staging/android/android_alarm.h
+++ b/drivers/staging/android/android_alarm.h
@@ -51,10 +51,12 @@ enum android_alarm_return_flags {
51#define ANDROID_ALARM_WAIT _IO('a', 1) 51#define ANDROID_ALARM_WAIT _IO('a', 1)
52 52
53#define ALARM_IOW(c, type, size) _IOW('a', (c) | ((type) << 4), size) 53#define ALARM_IOW(c, type, size) _IOW('a', (c) | ((type) << 4), size)
54#define ALARM_IOR(c, type, size) _IOR('a', (c) | ((type) << 4), size)
55
54/* Set alarm */ 56/* Set alarm */
55#define ANDROID_ALARM_SET(type) ALARM_IOW(2, type, struct timespec) 57#define ANDROID_ALARM_SET(type) ALARM_IOW(2, type, struct timespec)
56#define ANDROID_ALARM_SET_AND_WAIT(type) ALARM_IOW(3, type, struct timespec) 58#define ANDROID_ALARM_SET_AND_WAIT(type) ALARM_IOW(3, type, struct timespec)
57#define ANDROID_ALARM_GET_TIME(type) ALARM_IOW(4, type, struct timespec) 59#define ANDROID_ALARM_GET_TIME(type) ALARM_IOR(4, type, struct timespec)
58#define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec) 60#define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec)
59#define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0))) 61#define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0)))
60#define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4) 62#define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4)
diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c
index 6c81e377262c..cc8931fde839 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200.c
@@ -1412,6 +1412,13 @@ static int __devinit dio200_attach_pci(struct comedi_device *dev,
1412 dev_err(dev->class_dev, "BUG! cannot determine board type!\n"); 1412 dev_err(dev->class_dev, "BUG! cannot determine board type!\n");
1413 return -EINVAL; 1413 return -EINVAL;
1414 } 1414 }
1415 /*
1416 * Need to 'get' the PCI device to match the 'put' in dio200_detach().
1417 * TODO: Remove the pci_dev_get() and matching pci_dev_put() once
1418 * support for manual attachment of PCI devices via dio200_attach()
1419 * has been removed.
1420 */
1421 pci_dev_get(pci_dev);
1415 return dio200_pci_common_attach(dev, pci_dev); 1422 return dio200_pci_common_attach(dev, pci_dev);
1416} 1423}
1417 1424
diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c b/drivers/staging/comedi/drivers/amplc_pc236.c
index aabba9886b7d..f50287903038 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236.c
@@ -565,6 +565,13 @@ static int __devinit pc236_attach_pci(struct comedi_device *dev,
565 dev_err(dev->class_dev, "BUG! cannot determine board type!\n"); 565 dev_err(dev->class_dev, "BUG! cannot determine board type!\n");
566 return -EINVAL; 566 return -EINVAL;
567 } 567 }
568 /*
569 * Need to 'get' the PCI device to match the 'put' in pc236_detach().
570 * TODO: Remove the pci_dev_get() and matching pci_dev_put() once
571 * support for manual attachment of PCI devices via pc236_attach()
572 * has been removed.
573 */
574 pci_dev_get(pci_dev);
568 return pc236_pci_common_attach(dev, pci_dev); 575 return pc236_pci_common_attach(dev, pci_dev);
569} 576}
570 577
diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c b/drivers/staging/comedi/drivers/amplc_pc263.c
index 40ec1ffebba6..8191c4e28e0a 100644
--- a/drivers/staging/comedi/drivers/amplc_pc263.c
+++ b/drivers/staging/comedi/drivers/amplc_pc263.c
@@ -298,6 +298,13 @@ static int __devinit pc263_attach_pci(struct comedi_device *dev,
298 dev_err(dev->class_dev, "BUG! cannot determine board type!\n"); 298 dev_err(dev->class_dev, "BUG! cannot determine board type!\n");
299 return -EINVAL; 299 return -EINVAL;
300 } 300 }
301 /*
302 * Need to 'get' the PCI device to match the 'put' in pc263_detach().
303 * TODO: Remove the pci_dev_get() and matching pci_dev_put() once
304 * support for manual attachment of PCI devices via pc263_attach()
305 * has been removed.
306 */
307 pci_dev_get(pci_dev);
301 return pc263_pci_common_attach(dev, pci_dev); 308 return pc263_pci_common_attach(dev, pci_dev);
302} 309}
303 310
diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index 4e17f13e57f6..8bf109e7bb05 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -1503,6 +1503,13 @@ pci224_attach_pci(struct comedi_device *dev, struct pci_dev *pci_dev)
1503 DRIVER_NAME ": BUG! cannot determine board type!\n"); 1503 DRIVER_NAME ": BUG! cannot determine board type!\n");
1504 return -EINVAL; 1504 return -EINVAL;
1505 } 1505 }
1506 /*
1507 * Need to 'get' the PCI device to match the 'put' in pci224_detach().
1508 * TODO: Remove the pci_dev_get() and matching pci_dev_put() once
1509 * support for manual attachment of PCI devices via pci224_attach()
1510 * has been removed.
1511 */
1512 pci_dev_get(pci_dev);
1506 return pci224_attach_common(dev, pci_dev, NULL); 1513 return pci224_attach_common(dev, pci_dev, NULL);
1507} 1514}
1508 1515
diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
index 1b67d0c61fa7..66e74bd12267 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -2925,6 +2925,13 @@ static int __devinit pci230_attach_pci(struct comedi_device *dev,
2925 "amplc_pci230: BUG! cannot determine board type!\n"); 2925 "amplc_pci230: BUG! cannot determine board type!\n");
2926 return -EINVAL; 2926 return -EINVAL;
2927 } 2927 }
2928 /*
2929 * Need to 'get' the PCI device to match the 'put' in pci230_detach().
2930 * TODO: Remove the pci_dev_get() and matching pci_dev_put() once
2931 * support for manual attachment of PCI devices via pci230_attach()
2932 * has been removed.
2933 */
2934 pci_dev_get(pci_dev);
2928 return pci230_attach_common(dev, pci_dev); 2935 return pci230_attach_common(dev, pci_dev);
2929} 2936}
2930 2937
diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c
index 874e02e47668..67a914a10b55 100644
--- a/drivers/staging/comedi/drivers/das08.c
+++ b/drivers/staging/comedi/drivers/das08.c
@@ -378,7 +378,7 @@ das08jr_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
378 int chan; 378 int chan;
379 379
380 lsb = data[0] & 0xff; 380 lsb = data[0] & 0xff;
381 msb = (data[0] >> 8) & 0xf; 381 msb = (data[0] >> 8) & 0xff;
382 382
383 chan = CR_CHAN(insn->chanspec); 383 chan = CR_CHAN(insn->chanspec);
384 384
@@ -623,7 +623,7 @@ static const struct das08_board_struct das08_boards[] = {
623 .ai = das08_ai_rinsn, 623 .ai = das08_ai_rinsn,
624 .ai_nbits = 16, 624 .ai_nbits = 16,
625 .ai_pg = das08_pg_none, 625 .ai_pg = das08_pg_none,
626 .ai_encoding = das08_encode12, 626 .ai_encoding = das08_encode16,
627 .ao = das08jr_ao_winsn, 627 .ao = das08jr_ao_winsn,
628 .ao_nbits = 16, 628 .ao_nbits = 16,
629 .di = das08jr_di_rbits, 629 .di = das08jr_di_rbits,
@@ -922,6 +922,13 @@ das08_attach_pci(struct comedi_device *dev, struct pci_dev *pdev)
922 dev_err(dev->class_dev, "BUG! cannot determine board type!\n"); 922 dev_err(dev->class_dev, "BUG! cannot determine board type!\n");
923 return -EINVAL; 923 return -EINVAL;
924 } 924 }
925 /*
926 * Need to 'get' the PCI device to match the 'put' in das08_detach().
927 * TODO: Remove the pci_dev_get() and matching pci_dev_put() once
928 * support for manual attachment of PCI devices via das08_attach()
929 * has been removed.
930 */
931 pci_dev_get(pdev);
925 return das08_pci_attach_common(dev, pdev); 932 return das08_pci_attach_common(dev, pdev);
926} 933}
927 934
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 18d108fd967a..f3da59063ed2 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -121,8 +121,10 @@ static int lis3l02dq_get_buffer_element(struct iio_dev *indio_dev,
121 if (rx_array == NULL) 121 if (rx_array == NULL)
122 return -ENOMEM; 122 return -ENOMEM;
123 ret = lis3l02dq_read_all(indio_dev, rx_array); 123 ret = lis3l02dq_read_all(indio_dev, rx_array);
124 if (ret < 0) 124 if (ret < 0) {
125 kfree(rx_array);
125 return ret; 126 return ret;
127 }
126 for (i = 0; i < scan_count; i++) 128 for (i = 0; i < scan_count; i++)
127 data[i] = combine_8_to_16(rx_array[i*4+1], 129 data[i] = combine_8_to_16(rx_array[i*4+1],
128 rx_array[i*4+3]); 130 rx_array[i*4+3]);
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index 095837285f4f..19a064d649e3 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -647,6 +647,8 @@ static ssize_t ad7192_write_frequency(struct device *dev,
647 ret = strict_strtoul(buf, 10, &lval); 647 ret = strict_strtoul(buf, 10, &lval);
648 if (ret) 648 if (ret)
649 return ret; 649 return ret;
650 if (lval == 0)
651 return -EINVAL;
650 652
651 mutex_lock(&indio_dev->mlock); 653 mutex_lock(&indio_dev->mlock);
652 if (iio_buffer_enabled(indio_dev)) { 654 if (iio_buffer_enabled(indio_dev)) {
diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
index 93aa431287ac..eb8e9d69efd3 100644
--- a/drivers/staging/iio/gyro/adis16260_core.c
+++ b/drivers/staging/iio/gyro/adis16260_core.c
@@ -195,6 +195,8 @@ static ssize_t adis16260_write_frequency(struct device *dev,
195 ret = strict_strtol(buf, 10, &val); 195 ret = strict_strtol(buf, 10, &val);
196 if (ret) 196 if (ret)
197 return ret; 197 return ret;
198 if (val == 0)
199 return -EINVAL;
198 200
199 mutex_lock(&indio_dev->mlock); 201 mutex_lock(&indio_dev->mlock);
200 if (spi_get_device_id(st->us)) { 202 if (spi_get_device_id(st->us)) {
diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c
index 1f4c17779b5a..a618327e06ed 100644
--- a/drivers/staging/iio/imu/adis16400_core.c
+++ b/drivers/staging/iio/imu/adis16400_core.c
@@ -234,6 +234,8 @@ static ssize_t adis16400_write_frequency(struct device *dev,
234 ret = strict_strtol(buf, 10, &val); 234 ret = strict_strtol(buf, 10, &val);
235 if (ret) 235 if (ret)
236 return ret; 236 return ret;
237 if (val == 0)
238 return -EINVAL;
237 239
238 mutex_lock(&indio_dev->mlock); 240 mutex_lock(&indio_dev->mlock);
239 241
diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c
index f04ece7fbc2f..3ccff189f258 100644
--- a/drivers/staging/iio/meter/ade7753.c
+++ b/drivers/staging/iio/meter/ade7753.c
@@ -425,6 +425,8 @@ static ssize_t ade7753_write_frequency(struct device *dev,
425 ret = strict_strtol(buf, 10, &val); 425 ret = strict_strtol(buf, 10, &val);
426 if (ret) 426 if (ret)
427 return ret; 427 return ret;
428 if (val == 0)
429 return -EINVAL;
428 430
429 mutex_lock(&indio_dev->mlock); 431 mutex_lock(&indio_dev->mlock);
430 432
diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c
index 6cee28a5e877..abb1e9c8d094 100644
--- a/drivers/staging/iio/meter/ade7754.c
+++ b/drivers/staging/iio/meter/ade7754.c
@@ -445,6 +445,8 @@ static ssize_t ade7754_write_frequency(struct device *dev,
445 ret = strict_strtol(buf, 10, &val); 445 ret = strict_strtol(buf, 10, &val);
446 if (ret) 446 if (ret)
447 return ret; 447 return ret;
448 if (val == 0)
449 return -EINVAL;
448 450
449 mutex_lock(&indio_dev->mlock); 451 mutex_lock(&indio_dev->mlock);
450 452
diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c
index b3f7e0fa9612..eb0a2a98f388 100644
--- a/drivers/staging/iio/meter/ade7759.c
+++ b/drivers/staging/iio/meter/ade7759.c
@@ -385,6 +385,8 @@ static ssize_t ade7759_write_frequency(struct device *dev,
385 ret = strict_strtol(buf, 10, &val); 385 ret = strict_strtol(buf, 10, &val);
386 if (ret) 386 if (ret)
387 return ret; 387 return ret;
388 if (val == 0)
389 return -EINVAL;
388 390
389 mutex_lock(&indio_dev->mlock); 391 mutex_lock(&indio_dev->mlock);
390 392
diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index 695ea35f75b0..d0a7e408efe9 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -837,7 +837,7 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
837 } 837 }
838 838
839 ret = mfd_add_devices(nvec->dev, -1, nvec_devices, 839 ret = mfd_add_devices(nvec->dev, -1, nvec_devices,
840 ARRAY_SIZE(nvec_devices), base, 0); 840 ARRAY_SIZE(nvec_devices), base, 0, NULL);
841 if (ret) 841 if (ret)
842 dev_err(nvec->dev, "error adding subdevices\n"); 842 dev_err(nvec->dev, "error adding subdevices\n");
843 843
diff --git a/drivers/staging/omapdrm/omap_connector.c b/drivers/staging/omapdrm/omap_connector.c
index 5e2856c0e0bb..55e9c8655850 100644
--- a/drivers/staging/omapdrm/omap_connector.c
+++ b/drivers/staging/omapdrm/omap_connector.c
@@ -48,13 +48,20 @@ static inline void copy_timings_omap_to_drm(struct drm_display_mode *mode,
48 mode->vsync_end = mode->vsync_start + timings->vsw; 48 mode->vsync_end = mode->vsync_start + timings->vsw;
49 mode->vtotal = mode->vsync_end + timings->vbp; 49 mode->vtotal = mode->vsync_end + timings->vbp;
50 50
51 /* note: whether or not it is interlaced, +/- h/vsync, etc, 51 mode->flags = 0;
52 * which should be set in the mode flags, is not exposed in 52
53 * the omap_video_timings struct.. but hdmi driver tracks 53 if (timings->interlace)
54 * those separately so all we have to have to set the mode 54 mode->flags |= DRM_MODE_FLAG_INTERLACE;
55 * is the way to recover these timings values, and the 55
56 * omap_dss_driver would do the rest. 56 if (timings->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
57 */ 57 mode->flags |= DRM_MODE_FLAG_PHSYNC;
58 else
59 mode->flags |= DRM_MODE_FLAG_NHSYNC;
60
61 if (timings->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
62 mode->flags |= DRM_MODE_FLAG_PVSYNC;
63 else
64 mode->flags |= DRM_MODE_FLAG_NVSYNC;
58} 65}
59 66
60static inline void copy_timings_drm_to_omap(struct omap_video_timings *timings, 67static inline void copy_timings_drm_to_omap(struct omap_video_timings *timings,
@@ -71,6 +78,22 @@ static inline void copy_timings_drm_to_omap(struct omap_video_timings *timings,
71 timings->vfp = mode->vsync_start - mode->vdisplay; 78 timings->vfp = mode->vsync_start - mode->vdisplay;
72 timings->vsw = mode->vsync_end - mode->vsync_start; 79 timings->vsw = mode->vsync_end - mode->vsync_start;
73 timings->vbp = mode->vtotal - mode->vsync_end; 80 timings->vbp = mode->vtotal - mode->vsync_end;
81
82 timings->interlace = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
83
84 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
85 timings->hsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
86 else
87 timings->hsync_level = OMAPDSS_SIG_ACTIVE_LOW;
88
89 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
90 timings->vsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
91 else
92 timings->vsync_level = OMAPDSS_SIG_ACTIVE_LOW;
93
94 timings->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
95 timings->de_level = OMAPDSS_SIG_ACTIVE_HIGH;
96 timings->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
74} 97}
75 98
76static void omap_connector_dpms(struct drm_connector *connector, int mode) 99static void omap_connector_dpms(struct drm_connector *connector, int mode)
@@ -187,7 +210,7 @@ static int omap_connector_get_modes(struct drm_connector *connector)
187 } 210 }
188 } else { 211 } else {
189 struct drm_display_mode *mode = drm_mode_create(dev); 212 struct drm_display_mode *mode = drm_mode_create(dev);
190 struct omap_video_timings timings; 213 struct omap_video_timings timings = {0};
191 214
192 dssdrv->get_timings(dssdev, &timings); 215 dssdrv->get_timings(dssdev, &timings);
193 216
@@ -291,7 +314,7 @@ void omap_connector_mode_set(struct drm_connector *connector,
291 struct omap_connector *omap_connector = to_omap_connector(connector); 314 struct omap_connector *omap_connector = to_omap_connector(connector);
292 struct omap_dss_device *dssdev = omap_connector->dssdev; 315 struct omap_dss_device *dssdev = omap_connector->dssdev;
293 struct omap_dss_driver *dssdrv = dssdev->driver; 316 struct omap_dss_driver *dssdrv = dssdev->driver;
294 struct omap_video_timings timings; 317 struct omap_video_timings timings = {0};
295 318
296 copy_timings_drm_to_omap(&timings, mode); 319 copy_timings_drm_to_omap(&timings, mode);
297 320
diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c
index d98321945802..758ce0a8d82e 100644
--- a/drivers/staging/ozwpan/ozcdev.c
+++ b/drivers/staging/ozwpan/ozcdev.c
@@ -8,6 +8,7 @@
8#include <linux/cdev.h> 8#include <linux/cdev.h>
9#include <linux/uaccess.h> 9#include <linux/uaccess.h>
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/etherdevice.h>
11#include <linux/poll.h> 12#include <linux/poll.h>
12#include <linux/sched.h> 13#include <linux/sched.h>
13#include "ozconfig.h" 14#include "ozconfig.h"
@@ -213,7 +214,7 @@ static int oz_set_active_pd(u8 *addr)
213 if (old_pd) 214 if (old_pd)
214 oz_pd_put(old_pd); 215 oz_pd_put(old_pd);
215 } else { 216 } else {
216 if (!memcmp(addr, "\0\0\0\0\0\0", sizeof(addr))) { 217 if (is_zero_ether_addr(addr)) {
217 spin_lock_bh(&g_cdev.lock); 218 spin_lock_bh(&g_cdev.lock);
218 pd = g_cdev.active_pd; 219 pd = g_cdev.active_pd;
219 g_cdev.active_pd = 0; 220 g_cdev.active_pd = 0;
diff --git a/drivers/staging/rtl8712/recv_linux.c b/drivers/staging/rtl8712/recv_linux.c
index 0e26d5f6cf2d..495ee1205e02 100644
--- a/drivers/staging/rtl8712/recv_linux.c
+++ b/drivers/staging/rtl8712/recv_linux.c
@@ -117,13 +117,8 @@ void r8712_recv_indicatepkt(struct _adapter *padapter,
117 if (skb == NULL) 117 if (skb == NULL)
118 goto _recv_indicatepkt_drop; 118 goto _recv_indicatepkt_drop;
119 skb->data = precv_frame->u.hdr.rx_data; 119 skb->data = precv_frame->u.hdr.rx_data;
120#ifdef NET_SKBUFF_DATA_USES_OFFSET
121 skb->tail = (sk_buff_data_t)(precv_frame->u.hdr.rx_tail -
122 precv_frame->u.hdr.rx_head);
123#else
124 skb->tail = (sk_buff_data_t)precv_frame->u.hdr.rx_tail;
125#endif
126 skb->len = precv_frame->u.hdr.len; 120 skb->len = precv_frame->u.hdr.len;
121 skb_set_tail_pointer(skb, skb->len);
127 if ((pattrib->tcpchk_valid == 1) && (pattrib->tcp_chkrpt == 1)) 122 if ((pattrib->tcpchk_valid == 1) && (pattrib->tcp_chkrpt == 1))
128 skb->ip_summed = CHECKSUM_UNNECESSARY; 123 skb->ip_summed = CHECKSUM_UNNECESSARY;
129 else 124 else
diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c
index e4bdf2a2b582..3aa895ec6507 100644
--- a/drivers/staging/vt6656/dpc.c
+++ b/drivers/staging/vt6656/dpc.c
@@ -200,7 +200,7 @@ s_vProcessRxMACHeader (
200 } else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) { 200 } else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) {
201 cbHeaderSize += 6; 201 cbHeaderSize += 6;
202 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize); 202 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
203 if ((*pwType == cpu_to_le16(ETH_P_IPX)) || 203 if ((*pwType == cpu_to_be16(ETH_P_IPX)) ||
204 (*pwType == cpu_to_le16(0xF380))) { 204 (*pwType == cpu_to_le16(0xF380))) {
205 cbHeaderSize -= 8; 205 cbHeaderSize -= 8;
206 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize); 206 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c
index bb464527fc1b..b6e04e7b629b 100644
--- a/drivers/staging/vt6656/rxtx.c
+++ b/drivers/staging/vt6656/rxtx.c
@@ -1699,7 +1699,7 @@ s_bPacketToWirelessUsb(
1699 // 802.1H 1699 // 802.1H
1700 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) { 1700 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1701 if (pDevice->dwDiagRefCount == 0) { 1701 if (pDevice->dwDiagRefCount == 0) {
1702 if ((psEthHeader->wType == cpu_to_le16(ETH_P_IPX)) || 1702 if ((psEthHeader->wType == cpu_to_be16(ETH_P_IPX)) ||
1703 (psEthHeader->wType == cpu_to_le16(0xF380))) { 1703 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1704 memcpy((PBYTE) (pbyPayloadHead), 1704 memcpy((PBYTE) (pbyPayloadHead),
1705 abySNAP_Bridgetunnel, 6); 1705 abySNAP_Bridgetunnel, 6);
@@ -2838,10 +2838,10 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2838 Packet_Type = skb->data[ETH_HLEN+1]; 2838 Packet_Type = skb->data[ETH_HLEN+1];
2839 Descriptor_type = skb->data[ETH_HLEN+1+1+2]; 2839 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2840 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]); 2840 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2841 if (pDevice->sTxEthHeader.wType == cpu_to_le16(ETH_P_PAE)) { 2841 if (pDevice->sTxEthHeader.wType == cpu_to_be16(ETH_P_PAE)) {
2842 /* 802.1x OR eapol-key challenge frame transfer */ 2842 /* 802.1x OR eapol-key challenge frame transfer */
2843 if (((Protocol_Version == 1) || (Protocol_Version == 2)) && 2843 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2844 (Packet_Type == 3)) { 2844 (Packet_Type == 3)) {
2845 bTxeapol_key = TRUE; 2845 bTxeapol_key = TRUE;
2846 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge 2846 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2847 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key 2847 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
@@ -2987,19 +2987,19 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2987 } 2987 }
2988 } 2988 }
2989 2989
2990 if (pDevice->sTxEthHeader.wType == cpu_to_le16(ETH_P_PAE)) { 2990 if (pDevice->sTxEthHeader.wType == cpu_to_be16(ETH_P_PAE)) {
2991 if (pDevice->byBBType != BB_TYPE_11A) { 2991 if (pDevice->byBBType != BB_TYPE_11A) {
2992 pDevice->wCurrentRate = RATE_1M; 2992 pDevice->wCurrentRate = RATE_1M;
2993 pDevice->byACKRate = RATE_1M; 2993 pDevice->byACKRate = RATE_1M;
2994 pDevice->byTopCCKBasicRate = RATE_1M; 2994 pDevice->byTopCCKBasicRate = RATE_1M;
2995 pDevice->byTopOFDMBasicRate = RATE_6M; 2995 pDevice->byTopOFDMBasicRate = RATE_6M;
2996 } else { 2996 } else {
2997 pDevice->wCurrentRate = RATE_6M; 2997 pDevice->wCurrentRate = RATE_6M;
2998 pDevice->byACKRate = RATE_6M; 2998 pDevice->byACKRate = RATE_6M;
2999 pDevice->byTopCCKBasicRate = RATE_1M; 2999 pDevice->byTopCCKBasicRate = RATE_1M;
3000 pDevice->byTopOFDMBasicRate = RATE_6M; 3000 pDevice->byTopOFDMBasicRate = RATE_6M;
3001 } 3001 }
3002 } 3002 }
3003 3003
3004 DBG_PRT(MSG_LEVEL_DEBUG, 3004 DBG_PRT(MSG_LEVEL_DEBUG,
3005 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n", 3005 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
@@ -3015,7 +3015,7 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
3015 3015
3016 if (bNeedEncryption == TRUE) { 3016 if (bNeedEncryption == TRUE) {
3017 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType)); 3017 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
3018 if ((pDevice->sTxEthHeader.wType) == cpu_to_le16(ETH_P_PAE)) { 3018 if ((pDevice->sTxEthHeader.wType) == cpu_to_be16(ETH_P_PAE)) {
3019 bNeedEncryption = FALSE; 3019 bNeedEncryption = FALSE;
3020 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType)); 3020 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
3021 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { 3021 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
diff --git a/drivers/staging/wlan-ng/cfg80211.c b/drivers/staging/wlan-ng/cfg80211.c
index fabff4d650ef..0970127344e6 100644
--- a/drivers/staging/wlan-ng/cfg80211.c
+++ b/drivers/staging/wlan-ng/cfg80211.c
@@ -327,9 +327,9 @@ int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
327 return result; 327 return result;
328} 328}
329 329
330int prism2_scan(struct wiphy *wiphy, struct net_device *dev, 330int prism2_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
331 struct cfg80211_scan_request *request)
332{ 331{
332 struct net_device *dev = request->wdev->netdev;
333 struct prism2_wiphy_private *priv = wiphy_priv(wiphy); 333 struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
334 wlandevice_t *wlandev = dev->ml_priv; 334 wlandevice_t *wlandev = dev->ml_priv;
335 struct p80211msg_dot11req_scan msg1; 335 struct p80211msg_dot11req_scan msg1;
diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c
index c214977b4ab4..52b43b7b83d7 100644
--- a/drivers/staging/zcache/zcache-main.c
+++ b/drivers/staging/zcache/zcache-main.c
@@ -1251,13 +1251,12 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *bufsize, bool raw,
1251 void *pampd, struct tmem_pool *pool, 1251 void *pampd, struct tmem_pool *pool,
1252 struct tmem_oid *oid, uint32_t index) 1252 struct tmem_oid *oid, uint32_t index)
1253{ 1253{
1254 int ret = 0;
1255
1256 BUG_ON(!is_ephemeral(pool)); 1254 BUG_ON(!is_ephemeral(pool));
1257 zbud_decompress((struct page *)(data), pampd); 1255 if (zbud_decompress((struct page *)(data), pampd) < 0)
1256 return -EINVAL;
1258 zbud_free_and_delist((struct zbud_hdr *)pampd); 1257 zbud_free_and_delist((struct zbud_hdr *)pampd);
1259 atomic_dec(&zcache_curr_eph_pampd_count); 1258 atomic_dec(&zcache_curr_eph_pampd_count);
1260 return ret; 1259 return 0;
1261} 1260}
1262 1261
1263/* 1262/*
diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c
index 0694d9b1bce6..6aba4395e8d8 100644
--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -221,6 +221,7 @@ static int iscsi_login_zero_tsih_s1(
221{ 221{
222 struct iscsi_session *sess = NULL; 222 struct iscsi_session *sess = NULL;
223 struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf; 223 struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf;
224 int ret;
224 225
225 sess = kzalloc(sizeof(struct iscsi_session), GFP_KERNEL); 226 sess = kzalloc(sizeof(struct iscsi_session), GFP_KERNEL);
226 if (!sess) { 227 if (!sess) {
@@ -257,9 +258,17 @@ static int iscsi_login_zero_tsih_s1(
257 return -ENOMEM; 258 return -ENOMEM;
258 } 259 }
259 spin_lock(&sess_idr_lock); 260 spin_lock(&sess_idr_lock);
260 idr_get_new(&sess_idr, NULL, &sess->session_index); 261 ret = idr_get_new(&sess_idr, NULL, &sess->session_index);
261 spin_unlock(&sess_idr_lock); 262 spin_unlock(&sess_idr_lock);
262 263
264 if (ret < 0) {
265 pr_err("idr_get_new() for sess_idr failed\n");
266 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
267 ISCSI_LOGIN_STATUS_NO_RESOURCES);
268 kfree(sess);
269 return -ENOMEM;
270 }
271
263 sess->creation_time = get_jiffies_64(); 272 sess->creation_time = get_jiffies_64();
264 spin_lock_init(&sess->session_stats_lock); 273 spin_lock_init(&sess->session_stats_lock);
265 /* 274 /*
diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 0c4760fabfc0..240f7aa76ed1 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -662,7 +662,7 @@ int iscsi_extract_key_value(char *textbuf, char **key, char **value)
662{ 662{
663 *value = strchr(textbuf, '='); 663 *value = strchr(textbuf, '=');
664 if (!*value) { 664 if (!*value) {
665 pr_err("Unable to locate \"=\" seperator for key," 665 pr_err("Unable to locate \"=\" separator for key,"
666 " ignoring request.\n"); 666 " ignoring request.\n");
667 return -1; 667 return -1;
668 } 668 }
@@ -1269,7 +1269,7 @@ static int iscsi_check_value(struct iscsi_param *param, char *value)
1269 comma_ptr = strchr(value, ','); 1269 comma_ptr = strchr(value, ',');
1270 1270
1271 if (comma_ptr && !IS_TYPE_VALUE_LIST(param)) { 1271 if (comma_ptr && !IS_TYPE_VALUE_LIST(param)) {
1272 pr_err("Detected value seperator \",\", but" 1272 pr_err("Detected value separator \",\", but"
1273 " key \"%s\" does not allow a value list," 1273 " key \"%s\" does not allow a value list,"
1274 " protocol error.\n", param->name); 1274 " protocol error.\n", param->name);
1275 return -1; 1275 return -1;
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 91799973081a..41641ba54828 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -218,6 +218,13 @@ int target_emulate_set_target_port_groups(struct se_cmd *cmd)
218 cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 218 cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
219 return -EINVAL; 219 return -EINVAL;
220 } 220 }
221 if (cmd->data_length < 4) {
222 pr_warn("SET TARGET PORT GROUPS parameter list length %u too"
223 " small\n", cmd->data_length);
224 cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST;
225 return -EINVAL;
226 }
227
221 buf = transport_kmap_data_sg(cmd); 228 buf = transport_kmap_data_sg(cmd);
222 229
223 /* 230 /*
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index cf2c66f3c116..9fc9a6006ca0 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -669,6 +669,13 @@ int target_report_luns(struct se_cmd *se_cmd)
669 unsigned char *buf; 669 unsigned char *buf;
670 u32 lun_count = 0, offset = 8, i; 670 u32 lun_count = 0, offset = 8, i;
671 671
672 if (se_cmd->data_length < 16) {
673 pr_warn("REPORT LUNS allocation length %u too small\n",
674 se_cmd->data_length);
675 se_cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD;
676 return -EINVAL;
677 }
678
672 buf = transport_kmap_data_sg(se_cmd); 679 buf = transport_kmap_data_sg(se_cmd);
673 if (!buf) 680 if (!buf)
674 return -ENOMEM; 681 return -ENOMEM;
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 76db75e836ed..9ba495477fd2 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -325,17 +325,30 @@ static int iblock_execute_unmap(struct se_cmd *cmd)
325 struct iblock_dev *ibd = dev->dev_ptr; 325 struct iblock_dev *ibd = dev->dev_ptr;
326 unsigned char *buf, *ptr = NULL; 326 unsigned char *buf, *ptr = NULL;
327 sector_t lba; 327 sector_t lba;
328 int size = cmd->data_length; 328 int size;
329 u32 range; 329 u32 range;
330 int ret = 0; 330 int ret = 0;
331 int dl, bd_dl; 331 int dl, bd_dl;
332 332
333 if (cmd->data_length < 8) {
334 pr_warn("UNMAP parameter list length %u too small\n",
335 cmd->data_length);
336 cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST;
337 return -EINVAL;
338 }
339
333 buf = transport_kmap_data_sg(cmd); 340 buf = transport_kmap_data_sg(cmd);
334 341
335 dl = get_unaligned_be16(&buf[0]); 342 dl = get_unaligned_be16(&buf[0]);
336 bd_dl = get_unaligned_be16(&buf[2]); 343 bd_dl = get_unaligned_be16(&buf[2]);
337 344
338 size = min(size - 8, bd_dl); 345 size = cmd->data_length - 8;
346 if (bd_dl > size)
347 pr_warn("UNMAP parameter list length %u too small, ignoring bd_dl %u\n",
348 cmd->data_length, bd_dl);
349 else
350 size = bd_dl;
351
339 if (size / 16 > dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count) { 352 if (size / 16 > dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count) {
340 cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST; 353 cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST;
341 ret = -EINVAL; 354 ret = -EINVAL;
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 1e946502c378..956c84c6b666 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1540,6 +1540,14 @@ static int core_scsi3_decode_spec_i_port(
1540 tidh_new->dest_local_nexus = 1; 1540 tidh_new->dest_local_nexus = 1;
1541 list_add_tail(&tidh_new->dest_list, &tid_dest_list); 1541 list_add_tail(&tidh_new->dest_list, &tid_dest_list);
1542 1542
1543 if (cmd->data_length < 28) {
1544 pr_warn("SPC-PR: Received PR OUT parameter list"
1545 " length too small: %u\n", cmd->data_length);
1546 cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST;
1547 ret = -EINVAL;
1548 goto out;
1549 }
1550
1543 buf = transport_kmap_data_sg(cmd); 1551 buf = transport_kmap_data_sg(cmd);
1544 /* 1552 /*
1545 * For a PERSISTENT RESERVE OUT specify initiator ports payload, 1553 * For a PERSISTENT RESERVE OUT specify initiator ports payload,
diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
index 5552fa7426bc..9d7ce3daa262 100644
--- a/drivers/target/target_core_pscsi.c
+++ b/drivers/target/target_core_pscsi.c
@@ -667,7 +667,8 @@ static void pscsi_free_device(void *p)
667 kfree(pdv); 667 kfree(pdv);
668} 668}
669 669
670static int pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg) 670static void pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg,
671 unsigned char *sense_buffer)
671{ 672{
672 struct pscsi_dev_virt *pdv = cmd->se_dev->dev_ptr; 673 struct pscsi_dev_virt *pdv = cmd->se_dev->dev_ptr;
673 struct scsi_device *sd = pdv->pdv_sd; 674 struct scsi_device *sd = pdv->pdv_sd;
@@ -679,7 +680,7 @@ static int pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg)
679 * not been allocated because TCM is handling the emulation directly. 680 * not been allocated because TCM is handling the emulation directly.
680 */ 681 */
681 if (!pt) 682 if (!pt)
682 return 0; 683 return;
683 684
684 cdb = &pt->pscsi_cdb[0]; 685 cdb = &pt->pscsi_cdb[0];
685 result = pt->pscsi_result; 686 result = pt->pscsi_result;
@@ -687,11 +688,11 @@ static int pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg)
687 * Hack to make sure that Write-Protect modepage is set if R/O mode is 688 * Hack to make sure that Write-Protect modepage is set if R/O mode is
688 * forced. 689 * forced.
689 */ 690 */
691 if (!cmd->se_deve || !cmd->data_length)
692 goto after_mode_sense;
693
690 if (((cdb[0] == MODE_SENSE) || (cdb[0] == MODE_SENSE_10)) && 694 if (((cdb[0] == MODE_SENSE) || (cdb[0] == MODE_SENSE_10)) &&
691 (status_byte(result) << 1) == SAM_STAT_GOOD) { 695 (status_byte(result) << 1) == SAM_STAT_GOOD) {
692 if (!cmd->se_deve)
693 goto after_mode_sense;
694
695 if (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) { 696 if (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) {
696 unsigned char *buf = transport_kmap_data_sg(cmd); 697 unsigned char *buf = transport_kmap_data_sg(cmd);
697 698
@@ -708,7 +709,7 @@ static int pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg)
708 } 709 }
709after_mode_sense: 710after_mode_sense:
710 711
711 if (sd->type != TYPE_TAPE) 712 if (sd->type != TYPE_TAPE || !cmd->data_length)
712 goto after_mode_select; 713 goto after_mode_select;
713 714
714 /* 715 /*
@@ -750,10 +751,10 @@ after_mode_sense:
750 } 751 }
751after_mode_select: 752after_mode_select:
752 753
753 if (status_byte(result) & CHECK_CONDITION) 754 if (sense_buffer && (status_byte(result) & CHECK_CONDITION)) {
754 return 1; 755 memcpy(sense_buffer, pt->pscsi_sense, TRANSPORT_SENSE_BUFFER);
755 756 cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE;
756 return 0; 757 }
757} 758}
758 759
759enum { 760enum {
@@ -1184,13 +1185,6 @@ fail:
1184 return -ENOMEM; 1185 return -ENOMEM;
1185} 1186}
1186 1187
1187static unsigned char *pscsi_get_sense_buffer(struct se_cmd *cmd)
1188{
1189 struct pscsi_plugin_task *pt = cmd->priv;
1190
1191 return pt->pscsi_sense;
1192}
1193
1194/* pscsi_get_device_rev(): 1188/* pscsi_get_device_rev():
1195 * 1189 *
1196 * 1190 *
@@ -1273,7 +1267,6 @@ static struct se_subsystem_api pscsi_template = {
1273 .check_configfs_dev_params = pscsi_check_configfs_dev_params, 1267 .check_configfs_dev_params = pscsi_check_configfs_dev_params,
1274 .set_configfs_dev_params = pscsi_set_configfs_dev_params, 1268 .set_configfs_dev_params = pscsi_set_configfs_dev_params,
1275 .show_configfs_dev_params = pscsi_show_configfs_dev_params, 1269 .show_configfs_dev_params = pscsi_show_configfs_dev_params,
1276 .get_sense_buffer = pscsi_get_sense_buffer,
1277 .get_device_rev = pscsi_get_device_rev, 1270 .get_device_rev = pscsi_get_device_rev,
1278 .get_device_type = pscsi_get_device_type, 1271 .get_device_type = pscsi_get_device_type,
1279 .get_blocks = pscsi_get_blocks, 1272 .get_blocks = pscsi_get_blocks,
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index 4c861de538c9..388a922c8f6d 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -877,9 +877,11 @@ static int spc_emulate_modesense(struct se_cmd *cmd)
877static int spc_emulate_request_sense(struct se_cmd *cmd) 877static int spc_emulate_request_sense(struct se_cmd *cmd)
878{ 878{
879 unsigned char *cdb = cmd->t_task_cdb; 879 unsigned char *cdb = cmd->t_task_cdb;
880 unsigned char *buf; 880 unsigned char *rbuf;
881 u8 ua_asc = 0, ua_ascq = 0; 881 u8 ua_asc = 0, ua_ascq = 0;
882 int err = 0; 882 unsigned char buf[SE_SENSE_BUF];
883
884 memset(buf, 0, SE_SENSE_BUF);
883 885
884 if (cdb[1] & 0x01) { 886 if (cdb[1] & 0x01) {
885 pr_err("REQUEST_SENSE description emulation not" 887 pr_err("REQUEST_SENSE description emulation not"
@@ -888,20 +890,21 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
888 return -ENOSYS; 890 return -ENOSYS;
889 } 891 }
890 892
891 buf = transport_kmap_data_sg(cmd); 893 rbuf = transport_kmap_data_sg(cmd);
892 894 if (cmd->scsi_sense_reason != 0) {
893 if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) { 895 /*
896 * Out of memory. We will fail with CHECK CONDITION, so
897 * we must not clear the unit attention condition.
898 */
899 target_complete_cmd(cmd, CHECK_CONDITION);
900 return 0;
901 } else if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) {
894 /* 902 /*
895 * CURRENT ERROR, UNIT ATTENTION 903 * CURRENT ERROR, UNIT ATTENTION
896 */ 904 */
897 buf[0] = 0x70; 905 buf[0] = 0x70;
898 buf[SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION; 906 buf[SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION;
899 907
900 if (cmd->data_length < 18) {
901 buf[7] = 0x00;
902 err = -EINVAL;
903 goto end;
904 }
905 /* 908 /*
906 * The Additional Sense Code (ASC) from the UNIT ATTENTION 909 * The Additional Sense Code (ASC) from the UNIT ATTENTION
907 */ 910 */
@@ -915,11 +918,6 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
915 buf[0] = 0x70; 918 buf[0] = 0x70;
916 buf[SPC_SENSE_KEY_OFFSET] = NO_SENSE; 919 buf[SPC_SENSE_KEY_OFFSET] = NO_SENSE;
917 920
918 if (cmd->data_length < 18) {
919 buf[7] = 0x00;
920 err = -EINVAL;
921 goto end;
922 }
923 /* 921 /*
924 * NO ADDITIONAL SENSE INFORMATION 922 * NO ADDITIONAL SENSE INFORMATION
925 */ 923 */
@@ -927,8 +925,11 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
927 buf[7] = 0x0A; 925 buf[7] = 0x0A;
928 } 926 }
929 927
930end: 928 if (rbuf) {
931 transport_kunmap_data_sg(cmd); 929 memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
930 transport_kunmap_data_sg(cmd);
931 }
932
932 target_complete_cmd(cmd, GOOD); 933 target_complete_cmd(cmd, GOOD);
933 return 0; 934 return 0;
934} 935}
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 4de3186dc44e..269f54488397 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -567,6 +567,34 @@ static void target_complete_failure_work(struct work_struct *work)
567 transport_generic_request_failure(cmd); 567 transport_generic_request_failure(cmd);
568} 568}
569 569
570/*
571 * Used when asking transport to copy Sense Data from the underlying
572 * Linux/SCSI struct scsi_cmnd
573 */
574static unsigned char *transport_get_sense_buffer(struct se_cmd *cmd)
575{
576 unsigned char *buffer = cmd->sense_buffer;
577 struct se_device *dev = cmd->se_dev;
578 u32 offset = 0;
579
580 WARN_ON(!cmd->se_lun);
581
582 if (!dev)
583 return NULL;
584
585 if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION)
586 return NULL;
587
588 offset = cmd->se_tfo->set_fabric_sense_len(cmd, TRANSPORT_SENSE_BUFFER);
589
590 /* Automatically padded */
591 cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER + offset;
592
593 pr_debug("HBA_[%u]_PLUG[%s]: Requesting sense for SAM STATUS: 0x%02x\n",
594 dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status);
595 return &buffer[offset];
596}
597
570void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) 598void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
571{ 599{
572 struct se_device *dev = cmd->se_dev; 600 struct se_device *dev = cmd->se_dev;
@@ -580,11 +608,11 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
580 cmd->transport_state &= ~CMD_T_BUSY; 608 cmd->transport_state &= ~CMD_T_BUSY;
581 609
582 if (dev && dev->transport->transport_complete) { 610 if (dev && dev->transport->transport_complete) {
583 if (dev->transport->transport_complete(cmd, 611 dev->transport->transport_complete(cmd,
584 cmd->t_data_sg) != 0) { 612 cmd->t_data_sg,
585 cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE; 613 transport_get_sense_buffer(cmd));
614 if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE)
586 success = 1; 615 success = 1;
587 }
588 } 616 }
589 617
590 /* 618 /*
@@ -1181,15 +1209,20 @@ int target_cmd_size_check(struct se_cmd *cmd, unsigned int size)
1181 /* Returns CHECK_CONDITION + INVALID_CDB_FIELD */ 1209 /* Returns CHECK_CONDITION + INVALID_CDB_FIELD */
1182 goto out_invalid_cdb_field; 1210 goto out_invalid_cdb_field;
1183 } 1211 }
1184 1212 /*
1213 * For the overflow case keep the existing fabric provided
1214 * ->data_length. Otherwise for the underflow case, reset
1215 * ->data_length to the smaller SCSI expected data transfer
1216 * length.
1217 */
1185 if (size > cmd->data_length) { 1218 if (size > cmd->data_length) {
1186 cmd->se_cmd_flags |= SCF_OVERFLOW_BIT; 1219 cmd->se_cmd_flags |= SCF_OVERFLOW_BIT;
1187 cmd->residual_count = (size - cmd->data_length); 1220 cmd->residual_count = (size - cmd->data_length);
1188 } else { 1221 } else {
1189 cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; 1222 cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT;
1190 cmd->residual_count = (cmd->data_length - size); 1223 cmd->residual_count = (cmd->data_length - size);
1224 cmd->data_length = size;
1191 } 1225 }
1192 cmd->data_length = size;
1193 } 1226 }
1194 1227
1195 return 0; 1228 return 0;
@@ -1816,61 +1849,6 @@ execute:
1816EXPORT_SYMBOL(target_execute_cmd); 1849EXPORT_SYMBOL(target_execute_cmd);
1817 1850
1818/* 1851/*
1819 * Used to obtain Sense Data from underlying Linux/SCSI struct scsi_cmnd
1820 */
1821static int transport_get_sense_data(struct se_cmd *cmd)
1822{
1823 unsigned char *buffer = cmd->sense_buffer, *sense_buffer = NULL;
1824 struct se_device *dev = cmd->se_dev;
1825 unsigned long flags;
1826 u32 offset = 0;
1827
1828 WARN_ON(!cmd->se_lun);
1829
1830 if (!dev)
1831 return 0;
1832
1833 spin_lock_irqsave(&cmd->t_state_lock, flags);
1834 if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) {
1835 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
1836 return 0;
1837 }
1838
1839 if (!(cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE))
1840 goto out;
1841
1842 if (!dev->transport->get_sense_buffer) {
1843 pr_err("dev->transport->get_sense_buffer is NULL\n");
1844 goto out;
1845 }
1846
1847 sense_buffer = dev->transport->get_sense_buffer(cmd);
1848 if (!sense_buffer) {
1849 pr_err("ITT 0x%08x cmd %p: Unable to locate"
1850 " sense buffer for task with sense\n",
1851 cmd->se_tfo->get_task_tag(cmd), cmd);
1852 goto out;
1853 }
1854
1855 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
1856
1857 offset = cmd->se_tfo->set_fabric_sense_len(cmd, TRANSPORT_SENSE_BUFFER);
1858
1859 memcpy(&buffer[offset], sense_buffer, TRANSPORT_SENSE_BUFFER);
1860
1861 /* Automatically padded */
1862 cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER + offset;
1863
1864 pr_debug("HBA_[%u]_PLUG[%s]: Set SAM STATUS: 0x%02x and sense\n",
1865 dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status);
1866 return 0;
1867
1868out:
1869 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
1870 return -1;
1871}
1872
1873/*
1874 * Process all commands up to the last received ORDERED task attribute which 1852 * Process all commands up to the last received ORDERED task attribute which
1875 * requires another blocking boundary 1853 * requires another blocking boundary
1876 */ 1854 */
@@ -1985,7 +1963,7 @@ static void transport_handle_queue_full(
1985static void target_complete_ok_work(struct work_struct *work) 1963static void target_complete_ok_work(struct work_struct *work)
1986{ 1964{
1987 struct se_cmd *cmd = container_of(work, struct se_cmd, work); 1965 struct se_cmd *cmd = container_of(work, struct se_cmd, work);
1988 int reason = 0, ret; 1966 int ret;
1989 1967
1990 /* 1968 /*
1991 * Check if we need to move delayed/dormant tasks from cmds on the 1969 * Check if we need to move delayed/dormant tasks from cmds on the
@@ -2002,23 +1980,19 @@ static void target_complete_ok_work(struct work_struct *work)
2002 schedule_work(&cmd->se_dev->qf_work_queue); 1980 schedule_work(&cmd->se_dev->qf_work_queue);
2003 1981
2004 /* 1982 /*
2005 * Check if we need to retrieve a sense buffer from 1983 * Check if we need to send a sense buffer from
2006 * the struct se_cmd in question. 1984 * the struct se_cmd in question.
2007 */ 1985 */
2008 if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) { 1986 if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) {
2009 if (transport_get_sense_data(cmd) < 0) 1987 WARN_ON(!cmd->scsi_status);
2010 reason = TCM_NON_EXISTENT_LUN; 1988 ret = transport_send_check_condition_and_sense(
2011 1989 cmd, 0, 1);
2012 if (cmd->scsi_status) { 1990 if (ret == -EAGAIN || ret == -ENOMEM)
2013 ret = transport_send_check_condition_and_sense( 1991 goto queue_full;
2014 cmd, reason, 1);
2015 if (ret == -EAGAIN || ret == -ENOMEM)
2016 goto queue_full;
2017 1992
2018 transport_lun_remove_cmd(cmd); 1993 transport_lun_remove_cmd(cmd);
2019 transport_cmd_check_stop_to_fabric(cmd); 1994 transport_cmd_check_stop_to_fabric(cmd);
2020 return; 1995 return;
2021 }
2022 } 1996 }
2023 /* 1997 /*
2024 * Check for a callback, used by amongst other things 1998 * Check for a callback, used by amongst other things
@@ -2216,7 +2190,6 @@ void *transport_kmap_data_sg(struct se_cmd *cmd)
2216 struct page **pages; 2190 struct page **pages;
2217 int i; 2191 int i;
2218 2192
2219 BUG_ON(!sg);
2220 /* 2193 /*
2221 * We need to take into account a possible offset here for fabrics like 2194 * We need to take into account a possible offset here for fabrics like
2222 * tcm_loop who may be using a contig buffer from the SCSI midlayer for 2195 * tcm_loop who may be using a contig buffer from the SCSI midlayer for
@@ -2224,13 +2197,17 @@ void *transport_kmap_data_sg(struct se_cmd *cmd)
2224 */ 2197 */
2225 if (!cmd->t_data_nents) 2198 if (!cmd->t_data_nents)
2226 return NULL; 2199 return NULL;
2227 else if (cmd->t_data_nents == 1) 2200
2201 BUG_ON(!sg);
2202 if (cmd->t_data_nents == 1)
2228 return kmap(sg_page(sg)) + sg->offset; 2203 return kmap(sg_page(sg)) + sg->offset;
2229 2204
2230 /* >1 page. use vmap */ 2205 /* >1 page. use vmap */
2231 pages = kmalloc(sizeof(*pages) * cmd->t_data_nents, GFP_KERNEL); 2206 pages = kmalloc(sizeof(*pages) * cmd->t_data_nents, GFP_KERNEL);
2232 if (!pages) 2207 if (!pages) {
2208 cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
2233 return NULL; 2209 return NULL;
2210 }
2234 2211
2235 /* convert sg[] to pages[] */ 2212 /* convert sg[] to pages[] */
2236 for_each_sg(cmd->t_data_sg, sg, cmd->t_data_nents, i) { 2213 for_each_sg(cmd->t_data_sg, sg, cmd->t_data_nents, i) {
@@ -2239,8 +2216,10 @@ void *transport_kmap_data_sg(struct se_cmd *cmd)
2239 2216
2240 cmd->t_data_vmap = vmap(pages, cmd->t_data_nents, VM_MAP, PAGE_KERNEL); 2217 cmd->t_data_vmap = vmap(pages, cmd->t_data_nents, VM_MAP, PAGE_KERNEL);
2241 kfree(pages); 2218 kfree(pages);
2242 if (!cmd->t_data_vmap) 2219 if (!cmd->t_data_vmap) {
2220 cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
2243 return NULL; 2221 return NULL;
2222 }
2244 2223
2245 return cmd->t_data_vmap + cmd->t_data_sg[0].offset; 2224 return cmd->t_data_vmap + cmd->t_data_sg[0].offset;
2246} 2225}
@@ -2326,19 +2305,14 @@ int transport_generic_new_cmd(struct se_cmd *cmd)
2326 * into the fabric for data transfers, go ahead and complete it right 2305 * into the fabric for data transfers, go ahead and complete it right
2327 * away. 2306 * away.
2328 */ 2307 */
2329 if (!cmd->data_length) { 2308 if (!cmd->data_length &&
2309 cmd->t_task_cdb[0] != REQUEST_SENSE &&
2310 cmd->se_dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV) {
2330 spin_lock_irq(&cmd->t_state_lock); 2311 spin_lock_irq(&cmd->t_state_lock);
2331 cmd->t_state = TRANSPORT_COMPLETE; 2312 cmd->t_state = TRANSPORT_COMPLETE;
2332 cmd->transport_state |= CMD_T_ACTIVE; 2313 cmd->transport_state |= CMD_T_ACTIVE;
2333 spin_unlock_irq(&cmd->t_state_lock); 2314 spin_unlock_irq(&cmd->t_state_lock);
2334 2315
2335 if (cmd->t_task_cdb[0] == REQUEST_SENSE) {
2336 u8 ua_asc = 0, ua_ascq = 0;
2337
2338 core_scsi3_ua_clear_for_request_sense(cmd,
2339 &ua_asc, &ua_ascq);
2340 }
2341
2342 INIT_WORK(&cmd->work, target_complete_ok_work); 2316 INIT_WORK(&cmd->work, target_complete_ok_work);
2343 queue_work(target_completion_wq, &cmd->work); 2317 queue_work(target_completion_wq, &cmd->work);
2344 return 0; 2318 return 0;
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index d5c689d6217e..e309e8b0aaba 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -132,6 +132,7 @@
132#define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */ 132#define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */
133#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ 133#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */
134#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ 134#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */
135#define UFCR_DCEDTE (1<<6) /* DCE/DTE mode select */
135#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ 136#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */
136#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7) 137#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7)
137#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ 138#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */
@@ -667,22 +668,11 @@ static void imx_break_ctl(struct uart_port *port, int break_state)
667static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode) 668static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
668{ 669{
669 unsigned int val; 670 unsigned int val;
670 unsigned int ufcr_rfdiv;
671
672 /* set receiver / transmitter trigger level.
673 * RFDIV is set such way to satisfy requested uartclk value
674 */
675 val = TXTL << 10 | RXTL;
676 ufcr_rfdiv = (clk_get_rate(sport->clk_per) + sport->port.uartclk / 2)
677 / sport->port.uartclk;
678
679 if(!ufcr_rfdiv)
680 ufcr_rfdiv = 1;
681
682 val |= UFCR_RFDIV_REG(ufcr_rfdiv);
683 671
672 /* set receiver / transmitter trigger level */
673 val = readl(sport->port.membase + UFCR) & (UFCR_RFDIV | UFCR_DCEDTE);
674 val |= TXTL << UFCR_TXTL_SHF | RXTL;
684 writel(val, sport->port.membase + UFCR); 675 writel(val, sport->port.membase + UFCR);
685
686 return 0; 676 return 0;
687} 677}
688 678
@@ -754,6 +744,7 @@ static int imx_startup(struct uart_port *port)
754 } 744 }
755 } 745 }
756 746
747 spin_lock_irqsave(&sport->port.lock, flags);
757 /* 748 /*
758 * Finally, clear and enable interrupts 749 * Finally, clear and enable interrupts
759 */ 750 */
@@ -807,7 +798,6 @@ static int imx_startup(struct uart_port *port)
807 /* 798 /*
808 * Enable modem status interrupts 799 * Enable modem status interrupts
809 */ 800 */
810 spin_lock_irqsave(&sport->port.lock,flags);
811 imx_enable_ms(&sport->port); 801 imx_enable_ms(&sport->port);
812 spin_unlock_irqrestore(&sport->port.lock,flags); 802 spin_unlock_irqrestore(&sport->port.lock,flags);
813 803
@@ -837,10 +827,13 @@ static void imx_shutdown(struct uart_port *port)
837{ 827{
838 struct imx_port *sport = (struct imx_port *)port; 828 struct imx_port *sport = (struct imx_port *)port;
839 unsigned long temp; 829 unsigned long temp;
830 unsigned long flags;
840 831
832 spin_lock_irqsave(&sport->port.lock, flags);
841 temp = readl(sport->port.membase + UCR2); 833 temp = readl(sport->port.membase + UCR2);
842 temp &= ~(UCR2_TXEN); 834 temp &= ~(UCR2_TXEN);
843 writel(temp, sport->port.membase + UCR2); 835 writel(temp, sport->port.membase + UCR2);
836 spin_unlock_irqrestore(&sport->port.lock, flags);
844 837
845 if (USE_IRDA(sport)) { 838 if (USE_IRDA(sport)) {
846 struct imxuart_platform_data *pdata; 839 struct imxuart_platform_data *pdata;
@@ -869,12 +862,14 @@ static void imx_shutdown(struct uart_port *port)
869 * Disable all interrupts, port and break condition. 862 * Disable all interrupts, port and break condition.
870 */ 863 */
871 864
865 spin_lock_irqsave(&sport->port.lock, flags);
872 temp = readl(sport->port.membase + UCR1); 866 temp = readl(sport->port.membase + UCR1);
873 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); 867 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN);
874 if (USE_IRDA(sport)) 868 if (USE_IRDA(sport))
875 temp &= ~(UCR1_IREN); 869 temp &= ~(UCR1_IREN);
876 870
877 writel(temp, sport->port.membase + UCR1); 871 writel(temp, sport->port.membase + UCR1);
872 spin_unlock_irqrestore(&sport->port.lock, flags);
878} 873}
879 874
880static void 875static void
@@ -1217,6 +1212,9 @@ imx_console_write(struct console *co, const char *s, unsigned int count)
1217 struct imx_port *sport = imx_ports[co->index]; 1212 struct imx_port *sport = imx_ports[co->index];
1218 struct imx_port_ucrs old_ucr; 1213 struct imx_port_ucrs old_ucr;
1219 unsigned int ucr1; 1214 unsigned int ucr1;
1215 unsigned long flags;
1216
1217 spin_lock_irqsave(&sport->port.lock, flags);
1220 1218
1221 /* 1219 /*
1222 * First, save UCR1/2/3 and then disable interrupts 1220 * First, save UCR1/2/3 and then disable interrupts
@@ -1242,6 +1240,8 @@ imx_console_write(struct console *co, const char *s, unsigned int count)
1242 while (!(readl(sport->port.membase + USR2) & USR2_TXDC)); 1240 while (!(readl(sport->port.membase + USR2) & USR2_TXDC));
1243 1241
1244 imx_port_ucrs_restore(&sport->port, &old_ucr); 1242 imx_port_ucrs_restore(&sport->port, &old_ucr);
1243
1244 spin_unlock_irqrestore(&sport->port.lock, flags);
1245} 1245}
1246 1246
1247/* 1247/*
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index c7a032a4f0c5..d214448b677e 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -78,8 +78,7 @@ static inline int ep_to_bit(struct ci13xxx *ci, int n)
78} 78}
79 79
80/** 80/**
81 * hw_device_state: enables/disables interrupts & starts/stops device (execute 81 * hw_device_state: enables/disables interrupts (execute without interruption)
82 * without interruption)
83 * @dma: 0 => disable, !0 => enable and set dma engine 82 * @dma: 0 => disable, !0 => enable and set dma engine
84 * 83 *
85 * This function returns an error code 84 * This function returns an error code
@@ -91,9 +90,7 @@ static int hw_device_state(struct ci13xxx *ci, u32 dma)
91 /* interrupt, error, port change, reset, sleep/suspend */ 90 /* interrupt, error, port change, reset, sleep/suspend */
92 hw_write(ci, OP_USBINTR, ~0, 91 hw_write(ci, OP_USBINTR, ~0,
93 USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); 92 USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI);
94 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS);
95 } else { 93 } else {
96 hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
97 hw_write(ci, OP_USBINTR, ~0, 0); 94 hw_write(ci, OP_USBINTR, ~0, 0);
98 } 95 }
99 return 0; 96 return 0;
@@ -774,10 +771,7 @@ __acquires(mEp->lock)
774{ 771{
775 struct ci13xxx_req *mReq, *mReqTemp; 772 struct ci13xxx_req *mReq, *mReqTemp;
776 struct ci13xxx_ep *mEpTemp = mEp; 773 struct ci13xxx_ep *mEpTemp = mEp;
777 int uninitialized_var(retval); 774 int retval = 0;
778
779 if (list_empty(&mEp->qh.queue))
780 return -EINVAL;
781 775
782 list_for_each_entry_safe(mReq, mReqTemp, &mEp->qh.queue, 776 list_for_each_entry_safe(mReq, mReqTemp, &mEp->qh.queue,
783 queue) { 777 queue) {
@@ -1420,6 +1414,21 @@ static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1420 return -ENOTSUPP; 1414 return -ENOTSUPP;
1421} 1415}
1422 1416
1417/* Change Data+ pullup status
1418 * this func is used by usb_gadget_connect/disconnet
1419 */
1420static int ci13xxx_pullup(struct usb_gadget *_gadget, int is_on)
1421{
1422 struct ci13xxx *ci = container_of(_gadget, struct ci13xxx, gadget);
1423
1424 if (is_on)
1425 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS);
1426 else
1427 hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
1428
1429 return 0;
1430}
1431
1423static int ci13xxx_start(struct usb_gadget *gadget, 1432static int ci13xxx_start(struct usb_gadget *gadget,
1424 struct usb_gadget_driver *driver); 1433 struct usb_gadget_driver *driver);
1425static int ci13xxx_stop(struct usb_gadget *gadget, 1434static int ci13xxx_stop(struct usb_gadget *gadget,
@@ -1432,6 +1441,7 @@ static int ci13xxx_stop(struct usb_gadget *gadget,
1432static const struct usb_gadget_ops usb_gadget_ops = { 1441static const struct usb_gadget_ops usb_gadget_ops = {
1433 .vbus_session = ci13xxx_vbus_session, 1442 .vbus_session = ci13xxx_vbus_session,
1434 .wakeup = ci13xxx_wakeup, 1443 .wakeup = ci13xxx_wakeup,
1444 .pullup = ci13xxx_pullup,
1435 .vbus_draw = ci13xxx_vbus_draw, 1445 .vbus_draw = ci13xxx_vbus_draw,
1436 .udc_start = ci13xxx_start, 1446 .udc_start = ci13xxx_start,
1437 .udc_stop = ci13xxx_stop, 1447 .udc_stop = ci13xxx_stop,
@@ -1455,7 +1465,12 @@ static int init_eps(struct ci13xxx *ci)
1455 1465
1456 mEp->ep.name = mEp->name; 1466 mEp->ep.name = mEp->name;
1457 mEp->ep.ops = &usb_ep_ops; 1467 mEp->ep.ops = &usb_ep_ops;
1458 mEp->ep.maxpacket = CTRL_PAYLOAD_MAX; 1468 /*
1469 * for ep0: maxP defined in desc, for other
1470 * eps, maxP is set by epautoconfig() called
1471 * by gadget layer
1472 */
1473 mEp->ep.maxpacket = (unsigned short)~0;
1459 1474
1460 INIT_LIST_HEAD(&mEp->qh.queue); 1475 INIT_LIST_HEAD(&mEp->qh.queue);
1461 mEp->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL, 1476 mEp->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL,
@@ -1475,6 +1490,7 @@ static int init_eps(struct ci13xxx *ci)
1475 else 1490 else
1476 ci->ep0in = mEp; 1491 ci->ep0in = mEp;
1477 1492
1493 mEp->ep.maxpacket = CTRL_PAYLOAD_MAX;
1478 continue; 1494 continue;
1479 } 1495 }
1480 1496
@@ -1484,6 +1500,17 @@ static int init_eps(struct ci13xxx *ci)
1484 return retval; 1500 return retval;
1485} 1501}
1486 1502
1503static void destroy_eps(struct ci13xxx *ci)
1504{
1505 int i;
1506
1507 for (i = 0; i < ci->hw_ep_max; i++) {
1508 struct ci13xxx_ep *mEp = &ci->ci13xxx_ep[i];
1509
1510 dma_pool_free(ci->qh_pool, mEp->qh.ptr, mEp->qh.dma);
1511 }
1512}
1513
1487/** 1514/**
1488 * ci13xxx_start: register a gadget driver 1515 * ci13xxx_start: register a gadget driver
1489 * @gadget: our gadget 1516 * @gadget: our gadget
@@ -1691,7 +1718,7 @@ static int udc_start(struct ci13xxx *ci)
1691 if (ci->platdata->flags & CI13XXX_REQUIRE_TRANSCEIVER) { 1718 if (ci->platdata->flags & CI13XXX_REQUIRE_TRANSCEIVER) {
1692 if (ci->transceiver == NULL) { 1719 if (ci->transceiver == NULL) {
1693 retval = -ENODEV; 1720 retval = -ENODEV;
1694 goto free_pools; 1721 goto destroy_eps;
1695 } 1722 }
1696 } 1723 }
1697 1724
@@ -1729,7 +1756,7 @@ static int udc_start(struct ci13xxx *ci)
1729 1756
1730remove_trans: 1757remove_trans:
1731 if (!IS_ERR_OR_NULL(ci->transceiver)) { 1758 if (!IS_ERR_OR_NULL(ci->transceiver)) {
1732 otg_set_peripheral(ci->transceiver->otg, &ci->gadget); 1759 otg_set_peripheral(ci->transceiver->otg, NULL);
1733 if (ci->global_phy) 1760 if (ci->global_phy)
1734 usb_put_phy(ci->transceiver); 1761 usb_put_phy(ci->transceiver);
1735 } 1762 }
@@ -1742,6 +1769,8 @@ unreg_device:
1742put_transceiver: 1769put_transceiver:
1743 if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy) 1770 if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy)
1744 usb_put_phy(ci->transceiver); 1771 usb_put_phy(ci->transceiver);
1772destroy_eps:
1773 destroy_eps(ci);
1745free_pools: 1774free_pools:
1746 dma_pool_destroy(ci->td_pool); 1775 dma_pool_destroy(ci->td_pool);
1747free_qh_pool: 1776free_qh_pool:
@@ -1756,18 +1785,12 @@ free_qh_pool:
1756 */ 1785 */
1757static void udc_stop(struct ci13xxx *ci) 1786static void udc_stop(struct ci13xxx *ci)
1758{ 1787{
1759 int i;
1760
1761 if (ci == NULL) 1788 if (ci == NULL)
1762 return; 1789 return;
1763 1790
1764 usb_del_gadget_udc(&ci->gadget); 1791 usb_del_gadget_udc(&ci->gadget);
1765 1792
1766 for (i = 0; i < ci->hw_ep_max; i++) { 1793 destroy_eps(ci);
1767 struct ci13xxx_ep *mEp = &ci->ci13xxx_ep[i];
1768
1769 dma_pool_free(ci->qh_pool, mEp->qh.ptr, mEp->qh.dma);
1770 }
1771 1794
1772 dma_pool_destroy(ci->td_pool); 1795 dma_pool_destroy(ci->td_pool);
1773 dma_pool_destroy(ci->qh_pool); 1796 dma_pool_destroy(ci->qh_pool);
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 65a55abb791f..5f0cb417b736 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -109,12 +109,14 @@ static struct usb_driver wdm_driver;
109/* return intfdata if we own the interface, else look up intf in the list */ 109/* return intfdata if we own the interface, else look up intf in the list */
110static struct wdm_device *wdm_find_device(struct usb_interface *intf) 110static struct wdm_device *wdm_find_device(struct usb_interface *intf)
111{ 111{
112 struct wdm_device *desc = NULL; 112 struct wdm_device *desc;
113 113
114 spin_lock(&wdm_device_list_lock); 114 spin_lock(&wdm_device_list_lock);
115 list_for_each_entry(desc, &wdm_device_list, device_list) 115 list_for_each_entry(desc, &wdm_device_list, device_list)
116 if (desc->intf == intf) 116 if (desc->intf == intf)
117 break; 117 goto found;
118 desc = NULL;
119found:
118 spin_unlock(&wdm_device_list_lock); 120 spin_unlock(&wdm_device_list_lock);
119 121
120 return desc; 122 return desc;
@@ -122,12 +124,14 @@ static struct wdm_device *wdm_find_device(struct usb_interface *intf)
122 124
123static struct wdm_device *wdm_find_device_by_minor(int minor) 125static struct wdm_device *wdm_find_device_by_minor(int minor)
124{ 126{
125 struct wdm_device *desc = NULL; 127 struct wdm_device *desc;
126 128
127 spin_lock(&wdm_device_list_lock); 129 spin_lock(&wdm_device_list_lock);
128 list_for_each_entry(desc, &wdm_device_list, device_list) 130 list_for_each_entry(desc, &wdm_device_list, device_list)
129 if (desc->intf->minor == minor) 131 if (desc->intf->minor == minor)
130 break; 132 goto found;
133 desc = NULL;
134found:
131 spin_unlock(&wdm_device_list_lock); 135 spin_unlock(&wdm_device_list_lock);
132 136
133 return desc; 137 return desc;
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index d95696584762..3440812b4a84 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -624,7 +624,7 @@ static ssize_t usb_device_read(struct file *file, char __user *buf,
624 /* print devices for all busses */ 624 /* print devices for all busses */
625 list_for_each_entry(bus, &usb_bus_list, bus_list) { 625 list_for_each_entry(bus, &usb_bus_list, bus_list) {
626 /* recurse through all children of the root hub */ 626 /* recurse through all children of the root hub */
627 if (!bus->root_hub) 627 if (!bus_to_hcd(bus)->rh_registered)
628 continue; 628 continue;
629 usb_lock_device(bus->root_hub); 629 usb_lock_device(bus->root_hub);
630 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, 630 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos,
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index bc84106ac057..75ba2091f9b4 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1011,10 +1011,7 @@ static int register_root_hub(struct usb_hcd *hcd)
1011 if (retval) { 1011 if (retval) {
1012 dev_err (parent_dev, "can't register root hub for %s, %d\n", 1012 dev_err (parent_dev, "can't register root hub for %s, %d\n",
1013 dev_name(&usb_dev->dev), retval); 1013 dev_name(&usb_dev->dev), retval);
1014 } 1014 } else {
1015 mutex_unlock(&usb_bus_list_lock);
1016
1017 if (retval == 0) {
1018 spin_lock_irq (&hcd_root_hub_lock); 1015 spin_lock_irq (&hcd_root_hub_lock);
1019 hcd->rh_registered = 1; 1016 hcd->rh_registered = 1;
1020 spin_unlock_irq (&hcd_root_hub_lock); 1017 spin_unlock_irq (&hcd_root_hub_lock);
@@ -1023,6 +1020,7 @@ static int register_root_hub(struct usb_hcd *hcd)
1023 if (HCD_DEAD(hcd)) 1020 if (HCD_DEAD(hcd))
1024 usb_hc_died (hcd); /* This time clean up */ 1021 usb_hc_died (hcd); /* This time clean up */
1025 } 1022 }
1023 mutex_unlock(&usb_bus_list_lock);
1026 1024
1027 return retval; 1025 return retval;
1028} 1026}
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index f15501f4c585..e77a8e8eaa23 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -71,6 +71,10 @@ static const struct usb_device_id usb_quirk_list[] = {
71 { USB_DEVICE(0x04b4, 0x0526), .driver_info = 71 { USB_DEVICE(0x04b4, 0x0526), .driver_info =
72 USB_QUIRK_CONFIG_INTF_STRINGS }, 72 USB_QUIRK_CONFIG_INTF_STRINGS },
73 73
74 /* Microchip Joss Optical infrared touchboard device */
75 { USB_DEVICE(0x04d8, 0x000c), .driver_info =
76 USB_QUIRK_CONFIG_INTF_STRINGS },
77
74 /* Samsung Android phone modem - ID conflict with SPH-I500 */ 78 /* Samsung Android phone modem - ID conflict with SPH-I500 */
75 { USB_DEVICE(0x04e8, 0x6601), .driver_info = 79 { USB_DEVICE(0x04e8, 0x6601), .driver_info =
76 USB_QUIRK_CONFIG_INTF_STRINGS }, 80 USB_QUIRK_CONFIG_INTF_STRINGS },
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index c34452a7304f..a68ff53124dc 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -436,16 +436,21 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
436 dev_err(dev, "missing IRQ\n"); 436 dev_err(dev, "missing IRQ\n");
437 return -ENODEV; 437 return -ENODEV;
438 } 438 }
439 dwc->xhci_resources[1] = *res; 439 dwc->xhci_resources[1].start = res->start;
440 dwc->xhci_resources[1].end = res->end;
441 dwc->xhci_resources[1].flags = res->flags;
442 dwc->xhci_resources[1].name = res->name;
440 443
441 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 444 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
442 if (!res) { 445 if (!res) {
443 dev_err(dev, "missing memory resource\n"); 446 dev_err(dev, "missing memory resource\n");
444 return -ENODEV; 447 return -ENODEV;
445 } 448 }
446 dwc->xhci_resources[0] = *res; 449 dwc->xhci_resources[0].start = res->start;
447 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + 450 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
448 DWC3_XHCI_REGS_END; 451 DWC3_XHCI_REGS_END;
452 dwc->xhci_resources[0].flags = res->flags;
453 dwc->xhci_resources[0].name = res->name;
449 454
450 /* 455 /*
451 * Request memory region but exclude xHCI regs, 456 * Request memory region but exclude xHCI regs,
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 9b94886b66e5..e4d5ca86b9da 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -720,7 +720,6 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
720 transferred = min_t(u32, ur->length, 720 transferred = min_t(u32, ur->length,
721 transfer_size - length); 721 transfer_size - length);
722 memcpy(ur->buf, dwc->ep0_bounce, transferred); 722 memcpy(ur->buf, dwc->ep0_bounce, transferred);
723 dwc->ep0_bounced = false;
724 } else { 723 } else {
725 transferred = ur->length - length; 724 transferred = ur->length - length;
726 } 725 }
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 58fdfad96b4d..c2813c2b005a 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -263,8 +263,11 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
263 if (req->request.status == -EINPROGRESS) 263 if (req->request.status == -EINPROGRESS)
264 req->request.status = status; 264 req->request.status = status;
265 265
266 usb_gadget_unmap_request(&dwc->gadget, &req->request, 266 if (dwc->ep0_bounced && dep->number == 0)
267 req->direction); 267 dwc->ep0_bounced = false;
268 else
269 usb_gadget_unmap_request(&dwc->gadget, &req->request,
270 req->direction);
268 271
269 dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", 272 dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n",
270 req, dep->name, req->request.actual, 273 req, dep->name, req->request.actual,
@@ -1026,6 +1029,7 @@ static void __dwc3_gadget_start_isoc(struct dwc3 *dwc,
1026 if (list_empty(&dep->request_list)) { 1029 if (list_empty(&dep->request_list)) {
1027 dev_vdbg(dwc->dev, "ISOC ep %s run out for requests.\n", 1030 dev_vdbg(dwc->dev, "ISOC ep %s run out for requests.\n",
1028 dep->name); 1031 dep->name);
1032 dep->flags |= DWC3_EP_PENDING_REQUEST;
1029 return; 1033 return;
1030 } 1034 }
1031 1035
@@ -1089,6 +1093,17 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
1089 if (dep->flags & DWC3_EP_PENDING_REQUEST) { 1093 if (dep->flags & DWC3_EP_PENDING_REQUEST) {
1090 int ret; 1094 int ret;
1091 1095
1096 /*
1097 * If xfernotready is already elapsed and it is a case
1098 * of isoc transfer, then issue END TRANSFER, so that
1099 * you can receive xfernotready again and can have
1100 * notion of current microframe.
1101 */
1102 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
1103 dwc3_stop_active_transfer(dwc, dep->number);
1104 return 0;
1105 }
1106
1092 ret = __dwc3_gadget_kick_transfer(dep, 0, true); 1107 ret = __dwc3_gadget_kick_transfer(dep, 0, true);
1093 if (ret && ret != -EBUSY) { 1108 if (ret && ret != -EBUSY) {
1094 struct dwc3 *dwc = dep->dwc; 1109 struct dwc3 *dwc = dep->dwc;
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index c9e66dfb02e6..1e35963bd4ed 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -475,8 +475,7 @@ static int at91_ep_enable(struct usb_ep *_ep,
475 unsigned long flags; 475 unsigned long flags;
476 476
477 if (!_ep || !ep 477 if (!_ep || !ep
478 || !desc || ep->ep.desc 478 || !desc || _ep->name == ep0name
479 || _ep->name == ep0name
480 || desc->bDescriptorType != USB_DT_ENDPOINT 479 || desc->bDescriptorType != USB_DT_ENDPOINT
481 || (maxpacket = usb_endpoint_maxp(desc)) == 0 480 || (maxpacket = usb_endpoint_maxp(desc)) == 0
482 || maxpacket > ep->maxpacket) { 481 || maxpacket > ep->maxpacket) {
@@ -530,7 +529,6 @@ ok:
530 tmp |= AT91_UDP_EPEDS; 529 tmp |= AT91_UDP_EPEDS;
531 __raw_writel(tmp, ep->creg); 530 __raw_writel(tmp, ep->creg);
532 531
533 ep->ep.desc = desc;
534 ep->ep.maxpacket = maxpacket; 532 ep->ep.maxpacket = maxpacket;
535 533
536 /* 534 /*
@@ -1635,7 +1633,6 @@ static int at91_start(struct usb_gadget *gadget,
1635 udc->driver = driver; 1633 udc->driver = driver;
1636 udc->gadget.dev.driver = &driver->driver; 1634 udc->gadget.dev.driver = &driver->driver;
1637 udc->gadget.dev.of_node = udc->pdev->dev.of_node; 1635 udc->gadget.dev.of_node = udc->pdev->dev.of_node;
1638 dev_set_drvdata(&udc->gadget.dev, &driver->driver);
1639 udc->enabled = 1; 1636 udc->enabled = 1;
1640 udc->selfpowered = 1; 1637 udc->selfpowered = 1;
1641 1638
@@ -1656,7 +1653,6 @@ static int at91_stop(struct usb_gadget *gadget,
1656 spin_unlock_irqrestore(&udc->lock, flags); 1653 spin_unlock_irqrestore(&udc->lock, flags);
1657 1654
1658 udc->gadget.dev.driver = NULL; 1655 udc->gadget.dev.driver = NULL;
1659 dev_set_drvdata(&udc->gadget.dev, NULL);
1660 udc->driver = NULL; 1656 udc->driver = NULL;
1661 1657
1662 DBG("unbound from %s\n", driver->driver.name); 1658 DBG("unbound from %s\n", driver->driver.name);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index b799106027ad..afdbb1cbf5d9 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -1916,6 +1916,27 @@ done:
1916 return retval; 1916 return retval;
1917} 1917}
1918 1918
1919/* usb 3.0 root hub device descriptor */
1920struct {
1921 struct usb_bos_descriptor bos;
1922 struct usb_ss_cap_descriptor ss_cap;
1923} __packed usb3_bos_desc = {
1924
1925 .bos = {
1926 .bLength = USB_DT_BOS_SIZE,
1927 .bDescriptorType = USB_DT_BOS,
1928 .wTotalLength = cpu_to_le16(sizeof(usb3_bos_desc)),
1929 .bNumDeviceCaps = 1,
1930 },
1931 .ss_cap = {
1932 .bLength = USB_DT_USB_SS_CAP_SIZE,
1933 .bDescriptorType = USB_DT_DEVICE_CAPABILITY,
1934 .bDevCapabilityType = USB_SS_CAP_TYPE,
1935 .wSpeedSupported = cpu_to_le16(USB_5GBPS_OPERATION),
1936 .bFunctionalitySupport = ilog2(USB_5GBPS_OPERATION),
1937 },
1938};
1939
1919static inline void 1940static inline void
1920ss_hub_descriptor(struct usb_hub_descriptor *desc) 1941ss_hub_descriptor(struct usb_hub_descriptor *desc)
1921{ 1942{
@@ -2006,6 +2027,18 @@ static int dummy_hub_control(
2006 else 2027 else
2007 hub_descriptor((struct usb_hub_descriptor *) buf); 2028 hub_descriptor((struct usb_hub_descriptor *) buf);
2008 break; 2029 break;
2030
2031 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
2032 if (hcd->speed != HCD_USB3)
2033 goto error;
2034
2035 if ((wValue >> 8) != USB_DT_BOS)
2036 goto error;
2037
2038 memcpy(buf, &usb3_bos_desc, sizeof(usb3_bos_desc));
2039 retval = sizeof(usb3_bos_desc);
2040 break;
2041
2009 case GetHubStatus: 2042 case GetHubStatus:
2010 *(__le32 *) buf = cpu_to_le32(0); 2043 *(__le32 *) buf = cpu_to_le32(0);
2011 break; 2044 break;
@@ -2503,10 +2536,8 @@ static int dummy_hcd_probe(struct platform_device *pdev)
2503 hs_hcd->has_tt = 1; 2536 hs_hcd->has_tt = 1;
2504 2537
2505 retval = usb_add_hcd(hs_hcd, 0, 0); 2538 retval = usb_add_hcd(hs_hcd, 0, 0);
2506 if (retval != 0) { 2539 if (retval)
2507 usb_put_hcd(hs_hcd); 2540 goto put_usb2_hcd;
2508 return retval;
2509 }
2510 2541
2511 if (mod_data.is_super_speed) { 2542 if (mod_data.is_super_speed) {
2512 ss_hcd = usb_create_shared_hcd(&dummy_hcd, &pdev->dev, 2543 ss_hcd = usb_create_shared_hcd(&dummy_hcd, &pdev->dev,
@@ -2525,6 +2556,8 @@ static int dummy_hcd_probe(struct platform_device *pdev)
2525put_usb3_hcd: 2556put_usb3_hcd:
2526 usb_put_hcd(ss_hcd); 2557 usb_put_hcd(ss_hcd);
2527dealloc_usb2_hcd: 2558dealloc_usb2_hcd:
2559 usb_remove_hcd(hs_hcd);
2560put_usb2_hcd:
2528 usb_put_hcd(hs_hcd); 2561 usb_put_hcd(hs_hcd);
2529 the_controller.hs_hcd = the_controller.ss_hcd = NULL; 2562 the_controller.hs_hcd = the_controller.ss_hcd = NULL;
2530 return retval; 2563 return retval;
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 8adc79d1b402..829aba75a6df 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -34,11 +34,15 @@
34/* Debugging ****************************************************************/ 34/* Debugging ****************************************************************/
35 35
36#ifdef VERBOSE_DEBUG 36#ifdef VERBOSE_DEBUG
37#ifndef pr_vdebug
37# define pr_vdebug pr_debug 38# define pr_vdebug pr_debug
39#endif /* pr_vdebug */
38# define ffs_dump_mem(prefix, ptr, len) \ 40# define ffs_dump_mem(prefix, ptr, len) \
39 print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len) 41 print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len)
40#else 42#else
43#ifndef pr_vdebug
41# define pr_vdebug(...) do { } while (0) 44# define pr_vdebug(...) do { } while (0)
45#endif /* pr_vdebug */
42# define ffs_dump_mem(prefix, ptr, len) do { } while (0) 46# define ffs_dump_mem(prefix, ptr, len) do { } while (0)
43#endif /* VERBOSE_DEBUG */ 47#endif /* VERBOSE_DEBUG */
44 48
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index b13e0bb5f5b8..0bb617e1dda2 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -3599,6 +3599,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3599 3599
3600 if (hsotg->num_of_eps == 0) { 3600 if (hsotg->num_of_eps == 0) {
3601 dev_err(dev, "wrong number of EPs (zero)\n"); 3601 dev_err(dev, "wrong number of EPs (zero)\n");
3602 ret = -EINVAL;
3602 goto err_supplies; 3603 goto err_supplies;
3603 } 3604 }
3604 3605
@@ -3606,6 +3607,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3606 GFP_KERNEL); 3607 GFP_KERNEL);
3607 if (!eps) { 3608 if (!eps) {
3608 dev_err(dev, "cannot get memory\n"); 3609 dev_err(dev, "cannot get memory\n");
3610 ret = -ENOMEM;
3609 goto err_supplies; 3611 goto err_supplies;
3610 } 3612 }
3611 3613
@@ -3622,6 +3624,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3622 GFP_KERNEL); 3624 GFP_KERNEL);
3623 if (!hsotg->ctrl_req) { 3625 if (!hsotg->ctrl_req) {
3624 dev_err(dev, "failed to allocate ctrl req\n"); 3626 dev_err(dev, "failed to allocate ctrl req\n");
3627 ret = -ENOMEM;
3625 goto err_ep_mem; 3628 goto err_ep_mem;
3626 } 3629 }
3627 3630
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 5b3f5fffea92..da6d479ff9a6 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -132,11 +132,15 @@ static unsigned n_ports;
132 132
133 133
134#ifdef VERBOSE_DEBUG 134#ifdef VERBOSE_DEBUG
135#ifndef pr_vdebug
135#define pr_vdebug(fmt, arg...) \ 136#define pr_vdebug(fmt, arg...) \
136 pr_debug(fmt, ##arg) 137 pr_debug(fmt, ##arg)
138#endif /* pr_vdebug */
137#else 139#else
140#ifndef pr_vdebig
138#define pr_vdebug(fmt, arg...) \ 141#define pr_vdebug(fmt, arg...) \
139 ({ if (0) pr_debug(fmt, ##arg); }) 142 ({ if (0) pr_debug(fmt, ##arg); })
143#endif /* pr_vdebug */
140#endif 144#endif
141 145
142/*-------------------------------------------------------------------------*/ 146/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 9bc39ca460c8..4b66374bdc8e 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -128,9 +128,17 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
128 else { 128 else {
129 qtd = list_entry (qh->qtd_list.next, 129 qtd = list_entry (qh->qtd_list.next,
130 struct ehci_qtd, qtd_list); 130 struct ehci_qtd, qtd_list);
131 /* first qtd may already be partially processed */ 131 /*
132 if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) 132 * first qtd may already be partially processed.
133 * If we come here during unlink, the QH overlay region
134 * might have reference to the just unlinked qtd. The
135 * qtd is updated in qh_completions(). Update the QH
136 * overlay here.
137 */
138 if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) {
139 qh->hw->hw_qtd_next = qtd->hw_next;
133 qtd = NULL; 140 qtd = NULL;
141 }
134 } 142 }
135 143
136 if (qtd) 144 if (qtd)
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index a665b3eaa746..0bf72f943b00 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -467,7 +467,8 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
467 /* From the GPIO notifying the over-current situation, find 467 /* From the GPIO notifying the over-current situation, find
468 * out the corresponding port */ 468 * out the corresponding port */
469 at91_for_each_port(port) { 469 at91_for_each_port(port) {
470 if (gpio_to_irq(pdata->overcurrent_pin[port]) == irq) { 470 if (gpio_is_valid(pdata->overcurrent_pin[port]) &&
471 gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
471 gpio = pdata->overcurrent_pin[port]; 472 gpio = pdata->overcurrent_pin[port];
472 break; 473 break;
473 } 474 }
@@ -570,6 +571,16 @@ static int __devinit ohci_hcd_at91_drv_probe(struct platform_device *pdev)
570 571
571 if (pdata) { 572 if (pdata) {
572 at91_for_each_port(i) { 573 at91_for_each_port(i) {
574 /*
575 * do not configure PIO if not in relation with
576 * real USB port on board
577 */
578 if (i >= pdata->ports) {
579 pdata->vbus_pin[i] = -EINVAL;
580 pdata->overcurrent_pin[i] = -EINVAL;
581 break;
582 }
583
573 if (!gpio_is_valid(pdata->vbus_pin[i])) 584 if (!gpio_is_valid(pdata->vbus_pin[i]))
574 continue; 585 continue;
575 gpio = pdata->vbus_pin[i]; 586 gpio = pdata->vbus_pin[i];
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index c5e9e4a76f14..966d1484ee79 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -75,7 +75,9 @@
75#define NB_PIF0_PWRDOWN_1 0x01100013 75#define NB_PIF0_PWRDOWN_1 0x01100013
76 76
77#define USB_INTEL_XUSB2PR 0xD0 77#define USB_INTEL_XUSB2PR 0xD0
78#define USB_INTEL_USB2PRM 0xD4
78#define USB_INTEL_USB3_PSSEN 0xD8 79#define USB_INTEL_USB3_PSSEN 0xD8
80#define USB_INTEL_USB3PRM 0xDC
79 81
80static struct amd_chipset_info { 82static struct amd_chipset_info {
81 struct pci_dev *nb_dev; 83 struct pci_dev *nb_dev;
@@ -772,10 +774,18 @@ void usb_enable_xhci_ports(struct pci_dev *xhci_pdev)
772 return; 774 return;
773 } 775 }
774 776
775 ports_available = 0xffffffff; 777 /* Read USB3PRM, the USB 3.0 Port Routing Mask Register
778 * Indicate the ports that can be changed from OS.
779 */
780 pci_read_config_dword(xhci_pdev, USB_INTEL_USB3PRM,
781 &ports_available);
782
783 dev_dbg(&xhci_pdev->dev, "Configurable ports to enable SuperSpeed: 0x%x\n",
784 ports_available);
785
776 /* Write USB3_PSSEN, the USB 3.0 Port SuperSpeed Enable 786 /* Write USB3_PSSEN, the USB 3.0 Port SuperSpeed Enable
777 * Register, to turn on SuperSpeed terminations for all 787 * Register, to turn on SuperSpeed terminations for the
778 * available ports. 788 * switchable ports.
779 */ 789 */
780 pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN, 790 pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
781 cpu_to_le32(ports_available)); 791 cpu_to_le32(ports_available));
@@ -785,7 +795,16 @@ void usb_enable_xhci_ports(struct pci_dev *xhci_pdev)
785 dev_dbg(&xhci_pdev->dev, "USB 3.0 ports that are now enabled " 795 dev_dbg(&xhci_pdev->dev, "USB 3.0 ports that are now enabled "
786 "under xHCI: 0x%x\n", ports_available); 796 "under xHCI: 0x%x\n", ports_available);
787 797
788 ports_available = 0xffffffff; 798 /* Read XUSB2PRM, xHCI USB 2.0 Port Routing Mask Register
799 * Indicate the USB 2.0 ports to be controlled by the xHCI host.
800 */
801
802 pci_read_config_dword(xhci_pdev, USB_INTEL_USB2PRM,
803 &ports_available);
804
805 dev_dbg(&xhci_pdev->dev, "Configurable USB 2.0 ports to hand over to xCHI: 0x%x\n",
806 ports_available);
807
789 /* Write XUSB2PR, the xHC USB 2.0 Port Routing Register, to 808 /* Write XUSB2PR, the xHC USB 2.0 Port Routing Register, to
790 * switch the USB 2.0 power and data lines over to the xHCI 809 * switch the USB 2.0 power and data lines over to the xHCI
791 * host. 810 * host.
@@ -822,12 +841,12 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev)
822 void __iomem *op_reg_base; 841 void __iomem *op_reg_base;
823 u32 val; 842 u32 val;
824 int timeout; 843 int timeout;
844 int len = pci_resource_len(pdev, 0);
825 845
826 if (!mmio_resource_enabled(pdev, 0)) 846 if (!mmio_resource_enabled(pdev, 0))
827 return; 847 return;
828 848
829 base = ioremap_nocache(pci_resource_start(pdev, 0), 849 base = ioremap_nocache(pci_resource_start(pdev, 0), len);
830 pci_resource_len(pdev, 0));
831 if (base == NULL) 850 if (base == NULL)
832 return; 851 return;
833 852
@@ -837,9 +856,17 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev)
837 */ 856 */
838 ext_cap_offset = xhci_find_next_cap_offset(base, XHCI_HCC_PARAMS_OFFSET); 857 ext_cap_offset = xhci_find_next_cap_offset(base, XHCI_HCC_PARAMS_OFFSET);
839 do { 858 do {
859 if ((ext_cap_offset + sizeof(val)) > len) {
860 /* We're reading garbage from the controller */
861 dev_warn(&pdev->dev,
862 "xHCI controller failing to respond");
863 return;
864 }
865
840 if (!ext_cap_offset) 866 if (!ext_cap_offset)
841 /* We've reached the end of the extended capabilities */ 867 /* We've reached the end of the extended capabilities */
842 goto hc_init; 868 goto hc_init;
869
843 val = readl(base + ext_cap_offset); 870 val = readl(base + ext_cap_offset);
844 if (XHCI_EXT_CAPS_ID(val) == XHCI_EXT_CAPS_LEGACY) 871 if (XHCI_EXT_CAPS_ID(val) == XHCI_EXT_CAPS_LEGACY)
845 break; 872 break;
@@ -870,9 +897,10 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev)
870 /* Disable any BIOS SMIs and clear all SMI events*/ 897 /* Disable any BIOS SMIs and clear all SMI events*/
871 writel(val, base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET); 898 writel(val, base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
872 899
900hc_init:
873 if (usb_is_intel_switchable_xhci(pdev)) 901 if (usb_is_intel_switchable_xhci(pdev))
874 usb_enable_xhci_ports(pdev); 902 usb_enable_xhci_ports(pdev);
875hc_init: 903
876 op_reg_base = base + XHCI_HC_LENGTH(readl(base)); 904 op_reg_base = base + XHCI_HC_LENGTH(readl(base));
877 905
878 /* Wait for the host controller to be ready before writing any 906 /* Wait for the host controller to be ready before writing any
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h
index ef004a5de20f..7f69a39163ce 100644
--- a/drivers/usb/host/pci-quirks.h
+++ b/drivers/usb/host/pci-quirks.h
@@ -15,6 +15,7 @@ void usb_disable_xhci_ports(struct pci_dev *xhci_pdev);
15static inline void usb_amd_quirk_pll_disable(void) {} 15static inline void usb_amd_quirk_pll_disable(void) {}
16static inline void usb_amd_quirk_pll_enable(void) {} 16static inline void usb_amd_quirk_pll_enable(void) {}
17static inline void usb_amd_dev_put(void) {} 17static inline void usb_amd_dev_put(void) {}
18static inline void usb_disable_xhci_ports(struct pci_dev *xhci_pdev) {}
18#endif /* CONFIG_PCI */ 19#endif /* CONFIG_PCI */
19 20
20#endif /* __LINUX_USB_PCI_QUIRKS_H */ 21#endif /* __LINUX_USB_PCI_QUIRKS_H */
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 74bfc868b7ad..d5eb357aa5c4 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -493,11 +493,48 @@ static void xhci_hub_report_link_state(u32 *status, u32 status_reg)
493 * when this bit is set. 493 * when this bit is set.
494 */ 494 */
495 pls |= USB_PORT_STAT_CONNECTION; 495 pls |= USB_PORT_STAT_CONNECTION;
496 } else {
497 /*
498 * If CAS bit isn't set but the Port is already at
499 * Compliance Mode, fake a connection so the USB core
500 * notices the Compliance state and resets the port.
501 * This resolves an issue generated by the SN65LVPE502CP
502 * in which sometimes the port enters compliance mode
503 * caused by a delay on the host-device negotiation.
504 */
505 if (pls == USB_SS_PORT_LS_COMP_MOD)
506 pls |= USB_PORT_STAT_CONNECTION;
496 } 507 }
508
497 /* update status field */ 509 /* update status field */
498 *status |= pls; 510 *status |= pls;
499} 511}
500 512
513/*
514 * Function for Compliance Mode Quirk.
515 *
516 * This Function verifies if all xhc USB3 ports have entered U0, if so,
517 * the compliance mode timer is deleted. A port won't enter
518 * compliance mode if it has previously entered U0.
519 */
520void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, u16 wIndex)
521{
522 u32 all_ports_seen_u0 = ((1 << xhci->num_usb3_ports)-1);
523 bool port_in_u0 = ((status & PORT_PLS_MASK) == XDEV_U0);
524
525 if (!(xhci->quirks & XHCI_COMP_MODE_QUIRK))
526 return;
527
528 if ((xhci->port_status_u0 != all_ports_seen_u0) && port_in_u0) {
529 xhci->port_status_u0 |= 1 << wIndex;
530 if (xhci->port_status_u0 == all_ports_seen_u0) {
531 del_timer_sync(&xhci->comp_mode_recovery_timer);
532 xhci_dbg(xhci, "All USB3 ports have entered U0 already!\n");
533 xhci_dbg(xhci, "Compliance Mode Recovery Timer Deleted.\n");
534 }
535 }
536}
537
501int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 538int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
502 u16 wIndex, char *buf, u16 wLength) 539 u16 wIndex, char *buf, u16 wLength)
503{ 540{
@@ -651,6 +688,11 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
651 /* Update Port Link State for super speed ports*/ 688 /* Update Port Link State for super speed ports*/
652 if (hcd->speed == HCD_USB3) { 689 if (hcd->speed == HCD_USB3) {
653 xhci_hub_report_link_state(&status, temp); 690 xhci_hub_report_link_state(&status, temp);
691 /*
692 * Verify if all USB3 Ports Have entered U0 already.
693 * Delete Compliance Mode Timer if so.
694 */
695 xhci_del_comp_mod_timer(xhci, temp, wIndex);
654 } 696 }
655 if (bus_state->port_c_suspend & (1 << wIndex)) 697 if (bus_state->port_c_suspend & (1 << wIndex))
656 status |= 1 << USB_PORT_FEAT_C_SUSPEND; 698 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 689bc18b051d..df90fe51b4aa 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -118,7 +118,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
118 goto put_hcd; 118 goto put_hcd;
119 } 119 }
120 120
121 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 121 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
122 if (!hcd->regs) { 122 if (!hcd->regs) {
123 dev_dbg(&pdev->dev, "error mapping memory\n"); 123 dev_dbg(&pdev->dev, "error mapping memory\n");
124 ret = -EFAULT; 124 ret = -EFAULT;
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index c59d5b5b6c7d..6ece0ed288d4 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -26,6 +26,7 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/dmi.h>
29 30
30#include "xhci.h" 31#include "xhci.h"
31 32
@@ -398,6 +399,95 @@ static void xhci_msix_sync_irqs(struct xhci_hcd *xhci)
398 399
399#endif 400#endif
400 401
402static void compliance_mode_recovery(unsigned long arg)
403{
404 struct xhci_hcd *xhci;
405 struct usb_hcd *hcd;
406 u32 temp;
407 int i;
408
409 xhci = (struct xhci_hcd *)arg;
410
411 for (i = 0; i < xhci->num_usb3_ports; i++) {
412 temp = xhci_readl(xhci, xhci->usb3_ports[i]);
413 if ((temp & PORT_PLS_MASK) == USB_SS_PORT_LS_COMP_MOD) {
414 /*
415 * Compliance Mode Detected. Letting USB Core
416 * handle the Warm Reset
417 */
418 xhci_dbg(xhci, "Compliance Mode Detected->Port %d!\n",
419 i + 1);
420 xhci_dbg(xhci, "Attempting Recovery routine!\n");
421 hcd = xhci->shared_hcd;
422
423 if (hcd->state == HC_STATE_SUSPENDED)
424 usb_hcd_resume_root_hub(hcd);
425
426 usb_hcd_poll_rh_status(hcd);
427 }
428 }
429
430 if (xhci->port_status_u0 != ((1 << xhci->num_usb3_ports)-1))
431 mod_timer(&xhci->comp_mode_recovery_timer,
432 jiffies + msecs_to_jiffies(COMP_MODE_RCVRY_MSECS));
433}
434
435/*
436 * Quirk to work around issue generated by the SN65LVPE502CP USB3.0 re-driver
437 * that causes ports behind that hardware to enter compliance mode sometimes.
438 * The quirk creates a timer that polls every 2 seconds the link state of
439 * each host controller's port and recovers it by issuing a Warm reset
440 * if Compliance mode is detected, otherwise the port will become "dead" (no
441 * device connections or disconnections will be detected anymore). Becasue no
442 * status event is generated when entering compliance mode (per xhci spec),
443 * this quirk is needed on systems that have the failing hardware installed.
444 */
445static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci)
446{
447 xhci->port_status_u0 = 0;
448 init_timer(&xhci->comp_mode_recovery_timer);
449
450 xhci->comp_mode_recovery_timer.data = (unsigned long) xhci;
451 xhci->comp_mode_recovery_timer.function = compliance_mode_recovery;
452 xhci->comp_mode_recovery_timer.expires = jiffies +
453 msecs_to_jiffies(COMP_MODE_RCVRY_MSECS);
454
455 set_timer_slack(&xhci->comp_mode_recovery_timer,
456 msecs_to_jiffies(COMP_MODE_RCVRY_MSECS));
457 add_timer(&xhci->comp_mode_recovery_timer);
458 xhci_dbg(xhci, "Compliance Mode Recovery Timer Initialized.\n");
459}
460
461/*
462 * This function identifies the systems that have installed the SN65LVPE502CP
463 * USB3.0 re-driver and that need the Compliance Mode Quirk.
464 * Systems:
465 * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820
466 */
467static bool compliance_mode_recovery_timer_quirk_check(void)
468{
469 const char *dmi_product_name, *dmi_sys_vendor;
470
471 dmi_product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
472 dmi_sys_vendor = dmi_get_system_info(DMI_SYS_VENDOR);
473
474 if (!(strstr(dmi_sys_vendor, "Hewlett-Packard")))
475 return false;
476
477 if (strstr(dmi_product_name, "Z420") ||
478 strstr(dmi_product_name, "Z620") ||
479 strstr(dmi_product_name, "Z820"))
480 return true;
481
482 return false;
483}
484
485static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci)
486{
487 return (xhci->port_status_u0 == ((1 << xhci->num_usb3_ports)-1));
488}
489
490
401/* 491/*
402 * Initialize memory for HCD and xHC (one-time init). 492 * Initialize memory for HCD and xHC (one-time init).
403 * 493 *
@@ -421,6 +511,12 @@ int xhci_init(struct usb_hcd *hcd)
421 retval = xhci_mem_init(xhci, GFP_KERNEL); 511 retval = xhci_mem_init(xhci, GFP_KERNEL);
422 xhci_dbg(xhci, "Finished xhci_init\n"); 512 xhci_dbg(xhci, "Finished xhci_init\n");
423 513
514 /* Initializing Compliance Mode Recovery Data If Needed */
515 if (compliance_mode_recovery_timer_quirk_check()) {
516 xhci->quirks |= XHCI_COMP_MODE_QUIRK;
517 compliance_mode_recovery_timer_init(xhci);
518 }
519
424 return retval; 520 return retval;
425} 521}
426 522
@@ -629,6 +725,11 @@ void xhci_stop(struct usb_hcd *hcd)
629 del_timer_sync(&xhci->event_ring_timer); 725 del_timer_sync(&xhci->event_ring_timer);
630#endif 726#endif
631 727
728 /* Deleting Compliance Mode Recovery Timer */
729 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
730 (!(xhci_all_ports_seen_u0(xhci))))
731 del_timer_sync(&xhci->comp_mode_recovery_timer);
732
632 if (xhci->quirks & XHCI_AMD_PLL_FIX) 733 if (xhci->quirks & XHCI_AMD_PLL_FIX)
633 usb_amd_dev_put(); 734 usb_amd_dev_put();
634 735
@@ -659,7 +760,7 @@ void xhci_shutdown(struct usb_hcd *hcd)
659{ 760{
660 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 761 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
661 762
662 if (xhci->quirks && XHCI_SPURIOUS_REBOOT) 763 if (xhci->quirks & XHCI_SPURIOUS_REBOOT)
663 usb_disable_xhci_ports(to_pci_dev(hcd->self.controller)); 764 usb_disable_xhci_ports(to_pci_dev(hcd->self.controller));
664 765
665 spin_lock_irq(&xhci->lock); 766 spin_lock_irq(&xhci->lock);
@@ -806,6 +907,16 @@ int xhci_suspend(struct xhci_hcd *xhci)
806 } 907 }
807 spin_unlock_irq(&xhci->lock); 908 spin_unlock_irq(&xhci->lock);
808 909
910 /*
911 * Deleting Compliance Mode Recovery Timer because the xHCI Host
912 * is about to be suspended.
913 */
914 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
915 (!(xhci_all_ports_seen_u0(xhci)))) {
916 del_timer_sync(&xhci->comp_mode_recovery_timer);
917 xhci_dbg(xhci, "Compliance Mode Recovery Timer Deleted!\n");
918 }
919
809 /* step 5: remove core well power */ 920 /* step 5: remove core well power */
810 /* synchronize irq when using MSI-X */ 921 /* synchronize irq when using MSI-X */
811 xhci_msix_sync_irqs(xhci); 922 xhci_msix_sync_irqs(xhci);
@@ -938,6 +1049,16 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
938 usb_hcd_resume_root_hub(hcd); 1049 usb_hcd_resume_root_hub(hcd);
939 usb_hcd_resume_root_hub(xhci->shared_hcd); 1050 usb_hcd_resume_root_hub(xhci->shared_hcd);
940 } 1051 }
1052
1053 /*
1054 * If system is subject to the Quirk, Compliance Mode Timer needs to
1055 * be re-initialized Always after a system resume. Ports are subject
1056 * to suffer the Compliance Mode issue again. It doesn't matter if
1057 * ports have entered previously to U0 before system's suspension.
1058 */
1059 if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
1060 compliance_mode_recovery_timer_init(xhci);
1061
941 return retval; 1062 return retval;
942} 1063}
943#endif /* CONFIG_PM */ 1064#endif /* CONFIG_PM */
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index c713256297ac..1a05908c6673 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1495,6 +1495,7 @@ struct xhci_hcd {
1495#define XHCI_LPM_SUPPORT (1 << 11) 1495#define XHCI_LPM_SUPPORT (1 << 11)
1496#define XHCI_INTEL_HOST (1 << 12) 1496#define XHCI_INTEL_HOST (1 << 12)
1497#define XHCI_SPURIOUS_REBOOT (1 << 13) 1497#define XHCI_SPURIOUS_REBOOT (1 << 13)
1498#define XHCI_COMP_MODE_QUIRK (1 << 14)
1498 unsigned int num_active_eps; 1499 unsigned int num_active_eps;
1499 unsigned int limit_active_eps; 1500 unsigned int limit_active_eps;
1500 /* There are two roothubs to keep track of bus suspend info for */ 1501 /* There are two roothubs to keep track of bus suspend info for */
@@ -1511,6 +1512,11 @@ struct xhci_hcd {
1511 unsigned sw_lpm_support:1; 1512 unsigned sw_lpm_support:1;
1512 /* support xHCI 1.0 spec USB2 hardware LPM */ 1513 /* support xHCI 1.0 spec USB2 hardware LPM */
1513 unsigned hw_lpm_support:1; 1514 unsigned hw_lpm_support:1;
1515 /* Compliance Mode Recovery Data */
1516 struct timer_list comp_mode_recovery_timer;
1517 u32 port_status_u0;
1518/* Compliance Mode Timer Triggered every 2 seconds */
1519#define COMP_MODE_RCVRY_MSECS 2000
1514}; 1520};
1515 1521
1516/* convert between an HCD pointer and the corresponding EHCI_HCD */ 1522/* convert between an HCD pointer and the corresponding EHCI_HCD */
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 4bb717d0bd41..1ae378d5fc6f 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2049,7 +2049,7 @@ static int musb_urb_enqueue(
2049 * we only have work to do in the former case. 2049 * we only have work to do in the former case.
2050 */ 2050 */
2051 spin_lock_irqsave(&musb->lock, flags); 2051 spin_lock_irqsave(&musb->lock, flags);
2052 if (hep->hcpriv) { 2052 if (hep->hcpriv || !next_urb(qh)) {
2053 /* some concurrent activity submitted another urb to hep... 2053 /* some concurrent activity submitted another urb to hep...
2054 * odd, rare, error prone, but legal. 2054 * odd, rare, error prone, but legal.
2055 */ 2055 */
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index 57a608584e16..c1be687e00ec 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -388,7 +388,7 @@ dma_controller_create(struct musb *musb, void __iomem *base)
388 struct platform_device *pdev = to_platform_device(dev); 388 struct platform_device *pdev = to_platform_device(dev);
389 int irq = platform_get_irq_byname(pdev, "dma"); 389 int irq = platform_get_irq_byname(pdev, "dma");
390 390
391 if (irq == 0) { 391 if (irq <= 0) {
392 dev_err(dev, "No DMA interrupt line!\n"); 392 dev_err(dev, "No DMA interrupt line!\n");
393 return NULL; 393 return NULL;
394 } 394 }
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 1a1bd9cf40c5..341625442377 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -1215,7 +1215,7 @@ static int __devinit tusb_probe(struct platform_device *pdev)
1215 ret = platform_device_add(musb); 1215 ret = platform_device_add(musb);
1216 if (ret) { 1216 if (ret) {
1217 dev_err(&pdev->dev, "failed to register musb device\n"); 1217 dev_err(&pdev->dev, "failed to register musb device\n");
1218 goto err1; 1218 goto err2;
1219 } 1219 }
1220 1220
1221 return 0; 1221 return 0;
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index ecd173032fd4..143c4e9e1be4 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -818,7 +818,7 @@ static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
818 usbhs_pipe_is_dcp(pipe)) 818 usbhs_pipe_is_dcp(pipe))
819 goto usbhsf_pio_prepare_push; 819 goto usbhsf_pio_prepare_push;
820 820
821 if (len % 4) /* 32bit alignment */ 821 if (len & 0x7) /* 8byte alignment */
822 goto usbhsf_pio_prepare_push; 822 goto usbhsf_pio_prepare_push;
823 823
824 if ((uintptr_t)(pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */ 824 if ((uintptr_t)(pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
@@ -905,7 +905,7 @@ static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done)
905 /* use PIO if packet is less than pio_dma_border */ 905 /* use PIO if packet is less than pio_dma_border */
906 len = usbhsf_fifo_rcv_len(priv, fifo); 906 len = usbhsf_fifo_rcv_len(priv, fifo);
907 len = min(pkt->length - pkt->actual, len); 907 len = min(pkt->length - pkt->actual, len);
908 if (len % 4) /* 32bit alignment */ 908 if (len & 0x7) /* 8byte alignment */
909 goto usbhsf_pio_prepare_pop_unselect; 909 goto usbhsf_pio_prepare_pop_unselect;
910 910
911 if (len < usbhs_get_dparam(priv, pio_dma_border)) 911 if (len < usbhs_get_dparam(priv, pio_dma_border))
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 5620db6469e5..f906b3aec217 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -704,6 +704,7 @@ static struct usb_device_id id_table_combined [] = {
704 { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) }, 704 { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) },
705 { USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) }, 705 { USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) },
706 { USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) }, 706 { USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) },
707 { USB_DEVICE(FTDI_VID, FTDI_NZR_SEM_USB_PID) },
707 { USB_DEVICE(ICOM_VID, ICOM_ID_1_PID) }, 708 { USB_DEVICE(ICOM_VID, ICOM_ID_1_PID) },
708 { USB_DEVICE(ICOM_VID, ICOM_OPC_U_UC_PID) }, 709 { USB_DEVICE(ICOM_VID, ICOM_OPC_U_UC_PID) },
709 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2C1_PID) }, 710 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2C1_PID) },
@@ -804,13 +805,32 @@ static struct usb_device_id id_table_combined [] = {
804 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 805 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
805 { USB_DEVICE(ADI_VID, ADI_GNICEPLUS_PID), 806 { USB_DEVICE(ADI_VID, ADI_GNICEPLUS_PID),
806 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 807 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
807 { USB_DEVICE(MICROCHIP_VID, MICROCHIP_USB_BOARD_PID) }, 808 { USB_DEVICE_AND_INTERFACE_INFO(MICROCHIP_VID, MICROCHIP_USB_BOARD_PID,
809 USB_CLASS_VENDOR_SPEC,
810 USB_SUBCLASS_VENDOR_SPEC, 0x00) },
808 { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) }, 811 { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) },
809 { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID), 812 { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID),
810 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 813 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
811 { USB_DEVICE(LARSENBRUSGAARD_VID, LB_ALTITRACK_PID) }, 814 { USB_DEVICE(LARSENBRUSGAARD_VID, LB_ALTITRACK_PID) },
812 { USB_DEVICE(GN_OTOMETRICS_VID, AURICAL_USB_PID) }, 815 { USB_DEVICE(GN_OTOMETRICS_VID, AURICAL_USB_PID) },
816 { USB_DEVICE(FTDI_VID, PI_C865_PID) },
817 { USB_DEVICE(FTDI_VID, PI_C857_PID) },
818 { USB_DEVICE(PI_VID, PI_C866_PID) },
819 { USB_DEVICE(PI_VID, PI_C663_PID) },
820 { USB_DEVICE(PI_VID, PI_C725_PID) },
821 { USB_DEVICE(PI_VID, PI_E517_PID) },
822 { USB_DEVICE(PI_VID, PI_C863_PID) },
813 { USB_DEVICE(PI_VID, PI_E861_PID) }, 823 { USB_DEVICE(PI_VID, PI_E861_PID) },
824 { USB_DEVICE(PI_VID, PI_C867_PID) },
825 { USB_DEVICE(PI_VID, PI_E609_PID) },
826 { USB_DEVICE(PI_VID, PI_E709_PID) },
827 { USB_DEVICE(PI_VID, PI_100F_PID) },
828 { USB_DEVICE(PI_VID, PI_1011_PID) },
829 { USB_DEVICE(PI_VID, PI_1012_PID) },
830 { USB_DEVICE(PI_VID, PI_1013_PID) },
831 { USB_DEVICE(PI_VID, PI_1014_PID) },
832 { USB_DEVICE(PI_VID, PI_1015_PID) },
833 { USB_DEVICE(PI_VID, PI_1016_PID) },
814 { USB_DEVICE(KONDO_VID, KONDO_USB_SERIAL_PID) }, 834 { USB_DEVICE(KONDO_VID, KONDO_USB_SERIAL_PID) },
815 { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) }, 835 { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) },
816 { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID), 836 { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID),
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 5dd96ca6c380..41fe5826100c 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -75,6 +75,9 @@
75#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB 75#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB
76#define FTDI_OPENDCC_GBM_PID 0xBFDC 76#define FTDI_OPENDCC_GBM_PID 0xBFDC
77 77
78/* NZR SEM 16+ USB (http://www.nzr.de) */
79#define FTDI_NZR_SEM_USB_PID 0xC1E0 /* NZR SEM-LOG16+ */
80
78/* 81/*
79 * RR-CirKits LocoBuffer USB (http://www.rr-cirkits.com) 82 * RR-CirKits LocoBuffer USB (http://www.rr-cirkits.com)
80 */ 83 */
@@ -539,7 +542,10 @@
539/* 542/*
540 * Microchip Technology, Inc. 543 * Microchip Technology, Inc.
541 * 544 *
542 * MICROCHIP_VID (0x04D8) and MICROCHIP_USB_BOARD_PID (0x000A) are also used by: 545 * MICROCHIP_VID (0x04D8) and MICROCHIP_USB_BOARD_PID (0x000A) are
546 * used by single function CDC ACM class based firmware demo
547 * applications. The VID/PID has also been used in firmware
548 * emulating FTDI serial chips by:
543 * Hornby Elite - Digital Command Control Console 549 * Hornby Elite - Digital Command Control Console
544 * http://www.hornby.com/hornby-dcc/controllers/ 550 * http://www.hornby.com/hornby-dcc/controllers/
545 */ 551 */
@@ -791,8 +797,27 @@
791 * Physik Instrumente 797 * Physik Instrumente
792 * http://www.physikinstrumente.com/en/products/ 798 * http://www.physikinstrumente.com/en/products/
793 */ 799 */
800/* These two devices use the VID of FTDI */
801#define PI_C865_PID 0xe0a0 /* PI C-865 Piezomotor Controller */
802#define PI_C857_PID 0xe0a1 /* PI Encoder Trigger Box */
803
794#define PI_VID 0x1a72 /* Vendor ID */ 804#define PI_VID 0x1a72 /* Vendor ID */
795#define PI_E861_PID 0x1008 /* E-861 piezo controller USB connection */ 805#define PI_C866_PID 0x1000 /* PI C-866 Piezomotor Controller */
806#define PI_C663_PID 0x1001 /* PI C-663 Mercury-Step */
807#define PI_C725_PID 0x1002 /* PI C-725 Piezomotor Controller */
808#define PI_E517_PID 0x1005 /* PI E-517 Digital Piezo Controller Operation Module */
809#define PI_C863_PID 0x1007 /* PI C-863 */
810#define PI_E861_PID 0x1008 /* PI E-861 Piezomotor Controller */
811#define PI_C867_PID 0x1009 /* PI C-867 Piezomotor Controller */
812#define PI_E609_PID 0x100D /* PI E-609 Digital Piezo Controller */
813#define PI_E709_PID 0x100E /* PI E-709 Digital Piezo Controller */
814#define PI_100F_PID 0x100F /* PI Digital Piezo Controller */
815#define PI_1011_PID 0x1011 /* PI Digital Piezo Controller */
816#define PI_1012_PID 0x1012 /* PI Motion Controller */
817#define PI_1013_PID 0x1013 /* PI Motion Controller */
818#define PI_1014_PID 0x1014 /* PI Device */
819#define PI_1015_PID 0x1015 /* PI Device */
820#define PI_1016_PID 0x1016 /* PI Digital Servo Module */
796 821
797/* 822/*
798 * Kondo Kagaku Co.Ltd. 823 * Kondo Kagaku Co.Ltd.
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index cc40f47ecea1..5ce88d1bc6f1 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -886,8 +886,6 @@ static const struct usb_device_id option_ids[] = {
886 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1010, 0xff, 0xff, 0xff), 886 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1010, 0xff, 0xff, 0xff),
887 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 887 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
888 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1012, 0xff, 0xff, 0xff) }, 888 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1012, 0xff, 0xff, 0xff) },
889 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1018, 0xff, 0xff, 0xff),
890 .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
891 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1057, 0xff, 0xff, 0xff) }, 889 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1057, 0xff, 0xff, 0xff) },
892 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1058, 0xff, 0xff, 0xff) }, 890 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1058, 0xff, 0xff, 0xff) },
893 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1059, 0xff, 0xff, 0xff) }, 891 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1059, 0xff, 0xff, 0xff) },
@@ -1092,6 +1090,10 @@ static const struct usb_device_id option_ids[] = {
1092 .driver_info = (kernel_ulong_t)&zte_ad3812_z_blacklist }, 1090 .driver_info = (kernel_ulong_t)&zte_ad3812_z_blacklist },
1093 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MC2716, 0xff, 0xff, 0xff), 1091 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MC2716, 0xff, 0xff, 0xff),
1094 .driver_info = (kernel_ulong_t)&zte_mc2716_z_blacklist }, 1092 .driver_info = (kernel_ulong_t)&zte_mc2716_z_blacklist },
1093 { USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff, 0x02, 0x01) },
1094 { USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff, 0x02, 0x05) },
1095 { USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff, 0x86, 0x10) },
1096
1095 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, 1097 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) },
1096 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, 1098 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) },
1097 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */ 1099 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index 211a4920b88a..d8dedc7d3910 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -76,9 +76,24 @@ static int virqfd_wakeup(wait_queue_t *wait, unsigned mode, int sync, void *key)
76 schedule_work(&virqfd->inject); 76 schedule_work(&virqfd->inject);
77 } 77 }
78 78
79 if (flags & POLLHUP) 79 if (flags & POLLHUP) {
80 /* The eventfd is closing, detach from VFIO */ 80 unsigned long flags;
81 virqfd_deactivate(virqfd); 81 spin_lock_irqsave(&virqfd->vdev->irqlock, flags);
82
83 /*
84 * The eventfd is closing, if the virqfd has not yet been
85 * queued for release, as determined by testing whether the
86 * vdev pointer to it is still valid, queue it now. As
87 * with kvm irqfds, we know we won't race against the virqfd
88 * going away because we hold wqh->lock to get here.
89 */
90 if (*(virqfd->pvirqfd) == virqfd) {
91 *(virqfd->pvirqfd) = NULL;
92 virqfd_deactivate(virqfd);
93 }
94
95 spin_unlock_irqrestore(&virqfd->vdev->irqlock, flags);
96 }
82 97
83 return 0; 98 return 0;
84} 99}
@@ -93,7 +108,6 @@ static void virqfd_ptable_queue_proc(struct file *file,
93static void virqfd_shutdown(struct work_struct *work) 108static void virqfd_shutdown(struct work_struct *work)
94{ 109{
95 struct virqfd *virqfd = container_of(work, struct virqfd, shutdown); 110 struct virqfd *virqfd = container_of(work, struct virqfd, shutdown);
96 struct virqfd **pvirqfd = virqfd->pvirqfd;
97 u64 cnt; 111 u64 cnt;
98 112
99 eventfd_ctx_remove_wait_queue(virqfd->eventfd, &virqfd->wait, &cnt); 113 eventfd_ctx_remove_wait_queue(virqfd->eventfd, &virqfd->wait, &cnt);
@@ -101,7 +115,6 @@ static void virqfd_shutdown(struct work_struct *work)
101 eventfd_ctx_put(virqfd->eventfd); 115 eventfd_ctx_put(virqfd->eventfd);
102 116
103 kfree(virqfd); 117 kfree(virqfd);
104 *pvirqfd = NULL;
105} 118}
106 119
107static void virqfd_inject(struct work_struct *work) 120static void virqfd_inject(struct work_struct *work)
@@ -122,15 +135,11 @@ static int virqfd_enable(struct vfio_pci_device *vdev,
122 int ret = 0; 135 int ret = 0;
123 unsigned int events; 136 unsigned int events;
124 137
125 if (*pvirqfd)
126 return -EBUSY;
127
128 virqfd = kzalloc(sizeof(*virqfd), GFP_KERNEL); 138 virqfd = kzalloc(sizeof(*virqfd), GFP_KERNEL);
129 if (!virqfd) 139 if (!virqfd)
130 return -ENOMEM; 140 return -ENOMEM;
131 141
132 virqfd->pvirqfd = pvirqfd; 142 virqfd->pvirqfd = pvirqfd;
133 *pvirqfd = virqfd;
134 virqfd->vdev = vdev; 143 virqfd->vdev = vdev;
135 virqfd->handler = handler; 144 virqfd->handler = handler;
136 virqfd->thread = thread; 145 virqfd->thread = thread;
@@ -154,6 +163,23 @@ static int virqfd_enable(struct vfio_pci_device *vdev,
154 virqfd->eventfd = ctx; 163 virqfd->eventfd = ctx;
155 164
156 /* 165 /*
166 * virqfds can be released by closing the eventfd or directly
167 * through ioctl. These are both done through a workqueue, so
168 * we update the pointer to the virqfd under lock to avoid
169 * pushing multiple jobs to release the same virqfd.
170 */
171 spin_lock_irq(&vdev->irqlock);
172
173 if (*pvirqfd) {
174 spin_unlock_irq(&vdev->irqlock);
175 ret = -EBUSY;
176 goto fail;
177 }
178 *pvirqfd = virqfd;
179
180 spin_unlock_irq(&vdev->irqlock);
181
182 /*
157 * Install our own custom wake-up handling so we are notified via 183 * Install our own custom wake-up handling so we are notified via
158 * a callback whenever someone signals the underlying eventfd. 184 * a callback whenever someone signals the underlying eventfd.
159 */ 185 */
@@ -187,19 +213,29 @@ fail:
187 fput(file); 213 fput(file);
188 214
189 kfree(virqfd); 215 kfree(virqfd);
190 *pvirqfd = NULL;
191 216
192 return ret; 217 return ret;
193} 218}
194 219
195static void virqfd_disable(struct virqfd *virqfd) 220static void virqfd_disable(struct vfio_pci_device *vdev,
221 struct virqfd **pvirqfd)
196{ 222{
197 if (!virqfd) 223 unsigned long flags;
198 return; 224
225 spin_lock_irqsave(&vdev->irqlock, flags);
226
227 if (*pvirqfd) {
228 virqfd_deactivate(*pvirqfd);
229 *pvirqfd = NULL;
230 }
199 231
200 virqfd_deactivate(virqfd); 232 spin_unlock_irqrestore(&vdev->irqlock, flags);
201 233
202 /* Block until we know all outstanding shutdown jobs have completed. */ 234 /*
235 * Block until we know all outstanding shutdown jobs have completed.
236 * Even if we don't queue the job, flush the wq to be sure it's
237 * been released.
238 */
203 flush_workqueue(vfio_irqfd_cleanup_wq); 239 flush_workqueue(vfio_irqfd_cleanup_wq);
204} 240}
205 241
@@ -392,8 +428,8 @@ static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd)
392static void vfio_intx_disable(struct vfio_pci_device *vdev) 428static void vfio_intx_disable(struct vfio_pci_device *vdev)
393{ 429{
394 vfio_intx_set_signal(vdev, -1); 430 vfio_intx_set_signal(vdev, -1);
395 virqfd_disable(vdev->ctx[0].unmask); 431 virqfd_disable(vdev, &vdev->ctx[0].unmask);
396 virqfd_disable(vdev->ctx[0].mask); 432 virqfd_disable(vdev, &vdev->ctx[0].mask);
397 vdev->irq_type = VFIO_PCI_NUM_IRQS; 433 vdev->irq_type = VFIO_PCI_NUM_IRQS;
398 vdev->num_ctx = 0; 434 vdev->num_ctx = 0;
399 kfree(vdev->ctx); 435 kfree(vdev->ctx);
@@ -539,8 +575,8 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix)
539 vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix); 575 vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix);
540 576
541 for (i = 0; i < vdev->num_ctx; i++) { 577 for (i = 0; i < vdev->num_ctx; i++) {
542 virqfd_disable(vdev->ctx[i].unmask); 578 virqfd_disable(vdev, &vdev->ctx[i].unmask);
543 virqfd_disable(vdev->ctx[i].mask); 579 virqfd_disable(vdev, &vdev->ctx[i].mask);
544 } 580 }
545 581
546 if (msix) { 582 if (msix) {
@@ -577,7 +613,7 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_device *vdev,
577 vfio_send_intx_eventfd, NULL, 613 vfio_send_intx_eventfd, NULL,
578 &vdev->ctx[0].unmask, fd); 614 &vdev->ctx[0].unmask, fd);
579 615
580 virqfd_disable(vdev->ctx[0].unmask); 616 virqfd_disable(vdev, &vdev->ctx[0].unmask);
581 } 617 }
582 618
583 return 0; 619 return 0;
diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c
index f75da8758adc..f49181c73113 100644
--- a/drivers/video/backlight/88pm860x_bl.c
+++ b/drivers/video/backlight/88pm860x_bl.c
@@ -228,7 +228,6 @@ static int pm860x_backlight_probe(struct platform_device *pdev)
228 data->port = pdata->flags; 228 data->port = pdata->flags;
229 if (data->port < 0) { 229 if (data->port < 0) {
230 dev_err(&pdev->dev, "wrong platform data is assigned"); 230 dev_err(&pdev->dev, "wrong platform data is assigned");
231 kfree(data);
232 return -EINVAL; 231 return -EINVAL;
233 } 232 }
234 233
diff --git a/drivers/video/exynos/exynos_mipi_dsi.c b/drivers/video/exynos/exynos_mipi_dsi.c
index 4bc2b8a5dd8b..663c308d0e73 100644
--- a/drivers/video/exynos/exynos_mipi_dsi.c
+++ b/drivers/video/exynos/exynos_mipi_dsi.c
@@ -461,7 +461,7 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev)
461done: 461done:
462 platform_set_drvdata(pdev, dsim); 462 platform_set_drvdata(pdev, dsim);
463 463
464 dev_dbg(&pdev->dev, "%s() completed sucessfuly (%s mode)\n", __func__, 464 dev_dbg(&pdev->dev, "%s() completed successfully (%s mode)\n", __func__,
465 dsim_config->e_interface == DSIM_COMMAND ? "CPU" : "RGB"); 465 dsim_config->e_interface == DSIM_COMMAND ? "CPU" : "RGB");
466 466
467 return 0; 467 return 0;
diff --git a/drivers/video/tmiofb.c b/drivers/video/tmiofb.c
index 8e4a446b5ed1..b244f060f151 100644
--- a/drivers/video/tmiofb.c
+++ b/drivers/video/tmiofb.c
@@ -694,6 +694,10 @@ static int __devinit tmiofb_probe(struct platform_device *dev)
694 dev_err(&dev->dev, "NULL platform data!\n"); 694 dev_err(&dev->dev, "NULL platform data!\n");
695 return -EINVAL; 695 return -EINVAL;
696 } 696 }
697 if (ccr == NULL || lcr == NULL || vram == NULL || irq < 0) {
698 dev_err(&dev->dev, "missing resources\n");
699 return -EINVAL;
700 }
697 701
698 info = framebuffer_alloc(sizeof(struct tmiofb_par), &dev->dev); 702 info = framebuffer_alloc(sizeof(struct tmiofb_par), &dev->dev);
699 703
diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c
index 530a2d309063..7c294f4dc0ed 100644
--- a/drivers/w1/masters/ds1wm.c
+++ b/drivers/w1/masters/ds1wm.c
@@ -349,7 +349,7 @@ static void ds1wm_search(void *data, struct w1_master *master_dev,
349 "pass: %d entering ASM\n", pass); 349 "pass: %d entering ASM\n", pass);
350 ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_SRA); 350 ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_SRA);
351 dev_dbg(&ds1wm_data->pdev->dev, 351 dev_dbg(&ds1wm_data->pdev->dev,
352 "pass: %d begining nibble loop\n", pass); 352 "pass: %d beginning nibble loop\n", pass);
353 353
354 r_prime = 0; 354 r_prime = 0;
355 d = 0; 355 d = 0;
diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
index 1eff743ec497..ae60406ea8a1 100644
--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -814,6 +814,9 @@ static int __devinit hpwdt_init_one(struct pci_dev *dev,
814 hpwdt_timer_reg = pci_mem_addr + 0x70; 814 hpwdt_timer_reg = pci_mem_addr + 0x70;
815 hpwdt_timer_con = pci_mem_addr + 0x72; 815 hpwdt_timer_con = pci_mem_addr + 0x72;
816 816
817 /* Make sure that timer is disabled until /dev/watchdog is opened */
818 hpwdt_stop();
819
817 /* Make sure that we have a valid soft_margin */ 820 /* Make sure that we have a valid soft_margin */
818 if (hpwdt_change_timer(soft_margin)) 821 if (hpwdt_change_timer(soft_margin))
819 hpwdt_change_timer(DEFAULT_MARGIN); 822 hpwdt_change_timer(DEFAULT_MARGIN);
diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 6aa46a90ff02..3796434991fa 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -128,11 +128,12 @@ EXPORT_SYMBOL_GPL(watchdog_register_device);
128void watchdog_unregister_device(struct watchdog_device *wdd) 128void watchdog_unregister_device(struct watchdog_device *wdd)
129{ 129{
130 int ret; 130 int ret;
131 int devno = wdd->cdev.dev; 131 int devno;
132 132
133 if (wdd == NULL) 133 if (wdd == NULL)
134 return; 134 return;
135 135
136 devno = wdd->cdev.dev;
136 ret = watchdog_dev_unregister(wdd); 137 ret = watchdog_dev_unregister(wdd);
137 if (ret) 138 if (ret)
138 pr_err("error unregistering /dev/watchdog (err=%d)\n", ret); 139 pr_err("error unregistering /dev/watchdog (err=%d)\n", ret);
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 1ffd03bf8e10..7f1241608489 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -314,8 +314,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
314 } 314 }
315 } 315 }
316 316
317 err = gnttab_unmap_refs(map->unmap_ops + offset, map->pages + offset, 317 err = gnttab_unmap_refs(map->unmap_ops + offset,
318 pages, true); 318 use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset,
319 pages);
319 if (err) 320 if (err)
320 return err; 321 return err;
321 322
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 0bfc1ef11259..006726688baf 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -870,7 +870,8 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
870EXPORT_SYMBOL_GPL(gnttab_map_refs); 870EXPORT_SYMBOL_GPL(gnttab_map_refs);
871 871
872int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, 872int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
873 struct page **pages, unsigned int count, bool clear_pte) 873 struct gnttab_map_grant_ref *kmap_ops,
874 struct page **pages, unsigned int count)
874{ 875{
875 int i, ret; 876 int i, ret;
876 bool lazy = false; 877 bool lazy = false;
@@ -888,7 +889,8 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
888 } 889 }
889 890
890 for (i = 0; i < count; i++) { 891 for (i = 0; i < count; i++) {
891 ret = m2p_remove_override(pages[i], clear_pte); 892 ret = m2p_remove_override(pages[i], kmap_ops ?
893 &kmap_ops[i] : NULL);
892 if (ret) 894 if (ret)
893 return ret; 895 return ret;
894 } 896 }
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0d195b507660..9821b672f5a2 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -116,7 +116,7 @@ struct btrfs_ordered_sum;
116#define BTRFS_FREE_SPACE_OBJECTID -11ULL 116#define BTRFS_FREE_SPACE_OBJECTID -11ULL
117 117
118/* 118/*
119 * The inode number assigned to the special inode for sotring 119 * The inode number assigned to the special inode for storing
120 * free ino cache 120 * free ino cache
121 */ 121 */
122#define BTRFS_FREE_INO_OBJECTID -12ULL 122#define BTRFS_FREE_INO_OBJECTID -12ULL
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index ab5300595847..c9d703693df0 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -18,7 +18,7 @@
18#ifndef __DELAYED_REF__ 18#ifndef __DELAYED_REF__
19#define __DELAYED_REF__ 19#define __DELAYED_REF__
20 20
21/* these are the possible values of struct btrfs_delayed_ref->action */ 21/* these are the possible values of struct btrfs_delayed_ref_node->action */
22#define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */ 22#define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */
23#define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */ 23#define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */
24#define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */ 24#define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index ec154f954646..316b07a866d2 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1971,8 +1971,8 @@ out:
1971 ordered_extent->len - 1, NULL, GFP_NOFS); 1971 ordered_extent->len - 1, NULL, GFP_NOFS);
1972 1972
1973 /* 1973 /*
1974 * This needs to be dont to make sure anybody waiting knows we are done 1974 * This needs to be done to make sure anybody waiting knows we are done
1975 * upating everything for this ordered extent. 1975 * updating everything for this ordered extent.
1976 */ 1976 */
1977 btrfs_remove_ordered_extent(inode, ordered_extent); 1977 btrfs_remove_ordered_extent(inode, ordered_extent);
1978 1978
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 38b42e7bc91d..b65015581744 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1371,10 +1371,8 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
1371 1371
1372 if (srcid) { 1372 if (srcid) {
1373 srcgroup = find_qgroup_rb(fs_info, srcid); 1373 srcgroup = find_qgroup_rb(fs_info, srcid);
1374 if (!srcgroup) { 1374 if (!srcgroup)
1375 ret = -EINVAL;
1376 goto unlock; 1375 goto unlock;
1377 }
1378 dstgroup->rfer = srcgroup->rfer - level_size; 1376 dstgroup->rfer = srcgroup->rfer - level_size;
1379 dstgroup->rfer_cmpr = srcgroup->rfer_cmpr - level_size; 1377 dstgroup->rfer_cmpr = srcgroup->rfer_cmpr - level_size;
1380 srcgroup->excl = level_size; 1378 srcgroup->excl = level_size;
@@ -1383,10 +1381,8 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
1383 qgroup_dirty(fs_info, srcgroup); 1381 qgroup_dirty(fs_info, srcgroup);
1384 } 1382 }
1385 1383
1386 if (!inherit) { 1384 if (!inherit)
1387 ret = -EINVAL;
1388 goto unlock; 1385 goto unlock;
1389 }
1390 1386
1391 i_qgroups = (u64 *)(inherit + 1); 1387 i_qgroups = (u64 *)(inherit + 1);
1392 for (i = 0; i < inherit->num_qgroups; ++i) { 1388 for (i = 0; i < inherit->num_qgroups; ++i) {
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 7dab9c04ad52..53cf2aabce87 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -328,7 +328,7 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
328 } 328 }
329 329
330ctoUTF16_out: 330ctoUTF16_out:
331 return i; 331 return j;
332} 332}
333 333
334#ifdef CONFIG_CIFS_SMB2 334#ifdef CONFIG_CIFS_SMB2
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 9154192b0683..71e9ad9f5961 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -917,7 +917,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
917 if (!buf) { 917 if (!buf) {
918 mutex_unlock(&cinode->lock_mutex); 918 mutex_unlock(&cinode->lock_mutex);
919 free_xid(xid); 919 free_xid(xid);
920 return rc; 920 return -ENOMEM;
921 } 921 }
922 922
923 for (i = 0; i < 2; i++) { 923 for (i = 0; i < 2; i++) {
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
index c5fbfac5d576..15dc8eea8273 100644
--- a/fs/cifs/smb2pdu.h
+++ b/fs/cifs/smb2pdu.h
@@ -96,7 +96,7 @@
96 * 96 *
97 */ 97 */
98 98
99#define SMB2_HEADER_STRUCTURE_SIZE __constant_le16_to_cpu(64) 99#define SMB2_HEADER_STRUCTURE_SIZE __constant_cpu_to_le16(64)
100 100
101struct smb2_hdr { 101struct smb2_hdr {
102 __be32 smb2_buf_length; /* big endian on wire */ 102 __be32 smb2_buf_length; /* big endian on wire */
@@ -140,7 +140,7 @@ struct smb2_pdu {
140 * 140 *
141 */ 141 */
142 142
143#define SMB2_ERROR_STRUCTURE_SIZE2 __constant_le16_to_cpu(9) 143#define SMB2_ERROR_STRUCTURE_SIZE2 __constant_cpu_to_le16(9)
144 144
145struct smb2_err_rsp { 145struct smb2_err_rsp {
146 struct smb2_hdr hdr; 146 struct smb2_hdr hdr;
diff --git a/fs/dcache.c b/fs/dcache.c
index 8086636bf796..693f95bf1cae 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -389,7 +389,7 @@ static struct dentry *d_kill(struct dentry *dentry, struct dentry *parent)
389 * Inform try_to_ascend() that we are no longer attached to the 389 * Inform try_to_ascend() that we are no longer attached to the
390 * dentry tree 390 * dentry tree
391 */ 391 */
392 dentry->d_flags |= DCACHE_DISCONNECTED; 392 dentry->d_flags |= DCACHE_DENTRY_KILLED;
393 if (parent) 393 if (parent)
394 spin_unlock(&parent->d_lock); 394 spin_unlock(&parent->d_lock);
395 dentry_iput(dentry); 395 dentry_iput(dentry);
@@ -1048,7 +1048,7 @@ static struct dentry *try_to_ascend(struct dentry *old, int locked, unsigned seq
1048 * or deletion 1048 * or deletion
1049 */ 1049 */
1050 if (new != old->d_parent || 1050 if (new != old->d_parent ||
1051 (old->d_flags & DCACHE_DISCONNECTED) || 1051 (old->d_flags & DCACHE_DENTRY_KILLED) ||
1052 (!locked && read_seqretry(&rename_lock, seq))) { 1052 (!locked && read_seqretry(&rename_lock, seq))) {
1053 spin_unlock(&new->d_lock); 1053 spin_unlock(&new->d_lock);
1054 new = NULL; 1054 new = NULL;
@@ -1134,6 +1134,8 @@ positive:
1134 return 1; 1134 return 1;
1135 1135
1136rename_retry: 1136rename_retry:
1137 if (locked)
1138 goto again;
1137 locked = 1; 1139 locked = 1;
1138 write_seqlock(&rename_lock); 1140 write_seqlock(&rename_lock);
1139 goto again; 1141 goto again;
@@ -1141,7 +1143,7 @@ rename_retry:
1141EXPORT_SYMBOL(have_submounts); 1143EXPORT_SYMBOL(have_submounts);
1142 1144
1143/* 1145/*
1144 * Search the dentry child list for the specified parent, 1146 * Search the dentry child list of the specified parent,
1145 * and move any unused dentries to the end of the unused 1147 * and move any unused dentries to the end of the unused
1146 * list for prune_dcache(). We descend to the next level 1148 * list for prune_dcache(). We descend to the next level
1147 * whenever the d_subdirs list is non-empty and continue 1149 * whenever the d_subdirs list is non-empty and continue
@@ -1236,6 +1238,8 @@ out:
1236rename_retry: 1238rename_retry:
1237 if (found) 1239 if (found)
1238 return found; 1240 return found;
1241 if (locked)
1242 goto again;
1239 locked = 1; 1243 locked = 1;
1240 write_seqlock(&rename_lock); 1244 write_seqlock(&rename_lock);
1241 goto again; 1245 goto again;
@@ -3035,6 +3039,8 @@ resume:
3035 return; 3039 return;
3036 3040
3037rename_retry: 3041rename_retry:
3042 if (locked)
3043 goto again;
3038 locked = 1; 3044 locked = 1;
3039 write_seqlock(&rename_lock); 3045 write_seqlock(&rename_lock);
3040 goto again; 3046 goto again;
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 2340f6978d6e..c5ca6ae5a30c 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -526,73 +526,51 @@ struct array_data {
526 u32 elements; 526 u32 elements;
527}; 527};
528 528
529static int u32_array_open(struct inode *inode, struct file *file) 529static size_t u32_format_array(char *buf, size_t bufsize,
530{ 530 u32 *array, int array_size)
531 file->private_data = NULL;
532 return nonseekable_open(inode, file);
533}
534
535static size_t format_array(char *buf, size_t bufsize, const char *fmt,
536 u32 *array, u32 array_size)
537{ 531{
538 size_t ret = 0; 532 size_t ret = 0;
539 u32 i;
540 533
541 for (i = 0; i < array_size; i++) { 534 while (--array_size >= 0) {
542 size_t len; 535 size_t len;
536 char term = array_size ? ' ' : '\n';
543 537
544 len = snprintf(buf, bufsize, fmt, array[i]); 538 len = snprintf(buf, bufsize, "%u%c", *array++, term);
545 len++; /* ' ' or '\n' */
546 ret += len; 539 ret += len;
547 540
548 if (buf) { 541 buf += len;
549 buf += len; 542 bufsize -= len;
550 bufsize -= len;
551 buf[-1] = (i == array_size-1) ? '\n' : ' ';
552 }
553 } 543 }
554
555 ret++; /* \0 */
556 if (buf)
557 *buf = '\0';
558
559 return ret; 544 return ret;
560} 545}
561 546
562static char *format_array_alloc(const char *fmt, u32 *array, 547static int u32_array_open(struct inode *inode, struct file *file)
563 u32 array_size)
564{ 548{
565 size_t len = format_array(NULL, 0, fmt, array, array_size); 549 struct array_data *data = inode->i_private;
566 char *ret; 550 int size, elements = data->elements;
567 551 char *buf;
568 ret = kmalloc(len, GFP_KERNEL); 552
569 if (ret == NULL) 553 /*
570 return NULL; 554 * Max size:
555 * - 10 digits + ' '/'\n' = 11 bytes per number
556 * - terminating NUL character
557 */
558 size = elements*11;
559 buf = kmalloc(size+1, GFP_KERNEL);
560 if (!buf)
561 return -ENOMEM;
562 buf[size] = 0;
563
564 file->private_data = buf;
565 u32_format_array(buf, size, data->array, data->elements);
571 566
572 format_array(ret, len, fmt, array, array_size); 567 return nonseekable_open(inode, file);
573 return ret;
574} 568}
575 569
576static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len, 570static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len,
577 loff_t *ppos) 571 loff_t *ppos)
578{ 572{
579 struct inode *inode = file->f_path.dentry->d_inode; 573 size_t size = strlen(file->private_data);
580 struct array_data *data = inode->i_private;
581 size_t size;
582
583 if (*ppos == 0) {
584 if (file->private_data) {
585 kfree(file->private_data);
586 file->private_data = NULL;
587 }
588
589 file->private_data = format_array_alloc("%u", data->array,
590 data->elements);
591 }
592
593 size = 0;
594 if (file->private_data)
595 size = strlen(file->private_data);
596 574
597 return simple_read_from_buffer(buf, len, ppos, 575 return simple_read_from_buffer(buf, len, ppos,
598 file->private_data, size); 576 file->private_data, size);
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index 44ce5c6a541d..d45ba4568128 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -275,8 +275,14 @@ out:
275 275
276static int ecryptfs_flush(struct file *file, fl_owner_t td) 276static int ecryptfs_flush(struct file *file, fl_owner_t td)
277{ 277{
278 return file->f_mode & FMODE_WRITE 278 struct file *lower_file = ecryptfs_file_to_lower(file);
279 ? filemap_write_and_wait(file->f_mapping) : 0; 279
280 if (lower_file->f_op && lower_file->f_op->flush) {
281 filemap_write_and_wait(file->f_mapping);
282 return lower_file->f_op->flush(lower_file, td);
283 }
284
285 return 0;
280} 286}
281 287
282static int ecryptfs_release(struct inode *inode, struct file *file) 288static int ecryptfs_release(struct inode *inode, struct file *file)
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 534b129ea676..cc7709e7c508 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -619,6 +619,7 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
619 struct dentry *lower_old_dir_dentry; 619 struct dentry *lower_old_dir_dentry;
620 struct dentry *lower_new_dir_dentry; 620 struct dentry *lower_new_dir_dentry;
621 struct dentry *trap = NULL; 621 struct dentry *trap = NULL;
622 struct inode *target_inode;
622 623
623 lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); 624 lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
624 lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); 625 lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
@@ -626,6 +627,7 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
626 dget(lower_new_dentry); 627 dget(lower_new_dentry);
627 lower_old_dir_dentry = dget_parent(lower_old_dentry); 628 lower_old_dir_dentry = dget_parent(lower_old_dentry);
628 lower_new_dir_dentry = dget_parent(lower_new_dentry); 629 lower_new_dir_dentry = dget_parent(lower_new_dentry);
630 target_inode = new_dentry->d_inode;
629 trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); 631 trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
630 /* source should not be ancestor of target */ 632 /* source should not be ancestor of target */
631 if (trap == lower_old_dentry) { 633 if (trap == lower_old_dentry) {
@@ -641,6 +643,9 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
641 lower_new_dir_dentry->d_inode, lower_new_dentry); 643 lower_new_dir_dentry->d_inode, lower_new_dentry);
642 if (rc) 644 if (rc)
643 goto out_lock; 645 goto out_lock;
646 if (target_inode)
647 fsstack_copy_attr_all(target_inode,
648 ecryptfs_inode_to_lower(target_inode));
644 fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); 649 fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode);
645 if (new_dir != old_dir) 650 if (new_dir != old_dir)
646 fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); 651 fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode);
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 2768138eefee..9b627c15010a 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -162,6 +162,7 @@ void ecryptfs_put_lower_file(struct inode *inode)
162 inode_info = ecryptfs_inode_to_private(inode); 162 inode_info = ecryptfs_inode_to_private(inode);
163 if (atomic_dec_and_mutex_lock(&inode_info->lower_file_count, 163 if (atomic_dec_and_mutex_lock(&inode_info->lower_file_count,
164 &inode_info->lower_file_mutex)) { 164 &inode_info->lower_file_mutex)) {
165 filemap_write_and_wait(inode->i_mapping);
165 fput(inode_info->lower_file); 166 fput(inode_info->lower_file);
166 inode_info->lower_file = NULL; 167 inode_info->lower_file = NULL;
167 mutex_unlock(&inode_info->lower_file_mutex); 168 mutex_unlock(&inode_info->lower_file_mutex);
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 376aa77f3ca7..2616d0ea5c5c 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -479,7 +479,7 @@ void ext2_discard_reservation(struct inode *inode)
479/** 479/**
480 * ext2_free_blocks() -- Free given blocks and update quota and i_blocks 480 * ext2_free_blocks() -- Free given blocks and update quota and i_blocks
481 * @inode: inode 481 * @inode: inode
482 * @block: start physcial block to free 482 * @block: start physical block to free
483 * @count: number of blocks to free 483 * @count: number of blocks to free
484 */ 484 */
485void ext2_free_blocks (struct inode * inode, unsigned long block, 485void ext2_free_blocks (struct inode * inode, unsigned long block,
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
index 90d901f0486b..7320a66e958f 100644
--- a/fs/ext3/balloc.c
+++ b/fs/ext3/balloc.c
@@ -483,7 +483,7 @@ void ext3_discard_reservation(struct inode *inode)
483 * ext3_free_blocks_sb() -- Free given blocks and update quota 483 * ext3_free_blocks_sb() -- Free given blocks and update quota
484 * @handle: handle to this transaction 484 * @handle: handle to this transaction
485 * @sb: super block 485 * @sb: super block
486 * @block: start physcial block to free 486 * @block: start physical block to free
487 * @count: number of blocks to free 487 * @count: number of blocks to free
488 * @pdquot_freed_blocks: pointer to quota 488 * @pdquot_freed_blocks: pointer to quota
489 */ 489 */
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index a07597307fd1..7e87e37a372a 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -3072,6 +3072,8 @@ static int ext3_do_update_inode(handle_t *handle,
3072 struct ext3_inode_info *ei = EXT3_I(inode); 3072 struct ext3_inode_info *ei = EXT3_I(inode);
3073 struct buffer_head *bh = iloc->bh; 3073 struct buffer_head *bh = iloc->bh;
3074 int err = 0, rc, block; 3074 int err = 0, rc, block;
3075 int need_datasync = 0;
3076 __le32 disksize;
3075 uid_t i_uid; 3077 uid_t i_uid;
3076 gid_t i_gid; 3078 gid_t i_gid;
3077 3079
@@ -3113,7 +3115,11 @@ again:
3113 raw_inode->i_gid_high = 0; 3115 raw_inode->i_gid_high = 0;
3114 } 3116 }
3115 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink); 3117 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3116 raw_inode->i_size = cpu_to_le32(ei->i_disksize); 3118 disksize = cpu_to_le32(ei->i_disksize);
3119 if (disksize != raw_inode->i_size) {
3120 need_datasync = 1;
3121 raw_inode->i_size = disksize;
3122 }
3117 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec); 3123 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3118 raw_inode->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec); 3124 raw_inode->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec);
3119 raw_inode->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec); 3125 raw_inode->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec);
@@ -3129,8 +3135,11 @@ again:
3129 if (!S_ISREG(inode->i_mode)) { 3135 if (!S_ISREG(inode->i_mode)) {
3130 raw_inode->i_dir_acl = cpu_to_le32(ei->i_dir_acl); 3136 raw_inode->i_dir_acl = cpu_to_le32(ei->i_dir_acl);
3131 } else { 3137 } else {
3132 raw_inode->i_size_high = 3138 disksize = cpu_to_le32(ei->i_disksize >> 32);
3133 cpu_to_le32(ei->i_disksize >> 32); 3139 if (disksize != raw_inode->i_size_high) {
3140 raw_inode->i_size_high = disksize;
3141 need_datasync = 1;
3142 }
3134 if (ei->i_disksize > 0x7fffffffULL) { 3143 if (ei->i_disksize > 0x7fffffffULL) {
3135 struct super_block *sb = inode->i_sb; 3144 struct super_block *sb = inode->i_sb;
3136 if (!EXT3_HAS_RO_COMPAT_FEATURE(sb, 3145 if (!EXT3_HAS_RO_COMPAT_FEATURE(sb,
@@ -3183,6 +3192,8 @@ again:
3183 ext3_clear_inode_state(inode, EXT3_STATE_NEW); 3192 ext3_clear_inode_state(inode, EXT3_STATE_NEW);
3184 3193
3185 atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid); 3194 atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid);
3195 if (need_datasync)
3196 atomic_set(&ei->i_datasync_tid, handle->h_transaction->t_tid);
3186out_brelse: 3197out_brelse:
3187 brelse (bh); 3198 brelse (bh);
3188 ext3_std_error(inode->i_sb, err); 3199 ext3_std_error(inode->i_sb, err);
@@ -3196,7 +3207,7 @@ out_brelse:
3196 * 3207 *
3197 * - Within generic_file_write() for O_SYNC files. 3208 * - Within generic_file_write() for O_SYNC files.
3198 * Here, there will be no transaction running. We wait for any running 3209 * Here, there will be no transaction running. We wait for any running
3199 * trasnaction to commit. 3210 * transaction to commit.
3200 * 3211 *
3201 * - Within sys_sync(), kupdate and such. 3212 * - Within sys_sync(), kupdate and such.
3202 * We wait on commit, if tol to. 3213 * We wait on commit, if tol to.
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index dff171c3a123..c862ee5fe79d 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3313,7 +3313,7 @@ int ext4_discard_partial_page_buffers(handle_t *handle,
3313 * handle: The journal handle 3313 * handle: The journal handle
3314 * inode: The files inode 3314 * inode: The files inode
3315 * page: A locked page that contains the offset "from" 3315 * page: A locked page that contains the offset "from"
3316 * from: The starting byte offset (from the begining of the file) 3316 * from: The starting byte offset (from the beginning of the file)
3317 * to begin discarding 3317 * to begin discarding
3318 * len: The length of bytes to discard 3318 * len: The length of bytes to discard
3319 * flags: Optional flags that may be used: 3319 * flags: Optional flags that may be used:
@@ -3321,11 +3321,11 @@ int ext4_discard_partial_page_buffers(handle_t *handle,
3321 * EXT4_DISCARD_PARTIAL_PG_ZERO_UNMAPPED 3321 * EXT4_DISCARD_PARTIAL_PG_ZERO_UNMAPPED
3322 * Only zero the regions of the page whose buffer heads 3322 * Only zero the regions of the page whose buffer heads
3323 * have already been unmapped. This flag is appropriate 3323 * have already been unmapped. This flag is appropriate
3324 * for updateing the contents of a page whose blocks may 3324 * for updating the contents of a page whose blocks may
3325 * have already been released, and we only want to zero 3325 * have already been released, and we only want to zero
3326 * out the regions that correspond to those released blocks. 3326 * out the regions that correspond to those released blocks.
3327 * 3327 *
3328 * Returns zero on sucess or negative on failure. 3328 * Returns zero on success or negative on failure.
3329 */ 3329 */
3330static int ext4_discard_partial_page_buffers_no_lock(handle_t *handle, 3330static int ext4_discard_partial_page_buffers_no_lock(handle_t *handle,
3331 struct inode *inode, struct page *page, loff_t from, 3331 struct inode *inode, struct page *page, loff_t from,
@@ -3486,7 +3486,7 @@ int ext4_can_truncate(struct inode *inode)
3486 * @offset: The offset where the hole will begin 3486 * @offset: The offset where the hole will begin
3487 * @len: The length of the hole 3487 * @len: The length of the hole
3488 * 3488 *
3489 * Returns: 0 on sucess or negative on failure 3489 * Returns: 0 on success or negative on failure
3490 */ 3490 */
3491 3491
3492int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) 3492int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
@@ -4008,7 +4008,7 @@ static int ext4_inode_blocks_set(handle_t *handle,
4008 4008
4009 if (i_blocks <= ~0U) { 4009 if (i_blocks <= ~0U) {
4010 /* 4010 /*
4011 * i_blocks can be represnted in a 32 bit variable 4011 * i_blocks can be represented in a 32 bit variable
4012 * as multiple of 512 bytes 4012 * as multiple of 512 bytes
4013 */ 4013 */
4014 raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); 4014 raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
@@ -4169,7 +4169,7 @@ out_brelse:
4169 * 4169 *
4170 * - Within generic_file_write() for O_SYNC files. 4170 * - Within generic_file_write() for O_SYNC files.
4171 * Here, there will be no transaction running. We wait for any running 4171 * Here, there will be no transaction running. We wait for any running
4172 * trasnaction to commit. 4172 * transaction to commit.
4173 * 4173 *
4174 * - Within sys_sync(), kupdate and such. 4174 * - Within sys_sync(), kupdate and such.
4175 * We wait on commit, if tol to. 4175 * We wait on commit, if tol to.
@@ -4413,7 +4413,7 @@ static int ext4_index_trans_blocks(struct inode *inode, int nrblocks, int chunk)
4413 * worse case, the indexs blocks spread over different block groups 4413 * worse case, the indexs blocks spread over different block groups
4414 * 4414 *
4415 * If datablocks are discontiguous, they are possible to spread over 4415 * If datablocks are discontiguous, they are possible to spread over
4416 * different block groups too. If they are contiuguous, with flexbg, 4416 * different block groups too. If they are contiguous, with flexbg,
4417 * they could still across block group boundary. 4417 * they could still across block group boundary.
4418 * 4418 *
4419 * Also account for superblock, inode, quota and xattr blocks 4419 * Also account for superblock, inode, quota and xattr blocks
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 8eae94771c45..08778f6cdfe9 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4709,7 +4709,7 @@ error_return:
4709 * ext4_group_add_blocks() -- Add given blocks to an existing group 4709 * ext4_group_add_blocks() -- Add given blocks to an existing group
4710 * @handle: handle to this transaction 4710 * @handle: handle to this transaction
4711 * @sb: super block 4711 * @sb: super block
4712 * @block: start physcial block to add to the block group 4712 * @block: start physical block to add to the block group
4713 * @count: number of blocks to free 4713 * @count: number of blocks to free
4714 * 4714 *
4715 * This marks the blocks as free in the bitmap and buddy. 4715 * This marks the blocks as free in the bitmap and buddy.
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index be3efc4f64f4..6d46c0d78338 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -577,10 +577,6 @@ static long writeback_chunk_size(struct backing_dev_info *bdi,
577/* 577/*
578 * Write a portion of b_io inodes which belong to @sb. 578 * Write a portion of b_io inodes which belong to @sb.
579 * 579 *
580 * If @only_this_sb is true, then find and write all such
581 * inodes. Otherwise write only ones which go sequentially
582 * in reverse order.
583 *
584 * Return the number of pages and/or inodes written. 580 * Return the number of pages and/or inodes written.
585 */ 581 */
586static long writeback_sb_inodes(struct super_block *sb, 582static long writeback_sb_inodes(struct super_block *sb,
diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index 03ff5b1eba93..75a20c092dd4 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -117,7 +117,7 @@ static ssize_t fuse_conn_max_background_write(struct file *file,
117 const char __user *buf, 117 const char __user *buf,
118 size_t count, loff_t *ppos) 118 size_t count, loff_t *ppos)
119{ 119{
120 unsigned val; 120 unsigned uninitialized_var(val);
121 ssize_t ret; 121 ssize_t ret;
122 122
123 ret = fuse_conn_limit_write(file, buf, count, ppos, &val, 123 ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
@@ -154,7 +154,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
154 const char __user *buf, 154 const char __user *buf,
155 size_t count, loff_t *ppos) 155 size_t count, loff_t *ppos)
156{ 156{
157 unsigned val; 157 unsigned uninitialized_var(val);
158 ssize_t ret; 158 ssize_t ret;
159 159
160 ret = fuse_conn_limit_write(file, buf, count, ppos, &val, 160 ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
index 3426521f3205..ee8d55042298 100644
--- a/fs/fuse/cuse.c
+++ b/fs/fuse/cuse.c
@@ -396,7 +396,7 @@ err_device:
396err_region: 396err_region:
397 unregister_chrdev_region(devt, 1); 397 unregister_chrdev_region(devt, 1);
398err: 398err:
399 fc->conn_error = 1; 399 fuse_conn_kill(fc);
400 goto out; 400 goto out;
401} 401}
402 402
@@ -532,8 +532,6 @@ static int cuse_channel_release(struct inode *inode, struct file *file)
532 cdev_del(cc->cdev); 532 cdev_del(cc->cdev);
533 } 533 }
534 534
535 /* kill connection and shutdown channel */
536 fuse_conn_kill(&cc->fc);
537 rc = fuse_dev_release(inode, file); /* puts the base reference */ 535 rc = fuse_dev_release(inode, file); /* puts the base reference */
538 536
539 return rc; 537 return rc;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 7df2b5e8fbe1..f4246cfc8d87 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1576,6 +1576,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct inode *inode,
1576 req->pages[req->num_pages] = page; 1576 req->pages[req->num_pages] = page;
1577 req->num_pages++; 1577 req->num_pages++;
1578 1578
1579 offset = 0;
1579 num -= this_num; 1580 num -= this_num;
1580 total_len += this_num; 1581 total_len += this_num;
1581 index++; 1582 index++;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index ce0a2838ccd0..fca222dabe3c 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -367,11 +367,6 @@ void fuse_conn_kill(struct fuse_conn *fc)
367 wake_up_all(&fc->waitq); 367 wake_up_all(&fc->waitq);
368 wake_up_all(&fc->blocked_waitq); 368 wake_up_all(&fc->blocked_waitq);
369 wake_up_all(&fc->reserved_req_waitq); 369 wake_up_all(&fc->reserved_req_waitq);
370 mutex_lock(&fuse_mutex);
371 list_del(&fc->entry);
372 fuse_ctl_remove_conn(fc);
373 mutex_unlock(&fuse_mutex);
374 fuse_bdi_destroy(fc);
375} 370}
376EXPORT_SYMBOL_GPL(fuse_conn_kill); 371EXPORT_SYMBOL_GPL(fuse_conn_kill);
377 372
@@ -380,7 +375,14 @@ static void fuse_put_super(struct super_block *sb)
380 struct fuse_conn *fc = get_fuse_conn_super(sb); 375 struct fuse_conn *fc = get_fuse_conn_super(sb);
381 376
382 fuse_send_destroy(fc); 377 fuse_send_destroy(fc);
378
383 fuse_conn_kill(fc); 379 fuse_conn_kill(fc);
380 mutex_lock(&fuse_mutex);
381 list_del(&fc->entry);
382 fuse_ctl_remove_conn(fc);
383 mutex_unlock(&fuse_mutex);
384 fuse_bdi_destroy(fc);
385
384 fuse_conn_put(fc); 386 fuse_conn_put(fc);
385} 387}
386 388
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index d6526347d386..01c4975da4bc 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -612,6 +612,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
612 struct gfs2_sbd *sdp = GFS2_SB(mapping->host); 612 struct gfs2_sbd *sdp = GFS2_SB(mapping->host);
613 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); 613 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
614 unsigned int data_blocks = 0, ind_blocks = 0, rblocks; 614 unsigned int data_blocks = 0, ind_blocks = 0, rblocks;
615 unsigned requested = 0;
615 int alloc_required; 616 int alloc_required;
616 int error = 0; 617 int error = 0;
617 pgoff_t index = pos >> PAGE_CACHE_SHIFT; 618 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
@@ -641,7 +642,8 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
641 if (error) 642 if (error)
642 goto out_unlock; 643 goto out_unlock;
643 644
644 error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks); 645 requested = data_blocks + ind_blocks;
646 error = gfs2_inplace_reserve(ip, requested);
645 if (error) 647 if (error)
646 goto out_qunlock; 648 goto out_qunlock;
647 } 649 }
@@ -654,7 +656,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
654 if (&ip->i_inode == sdp->sd_rindex) 656 if (&ip->i_inode == sdp->sd_rindex)
655 rblocks += 2 * RES_STATFS; 657 rblocks += 2 * RES_STATFS;
656 if (alloc_required) 658 if (alloc_required)
657 rblocks += gfs2_rg_blocks(ip); 659 rblocks += gfs2_rg_blocks(ip, requested);
658 660
659 error = gfs2_trans_begin(sdp, rblocks, 661 error = gfs2_trans_begin(sdp, rblocks,
660 PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize); 662 PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize);
@@ -868,8 +870,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
868 brelse(dibh); 870 brelse(dibh);
869failed: 871failed:
870 gfs2_trans_end(sdp); 872 gfs2_trans_end(sdp);
871 if (gfs2_mb_reserved(ip)) 873 gfs2_inplace_release(ip);
872 gfs2_inplace_release(ip);
873 if (ip->i_res->rs_qa_qd_num) 874 if (ip->i_res->rs_qa_qd_num)
874 gfs2_quota_unlock(ip); 875 gfs2_quota_unlock(ip);
875 if (inode == sdp->sd_rindex) { 876 if (inode == sdp->sd_rindex) {
@@ -1023,7 +1024,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb,
1023 offset, nr_segs, gfs2_get_block_direct, 1024 offset, nr_segs, gfs2_get_block_direct,
1024 NULL, NULL, 0); 1025 NULL, NULL, 0);
1025out: 1026out:
1026 gfs2_glock_dq_m(1, &gh); 1027 gfs2_glock_dq(&gh);
1027 gfs2_holder_uninit(&gh); 1028 gfs2_holder_uninit(&gh);
1028 return rv; 1029 return rv;
1029} 1030}
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 49cd7dd4a9fa..1fd3ae237bdd 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -786,7 +786,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
786 goto out_rlist; 786 goto out_rlist;
787 787
788 if (gfs2_rs_active(ip->i_res)) /* needs to be done with the rgrp glock held */ 788 if (gfs2_rs_active(ip->i_res)) /* needs to be done with the rgrp glock held */
789 gfs2_rs_deltree(ip->i_res); 789 gfs2_rs_deltree(ip, ip->i_res);
790 790
791 error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + 791 error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE +
792 RES_INDIRECT + RES_STATFS + RES_QUOTA, 792 RES_INDIRECT + RES_STATFS + RES_QUOTA,
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index d1d791ef38de..30e21997a1a1 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -323,6 +323,29 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
323} 323}
324 324
325/** 325/**
326 * gfs2_size_hint - Give a hint to the size of a write request
327 * @file: The struct file
328 * @offset: The file offset of the write
329 * @size: The length of the write
330 *
331 * When we are about to do a write, this function records the total
332 * write size in order to provide a suitable hint to the lower layers
333 * about how many blocks will be required.
334 *
335 */
336
337static void gfs2_size_hint(struct file *filep, loff_t offset, size_t size)
338{
339 struct inode *inode = filep->f_dentry->d_inode;
340 struct gfs2_sbd *sdp = GFS2_SB(inode);
341 struct gfs2_inode *ip = GFS2_I(inode);
342 size_t blks = (size + sdp->sd_sb.sb_bsize - 1) >> sdp->sd_sb.sb_bsize_shift;
343 int hint = min_t(size_t, INT_MAX, blks);
344
345 atomic_set(&ip->i_res->rs_sizehint, hint);
346}
347
348/**
326 * gfs2_allocate_page_backing - Use bmap to allocate blocks 349 * gfs2_allocate_page_backing - Use bmap to allocate blocks
327 * @page: The (locked) page to allocate backing for 350 * @page: The (locked) page to allocate backing for
328 * 351 *
@@ -382,8 +405,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
382 if (ret) 405 if (ret)
383 return ret; 406 return ret;
384 407
385 atomic_set(&ip->i_res->rs_sizehint, 408 gfs2_size_hint(vma->vm_file, pos, PAGE_CACHE_SIZE);
386 PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift);
387 409
388 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); 410 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
389 ret = gfs2_glock_nq(&gh); 411 ret = gfs2_glock_nq(&gh);
@@ -419,7 +441,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
419 rblocks += data_blocks ? data_blocks : 1; 441 rblocks += data_blocks ? data_blocks : 1;
420 if (ind_blocks || data_blocks) { 442 if (ind_blocks || data_blocks) {
421 rblocks += RES_STATFS + RES_QUOTA; 443 rblocks += RES_STATFS + RES_QUOTA;
422 rblocks += gfs2_rg_blocks(ip); 444 rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks);
423 } 445 }
424 ret = gfs2_trans_begin(sdp, rblocks, 0); 446 ret = gfs2_trans_begin(sdp, rblocks, 0);
425 if (ret) 447 if (ret)
@@ -663,7 +685,8 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
663 if (ret) 685 if (ret)
664 return ret; 686 return ret;
665 687
666 atomic_set(&ip->i_res->rs_sizehint, writesize >> sdp->sd_sb.sb_bsize_shift); 688 gfs2_size_hint(file, pos, writesize);
689
667 if (file->f_flags & O_APPEND) { 690 if (file->f_flags & O_APPEND) {
668 struct gfs2_holder gh; 691 struct gfs2_holder gh;
669 692
@@ -789,7 +812,7 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset,
789 if (unlikely(error)) 812 if (unlikely(error))
790 goto out_uninit; 813 goto out_uninit;
791 814
792 atomic_set(&ip->i_res->rs_sizehint, len >> sdp->sd_sb.sb_bsize_shift); 815 gfs2_size_hint(file, offset, len);
793 816
794 while (len > 0) { 817 while (len > 0) {
795 if (len < bytes) 818 if (len < bytes)
@@ -822,7 +845,7 @@ retry:
822 &max_bytes, &data_blocks, &ind_blocks); 845 &max_bytes, &data_blocks, &ind_blocks);
823 846
824 rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + 847 rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA +
825 RES_RG_HDR + gfs2_rg_blocks(ip); 848 RES_RG_HDR + gfs2_rg_blocks(ip, data_blocks + ind_blocks);
826 if (gfs2_is_jdata(ip)) 849 if (gfs2_is_jdata(ip))
827 rblocks += data_blocks ? data_blocks : 1; 850 rblocks += data_blocks ? data_blocks : 1;
828 851
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 1ed81f40da0d..e6c2fd53cab2 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -186,20 +186,6 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
186} 186}
187 187
188/** 188/**
189 * __gfs2_glock_schedule_for_reclaim - Add a glock to the reclaim list
190 * @gl: the glock
191 *
192 * If the glock is demotable, then we add it (or move it) to the end
193 * of the glock LRU list.
194 */
195
196static void __gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl)
197{
198 if (demote_ok(gl))
199 gfs2_glock_add_to_lru(gl);
200}
201
202/**
203 * gfs2_glock_put_nolock() - Decrement reference count on glock 189 * gfs2_glock_put_nolock() - Decrement reference count on glock
204 * @gl: The glock to put 190 * @gl: The glock to put
205 * 191 *
@@ -883,7 +869,14 @@ static int gfs2_glock_demote_wait(void *word)
883 return 0; 869 return 0;
884} 870}
885 871
886static void wait_on_holder(struct gfs2_holder *gh) 872/**
873 * gfs2_glock_wait - wait on a glock acquisition
874 * @gh: the glock holder
875 *
876 * Returns: 0 on success
877 */
878
879int gfs2_glock_wait(struct gfs2_holder *gh)
887{ 880{
888 unsigned long time1 = jiffies; 881 unsigned long time1 = jiffies;
889 882
@@ -894,12 +887,7 @@ static void wait_on_holder(struct gfs2_holder *gh)
894 gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time + 887 gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time +
895 GL_GLOCK_HOLD_INCR, 888 GL_GLOCK_HOLD_INCR,
896 GL_GLOCK_MAX_HOLD); 889 GL_GLOCK_MAX_HOLD);
897} 890 return gh->gh_error;
898
899static void wait_on_demote(struct gfs2_glock *gl)
900{
901 might_sleep();
902 wait_on_bit(&gl->gl_flags, GLF_DEMOTE, gfs2_glock_demote_wait, TASK_UNINTERRUPTIBLE);
903} 891}
904 892
905/** 893/**
@@ -929,19 +917,6 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state,
929 trace_gfs2_demote_rq(gl); 917 trace_gfs2_demote_rq(gl);
930} 918}
931 919
932/**
933 * gfs2_glock_wait - wait on a glock acquisition
934 * @gh: the glock holder
935 *
936 * Returns: 0 on success
937 */
938
939int gfs2_glock_wait(struct gfs2_holder *gh)
940{
941 wait_on_holder(gh);
942 return gh->gh_error;
943}
944
945void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...) 920void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...)
946{ 921{
947 struct va_format vaf; 922 struct va_format vaf;
@@ -979,7 +954,7 @@ __acquires(&gl->gl_spin)
979 struct gfs2_sbd *sdp = gl->gl_sbd; 954 struct gfs2_sbd *sdp = gl->gl_sbd;
980 struct list_head *insert_pt = NULL; 955 struct list_head *insert_pt = NULL;
981 struct gfs2_holder *gh2; 956 struct gfs2_holder *gh2;
982 int try_lock = 0; 957 int try_futile = 0;
983 958
984 BUG_ON(gh->gh_owner_pid == NULL); 959 BUG_ON(gh->gh_owner_pid == NULL);
985 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) 960 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags))
@@ -987,7 +962,7 @@ __acquires(&gl->gl_spin)
987 962
988 if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { 963 if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) {
989 if (test_bit(GLF_LOCK, &gl->gl_flags)) 964 if (test_bit(GLF_LOCK, &gl->gl_flags))
990 try_lock = 1; 965 try_futile = !may_grant(gl, gh);
991 if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) 966 if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags))
992 goto fail; 967 goto fail;
993 } 968 }
@@ -996,9 +971,8 @@ __acquires(&gl->gl_spin)
996 if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid && 971 if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid &&
997 (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK))) 972 (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK)))
998 goto trap_recursive; 973 goto trap_recursive;
999 if (try_lock && 974 if (try_futile &&
1000 !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) && 975 !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) {
1001 !may_grant(gl, gh)) {
1002fail: 976fail:
1003 gh->gh_error = GLR_TRYFAILED; 977 gh->gh_error = GLR_TRYFAILED;
1004 gfs2_holder_wake(gh); 978 gfs2_holder_wake(gh);
@@ -1121,8 +1095,9 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
1121 !test_bit(GLF_DEMOTE, &gl->gl_flags)) 1095 !test_bit(GLF_DEMOTE, &gl->gl_flags))
1122 fast_path = 1; 1096 fast_path = 1;
1123 } 1097 }
1124 if (!test_bit(GLF_LFLUSH, &gl->gl_flags)) 1098 if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl))
1125 __gfs2_glock_schedule_for_reclaim(gl); 1099 gfs2_glock_add_to_lru(gl);
1100
1126 trace_gfs2_glock_queue(gh, 0); 1101 trace_gfs2_glock_queue(gh, 0);
1127 spin_unlock(&gl->gl_spin); 1102 spin_unlock(&gl->gl_spin);
1128 if (likely(fast_path)) 1103 if (likely(fast_path))
@@ -1141,7 +1116,8 @@ void gfs2_glock_dq_wait(struct gfs2_holder *gh)
1141{ 1116{
1142 struct gfs2_glock *gl = gh->gh_gl; 1117 struct gfs2_glock *gl = gh->gh_gl;
1143 gfs2_glock_dq(gh); 1118 gfs2_glock_dq(gh);
1144 wait_on_demote(gl); 1119 might_sleep();
1120 wait_on_bit(&gl->gl_flags, GLF_DEMOTE, gfs2_glock_demote_wait, TASK_UNINTERRUPTIBLE);
1145} 1121}
1146 1122
1147/** 1123/**
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 4bdcf3784187..32cc4fde975c 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -94,6 +94,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
94 /* A shortened, inline version of gfs2_trans_begin() */ 94 /* A shortened, inline version of gfs2_trans_begin() */
95 tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64)); 95 tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64));
96 tr.tr_ip = (unsigned long)__builtin_return_address(0); 96 tr.tr_ip = (unsigned long)__builtin_return_address(0);
97 sb_start_intwrite(sdp->sd_vfs);
97 gfs2_log_reserve(sdp, tr.tr_reserved); 98 gfs2_log_reserve(sdp, tr.tr_reserved);
98 BUG_ON(current->journal_info); 99 BUG_ON(current->journal_info);
99 current->journal_info = &tr; 100 current->journal_info = &tr;
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index aaecc8085fc5..3d469d37345e 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -99,9 +99,26 @@ struct gfs2_rgrpd {
99#define GFS2_RDF_MASK 0xf0000000 /* mask for internal flags */ 99#define GFS2_RDF_MASK 0xf0000000 /* mask for internal flags */
100 spinlock_t rd_rsspin; /* protects reservation related vars */ 100 spinlock_t rd_rsspin; /* protects reservation related vars */
101 struct rb_root rd_rstree; /* multi-block reservation tree */ 101 struct rb_root rd_rstree; /* multi-block reservation tree */
102 u32 rd_rs_cnt; /* count of current reservations */
103}; 102};
104 103
104struct gfs2_rbm {
105 struct gfs2_rgrpd *rgd;
106 struct gfs2_bitmap *bi; /* Bitmap must belong to the rgd */
107 u32 offset; /* The offset is bitmap relative */
108};
109
110static inline u64 gfs2_rbm_to_block(const struct gfs2_rbm *rbm)
111{
112 return rbm->rgd->rd_data0 + (rbm->bi->bi_start * GFS2_NBBY) + rbm->offset;
113}
114
115static inline bool gfs2_rbm_eq(const struct gfs2_rbm *rbm1,
116 const struct gfs2_rbm *rbm2)
117{
118 return (rbm1->rgd == rbm2->rgd) && (rbm1->bi == rbm2->bi) &&
119 (rbm1->offset == rbm2->offset);
120}
121
105enum gfs2_state_bits { 122enum gfs2_state_bits {
106 BH_Pinned = BH_PrivateStart, 123 BH_Pinned = BH_PrivateStart,
107 BH_Escaped = BH_PrivateStart + 1, 124 BH_Escaped = BH_PrivateStart + 1,
@@ -250,18 +267,11 @@ struct gfs2_blkreserv {
250 /* components used during write (step 1): */ 267 /* components used during write (step 1): */
251 atomic_t rs_sizehint; /* hint of the write size */ 268 atomic_t rs_sizehint; /* hint of the write size */
252 269
253 /* components used during inplace_reserve (step 2): */
254 u32 rs_requested; /* Filled in by caller of gfs2_inplace_reserve() */
255
256 /* components used during get_local_rgrp (step 3): */
257 struct gfs2_rgrpd *rs_rgd; /* pointer to the gfs2_rgrpd */
258 struct gfs2_holder rs_rgd_gh; /* Filled in by get_local_rgrp */ 270 struct gfs2_holder rs_rgd_gh; /* Filled in by get_local_rgrp */
259 struct rb_node rs_node; /* link to other block reservations */ 271 struct rb_node rs_node; /* link to other block reservations */
260 272 struct gfs2_rbm rs_rbm; /* Start of reservation */
261 /* components used during block searches and assignments (step 4): */
262 struct gfs2_bitmap *rs_bi; /* bitmap for the current allocation */
263 u32 rs_biblk; /* start block relative to the bi */
264 u32 rs_free; /* how many blocks are still free */ 273 u32 rs_free; /* how many blocks are still free */
274 u64 rs_inum; /* Inode number for reservation */
265 275
266 /* ancillary quota stuff */ 276 /* ancillary quota stuff */
267 struct gfs2_quota_data *rs_qa_qd[2 * MAXQUOTAS]; 277 struct gfs2_quota_data *rs_qa_qd[2 * MAXQUOTAS];
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 4ce22e547308..381893ceefa4 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -712,14 +712,9 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
712 if (error) 712 if (error)
713 goto fail_gunlock2; 713 goto fail_gunlock2;
714 714
715 /* The newly created inode needs a reservation so it can allocate 715 error = gfs2_rs_alloc(ip);
716 xattrs. At the same time, we want new blocks allocated to the new 716 if (error)
717 dinode to be as contiguous as possible. Since we allocated the 717 goto fail_gunlock2;
718 dinode block under the directory's reservation, we transfer
719 ownership of that reservation to the new inode. The directory
720 doesn't need a reservation unless it needs a new allocation. */
721 ip->i_res = dip->i_res;
722 dip->i_res = NULL;
723 718
724 error = gfs2_acl_create(dip, inode); 719 error = gfs2_acl_create(dip, inode);
725 if (error) 720 if (error)
@@ -737,10 +732,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
737 brelse(bh); 732 brelse(bh);
738 733
739 gfs2_trans_end(sdp); 734 gfs2_trans_end(sdp);
740 /* Check if we reserved space in the rgrp. Function link_dinode may 735 gfs2_inplace_release(dip);
741 not, depending on whether alloc is required. */
742 if (gfs2_mb_reserved(dip))
743 gfs2_inplace_release(dip);
744 gfs2_quota_unlock(dip); 736 gfs2_quota_unlock(dip);
745 mark_inode_dirty(inode); 737 mark_inode_dirty(inode);
746 gfs2_glock_dq_uninit_m(2, ghs); 738 gfs2_glock_dq_uninit_m(2, ghs);
@@ -897,7 +889,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
897 goto out_gunlock_q; 889 goto out_gunlock_q;
898 890
899 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + 891 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
900 gfs2_rg_blocks(dip) + 892 gfs2_rg_blocks(dip, sdp->sd_max_dirres) +
901 2 * RES_DINODE + RES_STATFS + 893 2 * RES_DINODE + RES_STATFS +
902 RES_QUOTA, 0); 894 RES_QUOTA, 0);
903 if (error) 895 if (error)
@@ -1378,7 +1370,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1378 goto out_gunlock_q; 1370 goto out_gunlock_q;
1379 1371
1380 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + 1372 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
1381 gfs2_rg_blocks(ndip) + 1373 gfs2_rg_blocks(ndip, sdp->sd_max_dirres) +
1382 4 * RES_DINODE + 4 * RES_LEAF + 1374 4 * RES_DINODE + 4 * RES_LEAF +
1383 RES_STATFS + RES_QUOTA + 4, 0); 1375 RES_STATFS + RES_QUOTA + 4, 0);
1384 if (error) 1376 if (error)
@@ -1722,7 +1714,9 @@ static int gfs2_setxattr(struct dentry *dentry, const char *name,
1722 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); 1714 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1723 ret = gfs2_glock_nq(&gh); 1715 ret = gfs2_glock_nq(&gh);
1724 if (ret == 0) { 1716 if (ret == 0) {
1725 ret = generic_setxattr(dentry, name, data, size, flags); 1717 ret = gfs2_rs_alloc(ip);
1718 if (ret == 0)
1719 ret = generic_setxattr(dentry, name, data, size, flags);
1726 gfs2_glock_dq(&gh); 1720 gfs2_glock_dq(&gh);
1727 } 1721 }
1728 gfs2_holder_uninit(&gh); 1722 gfs2_holder_uninit(&gh);
@@ -1757,7 +1751,9 @@ static int gfs2_removexattr(struct dentry *dentry, const char *name)
1757 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); 1751 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1758 ret = gfs2_glock_nq(&gh); 1752 ret = gfs2_glock_nq(&gh);
1759 if (ret == 0) { 1753 if (ret == 0) {
1760 ret = generic_removexattr(dentry, name); 1754 ret = gfs2_rs_alloc(ip);
1755 if (ret == 0)
1756 ret = generic_removexattr(dentry, name);
1761 gfs2_glock_dq(&gh); 1757 gfs2_glock_dq(&gh);
1762 } 1758 }
1763 gfs2_holder_uninit(&gh); 1759 gfs2_holder_uninit(&gh);
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index e5af9dc420ef..e443966c8106 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -19,6 +19,7 @@
19#include <linux/mount.h> 19#include <linux/mount.h>
20#include <linux/gfs2_ondisk.h> 20#include <linux/gfs2_ondisk.h>
21#include <linux/quotaops.h> 21#include <linux/quotaops.h>
22#include <linux/lockdep.h>
22 23
23#include "gfs2.h" 24#include "gfs2.h"
24#include "incore.h" 25#include "incore.h"
@@ -766,6 +767,7 @@ fail:
766 return error; 767 return error;
767} 768}
768 769
770static struct lock_class_key gfs2_quota_imutex_key;
769 771
770static int init_inodes(struct gfs2_sbd *sdp, int undo) 772static int init_inodes(struct gfs2_sbd *sdp, int undo)
771{ 773{
@@ -803,6 +805,12 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo)
803 fs_err(sdp, "can't get quota file inode: %d\n", error); 805 fs_err(sdp, "can't get quota file inode: %d\n", error);
804 goto fail_rindex; 806 goto fail_rindex;
805 } 807 }
808 /*
809 * i_mutex on quota files is special. Since this inode is hidden system
810 * file, we are safe to define locking ourselves.
811 */
812 lockdep_set_class(&sdp->sd_quota_inode->i_mutex,
813 &gfs2_quota_imutex_key);
806 814
807 error = gfs2_rindex_update(sdp); 815 error = gfs2_rindex_update(sdp);
808 if (error) 816 if (error)
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index a3bde91645c2..4021deca61ef 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -765,6 +765,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
765 struct gfs2_holder *ghs, i_gh; 765 struct gfs2_holder *ghs, i_gh;
766 unsigned int qx, x; 766 unsigned int qx, x;
767 struct gfs2_quota_data *qd; 767 struct gfs2_quota_data *qd;
768 unsigned reserved;
768 loff_t offset; 769 loff_t offset;
769 unsigned int nalloc = 0, blocks; 770 unsigned int nalloc = 0, blocks;
770 int error; 771 int error;
@@ -781,7 +782,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
781 return -ENOMEM; 782 return -ENOMEM;
782 783
783 sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL); 784 sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL);
784 mutex_lock_nested(&ip->i_inode.i_mutex, I_MUTEX_QUOTA); 785 mutex_lock(&ip->i_inode.i_mutex);
785 for (qx = 0; qx < num_qd; qx++) { 786 for (qx = 0; qx < num_qd; qx++) {
786 error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE, 787 error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE,
787 GL_NOCACHE, &ghs[qx]); 788 GL_NOCACHE, &ghs[qx]);
@@ -811,13 +812,13 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
811 * two blocks need to be updated instead of 1 */ 812 * two blocks need to be updated instead of 1 */
812 blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3; 813 blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3;
813 814
814 error = gfs2_inplace_reserve(ip, 1 + 815 reserved = 1 + (nalloc * (data_blocks + ind_blocks));
815 (nalloc * (data_blocks + ind_blocks))); 816 error = gfs2_inplace_reserve(ip, reserved);
816 if (error) 817 if (error)
817 goto out_alloc; 818 goto out_alloc;
818 819
819 if (nalloc) 820 if (nalloc)
820 blocks += gfs2_rg_blocks(ip) + nalloc * ind_blocks + RES_STATFS; 821 blocks += gfs2_rg_blocks(ip, reserved) + nalloc * ind_blocks + RES_STATFS;
821 822
822 error = gfs2_trans_begin(sdp, blocks, 0); 823 error = gfs2_trans_begin(sdp, blocks, 0);
823 if (error) 824 if (error)
@@ -1598,7 +1599,7 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
1598 error = gfs2_inplace_reserve(ip, blocks); 1599 error = gfs2_inplace_reserve(ip, blocks);
1599 if (error) 1600 if (error)
1600 goto out_i; 1601 goto out_i;
1601 blocks += gfs2_rg_blocks(ip); 1602 blocks += gfs2_rg_blocks(ip, blocks);
1602 } 1603 }
1603 1604
1604 /* Some quotas span block boundaries and can update two blocks, 1605 /* Some quotas span block boundaries and can update two blocks,
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 4d34887a601d..3cc402ce6fea 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -35,9 +35,6 @@
35#define BFITNOENT ((u32)~0) 35#define BFITNOENT ((u32)~0)
36#define NO_BLOCK ((u64)~0) 36#define NO_BLOCK ((u64)~0)
37 37
38#define RSRV_CONTENTION_FACTOR 4
39#define RGRP_RSRV_MAX_CONTENDERS 2
40
41#if BITS_PER_LONG == 32 38#if BITS_PER_LONG == 32
42#define LBITMASK (0x55555555UL) 39#define LBITMASK (0x55555555UL)
43#define LBITSKIP55 (0x55555555UL) 40#define LBITSKIP55 (0x55555555UL)
@@ -67,53 +64,48 @@ static const char valid_change[16] = {
67 1, 0, 0, 0 64 1, 0, 0, 0
68}; 65};
69 66
70static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, 67static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext,
71 unsigned char old_state, 68 const struct gfs2_inode *ip, bool nowrap);
72 struct gfs2_bitmap **rbi); 69
73 70
74/** 71/**
75 * gfs2_setbit - Set a bit in the bitmaps 72 * gfs2_setbit - Set a bit in the bitmaps
76 * @rgd: the resource group descriptor 73 * @rbm: The position of the bit to set
77 * @buf2: the clone buffer that holds the bitmaps 74 * @do_clone: Also set the clone bitmap, if it exists
78 * @bi: the bitmap structure
79 * @block: the block to set
80 * @new_state: the new state of the block 75 * @new_state: the new state of the block
81 * 76 *
82 */ 77 */
83 78
84static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2, 79static inline void gfs2_setbit(const struct gfs2_rbm *rbm, bool do_clone,
85 struct gfs2_bitmap *bi, u32 block,
86 unsigned char new_state) 80 unsigned char new_state)
87{ 81{
88 unsigned char *byte1, *byte2, *end, cur_state; 82 unsigned char *byte1, *byte2, *end, cur_state;
89 unsigned int buflen = bi->bi_len; 83 unsigned int buflen = rbm->bi->bi_len;
90 const unsigned int bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; 84 const unsigned int bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE;
91 85
92 byte1 = bi->bi_bh->b_data + bi->bi_offset + (block / GFS2_NBBY); 86 byte1 = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset + (rbm->offset / GFS2_NBBY);
93 end = bi->bi_bh->b_data + bi->bi_offset + buflen; 87 end = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset + buflen;
94 88
95 BUG_ON(byte1 >= end); 89 BUG_ON(byte1 >= end);
96 90
97 cur_state = (*byte1 >> bit) & GFS2_BIT_MASK; 91 cur_state = (*byte1 >> bit) & GFS2_BIT_MASK;
98 92
99 if (unlikely(!valid_change[new_state * 4 + cur_state])) { 93 if (unlikely(!valid_change[new_state * 4 + cur_state])) {
100 printk(KERN_WARNING "GFS2: buf_blk = 0x%llx old_state=%d, " 94 printk(KERN_WARNING "GFS2: buf_blk = 0x%x old_state=%d, "
101 "new_state=%d\n", 95 "new_state=%d\n", rbm->offset, cur_state, new_state);
102 (unsigned long long)block, cur_state, new_state); 96 printk(KERN_WARNING "GFS2: rgrp=0x%llx bi_start=0x%x\n",
103 printk(KERN_WARNING "GFS2: rgrp=0x%llx bi_start=0x%lx\n", 97 (unsigned long long)rbm->rgd->rd_addr,
104 (unsigned long long)rgd->rd_addr, 98 rbm->bi->bi_start);
105 (unsigned long)bi->bi_start); 99 printk(KERN_WARNING "GFS2: bi_offset=0x%x bi_len=0x%x\n",
106 printk(KERN_WARNING "GFS2: bi_offset=0x%lx bi_len=0x%lx\n", 100 rbm->bi->bi_offset, rbm->bi->bi_len);
107 (unsigned long)bi->bi_offset,
108 (unsigned long)bi->bi_len);
109 dump_stack(); 101 dump_stack();
110 gfs2_consist_rgrpd(rgd); 102 gfs2_consist_rgrpd(rbm->rgd);
111 return; 103 return;
112 } 104 }
113 *byte1 ^= (cur_state ^ new_state) << bit; 105 *byte1 ^= (cur_state ^ new_state) << bit;
114 106
115 if (buf2) { 107 if (do_clone && rbm->bi->bi_clone) {
116 byte2 = buf2 + bi->bi_offset + (block / GFS2_NBBY); 108 byte2 = rbm->bi->bi_clone + rbm->bi->bi_offset + (rbm->offset / GFS2_NBBY);
117 cur_state = (*byte2 >> bit) & GFS2_BIT_MASK; 109 cur_state = (*byte2 >> bit) & GFS2_BIT_MASK;
118 *byte2 ^= (cur_state ^ new_state) << bit; 110 *byte2 ^= (cur_state ^ new_state) << bit;
119 } 111 }
@@ -121,30 +113,21 @@ static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2,
121 113
122/** 114/**
123 * gfs2_testbit - test a bit in the bitmaps 115 * gfs2_testbit - test a bit in the bitmaps
124 * @rgd: the resource group descriptor 116 * @rbm: The bit to test
125 * @buffer: the buffer that holds the bitmaps
126 * @buflen: the length (in bytes) of the buffer
127 * @block: the block to read
128 * 117 *
118 * Returns: The two bit block state of the requested bit
129 */ 119 */
130 120
131static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, 121static inline u8 gfs2_testbit(const struct gfs2_rbm *rbm)
132 const unsigned char *buffer,
133 unsigned int buflen, u32 block)
134{ 122{
135 const unsigned char *byte, *end; 123 const u8 *buffer = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset;
136 unsigned char cur_state; 124 const u8 *byte;
137 unsigned int bit; 125 unsigned int bit;
138 126
139 byte = buffer + (block / GFS2_NBBY); 127 byte = buffer + (rbm->offset / GFS2_NBBY);
140 bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; 128 bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE;
141 end = buffer + buflen;
142
143 gfs2_assert(rgd->rd_sbd, byte < end);
144 129
145 cur_state = (*byte >> bit) & GFS2_BIT_MASK; 130 return (*byte >> bit) & GFS2_BIT_MASK;
146
147 return cur_state;
148} 131}
149 132
150/** 133/**
@@ -192,7 +175,7 @@ static inline u64 gfs2_bit_search(const __le64 *ptr, u64 mask, u8 state)
192 */ 175 */
193static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs) 176static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs)
194{ 177{
195 u64 startblk = gfs2_rs_startblk(rs); 178 u64 startblk = gfs2_rbm_to_block(&rs->rs_rbm);
196 179
197 if (blk >= startblk + rs->rs_free) 180 if (blk >= startblk + rs->rs_free)
198 return 1; 181 return 1;
@@ -202,36 +185,6 @@ static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs)
202} 185}
203 186
204/** 187/**
205 * rs_find - Find a rgrp multi-block reservation that contains a given block
206 * @rgd: The rgrp
207 * @rgblk: The block we're looking for, relative to the rgrp
208 */
209static struct gfs2_blkreserv *rs_find(struct gfs2_rgrpd *rgd, u32 rgblk)
210{
211 struct rb_node **newn;
212 int rc;
213 u64 fsblk = rgblk + rgd->rd_data0;
214
215 spin_lock(&rgd->rd_rsspin);
216 newn = &rgd->rd_rstree.rb_node;
217 while (*newn) {
218 struct gfs2_blkreserv *cur =
219 rb_entry(*newn, struct gfs2_blkreserv, rs_node);
220 rc = rs_cmp(fsblk, 1, cur);
221 if (rc < 0)
222 newn = &((*newn)->rb_left);
223 else if (rc > 0)
224 newn = &((*newn)->rb_right);
225 else {
226 spin_unlock(&rgd->rd_rsspin);
227 return cur;
228 }
229 }
230 spin_unlock(&rgd->rd_rsspin);
231 return NULL;
232}
233
234/**
235 * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing 188 * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing
236 * a block in a given allocation state. 189 * a block in a given allocation state.
237 * @buf: the buffer that holds the bitmaps 190 * @buf: the buffer that holds the bitmaps
@@ -262,8 +215,6 @@ static u32 gfs2_bitfit(const u8 *buf, const unsigned int len,
262 u64 mask = 0x5555555555555555ULL; 215 u64 mask = 0x5555555555555555ULL;
263 u32 bit; 216 u32 bit;
264 217
265 BUG_ON(state > 3);
266
267 /* Mask off bits we don't care about at the start of the search */ 218 /* Mask off bits we don't care about at the start of the search */
268 mask <<= spoint; 219 mask <<= spoint;
269 tmp = gfs2_bit_search(ptr, mask, state); 220 tmp = gfs2_bit_search(ptr, mask, state);
@@ -285,6 +236,131 @@ static u32 gfs2_bitfit(const u8 *buf, const unsigned int len,
285} 236}
286 237
287/** 238/**
239 * gfs2_rbm_from_block - Set the rbm based upon rgd and block number
240 * @rbm: The rbm with rgd already set correctly
241 * @block: The block number (filesystem relative)
242 *
243 * This sets the bi and offset members of an rbm based on a
244 * resource group and a filesystem relative block number. The
245 * resource group must be set in the rbm on entry, the bi and
246 * offset members will be set by this function.
247 *
248 * Returns: 0 on success, or an error code
249 */
250
251static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block)
252{
253 u64 rblock = block - rbm->rgd->rd_data0;
254 u32 goal = (u32)rblock;
255 int x;
256
257 if (WARN_ON_ONCE(rblock > UINT_MAX))
258 return -EINVAL;
259 if (block >= rbm->rgd->rd_data0 + rbm->rgd->rd_data)
260 return -E2BIG;
261
262 for (x = 0; x < rbm->rgd->rd_length; x++) {
263 rbm->bi = rbm->rgd->rd_bits + x;
264 if (goal < (rbm->bi->bi_start + rbm->bi->bi_len) * GFS2_NBBY) {
265 rbm->offset = goal - (rbm->bi->bi_start * GFS2_NBBY);
266 break;
267 }
268 }
269
270 return 0;
271}
272
273/**
274 * gfs2_unaligned_extlen - Look for free blocks which are not byte aligned
275 * @rbm: Position to search (value/result)
276 * @n_unaligned: Number of unaligned blocks to check
277 * @len: Decremented for each block found (terminate on zero)
278 *
279 * Returns: true if a non-free block is encountered
280 */
281
282static bool gfs2_unaligned_extlen(struct gfs2_rbm *rbm, u32 n_unaligned, u32 *len)
283{
284 u64 block;
285 u32 n;
286 u8 res;
287
288 for (n = 0; n < n_unaligned; n++) {
289 res = gfs2_testbit(rbm);
290 if (res != GFS2_BLKST_FREE)
291 return true;
292 (*len)--;
293 if (*len == 0)
294 return true;
295 block = gfs2_rbm_to_block(rbm);
296 if (gfs2_rbm_from_block(rbm, block + 1))
297 return true;
298 }
299
300 return false;
301}
302
303/**
304 * gfs2_free_extlen - Return extent length of free blocks
305 * @rbm: Starting position
306 * @len: Max length to check
307 *
308 * Starting at the block specified by the rbm, see how many free blocks
309 * there are, not reading more than len blocks ahead. This can be done
310 * using memchr_inv when the blocks are byte aligned, but has to be done
311 * on a block by block basis in case of unaligned blocks. Also this
312 * function can cope with bitmap boundaries (although it must stop on
313 * a resource group boundary)
314 *
315 * Returns: Number of free blocks in the extent
316 */
317
318static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len)
319{
320 struct gfs2_rbm rbm = *rrbm;
321 u32 n_unaligned = rbm.offset & 3;
322 u32 size = len;
323 u32 bytes;
324 u32 chunk_size;
325 u8 *ptr, *start, *end;
326 u64 block;
327
328 if (n_unaligned &&
329 gfs2_unaligned_extlen(&rbm, 4 - n_unaligned, &len))
330 goto out;
331
332 n_unaligned = len & 3;
333 /* Start is now byte aligned */
334 while (len > 3) {
335 start = rbm.bi->bi_bh->b_data;
336 if (rbm.bi->bi_clone)
337 start = rbm.bi->bi_clone;
338 end = start + rbm.bi->bi_bh->b_size;
339 start += rbm.bi->bi_offset;
340 BUG_ON(rbm.offset & 3);
341 start += (rbm.offset / GFS2_NBBY);
342 bytes = min_t(u32, len / GFS2_NBBY, (end - start));
343 ptr = memchr_inv(start, 0, bytes);
344 chunk_size = ((ptr == NULL) ? bytes : (ptr - start));
345 chunk_size *= GFS2_NBBY;
346 BUG_ON(len < chunk_size);
347 len -= chunk_size;
348 block = gfs2_rbm_to_block(&rbm);
349 gfs2_rbm_from_block(&rbm, block + chunk_size);
350 n_unaligned = 3;
351 if (ptr)
352 break;
353 n_unaligned = len & 3;
354 }
355
356 /* Deal with any bits left over at the end */
357 if (n_unaligned)
358 gfs2_unaligned_extlen(&rbm, n_unaligned, &len);
359out:
360 return size - len;
361}
362
363/**
288 * gfs2_bitcount - count the number of bits in a certain state 364 * gfs2_bitcount - count the number of bits in a certain state
289 * @rgd: the resource group descriptor 365 * @rgd: the resource group descriptor
290 * @buffer: the buffer that holds the bitmaps 366 * @buffer: the buffer that holds the bitmaps
@@ -487,6 +563,8 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
487 if (!res) 563 if (!res)
488 error = -ENOMEM; 564 error = -ENOMEM;
489 565
566 RB_CLEAR_NODE(&res->rs_node);
567
490 down_write(&ip->i_rw_mutex); 568 down_write(&ip->i_rw_mutex);
491 if (ip->i_res) 569 if (ip->i_res)
492 kmem_cache_free(gfs2_rsrv_cachep, res); 570 kmem_cache_free(gfs2_rsrv_cachep, res);
@@ -496,11 +574,12 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
496 return error; 574 return error;
497} 575}
498 576
499static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs) 577static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs)
500{ 578{
501 gfs2_print_dbg(seq, " r: %llu s:%llu b:%u f:%u\n", 579 gfs2_print_dbg(seq, " B: n:%llu s:%llu b:%u f:%u\n",
502 rs->rs_rgd->rd_addr, gfs2_rs_startblk(rs), rs->rs_biblk, 580 (unsigned long long)rs->rs_inum,
503 rs->rs_free); 581 (unsigned long long)gfs2_rbm_to_block(&rs->rs_rbm),
582 rs->rs_rbm.offset, rs->rs_free);
504} 583}
505 584
506/** 585/**
@@ -508,41 +587,26 @@ static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs)
508 * @rs: The reservation to remove 587 * @rs: The reservation to remove
509 * 588 *
510 */ 589 */
511static void __rs_deltree(struct gfs2_blkreserv *rs) 590static void __rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs)
512{ 591{
513 struct gfs2_rgrpd *rgd; 592 struct gfs2_rgrpd *rgd;
514 593
515 if (!gfs2_rs_active(rs)) 594 if (!gfs2_rs_active(rs))
516 return; 595 return;
517 596
518 rgd = rs->rs_rgd; 597 rgd = rs->rs_rbm.rgd;
519 /* We can't do this: The reason is that when the rgrp is invalidated, 598 trace_gfs2_rs(rs, TRACE_RS_TREEDEL);
520 it's in the "middle" of acquiring the glock, but the HOLDER bit 599 rb_erase(&rs->rs_node, &rgd->rd_rstree);
521 isn't set yet: 600 RB_CLEAR_NODE(&rs->rs_node);
522 BUG_ON(!gfs2_glock_is_locked_by_me(rs->rs_rgd->rd_gl));*/
523 trace_gfs2_rs(NULL, rs, TRACE_RS_TREEDEL);
524
525 if (!RB_EMPTY_ROOT(&rgd->rd_rstree))
526 rb_erase(&rs->rs_node, &rgd->rd_rstree);
527 BUG_ON(!rgd->rd_rs_cnt);
528 rgd->rd_rs_cnt--;
529 601
530 if (rs->rs_free) { 602 if (rs->rs_free) {
531 /* return reserved blocks to the rgrp and the ip */ 603 /* return reserved blocks to the rgrp and the ip */
532 BUG_ON(rs->rs_rgd->rd_reserved < rs->rs_free); 604 BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free);
533 rs->rs_rgd->rd_reserved -= rs->rs_free; 605 rs->rs_rbm.rgd->rd_reserved -= rs->rs_free;
534 rs->rs_free = 0; 606 rs->rs_free = 0;
535 clear_bit(GBF_FULL, &rs->rs_bi->bi_flags); 607 clear_bit(GBF_FULL, &rs->rs_rbm.bi->bi_flags);
536 smp_mb__after_clear_bit(); 608 smp_mb__after_clear_bit();
537 } 609 }
538 /* We can't change any of the step 1 or step 2 components of the rs.
539 E.g. We can't set rs_rgd to NULL because the rgd glock is held and
540 dequeued through this pointer.
541 Can't: atomic_set(&rs->rs_sizehint, 0);
542 Can't: rs->rs_requested = 0;
543 Can't: rs->rs_rgd = NULL;*/
544 rs->rs_bi = NULL;
545 rs->rs_biblk = 0;
546} 610}
547 611
548/** 612/**
@@ -550,17 +614,16 @@ static void __rs_deltree(struct gfs2_blkreserv *rs)
550 * @rs: The reservation to remove 614 * @rs: The reservation to remove
551 * 615 *
552 */ 616 */
553void gfs2_rs_deltree(struct gfs2_blkreserv *rs) 617void gfs2_rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs)
554{ 618{
555 struct gfs2_rgrpd *rgd; 619 struct gfs2_rgrpd *rgd;
556 620
557 if (!gfs2_rs_active(rs)) 621 rgd = rs->rs_rbm.rgd;
558 return; 622 if (rgd) {
559 623 spin_lock(&rgd->rd_rsspin);
560 rgd = rs->rs_rgd; 624 __rs_deltree(ip, rs);
561 spin_lock(&rgd->rd_rsspin); 625 spin_unlock(&rgd->rd_rsspin);
562 __rs_deltree(rs); 626 }
563 spin_unlock(&rgd->rd_rsspin);
564} 627}
565 628
566/** 629/**
@@ -572,8 +635,7 @@ void gfs2_rs_delete(struct gfs2_inode *ip)
572{ 635{
573 down_write(&ip->i_rw_mutex); 636 down_write(&ip->i_rw_mutex);
574 if (ip->i_res) { 637 if (ip->i_res) {
575 gfs2_rs_deltree(ip->i_res); 638 gfs2_rs_deltree(ip, ip->i_res);
576 trace_gfs2_rs(ip, ip->i_res, TRACE_RS_DELETE);
577 BUG_ON(ip->i_res->rs_free); 639 BUG_ON(ip->i_res->rs_free);
578 kmem_cache_free(gfs2_rsrv_cachep, ip->i_res); 640 kmem_cache_free(gfs2_rsrv_cachep, ip->i_res);
579 ip->i_res = NULL; 641 ip->i_res = NULL;
@@ -597,7 +659,7 @@ static void return_all_reservations(struct gfs2_rgrpd *rgd)
597 spin_lock(&rgd->rd_rsspin); 659 spin_lock(&rgd->rd_rsspin);
598 while ((n = rb_first(&rgd->rd_rstree))) { 660 while ((n = rb_first(&rgd->rd_rstree))) {
599 rs = rb_entry(n, struct gfs2_blkreserv, rs_node); 661 rs = rb_entry(n, struct gfs2_blkreserv, rs_node);
600 __rs_deltree(rs); 662 __rs_deltree(NULL, rs);
601 } 663 }
602 spin_unlock(&rgd->rd_rsspin); 664 spin_unlock(&rgd->rd_rsspin);
603} 665}
@@ -1270,211 +1332,276 @@ out:
1270 1332
1271/** 1333/**
1272 * rs_insert - insert a new multi-block reservation into the rgrp's rb_tree 1334 * rs_insert - insert a new multi-block reservation into the rgrp's rb_tree
1273 * @bi: the bitmap with the blocks
1274 * @ip: the inode structure 1335 * @ip: the inode structure
1275 * @biblk: the 32-bit block number relative to the start of the bitmap
1276 * @amount: the number of blocks to reserve
1277 * 1336 *
1278 * Returns: NULL - reservation was already taken, so not inserted
1279 * pointer to the inserted reservation
1280 */ 1337 */
1281static struct gfs2_blkreserv *rs_insert(struct gfs2_bitmap *bi, 1338static void rs_insert(struct gfs2_inode *ip)
1282 struct gfs2_inode *ip, u32 biblk,
1283 int amount)
1284{ 1339{
1285 struct rb_node **newn, *parent = NULL; 1340 struct rb_node **newn, *parent = NULL;
1286 int rc; 1341 int rc;
1287 struct gfs2_blkreserv *rs = ip->i_res; 1342 struct gfs2_blkreserv *rs = ip->i_res;
1288 struct gfs2_rgrpd *rgd = rs->rs_rgd; 1343 struct gfs2_rgrpd *rgd = rs->rs_rbm.rgd;
1289 u64 fsblock = gfs2_bi2rgd_blk(bi, biblk) + rgd->rd_data0; 1344 u64 fsblock = gfs2_rbm_to_block(&rs->rs_rbm);
1345
1346 BUG_ON(gfs2_rs_active(rs));
1290 1347
1291 spin_lock(&rgd->rd_rsspin); 1348 spin_lock(&rgd->rd_rsspin);
1292 newn = &rgd->rd_rstree.rb_node; 1349 newn = &rgd->rd_rstree.rb_node;
1293 BUG_ON(!ip->i_res);
1294 BUG_ON(gfs2_rs_active(rs));
1295 /* Figure out where to put new node */
1296 /*BUG_ON(!gfs2_glock_is_locked_by_me(rgd->rd_gl));*/
1297 while (*newn) { 1350 while (*newn) {
1298 struct gfs2_blkreserv *cur = 1351 struct gfs2_blkreserv *cur =
1299 rb_entry(*newn, struct gfs2_blkreserv, rs_node); 1352 rb_entry(*newn, struct gfs2_blkreserv, rs_node);
1300 1353
1301 parent = *newn; 1354 parent = *newn;
1302 rc = rs_cmp(fsblock, amount, cur); 1355 rc = rs_cmp(fsblock, rs->rs_free, cur);
1303 if (rc > 0) 1356 if (rc > 0)
1304 newn = &((*newn)->rb_right); 1357 newn = &((*newn)->rb_right);
1305 else if (rc < 0) 1358 else if (rc < 0)
1306 newn = &((*newn)->rb_left); 1359 newn = &((*newn)->rb_left);
1307 else { 1360 else {
1308 spin_unlock(&rgd->rd_rsspin); 1361 spin_unlock(&rgd->rd_rsspin);
1309 return NULL; /* reservation already in use */ 1362 WARN_ON(1);
1363 return;
1310 } 1364 }
1311 } 1365 }
1312 1366
1313 /* Do our reservation work */
1314 rs = ip->i_res;
1315 rs->rs_free = amount;
1316 rs->rs_biblk = biblk;
1317 rs->rs_bi = bi;
1318 rb_link_node(&rs->rs_node, parent, newn); 1367 rb_link_node(&rs->rs_node, parent, newn);
1319 rb_insert_color(&rs->rs_node, &rgd->rd_rstree); 1368 rb_insert_color(&rs->rs_node, &rgd->rd_rstree);
1320 1369
1321 /* Do our inode accounting for the reservation */
1322 /*BUG_ON(!gfs2_glock_is_locked_by_me(ip->i_gl));*/
1323
1324 /* Do our rgrp accounting for the reservation */ 1370 /* Do our rgrp accounting for the reservation */
1325 rgd->rd_reserved += amount; /* blocks reserved */ 1371 rgd->rd_reserved += rs->rs_free; /* blocks reserved */
1326 rgd->rd_rs_cnt++; /* number of in-tree reservations */
1327 spin_unlock(&rgd->rd_rsspin); 1372 spin_unlock(&rgd->rd_rsspin);
1328 trace_gfs2_rs(ip, rs, TRACE_RS_INSERT); 1373 trace_gfs2_rs(rs, TRACE_RS_INSERT);
1329 return rs;
1330} 1374}
1331 1375
1332/** 1376/**
1333 * unclaimed_blocks - return number of blocks that aren't spoken for 1377 * rg_mblk_search - find a group of multiple free blocks to form a reservation
1334 */
1335static u32 unclaimed_blocks(struct gfs2_rgrpd *rgd)
1336{
1337 return rgd->rd_free_clone - rgd->rd_reserved;
1338}
1339
1340/**
1341 * rg_mblk_search - find a group of multiple free blocks
1342 * @rgd: the resource group descriptor 1378 * @rgd: the resource group descriptor
1343 * @rs: the block reservation
1344 * @ip: pointer to the inode for which we're reserving blocks 1379 * @ip: pointer to the inode for which we're reserving blocks
1380 * @requested: number of blocks required for this allocation
1345 * 1381 *
1346 * This is very similar to rgblk_search, except we're looking for whole
1347 * 64-bit words that represent a chunk of 32 free blocks. I'm only focusing
1348 * on aligned dwords for speed's sake.
1349 *
1350 * Returns: 0 if successful or BFITNOENT if there isn't enough free space
1351 */ 1382 */
1352 1383
1353static int rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) 1384static void rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip,
1385 unsigned requested)
1354{ 1386{
1355 struct gfs2_bitmap *bi = rgd->rd_bits; 1387 struct gfs2_rbm rbm = { .rgd = rgd, };
1356 const u32 length = rgd->rd_length; 1388 u64 goal;
1357 u32 blk; 1389 struct gfs2_blkreserv *rs = ip->i_res;
1358 unsigned int buf, x, search_bytes; 1390 u32 extlen;
1359 u8 *buffer = NULL; 1391 u32 free_blocks = rgd->rd_free_clone - rgd->rd_reserved;
1360 u8 *ptr, *end, *nonzero; 1392 int ret;
1361 u32 goal, rsv_bytes; 1393
1362 struct gfs2_blkreserv *rs; 1394 extlen = max_t(u32, atomic_read(&rs->rs_sizehint), requested);
1363 u32 best_rs_bytes, unclaimed; 1395 extlen = clamp(extlen, RGRP_RSRV_MINBLKS, free_blocks);
1364 int best_rs_blocks; 1396 if ((rgd->rd_free_clone < rgd->rd_reserved) || (free_blocks < extlen))
1397 return;
1365 1398
1366 /* Find bitmap block that contains bits for goal block */ 1399 /* Find bitmap block that contains bits for goal block */
1367 if (rgrp_contains_block(rgd, ip->i_goal)) 1400 if (rgrp_contains_block(rgd, ip->i_goal))
1368 goal = ip->i_goal - rgd->rd_data0; 1401 goal = ip->i_goal;
1369 else 1402 else
1370 goal = rgd->rd_last_alloc; 1403 goal = rgd->rd_last_alloc + rgd->rd_data0;
1371 for (buf = 0; buf < length; buf++) { 1404
1372 bi = rgd->rd_bits + buf; 1405 if (WARN_ON(gfs2_rbm_from_block(&rbm, goal)))
1373 /* Convert scope of "goal" from rgrp-wide to within 1406 return;
1374 found bit block */ 1407
1375 if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) { 1408 ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, extlen, ip, true);
1376 goal -= bi->bi_start * GFS2_NBBY; 1409 if (ret == 0) {
1377 goto do_search; 1410 rs->rs_rbm = rbm;
1378 } 1411 rs->rs_free = extlen;
1412 rs->rs_inum = ip->i_no_addr;
1413 rs_insert(ip);
1379 } 1414 }
1380 buf = 0; 1415}
1381 goal = 0;
1382
1383do_search:
1384 best_rs_blocks = max_t(int, atomic_read(&ip->i_res->rs_sizehint),
1385 (RGRP_RSRV_MINBLKS * rgd->rd_length));
1386 best_rs_bytes = (best_rs_blocks *
1387 (1 + (RSRV_CONTENTION_FACTOR * rgd->rd_rs_cnt))) /
1388 GFS2_NBBY; /* 1 + is for our not-yet-created reservation */
1389 best_rs_bytes = ALIGN(best_rs_bytes, sizeof(u64));
1390 unclaimed = unclaimed_blocks(rgd);
1391 if (best_rs_bytes * GFS2_NBBY > unclaimed)
1392 best_rs_bytes = unclaimed >> GFS2_BIT_SIZE;
1393
1394 for (x = 0; x <= length; x++) {
1395 bi = rgd->rd_bits + buf;
1396 1416
1397 if (test_bit(GBF_FULL, &bi->bi_flags)) 1417/**
1398 goto skip; 1418 * gfs2_next_unreserved_block - Return next block that is not reserved
1419 * @rgd: The resource group
1420 * @block: The starting block
1421 * @length: The required length
1422 * @ip: Ignore any reservations for this inode
1423 *
1424 * If the block does not appear in any reservation, then return the
1425 * block number unchanged. If it does appear in the reservation, then
1426 * keep looking through the tree of reservations in order to find the
1427 * first block number which is not reserved.
1428 */
1399 1429
1400 WARN_ON(!buffer_uptodate(bi->bi_bh)); 1430static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block,
1401 if (bi->bi_clone) 1431 u32 length,
1402 buffer = bi->bi_clone + bi->bi_offset; 1432 const struct gfs2_inode *ip)
1433{
1434 struct gfs2_blkreserv *rs;
1435 struct rb_node *n;
1436 int rc;
1437
1438 spin_lock(&rgd->rd_rsspin);
1439 n = rgd->rd_rstree.rb_node;
1440 while (n) {
1441 rs = rb_entry(n, struct gfs2_blkreserv, rs_node);
1442 rc = rs_cmp(block, length, rs);
1443 if (rc < 0)
1444 n = n->rb_left;
1445 else if (rc > 0)
1446 n = n->rb_right;
1403 else 1447 else
1404 buffer = bi->bi_bh->b_data + bi->bi_offset; 1448 break;
1405 1449 }
1406 /* We have to keep the reservations aligned on u64 boundaries 1450
1407 otherwise we could get situations where a byte can't be 1451 if (n) {
1408 used because it's after a reservation, but a free bit still 1452 while ((rs_cmp(block, length, rs) == 0) && (ip->i_res != rs)) {
1409 is within the reservation's area. */ 1453 block = gfs2_rbm_to_block(&rs->rs_rbm) + rs->rs_free;
1410 ptr = buffer + ALIGN(goal >> GFS2_BIT_SIZE, sizeof(u64)); 1454 n = n->rb_right;
1411 end = (buffer + bi->bi_len); 1455 if (n == NULL)
1412 while (ptr < end) { 1456 break;
1413 rsv_bytes = 0; 1457 rs = rb_entry(n, struct gfs2_blkreserv, rs_node);
1414 if ((ptr + best_rs_bytes) <= end)
1415 search_bytes = best_rs_bytes;
1416 else
1417 search_bytes = end - ptr;
1418 BUG_ON(!search_bytes);
1419 nonzero = memchr_inv(ptr, 0, search_bytes);
1420 /* If the lot is all zeroes, reserve the whole size. If
1421 there's enough zeroes to satisfy the request, use
1422 what we can. If there's not enough, keep looking. */
1423 if (nonzero == NULL)
1424 rsv_bytes = search_bytes;
1425 else if ((nonzero - ptr) * GFS2_NBBY >=
1426 ip->i_res->rs_requested)
1427 rsv_bytes = (nonzero - ptr);
1428
1429 if (rsv_bytes) {
1430 blk = ((ptr - buffer) * GFS2_NBBY);
1431 BUG_ON(blk >= bi->bi_len * GFS2_NBBY);
1432 rs = rs_insert(bi, ip, blk,
1433 rsv_bytes * GFS2_NBBY);
1434 if (IS_ERR(rs))
1435 return PTR_ERR(rs);
1436 if (rs)
1437 return 0;
1438 }
1439 ptr += ALIGN(search_bytes, sizeof(u64));
1440 } 1458 }
1441skip:
1442 /* Try next bitmap block (wrap back to rgrp header
1443 if at end) */
1444 buf++;
1445 buf %= length;
1446 goal = 0;
1447 } 1459 }
1448 1460
1449 return BFITNOENT; 1461 spin_unlock(&rgd->rd_rsspin);
1462 return block;
1450} 1463}
1451 1464
1452/** 1465/**
1453 * try_rgrp_fit - See if a given reservation will fit in a given RG 1466 * gfs2_reservation_check_and_update - Check for reservations during block alloc
1454 * @rgd: the RG data 1467 * @rbm: The current position in the resource group
1455 * @ip: the inode 1468 * @ip: The inode for which we are searching for blocks
1469 * @minext: The minimum extent length
1456 * 1470 *
1457 * If there's room for the requested blocks to be allocated from the RG: 1471 * This checks the current position in the rgrp to see whether there is
1458 * This will try to get a multi-block reservation first, and if that doesn't 1472 * a reservation covering this block. If not then this function is a
1459 * fit, it will take what it can. 1473 * no-op. If there is, then the position is moved to the end of the
1474 * contiguous reservation(s) so that we are pointing at the first
1475 * non-reserved block.
1460 * 1476 *
1461 * Returns: 1 on success (it fits), 0 on failure (it doesn't fit) 1477 * Returns: 0 if no reservation, 1 if @rbm has changed, otherwise an error
1462 */ 1478 */
1463 1479
1464static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) 1480static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,
1481 const struct gfs2_inode *ip,
1482 u32 minext)
1465{ 1483{
1466 struct gfs2_blkreserv *rs = ip->i_res; 1484 u64 block = gfs2_rbm_to_block(rbm);
1485 u32 extlen = 1;
1486 u64 nblock;
1487 int ret;
1467 1488
1468 if (rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR)) 1489 /*
1490 * If we have a minimum extent length, then skip over any extent
1491 * which is less than the min extent length in size.
1492 */
1493 if (minext) {
1494 extlen = gfs2_free_extlen(rbm, minext);
1495 nblock = block + extlen;
1496 if (extlen < minext)
1497 goto fail;
1498 }
1499
1500 /*
1501 * Check the extent which has been found against the reservations
1502 * and skip if parts of it are already reserved
1503 */
1504 nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, ip);
1505 if (nblock == block)
1469 return 0; 1506 return 0;
1470 /* Look for a multi-block reservation. */ 1507fail:
1471 if (unclaimed_blocks(rgd) >= RGRP_RSRV_MINBLKS && 1508 ret = gfs2_rbm_from_block(rbm, nblock);
1472 rg_mblk_search(rgd, ip) != BFITNOENT) 1509 if (ret < 0)
1473 return 1; 1510 return ret;
1474 if (unclaimed_blocks(rgd) >= rs->rs_requested) 1511 return 1;
1475 return 1; 1512}
1476 1513
1477 return 0; 1514/**
1515 * gfs2_rbm_find - Look for blocks of a particular state
1516 * @rbm: Value/result starting position and final position
1517 * @state: The state which we want to find
1518 * @minext: The requested extent length (0 for a single block)
1519 * @ip: If set, check for reservations
1520 * @nowrap: Stop looking at the end of the rgrp, rather than wrapping
1521 * around until we've reached the starting point.
1522 *
1523 * Side effects:
1524 * - If looking for free blocks, we set GBF_FULL on each bitmap which
1525 * has no free blocks in it.
1526 *
1527 * Returns: 0 on success, -ENOSPC if there is no block of the requested state
1528 */
1529
1530static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext,
1531 const struct gfs2_inode *ip, bool nowrap)
1532{
1533 struct buffer_head *bh;
1534 struct gfs2_bitmap *initial_bi;
1535 u32 initial_offset;
1536 u32 offset;
1537 u8 *buffer;
1538 int index;
1539 int n = 0;
1540 int iters = rbm->rgd->rd_length;
1541 int ret;
1542
1543 /* If we are not starting at the beginning of a bitmap, then we
1544 * need to add one to the bitmap count to ensure that we search
1545 * the starting bitmap twice.
1546 */
1547 if (rbm->offset != 0)
1548 iters++;
1549
1550 while(1) {
1551 if (test_bit(GBF_FULL, &rbm->bi->bi_flags) &&
1552 (state == GFS2_BLKST_FREE))
1553 goto next_bitmap;
1554
1555 bh = rbm->bi->bi_bh;
1556 buffer = bh->b_data + rbm->bi->bi_offset;
1557 WARN_ON(!buffer_uptodate(bh));
1558 if (state != GFS2_BLKST_UNLINKED && rbm->bi->bi_clone)
1559 buffer = rbm->bi->bi_clone + rbm->bi->bi_offset;
1560 initial_offset = rbm->offset;
1561 offset = gfs2_bitfit(buffer, rbm->bi->bi_len, rbm->offset, state);
1562 if (offset == BFITNOENT)
1563 goto bitmap_full;
1564 rbm->offset = offset;
1565 if (ip == NULL)
1566 return 0;
1567
1568 initial_bi = rbm->bi;
1569 ret = gfs2_reservation_check_and_update(rbm, ip, minext);
1570 if (ret == 0)
1571 return 0;
1572 if (ret > 0) {
1573 n += (rbm->bi - initial_bi);
1574 goto next_iter;
1575 }
1576 if (ret == -E2BIG) {
1577 index = 0;
1578 rbm->offset = 0;
1579 n += (rbm->bi - initial_bi);
1580 goto res_covered_end_of_rgrp;
1581 }
1582 return ret;
1583
1584bitmap_full: /* Mark bitmap as full and fall through */
1585 if ((state == GFS2_BLKST_FREE) && initial_offset == 0)
1586 set_bit(GBF_FULL, &rbm->bi->bi_flags);
1587
1588next_bitmap: /* Find next bitmap in the rgrp */
1589 rbm->offset = 0;
1590 index = rbm->bi - rbm->rgd->rd_bits;
1591 index++;
1592 if (index == rbm->rgd->rd_length)
1593 index = 0;
1594res_covered_end_of_rgrp:
1595 rbm->bi = &rbm->rgd->rd_bits[index];
1596 if ((index == 0) && nowrap)
1597 break;
1598 n++;
1599next_iter:
1600 if (n >= iters)
1601 break;
1602 }
1603
1604 return -ENOSPC;
1478} 1605}
1479 1606
1480/** 1607/**
@@ -1489,34 +1616,33 @@ static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip)
1489 1616
1490static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip) 1617static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip)
1491{ 1618{
1492 u32 goal = 0, block; 1619 u64 block;
1493 u64 no_addr;
1494 struct gfs2_sbd *sdp = rgd->rd_sbd; 1620 struct gfs2_sbd *sdp = rgd->rd_sbd;
1495 struct gfs2_glock *gl; 1621 struct gfs2_glock *gl;
1496 struct gfs2_inode *ip; 1622 struct gfs2_inode *ip;
1497 int error; 1623 int error;
1498 int found = 0; 1624 int found = 0;
1499 struct gfs2_bitmap *bi; 1625 struct gfs2_rbm rbm = { .rgd = rgd, .bi = rgd->rd_bits, .offset = 0 };
1500 1626
1501 while (goal < rgd->rd_data) { 1627 while (1) {
1502 down_write(&sdp->sd_log_flush_lock); 1628 down_write(&sdp->sd_log_flush_lock);
1503 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, &bi); 1629 error = gfs2_rbm_find(&rbm, GFS2_BLKST_UNLINKED, 0, NULL, true);
1504 up_write(&sdp->sd_log_flush_lock); 1630 up_write(&sdp->sd_log_flush_lock);
1505 if (block == BFITNOENT) 1631 if (error == -ENOSPC)
1632 break;
1633 if (WARN_ON_ONCE(error))
1506 break; 1634 break;
1507 1635
1508 block = gfs2_bi2rgd_blk(bi, block); 1636 block = gfs2_rbm_to_block(&rbm);
1509 /* rgblk_search can return a block < goal, so we need to 1637 if (gfs2_rbm_from_block(&rbm, block + 1))
1510 keep it marching forward. */ 1638 break;
1511 no_addr = block + rgd->rd_data0; 1639 if (*last_unlinked != NO_BLOCK && block <= *last_unlinked)
1512 goal = max(block + 1, goal + 1);
1513 if (*last_unlinked != NO_BLOCK && no_addr <= *last_unlinked)
1514 continue; 1640 continue;
1515 if (no_addr == skip) 1641 if (block == skip)
1516 continue; 1642 continue;
1517 *last_unlinked = no_addr; 1643 *last_unlinked = block;
1518 1644
1519 error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &gl); 1645 error = gfs2_glock_get(sdp, block, &gfs2_inode_glops, CREATE, &gl);
1520 if (error) 1646 if (error)
1521 continue; 1647 continue;
1522 1648
@@ -1543,6 +1669,19 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
1543 return; 1669 return;
1544} 1670}
1545 1671
1672static bool gfs2_select_rgrp(struct gfs2_rgrpd **pos, const struct gfs2_rgrpd *begin)
1673{
1674 struct gfs2_rgrpd *rgd = *pos;
1675
1676 rgd = gfs2_rgrpd_get_next(rgd);
1677 if (rgd == NULL)
1678 rgd = gfs2_rgrpd_get_next(NULL);
1679 *pos = rgd;
1680 if (rgd != begin) /* If we didn't wrap */
1681 return true;
1682 return false;
1683}
1684
1546/** 1685/**
1547 * gfs2_inplace_reserve - Reserve space in the filesystem 1686 * gfs2_inplace_reserve - Reserve space in the filesystem
1548 * @ip: the inode to reserve space for 1687 * @ip: the inode to reserve space for
@@ -1562,103 +1701,96 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested)
1562 1701
1563 if (sdp->sd_args.ar_rgrplvb) 1702 if (sdp->sd_args.ar_rgrplvb)
1564 flags |= GL_SKIP; 1703 flags |= GL_SKIP;
1565 rs->rs_requested = requested; 1704 if (gfs2_assert_warn(sdp, requested))
1566 if (gfs2_assert_warn(sdp, requested)) { 1705 return -EINVAL;
1567 error = -EINVAL;
1568 goto out;
1569 }
1570 if (gfs2_rs_active(rs)) { 1706 if (gfs2_rs_active(rs)) {
1571 begin = rs->rs_rgd; 1707 begin = rs->rs_rbm.rgd;
1572 flags = 0; /* Yoda: Do or do not. There is no try */ 1708 flags = 0; /* Yoda: Do or do not. There is no try */
1573 } else if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal)) { 1709 } else if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal)) {
1574 rs->rs_rgd = begin = ip->i_rgd; 1710 rs->rs_rbm.rgd = begin = ip->i_rgd;
1575 } else { 1711 } else {
1576 rs->rs_rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1); 1712 rs->rs_rbm.rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1);
1577 } 1713 }
1578 if (rs->rs_rgd == NULL) 1714 if (rs->rs_rbm.rgd == NULL)
1579 return -EBADSLT; 1715 return -EBADSLT;
1580 1716
1581 while (loops < 3) { 1717 while (loops < 3) {
1582 rg_locked = 0; 1718 rg_locked = 1;
1583 1719
1584 if (gfs2_glock_is_locked_by_me(rs->rs_rgd->rd_gl)) { 1720 if (!gfs2_glock_is_locked_by_me(rs->rs_rbm.rgd->rd_gl)) {
1585 rg_locked = 1; 1721 rg_locked = 0;
1586 error = 0; 1722 error = gfs2_glock_nq_init(rs->rs_rbm.rgd->rd_gl,
1587 } else if (!loops && !gfs2_rs_active(rs) &&
1588 rs->rs_rgd->rd_rs_cnt > RGRP_RSRV_MAX_CONTENDERS) {
1589 /* If the rgrp already is maxed out for contenders,
1590 we can eliminate it as a "first pass" without even
1591 requesting the rgrp glock. */
1592 error = GLR_TRYFAILED;
1593 } else {
1594 error = gfs2_glock_nq_init(rs->rs_rgd->rd_gl,
1595 LM_ST_EXCLUSIVE, flags, 1723 LM_ST_EXCLUSIVE, flags,
1596 &rs->rs_rgd_gh); 1724 &rs->rs_rgd_gh);
1597 if (!error && sdp->sd_args.ar_rgrplvb) { 1725 if (error == GLR_TRYFAILED)
1598 error = update_rgrp_lvb(rs->rs_rgd); 1726 goto next_rgrp;
1599 if (error) { 1727 if (unlikely(error))
1728 return error;
1729 if (sdp->sd_args.ar_rgrplvb) {
1730 error = update_rgrp_lvb(rs->rs_rbm.rgd);
1731 if (unlikely(error)) {
1600 gfs2_glock_dq_uninit(&rs->rs_rgd_gh); 1732 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
1601 return error; 1733 return error;
1602 } 1734 }
1603 } 1735 }
1604 } 1736 }
1605 switch (error) {
1606 case 0:
1607 if (gfs2_rs_active(rs)) {
1608 if (unclaimed_blocks(rs->rs_rgd) +
1609 rs->rs_free >= rs->rs_requested) {
1610 ip->i_rgd = rs->rs_rgd;
1611 return 0;
1612 }
1613 /* We have a multi-block reservation, but the
1614 rgrp doesn't have enough free blocks to
1615 satisfy the request. Free the reservation
1616 and look for a suitable rgrp. */
1617 gfs2_rs_deltree(rs);
1618 }
1619 if (try_rgrp_fit(rs->rs_rgd, ip)) {
1620 if (sdp->sd_args.ar_rgrplvb)
1621 gfs2_rgrp_bh_get(rs->rs_rgd);
1622 ip->i_rgd = rs->rs_rgd;
1623 return 0;
1624 }
1625 if (rs->rs_rgd->rd_flags & GFS2_RDF_CHECK) {
1626 if (sdp->sd_args.ar_rgrplvb)
1627 gfs2_rgrp_bh_get(rs->rs_rgd);
1628 try_rgrp_unlink(rs->rs_rgd, &last_unlinked,
1629 ip->i_no_addr);
1630 }
1631 if (!rg_locked)
1632 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
1633 /* fall through */
1634 case GLR_TRYFAILED:
1635 rs->rs_rgd = gfs2_rgrpd_get_next(rs->rs_rgd);
1636 rs->rs_rgd = rs->rs_rgd ? : begin; /* if NULL, wrap */
1637 if (rs->rs_rgd != begin) /* If we didn't wrap */
1638 break;
1639 1737
1640 flags &= ~LM_FLAG_TRY; 1738 /* Skip unuseable resource groups */
1641 loops++; 1739 if (rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR))
1642 /* Check that fs hasn't grown if writing to rindex */ 1740 goto skip_rgrp;
1643 if (ip == GFS2_I(sdp->sd_rindex) && 1741
1644 !sdp->sd_rindex_uptodate) { 1742 if (sdp->sd_args.ar_rgrplvb)
1645 error = gfs2_ri_update(ip); 1743 gfs2_rgrp_bh_get(rs->rs_rbm.rgd);
1646 if (error) 1744
1647 goto out; 1745 /* Get a reservation if we don't already have one */
1648 } else if (loops == 2) 1746 if (!gfs2_rs_active(rs))
1649 /* Flushing the log may release space */ 1747 rg_mblk_search(rs->rs_rbm.rgd, ip, requested);
1650 gfs2_log_flush(sdp, NULL); 1748
1651 break; 1749 /* Skip rgrps when we can't get a reservation on first pass */
1652 default: 1750 if (!gfs2_rs_active(rs) && (loops < 1))
1653 goto out; 1751 goto check_rgrp;
1752
1753 /* If rgrp has enough free space, use it */
1754 if (rs->rs_rbm.rgd->rd_free_clone >= requested) {
1755 ip->i_rgd = rs->rs_rbm.rgd;
1756 return 0;
1757 }
1758
1759 /* Drop reservation, if we couldn't use reserved rgrp */
1760 if (gfs2_rs_active(rs))
1761 gfs2_rs_deltree(ip, rs);
1762check_rgrp:
1763 /* Check for unlinked inodes which can be reclaimed */
1764 if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK)
1765 try_rgrp_unlink(rs->rs_rbm.rgd, &last_unlinked,
1766 ip->i_no_addr);
1767skip_rgrp:
1768 /* Unlock rgrp if required */
1769 if (!rg_locked)
1770 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
1771next_rgrp:
1772 /* Find the next rgrp, and continue looking */
1773 if (gfs2_select_rgrp(&rs->rs_rbm.rgd, begin))
1774 continue;
1775
1776 /* If we've scanned all the rgrps, but found no free blocks
1777 * then this checks for some less likely conditions before
1778 * trying again.
1779 */
1780 flags &= ~LM_FLAG_TRY;
1781 loops++;
1782 /* Check that fs hasn't grown if writing to rindex */
1783 if (ip == GFS2_I(sdp->sd_rindex) && !sdp->sd_rindex_uptodate) {
1784 error = gfs2_ri_update(ip);
1785 if (error)
1786 return error;
1654 } 1787 }
1788 /* Flushing the log may release space */
1789 if (loops == 2)
1790 gfs2_log_flush(sdp, NULL);
1655 } 1791 }
1656 error = -ENOSPC;
1657 1792
1658out: 1793 return -ENOSPC;
1659 if (error)
1660 rs->rs_requested = 0;
1661 return error;
1662} 1794}
1663 1795
1664/** 1796/**
@@ -1672,15 +1804,8 @@ void gfs2_inplace_release(struct gfs2_inode *ip)
1672{ 1804{
1673 struct gfs2_blkreserv *rs = ip->i_res; 1805 struct gfs2_blkreserv *rs = ip->i_res;
1674 1806
1675 if (!rs)
1676 return;
1677
1678 if (!rs->rs_free)
1679 gfs2_rs_deltree(rs);
1680
1681 if (rs->rs_rgd_gh.gh_gl) 1807 if (rs->rs_rgd_gh.gh_gl)
1682 gfs2_glock_dq_uninit(&rs->rs_rgd_gh); 1808 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
1683 rs->rs_requested = 0;
1684} 1809}
1685 1810
1686/** 1811/**
@@ -1693,173 +1818,47 @@ void gfs2_inplace_release(struct gfs2_inode *ip)
1693 1818
1694static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) 1819static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
1695{ 1820{
1696 struct gfs2_bitmap *bi = NULL; 1821 struct gfs2_rbm rbm = { .rgd = rgd, };
1697 u32 length, rgrp_block, buf_block; 1822 int ret;
1698 unsigned int buf;
1699 unsigned char type;
1700
1701 length = rgd->rd_length;
1702 rgrp_block = block - rgd->rd_data0;
1703
1704 for (buf = 0; buf < length; buf++) {
1705 bi = rgd->rd_bits + buf;
1706 if (rgrp_block < (bi->bi_start + bi->bi_len) * GFS2_NBBY)
1707 break;
1708 }
1709 1823
1710 gfs2_assert(rgd->rd_sbd, buf < length); 1824 ret = gfs2_rbm_from_block(&rbm, block);
1711 buf_block = rgrp_block - bi->bi_start * GFS2_NBBY; 1825 WARN_ON_ONCE(ret != 0);
1712 1826
1713 type = gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset, 1827 return gfs2_testbit(&rbm);
1714 bi->bi_len, buf_block);
1715
1716 return type;
1717} 1828}
1718 1829
1719/**
1720 * rgblk_search - find a block in @state
1721 * @rgd: the resource group descriptor
1722 * @goal: the goal block within the RG (start here to search for avail block)
1723 * @state: GFS2_BLKST_XXX the before-allocation state to find
1724 * @rbi: address of the pointer to the bitmap containing the block found
1725 *
1726 * Walk rgrp's bitmap to find bits that represent a block in @state.
1727 *
1728 * This function never fails, because we wouldn't call it unless we
1729 * know (from reservation results, etc.) that a block is available.
1730 *
1731 * Scope of @goal is just within rgrp, not the whole filesystem.
1732 * Scope of @returned block is just within bitmap, not the whole filesystem.
1733 *
1734 * Returns: the block number found relative to the bitmap rbi
1735 */
1736
1737static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, unsigned char state,
1738 struct gfs2_bitmap **rbi)
1739{
1740 struct gfs2_bitmap *bi = NULL;
1741 const u32 length = rgd->rd_length;
1742 u32 biblk = BFITNOENT;
1743 unsigned int buf, x;
1744 const u8 *buffer = NULL;
1745
1746 *rbi = NULL;
1747 /* Find bitmap block that contains bits for goal block */
1748 for (buf = 0; buf < length; buf++) {
1749 bi = rgd->rd_bits + buf;
1750 /* Convert scope of "goal" from rgrp-wide to within found bit block */
1751 if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) {
1752 goal -= bi->bi_start * GFS2_NBBY;
1753 goto do_search;
1754 }
1755 }
1756 buf = 0;
1757 goal = 0;
1758
1759do_search:
1760 /* Search (up to entire) bitmap in this rgrp for allocatable block.
1761 "x <= length", instead of "x < length", because we typically start
1762 the search in the middle of a bit block, but if we can't find an
1763 allocatable block anywhere else, we want to be able wrap around and
1764 search in the first part of our first-searched bit block. */
1765 for (x = 0; x <= length; x++) {
1766 bi = rgd->rd_bits + buf;
1767
1768 if (test_bit(GBF_FULL, &bi->bi_flags) &&
1769 (state == GFS2_BLKST_FREE))
1770 goto skip;
1771
1772 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone
1773 bitmaps, so we must search the originals for that. */
1774 buffer = bi->bi_bh->b_data + bi->bi_offset;
1775 WARN_ON(!buffer_uptodate(bi->bi_bh));
1776 if (state != GFS2_BLKST_UNLINKED && bi->bi_clone)
1777 buffer = bi->bi_clone + bi->bi_offset;
1778
1779 while (1) {
1780 struct gfs2_blkreserv *rs;
1781 u32 rgblk;
1782
1783 biblk = gfs2_bitfit(buffer, bi->bi_len, goal, state);
1784 if (biblk == BFITNOENT)
1785 break;
1786 /* Check if this block is reserved() */
1787 rgblk = gfs2_bi2rgd_blk(bi, biblk);
1788 rs = rs_find(rgd, rgblk);
1789 if (rs == NULL)
1790 break;
1791
1792 BUG_ON(rs->rs_bi != bi);
1793 biblk = BFITNOENT;
1794 /* This should jump to the first block after the
1795 reservation. */
1796 goal = rs->rs_biblk + rs->rs_free;
1797 if (goal >= bi->bi_len * GFS2_NBBY)
1798 break;
1799 }
1800 if (biblk != BFITNOENT)
1801 break;
1802
1803 if ((goal == 0) && (state == GFS2_BLKST_FREE))
1804 set_bit(GBF_FULL, &bi->bi_flags);
1805
1806 /* Try next bitmap block (wrap back to rgrp header if at end) */
1807skip:
1808 buf++;
1809 buf %= length;
1810 goal = 0;
1811 }
1812
1813 if (biblk != BFITNOENT)
1814 *rbi = bi;
1815
1816 return biblk;
1817}
1818 1830
1819/** 1831/**
1820 * gfs2_alloc_extent - allocate an extent from a given bitmap 1832 * gfs2_alloc_extent - allocate an extent from a given bitmap
1821 * @rgd: the resource group descriptor 1833 * @rbm: the resource group information
1822 * @bi: the bitmap within the rgrp
1823 * @blk: the block within the bitmap
1824 * @dinode: TRUE if the first block we allocate is for a dinode 1834 * @dinode: TRUE if the first block we allocate is for a dinode
1825 * @n: The extent length 1835 * @n: The extent length (value/result)
1826 * 1836 *
1827 * Add the found bitmap buffer to the transaction. 1837 * Add the bitmap buffer to the transaction.
1828 * Set the found bits to @new_state to change block's allocation state. 1838 * Set the found bits to @new_state to change block's allocation state.
1829 * Returns: starting block number of the extent (fs scope)
1830 */ 1839 */
1831static u64 gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi, 1840static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, bool dinode,
1832 u32 blk, bool dinode, unsigned int *n) 1841 unsigned int *n)
1833{ 1842{
1843 struct gfs2_rbm pos = { .rgd = rbm->rgd, };
1834 const unsigned int elen = *n; 1844 const unsigned int elen = *n;
1835 u32 goal, rgblk; 1845 u64 block;
1836 const u8 *buffer = NULL; 1846 int ret;
1837 struct gfs2_blkreserv *rs; 1847
1838 1848 *n = 1;
1839 *n = 0; 1849 block = gfs2_rbm_to_block(rbm);
1840 buffer = bi->bi_bh->b_data + bi->bi_offset; 1850 gfs2_trans_add_bh(rbm->rgd->rd_gl, rbm->bi->bi_bh, 1);
1841 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); 1851 gfs2_setbit(rbm, true, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
1842 gfs2_setbit(rgd, bi->bi_clone, bi, blk, 1852 block++;
1843 dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
1844 (*n)++;
1845 goal = blk;
1846 while (*n < elen) { 1853 while (*n < elen) {
1847 goal++; 1854 ret = gfs2_rbm_from_block(&pos, block);
1848 if (goal >= (bi->bi_len * GFS2_NBBY)) 1855 if (ret || gfs2_testbit(&pos) != GFS2_BLKST_FREE)
1849 break;
1850 rgblk = gfs2_bi2rgd_blk(bi, goal);
1851 rs = rs_find(rgd, rgblk);
1852 if (rs) /* Oops, we bumped into someone's reservation */
1853 break;
1854 if (gfs2_testbit(rgd, buffer, bi->bi_len, goal) !=
1855 GFS2_BLKST_FREE)
1856 break; 1856 break;
1857 gfs2_setbit(rgd, bi->bi_clone, bi, goal, GFS2_BLKST_USED); 1857 gfs2_trans_add_bh(pos.rgd->rd_gl, pos.bi->bi_bh, 1);
1858 gfs2_setbit(&pos, true, GFS2_BLKST_USED);
1858 (*n)++; 1859 (*n)++;
1860 block++;
1859 } 1861 }
1860 blk = gfs2_bi2rgd_blk(bi, blk);
1861 rgd->rd_last_alloc = blk + *n - 1;
1862 return rgd->rd_data0 + blk;
1863} 1862}
1864 1863
1865/** 1864/**
@@ -1875,46 +1874,30 @@ static u64 gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi,
1875static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart, 1874static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
1876 u32 blen, unsigned char new_state) 1875 u32 blen, unsigned char new_state)
1877{ 1876{
1878 struct gfs2_rgrpd *rgd; 1877 struct gfs2_rbm rbm;
1879 struct gfs2_bitmap *bi = NULL;
1880 u32 length, rgrp_blk, buf_blk;
1881 unsigned int buf;
1882 1878
1883 rgd = gfs2_blk2rgrpd(sdp, bstart, 1); 1879 rbm.rgd = gfs2_blk2rgrpd(sdp, bstart, 1);
1884 if (!rgd) { 1880 if (!rbm.rgd) {
1885 if (gfs2_consist(sdp)) 1881 if (gfs2_consist(sdp))
1886 fs_err(sdp, "block = %llu\n", (unsigned long long)bstart); 1882 fs_err(sdp, "block = %llu\n", (unsigned long long)bstart);
1887 return NULL; 1883 return NULL;
1888 } 1884 }
1889 1885
1890 length = rgd->rd_length;
1891
1892 rgrp_blk = bstart - rgd->rd_data0;
1893
1894 while (blen--) { 1886 while (blen--) {
1895 for (buf = 0; buf < length; buf++) { 1887 gfs2_rbm_from_block(&rbm, bstart);
1896 bi = rgd->rd_bits + buf; 1888 bstart++;
1897 if (rgrp_blk < (bi->bi_start + bi->bi_len) * GFS2_NBBY) 1889 if (!rbm.bi->bi_clone) {
1898 break; 1890 rbm.bi->bi_clone = kmalloc(rbm.bi->bi_bh->b_size,
1899 } 1891 GFP_NOFS | __GFP_NOFAIL);
1900 1892 memcpy(rbm.bi->bi_clone + rbm.bi->bi_offset,
1901 gfs2_assert(rgd->rd_sbd, buf < length); 1893 rbm.bi->bi_bh->b_data + rbm.bi->bi_offset,
1902 1894 rbm.bi->bi_len);
1903 buf_blk = rgrp_blk - bi->bi_start * GFS2_NBBY;
1904 rgrp_blk++;
1905
1906 if (!bi->bi_clone) {
1907 bi->bi_clone = kmalloc(bi->bi_bh->b_size,
1908 GFP_NOFS | __GFP_NOFAIL);
1909 memcpy(bi->bi_clone + bi->bi_offset,
1910 bi->bi_bh->b_data + bi->bi_offset,
1911 bi->bi_len);
1912 } 1895 }
1913 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); 1896 gfs2_trans_add_bh(rbm.rgd->rd_gl, rbm.bi->bi_bh, 1);
1914 gfs2_setbit(rgd, NULL, bi, buf_blk, new_state); 1897 gfs2_setbit(&rbm, false, new_state);
1915 } 1898 }
1916 1899
1917 return rgd; 1900 return rbm.rgd;
1918} 1901}
1919 1902
1920/** 1903/**
@@ -1956,56 +1939,41 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)
1956} 1939}
1957 1940
1958/** 1941/**
1959 * claim_reserved_blks - Claim previously reserved blocks 1942 * gfs2_adjust_reservation - Adjust (or remove) a reservation after allocation
1960 * @ip: the inode that's claiming the reservation 1943 * @ip: The inode we have just allocated blocks for
1961 * @dinode: 1 if this block is a dinode block, otherwise data block 1944 * @rbm: The start of the allocated blocks
1962 * @nblocks: desired extent length 1945 * @len: The extent length
1963 * 1946 *
1964 * Lay claim to previously allocated block reservation blocks. 1947 * Adjusts a reservation after an allocation has taken place. If the
1965 * Returns: Starting block number of the blocks claimed. 1948 * reservation does not match the allocation, or if it is now empty
1966 * Sets *nblocks to the actual extent length allocated. 1949 * then it is removed.
1967 */ 1950 */
1968static u64 claim_reserved_blks(struct gfs2_inode *ip, bool dinode, 1951
1969 unsigned int *nblocks) 1952static void gfs2_adjust_reservation(struct gfs2_inode *ip,
1953 const struct gfs2_rbm *rbm, unsigned len)
1970{ 1954{
1971 struct gfs2_blkreserv *rs = ip->i_res; 1955 struct gfs2_blkreserv *rs = ip->i_res;
1972 struct gfs2_rgrpd *rgd = rs->rs_rgd; 1956 struct gfs2_rgrpd *rgd = rbm->rgd;
1973 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1957 unsigned rlen;
1974 struct gfs2_bitmap *bi; 1958 u64 block;
1975 u64 start_block = gfs2_rs_startblk(rs); 1959 int ret;
1976 const unsigned int elen = *nblocks;
1977
1978 /*BUG_ON(!gfs2_glock_is_locked_by_me(ip->i_gl));*/
1979 gfs2_assert_withdraw(sdp, rgd);
1980 /*BUG_ON(!gfs2_glock_is_locked_by_me(rgd->rd_gl));*/
1981 bi = rs->rs_bi;
1982 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
1983
1984 for (*nblocks = 0; *nblocks < elen && rs->rs_free; (*nblocks)++) {
1985 /* Make sure the bitmap hasn't changed */
1986 gfs2_setbit(rgd, bi->bi_clone, bi, rs->rs_biblk,
1987 dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
1988 rs->rs_biblk++;
1989 rs->rs_free--;
1990
1991 BUG_ON(!rgd->rd_reserved);
1992 rgd->rd_reserved--;
1993 dinode = false;
1994 trace_gfs2_rs(ip, rs, TRACE_RS_CLAIM);
1995 }
1996
1997 if (!rs->rs_free) {
1998 struct gfs2_rgrpd *rgd = ip->i_res->rs_rgd;
1999 1960
2000 gfs2_rs_deltree(rs); 1961 spin_lock(&rgd->rd_rsspin);
2001 /* -nblocks because we haven't returned to do the math yet. 1962 if (gfs2_rs_active(rs)) {
2002 I'm doing the math backwards to prevent negative numbers, 1963 if (gfs2_rbm_eq(&rs->rs_rbm, rbm)) {
2003 but think of it as: 1964 block = gfs2_rbm_to_block(rbm);
2004 if (unclaimed_blocks(rgd) - *nblocks >= RGRP_RSRV_MINBLKS */ 1965 ret = gfs2_rbm_from_block(&rs->rs_rbm, block + len);
2005 if (unclaimed_blocks(rgd) >= RGRP_RSRV_MINBLKS + *nblocks) 1966 rlen = min(rs->rs_free, len);
2006 rg_mblk_search(rgd, ip); 1967 rs->rs_free -= rlen;
1968 rgd->rd_reserved -= rlen;
1969 trace_gfs2_rs(rs, TRACE_RS_CLAIM);
1970 if (rs->rs_free && !ret)
1971 goto out;
1972 }
1973 __rs_deltree(ip, rs);
2007 } 1974 }
2008 return start_block; 1975out:
1976 spin_unlock(&rgd->rd_rsspin);
2009} 1977}
2010 1978
2011/** 1979/**
@@ -2024,47 +1992,40 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
2024{ 1992{
2025 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1993 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
2026 struct buffer_head *dibh; 1994 struct buffer_head *dibh;
2027 struct gfs2_rgrpd *rgd; 1995 struct gfs2_rbm rbm = { .rgd = ip->i_rgd, };
2028 unsigned int ndata; 1996 unsigned int ndata;
2029 u32 goal, blk; /* block, within the rgrp scope */ 1997 u64 goal;
2030 u64 block; /* block, within the file system scope */ 1998 u64 block; /* block, within the file system scope */
2031 int error; 1999 int error;
2032 struct gfs2_bitmap *bi;
2033 2000
2034 /* Only happens if there is a bug in gfs2, return something distinctive 2001 if (gfs2_rs_active(ip->i_res))
2035 * to ensure that it is noticed. 2002 goal = gfs2_rbm_to_block(&ip->i_res->rs_rbm);
2036 */ 2003 else if (!dinode && rgrp_contains_block(rbm.rgd, ip->i_goal))
2037 if (ip->i_res->rs_requested == 0) 2004 goal = ip->i_goal;
2038 return -ECANCELED; 2005 else
2039 2006 goal = rbm.rgd->rd_last_alloc + rbm.rgd->rd_data0;
2040 /* Check if we have a multi-block reservation, and if so, claim the
2041 next free block from it. */
2042 if (gfs2_rs_active(ip->i_res)) {
2043 BUG_ON(!ip->i_res->rs_free);
2044 rgd = ip->i_res->rs_rgd;
2045 block = claim_reserved_blks(ip, dinode, nblocks);
2046 } else {
2047 rgd = ip->i_rgd;
2048 2007
2049 if (!dinode && rgrp_contains_block(rgd, ip->i_goal)) 2008 gfs2_rbm_from_block(&rbm, goal);
2050 goal = ip->i_goal - rgd->rd_data0; 2009 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false);
2051 else
2052 goal = rgd->rd_last_alloc;
2053
2054 blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, &bi);
2055
2056 /* Since all blocks are reserved in advance, this shouldn't
2057 happen */
2058 if (blk == BFITNOENT) {
2059 printk(KERN_WARNING "BFITNOENT, nblocks=%u\n",
2060 *nblocks);
2061 printk(KERN_WARNING "FULL=%d\n",
2062 test_bit(GBF_FULL, &rgd->rd_bits->bi_flags));
2063 goto rgrp_error;
2064 }
2065 2010
2066 block = gfs2_alloc_extent(rgd, bi, blk, dinode, nblocks); 2011 if (error == -ENOSPC) {
2012 gfs2_rbm_from_block(&rbm, goal);
2013 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false);
2014 }
2015
2016 /* Since all blocks are reserved in advance, this shouldn't happen */
2017 if (error) {
2018 fs_warn(sdp, "inum=%llu error=%d, nblocks=%u, full=%d\n",
2019 (unsigned long long)ip->i_no_addr, error, *nblocks,
2020 test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags));
2021 goto rgrp_error;
2067 } 2022 }
2023
2024 gfs2_alloc_extent(&rbm, dinode, nblocks);
2025 block = gfs2_rbm_to_block(&rbm);
2026 rbm.rgd->rd_last_alloc = block - rbm.rgd->rd_data0;
2027 if (gfs2_rs_active(ip->i_res))
2028 gfs2_adjust_reservation(ip, &rbm, *nblocks);
2068 ndata = *nblocks; 2029 ndata = *nblocks;
2069 if (dinode) 2030 if (dinode)
2070 ndata--; 2031 ndata--;
@@ -2081,22 +2042,22 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
2081 brelse(dibh); 2042 brelse(dibh);
2082 } 2043 }
2083 } 2044 }
2084 if (rgd->rd_free < *nblocks) { 2045 if (rbm.rgd->rd_free < *nblocks) {
2085 printk(KERN_WARNING "nblocks=%u\n", *nblocks); 2046 printk(KERN_WARNING "nblocks=%u\n", *nblocks);
2086 goto rgrp_error; 2047 goto rgrp_error;
2087 } 2048 }
2088 2049
2089 rgd->rd_free -= *nblocks; 2050 rbm.rgd->rd_free -= *nblocks;
2090 if (dinode) { 2051 if (dinode) {
2091 rgd->rd_dinodes++; 2052 rbm.rgd->rd_dinodes++;
2092 *generation = rgd->rd_igeneration++; 2053 *generation = rbm.rgd->rd_igeneration++;
2093 if (*generation == 0) 2054 if (*generation == 0)
2094 *generation = rgd->rd_igeneration++; 2055 *generation = rbm.rgd->rd_igeneration++;
2095 } 2056 }
2096 2057
2097 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); 2058 gfs2_trans_add_bh(rbm.rgd->rd_gl, rbm.rgd->rd_bits[0].bi_bh, 1);
2098 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); 2059 gfs2_rgrp_out(rbm.rgd, rbm.rgd->rd_bits[0].bi_bh->b_data);
2099 gfs2_rgrp_ondisk2lvb(rgd->rd_rgl, rgd->rd_bits[0].bi_bh->b_data); 2060 gfs2_rgrp_ondisk2lvb(rbm.rgd->rd_rgl, rbm.rgd->rd_bits[0].bi_bh->b_data);
2100 2061
2101 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); 2062 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0);
2102 if (dinode) 2063 if (dinode)
@@ -2110,14 +2071,14 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
2110 gfs2_quota_change(ip, ndata, ip->i_inode.i_uid, 2071 gfs2_quota_change(ip, ndata, ip->i_inode.i_uid,
2111 ip->i_inode.i_gid); 2072 ip->i_inode.i_gid);
2112 2073
2113 rgd->rd_free_clone -= *nblocks; 2074 rbm.rgd->rd_free_clone -= *nblocks;
2114 trace_gfs2_block_alloc(ip, rgd, block, *nblocks, 2075 trace_gfs2_block_alloc(ip, rbm.rgd, block, *nblocks,
2115 dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); 2076 dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
2116 *bn = block; 2077 *bn = block;
2117 return 0; 2078 return 0;
2118 2079
2119rgrp_error: 2080rgrp_error:
2120 gfs2_rgrp_error(rgd); 2081 gfs2_rgrp_error(rbm.rgd);
2121 return -EIO; 2082 return -EIO;
2122} 2083}
2123 2084
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index ca6e26729b86..24077958dcf6 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -46,7 +46,7 @@ extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
46 bool dinode, u64 *generation); 46 bool dinode, u64 *generation);
47 47
48extern int gfs2_rs_alloc(struct gfs2_inode *ip); 48extern int gfs2_rs_alloc(struct gfs2_inode *ip);
49extern void gfs2_rs_deltree(struct gfs2_blkreserv *rs); 49extern void gfs2_rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs);
50extern void gfs2_rs_delete(struct gfs2_inode *ip); 50extern void gfs2_rs_delete(struct gfs2_inode *ip);
51extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta); 51extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta);
52extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); 52extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
@@ -73,30 +73,10 @@ extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
73 const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed); 73 const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed);
74extern int gfs2_fitrim(struct file *filp, void __user *argp); 74extern int gfs2_fitrim(struct file *filp, void __user *argp);
75 75
76/* This is how to tell if a multi-block reservation is "inplace" reserved: */ 76/* This is how to tell if a reservation is in the rgrp tree: */
77static inline int gfs2_mb_reserved(struct gfs2_inode *ip) 77static inline bool gfs2_rs_active(struct gfs2_blkreserv *rs)
78{ 78{
79 if (ip->i_res && ip->i_res->rs_requested) 79 return rs && !RB_EMPTY_NODE(&rs->rs_node);
80 return 1;
81 return 0;
82}
83
84/* This is how to tell if a multi-block reservation is in the rgrp tree: */
85static inline int gfs2_rs_active(struct gfs2_blkreserv *rs)
86{
87 if (rs && rs->rs_bi)
88 return 1;
89 return 0;
90}
91
92static inline u32 gfs2_bi2rgd_blk(const struct gfs2_bitmap *bi, u32 blk)
93{
94 return (bi->bi_start * GFS2_NBBY) + blk;
95}
96
97static inline u64 gfs2_rs_startblk(const struct gfs2_blkreserv *rs)
98{
99 return gfs2_bi2rgd_blk(rs->rs_bi, rs->rs_biblk) + rs->rs_rgd->rd_data0;
100} 80}
101 81
102#endif /* __RGRP_DOT_H__ */ 82#endif /* __RGRP_DOT_H__ */
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index fc3168f47a14..a8d90f2f576c 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1366,6 +1366,8 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root)
1366 val = sdp->sd_tune.gt_statfs_quantum; 1366 val = sdp->sd_tune.gt_statfs_quantum;
1367 if (val != 30) 1367 if (val != 30)
1368 seq_printf(s, ",statfs_quantum=%d", val); 1368 seq_printf(s, ",statfs_quantum=%d", val);
1369 else if (sdp->sd_tune.gt_statfs_slow)
1370 seq_puts(s, ",statfs_quantum=0");
1369 val = sdp->sd_tune.gt_quota_quantum; 1371 val = sdp->sd_tune.gt_quota_quantum;
1370 if (val != 60) 1372 if (val != 60)
1371 seq_printf(s, ",quota_quantum=%d", val); 1373 seq_printf(s, ",quota_quantum=%d", val);
@@ -1543,6 +1545,11 @@ static void gfs2_evict_inode(struct inode *inode)
1543 1545
1544out_truncate: 1546out_truncate:
1545 gfs2_log_flush(sdp, ip->i_gl); 1547 gfs2_log_flush(sdp, ip->i_gl);
1548 if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) {
1549 struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl);
1550 filemap_fdatawrite(metamapping);
1551 filemap_fdatawait(metamapping);
1552 }
1546 write_inode_now(inode, 1); 1553 write_inode_now(inode, 1);
1547 gfs2_ail_flush(ip->i_gl, 0); 1554 gfs2_ail_flush(ip->i_gl, 0);
1548 1555
@@ -1557,7 +1564,7 @@ out_truncate:
1557out_unlock: 1564out_unlock:
1558 /* Error path for case 1 */ 1565 /* Error path for case 1 */
1559 if (gfs2_rs_active(ip->i_res)) 1566 if (gfs2_rs_active(ip->i_res))
1560 gfs2_rs_deltree(ip->i_res); 1567 gfs2_rs_deltree(ip, ip->i_res);
1561 1568
1562 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) 1569 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
1563 gfs2_glock_dq(&ip->i_iopen_gh); 1570 gfs2_glock_dq(&ip->i_iopen_gh);
diff --git a/fs/gfs2/trace_gfs2.h b/fs/gfs2/trace_gfs2.h
index a25c252fe412..bbdc78af60ca 100644
--- a/fs/gfs2/trace_gfs2.h
+++ b/fs/gfs2/trace_gfs2.h
@@ -509,10 +509,9 @@ TRACE_EVENT(gfs2_block_alloc,
509/* Keep track of multi-block reservations as they are allocated/freed */ 509/* Keep track of multi-block reservations as they are allocated/freed */
510TRACE_EVENT(gfs2_rs, 510TRACE_EVENT(gfs2_rs,
511 511
512 TP_PROTO(const struct gfs2_inode *ip, const struct gfs2_blkreserv *rs, 512 TP_PROTO(const struct gfs2_blkreserv *rs, u8 func),
513 u8 func),
514 513
515 TP_ARGS(ip, rs, func), 514 TP_ARGS(rs, func),
516 515
517 TP_STRUCT__entry( 516 TP_STRUCT__entry(
518 __field( dev_t, dev ) 517 __field( dev_t, dev )
@@ -526,18 +525,17 @@ TRACE_EVENT(gfs2_rs,
526 ), 525 ),
527 526
528 TP_fast_assign( 527 TP_fast_assign(
529 __entry->dev = rs->rs_rgd ? rs->rs_rgd->rd_sbd->sd_vfs->s_dev : 0; 528 __entry->dev = rs->rs_rbm.rgd->rd_sbd->sd_vfs->s_dev;
530 __entry->rd_addr = rs->rs_rgd ? rs->rs_rgd->rd_addr : 0; 529 __entry->rd_addr = rs->rs_rbm.rgd->rd_addr;
531 __entry->rd_free_clone = rs->rs_rgd ? rs->rs_rgd->rd_free_clone : 0; 530 __entry->rd_free_clone = rs->rs_rbm.rgd->rd_free_clone;
532 __entry->rd_reserved = rs->rs_rgd ? rs->rs_rgd->rd_reserved : 0; 531 __entry->rd_reserved = rs->rs_rbm.rgd->rd_reserved;
533 __entry->inum = ip ? ip->i_no_addr : 0; 532 __entry->inum = rs->rs_inum;
534 __entry->start = gfs2_rs_startblk(rs); 533 __entry->start = gfs2_rbm_to_block(&rs->rs_rbm);
535 __entry->free = rs->rs_free; 534 __entry->free = rs->rs_free;
536 __entry->func = func; 535 __entry->func = func;
537 ), 536 ),
538 537
539 TP_printk("%u,%u bmap %llu resrv %llu rg:%llu rf:%lu rr:%lu %s " 538 TP_printk("%u,%u bmap %llu resrv %llu rg:%llu rf:%lu rr:%lu %s f:%lu",
540 "f:%lu",
541 MAJOR(__entry->dev), MINOR(__entry->dev), 539 MAJOR(__entry->dev), MINOR(__entry->dev),
542 (unsigned long long)__entry->inum, 540 (unsigned long long)__entry->inum,
543 (unsigned long long)__entry->start, 541 (unsigned long long)__entry->start,
diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h
index 41f42cdccbb8..bf2ae9aeee7a 100644
--- a/fs/gfs2/trans.h
+++ b/fs/gfs2/trans.h
@@ -28,11 +28,10 @@ struct gfs2_glock;
28 28
29/* reserve either the number of blocks to be allocated plus the rg header 29/* reserve either the number of blocks to be allocated plus the rg header
30 * block, or all of the blocks in the rg, whichever is smaller */ 30 * block, or all of the blocks in the rg, whichever is smaller */
31static inline unsigned int gfs2_rg_blocks(const struct gfs2_inode *ip) 31static inline unsigned int gfs2_rg_blocks(const struct gfs2_inode *ip, unsigned requested)
32{ 32{
33 const struct gfs2_blkreserv *rs = ip->i_res; 33 if (requested < ip->i_rgd->rd_length)
34 if (rs && rs->rs_requested < ip->i_rgd->rd_length) 34 return requested + 1;
35 return rs->rs_requested + 1;
36 return ip->i_rgd->rd_length; 35 return ip->i_rgd->rd_length;
37} 36}
38 37
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index 27a0b4a901f5..db330e5518cd 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -448,17 +448,18 @@ ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
448} 448}
449 449
450/** 450/**
451 * ea_get_unstuffed - actually copies the unstuffed data into the 451 * ea_iter_unstuffed - copies the unstuffed xattr data to/from the
452 * request buffer 452 * request buffer
453 * @ip: The GFS2 inode 453 * @ip: The GFS2 inode
454 * @ea: The extended attribute header structure 454 * @ea: The extended attribute header structure
455 * @data: The data to be copied 455 * @din: The data to be copied in
456 * @dout: The data to be copied out (one of din,dout will be NULL)
456 * 457 *
457 * Returns: errno 458 * Returns: errno
458 */ 459 */
459 460
460static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, 461static int gfs2_iter_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
461 char *data) 462 const char *din, char *dout)
462{ 463{
463 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 464 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
464 struct buffer_head **bh; 465 struct buffer_head **bh;
@@ -467,6 +468,8 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
467 __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); 468 __be64 *dataptrs = GFS2_EA2DATAPTRS(ea);
468 unsigned int x; 469 unsigned int x;
469 int error = 0; 470 int error = 0;
471 unsigned char *pos;
472 unsigned cp_size;
470 473
471 bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS); 474 bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS);
472 if (!bh) 475 if (!bh)
@@ -497,12 +500,21 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
497 goto out; 500 goto out;
498 } 501 }
499 502
500 memcpy(data, bh[x]->b_data + sizeof(struct gfs2_meta_header), 503 pos = bh[x]->b_data + sizeof(struct gfs2_meta_header);
501 (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); 504 cp_size = (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize;
502 505
503 amount -= sdp->sd_jbsize; 506 if (dout) {
504 data += sdp->sd_jbsize; 507 memcpy(dout, pos, cp_size);
508 dout += sdp->sd_jbsize;
509 }
510
511 if (din) {
512 gfs2_trans_add_bh(ip->i_gl, bh[x], 1);
513 memcpy(pos, din, cp_size);
514 din += sdp->sd_jbsize;
515 }
505 516
517 amount -= sdp->sd_jbsize;
506 brelse(bh[x]); 518 brelse(bh[x]);
507 } 519 }
508 520
@@ -523,7 +535,7 @@ static int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el,
523 memcpy(data, GFS2_EA2DATA(el->el_ea), len); 535 memcpy(data, GFS2_EA2DATA(el->el_ea), len);
524 return len; 536 return len;
525 } 537 }
526 ret = ea_get_unstuffed(ip, el->el_ea, data); 538 ret = gfs2_iter_unstuffed(ip, el->el_ea, NULL, data);
527 if (ret < 0) 539 if (ret < 0)
528 return ret; 540 return ret;
529 return len; 541 return len;
@@ -727,7 +739,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
727 goto out_gunlock_q; 739 goto out_gunlock_q;
728 740
729 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), 741 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode),
730 blks + gfs2_rg_blocks(ip) + 742 blks + gfs2_rg_blocks(ip, blks) +
731 RES_DINODE + RES_STATFS + RES_QUOTA, 0); 743 RES_DINODE + RES_STATFS + RES_QUOTA, 0);
732 if (error) 744 if (error)
733 goto out_ipres; 745 goto out_ipres;
@@ -1220,69 +1232,23 @@ static int gfs2_xattr_set(struct dentry *dentry, const char *name,
1220 size, flags, type); 1232 size, flags, type);
1221} 1233}
1222 1234
1235
1223static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, 1236static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip,
1224 struct gfs2_ea_header *ea, char *data) 1237 struct gfs2_ea_header *ea, char *data)
1225{ 1238{
1226 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1239 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1227 struct buffer_head **bh;
1228 unsigned int amount = GFS2_EA_DATA_LEN(ea); 1240 unsigned int amount = GFS2_EA_DATA_LEN(ea);
1229 unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); 1241 unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize);
1230 __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); 1242 int ret;
1231 unsigned int x;
1232 int error;
1233
1234 bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS);
1235 if (!bh)
1236 return -ENOMEM;
1237
1238 error = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0);
1239 if (error)
1240 goto out;
1241
1242 for (x = 0; x < nptrs; x++) {
1243 error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0,
1244 bh + x);
1245 if (error) {
1246 while (x--)
1247 brelse(bh[x]);
1248 goto fail;
1249 }
1250 dataptrs++;
1251 }
1252
1253 for (x = 0; x < nptrs; x++) {
1254 error = gfs2_meta_wait(sdp, bh[x]);
1255 if (error) {
1256 for (; x < nptrs; x++)
1257 brelse(bh[x]);
1258 goto fail;
1259 }
1260 if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) {
1261 for (; x < nptrs; x++)
1262 brelse(bh[x]);
1263 error = -EIO;
1264 goto fail;
1265 }
1266
1267 gfs2_trans_add_bh(ip->i_gl, bh[x], 1);
1268
1269 memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), data,
1270 (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize);
1271
1272 amount -= sdp->sd_jbsize;
1273 data += sdp->sd_jbsize;
1274
1275 brelse(bh[x]);
1276 }
1277 1243
1278out: 1244 ret = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0);
1279 kfree(bh); 1245 if (ret)
1280 return error; 1246 return ret;
1281 1247
1282fail: 1248 ret = gfs2_iter_unstuffed(ip, ea, data, NULL);
1283 gfs2_trans_end(sdp); 1249 gfs2_trans_end(sdp);
1284 kfree(bh); 1250
1285 return error; 1251 return ret;
1286} 1252}
1287 1253
1288int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) 1254int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data)
diff --git a/fs/libfs.c b/fs/libfs.c
index a74cb1725ac6..7cc37ca19cd8 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -874,7 +874,7 @@ struct dentry *generic_fh_to_dentry(struct super_block *sb, struct fid *fid,
874EXPORT_SYMBOL_GPL(generic_fh_to_dentry); 874EXPORT_SYMBOL_GPL(generic_fh_to_dentry);
875 875
876/** 876/**
877 * generic_fh_to_dentry - generic helper for the fh_to_parent export operation 877 * generic_fh_to_parent - generic helper for the fh_to_parent export operation
878 * @sb: filesystem to do the file handle conversion on 878 * @sb: filesystem to do the file handle conversion on
879 * @fid: file handle to convert 879 * @fid: file handle to convert
880 * @fh_len: length of the file handle in bytes 880 * @fh_len: length of the file handle in bytes
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index fb1a2bedbe97..8d80c990dffd 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -289,7 +289,6 @@ static void nlmsvc_free_block(struct kref *kref)
289 dprintk("lockd: freeing block %p...\n", block); 289 dprintk("lockd: freeing block %p...\n", block);
290 290
291 /* Remove block from file's list of blocks */ 291 /* Remove block from file's list of blocks */
292 mutex_lock(&file->f_mutex);
293 list_del_init(&block->b_flist); 292 list_del_init(&block->b_flist);
294 mutex_unlock(&file->f_mutex); 293 mutex_unlock(&file->f_mutex);
295 294
@@ -303,7 +302,7 @@ static void nlmsvc_free_block(struct kref *kref)
303static void nlmsvc_release_block(struct nlm_block *block) 302static void nlmsvc_release_block(struct nlm_block *block)
304{ 303{
305 if (block != NULL) 304 if (block != NULL)
306 kref_put(&block->b_count, nlmsvc_free_block); 305 kref_put_mutex(&block->b_count, nlmsvc_free_block, &block->b_file->f_mutex);
307} 306}
308 307
309/* 308/*
diff --git a/fs/namespace.c b/fs/namespace.c
index 4d31f73e2561..7bdf7907413f 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1886,8 +1886,14 @@ static int do_add_mount(struct mount *newmnt, struct path *path, int mnt_flags)
1886 return err; 1886 return err;
1887 1887
1888 err = -EINVAL; 1888 err = -EINVAL;
1889 if (!(mnt_flags & MNT_SHRINKABLE) && !check_mnt(real_mount(path->mnt))) 1889 if (unlikely(!check_mnt(real_mount(path->mnt)))) {
1890 goto unlock; 1890 /* that's acceptable only for automounts done in private ns */
1891 if (!(mnt_flags & MNT_SHRINKABLE))
1892 goto unlock;
1893 /* ... and for those we'd better have mountpoint still alive */
1894 if (!real_mount(path->mnt)->mnt_ns)
1895 goto unlock;
1896 }
1891 1897
1892 /* Refuse the same filesystem on the same mount point */ 1898 /* Refuse the same filesystem on the same mount point */
1893 err = -EBUSY; 1899 err = -EBUSY;
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 75d6d0a3d32e..6a7fcab7ecb3 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -287,10 +287,12 @@ nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
287 struct inode *inode = file->f_path.dentry->d_inode; 287 struct inode *inode = file->f_path.dentry->d_inode;
288 288
289 ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 289 ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
290 if (ret != 0)
291 goto out;
290 mutex_lock(&inode->i_mutex); 292 mutex_lock(&inode->i_mutex);
291 ret = nfs_file_fsync_commit(file, start, end, datasync); 293 ret = nfs_file_fsync_commit(file, start, end, datasync);
292 mutex_unlock(&inode->i_mutex); 294 mutex_unlock(&inode->i_mutex);
293 295out:
294 return ret; 296 return ret;
295} 297}
296 298
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index c6e895f0fbf3..9b47610338f5 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -154,7 +154,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
154 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); 154 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
155 nfsi->attrtimeo_timestamp = jiffies; 155 nfsi->attrtimeo_timestamp = jiffies;
156 156
157 memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode))); 157 memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf));
158 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) 158 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
159 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE; 159 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
160 else 160 else
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index d6b3b5f2d779..69322096c325 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -643,7 +643,7 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
643 u64 cookie, struct page **pages, unsigned int count, int plus) 643 u64 cookie, struct page **pages, unsigned int count, int plus)
644{ 644{
645 struct inode *dir = dentry->d_inode; 645 struct inode *dir = dentry->d_inode;
646 __be32 *verf = NFS_COOKIEVERF(dir); 646 __be32 *verf = NFS_I(dir)->cookieverf;
647 struct nfs3_readdirargs arg = { 647 struct nfs3_readdirargs arg = {
648 .fh = NFS_FH(dir), 648 .fh = NFS_FH(dir),
649 .cookie = cookie, 649 .cookie = cookie,
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index acb65e7887f8..eb5eb8eef4d3 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -96,13 +96,15 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
96 struct inode *inode = file->f_path.dentry->d_inode; 96 struct inode *inode = file->f_path.dentry->d_inode;
97 97
98 ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 98 ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
99 if (ret != 0)
100 goto out;
99 mutex_lock(&inode->i_mutex); 101 mutex_lock(&inode->i_mutex);
100 ret = nfs_file_fsync_commit(file, start, end, datasync); 102 ret = nfs_file_fsync_commit(file, start, end, datasync);
101 if (!ret && !datasync) 103 if (!ret && !datasync)
102 /* application has asked for meta-data sync */ 104 /* application has asked for meta-data sync */
103 ret = pnfs_layoutcommit_inode(inode, true); 105 ret = pnfs_layoutcommit_inode(inode, true);
104 mutex_unlock(&inode->i_mutex); 106 mutex_unlock(&inode->i_mutex);
105 107out:
106 return ret; 108 return ret;
107} 109}
108 110
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 635274140b18..1e50326d00dd 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -3215,11 +3215,11 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3215 dentry->d_parent->d_name.name, 3215 dentry->d_parent->d_name.name,
3216 dentry->d_name.name, 3216 dentry->d_name.name,
3217 (unsigned long long)cookie); 3217 (unsigned long long)cookie);
3218 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); 3218 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
3219 res.pgbase = args.pgbase; 3219 res.pgbase = args.pgbase;
3220 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); 3220 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
3221 if (status >= 0) { 3221 if (status >= 0) {
3222 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); 3222 memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE);
3223 status += args.pgbase; 3223 status += args.pgbase;
3224 } 3224 }
3225 3225
@@ -3653,11 +3653,11 @@ static inline int nfs4_server_supports_acls(struct nfs_server *server)
3653 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); 3653 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3654} 3654}
3655 3655
3656/* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that 3656/* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
3657 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on 3657 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
3658 * the stack. 3658 * the stack.
3659 */ 3659 */
3660#define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) 3660#define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
3661 3661
3662static int buf_to_pages_noslab(const void *buf, size_t buflen, 3662static int buf_to_pages_noslab(const void *buf, size_t buflen,
3663 struct page **pages, unsigned int *pgbase) 3663 struct page **pages, unsigned int *pgbase)
@@ -3668,7 +3668,7 @@ static int buf_to_pages_noslab(const void *buf, size_t buflen,
3668 spages = pages; 3668 spages = pages;
3669 3669
3670 do { 3670 do {
3671 len = min_t(size_t, PAGE_CACHE_SIZE, buflen); 3671 len = min_t(size_t, PAGE_SIZE, buflen);
3672 newpage = alloc_page(GFP_KERNEL); 3672 newpage = alloc_page(GFP_KERNEL);
3673 3673
3674 if (newpage == NULL) 3674 if (newpage == NULL)
@@ -3739,7 +3739,7 @@ static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size
3739 struct nfs4_cached_acl *acl; 3739 struct nfs4_cached_acl *acl;
3740 size_t buflen = sizeof(*acl) + acl_len; 3740 size_t buflen = sizeof(*acl) + acl_len;
3741 3741
3742 if (pages && buflen <= PAGE_SIZE) { 3742 if (buflen <= PAGE_SIZE) {
3743 acl = kmalloc(buflen, GFP_KERNEL); 3743 acl = kmalloc(buflen, GFP_KERNEL);
3744 if (acl == NULL) 3744 if (acl == NULL)
3745 goto out; 3745 goto out;
@@ -3782,17 +3782,15 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
3782 .rpc_argp = &args, 3782 .rpc_argp = &args,
3783 .rpc_resp = &res, 3783 .rpc_resp = &res,
3784 }; 3784 };
3785 int ret = -ENOMEM, npages, i; 3785 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
3786 size_t acl_len = 0; 3786 int ret = -ENOMEM, i;
3787 3787
3788 npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT;
3789 /* As long as we're doing a round trip to the server anyway, 3788 /* As long as we're doing a round trip to the server anyway,
3790 * let's be prepared for a page of acl data. */ 3789 * let's be prepared for a page of acl data. */
3791 if (npages == 0) 3790 if (npages == 0)
3792 npages = 1; 3791 npages = 1;
3793 3792 if (npages > ARRAY_SIZE(pages))
3794 /* Add an extra page to handle the bitmap returned */ 3793 return -ERANGE;
3795 npages++;
3796 3794
3797 for (i = 0; i < npages; i++) { 3795 for (i = 0; i < npages; i++) {
3798 pages[i] = alloc_page(GFP_KERNEL); 3796 pages[i] = alloc_page(GFP_KERNEL);
@@ -3808,11 +3806,6 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
3808 args.acl_len = npages * PAGE_SIZE; 3806 args.acl_len = npages * PAGE_SIZE;
3809 args.acl_pgbase = 0; 3807 args.acl_pgbase = 0;
3810 3808
3811 /* Let decode_getfacl know not to fail if the ACL data is larger than
3812 * the page we send as a guess */
3813 if (buf == NULL)
3814 res.acl_flags |= NFS4_ACL_LEN_REQUEST;
3815
3816 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n", 3809 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
3817 __func__, buf, buflen, npages, args.acl_len); 3810 __func__, buf, buflen, npages, args.acl_len);
3818 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), 3811 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode),
@@ -3820,20 +3813,19 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
3820 if (ret) 3813 if (ret)
3821 goto out_free; 3814 goto out_free;
3822 3815
3823 acl_len = res.acl_len; 3816 /* Handle the case where the passed-in buffer is too short */
3824 if (acl_len > args.acl_len) 3817 if (res.acl_flags & NFS4_ACL_TRUNC) {
3825 nfs4_write_cached_acl(inode, NULL, 0, acl_len); 3818 /* Did the user only issue a request for the acl length? */
3826 else 3819 if (buf == NULL)
3827 nfs4_write_cached_acl(inode, pages, res.acl_data_offset, 3820 goto out_ok;
3828 acl_len);
3829 if (buf) {
3830 ret = -ERANGE; 3821 ret = -ERANGE;
3831 if (acl_len > buflen) 3822 goto out_free;
3832 goto out_free;
3833 _copy_from_pages(buf, pages, res.acl_data_offset,
3834 acl_len);
3835 } 3823 }
3836 ret = acl_len; 3824 nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len);
3825 if (buf)
3826 _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len);
3827out_ok:
3828 ret = res.acl_len;
3837out_free: 3829out_free:
3838 for (i = 0; i < npages; i++) 3830 for (i = 0; i < npages; i++)
3839 if (pages[i]) 3831 if (pages[i])
@@ -3891,10 +3883,13 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl
3891 .rpc_argp = &arg, 3883 .rpc_argp = &arg,
3892 .rpc_resp = &res, 3884 .rpc_resp = &res,
3893 }; 3885 };
3886 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
3894 int ret, i; 3887 int ret, i;
3895 3888
3896 if (!nfs4_server_supports_acls(server)) 3889 if (!nfs4_server_supports_acls(server))
3897 return -EOPNOTSUPP; 3890 return -EOPNOTSUPP;
3891 if (npages > ARRAY_SIZE(pages))
3892 return -ERANGE;
3898 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); 3893 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3899 if (i < 0) 3894 if (i < 0)
3900 return i; 3895 return i;
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 1bfbd67c556d..8dba6bd48557 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -5072,18 +5072,14 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5072 * are stored with the acl data to handle the problem of 5072 * are stored with the acl data to handle the problem of
5073 * variable length bitmaps.*/ 5073 * variable length bitmaps.*/
5074 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset; 5074 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5075
5076 /* We ignore &savep and don't do consistency checks on
5077 * the attr length. Let userspace figure it out.... */
5078 res->acl_len = attrlen; 5075 res->acl_len = attrlen;
5079 if (attrlen > (xdr->nwords << 2)) { 5076
5080 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) { 5077 /* Check for receive buffer overflow */
5081 /* getxattr interface called with a NULL buf */ 5078 if (res->acl_len > (xdr->nwords << 2) ||
5082 goto out; 5079 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5083 } 5080 res->acl_flags |= NFS4_ACL_TRUNC;
5084 dprintk("NFS: acl reply: attrlen %u > page_len %u\n", 5081 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5085 attrlen, xdr->nwords << 2); 5082 attrlen, xdr->nwords << 2);
5086 return -EINVAL;
5087 } 5083 }
5088 } else 5084 } else
5089 status = -EOPNOTSUPP; 5085 status = -EOPNOTSUPP;
@@ -6229,7 +6225,8 @@ static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6229 status = decode_open(xdr, res); 6225 status = decode_open(xdr, res);
6230 if (status) 6226 if (status)
6231 goto out; 6227 goto out;
6232 if (decode_getfh(xdr, &res->fh) != 0) 6228 status = decode_getfh(xdr, &res->fh);
6229 if (status)
6233 goto out; 6230 goto out;
6234 decode_getfattr(xdr, res->f_attr, res->server); 6231 decode_getfattr(xdr, res->f_attr, res->server);
6235out: 6232out:
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 239aff7338eb..d2c7f5db0847 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -1537,7 +1537,7 @@ static int nfs_parse_mount_options(char *raw,
1537 1537
1538 /* 1538 /*
1539 * verify that any proto=/mountproto= options match the address 1539 * verify that any proto=/mountproto= options match the address
1540 * familiies in the addr=/mountaddr= options. 1540 * families in the addr=/mountaddr= options.
1541 */ 1541 */
1542 if (protofamily != AF_UNSPEC && 1542 if (protofamily != AF_UNSPEC &&
1543 protofamily != mnt->nfs_server.address.ss_family) 1543 protofamily != mnt->nfs_server.address.ss_family)
@@ -1867,6 +1867,7 @@ static int nfs23_validate_mount_data(void *options,
1867 1867
1868 memcpy(sap, &data->addr, sizeof(data->addr)); 1868 memcpy(sap, &data->addr, sizeof(data->addr));
1869 args->nfs_server.addrlen = sizeof(data->addr); 1869 args->nfs_server.addrlen = sizeof(data->addr);
1870 args->nfs_server.port = ntohs(data->addr.sin_port);
1870 if (!nfs_verify_server_address(sap)) 1871 if (!nfs_verify_server_address(sap))
1871 goto out_no_address; 1872 goto out_no_address;
1872 1873
@@ -2564,6 +2565,7 @@ static int nfs4_validate_mount_data(void *options,
2564 return -EFAULT; 2565 return -EFAULT;
2565 if (!nfs_verify_server_address(sap)) 2566 if (!nfs_verify_server_address(sap))
2566 goto out_no_address; 2567 goto out_no_address;
2568 args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
2567 2569
2568 if (data->auth_flavourlen) { 2570 if (data->auth_flavourlen) {
2569 if (data->auth_flavourlen > 1) 2571 if (data->auth_flavourlen > 1)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index dfafeb2b05a0..eb7cc91b7258 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -462,9 +462,6 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
462 462
463 err = ERR_PTR(-ENOMEM); 463 err = ERR_PTR(-ENOMEM);
464 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); 464 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
465 if (h)
466 sysctl_head_finish(h);
467
468 if (!inode) 465 if (!inode)
469 goto out; 466 goto out;
470 467
@@ -473,6 +470,8 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
473 d_add(dentry, inode); 470 d_add(dentry, inode);
474 471
475out: 472out:
473 if (h)
474 sysctl_head_finish(h);
476 sysctl_head_finish(head); 475 sysctl_head_finish(head);
477 return err; 476 return err;
478} 477}
diff --git a/fs/stat.c b/fs/stat.c
index b6ff11825fc8..40780229a032 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -58,7 +58,7 @@ EXPORT_SYMBOL(vfs_getattr);
58int vfs_fstat(unsigned int fd, struct kstat *stat) 58int vfs_fstat(unsigned int fd, struct kstat *stat)
59{ 59{
60 int fput_needed; 60 int fput_needed;
61 struct file *f = fget_light(fd, &fput_needed); 61 struct file *f = fget_raw_light(fd, &fput_needed);
62 int error = -EBADF; 62 int error = -EBADF;
63 63
64 if (f) { 64 if (f) {
diff --git a/fs/udf/file.c b/fs/udf/file.c
index 7f3f7ba3df6e..d1c6093fd3d3 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -39,20 +39,24 @@
39#include "udf_i.h" 39#include "udf_i.h"
40#include "udf_sb.h" 40#include "udf_sb.h"
41 41
42static int udf_adinicb_readpage(struct file *file, struct page *page) 42static void __udf_adinicb_readpage(struct page *page)
43{ 43{
44 struct inode *inode = page->mapping->host; 44 struct inode *inode = page->mapping->host;
45 char *kaddr; 45 char *kaddr;
46 struct udf_inode_info *iinfo = UDF_I(inode); 46 struct udf_inode_info *iinfo = UDF_I(inode);
47 47
48 BUG_ON(!PageLocked(page));
49
50 kaddr = kmap(page); 48 kaddr = kmap(page);
51 memset(kaddr, 0, PAGE_CACHE_SIZE);
52 memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr, inode->i_size); 49 memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr, inode->i_size);
50 memset(kaddr + inode->i_size, 0, PAGE_CACHE_SIZE - inode->i_size);
53 flush_dcache_page(page); 51 flush_dcache_page(page);
54 SetPageUptodate(page); 52 SetPageUptodate(page);
55 kunmap(page); 53 kunmap(page);
54}
55
56static int udf_adinicb_readpage(struct file *file, struct page *page)
57{
58 BUG_ON(!PageLocked(page));
59 __udf_adinicb_readpage(page);
56 unlock_page(page); 60 unlock_page(page);
57 61
58 return 0; 62 return 0;
@@ -77,6 +81,25 @@ static int udf_adinicb_writepage(struct page *page,
77 return 0; 81 return 0;
78} 82}
79 83
84static int udf_adinicb_write_begin(struct file *file,
85 struct address_space *mapping, loff_t pos,
86 unsigned len, unsigned flags, struct page **pagep,
87 void **fsdata)
88{
89 struct page *page;
90
91 if (WARN_ON_ONCE(pos >= PAGE_CACHE_SIZE))
92 return -EIO;
93 page = grab_cache_page_write_begin(mapping, 0, flags);
94 if (!page)
95 return -ENOMEM;
96 *pagep = page;
97
98 if (!PageUptodate(page) && len != PAGE_CACHE_SIZE)
99 __udf_adinicb_readpage(page);
100 return 0;
101}
102
80static int udf_adinicb_write_end(struct file *file, 103static int udf_adinicb_write_end(struct file *file,
81 struct address_space *mapping, 104 struct address_space *mapping,
82 loff_t pos, unsigned len, unsigned copied, 105 loff_t pos, unsigned len, unsigned copied,
@@ -98,8 +121,8 @@ static int udf_adinicb_write_end(struct file *file,
98const struct address_space_operations udf_adinicb_aops = { 121const struct address_space_operations udf_adinicb_aops = {
99 .readpage = udf_adinicb_readpage, 122 .readpage = udf_adinicb_readpage,
100 .writepage = udf_adinicb_writepage, 123 .writepage = udf_adinicb_writepage,
101 .write_begin = simple_write_begin, 124 .write_begin = udf_adinicb_write_begin,
102 .write_end = udf_adinicb_write_end, 125 .write_end = udf_adinicb_write_end,
103}; 126};
104 127
105static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 128static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index d7a9dd735e1e..933b7930b863 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -96,6 +96,7 @@ xfs_buf_lru_add(
96 atomic_inc(&bp->b_hold); 96 atomic_inc(&bp->b_hold);
97 list_add_tail(&bp->b_lru, &btp->bt_lru); 97 list_add_tail(&bp->b_lru, &btp->bt_lru);
98 btp->bt_lru_nr++; 98 btp->bt_lru_nr++;
99 bp->b_lru_flags &= ~_XBF_LRU_DISPOSE;
99 } 100 }
100 spin_unlock(&btp->bt_lru_lock); 101 spin_unlock(&btp->bt_lru_lock);
101} 102}
@@ -154,7 +155,8 @@ xfs_buf_stale(
154 struct xfs_buftarg *btp = bp->b_target; 155 struct xfs_buftarg *btp = bp->b_target;
155 156
156 spin_lock(&btp->bt_lru_lock); 157 spin_lock(&btp->bt_lru_lock);
157 if (!list_empty(&bp->b_lru)) { 158 if (!list_empty(&bp->b_lru) &&
159 !(bp->b_lru_flags & _XBF_LRU_DISPOSE)) {
158 list_del_init(&bp->b_lru); 160 list_del_init(&bp->b_lru);
159 btp->bt_lru_nr--; 161 btp->bt_lru_nr--;
160 atomic_dec(&bp->b_hold); 162 atomic_dec(&bp->b_hold);
@@ -1501,6 +1503,7 @@ xfs_buftarg_shrink(
1501 */ 1503 */
1502 list_move(&bp->b_lru, &dispose); 1504 list_move(&bp->b_lru, &dispose);
1503 btp->bt_lru_nr--; 1505 btp->bt_lru_nr--;
1506 bp->b_lru_flags |= _XBF_LRU_DISPOSE;
1504 } 1507 }
1505 spin_unlock(&btp->bt_lru_lock); 1508 spin_unlock(&btp->bt_lru_lock);
1506 1509
diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h
index d03b73b9604e..7c0b6a0a1557 100644
--- a/fs/xfs/xfs_buf.h
+++ b/fs/xfs/xfs_buf.h
@@ -38,27 +38,28 @@ typedef enum {
38 XBRW_ZERO = 3, /* Zero target memory */ 38 XBRW_ZERO = 3, /* Zero target memory */
39} xfs_buf_rw_t; 39} xfs_buf_rw_t;
40 40
41#define XBF_READ (1 << 0) /* buffer intended for reading from device */ 41#define XBF_READ (1 << 0) /* buffer intended for reading from device */
42#define XBF_WRITE (1 << 1) /* buffer intended for writing to device */ 42#define XBF_WRITE (1 << 1) /* buffer intended for writing to device */
43#define XBF_READ_AHEAD (1 << 2) /* asynchronous read-ahead */ 43#define XBF_READ_AHEAD (1 << 2) /* asynchronous read-ahead */
44#define XBF_ASYNC (1 << 4) /* initiator will not wait for completion */ 44#define XBF_ASYNC (1 << 4) /* initiator will not wait for completion */
45#define XBF_DONE (1 << 5) /* all pages in the buffer uptodate */ 45#define XBF_DONE (1 << 5) /* all pages in the buffer uptodate */
46#define XBF_STALE (1 << 6) /* buffer has been staled, do not find it */ 46#define XBF_STALE (1 << 6) /* buffer has been staled, do not find it */
47 47
48/* I/O hints for the BIO layer */ 48/* I/O hints for the BIO layer */
49#define XBF_SYNCIO (1 << 10)/* treat this buffer as synchronous I/O */ 49#define XBF_SYNCIO (1 << 10)/* treat this buffer as synchronous I/O */
50#define XBF_FUA (1 << 11)/* force cache write through mode */ 50#define XBF_FUA (1 << 11)/* force cache write through mode */
51#define XBF_FLUSH (1 << 12)/* flush the disk cache before a write */ 51#define XBF_FLUSH (1 << 12)/* flush the disk cache before a write */
52 52
53/* flags used only as arguments to access routines */ 53/* flags used only as arguments to access routines */
54#define XBF_TRYLOCK (1 << 16)/* lock requested, but do not wait */ 54#define XBF_TRYLOCK (1 << 16)/* lock requested, but do not wait */
55#define XBF_UNMAPPED (1 << 17)/* do not map the buffer */ 55#define XBF_UNMAPPED (1 << 17)/* do not map the buffer */
56 56
57/* flags used only internally */ 57/* flags used only internally */
58#define _XBF_PAGES (1 << 20)/* backed by refcounted pages */ 58#define _XBF_PAGES (1 << 20)/* backed by refcounted pages */
59#define _XBF_KMEM (1 << 21)/* backed by heap memory */ 59#define _XBF_KMEM (1 << 21)/* backed by heap memory */
60#define _XBF_DELWRI_Q (1 << 22)/* buffer on a delwri queue */ 60#define _XBF_DELWRI_Q (1 << 22)/* buffer on a delwri queue */
61#define _XBF_COMPOUND (1 << 23)/* compound buffer */ 61#define _XBF_COMPOUND (1 << 23)/* compound buffer */
62#define _XBF_LRU_DISPOSE (1 << 24)/* buffer being discarded */
62 63
63typedef unsigned int xfs_buf_flags_t; 64typedef unsigned int xfs_buf_flags_t;
64 65
@@ -72,12 +73,13 @@ typedef unsigned int xfs_buf_flags_t;
72 { XBF_SYNCIO, "SYNCIO" }, \ 73 { XBF_SYNCIO, "SYNCIO" }, \
73 { XBF_FUA, "FUA" }, \ 74 { XBF_FUA, "FUA" }, \
74 { XBF_FLUSH, "FLUSH" }, \ 75 { XBF_FLUSH, "FLUSH" }, \
75 { XBF_TRYLOCK, "TRYLOCK" }, /* should never be set */\ 76 { XBF_TRYLOCK, "TRYLOCK" }, /* should never be set */\
76 { XBF_UNMAPPED, "UNMAPPED" }, /* ditto */\ 77 { XBF_UNMAPPED, "UNMAPPED" }, /* ditto */\
77 { _XBF_PAGES, "PAGES" }, \ 78 { _XBF_PAGES, "PAGES" }, \
78 { _XBF_KMEM, "KMEM" }, \ 79 { _XBF_KMEM, "KMEM" }, \
79 { _XBF_DELWRI_Q, "DELWRI_Q" }, \ 80 { _XBF_DELWRI_Q, "DELWRI_Q" }, \
80 { _XBF_COMPOUND, "COMPOUND" } 81 { _XBF_COMPOUND, "COMPOUND" }, \
82 { _XBF_LRU_DISPOSE, "LRU_DISPOSE" }
81 83
82typedef struct xfs_buftarg { 84typedef struct xfs_buftarg {
83 dev_t bt_dev; 85 dev_t bt_dev;
@@ -124,7 +126,12 @@ typedef struct xfs_buf {
124 xfs_buf_flags_t b_flags; /* status flags */ 126 xfs_buf_flags_t b_flags; /* status flags */
125 struct semaphore b_sema; /* semaphore for lockables */ 127 struct semaphore b_sema; /* semaphore for lockables */
126 128
129 /*
130 * concurrent access to b_lru and b_lru_flags are protected by
131 * bt_lru_lock and not by b_sema
132 */
127 struct list_head b_lru; /* lru list */ 133 struct list_head b_lru; /* lru list */
134 xfs_buf_flags_t b_lru_flags; /* internal lru status flags */
128 wait_queue_head_t b_waiters; /* unpin waiters */ 135 wait_queue_head_t b_waiters; /* unpin waiters */
129 struct list_head b_list; 136 struct list_head b_list;
130 struct xfs_perag *b_pag; /* contains rbtree root */ 137 struct xfs_perag *b_pag; /* contains rbtree root */
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index bdaf4cb9f4a2..19e2380fb867 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -919,6 +919,7 @@ xfs_fs_put_super(
919 struct xfs_mount *mp = XFS_M(sb); 919 struct xfs_mount *mp = XFS_M(sb);
920 920
921 xfs_filestream_unmount(mp); 921 xfs_filestream_unmount(mp);
922 cancel_delayed_work_sync(&mp->m_sync_work);
922 xfs_unmountfs(mp); 923 xfs_unmountfs(mp);
923 xfs_syncd_stop(mp); 924 xfs_syncd_stop(mp);
924 xfs_freesb(mp); 925 xfs_freesb(mp);
diff --git a/include/asm-generic/unistd.h b/include/asm-generic/unistd.h
index 991ef01cd77e..3748ec92dcbc 100644
--- a/include/asm-generic/unistd.h
+++ b/include/asm-generic/unistd.h
@@ -691,9 +691,11 @@ __SC_COMP(__NR_process_vm_readv, sys_process_vm_readv, \
691#define __NR_process_vm_writev 271 691#define __NR_process_vm_writev 271
692__SC_COMP(__NR_process_vm_writev, sys_process_vm_writev, \ 692__SC_COMP(__NR_process_vm_writev, sys_process_vm_writev, \
693 compat_sys_process_vm_writev) 693 compat_sys_process_vm_writev)
694#define __NR_kcmp 272
695__SYSCALL(__NR_kcmp, sys_kcmp)
694 696
695#undef __NR_syscalls 697#undef __NR_syscalls
696#define __NR_syscalls 272 698#define __NR_syscalls 273
697 699
698/* 700/*
699 * All syscalls below here should go away really, 701 * All syscalls below here should go away really,
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index bdf0152cbbe9..f4621184a9b4 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -107,8 +107,7 @@
107#define DRM_FORMAT_NV16 fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */ 107#define DRM_FORMAT_NV16 fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */
108#define DRM_FORMAT_NV61 fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */ 108#define DRM_FORMAT_NV61 fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */
109 109
110/* 2 non contiguous plane YCbCr */ 110/* special NV12 tiled format */
111#define DRM_FORMAT_NV12M fourcc_code('N', 'M', '1', '2') /* 2x2 subsampled Cr:Cb plane */
112#define DRM_FORMAT_NV12MT fourcc_code('T', 'M', '1', '2') /* 2x2 subsampled Cr:Cb plane 64x32 macroblocks */ 111#define DRM_FORMAT_NV12MT fourcc_code('T', 'M', '1', '2') /* 2x2 subsampled Cr:Cb plane 64x32 macroblocks */
113 112
114/* 113/*
@@ -131,7 +130,4 @@
131#define DRM_FORMAT_YUV444 fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */ 130#define DRM_FORMAT_YUV444 fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
132#define DRM_FORMAT_YVU444 fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */ 131#define DRM_FORMAT_YVU444 fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
133 132
134/* 3 non contiguous plane YCbCr */
135#define DRM_FORMAT_YUV420M fourcc_code('Y', 'M', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */
136
137#endif /* DRM_FOURCC_H */ 133#endif /* DRM_FOURCC_H */
diff --git a/include/linux/atmel-ssc.h b/include/linux/atmel-ssc.h
index 06023393fba9..4eb31752e2b7 100644
--- a/include/linux/atmel-ssc.h
+++ b/include/linux/atmel-ssc.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/platform_device.h> 4#include <linux/platform_device.h>
5#include <linux/list.h> 5#include <linux/list.h>
6#include <linux/io.h>
6 7
7struct ssc_device { 8struct ssc_device {
8 struct list_head list; 9 struct list_head list;
diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
index 2f4079175afb..934bc34d5f99 100644
--- a/include/linux/compiler-gcc4.h
+++ b/include/linux/compiler-gcc4.h
@@ -49,6 +49,13 @@
49#endif 49#endif
50#endif 50#endif
51 51
52#if __GNUC_MINOR__ >= 6
53/*
54 * Tell the optimizer that something else uses this function or variable.
55 */
56#define __visible __attribute__((externally_visible))
57#endif
58
52#if __GNUC_MINOR__ > 0 59#if __GNUC_MINOR__ > 0
53#define __compiletime_object_size(obj) __builtin_object_size(obj, 0) 60#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
54#endif 61#endif
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 923d093c9cea..f430e4162f41 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -278,6 +278,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
278# define __section(S) __attribute__ ((__section__(#S))) 278# define __section(S) __attribute__ ((__section__(#S)))
279#endif 279#endif
280 280
281#ifndef __visible
282#define __visible
283#endif
284
281/* Are two types/vars the same type (ignoring qualifiers)? */ 285/* Are two types/vars the same type (ignoring qualifiers)? */
282#ifndef __same_type 286#ifndef __same_type
283# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 287# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index caa34e50537e..59200795482e 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -206,6 +206,8 @@ struct dentry_operations {
206#define DCACHE_MANAGED_DENTRY \ 206#define DCACHE_MANAGED_DENTRY \
207 (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT) 207 (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT)
208 208
209#define DCACHE_DENTRY_KILLED 0x100000
210
209extern seqlock_t rename_lock; 211extern seqlock_t rename_lock;
210 212
211static inline int dname_external(struct dentry *dentry) 213static inline int dname_external(struct dentry *dentry)
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 42970de1b40c..7e1f37db7582 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -414,7 +414,7 @@ struct hid_field {
414 __u16 dpad; /* dpad input code */ 414 __u16 dpad; /* dpad input code */
415}; 415};
416 416
417#define HID_MAX_FIELDS 128 417#define HID_MAX_FIELDS 256
418 418
419struct hid_report { 419struct hid_report {
420 struct list_head list; 420 struct list_head list;
@@ -626,6 +626,7 @@ struct hid_usage_id {
626 * @report_fixup: called before report descriptor parsing (NULL means nop) 626 * @report_fixup: called before report descriptor parsing (NULL means nop)
627 * @input_mapping: invoked on input registering before mapping an usage 627 * @input_mapping: invoked on input registering before mapping an usage
628 * @input_mapped: invoked on input registering after mapping an usage 628 * @input_mapped: invoked on input registering after mapping an usage
629 * @input_configured: invoked just before the device is registered
629 * @feature_mapping: invoked on feature registering 630 * @feature_mapping: invoked on feature registering
630 * @suspend: invoked on suspend (NULL means nop) 631 * @suspend: invoked on suspend (NULL means nop)
631 * @resume: invoked on resume if device was not reset (NULL means nop) 632 * @resume: invoked on resume if device was not reset (NULL means nop)
@@ -670,6 +671,8 @@ struct hid_driver {
670 int (*input_mapped)(struct hid_device *hdev, 671 int (*input_mapped)(struct hid_device *hdev,
671 struct hid_input *hidinput, struct hid_field *field, 672 struct hid_input *hidinput, struct hid_field *field,
672 struct hid_usage *usage, unsigned long **bit, int *max); 673 struct hid_usage *usage, unsigned long **bit, int *max);
674 void (*input_configured)(struct hid_device *hdev,
675 struct hid_input *hidinput);
673 void (*feature_mapping)(struct hid_device *hdev, 676 void (*feature_mapping)(struct hid_device *hdev,
674 struct hid_field *field, 677 struct hid_field *field,
675 struct hid_usage *usage); 678 struct hid_usage *usage);
diff --git a/include/linux/i2c-pnx.h b/include/linux/i2c-pnx.h
index 1bc74afe7a35..49ed17fdf055 100644
--- a/include/linux/i2c-pnx.h
+++ b/include/linux/i2c-pnx.h
@@ -22,6 +22,7 @@ struct i2c_pnx_mif {
22 struct timer_list timer; /* Timeout */ 22 struct timer_list timer; /* Timeout */
23 u8 * buf; /* Data buffer */ 23 u8 * buf; /* Data buffer */
24 int len; /* Length of data buffer */ 24 int len; /* Length of data buffer */
25 int order; /* RX Bytes to order via TX */
25}; 26};
26 27
27struct i2c_pnx_algo_data { 28struct i2c_pnx_algo_data {
diff --git a/include/linux/input.h b/include/linux/input.h
index 725dcd0f63a4..ba4874302939 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -1169,6 +1169,18 @@ struct ff_effect {
1169#include <linux/mod_devicetable.h> 1169#include <linux/mod_devicetable.h>
1170 1170
1171/** 1171/**
1172 * struct input_value - input value representation
1173 * @type: type of value (EV_KEY, EV_ABS, etc)
1174 * @code: the value code
1175 * @value: the value
1176 */
1177struct input_value {
1178 __u16 type;
1179 __u16 code;
1180 __s32 value;
1181};
1182
1183/**
1172 * struct input_dev - represents an input device 1184 * struct input_dev - represents an input device
1173 * @name: name of the device 1185 * @name: name of the device
1174 * @phys: physical path to the device in the system hierarchy 1186 * @phys: physical path to the device in the system hierarchy
@@ -1203,11 +1215,7 @@ struct ff_effect {
1203 * software autorepeat 1215 * software autorepeat
1204 * @timer: timer for software autorepeat 1216 * @timer: timer for software autorepeat
1205 * @rep: current values for autorepeat parameters (delay, rate) 1217 * @rep: current values for autorepeat parameters (delay, rate)
1206 * @mt: pointer to array of struct input_mt_slot holding current values 1218 * @mt: pointer to multitouch state
1207 * of tracked contacts
1208 * @mtsize: number of MT slots the device uses
1209 * @slot: MT slot currently being transmitted
1210 * @trkid: stores MT tracking ID for the current contact
1211 * @absinfo: array of &struct input_absinfo elements holding information 1219 * @absinfo: array of &struct input_absinfo elements holding information
1212 * about absolute axes (current value, min, max, flat, fuzz, 1220 * about absolute axes (current value, min, max, flat, fuzz,
1213 * resolution) 1221 * resolution)
@@ -1244,7 +1252,6 @@ struct ff_effect {
1244 * last user closes the device 1252 * last user closes the device
1245 * @going_away: marks devices that are in a middle of unregistering and 1253 * @going_away: marks devices that are in a middle of unregistering and
1246 * causes input_open_device*() fail with -ENODEV. 1254 * causes input_open_device*() fail with -ENODEV.
1247 * @sync: set to %true when there were no new events since last EV_SYN
1248 * @dev: driver model's view of this device 1255 * @dev: driver model's view of this device
1249 * @h_list: list of input handles associated with the device. When 1256 * @h_list: list of input handles associated with the device. When
1250 * accessing the list dev->mutex must be held 1257 * accessing the list dev->mutex must be held
@@ -1287,10 +1294,7 @@ struct input_dev {
1287 1294
1288 int rep[REP_CNT]; 1295 int rep[REP_CNT];
1289 1296
1290 struct input_mt_slot *mt; 1297 struct input_mt *mt;
1291 int mtsize;
1292 int slot;
1293 int trkid;
1294 1298
1295 struct input_absinfo *absinfo; 1299 struct input_absinfo *absinfo;
1296 1300
@@ -1312,12 +1316,14 @@ struct input_dev {
1312 unsigned int users; 1316 unsigned int users;
1313 bool going_away; 1317 bool going_away;
1314 1318
1315 bool sync;
1316
1317 struct device dev; 1319 struct device dev;
1318 1320
1319 struct list_head h_list; 1321 struct list_head h_list;
1320 struct list_head node; 1322 struct list_head node;
1323
1324 unsigned int num_vals;
1325 unsigned int max_vals;
1326 struct input_value *vals;
1321}; 1327};
1322#define to_input_dev(d) container_of(d, struct input_dev, dev) 1328#define to_input_dev(d) container_of(d, struct input_dev, dev)
1323 1329
@@ -1378,6 +1384,9 @@ struct input_handle;
1378 * @event: event handler. This method is being called by input core with 1384 * @event: event handler. This method is being called by input core with
1379 * interrupts disabled and dev->event_lock spinlock held and so 1385 * interrupts disabled and dev->event_lock spinlock held and so
1380 * it may not sleep 1386 * it may not sleep
1387 * @events: event sequence handler. This method is being called by
1388 * input core with interrupts disabled and dev->event_lock
1389 * spinlock held and so it may not sleep
1381 * @filter: similar to @event; separates normal event handlers from 1390 * @filter: similar to @event; separates normal event handlers from
1382 * "filters". 1391 * "filters".
1383 * @match: called after comparing device's id with handler's id_table 1392 * @match: called after comparing device's id with handler's id_table
@@ -1414,6 +1423,8 @@ struct input_handler {
1414 void *private; 1423 void *private;
1415 1424
1416 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value); 1425 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1426 void (*events)(struct input_handle *handle,
1427 const struct input_value *vals, unsigned int count);
1417 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value); 1428 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1418 bool (*match)(struct input_handler *handler, struct input_dev *dev); 1429 bool (*match)(struct input_handler *handler, struct input_dev *dev);
1419 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id); 1430 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
diff --git a/include/linux/input/mt.h b/include/linux/input/mt.h
index f86737586e19..cc5cca774bab 100644
--- a/include/linux/input/mt.h
+++ b/include/linux/input/mt.h
@@ -15,12 +15,41 @@
15 15
16#define TRKID_MAX 0xffff 16#define TRKID_MAX 0xffff
17 17
18#define INPUT_MT_POINTER 0x0001 /* pointer device, e.g. trackpad */
19#define INPUT_MT_DIRECT 0x0002 /* direct device, e.g. touchscreen */
20#define INPUT_MT_DROP_UNUSED 0x0004 /* drop contacts not seen in frame */
21#define INPUT_MT_TRACK 0x0008 /* use in-kernel tracking */
22
18/** 23/**
19 * struct input_mt_slot - represents the state of an input MT slot 24 * struct input_mt_slot - represents the state of an input MT slot
20 * @abs: holds current values of ABS_MT axes for this slot 25 * @abs: holds current values of ABS_MT axes for this slot
26 * @frame: last frame at which input_mt_report_slot_state() was called
27 * @key: optional driver designation of this slot
21 */ 28 */
22struct input_mt_slot { 29struct input_mt_slot {
23 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1]; 30 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
31 unsigned int frame;
32 unsigned int key;
33};
34
35/**
36 * struct input_mt - state of tracked contacts
37 * @trkid: stores MT tracking ID for the next contact
38 * @num_slots: number of MT slots the device uses
39 * @slot: MT slot currently being transmitted
40 * @flags: input_mt operation flags
41 * @frame: increases every time input_mt_sync_frame() is called
42 * @red: reduced cost matrix for in-kernel tracking
43 * @slots: array of slots holding current values of tracked contacts
44 */
45struct input_mt {
46 int trkid;
47 int num_slots;
48 int slot;
49 unsigned int flags;
50 unsigned int frame;
51 int *red;
52 struct input_mt_slot slots[];
24}; 53};
25 54
26static inline void input_mt_set_value(struct input_mt_slot *slot, 55static inline void input_mt_set_value(struct input_mt_slot *slot,
@@ -35,12 +64,18 @@ static inline int input_mt_get_value(const struct input_mt_slot *slot,
35 return slot->abs[code - ABS_MT_FIRST]; 64 return slot->abs[code - ABS_MT_FIRST];
36} 65}
37 66
38int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots); 67static inline bool input_mt_is_active(const struct input_mt_slot *slot)
68{
69 return input_mt_get_value(slot, ABS_MT_TRACKING_ID) >= 0;
70}
71
72int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
73 unsigned int flags);
39void input_mt_destroy_slots(struct input_dev *dev); 74void input_mt_destroy_slots(struct input_dev *dev);
40 75
41static inline int input_mt_new_trkid(struct input_dev *dev) 76static inline int input_mt_new_trkid(struct input_mt *mt)
42{ 77{
43 return dev->trkid++ & TRKID_MAX; 78 return mt->trkid++ & TRKID_MAX;
44} 79}
45 80
46static inline void input_mt_slot(struct input_dev *dev, int slot) 81static inline void input_mt_slot(struct input_dev *dev, int slot)
@@ -64,4 +99,20 @@ void input_mt_report_slot_state(struct input_dev *dev,
64void input_mt_report_finger_count(struct input_dev *dev, int count); 99void input_mt_report_finger_count(struct input_dev *dev, int count);
65void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count); 100void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
66 101
102void input_mt_sync_frame(struct input_dev *dev);
103
104/**
105 * struct input_mt_pos - contact position
106 * @x: horizontal coordinate
107 * @y: vertical coordinate
108 */
109struct input_mt_pos {
110 s16 x, y;
111};
112
113int input_mt_assign_slots(struct input_dev *dev, int *slots,
114 const struct input_mt_pos *pos, int num_pos);
115
116int input_mt_get_slot_by_key(struct input_dev *dev, int key);
117
67#endif 118#endif
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index c5f856a040b9..5e4e6170f43a 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -430,6 +430,8 @@ enum
430 NR_SOFTIRQS 430 NR_SOFTIRQS
431}; 431};
432 432
433#define SOFTIRQ_STOP_IDLE_MASK (~(1 << RCU_SOFTIRQ))
434
433/* map softirq index to softirq name. update 'softirq_to_name' in 435/* map softirq index to softirq name. update 'softirq_to_name' in
434 * kernel/softirq.c when adding a new softirq. 436 * kernel/softirq.c when adding a new softirq.
435 */ 437 */
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 7e83370e6fd2..f3b99e1c1042 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -256,72 +256,78 @@ static inline void iommu_set_fault_handler(struct iommu_domain *domain,
256{ 256{
257} 257}
258 258
259int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group) 259static inline int iommu_attach_group(struct iommu_domain *domain,
260 struct iommu_group *group)
260{ 261{
261 return -ENODEV; 262 return -ENODEV;
262} 263}
263 264
264void iommu_detach_group(struct iommu_domain *domain, struct iommu_group *group) 265static inline void iommu_detach_group(struct iommu_domain *domain,
266 struct iommu_group *group)
265{ 267{
266} 268}
267 269
268struct iommu_group *iommu_group_alloc(void) 270static inline struct iommu_group *iommu_group_alloc(void)
269{ 271{
270 return ERR_PTR(-ENODEV); 272 return ERR_PTR(-ENODEV);
271} 273}
272 274
273void *iommu_group_get_iommudata(struct iommu_group *group) 275static inline void *iommu_group_get_iommudata(struct iommu_group *group)
274{ 276{
275 return NULL; 277 return NULL;
276} 278}
277 279
278void iommu_group_set_iommudata(struct iommu_group *group, void *iommu_data, 280static inline void iommu_group_set_iommudata(struct iommu_group *group,
279 void (*release)(void *iommu_data)) 281 void *iommu_data,
282 void (*release)(void *iommu_data))
280{ 283{
281} 284}
282 285
283int iommu_group_set_name(struct iommu_group *group, const char *name) 286static inline int iommu_group_set_name(struct iommu_group *group,
287 const char *name)
284{ 288{
285 return -ENODEV; 289 return -ENODEV;
286} 290}
287 291
288int iommu_group_add_device(struct iommu_group *group, struct device *dev) 292static inline int iommu_group_add_device(struct iommu_group *group,
293 struct device *dev)
289{ 294{
290 return -ENODEV; 295 return -ENODEV;
291} 296}
292 297
293void iommu_group_remove_device(struct device *dev) 298static inline void iommu_group_remove_device(struct device *dev)
294{ 299{
295} 300}
296 301
297int iommu_group_for_each_dev(struct iommu_group *group, void *data, 302static inline int iommu_group_for_each_dev(struct iommu_group *group,
298 int (*fn)(struct device *, void *)) 303 void *data,
304 int (*fn)(struct device *, void *))
299{ 305{
300 return -ENODEV; 306 return -ENODEV;
301} 307}
302 308
303struct iommu_group *iommu_group_get(struct device *dev) 309static inline struct iommu_group *iommu_group_get(struct device *dev)
304{ 310{
305 return NULL; 311 return NULL;
306} 312}
307 313
308void iommu_group_put(struct iommu_group *group) 314static inline void iommu_group_put(struct iommu_group *group)
309{ 315{
310} 316}
311 317
312int iommu_group_register_notifier(struct iommu_group *group, 318static inline int iommu_group_register_notifier(struct iommu_group *group,
313 struct notifier_block *nb) 319 struct notifier_block *nb)
314{ 320{
315 return -ENODEV; 321 return -ENODEV;
316} 322}
317 323
318int iommu_group_unregister_notifier(struct iommu_group *group, 324static inline int iommu_group_unregister_notifier(struct iommu_group *group,
319 struct notifier_block *nb) 325 struct notifier_block *nb)
320{ 326{
321 return 0; 327 return 0;
322} 328}
323 329
324int iommu_group_id(struct iommu_group *group) 330static inline int iommu_group_id(struct iommu_group *group)
325{ 331{
326 return -ENODEV; 332 return -ENODEV;
327} 333}
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index 9a323d12de1c..0ba014c55056 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -10,12 +10,10 @@
10 10
11struct irq_affinity_notify; 11struct irq_affinity_notify;
12struct proc_dir_entry; 12struct proc_dir_entry;
13struct timer_rand_state;
14struct module; 13struct module;
15/** 14/**
16 * struct irq_desc - interrupt descriptor 15 * struct irq_desc - interrupt descriptor
17 * @irq_data: per irq and chip data passed down to chip functions 16 * @irq_data: per irq and chip data passed down to chip functions
18 * @timer_rand_state: pointer to timer rand state struct
19 * @kstat_irqs: irq stats per cpu 17 * @kstat_irqs: irq stats per cpu
20 * @handle_irq: highlevel irq-events handler 18 * @handle_irq: highlevel irq-events handler
21 * @preflow_handler: handler called before the flow handler (currently used by sparc) 19 * @preflow_handler: handler called before the flow handler (currently used by sparc)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 594b419b7d20..2451f1f7a1d9 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -91,7 +91,7 @@
91{ \ 91{ \
92 typeof(x) __x = x; \ 92 typeof(x) __x = x; \
93 typeof(divisor) __d = divisor; \ 93 typeof(divisor) __d = divisor; \
94 (((typeof(x))-1) >= 0 || (__x) >= 0) ? \ 94 (((typeof(x))-1) > 0 || (__x) > 0) ? \
95 (((__x) + ((__d) / 2)) / (__d)) : \ 95 (((__x) + ((__d) / 2)) / (__d)) : \
96 (((__x) - ((__d) / 2)) / (__d)); \ 96 (((__x) - ((__d) / 2)) / (__d)); \
97} \ 97} \
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index fc615a97e2d3..1e57449395b1 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -224,7 +224,7 @@ static inline int kobject_uevent_env(struct kobject *kobj,
224 224
225static inline __printf(2, 3) 225static inline __printf(2, 3)
226int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) 226int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
227{ return 0; } 227{ return -ENOMEM; }
228 228
229static inline int kobject_action_type(const char *buf, size_t count, 229static inline int kobject_action_type(const char *buf, size_t count,
230 enum kobject_action *type) 230 enum kobject_action *type)
diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 22ccf9dee177..8d816646f766 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -14,6 +14,11 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
14 kthread_create_on_node(threadfn, data, -1, namefmt, ##arg) 14 kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)
15 15
16 16
17struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
18 void *data,
19 unsigned int cpu,
20 const char *namefmt);
21
17/** 22/**
18 * kthread_run - create and wake a thread. 23 * kthread_run - create and wake a thread.
19 * @threadfn: the function to run until signal_pending(current). 24 * @threadfn: the function to run until signal_pending(current).
@@ -34,9 +39,13 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
34 39
35void kthread_bind(struct task_struct *k, unsigned int cpu); 40void kthread_bind(struct task_struct *k, unsigned int cpu);
36int kthread_stop(struct task_struct *k); 41int kthread_stop(struct task_struct *k);
37int kthread_should_stop(void); 42bool kthread_should_stop(void);
43bool kthread_should_park(void);
38bool kthread_freezable_should_stop(bool *was_frozen); 44bool kthread_freezable_should_stop(bool *was_frozen);
39void *kthread_data(struct task_struct *k); 45void *kthread_data(struct task_struct *k);
46int kthread_park(struct task_struct *k);
47void kthread_unpark(struct task_struct *k);
48void kthread_parkme(void);
40 49
41int kthreadd(void *unused); 50int kthreadd(void *unused);
42extern struct task_struct *kthreadd_task; 51extern struct task_struct *kthreadd_task;
diff --git a/include/linux/mISDNhw.h b/include/linux/mISDNhw.h
index d0752eca9b44..9d96d5d4dfed 100644
--- a/include/linux/mISDNhw.h
+++ b/include/linux/mISDNhw.h
@@ -183,7 +183,7 @@ extern int mISDN_initbchannel(struct bchannel *, unsigned short,
183 unsigned short); 183 unsigned short);
184extern int mISDN_freedchannel(struct dchannel *); 184extern int mISDN_freedchannel(struct dchannel *);
185extern void mISDN_clear_bchannel(struct bchannel *); 185extern void mISDN_clear_bchannel(struct bchannel *);
186extern int mISDN_freebchannel(struct bchannel *); 186extern void mISDN_freebchannel(struct bchannel *);
187extern int mISDN_ctrl_bchannel(struct bchannel *, struct mISDN_ctrl_req *); 187extern int mISDN_ctrl_bchannel(struct bchannel *, struct mISDN_ctrl_req *);
188extern void queue_ch_frame(struct mISDNchannel *, u_int, 188extern void queue_ch_frame(struct mISDNchannel *, u_int,
189 int, struct sk_buff *); 189 int, struct sk_buff *);
diff --git a/include/linux/memory.h b/include/linux/memory.h
index 1ac7f6e405f9..ff9a9f8e0ed9 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -19,7 +19,7 @@
19#include <linux/compiler.h> 19#include <linux/compiler.h>
20#include <linux/mutex.h> 20#include <linux/mutex.h>
21 21
22#define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS) 22#define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS)
23 23
24struct memory_block { 24struct memory_block {
25 unsigned long start_section_nr; 25 unsigned long start_section_nr;
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index 3a8435a8058f..cebe97ee98b8 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -16,6 +16,8 @@
16 16
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18 18
19struct irq_domain;
20
19/* 21/*
20 * This struct describes the MFD part ("cell"). 22 * This struct describes the MFD part ("cell").
21 * After registration the copy of this structure will become the platform data 23 * After registration the copy of this structure will become the platform data
@@ -98,7 +100,7 @@ static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
98extern int mfd_add_devices(struct device *parent, int id, 100extern int mfd_add_devices(struct device *parent, int id,
99 struct mfd_cell *cells, int n_devs, 101 struct mfd_cell *cells, int n_devs,
100 struct resource *mem_base, 102 struct resource *mem_base,
101 int irq_base); 103 int irq_base, struct irq_domain *irq_domain);
102 104
103extern void mfd_remove_devices(struct device *parent); 105extern void mfd_remove_devices(struct device *parent);
104 106
diff --git a/include/linux/mfd/max77686.h b/include/linux/mfd/max77686.h
index 3d7ae4d7fd36..46c0f320ed76 100644
--- a/include/linux/mfd/max77686.h
+++ b/include/linux/mfd/max77686.h
@@ -74,6 +74,7 @@ enum max77686_regulators {
74struct max77686_regulator_data { 74struct max77686_regulator_data {
75 int id; 75 int id;
76 struct regulator_init_data *initdata; 76 struct regulator_init_data *initdata;
77 struct device_node *of_node;
77}; 78};
78 79
79enum max77686_opmode { 80enum max77686_opmode {
diff --git a/include/linux/mfd/max8998.h b/include/linux/mfd/max8998.h
index f4f0dfa4698a..6823548d0c0a 100644
--- a/include/linux/mfd/max8998.h
+++ b/include/linux/mfd/max8998.h
@@ -67,7 +67,7 @@ struct max8998_regulator_data {
67/** 67/**
68 * struct max8998_board - packages regulator init data 68 * struct max8998_board - packages regulator init data
69 * @regulators: array of defined regulators 69 * @regulators: array of defined regulators
70 * @num_regulators: number of regultors used 70 * @num_regulators: number of regulators used
71 * @irq_base: base IRQ number for max8998, required for IRQs 71 * @irq_base: base IRQ number for max8998, required for IRQs
72 * @ono: power onoff IRQ number for max8998 72 * @ono: power onoff IRQ number for max8998
73 * @buck_voltage_lock: Do NOT change the values of the following six 73 * @buck_voltage_lock: Do NOT change the values of the following six
diff --git a/include/linux/mfd/tps65217.h b/include/linux/mfd/tps65217.h
index 12c06870829a..7cd83d826ed8 100644
--- a/include/linux/mfd/tps65217.h
+++ b/include/linux/mfd/tps65217.h
@@ -22,6 +22,9 @@
22#include <linux/regulator/driver.h> 22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h> 23#include <linux/regulator/machine.h>
24 24
25/* TPS chip id list */
26#define TPS65217 0xF0
27
25/* I2C ID for TPS65217 part */ 28/* I2C ID for TPS65217 part */
26#define TPS65217_I2C_ID 0x24 29#define TPS65217_I2C_ID 0x24
27 30
@@ -248,13 +251,11 @@ struct tps_info {
248struct tps65217 { 251struct tps65217 {
249 struct device *dev; 252 struct device *dev;
250 struct tps65217_board *pdata; 253 struct tps65217_board *pdata;
254 unsigned int id;
251 struct regulator_desc desc[TPS65217_NUM_REGULATOR]; 255 struct regulator_desc desc[TPS65217_NUM_REGULATOR];
252 struct regulator_dev *rdev[TPS65217_NUM_REGULATOR]; 256 struct regulator_dev *rdev[TPS65217_NUM_REGULATOR];
253 struct tps_info *info[TPS65217_NUM_REGULATOR]; 257 struct tps_info *info[TPS65217_NUM_REGULATOR];
254 struct regmap *regmap; 258 struct regmap *regmap;
255
256 /* Client devices */
257 struct platform_device *regulator_pdev[TPS65217_NUM_REGULATOR];
258}; 259};
259 260
260static inline struct tps65217 *dev_to_tps65217(struct device *dev) 261static inline struct tps65217 *dev_to_tps65217(struct device *dev)
@@ -262,6 +263,11 @@ static inline struct tps65217 *dev_to_tps65217(struct device *dev)
262 return dev_get_drvdata(dev); 263 return dev_get_drvdata(dev);
263} 264}
264 265
266static inline int tps65217_chip_id(struct tps65217 *tps65217)
267{
268 return tps65217->id;
269}
270
265int tps65217_reg_read(struct tps65217 *tps, unsigned int reg, 271int tps65217_reg_read(struct tps65217 *tps, unsigned int reg,
266 unsigned int *val); 272 unsigned int *val);
267int tps65217_reg_write(struct tps65217 *tps, unsigned int reg, 273int tps65217_reg_write(struct tps65217 *tps, unsigned int reg,
diff --git a/include/linux/mfd/tps6586x.h b/include/linux/mfd/tps6586x.h
index f350fd0ba1df..94514710a03f 100644
--- a/include/linux/mfd/tps6586x.h
+++ b/include/linux/mfd/tps6586x.h
@@ -14,6 +14,7 @@
14#define TPS6586X_SLEW_RATE_MASK 0x07 14#define TPS6586X_SLEW_RATE_MASK 0x07
15 15
16enum { 16enum {
17 TPS6586X_ID_SYS,
17 TPS6586X_ID_SM_0, 18 TPS6586X_ID_SM_0,
18 TPS6586X_ID_SM_1, 19 TPS6586X_ID_SM_1,
19 TPS6586X_ID_SM_2, 20 TPS6586X_ID_SM_2,
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index 61f0905bdc48..de201203bc7c 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -1,3 +1,15 @@
1/*
2 * include/linux/micrel_phy.h
3 *
4 * Micrel PHY IDs
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
1#ifndef _MICREL_PHY_H 13#ifndef _MICREL_PHY_H
2#define _MICREL_PHY_H 14#define _MICREL_PHY_H
3 15
@@ -5,10 +17,11 @@
5 17
6#define PHY_ID_KSZ9021 0x00221610 18#define PHY_ID_KSZ9021 0x00221610
7#define PHY_ID_KS8737 0x00221720 19#define PHY_ID_KS8737 0x00221720
8#define PHY_ID_KS8041 0x00221510 20#define PHY_ID_KSZ8021 0x00221555
9#define PHY_ID_KS8051 0x00221550 21#define PHY_ID_KSZ8041 0x00221510
22#define PHY_ID_KSZ8051 0x00221550
10/* both for ks8001 Rev. A/B, and for ks8721 Rev 3. */ 23/* both for ks8001 Rev. A/B, and for ks8721 Rev 3. */
11#define PHY_ID_KS8001 0x0022161A 24#define PHY_ID_KSZ8001 0x0022161A
12 25
13/* struct phy_device dev_flags definitions */ 26/* struct phy_device dev_flags definitions */
14#define MICREL_PHY_50MHZ_CLK 0x00000001 27#define MICREL_PHY_50MHZ_CLK 0x00000001
diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
index bd6c9fcdf2dd..6e1b0f973a03 100644
--- a/include/linux/mlx4/device.h
+++ b/include/linux/mlx4/device.h
@@ -796,6 +796,19 @@ enum mlx4_net_trans_rule_id {
796 MLX4_NET_TRANS_RULE_NUM, /* should be last */ 796 MLX4_NET_TRANS_RULE_NUM, /* should be last */
797}; 797};
798 798
799extern const u16 __sw_id_hw[];
800
801static inline int map_hw_to_sw_id(u16 header_id)
802{
803
804 int i;
805 for (i = 0; i < MLX4_NET_TRANS_RULE_NUM; i++) {
806 if (header_id == __sw_id_hw[i])
807 return i;
808 }
809 return -EINVAL;
810}
811
799enum mlx4_net_trans_promisc_mode { 812enum mlx4_net_trans_promisc_mode {
800 MLX4_FS_PROMISC_NONE = 0, 813 MLX4_FS_PROMISC_NONE = 0,
801 MLX4_FS_PROMISC_UPLINK, 814 MLX4_FS_PROMISC_UPLINK,
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 1f8fc7f9bcd8..4b03f56e280e 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -265,11 +265,6 @@ static inline const struct nfs_rpc_ops *NFS_PROTO(const struct inode *inode)
265 return NFS_SERVER(inode)->nfs_client->rpc_ops; 265 return NFS_SERVER(inode)->nfs_client->rpc_ops;
266} 266}
267 267
268static inline __be32 *NFS_COOKIEVERF(const struct inode *inode)
269{
270 return NFS_I(inode)->cookieverf;
271}
272
273static inline unsigned NFS_MINATTRTIMEO(const struct inode *inode) 268static inline unsigned NFS_MINATTRTIMEO(const struct inode *inode)
274{ 269{
275 struct nfs_server *nfss = NFS_SERVER(inode); 270 struct nfs_server *nfss = NFS_SERVER(inode);
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index ac7c8ae254f2..be9cf3c7e79e 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -652,7 +652,7 @@ struct nfs_getaclargs {
652}; 652};
653 653
654/* getxattr ACL interface flags */ 654/* getxattr ACL interface flags */
655#define NFS4_ACL_LEN_REQUEST 0x0001 /* zero length getxattr buffer */ 655#define NFS4_ACL_TRUNC 0x0001 /* ACL was truncated */
656struct nfs_getaclres { 656struct nfs_getaclres {
657 size_t acl_len; 657 size_t acl_len;
658 size_t acl_data_offset; 658 size_t acl_data_offset;
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 9490a00529f4..c25cccaa555a 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -35,8 +35,10 @@ struct nvme_bar {
35 __u64 acq; /* Admin CQ Base Address */ 35 __u64 acq; /* Admin CQ Base Address */
36}; 36};
37 37
38#define NVME_CAP_MQES(cap) ((cap) & 0xffff)
38#define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff) 39#define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
39#define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf) 40#define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
41#define NVME_CAP_MPSMIN(cap) (((cap) >> 48) & 0xf)
40 42
41enum { 43enum {
42 NVME_CC_ENABLE = 1 << 0, 44 NVME_CC_ENABLE = 1 << 0,
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 28f9cee3fbc3..599afc4bb67e 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -304,6 +304,8 @@ struct perf_event_attr {
304 __u32 __reserved_2; 304 __u32 __reserved_2;
305}; 305};
306 306
307#define perf_flags(attr) (*(&(attr)->read_format + 1))
308
307/* 309/*
308 * Ioctls that can be done on a perf event fd: 310 * Ioctls that can be done on a perf event fd:
309 */ 311 */
@@ -969,7 +971,7 @@ struct perf_event {
969 struct hw_perf_event hw; 971 struct hw_perf_event hw;
970 972
971 struct perf_event_context *ctx; 973 struct perf_event_context *ctx;
972 struct file *filp; 974 atomic_long_t refcount;
973 975
974 /* 976 /*
975 * These accumulate total time (in nanoseconds) that children 977 * These accumulate total time (in nanoseconds) that children
@@ -1346,6 +1348,7 @@ extern int perf_swevent_get_recursion_context(void);
1346extern void perf_swevent_put_recursion_context(int rctx); 1348extern void perf_swevent_put_recursion_context(int rctx);
1347extern void perf_event_enable(struct perf_event *event); 1349extern void perf_event_enable(struct perf_event *event);
1348extern void perf_event_disable(struct perf_event *event); 1350extern void perf_event_disable(struct perf_event *event);
1351extern int __perf_event_disable(void *info);
1349extern void perf_event_task_tick(void); 1352extern void perf_event_task_tick(void);
1350#else 1353#else
1351static inline void 1354static inline void
@@ -1384,6 +1387,7 @@ static inline int perf_swevent_get_recursion_context(void) { return -1; }
1384static inline void perf_swevent_put_recursion_context(int rctx) { } 1387static inline void perf_swevent_put_recursion_context(int rctx) { }
1385static inline void perf_event_enable(struct perf_event *event) { } 1388static inline void perf_event_enable(struct perf_event *event) { }
1386static inline void perf_event_disable(struct perf_event *event) { } 1389static inline void perf_event_disable(struct perf_event *event) { }
1390static inline int __perf_event_disable(void *info) { return -1; }
1387static inline void perf_event_task_tick(void) { } 1391static inline void perf_event_task_tick(void) { }
1388#endif 1392#endif
1389 1393
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 115ead2b5155..7c968e4f929e 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -191,6 +191,21 @@ extern void rcu_idle_enter(void);
191extern void rcu_idle_exit(void); 191extern void rcu_idle_exit(void);
192extern void rcu_irq_enter(void); 192extern void rcu_irq_enter(void);
193extern void rcu_irq_exit(void); 193extern void rcu_irq_exit(void);
194
195#ifdef CONFIG_RCU_USER_QS
196extern void rcu_user_enter(void);
197extern void rcu_user_exit(void);
198extern void rcu_user_enter_after_irq(void);
199extern void rcu_user_exit_after_irq(void);
200extern void rcu_user_hooks_switch(struct task_struct *prev,
201 struct task_struct *next);
202#else
203static inline void rcu_user_enter(void) { }
204static inline void rcu_user_exit(void) { }
205static inline void rcu_user_enter_after_irq(void) { }
206static inline void rcu_user_exit_after_irq(void) { }
207#endif /* CONFIG_RCU_USER_QS */
208
194extern void exit_rcu(void); 209extern void exit_rcu(void);
195 210
196/** 211/**
@@ -210,14 +225,12 @@ extern void exit_rcu(void);
210 * to nest RCU_NONIDLE() wrappers, but the nesting level is currently 225 * to nest RCU_NONIDLE() wrappers, but the nesting level is currently
211 * quite limited. If deeper nesting is required, it will be necessary 226 * quite limited. If deeper nesting is required, it will be necessary
212 * to adjust DYNTICK_TASK_NESTING_VALUE accordingly. 227 * to adjust DYNTICK_TASK_NESTING_VALUE accordingly.
213 *
214 * This macro may be used from process-level code only.
215 */ 228 */
216#define RCU_NONIDLE(a) \ 229#define RCU_NONIDLE(a) \
217 do { \ 230 do { \
218 rcu_idle_exit(); \ 231 rcu_irq_enter(); \
219 do { a; } while (0); \ 232 do { a; } while (0); \
220 rcu_idle_enter(); \ 233 rcu_irq_exit(); \
221 } while (0) 234 } while (0)
222 235
223/* 236/*
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 7f7e00df3adf..e3bcc3f4dcb8 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -285,6 +285,7 @@ struct regmap_irq {
285 * @ack_base: Base ack address. If zero then the chip is clear on read. 285 * @ack_base: Base ack address. If zero then the chip is clear on read.
286 * @wake_base: Base address for wake enables. If zero unsupported. 286 * @wake_base: Base address for wake enables. If zero unsupported.
287 * @irq_reg_stride: Stride to use for chips where registers are not contiguous. 287 * @irq_reg_stride: Stride to use for chips where registers are not contiguous.
288 * @runtime_pm: Hold a runtime PM lock on the device when accessing it.
288 * 289 *
289 * @num_regs: Number of registers in each control bank. 290 * @num_regs: Number of registers in each control bank.
290 * @irqs: Descriptors for individual IRQs. Interrupt numbers are 291 * @irqs: Descriptors for individual IRQs. Interrupt numbers are
@@ -299,6 +300,8 @@ struct regmap_irq_chip {
299 unsigned int ack_base; 300 unsigned int ack_base;
300 unsigned int wake_base; 301 unsigned int wake_base;
301 unsigned int irq_reg_stride; 302 unsigned int irq_reg_stride;
303 unsigned int mask_invert;
304 bool runtime_pm;
302 305
303 int num_regs; 306 int num_regs;
304 307
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index da339fd8c755..c43cd3556b1f 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -177,6 +177,8 @@ int regulator_set_mode(struct regulator *regulator, unsigned int mode);
177unsigned int regulator_get_mode(struct regulator *regulator); 177unsigned int regulator_get_mode(struct regulator *regulator);
178int regulator_set_optimum_mode(struct regulator *regulator, int load_uA); 178int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
179 179
180int regulator_allow_bypass(struct regulator *regulator, bool allow);
181
180/* regulator notifier block */ 182/* regulator notifier block */
181int regulator_register_notifier(struct regulator *regulator, 183int regulator_register_notifier(struct regulator *regulator,
182 struct notifier_block *nb); 184 struct notifier_block *nb);
@@ -328,6 +330,12 @@ static inline int regulator_set_optimum_mode(struct regulator *regulator,
328 return REGULATOR_MODE_NORMAL; 330 return REGULATOR_MODE_NORMAL;
329} 331}
330 332
333static inline int regulator_allow_bypass(struct regulator *regulator,
334 bool allow)
335{
336 return 0;
337}
338
331static inline int regulator_register_notifier(struct regulator *regulator, 339static inline int regulator_register_notifier(struct regulator *regulator,
332 struct notifier_block *nb) 340 struct notifier_block *nb)
333{ 341{
@@ -352,4 +360,11 @@ static inline void regulator_set_drvdata(struct regulator *regulator,
352 360
353#endif 361#endif
354 362
363static inline int regulator_set_voltage_tol(struct regulator *regulator,
364 int new_uV, int tol_uV)
365{
366 return regulator_set_voltage(regulator,
367 new_uV - tol_uV, new_uV + tol_uV);
368}
369
355#endif 370#endif
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index bac4c871f3bd..7932a3bf21bd 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -32,6 +32,8 @@ enum regulator_status {
32 REGULATOR_STATUS_NORMAL, 32 REGULATOR_STATUS_NORMAL,
33 REGULATOR_STATUS_IDLE, 33 REGULATOR_STATUS_IDLE,
34 REGULATOR_STATUS_STANDBY, 34 REGULATOR_STATUS_STANDBY,
35 /* The regulator is enabled but not regulating */
36 REGULATOR_STATUS_BYPASS,
35 /* in case that any other status doesn't apply */ 37 /* in case that any other status doesn't apply */
36 REGULATOR_STATUS_UNDEFINED, 38 REGULATOR_STATUS_UNDEFINED,
37}; 39};
@@ -58,6 +60,7 @@ enum regulator_status {
58 * regulator_desc.n_voltages. Voltages may be reported in any order. 60 * regulator_desc.n_voltages. Voltages may be reported in any order.
59 * 61 *
60 * @set_current_limit: Configure a limit for a current-limited regulator. 62 * @set_current_limit: Configure a limit for a current-limited regulator.
63 * The driver should select the current closest to max_uA.
61 * @get_current_limit: Get the configured limit for a current-limited regulator. 64 * @get_current_limit: Get the configured limit for a current-limited regulator.
62 * 65 *
63 * @set_mode: Set the configured operating mode for the regulator. 66 * @set_mode: Set the configured operating mode for the regulator.
@@ -67,6 +70,9 @@ enum regulator_status {
67 * @get_optimum_mode: Get the most efficient operating mode for the regulator 70 * @get_optimum_mode: Get the most efficient operating mode for the regulator
68 * when running with the specified parameters. 71 * when running with the specified parameters.
69 * 72 *
73 * @set_bypass: Set the regulator in bypass mode.
74 * @get_bypass: Get the regulator bypass mode state.
75 *
70 * @enable_time: Time taken for the regulator voltage output voltage to 76 * @enable_time: Time taken for the regulator voltage output voltage to
71 * stabilise after being enabled, in microseconds. 77 * stabilise after being enabled, in microseconds.
72 * @set_ramp_delay: Set the ramp delay for the regulator. The driver should 78 * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
@@ -133,6 +139,10 @@ struct regulator_ops {
133 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, 139 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
134 int output_uV, int load_uA); 140 int output_uV, int load_uA);
135 141
142 /* control and report on bypass mode */
143 int (*set_bypass)(struct regulator_dev *dev, bool enable);
144 int (*get_bypass)(struct regulator_dev *dev, bool *enable);
145
136 /* the operations below are for configuration of regulator state when 146 /* the operations below are for configuration of regulator state when
137 * its parent PMIC enters a global STANDBY/HIBERNATE state */ 147 * its parent PMIC enters a global STANDBY/HIBERNATE state */
138 148
@@ -205,6 +215,8 @@ struct regulator_desc {
205 unsigned int vsel_mask; 215 unsigned int vsel_mask;
206 unsigned int enable_reg; 216 unsigned int enable_reg;
207 unsigned int enable_mask; 217 unsigned int enable_mask;
218 unsigned int bypass_reg;
219 unsigned int bypass_mask;
208 220
209 unsigned int enable_time; 221 unsigned int enable_time;
210}; 222};
@@ -221,7 +233,8 @@ struct regulator_desc {
221 * @driver_data: private regulator data 233 * @driver_data: private regulator data
222 * @of_node: OpenFirmware node to parse for device tree bindings (may be 234 * @of_node: OpenFirmware node to parse for device tree bindings (may be
223 * NULL). 235 * NULL).
224 * @regmap: regmap to use for core regmap helpers 236 * @regmap: regmap to use for core regmap helpers if dev_get_regulator() is
237 * insufficient.
225 * @ena_gpio: GPIO controlling regulator enable. 238 * @ena_gpio: GPIO controlling regulator enable.
226 * @ena_gpio_invert: Sense for GPIO enable control. 239 * @ena_gpio_invert: Sense for GPIO enable control.
227 * @ena_gpio_flags: Flags to use when calling gpio_request_one() 240 * @ena_gpio_flags: Flags to use when calling gpio_request_one()
@@ -253,6 +266,7 @@ struct regulator_dev {
253 int exclusive; 266 int exclusive;
254 u32 use_count; 267 u32 use_count;
255 u32 open_count; 268 u32 open_count;
269 u32 bypass_count;
256 270
257 /* lists we belong to */ 271 /* lists we belong to */
258 struct list_head list; /* list of all regulators */ 272 struct list_head list; /* list of all regulators */
@@ -310,6 +324,8 @@ int regulator_disable_regmap(struct regulator_dev *rdev);
310int regulator_set_voltage_time_sel(struct regulator_dev *rdev, 324int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
311 unsigned int old_selector, 325 unsigned int old_selector,
312 unsigned int new_selector); 326 unsigned int new_selector);
327int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
328int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
313 329
314void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 330void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
315 331
diff --git a/include/linux/regulator/fan53555.h b/include/linux/regulator/fan53555.h
new file mode 100644
index 000000000000..5c45c85d52ca
--- /dev/null
+++ b/include/linux/regulator/fan53555.h
@@ -0,0 +1,60 @@
1/*
2 * fan53555.h - Fairchild Regulator FAN53555 Driver
3 *
4 * Copyright (C) 2012 Marvell Technology Ltd.
5 * Yunfan Zhang <yfzhang@marvell.com>
6 *
7 * This package 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 * published by the Free Software Foundation.
10 *
11 */
12
13#ifndef __FAN53555_H__
14
15/* VSEL ID */
16enum {
17 FAN53555_VSEL_ID_0 = 0,
18 FAN53555_VSEL_ID_1,
19};
20
21/* Transition slew rate limiting from a low to high voltage.
22 * -----------------------
23 * Bin |Slew Rate(mV/uS)
24 * ------|----------------
25 * 000 | 64.00
26 * ------|----------------
27 * 001 | 32.00
28 * ------|----------------
29 * 010 | 16.00
30 * ------|----------------
31 * 011 | 8.00
32 * ------|----------------
33 * 100 | 4.00
34 * ------|----------------
35 * 101 | 2.00
36 * ------|----------------
37 * 110 | 1.00
38 * ------|----------------
39 * 111 | 0.50
40 * -----------------------
41 */
42enum {
43 FAN53555_SLEW_RATE_64MV = 0,
44 FAN53555_SLEW_RATE_32MV,
45 FAN53555_SLEW_RATE_16MV,
46 FAN53555_SLEW_RATE_8MV,
47 FAN53555_SLEW_RATE_4MV,
48 FAN53555_SLEW_RATE_2MV,
49 FAN53555_SLEW_RATE_1MV,
50 FAN53555_SLEW_RATE_0_5MV,
51};
52
53struct fan53555_platform_data {
54 struct regulator_init_data *regulator;
55 unsigned int slew_rate;
56 /* Sleep VSEL ID */
57 unsigned int sleep_vsel_id;
58};
59
60#endif /* __FAN53555_H__ */
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 40dd0a394cfa..36adbc82de6a 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -32,6 +32,7 @@ struct regulator;
32 * board/machine. 32 * board/machine.
33 * STATUS: Regulator can be enabled and disabled. 33 * STATUS: Regulator can be enabled and disabled.
34 * DRMS: Dynamic Regulator Mode Switching is enabled for this regulator. 34 * DRMS: Dynamic Regulator Mode Switching is enabled for this regulator.
35 * BYPASS: Regulator can be put into bypass mode
35 */ 36 */
36 37
37#define REGULATOR_CHANGE_VOLTAGE 0x1 38#define REGULATOR_CHANGE_VOLTAGE 0x1
@@ -39,6 +40,7 @@ struct regulator;
39#define REGULATOR_CHANGE_MODE 0x4 40#define REGULATOR_CHANGE_MODE 0x4
40#define REGULATOR_CHANGE_STATUS 0x8 41#define REGULATOR_CHANGE_STATUS 0x8
41#define REGULATOR_CHANGE_DRMS 0x10 42#define REGULATOR_CHANGE_DRMS 0x10
43#define REGULATOR_CHANGE_BYPASS 0x20
42 44
43/** 45/**
44 * struct regulator_state - regulator state during low power system states 46 * struct regulator_state - regulator state during low power system states
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 255661d48834..83035269e597 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -957,7 +957,6 @@ struct sched_domain {
957 unsigned int smt_gain; 957 unsigned int smt_gain;
958 int flags; /* See SD_* */ 958 int flags; /* See SD_* */
959 int level; 959 int level;
960 int idle_buddy; /* cpu assigned to select_idle_sibling() */
961 960
962 /* Runtime fields. */ 961 /* Runtime fields. */
963 unsigned long last_balance; /* init to jiffies. units in jiffies */ 962 unsigned long last_balance; /* init to jiffies. units in jiffies */
@@ -1889,6 +1888,14 @@ static inline void rcu_copy_process(struct task_struct *p)
1889 1888
1890#endif 1889#endif
1891 1890
1891static inline void rcu_switch(struct task_struct *prev,
1892 struct task_struct *next)
1893{
1894#ifdef CONFIG_RCU_USER_QS
1895 rcu_user_hooks_switch(prev, next);
1896#endif
1897}
1898
1892static inline void tsk_restore_flags(struct task_struct *task, 1899static inline void tsk_restore_flags(struct task_struct *task,
1893 unsigned long orig_flags, unsigned long flags) 1900 unsigned long orig_flags, unsigned long flags)
1894{ 1901{
diff --git a/include/linux/security.h b/include/linux/security.h
index 3dea6a9d568f..d143b8e01954 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -118,6 +118,7 @@ void reset_security_ops(void);
118extern unsigned long mmap_min_addr; 118extern unsigned long mmap_min_addr;
119extern unsigned long dac_mmap_min_addr; 119extern unsigned long dac_mmap_min_addr;
120#else 120#else
121#define mmap_min_addr 0UL
121#define dac_mmap_min_addr 0UL 122#define dac_mmap_min_addr 0UL
122#endif 123#endif
123 124
diff --git a/include/linux/smpboot.h b/include/linux/smpboot.h
new file mode 100644
index 000000000000..e0106d8581d3
--- /dev/null
+++ b/include/linux/smpboot.h
@@ -0,0 +1,43 @@
1#ifndef _LINUX_SMPBOOT_H
2#define _LINUX_SMPBOOT_H
3
4#include <linux/types.h>
5
6struct task_struct;
7/* Cookie handed to the thread_fn*/
8struct smpboot_thread_data;
9
10/**
11 * struct smp_hotplug_thread - CPU hotplug related thread descriptor
12 * @store: Pointer to per cpu storage for the task pointers
13 * @list: List head for core management
14 * @thread_should_run: Check whether the thread should run or not. Called with
15 * preemption disabled.
16 * @thread_fn: The associated thread function
17 * @setup: Optional setup function, called when the thread gets
18 * operational the first time
19 * @cleanup: Optional cleanup function, called when the thread
20 * should stop (module exit)
21 * @park: Optional park function, called when the thread is
22 * parked (cpu offline)
23 * @unpark: Optional unpark function, called when the thread is
24 * unparked (cpu online)
25 * @thread_comm: The base name of the thread
26 */
27struct smp_hotplug_thread {
28 struct task_struct __percpu **store;
29 struct list_head list;
30 int (*thread_should_run)(unsigned int cpu);
31 void (*thread_fn)(unsigned int cpu);
32 void (*setup)(unsigned int cpu);
33 void (*cleanup)(unsigned int cpu, bool online);
34 void (*park)(unsigned int cpu);
35 void (*unpark)(unsigned int cpu);
36 const char *thread_comm;
37};
38
39int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread);
40void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread);
41int smpboot_thread_schedule(void);
42
43#endif
diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index cff40aa7db62..bf8c49ff7530 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -114,6 +114,7 @@ struct rpc_xprt_ops {
114 void (*set_buffer_size)(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize); 114 void (*set_buffer_size)(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize);
115 int (*reserve_xprt)(struct rpc_xprt *xprt, struct rpc_task *task); 115 int (*reserve_xprt)(struct rpc_xprt *xprt, struct rpc_task *task);
116 void (*release_xprt)(struct rpc_xprt *xprt, struct rpc_task *task); 116 void (*release_xprt)(struct rpc_xprt *xprt, struct rpc_task *task);
117 void (*alloc_slot)(struct rpc_xprt *xprt, struct rpc_task *task);
117 void (*rpcbind)(struct rpc_task *task); 118 void (*rpcbind)(struct rpc_task *task);
118 void (*set_port)(struct rpc_xprt *xprt, unsigned short port); 119 void (*set_port)(struct rpc_xprt *xprt, unsigned short port);
119 void (*connect)(struct rpc_task *task); 120 void (*connect)(struct rpc_task *task);
@@ -281,6 +282,8 @@ void xprt_connect(struct rpc_task *task);
281void xprt_reserve(struct rpc_task *task); 282void xprt_reserve(struct rpc_task *task);
282int xprt_reserve_xprt(struct rpc_xprt *xprt, struct rpc_task *task); 283int xprt_reserve_xprt(struct rpc_xprt *xprt, struct rpc_task *task);
283int xprt_reserve_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task); 284int xprt_reserve_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task);
285void xprt_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task);
286void xprt_lock_and_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task);
284int xprt_prepare_transmit(struct rpc_task *task); 287int xprt_prepare_transmit(struct rpc_task *task);
285void xprt_transmit(struct rpc_task *task); 288void xprt_transmit(struct rpc_task *task);
286void xprt_end_transmit(struct rpc_task *task); 289void xprt_end_transmit(struct rpc_task *task);
diff --git a/include/linux/task_work.h b/include/linux/task_work.h
index fb46b03b1852..ca5a1cf27dae 100644
--- a/include/linux/task_work.h
+++ b/include/linux/task_work.h
@@ -18,8 +18,7 @@ void task_work_run(void);
18 18
19static inline void exit_task_work(struct task_struct *task) 19static inline void exit_task_work(struct task_struct *task)
20{ 20{
21 if (unlikely(task->task_works)) 21 task_work_run();
22 task_work_run();
23} 22}
24 23
25#endif /* _LINUX_TASK_WORK_H */ 24#endif /* _LINUX_TASK_WORK_H */
diff --git a/include/linux/xfrm.h b/include/linux/xfrm.h
index 22e61fdf75a2..28e493b5b94c 100644
--- a/include/linux/xfrm.h
+++ b/include/linux/xfrm.h
@@ -84,6 +84,8 @@ struct xfrm_replay_state {
84 __u32 bitmap; 84 __u32 bitmap;
85}; 85};
86 86
87#define XFRMA_REPLAY_ESN_MAX 4096
88
87struct xfrm_replay_state_esn { 89struct xfrm_replay_state_esn {
88 unsigned int bmp_len; 90 unsigned int bmp_len;
89 __u32 oseq; 91 __u32 oseq;
diff --git a/include/net/bluetooth/smp.h b/include/net/bluetooth/smp.h
index ca356a734920..8b27927b2a55 100644
--- a/include/net/bluetooth/smp.h
+++ b/include/net/bluetooth/smp.h
@@ -136,7 +136,7 @@ struct smp_chan {
136}; 136};
137 137
138/* SMP Commands */ 138/* SMP Commands */
139int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level); 139int smp_conn_security(struct hci_conn *hcon, __u8 sec_level);
140int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb); 140int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb);
141int smp_distribute_keys(struct l2cap_conn *conn, __u8 force); 141int smp_distribute_keys(struct l2cap_conn *conn, __u8 force);
142int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey); 142int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey);
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index 0fedbd8d747a..9fc7114159e8 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -111,9 +111,8 @@ struct rt6_info {
111 struct inet6_dev *rt6i_idev; 111 struct inet6_dev *rt6i_idev;
112 unsigned long _rt6i_peer; 112 unsigned long _rt6i_peer;
113 113
114#ifdef CONFIG_XFRM 114 u32 rt6i_genid;
115 u32 rt6i_flow_cache_genid; 115
116#endif
117 /* more non-fragment space at head required */ 116 /* more non-fragment space at head required */
118 unsigned short rt6i_nfheader_len; 117 unsigned short rt6i_nfheader_len;
119 118
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index ae1cd6c9ba52..fd87963a0ea5 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -102,6 +102,7 @@ struct net {
102#endif 102#endif
103 struct netns_ipvs *ipvs; 103 struct netns_ipvs *ipvs;
104 struct sock *diag_nlsk; 104 struct sock *diag_nlsk;
105 atomic_t rt_genid;
105}; 106};
106 107
107 108
@@ -300,5 +301,14 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
300} 301}
301#endif 302#endif
302 303
304static inline int rt_genid(struct net *net)
305{
306 return atomic_read(&net->rt_genid);
307}
308
309static inline void rt_genid_bump(struct net *net)
310{
311 atomic_inc(&net->rt_genid);
312}
303 313
304#endif /* __NET_NET_NAMESPACE_H */ 314#endif /* __NET_NET_NAMESPACE_H */
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 1474dd65c66f..eb24dbccd81e 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -65,7 +65,6 @@ struct netns_ipv4 {
65 unsigned int sysctl_ping_group_range[2]; 65 unsigned int sysctl_ping_group_range[2];
66 long sysctl_tcp_mem[3]; 66 long sysctl_tcp_mem[3];
67 67
68 atomic_t rt_genid;
69 atomic_t dev_addr_genid; 68 atomic_t dev_addr_genid;
70 69
71#ifdef CONFIG_IP_MROUTE 70#ifdef CONFIG_IP_MROUTE
diff --git a/include/net/route.h b/include/net/route.h
index 776a27f1ab78..da22243d2760 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -108,7 +108,7 @@ extern struct ip_rt_acct __percpu *ip_rt_acct;
108 108
109struct in_device; 109struct in_device;
110extern int ip_rt_init(void); 110extern int ip_rt_init(void);
111extern void rt_cache_flush(struct net *net, int how); 111extern void rt_cache_flush(struct net *net);
112extern void rt_flush_dev(struct net_device *dev); 112extern void rt_flush_dev(struct net_device *dev);
113extern struct rtable *__ip_route_output_key(struct net *, struct flowi4 *flp); 113extern struct rtable *__ip_route_output_key(struct net *, struct flowi4 *flp);
114extern struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp, 114extern struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
diff --git a/include/net/sock.h b/include/net/sock.h
index 72132aef53fc..adb7da20b5a1 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1332,7 +1332,7 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size)
1332} 1332}
1333 1333
1334static inline bool 1334static inline bool
1335sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, unsigned int size) 1335sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size)
1336{ 1336{
1337 if (!sk_has_account(sk)) 1337 if (!sk_has_account(sk))
1338 return true; 1338 return true;
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 976a81abe1a2..639dd1316d37 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -273,6 +273,9 @@ struct xfrm_replay {
273 int (*check)(struct xfrm_state *x, 273 int (*check)(struct xfrm_state *x,
274 struct sk_buff *skb, 274 struct sk_buff *skb,
275 __be32 net_seq); 275 __be32 net_seq);
276 int (*recheck)(struct xfrm_state *x,
277 struct sk_buff *skb,
278 __be32 net_seq);
276 void (*notify)(struct xfrm_state *x, int event); 279 void (*notify)(struct xfrm_state *x, int event);
277 int (*overflow)(struct xfrm_state *x, struct sk_buff *skb); 280 int (*overflow)(struct xfrm_state *x, struct sk_buff *skb);
278}; 281};
diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
index f1405d335a96..941c84bf1065 100644
--- a/include/target/target_core_backend.h
+++ b/include/target/target_core_backend.h
@@ -23,7 +23,9 @@ struct se_subsystem_api {
23 struct se_device *(*create_virtdevice)(struct se_hba *, 23 struct se_device *(*create_virtdevice)(struct se_hba *,
24 struct se_subsystem_dev *, void *); 24 struct se_subsystem_dev *, void *);
25 void (*free_device)(void *); 25 void (*free_device)(void *);
26 int (*transport_complete)(struct se_cmd *cmd, struct scatterlist *); 26 void (*transport_complete)(struct se_cmd *cmd,
27 struct scatterlist *,
28 unsigned char *);
27 29
28 int (*parse_cdb)(struct se_cmd *cmd); 30 int (*parse_cdb)(struct se_cmd *cmd);
29 ssize_t (*check_configfs_dev_params)(struct se_hba *, 31 ssize_t (*check_configfs_dev_params)(struct se_hba *,
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 015cea01ae39..5be89373ceac 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -121,6 +121,7 @@
121 121
122#define SE_INQUIRY_BUF 512 122#define SE_INQUIRY_BUF 512
123#define SE_MODE_PAGE_BUF 512 123#define SE_MODE_PAGE_BUF 512
124#define SE_SENSE_BUF 96
124 125
125/* struct se_hba->hba_flags */ 126/* struct se_hba->hba_flags */
126enum hba_flags_table { 127enum hba_flags_table {
diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h
index b0b4eb24d592..1905ca8dd399 100644
--- a/include/trace/define_trace.h
+++ b/include/trace/define_trace.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Trace files that want to automate creationg of all tracepoints defined 2 * Trace files that want to automate creation of all tracepoints defined
3 * in their file should include this file. The following are macros that the 3 * in their file should include this file. The following are macros that the
4 * trace file may define: 4 * trace file may define:
5 * 5 *
diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h
index 5f889f16b0c8..08fa27244da7 100644
--- a/include/trace/events/kmem.h
+++ b/include/trace/events/kmem.h
@@ -214,7 +214,7 @@ TRACE_EVENT(mm_page_alloc,
214 214
215 TP_printk("page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s", 215 TP_printk("page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s",
216 __entry->page, 216 __entry->page,
217 page_to_pfn(__entry->page), 217 __entry->page ? page_to_pfn(__entry->page) : 0,
218 __entry->order, 218 __entry->order,
219 __entry->migratetype, 219 __entry->migratetype,
220 show_gfp_flags(__entry->gfp_flags)) 220 show_gfp_flags(__entry->gfp_flags))
@@ -240,7 +240,7 @@ DECLARE_EVENT_CLASS(mm_page,
240 240
241 TP_printk("page=%p pfn=%lu order=%u migratetype=%d percpu_refill=%d", 241 TP_printk("page=%p pfn=%lu order=%u migratetype=%d percpu_refill=%d",
242 __entry->page, 242 __entry->page,
243 page_to_pfn(__entry->page), 243 __entry->page ? page_to_pfn(__entry->page) : 0,
244 __entry->order, 244 __entry->order,
245 __entry->migratetype, 245 __entry->migratetype,
246 __entry->order == 0) 246 __entry->order == 0)
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 11e27c3af3cb..f19fff8650e9 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -187,6 +187,7 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
187 struct gnttab_map_grant_ref *kmap_ops, 187 struct gnttab_map_grant_ref *kmap_ops,
188 struct page **pages, unsigned int count); 188 struct page **pages, unsigned int count);
189int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, 189int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
190 struct page **pages, unsigned int count, bool clear_pte); 190 struct gnttab_map_grant_ref *kunmap_ops,
191 struct page **pages, unsigned int count);
191 192
192#endif /* __ASM_GNTTAB_H__ */ 193#endif /* __ASM_GNTTAB_H__ */
diff --git a/init/Kconfig b/init/Kconfig
index af6c7f8ba019..c26b8a1d2b57 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -441,6 +441,24 @@ config PREEMPT_RCU
441 This option enables preemptible-RCU code that is common between 441 This option enables preemptible-RCU code that is common between
442 the TREE_PREEMPT_RCU and TINY_PREEMPT_RCU implementations. 442 the TREE_PREEMPT_RCU and TINY_PREEMPT_RCU implementations.
443 443
444config RCU_USER_QS
445 bool "Consider userspace as in RCU extended quiescent state"
446 depends on HAVE_RCU_USER_QS && SMP
447 help
448 This option sets hooks on kernel / userspace boundaries and
449 puts RCU in extended quiescent state when the CPU runs in
450 userspace. It means that when a CPU runs in userspace, it is
451 excluded from the global RCU state machine and thus doesn't
452 to keep the timer tick on for RCU.
453
454config RCU_USER_QS_FORCE
455 bool "Force userspace extended QS by default"
456 depends on RCU_USER_QS
457 help
458 Set the hooks in user/kernel boundaries by default in order to
459 test this feature that treats userspace as an extended quiescent
460 state until we have a real user like a full adaptive nohz option.
461
444config RCU_FANOUT 462config RCU_FANOUT
445 int "Tree-based hierarchical RCU fanout value" 463 int "Tree-based hierarchical RCU fanout value"
446 range 2 64 if 64BIT 464 range 2 64 if 64BIT
diff --git a/kernel/Kconfig.locks b/kernel/Kconfig.locks
index 2251882daf53..44511d100eaa 100644
--- a/kernel/Kconfig.locks
+++ b/kernel/Kconfig.locks
@@ -87,6 +87,9 @@ config ARCH_INLINE_WRITE_UNLOCK_IRQ
87config ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE 87config ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE
88 bool 88 bool
89 89
90config UNINLINE_SPIN_UNLOCK
91 bool
92
90# 93#
91# lock_* functions are inlined when: 94# lock_* functions are inlined when:
92# - DEBUG_SPINLOCK=n and GENERIC_LOCKBREAK=n and ARCH_INLINE_*LOCK=y 95# - DEBUG_SPINLOCK=n and GENERIC_LOCKBREAK=n and ARCH_INLINE_*LOCK=y
@@ -103,100 +106,120 @@ config ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE
103# - DEBUG_SPINLOCK=n and ARCH_INLINE_*LOCK=y 106# - DEBUG_SPINLOCK=n and ARCH_INLINE_*LOCK=y
104# 107#
105 108
109if !DEBUG_SPINLOCK
110
106config INLINE_SPIN_TRYLOCK 111config INLINE_SPIN_TRYLOCK
107 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_SPIN_TRYLOCK 112 def_bool y
113 depends on ARCH_INLINE_SPIN_TRYLOCK
108 114
109config INLINE_SPIN_TRYLOCK_BH 115config INLINE_SPIN_TRYLOCK_BH
110 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_SPIN_TRYLOCK_BH 116 def_bool y
117 depends on ARCH_INLINE_SPIN_TRYLOCK_BH
111 118
112config INLINE_SPIN_LOCK 119config INLINE_SPIN_LOCK
113 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && ARCH_INLINE_SPIN_LOCK 120 def_bool y
121 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_SPIN_LOCK
114 122
115config INLINE_SPIN_LOCK_BH 123config INLINE_SPIN_LOCK_BH
116 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 124 def_bool y
117 ARCH_INLINE_SPIN_LOCK_BH 125 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_SPIN_LOCK_BH
118 126
119config INLINE_SPIN_LOCK_IRQ 127config INLINE_SPIN_LOCK_IRQ
120 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 128 def_bool y
121 ARCH_INLINE_SPIN_LOCK_IRQ 129 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_SPIN_LOCK_IRQ
122 130
123config INLINE_SPIN_LOCK_IRQSAVE 131config INLINE_SPIN_LOCK_IRQSAVE
124 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 132 def_bool y
125 ARCH_INLINE_SPIN_LOCK_IRQSAVE 133 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_SPIN_LOCK_IRQSAVE
126
127config UNINLINE_SPIN_UNLOCK
128 bool
129 134
130config INLINE_SPIN_UNLOCK_BH 135config INLINE_SPIN_UNLOCK_BH
131 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_SPIN_UNLOCK_BH 136 def_bool y
137 depends on ARCH_INLINE_SPIN_UNLOCK_BH
132 138
133config INLINE_SPIN_UNLOCK_IRQ 139config INLINE_SPIN_UNLOCK_IRQ
134 def_bool !DEBUG_SPINLOCK && (!PREEMPT || ARCH_INLINE_SPIN_UNLOCK_BH) 140 def_bool y
141 depends on !PREEMPT || ARCH_INLINE_SPIN_UNLOCK_BH
135 142
136config INLINE_SPIN_UNLOCK_IRQRESTORE 143config INLINE_SPIN_UNLOCK_IRQRESTORE
137 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_SPIN_UNLOCK_IRQRESTORE 144 def_bool y
145 depends on ARCH_INLINE_SPIN_UNLOCK_IRQRESTORE
138 146
139 147
140config INLINE_READ_TRYLOCK 148config INLINE_READ_TRYLOCK
141 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_READ_TRYLOCK 149 def_bool y
150 depends on ARCH_INLINE_READ_TRYLOCK
142 151
143config INLINE_READ_LOCK 152config INLINE_READ_LOCK
144 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && ARCH_INLINE_READ_LOCK 153 def_bool y
154 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_READ_LOCK
145 155
146config INLINE_READ_LOCK_BH 156config INLINE_READ_LOCK_BH
147 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 157 def_bool y
148 ARCH_INLINE_READ_LOCK_BH 158 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_READ_LOCK_BH
149 159
150config INLINE_READ_LOCK_IRQ 160config INLINE_READ_LOCK_IRQ
151 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 161 def_bool y
152 ARCH_INLINE_READ_LOCK_IRQ 162 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_READ_LOCK_IRQ
153 163
154config INLINE_READ_LOCK_IRQSAVE 164config INLINE_READ_LOCK_IRQSAVE
155 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 165 def_bool y
156 ARCH_INLINE_READ_LOCK_IRQSAVE 166 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_READ_LOCK_IRQSAVE
157 167
158config INLINE_READ_UNLOCK 168config INLINE_READ_UNLOCK
159 def_bool !DEBUG_SPINLOCK && (!PREEMPT || ARCH_INLINE_READ_UNLOCK) 169 def_bool y
170 depends on !PREEMPT || ARCH_INLINE_READ_UNLOCK
160 171
161config INLINE_READ_UNLOCK_BH 172config INLINE_READ_UNLOCK_BH
162 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_READ_UNLOCK_BH 173 def_bool y
174 depends on ARCH_INLINE_READ_UNLOCK_BH
163 175
164config INLINE_READ_UNLOCK_IRQ 176config INLINE_READ_UNLOCK_IRQ
165 def_bool !DEBUG_SPINLOCK && (!PREEMPT || ARCH_INLINE_READ_UNLOCK_BH) 177 def_bool y
178 depends on !PREEMPT || ARCH_INLINE_READ_UNLOCK_BH
166 179
167config INLINE_READ_UNLOCK_IRQRESTORE 180config INLINE_READ_UNLOCK_IRQRESTORE
168 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_READ_UNLOCK_IRQRESTORE 181 def_bool y
182 depends on ARCH_INLINE_READ_UNLOCK_IRQRESTORE
169 183
170 184
171config INLINE_WRITE_TRYLOCK 185config INLINE_WRITE_TRYLOCK
172 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_WRITE_TRYLOCK 186 def_bool y
187 depends on ARCH_INLINE_WRITE_TRYLOCK
173 188
174config INLINE_WRITE_LOCK 189config INLINE_WRITE_LOCK
175 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && ARCH_INLINE_WRITE_LOCK 190 def_bool y
191 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_WRITE_LOCK
176 192
177config INLINE_WRITE_LOCK_BH 193config INLINE_WRITE_LOCK_BH
178 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 194 def_bool y
179 ARCH_INLINE_WRITE_LOCK_BH 195 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_WRITE_LOCK_BH
180 196
181config INLINE_WRITE_LOCK_IRQ 197config INLINE_WRITE_LOCK_IRQ
182 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 198 def_bool y
183 ARCH_INLINE_WRITE_LOCK_IRQ 199 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_WRITE_LOCK_IRQ
184 200
185config INLINE_WRITE_LOCK_IRQSAVE 201config INLINE_WRITE_LOCK_IRQSAVE
186 def_bool !DEBUG_SPINLOCK && !GENERIC_LOCKBREAK && \ 202 def_bool y
187 ARCH_INLINE_WRITE_LOCK_IRQSAVE 203 depends on !GENERIC_LOCKBREAK && ARCH_INLINE_WRITE_LOCK_IRQSAVE
188 204
189config INLINE_WRITE_UNLOCK 205config INLINE_WRITE_UNLOCK
190 def_bool !DEBUG_SPINLOCK && (!PREEMPT || ARCH_INLINE_WRITE_UNLOCK) 206 def_bool y
207 depends on !PREEMPT || ARCH_INLINE_WRITE_UNLOCK
191 208
192config INLINE_WRITE_UNLOCK_BH 209config INLINE_WRITE_UNLOCK_BH
193 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_WRITE_UNLOCK_BH 210 def_bool y
211 depends on ARCH_INLINE_WRITE_UNLOCK_BH
194 212
195config INLINE_WRITE_UNLOCK_IRQ 213config INLINE_WRITE_UNLOCK_IRQ
196 def_bool !DEBUG_SPINLOCK && (!PREEMPT || ARCH_INLINE_WRITE_UNLOCK_BH) 214 def_bool y
215 depends on !PREEMPT || ARCH_INLINE_WRITE_UNLOCK_BH
197 216
198config INLINE_WRITE_UNLOCK_IRQRESTORE 217config INLINE_WRITE_UNLOCK_IRQRESTORE
199 def_bool !DEBUG_SPINLOCK && ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE 218 def_bool y
219 depends on ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE
220
221endif
200 222
201config MUTEX_SPIN_ON_OWNER 223config MUTEX_SPIN_ON_OWNER
202 def_bool SMP && !DEBUG_MUTEXES 224 def_bool y
225 depends on SMP && !DEBUG_MUTEXES
diff --git a/kernel/Makefile b/kernel/Makefile
index 29d993be7dba..5404911eaee9 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o printk.o \
10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ 10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
11 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ 11 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
12 notifier.o ksysfs.o cred.o \ 12 notifier.o ksysfs.o cred.o \
13 async.o range.o groups.o lglock.o 13 async.o range.o groups.o lglock.o smpboot.o
14 14
15ifdef CONFIG_FUNCTION_TRACER 15ifdef CONFIG_FUNCTION_TRACER
16# Do not trace debug files and internal ftrace files 16# Do not trace debug files and internal ftrace files
@@ -46,7 +46,6 @@ obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o
46obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o 46obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o
47obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o 47obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
48obj-$(CONFIG_SMP) += smp.o 48obj-$(CONFIG_SMP) += smp.o
49obj-$(CONFIG_SMP) += smpboot.o
50ifneq ($(CONFIG_SMP),y) 49ifneq ($(CONFIG_SMP),y)
51obj-y += up.o 50obj-y += up.o
52endif 51endif
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 14d32588cccd..e615dfbcf794 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -280,12 +280,13 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
280 __func__, cpu); 280 __func__, cpu);
281 goto out_release; 281 goto out_release;
282 } 282 }
283 smpboot_park_threads(cpu);
283 284
284 err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu)); 285 err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu));
285 if (err) { 286 if (err) {
286 /* CPU didn't die: tell everyone. Can't complain. */ 287 /* CPU didn't die: tell everyone. Can't complain. */
288 smpboot_unpark_threads(cpu);
287 cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu); 289 cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu);
288
289 goto out_release; 290 goto out_release;
290 } 291 }
291 BUG_ON(cpu_online(cpu)); 292 BUG_ON(cpu_online(cpu));
@@ -354,6 +355,10 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
354 goto out; 355 goto out;
355 } 356 }
356 357
358 ret = smpboot_create_threads(cpu);
359 if (ret)
360 goto out;
361
357 ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls); 362 ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls);
358 if (ret) { 363 if (ret) {
359 nr_calls--; 364 nr_calls--;
@@ -368,6 +373,9 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
368 goto out_notify; 373 goto out_notify;
369 BUG_ON(!cpu_online(cpu)); 374 BUG_ON(!cpu_online(cpu));
370 375
376 /* Wake the per cpu threads */
377 smpboot_unpark_threads(cpu);
378
371 /* Now call notifier in preparation. */ 379 /* Now call notifier in preparation. */
372 cpu_notify(CPU_ONLINE | mod, hcpu); 380 cpu_notify(CPU_ONLINE | mod, hcpu);
373 381
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 2ba890450d15..7b9df353ba1b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1254,7 +1254,7 @@ retry:
1254/* 1254/*
1255 * Cross CPU call to disable a performance event 1255 * Cross CPU call to disable a performance event
1256 */ 1256 */
1257static int __perf_event_disable(void *info) 1257int __perf_event_disable(void *info)
1258{ 1258{
1259 struct perf_event *event = info; 1259 struct perf_event *event = info;
1260 struct perf_event_context *ctx = event->ctx; 1260 struct perf_event_context *ctx = event->ctx;
@@ -2936,12 +2936,12 @@ EXPORT_SYMBOL_GPL(perf_event_release_kernel);
2936/* 2936/*
2937 * Called when the last reference to the file is gone. 2937 * Called when the last reference to the file is gone.
2938 */ 2938 */
2939static int perf_release(struct inode *inode, struct file *file) 2939static void put_event(struct perf_event *event)
2940{ 2940{
2941 struct perf_event *event = file->private_data;
2942 struct task_struct *owner; 2941 struct task_struct *owner;
2943 2942
2944 file->private_data = NULL; 2943 if (!atomic_long_dec_and_test(&event->refcount))
2944 return;
2945 2945
2946 rcu_read_lock(); 2946 rcu_read_lock();
2947 owner = ACCESS_ONCE(event->owner); 2947 owner = ACCESS_ONCE(event->owner);
@@ -2976,7 +2976,13 @@ static int perf_release(struct inode *inode, struct file *file)
2976 put_task_struct(owner); 2976 put_task_struct(owner);
2977 } 2977 }
2978 2978
2979 return perf_event_release_kernel(event); 2979 perf_event_release_kernel(event);
2980}
2981
2982static int perf_release(struct inode *inode, struct file *file)
2983{
2984 put_event(file->private_data);
2985 return 0;
2980} 2986}
2981 2987
2982u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running) 2988u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
@@ -3228,7 +3234,7 @@ unlock:
3228 3234
3229static const struct file_operations perf_fops; 3235static const struct file_operations perf_fops;
3230 3236
3231static struct perf_event *perf_fget_light(int fd, int *fput_needed) 3237static struct file *perf_fget_light(int fd, int *fput_needed)
3232{ 3238{
3233 struct file *file; 3239 struct file *file;
3234 3240
@@ -3242,7 +3248,7 @@ static struct perf_event *perf_fget_light(int fd, int *fput_needed)
3242 return ERR_PTR(-EBADF); 3248 return ERR_PTR(-EBADF);
3243 } 3249 }
3244 3250
3245 return file->private_data; 3251 return file;
3246} 3252}
3247 3253
3248static int perf_event_set_output(struct perf_event *event, 3254static int perf_event_set_output(struct perf_event *event,
@@ -3274,19 +3280,21 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3274 3280
3275 case PERF_EVENT_IOC_SET_OUTPUT: 3281 case PERF_EVENT_IOC_SET_OUTPUT:
3276 { 3282 {
3283 struct file *output_file = NULL;
3277 struct perf_event *output_event = NULL; 3284 struct perf_event *output_event = NULL;
3278 int fput_needed = 0; 3285 int fput_needed = 0;
3279 int ret; 3286 int ret;
3280 3287
3281 if (arg != -1) { 3288 if (arg != -1) {
3282 output_event = perf_fget_light(arg, &fput_needed); 3289 output_file = perf_fget_light(arg, &fput_needed);
3283 if (IS_ERR(output_event)) 3290 if (IS_ERR(output_file))
3284 return PTR_ERR(output_event); 3291 return PTR_ERR(output_file);
3292 output_event = output_file->private_data;
3285 } 3293 }
3286 3294
3287 ret = perf_event_set_output(event, output_event); 3295 ret = perf_event_set_output(event, output_event);
3288 if (output_event) 3296 if (output_event)
3289 fput_light(output_event->filp, fput_needed); 3297 fput_light(output_file, fput_needed);
3290 3298
3291 return ret; 3299 return ret;
3292 } 3300 }
@@ -6142,6 +6150,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
6142 6150
6143 mutex_init(&event->mmap_mutex); 6151 mutex_init(&event->mmap_mutex);
6144 6152
6153 atomic_long_set(&event->refcount, 1);
6145 event->cpu = cpu; 6154 event->cpu = cpu;
6146 event->attr = *attr; 6155 event->attr = *attr;
6147 event->group_leader = group_leader; 6156 event->group_leader = group_leader;
@@ -6474,12 +6483,12 @@ SYSCALL_DEFINE5(perf_event_open,
6474 return event_fd; 6483 return event_fd;
6475 6484
6476 if (group_fd != -1) { 6485 if (group_fd != -1) {
6477 group_leader = perf_fget_light(group_fd, &fput_needed); 6486 group_file = perf_fget_light(group_fd, &fput_needed);
6478 if (IS_ERR(group_leader)) { 6487 if (IS_ERR(group_file)) {
6479 err = PTR_ERR(group_leader); 6488 err = PTR_ERR(group_file);
6480 goto err_fd; 6489 goto err_fd;
6481 } 6490 }
6482 group_file = group_leader->filp; 6491 group_leader = group_file->private_data;
6483 if (flags & PERF_FLAG_FD_OUTPUT) 6492 if (flags & PERF_FLAG_FD_OUTPUT)
6484 output_event = group_leader; 6493 output_event = group_leader;
6485 if (flags & PERF_FLAG_FD_NO_GROUP) 6494 if (flags & PERF_FLAG_FD_NO_GROUP)
@@ -6616,7 +6625,6 @@ SYSCALL_DEFINE5(perf_event_open,
6616 put_ctx(gctx); 6625 put_ctx(gctx);
6617 } 6626 }
6618 6627
6619 event->filp = event_file;
6620 WARN_ON_ONCE(ctx->parent_ctx); 6628 WARN_ON_ONCE(ctx->parent_ctx);
6621 mutex_lock(&ctx->mutex); 6629 mutex_lock(&ctx->mutex);
6622 6630
@@ -6710,7 +6718,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
6710 goto err_free; 6718 goto err_free;
6711 } 6719 }
6712 6720
6713 event->filp = NULL;
6714 WARN_ON_ONCE(ctx->parent_ctx); 6721 WARN_ON_ONCE(ctx->parent_ctx);
6715 mutex_lock(&ctx->mutex); 6722 mutex_lock(&ctx->mutex);
6716 perf_install_in_context(ctx, event, cpu); 6723 perf_install_in_context(ctx, event, cpu);
@@ -6792,7 +6799,7 @@ static void sync_child_event(struct perf_event *child_event,
6792 * Release the parent event, if this was the last 6799 * Release the parent event, if this was the last
6793 * reference to it. 6800 * reference to it.
6794 */ 6801 */
6795 fput(parent_event->filp); 6802 put_event(parent_event);
6796} 6803}
6797 6804
6798static void 6805static void
@@ -6868,9 +6875,8 @@ static void perf_event_exit_task_context(struct task_struct *child, int ctxn)
6868 * 6875 *
6869 * __perf_event_exit_task() 6876 * __perf_event_exit_task()
6870 * sync_child_event() 6877 * sync_child_event()
6871 * fput(parent_event->filp) 6878 * put_event()
6872 * perf_release() 6879 * mutex_lock(&ctx->mutex)
6873 * mutex_lock(&ctx->mutex)
6874 * 6880 *
6875 * But since its the parent context it won't be the same instance. 6881 * But since its the parent context it won't be the same instance.
6876 */ 6882 */
@@ -6938,7 +6944,7 @@ static void perf_free_event(struct perf_event *event,
6938 list_del_init(&event->child_list); 6944 list_del_init(&event->child_list);
6939 mutex_unlock(&parent->child_mutex); 6945 mutex_unlock(&parent->child_mutex);
6940 6946
6941 fput(parent->filp); 6947 put_event(parent);
6942 6948
6943 perf_group_detach(event); 6949 perf_group_detach(event);
6944 list_del_event(event, ctx); 6950 list_del_event(event, ctx);
@@ -7018,6 +7024,12 @@ inherit_event(struct perf_event *parent_event,
7018 NULL, NULL); 7024 NULL, NULL);
7019 if (IS_ERR(child_event)) 7025 if (IS_ERR(child_event))
7020 return child_event; 7026 return child_event;
7027
7028 if (!atomic_long_inc_not_zero(&parent_event->refcount)) {
7029 free_event(child_event);
7030 return NULL;
7031 }
7032
7021 get_ctx(child_ctx); 7033 get_ctx(child_ctx);
7022 7034
7023 /* 7035 /*
@@ -7059,14 +7071,6 @@ inherit_event(struct perf_event *parent_event,
7059 raw_spin_unlock_irqrestore(&child_ctx->lock, flags); 7071 raw_spin_unlock_irqrestore(&child_ctx->lock, flags);
7060 7072
7061 /* 7073 /*
7062 * Get a reference to the parent filp - we will fput it
7063 * when the child event exits. This is safe to do because
7064 * we are in the parent and we know that the filp still
7065 * exists and has a nonzero count:
7066 */
7067 atomic_long_inc(&parent_event->filp->f_count);
7068
7069 /*
7070 * Link this into the parent event's child list 7074 * Link this into the parent event's child list
7071 */ 7075 */
7072 WARN_ON_ONCE(parent_event->ctx->parent_ctx); 7076 WARN_ON_ONCE(parent_event->ctx->parent_ctx);
diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index bb38c4d3ee12..9a7b487c6fe2 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -453,7 +453,16 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
453 int old_type = bp->attr.bp_type; 453 int old_type = bp->attr.bp_type;
454 int err = 0; 454 int err = 0;
455 455
456 perf_event_disable(bp); 456 /*
457 * modify_user_hw_breakpoint can be invoked with IRQs disabled and hence it
458 * will not be possible to raise IPIs that invoke __perf_event_disable.
459 * So call the function directly after making sure we are targeting the
460 * current task.
461 */
462 if (irqs_disabled() && bp->ctx && bp->ctx->task == current)
463 __perf_event_disable(bp);
464 else
465 perf_event_disable(bp);
457 466
458 bp->attr.bp_addr = attr->bp_addr; 467 bp->attr.bp_addr = attr->bp_addr;
459 bp->attr.bp_type = attr->bp_type; 468 bp->attr.bp_type = attr->bp_type;
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index eebd6d5cfb44..57d86d07221e 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -671,6 +671,7 @@ irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
671 irq_set_chip(irq, chip); 671 irq_set_chip(irq, chip);
672 __irq_set_handler(irq, handle, 0, name); 672 __irq_set_handler(irq, handle, 0, name);
673} 673}
674EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);
674 675
675void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set) 676void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
676{ 677{
diff --git a/kernel/irq/dummychip.c b/kernel/irq/dummychip.c
index b5fcd96c7102..988dc58e8847 100644
--- a/kernel/irq/dummychip.c
+++ b/kernel/irq/dummychip.c
@@ -6,6 +6,7 @@
6 */ 6 */
7#include <linux/interrupt.h> 7#include <linux/interrupt.h>
8#include <linux/irq.h> 8#include <linux/irq.h>
9#include <linux/export.h>
9 10
10#include "internals.h" 11#include "internals.h"
11 12
@@ -57,3 +58,4 @@ struct irq_chip dummy_irq_chip = {
57 .irq_mask = noop, 58 .irq_mask = noop,
58 .irq_unmask = noop, 59 .irq_unmask = noop,
59}; 60};
61EXPORT_SYMBOL_GPL(dummy_irq_chip);
diff --git a/kernel/kthread.c b/kernel/kthread.c
index b579af57ea10..146a6fa96825 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -37,11 +37,20 @@ struct kthread_create_info
37}; 37};
38 38
39struct kthread { 39struct kthread {
40 int should_stop; 40 unsigned long flags;
41 unsigned int cpu;
41 void *data; 42 void *data;
43 struct completion parked;
42 struct completion exited; 44 struct completion exited;
43}; 45};
44 46
47enum KTHREAD_BITS {
48 KTHREAD_IS_PER_CPU = 0,
49 KTHREAD_SHOULD_STOP,
50 KTHREAD_SHOULD_PARK,
51 KTHREAD_IS_PARKED,
52};
53
45#define to_kthread(tsk) \ 54#define to_kthread(tsk) \
46 container_of((tsk)->vfork_done, struct kthread, exited) 55 container_of((tsk)->vfork_done, struct kthread, exited)
47 56
@@ -52,13 +61,29 @@ struct kthread {
52 * and this will return true. You should then return, and your return 61 * and this will return true. You should then return, and your return
53 * value will be passed through to kthread_stop(). 62 * value will be passed through to kthread_stop().
54 */ 63 */
55int kthread_should_stop(void) 64bool kthread_should_stop(void)
56{ 65{
57 return to_kthread(current)->should_stop; 66 return test_bit(KTHREAD_SHOULD_STOP, &to_kthread(current)->flags);
58} 67}
59EXPORT_SYMBOL(kthread_should_stop); 68EXPORT_SYMBOL(kthread_should_stop);
60 69
61/** 70/**
71 * kthread_should_park - should this kthread park now?
72 *
73 * When someone calls kthread_park() on your kthread, it will be woken
74 * and this will return true. You should then do the necessary
75 * cleanup and call kthread_parkme()
76 *
77 * Similar to kthread_should_stop(), but this keeps the thread alive
78 * and in a park position. kthread_unpark() "restarts" the thread and
79 * calls the thread function again.
80 */
81bool kthread_should_park(void)
82{
83 return test_bit(KTHREAD_SHOULD_PARK, &to_kthread(current)->flags);
84}
85
86/**
62 * kthread_freezable_should_stop - should this freezable kthread return now? 87 * kthread_freezable_should_stop - should this freezable kthread return now?
63 * @was_frozen: optional out parameter, indicates whether %current was frozen 88 * @was_frozen: optional out parameter, indicates whether %current was frozen
64 * 89 *
@@ -96,6 +121,24 @@ void *kthread_data(struct task_struct *task)
96 return to_kthread(task)->data; 121 return to_kthread(task)->data;
97} 122}
98 123
124static void __kthread_parkme(struct kthread *self)
125{
126 __set_current_state(TASK_INTERRUPTIBLE);
127 while (test_bit(KTHREAD_SHOULD_PARK, &self->flags)) {
128 if (!test_and_set_bit(KTHREAD_IS_PARKED, &self->flags))
129 complete(&self->parked);
130 schedule();
131 __set_current_state(TASK_INTERRUPTIBLE);
132 }
133 clear_bit(KTHREAD_IS_PARKED, &self->flags);
134 __set_current_state(TASK_RUNNING);
135}
136
137void kthread_parkme(void)
138{
139 __kthread_parkme(to_kthread(current));
140}
141
99static int kthread(void *_create) 142static int kthread(void *_create)
100{ 143{
101 /* Copy data: it's on kthread's stack */ 144 /* Copy data: it's on kthread's stack */
@@ -105,9 +148,10 @@ static int kthread(void *_create)
105 struct kthread self; 148 struct kthread self;
106 int ret; 149 int ret;
107 150
108 self.should_stop = 0; 151 self.flags = 0;
109 self.data = data; 152 self.data = data;
110 init_completion(&self.exited); 153 init_completion(&self.exited);
154 init_completion(&self.parked);
111 current->vfork_done = &self.exited; 155 current->vfork_done = &self.exited;
112 156
113 /* OK, tell user we're spawned, wait for stop or wakeup */ 157 /* OK, tell user we're spawned, wait for stop or wakeup */
@@ -117,9 +161,11 @@ static int kthread(void *_create)
117 schedule(); 161 schedule();
118 162
119 ret = -EINTR; 163 ret = -EINTR;
120 if (!self.should_stop)
121 ret = threadfn(data);
122 164
165 if (!test_bit(KTHREAD_SHOULD_STOP, &self.flags)) {
166 __kthread_parkme(&self);
167 ret = threadfn(data);
168 }
123 /* we can't just return, we must preserve "self" on stack */ 169 /* we can't just return, we must preserve "self" on stack */
124 do_exit(ret); 170 do_exit(ret);
125} 171}
@@ -172,8 +218,7 @@ static void create_kthread(struct kthread_create_info *create)
172 * Returns a task_struct or ERR_PTR(-ENOMEM). 218 * Returns a task_struct or ERR_PTR(-ENOMEM).
173 */ 219 */
174struct task_struct *kthread_create_on_node(int (*threadfn)(void *data), 220struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
175 void *data, 221 void *data, int node,
176 int node,
177 const char namefmt[], 222 const char namefmt[],
178 ...) 223 ...)
179{ 224{
@@ -210,6 +255,13 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
210} 255}
211EXPORT_SYMBOL(kthread_create_on_node); 256EXPORT_SYMBOL(kthread_create_on_node);
212 257
258static void __kthread_bind(struct task_struct *p, unsigned int cpu)
259{
260 /* It's safe because the task is inactive. */
261 do_set_cpus_allowed(p, cpumask_of(cpu));
262 p->flags |= PF_THREAD_BOUND;
263}
264
213/** 265/**
214 * kthread_bind - bind a just-created kthread to a cpu. 266 * kthread_bind - bind a just-created kthread to a cpu.
215 * @p: thread created by kthread_create(). 267 * @p: thread created by kthread_create().
@@ -226,14 +278,112 @@ void kthread_bind(struct task_struct *p, unsigned int cpu)
226 WARN_ON(1); 278 WARN_ON(1);
227 return; 279 return;
228 } 280 }
229 281 __kthread_bind(p, cpu);
230 /* It's safe because the task is inactive. */
231 do_set_cpus_allowed(p, cpumask_of(cpu));
232 p->flags |= PF_THREAD_BOUND;
233} 282}
234EXPORT_SYMBOL(kthread_bind); 283EXPORT_SYMBOL(kthread_bind);
235 284
236/** 285/**
286 * kthread_create_on_cpu - Create a cpu bound kthread
287 * @threadfn: the function to run until signal_pending(current).
288 * @data: data ptr for @threadfn.
289 * @cpu: The cpu on which the thread should be bound,
290 * @namefmt: printf-style name for the thread. Format is restricted
291 * to "name.*%u". Code fills in cpu number.
292 *
293 * Description: This helper function creates and names a kernel thread
294 * The thread will be woken and put into park mode.
295 */
296struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
297 void *data, unsigned int cpu,
298 const char *namefmt)
299{
300 struct task_struct *p;
301
302 p = kthread_create_on_node(threadfn, data, cpu_to_node(cpu), namefmt,
303 cpu);
304 if (IS_ERR(p))
305 return p;
306 set_bit(KTHREAD_IS_PER_CPU, &to_kthread(p)->flags);
307 to_kthread(p)->cpu = cpu;
308 /* Park the thread to get it out of TASK_UNINTERRUPTIBLE state */
309 kthread_park(p);
310 return p;
311}
312
313static struct kthread *task_get_live_kthread(struct task_struct *k)
314{
315 struct kthread *kthread;
316
317 get_task_struct(k);
318 kthread = to_kthread(k);
319 /* It might have exited */
320 barrier();
321 if (k->vfork_done != NULL)
322 return kthread;
323 return NULL;
324}
325
326/**
327 * kthread_unpark - unpark a thread created by kthread_create().
328 * @k: thread created by kthread_create().
329 *
330 * Sets kthread_should_park() for @k to return false, wakes it, and
331 * waits for it to return. If the thread is marked percpu then its
332 * bound to the cpu again.
333 */
334void kthread_unpark(struct task_struct *k)
335{
336 struct kthread *kthread = task_get_live_kthread(k);
337
338 if (kthread) {
339 clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
340 /*
341 * We clear the IS_PARKED bit here as we don't wait
342 * until the task has left the park code. So if we'd
343 * park before that happens we'd see the IS_PARKED bit
344 * which might be about to be cleared.
345 */
346 if (test_and_clear_bit(KTHREAD_IS_PARKED, &kthread->flags)) {
347 if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags))
348 __kthread_bind(k, kthread->cpu);
349 wake_up_process(k);
350 }
351 }
352 put_task_struct(k);
353}
354
355/**
356 * kthread_park - park a thread created by kthread_create().
357 * @k: thread created by kthread_create().
358 *
359 * Sets kthread_should_park() for @k to return true, wakes it, and
360 * waits for it to return. This can also be called after kthread_create()
361 * instead of calling wake_up_process(): the thread will park without
362 * calling threadfn().
363 *
364 * Returns 0 if the thread is parked, -ENOSYS if the thread exited.
365 * If called by the kthread itself just the park bit is set.
366 */
367int kthread_park(struct task_struct *k)
368{
369 struct kthread *kthread = task_get_live_kthread(k);
370 int ret = -ENOSYS;
371
372 if (kthread) {
373 if (!test_bit(KTHREAD_IS_PARKED, &kthread->flags)) {
374 set_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
375 if (k != current) {
376 wake_up_process(k);
377 wait_for_completion(&kthread->parked);
378 }
379 }
380 ret = 0;
381 }
382 put_task_struct(k);
383 return ret;
384}
385
386/**
237 * kthread_stop - stop a thread created by kthread_create(). 387 * kthread_stop - stop a thread created by kthread_create().
238 * @k: thread created by kthread_create(). 388 * @k: thread created by kthread_create().
239 * 389 *
@@ -250,16 +400,13 @@ EXPORT_SYMBOL(kthread_bind);
250 */ 400 */
251int kthread_stop(struct task_struct *k) 401int kthread_stop(struct task_struct *k)
252{ 402{
253 struct kthread *kthread; 403 struct kthread *kthread = task_get_live_kthread(k);
254 int ret; 404 int ret;
255 405
256 trace_sched_kthread_stop(k); 406 trace_sched_kthread_stop(k);
257 get_task_struct(k); 407 if (kthread) {
258 408 set_bit(KTHREAD_SHOULD_STOP, &kthread->flags);
259 kthread = to_kthread(k); 409 clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
260 barrier(); /* it might have exited */
261 if (k->vfork_done != NULL) {
262 kthread->should_stop = 1;
263 wake_up_process(k); 410 wake_up_process(k);
264 wait_for_completion(&kthread->exited); 411 wait_for_completion(&kthread->exited);
265 } 412 }
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index ea9ee4518c35..7981e5b2350d 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -2998,6 +2998,42 @@ EXPORT_SYMBOL_GPL(lockdep_init_map);
2998 2998
2999struct lock_class_key __lockdep_no_validate__; 2999struct lock_class_key __lockdep_no_validate__;
3000 3000
3001static int
3002print_lock_nested_lock_not_held(struct task_struct *curr,
3003 struct held_lock *hlock,
3004 unsigned long ip)
3005{
3006 if (!debug_locks_off())
3007 return 0;
3008 if (debug_locks_silent)
3009 return 0;
3010
3011 printk("\n");
3012 printk("==================================\n");
3013 printk("[ BUG: Nested lock was not taken ]\n");
3014 print_kernel_ident();
3015 printk("----------------------------------\n");
3016
3017 printk("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr));
3018 print_lock(hlock);
3019
3020 printk("\nbut this task is not holding:\n");
3021 printk("%s\n", hlock->nest_lock->name);
3022
3023 printk("\nstack backtrace:\n");
3024 dump_stack();
3025
3026 printk("\nother info that might help us debug this:\n");
3027 lockdep_print_held_locks(curr);
3028
3029 printk("\nstack backtrace:\n");
3030 dump_stack();
3031
3032 return 0;
3033}
3034
3035static int __lock_is_held(struct lockdep_map *lock);
3036
3001/* 3037/*
3002 * This gets called for every mutex_lock*()/spin_lock*() operation. 3038 * This gets called for every mutex_lock*()/spin_lock*() operation.
3003 * We maintain the dependency maps and validate the locking attempt: 3039 * We maintain the dependency maps and validate the locking attempt:
@@ -3139,6 +3175,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
3139 } 3175 }
3140 chain_key = iterate_chain_key(chain_key, id); 3176 chain_key = iterate_chain_key(chain_key, id);
3141 3177
3178 if (nest_lock && !__lock_is_held(nest_lock))
3179 return print_lock_nested_lock_not_held(curr, hlock, ip);
3180
3142 if (!validate_chain(curr, lock, hlock, chain_head, chain_key)) 3181 if (!validate_chain(curr, lock, hlock, chain_head, chain_key))
3143 return 0; 3182 return 0;
3144 3183
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index b3c7fd554250..6144bab8fd8e 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -232,15 +232,19 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
232 */ 232 */
233 233
234 tmp.data = &current->nsproxy->pid_ns->last_pid; 234 tmp.data = &current->nsproxy->pid_ns->last_pid;
235 return proc_dointvec(&tmp, write, buffer, lenp, ppos); 235 return proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
236} 236}
237 237
238extern int pid_max;
239static int zero = 0;
238static struct ctl_table pid_ns_ctl_table[] = { 240static struct ctl_table pid_ns_ctl_table[] = {
239 { 241 {
240 .procname = "ns_last_pid", 242 .procname = "ns_last_pid",
241 .maxlen = sizeof(int), 243 .maxlen = sizeof(int),
242 .mode = 0666, /* permissions are checked in the handler */ 244 .mode = 0666, /* permissions are checked in the handler */
243 .proc_handler = pid_ns_ctl_handler, 245 .proc_handler = pid_ns_ctl_handler,
246 .extra1 = &zero,
247 .extra2 = &pid_max,
244 }, 248 },
245 { } 249 { }
246}; 250};
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
index 4e6a61b15e86..29ca1c6da594 100644
--- a/kernel/rcupdate.c
+++ b/kernel/rcupdate.c
@@ -45,6 +45,7 @@
45#include <linux/mutex.h> 45#include <linux/mutex.h>
46#include <linux/export.h> 46#include <linux/export.h>
47#include <linux/hardirq.h> 47#include <linux/hardirq.h>
48#include <linux/delay.h>
48 49
49#define CREATE_TRACE_POINTS 50#define CREATE_TRACE_POINTS
50#include <trace/events/rcu.h> 51#include <trace/events/rcu.h>
@@ -81,6 +82,9 @@ void __rcu_read_unlock(void)
81 } else { 82 } else {
82 barrier(); /* critical section before exit code. */ 83 barrier(); /* critical section before exit code. */
83 t->rcu_read_lock_nesting = INT_MIN; 84 t->rcu_read_lock_nesting = INT_MIN;
85#ifdef CONFIG_PROVE_RCU_DELAY
86 udelay(10); /* Make preemption more probable. */
87#endif /* #ifdef CONFIG_PROVE_RCU_DELAY */
84 barrier(); /* assign before ->rcu_read_unlock_special load */ 88 barrier(); /* assign before ->rcu_read_unlock_special load */
85 if (unlikely(ACCESS_ONCE(t->rcu_read_unlock_special))) 89 if (unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
86 rcu_read_unlock_special(t); 90 rcu_read_unlock_special(t);
diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
index 547b1fe5b052..e4c6a598d6f7 100644
--- a/kernel/rcutiny.c
+++ b/kernel/rcutiny.c
@@ -56,25 +56,28 @@ static void __call_rcu(struct rcu_head *head,
56static long long rcu_dynticks_nesting = DYNTICK_TASK_EXIT_IDLE; 56static long long rcu_dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
57 57
58/* Common code for rcu_idle_enter() and rcu_irq_exit(), see kernel/rcutree.c. */ 58/* Common code for rcu_idle_enter() and rcu_irq_exit(), see kernel/rcutree.c. */
59static void rcu_idle_enter_common(long long oldval) 59static void rcu_idle_enter_common(long long newval)
60{ 60{
61 if (rcu_dynticks_nesting) { 61 if (newval) {
62 RCU_TRACE(trace_rcu_dyntick("--=", 62 RCU_TRACE(trace_rcu_dyntick("--=",
63 oldval, rcu_dynticks_nesting)); 63 rcu_dynticks_nesting, newval));
64 rcu_dynticks_nesting = newval;
64 return; 65 return;
65 } 66 }
66 RCU_TRACE(trace_rcu_dyntick("Start", oldval, rcu_dynticks_nesting)); 67 RCU_TRACE(trace_rcu_dyntick("Start", rcu_dynticks_nesting, newval));
67 if (!is_idle_task(current)) { 68 if (!is_idle_task(current)) {
68 struct task_struct *idle = idle_task(smp_processor_id()); 69 struct task_struct *idle = idle_task(smp_processor_id());
69 70
70 RCU_TRACE(trace_rcu_dyntick("Error on entry: not idle task", 71 RCU_TRACE(trace_rcu_dyntick("Error on entry: not idle task",
71 oldval, rcu_dynticks_nesting)); 72 rcu_dynticks_nesting, newval));
72 ftrace_dump(DUMP_ALL); 73 ftrace_dump(DUMP_ALL);
73 WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s", 74 WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s",
74 current->pid, current->comm, 75 current->pid, current->comm,
75 idle->pid, idle->comm); /* must be idle task! */ 76 idle->pid, idle->comm); /* must be idle task! */
76 } 77 }
77 rcu_sched_qs(0); /* implies rcu_bh_qsctr_inc(0) */ 78 rcu_sched_qs(0); /* implies rcu_bh_qsctr_inc(0) */
79 barrier();
80 rcu_dynticks_nesting = newval;
78} 81}
79 82
80/* 83/*
@@ -84,17 +87,16 @@ static void rcu_idle_enter_common(long long oldval)
84void rcu_idle_enter(void) 87void rcu_idle_enter(void)
85{ 88{
86 unsigned long flags; 89 unsigned long flags;
87 long long oldval; 90 long long newval;
88 91
89 local_irq_save(flags); 92 local_irq_save(flags);
90 oldval = rcu_dynticks_nesting;
91 WARN_ON_ONCE((rcu_dynticks_nesting & DYNTICK_TASK_NEST_MASK) == 0); 93 WARN_ON_ONCE((rcu_dynticks_nesting & DYNTICK_TASK_NEST_MASK) == 0);
92 if ((rcu_dynticks_nesting & DYNTICK_TASK_NEST_MASK) == 94 if ((rcu_dynticks_nesting & DYNTICK_TASK_NEST_MASK) ==
93 DYNTICK_TASK_NEST_VALUE) 95 DYNTICK_TASK_NEST_VALUE)
94 rcu_dynticks_nesting = 0; 96 newval = 0;
95 else 97 else
96 rcu_dynticks_nesting -= DYNTICK_TASK_NEST_VALUE; 98 newval = rcu_dynticks_nesting - DYNTICK_TASK_NEST_VALUE;
97 rcu_idle_enter_common(oldval); 99 rcu_idle_enter_common(newval);
98 local_irq_restore(flags); 100 local_irq_restore(flags);
99} 101}
100EXPORT_SYMBOL_GPL(rcu_idle_enter); 102EXPORT_SYMBOL_GPL(rcu_idle_enter);
@@ -105,15 +107,15 @@ EXPORT_SYMBOL_GPL(rcu_idle_enter);
105void rcu_irq_exit(void) 107void rcu_irq_exit(void)
106{ 108{
107 unsigned long flags; 109 unsigned long flags;
108 long long oldval; 110 long long newval;
109 111
110 local_irq_save(flags); 112 local_irq_save(flags);
111 oldval = rcu_dynticks_nesting; 113 newval = rcu_dynticks_nesting - 1;
112 rcu_dynticks_nesting--; 114 WARN_ON_ONCE(newval < 0);
113 WARN_ON_ONCE(rcu_dynticks_nesting < 0); 115 rcu_idle_enter_common(newval);
114 rcu_idle_enter_common(oldval);
115 local_irq_restore(flags); 116 local_irq_restore(flags);
116} 117}
118EXPORT_SYMBOL_GPL(rcu_irq_exit);
117 119
118/* Common code for rcu_idle_exit() and rcu_irq_enter(), see kernel/rcutree.c. */ 120/* Common code for rcu_idle_exit() and rcu_irq_enter(), see kernel/rcutree.c. */
119static void rcu_idle_exit_common(long long oldval) 121static void rcu_idle_exit_common(long long oldval)
@@ -171,6 +173,7 @@ void rcu_irq_enter(void)
171 rcu_idle_exit_common(oldval); 173 rcu_idle_exit_common(oldval);
172 local_irq_restore(flags); 174 local_irq_restore(flags);
173} 175}
176EXPORT_SYMBOL_GPL(rcu_irq_enter);
174 177
175#ifdef CONFIG_DEBUG_LOCK_ALLOC 178#ifdef CONFIG_DEBUG_LOCK_ALLOC
176 179
diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
index 918fd1e8509c..3d0190282204 100644
--- a/kernel/rcutiny_plugin.h
+++ b/kernel/rcutiny_plugin.h
@@ -278,7 +278,7 @@ static int rcu_boost(void)
278 rcu_preempt_ctrlblk.exp_tasks == NULL) 278 rcu_preempt_ctrlblk.exp_tasks == NULL)
279 return 0; /* Nothing to boost. */ 279 return 0; /* Nothing to boost. */
280 280
281 raw_local_irq_save(flags); 281 local_irq_save(flags);
282 282
283 /* 283 /*
284 * Recheck with irqs disabled: all tasks in need of boosting 284 * Recheck with irqs disabled: all tasks in need of boosting
@@ -287,7 +287,7 @@ static int rcu_boost(void)
287 */ 287 */
288 if (rcu_preempt_ctrlblk.boost_tasks == NULL && 288 if (rcu_preempt_ctrlblk.boost_tasks == NULL &&
289 rcu_preempt_ctrlblk.exp_tasks == NULL) { 289 rcu_preempt_ctrlblk.exp_tasks == NULL) {
290 raw_local_irq_restore(flags); 290 local_irq_restore(flags);
291 return 0; 291 return 0;
292 } 292 }
293 293
@@ -317,7 +317,7 @@ static int rcu_boost(void)
317 t = container_of(tb, struct task_struct, rcu_node_entry); 317 t = container_of(tb, struct task_struct, rcu_node_entry);
318 rt_mutex_init_proxy_locked(&mtx, t); 318 rt_mutex_init_proxy_locked(&mtx, t);
319 t->rcu_boost_mutex = &mtx; 319 t->rcu_boost_mutex = &mtx;
320 raw_local_irq_restore(flags); 320 local_irq_restore(flags);
321 rt_mutex_lock(&mtx); 321 rt_mutex_lock(&mtx);
322 rt_mutex_unlock(&mtx); /* Keep lockdep happy. */ 322 rt_mutex_unlock(&mtx); /* Keep lockdep happy. */
323 323
@@ -991,9 +991,9 @@ static void rcu_trace_sub_qlen(struct rcu_ctrlblk *rcp, int n)
991{ 991{
992 unsigned long flags; 992 unsigned long flags;
993 993
994 raw_local_irq_save(flags); 994 local_irq_save(flags);
995 rcp->qlen -= n; 995 rcp->qlen -= n;
996 raw_local_irq_restore(flags); 996 local_irq_restore(flags);
997} 997}
998 998
999/* 999/*
diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
index 25b15033c61f..aaa7b9f3532a 100644
--- a/kernel/rcutorture.c
+++ b/kernel/rcutorture.c
@@ -53,10 +53,11 @@ MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@fre
53 53
54static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */ 54static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
55static int nfakewriters = 4; /* # fake writer threads */ 55static int nfakewriters = 4; /* # fake writer threads */
56static int stat_interval; /* Interval between stats, in seconds. */ 56static int stat_interval = 60; /* Interval between stats, in seconds. */
57 /* Defaults to "only at end of test". */ 57 /* Zero means "only at end of test". */
58static bool verbose; /* Print more debug info. */ 58static bool verbose; /* Print more debug info. */
59static bool test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */ 59static bool test_no_idle_hz = true;
60 /* Test RCU support for tickless idle CPUs. */
60static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/ 61static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
61static int stutter = 5; /* Start/stop testing interval (in sec) */ 62static int stutter = 5; /* Start/stop testing interval (in sec) */
62static int irqreader = 1; /* RCU readers from irq (timers). */ 63static int irqreader = 1; /* RCU readers from irq (timers). */
@@ -119,11 +120,11 @@ MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
119 120
120#define TORTURE_FLAG "-torture:" 121#define TORTURE_FLAG "-torture:"
121#define PRINTK_STRING(s) \ 122#define PRINTK_STRING(s) \
122 do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) 123 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
123#define VERBOSE_PRINTK_STRING(s) \ 124#define VERBOSE_PRINTK_STRING(s) \
124 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) 125 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
125#define VERBOSE_PRINTK_ERRSTRING(s) \ 126#define VERBOSE_PRINTK_ERRSTRING(s) \
126 do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) 127 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
127 128
128static char printk_buf[4096]; 129static char printk_buf[4096];
129 130
@@ -176,8 +177,14 @@ static long n_rcu_torture_boosts;
176static long n_rcu_torture_timers; 177static long n_rcu_torture_timers;
177static long n_offline_attempts; 178static long n_offline_attempts;
178static long n_offline_successes; 179static long n_offline_successes;
180static unsigned long sum_offline;
181static int min_offline = -1;
182static int max_offline;
179static long n_online_attempts; 183static long n_online_attempts;
180static long n_online_successes; 184static long n_online_successes;
185static unsigned long sum_online;
186static int min_online = -1;
187static int max_online;
181static long n_barrier_attempts; 188static long n_barrier_attempts;
182static long n_barrier_successes; 189static long n_barrier_successes;
183static struct list_head rcu_torture_removed; 190static struct list_head rcu_torture_removed;
@@ -235,7 +242,7 @@ rcutorture_shutdown_notify(struct notifier_block *unused1,
235 if (fullstop == FULLSTOP_DONTSTOP) 242 if (fullstop == FULLSTOP_DONTSTOP)
236 fullstop = FULLSTOP_SHUTDOWN; 243 fullstop = FULLSTOP_SHUTDOWN;
237 else 244 else
238 printk(KERN_WARNING /* but going down anyway, so... */ 245 pr_warn(/* but going down anyway, so... */
239 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); 246 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
240 mutex_unlock(&fullstop_mutex); 247 mutex_unlock(&fullstop_mutex);
241 return NOTIFY_DONE; 248 return NOTIFY_DONE;
@@ -248,7 +255,7 @@ rcutorture_shutdown_notify(struct notifier_block *unused1,
248static void rcutorture_shutdown_absorb(char *title) 255static void rcutorture_shutdown_absorb(char *title)
249{ 256{
250 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { 257 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
251 printk(KERN_NOTICE 258 pr_notice(
252 "rcutorture thread %s parking due to system shutdown\n", 259 "rcutorture thread %s parking due to system shutdown\n",
253 title); 260 title);
254 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT); 261 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
@@ -1214,11 +1221,13 @@ rcu_torture_printk(char *page)
1214 n_rcu_torture_boost_failure, 1221 n_rcu_torture_boost_failure,
1215 n_rcu_torture_boosts, 1222 n_rcu_torture_boosts,
1216 n_rcu_torture_timers); 1223 n_rcu_torture_timers);
1217 cnt += sprintf(&page[cnt], "onoff: %ld/%ld:%ld/%ld ", 1224 cnt += sprintf(&page[cnt],
1218 n_online_successes, 1225 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1219 n_online_attempts, 1226 n_online_successes, n_online_attempts,
1220 n_offline_successes, 1227 n_offline_successes, n_offline_attempts,
1221 n_offline_attempts); 1228 min_online, max_online,
1229 min_offline, max_offline,
1230 sum_online, sum_offline, HZ);
1222 cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld", 1231 cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld",
1223 n_barrier_successes, 1232 n_barrier_successes,
1224 n_barrier_attempts, 1233 n_barrier_attempts,
@@ -1267,7 +1276,7 @@ rcu_torture_stats_print(void)
1267 int cnt; 1276 int cnt;
1268 1277
1269 cnt = rcu_torture_printk(printk_buf); 1278 cnt = rcu_torture_printk(printk_buf);
1270 printk(KERN_ALERT "%s", printk_buf); 1279 pr_alert("%s", printk_buf);
1271} 1280}
1272 1281
1273/* 1282/*
@@ -1380,20 +1389,20 @@ rcu_torture_stutter(void *arg)
1380static inline void 1389static inline void
1381rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag) 1390rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
1382{ 1391{
1383 printk(KERN_ALERT "%s" TORTURE_FLAG 1392 pr_alert("%s" TORTURE_FLAG
1384 "--- %s: nreaders=%d nfakewriters=%d " 1393 "--- %s: nreaders=%d nfakewriters=%d "
1385 "stat_interval=%d verbose=%d test_no_idle_hz=%d " 1394 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1386 "shuffle_interval=%d stutter=%d irqreader=%d " 1395 "shuffle_interval=%d stutter=%d irqreader=%d "
1387 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d " 1396 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1388 "test_boost=%d/%d test_boost_interval=%d " 1397 "test_boost=%d/%d test_boost_interval=%d "
1389 "test_boost_duration=%d shutdown_secs=%d " 1398 "test_boost_duration=%d shutdown_secs=%d "
1390 "onoff_interval=%d onoff_holdoff=%d\n", 1399 "onoff_interval=%d onoff_holdoff=%d\n",
1391 torture_type, tag, nrealreaders, nfakewriters, 1400 torture_type, tag, nrealreaders, nfakewriters,
1392 stat_interval, verbose, test_no_idle_hz, shuffle_interval, 1401 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1393 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter, 1402 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1394 test_boost, cur_ops->can_boost, 1403 test_boost, cur_ops->can_boost,
1395 test_boost_interval, test_boost_duration, shutdown_secs, 1404 test_boost_interval, test_boost_duration, shutdown_secs,
1396 onoff_interval, onoff_holdoff); 1405 onoff_interval, onoff_holdoff);
1397} 1406}
1398 1407
1399static struct notifier_block rcutorture_shutdown_nb = { 1408static struct notifier_block rcutorture_shutdown_nb = {
@@ -1460,9 +1469,9 @@ rcu_torture_shutdown(void *arg)
1460 !kthread_should_stop()) { 1469 !kthread_should_stop()) {
1461 delta = shutdown_time - jiffies_snap; 1470 delta = shutdown_time - jiffies_snap;
1462 if (verbose) 1471 if (verbose)
1463 printk(KERN_ALERT "%s" TORTURE_FLAG 1472 pr_alert("%s" TORTURE_FLAG
1464 "rcu_torture_shutdown task: %lu jiffies remaining\n", 1473 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1465 torture_type, delta); 1474 torture_type, delta);
1466 schedule_timeout_interruptible(delta); 1475 schedule_timeout_interruptible(delta);
1467 jiffies_snap = ACCESS_ONCE(jiffies); 1476 jiffies_snap = ACCESS_ONCE(jiffies);
1468 } 1477 }
@@ -1490,8 +1499,10 @@ static int __cpuinit
1490rcu_torture_onoff(void *arg) 1499rcu_torture_onoff(void *arg)
1491{ 1500{
1492 int cpu; 1501 int cpu;
1502 unsigned long delta;
1493 int maxcpu = -1; 1503 int maxcpu = -1;
1494 DEFINE_RCU_RANDOM(rand); 1504 DEFINE_RCU_RANDOM(rand);
1505 unsigned long starttime;
1495 1506
1496 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started"); 1507 VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1497 for_each_online_cpu(cpu) 1508 for_each_online_cpu(cpu)
@@ -1506,29 +1517,51 @@ rcu_torture_onoff(void *arg)
1506 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1); 1517 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
1507 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) { 1518 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) {
1508 if (verbose) 1519 if (verbose)
1509 printk(KERN_ALERT "%s" TORTURE_FLAG 1520 pr_alert("%s" TORTURE_FLAG
1510 "rcu_torture_onoff task: offlining %d\n", 1521 "rcu_torture_onoff task: offlining %d\n",
1511 torture_type, cpu); 1522 torture_type, cpu);
1523 starttime = jiffies;
1512 n_offline_attempts++; 1524 n_offline_attempts++;
1513 if (cpu_down(cpu) == 0) { 1525 if (cpu_down(cpu) == 0) {
1514 if (verbose) 1526 if (verbose)
1515 printk(KERN_ALERT "%s" TORTURE_FLAG 1527 pr_alert("%s" TORTURE_FLAG
1516 "rcu_torture_onoff task: offlined %d\n", 1528 "rcu_torture_onoff task: offlined %d\n",
1517 torture_type, cpu); 1529 torture_type, cpu);
1518 n_offline_successes++; 1530 n_offline_successes++;
1531 delta = jiffies - starttime;
1532 sum_offline += delta;
1533 if (min_offline < 0) {
1534 min_offline = delta;
1535 max_offline = delta;
1536 }
1537 if (min_offline > delta)
1538 min_offline = delta;
1539 if (max_offline < delta)
1540 max_offline = delta;
1519 } 1541 }
1520 } else if (cpu_is_hotpluggable(cpu)) { 1542 } else if (cpu_is_hotpluggable(cpu)) {
1521 if (verbose) 1543 if (verbose)
1522 printk(KERN_ALERT "%s" TORTURE_FLAG 1544 pr_alert("%s" TORTURE_FLAG
1523 "rcu_torture_onoff task: onlining %d\n", 1545 "rcu_torture_onoff task: onlining %d\n",
1524 torture_type, cpu); 1546 torture_type, cpu);
1547 starttime = jiffies;
1525 n_online_attempts++; 1548 n_online_attempts++;
1526 if (cpu_up(cpu) == 0) { 1549 if (cpu_up(cpu) == 0) {
1527 if (verbose) 1550 if (verbose)
1528 printk(KERN_ALERT "%s" TORTURE_FLAG 1551 pr_alert("%s" TORTURE_FLAG
1529 "rcu_torture_onoff task: onlined %d\n", 1552 "rcu_torture_onoff task: onlined %d\n",
1530 torture_type, cpu); 1553 torture_type, cpu);
1531 n_online_successes++; 1554 n_online_successes++;
1555 delta = jiffies - starttime;
1556 sum_online += delta;
1557 if (min_online < 0) {
1558 min_online = delta;
1559 max_online = delta;
1560 }
1561 if (min_online > delta)
1562 min_online = delta;
1563 if (max_online < delta)
1564 max_online = delta;
1532 } 1565 }
1533 } 1566 }
1534 schedule_timeout_interruptible(onoff_interval * HZ); 1567 schedule_timeout_interruptible(onoff_interval * HZ);
@@ -1593,14 +1626,14 @@ static int __cpuinit rcu_torture_stall(void *args)
1593 if (!kthread_should_stop()) { 1626 if (!kthread_should_stop()) {
1594 stop_at = get_seconds() + stall_cpu; 1627 stop_at = get_seconds() + stall_cpu;
1595 /* RCU CPU stall is expected behavior in following code. */ 1628 /* RCU CPU stall is expected behavior in following code. */
1596 printk(KERN_ALERT "rcu_torture_stall start.\n"); 1629 pr_alert("rcu_torture_stall start.\n");
1597 rcu_read_lock(); 1630 rcu_read_lock();
1598 preempt_disable(); 1631 preempt_disable();
1599 while (ULONG_CMP_LT(get_seconds(), stop_at)) 1632 while (ULONG_CMP_LT(get_seconds(), stop_at))
1600 continue; /* Induce RCU CPU stall warning. */ 1633 continue; /* Induce RCU CPU stall warning. */
1601 preempt_enable(); 1634 preempt_enable();
1602 rcu_read_unlock(); 1635 rcu_read_unlock();
1603 printk(KERN_ALERT "rcu_torture_stall end.\n"); 1636 pr_alert("rcu_torture_stall end.\n");
1604 } 1637 }
1605 rcutorture_shutdown_absorb("rcu_torture_stall"); 1638 rcutorture_shutdown_absorb("rcu_torture_stall");
1606 while (!kthread_should_stop()) 1639 while (!kthread_should_stop())
@@ -1716,12 +1749,12 @@ static int rcu_torture_barrier_init(void)
1716 if (n_barrier_cbs == 0) 1749 if (n_barrier_cbs == 0)
1717 return 0; 1750 return 0;
1718 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) { 1751 if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
1719 printk(KERN_ALERT "%s" TORTURE_FLAG 1752 pr_alert("%s" TORTURE_FLAG
1720 " Call or barrier ops missing for %s,\n", 1753 " Call or barrier ops missing for %s,\n",
1721 torture_type, cur_ops->name); 1754 torture_type, cur_ops->name);
1722 printk(KERN_ALERT "%s" TORTURE_FLAG 1755 pr_alert("%s" TORTURE_FLAG
1723 " RCU barrier testing omitted from run.\n", 1756 " RCU barrier testing omitted from run.\n",
1724 torture_type); 1757 torture_type);
1725 return 0; 1758 return 0;
1726 } 1759 }
1727 atomic_set(&barrier_cbs_count, 0); 1760 atomic_set(&barrier_cbs_count, 0);
@@ -1814,7 +1847,7 @@ rcu_torture_cleanup(void)
1814 mutex_lock(&fullstop_mutex); 1847 mutex_lock(&fullstop_mutex);
1815 rcutorture_record_test_transition(); 1848 rcutorture_record_test_transition();
1816 if (fullstop == FULLSTOP_SHUTDOWN) { 1849 if (fullstop == FULLSTOP_SHUTDOWN) {
1817 printk(KERN_WARNING /* but going down anyway, so... */ 1850 pr_warn(/* but going down anyway, so... */
1818 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); 1851 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1819 mutex_unlock(&fullstop_mutex); 1852 mutex_unlock(&fullstop_mutex);
1820 schedule_timeout_uninterruptible(10); 1853 schedule_timeout_uninterruptible(10);
@@ -1938,17 +1971,17 @@ rcu_torture_init(void)
1938 break; 1971 break;
1939 } 1972 }
1940 if (i == ARRAY_SIZE(torture_ops)) { 1973 if (i == ARRAY_SIZE(torture_ops)) {
1941 printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n", 1974 pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
1942 torture_type); 1975 torture_type);
1943 printk(KERN_ALERT "rcu-torture types:"); 1976 pr_alert("rcu-torture types:");
1944 for (i = 0; i < ARRAY_SIZE(torture_ops); i++) 1977 for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
1945 printk(KERN_ALERT " %s", torture_ops[i]->name); 1978 pr_alert(" %s", torture_ops[i]->name);
1946 printk(KERN_ALERT "\n"); 1979 pr_alert("\n");
1947 mutex_unlock(&fullstop_mutex); 1980 mutex_unlock(&fullstop_mutex);
1948 return -EINVAL; 1981 return -EINVAL;
1949 } 1982 }
1950 if (cur_ops->fqs == NULL && fqs_duration != 0) { 1983 if (cur_ops->fqs == NULL && fqs_duration != 0) {
1951 printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n"); 1984 pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
1952 fqs_duration = 0; 1985 fqs_duration = 0;
1953 } 1986 }
1954 if (cur_ops->init) 1987 if (cur_ops->init)
@@ -1996,14 +2029,15 @@ rcu_torture_init(void)
1996 /* Start up the kthreads. */ 2029 /* Start up the kthreads. */
1997 2030
1998 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); 2031 VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
1999 writer_task = kthread_run(rcu_torture_writer, NULL, 2032 writer_task = kthread_create(rcu_torture_writer, NULL,
2000 "rcu_torture_writer"); 2033 "rcu_torture_writer");
2001 if (IS_ERR(writer_task)) { 2034 if (IS_ERR(writer_task)) {
2002 firsterr = PTR_ERR(writer_task); 2035 firsterr = PTR_ERR(writer_task);
2003 VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); 2036 VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
2004 writer_task = NULL; 2037 writer_task = NULL;
2005 goto unwind; 2038 goto unwind;
2006 } 2039 }
2040 wake_up_process(writer_task);
2007 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), 2041 fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
2008 GFP_KERNEL); 2042 GFP_KERNEL);
2009 if (fakewriter_tasks == NULL) { 2043 if (fakewriter_tasks == NULL) {
@@ -2118,14 +2152,15 @@ rcu_torture_init(void)
2118 } 2152 }
2119 if (shutdown_secs > 0) { 2153 if (shutdown_secs > 0) {
2120 shutdown_time = jiffies + shutdown_secs * HZ; 2154 shutdown_time = jiffies + shutdown_secs * HZ;
2121 shutdown_task = kthread_run(rcu_torture_shutdown, NULL, 2155 shutdown_task = kthread_create(rcu_torture_shutdown, NULL,
2122 "rcu_torture_shutdown"); 2156 "rcu_torture_shutdown");
2123 if (IS_ERR(shutdown_task)) { 2157 if (IS_ERR(shutdown_task)) {
2124 firsterr = PTR_ERR(shutdown_task); 2158 firsterr = PTR_ERR(shutdown_task);
2125 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown"); 2159 VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
2126 shutdown_task = NULL; 2160 shutdown_task = NULL;
2127 goto unwind; 2161 goto unwind;
2128 } 2162 }
2163 wake_up_process(shutdown_task);
2129 } 2164 }
2130 i = rcu_torture_onoff_init(); 2165 i = rcu_torture_onoff_init();
2131 if (i != 0) { 2166 if (i != 0) {
diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index f280e542e3e9..4fb2376ddf06 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -52,6 +52,7 @@
52#include <linux/prefetch.h> 52#include <linux/prefetch.h>
53#include <linux/delay.h> 53#include <linux/delay.h>
54#include <linux/stop_machine.h> 54#include <linux/stop_machine.h>
55#include <linux/random.h>
55 56
56#include "rcutree.h" 57#include "rcutree.h"
57#include <trace/events/rcu.h> 58#include <trace/events/rcu.h>
@@ -61,6 +62,7 @@
61/* Data structures. */ 62/* Data structures. */
62 63
63static struct lock_class_key rcu_node_class[RCU_NUM_LVLS]; 64static struct lock_class_key rcu_node_class[RCU_NUM_LVLS];
65static struct lock_class_key rcu_fqs_class[RCU_NUM_LVLS];
64 66
65#define RCU_STATE_INITIALIZER(sname, cr) { \ 67#define RCU_STATE_INITIALIZER(sname, cr) { \
66 .level = { &sname##_state.node[0] }, \ 68 .level = { &sname##_state.node[0] }, \
@@ -72,7 +74,6 @@ static struct lock_class_key rcu_node_class[RCU_NUM_LVLS];
72 .orphan_nxttail = &sname##_state.orphan_nxtlist, \ 74 .orphan_nxttail = &sname##_state.orphan_nxtlist, \
73 .orphan_donetail = &sname##_state.orphan_donelist, \ 75 .orphan_donetail = &sname##_state.orphan_donelist, \
74 .barrier_mutex = __MUTEX_INITIALIZER(sname##_state.barrier_mutex), \ 76 .barrier_mutex = __MUTEX_INITIALIZER(sname##_state.barrier_mutex), \
75 .fqslock = __RAW_SPIN_LOCK_UNLOCKED(&sname##_state.fqslock), \
76 .name = #sname, \ 77 .name = #sname, \
77} 78}
78 79
@@ -88,7 +89,7 @@ LIST_HEAD(rcu_struct_flavors);
88 89
89/* Increase (but not decrease) the CONFIG_RCU_FANOUT_LEAF at boot time. */ 90/* Increase (but not decrease) the CONFIG_RCU_FANOUT_LEAF at boot time. */
90static int rcu_fanout_leaf = CONFIG_RCU_FANOUT_LEAF; 91static int rcu_fanout_leaf = CONFIG_RCU_FANOUT_LEAF;
91module_param(rcu_fanout_leaf, int, 0); 92module_param(rcu_fanout_leaf, int, 0444);
92int rcu_num_lvls __read_mostly = RCU_NUM_LVLS; 93int rcu_num_lvls __read_mostly = RCU_NUM_LVLS;
93static int num_rcu_lvl[] = { /* Number of rcu_nodes at specified level. */ 94static int num_rcu_lvl[] = { /* Number of rcu_nodes at specified level. */
94 NUM_RCU_LVL_0, 95 NUM_RCU_LVL_0,
@@ -133,13 +134,12 @@ static int rcu_scheduler_fully_active __read_mostly;
133 */ 134 */
134static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task); 135static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
135DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status); 136DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
136DEFINE_PER_CPU(int, rcu_cpu_kthread_cpu);
137DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops); 137DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
138DEFINE_PER_CPU(char, rcu_cpu_has_work); 138DEFINE_PER_CPU(char, rcu_cpu_has_work);
139 139
140#endif /* #ifdef CONFIG_RCU_BOOST */ 140#endif /* #ifdef CONFIG_RCU_BOOST */
141 141
142static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu); 142static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu);
143static void invoke_rcu_core(void); 143static void invoke_rcu_core(void);
144static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp); 144static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp);
145 145
@@ -175,8 +175,6 @@ void rcu_sched_qs(int cpu)
175{ 175{
176 struct rcu_data *rdp = &per_cpu(rcu_sched_data, cpu); 176 struct rcu_data *rdp = &per_cpu(rcu_sched_data, cpu);
177 177
178 rdp->passed_quiesce_gpnum = rdp->gpnum;
179 barrier();
180 if (rdp->passed_quiesce == 0) 178 if (rdp->passed_quiesce == 0)
181 trace_rcu_grace_period("rcu_sched", rdp->gpnum, "cpuqs"); 179 trace_rcu_grace_period("rcu_sched", rdp->gpnum, "cpuqs");
182 rdp->passed_quiesce = 1; 180 rdp->passed_quiesce = 1;
@@ -186,8 +184,6 @@ void rcu_bh_qs(int cpu)
186{ 184{
187 struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu); 185 struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
188 186
189 rdp->passed_quiesce_gpnum = rdp->gpnum;
190 barrier();
191 if (rdp->passed_quiesce == 0) 187 if (rdp->passed_quiesce == 0)
192 trace_rcu_grace_period("rcu_bh", rdp->gpnum, "cpuqs"); 188 trace_rcu_grace_period("rcu_bh", rdp->gpnum, "cpuqs");
193 rdp->passed_quiesce = 1; 189 rdp->passed_quiesce = 1;
@@ -210,15 +206,18 @@ EXPORT_SYMBOL_GPL(rcu_note_context_switch);
210DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = { 206DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
211 .dynticks_nesting = DYNTICK_TASK_EXIT_IDLE, 207 .dynticks_nesting = DYNTICK_TASK_EXIT_IDLE,
212 .dynticks = ATOMIC_INIT(1), 208 .dynticks = ATOMIC_INIT(1),
209#if defined(CONFIG_RCU_USER_QS) && !defined(CONFIG_RCU_USER_QS_FORCE)
210 .ignore_user_qs = true,
211#endif
213}; 212};
214 213
215static int blimit = 10; /* Maximum callbacks per rcu_do_batch. */ 214static int blimit = 10; /* Maximum callbacks per rcu_do_batch. */
216static int qhimark = 10000; /* If this many pending, ignore blimit. */ 215static int qhimark = 10000; /* If this many pending, ignore blimit. */
217static int qlowmark = 100; /* Once only this many pending, use blimit. */ 216static int qlowmark = 100; /* Once only this many pending, use blimit. */
218 217
219module_param(blimit, int, 0); 218module_param(blimit, int, 0444);
220module_param(qhimark, int, 0); 219module_param(qhimark, int, 0444);
221module_param(qlowmark, int, 0); 220module_param(qlowmark, int, 0444);
222 221
223int rcu_cpu_stall_suppress __read_mostly; /* 1 = suppress stall warnings. */ 222int rcu_cpu_stall_suppress __read_mostly; /* 1 = suppress stall warnings. */
224int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT; 223int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT;
@@ -226,7 +225,14 @@ int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT;
226module_param(rcu_cpu_stall_suppress, int, 0644); 225module_param(rcu_cpu_stall_suppress, int, 0644);
227module_param(rcu_cpu_stall_timeout, int, 0644); 226module_param(rcu_cpu_stall_timeout, int, 0644);
228 227
229static void force_quiescent_state(struct rcu_state *rsp, int relaxed); 228static ulong jiffies_till_first_fqs = RCU_JIFFIES_TILL_FORCE_QS;
229static ulong jiffies_till_next_fqs = RCU_JIFFIES_TILL_FORCE_QS;
230
231module_param(jiffies_till_first_fqs, ulong, 0644);
232module_param(jiffies_till_next_fqs, ulong, 0644);
233
234static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *));
235static void force_quiescent_state(struct rcu_state *rsp);
230static int rcu_pending(int cpu); 236static int rcu_pending(int cpu);
231 237
232/* 238/*
@@ -252,7 +258,7 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
252 */ 258 */
253void rcu_bh_force_quiescent_state(void) 259void rcu_bh_force_quiescent_state(void)
254{ 260{
255 force_quiescent_state(&rcu_bh_state, 0); 261 force_quiescent_state(&rcu_bh_state);
256} 262}
257EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state); 263EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
258 264
@@ -286,7 +292,7 @@ EXPORT_SYMBOL_GPL(rcutorture_record_progress);
286 */ 292 */
287void rcu_sched_force_quiescent_state(void) 293void rcu_sched_force_quiescent_state(void)
288{ 294{
289 force_quiescent_state(&rcu_sched_state, 0); 295 force_quiescent_state(&rcu_sched_state);
290} 296}
291EXPORT_SYMBOL_GPL(rcu_sched_force_quiescent_state); 297EXPORT_SYMBOL_GPL(rcu_sched_force_quiescent_state);
292 298
@@ -305,7 +311,9 @@ cpu_has_callbacks_ready_to_invoke(struct rcu_data *rdp)
305static int 311static int
306cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp) 312cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp)
307{ 313{
308 return *rdp->nxttail[RCU_DONE_TAIL] && !rcu_gp_in_progress(rsp); 314 return *rdp->nxttail[RCU_DONE_TAIL +
315 ACCESS_ONCE(rsp->completed) != rdp->completed] &&
316 !rcu_gp_in_progress(rsp);
309} 317}
310 318
311/* 319/*
@@ -317,45 +325,17 @@ static struct rcu_node *rcu_get_root(struct rcu_state *rsp)
317} 325}
318 326
319/* 327/*
320 * If the specified CPU is offline, tell the caller that it is in 328 * rcu_eqs_enter_common - current CPU is moving towards extended quiescent state
321 * a quiescent state. Otherwise, whack it with a reschedule IPI.
322 * Grace periods can end up waiting on an offline CPU when that
323 * CPU is in the process of coming online -- it will be added to the
324 * rcu_node bitmasks before it actually makes it online. The same thing
325 * can happen while a CPU is in the process of coming online. Because this
326 * race is quite rare, we check for it after detecting that the grace
327 * period has been delayed rather than checking each and every CPU
328 * each and every time we start a new grace period.
329 */
330static int rcu_implicit_offline_qs(struct rcu_data *rdp)
331{
332 /*
333 * If the CPU is offline for more than a jiffy, it is in a quiescent
334 * state. We can trust its state not to change because interrupts
335 * are disabled. The reason for the jiffy's worth of slack is to
336 * handle CPUs initializing on the way up and finding their way
337 * to the idle loop on the way down.
338 */
339 if (cpu_is_offline(rdp->cpu) &&
340 ULONG_CMP_LT(rdp->rsp->gp_start + 2, jiffies)) {
341 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, "ofl");
342 rdp->offline_fqs++;
343 return 1;
344 }
345 return 0;
346}
347
348/*
349 * rcu_idle_enter_common - inform RCU that current CPU is moving towards idle
350 * 329 *
351 * If the new value of the ->dynticks_nesting counter now is zero, 330 * If the new value of the ->dynticks_nesting counter now is zero,
352 * we really have entered idle, and must do the appropriate accounting. 331 * we really have entered idle, and must do the appropriate accounting.
353 * The caller must have disabled interrupts. 332 * The caller must have disabled interrupts.
354 */ 333 */
355static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval) 334static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
335 bool user)
356{ 336{
357 trace_rcu_dyntick("Start", oldval, 0); 337 trace_rcu_dyntick("Start", oldval, 0);
358 if (!is_idle_task(current)) { 338 if (!user && !is_idle_task(current)) {
359 struct task_struct *idle = idle_task(smp_processor_id()); 339 struct task_struct *idle = idle_task(smp_processor_id());
360 340
361 trace_rcu_dyntick("Error on entry: not idle task", oldval, 0); 341 trace_rcu_dyntick("Error on entry: not idle task", oldval, 0);
@@ -372,7 +352,7 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
372 WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1); 352 WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
373 353
374 /* 354 /*
375 * The idle task is not permitted to enter the idle loop while 355 * It is illegal to enter an extended quiescent state while
376 * in an RCU read-side critical section. 356 * in an RCU read-side critical section.
377 */ 357 */
378 rcu_lockdep_assert(!lock_is_held(&rcu_lock_map), 358 rcu_lockdep_assert(!lock_is_held(&rcu_lock_map),
@@ -383,6 +363,25 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
383 "Illegal idle entry in RCU-sched read-side critical section."); 363 "Illegal idle entry in RCU-sched read-side critical section.");
384} 364}
385 365
366/*
367 * Enter an RCU extended quiescent state, which can be either the
368 * idle loop or adaptive-tickless usermode execution.
369 */
370static void rcu_eqs_enter(bool user)
371{
372 long long oldval;
373 struct rcu_dynticks *rdtp;
374
375 rdtp = &__get_cpu_var(rcu_dynticks);
376 oldval = rdtp->dynticks_nesting;
377 WARN_ON_ONCE((oldval & DYNTICK_TASK_NEST_MASK) == 0);
378 if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE)
379 rdtp->dynticks_nesting = 0;
380 else
381 rdtp->dynticks_nesting -= DYNTICK_TASK_NEST_VALUE;
382 rcu_eqs_enter_common(rdtp, oldval, user);
383}
384
386/** 385/**
387 * rcu_idle_enter - inform RCU that current CPU is entering idle 386 * rcu_idle_enter - inform RCU that current CPU is entering idle
388 * 387 *
@@ -398,21 +397,70 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
398void rcu_idle_enter(void) 397void rcu_idle_enter(void)
399{ 398{
400 unsigned long flags; 399 unsigned long flags;
401 long long oldval; 400
401 local_irq_save(flags);
402 rcu_eqs_enter(false);
403 local_irq_restore(flags);
404}
405EXPORT_SYMBOL_GPL(rcu_idle_enter);
406
407#ifdef CONFIG_RCU_USER_QS
408/**
409 * rcu_user_enter - inform RCU that we are resuming userspace.
410 *
411 * Enter RCU idle mode right before resuming userspace. No use of RCU
412 * is permitted between this call and rcu_user_exit(). This way the
413 * CPU doesn't need to maintain the tick for RCU maintenance purposes
414 * when the CPU runs in userspace.
415 */
416void rcu_user_enter(void)
417{
418 unsigned long flags;
402 struct rcu_dynticks *rdtp; 419 struct rcu_dynticks *rdtp;
403 420
421 /*
422 * Some contexts may involve an exception occuring in an irq,
423 * leading to that nesting:
424 * rcu_irq_enter() rcu_user_exit() rcu_user_exit() rcu_irq_exit()
425 * This would mess up the dyntick_nesting count though. And rcu_irq_*()
426 * helpers are enough to protect RCU uses inside the exception. So
427 * just return immediately if we detect we are in an IRQ.
428 */
429 if (in_interrupt())
430 return;
431
432 WARN_ON_ONCE(!current->mm);
433
404 local_irq_save(flags); 434 local_irq_save(flags);
405 rdtp = &__get_cpu_var(rcu_dynticks); 435 rdtp = &__get_cpu_var(rcu_dynticks);
406 oldval = rdtp->dynticks_nesting; 436 if (!rdtp->ignore_user_qs && !rdtp->in_user) {
407 WARN_ON_ONCE((oldval & DYNTICK_TASK_NEST_MASK) == 0); 437 rdtp->in_user = true;
408 if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE) 438 rcu_eqs_enter(true);
409 rdtp->dynticks_nesting = 0; 439 }
410 else
411 rdtp->dynticks_nesting -= DYNTICK_TASK_NEST_VALUE;
412 rcu_idle_enter_common(rdtp, oldval);
413 local_irq_restore(flags); 440 local_irq_restore(flags);
414} 441}
415EXPORT_SYMBOL_GPL(rcu_idle_enter); 442
443/**
444 * rcu_user_enter_after_irq - inform RCU that we are going to resume userspace
445 * after the current irq returns.
446 *
447 * This is similar to rcu_user_enter() but in the context of a non-nesting
448 * irq. After this call, RCU enters into idle mode when the interrupt
449 * returns.
450 */
451void rcu_user_enter_after_irq(void)
452{
453 unsigned long flags;
454 struct rcu_dynticks *rdtp;
455
456 local_irq_save(flags);
457 rdtp = &__get_cpu_var(rcu_dynticks);
458 /* Ensure this irq is interrupting a non-idle RCU state. */
459 WARN_ON_ONCE(!(rdtp->dynticks_nesting & DYNTICK_TASK_MASK));
460 rdtp->dynticks_nesting = 1;
461 local_irq_restore(flags);
462}
463#endif /* CONFIG_RCU_USER_QS */
416 464
417/** 465/**
418 * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle 466 * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle
@@ -444,18 +492,19 @@ void rcu_irq_exit(void)
444 if (rdtp->dynticks_nesting) 492 if (rdtp->dynticks_nesting)
445 trace_rcu_dyntick("--=", oldval, rdtp->dynticks_nesting); 493 trace_rcu_dyntick("--=", oldval, rdtp->dynticks_nesting);
446 else 494 else
447 rcu_idle_enter_common(rdtp, oldval); 495 rcu_eqs_enter_common(rdtp, oldval, true);
448 local_irq_restore(flags); 496 local_irq_restore(flags);
449} 497}
450 498
451/* 499/*
452 * rcu_idle_exit_common - inform RCU that current CPU is moving away from idle 500 * rcu_eqs_exit_common - current CPU moving away from extended quiescent state
453 * 501 *
454 * If the new value of the ->dynticks_nesting counter was previously zero, 502 * If the new value of the ->dynticks_nesting counter was previously zero,
455 * we really have exited idle, and must do the appropriate accounting. 503 * we really have exited idle, and must do the appropriate accounting.
456 * The caller must have disabled interrupts. 504 * The caller must have disabled interrupts.
457 */ 505 */
458static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval) 506static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
507 int user)
459{ 508{
460 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */ 509 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
461 atomic_inc(&rdtp->dynticks); 510 atomic_inc(&rdtp->dynticks);
@@ -464,7 +513,7 @@ static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
464 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1)); 513 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
465 rcu_cleanup_after_idle(smp_processor_id()); 514 rcu_cleanup_after_idle(smp_processor_id());
466 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting); 515 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
467 if (!is_idle_task(current)) { 516 if (!user && !is_idle_task(current)) {
468 struct task_struct *idle = idle_task(smp_processor_id()); 517 struct task_struct *idle = idle_task(smp_processor_id());
469 518
470 trace_rcu_dyntick("Error on exit: not idle task", 519 trace_rcu_dyntick("Error on exit: not idle task",
@@ -476,6 +525,25 @@ static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
476 } 525 }
477} 526}
478 527
528/*
529 * Exit an RCU extended quiescent state, which can be either the
530 * idle loop or adaptive-tickless usermode execution.
531 */
532static void rcu_eqs_exit(bool user)
533{
534 struct rcu_dynticks *rdtp;
535 long long oldval;
536
537 rdtp = &__get_cpu_var(rcu_dynticks);
538 oldval = rdtp->dynticks_nesting;
539 WARN_ON_ONCE(oldval < 0);
540 if (oldval & DYNTICK_TASK_NEST_MASK)
541 rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE;
542 else
543 rdtp->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
544 rcu_eqs_exit_common(rdtp, oldval, user);
545}
546
479/** 547/**
480 * rcu_idle_exit - inform RCU that current CPU is leaving idle 548 * rcu_idle_exit - inform RCU that current CPU is leaving idle
481 * 549 *
@@ -490,21 +558,67 @@ static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
490void rcu_idle_exit(void) 558void rcu_idle_exit(void)
491{ 559{
492 unsigned long flags; 560 unsigned long flags;
561
562 local_irq_save(flags);
563 rcu_eqs_exit(false);
564 local_irq_restore(flags);
565}
566EXPORT_SYMBOL_GPL(rcu_idle_exit);
567
568#ifdef CONFIG_RCU_USER_QS
569/**
570 * rcu_user_exit - inform RCU that we are exiting userspace.
571 *
572 * Exit RCU idle mode while entering the kernel because it can
573 * run a RCU read side critical section anytime.
574 */
575void rcu_user_exit(void)
576{
577 unsigned long flags;
493 struct rcu_dynticks *rdtp; 578 struct rcu_dynticks *rdtp;
494 long long oldval; 579
580 /*
581 * Some contexts may involve an exception occuring in an irq,
582 * leading to that nesting:
583 * rcu_irq_enter() rcu_user_exit() rcu_user_exit() rcu_irq_exit()
584 * This would mess up the dyntick_nesting count though. And rcu_irq_*()
585 * helpers are enough to protect RCU uses inside the exception. So
586 * just return immediately if we detect we are in an IRQ.
587 */
588 if (in_interrupt())
589 return;
495 590
496 local_irq_save(flags); 591 local_irq_save(flags);
497 rdtp = &__get_cpu_var(rcu_dynticks); 592 rdtp = &__get_cpu_var(rcu_dynticks);
498 oldval = rdtp->dynticks_nesting; 593 if (rdtp->in_user) {
499 WARN_ON_ONCE(oldval < 0); 594 rdtp->in_user = false;
500 if (oldval & DYNTICK_TASK_NEST_MASK) 595 rcu_eqs_exit(true);
501 rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE; 596 }
502 else
503 rdtp->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
504 rcu_idle_exit_common(rdtp, oldval);
505 local_irq_restore(flags); 597 local_irq_restore(flags);
506} 598}
507EXPORT_SYMBOL_GPL(rcu_idle_exit); 599
600/**
601 * rcu_user_exit_after_irq - inform RCU that we won't resume to userspace
602 * idle mode after the current non-nesting irq returns.
603 *
604 * This is similar to rcu_user_exit() but in the context of an irq.
605 * This is called when the irq has interrupted a userspace RCU idle mode
606 * context. When the current non-nesting interrupt returns after this call,
607 * the CPU won't restore the RCU idle mode.
608 */
609void rcu_user_exit_after_irq(void)
610{
611 unsigned long flags;
612 struct rcu_dynticks *rdtp;
613
614 local_irq_save(flags);
615 rdtp = &__get_cpu_var(rcu_dynticks);
616 /* Ensure we are interrupting an RCU idle mode. */
617 WARN_ON_ONCE(rdtp->dynticks_nesting & DYNTICK_TASK_NEST_MASK);
618 rdtp->dynticks_nesting += DYNTICK_TASK_EXIT_IDLE;
619 local_irq_restore(flags);
620}
621#endif /* CONFIG_RCU_USER_QS */
508 622
509/** 623/**
510 * rcu_irq_enter - inform RCU that current CPU is entering irq away from idle 624 * rcu_irq_enter - inform RCU that current CPU is entering irq away from idle
@@ -539,7 +653,7 @@ void rcu_irq_enter(void)
539 if (oldval) 653 if (oldval)
540 trace_rcu_dyntick("++=", oldval, rdtp->dynticks_nesting); 654 trace_rcu_dyntick("++=", oldval, rdtp->dynticks_nesting);
541 else 655 else
542 rcu_idle_exit_common(rdtp, oldval); 656 rcu_eqs_exit_common(rdtp, oldval, true);
543 local_irq_restore(flags); 657 local_irq_restore(flags);
544} 658}
545 659
@@ -603,6 +717,21 @@ int rcu_is_cpu_idle(void)
603} 717}
604EXPORT_SYMBOL(rcu_is_cpu_idle); 718EXPORT_SYMBOL(rcu_is_cpu_idle);
605 719
720#ifdef CONFIG_RCU_USER_QS
721void rcu_user_hooks_switch(struct task_struct *prev,
722 struct task_struct *next)
723{
724 struct rcu_dynticks *rdtp;
725
726 /* Interrupts are disabled in context switch */
727 rdtp = &__get_cpu_var(rcu_dynticks);
728 if (!rdtp->ignore_user_qs) {
729 clear_tsk_thread_flag(prev, TIF_NOHZ);
730 set_tsk_thread_flag(next, TIF_NOHZ);
731 }
732}
733#endif /* #ifdef CONFIG_RCU_USER_QS */
734
606#if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU) 735#if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU)
607 736
608/* 737/*
@@ -673,7 +802,7 @@ static int dyntick_save_progress_counter(struct rcu_data *rdp)
673 * Return true if the specified CPU has passed through a quiescent 802 * Return true if the specified CPU has passed through a quiescent
674 * state by virtue of being in or having passed through an dynticks 803 * state by virtue of being in or having passed through an dynticks
675 * idle state since the last call to dyntick_save_progress_counter() 804 * idle state since the last call to dyntick_save_progress_counter()
676 * for this same CPU. 805 * for this same CPU, or by virtue of having been offline.
677 */ 806 */
678static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) 807static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
679{ 808{
@@ -697,8 +826,26 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
697 return 1; 826 return 1;
698 } 827 }
699 828
700 /* Go check for the CPU being offline. */ 829 /*
701 return rcu_implicit_offline_qs(rdp); 830 * Check for the CPU being offline, but only if the grace period
831 * is old enough. We don't need to worry about the CPU changing
832 * state: If we see it offline even once, it has been through a
833 * quiescent state.
834 *
835 * The reason for insisting that the grace period be at least
836 * one jiffy old is that CPUs that are not quite online and that
837 * have just gone offline can still execute RCU read-side critical
838 * sections.
839 */
840 if (ULONG_CMP_GE(rdp->rsp->gp_start + 2, jiffies))
841 return 0; /* Grace period is not old enough. */
842 barrier();
843 if (cpu_is_offline(rdp->cpu)) {
844 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, "ofl");
845 rdp->offline_fqs++;
846 return 1;
847 }
848 return 0;
702} 849}
703 850
704static int jiffies_till_stall_check(void) 851static int jiffies_till_stall_check(void)
@@ -755,14 +902,15 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
755 rcu_for_each_leaf_node(rsp, rnp) { 902 rcu_for_each_leaf_node(rsp, rnp) {
756 raw_spin_lock_irqsave(&rnp->lock, flags); 903 raw_spin_lock_irqsave(&rnp->lock, flags);
757 ndetected += rcu_print_task_stall(rnp); 904 ndetected += rcu_print_task_stall(rnp);
905 if (rnp->qsmask != 0) {
906 for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
907 if (rnp->qsmask & (1UL << cpu)) {
908 print_cpu_stall_info(rsp,
909 rnp->grplo + cpu);
910 ndetected++;
911 }
912 }
758 raw_spin_unlock_irqrestore(&rnp->lock, flags); 913 raw_spin_unlock_irqrestore(&rnp->lock, flags);
759 if (rnp->qsmask == 0)
760 continue;
761 for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
762 if (rnp->qsmask & (1UL << cpu)) {
763 print_cpu_stall_info(rsp, rnp->grplo + cpu);
764 ndetected++;
765 }
766 } 914 }
767 915
768 /* 916 /*
@@ -782,11 +930,11 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
782 else if (!trigger_all_cpu_backtrace()) 930 else if (!trigger_all_cpu_backtrace())
783 dump_stack(); 931 dump_stack();
784 932
785 /* If so configured, complain about tasks blocking the grace period. */ 933 /* Complain about tasks blocking the grace period. */
786 934
787 rcu_print_detail_task_stall(rsp); 935 rcu_print_detail_task_stall(rsp);
788 936
789 force_quiescent_state(rsp, 0); /* Kick them all. */ 937 force_quiescent_state(rsp); /* Kick them all. */
790} 938}
791 939
792static void print_cpu_stall(struct rcu_state *rsp) 940static void print_cpu_stall(struct rcu_state *rsp)
@@ -827,7 +975,8 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
827 j = ACCESS_ONCE(jiffies); 975 j = ACCESS_ONCE(jiffies);
828 js = ACCESS_ONCE(rsp->jiffies_stall); 976 js = ACCESS_ONCE(rsp->jiffies_stall);
829 rnp = rdp->mynode; 977 rnp = rdp->mynode;
830 if ((ACCESS_ONCE(rnp->qsmask) & rdp->grpmask) && ULONG_CMP_GE(j, js)) { 978 if (rcu_gp_in_progress(rsp) &&
979 (ACCESS_ONCE(rnp->qsmask) & rdp->grpmask) && ULONG_CMP_GE(j, js)) {
831 980
832 /* We haven't checked in, so go dump stack. */ 981 /* We haven't checked in, so go dump stack. */
833 print_cpu_stall(rsp); 982 print_cpu_stall(rsp);
@@ -889,12 +1038,8 @@ static void __note_new_gpnum(struct rcu_state *rsp, struct rcu_node *rnp, struct
889 */ 1038 */
890 rdp->gpnum = rnp->gpnum; 1039 rdp->gpnum = rnp->gpnum;
891 trace_rcu_grace_period(rsp->name, rdp->gpnum, "cpustart"); 1040 trace_rcu_grace_period(rsp->name, rdp->gpnum, "cpustart");
892 if (rnp->qsmask & rdp->grpmask) { 1041 rdp->passed_quiesce = 0;
893 rdp->qs_pending = 1; 1042 rdp->qs_pending = !!(rnp->qsmask & rdp->grpmask);
894 rdp->passed_quiesce = 0;
895 } else {
896 rdp->qs_pending = 0;
897 }
898 zero_cpu_stall_ticks(rdp); 1043 zero_cpu_stall_ticks(rdp);
899 } 1044 }
900} 1045}
@@ -974,10 +1119,13 @@ __rcu_process_gp_end(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_dat
974 * our behalf. Catch up with this state to avoid noting 1119 * our behalf. Catch up with this state to avoid noting
975 * spurious new grace periods. If another grace period 1120 * spurious new grace periods. If another grace period
976 * has started, then rnp->gpnum will have advanced, so 1121 * has started, then rnp->gpnum will have advanced, so
977 * we will detect this later on. 1122 * we will detect this later on. Of course, any quiescent
1123 * states we found for the old GP are now invalid.
978 */ 1124 */
979 if (ULONG_CMP_LT(rdp->gpnum, rdp->completed)) 1125 if (ULONG_CMP_LT(rdp->gpnum, rdp->completed)) {
980 rdp->gpnum = rdp->completed; 1126 rdp->gpnum = rdp->completed;
1127 rdp->passed_quiesce = 0;
1128 }
981 1129
982 /* 1130 /*
983 * If RCU does not need a quiescent state from this CPU, 1131 * If RCU does not need a quiescent state from this CPU,
@@ -1021,97 +1169,56 @@ rcu_start_gp_per_cpu(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_dat
1021 /* Prior grace period ended, so advance callbacks for current CPU. */ 1169 /* Prior grace period ended, so advance callbacks for current CPU. */
1022 __rcu_process_gp_end(rsp, rnp, rdp); 1170 __rcu_process_gp_end(rsp, rnp, rdp);
1023 1171
1024 /*
1025 * Because this CPU just now started the new grace period, we know
1026 * that all of its callbacks will be covered by this upcoming grace
1027 * period, even the ones that were registered arbitrarily recently.
1028 * Therefore, advance all outstanding callbacks to RCU_WAIT_TAIL.
1029 *
1030 * Other CPUs cannot be sure exactly when the grace period started.
1031 * Therefore, their recently registered callbacks must pass through
1032 * an additional RCU_NEXT_READY stage, so that they will be handled
1033 * by the next RCU grace period.
1034 */
1035 rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL];
1036 rdp->nxttail[RCU_WAIT_TAIL] = rdp->nxttail[RCU_NEXT_TAIL];
1037
1038 /* Set state so that this CPU will detect the next quiescent state. */ 1172 /* Set state so that this CPU will detect the next quiescent state. */
1039 __note_new_gpnum(rsp, rnp, rdp); 1173 __note_new_gpnum(rsp, rnp, rdp);
1040} 1174}
1041 1175
1042/* 1176/*
1043 * Start a new RCU grace period if warranted, re-initializing the hierarchy 1177 * Initialize a new grace period.
1044 * in preparation for detecting the next grace period. The caller must hold
1045 * the root node's ->lock, which is released before return. Hard irqs must
1046 * be disabled.
1047 *
1048 * Note that it is legal for a dying CPU (which is marked as offline) to
1049 * invoke this function. This can happen when the dying CPU reports its
1050 * quiescent state.
1051 */ 1178 */
1052static void 1179static int rcu_gp_init(struct rcu_state *rsp)
1053rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
1054 __releases(rcu_get_root(rsp)->lock)
1055{ 1180{
1056 struct rcu_data *rdp = this_cpu_ptr(rsp->rda); 1181 struct rcu_data *rdp;
1057 struct rcu_node *rnp = rcu_get_root(rsp); 1182 struct rcu_node *rnp = rcu_get_root(rsp);
1058 1183
1059 if (!rcu_scheduler_fully_active || 1184 raw_spin_lock_irq(&rnp->lock);
1060 !cpu_needs_another_gp(rsp, rdp)) { 1185 rsp->gp_flags = 0; /* Clear all flags: New grace period. */
1061 /*
1062 * Either the scheduler hasn't yet spawned the first
1063 * non-idle task or this CPU does not need another
1064 * grace period. Either way, don't start a new grace
1065 * period.
1066 */
1067 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1068 return;
1069 }
1070 1186
1071 if (rsp->fqs_active) { 1187 if (rcu_gp_in_progress(rsp)) {
1072 /* 1188 /* Grace period already in progress, don't start another. */
1073 * This CPU needs a grace period, but force_quiescent_state() 1189 raw_spin_unlock_irq(&rnp->lock);
1074 * is running. Tell it to start one on this CPU's behalf. 1190 return 0;
1075 */
1076 rsp->fqs_need_gp = 1;
1077 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1078 return;
1079 } 1191 }
1080 1192
1081 /* Advance to a new grace period and initialize state. */ 1193 /* Advance to a new grace period and initialize state. */
1082 rsp->gpnum++; 1194 rsp->gpnum++;
1083 trace_rcu_grace_period(rsp->name, rsp->gpnum, "start"); 1195 trace_rcu_grace_period(rsp->name, rsp->gpnum, "start");
1084 WARN_ON_ONCE(rsp->fqs_state == RCU_GP_INIT);
1085 rsp->fqs_state = RCU_GP_INIT; /* Hold off force_quiescent_state. */
1086 rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS;
1087 record_gp_stall_check_time(rsp); 1196 record_gp_stall_check_time(rsp);
1088 raw_spin_unlock(&rnp->lock); /* leave irqs disabled. */ 1197 raw_spin_unlock_irq(&rnp->lock);
1089 1198
1090 /* Exclude any concurrent CPU-hotplug operations. */ 1199 /* Exclude any concurrent CPU-hotplug operations. */
1091 raw_spin_lock(&rsp->onofflock); /* irqs already disabled. */ 1200 get_online_cpus();
1092 1201
1093 /* 1202 /*
1094 * Set the quiescent-state-needed bits in all the rcu_node 1203 * Set the quiescent-state-needed bits in all the rcu_node
1095 * structures for all currently online CPUs in breadth-first 1204 * structures for all currently online CPUs in breadth-first order,
1096 * order, starting from the root rcu_node structure. This 1205 * starting from the root rcu_node structure, relying on the layout
1097 * operation relies on the layout of the hierarchy within the 1206 * of the tree within the rsp->node[] array. Note that other CPUs
1098 * rsp->node[] array. Note that other CPUs will access only 1207 * will access only the leaves of the hierarchy, thus seeing that no
1099 * the leaves of the hierarchy, which still indicate that no
1100 * grace period is in progress, at least until the corresponding 1208 * grace period is in progress, at least until the corresponding
1101 * leaf node has been initialized. In addition, we have excluded 1209 * leaf node has been initialized. In addition, we have excluded
1102 * CPU-hotplug operations. 1210 * CPU-hotplug operations.
1103 * 1211 *
1104 * Note that the grace period cannot complete until we finish 1212 * The grace period cannot complete until the initialization
1105 * the initialization process, as there will be at least one 1213 * process finishes, because this kthread handles both.
1106 * qsmask bit set in the root node until that time, namely the
1107 * one corresponding to this CPU, due to the fact that we have
1108 * irqs disabled.
1109 */ 1214 */
1110 rcu_for_each_node_breadth_first(rsp, rnp) { 1215 rcu_for_each_node_breadth_first(rsp, rnp) {
1111 raw_spin_lock(&rnp->lock); /* irqs already disabled. */ 1216 raw_spin_lock_irq(&rnp->lock);
1217 rdp = this_cpu_ptr(rsp->rda);
1112 rcu_preempt_check_blocked_tasks(rnp); 1218 rcu_preempt_check_blocked_tasks(rnp);
1113 rnp->qsmask = rnp->qsmaskinit; 1219 rnp->qsmask = rnp->qsmaskinit;
1114 rnp->gpnum = rsp->gpnum; 1220 rnp->gpnum = rsp->gpnum;
1221 WARN_ON_ONCE(rnp->completed != rsp->completed);
1115 rnp->completed = rsp->completed; 1222 rnp->completed = rsp->completed;
1116 if (rnp == rdp->mynode) 1223 if (rnp == rdp->mynode)
1117 rcu_start_gp_per_cpu(rsp, rnp, rdp); 1224 rcu_start_gp_per_cpu(rsp, rnp, rdp);
@@ -1119,37 +1226,54 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
1119 trace_rcu_grace_period_init(rsp->name, rnp->gpnum, 1226 trace_rcu_grace_period_init(rsp->name, rnp->gpnum,
1120 rnp->level, rnp->grplo, 1227 rnp->level, rnp->grplo,
1121 rnp->grphi, rnp->qsmask); 1228 rnp->grphi, rnp->qsmask);
1122 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ 1229 raw_spin_unlock_irq(&rnp->lock);
1230#ifdef CONFIG_PROVE_RCU_DELAY
1231 if ((random32() % (rcu_num_nodes * 8)) == 0)
1232 schedule_timeout_uninterruptible(2);
1233#endif /* #ifdef CONFIG_PROVE_RCU_DELAY */
1234 cond_resched();
1123 } 1235 }
1124 1236
1125 rnp = rcu_get_root(rsp); 1237 put_online_cpus();
1126 raw_spin_lock(&rnp->lock); /* irqs already disabled. */ 1238 return 1;
1127 rsp->fqs_state = RCU_SIGNAL_INIT; /* force_quiescent_state now OK. */
1128 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
1129 raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
1130} 1239}
1131 1240
1132/* 1241/*
1133 * Report a full set of quiescent states to the specified rcu_state 1242 * Do one round of quiescent-state forcing.
1134 * data structure. This involves cleaning up after the prior grace
1135 * period and letting rcu_start_gp() start up the next grace period
1136 * if one is needed. Note that the caller must hold rnp->lock, as
1137 * required by rcu_start_gp(), which will release it.
1138 */ 1243 */
1139static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags) 1244int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
1140 __releases(rcu_get_root(rsp)->lock)
1141{ 1245{
1142 unsigned long gp_duration; 1246 int fqs_state = fqs_state_in;
1143 struct rcu_node *rnp = rcu_get_root(rsp); 1247 struct rcu_node *rnp = rcu_get_root(rsp);
1144 struct rcu_data *rdp = this_cpu_ptr(rsp->rda);
1145 1248
1146 WARN_ON_ONCE(!rcu_gp_in_progress(rsp)); 1249 rsp->n_force_qs++;
1250 if (fqs_state == RCU_SAVE_DYNTICK) {
1251 /* Collect dyntick-idle snapshots. */
1252 force_qs_rnp(rsp, dyntick_save_progress_counter);
1253 fqs_state = RCU_FORCE_QS;
1254 } else {
1255 /* Handle dyntick-idle and offline CPUs. */
1256 force_qs_rnp(rsp, rcu_implicit_dynticks_qs);
1257 }
1258 /* Clear flag to prevent immediate re-entry. */
1259 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
1260 raw_spin_lock_irq(&rnp->lock);
1261 rsp->gp_flags &= ~RCU_GP_FLAG_FQS;
1262 raw_spin_unlock_irq(&rnp->lock);
1263 }
1264 return fqs_state;
1265}
1147 1266
1148 /* 1267/*
1149 * Ensure that all grace-period and pre-grace-period activity 1268 * Clean up after the old grace period.
1150 * is seen before the assignment to rsp->completed. 1269 */
1151 */ 1270static void rcu_gp_cleanup(struct rcu_state *rsp)
1152 smp_mb(); /* See above block comment. */ 1271{
1272 unsigned long gp_duration;
1273 struct rcu_data *rdp;
1274 struct rcu_node *rnp = rcu_get_root(rsp);
1275
1276 raw_spin_lock_irq(&rnp->lock);
1153 gp_duration = jiffies - rsp->gp_start; 1277 gp_duration = jiffies - rsp->gp_start;
1154 if (gp_duration > rsp->gp_max) 1278 if (gp_duration > rsp->gp_max)
1155 rsp->gp_max = gp_duration; 1279 rsp->gp_max = gp_duration;
@@ -1161,35 +1285,149 @@ static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags)
1161 * they can do to advance the grace period. It is therefore 1285 * they can do to advance the grace period. It is therefore
1162 * safe for us to drop the lock in order to mark the grace 1286 * safe for us to drop the lock in order to mark the grace
1163 * period as completed in all of the rcu_node structures. 1287 * period as completed in all of the rcu_node structures.
1164 *
1165 * But if this CPU needs another grace period, it will take
1166 * care of this while initializing the next grace period.
1167 * We use RCU_WAIT_TAIL instead of the usual RCU_DONE_TAIL
1168 * because the callbacks have not yet been advanced: Those
1169 * callbacks are waiting on the grace period that just now
1170 * completed.
1171 */ 1288 */
1172 if (*rdp->nxttail[RCU_WAIT_TAIL] == NULL) { 1289 raw_spin_unlock_irq(&rnp->lock);
1173 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
1174 1290
1175 /* 1291 /*
1176 * Propagate new ->completed value to rcu_node structures 1292 * Propagate new ->completed value to rcu_node structures so
1177 * so that other CPUs don't have to wait until the start 1293 * that other CPUs don't have to wait until the start of the next
1178 * of the next grace period to process their callbacks. 1294 * grace period to process their callbacks. This also avoids
1179 */ 1295 * some nasty RCU grace-period initialization races by forcing
1180 rcu_for_each_node_breadth_first(rsp, rnp) { 1296 * the end of the current grace period to be completely recorded in
1181 raw_spin_lock(&rnp->lock); /* irqs already disabled. */ 1297 * all of the rcu_node structures before the beginning of the next
1182 rnp->completed = rsp->gpnum; 1298 * grace period is recorded in any of the rcu_node structures.
1183 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ 1299 */
1184 } 1300 rcu_for_each_node_breadth_first(rsp, rnp) {
1185 rnp = rcu_get_root(rsp); 1301 raw_spin_lock_irq(&rnp->lock);
1186 raw_spin_lock(&rnp->lock); /* irqs already disabled. */ 1302 rnp->completed = rsp->gpnum;
1303 raw_spin_unlock_irq(&rnp->lock);
1304 cond_resched();
1187 } 1305 }
1306 rnp = rcu_get_root(rsp);
1307 raw_spin_lock_irq(&rnp->lock);
1188 1308
1189 rsp->completed = rsp->gpnum; /* Declare the grace period complete. */ 1309 rsp->completed = rsp->gpnum; /* Declare grace period done. */
1190 trace_rcu_grace_period(rsp->name, rsp->completed, "end"); 1310 trace_rcu_grace_period(rsp->name, rsp->completed, "end");
1191 rsp->fqs_state = RCU_GP_IDLE; 1311 rsp->fqs_state = RCU_GP_IDLE;
1192 rcu_start_gp(rsp, flags); /* releases root node's rnp->lock. */ 1312 rdp = this_cpu_ptr(rsp->rda);
1313 if (cpu_needs_another_gp(rsp, rdp))
1314 rsp->gp_flags = 1;
1315 raw_spin_unlock_irq(&rnp->lock);
1316}
1317
1318/*
1319 * Body of kthread that handles grace periods.
1320 */
1321static int __noreturn rcu_gp_kthread(void *arg)
1322{
1323 int fqs_state;
1324 unsigned long j;
1325 int ret;
1326 struct rcu_state *rsp = arg;
1327 struct rcu_node *rnp = rcu_get_root(rsp);
1328
1329 for (;;) {
1330
1331 /* Handle grace-period start. */
1332 for (;;) {
1333 wait_event_interruptible(rsp->gp_wq,
1334 rsp->gp_flags &
1335 RCU_GP_FLAG_INIT);
1336 if ((rsp->gp_flags & RCU_GP_FLAG_INIT) &&
1337 rcu_gp_init(rsp))
1338 break;
1339 cond_resched();
1340 flush_signals(current);
1341 }
1342
1343 /* Handle quiescent-state forcing. */
1344 fqs_state = RCU_SAVE_DYNTICK;
1345 j = jiffies_till_first_fqs;
1346 if (j > HZ) {
1347 j = HZ;
1348 jiffies_till_first_fqs = HZ;
1349 }
1350 for (;;) {
1351 rsp->jiffies_force_qs = jiffies + j;
1352 ret = wait_event_interruptible_timeout(rsp->gp_wq,
1353 (rsp->gp_flags & RCU_GP_FLAG_FQS) ||
1354 (!ACCESS_ONCE(rnp->qsmask) &&
1355 !rcu_preempt_blocked_readers_cgp(rnp)),
1356 j);
1357 /* If grace period done, leave loop. */
1358 if (!ACCESS_ONCE(rnp->qsmask) &&
1359 !rcu_preempt_blocked_readers_cgp(rnp))
1360 break;
1361 /* If time for quiescent-state forcing, do it. */
1362 if (ret == 0 || (rsp->gp_flags & RCU_GP_FLAG_FQS)) {
1363 fqs_state = rcu_gp_fqs(rsp, fqs_state);
1364 cond_resched();
1365 } else {
1366 /* Deal with stray signal. */
1367 cond_resched();
1368 flush_signals(current);
1369 }
1370 j = jiffies_till_next_fqs;
1371 if (j > HZ) {
1372 j = HZ;
1373 jiffies_till_next_fqs = HZ;
1374 } else if (j < 1) {
1375 j = 1;
1376 jiffies_till_next_fqs = 1;
1377 }
1378 }
1379
1380 /* Handle grace-period end. */
1381 rcu_gp_cleanup(rsp);
1382 }
1383}
1384
1385/*
1386 * Start a new RCU grace period if warranted, re-initializing the hierarchy
1387 * in preparation for detecting the next grace period. The caller must hold
1388 * the root node's ->lock, which is released before return. Hard irqs must
1389 * be disabled.
1390 *
1391 * Note that it is legal for a dying CPU (which is marked as offline) to
1392 * invoke this function. This can happen when the dying CPU reports its
1393 * quiescent state.
1394 */
1395static void
1396rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
1397 __releases(rcu_get_root(rsp)->lock)
1398{
1399 struct rcu_data *rdp = this_cpu_ptr(rsp->rda);
1400 struct rcu_node *rnp = rcu_get_root(rsp);
1401
1402 if (!rsp->gp_kthread ||
1403 !cpu_needs_another_gp(rsp, rdp)) {
1404 /*
1405 * Either we have not yet spawned the grace-period
1406 * task or this CPU does not need another grace period.
1407 * Either way, don't start a new grace period.
1408 */
1409 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1410 return;
1411 }
1412
1413 rsp->gp_flags = RCU_GP_FLAG_INIT;
1414 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1415 wake_up(&rsp->gp_wq);
1416}
1417
1418/*
1419 * Report a full set of quiescent states to the specified rcu_state
1420 * data structure. This involves cleaning up after the prior grace
1421 * period and letting rcu_start_gp() start up the next grace period
1422 * if one is needed. Note that the caller must hold rnp->lock, as
1423 * required by rcu_start_gp(), which will release it.
1424 */
1425static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags)
1426 __releases(rcu_get_root(rsp)->lock)
1427{
1428 WARN_ON_ONCE(!rcu_gp_in_progress(rsp));
1429 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
1430 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
1193} 1431}
1194 1432
1195/* 1433/*
@@ -1258,7 +1496,7 @@ rcu_report_qs_rnp(unsigned long mask, struct rcu_state *rsp,
1258 * based on quiescent states detected in an earlier grace period! 1496 * based on quiescent states detected in an earlier grace period!
1259 */ 1497 */
1260static void 1498static void
1261rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long lastgp) 1499rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp)
1262{ 1500{
1263 unsigned long flags; 1501 unsigned long flags;
1264 unsigned long mask; 1502 unsigned long mask;
@@ -1266,7 +1504,8 @@ rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long las
1266 1504
1267 rnp = rdp->mynode; 1505 rnp = rdp->mynode;
1268 raw_spin_lock_irqsave(&rnp->lock, flags); 1506 raw_spin_lock_irqsave(&rnp->lock, flags);
1269 if (lastgp != rnp->gpnum || rnp->completed == rnp->gpnum) { 1507 if (rdp->passed_quiesce == 0 || rdp->gpnum != rnp->gpnum ||
1508 rnp->completed == rnp->gpnum) {
1270 1509
1271 /* 1510 /*
1272 * The grace period in which this quiescent state was 1511 * The grace period in which this quiescent state was
@@ -1325,7 +1564,7 @@ rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp)
1325 * Tell RCU we are done (but rcu_report_qs_rdp() will be the 1564 * Tell RCU we are done (but rcu_report_qs_rdp() will be the
1326 * judge of that). 1565 * judge of that).
1327 */ 1566 */
1328 rcu_report_qs_rdp(rdp->cpu, rsp, rdp, rdp->passed_quiesce_gpnum); 1567 rcu_report_qs_rdp(rdp->cpu, rsp, rdp);
1329} 1568}
1330 1569
1331#ifdef CONFIG_HOTPLUG_CPU 1570#ifdef CONFIG_HOTPLUG_CPU
@@ -1390,17 +1629,6 @@ static void rcu_adopt_orphan_cbs(struct rcu_state *rsp)
1390 int i; 1629 int i;
1391 struct rcu_data *rdp = __this_cpu_ptr(rsp->rda); 1630 struct rcu_data *rdp = __this_cpu_ptr(rsp->rda);
1392 1631
1393 /*
1394 * If there is an rcu_barrier() operation in progress, then
1395 * only the task doing that operation is permitted to adopt
1396 * callbacks. To do otherwise breaks rcu_barrier() and friends
1397 * by causing them to fail to wait for the callbacks in the
1398 * orphanage.
1399 */
1400 if (rsp->rcu_barrier_in_progress &&
1401 rsp->rcu_barrier_in_progress != current)
1402 return;
1403
1404 /* Do the accounting first. */ 1632 /* Do the accounting first. */
1405 rdp->qlen_lazy += rsp->qlen_lazy; 1633 rdp->qlen_lazy += rsp->qlen_lazy;
1406 rdp->qlen += rsp->qlen; 1634 rdp->qlen += rsp->qlen;
@@ -1455,9 +1683,8 @@ static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
1455 * The CPU has been completely removed, and some other CPU is reporting 1683 * The CPU has been completely removed, and some other CPU is reporting
1456 * this fact from process context. Do the remainder of the cleanup, 1684 * this fact from process context. Do the remainder of the cleanup,
1457 * including orphaning the outgoing CPU's RCU callbacks, and also 1685 * including orphaning the outgoing CPU's RCU callbacks, and also
1458 * adopting them, if there is no _rcu_barrier() instance running. 1686 * adopting them. There can only be one CPU hotplug operation at a time,
1459 * There can only be one CPU hotplug operation at a time, so no other 1687 * so no other CPU can be attempting to update rcu_cpu_kthread_task.
1460 * CPU can be attempting to update rcu_cpu_kthread_task.
1461 */ 1688 */
1462static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp) 1689static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
1463{ 1690{
@@ -1468,8 +1695,7 @@ static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
1468 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */ 1695 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
1469 1696
1470 /* Adjust any no-longer-needed kthreads. */ 1697 /* Adjust any no-longer-needed kthreads. */
1471 rcu_stop_cpu_kthread(cpu); 1698 rcu_boost_kthread_setaffinity(rnp, -1);
1472 rcu_node_kthread_setaffinity(rnp, -1);
1473 1699
1474 /* Remove the dead CPU from the bitmasks in the rcu_node hierarchy. */ 1700 /* Remove the dead CPU from the bitmasks in the rcu_node hierarchy. */
1475 1701
@@ -1515,14 +1741,13 @@ static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
1515 WARN_ONCE(rdp->qlen != 0 || rdp->nxtlist != NULL, 1741 WARN_ONCE(rdp->qlen != 0 || rdp->nxtlist != NULL,
1516 "rcu_cleanup_dead_cpu: Callbacks on offline CPU %d: qlen=%lu, nxtlist=%p\n", 1742 "rcu_cleanup_dead_cpu: Callbacks on offline CPU %d: qlen=%lu, nxtlist=%p\n",
1517 cpu, rdp->qlen, rdp->nxtlist); 1743 cpu, rdp->qlen, rdp->nxtlist);
1744 init_callback_list(rdp);
1745 /* Disallow further callbacks on this CPU. */
1746 rdp->nxttail[RCU_NEXT_TAIL] = NULL;
1518} 1747}
1519 1748
1520#else /* #ifdef CONFIG_HOTPLUG_CPU */ 1749#else /* #ifdef CONFIG_HOTPLUG_CPU */
1521 1750
1522static void rcu_adopt_orphan_cbs(struct rcu_state *rsp)
1523{
1524}
1525
1526static void rcu_cleanup_dying_cpu(struct rcu_state *rsp) 1751static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
1527{ 1752{
1528} 1753}
@@ -1687,6 +1912,7 @@ static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *))
1687 struct rcu_node *rnp; 1912 struct rcu_node *rnp;
1688 1913
1689 rcu_for_each_leaf_node(rsp, rnp) { 1914 rcu_for_each_leaf_node(rsp, rnp) {
1915 cond_resched();
1690 mask = 0; 1916 mask = 0;
1691 raw_spin_lock_irqsave(&rnp->lock, flags); 1917 raw_spin_lock_irqsave(&rnp->lock, flags);
1692 if (!rcu_gp_in_progress(rsp)) { 1918 if (!rcu_gp_in_progress(rsp)) {
@@ -1723,72 +1949,39 @@ static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *))
1723 * Force quiescent states on reluctant CPUs, and also detect which 1949 * Force quiescent states on reluctant CPUs, and also detect which
1724 * CPUs are in dyntick-idle mode. 1950 * CPUs are in dyntick-idle mode.
1725 */ 1951 */
1726static void force_quiescent_state(struct rcu_state *rsp, int relaxed) 1952static void force_quiescent_state(struct rcu_state *rsp)
1727{ 1953{
1728 unsigned long flags; 1954 unsigned long flags;
1729 struct rcu_node *rnp = rcu_get_root(rsp); 1955 bool ret;
1730 1956 struct rcu_node *rnp;
1731 trace_rcu_utilization("Start fqs"); 1957 struct rcu_node *rnp_old = NULL;
1732 if (!rcu_gp_in_progress(rsp)) { 1958
1733 trace_rcu_utilization("End fqs"); 1959 /* Funnel through hierarchy to reduce memory contention. */
1734 return; /* No grace period in progress, nothing to force. */ 1960 rnp = per_cpu_ptr(rsp->rda, raw_smp_processor_id())->mynode;
1735 } 1961 for (; rnp != NULL; rnp = rnp->parent) {
1736 if (!raw_spin_trylock_irqsave(&rsp->fqslock, flags)) { 1962 ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
1737 rsp->n_force_qs_lh++; /* Inexact, can lose counts. Tough! */ 1963 !raw_spin_trylock(&rnp->fqslock);
1738 trace_rcu_utilization("End fqs"); 1964 if (rnp_old != NULL)
1739 return; /* Someone else is already on the job. */ 1965 raw_spin_unlock(&rnp_old->fqslock);
1740 } 1966 if (ret) {
1741 if (relaxed && ULONG_CMP_GE(rsp->jiffies_force_qs, jiffies)) 1967 rsp->n_force_qs_lh++;
1742 goto unlock_fqs_ret; /* no emergency and done recently. */ 1968 return;
1743 rsp->n_force_qs++; 1969 }
1744 raw_spin_lock(&rnp->lock); /* irqs already disabled */ 1970 rnp_old = rnp;
1745 rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS;
1746 if(!rcu_gp_in_progress(rsp)) {
1747 rsp->n_force_qs_ngp++;
1748 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
1749 goto unlock_fqs_ret; /* no GP in progress, time updated. */
1750 }
1751 rsp->fqs_active = 1;
1752 switch (rsp->fqs_state) {
1753 case RCU_GP_IDLE:
1754 case RCU_GP_INIT:
1755
1756 break; /* grace period idle or initializing, ignore. */
1757
1758 case RCU_SAVE_DYNTICK:
1759
1760 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
1761
1762 /* Record dyntick-idle state. */
1763 force_qs_rnp(rsp, dyntick_save_progress_counter);
1764 raw_spin_lock(&rnp->lock); /* irqs already disabled */
1765 if (rcu_gp_in_progress(rsp))
1766 rsp->fqs_state = RCU_FORCE_QS;
1767 break;
1768
1769 case RCU_FORCE_QS:
1770
1771 /* Check dyntick-idle state, send IPI to laggarts. */
1772 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
1773 force_qs_rnp(rsp, rcu_implicit_dynticks_qs);
1774
1775 /* Leave state in case more forcing is required. */
1776
1777 raw_spin_lock(&rnp->lock); /* irqs already disabled */
1778 break;
1779 } 1971 }
1780 rsp->fqs_active = 0; 1972 /* rnp_old == rcu_get_root(rsp), rnp == NULL. */
1781 if (rsp->fqs_need_gp) { 1973
1782 raw_spin_unlock(&rsp->fqslock); /* irqs remain disabled */ 1974 /* Reached the root of the rcu_node tree, acquire lock. */
1783 rsp->fqs_need_gp = 0; 1975 raw_spin_lock_irqsave(&rnp_old->lock, flags);
1784 rcu_start_gp(rsp, flags); /* releases rnp->lock */ 1976 raw_spin_unlock(&rnp_old->fqslock);
1785 trace_rcu_utilization("End fqs"); 1977 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
1786 return; 1978 rsp->n_force_qs_lh++;
1979 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
1980 return; /* Someone beat us to it. */
1787 } 1981 }
1788 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */ 1982 rsp->gp_flags |= RCU_GP_FLAG_FQS;
1789unlock_fqs_ret: 1983 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
1790 raw_spin_unlock_irqrestore(&rsp->fqslock, flags); 1984 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
1791 trace_rcu_utilization("End fqs");
1792} 1985}
1793 1986
1794/* 1987/*
@@ -1805,13 +1998,6 @@ __rcu_process_callbacks(struct rcu_state *rsp)
1805 WARN_ON_ONCE(rdp->beenonline == 0); 1998 WARN_ON_ONCE(rdp->beenonline == 0);
1806 1999
1807 /* 2000 /*
1808 * If an RCU GP has gone long enough, go check for dyntick
1809 * idle CPUs and, if needed, send resched IPIs.
1810 */
1811 if (ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs), jiffies))
1812 force_quiescent_state(rsp, 1);
1813
1814 /*
1815 * Advance callbacks in response to end of earlier grace 2001 * Advance callbacks in response to end of earlier grace
1816 * period that some other CPU ended. 2002 * period that some other CPU ended.
1817 */ 2003 */
@@ -1838,6 +2024,8 @@ static void rcu_process_callbacks(struct softirq_action *unused)
1838{ 2024{
1839 struct rcu_state *rsp; 2025 struct rcu_state *rsp;
1840 2026
2027 if (cpu_is_offline(smp_processor_id()))
2028 return;
1841 trace_rcu_utilization("Start RCU core"); 2029 trace_rcu_utilization("Start RCU core");
1842 for_each_rcu_flavor(rsp) 2030 for_each_rcu_flavor(rsp)
1843 __rcu_process_callbacks(rsp); 2031 __rcu_process_callbacks(rsp);
@@ -1909,12 +2097,11 @@ static void __call_rcu_core(struct rcu_state *rsp, struct rcu_data *rdp,
1909 rdp->blimit = LONG_MAX; 2097 rdp->blimit = LONG_MAX;
1910 if (rsp->n_force_qs == rdp->n_force_qs_snap && 2098 if (rsp->n_force_qs == rdp->n_force_qs_snap &&
1911 *rdp->nxttail[RCU_DONE_TAIL] != head) 2099 *rdp->nxttail[RCU_DONE_TAIL] != head)
1912 force_quiescent_state(rsp, 0); 2100 force_quiescent_state(rsp);
1913 rdp->n_force_qs_snap = rsp->n_force_qs; 2101 rdp->n_force_qs_snap = rsp->n_force_qs;
1914 rdp->qlen_last_fqs_check = rdp->qlen; 2102 rdp->qlen_last_fqs_check = rdp->qlen;
1915 } 2103 }
1916 } else if (ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs), jiffies)) 2104 }
1917 force_quiescent_state(rsp, 1);
1918} 2105}
1919 2106
1920static void 2107static void
@@ -1929,8 +2116,6 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
1929 head->func = func; 2116 head->func = func;
1930 head->next = NULL; 2117 head->next = NULL;
1931 2118
1932 smp_mb(); /* Ensure RCU update seen before callback registry. */
1933
1934 /* 2119 /*
1935 * Opportunistically note grace-period endings and beginnings. 2120 * Opportunistically note grace-period endings and beginnings.
1936 * Note that we might see a beginning right after we see an 2121 * Note that we might see a beginning right after we see an
@@ -1941,6 +2126,12 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
1941 rdp = this_cpu_ptr(rsp->rda); 2126 rdp = this_cpu_ptr(rsp->rda);
1942 2127
1943 /* Add the callback to our list. */ 2128 /* Add the callback to our list. */
2129 if (unlikely(rdp->nxttail[RCU_NEXT_TAIL] == NULL)) {
2130 /* _call_rcu() is illegal on offline CPU; leak the callback. */
2131 WARN_ON_ONCE(1);
2132 local_irq_restore(flags);
2133 return;
2134 }
1944 ACCESS_ONCE(rdp->qlen)++; 2135 ACCESS_ONCE(rdp->qlen)++;
1945 if (lazy) 2136 if (lazy)
1946 rdp->qlen_lazy++; 2137 rdp->qlen_lazy++;
@@ -2195,17 +2386,7 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
2195 /* Is the RCU core waiting for a quiescent state from this CPU? */ 2386 /* Is the RCU core waiting for a quiescent state from this CPU? */
2196 if (rcu_scheduler_fully_active && 2387 if (rcu_scheduler_fully_active &&
2197 rdp->qs_pending && !rdp->passed_quiesce) { 2388 rdp->qs_pending && !rdp->passed_quiesce) {
2198
2199 /*
2200 * If force_quiescent_state() coming soon and this CPU
2201 * needs a quiescent state, and this is either RCU-sched
2202 * or RCU-bh, force a local reschedule.
2203 */
2204 rdp->n_rp_qs_pending++; 2389 rdp->n_rp_qs_pending++;
2205 if (!rdp->preemptible &&
2206 ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs) - 1,
2207 jiffies))
2208 set_need_resched();
2209 } else if (rdp->qs_pending && rdp->passed_quiesce) { 2390 } else if (rdp->qs_pending && rdp->passed_quiesce) {
2210 rdp->n_rp_report_qs++; 2391 rdp->n_rp_report_qs++;
2211 return 1; 2392 return 1;
@@ -2235,13 +2416,6 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
2235 return 1; 2416 return 1;
2236 } 2417 }
2237 2418
2238 /* Has an RCU GP gone long enough to send resched IPIs &c? */
2239 if (rcu_gp_in_progress(rsp) &&
2240 ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs), jiffies)) {
2241 rdp->n_rp_need_fqs++;
2242 return 1;
2243 }
2244
2245 /* nothing to do */ 2419 /* nothing to do */
2246 rdp->n_rp_need_nothing++; 2420 rdp->n_rp_need_nothing++;
2247 return 0; 2421 return 0;
@@ -2326,13 +2500,10 @@ static void rcu_barrier_func(void *type)
2326static void _rcu_barrier(struct rcu_state *rsp) 2500static void _rcu_barrier(struct rcu_state *rsp)
2327{ 2501{
2328 int cpu; 2502 int cpu;
2329 unsigned long flags;
2330 struct rcu_data *rdp; 2503 struct rcu_data *rdp;
2331 struct rcu_data rd;
2332 unsigned long snap = ACCESS_ONCE(rsp->n_barrier_done); 2504 unsigned long snap = ACCESS_ONCE(rsp->n_barrier_done);
2333 unsigned long snap_done; 2505 unsigned long snap_done;
2334 2506
2335 init_rcu_head_on_stack(&rd.barrier_head);
2336 _rcu_barrier_trace(rsp, "Begin", -1, snap); 2507 _rcu_barrier_trace(rsp, "Begin", -1, snap);
2337 2508
2338 /* Take mutex to serialize concurrent rcu_barrier() requests. */ 2509 /* Take mutex to serialize concurrent rcu_barrier() requests. */
@@ -2372,70 +2543,30 @@ static void _rcu_barrier(struct rcu_state *rsp)
2372 /* 2543 /*
2373 * Initialize the count to one rather than to zero in order to 2544 * Initialize the count to one rather than to zero in order to
2374 * avoid a too-soon return to zero in case of a short grace period 2545 * avoid a too-soon return to zero in case of a short grace period
2375 * (or preemption of this task). Also flag this task as doing 2546 * (or preemption of this task). Exclude CPU-hotplug operations
2376 * an rcu_barrier(). This will prevent anyone else from adopting 2547 * to ensure that no offline CPU has callbacks queued.
2377 * orphaned callbacks, which could cause otherwise failure if a
2378 * CPU went offline and quickly came back online. To see this,
2379 * consider the following sequence of events:
2380 *
2381 * 1. We cause CPU 0 to post an rcu_barrier_callback() callback.
2382 * 2. CPU 1 goes offline, orphaning its callbacks.
2383 * 3. CPU 0 adopts CPU 1's orphaned callbacks.
2384 * 4. CPU 1 comes back online.
2385 * 5. We cause CPU 1 to post an rcu_barrier_callback() callback.
2386 * 6. Both rcu_barrier_callback() callbacks are invoked, awakening
2387 * us -- but before CPU 1's orphaned callbacks are invoked!!!
2388 */ 2548 */
2389 init_completion(&rsp->barrier_completion); 2549 init_completion(&rsp->barrier_completion);
2390 atomic_set(&rsp->barrier_cpu_count, 1); 2550 atomic_set(&rsp->barrier_cpu_count, 1);
2391 raw_spin_lock_irqsave(&rsp->onofflock, flags); 2551 get_online_cpus();
2392 rsp->rcu_barrier_in_progress = current;
2393 raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
2394 2552
2395 /* 2553 /*
2396 * Force every CPU with callbacks to register a new callback 2554 * Force each CPU with callbacks to register a new callback.
2397 * that will tell us when all the preceding callbacks have 2555 * When that callback is invoked, we will know that all of the
2398 * been invoked. If an offline CPU has callbacks, wait for 2556 * corresponding CPU's preceding callbacks have been invoked.
2399 * it to either come back online or to finish orphaning those
2400 * callbacks.
2401 */ 2557 */
2402 for_each_possible_cpu(cpu) { 2558 for_each_online_cpu(cpu) {
2403 preempt_disable();
2404 rdp = per_cpu_ptr(rsp->rda, cpu); 2559 rdp = per_cpu_ptr(rsp->rda, cpu);
2405 if (cpu_is_offline(cpu)) { 2560 if (ACCESS_ONCE(rdp->qlen)) {
2406 _rcu_barrier_trace(rsp, "Offline", cpu,
2407 rsp->n_barrier_done);
2408 preempt_enable();
2409 while (cpu_is_offline(cpu) && ACCESS_ONCE(rdp->qlen))
2410 schedule_timeout_interruptible(1);
2411 } else if (ACCESS_ONCE(rdp->qlen)) {
2412 _rcu_barrier_trace(rsp, "OnlineQ", cpu, 2561 _rcu_barrier_trace(rsp, "OnlineQ", cpu,
2413 rsp->n_barrier_done); 2562 rsp->n_barrier_done);
2414 smp_call_function_single(cpu, rcu_barrier_func, rsp, 1); 2563 smp_call_function_single(cpu, rcu_barrier_func, rsp, 1);
2415 preempt_enable();
2416 } else { 2564 } else {
2417 _rcu_barrier_trace(rsp, "OnlineNQ", cpu, 2565 _rcu_barrier_trace(rsp, "OnlineNQ", cpu,
2418 rsp->n_barrier_done); 2566 rsp->n_barrier_done);
2419 preempt_enable();
2420 } 2567 }
2421 } 2568 }
2422 2569 put_online_cpus();
2423 /*
2424 * Now that all online CPUs have rcu_barrier_callback() callbacks
2425 * posted, we can adopt all of the orphaned callbacks and place
2426 * an rcu_barrier_callback() callback after them. When that is done,
2427 * we are guaranteed to have an rcu_barrier_callback() callback
2428 * following every callback that could possibly have been
2429 * registered before _rcu_barrier() was called.
2430 */
2431 raw_spin_lock_irqsave(&rsp->onofflock, flags);
2432 rcu_adopt_orphan_cbs(rsp);
2433 rsp->rcu_barrier_in_progress = NULL;
2434 raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
2435 atomic_inc(&rsp->barrier_cpu_count);
2436 smp_mb__after_atomic_inc(); /* Ensure atomic_inc() before callback. */
2437 rd.rsp = rsp;
2438 rsp->call(&rd.barrier_head, rcu_barrier_callback);
2439 2570
2440 /* 2571 /*
2441 * Now that we have an rcu_barrier_callback() callback on each 2572 * Now that we have an rcu_barrier_callback() callback on each
@@ -2456,8 +2587,6 @@ static void _rcu_barrier(struct rcu_state *rsp)
2456 2587
2457 /* Other rcu_barrier() invocations can now safely proceed. */ 2588 /* Other rcu_barrier() invocations can now safely proceed. */
2458 mutex_unlock(&rsp->barrier_mutex); 2589 mutex_unlock(&rsp->barrier_mutex);
2459
2460 destroy_rcu_head_on_stack(&rd.barrier_head);
2461} 2590}
2462 2591
2463/** 2592/**
@@ -2497,6 +2626,9 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
2497 rdp->dynticks = &per_cpu(rcu_dynticks, cpu); 2626 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
2498 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE); 2627 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
2499 WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1); 2628 WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
2629#ifdef CONFIG_RCU_USER_QS
2630 WARN_ON_ONCE(rdp->dynticks->in_user);
2631#endif
2500 rdp->cpu = cpu; 2632 rdp->cpu = cpu;
2501 rdp->rsp = rsp; 2633 rdp->rsp = rsp;
2502 raw_spin_unlock_irqrestore(&rnp->lock, flags); 2634 raw_spin_unlock_irqrestore(&rnp->lock, flags);
@@ -2523,6 +2655,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
2523 rdp->qlen_last_fqs_check = 0; 2655 rdp->qlen_last_fqs_check = 0;
2524 rdp->n_force_qs_snap = rsp->n_force_qs; 2656 rdp->n_force_qs_snap = rsp->n_force_qs;
2525 rdp->blimit = blimit; 2657 rdp->blimit = blimit;
2658 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
2526 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE; 2659 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
2527 atomic_set(&rdp->dynticks->dynticks, 2660 atomic_set(&rdp->dynticks->dynticks,
2528 (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1); 2661 (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
@@ -2555,7 +2688,6 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
2555 rdp->completed = rnp->completed; 2688 rdp->completed = rnp->completed;
2556 rdp->passed_quiesce = 0; 2689 rdp->passed_quiesce = 0;
2557 rdp->qs_pending = 0; 2690 rdp->qs_pending = 0;
2558 rdp->passed_quiesce_gpnum = rnp->gpnum - 1;
2559 trace_rcu_grace_period(rsp->name, rdp->gpnum, "cpuonl"); 2691 trace_rcu_grace_period(rsp->name, rdp->gpnum, "cpuonl");
2560 } 2692 }
2561 raw_spin_unlock(&rnp->lock); /* irqs already disabled. */ 2693 raw_spin_unlock(&rnp->lock); /* irqs already disabled. */
@@ -2594,12 +2726,10 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
2594 break; 2726 break;
2595 case CPU_ONLINE: 2727 case CPU_ONLINE:
2596 case CPU_DOWN_FAILED: 2728 case CPU_DOWN_FAILED:
2597 rcu_node_kthread_setaffinity(rnp, -1); 2729 rcu_boost_kthread_setaffinity(rnp, -1);
2598 rcu_cpu_kthread_setrt(cpu, 1);
2599 break; 2730 break;
2600 case CPU_DOWN_PREPARE: 2731 case CPU_DOWN_PREPARE:
2601 rcu_node_kthread_setaffinity(rnp, cpu); 2732 rcu_boost_kthread_setaffinity(rnp, cpu);
2602 rcu_cpu_kthread_setrt(cpu, 0);
2603 break; 2733 break;
2604 case CPU_DYING: 2734 case CPU_DYING:
2605 case CPU_DYING_FROZEN: 2735 case CPU_DYING_FROZEN:
@@ -2627,6 +2757,28 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
2627} 2757}
2628 2758
2629/* 2759/*
2760 * Spawn the kthread that handles this RCU flavor's grace periods.
2761 */
2762static int __init rcu_spawn_gp_kthread(void)
2763{
2764 unsigned long flags;
2765 struct rcu_node *rnp;
2766 struct rcu_state *rsp;
2767 struct task_struct *t;
2768
2769 for_each_rcu_flavor(rsp) {
2770 t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
2771 BUG_ON(IS_ERR(t));
2772 rnp = rcu_get_root(rsp);
2773 raw_spin_lock_irqsave(&rnp->lock, flags);
2774 rsp->gp_kthread = t;
2775 raw_spin_unlock_irqrestore(&rnp->lock, flags);
2776 }
2777 return 0;
2778}
2779early_initcall(rcu_spawn_gp_kthread);
2780
2781/*
2630 * This function is invoked towards the end of the scheduler's initialization 2782 * This function is invoked towards the end of the scheduler's initialization
2631 * process. Before this is called, the idle task might contain 2783 * process. Before this is called, the idle task might contain
2632 * RCU read-side critical sections (during which time, this idle 2784 * RCU read-side critical sections (during which time, this idle
@@ -2661,7 +2813,7 @@ static void __init rcu_init_levelspread(struct rcu_state *rsp)
2661 int cprv; 2813 int cprv;
2662 int i; 2814 int i;
2663 2815
2664 cprv = NR_CPUS; 2816 cprv = nr_cpu_ids;
2665 for (i = rcu_num_lvls - 1; i >= 0; i--) { 2817 for (i = rcu_num_lvls - 1; i >= 0; i--) {
2666 ccur = rsp->levelcnt[i]; 2818 ccur = rsp->levelcnt[i];
2667 rsp->levelspread[i] = (cprv + ccur - 1) / ccur; 2819 rsp->levelspread[i] = (cprv + ccur - 1) / ccur;
@@ -2676,10 +2828,14 @@ static void __init rcu_init_levelspread(struct rcu_state *rsp)
2676static void __init rcu_init_one(struct rcu_state *rsp, 2828static void __init rcu_init_one(struct rcu_state *rsp,
2677 struct rcu_data __percpu *rda) 2829 struct rcu_data __percpu *rda)
2678{ 2830{
2679 static char *buf[] = { "rcu_node_level_0", 2831 static char *buf[] = { "rcu_node_0",
2680 "rcu_node_level_1", 2832 "rcu_node_1",
2681 "rcu_node_level_2", 2833 "rcu_node_2",
2682 "rcu_node_level_3" }; /* Match MAX_RCU_LVLS */ 2834 "rcu_node_3" }; /* Match MAX_RCU_LVLS */
2835 static char *fqs[] = { "rcu_node_fqs_0",
2836 "rcu_node_fqs_1",
2837 "rcu_node_fqs_2",
2838 "rcu_node_fqs_3" }; /* Match MAX_RCU_LVLS */
2683 int cpustride = 1; 2839 int cpustride = 1;
2684 int i; 2840 int i;
2685 int j; 2841 int j;
@@ -2704,7 +2860,11 @@ static void __init rcu_init_one(struct rcu_state *rsp,
2704 raw_spin_lock_init(&rnp->lock); 2860 raw_spin_lock_init(&rnp->lock);
2705 lockdep_set_class_and_name(&rnp->lock, 2861 lockdep_set_class_and_name(&rnp->lock,
2706 &rcu_node_class[i], buf[i]); 2862 &rcu_node_class[i], buf[i]);
2707 rnp->gpnum = 0; 2863 raw_spin_lock_init(&rnp->fqslock);
2864 lockdep_set_class_and_name(&rnp->fqslock,
2865 &rcu_fqs_class[i], fqs[i]);
2866 rnp->gpnum = rsp->gpnum;
2867 rnp->completed = rsp->completed;
2708 rnp->qsmask = 0; 2868 rnp->qsmask = 0;
2709 rnp->qsmaskinit = 0; 2869 rnp->qsmaskinit = 0;
2710 rnp->grplo = j * cpustride; 2870 rnp->grplo = j * cpustride;
@@ -2727,6 +2887,7 @@ static void __init rcu_init_one(struct rcu_state *rsp,
2727 } 2887 }
2728 2888
2729 rsp->rda = rda; 2889 rsp->rda = rda;
2890 init_waitqueue_head(&rsp->gp_wq);
2730 rnp = rsp->level[rcu_num_lvls - 1]; 2891 rnp = rsp->level[rcu_num_lvls - 1];
2731 for_each_possible_cpu(i) { 2892 for_each_possible_cpu(i) {
2732 while (i > rnp->grphi) 2893 while (i > rnp->grphi)
@@ -2750,7 +2911,8 @@ static void __init rcu_init_geometry(void)
2750 int rcu_capacity[MAX_RCU_LVLS + 1]; 2911 int rcu_capacity[MAX_RCU_LVLS + 1];
2751 2912
2752 /* If the compile-time values are accurate, just leave. */ 2913 /* If the compile-time values are accurate, just leave. */
2753 if (rcu_fanout_leaf == CONFIG_RCU_FANOUT_LEAF) 2914 if (rcu_fanout_leaf == CONFIG_RCU_FANOUT_LEAF &&
2915 nr_cpu_ids == NR_CPUS)
2754 return; 2916 return;
2755 2917
2756 /* 2918 /*
diff --git a/kernel/rcutree.h b/kernel/rcutree.h
index 4d29169f2124..5faf05d68326 100644
--- a/kernel/rcutree.h
+++ b/kernel/rcutree.h
@@ -102,6 +102,10 @@ struct rcu_dynticks {
102 /* idle-period nonlazy_posted snapshot. */ 102 /* idle-period nonlazy_posted snapshot. */
103 int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */ 103 int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */
104#endif /* #ifdef CONFIG_RCU_FAST_NO_HZ */ 104#endif /* #ifdef CONFIG_RCU_FAST_NO_HZ */
105#ifdef CONFIG_RCU_USER_QS
106 bool ignore_user_qs; /* Treat userspace as extended QS or not */
107 bool in_user; /* Is the CPU in userland from RCU POV? */
108#endif
105}; 109};
106 110
107/* RCU's kthread states for tracing. */ 111/* RCU's kthread states for tracing. */
@@ -196,12 +200,7 @@ struct rcu_node {
196 /* Refused to boost: not sure why, though. */ 200 /* Refused to boost: not sure why, though. */
197 /* This can happen due to race conditions. */ 201 /* This can happen due to race conditions. */
198#endif /* #ifdef CONFIG_RCU_BOOST */ 202#endif /* #ifdef CONFIG_RCU_BOOST */
199 struct task_struct *node_kthread_task; 203 raw_spinlock_t fqslock ____cacheline_internodealigned_in_smp;
200 /* kthread that takes care of this rcu_node */
201 /* structure, for example, awakening the */
202 /* per-CPU kthreads as needed. */
203 unsigned int node_kthread_status;
204 /* State of node_kthread_task for tracing. */
205} ____cacheline_internodealigned_in_smp; 204} ____cacheline_internodealigned_in_smp;
206 205
207/* 206/*
@@ -245,8 +244,6 @@ struct rcu_data {
245 /* in order to detect GP end. */ 244 /* in order to detect GP end. */
246 unsigned long gpnum; /* Highest gp number that this CPU */ 245 unsigned long gpnum; /* Highest gp number that this CPU */
247 /* is aware of having started. */ 246 /* is aware of having started. */
248 unsigned long passed_quiesce_gpnum;
249 /* gpnum at time of quiescent state. */
250 bool passed_quiesce; /* User-mode/idle loop etc. */ 247 bool passed_quiesce; /* User-mode/idle loop etc. */
251 bool qs_pending; /* Core waits for quiesc state. */ 248 bool qs_pending; /* Core waits for quiesc state. */
252 bool beenonline; /* CPU online at least once. */ 249 bool beenonline; /* CPU online at least once. */
@@ -312,11 +309,13 @@ struct rcu_data {
312 unsigned long n_rp_cpu_needs_gp; 309 unsigned long n_rp_cpu_needs_gp;
313 unsigned long n_rp_gp_completed; 310 unsigned long n_rp_gp_completed;
314 unsigned long n_rp_gp_started; 311 unsigned long n_rp_gp_started;
315 unsigned long n_rp_need_fqs;
316 unsigned long n_rp_need_nothing; 312 unsigned long n_rp_need_nothing;
317 313
318 /* 6) _rcu_barrier() callback. */ 314 /* 6) _rcu_barrier() and OOM callbacks. */
319 struct rcu_head barrier_head; 315 struct rcu_head barrier_head;
316#ifdef CONFIG_RCU_FAST_NO_HZ
317 struct rcu_head oom_head;
318#endif /* #ifdef CONFIG_RCU_FAST_NO_HZ */
320 319
321 int cpu; 320 int cpu;
322 struct rcu_state *rsp; 321 struct rcu_state *rsp;
@@ -375,20 +374,17 @@ struct rcu_state {
375 374
376 u8 fqs_state ____cacheline_internodealigned_in_smp; 375 u8 fqs_state ____cacheline_internodealigned_in_smp;
377 /* Force QS state. */ 376 /* Force QS state. */
378 u8 fqs_active; /* force_quiescent_state() */
379 /* is running. */
380 u8 fqs_need_gp; /* A CPU was prevented from */
381 /* starting a new grace */
382 /* period because */
383 /* force_quiescent_state() */
384 /* was running. */
385 u8 boost; /* Subject to priority boost. */ 377 u8 boost; /* Subject to priority boost. */
386 unsigned long gpnum; /* Current gp number. */ 378 unsigned long gpnum; /* Current gp number. */
387 unsigned long completed; /* # of last completed gp. */ 379 unsigned long completed; /* # of last completed gp. */
380 struct task_struct *gp_kthread; /* Task for grace periods. */
381 wait_queue_head_t gp_wq; /* Where GP task waits. */
382 int gp_flags; /* Commands for GP task. */
388 383
389 /* End of fields guarded by root rcu_node's lock. */ 384 /* End of fields guarded by root rcu_node's lock. */
390 385
391 raw_spinlock_t onofflock; /* exclude on/offline and */ 386 raw_spinlock_t onofflock ____cacheline_internodealigned_in_smp;
387 /* exclude on/offline and */
392 /* starting new GP. */ 388 /* starting new GP. */
393 struct rcu_head *orphan_nxtlist; /* Orphaned callbacks that */ 389 struct rcu_head *orphan_nxtlist; /* Orphaned callbacks that */
394 /* need a grace period. */ 390 /* need a grace period. */
@@ -398,16 +394,11 @@ struct rcu_state {
398 struct rcu_head **orphan_donetail; /* Tail of above. */ 394 struct rcu_head **orphan_donetail; /* Tail of above. */
399 long qlen_lazy; /* Number of lazy callbacks. */ 395 long qlen_lazy; /* Number of lazy callbacks. */
400 long qlen; /* Total number of callbacks. */ 396 long qlen; /* Total number of callbacks. */
401 struct task_struct *rcu_barrier_in_progress;
402 /* Task doing rcu_barrier(), */
403 /* or NULL if no barrier. */
404 struct mutex barrier_mutex; /* Guards barrier fields. */ 397 struct mutex barrier_mutex; /* Guards barrier fields. */
405 atomic_t barrier_cpu_count; /* # CPUs waiting on. */ 398 atomic_t barrier_cpu_count; /* # CPUs waiting on. */
406 struct completion barrier_completion; /* Wake at barrier end. */ 399 struct completion barrier_completion; /* Wake at barrier end. */
407 unsigned long n_barrier_done; /* ++ at start and end of */ 400 unsigned long n_barrier_done; /* ++ at start and end of */
408 /* _rcu_barrier(). */ 401 /* _rcu_barrier(). */
409 raw_spinlock_t fqslock; /* Only one task forcing */
410 /* quiescent states. */
411 unsigned long jiffies_force_qs; /* Time at which to invoke */ 402 unsigned long jiffies_force_qs; /* Time at which to invoke */
412 /* force_quiescent_state(). */ 403 /* force_quiescent_state(). */
413 unsigned long n_force_qs; /* Number of calls to */ 404 unsigned long n_force_qs; /* Number of calls to */
@@ -426,6 +417,10 @@ struct rcu_state {
426 struct list_head flavors; /* List of RCU flavors. */ 417 struct list_head flavors; /* List of RCU flavors. */
427}; 418};
428 419
420/* Values for rcu_state structure's gp_flags field. */
421#define RCU_GP_FLAG_INIT 0x1 /* Need grace-period initialization. */
422#define RCU_GP_FLAG_FQS 0x2 /* Need grace-period quiescent-state forcing. */
423
429extern struct list_head rcu_struct_flavors; 424extern struct list_head rcu_struct_flavors;
430#define for_each_rcu_flavor(rsp) \ 425#define for_each_rcu_flavor(rsp) \
431 list_for_each_entry((rsp), &rcu_struct_flavors, flavors) 426 list_for_each_entry((rsp), &rcu_struct_flavors, flavors)
@@ -468,7 +463,6 @@ static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp);
468#ifdef CONFIG_HOTPLUG_CPU 463#ifdef CONFIG_HOTPLUG_CPU
469static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, 464static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp,
470 unsigned long flags); 465 unsigned long flags);
471static void rcu_stop_cpu_kthread(int cpu);
472#endif /* #ifdef CONFIG_HOTPLUG_CPU */ 466#endif /* #ifdef CONFIG_HOTPLUG_CPU */
473static void rcu_print_detail_task_stall(struct rcu_state *rsp); 467static void rcu_print_detail_task_stall(struct rcu_state *rsp);
474static int rcu_print_task_stall(struct rcu_node *rnp); 468static int rcu_print_task_stall(struct rcu_node *rnp);
@@ -491,15 +485,9 @@ static void invoke_rcu_callbacks_kthread(void);
491static bool rcu_is_callbacks_kthread(void); 485static bool rcu_is_callbacks_kthread(void);
492#ifdef CONFIG_RCU_BOOST 486#ifdef CONFIG_RCU_BOOST
493static void rcu_preempt_do_callbacks(void); 487static void rcu_preempt_do_callbacks(void);
494static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp,
495 cpumask_var_t cm);
496static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp, 488static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
497 struct rcu_node *rnp, 489 struct rcu_node *rnp);
498 int rnp_index);
499static void invoke_rcu_node_kthread(struct rcu_node *rnp);
500static void rcu_yield(void (*f)(unsigned long), unsigned long arg);
501#endif /* #ifdef CONFIG_RCU_BOOST */ 490#endif /* #ifdef CONFIG_RCU_BOOST */
502static void rcu_cpu_kthread_setrt(int cpu, int to_rt);
503static void __cpuinit rcu_prepare_kthreads(int cpu); 491static void __cpuinit rcu_prepare_kthreads(int cpu);
504static void rcu_prepare_for_idle_init(int cpu); 492static void rcu_prepare_for_idle_init(int cpu);
505static void rcu_cleanup_after_idle(int cpu); 493static void rcu_cleanup_after_idle(int cpu);
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
index 7f3244c0df01..f92115488187 100644
--- a/kernel/rcutree_plugin.h
+++ b/kernel/rcutree_plugin.h
@@ -25,6 +25,8 @@
25 */ 25 */
26 26
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/oom.h>
29#include <linux/smpboot.h>
28 30
29#define RCU_KTHREAD_PRIO 1 31#define RCU_KTHREAD_PRIO 1
30 32
@@ -118,7 +120,7 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed);
118 */ 120 */
119void rcu_force_quiescent_state(void) 121void rcu_force_quiescent_state(void)
120{ 122{
121 force_quiescent_state(&rcu_preempt_state, 0); 123 force_quiescent_state(&rcu_preempt_state);
122} 124}
123EXPORT_SYMBOL_GPL(rcu_force_quiescent_state); 125EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
124 126
@@ -136,8 +138,6 @@ static void rcu_preempt_qs(int cpu)
136{ 138{
137 struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu); 139 struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
138 140
139 rdp->passed_quiesce_gpnum = rdp->gpnum;
140 barrier();
141 if (rdp->passed_quiesce == 0) 141 if (rdp->passed_quiesce == 0)
142 trace_rcu_grace_period("rcu_preempt", rdp->gpnum, "cpuqs"); 142 trace_rcu_grace_period("rcu_preempt", rdp->gpnum, "cpuqs");
143 rdp->passed_quiesce = 1; 143 rdp->passed_quiesce = 1;
@@ -422,9 +422,11 @@ static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
422 unsigned long flags; 422 unsigned long flags;
423 struct task_struct *t; 423 struct task_struct *t;
424 424
425 if (!rcu_preempt_blocked_readers_cgp(rnp))
426 return;
427 raw_spin_lock_irqsave(&rnp->lock, flags); 425 raw_spin_lock_irqsave(&rnp->lock, flags);
426 if (!rcu_preempt_blocked_readers_cgp(rnp)) {
427 raw_spin_unlock_irqrestore(&rnp->lock, flags);
428 return;
429 }
428 t = list_entry(rnp->gp_tasks, 430 t = list_entry(rnp->gp_tasks,
429 struct task_struct, rcu_node_entry); 431 struct task_struct, rcu_node_entry);
430 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) 432 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry)
@@ -584,17 +586,23 @@ static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
584 raw_spin_unlock(&rnp_root->lock); /* irqs still disabled */ 586 raw_spin_unlock(&rnp_root->lock); /* irqs still disabled */
585 } 587 }
586 588
589 rnp->gp_tasks = NULL;
590 rnp->exp_tasks = NULL;
587#ifdef CONFIG_RCU_BOOST 591#ifdef CONFIG_RCU_BOOST
588 /* In case root is being boosted and leaf is not. */ 592 rnp->boost_tasks = NULL;
593 /*
594 * In case root is being boosted and leaf was not. Make sure
595 * that we boost the tasks blocking the current grace period
596 * in this case.
597 */
589 raw_spin_lock(&rnp_root->lock); /* irqs already disabled */ 598 raw_spin_lock(&rnp_root->lock); /* irqs already disabled */
590 if (rnp_root->boost_tasks != NULL && 599 if (rnp_root->boost_tasks != NULL &&
591 rnp_root->boost_tasks != rnp_root->gp_tasks) 600 rnp_root->boost_tasks != rnp_root->gp_tasks &&
601 rnp_root->boost_tasks != rnp_root->exp_tasks)
592 rnp_root->boost_tasks = rnp_root->gp_tasks; 602 rnp_root->boost_tasks = rnp_root->gp_tasks;
593 raw_spin_unlock(&rnp_root->lock); /* irqs still disabled */ 603 raw_spin_unlock(&rnp_root->lock); /* irqs still disabled */
594#endif /* #ifdef CONFIG_RCU_BOOST */ 604#endif /* #ifdef CONFIG_RCU_BOOST */
595 605
596 rnp->gp_tasks = NULL;
597 rnp->exp_tasks = NULL;
598 return retval; 606 return retval;
599} 607}
600 608
@@ -676,7 +684,7 @@ void synchronize_rcu(void)
676EXPORT_SYMBOL_GPL(synchronize_rcu); 684EXPORT_SYMBOL_GPL(synchronize_rcu);
677 685
678static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq); 686static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq);
679static long sync_rcu_preempt_exp_count; 687static unsigned long sync_rcu_preempt_exp_count;
680static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex); 688static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex);
681 689
682/* 690/*
@@ -791,7 +799,7 @@ void synchronize_rcu_expedited(void)
791 unsigned long flags; 799 unsigned long flags;
792 struct rcu_node *rnp; 800 struct rcu_node *rnp;
793 struct rcu_state *rsp = &rcu_preempt_state; 801 struct rcu_state *rsp = &rcu_preempt_state;
794 long snap; 802 unsigned long snap;
795 int trycount = 0; 803 int trycount = 0;
796 804
797 smp_mb(); /* Caller's modifications seen first by other CPUs. */ 805 smp_mb(); /* Caller's modifications seen first by other CPUs. */
@@ -799,33 +807,47 @@ void synchronize_rcu_expedited(void)
799 smp_mb(); /* Above access cannot bleed into critical section. */ 807 smp_mb(); /* Above access cannot bleed into critical section. */
800 808
801 /* 809 /*
810 * Block CPU-hotplug operations. This means that any CPU-hotplug
811 * operation that finds an rcu_node structure with tasks in the
812 * process of being boosted will know that all tasks blocking
813 * this expedited grace period will already be in the process of
814 * being boosted. This simplifies the process of moving tasks
815 * from leaf to root rcu_node structures.
816 */
817 get_online_cpus();
818
819 /*
802 * Acquire lock, falling back to synchronize_rcu() if too many 820 * Acquire lock, falling back to synchronize_rcu() if too many
803 * lock-acquisition failures. Of course, if someone does the 821 * lock-acquisition failures. Of course, if someone does the
804 * expedited grace period for us, just leave. 822 * expedited grace period for us, just leave.
805 */ 823 */
806 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) { 824 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) {
825 if (ULONG_CMP_LT(snap,
826 ACCESS_ONCE(sync_rcu_preempt_exp_count))) {
827 put_online_cpus();
828 goto mb_ret; /* Others did our work for us. */
829 }
807 if (trycount++ < 10) { 830 if (trycount++ < 10) {
808 udelay(trycount * num_online_cpus()); 831 udelay(trycount * num_online_cpus());
809 } else { 832 } else {
833 put_online_cpus();
810 synchronize_rcu(); 834 synchronize_rcu();
811 return; 835 return;
812 } 836 }
813 if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
814 goto mb_ret; /* Others did our work for us. */
815 } 837 }
816 if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0) 838 if (ULONG_CMP_LT(snap, ACCESS_ONCE(sync_rcu_preempt_exp_count))) {
839 put_online_cpus();
817 goto unlock_mb_ret; /* Others did our work for us. */ 840 goto unlock_mb_ret; /* Others did our work for us. */
841 }
818 842
819 /* force all RCU readers onto ->blkd_tasks lists. */ 843 /* force all RCU readers onto ->blkd_tasks lists. */
820 synchronize_sched_expedited(); 844 synchronize_sched_expedited();
821 845
822 raw_spin_lock_irqsave(&rsp->onofflock, flags);
823
824 /* Initialize ->expmask for all non-leaf rcu_node structures. */ 846 /* Initialize ->expmask for all non-leaf rcu_node structures. */
825 rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) { 847 rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) {
826 raw_spin_lock(&rnp->lock); /* irqs already disabled. */ 848 raw_spin_lock_irqsave(&rnp->lock, flags);
827 rnp->expmask = rnp->qsmaskinit; 849 rnp->expmask = rnp->qsmaskinit;
828 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ 850 raw_spin_unlock_irqrestore(&rnp->lock, flags);
829 } 851 }
830 852
831 /* Snapshot current state of ->blkd_tasks lists. */ 853 /* Snapshot current state of ->blkd_tasks lists. */
@@ -834,7 +856,7 @@ void synchronize_rcu_expedited(void)
834 if (NUM_RCU_NODES > 1) 856 if (NUM_RCU_NODES > 1)
835 sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp)); 857 sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp));
836 858
837 raw_spin_unlock_irqrestore(&rsp->onofflock, flags); 859 put_online_cpus();
838 860
839 /* Wait for snapshotted ->blkd_tasks lists to drain. */ 861 /* Wait for snapshotted ->blkd_tasks lists to drain. */
840 rnp = rcu_get_root(rsp); 862 rnp = rcu_get_root(rsp);
@@ -1069,6 +1091,16 @@ static void rcu_initiate_boost_trace(struct rcu_node *rnp)
1069 1091
1070#endif /* #else #ifdef CONFIG_RCU_TRACE */ 1092#endif /* #else #ifdef CONFIG_RCU_TRACE */
1071 1093
1094static void rcu_wake_cond(struct task_struct *t, int status)
1095{
1096 /*
1097 * If the thread is yielding, only wake it when this
1098 * is invoked from idle
1099 */
1100 if (status != RCU_KTHREAD_YIELDING || is_idle_task(current))
1101 wake_up_process(t);
1102}
1103
1072/* 1104/*
1073 * Carry out RCU priority boosting on the task indicated by ->exp_tasks 1105 * Carry out RCU priority boosting on the task indicated by ->exp_tasks
1074 * or ->boost_tasks, advancing the pointer to the next task in the 1106 * or ->boost_tasks, advancing the pointer to the next task in the
@@ -1141,17 +1173,6 @@ static int rcu_boost(struct rcu_node *rnp)
1141} 1173}
1142 1174
1143/* 1175/*
1144 * Timer handler to initiate waking up of boost kthreads that
1145 * have yielded the CPU due to excessive numbers of tasks to
1146 * boost. We wake up the per-rcu_node kthread, which in turn
1147 * will wake up the booster kthread.
1148 */
1149static void rcu_boost_kthread_timer(unsigned long arg)
1150{
1151 invoke_rcu_node_kthread((struct rcu_node *)arg);
1152}
1153
1154/*
1155 * Priority-boosting kthread. One per leaf rcu_node and one for the 1176 * Priority-boosting kthread. One per leaf rcu_node and one for the
1156 * root rcu_node. 1177 * root rcu_node.
1157 */ 1178 */
@@ -1174,8 +1195,9 @@ static int rcu_boost_kthread(void *arg)
1174 else 1195 else
1175 spincnt = 0; 1196 spincnt = 0;
1176 if (spincnt > 10) { 1197 if (spincnt > 10) {
1198 rnp->boost_kthread_status = RCU_KTHREAD_YIELDING;
1177 trace_rcu_utilization("End boost kthread@rcu_yield"); 1199 trace_rcu_utilization("End boost kthread@rcu_yield");
1178 rcu_yield(rcu_boost_kthread_timer, (unsigned long)rnp); 1200 schedule_timeout_interruptible(2);
1179 trace_rcu_utilization("Start boost kthread@rcu_yield"); 1201 trace_rcu_utilization("Start boost kthread@rcu_yield");
1180 spincnt = 0; 1202 spincnt = 0;
1181 } 1203 }
@@ -1191,9 +1213,9 @@ static int rcu_boost_kthread(void *arg)
1191 * kthread to start boosting them. If there is an expedited grace 1213 * kthread to start boosting them. If there is an expedited grace
1192 * period in progress, it is always time to boost. 1214 * period in progress, it is always time to boost.
1193 * 1215 *
1194 * The caller must hold rnp->lock, which this function releases, 1216 * The caller must hold rnp->lock, which this function releases.
1195 * but irqs remain disabled. The ->boost_kthread_task is immortal, 1217 * The ->boost_kthread_task is immortal, so we don't need to worry
1196 * so we don't need to worry about it going away. 1218 * about it going away.
1197 */ 1219 */
1198static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags) 1220static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
1199{ 1221{
@@ -1213,8 +1235,8 @@ static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
1213 rnp->boost_tasks = rnp->gp_tasks; 1235 rnp->boost_tasks = rnp->gp_tasks;
1214 raw_spin_unlock_irqrestore(&rnp->lock, flags); 1236 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1215 t = rnp->boost_kthread_task; 1237 t = rnp->boost_kthread_task;
1216 if (t != NULL) 1238 if (t)
1217 wake_up_process(t); 1239 rcu_wake_cond(t, rnp->boost_kthread_status);
1218 } else { 1240 } else {
1219 rcu_initiate_boost_trace(rnp); 1241 rcu_initiate_boost_trace(rnp);
1220 raw_spin_unlock_irqrestore(&rnp->lock, flags); 1242 raw_spin_unlock_irqrestore(&rnp->lock, flags);
@@ -1231,8 +1253,10 @@ static void invoke_rcu_callbacks_kthread(void)
1231 local_irq_save(flags); 1253 local_irq_save(flags);
1232 __this_cpu_write(rcu_cpu_has_work, 1); 1254 __this_cpu_write(rcu_cpu_has_work, 1);
1233 if (__this_cpu_read(rcu_cpu_kthread_task) != NULL && 1255 if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
1234 current != __this_cpu_read(rcu_cpu_kthread_task)) 1256 current != __this_cpu_read(rcu_cpu_kthread_task)) {
1235 wake_up_process(__this_cpu_read(rcu_cpu_kthread_task)); 1257 rcu_wake_cond(__this_cpu_read(rcu_cpu_kthread_task),
1258 __this_cpu_read(rcu_cpu_kthread_status));
1259 }
1236 local_irq_restore(flags); 1260 local_irq_restore(flags);
1237} 1261}
1238 1262
@@ -1245,21 +1269,6 @@ static bool rcu_is_callbacks_kthread(void)
1245 return __get_cpu_var(rcu_cpu_kthread_task) == current; 1269 return __get_cpu_var(rcu_cpu_kthread_task) == current;
1246} 1270}
1247 1271
1248/*
1249 * Set the affinity of the boost kthread. The CPU-hotplug locks are
1250 * held, so no one should be messing with the existence of the boost
1251 * kthread.
1252 */
1253static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp,
1254 cpumask_var_t cm)
1255{
1256 struct task_struct *t;
1257
1258 t = rnp->boost_kthread_task;
1259 if (t != NULL)
1260 set_cpus_allowed_ptr(rnp->boost_kthread_task, cm);
1261}
1262
1263#define RCU_BOOST_DELAY_JIFFIES DIV_ROUND_UP(CONFIG_RCU_BOOST_DELAY * HZ, 1000) 1272#define RCU_BOOST_DELAY_JIFFIES DIV_ROUND_UP(CONFIG_RCU_BOOST_DELAY * HZ, 1000)
1264 1273
1265/* 1274/*
@@ -1276,15 +1285,19 @@ static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
1276 * Returns zero if all is well, a negated errno otherwise. 1285 * Returns zero if all is well, a negated errno otherwise.
1277 */ 1286 */
1278static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp, 1287static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
1279 struct rcu_node *rnp, 1288 struct rcu_node *rnp)
1280 int rnp_index)
1281{ 1289{
1290 int rnp_index = rnp - &rsp->node[0];
1282 unsigned long flags; 1291 unsigned long flags;
1283 struct sched_param sp; 1292 struct sched_param sp;
1284 struct task_struct *t; 1293 struct task_struct *t;
1285 1294
1286 if (&rcu_preempt_state != rsp) 1295 if (&rcu_preempt_state != rsp)
1287 return 0; 1296 return 0;
1297
1298 if (!rcu_scheduler_fully_active || rnp->qsmaskinit == 0)
1299 return 0;
1300
1288 rsp->boost = 1; 1301 rsp->boost = 1;
1289 if (rnp->boost_kthread_task != NULL) 1302 if (rnp->boost_kthread_task != NULL)
1290 return 0; 1303 return 0;
@@ -1301,25 +1314,6 @@ static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
1301 return 0; 1314 return 0;
1302} 1315}
1303 1316
1304#ifdef CONFIG_HOTPLUG_CPU
1305
1306/*
1307 * Stop the RCU's per-CPU kthread when its CPU goes offline,.
1308 */
1309static void rcu_stop_cpu_kthread(int cpu)
1310{
1311 struct task_struct *t;
1312
1313 /* Stop the CPU's kthread. */
1314 t = per_cpu(rcu_cpu_kthread_task, cpu);
1315 if (t != NULL) {
1316 per_cpu(rcu_cpu_kthread_task, cpu) = NULL;
1317 kthread_stop(t);
1318 }
1319}
1320
1321#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1322
1323static void rcu_kthread_do_work(void) 1317static void rcu_kthread_do_work(void)
1324{ 1318{
1325 rcu_do_batch(&rcu_sched_state, &__get_cpu_var(rcu_sched_data)); 1319 rcu_do_batch(&rcu_sched_state, &__get_cpu_var(rcu_sched_data));
@@ -1327,112 +1321,22 @@ static void rcu_kthread_do_work(void)
1327 rcu_preempt_do_callbacks(); 1321 rcu_preempt_do_callbacks();
1328} 1322}
1329 1323
1330/* 1324static void rcu_cpu_kthread_setup(unsigned int cpu)
1331 * Wake up the specified per-rcu_node-structure kthread.
1332 * Because the per-rcu_node kthreads are immortal, we don't need
1333 * to do anything to keep them alive.
1334 */
1335static void invoke_rcu_node_kthread(struct rcu_node *rnp)
1336{
1337 struct task_struct *t;
1338
1339 t = rnp->node_kthread_task;
1340 if (t != NULL)
1341 wake_up_process(t);
1342}
1343
1344/*
1345 * Set the specified CPU's kthread to run RT or not, as specified by
1346 * the to_rt argument. The CPU-hotplug locks are held, so the task
1347 * is not going away.
1348 */
1349static void rcu_cpu_kthread_setrt(int cpu, int to_rt)
1350{ 1325{
1351 int policy;
1352 struct sched_param sp; 1326 struct sched_param sp;
1353 struct task_struct *t;
1354 1327
1355 t = per_cpu(rcu_cpu_kthread_task, cpu); 1328 sp.sched_priority = RCU_KTHREAD_PRIO;
1356 if (t == NULL) 1329 sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
1357 return;
1358 if (to_rt) {
1359 policy = SCHED_FIFO;
1360 sp.sched_priority = RCU_KTHREAD_PRIO;
1361 } else {
1362 policy = SCHED_NORMAL;
1363 sp.sched_priority = 0;
1364 }
1365 sched_setscheduler_nocheck(t, policy, &sp);
1366} 1330}
1367 1331
1368/* 1332static void rcu_cpu_kthread_park(unsigned int cpu)
1369 * Timer handler to initiate the waking up of per-CPU kthreads that
1370 * have yielded the CPU due to excess numbers of RCU callbacks.
1371 * We wake up the per-rcu_node kthread, which in turn will wake up
1372 * the booster kthread.
1373 */
1374static void rcu_cpu_kthread_timer(unsigned long arg)
1375{ 1333{
1376 struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, arg); 1334 per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
1377 struct rcu_node *rnp = rdp->mynode;
1378
1379 atomic_or(rdp->grpmask, &rnp->wakemask);
1380 invoke_rcu_node_kthread(rnp);
1381} 1335}
1382 1336
1383/* 1337static int rcu_cpu_kthread_should_run(unsigned int cpu)
1384 * Drop to non-real-time priority and yield, but only after posting a
1385 * timer that will cause us to regain our real-time priority if we
1386 * remain preempted. Either way, we restore our real-time priority
1387 * before returning.
1388 */
1389static void rcu_yield(void (*f)(unsigned long), unsigned long arg)
1390{ 1338{
1391 struct sched_param sp; 1339 return __get_cpu_var(rcu_cpu_has_work);
1392 struct timer_list yield_timer;
1393 int prio = current->rt_priority;
1394
1395 setup_timer_on_stack(&yield_timer, f, arg);
1396 mod_timer(&yield_timer, jiffies + 2);
1397 sp.sched_priority = 0;
1398 sched_setscheduler_nocheck(current, SCHED_NORMAL, &sp);
1399 set_user_nice(current, 19);
1400 schedule();
1401 set_user_nice(current, 0);
1402 sp.sched_priority = prio;
1403 sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
1404 del_timer(&yield_timer);
1405}
1406
1407/*
1408 * Handle cases where the rcu_cpu_kthread() ends up on the wrong CPU.
1409 * This can happen while the corresponding CPU is either coming online
1410 * or going offline. We cannot wait until the CPU is fully online
1411 * before starting the kthread, because the various notifier functions
1412 * can wait for RCU grace periods. So we park rcu_cpu_kthread() until
1413 * the corresponding CPU is online.
1414 *
1415 * Return 1 if the kthread needs to stop, 0 otherwise.
1416 *
1417 * Caller must disable bh. This function can momentarily enable it.
1418 */
1419static int rcu_cpu_kthread_should_stop(int cpu)
1420{
1421 while (cpu_is_offline(cpu) ||
1422 !cpumask_equal(&current->cpus_allowed, cpumask_of(cpu)) ||
1423 smp_processor_id() != cpu) {
1424 if (kthread_should_stop())
1425 return 1;
1426 per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
1427 per_cpu(rcu_cpu_kthread_cpu, cpu) = raw_smp_processor_id();
1428 local_bh_enable();
1429 schedule_timeout_uninterruptible(1);
1430 if (!cpumask_equal(&current->cpus_allowed, cpumask_of(cpu)))
1431 set_cpus_allowed_ptr(current, cpumask_of(cpu));
1432 local_bh_disable();
1433 }
1434 per_cpu(rcu_cpu_kthread_cpu, cpu) = cpu;
1435 return 0;
1436} 1340}
1437 1341
1438/* 1342/*
@@ -1440,138 +1344,35 @@ static int rcu_cpu_kthread_should_stop(int cpu)
1440 * RCU softirq used in flavors and configurations of RCU that do not 1344 * RCU softirq used in flavors and configurations of RCU that do not
1441 * support RCU priority boosting. 1345 * support RCU priority boosting.
1442 */ 1346 */
1443static int rcu_cpu_kthread(void *arg) 1347static void rcu_cpu_kthread(unsigned int cpu)
1444{ 1348{
1445 int cpu = (int)(long)arg; 1349 unsigned int *statusp = &__get_cpu_var(rcu_cpu_kthread_status);
1446 unsigned long flags; 1350 char work, *workp = &__get_cpu_var(rcu_cpu_has_work);
1447 int spincnt = 0; 1351 int spincnt;
1448 unsigned int *statusp = &per_cpu(rcu_cpu_kthread_status, cpu);
1449 char work;
1450 char *workp = &per_cpu(rcu_cpu_has_work, cpu);
1451 1352
1452 trace_rcu_utilization("Start CPU kthread@init"); 1353 for (spincnt = 0; spincnt < 10; spincnt++) {
1453 for (;;) {
1454 *statusp = RCU_KTHREAD_WAITING;
1455 trace_rcu_utilization("End CPU kthread@rcu_wait");
1456 rcu_wait(*workp != 0 || kthread_should_stop());
1457 trace_rcu_utilization("Start CPU kthread@rcu_wait"); 1354 trace_rcu_utilization("Start CPU kthread@rcu_wait");
1458 local_bh_disable(); 1355 local_bh_disable();
1459 if (rcu_cpu_kthread_should_stop(cpu)) {
1460 local_bh_enable();
1461 break;
1462 }
1463 *statusp = RCU_KTHREAD_RUNNING; 1356 *statusp = RCU_KTHREAD_RUNNING;
1464 per_cpu(rcu_cpu_kthread_loops, cpu)++; 1357 this_cpu_inc(rcu_cpu_kthread_loops);
1465 local_irq_save(flags); 1358 local_irq_disable();
1466 work = *workp; 1359 work = *workp;
1467 *workp = 0; 1360 *workp = 0;
1468 local_irq_restore(flags); 1361 local_irq_enable();
1469 if (work) 1362 if (work)
1470 rcu_kthread_do_work(); 1363 rcu_kthread_do_work();
1471 local_bh_enable(); 1364 local_bh_enable();
1472 if (*workp != 0) 1365 if (*workp == 0) {
1473 spincnt++; 1366 trace_rcu_utilization("End CPU kthread@rcu_wait");
1474 else 1367 *statusp = RCU_KTHREAD_WAITING;
1475 spincnt = 0; 1368 return;
1476 if (spincnt > 10) {
1477 *statusp = RCU_KTHREAD_YIELDING;
1478 trace_rcu_utilization("End CPU kthread@rcu_yield");
1479 rcu_yield(rcu_cpu_kthread_timer, (unsigned long)cpu);
1480 trace_rcu_utilization("Start CPU kthread@rcu_yield");
1481 spincnt = 0;
1482 }
1483 }
1484 *statusp = RCU_KTHREAD_STOPPED;
1485 trace_rcu_utilization("End CPU kthread@term");
1486 return 0;
1487}
1488
1489/*
1490 * Spawn a per-CPU kthread, setting up affinity and priority.
1491 * Because the CPU hotplug lock is held, no other CPU will be attempting
1492 * to manipulate rcu_cpu_kthread_task. There might be another CPU
1493 * attempting to access it during boot, but the locking in kthread_bind()
1494 * will enforce sufficient ordering.
1495 *
1496 * Please note that we cannot simply refuse to wake up the per-CPU
1497 * kthread because kthreads are created in TASK_UNINTERRUPTIBLE state,
1498 * which can result in softlockup complaints if the task ends up being
1499 * idle for more than a couple of minutes.
1500 *
1501 * However, please note also that we cannot bind the per-CPU kthread to its
1502 * CPU until that CPU is fully online. We also cannot wait until the
1503 * CPU is fully online before we create its per-CPU kthread, as this would
1504 * deadlock the system when CPU notifiers tried waiting for grace
1505 * periods. So we bind the per-CPU kthread to its CPU only if the CPU
1506 * is online. If its CPU is not yet fully online, then the code in
1507 * rcu_cpu_kthread() will wait until it is fully online, and then do
1508 * the binding.
1509 */
1510static int __cpuinit rcu_spawn_one_cpu_kthread(int cpu)
1511{
1512 struct sched_param sp;
1513 struct task_struct *t;
1514
1515 if (!rcu_scheduler_fully_active ||
1516 per_cpu(rcu_cpu_kthread_task, cpu) != NULL)
1517 return 0;
1518 t = kthread_create_on_node(rcu_cpu_kthread,
1519 (void *)(long)cpu,
1520 cpu_to_node(cpu),
1521 "rcuc/%d", cpu);
1522 if (IS_ERR(t))
1523 return PTR_ERR(t);
1524 if (cpu_online(cpu))
1525 kthread_bind(t, cpu);
1526 per_cpu(rcu_cpu_kthread_cpu, cpu) = cpu;
1527 WARN_ON_ONCE(per_cpu(rcu_cpu_kthread_task, cpu) != NULL);
1528 sp.sched_priority = RCU_KTHREAD_PRIO;
1529 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
1530 per_cpu(rcu_cpu_kthread_task, cpu) = t;
1531 wake_up_process(t); /* Get to TASK_INTERRUPTIBLE quickly. */
1532 return 0;
1533}
1534
1535/*
1536 * Per-rcu_node kthread, which is in charge of waking up the per-CPU
1537 * kthreads when needed. We ignore requests to wake up kthreads
1538 * for offline CPUs, which is OK because force_quiescent_state()
1539 * takes care of this case.
1540 */
1541static int rcu_node_kthread(void *arg)
1542{
1543 int cpu;
1544 unsigned long flags;
1545 unsigned long mask;
1546 struct rcu_node *rnp = (struct rcu_node *)arg;
1547 struct sched_param sp;
1548 struct task_struct *t;
1549
1550 for (;;) {
1551 rnp->node_kthread_status = RCU_KTHREAD_WAITING;
1552 rcu_wait(atomic_read(&rnp->wakemask) != 0);
1553 rnp->node_kthread_status = RCU_KTHREAD_RUNNING;
1554 raw_spin_lock_irqsave(&rnp->lock, flags);
1555 mask = atomic_xchg(&rnp->wakemask, 0);
1556 rcu_initiate_boost(rnp, flags); /* releases rnp->lock. */
1557 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1) {
1558 if ((mask & 0x1) == 0)
1559 continue;
1560 preempt_disable();
1561 t = per_cpu(rcu_cpu_kthread_task, cpu);
1562 if (!cpu_online(cpu) || t == NULL) {
1563 preempt_enable();
1564 continue;
1565 }
1566 per_cpu(rcu_cpu_has_work, cpu) = 1;
1567 sp.sched_priority = RCU_KTHREAD_PRIO;
1568 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
1569 preempt_enable();
1570 } 1369 }
1571 } 1370 }
1572 /* NOTREACHED */ 1371 *statusp = RCU_KTHREAD_YIELDING;
1573 rnp->node_kthread_status = RCU_KTHREAD_STOPPED; 1372 trace_rcu_utilization("Start CPU kthread@rcu_yield");
1574 return 0; 1373 schedule_timeout_interruptible(2);
1374 trace_rcu_utilization("End CPU kthread@rcu_yield");
1375 *statusp = RCU_KTHREAD_WAITING;
1575} 1376}
1576 1377
1577/* 1378/*
@@ -1583,17 +1384,17 @@ static int rcu_node_kthread(void *arg)
1583 * no outgoing CPU. If there are no CPUs left in the affinity set, 1384 * no outgoing CPU. If there are no CPUs left in the affinity set,
1584 * this function allows the kthread to execute on any CPU. 1385 * this function allows the kthread to execute on any CPU.
1585 */ 1386 */
1586static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu) 1387static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1587{ 1388{
1389 struct task_struct *t = rnp->boost_kthread_task;
1390 unsigned long mask = rnp->qsmaskinit;
1588 cpumask_var_t cm; 1391 cpumask_var_t cm;
1589 int cpu; 1392 int cpu;
1590 unsigned long mask = rnp->qsmaskinit;
1591 1393
1592 if (rnp->node_kthread_task == NULL) 1394 if (!t)
1593 return; 1395 return;
1594 if (!alloc_cpumask_var(&cm, GFP_KERNEL)) 1396 if (!zalloc_cpumask_var(&cm, GFP_KERNEL))
1595 return; 1397 return;
1596 cpumask_clear(cm);
1597 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1) 1398 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1)
1598 if ((mask & 0x1) && cpu != outgoingcpu) 1399 if ((mask & 0x1) && cpu != outgoingcpu)
1599 cpumask_set_cpu(cpu, cm); 1400 cpumask_set_cpu(cpu, cm);
@@ -1603,62 +1404,36 @@ static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1603 cpumask_clear_cpu(cpu, cm); 1404 cpumask_clear_cpu(cpu, cm);
1604 WARN_ON_ONCE(cpumask_weight(cm) == 0); 1405 WARN_ON_ONCE(cpumask_weight(cm) == 0);
1605 } 1406 }
1606 set_cpus_allowed_ptr(rnp->node_kthread_task, cm); 1407 set_cpus_allowed_ptr(t, cm);
1607 rcu_boost_kthread_setaffinity(rnp, cm);
1608 free_cpumask_var(cm); 1408 free_cpumask_var(cm);
1609} 1409}
1610 1410
1611/* 1411static struct smp_hotplug_thread rcu_cpu_thread_spec = {
1612 * Spawn a per-rcu_node kthread, setting priority and affinity. 1412 .store = &rcu_cpu_kthread_task,
1613 * Called during boot before online/offline can happen, or, if 1413 .thread_should_run = rcu_cpu_kthread_should_run,
1614 * during runtime, with the main CPU-hotplug locks held. So only 1414 .thread_fn = rcu_cpu_kthread,
1615 * one of these can be executing at a time. 1415 .thread_comm = "rcuc/%u",
1616 */ 1416 .setup = rcu_cpu_kthread_setup,
1617static int __cpuinit rcu_spawn_one_node_kthread(struct rcu_state *rsp, 1417 .park = rcu_cpu_kthread_park,
1618 struct rcu_node *rnp) 1418};
1619{
1620 unsigned long flags;
1621 int rnp_index = rnp - &rsp->node[0];
1622 struct sched_param sp;
1623 struct task_struct *t;
1624
1625 if (!rcu_scheduler_fully_active ||
1626 rnp->qsmaskinit == 0)
1627 return 0;
1628 if (rnp->node_kthread_task == NULL) {
1629 t = kthread_create(rcu_node_kthread, (void *)rnp,
1630 "rcun/%d", rnp_index);
1631 if (IS_ERR(t))
1632 return PTR_ERR(t);
1633 raw_spin_lock_irqsave(&rnp->lock, flags);
1634 rnp->node_kthread_task = t;
1635 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1636 sp.sched_priority = 99;
1637 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
1638 wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */
1639 }
1640 return rcu_spawn_one_boost_kthread(rsp, rnp, rnp_index);
1641}
1642 1419
1643/* 1420/*
1644 * Spawn all kthreads -- called as soon as the scheduler is running. 1421 * Spawn all kthreads -- called as soon as the scheduler is running.
1645 */ 1422 */
1646static int __init rcu_spawn_kthreads(void) 1423static int __init rcu_spawn_kthreads(void)
1647{ 1424{
1648 int cpu;
1649 struct rcu_node *rnp; 1425 struct rcu_node *rnp;
1426 int cpu;
1650 1427
1651 rcu_scheduler_fully_active = 1; 1428 rcu_scheduler_fully_active = 1;
1652 for_each_possible_cpu(cpu) { 1429 for_each_possible_cpu(cpu)
1653 per_cpu(rcu_cpu_has_work, cpu) = 0; 1430 per_cpu(rcu_cpu_has_work, cpu) = 0;
1654 if (cpu_online(cpu)) 1431 BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
1655 (void)rcu_spawn_one_cpu_kthread(cpu);
1656 }
1657 rnp = rcu_get_root(rcu_state); 1432 rnp = rcu_get_root(rcu_state);
1658 (void)rcu_spawn_one_node_kthread(rcu_state, rnp); 1433 (void)rcu_spawn_one_boost_kthread(rcu_state, rnp);
1659 if (NUM_RCU_NODES > 1) { 1434 if (NUM_RCU_NODES > 1) {
1660 rcu_for_each_leaf_node(rcu_state, rnp) 1435 rcu_for_each_leaf_node(rcu_state, rnp)
1661 (void)rcu_spawn_one_node_kthread(rcu_state, rnp); 1436 (void)rcu_spawn_one_boost_kthread(rcu_state, rnp);
1662 } 1437 }
1663 return 0; 1438 return 0;
1664} 1439}
@@ -1670,11 +1445,8 @@ static void __cpuinit rcu_prepare_kthreads(int cpu)
1670 struct rcu_node *rnp = rdp->mynode; 1445 struct rcu_node *rnp = rdp->mynode;
1671 1446
1672 /* Fire up the incoming CPU's kthread and leaf rcu_node kthread. */ 1447 /* Fire up the incoming CPU's kthread and leaf rcu_node kthread. */
1673 if (rcu_scheduler_fully_active) { 1448 if (rcu_scheduler_fully_active)
1674 (void)rcu_spawn_one_cpu_kthread(cpu); 1449 (void)rcu_spawn_one_boost_kthread(rcu_state, rnp);
1675 if (rnp->node_kthread_task == NULL)
1676 (void)rcu_spawn_one_node_kthread(rcu_state, rnp);
1677 }
1678} 1450}
1679 1451
1680#else /* #ifdef CONFIG_RCU_BOOST */ 1452#else /* #ifdef CONFIG_RCU_BOOST */
@@ -1698,19 +1470,7 @@ static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
1698{ 1470{
1699} 1471}
1700 1472
1701#ifdef CONFIG_HOTPLUG_CPU 1473static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1702
1703static void rcu_stop_cpu_kthread(int cpu)
1704{
1705}
1706
1707#endif /* #ifdef CONFIG_HOTPLUG_CPU */
1708
1709static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1710{
1711}
1712
1713static void rcu_cpu_kthread_setrt(int cpu, int to_rt)
1714{ 1474{
1715} 1475}
1716 1476
@@ -1997,6 +1757,26 @@ static void rcu_prepare_for_idle(int cpu)
1997 if (!tne) 1757 if (!tne)
1998 return; 1758 return;
1999 1759
1760 /* Adaptive-tick mode, where usermode execution is idle to RCU. */
1761 if (!is_idle_task(current)) {
1762 rdtp->dyntick_holdoff = jiffies - 1;
1763 if (rcu_cpu_has_nonlazy_callbacks(cpu)) {
1764 trace_rcu_prep_idle("User dyntick with callbacks");
1765 rdtp->idle_gp_timer_expires =
1766 round_up(jiffies + RCU_IDLE_GP_DELAY,
1767 RCU_IDLE_GP_DELAY);
1768 } else if (rcu_cpu_has_callbacks(cpu)) {
1769 rdtp->idle_gp_timer_expires =
1770 round_jiffies(jiffies + RCU_IDLE_LAZY_GP_DELAY);
1771 trace_rcu_prep_idle("User dyntick with lazy callbacks");
1772 } else {
1773 return;
1774 }
1775 tp = &rdtp->idle_gp_timer;
1776 mod_timer_pinned(tp, rdtp->idle_gp_timer_expires);
1777 return;
1778 }
1779
2000 /* 1780 /*
2001 * If this is an idle re-entry, for example, due to use of 1781 * If this is an idle re-entry, for example, due to use of
2002 * RCU_NONIDLE() or the new idle-loop tracing API within the idle 1782 * RCU_NONIDLE() or the new idle-loop tracing API within the idle
@@ -2075,16 +1855,16 @@ static void rcu_prepare_for_idle(int cpu)
2075#ifdef CONFIG_TREE_PREEMPT_RCU 1855#ifdef CONFIG_TREE_PREEMPT_RCU
2076 if (per_cpu(rcu_preempt_data, cpu).nxtlist) { 1856 if (per_cpu(rcu_preempt_data, cpu).nxtlist) {
2077 rcu_preempt_qs(cpu); 1857 rcu_preempt_qs(cpu);
2078 force_quiescent_state(&rcu_preempt_state, 0); 1858 force_quiescent_state(&rcu_preempt_state);
2079 } 1859 }
2080#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ 1860#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
2081 if (per_cpu(rcu_sched_data, cpu).nxtlist) { 1861 if (per_cpu(rcu_sched_data, cpu).nxtlist) {
2082 rcu_sched_qs(cpu); 1862 rcu_sched_qs(cpu);
2083 force_quiescent_state(&rcu_sched_state, 0); 1863 force_quiescent_state(&rcu_sched_state);
2084 } 1864 }
2085 if (per_cpu(rcu_bh_data, cpu).nxtlist) { 1865 if (per_cpu(rcu_bh_data, cpu).nxtlist) {
2086 rcu_bh_qs(cpu); 1866 rcu_bh_qs(cpu);
2087 force_quiescent_state(&rcu_bh_state, 0); 1867 force_quiescent_state(&rcu_bh_state);
2088 } 1868 }
2089 1869
2090 /* 1870 /*
@@ -2112,6 +1892,88 @@ static void rcu_idle_count_callbacks_posted(void)
2112 __this_cpu_add(rcu_dynticks.nonlazy_posted, 1); 1892 __this_cpu_add(rcu_dynticks.nonlazy_posted, 1);
2113} 1893}
2114 1894
1895/*
1896 * Data for flushing lazy RCU callbacks at OOM time.
1897 */
1898static atomic_t oom_callback_count;
1899static DECLARE_WAIT_QUEUE_HEAD(oom_callback_wq);
1900
1901/*
1902 * RCU OOM callback -- decrement the outstanding count and deliver the
1903 * wake-up if we are the last one.
1904 */
1905static void rcu_oom_callback(struct rcu_head *rhp)
1906{
1907 if (atomic_dec_and_test(&oom_callback_count))
1908 wake_up(&oom_callback_wq);
1909}
1910
1911/*
1912 * Post an rcu_oom_notify callback on the current CPU if it has at
1913 * least one lazy callback. This will unnecessarily post callbacks
1914 * to CPUs that already have a non-lazy callback at the end of their
1915 * callback list, but this is an infrequent operation, so accept some
1916 * extra overhead to keep things simple.
1917 */
1918static void rcu_oom_notify_cpu(void *unused)
1919{
1920 struct rcu_state *rsp;
1921 struct rcu_data *rdp;
1922
1923 for_each_rcu_flavor(rsp) {
1924 rdp = __this_cpu_ptr(rsp->rda);
1925 if (rdp->qlen_lazy != 0) {
1926 atomic_inc(&oom_callback_count);
1927 rsp->call(&rdp->oom_head, rcu_oom_callback);
1928 }
1929 }
1930}
1931
1932/*
1933 * If low on memory, ensure that each CPU has a non-lazy callback.
1934 * This will wake up CPUs that have only lazy callbacks, in turn
1935 * ensuring that they free up the corresponding memory in a timely manner.
1936 * Because an uncertain amount of memory will be freed in some uncertain
1937 * timeframe, we do not claim to have freed anything.
1938 */
1939static int rcu_oom_notify(struct notifier_block *self,
1940 unsigned long notused, void *nfreed)
1941{
1942 int cpu;
1943
1944 /* Wait for callbacks from earlier instance to complete. */
1945 wait_event(oom_callback_wq, atomic_read(&oom_callback_count) == 0);
1946
1947 /*
1948 * Prevent premature wakeup: ensure that all increments happen
1949 * before there is a chance of the counter reaching zero.
1950 */
1951 atomic_set(&oom_callback_count, 1);
1952
1953 get_online_cpus();
1954 for_each_online_cpu(cpu) {
1955 smp_call_function_single(cpu, rcu_oom_notify_cpu, NULL, 1);
1956 cond_resched();
1957 }
1958 put_online_cpus();
1959
1960 /* Unconditionally decrement: no need to wake ourselves up. */
1961 atomic_dec(&oom_callback_count);
1962
1963 return NOTIFY_OK;
1964}
1965
1966static struct notifier_block rcu_oom_nb = {
1967 .notifier_call = rcu_oom_notify
1968};
1969
1970static int __init rcu_register_oom_notifier(void)
1971{
1972 register_oom_notifier(&rcu_oom_nb);
1973 return 0;
1974}
1975early_initcall(rcu_register_oom_notifier);
1976
2115#endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */ 1977#endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */
2116 1978
2117#ifdef CONFIG_RCU_CPU_STALL_INFO 1979#ifdef CONFIG_RCU_CPU_STALL_INFO
@@ -2122,11 +1984,15 @@ static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
2122{ 1984{
2123 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu); 1985 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
2124 struct timer_list *tltp = &rdtp->idle_gp_timer; 1986 struct timer_list *tltp = &rdtp->idle_gp_timer;
1987 char c;
2125 1988
2126 sprintf(cp, "drain=%d %c timer=%lu", 1989 c = rdtp->dyntick_holdoff == jiffies ? 'H' : '.';
2127 rdtp->dyntick_drain, 1990 if (timer_pending(tltp))
2128 rdtp->dyntick_holdoff == jiffies ? 'H' : '.', 1991 sprintf(cp, "drain=%d %c timer=%lu",
2129 timer_pending(tltp) ? tltp->expires - jiffies : -1); 1992 rdtp->dyntick_drain, c, tltp->expires - jiffies);
1993 else
1994 sprintf(cp, "drain=%d %c timer not pending",
1995 rdtp->dyntick_drain, c);
2130} 1996}
2131 1997
2132#else /* #ifdef CONFIG_RCU_FAST_NO_HZ */ 1998#else /* #ifdef CONFIG_RCU_FAST_NO_HZ */
@@ -2194,11 +2060,10 @@ static void zero_cpu_stall_ticks(struct rcu_data *rdp)
2194/* Increment ->ticks_this_gp for all flavors of RCU. */ 2060/* Increment ->ticks_this_gp for all flavors of RCU. */
2195static void increment_cpu_stall_ticks(void) 2061static void increment_cpu_stall_ticks(void)
2196{ 2062{
2197 __get_cpu_var(rcu_sched_data).ticks_this_gp++; 2063 struct rcu_state *rsp;
2198 __get_cpu_var(rcu_bh_data).ticks_this_gp++; 2064
2199#ifdef CONFIG_TREE_PREEMPT_RCU 2065 for_each_rcu_flavor(rsp)
2200 __get_cpu_var(rcu_preempt_data).ticks_this_gp++; 2066 __this_cpu_ptr(rsp->rda)->ticks_this_gp++;
2201#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
2202} 2067}
2203 2068
2204#else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */ 2069#else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */
diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
index abffb486e94e..693513bc50e6 100644
--- a/kernel/rcutree_trace.c
+++ b/kernel/rcutree_trace.c
@@ -51,8 +51,8 @@ static int show_rcubarrier(struct seq_file *m, void *unused)
51 struct rcu_state *rsp; 51 struct rcu_state *rsp;
52 52
53 for_each_rcu_flavor(rsp) 53 for_each_rcu_flavor(rsp)
54 seq_printf(m, "%s: %c bcc: %d nbd: %lu\n", 54 seq_printf(m, "%s: bcc: %d nbd: %lu\n",
55 rsp->name, rsp->rcu_barrier_in_progress ? 'B' : '.', 55 rsp->name,
56 atomic_read(&rsp->barrier_cpu_count), 56 atomic_read(&rsp->barrier_cpu_count),
57 rsp->n_barrier_done); 57 rsp->n_barrier_done);
58 return 0; 58 return 0;
@@ -86,12 +86,11 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
86{ 86{
87 if (!rdp->beenonline) 87 if (!rdp->beenonline)
88 return; 88 return;
89 seq_printf(m, "%3d%cc=%lu g=%lu pq=%d pgp=%lu qp=%d", 89 seq_printf(m, "%3d%cc=%lu g=%lu pq=%d qp=%d",
90 rdp->cpu, 90 rdp->cpu,
91 cpu_is_offline(rdp->cpu) ? '!' : ' ', 91 cpu_is_offline(rdp->cpu) ? '!' : ' ',
92 rdp->completed, rdp->gpnum, 92 rdp->completed, rdp->gpnum,
93 rdp->passed_quiesce, rdp->passed_quiesce_gpnum, 93 rdp->passed_quiesce, rdp->qs_pending);
94 rdp->qs_pending);
95 seq_printf(m, " dt=%d/%llx/%d df=%lu", 94 seq_printf(m, " dt=%d/%llx/%d df=%lu",
96 atomic_read(&rdp->dynticks->dynticks), 95 atomic_read(&rdp->dynticks->dynticks),
97 rdp->dynticks->dynticks_nesting, 96 rdp->dynticks->dynticks_nesting,
@@ -108,11 +107,10 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
108 rdp->nxttail[RCU_WAIT_TAIL]], 107 rdp->nxttail[RCU_WAIT_TAIL]],
109 ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]]); 108 ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]]);
110#ifdef CONFIG_RCU_BOOST 109#ifdef CONFIG_RCU_BOOST
111 seq_printf(m, " kt=%d/%c/%d ktl=%x", 110 seq_printf(m, " kt=%d/%c ktl=%x",
112 per_cpu(rcu_cpu_has_work, rdp->cpu), 111 per_cpu(rcu_cpu_has_work, rdp->cpu),
113 convert_kthread_status(per_cpu(rcu_cpu_kthread_status, 112 convert_kthread_status(per_cpu(rcu_cpu_kthread_status,
114 rdp->cpu)), 113 rdp->cpu)),
115 per_cpu(rcu_cpu_kthread_cpu, rdp->cpu),
116 per_cpu(rcu_cpu_kthread_loops, rdp->cpu) & 0xffff); 114 per_cpu(rcu_cpu_kthread_loops, rdp->cpu) & 0xffff);
117#endif /* #ifdef CONFIG_RCU_BOOST */ 115#endif /* #ifdef CONFIG_RCU_BOOST */
118 seq_printf(m, " b=%ld", rdp->blimit); 116 seq_printf(m, " b=%ld", rdp->blimit);
@@ -150,12 +148,11 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
150{ 148{
151 if (!rdp->beenonline) 149 if (!rdp->beenonline)
152 return; 150 return;
153 seq_printf(m, "%d,%s,%lu,%lu,%d,%lu,%d", 151 seq_printf(m, "%d,%s,%lu,%lu,%d,%d",
154 rdp->cpu, 152 rdp->cpu,
155 cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"", 153 cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
156 rdp->completed, rdp->gpnum, 154 rdp->completed, rdp->gpnum,
157 rdp->passed_quiesce, rdp->passed_quiesce_gpnum, 155 rdp->passed_quiesce, rdp->qs_pending);
158 rdp->qs_pending);
159 seq_printf(m, ",%d,%llx,%d,%lu", 156 seq_printf(m, ",%d,%llx,%d,%lu",
160 atomic_read(&rdp->dynticks->dynticks), 157 atomic_read(&rdp->dynticks->dynticks),
161 rdp->dynticks->dynticks_nesting, 158 rdp->dynticks->dynticks_nesting,
@@ -186,7 +183,7 @@ static int show_rcudata_csv(struct seq_file *m, void *unused)
186 int cpu; 183 int cpu;
187 struct rcu_state *rsp; 184 struct rcu_state *rsp;
188 185
189 seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pgp\",\"pq\","); 186 seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pq\",");
190 seq_puts(m, "\"dt\",\"dt nesting\",\"dt NMI nesting\",\"df\","); 187 seq_puts(m, "\"dt\",\"dt nesting\",\"dt NMI nesting\",\"df\",");
191 seq_puts(m, "\"of\",\"qll\",\"ql\",\"qs\""); 188 seq_puts(m, "\"of\",\"qll\",\"ql\",\"qs\"");
192#ifdef CONFIG_RCU_BOOST 189#ifdef CONFIG_RCU_BOOST
@@ -386,10 +383,9 @@ static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
386 rdp->n_rp_report_qs, 383 rdp->n_rp_report_qs,
387 rdp->n_rp_cb_ready, 384 rdp->n_rp_cb_ready,
388 rdp->n_rp_cpu_needs_gp); 385 rdp->n_rp_cpu_needs_gp);
389 seq_printf(m, "gpc=%ld gps=%ld nf=%ld nn=%ld\n", 386 seq_printf(m, "gpc=%ld gps=%ld nn=%ld\n",
390 rdp->n_rp_gp_completed, 387 rdp->n_rp_gp_completed,
391 rdp->n_rp_gp_started, 388 rdp->n_rp_gp_started,
392 rdp->n_rp_need_fqs,
393 rdp->n_rp_need_nothing); 389 rdp->n_rp_need_nothing);
394} 390}
395 391
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fbf1fd098dc6..3c4dec0594d6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2081,6 +2081,7 @@ context_switch(struct rq *rq, struct task_struct *prev,
2081#endif 2081#endif
2082 2082
2083 /* Here we just switch the register state and the stack. */ 2083 /* Here we just switch the register state and the stack. */
2084 rcu_switch(prev, next);
2084 switch_to(prev, next, prev); 2085 switch_to(prev, next, prev);
2085 2086
2086 barrier(); 2087 barrier();
@@ -3468,6 +3469,21 @@ asmlinkage void __sched schedule(void)
3468} 3469}
3469EXPORT_SYMBOL(schedule); 3470EXPORT_SYMBOL(schedule);
3470 3471
3472#ifdef CONFIG_RCU_USER_QS
3473asmlinkage void __sched schedule_user(void)
3474{
3475 /*
3476 * If we come here after a random call to set_need_resched(),
3477 * or we have been woken up remotely but the IPI has not yet arrived,
3478 * we haven't yet exited the RCU idle mode. Do it here manually until
3479 * we find a better solution.
3480 */
3481 rcu_user_exit();
3482 schedule();
3483 rcu_user_enter();
3484}
3485#endif
3486
3471/** 3487/**
3472 * schedule_preempt_disabled - called with preemption disabled 3488 * schedule_preempt_disabled - called with preemption disabled
3473 * 3489 *
@@ -3569,6 +3585,7 @@ asmlinkage void __sched preempt_schedule_irq(void)
3569 /* Catch callers which need to be fixed */ 3585 /* Catch callers which need to be fixed */
3570 BUG_ON(ti->preempt_count || !irqs_disabled()); 3586 BUG_ON(ti->preempt_count || !irqs_disabled());
3571 3587
3588 rcu_user_exit();
3572 do { 3589 do {
3573 add_preempt_count(PREEMPT_ACTIVE); 3590 add_preempt_count(PREEMPT_ACTIVE);
3574 local_irq_enable(); 3591 local_irq_enable();
@@ -5304,27 +5321,17 @@ void idle_task_exit(void)
5304} 5321}
5305 5322
5306/* 5323/*
5307 * While a dead CPU has no uninterruptible tasks queued at this point, 5324 * Since this CPU is going 'away' for a while, fold any nr_active delta
5308 * it might still have a nonzero ->nr_uninterruptible counter, because 5325 * we might have. Assumes we're called after migrate_tasks() so that the
5309 * for performance reasons the counter is not stricly tracking tasks to 5326 * nr_active count is stable.
5310 * their home CPUs. So we just add the counter to another CPU's counter, 5327 *
5311 * to keep the global sum constant after CPU-down: 5328 * Also see the comment "Global load-average calculations".
5312 */
5313static void migrate_nr_uninterruptible(struct rq *rq_src)
5314{
5315 struct rq *rq_dest = cpu_rq(cpumask_any(cpu_active_mask));
5316
5317 rq_dest->nr_uninterruptible += rq_src->nr_uninterruptible;
5318 rq_src->nr_uninterruptible = 0;
5319}
5320
5321/*
5322 * remove the tasks which were accounted by rq from calc_load_tasks.
5323 */ 5329 */
5324static void calc_global_load_remove(struct rq *rq) 5330static void calc_load_migrate(struct rq *rq)
5325{ 5331{
5326 atomic_long_sub(rq->calc_load_active, &calc_load_tasks); 5332 long delta = calc_load_fold_active(rq);
5327 rq->calc_load_active = 0; 5333 if (delta)
5334 atomic_long_add(delta, &calc_load_tasks);
5328} 5335}
5329 5336
5330/* 5337/*
@@ -5352,9 +5359,6 @@ static void migrate_tasks(unsigned int dead_cpu)
5352 */ 5359 */
5353 rq->stop = NULL; 5360 rq->stop = NULL;
5354 5361
5355 /* Ensure any throttled groups are reachable by pick_next_task */
5356 unthrottle_offline_cfs_rqs(rq);
5357
5358 for ( ; ; ) { 5362 for ( ; ; ) {
5359 /* 5363 /*
5360 * There's this thread running, bail when that's the only 5364 * There's this thread running, bail when that's the only
@@ -5617,9 +5621,10 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
5617 migrate_tasks(cpu); 5621 migrate_tasks(cpu);
5618 BUG_ON(rq->nr_running != 1); /* the migration thread */ 5622 BUG_ON(rq->nr_running != 1); /* the migration thread */
5619 raw_spin_unlock_irqrestore(&rq->lock, flags); 5623 raw_spin_unlock_irqrestore(&rq->lock, flags);
5624 break;
5620 5625
5621 migrate_nr_uninterruptible(rq); 5626 case CPU_DEAD:
5622 calc_global_load_remove(rq); 5627 calc_load_migrate(rq);
5623 break; 5628 break;
5624#endif 5629#endif
5625 } 5630 }
@@ -6028,11 +6033,6 @@ static void destroy_sched_domains(struct sched_domain *sd, int cpu)
6028 * SD_SHARE_PKG_RESOURCE set (Last Level Cache Domain) for this 6033 * SD_SHARE_PKG_RESOURCE set (Last Level Cache Domain) for this
6029 * allows us to avoid some pointer chasing select_idle_sibling(). 6034 * allows us to avoid some pointer chasing select_idle_sibling().
6030 * 6035 *
6031 * Iterate domains and sched_groups downward, assigning CPUs to be
6032 * select_idle_sibling() hw buddy. Cross-wiring hw makes bouncing
6033 * due to random perturbation self canceling, ie sw buddies pull
6034 * their counterpart to their CPU's hw counterpart.
6035 *
6036 * Also keep a unique ID per domain (we use the first cpu number in 6036 * Also keep a unique ID per domain (we use the first cpu number in
6037 * the cpumask of the domain), this allows us to quickly tell if 6037 * the cpumask of the domain), this allows us to quickly tell if
6038 * two cpus are in the same cache domain, see cpus_share_cache(). 6038 * two cpus are in the same cache domain, see cpus_share_cache().
@@ -6046,40 +6046,8 @@ static void update_top_cache_domain(int cpu)
6046 int id = cpu; 6046 int id = cpu;
6047 6047
6048 sd = highest_flag_domain(cpu, SD_SHARE_PKG_RESOURCES); 6048 sd = highest_flag_domain(cpu, SD_SHARE_PKG_RESOURCES);
6049 if (sd) { 6049 if (sd)
6050 struct sched_domain *tmp = sd;
6051 struct sched_group *sg, *prev;
6052 bool right;
6053
6054 /*
6055 * Traverse to first CPU in group, and count hops
6056 * to cpu from there, switching direction on each
6057 * hop, never ever pointing the last CPU rightward.
6058 */
6059 do {
6060 id = cpumask_first(sched_domain_span(tmp));
6061 prev = sg = tmp->groups;
6062 right = 1;
6063
6064 while (cpumask_first(sched_group_cpus(sg)) != id)
6065 sg = sg->next;
6066
6067 while (!cpumask_test_cpu(cpu, sched_group_cpus(sg))) {
6068 prev = sg;
6069 sg = sg->next;
6070 right = !right;
6071 }
6072
6073 /* A CPU went down, never point back to domain start. */
6074 if (right && cpumask_first(sched_group_cpus(sg->next)) == id)
6075 right = false;
6076
6077 sg = right ? sg->next : prev;
6078 tmp->idle_buddy = cpumask_first(sched_group_cpus(sg));
6079 } while ((tmp = tmp->child));
6080
6081 id = cpumask_first(sched_domain_span(sd)); 6050 id = cpumask_first(sched_domain_span(sd));
6082 }
6083 6051
6084 rcu_assign_pointer(per_cpu(sd_llc, cpu), sd); 6052 rcu_assign_pointer(per_cpu(sd_llc, cpu), sd);
6085 per_cpu(sd_llc_id, cpu) = id; 6053 per_cpu(sd_llc_id, cpu) = id;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index c219bf8d704c..96e2b18b6283 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2052,7 +2052,7 @@ static void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b)
2052 hrtimer_cancel(&cfs_b->slack_timer); 2052 hrtimer_cancel(&cfs_b->slack_timer);
2053} 2053}
2054 2054
2055void unthrottle_offline_cfs_rqs(struct rq *rq) 2055static void unthrottle_offline_cfs_rqs(struct rq *rq)
2056{ 2056{
2057 struct cfs_rq *cfs_rq; 2057 struct cfs_rq *cfs_rq;
2058 2058
@@ -2106,7 +2106,7 @@ static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
2106 return NULL; 2106 return NULL;
2107} 2107}
2108static inline void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b) {} 2108static inline void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b) {}
2109void unthrottle_offline_cfs_rqs(struct rq *rq) {} 2109static inline void unthrottle_offline_cfs_rqs(struct rq *rq) {}
2110 2110
2111#endif /* CONFIG_CFS_BANDWIDTH */ 2111#endif /* CONFIG_CFS_BANDWIDTH */
2112 2112
@@ -2637,6 +2637,8 @@ static int select_idle_sibling(struct task_struct *p, int target)
2637 int cpu = smp_processor_id(); 2637 int cpu = smp_processor_id();
2638 int prev_cpu = task_cpu(p); 2638 int prev_cpu = task_cpu(p);
2639 struct sched_domain *sd; 2639 struct sched_domain *sd;
2640 struct sched_group *sg;
2641 int i;
2640 2642
2641 /* 2643 /*
2642 * If the task is going to be woken-up on this cpu and if it is 2644 * If the task is going to be woken-up on this cpu and if it is
@@ -2653,17 +2655,29 @@ static int select_idle_sibling(struct task_struct *p, int target)
2653 return prev_cpu; 2655 return prev_cpu;
2654 2656
2655 /* 2657 /*
2656 * Otherwise, check assigned siblings to find an elegible idle cpu. 2658 * Otherwise, iterate the domains and find an elegible idle cpu.
2657 */ 2659 */
2658 sd = rcu_dereference(per_cpu(sd_llc, target)); 2660 sd = rcu_dereference(per_cpu(sd_llc, target));
2659
2660 for_each_lower_domain(sd) { 2661 for_each_lower_domain(sd) {
2661 if (!cpumask_test_cpu(sd->idle_buddy, tsk_cpus_allowed(p))) 2662 sg = sd->groups;
2662 continue; 2663 do {
2663 if (idle_cpu(sd->idle_buddy)) 2664 if (!cpumask_intersects(sched_group_cpus(sg),
2664 return sd->idle_buddy; 2665 tsk_cpus_allowed(p)))
2665 } 2666 goto next;
2666 2667
2668 for_each_cpu(i, sched_group_cpus(sg)) {
2669 if (!idle_cpu(i))
2670 goto next;
2671 }
2672
2673 target = cpumask_first_and(sched_group_cpus(sg),
2674 tsk_cpus_allowed(p));
2675 goto done;
2676next:
2677 sg = sg->next;
2678 } while (sg != sd->groups);
2679 }
2680done:
2667 return target; 2681 return target;
2668} 2682}
2669 2683
@@ -3658,7 +3672,6 @@ fix_small_capacity(struct sched_domain *sd, struct sched_group *group)
3658 * @group: sched_group whose statistics are to be updated. 3672 * @group: sched_group whose statistics are to be updated.
3659 * @load_idx: Load index of sched_domain of this_cpu for load calc. 3673 * @load_idx: Load index of sched_domain of this_cpu for load calc.
3660 * @local_group: Does group contain this_cpu. 3674 * @local_group: Does group contain this_cpu.
3661 * @cpus: Set of cpus considered for load balancing.
3662 * @balance: Should we balance. 3675 * @balance: Should we balance.
3663 * @sgs: variable to hold the statistics for this group. 3676 * @sgs: variable to hold the statistics for this group.
3664 */ 3677 */
@@ -3805,7 +3818,6 @@ static bool update_sd_pick_busiest(struct lb_env *env,
3805/** 3818/**
3806 * update_sd_lb_stats - Update sched_domain's statistics for load balancing. 3819 * update_sd_lb_stats - Update sched_domain's statistics for load balancing.
3807 * @env: The load balancing environment. 3820 * @env: The load balancing environment.
3808 * @cpus: Set of cpus considered for load balancing.
3809 * @balance: Should we balance. 3821 * @balance: Should we balance.
3810 * @sds: variable to hold the statistics for this sched_domain. 3822 * @sds: variable to hold the statistics for this sched_domain.
3811 */ 3823 */
@@ -4956,6 +4968,9 @@ static void rq_online_fair(struct rq *rq)
4956static void rq_offline_fair(struct rq *rq) 4968static void rq_offline_fair(struct rq *rq)
4957{ 4969{
4958 update_sysctl(); 4970 update_sysctl();
4971
4972 /* Ensure any throttled groups are reachable by pick_next_task */
4973 unthrottle_offline_cfs_rqs(rq);
4959} 4974}
4960 4975
4961#endif /* CONFIG_SMP */ 4976#endif /* CONFIG_SMP */
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 944cb68420e9..e0b7ba9c040f 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -691,6 +691,7 @@ balanced:
691 * runtime - in which case borrowing doesn't make sense. 691 * runtime - in which case borrowing doesn't make sense.
692 */ 692 */
693 rt_rq->rt_runtime = RUNTIME_INF; 693 rt_rq->rt_runtime = RUNTIME_INF;
694 rt_rq->rt_throttled = 0;
694 raw_spin_unlock(&rt_rq->rt_runtime_lock); 695 raw_spin_unlock(&rt_rq->rt_runtime_lock);
695 raw_spin_unlock(&rt_b->rt_runtime_lock); 696 raw_spin_unlock(&rt_b->rt_runtime_lock);
696 } 697 }
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index f6714d009e77..0848fa36c383 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1144,7 +1144,6 @@ extern void print_rt_stats(struct seq_file *m, int cpu);
1144 1144
1145extern void init_cfs_rq(struct cfs_rq *cfs_rq); 1145extern void init_cfs_rq(struct cfs_rq *cfs_rq);
1146extern void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq); 1146extern void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq);
1147extern void unthrottle_offline_cfs_rqs(struct rq *rq);
1148 1147
1149extern void account_cfs_bandwidth_used(int enabled, int was_enabled); 1148extern void account_cfs_bandwidth_used(int enabled, int was_enabled);
1150 1149
diff --git a/kernel/signal.c b/kernel/signal.c
index be4f856d52f8..2c681f11b7d2 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1971,13 +1971,8 @@ static void ptrace_do_notify(int signr, int exit_code, int why)
1971void ptrace_notify(int exit_code) 1971void ptrace_notify(int exit_code)
1972{ 1972{
1973 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP); 1973 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
1974 if (unlikely(current->task_works)) { 1974 if (unlikely(current->task_works))
1975 if (test_and_clear_ti_thread_flag(current_thread_info(), 1975 task_work_run();
1976 TIF_NOTIFY_RESUME)) {
1977 smp_mb__after_clear_bit();
1978 task_work_run();
1979 }
1980 }
1981 1976
1982 spin_lock_irq(&current->sighand->siglock); 1977 spin_lock_irq(&current->sighand->siglock);
1983 ptrace_do_notify(SIGTRAP, exit_code, CLD_TRAPPED); 1978 ptrace_do_notify(SIGTRAP, exit_code, CLD_TRAPPED);
@@ -2198,13 +2193,8 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
2198 struct signal_struct *signal = current->signal; 2193 struct signal_struct *signal = current->signal;
2199 int signr; 2194 int signr;
2200 2195
2201 if (unlikely(current->task_works)) { 2196 if (unlikely(current->task_works))
2202 if (test_and_clear_ti_thread_flag(current_thread_info(), 2197 task_work_run();
2203 TIF_NOTIFY_RESUME)) {
2204 smp_mb__after_clear_bit();
2205 task_work_run();
2206 }
2207 }
2208 2198
2209 if (unlikely(uprobe_deny_signal())) 2199 if (unlikely(uprobe_deny_signal()))
2210 return 0; 2200 return 0;
diff --git a/kernel/smpboot.c b/kernel/smpboot.c
index 98f60c5caa1b..d6c5fc054242 100644
--- a/kernel/smpboot.c
+++ b/kernel/smpboot.c
@@ -1,14 +1,22 @@
1/* 1/*
2 * Common SMP CPU bringup/teardown functions 2 * Common SMP CPU bringup/teardown functions
3 */ 3 */
4#include <linux/cpu.h>
4#include <linux/err.h> 5#include <linux/err.h>
5#include <linux/smp.h> 6#include <linux/smp.h>
6#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/list.h>
9#include <linux/slab.h>
7#include <linux/sched.h> 10#include <linux/sched.h>
11#include <linux/export.h>
8#include <linux/percpu.h> 12#include <linux/percpu.h>
13#include <linux/kthread.h>
14#include <linux/smpboot.h>
9 15
10#include "smpboot.h" 16#include "smpboot.h"
11 17
18#ifdef CONFIG_SMP
19
12#ifdef CONFIG_GENERIC_SMP_IDLE_THREAD 20#ifdef CONFIG_GENERIC_SMP_IDLE_THREAD
13/* 21/*
14 * For the hotplug case we keep the task structs around and reuse 22 * For the hotplug case we keep the task structs around and reuse
@@ -65,3 +73,228 @@ void __init idle_threads_init(void)
65 } 73 }
66} 74}
67#endif 75#endif
76
77#endif /* #ifdef CONFIG_SMP */
78
79static LIST_HEAD(hotplug_threads);
80static DEFINE_MUTEX(smpboot_threads_lock);
81
82struct smpboot_thread_data {
83 unsigned int cpu;
84 unsigned int status;
85 struct smp_hotplug_thread *ht;
86};
87
88enum {
89 HP_THREAD_NONE = 0,
90 HP_THREAD_ACTIVE,
91 HP_THREAD_PARKED,
92};
93
94/**
95 * smpboot_thread_fn - percpu hotplug thread loop function
96 * @data: thread data pointer
97 *
98 * Checks for thread stop and park conditions. Calls the necessary
99 * setup, cleanup, park and unpark functions for the registered
100 * thread.
101 *
102 * Returns 1 when the thread should exit, 0 otherwise.
103 */
104static int smpboot_thread_fn(void *data)
105{
106 struct smpboot_thread_data *td = data;
107 struct smp_hotplug_thread *ht = td->ht;
108
109 while (1) {
110 set_current_state(TASK_INTERRUPTIBLE);
111 preempt_disable();
112 if (kthread_should_stop()) {
113 set_current_state(TASK_RUNNING);
114 preempt_enable();
115 if (ht->cleanup)
116 ht->cleanup(td->cpu, cpu_online(td->cpu));
117 kfree(td);
118 return 0;
119 }
120
121 if (kthread_should_park()) {
122 __set_current_state(TASK_RUNNING);
123 preempt_enable();
124 if (ht->park && td->status == HP_THREAD_ACTIVE) {
125 BUG_ON(td->cpu != smp_processor_id());
126 ht->park(td->cpu);
127 td->status = HP_THREAD_PARKED;
128 }
129 kthread_parkme();
130 /* We might have been woken for stop */
131 continue;
132 }
133
134 BUG_ON(td->cpu != smp_processor_id());
135
136 /* Check for state change setup */
137 switch (td->status) {
138 case HP_THREAD_NONE:
139 preempt_enable();
140 if (ht->setup)
141 ht->setup(td->cpu);
142 td->status = HP_THREAD_ACTIVE;
143 preempt_disable();
144 break;
145 case HP_THREAD_PARKED:
146 preempt_enable();
147 if (ht->unpark)
148 ht->unpark(td->cpu);
149 td->status = HP_THREAD_ACTIVE;
150 preempt_disable();
151 break;
152 }
153
154 if (!ht->thread_should_run(td->cpu)) {
155 preempt_enable();
156 schedule();
157 } else {
158 set_current_state(TASK_RUNNING);
159 preempt_enable();
160 ht->thread_fn(td->cpu);
161 }
162 }
163}
164
165static int
166__smpboot_create_thread(struct smp_hotplug_thread *ht, unsigned int cpu)
167{
168 struct task_struct *tsk = *per_cpu_ptr(ht->store, cpu);
169 struct smpboot_thread_data *td;
170
171 if (tsk)
172 return 0;
173
174 td = kzalloc_node(sizeof(*td), GFP_KERNEL, cpu_to_node(cpu));
175 if (!td)
176 return -ENOMEM;
177 td->cpu = cpu;
178 td->ht = ht;
179
180 tsk = kthread_create_on_cpu(smpboot_thread_fn, td, cpu,
181 ht->thread_comm);
182 if (IS_ERR(tsk)) {
183 kfree(td);
184 return PTR_ERR(tsk);
185 }
186
187 get_task_struct(tsk);
188 *per_cpu_ptr(ht->store, cpu) = tsk;
189 return 0;
190}
191
192int smpboot_create_threads(unsigned int cpu)
193{
194 struct smp_hotplug_thread *cur;
195 int ret = 0;
196
197 mutex_lock(&smpboot_threads_lock);
198 list_for_each_entry(cur, &hotplug_threads, list) {
199 ret = __smpboot_create_thread(cur, cpu);
200 if (ret)
201 break;
202 }
203 mutex_unlock(&smpboot_threads_lock);
204 return ret;
205}
206
207static void smpboot_unpark_thread(struct smp_hotplug_thread *ht, unsigned int cpu)
208{
209 struct task_struct *tsk = *per_cpu_ptr(ht->store, cpu);
210
211 kthread_unpark(tsk);
212}
213
214void smpboot_unpark_threads(unsigned int cpu)
215{
216 struct smp_hotplug_thread *cur;
217
218 mutex_lock(&smpboot_threads_lock);
219 list_for_each_entry(cur, &hotplug_threads, list)
220 smpboot_unpark_thread(cur, cpu);
221 mutex_unlock(&smpboot_threads_lock);
222}
223
224static void smpboot_park_thread(struct smp_hotplug_thread *ht, unsigned int cpu)
225{
226 struct task_struct *tsk = *per_cpu_ptr(ht->store, cpu);
227
228 if (tsk)
229 kthread_park(tsk);
230}
231
232void smpboot_park_threads(unsigned int cpu)
233{
234 struct smp_hotplug_thread *cur;
235
236 mutex_lock(&smpboot_threads_lock);
237 list_for_each_entry_reverse(cur, &hotplug_threads, list)
238 smpboot_park_thread(cur, cpu);
239 mutex_unlock(&smpboot_threads_lock);
240}
241
242static void smpboot_destroy_threads(struct smp_hotplug_thread *ht)
243{
244 unsigned int cpu;
245
246 /* We need to destroy also the parked threads of offline cpus */
247 for_each_possible_cpu(cpu) {
248 struct task_struct *tsk = *per_cpu_ptr(ht->store, cpu);
249
250 if (tsk) {
251 kthread_stop(tsk);
252 put_task_struct(tsk);
253 *per_cpu_ptr(ht->store, cpu) = NULL;
254 }
255 }
256}
257
258/**
259 * smpboot_register_percpu_thread - Register a per_cpu thread related to hotplug
260 * @plug_thread: Hotplug thread descriptor
261 *
262 * Creates and starts the threads on all online cpus.
263 */
264int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
265{
266 unsigned int cpu;
267 int ret = 0;
268
269 mutex_lock(&smpboot_threads_lock);
270 for_each_online_cpu(cpu) {
271 ret = __smpboot_create_thread(plug_thread, cpu);
272 if (ret) {
273 smpboot_destroy_threads(plug_thread);
274 goto out;
275 }
276 smpboot_unpark_thread(plug_thread, cpu);
277 }
278 list_add(&plug_thread->list, &hotplug_threads);
279out:
280 mutex_unlock(&smpboot_threads_lock);
281 return ret;
282}
283EXPORT_SYMBOL_GPL(smpboot_register_percpu_thread);
284
285/**
286 * smpboot_unregister_percpu_thread - Unregister a per_cpu thread related to hotplug
287 * @plug_thread: Hotplug thread descriptor
288 *
289 * Stops all threads on all possible cpus.
290 */
291void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
292{
293 get_online_cpus();
294 mutex_lock(&smpboot_threads_lock);
295 list_del(&plug_thread->list);
296 smpboot_destroy_threads(plug_thread);
297 mutex_unlock(&smpboot_threads_lock);
298 put_online_cpus();
299}
300EXPORT_SYMBOL_GPL(smpboot_unregister_percpu_thread);
diff --git a/kernel/smpboot.h b/kernel/smpboot.h
index 6ef9433e1c70..72415a0eb955 100644
--- a/kernel/smpboot.h
+++ b/kernel/smpboot.h
@@ -13,4 +13,8 @@ static inline void idle_thread_set_boot_cpu(void) { }
13static inline void idle_threads_init(void) { } 13static inline void idle_threads_init(void) { }
14#endif 14#endif
15 15
16int smpboot_create_threads(unsigned int cpu);
17void smpboot_park_threads(unsigned int cpu);
18void smpboot_unpark_threads(unsigned int cpu);
19
16#endif 20#endif
diff --git a/kernel/softirq.c b/kernel/softirq.c
index b73e681df09e..5c6a5bd8462f 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -23,6 +23,7 @@
23#include <linux/rcupdate.h> 23#include <linux/rcupdate.h>
24#include <linux/ftrace.h> 24#include <linux/ftrace.h>
25#include <linux/smp.h> 25#include <linux/smp.h>
26#include <linux/smpboot.h>
26#include <linux/tick.h> 27#include <linux/tick.h>
27 28
28#define CREATE_TRACE_POINTS 29#define CREATE_TRACE_POINTS
@@ -742,49 +743,22 @@ void __init softirq_init(void)
742 open_softirq(HI_SOFTIRQ, tasklet_hi_action); 743 open_softirq(HI_SOFTIRQ, tasklet_hi_action);
743} 744}
744 745
745static int run_ksoftirqd(void * __bind_cpu) 746static int ksoftirqd_should_run(unsigned int cpu)
746{ 747{
747 set_current_state(TASK_INTERRUPTIBLE); 748 return local_softirq_pending();
748 749}
749 while (!kthread_should_stop()) {
750 preempt_disable();
751 if (!local_softirq_pending()) {
752 schedule_preempt_disabled();
753 }
754
755 __set_current_state(TASK_RUNNING);
756
757 while (local_softirq_pending()) {
758 /* Preempt disable stops cpu going offline.
759 If already offline, we'll be on wrong CPU:
760 don't process */
761 if (cpu_is_offline((long)__bind_cpu))
762 goto wait_to_die;
763 local_irq_disable();
764 if (local_softirq_pending())
765 __do_softirq();
766 local_irq_enable();
767 sched_preempt_enable_no_resched();
768 cond_resched();
769 preempt_disable();
770 rcu_note_context_switch((long)__bind_cpu);
771 }
772 preempt_enable();
773 set_current_state(TASK_INTERRUPTIBLE);
774 }
775 __set_current_state(TASK_RUNNING);
776 return 0;
777 750
778wait_to_die: 751static void run_ksoftirqd(unsigned int cpu)
779 preempt_enable(); 752{
780 /* Wait for kthread_stop */ 753 local_irq_disable();
781 set_current_state(TASK_INTERRUPTIBLE); 754 if (local_softirq_pending()) {
782 while (!kthread_should_stop()) { 755 __do_softirq();
783 schedule(); 756 rcu_note_context_switch(cpu);
784 set_current_state(TASK_INTERRUPTIBLE); 757 local_irq_enable();
758 cond_resched();
759 return;
785 } 760 }
786 __set_current_state(TASK_RUNNING); 761 local_irq_enable();
787 return 0;
788} 762}
789 763
790#ifdef CONFIG_HOTPLUG_CPU 764#ifdef CONFIG_HOTPLUG_CPU
@@ -850,50 +824,14 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
850 unsigned long action, 824 unsigned long action,
851 void *hcpu) 825 void *hcpu)
852{ 826{
853 int hotcpu = (unsigned long)hcpu;
854 struct task_struct *p;
855
856 switch (action) { 827 switch (action) {
857 case CPU_UP_PREPARE:
858 case CPU_UP_PREPARE_FROZEN:
859 p = kthread_create_on_node(run_ksoftirqd,
860 hcpu,
861 cpu_to_node(hotcpu),
862 "ksoftirqd/%d", hotcpu);
863 if (IS_ERR(p)) {
864 printk("ksoftirqd for %i failed\n", hotcpu);
865 return notifier_from_errno(PTR_ERR(p));
866 }
867 kthread_bind(p, hotcpu);
868 per_cpu(ksoftirqd, hotcpu) = p;
869 break;
870 case CPU_ONLINE:
871 case CPU_ONLINE_FROZEN:
872 wake_up_process(per_cpu(ksoftirqd, hotcpu));
873 break;
874#ifdef CONFIG_HOTPLUG_CPU 828#ifdef CONFIG_HOTPLUG_CPU
875 case CPU_UP_CANCELED:
876 case CPU_UP_CANCELED_FROZEN:
877 if (!per_cpu(ksoftirqd, hotcpu))
878 break;
879 /* Unbind so it can run. Fall thru. */
880 kthread_bind(per_cpu(ksoftirqd, hotcpu),
881 cpumask_any(cpu_online_mask));
882 case CPU_DEAD: 829 case CPU_DEAD:
883 case CPU_DEAD_FROZEN: { 830 case CPU_DEAD_FROZEN:
884 static const struct sched_param param = { 831 takeover_tasklets((unsigned long)hcpu);
885 .sched_priority = MAX_RT_PRIO-1
886 };
887
888 p = per_cpu(ksoftirqd, hotcpu);
889 per_cpu(ksoftirqd, hotcpu) = NULL;
890 sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
891 kthread_stop(p);
892 takeover_tasklets(hotcpu);
893 break; 832 break;
894 }
895#endif /* CONFIG_HOTPLUG_CPU */ 833#endif /* CONFIG_HOTPLUG_CPU */
896 } 834 }
897 return NOTIFY_OK; 835 return NOTIFY_OK;
898} 836}
899 837
@@ -901,14 +839,19 @@ static struct notifier_block __cpuinitdata cpu_nfb = {
901 .notifier_call = cpu_callback 839 .notifier_call = cpu_callback
902}; 840};
903 841
842static struct smp_hotplug_thread softirq_threads = {
843 .store = &ksoftirqd,
844 .thread_should_run = ksoftirqd_should_run,
845 .thread_fn = run_ksoftirqd,
846 .thread_comm = "ksoftirqd/%u",
847};
848
904static __init int spawn_ksoftirqd(void) 849static __init int spawn_ksoftirqd(void)
905{ 850{
906 void *cpu = (void *)(long)smp_processor_id();
907 int err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu);
908
909 BUG_ON(err != NOTIFY_OK);
910 cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
911 register_cpu_notifier(&cpu_nfb); 851 register_cpu_notifier(&cpu_nfb);
852
853 BUG_ON(smpboot_register_percpu_thread(&softirq_threads));
854
912 return 0; 855 return 0;
913} 856}
914early_initcall(spawn_ksoftirqd); 857early_initcall(spawn_ksoftirqd);
diff --git a/kernel/task_work.c b/kernel/task_work.c
index d320d44903bd..65bd3c92d6f3 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -2,26 +2,20 @@
2#include <linux/task_work.h> 2#include <linux/task_work.h>
3#include <linux/tracehook.h> 3#include <linux/tracehook.h>
4 4
5static struct callback_head work_exited; /* all we need is ->next == NULL */
6
5int 7int
6task_work_add(struct task_struct *task, struct callback_head *twork, bool notify) 8task_work_add(struct task_struct *task, struct callback_head *work, bool notify)
7{ 9{
8 struct callback_head *last, *first; 10 struct callback_head *head;
9 unsigned long flags;
10 11
11 /* 12 do {
12 * Not inserting the new work if the task has already passed 13 head = ACCESS_ONCE(task->task_works);
13 * exit_task_work() is the responisbility of callers. 14 if (unlikely(head == &work_exited))
14 */ 15 return -ESRCH;
15 raw_spin_lock_irqsave(&task->pi_lock, flags); 16 work->next = head;
16 last = task->task_works; 17 } while (cmpxchg(&task->task_works, head, work) != head);
17 first = last ? last->next : twork;
18 twork->next = first;
19 if (last)
20 last->next = twork;
21 task->task_works = twork;
22 raw_spin_unlock_irqrestore(&task->pi_lock, flags);
23 18
24 /* test_and_set_bit() implies mb(), see tracehook_notify_resume(). */
25 if (notify) 19 if (notify)
26 set_notify_resume(task); 20 set_notify_resume(task);
27 return 0; 21 return 0;
@@ -30,52 +24,69 @@ task_work_add(struct task_struct *task, struct callback_head *twork, bool notify
30struct callback_head * 24struct callback_head *
31task_work_cancel(struct task_struct *task, task_work_func_t func) 25task_work_cancel(struct task_struct *task, task_work_func_t func)
32{ 26{
27 struct callback_head **pprev = &task->task_works;
28 struct callback_head *work = NULL;
33 unsigned long flags; 29 unsigned long flags;
34 struct callback_head *last, *res = NULL; 30 /*
35 31 * If cmpxchg() fails we continue without updating pprev.
32 * Either we raced with task_work_add() which added the
33 * new entry before this work, we will find it again. Or
34 * we raced with task_work_run(), *pprev == NULL/exited.
35 */
36 raw_spin_lock_irqsave(&task->pi_lock, flags); 36 raw_spin_lock_irqsave(&task->pi_lock, flags);
37 last = task->task_works; 37 while ((work = ACCESS_ONCE(*pprev))) {
38 if (last) { 38 read_barrier_depends();
39 struct callback_head *q = last, *p = q->next; 39 if (work->func != func)
40 while (1) { 40 pprev = &work->next;
41 if (p->func == func) { 41 else if (cmpxchg(pprev, work, work->next) == work)
42 q->next = p->next; 42 break;
43 if (p == last)
44 task->task_works = q == p ? NULL : q;
45 res = p;
46 break;
47 }
48 if (p == last)
49 break;
50 q = p;
51 p = q->next;
52 }
53 } 43 }
54 raw_spin_unlock_irqrestore(&task->pi_lock, flags); 44 raw_spin_unlock_irqrestore(&task->pi_lock, flags);
55 return res; 45
46 return work;
56} 47}
57 48
58void task_work_run(void) 49void task_work_run(void)
59{ 50{
60 struct task_struct *task = current; 51 struct task_struct *task = current;
61 struct callback_head *p, *q; 52 struct callback_head *work, *head, *next;
53
54 for (;;) {
55 /*
56 * work->func() can do task_work_add(), do not set
57 * work_exited unless the list is empty.
58 */
59 do {
60 work = ACCESS_ONCE(task->task_works);
61 head = !work && (task->flags & PF_EXITING) ?
62 &work_exited : NULL;
63 } while (cmpxchg(&task->task_works, work, head) != work);
62 64
63 while (1) { 65 if (!work)
64 raw_spin_lock_irq(&task->pi_lock); 66 break;
65 p = task->task_works; 67 /*
66 task->task_works = NULL; 68 * Synchronize with task_work_cancel(). It can't remove
67 raw_spin_unlock_irq(&task->pi_lock); 69 * the first entry == work, cmpxchg(task_works) should
70 * fail, but it can play with *work and other entries.
71 */
72 raw_spin_unlock_wait(&task->pi_lock);
73 smp_mb();
68 74
69 if (unlikely(!p)) 75 /* Reverse the list to run the works in fifo order */
70 return; 76 head = NULL;
77 do {
78 next = work->next;
79 work->next = head;
80 head = work;
81 work = next;
82 } while (work);
71 83
72 q = p->next; /* head */ 84 work = head;
73 p->next = NULL; /* cut it */ 85 do {
74 while (q) { 86 next = work->next;
75 p = q->next; 87 work->func(work);
76 q->func(q); 88 work = next;
77 q = p;
78 cond_resched(); 89 cond_resched();
79 } 90 } while (work);
80 } 91 }
81} 92}
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 024540f97f74..cf5f6b262673 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -436,7 +436,8 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts)
436 if (unlikely(local_softirq_pending() && cpu_online(cpu))) { 436 if (unlikely(local_softirq_pending() && cpu_online(cpu))) {
437 static int ratelimit; 437 static int ratelimit;
438 438
439 if (ratelimit < 10) { 439 if (ratelimit < 10 &&
440 (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
440 printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n", 441 printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
441 (unsigned int) local_softirq_pending()); 442 (unsigned int) local_softirq_pending());
442 ratelimit++; 443 ratelimit++;
@@ -573,6 +574,7 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now)
573 tick_do_update_jiffies64(now); 574 tick_do_update_jiffies64(now);
574 update_cpu_load_nohz(); 575 update_cpu_load_nohz();
575 576
577 calc_load_exit_idle();
576 touch_softlockup_watchdog(); 578 touch_softlockup_watchdog();
577 /* 579 /*
578 * Cancel the scheduled timer and restore the tick 580 * Cancel the scheduled timer and restore the tick
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 34e5eac81424..d3b91e75cecd 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -303,10 +303,11 @@ void getnstimeofday(struct timespec *ts)
303 seq = read_seqbegin(&tk->lock); 303 seq = read_seqbegin(&tk->lock);
304 304
305 ts->tv_sec = tk->xtime_sec; 305 ts->tv_sec = tk->xtime_sec;
306 ts->tv_nsec = timekeeping_get_ns(tk); 306 nsecs = timekeeping_get_ns(tk);
307 307
308 } while (read_seqretry(&tk->lock, seq)); 308 } while (read_seqretry(&tk->lock, seq));
309 309
310 ts->tv_nsec = 0;
310 timespec_add_ns(ts, nsecs); 311 timespec_add_ns(ts, nsecs);
311} 312}
312EXPORT_SYMBOL(getnstimeofday); 313EXPORT_SYMBOL(getnstimeofday);
@@ -345,6 +346,7 @@ void ktime_get_ts(struct timespec *ts)
345{ 346{
346 struct timekeeper *tk = &timekeeper; 347 struct timekeeper *tk = &timekeeper;
347 struct timespec tomono; 348 struct timespec tomono;
349 s64 nsec;
348 unsigned int seq; 350 unsigned int seq;
349 351
350 WARN_ON(timekeeping_suspended); 352 WARN_ON(timekeeping_suspended);
@@ -352,13 +354,14 @@ void ktime_get_ts(struct timespec *ts)
352 do { 354 do {
353 seq = read_seqbegin(&tk->lock); 355 seq = read_seqbegin(&tk->lock);
354 ts->tv_sec = tk->xtime_sec; 356 ts->tv_sec = tk->xtime_sec;
355 ts->tv_nsec = timekeeping_get_ns(tk); 357 nsec = timekeeping_get_ns(tk);
356 tomono = tk->wall_to_monotonic; 358 tomono = tk->wall_to_monotonic;
357 359
358 } while (read_seqretry(&tk->lock, seq)); 360 } while (read_seqretry(&tk->lock, seq));
359 361
360 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec, 362 ts->tv_sec += tomono.tv_sec;
361 ts->tv_nsec + tomono.tv_nsec); 363 ts->tv_nsec = 0;
364 timespec_add_ns(ts, nsec + tomono.tv_nsec);
362} 365}
363EXPORT_SYMBOL_GPL(ktime_get_ts); 366EXPORT_SYMBOL_GPL(ktime_get_ts);
364 367
@@ -1244,6 +1247,7 @@ void get_monotonic_boottime(struct timespec *ts)
1244{ 1247{
1245 struct timekeeper *tk = &timekeeper; 1248 struct timekeeper *tk = &timekeeper;
1246 struct timespec tomono, sleep; 1249 struct timespec tomono, sleep;
1250 s64 nsec;
1247 unsigned int seq; 1251 unsigned int seq;
1248 1252
1249 WARN_ON(timekeeping_suspended); 1253 WARN_ON(timekeeping_suspended);
@@ -1251,14 +1255,15 @@ void get_monotonic_boottime(struct timespec *ts)
1251 do { 1255 do {
1252 seq = read_seqbegin(&tk->lock); 1256 seq = read_seqbegin(&tk->lock);
1253 ts->tv_sec = tk->xtime_sec; 1257 ts->tv_sec = tk->xtime_sec;
1254 ts->tv_nsec = timekeeping_get_ns(tk); 1258 nsec = timekeeping_get_ns(tk);
1255 tomono = tk->wall_to_monotonic; 1259 tomono = tk->wall_to_monotonic;
1256 sleep = tk->total_sleep_time; 1260 sleep = tk->total_sleep_time;
1257 1261
1258 } while (read_seqretry(&tk->lock, seq)); 1262 } while (read_seqretry(&tk->lock, seq));
1259 1263
1260 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec, 1264 ts->tv_sec += tomono.tv_sec + sleep.tv_sec;
1261 ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec); 1265 ts->tv_nsec = 0;
1266 timespec_add_ns(ts, nsec + tomono.tv_nsec + sleep.tv_nsec);
1262} 1267}
1263EXPORT_SYMBOL_GPL(get_monotonic_boottime); 1268EXPORT_SYMBOL_GPL(get_monotonic_boottime);
1264 1269
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 4b1dfba70f7c..9d4c8d5a1f53 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -22,6 +22,7 @@
22#include <linux/notifier.h> 22#include <linux/notifier.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/sysctl.h> 24#include <linux/sysctl.h>
25#include <linux/smpboot.h>
25 26
26#include <asm/irq_regs.h> 27#include <asm/irq_regs.h>
27#include <linux/kvm_para.h> 28#include <linux/kvm_para.h>
@@ -29,16 +30,18 @@
29 30
30int watchdog_enabled = 1; 31int watchdog_enabled = 1;
31int __read_mostly watchdog_thresh = 10; 32int __read_mostly watchdog_thresh = 10;
33static int __read_mostly watchdog_disabled;
32 34
33static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts); 35static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);
34static DEFINE_PER_CPU(struct task_struct *, softlockup_watchdog); 36static DEFINE_PER_CPU(struct task_struct *, softlockup_watchdog);
35static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer); 37static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer);
36static DEFINE_PER_CPU(bool, softlockup_touch_sync); 38static DEFINE_PER_CPU(bool, softlockup_touch_sync);
37static DEFINE_PER_CPU(bool, soft_watchdog_warn); 39static DEFINE_PER_CPU(bool, soft_watchdog_warn);
40static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts);
41static DEFINE_PER_CPU(unsigned long, soft_lockup_hrtimer_cnt);
38#ifdef CONFIG_HARDLOCKUP_DETECTOR 42#ifdef CONFIG_HARDLOCKUP_DETECTOR
39static DEFINE_PER_CPU(bool, hard_watchdog_warn); 43static DEFINE_PER_CPU(bool, hard_watchdog_warn);
40static DEFINE_PER_CPU(bool, watchdog_nmi_touch); 44static DEFINE_PER_CPU(bool, watchdog_nmi_touch);
41static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts);
42static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts_saved); 45static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts_saved);
43static DEFINE_PER_CPU(struct perf_event *, watchdog_ev); 46static DEFINE_PER_CPU(struct perf_event *, watchdog_ev);
44#endif 47#endif
@@ -248,13 +251,15 @@ static void watchdog_overflow_callback(struct perf_event *event,
248 __this_cpu_write(hard_watchdog_warn, false); 251 __this_cpu_write(hard_watchdog_warn, false);
249 return; 252 return;
250} 253}
254#endif /* CONFIG_HARDLOCKUP_DETECTOR */
255
251static void watchdog_interrupt_count(void) 256static void watchdog_interrupt_count(void)
252{ 257{
253 __this_cpu_inc(hrtimer_interrupts); 258 __this_cpu_inc(hrtimer_interrupts);
254} 259}
255#else 260
256static inline void watchdog_interrupt_count(void) { return; } 261static int watchdog_nmi_enable(unsigned int cpu);
257#endif /* CONFIG_HARDLOCKUP_DETECTOR */ 262static void watchdog_nmi_disable(unsigned int cpu);
258 263
259/* watchdog kicker functions */ 264/* watchdog kicker functions */
260static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) 265static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
@@ -327,49 +332,68 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
327 return HRTIMER_RESTART; 332 return HRTIMER_RESTART;
328} 333}
329 334
335static void watchdog_set_prio(unsigned int policy, unsigned int prio)
336{
337 struct sched_param param = { .sched_priority = prio };
330 338
331/* 339 sched_setscheduler(current, policy, &param);
332 * The watchdog thread - touches the timestamp. 340}
333 */ 341
334static int watchdog(void *unused) 342static void watchdog_enable(unsigned int cpu)
335{ 343{
336 struct sched_param param = { .sched_priority = 0 };
337 struct hrtimer *hrtimer = &__raw_get_cpu_var(watchdog_hrtimer); 344 struct hrtimer *hrtimer = &__raw_get_cpu_var(watchdog_hrtimer);
338 345
339 /* initialize timestamp */ 346 if (!watchdog_enabled) {
340 __touch_watchdog(); 347 kthread_park(current);
348 return;
349 }
350
351 /* Enable the perf event */
352 watchdog_nmi_enable(cpu);
341 353
342 /* kick off the timer for the hardlockup detector */ 354 /* kick off the timer for the hardlockup detector */
355 hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
356 hrtimer->function = watchdog_timer_fn;
357
343 /* done here because hrtimer_start can only pin to smp_processor_id() */ 358 /* done here because hrtimer_start can only pin to smp_processor_id() */
344 hrtimer_start(hrtimer, ns_to_ktime(get_sample_period()), 359 hrtimer_start(hrtimer, ns_to_ktime(get_sample_period()),
345 HRTIMER_MODE_REL_PINNED); 360 HRTIMER_MODE_REL_PINNED);
346 361
347 set_current_state(TASK_INTERRUPTIBLE); 362 /* initialize timestamp */
348 /* 363 watchdog_set_prio(SCHED_FIFO, MAX_RT_PRIO - 1);
349 * Run briefly (kicked by the hrtimer callback function) once every 364 __touch_watchdog();
350 * get_sample_period() seconds (4 seconds by default) to reset the 365}
351 * softlockup timestamp. If this gets delayed for more than
352 * 2*watchdog_thresh seconds then the debug-printout triggers in
353 * watchdog_timer_fn().
354 */
355 while (!kthread_should_stop()) {
356 __touch_watchdog();
357 schedule();
358 366
359 if (kthread_should_stop()) 367static void watchdog_disable(unsigned int cpu)
360 break; 368{
369 struct hrtimer *hrtimer = &__raw_get_cpu_var(watchdog_hrtimer);
361 370
362 set_current_state(TASK_INTERRUPTIBLE); 371 watchdog_set_prio(SCHED_NORMAL, 0);
363 } 372 hrtimer_cancel(hrtimer);
364 /* 373 /* disable the perf event */
365 * Drop the policy/priority elevation during thread exit to avoid a 374 watchdog_nmi_disable(cpu);
366 * scheduling latency spike.
367 */
368 __set_current_state(TASK_RUNNING);
369 sched_setscheduler(current, SCHED_NORMAL, &param);
370 return 0;
371} 375}
372 376
377static int watchdog_should_run(unsigned int cpu)
378{
379 return __this_cpu_read(hrtimer_interrupts) !=
380 __this_cpu_read(soft_lockup_hrtimer_cnt);
381}
382
383/*
384 * The watchdog thread function - touches the timestamp.
385 *
386 * It only runs once every get_sample_period() seconds (4 seconds by
387 * default) to reset the softlockup timestamp. If this gets delayed
388 * for more than 2*watchdog_thresh seconds then the debug-printout
389 * triggers in watchdog_timer_fn().
390 */
391static void watchdog(unsigned int cpu)
392{
393 __this_cpu_write(soft_lockup_hrtimer_cnt,
394 __this_cpu_read(hrtimer_interrupts));
395 __touch_watchdog();
396}
373 397
374#ifdef CONFIG_HARDLOCKUP_DETECTOR 398#ifdef CONFIG_HARDLOCKUP_DETECTOR
375/* 399/*
@@ -379,7 +403,7 @@ static int watchdog(void *unused)
379 */ 403 */
380static unsigned long cpu0_err; 404static unsigned long cpu0_err;
381 405
382static int watchdog_nmi_enable(int cpu) 406static int watchdog_nmi_enable(unsigned int cpu)
383{ 407{
384 struct perf_event_attr *wd_attr; 408 struct perf_event_attr *wd_attr;
385 struct perf_event *event = per_cpu(watchdog_ev, cpu); 409 struct perf_event *event = per_cpu(watchdog_ev, cpu);
@@ -433,7 +457,7 @@ out:
433 return 0; 457 return 0;
434} 458}
435 459
436static void watchdog_nmi_disable(int cpu) 460static void watchdog_nmi_disable(unsigned int cpu)
437{ 461{
438 struct perf_event *event = per_cpu(watchdog_ev, cpu); 462 struct perf_event *event = per_cpu(watchdog_ev, cpu);
439 463
@@ -447,107 +471,35 @@ static void watchdog_nmi_disable(int cpu)
447 return; 471 return;
448} 472}
449#else 473#else
450static int watchdog_nmi_enable(int cpu) { return 0; } 474static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
451static void watchdog_nmi_disable(int cpu) { return; } 475static void watchdog_nmi_disable(unsigned int cpu) { return; }
452#endif /* CONFIG_HARDLOCKUP_DETECTOR */ 476#endif /* CONFIG_HARDLOCKUP_DETECTOR */
453 477
454/* prepare/enable/disable routines */ 478/* prepare/enable/disable routines */
455static void watchdog_prepare_cpu(int cpu)
456{
457 struct hrtimer *hrtimer = &per_cpu(watchdog_hrtimer, cpu);
458
459 WARN_ON(per_cpu(softlockup_watchdog, cpu));
460 hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
461 hrtimer->function = watchdog_timer_fn;
462}
463
464static int watchdog_enable(int cpu)
465{
466 struct task_struct *p = per_cpu(softlockup_watchdog, cpu);
467 int err = 0;
468
469 /* enable the perf event */
470 err = watchdog_nmi_enable(cpu);
471
472 /* Regardless of err above, fall through and start softlockup */
473
474 /* create the watchdog thread */
475 if (!p) {
476 struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
477 p = kthread_create_on_node(watchdog, NULL, cpu_to_node(cpu), "watchdog/%d", cpu);
478 if (IS_ERR(p)) {
479 pr_err("softlockup watchdog for %i failed\n", cpu);
480 if (!err) {
481 /* if hardlockup hasn't already set this */
482 err = PTR_ERR(p);
483 /* and disable the perf event */
484 watchdog_nmi_disable(cpu);
485 }
486 goto out;
487 }
488 sched_setscheduler(p, SCHED_FIFO, &param);
489 kthread_bind(p, cpu);
490 per_cpu(watchdog_touch_ts, cpu) = 0;
491 per_cpu(softlockup_watchdog, cpu) = p;
492 wake_up_process(p);
493 }
494
495out:
496 return err;
497}
498
499static void watchdog_disable(int cpu)
500{
501 struct task_struct *p = per_cpu(softlockup_watchdog, cpu);
502 struct hrtimer *hrtimer = &per_cpu(watchdog_hrtimer, cpu);
503
504 /*
505 * cancel the timer first to stop incrementing the stats
506 * and waking up the kthread
507 */
508 hrtimer_cancel(hrtimer);
509
510 /* disable the perf event */
511 watchdog_nmi_disable(cpu);
512
513 /* stop the watchdog thread */
514 if (p) {
515 per_cpu(softlockup_watchdog, cpu) = NULL;
516 kthread_stop(p);
517 }
518}
519
520/* sysctl functions */ 479/* sysctl functions */
521#ifdef CONFIG_SYSCTL 480#ifdef CONFIG_SYSCTL
522static void watchdog_enable_all_cpus(void) 481static void watchdog_enable_all_cpus(void)
523{ 482{
524 int cpu; 483 unsigned int cpu;
525
526 watchdog_enabled = 0;
527
528 for_each_online_cpu(cpu)
529 if (!watchdog_enable(cpu))
530 /* if any cpu succeeds, watchdog is considered
531 enabled for the system */
532 watchdog_enabled = 1;
533
534 if (!watchdog_enabled)
535 pr_err("failed to be enabled on some cpus\n");
536 484
485 if (watchdog_disabled) {
486 watchdog_disabled = 0;
487 for_each_online_cpu(cpu)
488 kthread_unpark(per_cpu(softlockup_watchdog, cpu));
489 }
537} 490}
538 491
539static void watchdog_disable_all_cpus(void) 492static void watchdog_disable_all_cpus(void)
540{ 493{
541 int cpu; 494 unsigned int cpu;
542
543 for_each_online_cpu(cpu)
544 watchdog_disable(cpu);
545 495
546 /* if all watchdogs are disabled, then they are disabled for the system */ 496 if (!watchdog_disabled) {
547 watchdog_enabled = 0; 497 watchdog_disabled = 1;
498 for_each_online_cpu(cpu)
499 kthread_park(per_cpu(softlockup_watchdog, cpu));
500 }
548} 501}
549 502
550
551/* 503/*
552 * proc handler for /proc/sys/kernel/nmi_watchdog,watchdog_thresh 504 * proc handler for /proc/sys/kernel/nmi_watchdog,watchdog_thresh
553 */ 505 */
@@ -557,73 +509,36 @@ int proc_dowatchdog(struct ctl_table *table, int write,
557{ 509{
558 int ret; 510 int ret;
559 511
512 if (watchdog_disabled < 0)
513 return -ENODEV;
514
560 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); 515 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
561 if (ret || !write) 516 if (ret || !write)
562 goto out; 517 return ret;
563 518
564 if (watchdog_enabled && watchdog_thresh) 519 if (watchdog_enabled && watchdog_thresh)
565 watchdog_enable_all_cpus(); 520 watchdog_enable_all_cpus();
566 else 521 else
567 watchdog_disable_all_cpus(); 522 watchdog_disable_all_cpus();
568 523
569out:
570 return ret; 524 return ret;
571} 525}
572#endif /* CONFIG_SYSCTL */ 526#endif /* CONFIG_SYSCTL */
573 527
574 528static struct smp_hotplug_thread watchdog_threads = {
575/* 529 .store = &softlockup_watchdog,
576 * Create/destroy watchdog threads as CPUs come and go: 530 .thread_should_run = watchdog_should_run,
577 */ 531 .thread_fn = watchdog,
578static int __cpuinit 532 .thread_comm = "watchdog/%u",
579cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) 533 .setup = watchdog_enable,
580{ 534 .park = watchdog_disable,
581 int hotcpu = (unsigned long)hcpu; 535 .unpark = watchdog_enable,
582
583 switch (action) {
584 case CPU_UP_PREPARE:
585 case CPU_UP_PREPARE_FROZEN:
586 watchdog_prepare_cpu(hotcpu);
587 break;
588 case CPU_ONLINE:
589 case CPU_ONLINE_FROZEN:
590 if (watchdog_enabled)
591 watchdog_enable(hotcpu);
592 break;
593#ifdef CONFIG_HOTPLUG_CPU
594 case CPU_UP_CANCELED:
595 case CPU_UP_CANCELED_FROZEN:
596 watchdog_disable(hotcpu);
597 break;
598 case CPU_DEAD:
599 case CPU_DEAD_FROZEN:
600 watchdog_disable(hotcpu);
601 break;
602#endif /* CONFIG_HOTPLUG_CPU */
603 }
604
605 /*
606 * hardlockup and softlockup are not important enough
607 * to block cpu bring up. Just always succeed and
608 * rely on printk output to flag problems.
609 */
610 return NOTIFY_OK;
611}
612
613static struct notifier_block __cpuinitdata cpu_nfb = {
614 .notifier_call = cpu_callback
615}; 536};
616 537
617void __init lockup_detector_init(void) 538void __init lockup_detector_init(void)
618{ 539{
619 void *cpu = (void *)(long)smp_processor_id(); 540 if (smpboot_register_percpu_thread(&watchdog_threads)) {
620 int err; 541 pr_err("Failed to create watchdog threads, disabled\n");
621 542 watchdog_disabled = -ENODEV;
622 err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu); 543 }
623 WARN_ON(notifier_to_errno(err));
624
625 cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
626 register_cpu_notifier(&cpu_nfb);
627
628 return;
629} 544}
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 692d97628a10..3c5a79e2134c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -66,6 +66,7 @@ enum {
66 66
67 /* pool flags */ 67 /* pool flags */
68 POOL_MANAGE_WORKERS = 1 << 0, /* need to manage workers */ 68 POOL_MANAGE_WORKERS = 1 << 0, /* need to manage workers */
69 POOL_MANAGING_WORKERS = 1 << 1, /* managing workers */
69 70
70 /* worker flags */ 71 /* worker flags */
71 WORKER_STARTED = 1 << 0, /* started */ 72 WORKER_STARTED = 1 << 0, /* started */
@@ -652,7 +653,7 @@ static bool need_to_manage_workers(struct worker_pool *pool)
652/* Do we have too many workers and should some go away? */ 653/* Do we have too many workers and should some go away? */
653static bool too_many_workers(struct worker_pool *pool) 654static bool too_many_workers(struct worker_pool *pool)
654{ 655{
655 bool managing = mutex_is_locked(&pool->manager_mutex); 656 bool managing = pool->flags & POOL_MANAGING_WORKERS;
656 int nr_idle = pool->nr_idle + managing; /* manager is considered idle */ 657 int nr_idle = pool->nr_idle + managing; /* manager is considered idle */
657 int nr_busy = pool->nr_workers - nr_idle; 658 int nr_busy = pool->nr_workers - nr_idle;
658 659
@@ -1326,6 +1327,15 @@ static void idle_worker_rebind(struct worker *worker)
1326 1327
1327 /* we did our part, wait for rebind_workers() to finish up */ 1328 /* we did our part, wait for rebind_workers() to finish up */
1328 wait_event(gcwq->rebind_hold, !(worker->flags & WORKER_REBIND)); 1329 wait_event(gcwq->rebind_hold, !(worker->flags & WORKER_REBIND));
1330
1331 /*
1332 * rebind_workers() shouldn't finish until all workers passed the
1333 * above WORKER_REBIND wait. Tell it when done.
1334 */
1335 spin_lock_irq(&worker->pool->gcwq->lock);
1336 if (!--worker->idle_rebind->cnt)
1337 complete(&worker->idle_rebind->done);
1338 spin_unlock_irq(&worker->pool->gcwq->lock);
1329} 1339}
1330 1340
1331/* 1341/*
@@ -1339,8 +1349,16 @@ static void busy_worker_rebind_fn(struct work_struct *work)
1339 struct worker *worker = container_of(work, struct worker, rebind_work); 1349 struct worker *worker = container_of(work, struct worker, rebind_work);
1340 struct global_cwq *gcwq = worker->pool->gcwq; 1350 struct global_cwq *gcwq = worker->pool->gcwq;
1341 1351
1342 if (worker_maybe_bind_and_lock(worker)) 1352 worker_maybe_bind_and_lock(worker);
1343 worker_clr_flags(worker, WORKER_REBIND); 1353
1354 /*
1355 * %WORKER_REBIND must be cleared even if the above binding failed;
1356 * otherwise, we may confuse the next CPU_UP cycle or oops / get
1357 * stuck by calling idle_worker_rebind() prematurely. If CPU went
1358 * down again inbetween, %WORKER_UNBOUND would be set, so clearing
1359 * %WORKER_REBIND is always safe.
1360 */
1361 worker_clr_flags(worker, WORKER_REBIND);
1344 1362
1345 spin_unlock_irq(&gcwq->lock); 1363 spin_unlock_irq(&gcwq->lock);
1346} 1364}
@@ -1396,12 +1414,15 @@ retry:
1396 /* set REBIND and kick idle ones, we'll wait for these later */ 1414 /* set REBIND and kick idle ones, we'll wait for these later */
1397 for_each_worker_pool(pool, gcwq) { 1415 for_each_worker_pool(pool, gcwq) {
1398 list_for_each_entry(worker, &pool->idle_list, entry) { 1416 list_for_each_entry(worker, &pool->idle_list, entry) {
1417 unsigned long worker_flags = worker->flags;
1418
1399 if (worker->flags & WORKER_REBIND) 1419 if (worker->flags & WORKER_REBIND)
1400 continue; 1420 continue;
1401 1421
1402 /* morph UNBOUND to REBIND */ 1422 /* morph UNBOUND to REBIND atomically */
1403 worker->flags &= ~WORKER_UNBOUND; 1423 worker_flags &= ~WORKER_UNBOUND;
1404 worker->flags |= WORKER_REBIND; 1424 worker_flags |= WORKER_REBIND;
1425 ACCESS_ONCE(worker->flags) = worker_flags;
1405 1426
1406 idle_rebind.cnt++; 1427 idle_rebind.cnt++;
1407 worker->idle_rebind = &idle_rebind; 1428 worker->idle_rebind = &idle_rebind;
@@ -1419,25 +1440,15 @@ retry:
1419 goto retry; 1440 goto retry;
1420 } 1441 }
1421 1442
1422 /* 1443 /* all idle workers are rebound, rebind busy workers */
1423 * All idle workers are rebound and waiting for %WORKER_REBIND to
1424 * be cleared inside idle_worker_rebind(). Clear and release.
1425 * Clearing %WORKER_REBIND from this foreign context is safe
1426 * because these workers are still guaranteed to be idle.
1427 */
1428 for_each_worker_pool(pool, gcwq)
1429 list_for_each_entry(worker, &pool->idle_list, entry)
1430 worker->flags &= ~WORKER_REBIND;
1431
1432 wake_up_all(&gcwq->rebind_hold);
1433
1434 /* rebind busy workers */
1435 for_each_busy_worker(worker, i, pos, gcwq) { 1444 for_each_busy_worker(worker, i, pos, gcwq) {
1436 struct work_struct *rebind_work = &worker->rebind_work; 1445 struct work_struct *rebind_work = &worker->rebind_work;
1446 unsigned long worker_flags = worker->flags;
1437 1447
1438 /* morph UNBOUND to REBIND */ 1448 /* morph UNBOUND to REBIND atomically */
1439 worker->flags &= ~WORKER_UNBOUND; 1449 worker_flags &= ~WORKER_UNBOUND;
1440 worker->flags |= WORKER_REBIND; 1450 worker_flags |= WORKER_REBIND;
1451 ACCESS_ONCE(worker->flags) = worker_flags;
1441 1452
1442 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT, 1453 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
1443 work_data_bits(rebind_work))) 1454 work_data_bits(rebind_work)))
@@ -1449,6 +1460,34 @@ retry:
1449 worker->scheduled.next, 1460 worker->scheduled.next,
1450 work_color_to_flags(WORK_NO_COLOR)); 1461 work_color_to_flags(WORK_NO_COLOR));
1451 } 1462 }
1463
1464 /*
1465 * All idle workers are rebound and waiting for %WORKER_REBIND to
1466 * be cleared inside idle_worker_rebind(). Clear and release.
1467 * Clearing %WORKER_REBIND from this foreign context is safe
1468 * because these workers are still guaranteed to be idle.
1469 *
1470 * We need to make sure all idle workers passed WORKER_REBIND wait
1471 * in idle_worker_rebind() before returning; otherwise, workers can
1472 * get stuck at the wait if hotplug cycle repeats.
1473 */
1474 idle_rebind.cnt = 1;
1475 INIT_COMPLETION(idle_rebind.done);
1476
1477 for_each_worker_pool(pool, gcwq) {
1478 list_for_each_entry(worker, &pool->idle_list, entry) {
1479 worker->flags &= ~WORKER_REBIND;
1480 idle_rebind.cnt++;
1481 }
1482 }
1483
1484 wake_up_all(&gcwq->rebind_hold);
1485
1486 if (--idle_rebind.cnt) {
1487 spin_unlock_irq(&gcwq->lock);
1488 wait_for_completion(&idle_rebind.done);
1489 spin_lock_irq(&gcwq->lock);
1490 }
1452} 1491}
1453 1492
1454static struct worker *alloc_worker(void) 1493static struct worker *alloc_worker(void)
@@ -1794,9 +1833,45 @@ static bool manage_workers(struct worker *worker)
1794 struct worker_pool *pool = worker->pool; 1833 struct worker_pool *pool = worker->pool;
1795 bool ret = false; 1834 bool ret = false;
1796 1835
1797 if (!mutex_trylock(&pool->manager_mutex)) 1836 if (pool->flags & POOL_MANAGING_WORKERS)
1798 return ret; 1837 return ret;
1799 1838
1839 pool->flags |= POOL_MANAGING_WORKERS;
1840
1841 /*
1842 * To simplify both worker management and CPU hotplug, hold off
1843 * management while hotplug is in progress. CPU hotplug path can't
1844 * grab %POOL_MANAGING_WORKERS to achieve this because that can
1845 * lead to idle worker depletion (all become busy thinking someone
1846 * else is managing) which in turn can result in deadlock under
1847 * extreme circumstances. Use @pool->manager_mutex to synchronize
1848 * manager against CPU hotplug.
1849 *
1850 * manager_mutex would always be free unless CPU hotplug is in
1851 * progress. trylock first without dropping @gcwq->lock.
1852 */
1853 if (unlikely(!mutex_trylock(&pool->manager_mutex))) {
1854 spin_unlock_irq(&pool->gcwq->lock);
1855 mutex_lock(&pool->manager_mutex);
1856 /*
1857 * CPU hotplug could have happened while we were waiting
1858 * for manager_mutex. Hotplug itself can't handle us
1859 * because manager isn't either on idle or busy list, and
1860 * @gcwq's state and ours could have deviated.
1861 *
1862 * As hotplug is now excluded via manager_mutex, we can
1863 * simply try to bind. It will succeed or fail depending
1864 * on @gcwq's current state. Try it and adjust
1865 * %WORKER_UNBOUND accordingly.
1866 */
1867 if (worker_maybe_bind_and_lock(worker))
1868 worker->flags &= ~WORKER_UNBOUND;
1869 else
1870 worker->flags |= WORKER_UNBOUND;
1871
1872 ret = true;
1873 }
1874
1800 pool->flags &= ~POOL_MANAGE_WORKERS; 1875 pool->flags &= ~POOL_MANAGE_WORKERS;
1801 1876
1802 /* 1877 /*
@@ -1806,6 +1881,7 @@ static bool manage_workers(struct worker *worker)
1806 ret |= maybe_destroy_workers(pool); 1881 ret |= maybe_destroy_workers(pool);
1807 ret |= maybe_create_worker(pool); 1882 ret |= maybe_create_worker(pool);
1808 1883
1884 pool->flags &= ~POOL_MANAGING_WORKERS;
1809 mutex_unlock(&pool->manager_mutex); 1885 mutex_unlock(&pool->manager_mutex);
1810 return ret; 1886 return ret;
1811} 1887}
@@ -3500,18 +3576,17 @@ static int __devinit workqueue_cpu_down_callback(struct notifier_block *nfb,
3500#ifdef CONFIG_SMP 3576#ifdef CONFIG_SMP
3501 3577
3502struct work_for_cpu { 3578struct work_for_cpu {
3503 struct completion completion; 3579 struct work_struct work;
3504 long (*fn)(void *); 3580 long (*fn)(void *);
3505 void *arg; 3581 void *arg;
3506 long ret; 3582 long ret;
3507}; 3583};
3508 3584
3509static int do_work_for_cpu(void *_wfc) 3585static void work_for_cpu_fn(struct work_struct *work)
3510{ 3586{
3511 struct work_for_cpu *wfc = _wfc; 3587 struct work_for_cpu *wfc = container_of(work, struct work_for_cpu, work);
3588
3512 wfc->ret = wfc->fn(wfc->arg); 3589 wfc->ret = wfc->fn(wfc->arg);
3513 complete(&wfc->completion);
3514 return 0;
3515} 3590}
3516 3591
3517/** 3592/**
@@ -3526,19 +3601,11 @@ static int do_work_for_cpu(void *_wfc)
3526 */ 3601 */
3527long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) 3602long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg)
3528{ 3603{
3529 struct task_struct *sub_thread; 3604 struct work_for_cpu wfc = { .fn = fn, .arg = arg };
3530 struct work_for_cpu wfc = {
3531 .completion = COMPLETION_INITIALIZER_ONSTACK(wfc.completion),
3532 .fn = fn,
3533 .arg = arg,
3534 };
3535 3605
3536 sub_thread = kthread_create(do_work_for_cpu, &wfc, "work_for_cpu"); 3606 INIT_WORK_ONSTACK(&wfc.work, work_for_cpu_fn);
3537 if (IS_ERR(sub_thread)) 3607 schedule_work_on(cpu, &wfc.work);
3538 return PTR_ERR(sub_thread); 3608 flush_work(&wfc.work);
3539 kthread_bind(sub_thread, cpu);
3540 wake_up_process(sub_thread);
3541 wait_for_completion(&wfc.completion);
3542 return wfc.ret; 3609 return wfc.ret;
3543} 3610}
3544EXPORT_SYMBOL_GPL(work_on_cpu); 3611EXPORT_SYMBOL_GPL(work_on_cpu);
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2403a63b5da5..dacbbe4d7a80 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -629,6 +629,20 @@ config PROVE_RCU_REPEATEDLY
629 629
630 Say N if you are unsure. 630 Say N if you are unsure.
631 631
632config PROVE_RCU_DELAY
633 bool "RCU debugging: preemptible RCU race provocation"
634 depends on DEBUG_KERNEL && PREEMPT_RCU
635 default n
636 help
637 There is a class of races that involve an unlikely preemption
638 of __rcu_read_unlock() just after ->rcu_read_lock_nesting has
639 been set to INT_MIN. This feature inserts a delay at that
640 point to increase the probability of these races.
641
642 Say Y to increase probability of preemption of __rcu_read_unlock().
643
644 Say N if you are unsure.
645
632config SPARSE_RCU_POINTER 646config SPARSE_RCU_POINTER
633 bool "RCU debugging: sparse-based checks for pointer usage" 647 bool "RCU debugging: sparse-based checks for pointer usage"
634 default n 648 default n
diff --git a/lib/digsig.c b/lib/digsig.c
index 286d558033e2..8c0e62975c88 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -163,9 +163,11 @@ static int digsig_verify_rsa(struct key *key,
163 memcpy(out1 + head, p, l); 163 memcpy(out1 + head, p, l);
164 164
165 err = pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len); 165 err = pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len);
166 if (err)
167 goto err;
166 168
167 if (!err && len == hlen) 169 if (len != hlen || memcmp(out2, h, hlen))
168 err = memcmp(out2, h, hlen); 170 err = -EINVAL;
169 171
170err: 172err:
171 mpi_free(in); 173 mpi_free(in);
diff --git a/lib/flex_proportions.c b/lib/flex_proportions.c
index c785554f9523..ebf3bac460b0 100644
--- a/lib/flex_proportions.c
+++ b/lib/flex_proportions.c
@@ -62,7 +62,7 @@ void fprop_global_destroy(struct fprop_global *p)
62 */ 62 */
63bool fprop_new_period(struct fprop_global *p, int periods) 63bool fprop_new_period(struct fprop_global *p, int periods)
64{ 64{
65 u64 events; 65 s64 events;
66 unsigned long flags; 66 unsigned long flags;
67 67
68 local_irq_save(flags); 68 local_irq_save(flags);
diff --git a/mm/bootmem.c b/mm/bootmem.c
index bcb63ac48cc5..f468185b3b28 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -419,7 +419,7 @@ int __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
419} 419}
420 420
421/** 421/**
422 * reserve_bootmem - mark a page range as usable 422 * reserve_bootmem - mark a page range as reserved
423 * @addr: starting address of the range 423 * @addr: starting address of the range
424 * @size: size of the range in bytes 424 * @size: size of the range in bytes
425 * @flags: reservation flags (see linux/bootmem.h) 425 * @flags: reservation flags (see linux/bootmem.h)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 57c4b9309015..141dbb695097 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1811,7 +1811,6 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page,
1811 src_page = pte_page(pteval); 1811 src_page = pte_page(pteval);
1812 copy_user_highpage(page, src_page, address, vma); 1812 copy_user_highpage(page, src_page, address, vma);
1813 VM_BUG_ON(page_mapcount(src_page) != 1); 1813 VM_BUG_ON(page_mapcount(src_page) != 1);
1814 VM_BUG_ON(page_count(src_page) != 2);
1815 release_pte_page(src_page); 1814 release_pte_page(src_page);
1816 /* 1815 /*
1817 * ptl mostly unnecessary, but preempt has to 1816 * ptl mostly unnecessary, but preempt has to
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 45eb6217bf38..0de83b4541e9 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1483,13 +1483,11 @@ static void *kmemleak_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1483{ 1483{
1484 struct kmemleak_object *prev_obj = v; 1484 struct kmemleak_object *prev_obj = v;
1485 struct kmemleak_object *next_obj = NULL; 1485 struct kmemleak_object *next_obj = NULL;
1486 struct list_head *n = &prev_obj->object_list; 1486 struct kmemleak_object *obj = prev_obj;
1487 1487
1488 ++(*pos); 1488 ++(*pos);
1489 1489
1490 list_for_each_continue_rcu(n, &object_list) { 1490 list_for_each_entry_continue_rcu(obj, &object_list, object_list) {
1491 struct kmemleak_object *obj =
1492 list_entry(n, struct kmemleak_object, object_list);
1493 if (get_object(obj)) { 1491 if (get_object(obj)) {
1494 next_obj = obj; 1492 next_obj = obj;
1495 break; 1493 break;
diff --git a/mm/memblock.c b/mm/memblock.c
index 4d9393c7edc9..82aa349d2f7a 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -246,7 +246,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,
246 min(new_area_start, memblock.current_limit), 246 min(new_area_start, memblock.current_limit),
247 new_alloc_size, PAGE_SIZE); 247 new_alloc_size, PAGE_SIZE);
248 248
249 new_array = addr ? __va(addr) : 0; 249 new_array = addr ? __va(addr) : NULL;
250 } 250 }
251 if (!addr) { 251 if (!addr) {
252 pr_err("memblock: Failed to double %s array from %ld to %ld entries !\n", 252 pr_err("memblock: Failed to double %s array from %ld to %ld entries !\n",
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 3ad25f9d1fc1..6a5b90d0cfd7 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -126,9 +126,6 @@ static void register_page_bootmem_info_section(unsigned long start_pfn)
126 struct mem_section *ms; 126 struct mem_section *ms;
127 struct page *page, *memmap; 127 struct page *page, *memmap;
128 128
129 if (!pfn_valid(start_pfn))
130 return;
131
132 section_nr = pfn_to_section_nr(start_pfn); 129 section_nr = pfn_to_section_nr(start_pfn);
133 ms = __nr_to_section(section_nr); 130 ms = __nr_to_section(section_nr);
134 131
@@ -187,9 +184,16 @@ void register_page_bootmem_info_node(struct pglist_data *pgdat)
187 end_pfn = pfn + pgdat->node_spanned_pages; 184 end_pfn = pfn + pgdat->node_spanned_pages;
188 185
189 /* register_section info */ 186 /* register_section info */
190 for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) 187 for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
191 register_page_bootmem_info_section(pfn); 188 /*
192 189 * Some platforms can assign the same pfn to multiple nodes - on
190 * node0 as well as nodeN. To avoid registering a pfn against
191 * multiple nodes we check that this pfn does not already
192 * reside in some other node.
193 */
194 if (pfn_valid(pfn) && (pfn_to_nid(pfn) == node))
195 register_page_bootmem_info_section(pfn);
196 }
193} 197}
194#endif /* !CONFIG_SPARSEMEM_VMEMMAP */ 198#endif /* !CONFIG_SPARSEMEM_VMEMMAP */
195 199
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index c66fb875104a..c13ea7538891 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -584,7 +584,7 @@ static inline void __free_one_page(struct page *page,
584 combined_idx = buddy_idx & page_idx; 584 combined_idx = buddy_idx & page_idx;
585 higher_page = page + (combined_idx - page_idx); 585 higher_page = page + (combined_idx - page_idx);
586 buddy_idx = __find_buddy_index(combined_idx, order + 1); 586 buddy_idx = __find_buddy_index(combined_idx, order + 1);
587 higher_buddy = page + (buddy_idx - combined_idx); 587 higher_buddy = higher_page + (buddy_idx - combined_idx);
588 if (page_is_buddy(higher_page, higher_buddy, order + 1)) { 588 if (page_is_buddy(higher_page, higher_buddy, order + 1)) {
589 list_add_tail(&page->lru, 589 list_add_tail(&page->lru,
590 &zone->free_area[order].free_list[migratetype]); 590 &zone->free_area[order].free_list[migratetype]);
diff --git a/mm/slab.c b/mm/slab.c
index 811af03a14ef..c6854759bcf1 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -983,7 +983,7 @@ static void *__ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac,
983 } 983 }
984 984
985 /* The caller cannot use PFMEMALLOC objects, find another one */ 985 /* The caller cannot use PFMEMALLOC objects, find another one */
986 for (i = 1; i < ac->avail; i++) { 986 for (i = 0; i < ac->avail; i++) {
987 /* If a !PFMEMALLOC object is found, swap them */ 987 /* If a !PFMEMALLOC object is found, swap them */
988 if (!is_obj_pfmemalloc(ac->entry[i])) { 988 if (!is_obj_pfmemalloc(ac->entry[i])) {
989 objp = ac->entry[i]; 989 objp = ac->entry[i];
@@ -1000,7 +1000,7 @@ static void *__ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac,
1000 l3 = cachep->nodelists[numa_mem_id()]; 1000 l3 = cachep->nodelists[numa_mem_id()];
1001 if (!list_empty(&l3->slabs_free) && force_refill) { 1001 if (!list_empty(&l3->slabs_free) && force_refill) {
1002 struct slab *slabp = virt_to_slab(objp); 1002 struct slab *slabp = virt_to_slab(objp);
1003 ClearPageSlabPfmemalloc(virt_to_page(slabp->s_mem)); 1003 ClearPageSlabPfmemalloc(virt_to_head_page(slabp->s_mem));
1004 clear_obj_pfmemalloc(&objp); 1004 clear_obj_pfmemalloc(&objp);
1005 recheck_pfmemalloc_active(cachep, ac); 1005 recheck_pfmemalloc_active(cachep, ac);
1006 return objp; 1006 return objp;
@@ -1032,7 +1032,7 @@ static void *__ac_put_obj(struct kmem_cache *cachep, struct array_cache *ac,
1032{ 1032{
1033 if (unlikely(pfmemalloc_active)) { 1033 if (unlikely(pfmemalloc_active)) {
1034 /* Some pfmemalloc slabs exist, check if this is one */ 1034 /* Some pfmemalloc slabs exist, check if this is one */
1035 struct page *page = virt_to_page(objp); 1035 struct page *page = virt_to_head_page(objp);
1036 if (PageSlabPfmemalloc(page)) 1036 if (PageSlabPfmemalloc(page))
1037 set_obj_pfmemalloc(&objp); 1037 set_obj_pfmemalloc(&objp);
1038 } 1038 }
diff --git a/mm/slub.c b/mm/slub.c
index 8f78e2577031..2fdd96f9e998 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1524,12 +1524,13 @@ static inline void *acquire_slab(struct kmem_cache *s,
1524} 1524}
1525 1525
1526static int put_cpu_partial(struct kmem_cache *s, struct page *page, int drain); 1526static int put_cpu_partial(struct kmem_cache *s, struct page *page, int drain);
1527static inline bool pfmemalloc_match(struct page *page, gfp_t gfpflags);
1527 1528
1528/* 1529/*
1529 * Try to allocate a partial slab from a specific node. 1530 * Try to allocate a partial slab from a specific node.
1530 */ 1531 */
1531static void *get_partial_node(struct kmem_cache *s, 1532static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
1532 struct kmem_cache_node *n, struct kmem_cache_cpu *c) 1533 struct kmem_cache_cpu *c, gfp_t flags)
1533{ 1534{
1534 struct page *page, *page2; 1535 struct page *page, *page2;
1535 void *object = NULL; 1536 void *object = NULL;
@@ -1545,9 +1546,13 @@ static void *get_partial_node(struct kmem_cache *s,
1545 1546
1546 spin_lock(&n->list_lock); 1547 spin_lock(&n->list_lock);
1547 list_for_each_entry_safe(page, page2, &n->partial, lru) { 1548 list_for_each_entry_safe(page, page2, &n->partial, lru) {
1548 void *t = acquire_slab(s, n, page, object == NULL); 1549 void *t;
1549 int available; 1550 int available;
1550 1551
1552 if (!pfmemalloc_match(page, flags))
1553 continue;
1554
1555 t = acquire_slab(s, n, page, object == NULL);
1551 if (!t) 1556 if (!t)
1552 break; 1557 break;
1553 1558
@@ -1614,7 +1619,7 @@ static void *get_any_partial(struct kmem_cache *s, gfp_t flags,
1614 1619
1615 if (n && cpuset_zone_allowed_hardwall(zone, flags) && 1620 if (n && cpuset_zone_allowed_hardwall(zone, flags) &&
1616 n->nr_partial > s->min_partial) { 1621 n->nr_partial > s->min_partial) {
1617 object = get_partial_node(s, n, c); 1622 object = get_partial_node(s, n, c, flags);
1618 if (object) { 1623 if (object) {
1619 /* 1624 /*
1620 * Return the object even if 1625 * Return the object even if
@@ -1643,7 +1648,7 @@ static void *get_partial(struct kmem_cache *s, gfp_t flags, int node,
1643 void *object; 1648 void *object;
1644 int searchnode = (node == NUMA_NO_NODE) ? numa_node_id() : node; 1649 int searchnode = (node == NUMA_NO_NODE) ? numa_node_id() : node;
1645 1650
1646 object = get_partial_node(s, get_node(s, searchnode), c); 1651 object = get_partial_node(s, get_node(s, searchnode), c, flags);
1647 if (object || node != NUMA_NO_NODE) 1652 if (object || node != NUMA_NO_NODE)
1648 return object; 1653 return object;
1649 1654
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8d01243d9560..99b434b674c0 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3102,6 +3102,7 @@ int kswapd_run(int nid)
3102 /* failure at boot is fatal */ 3102 /* failure at boot is fatal */
3103 BUG_ON(system_state == SYSTEM_BOOTING); 3103 BUG_ON(system_state == SYSTEM_BOOTING);
3104 printk("Failed to start kswapd on node %d\n",nid); 3104 printk("Failed to start kswapd on node %d\n",nid);
3105 pgdat->kswapd = NULL;
3105 ret = -1; 3106 ret = -1;
3106 } 3107 }
3107 return ret; 3108 return ret;
diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
index c718fd3664b6..4de77ea5fa37 100644
--- a/net/8021q/vlanproc.c
+++ b/net/8021q/vlanproc.c
@@ -105,7 +105,7 @@ static const struct file_operations vlandev_fops = {
105}; 105};
106 106
107/* 107/*
108 * Proc filesystem derectory entries. 108 * Proc filesystem directory entries.
109 */ 109 */
110 110
111/* Strings */ 111/* Strings */
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index e877af8bdd1e..469daabd90c7 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -642,7 +642,8 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
642 struct batadv_neigh_node *router = NULL; 642 struct batadv_neigh_node *router = NULL;
643 struct batadv_orig_node *orig_node_tmp; 643 struct batadv_orig_node *orig_node_tmp;
644 struct hlist_node *node; 644 struct hlist_node *node;
645 uint8_t bcast_own_sum_orig, bcast_own_sum_neigh; 645 int if_num;
646 uint8_t sum_orig, sum_neigh;
646 uint8_t *neigh_addr; 647 uint8_t *neigh_addr;
647 648
648 batadv_dbg(BATADV_DBG_BATMAN, bat_priv, 649 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
@@ -727,17 +728,17 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
727 if (router && (neigh_node->tq_avg == router->tq_avg)) { 728 if (router && (neigh_node->tq_avg == router->tq_avg)) {
728 orig_node_tmp = router->orig_node; 729 orig_node_tmp = router->orig_node;
729 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); 730 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
730 bcast_own_sum_orig = 731 if_num = router->if_incoming->if_num;
731 orig_node_tmp->bcast_own_sum[if_incoming->if_num]; 732 sum_orig = orig_node_tmp->bcast_own_sum[if_num];
732 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock); 733 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
733 734
734 orig_node_tmp = neigh_node->orig_node; 735 orig_node_tmp = neigh_node->orig_node;
735 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); 736 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
736 bcast_own_sum_neigh = 737 if_num = neigh_node->if_incoming->if_num;
737 orig_node_tmp->bcast_own_sum[if_incoming->if_num]; 738 sum_neigh = orig_node_tmp->bcast_own_sum[if_num];
738 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock); 739 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
739 740
740 if (bcast_own_sum_orig >= bcast_own_sum_neigh) 741 if (sum_orig >= sum_neigh)
741 goto update_tt; 742 goto update_tt;
742 } 743 }
743 744
diff --git a/net/batman-adv/bitarray.h b/net/batman-adv/bitarray.h
index a081ce1c0514..cebaae7e148b 100644
--- a/net/batman-adv/bitarray.h
+++ b/net/batman-adv/bitarray.h
@@ -20,8 +20,8 @@
20#ifndef _NET_BATMAN_ADV_BITARRAY_H_ 20#ifndef _NET_BATMAN_ADV_BITARRAY_H_
21#define _NET_BATMAN_ADV_BITARRAY_H_ 21#define _NET_BATMAN_ADV_BITARRAY_H_
22 22
23/* returns true if the corresponding bit in the given seq_bits indicates true 23/* Returns 1 if the corresponding bit in the given seq_bits indicates true
24 * and curr_seqno is within range of last_seqno 24 * and curr_seqno is within range of last_seqno. Otherwise returns 0.
25 */ 25 */
26static inline int batadv_test_bit(const unsigned long *seq_bits, 26static inline int batadv_test_bit(const unsigned long *seq_bits,
27 uint32_t last_seqno, uint32_t curr_seqno) 27 uint32_t last_seqno, uint32_t curr_seqno)
@@ -32,7 +32,7 @@ static inline int batadv_test_bit(const unsigned long *seq_bits,
32 if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE) 32 if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE)
33 return 0; 33 return 0;
34 else 34 else
35 return test_bit(diff, seq_bits); 35 return test_bit(diff, seq_bits) != 0;
36} 36}
37 37
38/* turn corresponding bit on, so we can remember that we got the packet */ 38/* turn corresponding bit on, so we can remember that we got the packet */
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 109ea2aae96c..21c53577c8d6 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -100,18 +100,21 @@ static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
100{ 100{
101 struct batadv_priv *bat_priv = netdev_priv(dev); 101 struct batadv_priv *bat_priv = netdev_priv(dev);
102 struct sockaddr *addr = p; 102 struct sockaddr *addr = p;
103 uint8_t old_addr[ETH_ALEN];
103 104
104 if (!is_valid_ether_addr(addr->sa_data)) 105 if (!is_valid_ether_addr(addr->sa_data))
105 return -EADDRNOTAVAIL; 106 return -EADDRNOTAVAIL;
106 107
108 memcpy(old_addr, dev->dev_addr, ETH_ALEN);
109 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
110
107 /* only modify transtable if it has been initialized before */ 111 /* only modify transtable if it has been initialized before */
108 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE) { 112 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE) {
109 batadv_tt_local_remove(bat_priv, dev->dev_addr, 113 batadv_tt_local_remove(bat_priv, old_addr,
110 "mac address changed", false); 114 "mac address changed", false);
111 batadv_tt_local_add(dev, addr->sa_data, BATADV_NULL_IFINDEX); 115 batadv_tt_local_add(dev, addr->sa_data, BATADV_NULL_IFINDEX);
112 } 116 }
113 117
114 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
115 dev->addr_assign_type &= ~NET_ADDR_RANDOM; 118 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
116 return 0; 119 return 0;
117} 120}
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
index 5e5f5b410e0b..1eaacf10d19d 100644
--- a/net/bluetooth/bnep/sock.c
+++ b/net/bluetooth/bnep/sock.c
@@ -58,7 +58,7 @@ static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
58 switch (cmd) { 58 switch (cmd) {
59 case BNEPCONNADD: 59 case BNEPCONNADD:
60 if (!capable(CAP_NET_ADMIN)) 60 if (!capable(CAP_NET_ADMIN))
61 return -EACCES; 61 return -EPERM;
62 62
63 if (copy_from_user(&ca, argp, sizeof(ca))) 63 if (copy_from_user(&ca, argp, sizeof(ca)))
64 return -EFAULT; 64 return -EFAULT;
@@ -84,7 +84,7 @@ static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
84 84
85 case BNEPCONNDEL: 85 case BNEPCONNDEL:
86 if (!capable(CAP_NET_ADMIN)) 86 if (!capable(CAP_NET_ADMIN))
87 return -EACCES; 87 return -EPERM;
88 88
89 if (copy_from_user(&cd, argp, sizeof(cd))) 89 if (copy_from_user(&cd, argp, sizeof(cd)))
90 return -EFAULT; 90 return -EFAULT;
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
index 311668d14571..32dc83dcb6b2 100644
--- a/net/bluetooth/cmtp/sock.c
+++ b/net/bluetooth/cmtp/sock.c
@@ -72,7 +72,7 @@ static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
72 switch (cmd) { 72 switch (cmd) {
73 case CMTPCONNADD: 73 case CMTPCONNADD:
74 if (!capable(CAP_NET_ADMIN)) 74 if (!capable(CAP_NET_ADMIN))
75 return -EACCES; 75 return -EPERM;
76 76
77 if (copy_from_user(&ca, argp, sizeof(ca))) 77 if (copy_from_user(&ca, argp, sizeof(ca)))
78 return -EFAULT; 78 return -EFAULT;
@@ -97,7 +97,7 @@ static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
97 97
98 case CMTPCONNDEL: 98 case CMTPCONNDEL:
99 if (!capable(CAP_NET_ADMIN)) 99 if (!capable(CAP_NET_ADMIN))
100 return -EACCES; 100 return -EPERM;
101 101
102 if (copy_from_user(&cd, argp, sizeof(cd))) 102 if (copy_from_user(&cd, argp, sizeof(cd)))
103 return -EFAULT; 103 return -EFAULT;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 5ad7da217474..3c094e78dde9 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -29,6 +29,7 @@
29#include <net/bluetooth/bluetooth.h> 29#include <net/bluetooth/bluetooth.h>
30#include <net/bluetooth/hci_core.h> 30#include <net/bluetooth/hci_core.h>
31#include <net/bluetooth/a2mp.h> 31#include <net/bluetooth/a2mp.h>
32#include <net/bluetooth/smp.h>
32 33
33static void hci_le_connect(struct hci_conn *conn) 34static void hci_le_connect(struct hci_conn *conn)
34{ 35{
@@ -619,6 +620,9 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
619{ 620{
620 BT_DBG("hcon %p", conn); 621 BT_DBG("hcon %p", conn);
621 622
623 if (conn->type == LE_LINK)
624 return smp_conn_security(conn, sec_level);
625
622 /* For sdp we don't need the link key. */ 626 /* For sdp we don't need the link key. */
623 if (sec_level == BT_SECURITY_SDP) 627 if (sec_level == BT_SECURITY_SDP)
624 return 1; 628 return 1;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d4de5db18d5a..0b997c8f9655 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -734,6 +734,8 @@ static int hci_dev_do_close(struct hci_dev *hdev)
734 734
735 cancel_work_sync(&hdev->le_scan); 735 cancel_work_sync(&hdev->le_scan);
736 736
737 cancel_delayed_work(&hdev->power_off);
738
737 hci_req_cancel(hdev, ENODEV); 739 hci_req_cancel(hdev, ENODEV);
738 hci_req_lock(hdev); 740 hci_req_lock(hdev);
739 741
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 19fdac78e555..d5ace1eda3ed 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -490,7 +490,7 @@ static int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd,
490 switch (cmd) { 490 switch (cmd) {
491 case HCISETRAW: 491 case HCISETRAW:
492 if (!capable(CAP_NET_ADMIN)) 492 if (!capable(CAP_NET_ADMIN))
493 return -EACCES; 493 return -EPERM;
494 494
495 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) 495 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
496 return -EPERM; 496 return -EPERM;
@@ -510,12 +510,12 @@ static int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd,
510 510
511 case HCIBLOCKADDR: 511 case HCIBLOCKADDR:
512 if (!capable(CAP_NET_ADMIN)) 512 if (!capable(CAP_NET_ADMIN))
513 return -EACCES; 513 return -EPERM;
514 return hci_sock_blacklist_add(hdev, (void __user *) arg); 514 return hci_sock_blacklist_add(hdev, (void __user *) arg);
515 515
516 case HCIUNBLOCKADDR: 516 case HCIUNBLOCKADDR:
517 if (!capable(CAP_NET_ADMIN)) 517 if (!capable(CAP_NET_ADMIN))
518 return -EACCES; 518 return -EPERM;
519 return hci_sock_blacklist_del(hdev, (void __user *) arg); 519 return hci_sock_blacklist_del(hdev, (void __user *) arg);
520 520
521 default: 521 default:
@@ -546,22 +546,22 @@ static int hci_sock_ioctl(struct socket *sock, unsigned int cmd,
546 546
547 case HCIDEVUP: 547 case HCIDEVUP:
548 if (!capable(CAP_NET_ADMIN)) 548 if (!capable(CAP_NET_ADMIN))
549 return -EACCES; 549 return -EPERM;
550 return hci_dev_open(arg); 550 return hci_dev_open(arg);
551 551
552 case HCIDEVDOWN: 552 case HCIDEVDOWN:
553 if (!capable(CAP_NET_ADMIN)) 553 if (!capable(CAP_NET_ADMIN))
554 return -EACCES; 554 return -EPERM;
555 return hci_dev_close(arg); 555 return hci_dev_close(arg);
556 556
557 case HCIDEVRESET: 557 case HCIDEVRESET:
558 if (!capable(CAP_NET_ADMIN)) 558 if (!capable(CAP_NET_ADMIN))
559 return -EACCES; 559 return -EPERM;
560 return hci_dev_reset(arg); 560 return hci_dev_reset(arg);
561 561
562 case HCIDEVRESTAT: 562 case HCIDEVRESTAT:
563 if (!capable(CAP_NET_ADMIN)) 563 if (!capable(CAP_NET_ADMIN))
564 return -EACCES; 564 return -EPERM;
565 return hci_dev_reset_stat(arg); 565 return hci_dev_reset_stat(arg);
566 566
567 case HCISETSCAN: 567 case HCISETSCAN:
@@ -573,7 +573,7 @@ static int hci_sock_ioctl(struct socket *sock, unsigned int cmd,
573 case HCISETACLMTU: 573 case HCISETACLMTU:
574 case HCISETSCOMTU: 574 case HCISETSCOMTU:
575 if (!capable(CAP_NET_ADMIN)) 575 if (!capable(CAP_NET_ADMIN))
576 return -EACCES; 576 return -EPERM;
577 return hci_dev_cmd(cmd, argp); 577 return hci_dev_cmd(cmd, argp);
578 578
579 case HCIINQUIRY: 579 case HCIINQUIRY:
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index 18b3f6892a36..b24fb3bd8625 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -56,7 +56,7 @@ static int hidp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
56 switch (cmd) { 56 switch (cmd) {
57 case HIDPCONNADD: 57 case HIDPCONNADD:
58 if (!capable(CAP_NET_ADMIN)) 58 if (!capable(CAP_NET_ADMIN))
59 return -EACCES; 59 return -EPERM;
60 60
61 if (copy_from_user(&ca, argp, sizeof(ca))) 61 if (copy_from_user(&ca, argp, sizeof(ca)))
62 return -EFAULT; 62 return -EFAULT;
@@ -91,7 +91,7 @@ static int hidp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
91 91
92 case HIDPCONNDEL: 92 case HIDPCONNDEL:
93 if (!capable(CAP_NET_ADMIN)) 93 if (!capable(CAP_NET_ADMIN))
94 return -EACCES; 94 return -EPERM;
95 95
96 if (copy_from_user(&cd, argp, sizeof(cd))) 96 if (copy_from_user(&cd, argp, sizeof(cd)))
97 return -EFAULT; 97 return -EFAULT;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index daa149b7003c..38c00f142203 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1008,7 +1008,7 @@ static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *c
1008 if (!conn) 1008 if (!conn)
1009 return; 1009 return;
1010 1010
1011 if (chan->mode == L2CAP_MODE_ERTM) { 1011 if (chan->mode == L2CAP_MODE_ERTM && chan->state == BT_CONNECTED) {
1012 __clear_retrans_timer(chan); 1012 __clear_retrans_timer(chan);
1013 __clear_monitor_timer(chan); 1013 __clear_monitor_timer(chan);
1014 __clear_ack_timer(chan); 1014 __clear_ack_timer(chan);
@@ -1199,14 +1199,15 @@ clean:
1199static void l2cap_conn_ready(struct l2cap_conn *conn) 1199static void l2cap_conn_ready(struct l2cap_conn *conn)
1200{ 1200{
1201 struct l2cap_chan *chan; 1201 struct l2cap_chan *chan;
1202 struct hci_conn *hcon = conn->hcon;
1202 1203
1203 BT_DBG("conn %p", conn); 1204 BT_DBG("conn %p", conn);
1204 1205
1205 if (!conn->hcon->out && conn->hcon->type == LE_LINK) 1206 if (!hcon->out && hcon->type == LE_LINK)
1206 l2cap_le_conn_ready(conn); 1207 l2cap_le_conn_ready(conn);
1207 1208
1208 if (conn->hcon->out && conn->hcon->type == LE_LINK) 1209 if (hcon->out && hcon->type == LE_LINK)
1209 smp_conn_security(conn, conn->hcon->pending_sec_level); 1210 smp_conn_security(hcon, hcon->pending_sec_level);
1210 1211
1211 mutex_lock(&conn->chan_lock); 1212 mutex_lock(&conn->chan_lock);
1212 1213
@@ -1219,8 +1220,8 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
1219 continue; 1220 continue;
1220 } 1221 }
1221 1222
1222 if (conn->hcon->type == LE_LINK) { 1223 if (hcon->type == LE_LINK) {
1223 if (smp_conn_security(conn, chan->sec_level)) 1224 if (smp_conn_security(hcon, chan->sec_level))
1224 l2cap_chan_ready(chan); 1225 l2cap_chan_ready(chan);
1225 1226
1226 } else if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { 1227 } else if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 1497edd191a2..34bbe1c5e389 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -616,7 +616,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
616 break; 616 break;
617 } 617 }
618 618
619 if (smp_conn_security(conn, sec.level)) 619 if (smp_conn_security(conn->hcon, sec.level))
620 break; 620 break;
621 sk->sk_state = BT_CONFIG; 621 sk->sk_state = BT_CONFIG;
622 chan->state = BT_CONFIG; 622 chan->state = BT_CONFIG;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index ad6613d17ca6..eba022de3c20 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2875,6 +2875,22 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered)
2875 if (scan) 2875 if (scan)
2876 hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); 2876 hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
2877 2877
2878 if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) {
2879 u8 ssp = 1;
2880
2881 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, 1, &ssp);
2882 }
2883
2884 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) {
2885 struct hci_cp_write_le_host_supported cp;
2886
2887 cp.le = 1;
2888 cp.simul = !!(hdev->features[6] & LMP_SIMUL_LE_BR);
2889
2890 hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED,
2891 sizeof(cp), &cp);
2892 }
2893
2878 update_class(hdev); 2894 update_class(hdev);
2879 update_name(hdev, hdev->dev_name); 2895 update_name(hdev, hdev->dev_name);
2880 update_eir(hdev); 2896 update_eir(hdev);
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 901a616c8083..8c225ef349cd 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -267,10 +267,10 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send)
267 mgmt_auth_failed(conn->hcon->hdev, conn->dst, hcon->type, 267 mgmt_auth_failed(conn->hcon->hdev, conn->dst, hcon->type,
268 hcon->dst_type, reason); 268 hcon->dst_type, reason);
269 269
270 if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) { 270 cancel_delayed_work_sync(&conn->security_timer);
271 cancel_delayed_work_sync(&conn->security_timer); 271
272 if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags))
272 smp_chan_destroy(conn); 273 smp_chan_destroy(conn);
273 }
274} 274}
275 275
276#define JUST_WORKS 0x00 276#define JUST_WORKS 0x00
@@ -760,9 +760,9 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
760 return 0; 760 return 0;
761} 761}
762 762
763int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) 763int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)
764{ 764{
765 struct hci_conn *hcon = conn->hcon; 765 struct l2cap_conn *conn = hcon->l2cap_data;
766 struct smp_chan *smp = conn->smp_chan; 766 struct smp_chan *smp = conn->smp_chan;
767 __u8 authreq; 767 __u8 authreq;
768 768
diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index f88ee537fb2b..92de5e5f9db2 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -80,7 +80,7 @@ ebt_log_packet(u_int8_t pf, unsigned int hooknum,
80 unsigned int bitmask; 80 unsigned int bitmask;
81 81
82 spin_lock_bh(&ebt_log_lock); 82 spin_lock_bh(&ebt_log_lock);
83 printk("<%c>%s IN=%s OUT=%s MAC source = %pM MAC dest = %pM proto = 0x%04x", 83 printk(KERN_SOH "%c%s IN=%s OUT=%s MAC source = %pM MAC dest = %pM proto = 0x%04x",
84 '0' + loginfo->u.log.level, prefix, 84 '0' + loginfo->u.log.level, prefix,
85 in ? in->name : "", out ? out->name : "", 85 in ? in->name : "", out ? out->name : "",
86 eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest, 86 eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest,
diff --git a/net/caif/cfsrvl.c b/net/caif/cfsrvl.c
index dd485f6128e8..ba217e90765e 100644
--- a/net/caif/cfsrvl.c
+++ b/net/caif/cfsrvl.c
@@ -211,9 +211,10 @@ void caif_client_register_refcnt(struct cflayer *adapt_layer,
211 void (*put)(struct cflayer *lyr)) 211 void (*put)(struct cflayer *lyr))
212{ 212{
213 struct cfsrvl *service; 213 struct cfsrvl *service;
214 service = container_of(adapt_layer->dn, struct cfsrvl, layer);
215 214
216 WARN_ON(adapt_layer == NULL || adapt_layer->dn == NULL); 215 if (WARN_ON(adapt_layer == NULL || adapt_layer->dn == NULL))
216 return;
217 service = container_of(adapt_layer->dn, struct cfsrvl, layer);
217 service->hold = hold; 218 service->hold = hold;
218 service->put = put; 219 service->put = put;
219} 220}
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 24c5eea8c45b..159aa8bef9e7 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1073,16 +1073,13 @@ static int write_partial_msg_pages(struct ceph_connection *con)
1073 BUG_ON(kaddr == NULL); 1073 BUG_ON(kaddr == NULL);
1074 base = kaddr + con->out_msg_pos.page_pos + bio_offset; 1074 base = kaddr + con->out_msg_pos.page_pos + bio_offset;
1075 crc = crc32c(crc, base, len); 1075 crc = crc32c(crc, base, len);
1076 kunmap(page);
1076 msg->footer.data_crc = cpu_to_le32(crc); 1077 msg->footer.data_crc = cpu_to_le32(crc);
1077 con->out_msg_pos.did_page_crc = true; 1078 con->out_msg_pos.did_page_crc = true;
1078 } 1079 }
1079 ret = ceph_tcp_sendpage(con->sock, page, 1080 ret = ceph_tcp_sendpage(con->sock, page,
1080 con->out_msg_pos.page_pos + bio_offset, 1081 con->out_msg_pos.page_pos + bio_offset,
1081 len, 1); 1082 len, 1);
1082
1083 if (do_datacrc)
1084 kunmap(page);
1085
1086 if (ret <= 0) 1083 if (ret <= 0)
1087 goto out; 1084 goto out;
1088 1085
diff --git a/net/core/dev.c b/net/core/dev.c
index 83988362805e..89e33a5d4d93 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2134,7 +2134,8 @@ static bool can_checksum_protocol(netdev_features_t features, __be16 protocol)
2134static netdev_features_t harmonize_features(struct sk_buff *skb, 2134static netdev_features_t harmonize_features(struct sk_buff *skb,
2135 __be16 protocol, netdev_features_t features) 2135 __be16 protocol, netdev_features_t features)
2136{ 2136{
2137 if (!can_checksum_protocol(features, protocol)) { 2137 if (skb->ip_summed != CHECKSUM_NONE &&
2138 !can_checksum_protocol(features, protocol)) {
2138 features &= ~NETIF_F_ALL_CSUM; 2139 features &= ~NETIF_F_ALL_CSUM;
2139 features &= ~NETIF_F_SG; 2140 features &= ~NETIF_F_SG;
2140 } else if (illegal_highdma(skb->dev, skb)) { 2141 } else if (illegal_highdma(skb->dev, skb)) {
@@ -2647,15 +2648,16 @@ void __skb_get_rxhash(struct sk_buff *skb)
2647 if (!skb_flow_dissect(skb, &keys)) 2648 if (!skb_flow_dissect(skb, &keys))
2648 return; 2649 return;
2649 2650
2650 if (keys.ports) { 2651 if (keys.ports)
2651 if ((__force u16)keys.port16[1] < (__force u16)keys.port16[0])
2652 swap(keys.port16[0], keys.port16[1]);
2653 skb->l4_rxhash = 1; 2652 skb->l4_rxhash = 1;
2654 }
2655 2653
2656 /* get a consistent hash (same value on both flow directions) */ 2654 /* get a consistent hash (same value on both flow directions) */
2657 if ((__force u32)keys.dst < (__force u32)keys.src) 2655 if (((__force u32)keys.dst < (__force u32)keys.src) ||
2656 (((__force u32)keys.dst == (__force u32)keys.src) &&
2657 ((__force u16)keys.port16[1] < (__force u16)keys.port16[0]))) {
2658 swap(keys.dst, keys.src); 2658 swap(keys.dst, keys.src);
2659 swap(keys.port16[0], keys.port16[1]);
2660 }
2659 2661
2660 hash = jhash_3words((__force u32)keys.dst, 2662 hash = jhash_3words((__force u32)keys.dst,
2661 (__force u32)keys.src, 2663 (__force u32)keys.src,
@@ -3321,7 +3323,7 @@ ncls:
3321 3323
3322 if (pt_prev) { 3324 if (pt_prev) {
3323 if (unlikely(skb_orphan_frags(skb, GFP_ATOMIC))) 3325 if (unlikely(skb_orphan_frags(skb, GFP_ATOMIC)))
3324 ret = -ENOMEM; 3326 goto drop;
3325 else 3327 else
3326 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev); 3328 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
3327 } else { 3329 } else {
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index cce9e53528b1..148e73d2c451 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -2721,7 +2721,7 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
2721 /* Eth + IPh + UDPh + mpls */ 2721 /* Eth + IPh + UDPh + mpls */
2722 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 - 2722 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 -
2723 pkt_dev->pkt_overhead; 2723 pkt_dev->pkt_overhead;
2724 if (datalen < sizeof(struct pktgen_hdr)) 2724 if (datalen < 0 || datalen < sizeof(struct pktgen_hdr))
2725 datalen = sizeof(struct pktgen_hdr); 2725 datalen = sizeof(struct pktgen_hdr);
2726 2726
2727 udph->source = htons(pkt_dev->cur_udp_src); 2727 udph->source = htons(pkt_dev->cur_udp_src);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index fe00d1208167..e33ebae519c8 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3502,7 +3502,9 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
3502 if (!skb_cloned(from)) 3502 if (!skb_cloned(from))
3503 skb_shinfo(from)->nr_frags = 0; 3503 skb_shinfo(from)->nr_frags = 0;
3504 3504
3505 /* if the skb is cloned this does nothing since we set nr_frags to 0 */ 3505 /* if the skb is not cloned this does nothing
3506 * since we set nr_frags to 0.
3507 */
3506 for (i = 0; i < skb_shinfo(from)->nr_frags; i++) 3508 for (i = 0; i < skb_shinfo(from)->nr_frags; i++)
3507 skb_frag_ref(from, i); 3509 skb_frag_ref(from, i);
3508 3510
diff --git a/net/core/sock.c b/net/core/sock.c
index 8f67ced8d6a8..a6000fbad294 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -691,7 +691,8 @@ set_rcvbuf:
691 691
692 case SO_KEEPALIVE: 692 case SO_KEEPALIVE:
693#ifdef CONFIG_INET 693#ifdef CONFIG_INET
694 if (sk->sk_protocol == IPPROTO_TCP) 694 if (sk->sk_protocol == IPPROTO_TCP &&
695 sk->sk_type == SOCK_STREAM)
695 tcp_set_keepalive(sk, valbool); 696 tcp_set_keepalive(sk, valbool);
696#endif 697#endif
697 sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool); 698 sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
@@ -1523,7 +1524,14 @@ EXPORT_SYMBOL(sock_rfree);
1523 1524
1524void sock_edemux(struct sk_buff *skb) 1525void sock_edemux(struct sk_buff *skb)
1525{ 1526{
1526 sock_put(skb->sk); 1527 struct sock *sk = skb->sk;
1528
1529#ifdef CONFIG_INET
1530 if (sk->sk_state == TCP_TIME_WAIT)
1531 inet_twsk_put(inet_twsk(sk));
1532 else
1533#endif
1534 sock_put(sk);
1527} 1535}
1528EXPORT_SYMBOL(sock_edemux); 1536EXPORT_SYMBOL(sock_edemux);
1529 1537
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 77e87aff419a..47800459e4cb 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -1225,7 +1225,7 @@ static int arp_netdev_event(struct notifier_block *this, unsigned long event,
1225 switch (event) { 1225 switch (event) {
1226 case NETDEV_CHANGEADDR: 1226 case NETDEV_CHANGEADDR:
1227 neigh_changeaddr(&arp_tbl, dev); 1227 neigh_changeaddr(&arp_tbl, dev);
1228 rt_cache_flush(dev_net(dev), 0); 1228 rt_cache_flush(dev_net(dev));
1229 break; 1229 break;
1230 default: 1230 default:
1231 break; 1231 break;
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 44bf82e3aef7..e12fad773852 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -725,7 +725,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
725 break; 725 break;
726 726
727 case SIOCSIFFLAGS: 727 case SIOCSIFFLAGS:
728 ret = -EACCES; 728 ret = -EPERM;
729 if (!capable(CAP_NET_ADMIN)) 729 if (!capable(CAP_NET_ADMIN))
730 goto out; 730 goto out;
731 break; 731 break;
@@ -733,7 +733,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
733 case SIOCSIFBRDADDR: /* Set the broadcast address */ 733 case SIOCSIFBRDADDR: /* Set the broadcast address */
734 case SIOCSIFDSTADDR: /* Set the destination address */ 734 case SIOCSIFDSTADDR: /* Set the destination address */
735 case SIOCSIFNETMASK: /* Set the netmask for the interface */ 735 case SIOCSIFNETMASK: /* Set the netmask for the interface */
736 ret = -EACCES; 736 ret = -EPERM;
737 if (!capable(CAP_NET_ADMIN)) 737 if (!capable(CAP_NET_ADMIN))
738 goto out; 738 goto out;
739 ret = -EINVAL; 739 ret = -EINVAL;
@@ -1503,7 +1503,7 @@ static int devinet_conf_proc(ctl_table *ctl, int write,
1503 if (i == IPV4_DEVCONF_ACCEPT_LOCAL - 1 || 1503 if (i == IPV4_DEVCONF_ACCEPT_LOCAL - 1 ||
1504 i == IPV4_DEVCONF_ROUTE_LOCALNET - 1) 1504 i == IPV4_DEVCONF_ROUTE_LOCALNET - 1)
1505 if ((new_value == 0) && (old_value != 0)) 1505 if ((new_value == 0) && (old_value != 0))
1506 rt_cache_flush(net, 0); 1506 rt_cache_flush(net);
1507 } 1507 }
1508 1508
1509 return ret; 1509 return ret;
@@ -1537,7 +1537,7 @@ static int devinet_sysctl_forward(ctl_table *ctl, int write,
1537 dev_disable_lro(idev->dev); 1537 dev_disable_lro(idev->dev);
1538 } 1538 }
1539 rtnl_unlock(); 1539 rtnl_unlock();
1540 rt_cache_flush(net, 0); 1540 rt_cache_flush(net);
1541 } 1541 }
1542 } 1542 }
1543 1543
@@ -1554,7 +1554,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
1554 struct net *net = ctl->extra2; 1554 struct net *net = ctl->extra2;
1555 1555
1556 if (write && *valp != val) 1556 if (write && *valp != val)
1557 rt_cache_flush(net, 0); 1557 rt_cache_flush(net);
1558 1558
1559 return ret; 1559 return ret;
1560} 1560}
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index c43ae3fba792..8e2b475da9fa 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -148,7 +148,7 @@ static void fib_flush(struct net *net)
148 } 148 }
149 149
150 if (flushed) 150 if (flushed)
151 rt_cache_flush(net, -1); 151 rt_cache_flush(net);
152} 152}
153 153
154/* 154/*
@@ -999,11 +999,11 @@ static void nl_fib_lookup_exit(struct net *net)
999 net->ipv4.fibnl = NULL; 999 net->ipv4.fibnl = NULL;
1000} 1000}
1001 1001
1002static void fib_disable_ip(struct net_device *dev, int force, int delay) 1002static void fib_disable_ip(struct net_device *dev, int force)
1003{ 1003{
1004 if (fib_sync_down_dev(dev, force)) 1004 if (fib_sync_down_dev(dev, force))
1005 fib_flush(dev_net(dev)); 1005 fib_flush(dev_net(dev));
1006 rt_cache_flush(dev_net(dev), delay); 1006 rt_cache_flush(dev_net(dev));
1007 arp_ifdown(dev); 1007 arp_ifdown(dev);
1008} 1008}
1009 1009
@@ -1020,7 +1020,7 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
1020 fib_sync_up(dev); 1020 fib_sync_up(dev);
1021#endif 1021#endif
1022 atomic_inc(&net->ipv4.dev_addr_genid); 1022 atomic_inc(&net->ipv4.dev_addr_genid);
1023 rt_cache_flush(dev_net(dev), -1); 1023 rt_cache_flush(dev_net(dev));
1024 break; 1024 break;
1025 case NETDEV_DOWN: 1025 case NETDEV_DOWN:
1026 fib_del_ifaddr(ifa, NULL); 1026 fib_del_ifaddr(ifa, NULL);
@@ -1029,9 +1029,9 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
1029 /* Last address was deleted from this interface. 1029 /* Last address was deleted from this interface.
1030 * Disable IP. 1030 * Disable IP.
1031 */ 1031 */
1032 fib_disable_ip(dev, 1, 0); 1032 fib_disable_ip(dev, 1);
1033 } else { 1033 } else {
1034 rt_cache_flush(dev_net(dev), -1); 1034 rt_cache_flush(dev_net(dev));
1035 } 1035 }
1036 break; 1036 break;
1037 } 1037 }
@@ -1045,7 +1045,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
1045 struct net *net = dev_net(dev); 1045 struct net *net = dev_net(dev);
1046 1046
1047 if (event == NETDEV_UNREGISTER) { 1047 if (event == NETDEV_UNREGISTER) {
1048 fib_disable_ip(dev, 2, -1); 1048 fib_disable_ip(dev, 2);
1049 rt_flush_dev(dev); 1049 rt_flush_dev(dev);
1050 return NOTIFY_DONE; 1050 return NOTIFY_DONE;
1051 } 1051 }
@@ -1062,14 +1062,14 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
1062 fib_sync_up(dev); 1062 fib_sync_up(dev);
1063#endif 1063#endif
1064 atomic_inc(&net->ipv4.dev_addr_genid); 1064 atomic_inc(&net->ipv4.dev_addr_genid);
1065 rt_cache_flush(dev_net(dev), -1); 1065 rt_cache_flush(dev_net(dev));
1066 break; 1066 break;
1067 case NETDEV_DOWN: 1067 case NETDEV_DOWN:
1068 fib_disable_ip(dev, 0, 0); 1068 fib_disable_ip(dev, 0);
1069 break; 1069 break;
1070 case NETDEV_CHANGEMTU: 1070 case NETDEV_CHANGEMTU:
1071 case NETDEV_CHANGE: 1071 case NETDEV_CHANGE:
1072 rt_cache_flush(dev_net(dev), 0); 1072 rt_cache_flush(dev_net(dev));
1073 break; 1073 break;
1074 case NETDEV_UNREGISTER_BATCH: 1074 case NETDEV_UNREGISTER_BATCH:
1075 break; 1075 break;
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index a83d74e498d2..274309d3aded 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -259,7 +259,7 @@ static size_t fib4_rule_nlmsg_payload(struct fib_rule *rule)
259 259
260static void fib4_rule_flush_cache(struct fib_rules_ops *ops) 260static void fib4_rule_flush_cache(struct fib_rules_ops *ops)
261{ 261{
262 rt_cache_flush(ops->fro_net, -1); 262 rt_cache_flush(ops->fro_net);
263} 263}
264 264
265static const struct fib_rules_ops __net_initdata fib4_rules_ops_template = { 265static const struct fib_rules_ops __net_initdata fib4_rules_ops_template = {
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 57bd978483e1..d1b93595b4a7 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1286,7 +1286,7 @@ int fib_table_insert(struct fib_table *tb, struct fib_config *cfg)
1286 1286
1287 fib_release_info(fi_drop); 1287 fib_release_info(fi_drop);
1288 if (state & FA_S_ACCESSED) 1288 if (state & FA_S_ACCESSED)
1289 rt_cache_flush(cfg->fc_nlinfo.nl_net, -1); 1289 rt_cache_flush(cfg->fc_nlinfo.nl_net);
1290 rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, 1290 rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen,
1291 tb->tb_id, &cfg->fc_nlinfo, NLM_F_REPLACE); 1291 tb->tb_id, &cfg->fc_nlinfo, NLM_F_REPLACE);
1292 1292
@@ -1333,7 +1333,7 @@ int fib_table_insert(struct fib_table *tb, struct fib_config *cfg)
1333 list_add_tail_rcu(&new_fa->fa_list, 1333 list_add_tail_rcu(&new_fa->fa_list,
1334 (fa ? &fa->fa_list : fa_head)); 1334 (fa ? &fa->fa_list : fa_head));
1335 1335
1336 rt_cache_flush(cfg->fc_nlinfo.nl_net, -1); 1336 rt_cache_flush(cfg->fc_nlinfo.nl_net);
1337 rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id, 1337 rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id,
1338 &cfg->fc_nlinfo, 0); 1338 &cfg->fc_nlinfo, 0);
1339succeeded: 1339succeeded:
@@ -1708,7 +1708,7 @@ int fib_table_delete(struct fib_table *tb, struct fib_config *cfg)
1708 trie_leaf_remove(t, l); 1708 trie_leaf_remove(t, l);
1709 1709
1710 if (fa->fa_state & FA_S_ACCESSED) 1710 if (fa->fa_state & FA_S_ACCESSED)
1711 rt_cache_flush(cfg->fc_nlinfo.nl_net, -1); 1711 rt_cache_flush(cfg->fc_nlinfo.nl_net);
1712 1712
1713 fib_release_info(fa->fa_info); 1713 fib_release_info(fa->fa_info);
1714 alias_free_mem_rcu(fa); 1714 alias_free_mem_rcu(fa);
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index e1e0a4e8fd34..c7527f6b9ad9 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -510,7 +510,10 @@ relookup:
510 secure_ipv6_id(daddr->addr.a6)); 510 secure_ipv6_id(daddr->addr.a6));
511 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW; 511 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
512 p->rate_tokens = 0; 512 p->rate_tokens = 0;
513 p->rate_last = 0; 513 /* 60*HZ is arbitrary, but chosen enough high so that the first
514 * calculation of tokens is at its maximum.
515 */
516 p->rate_last = jiffies - 60*HZ;
514 INIT_LIST_HEAD(&p->gc_list); 517 INIT_LIST_HEAD(&p->gc_list);
515 518
516 /* Link the node. */ 519 /* Link the node. */
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index ff0f071969ea..d23c6571ba1c 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -131,18 +131,20 @@ found:
131 * 0 - deliver 131 * 0 - deliver
132 * 1 - block 132 * 1 - block
133 */ 133 */
134static __inline__ int icmp_filter(struct sock *sk, struct sk_buff *skb) 134static int icmp_filter(const struct sock *sk, const struct sk_buff *skb)
135{ 135{
136 int type; 136 struct icmphdr _hdr;
137 const struct icmphdr *hdr;
137 138
138 if (!pskb_may_pull(skb, sizeof(struct icmphdr))) 139 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
140 sizeof(_hdr), &_hdr);
141 if (!hdr)
139 return 1; 142 return 1;
140 143
141 type = icmp_hdr(skb)->type; 144 if (hdr->type < 32) {
142 if (type < 32) {
143 __u32 data = raw_sk(sk)->filter.data; 145 __u32 data = raw_sk(sk)->filter.data;
144 146
145 return ((1 << type) & data) != 0; 147 return ((1U << hdr->type) & data) != 0;
146 } 148 }
147 149
148 /* Do not block unknown ICMP types */ 150 /* Do not block unknown ICMP types */
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 82cf2a722b23..fd9af60397b5 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -202,11 +202,6 @@ EXPORT_SYMBOL(ip_tos2prio);
202static DEFINE_PER_CPU(struct rt_cache_stat, rt_cache_stat); 202static DEFINE_PER_CPU(struct rt_cache_stat, rt_cache_stat);
203#define RT_CACHE_STAT_INC(field) __this_cpu_inc(rt_cache_stat.field) 203#define RT_CACHE_STAT_INC(field) __this_cpu_inc(rt_cache_stat.field)
204 204
205static inline int rt_genid(struct net *net)
206{
207 return atomic_read(&net->ipv4.rt_genid);
208}
209
210#ifdef CONFIG_PROC_FS 205#ifdef CONFIG_PROC_FS
211static void *rt_cache_seq_start(struct seq_file *seq, loff_t *pos) 206static void *rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
212{ 207{
@@ -447,27 +442,9 @@ static inline bool rt_is_expired(const struct rtable *rth)
447 return rth->rt_genid != rt_genid(dev_net(rth->dst.dev)); 442 return rth->rt_genid != rt_genid(dev_net(rth->dst.dev));
448} 443}
449 444
450/* 445void rt_cache_flush(struct net *net)
451 * Perturbation of rt_genid by a small quantity [1..256]
452 * Using 8 bits of shuffling ensure we can call rt_cache_invalidate()
453 * many times (2^24) without giving recent rt_genid.
454 * Jenkins hash is strong enough that litle changes of rt_genid are OK.
455 */
456static void rt_cache_invalidate(struct net *net)
457{ 446{
458 unsigned char shuffle; 447 rt_genid_bump(net);
459
460 get_random_bytes(&shuffle, sizeof(shuffle));
461 atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
462}
463
464/*
465 * delay < 0 : invalidate cache (fast : entries will be deleted later)
466 * delay >= 0 : invalidate & flush cache (can be long)
467 */
468void rt_cache_flush(struct net *net, int delay)
469{
470 rt_cache_invalidate(net);
471} 448}
472 449
473static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst, 450static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
@@ -2345,7 +2322,7 @@ int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb)
2345 2322
2346void ip_rt_multicast_event(struct in_device *in_dev) 2323void ip_rt_multicast_event(struct in_device *in_dev)
2347{ 2324{
2348 rt_cache_flush(dev_net(in_dev->dev), 0); 2325 rt_cache_flush(dev_net(in_dev->dev));
2349} 2326}
2350 2327
2351#ifdef CONFIG_SYSCTL 2328#ifdef CONFIG_SYSCTL
@@ -2354,16 +2331,7 @@ static int ipv4_sysctl_rtcache_flush(ctl_table *__ctl, int write,
2354 size_t *lenp, loff_t *ppos) 2331 size_t *lenp, loff_t *ppos)
2355{ 2332{
2356 if (write) { 2333 if (write) {
2357 int flush_delay; 2334 rt_cache_flush((struct net *)__ctl->extra1);
2358 ctl_table ctl;
2359 struct net *net;
2360
2361 memcpy(&ctl, __ctl, sizeof(ctl));
2362 ctl.data = &flush_delay;
2363 proc_dointvec(&ctl, write, buffer, lenp, ppos);
2364
2365 net = (struct net *)__ctl->extra1;
2366 rt_cache_flush(net, flush_delay);
2367 return 0; 2335 return 0;
2368 } 2336 }
2369 2337
@@ -2533,8 +2501,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
2533 2501
2534static __net_init int rt_genid_init(struct net *net) 2502static __net_init int rt_genid_init(struct net *net)
2535{ 2503{
2536 get_random_bytes(&net->ipv4.rt_genid, 2504 atomic_set(&net->rt_genid, 0);
2537 sizeof(net->ipv4.rt_genid));
2538 get_random_bytes(&net->ipv4.dev_addr_genid, 2505 get_random_bytes(&net->ipv4.dev_addr_genid,
2539 sizeof(net->ipv4.dev_addr_genid)); 2506 sizeof(net->ipv4.dev_addr_genid));
2540 return 0; 2507 return 0;
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 2109ff4a1daf..5f6419341821 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1762,8 +1762,14 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
1762 } 1762 }
1763 1763
1764#ifdef CONFIG_NET_DMA 1764#ifdef CONFIG_NET_DMA
1765 if (tp->ucopy.dma_chan) 1765 if (tp->ucopy.dma_chan) {
1766 dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); 1766 if (tp->rcv_wnd == 0 &&
1767 !skb_queue_empty(&sk->sk_async_wait_queue)) {
1768 tcp_service_net_dma(sk, true);
1769 tcp_cleanup_rbuf(sk, copied);
1770 } else
1771 dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
1772 }
1767#endif 1773#endif
1768 if (copied >= target) { 1774 if (copied >= target) {
1769 /* Do not sleep, just process backlog. */ 1775 /* Do not sleep, just process backlog. */
@@ -2325,10 +2331,17 @@ static int tcp_repair_options_est(struct tcp_sock *tp,
2325 tp->rx_opt.mss_clamp = opt.opt_val; 2331 tp->rx_opt.mss_clamp = opt.opt_val;
2326 break; 2332 break;
2327 case TCPOPT_WINDOW: 2333 case TCPOPT_WINDOW:
2328 if (opt.opt_val > 14) 2334 {
2329 return -EFBIG; 2335 u16 snd_wscale = opt.opt_val & 0xFFFF;
2336 u16 rcv_wscale = opt.opt_val >> 16;
2337
2338 if (snd_wscale > 14 || rcv_wscale > 14)
2339 return -EFBIG;
2330 2340
2331 tp->rx_opt.snd_wscale = opt.opt_val; 2341 tp->rx_opt.snd_wscale = snd_wscale;
2342 tp->rx_opt.rcv_wscale = rcv_wscale;
2343 tp->rx_opt.wscale_ok = 1;
2344 }
2332 break; 2345 break;
2333 case TCPOPT_SACK_PERM: 2346 case TCPOPT_SACK_PERM:
2334 if (opt.opt_val != 0) 2347 if (opt.opt_val != 0)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 6e38c6c23caa..d377f4854cb8 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4661,7 +4661,7 @@ queue_and_out:
4661 4661
4662 if (eaten > 0) 4662 if (eaten > 0)
4663 kfree_skb_partial(skb, fragstolen); 4663 kfree_skb_partial(skb, fragstolen);
4664 else if (!sock_flag(sk, SOCK_DEAD)) 4664 if (!sock_flag(sk, SOCK_DEAD))
4665 sk->sk_data_ready(sk, 0); 4665 sk->sk_data_ready(sk, 0);
4666 return; 4666 return;
4667 } 4667 }
@@ -5556,8 +5556,7 @@ no_ack:
5556#endif 5556#endif
5557 if (eaten) 5557 if (eaten)
5558 kfree_skb_partial(skb, fragstolen); 5558 kfree_skb_partial(skb, fragstolen);
5559 else 5559 sk->sk_data_ready(sk, 0);
5560 sk->sk_data_ready(sk, 0);
5561 return 0; 5560 return 0;
5562 } 5561 }
5563 } 5562 }
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 6f6d1aca3c3d..2814f66dac64 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1226,6 +1226,11 @@ try_again:
1226 1226
1227 if (unlikely(err)) { 1227 if (unlikely(err)) {
1228 trace_kfree_skb(skb, udp_recvmsg); 1228 trace_kfree_skb(skb, udp_recvmsg);
1229 if (!peeked) {
1230 atomic_inc(&sk->sk_drops);
1231 UDP_INC_STATS_USER(sock_net(sk),
1232 UDP_MIB_INERRORS, is_udplite);
1233 }
1229 goto out_free; 1234 goto out_free;
1230 } 1235 }
1231 1236
diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
index 0251a6005be8..c4f934176cab 100644
--- a/net/ipv6/inet6_connection_sock.c
+++ b/net/ipv6/inet6_connection_sock.c
@@ -175,33 +175,12 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
175 const struct in6_addr *saddr) 175 const struct in6_addr *saddr)
176{ 176{
177 __ip6_dst_store(sk, dst, daddr, saddr); 177 __ip6_dst_store(sk, dst, daddr, saddr);
178
179#ifdef CONFIG_XFRM
180 {
181 struct rt6_info *rt = (struct rt6_info *)dst;
182 rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
183 }
184#endif
185} 178}
186 179
187static inline 180static inline
188struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie) 181struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
189{ 182{
190 struct dst_entry *dst; 183 return __sk_dst_check(sk, cookie);
191
192 dst = __sk_dst_check(sk, cookie);
193
194#ifdef CONFIG_XFRM
195 if (dst) {
196 struct rt6_info *rt = (struct rt6_info *)dst;
197 if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
198 __sk_dst_reset(sk);
199 dst = NULL;
200 }
201 }
202#endif
203
204 return dst;
205} 184}
206 185
207static struct dst_entry *inet6_csk_route_socket(struct sock *sk, 186static struct dst_entry *inet6_csk_route_socket(struct sock *sk,
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 13690d650c3e..286acfc21250 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -819,6 +819,10 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
819 offsetof(struct rt6_info, rt6i_src), 819 offsetof(struct rt6_info, rt6i_src),
820 allow_create, replace_required); 820 allow_create, replace_required);
821 821
822 if (IS_ERR(sn)) {
823 err = PTR_ERR(sn);
824 sn = NULL;
825 }
822 if (!sn) { 826 if (!sn) {
823 /* If it is failed, discard just allocated 827 /* If it is failed, discard just allocated
824 root, and then (in st_failure) stale node 828 root, and then (in st_failure) stale node
diff --git a/net/ipv6/mip6.c b/net/ipv6/mip6.c
index 5b087c31d87b..0f9bdc5ee9f3 100644
--- a/net/ipv6/mip6.c
+++ b/net/ipv6/mip6.c
@@ -86,28 +86,30 @@ static int mip6_mh_len(int type)
86 86
87static int mip6_mh_filter(struct sock *sk, struct sk_buff *skb) 87static int mip6_mh_filter(struct sock *sk, struct sk_buff *skb)
88{ 88{
89 struct ip6_mh *mh; 89 struct ip6_mh _hdr;
90 const struct ip6_mh *mh;
90 91
91 if (!pskb_may_pull(skb, (skb_transport_offset(skb)) + 8) || 92 mh = skb_header_pointer(skb, skb_transport_offset(skb),
92 !pskb_may_pull(skb, (skb_transport_offset(skb) + 93 sizeof(_hdr), &_hdr);
93 ((skb_transport_header(skb)[1] + 1) << 3)))) 94 if (!mh)
94 return -1; 95 return -1;
95 96
96 mh = (struct ip6_mh *)skb_transport_header(skb); 97 if (((mh->ip6mh_hdrlen + 1) << 3) > skb->len)
98 return -1;
97 99
98 if (mh->ip6mh_hdrlen < mip6_mh_len(mh->ip6mh_type)) { 100 if (mh->ip6mh_hdrlen < mip6_mh_len(mh->ip6mh_type)) {
99 LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH message too short: %d vs >=%d\n", 101 LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH message too short: %d vs >=%d\n",
100 mh->ip6mh_hdrlen, mip6_mh_len(mh->ip6mh_type)); 102 mh->ip6mh_hdrlen, mip6_mh_len(mh->ip6mh_type));
101 mip6_param_prob(skb, 0, ((&mh->ip6mh_hdrlen) - 103 mip6_param_prob(skb, 0, offsetof(struct ip6_mh, ip6mh_hdrlen) +
102 skb_network_header(skb))); 104 skb_network_header_len(skb));
103 return -1; 105 return -1;
104 } 106 }
105 107
106 if (mh->ip6mh_proto != IPPROTO_NONE) { 108 if (mh->ip6mh_proto != IPPROTO_NONE) {
107 LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH invalid payload proto = %d\n", 109 LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH invalid payload proto = %d\n",
108 mh->ip6mh_proto); 110 mh->ip6mh_proto);
109 mip6_param_prob(skb, 0, ((&mh->ip6mh_proto) - 111 mip6_param_prob(skb, 0, offsetof(struct ip6_mh, ip6mh_proto) +
110 skb_network_header(skb))); 112 skb_network_header_len(skb));
111 return -1; 113 return -1;
112 } 114 }
113 115
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index ef0579d5bca6..4a5f78b50495 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -107,21 +107,20 @@ found:
107 * 0 - deliver 107 * 0 - deliver
108 * 1 - block 108 * 1 - block
109 */ 109 */
110static __inline__ int icmpv6_filter(struct sock *sk, struct sk_buff *skb) 110static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
111{ 111{
112 struct icmp6hdr *icmph; 112 struct icmp6hdr *_hdr;
113 struct raw6_sock *rp = raw6_sk(sk); 113 const struct icmp6hdr *hdr;
114
115 if (pskb_may_pull(skb, sizeof(struct icmp6hdr))) {
116 __u32 *data = &rp->filter.data[0];
117 int bit_nr;
118 114
119 icmph = (struct icmp6hdr *) skb->data; 115 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
120 bit_nr = icmph->icmp6_type; 116 sizeof(_hdr), &_hdr);
117 if (hdr) {
118 const __u32 *data = &raw6_sk(sk)->filter.data[0];
119 unsigned int type = hdr->icmp6_type;
121 120
122 return (data[bit_nr >> 5] & (1 << (bit_nr & 31))) != 0; 121 return (data[type >> 5] & (1U << (type & 31))) != 0;
123 } 122 }
124 return 0; 123 return 1;
125} 124}
126 125
127#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) 126#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 8e80fd279100..854e4018d205 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -226,7 +226,7 @@ static struct rt6_info ip6_null_entry_template = {
226 .dst = { 226 .dst = {
227 .__refcnt = ATOMIC_INIT(1), 227 .__refcnt = ATOMIC_INIT(1),
228 .__use = 1, 228 .__use = 1,
229 .obsolete = -1, 229 .obsolete = DST_OBSOLETE_FORCE_CHK,
230 .error = -ENETUNREACH, 230 .error = -ENETUNREACH,
231 .input = ip6_pkt_discard, 231 .input = ip6_pkt_discard,
232 .output = ip6_pkt_discard_out, 232 .output = ip6_pkt_discard_out,
@@ -246,7 +246,7 @@ static struct rt6_info ip6_prohibit_entry_template = {
246 .dst = { 246 .dst = {
247 .__refcnt = ATOMIC_INIT(1), 247 .__refcnt = ATOMIC_INIT(1),
248 .__use = 1, 248 .__use = 1,
249 .obsolete = -1, 249 .obsolete = DST_OBSOLETE_FORCE_CHK,
250 .error = -EACCES, 250 .error = -EACCES,
251 .input = ip6_pkt_prohibit, 251 .input = ip6_pkt_prohibit,
252 .output = ip6_pkt_prohibit_out, 252 .output = ip6_pkt_prohibit_out,
@@ -261,7 +261,7 @@ static struct rt6_info ip6_blk_hole_entry_template = {
261 .dst = { 261 .dst = {
262 .__refcnt = ATOMIC_INIT(1), 262 .__refcnt = ATOMIC_INIT(1),
263 .__use = 1, 263 .__use = 1,
264 .obsolete = -1, 264 .obsolete = DST_OBSOLETE_FORCE_CHK,
265 .error = -EINVAL, 265 .error = -EINVAL,
266 .input = dst_discard, 266 .input = dst_discard,
267 .output = dst_discard, 267 .output = dst_discard,
@@ -281,13 +281,14 @@ static inline struct rt6_info *ip6_dst_alloc(struct net *net,
281 struct fib6_table *table) 281 struct fib6_table *table)
282{ 282{
283 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev, 283 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev,
284 0, DST_OBSOLETE_NONE, flags); 284 0, DST_OBSOLETE_FORCE_CHK, flags);
285 285
286 if (rt) { 286 if (rt) {
287 struct dst_entry *dst = &rt->dst; 287 struct dst_entry *dst = &rt->dst;
288 288
289 memset(dst + 1, 0, sizeof(*rt) - sizeof(*dst)); 289 memset(dst + 1, 0, sizeof(*rt) - sizeof(*dst));
290 rt6_init_peer(rt, table ? &table->tb6_peers : net->ipv6.peers); 290 rt6_init_peer(rt, table ? &table->tb6_peers : net->ipv6.peers);
291 rt->rt6i_genid = rt_genid(net);
291 } 292 }
292 return rt; 293 return rt;
293} 294}
@@ -1031,6 +1032,13 @@ static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie)
1031 1032
1032 rt = (struct rt6_info *) dst; 1033 rt = (struct rt6_info *) dst;
1033 1034
1035 /* All IPV6 dsts are created with ->obsolete set to the value
1036 * DST_OBSOLETE_FORCE_CHK which forces validation calls down
1037 * into this function always.
1038 */
1039 if (rt->rt6i_genid != rt_genid(dev_net(rt->dst.dev)))
1040 return NULL;
1041
1034 if (rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie)) { 1042 if (rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie)) {
1035 if (rt->rt6i_peer_genid != rt6_peer_genid()) { 1043 if (rt->rt6i_peer_genid != rt6_peer_genid()) {
1036 if (!rt6_has_peer(rt)) 1044 if (!rt6_has_peer(rt))
@@ -1397,8 +1405,6 @@ int ip6_route_add(struct fib6_config *cfg)
1397 goto out; 1405 goto out;
1398 } 1406 }
1399 1407
1400 rt->dst.obsolete = -1;
1401
1402 if (cfg->fc_flags & RTF_EXPIRES) 1408 if (cfg->fc_flags & RTF_EXPIRES)
1403 rt6_set_expires(rt, jiffies + 1409 rt6_set_expires(rt, jiffies +
1404 clock_t_to_jiffies(cfg->fc_expires)); 1410 clock_t_to_jiffies(cfg->fc_expires));
@@ -2080,7 +2086,6 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
2080 rt->dst.input = ip6_input; 2086 rt->dst.input = ip6_input;
2081 rt->dst.output = ip6_output; 2087 rt->dst.output = ip6_output;
2082 rt->rt6i_idev = idev; 2088 rt->rt6i_idev = idev;
2083 rt->dst.obsolete = -1;
2084 2089
2085 rt->rt6i_flags = RTF_UP | RTF_NONEXTHOP; 2090 rt->rt6i_flags = RTF_UP | RTF_NONEXTHOP;
2086 if (anycast) 2091 if (anycast)
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index a3e60cc04a8a..acd32e3f1b68 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -403,8 +403,9 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
403 tp->mtu_info = ntohl(info); 403 tp->mtu_info = ntohl(info);
404 if (!sock_owned_by_user(sk)) 404 if (!sock_owned_by_user(sk))
405 tcp_v6_mtu_reduced(sk); 405 tcp_v6_mtu_reduced(sk);
406 else 406 else if (!test_and_set_bit(TCP_MTU_REDUCED_DEFERRED,
407 set_bit(TCP_MTU_REDUCED_DEFERRED, &tp->tsq_flags); 407 &tp->tsq_flags))
408 sock_hold(sk);
408 goto out; 409 goto out;
409 } 410 }
410 411
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 99d0077b56b8..07e2bfef6845 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -394,6 +394,17 @@ try_again:
394 } 394 }
395 if (unlikely(err)) { 395 if (unlikely(err)) {
396 trace_kfree_skb(skb, udpv6_recvmsg); 396 trace_kfree_skb(skb, udpv6_recvmsg);
397 if (!peeked) {
398 atomic_inc(&sk->sk_drops);
399 if (is_udp4)
400 UDP_INC_STATS_USER(sock_net(sk),
401 UDP_MIB_INERRORS,
402 is_udplite);
403 else
404 UDP6_INC_STATS_USER(sock_net(sk),
405 UDP_MIB_INERRORS,
406 is_udplite);
407 }
397 goto out_free; 408 goto out_free;
398 } 409 }
399 if (!peeked) { 410 if (!peeked) {
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 513cab08a986..1a9f3723c13c 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -1501,6 +1501,8 @@ out:
1501 return err; 1501 return err;
1502} 1502}
1503 1503
1504static struct lock_class_key l2tp_socket_class;
1505
1504int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel **tunnelp) 1506int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel **tunnelp)
1505{ 1507{
1506 struct l2tp_tunnel *tunnel = NULL; 1508 struct l2tp_tunnel *tunnel = NULL;
@@ -1605,6 +1607,8 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1605 tunnel->old_sk_destruct = sk->sk_destruct; 1607 tunnel->old_sk_destruct = sk->sk_destruct;
1606 sk->sk_destruct = &l2tp_tunnel_destruct; 1608 sk->sk_destruct = &l2tp_tunnel_destruct;
1607 tunnel->sock = sk; 1609 tunnel->sock = sk;
1610 lockdep_set_class_and_name(&sk->sk_lock.slock, &l2tp_socket_class, "l2tp_sock");
1611
1608 sk->sk_allocation = GFP_ATOMIC; 1612 sk->sk_allocation = GFP_ATOMIC;
1609 1613
1610 /* Add tunnel to our list */ 1614 /* Add tunnel to our list */
diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
index f9ee74deeac2..3bfb34aaee29 100644
--- a/net/l2tp/l2tp_eth.c
+++ b/net/l2tp/l2tp_eth.c
@@ -153,7 +153,7 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
153 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, skb->data, length); 153 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, skb->data, length);
154 } 154 }
155 155
156 if (!pskb_may_pull(skb, sizeof(ETH_HLEN))) 156 if (!pskb_may_pull(skb, ETH_HLEN))
157 goto error; 157 goto error;
158 158
159 secpath_reset(skb); 159 secpath_reset(skb);
diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c
index d71cd9229a47..6f936358d664 100644
--- a/net/l2tp/l2tp_netlink.c
+++ b/net/l2tp/l2tp_netlink.c
@@ -80,8 +80,8 @@ static int l2tp_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
80 80
81 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq, 81 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
82 &l2tp_nl_family, 0, L2TP_CMD_NOOP); 82 &l2tp_nl_family, 0, L2TP_CMD_NOOP);
83 if (IS_ERR(hdr)) { 83 if (!hdr) {
84 ret = PTR_ERR(hdr); 84 ret = -EMSGSIZE;
85 goto err_out; 85 goto err_out;
86 } 86 }
87 87
@@ -250,8 +250,8 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
250 250
251 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, 251 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags,
252 L2TP_CMD_TUNNEL_GET); 252 L2TP_CMD_TUNNEL_GET);
253 if (IS_ERR(hdr)) 253 if (!hdr)
254 return PTR_ERR(hdr); 254 return -EMSGSIZE;
255 255
256 if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) || 256 if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) ||
257 nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) || 257 nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
@@ -617,8 +617,8 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 pid, u32 seq, int flags
617 sk = tunnel->sock; 617 sk = tunnel->sock;
618 618
619 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, L2TP_CMD_SESSION_GET); 619 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, L2TP_CMD_SESSION_GET);
620 if (IS_ERR(hdr)) 620 if (!hdr)
621 return PTR_ERR(hdr); 621 return -EMSGSIZE;
622 622
623 if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) || 623 if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
624 nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) || 624 nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) ||
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index d41974aacf51..a58c0b649ba1 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -1378,6 +1378,8 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1378 else 1378 else
1379 memset(next_hop, 0, ETH_ALEN); 1379 memset(next_hop, 0, ETH_ALEN);
1380 1380
1381 memset(pinfo, 0, sizeof(*pinfo));
1382
1381 pinfo->generation = mesh_paths_generation; 1383 pinfo->generation = mesh_paths_generation;
1382 1384
1383 pinfo->filled = MPATH_INFO_FRAME_QLEN | 1385 pinfo->filled = MPATH_INFO_FRAME_QLEN |
@@ -1396,7 +1398,6 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1396 pinfo->discovery_timeout = 1398 pinfo->discovery_timeout =
1397 jiffies_to_msecs(mpath->discovery_timeout); 1399 jiffies_to_msecs(mpath->discovery_timeout);
1398 pinfo->discovery_retries = mpath->discovery_retries; 1400 pinfo->discovery_retries = mpath->discovery_retries;
1399 pinfo->flags = 0;
1400 if (mpath->flags & MESH_PATH_ACTIVE) 1401 if (mpath->flags & MESH_PATH_ACTIVE)
1401 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; 1402 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1402 if (mpath->flags & MESH_PATH_RESOLVING) 1403 if (mpath->flags & MESH_PATH_RESOLVING)
@@ -1405,10 +1406,8 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1405 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; 1406 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1406 if (mpath->flags & MESH_PATH_FIXED) 1407 if (mpath->flags & MESH_PATH_FIXED)
1407 pinfo->flags |= NL80211_MPATH_FLAG_FIXED; 1408 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1408 if (mpath->flags & MESH_PATH_RESOLVING) 1409 if (mpath->flags & MESH_PATH_RESOLVED)
1409 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; 1410 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1410
1411 pinfo->flags = mpath->flags;
1412} 1411}
1413 1412
1414static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, 1413static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index a4a5acdbaa4d..f76b83341cf9 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -3248,6 +3248,8 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3248 goto out_unlock; 3248 goto out_unlock;
3249 3249
3250 err_clear: 3250 err_clear:
3251 memset(ifmgd->bssid, 0, ETH_ALEN);
3252 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
3251 ifmgd->auth_data = NULL; 3253 ifmgd->auth_data = NULL;
3252 err_free: 3254 err_free:
3253 kfree(auth_data); 3255 kfree(auth_data);
@@ -3439,6 +3441,8 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3439 err = 0; 3441 err = 0;
3440 goto out; 3442 goto out;
3441 err_clear: 3443 err_clear:
3444 memset(ifmgd->bssid, 0, ETH_ALEN);
3445 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
3442 ifmgd->assoc_data = NULL; 3446 ifmgd->assoc_data = NULL;
3443 err_free: 3447 err_free:
3444 kfree(assoc_data); 3448 kfree(assoc_data);
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index a5ac11ebef33..e046b3756aab 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -158,21 +158,18 @@ static const u8 tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
158 * sCL -> sSS 158 * sCL -> sSS
159 */ 159 */
160/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ 160/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
161/*synack*/ { sIV, sIV, sIG, sIG, sIG, sIG, sIG, sIG, sIG, sSR }, 161/*synack*/ { sIV, sIV, sSR, sIV, sIV, sIV, sIV, sIV, sIV, sSR },
162/* 162/*
163 * sNO -> sIV Too late and no reason to do anything 163 * sNO -> sIV Too late and no reason to do anything
164 * sSS -> sIV Client can't send SYN and then SYN/ACK 164 * sSS -> sIV Client can't send SYN and then SYN/ACK
165 * sS2 -> sSR SYN/ACK sent to SYN2 in simultaneous open 165 * sS2 -> sSR SYN/ACK sent to SYN2 in simultaneous open
166 * sSR -> sIG 166 * sSR -> sSR Late retransmitted SYN/ACK in simultaneous open
167 * sES -> sIG Error: SYNs in window outside the SYN_SENT state 167 * sES -> sIV Invalid SYN/ACK packets sent by the client
168 * are errors. Receiver will reply with RST 168 * sFW -> sIV
169 * and close the connection. 169 * sCW -> sIV
170 * Or we are not in sync and hold a dead connection. 170 * sLA -> sIV
171 * sFW -> sIG 171 * sTW -> sIV
172 * sCW -> sIG 172 * sCL -> sIV
173 * sLA -> sIG
174 * sTW -> sIG
175 * sCL -> sIG
176 */ 173 */
177/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */ 174/* sNO, sSS, sSR, sES, sFW, sCW, sLA, sTW, sCL, sS2 */
178/*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV }, 175/*fin*/ { sIV, sIV, sFW, sFW, sLA, sLA, sLA, sTW, sCL, sIV },
@@ -633,15 +630,9 @@ static bool tcp_in_window(const struct nf_conn *ct,
633 ack = sack = receiver->td_end; 630 ack = sack = receiver->td_end;
634 } 631 }
635 632
636 if (seq == end 633 if (tcph->rst && seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)
637 && (!tcph->rst
638 || (seq == 0 && state->state == TCP_CONNTRACK_SYN_SENT)))
639 /* 634 /*
640 * Packets contains no data: we assume it is valid 635 * RST sent answering SYN.
641 * and check the ack value only.
642 * However RST segments are always validated by their
643 * SEQ number, except when seq == 0 (reset sent answering
644 * SYN.
645 */ 636 */
646 seq = end = sender->td_end; 637 seq = end = sender->td_end;
647 638
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 14e2f3903142..5cfb5bedb2b8 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -381,6 +381,7 @@ __build_packet_message(struct nfulnl_instance *inst,
381 struct nlmsghdr *nlh; 381 struct nlmsghdr *nlh;
382 struct nfgenmsg *nfmsg; 382 struct nfgenmsg *nfmsg;
383 sk_buff_data_t old_tail = inst->skb->tail; 383 sk_buff_data_t old_tail = inst->skb->tail;
384 struct sock *sk;
384 385
385 nlh = nlmsg_put(inst->skb, 0, 0, 386 nlh = nlmsg_put(inst->skb, 0, 0,
386 NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET, 387 NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET,
@@ -499,18 +500,19 @@ __build_packet_message(struct nfulnl_instance *inst,
499 } 500 }
500 501
501 /* UID */ 502 /* UID */
502 if (skb->sk) { 503 sk = skb->sk;
503 read_lock_bh(&skb->sk->sk_callback_lock); 504 if (sk && sk->sk_state != TCP_TIME_WAIT) {
504 if (skb->sk->sk_socket && skb->sk->sk_socket->file) { 505 read_lock_bh(&sk->sk_callback_lock);
505 struct file *file = skb->sk->sk_socket->file; 506 if (sk->sk_socket && sk->sk_socket->file) {
507 struct file *file = sk->sk_socket->file;
506 __be32 uid = htonl(file->f_cred->fsuid); 508 __be32 uid = htonl(file->f_cred->fsuid);
507 __be32 gid = htonl(file->f_cred->fsgid); 509 __be32 gid = htonl(file->f_cred->fsgid);
508 read_unlock_bh(&skb->sk->sk_callback_lock); 510 read_unlock_bh(&sk->sk_callback_lock);
509 if (nla_put_be32(inst->skb, NFULA_UID, uid) || 511 if (nla_put_be32(inst->skb, NFULA_UID, uid) ||
510 nla_put_be32(inst->skb, NFULA_GID, gid)) 512 nla_put_be32(inst->skb, NFULA_GID, gid))
511 goto nla_put_failure; 513 goto nla_put_failure;
512 } else 514 } else
513 read_unlock_bh(&skb->sk->sk_callback_lock); 515 read_unlock_bh(&sk->sk_callback_lock);
514 } 516 }
515 517
516 /* local sequence number */ 518 /* local sequence number */
diff --git a/net/netfilter/xt_LOG.c b/net/netfilter/xt_LOG.c
index ff5f75fddb15..91e9af4d1f42 100644
--- a/net/netfilter/xt_LOG.c
+++ b/net/netfilter/xt_LOG.c
@@ -145,6 +145,19 @@ static int dump_tcp_header(struct sbuff *m, const struct sk_buff *skb,
145 return 0; 145 return 0;
146} 146}
147 147
148static void dump_sk_uid_gid(struct sbuff *m, struct sock *sk)
149{
150 if (!sk || sk->sk_state == TCP_TIME_WAIT)
151 return;
152
153 read_lock_bh(&sk->sk_callback_lock);
154 if (sk->sk_socket && sk->sk_socket->file)
155 sb_add(m, "UID=%u GID=%u ",
156 sk->sk_socket->file->f_cred->fsuid,
157 sk->sk_socket->file->f_cred->fsgid);
158 read_unlock_bh(&sk->sk_callback_lock);
159}
160
148/* One level of recursion won't kill us */ 161/* One level of recursion won't kill us */
149static void dump_ipv4_packet(struct sbuff *m, 162static void dump_ipv4_packet(struct sbuff *m,
150 const struct nf_loginfo *info, 163 const struct nf_loginfo *info,
@@ -361,14 +374,8 @@ static void dump_ipv4_packet(struct sbuff *m,
361 } 374 }
362 375
363 /* Max length: 15 "UID=4294967295 " */ 376 /* Max length: 15 "UID=4294967295 " */
364 if ((logflags & XT_LOG_UID) && !iphoff && skb->sk) { 377 if ((logflags & XT_LOG_UID) && !iphoff)
365 read_lock_bh(&skb->sk->sk_callback_lock); 378 dump_sk_uid_gid(m, skb->sk);
366 if (skb->sk->sk_socket && skb->sk->sk_socket->file)
367 sb_add(m, "UID=%u GID=%u ",
368 skb->sk->sk_socket->file->f_cred->fsuid,
369 skb->sk->sk_socket->file->f_cred->fsgid);
370 read_unlock_bh(&skb->sk->sk_callback_lock);
371 }
372 379
373 /* Max length: 16 "MARK=0xFFFFFFFF " */ 380 /* Max length: 16 "MARK=0xFFFFFFFF " */
374 if (!iphoff && skb->mark) 381 if (!iphoff && skb->mark)
@@ -436,8 +443,8 @@ log_packet_common(struct sbuff *m,
436 const struct nf_loginfo *loginfo, 443 const struct nf_loginfo *loginfo,
437 const char *prefix) 444 const char *prefix)
438{ 445{
439 sb_add(m, "<%d>%sIN=%s OUT=%s ", loginfo->u.log.level, 446 sb_add(m, KERN_SOH "%c%sIN=%s OUT=%s ",
440 prefix, 447 '0' + loginfo->u.log.level, prefix,
441 in ? in->name : "", 448 in ? in->name : "",
442 out ? out->name : ""); 449 out ? out->name : "");
443#ifdef CONFIG_BRIDGE_NETFILTER 450#ifdef CONFIG_BRIDGE_NETFILTER
@@ -717,14 +724,8 @@ static void dump_ipv6_packet(struct sbuff *m,
717 } 724 }
718 725
719 /* Max length: 15 "UID=4294967295 " */ 726 /* Max length: 15 "UID=4294967295 " */
720 if ((logflags & XT_LOG_UID) && recurse && skb->sk) { 727 if ((logflags & XT_LOG_UID) && recurse)
721 read_lock_bh(&skb->sk->sk_callback_lock); 728 dump_sk_uid_gid(m, skb->sk);
722 if (skb->sk->sk_socket && skb->sk->sk_socket->file)
723 sb_add(m, "UID=%u GID=%u ",
724 skb->sk->sk_socket->file->f_cred->fsuid,
725 skb->sk->sk_socket->file->f_cred->fsgid);
726 read_unlock_bh(&skb->sk->sk_callback_lock);
727 }
728 729
729 /* Max length: 16 "MARK=0xFFFFFFFF " */ 730 /* Max length: 16 "MARK=0xFFFFFFFF " */
730 if (!recurse && skb->mark) 731 if (!recurse && skb->mark)
diff --git a/net/netfilter/xt_limit.c b/net/netfilter/xt_limit.c
index 5c22ce8ab309..a4c1e4528cac 100644
--- a/net/netfilter/xt_limit.c
+++ b/net/netfilter/xt_limit.c
@@ -117,11 +117,11 @@ static int limit_mt_check(const struct xt_mtchk_param *par)
117 117
118 /* For SMP, we only want to use one set of state. */ 118 /* For SMP, we only want to use one set of state. */
119 r->master = priv; 119 r->master = priv;
120 /* User avg in seconds * XT_LIMIT_SCALE: convert to jiffies *
121 128. */
122 priv->prev = jiffies;
123 priv->credit = user2credits(r->avg * r->burst); /* Credits full. */
120 if (r->cost == 0) { 124 if (r->cost == 0) {
121 /* User avg in seconds * XT_LIMIT_SCALE: convert to jiffies *
122 128. */
123 priv->prev = jiffies;
124 priv->credit = user2credits(r->avg * r->burst); /* Credits full. */
125 r->credit_cap = priv->credit; /* Credits full. */ 125 r->credit_cap = priv->credit; /* Credits full. */
126 r->cost = user2credits(r->avg); 126 r->cost = user2credits(r->avg);
127 } 127 }
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index 06592d8b4a2b..7261eb81974f 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -601,7 +601,7 @@ static int nr_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
601 if (!capable(CAP_NET_BIND_SERVICE)) { 601 if (!capable(CAP_NET_BIND_SERVICE)) {
602 dev_put(dev); 602 dev_put(dev);
603 release_sock(sk); 603 release_sock(sk);
604 return -EACCES; 604 return -EPERM;
605 } 605 }
606 nr->user_addr = addr->fsa_digipeater[0]; 606 nr->user_addr = addr->fsa_digipeater[0];
607 nr->source_addr = addr->fsa_ax25.sax25_call; 607 nr->source_addr = addr->fsa_ax25.sax25_call;
@@ -1169,7 +1169,12 @@ static int nr_recvmsg(struct kiocb *iocb, struct socket *sock,
1169 msg->msg_flags |= MSG_TRUNC; 1169 msg->msg_flags |= MSG_TRUNC;
1170 } 1170 }
1171 1171
1172 skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); 1172 er = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1173 if (er < 0) {
1174 skb_free_datagram(sk, skb);
1175 release_sock(sk);
1176 return er;
1177 }
1173 1178
1174 if (sax != NULL) { 1179 if (sax != NULL) {
1175 sax->sax25_family = AF_NETROM; 1180 sax->sax25_family = AF_NETROM;
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index f3f96badf5aa..954405ceae9e 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -45,7 +45,7 @@ static int make_writable(struct sk_buff *skb, int write_len)
45 return pskb_expand_head(skb, 0, 0, GFP_ATOMIC); 45 return pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
46} 46}
47 47
48/* remove VLAN header from packet and update csum accrodingly. */ 48/* remove VLAN header from packet and update csum accordingly. */
49static int __pop_vlan_tci(struct sk_buff *skb, __be16 *current_tci) 49static int __pop_vlan_tci(struct sk_buff *skb, __be16 *current_tci)
50{ 50{
51 struct vlan_hdr *vhdr; 51 struct vlan_hdr *vhdr;
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index d8277d29e710..cf58cedad083 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -425,10 +425,10 @@ static int validate_sample(const struct nlattr *attr,
425static int validate_tp_port(const struct sw_flow_key *flow_key) 425static int validate_tp_port(const struct sw_flow_key *flow_key)
426{ 426{
427 if (flow_key->eth.type == htons(ETH_P_IP)) { 427 if (flow_key->eth.type == htons(ETH_P_IP)) {
428 if (flow_key->ipv4.tp.src && flow_key->ipv4.tp.dst) 428 if (flow_key->ipv4.tp.src || flow_key->ipv4.tp.dst)
429 return 0; 429 return 0;
430 } else if (flow_key->eth.type == htons(ETH_P_IPV6)) { 430 } else if (flow_key->eth.type == htons(ETH_P_IPV6)) {
431 if (flow_key->ipv6.tp.src && flow_key->ipv6.tp.dst) 431 if (flow_key->ipv6.tp.src || flow_key->ipv6.tp.dst)
432 return 0; 432 return 0;
433 } 433 }
434 434
@@ -460,7 +460,7 @@ static int validate_set(const struct nlattr *a,
460 if (flow_key->eth.type != htons(ETH_P_IP)) 460 if (flow_key->eth.type != htons(ETH_P_IP))
461 return -EINVAL; 461 return -EINVAL;
462 462
463 if (!flow_key->ipv4.addr.src || !flow_key->ipv4.addr.dst) 463 if (!flow_key->ip.proto)
464 return -EINVAL; 464 return -EINVAL;
465 465
466 ipv4_key = nla_data(ovs_key); 466 ipv4_key = nla_data(ovs_key);
diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h
index 9b75617ca4e0..c30df1a10c67 100644
--- a/net/openvswitch/flow.h
+++ b/net/openvswitch/flow.h
@@ -145,15 +145,17 @@ u64 ovs_flow_used_time(unsigned long flow_jiffies);
145 * OVS_KEY_ATTR_PRIORITY 4 -- 4 8 145 * OVS_KEY_ATTR_PRIORITY 4 -- 4 8
146 * OVS_KEY_ATTR_IN_PORT 4 -- 4 8 146 * OVS_KEY_ATTR_IN_PORT 4 -- 4 8
147 * OVS_KEY_ATTR_ETHERNET 12 -- 4 16 147 * OVS_KEY_ATTR_ETHERNET 12 -- 4 16
148 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (outer VLAN ethertype)
148 * OVS_KEY_ATTR_8021Q 4 -- 4 8 149 * OVS_KEY_ATTR_8021Q 4 -- 4 8
149 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 150 * OVS_KEY_ATTR_ENCAP 0 -- 4 4 (VLAN encapsulation)
151 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 (inner VLAN ethertype)
150 * OVS_KEY_ATTR_IPV6 40 -- 4 44 152 * OVS_KEY_ATTR_IPV6 40 -- 4 44
151 * OVS_KEY_ATTR_ICMPV6 2 2 4 8 153 * OVS_KEY_ATTR_ICMPV6 2 2 4 8
152 * OVS_KEY_ATTR_ND 28 -- 4 32 154 * OVS_KEY_ATTR_ND 28 -- 4 32
153 * ------------------------------------------------- 155 * -------------------------------------------------
154 * total 132 156 * total 144
155 */ 157 */
156#define FLOW_BUFSIZE 132 158#define FLOW_BUFSIZE 144
157 159
158int ovs_flow_to_nlattrs(const struct sw_flow_key *, struct sk_buff *); 160int ovs_flow_to_nlattrs(const struct sw_flow_key *, struct sk_buff *);
159int ovs_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp, 161int ovs_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp,
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 6aabd77d1cfd..564b9fc8efd3 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -250,10 +250,11 @@ cbq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
250 else if ((cl = defmap[res.classid & TC_PRIO_MAX]) == NULL) 250 else if ((cl = defmap[res.classid & TC_PRIO_MAX]) == NULL)
251 cl = defmap[TC_PRIO_BESTEFFORT]; 251 cl = defmap[TC_PRIO_BESTEFFORT];
252 252
253 if (cl == NULL || cl->level >= head->level) 253 if (cl == NULL)
254 goto fallback; 254 goto fallback;
255 } 255 }
256 256 if (cl->level >= head->level)
257 goto fallback;
257#ifdef CONFIG_NET_CLS_ACT 258#ifdef CONFIG_NET_CLS_ACT
258 switch (result) { 259 switch (result) {
259 case TC_ACT_QUEUED: 260 case TC_ACT_QUEUED:
diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
index 9fc1c62ec80e..4e606fcb2534 100644
--- a/net/sched/sch_fq_codel.c
+++ b/net/sched/sch_fq_codel.c
@@ -191,7 +191,6 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch)
191 191
192 if (list_empty(&flow->flowchain)) { 192 if (list_empty(&flow->flowchain)) {
193 list_add_tail(&flow->flowchain, &q->new_flows); 193 list_add_tail(&flow->flowchain, &q->new_flows);
194 codel_vars_init(&flow->cvars);
195 q->new_flow_count++; 194 q->new_flow_count++;
196 flow->deficit = q->quantum; 195 flow->deficit = q->quantum;
197 flow->dropped = 0; 196 flow->dropped = 0;
@@ -418,6 +417,7 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
418 struct fq_codel_flow *flow = q->flows + i; 417 struct fq_codel_flow *flow = q->flows + i;
419 418
420 INIT_LIST_HEAD(&flow->flowchain); 419 INIT_LIST_HEAD(&flow->flowchain);
420 codel_vars_init(&flow->cvars);
421 } 421 }
422 } 422 }
423 if (sch->limit >= 1) 423 if (sch->limit >= 1)
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index e901583e4ea5..d42234c0f13b 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -102,9 +102,8 @@ static inline int gred_wred_mode_check(struct Qdisc *sch)
102 if (q == NULL) 102 if (q == NULL)
103 continue; 103 continue;
104 104
105 for (n = 0; n < table->DPs; n++) 105 for (n = i + 1; n < table->DPs; n++)
106 if (table->tab[n] && table->tab[n] != q && 106 if (table->tab[n] && table->tab[n]->prio == q->prio)
107 table->tab[n]->prio == q->prio)
108 return 1; 107 return 1;
109 } 108 }
110 109
@@ -137,6 +136,7 @@ static inline void gred_store_wred_set(struct gred_sched *table,
137 struct gred_sched_data *q) 136 struct gred_sched_data *q)
138{ 137{
139 table->wred_set.qavg = q->vars.qavg; 138 table->wred_set.qavg = q->vars.qavg;
139 table->wred_set.qidlestart = q->vars.qidlestart;
140} 140}
141 141
142static inline int gred_use_ecn(struct gred_sched *t) 142static inline int gred_use_ecn(struct gred_sched *t)
@@ -176,7 +176,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch)
176 skb->tc_index = (skb->tc_index & ~GRED_VQ_MASK) | dp; 176 skb->tc_index = (skb->tc_index & ~GRED_VQ_MASK) | dp;
177 } 177 }
178 178
179 /* sum up all the qaves of prios <= to ours to get the new qave */ 179 /* sum up all the qaves of prios < ours to get the new qave */
180 if (!gred_wred_mode(t) && gred_rio_mode(t)) { 180 if (!gred_wred_mode(t) && gred_rio_mode(t)) {
181 int i; 181 int i;
182 182
@@ -260,16 +260,18 @@ static struct sk_buff *gred_dequeue(struct Qdisc *sch)
260 } else { 260 } else {
261 q->backlog -= qdisc_pkt_len(skb); 261 q->backlog -= qdisc_pkt_len(skb);
262 262
263 if (!q->backlog && !gred_wred_mode(t)) 263 if (gred_wred_mode(t)) {
264 red_start_of_idle_period(&q->vars); 264 if (!sch->qstats.backlog)
265 red_start_of_idle_period(&t->wred_set);
266 } else {
267 if (!q->backlog)
268 red_start_of_idle_period(&q->vars);
269 }
265 } 270 }
266 271
267 return skb; 272 return skb;
268 } 273 }
269 274
270 if (gred_wred_mode(t) && !red_is_idling(&t->wred_set))
271 red_start_of_idle_period(&t->wred_set);
272
273 return NULL; 275 return NULL;
274} 276}
275 277
@@ -291,19 +293,20 @@ static unsigned int gred_drop(struct Qdisc *sch)
291 q->backlog -= len; 293 q->backlog -= len;
292 q->stats.other++; 294 q->stats.other++;
293 295
294 if (!q->backlog && !gred_wred_mode(t)) 296 if (gred_wred_mode(t)) {
295 red_start_of_idle_period(&q->vars); 297 if (!sch->qstats.backlog)
298 red_start_of_idle_period(&t->wred_set);
299 } else {
300 if (!q->backlog)
301 red_start_of_idle_period(&q->vars);
302 }
296 } 303 }
297 304
298 qdisc_drop(skb, sch); 305 qdisc_drop(skb, sch);
299 return len; 306 return len;
300 } 307 }
301 308
302 if (gred_wred_mode(t) && !red_is_idling(&t->wred_set))
303 red_start_of_idle_period(&t->wred_set);
304
305 return 0; 309 return 0;
306
307} 310}
308 311
309static void gred_reset(struct Qdisc *sch) 312static void gred_reset(struct Qdisc *sch)
@@ -535,6 +538,7 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
535 for (i = 0; i < MAX_DPs; i++) { 538 for (i = 0; i < MAX_DPs; i++) {
536 struct gred_sched_data *q = table->tab[i]; 539 struct gred_sched_data *q = table->tab[i];
537 struct tc_gred_qopt opt; 540 struct tc_gred_qopt opt;
541 unsigned long qavg;
538 542
539 memset(&opt, 0, sizeof(opt)); 543 memset(&opt, 0, sizeof(opt));
540 544
@@ -566,7 +570,9 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
566 if (gred_wred_mode(table)) 570 if (gred_wred_mode(table))
567 gred_load_wred_set(table, q); 571 gred_load_wred_set(table, q);
568 572
569 opt.qave = red_calc_qavg(&q->parms, &q->vars, q->vars.qavg); 573 qavg = red_calc_qavg(&q->parms, &q->vars,
574 q->vars.qavg >> q->parms.Wlog);
575 opt.qave = qavg >> q->parms.Wlog;
570 576
571append_opt: 577append_opt:
572 if (nla_append(skb, sizeof(opt), &opt) < 0) 578 if (nla_append(skb, sizeof(opt), &opt) < 0)
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
index e4723d31fdd5..211a21217045 100644
--- a/net/sched/sch_qfq.c
+++ b/net/sched/sch_qfq.c
@@ -865,7 +865,10 @@ static void qfq_update_start(struct qfq_sched *q, struct qfq_class *cl)
865 if (mask) { 865 if (mask) {
866 struct qfq_group *next = qfq_ffs(q, mask); 866 struct qfq_group *next = qfq_ffs(q, mask);
867 if (qfq_gt(roundedF, next->F)) { 867 if (qfq_gt(roundedF, next->F)) {
868 cl->S = next->F; 868 if (qfq_gt(limit, next->F))
869 cl->S = next->F;
870 else /* preserve timestamp correctness */
871 cl->S = limit;
869 return; 872 return;
870 } 873 }
871 } 874 }
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 838e18b4d7ea..be50aa234dcd 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -364,6 +364,25 @@ finish:
364 return retval; 364 return retval;
365} 365}
366 366
367static void sctp_packet_release_owner(struct sk_buff *skb)
368{
369 sk_free(skb->sk);
370}
371
372static void sctp_packet_set_owner_w(struct sk_buff *skb, struct sock *sk)
373{
374 skb_orphan(skb);
375 skb->sk = sk;
376 skb->destructor = sctp_packet_release_owner;
377
378 /*
379 * The data chunks have already been accounted for in sctp_sendmsg(),
380 * therefore only reserve a single byte to keep socket around until
381 * the packet has been transmitted.
382 */
383 atomic_inc(&sk->sk_wmem_alloc);
384}
385
367/* All packets are sent to the network through this function from 386/* All packets are sent to the network through this function from
368 * sctp_outq_tail(). 387 * sctp_outq_tail().
369 * 388 *
@@ -405,7 +424,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
405 /* Set the owning socket so that we know where to get the 424 /* Set the owning socket so that we know where to get the
406 * destination IP address. 425 * destination IP address.
407 */ 426 */
408 skb_set_owner_w(nskb, sk); 427 sctp_packet_set_owner_w(nskb, sk);
409 428
410 if (!sctp_transport_dst_check(tp)) { 429 if (!sctp_transport_dst_check(tp)) {
411 sctp_transport_route(tp, NULL, sctp_sk(sk)); 430 sctp_transport_route(tp, NULL, sctp_sk(sk));
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index a5a402a7d21f..5d7f61d7559c 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -969,11 +969,11 @@ static bool xprt_dynamic_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
969 return false; 969 return false;
970} 970}
971 971
972static void xprt_alloc_slot(struct rpc_task *task) 972void xprt_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task)
973{ 973{
974 struct rpc_xprt *xprt = task->tk_xprt;
975 struct rpc_rqst *req; 974 struct rpc_rqst *req;
976 975
976 spin_lock(&xprt->reserve_lock);
977 if (!list_empty(&xprt->free)) { 977 if (!list_empty(&xprt->free)) {
978 req = list_entry(xprt->free.next, struct rpc_rqst, rq_list); 978 req = list_entry(xprt->free.next, struct rpc_rqst, rq_list);
979 list_del(&req->rq_list); 979 list_del(&req->rq_list);
@@ -994,12 +994,29 @@ static void xprt_alloc_slot(struct rpc_task *task)
994 default: 994 default:
995 task->tk_status = -EAGAIN; 995 task->tk_status = -EAGAIN;
996 } 996 }
997 spin_unlock(&xprt->reserve_lock);
997 return; 998 return;
998out_init_req: 999out_init_req:
999 task->tk_status = 0; 1000 task->tk_status = 0;
1000 task->tk_rqstp = req; 1001 task->tk_rqstp = req;
1001 xprt_request_init(task, xprt); 1002 xprt_request_init(task, xprt);
1003 spin_unlock(&xprt->reserve_lock);
1004}
1005EXPORT_SYMBOL_GPL(xprt_alloc_slot);
1006
1007void xprt_lock_and_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task)
1008{
1009 /* Note: grabbing the xprt_lock_write() ensures that we throttle
1010 * new slot allocation if the transport is congested (i.e. when
1011 * reconnecting a stream transport or when out of socket write
1012 * buffer space).
1013 */
1014 if (xprt_lock_write(xprt, task)) {
1015 xprt_alloc_slot(xprt, task);
1016 xprt_release_write(xprt, task);
1017 }
1002} 1018}
1019EXPORT_SYMBOL_GPL(xprt_lock_and_alloc_slot);
1003 1020
1004static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req) 1021static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
1005{ 1022{
@@ -1083,20 +1100,9 @@ void xprt_reserve(struct rpc_task *task)
1083 if (task->tk_rqstp != NULL) 1100 if (task->tk_rqstp != NULL)
1084 return; 1101 return;
1085 1102
1086 /* Note: grabbing the xprt_lock_write() here is not strictly needed,
1087 * but ensures that we throttle new slot allocation if the transport
1088 * is congested (e.g. if reconnecting or if we're out of socket
1089 * write buffer space).
1090 */
1091 task->tk_timeout = 0; 1103 task->tk_timeout = 0;
1092 task->tk_status = -EAGAIN; 1104 task->tk_status = -EAGAIN;
1093 if (!xprt_lock_write(xprt, task)) 1105 xprt->ops->alloc_slot(xprt, task);
1094 return;
1095
1096 spin_lock(&xprt->reserve_lock);
1097 xprt_alloc_slot(task);
1098 spin_unlock(&xprt->reserve_lock);
1099 xprt_release_write(xprt, task);
1100} 1106}
1101 1107
1102static inline __be32 xprt_alloc_xid(struct rpc_xprt *xprt) 1108static inline __be32 xprt_alloc_xid(struct rpc_xprt *xprt)
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 06cdbff79e4a..5d9202dc7cb1 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -713,6 +713,7 @@ static void xprt_rdma_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
713static struct rpc_xprt_ops xprt_rdma_procs = { 713static struct rpc_xprt_ops xprt_rdma_procs = {
714 .reserve_xprt = xprt_rdma_reserve_xprt, 714 .reserve_xprt = xprt_rdma_reserve_xprt,
715 .release_xprt = xprt_release_xprt_cong, /* sunrpc/xprt.c */ 715 .release_xprt = xprt_release_xprt_cong, /* sunrpc/xprt.c */
716 .alloc_slot = xprt_alloc_slot,
716 .release_request = xprt_release_rqst_cong, /* ditto */ 717 .release_request = xprt_release_rqst_cong, /* ditto */
717 .set_retrans_timeout = xprt_set_retrans_timeout_def, /* ditto */ 718 .set_retrans_timeout = xprt_set_retrans_timeout_def, /* ditto */
718 .rpcbind = rpcb_getport_async, /* sunrpc/rpcb_clnt.c */ 719 .rpcbind = rpcb_getport_async, /* sunrpc/rpcb_clnt.c */
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 400567243f84..a35b8e52e551 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -2473,6 +2473,7 @@ static void bc_destroy(struct rpc_xprt *xprt)
2473static struct rpc_xprt_ops xs_local_ops = { 2473static struct rpc_xprt_ops xs_local_ops = {
2474 .reserve_xprt = xprt_reserve_xprt, 2474 .reserve_xprt = xprt_reserve_xprt,
2475 .release_xprt = xs_tcp_release_xprt, 2475 .release_xprt = xs_tcp_release_xprt,
2476 .alloc_slot = xprt_alloc_slot,
2476 .rpcbind = xs_local_rpcbind, 2477 .rpcbind = xs_local_rpcbind,
2477 .set_port = xs_local_set_port, 2478 .set_port = xs_local_set_port,
2478 .connect = xs_connect, 2479 .connect = xs_connect,
@@ -2489,6 +2490,7 @@ static struct rpc_xprt_ops xs_udp_ops = {
2489 .set_buffer_size = xs_udp_set_buffer_size, 2490 .set_buffer_size = xs_udp_set_buffer_size,
2490 .reserve_xprt = xprt_reserve_xprt_cong, 2491 .reserve_xprt = xprt_reserve_xprt_cong,
2491 .release_xprt = xprt_release_xprt_cong, 2492 .release_xprt = xprt_release_xprt_cong,
2493 .alloc_slot = xprt_alloc_slot,
2492 .rpcbind = rpcb_getport_async, 2494 .rpcbind = rpcb_getport_async,
2493 .set_port = xs_set_port, 2495 .set_port = xs_set_port,
2494 .connect = xs_connect, 2496 .connect = xs_connect,
@@ -2506,6 +2508,7 @@ static struct rpc_xprt_ops xs_udp_ops = {
2506static struct rpc_xprt_ops xs_tcp_ops = { 2508static struct rpc_xprt_ops xs_tcp_ops = {
2507 .reserve_xprt = xprt_reserve_xprt, 2509 .reserve_xprt = xprt_reserve_xprt,
2508 .release_xprt = xs_tcp_release_xprt, 2510 .release_xprt = xs_tcp_release_xprt,
2511 .alloc_slot = xprt_lock_and_alloc_slot,
2509 .rpcbind = rpcb_getport_async, 2512 .rpcbind = rpcb_getport_async,
2510 .set_port = xs_set_port, 2513 .set_port = xs_set_port,
2511 .connect = xs_connect, 2514 .connect = xs_connect,
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 97026f3b215a..1e37dbf00cb3 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5633,8 +5633,10 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5633 sizeof(connect.ht_capa_mask)); 5633 sizeof(connect.ht_capa_mask));
5634 5634
5635 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 5635 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5636 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 5636 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
5637 kfree(connkeys);
5637 return -EINVAL; 5638 return -EINVAL;
5639 }
5638 memcpy(&connect.ht_capa, 5640 memcpy(&connect.ht_capa,
5639 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 5641 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5640 sizeof(connect.ht_capa)); 5642 sizeof(connect.ht_capa));
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 2ded3c7fad06..72d170ca3406 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -350,6 +350,9 @@ static void reg_regdb_search(struct work_struct *work)
350 struct reg_regdb_search_request *request; 350 struct reg_regdb_search_request *request;
351 const struct ieee80211_regdomain *curdom, *regdom; 351 const struct ieee80211_regdomain *curdom, *regdom;
352 int i, r; 352 int i, r;
353 bool set_reg = false;
354
355 mutex_lock(&cfg80211_mutex);
353 356
354 mutex_lock(&reg_regdb_search_mutex); 357 mutex_lock(&reg_regdb_search_mutex);
355 while (!list_empty(&reg_regdb_search_list)) { 358 while (!list_empty(&reg_regdb_search_list)) {
@@ -365,9 +368,7 @@ static void reg_regdb_search(struct work_struct *work)
365 r = reg_copy_regd(&regdom, curdom); 368 r = reg_copy_regd(&regdom, curdom);
366 if (r) 369 if (r)
367 break; 370 break;
368 mutex_lock(&cfg80211_mutex); 371 set_reg = true;
369 set_regdom(regdom);
370 mutex_unlock(&cfg80211_mutex);
371 break; 372 break;
372 } 373 }
373 } 374 }
@@ -375,6 +376,11 @@ static void reg_regdb_search(struct work_struct *work)
375 kfree(request); 376 kfree(request);
376 } 377 }
377 mutex_unlock(&reg_regdb_search_mutex); 378 mutex_unlock(&reg_regdb_search_mutex);
379
380 if (set_reg)
381 set_regdom(regdom);
382
383 mutex_unlock(&cfg80211_mutex);
378} 384}
379 385
380static DECLARE_WORK(reg_regdb_work, reg_regdb_search); 386static DECLARE_WORK(reg_regdb_work, reg_regdb_search);
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 54a0dc2e2f8d..ab2bb42fe094 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -212,7 +212,7 @@ resume:
212 /* only the first xfrm gets the encap type */ 212 /* only the first xfrm gets the encap type */
213 encap_type = 0; 213 encap_type = 0;
214 214
215 if (async && x->repl->check(x, skb, seq)) { 215 if (async && x->repl->recheck(x, skb, seq)) {
216 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR); 216 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR);
217 goto drop_unlock; 217 goto drop_unlock;
218 } 218 }
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 5a2aa17e4d3c..387848e90078 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -585,6 +585,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
585 xfrm_pol_hold(policy); 585 xfrm_pol_hold(policy);
586 net->xfrm.policy_count[dir]++; 586 net->xfrm.policy_count[dir]++;
587 atomic_inc(&flow_cache_genid); 587 atomic_inc(&flow_cache_genid);
588 rt_genid_bump(net);
588 if (delpol) 589 if (delpol)
589 __xfrm_policy_unlink(delpol, dir); 590 __xfrm_policy_unlink(delpol, dir);
590 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir); 591 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
@@ -1763,7 +1764,7 @@ static struct dst_entry *make_blackhole(struct net *net, u16 family,
1763 1764
1764 if (!afinfo) { 1765 if (!afinfo) {
1765 dst_release(dst_orig); 1766 dst_release(dst_orig);
1766 ret = ERR_PTR(-EINVAL); 1767 return ERR_PTR(-EINVAL);
1767 } else { 1768 } else {
1768 ret = afinfo->blackhole_route(net, dst_orig); 1769 ret = afinfo->blackhole_route(net, dst_orig);
1769 } 1770 }
diff --git a/net/xfrm/xfrm_replay.c b/net/xfrm/xfrm_replay.c
index 2f6d11d04a2b..3efb07d3eb27 100644
--- a/net/xfrm/xfrm_replay.c
+++ b/net/xfrm/xfrm_replay.c
@@ -420,6 +420,18 @@ err:
420 return -EINVAL; 420 return -EINVAL;
421} 421}
422 422
423static int xfrm_replay_recheck_esn(struct xfrm_state *x,
424 struct sk_buff *skb, __be32 net_seq)
425{
426 if (unlikely(XFRM_SKB_CB(skb)->seq.input.hi !=
427 htonl(xfrm_replay_seqhi(x, net_seq)))) {
428 x->stats.replay_window++;
429 return -EINVAL;
430 }
431
432 return xfrm_replay_check_esn(x, skb, net_seq);
433}
434
423static void xfrm_replay_advance_esn(struct xfrm_state *x, __be32 net_seq) 435static void xfrm_replay_advance_esn(struct xfrm_state *x, __be32 net_seq)
424{ 436{
425 unsigned int bitnr, nr, i; 437 unsigned int bitnr, nr, i;
@@ -479,6 +491,7 @@ static void xfrm_replay_advance_esn(struct xfrm_state *x, __be32 net_seq)
479static struct xfrm_replay xfrm_replay_legacy = { 491static struct xfrm_replay xfrm_replay_legacy = {
480 .advance = xfrm_replay_advance, 492 .advance = xfrm_replay_advance,
481 .check = xfrm_replay_check, 493 .check = xfrm_replay_check,
494 .recheck = xfrm_replay_check,
482 .notify = xfrm_replay_notify, 495 .notify = xfrm_replay_notify,
483 .overflow = xfrm_replay_overflow, 496 .overflow = xfrm_replay_overflow,
484}; 497};
@@ -486,6 +499,7 @@ static struct xfrm_replay xfrm_replay_legacy = {
486static struct xfrm_replay xfrm_replay_bmp = { 499static struct xfrm_replay xfrm_replay_bmp = {
487 .advance = xfrm_replay_advance_bmp, 500 .advance = xfrm_replay_advance_bmp,
488 .check = xfrm_replay_check_bmp, 501 .check = xfrm_replay_check_bmp,
502 .recheck = xfrm_replay_check_bmp,
489 .notify = xfrm_replay_notify_bmp, 503 .notify = xfrm_replay_notify_bmp,
490 .overflow = xfrm_replay_overflow_bmp, 504 .overflow = xfrm_replay_overflow_bmp,
491}; 505};
@@ -493,6 +507,7 @@ static struct xfrm_replay xfrm_replay_bmp = {
493static struct xfrm_replay xfrm_replay_esn = { 507static struct xfrm_replay xfrm_replay_esn = {
494 .advance = xfrm_replay_advance_esn, 508 .advance = xfrm_replay_advance_esn,
495 .check = xfrm_replay_check_esn, 509 .check = xfrm_replay_check_esn,
510 .recheck = xfrm_replay_recheck_esn,
496 .notify = xfrm_replay_notify_bmp, 511 .notify = xfrm_replay_notify_bmp,
497 .overflow = xfrm_replay_overflow_esn, 512 .overflow = xfrm_replay_overflow_esn,
498}; 513};
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index e75d8e47f35c..289f4bf18ff0 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -123,9 +123,21 @@ static inline int verify_replay(struct xfrm_usersa_info *p,
123 struct nlattr **attrs) 123 struct nlattr **attrs)
124{ 124{
125 struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL]; 125 struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL];
126 struct xfrm_replay_state_esn *rs;
126 127
127 if ((p->flags & XFRM_STATE_ESN) && !rt) 128 if (p->flags & XFRM_STATE_ESN) {
128 return -EINVAL; 129 if (!rt)
130 return -EINVAL;
131
132 rs = nla_data(rt);
133
134 if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8)
135 return -EINVAL;
136
137 if (nla_len(rt) < xfrm_replay_state_esn_len(rs) &&
138 nla_len(rt) != sizeof(*rs))
139 return -EINVAL;
140 }
129 141
130 if (!rt) 142 if (!rt)
131 return 0; 143 return 0;
@@ -370,14 +382,15 @@ static inline int xfrm_replay_verify_len(struct xfrm_replay_state_esn *replay_es
370 struct nlattr *rp) 382 struct nlattr *rp)
371{ 383{
372 struct xfrm_replay_state_esn *up; 384 struct xfrm_replay_state_esn *up;
385 int ulen;
373 386
374 if (!replay_esn || !rp) 387 if (!replay_esn || !rp)
375 return 0; 388 return 0;
376 389
377 up = nla_data(rp); 390 up = nla_data(rp);
391 ulen = xfrm_replay_state_esn_len(up);
378 392
379 if (xfrm_replay_state_esn_len(replay_esn) != 393 if (nla_len(rp) < ulen || xfrm_replay_state_esn_len(replay_esn) != ulen)
380 xfrm_replay_state_esn_len(up))
381 return -EINVAL; 394 return -EINVAL;
382 395
383 return 0; 396 return 0;
@@ -388,22 +401,28 @@ static int xfrm_alloc_replay_state_esn(struct xfrm_replay_state_esn **replay_esn
388 struct nlattr *rta) 401 struct nlattr *rta)
389{ 402{
390 struct xfrm_replay_state_esn *p, *pp, *up; 403 struct xfrm_replay_state_esn *p, *pp, *up;
404 int klen, ulen;
391 405
392 if (!rta) 406 if (!rta)
393 return 0; 407 return 0;
394 408
395 up = nla_data(rta); 409 up = nla_data(rta);
410 klen = xfrm_replay_state_esn_len(up);
411 ulen = nla_len(rta) >= klen ? klen : sizeof(*up);
396 412
397 p = kmemdup(up, xfrm_replay_state_esn_len(up), GFP_KERNEL); 413 p = kzalloc(klen, GFP_KERNEL);
398 if (!p) 414 if (!p)
399 return -ENOMEM; 415 return -ENOMEM;
400 416
401 pp = kmemdup(up, xfrm_replay_state_esn_len(up), GFP_KERNEL); 417 pp = kzalloc(klen, GFP_KERNEL);
402 if (!pp) { 418 if (!pp) {
403 kfree(p); 419 kfree(p);
404 return -ENOMEM; 420 return -ENOMEM;
405 } 421 }
406 422
423 memcpy(p, up, ulen);
424 memcpy(pp, up, ulen);
425
407 *replay_esn = p; 426 *replay_esn = p;
408 *preplay_esn = pp; 427 *preplay_esn = pp;
409 428
@@ -442,10 +461,11 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *
442 * somehow made shareable and move it to xfrm_state.c - JHS 461 * somehow made shareable and move it to xfrm_state.c - JHS
443 * 462 *
444*/ 463*/
445static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs) 464static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs,
465 int update_esn)
446{ 466{
447 struct nlattr *rp = attrs[XFRMA_REPLAY_VAL]; 467 struct nlattr *rp = attrs[XFRMA_REPLAY_VAL];
448 struct nlattr *re = attrs[XFRMA_REPLAY_ESN_VAL]; 468 struct nlattr *re = update_esn ? attrs[XFRMA_REPLAY_ESN_VAL] : NULL;
449 struct nlattr *lt = attrs[XFRMA_LTIME_VAL]; 469 struct nlattr *lt = attrs[XFRMA_LTIME_VAL];
450 struct nlattr *et = attrs[XFRMA_ETIMER_THRESH]; 470 struct nlattr *et = attrs[XFRMA_ETIMER_THRESH];
451 struct nlattr *rt = attrs[XFRMA_REPLAY_THRESH]; 471 struct nlattr *rt = attrs[XFRMA_REPLAY_THRESH];
@@ -555,7 +575,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
555 goto error; 575 goto error;
556 576
557 /* override default values from above */ 577 /* override default values from above */
558 xfrm_update_ae_params(x, attrs); 578 xfrm_update_ae_params(x, attrs, 0);
559 579
560 return x; 580 return x;
561 581
@@ -689,6 +709,7 @@ out:
689 709
690static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p) 710static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p)
691{ 711{
712 memset(p, 0, sizeof(*p));
692 memcpy(&p->id, &x->id, sizeof(p->id)); 713 memcpy(&p->id, &x->id, sizeof(p->id));
693 memcpy(&p->sel, &x->sel, sizeof(p->sel)); 714 memcpy(&p->sel, &x->sel, sizeof(p->sel));
694 memcpy(&p->lft, &x->lft, sizeof(p->lft)); 715 memcpy(&p->lft, &x->lft, sizeof(p->lft));
@@ -742,7 +763,7 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
742 return -EMSGSIZE; 763 return -EMSGSIZE;
743 764
744 algo = nla_data(nla); 765 algo = nla_data(nla);
745 strcpy(algo->alg_name, auth->alg_name); 766 strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
746 memcpy(algo->alg_key, auth->alg_key, (auth->alg_key_len + 7) / 8); 767 memcpy(algo->alg_key, auth->alg_key, (auth->alg_key_len + 7) / 8);
747 algo->alg_key_len = auth->alg_key_len; 768 algo->alg_key_len = auth->alg_key_len;
748 769
@@ -878,6 +899,7 @@ static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb,
878{ 899{
879 struct xfrm_dump_info info; 900 struct xfrm_dump_info info;
880 struct sk_buff *skb; 901 struct sk_buff *skb;
902 int err;
881 903
882 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 904 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
883 if (!skb) 905 if (!skb)
@@ -888,9 +910,10 @@ static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb,
888 info.nlmsg_seq = seq; 910 info.nlmsg_seq = seq;
889 info.nlmsg_flags = 0; 911 info.nlmsg_flags = 0;
890 912
891 if (dump_one_state(x, 0, &info)) { 913 err = dump_one_state(x, 0, &info);
914 if (err) {
892 kfree_skb(skb); 915 kfree_skb(skb);
893 return NULL; 916 return ERR_PTR(err);
894 } 917 }
895 918
896 return skb; 919 return skb;
@@ -1317,6 +1340,7 @@ static void copy_from_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy
1317 1340
1318static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_info *p, int dir) 1341static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_info *p, int dir)
1319{ 1342{
1343 memset(p, 0, sizeof(*p));
1320 memcpy(&p->sel, &xp->selector, sizeof(p->sel)); 1344 memcpy(&p->sel, &xp->selector, sizeof(p->sel));
1321 memcpy(&p->lft, &xp->lft, sizeof(p->lft)); 1345 memcpy(&p->lft, &xp->lft, sizeof(p->lft));
1322 memcpy(&p->curlft, &xp->curlft, sizeof(p->curlft)); 1346 memcpy(&p->curlft, &xp->curlft, sizeof(p->curlft));
@@ -1421,6 +1445,7 @@ static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
1421 struct xfrm_user_tmpl *up = &vec[i]; 1445 struct xfrm_user_tmpl *up = &vec[i];
1422 struct xfrm_tmpl *kp = &xp->xfrm_vec[i]; 1446 struct xfrm_tmpl *kp = &xp->xfrm_vec[i];
1423 1447
1448 memset(up, 0, sizeof(*up));
1424 memcpy(&up->id, &kp->id, sizeof(up->id)); 1449 memcpy(&up->id, &kp->id, sizeof(up->id));
1425 up->family = kp->encap_family; 1450 up->family = kp->encap_family;
1426 memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr)); 1451 memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr));
@@ -1546,6 +1571,7 @@ static struct sk_buff *xfrm_policy_netlink(struct sk_buff *in_skb,
1546{ 1571{
1547 struct xfrm_dump_info info; 1572 struct xfrm_dump_info info;
1548 struct sk_buff *skb; 1573 struct sk_buff *skb;
1574 int err;
1549 1575
1550 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 1576 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1551 if (!skb) 1577 if (!skb)
@@ -1556,9 +1582,10 @@ static struct sk_buff *xfrm_policy_netlink(struct sk_buff *in_skb,
1556 info.nlmsg_seq = seq; 1582 info.nlmsg_seq = seq;
1557 info.nlmsg_flags = 0; 1583 info.nlmsg_flags = 0;
1558 1584
1559 if (dump_one_policy(xp, dir, 0, &info) < 0) { 1585 err = dump_one_policy(xp, dir, 0, &info);
1586 if (err) {
1560 kfree_skb(skb); 1587 kfree_skb(skb);
1561 return NULL; 1588 return ERR_PTR(err);
1562 } 1589 }
1563 1590
1564 return skb; 1591 return skb;
@@ -1822,7 +1849,7 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1822 goto out; 1849 goto out;
1823 1850
1824 spin_lock_bh(&x->lock); 1851 spin_lock_bh(&x->lock);
1825 xfrm_update_ae_params(x, attrs); 1852 xfrm_update_ae_params(x, attrs, 1);
1826 spin_unlock_bh(&x->lock); 1853 spin_unlock_bh(&x->lock);
1827 1854
1828 c.event = nlh->nlmsg_type; 1855 c.event = nlh->nlmsg_type;
diff --git a/scripts/Makefile.fwinst b/scripts/Makefile.fwinst
index c3f69ae275d1..4d908d16c035 100644
--- a/scripts/Makefile.fwinst
+++ b/scripts/Makefile.fwinst
@@ -27,7 +27,7 @@ endif
27installed-mod-fw := $(addprefix $(INSTALL_FW_PATH)/,$(mod-fw)) 27installed-mod-fw := $(addprefix $(INSTALL_FW_PATH)/,$(mod-fw))
28 28
29installed-fw := $(addprefix $(INSTALL_FW_PATH)/,$(fw-shipped-all)) 29installed-fw := $(addprefix $(INSTALL_FW_PATH)/,$(fw-shipped-all))
30installed-fw-dirs := $(sort $(dir $(installed-fw))) $(INSTALL_FW_PATH)/. 30installed-fw-dirs := $(sort $(dir $(installed-fw))) $(INSTALL_FW_PATH)/./
31 31
32# Workaround for make < 3.81, where .SECONDEXPANSION doesn't work. 32# Workaround for make < 3.81, where .SECONDEXPANSION doesn't work.
33PHONY += $(INSTALL_FW_PATH)/$$(%) install-all-dirs 33PHONY += $(INSTALL_FW_PATH)/$$(%) install-all-dirs
@@ -42,7 +42,7 @@ quiet_cmd_install = INSTALL $(subst $(srctree)/,,$@)
42$(installed-fw-dirs): 42$(installed-fw-dirs):
43 $(call cmd,mkdir) 43 $(call cmd,mkdir)
44 44
45$(installed-fw): $(INSTALL_FW_PATH)/%: $(obj)/% | $$(dir $(INSTALL_FW_PATH)/%) 45$(installed-fw): $(INSTALL_FW_PATH)/%: $(obj)/% | $(INSTALL_FW_PATH)/$$(dir %)
46 $(call cmd,install) 46 $(call cmd,install)
47 47
48PHONY += __fw_install __fw_modinst FORCE 48PHONY += __fw_install __fw_modinst FORCE
diff --git a/scripts/checksyscalls.sh b/scripts/checksyscalls.sh
index d24810fc6af6..fd8fa9aa7c4e 100755
--- a/scripts/checksyscalls.sh
+++ b/scripts/checksyscalls.sh
@@ -200,7 +200,7 @@ EOF
200syscall_list() { 200syscall_list() {
201 grep '^[0-9]' "$1" | sort -n | ( 201 grep '^[0-9]' "$1" | sort -n | (
202 while read nr abi name entry ; do 202 while read nr abi name entry ; do
203 echo <<EOF 203 cat <<EOF
204#if !defined(__NR_${name}) && !defined(__IGNORE_${name}) 204#if !defined(__NR_${name}) && !defined(__IGNORE_${name})
205#warning syscall ${name} not implemented 205#warning syscall ${name} not implemented
206#endif 206#endif
diff --git a/scripts/coccinelle/api/memdup_user.cocci b/scripts/coccinelle/api/memdup_user.cocci
index 2efac289fd59..2b131a8a1306 100644
--- a/scripts/coccinelle/api/memdup_user.cocci
+++ b/scripts/coccinelle/api/memdup_user.cocci
@@ -51,10 +51,10 @@ statement S1,S2;
51p << r.p; 51p << r.p;
52@@ 52@@
53 53
54coccilib.org.print_todo(p[0], "WARNING opportunity for memdep_user") 54coccilib.org.print_todo(p[0], "WARNING opportunity for memdup_user")
55 55
56@script:python depends on report@ 56@script:python depends on report@
57p << r.p; 57p << r.p;
58@@ 58@@
59 59
60coccilib.report.print_report(p[0], "WARNING opportunity for memdep_user") 60coccilib.report.print_report(p[0], "WARNING opportunity for memdup_user")
diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl
index 2fbbbc1ddea0..33689396953a 100644
--- a/scripts/kconfig/streamline_config.pl
+++ b/scripts/kconfig/streamline_config.pl
@@ -100,7 +100,7 @@ my @searchconfigs = (
100 }, 100 },
101); 101);
102 102
103sub find_config { 103sub read_config {
104 foreach my $conf (@searchconfigs) { 104 foreach my $conf (@searchconfigs) {
105 my $file = $conf->{"file"}; 105 my $file = $conf->{"file"};
106 106
@@ -115,17 +115,15 @@ sub find_config {
115 115
116 print STDERR "using config: '$file'\n"; 116 print STDERR "using config: '$file'\n";
117 117
118 open(CIN, "$exec $file |") || die "Failed to run $exec $file"; 118 open(my $infile, '-|', "$exec $file") || die "Failed to run $exec $file";
119 return; 119 my @x = <$infile>;
120 close $infile;
121 return @x;
120 } 122 }
121 die "No config file found"; 123 die "No config file found";
122} 124}
123 125
124find_config; 126my @config_file = read_config;
125
126# Read in the entire config file into config_file
127my @config_file = <CIN>;
128close CIN;
129 127
130# Parse options 128# Parse options
131my $localmodconfig = 0; 129my $localmodconfig = 0;
@@ -135,7 +133,7 @@ GetOptions("localmodconfig" => \$localmodconfig,
135 "localyesconfig" => \$localyesconfig); 133 "localyesconfig" => \$localyesconfig);
136 134
137# Get the build source and top level Kconfig file (passed in) 135# Get the build source and top level Kconfig file (passed in)
138my $ksource = $ARGV[0]; 136my $ksource = ($ARGV[0] ? $ARGV[0] : '.');
139my $kconfig = $ARGV[1]; 137my $kconfig = $ARGV[1];
140my $lsmod_file = $ENV{'LSMOD'}; 138my $lsmod_file = $ENV{'LSMOD'};
141 139
@@ -173,8 +171,8 @@ sub read_kconfig {
173 $source =~ s/\$$env/$ENV{$env}/; 171 $source =~ s/\$$env/$ENV{$env}/;
174 } 172 }
175 173
176 open(KIN, "$source") || die "Can't open $kconfig"; 174 open(my $kinfile, '<', $source) || die "Can't open $kconfig";
177 while (<KIN>) { 175 while (<$kinfile>) {
178 chomp; 176 chomp;
179 177
180 # Make sure that lines ending with \ continue 178 # Make sure that lines ending with \ continue
@@ -251,10 +249,10 @@ sub read_kconfig {
251 $state = "NONE"; 249 $state = "NONE";
252 } 250 }
253 } 251 }
254 close(KIN); 252 close($kinfile);
255 253
256 # read in any configs that were found. 254 # read in any configs that were found.
257 foreach $kconfig (@kconfigs) { 255 foreach my $kconfig (@kconfigs) {
258 if (!defined($read_kconfigs{$kconfig})) { 256 if (!defined($read_kconfigs{$kconfig})) {
259 $read_kconfigs{$kconfig} = 1; 257 $read_kconfigs{$kconfig} = 1;
260 read_kconfig($kconfig); 258 read_kconfig($kconfig);
@@ -295,8 +293,8 @@ foreach my $makefile (@makefiles) {
295 my $line = ""; 293 my $line = "";
296 my %make_vars; 294 my %make_vars;
297 295
298 open(MIN,$makefile) || die "Can't open $makefile"; 296 open(my $infile, '<', $makefile) || die "Can't open $makefile";
299 while (<MIN>) { 297 while (<$infile>) {
300 # if this line ends with a backslash, continue 298 # if this line ends with a backslash, continue
301 chomp; 299 chomp;
302 if (/^(.*)\\$/) { 300 if (/^(.*)\\$/) {
@@ -343,10 +341,11 @@ foreach my $makefile (@makefiles) {
343 } 341 }
344 } 342 }
345 } 343 }
346 close(MIN); 344 close($infile);
347} 345}
348 346
349my %modules; 347my %modules;
348my $linfile;
350 349
351if (defined($lsmod_file)) { 350if (defined($lsmod_file)) {
352 if ( ! -f $lsmod_file) { 351 if ( ! -f $lsmod_file) {
@@ -356,13 +355,10 @@ if (defined($lsmod_file)) {
356 die "$lsmod_file not found"; 355 die "$lsmod_file not found";
357 } 356 }
358 } 357 }
359 if ( -x $lsmod_file) { 358
360 # the file is executable, run it 359 my $otype = ( -x $lsmod_file) ? '-|' : '<';
361 open(LIN, "$lsmod_file|"); 360 open($linfile, $otype, $lsmod_file);
362 } else { 361
363 # Just read the contents
364 open(LIN, "$lsmod_file");
365 }
366} else { 362} else {
367 363
368 # see what modules are loaded on this system 364 # see what modules are loaded on this system
@@ -379,16 +375,16 @@ if (defined($lsmod_file)) {
379 $lsmod = "lsmod"; 375 $lsmod = "lsmod";
380 } 376 }
381 377
382 open(LIN,"$lsmod|") || die "Can not call lsmod with $lsmod"; 378 open($linfile, '-|', $lsmod) || die "Can not call lsmod with $lsmod";
383} 379}
384 380
385while (<LIN>) { 381while (<$linfile>) {
386 next if (/^Module/); # Skip the first line. 382 next if (/^Module/); # Skip the first line.
387 if (/^(\S+)/) { 383 if (/^(\S+)/) {
388 $modules{$1} = 1; 384 $modules{$1} = 1;
389 } 385 }
390} 386}
391close (LIN); 387close ($linfile);
392 388
393# add to the configs hash all configs that are needed to enable 389# add to the configs hash all configs that are needed to enable
394# a loaded module. This is a direct obj-${CONFIG_FOO} += bar.o 390# a loaded module. This is a direct obj-${CONFIG_FOO} += bar.o
@@ -605,6 +601,8 @@ foreach my $line (@config_file) {
605 if (defined($configs{$1})) { 601 if (defined($configs{$1})) {
606 if ($localyesconfig) { 602 if ($localyesconfig) {
607 $setconfigs{$1} = 'y'; 603 $setconfigs{$1} = 'y';
604 print "$1=y\n";
605 next;
608 } else { 606 } else {
609 $setconfigs{$1} = $2; 607 $setconfigs{$1} = $2;
610 } 608 }
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 4235a6361fec..b3d907eb93a9 100644
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -74,8 +74,13 @@ kallsyms()
74 info KSYM ${2} 74 info KSYM ${2}
75 local kallsymopt; 75 local kallsymopt;
76 76
77 if [ -n "${CONFIG_SYMBOL_PREFIX}" ]; then
78 kallsymopt="${kallsymopt} \
79 --symbol-prefix=${CONFIG_SYMBOL_PREFIX}"
80 fi
81
77 if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then 82 if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then
78 kallsymopt=--all-symbols 83 kallsymopt="${kallsymopt} --all-symbols"
79 fi 84 fi
80 85
81 local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ 86 local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
diff --git a/security/apparmor/.gitignore b/security/apparmor/.gitignore
index 4d995aeaebc0..9cdec70d72b8 100644
--- a/security/apparmor/.gitignore
+++ b/security/apparmor/.gitignore
@@ -1,6 +1,5 @@
1# 1#
2# Generated include files 2# Generated include files
3# 3#
4af_names.h
5capability_names.h 4capability_names.h
6rlim_names.h 5rlim_names.h
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 3364fbf46807..6cfc6478863e 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -1486,7 +1486,6 @@ long keyctl_session_to_parent(void)
1486 oldwork = NULL; 1486 oldwork = NULL;
1487 parent = me->real_parent; 1487 parent = me->real_parent;
1488 1488
1489 task_lock(parent);
1490 /* the parent mustn't be init and mustn't be a kernel thread */ 1489 /* the parent mustn't be init and mustn't be a kernel thread */
1491 if (parent->pid <= 1 || !parent->mm) 1490 if (parent->pid <= 1 || !parent->mm)
1492 goto unlock; 1491 goto unlock;
@@ -1530,7 +1529,6 @@ long keyctl_session_to_parent(void)
1530 if (!ret) 1529 if (!ret)
1531 newwork = NULL; 1530 newwork = NULL;
1532unlock: 1531unlock:
1533 task_unlock(parent);
1534 write_unlock_irq(&tasklist_lock); 1532 write_unlock_irq(&tasklist_lock);
1535 rcu_read_unlock(); 1533 rcu_read_unlock();
1536 if (oldwork) 1534 if (oldwork)
diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
index c220f314709c..65f67cb0aefb 100644
--- a/security/selinux/include/xfrm.h
+++ b/security/selinux/include/xfrm.h
@@ -51,6 +51,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
51static inline void selinux_xfrm_notify_policyload(void) 51static inline void selinux_xfrm_notify_policyload(void)
52{ 52{
53 atomic_inc(&flow_cache_genid); 53 atomic_inc(&flow_cache_genid);
54 rt_genid_bump(&init_net);
54} 55}
55#else 56#else
56static inline int selinux_xfrm_enabled(void) 57static inline int selinux_xfrm_enabled(void)
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index ec2118d0e27a..eb60cb8dbb8a 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -80,14 +80,12 @@ static int snd_compr_open(struct inode *inode, struct file *f)
80 int maj = imajor(inode); 80 int maj = imajor(inode);
81 int ret; 81 int ret;
82 82
83 if (f->f_flags & O_WRONLY) 83 if ((f->f_flags & O_ACCMODE) == O_WRONLY)
84 dirn = SND_COMPRESS_PLAYBACK; 84 dirn = SND_COMPRESS_PLAYBACK;
85 else if (f->f_flags & O_RDONLY) 85 else if ((f->f_flags & O_ACCMODE) == O_RDONLY)
86 dirn = SND_COMPRESS_CAPTURE; 86 dirn = SND_COMPRESS_CAPTURE;
87 else { 87 else
88 pr_err("invalid direction\n");
89 return -EINVAL; 88 return -EINVAL;
90 }
91 89
92 if (maj == snd_major) 90 if (maj == snd_major)
93 compr = snd_lookup_minor_data(iminor(inode), 91 compr = snd_lookup_minor_data(iminor(inode),
diff --git a/sound/oss/.gitignore b/sound/oss/.gitignore
index 7efb12b45502..12a3920d6fb6 100644
--- a/sound/oss/.gitignore
+++ b/sound/oss/.gitignore
@@ -1,4 +1,3 @@
1#Ignore generated files 1#Ignore generated files
2maui_boot.h
3pss_boot.h 2pss_boot.h
4trix_boot.h 3trix_boot.h
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index f25c24c743f9..1c65cc5e3a31 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -2353,6 +2353,7 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2353 } 2353 }
2354 if (codec->patch_ops.free) 2354 if (codec->patch_ops.free)
2355 codec->patch_ops.free(codec); 2355 codec->patch_ops.free(codec);
2356 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
2356 snd_hda_jack_tbl_clear(codec); 2357 snd_hda_jack_tbl_clear(codec);
2357 codec->proc_widget_hook = NULL; 2358 codec->proc_widget_hook = NULL;
2358 codec->spec = NULL; 2359 codec->spec = NULL;
@@ -2368,7 +2369,6 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2368 codec->num_pcms = 0; 2369 codec->num_pcms = 0;
2369 codec->pcm_info = NULL; 2370 codec->pcm_info = NULL;
2370 codec->preset = NULL; 2371 codec->preset = NULL;
2371 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
2372 codec->slave_dig_outs = NULL; 2372 codec->slave_dig_outs = NULL;
2373 codec->spdif_status_reset = 0; 2373 codec->spdif_status_reset = 0;
2374 module_put(codec->owner); 2374 module_put(codec->owner);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 60882c62f180..c4763c52eaf6 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -2701,6 +2701,8 @@ static struct snd_pci_quirk position_fix_list[] __devinitdata = {
2701 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB), 2701 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
2702 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB), 2702 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
2703 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB), 2703 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
2704 SND_PCI_QUIRK(0x1043, 0x1ac3, "ASUS X53S", POS_FIX_POSBUF),
2705 SND_PCI_QUIRK(0x1043, 0x1b43, "ASUS K53E", POS_FIX_POSBUF),
2704 SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB), 2706 SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
2705 SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB), 2707 SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB),
2706 SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB), 2708 SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 6f806d3e56bb..3d4722f0a1ca 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -1075,7 +1075,7 @@ static struct snd_kcontrol_new stac_smux_mixer = {
1075 1075
1076static const char * const slave_pfxs[] = { 1076static const char * const slave_pfxs[] = {
1077 "Front", "Surround", "Center", "LFE", "Side", 1077 "Front", "Surround", "Center", "LFE", "Side",
1078 "Headphone", "Speaker", "IEC958", 1078 "Headphone", "Speaker", "IEC958", "PCM",
1079 NULL 1079 NULL
1080}; 1080};
1081 1081
diff --git a/sound/pci/ice1712/prodigy_hifi.c b/sound/pci/ice1712/prodigy_hifi.c
index 764cc93dbca4..075d5aa1fee0 100644
--- a/sound/pci/ice1712/prodigy_hifi.c
+++ b/sound/pci/ice1712/prodigy_hifi.c
@@ -297,6 +297,7 @@ static int ak4396_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
297} 297}
298 298
299static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -12700, 100, 1); 299static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -12700, 100, 1);
300static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
300 301
301static struct snd_kcontrol_new prodigy_hd2_controls[] __devinitdata = { 302static struct snd_kcontrol_new prodigy_hd2_controls[] __devinitdata = {
302 { 303 {
@@ -307,7 +308,7 @@ static struct snd_kcontrol_new prodigy_hd2_controls[] __devinitdata = {
307 .info = ak4396_dac_vol_info, 308 .info = ak4396_dac_vol_info,
308 .get = ak4396_dac_vol_get, 309 .get = ak4396_dac_vol_get,
309 .put = ak4396_dac_vol_put, 310 .put = ak4396_dac_vol_put,
310 .tlv = { .p = db_scale_wm_dac }, 311 .tlv = { .p = ak4396_db_scale },
311 }, 312 },
312}; 313};
313 314
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index 5c9cacaf2d52..1cf7a32d1b21 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -426,7 +426,7 @@ static const int arizona_44k1_bclk_rates[] = {
426 940800, 426 940800,
427 1411200, 427 1411200,
428 1881600, 428 1881600,
429 2882400, 429 2822400,
430 3763200, 430 3763200,
431 5644800, 431 5644800,
432 7526400, 432 7526400,
diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c
index 8f726c063f42..115a40301810 100644
--- a/sound/soc/codecs/mc13783.c
+++ b/sound/soc/codecs/mc13783.c
@@ -659,7 +659,7 @@ static struct snd_soc_dai_driver mc13783_dai_async[] = {
659 .id = MC13783_ID_STEREO_DAC, 659 .id = MC13783_ID_STEREO_DAC,
660 .playback = { 660 .playback = {
661 .stream_name = "Playback", 661 .stream_name = "Playback",
662 .channels_min = 1, 662 .channels_min = 2,
663 .channels_max = 2, 663 .channels_max = 2,
664 .rates = SNDRV_PCM_RATE_8000_96000, 664 .rates = SNDRV_PCM_RATE_8000_96000,
665 .formats = MC13783_FORMATS, 665 .formats = MC13783_FORMATS,
@@ -670,7 +670,7 @@ static struct snd_soc_dai_driver mc13783_dai_async[] = {
670 .id = MC13783_ID_STEREO_CODEC, 670 .id = MC13783_ID_STEREO_CODEC,
671 .capture = { 671 .capture = {
672 .stream_name = "Capture", 672 .stream_name = "Capture",
673 .channels_min = 1, 673 .channels_min = 2,
674 .channels_max = 2, 674 .channels_max = 2,
675 .rates = MC13783_RATES_RECORD, 675 .rates = MC13783_RATES_RECORD,
676 .formats = MC13783_FORMATS, 676 .formats = MC13783_FORMATS,
@@ -692,14 +692,14 @@ static struct snd_soc_dai_driver mc13783_dai_sync[] = {
692 .id = MC13783_ID_SYNC, 692 .id = MC13783_ID_SYNC,
693 .playback = { 693 .playback = {
694 .stream_name = "Playback", 694 .stream_name = "Playback",
695 .channels_min = 1, 695 .channels_min = 2,
696 .channels_max = 2, 696 .channels_max = 2,
697 .rates = SNDRV_PCM_RATE_8000_96000, 697 .rates = SNDRV_PCM_RATE_8000_96000,
698 .formats = MC13783_FORMATS, 698 .formats = MC13783_FORMATS,
699 }, 699 },
700 .capture = { 700 .capture = {
701 .stream_name = "Capture", 701 .stream_name = "Capture",
702 .channels_min = 1, 702 .channels_min = 2,
703 .channels_max = 2, 703 .channels_max = 2,
704 .rates = MC13783_RATES_RECORD, 704 .rates = MC13783_RATES_RECORD,
705 .formats = MC13783_FORMATS, 705 .formats = MC13783_FORMATS,
diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index 3fd5b29dc933..a3acb7a85f6a 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -702,7 +702,7 @@ static bool wm2000_readable_reg(struct device *dev, unsigned int reg)
702} 702}
703 703
704static const struct regmap_config wm2000_regmap = { 704static const struct regmap_config wm2000_regmap = {
705 .reg_bits = 8, 705 .reg_bits = 16,
706 .val_bits = 8, 706 .val_bits = 8,
707 707
708 .max_register = WM2000_REG_IF_CTL, 708 .max_register = WM2000_REG_IF_CTL,
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 0013afe48e66..dc4262eea4b7 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -100,7 +100,7 @@ static const struct reg_default wm8904_reg_defaults[] = {
100 { 14, 0x0000 }, /* R14 - Power Management 2 */ 100 { 14, 0x0000 }, /* R14 - Power Management 2 */
101 { 15, 0x0000 }, /* R15 - Power Management 3 */ 101 { 15, 0x0000 }, /* R15 - Power Management 3 */
102 { 18, 0x0000 }, /* R18 - Power Management 6 */ 102 { 18, 0x0000 }, /* R18 - Power Management 6 */
103 { 19, 0x945E }, /* R20 - Clock Rates 0 */ 103 { 20, 0x945E }, /* R20 - Clock Rates 0 */
104 { 21, 0x0C05 }, /* R21 - Clock Rates 1 */ 104 { 21, 0x0C05 }, /* R21 - Clock Rates 1 */
105 { 22, 0x0006 }, /* R22 - Clock Rates 2 */ 105 { 22, 0x0006 }, /* R22 - Clock Rates 2 */
106 { 24, 0x0050 }, /* R24 - Audio Interface 0 */ 106 { 24, 0x0050 }, /* R24 - Audio Interface 0 */
diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c
index fb21b17f17f5..199408ec4261 100644
--- a/sound/soc/fsl/imx-sgtl5000.c
+++ b/sound/soc/fsl/imx-sgtl5000.c
@@ -94,7 +94,7 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev)
94 dev_err(&pdev->dev, "audmux internal port setup failed\n"); 94 dev_err(&pdev->dev, "audmux internal port setup failed\n");
95 return ret; 95 return ret;
96 } 96 }
97 imx_audmux_v2_configure_port(ext_port, 97 ret = imx_audmux_v2_configure_port(ext_port,
98 IMX_AUDMUX_V2_PTCR_SYN, 98 IMX_AUDMUX_V2_PTCR_SYN,
99 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)); 99 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
100 if (ret) { 100 if (ret) {
diff --git a/sound/soc/omap/am3517evm.c b/sound/soc/omap/am3517evm.c
index 009533ab8d18..df65f98211ec 100644
--- a/sound/soc/omap/am3517evm.c
+++ b/sound/soc/omap/am3517evm.c
@@ -59,7 +59,7 @@ static int am3517evm_hw_params(struct snd_pcm_substream *substream,
59 return ret; 59 return ret;
60 } 60 }
61 61
62 snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_FSR_SRC_FSX, 0, 62 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_FSR_SRC_FSX, 0,
63 SND_SOC_CLOCK_IN); 63 SND_SOC_CLOCK_IN);
64 if (ret < 0) { 64 if (ret < 0) {
65 printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_FSR_SRC_FSX\n"); 65 printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_FSR_SRC_FSX\n");
diff --git a/sound/soc/samsung/dma.c b/sound/soc/samsung/dma.c
index f3ebc38c10fe..b70964ea448c 100644
--- a/sound/soc/samsung/dma.c
+++ b/sound/soc/samsung/dma.c
@@ -34,9 +34,7 @@ static const struct snd_pcm_hardware dma_hardware = {
34 .info = SNDRV_PCM_INFO_INTERLEAVED | 34 .info = SNDRV_PCM_INFO_INTERLEAVED |
35 SNDRV_PCM_INFO_BLOCK_TRANSFER | 35 SNDRV_PCM_INFO_BLOCK_TRANSFER |
36 SNDRV_PCM_INFO_MMAP | 36 SNDRV_PCM_INFO_MMAP |
37 SNDRV_PCM_INFO_MMAP_VALID | 37 SNDRV_PCM_INFO_MMAP_VALID,
38 SNDRV_PCM_INFO_PAUSE |
39 SNDRV_PCM_INFO_RESUME,
40 .formats = SNDRV_PCM_FMTBIT_S16_LE | 38 .formats = SNDRV_PCM_FMTBIT_S16_LE |
41 SNDRV_PCM_FMTBIT_U16_LE | 39 SNDRV_PCM_FMTBIT_U16_LE |
42 SNDRV_PCM_FMTBIT_U8 | 40 SNDRV_PCM_FMTBIT_U8 |
@@ -248,15 +246,11 @@ static int dma_trigger(struct snd_pcm_substream *substream, int cmd)
248 246
249 switch (cmd) { 247 switch (cmd) {
250 case SNDRV_PCM_TRIGGER_START: 248 case SNDRV_PCM_TRIGGER_START:
251 case SNDRV_PCM_TRIGGER_RESUME:
252 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
253 prtd->state |= ST_RUNNING; 249 prtd->state |= ST_RUNNING;
254 prtd->params->ops->trigger(prtd->params->ch); 250 prtd->params->ops->trigger(prtd->params->ch);
255 break; 251 break;
256 252
257 case SNDRV_PCM_TRIGGER_STOP: 253 case SNDRV_PCM_TRIGGER_STOP:
258 case SNDRV_PCM_TRIGGER_SUSPEND:
259 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
260 prtd->state &= ~ST_RUNNING; 254 prtd->state &= ~ST_RUNNING;
261 prtd->params->ops->stop(prtd->params->ch); 255 prtd->params->ops->stop(prtd->params->ch);
262 break; 256 break;
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index dd7c49fafd75..f90139b5f50d 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -291,8 +291,11 @@ static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
291 if (dapm->codec->driver->set_bias_level) 291 if (dapm->codec->driver->set_bias_level)
292 ret = dapm->codec->driver->set_bias_level(dapm->codec, 292 ret = dapm->codec->driver->set_bias_level(dapm->codec,
293 level); 293 level);
294 } else 294 else
295 dapm->bias_level = level;
296 } else if (!card || dapm != &card->dapm) {
295 dapm->bias_level = level; 297 dapm->bias_level = level;
298 }
296 299
297 if (ret != 0) 300 if (ret != 0)
298 goto out; 301 goto out;
diff --git a/sound/soc/spear/spear_pcm.c b/sound/soc/spear/spear_pcm.c
index 97c2cac8e92c..8c7f23729446 100644
--- a/sound/soc/spear/spear_pcm.c
+++ b/sound/soc/spear/spear_pcm.c
@@ -138,7 +138,7 @@ static void spear_pcm_free(struct snd_pcm *pcm)
138 continue; 138 continue;
139 139
140 buf = &substream->dma_buffer; 140 buf = &substream->dma_buffer;
141 if (!buf && !buf->area) 141 if (!buf || !buf->area)
142 continue; 142 continue;
143 143
144 dma_free_writecombine(pcm->card->dev, buf->bytes, 144 dma_free_writecombine(pcm->card->dev, buf->bytes,
diff --git a/sound/soc/tegra/tegra_alc5632.c b/sound/soc/tegra/tegra_alc5632.c
index e463529b38bb..76cb1b363b71 100644
--- a/sound/soc/tegra/tegra_alc5632.c
+++ b/sound/soc/tegra/tegra_alc5632.c
@@ -89,7 +89,6 @@ static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio = {
89 .name = "Headset detection", 89 .name = "Headset detection",
90 .report = SND_JACK_HEADSET, 90 .report = SND_JACK_HEADSET,
91 .debounce_time = 150, 91 .debounce_time = 150,
92 .invert = 1,
93}; 92};
94 93
95static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = { 94static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = {
diff --git a/sound/soc/tegra/tegra_pcm.c b/sound/soc/tegra/tegra_pcm.c
index 5658bcec1931..8d6900c1ee47 100644
--- a/sound/soc/tegra/tegra_pcm.c
+++ b/sound/soc/tegra/tegra_pcm.c
@@ -334,11 +334,11 @@ static int tegra_pcm_hw_params(struct snd_pcm_substream *substream,
334 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 334 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
335 slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 335 slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
336 slave_config.dst_addr = dmap->addr; 336 slave_config.dst_addr = dmap->addr;
337 slave_config.src_maxburst = 0; 337 slave_config.dst_maxburst = 4;
338 } else { 338 } else {
339 slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 339 slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
340 slave_config.src_addr = dmap->addr; 340 slave_config.src_addr = dmap->addr;
341 slave_config.dst_maxburst = 0; 341 slave_config.src_maxburst = 4;
342 } 342 }
343 slave_config.slave_id = dmap->req_sel; 343 slave_config.slave_id = dmap->req_sel;
344 344
diff --git a/sound/soc/ux500/ux500_msp_i2s.c b/sound/soc/ux500/ux500_msp_i2s.c
index 5c472f335a64..eb85113d472a 100644
--- a/sound/soc/ux500/ux500_msp_i2s.c
+++ b/sound/soc/ux500/ux500_msp_i2s.c
@@ -663,7 +663,6 @@ int ux500_msp_i2s_init_msp(struct platform_device *pdev,
663 struct ux500_msp **msp_p, 663 struct ux500_msp **msp_p,
664 struct msp_i2s_platform_data *platform_data) 664 struct msp_i2s_platform_data *platform_data)
665{ 665{
666 int ret = 0;
667 struct resource *res = NULL; 666 struct resource *res = NULL;
668 struct i2s_controller *i2s_cont; 667 struct i2s_controller *i2s_cont;
669 struct ux500_msp *msp; 668 struct ux500_msp *msp;
@@ -685,15 +684,14 @@ int ux500_msp_i2s_init_msp(struct platform_device *pdev,
685 if (res == NULL) { 684 if (res == NULL) {
686 dev_err(&pdev->dev, "%s: ERROR: Unable to get resource!\n", 685 dev_err(&pdev->dev, "%s: ERROR: Unable to get resource!\n",
687 __func__); 686 __func__);
688 ret = -ENOMEM; 687 return -ENOMEM;
689 goto err_res;
690 } 688 }
691 689
692 msp->registers = ioremap(res->start, (res->end - res->start + 1)); 690 msp->registers = devm_ioremap(&pdev->dev, res->start,
691 resource_size(res));
693 if (msp->registers == NULL) { 692 if (msp->registers == NULL) {
694 dev_err(&pdev->dev, "%s: ERROR: ioremap failed!\n", __func__); 693 dev_err(&pdev->dev, "%s: ERROR: ioremap failed!\n", __func__);
695 ret = -ENOMEM; 694 return -ENOMEM;
696 goto err_res;
697 } 695 }
698 696
699 msp->msp_state = MSP_STATE_IDLE; 697 msp->msp_state = MSP_STATE_IDLE;
@@ -705,7 +703,7 @@ int ux500_msp_i2s_init_msp(struct platform_device *pdev,
705 dev_err(&pdev->dev, 703 dev_err(&pdev->dev,
706 "%s: ERROR: Failed to allocate I2S-controller!\n", 704 "%s: ERROR: Failed to allocate I2S-controller!\n",
707 __func__); 705 __func__);
708 goto err_i2s_cont; 706 return -ENOMEM;
709 } 707 }
710 i2s_cont->dev.parent = &pdev->dev; 708 i2s_cont->dev.parent = &pdev->dev;
711 i2s_cont->data = (void *)msp; 709 i2s_cont->data = (void *)msp;
@@ -716,14 +714,6 @@ int ux500_msp_i2s_init_msp(struct platform_device *pdev,
716 msp->i2s_cont = i2s_cont; 714 msp->i2s_cont = i2s_cont;
717 715
718 return 0; 716 return 0;
719
720err_i2s_cont:
721 iounmap(msp->registers);
722
723err_res:
724 devm_kfree(&pdev->dev, msp);
725
726 return ret;
727} 717}
728 718
729void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev, 719void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev,
@@ -732,11 +722,6 @@ void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev,
732 dev_dbg(msp->dev, "%s: Enter (id = %d).\n", __func__, msp->id); 722 dev_dbg(msp->dev, "%s: Enter (id = %d).\n", __func__, msp->id);
733 723
734 device_unregister(&msp->i2s_cont->dev); 724 device_unregister(&msp->i2s_cont->dev);
735 devm_kfree(&pdev->dev, msp->i2s_cont);
736
737 iounmap(msp->registers);
738
739 devm_kfree(&pdev->dev, msp);
740} 725}
741 726
742MODULE_LICENSE("GPL v2"); 727MODULE_LICENSE("GPL v2");
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index d6e2bb49c59c..060dccb9ec75 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -197,7 +197,13 @@ static void prepare_outbound_urb(struct snd_usb_endpoint *ep,
197 /* no data provider, so send silence */ 197 /* no data provider, so send silence */
198 unsigned int offs = 0; 198 unsigned int offs = 0;
199 for (i = 0; i < ctx->packets; ++i) { 199 for (i = 0; i < ctx->packets; ++i) {
200 int counts = ctx->packet_size[i]; 200 int counts;
201
202 if (ctx->packet_size[i])
203 counts = ctx->packet_size[i];
204 else
205 counts = snd_usb_endpoint_next_packet_size(ep);
206
201 urb->iso_frame_desc[i].offset = offs * ep->stride; 207 urb->iso_frame_desc[i].offset = offs * ep->stride;
202 urb->iso_frame_desc[i].length = counts * ep->stride; 208 urb->iso_frame_desc[i].length = counts * ep->stride;
203 offs += counts; 209 offs += counts;
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index fd5e982fc98c..f782ce19bf5a 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -1140,6 +1140,12 @@ static void retire_playback_urb(struct snd_usb_substream *subs,
1140 int processed = urb->transfer_buffer_length / stride; 1140 int processed = urb->transfer_buffer_length / stride;
1141 int est_delay; 1141 int est_delay;
1142 1142
1143 /* ignore the delay accounting when procssed=0 is given, i.e.
1144 * silent payloads are procssed before handling the actual data
1145 */
1146 if (!processed)
1147 return;
1148
1143 spin_lock_irqsave(&subs->lock, flags); 1149 spin_lock_irqsave(&subs->lock, flags);
1144 est_delay = snd_usb_pcm_delay(subs, runtime->rate); 1150 est_delay = snd_usb_pcm_delay(subs, runtime->rate);
1145 /* update delay with exact number of samples played */ 1151 /* update delay with exact number of samples played */
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 3bdb407f9cd9..eb340571e7d6 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -58,7 +58,7 @@ struct callchain_list {
58/* 58/*
59 * A callchain cursor is a single linked list that 59 * A callchain cursor is a single linked list that
60 * let one feed a callchain progressively. 60 * let one feed a callchain progressively.
61 * It keeps persitent allocated entries to minimize 61 * It keeps persistent allocated entries to minimize
62 * allocations. 62 * allocations.
63 */ 63 */
64struct callchain_cursor_node { 64struct callchain_cursor_node {
diff --git a/tools/perf/util/parse-events-test.c b/tools/perf/util/parse-events-test.c
index d7244e553670..28c18d1d52c3 100644
--- a/tools/perf/util/parse-events-test.c
+++ b/tools/perf/util/parse-events-test.c
@@ -1016,7 +1016,7 @@ static int test_pmu(void)
1016 1016
1017 ret = stat(path, &st); 1017 ret = stat(path, &st);
1018 if (ret) 1018 if (ret)
1019 pr_debug("ommiting PMU cpu tests\n"); 1019 pr_debug("omitting PMU cpu tests\n");
1020 return !ret; 1020 return !ret;
1021} 1021}
1022 1022
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 213362850abd..c40c2d33199e 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -1,5 +1,5 @@
1# 1#
2# List of files needed by perf python extention 2# List of files needed by perf python extension
3# 3#
4# Each source file must be placed on its own line so that it can be 4# Each source file must be placed on its own line so that it can be
5# processed by Makefile and util/setup.py accordingly. 5# processed by Makefile and util/setup.py accordingly.
diff --git a/tools/testing/ktest/examples/include/defaults.conf b/tools/testing/ktest/examples/include/defaults.conf
index 323a552ce642..63a1a83f4f0b 100644
--- a/tools/testing/ktest/examples/include/defaults.conf
+++ b/tools/testing/ktest/examples/include/defaults.conf
@@ -33,7 +33,7 @@ DEFAULTS
33THIS_DIR := ${PWD} 33THIS_DIR := ${PWD}
34 34
35 35
36# to orginize your configs, having each machine save their configs 36# to organize your configs, having each machine save their configs
37# into a separate directly is useful. 37# into a separate directly is useful.
38CONFIG_DIR := ${THIS_DIR}/configs/${MACHINE} 38CONFIG_DIR := ${THIS_DIR}/configs/${MACHINE}
39 39
diff --git a/tools/testing/ktest/examples/include/tests.conf b/tools/testing/ktest/examples/include/tests.conf
index 4fdb811bd810..60cedb1a1154 100644
--- a/tools/testing/ktest/examples/include/tests.conf
+++ b/tools/testing/ktest/examples/include/tests.conf
@@ -47,7 +47,7 @@ BUILD_NOCLEAN = 1
47# Build, install, boot and test with a randconfg 10 times. 47# Build, install, boot and test with a randconfg 10 times.
48# It is important that you have set MIN_CONFIG in the config 48# It is important that you have set MIN_CONFIG in the config
49# that includes this file otherwise it is likely that the 49# that includes this file otherwise it is likely that the
50# randconfig will not have the neccessary configs needed to 50# randconfig will not have the necessary configs needed to
51# boot your box. This version of the test requires a min 51# boot your box. This version of the test requires a min
52# config that has enough to make sure the target has network 52# config that has enough to make sure the target has network
53# working. 53# working.
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 52b7959cd513..c05bcd293d8c 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -840,7 +840,9 @@ sub __read_config {
840 840
841 if ($rest =~ /\sIF\s+(.*)/) { 841 if ($rest =~ /\sIF\s+(.*)/) {
842 # May be a ELSE IF section. 842 # May be a ELSE IF section.
843 if (!process_if($name, $1)) { 843 if (process_if($name, $1)) {
844 $if_set = 1;
845 } else {
844 $skip = 1; 846 $skip = 1;
845 } 847 }
846 $rest = ""; 848 $rest = "";
diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests
index 8b40bd5e5cc2..4c53cae6c273 100644
--- a/tools/testing/selftests/vm/run_vmtests
+++ b/tools/testing/selftests/vm/run_vmtests
@@ -36,7 +36,7 @@ mkdir $mnt
36mount -t hugetlbfs none $mnt 36mount -t hugetlbfs none $mnt
37 37
38echo "--------------------" 38echo "--------------------"
39echo "runing hugepage-mmap" 39echo "running hugepage-mmap"
40echo "--------------------" 40echo "--------------------"
41./hugepage-mmap 41./hugepage-mmap
42if [ $? -ne 0 ]; then 42if [ $? -ne 0 ]; then
@@ -50,7 +50,7 @@ shmall=`cat /proc/sys/kernel/shmall`
50echo 268435456 > /proc/sys/kernel/shmmax 50echo 268435456 > /proc/sys/kernel/shmmax
51echo 4194304 > /proc/sys/kernel/shmall 51echo 4194304 > /proc/sys/kernel/shmall
52echo "--------------------" 52echo "--------------------"
53echo "runing hugepage-shm" 53echo "running hugepage-shm"
54echo "--------------------" 54echo "--------------------"
55./hugepage-shm 55./hugepage-shm
56if [ $? -ne 0 ]; then 56if [ $? -ne 0 ]; then
@@ -62,7 +62,7 @@ echo $shmmax > /proc/sys/kernel/shmmax
62echo $shmall > /proc/sys/kernel/shmall 62echo $shmall > /proc/sys/kernel/shmall
63 63
64echo "--------------------" 64echo "--------------------"
65echo "runing map_hugetlb" 65echo "running map_hugetlb"
66echo "--------------------" 66echo "--------------------"
67./map_hugetlb 67./map_hugetlb
68if [ $? -ne 0 ]; then 68if [ $? -ne 0 ]; then